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 | |
72b9f47f | 989 | static void dwarf_decode_lines (struct line_header *, const char *, bfd *, |
aaa75496 | 990 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 991 | |
72b9f47f | 992 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 993 | |
a14ed312 | 994 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 995 | struct dwarf2_cu *); |
c906108c | 996 | |
34eaf542 TT |
997 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
998 | struct dwarf2_cu *, struct symbol *); | |
999 | ||
a14ed312 | 1000 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1001 | struct dwarf2_cu *); |
c906108c | 1002 | |
98bfdba5 PA |
1003 | static void dwarf2_const_value_attr (struct attribute *attr, |
1004 | struct type *type, | |
1005 | const char *name, | |
1006 | struct obstack *obstack, | |
1007 | struct dwarf2_cu *cu, long *value, | |
1008 | gdb_byte **bytes, | |
1009 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1010 | |
e7c27a73 | 1011 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1012 | |
b4ba55a1 JB |
1013 | static int need_gnat_info (struct dwarf2_cu *); |
1014 | ||
3e43a32a MS |
1015 | static struct type *die_descriptive_type (struct die_info *, |
1016 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1017 | |
1018 | static void set_descriptive_type (struct type *, struct die_info *, | |
1019 | struct dwarf2_cu *); | |
1020 | ||
e7c27a73 DJ |
1021 | static struct type *die_containing_type (struct die_info *, |
1022 | struct dwarf2_cu *); | |
c906108c | 1023 | |
673bfd45 DE |
1024 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1025 | struct dwarf2_cu *); | |
c906108c | 1026 | |
f792889a | 1027 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1028 | |
673bfd45 DE |
1029 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1030 | ||
086ed43d | 1031 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1032 | |
6e70227d | 1033 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1034 | const char *suffix, int physname, |
1035 | struct dwarf2_cu *cu); | |
63d06c5c | 1036 | |
e7c27a73 | 1037 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1038 | |
348e048f DE |
1039 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1040 | ||
e7c27a73 | 1041 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1042 | |
e7c27a73 | 1043 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1044 | |
96408a79 SA |
1045 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1046 | ||
ff013f42 JK |
1047 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1048 | struct dwarf2_cu *, struct partial_symtab *); | |
1049 | ||
a14ed312 | 1050 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1051 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1052 | struct partial_symtab *); | |
c906108c | 1053 | |
fae299cd DC |
1054 | static void get_scope_pc_bounds (struct die_info *, |
1055 | CORE_ADDR *, CORE_ADDR *, | |
1056 | struct dwarf2_cu *); | |
1057 | ||
801e3a5b JB |
1058 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1059 | CORE_ADDR, struct dwarf2_cu *); | |
1060 | ||
a14ed312 | 1061 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1062 | struct dwarf2_cu *); |
c906108c | 1063 | |
a14ed312 | 1064 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1065 | struct type *, struct dwarf2_cu *); |
c906108c | 1066 | |
a14ed312 | 1067 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1068 | struct die_info *, struct type *, |
e7c27a73 | 1069 | struct dwarf2_cu *); |
c906108c | 1070 | |
a14ed312 | 1071 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1072 | struct type *, |
1073 | struct dwarf2_cu *); | |
c906108c | 1074 | |
134d01f1 | 1075 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1076 | |
e7c27a73 | 1077 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1078 | |
e7c27a73 | 1079 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1080 | |
5d7cb8df JK |
1081 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1082 | ||
27aa8d6a SW |
1083 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1084 | ||
f55ee35c JK |
1085 | static struct type *read_module_type (struct die_info *die, |
1086 | struct dwarf2_cu *cu); | |
1087 | ||
38d518c9 | 1088 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1089 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1090 | |
134d01f1 | 1091 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1092 | |
e7c27a73 | 1093 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1094 | |
6e70227d | 1095 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1096 | struct dwarf2_cu *); |
1097 | ||
93311388 | 1098 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1099 | |
93311388 DE |
1100 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1101 | gdb_byte *info_ptr, | |
d97bc12b DE |
1102 | gdb_byte **new_info_ptr, |
1103 | struct die_info *parent); | |
1104 | ||
93311388 DE |
1105 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1106 | gdb_byte *info_ptr, | |
fe1b8b76 | 1107 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1108 | struct die_info *parent); |
1109 | ||
93311388 DE |
1110 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1111 | gdb_byte *info_ptr, | |
fe1b8b76 | 1112 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1113 | struct die_info *parent); |
1114 | ||
93311388 DE |
1115 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1116 | struct die_info **, gdb_byte *, | |
1117 | int *); | |
1118 | ||
e7c27a73 | 1119 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1120 | |
71c25dea TT |
1121 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1122 | struct obstack *); | |
1123 | ||
e142c38c | 1124 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1125 | |
98bfdba5 PA |
1126 | static const char *dwarf2_full_name (char *name, |
1127 | struct die_info *die, | |
1128 | struct dwarf2_cu *cu); | |
1129 | ||
e142c38c | 1130 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1131 | struct dwarf2_cu **); |
9219021c | 1132 | |
a14ed312 | 1133 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1134 | |
a14ed312 | 1135 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1136 | |
a14ed312 | 1137 | static char *dwarf_form_name (unsigned int); |
c906108c | 1138 | |
a14ed312 | 1139 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1140 | |
a14ed312 | 1141 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1142 | |
1143 | #if 0 | |
a14ed312 | 1144 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1145 | #endif |
1146 | ||
f9aca02d | 1147 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1148 | |
d97bc12b DE |
1149 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1150 | ||
1151 | static void dump_die_for_error (struct die_info *); | |
1152 | ||
1153 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1154 | struct die_info *); | |
c906108c | 1155 | |
d97bc12b | 1156 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1157 | |
51545339 | 1158 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1159 | struct dwarf2_cu *); |
c906108c | 1160 | |
93311388 DE |
1161 | static int is_ref_attr (struct attribute *); |
1162 | ||
c764a876 | 1163 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1164 | |
43bbcdc2 | 1165 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1166 | |
348e048f DE |
1167 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1168 | struct attribute *, | |
1169 | struct dwarf2_cu **); | |
1170 | ||
10b3939b DJ |
1171 | static struct die_info *follow_die_ref (struct die_info *, |
1172 | struct attribute *, | |
f2f0e013 | 1173 | struct dwarf2_cu **); |
c906108c | 1174 | |
348e048f DE |
1175 | static struct die_info *follow_die_sig (struct die_info *, |
1176 | struct attribute *, | |
1177 | struct dwarf2_cu **); | |
1178 | ||
6c83ed52 TT |
1179 | static struct signatured_type *lookup_signatured_type_at_offset |
1180 | (struct objfile *objfile, | |
1181 | struct dwarf2_section_info *section, | |
1182 | unsigned int offset); | |
1183 | ||
e5fe5e75 | 1184 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1185 | |
a0f42c21 | 1186 | static void read_signatured_type (struct signatured_type *type_sig); |
348e048f | 1187 | |
c906108c SS |
1188 | /* memory allocation interface */ |
1189 | ||
7b5a2f43 | 1190 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1191 | |
f3dd6933 | 1192 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1193 | |
b60c80d6 | 1194 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1195 | |
2e276125 | 1196 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1197 | char *, bfd *, struct dwarf2_cu *, |
1198 | struct dwarf2_section_info *, | |
1199 | int); | |
2e276125 | 1200 | |
8e19ed76 PS |
1201 | static int attr_form_is_block (struct attribute *); |
1202 | ||
3690dd37 JB |
1203 | static int attr_form_is_section_offset (struct attribute *); |
1204 | ||
1205 | static int attr_form_is_constant (struct attribute *); | |
1206 | ||
8cf6f0b1 TT |
1207 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1208 | struct dwarf2_loclist_baton *baton, | |
1209 | struct attribute *attr); | |
1210 | ||
93e7bd98 DJ |
1211 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1212 | struct symbol *sym, | |
1213 | struct dwarf2_cu *cu); | |
4c2df51b | 1214 | |
93311388 DE |
1215 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1216 | struct abbrev_info *abbrev, | |
1217 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1218 | |
72bf9492 DJ |
1219 | static void free_stack_comp_unit (void *); |
1220 | ||
72bf9492 DJ |
1221 | static hashval_t partial_die_hash (const void *item); |
1222 | ||
1223 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1224 | ||
ae038cb0 | 1225 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1226 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1227 | |
9816fde3 | 1228 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1229 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1230 | |
1231 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1232 | struct die_info *comp_unit_die); | |
93311388 | 1233 | |
68dc6402 | 1234 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1235 | |
1236 | static void free_cached_comp_units (void *); | |
1237 | ||
1238 | static void age_cached_comp_units (void); | |
1239 | ||
1240 | static void free_one_cached_comp_unit (void *); | |
1241 | ||
f792889a DJ |
1242 | static struct type *set_die_type (struct die_info *, struct type *, |
1243 | struct dwarf2_cu *); | |
1c379e20 | 1244 | |
ae038cb0 DJ |
1245 | static void create_all_comp_units (struct objfile *); |
1246 | ||
1fd400ff TT |
1247 | static int create_debug_types_hash_table (struct objfile *objfile); |
1248 | ||
a0f42c21 | 1249 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
10b3939b DJ |
1250 | |
1251 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1252 | ||
1253 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1254 | struct dwarf2_per_cu_data *); | |
1255 | ||
ae038cb0 DJ |
1256 | static void dwarf2_mark (struct dwarf2_cu *); |
1257 | ||
1258 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1259 | ||
673bfd45 DE |
1260 | static struct type *get_die_type_at_offset (unsigned int, |
1261 | struct dwarf2_per_cu_data *per_cu); | |
1262 | ||
f792889a | 1263 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1264 | |
9291a0cd TT |
1265 | static void dwarf2_release_queue (void *dummy); |
1266 | ||
a0f42c21 | 1267 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
9291a0cd | 1268 | |
a0f42c21 | 1269 | static void process_queue (void); |
9291a0cd TT |
1270 | |
1271 | static void find_file_and_directory (struct die_info *die, | |
1272 | struct dwarf2_cu *cu, | |
1273 | char **name, char **comp_dir); | |
1274 | ||
1275 | static char *file_full_name (int file, struct line_header *lh, | |
1276 | const char *comp_dir); | |
1277 | ||
9ff913ba DE |
1278 | static gdb_byte *read_and_check_comp_unit_head |
1279 | (struct comp_unit_head *header, | |
1280 | struct dwarf2_section_info *section, gdb_byte *info_ptr, | |
1281 | int is_debug_types_section); | |
9291a0cd TT |
1282 | |
1283 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1284 | struct dwarf2_cu *cu); | |
1285 | ||
673bfd45 | 1286 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1287 | |
9291a0cd TT |
1288 | #if WORDS_BIGENDIAN |
1289 | ||
1290 | /* Convert VALUE between big- and little-endian. */ | |
1291 | static offset_type | |
1292 | byte_swap (offset_type value) | |
1293 | { | |
1294 | offset_type result; | |
1295 | ||
1296 | result = (value & 0xff) << 24; | |
1297 | result |= (value & 0xff00) << 8; | |
1298 | result |= (value & 0xff0000) >> 8; | |
1299 | result |= (value & 0xff000000) >> 24; | |
1300 | return result; | |
1301 | } | |
1302 | ||
1303 | #define MAYBE_SWAP(V) byte_swap (V) | |
1304 | ||
1305 | #else | |
1306 | #define MAYBE_SWAP(V) (V) | |
1307 | #endif /* WORDS_BIGENDIAN */ | |
1308 | ||
1309 | /* The suffix for an index file. */ | |
1310 | #define INDEX_SUFFIX ".gdb-index" | |
1311 | ||
3da10d80 KS |
1312 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1313 | struct dwarf2_cu *cu); | |
1314 | ||
c906108c | 1315 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1316 | information and return true if we have enough to do something. |
1317 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1318 | ELF names are used. */ | |
c906108c SS |
1319 | |
1320 | int | |
251d32d9 TG |
1321 | dwarf2_has_info (struct objfile *objfile, |
1322 | const struct dwarf2_debug_sections *names) | |
c906108c | 1323 | { |
be391dca TT |
1324 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1325 | if (!dwarf2_per_objfile) | |
1326 | { | |
1327 | /* Initialize per-objfile state. */ | |
1328 | struct dwarf2_per_objfile *data | |
1329 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1330 | |
be391dca TT |
1331 | memset (data, 0, sizeof (*data)); |
1332 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1333 | dwarf2_per_objfile = data; | |
6502dd73 | 1334 | |
251d32d9 TG |
1335 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1336 | (void *) names); | |
be391dca TT |
1337 | dwarf2_per_objfile->objfile = objfile; |
1338 | } | |
1339 | return (dwarf2_per_objfile->info.asection != NULL | |
1340 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1341 | } |
1342 | ||
251d32d9 TG |
1343 | /* When loading sections, we look either for uncompressed section or for |
1344 | compressed section names. */ | |
233a11ab CS |
1345 | |
1346 | static int | |
251d32d9 TG |
1347 | section_is_p (const char *section_name, |
1348 | const struct dwarf2_section_names *names) | |
233a11ab | 1349 | { |
251d32d9 TG |
1350 | if (names->normal != NULL |
1351 | && strcmp (section_name, names->normal) == 0) | |
1352 | return 1; | |
1353 | if (names->compressed != NULL | |
1354 | && strcmp (section_name, names->compressed) == 0) | |
1355 | return 1; | |
1356 | return 0; | |
233a11ab CS |
1357 | } |
1358 | ||
c906108c SS |
1359 | /* This function is mapped across the sections and remembers the |
1360 | offset and size of each of the debugging sections we are interested | |
1361 | in. */ | |
1362 | ||
1363 | static void | |
251d32d9 | 1364 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1365 | { |
251d32d9 TG |
1366 | const struct dwarf2_debug_sections *names; |
1367 | ||
1368 | if (vnames == NULL) | |
1369 | names = &dwarf2_elf_names; | |
1370 | else | |
1371 | names = (const struct dwarf2_debug_sections *) vnames; | |
1372 | ||
1373 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1374 | { |
dce234bc PP |
1375 | dwarf2_per_objfile->info.asection = sectp; |
1376 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1377 | } |
251d32d9 | 1378 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1379 | { |
dce234bc PP |
1380 | dwarf2_per_objfile->abbrev.asection = sectp; |
1381 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1382 | } |
251d32d9 | 1383 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1384 | { |
dce234bc PP |
1385 | dwarf2_per_objfile->line.asection = sectp; |
1386 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1387 | } |
251d32d9 | 1388 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1389 | { |
dce234bc PP |
1390 | dwarf2_per_objfile->loc.asection = sectp; |
1391 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1392 | } |
251d32d9 | 1393 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1394 | { |
dce234bc PP |
1395 | dwarf2_per_objfile->macinfo.asection = sectp; |
1396 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1397 | } |
cf2c3c16 TT |
1398 | else if (section_is_p (sectp->name, &names->macro)) |
1399 | { | |
1400 | dwarf2_per_objfile->macro.asection = sectp; | |
1401 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1402 | } | |
251d32d9 | 1403 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1404 | { |
dce234bc PP |
1405 | dwarf2_per_objfile->str.asection = sectp; |
1406 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1407 | } |
251d32d9 | 1408 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1409 | { |
dce234bc PP |
1410 | dwarf2_per_objfile->frame.asection = sectp; |
1411 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1412 | } |
251d32d9 | 1413 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1414 | { |
3799ccc6 | 1415 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1416 | |
3799ccc6 EZ |
1417 | if (aflag & SEC_HAS_CONTENTS) |
1418 | { | |
dce234bc PP |
1419 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1420 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1421 | } |
b6af0555 | 1422 | } |
251d32d9 | 1423 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1424 | { |
dce234bc PP |
1425 | dwarf2_per_objfile->ranges.asection = sectp; |
1426 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1427 | } |
251d32d9 | 1428 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1429 | { |
8b70b953 TT |
1430 | struct dwarf2_section_info type_section; |
1431 | ||
1432 | memset (&type_section, 0, sizeof (type_section)); | |
1433 | type_section.asection = sectp; | |
1434 | type_section.size = bfd_get_section_size (sectp); | |
1435 | ||
1436 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1437 | &type_section); | |
348e048f | 1438 | } |
251d32d9 | 1439 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1440 | { |
1441 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1442 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1443 | } | |
dce234bc | 1444 | |
72dca2f5 FR |
1445 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1446 | && bfd_section_vma (abfd, sectp) == 0) | |
1447 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1448 | } |
1449 | ||
dce234bc PP |
1450 | /* Decompress a section that was compressed using zlib. Store the |
1451 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1452 | |
1453 | static void | |
dce234bc PP |
1454 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1455 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1456 | { | |
1457 | bfd *abfd = objfile->obfd; | |
1458 | #ifndef HAVE_ZLIB_H | |
1459 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1460 | "is disabled in this copy of GDB"), | |
1461 | bfd_get_filename (abfd)); | |
1462 | #else | |
1463 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1464 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1465 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1466 | bfd_size_type uncompressed_size; |
1467 | gdb_byte *uncompressed_buffer; | |
1468 | z_stream strm; | |
1469 | int rc; | |
1470 | int header_size = 12; | |
1471 | ||
1472 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1473 | || bfd_bread (compressed_buffer, |
1474 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1475 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1476 | bfd_get_filename (abfd)); | |
1477 | ||
1478 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1479 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1480 | if (compressed_size < header_size | |
1481 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1482 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1483 | bfd_get_filename (abfd)); | |
1484 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1485 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1486 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1487 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1488 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1489 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1490 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1491 | uncompressed_size += compressed_buffer[11]; | |
1492 | ||
1493 | /* It is possible the section consists of several compressed | |
1494 | buffers concatenated together, so we uncompress in a loop. */ | |
1495 | strm.zalloc = NULL; | |
1496 | strm.zfree = NULL; | |
1497 | strm.opaque = NULL; | |
1498 | strm.avail_in = compressed_size - header_size; | |
1499 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1500 | strm.avail_out = uncompressed_size; | |
1501 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1502 | uncompressed_size); | |
1503 | rc = inflateInit (&strm); | |
1504 | while (strm.avail_in > 0) | |
1505 | { | |
1506 | if (rc != Z_OK) | |
1507 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1508 | bfd_get_filename (abfd), rc); | |
1509 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1510 | + (uncompressed_size - strm.avail_out)); | |
1511 | rc = inflate (&strm, Z_FINISH); | |
1512 | if (rc != Z_STREAM_END) | |
1513 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1514 | bfd_get_filename (abfd), rc); | |
1515 | rc = inflateReset (&strm); | |
1516 | } | |
1517 | rc = inflateEnd (&strm); | |
1518 | if (rc != Z_OK | |
1519 | || strm.avail_out != 0) | |
1520 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1521 | bfd_get_filename (abfd), rc); | |
1522 | ||
affddf13 | 1523 | do_cleanups (cleanup); |
dce234bc PP |
1524 | *outbuf = uncompressed_buffer; |
1525 | *outsize = uncompressed_size; | |
1526 | #endif | |
233a11ab CS |
1527 | } |
1528 | ||
9e0ac564 TT |
1529 | /* A helper function that decides whether a section is empty. */ |
1530 | ||
1531 | static int | |
1532 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1533 | { | |
1534 | return info->asection == NULL || info->size == 0; | |
1535 | } | |
1536 | ||
9cdd5dbd | 1537 | /* Read the contents of the section INFO from object file specified by |
dce234bc PP |
1538 | OBJFILE, store info about the section into INFO. |
1539 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1540 | |
dce234bc PP |
1541 | static void |
1542 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1543 | { |
dce234bc PP |
1544 | bfd *abfd = objfile->obfd; |
1545 | asection *sectp = info->asection; | |
1546 | gdb_byte *buf, *retbuf; | |
1547 | unsigned char header[4]; | |
c906108c | 1548 | |
be391dca TT |
1549 | if (info->readin) |
1550 | return; | |
dce234bc | 1551 | info->buffer = NULL; |
b315ab21 | 1552 | info->map_addr = NULL; |
be391dca | 1553 | info->readin = 1; |
188dd5d6 | 1554 | |
9e0ac564 | 1555 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1556 | return; |
c906108c | 1557 | |
dce234bc PP |
1558 | /* Check if the file has a 4-byte header indicating compression. */ |
1559 | if (info->size > sizeof (header) | |
1560 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1561 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1562 | { | |
1563 | /* Upon decompression, update the buffer and its size. */ | |
1564 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1565 | { | |
1566 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1567 | &info->size); | |
1568 | return; | |
1569 | } | |
1570 | } | |
4bdf3d34 | 1571 | |
dce234bc PP |
1572 | #ifdef HAVE_MMAP |
1573 | if (pagesize == 0) | |
1574 | pagesize = getpagesize (); | |
2e276125 | 1575 | |
dce234bc PP |
1576 | /* Only try to mmap sections which are large enough: we don't want to |
1577 | waste space due to fragmentation. Also, only try mmap for sections | |
1578 | without relocations. */ | |
1579 | ||
1580 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1581 | { | |
b315ab21 TG |
1582 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1583 | MAP_PRIVATE, sectp->filepos, | |
1584 | &info->map_addr, &info->map_len); | |
dce234bc | 1585 | |
b315ab21 | 1586 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1587 | { |
be391dca | 1588 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1589 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1590 | #endif |
dce234bc PP |
1591 | return; |
1592 | } | |
1593 | } | |
1594 | #endif | |
1595 | ||
1596 | /* If we get here, we are a normal, not-compressed section. */ | |
1597 | info->buffer = buf | |
1598 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1599 | ||
1600 | /* When debugging .o files, we may need to apply relocations; see | |
1601 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1602 | We never compress sections in .o files, so we only need to | |
1603 | try this when the section is not compressed. */ | |
ac8035ab | 1604 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1605 | if (retbuf != NULL) |
1606 | { | |
1607 | info->buffer = retbuf; | |
1608 | return; | |
1609 | } | |
1610 | ||
1611 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1612 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1613 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1614 | bfd_get_filename (abfd)); | |
1615 | } | |
1616 | ||
9e0ac564 TT |
1617 | /* A helper function that returns the size of a section in a safe way. |
1618 | If you are positive that the section has been read before using the | |
1619 | size, then it is safe to refer to the dwarf2_section_info object's | |
1620 | "size" field directly. In other cases, you must call this | |
1621 | function, because for compressed sections the size field is not set | |
1622 | correctly until the section has been read. */ | |
1623 | ||
1624 | static bfd_size_type | |
1625 | dwarf2_section_size (struct objfile *objfile, | |
1626 | struct dwarf2_section_info *info) | |
1627 | { | |
1628 | if (!info->readin) | |
1629 | dwarf2_read_section (objfile, info); | |
1630 | return info->size; | |
1631 | } | |
1632 | ||
dce234bc | 1633 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1634 | SECTION_NAME. */ |
af34e669 | 1635 | |
dce234bc | 1636 | void |
3017a003 TG |
1637 | dwarf2_get_section_info (struct objfile *objfile, |
1638 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1639 | asection **sectp, gdb_byte **bufp, |
1640 | bfd_size_type *sizep) | |
1641 | { | |
1642 | struct dwarf2_per_objfile *data | |
1643 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1644 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1645 | |
1646 | /* We may see an objfile without any DWARF, in which case we just | |
1647 | return nothing. */ | |
1648 | if (data == NULL) | |
1649 | { | |
1650 | *sectp = NULL; | |
1651 | *bufp = NULL; | |
1652 | *sizep = 0; | |
1653 | return; | |
1654 | } | |
3017a003 TG |
1655 | switch (sect) |
1656 | { | |
1657 | case DWARF2_DEBUG_FRAME: | |
1658 | info = &data->frame; | |
1659 | break; | |
1660 | case DWARF2_EH_FRAME: | |
1661 | info = &data->eh_frame; | |
1662 | break; | |
1663 | default: | |
1664 | gdb_assert_not_reached ("unexpected section"); | |
1665 | } | |
dce234bc | 1666 | |
9e0ac564 | 1667 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1668 | |
1669 | *sectp = info->asection; | |
1670 | *bufp = info->buffer; | |
1671 | *sizep = info->size; | |
1672 | } | |
1673 | ||
9291a0cd | 1674 | \f |
7b9f3c50 DE |
1675 | /* DWARF quick_symbols_functions support. */ |
1676 | ||
1677 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1678 | unique line tables, so we maintain a separate table of all .debug_line | |
1679 | derived entries to support the sharing. | |
1680 | All the quick functions need is the list of file names. We discard the | |
1681 | line_header when we're done and don't need to record it here. */ | |
1682 | struct quick_file_names | |
1683 | { | |
1684 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1685 | unsigned int offset; | |
1686 | ||
1687 | /* The number of entries in file_names, real_names. */ | |
1688 | unsigned int num_file_names; | |
1689 | ||
1690 | /* The file names from the line table, after being run through | |
1691 | file_full_name. */ | |
1692 | const char **file_names; | |
1693 | ||
1694 | /* The file names from the line table after being run through | |
1695 | gdb_realpath. These are computed lazily. */ | |
1696 | const char **real_names; | |
1697 | }; | |
1698 | ||
1699 | /* When using the index (and thus not using psymtabs), each CU has an | |
1700 | object of this type. This is used to hold information needed by | |
1701 | the various "quick" methods. */ | |
1702 | struct dwarf2_per_cu_quick_data | |
1703 | { | |
1704 | /* The file table. This can be NULL if there was no file table | |
1705 | or it's currently not read in. | |
1706 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1707 | struct quick_file_names *file_names; | |
1708 | ||
1709 | /* The corresponding symbol table. This is NULL if symbols for this | |
1710 | CU have not yet been read. */ | |
1711 | struct symtab *symtab; | |
1712 | ||
1713 | /* A temporary mark bit used when iterating over all CUs in | |
1714 | expand_symtabs_matching. */ | |
1715 | unsigned int mark : 1; | |
1716 | ||
1717 | /* True if we've tried to read the file table and found there isn't one. | |
1718 | There will be no point in trying to read it again next time. */ | |
1719 | unsigned int no_file_data : 1; | |
1720 | }; | |
1721 | ||
1722 | /* Hash function for a quick_file_names. */ | |
1723 | ||
1724 | static hashval_t | |
1725 | hash_file_name_entry (const void *e) | |
1726 | { | |
1727 | const struct quick_file_names *file_data = e; | |
1728 | ||
1729 | return file_data->offset; | |
1730 | } | |
1731 | ||
1732 | /* Equality function for a quick_file_names. */ | |
1733 | ||
1734 | static int | |
1735 | eq_file_name_entry (const void *a, const void *b) | |
1736 | { | |
1737 | const struct quick_file_names *ea = a; | |
1738 | const struct quick_file_names *eb = b; | |
1739 | ||
1740 | return ea->offset == eb->offset; | |
1741 | } | |
1742 | ||
1743 | /* Delete function for a quick_file_names. */ | |
1744 | ||
1745 | static void | |
1746 | delete_file_name_entry (void *e) | |
1747 | { | |
1748 | struct quick_file_names *file_data = e; | |
1749 | int i; | |
1750 | ||
1751 | for (i = 0; i < file_data->num_file_names; ++i) | |
1752 | { | |
1753 | xfree ((void*) file_data->file_names[i]); | |
1754 | if (file_data->real_names) | |
1755 | xfree ((void*) file_data->real_names[i]); | |
1756 | } | |
1757 | ||
1758 | /* The space for the struct itself lives on objfile_obstack, | |
1759 | so we don't free it here. */ | |
1760 | } | |
1761 | ||
1762 | /* Create a quick_file_names hash table. */ | |
1763 | ||
1764 | static htab_t | |
1765 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1766 | { | |
1767 | return htab_create_alloc (nr_initial_entries, | |
1768 | hash_file_name_entry, eq_file_name_entry, | |
1769 | delete_file_name_entry, xcalloc, xfree); | |
1770 | } | |
9291a0cd | 1771 | |
918dd910 JK |
1772 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1773 | have to be created afterwards. You should call age_cached_comp_units after | |
1774 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1775 | ||
1776 | static void | |
1777 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1778 | { | |
b0df02fd | 1779 | if (per_cu->debug_types_section) |
e5fe5e75 | 1780 | load_full_type_unit (per_cu); |
918dd910 | 1781 | else |
a0f42c21 | 1782 | load_full_comp_unit (per_cu); |
918dd910 | 1783 | |
918dd910 | 1784 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
1785 | |
1786 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
1787 | } |
1788 | ||
a0f42c21 | 1789 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 1790 | |
9291a0cd | 1791 | static void |
a0f42c21 | 1792 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1793 | { |
1794 | struct cleanup *back_to; | |
1795 | ||
1796 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1797 | ||
a0f42c21 | 1798 | queue_comp_unit (per_cu); |
9291a0cd | 1799 | |
918dd910 | 1800 | load_cu (per_cu); |
9291a0cd | 1801 | |
a0f42c21 | 1802 | process_queue (); |
9291a0cd TT |
1803 | |
1804 | /* Age the cache, releasing compilation units that have not | |
1805 | been used recently. */ | |
1806 | age_cached_comp_units (); | |
1807 | ||
1808 | do_cleanups (back_to); | |
1809 | } | |
1810 | ||
1811 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1812 | the objfile from which this CU came. Returns the resulting symbol | |
1813 | table. */ | |
2fdf6df6 | 1814 | |
9291a0cd | 1815 | static struct symtab * |
a0f42c21 | 1816 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1817 | { |
1818 | if (!per_cu->v.quick->symtab) | |
1819 | { | |
1820 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1821 | increment_reading_symtab (); | |
a0f42c21 | 1822 | dw2_do_instantiate_symtab (per_cu); |
9291a0cd TT |
1823 | do_cleanups (back_to); |
1824 | } | |
1825 | return per_cu->v.quick->symtab; | |
1826 | } | |
1827 | ||
1fd400ff | 1828 | /* Return the CU given its index. */ |
2fdf6df6 | 1829 | |
1fd400ff TT |
1830 | static struct dwarf2_per_cu_data * |
1831 | dw2_get_cu (int index) | |
1832 | { | |
1833 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1834 | { | |
1835 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 1836 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
1837 | } |
1838 | return dwarf2_per_objfile->all_comp_units[index]; | |
1839 | } | |
1840 | ||
9291a0cd TT |
1841 | /* A helper function that knows how to read a 64-bit value in a way |
1842 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1843 | otherwise. */ | |
2fdf6df6 | 1844 | |
9291a0cd TT |
1845 | static int |
1846 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1847 | { | |
1848 | if (sizeof (ULONGEST) < 8) | |
1849 | { | |
1850 | int i; | |
1851 | ||
1852 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1853 | for (i = 0; i < 4; ++i) | |
1854 | if (bytes[i + 4] != 0) | |
1855 | return 0; | |
1856 | ||
1857 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1858 | } | |
1859 | else | |
1860 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1861 | return 1; | |
1862 | } | |
1863 | ||
1864 | /* Read the CU list from the mapped index, and use it to create all | |
1865 | the CU objects for this objfile. Return 0 if something went wrong, | |
1866 | 1 if everything went ok. */ | |
2fdf6df6 | 1867 | |
9291a0cd | 1868 | static int |
1fd400ff TT |
1869 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1870 | offset_type cu_list_elements) | |
9291a0cd TT |
1871 | { |
1872 | offset_type i; | |
9291a0cd TT |
1873 | |
1874 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1875 | dwarf2_per_objfile->all_comp_units | |
1876 | = obstack_alloc (&objfile->objfile_obstack, | |
1877 | dwarf2_per_objfile->n_comp_units | |
1878 | * sizeof (struct dwarf2_per_cu_data *)); | |
1879 | ||
1880 | for (i = 0; i < cu_list_elements; i += 2) | |
1881 | { | |
1882 | struct dwarf2_per_cu_data *the_cu; | |
1883 | ULONGEST offset, length; | |
1884 | ||
1885 | if (!extract_cu_value (cu_list, &offset) | |
1886 | || !extract_cu_value (cu_list + 8, &length)) | |
1887 | return 0; | |
1888 | cu_list += 2 * 8; | |
1889 | ||
1890 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1891 | struct dwarf2_per_cu_data); | |
1892 | the_cu->offset = offset; | |
1893 | the_cu->length = length; | |
1894 | the_cu->objfile = objfile; | |
1895 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1896 | struct dwarf2_per_cu_quick_data); | |
1897 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1898 | } | |
1899 | ||
1900 | return 1; | |
1901 | } | |
1902 | ||
1fd400ff | 1903 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1904 | |
1fd400ff | 1905 | static int |
673bfd45 | 1906 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 1907 | struct dwarf2_section_info *section, |
673bfd45 DE |
1908 | const gdb_byte *bytes, |
1909 | offset_type elements) | |
1fd400ff TT |
1910 | { |
1911 | offset_type i; | |
673bfd45 | 1912 | htab_t sig_types_hash; |
1fd400ff | 1913 | |
d467dd73 DE |
1914 | dwarf2_per_objfile->n_type_units = elements / 3; |
1915 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 1916 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 1917 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
1918 | * sizeof (struct dwarf2_per_cu_data *)); |
1919 | ||
673bfd45 | 1920 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1921 | |
1922 | for (i = 0; i < elements; i += 3) | |
1923 | { | |
1924 | struct signatured_type *type_sig; | |
1925 | ULONGEST offset, type_offset, signature; | |
1926 | void **slot; | |
1927 | ||
1928 | if (!extract_cu_value (bytes, &offset) | |
1929 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1930 | return 0; | |
1931 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1932 | bytes += 3 * 8; | |
1933 | ||
1934 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1935 | struct signatured_type); | |
1936 | type_sig->signature = signature; | |
1fd400ff | 1937 | type_sig->type_offset = type_offset; |
b0df02fd | 1938 | type_sig->per_cu.debug_types_section = section; |
1fd400ff TT |
1939 | type_sig->per_cu.offset = offset; |
1940 | type_sig->per_cu.objfile = objfile; | |
1941 | type_sig->per_cu.v.quick | |
1942 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1943 | struct dwarf2_per_cu_quick_data); | |
1944 | ||
673bfd45 | 1945 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1946 | *slot = type_sig; |
1947 | ||
d467dd73 | 1948 | dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu; |
1fd400ff TT |
1949 | } |
1950 | ||
673bfd45 | 1951 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1952 | |
1953 | return 1; | |
1954 | } | |
1955 | ||
9291a0cd TT |
1956 | /* Read the address map data from the mapped index, and use it to |
1957 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1958 | |
9291a0cd TT |
1959 | static void |
1960 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1961 | { | |
1962 | const gdb_byte *iter, *end; | |
1963 | struct obstack temp_obstack; | |
1964 | struct addrmap *mutable_map; | |
1965 | struct cleanup *cleanup; | |
1966 | CORE_ADDR baseaddr; | |
1967 | ||
1968 | obstack_init (&temp_obstack); | |
1969 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1970 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1971 | ||
1972 | iter = index->address_table; | |
1973 | end = iter + index->address_table_size; | |
1974 | ||
1975 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1976 | ||
1977 | while (iter < end) | |
1978 | { | |
1979 | ULONGEST hi, lo, cu_index; | |
1980 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1981 | iter += 8; | |
1982 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1983 | iter += 8; | |
1984 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1985 | iter += 4; | |
1986 | ||
1987 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1988 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1989 | } |
1990 | ||
1991 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1992 | &objfile->objfile_obstack); | |
1993 | do_cleanups (cleanup); | |
1994 | } | |
1995 | ||
59d7bcaf JK |
1996 | /* The hash function for strings in the mapped index. This is the same as |
1997 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
1998 | implementation. This is necessary because the hash function is tied to the | |
1999 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
2000 | SYMBOL_HASH_NEXT. |
2001 | ||
2002 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2003 | |
9291a0cd | 2004 | static hashval_t |
559a7a62 | 2005 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2006 | { |
2007 | const unsigned char *str = (const unsigned char *) p; | |
2008 | hashval_t r = 0; | |
2009 | unsigned char c; | |
2010 | ||
2011 | while ((c = *str++) != 0) | |
559a7a62 JK |
2012 | { |
2013 | if (index_version >= 5) | |
2014 | c = tolower (c); | |
2015 | r = r * 67 + c - 113; | |
2016 | } | |
9291a0cd TT |
2017 | |
2018 | return r; | |
2019 | } | |
2020 | ||
2021 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2022 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2023 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2024 | |
9291a0cd TT |
2025 | static int |
2026 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2027 | offset_type **vec_out) | |
2028 | { | |
0cf03b49 JK |
2029 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2030 | offset_type hash; | |
9291a0cd | 2031 | offset_type slot, step; |
559a7a62 | 2032 | int (*cmp) (const char *, const char *); |
9291a0cd | 2033 | |
0cf03b49 JK |
2034 | if (current_language->la_language == language_cplus |
2035 | || current_language->la_language == language_java | |
2036 | || current_language->la_language == language_fortran) | |
2037 | { | |
2038 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2039 | not contain any. */ | |
2040 | const char *paren = strchr (name, '('); | |
2041 | ||
2042 | if (paren) | |
2043 | { | |
2044 | char *dup; | |
2045 | ||
2046 | dup = xmalloc (paren - name + 1); | |
2047 | memcpy (dup, name, paren - name); | |
2048 | dup[paren - name] = 0; | |
2049 | ||
2050 | make_cleanup (xfree, dup); | |
2051 | name = dup; | |
2052 | } | |
2053 | } | |
2054 | ||
559a7a62 JK |
2055 | /* Index version 4 did not support case insensitive searches. But the |
2056 | indexes for case insensitive languages are built in lowercase, therefore | |
2057 | simulate our NAME being searched is also lowercased. */ | |
2058 | hash = mapped_index_string_hash ((index->version == 4 | |
2059 | && case_sensitivity == case_sensitive_off | |
2060 | ? 5 : index->version), | |
2061 | name); | |
2062 | ||
3876f04e DE |
2063 | slot = hash & (index->symbol_table_slots - 1); |
2064 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2065 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2066 | |
2067 | for (;;) | |
2068 | { | |
2069 | /* Convert a slot number to an offset into the table. */ | |
2070 | offset_type i = 2 * slot; | |
2071 | const char *str; | |
3876f04e | 2072 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2073 | { |
2074 | do_cleanups (back_to); | |
2075 | return 0; | |
2076 | } | |
9291a0cd | 2077 | |
3876f04e | 2078 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2079 | if (!cmp (name, str)) |
9291a0cd TT |
2080 | { |
2081 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2082 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2083 | do_cleanups (back_to); |
9291a0cd TT |
2084 | return 1; |
2085 | } | |
2086 | ||
3876f04e | 2087 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2088 | } |
2089 | } | |
2090 | ||
2091 | /* Read the index file. If everything went ok, initialize the "quick" | |
2092 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2093 | |
9291a0cd TT |
2094 | static int |
2095 | dwarf2_read_index (struct objfile *objfile) | |
2096 | { | |
9291a0cd TT |
2097 | char *addr; |
2098 | struct mapped_index *map; | |
b3b272e1 | 2099 | offset_type *metadata; |
ac0b195c KW |
2100 | const gdb_byte *cu_list; |
2101 | const gdb_byte *types_list = NULL; | |
2102 | offset_type version, cu_list_elements; | |
2103 | offset_type types_list_elements = 0; | |
1fd400ff | 2104 | int i; |
9291a0cd | 2105 | |
9e0ac564 | 2106 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2107 | return 0; |
82430852 JK |
2108 | |
2109 | /* Older elfutils strip versions could keep the section in the main | |
2110 | executable while splitting it for the separate debug info file. */ | |
2111 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2112 | & SEC_HAS_CONTENTS) == 0) | |
2113 | return 0; | |
2114 | ||
9291a0cd TT |
2115 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2116 | ||
2117 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2118 | /* Version check. */ | |
1fd400ff | 2119 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2120 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2121 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2122 | contained incomplete addrmap. So, it seems better to just ignore such |
559a7a62 JK |
2123 | indices. Index version 4 uses a different hash function than index |
2124 | version 5 and later. */ | |
831adc1f | 2125 | if (version < 4) |
9291a0cd | 2126 | return 0; |
594e8718 JK |
2127 | /* Indexes with higher version than the one supported by GDB may be no |
2128 | longer backward compatible. */ | |
559a7a62 | 2129 | if (version > 5) |
594e8718 | 2130 | return 0; |
9291a0cd TT |
2131 | |
2132 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2133 | map->version = version; |
b3b272e1 | 2134 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2135 | |
2136 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2137 | |
2138 | i = 0; | |
2139 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2140 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2141 | / 8); |
1fd400ff TT |
2142 | ++i; |
2143 | ||
987d643c TT |
2144 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2145 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2146 | - MAYBE_SWAP (metadata[i])) | |
2147 | / 8); | |
2148 | ++i; | |
1fd400ff TT |
2149 | |
2150 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2151 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2152 | - MAYBE_SWAP (metadata[i])); | |
2153 | ++i; | |
2154 | ||
3876f04e DE |
2155 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2156 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2157 | - MAYBE_SWAP (metadata[i])) | |
2158 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2159 | ++i; |
9291a0cd | 2160 | |
1fd400ff TT |
2161 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2162 | ||
2163 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2164 | return 0; | |
2165 | ||
8b70b953 TT |
2166 | if (types_list_elements) |
2167 | { | |
2168 | struct dwarf2_section_info *section; | |
2169 | ||
2170 | /* We can only handle a single .debug_types when we have an | |
2171 | index. */ | |
2172 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2173 | return 0; | |
2174 | ||
2175 | section = VEC_index (dwarf2_section_info_def, | |
2176 | dwarf2_per_objfile->types, 0); | |
2177 | ||
2178 | if (!create_signatured_type_table_from_index (objfile, section, | |
2179 | types_list, | |
2180 | types_list_elements)) | |
2181 | return 0; | |
2182 | } | |
9291a0cd TT |
2183 | |
2184 | create_addrmap_from_index (objfile, map); | |
2185 | ||
2186 | dwarf2_per_objfile->index_table = map; | |
2187 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2188 | dwarf2_per_objfile->quick_file_names_table = |
2189 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2190 | |
2191 | return 1; | |
2192 | } | |
2193 | ||
2194 | /* A helper for the "quick" functions which sets the global | |
2195 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2196 | |
9291a0cd TT |
2197 | static void |
2198 | dw2_setup (struct objfile *objfile) | |
2199 | { | |
2200 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2201 | gdb_assert (dwarf2_per_objfile); | |
2202 | } | |
2203 | ||
2204 | /* A helper for the "quick" functions which attempts to read the line | |
2205 | table for THIS_CU. */ | |
2fdf6df6 | 2206 | |
7b9f3c50 DE |
2207 | static struct quick_file_names * |
2208 | dw2_get_file_names (struct objfile *objfile, | |
2209 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2210 | { |
2211 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2212 | struct line_header *lh; |
9291a0cd TT |
2213 | struct attribute *attr; |
2214 | struct cleanup *cleanups; | |
2215 | struct die_info *comp_unit_die; | |
36374493 | 2216 | struct dwarf2_section_info* sec; |
9ff913ba | 2217 | gdb_byte *info_ptr; |
9291a0cd TT |
2218 | int has_children, i; |
2219 | struct dwarf2_cu cu; | |
9ff913ba | 2220 | unsigned int bytes_read; |
9291a0cd TT |
2221 | struct die_reader_specs reader_specs; |
2222 | char *name, *comp_dir; | |
7b9f3c50 DE |
2223 | void **slot; |
2224 | struct quick_file_names *qfn; | |
2225 | unsigned int line_offset; | |
9291a0cd | 2226 | |
7b9f3c50 DE |
2227 | if (this_cu->v.quick->file_names != NULL) |
2228 | return this_cu->v.quick->file_names; | |
2229 | /* If we know there is no line data, no point in looking again. */ | |
2230 | if (this_cu->v.quick->no_file_data) | |
2231 | return NULL; | |
9291a0cd | 2232 | |
23745b47 | 2233 | init_one_comp_unit (&cu, this_cu); |
9291a0cd TT |
2234 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2235 | ||
b0df02fd DE |
2236 | if (this_cu->debug_types_section) |
2237 | sec = this_cu->debug_types_section; | |
36374493 DE |
2238 | else |
2239 | sec = &dwarf2_per_objfile->info; | |
2240 | dwarf2_read_section (objfile, sec); | |
9ff913ba | 2241 | info_ptr = sec->buffer + this_cu->offset; |
9291a0cd | 2242 | |
9ff913ba DE |
2243 | info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr, |
2244 | this_cu->debug_types_section != NULL); | |
9291a0cd | 2245 | |
6caca83c | 2246 | /* Skip dummy compilation units. */ |
9ff913ba | 2247 | if (info_ptr >= (sec->buffer + sec->size) |
6caca83c CC |
2248 | || peek_abbrev_code (abfd, info_ptr) == 0) |
2249 | { | |
2250 | do_cleanups (cleanups); | |
2251 | return NULL; | |
2252 | } | |
2253 | ||
e5fe5e75 | 2254 | dwarf2_read_abbrevs (&cu); |
9291a0cd TT |
2255 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
2256 | ||
9291a0cd | 2257 | init_cu_die_reader (&reader_specs, &cu); |
e8e80198 MS |
2258 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2259 | &has_children); | |
9291a0cd | 2260 | |
7b9f3c50 DE |
2261 | lh = NULL; |
2262 | slot = NULL; | |
2263 | line_offset = 0; | |
9291a0cd TT |
2264 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2265 | if (attr) | |
2266 | { | |
7b9f3c50 DE |
2267 | struct quick_file_names find_entry; |
2268 | ||
2269 | line_offset = DW_UNSND (attr); | |
2270 | ||
2271 | /* We may have already read in this line header (TU line header sharing). | |
2272 | If we have we're done. */ | |
2273 | find_entry.offset = line_offset; | |
2274 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2275 | &find_entry, INSERT); | |
2276 | if (*slot != NULL) | |
2277 | { | |
2278 | do_cleanups (cleanups); | |
2279 | this_cu->v.quick->file_names = *slot; | |
2280 | return *slot; | |
2281 | } | |
2282 | ||
9291a0cd TT |
2283 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2284 | } | |
2285 | if (lh == NULL) | |
2286 | { | |
2287 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2288 | this_cu->v.quick->no_file_data = 1; |
2289 | return NULL; | |
9291a0cd TT |
2290 | } |
2291 | ||
7b9f3c50 DE |
2292 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2293 | qfn->offset = line_offset; | |
2294 | gdb_assert (slot != NULL); | |
2295 | *slot = qfn; | |
9291a0cd | 2296 | |
7b9f3c50 | 2297 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2298 | |
7b9f3c50 DE |
2299 | qfn->num_file_names = lh->num_file_names; |
2300 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2301 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2302 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2303 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2304 | qfn->real_names = NULL; | |
9291a0cd | 2305 | |
7b9f3c50 | 2306 | free_line_header (lh); |
9291a0cd | 2307 | do_cleanups (cleanups); |
7b9f3c50 DE |
2308 | |
2309 | this_cu->v.quick->file_names = qfn; | |
2310 | return qfn; | |
9291a0cd TT |
2311 | } |
2312 | ||
2313 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2314 | real path for a given file name from the line table. */ |
2fdf6df6 | 2315 | |
9291a0cd | 2316 | static const char * |
7b9f3c50 DE |
2317 | dw2_get_real_path (struct objfile *objfile, |
2318 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2319 | { |
7b9f3c50 DE |
2320 | if (qfn->real_names == NULL) |
2321 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2322 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2323 | |
7b9f3c50 DE |
2324 | if (qfn->real_names[index] == NULL) |
2325 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2326 | |
7b9f3c50 | 2327 | return qfn->real_names[index]; |
9291a0cd TT |
2328 | } |
2329 | ||
2330 | static struct symtab * | |
2331 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2332 | { | |
2333 | int index; | |
ae2de4f8 | 2334 | |
9291a0cd TT |
2335 | dw2_setup (objfile); |
2336 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2337 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2338 | } |
2339 | ||
7b9f3c50 DE |
2340 | /* Traversal function for dw2_forget_cached_source_info. */ |
2341 | ||
2342 | static int | |
2343 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2344 | { |
7b9f3c50 | 2345 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2346 | |
7b9f3c50 | 2347 | if (file_data->real_names) |
9291a0cd | 2348 | { |
7b9f3c50 | 2349 | int i; |
9291a0cd | 2350 | |
7b9f3c50 | 2351 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2352 | { |
7b9f3c50 DE |
2353 | xfree ((void*) file_data->real_names[i]); |
2354 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2355 | } |
2356 | } | |
7b9f3c50 DE |
2357 | |
2358 | return 1; | |
2359 | } | |
2360 | ||
2361 | static void | |
2362 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2363 | { | |
2364 | dw2_setup (objfile); | |
2365 | ||
2366 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2367 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2368 | } |
2369 | ||
f8eba3c6 TT |
2370 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2371 | the symtabs and calls the iterator. */ | |
2372 | ||
2373 | static int | |
2374 | dw2_map_expand_apply (struct objfile *objfile, | |
2375 | struct dwarf2_per_cu_data *per_cu, | |
2376 | const char *name, | |
2377 | const char *full_path, const char *real_path, | |
2378 | int (*callback) (struct symtab *, void *), | |
2379 | void *data) | |
2380 | { | |
2381 | struct symtab *last_made = objfile->symtabs; | |
2382 | ||
2383 | /* Don't visit already-expanded CUs. */ | |
2384 | if (per_cu->v.quick->symtab) | |
2385 | return 0; | |
2386 | ||
2387 | /* This may expand more than one symtab, and we want to iterate over | |
2388 | all of them. */ | |
a0f42c21 | 2389 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2390 | |
2391 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2392 | objfile->symtabs, last_made); | |
2393 | } | |
2394 | ||
2395 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2396 | ||
9291a0cd | 2397 | static int |
f8eba3c6 TT |
2398 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2399 | const char *full_path, const char *real_path, | |
2400 | int (*callback) (struct symtab *, void *), | |
2401 | void *data) | |
9291a0cd TT |
2402 | { |
2403 | int i; | |
c011a4f4 DE |
2404 | const char *name_basename = lbasename (name); |
2405 | int check_basename = name_basename == name; | |
9291a0cd TT |
2406 | struct dwarf2_per_cu_data *base_cu = NULL; |
2407 | ||
2408 | dw2_setup (objfile); | |
ae2de4f8 | 2409 | |
1fd400ff | 2410 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2411 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2412 | { |
2413 | int j; | |
e254ef6a | 2414 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2415 | struct quick_file_names *file_data; |
9291a0cd | 2416 | |
3d7bb9d9 | 2417 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2418 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2419 | continue; |
2420 | ||
7b9f3c50 DE |
2421 | file_data = dw2_get_file_names (objfile, per_cu); |
2422 | if (file_data == NULL) | |
9291a0cd TT |
2423 | continue; |
2424 | ||
7b9f3c50 | 2425 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2426 | { |
7b9f3c50 | 2427 | const char *this_name = file_data->file_names[j]; |
9291a0cd TT |
2428 | |
2429 | if (FILENAME_CMP (name, this_name) == 0) | |
2430 | { | |
f8eba3c6 TT |
2431 | if (dw2_map_expand_apply (objfile, per_cu, |
2432 | name, full_path, real_path, | |
2433 | callback, data)) | |
2434 | return 1; | |
9291a0cd TT |
2435 | } |
2436 | ||
2437 | if (check_basename && ! base_cu | |
2438 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2439 | base_cu = per_cu; |
9291a0cd | 2440 | |
c011a4f4 DE |
2441 | /* Before we invoke realpath, which can get expensive when many |
2442 | files are involved, do a quick comparison of the basenames. */ | |
2443 | if (! basenames_may_differ | |
2444 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2445 | continue; | |
2446 | ||
9291a0cd TT |
2447 | if (full_path != NULL) |
2448 | { | |
7b9f3c50 DE |
2449 | const char *this_real_name = dw2_get_real_path (objfile, |
2450 | file_data, j); | |
9291a0cd | 2451 | |
7b9f3c50 DE |
2452 | if (this_real_name != NULL |
2453 | && FILENAME_CMP (full_path, this_real_name) == 0) | |
9291a0cd | 2454 | { |
f8eba3c6 TT |
2455 | if (dw2_map_expand_apply (objfile, per_cu, |
2456 | name, full_path, real_path, | |
2457 | callback, data)) | |
2458 | return 1; | |
9291a0cd TT |
2459 | } |
2460 | } | |
2461 | ||
2462 | if (real_path != NULL) | |
2463 | { | |
7b9f3c50 DE |
2464 | const char *this_real_name = dw2_get_real_path (objfile, |
2465 | file_data, j); | |
9291a0cd | 2466 | |
7b9f3c50 DE |
2467 | if (this_real_name != NULL |
2468 | && FILENAME_CMP (real_path, this_real_name) == 0) | |
9291a0cd | 2469 | { |
f8eba3c6 TT |
2470 | if (dw2_map_expand_apply (objfile, per_cu, |
2471 | name, full_path, real_path, | |
2472 | callback, data)) | |
2473 | return 1; | |
9291a0cd TT |
2474 | } |
2475 | } | |
2476 | } | |
2477 | } | |
2478 | ||
2479 | if (base_cu) | |
2480 | { | |
f8eba3c6 TT |
2481 | if (dw2_map_expand_apply (objfile, base_cu, |
2482 | name, full_path, real_path, | |
2483 | callback, data)) | |
2484 | return 1; | |
9291a0cd TT |
2485 | } |
2486 | ||
2487 | return 0; | |
2488 | } | |
2489 | ||
2490 | static struct symtab * | |
2491 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2492 | const char *name, domain_enum domain) | |
2493 | { | |
774b6a14 | 2494 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2495 | instead. */ |
2496 | return NULL; | |
2497 | } | |
2498 | ||
2499 | /* A helper function that expands all symtabs that hold an object | |
2500 | named NAME. */ | |
2fdf6df6 | 2501 | |
9291a0cd TT |
2502 | static void |
2503 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2504 | { | |
2505 | dw2_setup (objfile); | |
2506 | ||
ae2de4f8 | 2507 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2508 | if (dwarf2_per_objfile->index_table) |
2509 | { | |
2510 | offset_type *vec; | |
2511 | ||
2512 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2513 | name, &vec)) | |
2514 | { | |
2515 | offset_type i, len = MAYBE_SWAP (*vec); | |
2516 | for (i = 0; i < len; ++i) | |
2517 | { | |
2518 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2519 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2520 | |
a0f42c21 | 2521 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2522 | } |
2523 | } | |
2524 | } | |
2525 | } | |
2526 | ||
774b6a14 TT |
2527 | static void |
2528 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2529 | enum block_enum block_kind, const char *name, |
774b6a14 | 2530 | domain_enum domain) |
9291a0cd | 2531 | { |
774b6a14 | 2532 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2533 | } |
2534 | ||
2535 | static void | |
2536 | dw2_print_stats (struct objfile *objfile) | |
2537 | { | |
2538 | int i, count; | |
2539 | ||
2540 | dw2_setup (objfile); | |
2541 | count = 0; | |
1fd400ff | 2542 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2543 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2544 | { |
e254ef6a | 2545 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2546 | |
e254ef6a | 2547 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2548 | ++count; |
2549 | } | |
2550 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2551 | } | |
2552 | ||
2553 | static void | |
2554 | dw2_dump (struct objfile *objfile) | |
2555 | { | |
2556 | /* Nothing worth printing. */ | |
2557 | } | |
2558 | ||
2559 | static void | |
2560 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2561 | struct section_offsets *delta) | |
2562 | { | |
2563 | /* There's nothing to relocate here. */ | |
2564 | } | |
2565 | ||
2566 | static void | |
2567 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2568 | const char *func_name) | |
2569 | { | |
2570 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2571 | } | |
2572 | ||
2573 | static void | |
2574 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2575 | { | |
2576 | int i; | |
2577 | ||
2578 | dw2_setup (objfile); | |
1fd400ff TT |
2579 | |
2580 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2581 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2582 | { |
e254ef6a | 2583 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2584 | |
a0f42c21 | 2585 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2586 | } |
2587 | } | |
2588 | ||
2589 | static void | |
2590 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2591 | const char *filename) | |
2592 | { | |
2593 | int i; | |
2594 | ||
2595 | dw2_setup (objfile); | |
d4637a04 DE |
2596 | |
2597 | /* We don't need to consider type units here. | |
2598 | This is only called for examining code, e.g. expand_line_sal. | |
2599 | There can be an order of magnitude (or more) more type units | |
2600 | than comp units, and we avoid them if we can. */ | |
2601 | ||
2602 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2603 | { |
2604 | int j; | |
e254ef6a | 2605 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2606 | struct quick_file_names *file_data; |
9291a0cd | 2607 | |
3d7bb9d9 | 2608 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2609 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2610 | continue; |
2611 | ||
7b9f3c50 DE |
2612 | file_data = dw2_get_file_names (objfile, per_cu); |
2613 | if (file_data == NULL) | |
9291a0cd TT |
2614 | continue; |
2615 | ||
7b9f3c50 | 2616 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2617 | { |
7b9f3c50 | 2618 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2619 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2620 | { |
a0f42c21 | 2621 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2622 | break; |
2623 | } | |
2624 | } | |
2625 | } | |
2626 | } | |
2627 | ||
dd786858 | 2628 | static const char * |
9291a0cd TT |
2629 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2630 | { | |
e254ef6a | 2631 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2632 | offset_type *vec; |
7b9f3c50 | 2633 | struct quick_file_names *file_data; |
9291a0cd TT |
2634 | |
2635 | dw2_setup (objfile); | |
2636 | ||
ae2de4f8 | 2637 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2638 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2639 | { |
2640 | struct symtab *s; | |
2641 | ||
2642 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2643 | if (s->primary) | |
2644 | { | |
2645 | struct blockvector *bv = BLOCKVECTOR (s); | |
2646 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2647 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2648 | ||
2649 | if (sym) | |
2650 | return sym->symtab->filename; | |
2651 | } | |
2652 | return NULL; | |
2653 | } | |
9291a0cd TT |
2654 | |
2655 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2656 | name, &vec)) | |
2657 | return NULL; | |
2658 | ||
2659 | /* Note that this just looks at the very first one named NAME -- but | |
2660 | actually we are looking for a function. find_main_filename | |
2661 | should be rewritten so that it doesn't require a custom hook. It | |
2662 | could just use the ordinary symbol tables. */ | |
2663 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2664 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2665 | |
7b9f3c50 DE |
2666 | file_data = dw2_get_file_names (objfile, per_cu); |
2667 | if (file_data == NULL) | |
9291a0cd TT |
2668 | return NULL; |
2669 | ||
7b9f3c50 | 2670 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2671 | } |
2672 | ||
2673 | static void | |
40658b94 PH |
2674 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2675 | struct objfile *objfile, int global, | |
2676 | int (*callback) (struct block *, | |
2677 | struct symbol *, void *), | |
2edb89d3 JK |
2678 | void *data, symbol_compare_ftype *match, |
2679 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2680 | { |
40658b94 | 2681 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2682 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2683 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2684 | } |
2685 | ||
2686 | static void | |
f8eba3c6 TT |
2687 | dw2_expand_symtabs_matching |
2688 | (struct objfile *objfile, | |
2689 | int (*file_matcher) (const char *, void *), | |
2690 | int (*name_matcher) (const struct language_defn *, const char *, void *), | |
2691 | enum search_domain kind, | |
2692 | void *data) | |
9291a0cd TT |
2693 | { |
2694 | int i; | |
2695 | offset_type iter; | |
4b5246aa | 2696 | struct mapped_index *index; |
9291a0cd TT |
2697 | |
2698 | dw2_setup (objfile); | |
ae2de4f8 DE |
2699 | |
2700 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2701 | if (!dwarf2_per_objfile->index_table) |
2702 | return; | |
4b5246aa | 2703 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2704 | |
7b08b9eb JK |
2705 | if (file_matcher != NULL) |
2706 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2707 | + dwarf2_per_objfile->n_type_units); ++i) |
7b08b9eb JK |
2708 | { |
2709 | int j; | |
2710 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2711 | struct quick_file_names *file_data; | |
2712 | ||
2713 | per_cu->v.quick->mark = 0; | |
3d7bb9d9 DE |
2714 | |
2715 | /* We only need to look at symtabs not already expanded. */ | |
7b08b9eb JK |
2716 | if (per_cu->v.quick->symtab) |
2717 | continue; | |
2718 | ||
2719 | file_data = dw2_get_file_names (objfile, per_cu); | |
2720 | if (file_data == NULL) | |
2721 | continue; | |
2722 | ||
2723 | for (j = 0; j < file_data->num_file_names; ++j) | |
2724 | { | |
2725 | if (file_matcher (file_data->file_names[j], data)) | |
2726 | { | |
2727 | per_cu->v.quick->mark = 1; | |
2728 | break; | |
2729 | } | |
2730 | } | |
2731 | } | |
9291a0cd | 2732 | |
3876f04e | 2733 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2734 | { |
2735 | offset_type idx = 2 * iter; | |
2736 | const char *name; | |
2737 | offset_type *vec, vec_len, vec_idx; | |
2738 | ||
3876f04e | 2739 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2740 | continue; |
2741 | ||
3876f04e | 2742 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 2743 | |
f8eba3c6 | 2744 | if (! (*name_matcher) (current_language, name, data)) |
9291a0cd TT |
2745 | continue; |
2746 | ||
2747 | /* The name was matched, now expand corresponding CUs that were | |
2748 | marked. */ | |
4b5246aa | 2749 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2750 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2751 | vec_len = MAYBE_SWAP (vec[0]); |
2752 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2753 | { | |
e254ef6a | 2754 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2755 | |
e254ef6a | 2756 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2757 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 2758 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2759 | } |
2760 | } | |
2761 | } | |
2762 | ||
2763 | static struct symtab * | |
2764 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2765 | struct minimal_symbol *msymbol, | |
2766 | CORE_ADDR pc, | |
2767 | struct obj_section *section, | |
2768 | int warn_if_readin) | |
2769 | { | |
2770 | struct dwarf2_per_cu_data *data; | |
2771 | ||
2772 | dw2_setup (objfile); | |
2773 | ||
2774 | if (!objfile->psymtabs_addrmap) | |
2775 | return NULL; | |
2776 | ||
2777 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2778 | if (!data) | |
2779 | return NULL; | |
2780 | ||
2781 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2782 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2783 | paddress (get_objfile_arch (objfile), pc)); |
2784 | ||
a0f42c21 | 2785 | return dw2_instantiate_symtab (data); |
9291a0cd TT |
2786 | } |
2787 | ||
9291a0cd | 2788 | static void |
44b13c5a | 2789 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 2790 | void *data, int need_fullname) |
9291a0cd TT |
2791 | { |
2792 | int i; | |
2793 | ||
2794 | dw2_setup (objfile); | |
ae2de4f8 | 2795 | |
1fd400ff | 2796 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2797 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2798 | { |
2799 | int j; | |
e254ef6a | 2800 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2801 | struct quick_file_names *file_data; |
9291a0cd | 2802 | |
3d7bb9d9 | 2803 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2804 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2805 | continue; |
2806 | ||
7b9f3c50 DE |
2807 | file_data = dw2_get_file_names (objfile, per_cu); |
2808 | if (file_data == NULL) | |
9291a0cd TT |
2809 | continue; |
2810 | ||
7b9f3c50 | 2811 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2812 | { |
74e2f255 DE |
2813 | const char *this_real_name; |
2814 | ||
2815 | if (need_fullname) | |
2816 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
2817 | else | |
2818 | this_real_name = NULL; | |
7b9f3c50 | 2819 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
2820 | } |
2821 | } | |
2822 | } | |
2823 | ||
2824 | static int | |
2825 | dw2_has_symbols (struct objfile *objfile) | |
2826 | { | |
2827 | return 1; | |
2828 | } | |
2829 | ||
2830 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2831 | { | |
2832 | dw2_has_symbols, | |
2833 | dw2_find_last_source_symtab, | |
2834 | dw2_forget_cached_source_info, | |
f8eba3c6 | 2835 | dw2_map_symtabs_matching_filename, |
9291a0cd | 2836 | dw2_lookup_symbol, |
774b6a14 | 2837 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2838 | dw2_print_stats, |
2839 | dw2_dump, | |
2840 | dw2_relocate, | |
2841 | dw2_expand_symtabs_for_function, | |
2842 | dw2_expand_all_symtabs, | |
2843 | dw2_expand_symtabs_with_filename, | |
2844 | dw2_find_symbol_file, | |
40658b94 | 2845 | dw2_map_matching_symbols, |
9291a0cd TT |
2846 | dw2_expand_symtabs_matching, |
2847 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2848 | dw2_map_symbol_filenames |
2849 | }; | |
2850 | ||
2851 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2852 | file will use psymtabs, or 1 if using the GNU index. */ | |
2853 | ||
2854 | int | |
2855 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2856 | { | |
2857 | /* If we're about to read full symbols, don't bother with the | |
2858 | indices. In this case we also don't care if some other debug | |
2859 | format is making psymtabs, because they are all about to be | |
2860 | expanded anyway. */ | |
2861 | if ((objfile->flags & OBJF_READNOW)) | |
2862 | { | |
2863 | int i; | |
2864 | ||
2865 | dwarf2_per_objfile->using_index = 1; | |
2866 | create_all_comp_units (objfile); | |
1fd400ff | 2867 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2868 | dwarf2_per_objfile->quick_file_names_table = |
2869 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2870 | |
1fd400ff | 2871 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2872 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2873 | { |
e254ef6a | 2874 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2875 | |
e254ef6a DE |
2876 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2877 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2878 | } |
2879 | ||
2880 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2881 | these functions will be no-ops because we will have expanded | |
2882 | all symtabs. */ | |
2883 | return 1; | |
2884 | } | |
2885 | ||
2886 | if (dwarf2_read_index (objfile)) | |
2887 | return 1; | |
2888 | ||
9291a0cd TT |
2889 | return 0; |
2890 | } | |
2891 | ||
2892 | \f | |
2893 | ||
dce234bc PP |
2894 | /* Build a partial symbol table. */ |
2895 | ||
2896 | void | |
f29dff0a | 2897 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2898 | { |
f29dff0a | 2899 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2900 | { |
2901 | init_psymbol_list (objfile, 1024); | |
2902 | } | |
2903 | ||
d146bf1e | 2904 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2905 | } |
c906108c | 2906 | |
45452591 DE |
2907 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2908 | ||
2909 | static inline int | |
2910 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2911 | { | |
2912 | unsigned int bottom = cu_header->offset; | |
2913 | unsigned int top = (cu_header->offset | |
2914 | + cu_header->length | |
2915 | + cu_header->initial_length_size); | |
9a619af0 | 2916 | |
45452591 DE |
2917 | return (offset >= bottom && offset < top); |
2918 | } | |
2919 | ||
93311388 DE |
2920 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2921 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2922 | by the caller. */ | |
107d2387 | 2923 | |
fe1b8b76 | 2924 | static gdb_byte * |
107d2387 | 2925 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2926 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2927 | { |
2928 | int signed_addr; | |
891d2f0b | 2929 | unsigned int bytes_read; |
c764a876 DE |
2930 | |
2931 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2932 | cu_header->initial_length_size = bytes_read; | |
2933 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2934 | info_ptr += bytes_read; |
107d2387 AC |
2935 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2936 | info_ptr += 2; | |
613e1657 | 2937 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2938 | &bytes_read); |
613e1657 | 2939 | info_ptr += bytes_read; |
107d2387 AC |
2940 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2941 | info_ptr += 1; | |
2942 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2943 | if (signed_addr < 0) | |
8e65ff28 | 2944 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2945 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2946 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2947 | |
107d2387 AC |
2948 | return info_ptr; |
2949 | } | |
2950 | ||
9ff913ba DE |
2951 | /* Subroutine of read_and_check_comp_unit_head and |
2952 | read_and_check_type_unit_head to simplify them. | |
2953 | Perform various error checking on the header. */ | |
2954 | ||
2955 | static void | |
2956 | error_check_comp_unit_head (struct comp_unit_head *header, | |
2957 | struct dwarf2_section_info *section) | |
2958 | { | |
2959 | bfd *abfd = section->asection->owner; | |
2960 | const char *filename = bfd_get_filename (abfd); | |
2961 | ||
2962 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
2963 | error (_("Dwarf Error: wrong version in compilation unit header " | |
2964 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
2965 | filename); | |
2966 | ||
2967 | if (header->abbrev_offset | |
2968 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
2969 | &dwarf2_per_objfile->abbrev)) | |
2970 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
2971 | "(offset 0x%lx + 6) [in module %s]"), | |
2972 | (long) header->abbrev_offset, (long) header->offset, | |
2973 | filename); | |
2974 | ||
2975 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
2976 | avoid potential 32-bit overflow. */ | |
2977 | if (((unsigned long) header->offset | |
2978 | + header->length + header->initial_length_size) | |
2979 | > section->size) | |
2980 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
2981 | "(offset 0x%lx + 0) [in module %s]"), | |
2982 | (long) header->length, (long) header->offset, | |
2983 | filename); | |
2984 | } | |
2985 | ||
2986 | /* Read in a CU/TU header and perform some basic error checking. | |
2987 | The contents of the header are stored in HEADER. | |
2988 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 2989 | |
fe1b8b76 | 2990 | static gdb_byte * |
9ff913ba DE |
2991 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
2992 | struct dwarf2_section_info *section, | |
2993 | gdb_byte *info_ptr, | |
2994 | int is_debug_types_section) | |
72bf9492 | 2995 | { |
fe1b8b76 | 2996 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 2997 | bfd *abfd = section->asection->owner; |
72bf9492 | 2998 | |
9ff913ba | 2999 | header->offset = beg_of_comp_unit - section->buffer; |
adabb602 | 3000 | |
72bf9492 DJ |
3001 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3002 | ||
460c1c54 CC |
3003 | /* If we're reading a type unit, skip over the signature and |
3004 | type_offset fields. */ | |
b0df02fd | 3005 | if (is_debug_types_section) |
460c1c54 CC |
3006 | info_ptr += 8 /*signature*/ + header->offset_size; |
3007 | ||
adabb602 DE |
3008 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
3009 | ||
9ff913ba | 3010 | error_check_comp_unit_head (header, section); |
72bf9492 DJ |
3011 | |
3012 | return info_ptr; | |
3013 | } | |
3014 | ||
348e048f DE |
3015 | /* Read in the types comp unit header information from .debug_types entry at |
3016 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3017 | ||
3018 | static gdb_byte * | |
9ff913ba DE |
3019 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3020 | struct dwarf2_section_info *section, | |
3021 | gdb_byte *info_ptr, | |
3022 | ULONGEST *signature, unsigned int *type_offset) | |
348e048f | 3023 | { |
9ff913ba DE |
3024 | gdb_byte *beg_of_comp_unit = info_ptr; |
3025 | bfd *abfd = section->asection->owner; | |
348e048f | 3026 | |
9ff913ba | 3027 | header->offset = beg_of_comp_unit - section->buffer; |
348e048f | 3028 | |
9ff913ba | 3029 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3030 | |
9ff913ba DE |
3031 | /* If we're reading a type unit, skip over the signature and |
3032 | type_offset fields. */ | |
3033 | if (signature != NULL) | |
3034 | *signature = read_8_bytes (abfd, info_ptr); | |
3035 | info_ptr += 8; | |
3036 | if (type_offset != NULL) | |
3037 | *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size); | |
3038 | info_ptr += header->offset_size; | |
3039 | ||
3040 | header->first_die_offset = info_ptr - beg_of_comp_unit; | |
348e048f | 3041 | |
9ff913ba DE |
3042 | error_check_comp_unit_head (header, section); |
3043 | ||
3044 | return info_ptr; | |
348e048f DE |
3045 | } |
3046 | ||
aaa75496 JB |
3047 | /* Allocate a new partial symtab for file named NAME and mark this new |
3048 | partial symtab as being an include of PST. */ | |
3049 | ||
3050 | static void | |
3051 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3052 | struct objfile *objfile) | |
3053 | { | |
3054 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3055 | ||
3056 | subpst->section_offsets = pst->section_offsets; | |
3057 | subpst->textlow = 0; | |
3058 | subpst->texthigh = 0; | |
3059 | ||
3060 | subpst->dependencies = (struct partial_symtab **) | |
3061 | obstack_alloc (&objfile->objfile_obstack, | |
3062 | sizeof (struct partial_symtab *)); | |
3063 | subpst->dependencies[0] = pst; | |
3064 | subpst->number_of_dependencies = 1; | |
3065 | ||
3066 | subpst->globals_offset = 0; | |
3067 | subpst->n_global_syms = 0; | |
3068 | subpst->statics_offset = 0; | |
3069 | subpst->n_static_syms = 0; | |
3070 | subpst->symtab = NULL; | |
3071 | subpst->read_symtab = pst->read_symtab; | |
3072 | subpst->readin = 0; | |
3073 | ||
3074 | /* No private part is necessary for include psymtabs. This property | |
3075 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3076 | the regular ones. */ |
58a9656e | 3077 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3078 | } |
3079 | ||
3080 | /* Read the Line Number Program data and extract the list of files | |
3081 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3082 | partial symtab for each of these included files. */ |
aaa75496 JB |
3083 | |
3084 | static void | |
3085 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 3086 | struct die_info *die, |
aaa75496 JB |
3087 | struct partial_symtab *pst) |
3088 | { | |
3089 | struct objfile *objfile = cu->objfile; | |
3090 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
3091 | struct line_header *lh = NULL; |
3092 | struct attribute *attr; | |
aaa75496 | 3093 | |
d85a05f0 DJ |
3094 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3095 | if (attr) | |
3096 | { | |
3097 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 3098 | |
d85a05f0 DJ |
3099 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
3100 | } | |
aaa75496 JB |
3101 | if (lh == NULL) |
3102 | return; /* No linetable, so no includes. */ | |
3103 | ||
c6da4cef DE |
3104 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
3105 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
3106 | |
3107 | free_line_header (lh); | |
3108 | } | |
3109 | ||
348e048f DE |
3110 | static hashval_t |
3111 | hash_type_signature (const void *item) | |
3112 | { | |
3113 | const struct signatured_type *type_sig = item; | |
9a619af0 | 3114 | |
348e048f DE |
3115 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
3116 | return type_sig->signature; | |
3117 | } | |
3118 | ||
3119 | static int | |
3120 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
3121 | { | |
3122 | const struct signatured_type *lhs = item_lhs; | |
3123 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3124 | |
348e048f DE |
3125 | return lhs->signature == rhs->signature; |
3126 | } | |
3127 | ||
1fd400ff TT |
3128 | /* Allocate a hash table for signatured types. */ |
3129 | ||
3130 | static htab_t | |
673bfd45 | 3131 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3132 | { |
3133 | return htab_create_alloc_ex (41, | |
3134 | hash_type_signature, | |
3135 | eq_type_signature, | |
3136 | NULL, | |
3137 | &objfile->objfile_obstack, | |
3138 | hashtab_obstack_allocate, | |
3139 | dummy_obstack_deallocate); | |
3140 | } | |
3141 | ||
d467dd73 | 3142 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3143 | |
3144 | static int | |
d467dd73 | 3145 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3146 | { |
3147 | struct signatured_type *sigt = *slot; | |
3148 | struct dwarf2_per_cu_data ***datap = datum; | |
3149 | ||
3150 | **datap = &sigt->per_cu; | |
3151 | ++*datap; | |
3152 | ||
3153 | return 1; | |
3154 | } | |
3155 | ||
d467dd73 | 3156 | /* Create the hash table of all entries in the .debug_types section(s). |
348e048f DE |
3157 | The result is zero if there is an error (e.g. missing .debug_types section), |
3158 | otherwise non-zero. */ | |
3159 | ||
3160 | static int | |
3161 | create_debug_types_hash_table (struct objfile *objfile) | |
3162 | { | |
8b70b953 | 3163 | htab_t types_htab = NULL; |
1fd400ff | 3164 | struct dwarf2_per_cu_data **iter; |
8b70b953 TT |
3165 | int ix; |
3166 | struct dwarf2_section_info *section; | |
348e048f | 3167 | |
8b70b953 | 3168 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
348e048f DE |
3169 | { |
3170 | dwarf2_per_objfile->signatured_types = NULL; | |
3171 | return 0; | |
3172 | } | |
3173 | ||
8b70b953 TT |
3174 | for (ix = 0; |
3175 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
3176 | ix, section); | |
3177 | ++ix) | |
3178 | { | |
3179 | gdb_byte *info_ptr, *end_ptr; | |
348e048f | 3180 | |
8b70b953 TT |
3181 | dwarf2_read_section (objfile, section); |
3182 | info_ptr = section->buffer; | |
348e048f | 3183 | |
8b70b953 TT |
3184 | if (info_ptr == NULL) |
3185 | continue; | |
348e048f | 3186 | |
8b70b953 TT |
3187 | if (types_htab == NULL) |
3188 | types_htab = allocate_signatured_type_table (objfile); | |
348e048f | 3189 | |
8b70b953 TT |
3190 | if (dwarf2_die_debug) |
3191 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3192 | ||
3193 | end_ptr = info_ptr + section->size; | |
3194 | while (info_ptr < end_ptr) | |
3195 | { | |
3196 | unsigned int offset; | |
8b70b953 | 3197 | unsigned int type_offset; |
8b70b953 TT |
3198 | ULONGEST signature; |
3199 | struct signatured_type *type_sig; | |
3200 | void **slot; | |
3201 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3202 | struct comp_unit_head header; |
348e048f | 3203 | |
8b70b953 | 3204 | offset = ptr - section->buffer; |
348e048f | 3205 | |
8b70b953 | 3206 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3207 | table, but we don't need anything else just yet. */ |
348e048f | 3208 | |
9ff913ba DE |
3209 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
3210 | &signature, &type_offset); | |
6caca83c CC |
3211 | |
3212 | /* Skip dummy type units. */ | |
3213 | if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0) | |
3214 | { | |
9ff913ba | 3215 | info_ptr = info_ptr + header.initial_length_size + header.length; |
6caca83c CC |
3216 | continue; |
3217 | } | |
8b70b953 TT |
3218 | |
3219 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3220 | memset (type_sig, 0, sizeof (*type_sig)); | |
3221 | type_sig->signature = signature; | |
3222 | type_sig->type_offset = type_offset; | |
3223 | type_sig->per_cu.objfile = objfile; | |
b0df02fd | 3224 | type_sig->per_cu.debug_types_section = section; |
8b70b953 TT |
3225 | type_sig->per_cu.offset = offset; |
3226 | ||
3227 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3228 | gdb_assert (slot != NULL); | |
3229 | if (*slot != NULL) | |
3230 | { | |
3231 | const struct signatured_type *dup_sig = *slot; | |
b3c8eb43 | 3232 | |
8b70b953 TT |
3233 | complaint (&symfile_complaints, |
3234 | _("debug type entry at offset 0x%x is duplicate to the " | |
3235 | "entry at offset 0x%x, signature 0x%s"), | |
3236 | offset, dup_sig->per_cu.offset, | |
3237 | phex (signature, sizeof (signature))); | |
3238 | gdb_assert (signature == dup_sig->signature); | |
3239 | } | |
3240 | *slot = type_sig; | |
348e048f | 3241 | |
8b70b953 TT |
3242 | if (dwarf2_die_debug) |
3243 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3244 | offset, phex (signature, sizeof (signature))); | |
348e048f | 3245 | |
9ff913ba | 3246 | info_ptr = info_ptr + header.initial_length_size + header.length; |
8b70b953 | 3247 | } |
348e048f DE |
3248 | } |
3249 | ||
3250 | dwarf2_per_objfile->signatured_types = types_htab; | |
3251 | ||
d467dd73 DE |
3252 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3253 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3254 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3255 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3256 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3257 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3258 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3259 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3260 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3261 | |
348e048f DE |
3262 | return 1; |
3263 | } | |
3264 | ||
3265 | /* Lookup a signature based type. | |
3266 | Returns NULL if SIG is not present in the table. */ | |
3267 | ||
3268 | static struct signatured_type * | |
3269 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3270 | { | |
3271 | struct signatured_type find_entry, *entry; | |
3272 | ||
3273 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3274 | { | |
3275 | complaint (&symfile_complaints, | |
55f1336d | 3276 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3277 | return 0; |
3278 | } | |
3279 | ||
3280 | find_entry.signature = sig; | |
3281 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3282 | return entry; | |
3283 | } | |
3284 | ||
d85a05f0 DJ |
3285 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3286 | ||
3287 | static void | |
3288 | init_cu_die_reader (struct die_reader_specs *reader, | |
3289 | struct dwarf2_cu *cu) | |
3290 | { | |
3291 | reader->abfd = cu->objfile->obfd; | |
3292 | reader->cu = cu; | |
b0df02fd | 3293 | if (cu->per_cu->debug_types_section) |
be391dca | 3294 | { |
b0df02fd DE |
3295 | gdb_assert (cu->per_cu->debug_types_section->readin); |
3296 | reader->buffer = cu->per_cu->debug_types_section->buffer; | |
be391dca | 3297 | } |
d85a05f0 | 3298 | else |
be391dca TT |
3299 | { |
3300 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3301 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3302 | } | |
d85a05f0 DJ |
3303 | } |
3304 | ||
3305 | /* Find the base address of the compilation unit for range lists and | |
3306 | location lists. It will normally be specified by DW_AT_low_pc. | |
3307 | In DWARF-3 draft 4, the base address could be overridden by | |
3308 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3309 | compilation units with discontinuous ranges. */ | |
3310 | ||
3311 | static void | |
3312 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3313 | { | |
3314 | struct attribute *attr; | |
3315 | ||
3316 | cu->base_known = 0; | |
3317 | cu->base_address = 0; | |
3318 | ||
3319 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3320 | if (attr) | |
3321 | { | |
3322 | cu->base_address = DW_ADDR (attr); | |
3323 | cu->base_known = 1; | |
3324 | } | |
3325 | else | |
3326 | { | |
3327 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3328 | if (attr) | |
3329 | { | |
3330 | cu->base_address = DW_ADDR (attr); | |
3331 | cu->base_known = 1; | |
3332 | } | |
3333 | } | |
3334 | } | |
3335 | ||
348e048f DE |
3336 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3337 | to combine the common parts. | |
21b2bd31 DE |
3338 | Process compilation unit THIS_CU for a psymtab. |
3339 | SECTION is the section the CU/TU comes from, | |
3340 | either .debug_info or .debug_types. */ | |
aaa75496 | 3341 | |
21b2bd31 | 3342 | void |
a0f42c21 | 3343 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
21b2bd31 DE |
3344 | struct dwarf2_section_info *section, |
3345 | int is_debug_types_section) | |
c906108c | 3346 | { |
a0f42c21 | 3347 | struct objfile *objfile = this_cu->objfile; |
c906108c | 3348 | bfd *abfd = objfile->obfd; |
21b2bd31 DE |
3349 | gdb_byte *buffer = section->buffer; |
3350 | gdb_byte *info_ptr = buffer + this_cu->offset; | |
3351 | unsigned int buffer_size = section->size; | |
93311388 | 3352 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3353 | struct die_info *comp_unit_die; |
c906108c | 3354 | struct partial_symtab *pst; |
5734ee8b | 3355 | CORE_ADDR baseaddr; |
93311388 DE |
3356 | struct cleanup *back_to_inner; |
3357 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3358 | int has_children, has_pc_info; |
3359 | struct attribute *attr; | |
d85a05f0 DJ |
3360 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3361 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3362 | const char *filename; |
c906108c | 3363 | |
23745b47 DE |
3364 | /* If this compilation unit was already read in, free the |
3365 | cached copy in order to read it in again. This is | |
3366 | necessary because we skipped some symbols when we first | |
3367 | read in the compilation unit (see load_partial_dies). | |
3368 | This problem could be avoided, but the benefit is | |
3369 | unclear. */ | |
3370 | if (this_cu->cu != NULL) | |
3371 | free_one_cached_comp_unit (this_cu->cu); | |
3372 | ||
3373 | /* Note that this is a pointer to our stack frame, being | |
3374 | added to a global data structure. It will be cleaned up | |
3375 | in free_stack_comp_unit when we finish with this | |
3376 | compilation unit. */ | |
3377 | init_one_comp_unit (&cu, this_cu); | |
93311388 | 3378 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3379 | |
9ff913ba DE |
3380 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, |
3381 | is_debug_types_section); | |
10b3939b | 3382 | |
6caca83c CC |
3383 | /* Skip dummy compilation units. */ |
3384 | if (info_ptr >= buffer + buffer_size | |
3385 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
3386 | { | |
6caca83c | 3387 | do_cleanups (back_to_inner); |
21b2bd31 | 3388 | return; |
6caca83c CC |
3389 | } |
3390 | ||
93311388 | 3391 | cu.list_in_scope = &file_symbols; |
af703f96 | 3392 | |
93311388 | 3393 | /* Read the abbrevs for this compilation unit into a table. */ |
e5fe5e75 | 3394 | dwarf2_read_abbrevs (&cu); |
93311388 | 3395 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
af703f96 | 3396 | |
93311388 | 3397 | /* Read the compilation unit die. */ |
d85a05f0 DJ |
3398 | init_cu_die_reader (&reader_specs, &cu); |
3399 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3400 | &has_children); | |
93311388 | 3401 | |
21b2bd31 | 3402 | if (is_debug_types_section) |
348e048f | 3403 | { |
b3c8eb43 JK |
3404 | /* LENGTH has not been set yet for type units. */ |
3405 | gdb_assert (this_cu->offset == cu.header.offset); | |
348e048f DE |
3406 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
3407 | } | |
d85a05f0 | 3408 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3409 | { |
93311388 | 3410 | do_cleanups (back_to_inner); |
21b2bd31 | 3411 | return; |
93311388 | 3412 | } |
72bf9492 | 3413 | |
9816fde3 | 3414 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3415 | |
93311388 | 3416 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3417 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3418 | if (attr == NULL || !DW_STRING (attr)) |
3419 | filename = ""; | |
3420 | else | |
3421 | filename = DW_STRING (attr); | |
93311388 | 3422 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3423 | filename, |
93311388 DE |
3424 | /* TEXTLOW and TEXTHIGH are set below. */ |
3425 | 0, | |
3426 | objfile->global_psymbols.next, | |
3427 | objfile->static_psymbols.next); | |
9750bca9 | 3428 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 3429 | |
d85a05f0 DJ |
3430 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3431 | if (attr != NULL) | |
3432 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3433 | |
e38df1d0 | 3434 | pst->read_symtab_private = this_cu; |
72bf9492 | 3435 | |
93311388 | 3436 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3437 | |
0963b4bd | 3438 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3439 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3440 | |
9291a0cd | 3441 | this_cu->v.psymtab = pst; |
c906108c | 3442 | |
d85a05f0 DJ |
3443 | dwarf2_find_base_address (comp_unit_die, &cu); |
3444 | ||
93311388 DE |
3445 | /* Possibly set the default values of LOWPC and HIGHPC from |
3446 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3447 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3448 | &best_highpc, &cu, pst); | |
3449 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3450 | /* Store the contiguous range if it is not empty; it can be empty for |
3451 | CUs with no code. */ | |
3452 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3453 | best_lowpc + baseaddr, |
3454 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3455 | |
3456 | /* Check if comp unit has_children. | |
3457 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3458 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3459 | if (has_children) |
93311388 DE |
3460 | { |
3461 | struct partial_die_info *first_die; | |
3462 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3463 | |
93311388 DE |
3464 | lowpc = ((CORE_ADDR) -1); |
3465 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3466 | |
93311388 | 3467 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3468 | |
93311388 | 3469 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3470 | ! has_pc_info, &cu); |
57c22c6c | 3471 | |
93311388 DE |
3472 | /* If we didn't find a lowpc, set it to highpc to avoid |
3473 | complaints from `maint check'. */ | |
3474 | if (lowpc == ((CORE_ADDR) -1)) | |
3475 | lowpc = highpc; | |
10b3939b | 3476 | |
93311388 DE |
3477 | /* If the compilation unit didn't have an explicit address range, |
3478 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3479 | if (! has_pc_info) |
93311388 | 3480 | { |
d85a05f0 DJ |
3481 | best_lowpc = lowpc; |
3482 | best_highpc = highpc; | |
93311388 DE |
3483 | } |
3484 | } | |
d85a05f0 DJ |
3485 | pst->textlow = best_lowpc + baseaddr; |
3486 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3487 | |
93311388 DE |
3488 | pst->n_global_syms = objfile->global_psymbols.next - |
3489 | (objfile->global_psymbols.list + pst->globals_offset); | |
3490 | pst->n_static_syms = objfile->static_psymbols.next - | |
3491 | (objfile->static_psymbols.list + pst->statics_offset); | |
3492 | sort_pst_symbols (pst); | |
c906108c | 3493 | |
21b2bd31 | 3494 | if (is_debug_types_section) |
348e048f DE |
3495 | { |
3496 | /* It's not clear we want to do anything with stmt lists here. | |
3497 | Waiting to see what gcc ultimately does. */ | |
3498 | } | |
d85a05f0 | 3499 | else |
93311388 DE |
3500 | { |
3501 | /* Get the list of files included in the current compilation unit, | |
3502 | and build a psymtab for each of them. */ | |
d85a05f0 | 3503 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3504 | } |
ae038cb0 | 3505 | |
93311388 | 3506 | do_cleanups (back_to_inner); |
93311388 | 3507 | } |
ff013f42 | 3508 | |
348e048f DE |
3509 | /* Traversal function for htab_traverse_noresize. |
3510 | Process one .debug_types comp-unit. */ | |
3511 | ||
3512 | static int | |
3513 | process_type_comp_unit (void **slot, void *info) | |
3514 | { | |
3515 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
348e048f DE |
3516 | struct dwarf2_per_cu_data *this_cu; |
3517 | ||
a0f42c21 | 3518 | gdb_assert (info == NULL); |
348e048f | 3519 | this_cu = &entry->per_cu; |
348e048f | 3520 | |
b0df02fd | 3521 | gdb_assert (this_cu->debug_types_section->readin); |
21b2bd31 | 3522 | process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1); |
348e048f DE |
3523 | |
3524 | return 1; | |
3525 | } | |
3526 | ||
3527 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3528 | Build partial symbol tables for the .debug_types comp-units. */ | |
3529 | ||
3530 | static void | |
3531 | build_type_psymtabs (struct objfile *objfile) | |
3532 | { | |
3533 | if (! create_debug_types_hash_table (objfile)) | |
3534 | return; | |
3535 | ||
3536 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
a0f42c21 | 3537 | process_type_comp_unit, NULL); |
348e048f DE |
3538 | } |
3539 | ||
60606b2c TT |
3540 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3541 | ||
3542 | static void | |
3543 | psymtabs_addrmap_cleanup (void *o) | |
3544 | { | |
3545 | struct objfile *objfile = o; | |
ec61707d | 3546 | |
60606b2c TT |
3547 | objfile->psymtabs_addrmap = NULL; |
3548 | } | |
3549 | ||
93311388 DE |
3550 | /* Build the partial symbol table by doing a quick pass through the |
3551 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3552 | |
93311388 | 3553 | static void |
c67a9c90 | 3554 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3555 | { |
60606b2c TT |
3556 | struct cleanup *back_to, *addrmap_cleanup; |
3557 | struct obstack temp_obstack; | |
21b2bd31 | 3558 | int i; |
93311388 | 3559 | |
98bfdba5 PA |
3560 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3561 | ||
be391dca | 3562 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 3563 | |
93311388 DE |
3564 | /* Any cached compilation units will be linked by the per-objfile |
3565 | read_in_chain. Make sure to free them when we're done. */ | |
3566 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3567 | |
348e048f DE |
3568 | build_type_psymtabs (objfile); |
3569 | ||
93311388 | 3570 | create_all_comp_units (objfile); |
c906108c | 3571 | |
60606b2c TT |
3572 | /* Create a temporary address map on a temporary obstack. We later |
3573 | copy this to the final obstack. */ | |
3574 | obstack_init (&temp_obstack); | |
3575 | make_cleanup_obstack_free (&temp_obstack); | |
3576 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3577 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3578 | |
21b2bd31 | 3579 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 3580 | { |
21b2bd31 | 3581 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 3582 | |
21b2bd31 | 3583 | process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0); |
c906108c | 3584 | } |
ff013f42 JK |
3585 | |
3586 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3587 | &objfile->objfile_obstack); | |
60606b2c | 3588 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3589 | |
ae038cb0 DJ |
3590 | do_cleanups (back_to); |
3591 | } | |
3592 | ||
93311388 | 3593 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3594 | |
3595 | static void | |
a0f42c21 | 3596 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) |
ae038cb0 | 3597 | { |
a0f42c21 | 3598 | struct objfile *objfile = this_cu->objfile; |
ae038cb0 | 3599 | bfd *abfd = objfile->obfd; |
adabb602 | 3600 | gdb_byte *info_ptr; |
d85a05f0 | 3601 | struct die_info *comp_unit_die; |
ae038cb0 | 3602 | struct dwarf2_cu *cu; |
1d9ec526 | 3603 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3604 | int has_children; |
3605 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3606 | int read_cu = 0; |
9ff913ba | 3607 | struct dwarf2_section_info *section = &dwarf2_per_objfile->info; |
ae038cb0 | 3608 | |
b0df02fd | 3609 | gdb_assert (! this_cu->debug_types_section); |
348e048f | 3610 | |
9ff913ba DE |
3611 | gdb_assert (section->readin); |
3612 | info_ptr = section->buffer + this_cu->offset; | |
ae038cb0 | 3613 | |
98bfdba5 PA |
3614 | if (this_cu->cu == NULL) |
3615 | { | |
9816fde3 | 3616 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 3617 | init_one_comp_unit (cu, this_cu); |
ae038cb0 | 3618 | |
98bfdba5 | 3619 | read_cu = 1; |
ae038cb0 | 3620 | |
98bfdba5 | 3621 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 3622 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
328c9494 | 3623 | |
9ff913ba DE |
3624 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr, |
3625 | 0); | |
ae038cb0 | 3626 | |
6caca83c | 3627 | /* Skip dummy compilation units. */ |
9ff913ba | 3628 | if (info_ptr >= (section->buffer + section->size) |
6caca83c CC |
3629 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3630 | { | |
3631 | do_cleanups (free_cu_cleanup); | |
3632 | return; | |
3633 | } | |
3634 | ||
98bfdba5 PA |
3635 | /* Link this CU into read_in_chain. */ |
3636 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3637 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3638 | } | |
3639 | else | |
3640 | { | |
3641 | cu = this_cu->cu; | |
3642 | info_ptr += cu->header.first_die_offset; | |
3643 | } | |
ae038cb0 DJ |
3644 | |
3645 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3646 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
e5fe5e75 | 3647 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 3648 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3649 | |
3650 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3651 | init_cu_die_reader (&reader_specs, cu); |
3652 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3653 | &has_children); | |
ae038cb0 | 3654 | |
9816fde3 | 3655 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3656 | |
ae038cb0 DJ |
3657 | /* Check if comp unit has_children. |
3658 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3659 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3660 | if (has_children) |
9ff913ba | 3661 | load_partial_dies (abfd, section->buffer, info_ptr, 0, cu); |
ae038cb0 | 3662 | |
98bfdba5 PA |
3663 | do_cleanups (free_abbrevs_cleanup); |
3664 | ||
3665 | if (read_cu) | |
3666 | { | |
3667 | /* We've successfully allocated this compilation unit. Let our | |
3668 | caller clean it up when finished with it. */ | |
3669 | discard_cleanups (free_cu_cleanup); | |
3670 | } | |
ae038cb0 DJ |
3671 | } |
3672 | ||
9cdd5dbd DE |
3673 | /* Create a list of all compilation units in OBJFILE. |
3674 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
3675 | |
3676 | static void | |
3677 | create_all_comp_units (struct objfile *objfile) | |
3678 | { | |
3679 | int n_allocated; | |
3680 | int n_comp_units; | |
3681 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3682 | gdb_byte *info_ptr; |
3683 | ||
3684 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3685 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3686 | |
3687 | n_comp_units = 0; | |
3688 | n_allocated = 10; | |
3689 | all_comp_units = xmalloc (n_allocated | |
3690 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3691 | |
3e43a32a MS |
3692 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3693 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3694 | { |
c764a876 | 3695 | unsigned int length, initial_length_size; |
ae038cb0 | 3696 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3697 | unsigned int offset; |
ae038cb0 | 3698 | |
dce234bc | 3699 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3700 | |
3701 | /* Read just enough information to find out where the next | |
3702 | compilation unit is. */ | |
c764a876 DE |
3703 | length = read_initial_length (objfile->obfd, info_ptr, |
3704 | &initial_length_size); | |
ae038cb0 DJ |
3705 | |
3706 | /* Save the compilation unit for later lookup. */ | |
3707 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3708 | sizeof (struct dwarf2_per_cu_data)); | |
3709 | memset (this_cu, 0, sizeof (*this_cu)); | |
3710 | this_cu->offset = offset; | |
c764a876 | 3711 | this_cu->length = length + initial_length_size; |
9291a0cd | 3712 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3713 | |
3714 | if (n_comp_units == n_allocated) | |
3715 | { | |
3716 | n_allocated *= 2; | |
3717 | all_comp_units = xrealloc (all_comp_units, | |
3718 | n_allocated | |
3719 | * sizeof (struct dwarf2_per_cu_data *)); | |
3720 | } | |
3721 | all_comp_units[n_comp_units++] = this_cu; | |
3722 | ||
3723 | info_ptr = info_ptr + this_cu->length; | |
3724 | } | |
3725 | ||
3726 | dwarf2_per_objfile->all_comp_units | |
3727 | = obstack_alloc (&objfile->objfile_obstack, | |
3728 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3729 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3730 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3731 | xfree (all_comp_units); | |
3732 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3733 | } |
3734 | ||
5734ee8b DJ |
3735 | /* Process all loaded DIEs for compilation unit CU, starting at |
3736 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3737 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3738 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3739 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3740 | and record the covered ranges in the addrmap. */ | |
c906108c | 3741 | |
72bf9492 DJ |
3742 | static void |
3743 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3744 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3745 | { |
72bf9492 | 3746 | struct partial_die_info *pdi; |
c906108c | 3747 | |
91c24f0a DC |
3748 | /* Now, march along the PDI's, descending into ones which have |
3749 | interesting children but skipping the children of the other ones, | |
3750 | until we reach the end of the compilation unit. */ | |
c906108c | 3751 | |
72bf9492 | 3752 | pdi = first_die; |
91c24f0a | 3753 | |
72bf9492 DJ |
3754 | while (pdi != NULL) |
3755 | { | |
3756 | fixup_partial_die (pdi, cu); | |
c906108c | 3757 | |
f55ee35c | 3758 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3759 | children, so we need to look at them. Ditto for anonymous |
3760 | enums. */ | |
933c6fe4 | 3761 | |
72bf9492 | 3762 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3763 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3764 | { |
72bf9492 | 3765 | switch (pdi->tag) |
c906108c SS |
3766 | { |
3767 | case DW_TAG_subprogram: | |
5734ee8b | 3768 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3769 | break; |
72929c62 | 3770 | case DW_TAG_constant: |
c906108c SS |
3771 | case DW_TAG_variable: |
3772 | case DW_TAG_typedef: | |
91c24f0a | 3773 | case DW_TAG_union_type: |
72bf9492 | 3774 | if (!pdi->is_declaration) |
63d06c5c | 3775 | { |
72bf9492 | 3776 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3777 | } |
3778 | break; | |
c906108c | 3779 | case DW_TAG_class_type: |
680b30c7 | 3780 | case DW_TAG_interface_type: |
c906108c | 3781 | case DW_TAG_structure_type: |
72bf9492 | 3782 | if (!pdi->is_declaration) |
c906108c | 3783 | { |
72bf9492 | 3784 | add_partial_symbol (pdi, cu); |
c906108c SS |
3785 | } |
3786 | break; | |
91c24f0a | 3787 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3788 | if (!pdi->is_declaration) |
3789 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3790 | break; |
3791 | case DW_TAG_base_type: | |
a02abb62 | 3792 | case DW_TAG_subrange_type: |
c906108c | 3793 | /* File scope base type definitions are added to the partial |
c5aa993b | 3794 | symbol table. */ |
72bf9492 | 3795 | add_partial_symbol (pdi, cu); |
c906108c | 3796 | break; |
d9fa45fe | 3797 | case DW_TAG_namespace: |
5734ee8b | 3798 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3799 | break; |
5d7cb8df JK |
3800 | case DW_TAG_module: |
3801 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3802 | break; | |
c906108c SS |
3803 | default: |
3804 | break; | |
3805 | } | |
3806 | } | |
3807 | ||
72bf9492 DJ |
3808 | /* If the die has a sibling, skip to the sibling. */ |
3809 | ||
3810 | pdi = pdi->die_sibling; | |
3811 | } | |
3812 | } | |
3813 | ||
3814 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3815 | |
72bf9492 | 3816 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3817 | name is concatenated with "::" and the partial DIE's name. For |
3818 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3819 | Enumerators are an exception; they use the scope of their parent |
3820 | enumeration type, i.e. the name of the enumeration type is not | |
3821 | prepended to the enumerator. | |
91c24f0a | 3822 | |
72bf9492 DJ |
3823 | There are two complexities. One is DW_AT_specification; in this |
3824 | case "parent" means the parent of the target of the specification, | |
3825 | instead of the direct parent of the DIE. The other is compilers | |
3826 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3827 | the fully qualified name of structure types from their members' | |
3828 | linkage names. This must be done using the DIE's children rather | |
3829 | than the children of any DW_AT_specification target. We only need | |
3830 | to do this for structures at the top level, i.e. if the target of | |
3831 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3832 | have a parent. */ | |
3833 | ||
3834 | /* Compute the scope prefix associated with PDI's parent, in | |
3835 | compilation unit CU. The result will be allocated on CU's | |
3836 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3837 | field. NULL is returned if no prefix is necessary. */ | |
3838 | static char * | |
3839 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3840 | struct dwarf2_cu *cu) | |
3841 | { | |
3842 | char *grandparent_scope; | |
3843 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3844 | |
72bf9492 DJ |
3845 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3846 | then this means the parent of the specification DIE. */ | |
3847 | ||
3848 | real_pdi = pdi; | |
72bf9492 | 3849 | while (real_pdi->has_specification) |
10b3939b | 3850 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3851 | |
3852 | parent = real_pdi->die_parent; | |
3853 | if (parent == NULL) | |
3854 | return NULL; | |
3855 | ||
3856 | if (parent->scope_set) | |
3857 | return parent->scope; | |
3858 | ||
3859 | fixup_partial_die (parent, cu); | |
3860 | ||
10b3939b | 3861 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3862 | |
acebe513 UW |
3863 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3864 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3865 | Work around this problem here. */ | |
3866 | if (cu->language == language_cplus | |
6e70227d | 3867 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3868 | && strcmp (parent->name, "::") == 0 |
3869 | && grandparent_scope == NULL) | |
3870 | { | |
3871 | parent->scope = NULL; | |
3872 | parent->scope_set = 1; | |
3873 | return NULL; | |
3874 | } | |
3875 | ||
9c6c53f7 SA |
3876 | if (pdi->tag == DW_TAG_enumerator) |
3877 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
3878 | parent->scope = grandparent_scope; | |
3879 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 3880 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3881 | || parent->tag == DW_TAG_structure_type |
3882 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3883 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3884 | || parent->tag == DW_TAG_union_type |
3885 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3886 | { |
3887 | if (grandparent_scope == NULL) | |
3888 | parent->scope = parent->name; | |
3889 | else | |
3e43a32a MS |
3890 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3891 | grandparent_scope, | |
f55ee35c | 3892 | parent->name, 0, cu); |
72bf9492 | 3893 | } |
72bf9492 DJ |
3894 | else |
3895 | { | |
3896 | /* FIXME drow/2004-04-01: What should we be doing with | |
3897 | function-local names? For partial symbols, we should probably be | |
3898 | ignoring them. */ | |
3899 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3900 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3901 | parent->tag, pdi->offset); |
3902 | parent->scope = grandparent_scope; | |
c906108c SS |
3903 | } |
3904 | ||
72bf9492 DJ |
3905 | parent->scope_set = 1; |
3906 | return parent->scope; | |
3907 | } | |
3908 | ||
3909 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3910 | CU. The result will be allocated with malloc. */ | |
3911 | static char * | |
3912 | partial_die_full_name (struct partial_die_info *pdi, | |
3913 | struct dwarf2_cu *cu) | |
3914 | { | |
3915 | char *parent_scope; | |
3916 | ||
98bfdba5 PA |
3917 | /* If this is a template instantiation, we can not work out the |
3918 | template arguments from partial DIEs. So, unfortunately, we have | |
3919 | to go through the full DIEs. At least any work we do building | |
3920 | types here will be reused if full symbols are loaded later. */ | |
3921 | if (pdi->has_template_arguments) | |
3922 | { | |
3923 | fixup_partial_die (pdi, cu); | |
3924 | ||
3925 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3926 | { | |
3927 | struct die_info *die; | |
3928 | struct attribute attr; | |
3929 | struct dwarf2_cu *ref_cu = cu; | |
3930 | ||
3931 | attr.name = 0; | |
3932 | attr.form = DW_FORM_ref_addr; | |
3933 | attr.u.addr = pdi->offset; | |
3934 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3935 | ||
3936 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3937 | } | |
3938 | } | |
3939 | ||
72bf9492 DJ |
3940 | parent_scope = partial_die_parent_scope (pdi, cu); |
3941 | if (parent_scope == NULL) | |
3942 | return NULL; | |
3943 | else | |
f55ee35c | 3944 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3945 | } |
3946 | ||
3947 | static void | |
72bf9492 | 3948 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3949 | { |
e7c27a73 | 3950 | struct objfile *objfile = cu->objfile; |
c906108c | 3951 | CORE_ADDR addr = 0; |
decbce07 | 3952 | char *actual_name = NULL; |
5c4e30ca | 3953 | const struct partial_symbol *psym = NULL; |
e142c38c | 3954 | CORE_ADDR baseaddr; |
72bf9492 | 3955 | int built_actual_name = 0; |
e142c38c DJ |
3956 | |
3957 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3958 | |
94af9270 KS |
3959 | actual_name = partial_die_full_name (pdi, cu); |
3960 | if (actual_name) | |
3961 | built_actual_name = 1; | |
63d06c5c | 3962 | |
72bf9492 DJ |
3963 | if (actual_name == NULL) |
3964 | actual_name = pdi->name; | |
3965 | ||
c906108c SS |
3966 | switch (pdi->tag) |
3967 | { | |
3968 | case DW_TAG_subprogram: | |
2cfa0c8d | 3969 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3970 | { |
2cfa0c8d JB |
3971 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3972 | of the global scope. But in Ada, we want to be able to access | |
3973 | nested procedures globally. So all Ada subprograms are stored | |
3974 | in the global scope. */ | |
f47fb265 | 3975 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3976 | mst_text, objfile); */ |
f47fb265 MS |
3977 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3978 | built_actual_name, | |
3979 | VAR_DOMAIN, LOC_BLOCK, | |
3980 | &objfile->global_psymbols, | |
3981 | 0, pdi->lowpc + baseaddr, | |
3982 | cu->language, objfile); | |
c906108c SS |
3983 | } |
3984 | else | |
3985 | { | |
f47fb265 | 3986 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3987 | mst_file_text, objfile); */ |
f47fb265 MS |
3988 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3989 | built_actual_name, | |
3990 | VAR_DOMAIN, LOC_BLOCK, | |
3991 | &objfile->static_psymbols, | |
3992 | 0, pdi->lowpc + baseaddr, | |
3993 | cu->language, objfile); | |
c906108c SS |
3994 | } |
3995 | break; | |
72929c62 JB |
3996 | case DW_TAG_constant: |
3997 | { | |
3998 | struct psymbol_allocation_list *list; | |
3999 | ||
4000 | if (pdi->is_external) | |
4001 | list = &objfile->global_psymbols; | |
4002 | else | |
4003 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4004 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4005 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4006 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4007 | } |
4008 | break; | |
c906108c | 4009 | case DW_TAG_variable: |
caac4577 JG |
4010 | if (pdi->locdesc) |
4011 | addr = decode_locdesc (pdi->locdesc, cu); | |
4012 | ||
4013 | if (pdi->locdesc | |
4014 | && addr == 0 | |
4015 | && !dwarf2_per_objfile->has_section_at_zero) | |
4016 | { | |
4017 | /* A global or static variable may also have been stripped | |
4018 | out by the linker if unused, in which case its address | |
4019 | will be nullified; do not add such variables into partial | |
4020 | symbol table then. */ | |
4021 | } | |
4022 | else if (pdi->is_external) | |
c906108c SS |
4023 | { |
4024 | /* Global Variable. | |
4025 | Don't enter into the minimal symbol tables as there is | |
4026 | a minimal symbol table entry from the ELF symbols already. | |
4027 | Enter into partial symbol table if it has a location | |
4028 | descriptor or a type. | |
4029 | If the location descriptor is missing, new_symbol will create | |
4030 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4031 | be determined from the minimal symbol table whenever the variable | |
4032 | is referenced. | |
4033 | The address for the partial symbol table entry is not | |
4034 | used by GDB, but it comes in handy for debugging partial symbol | |
4035 | table building. */ | |
4036 | ||
c906108c | 4037 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4038 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4039 | built_actual_name, | |
4040 | VAR_DOMAIN, LOC_STATIC, | |
4041 | &objfile->global_psymbols, | |
4042 | 0, addr + baseaddr, | |
4043 | cu->language, objfile); | |
c906108c SS |
4044 | } |
4045 | else | |
4046 | { | |
0963b4bd | 4047 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4048 | if (pdi->locdesc == NULL) |
decbce07 MS |
4049 | { |
4050 | if (built_actual_name) | |
4051 | xfree (actual_name); | |
4052 | return; | |
4053 | } | |
f47fb265 | 4054 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4055 | mst_file_data, objfile); */ |
f47fb265 MS |
4056 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4057 | built_actual_name, | |
4058 | VAR_DOMAIN, LOC_STATIC, | |
4059 | &objfile->static_psymbols, | |
4060 | 0, addr + baseaddr, | |
4061 | cu->language, objfile); | |
c906108c SS |
4062 | } |
4063 | break; | |
4064 | case DW_TAG_typedef: | |
4065 | case DW_TAG_base_type: | |
a02abb62 | 4066 | case DW_TAG_subrange_type: |
38d518c9 | 4067 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4068 | built_actual_name, |
176620f1 | 4069 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4070 | &objfile->static_psymbols, |
e142c38c | 4071 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4072 | break; |
72bf9492 DJ |
4073 | case DW_TAG_namespace: |
4074 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4075 | built_actual_name, |
72bf9492 DJ |
4076 | VAR_DOMAIN, LOC_TYPEDEF, |
4077 | &objfile->global_psymbols, | |
4078 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4079 | break; | |
c906108c | 4080 | case DW_TAG_class_type: |
680b30c7 | 4081 | case DW_TAG_interface_type: |
c906108c SS |
4082 | case DW_TAG_structure_type: |
4083 | case DW_TAG_union_type: | |
4084 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4085 | /* Skip external references. The DWARF standard says in the section |
4086 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4087 | structure, union or class type is represented by a structure, | |
4088 | union or class entry that does not have a byte size attribute | |
4089 | and that has a DW_AT_declaration attribute." */ | |
4090 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4091 | { |
4092 | if (built_actual_name) | |
4093 | xfree (actual_name); | |
4094 | return; | |
4095 | } | |
fa4028e9 | 4096 | |
63d06c5c DC |
4097 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4098 | static vs. global. */ | |
38d518c9 | 4099 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4100 | built_actual_name, |
176620f1 | 4101 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4102 | (cu->language == language_cplus |
4103 | || cu->language == language_java) | |
63d06c5c DC |
4104 | ? &objfile->global_psymbols |
4105 | : &objfile->static_psymbols, | |
e142c38c | 4106 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4107 | |
c906108c SS |
4108 | break; |
4109 | case DW_TAG_enumerator: | |
38d518c9 | 4110 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4111 | built_actual_name, |
176620f1 | 4112 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4113 | (cu->language == language_cplus |
4114 | || cu->language == language_java) | |
f6fe98ef DJ |
4115 | ? &objfile->global_psymbols |
4116 | : &objfile->static_psymbols, | |
e142c38c | 4117 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4118 | break; |
4119 | default: | |
4120 | break; | |
4121 | } | |
5c4e30ca | 4122 | |
72bf9492 DJ |
4123 | if (built_actual_name) |
4124 | xfree (actual_name); | |
c906108c SS |
4125 | } |
4126 | ||
5c4e30ca DC |
4127 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4128 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4129 | the name of the enclosing namespace. */ | |
91c24f0a | 4130 | |
72bf9492 DJ |
4131 | static void |
4132 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4133 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4134 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4135 | { |
72bf9492 | 4136 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4137 | |
72bf9492 | 4138 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4139 | |
4140 | /* Now scan partial symbols in that namespace. */ | |
4141 | ||
91c24f0a | 4142 | if (pdi->has_children) |
5734ee8b | 4143 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4144 | } |
4145 | ||
5d7cb8df JK |
4146 | /* Read a partial die corresponding to a Fortran module. */ |
4147 | ||
4148 | static void | |
4149 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4150 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4151 | { | |
f55ee35c | 4152 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4153 | |
4154 | if (pdi->has_children) | |
4155 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4156 | } | |
4157 | ||
bc30ff58 JB |
4158 | /* Read a partial die corresponding to a subprogram and create a partial |
4159 | symbol for that subprogram. When the CU language allows it, this | |
4160 | routine also defines a partial symbol for each nested subprogram | |
4161 | that this subprogram contains. | |
6e70227d | 4162 | |
bc30ff58 JB |
4163 | DIE my also be a lexical block, in which case we simply search |
4164 | recursively for suprograms defined inside that lexical block. | |
4165 | Again, this is only performed when the CU language allows this | |
4166 | type of definitions. */ | |
4167 | ||
4168 | static void | |
4169 | add_partial_subprogram (struct partial_die_info *pdi, | |
4170 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4171 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4172 | { |
4173 | if (pdi->tag == DW_TAG_subprogram) | |
4174 | { | |
4175 | if (pdi->has_pc_info) | |
4176 | { | |
4177 | if (pdi->lowpc < *lowpc) | |
4178 | *lowpc = pdi->lowpc; | |
4179 | if (pdi->highpc > *highpc) | |
4180 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4181 | if (need_pc) |
4182 | { | |
4183 | CORE_ADDR baseaddr; | |
4184 | struct objfile *objfile = cu->objfile; | |
4185 | ||
4186 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4187 | SECT_OFF_TEXT (objfile)); | |
4188 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4189 | pdi->lowpc + baseaddr, |
4190 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4191 | cu->per_cu->v.psymtab); |
5734ee8b | 4192 | } |
bc30ff58 | 4193 | if (!pdi->is_declaration) |
e8d05480 JB |
4194 | /* Ignore subprogram DIEs that do not have a name, they are |
4195 | illegal. Do not emit a complaint at this point, we will | |
4196 | do so when we convert this psymtab into a symtab. */ | |
4197 | if (pdi->name) | |
4198 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4199 | } |
4200 | } | |
6e70227d | 4201 | |
bc30ff58 JB |
4202 | if (! pdi->has_children) |
4203 | return; | |
4204 | ||
4205 | if (cu->language == language_ada) | |
4206 | { | |
4207 | pdi = pdi->die_child; | |
4208 | while (pdi != NULL) | |
4209 | { | |
4210 | fixup_partial_die (pdi, cu); | |
4211 | if (pdi->tag == DW_TAG_subprogram | |
4212 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4213 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4214 | pdi = pdi->die_sibling; |
4215 | } | |
4216 | } | |
4217 | } | |
4218 | ||
91c24f0a DC |
4219 | /* Read a partial die corresponding to an enumeration type. */ |
4220 | ||
72bf9492 DJ |
4221 | static void |
4222 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4223 | struct dwarf2_cu *cu) | |
91c24f0a | 4224 | { |
72bf9492 | 4225 | struct partial_die_info *pdi; |
91c24f0a DC |
4226 | |
4227 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4228 | add_partial_symbol (enum_pdi, cu); |
4229 | ||
4230 | pdi = enum_pdi->die_child; | |
4231 | while (pdi) | |
91c24f0a | 4232 | { |
72bf9492 | 4233 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4234 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4235 | else |
72bf9492 DJ |
4236 | add_partial_symbol (pdi, cu); |
4237 | pdi = pdi->die_sibling; | |
91c24f0a | 4238 | } |
91c24f0a DC |
4239 | } |
4240 | ||
6caca83c CC |
4241 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
4242 | ||
4243 | static unsigned int | |
4244 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
4245 | { | |
4246 | unsigned int bytes_read; | |
4247 | ||
4248 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4249 | } | |
4250 | ||
4bb7a0a7 DJ |
4251 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4252 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4253 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4254 | the initial number. */ | |
4255 | ||
4256 | static struct abbrev_info * | |
fe1b8b76 | 4257 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4258 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4259 | { |
4260 | bfd *abfd = cu->objfile->obfd; | |
4261 | unsigned int abbrev_number; | |
4262 | struct abbrev_info *abbrev; | |
4263 | ||
4264 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4265 | ||
4266 | if (abbrev_number == 0) | |
4267 | return NULL; | |
4268 | ||
4269 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4270 | if (!abbrev) | |
4271 | { | |
3e43a32a MS |
4272 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4273 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4274 | } |
4275 | ||
4276 | return abbrev; | |
4277 | } | |
4278 | ||
93311388 DE |
4279 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4280 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4281 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4282 | ||
fe1b8b76 | 4283 | static gdb_byte * |
93311388 | 4284 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4285 | { |
4286 | struct abbrev_info *abbrev; | |
4287 | unsigned int bytes_read; | |
4288 | ||
4289 | while (1) | |
4290 | { | |
4291 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4292 | if (abbrev == NULL) | |
4293 | return info_ptr + bytes_read; | |
4294 | else | |
93311388 | 4295 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4296 | } |
4297 | } | |
4298 | ||
93311388 DE |
4299 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4300 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4301 | abbrev corresponding to that skipped uleb128 should be passed in |
4302 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4303 | children. */ | |
4304 | ||
fe1b8b76 | 4305 | static gdb_byte * |
93311388 DE |
4306 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4307 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4308 | { |
4309 | unsigned int bytes_read; | |
4310 | struct attribute attr; | |
4311 | bfd *abfd = cu->objfile->obfd; | |
4312 | unsigned int form, i; | |
4313 | ||
4314 | for (i = 0; i < abbrev->num_attrs; i++) | |
4315 | { | |
4316 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4317 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4318 | { | |
4319 | read_attribute (&attr, &abbrev->attrs[i], | |
4320 | abfd, info_ptr, cu); | |
4321 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4322 | complaint (&symfile_complaints, |
4323 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4324 | else |
93311388 | 4325 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4326 | } |
4327 | ||
4328 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4329 | form = abbrev->attrs[i].form; | |
4330 | skip_attribute: | |
4331 | switch (form) | |
4332 | { | |
4bb7a0a7 | 4333 | case DW_FORM_ref_addr: |
ae411497 TT |
4334 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4335 | and later it is offset sized. */ | |
4336 | if (cu->header.version == 2) | |
4337 | info_ptr += cu->header.addr_size; | |
4338 | else | |
4339 | info_ptr += cu->header.offset_size; | |
4340 | break; | |
4341 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4342 | info_ptr += cu->header.addr_size; |
4343 | break; | |
4344 | case DW_FORM_data1: | |
4345 | case DW_FORM_ref1: | |
4346 | case DW_FORM_flag: | |
4347 | info_ptr += 1; | |
4348 | break; | |
2dc7f7b3 TT |
4349 | case DW_FORM_flag_present: |
4350 | break; | |
4bb7a0a7 DJ |
4351 | case DW_FORM_data2: |
4352 | case DW_FORM_ref2: | |
4353 | info_ptr += 2; | |
4354 | break; | |
4355 | case DW_FORM_data4: | |
4356 | case DW_FORM_ref4: | |
4357 | info_ptr += 4; | |
4358 | break; | |
4359 | case DW_FORM_data8: | |
4360 | case DW_FORM_ref8: | |
55f1336d | 4361 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4362 | info_ptr += 8; |
4363 | break; | |
4364 | case DW_FORM_string: | |
9b1c24c8 | 4365 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4366 | info_ptr += bytes_read; |
4367 | break; | |
2dc7f7b3 | 4368 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4369 | case DW_FORM_strp: |
4370 | info_ptr += cu->header.offset_size; | |
4371 | break; | |
2dc7f7b3 | 4372 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4373 | case DW_FORM_block: |
4374 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4375 | info_ptr += bytes_read; | |
4376 | break; | |
4377 | case DW_FORM_block1: | |
4378 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4379 | break; | |
4380 | case DW_FORM_block2: | |
4381 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4382 | break; | |
4383 | case DW_FORM_block4: | |
4384 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4385 | break; | |
4386 | case DW_FORM_sdata: | |
4387 | case DW_FORM_udata: | |
4388 | case DW_FORM_ref_udata: | |
4389 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4390 | break; | |
4391 | case DW_FORM_indirect: | |
4392 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4393 | info_ptr += bytes_read; | |
4394 | /* We need to continue parsing from here, so just go back to | |
4395 | the top. */ | |
4396 | goto skip_attribute; | |
4397 | ||
4398 | default: | |
3e43a32a MS |
4399 | error (_("Dwarf Error: Cannot handle %s " |
4400 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4401 | dwarf_form_name (form), |
4402 | bfd_get_filename (abfd)); | |
4403 | } | |
4404 | } | |
4405 | ||
4406 | if (abbrev->has_children) | |
93311388 | 4407 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4408 | else |
4409 | return info_ptr; | |
4410 | } | |
4411 | ||
93311388 DE |
4412 | /* Locate ORIG_PDI's sibling. |
4413 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4414 | in BUFFER. */ | |
91c24f0a | 4415 | |
fe1b8b76 | 4416 | static gdb_byte * |
93311388 DE |
4417 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4418 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4419 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4420 | { |
4421 | /* Do we know the sibling already? */ | |
72bf9492 | 4422 | |
91c24f0a DC |
4423 | if (orig_pdi->sibling) |
4424 | return orig_pdi->sibling; | |
4425 | ||
4426 | /* Are there any children to deal with? */ | |
4427 | ||
4428 | if (!orig_pdi->has_children) | |
4429 | return info_ptr; | |
4430 | ||
4bb7a0a7 | 4431 | /* Skip the children the long way. */ |
91c24f0a | 4432 | |
93311388 | 4433 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4434 | } |
4435 | ||
c906108c SS |
4436 | /* Expand this partial symbol table into a full symbol table. */ |
4437 | ||
4438 | static void | |
fba45db2 | 4439 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4440 | { |
c906108c SS |
4441 | if (pst != NULL) |
4442 | { | |
4443 | if (pst->readin) | |
4444 | { | |
3e43a32a MS |
4445 | warning (_("bug: psymtab for %s is already read in."), |
4446 | pst->filename); | |
c906108c SS |
4447 | } |
4448 | else | |
4449 | { | |
4450 | if (info_verbose) | |
4451 | { | |
3e43a32a MS |
4452 | printf_filtered (_("Reading in symbols for %s..."), |
4453 | pst->filename); | |
c906108c SS |
4454 | gdb_flush (gdb_stdout); |
4455 | } | |
4456 | ||
10b3939b DJ |
4457 | /* Restore our global data. */ |
4458 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4459 | dwarf2_objfile_data_key); | |
4460 | ||
b2ab525c KB |
4461 | /* If this psymtab is constructed from a debug-only objfile, the |
4462 | has_section_at_zero flag will not necessarily be correct. We | |
4463 | can get the correct value for this flag by looking at the data | |
4464 | associated with the (presumably stripped) associated objfile. */ | |
4465 | if (pst->objfile->separate_debug_objfile_backlink) | |
4466 | { | |
4467 | struct dwarf2_per_objfile *dpo_backlink | |
4468 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4469 | dwarf2_objfile_data_key); | |
9a619af0 | 4470 | |
b2ab525c KB |
4471 | dwarf2_per_objfile->has_section_at_zero |
4472 | = dpo_backlink->has_section_at_zero; | |
4473 | } | |
4474 | ||
98bfdba5 PA |
4475 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4476 | ||
c906108c SS |
4477 | psymtab_to_symtab_1 (pst); |
4478 | ||
4479 | /* Finish up the debug error message. */ | |
4480 | if (info_verbose) | |
a3f17187 | 4481 | printf_filtered (_("done.\n")); |
c906108c SS |
4482 | } |
4483 | } | |
4484 | } | |
9cdd5dbd DE |
4485 | \f |
4486 | /* Reading in full CUs. */ | |
c906108c | 4487 | |
10b3939b DJ |
4488 | /* Add PER_CU to the queue. */ |
4489 | ||
4490 | static void | |
a0f42c21 | 4491 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b DJ |
4492 | { |
4493 | struct dwarf2_queue_item *item; | |
4494 | ||
4495 | per_cu->queued = 1; | |
4496 | item = xmalloc (sizeof (*item)); | |
4497 | item->per_cu = per_cu; | |
4498 | item->next = NULL; | |
4499 | ||
4500 | if (dwarf2_queue == NULL) | |
4501 | dwarf2_queue = item; | |
4502 | else | |
4503 | dwarf2_queue_tail->next = item; | |
4504 | ||
4505 | dwarf2_queue_tail = item; | |
4506 | } | |
4507 | ||
4508 | /* Process the queue. */ | |
4509 | ||
4510 | static void | |
a0f42c21 | 4511 | process_queue (void) |
10b3939b DJ |
4512 | { |
4513 | struct dwarf2_queue_item *item, *next_item; | |
4514 | ||
03dd20cc DJ |
4515 | /* The queue starts out with one item, but following a DIE reference |
4516 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4517 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4518 | { | |
9291a0cd TT |
4519 | if (dwarf2_per_objfile->using_index |
4520 | ? !item->per_cu->v.quick->symtab | |
4521 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4522 | process_full_comp_unit (item->per_cu); |
4523 | ||
4524 | item->per_cu->queued = 0; | |
4525 | next_item = item->next; | |
4526 | xfree (item); | |
4527 | } | |
4528 | ||
4529 | dwarf2_queue_tail = NULL; | |
4530 | } | |
4531 | ||
4532 | /* Free all allocated queue entries. This function only releases anything if | |
4533 | an error was thrown; if the queue was processed then it would have been | |
4534 | freed as we went along. */ | |
4535 | ||
4536 | static void | |
4537 | dwarf2_release_queue (void *dummy) | |
4538 | { | |
4539 | struct dwarf2_queue_item *item, *last; | |
4540 | ||
4541 | item = dwarf2_queue; | |
4542 | while (item) | |
4543 | { | |
4544 | /* Anything still marked queued is likely to be in an | |
4545 | inconsistent state, so discard it. */ | |
4546 | if (item->per_cu->queued) | |
4547 | { | |
4548 | if (item->per_cu->cu != NULL) | |
4549 | free_one_cached_comp_unit (item->per_cu->cu); | |
4550 | item->per_cu->queued = 0; | |
4551 | } | |
4552 | ||
4553 | last = item; | |
4554 | item = item->next; | |
4555 | xfree (last); | |
4556 | } | |
4557 | ||
4558 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4559 | } | |
4560 | ||
4561 | /* Read in full symbols for PST, and anything it depends on. */ | |
4562 | ||
c906108c | 4563 | static void |
fba45db2 | 4564 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4565 | { |
10b3939b | 4566 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4567 | struct cleanup *back_to; |
aaa75496 JB |
4568 | int i; |
4569 | ||
4570 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4571 | if (!pst->dependencies[i]->readin) | |
4572 | { | |
4573 | /* Inform about additional files that need to be read in. */ | |
4574 | if (info_verbose) | |
4575 | { | |
a3f17187 | 4576 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4577 | fputs_filtered (" ", gdb_stdout); |
4578 | wrap_here (""); | |
4579 | fputs_filtered ("and ", gdb_stdout); | |
4580 | wrap_here (""); | |
4581 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4582 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4583 | gdb_flush (gdb_stdout); |
4584 | } | |
4585 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4586 | } | |
4587 | ||
e38df1d0 | 4588 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4589 | |
4590 | if (per_cu == NULL) | |
aaa75496 JB |
4591 | { |
4592 | /* It's an include file, no symbols to read for it. | |
4593 | Everything is in the parent symtab. */ | |
4594 | pst->readin = 1; | |
4595 | return; | |
4596 | } | |
c906108c | 4597 | |
a0f42c21 | 4598 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
4599 | } |
4600 | ||
93311388 | 4601 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4602 | |
93311388 | 4603 | static void |
a0f42c21 | 4604 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b | 4605 | { |
a0f42c21 | 4606 | struct objfile *objfile = per_cu->objfile; |
31ffec48 | 4607 | bfd *abfd = objfile->obfd; |
10b3939b | 4608 | struct dwarf2_cu *cu; |
c764a876 | 4609 | unsigned int offset; |
93311388 | 4610 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4611 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4612 | struct attribute *attr; |
98bfdba5 | 4613 | int read_cu = 0; |
6502dd73 | 4614 | |
b0df02fd | 4615 | gdb_assert (! per_cu->debug_types_section); |
348e048f | 4616 | |
c906108c | 4617 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4618 | offset = per_cu->offset; |
6502dd73 | 4619 | |
be391dca | 4620 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4621 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4622 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4623 | |
98bfdba5 PA |
4624 | if (per_cu->cu == NULL) |
4625 | { | |
9816fde3 | 4626 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 4627 | init_one_comp_unit (cu, per_cu); |
98bfdba5 PA |
4628 | |
4629 | read_cu = 1; | |
c906108c | 4630 | |
98bfdba5 | 4631 | /* If an error occurs while loading, release our storage. */ |
68dc6402 | 4632 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
c906108c | 4633 | |
98bfdba5 PA |
4634 | /* Read in the comp_unit header. */ |
4635 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4636 | |
6caca83c CC |
4637 | /* Skip dummy compilation units. */ |
4638 | if (info_ptr >= (dwarf2_per_objfile->info.buffer | |
4639 | + dwarf2_per_objfile->info.size) | |
4640 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
4641 | { | |
4642 | do_cleanups (free_cu_cleanup); | |
4643 | return; | |
4644 | } | |
4645 | ||
98bfdba5 PA |
4646 | /* Complete the cu_header. */ |
4647 | cu->header.offset = offset; | |
4648 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4649 | |
98bfdba5 | 4650 | /* Read the abbrevs for this compilation unit. */ |
e5fe5e75 | 4651 | dwarf2_read_abbrevs (cu); |
98bfdba5 | 4652 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
10b3939b | 4653 | |
98bfdba5 PA |
4654 | /* Link this CU into read_in_chain. */ |
4655 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4656 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4657 | } | |
4658 | else | |
4659 | { | |
4660 | cu = per_cu->cu; | |
4661 | info_ptr += cu->header.first_die_offset; | |
4662 | } | |
e142c38c | 4663 | |
93311388 | 4664 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4665 | |
4666 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 4667 | all CUs needed for references have been loaded yet, and symbol |
10b3939b DJ |
4668 | table processing isn't initialized. But we have to set the CU language, |
4669 | or we won't be able to build types correctly. */ | |
9816fde3 | 4670 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4671 | |
a6c727b2 DJ |
4672 | /* Similarly, if we do not read the producer, we can not apply |
4673 | producer-specific interpretation. */ | |
4674 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4675 | if (attr) | |
4676 | cu->producer = DW_STRING (attr); | |
4677 | ||
98bfdba5 PA |
4678 | if (read_cu) |
4679 | { | |
4680 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4681 | |
98bfdba5 PA |
4682 | /* We've successfully allocated this compilation unit. Let our |
4683 | caller clean it up when finished with it. */ | |
4684 | discard_cleanups (free_cu_cleanup); | |
4685 | } | |
10b3939b DJ |
4686 | } |
4687 | ||
3da10d80 KS |
4688 | /* Add a DIE to the delayed physname list. */ |
4689 | ||
4690 | static void | |
4691 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4692 | const char *name, struct die_info *die, | |
4693 | struct dwarf2_cu *cu) | |
4694 | { | |
4695 | struct delayed_method_info mi; | |
4696 | mi.type = type; | |
4697 | mi.fnfield_index = fnfield_index; | |
4698 | mi.index = index; | |
4699 | mi.name = name; | |
4700 | mi.die = die; | |
4701 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4702 | } | |
4703 | ||
4704 | /* A cleanup for freeing the delayed method list. */ | |
4705 | ||
4706 | static void | |
4707 | free_delayed_list (void *ptr) | |
4708 | { | |
4709 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4710 | if (cu->method_list != NULL) | |
4711 | { | |
4712 | VEC_free (delayed_method_info, cu->method_list); | |
4713 | cu->method_list = NULL; | |
4714 | } | |
4715 | } | |
4716 | ||
4717 | /* Compute the physnames of any methods on the CU's method list. | |
4718 | ||
4719 | The computation of method physnames is delayed in order to avoid the | |
4720 | (bad) condition that one of the method's formal parameters is of an as yet | |
4721 | incomplete type. */ | |
4722 | ||
4723 | static void | |
4724 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4725 | { | |
4726 | int i; | |
4727 | struct delayed_method_info *mi; | |
4728 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4729 | { | |
1d06ead6 | 4730 | const char *physname; |
3da10d80 KS |
4731 | struct fn_fieldlist *fn_flp |
4732 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4733 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4734 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4735 | } | |
4736 | } | |
4737 | ||
9cdd5dbd | 4738 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
4739 | already been loaded into memory. */ |
4740 | ||
4741 | static void | |
4742 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4743 | { | |
10b3939b | 4744 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4745 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4746 | CORE_ADDR lowpc, highpc; |
4747 | struct symtab *symtab; | |
3da10d80 | 4748 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4749 | CORE_ADDR baseaddr; |
4750 | ||
4751 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4752 | ||
10b3939b DJ |
4753 | buildsym_init (); |
4754 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4755 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4756 | |
4757 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
4758 | |
4759 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 4760 | process_die (cu->dies, cu); |
c906108c | 4761 | |
3da10d80 KS |
4762 | /* Now that we have processed all the DIEs in the CU, all the types |
4763 | should be complete, and it should now be safe to compute all of the | |
4764 | physnames. */ | |
4765 | compute_delayed_physnames (cu); | |
4766 | do_cleanups (delayed_list_cleanup); | |
4767 | ||
fae299cd DC |
4768 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4769 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4770 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4771 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4772 | |
613e1657 | 4773 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 4774 | |
8be455d7 | 4775 | if (symtab != NULL) |
c906108c | 4776 | { |
df15bd07 | 4777 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 4778 | |
8be455d7 JK |
4779 | /* Set symtab language to language from DW_AT_language. If the |
4780 | compilation is from a C file generated by language preprocessors, do | |
4781 | not set the language if it was already deduced by start_subfile. */ | |
4782 | if (!(cu->language == language_c && symtab->language != language_c)) | |
4783 | symtab->language = cu->language; | |
4784 | ||
4785 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
4786 | produce DW_AT_location with location lists but it can be possibly | |
4787 | invalid without -fvar-tracking. | |
4788 | ||
4789 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
4790 | needed, it would be wrong due to missing DW_AT_producer there. | |
4791 | ||
4792 | Still one can confuse GDB by using non-standard GCC compilation | |
4793 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
4794 | */ | |
4632c0d0 | 4795 | if (cu->has_loclist && gcc_4_minor >= 0) |
8be455d7 | 4796 | symtab->locations_valid = 1; |
e0d00bc7 JK |
4797 | |
4798 | if (gcc_4_minor >= 5) | |
4799 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
4800 | |
4801 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 4802 | } |
9291a0cd TT |
4803 | |
4804 | if (dwarf2_per_objfile->using_index) | |
4805 | per_cu->v.quick->symtab = symtab; | |
4806 | else | |
4807 | { | |
4808 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4809 | pst->symtab = symtab; | |
4810 | pst->readin = 1; | |
4811 | } | |
c906108c SS |
4812 | |
4813 | do_cleanups (back_to); | |
4814 | } | |
4815 | ||
4816 | /* Process a die and its children. */ | |
4817 | ||
4818 | static void | |
e7c27a73 | 4819 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4820 | { |
4821 | switch (die->tag) | |
4822 | { | |
4823 | case DW_TAG_padding: | |
4824 | break; | |
4825 | case DW_TAG_compile_unit: | |
e7c27a73 | 4826 | read_file_scope (die, cu); |
c906108c | 4827 | break; |
348e048f DE |
4828 | case DW_TAG_type_unit: |
4829 | read_type_unit_scope (die, cu); | |
4830 | break; | |
c906108c | 4831 | case DW_TAG_subprogram: |
c906108c | 4832 | case DW_TAG_inlined_subroutine: |
edb3359d | 4833 | read_func_scope (die, cu); |
c906108c SS |
4834 | break; |
4835 | case DW_TAG_lexical_block: | |
14898363 L |
4836 | case DW_TAG_try_block: |
4837 | case DW_TAG_catch_block: | |
e7c27a73 | 4838 | read_lexical_block_scope (die, cu); |
c906108c | 4839 | break; |
96408a79 SA |
4840 | case DW_TAG_GNU_call_site: |
4841 | read_call_site_scope (die, cu); | |
4842 | break; | |
c906108c | 4843 | case DW_TAG_class_type: |
680b30c7 | 4844 | case DW_TAG_interface_type: |
c906108c SS |
4845 | case DW_TAG_structure_type: |
4846 | case DW_TAG_union_type: | |
134d01f1 | 4847 | process_structure_scope (die, cu); |
c906108c SS |
4848 | break; |
4849 | case DW_TAG_enumeration_type: | |
134d01f1 | 4850 | process_enumeration_scope (die, cu); |
c906108c | 4851 | break; |
134d01f1 | 4852 | |
f792889a DJ |
4853 | /* These dies have a type, but processing them does not create |
4854 | a symbol or recurse to process the children. Therefore we can | |
4855 | read them on-demand through read_type_die. */ | |
c906108c | 4856 | case DW_TAG_subroutine_type: |
72019c9c | 4857 | case DW_TAG_set_type: |
c906108c | 4858 | case DW_TAG_array_type: |
c906108c | 4859 | case DW_TAG_pointer_type: |
c906108c | 4860 | case DW_TAG_ptr_to_member_type: |
c906108c | 4861 | case DW_TAG_reference_type: |
c906108c | 4862 | case DW_TAG_string_type: |
c906108c | 4863 | break; |
134d01f1 | 4864 | |
c906108c | 4865 | case DW_TAG_base_type: |
a02abb62 | 4866 | case DW_TAG_subrange_type: |
cb249c71 | 4867 | case DW_TAG_typedef: |
134d01f1 DJ |
4868 | /* Add a typedef symbol for the type definition, if it has a |
4869 | DW_AT_name. */ | |
f792889a | 4870 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4871 | break; |
c906108c | 4872 | case DW_TAG_common_block: |
e7c27a73 | 4873 | read_common_block (die, cu); |
c906108c SS |
4874 | break; |
4875 | case DW_TAG_common_inclusion: | |
4876 | break; | |
d9fa45fe | 4877 | case DW_TAG_namespace: |
63d06c5c | 4878 | processing_has_namespace_info = 1; |
e7c27a73 | 4879 | read_namespace (die, cu); |
d9fa45fe | 4880 | break; |
5d7cb8df | 4881 | case DW_TAG_module: |
f55ee35c | 4882 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4883 | read_module (die, cu); |
4884 | break; | |
d9fa45fe DC |
4885 | case DW_TAG_imported_declaration: |
4886 | case DW_TAG_imported_module: | |
63d06c5c | 4887 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4888 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4889 | || cu->language != language_fortran)) | |
4890 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4891 | dwarf_tag_name (die->tag)); | |
4892 | read_import_statement (die, cu); | |
d9fa45fe | 4893 | break; |
c906108c | 4894 | default: |
e7c27a73 | 4895 | new_symbol (die, NULL, cu); |
c906108c SS |
4896 | break; |
4897 | } | |
4898 | } | |
4899 | ||
94af9270 KS |
4900 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4901 | needs to have the name of the scope prepended to the name listed in the | |
4902 | die. */ | |
4903 | ||
4904 | static int | |
4905 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4906 | { | |
1c809c68 TT |
4907 | struct attribute *attr; |
4908 | ||
94af9270 KS |
4909 | switch (die->tag) |
4910 | { | |
4911 | case DW_TAG_namespace: | |
4912 | case DW_TAG_typedef: | |
4913 | case DW_TAG_class_type: | |
4914 | case DW_TAG_interface_type: | |
4915 | case DW_TAG_structure_type: | |
4916 | case DW_TAG_union_type: | |
4917 | case DW_TAG_enumeration_type: | |
4918 | case DW_TAG_enumerator: | |
4919 | case DW_TAG_subprogram: | |
4920 | case DW_TAG_member: | |
4921 | return 1; | |
4922 | ||
4923 | case DW_TAG_variable: | |
c2b0a229 | 4924 | case DW_TAG_constant: |
94af9270 KS |
4925 | /* We only need to prefix "globally" visible variables. These include |
4926 | any variable marked with DW_AT_external or any variable that | |
4927 | lives in a namespace. [Variables in anonymous namespaces | |
4928 | require prefixing, but they are not DW_AT_external.] */ | |
4929 | ||
4930 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4931 | { | |
4932 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4933 | |
94af9270 KS |
4934 | return die_needs_namespace (die_specification (die, &spec_cu), |
4935 | spec_cu); | |
4936 | } | |
4937 | ||
1c809c68 | 4938 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4939 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4940 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4941 | return 0; |
4942 | /* A variable in a lexical block of some kind does not need a | |
4943 | namespace, even though in C++ such variables may be external | |
4944 | and have a mangled name. */ | |
4945 | if (die->parent->tag == DW_TAG_lexical_block | |
4946 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4947 | || die->parent->tag == DW_TAG_catch_block |
4948 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4949 | return 0; |
4950 | return 1; | |
94af9270 KS |
4951 | |
4952 | default: | |
4953 | return 0; | |
4954 | } | |
4955 | } | |
4956 | ||
98bfdba5 PA |
4957 | /* Retrieve the last character from a mem_file. */ |
4958 | ||
4959 | static void | |
4960 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4961 | { | |
4962 | char *last_char_p = (char *) object; | |
4963 | ||
4964 | if (length > 0) | |
4965 | *last_char_p = buffer[length - 1]; | |
4966 | } | |
4967 | ||
94af9270 KS |
4968 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4969 | compute the physname for the object, which include a method's | |
4970 | formal parameters (C++/Java) and return type (Java). | |
4971 | ||
af6b7be1 JB |
4972 | For Ada, return the DIE's linkage name rather than the fully qualified |
4973 | name. PHYSNAME is ignored.. | |
4974 | ||
94af9270 KS |
4975 | The result is allocated on the objfile_obstack and canonicalized. */ |
4976 | ||
4977 | static const char * | |
4978 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4979 | int physname) | |
4980 | { | |
bb5ed363 DE |
4981 | struct objfile *objfile = cu->objfile; |
4982 | ||
94af9270 KS |
4983 | if (name == NULL) |
4984 | name = dwarf2_name (die, cu); | |
4985 | ||
f55ee35c JK |
4986 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4987 | compute it by typename_concat inside GDB. */ | |
4988 | if (cu->language == language_ada | |
4989 | || (cu->language == language_fortran && physname)) | |
4990 | { | |
4991 | /* For Ada unit, we prefer the linkage name over the name, as | |
4992 | the former contains the exported name, which the user expects | |
4993 | to be able to reference. Ideally, we want the user to be able | |
4994 | to reference this entity using either natural or linkage name, | |
4995 | but we haven't started looking at this enhancement yet. */ | |
4996 | struct attribute *attr; | |
4997 | ||
4998 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4999 | if (attr == NULL) | |
5000 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5001 | if (attr && DW_STRING (attr)) | |
5002 | return DW_STRING (attr); | |
5003 | } | |
5004 | ||
94af9270 KS |
5005 | /* These are the only languages we know how to qualify names in. */ |
5006 | if (name != NULL | |
f55ee35c JK |
5007 | && (cu->language == language_cplus || cu->language == language_java |
5008 | || cu->language == language_fortran)) | |
94af9270 KS |
5009 | { |
5010 | if (die_needs_namespace (die, cu)) | |
5011 | { | |
5012 | long length; | |
5013 | char *prefix; | |
5014 | struct ui_file *buf; | |
5015 | ||
5016 | prefix = determine_prefix (die, cu); | |
5017 | buf = mem_fileopen (); | |
5018 | if (*prefix != '\0') | |
5019 | { | |
f55ee35c JK |
5020 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5021 | physname, cu); | |
9a619af0 | 5022 | |
94af9270 KS |
5023 | fputs_unfiltered (prefixed_name, buf); |
5024 | xfree (prefixed_name); | |
5025 | } | |
5026 | else | |
62d5b8da | 5027 | fputs_unfiltered (name, buf); |
94af9270 | 5028 | |
98bfdba5 PA |
5029 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5030 | as children with DW_TAG_template_type_param or | |
5031 | DW_TAG_value_type_param. If the latter, add them to the name | |
5032 | here. If the name already has template parameters, then | |
5033 | skip this step; some versions of GCC emit both, and | |
5034 | it is more efficient to use the pre-computed name. | |
5035 | ||
5036 | Something to keep in mind about this process: it is very | |
5037 | unlikely, or in some cases downright impossible, to produce | |
5038 | something that will match the mangled name of a function. | |
5039 | If the definition of the function has the same debug info, | |
5040 | we should be able to match up with it anyway. But fallbacks | |
5041 | using the minimal symbol, for instance to find a method | |
5042 | implemented in a stripped copy of libstdc++, will not work. | |
5043 | If we do not have debug info for the definition, we will have to | |
5044 | match them up some other way. | |
5045 | ||
5046 | When we do name matching there is a related problem with function | |
5047 | templates; two instantiated function templates are allowed to | |
5048 | differ only by their return types, which we do not add here. */ | |
5049 | ||
5050 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5051 | { | |
5052 | struct attribute *attr; | |
5053 | struct die_info *child; | |
5054 | int first = 1; | |
5055 | ||
5056 | die->building_fullname = 1; | |
5057 | ||
5058 | for (child = die->child; child != NULL; child = child->sibling) | |
5059 | { | |
5060 | struct type *type; | |
5061 | long value; | |
5062 | gdb_byte *bytes; | |
5063 | struct dwarf2_locexpr_baton *baton; | |
5064 | struct value *v; | |
5065 | ||
5066 | if (child->tag != DW_TAG_template_type_param | |
5067 | && child->tag != DW_TAG_template_value_param) | |
5068 | continue; | |
5069 | ||
5070 | if (first) | |
5071 | { | |
5072 | fputs_unfiltered ("<", buf); | |
5073 | first = 0; | |
5074 | } | |
5075 | else | |
5076 | fputs_unfiltered (", ", buf); | |
5077 | ||
5078 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5079 | if (attr == NULL) | |
5080 | { | |
5081 | complaint (&symfile_complaints, | |
5082 | _("template parameter missing DW_AT_type")); | |
5083 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5084 | continue; | |
5085 | } | |
5086 | type = die_type (child, cu); | |
5087 | ||
5088 | if (child->tag == DW_TAG_template_type_param) | |
5089 | { | |
5090 | c_print_type (type, "", buf, -1, 0); | |
5091 | continue; | |
5092 | } | |
5093 | ||
5094 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5095 | if (attr == NULL) | |
5096 | { | |
5097 | complaint (&symfile_complaints, | |
3e43a32a MS |
5098 | _("template parameter missing " |
5099 | "DW_AT_const_value")); | |
98bfdba5 PA |
5100 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5101 | continue; | |
5102 | } | |
5103 | ||
5104 | dwarf2_const_value_attr (attr, type, name, | |
5105 | &cu->comp_unit_obstack, cu, | |
5106 | &value, &bytes, &baton); | |
5107 | ||
5108 | if (TYPE_NOSIGN (type)) | |
5109 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5110 | changed, this can use value_print instead. */ | |
5111 | c_printchar (value, type, buf); | |
5112 | else | |
5113 | { | |
5114 | struct value_print_options opts; | |
5115 | ||
5116 | if (baton != NULL) | |
5117 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5118 | baton->data, | |
5119 | baton->size, | |
5120 | baton->per_cu); | |
5121 | else if (bytes != NULL) | |
5122 | { | |
5123 | v = allocate_value (type); | |
5124 | memcpy (value_contents_writeable (v), bytes, | |
5125 | TYPE_LENGTH (type)); | |
5126 | } | |
5127 | else | |
5128 | v = value_from_longest (type, value); | |
5129 | ||
3e43a32a MS |
5130 | /* Specify decimal so that we do not depend on |
5131 | the radix. */ | |
98bfdba5 PA |
5132 | get_formatted_print_options (&opts, 'd'); |
5133 | opts.raw = 1; | |
5134 | value_print (v, buf, &opts); | |
5135 | release_value (v); | |
5136 | value_free (v); | |
5137 | } | |
5138 | } | |
5139 | ||
5140 | die->building_fullname = 0; | |
5141 | ||
5142 | if (!first) | |
5143 | { | |
5144 | /* Close the argument list, with a space if necessary | |
5145 | (nested templates). */ | |
5146 | char last_char = '\0'; | |
5147 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5148 | if (last_char == '>') | |
5149 | fputs_unfiltered (" >", buf); | |
5150 | else | |
5151 | fputs_unfiltered (">", buf); | |
5152 | } | |
5153 | } | |
5154 | ||
94af9270 KS |
5155 | /* For Java and C++ methods, append formal parameter type |
5156 | information, if PHYSNAME. */ | |
6e70227d | 5157 | |
94af9270 KS |
5158 | if (physname && die->tag == DW_TAG_subprogram |
5159 | && (cu->language == language_cplus | |
5160 | || cu->language == language_java)) | |
5161 | { | |
5162 | struct type *type = read_type_die (die, cu); | |
5163 | ||
3167638f | 5164 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5165 | |
5166 | if (cu->language == language_java) | |
5167 | { | |
5168 | /* For java, we must append the return type to method | |
0963b4bd | 5169 | names. */ |
94af9270 KS |
5170 | if (die->tag == DW_TAG_subprogram) |
5171 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5172 | 0, 0); | |
5173 | } | |
5174 | else if (cu->language == language_cplus) | |
5175 | { | |
60430eff DJ |
5176 | /* Assume that an artificial first parameter is |
5177 | "this", but do not crash if it is not. RealView | |
5178 | marks unnamed (and thus unused) parameters as | |
5179 | artificial; there is no way to differentiate | |
5180 | the two cases. */ | |
94af9270 KS |
5181 | if (TYPE_NFIELDS (type) > 0 |
5182 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5183 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5184 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5185 | 0)))) | |
94af9270 KS |
5186 | fputs_unfiltered (" const", buf); |
5187 | } | |
5188 | } | |
5189 | ||
bb5ed363 | 5190 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
5191 | &length); |
5192 | ui_file_delete (buf); | |
5193 | ||
5194 | if (cu->language == language_cplus) | |
5195 | { | |
5196 | char *cname | |
5197 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 5198 | &objfile->objfile_obstack); |
9a619af0 | 5199 | |
94af9270 KS |
5200 | if (cname != NULL) |
5201 | name = cname; | |
5202 | } | |
5203 | } | |
5204 | } | |
5205 | ||
5206 | return name; | |
5207 | } | |
5208 | ||
0114d602 DJ |
5209 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5210 | If scope qualifiers are appropriate they will be added. The result | |
5211 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5212 | not have a name. NAME may either be from a previous call to |
5213 | dwarf2_name or NULL. | |
5214 | ||
0963b4bd | 5215 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5216 | |
5217 | static const char * | |
94af9270 | 5218 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5219 | { |
94af9270 KS |
5220 | return dwarf2_compute_name (name, die, cu, 0); |
5221 | } | |
0114d602 | 5222 | |
94af9270 KS |
5223 | /* Construct a physname for the given DIE in CU. NAME may either be |
5224 | from a previous call to dwarf2_name or NULL. The result will be | |
5225 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5226 | name. | |
0114d602 | 5227 | |
94af9270 | 5228 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5229 | |
94af9270 KS |
5230 | static const char * |
5231 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5232 | { | |
bb5ed363 | 5233 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
5234 | struct attribute *attr; |
5235 | const char *retval, *mangled = NULL, *canon = NULL; | |
5236 | struct cleanup *back_to; | |
5237 | int need_copy = 1; | |
5238 | ||
5239 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5240 | on its own. */ | |
5241 | if (!die_needs_namespace (die, cu)) | |
5242 | return dwarf2_compute_name (name, die, cu, 1); | |
5243 | ||
5244 | back_to = make_cleanup (null_cleanup, NULL); | |
5245 | ||
5246 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5247 | if (!attr) | |
5248 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5249 | ||
5250 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5251 | has computed. */ | |
5252 | if (attr && DW_STRING (attr)) | |
5253 | { | |
5254 | char *demangled; | |
5255 | ||
5256 | mangled = DW_STRING (attr); | |
5257 | ||
5258 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5259 | type. It is easier for GDB users to search for such functions as | |
5260 | `name(params)' than `long name(params)'. In such case the minimal | |
5261 | symbol names do not match the full symbol names but for template | |
5262 | functions there is never a need to look up their definition from their | |
5263 | declaration so the only disadvantage remains the minimal symbol | |
5264 | variant `long name(params)' does not have the proper inferior type. | |
5265 | */ | |
5266 | ||
5267 | demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI | |
5268 | | (cu->language == language_java | |
5269 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5270 | : DMGL_RET_DROP))); | |
5271 | if (demangled) | |
5272 | { | |
5273 | make_cleanup (xfree, demangled); | |
5274 | canon = demangled; | |
5275 | } | |
5276 | else | |
5277 | { | |
5278 | canon = mangled; | |
5279 | need_copy = 0; | |
5280 | } | |
5281 | } | |
5282 | ||
5283 | if (canon == NULL || check_physname) | |
5284 | { | |
5285 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
5286 | ||
5287 | if (canon != NULL && strcmp (physname, canon) != 0) | |
5288 | { | |
5289 | /* It may not mean a bug in GDB. The compiler could also | |
5290 | compute DW_AT_linkage_name incorrectly. But in such case | |
5291 | GDB would need to be bug-to-bug compatible. */ | |
5292 | ||
5293 | complaint (&symfile_complaints, | |
5294 | _("Computed physname <%s> does not match demangled <%s> " | |
5295 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5296 | physname, canon, mangled, die->offset, objfile->name); |
900e11f9 JK |
5297 | |
5298 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
5299 | is available here - over computed PHYSNAME. It is safer | |
5300 | against both buggy GDB and buggy compilers. */ | |
5301 | ||
5302 | retval = canon; | |
5303 | } | |
5304 | else | |
5305 | { | |
5306 | retval = physname; | |
5307 | need_copy = 0; | |
5308 | } | |
5309 | } | |
5310 | else | |
5311 | retval = canon; | |
5312 | ||
5313 | if (need_copy) | |
5314 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 5315 | &objfile->objfile_obstack); |
900e11f9 JK |
5316 | |
5317 | do_cleanups (back_to); | |
5318 | return retval; | |
0114d602 DJ |
5319 | } |
5320 | ||
27aa8d6a SW |
5321 | /* Read the import statement specified by the given die and record it. */ |
5322 | ||
5323 | static void | |
5324 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5325 | { | |
bb5ed363 | 5326 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 5327 | struct attribute *import_attr; |
32019081 | 5328 | struct die_info *imported_die, *child_die; |
de4affc9 | 5329 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5330 | const char *imported_name; |
794684b6 | 5331 | const char *imported_name_prefix; |
13387711 SW |
5332 | const char *canonical_name; |
5333 | const char *import_alias; | |
5334 | const char *imported_declaration = NULL; | |
794684b6 | 5335 | const char *import_prefix; |
32019081 JK |
5336 | VEC (const_char_ptr) *excludes = NULL; |
5337 | struct cleanup *cleanups; | |
13387711 SW |
5338 | |
5339 | char *temp; | |
27aa8d6a SW |
5340 | |
5341 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5342 | if (import_attr == NULL) | |
5343 | { | |
5344 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5345 | dwarf_tag_name (die->tag)); | |
5346 | return; | |
5347 | } | |
5348 | ||
de4affc9 CC |
5349 | imported_cu = cu; |
5350 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5351 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5352 | if (imported_name == NULL) |
5353 | { | |
5354 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5355 | ||
5356 | The import in the following code: | |
5357 | namespace A | |
5358 | { | |
5359 | typedef int B; | |
5360 | } | |
5361 | ||
5362 | int main () | |
5363 | { | |
5364 | using A::B; | |
5365 | B b; | |
5366 | return b; | |
5367 | } | |
5368 | ||
5369 | ... | |
5370 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5371 | <52> DW_AT_decl_file : 1 | |
5372 | <53> DW_AT_decl_line : 6 | |
5373 | <54> DW_AT_import : <0x75> | |
5374 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5375 | <59> DW_AT_name : B | |
5376 | <5b> DW_AT_decl_file : 1 | |
5377 | <5c> DW_AT_decl_line : 2 | |
5378 | <5d> DW_AT_type : <0x6e> | |
5379 | ... | |
5380 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5381 | <76> DW_AT_byte_size : 4 | |
5382 | <77> DW_AT_encoding : 5 (signed) | |
5383 | ||
5384 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5385 | This case will be ignored until the gcc bug is fixed. */ | |
5386 | return; | |
5387 | } | |
5388 | ||
82856980 SW |
5389 | /* Figure out the local name after import. */ |
5390 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5391 | |
794684b6 SW |
5392 | /* Figure out where the statement is being imported to. */ |
5393 | import_prefix = determine_prefix (die, cu); | |
5394 | ||
5395 | /* Figure out what the scope of the imported die is and prepend it | |
5396 | to the name of the imported die. */ | |
de4affc9 | 5397 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5398 | |
f55ee35c JK |
5399 | if (imported_die->tag != DW_TAG_namespace |
5400 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5401 | { |
13387711 SW |
5402 | imported_declaration = imported_name; |
5403 | canonical_name = imported_name_prefix; | |
794684b6 | 5404 | } |
13387711 | 5405 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5406 | { |
13387711 SW |
5407 | temp = alloca (strlen (imported_name_prefix) |
5408 | + 2 + strlen (imported_name) + 1); | |
5409 | strcpy (temp, imported_name_prefix); | |
5410 | strcat (temp, "::"); | |
5411 | strcat (temp, imported_name); | |
5412 | canonical_name = temp; | |
794684b6 | 5413 | } |
13387711 SW |
5414 | else |
5415 | canonical_name = imported_name; | |
794684b6 | 5416 | |
32019081 JK |
5417 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
5418 | ||
5419 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
5420 | for (child_die = die->child; child_die && child_die->tag; | |
5421 | child_die = sibling_die (child_die)) | |
5422 | { | |
5423 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
5424 | represented by an imported module entry with an import attribute | |
5425 | referring to the module and owned entries corresponding to those | |
5426 | entities that are renamed as part of being imported. */ | |
5427 | ||
5428 | if (child_die->tag != DW_TAG_imported_declaration) | |
5429 | { | |
5430 | complaint (&symfile_complaints, | |
5431 | _("child DW_TAG_imported_declaration expected " | |
5432 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5433 | child_die->offset, objfile->name); |
32019081 JK |
5434 | continue; |
5435 | } | |
5436 | ||
5437 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
5438 | if (import_attr == NULL) | |
5439 | { | |
5440 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5441 | dwarf_tag_name (child_die->tag)); | |
5442 | continue; | |
5443 | } | |
5444 | ||
5445 | imported_cu = cu; | |
5446 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
5447 | &imported_cu); | |
5448 | imported_name = dwarf2_name (imported_die, imported_cu); | |
5449 | if (imported_name == NULL) | |
5450 | { | |
5451 | complaint (&symfile_complaints, | |
5452 | _("child DW_TAG_imported_declaration has unknown " | |
5453 | "imported name - DIE at 0x%x [in module %s]"), | |
bb5ed363 | 5454 | child_die->offset, objfile->name); |
32019081 JK |
5455 | continue; |
5456 | } | |
5457 | ||
5458 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
5459 | ||
5460 | process_die (child_die, cu); | |
5461 | } | |
5462 | ||
c0cc3a76 SW |
5463 | cp_add_using_directive (import_prefix, |
5464 | canonical_name, | |
5465 | import_alias, | |
13387711 | 5466 | imported_declaration, |
32019081 | 5467 | excludes, |
bb5ed363 | 5468 | &objfile->objfile_obstack); |
32019081 JK |
5469 | |
5470 | do_cleanups (cleanups); | |
27aa8d6a SW |
5471 | } |
5472 | ||
ae2de4f8 DE |
5473 | /* Cleanup function for read_file_scope. */ |
5474 | ||
cb1df416 DJ |
5475 | static void |
5476 | free_cu_line_header (void *arg) | |
5477 | { | |
5478 | struct dwarf2_cu *cu = arg; | |
5479 | ||
5480 | free_line_header (cu->line_header); | |
5481 | cu->line_header = NULL; | |
5482 | } | |
5483 | ||
9291a0cd TT |
5484 | static void |
5485 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5486 | char **name, char **comp_dir) | |
5487 | { | |
5488 | struct attribute *attr; | |
5489 | ||
5490 | *name = NULL; | |
5491 | *comp_dir = NULL; | |
5492 | ||
5493 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5494 | is not a source language identifier. */ | |
5495 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5496 | if (attr) | |
5497 | { | |
5498 | *name = DW_STRING (attr); | |
5499 | } | |
5500 | ||
5501 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5502 | if (attr) | |
5503 | *comp_dir = DW_STRING (attr); | |
5504 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5505 | { | |
5506 | *comp_dir = ldirname (*name); | |
5507 | if (*comp_dir != NULL) | |
5508 | make_cleanup (xfree, *comp_dir); | |
5509 | } | |
5510 | if (*comp_dir != NULL) | |
5511 | { | |
5512 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5513 | directory, get rid of it. */ | |
5514 | char *cp = strchr (*comp_dir, ':'); | |
5515 | ||
5516 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5517 | *comp_dir = cp + 1; | |
5518 | } | |
5519 | ||
5520 | if (*name == NULL) | |
5521 | *name = "<unknown>"; | |
5522 | } | |
5523 | ||
2ab95328 TT |
5524 | /* Handle DW_AT_stmt_list for a compilation unit. */ |
5525 | ||
5526 | static void | |
5527 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
5528 | const char *comp_dir) | |
5529 | { | |
5530 | struct attribute *attr; | |
5531 | struct objfile *objfile = cu->objfile; | |
5532 | bfd *abfd = objfile->obfd; | |
5533 | ||
5534 | /* Decode line number information if present. We do this before | |
5535 | processing child DIEs, so that the line header table is available | |
5536 | for DW_AT_decl_file. */ | |
5537 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); | |
5538 | if (attr) | |
5539 | { | |
5540 | unsigned int line_offset = DW_UNSND (attr); | |
5541 | struct line_header *line_header | |
5542 | = dwarf_decode_line_header (line_offset, abfd, cu); | |
5543 | ||
5544 | if (line_header) | |
5545 | { | |
5546 | cu->line_header = line_header; | |
5547 | make_cleanup (free_cu_line_header, cu); | |
5548 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); | |
5549 | } | |
5550 | } | |
5551 | } | |
5552 | ||
ae2de4f8 DE |
5553 | /* Process DW_TAG_compile_unit. */ |
5554 | ||
c906108c | 5555 | static void |
e7c27a73 | 5556 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5557 | { |
e7c27a73 | 5558 | struct objfile *objfile = cu->objfile; |
debd256d | 5559 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5560 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5561 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5562 | struct attribute *attr; | |
e1024ff1 | 5563 | char *name = NULL; |
c906108c SS |
5564 | char *comp_dir = NULL; |
5565 | struct die_info *child_die; | |
5566 | bfd *abfd = objfile->obfd; | |
e142c38c | 5567 | CORE_ADDR baseaddr; |
6e70227d | 5568 | |
e142c38c | 5569 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5570 | |
fae299cd | 5571 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5572 | |
5573 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5574 | from finish_block. */ | |
2acceee2 | 5575 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5576 | lowpc = highpc; |
5577 | lowpc += baseaddr; | |
5578 | highpc += baseaddr; | |
5579 | ||
9291a0cd | 5580 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5581 | |
e142c38c | 5582 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5583 | if (attr) |
5584 | { | |
e142c38c | 5585 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5586 | } |
5587 | ||
b0f35d58 | 5588 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5589 | if (attr) |
b0f35d58 | 5590 | cu->producer = DW_STRING (attr); |
303b6f5d | 5591 | |
f4b8a18d KW |
5592 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5593 | standardised yet. As a workaround for the language detection we fall | |
5594 | back to the DW_AT_producer string. */ | |
5595 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5596 | cu->language = language_opencl; | |
5597 | ||
0963b4bd | 5598 | /* We assume that we're processing GCC output. */ |
c906108c | 5599 | processing_gcc_compilation = 2; |
c906108c | 5600 | |
df8a16a1 DJ |
5601 | processing_has_namespace_info = 0; |
5602 | ||
c906108c SS |
5603 | start_symtab (name, comp_dir, lowpc); |
5604 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5605 | record_producer (cu->producer); |
c906108c | 5606 | |
2ab95328 | 5607 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
debd256d | 5608 | |
cb1df416 DJ |
5609 | /* Process all dies in compilation unit. */ |
5610 | if (die->child != NULL) | |
5611 | { | |
5612 | child_die = die->child; | |
5613 | while (child_die && child_die->tag) | |
5614 | { | |
5615 | process_die (child_die, cu); | |
5616 | child_die = sibling_die (child_die); | |
5617 | } | |
5618 | } | |
5619 | ||
2e276125 JB |
5620 | /* Decode macro information, if present. Dwarf 2 macro information |
5621 | refers to information in the line number info statement program | |
5622 | header, so we can only read it if we've read the header | |
5623 | successfully. */ | |
cf2c3c16 | 5624 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
2ab95328 | 5625 | if (attr && cu->line_header) |
2e276125 | 5626 | { |
cf2c3c16 TT |
5627 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
5628 | complaint (&symfile_complaints, | |
5629 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
5630 | ||
5631 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
5632 | comp_dir, abfd, cu, | |
5633 | &dwarf2_per_objfile->macro, 1); | |
5634 | } | |
5635 | else | |
5636 | { | |
5637 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
5638 | if (attr && cu->line_header) | |
5639 | { | |
5640 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5641 | |
cf2c3c16 TT |
5642 | dwarf_decode_macros (cu->line_header, macro_offset, |
5643 | comp_dir, abfd, cu, | |
5644 | &dwarf2_per_objfile->macinfo, 0); | |
5645 | } | |
2e276125 | 5646 | } |
9cdd5dbd | 5647 | |
debd256d | 5648 | do_cleanups (back_to); |
5fb290d7 DJ |
5649 | } |
5650 | ||
ae2de4f8 DE |
5651 | /* Process DW_TAG_type_unit. |
5652 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5653 | actual type being defined by this TU. In this case the first top |
5654 | level sibling is there to provide context only. */ | |
5655 | ||
5656 | static void | |
5657 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5658 | { | |
5659 | struct objfile *objfile = cu->objfile; | |
5660 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5661 | CORE_ADDR lowpc; | |
5662 | struct attribute *attr; | |
5663 | char *name = NULL; | |
5664 | char *comp_dir = NULL; | |
5665 | struct die_info *child_die; | |
5666 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5667 | |
5668 | /* start_symtab needs a low pc, but we don't really have one. | |
5669 | Do what read_file_scope would do in the absence of such info. */ | |
5670 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5671 | ||
5672 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5673 | is not a source language identifier. */ | |
5674 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5675 | if (attr) | |
5676 | name = DW_STRING (attr); | |
5677 | ||
5678 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5679 | if (attr) | |
5680 | comp_dir = DW_STRING (attr); | |
5681 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5682 | { | |
5683 | comp_dir = ldirname (name); | |
5684 | if (comp_dir != NULL) | |
5685 | make_cleanup (xfree, comp_dir); | |
5686 | } | |
5687 | ||
5688 | if (name == NULL) | |
5689 | name = "<unknown>"; | |
5690 | ||
5691 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5692 | if (attr) | |
5693 | set_cu_language (DW_UNSND (attr), cu); | |
5694 | ||
5695 | /* This isn't technically needed today. It is done for symmetry | |
5696 | with read_file_scope. */ | |
5697 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5698 | if (attr) |
348e048f DE |
5699 | cu->producer = DW_STRING (attr); |
5700 | ||
0963b4bd | 5701 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5702 | processing_gcc_compilation = 2; |
5703 | ||
5704 | processing_has_namespace_info = 0; | |
5705 | ||
5706 | start_symtab (name, comp_dir, lowpc); | |
5707 | record_debugformat ("DWARF 2"); | |
5708 | record_producer (cu->producer); | |
5709 | ||
2ab95328 TT |
5710 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
5711 | ||
348e048f DE |
5712 | /* Process the dies in the type unit. */ |
5713 | if (die->child == NULL) | |
5714 | { | |
5715 | dump_die_for_error (die); | |
5716 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5717 | bfd_get_filename (abfd)); | |
5718 | } | |
5719 | ||
5720 | child_die = die->child; | |
5721 | ||
5722 | while (child_die && child_die->tag) | |
5723 | { | |
5724 | process_die (child_die, cu); | |
5725 | ||
5726 | child_die = sibling_die (child_die); | |
5727 | } | |
5728 | ||
5729 | do_cleanups (back_to); | |
5730 | } | |
5731 | ||
d389af10 JK |
5732 | /* qsort helper for inherit_abstract_dies. */ |
5733 | ||
5734 | static int | |
5735 | unsigned_int_compar (const void *ap, const void *bp) | |
5736 | { | |
5737 | unsigned int a = *(unsigned int *) ap; | |
5738 | unsigned int b = *(unsigned int *) bp; | |
5739 | ||
5740 | return (a > b) - (b > a); | |
5741 | } | |
5742 | ||
5743 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5744 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5745 | already referenced by DW_AT_abstract_origin from the children of the | |
5746 | current DIE. */ | |
d389af10 JK |
5747 | |
5748 | static void | |
5749 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5750 | { | |
5751 | struct die_info *child_die; | |
5752 | unsigned die_children_count; | |
5753 | /* CU offsets which were referenced by children of the current DIE. */ | |
5754 | unsigned *offsets; | |
5755 | unsigned *offsets_end, *offsetp; | |
5756 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5757 | struct die_info *origin_die; | |
5758 | /* Iterator of the ORIGIN_DIE children. */ | |
5759 | struct die_info *origin_child_die; | |
5760 | struct cleanup *cleanups; | |
5761 | struct attribute *attr; | |
cd02d79d PA |
5762 | struct dwarf2_cu *origin_cu; |
5763 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5764 | |
5765 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5766 | if (!attr) | |
5767 | return; | |
5768 | ||
cd02d79d PA |
5769 | /* Note that following die references may follow to a die in a |
5770 | different cu. */ | |
5771 | ||
5772 | origin_cu = cu; | |
5773 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5774 | ||
5775 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5776 | symbols in. */ | |
5777 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5778 | origin_cu->list_in_scope = cu->list_in_scope; | |
5779 | ||
edb3359d DJ |
5780 | if (die->tag != origin_die->tag |
5781 | && !(die->tag == DW_TAG_inlined_subroutine | |
5782 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5783 | complaint (&symfile_complaints, |
5784 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5785 | die->offset, origin_die->offset); | |
5786 | ||
5787 | child_die = die->child; | |
5788 | die_children_count = 0; | |
5789 | while (child_die && child_die->tag) | |
5790 | { | |
5791 | child_die = sibling_die (child_die); | |
5792 | die_children_count++; | |
5793 | } | |
5794 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5795 | cleanups = make_cleanup (xfree, offsets); | |
5796 | ||
5797 | offsets_end = offsets; | |
5798 | child_die = die->child; | |
5799 | while (child_die && child_die->tag) | |
5800 | { | |
c38f313d DJ |
5801 | /* For each CHILD_DIE, find the corresponding child of |
5802 | ORIGIN_DIE. If there is more than one layer of | |
5803 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5804 | but GCC versions at least through 4.4 generate this (GCC PR | |
5805 | 40573). */ | |
5806 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5807 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5808 | |
c38f313d DJ |
5809 | while (1) |
5810 | { | |
cd02d79d PA |
5811 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5812 | child_origin_cu); | |
c38f313d DJ |
5813 | if (attr == NULL) |
5814 | break; | |
cd02d79d PA |
5815 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5816 | &child_origin_cu); | |
c38f313d DJ |
5817 | } |
5818 | ||
d389af10 JK |
5819 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5820 | counterpart may exist. */ | |
c38f313d | 5821 | if (child_origin_die != child_die) |
d389af10 | 5822 | { |
edb3359d DJ |
5823 | if (child_die->tag != child_origin_die->tag |
5824 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5825 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5826 | complaint (&symfile_complaints, |
5827 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5828 | "different tags"), child_die->offset, | |
5829 | child_origin_die->offset); | |
c38f313d DJ |
5830 | if (child_origin_die->parent != origin_die) |
5831 | complaint (&symfile_complaints, | |
5832 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5833 | "different parents"), child_die->offset, | |
5834 | child_origin_die->offset); | |
5835 | else | |
5836 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5837 | } |
5838 | child_die = sibling_die (child_die); | |
5839 | } | |
5840 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5841 | unsigned_int_compar); | |
5842 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5843 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5844 | complaint (&symfile_complaints, |
5845 | _("Multiple children of DIE 0x%x refer " | |
5846 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5847 | die->offset, *offsetp); |
5848 | ||
5849 | offsetp = offsets; | |
5850 | origin_child_die = origin_die->child; | |
5851 | while (origin_child_die && origin_child_die->tag) | |
5852 | { | |
5853 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5854 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5855 | offsetp++; | |
5856 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5857 | { | |
5858 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5859 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5860 | } |
5861 | origin_child_die = sibling_die (origin_child_die); | |
5862 | } | |
cd02d79d | 5863 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5864 | |
5865 | do_cleanups (cleanups); | |
5866 | } | |
5867 | ||
c906108c | 5868 | static void |
e7c27a73 | 5869 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5870 | { |
e7c27a73 | 5871 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5872 | struct context_stack *new; |
c906108c SS |
5873 | CORE_ADDR lowpc; |
5874 | CORE_ADDR highpc; | |
5875 | struct die_info *child_die; | |
edb3359d | 5876 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5877 | char *name; |
e142c38c | 5878 | CORE_ADDR baseaddr; |
801e3a5b | 5879 | struct block *block; |
edb3359d | 5880 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5881 | VEC (symbolp) *template_args = NULL; |
5882 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5883 | |
5884 | if (inlined_func) | |
5885 | { | |
5886 | /* If we do not have call site information, we can't show the | |
5887 | caller of this inlined function. That's too confusing, so | |
5888 | only use the scope for local variables. */ | |
5889 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5890 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5891 | if (call_line == NULL || call_file == NULL) | |
5892 | { | |
5893 | read_lexical_block_scope (die, cu); | |
5894 | return; | |
5895 | } | |
5896 | } | |
c906108c | 5897 | |
e142c38c DJ |
5898 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5899 | ||
94af9270 | 5900 | name = dwarf2_name (die, cu); |
c906108c | 5901 | |
e8d05480 JB |
5902 | /* Ignore functions with missing or empty names. These are actually |
5903 | illegal according to the DWARF standard. */ | |
5904 | if (name == NULL) | |
5905 | { | |
5906 | complaint (&symfile_complaints, | |
5907 | _("missing name for subprogram DIE at %d"), die->offset); | |
5908 | return; | |
5909 | } | |
5910 | ||
5911 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5912 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5913 | { | |
ae4d0c03 PM |
5914 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5915 | if (!attr || !DW_UNSND (attr)) | |
5916 | complaint (&symfile_complaints, | |
3e43a32a MS |
5917 | _("cannot get low and high bounds " |
5918 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5919 | die->offset); |
e8d05480 JB |
5920 | return; |
5921 | } | |
c906108c SS |
5922 | |
5923 | lowpc += baseaddr; | |
5924 | highpc += baseaddr; | |
5925 | ||
34eaf542 TT |
5926 | /* If we have any template arguments, then we must allocate a |
5927 | different sort of symbol. */ | |
5928 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5929 | { | |
5930 | if (child_die->tag == DW_TAG_template_type_param | |
5931 | || child_die->tag == DW_TAG_template_value_param) | |
5932 | { | |
5933 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5934 | struct template_symbol); | |
5935 | templ_func->base.is_cplus_template_function = 1; | |
5936 | break; | |
5937 | } | |
5938 | } | |
5939 | ||
c906108c | 5940 | new = push_context (0, lowpc); |
34eaf542 TT |
5941 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5942 | (struct symbol *) templ_func); | |
4c2df51b | 5943 | |
4cecd739 DJ |
5944 | /* If there is a location expression for DW_AT_frame_base, record |
5945 | it. */ | |
e142c38c | 5946 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5947 | if (attr) |
c034e007 AC |
5948 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5949 | expression is being recorded directly in the function's symbol | |
5950 | and not in a separate frame-base object. I guess this hack is | |
5951 | to avoid adding some sort of frame-base adjunct/annex to the | |
5952 | function's symbol :-(. The problem with doing this is that it | |
5953 | results in a function symbol with a location expression that | |
5954 | has nothing to do with the location of the function, ouch! The | |
5955 | relationship should be: a function's symbol has-a frame base; a | |
5956 | frame-base has-a location expression. */ | |
e7c27a73 | 5957 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5958 | |
e142c38c | 5959 | cu->list_in_scope = &local_symbols; |
c906108c | 5960 | |
639d11d3 | 5961 | if (die->child != NULL) |
c906108c | 5962 | { |
639d11d3 | 5963 | child_die = die->child; |
c906108c SS |
5964 | while (child_die && child_die->tag) |
5965 | { | |
34eaf542 TT |
5966 | if (child_die->tag == DW_TAG_template_type_param |
5967 | || child_die->tag == DW_TAG_template_value_param) | |
5968 | { | |
5969 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5970 | ||
f1078f66 DJ |
5971 | if (arg != NULL) |
5972 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
5973 | } |
5974 | else | |
5975 | process_die (child_die, cu); | |
c906108c SS |
5976 | child_die = sibling_die (child_die); |
5977 | } | |
5978 | } | |
5979 | ||
d389af10 JK |
5980 | inherit_abstract_dies (die, cu); |
5981 | ||
4a811a97 UW |
5982 | /* If we have a DW_AT_specification, we might need to import using |
5983 | directives from the context of the specification DIE. See the | |
5984 | comment in determine_prefix. */ | |
5985 | if (cu->language == language_cplus | |
5986 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5987 | { | |
5988 | struct dwarf2_cu *spec_cu = cu; | |
5989 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5990 | ||
5991 | while (spec_die) | |
5992 | { | |
5993 | child_die = spec_die->child; | |
5994 | while (child_die && child_die->tag) | |
5995 | { | |
5996 | if (child_die->tag == DW_TAG_imported_module) | |
5997 | process_die (child_die, spec_cu); | |
5998 | child_die = sibling_die (child_die); | |
5999 | } | |
6000 | ||
6001 | /* In some cases, GCC generates specification DIEs that | |
6002 | themselves contain DW_AT_specification attributes. */ | |
6003 | spec_die = die_specification (spec_die, &spec_cu); | |
6004 | } | |
6005 | } | |
6006 | ||
c906108c SS |
6007 | new = pop_context (); |
6008 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
6009 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
6010 | lowpc, highpc, objfile); | |
6011 | ||
df8a16a1 | 6012 | /* For C++, set the block's scope. */ |
f55ee35c | 6013 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 6014 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 6015 | determine_prefix (die, cu), |
df8a16a1 DJ |
6016 | processing_has_namespace_info); |
6017 | ||
801e3a5b JB |
6018 | /* If we have address ranges, record them. */ |
6019 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 6020 | |
34eaf542 TT |
6021 | /* Attach template arguments to function. */ |
6022 | if (! VEC_empty (symbolp, template_args)) | |
6023 | { | |
6024 | gdb_assert (templ_func != NULL); | |
6025 | ||
6026 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
6027 | templ_func->template_arguments | |
6028 | = obstack_alloc (&objfile->objfile_obstack, | |
6029 | (templ_func->n_template_arguments | |
6030 | * sizeof (struct symbol *))); | |
6031 | memcpy (templ_func->template_arguments, | |
6032 | VEC_address (symbolp, template_args), | |
6033 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
6034 | VEC_free (symbolp, template_args); | |
6035 | } | |
6036 | ||
208d8187 JB |
6037 | /* In C++, we can have functions nested inside functions (e.g., when |
6038 | a function declares a class that has methods). This means that | |
6039 | when we finish processing a function scope, we may need to go | |
6040 | back to building a containing block's symbol lists. */ | |
6041 | local_symbols = new->locals; | |
6042 | param_symbols = new->params; | |
27aa8d6a | 6043 | using_directives = new->using_directives; |
208d8187 | 6044 | |
921e78cf JB |
6045 | /* If we've finished processing a top-level function, subsequent |
6046 | symbols go in the file symbol list. */ | |
6047 | if (outermost_context_p ()) | |
e142c38c | 6048 | cu->list_in_scope = &file_symbols; |
c906108c SS |
6049 | } |
6050 | ||
6051 | /* Process all the DIES contained within a lexical block scope. Start | |
6052 | a new scope, process the dies, and then close the scope. */ | |
6053 | ||
6054 | static void | |
e7c27a73 | 6055 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6056 | { |
e7c27a73 | 6057 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6058 | struct context_stack *new; |
c906108c SS |
6059 | CORE_ADDR lowpc, highpc; |
6060 | struct die_info *child_die; | |
e142c38c DJ |
6061 | CORE_ADDR baseaddr; |
6062 | ||
6063 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
6064 | |
6065 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
6066 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
6067 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 6068 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 6069 | describe ranges. */ |
d85a05f0 | 6070 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
6071 | return; |
6072 | lowpc += baseaddr; | |
6073 | highpc += baseaddr; | |
6074 | ||
6075 | push_context (0, lowpc); | |
639d11d3 | 6076 | if (die->child != NULL) |
c906108c | 6077 | { |
639d11d3 | 6078 | child_die = die->child; |
c906108c SS |
6079 | while (child_die && child_die->tag) |
6080 | { | |
e7c27a73 | 6081 | process_die (child_die, cu); |
c906108c SS |
6082 | child_die = sibling_die (child_die); |
6083 | } | |
6084 | } | |
6085 | new = pop_context (); | |
6086 | ||
8540c487 | 6087 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 6088 | { |
801e3a5b JB |
6089 | struct block *block |
6090 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
6091 | highpc, objfile); | |
6092 | ||
6093 | /* Note that recording ranges after traversing children, as we | |
6094 | do here, means that recording a parent's ranges entails | |
6095 | walking across all its children's ranges as they appear in | |
6096 | the address map, which is quadratic behavior. | |
6097 | ||
6098 | It would be nicer to record the parent's ranges before | |
6099 | traversing its children, simply overriding whatever you find | |
6100 | there. But since we don't even decide whether to create a | |
6101 | block until after we've traversed its children, that's hard | |
6102 | to do. */ | |
6103 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
6104 | } |
6105 | local_symbols = new->locals; | |
27aa8d6a | 6106 | using_directives = new->using_directives; |
c906108c SS |
6107 | } |
6108 | ||
96408a79 SA |
6109 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
6110 | ||
6111 | static void | |
6112 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6113 | { | |
6114 | struct objfile *objfile = cu->objfile; | |
6115 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6116 | CORE_ADDR pc, baseaddr; | |
6117 | struct attribute *attr; | |
6118 | struct call_site *call_site, call_site_local; | |
6119 | void **slot; | |
6120 | int nparams; | |
6121 | struct die_info *child_die; | |
6122 | ||
6123 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6124 | ||
6125 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
6126 | if (!attr) | |
6127 | { | |
6128 | complaint (&symfile_complaints, | |
6129 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
6130 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6131 | die->offset, objfile->name); |
96408a79 SA |
6132 | return; |
6133 | } | |
6134 | pc = DW_ADDR (attr) + baseaddr; | |
6135 | ||
6136 | if (cu->call_site_htab == NULL) | |
6137 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
6138 | NULL, &objfile->objfile_obstack, | |
6139 | hashtab_obstack_allocate, NULL); | |
6140 | call_site_local.pc = pc; | |
6141 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
6142 | if (*slot != NULL) | |
6143 | { | |
6144 | complaint (&symfile_complaints, | |
6145 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
6146 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6147 | paddress (gdbarch, pc), die->offset, objfile->name); |
96408a79 SA |
6148 | return; |
6149 | } | |
6150 | ||
6151 | /* Count parameters at the caller. */ | |
6152 | ||
6153 | nparams = 0; | |
6154 | for (child_die = die->child; child_die && child_die->tag; | |
6155 | child_die = sibling_die (child_die)) | |
6156 | { | |
6157 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6158 | { | |
6159 | complaint (&symfile_complaints, | |
6160 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
6161 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6162 | child_die->tag, child_die->offset, objfile->name); |
96408a79 SA |
6163 | continue; |
6164 | } | |
6165 | ||
6166 | nparams++; | |
6167 | } | |
6168 | ||
6169 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
6170 | (sizeof (*call_site) | |
6171 | + (sizeof (*call_site->parameter) | |
6172 | * (nparams - 1)))); | |
6173 | *slot = call_site; | |
6174 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
6175 | call_site->pc = pc; | |
6176 | ||
6177 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
6178 | { | |
6179 | struct die_info *func_die; | |
6180 | ||
6181 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
6182 | for (func_die = die->parent; | |
6183 | func_die && func_die->tag != DW_TAG_subprogram | |
6184 | && func_die->tag != DW_TAG_subroutine_type; | |
6185 | func_die = func_die->parent); | |
6186 | ||
6187 | /* DW_AT_GNU_all_call_sites is a superset | |
6188 | of DW_AT_GNU_all_tail_call_sites. */ | |
6189 | if (func_die | |
6190 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
6191 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
6192 | { | |
6193 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
6194 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
6195 | both the initial caller containing the real return address PC and | |
6196 | the final callee containing the current PC of a chain of tail | |
6197 | calls do not need to have the tail call list complete. But any | |
6198 | function candidate for a virtual tail call frame searched via | |
6199 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
6200 | determined unambiguously. */ | |
6201 | } | |
6202 | else | |
6203 | { | |
6204 | struct type *func_type = NULL; | |
6205 | ||
6206 | if (func_die) | |
6207 | func_type = get_die_type (func_die, cu); | |
6208 | if (func_type != NULL) | |
6209 | { | |
6210 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
6211 | ||
6212 | /* Enlist this call site to the function. */ | |
6213 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
6214 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
6215 | } | |
6216 | else | |
6217 | complaint (&symfile_complaints, | |
6218 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
6219 | "DIE 0x%x [in module %s]"), | |
bb5ed363 | 6220 | die->offset, objfile->name); |
96408a79 SA |
6221 | } |
6222 | } | |
6223 | ||
6224 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
6225 | if (attr == NULL) | |
6226 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6227 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
6228 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
6229 | /* Keep NULL DWARF_BLOCK. */; | |
6230 | else if (attr_form_is_block (attr)) | |
6231 | { | |
6232 | struct dwarf2_locexpr_baton *dlbaton; | |
6233 | ||
6234 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
6235 | dlbaton->data = DW_BLOCK (attr)->data; | |
6236 | dlbaton->size = DW_BLOCK (attr)->size; | |
6237 | dlbaton->per_cu = cu->per_cu; | |
6238 | ||
6239 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
6240 | } | |
6241 | else if (is_ref_attr (attr)) | |
6242 | { | |
96408a79 SA |
6243 | struct dwarf2_cu *target_cu = cu; |
6244 | struct die_info *target_die; | |
6245 | ||
6246 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
6247 | gdb_assert (target_cu->objfile == objfile); | |
6248 | if (die_is_declaration (target_die, target_cu)) | |
6249 | { | |
6250 | const char *target_physname; | |
6251 | ||
6252 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
6253 | if (target_physname == NULL) | |
6254 | complaint (&symfile_complaints, | |
6255 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6256 | "physname, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6257 | die->offset, objfile->name); |
96408a79 SA |
6258 | else |
6259 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
6260 | } | |
6261 | else | |
6262 | { | |
6263 | CORE_ADDR lowpc; | |
6264 | ||
6265 | /* DW_AT_entry_pc should be preferred. */ | |
6266 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
6267 | complaint (&symfile_complaints, | |
6268 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6269 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
bb5ed363 | 6270 | die->offset, objfile->name); |
96408a79 SA |
6271 | else |
6272 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
6273 | } | |
6274 | } | |
6275 | else | |
6276 | complaint (&symfile_complaints, | |
6277 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
6278 | "block nor reference, for DIE 0x%x [in module %s]"), | |
bb5ed363 | 6279 | die->offset, objfile->name); |
96408a79 SA |
6280 | |
6281 | call_site->per_cu = cu->per_cu; | |
6282 | ||
6283 | for (child_die = die->child; | |
6284 | child_die && child_die->tag; | |
6285 | child_die = sibling_die (child_die)) | |
6286 | { | |
6287 | struct dwarf2_locexpr_baton *dlbaton; | |
6288 | struct call_site_parameter *parameter; | |
6289 | ||
6290 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6291 | { | |
6292 | /* Already printed the complaint above. */ | |
6293 | continue; | |
6294 | } | |
6295 | ||
6296 | gdb_assert (call_site->parameter_count < nparams); | |
6297 | parameter = &call_site->parameter[call_site->parameter_count]; | |
6298 | ||
6299 | /* DW_AT_location specifies the register number. Value of the data | |
6300 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
6301 | ||
6302 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
6303 | if (!attr || !attr_form_is_block (attr)) | |
6304 | { | |
6305 | complaint (&symfile_complaints, | |
6306 | _("No DW_FORM_block* DW_AT_location for " | |
6307 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6308 | child_die->offset, objfile->name); |
96408a79 SA |
6309 | continue; |
6310 | } | |
6311 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
6312 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
6313 | if (parameter->dwarf_reg == -1 | |
6314 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
6315 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
6316 | ¶meter->fb_offset)) | |
6317 | { | |
6318 | complaint (&symfile_complaints, | |
6319 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
6320 | "for DW_FORM_block* DW_AT_location for " | |
6321 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6322 | child_die->offset, objfile->name); |
96408a79 SA |
6323 | continue; |
6324 | } | |
6325 | ||
6326 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
6327 | if (!attr_form_is_block (attr)) | |
6328 | { | |
6329 | complaint (&symfile_complaints, | |
6330 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
6331 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6332 | child_die->offset, objfile->name); |
96408a79 SA |
6333 | continue; |
6334 | } | |
6335 | parameter->value = DW_BLOCK (attr)->data; | |
6336 | parameter->value_size = DW_BLOCK (attr)->size; | |
6337 | ||
6338 | /* Parameters are not pre-cleared by memset above. */ | |
6339 | parameter->data_value = NULL; | |
6340 | parameter->data_value_size = 0; | |
6341 | call_site->parameter_count++; | |
6342 | ||
6343 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
6344 | if (attr) | |
6345 | { | |
6346 | if (!attr_form_is_block (attr)) | |
6347 | complaint (&symfile_complaints, | |
6348 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
6349 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
bb5ed363 | 6350 | child_die->offset, objfile->name); |
96408a79 SA |
6351 | else |
6352 | { | |
6353 | parameter->data_value = DW_BLOCK (attr)->data; | |
6354 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
6355 | } | |
6356 | } | |
6357 | } | |
6358 | } | |
6359 | ||
43039443 | 6360 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
6361 | Return 1 if the attributes are present and valid, otherwise, return 0. |
6362 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
6363 | |
6364 | static int | |
6365 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
6366 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
6367 | struct partial_symtab *ranges_pst) | |
43039443 JK |
6368 | { |
6369 | struct objfile *objfile = cu->objfile; | |
6370 | struct comp_unit_head *cu_header = &cu->header; | |
6371 | bfd *obfd = objfile->obfd; | |
6372 | unsigned int addr_size = cu_header->addr_size; | |
6373 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6374 | /* Base address selection entry. */ | |
6375 | CORE_ADDR base; | |
6376 | int found_base; | |
6377 | unsigned int dummy; | |
6378 | gdb_byte *buffer; | |
6379 | CORE_ADDR marker; | |
6380 | int low_set; | |
6381 | CORE_ADDR low = 0; | |
6382 | CORE_ADDR high = 0; | |
ff013f42 | 6383 | CORE_ADDR baseaddr; |
43039443 | 6384 | |
d00adf39 DE |
6385 | found_base = cu->base_known; |
6386 | base = cu->base_address; | |
43039443 | 6387 | |
be391dca | 6388 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 6389 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
6390 | { |
6391 | complaint (&symfile_complaints, | |
6392 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
6393 | offset); | |
6394 | return 0; | |
6395 | } | |
dce234bc | 6396 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
6397 | |
6398 | /* Read in the largest possible address. */ | |
6399 | marker = read_address (obfd, buffer, cu, &dummy); | |
6400 | if ((marker & mask) == mask) | |
6401 | { | |
6402 | /* If we found the largest possible address, then | |
6403 | read the base address. */ | |
6404 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6405 | buffer += 2 * addr_size; | |
6406 | offset += 2 * addr_size; | |
6407 | found_base = 1; | |
6408 | } | |
6409 | ||
6410 | low_set = 0; | |
6411 | ||
e7030f15 | 6412 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 6413 | |
43039443 JK |
6414 | while (1) |
6415 | { | |
6416 | CORE_ADDR range_beginning, range_end; | |
6417 | ||
6418 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
6419 | buffer += addr_size; | |
6420 | range_end = read_address (obfd, buffer, cu, &dummy); | |
6421 | buffer += addr_size; | |
6422 | offset += 2 * addr_size; | |
6423 | ||
6424 | /* An end of list marker is a pair of zero addresses. */ | |
6425 | if (range_beginning == 0 && range_end == 0) | |
6426 | /* Found the end of list entry. */ | |
6427 | break; | |
6428 | ||
6429 | /* Each base address selection entry is a pair of 2 values. | |
6430 | The first is the largest possible address, the second is | |
6431 | the base address. Check for a base address here. */ | |
6432 | if ((range_beginning & mask) == mask) | |
6433 | { | |
6434 | /* If we found the largest possible address, then | |
6435 | read the base address. */ | |
6436 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6437 | found_base = 1; | |
6438 | continue; | |
6439 | } | |
6440 | ||
6441 | if (!found_base) | |
6442 | { | |
6443 | /* We have no valid base address for the ranges | |
6444 | data. */ | |
6445 | complaint (&symfile_complaints, | |
6446 | _("Invalid .debug_ranges data (no base address)")); | |
6447 | return 0; | |
6448 | } | |
6449 | ||
9277c30c UW |
6450 | if (range_beginning > range_end) |
6451 | { | |
6452 | /* Inverted range entries are invalid. */ | |
6453 | complaint (&symfile_complaints, | |
6454 | _("Invalid .debug_ranges data (inverted range)")); | |
6455 | return 0; | |
6456 | } | |
6457 | ||
6458 | /* Empty range entries have no effect. */ | |
6459 | if (range_beginning == range_end) | |
6460 | continue; | |
6461 | ||
43039443 JK |
6462 | range_beginning += base; |
6463 | range_end += base; | |
6464 | ||
9277c30c | 6465 | if (ranges_pst != NULL) |
ff013f42 | 6466 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6467 | range_beginning + baseaddr, |
6468 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6469 | ranges_pst); |
6470 | ||
43039443 JK |
6471 | /* FIXME: This is recording everything as a low-high |
6472 | segment of consecutive addresses. We should have a | |
6473 | data structure for discontiguous block ranges | |
6474 | instead. */ | |
6475 | if (! low_set) | |
6476 | { | |
6477 | low = range_beginning; | |
6478 | high = range_end; | |
6479 | low_set = 1; | |
6480 | } | |
6481 | else | |
6482 | { | |
6483 | if (range_beginning < low) | |
6484 | low = range_beginning; | |
6485 | if (range_end > high) | |
6486 | high = range_end; | |
6487 | } | |
6488 | } | |
6489 | ||
6490 | if (! low_set) | |
6491 | /* If the first entry is an end-of-list marker, the range | |
6492 | describes an empty scope, i.e. no instructions. */ | |
6493 | return 0; | |
6494 | ||
6495 | if (low_return) | |
6496 | *low_return = low; | |
6497 | if (high_return) | |
6498 | *high_return = high; | |
6499 | return 1; | |
6500 | } | |
6501 | ||
af34e669 DJ |
6502 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6503 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6504 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 6505 | static int |
af34e669 | 6506 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6507 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6508 | struct partial_symtab *pst) | |
c906108c SS |
6509 | { |
6510 | struct attribute *attr; | |
af34e669 DJ |
6511 | CORE_ADDR low = 0; |
6512 | CORE_ADDR high = 0; | |
6513 | int ret = 0; | |
c906108c | 6514 | |
e142c38c | 6515 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 6516 | if (attr) |
af34e669 DJ |
6517 | { |
6518 | high = DW_ADDR (attr); | |
e142c38c | 6519 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
6520 | if (attr) |
6521 | low = DW_ADDR (attr); | |
6522 | else | |
6523 | /* Found high w/o low attribute. */ | |
6524 | return 0; | |
6525 | ||
6526 | /* Found consecutive range of addresses. */ | |
6527 | ret = 1; | |
6528 | } | |
c906108c | 6529 | else |
af34e669 | 6530 | { |
e142c38c | 6531 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6532 | if (attr != NULL) |
6533 | { | |
af34e669 | 6534 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6535 | .debug_ranges section. */ |
d85a05f0 | 6536 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6537 | return 0; |
43039443 | 6538 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6539 | ret = -1; |
6540 | } | |
6541 | } | |
c906108c | 6542 | |
9373cf26 JK |
6543 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6544 | if (high <= low) | |
c906108c SS |
6545 | return 0; |
6546 | ||
6547 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6548 | eliminate duplicate copies of functions and vtables and such. | |
6549 | The linker will arbitrarily choose one and discard the others. | |
6550 | The AT_*_pc values for such functions refer to local labels in | |
6551 | these sections. If the section from that file was discarded, the | |
6552 | labels are not in the output, so the relocs get a value of 0. | |
6553 | If this is a discarded function, mark the pc bounds as invalid, | |
6554 | so that GDB will ignore it. */ | |
72dca2f5 | 6555 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6556 | return 0; |
6557 | ||
6558 | *lowpc = low; | |
96408a79 SA |
6559 | if (highpc) |
6560 | *highpc = high; | |
af34e669 | 6561 | return ret; |
c906108c SS |
6562 | } |
6563 | ||
b084d499 JB |
6564 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6565 | its low and high PC addresses. Do nothing if these addresses could not | |
6566 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6567 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6568 | ||
6569 | static void | |
6570 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6571 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6572 | struct dwarf2_cu *cu) | |
6573 | { | |
6574 | CORE_ADDR low, high; | |
6575 | struct die_info *child = die->child; | |
6576 | ||
d85a05f0 | 6577 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6578 | { |
6579 | *lowpc = min (*lowpc, low); | |
6580 | *highpc = max (*highpc, high); | |
6581 | } | |
6582 | ||
6583 | /* If the language does not allow nested subprograms (either inside | |
6584 | subprograms or lexical blocks), we're done. */ | |
6585 | if (cu->language != language_ada) | |
6586 | return; | |
6e70227d | 6587 | |
b084d499 JB |
6588 | /* Check all the children of the given DIE. If it contains nested |
6589 | subprograms, then check their pc bounds. Likewise, we need to | |
6590 | check lexical blocks as well, as they may also contain subprogram | |
6591 | definitions. */ | |
6592 | while (child && child->tag) | |
6593 | { | |
6594 | if (child->tag == DW_TAG_subprogram | |
6595 | || child->tag == DW_TAG_lexical_block) | |
6596 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6597 | child = sibling_die (child); | |
6598 | } | |
6599 | } | |
6600 | ||
fae299cd DC |
6601 | /* Get the low and high pc's represented by the scope DIE, and store |
6602 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6603 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6604 | ||
6605 | static void | |
6606 | get_scope_pc_bounds (struct die_info *die, | |
6607 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6608 | struct dwarf2_cu *cu) | |
6609 | { | |
6610 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6611 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6612 | CORE_ADDR current_low, current_high; | |
6613 | ||
d85a05f0 | 6614 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6615 | { |
6616 | best_low = current_low; | |
6617 | best_high = current_high; | |
6618 | } | |
6619 | else | |
6620 | { | |
6621 | struct die_info *child = die->child; | |
6622 | ||
6623 | while (child && child->tag) | |
6624 | { | |
6625 | switch (child->tag) { | |
6626 | case DW_TAG_subprogram: | |
b084d499 | 6627 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6628 | break; |
6629 | case DW_TAG_namespace: | |
f55ee35c | 6630 | case DW_TAG_module: |
fae299cd DC |
6631 | /* FIXME: carlton/2004-01-16: Should we do this for |
6632 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6633 | that current GCC's always emit the DIEs corresponding | |
6634 | to definitions of methods of classes as children of a | |
6635 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6636 | the DIEs giving the declarations, which could be | |
6637 | anywhere). But I don't see any reason why the | |
6638 | standards says that they have to be there. */ | |
6639 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6640 | ||
6641 | if (current_low != ((CORE_ADDR) -1)) | |
6642 | { | |
6643 | best_low = min (best_low, current_low); | |
6644 | best_high = max (best_high, current_high); | |
6645 | } | |
6646 | break; | |
6647 | default: | |
0963b4bd | 6648 | /* Ignore. */ |
fae299cd DC |
6649 | break; |
6650 | } | |
6651 | ||
6652 | child = sibling_die (child); | |
6653 | } | |
6654 | } | |
6655 | ||
6656 | *lowpc = best_low; | |
6657 | *highpc = best_high; | |
6658 | } | |
6659 | ||
801e3a5b JB |
6660 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6661 | in DIE. */ | |
6662 | static void | |
6663 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6664 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6665 | { | |
bb5ed363 | 6666 | struct objfile *objfile = cu->objfile; |
801e3a5b JB |
6667 | struct attribute *attr; |
6668 | ||
6669 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6670 | if (attr) | |
6671 | { | |
6672 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6673 | |
801e3a5b JB |
6674 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6675 | if (attr) | |
6676 | { | |
6677 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6678 | |
801e3a5b JB |
6679 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6680 | } | |
6681 | } | |
6682 | ||
6683 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6684 | if (attr) | |
6685 | { | |
bb5ed363 | 6686 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
6687 | |
6688 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6689 | address range list in the .debug_ranges section. */ | |
6690 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6691 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6692 | |
6693 | /* For some target architectures, but not others, the | |
6694 | read_address function sign-extends the addresses it returns. | |
6695 | To recognize base address selection entries, we need a | |
6696 | mask. */ | |
6697 | unsigned int addr_size = cu->header.addr_size; | |
6698 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6699 | ||
6700 | /* The base address, to which the next pair is relative. Note | |
6701 | that this 'base' is a DWARF concept: most entries in a range | |
6702 | list are relative, to reduce the number of relocs against the | |
6703 | debugging information. This is separate from this function's | |
6704 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6705 | information from a shared library based on the address at | |
6706 | which the library was loaded. */ | |
d00adf39 DE |
6707 | CORE_ADDR base = cu->base_address; |
6708 | int base_known = cu->base_known; | |
801e3a5b | 6709 | |
be391dca | 6710 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6711 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6712 | { |
6713 | complaint (&symfile_complaints, | |
6714 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6715 | offset); | |
6716 | return; | |
6717 | } | |
6718 | ||
6719 | for (;;) | |
6720 | { | |
6721 | unsigned int bytes_read; | |
6722 | CORE_ADDR start, end; | |
6723 | ||
6724 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6725 | buffer += bytes_read; | |
6726 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6727 | buffer += bytes_read; | |
6728 | ||
6729 | /* Did we find the end of the range list? */ | |
6730 | if (start == 0 && end == 0) | |
6731 | break; | |
6732 | ||
6733 | /* Did we find a base address selection entry? */ | |
6734 | else if ((start & base_select_mask) == base_select_mask) | |
6735 | { | |
6736 | base = end; | |
6737 | base_known = 1; | |
6738 | } | |
6739 | ||
6740 | /* We found an ordinary address range. */ | |
6741 | else | |
6742 | { | |
6743 | if (!base_known) | |
6744 | { | |
6745 | complaint (&symfile_complaints, | |
3e43a32a MS |
6746 | _("Invalid .debug_ranges data " |
6747 | "(no base address)")); | |
801e3a5b JB |
6748 | return; |
6749 | } | |
6750 | ||
9277c30c UW |
6751 | if (start > end) |
6752 | { | |
6753 | /* Inverted range entries are invalid. */ | |
6754 | complaint (&symfile_complaints, | |
6755 | _("Invalid .debug_ranges data " | |
6756 | "(inverted range)")); | |
6757 | return; | |
6758 | } | |
6759 | ||
6760 | /* Empty range entries have no effect. */ | |
6761 | if (start == end) | |
6762 | continue; | |
6763 | ||
6e70227d DE |
6764 | record_block_range (block, |
6765 | baseaddr + base + start, | |
801e3a5b JB |
6766 | baseaddr + base + end - 1); |
6767 | } | |
6768 | } | |
6769 | } | |
6770 | } | |
6771 | ||
60d5a603 JK |
6772 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
6773 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
6774 | during 4.6.0 experimental. */ | |
6775 | ||
6776 | static int | |
6777 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
6778 | { | |
6779 | const char *cs; | |
6780 | int major, minor, release; | |
6781 | ||
6782 | if (cu->producer == NULL) | |
6783 | { | |
6784 | /* For unknown compilers expect their behavior is DWARF version | |
6785 | compliant. | |
6786 | ||
6787 | GCC started to support .debug_types sections by -gdwarf-4 since | |
6788 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
6789 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
6790 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
6791 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
6792 | ||
6793 | return 0; | |
6794 | } | |
6795 | ||
6796 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ | |
6797 | ||
6798 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
6799 | { | |
6800 | /* For non-GCC compilers expect their behavior is DWARF version | |
6801 | compliant. */ | |
6802 | ||
6803 | return 0; | |
6804 | } | |
6805 | cs = &cu->producer[strlen ("GNU ")]; | |
6806 | while (*cs && !isdigit (*cs)) | |
6807 | cs++; | |
6808 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
6809 | { | |
6810 | /* Not recognized as GCC. */ | |
6811 | ||
6812 | return 0; | |
6813 | } | |
6814 | ||
6815 | return major < 4 || (major == 4 && minor < 6); | |
6816 | } | |
6817 | ||
6818 | /* Return the default accessibility type if it is not overriden by | |
6819 | DW_AT_accessibility. */ | |
6820 | ||
6821 | static enum dwarf_access_attribute | |
6822 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
6823 | { | |
6824 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
6825 | { | |
6826 | /* The default DWARF 2 accessibility for members is public, the default | |
6827 | accessibility for inheritance is private. */ | |
6828 | ||
6829 | if (die->tag != DW_TAG_inheritance) | |
6830 | return DW_ACCESS_public; | |
6831 | else | |
6832 | return DW_ACCESS_private; | |
6833 | } | |
6834 | else | |
6835 | { | |
6836 | /* DWARF 3+ defines the default accessibility a different way. The same | |
6837 | rules apply now for DW_TAG_inheritance as for the members and it only | |
6838 | depends on the container kind. */ | |
6839 | ||
6840 | if (die->parent->tag == DW_TAG_class_type) | |
6841 | return DW_ACCESS_private; | |
6842 | else | |
6843 | return DW_ACCESS_public; | |
6844 | } | |
6845 | } | |
6846 | ||
74ac6d43 TT |
6847 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
6848 | offset. If the attribute was not found return 0, otherwise return | |
6849 | 1. If it was found but could not properly be handled, set *OFFSET | |
6850 | to 0. */ | |
6851 | ||
6852 | static int | |
6853 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
6854 | LONGEST *offset) | |
6855 | { | |
6856 | struct attribute *attr; | |
6857 | ||
6858 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
6859 | if (attr != NULL) | |
6860 | { | |
6861 | *offset = 0; | |
6862 | ||
6863 | /* Note that we do not check for a section offset first here. | |
6864 | This is because DW_AT_data_member_location is new in DWARF 4, | |
6865 | so if we see it, we can assume that a constant form is really | |
6866 | a constant and not a section offset. */ | |
6867 | if (attr_form_is_constant (attr)) | |
6868 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
6869 | else if (attr_form_is_section_offset (attr)) | |
6870 | dwarf2_complex_location_expr_complaint (); | |
6871 | else if (attr_form_is_block (attr)) | |
6872 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6873 | else | |
6874 | dwarf2_complex_location_expr_complaint (); | |
6875 | ||
6876 | return 1; | |
6877 | } | |
6878 | ||
6879 | return 0; | |
6880 | } | |
6881 | ||
c906108c SS |
6882 | /* Add an aggregate field to the field list. */ |
6883 | ||
6884 | static void | |
107d2387 | 6885 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6886 | struct dwarf2_cu *cu) |
6e70227d | 6887 | { |
e7c27a73 | 6888 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6889 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6890 | struct nextfield *new_field; |
6891 | struct attribute *attr; | |
6892 | struct field *fp; | |
6893 | char *fieldname = ""; | |
6894 | ||
6895 | /* Allocate a new field list entry and link it in. */ | |
6896 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6897 | make_cleanup (xfree, new_field); |
c906108c | 6898 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6899 | |
6900 | if (die->tag == DW_TAG_inheritance) | |
6901 | { | |
6902 | new_field->next = fip->baseclasses; | |
6903 | fip->baseclasses = new_field; | |
6904 | } | |
6905 | else | |
6906 | { | |
6907 | new_field->next = fip->fields; | |
6908 | fip->fields = new_field; | |
6909 | } | |
c906108c SS |
6910 | fip->nfields++; |
6911 | ||
e142c38c | 6912 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6913 | if (attr) |
6914 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
6915 | else |
6916 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
6917 | if (new_field->accessibility != DW_ACCESS_public) |
6918 | fip->non_public_fields = 1; | |
60d5a603 | 6919 | |
e142c38c | 6920 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6921 | if (attr) |
6922 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
6923 | else |
6924 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
6925 | |
6926 | fp = &new_field->field; | |
a9a9bd0f | 6927 | |
e142c38c | 6928 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6929 | { |
74ac6d43 TT |
6930 | LONGEST offset; |
6931 | ||
a9a9bd0f | 6932 | /* Data member other than a C++ static data member. */ |
6e70227d | 6933 | |
c906108c | 6934 | /* Get type of field. */ |
e7c27a73 | 6935 | fp->type = die_type (die, cu); |
c906108c | 6936 | |
d6a843b5 | 6937 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6938 | |
c906108c | 6939 | /* Get bit size of field (zero if none). */ |
e142c38c | 6940 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6941 | if (attr) |
6942 | { | |
6943 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6944 | } | |
6945 | else | |
6946 | { | |
6947 | FIELD_BITSIZE (*fp) = 0; | |
6948 | } | |
6949 | ||
6950 | /* Get bit offset of field. */ | |
74ac6d43 TT |
6951 | if (handle_data_member_location (die, cu, &offset)) |
6952 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 6953 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6954 | if (attr) |
6955 | { | |
5e2b427d | 6956 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6957 | { |
6958 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6959 | additional bit offset from the MSB of the containing |
6960 | anonymous object to the MSB of the field. We don't | |
6961 | have to do anything special since we don't need to | |
6962 | know the size of the anonymous object. */ | |
c906108c SS |
6963 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6964 | } | |
6965 | else | |
6966 | { | |
6967 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6968 | MSB of the anonymous object, subtract off the number of |
6969 | bits from the MSB of the field to the MSB of the | |
6970 | object, and then subtract off the number of bits of | |
6971 | the field itself. The result is the bit offset of | |
6972 | the LSB of the field. */ | |
c906108c SS |
6973 | int anonymous_size; |
6974 | int bit_offset = DW_UNSND (attr); | |
6975 | ||
e142c38c | 6976 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6977 | if (attr) |
6978 | { | |
6979 | /* The size of the anonymous object containing | |
6980 | the bit field is explicit, so use the | |
6981 | indicated size (in bytes). */ | |
6982 | anonymous_size = DW_UNSND (attr); | |
6983 | } | |
6984 | else | |
6985 | { | |
6986 | /* The size of the anonymous object containing | |
6987 | the bit field must be inferred from the type | |
6988 | attribute of the data member containing the | |
6989 | bit field. */ | |
6990 | anonymous_size = TYPE_LENGTH (fp->type); | |
6991 | } | |
6992 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
6993 | - bit_offset - FIELD_BITSIZE (*fp); | |
6994 | } | |
6995 | } | |
6996 | ||
6997 | /* Get name of field. */ | |
39cbfefa DJ |
6998 | fieldname = dwarf2_name (die, cu); |
6999 | if (fieldname == NULL) | |
7000 | fieldname = ""; | |
d8151005 DJ |
7001 | |
7002 | /* The name is already allocated along with this objfile, so we don't | |
7003 | need to duplicate it for the type. */ | |
7004 | fp->name = fieldname; | |
c906108c SS |
7005 | |
7006 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 7007 | pointer or virtual base class pointer) to private. */ |
e142c38c | 7008 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 7009 | { |
d48cc9dd | 7010 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
7011 | new_field->accessibility = DW_ACCESS_private; |
7012 | fip->non_public_fields = 1; | |
7013 | } | |
7014 | } | |
a9a9bd0f | 7015 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 7016 | { |
a9a9bd0f DC |
7017 | /* C++ static member. */ |
7018 | ||
7019 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
7020 | is a declaration, but all versions of G++ as of this writing | |
7021 | (so through at least 3.2.1) incorrectly generate | |
7022 | DW_TAG_variable tags. */ | |
6e70227d | 7023 | |
ff355380 | 7024 | const char *physname; |
c906108c | 7025 | |
a9a9bd0f | 7026 | /* Get name of field. */ |
39cbfefa DJ |
7027 | fieldname = dwarf2_name (die, cu); |
7028 | if (fieldname == NULL) | |
c906108c SS |
7029 | return; |
7030 | ||
254e6b9e | 7031 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
7032 | if (attr |
7033 | /* Only create a symbol if this is an external value. | |
7034 | new_symbol checks this and puts the value in the global symbol | |
7035 | table, which we want. If it is not external, new_symbol | |
7036 | will try to put the value in cu->list_in_scope which is wrong. */ | |
7037 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
7038 | { |
7039 | /* A static const member, not much different than an enum as far as | |
7040 | we're concerned, except that we can support more types. */ | |
7041 | new_symbol (die, NULL, cu); | |
7042 | } | |
7043 | ||
2df3850c | 7044 | /* Get physical name. */ |
ff355380 | 7045 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 7046 | |
d8151005 DJ |
7047 | /* The name is already allocated along with this objfile, so we don't |
7048 | need to duplicate it for the type. */ | |
7049 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 7050 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 7051 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
7052 | } |
7053 | else if (die->tag == DW_TAG_inheritance) | |
7054 | { | |
74ac6d43 | 7055 | LONGEST offset; |
d4b96c9a | 7056 | |
74ac6d43 TT |
7057 | /* C++ base class field. */ |
7058 | if (handle_data_member_location (die, cu, &offset)) | |
7059 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 7060 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 7061 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
7062 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
7063 | fip->nbaseclasses++; | |
7064 | } | |
7065 | } | |
7066 | ||
98751a41 JK |
7067 | /* Add a typedef defined in the scope of the FIP's class. */ |
7068 | ||
7069 | static void | |
7070 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
7071 | struct dwarf2_cu *cu) | |
6e70227d | 7072 | { |
98751a41 | 7073 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
7074 | struct typedef_field_list *new_field; |
7075 | struct attribute *attr; | |
7076 | struct typedef_field *fp; | |
7077 | char *fieldname = ""; | |
7078 | ||
7079 | /* Allocate a new field list entry and link it in. */ | |
7080 | new_field = xzalloc (sizeof (*new_field)); | |
7081 | make_cleanup (xfree, new_field); | |
7082 | ||
7083 | gdb_assert (die->tag == DW_TAG_typedef); | |
7084 | ||
7085 | fp = &new_field->field; | |
7086 | ||
7087 | /* Get name of field. */ | |
7088 | fp->name = dwarf2_name (die, cu); | |
7089 | if (fp->name == NULL) | |
7090 | return; | |
7091 | ||
7092 | fp->type = read_type_die (die, cu); | |
7093 | ||
7094 | new_field->next = fip->typedef_field_list; | |
7095 | fip->typedef_field_list = new_field; | |
7096 | fip->typedef_field_list_count++; | |
7097 | } | |
7098 | ||
c906108c SS |
7099 | /* Create the vector of fields, and attach it to the type. */ |
7100 | ||
7101 | static void | |
fba45db2 | 7102 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7103 | struct dwarf2_cu *cu) |
c906108c SS |
7104 | { |
7105 | int nfields = fip->nfields; | |
7106 | ||
7107 | /* Record the field count, allocate space for the array of fields, | |
7108 | and create blank accessibility bitfields if necessary. */ | |
7109 | TYPE_NFIELDS (type) = nfields; | |
7110 | TYPE_FIELDS (type) = (struct field *) | |
7111 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
7112 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
7113 | ||
b4ba55a1 | 7114 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
7115 | { |
7116 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7117 | ||
7118 | TYPE_FIELD_PRIVATE_BITS (type) = | |
7119 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7120 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
7121 | ||
7122 | TYPE_FIELD_PROTECTED_BITS (type) = | |
7123 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7124 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
7125 | ||
774b6a14 TT |
7126 | TYPE_FIELD_IGNORE_BITS (type) = |
7127 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7128 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
7129 | } |
7130 | ||
7131 | /* If the type has baseclasses, allocate and clear a bit vector for | |
7132 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 7133 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
7134 | { |
7135 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 7136 | unsigned char *pointer; |
c906108c SS |
7137 | |
7138 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
7139 | pointer = TYPE_ALLOC (type, num_bytes); |
7140 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
7141 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
7142 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
7143 | } | |
7144 | ||
3e43a32a MS |
7145 | /* Copy the saved-up fields into the field vector. Start from the head of |
7146 | the list, adding to the tail of the field array, so that they end up in | |
7147 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
7148 | while (nfields-- > 0) |
7149 | { | |
7d0ccb61 DJ |
7150 | struct nextfield *fieldp; |
7151 | ||
7152 | if (fip->fields) | |
7153 | { | |
7154 | fieldp = fip->fields; | |
7155 | fip->fields = fieldp->next; | |
7156 | } | |
7157 | else | |
7158 | { | |
7159 | fieldp = fip->baseclasses; | |
7160 | fip->baseclasses = fieldp->next; | |
7161 | } | |
7162 | ||
7163 | TYPE_FIELD (type, nfields) = fieldp->field; | |
7164 | switch (fieldp->accessibility) | |
c906108c | 7165 | { |
c5aa993b | 7166 | case DW_ACCESS_private: |
b4ba55a1 JB |
7167 | if (cu->language != language_ada) |
7168 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 7169 | break; |
c906108c | 7170 | |
c5aa993b | 7171 | case DW_ACCESS_protected: |
b4ba55a1 JB |
7172 | if (cu->language != language_ada) |
7173 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 7174 | break; |
c906108c | 7175 | |
c5aa993b JM |
7176 | case DW_ACCESS_public: |
7177 | break; | |
c906108c | 7178 | |
c5aa993b JM |
7179 | default: |
7180 | /* Unknown accessibility. Complain and treat it as public. */ | |
7181 | { | |
e2e0b3e5 | 7182 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 7183 | fieldp->accessibility); |
c5aa993b JM |
7184 | } |
7185 | break; | |
c906108c SS |
7186 | } |
7187 | if (nfields < fip->nbaseclasses) | |
7188 | { | |
7d0ccb61 | 7189 | switch (fieldp->virtuality) |
c906108c | 7190 | { |
c5aa993b JM |
7191 | case DW_VIRTUALITY_virtual: |
7192 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 7193 | if (cu->language == language_ada) |
a73c6dcd | 7194 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
7195 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
7196 | break; | |
c906108c SS |
7197 | } |
7198 | } | |
c906108c SS |
7199 | } |
7200 | } | |
7201 | ||
c906108c SS |
7202 | /* Add a member function to the proper fieldlist. */ |
7203 | ||
7204 | static void | |
107d2387 | 7205 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7206 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 7207 | { |
e7c27a73 | 7208 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7209 | struct attribute *attr; |
7210 | struct fnfieldlist *flp; | |
7211 | int i; | |
7212 | struct fn_field *fnp; | |
7213 | char *fieldname; | |
c906108c | 7214 | struct nextfnfield *new_fnfield; |
f792889a | 7215 | struct type *this_type; |
60d5a603 | 7216 | enum dwarf_access_attribute accessibility; |
c906108c | 7217 | |
b4ba55a1 | 7218 | if (cu->language == language_ada) |
a73c6dcd | 7219 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 7220 | |
2df3850c | 7221 | /* Get name of member function. */ |
39cbfefa DJ |
7222 | fieldname = dwarf2_name (die, cu); |
7223 | if (fieldname == NULL) | |
2df3850c | 7224 | return; |
c906108c | 7225 | |
c906108c SS |
7226 | /* Look up member function name in fieldlist. */ |
7227 | for (i = 0; i < fip->nfnfields; i++) | |
7228 | { | |
27bfe10e | 7229 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
7230 | break; |
7231 | } | |
7232 | ||
7233 | /* Create new list element if necessary. */ | |
7234 | if (i < fip->nfnfields) | |
7235 | flp = &fip->fnfieldlists[i]; | |
7236 | else | |
7237 | { | |
7238 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7239 | { | |
7240 | fip->fnfieldlists = (struct fnfieldlist *) | |
7241 | xrealloc (fip->fnfieldlists, | |
7242 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7243 | * sizeof (struct fnfieldlist)); |
c906108c | 7244 | if (fip->nfnfields == 0) |
c13c43fd | 7245 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
7246 | } |
7247 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
7248 | flp->name = fieldname; | |
7249 | flp->length = 0; | |
7250 | flp->head = NULL; | |
3da10d80 | 7251 | i = fip->nfnfields++; |
c906108c SS |
7252 | } |
7253 | ||
7254 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 7255 | entry. */ |
c906108c | 7256 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 7257 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
7258 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
7259 | new_fnfield->next = flp->head; | |
7260 | flp->head = new_fnfield; | |
7261 | flp->length++; | |
7262 | ||
7263 | /* Fill in the member function field info. */ | |
7264 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
7265 | |
7266 | /* Delay processing of the physname until later. */ | |
7267 | if (cu->language == language_cplus || cu->language == language_java) | |
7268 | { | |
7269 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
7270 | die, cu); | |
7271 | } | |
7272 | else | |
7273 | { | |
1d06ead6 | 7274 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
7275 | fnp->physname = physname ? physname : ""; |
7276 | } | |
7277 | ||
c906108c | 7278 | fnp->type = alloc_type (objfile); |
f792889a DJ |
7279 | this_type = read_type_die (die, cu); |
7280 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 7281 | { |
f792889a | 7282 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 7283 | |
f792889a | 7284 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
7285 | of the method itself (TYPE_CODE_METHOD). */ |
7286 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
7287 | TYPE_TARGET_TYPE (this_type), |
7288 | TYPE_FIELDS (this_type), | |
7289 | TYPE_NFIELDS (this_type), | |
7290 | TYPE_VARARGS (this_type)); | |
c906108c SS |
7291 | |
7292 | /* Handle static member functions. | |
c5aa993b | 7293 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
7294 | member functions. G++ helps GDB by marking the first |
7295 | parameter for non-static member functions (which is the this | |
7296 | pointer) as artificial. We obtain this information from | |
7297 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 7298 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
7299 | fnp->voffset = VOFFSET_STATIC; |
7300 | } | |
7301 | else | |
e2e0b3e5 | 7302 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 7303 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
7304 | |
7305 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 7306 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 7307 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 7308 | |
3e43a32a MS |
7309 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
7310 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
7311 | |
7312 | /* Get accessibility. */ | |
e142c38c | 7313 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 7314 | if (attr) |
60d5a603 JK |
7315 | accessibility = DW_UNSND (attr); |
7316 | else | |
7317 | accessibility = dwarf2_default_access_attribute (die, cu); | |
7318 | switch (accessibility) | |
c906108c | 7319 | { |
60d5a603 JK |
7320 | case DW_ACCESS_private: |
7321 | fnp->is_private = 1; | |
7322 | break; | |
7323 | case DW_ACCESS_protected: | |
7324 | fnp->is_protected = 1; | |
7325 | break; | |
c906108c SS |
7326 | } |
7327 | ||
b02dede2 | 7328 | /* Check for artificial methods. */ |
e142c38c | 7329 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
7330 | if (attr && DW_UNSND (attr) != 0) |
7331 | fnp->is_artificial = 1; | |
7332 | ||
0d564a31 | 7333 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
7334 | function. For older versions of GCC, this is an offset in the |
7335 | appropriate virtual table, as specified by DW_AT_containing_type. | |
7336 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
7337 | to the object address. */ |
7338 | ||
e142c38c | 7339 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 7340 | if (attr) |
8e19ed76 | 7341 | { |
aec5aa8b | 7342 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 7343 | { |
aec5aa8b TT |
7344 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
7345 | { | |
7346 | /* Old-style GCC. */ | |
7347 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
7348 | } | |
7349 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7350 | || (DW_BLOCK (attr)->size > 1 | |
7351 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
7352 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
7353 | { | |
7354 | struct dwarf_block blk; | |
7355 | int offset; | |
7356 | ||
7357 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7358 | ? 1 : 2); | |
7359 | blk.size = DW_BLOCK (attr)->size - offset; | |
7360 | blk.data = DW_BLOCK (attr)->data + offset; | |
7361 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
7362 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
7363 | dwarf2_complex_location_expr_complaint (); | |
7364 | else | |
7365 | fnp->voffset /= cu->header.addr_size; | |
7366 | fnp->voffset += 2; | |
7367 | } | |
7368 | else | |
7369 | dwarf2_complex_location_expr_complaint (); | |
7370 | ||
7371 | if (!fnp->fcontext) | |
7372 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
7373 | } | |
3690dd37 | 7374 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7375 | { |
4d3c2250 | 7376 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7377 | } |
7378 | else | |
7379 | { | |
4d3c2250 KB |
7380 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
7381 | fieldname); | |
8e19ed76 | 7382 | } |
0d564a31 | 7383 | } |
d48cc9dd DJ |
7384 | else |
7385 | { | |
7386 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
7387 | if (attr && DW_UNSND (attr)) | |
7388 | { | |
7389 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
7390 | complaint (&symfile_complaints, | |
3e43a32a MS |
7391 | _("Member function \"%s\" (offset %d) is virtual " |
7392 | "but the vtable offset is not specified"), | |
d48cc9dd | 7393 | fieldname, die->offset); |
9655fd1a | 7394 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
7395 | TYPE_CPLUS_DYNAMIC (type) = 1; |
7396 | } | |
7397 | } | |
c906108c SS |
7398 | } |
7399 | ||
7400 | /* Create the vector of member function fields, and attach it to the type. */ | |
7401 | ||
7402 | static void | |
fba45db2 | 7403 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7404 | struct dwarf2_cu *cu) |
c906108c SS |
7405 | { |
7406 | struct fnfieldlist *flp; | |
c906108c SS |
7407 | int i; |
7408 | ||
b4ba55a1 | 7409 | if (cu->language == language_ada) |
a73c6dcd | 7410 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 7411 | |
c906108c SS |
7412 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
7413 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
7414 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
7415 | ||
7416 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
7417 | { | |
7418 | struct nextfnfield *nfp = flp->head; | |
7419 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
7420 | int k; | |
7421 | ||
7422 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
7423 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
7424 | fn_flp->fn_fields = (struct fn_field *) | |
7425 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
7426 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 7427 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
7428 | } |
7429 | ||
7430 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
7431 | } |
7432 | ||
1168df01 JB |
7433 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
7434 | language, zero otherwise. */ | |
7435 | static int | |
7436 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
7437 | { | |
7438 | static const char vptr[] = "_vptr"; | |
987504bb | 7439 | static const char vtable[] = "vtable"; |
1168df01 | 7440 | |
987504bb JJ |
7441 | /* Look for the C++ and Java forms of the vtable. */ |
7442 | if ((cu->language == language_java | |
7443 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
7444 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7445 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7446 | return 1; |
7447 | ||
7448 | return 0; | |
7449 | } | |
7450 | ||
c0dd20ea | 7451 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7452 | functions, with the ABI-specified layout. If TYPE describes |
7453 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7454 | |
7455 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7456 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7457 | |
0b92b5bb TT |
7458 | static void |
7459 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7460 | { |
0b92b5bb | 7461 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7462 | |
7463 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7464 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7465 | return; | |
c0dd20ea DJ |
7466 | |
7467 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7468 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7469 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7470 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7471 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7472 | return; | |
c0dd20ea DJ |
7473 | |
7474 | /* Find the type of the method. */ | |
0b92b5bb | 7475 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7476 | if (pfn_type == NULL |
7477 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7478 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7479 | return; |
c0dd20ea DJ |
7480 | |
7481 | /* Look for the "this" argument. */ | |
7482 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7483 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7484 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7485 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7486 | return; |
c0dd20ea DJ |
7487 | |
7488 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7489 | new_type = alloc_type (objfile); |
7490 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7491 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7492 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7493 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7494 | } |
1168df01 | 7495 | |
c906108c | 7496 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7497 | (definition) to create a type for the structure or union. Fill in |
7498 | the type's name and general properties; the members will not be | |
7499 | processed until process_structure_type. | |
c906108c | 7500 | |
c767944b DJ |
7501 | NOTE: we need to call these functions regardless of whether or not the |
7502 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7503 | structure or union. This gets the type entered into our set of |
7504 | user defined types. | |
7505 | ||
7506 | However, if the structure is incomplete (an opaque struct/union) | |
7507 | then suppress creating a symbol table entry for it since gdb only | |
7508 | wants to find the one with the complete definition. Note that if | |
7509 | it is complete, we just call new_symbol, which does it's own | |
7510 | checking about whether the struct/union is anonymous or not (and | |
7511 | suppresses creating a symbol table entry itself). */ | |
7512 | ||
f792889a | 7513 | static struct type * |
134d01f1 | 7514 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7515 | { |
e7c27a73 | 7516 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7517 | struct type *type; |
7518 | struct attribute *attr; | |
39cbfefa | 7519 | char *name; |
c906108c | 7520 | |
348e048f DE |
7521 | /* If the definition of this type lives in .debug_types, read that type. |
7522 | Don't follow DW_AT_specification though, that will take us back up | |
7523 | the chain and we want to go down. */ | |
7524 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7525 | if (attr) | |
7526 | { | |
7527 | struct dwarf2_cu *type_cu = cu; | |
7528 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7529 | |
348e048f DE |
7530 | /* We could just recurse on read_structure_type, but we need to call |
7531 | get_die_type to ensure only one type for this DIE is created. | |
7532 | This is important, for example, because for c++ classes we need | |
7533 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7534 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7535 | |
7536 | /* TYPE_CU may not be the same as CU. | |
7537 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7538 | return set_die_type (die, type, cu); |
7539 | } | |
7540 | ||
c0dd20ea | 7541 | type = alloc_type (objfile); |
c906108c | 7542 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7543 | |
39cbfefa DJ |
7544 | name = dwarf2_name (die, cu); |
7545 | if (name != NULL) | |
c906108c | 7546 | { |
987504bb JJ |
7547 | if (cu->language == language_cplus |
7548 | || cu->language == language_java) | |
63d06c5c | 7549 | { |
3da10d80 KS |
7550 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7551 | ||
7552 | /* dwarf2_full_name might have already finished building the DIE's | |
7553 | type. If so, there is no need to continue. */ | |
7554 | if (get_die_type (die, cu) != NULL) | |
7555 | return get_die_type (die, cu); | |
7556 | ||
7557 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7558 | if (die->tag == DW_TAG_structure_type |
7559 | || die->tag == DW_TAG_class_type) | |
7560 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7561 | } |
7562 | else | |
7563 | { | |
d8151005 DJ |
7564 | /* The name is already allocated along with this objfile, so |
7565 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7566 | TYPE_TAG_NAME (type) = (char *) name; |
7567 | if (die->tag == DW_TAG_class_type) | |
7568 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7569 | } |
c906108c SS |
7570 | } |
7571 | ||
7572 | if (die->tag == DW_TAG_structure_type) | |
7573 | { | |
7574 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7575 | } | |
7576 | else if (die->tag == DW_TAG_union_type) | |
7577 | { | |
7578 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7579 | } | |
7580 | else | |
7581 | { | |
c906108c SS |
7582 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7583 | } | |
7584 | ||
0cc2414c TT |
7585 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7586 | TYPE_DECLARED_CLASS (type) = 1; | |
7587 | ||
e142c38c | 7588 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7589 | if (attr) |
7590 | { | |
7591 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7592 | } | |
7593 | else | |
7594 | { | |
7595 | TYPE_LENGTH (type) = 0; | |
7596 | } | |
7597 | ||
876cecd0 | 7598 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7599 | if (die_is_declaration (die, cu)) |
876cecd0 | 7600 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7601 | else if (attr == NULL && die->child == NULL |
7602 | && producer_is_realview (cu->producer)) | |
7603 | /* RealView does not output the required DW_AT_declaration | |
7604 | on incomplete types. */ | |
7605 | TYPE_STUB (type) = 1; | |
dc718098 | 7606 | |
c906108c SS |
7607 | /* We need to add the type field to the die immediately so we don't |
7608 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7609 | type within the structure itself. */ |
1c379e20 | 7610 | set_die_type (die, type, cu); |
c906108c | 7611 | |
7e314c57 JK |
7612 | /* set_die_type should be already done. */ |
7613 | set_descriptive_type (type, die, cu); | |
7614 | ||
c767944b DJ |
7615 | return type; |
7616 | } | |
7617 | ||
7618 | /* Finish creating a structure or union type, including filling in | |
7619 | its members and creating a symbol for it. */ | |
7620 | ||
7621 | static void | |
7622 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7623 | { | |
7624 | struct objfile *objfile = cu->objfile; | |
7625 | struct die_info *child_die = die->child; | |
7626 | struct type *type; | |
7627 | ||
7628 | type = get_die_type (die, cu); | |
7629 | if (type == NULL) | |
7630 | type = read_structure_type (die, cu); | |
7631 | ||
e142c38c | 7632 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7633 | { |
7634 | struct field_info fi; | |
7635 | struct die_info *child_die; | |
34eaf542 | 7636 | VEC (symbolp) *template_args = NULL; |
c767944b | 7637 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7638 | |
7639 | memset (&fi, 0, sizeof (struct field_info)); | |
7640 | ||
639d11d3 | 7641 | child_die = die->child; |
c906108c SS |
7642 | |
7643 | while (child_die && child_die->tag) | |
7644 | { | |
a9a9bd0f DC |
7645 | if (child_die->tag == DW_TAG_member |
7646 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7647 | { |
a9a9bd0f DC |
7648 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7649 | should be a DW_TAG_member that is a declaration, but | |
7650 | all versions of G++ as of this writing (so through at | |
7651 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7652 | tags for them instead. */ | |
e7c27a73 | 7653 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7654 | } |
8713b1b1 | 7655 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7656 | { |
0963b4bd | 7657 | /* C++ member function. */ |
e7c27a73 | 7658 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7659 | } |
7660 | else if (child_die->tag == DW_TAG_inheritance) | |
7661 | { | |
7662 | /* C++ base class field. */ | |
e7c27a73 | 7663 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7664 | } |
98751a41 JK |
7665 | else if (child_die->tag == DW_TAG_typedef) |
7666 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7667 | else if (child_die->tag == DW_TAG_template_type_param |
7668 | || child_die->tag == DW_TAG_template_value_param) | |
7669 | { | |
7670 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7671 | ||
f1078f66 DJ |
7672 | if (arg != NULL) |
7673 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7674 | } |
7675 | ||
c906108c SS |
7676 | child_die = sibling_die (child_die); |
7677 | } | |
7678 | ||
34eaf542 TT |
7679 | /* Attach template arguments to type. */ |
7680 | if (! VEC_empty (symbolp, template_args)) | |
7681 | { | |
7682 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7683 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7684 | = VEC_length (symbolp, template_args); | |
7685 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7686 | = obstack_alloc (&objfile->objfile_obstack, | |
7687 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7688 | * sizeof (struct symbol *))); | |
7689 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7690 | VEC_address (symbolp, template_args), | |
7691 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7692 | * sizeof (struct symbol *))); | |
7693 | VEC_free (symbolp, template_args); | |
7694 | } | |
7695 | ||
c906108c SS |
7696 | /* Attach fields and member functions to the type. */ |
7697 | if (fi.nfields) | |
e7c27a73 | 7698 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7699 | if (fi.nfnfields) |
7700 | { | |
e7c27a73 | 7701 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7702 | |
c5aa993b | 7703 | /* Get the type which refers to the base class (possibly this |
c906108c | 7704 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7705 | class from the DW_AT_containing_type attribute. This use of |
7706 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7707 | |
e142c38c | 7708 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7709 | { |
e7c27a73 | 7710 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7711 | |
7712 | TYPE_VPTR_BASETYPE (type) = t; | |
7713 | if (type == t) | |
7714 | { | |
c906108c SS |
7715 | int i; |
7716 | ||
7717 | /* Our own class provides vtbl ptr. */ | |
7718 | for (i = TYPE_NFIELDS (t) - 1; | |
7719 | i >= TYPE_N_BASECLASSES (t); | |
7720 | --i) | |
7721 | { | |
7722 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
7723 | ||
1168df01 | 7724 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7725 | { |
7726 | TYPE_VPTR_FIELDNO (type) = i; | |
7727 | break; | |
7728 | } | |
7729 | } | |
7730 | ||
7731 | /* Complain if virtual function table field not found. */ | |
7732 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7733 | complaint (&symfile_complaints, |
3e43a32a MS |
7734 | _("virtual function table pointer " |
7735 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7736 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7737 | ""); | |
c906108c SS |
7738 | } |
7739 | else | |
7740 | { | |
7741 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7742 | } | |
7743 | } | |
f6235d4c EZ |
7744 | else if (cu->producer |
7745 | && strncmp (cu->producer, | |
7746 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7747 | { | |
7748 | /* The IBM XLC compiler does not provide direct indication | |
7749 | of the containing type, but the vtable pointer is | |
7750 | always named __vfp. */ | |
7751 | ||
7752 | int i; | |
7753 | ||
7754 | for (i = TYPE_NFIELDS (type) - 1; | |
7755 | i >= TYPE_N_BASECLASSES (type); | |
7756 | --i) | |
7757 | { | |
7758 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7759 | { | |
7760 | TYPE_VPTR_FIELDNO (type) = i; | |
7761 | TYPE_VPTR_BASETYPE (type) = type; | |
7762 | break; | |
7763 | } | |
7764 | } | |
7765 | } | |
c906108c | 7766 | } |
98751a41 JK |
7767 | |
7768 | /* Copy fi.typedef_field_list linked list elements content into the | |
7769 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7770 | if (fi.typedef_field_list) | |
7771 | { | |
7772 | int i = fi.typedef_field_list_count; | |
7773 | ||
a0d7a4ff | 7774 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7775 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7776 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7777 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7778 | ||
7779 | /* Reverse the list order to keep the debug info elements order. */ | |
7780 | while (--i >= 0) | |
7781 | { | |
7782 | struct typedef_field *dest, *src; | |
6e70227d | 7783 | |
98751a41 JK |
7784 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7785 | src = &fi.typedef_field_list->field; | |
7786 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7787 | *dest = *src; | |
7788 | } | |
7789 | } | |
c767944b DJ |
7790 | |
7791 | do_cleanups (back_to); | |
eb2a6f42 TT |
7792 | |
7793 | if (HAVE_CPLUS_STRUCT (type)) | |
7794 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 7795 | } |
63d06c5c | 7796 | |
bb5ed363 | 7797 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 7798 | |
90aeadfc DC |
7799 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7800 | snapshots) has been known to create a die giving a declaration | |
7801 | for a class that has, as a child, a die giving a definition for a | |
7802 | nested class. So we have to process our children even if the | |
7803 | current die is a declaration. Normally, of course, a declaration | |
7804 | won't have any children at all. */ | |
134d01f1 | 7805 | |
90aeadfc DC |
7806 | while (child_die != NULL && child_die->tag) |
7807 | { | |
7808 | if (child_die->tag == DW_TAG_member | |
7809 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7810 | || child_die->tag == DW_TAG_inheritance |
7811 | || child_die->tag == DW_TAG_template_value_param | |
7812 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7813 | { |
90aeadfc | 7814 | /* Do nothing. */ |
134d01f1 | 7815 | } |
90aeadfc DC |
7816 | else |
7817 | process_die (child_die, cu); | |
134d01f1 | 7818 | |
90aeadfc | 7819 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7820 | } |
7821 | ||
fa4028e9 JB |
7822 | /* Do not consider external references. According to the DWARF standard, |
7823 | these DIEs are identified by the fact that they have no byte_size | |
7824 | attribute, and a declaration attribute. */ | |
7825 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7826 | || !die_is_declaration (die, cu)) | |
c767944b | 7827 | new_symbol (die, type, cu); |
134d01f1 DJ |
7828 | } |
7829 | ||
7830 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7831 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7832 | |
f792889a | 7833 | static struct type * |
134d01f1 | 7834 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7835 | { |
e7c27a73 | 7836 | struct objfile *objfile = cu->objfile; |
c906108c | 7837 | struct type *type; |
c906108c | 7838 | struct attribute *attr; |
0114d602 | 7839 | const char *name; |
134d01f1 | 7840 | |
348e048f DE |
7841 | /* If the definition of this type lives in .debug_types, read that type. |
7842 | Don't follow DW_AT_specification though, that will take us back up | |
7843 | the chain and we want to go down. */ | |
7844 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7845 | if (attr) | |
7846 | { | |
7847 | struct dwarf2_cu *type_cu = cu; | |
7848 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7849 | |
348e048f | 7850 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7851 | |
7852 | /* TYPE_CU may not be the same as CU. | |
7853 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7854 | return set_die_type (die, type, cu); |
7855 | } | |
7856 | ||
c906108c SS |
7857 | type = alloc_type (objfile); |
7858 | ||
7859 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7860 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7861 | if (name != NULL) |
0114d602 | 7862 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7863 | |
e142c38c | 7864 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7865 | if (attr) |
7866 | { | |
7867 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7868 | } | |
7869 | else | |
7870 | { | |
7871 | TYPE_LENGTH (type) = 0; | |
7872 | } | |
7873 | ||
137033e9 JB |
7874 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7875 | declared as private in the package spec, and then defined only | |
7876 | inside the package body. Such types are known as Taft Amendment | |
7877 | Types. When another package uses such a type, an incomplete DIE | |
7878 | may be generated by the compiler. */ | |
02eb380e | 7879 | if (die_is_declaration (die, cu)) |
876cecd0 | 7880 | TYPE_STUB (type) = 1; |
02eb380e | 7881 | |
f792889a | 7882 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7883 | } |
7884 | ||
7885 | /* Given a pointer to a die which begins an enumeration, process all | |
7886 | the dies that define the members of the enumeration, and create the | |
7887 | symbol for the enumeration type. | |
7888 | ||
7889 | NOTE: We reverse the order of the element list. */ | |
7890 | ||
7891 | static void | |
7892 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7893 | { | |
f792889a | 7894 | struct type *this_type; |
134d01f1 | 7895 | |
f792889a DJ |
7896 | this_type = get_die_type (die, cu); |
7897 | if (this_type == NULL) | |
7898 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7899 | |
639d11d3 | 7900 | if (die->child != NULL) |
c906108c | 7901 | { |
9dc481d3 DE |
7902 | struct die_info *child_die; |
7903 | struct symbol *sym; | |
7904 | struct field *fields = NULL; | |
7905 | int num_fields = 0; | |
7906 | int unsigned_enum = 1; | |
7907 | char *name; | |
7908 | ||
639d11d3 | 7909 | child_die = die->child; |
c906108c SS |
7910 | while (child_die && child_die->tag) |
7911 | { | |
7912 | if (child_die->tag != DW_TAG_enumerator) | |
7913 | { | |
e7c27a73 | 7914 | process_die (child_die, cu); |
c906108c SS |
7915 | } |
7916 | else | |
7917 | { | |
39cbfefa DJ |
7918 | name = dwarf2_name (child_die, cu); |
7919 | if (name) | |
c906108c | 7920 | { |
f792889a | 7921 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7922 | if (SYMBOL_VALUE (sym) < 0) |
7923 | unsigned_enum = 0; | |
7924 | ||
7925 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7926 | { | |
7927 | fields = (struct field *) | |
7928 | xrealloc (fields, | |
7929 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7930 | * sizeof (struct field)); |
c906108c SS |
7931 | } |
7932 | ||
3567439c | 7933 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7934 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7935 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7936 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7937 | ||
7938 | num_fields++; | |
7939 | } | |
7940 | } | |
7941 | ||
7942 | child_die = sibling_die (child_die); | |
7943 | } | |
7944 | ||
7945 | if (num_fields) | |
7946 | { | |
f792889a DJ |
7947 | TYPE_NFIELDS (this_type) = num_fields; |
7948 | TYPE_FIELDS (this_type) = (struct field *) | |
7949 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7950 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7951 | sizeof (struct field) * num_fields); |
b8c9b27d | 7952 | xfree (fields); |
c906108c SS |
7953 | } |
7954 | if (unsigned_enum) | |
876cecd0 | 7955 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7956 | } |
134d01f1 | 7957 | |
6c83ed52 TT |
7958 | /* If we are reading an enum from a .debug_types unit, and the enum |
7959 | is a declaration, and the enum is not the signatured type in the | |
7960 | unit, then we do not want to add a symbol for it. Adding a | |
7961 | symbol would in some cases obscure the true definition of the | |
7962 | enum, giving users an incomplete type when the definition is | |
7963 | actually available. Note that we do not want to do this for all | |
7964 | enums which are just declarations, because C++0x allows forward | |
7965 | enum declarations. */ | |
b0df02fd | 7966 | if (cu->per_cu->debug_types_section |
6c83ed52 TT |
7967 | && die_is_declaration (die, cu)) |
7968 | { | |
7969 | struct signatured_type *type_sig; | |
7970 | ||
7971 | type_sig | |
7972 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, | |
b0df02fd | 7973 | cu->per_cu->debug_types_section, |
6c83ed52 TT |
7974 | cu->per_cu->offset); |
7975 | if (type_sig->type_offset != die->offset) | |
7976 | return; | |
7977 | } | |
7978 | ||
f792889a | 7979 | new_symbol (die, this_type, cu); |
c906108c SS |
7980 | } |
7981 | ||
7982 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7983 | the DIE's type field. For now, this only handles one dimensional | |
7984 | arrays. */ | |
7985 | ||
f792889a | 7986 | static struct type * |
e7c27a73 | 7987 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7988 | { |
e7c27a73 | 7989 | struct objfile *objfile = cu->objfile; |
c906108c | 7990 | struct die_info *child_die; |
7e314c57 | 7991 | struct type *type; |
c906108c SS |
7992 | struct type *element_type, *range_type, *index_type; |
7993 | struct type **range_types = NULL; | |
7994 | struct attribute *attr; | |
7995 | int ndim = 0; | |
7996 | struct cleanup *back_to; | |
39cbfefa | 7997 | char *name; |
c906108c | 7998 | |
e7c27a73 | 7999 | element_type = die_type (die, cu); |
c906108c | 8000 | |
7e314c57 JK |
8001 | /* The die_type call above may have already set the type for this DIE. */ |
8002 | type = get_die_type (die, cu); | |
8003 | if (type) | |
8004 | return type; | |
8005 | ||
c906108c SS |
8006 | /* Irix 6.2 native cc creates array types without children for |
8007 | arrays with unspecified length. */ | |
639d11d3 | 8008 | if (die->child == NULL) |
c906108c | 8009 | { |
46bf5051 | 8010 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8011 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
8012 | type = create_array_type (NULL, element_type, range_type); |
8013 | return set_die_type (die, type, cu); | |
c906108c SS |
8014 | } |
8015 | ||
8016 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 8017 | child_die = die->child; |
c906108c SS |
8018 | while (child_die && child_die->tag) |
8019 | { | |
8020 | if (child_die->tag == DW_TAG_subrange_type) | |
8021 | { | |
f792889a | 8022 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 8023 | |
f792889a | 8024 | if (child_type != NULL) |
a02abb62 | 8025 | { |
0963b4bd MS |
8026 | /* The range type was succesfully read. Save it for the |
8027 | array type creation. */ | |
a02abb62 JB |
8028 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
8029 | { | |
8030 | range_types = (struct type **) | |
8031 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
8032 | * sizeof (struct type *)); | |
8033 | if (ndim == 0) | |
8034 | make_cleanup (free_current_contents, &range_types); | |
8035 | } | |
f792889a | 8036 | range_types[ndim++] = child_type; |
a02abb62 | 8037 | } |
c906108c SS |
8038 | } |
8039 | child_die = sibling_die (child_die); | |
8040 | } | |
8041 | ||
8042 | /* Dwarf2 dimensions are output from left to right, create the | |
8043 | necessary array types in backwards order. */ | |
7ca2d3a3 | 8044 | |
c906108c | 8045 | type = element_type; |
7ca2d3a3 DL |
8046 | |
8047 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
8048 | { | |
8049 | int i = 0; | |
9a619af0 | 8050 | |
7ca2d3a3 DL |
8051 | while (i < ndim) |
8052 | type = create_array_type (NULL, type, range_types[i++]); | |
8053 | } | |
8054 | else | |
8055 | { | |
8056 | while (ndim-- > 0) | |
8057 | type = create_array_type (NULL, type, range_types[ndim]); | |
8058 | } | |
c906108c | 8059 | |
f5f8a009 EZ |
8060 | /* Understand Dwarf2 support for vector types (like they occur on |
8061 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
8062 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
8063 | custom vendor extension. The main difference between a regular | |
8064 | array and the vector variant is that vectors are passed by value | |
8065 | to functions. */ | |
e142c38c | 8066 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 8067 | if (attr) |
ea37ba09 | 8068 | make_vector_type (type); |
f5f8a009 | 8069 | |
dbc98a8b KW |
8070 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
8071 | implementation may choose to implement triple vectors using this | |
8072 | attribute. */ | |
8073 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
8074 | if (attr) | |
8075 | { | |
8076 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
8077 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8078 | else | |
3e43a32a MS |
8079 | complaint (&symfile_complaints, |
8080 | _("DW_AT_byte_size for array type smaller " | |
8081 | "than the total size of elements")); | |
dbc98a8b KW |
8082 | } |
8083 | ||
39cbfefa DJ |
8084 | name = dwarf2_name (die, cu); |
8085 | if (name) | |
8086 | TYPE_NAME (type) = name; | |
6e70227d | 8087 | |
0963b4bd | 8088 | /* Install the type in the die. */ |
7e314c57 JK |
8089 | set_die_type (die, type, cu); |
8090 | ||
8091 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8092 | set_descriptive_type (type, die, cu); |
8093 | ||
c906108c SS |
8094 | do_cleanups (back_to); |
8095 | ||
7e314c57 | 8096 | return type; |
c906108c SS |
8097 | } |
8098 | ||
7ca2d3a3 | 8099 | static enum dwarf_array_dim_ordering |
6e70227d | 8100 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
8101 | { |
8102 | struct attribute *attr; | |
8103 | ||
8104 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
8105 | ||
8106 | if (attr) return DW_SND (attr); | |
8107 | ||
0963b4bd MS |
8108 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
8109 | opposite order to the dwarf2 specification, but data is still | |
8110 | laid out as per normal fortran. | |
7ca2d3a3 | 8111 | |
0963b4bd MS |
8112 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
8113 | version checking. */ | |
7ca2d3a3 | 8114 | |
905e0470 PM |
8115 | if (cu->language == language_fortran |
8116 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
8117 | { |
8118 | return DW_ORD_row_major; | |
8119 | } | |
8120 | ||
6e70227d | 8121 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
8122 | { |
8123 | case array_column_major: | |
8124 | return DW_ORD_col_major; | |
8125 | case array_row_major: | |
8126 | default: | |
8127 | return DW_ORD_row_major; | |
8128 | }; | |
8129 | } | |
8130 | ||
72019c9c | 8131 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 8132 | the DIE's type field. */ |
72019c9c | 8133 | |
f792889a | 8134 | static struct type * |
72019c9c GM |
8135 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
8136 | { | |
7e314c57 JK |
8137 | struct type *domain_type, *set_type; |
8138 | struct attribute *attr; | |
f792889a | 8139 | |
7e314c57 JK |
8140 | domain_type = die_type (die, cu); |
8141 | ||
8142 | /* The die_type call above may have already set the type for this DIE. */ | |
8143 | set_type = get_die_type (die, cu); | |
8144 | if (set_type) | |
8145 | return set_type; | |
8146 | ||
8147 | set_type = create_set_type (NULL, domain_type); | |
8148 | ||
8149 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
8150 | if (attr) |
8151 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 8152 | |
f792889a | 8153 | return set_die_type (die, set_type, cu); |
72019c9c | 8154 | } |
7ca2d3a3 | 8155 | |
c906108c SS |
8156 | /* First cut: install each common block member as a global variable. */ |
8157 | ||
8158 | static void | |
e7c27a73 | 8159 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8160 | { |
8161 | struct die_info *child_die; | |
8162 | struct attribute *attr; | |
8163 | struct symbol *sym; | |
8164 | CORE_ADDR base = (CORE_ADDR) 0; | |
8165 | ||
e142c38c | 8166 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8167 | if (attr) |
8168 | { | |
0963b4bd | 8169 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
8170 | if (attr_form_is_block (attr)) |
8171 | { | |
e7c27a73 | 8172 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 8173 | } |
3690dd37 | 8174 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8175 | { |
4d3c2250 | 8176 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8177 | } |
8178 | else | |
8179 | { | |
4d3c2250 KB |
8180 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8181 | "common block member"); | |
8e19ed76 | 8182 | } |
c906108c | 8183 | } |
639d11d3 | 8184 | if (die->child != NULL) |
c906108c | 8185 | { |
639d11d3 | 8186 | child_die = die->child; |
c906108c SS |
8187 | while (child_die && child_die->tag) |
8188 | { | |
74ac6d43 TT |
8189 | LONGEST offset; |
8190 | ||
e7c27a73 | 8191 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
8192 | if (sym != NULL |
8193 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 8194 | { |
74ac6d43 | 8195 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
8196 | add_symbol_to_list (sym, &global_symbols); |
8197 | } | |
8198 | child_die = sibling_die (child_die); | |
8199 | } | |
8200 | } | |
8201 | } | |
8202 | ||
0114d602 | 8203 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 8204 | |
0114d602 DJ |
8205 | static struct type * |
8206 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 8207 | { |
e7c27a73 | 8208 | struct objfile *objfile = cu->objfile; |
0114d602 | 8209 | const char *previous_prefix, *name; |
9219021c | 8210 | int is_anonymous; |
0114d602 DJ |
8211 | struct type *type; |
8212 | ||
8213 | /* For extensions, reuse the type of the original namespace. */ | |
8214 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
8215 | { | |
8216 | struct die_info *ext_die; | |
8217 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 8218 | |
0114d602 DJ |
8219 | ext_die = dwarf2_extension (die, &ext_cu); |
8220 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
8221 | |
8222 | /* EXT_CU may not be the same as CU. | |
8223 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
8224 | return set_die_type (die, type, cu); |
8225 | } | |
9219021c | 8226 | |
e142c38c | 8227 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
8228 | |
8229 | /* Now build the name of the current namespace. */ | |
8230 | ||
0114d602 DJ |
8231 | previous_prefix = determine_prefix (die, cu); |
8232 | if (previous_prefix[0] != '\0') | |
8233 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 8234 | previous_prefix, name, 0, cu); |
0114d602 DJ |
8235 | |
8236 | /* Create the type. */ | |
8237 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
8238 | objfile); | |
8239 | TYPE_NAME (type) = (char *) name; | |
8240 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8241 | ||
60531b24 | 8242 | return set_die_type (die, type, cu); |
0114d602 DJ |
8243 | } |
8244 | ||
8245 | /* Read a C++ namespace. */ | |
8246 | ||
8247 | static void | |
8248 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8249 | { | |
8250 | struct objfile *objfile = cu->objfile; | |
0114d602 | 8251 | int is_anonymous; |
9219021c | 8252 | |
5c4e30ca DC |
8253 | /* Add a symbol associated to this if we haven't seen the namespace |
8254 | before. Also, add a using directive if it's an anonymous | |
8255 | namespace. */ | |
9219021c | 8256 | |
f2f0e013 | 8257 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
8258 | { |
8259 | struct type *type; | |
8260 | ||
0114d602 | 8261 | type = read_type_die (die, cu); |
e7c27a73 | 8262 | new_symbol (die, type, cu); |
5c4e30ca | 8263 | |
e8e80198 | 8264 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 8265 | if (is_anonymous) |
0114d602 DJ |
8266 | { |
8267 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 8268 | |
c0cc3a76 | 8269 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 8270 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 8271 | } |
5c4e30ca | 8272 | } |
9219021c | 8273 | |
639d11d3 | 8274 | if (die->child != NULL) |
d9fa45fe | 8275 | { |
639d11d3 | 8276 | struct die_info *child_die = die->child; |
6e70227d | 8277 | |
d9fa45fe DC |
8278 | while (child_die && child_die->tag) |
8279 | { | |
e7c27a73 | 8280 | process_die (child_die, cu); |
d9fa45fe DC |
8281 | child_die = sibling_die (child_die); |
8282 | } | |
8283 | } | |
38d518c9 EZ |
8284 | } |
8285 | ||
f55ee35c JK |
8286 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
8287 | imported module. Still we need that type as local Fortran "use ... only" | |
8288 | declaration imports depend on the created type in determine_prefix. */ | |
8289 | ||
8290 | static struct type * | |
8291 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
8292 | { | |
8293 | struct objfile *objfile = cu->objfile; | |
8294 | char *module_name; | |
8295 | struct type *type; | |
8296 | ||
8297 | module_name = dwarf2_name (die, cu); | |
8298 | if (!module_name) | |
3e43a32a MS |
8299 | complaint (&symfile_complaints, |
8300 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
8301 | die->offset); |
8302 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
8303 | ||
8304 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
8305 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8306 | ||
8307 | return set_die_type (die, type, cu); | |
8308 | } | |
8309 | ||
5d7cb8df JK |
8310 | /* Read a Fortran module. */ |
8311 | ||
8312 | static void | |
8313 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
8314 | { | |
8315 | struct die_info *child_die = die->child; | |
8316 | ||
5d7cb8df JK |
8317 | while (child_die && child_die->tag) |
8318 | { | |
8319 | process_die (child_die, cu); | |
8320 | child_die = sibling_die (child_die); | |
8321 | } | |
8322 | } | |
8323 | ||
38d518c9 EZ |
8324 | /* Return the name of the namespace represented by DIE. Set |
8325 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
8326 | namespace. */ | |
8327 | ||
8328 | static const char * | |
e142c38c | 8329 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
8330 | { |
8331 | struct die_info *current_die; | |
8332 | const char *name = NULL; | |
8333 | ||
8334 | /* Loop through the extensions until we find a name. */ | |
8335 | ||
8336 | for (current_die = die; | |
8337 | current_die != NULL; | |
f2f0e013 | 8338 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 8339 | { |
e142c38c | 8340 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
8341 | if (name != NULL) |
8342 | break; | |
8343 | } | |
8344 | ||
8345 | /* Is it an anonymous namespace? */ | |
8346 | ||
8347 | *is_anonymous = (name == NULL); | |
8348 | if (*is_anonymous) | |
2b1dbab0 | 8349 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
8350 | |
8351 | return name; | |
d9fa45fe DC |
8352 | } |
8353 | ||
c906108c SS |
8354 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
8355 | the user defined type vector. */ | |
8356 | ||
f792889a | 8357 | static struct type * |
e7c27a73 | 8358 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8359 | { |
5e2b427d | 8360 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 8361 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 8362 | struct type *type; |
8b2dbe47 KB |
8363 | struct attribute *attr_byte_size; |
8364 | struct attribute *attr_address_class; | |
8365 | int byte_size, addr_class; | |
7e314c57 JK |
8366 | struct type *target_type; |
8367 | ||
8368 | target_type = die_type (die, cu); | |
c906108c | 8369 | |
7e314c57 JK |
8370 | /* The die_type call above may have already set the type for this DIE. */ |
8371 | type = get_die_type (die, cu); | |
8372 | if (type) | |
8373 | return type; | |
8374 | ||
8375 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 8376 | |
e142c38c | 8377 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
8378 | if (attr_byte_size) |
8379 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 8380 | else |
8b2dbe47 KB |
8381 | byte_size = cu_header->addr_size; |
8382 | ||
e142c38c | 8383 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
8384 | if (attr_address_class) |
8385 | addr_class = DW_UNSND (attr_address_class); | |
8386 | else | |
8387 | addr_class = DW_ADDR_none; | |
8388 | ||
8389 | /* If the pointer size or address class is different than the | |
8390 | default, create a type variant marked as such and set the | |
8391 | length accordingly. */ | |
8392 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 8393 | { |
5e2b427d | 8394 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
8395 | { |
8396 | int type_flags; | |
8397 | ||
849957d9 | 8398 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 8399 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
8400 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
8401 | == 0); | |
8b2dbe47 KB |
8402 | type = make_type_with_address_space (type, type_flags); |
8403 | } | |
8404 | else if (TYPE_LENGTH (type) != byte_size) | |
8405 | { | |
3e43a32a MS |
8406 | complaint (&symfile_complaints, |
8407 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 8408 | } |
6e70227d | 8409 | else |
9a619af0 MS |
8410 | { |
8411 | /* Should we also complain about unhandled address classes? */ | |
8412 | } | |
c906108c | 8413 | } |
8b2dbe47 KB |
8414 | |
8415 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 8416 | return set_die_type (die, type, cu); |
c906108c SS |
8417 | } |
8418 | ||
8419 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
8420 | the user defined type vector. */ | |
8421 | ||
f792889a | 8422 | static struct type * |
e7c27a73 | 8423 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8424 | { |
8425 | struct type *type; | |
8426 | struct type *to_type; | |
8427 | struct type *domain; | |
8428 | ||
e7c27a73 DJ |
8429 | to_type = die_type (die, cu); |
8430 | domain = die_containing_type (die, cu); | |
0d5de010 | 8431 | |
7e314c57 JK |
8432 | /* The calls above may have already set the type for this DIE. */ |
8433 | type = get_die_type (die, cu); | |
8434 | if (type) | |
8435 | return type; | |
8436 | ||
0d5de010 DJ |
8437 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
8438 | type = lookup_methodptr_type (to_type); | |
8439 | else | |
8440 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 8441 | |
f792889a | 8442 | return set_die_type (die, type, cu); |
c906108c SS |
8443 | } |
8444 | ||
8445 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
8446 | the user defined type vector. */ | |
8447 | ||
f792889a | 8448 | static struct type * |
e7c27a73 | 8449 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8450 | { |
e7c27a73 | 8451 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 8452 | struct type *type, *target_type; |
c906108c SS |
8453 | struct attribute *attr; |
8454 | ||
7e314c57 JK |
8455 | target_type = die_type (die, cu); |
8456 | ||
8457 | /* The die_type call above may have already set the type for this DIE. */ | |
8458 | type = get_die_type (die, cu); | |
8459 | if (type) | |
8460 | return type; | |
8461 | ||
8462 | type = lookup_reference_type (target_type); | |
e142c38c | 8463 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8464 | if (attr) |
8465 | { | |
8466 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8467 | } | |
8468 | else | |
8469 | { | |
107d2387 | 8470 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8471 | } |
f792889a | 8472 | return set_die_type (die, type, cu); |
c906108c SS |
8473 | } |
8474 | ||
f792889a | 8475 | static struct type * |
e7c27a73 | 8476 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8477 | { |
f792889a | 8478 | struct type *base_type, *cv_type; |
c906108c | 8479 | |
e7c27a73 | 8480 | base_type = die_type (die, cu); |
7e314c57 JK |
8481 | |
8482 | /* The die_type call above may have already set the type for this DIE. */ | |
8483 | cv_type = get_die_type (die, cu); | |
8484 | if (cv_type) | |
8485 | return cv_type; | |
8486 | ||
2f608a3a KW |
8487 | /* In case the const qualifier is applied to an array type, the element type |
8488 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8489 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8490 | { | |
8491 | struct type *el_type, *inner_array; | |
8492 | ||
8493 | base_type = copy_type (base_type); | |
8494 | inner_array = base_type; | |
8495 | ||
8496 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8497 | { | |
8498 | TYPE_TARGET_TYPE (inner_array) = | |
8499 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8500 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8501 | } | |
8502 | ||
8503 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8504 | TYPE_TARGET_TYPE (inner_array) = | |
8505 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8506 | ||
8507 | return set_die_type (die, base_type, cu); | |
8508 | } | |
8509 | ||
f792889a DJ |
8510 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8511 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8512 | } |
8513 | ||
f792889a | 8514 | static struct type * |
e7c27a73 | 8515 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8516 | { |
f792889a | 8517 | struct type *base_type, *cv_type; |
c906108c | 8518 | |
e7c27a73 | 8519 | base_type = die_type (die, cu); |
7e314c57 JK |
8520 | |
8521 | /* The die_type call above may have already set the type for this DIE. */ | |
8522 | cv_type = get_die_type (die, cu); | |
8523 | if (cv_type) | |
8524 | return cv_type; | |
8525 | ||
f792889a DJ |
8526 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8527 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8528 | } |
8529 | ||
8530 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8531 | the user defined type vector. It isn't really a user defined type, | |
8532 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8533 | attribute to reference it. */ | |
8534 | ||
f792889a | 8535 | static struct type * |
e7c27a73 | 8536 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8537 | { |
e7c27a73 | 8538 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8539 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8540 | struct type *type, *range_type, *index_type, *char_type; |
8541 | struct attribute *attr; | |
8542 | unsigned int length; | |
8543 | ||
e142c38c | 8544 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8545 | if (attr) |
8546 | { | |
8547 | length = DW_UNSND (attr); | |
8548 | } | |
8549 | else | |
8550 | { | |
0963b4bd | 8551 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8552 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8553 | if (attr) |
8554 | { | |
8555 | length = DW_UNSND (attr); | |
8556 | } | |
8557 | else | |
8558 | { | |
8559 | length = 1; | |
8560 | } | |
c906108c | 8561 | } |
6ccb9162 | 8562 | |
46bf5051 | 8563 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8564 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8565 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8566 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8567 | |
f792889a | 8568 | return set_die_type (die, type, cu); |
c906108c SS |
8569 | } |
8570 | ||
8571 | /* Handle DIES due to C code like: | |
8572 | ||
8573 | struct foo | |
c5aa993b JM |
8574 | { |
8575 | int (*funcp)(int a, long l); | |
8576 | int b; | |
8577 | }; | |
c906108c | 8578 | |
0963b4bd | 8579 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8580 | |
f792889a | 8581 | static struct type * |
e7c27a73 | 8582 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8583 | { |
bb5ed363 | 8584 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
8585 | struct type *type; /* Type that this function returns. */ |
8586 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8587 | struct attribute *attr; |
8588 | ||
e7c27a73 | 8589 | type = die_type (die, cu); |
7e314c57 JK |
8590 | |
8591 | /* The die_type call above may have already set the type for this DIE. */ | |
8592 | ftype = get_die_type (die, cu); | |
8593 | if (ftype) | |
8594 | return ftype; | |
8595 | ||
0c8b41f1 | 8596 | ftype = lookup_function_type (type); |
c906108c | 8597 | |
5b8101ae | 8598 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8599 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8600 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8601 | || cu->language == language_cplus |
5b8101ae PM |
8602 | || cu->language == language_java |
8603 | || cu->language == language_pascal) | |
876cecd0 | 8604 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8605 | else if (producer_is_realview (cu->producer)) |
8606 | /* RealView does not emit DW_AT_prototyped. We can not | |
8607 | distinguish prototyped and unprototyped functions; default to | |
8608 | prototyped, since that is more common in modern code (and | |
8609 | RealView warns about unprototyped functions). */ | |
8610 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8611 | |
c055b101 CV |
8612 | /* Store the calling convention in the type if it's available in |
8613 | the subroutine die. Otherwise set the calling convention to | |
8614 | the default value DW_CC_normal. */ | |
8615 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
8616 | if (attr) |
8617 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
8618 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
8619 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
8620 | else | |
8621 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
8622 | |
8623 | /* We need to add the subroutine type to the die immediately so | |
8624 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 8625 | declared as the same subroutine type. */ |
76c10ea2 | 8626 | set_die_type (die, ftype, cu); |
6e70227d | 8627 | |
639d11d3 | 8628 | if (die->child != NULL) |
c906108c | 8629 | { |
bb5ed363 | 8630 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 8631 | struct die_info *child_die; |
8072405b | 8632 | int nparams, iparams; |
c906108c SS |
8633 | |
8634 | /* Count the number of parameters. | |
8635 | FIXME: GDB currently ignores vararg functions, but knows about | |
8636 | vararg member functions. */ | |
8072405b | 8637 | nparams = 0; |
639d11d3 | 8638 | child_die = die->child; |
c906108c SS |
8639 | while (child_die && child_die->tag) |
8640 | { | |
8641 | if (child_die->tag == DW_TAG_formal_parameter) | |
8642 | nparams++; | |
8643 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8644 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8645 | child_die = sibling_die (child_die); |
8646 | } | |
8647 | ||
8648 | /* Allocate storage for parameters and fill them in. */ | |
8649 | TYPE_NFIELDS (ftype) = nparams; | |
8650 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8651 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8652 | |
8072405b JK |
8653 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8654 | even if we error out during the parameters reading below. */ | |
8655 | for (iparams = 0; iparams < nparams; iparams++) | |
8656 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8657 | ||
8658 | iparams = 0; | |
639d11d3 | 8659 | child_die = die->child; |
c906108c SS |
8660 | while (child_die && child_die->tag) |
8661 | { | |
8662 | if (child_die->tag == DW_TAG_formal_parameter) | |
8663 | { | |
3ce3b1ba PA |
8664 | struct type *arg_type; |
8665 | ||
8666 | /* DWARF version 2 has no clean way to discern C++ | |
8667 | static and non-static member functions. G++ helps | |
8668 | GDB by marking the first parameter for non-static | |
8669 | member functions (which is the this pointer) as | |
8670 | artificial. We pass this information to | |
8671 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8672 | ||
8673 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8674 | 4.5 does not yet generate. */ | |
e142c38c | 8675 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8676 | if (attr) |
8677 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8678 | else | |
418835cc KS |
8679 | { |
8680 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8681 | ||
8682 | /* GCC/43521: In java, the formal parameter | |
8683 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8684 | if (cu->language == language_java) | |
8685 | { | |
8686 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8687 | |
418835cc KS |
8688 | if (name && !strcmp (name, "this")) |
8689 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8690 | } | |
8691 | } | |
3ce3b1ba PA |
8692 | arg_type = die_type (child_die, cu); |
8693 | ||
8694 | /* RealView does not mark THIS as const, which the testsuite | |
8695 | expects. GCC marks THIS as const in method definitions, | |
8696 | but not in the class specifications (GCC PR 43053). */ | |
8697 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8698 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8699 | { | |
8700 | int is_this = 0; | |
8701 | struct dwarf2_cu *arg_cu = cu; | |
8702 | const char *name = dwarf2_name (child_die, cu); | |
8703 | ||
8704 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8705 | if (attr) | |
8706 | { | |
8707 | /* If the compiler emits this, use it. */ | |
8708 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8709 | is_this = 1; | |
8710 | } | |
8711 | else if (name && strcmp (name, "this") == 0) | |
8712 | /* Function definitions will have the argument names. */ | |
8713 | is_this = 1; | |
8714 | else if (name == NULL && iparams == 0) | |
8715 | /* Declarations may not have the names, so like | |
8716 | elsewhere in GDB, assume an artificial first | |
8717 | argument is "this". */ | |
8718 | is_this = 1; | |
8719 | ||
8720 | if (is_this) | |
8721 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8722 | arg_type, 0); | |
8723 | } | |
8724 | ||
8725 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8726 | iparams++; |
8727 | } | |
8728 | child_die = sibling_die (child_die); | |
8729 | } | |
8730 | } | |
8731 | ||
76c10ea2 | 8732 | return ftype; |
c906108c SS |
8733 | } |
8734 | ||
f792889a | 8735 | static struct type * |
e7c27a73 | 8736 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8737 | { |
e7c27a73 | 8738 | struct objfile *objfile = cu->objfile; |
0114d602 | 8739 | const char *name = NULL; |
3c8e0968 | 8740 | struct type *this_type, *target_type; |
c906108c | 8741 | |
94af9270 | 8742 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8743 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8744 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8745 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 8746 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
8747 | target_type = die_type (die, cu); |
8748 | if (target_type != this_type) | |
8749 | TYPE_TARGET_TYPE (this_type) = target_type; | |
8750 | else | |
8751 | { | |
8752 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
8753 | spec and cause infinite loops in GDB. */ | |
8754 | complaint (&symfile_complaints, | |
8755 | _("Self-referential DW_TAG_typedef " | |
8756 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 8757 | die->offset, objfile->name); |
3c8e0968 DE |
8758 | TYPE_TARGET_TYPE (this_type) = NULL; |
8759 | } | |
f792889a | 8760 | return this_type; |
c906108c SS |
8761 | } |
8762 | ||
8763 | /* Find a representation of a given base type and install | |
8764 | it in the TYPE field of the die. */ | |
8765 | ||
f792889a | 8766 | static struct type * |
e7c27a73 | 8767 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8768 | { |
e7c27a73 | 8769 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8770 | struct type *type; |
8771 | struct attribute *attr; | |
8772 | int encoding = 0, size = 0; | |
39cbfefa | 8773 | char *name; |
6ccb9162 UW |
8774 | enum type_code code = TYPE_CODE_INT; |
8775 | int type_flags = 0; | |
8776 | struct type *target_type = NULL; | |
c906108c | 8777 | |
e142c38c | 8778 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8779 | if (attr) |
8780 | { | |
8781 | encoding = DW_UNSND (attr); | |
8782 | } | |
e142c38c | 8783 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8784 | if (attr) |
8785 | { | |
8786 | size = DW_UNSND (attr); | |
8787 | } | |
39cbfefa | 8788 | name = dwarf2_name (die, cu); |
6ccb9162 | 8789 | if (!name) |
c906108c | 8790 | { |
6ccb9162 UW |
8791 | complaint (&symfile_complaints, |
8792 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8793 | } |
6ccb9162 UW |
8794 | |
8795 | switch (encoding) | |
c906108c | 8796 | { |
6ccb9162 UW |
8797 | case DW_ATE_address: |
8798 | /* Turn DW_ATE_address into a void * pointer. */ | |
8799 | code = TYPE_CODE_PTR; | |
8800 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8801 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8802 | break; | |
8803 | case DW_ATE_boolean: | |
8804 | code = TYPE_CODE_BOOL; | |
8805 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8806 | break; | |
8807 | case DW_ATE_complex_float: | |
8808 | code = TYPE_CODE_COMPLEX; | |
8809 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8810 | break; | |
8811 | case DW_ATE_decimal_float: | |
8812 | code = TYPE_CODE_DECFLOAT; | |
8813 | break; | |
8814 | case DW_ATE_float: | |
8815 | code = TYPE_CODE_FLT; | |
8816 | break; | |
8817 | case DW_ATE_signed: | |
8818 | break; | |
8819 | case DW_ATE_unsigned: | |
8820 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
8821 | if (cu->language == language_fortran |
8822 | && name | |
8823 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
8824 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
8825 | break; |
8826 | case DW_ATE_signed_char: | |
6e70227d | 8827 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8828 | || cu->language == language_pascal |
8829 | || cu->language == language_fortran) | |
6ccb9162 UW |
8830 | code = TYPE_CODE_CHAR; |
8831 | break; | |
8832 | case DW_ATE_unsigned_char: | |
868a0084 | 8833 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
8834 | || cu->language == language_pascal |
8835 | || cu->language == language_fortran) | |
6ccb9162 UW |
8836 | code = TYPE_CODE_CHAR; |
8837 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8838 | break; | |
75079b2b TT |
8839 | case DW_ATE_UTF: |
8840 | /* We just treat this as an integer and then recognize the | |
8841 | type by name elsewhere. */ | |
8842 | break; | |
8843 | ||
6ccb9162 UW |
8844 | default: |
8845 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8846 | dwarf_type_encoding_name (encoding)); | |
8847 | break; | |
c906108c | 8848 | } |
6ccb9162 | 8849 | |
0114d602 DJ |
8850 | type = init_type (code, size, type_flags, NULL, objfile); |
8851 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8852 | TYPE_TARGET_TYPE (type) = target_type; |
8853 | ||
0114d602 | 8854 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8855 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8856 | |
f792889a | 8857 | return set_die_type (die, type, cu); |
c906108c SS |
8858 | } |
8859 | ||
a02abb62 JB |
8860 | /* Read the given DW_AT_subrange DIE. */ |
8861 | ||
f792889a | 8862 | static struct type * |
a02abb62 JB |
8863 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8864 | { | |
8865 | struct type *base_type; | |
8866 | struct type *range_type; | |
8867 | struct attribute *attr; | |
43bbcdc2 PH |
8868 | LONGEST low = 0; |
8869 | LONGEST high = -1; | |
39cbfefa | 8870 | char *name; |
43bbcdc2 | 8871 | LONGEST negative_mask; |
e77813c8 | 8872 | |
a02abb62 | 8873 | base_type = die_type (die, cu); |
953ac07e JK |
8874 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8875 | check_typedef (base_type); | |
a02abb62 | 8876 | |
7e314c57 JK |
8877 | /* The die_type call above may have already set the type for this DIE. */ |
8878 | range_type = get_die_type (die, cu); | |
8879 | if (range_type) | |
8880 | return range_type; | |
8881 | ||
e142c38c | 8882 | if (cu->language == language_fortran) |
6e70227d | 8883 | { |
a02abb62 JB |
8884 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8885 | low = 1; | |
8886 | } | |
8887 | ||
dd5e6932 DJ |
8888 | /* FIXME: For variable sized arrays either of these could be |
8889 | a variable rather than a constant value. We'll allow it, | |
8890 | but we don't know how to handle it. */ | |
e142c38c | 8891 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8892 | if (attr) |
8893 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8894 | ||
e142c38c | 8895 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8896 | if (attr) |
6e70227d | 8897 | { |
d48323d8 | 8898 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
8899 | { |
8900 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8901 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8902 | FIXME: GDB does not yet know how to handle dynamic |
8903 | arrays properly, treat them as arrays with unspecified | |
8904 | length for now. | |
8905 | ||
8906 | FIXME: jimb/2003-09-22: GDB does not really know | |
8907 | how to handle arrays of unspecified length | |
8908 | either; we just represent them as zero-length | |
8909 | arrays. Choose an appropriate upper bound given | |
8910 | the lower bound we've computed above. */ | |
8911 | high = low - 1; | |
8912 | } | |
8913 | else | |
8914 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8915 | } | |
e77813c8 PM |
8916 | else |
8917 | { | |
8918 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8919 | if (attr) | |
8920 | { | |
8921 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8922 | high = low + count - 1; | |
8923 | } | |
c2ff108b JK |
8924 | else |
8925 | { | |
8926 | /* Unspecified array length. */ | |
8927 | high = low - 1; | |
8928 | } | |
e77813c8 PM |
8929 | } |
8930 | ||
8931 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8932 | without specifying a base type. | |
8933 | In that case, the base type must be set to the type of | |
8934 | the lower bound, upper bound or count, in that order, if any of these | |
8935 | three attributes references an object that has a type. | |
8936 | If no base type is found, the Dwarf-2 specifications say that | |
8937 | a signed integer type of size equal to the size of an address should | |
8938 | be used. | |
8939 | For the following C code: `extern char gdb_int [];' | |
8940 | GCC produces an empty range DIE. | |
8941 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 8942 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
8943 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
8944 | { | |
8945 | struct objfile *objfile = cu->objfile; | |
8946 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8947 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8948 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8949 | ||
8950 | /* Test "int", "long int", and "long long int" objfile types, | |
8951 | and select the first one having a size above or equal to the | |
8952 | architecture address size. */ | |
8953 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8954 | base_type = int_type; | |
8955 | else | |
8956 | { | |
8957 | int_type = objfile_type (objfile)->builtin_long; | |
8958 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8959 | base_type = int_type; | |
8960 | else | |
8961 | { | |
8962 | int_type = objfile_type (objfile)->builtin_long_long; | |
8963 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8964 | base_type = int_type; | |
8965 | } | |
8966 | } | |
8967 | } | |
a02abb62 | 8968 | |
6e70227d | 8969 | negative_mask = |
43bbcdc2 PH |
8970 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8971 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8972 | low |= negative_mask; | |
8973 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8974 | high |= negative_mask; | |
8975 | ||
a02abb62 JB |
8976 | range_type = create_range_type (NULL, base_type, low, high); |
8977 | ||
bbb0eef6 JK |
8978 | /* Mark arrays with dynamic length at least as an array of unspecified |
8979 | length. GDB could check the boundary but before it gets implemented at | |
8980 | least allow accessing the array elements. */ | |
d48323d8 | 8981 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
8982 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
8983 | ||
c2ff108b JK |
8984 | /* Ada expects an empty array on no boundary attributes. */ |
8985 | if (attr == NULL && cu->language != language_ada) | |
8986 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8987 | ||
39cbfefa DJ |
8988 | name = dwarf2_name (die, cu); |
8989 | if (name) | |
8990 | TYPE_NAME (range_type) = name; | |
6e70227d | 8991 | |
e142c38c | 8992 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
8993 | if (attr) |
8994 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
8995 | ||
7e314c57 JK |
8996 | set_die_type (die, range_type, cu); |
8997 | ||
8998 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8999 | set_descriptive_type (range_type, die, cu); |
9000 | ||
7e314c57 | 9001 | return range_type; |
a02abb62 | 9002 | } |
6e70227d | 9003 | |
f792889a | 9004 | static struct type * |
81a17f79 JB |
9005 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
9006 | { | |
9007 | struct type *type; | |
81a17f79 | 9008 | |
81a17f79 JB |
9009 | /* For now, we only support the C meaning of an unspecified type: void. */ |
9010 | ||
0114d602 DJ |
9011 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
9012 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 9013 | |
f792889a | 9014 | return set_die_type (die, type, cu); |
81a17f79 | 9015 | } |
a02abb62 | 9016 | |
51545339 DJ |
9017 | /* Trivial hash function for die_info: the hash value of a DIE |
9018 | is its offset in .debug_info for this objfile. */ | |
9019 | ||
9020 | static hashval_t | |
9021 | die_hash (const void *item) | |
9022 | { | |
9023 | const struct die_info *die = item; | |
9a619af0 | 9024 | |
51545339 DJ |
9025 | return die->offset; |
9026 | } | |
9027 | ||
9028 | /* Trivial comparison function for die_info structures: two DIEs | |
9029 | are equal if they have the same offset. */ | |
9030 | ||
9031 | static int | |
9032 | die_eq (const void *item_lhs, const void *item_rhs) | |
9033 | { | |
9034 | const struct die_info *die_lhs = item_lhs; | |
9035 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 9036 | |
51545339 DJ |
9037 | return die_lhs->offset == die_rhs->offset; |
9038 | } | |
9039 | ||
c906108c SS |
9040 | /* Read a whole compilation unit into a linked list of dies. */ |
9041 | ||
f9aca02d | 9042 | static struct die_info * |
93311388 | 9043 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 9044 | { |
93311388 | 9045 | struct die_reader_specs reader_specs; |
98bfdba5 | 9046 | int read_abbrevs = 0; |
1d9ec526 | 9047 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
9048 | struct die_info *die; |
9049 | ||
9050 | if (cu->dwarf2_abbrevs == NULL) | |
9051 | { | |
e5fe5e75 | 9052 | dwarf2_read_abbrevs (cu); |
98bfdba5 PA |
9053 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
9054 | read_abbrevs = 1; | |
9055 | } | |
93311388 | 9056 | |
348e048f | 9057 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
9058 | cu->die_hash |
9059 | = htab_create_alloc_ex (cu->header.length / 12, | |
9060 | die_hash, | |
9061 | die_eq, | |
9062 | NULL, | |
9063 | &cu->comp_unit_obstack, | |
9064 | hashtab_obstack_allocate, | |
9065 | dummy_obstack_deallocate); | |
9066 | ||
93311388 DE |
9067 | init_cu_die_reader (&reader_specs, cu); |
9068 | ||
98bfdba5 PA |
9069 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
9070 | ||
9071 | if (read_abbrevs) | |
9072 | do_cleanups (back_to); | |
9073 | ||
9074 | return die; | |
639d11d3 DC |
9075 | } |
9076 | ||
d97bc12b DE |
9077 | /* Main entry point for reading a DIE and all children. |
9078 | Read the DIE and dump it if requested. */ | |
9079 | ||
9080 | static struct die_info * | |
93311388 DE |
9081 | read_die_and_children (const struct die_reader_specs *reader, |
9082 | gdb_byte *info_ptr, | |
d97bc12b DE |
9083 | gdb_byte **new_info_ptr, |
9084 | struct die_info *parent) | |
9085 | { | |
93311388 | 9086 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
9087 | new_info_ptr, parent); |
9088 | ||
9089 | if (dwarf2_die_debug) | |
9090 | { | |
348e048f DE |
9091 | fprintf_unfiltered (gdb_stdlog, |
9092 | "\nRead die from %s of %s:\n", | |
b0df02fd | 9093 | (reader->cu->per_cu->debug_types_section |
8b70b953 TT |
9094 | ? ".debug_types" |
9095 | : ".debug_info"), | |
348e048f | 9096 | reader->abfd->filename); |
d97bc12b DE |
9097 | dump_die (result, dwarf2_die_debug); |
9098 | } | |
9099 | ||
9100 | return result; | |
9101 | } | |
9102 | ||
639d11d3 DC |
9103 | /* Read a single die and all its descendents. Set the die's sibling |
9104 | field to NULL; set other fields in the die correctly, and set all | |
9105 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
9106 | location of the info_ptr after reading all of those dies. PARENT | |
9107 | is the parent of the die in question. */ | |
9108 | ||
9109 | static struct die_info * | |
93311388 DE |
9110 | read_die_and_children_1 (const struct die_reader_specs *reader, |
9111 | gdb_byte *info_ptr, | |
d97bc12b DE |
9112 | gdb_byte **new_info_ptr, |
9113 | struct die_info *parent) | |
639d11d3 DC |
9114 | { |
9115 | struct die_info *die; | |
fe1b8b76 | 9116 | gdb_byte *cur_ptr; |
639d11d3 DC |
9117 | int has_children; |
9118 | ||
93311388 | 9119 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
9120 | if (die == NULL) |
9121 | { | |
9122 | *new_info_ptr = cur_ptr; | |
9123 | return NULL; | |
9124 | } | |
93311388 | 9125 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
9126 | |
9127 | if (has_children) | |
348e048f | 9128 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
9129 | else |
9130 | { | |
9131 | die->child = NULL; | |
9132 | *new_info_ptr = cur_ptr; | |
9133 | } | |
9134 | ||
9135 | die->sibling = NULL; | |
9136 | die->parent = parent; | |
9137 | return die; | |
9138 | } | |
9139 | ||
9140 | /* Read a die, all of its descendents, and all of its siblings; set | |
9141 | all of the fields of all of the dies correctly. Arguments are as | |
9142 | in read_die_and_children. */ | |
9143 | ||
9144 | static struct die_info * | |
93311388 DE |
9145 | read_die_and_siblings (const struct die_reader_specs *reader, |
9146 | gdb_byte *info_ptr, | |
fe1b8b76 | 9147 | gdb_byte **new_info_ptr, |
639d11d3 DC |
9148 | struct die_info *parent) |
9149 | { | |
9150 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 9151 | gdb_byte *cur_ptr; |
639d11d3 | 9152 | |
c906108c | 9153 | cur_ptr = info_ptr; |
639d11d3 DC |
9154 | first_die = last_sibling = NULL; |
9155 | ||
9156 | while (1) | |
c906108c | 9157 | { |
639d11d3 | 9158 | struct die_info *die |
93311388 | 9159 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 9160 | |
1d325ec1 | 9161 | if (die == NULL) |
c906108c | 9162 | { |
639d11d3 DC |
9163 | *new_info_ptr = cur_ptr; |
9164 | return first_die; | |
c906108c | 9165 | } |
1d325ec1 DJ |
9166 | |
9167 | if (!first_die) | |
9168 | first_die = die; | |
c906108c | 9169 | else |
1d325ec1 DJ |
9170 | last_sibling->sibling = die; |
9171 | ||
9172 | last_sibling = die; | |
c906108c | 9173 | } |
c906108c SS |
9174 | } |
9175 | ||
93311388 DE |
9176 | /* Read the die from the .debug_info section buffer. Set DIEP to |
9177 | point to a newly allocated die with its information, except for its | |
9178 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
9179 | whether the die has children or not. */ | |
9180 | ||
9181 | static gdb_byte * | |
9182 | read_full_die (const struct die_reader_specs *reader, | |
9183 | struct die_info **diep, gdb_byte *info_ptr, | |
9184 | int *has_children) | |
9185 | { | |
9186 | unsigned int abbrev_number, bytes_read, i, offset; | |
9187 | struct abbrev_info *abbrev; | |
9188 | struct die_info *die; | |
9189 | struct dwarf2_cu *cu = reader->cu; | |
9190 | bfd *abfd = reader->abfd; | |
9191 | ||
9192 | offset = info_ptr - reader->buffer; | |
9193 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9194 | info_ptr += bytes_read; | |
9195 | if (!abbrev_number) | |
9196 | { | |
9197 | *diep = NULL; | |
9198 | *has_children = 0; | |
9199 | return info_ptr; | |
9200 | } | |
9201 | ||
9202 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
9203 | if (!abbrev) | |
348e048f DE |
9204 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
9205 | abbrev_number, | |
9206 | bfd_get_filename (abfd)); | |
9207 | ||
93311388 DE |
9208 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
9209 | die->offset = offset; | |
9210 | die->tag = abbrev->tag; | |
9211 | die->abbrev = abbrev_number; | |
9212 | ||
9213 | die->num_attrs = abbrev->num_attrs; | |
9214 | ||
9215 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9216 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
9217 | abfd, info_ptr, cu); | |
9218 | ||
9219 | *diep = die; | |
9220 | *has_children = abbrev->has_children; | |
9221 | return info_ptr; | |
9222 | } | |
9223 | ||
c906108c SS |
9224 | /* In DWARF version 2, the description of the debugging information is |
9225 | stored in a separate .debug_abbrev section. Before we read any | |
9226 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
9227 | in a hash table. This function also sets flags in CU describing |
9228 | the data found in the abbrev table. */ | |
c906108c SS |
9229 | |
9230 | static void | |
e5fe5e75 | 9231 | dwarf2_read_abbrevs (struct dwarf2_cu *cu) |
c906108c | 9232 | { |
e5fe5e75 | 9233 | bfd *abfd = cu->objfile->obfd; |
e7c27a73 | 9234 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 9235 | gdb_byte *abbrev_ptr; |
c906108c SS |
9236 | struct abbrev_info *cur_abbrev; |
9237 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
9238 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
9239 | struct attr_abbrev *cur_attrs; |
9240 | unsigned int allocated_attrs; | |
c906108c | 9241 | |
0963b4bd | 9242 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
9243 | obstack_init (&cu->abbrev_obstack); |
9244 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
9245 | (ABBREV_HASH_SIZE | |
9246 | * sizeof (struct abbrev_info *))); | |
9247 | memset (cu->dwarf2_abbrevs, 0, | |
9248 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 9249 | |
be391dca TT |
9250 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
9251 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 9252 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
9253 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9254 | abbrev_ptr += bytes_read; | |
9255 | ||
f3dd6933 DJ |
9256 | allocated_attrs = ATTR_ALLOC_CHUNK; |
9257 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 9258 | |
0963b4bd | 9259 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
9260 | while (abbrev_number) |
9261 | { | |
f3dd6933 | 9262 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
9263 | |
9264 | /* read in abbrev header */ | |
9265 | cur_abbrev->number = abbrev_number; | |
9266 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9267 | abbrev_ptr += bytes_read; | |
9268 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
9269 | abbrev_ptr += 1; | |
9270 | ||
72bf9492 DJ |
9271 | if (cur_abbrev->tag == DW_TAG_namespace) |
9272 | cu->has_namespace_info = 1; | |
9273 | ||
c906108c SS |
9274 | /* now read in declarations */ |
9275 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9276 | abbrev_ptr += bytes_read; | |
9277 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9278 | abbrev_ptr += bytes_read; | |
9279 | while (abbrev_name) | |
9280 | { | |
f3dd6933 | 9281 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 9282 | { |
f3dd6933 DJ |
9283 | allocated_attrs += ATTR_ALLOC_CHUNK; |
9284 | cur_attrs | |
9285 | = xrealloc (cur_attrs, (allocated_attrs | |
9286 | * sizeof (struct attr_abbrev))); | |
c906108c | 9287 | } |
ae038cb0 DJ |
9288 | |
9289 | /* Record whether this compilation unit might have | |
9290 | inter-compilation-unit references. If we don't know what form | |
9291 | this attribute will have, then it might potentially be a | |
9292 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
9293 | references. */ | |
9294 | ||
9295 | if (abbrev_form == DW_FORM_ref_addr | |
9296 | || abbrev_form == DW_FORM_indirect) | |
9297 | cu->has_form_ref_addr = 1; | |
9298 | ||
f3dd6933 DJ |
9299 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
9300 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
9301 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9302 | abbrev_ptr += bytes_read; | |
9303 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9304 | abbrev_ptr += bytes_read; | |
9305 | } | |
9306 | ||
f3dd6933 DJ |
9307 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
9308 | (cur_abbrev->num_attrs | |
9309 | * sizeof (struct attr_abbrev))); | |
9310 | memcpy (cur_abbrev->attrs, cur_attrs, | |
9311 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
9312 | ||
c906108c | 9313 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
9314 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
9315 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
9316 | |
9317 | /* Get next abbreviation. | |
9318 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
9319 | always properly terminated with an abbrev number of 0. |
9320 | Exit loop if we encounter an abbreviation which we have | |
9321 | already read (which means we are about to read the abbreviations | |
9322 | for the next compile unit) or if the end of the abbreviation | |
9323 | table is reached. */ | |
dce234bc PP |
9324 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
9325 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
9326 | break; |
9327 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9328 | abbrev_ptr += bytes_read; | |
e7c27a73 | 9329 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
9330 | break; |
9331 | } | |
f3dd6933 DJ |
9332 | |
9333 | xfree (cur_attrs); | |
c906108c SS |
9334 | } |
9335 | ||
f3dd6933 | 9336 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 9337 | |
c906108c | 9338 | static void |
f3dd6933 | 9339 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 9340 | { |
f3dd6933 | 9341 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 9342 | |
f3dd6933 DJ |
9343 | obstack_free (&cu->abbrev_obstack, NULL); |
9344 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
9345 | } |
9346 | ||
9347 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
9348 | ||
9349 | static struct abbrev_info * | |
e7c27a73 | 9350 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
9351 | { |
9352 | unsigned int hash_number; | |
9353 | struct abbrev_info *abbrev; | |
9354 | ||
9355 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 9356 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
9357 | |
9358 | while (abbrev) | |
9359 | { | |
9360 | if (abbrev->number == number) | |
9361 | return abbrev; | |
9362 | else | |
9363 | abbrev = abbrev->next; | |
9364 | } | |
9365 | return NULL; | |
9366 | } | |
9367 | ||
72bf9492 DJ |
9368 | /* Returns nonzero if TAG represents a type that we might generate a partial |
9369 | symbol for. */ | |
9370 | ||
9371 | static int | |
9372 | is_type_tag_for_partial (int tag) | |
9373 | { | |
9374 | switch (tag) | |
9375 | { | |
9376 | #if 0 | |
9377 | /* Some types that would be reasonable to generate partial symbols for, | |
9378 | that we don't at present. */ | |
9379 | case DW_TAG_array_type: | |
9380 | case DW_TAG_file_type: | |
9381 | case DW_TAG_ptr_to_member_type: | |
9382 | case DW_TAG_set_type: | |
9383 | case DW_TAG_string_type: | |
9384 | case DW_TAG_subroutine_type: | |
9385 | #endif | |
9386 | case DW_TAG_base_type: | |
9387 | case DW_TAG_class_type: | |
680b30c7 | 9388 | case DW_TAG_interface_type: |
72bf9492 DJ |
9389 | case DW_TAG_enumeration_type: |
9390 | case DW_TAG_structure_type: | |
9391 | case DW_TAG_subrange_type: | |
9392 | case DW_TAG_typedef: | |
9393 | case DW_TAG_union_type: | |
9394 | return 1; | |
9395 | default: | |
9396 | return 0; | |
9397 | } | |
9398 | } | |
9399 | ||
9400 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
9401 | ||
9402 | static struct partial_die_info * | |
93311388 DE |
9403 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
9404 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 | 9405 | { |
bb5ed363 | 9406 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
9407 | struct partial_die_info *part_die; |
9408 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
9409 | struct abbrev_info *abbrev; | |
9410 | unsigned int bytes_read; | |
5afb4e99 | 9411 | unsigned int load_all = 0; |
72bf9492 DJ |
9412 | |
9413 | int nesting_level = 1; | |
9414 | ||
9415 | parent_die = NULL; | |
9416 | last_die = NULL; | |
9417 | ||
5afb4e99 DJ |
9418 | if (cu->per_cu && cu->per_cu->load_all_dies) |
9419 | load_all = 1; | |
9420 | ||
72bf9492 DJ |
9421 | cu->partial_dies |
9422 | = htab_create_alloc_ex (cu->header.length / 12, | |
9423 | partial_die_hash, | |
9424 | partial_die_eq, | |
9425 | NULL, | |
9426 | &cu->comp_unit_obstack, | |
9427 | hashtab_obstack_allocate, | |
9428 | dummy_obstack_deallocate); | |
9429 | ||
9430 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9431 | sizeof (struct partial_die_info)); | |
9432 | ||
9433 | while (1) | |
9434 | { | |
9435 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
9436 | ||
9437 | /* A NULL abbrev means the end of a series of children. */ | |
9438 | if (abbrev == NULL) | |
9439 | { | |
9440 | if (--nesting_level == 0) | |
9441 | { | |
9442 | /* PART_DIE was probably the last thing allocated on the | |
9443 | comp_unit_obstack, so we could call obstack_free | |
9444 | here. We don't do that because the waste is small, | |
9445 | and will be cleaned up when we're done with this | |
9446 | compilation unit. This way, we're also more robust | |
9447 | against other users of the comp_unit_obstack. */ | |
9448 | return first_die; | |
9449 | } | |
9450 | info_ptr += bytes_read; | |
9451 | last_die = parent_die; | |
9452 | parent_die = parent_die->die_parent; | |
9453 | continue; | |
9454 | } | |
9455 | ||
98bfdba5 PA |
9456 | /* Check for template arguments. We never save these; if |
9457 | they're seen, we just mark the parent, and go on our way. */ | |
9458 | if (parent_die != NULL | |
9459 | && cu->language == language_cplus | |
9460 | && (abbrev->tag == DW_TAG_template_type_param | |
9461 | || abbrev->tag == DW_TAG_template_value_param)) | |
9462 | { | |
9463 | parent_die->has_template_arguments = 1; | |
9464 | ||
9465 | if (!load_all) | |
9466 | { | |
9467 | /* We don't need a partial DIE for the template argument. */ | |
9468 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
9469 | cu); | |
9470 | continue; | |
9471 | } | |
9472 | } | |
9473 | ||
9474 | /* We only recurse into subprograms looking for template arguments. | |
9475 | Skip their other children. */ | |
9476 | if (!load_all | |
9477 | && cu->language == language_cplus | |
9478 | && parent_die != NULL | |
9479 | && parent_die->tag == DW_TAG_subprogram) | |
9480 | { | |
9481 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
9482 | continue; | |
9483 | } | |
9484 | ||
5afb4e99 DJ |
9485 | /* Check whether this DIE is interesting enough to save. Normally |
9486 | we would not be interested in members here, but there may be | |
9487 | later variables referencing them via DW_AT_specification (for | |
9488 | static members). */ | |
9489 | if (!load_all | |
9490 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9491 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9492 | && abbrev->tag != DW_TAG_enumerator |
9493 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9494 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9495 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9496 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9497 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9498 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9499 | { |
9500 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9501 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
9502 | continue; |
9503 | } | |
9504 | ||
93311388 DE |
9505 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
9506 | buffer, info_ptr, cu); | |
72bf9492 DJ |
9507 | |
9508 | /* This two-pass algorithm for processing partial symbols has a | |
9509 | high cost in cache pressure. Thus, handle some simple cases | |
9510 | here which cover the majority of C partial symbols. DIEs | |
9511 | which neither have specification tags in them, nor could have | |
9512 | specification tags elsewhere pointing at them, can simply be | |
9513 | processed and discarded. | |
9514 | ||
9515 | This segment is also optional; scan_partial_symbols and | |
9516 | add_partial_symbol will handle these DIEs if we chain | |
9517 | them in normally. When compilers which do not emit large | |
9518 | quantities of duplicate debug information are more common, | |
9519 | this code can probably be removed. */ | |
9520 | ||
9521 | /* Any complete simple types at the top level (pretty much all | |
9522 | of them, for a language without namespaces), can be processed | |
9523 | directly. */ | |
9524 | if (parent_die == NULL | |
9525 | && part_die->has_specification == 0 | |
9526 | && part_die->is_declaration == 0 | |
d8228535 | 9527 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9528 | || part_die->tag == DW_TAG_base_type |
9529 | || part_die->tag == DW_TAG_subrange_type)) | |
9530 | { | |
9531 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9532 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9533 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
9534 | &objfile->static_psymbols, |
9535 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
93311388 | 9536 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9537 | continue; |
9538 | } | |
9539 | ||
d8228535 JK |
9540 | /* The exception for DW_TAG_typedef with has_children above is |
9541 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9542 | type_name_no_tag_or_error will error on such types later. | |
9543 | ||
9544 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9545 | it could not find the child DIEs referenced later, this is checked | |
9546 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9547 | ||
9548 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9549 | complaint (&symfile_complaints, | |
9550 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9551 | "- DIE at 0x%x [in module %s]"), | |
bb5ed363 | 9552 | part_die->offset, objfile->name); |
d8228535 | 9553 | |
72bf9492 DJ |
9554 | /* If we're at the second level, and we're an enumerator, and |
9555 | our parent has no specification (meaning possibly lives in a | |
9556 | namespace elsewhere), then we can add the partial symbol now | |
9557 | instead of queueing it. */ | |
9558 | if (part_die->tag == DW_TAG_enumerator | |
9559 | && parent_die != NULL | |
9560 | && parent_die->die_parent == NULL | |
9561 | && parent_die->tag == DW_TAG_enumeration_type | |
9562 | && parent_die->has_specification == 0) | |
9563 | { | |
9564 | if (part_die->name == NULL) | |
3e43a32a MS |
9565 | complaint (&symfile_complaints, |
9566 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9567 | else if (building_psymtab) |
04a679b8 | 9568 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9569 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9570 | (cu->language == language_cplus |
9571 | || cu->language == language_java) | |
bb5ed363 DE |
9572 | ? &objfile->global_psymbols |
9573 | : &objfile->static_psymbols, | |
9574 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 9575 | |
93311388 | 9576 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9577 | continue; |
9578 | } | |
9579 | ||
9580 | /* We'll save this DIE so link it in. */ | |
9581 | part_die->die_parent = parent_die; | |
9582 | part_die->die_sibling = NULL; | |
9583 | part_die->die_child = NULL; | |
9584 | ||
9585 | if (last_die && last_die == parent_die) | |
9586 | last_die->die_child = part_die; | |
9587 | else if (last_die) | |
9588 | last_die->die_sibling = part_die; | |
9589 | ||
9590 | last_die = part_die; | |
9591 | ||
9592 | if (first_die == NULL) | |
9593 | first_die = part_die; | |
9594 | ||
9595 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9596 | find interesting need to be in the hash table, because we | |
9597 | also have the parent/sibling/child chains; only those that we | |
9598 | might refer to by offset later during partial symbol reading. | |
9599 | ||
9600 | For now this means things that might have be the target of a | |
9601 | DW_AT_specification, DW_AT_abstract_origin, or | |
9602 | DW_AT_extension. DW_AT_extension will refer only to | |
9603 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9604 | many things under the function DIE, but we do not recurse | |
9605 | into function DIEs during partial symbol reading) and | |
9606 | possibly variables as well; DW_AT_specification refers to | |
9607 | declarations. Declarations ought to have the DW_AT_declaration | |
9608 | flag. It happens that GCC forgets to put it in sometimes, but | |
9609 | only for functions, not for types. | |
9610 | ||
9611 | Adding more things than necessary to the hash table is harmless | |
9612 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9613 | wasted time in find_partial_die, when we reread the compilation |
9614 | unit with load_all_dies set. */ | |
72bf9492 | 9615 | |
5afb4e99 | 9616 | if (load_all |
72929c62 | 9617 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9618 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9619 | || abbrev->tag == DW_TAG_variable |
9620 | || abbrev->tag == DW_TAG_namespace | |
9621 | || part_die->is_declaration) | |
9622 | { | |
9623 | void **slot; | |
9624 | ||
9625 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
9626 | part_die->offset, INSERT); | |
9627 | *slot = part_die; | |
9628 | } | |
9629 | ||
9630 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9631 | sizeof (struct partial_die_info)); | |
9632 | ||
9633 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9634 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9635 | languages we have to, so that we can get at method physnames |
9636 | to infer fully qualified class names, for DW_AT_specification, | |
9637 | and for C++ template arguments. For C++, we also look one level | |
9638 | inside functions to find template arguments (if the name of the | |
9639 | function does not already contain the template arguments). | |
bc30ff58 JB |
9640 | |
9641 | For Ada, we need to scan the children of subprograms and lexical | |
9642 | blocks as well because Ada allows the definition of nested | |
9643 | entities that could be interesting for the debugger, such as | |
9644 | nested subprograms for instance. */ | |
72bf9492 | 9645 | if (last_die->has_children |
5afb4e99 DJ |
9646 | && (load_all |
9647 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9648 | || last_die->tag == DW_TAG_module |
72bf9492 | 9649 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9650 | || (cu->language == language_cplus |
9651 | && last_die->tag == DW_TAG_subprogram | |
9652 | && (last_die->name == NULL | |
9653 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9654 | || (cu->language != language_c |
9655 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9656 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9657 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9658 | || last_die->tag == DW_TAG_union_type)) |
9659 | || (cu->language == language_ada | |
9660 | && (last_die->tag == DW_TAG_subprogram | |
9661 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9662 | { |
9663 | nesting_level++; | |
9664 | parent_die = last_die; | |
9665 | continue; | |
9666 | } | |
9667 | ||
9668 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9669 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9670 | |
9671 | /* Back to the top, do it again. */ | |
9672 | } | |
9673 | } | |
9674 | ||
c906108c SS |
9675 | /* Read a minimal amount of information into the minimal die structure. */ |
9676 | ||
fe1b8b76 | 9677 | static gdb_byte * |
72bf9492 DJ |
9678 | read_partial_die (struct partial_die_info *part_die, |
9679 | struct abbrev_info *abbrev, | |
9680 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9681 | gdb_byte *buffer, gdb_byte *info_ptr, |
9682 | struct dwarf2_cu *cu) | |
c906108c | 9683 | { |
bb5ed363 | 9684 | struct objfile *objfile = cu->objfile; |
fa238c03 | 9685 | unsigned int i; |
c906108c | 9686 | struct attribute attr; |
c5aa993b | 9687 | int has_low_pc_attr = 0; |
c906108c SS |
9688 | int has_high_pc_attr = 0; |
9689 | ||
72bf9492 | 9690 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9691 | |
93311388 | 9692 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9693 | |
9694 | info_ptr += abbrev_len; | |
9695 | ||
9696 | if (abbrev == NULL) | |
9697 | return info_ptr; | |
9698 | ||
c906108c SS |
9699 | part_die->tag = abbrev->tag; |
9700 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9701 | |
9702 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9703 | { | |
e7c27a73 | 9704 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9705 | |
9706 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9707 | partial symbol table. */ |
c906108c SS |
9708 | switch (attr.name) |
9709 | { | |
9710 | case DW_AT_name: | |
71c25dea TT |
9711 | switch (part_die->tag) |
9712 | { | |
9713 | case DW_TAG_compile_unit: | |
348e048f | 9714 | case DW_TAG_type_unit: |
71c25dea TT |
9715 | /* Compilation units have a DW_AT_name that is a filename, not |
9716 | a source language identifier. */ | |
9717 | case DW_TAG_enumeration_type: | |
9718 | case DW_TAG_enumerator: | |
9719 | /* These tags always have simple identifiers already; no need | |
9720 | to canonicalize them. */ | |
9721 | part_die->name = DW_STRING (&attr); | |
9722 | break; | |
9723 | default: | |
9724 | part_die->name | |
9725 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 9726 | &objfile->objfile_obstack); |
71c25dea TT |
9727 | break; |
9728 | } | |
c906108c | 9729 | break; |
31ef98ae | 9730 | case DW_AT_linkage_name: |
c906108c | 9731 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9732 | /* Note that both forms of linkage name might appear. We |
9733 | assume they will be the same, and we only store the last | |
9734 | one we see. */ | |
94af9270 KS |
9735 | if (cu->language == language_ada) |
9736 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9737 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9738 | break; |
9739 | case DW_AT_low_pc: | |
9740 | has_low_pc_attr = 1; | |
9741 | part_die->lowpc = DW_ADDR (&attr); | |
9742 | break; | |
9743 | case DW_AT_high_pc: | |
9744 | has_high_pc_attr = 1; | |
9745 | part_die->highpc = DW_ADDR (&attr); | |
9746 | break; | |
9747 | case DW_AT_location: | |
0963b4bd | 9748 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9749 | if (attr_form_is_block (&attr)) |
9750 | { | |
9751 | part_die->locdesc = DW_BLOCK (&attr); | |
9752 | } | |
3690dd37 | 9753 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9754 | { |
4d3c2250 | 9755 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9756 | } |
9757 | else | |
9758 | { | |
4d3c2250 KB |
9759 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9760 | "partial symbol information"); | |
8e19ed76 | 9761 | } |
c906108c | 9762 | break; |
c906108c SS |
9763 | case DW_AT_external: |
9764 | part_die->is_external = DW_UNSND (&attr); | |
9765 | break; | |
9766 | case DW_AT_declaration: | |
9767 | part_die->is_declaration = DW_UNSND (&attr); | |
9768 | break; | |
9769 | case DW_AT_type: | |
9770 | part_die->has_type = 1; | |
9771 | break; | |
9772 | case DW_AT_abstract_origin: | |
9773 | case DW_AT_specification: | |
72bf9492 DJ |
9774 | case DW_AT_extension: |
9775 | part_die->has_specification = 1; | |
c764a876 | 9776 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9777 | break; |
9778 | case DW_AT_sibling: | |
9779 | /* Ignore absolute siblings, they might point outside of | |
9780 | the current compile unit. */ | |
9781 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9782 | complaint (&symfile_complaints, |
9783 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9784 | else |
93311388 | 9785 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9786 | break; |
fa4028e9 JB |
9787 | case DW_AT_byte_size: |
9788 | part_die->has_byte_size = 1; | |
9789 | break; | |
68511cec CES |
9790 | case DW_AT_calling_convention: |
9791 | /* DWARF doesn't provide a way to identify a program's source-level | |
9792 | entry point. DW_AT_calling_convention attributes are only meant | |
9793 | to describe functions' calling conventions. | |
9794 | ||
9795 | However, because it's a necessary piece of information in | |
9796 | Fortran, and because DW_CC_program is the only piece of debugging | |
9797 | information whose definition refers to a 'main program' at all, | |
9798 | several compilers have begun marking Fortran main programs with | |
9799 | DW_CC_program --- even when those functions use the standard | |
9800 | calling conventions. | |
9801 | ||
9802 | So until DWARF specifies a way to provide this information and | |
9803 | compilers pick up the new representation, we'll support this | |
9804 | practice. */ | |
9805 | if (DW_UNSND (&attr) == DW_CC_program | |
9806 | && cu->language == language_fortran) | |
01f8c46d JK |
9807 | { |
9808 | set_main_name (part_die->name); | |
9809 | ||
9810 | /* As this DIE has a static linkage the name would be difficult | |
9811 | to look up later. */ | |
9812 | language_of_main = language_fortran; | |
9813 | } | |
68511cec | 9814 | break; |
c906108c SS |
9815 | default: |
9816 | break; | |
9817 | } | |
9818 | } | |
9819 | ||
9373cf26 JK |
9820 | if (has_low_pc_attr && has_high_pc_attr) |
9821 | { | |
9822 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9823 | eliminate duplicate copies of functions and vtables and such. | |
9824 | The linker will arbitrarily choose one and discard the others. | |
9825 | The AT_*_pc values for such functions refer to local labels in | |
9826 | these sections. If the section from that file was discarded, the | |
9827 | labels are not in the output, so the relocs get a value of 0. | |
9828 | If this is a discarded function, mark the pc bounds as invalid, | |
9829 | so that GDB will ignore it. */ | |
9830 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9831 | { | |
bb5ed363 | 9832 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9833 | |
9834 | complaint (&symfile_complaints, | |
9835 | _("DW_AT_low_pc %s is zero " | |
9836 | "for DIE at 0x%x [in module %s]"), | |
9837 | paddress (gdbarch, part_die->lowpc), | |
bb5ed363 | 9838 | part_die->offset, objfile->name); |
9373cf26 JK |
9839 | } |
9840 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9841 | else if (part_die->lowpc >= part_die->highpc) | |
9842 | { | |
bb5ed363 | 9843 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
9844 | |
9845 | complaint (&symfile_complaints, | |
9846 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9847 | "for DIE at 0x%x [in module %s]"), | |
9848 | paddress (gdbarch, part_die->lowpc), | |
9849 | paddress (gdbarch, part_die->highpc), | |
bb5ed363 | 9850 | part_die->offset, objfile->name); |
9373cf26 JK |
9851 | } |
9852 | else | |
9853 | part_die->has_pc_info = 1; | |
9854 | } | |
85cbf3d3 | 9855 | |
c906108c SS |
9856 | return info_ptr; |
9857 | } | |
9858 | ||
72bf9492 DJ |
9859 | /* Find a cached partial DIE at OFFSET in CU. */ |
9860 | ||
9861 | static struct partial_die_info * | |
c764a876 | 9862 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9863 | { |
9864 | struct partial_die_info *lookup_die = NULL; | |
9865 | struct partial_die_info part_die; | |
9866 | ||
9867 | part_die.offset = offset; | |
9868 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9869 | ||
72bf9492 DJ |
9870 | return lookup_die; |
9871 | } | |
9872 | ||
348e048f DE |
9873 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9874 | except in the case of .debug_types DIEs which do not reference | |
9875 | outside their CU (they do however referencing other types via | |
55f1336d | 9876 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9877 | |
9878 | static struct partial_die_info * | |
c764a876 | 9879 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9880 | { |
bb5ed363 | 9881 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
9882 | struct dwarf2_per_cu_data *per_cu = NULL; |
9883 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9884 | |
b0df02fd | 9885 | if (cu->per_cu->debug_types_section) |
348e048f DE |
9886 | { |
9887 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9888 | if (pd != NULL) | |
9889 | return pd; | |
9890 | goto not_found; | |
9891 | } | |
9892 | ||
45452591 | 9893 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9894 | { |
9895 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9896 | if (pd != NULL) | |
9897 | return pd; | |
9898 | } | |
72bf9492 | 9899 | |
bb5ed363 | 9900 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
ae038cb0 | 9901 | |
98bfdba5 | 9902 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
a0f42c21 | 9903 | load_partial_comp_unit (per_cu); |
ae038cb0 DJ |
9904 | |
9905 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9906 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9907 | ||
9908 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9909 | { | |
9910 | struct cleanup *back_to; | |
9911 | struct partial_die_info comp_unit_die; | |
9912 | struct abbrev_info *abbrev; | |
9913 | unsigned int bytes_read; | |
9914 | char *info_ptr; | |
9915 | ||
9916 | per_cu->load_all_dies = 1; | |
9917 | ||
9918 | /* Re-read the DIEs. */ | |
9919 | back_to = make_cleanup (null_cleanup, 0); | |
9920 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9921 | { | |
e5fe5e75 | 9922 | dwarf2_read_abbrevs (per_cu->cu); |
53d72f98 | 9923 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9924 | } |
dce234bc | 9925 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9926 | + per_cu->cu->header.offset |
9927 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9928 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9929 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
bb5ed363 | 9930 | objfile->obfd, |
93311388 | 9931 | dwarf2_per_objfile->info.buffer, info_ptr, |
5afb4e99 DJ |
9932 | per_cu->cu); |
9933 | if (comp_unit_die.has_children) | |
bb5ed363 | 9934 | load_partial_dies (objfile->obfd, |
93311388 DE |
9935 | dwarf2_per_objfile->info.buffer, info_ptr, |
9936 | 0, per_cu->cu); | |
5afb4e99 DJ |
9937 | do_cleanups (back_to); |
9938 | ||
9939 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9940 | } | |
9941 | ||
348e048f DE |
9942 | not_found: |
9943 | ||
5afb4e99 DJ |
9944 | if (pd == NULL) |
9945 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9946 | _("could not find partial DIE 0x%x " |
9947 | "in cache [from module %s]\n"), | |
bb5ed363 | 9948 | offset, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 9949 | return pd; |
72bf9492 DJ |
9950 | } |
9951 | ||
abc72ce4 DE |
9952 | /* See if we can figure out if the class lives in a namespace. We do |
9953 | this by looking for a member function; its demangled name will | |
9954 | contain namespace info, if there is any. */ | |
9955 | ||
9956 | static void | |
9957 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
9958 | struct dwarf2_cu *cu) | |
9959 | { | |
9960 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
9961 | what template types look like, because the demangler | |
9962 | frequently doesn't give the same name as the debug info. We | |
9963 | could fix this by only using the demangled name to get the | |
9964 | prefix (but see comment in read_structure_type). */ | |
9965 | ||
9966 | struct partial_die_info *real_pdi; | |
9967 | struct partial_die_info *child_pdi; | |
9968 | ||
9969 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
9970 | we should not do this. We'll prepend the parent's fully qualified | |
9971 | name when we create the partial symbol. */ | |
9972 | ||
9973 | real_pdi = struct_pdi; | |
9974 | while (real_pdi->has_specification) | |
9975 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
9976 | ||
9977 | if (real_pdi->die_parent != NULL) | |
9978 | return; | |
9979 | ||
9980 | for (child_pdi = struct_pdi->die_child; | |
9981 | child_pdi != NULL; | |
9982 | child_pdi = child_pdi->die_sibling) | |
9983 | { | |
9984 | if (child_pdi->tag == DW_TAG_subprogram | |
9985 | && child_pdi->linkage_name != NULL) | |
9986 | { | |
9987 | char *actual_class_name | |
9988 | = language_class_name_from_physname (cu->language_defn, | |
9989 | child_pdi->linkage_name); | |
9990 | if (actual_class_name != NULL) | |
9991 | { | |
9992 | struct_pdi->name | |
9993 | = obsavestring (actual_class_name, | |
9994 | strlen (actual_class_name), | |
9995 | &cu->objfile->objfile_obstack); | |
9996 | xfree (actual_class_name); | |
9997 | } | |
9998 | break; | |
9999 | } | |
10000 | } | |
10001 | } | |
10002 | ||
72bf9492 DJ |
10003 | /* Adjust PART_DIE before generating a symbol for it. This function |
10004 | may set the is_external flag or change the DIE's name. */ | |
10005 | ||
10006 | static void | |
10007 | fixup_partial_die (struct partial_die_info *part_die, | |
10008 | struct dwarf2_cu *cu) | |
10009 | { | |
abc72ce4 DE |
10010 | /* Once we've fixed up a die, there's no point in doing so again. |
10011 | This also avoids a memory leak if we were to call | |
10012 | guess_partial_die_structure_name multiple times. */ | |
10013 | if (part_die->fixup_called) | |
10014 | return; | |
10015 | ||
72bf9492 DJ |
10016 | /* If we found a reference attribute and the DIE has no name, try |
10017 | to find a name in the referred to DIE. */ | |
10018 | ||
10019 | if (part_die->name == NULL && part_die->has_specification) | |
10020 | { | |
10021 | struct partial_die_info *spec_die; | |
72bf9492 | 10022 | |
10b3939b | 10023 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 10024 | |
10b3939b | 10025 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
10026 | |
10027 | if (spec_die->name) | |
10028 | { | |
10029 | part_die->name = spec_die->name; | |
10030 | ||
10031 | /* Copy DW_AT_external attribute if it is set. */ | |
10032 | if (spec_die->is_external) | |
10033 | part_die->is_external = spec_die->is_external; | |
10034 | } | |
10035 | } | |
10036 | ||
10037 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
10038 | |
10039 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 10040 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 10041 | |
abc72ce4 DE |
10042 | /* If there is no parent die to provide a namespace, and there are |
10043 | children, see if we can determine the namespace from their linkage | |
10044 | name. | |
10045 | NOTE: We need to do this even if cu->has_namespace_info != 0. | |
10046 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ | |
10047 | if (cu->language == language_cplus | |
8b70b953 | 10048 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
10049 | && part_die->die_parent == NULL |
10050 | && part_die->has_children | |
10051 | && (part_die->tag == DW_TAG_class_type | |
10052 | || part_die->tag == DW_TAG_structure_type | |
10053 | || part_die->tag == DW_TAG_union_type)) | |
10054 | guess_partial_die_structure_name (part_die, cu); | |
10055 | ||
53832f31 TT |
10056 | /* GCC might emit a nameless struct or union that has a linkage |
10057 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
10058 | if (part_die->name == NULL | |
96408a79 SA |
10059 | && (part_die->tag == DW_TAG_class_type |
10060 | || part_die->tag == DW_TAG_interface_type | |
10061 | || part_die->tag == DW_TAG_structure_type | |
10062 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
10063 | && part_die->linkage_name != NULL) |
10064 | { | |
10065 | char *demangled; | |
10066 | ||
10067 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
10068 | if (demangled) | |
10069 | { | |
96408a79 SA |
10070 | const char *base; |
10071 | ||
10072 | /* Strip any leading namespaces/classes, keep only the base name. | |
10073 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
10074 | base = strrchr (demangled, ':'); | |
10075 | if (base && base > demangled && base[-1] == ':') | |
10076 | base++; | |
10077 | else | |
10078 | base = demangled; | |
10079 | ||
10080 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
10081 | &cu->objfile->objfile_obstack); |
10082 | xfree (demangled); | |
10083 | } | |
10084 | } | |
10085 | ||
abc72ce4 | 10086 | part_die->fixup_called = 1; |
72bf9492 DJ |
10087 | } |
10088 | ||
a8329558 | 10089 | /* Read an attribute value described by an attribute form. */ |
c906108c | 10090 | |
fe1b8b76 | 10091 | static gdb_byte * |
a8329558 | 10092 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 10093 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 10094 | struct dwarf2_cu *cu) |
c906108c | 10095 | { |
e7c27a73 | 10096 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10097 | unsigned int bytes_read; |
10098 | struct dwarf_block *blk; | |
10099 | ||
a8329558 KW |
10100 | attr->form = form; |
10101 | switch (form) | |
c906108c | 10102 | { |
c906108c | 10103 | case DW_FORM_ref_addr: |
ae411497 TT |
10104 | if (cu->header.version == 2) |
10105 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
10106 | else | |
3e43a32a MS |
10107 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
10108 | &cu->header, &bytes_read); | |
ae411497 TT |
10109 | info_ptr += bytes_read; |
10110 | break; | |
10111 | case DW_FORM_addr: | |
e7c27a73 | 10112 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 10113 | info_ptr += bytes_read; |
c906108c SS |
10114 | break; |
10115 | case DW_FORM_block2: | |
7b5a2f43 | 10116 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10117 | blk->size = read_2_bytes (abfd, info_ptr); |
10118 | info_ptr += 2; | |
10119 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10120 | info_ptr += blk->size; | |
10121 | DW_BLOCK (attr) = blk; | |
10122 | break; | |
10123 | case DW_FORM_block4: | |
7b5a2f43 | 10124 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10125 | blk->size = read_4_bytes (abfd, info_ptr); |
10126 | info_ptr += 4; | |
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_data2: | |
10132 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
10133 | info_ptr += 2; | |
10134 | break; | |
10135 | case DW_FORM_data4: | |
10136 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
10137 | info_ptr += 4; | |
10138 | break; | |
10139 | case DW_FORM_data8: | |
10140 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
10141 | info_ptr += 8; | |
10142 | break; | |
2dc7f7b3 TT |
10143 | case DW_FORM_sec_offset: |
10144 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
10145 | info_ptr += bytes_read; | |
10146 | break; | |
c906108c | 10147 | case DW_FORM_string: |
9b1c24c8 | 10148 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 10149 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
10150 | info_ptr += bytes_read; |
10151 | break; | |
4bdf3d34 JJ |
10152 | case DW_FORM_strp: |
10153 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
10154 | &bytes_read); | |
8285870a | 10155 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
10156 | info_ptr += bytes_read; |
10157 | break; | |
2dc7f7b3 | 10158 | case DW_FORM_exprloc: |
c906108c | 10159 | case DW_FORM_block: |
7b5a2f43 | 10160 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10161 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10162 | info_ptr += bytes_read; | |
10163 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10164 | info_ptr += blk->size; | |
10165 | DW_BLOCK (attr) = blk; | |
10166 | break; | |
10167 | case DW_FORM_block1: | |
7b5a2f43 | 10168 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10169 | blk->size = read_1_byte (abfd, info_ptr); |
10170 | info_ptr += 1; | |
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_data1: | |
10176 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10177 | info_ptr += 1; | |
10178 | break; | |
10179 | case DW_FORM_flag: | |
10180 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10181 | info_ptr += 1; | |
10182 | break; | |
2dc7f7b3 TT |
10183 | case DW_FORM_flag_present: |
10184 | DW_UNSND (attr) = 1; | |
10185 | break; | |
c906108c SS |
10186 | case DW_FORM_sdata: |
10187 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
10188 | info_ptr += bytes_read; | |
10189 | break; | |
10190 | case DW_FORM_udata: | |
10191 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
10192 | info_ptr += bytes_read; | |
10193 | break; | |
10194 | case DW_FORM_ref1: | |
10b3939b | 10195 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
10196 | info_ptr += 1; |
10197 | break; | |
10198 | case DW_FORM_ref2: | |
10b3939b | 10199 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
10200 | info_ptr += 2; |
10201 | break; | |
10202 | case DW_FORM_ref4: | |
10b3939b | 10203 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
10204 | info_ptr += 4; |
10205 | break; | |
613e1657 | 10206 | case DW_FORM_ref8: |
10b3939b | 10207 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
10208 | info_ptr += 8; |
10209 | break; | |
55f1336d | 10210 | case DW_FORM_ref_sig8: |
348e048f DE |
10211 | /* Convert the signature to something we can record in DW_UNSND |
10212 | for later lookup. | |
10213 | NOTE: This is NULL if the type wasn't found. */ | |
10214 | DW_SIGNATURED_TYPE (attr) = | |
10215 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
10216 | info_ptr += 8; | |
10217 | break; | |
c906108c | 10218 | case DW_FORM_ref_udata: |
10b3939b DJ |
10219 | DW_ADDR (attr) = (cu->header.offset |
10220 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
10221 | info_ptr += bytes_read; |
10222 | break; | |
c906108c | 10223 | case DW_FORM_indirect: |
a8329558 KW |
10224 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10225 | info_ptr += bytes_read; | |
e7c27a73 | 10226 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 10227 | break; |
c906108c | 10228 | default: |
8a3fe4f8 | 10229 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
10230 | dwarf_form_name (form), |
10231 | bfd_get_filename (abfd)); | |
c906108c | 10232 | } |
28e94949 JB |
10233 | |
10234 | /* We have seen instances where the compiler tried to emit a byte | |
10235 | size attribute of -1 which ended up being encoded as an unsigned | |
10236 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
10237 | an object of this size seems pretty unlikely so we can relatively | |
10238 | safely treat these cases as if the size attribute was invalid and | |
10239 | treat them as zero by default. */ | |
10240 | if (attr->name == DW_AT_byte_size | |
10241 | && form == DW_FORM_data4 | |
10242 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
10243 | { |
10244 | complaint | |
10245 | (&symfile_complaints, | |
43bbcdc2 PH |
10246 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
10247 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
10248 | DW_UNSND (attr) = 0; |
10249 | } | |
28e94949 | 10250 | |
c906108c SS |
10251 | return info_ptr; |
10252 | } | |
10253 | ||
a8329558 KW |
10254 | /* Read an attribute described by an abbreviated attribute. */ |
10255 | ||
fe1b8b76 | 10256 | static gdb_byte * |
a8329558 | 10257 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 10258 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
10259 | { |
10260 | attr->name = abbrev->name; | |
e7c27a73 | 10261 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
10262 | } |
10263 | ||
0963b4bd | 10264 | /* Read dwarf information from a buffer. */ |
c906108c SS |
10265 | |
10266 | static unsigned int | |
fe1b8b76 | 10267 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10268 | { |
fe1b8b76 | 10269 | return bfd_get_8 (abfd, buf); |
c906108c SS |
10270 | } |
10271 | ||
10272 | static int | |
fe1b8b76 | 10273 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10274 | { |
fe1b8b76 | 10275 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
10276 | } |
10277 | ||
10278 | static unsigned int | |
fe1b8b76 | 10279 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10280 | { |
fe1b8b76 | 10281 | return bfd_get_16 (abfd, buf); |
c906108c SS |
10282 | } |
10283 | ||
21ae7a4d JK |
10284 | static int |
10285 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10286 | { | |
10287 | return bfd_get_signed_16 (abfd, buf); | |
10288 | } | |
10289 | ||
c906108c | 10290 | static unsigned int |
fe1b8b76 | 10291 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10292 | { |
fe1b8b76 | 10293 | return bfd_get_32 (abfd, buf); |
c906108c SS |
10294 | } |
10295 | ||
21ae7a4d JK |
10296 | static int |
10297 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10298 | { | |
10299 | return bfd_get_signed_32 (abfd, buf); | |
10300 | } | |
10301 | ||
93311388 | 10302 | static ULONGEST |
fe1b8b76 | 10303 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10304 | { |
fe1b8b76 | 10305 | return bfd_get_64 (abfd, buf); |
c906108c SS |
10306 | } |
10307 | ||
10308 | static CORE_ADDR | |
fe1b8b76 | 10309 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 10310 | unsigned int *bytes_read) |
c906108c | 10311 | { |
e7c27a73 | 10312 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10313 | CORE_ADDR retval = 0; |
10314 | ||
107d2387 | 10315 | if (cu_header->signed_addr_p) |
c906108c | 10316 | { |
107d2387 AC |
10317 | switch (cu_header->addr_size) |
10318 | { | |
10319 | case 2: | |
fe1b8b76 | 10320 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
10321 | break; |
10322 | case 4: | |
fe1b8b76 | 10323 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
10324 | break; |
10325 | case 8: | |
fe1b8b76 | 10326 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
10327 | break; |
10328 | default: | |
8e65ff28 | 10329 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 10330 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 10331 | bfd_get_filename (abfd)); |
107d2387 AC |
10332 | } |
10333 | } | |
10334 | else | |
10335 | { | |
10336 | switch (cu_header->addr_size) | |
10337 | { | |
10338 | case 2: | |
fe1b8b76 | 10339 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
10340 | break; |
10341 | case 4: | |
fe1b8b76 | 10342 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
10343 | break; |
10344 | case 8: | |
fe1b8b76 | 10345 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
10346 | break; |
10347 | default: | |
8e65ff28 | 10348 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
10349 | _("read_address: bad switch, " |
10350 | "unsigned [in module %s]"), | |
659b0389 | 10351 | bfd_get_filename (abfd)); |
107d2387 | 10352 | } |
c906108c | 10353 | } |
64367e0a | 10354 | |
107d2387 AC |
10355 | *bytes_read = cu_header->addr_size; |
10356 | return retval; | |
c906108c SS |
10357 | } |
10358 | ||
f7ef9339 | 10359 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
10360 | specification allows the initial length to take up either 4 bytes |
10361 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
10362 | bytes describe the length and all offsets will be 8 bytes in length | |
10363 | instead of 4. | |
10364 | ||
f7ef9339 KB |
10365 | An older, non-standard 64-bit format is also handled by this |
10366 | function. The older format in question stores the initial length | |
10367 | as an 8-byte quantity without an escape value. Lengths greater | |
10368 | than 2^32 aren't very common which means that the initial 4 bytes | |
10369 | is almost always zero. Since a length value of zero doesn't make | |
10370 | sense for the 32-bit format, this initial zero can be considered to | |
10371 | be an escape value which indicates the presence of the older 64-bit | |
10372 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
10373 | greater than 4GB. If it becomes necessary to handle lengths |
10374 | somewhat larger than 4GB, we could allow other small values (such | |
10375 | as the non-sensical values of 1, 2, and 3) to also be used as | |
10376 | escape values indicating the presence of the old format. | |
f7ef9339 | 10377 | |
917c78fc MK |
10378 | The value returned via bytes_read should be used to increment the |
10379 | relevant pointer after calling read_initial_length(). | |
c764a876 | 10380 | |
613e1657 KB |
10381 | [ Note: read_initial_length() and read_offset() are based on the |
10382 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 10383 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
10384 | from: |
10385 | ||
f7ef9339 | 10386 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 10387 | |
613e1657 KB |
10388 | This document is only a draft and is subject to change. (So beware.) |
10389 | ||
f7ef9339 | 10390 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
10391 | determined empirically by examining 64-bit ELF files produced by |
10392 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
10393 | |
10394 | - Kevin, July 16, 2002 | |
613e1657 KB |
10395 | ] */ |
10396 | ||
10397 | static LONGEST | |
c764a876 | 10398 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 10399 | { |
fe1b8b76 | 10400 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 10401 | |
dd373385 | 10402 | if (length == 0xffffffff) |
613e1657 | 10403 | { |
fe1b8b76 | 10404 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 10405 | *bytes_read = 12; |
613e1657 | 10406 | } |
dd373385 | 10407 | else if (length == 0) |
f7ef9339 | 10408 | { |
dd373385 | 10409 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 10410 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 10411 | *bytes_read = 8; |
f7ef9339 | 10412 | } |
613e1657 KB |
10413 | else |
10414 | { | |
10415 | *bytes_read = 4; | |
613e1657 KB |
10416 | } |
10417 | ||
c764a876 DE |
10418 | return length; |
10419 | } | |
dd373385 | 10420 | |
c764a876 DE |
10421 | /* Cover function for read_initial_length. |
10422 | Returns the length of the object at BUF, and stores the size of the | |
10423 | initial length in *BYTES_READ and stores the size that offsets will be in | |
10424 | *OFFSET_SIZE. | |
10425 | If the initial length size is not equivalent to that specified in | |
10426 | CU_HEADER then issue a complaint. | |
10427 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 10428 | |
c764a876 DE |
10429 | static LONGEST |
10430 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
10431 | const struct comp_unit_head *cu_header, | |
10432 | unsigned int *bytes_read, | |
10433 | unsigned int *offset_size) | |
10434 | { | |
10435 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
10436 | ||
10437 | gdb_assert (cu_header->initial_length_size == 4 | |
10438 | || cu_header->initial_length_size == 8 | |
10439 | || cu_header->initial_length_size == 12); | |
10440 | ||
10441 | if (cu_header->initial_length_size != *bytes_read) | |
10442 | complaint (&symfile_complaints, | |
10443 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 10444 | |
c764a876 | 10445 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 10446 | return length; |
613e1657 KB |
10447 | } |
10448 | ||
10449 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 10450 | given by cu_header->offset_size. */ |
613e1657 KB |
10451 | |
10452 | static LONGEST | |
fe1b8b76 | 10453 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 10454 | unsigned int *bytes_read) |
c764a876 DE |
10455 | { |
10456 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 10457 | |
c764a876 DE |
10458 | *bytes_read = cu_header->offset_size; |
10459 | return offset; | |
10460 | } | |
10461 | ||
10462 | /* Read an offset from the data stream. */ | |
10463 | ||
10464 | static LONGEST | |
10465 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
10466 | { |
10467 | LONGEST retval = 0; | |
10468 | ||
c764a876 | 10469 | switch (offset_size) |
613e1657 KB |
10470 | { |
10471 | case 4: | |
fe1b8b76 | 10472 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
10473 | break; |
10474 | case 8: | |
fe1b8b76 | 10475 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
10476 | break; |
10477 | default: | |
8e65ff28 | 10478 | internal_error (__FILE__, __LINE__, |
c764a876 | 10479 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 10480 | bfd_get_filename (abfd)); |
613e1657 KB |
10481 | } |
10482 | ||
917c78fc | 10483 | return retval; |
613e1657 KB |
10484 | } |
10485 | ||
fe1b8b76 JB |
10486 | static gdb_byte * |
10487 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
10488 | { |
10489 | /* If the size of a host char is 8 bits, we can return a pointer | |
10490 | to the buffer, otherwise we have to copy the data to a buffer | |
10491 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10492 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 10493 | return buf; |
c906108c SS |
10494 | } |
10495 | ||
10496 | static char * | |
9b1c24c8 | 10497 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
10498 | { |
10499 | /* If the size of a host char is 8 bits, we can return a pointer | |
10500 | to the string, otherwise we have to copy the string to a buffer | |
10501 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10502 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10503 | if (*buf == '\0') |
10504 | { | |
10505 | *bytes_read_ptr = 1; | |
10506 | return NULL; | |
10507 | } | |
fe1b8b76 JB |
10508 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10509 | return (char *) buf; | |
4bdf3d34 JJ |
10510 | } |
10511 | ||
10512 | static char * | |
cf2c3c16 | 10513 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 10514 | { |
be391dca | 10515 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10516 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
10517 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
10518 | bfd_get_filename (abfd)); | |
dce234bc | 10519 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
10520 | error (_("DW_FORM_strp pointing outside of " |
10521 | ".debug_str section [in module %s]"), | |
10522 | bfd_get_filename (abfd)); | |
4bdf3d34 | 10523 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10524 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10525 | return NULL; |
dce234bc | 10526 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10527 | } |
10528 | ||
cf2c3c16 TT |
10529 | static char * |
10530 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
10531 | const struct comp_unit_head *cu_header, | |
10532 | unsigned int *bytes_read_ptr) | |
10533 | { | |
10534 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
10535 | ||
10536 | return read_indirect_string_at_offset (abfd, str_offset); | |
10537 | } | |
10538 | ||
ce5d95e1 | 10539 | static unsigned long |
fe1b8b76 | 10540 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10541 | { |
ce5d95e1 JB |
10542 | unsigned long result; |
10543 | unsigned int num_read; | |
c906108c SS |
10544 | int i, shift; |
10545 | unsigned char byte; | |
10546 | ||
10547 | result = 0; | |
10548 | shift = 0; | |
10549 | num_read = 0; | |
10550 | i = 0; | |
10551 | while (1) | |
10552 | { | |
fe1b8b76 | 10553 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10554 | buf++; |
10555 | num_read++; | |
ce5d95e1 | 10556 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
10557 | if ((byte & 128) == 0) |
10558 | { | |
10559 | break; | |
10560 | } | |
10561 | shift += 7; | |
10562 | } | |
10563 | *bytes_read_ptr = num_read; | |
10564 | return result; | |
10565 | } | |
10566 | ||
ce5d95e1 | 10567 | static long |
fe1b8b76 | 10568 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10569 | { |
ce5d95e1 | 10570 | long result; |
77e0b926 | 10571 | int i, shift, num_read; |
c906108c SS |
10572 | unsigned char byte; |
10573 | ||
10574 | result = 0; | |
10575 | shift = 0; | |
c906108c SS |
10576 | num_read = 0; |
10577 | i = 0; | |
10578 | while (1) | |
10579 | { | |
fe1b8b76 | 10580 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10581 | buf++; |
10582 | num_read++; | |
ce5d95e1 | 10583 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
10584 | shift += 7; |
10585 | if ((byte & 128) == 0) | |
10586 | { | |
10587 | break; | |
10588 | } | |
10589 | } | |
77e0b926 DJ |
10590 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
10591 | result |= -(((long)1) << shift); | |
c906108c SS |
10592 | *bytes_read_ptr = num_read; |
10593 | return result; | |
10594 | } | |
10595 | ||
4bb7a0a7 DJ |
10596 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10597 | ||
fe1b8b76 JB |
10598 | static gdb_byte * |
10599 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10600 | { |
10601 | int byte; | |
10602 | ||
10603 | while (1) | |
10604 | { | |
fe1b8b76 | 10605 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10606 | buf++; |
10607 | if ((byte & 128) == 0) | |
10608 | return buf; | |
10609 | } | |
10610 | } | |
10611 | ||
c906108c | 10612 | static void |
e142c38c | 10613 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10614 | { |
10615 | switch (lang) | |
10616 | { | |
10617 | case DW_LANG_C89: | |
76bee0cc | 10618 | case DW_LANG_C99: |
c906108c | 10619 | case DW_LANG_C: |
e142c38c | 10620 | cu->language = language_c; |
c906108c SS |
10621 | break; |
10622 | case DW_LANG_C_plus_plus: | |
e142c38c | 10623 | cu->language = language_cplus; |
c906108c | 10624 | break; |
6aecb9c2 JB |
10625 | case DW_LANG_D: |
10626 | cu->language = language_d; | |
10627 | break; | |
c906108c SS |
10628 | case DW_LANG_Fortran77: |
10629 | case DW_LANG_Fortran90: | |
b21b22e0 | 10630 | case DW_LANG_Fortran95: |
e142c38c | 10631 | cu->language = language_fortran; |
c906108c SS |
10632 | break; |
10633 | case DW_LANG_Mips_Assembler: | |
e142c38c | 10634 | cu->language = language_asm; |
c906108c | 10635 | break; |
bebd888e | 10636 | case DW_LANG_Java: |
e142c38c | 10637 | cu->language = language_java; |
bebd888e | 10638 | break; |
c906108c | 10639 | case DW_LANG_Ada83: |
8aaf0b47 | 10640 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10641 | cu->language = language_ada; |
10642 | break; | |
72019c9c GM |
10643 | case DW_LANG_Modula2: |
10644 | cu->language = language_m2; | |
10645 | break; | |
fe8e67fd PM |
10646 | case DW_LANG_Pascal83: |
10647 | cu->language = language_pascal; | |
10648 | break; | |
22566fbd DJ |
10649 | case DW_LANG_ObjC: |
10650 | cu->language = language_objc; | |
10651 | break; | |
c906108c SS |
10652 | case DW_LANG_Cobol74: |
10653 | case DW_LANG_Cobol85: | |
c906108c | 10654 | default: |
e142c38c | 10655 | cu->language = language_minimal; |
c906108c SS |
10656 | break; |
10657 | } | |
e142c38c | 10658 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10659 | } |
10660 | ||
10661 | /* Return the named attribute or NULL if not there. */ | |
10662 | ||
10663 | static struct attribute * | |
e142c38c | 10664 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
10665 | { |
10666 | unsigned int i; | |
10667 | struct attribute *spec = NULL; | |
10668 | ||
10669 | for (i = 0; i < die->num_attrs; ++i) | |
10670 | { | |
10671 | if (die->attrs[i].name == name) | |
10b3939b | 10672 | return &die->attrs[i]; |
c906108c SS |
10673 | if (die->attrs[i].name == DW_AT_specification |
10674 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10675 | spec = &die->attrs[i]; | |
10676 | } | |
c906108c | 10677 | |
10b3939b | 10678 | if (spec) |
f2f0e013 DJ |
10679 | { |
10680 | die = follow_die_ref (die, spec, &cu); | |
10681 | return dwarf2_attr (die, name, cu); | |
10682 | } | |
c5aa993b | 10683 | |
c906108c SS |
10684 | return NULL; |
10685 | } | |
10686 | ||
348e048f DE |
10687 | /* Return the named attribute or NULL if not there, |
10688 | but do not follow DW_AT_specification, etc. | |
10689 | This is for use in contexts where we're reading .debug_types dies. | |
10690 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10691 | back up the chain, and we want to go down. */ | |
10692 | ||
10693 | static struct attribute * | |
10694 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10695 | struct dwarf2_cu *cu) | |
10696 | { | |
10697 | unsigned int i; | |
10698 | ||
10699 | for (i = 0; i < die->num_attrs; ++i) | |
10700 | if (die->attrs[i].name == name) | |
10701 | return &die->attrs[i]; | |
10702 | ||
10703 | return NULL; | |
10704 | } | |
10705 | ||
05cf31d1 JB |
10706 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10707 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10708 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10709 | |
10710 | static int | |
10711 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10712 | { | |
10713 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10714 | ||
10715 | return (attr && DW_UNSND (attr)); | |
10716 | } | |
10717 | ||
3ca72b44 | 10718 | static int |
e142c38c | 10719 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10720 | { |
05cf31d1 JB |
10721 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10722 | which value is non-zero. However, we have to be careful with | |
10723 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10724 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10725 | end up accidently finding a declaration attribute that belongs | |
10726 | to a different DIE referenced by the specification attribute, | |
10727 | even though the given DIE does not have a declaration attribute. */ | |
10728 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10729 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10730 | } |
10731 | ||
63d06c5c | 10732 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10733 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10734 | containing the return value on output. If there is no |
10735 | specification, but there is an abstract origin, that is | |
10736 | returned. */ | |
63d06c5c DC |
10737 | |
10738 | static struct die_info * | |
f2f0e013 | 10739 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10740 | { |
f2f0e013 DJ |
10741 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10742 | *spec_cu); | |
63d06c5c | 10743 | |
edb3359d DJ |
10744 | if (spec_attr == NULL) |
10745 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10746 | ||
63d06c5c DC |
10747 | if (spec_attr == NULL) |
10748 | return NULL; | |
10749 | else | |
f2f0e013 | 10750 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10751 | } |
c906108c | 10752 | |
debd256d | 10753 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10754 | refers to. |
10755 | NOTE: This is also used as a "cleanup" function. */ | |
10756 | ||
debd256d JB |
10757 | static void |
10758 | free_line_header (struct line_header *lh) | |
10759 | { | |
10760 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10761 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10762 | |
10763 | /* Remember that all the lh->file_names[i].name pointers are | |
10764 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10765 | if (lh->file_names) | |
a8bc7b56 | 10766 | xfree (lh->file_names); |
debd256d JB |
10767 | |
10768 | /* Similarly for the include directory names. */ | |
10769 | if (lh->include_dirs) | |
a8bc7b56 | 10770 | xfree (lh->include_dirs); |
debd256d | 10771 | |
a8bc7b56 | 10772 | xfree (lh); |
debd256d JB |
10773 | } |
10774 | ||
debd256d | 10775 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10776 | |
debd256d JB |
10777 | static void |
10778 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10779 | { |
debd256d JB |
10780 | /* Grow the array if necessary. */ |
10781 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10782 | { |
debd256d JB |
10783 | lh->include_dirs_size = 1; /* for testing */ |
10784 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10785 | * sizeof (*lh->include_dirs)); | |
10786 | } | |
10787 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10788 | { | |
10789 | lh->include_dirs_size *= 2; | |
10790 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10791 | (lh->include_dirs_size | |
10792 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10793 | } |
c906108c | 10794 | |
debd256d JB |
10795 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10796 | } | |
6e70227d | 10797 | |
debd256d | 10798 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10799 | |
debd256d JB |
10800 | static void |
10801 | add_file_name (struct line_header *lh, | |
10802 | char *name, | |
10803 | unsigned int dir_index, | |
10804 | unsigned int mod_time, | |
10805 | unsigned int length) | |
10806 | { | |
10807 | struct file_entry *fe; | |
10808 | ||
10809 | /* Grow the array if necessary. */ | |
10810 | if (lh->file_names_size == 0) | |
10811 | { | |
10812 | lh->file_names_size = 1; /* for testing */ | |
10813 | lh->file_names = xmalloc (lh->file_names_size | |
10814 | * sizeof (*lh->file_names)); | |
10815 | } | |
10816 | else if (lh->num_file_names >= lh->file_names_size) | |
10817 | { | |
10818 | lh->file_names_size *= 2; | |
10819 | lh->file_names = xrealloc (lh->file_names, | |
10820 | (lh->file_names_size | |
10821 | * sizeof (*lh->file_names))); | |
10822 | } | |
10823 | ||
10824 | fe = &lh->file_names[lh->num_file_names++]; | |
10825 | fe->name = name; | |
10826 | fe->dir_index = dir_index; | |
10827 | fe->mod_time = mod_time; | |
10828 | fe->length = length; | |
aaa75496 | 10829 | fe->included_p = 0; |
cb1df416 | 10830 | fe->symtab = NULL; |
debd256d | 10831 | } |
6e70227d | 10832 | |
debd256d | 10833 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10834 | .debug_line, according to the endianness of ABFD. Return a pointer |
10835 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10836 | |
10837 | NOTE: the strings in the include directory and file name tables of | |
10838 | the returned object point into debug_line_buffer, and must not be | |
10839 | freed. */ | |
ae2de4f8 | 10840 | |
debd256d JB |
10841 | static struct line_header * |
10842 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10843 | struct dwarf2_cu *cu) |
debd256d JB |
10844 | { |
10845 | struct cleanup *back_to; | |
10846 | struct line_header *lh; | |
fe1b8b76 | 10847 | gdb_byte *line_ptr; |
c764a876 | 10848 | unsigned int bytes_read, offset_size; |
debd256d JB |
10849 | int i; |
10850 | char *cur_dir, *cur_file; | |
10851 | ||
be391dca | 10852 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10853 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10854 | { |
e2e0b3e5 | 10855 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10856 | return 0; |
10857 | } | |
10858 | ||
a738430d MK |
10859 | /* Make sure that at least there's room for the total_length field. |
10860 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10861 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10862 | { |
4d3c2250 | 10863 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10864 | return 0; |
10865 | } | |
10866 | ||
10867 | lh = xmalloc (sizeof (*lh)); | |
10868 | memset (lh, 0, sizeof (*lh)); | |
10869 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10870 | (void *) lh); | |
10871 | ||
dce234bc | 10872 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10873 | |
a738430d | 10874 | /* Read in the header. */ |
6e70227d | 10875 | lh->total_length = |
c764a876 DE |
10876 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10877 | &bytes_read, &offset_size); | |
debd256d | 10878 | line_ptr += bytes_read; |
dce234bc PP |
10879 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10880 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10881 | { |
4d3c2250 | 10882 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10883 | return 0; |
10884 | } | |
10885 | lh->statement_program_end = line_ptr + lh->total_length; | |
10886 | lh->version = read_2_bytes (abfd, line_ptr); | |
10887 | line_ptr += 2; | |
c764a876 DE |
10888 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10889 | line_ptr += offset_size; | |
debd256d JB |
10890 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10891 | line_ptr += 1; | |
2dc7f7b3 TT |
10892 | if (lh->version >= 4) |
10893 | { | |
10894 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10895 | line_ptr += 1; | |
10896 | } | |
10897 | else | |
10898 | lh->maximum_ops_per_instruction = 1; | |
10899 | ||
10900 | if (lh->maximum_ops_per_instruction == 0) | |
10901 | { | |
10902 | lh->maximum_ops_per_instruction = 1; | |
10903 | complaint (&symfile_complaints, | |
3e43a32a MS |
10904 | _("invalid maximum_ops_per_instruction " |
10905 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10906 | } |
10907 | ||
debd256d JB |
10908 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10909 | line_ptr += 1; | |
10910 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10911 | line_ptr += 1; | |
10912 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10913 | line_ptr += 1; | |
10914 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10915 | line_ptr += 1; | |
10916 | lh->standard_opcode_lengths | |
fe1b8b76 | 10917 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10918 | |
10919 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10920 | for (i = 1; i < lh->opcode_base; ++i) | |
10921 | { | |
10922 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10923 | line_ptr += 1; | |
10924 | } | |
10925 | ||
a738430d | 10926 | /* Read directory table. */ |
9b1c24c8 | 10927 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10928 | { |
10929 | line_ptr += bytes_read; | |
10930 | add_include_dir (lh, cur_dir); | |
10931 | } | |
10932 | line_ptr += bytes_read; | |
10933 | ||
a738430d | 10934 | /* Read file name table. */ |
9b1c24c8 | 10935 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10936 | { |
10937 | unsigned int dir_index, mod_time, length; | |
10938 | ||
10939 | line_ptr += bytes_read; | |
10940 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10941 | line_ptr += bytes_read; | |
10942 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10943 | line_ptr += bytes_read; | |
10944 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10945 | line_ptr += bytes_read; | |
10946 | ||
10947 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10948 | } | |
10949 | line_ptr += bytes_read; | |
6e70227d | 10950 | lh->statement_program_start = line_ptr; |
debd256d | 10951 | |
dce234bc PP |
10952 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
10953 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 10954 | complaint (&symfile_complaints, |
3e43a32a MS |
10955 | _("line number info header doesn't " |
10956 | "fit in `.debug_line' section")); | |
debd256d JB |
10957 | |
10958 | discard_cleanups (back_to); | |
10959 | return lh; | |
10960 | } | |
c906108c | 10961 | |
c6da4cef DE |
10962 | /* Subroutine of dwarf_decode_lines to simplify it. |
10963 | Return the file name of the psymtab for included file FILE_INDEX | |
10964 | in line header LH of PST. | |
10965 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10966 | If space for the result is malloc'd, it will be freed by a cleanup. | |
10967 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
10968 | ||
10969 | static char * | |
10970 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
10971 | const struct partial_symtab *pst, | |
10972 | const char *comp_dir) | |
10973 | { | |
10974 | const struct file_entry fe = lh->file_names [file_index]; | |
10975 | char *include_name = fe.name; | |
10976 | char *include_name_to_compare = include_name; | |
10977 | char *dir_name = NULL; | |
72b9f47f TT |
10978 | const char *pst_filename; |
10979 | char *copied_name = NULL; | |
c6da4cef DE |
10980 | int file_is_pst; |
10981 | ||
10982 | if (fe.dir_index) | |
10983 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
10984 | ||
10985 | if (!IS_ABSOLUTE_PATH (include_name) | |
10986 | && (dir_name != NULL || comp_dir != NULL)) | |
10987 | { | |
10988 | /* Avoid creating a duplicate psymtab for PST. | |
10989 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
10990 | Before we do the comparison, however, we need to account | |
10991 | for DIR_NAME and COMP_DIR. | |
10992 | First prepend dir_name (if non-NULL). If we still don't | |
10993 | have an absolute path prepend comp_dir (if non-NULL). | |
10994 | However, the directory we record in the include-file's | |
10995 | psymtab does not contain COMP_DIR (to match the | |
10996 | corresponding symtab(s)). | |
10997 | ||
10998 | Example: | |
10999 | ||
11000 | bash$ cd /tmp | |
11001 | bash$ gcc -g ./hello.c | |
11002 | include_name = "hello.c" | |
11003 | dir_name = "." | |
11004 | DW_AT_comp_dir = comp_dir = "/tmp" | |
11005 | DW_AT_name = "./hello.c" */ | |
11006 | ||
11007 | if (dir_name != NULL) | |
11008 | { | |
11009 | include_name = concat (dir_name, SLASH_STRING, | |
11010 | include_name, (char *)NULL); | |
11011 | include_name_to_compare = include_name; | |
11012 | make_cleanup (xfree, include_name); | |
11013 | } | |
11014 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
11015 | { | |
11016 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
11017 | include_name, (char *)NULL); | |
11018 | } | |
11019 | } | |
11020 | ||
11021 | pst_filename = pst->filename; | |
11022 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
11023 | { | |
72b9f47f TT |
11024 | copied_name = concat (pst->dirname, SLASH_STRING, |
11025 | pst_filename, (char *)NULL); | |
11026 | pst_filename = copied_name; | |
c6da4cef DE |
11027 | } |
11028 | ||
1e3fad37 | 11029 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
11030 | |
11031 | if (include_name_to_compare != include_name) | |
11032 | xfree (include_name_to_compare); | |
72b9f47f TT |
11033 | if (copied_name != NULL) |
11034 | xfree (copied_name); | |
c6da4cef DE |
11035 | |
11036 | if (file_is_pst) | |
11037 | return NULL; | |
11038 | return include_name; | |
11039 | } | |
11040 | ||
c91513d8 PP |
11041 | /* Ignore this record_line request. */ |
11042 | ||
11043 | static void | |
11044 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
11045 | { | |
11046 | return; | |
11047 | } | |
11048 | ||
aaa75496 JB |
11049 | /* Decode the Line Number Program (LNP) for the given line_header |
11050 | structure and CU. The actual information extracted and the type | |
11051 | of structures created from the LNP depends on the value of PST. | |
11052 | ||
11053 | 1. If PST is NULL, then this procedure uses the data from the program | |
11054 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 11055 | |
aaa75496 JB |
11056 | 2. If PST is not NULL, this procedure reads the program to determine |
11057 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
11058 | builds all the associated partial symbol tables. |
11059 | ||
11060 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11061 | It is used for relative paths in the line table. | |
11062 | NOTE: When processing partial symtabs (pst != NULL), | |
11063 | comp_dir == pst->dirname. | |
11064 | ||
11065 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
11066 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
11067 | symtab we don't use it in the name of the psymtabs we create. | |
11068 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
11069 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 11070 | |
c906108c | 11071 | static void |
72b9f47f | 11072 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd, |
aaa75496 | 11073 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 11074 | { |
a8c50c1f | 11075 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 11076 | gdb_byte *line_end; |
a8c50c1f | 11077 | unsigned int bytes_read, extended_len; |
c906108c | 11078 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
11079 | CORE_ADDR baseaddr; |
11080 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 11081 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 11082 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 11083 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
c91513d8 PP |
11084 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
11085 | = record_line; | |
e142c38c DJ |
11086 | |
11087 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11088 | |
debd256d JB |
11089 | line_ptr = lh->statement_program_start; |
11090 | line_end = lh->statement_program_end; | |
c906108c SS |
11091 | |
11092 | /* Read the statement sequences until there's nothing left. */ | |
11093 | while (line_ptr < line_end) | |
11094 | { | |
11095 | /* state machine registers */ | |
11096 | CORE_ADDR address = 0; | |
11097 | unsigned int file = 1; | |
11098 | unsigned int line = 1; | |
11099 | unsigned int column = 0; | |
debd256d | 11100 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
11101 | int basic_block = 0; |
11102 | int end_sequence = 0; | |
fbf65064 | 11103 | CORE_ADDR addr; |
2dc7f7b3 | 11104 | unsigned char op_index = 0; |
c906108c | 11105 | |
aaa75496 | 11106 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 11107 | { |
aaa75496 | 11108 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
11109 | /* lh->include_dirs and lh->file_names are 0-based, but the |
11110 | directory and file name numbers in the statement program | |
11111 | are 1-based. */ | |
11112 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 11113 | char *dir = NULL; |
a738430d | 11114 | |
debd256d JB |
11115 | if (fe->dir_index) |
11116 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
11117 | |
11118 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
11119 | } |
11120 | ||
a738430d | 11121 | /* Decode the table. */ |
c5aa993b | 11122 | while (!end_sequence) |
c906108c SS |
11123 | { |
11124 | op_code = read_1_byte (abfd, line_ptr); | |
11125 | line_ptr += 1; | |
59205f5a JB |
11126 | if (line_ptr > line_end) |
11127 | { | |
11128 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
11129 | break; | |
11130 | } | |
9aa1fe7e | 11131 | |
debd256d | 11132 | if (op_code >= lh->opcode_base) |
6e70227d | 11133 | { |
a738430d | 11134 | /* Special operand. */ |
debd256d | 11135 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
11136 | address += (((op_index + (adj_opcode / lh->line_range)) |
11137 | / lh->maximum_ops_per_instruction) | |
11138 | * lh->minimum_instruction_length); | |
11139 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
11140 | % lh->maximum_ops_per_instruction); | |
debd256d | 11141 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 11142 | if (lh->num_file_names < file || file == 0) |
25e43795 | 11143 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
11144 | /* For now we ignore lines not starting on an |
11145 | instruction boundary. */ | |
11146 | else if (op_index == 0) | |
25e43795 DJ |
11147 | { |
11148 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 11149 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11150 | { |
11151 | if (last_subfile != current_subfile) | |
11152 | { | |
11153 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11154 | if (last_subfile) | |
c91513d8 | 11155 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11156 | last_subfile = current_subfile; |
11157 | } | |
25e43795 | 11158 | /* Append row to matrix using current values. */ |
7019d805 | 11159 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11160 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 11161 | } |
25e43795 | 11162 | } |
ca5f395d | 11163 | basic_block = 0; |
9aa1fe7e GK |
11164 | } |
11165 | else switch (op_code) | |
c906108c SS |
11166 | { |
11167 | case DW_LNS_extended_op: | |
3e43a32a MS |
11168 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
11169 | &bytes_read); | |
473b7be6 | 11170 | line_ptr += bytes_read; |
a8c50c1f | 11171 | extended_end = line_ptr + extended_len; |
c906108c SS |
11172 | extended_op = read_1_byte (abfd, line_ptr); |
11173 | line_ptr += 1; | |
11174 | switch (extended_op) | |
11175 | { | |
11176 | case DW_LNE_end_sequence: | |
c91513d8 | 11177 | p_record_line = record_line; |
c906108c | 11178 | end_sequence = 1; |
c906108c SS |
11179 | break; |
11180 | case DW_LNE_set_address: | |
e7c27a73 | 11181 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
11182 | |
11183 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11184 | { | |
11185 | /* This line table is for a function which has been | |
11186 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
11187 | ||
11188 | long line_offset | |
11189 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
11190 | ||
11191 | complaint (&symfile_complaints, | |
11192 | _(".debug_line address at offset 0x%lx is 0 " | |
11193 | "[in module %s]"), | |
bb5ed363 | 11194 | line_offset, objfile->name); |
c91513d8 PP |
11195 | p_record_line = noop_record_line; |
11196 | } | |
11197 | ||
2dc7f7b3 | 11198 | op_index = 0; |
107d2387 AC |
11199 | line_ptr += bytes_read; |
11200 | address += baseaddr; | |
c906108c SS |
11201 | break; |
11202 | case DW_LNE_define_file: | |
debd256d JB |
11203 | { |
11204 | char *cur_file; | |
11205 | unsigned int dir_index, mod_time, length; | |
6e70227d | 11206 | |
3e43a32a MS |
11207 | cur_file = read_direct_string (abfd, line_ptr, |
11208 | &bytes_read); | |
debd256d JB |
11209 | line_ptr += bytes_read; |
11210 | dir_index = | |
11211 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11212 | line_ptr += bytes_read; | |
11213 | mod_time = | |
11214 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11215 | line_ptr += bytes_read; | |
11216 | length = | |
11217 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11218 | line_ptr += bytes_read; | |
11219 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11220 | } | |
c906108c | 11221 | break; |
d0c6ba3d CC |
11222 | case DW_LNE_set_discriminator: |
11223 | /* The discriminator is not interesting to the debugger; | |
11224 | just ignore it. */ | |
11225 | line_ptr = extended_end; | |
11226 | break; | |
c906108c | 11227 | default: |
4d3c2250 | 11228 | complaint (&symfile_complaints, |
e2e0b3e5 | 11229 | _("mangled .debug_line section")); |
debd256d | 11230 | return; |
c906108c | 11231 | } |
a8c50c1f DJ |
11232 | /* Make sure that we parsed the extended op correctly. If e.g. |
11233 | we expected a different address size than the producer used, | |
11234 | we may have read the wrong number of bytes. */ | |
11235 | if (line_ptr != extended_end) | |
11236 | { | |
11237 | complaint (&symfile_complaints, | |
11238 | _("mangled .debug_line section")); | |
11239 | return; | |
11240 | } | |
c906108c SS |
11241 | break; |
11242 | case DW_LNS_copy: | |
59205f5a | 11243 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11244 | dwarf2_debug_line_missing_file_complaint (); |
11245 | else | |
366da635 | 11246 | { |
25e43795 | 11247 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 11248 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11249 | { |
11250 | if (last_subfile != current_subfile) | |
11251 | { | |
11252 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11253 | if (last_subfile) | |
c91513d8 | 11254 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11255 | last_subfile = current_subfile; |
11256 | } | |
7019d805 | 11257 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11258 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 11259 | } |
366da635 | 11260 | } |
c906108c SS |
11261 | basic_block = 0; |
11262 | break; | |
11263 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
11264 | { |
11265 | CORE_ADDR adjust | |
11266 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11267 | ||
11268 | address += (((op_index + adjust) | |
11269 | / lh->maximum_ops_per_instruction) | |
11270 | * lh->minimum_instruction_length); | |
11271 | op_index = ((op_index + adjust) | |
11272 | % lh->maximum_ops_per_instruction); | |
11273 | line_ptr += bytes_read; | |
11274 | } | |
c906108c SS |
11275 | break; |
11276 | case DW_LNS_advance_line: | |
11277 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
11278 | line_ptr += bytes_read; | |
11279 | break; | |
11280 | case DW_LNS_set_file: | |
debd256d | 11281 | { |
a738430d MK |
11282 | /* The arrays lh->include_dirs and lh->file_names are |
11283 | 0-based, but the directory and file name numbers in | |
11284 | the statement program are 1-based. */ | |
debd256d | 11285 | struct file_entry *fe; |
4f1520fb | 11286 | char *dir = NULL; |
a738430d | 11287 | |
debd256d JB |
11288 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
11289 | line_ptr += bytes_read; | |
59205f5a | 11290 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11291 | dwarf2_debug_line_missing_file_complaint (); |
11292 | else | |
11293 | { | |
11294 | fe = &lh->file_names[file - 1]; | |
11295 | if (fe->dir_index) | |
11296 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11297 | if (!decode_for_pst_p) | |
11298 | { | |
11299 | last_subfile = current_subfile; | |
11300 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11301 | } | |
11302 | } | |
debd256d | 11303 | } |
c906108c SS |
11304 | break; |
11305 | case DW_LNS_set_column: | |
11306 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11307 | line_ptr += bytes_read; | |
11308 | break; | |
11309 | case DW_LNS_negate_stmt: | |
11310 | is_stmt = (!is_stmt); | |
11311 | break; | |
11312 | case DW_LNS_set_basic_block: | |
11313 | basic_block = 1; | |
11314 | break; | |
c2c6d25f JM |
11315 | /* Add to the address register of the state machine the |
11316 | address increment value corresponding to special opcode | |
a738430d MK |
11317 | 255. I.e., this value is scaled by the minimum |
11318 | instruction length since special opcode 255 would have | |
b021a221 | 11319 | scaled the increment. */ |
c906108c | 11320 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
11321 | { |
11322 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
11323 | ||
11324 | address += (((op_index + adjust) | |
11325 | / lh->maximum_ops_per_instruction) | |
11326 | * lh->minimum_instruction_length); | |
11327 | op_index = ((op_index + adjust) | |
11328 | % lh->maximum_ops_per_instruction); | |
11329 | } | |
c906108c SS |
11330 | break; |
11331 | case DW_LNS_fixed_advance_pc: | |
11332 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 11333 | op_index = 0; |
c906108c SS |
11334 | line_ptr += 2; |
11335 | break; | |
9aa1fe7e | 11336 | default: |
a738430d MK |
11337 | { |
11338 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 11339 | int i; |
a738430d | 11340 | |
debd256d | 11341 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
11342 | { |
11343 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11344 | line_ptr += bytes_read; | |
11345 | } | |
11346 | } | |
c906108c SS |
11347 | } |
11348 | } | |
59205f5a JB |
11349 | if (lh->num_file_names < file || file == 0) |
11350 | dwarf2_debug_line_missing_file_complaint (); | |
11351 | else | |
11352 | { | |
11353 | lh->file_names[file - 1].included_p = 1; | |
11354 | if (!decode_for_pst_p) | |
fbf65064 UW |
11355 | { |
11356 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 11357 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 11358 | } |
59205f5a | 11359 | } |
c906108c | 11360 | } |
aaa75496 JB |
11361 | |
11362 | if (decode_for_pst_p) | |
11363 | { | |
11364 | int file_index; | |
11365 | ||
11366 | /* Now that we're done scanning the Line Header Program, we can | |
11367 | create the psymtab of each included file. */ | |
11368 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
11369 | if (lh->file_names[file_index].included_p == 1) | |
11370 | { | |
c6da4cef DE |
11371 | char *include_name = |
11372 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
11373 | if (include_name != NULL) | |
aaa75496 JB |
11374 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
11375 | } | |
11376 | } | |
cb1df416 DJ |
11377 | else |
11378 | { | |
11379 | /* Make sure a symtab is created for every file, even files | |
11380 | which contain only variables (i.e. no code with associated | |
11381 | line numbers). */ | |
11382 | ||
11383 | int i; | |
11384 | struct file_entry *fe; | |
11385 | ||
11386 | for (i = 0; i < lh->num_file_names; i++) | |
11387 | { | |
11388 | char *dir = NULL; | |
9a619af0 | 11389 | |
cb1df416 DJ |
11390 | fe = &lh->file_names[i]; |
11391 | if (fe->dir_index) | |
11392 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11393 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11394 | ||
11395 | /* Skip the main file; we don't need it, and it must be | |
11396 | allocated last, so that it will show up before the | |
11397 | non-primary symtabs in the objfile's symtab list. */ | |
11398 | if (current_subfile == first_subfile) | |
11399 | continue; | |
11400 | ||
11401 | if (current_subfile->symtab == NULL) | |
11402 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 11403 | objfile); |
cb1df416 DJ |
11404 | fe->symtab = current_subfile->symtab; |
11405 | } | |
11406 | } | |
c906108c SS |
11407 | } |
11408 | ||
11409 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
11410 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
11411 | or NULL if not known. COMP_DIR is the compilation directory for the |
11412 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
11413 | This routine tries to keep line numbers from identical absolute and |
11414 | relative file names in a common subfile. | |
11415 | ||
11416 | Using the `list' example from the GDB testsuite, which resides in | |
11417 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
11418 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
11419 | ||
c5aa993b JM |
11420 | DW_AT_name: /srcdir/list0.c |
11421 | DW_AT_comp_dir: /compdir | |
357e46e7 | 11422 | files.files[0].name: list0.h |
c5aa993b | 11423 | files.files[0].dir: /srcdir |
357e46e7 | 11424 | files.files[1].name: list0.c |
c5aa993b | 11425 | files.files[1].dir: /srcdir |
c906108c SS |
11426 | |
11427 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
11428 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
11429 | start_subfile will ensure that this happens provided that we pass the | |
11430 | concatenation of files.files[1].dir and files.files[1].name as the | |
11431 | subfile's name. */ | |
c906108c SS |
11432 | |
11433 | static void | |
3e43a32a MS |
11434 | dwarf2_start_subfile (char *filename, const char *dirname, |
11435 | const char *comp_dir) | |
c906108c | 11436 | { |
4f1520fb FR |
11437 | char *fullname; |
11438 | ||
11439 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
11440 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
11441 | second argument to start_subfile. To be consistent, we do the | |
11442 | same here. In order not to lose the line information directory, | |
11443 | we concatenate it to the filename when it makes sense. | |
11444 | Note that the Dwarf3 standard says (speaking of filenames in line | |
11445 | information): ``The directory index is ignored for file names | |
11446 | that represent full path names''. Thus ignoring dirname in the | |
11447 | `else' branch below isn't an issue. */ | |
c906108c | 11448 | |
d5166ae1 | 11449 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
11450 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
11451 | else | |
11452 | fullname = filename; | |
c906108c | 11453 | |
4f1520fb FR |
11454 | start_subfile (fullname, comp_dir); |
11455 | ||
11456 | if (fullname != filename) | |
11457 | xfree (fullname); | |
c906108c SS |
11458 | } |
11459 | ||
4c2df51b DJ |
11460 | static void |
11461 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11462 | struct dwarf2_cu *cu) |
4c2df51b | 11463 | { |
e7c27a73 DJ |
11464 | struct objfile *objfile = cu->objfile; |
11465 | struct comp_unit_head *cu_header = &cu->header; | |
11466 | ||
4c2df51b DJ |
11467 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11468 | code here to turn a symbol with DW_AT_external and a | |
11469 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11470 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11471 | with some versions of binutils) where shared libraries could have | |
11472 | relocations against symbols in their debug information - the | |
11473 | minimal symbol would have the right address, but the debug info | |
11474 | would not. It's no longer necessary, because we will explicitly | |
11475 | apply relocations when we read in the debug information now. */ | |
11476 | ||
11477 | /* A DW_AT_location attribute with no contents indicates that a | |
11478 | variable has been optimized away. */ | |
11479 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11480 | { | |
11481 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11482 | return; | |
11483 | } | |
11484 | ||
11485 | /* Handle one degenerate form of location expression specially, to | |
11486 | preserve GDB's previous behavior when section offsets are | |
11487 | specified. If this is just a DW_OP_addr then mark this symbol | |
11488 | as LOC_STATIC. */ | |
11489 | ||
11490 | if (attr_form_is_block (attr) | |
11491 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11492 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11493 | { | |
891d2f0b | 11494 | unsigned int dummy; |
4c2df51b DJ |
11495 | |
11496 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11497 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11498 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11499 | fixup_symbol_section (sym, objfile); |
11500 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11501 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11502 | return; |
11503 | } | |
11504 | ||
11505 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11506 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11507 | (i.e. when the value of a register or memory location is | |
11508 | referenced, or a thread-local block, etc.). Then again, it might | |
11509 | not be worthwhile. I'm assuming that it isn't unless performance | |
11510 | or memory numbers show me otherwise. */ | |
11511 | ||
e7c27a73 | 11512 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11513 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11514 | |
11515 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11516 | cu->has_loclist = 1; | |
4c2df51b DJ |
11517 | } |
11518 | ||
c906108c SS |
11519 | /* Given a pointer to a DWARF information entry, figure out if we need |
11520 | to make a symbol table entry for it, and if so, create a new entry | |
11521 | and return a pointer to it. | |
11522 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11523 | used the passed type. |
11524 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11525 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11526 | |
11527 | static struct symbol * | |
34eaf542 TT |
11528 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11529 | struct symbol *space) | |
c906108c | 11530 | { |
e7c27a73 | 11531 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11532 | struct symbol *sym = NULL; |
11533 | char *name; | |
11534 | struct attribute *attr = NULL; | |
11535 | struct attribute *attr2 = NULL; | |
e142c38c | 11536 | CORE_ADDR baseaddr; |
e37fd15a SW |
11537 | struct pending **list_to_add = NULL; |
11538 | ||
edb3359d | 11539 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11540 | |
11541 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11542 | |
94af9270 | 11543 | name = dwarf2_name (die, cu); |
c906108c SS |
11544 | if (name) |
11545 | { | |
94af9270 | 11546 | const char *linkagename; |
34eaf542 | 11547 | int suppress_add = 0; |
94af9270 | 11548 | |
34eaf542 TT |
11549 | if (space) |
11550 | sym = space; | |
11551 | else | |
11552 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11553 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11554 | |
11555 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11556 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11557 | linkagename = dwarf2_physname (name, die, cu); |
11558 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11559 | |
f55ee35c JK |
11560 | /* Fortran does not have mangling standard and the mangling does differ |
11561 | between gfortran, iFort etc. */ | |
11562 | if (cu->language == language_fortran | |
b250c185 | 11563 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11564 | symbol_set_demangled_name (&(sym->ginfo), |
11565 | (char *) dwarf2_full_name (name, die, cu), | |
11566 | NULL); | |
f55ee35c | 11567 | |
c906108c | 11568 | /* Default assumptions. |
c5aa993b | 11569 | Use the passed type or decode it from the die. */ |
176620f1 | 11570 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11571 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11572 | if (type != NULL) |
11573 | SYMBOL_TYPE (sym) = type; | |
11574 | else | |
e7c27a73 | 11575 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11576 | attr = dwarf2_attr (die, |
11577 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11578 | cu); | |
c906108c SS |
11579 | if (attr) |
11580 | { | |
11581 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11582 | } | |
cb1df416 | 11583 | |
edb3359d DJ |
11584 | attr = dwarf2_attr (die, |
11585 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11586 | cu); | |
cb1df416 DJ |
11587 | if (attr) |
11588 | { | |
11589 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11590 | |
cb1df416 DJ |
11591 | if (cu->line_header == NULL |
11592 | || file_index > cu->line_header->num_file_names) | |
11593 | complaint (&symfile_complaints, | |
11594 | _("file index out of range")); | |
1c3d648d | 11595 | else if (file_index > 0) |
cb1df416 DJ |
11596 | { |
11597 | struct file_entry *fe; | |
9a619af0 | 11598 | |
cb1df416 DJ |
11599 | fe = &cu->line_header->file_names[file_index - 1]; |
11600 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11601 | } | |
11602 | } | |
11603 | ||
c906108c SS |
11604 | switch (die->tag) |
11605 | { | |
11606 | case DW_TAG_label: | |
e142c38c | 11607 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11608 | if (attr) |
11609 | { | |
11610 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11611 | } | |
0f5238ed TT |
11612 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11613 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11614 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11615 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11616 | break; |
11617 | case DW_TAG_subprogram: | |
11618 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11619 | finish_block. */ | |
11620 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11621 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11622 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11623 | || cu->language == language_ada) | |
c906108c | 11624 | { |
2cfa0c8d JB |
11625 | /* Subprograms marked external are stored as a global symbol. |
11626 | Ada subprograms, whether marked external or not, are always | |
11627 | stored as a global symbol, because we want to be able to | |
11628 | access them globally. For instance, we want to be able | |
11629 | to break on a nested subprogram without having to | |
11630 | specify the context. */ | |
e37fd15a | 11631 | list_to_add = &global_symbols; |
c906108c SS |
11632 | } |
11633 | else | |
11634 | { | |
e37fd15a | 11635 | list_to_add = cu->list_in_scope; |
c906108c SS |
11636 | } |
11637 | break; | |
edb3359d DJ |
11638 | case DW_TAG_inlined_subroutine: |
11639 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11640 | finish_block. */ | |
11641 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11642 | SYMBOL_INLINED (sym) = 1; | |
11643 | /* Do not add the symbol to any lists. It will be found via | |
11644 | BLOCK_FUNCTION from the blockvector. */ | |
11645 | break; | |
34eaf542 TT |
11646 | case DW_TAG_template_value_param: |
11647 | suppress_add = 1; | |
11648 | /* Fall through. */ | |
72929c62 | 11649 | case DW_TAG_constant: |
c906108c | 11650 | case DW_TAG_variable: |
254e6b9e | 11651 | case DW_TAG_member: |
0963b4bd MS |
11652 | /* Compilation with minimal debug info may result in |
11653 | variables with missing type entries. Change the | |
11654 | misleading `void' type to something sensible. */ | |
c906108c | 11655 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11656 | SYMBOL_TYPE (sym) |
46bf5051 | 11657 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11658 | |
e142c38c | 11659 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11660 | /* In the case of DW_TAG_member, we should only be called for |
11661 | static const members. */ | |
11662 | if (die->tag == DW_TAG_member) | |
11663 | { | |
3863f96c DE |
11664 | /* dwarf2_add_field uses die_is_declaration, |
11665 | so we do the same. */ | |
254e6b9e DE |
11666 | gdb_assert (die_is_declaration (die, cu)); |
11667 | gdb_assert (attr); | |
11668 | } | |
c906108c SS |
11669 | if (attr) |
11670 | { | |
e7c27a73 | 11671 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11672 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11673 | if (!suppress_add) |
34eaf542 TT |
11674 | { |
11675 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11676 | list_to_add = &global_symbols; |
34eaf542 | 11677 | else |
e37fd15a | 11678 | list_to_add = cu->list_in_scope; |
34eaf542 | 11679 | } |
c906108c SS |
11680 | break; |
11681 | } | |
e142c38c | 11682 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11683 | if (attr) |
11684 | { | |
e7c27a73 | 11685 | var_decode_location (attr, sym, cu); |
e142c38c | 11686 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11687 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11688 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11689 | && !dwarf2_per_objfile->has_section_at_zero) | |
11690 | { | |
11691 | /* When a static variable is eliminated by the linker, | |
11692 | the corresponding debug information is not stripped | |
11693 | out, but the variable address is set to null; | |
11694 | do not add such variables into symbol table. */ | |
11695 | } | |
11696 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11697 | { |
f55ee35c JK |
11698 | /* Workaround gfortran PR debug/40040 - it uses |
11699 | DW_AT_location for variables in -fPIC libraries which may | |
11700 | get overriden by other libraries/executable and get | |
11701 | a different address. Resolve it by the minimal symbol | |
11702 | which may come from inferior's executable using copy | |
11703 | relocation. Make this workaround only for gfortran as for | |
11704 | other compilers GDB cannot guess the minimal symbol | |
11705 | Fortran mangling kind. */ | |
11706 | if (cu->language == language_fortran && die->parent | |
11707 | && die->parent->tag == DW_TAG_module | |
11708 | && cu->producer | |
11709 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11710 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11711 | ||
1c809c68 TT |
11712 | /* A variable with DW_AT_external is never static, |
11713 | but it may be block-scoped. */ | |
11714 | list_to_add = (cu->list_in_scope == &file_symbols | |
11715 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11716 | } |
c906108c | 11717 | else |
e37fd15a | 11718 | list_to_add = cu->list_in_scope; |
c906108c SS |
11719 | } |
11720 | else | |
11721 | { | |
11722 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11723 | If it is an external symbol and we have type information |
11724 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11725 | The address of the variable will then be determined from | |
11726 | the minimal symbol table whenever the variable is | |
11727 | referenced. */ | |
e142c38c | 11728 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11729 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11730 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11731 | { |
0fe7935b DJ |
11732 | /* A variable with DW_AT_external is never static, but it |
11733 | may be block-scoped. */ | |
11734 | list_to_add = (cu->list_in_scope == &file_symbols | |
11735 | ? &global_symbols : cu->list_in_scope); | |
11736 | ||
c906108c | 11737 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11738 | } |
442ddf59 JK |
11739 | else if (!die_is_declaration (die, cu)) |
11740 | { | |
11741 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11742 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11743 | if (!suppress_add) |
11744 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11745 | } |
c906108c SS |
11746 | } |
11747 | break; | |
11748 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11749 | /* If we are inside a function, mark this as an argument. If |
11750 | not, we might be looking at an argument to an inlined function | |
11751 | when we do not have enough information to show inlined frames; | |
11752 | pretend it's a local variable in that case so that the user can | |
11753 | still see it. */ | |
11754 | if (context_stack_depth > 0 | |
11755 | && context_stack[context_stack_depth - 1].name != NULL) | |
11756 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11757 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11758 | if (attr) |
11759 | { | |
e7c27a73 | 11760 | var_decode_location (attr, sym, cu); |
c906108c | 11761 | } |
e142c38c | 11762 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11763 | if (attr) |
11764 | { | |
e7c27a73 | 11765 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11766 | } |
f346a30d | 11767 | |
e37fd15a | 11768 | list_to_add = cu->list_in_scope; |
c906108c SS |
11769 | break; |
11770 | case DW_TAG_unspecified_parameters: | |
11771 | /* From varargs functions; gdb doesn't seem to have any | |
11772 | interest in this information, so just ignore it for now. | |
11773 | (FIXME?) */ | |
11774 | break; | |
34eaf542 TT |
11775 | case DW_TAG_template_type_param: |
11776 | suppress_add = 1; | |
11777 | /* Fall through. */ | |
c906108c | 11778 | case DW_TAG_class_type: |
680b30c7 | 11779 | case DW_TAG_interface_type: |
c906108c SS |
11780 | case DW_TAG_structure_type: |
11781 | case DW_TAG_union_type: | |
72019c9c | 11782 | case DW_TAG_set_type: |
c906108c SS |
11783 | case DW_TAG_enumeration_type: |
11784 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11785 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11786 | |
63d06c5c | 11787 | { |
987504bb | 11788 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11789 | really ever be static objects: otherwise, if you try |
11790 | to, say, break of a class's method and you're in a file | |
11791 | which doesn't mention that class, it won't work unless | |
11792 | the check for all static symbols in lookup_symbol_aux | |
11793 | saves you. See the OtherFileClass tests in | |
11794 | gdb.c++/namespace.exp. */ | |
11795 | ||
e37fd15a | 11796 | if (!suppress_add) |
34eaf542 | 11797 | { |
34eaf542 TT |
11798 | list_to_add = (cu->list_in_scope == &file_symbols |
11799 | && (cu->language == language_cplus | |
11800 | || cu->language == language_java) | |
11801 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11802 | |
64382290 TT |
11803 | /* The semantics of C++ state that "struct foo { |
11804 | ... }" also defines a typedef for "foo". A Java | |
11805 | class declaration also defines a typedef for the | |
11806 | class. */ | |
11807 | if (cu->language == language_cplus | |
11808 | || cu->language == language_java | |
11809 | || cu->language == language_ada) | |
11810 | { | |
11811 | /* The symbol's name is already allocated along | |
11812 | with this objfile, so we don't need to | |
11813 | duplicate it for the type. */ | |
11814 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11815 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11816 | } | |
63d06c5c DC |
11817 | } |
11818 | } | |
c906108c SS |
11819 | break; |
11820 | case DW_TAG_typedef: | |
63d06c5c DC |
11821 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11822 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11823 | list_to_add = cu->list_in_scope; |
63d06c5c | 11824 | break; |
c906108c | 11825 | case DW_TAG_base_type: |
a02abb62 | 11826 | case DW_TAG_subrange_type: |
c906108c | 11827 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11828 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11829 | list_to_add = cu->list_in_scope; |
c906108c SS |
11830 | break; |
11831 | case DW_TAG_enumerator: | |
e142c38c | 11832 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11833 | if (attr) |
11834 | { | |
e7c27a73 | 11835 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11836 | } |
63d06c5c DC |
11837 | { |
11838 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11839 | DW_TAG_class_type, etc. block. */ | |
11840 | ||
e142c38c | 11841 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11842 | && (cu->language == language_cplus |
11843 | || cu->language == language_java) | |
e142c38c | 11844 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11845 | } |
c906108c | 11846 | break; |
5c4e30ca DC |
11847 | case DW_TAG_namespace: |
11848 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11849 | list_to_add = &global_symbols; |
5c4e30ca | 11850 | break; |
c906108c SS |
11851 | default: |
11852 | /* Not a tag we recognize. Hopefully we aren't processing | |
11853 | trash data, but since we must specifically ignore things | |
11854 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11855 | this point. */ |
e2e0b3e5 | 11856 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11857 | dwarf_tag_name (die->tag)); |
c906108c SS |
11858 | break; |
11859 | } | |
df8a16a1 | 11860 | |
e37fd15a SW |
11861 | if (suppress_add) |
11862 | { | |
11863 | sym->hash_next = objfile->template_symbols; | |
11864 | objfile->template_symbols = sym; | |
11865 | list_to_add = NULL; | |
11866 | } | |
11867 | ||
11868 | if (list_to_add != NULL) | |
11869 | add_symbol_to_list (sym, list_to_add); | |
11870 | ||
df8a16a1 DJ |
11871 | /* For the benefit of old versions of GCC, check for anonymous |
11872 | namespaces based on the demangled name. */ | |
11873 | if (!processing_has_namespace_info | |
94af9270 | 11874 | && cu->language == language_cplus) |
a10964d1 | 11875 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
11876 | } |
11877 | return (sym); | |
11878 | } | |
11879 | ||
34eaf542 TT |
11880 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11881 | ||
11882 | static struct symbol * | |
11883 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11884 | { | |
11885 | return new_symbol_full (die, type, cu, NULL); | |
11886 | } | |
11887 | ||
98bfdba5 PA |
11888 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11889 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11890 | standard (v4) is not entirely clear about the meaning of using | |
11891 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11892 | wider than the data. The conclusion of a discussion on the DWARF | |
11893 | list was that this is unspecified. We choose to always zero-extend | |
11894 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11895 | |
98bfdba5 PA |
11896 | static gdb_byte * |
11897 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11898 | const char *name, struct obstack *obstack, | |
11899 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11900 | { |
e7c27a73 | 11901 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11902 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11903 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11904 | LONGEST l = DW_UNSND (attr); |
11905 | ||
11906 | if (bits < sizeof (*value) * 8) | |
11907 | { | |
11908 | l &= ((LONGEST) 1 << bits) - 1; | |
11909 | *value = l; | |
11910 | } | |
11911 | else if (bits == sizeof (*value) * 8) | |
11912 | *value = l; | |
11913 | else | |
11914 | { | |
11915 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11916 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11917 | return bytes; | |
11918 | } | |
11919 | ||
11920 | return NULL; | |
11921 | } | |
11922 | ||
11923 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11924 | the value does not fit in *VALUE, set *BYTES - either already | |
11925 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11926 | or, set *BATON, if we translated the constant to a location | |
11927 | expression. */ | |
11928 | ||
11929 | static void | |
11930 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11931 | const char *name, struct obstack *obstack, | |
11932 | struct dwarf2_cu *cu, | |
11933 | long *value, gdb_byte **bytes, | |
11934 | struct dwarf2_locexpr_baton **baton) | |
11935 | { | |
11936 | struct objfile *objfile = cu->objfile; | |
11937 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 11938 | struct dwarf_block *blk; |
98bfdba5 PA |
11939 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
11940 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
11941 | ||
11942 | *value = 0; | |
11943 | *bytes = NULL; | |
11944 | *baton = NULL; | |
c906108c SS |
11945 | |
11946 | switch (attr->form) | |
11947 | { | |
11948 | case DW_FORM_addr: | |
ac56253d | 11949 | { |
ac56253d TT |
11950 | gdb_byte *data; |
11951 | ||
98bfdba5 PA |
11952 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
11953 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 11954 | cu_header->addr_size, |
98bfdba5 | 11955 | TYPE_LENGTH (type)); |
ac56253d TT |
11956 | /* Symbols of this form are reasonably rare, so we just |
11957 | piggyback on the existing location code rather than writing | |
11958 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
11959 | *baton = obstack_alloc (&objfile->objfile_obstack, |
11960 | sizeof (struct dwarf2_locexpr_baton)); | |
11961 | (*baton)->per_cu = cu->per_cu; | |
11962 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 11963 | |
98bfdba5 PA |
11964 | (*baton)->size = 2 + cu_header->addr_size; |
11965 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
11966 | (*baton)->data = data; | |
ac56253d TT |
11967 | |
11968 | data[0] = DW_OP_addr; | |
11969 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
11970 | byte_order, DW_ADDR (attr)); | |
11971 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 11972 | } |
c906108c | 11973 | break; |
4ac36638 | 11974 | case DW_FORM_string: |
93b5768b | 11975 | case DW_FORM_strp: |
98bfdba5 PA |
11976 | /* DW_STRING is already allocated on the objfile obstack, point |
11977 | directly to it. */ | |
11978 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 11979 | break; |
c906108c SS |
11980 | case DW_FORM_block1: |
11981 | case DW_FORM_block2: | |
11982 | case DW_FORM_block4: | |
11983 | case DW_FORM_block: | |
2dc7f7b3 | 11984 | case DW_FORM_exprloc: |
c906108c | 11985 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
11986 | if (TYPE_LENGTH (type) != blk->size) |
11987 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
11988 | TYPE_LENGTH (type)); | |
11989 | *bytes = blk->data; | |
c906108c | 11990 | break; |
2df3850c JM |
11991 | |
11992 | /* The DW_AT_const_value attributes are supposed to carry the | |
11993 | symbol's value "represented as it would be on the target | |
11994 | architecture." By the time we get here, it's already been | |
11995 | converted to host endianness, so we just need to sign- or | |
11996 | zero-extend it as appropriate. */ | |
11997 | case DW_FORM_data1: | |
3e43a32a MS |
11998 | *bytes = dwarf2_const_value_data (attr, type, name, |
11999 | obstack, cu, value, 8); | |
2df3850c | 12000 | break; |
c906108c | 12001 | case DW_FORM_data2: |
3e43a32a MS |
12002 | *bytes = dwarf2_const_value_data (attr, type, name, |
12003 | obstack, cu, value, 16); | |
2df3850c | 12004 | break; |
c906108c | 12005 | case DW_FORM_data4: |
3e43a32a MS |
12006 | *bytes = dwarf2_const_value_data (attr, type, name, |
12007 | obstack, cu, value, 32); | |
2df3850c | 12008 | break; |
c906108c | 12009 | case DW_FORM_data8: |
3e43a32a MS |
12010 | *bytes = dwarf2_const_value_data (attr, type, name, |
12011 | obstack, cu, value, 64); | |
2df3850c JM |
12012 | break; |
12013 | ||
c906108c | 12014 | case DW_FORM_sdata: |
98bfdba5 | 12015 | *value = DW_SND (attr); |
2df3850c JM |
12016 | break; |
12017 | ||
c906108c | 12018 | case DW_FORM_udata: |
98bfdba5 | 12019 | *value = DW_UNSND (attr); |
c906108c | 12020 | break; |
2df3850c | 12021 | |
c906108c | 12022 | default: |
4d3c2250 | 12023 | complaint (&symfile_complaints, |
e2e0b3e5 | 12024 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 12025 | dwarf_form_name (attr->form)); |
98bfdba5 | 12026 | *value = 0; |
c906108c SS |
12027 | break; |
12028 | } | |
12029 | } | |
12030 | ||
2df3850c | 12031 | |
98bfdba5 PA |
12032 | /* Copy constant value from an attribute to a symbol. */ |
12033 | ||
2df3850c | 12034 | static void |
98bfdba5 PA |
12035 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
12036 | struct dwarf2_cu *cu) | |
2df3850c | 12037 | { |
98bfdba5 PA |
12038 | struct objfile *objfile = cu->objfile; |
12039 | struct comp_unit_head *cu_header = &cu->header; | |
12040 | long value; | |
12041 | gdb_byte *bytes; | |
12042 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 12043 | |
98bfdba5 PA |
12044 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
12045 | SYMBOL_PRINT_NAME (sym), | |
12046 | &objfile->objfile_obstack, cu, | |
12047 | &value, &bytes, &baton); | |
2df3850c | 12048 | |
98bfdba5 PA |
12049 | if (baton != NULL) |
12050 | { | |
12051 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
12052 | SYMBOL_LOCATION_BATON (sym) = baton; | |
12053 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
12054 | } | |
12055 | else if (bytes != NULL) | |
12056 | { | |
12057 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
12058 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
12059 | } | |
12060 | else | |
12061 | { | |
12062 | SYMBOL_VALUE (sym) = value; | |
12063 | SYMBOL_CLASS (sym) = LOC_CONST; | |
12064 | } | |
2df3850c JM |
12065 | } |
12066 | ||
c906108c SS |
12067 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
12068 | ||
12069 | static struct type * | |
e7c27a73 | 12070 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12071 | { |
c906108c | 12072 | struct attribute *type_attr; |
c906108c | 12073 | |
e142c38c | 12074 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
12075 | if (!type_attr) |
12076 | { | |
12077 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 12078 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 12079 | } |
348e048f | 12080 | |
673bfd45 | 12081 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12082 | } |
12083 | ||
b4ba55a1 JB |
12084 | /* True iff CU's producer generates GNAT Ada auxiliary information |
12085 | that allows to find parallel types through that information instead | |
12086 | of having to do expensive parallel lookups by type name. */ | |
12087 | ||
12088 | static int | |
12089 | need_gnat_info (struct dwarf2_cu *cu) | |
12090 | { | |
12091 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
12092 | of GNAT produces this auxiliary information, without any indication | |
12093 | that it is produced. Part of enhancing the FSF version of GNAT | |
12094 | to produce that information will be to put in place an indicator | |
12095 | that we can use in order to determine whether the descriptive type | |
12096 | info is available or not. One suggestion that has been made is | |
12097 | to use a new attribute, attached to the CU die. For now, assume | |
12098 | that the descriptive type info is not available. */ | |
12099 | return 0; | |
12100 | } | |
12101 | ||
b4ba55a1 JB |
12102 | /* Return the auxiliary type of the die in question using its |
12103 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
12104 | attribute is not present. */ | |
12105 | ||
12106 | static struct type * | |
12107 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
12108 | { | |
b4ba55a1 | 12109 | struct attribute *type_attr; |
b4ba55a1 JB |
12110 | |
12111 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
12112 | if (!type_attr) | |
12113 | return NULL; | |
12114 | ||
673bfd45 | 12115 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
12116 | } |
12117 | ||
12118 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
12119 | descriptive type accordingly. */ | |
12120 | ||
12121 | static void | |
12122 | set_descriptive_type (struct type *type, struct die_info *die, | |
12123 | struct dwarf2_cu *cu) | |
12124 | { | |
12125 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
12126 | ||
12127 | if (descriptive_type) | |
12128 | { | |
12129 | ALLOCATE_GNAT_AUX_TYPE (type); | |
12130 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
12131 | } | |
12132 | } | |
12133 | ||
c906108c SS |
12134 | /* Return the containing type of the die in question using its |
12135 | DW_AT_containing_type attribute. */ | |
12136 | ||
12137 | static struct type * | |
e7c27a73 | 12138 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12139 | { |
c906108c | 12140 | struct attribute *type_attr; |
c906108c | 12141 | |
e142c38c | 12142 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
12143 | if (!type_attr) |
12144 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
12145 | "[in module %s]"), cu->objfile->name); | |
12146 | ||
673bfd45 | 12147 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12148 | } |
12149 | ||
673bfd45 DE |
12150 | /* Look up the type of DIE in CU using its type attribute ATTR. |
12151 | If there is no type substitute an error marker. */ | |
12152 | ||
c906108c | 12153 | static struct type * |
673bfd45 DE |
12154 | lookup_die_type (struct die_info *die, struct attribute *attr, |
12155 | struct dwarf2_cu *cu) | |
c906108c | 12156 | { |
bb5ed363 | 12157 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
12158 | struct type *this_type; |
12159 | ||
673bfd45 DE |
12160 | /* First see if we have it cached. */ |
12161 | ||
12162 | if (is_ref_attr (attr)) | |
12163 | { | |
12164 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12165 | ||
12166 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
12167 | } | |
55f1336d | 12168 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
12169 | { |
12170 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12171 | struct dwarf2_cu *sig_cu; | |
12172 | unsigned int offset; | |
12173 | ||
12174 | /* sig_type will be NULL if the signatured type is missing from | |
12175 | the debug info. */ | |
12176 | if (sig_type == NULL) | |
12177 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12178 | "at 0x%x [in module %s]"), | |
bb5ed363 | 12179 | die->offset, objfile->name); |
673bfd45 | 12180 | |
b0df02fd | 12181 | gdb_assert (sig_type->per_cu.debug_types_section); |
b3c8eb43 | 12182 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
673bfd45 DE |
12183 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
12184 | } | |
12185 | else | |
12186 | { | |
12187 | dump_die_for_error (die); | |
12188 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 12189 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
12190 | } |
12191 | ||
12192 | /* If not cached we need to read it in. */ | |
12193 | ||
12194 | if (this_type == NULL) | |
12195 | { | |
12196 | struct die_info *type_die; | |
12197 | struct dwarf2_cu *type_cu = cu; | |
12198 | ||
12199 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
12200 | /* If the type is cached, we should have found it above. */ | |
12201 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
12202 | this_type = read_type_die_1 (type_die, type_cu); | |
12203 | } | |
12204 | ||
12205 | /* If we still don't have a type use an error marker. */ | |
12206 | ||
12207 | if (this_type == NULL) | |
c906108c | 12208 | { |
b00fdb78 TT |
12209 | char *message, *saved; |
12210 | ||
12211 | /* read_type_die already issued a complaint. */ | |
12212 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 12213 | objfile->name, |
b00fdb78 TT |
12214 | cu->header.offset, |
12215 | die->offset); | |
bb5ed363 | 12216 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
12217 | message, strlen (message)); |
12218 | xfree (message); | |
12219 | ||
bb5ed363 | 12220 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 12221 | } |
673bfd45 | 12222 | |
f792889a | 12223 | return this_type; |
c906108c SS |
12224 | } |
12225 | ||
673bfd45 DE |
12226 | /* Return the type in DIE, CU. |
12227 | Returns NULL for invalid types. | |
12228 | ||
12229 | This first does a lookup in the appropriate type_hash table, | |
12230 | and only reads the die in if necessary. | |
12231 | ||
12232 | NOTE: This can be called when reading in partial or full symbols. */ | |
12233 | ||
f792889a | 12234 | static struct type * |
e7c27a73 | 12235 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12236 | { |
f792889a DJ |
12237 | struct type *this_type; |
12238 | ||
12239 | this_type = get_die_type (die, cu); | |
12240 | if (this_type) | |
12241 | return this_type; | |
12242 | ||
673bfd45 DE |
12243 | return read_type_die_1 (die, cu); |
12244 | } | |
12245 | ||
12246 | /* Read the type in DIE, CU. | |
12247 | Returns NULL for invalid types. */ | |
12248 | ||
12249 | static struct type * | |
12250 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
12251 | { | |
12252 | struct type *this_type = NULL; | |
12253 | ||
c906108c SS |
12254 | switch (die->tag) |
12255 | { | |
12256 | case DW_TAG_class_type: | |
680b30c7 | 12257 | case DW_TAG_interface_type: |
c906108c SS |
12258 | case DW_TAG_structure_type: |
12259 | case DW_TAG_union_type: | |
f792889a | 12260 | this_type = read_structure_type (die, cu); |
c906108c SS |
12261 | break; |
12262 | case DW_TAG_enumeration_type: | |
f792889a | 12263 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
12264 | break; |
12265 | case DW_TAG_subprogram: | |
12266 | case DW_TAG_subroutine_type: | |
edb3359d | 12267 | case DW_TAG_inlined_subroutine: |
f792889a | 12268 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
12269 | break; |
12270 | case DW_TAG_array_type: | |
f792889a | 12271 | this_type = read_array_type (die, cu); |
c906108c | 12272 | break; |
72019c9c | 12273 | case DW_TAG_set_type: |
f792889a | 12274 | this_type = read_set_type (die, cu); |
72019c9c | 12275 | break; |
c906108c | 12276 | case DW_TAG_pointer_type: |
f792889a | 12277 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
12278 | break; |
12279 | case DW_TAG_ptr_to_member_type: | |
f792889a | 12280 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
12281 | break; |
12282 | case DW_TAG_reference_type: | |
f792889a | 12283 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
12284 | break; |
12285 | case DW_TAG_const_type: | |
f792889a | 12286 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
12287 | break; |
12288 | case DW_TAG_volatile_type: | |
f792889a | 12289 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
12290 | break; |
12291 | case DW_TAG_string_type: | |
f792889a | 12292 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
12293 | break; |
12294 | case DW_TAG_typedef: | |
f792889a | 12295 | this_type = read_typedef (die, cu); |
c906108c | 12296 | break; |
a02abb62 | 12297 | case DW_TAG_subrange_type: |
f792889a | 12298 | this_type = read_subrange_type (die, cu); |
a02abb62 | 12299 | break; |
c906108c | 12300 | case DW_TAG_base_type: |
f792889a | 12301 | this_type = read_base_type (die, cu); |
c906108c | 12302 | break; |
81a17f79 | 12303 | case DW_TAG_unspecified_type: |
f792889a | 12304 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 12305 | break; |
0114d602 DJ |
12306 | case DW_TAG_namespace: |
12307 | this_type = read_namespace_type (die, cu); | |
12308 | break; | |
f55ee35c JK |
12309 | case DW_TAG_module: |
12310 | this_type = read_module_type (die, cu); | |
12311 | break; | |
c906108c | 12312 | default: |
3e43a32a MS |
12313 | complaint (&symfile_complaints, |
12314 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 12315 | dwarf_tag_name (die->tag)); |
c906108c SS |
12316 | break; |
12317 | } | |
63d06c5c | 12318 | |
f792889a | 12319 | return this_type; |
63d06c5c DC |
12320 | } |
12321 | ||
abc72ce4 DE |
12322 | /* See if we can figure out if the class lives in a namespace. We do |
12323 | this by looking for a member function; its demangled name will | |
12324 | contain namespace info, if there is any. | |
12325 | Return the computed name or NULL. | |
12326 | Space for the result is allocated on the objfile's obstack. | |
12327 | This is the full-die version of guess_partial_die_structure_name. | |
12328 | In this case we know DIE has no useful parent. */ | |
12329 | ||
12330 | static char * | |
12331 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
12332 | { | |
12333 | struct die_info *spec_die; | |
12334 | struct dwarf2_cu *spec_cu; | |
12335 | struct die_info *child; | |
12336 | ||
12337 | spec_cu = cu; | |
12338 | spec_die = die_specification (die, &spec_cu); | |
12339 | if (spec_die != NULL) | |
12340 | { | |
12341 | die = spec_die; | |
12342 | cu = spec_cu; | |
12343 | } | |
12344 | ||
12345 | for (child = die->child; | |
12346 | child != NULL; | |
12347 | child = child->sibling) | |
12348 | { | |
12349 | if (child->tag == DW_TAG_subprogram) | |
12350 | { | |
12351 | struct attribute *attr; | |
12352 | ||
12353 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
12354 | if (attr == NULL) | |
12355 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
12356 | if (attr != NULL) | |
12357 | { | |
12358 | char *actual_name | |
12359 | = language_class_name_from_physname (cu->language_defn, | |
12360 | DW_STRING (attr)); | |
12361 | char *name = NULL; | |
12362 | ||
12363 | if (actual_name != NULL) | |
12364 | { | |
12365 | char *die_name = dwarf2_name (die, cu); | |
12366 | ||
12367 | if (die_name != NULL | |
12368 | && strcmp (die_name, actual_name) != 0) | |
12369 | { | |
12370 | /* Strip off the class name from the full name. | |
12371 | We want the prefix. */ | |
12372 | int die_name_len = strlen (die_name); | |
12373 | int actual_name_len = strlen (actual_name); | |
12374 | ||
12375 | /* Test for '::' as a sanity check. */ | |
12376 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
12377 | && actual_name[actual_name_len |
12378 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
12379 | name = |
12380 | obsavestring (actual_name, | |
12381 | actual_name_len - die_name_len - 2, | |
12382 | &cu->objfile->objfile_obstack); | |
12383 | } | |
12384 | } | |
12385 | xfree (actual_name); | |
12386 | return name; | |
12387 | } | |
12388 | } | |
12389 | } | |
12390 | ||
12391 | return NULL; | |
12392 | } | |
12393 | ||
96408a79 SA |
12394 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
12395 | prefix part in such case. See | |
12396 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12397 | ||
12398 | static char * | |
12399 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
12400 | { | |
12401 | struct attribute *attr; | |
12402 | char *base; | |
12403 | ||
12404 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
12405 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
12406 | return NULL; | |
12407 | ||
12408 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
12409 | if (attr != NULL && DW_STRING (attr) != NULL) | |
12410 | return NULL; | |
12411 | ||
12412 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12413 | if (attr == NULL) | |
12414 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12415 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12416 | return NULL; | |
12417 | ||
12418 | /* dwarf2_name had to be already called. */ | |
12419 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
12420 | ||
12421 | /* Strip the base name, keep any leading namespaces/classes. */ | |
12422 | base = strrchr (DW_STRING (attr), ':'); | |
12423 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
12424 | return ""; | |
12425 | ||
12426 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
12427 | &cu->objfile->objfile_obstack); | |
12428 | } | |
12429 | ||
fdde2d81 | 12430 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 12431 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 12432 | |
0114d602 DJ |
12433 | For example, if we're within the method foo() in the following |
12434 | code: | |
12435 | ||
12436 | namespace N { | |
12437 | class C { | |
12438 | void foo () { | |
12439 | } | |
12440 | }; | |
12441 | } | |
12442 | ||
12443 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
12444 | |
12445 | static char * | |
e142c38c | 12446 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 12447 | { |
0114d602 DJ |
12448 | struct die_info *parent, *spec_die; |
12449 | struct dwarf2_cu *spec_cu; | |
12450 | struct type *parent_type; | |
96408a79 | 12451 | char *retval; |
63d06c5c | 12452 | |
f55ee35c JK |
12453 | if (cu->language != language_cplus && cu->language != language_java |
12454 | && cu->language != language_fortran) | |
0114d602 DJ |
12455 | return ""; |
12456 | ||
96408a79 SA |
12457 | retval = anonymous_struct_prefix (die, cu); |
12458 | if (retval) | |
12459 | return retval; | |
12460 | ||
0114d602 DJ |
12461 | /* We have to be careful in the presence of DW_AT_specification. |
12462 | For example, with GCC 3.4, given the code | |
12463 | ||
12464 | namespace N { | |
12465 | void foo() { | |
12466 | // Definition of N::foo. | |
12467 | } | |
12468 | } | |
12469 | ||
12470 | then we'll have a tree of DIEs like this: | |
12471 | ||
12472 | 1: DW_TAG_compile_unit | |
12473 | 2: DW_TAG_namespace // N | |
12474 | 3: DW_TAG_subprogram // declaration of N::foo | |
12475 | 4: DW_TAG_subprogram // definition of N::foo | |
12476 | DW_AT_specification // refers to die #3 | |
12477 | ||
12478 | Thus, when processing die #4, we have to pretend that we're in | |
12479 | the context of its DW_AT_specification, namely the contex of die | |
12480 | #3. */ | |
12481 | spec_cu = cu; | |
12482 | spec_die = die_specification (die, &spec_cu); | |
12483 | if (spec_die == NULL) | |
12484 | parent = die->parent; | |
12485 | else | |
63d06c5c | 12486 | { |
0114d602 DJ |
12487 | parent = spec_die->parent; |
12488 | cu = spec_cu; | |
63d06c5c | 12489 | } |
0114d602 DJ |
12490 | |
12491 | if (parent == NULL) | |
12492 | return ""; | |
98bfdba5 PA |
12493 | else if (parent->building_fullname) |
12494 | { | |
12495 | const char *name; | |
12496 | const char *parent_name; | |
12497 | ||
12498 | /* It has been seen on RealView 2.2 built binaries, | |
12499 | DW_TAG_template_type_param types actually _defined_ as | |
12500 | children of the parent class: | |
12501 | ||
12502 | enum E {}; | |
12503 | template class <class Enum> Class{}; | |
12504 | Class<enum E> class_e; | |
12505 | ||
12506 | 1: DW_TAG_class_type (Class) | |
12507 | 2: DW_TAG_enumeration_type (E) | |
12508 | 3: DW_TAG_enumerator (enum1:0) | |
12509 | 3: DW_TAG_enumerator (enum2:1) | |
12510 | ... | |
12511 | 2: DW_TAG_template_type_param | |
12512 | DW_AT_type DW_FORM_ref_udata (E) | |
12513 | ||
12514 | Besides being broken debug info, it can put GDB into an | |
12515 | infinite loop. Consider: | |
12516 | ||
12517 | When we're building the full name for Class<E>, we'll start | |
12518 | at Class, and go look over its template type parameters, | |
12519 | finding E. We'll then try to build the full name of E, and | |
12520 | reach here. We're now trying to build the full name of E, | |
12521 | and look over the parent DIE for containing scope. In the | |
12522 | broken case, if we followed the parent DIE of E, we'd again | |
12523 | find Class, and once again go look at its template type | |
12524 | arguments, etc., etc. Simply don't consider such parent die | |
12525 | as source-level parent of this die (it can't be, the language | |
12526 | doesn't allow it), and break the loop here. */ | |
12527 | name = dwarf2_name (die, cu); | |
12528 | parent_name = dwarf2_name (parent, cu); | |
12529 | complaint (&symfile_complaints, | |
12530 | _("template param type '%s' defined within parent '%s'"), | |
12531 | name ? name : "<unknown>", | |
12532 | parent_name ? parent_name : "<unknown>"); | |
12533 | return ""; | |
12534 | } | |
63d06c5c | 12535 | else |
0114d602 DJ |
12536 | switch (parent->tag) |
12537 | { | |
63d06c5c | 12538 | case DW_TAG_namespace: |
0114d602 | 12539 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12540 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12541 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12542 | Work around this problem here. */ | |
12543 | if (cu->language == language_cplus | |
12544 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12545 | return ""; | |
0114d602 DJ |
12546 | /* We give a name to even anonymous namespaces. */ |
12547 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12548 | case DW_TAG_class_type: |
680b30c7 | 12549 | case DW_TAG_interface_type: |
63d06c5c | 12550 | case DW_TAG_structure_type: |
0114d602 | 12551 | case DW_TAG_union_type: |
f55ee35c | 12552 | case DW_TAG_module: |
0114d602 DJ |
12553 | parent_type = read_type_die (parent, cu); |
12554 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12555 | return TYPE_TAG_NAME (parent_type); | |
12556 | else | |
12557 | /* An anonymous structure is only allowed non-static data | |
12558 | members; no typedefs, no member functions, et cetera. | |
12559 | So it does not need a prefix. */ | |
12560 | return ""; | |
abc72ce4 DE |
12561 | case DW_TAG_compile_unit: |
12562 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12563 | if (cu->language == language_cplus | |
8b70b953 | 12564 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
12565 | && die->child != NULL |
12566 | && (die->tag == DW_TAG_class_type | |
12567 | || die->tag == DW_TAG_structure_type | |
12568 | || die->tag == DW_TAG_union_type)) | |
12569 | { | |
12570 | char *name = guess_full_die_structure_name (die, cu); | |
12571 | if (name != NULL) | |
12572 | return name; | |
12573 | } | |
12574 | return ""; | |
63d06c5c | 12575 | default: |
8176b9b8 | 12576 | return determine_prefix (parent, cu); |
63d06c5c | 12577 | } |
63d06c5c DC |
12578 | } |
12579 | ||
3e43a32a MS |
12580 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12581 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12582 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12583 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12584 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12585 | |
f55ee35c | 12586 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12587 | |
12588 | static char * | |
f55ee35c JK |
12589 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12590 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12591 | { |
f55ee35c | 12592 | const char *lead = ""; |
5c315b68 | 12593 | const char *sep; |
63d06c5c | 12594 | |
3e43a32a MS |
12595 | if (suffix == NULL || suffix[0] == '\0' |
12596 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12597 | sep = ""; |
12598 | else if (cu->language == language_java) | |
12599 | sep = "."; | |
f55ee35c JK |
12600 | else if (cu->language == language_fortran && physname) |
12601 | { | |
12602 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12603 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12604 | ||
12605 | lead = "__"; | |
12606 | sep = "_MOD_"; | |
12607 | } | |
987504bb JJ |
12608 | else |
12609 | sep = "::"; | |
63d06c5c | 12610 | |
6dd47d34 DE |
12611 | if (prefix == NULL) |
12612 | prefix = ""; | |
12613 | if (suffix == NULL) | |
12614 | suffix = ""; | |
12615 | ||
987504bb JJ |
12616 | if (obs == NULL) |
12617 | { | |
3e43a32a MS |
12618 | char *retval |
12619 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12620 | |
f55ee35c JK |
12621 | strcpy (retval, lead); |
12622 | strcat (retval, prefix); | |
6dd47d34 DE |
12623 | strcat (retval, sep); |
12624 | strcat (retval, suffix); | |
63d06c5c DC |
12625 | return retval; |
12626 | } | |
987504bb JJ |
12627 | else |
12628 | { | |
12629 | /* We have an obstack. */ | |
f55ee35c | 12630 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12631 | } |
63d06c5c DC |
12632 | } |
12633 | ||
c906108c SS |
12634 | /* Return sibling of die, NULL if no sibling. */ |
12635 | ||
f9aca02d | 12636 | static struct die_info * |
fba45db2 | 12637 | sibling_die (struct die_info *die) |
c906108c | 12638 | { |
639d11d3 | 12639 | return die->sibling; |
c906108c SS |
12640 | } |
12641 | ||
71c25dea TT |
12642 | /* Get name of a die, return NULL if not found. */ |
12643 | ||
12644 | static char * | |
12645 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12646 | struct obstack *obstack) | |
12647 | { | |
12648 | if (name && cu->language == language_cplus) | |
12649 | { | |
12650 | char *canon_name = cp_canonicalize_string (name); | |
12651 | ||
12652 | if (canon_name != NULL) | |
12653 | { | |
12654 | if (strcmp (canon_name, name) != 0) | |
12655 | name = obsavestring (canon_name, strlen (canon_name), | |
12656 | obstack); | |
12657 | xfree (canon_name); | |
12658 | } | |
12659 | } | |
12660 | ||
12661 | return name; | |
c906108c SS |
12662 | } |
12663 | ||
9219021c DC |
12664 | /* Get name of a die, return NULL if not found. */ |
12665 | ||
12666 | static char * | |
e142c38c | 12667 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12668 | { |
12669 | struct attribute *attr; | |
12670 | ||
e142c38c | 12671 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12672 | if ((!attr || !DW_STRING (attr)) |
12673 | && die->tag != DW_TAG_class_type | |
12674 | && die->tag != DW_TAG_interface_type | |
12675 | && die->tag != DW_TAG_structure_type | |
12676 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12677 | return NULL; |
12678 | ||
12679 | switch (die->tag) | |
12680 | { | |
12681 | case DW_TAG_compile_unit: | |
12682 | /* Compilation units have a DW_AT_name that is a filename, not | |
12683 | a source language identifier. */ | |
12684 | case DW_TAG_enumeration_type: | |
12685 | case DW_TAG_enumerator: | |
12686 | /* These tags always have simple identifiers already; no need | |
12687 | to canonicalize them. */ | |
12688 | return DW_STRING (attr); | |
907af001 | 12689 | |
418835cc KS |
12690 | case DW_TAG_subprogram: |
12691 | /* Java constructors will all be named "<init>", so return | |
12692 | the class name when we see this special case. */ | |
12693 | if (cu->language == language_java | |
12694 | && DW_STRING (attr) != NULL | |
12695 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12696 | { | |
12697 | struct dwarf2_cu *spec_cu = cu; | |
12698 | struct die_info *spec_die; | |
12699 | ||
12700 | /* GCJ will output '<init>' for Java constructor names. | |
12701 | For this special case, return the name of the parent class. */ | |
12702 | ||
12703 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12704 | If so, use the name of the specified DIE. */ | |
12705 | spec_die = die_specification (die, &spec_cu); | |
12706 | if (spec_die != NULL) | |
12707 | return dwarf2_name (spec_die, spec_cu); | |
12708 | ||
12709 | do | |
12710 | { | |
12711 | die = die->parent; | |
12712 | if (die->tag == DW_TAG_class_type) | |
12713 | return dwarf2_name (die, cu); | |
12714 | } | |
12715 | while (die->tag != DW_TAG_compile_unit); | |
12716 | } | |
907af001 UW |
12717 | break; |
12718 | ||
12719 | case DW_TAG_class_type: | |
12720 | case DW_TAG_interface_type: | |
12721 | case DW_TAG_structure_type: | |
12722 | case DW_TAG_union_type: | |
12723 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12724 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12725 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12726 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12727 | if (attr && DW_STRING (attr) |
12728 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12729 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12730 | return NULL; |
53832f31 TT |
12731 | |
12732 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12733 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12734 | if (!attr || DW_STRING (attr) == NULL) | |
12735 | { | |
df5c6c50 | 12736 | char *demangled = NULL; |
53832f31 TT |
12737 | |
12738 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12739 | if (attr == NULL) | |
12740 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12741 | ||
12742 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12743 | return NULL; | |
12744 | ||
df5c6c50 JK |
12745 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12746 | call for the same DIE. */ | |
12747 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12748 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12749 | |
12750 | if (demangled) | |
12751 | { | |
96408a79 SA |
12752 | char *base; |
12753 | ||
53832f31 | 12754 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
12755 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
12756 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
12757 | DW_STRING_IS_CANONICAL (attr) = 1; |
12758 | xfree (demangled); | |
96408a79 SA |
12759 | |
12760 | /* Strip any leading namespaces/classes, keep only the base name. | |
12761 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
12762 | base = strrchr (DW_STRING (attr), ':'); | |
12763 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
12764 | return &base[1]; | |
12765 | else | |
12766 | return DW_STRING (attr); | |
53832f31 TT |
12767 | } |
12768 | } | |
907af001 UW |
12769 | break; |
12770 | ||
71c25dea | 12771 | default: |
907af001 UW |
12772 | break; |
12773 | } | |
12774 | ||
12775 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12776 | { | |
12777 | DW_STRING (attr) | |
12778 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12779 | &cu->objfile->objfile_obstack); | |
12780 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12781 | } |
907af001 | 12782 | return DW_STRING (attr); |
9219021c DC |
12783 | } |
12784 | ||
12785 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12786 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12787 | containing the return value on output. */ | |
9219021c DC |
12788 | |
12789 | static struct die_info * | |
f2f0e013 | 12790 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12791 | { |
12792 | struct attribute *attr; | |
9219021c | 12793 | |
f2f0e013 | 12794 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12795 | if (attr == NULL) |
12796 | return NULL; | |
12797 | ||
f2f0e013 | 12798 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12799 | } |
12800 | ||
c906108c SS |
12801 | /* Convert a DIE tag into its string name. */ |
12802 | ||
12803 | static char * | |
aa1ee363 | 12804 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12805 | { |
12806 | switch (tag) | |
12807 | { | |
12808 | case DW_TAG_padding: | |
12809 | return "DW_TAG_padding"; | |
12810 | case DW_TAG_array_type: | |
12811 | return "DW_TAG_array_type"; | |
12812 | case DW_TAG_class_type: | |
12813 | return "DW_TAG_class_type"; | |
12814 | case DW_TAG_entry_point: | |
12815 | return "DW_TAG_entry_point"; | |
12816 | case DW_TAG_enumeration_type: | |
12817 | return "DW_TAG_enumeration_type"; | |
12818 | case DW_TAG_formal_parameter: | |
12819 | return "DW_TAG_formal_parameter"; | |
12820 | case DW_TAG_imported_declaration: | |
12821 | return "DW_TAG_imported_declaration"; | |
12822 | case DW_TAG_label: | |
12823 | return "DW_TAG_label"; | |
12824 | case DW_TAG_lexical_block: | |
12825 | return "DW_TAG_lexical_block"; | |
12826 | case DW_TAG_member: | |
12827 | return "DW_TAG_member"; | |
12828 | case DW_TAG_pointer_type: | |
12829 | return "DW_TAG_pointer_type"; | |
12830 | case DW_TAG_reference_type: | |
12831 | return "DW_TAG_reference_type"; | |
12832 | case DW_TAG_compile_unit: | |
12833 | return "DW_TAG_compile_unit"; | |
12834 | case DW_TAG_string_type: | |
12835 | return "DW_TAG_string_type"; | |
12836 | case DW_TAG_structure_type: | |
12837 | return "DW_TAG_structure_type"; | |
12838 | case DW_TAG_subroutine_type: | |
12839 | return "DW_TAG_subroutine_type"; | |
12840 | case DW_TAG_typedef: | |
12841 | return "DW_TAG_typedef"; | |
12842 | case DW_TAG_union_type: | |
12843 | return "DW_TAG_union_type"; | |
12844 | case DW_TAG_unspecified_parameters: | |
12845 | return "DW_TAG_unspecified_parameters"; | |
12846 | case DW_TAG_variant: | |
12847 | return "DW_TAG_variant"; | |
12848 | case DW_TAG_common_block: | |
12849 | return "DW_TAG_common_block"; | |
12850 | case DW_TAG_common_inclusion: | |
12851 | return "DW_TAG_common_inclusion"; | |
12852 | case DW_TAG_inheritance: | |
12853 | return "DW_TAG_inheritance"; | |
12854 | case DW_TAG_inlined_subroutine: | |
12855 | return "DW_TAG_inlined_subroutine"; | |
12856 | case DW_TAG_module: | |
12857 | return "DW_TAG_module"; | |
12858 | case DW_TAG_ptr_to_member_type: | |
12859 | return "DW_TAG_ptr_to_member_type"; | |
12860 | case DW_TAG_set_type: | |
12861 | return "DW_TAG_set_type"; | |
12862 | case DW_TAG_subrange_type: | |
12863 | return "DW_TAG_subrange_type"; | |
12864 | case DW_TAG_with_stmt: | |
12865 | return "DW_TAG_with_stmt"; | |
12866 | case DW_TAG_access_declaration: | |
12867 | return "DW_TAG_access_declaration"; | |
12868 | case DW_TAG_base_type: | |
12869 | return "DW_TAG_base_type"; | |
12870 | case DW_TAG_catch_block: | |
12871 | return "DW_TAG_catch_block"; | |
12872 | case DW_TAG_const_type: | |
12873 | return "DW_TAG_const_type"; | |
12874 | case DW_TAG_constant: | |
12875 | return "DW_TAG_constant"; | |
12876 | case DW_TAG_enumerator: | |
12877 | return "DW_TAG_enumerator"; | |
12878 | case DW_TAG_file_type: | |
12879 | return "DW_TAG_file_type"; | |
12880 | case DW_TAG_friend: | |
12881 | return "DW_TAG_friend"; | |
12882 | case DW_TAG_namelist: | |
12883 | return "DW_TAG_namelist"; | |
12884 | case DW_TAG_namelist_item: | |
12885 | return "DW_TAG_namelist_item"; | |
12886 | case DW_TAG_packed_type: | |
12887 | return "DW_TAG_packed_type"; | |
12888 | case DW_TAG_subprogram: | |
12889 | return "DW_TAG_subprogram"; | |
12890 | case DW_TAG_template_type_param: | |
12891 | return "DW_TAG_template_type_param"; | |
12892 | case DW_TAG_template_value_param: | |
12893 | return "DW_TAG_template_value_param"; | |
12894 | case DW_TAG_thrown_type: | |
12895 | return "DW_TAG_thrown_type"; | |
12896 | case DW_TAG_try_block: | |
12897 | return "DW_TAG_try_block"; | |
12898 | case DW_TAG_variant_part: | |
12899 | return "DW_TAG_variant_part"; | |
12900 | case DW_TAG_variable: | |
12901 | return "DW_TAG_variable"; | |
12902 | case DW_TAG_volatile_type: | |
12903 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12904 | case DW_TAG_dwarf_procedure: |
12905 | return "DW_TAG_dwarf_procedure"; | |
12906 | case DW_TAG_restrict_type: | |
12907 | return "DW_TAG_restrict_type"; | |
12908 | case DW_TAG_interface_type: | |
12909 | return "DW_TAG_interface_type"; | |
12910 | case DW_TAG_namespace: | |
12911 | return "DW_TAG_namespace"; | |
12912 | case DW_TAG_imported_module: | |
12913 | return "DW_TAG_imported_module"; | |
12914 | case DW_TAG_unspecified_type: | |
12915 | return "DW_TAG_unspecified_type"; | |
12916 | case DW_TAG_partial_unit: | |
12917 | return "DW_TAG_partial_unit"; | |
12918 | case DW_TAG_imported_unit: | |
12919 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12920 | case DW_TAG_condition: |
12921 | return "DW_TAG_condition"; | |
12922 | case DW_TAG_shared_type: | |
12923 | return "DW_TAG_shared_type"; | |
348e048f DE |
12924 | case DW_TAG_type_unit: |
12925 | return "DW_TAG_type_unit"; | |
c906108c SS |
12926 | case DW_TAG_MIPS_loop: |
12927 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12928 | case DW_TAG_HP_array_descriptor: |
12929 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12930 | case DW_TAG_format_label: |
12931 | return "DW_TAG_format_label"; | |
12932 | case DW_TAG_function_template: | |
12933 | return "DW_TAG_function_template"; | |
12934 | case DW_TAG_class_template: | |
12935 | return "DW_TAG_class_template"; | |
b7619582 GF |
12936 | case DW_TAG_GNU_BINCL: |
12937 | return "DW_TAG_GNU_BINCL"; | |
12938 | case DW_TAG_GNU_EINCL: | |
12939 | return "DW_TAG_GNU_EINCL"; | |
12940 | case DW_TAG_upc_shared_type: | |
12941 | return "DW_TAG_upc_shared_type"; | |
12942 | case DW_TAG_upc_strict_type: | |
12943 | return "DW_TAG_upc_strict_type"; | |
12944 | case DW_TAG_upc_relaxed_type: | |
12945 | return "DW_TAG_upc_relaxed_type"; | |
12946 | case DW_TAG_PGI_kanji_type: | |
12947 | return "DW_TAG_PGI_kanji_type"; | |
12948 | case DW_TAG_PGI_interface_block: | |
12949 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
12950 | case DW_TAG_GNU_call_site: |
12951 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
12952 | default: |
12953 | return "DW_TAG_<unknown>"; | |
12954 | } | |
12955 | } | |
12956 | ||
12957 | /* Convert a DWARF attribute code into its string name. */ | |
12958 | ||
12959 | static char * | |
aa1ee363 | 12960 | dwarf_attr_name (unsigned attr) |
c906108c SS |
12961 | { |
12962 | switch (attr) | |
12963 | { | |
12964 | case DW_AT_sibling: | |
12965 | return "DW_AT_sibling"; | |
12966 | case DW_AT_location: | |
12967 | return "DW_AT_location"; | |
12968 | case DW_AT_name: | |
12969 | return "DW_AT_name"; | |
12970 | case DW_AT_ordering: | |
12971 | return "DW_AT_ordering"; | |
12972 | case DW_AT_subscr_data: | |
12973 | return "DW_AT_subscr_data"; | |
12974 | case DW_AT_byte_size: | |
12975 | return "DW_AT_byte_size"; | |
12976 | case DW_AT_bit_offset: | |
12977 | return "DW_AT_bit_offset"; | |
12978 | case DW_AT_bit_size: | |
12979 | return "DW_AT_bit_size"; | |
12980 | case DW_AT_element_list: | |
12981 | return "DW_AT_element_list"; | |
12982 | case DW_AT_stmt_list: | |
12983 | return "DW_AT_stmt_list"; | |
12984 | case DW_AT_low_pc: | |
12985 | return "DW_AT_low_pc"; | |
12986 | case DW_AT_high_pc: | |
12987 | return "DW_AT_high_pc"; | |
12988 | case DW_AT_language: | |
12989 | return "DW_AT_language"; | |
12990 | case DW_AT_member: | |
12991 | return "DW_AT_member"; | |
12992 | case DW_AT_discr: | |
12993 | return "DW_AT_discr"; | |
12994 | case DW_AT_discr_value: | |
12995 | return "DW_AT_discr_value"; | |
12996 | case DW_AT_visibility: | |
12997 | return "DW_AT_visibility"; | |
12998 | case DW_AT_import: | |
12999 | return "DW_AT_import"; | |
13000 | case DW_AT_string_length: | |
13001 | return "DW_AT_string_length"; | |
13002 | case DW_AT_common_reference: | |
13003 | return "DW_AT_common_reference"; | |
13004 | case DW_AT_comp_dir: | |
13005 | return "DW_AT_comp_dir"; | |
13006 | case DW_AT_const_value: | |
13007 | return "DW_AT_const_value"; | |
13008 | case DW_AT_containing_type: | |
13009 | return "DW_AT_containing_type"; | |
13010 | case DW_AT_default_value: | |
13011 | return "DW_AT_default_value"; | |
13012 | case DW_AT_inline: | |
13013 | return "DW_AT_inline"; | |
13014 | case DW_AT_is_optional: | |
13015 | return "DW_AT_is_optional"; | |
13016 | case DW_AT_lower_bound: | |
13017 | return "DW_AT_lower_bound"; | |
13018 | case DW_AT_producer: | |
13019 | return "DW_AT_producer"; | |
13020 | case DW_AT_prototyped: | |
13021 | return "DW_AT_prototyped"; | |
13022 | case DW_AT_return_addr: | |
13023 | return "DW_AT_return_addr"; | |
13024 | case DW_AT_start_scope: | |
13025 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
13026 | case DW_AT_bit_stride: |
13027 | return "DW_AT_bit_stride"; | |
c906108c SS |
13028 | case DW_AT_upper_bound: |
13029 | return "DW_AT_upper_bound"; | |
13030 | case DW_AT_abstract_origin: | |
13031 | return "DW_AT_abstract_origin"; | |
13032 | case DW_AT_accessibility: | |
13033 | return "DW_AT_accessibility"; | |
13034 | case DW_AT_address_class: | |
13035 | return "DW_AT_address_class"; | |
13036 | case DW_AT_artificial: | |
13037 | return "DW_AT_artificial"; | |
13038 | case DW_AT_base_types: | |
13039 | return "DW_AT_base_types"; | |
13040 | case DW_AT_calling_convention: | |
13041 | return "DW_AT_calling_convention"; | |
13042 | case DW_AT_count: | |
13043 | return "DW_AT_count"; | |
13044 | case DW_AT_data_member_location: | |
13045 | return "DW_AT_data_member_location"; | |
13046 | case DW_AT_decl_column: | |
13047 | return "DW_AT_decl_column"; | |
13048 | case DW_AT_decl_file: | |
13049 | return "DW_AT_decl_file"; | |
13050 | case DW_AT_decl_line: | |
13051 | return "DW_AT_decl_line"; | |
13052 | case DW_AT_declaration: | |
13053 | return "DW_AT_declaration"; | |
13054 | case DW_AT_discr_list: | |
13055 | return "DW_AT_discr_list"; | |
13056 | case DW_AT_encoding: | |
13057 | return "DW_AT_encoding"; | |
13058 | case DW_AT_external: | |
13059 | return "DW_AT_external"; | |
13060 | case DW_AT_frame_base: | |
13061 | return "DW_AT_frame_base"; | |
13062 | case DW_AT_friend: | |
13063 | return "DW_AT_friend"; | |
13064 | case DW_AT_identifier_case: | |
13065 | return "DW_AT_identifier_case"; | |
13066 | case DW_AT_macro_info: | |
13067 | return "DW_AT_macro_info"; | |
13068 | case DW_AT_namelist_items: | |
13069 | return "DW_AT_namelist_items"; | |
13070 | case DW_AT_priority: | |
13071 | return "DW_AT_priority"; | |
13072 | case DW_AT_segment: | |
13073 | return "DW_AT_segment"; | |
13074 | case DW_AT_specification: | |
13075 | return "DW_AT_specification"; | |
13076 | case DW_AT_static_link: | |
13077 | return "DW_AT_static_link"; | |
13078 | case DW_AT_type: | |
13079 | return "DW_AT_type"; | |
13080 | case DW_AT_use_location: | |
13081 | return "DW_AT_use_location"; | |
13082 | case DW_AT_variable_parameter: | |
13083 | return "DW_AT_variable_parameter"; | |
13084 | case DW_AT_virtuality: | |
13085 | return "DW_AT_virtuality"; | |
13086 | case DW_AT_vtable_elem_location: | |
13087 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 13088 | /* DWARF 3 values. */ |
d9fa45fe DC |
13089 | case DW_AT_allocated: |
13090 | return "DW_AT_allocated"; | |
13091 | case DW_AT_associated: | |
13092 | return "DW_AT_associated"; | |
13093 | case DW_AT_data_location: | |
13094 | return "DW_AT_data_location"; | |
09fa0d7c JK |
13095 | case DW_AT_byte_stride: |
13096 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
13097 | case DW_AT_entry_pc: |
13098 | return "DW_AT_entry_pc"; | |
13099 | case DW_AT_use_UTF8: | |
13100 | return "DW_AT_use_UTF8"; | |
13101 | case DW_AT_extension: | |
13102 | return "DW_AT_extension"; | |
13103 | case DW_AT_ranges: | |
13104 | return "DW_AT_ranges"; | |
13105 | case DW_AT_trampoline: | |
13106 | return "DW_AT_trampoline"; | |
13107 | case DW_AT_call_column: | |
13108 | return "DW_AT_call_column"; | |
13109 | case DW_AT_call_file: | |
13110 | return "DW_AT_call_file"; | |
13111 | case DW_AT_call_line: | |
13112 | return "DW_AT_call_line"; | |
b7619582 GF |
13113 | case DW_AT_description: |
13114 | return "DW_AT_description"; | |
13115 | case DW_AT_binary_scale: | |
13116 | return "DW_AT_binary_scale"; | |
13117 | case DW_AT_decimal_scale: | |
13118 | return "DW_AT_decimal_scale"; | |
13119 | case DW_AT_small: | |
13120 | return "DW_AT_small"; | |
13121 | case DW_AT_decimal_sign: | |
13122 | return "DW_AT_decimal_sign"; | |
13123 | case DW_AT_digit_count: | |
13124 | return "DW_AT_digit_count"; | |
13125 | case DW_AT_picture_string: | |
13126 | return "DW_AT_picture_string"; | |
13127 | case DW_AT_mutable: | |
13128 | return "DW_AT_mutable"; | |
13129 | case DW_AT_threads_scaled: | |
13130 | return "DW_AT_threads_scaled"; | |
13131 | case DW_AT_explicit: | |
13132 | return "DW_AT_explicit"; | |
13133 | case DW_AT_object_pointer: | |
13134 | return "DW_AT_object_pointer"; | |
13135 | case DW_AT_endianity: | |
13136 | return "DW_AT_endianity"; | |
13137 | case DW_AT_elemental: | |
13138 | return "DW_AT_elemental"; | |
13139 | case DW_AT_pure: | |
13140 | return "DW_AT_pure"; | |
13141 | case DW_AT_recursive: | |
13142 | return "DW_AT_recursive"; | |
348e048f DE |
13143 | /* DWARF 4 values. */ |
13144 | case DW_AT_signature: | |
13145 | return "DW_AT_signature"; | |
31ef98ae TT |
13146 | case DW_AT_linkage_name: |
13147 | return "DW_AT_linkage_name"; | |
b7619582 | 13148 | /* SGI/MIPS extensions. */ |
c764a876 | 13149 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
13150 | case DW_AT_MIPS_fde: |
13151 | return "DW_AT_MIPS_fde"; | |
c764a876 | 13152 | #endif |
c906108c SS |
13153 | case DW_AT_MIPS_loop_begin: |
13154 | return "DW_AT_MIPS_loop_begin"; | |
13155 | case DW_AT_MIPS_tail_loop_begin: | |
13156 | return "DW_AT_MIPS_tail_loop_begin"; | |
13157 | case DW_AT_MIPS_epilog_begin: | |
13158 | return "DW_AT_MIPS_epilog_begin"; | |
13159 | case DW_AT_MIPS_loop_unroll_factor: | |
13160 | return "DW_AT_MIPS_loop_unroll_factor"; | |
13161 | case DW_AT_MIPS_software_pipeline_depth: | |
13162 | return "DW_AT_MIPS_software_pipeline_depth"; | |
13163 | case DW_AT_MIPS_linkage_name: | |
13164 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
13165 | case DW_AT_MIPS_stride: |
13166 | return "DW_AT_MIPS_stride"; | |
13167 | case DW_AT_MIPS_abstract_name: | |
13168 | return "DW_AT_MIPS_abstract_name"; | |
13169 | case DW_AT_MIPS_clone_origin: | |
13170 | return "DW_AT_MIPS_clone_origin"; | |
13171 | case DW_AT_MIPS_has_inlines: | |
13172 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 13173 | /* HP extensions. */ |
c764a876 | 13174 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
13175 | case DW_AT_HP_block_index: |
13176 | return "DW_AT_HP_block_index"; | |
c764a876 | 13177 | #endif |
b7619582 GF |
13178 | case DW_AT_HP_unmodifiable: |
13179 | return "DW_AT_HP_unmodifiable"; | |
13180 | case DW_AT_HP_actuals_stmt_list: | |
13181 | return "DW_AT_HP_actuals_stmt_list"; | |
13182 | case DW_AT_HP_proc_per_section: | |
13183 | return "DW_AT_HP_proc_per_section"; | |
13184 | case DW_AT_HP_raw_data_ptr: | |
13185 | return "DW_AT_HP_raw_data_ptr"; | |
13186 | case DW_AT_HP_pass_by_reference: | |
13187 | return "DW_AT_HP_pass_by_reference"; | |
13188 | case DW_AT_HP_opt_level: | |
13189 | return "DW_AT_HP_opt_level"; | |
13190 | case DW_AT_HP_prof_version_id: | |
13191 | return "DW_AT_HP_prof_version_id"; | |
13192 | case DW_AT_HP_opt_flags: | |
13193 | return "DW_AT_HP_opt_flags"; | |
13194 | case DW_AT_HP_cold_region_low_pc: | |
13195 | return "DW_AT_HP_cold_region_low_pc"; | |
13196 | case DW_AT_HP_cold_region_high_pc: | |
13197 | return "DW_AT_HP_cold_region_high_pc"; | |
13198 | case DW_AT_HP_all_variables_modifiable: | |
13199 | return "DW_AT_HP_all_variables_modifiable"; | |
13200 | case DW_AT_HP_linkage_name: | |
13201 | return "DW_AT_HP_linkage_name"; | |
13202 | case DW_AT_HP_prof_flags: | |
13203 | return "DW_AT_HP_prof_flags"; | |
13204 | /* GNU extensions. */ | |
c906108c SS |
13205 | case DW_AT_sf_names: |
13206 | return "DW_AT_sf_names"; | |
13207 | case DW_AT_src_info: | |
13208 | return "DW_AT_src_info"; | |
13209 | case DW_AT_mac_info: | |
13210 | return "DW_AT_mac_info"; | |
13211 | case DW_AT_src_coords: | |
13212 | return "DW_AT_src_coords"; | |
13213 | case DW_AT_body_begin: | |
13214 | return "DW_AT_body_begin"; | |
13215 | case DW_AT_body_end: | |
13216 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
13217 | case DW_AT_GNU_vector: |
13218 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
13219 | case DW_AT_GNU_odr_signature: |
13220 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
13221 | /* VMS extensions. */ |
13222 | case DW_AT_VMS_rtnbeg_pd_address: | |
13223 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
13224 | /* UPC extension. */ | |
13225 | case DW_AT_upc_threads_scaled: | |
13226 | return "DW_AT_upc_threads_scaled"; | |
13227 | /* PGI (STMicroelectronics) extensions. */ | |
13228 | case DW_AT_PGI_lbase: | |
13229 | return "DW_AT_PGI_lbase"; | |
13230 | case DW_AT_PGI_soffset: | |
13231 | return "DW_AT_PGI_soffset"; | |
13232 | case DW_AT_PGI_lstride: | |
13233 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
13234 | default: |
13235 | return "DW_AT_<unknown>"; | |
13236 | } | |
13237 | } | |
13238 | ||
13239 | /* Convert a DWARF value form code into its string name. */ | |
13240 | ||
13241 | static char * | |
aa1ee363 | 13242 | dwarf_form_name (unsigned form) |
c906108c SS |
13243 | { |
13244 | switch (form) | |
13245 | { | |
13246 | case DW_FORM_addr: | |
13247 | return "DW_FORM_addr"; | |
13248 | case DW_FORM_block2: | |
13249 | return "DW_FORM_block2"; | |
13250 | case DW_FORM_block4: | |
13251 | return "DW_FORM_block4"; | |
13252 | case DW_FORM_data2: | |
13253 | return "DW_FORM_data2"; | |
13254 | case DW_FORM_data4: | |
13255 | return "DW_FORM_data4"; | |
13256 | case DW_FORM_data8: | |
13257 | return "DW_FORM_data8"; | |
13258 | case DW_FORM_string: | |
13259 | return "DW_FORM_string"; | |
13260 | case DW_FORM_block: | |
13261 | return "DW_FORM_block"; | |
13262 | case DW_FORM_block1: | |
13263 | return "DW_FORM_block1"; | |
13264 | case DW_FORM_data1: | |
13265 | return "DW_FORM_data1"; | |
13266 | case DW_FORM_flag: | |
13267 | return "DW_FORM_flag"; | |
13268 | case DW_FORM_sdata: | |
13269 | return "DW_FORM_sdata"; | |
13270 | case DW_FORM_strp: | |
13271 | return "DW_FORM_strp"; | |
13272 | case DW_FORM_udata: | |
13273 | return "DW_FORM_udata"; | |
13274 | case DW_FORM_ref_addr: | |
13275 | return "DW_FORM_ref_addr"; | |
13276 | case DW_FORM_ref1: | |
13277 | return "DW_FORM_ref1"; | |
13278 | case DW_FORM_ref2: | |
13279 | return "DW_FORM_ref2"; | |
13280 | case DW_FORM_ref4: | |
13281 | return "DW_FORM_ref4"; | |
13282 | case DW_FORM_ref8: | |
13283 | return "DW_FORM_ref8"; | |
13284 | case DW_FORM_ref_udata: | |
13285 | return "DW_FORM_ref_udata"; | |
13286 | case DW_FORM_indirect: | |
13287 | return "DW_FORM_indirect"; | |
348e048f DE |
13288 | case DW_FORM_sec_offset: |
13289 | return "DW_FORM_sec_offset"; | |
13290 | case DW_FORM_exprloc: | |
13291 | return "DW_FORM_exprloc"; | |
13292 | case DW_FORM_flag_present: | |
13293 | return "DW_FORM_flag_present"; | |
55f1336d TT |
13294 | case DW_FORM_ref_sig8: |
13295 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
13296 | default: |
13297 | return "DW_FORM_<unknown>"; | |
13298 | } | |
13299 | } | |
13300 | ||
13301 | /* Convert a DWARF stack opcode into its string name. */ | |
13302 | ||
9eae7c52 | 13303 | const char * |
b1bfef65 | 13304 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
13305 | { |
13306 | switch (op) | |
13307 | { | |
13308 | case DW_OP_addr: | |
13309 | return "DW_OP_addr"; | |
13310 | case DW_OP_deref: | |
13311 | return "DW_OP_deref"; | |
13312 | case DW_OP_const1u: | |
13313 | return "DW_OP_const1u"; | |
13314 | case DW_OP_const1s: | |
13315 | return "DW_OP_const1s"; | |
13316 | case DW_OP_const2u: | |
13317 | return "DW_OP_const2u"; | |
13318 | case DW_OP_const2s: | |
13319 | return "DW_OP_const2s"; | |
13320 | case DW_OP_const4u: | |
13321 | return "DW_OP_const4u"; | |
13322 | case DW_OP_const4s: | |
13323 | return "DW_OP_const4s"; | |
13324 | case DW_OP_const8u: | |
13325 | return "DW_OP_const8u"; | |
13326 | case DW_OP_const8s: | |
13327 | return "DW_OP_const8s"; | |
13328 | case DW_OP_constu: | |
13329 | return "DW_OP_constu"; | |
13330 | case DW_OP_consts: | |
13331 | return "DW_OP_consts"; | |
13332 | case DW_OP_dup: | |
13333 | return "DW_OP_dup"; | |
13334 | case DW_OP_drop: | |
13335 | return "DW_OP_drop"; | |
13336 | case DW_OP_over: | |
13337 | return "DW_OP_over"; | |
13338 | case DW_OP_pick: | |
13339 | return "DW_OP_pick"; | |
13340 | case DW_OP_swap: | |
13341 | return "DW_OP_swap"; | |
13342 | case DW_OP_rot: | |
13343 | return "DW_OP_rot"; | |
13344 | case DW_OP_xderef: | |
13345 | return "DW_OP_xderef"; | |
13346 | case DW_OP_abs: | |
13347 | return "DW_OP_abs"; | |
13348 | case DW_OP_and: | |
13349 | return "DW_OP_and"; | |
13350 | case DW_OP_div: | |
13351 | return "DW_OP_div"; | |
13352 | case DW_OP_minus: | |
13353 | return "DW_OP_minus"; | |
13354 | case DW_OP_mod: | |
13355 | return "DW_OP_mod"; | |
13356 | case DW_OP_mul: | |
13357 | return "DW_OP_mul"; | |
13358 | case DW_OP_neg: | |
13359 | return "DW_OP_neg"; | |
13360 | case DW_OP_not: | |
13361 | return "DW_OP_not"; | |
13362 | case DW_OP_or: | |
13363 | return "DW_OP_or"; | |
13364 | case DW_OP_plus: | |
13365 | return "DW_OP_plus"; | |
13366 | case DW_OP_plus_uconst: | |
13367 | return "DW_OP_plus_uconst"; | |
13368 | case DW_OP_shl: | |
13369 | return "DW_OP_shl"; | |
13370 | case DW_OP_shr: | |
13371 | return "DW_OP_shr"; | |
13372 | case DW_OP_shra: | |
13373 | return "DW_OP_shra"; | |
13374 | case DW_OP_xor: | |
13375 | return "DW_OP_xor"; | |
13376 | case DW_OP_bra: | |
13377 | return "DW_OP_bra"; | |
13378 | case DW_OP_eq: | |
13379 | return "DW_OP_eq"; | |
13380 | case DW_OP_ge: | |
13381 | return "DW_OP_ge"; | |
13382 | case DW_OP_gt: | |
13383 | return "DW_OP_gt"; | |
13384 | case DW_OP_le: | |
13385 | return "DW_OP_le"; | |
13386 | case DW_OP_lt: | |
13387 | return "DW_OP_lt"; | |
13388 | case DW_OP_ne: | |
13389 | return "DW_OP_ne"; | |
13390 | case DW_OP_skip: | |
13391 | return "DW_OP_skip"; | |
13392 | case DW_OP_lit0: | |
13393 | return "DW_OP_lit0"; | |
13394 | case DW_OP_lit1: | |
13395 | return "DW_OP_lit1"; | |
13396 | case DW_OP_lit2: | |
13397 | return "DW_OP_lit2"; | |
13398 | case DW_OP_lit3: | |
13399 | return "DW_OP_lit3"; | |
13400 | case DW_OP_lit4: | |
13401 | return "DW_OP_lit4"; | |
13402 | case DW_OP_lit5: | |
13403 | return "DW_OP_lit5"; | |
13404 | case DW_OP_lit6: | |
13405 | return "DW_OP_lit6"; | |
13406 | case DW_OP_lit7: | |
13407 | return "DW_OP_lit7"; | |
13408 | case DW_OP_lit8: | |
13409 | return "DW_OP_lit8"; | |
13410 | case DW_OP_lit9: | |
13411 | return "DW_OP_lit9"; | |
13412 | case DW_OP_lit10: | |
13413 | return "DW_OP_lit10"; | |
13414 | case DW_OP_lit11: | |
13415 | return "DW_OP_lit11"; | |
13416 | case DW_OP_lit12: | |
13417 | return "DW_OP_lit12"; | |
13418 | case DW_OP_lit13: | |
13419 | return "DW_OP_lit13"; | |
13420 | case DW_OP_lit14: | |
13421 | return "DW_OP_lit14"; | |
13422 | case DW_OP_lit15: | |
13423 | return "DW_OP_lit15"; | |
13424 | case DW_OP_lit16: | |
13425 | return "DW_OP_lit16"; | |
13426 | case DW_OP_lit17: | |
13427 | return "DW_OP_lit17"; | |
13428 | case DW_OP_lit18: | |
13429 | return "DW_OP_lit18"; | |
13430 | case DW_OP_lit19: | |
13431 | return "DW_OP_lit19"; | |
13432 | case DW_OP_lit20: | |
13433 | return "DW_OP_lit20"; | |
13434 | case DW_OP_lit21: | |
13435 | return "DW_OP_lit21"; | |
13436 | case DW_OP_lit22: | |
13437 | return "DW_OP_lit22"; | |
13438 | case DW_OP_lit23: | |
13439 | return "DW_OP_lit23"; | |
13440 | case DW_OP_lit24: | |
13441 | return "DW_OP_lit24"; | |
13442 | case DW_OP_lit25: | |
13443 | return "DW_OP_lit25"; | |
13444 | case DW_OP_lit26: | |
13445 | return "DW_OP_lit26"; | |
13446 | case DW_OP_lit27: | |
13447 | return "DW_OP_lit27"; | |
13448 | case DW_OP_lit28: | |
13449 | return "DW_OP_lit28"; | |
13450 | case DW_OP_lit29: | |
13451 | return "DW_OP_lit29"; | |
13452 | case DW_OP_lit30: | |
13453 | return "DW_OP_lit30"; | |
13454 | case DW_OP_lit31: | |
13455 | return "DW_OP_lit31"; | |
13456 | case DW_OP_reg0: | |
13457 | return "DW_OP_reg0"; | |
13458 | case DW_OP_reg1: | |
13459 | return "DW_OP_reg1"; | |
13460 | case DW_OP_reg2: | |
13461 | return "DW_OP_reg2"; | |
13462 | case DW_OP_reg3: | |
13463 | return "DW_OP_reg3"; | |
13464 | case DW_OP_reg4: | |
13465 | return "DW_OP_reg4"; | |
13466 | case DW_OP_reg5: | |
13467 | return "DW_OP_reg5"; | |
13468 | case DW_OP_reg6: | |
13469 | return "DW_OP_reg6"; | |
13470 | case DW_OP_reg7: | |
13471 | return "DW_OP_reg7"; | |
13472 | case DW_OP_reg8: | |
13473 | return "DW_OP_reg8"; | |
13474 | case DW_OP_reg9: | |
13475 | return "DW_OP_reg9"; | |
13476 | case DW_OP_reg10: | |
13477 | return "DW_OP_reg10"; | |
13478 | case DW_OP_reg11: | |
13479 | return "DW_OP_reg11"; | |
13480 | case DW_OP_reg12: | |
13481 | return "DW_OP_reg12"; | |
13482 | case DW_OP_reg13: | |
13483 | return "DW_OP_reg13"; | |
13484 | case DW_OP_reg14: | |
13485 | return "DW_OP_reg14"; | |
13486 | case DW_OP_reg15: | |
13487 | return "DW_OP_reg15"; | |
13488 | case DW_OP_reg16: | |
13489 | return "DW_OP_reg16"; | |
13490 | case DW_OP_reg17: | |
13491 | return "DW_OP_reg17"; | |
13492 | case DW_OP_reg18: | |
13493 | return "DW_OP_reg18"; | |
13494 | case DW_OP_reg19: | |
13495 | return "DW_OP_reg19"; | |
13496 | case DW_OP_reg20: | |
13497 | return "DW_OP_reg20"; | |
13498 | case DW_OP_reg21: | |
13499 | return "DW_OP_reg21"; | |
13500 | case DW_OP_reg22: | |
13501 | return "DW_OP_reg22"; | |
13502 | case DW_OP_reg23: | |
13503 | return "DW_OP_reg23"; | |
13504 | case DW_OP_reg24: | |
13505 | return "DW_OP_reg24"; | |
13506 | case DW_OP_reg25: | |
13507 | return "DW_OP_reg25"; | |
13508 | case DW_OP_reg26: | |
13509 | return "DW_OP_reg26"; | |
13510 | case DW_OP_reg27: | |
13511 | return "DW_OP_reg27"; | |
13512 | case DW_OP_reg28: | |
13513 | return "DW_OP_reg28"; | |
13514 | case DW_OP_reg29: | |
13515 | return "DW_OP_reg29"; | |
13516 | case DW_OP_reg30: | |
13517 | return "DW_OP_reg30"; | |
13518 | case DW_OP_reg31: | |
13519 | return "DW_OP_reg31"; | |
13520 | case DW_OP_breg0: | |
13521 | return "DW_OP_breg0"; | |
13522 | case DW_OP_breg1: | |
13523 | return "DW_OP_breg1"; | |
13524 | case DW_OP_breg2: | |
13525 | return "DW_OP_breg2"; | |
13526 | case DW_OP_breg3: | |
13527 | return "DW_OP_breg3"; | |
13528 | case DW_OP_breg4: | |
13529 | return "DW_OP_breg4"; | |
13530 | case DW_OP_breg5: | |
13531 | return "DW_OP_breg5"; | |
13532 | case DW_OP_breg6: | |
13533 | return "DW_OP_breg6"; | |
13534 | case DW_OP_breg7: | |
13535 | return "DW_OP_breg7"; | |
13536 | case DW_OP_breg8: | |
13537 | return "DW_OP_breg8"; | |
13538 | case DW_OP_breg9: | |
13539 | return "DW_OP_breg9"; | |
13540 | case DW_OP_breg10: | |
13541 | return "DW_OP_breg10"; | |
13542 | case DW_OP_breg11: | |
13543 | return "DW_OP_breg11"; | |
13544 | case DW_OP_breg12: | |
13545 | return "DW_OP_breg12"; | |
13546 | case DW_OP_breg13: | |
13547 | return "DW_OP_breg13"; | |
13548 | case DW_OP_breg14: | |
13549 | return "DW_OP_breg14"; | |
13550 | case DW_OP_breg15: | |
13551 | return "DW_OP_breg15"; | |
13552 | case DW_OP_breg16: | |
13553 | return "DW_OP_breg16"; | |
13554 | case DW_OP_breg17: | |
13555 | return "DW_OP_breg17"; | |
13556 | case DW_OP_breg18: | |
13557 | return "DW_OP_breg18"; | |
13558 | case DW_OP_breg19: | |
13559 | return "DW_OP_breg19"; | |
13560 | case DW_OP_breg20: | |
13561 | return "DW_OP_breg20"; | |
13562 | case DW_OP_breg21: | |
13563 | return "DW_OP_breg21"; | |
13564 | case DW_OP_breg22: | |
13565 | return "DW_OP_breg22"; | |
13566 | case DW_OP_breg23: | |
13567 | return "DW_OP_breg23"; | |
13568 | case DW_OP_breg24: | |
13569 | return "DW_OP_breg24"; | |
13570 | case DW_OP_breg25: | |
13571 | return "DW_OP_breg25"; | |
13572 | case DW_OP_breg26: | |
13573 | return "DW_OP_breg26"; | |
13574 | case DW_OP_breg27: | |
13575 | return "DW_OP_breg27"; | |
13576 | case DW_OP_breg28: | |
13577 | return "DW_OP_breg28"; | |
13578 | case DW_OP_breg29: | |
13579 | return "DW_OP_breg29"; | |
13580 | case DW_OP_breg30: | |
13581 | return "DW_OP_breg30"; | |
13582 | case DW_OP_breg31: | |
13583 | return "DW_OP_breg31"; | |
13584 | case DW_OP_regx: | |
13585 | return "DW_OP_regx"; | |
13586 | case DW_OP_fbreg: | |
13587 | return "DW_OP_fbreg"; | |
13588 | case DW_OP_bregx: | |
13589 | return "DW_OP_bregx"; | |
13590 | case DW_OP_piece: | |
13591 | return "DW_OP_piece"; | |
13592 | case DW_OP_deref_size: | |
13593 | return "DW_OP_deref_size"; | |
13594 | case DW_OP_xderef_size: | |
13595 | return "DW_OP_xderef_size"; | |
13596 | case DW_OP_nop: | |
13597 | return "DW_OP_nop"; | |
b7619582 | 13598 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13599 | case DW_OP_push_object_address: |
13600 | return "DW_OP_push_object_address"; | |
13601 | case DW_OP_call2: | |
13602 | return "DW_OP_call2"; | |
13603 | case DW_OP_call4: | |
13604 | return "DW_OP_call4"; | |
13605 | case DW_OP_call_ref: | |
13606 | return "DW_OP_call_ref"; | |
b7619582 GF |
13607 | case DW_OP_form_tls_address: |
13608 | return "DW_OP_form_tls_address"; | |
13609 | case DW_OP_call_frame_cfa: | |
13610 | return "DW_OP_call_frame_cfa"; | |
13611 | case DW_OP_bit_piece: | |
13612 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13613 | /* DWARF 4 extensions. */ |
13614 | case DW_OP_implicit_value: | |
13615 | return "DW_OP_implicit_value"; | |
13616 | case DW_OP_stack_value: | |
13617 | return "DW_OP_stack_value"; | |
13618 | /* GNU extensions. */ | |
ed348acc EZ |
13619 | case DW_OP_GNU_push_tls_address: |
13620 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13621 | case DW_OP_GNU_uninit: |
13622 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
13623 | case DW_OP_GNU_implicit_pointer: |
13624 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13625 | case DW_OP_GNU_entry_value: |
13626 | return "DW_OP_GNU_entry_value"; | |
13627 | case DW_OP_GNU_const_type: | |
13628 | return "DW_OP_GNU_const_type"; | |
13629 | case DW_OP_GNU_regval_type: | |
13630 | return "DW_OP_GNU_regval_type"; | |
13631 | case DW_OP_GNU_deref_type: | |
13632 | return "DW_OP_GNU_deref_type"; | |
13633 | case DW_OP_GNU_convert: | |
13634 | return "DW_OP_GNU_convert"; | |
13635 | case DW_OP_GNU_reinterpret: | |
13636 | return "DW_OP_GNU_reinterpret"; | |
c906108c | 13637 | default: |
b1bfef65 | 13638 | return NULL; |
c906108c SS |
13639 | } |
13640 | } | |
13641 | ||
13642 | static char * | |
fba45db2 | 13643 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13644 | { |
13645 | if (mybool) | |
13646 | return "TRUE"; | |
13647 | else | |
13648 | return "FALSE"; | |
13649 | } | |
13650 | ||
13651 | /* Convert a DWARF type code into its string name. */ | |
13652 | ||
13653 | static char * | |
aa1ee363 | 13654 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
13655 | { |
13656 | switch (enc) | |
13657 | { | |
b7619582 GF |
13658 | case DW_ATE_void: |
13659 | return "DW_ATE_void"; | |
c906108c SS |
13660 | case DW_ATE_address: |
13661 | return "DW_ATE_address"; | |
13662 | case DW_ATE_boolean: | |
13663 | return "DW_ATE_boolean"; | |
13664 | case DW_ATE_complex_float: | |
13665 | return "DW_ATE_complex_float"; | |
13666 | case DW_ATE_float: | |
13667 | return "DW_ATE_float"; | |
13668 | case DW_ATE_signed: | |
13669 | return "DW_ATE_signed"; | |
13670 | case DW_ATE_signed_char: | |
13671 | return "DW_ATE_signed_char"; | |
13672 | case DW_ATE_unsigned: | |
13673 | return "DW_ATE_unsigned"; | |
13674 | case DW_ATE_unsigned_char: | |
13675 | return "DW_ATE_unsigned_char"; | |
b7619582 | 13676 | /* DWARF 3. */ |
d9fa45fe DC |
13677 | case DW_ATE_imaginary_float: |
13678 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
13679 | case DW_ATE_packed_decimal: |
13680 | return "DW_ATE_packed_decimal"; | |
13681 | case DW_ATE_numeric_string: | |
13682 | return "DW_ATE_numeric_string"; | |
13683 | case DW_ATE_edited: | |
13684 | return "DW_ATE_edited"; | |
13685 | case DW_ATE_signed_fixed: | |
13686 | return "DW_ATE_signed_fixed"; | |
13687 | case DW_ATE_unsigned_fixed: | |
13688 | return "DW_ATE_unsigned_fixed"; | |
13689 | case DW_ATE_decimal_float: | |
13690 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13691 | /* DWARF 4. */ |
13692 | case DW_ATE_UTF: | |
13693 | return "DW_ATE_UTF"; | |
b7619582 GF |
13694 | /* HP extensions. */ |
13695 | case DW_ATE_HP_float80: | |
13696 | return "DW_ATE_HP_float80"; | |
13697 | case DW_ATE_HP_complex_float80: | |
13698 | return "DW_ATE_HP_complex_float80"; | |
13699 | case DW_ATE_HP_float128: | |
13700 | return "DW_ATE_HP_float128"; | |
13701 | case DW_ATE_HP_complex_float128: | |
13702 | return "DW_ATE_HP_complex_float128"; | |
13703 | case DW_ATE_HP_floathpintel: | |
13704 | return "DW_ATE_HP_floathpintel"; | |
13705 | case DW_ATE_HP_imaginary_float80: | |
13706 | return "DW_ATE_HP_imaginary_float80"; | |
13707 | case DW_ATE_HP_imaginary_float128: | |
13708 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13709 | default: |
13710 | return "DW_ATE_<unknown>"; | |
13711 | } | |
13712 | } | |
13713 | ||
0963b4bd | 13714 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13715 | |
13716 | #if 0 | |
13717 | static char * | |
aa1ee363 | 13718 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13719 | { |
13720 | switch (cfi_opc) | |
13721 | { | |
13722 | case DW_CFA_advance_loc: | |
13723 | return "DW_CFA_advance_loc"; | |
13724 | case DW_CFA_offset: | |
13725 | return "DW_CFA_offset"; | |
13726 | case DW_CFA_restore: | |
13727 | return "DW_CFA_restore"; | |
13728 | case DW_CFA_nop: | |
13729 | return "DW_CFA_nop"; | |
13730 | case DW_CFA_set_loc: | |
13731 | return "DW_CFA_set_loc"; | |
13732 | case DW_CFA_advance_loc1: | |
13733 | return "DW_CFA_advance_loc1"; | |
13734 | case DW_CFA_advance_loc2: | |
13735 | return "DW_CFA_advance_loc2"; | |
13736 | case DW_CFA_advance_loc4: | |
13737 | return "DW_CFA_advance_loc4"; | |
13738 | case DW_CFA_offset_extended: | |
13739 | return "DW_CFA_offset_extended"; | |
13740 | case DW_CFA_restore_extended: | |
13741 | return "DW_CFA_restore_extended"; | |
13742 | case DW_CFA_undefined: | |
13743 | return "DW_CFA_undefined"; | |
13744 | case DW_CFA_same_value: | |
13745 | return "DW_CFA_same_value"; | |
13746 | case DW_CFA_register: | |
13747 | return "DW_CFA_register"; | |
13748 | case DW_CFA_remember_state: | |
13749 | return "DW_CFA_remember_state"; | |
13750 | case DW_CFA_restore_state: | |
13751 | return "DW_CFA_restore_state"; | |
13752 | case DW_CFA_def_cfa: | |
13753 | return "DW_CFA_def_cfa"; | |
13754 | case DW_CFA_def_cfa_register: | |
13755 | return "DW_CFA_def_cfa_register"; | |
13756 | case DW_CFA_def_cfa_offset: | |
13757 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13758 | /* DWARF 3. */ |
985cb1a3 JM |
13759 | case DW_CFA_def_cfa_expression: |
13760 | return "DW_CFA_def_cfa_expression"; | |
13761 | case DW_CFA_expression: | |
13762 | return "DW_CFA_expression"; | |
13763 | case DW_CFA_offset_extended_sf: | |
13764 | return "DW_CFA_offset_extended_sf"; | |
13765 | case DW_CFA_def_cfa_sf: | |
13766 | return "DW_CFA_def_cfa_sf"; | |
13767 | case DW_CFA_def_cfa_offset_sf: | |
13768 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13769 | case DW_CFA_val_offset: |
13770 | return "DW_CFA_val_offset"; | |
13771 | case DW_CFA_val_offset_sf: | |
13772 | return "DW_CFA_val_offset_sf"; | |
13773 | case DW_CFA_val_expression: | |
13774 | return "DW_CFA_val_expression"; | |
13775 | /* SGI/MIPS specific. */ | |
c906108c SS |
13776 | case DW_CFA_MIPS_advance_loc8: |
13777 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13778 | /* GNU extensions. */ |
985cb1a3 JM |
13779 | case DW_CFA_GNU_window_save: |
13780 | return "DW_CFA_GNU_window_save"; | |
13781 | case DW_CFA_GNU_args_size: | |
13782 | return "DW_CFA_GNU_args_size"; | |
13783 | case DW_CFA_GNU_negative_offset_extended: | |
13784 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13785 | default: |
13786 | return "DW_CFA_<unknown>"; | |
13787 | } | |
13788 | } | |
13789 | #endif | |
13790 | ||
f9aca02d | 13791 | static void |
d97bc12b | 13792 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13793 | { |
13794 | unsigned int i; | |
13795 | ||
d97bc12b DE |
13796 | print_spaces (indent, f); |
13797 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13798 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13799 | |
13800 | if (die->parent != NULL) | |
13801 | { | |
13802 | print_spaces (indent, f); | |
13803 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13804 | die->parent->offset); | |
13805 | } | |
13806 | ||
13807 | print_spaces (indent, f); | |
13808 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13809 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13810 | |
d97bc12b DE |
13811 | print_spaces (indent, f); |
13812 | fprintf_unfiltered (f, " attributes:\n"); | |
13813 | ||
c906108c SS |
13814 | for (i = 0; i < die->num_attrs; ++i) |
13815 | { | |
d97bc12b DE |
13816 | print_spaces (indent, f); |
13817 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13818 | dwarf_attr_name (die->attrs[i].name), |
13819 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13820 | |
c906108c SS |
13821 | switch (die->attrs[i].form) |
13822 | { | |
13823 | case DW_FORM_ref_addr: | |
13824 | case DW_FORM_addr: | |
d97bc12b | 13825 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13826 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13827 | break; |
13828 | case DW_FORM_block2: | |
13829 | case DW_FORM_block4: | |
13830 | case DW_FORM_block: | |
13831 | case DW_FORM_block1: | |
3e43a32a MS |
13832 | fprintf_unfiltered (f, "block: size %d", |
13833 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13834 | break; |
2dc7f7b3 TT |
13835 | case DW_FORM_exprloc: |
13836 | fprintf_unfiltered (f, "expression: size %u", | |
13837 | DW_BLOCK (&die->attrs[i])->size); | |
13838 | break; | |
10b3939b DJ |
13839 | case DW_FORM_ref1: |
13840 | case DW_FORM_ref2: | |
13841 | case DW_FORM_ref4: | |
d97bc12b | 13842 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13843 | (long) (DW_ADDR (&die->attrs[i]))); |
13844 | break; | |
c906108c SS |
13845 | case DW_FORM_data1: |
13846 | case DW_FORM_data2: | |
13847 | case DW_FORM_data4: | |
ce5d95e1 | 13848 | case DW_FORM_data8: |
c906108c SS |
13849 | case DW_FORM_udata: |
13850 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13851 | fprintf_unfiltered (f, "constant: %s", |
13852 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13853 | break; |
2dc7f7b3 TT |
13854 | case DW_FORM_sec_offset: |
13855 | fprintf_unfiltered (f, "section offset: %s", | |
13856 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13857 | break; | |
55f1336d | 13858 | case DW_FORM_ref_sig8: |
348e048f DE |
13859 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13860 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b3c8eb43 | 13861 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
348e048f DE |
13862 | else |
13863 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13864 | break; | |
c906108c | 13865 | case DW_FORM_string: |
4bdf3d34 | 13866 | case DW_FORM_strp: |
8285870a | 13867 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13868 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13869 | ? DW_STRING (&die->attrs[i]) : "", |
13870 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13871 | break; |
13872 | case DW_FORM_flag: | |
13873 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13874 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13875 | else |
d97bc12b | 13876 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13877 | break; |
2dc7f7b3 TT |
13878 | case DW_FORM_flag_present: |
13879 | fprintf_unfiltered (f, "flag: TRUE"); | |
13880 | break; | |
a8329558 | 13881 | case DW_FORM_indirect: |
0963b4bd MS |
13882 | /* The reader will have reduced the indirect form to |
13883 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13884 | fprintf_unfiltered (f, |
13885 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13886 | break; |
c906108c | 13887 | default: |
d97bc12b | 13888 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13889 | die->attrs[i].form); |
d97bc12b | 13890 | break; |
c906108c | 13891 | } |
d97bc12b | 13892 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13893 | } |
13894 | } | |
13895 | ||
f9aca02d | 13896 | static void |
d97bc12b | 13897 | dump_die_for_error (struct die_info *die) |
c906108c | 13898 | { |
d97bc12b DE |
13899 | dump_die_shallow (gdb_stderr, 0, die); |
13900 | } | |
13901 | ||
13902 | static void | |
13903 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13904 | { | |
13905 | int indent = level * 4; | |
13906 | ||
13907 | gdb_assert (die != NULL); | |
13908 | ||
13909 | if (level >= max_level) | |
13910 | return; | |
13911 | ||
13912 | dump_die_shallow (f, indent, die); | |
13913 | ||
13914 | if (die->child != NULL) | |
c906108c | 13915 | { |
d97bc12b DE |
13916 | print_spaces (indent, f); |
13917 | fprintf_unfiltered (f, " Children:"); | |
13918 | if (level + 1 < max_level) | |
13919 | { | |
13920 | fprintf_unfiltered (f, "\n"); | |
13921 | dump_die_1 (f, level + 1, max_level, die->child); | |
13922 | } | |
13923 | else | |
13924 | { | |
3e43a32a MS |
13925 | fprintf_unfiltered (f, |
13926 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13927 | } |
13928 | } | |
13929 | ||
13930 | if (die->sibling != NULL && level > 0) | |
13931 | { | |
13932 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13933 | } |
13934 | } | |
13935 | ||
d97bc12b DE |
13936 | /* This is called from the pdie macro in gdbinit.in. |
13937 | It's not static so gcc will keep a copy callable from gdb. */ | |
13938 | ||
13939 | void | |
13940 | dump_die (struct die_info *die, int max_level) | |
13941 | { | |
13942 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
13943 | } | |
13944 | ||
f9aca02d | 13945 | static void |
51545339 | 13946 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13947 | { |
51545339 | 13948 | void **slot; |
c906108c | 13949 | |
51545339 DJ |
13950 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
13951 | ||
13952 | *slot = die; | |
c906108c SS |
13953 | } |
13954 | ||
93311388 DE |
13955 | static int |
13956 | is_ref_attr (struct attribute *attr) | |
c906108c | 13957 | { |
c906108c SS |
13958 | switch (attr->form) |
13959 | { | |
13960 | case DW_FORM_ref_addr: | |
c906108c SS |
13961 | case DW_FORM_ref1: |
13962 | case DW_FORM_ref2: | |
13963 | case DW_FORM_ref4: | |
613e1657 | 13964 | case DW_FORM_ref8: |
c906108c | 13965 | case DW_FORM_ref_udata: |
93311388 | 13966 | return 1; |
c906108c | 13967 | default: |
93311388 | 13968 | return 0; |
c906108c | 13969 | } |
93311388 DE |
13970 | } |
13971 | ||
13972 | static unsigned int | |
13973 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
13974 | { | |
13975 | if (is_ref_attr (attr)) | |
13976 | return DW_ADDR (attr); | |
13977 | ||
13978 | complaint (&symfile_complaints, | |
13979 | _("unsupported die ref attribute form: '%s'"), | |
13980 | dwarf_form_name (attr->form)); | |
13981 | return 0; | |
c906108c SS |
13982 | } |
13983 | ||
43bbcdc2 PH |
13984 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
13985 | * the value held by the attribute is not constant. */ | |
a02abb62 | 13986 | |
43bbcdc2 | 13987 | static LONGEST |
a02abb62 JB |
13988 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
13989 | { | |
13990 | if (attr->form == DW_FORM_sdata) | |
13991 | return DW_SND (attr); | |
13992 | else if (attr->form == DW_FORM_udata | |
13993 | || attr->form == DW_FORM_data1 | |
13994 | || attr->form == DW_FORM_data2 | |
13995 | || attr->form == DW_FORM_data4 | |
13996 | || attr->form == DW_FORM_data8) | |
13997 | return DW_UNSND (attr); | |
13998 | else | |
13999 | { | |
3e43a32a MS |
14000 | complaint (&symfile_complaints, |
14001 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
14002 | dwarf_form_name (attr->form)); |
14003 | return default_value; | |
14004 | } | |
14005 | } | |
14006 | ||
03dd20cc | 14007 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
14008 | unit and add it to our queue. |
14009 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
14010 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 14011 | |
348e048f | 14012 | static int |
03dd20cc DJ |
14013 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
14014 | struct dwarf2_per_cu_data *per_cu) | |
14015 | { | |
98bfdba5 PA |
14016 | /* We may arrive here during partial symbol reading, if we need full |
14017 | DIEs to process an unusual case (e.g. template arguments). Do | |
14018 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
14019 | if (dwarf2_per_objfile->reading_partial_symbols) | |
14020 | { | |
14021 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
14022 | return 1; | |
14023 | return 0; | |
14024 | } | |
14025 | ||
03dd20cc DJ |
14026 | /* Mark the dependence relation so that we don't flush PER_CU |
14027 | too early. */ | |
14028 | dwarf2_add_dependence (this_cu, per_cu); | |
14029 | ||
14030 | /* If it's already on the queue, we have nothing to do. */ | |
14031 | if (per_cu->queued) | |
348e048f | 14032 | return 0; |
03dd20cc DJ |
14033 | |
14034 | /* If the compilation unit is already loaded, just mark it as | |
14035 | used. */ | |
14036 | if (per_cu->cu != NULL) | |
14037 | { | |
14038 | per_cu->cu->last_used = 0; | |
348e048f | 14039 | return 0; |
03dd20cc DJ |
14040 | } |
14041 | ||
14042 | /* Add it to the queue. */ | |
a0f42c21 | 14043 | queue_comp_unit (per_cu); |
348e048f DE |
14044 | |
14045 | return 1; | |
14046 | } | |
14047 | ||
14048 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
14049 | On entry *REF_CU is the CU of SRC_DIE. | |
14050 | On exit *REF_CU is the CU of the result. */ | |
14051 | ||
14052 | static struct die_info * | |
14053 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
14054 | struct dwarf2_cu **ref_cu) | |
14055 | { | |
14056 | struct die_info *die; | |
14057 | ||
14058 | if (is_ref_attr (attr)) | |
14059 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 14060 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
14061 | die = follow_die_sig (src_die, attr, ref_cu); |
14062 | else | |
14063 | { | |
14064 | dump_die_for_error (src_die); | |
14065 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
14066 | (*ref_cu)->objfile->name); | |
14067 | } | |
14068 | ||
14069 | return die; | |
03dd20cc DJ |
14070 | } |
14071 | ||
5c631832 | 14072 | /* Follow reference OFFSET. |
673bfd45 DE |
14073 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
14074 | On exit *REF_CU is the CU of the result. | |
14075 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 14076 | |
f9aca02d | 14077 | static struct die_info * |
5c631832 | 14078 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 14079 | { |
10b3939b | 14080 | struct die_info temp_die; |
f2f0e013 | 14081 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 14082 | |
348e048f DE |
14083 | gdb_assert (cu->per_cu != NULL); |
14084 | ||
98bfdba5 PA |
14085 | target_cu = cu; |
14086 | ||
b0df02fd | 14087 | if (cu->per_cu->debug_types_section) |
348e048f DE |
14088 | { |
14089 | /* .debug_types CUs cannot reference anything outside their CU. | |
14090 | If they need to, they have to reference a signatured type via | |
55f1336d | 14091 | DW_FORM_ref_sig8. */ |
348e048f | 14092 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 14093 | return NULL; |
348e048f DE |
14094 | } |
14095 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
14096 | { |
14097 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 14098 | |
45452591 | 14099 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
14100 | |
14101 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f | 14102 | if (maybe_queue_comp_unit (cu, per_cu)) |
a0f42c21 | 14103 | load_full_comp_unit (per_cu); |
03dd20cc | 14104 | |
10b3939b DJ |
14105 | target_cu = per_cu->cu; |
14106 | } | |
98bfdba5 PA |
14107 | else if (cu->dies == NULL) |
14108 | { | |
14109 | /* We're loading full DIEs during partial symbol reading. */ | |
14110 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
a0f42c21 | 14111 | load_full_comp_unit (cu->per_cu); |
98bfdba5 | 14112 | } |
c906108c | 14113 | |
f2f0e013 | 14114 | *ref_cu = target_cu; |
51545339 | 14115 | temp_die.offset = offset; |
5c631832 JK |
14116 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
14117 | } | |
10b3939b | 14118 | |
5c631832 JK |
14119 | /* Follow reference attribute ATTR of SRC_DIE. |
14120 | On entry *REF_CU is the CU of SRC_DIE. | |
14121 | On exit *REF_CU is the CU of the result. */ | |
14122 | ||
14123 | static struct die_info * | |
14124 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
14125 | struct dwarf2_cu **ref_cu) | |
14126 | { | |
14127 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
14128 | struct dwarf2_cu *cu = *ref_cu; | |
14129 | struct die_info *die; | |
14130 | ||
14131 | die = follow_die_offset (offset, ref_cu); | |
14132 | if (!die) | |
14133 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
14134 | "at 0x%x [in module %s]"), | |
14135 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 14136 | |
5c631832 JK |
14137 | return die; |
14138 | } | |
14139 | ||
d83e736b JK |
14140 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
14141 | Returned value is intended for DW_OP_call*. Returned | |
14142 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
14143 | |
14144 | struct dwarf2_locexpr_baton | |
14145 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
14146 | struct dwarf2_per_cu_data *per_cu, |
14147 | CORE_ADDR (*get_frame_pc) (void *baton), | |
14148 | void *baton) | |
5c631832 | 14149 | { |
918dd910 | 14150 | struct dwarf2_cu *cu; |
5c631832 JK |
14151 | struct die_info *die; |
14152 | struct attribute *attr; | |
14153 | struct dwarf2_locexpr_baton retval; | |
14154 | ||
8cf6f0b1 TT |
14155 | dw2_setup (per_cu->objfile); |
14156 | ||
918dd910 JK |
14157 | if (per_cu->cu == NULL) |
14158 | load_cu (per_cu); | |
14159 | cu = per_cu->cu; | |
14160 | ||
5c631832 JK |
14161 | die = follow_die_offset (offset, &cu); |
14162 | if (!die) | |
14163 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
bb5ed363 | 14164 | offset, per_cu->objfile->name); |
5c631832 JK |
14165 | |
14166 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14167 | if (!attr) | |
14168 | { | |
e103e986 JK |
14169 | /* DWARF: "If there is no such attribute, then there is no effect.". |
14170 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 14171 | |
e103e986 | 14172 | retval.data = NULL; |
5c631832 JK |
14173 | retval.size = 0; |
14174 | } | |
8cf6f0b1 TT |
14175 | else if (attr_form_is_section_offset (attr)) |
14176 | { | |
14177 | struct dwarf2_loclist_baton loclist_baton; | |
14178 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
14179 | size_t size; | |
14180 | ||
14181 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
14182 | ||
14183 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
14184 | &size, pc); | |
14185 | retval.size = size; | |
14186 | } | |
5c631832 JK |
14187 | else |
14188 | { | |
14189 | if (!attr_form_is_block (attr)) | |
14190 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
14191 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
bb5ed363 | 14192 | offset, per_cu->objfile->name); |
5c631832 JK |
14193 | |
14194 | retval.data = DW_BLOCK (attr)->data; | |
14195 | retval.size = DW_BLOCK (attr)->size; | |
14196 | } | |
14197 | retval.per_cu = cu->per_cu; | |
918dd910 | 14198 | |
918dd910 JK |
14199 | age_cached_comp_units (); |
14200 | ||
5c631832 | 14201 | return retval; |
348e048f DE |
14202 | } |
14203 | ||
8a9b8146 TT |
14204 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
14205 | PER_CU. */ | |
14206 | ||
14207 | struct type * | |
14208 | dwarf2_get_die_type (unsigned int die_offset, | |
14209 | struct dwarf2_per_cu_data *per_cu) | |
14210 | { | |
8a9b8146 | 14211 | dw2_setup (per_cu->objfile); |
9ff3b74f | 14212 | return get_die_type_at_offset (die_offset, per_cu); |
8a9b8146 TT |
14213 | } |
14214 | ||
348e048f DE |
14215 | /* Follow the signature attribute ATTR in SRC_DIE. |
14216 | On entry *REF_CU is the CU of SRC_DIE. | |
14217 | On exit *REF_CU is the CU of the result. */ | |
14218 | ||
14219 | static struct die_info * | |
14220 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
14221 | struct dwarf2_cu **ref_cu) | |
14222 | { | |
14223 | struct objfile *objfile = (*ref_cu)->objfile; | |
14224 | struct die_info temp_die; | |
14225 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
14226 | struct dwarf2_cu *sig_cu; | |
14227 | struct die_info *die; | |
14228 | ||
14229 | /* sig_type will be NULL if the signatured type is missing from | |
14230 | the debug info. */ | |
14231 | if (sig_type == NULL) | |
14232 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14233 | "at 0x%x [in module %s]"), | |
14234 | src_die->offset, objfile->name); | |
14235 | ||
14236 | /* If necessary, add it to the queue and load its DIEs. */ | |
14237 | ||
14238 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
a0f42c21 | 14239 | read_signatured_type (sig_type); |
348e048f DE |
14240 | |
14241 | gdb_assert (sig_type->per_cu.cu != NULL); | |
14242 | ||
14243 | sig_cu = sig_type->per_cu.cu; | |
14244 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
14245 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
14246 | if (die) | |
14247 | { | |
14248 | *ref_cu = sig_cu; | |
14249 | return die; | |
14250 | } | |
14251 | ||
3e43a32a MS |
14252 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
14253 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
14254 | sig_type->type_offset, src_die->offset, objfile->name); |
14255 | } | |
14256 | ||
14257 | /* Given an offset of a signatured type, return its signatured_type. */ | |
14258 | ||
14259 | static struct signatured_type * | |
8b70b953 TT |
14260 | lookup_signatured_type_at_offset (struct objfile *objfile, |
14261 | struct dwarf2_section_info *section, | |
14262 | unsigned int offset) | |
348e048f | 14263 | { |
8b70b953 | 14264 | gdb_byte *info_ptr = section->buffer + offset; |
348e048f DE |
14265 | unsigned int length, initial_length_size; |
14266 | unsigned int sig_offset; | |
14267 | struct signatured_type find_entry, *type_sig; | |
14268 | ||
14269 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
14270 | sig_offset = (initial_length_size | |
14271 | + 2 /*version*/ | |
14272 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
14273 | + 1 /*address_size*/); | |
14274 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
14275 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
14276 | ||
14277 | /* This is only used to lookup previously recorded types. | |
14278 | If we didn't find it, it's our bug. */ | |
14279 | gdb_assert (type_sig != NULL); | |
b3c8eb43 | 14280 | gdb_assert (offset == type_sig->per_cu.offset); |
348e048f DE |
14281 | |
14282 | return type_sig; | |
14283 | } | |
14284 | ||
e5fe5e75 | 14285 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
14286 | |
14287 | static void | |
e5fe5e75 | 14288 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 14289 | { |
e5fe5e75 DE |
14290 | struct objfile *objfile = per_cu->objfile; |
14291 | struct dwarf2_section_info *sect = per_cu->debug_types_section; | |
14292 | unsigned int offset = per_cu->offset; | |
348e048f DE |
14293 | struct signatured_type *type_sig; |
14294 | ||
8b70b953 | 14295 | dwarf2_read_section (objfile, sect); |
be391dca | 14296 | |
348e048f | 14297 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
14298 | hash table lookup. */ |
14299 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
14300 | the signature to assert we found the right one. | |
14301 | Ok, but it's a lot of work. We should simplify things so any needed | |
14302 | assert doesn't require all this clumsiness. */ | |
8b70b953 | 14303 | type_sig = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f DE |
14304 | |
14305 | gdb_assert (type_sig->per_cu.cu == NULL); | |
14306 | ||
a0f42c21 | 14307 | read_signatured_type (type_sig); |
348e048f DE |
14308 | |
14309 | gdb_assert (type_sig->per_cu.cu != NULL); | |
14310 | } | |
14311 | ||
14312 | /* Read in a signatured type and build its CU and DIEs. */ | |
14313 | ||
14314 | static void | |
a0f42c21 | 14315 | read_signatured_type (struct signatured_type *type_sig) |
348e048f | 14316 | { |
a0f42c21 | 14317 | struct objfile *objfile = type_sig->per_cu.objfile; |
1fd400ff | 14318 | gdb_byte *types_ptr; |
348e048f DE |
14319 | struct die_reader_specs reader_specs; |
14320 | struct dwarf2_cu *cu; | |
14321 | ULONGEST signature; | |
14322 | struct cleanup *back_to, *free_cu_cleanup; | |
b0df02fd | 14323 | struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section; |
348e048f | 14324 | |
8b70b953 TT |
14325 | dwarf2_read_section (objfile, section); |
14326 | types_ptr = section->buffer + type_sig->per_cu.offset; | |
1fd400ff | 14327 | |
348e048f DE |
14328 | gdb_assert (type_sig->per_cu.cu == NULL); |
14329 | ||
9816fde3 | 14330 | cu = xmalloc (sizeof (*cu)); |
23745b47 | 14331 | init_one_comp_unit (cu, &type_sig->per_cu); |
348e048f DE |
14332 | |
14333 | /* If an error occurs while loading, release our storage. */ | |
68dc6402 | 14334 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
348e048f | 14335 | |
9ff913ba DE |
14336 | types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr, |
14337 | &signature, NULL); | |
348e048f DE |
14338 | gdb_assert (signature == type_sig->signature); |
14339 | ||
14340 | cu->die_hash | |
14341 | = htab_create_alloc_ex (cu->header.length / 12, | |
14342 | die_hash, | |
14343 | die_eq, | |
14344 | NULL, | |
14345 | &cu->comp_unit_obstack, | |
14346 | hashtab_obstack_allocate, | |
14347 | dummy_obstack_deallocate); | |
14348 | ||
e5fe5e75 | 14349 | dwarf2_read_abbrevs (cu); |
348e048f DE |
14350 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
14351 | ||
14352 | init_cu_die_reader (&reader_specs, cu); | |
14353 | ||
14354 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
14355 | NULL /*parent*/); | |
14356 | ||
14357 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 14358 | all CUs needed for references have been loaded yet, and symbol |
348e048f DE |
14359 | table processing isn't initialized. But we have to set the CU language, |
14360 | or we won't be able to build types correctly. */ | |
9816fde3 | 14361 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
14362 | |
14363 | do_cleanups (back_to); | |
14364 | ||
14365 | /* We've successfully allocated this compilation unit. Let our caller | |
14366 | clean it up when finished with it. */ | |
14367 | discard_cleanups (free_cu_cleanup); | |
14368 | ||
14369 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
14370 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
14371 | } |
14372 | ||
c906108c SS |
14373 | /* Decode simple location descriptions. |
14374 | Given a pointer to a dwarf block that defines a location, compute | |
14375 | the location and return the value. | |
14376 | ||
4cecd739 DJ |
14377 | NOTE drow/2003-11-18: This function is called in two situations |
14378 | now: for the address of static or global variables (partial symbols | |
14379 | only) and for offsets into structures which are expected to be | |
14380 | (more or less) constant. The partial symbol case should go away, | |
14381 | and only the constant case should remain. That will let this | |
14382 | function complain more accurately. A few special modes are allowed | |
14383 | without complaint for global variables (for instance, global | |
14384 | register values and thread-local values). | |
c906108c SS |
14385 | |
14386 | A location description containing no operations indicates that the | |
4cecd739 | 14387 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
14388 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
14389 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
14390 | complaint. |
14391 | ||
14392 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
14393 | |
14394 | static CORE_ADDR | |
e7c27a73 | 14395 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 14396 | { |
e7c27a73 | 14397 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
14398 | int i; |
14399 | int size = blk->size; | |
14400 | gdb_byte *data = blk->data; | |
14401 | CORE_ADDR stack[64]; | |
14402 | int stacki; | |
14403 | unsigned int bytes_read, unsnd; | |
14404 | gdb_byte op; | |
c906108c | 14405 | |
21ae7a4d JK |
14406 | i = 0; |
14407 | stacki = 0; | |
14408 | stack[stacki] = 0; | |
14409 | stack[++stacki] = 0; | |
14410 | ||
14411 | while (i < size) | |
14412 | { | |
14413 | op = data[i++]; | |
14414 | switch (op) | |
14415 | { | |
14416 | case DW_OP_lit0: | |
14417 | case DW_OP_lit1: | |
14418 | case DW_OP_lit2: | |
14419 | case DW_OP_lit3: | |
14420 | case DW_OP_lit4: | |
14421 | case DW_OP_lit5: | |
14422 | case DW_OP_lit6: | |
14423 | case DW_OP_lit7: | |
14424 | case DW_OP_lit8: | |
14425 | case DW_OP_lit9: | |
14426 | case DW_OP_lit10: | |
14427 | case DW_OP_lit11: | |
14428 | case DW_OP_lit12: | |
14429 | case DW_OP_lit13: | |
14430 | case DW_OP_lit14: | |
14431 | case DW_OP_lit15: | |
14432 | case DW_OP_lit16: | |
14433 | case DW_OP_lit17: | |
14434 | case DW_OP_lit18: | |
14435 | case DW_OP_lit19: | |
14436 | case DW_OP_lit20: | |
14437 | case DW_OP_lit21: | |
14438 | case DW_OP_lit22: | |
14439 | case DW_OP_lit23: | |
14440 | case DW_OP_lit24: | |
14441 | case DW_OP_lit25: | |
14442 | case DW_OP_lit26: | |
14443 | case DW_OP_lit27: | |
14444 | case DW_OP_lit28: | |
14445 | case DW_OP_lit29: | |
14446 | case DW_OP_lit30: | |
14447 | case DW_OP_lit31: | |
14448 | stack[++stacki] = op - DW_OP_lit0; | |
14449 | break; | |
f1bea926 | 14450 | |
21ae7a4d JK |
14451 | case DW_OP_reg0: |
14452 | case DW_OP_reg1: | |
14453 | case DW_OP_reg2: | |
14454 | case DW_OP_reg3: | |
14455 | case DW_OP_reg4: | |
14456 | case DW_OP_reg5: | |
14457 | case DW_OP_reg6: | |
14458 | case DW_OP_reg7: | |
14459 | case DW_OP_reg8: | |
14460 | case DW_OP_reg9: | |
14461 | case DW_OP_reg10: | |
14462 | case DW_OP_reg11: | |
14463 | case DW_OP_reg12: | |
14464 | case DW_OP_reg13: | |
14465 | case DW_OP_reg14: | |
14466 | case DW_OP_reg15: | |
14467 | case DW_OP_reg16: | |
14468 | case DW_OP_reg17: | |
14469 | case DW_OP_reg18: | |
14470 | case DW_OP_reg19: | |
14471 | case DW_OP_reg20: | |
14472 | case DW_OP_reg21: | |
14473 | case DW_OP_reg22: | |
14474 | case DW_OP_reg23: | |
14475 | case DW_OP_reg24: | |
14476 | case DW_OP_reg25: | |
14477 | case DW_OP_reg26: | |
14478 | case DW_OP_reg27: | |
14479 | case DW_OP_reg28: | |
14480 | case DW_OP_reg29: | |
14481 | case DW_OP_reg30: | |
14482 | case DW_OP_reg31: | |
14483 | stack[++stacki] = op - DW_OP_reg0; | |
14484 | if (i < size) | |
14485 | dwarf2_complex_location_expr_complaint (); | |
14486 | break; | |
c906108c | 14487 | |
21ae7a4d JK |
14488 | case DW_OP_regx: |
14489 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
14490 | i += bytes_read; | |
14491 | stack[++stacki] = unsnd; | |
14492 | if (i < size) | |
14493 | dwarf2_complex_location_expr_complaint (); | |
14494 | break; | |
c906108c | 14495 | |
21ae7a4d JK |
14496 | case DW_OP_addr: |
14497 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
14498 | cu, &bytes_read); | |
14499 | i += bytes_read; | |
14500 | break; | |
d53d4ac5 | 14501 | |
21ae7a4d JK |
14502 | case DW_OP_const1u: |
14503 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
14504 | i += 1; | |
14505 | break; | |
14506 | ||
14507 | case DW_OP_const1s: | |
14508 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
14509 | i += 1; | |
14510 | break; | |
14511 | ||
14512 | case DW_OP_const2u: | |
14513 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
14514 | i += 2; | |
14515 | break; | |
14516 | ||
14517 | case DW_OP_const2s: | |
14518 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
14519 | i += 2; | |
14520 | break; | |
d53d4ac5 | 14521 | |
21ae7a4d JK |
14522 | case DW_OP_const4u: |
14523 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
14524 | i += 4; | |
14525 | break; | |
14526 | ||
14527 | case DW_OP_const4s: | |
14528 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
14529 | i += 4; | |
14530 | break; | |
14531 | ||
585861ea JK |
14532 | case DW_OP_const8u: |
14533 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
14534 | i += 8; | |
14535 | break; | |
14536 | ||
21ae7a4d JK |
14537 | case DW_OP_constu: |
14538 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
14539 | &bytes_read); | |
14540 | i += bytes_read; | |
14541 | break; | |
14542 | ||
14543 | case DW_OP_consts: | |
14544 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
14545 | i += bytes_read; | |
14546 | break; | |
14547 | ||
14548 | case DW_OP_dup: | |
14549 | stack[stacki + 1] = stack[stacki]; | |
14550 | stacki++; | |
14551 | break; | |
14552 | ||
14553 | case DW_OP_plus: | |
14554 | stack[stacki - 1] += stack[stacki]; | |
14555 | stacki--; | |
14556 | break; | |
14557 | ||
14558 | case DW_OP_plus_uconst: | |
14559 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
14560 | &bytes_read); | |
14561 | i += bytes_read; | |
14562 | break; | |
14563 | ||
14564 | case DW_OP_minus: | |
14565 | stack[stacki - 1] -= stack[stacki]; | |
14566 | stacki--; | |
14567 | break; | |
14568 | ||
14569 | case DW_OP_deref: | |
14570 | /* If we're not the last op, then we definitely can't encode | |
14571 | this using GDB's address_class enum. This is valid for partial | |
14572 | global symbols, although the variable's address will be bogus | |
14573 | in the psymtab. */ | |
14574 | if (i < size) | |
14575 | dwarf2_complex_location_expr_complaint (); | |
14576 | break; | |
14577 | ||
14578 | case DW_OP_GNU_push_tls_address: | |
14579 | /* The top of the stack has the offset from the beginning | |
14580 | of the thread control block at which the variable is located. */ | |
14581 | /* Nothing should follow this operator, so the top of stack would | |
14582 | be returned. */ | |
14583 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
14584 | address will be bogus in the psymtab. Make it always at least |
14585 | non-zero to not look as a variable garbage collected by linker | |
14586 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
14587 | if (i < size) |
14588 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 14589 | stack[stacki]++; |
21ae7a4d JK |
14590 | break; |
14591 | ||
14592 | case DW_OP_GNU_uninit: | |
14593 | break; | |
14594 | ||
14595 | default: | |
14596 | { | |
14597 | const char *name = dwarf_stack_op_name (op); | |
14598 | ||
14599 | if (name) | |
14600 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
14601 | name); | |
14602 | else | |
14603 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
14604 | op); | |
14605 | } | |
14606 | ||
14607 | return (stack[stacki]); | |
d53d4ac5 | 14608 | } |
3c6e0cb3 | 14609 | |
21ae7a4d JK |
14610 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
14611 | outside of the allocated space. Also enforce minimum>0. */ | |
14612 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
14613 | { | |
14614 | complaint (&symfile_complaints, | |
14615 | _("location description stack overflow")); | |
14616 | return 0; | |
14617 | } | |
14618 | ||
14619 | if (stacki <= 0) | |
14620 | { | |
14621 | complaint (&symfile_complaints, | |
14622 | _("location description stack underflow")); | |
14623 | return 0; | |
14624 | } | |
14625 | } | |
14626 | return (stack[stacki]); | |
c906108c SS |
14627 | } |
14628 | ||
14629 | /* memory allocation interface */ | |
14630 | ||
c906108c | 14631 | static struct dwarf_block * |
7b5a2f43 | 14632 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14633 | { |
14634 | struct dwarf_block *blk; | |
14635 | ||
14636 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14637 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
14638 | return (blk); |
14639 | } | |
14640 | ||
14641 | static struct abbrev_info * | |
f3dd6933 | 14642 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
14643 | { |
14644 | struct abbrev_info *abbrev; | |
14645 | ||
f3dd6933 DJ |
14646 | abbrev = (struct abbrev_info *) |
14647 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
14648 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
14649 | return (abbrev); | |
14650 | } | |
14651 | ||
14652 | static struct die_info * | |
b60c80d6 | 14653 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
14654 | { |
14655 | struct die_info *die; | |
b60c80d6 DJ |
14656 | size_t size = sizeof (struct die_info); |
14657 | ||
14658 | if (num_attrs > 1) | |
14659 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 14660 | |
b60c80d6 | 14661 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
14662 | memset (die, 0, sizeof (struct die_info)); |
14663 | return (die); | |
14664 | } | |
2e276125 JB |
14665 | |
14666 | \f | |
14667 | /* Macro support. */ | |
14668 | ||
2e276125 JB |
14669 | /* Return the full name of file number I in *LH's file name table. |
14670 | Use COMP_DIR as the name of the current directory of the | |
14671 | compilation. The result is allocated using xmalloc; the caller is | |
14672 | responsible for freeing it. */ | |
14673 | static char * | |
14674 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
14675 | { | |
6a83a1e6 EZ |
14676 | /* Is the file number a valid index into the line header's file name |
14677 | table? Remember that file numbers start with one, not zero. */ | |
14678 | if (1 <= file && file <= lh->num_file_names) | |
14679 | { | |
14680 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 14681 | |
6a83a1e6 EZ |
14682 | if (IS_ABSOLUTE_PATH (fe->name)) |
14683 | return xstrdup (fe->name); | |
14684 | else | |
14685 | { | |
14686 | const char *dir; | |
14687 | int dir_len; | |
14688 | char *full_name; | |
14689 | ||
14690 | if (fe->dir_index) | |
14691 | dir = lh->include_dirs[fe->dir_index - 1]; | |
14692 | else | |
14693 | dir = comp_dir; | |
14694 | ||
14695 | if (dir) | |
14696 | { | |
14697 | dir_len = strlen (dir); | |
14698 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
14699 | strcpy (full_name, dir); | |
14700 | full_name[dir_len] = '/'; | |
14701 | strcpy (full_name + dir_len + 1, fe->name); | |
14702 | return full_name; | |
14703 | } | |
14704 | else | |
14705 | return xstrdup (fe->name); | |
14706 | } | |
14707 | } | |
2e276125 JB |
14708 | else |
14709 | { | |
6a83a1e6 EZ |
14710 | /* The compiler produced a bogus file number. We can at least |
14711 | record the macro definitions made in the file, even if we | |
14712 | won't be able to find the file by name. */ | |
14713 | char fake_name[80]; | |
9a619af0 | 14714 | |
6a83a1e6 | 14715 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 14716 | |
6e70227d | 14717 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
14718 | _("bad file number in macro information (%d)"), |
14719 | file); | |
2e276125 | 14720 | |
6a83a1e6 | 14721 | return xstrdup (fake_name); |
2e276125 JB |
14722 | } |
14723 | } | |
14724 | ||
14725 | ||
14726 | static struct macro_source_file * | |
14727 | macro_start_file (int file, int line, | |
14728 | struct macro_source_file *current_file, | |
14729 | const char *comp_dir, | |
14730 | struct line_header *lh, struct objfile *objfile) | |
14731 | { | |
14732 | /* The full name of this source file. */ | |
14733 | char *full_name = file_full_name (file, lh, comp_dir); | |
14734 | ||
14735 | /* We don't create a macro table for this compilation unit | |
14736 | at all until we actually get a filename. */ | |
14737 | if (! pending_macros) | |
4a146b47 | 14738 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14739 | objfile->macro_cache); |
2e276125 JB |
14740 | |
14741 | if (! current_file) | |
14742 | /* If we have no current file, then this must be the start_file | |
14743 | directive for the compilation unit's main source file. */ | |
14744 | current_file = macro_set_main (pending_macros, full_name); | |
14745 | else | |
14746 | current_file = macro_include (current_file, line, full_name); | |
14747 | ||
14748 | xfree (full_name); | |
6e70227d | 14749 | |
2e276125 JB |
14750 | return current_file; |
14751 | } | |
14752 | ||
14753 | ||
14754 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14755 | followed by a null byte. */ | |
14756 | static char * | |
14757 | copy_string (const char *buf, int len) | |
14758 | { | |
14759 | char *s = xmalloc (len + 1); | |
9a619af0 | 14760 | |
2e276125 JB |
14761 | memcpy (s, buf, len); |
14762 | s[len] = '\0'; | |
2e276125 JB |
14763 | return s; |
14764 | } | |
14765 | ||
14766 | ||
14767 | static const char * | |
14768 | consume_improper_spaces (const char *p, const char *body) | |
14769 | { | |
14770 | if (*p == ' ') | |
14771 | { | |
4d3c2250 | 14772 | complaint (&symfile_complaints, |
3e43a32a MS |
14773 | _("macro definition contains spaces " |
14774 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14775 | body); |
2e276125 JB |
14776 | |
14777 | while (*p == ' ') | |
14778 | p++; | |
14779 | } | |
14780 | ||
14781 | return p; | |
14782 | } | |
14783 | ||
14784 | ||
14785 | static void | |
14786 | parse_macro_definition (struct macro_source_file *file, int line, | |
14787 | const char *body) | |
14788 | { | |
14789 | const char *p; | |
14790 | ||
14791 | /* The body string takes one of two forms. For object-like macro | |
14792 | definitions, it should be: | |
14793 | ||
14794 | <macro name> " " <definition> | |
14795 | ||
14796 | For function-like macro definitions, it should be: | |
14797 | ||
14798 | <macro name> "() " <definition> | |
14799 | or | |
14800 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14801 | ||
14802 | Spaces may appear only where explicitly indicated, and in the | |
14803 | <definition>. | |
14804 | ||
14805 | The Dwarf 2 spec says that an object-like macro's name is always | |
14806 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14807 | the space when the macro's definition is the empty string. |
2e276125 JB |
14808 | |
14809 | The Dwarf 2 spec says that there should be no spaces between the | |
14810 | formal arguments in a function-like macro's formal argument list, | |
14811 | but versions of GCC around March 2002 include spaces after the | |
14812 | commas. */ | |
14813 | ||
14814 | ||
14815 | /* Find the extent of the macro name. The macro name is terminated | |
14816 | by either a space or null character (for an object-like macro) or | |
14817 | an opening paren (for a function-like macro). */ | |
14818 | for (p = body; *p; p++) | |
14819 | if (*p == ' ' || *p == '(') | |
14820 | break; | |
14821 | ||
14822 | if (*p == ' ' || *p == '\0') | |
14823 | { | |
14824 | /* It's an object-like macro. */ | |
14825 | int name_len = p - body; | |
14826 | char *name = copy_string (body, name_len); | |
14827 | const char *replacement; | |
14828 | ||
14829 | if (*p == ' ') | |
14830 | replacement = body + name_len + 1; | |
14831 | else | |
14832 | { | |
4d3c2250 | 14833 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14834 | replacement = body + name_len; |
14835 | } | |
6e70227d | 14836 | |
2e276125 JB |
14837 | macro_define_object (file, line, name, replacement); |
14838 | ||
14839 | xfree (name); | |
14840 | } | |
14841 | else if (*p == '(') | |
14842 | { | |
14843 | /* It's a function-like macro. */ | |
14844 | char *name = copy_string (body, p - body); | |
14845 | int argc = 0; | |
14846 | int argv_size = 1; | |
14847 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14848 | ||
14849 | p++; | |
14850 | ||
14851 | p = consume_improper_spaces (p, body); | |
14852 | ||
14853 | /* Parse the formal argument list. */ | |
14854 | while (*p && *p != ')') | |
14855 | { | |
14856 | /* Find the extent of the current argument name. */ | |
14857 | const char *arg_start = p; | |
14858 | ||
14859 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14860 | p++; | |
14861 | ||
14862 | if (! *p || p == arg_start) | |
4d3c2250 | 14863 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14864 | else |
14865 | { | |
14866 | /* Make sure argv has room for the new argument. */ | |
14867 | if (argc >= argv_size) | |
14868 | { | |
14869 | argv_size *= 2; | |
14870 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14871 | } | |
14872 | ||
14873 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14874 | } | |
14875 | ||
14876 | p = consume_improper_spaces (p, body); | |
14877 | ||
14878 | /* Consume the comma, if present. */ | |
14879 | if (*p == ',') | |
14880 | { | |
14881 | p++; | |
14882 | ||
14883 | p = consume_improper_spaces (p, body); | |
14884 | } | |
14885 | } | |
14886 | ||
14887 | if (*p == ')') | |
14888 | { | |
14889 | p++; | |
14890 | ||
14891 | if (*p == ' ') | |
14892 | /* Perfectly formed definition, no complaints. */ | |
14893 | macro_define_function (file, line, name, | |
6e70227d | 14894 | argc, (const char **) argv, |
2e276125 JB |
14895 | p + 1); |
14896 | else if (*p == '\0') | |
14897 | { | |
14898 | /* Complain, but do define it. */ | |
4d3c2250 | 14899 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14900 | macro_define_function (file, line, name, |
6e70227d | 14901 | argc, (const char **) argv, |
2e276125 JB |
14902 | p); |
14903 | } | |
14904 | else | |
14905 | /* Just complain. */ | |
4d3c2250 | 14906 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14907 | } |
14908 | else | |
14909 | /* Just complain. */ | |
4d3c2250 | 14910 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14911 | |
14912 | xfree (name); | |
14913 | { | |
14914 | int i; | |
14915 | ||
14916 | for (i = 0; i < argc; i++) | |
14917 | xfree (argv[i]); | |
14918 | } | |
14919 | xfree (argv); | |
14920 | } | |
14921 | else | |
4d3c2250 | 14922 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14923 | } |
14924 | ||
cf2c3c16 TT |
14925 | /* Skip some bytes from BYTES according to the form given in FORM. |
14926 | Returns the new pointer. */ | |
2e276125 | 14927 | |
cf2c3c16 TT |
14928 | static gdb_byte * |
14929 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
14930 | enum dwarf_form form, | |
14931 | unsigned int offset_size, | |
14932 | struct dwarf2_section_info *section) | |
2e276125 | 14933 | { |
cf2c3c16 | 14934 | unsigned int bytes_read; |
2e276125 | 14935 | |
cf2c3c16 | 14936 | switch (form) |
2e276125 | 14937 | { |
cf2c3c16 TT |
14938 | case DW_FORM_data1: |
14939 | case DW_FORM_flag: | |
14940 | ++bytes; | |
14941 | break; | |
14942 | ||
14943 | case DW_FORM_data2: | |
14944 | bytes += 2; | |
14945 | break; | |
14946 | ||
14947 | case DW_FORM_data4: | |
14948 | bytes += 4; | |
14949 | break; | |
14950 | ||
14951 | case DW_FORM_data8: | |
14952 | bytes += 8; | |
14953 | break; | |
14954 | ||
14955 | case DW_FORM_string: | |
14956 | read_direct_string (abfd, bytes, &bytes_read); | |
14957 | bytes += bytes_read; | |
14958 | break; | |
14959 | ||
14960 | case DW_FORM_sec_offset: | |
14961 | case DW_FORM_strp: | |
14962 | bytes += offset_size; | |
14963 | break; | |
14964 | ||
14965 | case DW_FORM_block: | |
14966 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
14967 | bytes += bytes_read; | |
14968 | break; | |
14969 | ||
14970 | case DW_FORM_block1: | |
14971 | bytes += 1 + read_1_byte (abfd, bytes); | |
14972 | break; | |
14973 | case DW_FORM_block2: | |
14974 | bytes += 2 + read_2_bytes (abfd, bytes); | |
14975 | break; | |
14976 | case DW_FORM_block4: | |
14977 | bytes += 4 + read_4_bytes (abfd, bytes); | |
14978 | break; | |
14979 | ||
14980 | case DW_FORM_sdata: | |
14981 | case DW_FORM_udata: | |
14982 | bytes = skip_leb128 (abfd, bytes); | |
14983 | break; | |
14984 | ||
14985 | default: | |
14986 | { | |
14987 | complain: | |
14988 | complaint (&symfile_complaints, | |
14989 | _("invalid form 0x%x in `%s'"), | |
14990 | form, | |
14991 | section->asection->name); | |
14992 | return NULL; | |
14993 | } | |
2e276125 JB |
14994 | } |
14995 | ||
cf2c3c16 TT |
14996 | return bytes; |
14997 | } | |
757a13d0 | 14998 | |
cf2c3c16 TT |
14999 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
15000 | opcode. Returns an updated pointer to the macro data buffer; or, | |
15001 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 15002 | |
cf2c3c16 TT |
15003 | static gdb_byte * |
15004 | skip_unknown_opcode (unsigned int opcode, | |
15005 | gdb_byte **opcode_definitions, | |
15006 | gdb_byte *mac_ptr, | |
15007 | bfd *abfd, | |
15008 | unsigned int offset_size, | |
15009 | struct dwarf2_section_info *section) | |
15010 | { | |
15011 | unsigned int bytes_read, i; | |
15012 | unsigned long arg; | |
15013 | gdb_byte *defn; | |
2e276125 | 15014 | |
cf2c3c16 | 15015 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 15016 | { |
cf2c3c16 TT |
15017 | complaint (&symfile_complaints, |
15018 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
15019 | opcode); | |
15020 | return NULL; | |
15021 | } | |
2e276125 | 15022 | |
cf2c3c16 TT |
15023 | defn = opcode_definitions[opcode]; |
15024 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
15025 | defn += bytes_read; | |
2e276125 | 15026 | |
cf2c3c16 TT |
15027 | for (i = 0; i < arg; ++i) |
15028 | { | |
15029 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
15030 | if (mac_ptr == NULL) | |
15031 | { | |
15032 | /* skip_form_bytes already issued the complaint. */ | |
15033 | return NULL; | |
15034 | } | |
15035 | } | |
757a13d0 | 15036 | |
cf2c3c16 TT |
15037 | return mac_ptr; |
15038 | } | |
757a13d0 | 15039 | |
cf2c3c16 TT |
15040 | /* A helper function which parses the header of a macro section. |
15041 | If the macro section is the extended (for now called "GNU") type, | |
15042 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
15043 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 15044 | |
cf2c3c16 TT |
15045 | static gdb_byte * |
15046 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
15047 | bfd *abfd, | |
15048 | gdb_byte *mac_ptr, | |
15049 | unsigned int *offset_size, | |
15050 | int section_is_gnu) | |
15051 | { | |
15052 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 15053 | |
cf2c3c16 TT |
15054 | if (section_is_gnu) |
15055 | { | |
15056 | unsigned int version, flags; | |
757a13d0 | 15057 | |
cf2c3c16 TT |
15058 | version = read_2_bytes (abfd, mac_ptr); |
15059 | if (version != 4) | |
15060 | { | |
15061 | complaint (&symfile_complaints, | |
15062 | _("unrecognized version `%d' in .debug_macro section"), | |
15063 | version); | |
15064 | return NULL; | |
15065 | } | |
15066 | mac_ptr += 2; | |
757a13d0 | 15067 | |
cf2c3c16 TT |
15068 | flags = read_1_byte (abfd, mac_ptr); |
15069 | ++mac_ptr; | |
15070 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 15071 | |
cf2c3c16 TT |
15072 | if ((flags & 2) != 0) |
15073 | /* We don't need the line table offset. */ | |
15074 | mac_ptr += *offset_size; | |
757a13d0 | 15075 | |
cf2c3c16 TT |
15076 | /* Vendor opcode descriptions. */ |
15077 | if ((flags & 4) != 0) | |
15078 | { | |
15079 | unsigned int i, count; | |
757a13d0 | 15080 | |
cf2c3c16 TT |
15081 | count = read_1_byte (abfd, mac_ptr); |
15082 | ++mac_ptr; | |
15083 | for (i = 0; i < count; ++i) | |
15084 | { | |
15085 | unsigned int opcode, bytes_read; | |
15086 | unsigned long arg; | |
15087 | ||
15088 | opcode = read_1_byte (abfd, mac_ptr); | |
15089 | ++mac_ptr; | |
15090 | opcode_definitions[opcode] = mac_ptr; | |
15091 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15092 | mac_ptr += bytes_read; | |
15093 | mac_ptr += arg; | |
15094 | } | |
757a13d0 | 15095 | } |
cf2c3c16 | 15096 | } |
757a13d0 | 15097 | |
cf2c3c16 TT |
15098 | return mac_ptr; |
15099 | } | |
757a13d0 | 15100 | |
cf2c3c16 TT |
15101 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
15102 | including DW_GNU_MACINFO_transparent_include. */ | |
15103 | ||
15104 | static void | |
15105 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
15106 | struct macro_source_file *current_file, | |
15107 | struct line_header *lh, char *comp_dir, | |
15108 | struct dwarf2_section_info *section, | |
15109 | int section_is_gnu, | |
15110 | unsigned int offset_size, | |
15111 | struct objfile *objfile) | |
15112 | { | |
15113 | enum dwarf_macro_record_type macinfo_type; | |
15114 | int at_commandline; | |
15115 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 15116 | |
cf2c3c16 TT |
15117 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
15118 | &offset_size, section_is_gnu); | |
15119 | if (mac_ptr == NULL) | |
15120 | { | |
15121 | /* We already issued a complaint. */ | |
15122 | return; | |
15123 | } | |
757a13d0 JK |
15124 | |
15125 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
15126 | GDB is still reading the definitions from command line. First | |
15127 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
15128 | to create CURRENT_FILE for the main source holding also the command line | |
15129 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
15130 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
15131 | ||
15132 | at_commandline = 1; | |
15133 | ||
15134 | do | |
15135 | { | |
15136 | /* Do we at least have room for a macinfo type byte? */ | |
15137 | if (mac_ptr >= mac_end) | |
15138 | { | |
cf2c3c16 | 15139 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
15140 | break; |
15141 | } | |
15142 | ||
15143 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15144 | mac_ptr++; | |
15145 | ||
cf2c3c16 TT |
15146 | /* Note that we rely on the fact that the corresponding GNU and |
15147 | DWARF constants are the same. */ | |
757a13d0 JK |
15148 | switch (macinfo_type) |
15149 | { | |
15150 | /* A zero macinfo type indicates the end of the macro | |
15151 | information. */ | |
15152 | case 0: | |
15153 | break; | |
2e276125 | 15154 | |
cf2c3c16 TT |
15155 | case DW_MACRO_GNU_define: |
15156 | case DW_MACRO_GNU_undef: | |
15157 | case DW_MACRO_GNU_define_indirect: | |
15158 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 15159 | { |
891d2f0b | 15160 | unsigned int bytes_read; |
2e276125 JB |
15161 | int line; |
15162 | char *body; | |
cf2c3c16 | 15163 | int is_define; |
2e276125 | 15164 | |
cf2c3c16 TT |
15165 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15166 | mac_ptr += bytes_read; | |
15167 | ||
15168 | if (macinfo_type == DW_MACRO_GNU_define | |
15169 | || macinfo_type == DW_MACRO_GNU_undef) | |
15170 | { | |
15171 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
15172 | mac_ptr += bytes_read; | |
15173 | } | |
15174 | else | |
15175 | { | |
15176 | LONGEST str_offset; | |
15177 | ||
15178 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15179 | mac_ptr += offset_size; | |
2e276125 | 15180 | |
cf2c3c16 TT |
15181 | body = read_indirect_string_at_offset (abfd, str_offset); |
15182 | } | |
15183 | ||
15184 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
15185 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 15186 | if (! current_file) |
757a13d0 JK |
15187 | { |
15188 | /* DWARF violation as no main source is present. */ | |
15189 | complaint (&symfile_complaints, | |
15190 | _("debug info with no main source gives macro %s " | |
15191 | "on line %d: %s"), | |
cf2c3c16 TT |
15192 | is_define ? _("definition") : _("undefinition"), |
15193 | line, body); | |
757a13d0 JK |
15194 | break; |
15195 | } | |
3e43a32a MS |
15196 | if ((line == 0 && !at_commandline) |
15197 | || (line != 0 && at_commandline)) | |
4d3c2250 | 15198 | complaint (&symfile_complaints, |
757a13d0 JK |
15199 | _("debug info gives %s macro %s with %s line %d: %s"), |
15200 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 15201 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
15202 | line == 0 ? _("zero") : _("non-zero"), line, body); |
15203 | ||
cf2c3c16 | 15204 | if (is_define) |
757a13d0 | 15205 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
15206 | else |
15207 | { | |
15208 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
15209 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
15210 | macro_undef (current_file, line, body); | |
15211 | } | |
2e276125 JB |
15212 | } |
15213 | break; | |
15214 | ||
cf2c3c16 | 15215 | case DW_MACRO_GNU_start_file: |
2e276125 | 15216 | { |
891d2f0b | 15217 | unsigned int bytes_read; |
2e276125 JB |
15218 | int line, file; |
15219 | ||
15220 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15221 | mac_ptr += bytes_read; | |
15222 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15223 | mac_ptr += bytes_read; | |
15224 | ||
3e43a32a MS |
15225 | if ((line == 0 && !at_commandline) |
15226 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
15227 | complaint (&symfile_complaints, |
15228 | _("debug info gives source %d included " | |
15229 | "from %s at %s line %d"), | |
15230 | file, at_commandline ? _("command-line") : _("file"), | |
15231 | line == 0 ? _("zero") : _("non-zero"), line); | |
15232 | ||
15233 | if (at_commandline) | |
15234 | { | |
cf2c3c16 TT |
15235 | /* This DW_MACRO_GNU_start_file was executed in the |
15236 | pass one. */ | |
757a13d0 JK |
15237 | at_commandline = 0; |
15238 | } | |
15239 | else | |
15240 | current_file = macro_start_file (file, line, | |
15241 | current_file, comp_dir, | |
cf2c3c16 | 15242 | lh, objfile); |
2e276125 JB |
15243 | } |
15244 | break; | |
15245 | ||
cf2c3c16 | 15246 | case DW_MACRO_GNU_end_file: |
2e276125 | 15247 | if (! current_file) |
4d3c2250 | 15248 | complaint (&symfile_complaints, |
3e43a32a MS |
15249 | _("macro debug info has an unmatched " |
15250 | "`close_file' directive")); | |
2e276125 JB |
15251 | else |
15252 | { | |
15253 | current_file = current_file->included_by; | |
15254 | if (! current_file) | |
15255 | { | |
cf2c3c16 | 15256 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
15257 | |
15258 | /* GCC circa March 2002 doesn't produce the zero | |
15259 | type byte marking the end of the compilation | |
15260 | unit. Complain if it's not there, but exit no | |
15261 | matter what. */ | |
15262 | ||
15263 | /* Do we at least have room for a macinfo type byte? */ | |
15264 | if (mac_ptr >= mac_end) | |
15265 | { | |
cf2c3c16 | 15266 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
15267 | return; |
15268 | } | |
15269 | ||
15270 | /* We don't increment mac_ptr here, so this is just | |
15271 | a look-ahead. */ | |
15272 | next_type = read_1_byte (abfd, mac_ptr); | |
15273 | if (next_type != 0) | |
4d3c2250 | 15274 | complaint (&symfile_complaints, |
3e43a32a MS |
15275 | _("no terminating 0-type entry for " |
15276 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
15277 | |
15278 | return; | |
15279 | } | |
15280 | } | |
15281 | break; | |
15282 | ||
cf2c3c16 TT |
15283 | case DW_MACRO_GNU_transparent_include: |
15284 | { | |
15285 | LONGEST offset; | |
15286 | ||
15287 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15288 | mac_ptr += offset_size; | |
15289 | ||
15290 | dwarf_decode_macro_bytes (abfd, | |
15291 | section->buffer + offset, | |
15292 | mac_end, current_file, | |
15293 | lh, comp_dir, | |
15294 | section, section_is_gnu, | |
15295 | offset_size, objfile); | |
15296 | } | |
15297 | break; | |
15298 | ||
2e276125 | 15299 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
15300 | if (!section_is_gnu) |
15301 | { | |
15302 | unsigned int bytes_read; | |
15303 | int constant; | |
2e276125 | 15304 | |
cf2c3c16 TT |
15305 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15306 | mac_ptr += bytes_read; | |
15307 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15308 | mac_ptr += bytes_read; | |
2e276125 | 15309 | |
cf2c3c16 TT |
15310 | /* We don't recognize any vendor extensions. */ |
15311 | break; | |
15312 | } | |
15313 | /* FALLTHROUGH */ | |
15314 | ||
15315 | default: | |
15316 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15317 | mac_ptr, abfd, offset_size, | |
15318 | section); | |
15319 | if (mac_ptr == NULL) | |
15320 | return; | |
15321 | break; | |
2e276125 | 15322 | } |
757a13d0 | 15323 | } while (macinfo_type != 0); |
2e276125 | 15324 | } |
8e19ed76 | 15325 | |
cf2c3c16 TT |
15326 | static void |
15327 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
15328 | char *comp_dir, bfd *abfd, | |
15329 | struct dwarf2_cu *cu, | |
15330 | struct dwarf2_section_info *section, | |
15331 | int section_is_gnu) | |
15332 | { | |
bb5ed363 | 15333 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
15334 | gdb_byte *mac_ptr, *mac_end; |
15335 | struct macro_source_file *current_file = 0; | |
15336 | enum dwarf_macro_record_type macinfo_type; | |
15337 | unsigned int offset_size = cu->header.offset_size; | |
15338 | gdb_byte *opcode_definitions[256]; | |
15339 | ||
bb5ed363 | 15340 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
15341 | if (section->buffer == NULL) |
15342 | { | |
15343 | complaint (&symfile_complaints, _("missing %s section"), | |
15344 | section->asection->name); | |
15345 | return; | |
15346 | } | |
15347 | ||
15348 | /* First pass: Find the name of the base filename. | |
15349 | This filename is needed in order to process all macros whose definition | |
15350 | (or undefinition) comes from the command line. These macros are defined | |
15351 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
15352 | associated to the base file. | |
15353 | ||
15354 | To determine the base file name, we scan the macro definitions until we | |
15355 | reach the first DW_MACINFO_start_file entry. We then initialize | |
15356 | CURRENT_FILE accordingly so that any macro definition found before the | |
15357 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
15358 | ||
15359 | mac_ptr = section->buffer + offset; | |
15360 | mac_end = section->buffer + section->size; | |
15361 | ||
15362 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
15363 | &offset_size, section_is_gnu); | |
15364 | if (mac_ptr == NULL) | |
15365 | { | |
15366 | /* We already issued a complaint. */ | |
15367 | return; | |
15368 | } | |
15369 | ||
15370 | do | |
15371 | { | |
15372 | /* Do we at least have room for a macinfo type byte? */ | |
15373 | if (mac_ptr >= mac_end) | |
15374 | { | |
15375 | /* Complaint is printed during the second pass as GDB will probably | |
15376 | stop the first pass earlier upon finding | |
15377 | DW_MACINFO_start_file. */ | |
15378 | break; | |
15379 | } | |
15380 | ||
15381 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15382 | mac_ptr++; | |
15383 | ||
15384 | /* Note that we rely on the fact that the corresponding GNU and | |
15385 | DWARF constants are the same. */ | |
15386 | switch (macinfo_type) | |
15387 | { | |
15388 | /* A zero macinfo type indicates the end of the macro | |
15389 | information. */ | |
15390 | case 0: | |
15391 | break; | |
15392 | ||
15393 | case DW_MACRO_GNU_define: | |
15394 | case DW_MACRO_GNU_undef: | |
15395 | /* Only skip the data by MAC_PTR. */ | |
15396 | { | |
15397 | unsigned int bytes_read; | |
15398 | ||
15399 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15400 | mac_ptr += bytes_read; | |
15401 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15402 | mac_ptr += bytes_read; | |
15403 | } | |
15404 | break; | |
15405 | ||
15406 | case DW_MACRO_GNU_start_file: | |
15407 | { | |
15408 | unsigned int bytes_read; | |
15409 | int line, file; | |
15410 | ||
15411 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15412 | mac_ptr += bytes_read; | |
15413 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15414 | mac_ptr += bytes_read; | |
15415 | ||
15416 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 15417 | comp_dir, lh, objfile); |
cf2c3c16 TT |
15418 | } |
15419 | break; | |
15420 | ||
15421 | case DW_MACRO_GNU_end_file: | |
15422 | /* No data to skip by MAC_PTR. */ | |
15423 | break; | |
15424 | ||
15425 | case DW_MACRO_GNU_define_indirect: | |
15426 | case DW_MACRO_GNU_undef_indirect: | |
15427 | { | |
15428 | unsigned int bytes_read; | |
15429 | ||
15430 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15431 | mac_ptr += bytes_read; | |
15432 | mac_ptr += offset_size; | |
15433 | } | |
15434 | break; | |
15435 | ||
15436 | case DW_MACRO_GNU_transparent_include: | |
15437 | /* Note that, according to the spec, a transparent include | |
15438 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
15439 | skip this opcode. */ | |
15440 | mac_ptr += offset_size; | |
15441 | break; | |
15442 | ||
15443 | case DW_MACINFO_vendor_ext: | |
15444 | /* Only skip the data by MAC_PTR. */ | |
15445 | if (!section_is_gnu) | |
15446 | { | |
15447 | unsigned int bytes_read; | |
15448 | ||
15449 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15450 | mac_ptr += bytes_read; | |
15451 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15452 | mac_ptr += bytes_read; | |
15453 | } | |
15454 | /* FALLTHROUGH */ | |
15455 | ||
15456 | default: | |
15457 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15458 | mac_ptr, abfd, offset_size, | |
15459 | section); | |
15460 | if (mac_ptr == NULL) | |
15461 | return; | |
15462 | break; | |
15463 | } | |
15464 | } while (macinfo_type != 0 && current_file == NULL); | |
15465 | ||
15466 | /* Second pass: Process all entries. | |
15467 | ||
15468 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
15469 | command-line macro definitions/undefinitions. This flag is unset when we | |
15470 | reach the first DW_MACINFO_start_file entry. */ | |
15471 | ||
15472 | dwarf_decode_macro_bytes (abfd, section->buffer + offset, mac_end, | |
15473 | current_file, lh, comp_dir, section, section_is_gnu, | |
bb5ed363 | 15474 | offset_size, objfile); |
cf2c3c16 TT |
15475 | } |
15476 | ||
8e19ed76 | 15477 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 15478 | if so return true else false. */ |
8e19ed76 PS |
15479 | static int |
15480 | attr_form_is_block (struct attribute *attr) | |
15481 | { | |
15482 | return (attr == NULL ? 0 : | |
15483 | attr->form == DW_FORM_block1 | |
15484 | || attr->form == DW_FORM_block2 | |
15485 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
15486 | || attr->form == DW_FORM_block |
15487 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 15488 | } |
4c2df51b | 15489 | |
c6a0999f JB |
15490 | /* Return non-zero if ATTR's value is a section offset --- classes |
15491 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
15492 | You may use DW_UNSND (attr) to retrieve such offsets. | |
15493 | ||
15494 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
15495 | may have a value that belongs to more than one of these classes; it | |
15496 | would be ambiguous if we did, because we use the same forms for all | |
15497 | of them. */ | |
3690dd37 JB |
15498 | static int |
15499 | attr_form_is_section_offset (struct attribute *attr) | |
15500 | { | |
15501 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
15502 | || attr->form == DW_FORM_data8 |
15503 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
15504 | } |
15505 | ||
15506 | ||
15507 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
15508 | zero otherwise. When this function returns true, you can apply | |
15509 | dwarf2_get_attr_constant_value to it. | |
15510 | ||
15511 | However, note that for some attributes you must check | |
15512 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
15513 | and DW_FORM_data8 are members of both the constant class, and of | |
15514 | the classes that contain offsets into other debug sections | |
15515 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
15516 | that, if an attribute's can be either a constant or one of the | |
15517 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
15518 | taken as section offsets, not constants. */ | |
15519 | static int | |
15520 | attr_form_is_constant (struct attribute *attr) | |
15521 | { | |
15522 | switch (attr->form) | |
15523 | { | |
15524 | case DW_FORM_sdata: | |
15525 | case DW_FORM_udata: | |
15526 | case DW_FORM_data1: | |
15527 | case DW_FORM_data2: | |
15528 | case DW_FORM_data4: | |
15529 | case DW_FORM_data8: | |
15530 | return 1; | |
15531 | default: | |
15532 | return 0; | |
15533 | } | |
15534 | } | |
15535 | ||
8cf6f0b1 TT |
15536 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
15537 | ||
15538 | static void | |
15539 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
15540 | struct dwarf2_loclist_baton *baton, | |
15541 | struct attribute *attr) | |
15542 | { | |
15543 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
15544 | &dwarf2_per_objfile->loc); | |
15545 | ||
15546 | baton->per_cu = cu->per_cu; | |
15547 | gdb_assert (baton->per_cu); | |
15548 | /* We don't know how long the location list is, but make sure we | |
15549 | don't run off the edge of the section. */ | |
15550 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
15551 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
15552 | baton->base_address = cu->base_address; | |
15553 | } | |
15554 | ||
4c2df51b DJ |
15555 | static void |
15556 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15557 | struct dwarf2_cu *cu) |
4c2df51b | 15558 | { |
bb5ed363 DE |
15559 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
15560 | ||
3690dd37 | 15561 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
15562 | /* ".debug_loc" may not exist at all, or the offset may be outside |
15563 | the section. If so, fall through to the complaint in the | |
15564 | other branch. */ | |
bb5ed363 | 15565 | && DW_UNSND (attr) < dwarf2_section_size (objfile, |
9e0ac564 | 15566 | &dwarf2_per_objfile->loc)) |
4c2df51b | 15567 | { |
0d53c4c4 | 15568 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 15569 | |
bb5ed363 | 15570 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15571 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 15572 | |
8cf6f0b1 | 15573 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 15574 | |
d00adf39 | 15575 | if (cu->base_known == 0) |
0d53c4c4 | 15576 | complaint (&symfile_complaints, |
3e43a32a MS |
15577 | _("Location list used without " |
15578 | "specifying the CU base address.")); | |
4c2df51b | 15579 | |
768a979c | 15580 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
15581 | SYMBOL_LOCATION_BATON (sym) = baton; |
15582 | } | |
15583 | else | |
15584 | { | |
15585 | struct dwarf2_locexpr_baton *baton; | |
15586 | ||
bb5ed363 | 15587 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15588 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
15589 | baton->per_cu = cu->per_cu; |
15590 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
15591 | |
15592 | if (attr_form_is_block (attr)) | |
15593 | { | |
15594 | /* Note that we're just copying the block's data pointer | |
15595 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
15596 | info_buffer for SYM's objfile; right now we never release |
15597 | that buffer, but when we do clean up properly this may | |
15598 | need to change. */ | |
0d53c4c4 DJ |
15599 | baton->size = DW_BLOCK (attr)->size; |
15600 | baton->data = DW_BLOCK (attr)->data; | |
15601 | } | |
15602 | else | |
15603 | { | |
15604 | dwarf2_invalid_attrib_class_complaint ("location description", | |
15605 | SYMBOL_NATURAL_NAME (sym)); | |
15606 | baton->size = 0; | |
0d53c4c4 | 15607 | } |
6e70227d | 15608 | |
768a979c | 15609 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
15610 | SYMBOL_LOCATION_BATON (sym) = baton; |
15611 | } | |
4c2df51b | 15612 | } |
6502dd73 | 15613 | |
9aa1f1e3 TT |
15614 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
15615 | came from a separate debuginfo file, then the master objfile is | |
15616 | returned. */ | |
ae0d2f24 UW |
15617 | |
15618 | struct objfile * | |
15619 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
15620 | { | |
9291a0cd | 15621 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
15622 | |
15623 | /* Return the master objfile, so that we can report and look up the | |
15624 | correct file containing this variable. */ | |
15625 | if (objfile->separate_debug_objfile_backlink) | |
15626 | objfile = objfile->separate_debug_objfile_backlink; | |
15627 | ||
15628 | return objfile; | |
15629 | } | |
15630 | ||
96408a79 SA |
15631 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
15632 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
15633 | CU_HEADERP first. */ | |
15634 | ||
15635 | static const struct comp_unit_head * | |
15636 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
15637 | struct dwarf2_per_cu_data *per_cu) | |
15638 | { | |
15639 | struct objfile *objfile; | |
15640 | struct dwarf2_per_objfile *per_objfile; | |
15641 | gdb_byte *info_ptr; | |
15642 | ||
15643 | if (per_cu->cu) | |
15644 | return &per_cu->cu->header; | |
15645 | ||
15646 | objfile = per_cu->objfile; | |
15647 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15648 | info_ptr = per_objfile->info.buffer + per_cu->offset; | |
15649 | ||
15650 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
15651 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
15652 | ||
15653 | return cu_headerp; | |
15654 | } | |
15655 | ||
ae0d2f24 UW |
15656 | /* Return the address size given in the compilation unit header for CU. */ |
15657 | ||
98714339 | 15658 | int |
ae0d2f24 UW |
15659 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
15660 | { | |
96408a79 SA |
15661 | struct comp_unit_head cu_header_local; |
15662 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 15663 | |
96408a79 SA |
15664 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15665 | ||
15666 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
15667 | } |
15668 | ||
9eae7c52 TT |
15669 | /* Return the offset size given in the compilation unit header for CU. */ |
15670 | ||
15671 | int | |
15672 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
15673 | { | |
96408a79 SA |
15674 | struct comp_unit_head cu_header_local; |
15675 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 15676 | |
96408a79 SA |
15677 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
15678 | ||
15679 | return cu_headerp->offset_size; | |
15680 | } | |
15681 | ||
15682 | /* See its dwarf2loc.h declaration. */ | |
15683 | ||
15684 | int | |
15685 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
15686 | { | |
15687 | struct comp_unit_head cu_header_local; | |
15688 | const struct comp_unit_head *cu_headerp; | |
15689 | ||
15690 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
15691 | ||
15692 | if (cu_headerp->version == 2) | |
15693 | return cu_headerp->addr_size; | |
15694 | else | |
15695 | return cu_headerp->offset_size; | |
181cebd4 JK |
15696 | } |
15697 | ||
9aa1f1e3 TT |
15698 | /* Return the text offset of the CU. The returned offset comes from |
15699 | this CU's objfile. If this objfile came from a separate debuginfo | |
15700 | file, then the offset may be different from the corresponding | |
15701 | offset in the parent objfile. */ | |
15702 | ||
15703 | CORE_ADDR | |
15704 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
15705 | { | |
bb3fa9d0 | 15706 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
15707 | |
15708 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15709 | } | |
15710 | ||
348e048f DE |
15711 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
15712 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
15713 | |
15714 | static struct dwarf2_per_cu_data * | |
c764a876 | 15715 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
15716 | struct objfile *objfile) |
15717 | { | |
15718 | struct dwarf2_per_cu_data *this_cu; | |
15719 | int low, high; | |
15720 | ||
ae038cb0 DJ |
15721 | low = 0; |
15722 | high = dwarf2_per_objfile->n_comp_units - 1; | |
15723 | while (high > low) | |
15724 | { | |
15725 | int mid = low + (high - low) / 2; | |
9a619af0 | 15726 | |
ae038cb0 DJ |
15727 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
15728 | high = mid; | |
15729 | else | |
15730 | low = mid + 1; | |
15731 | } | |
15732 | gdb_assert (low == high); | |
15733 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
15734 | { | |
10b3939b | 15735 | if (low == 0) |
8a3fe4f8 AC |
15736 | error (_("Dwarf Error: could not find partial DIE containing " |
15737 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
15738 | (long) offset, bfd_get_filename (objfile->obfd)); |
15739 | ||
ae038cb0 DJ |
15740 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
15741 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
15742 | } | |
15743 | else | |
15744 | { | |
15745 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
15746 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
15747 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 15748 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
15749 | gdb_assert (offset < this_cu->offset + this_cu->length); |
15750 | return this_cu; | |
15751 | } | |
15752 | } | |
15753 | ||
23745b47 | 15754 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 15755 | |
9816fde3 | 15756 | static void |
23745b47 | 15757 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 15758 | { |
9816fde3 | 15759 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
15760 | per_cu->cu = cu; |
15761 | cu->per_cu = per_cu; | |
15762 | cu->objfile = per_cu->objfile; | |
93311388 | 15763 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
15764 | } |
15765 | ||
15766 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
15767 | ||
15768 | static void | |
15769 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
15770 | { | |
15771 | struct attribute *attr; | |
15772 | ||
15773 | /* Set the language we're debugging. */ | |
15774 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
15775 | if (attr) | |
15776 | set_cu_language (DW_UNSND (attr), cu); | |
15777 | else | |
9cded63f TT |
15778 | { |
15779 | cu->language = language_minimal; | |
15780 | cu->language_defn = language_def (cu->language); | |
15781 | } | |
93311388 DE |
15782 | } |
15783 | ||
ae038cb0 DJ |
15784 | /* Release one cached compilation unit, CU. We unlink it from the tree |
15785 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
15786 | the caller is responsible for that. |
15787 | NOTE: DATA is a void * because this function is also used as a | |
15788 | cleanup routine. */ | |
ae038cb0 DJ |
15789 | |
15790 | static void | |
68dc6402 | 15791 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
15792 | { |
15793 | struct dwarf2_cu *cu = data; | |
15794 | ||
23745b47 DE |
15795 | gdb_assert (cu->per_cu != NULL); |
15796 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
15797 | cu->per_cu = NULL; |
15798 | ||
15799 | obstack_free (&cu->comp_unit_obstack, NULL); | |
15800 | ||
15801 | xfree (cu); | |
15802 | } | |
15803 | ||
72bf9492 | 15804 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
15805 | when we're finished with it. We can't free the pointer itself, but be |
15806 | sure to unlink it from the cache. Also release any associated storage | |
15807 | and perform cache maintenance. | |
72bf9492 DJ |
15808 | |
15809 | Only used during partial symbol parsing. */ | |
15810 | ||
15811 | static void | |
15812 | free_stack_comp_unit (void *data) | |
15813 | { | |
15814 | struct dwarf2_cu *cu = data; | |
15815 | ||
23745b47 DE |
15816 | gdb_assert (cu->per_cu != NULL); |
15817 | cu->per_cu->cu = NULL; | |
15818 | cu->per_cu = NULL; | |
15819 | ||
72bf9492 DJ |
15820 | obstack_free (&cu->comp_unit_obstack, NULL); |
15821 | cu->partial_dies = NULL; | |
ae038cb0 | 15822 | |
23745b47 DE |
15823 | /* The previous code only did this if per_cu != NULL. |
15824 | But that would always succeed, so now we just unconditionally do | |
15825 | the aging. This seems like the wrong place to do such aging, | |
15826 | but cleaning that up is left for later. */ | |
15827 | age_cached_comp_units (); | |
ae038cb0 DJ |
15828 | } |
15829 | ||
15830 | /* Free all cached compilation units. */ | |
15831 | ||
15832 | static void | |
15833 | free_cached_comp_units (void *data) | |
15834 | { | |
15835 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15836 | ||
15837 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15838 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15839 | while (per_cu != NULL) | |
15840 | { | |
15841 | struct dwarf2_per_cu_data *next_cu; | |
15842 | ||
15843 | next_cu = per_cu->cu->read_in_chain; | |
15844 | ||
68dc6402 | 15845 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15846 | *last_chain = next_cu; |
15847 | ||
15848 | per_cu = next_cu; | |
15849 | } | |
15850 | } | |
15851 | ||
15852 | /* Increase the age counter on each cached compilation unit, and free | |
15853 | any that are too old. */ | |
15854 | ||
15855 | static void | |
15856 | age_cached_comp_units (void) | |
15857 | { | |
15858 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15859 | ||
15860 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
15861 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15862 | while (per_cu != NULL) | |
15863 | { | |
15864 | per_cu->cu->last_used ++; | |
15865 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
15866 | dwarf2_mark (per_cu->cu); | |
15867 | per_cu = per_cu->cu->read_in_chain; | |
15868 | } | |
15869 | ||
15870 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15871 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15872 | while (per_cu != NULL) | |
15873 | { | |
15874 | struct dwarf2_per_cu_data *next_cu; | |
15875 | ||
15876 | next_cu = per_cu->cu->read_in_chain; | |
15877 | ||
15878 | if (!per_cu->cu->mark) | |
15879 | { | |
68dc6402 | 15880 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15881 | *last_chain = next_cu; |
15882 | } | |
15883 | else | |
15884 | last_chain = &per_cu->cu->read_in_chain; | |
15885 | ||
15886 | per_cu = next_cu; | |
15887 | } | |
15888 | } | |
15889 | ||
15890 | /* Remove a single compilation unit from the cache. */ | |
15891 | ||
15892 | static void | |
15893 | free_one_cached_comp_unit (void *target_cu) | |
15894 | { | |
15895 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
15896 | ||
15897 | per_cu = dwarf2_per_objfile->read_in_chain; | |
15898 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
15899 | while (per_cu != NULL) | |
15900 | { | |
15901 | struct dwarf2_per_cu_data *next_cu; | |
15902 | ||
15903 | next_cu = per_cu->cu->read_in_chain; | |
15904 | ||
15905 | if (per_cu->cu == target_cu) | |
15906 | { | |
68dc6402 | 15907 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
15908 | *last_chain = next_cu; |
15909 | break; | |
15910 | } | |
15911 | else | |
15912 | last_chain = &per_cu->cu->read_in_chain; | |
15913 | ||
15914 | per_cu = next_cu; | |
15915 | } | |
15916 | } | |
15917 | ||
fe3e1990 DJ |
15918 | /* Release all extra memory associated with OBJFILE. */ |
15919 | ||
15920 | void | |
15921 | dwarf2_free_objfile (struct objfile *objfile) | |
15922 | { | |
15923 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15924 | ||
15925 | if (dwarf2_per_objfile == NULL) | |
15926 | return; | |
15927 | ||
15928 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
15929 | free_cached_comp_units (NULL); | |
15930 | ||
7b9f3c50 DE |
15931 | if (dwarf2_per_objfile->quick_file_names_table) |
15932 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 15933 | |
fe3e1990 DJ |
15934 | /* Everything else should be on the objfile obstack. */ |
15935 | } | |
15936 | ||
1c379e20 DJ |
15937 | /* A pair of DIE offset and GDB type pointer. We store these |
15938 | in a hash table separate from the DIEs, and preserve them | |
15939 | when the DIEs are flushed out of cache. */ | |
15940 | ||
15941 | struct dwarf2_offset_and_type | |
15942 | { | |
15943 | unsigned int offset; | |
15944 | struct type *type; | |
15945 | }; | |
15946 | ||
15947 | /* Hash function for a dwarf2_offset_and_type. */ | |
15948 | ||
15949 | static hashval_t | |
15950 | offset_and_type_hash (const void *item) | |
15951 | { | |
15952 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 15953 | |
1c379e20 DJ |
15954 | return ofs->offset; |
15955 | } | |
15956 | ||
15957 | /* Equality function for a dwarf2_offset_and_type. */ | |
15958 | ||
15959 | static int | |
15960 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
15961 | { | |
15962 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
15963 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 15964 | |
1c379e20 DJ |
15965 | return ofs_lhs->offset == ofs_rhs->offset; |
15966 | } | |
15967 | ||
15968 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
15969 | table if necessary. For convenience, return TYPE. |
15970 | ||
15971 | The DIEs reading must have careful ordering to: | |
15972 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
15973 | reading current DIE. | |
15974 | * Not trying to dereference contents of still incompletely read in types | |
15975 | while reading in other DIEs. | |
15976 | * Enable referencing still incompletely read in types just by a pointer to | |
15977 | the type without accessing its fields. | |
15978 | ||
15979 | Therefore caller should follow these rules: | |
15980 | * Try to fetch any prerequisite types we may need to build this DIE type | |
15981 | before building the type and calling set_die_type. | |
e71ec853 | 15982 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
15983 | possible before fetching more types to complete the current type. |
15984 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 15985 | |
f792889a | 15986 | static struct type * |
1c379e20 DJ |
15987 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
15988 | { | |
15989 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
15990 | struct objfile *objfile = cu->objfile; |
15991 | htab_t *type_hash_ptr; | |
1c379e20 | 15992 | |
b4ba55a1 JB |
15993 | /* For Ada types, make sure that the gnat-specific data is always |
15994 | initialized (if not already set). There are a few types where | |
15995 | we should not be doing so, because the type-specific area is | |
15996 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
15997 | where the type-specific area is used to store the floatformat). | |
15998 | But this is not a problem, because the gnat-specific information | |
15999 | is actually not needed for these types. */ | |
16000 | if (need_gnat_info (cu) | |
16001 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
16002 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
16003 | && !HAVE_GNAT_AUX_INFO (type)) | |
16004 | INIT_GNAT_SPECIFIC (type); | |
16005 | ||
b0df02fd | 16006 | if (cu->per_cu->debug_types_section) |
673bfd45 DE |
16007 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
16008 | else | |
16009 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
16010 | ||
16011 | if (*type_hash_ptr == NULL) | |
f792889a | 16012 | { |
673bfd45 DE |
16013 | *type_hash_ptr |
16014 | = htab_create_alloc_ex (127, | |
f792889a DJ |
16015 | offset_and_type_hash, |
16016 | offset_and_type_eq, | |
16017 | NULL, | |
673bfd45 | 16018 | &objfile->objfile_obstack, |
f792889a DJ |
16019 | hashtab_obstack_allocate, |
16020 | dummy_obstack_deallocate); | |
f792889a | 16021 | } |
1c379e20 DJ |
16022 | |
16023 | ofs.offset = die->offset; | |
16024 | ofs.type = type; | |
16025 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 16026 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
16027 | if (*slot) |
16028 | complaint (&symfile_complaints, | |
16029 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
16030 | die->offset); | |
673bfd45 | 16031 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 16032 | **slot = ofs; |
f792889a | 16033 | return type; |
1c379e20 DJ |
16034 | } |
16035 | ||
673bfd45 DE |
16036 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
16037 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
16038 | |
16039 | static struct type * | |
673bfd45 DE |
16040 | get_die_type_at_offset (unsigned int offset, |
16041 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
16042 | { |
16043 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 16044 | htab_t type_hash; |
f792889a | 16045 | |
b0df02fd | 16046 | if (per_cu->debug_types_section) |
673bfd45 DE |
16047 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
16048 | else | |
16049 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
16050 | if (type_hash == NULL) |
16051 | return NULL; | |
1c379e20 | 16052 | |
673bfd45 | 16053 | ofs.offset = offset; |
1c379e20 DJ |
16054 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
16055 | if (slot) | |
16056 | return slot->type; | |
16057 | else | |
16058 | return NULL; | |
16059 | } | |
16060 | ||
673bfd45 DE |
16061 | /* Look up the type for DIE in the appropriate type_hash table, |
16062 | or return NULL if DIE does not have a saved type. */ | |
16063 | ||
16064 | static struct type * | |
16065 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
16066 | { | |
16067 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
16068 | } | |
16069 | ||
10b3939b DJ |
16070 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
16071 | ||
16072 | static void | |
16073 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
16074 | struct dwarf2_per_cu_data *ref_per_cu) | |
16075 | { | |
16076 | void **slot; | |
16077 | ||
16078 | if (cu->dependencies == NULL) | |
16079 | cu->dependencies | |
16080 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
16081 | NULL, &cu->comp_unit_obstack, | |
16082 | hashtab_obstack_allocate, | |
16083 | dummy_obstack_deallocate); | |
16084 | ||
16085 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
16086 | if (*slot == NULL) | |
16087 | *slot = ref_per_cu; | |
16088 | } | |
1c379e20 | 16089 | |
f504f079 DE |
16090 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
16091 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
16092 | cache that we must keep because we are keeping CU. */ |
16093 | ||
10b3939b DJ |
16094 | static int |
16095 | dwarf2_mark_helper (void **slot, void *data) | |
16096 | { | |
16097 | struct dwarf2_per_cu_data *per_cu; | |
16098 | ||
16099 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
16100 | |
16101 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
16102 | reading of the chain. As such dependencies remain valid it is not much | |
16103 | useful to track and undo them during QUIT cleanups. */ | |
16104 | if (per_cu->cu == NULL) | |
16105 | return 1; | |
16106 | ||
10b3939b DJ |
16107 | if (per_cu->cu->mark) |
16108 | return 1; | |
16109 | per_cu->cu->mark = 1; | |
16110 | ||
16111 | if (per_cu->cu->dependencies != NULL) | |
16112 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
16113 | ||
16114 | return 1; | |
16115 | } | |
16116 | ||
f504f079 DE |
16117 | /* Set the mark field in CU and in every other compilation unit in the |
16118 | cache that we must keep because we are keeping CU. */ | |
16119 | ||
ae038cb0 DJ |
16120 | static void |
16121 | dwarf2_mark (struct dwarf2_cu *cu) | |
16122 | { | |
16123 | if (cu->mark) | |
16124 | return; | |
16125 | cu->mark = 1; | |
10b3939b DJ |
16126 | if (cu->dependencies != NULL) |
16127 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
16128 | } |
16129 | ||
16130 | static void | |
16131 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
16132 | { | |
16133 | while (per_cu) | |
16134 | { | |
16135 | per_cu->cu->mark = 0; | |
16136 | per_cu = per_cu->cu->read_in_chain; | |
16137 | } | |
72bf9492 DJ |
16138 | } |
16139 | ||
72bf9492 DJ |
16140 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
16141 | is its offset in .debug_info for this objfile. */ | |
16142 | ||
16143 | static hashval_t | |
16144 | partial_die_hash (const void *item) | |
16145 | { | |
16146 | const struct partial_die_info *part_die = item; | |
9a619af0 | 16147 | |
72bf9492 DJ |
16148 | return part_die->offset; |
16149 | } | |
16150 | ||
16151 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
16152 | are equal if they have the same offset. */ | |
16153 | ||
16154 | static int | |
16155 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
16156 | { | |
16157 | const struct partial_die_info *part_die_lhs = item_lhs; | |
16158 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 16159 | |
72bf9492 DJ |
16160 | return part_die_lhs->offset == part_die_rhs->offset; |
16161 | } | |
16162 | ||
ae038cb0 DJ |
16163 | static struct cmd_list_element *set_dwarf2_cmdlist; |
16164 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
16165 | ||
16166 | static void | |
16167 | set_dwarf2_cmd (char *args, int from_tty) | |
16168 | { | |
16169 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
16170 | } | |
16171 | ||
16172 | static void | |
16173 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 16174 | { |
ae038cb0 DJ |
16175 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
16176 | } | |
16177 | ||
dce234bc PP |
16178 | /* If section described by INFO was mmapped, munmap it now. */ |
16179 | ||
16180 | static void | |
16181 | munmap_section_buffer (struct dwarf2_section_info *info) | |
16182 | { | |
b315ab21 | 16183 | if (info->map_addr != NULL) |
dce234bc PP |
16184 | { |
16185 | #ifdef HAVE_MMAP | |
b315ab21 | 16186 | int res; |
9a619af0 | 16187 | |
b315ab21 TG |
16188 | res = munmap (info->map_addr, info->map_len); |
16189 | gdb_assert (res == 0); | |
dce234bc PP |
16190 | #else |
16191 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 16192 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
16193 | #endif |
16194 | } | |
16195 | } | |
16196 | ||
16197 | /* munmap debug sections for OBJFILE, if necessary. */ | |
16198 | ||
16199 | static void | |
c1bd65d0 | 16200 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
16201 | { |
16202 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
16203 | int ix; |
16204 | struct dwarf2_section_info *section; | |
9a619af0 | 16205 | |
16be1145 DE |
16206 | /* This is sorted according to the order they're defined in to make it easier |
16207 | to keep in sync. */ | |
dce234bc PP |
16208 | munmap_section_buffer (&data->info); |
16209 | munmap_section_buffer (&data->abbrev); | |
16210 | munmap_section_buffer (&data->line); | |
16be1145 | 16211 | munmap_section_buffer (&data->loc); |
dce234bc | 16212 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 16213 | munmap_section_buffer (&data->macro); |
16be1145 | 16214 | munmap_section_buffer (&data->str); |
dce234bc | 16215 | munmap_section_buffer (&data->ranges); |
dce234bc PP |
16216 | munmap_section_buffer (&data->frame); |
16217 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 16218 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
16219 | |
16220 | for (ix = 0; | |
16221 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
16222 | ++ix) | |
16223 | munmap_section_buffer (section); | |
16224 | ||
16225 | VEC_free (dwarf2_section_info_def, data->types); | |
9291a0cd TT |
16226 | } |
16227 | ||
16228 | \f | |
ae2de4f8 | 16229 | /* The "save gdb-index" command. */ |
9291a0cd TT |
16230 | |
16231 | /* The contents of the hash table we create when building the string | |
16232 | table. */ | |
16233 | struct strtab_entry | |
16234 | { | |
16235 | offset_type offset; | |
16236 | const char *str; | |
16237 | }; | |
16238 | ||
559a7a62 JK |
16239 | /* Hash function for a strtab_entry. |
16240 | ||
16241 | Function is used only during write_hash_table so no index format backward | |
16242 | compatibility is needed. */ | |
b89be57b | 16243 | |
9291a0cd TT |
16244 | static hashval_t |
16245 | hash_strtab_entry (const void *e) | |
16246 | { | |
16247 | const struct strtab_entry *entry = e; | |
559a7a62 | 16248 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
16249 | } |
16250 | ||
16251 | /* Equality function for a strtab_entry. */ | |
b89be57b | 16252 | |
9291a0cd TT |
16253 | static int |
16254 | eq_strtab_entry (const void *a, const void *b) | |
16255 | { | |
16256 | const struct strtab_entry *ea = a; | |
16257 | const struct strtab_entry *eb = b; | |
16258 | return !strcmp (ea->str, eb->str); | |
16259 | } | |
16260 | ||
16261 | /* Create a strtab_entry hash table. */ | |
b89be57b | 16262 | |
9291a0cd TT |
16263 | static htab_t |
16264 | create_strtab (void) | |
16265 | { | |
16266 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
16267 | xfree, xcalloc, xfree); | |
16268 | } | |
16269 | ||
16270 | /* Add a string to the constant pool. Return the string's offset in | |
16271 | host order. */ | |
b89be57b | 16272 | |
9291a0cd TT |
16273 | static offset_type |
16274 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
16275 | { | |
16276 | void **slot; | |
16277 | struct strtab_entry entry; | |
16278 | struct strtab_entry *result; | |
16279 | ||
16280 | entry.str = str; | |
16281 | slot = htab_find_slot (table, &entry, INSERT); | |
16282 | if (*slot) | |
16283 | result = *slot; | |
16284 | else | |
16285 | { | |
16286 | result = XNEW (struct strtab_entry); | |
16287 | result->offset = obstack_object_size (cpool); | |
16288 | result->str = str; | |
16289 | obstack_grow_str0 (cpool, str); | |
16290 | *slot = result; | |
16291 | } | |
16292 | return result->offset; | |
16293 | } | |
16294 | ||
16295 | /* An entry in the symbol table. */ | |
16296 | struct symtab_index_entry | |
16297 | { | |
16298 | /* The name of the symbol. */ | |
16299 | const char *name; | |
16300 | /* The offset of the name in the constant pool. */ | |
16301 | offset_type index_offset; | |
16302 | /* A sorted vector of the indices of all the CUs that hold an object | |
16303 | of this name. */ | |
16304 | VEC (offset_type) *cu_indices; | |
16305 | }; | |
16306 | ||
16307 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
16308 | struct mapped_symtab | |
16309 | { | |
16310 | offset_type n_elements; | |
16311 | offset_type size; | |
16312 | struct symtab_index_entry **data; | |
16313 | }; | |
16314 | ||
16315 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 16316 | |
9291a0cd TT |
16317 | static hashval_t |
16318 | hash_symtab_entry (const void *e) | |
16319 | { | |
16320 | const struct symtab_index_entry *entry = e; | |
16321 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
16322 | sizeof (offset_type) * VEC_length (offset_type, | |
16323 | entry->cu_indices), | |
16324 | 0); | |
16325 | } | |
16326 | ||
16327 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 16328 | |
9291a0cd TT |
16329 | static int |
16330 | eq_symtab_entry (const void *a, const void *b) | |
16331 | { | |
16332 | const struct symtab_index_entry *ea = a; | |
16333 | const struct symtab_index_entry *eb = b; | |
16334 | int len = VEC_length (offset_type, ea->cu_indices); | |
16335 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
16336 | return 0; | |
16337 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
16338 | VEC_address (offset_type, eb->cu_indices), | |
16339 | sizeof (offset_type) * len); | |
16340 | } | |
16341 | ||
16342 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 16343 | |
9291a0cd TT |
16344 | static void |
16345 | delete_symtab_entry (void *p) | |
16346 | { | |
16347 | struct symtab_index_entry *entry = p; | |
16348 | VEC_free (offset_type, entry->cu_indices); | |
16349 | xfree (entry); | |
16350 | } | |
16351 | ||
16352 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 16353 | |
9291a0cd | 16354 | static htab_t |
3876f04e | 16355 | create_symbol_hash_table (void) |
9291a0cd TT |
16356 | { |
16357 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
16358 | delete_symtab_entry, xcalloc, xfree); | |
16359 | } | |
16360 | ||
16361 | /* Create a new mapped symtab object. */ | |
b89be57b | 16362 | |
9291a0cd TT |
16363 | static struct mapped_symtab * |
16364 | create_mapped_symtab (void) | |
16365 | { | |
16366 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
16367 | symtab->n_elements = 0; | |
16368 | symtab->size = 1024; | |
16369 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16370 | return symtab; | |
16371 | } | |
16372 | ||
16373 | /* Destroy a mapped_symtab. */ | |
b89be57b | 16374 | |
9291a0cd TT |
16375 | static void |
16376 | cleanup_mapped_symtab (void *p) | |
16377 | { | |
16378 | struct mapped_symtab *symtab = p; | |
16379 | /* The contents of the array are freed when the other hash table is | |
16380 | destroyed. */ | |
16381 | xfree (symtab->data); | |
16382 | xfree (symtab); | |
16383 | } | |
16384 | ||
16385 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
16386 | the slot. |
16387 | ||
16388 | Function is used only during write_hash_table so no index format backward | |
16389 | compatibility is needed. */ | |
b89be57b | 16390 | |
9291a0cd TT |
16391 | static struct symtab_index_entry ** |
16392 | find_slot (struct mapped_symtab *symtab, const char *name) | |
16393 | { | |
559a7a62 | 16394 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
16395 | |
16396 | index = hash & (symtab->size - 1); | |
16397 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
16398 | ||
16399 | for (;;) | |
16400 | { | |
16401 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
16402 | return &symtab->data[index]; | |
16403 | index = (index + step) & (symtab->size - 1); | |
16404 | } | |
16405 | } | |
16406 | ||
16407 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 16408 | |
9291a0cd TT |
16409 | static void |
16410 | hash_expand (struct mapped_symtab *symtab) | |
16411 | { | |
16412 | offset_type old_size = symtab->size; | |
16413 | offset_type i; | |
16414 | struct symtab_index_entry **old_entries = symtab->data; | |
16415 | ||
16416 | symtab->size *= 2; | |
16417 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16418 | ||
16419 | for (i = 0; i < old_size; ++i) | |
16420 | { | |
16421 | if (old_entries[i]) | |
16422 | { | |
16423 | struct symtab_index_entry **slot = find_slot (symtab, | |
16424 | old_entries[i]->name); | |
16425 | *slot = old_entries[i]; | |
16426 | } | |
16427 | } | |
16428 | ||
16429 | xfree (old_entries); | |
16430 | } | |
16431 | ||
16432 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
16433 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 16434 | |
9291a0cd TT |
16435 | static void |
16436 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
16437 | offset_type cu_index) | |
16438 | { | |
16439 | struct symtab_index_entry **slot; | |
16440 | ||
16441 | ++symtab->n_elements; | |
16442 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
16443 | hash_expand (symtab); | |
16444 | ||
16445 | slot = find_slot (symtab, name); | |
16446 | if (!*slot) | |
16447 | { | |
16448 | *slot = XNEW (struct symtab_index_entry); | |
16449 | (*slot)->name = name; | |
16450 | (*slot)->cu_indices = NULL; | |
16451 | } | |
16452 | /* Don't push an index twice. Due to how we add entries we only | |
16453 | have to check the last one. */ | |
16454 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 16455 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
16456 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
16457 | } | |
16458 | ||
16459 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 16460 | |
9291a0cd | 16461 | static offset_type |
3876f04e | 16462 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
16463 | struct symtab_index_entry *entry) |
16464 | { | |
16465 | void **slot; | |
16466 | ||
3876f04e | 16467 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
16468 | if (!*slot) |
16469 | { | |
16470 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
16471 | offset_type val = MAYBE_SWAP (len); | |
16472 | offset_type iter; | |
16473 | int i; | |
16474 | ||
16475 | *slot = entry; | |
16476 | entry->index_offset = obstack_object_size (cpool); | |
16477 | ||
16478 | obstack_grow (cpool, &val, sizeof (val)); | |
16479 | for (i = 0; | |
16480 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
16481 | ++i) | |
16482 | { | |
16483 | val = MAYBE_SWAP (iter); | |
16484 | obstack_grow (cpool, &val, sizeof (val)); | |
16485 | } | |
16486 | } | |
16487 | else | |
16488 | { | |
16489 | struct symtab_index_entry *old_entry = *slot; | |
16490 | entry->index_offset = old_entry->index_offset; | |
16491 | entry = old_entry; | |
16492 | } | |
16493 | return entry->index_offset; | |
16494 | } | |
16495 | ||
16496 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
16497 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 16498 | |
9291a0cd TT |
16499 | static void |
16500 | write_hash_table (struct mapped_symtab *symtab, | |
16501 | struct obstack *output, struct obstack *cpool) | |
16502 | { | |
16503 | offset_type i; | |
3876f04e | 16504 | htab_t symbol_hash_table; |
9291a0cd TT |
16505 | htab_t str_table; |
16506 | ||
3876f04e | 16507 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 16508 | str_table = create_strtab (); |
3876f04e | 16509 | |
9291a0cd TT |
16510 | /* We add all the index vectors to the constant pool first, to |
16511 | ensure alignment is ok. */ | |
16512 | for (i = 0; i < symtab->size; ++i) | |
16513 | { | |
16514 | if (symtab->data[i]) | |
3876f04e | 16515 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
16516 | } |
16517 | ||
16518 | /* Now write out the hash table. */ | |
16519 | for (i = 0; i < symtab->size; ++i) | |
16520 | { | |
16521 | offset_type str_off, vec_off; | |
16522 | ||
16523 | if (symtab->data[i]) | |
16524 | { | |
16525 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
16526 | vec_off = symtab->data[i]->index_offset; | |
16527 | } | |
16528 | else | |
16529 | { | |
16530 | /* While 0 is a valid constant pool index, it is not valid | |
16531 | to have 0 for both offsets. */ | |
16532 | str_off = 0; | |
16533 | vec_off = 0; | |
16534 | } | |
16535 | ||
16536 | str_off = MAYBE_SWAP (str_off); | |
16537 | vec_off = MAYBE_SWAP (vec_off); | |
16538 | ||
16539 | obstack_grow (output, &str_off, sizeof (str_off)); | |
16540 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
16541 | } | |
16542 | ||
16543 | htab_delete (str_table); | |
3876f04e | 16544 | htab_delete (symbol_hash_table); |
9291a0cd TT |
16545 | } |
16546 | ||
0a5429f6 DE |
16547 | /* Struct to map psymtab to CU index in the index file. */ |
16548 | struct psymtab_cu_index_map | |
16549 | { | |
16550 | struct partial_symtab *psymtab; | |
16551 | unsigned int cu_index; | |
16552 | }; | |
16553 | ||
16554 | static hashval_t | |
16555 | hash_psymtab_cu_index (const void *item) | |
16556 | { | |
16557 | const struct psymtab_cu_index_map *map = item; | |
16558 | ||
16559 | return htab_hash_pointer (map->psymtab); | |
16560 | } | |
16561 | ||
16562 | static int | |
16563 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
16564 | { | |
16565 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
16566 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
16567 | ||
16568 | return lhs->psymtab == rhs->psymtab; | |
16569 | } | |
16570 | ||
16571 | /* Helper struct for building the address table. */ | |
16572 | struct addrmap_index_data | |
16573 | { | |
16574 | struct objfile *objfile; | |
16575 | struct obstack *addr_obstack; | |
16576 | htab_t cu_index_htab; | |
16577 | ||
16578 | /* Non-zero if the previous_* fields are valid. | |
16579 | We can't write an entry until we see the next entry (since it is only then | |
16580 | that we know the end of the entry). */ | |
16581 | int previous_valid; | |
16582 | /* Index of the CU in the table of all CUs in the index file. */ | |
16583 | unsigned int previous_cu_index; | |
0963b4bd | 16584 | /* Start address of the CU. */ |
0a5429f6 DE |
16585 | CORE_ADDR previous_cu_start; |
16586 | }; | |
16587 | ||
16588 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 16589 | |
9291a0cd | 16590 | static void |
0a5429f6 DE |
16591 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
16592 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 16593 | { |
0a5429f6 | 16594 | offset_type cu_index_to_write; |
9291a0cd TT |
16595 | char addr[8]; |
16596 | CORE_ADDR baseaddr; | |
16597 | ||
16598 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16599 | ||
0a5429f6 DE |
16600 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
16601 | obstack_grow (obstack, addr, 8); | |
16602 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
16603 | obstack_grow (obstack, addr, 8); | |
16604 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
16605 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
16606 | } | |
16607 | ||
16608 | /* Worker function for traversing an addrmap to build the address table. */ | |
16609 | ||
16610 | static int | |
16611 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
16612 | { | |
16613 | struct addrmap_index_data *data = datap; | |
16614 | struct partial_symtab *pst = obj; | |
16615 | offset_type cu_index; | |
16616 | void **slot; | |
16617 | ||
16618 | if (data->previous_valid) | |
16619 | add_address_entry (data->objfile, data->addr_obstack, | |
16620 | data->previous_cu_start, start_addr, | |
16621 | data->previous_cu_index); | |
16622 | ||
16623 | data->previous_cu_start = start_addr; | |
16624 | if (pst != NULL) | |
16625 | { | |
16626 | struct psymtab_cu_index_map find_map, *map; | |
16627 | find_map.psymtab = pst; | |
16628 | map = htab_find (data->cu_index_htab, &find_map); | |
16629 | gdb_assert (map != NULL); | |
16630 | data->previous_cu_index = map->cu_index; | |
16631 | data->previous_valid = 1; | |
16632 | } | |
16633 | else | |
16634 | data->previous_valid = 0; | |
16635 | ||
16636 | return 0; | |
16637 | } | |
16638 | ||
16639 | /* Write OBJFILE's address map to OBSTACK. | |
16640 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
16641 | in the index file. */ | |
16642 | ||
16643 | static void | |
16644 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
16645 | htab_t cu_index_htab) | |
16646 | { | |
16647 | struct addrmap_index_data addrmap_index_data; | |
16648 | ||
16649 | /* When writing the address table, we have to cope with the fact that | |
16650 | the addrmap iterator only provides the start of a region; we have to | |
16651 | wait until the next invocation to get the start of the next region. */ | |
16652 | ||
16653 | addrmap_index_data.objfile = objfile; | |
16654 | addrmap_index_data.addr_obstack = obstack; | |
16655 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
16656 | addrmap_index_data.previous_valid = 0; | |
16657 | ||
16658 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
16659 | &addrmap_index_data); | |
16660 | ||
16661 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
16662 | is valid, but we should still handle it. | |
16663 | The end address is recorded as the start of the next region, but that | |
16664 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
16665 | anyway. */ | |
16666 | if (addrmap_index_data.previous_valid) | |
16667 | add_address_entry (objfile, obstack, | |
16668 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
16669 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
16670 | } |
16671 | ||
16672 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 16673 | |
9291a0cd TT |
16674 | static void |
16675 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 16676 | htab_t psyms_seen, |
9291a0cd TT |
16677 | struct partial_symbol **psymp, |
16678 | int count, | |
987d643c TT |
16679 | offset_type cu_index, |
16680 | int is_static) | |
9291a0cd TT |
16681 | { |
16682 | for (; count-- > 0; ++psymp) | |
16683 | { | |
987d643c TT |
16684 | void **slot, *lookup; |
16685 | ||
9291a0cd TT |
16686 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
16687 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
16688 | |
16689 | /* We only want to add a given psymbol once. However, we also | |
16690 | want to account for whether it is global or static. So, we | |
16691 | may add it twice, using slightly different values. */ | |
16692 | if (is_static) | |
16693 | { | |
16694 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
16695 | ||
16696 | lookup = (void *) val; | |
16697 | } | |
16698 | else | |
16699 | lookup = *psymp; | |
16700 | ||
16701 | /* Only add a given psymbol once. */ | |
16702 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
16703 | if (!*slot) | |
16704 | { | |
16705 | *slot = lookup; | |
bb2f58dc | 16706 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
987d643c | 16707 | } |
9291a0cd TT |
16708 | } |
16709 | } | |
16710 | ||
16711 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
16712 | exception if there is an error. */ | |
b89be57b | 16713 | |
9291a0cd TT |
16714 | static void |
16715 | write_obstack (FILE *file, struct obstack *obstack) | |
16716 | { | |
16717 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
16718 | file) | |
16719 | != obstack_object_size (obstack)) | |
16720 | error (_("couldn't data write to file")); | |
16721 | } | |
16722 | ||
16723 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 16724 | |
9291a0cd TT |
16725 | static void |
16726 | unlink_if_set (void *p) | |
16727 | { | |
16728 | char **filename = p; | |
16729 | if (*filename) | |
16730 | unlink (*filename); | |
16731 | } | |
16732 | ||
1fd400ff TT |
16733 | /* A helper struct used when iterating over debug_types. */ |
16734 | struct signatured_type_index_data | |
16735 | { | |
16736 | struct objfile *objfile; | |
16737 | struct mapped_symtab *symtab; | |
16738 | struct obstack *types_list; | |
987d643c | 16739 | htab_t psyms_seen; |
1fd400ff TT |
16740 | int cu_index; |
16741 | }; | |
16742 | ||
16743 | /* A helper function that writes a single signatured_type to an | |
16744 | obstack. */ | |
b89be57b | 16745 | |
1fd400ff TT |
16746 | static int |
16747 | write_one_signatured_type (void **slot, void *d) | |
16748 | { | |
16749 | struct signatured_type_index_data *info = d; | |
16750 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
16751 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
16752 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
16753 | gdb_byte val[8]; |
16754 | ||
16755 | write_psymbols (info->symtab, | |
987d643c | 16756 | info->psyms_seen, |
3e43a32a MS |
16757 | info->objfile->global_psymbols.list |
16758 | + psymtab->globals_offset, | |
987d643c TT |
16759 | psymtab->n_global_syms, info->cu_index, |
16760 | 0); | |
1fd400ff | 16761 | write_psymbols (info->symtab, |
987d643c | 16762 | info->psyms_seen, |
3e43a32a MS |
16763 | info->objfile->static_psymbols.list |
16764 | + psymtab->statics_offset, | |
987d643c TT |
16765 | psymtab->n_static_syms, info->cu_index, |
16766 | 1); | |
1fd400ff | 16767 | |
b3c8eb43 | 16768 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
1fd400ff TT |
16769 | obstack_grow (info->types_list, val, 8); |
16770 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
16771 | obstack_grow (info->types_list, val, 8); | |
16772 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
16773 | obstack_grow (info->types_list, val, 8); | |
16774 | ||
16775 | ++info->cu_index; | |
16776 | ||
16777 | return 1; | |
16778 | } | |
16779 | ||
9291a0cd | 16780 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 16781 | |
9291a0cd TT |
16782 | static void |
16783 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
16784 | { | |
16785 | struct cleanup *cleanup; | |
16786 | char *filename, *cleanup_filename; | |
1fd400ff TT |
16787 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
16788 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
16789 | int i; |
16790 | FILE *out_file; | |
16791 | struct mapped_symtab *symtab; | |
16792 | offset_type val, size_of_contents, total_len; | |
16793 | struct stat st; | |
16794 | char buf[8]; | |
987d643c | 16795 | htab_t psyms_seen; |
0a5429f6 DE |
16796 | htab_t cu_index_htab; |
16797 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 16798 | |
b4f2f049 | 16799 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 16800 | return; |
b4f2f049 | 16801 | |
9291a0cd TT |
16802 | if (dwarf2_per_objfile->using_index) |
16803 | error (_("Cannot use an index to create the index")); | |
16804 | ||
8b70b953 TT |
16805 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
16806 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
16807 | ||
9291a0cd | 16808 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 16809 | perror_with_name (objfile->name); |
9291a0cd TT |
16810 | |
16811 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
16812 | INDEX_SUFFIX, (char *) NULL); | |
16813 | cleanup = make_cleanup (xfree, filename); | |
16814 | ||
16815 | out_file = fopen (filename, "wb"); | |
16816 | if (!out_file) | |
16817 | error (_("Can't open `%s' for writing"), filename); | |
16818 | ||
16819 | cleanup_filename = filename; | |
16820 | make_cleanup (unlink_if_set, &cleanup_filename); | |
16821 | ||
16822 | symtab = create_mapped_symtab (); | |
16823 | make_cleanup (cleanup_mapped_symtab, symtab); | |
16824 | ||
16825 | obstack_init (&addr_obstack); | |
16826 | make_cleanup_obstack_free (&addr_obstack); | |
16827 | ||
16828 | obstack_init (&cu_list); | |
16829 | make_cleanup_obstack_free (&cu_list); | |
16830 | ||
1fd400ff TT |
16831 | obstack_init (&types_cu_list); |
16832 | make_cleanup_obstack_free (&types_cu_list); | |
16833 | ||
987d643c TT |
16834 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
16835 | NULL, xcalloc, xfree); | |
96408a79 | 16836 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 16837 | |
0a5429f6 DE |
16838 | /* While we're scanning CU's create a table that maps a psymtab pointer |
16839 | (which is what addrmap records) to its index (which is what is recorded | |
16840 | in the index file). This will later be needed to write the address | |
16841 | table. */ | |
16842 | cu_index_htab = htab_create_alloc (100, | |
16843 | hash_psymtab_cu_index, | |
16844 | eq_psymtab_cu_index, | |
16845 | NULL, xcalloc, xfree); | |
96408a79 | 16846 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
16847 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
16848 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
16849 | * dwarf2_per_objfile->n_comp_units); | |
16850 | make_cleanup (xfree, psymtab_cu_index_map); | |
16851 | ||
16852 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
16853 | work here. Also, the debug_types entries do not appear in |
16854 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
16855 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
16856 | { | |
3e43a32a MS |
16857 | struct dwarf2_per_cu_data *per_cu |
16858 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 16859 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 16860 | gdb_byte val[8]; |
0a5429f6 DE |
16861 | struct psymtab_cu_index_map *map; |
16862 | void **slot; | |
9291a0cd TT |
16863 | |
16864 | write_psymbols (symtab, | |
987d643c | 16865 | psyms_seen, |
9291a0cd | 16866 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
16867 | psymtab->n_global_syms, i, |
16868 | 0); | |
9291a0cd | 16869 | write_psymbols (symtab, |
987d643c | 16870 | psyms_seen, |
9291a0cd | 16871 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
16872 | psymtab->n_static_syms, i, |
16873 | 1); | |
9291a0cd | 16874 | |
0a5429f6 DE |
16875 | map = &psymtab_cu_index_map[i]; |
16876 | map->psymtab = psymtab; | |
16877 | map->cu_index = i; | |
16878 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
16879 | gdb_assert (slot != NULL); | |
16880 | gdb_assert (*slot == NULL); | |
16881 | *slot = map; | |
9291a0cd | 16882 | |
e254ef6a | 16883 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 16884 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 16885 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
16886 | obstack_grow (&cu_list, val, 8); |
16887 | } | |
16888 | ||
0a5429f6 DE |
16889 | /* Dump the address map. */ |
16890 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
16891 | ||
1fd400ff TT |
16892 | /* Write out the .debug_type entries, if any. */ |
16893 | if (dwarf2_per_objfile->signatured_types) | |
16894 | { | |
16895 | struct signatured_type_index_data sig_data; | |
16896 | ||
16897 | sig_data.objfile = objfile; | |
16898 | sig_data.symtab = symtab; | |
16899 | sig_data.types_list = &types_cu_list; | |
987d643c | 16900 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
16901 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
16902 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
16903 | write_one_signatured_type, &sig_data); | |
16904 | } | |
16905 | ||
9291a0cd TT |
16906 | obstack_init (&constant_pool); |
16907 | make_cleanup_obstack_free (&constant_pool); | |
16908 | obstack_init (&symtab_obstack); | |
16909 | make_cleanup_obstack_free (&symtab_obstack); | |
16910 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
16911 | ||
16912 | obstack_init (&contents); | |
16913 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 16914 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
16915 | total_len = size_of_contents; |
16916 | ||
16917 | /* The version number. */ | |
559a7a62 | 16918 | val = MAYBE_SWAP (5); |
9291a0cd TT |
16919 | obstack_grow (&contents, &val, sizeof (val)); |
16920 | ||
16921 | /* The offset of the CU list from the start of the file. */ | |
16922 | val = MAYBE_SWAP (total_len); | |
16923 | obstack_grow (&contents, &val, sizeof (val)); | |
16924 | total_len += obstack_object_size (&cu_list); | |
16925 | ||
1fd400ff TT |
16926 | /* The offset of the types CU list from the start of the file. */ |
16927 | val = MAYBE_SWAP (total_len); | |
16928 | obstack_grow (&contents, &val, sizeof (val)); | |
16929 | total_len += obstack_object_size (&types_cu_list); | |
16930 | ||
9291a0cd TT |
16931 | /* The offset of the address table from the start of the file. */ |
16932 | val = MAYBE_SWAP (total_len); | |
16933 | obstack_grow (&contents, &val, sizeof (val)); | |
16934 | total_len += obstack_object_size (&addr_obstack); | |
16935 | ||
16936 | /* The offset of the symbol table from the start of the file. */ | |
16937 | val = MAYBE_SWAP (total_len); | |
16938 | obstack_grow (&contents, &val, sizeof (val)); | |
16939 | total_len += obstack_object_size (&symtab_obstack); | |
16940 | ||
16941 | /* The offset of the constant pool from the start of the file. */ | |
16942 | val = MAYBE_SWAP (total_len); | |
16943 | obstack_grow (&contents, &val, sizeof (val)); | |
16944 | total_len += obstack_object_size (&constant_pool); | |
16945 | ||
16946 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
16947 | ||
16948 | write_obstack (out_file, &contents); | |
16949 | write_obstack (out_file, &cu_list); | |
1fd400ff | 16950 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
16951 | write_obstack (out_file, &addr_obstack); |
16952 | write_obstack (out_file, &symtab_obstack); | |
16953 | write_obstack (out_file, &constant_pool); | |
16954 | ||
16955 | fclose (out_file); | |
16956 | ||
16957 | /* We want to keep the file, so we set cleanup_filename to NULL | |
16958 | here. See unlink_if_set. */ | |
16959 | cleanup_filename = NULL; | |
16960 | ||
16961 | do_cleanups (cleanup); | |
16962 | } | |
16963 | ||
90476074 TT |
16964 | /* Implementation of the `save gdb-index' command. |
16965 | ||
16966 | Note that the file format used by this command is documented in the | |
16967 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 16968 | |
9291a0cd TT |
16969 | static void |
16970 | save_gdb_index_command (char *arg, int from_tty) | |
16971 | { | |
16972 | struct objfile *objfile; | |
16973 | ||
16974 | if (!arg || !*arg) | |
96d19272 | 16975 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
16976 | |
16977 | ALL_OBJFILES (objfile) | |
16978 | { | |
16979 | struct stat st; | |
16980 | ||
16981 | /* If the objfile does not correspond to an actual file, skip it. */ | |
16982 | if (stat (objfile->name, &st) < 0) | |
16983 | continue; | |
16984 | ||
16985 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16986 | if (dwarf2_per_objfile) | |
16987 | { | |
16988 | volatile struct gdb_exception except; | |
16989 | ||
16990 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
16991 | { | |
16992 | write_psymtabs_to_index (objfile, arg); | |
16993 | } | |
16994 | if (except.reason < 0) | |
16995 | exception_fprintf (gdb_stderr, except, | |
16996 | _("Error while writing index for `%s': "), | |
16997 | objfile->name); | |
16998 | } | |
16999 | } | |
dce234bc PP |
17000 | } |
17001 | ||
9291a0cd TT |
17002 | \f |
17003 | ||
9eae7c52 TT |
17004 | int dwarf2_always_disassemble; |
17005 | ||
17006 | static void | |
17007 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
17008 | struct cmd_list_element *c, const char *value) | |
17009 | { | |
3e43a32a MS |
17010 | fprintf_filtered (file, |
17011 | _("Whether to always disassemble " | |
17012 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
17013 | value); |
17014 | } | |
17015 | ||
900e11f9 JK |
17016 | static void |
17017 | show_check_physname (struct ui_file *file, int from_tty, | |
17018 | struct cmd_list_element *c, const char *value) | |
17019 | { | |
17020 | fprintf_filtered (file, | |
17021 | _("Whether to check \"physname\" is %s.\n"), | |
17022 | value); | |
17023 | } | |
17024 | ||
6502dd73 DJ |
17025 | void _initialize_dwarf2_read (void); |
17026 | ||
17027 | void | |
17028 | _initialize_dwarf2_read (void) | |
17029 | { | |
96d19272 JK |
17030 | struct cmd_list_element *c; |
17031 | ||
dce234bc | 17032 | dwarf2_objfile_data_key |
c1bd65d0 | 17033 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 17034 | |
1bedd215 AC |
17035 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
17036 | Set DWARF 2 specific variables.\n\ | |
17037 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17038 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
17039 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
17040 | ||
1bedd215 AC |
17041 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
17042 | Show DWARF 2 specific variables\n\ | |
17043 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17044 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
17045 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
17046 | ||
17047 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
17048 | &dwarf2_max_cache_age, _("\ |
17049 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17050 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17051 | A higher limit means that cached compilation units will be stored\n\ | |
17052 | in memory longer, and more total memory will be used. Zero disables\n\ | |
17053 | caching, which can slow down startup."), | |
2c5b56ce | 17054 | NULL, |
920d2a44 | 17055 | show_dwarf2_max_cache_age, |
2c5b56ce | 17056 | &set_dwarf2_cmdlist, |
ae038cb0 | 17057 | &show_dwarf2_cmdlist); |
d97bc12b | 17058 | |
9eae7c52 TT |
17059 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
17060 | &dwarf2_always_disassemble, _("\ | |
17061 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
17062 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
17063 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
17064 | syntax. When disabled, expressions will be printed in a more\n\ | |
17065 | conversational style, when possible."), | |
17066 | NULL, | |
17067 | show_dwarf2_always_disassemble, | |
17068 | &set_dwarf2_cmdlist, | |
17069 | &show_dwarf2_cmdlist); | |
17070 | ||
d97bc12b DE |
17071 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
17072 | Set debugging of the dwarf2 DIE reader."), _("\ | |
17073 | Show debugging of the dwarf2 DIE reader."), _("\ | |
17074 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
17075 | The value is the maximum depth to print."), | |
17076 | NULL, | |
17077 | NULL, | |
17078 | &setdebuglist, &showdebuglist); | |
9291a0cd | 17079 | |
900e11f9 JK |
17080 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
17081 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
17082 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
17083 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
17084 | the demangler."), | |
17085 | NULL, show_check_physname, | |
17086 | &setdebuglist, &showdebuglist); | |
17087 | ||
96d19272 | 17088 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 17089 | _("\ |
fc1a9d6e | 17090 | Save a gdb-index file.\n\ |
11570e71 | 17091 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
17092 | &save_cmdlist); |
17093 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 17094 | } |