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 | 61 | #include "c-lang.h" |
a766d390 | 62 | #include "go-lang.h" |
98bfdba5 | 63 | #include "valprint.h" |
60d5a603 | 64 | #include <ctype.h> |
4c2df51b | 65 | |
c906108c SS |
66 | #include <fcntl.h> |
67 | #include "gdb_string.h" | |
4bdf3d34 | 68 | #include "gdb_assert.h" |
c906108c | 69 | #include <sys/types.h> |
233a11ab CS |
70 | #ifdef HAVE_ZLIB_H |
71 | #include <zlib.h> | |
72 | #endif | |
dce234bc PP |
73 | #ifdef HAVE_MMAP |
74 | #include <sys/mman.h> | |
85d9bd0e TT |
75 | #ifndef MAP_FAILED |
76 | #define MAP_FAILED ((void *) -1) | |
77 | #endif | |
dce234bc | 78 | #endif |
d8151005 | 79 | |
34eaf542 TT |
80 | typedef struct symbol *symbolp; |
81 | DEF_VEC_P (symbolp); | |
82 | ||
d97bc12b DE |
83 | /* When non-zero, dump DIEs after they are read in. */ |
84 | static int dwarf2_die_debug = 0; | |
85 | ||
900e11f9 JK |
86 | /* When non-zero, cross-check physname against demangler. */ |
87 | static int check_physname = 0; | |
88 | ||
481860b3 GB |
89 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
90 | int use_deprecated_index_sections = 0; | |
91 | ||
dce234bc PP |
92 | static int pagesize; |
93 | ||
df8a16a1 DJ |
94 | /* When set, the file that we're processing is known to have debugging |
95 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
96 | but later versions do. */ | |
97 | ||
98 | static int processing_has_namespace_info; | |
99 | ||
6502dd73 DJ |
100 | static const struct objfile_data *dwarf2_objfile_data_key; |
101 | ||
dce234bc PP |
102 | struct dwarf2_section_info |
103 | { | |
104 | asection *asection; | |
105 | gdb_byte *buffer; | |
106 | bfd_size_type size; | |
b315ab21 TG |
107 | /* Not NULL if the section was actually mmapped. */ |
108 | void *map_addr; | |
109 | /* Page aligned size of mmapped area. */ | |
110 | bfd_size_type map_len; | |
be391dca TT |
111 | /* True if we have tried to read this section. */ |
112 | int readin; | |
dce234bc PP |
113 | }; |
114 | ||
8b70b953 TT |
115 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
116 | DEF_VEC_O (dwarf2_section_info_def); | |
117 | ||
9291a0cd TT |
118 | /* All offsets in the index are of this type. It must be |
119 | architecture-independent. */ | |
120 | typedef uint32_t offset_type; | |
121 | ||
122 | DEF_VEC_I (offset_type); | |
123 | ||
124 | /* A description of the mapped index. The file format is described in | |
125 | a comment by the code that writes the index. */ | |
126 | struct mapped_index | |
127 | { | |
559a7a62 JK |
128 | /* Index data format version. */ |
129 | int version; | |
130 | ||
9291a0cd TT |
131 | /* The total length of the buffer. */ |
132 | off_t total_size; | |
b11b1f88 | 133 | |
9291a0cd TT |
134 | /* A pointer to the address table data. */ |
135 | const gdb_byte *address_table; | |
b11b1f88 | 136 | |
9291a0cd TT |
137 | /* Size of the address table data in bytes. */ |
138 | offset_type address_table_size; | |
b11b1f88 | 139 | |
3876f04e DE |
140 | /* The symbol table, implemented as a hash table. */ |
141 | const offset_type *symbol_table; | |
b11b1f88 | 142 | |
9291a0cd | 143 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 144 | offset_type symbol_table_slots; |
b11b1f88 | 145 | |
9291a0cd TT |
146 | /* A pointer to the constant pool. */ |
147 | const char *constant_pool; | |
148 | }; | |
149 | ||
9cdd5dbd DE |
150 | /* Collection of data recorded per objfile. |
151 | This hangs off of dwarf2_objfile_data_key. */ | |
152 | ||
6502dd73 DJ |
153 | struct dwarf2_per_objfile |
154 | { | |
dce234bc PP |
155 | struct dwarf2_section_info info; |
156 | struct dwarf2_section_info abbrev; | |
157 | struct dwarf2_section_info line; | |
dce234bc PP |
158 | struct dwarf2_section_info loc; |
159 | struct dwarf2_section_info macinfo; | |
cf2c3c16 | 160 | struct dwarf2_section_info macro; |
dce234bc PP |
161 | struct dwarf2_section_info str; |
162 | struct dwarf2_section_info ranges; | |
163 | struct dwarf2_section_info frame; | |
164 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 165 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 166 | |
8b70b953 TT |
167 | VEC (dwarf2_section_info_def) *types; |
168 | ||
be391dca TT |
169 | /* Back link. */ |
170 | struct objfile *objfile; | |
171 | ||
d467dd73 | 172 | /* Table of all the compilation units. This is used to locate |
10b3939b | 173 | the target compilation unit of a particular reference. */ |
ae038cb0 DJ |
174 | struct dwarf2_per_cu_data **all_comp_units; |
175 | ||
176 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
177 | int n_comp_units; | |
178 | ||
1fd400ff | 179 | /* The number of .debug_types-related CUs. */ |
d467dd73 | 180 | int n_type_units; |
1fd400ff | 181 | |
d467dd73 DE |
182 | /* The .debug_types-related CUs (TUs). */ |
183 | struct dwarf2_per_cu_data **all_type_units; | |
1fd400ff | 184 | |
ae038cb0 DJ |
185 | /* A chain of compilation units that are currently read in, so that |
186 | they can be freed later. */ | |
187 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 188 | |
348e048f DE |
189 | /* A table mapping .debug_types signatures to its signatured_type entry. |
190 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
191 | htab_t signatured_types; | |
192 | ||
72dca2f5 FR |
193 | /* A flag indicating wether this objfile has a section loaded at a |
194 | VMA of 0. */ | |
195 | int has_section_at_zero; | |
9291a0cd | 196 | |
ae2de4f8 DE |
197 | /* True if we are using the mapped index, |
198 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
199 | unsigned char using_index; |
200 | ||
ae2de4f8 | 201 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 202 | struct mapped_index *index_table; |
98bfdba5 | 203 | |
7b9f3c50 DE |
204 | /* When using index_table, this keeps track of all quick_file_names entries. |
205 | TUs can share line table entries with CUs or other TUs, and there can be | |
206 | a lot more TUs than unique line tables, so we maintain a separate table | |
207 | of all line table entries to support the sharing. */ | |
208 | htab_t quick_file_names_table; | |
209 | ||
98bfdba5 PA |
210 | /* Set during partial symbol reading, to prevent queueing of full |
211 | symbols. */ | |
212 | int reading_partial_symbols; | |
673bfd45 | 213 | |
dee91e82 | 214 | /* Table mapping type DIEs to their struct type *. |
673bfd45 | 215 | This is NULL if not allocated yet. |
dee91e82 DE |
216 | The mapping is done via (CU/TU signature + DIE offset) -> type. */ |
217 | htab_t die_type_hash; | |
6502dd73 DJ |
218 | }; |
219 | ||
220 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 221 | |
251d32d9 | 222 | /* Default names of the debugging sections. */ |
c906108c | 223 | |
233a11ab CS |
224 | /* Note that if the debugging section has been compressed, it might |
225 | have a name like .zdebug_info. */ | |
226 | ||
9cdd5dbd DE |
227 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
228 | { | |
251d32d9 TG |
229 | { ".debug_info", ".zdebug_info" }, |
230 | { ".debug_abbrev", ".zdebug_abbrev" }, | |
231 | { ".debug_line", ".zdebug_line" }, | |
232 | { ".debug_loc", ".zdebug_loc" }, | |
233 | { ".debug_macinfo", ".zdebug_macinfo" }, | |
cf2c3c16 | 234 | { ".debug_macro", ".zdebug_macro" }, |
251d32d9 TG |
235 | { ".debug_str", ".zdebug_str" }, |
236 | { ".debug_ranges", ".zdebug_ranges" }, | |
237 | { ".debug_types", ".zdebug_types" }, | |
238 | { ".debug_frame", ".zdebug_frame" }, | |
239 | { ".eh_frame", NULL }, | |
24d3216f TT |
240 | { ".gdb_index", ".zgdb_index" }, |
241 | 23 | |
251d32d9 | 242 | }; |
c906108c SS |
243 | |
244 | /* local data types */ | |
245 | ||
0963b4bd | 246 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
247 | #ifndef ABBREV_HASH_SIZE |
248 | #define ABBREV_HASH_SIZE 121 | |
249 | #endif | |
250 | ||
107d2387 AC |
251 | /* The data in a compilation unit header, after target2host |
252 | translation, looks like this. */ | |
c906108c | 253 | struct comp_unit_head |
a738430d | 254 | { |
c764a876 | 255 | unsigned int length; |
a738430d | 256 | short version; |
a738430d MK |
257 | unsigned char addr_size; |
258 | unsigned char signed_addr_p; | |
b64f50a1 | 259 | sect_offset abbrev_offset; |
57349743 | 260 | |
a738430d MK |
261 | /* Size of file offsets; either 4 or 8. */ |
262 | unsigned int offset_size; | |
57349743 | 263 | |
a738430d MK |
264 | /* Size of the length field; either 4 or 12. */ |
265 | unsigned int initial_length_size; | |
57349743 | 266 | |
a738430d MK |
267 | /* Offset to the first byte of this compilation unit header in the |
268 | .debug_info section, for resolving relative reference dies. */ | |
b64f50a1 | 269 | sect_offset offset; |
57349743 | 270 | |
d00adf39 DE |
271 | /* Offset to first die in this cu from the start of the cu. |
272 | This will be the first byte following the compilation unit header. */ | |
b64f50a1 | 273 | cu_offset first_die_offset; |
a738430d | 274 | }; |
c906108c | 275 | |
3da10d80 KS |
276 | /* Type used for delaying computation of method physnames. |
277 | See comments for compute_delayed_physnames. */ | |
278 | struct delayed_method_info | |
279 | { | |
280 | /* The type to which the method is attached, i.e., its parent class. */ | |
281 | struct type *type; | |
282 | ||
283 | /* The index of the method in the type's function fieldlists. */ | |
284 | int fnfield_index; | |
285 | ||
286 | /* The index of the method in the fieldlist. */ | |
287 | int index; | |
288 | ||
289 | /* The name of the DIE. */ | |
290 | const char *name; | |
291 | ||
292 | /* The DIE associated with this method. */ | |
293 | struct die_info *die; | |
294 | }; | |
295 | ||
296 | typedef struct delayed_method_info delayed_method_info; | |
297 | DEF_VEC_O (delayed_method_info); | |
298 | ||
e7c27a73 DJ |
299 | /* Internal state when decoding a particular compilation unit. */ |
300 | struct dwarf2_cu | |
301 | { | |
302 | /* The objfile containing this compilation unit. */ | |
303 | struct objfile *objfile; | |
304 | ||
d00adf39 | 305 | /* The header of the compilation unit. */ |
e7c27a73 | 306 | struct comp_unit_head header; |
e142c38c | 307 | |
d00adf39 DE |
308 | /* Base address of this compilation unit. */ |
309 | CORE_ADDR base_address; | |
310 | ||
311 | /* Non-zero if base_address has been set. */ | |
312 | int base_known; | |
313 | ||
e142c38c DJ |
314 | /* The language we are debugging. */ |
315 | enum language language; | |
316 | const struct language_defn *language_defn; | |
317 | ||
b0f35d58 DL |
318 | const char *producer; |
319 | ||
e142c38c DJ |
320 | /* The generic symbol table building routines have separate lists for |
321 | file scope symbols and all all other scopes (local scopes). So | |
322 | we need to select the right one to pass to add_symbol_to_list(). | |
323 | We do it by keeping a pointer to the correct list in list_in_scope. | |
324 | ||
325 | FIXME: The original dwarf code just treated the file scope as the | |
326 | first local scope, and all other local scopes as nested local | |
327 | scopes, and worked fine. Check to see if we really need to | |
328 | distinguish these in buildsym.c. */ | |
329 | struct pending **list_in_scope; | |
330 | ||
f3dd6933 DJ |
331 | /* DWARF abbreviation table associated with this compilation unit. */ |
332 | struct abbrev_info **dwarf2_abbrevs; | |
333 | ||
334 | /* Storage for the abbrev table. */ | |
335 | struct obstack abbrev_obstack; | |
72bf9492 | 336 | |
b64f50a1 JK |
337 | /* Hash table holding all the loaded partial DIEs |
338 | with partial_die->offset.SECT_OFF as hash. */ | |
72bf9492 DJ |
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 | ||
b64f50a1 JK |
357 | /* A hash table of DIE cu_offset for following references with |
358 | die_info->offset.sect_off as hash. */ | |
51545339 | 359 | htab_t die_hash; |
10b3939b DJ |
360 | |
361 | /* Full DIEs if read in. */ | |
362 | struct die_info *dies; | |
363 | ||
364 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
365 | units referenced by this one. Only set during full symbol processing; | |
366 | partial symbol tables do not have dependencies. */ | |
367 | htab_t dependencies; | |
368 | ||
cb1df416 DJ |
369 | /* Header data from the line table, during full symbol processing. */ |
370 | struct line_header *line_header; | |
371 | ||
3da10d80 KS |
372 | /* A list of methods which need to have physnames computed |
373 | after all type information has been read. */ | |
374 | VEC (delayed_method_info) *method_list; | |
375 | ||
96408a79 SA |
376 | /* To be copied to symtab->call_site_htab. */ |
377 | htab_t call_site_htab; | |
378 | ||
ae038cb0 DJ |
379 | /* Mark used when releasing cached dies. */ |
380 | unsigned int mark : 1; | |
381 | ||
8be455d7 JK |
382 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
383 | This test is imperfect as there may exist optimized debug code not using | |
384 | any location list and still facing inlining issues if handled as | |
385 | unoptimized code. For a future better test see GCC PR other/32998. */ | |
8be455d7 | 386 | unsigned int has_loclist : 1; |
ba919b58 TT |
387 | |
388 | /* These cache the results of producer_is_gxx_lt_4_6. | |
389 | CHECKED_PRODUCER is set if PRODUCER_IS_GXX_LT_4_6 is valid. This | |
390 | information is cached because profiling CU expansion showed | |
391 | excessive time spent in producer_is_gxx_lt_4_6. */ | |
392 | unsigned int checked_producer : 1; | |
393 | unsigned int producer_is_gxx_lt_4_6 : 1; | |
e7c27a73 DJ |
394 | }; |
395 | ||
10b3939b DJ |
396 | /* Persistent data held for a compilation unit, even when not |
397 | processing it. We put a pointer to this structure in the | |
28dee7f5 | 398 | read_symtab_private field of the psymtab. */ |
10b3939b | 399 | |
ae038cb0 DJ |
400 | struct dwarf2_per_cu_data |
401 | { | |
348e048f | 402 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 403 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
404 | - if it doesn't, GDB will fall over anyway. |
405 | NOTE: Unlike comp_unit_head.length, this length includes | |
406 | initial_length_size. */ | |
b64f50a1 | 407 | sect_offset offset; |
348e048f | 408 | unsigned int length : 29; |
ae038cb0 DJ |
409 | |
410 | /* Flag indicating this compilation unit will be read in before | |
411 | any of the current compilation units are processed. */ | |
c764a876 | 412 | unsigned int queued : 1; |
ae038cb0 | 413 | |
0d99eb77 DE |
414 | /* This flag will be set when reading partial DIEs if we need to load |
415 | absolutely all DIEs for this compilation unit, instead of just the ones | |
416 | we think are interesting. It gets set if we look for a DIE in the | |
5afb4e99 DJ |
417 | hash table and don't find it. */ |
418 | unsigned int load_all_dies : 1; | |
419 | ||
8b70b953 TT |
420 | /* Non-null if this CU is from .debug_types; in which case it points |
421 | to the section. Otherwise it's from .debug_info. */ | |
b0df02fd | 422 | struct dwarf2_section_info *debug_types_section; |
348e048f | 423 | |
17ea53c3 JK |
424 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
425 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 426 | struct dwarf2_cu *cu; |
1c379e20 | 427 | |
9cdd5dbd DE |
428 | /* The corresponding objfile. |
429 | Normally we can get the objfile from dwarf2_per_objfile. | |
430 | However we can enter this file with just a "per_cu" handle. */ | |
9291a0cd TT |
431 | struct objfile *objfile; |
432 | ||
433 | /* When using partial symbol tables, the 'psymtab' field is active. | |
434 | Otherwise the 'quick' field is active. */ | |
435 | union | |
436 | { | |
437 | /* The partial symbol table associated with this compilation unit, | |
438 | or NULL for partial units (which do not have an associated | |
439 | symtab). */ | |
440 | struct partial_symtab *psymtab; | |
441 | ||
442 | /* Data needed by the "quick" functions. */ | |
443 | struct dwarf2_per_cu_quick_data *quick; | |
444 | } v; | |
ae038cb0 DJ |
445 | }; |
446 | ||
348e048f DE |
447 | /* Entry in the signatured_types hash table. */ |
448 | ||
449 | struct signatured_type | |
450 | { | |
451 | ULONGEST signature; | |
452 | ||
b64f50a1 JK |
453 | /* Offset in this TU of the type defined by this TU. */ |
454 | cu_offset type_offset; | |
348e048f DE |
455 | |
456 | /* The CU(/TU) of this type. */ | |
457 | struct dwarf2_per_cu_data per_cu; | |
458 | }; | |
459 | ||
0963b4bd MS |
460 | /* Struct used to pass misc. parameters to read_die_and_children, et |
461 | al. which are used for both .debug_info and .debug_types dies. | |
462 | All parameters here are unchanging for the life of the call. This | |
dee91e82 | 463 | struct exists to abstract away the constant parameters of die reading. */ |
93311388 DE |
464 | |
465 | struct die_reader_specs | |
466 | { | |
dee91e82 | 467 | /* die_section->asection->owner. */ |
93311388 DE |
468 | bfd* abfd; |
469 | ||
470 | /* The CU of the DIE we are parsing. */ | |
471 | struct dwarf2_cu *cu; | |
472 | ||
dee91e82 DE |
473 | /* The section the die comes from. |
474 | This is either .debug_info or .debug_types. */ | |
475 | struct dwarf2_section_info *die_section; | |
476 | ||
477 | /* die_section->buffer. */ | |
478 | gdb_byte *buffer; | |
93311388 DE |
479 | }; |
480 | ||
dee91e82 DE |
481 | /* Type of function passed to init_cu_and_read_dies, et.al. */ |
482 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, | |
483 | gdb_byte *info_ptr, | |
484 | struct die_info *comp_unit_die, | |
485 | int has_children, | |
486 | void *data); | |
487 | ||
debd256d JB |
488 | /* The line number information for a compilation unit (found in the |
489 | .debug_line section) begins with a "statement program header", | |
490 | which contains the following information. */ | |
491 | struct line_header | |
492 | { | |
493 | unsigned int total_length; | |
494 | unsigned short version; | |
495 | unsigned int header_length; | |
496 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 497 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
498 | unsigned char default_is_stmt; |
499 | int line_base; | |
500 | unsigned char line_range; | |
501 | unsigned char opcode_base; | |
502 | ||
503 | /* standard_opcode_lengths[i] is the number of operands for the | |
504 | standard opcode whose value is i. This means that | |
505 | standard_opcode_lengths[0] is unused, and the last meaningful | |
506 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
507 | unsigned char *standard_opcode_lengths; | |
508 | ||
509 | /* The include_directories table. NOTE! These strings are not | |
510 | allocated with xmalloc; instead, they are pointers into | |
511 | debug_line_buffer. If you try to free them, `free' will get | |
512 | indigestion. */ | |
513 | unsigned int num_include_dirs, include_dirs_size; | |
514 | char **include_dirs; | |
515 | ||
516 | /* The file_names table. NOTE! These strings are not allocated | |
517 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
518 | Don't try to free them directly. */ | |
519 | unsigned int num_file_names, file_names_size; | |
520 | struct file_entry | |
c906108c | 521 | { |
debd256d JB |
522 | char *name; |
523 | unsigned int dir_index; | |
524 | unsigned int mod_time; | |
525 | unsigned int length; | |
aaa75496 | 526 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 527 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
528 | } *file_names; |
529 | ||
530 | /* The start and end of the statement program following this | |
6502dd73 | 531 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 532 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 533 | }; |
c906108c SS |
534 | |
535 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 536 | need this much information. */ |
c906108c SS |
537 | struct partial_die_info |
538 | { | |
72bf9492 | 539 | /* Offset of this DIE. */ |
b64f50a1 | 540 | sect_offset offset; |
72bf9492 DJ |
541 | |
542 | /* DWARF-2 tag for this DIE. */ | |
543 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
544 | ||
72bf9492 DJ |
545 | /* Assorted flags describing the data found in this DIE. */ |
546 | unsigned int has_children : 1; | |
547 | unsigned int is_external : 1; | |
548 | unsigned int is_declaration : 1; | |
549 | unsigned int has_type : 1; | |
550 | unsigned int has_specification : 1; | |
551 | unsigned int has_pc_info : 1; | |
481860b3 | 552 | unsigned int may_be_inlined : 1; |
72bf9492 DJ |
553 | |
554 | /* Flag set if the SCOPE field of this structure has been | |
555 | computed. */ | |
556 | unsigned int scope_set : 1; | |
557 | ||
fa4028e9 JB |
558 | /* Flag set if the DIE has a byte_size attribute. */ |
559 | unsigned int has_byte_size : 1; | |
560 | ||
98bfdba5 PA |
561 | /* Flag set if any of the DIE's children are template arguments. */ |
562 | unsigned int has_template_arguments : 1; | |
563 | ||
abc72ce4 DE |
564 | /* Flag set if fixup_partial_die has been called on this die. */ |
565 | unsigned int fixup_called : 1; | |
566 | ||
72bf9492 | 567 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 568 | sometimes a default name for unnamed DIEs. */ |
c906108c | 569 | char *name; |
72bf9492 | 570 | |
abc72ce4 DE |
571 | /* The linkage name, if present. */ |
572 | const char *linkage_name; | |
573 | ||
72bf9492 DJ |
574 | /* The scope to prepend to our children. This is generally |
575 | allocated on the comp_unit_obstack, so will disappear | |
576 | when this compilation unit leaves the cache. */ | |
577 | char *scope; | |
578 | ||
579 | /* The location description associated with this DIE, if any. */ | |
580 | struct dwarf_block *locdesc; | |
581 | ||
582 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
583 | CORE_ADDR lowpc; |
584 | CORE_ADDR highpc; | |
72bf9492 | 585 | |
93311388 | 586 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 587 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
588 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
589 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 590 | gdb_byte *sibling; |
72bf9492 DJ |
591 | |
592 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
593 | DW_AT_specification (or DW_AT_abstract_origin or | |
594 | DW_AT_extension). */ | |
b64f50a1 | 595 | sect_offset spec_offset; |
72bf9492 DJ |
596 | |
597 | /* Pointers to this DIE's parent, first child, and next sibling, | |
598 | if any. */ | |
599 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
600 | }; |
601 | ||
0963b4bd | 602 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
603 | struct abbrev_info |
604 | { | |
605 | unsigned int number; /* number identifying abbrev */ | |
606 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
607 | unsigned short has_children; /* boolean */ |
608 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
609 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
610 | struct abbrev_info *next; /* next in chain */ | |
611 | }; | |
612 | ||
613 | struct attr_abbrev | |
614 | { | |
9d25dd43 DE |
615 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
616 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
617 | }; |
618 | ||
0963b4bd | 619 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
620 | struct attribute |
621 | { | |
9d25dd43 | 622 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
623 | ENUM_BITFIELD(dwarf_form) form : 15; |
624 | ||
625 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
626 | field should be in u.str (existing only for DW_STRING) but it is kept | |
627 | here for better struct attribute alignment. */ | |
628 | unsigned int string_is_canonical : 1; | |
629 | ||
b60c80d6 DJ |
630 | union |
631 | { | |
632 | char *str; | |
633 | struct dwarf_block *blk; | |
43bbcdc2 PH |
634 | ULONGEST unsnd; |
635 | LONGEST snd; | |
b60c80d6 | 636 | CORE_ADDR addr; |
348e048f | 637 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
638 | } |
639 | u; | |
640 | }; | |
641 | ||
0963b4bd | 642 | /* This data structure holds a complete die structure. */ |
c906108c SS |
643 | struct die_info |
644 | { | |
76815b17 DE |
645 | /* DWARF-2 tag for this DIE. */ |
646 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
647 | ||
648 | /* Number of attributes */ | |
98bfdba5 PA |
649 | unsigned char num_attrs; |
650 | ||
651 | /* True if we're presently building the full type name for the | |
652 | type derived from this DIE. */ | |
653 | unsigned char building_fullname : 1; | |
76815b17 DE |
654 | |
655 | /* Abbrev number */ | |
656 | unsigned int abbrev; | |
657 | ||
93311388 | 658 | /* Offset in .debug_info or .debug_types section. */ |
b64f50a1 | 659 | sect_offset offset; |
78ba4af6 JB |
660 | |
661 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
662 | points to this die's parent; CHILD points to the first child of | |
663 | this node; and all the children of a given node are chained | |
4950bc1c | 664 | together via their SIBLING fields. */ |
639d11d3 DC |
665 | struct die_info *child; /* Its first child, if any. */ |
666 | struct die_info *sibling; /* Its next sibling, if any. */ | |
667 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 668 | |
b60c80d6 DJ |
669 | /* An array of attributes, with NUM_ATTRS elements. There may be |
670 | zero, but it's not common and zero-sized arrays are not | |
671 | sufficiently portable C. */ | |
672 | struct attribute attrs[1]; | |
c906108c SS |
673 | }; |
674 | ||
0963b4bd | 675 | /* Get at parts of an attribute structure. */ |
c906108c SS |
676 | |
677 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 678 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
679 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
680 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
681 | #define DW_SND(attr) ((attr)->u.snd) | |
682 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 683 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 684 | |
0963b4bd | 685 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
686 | struct dwarf_block |
687 | { | |
688 | unsigned int size; | |
1d6edc3c JK |
689 | |
690 | /* Valid only if SIZE is not zero. */ | |
fe1b8b76 | 691 | gdb_byte *data; |
c906108c SS |
692 | }; |
693 | ||
c906108c SS |
694 | #ifndef ATTR_ALLOC_CHUNK |
695 | #define ATTR_ALLOC_CHUNK 4 | |
696 | #endif | |
697 | ||
c906108c SS |
698 | /* Allocate fields for structs, unions and enums in this size. */ |
699 | #ifndef DW_FIELD_ALLOC_CHUNK | |
700 | #define DW_FIELD_ALLOC_CHUNK 4 | |
701 | #endif | |
702 | ||
c906108c SS |
703 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
704 | but this would require a corresponding change in unpack_field_as_long | |
705 | and friends. */ | |
706 | static int bits_per_byte = 8; | |
707 | ||
708 | /* The routines that read and process dies for a C struct or C++ class | |
709 | pass lists of data member fields and lists of member function fields | |
710 | in an instance of a field_info structure, as defined below. */ | |
711 | struct field_info | |
c5aa993b | 712 | { |
0963b4bd | 713 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
714 | struct nextfield |
715 | { | |
716 | struct nextfield *next; | |
717 | int accessibility; | |
718 | int virtuality; | |
719 | struct field field; | |
720 | } | |
7d0ccb61 | 721 | *fields, *baseclasses; |
c906108c | 722 | |
7d0ccb61 | 723 | /* Number of fields (including baseclasses). */ |
c5aa993b | 724 | int nfields; |
c906108c | 725 | |
c5aa993b JM |
726 | /* Number of baseclasses. */ |
727 | int nbaseclasses; | |
c906108c | 728 | |
c5aa993b JM |
729 | /* Set if the accesibility of one of the fields is not public. */ |
730 | int non_public_fields; | |
c906108c | 731 | |
c5aa993b JM |
732 | /* Member function fields array, entries are allocated in the order they |
733 | are encountered in the object file. */ | |
734 | struct nextfnfield | |
735 | { | |
736 | struct nextfnfield *next; | |
737 | struct fn_field fnfield; | |
738 | } | |
739 | *fnfields; | |
c906108c | 740 | |
c5aa993b JM |
741 | /* Member function fieldlist array, contains name of possibly overloaded |
742 | member function, number of overloaded member functions and a pointer | |
743 | to the head of the member function field chain. */ | |
744 | struct fnfieldlist | |
745 | { | |
746 | char *name; | |
747 | int length; | |
748 | struct nextfnfield *head; | |
749 | } | |
750 | *fnfieldlists; | |
c906108c | 751 | |
c5aa993b JM |
752 | /* Number of entries in the fnfieldlists array. */ |
753 | int nfnfields; | |
98751a41 JK |
754 | |
755 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
756 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
757 | struct typedef_field_list | |
758 | { | |
759 | struct typedef_field field; | |
760 | struct typedef_field_list *next; | |
761 | } | |
762 | *typedef_field_list; | |
763 | unsigned typedef_field_list_count; | |
c5aa993b | 764 | }; |
c906108c | 765 | |
10b3939b DJ |
766 | /* One item on the queue of compilation units to read in full symbols |
767 | for. */ | |
768 | struct dwarf2_queue_item | |
769 | { | |
770 | struct dwarf2_per_cu_data *per_cu; | |
771 | struct dwarf2_queue_item *next; | |
772 | }; | |
773 | ||
774 | /* The current queue. */ | |
775 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
776 | ||
ae038cb0 DJ |
777 | /* Loaded secondary compilation units are kept in memory until they |
778 | have not been referenced for the processing of this many | |
779 | compilation units. Set this to zero to disable caching. Cache | |
780 | sizes of up to at least twenty will improve startup time for | |
781 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
782 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
783 | static void |
784 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
785 | struct cmd_list_element *c, const char *value) | |
786 | { | |
3e43a32a MS |
787 | fprintf_filtered (file, _("The upper bound on the age of cached " |
788 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
789 | value); |
790 | } | |
791 | ||
ae038cb0 | 792 | |
0963b4bd | 793 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 794 | |
4d3c2250 KB |
795 | static void |
796 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 797 | { |
4d3c2250 | 798 | complaint (&symfile_complaints, |
e2e0b3e5 | 799 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
800 | } |
801 | ||
25e43795 DJ |
802 | static void |
803 | dwarf2_debug_line_missing_file_complaint (void) | |
804 | { | |
805 | complaint (&symfile_complaints, | |
806 | _(".debug_line section has line data without a file")); | |
807 | } | |
808 | ||
59205f5a JB |
809 | static void |
810 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
811 | { | |
812 | complaint (&symfile_complaints, | |
3e43a32a MS |
813 | _(".debug_line section has line " |
814 | "program sequence without an end")); | |
59205f5a JB |
815 | } |
816 | ||
4d3c2250 KB |
817 | static void |
818 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 819 | { |
e2e0b3e5 | 820 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
821 | } |
822 | ||
4d3c2250 KB |
823 | static void |
824 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
825 | int arg3) | |
2e276125 | 826 | { |
4d3c2250 | 827 | complaint (&symfile_complaints, |
3e43a32a MS |
828 | _("const value length mismatch for '%s', got %d, expected %d"), |
829 | arg1, arg2, arg3); | |
4d3c2250 KB |
830 | } |
831 | ||
832 | static void | |
cf2c3c16 | 833 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
2e276125 | 834 | { |
4d3c2250 | 835 | complaint (&symfile_complaints, |
cf2c3c16 TT |
836 | _("macro info runs off end of `%s' section"), |
837 | section->asection->name); | |
4d3c2250 KB |
838 | } |
839 | ||
840 | static void | |
841 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 842 | { |
4d3c2250 | 843 | complaint (&symfile_complaints, |
3e43a32a MS |
844 | _("macro debug info contains a " |
845 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
846 | arg1); |
847 | } | |
848 | ||
849 | static void | |
850 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 851 | { |
4d3c2250 | 852 | complaint (&symfile_complaints, |
3e43a32a MS |
853 | _("invalid attribute class or form for '%s' in '%s'"), |
854 | arg1, arg2); | |
4d3c2250 | 855 | } |
c906108c | 856 | |
c906108c SS |
857 | /* local function prototypes */ |
858 | ||
4efb68b1 | 859 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 860 | |
aaa75496 JB |
861 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
862 | struct objfile *); | |
863 | ||
918dd910 JK |
864 | static void dwarf2_find_base_address (struct die_info *die, |
865 | struct dwarf2_cu *cu); | |
866 | ||
c67a9c90 | 867 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 868 | |
72bf9492 DJ |
869 | static void scan_partial_symbols (struct partial_die_info *, |
870 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 871 | int, struct dwarf2_cu *); |
c906108c | 872 | |
72bf9492 DJ |
873 | static void add_partial_symbol (struct partial_die_info *, |
874 | struct dwarf2_cu *); | |
63d06c5c | 875 | |
72bf9492 DJ |
876 | static void add_partial_namespace (struct partial_die_info *pdi, |
877 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 878 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 879 | |
5d7cb8df JK |
880 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
881 | CORE_ADDR *highpc, int need_pc, | |
882 | struct dwarf2_cu *cu); | |
883 | ||
72bf9492 DJ |
884 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
885 | struct dwarf2_cu *cu); | |
91c24f0a | 886 | |
bc30ff58 JB |
887 | static void add_partial_subprogram (struct partial_die_info *pdi, |
888 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 889 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 890 | |
a14ed312 | 891 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 892 | |
a14ed312 | 893 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 894 | |
dee91e82 DE |
895 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
896 | struct dwarf2_section_info *); | |
c906108c | 897 | |
f3dd6933 | 898 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 899 | |
6caca83c CC |
900 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
901 | ||
fe1b8b76 | 902 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 903 | struct dwarf2_cu *); |
72bf9492 | 904 | |
57349743 | 905 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 906 | struct dwarf2_cu *); |
c906108c | 907 | |
dee91e82 DE |
908 | static struct partial_die_info *load_partial_dies |
909 | (const struct die_reader_specs *, gdb_byte *, int); | |
72bf9492 | 910 | |
dee91e82 DE |
911 | static gdb_byte *read_partial_die (const struct die_reader_specs *, |
912 | struct partial_die_info *, | |
913 | struct abbrev_info *, | |
914 | unsigned int, | |
915 | gdb_byte *); | |
c906108c | 916 | |
b64f50a1 | 917 | static struct partial_die_info *find_partial_die (sect_offset, |
10b3939b | 918 | struct dwarf2_cu *); |
72bf9492 DJ |
919 | |
920 | static void fixup_partial_die (struct partial_die_info *, | |
921 | struct dwarf2_cu *); | |
922 | ||
dee91e82 DE |
923 | static gdb_byte *read_attribute (const struct die_reader_specs *, |
924 | struct attribute *, struct attr_abbrev *, | |
925 | gdb_byte *); | |
a8329558 | 926 | |
fe1b8b76 | 927 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 928 | |
fe1b8b76 | 929 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 930 | |
fe1b8b76 | 931 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 932 | |
fe1b8b76 | 933 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 934 | |
93311388 | 935 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 936 | |
fe1b8b76 | 937 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 938 | unsigned int *); |
c906108c | 939 | |
c764a876 DE |
940 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
941 | ||
942 | static LONGEST read_checked_initial_length_and_offset | |
943 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
944 | unsigned int *, unsigned int *); | |
613e1657 | 945 | |
fe1b8b76 | 946 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
947 | unsigned int *); |
948 | ||
949 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 950 | |
fe1b8b76 | 951 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 952 | |
9b1c24c8 | 953 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 954 | |
fe1b8b76 JB |
955 | static char *read_indirect_string (bfd *, gdb_byte *, |
956 | const struct comp_unit_head *, | |
957 | unsigned int *); | |
4bdf3d34 | 958 | |
12df843f | 959 | static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 960 | |
12df843f | 961 | static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 962 | |
fe1b8b76 | 963 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 964 | |
e142c38c | 965 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 966 | |
e142c38c DJ |
967 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
968 | struct dwarf2_cu *); | |
c906108c | 969 | |
348e048f DE |
970 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
971 | unsigned int, | |
972 | struct dwarf2_cu *); | |
973 | ||
05cf31d1 JB |
974 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
975 | struct dwarf2_cu *cu); | |
976 | ||
e142c38c | 977 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 978 | |
e142c38c | 979 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 980 | struct dwarf2_cu **); |
63d06c5c | 981 | |
debd256d JB |
982 | static void free_line_header (struct line_header *lh); |
983 | ||
aaa75496 JB |
984 | static void add_file_name (struct line_header *, char *, unsigned int, |
985 | unsigned int, unsigned int); | |
986 | ||
debd256d JB |
987 | static struct line_header *(dwarf_decode_line_header |
988 | (unsigned int offset, | |
e7c27a73 | 989 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 990 | |
f3f5162e DE |
991 | static void dwarf_decode_lines (struct line_header *, const char *, |
992 | struct dwarf2_cu *, struct partial_symtab *, | |
993 | int); | |
c906108c | 994 | |
72b9f47f | 995 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 996 | |
a14ed312 | 997 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 998 | struct dwarf2_cu *); |
c906108c | 999 | |
34eaf542 TT |
1000 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1001 | struct dwarf2_cu *, struct symbol *); | |
1002 | ||
a14ed312 | 1003 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1004 | struct dwarf2_cu *); |
c906108c | 1005 | |
98bfdba5 PA |
1006 | static void dwarf2_const_value_attr (struct attribute *attr, |
1007 | struct type *type, | |
1008 | const char *name, | |
1009 | struct obstack *obstack, | |
12df843f | 1010 | struct dwarf2_cu *cu, LONGEST *value, |
98bfdba5 PA |
1011 | gdb_byte **bytes, |
1012 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1013 | |
e7c27a73 | 1014 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1015 | |
b4ba55a1 JB |
1016 | static int need_gnat_info (struct dwarf2_cu *); |
1017 | ||
3e43a32a MS |
1018 | static struct type *die_descriptive_type (struct die_info *, |
1019 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1020 | |
1021 | static void set_descriptive_type (struct type *, struct die_info *, | |
1022 | struct dwarf2_cu *); | |
1023 | ||
e7c27a73 DJ |
1024 | static struct type *die_containing_type (struct die_info *, |
1025 | struct dwarf2_cu *); | |
c906108c | 1026 | |
673bfd45 DE |
1027 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1028 | struct dwarf2_cu *); | |
c906108c | 1029 | |
f792889a | 1030 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1031 | |
673bfd45 DE |
1032 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1033 | ||
0d5cff50 | 1034 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1035 | |
6e70227d | 1036 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1037 | const char *suffix, int physname, |
1038 | struct dwarf2_cu *cu); | |
63d06c5c | 1039 | |
e7c27a73 | 1040 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1041 | |
348e048f DE |
1042 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1043 | ||
e7c27a73 | 1044 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1045 | |
e7c27a73 | 1046 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1047 | |
96408a79 SA |
1048 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
1049 | ||
ff013f42 JK |
1050 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1051 | struct dwarf2_cu *, struct partial_symtab *); | |
1052 | ||
a14ed312 | 1053 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1054 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1055 | struct partial_symtab *); | |
c906108c | 1056 | |
fae299cd DC |
1057 | static void get_scope_pc_bounds (struct die_info *, |
1058 | CORE_ADDR *, CORE_ADDR *, | |
1059 | struct dwarf2_cu *); | |
1060 | ||
801e3a5b JB |
1061 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1062 | CORE_ADDR, struct dwarf2_cu *); | |
1063 | ||
a14ed312 | 1064 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1065 | struct dwarf2_cu *); |
c906108c | 1066 | |
a14ed312 | 1067 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1068 | struct type *, struct dwarf2_cu *); |
c906108c | 1069 | |
a14ed312 | 1070 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1071 | struct die_info *, struct type *, |
e7c27a73 | 1072 | struct dwarf2_cu *); |
c906108c | 1073 | |
a14ed312 | 1074 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
3e43a32a MS |
1075 | struct type *, |
1076 | struct dwarf2_cu *); | |
c906108c | 1077 | |
134d01f1 | 1078 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1079 | |
e7c27a73 | 1080 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1081 | |
e7c27a73 | 1082 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1083 | |
5d7cb8df JK |
1084 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1085 | ||
27aa8d6a SW |
1086 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1087 | ||
f55ee35c JK |
1088 | static struct type *read_module_type (struct die_info *die, |
1089 | struct dwarf2_cu *cu); | |
1090 | ||
38d518c9 | 1091 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1092 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1093 | |
134d01f1 | 1094 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1095 | |
e7c27a73 | 1096 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1097 | |
6e70227d | 1098 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1099 | struct dwarf2_cu *); |
1100 | ||
dee91e82 | 1101 | static struct die_info *read_die_and_children (const struct die_reader_specs *, |
93311388 | 1102 | gdb_byte *info_ptr, |
fe1b8b76 | 1103 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1104 | struct die_info *parent); |
1105 | ||
dee91e82 | 1106 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
93311388 | 1107 | gdb_byte *info_ptr, |
fe1b8b76 | 1108 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1109 | struct die_info *parent); |
1110 | ||
dee91e82 DE |
1111 | static gdb_byte *read_full_die (const struct die_reader_specs *, |
1112 | struct die_info **, gdb_byte *, int *); | |
93311388 | 1113 | |
e7c27a73 | 1114 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1115 | |
71c25dea TT |
1116 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1117 | struct obstack *); | |
1118 | ||
e142c38c | 1119 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1120 | |
98bfdba5 PA |
1121 | static const char *dwarf2_full_name (char *name, |
1122 | struct die_info *die, | |
1123 | struct dwarf2_cu *cu); | |
1124 | ||
e142c38c | 1125 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1126 | struct dwarf2_cu **); |
9219021c | 1127 | |
a14ed312 | 1128 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1129 | |
a14ed312 | 1130 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1131 | |
a14ed312 | 1132 | static char *dwarf_form_name (unsigned int); |
c906108c | 1133 | |
a14ed312 | 1134 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1135 | |
a14ed312 | 1136 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1137 | |
1138 | #if 0 | |
a14ed312 | 1139 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1140 | #endif |
1141 | ||
f9aca02d | 1142 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1143 | |
d97bc12b DE |
1144 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1145 | ||
1146 | static void dump_die_for_error (struct die_info *); | |
1147 | ||
1148 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1149 | struct die_info *); | |
c906108c | 1150 | |
d97bc12b | 1151 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1152 | |
51545339 | 1153 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1154 | struct dwarf2_cu *); |
c906108c | 1155 | |
93311388 DE |
1156 | static int is_ref_attr (struct attribute *); |
1157 | ||
b64f50a1 | 1158 | static sect_offset dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1159 | |
43bbcdc2 | 1160 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1161 | |
348e048f DE |
1162 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1163 | struct attribute *, | |
1164 | struct dwarf2_cu **); | |
1165 | ||
10b3939b DJ |
1166 | static struct die_info *follow_die_ref (struct die_info *, |
1167 | struct attribute *, | |
f2f0e013 | 1168 | struct dwarf2_cu **); |
c906108c | 1169 | |
348e048f DE |
1170 | static struct die_info *follow_die_sig (struct die_info *, |
1171 | struct attribute *, | |
1172 | struct dwarf2_cu **); | |
1173 | ||
6c83ed52 TT |
1174 | static struct signatured_type *lookup_signatured_type_at_offset |
1175 | (struct objfile *objfile, | |
b64f50a1 | 1176 | struct dwarf2_section_info *section, sect_offset offset); |
6c83ed52 | 1177 | |
e5fe5e75 | 1178 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
348e048f | 1179 | |
52dc124a | 1180 | static void read_signatured_type (struct signatured_type *); |
348e048f | 1181 | |
c906108c SS |
1182 | /* memory allocation interface */ |
1183 | ||
7b5a2f43 | 1184 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1185 | |
f3dd6933 | 1186 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1187 | |
b60c80d6 | 1188 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1189 | |
2e276125 | 1190 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
cf2c3c16 TT |
1191 | char *, bfd *, struct dwarf2_cu *, |
1192 | struct dwarf2_section_info *, | |
1193 | int); | |
2e276125 | 1194 | |
8e19ed76 PS |
1195 | static int attr_form_is_block (struct attribute *); |
1196 | ||
3690dd37 JB |
1197 | static int attr_form_is_section_offset (struct attribute *); |
1198 | ||
1199 | static int attr_form_is_constant (struct attribute *); | |
1200 | ||
8cf6f0b1 TT |
1201 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1202 | struct dwarf2_loclist_baton *baton, | |
1203 | struct attribute *attr); | |
1204 | ||
93e7bd98 DJ |
1205 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1206 | struct symbol *sym, | |
1207 | struct dwarf2_cu *cu); | |
4c2df51b | 1208 | |
dee91e82 DE |
1209 | static gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
1210 | gdb_byte *info_ptr, | |
1211 | struct abbrev_info *abbrev); | |
4bb7a0a7 | 1212 | |
72bf9492 DJ |
1213 | static void free_stack_comp_unit (void *); |
1214 | ||
72bf9492 DJ |
1215 | static hashval_t partial_die_hash (const void *item); |
1216 | ||
1217 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1218 | ||
ae038cb0 | 1219 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
b64f50a1 | 1220 | (sect_offset offset, struct objfile *objfile); |
ae038cb0 | 1221 | |
9816fde3 | 1222 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
23745b47 | 1223 | struct dwarf2_per_cu_data *per_cu); |
9816fde3 JK |
1224 | |
1225 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1226 | struct die_info *comp_unit_die); | |
93311388 | 1227 | |
68dc6402 | 1228 | static void free_heap_comp_unit (void *); |
ae038cb0 DJ |
1229 | |
1230 | static void free_cached_comp_units (void *); | |
1231 | ||
1232 | static void age_cached_comp_units (void); | |
1233 | ||
dee91e82 | 1234 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
ae038cb0 | 1235 | |
f792889a DJ |
1236 | static struct type *set_die_type (struct die_info *, struct type *, |
1237 | struct dwarf2_cu *); | |
1c379e20 | 1238 | |
ae038cb0 DJ |
1239 | static void create_all_comp_units (struct objfile *); |
1240 | ||
0e50663e | 1241 | static int create_all_type_units (struct objfile *); |
1fd400ff | 1242 | |
a0f42c21 | 1243 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
10b3939b DJ |
1244 | |
1245 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1246 | ||
1247 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1248 | struct dwarf2_per_cu_data *); | |
1249 | ||
ae038cb0 DJ |
1250 | static void dwarf2_mark (struct dwarf2_cu *); |
1251 | ||
1252 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1253 | ||
b64f50a1 | 1254 | static struct type *get_die_type_at_offset (sect_offset, |
673bfd45 DE |
1255 | struct dwarf2_per_cu_data *per_cu); |
1256 | ||
f792889a | 1257 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1258 | |
9291a0cd TT |
1259 | static void dwarf2_release_queue (void *dummy); |
1260 | ||
a0f42c21 | 1261 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
9291a0cd | 1262 | |
a0f42c21 | 1263 | static void process_queue (void); |
9291a0cd TT |
1264 | |
1265 | static void find_file_and_directory (struct die_info *die, | |
1266 | struct dwarf2_cu *cu, | |
1267 | char **name, char **comp_dir); | |
1268 | ||
1269 | static char *file_full_name (int file, struct line_header *lh, | |
1270 | const char *comp_dir); | |
1271 | ||
9ff913ba DE |
1272 | static gdb_byte *read_and_check_comp_unit_head |
1273 | (struct comp_unit_head *header, | |
1274 | struct dwarf2_section_info *section, gdb_byte *info_ptr, | |
1275 | int is_debug_types_section); | |
9291a0cd | 1276 | |
dee91e82 DE |
1277 | static void init_cutu_and_read_dies_simple |
1278 | (struct dwarf2_per_cu_data *this_cu, | |
1279 | die_reader_func_ftype *die_reader_func, void *data); | |
9291a0cd | 1280 | |
673bfd45 | 1281 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1282 | |
dee91e82 DE |
1283 | static void process_psymtab_comp_unit (struct dwarf2_per_cu_data *); |
1284 | ||
9291a0cd TT |
1285 | #if WORDS_BIGENDIAN |
1286 | ||
1287 | /* Convert VALUE between big- and little-endian. */ | |
1288 | static offset_type | |
1289 | byte_swap (offset_type value) | |
1290 | { | |
1291 | offset_type result; | |
1292 | ||
1293 | result = (value & 0xff) << 24; | |
1294 | result |= (value & 0xff00) << 8; | |
1295 | result |= (value & 0xff0000) >> 8; | |
1296 | result |= (value & 0xff000000) >> 24; | |
1297 | return result; | |
1298 | } | |
1299 | ||
1300 | #define MAYBE_SWAP(V) byte_swap (V) | |
1301 | ||
1302 | #else | |
1303 | #define MAYBE_SWAP(V) (V) | |
1304 | #endif /* WORDS_BIGENDIAN */ | |
1305 | ||
1306 | /* The suffix for an index file. */ | |
1307 | #define INDEX_SUFFIX ".gdb-index" | |
1308 | ||
3da10d80 KS |
1309 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1310 | struct dwarf2_cu *cu); | |
1311 | ||
c906108c | 1312 | /* Try to locate the sections we need for DWARF 2 debugging |
251d32d9 TG |
1313 | information and return true if we have enough to do something. |
1314 | NAMES points to the dwarf2 section names, or is NULL if the standard | |
1315 | ELF names are used. */ | |
c906108c SS |
1316 | |
1317 | int | |
251d32d9 TG |
1318 | dwarf2_has_info (struct objfile *objfile, |
1319 | const struct dwarf2_debug_sections *names) | |
c906108c | 1320 | { |
be391dca TT |
1321 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1322 | if (!dwarf2_per_objfile) | |
1323 | { | |
1324 | /* Initialize per-objfile state. */ | |
1325 | struct dwarf2_per_objfile *data | |
1326 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1327 | |
be391dca TT |
1328 | memset (data, 0, sizeof (*data)); |
1329 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1330 | dwarf2_per_objfile = data; | |
6502dd73 | 1331 | |
251d32d9 TG |
1332 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
1333 | (void *) names); | |
be391dca TT |
1334 | dwarf2_per_objfile->objfile = objfile; |
1335 | } | |
1336 | return (dwarf2_per_objfile->info.asection != NULL | |
1337 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1338 | } |
1339 | ||
251d32d9 TG |
1340 | /* When loading sections, we look either for uncompressed section or for |
1341 | compressed section names. */ | |
233a11ab CS |
1342 | |
1343 | static int | |
251d32d9 TG |
1344 | section_is_p (const char *section_name, |
1345 | const struct dwarf2_section_names *names) | |
233a11ab | 1346 | { |
251d32d9 TG |
1347 | if (names->normal != NULL |
1348 | && strcmp (section_name, names->normal) == 0) | |
1349 | return 1; | |
1350 | if (names->compressed != NULL | |
1351 | && strcmp (section_name, names->compressed) == 0) | |
1352 | return 1; | |
1353 | return 0; | |
233a11ab CS |
1354 | } |
1355 | ||
c906108c SS |
1356 | /* This function is mapped across the sections and remembers the |
1357 | offset and size of each of the debugging sections we are interested | |
1358 | in. */ | |
1359 | ||
1360 | static void | |
251d32d9 | 1361 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
c906108c | 1362 | { |
251d32d9 TG |
1363 | const struct dwarf2_debug_sections *names; |
1364 | ||
1365 | if (vnames == NULL) | |
1366 | names = &dwarf2_elf_names; | |
1367 | else | |
1368 | names = (const struct dwarf2_debug_sections *) vnames; | |
1369 | ||
1370 | if (section_is_p (sectp->name, &names->info)) | |
c906108c | 1371 | { |
dce234bc PP |
1372 | dwarf2_per_objfile->info.asection = sectp; |
1373 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1374 | } |
251d32d9 | 1375 | else if (section_is_p (sectp->name, &names->abbrev)) |
c906108c | 1376 | { |
dce234bc PP |
1377 | dwarf2_per_objfile->abbrev.asection = sectp; |
1378 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1379 | } |
251d32d9 | 1380 | else if (section_is_p (sectp->name, &names->line)) |
c906108c | 1381 | { |
dce234bc PP |
1382 | dwarf2_per_objfile->line.asection = sectp; |
1383 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1384 | } |
251d32d9 | 1385 | else if (section_is_p (sectp->name, &names->loc)) |
c906108c | 1386 | { |
dce234bc PP |
1387 | dwarf2_per_objfile->loc.asection = sectp; |
1388 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1389 | } |
251d32d9 | 1390 | else if (section_is_p (sectp->name, &names->macinfo)) |
c906108c | 1391 | { |
dce234bc PP |
1392 | dwarf2_per_objfile->macinfo.asection = sectp; |
1393 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1394 | } |
cf2c3c16 TT |
1395 | else if (section_is_p (sectp->name, &names->macro)) |
1396 | { | |
1397 | dwarf2_per_objfile->macro.asection = sectp; | |
1398 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); | |
1399 | } | |
251d32d9 | 1400 | else if (section_is_p (sectp->name, &names->str)) |
c906108c | 1401 | { |
dce234bc PP |
1402 | dwarf2_per_objfile->str.asection = sectp; |
1403 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1404 | } |
251d32d9 | 1405 | else if (section_is_p (sectp->name, &names->frame)) |
b6af0555 | 1406 | { |
dce234bc PP |
1407 | dwarf2_per_objfile->frame.asection = sectp; |
1408 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1409 | } |
251d32d9 | 1410 | else if (section_is_p (sectp->name, &names->eh_frame)) |
b6af0555 | 1411 | { |
3799ccc6 | 1412 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1413 | |
3799ccc6 EZ |
1414 | if (aflag & SEC_HAS_CONTENTS) |
1415 | { | |
dce234bc PP |
1416 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1417 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1418 | } |
b6af0555 | 1419 | } |
251d32d9 | 1420 | else if (section_is_p (sectp->name, &names->ranges)) |
af34e669 | 1421 | { |
dce234bc PP |
1422 | dwarf2_per_objfile->ranges.asection = sectp; |
1423 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1424 | } |
251d32d9 | 1425 | else if (section_is_p (sectp->name, &names->types)) |
348e048f | 1426 | { |
8b70b953 TT |
1427 | struct dwarf2_section_info type_section; |
1428 | ||
1429 | memset (&type_section, 0, sizeof (type_section)); | |
1430 | type_section.asection = sectp; | |
1431 | type_section.size = bfd_get_section_size (sectp); | |
1432 | ||
1433 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
1434 | &type_section); | |
348e048f | 1435 | } |
251d32d9 | 1436 | else if (section_is_p (sectp->name, &names->gdb_index)) |
9291a0cd TT |
1437 | { |
1438 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1439 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1440 | } | |
dce234bc | 1441 | |
72dca2f5 FR |
1442 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1443 | && bfd_section_vma (abfd, sectp) == 0) | |
1444 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1445 | } |
1446 | ||
dce234bc PP |
1447 | /* Decompress a section that was compressed using zlib. Store the |
1448 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1449 | |
1450 | static void | |
dce234bc PP |
1451 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1452 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1453 | { | |
1454 | bfd *abfd = objfile->obfd; | |
1455 | #ifndef HAVE_ZLIB_H | |
1456 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1457 | "is disabled in this copy of GDB"), | |
1458 | bfd_get_filename (abfd)); | |
1459 | #else | |
1460 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1461 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1462 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1463 | bfd_size_type uncompressed_size; |
1464 | gdb_byte *uncompressed_buffer; | |
1465 | z_stream strm; | |
1466 | int rc; | |
1467 | int header_size = 12; | |
1468 | ||
1469 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1470 | || bfd_bread (compressed_buffer, |
1471 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1472 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1473 | bfd_get_filename (abfd)); | |
1474 | ||
1475 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1476 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1477 | if (compressed_size < header_size | |
1478 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1479 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1480 | bfd_get_filename (abfd)); | |
1481 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1482 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1483 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1484 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1485 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1486 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1487 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1488 | uncompressed_size += compressed_buffer[11]; | |
1489 | ||
1490 | /* It is possible the section consists of several compressed | |
1491 | buffers concatenated together, so we uncompress in a loop. */ | |
1492 | strm.zalloc = NULL; | |
1493 | strm.zfree = NULL; | |
1494 | strm.opaque = NULL; | |
1495 | strm.avail_in = compressed_size - header_size; | |
1496 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1497 | strm.avail_out = uncompressed_size; | |
1498 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1499 | uncompressed_size); | |
1500 | rc = inflateInit (&strm); | |
1501 | while (strm.avail_in > 0) | |
1502 | { | |
1503 | if (rc != Z_OK) | |
1504 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1505 | bfd_get_filename (abfd), rc); | |
1506 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1507 | + (uncompressed_size - strm.avail_out)); | |
1508 | rc = inflate (&strm, Z_FINISH); | |
1509 | if (rc != Z_STREAM_END) | |
1510 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1511 | bfd_get_filename (abfd), rc); | |
1512 | rc = inflateReset (&strm); | |
1513 | } | |
1514 | rc = inflateEnd (&strm); | |
1515 | if (rc != Z_OK | |
1516 | || strm.avail_out != 0) | |
1517 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1518 | bfd_get_filename (abfd), rc); | |
1519 | ||
affddf13 | 1520 | do_cleanups (cleanup); |
dce234bc PP |
1521 | *outbuf = uncompressed_buffer; |
1522 | *outsize = uncompressed_size; | |
1523 | #endif | |
233a11ab CS |
1524 | } |
1525 | ||
9e0ac564 TT |
1526 | /* A helper function that decides whether a section is empty. */ |
1527 | ||
1528 | static int | |
1529 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1530 | { | |
1531 | return info->asection == NULL || info->size == 0; | |
1532 | } | |
1533 | ||
9cdd5dbd | 1534 | /* Read the contents of the section INFO from object file specified by |
dce234bc PP |
1535 | OBJFILE, store info about the section into INFO. |
1536 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1537 | |
dce234bc PP |
1538 | static void |
1539 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1540 | { |
dce234bc PP |
1541 | bfd *abfd = objfile->obfd; |
1542 | asection *sectp = info->asection; | |
1543 | gdb_byte *buf, *retbuf; | |
1544 | unsigned char header[4]; | |
c906108c | 1545 | |
be391dca TT |
1546 | if (info->readin) |
1547 | return; | |
dce234bc | 1548 | info->buffer = NULL; |
b315ab21 | 1549 | info->map_addr = NULL; |
be391dca | 1550 | info->readin = 1; |
188dd5d6 | 1551 | |
9e0ac564 | 1552 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1553 | return; |
c906108c | 1554 | |
dce234bc PP |
1555 | /* Check if the file has a 4-byte header indicating compression. */ |
1556 | if (info->size > sizeof (header) | |
1557 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1558 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1559 | { | |
1560 | /* Upon decompression, update the buffer and its size. */ | |
1561 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1562 | { | |
1563 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1564 | &info->size); | |
1565 | return; | |
1566 | } | |
1567 | } | |
4bdf3d34 | 1568 | |
dce234bc PP |
1569 | #ifdef HAVE_MMAP |
1570 | if (pagesize == 0) | |
1571 | pagesize = getpagesize (); | |
2e276125 | 1572 | |
dce234bc PP |
1573 | /* Only try to mmap sections which are large enough: we don't want to |
1574 | waste space due to fragmentation. Also, only try mmap for sections | |
1575 | without relocations. */ | |
1576 | ||
1577 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1578 | { | |
b315ab21 TG |
1579 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
1580 | MAP_PRIVATE, sectp->filepos, | |
1581 | &info->map_addr, &info->map_len); | |
dce234bc | 1582 | |
b315ab21 | 1583 | if ((caddr_t)info->buffer != MAP_FAILED) |
dce234bc | 1584 | { |
be391dca | 1585 | #if HAVE_POSIX_MADVISE |
b315ab21 | 1586 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
be391dca | 1587 | #endif |
dce234bc PP |
1588 | return; |
1589 | } | |
1590 | } | |
1591 | #endif | |
1592 | ||
1593 | /* If we get here, we are a normal, not-compressed section. */ | |
1594 | info->buffer = buf | |
1595 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1596 | ||
1597 | /* When debugging .o files, we may need to apply relocations; see | |
1598 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1599 | We never compress sections in .o files, so we only need to | |
1600 | try this when the section is not compressed. */ | |
ac8035ab | 1601 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1602 | if (retbuf != NULL) |
1603 | { | |
1604 | info->buffer = retbuf; | |
1605 | return; | |
1606 | } | |
1607 | ||
1608 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1609 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1610 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1611 | bfd_get_filename (abfd)); | |
1612 | } | |
1613 | ||
9e0ac564 TT |
1614 | /* A helper function that returns the size of a section in a safe way. |
1615 | If you are positive that the section has been read before using the | |
1616 | size, then it is safe to refer to the dwarf2_section_info object's | |
1617 | "size" field directly. In other cases, you must call this | |
1618 | function, because for compressed sections the size field is not set | |
1619 | correctly until the section has been read. */ | |
1620 | ||
1621 | static bfd_size_type | |
1622 | dwarf2_section_size (struct objfile *objfile, | |
1623 | struct dwarf2_section_info *info) | |
1624 | { | |
1625 | if (!info->readin) | |
1626 | dwarf2_read_section (objfile, info); | |
1627 | return info->size; | |
1628 | } | |
1629 | ||
dce234bc | 1630 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1631 | SECTION_NAME. */ |
af34e669 | 1632 | |
dce234bc | 1633 | void |
3017a003 TG |
1634 | dwarf2_get_section_info (struct objfile *objfile, |
1635 | enum dwarf2_section_enum sect, | |
dce234bc PP |
1636 | asection **sectp, gdb_byte **bufp, |
1637 | bfd_size_type *sizep) | |
1638 | { | |
1639 | struct dwarf2_per_objfile *data | |
1640 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1641 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1642 | |
1643 | /* We may see an objfile without any DWARF, in which case we just | |
1644 | return nothing. */ | |
1645 | if (data == NULL) | |
1646 | { | |
1647 | *sectp = NULL; | |
1648 | *bufp = NULL; | |
1649 | *sizep = 0; | |
1650 | return; | |
1651 | } | |
3017a003 TG |
1652 | switch (sect) |
1653 | { | |
1654 | case DWARF2_DEBUG_FRAME: | |
1655 | info = &data->frame; | |
1656 | break; | |
1657 | case DWARF2_EH_FRAME: | |
1658 | info = &data->eh_frame; | |
1659 | break; | |
1660 | default: | |
1661 | gdb_assert_not_reached ("unexpected section"); | |
1662 | } | |
dce234bc | 1663 | |
9e0ac564 | 1664 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1665 | |
1666 | *sectp = info->asection; | |
1667 | *bufp = info->buffer; | |
1668 | *sizep = info->size; | |
1669 | } | |
1670 | ||
9291a0cd | 1671 | \f |
7b9f3c50 DE |
1672 | /* DWARF quick_symbols_functions support. */ |
1673 | ||
1674 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1675 | unique line tables, so we maintain a separate table of all .debug_line | |
1676 | derived entries to support the sharing. | |
1677 | All the quick functions need is the list of file names. We discard the | |
1678 | line_header when we're done and don't need to record it here. */ | |
1679 | struct quick_file_names | |
1680 | { | |
1681 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1682 | unsigned int offset; | |
1683 | ||
1684 | /* The number of entries in file_names, real_names. */ | |
1685 | unsigned int num_file_names; | |
1686 | ||
1687 | /* The file names from the line table, after being run through | |
1688 | file_full_name. */ | |
1689 | const char **file_names; | |
1690 | ||
1691 | /* The file names from the line table after being run through | |
1692 | gdb_realpath. These are computed lazily. */ | |
1693 | const char **real_names; | |
1694 | }; | |
1695 | ||
1696 | /* When using the index (and thus not using psymtabs), each CU has an | |
1697 | object of this type. This is used to hold information needed by | |
1698 | the various "quick" methods. */ | |
1699 | struct dwarf2_per_cu_quick_data | |
1700 | { | |
1701 | /* The file table. This can be NULL if there was no file table | |
1702 | or it's currently not read in. | |
1703 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1704 | struct quick_file_names *file_names; | |
1705 | ||
1706 | /* The corresponding symbol table. This is NULL if symbols for this | |
1707 | CU have not yet been read. */ | |
1708 | struct symtab *symtab; | |
1709 | ||
1710 | /* A temporary mark bit used when iterating over all CUs in | |
1711 | expand_symtabs_matching. */ | |
1712 | unsigned int mark : 1; | |
1713 | ||
1714 | /* True if we've tried to read the file table and found there isn't one. | |
1715 | There will be no point in trying to read it again next time. */ | |
1716 | unsigned int no_file_data : 1; | |
1717 | }; | |
1718 | ||
1719 | /* Hash function for a quick_file_names. */ | |
1720 | ||
1721 | static hashval_t | |
1722 | hash_file_name_entry (const void *e) | |
1723 | { | |
1724 | const struct quick_file_names *file_data = e; | |
1725 | ||
1726 | return file_data->offset; | |
1727 | } | |
1728 | ||
1729 | /* Equality function for a quick_file_names. */ | |
1730 | ||
1731 | static int | |
1732 | eq_file_name_entry (const void *a, const void *b) | |
1733 | { | |
1734 | const struct quick_file_names *ea = a; | |
1735 | const struct quick_file_names *eb = b; | |
1736 | ||
1737 | return ea->offset == eb->offset; | |
1738 | } | |
1739 | ||
1740 | /* Delete function for a quick_file_names. */ | |
1741 | ||
1742 | static void | |
1743 | delete_file_name_entry (void *e) | |
1744 | { | |
1745 | struct quick_file_names *file_data = e; | |
1746 | int i; | |
1747 | ||
1748 | for (i = 0; i < file_data->num_file_names; ++i) | |
1749 | { | |
1750 | xfree ((void*) file_data->file_names[i]); | |
1751 | if (file_data->real_names) | |
1752 | xfree ((void*) file_data->real_names[i]); | |
1753 | } | |
1754 | ||
1755 | /* The space for the struct itself lives on objfile_obstack, | |
1756 | so we don't free it here. */ | |
1757 | } | |
1758 | ||
1759 | /* Create a quick_file_names hash table. */ | |
1760 | ||
1761 | static htab_t | |
1762 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1763 | { | |
1764 | return htab_create_alloc (nr_initial_entries, | |
1765 | hash_file_name_entry, eq_file_name_entry, | |
1766 | delete_file_name_entry, xcalloc, xfree); | |
1767 | } | |
9291a0cd | 1768 | |
918dd910 JK |
1769 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
1770 | have to be created afterwards. You should call age_cached_comp_units after | |
1771 | processing PER_CU->CU. dw2_setup must have been already called. */ | |
1772 | ||
1773 | static void | |
1774 | load_cu (struct dwarf2_per_cu_data *per_cu) | |
1775 | { | |
b0df02fd | 1776 | if (per_cu->debug_types_section) |
e5fe5e75 | 1777 | load_full_type_unit (per_cu); |
918dd910 | 1778 | else |
a0f42c21 | 1779 | load_full_comp_unit (per_cu); |
918dd910 | 1780 | |
918dd910 | 1781 | gdb_assert (per_cu->cu != NULL); |
2dc860c0 DE |
1782 | |
1783 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); | |
918dd910 JK |
1784 | } |
1785 | ||
a0f42c21 | 1786 | /* Read in the symbols for PER_CU. */ |
2fdf6df6 | 1787 | |
9291a0cd | 1788 | static void |
a0f42c21 | 1789 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1790 | { |
1791 | struct cleanup *back_to; | |
1792 | ||
1793 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1794 | ||
a0f42c21 | 1795 | queue_comp_unit (per_cu); |
9291a0cd | 1796 | |
918dd910 | 1797 | load_cu (per_cu); |
9291a0cd | 1798 | |
a0f42c21 | 1799 | process_queue (); |
9291a0cd TT |
1800 | |
1801 | /* Age the cache, releasing compilation units that have not | |
1802 | been used recently. */ | |
1803 | age_cached_comp_units (); | |
1804 | ||
1805 | do_cleanups (back_to); | |
1806 | } | |
1807 | ||
1808 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1809 | the objfile from which this CU came. Returns the resulting symbol | |
1810 | table. */ | |
2fdf6df6 | 1811 | |
9291a0cd | 1812 | static struct symtab * |
a0f42c21 | 1813 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
9291a0cd TT |
1814 | { |
1815 | if (!per_cu->v.quick->symtab) | |
1816 | { | |
1817 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1818 | increment_reading_symtab (); | |
a0f42c21 | 1819 | dw2_do_instantiate_symtab (per_cu); |
9291a0cd TT |
1820 | do_cleanups (back_to); |
1821 | } | |
1822 | return per_cu->v.quick->symtab; | |
1823 | } | |
1824 | ||
1fd400ff | 1825 | /* Return the CU given its index. */ |
2fdf6df6 | 1826 | |
1fd400ff TT |
1827 | static struct dwarf2_per_cu_data * |
1828 | dw2_get_cu (int index) | |
1829 | { | |
1830 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1831 | { | |
1832 | index -= dwarf2_per_objfile->n_comp_units; | |
d467dd73 | 1833 | return dwarf2_per_objfile->all_type_units[index]; |
1fd400ff TT |
1834 | } |
1835 | return dwarf2_per_objfile->all_comp_units[index]; | |
1836 | } | |
1837 | ||
9291a0cd TT |
1838 | /* A helper function that knows how to read a 64-bit value in a way |
1839 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1840 | otherwise. */ | |
2fdf6df6 | 1841 | |
9291a0cd TT |
1842 | static int |
1843 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1844 | { | |
1845 | if (sizeof (ULONGEST) < 8) | |
1846 | { | |
1847 | int i; | |
1848 | ||
1849 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1850 | for (i = 0; i < 4; ++i) | |
1851 | if (bytes[i + 4] != 0) | |
1852 | return 0; | |
1853 | ||
1854 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1855 | } | |
1856 | else | |
1857 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1858 | return 1; | |
1859 | } | |
1860 | ||
1861 | /* Read the CU list from the mapped index, and use it to create all | |
1862 | the CU objects for this objfile. Return 0 if something went wrong, | |
1863 | 1 if everything went ok. */ | |
2fdf6df6 | 1864 | |
9291a0cd | 1865 | static int |
1fd400ff TT |
1866 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1867 | offset_type cu_list_elements) | |
9291a0cd TT |
1868 | { |
1869 | offset_type i; | |
9291a0cd TT |
1870 | |
1871 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1872 | dwarf2_per_objfile->all_comp_units | |
1873 | = obstack_alloc (&objfile->objfile_obstack, | |
1874 | dwarf2_per_objfile->n_comp_units | |
1875 | * sizeof (struct dwarf2_per_cu_data *)); | |
1876 | ||
1877 | for (i = 0; i < cu_list_elements; i += 2) | |
1878 | { | |
1879 | struct dwarf2_per_cu_data *the_cu; | |
1880 | ULONGEST offset, length; | |
1881 | ||
1882 | if (!extract_cu_value (cu_list, &offset) | |
1883 | || !extract_cu_value (cu_list + 8, &length)) | |
1884 | return 0; | |
1885 | cu_list += 2 * 8; | |
1886 | ||
1887 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1888 | struct dwarf2_per_cu_data); | |
b64f50a1 | 1889 | the_cu->offset.sect_off = offset; |
9291a0cd TT |
1890 | the_cu->length = length; |
1891 | the_cu->objfile = objfile; | |
1892 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1893 | struct dwarf2_per_cu_quick_data); | |
1894 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1895 | } | |
1896 | ||
1897 | return 1; | |
1898 | } | |
1899 | ||
1fd400ff | 1900 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1901 | |
1fd400ff | 1902 | static int |
673bfd45 | 1903 | create_signatured_type_table_from_index (struct objfile *objfile, |
8b70b953 | 1904 | struct dwarf2_section_info *section, |
673bfd45 DE |
1905 | const gdb_byte *bytes, |
1906 | offset_type elements) | |
1fd400ff TT |
1907 | { |
1908 | offset_type i; | |
673bfd45 | 1909 | htab_t sig_types_hash; |
1fd400ff | 1910 | |
d467dd73 DE |
1911 | dwarf2_per_objfile->n_type_units = elements / 3; |
1912 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 1913 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 1914 | dwarf2_per_objfile->n_type_units |
1fd400ff TT |
1915 | * sizeof (struct dwarf2_per_cu_data *)); |
1916 | ||
673bfd45 | 1917 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1918 | |
1919 | for (i = 0; i < elements; i += 3) | |
1920 | { | |
52dc124a DE |
1921 | struct signatured_type *sig_type; |
1922 | ULONGEST offset, type_offset_in_tu, signature; | |
1fd400ff TT |
1923 | void **slot; |
1924 | ||
1925 | if (!extract_cu_value (bytes, &offset) | |
52dc124a | 1926 | || !extract_cu_value (bytes + 8, &type_offset_in_tu)) |
1fd400ff TT |
1927 | return 0; |
1928 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1929 | bytes += 3 * 8; | |
1930 | ||
52dc124a | 1931 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1fd400ff | 1932 | struct signatured_type); |
52dc124a DE |
1933 | sig_type->signature = signature; |
1934 | sig_type->type_offset.cu_off = type_offset_in_tu; | |
1935 | sig_type->per_cu.debug_types_section = section; | |
1936 | sig_type->per_cu.offset.sect_off = offset; | |
1937 | sig_type->per_cu.objfile = objfile; | |
1938 | sig_type->per_cu.v.quick | |
1fd400ff TT |
1939 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
1940 | struct dwarf2_per_cu_quick_data); | |
1941 | ||
52dc124a DE |
1942 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
1943 | *slot = sig_type; | |
1fd400ff | 1944 | |
52dc124a | 1945 | dwarf2_per_objfile->all_type_units[i / 3] = &sig_type->per_cu; |
1fd400ff TT |
1946 | } |
1947 | ||
673bfd45 | 1948 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1949 | |
1950 | return 1; | |
1951 | } | |
1952 | ||
9291a0cd TT |
1953 | /* Read the address map data from the mapped index, and use it to |
1954 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1955 | |
9291a0cd TT |
1956 | static void |
1957 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1958 | { | |
1959 | const gdb_byte *iter, *end; | |
1960 | struct obstack temp_obstack; | |
1961 | struct addrmap *mutable_map; | |
1962 | struct cleanup *cleanup; | |
1963 | CORE_ADDR baseaddr; | |
1964 | ||
1965 | obstack_init (&temp_obstack); | |
1966 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1967 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1968 | ||
1969 | iter = index->address_table; | |
1970 | end = iter + index->address_table_size; | |
1971 | ||
1972 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1973 | ||
1974 | while (iter < end) | |
1975 | { | |
1976 | ULONGEST hi, lo, cu_index; | |
1977 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1978 | iter += 8; | |
1979 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1980 | iter += 8; | |
1981 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1982 | iter += 4; | |
1983 | ||
1984 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1985 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1986 | } |
1987 | ||
1988 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1989 | &objfile->objfile_obstack); | |
1990 | do_cleanups (cleanup); | |
1991 | } | |
1992 | ||
59d7bcaf JK |
1993 | /* The hash function for strings in the mapped index. This is the same as |
1994 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
1995 | implementation. This is necessary because the hash function is tied to the | |
1996 | format of the mapped index file. The hash values do not have to match with | |
559a7a62 JK |
1997 | SYMBOL_HASH_NEXT. |
1998 | ||
1999 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ | |
2fdf6df6 | 2000 | |
9291a0cd | 2001 | static hashval_t |
559a7a62 | 2002 | mapped_index_string_hash (int index_version, const void *p) |
9291a0cd TT |
2003 | { |
2004 | const unsigned char *str = (const unsigned char *) p; | |
2005 | hashval_t r = 0; | |
2006 | unsigned char c; | |
2007 | ||
2008 | while ((c = *str++) != 0) | |
559a7a62 JK |
2009 | { |
2010 | if (index_version >= 5) | |
2011 | c = tolower (c); | |
2012 | r = r * 67 + c - 113; | |
2013 | } | |
9291a0cd TT |
2014 | |
2015 | return r; | |
2016 | } | |
2017 | ||
2018 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
2019 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
2020 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 2021 | |
9291a0cd TT |
2022 | static int |
2023 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
2024 | offset_type **vec_out) | |
2025 | { | |
0cf03b49 JK |
2026 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2027 | offset_type hash; | |
9291a0cd | 2028 | offset_type slot, step; |
559a7a62 | 2029 | int (*cmp) (const char *, const char *); |
9291a0cd | 2030 | |
0cf03b49 JK |
2031 | if (current_language->la_language == language_cplus |
2032 | || current_language->la_language == language_java | |
2033 | || current_language->la_language == language_fortran) | |
2034 | { | |
2035 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2036 | not contain any. */ | |
2037 | const char *paren = strchr (name, '('); | |
2038 | ||
2039 | if (paren) | |
2040 | { | |
2041 | char *dup; | |
2042 | ||
2043 | dup = xmalloc (paren - name + 1); | |
2044 | memcpy (dup, name, paren - name); | |
2045 | dup[paren - name] = 0; | |
2046 | ||
2047 | make_cleanup (xfree, dup); | |
2048 | name = dup; | |
2049 | } | |
2050 | } | |
2051 | ||
559a7a62 | 2052 | /* Index version 4 did not support case insensitive searches. But the |
feea76c2 | 2053 | indices for case insensitive languages are built in lowercase, therefore |
559a7a62 JK |
2054 | simulate our NAME being searched is also lowercased. */ |
2055 | hash = mapped_index_string_hash ((index->version == 4 | |
2056 | && case_sensitivity == case_sensitive_off | |
2057 | ? 5 : index->version), | |
2058 | name); | |
2059 | ||
3876f04e DE |
2060 | slot = hash & (index->symbol_table_slots - 1); |
2061 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
559a7a62 | 2062 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
9291a0cd TT |
2063 | |
2064 | for (;;) | |
2065 | { | |
2066 | /* Convert a slot number to an offset into the table. */ | |
2067 | offset_type i = 2 * slot; | |
2068 | const char *str; | |
3876f04e | 2069 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2070 | { |
2071 | do_cleanups (back_to); | |
2072 | return 0; | |
2073 | } | |
9291a0cd | 2074 | |
3876f04e | 2075 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
559a7a62 | 2076 | if (!cmp (name, str)) |
9291a0cd TT |
2077 | { |
2078 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2079 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2080 | do_cleanups (back_to); |
9291a0cd TT |
2081 | return 1; |
2082 | } | |
2083 | ||
3876f04e | 2084 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2085 | } |
2086 | } | |
2087 | ||
2088 | /* Read the index file. If everything went ok, initialize the "quick" | |
2089 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2090 | |
9291a0cd TT |
2091 | static int |
2092 | dwarf2_read_index (struct objfile *objfile) | |
2093 | { | |
9291a0cd TT |
2094 | char *addr; |
2095 | struct mapped_index *map; | |
b3b272e1 | 2096 | offset_type *metadata; |
ac0b195c KW |
2097 | const gdb_byte *cu_list; |
2098 | const gdb_byte *types_list = NULL; | |
2099 | offset_type version, cu_list_elements; | |
2100 | offset_type types_list_elements = 0; | |
1fd400ff | 2101 | int i; |
9291a0cd | 2102 | |
9e0ac564 | 2103 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2104 | return 0; |
82430852 JK |
2105 | |
2106 | /* Older elfutils strip versions could keep the section in the main | |
2107 | executable while splitting it for the separate debug info file. */ | |
2108 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2109 | & SEC_HAS_CONTENTS) == 0) | |
2110 | return 0; | |
2111 | ||
9291a0cd TT |
2112 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2113 | ||
2114 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2115 | /* Version check. */ | |
1fd400ff | 2116 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2117 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2118 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f | 2119 | contained incomplete addrmap. So, it seems better to just ignore such |
481860b3 | 2120 | indices. */ |
831adc1f | 2121 | if (version < 4) |
481860b3 GB |
2122 | { |
2123 | static int warning_printed = 0; | |
2124 | if (!warning_printed) | |
2125 | { | |
2126 | warning (_("Skipping obsolete .gdb_index section in %s."), | |
2127 | objfile->name); | |
2128 | warning_printed = 1; | |
2129 | } | |
2130 | return 0; | |
2131 | } | |
2132 | /* Index version 4 uses a different hash function than index version | |
2133 | 5 and later. | |
2134 | ||
2135 | Versions earlier than 6 did not emit psymbols for inlined | |
2136 | functions. Using these files will cause GDB not to be able to | |
2137 | set breakpoints on inlined functions by name, so we ignore these | |
2138 | indices unless the --use-deprecated-index-sections command line | |
2139 | option was supplied. */ | |
2140 | if (version < 6 && !use_deprecated_index_sections) | |
2141 | { | |
2142 | static int warning_printed = 0; | |
2143 | if (!warning_printed) | |
2144 | { | |
2145 | warning (_("Skipping deprecated .gdb_index section in %s, pass " | |
2146 | "--use-deprecated-index-sections to use them anyway"), | |
2147 | objfile->name); | |
2148 | warning_printed = 1; | |
2149 | } | |
2150 | return 0; | |
2151 | } | |
2152 | /* Indexes with higher version than the one supported by GDB may be no | |
594e8718 | 2153 | longer backward compatible. */ |
481860b3 | 2154 | if (version > 6) |
594e8718 | 2155 | return 0; |
9291a0cd TT |
2156 | |
2157 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
559a7a62 | 2158 | map->version = version; |
b3b272e1 | 2159 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2160 | |
2161 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2162 | |
2163 | i = 0; | |
2164 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2165 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2166 | / 8); |
1fd400ff TT |
2167 | ++i; |
2168 | ||
987d643c TT |
2169 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2170 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2171 | - MAYBE_SWAP (metadata[i])) | |
2172 | / 8); | |
2173 | ++i; | |
1fd400ff TT |
2174 | |
2175 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2176 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2177 | - MAYBE_SWAP (metadata[i])); | |
2178 | ++i; | |
2179 | ||
3876f04e DE |
2180 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2181 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2182 | - MAYBE_SWAP (metadata[i])) | |
2183 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2184 | ++i; |
9291a0cd | 2185 | |
1fd400ff TT |
2186 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2187 | ||
0fefef59 DE |
2188 | /* Don't use the index if it's empty. */ |
2189 | if (map->symbol_table_slots == 0) | |
2190 | return 0; | |
2191 | ||
1fd400ff TT |
2192 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) |
2193 | return 0; | |
2194 | ||
8b70b953 TT |
2195 | if (types_list_elements) |
2196 | { | |
2197 | struct dwarf2_section_info *section; | |
2198 | ||
2199 | /* We can only handle a single .debug_types when we have an | |
2200 | index. */ | |
2201 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) | |
2202 | return 0; | |
2203 | ||
2204 | section = VEC_index (dwarf2_section_info_def, | |
2205 | dwarf2_per_objfile->types, 0); | |
2206 | ||
2207 | if (!create_signatured_type_table_from_index (objfile, section, | |
2208 | types_list, | |
2209 | types_list_elements)) | |
2210 | return 0; | |
2211 | } | |
9291a0cd TT |
2212 | |
2213 | create_addrmap_from_index (objfile, map); | |
2214 | ||
2215 | dwarf2_per_objfile->index_table = map; | |
2216 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2217 | dwarf2_per_objfile->quick_file_names_table = |
2218 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2219 | |
2220 | return 1; | |
2221 | } | |
2222 | ||
2223 | /* A helper for the "quick" functions which sets the global | |
2224 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2225 | |
9291a0cd TT |
2226 | static void |
2227 | dw2_setup (struct objfile *objfile) | |
2228 | { | |
2229 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2230 | gdb_assert (dwarf2_per_objfile); | |
2231 | } | |
2232 | ||
dee91e82 | 2233 | /* die_reader_func for dw2_get_file_names. */ |
2fdf6df6 | 2234 | |
dee91e82 DE |
2235 | static void |
2236 | dw2_get_file_names_reader (const struct die_reader_specs *reader, | |
2237 | gdb_byte *info_ptr, | |
2238 | struct die_info *comp_unit_die, | |
2239 | int has_children, | |
2240 | void *data) | |
9291a0cd | 2241 | { |
dee91e82 DE |
2242 | struct dwarf2_cu *cu = reader->cu; |
2243 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; | |
2244 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
9291a0cd | 2245 | bfd *abfd = objfile->obfd; |
7b9f3c50 | 2246 | struct line_header *lh; |
9291a0cd | 2247 | struct attribute *attr; |
dee91e82 | 2248 | int i; |
9ff913ba | 2249 | unsigned int bytes_read; |
9291a0cd | 2250 | char *name, *comp_dir; |
7b9f3c50 DE |
2251 | void **slot; |
2252 | struct quick_file_names *qfn; | |
2253 | unsigned int line_offset; | |
9291a0cd | 2254 | |
7b9f3c50 DE |
2255 | lh = NULL; |
2256 | slot = NULL; | |
2257 | line_offset = 0; | |
dee91e82 DE |
2258 | |
2259 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); | |
9291a0cd TT |
2260 | if (attr) |
2261 | { | |
7b9f3c50 DE |
2262 | struct quick_file_names find_entry; |
2263 | ||
2264 | line_offset = DW_UNSND (attr); | |
2265 | ||
2266 | /* We may have already read in this line header (TU line header sharing). | |
2267 | If we have we're done. */ | |
2268 | find_entry.offset = line_offset; | |
2269 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2270 | &find_entry, INSERT); | |
2271 | if (*slot != NULL) | |
2272 | { | |
7b9f3c50 | 2273 | this_cu->v.quick->file_names = *slot; |
dee91e82 | 2274 | return; |
7b9f3c50 DE |
2275 | } |
2276 | ||
dee91e82 | 2277 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
9291a0cd TT |
2278 | } |
2279 | if (lh == NULL) | |
2280 | { | |
7b9f3c50 | 2281 | this_cu->v.quick->no_file_data = 1; |
dee91e82 | 2282 | return; |
9291a0cd TT |
2283 | } |
2284 | ||
7b9f3c50 DE |
2285 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2286 | qfn->offset = line_offset; | |
2287 | gdb_assert (slot != NULL); | |
2288 | *slot = qfn; | |
9291a0cd | 2289 | |
dee91e82 | 2290 | find_file_and_directory (comp_unit_die, cu, &name, &comp_dir); |
9291a0cd | 2291 | |
7b9f3c50 DE |
2292 | qfn->num_file_names = lh->num_file_names; |
2293 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2294 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2295 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2296 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2297 | qfn->real_names = NULL; | |
9291a0cd | 2298 | |
7b9f3c50 | 2299 | free_line_header (lh); |
7b9f3c50 DE |
2300 | |
2301 | this_cu->v.quick->file_names = qfn; | |
dee91e82 DE |
2302 | } |
2303 | ||
2304 | /* A helper for the "quick" functions which attempts to read the line | |
2305 | table for THIS_CU. */ | |
2306 | ||
2307 | static struct quick_file_names * | |
2308 | dw2_get_file_names (struct objfile *objfile, | |
2309 | struct dwarf2_per_cu_data *this_cu) | |
2310 | { | |
2311 | if (this_cu->v.quick->file_names != NULL) | |
2312 | return this_cu->v.quick->file_names; | |
2313 | /* If we know there is no line data, no point in looking again. */ | |
2314 | if (this_cu->v.quick->no_file_data) | |
2315 | return NULL; | |
2316 | ||
2317 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); | |
2318 | ||
2319 | if (this_cu->v.quick->no_file_data) | |
2320 | return NULL; | |
2321 | return this_cu->v.quick->file_names; | |
9291a0cd TT |
2322 | } |
2323 | ||
2324 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2325 | real path for a given file name from the line table. */ |
2fdf6df6 | 2326 | |
9291a0cd | 2327 | static const char * |
7b9f3c50 DE |
2328 | dw2_get_real_path (struct objfile *objfile, |
2329 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2330 | { |
7b9f3c50 DE |
2331 | if (qfn->real_names == NULL) |
2332 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2333 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2334 | |
7b9f3c50 DE |
2335 | if (qfn->real_names[index] == NULL) |
2336 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2337 | |
7b9f3c50 | 2338 | return qfn->real_names[index]; |
9291a0cd TT |
2339 | } |
2340 | ||
2341 | static struct symtab * | |
2342 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2343 | { | |
2344 | int index; | |
ae2de4f8 | 2345 | |
9291a0cd TT |
2346 | dw2_setup (objfile); |
2347 | index = dwarf2_per_objfile->n_comp_units - 1; | |
a0f42c21 | 2348 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
9291a0cd TT |
2349 | } |
2350 | ||
7b9f3c50 DE |
2351 | /* Traversal function for dw2_forget_cached_source_info. */ |
2352 | ||
2353 | static int | |
2354 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2355 | { |
7b9f3c50 | 2356 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2357 | |
7b9f3c50 | 2358 | if (file_data->real_names) |
9291a0cd | 2359 | { |
7b9f3c50 | 2360 | int i; |
9291a0cd | 2361 | |
7b9f3c50 | 2362 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2363 | { |
7b9f3c50 DE |
2364 | xfree ((void*) file_data->real_names[i]); |
2365 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2366 | } |
2367 | } | |
7b9f3c50 DE |
2368 | |
2369 | return 1; | |
2370 | } | |
2371 | ||
2372 | static void | |
2373 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2374 | { | |
2375 | dw2_setup (objfile); | |
2376 | ||
2377 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2378 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2379 | } |
2380 | ||
f8eba3c6 TT |
2381 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
2382 | the symtabs and calls the iterator. */ | |
2383 | ||
2384 | static int | |
2385 | dw2_map_expand_apply (struct objfile *objfile, | |
2386 | struct dwarf2_per_cu_data *per_cu, | |
2387 | const char *name, | |
2388 | const char *full_path, const char *real_path, | |
2389 | int (*callback) (struct symtab *, void *), | |
2390 | void *data) | |
2391 | { | |
2392 | struct symtab *last_made = objfile->symtabs; | |
2393 | ||
2394 | /* Don't visit already-expanded CUs. */ | |
2395 | if (per_cu->v.quick->symtab) | |
2396 | return 0; | |
2397 | ||
2398 | /* This may expand more than one symtab, and we want to iterate over | |
2399 | all of them. */ | |
a0f42c21 | 2400 | dw2_instantiate_symtab (per_cu); |
f8eba3c6 TT |
2401 | |
2402 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, | |
2403 | objfile->symtabs, last_made); | |
2404 | } | |
2405 | ||
2406 | /* Implementation of the map_symtabs_matching_filename method. */ | |
2407 | ||
9291a0cd | 2408 | static int |
f8eba3c6 TT |
2409 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
2410 | const char *full_path, const char *real_path, | |
2411 | int (*callback) (struct symtab *, void *), | |
2412 | void *data) | |
9291a0cd TT |
2413 | { |
2414 | int i; | |
c011a4f4 | 2415 | const char *name_basename = lbasename (name); |
4aac40c8 TT |
2416 | int name_len = strlen (name); |
2417 | int is_abs = IS_ABSOLUTE_PATH (name); | |
9291a0cd TT |
2418 | |
2419 | dw2_setup (objfile); | |
ae2de4f8 | 2420 | |
1fd400ff | 2421 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2422 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2423 | { |
2424 | int j; | |
e254ef6a | 2425 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2426 | struct quick_file_names *file_data; |
9291a0cd | 2427 | |
3d7bb9d9 | 2428 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2429 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2430 | continue; |
2431 | ||
7b9f3c50 DE |
2432 | file_data = dw2_get_file_names (objfile, per_cu); |
2433 | if (file_data == NULL) | |
9291a0cd TT |
2434 | continue; |
2435 | ||
7b9f3c50 | 2436 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2437 | { |
7b9f3c50 | 2438 | const char *this_name = file_data->file_names[j]; |
9291a0cd | 2439 | |
4aac40c8 TT |
2440 | if (FILENAME_CMP (name, this_name) == 0 |
2441 | || (!is_abs && compare_filenames_for_search (this_name, | |
2442 | name, name_len))) | |
9291a0cd | 2443 | { |
f8eba3c6 TT |
2444 | if (dw2_map_expand_apply (objfile, per_cu, |
2445 | name, full_path, real_path, | |
2446 | callback, data)) | |
2447 | return 1; | |
4aac40c8 | 2448 | } |
9291a0cd | 2449 | |
c011a4f4 DE |
2450 | /* Before we invoke realpath, which can get expensive when many |
2451 | files are involved, do a quick comparison of the basenames. */ | |
2452 | if (! basenames_may_differ | |
2453 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) | |
2454 | continue; | |
2455 | ||
9291a0cd TT |
2456 | if (full_path != NULL) |
2457 | { | |
7b9f3c50 DE |
2458 | const char *this_real_name = dw2_get_real_path (objfile, |
2459 | file_data, j); | |
9291a0cd | 2460 | |
7b9f3c50 | 2461 | if (this_real_name != NULL |
4aac40c8 TT |
2462 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
2463 | || (!is_abs | |
2464 | && compare_filenames_for_search (this_real_name, | |
2465 | name, name_len)))) | |
9291a0cd | 2466 | { |
f8eba3c6 TT |
2467 | if (dw2_map_expand_apply (objfile, per_cu, |
2468 | name, full_path, real_path, | |
2469 | callback, data)) | |
2470 | return 1; | |
9291a0cd TT |
2471 | } |
2472 | } | |
2473 | ||
2474 | if (real_path != NULL) | |
2475 | { | |
7b9f3c50 DE |
2476 | const char *this_real_name = dw2_get_real_path (objfile, |
2477 | file_data, j); | |
9291a0cd | 2478 | |
7b9f3c50 | 2479 | if (this_real_name != NULL |
4aac40c8 TT |
2480 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
2481 | || (!is_abs | |
2482 | && compare_filenames_for_search (this_real_name, | |
2483 | name, name_len)))) | |
9291a0cd | 2484 | { |
f8eba3c6 TT |
2485 | if (dw2_map_expand_apply (objfile, per_cu, |
2486 | name, full_path, real_path, | |
2487 | callback, data)) | |
2488 | return 1; | |
9291a0cd TT |
2489 | } |
2490 | } | |
2491 | } | |
2492 | } | |
2493 | ||
9291a0cd TT |
2494 | return 0; |
2495 | } | |
2496 | ||
2497 | static struct symtab * | |
2498 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2499 | const char *name, domain_enum domain) | |
2500 | { | |
774b6a14 | 2501 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2502 | instead. */ |
2503 | return NULL; | |
2504 | } | |
2505 | ||
2506 | /* A helper function that expands all symtabs that hold an object | |
2507 | named NAME. */ | |
2fdf6df6 | 2508 | |
9291a0cd TT |
2509 | static void |
2510 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2511 | { | |
2512 | dw2_setup (objfile); | |
2513 | ||
ae2de4f8 | 2514 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2515 | if (dwarf2_per_objfile->index_table) |
2516 | { | |
2517 | offset_type *vec; | |
2518 | ||
2519 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2520 | name, &vec)) | |
2521 | { | |
2522 | offset_type i, len = MAYBE_SWAP (*vec); | |
2523 | for (i = 0; i < len; ++i) | |
2524 | { | |
2525 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2526 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2527 | |
a0f42c21 | 2528 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2529 | } |
2530 | } | |
2531 | } | |
2532 | } | |
2533 | ||
774b6a14 TT |
2534 | static void |
2535 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2536 | enum block_enum block_kind, const char *name, |
774b6a14 | 2537 | domain_enum domain) |
9291a0cd | 2538 | { |
774b6a14 | 2539 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2540 | } |
2541 | ||
2542 | static void | |
2543 | dw2_print_stats (struct objfile *objfile) | |
2544 | { | |
2545 | int i, count; | |
2546 | ||
2547 | dw2_setup (objfile); | |
2548 | count = 0; | |
1fd400ff | 2549 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2550 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2551 | { |
e254ef6a | 2552 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2553 | |
e254ef6a | 2554 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2555 | ++count; |
2556 | } | |
2557 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2558 | } | |
2559 | ||
2560 | static void | |
2561 | dw2_dump (struct objfile *objfile) | |
2562 | { | |
2563 | /* Nothing worth printing. */ | |
2564 | } | |
2565 | ||
2566 | static void | |
2567 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2568 | struct section_offsets *delta) | |
2569 | { | |
2570 | /* There's nothing to relocate here. */ | |
2571 | } | |
2572 | ||
2573 | static void | |
2574 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2575 | const char *func_name) | |
2576 | { | |
2577 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2578 | } | |
2579 | ||
2580 | static void | |
2581 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2582 | { | |
2583 | int i; | |
2584 | ||
2585 | dw2_setup (objfile); | |
1fd400ff TT |
2586 | |
2587 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
d467dd73 | 2588 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2589 | { |
e254ef6a | 2590 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2591 | |
a0f42c21 | 2592 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2593 | } |
2594 | } | |
2595 | ||
2596 | static void | |
2597 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2598 | const char *filename) | |
2599 | { | |
2600 | int i; | |
2601 | ||
2602 | dw2_setup (objfile); | |
d4637a04 DE |
2603 | |
2604 | /* We don't need to consider type units here. | |
2605 | This is only called for examining code, e.g. expand_line_sal. | |
2606 | There can be an order of magnitude (or more) more type units | |
2607 | than comp units, and we avoid them if we can. */ | |
2608 | ||
2609 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2610 | { |
2611 | int j; | |
e254ef6a | 2612 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2613 | struct quick_file_names *file_data; |
9291a0cd | 2614 | |
3d7bb9d9 | 2615 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2616 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2617 | continue; |
2618 | ||
7b9f3c50 DE |
2619 | file_data = dw2_get_file_names (objfile, per_cu); |
2620 | if (file_data == NULL) | |
9291a0cd TT |
2621 | continue; |
2622 | ||
7b9f3c50 | 2623 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2624 | { |
7b9f3c50 | 2625 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2626 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2627 | { |
a0f42c21 | 2628 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2629 | break; |
2630 | } | |
2631 | } | |
2632 | } | |
2633 | } | |
2634 | ||
dd786858 | 2635 | static const char * |
9291a0cd TT |
2636 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2637 | { | |
e254ef6a | 2638 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2639 | offset_type *vec; |
7b9f3c50 | 2640 | struct quick_file_names *file_data; |
9291a0cd TT |
2641 | |
2642 | dw2_setup (objfile); | |
2643 | ||
ae2de4f8 | 2644 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd | 2645 | if (!dwarf2_per_objfile->index_table) |
96408a79 SA |
2646 | { |
2647 | struct symtab *s; | |
2648 | ||
2649 | ALL_OBJFILE_SYMTABS (objfile, s) | |
2650 | if (s->primary) | |
2651 | { | |
2652 | struct blockvector *bv = BLOCKVECTOR (s); | |
2653 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); | |
2654 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); | |
2655 | ||
2656 | if (sym) | |
2657 | return sym->symtab->filename; | |
2658 | } | |
2659 | return NULL; | |
2660 | } | |
9291a0cd TT |
2661 | |
2662 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2663 | name, &vec)) | |
2664 | return NULL; | |
2665 | ||
2666 | /* Note that this just looks at the very first one named NAME -- but | |
2667 | actually we are looking for a function. find_main_filename | |
2668 | should be rewritten so that it doesn't require a custom hook. It | |
2669 | could just use the ordinary symbol tables. */ | |
2670 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2671 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2672 | |
7b9f3c50 DE |
2673 | file_data = dw2_get_file_names (objfile, per_cu); |
2674 | if (file_data == NULL) | |
9291a0cd TT |
2675 | return NULL; |
2676 | ||
7b9f3c50 | 2677 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2678 | } |
2679 | ||
2680 | static void | |
40658b94 PH |
2681 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2682 | struct objfile *objfile, int global, | |
2683 | int (*callback) (struct block *, | |
2684 | struct symbol *, void *), | |
2edb89d3 JK |
2685 | void *data, symbol_compare_ftype *match, |
2686 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2687 | { |
40658b94 | 2688 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2689 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2690 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2691 | } |
2692 | ||
2693 | static void | |
f8eba3c6 TT |
2694 | dw2_expand_symtabs_matching |
2695 | (struct objfile *objfile, | |
2696 | int (*file_matcher) (const char *, void *), | |
e078317b | 2697 | int (*name_matcher) (const char *, void *), |
f8eba3c6 TT |
2698 | enum search_domain kind, |
2699 | void *data) | |
9291a0cd TT |
2700 | { |
2701 | int i; | |
2702 | offset_type iter; | |
4b5246aa | 2703 | struct mapped_index *index; |
9291a0cd TT |
2704 | |
2705 | dw2_setup (objfile); | |
ae2de4f8 DE |
2706 | |
2707 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2708 | if (!dwarf2_per_objfile->index_table) |
2709 | return; | |
4b5246aa | 2710 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2711 | |
7b08b9eb | 2712 | if (file_matcher != NULL) |
24c79950 TT |
2713 | { |
2714 | struct cleanup *cleanup; | |
2715 | htab_t visited_found, visited_not_found; | |
2716 | ||
2717 | visited_found = htab_create_alloc (10, | |
2718 | htab_hash_pointer, htab_eq_pointer, | |
2719 | NULL, xcalloc, xfree); | |
2720 | cleanup = make_cleanup_htab_delete (visited_found); | |
2721 | visited_not_found = htab_create_alloc (10, | |
2722 | htab_hash_pointer, htab_eq_pointer, | |
2723 | NULL, xcalloc, xfree); | |
2724 | make_cleanup_htab_delete (visited_not_found); | |
2725 | ||
2726 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2727 | + dwarf2_per_objfile->n_type_units); ++i) | |
2728 | { | |
2729 | int j; | |
2730 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2731 | struct quick_file_names *file_data; | |
2732 | void **slot; | |
7b08b9eb | 2733 | |
24c79950 | 2734 | per_cu->v.quick->mark = 0; |
3d7bb9d9 | 2735 | |
24c79950 TT |
2736 | /* We only need to look at symtabs not already expanded. */ |
2737 | if (per_cu->v.quick->symtab) | |
2738 | continue; | |
7b08b9eb | 2739 | |
24c79950 TT |
2740 | file_data = dw2_get_file_names (objfile, per_cu); |
2741 | if (file_data == NULL) | |
2742 | continue; | |
7b08b9eb | 2743 | |
24c79950 TT |
2744 | if (htab_find (visited_not_found, file_data) != NULL) |
2745 | continue; | |
2746 | else if (htab_find (visited_found, file_data) != NULL) | |
2747 | { | |
2748 | per_cu->v.quick->mark = 1; | |
2749 | continue; | |
2750 | } | |
2751 | ||
2752 | for (j = 0; j < file_data->num_file_names; ++j) | |
2753 | { | |
2754 | if (file_matcher (file_data->file_names[j], data)) | |
2755 | { | |
2756 | per_cu->v.quick->mark = 1; | |
2757 | break; | |
2758 | } | |
2759 | } | |
2760 | ||
2761 | slot = htab_find_slot (per_cu->v.quick->mark | |
2762 | ? visited_found | |
2763 | : visited_not_found, | |
2764 | file_data, INSERT); | |
2765 | *slot = file_data; | |
2766 | } | |
2767 | ||
2768 | do_cleanups (cleanup); | |
2769 | } | |
9291a0cd | 2770 | |
3876f04e | 2771 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2772 | { |
2773 | offset_type idx = 2 * iter; | |
2774 | const char *name; | |
2775 | offset_type *vec, vec_len, vec_idx; | |
2776 | ||
3876f04e | 2777 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2778 | continue; |
2779 | ||
3876f04e | 2780 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd | 2781 | |
e078317b | 2782 | if (! (*name_matcher) (name, data)) |
9291a0cd TT |
2783 | continue; |
2784 | ||
2785 | /* The name was matched, now expand corresponding CUs that were | |
2786 | marked. */ | |
4b5246aa | 2787 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2788 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2789 | vec_len = MAYBE_SWAP (vec[0]); |
2790 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2791 | { | |
e254ef6a | 2792 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2793 | |
e254ef6a | 2794 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
7b08b9eb | 2795 | if (file_matcher == NULL || per_cu->v.quick->mark) |
a0f42c21 | 2796 | dw2_instantiate_symtab (per_cu); |
9291a0cd TT |
2797 | } |
2798 | } | |
2799 | } | |
2800 | ||
2801 | static struct symtab * | |
2802 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2803 | struct minimal_symbol *msymbol, | |
2804 | CORE_ADDR pc, | |
2805 | struct obj_section *section, | |
2806 | int warn_if_readin) | |
2807 | { | |
2808 | struct dwarf2_per_cu_data *data; | |
2809 | ||
2810 | dw2_setup (objfile); | |
2811 | ||
2812 | if (!objfile->psymtabs_addrmap) | |
2813 | return NULL; | |
2814 | ||
2815 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2816 | if (!data) | |
2817 | return NULL; | |
2818 | ||
2819 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2820 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2821 | paddress (get_objfile_arch (objfile), pc)); |
2822 | ||
a0f42c21 | 2823 | return dw2_instantiate_symtab (data); |
9291a0cd TT |
2824 | } |
2825 | ||
9291a0cd | 2826 | static void |
44b13c5a | 2827 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
74e2f255 | 2828 | void *data, int need_fullname) |
9291a0cd TT |
2829 | { |
2830 | int i; | |
24c79950 TT |
2831 | struct cleanup *cleanup; |
2832 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, | |
2833 | NULL, xcalloc, xfree); | |
9291a0cd | 2834 | |
24c79950 | 2835 | cleanup = make_cleanup_htab_delete (visited); |
9291a0cd | 2836 | dw2_setup (objfile); |
ae2de4f8 | 2837 | |
24c79950 TT |
2838 | /* We can ignore file names coming from already-expanded CUs. */ |
2839 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2840 | + dwarf2_per_objfile->n_type_units); ++i) | |
2841 | { | |
2842 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); | |
2843 | ||
2844 | if (per_cu->v.quick->symtab) | |
2845 | { | |
2846 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, | |
2847 | INSERT); | |
2848 | ||
2849 | *slot = per_cu->v.quick->file_names; | |
2850 | } | |
2851 | } | |
2852 | ||
1fd400ff | 2853 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2854 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd TT |
2855 | { |
2856 | int j; | |
e254ef6a | 2857 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2858 | struct quick_file_names *file_data; |
24c79950 | 2859 | void **slot; |
9291a0cd | 2860 | |
3d7bb9d9 | 2861 | /* We only need to look at symtabs not already expanded. */ |
e254ef6a | 2862 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2863 | continue; |
2864 | ||
7b9f3c50 DE |
2865 | file_data = dw2_get_file_names (objfile, per_cu); |
2866 | if (file_data == NULL) | |
9291a0cd TT |
2867 | continue; |
2868 | ||
24c79950 TT |
2869 | slot = htab_find_slot (visited, file_data, INSERT); |
2870 | if (*slot) | |
2871 | { | |
2872 | /* Already visited. */ | |
2873 | continue; | |
2874 | } | |
2875 | *slot = file_data; | |
2876 | ||
7b9f3c50 | 2877 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2878 | { |
74e2f255 DE |
2879 | const char *this_real_name; |
2880 | ||
2881 | if (need_fullname) | |
2882 | this_real_name = dw2_get_real_path (objfile, file_data, j); | |
2883 | else | |
2884 | this_real_name = NULL; | |
7b9f3c50 | 2885 | (*fun) (file_data->file_names[j], this_real_name, data); |
9291a0cd TT |
2886 | } |
2887 | } | |
24c79950 TT |
2888 | |
2889 | do_cleanups (cleanup); | |
9291a0cd TT |
2890 | } |
2891 | ||
2892 | static int | |
2893 | dw2_has_symbols (struct objfile *objfile) | |
2894 | { | |
2895 | return 1; | |
2896 | } | |
2897 | ||
2898 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2899 | { | |
2900 | dw2_has_symbols, | |
2901 | dw2_find_last_source_symtab, | |
2902 | dw2_forget_cached_source_info, | |
f8eba3c6 | 2903 | dw2_map_symtabs_matching_filename, |
9291a0cd | 2904 | dw2_lookup_symbol, |
774b6a14 | 2905 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2906 | dw2_print_stats, |
2907 | dw2_dump, | |
2908 | dw2_relocate, | |
2909 | dw2_expand_symtabs_for_function, | |
2910 | dw2_expand_all_symtabs, | |
2911 | dw2_expand_symtabs_with_filename, | |
2912 | dw2_find_symbol_file, | |
40658b94 | 2913 | dw2_map_matching_symbols, |
9291a0cd TT |
2914 | dw2_expand_symtabs_matching, |
2915 | dw2_find_pc_sect_symtab, | |
9291a0cd TT |
2916 | dw2_map_symbol_filenames |
2917 | }; | |
2918 | ||
2919 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2920 | file will use psymtabs, or 1 if using the GNU index. */ | |
2921 | ||
2922 | int | |
2923 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2924 | { | |
2925 | /* If we're about to read full symbols, don't bother with the | |
2926 | indices. In this case we also don't care if some other debug | |
2927 | format is making psymtabs, because they are all about to be | |
2928 | expanded anyway. */ | |
2929 | if ((objfile->flags & OBJF_READNOW)) | |
2930 | { | |
2931 | int i; | |
2932 | ||
2933 | dwarf2_per_objfile->using_index = 1; | |
2934 | create_all_comp_units (objfile); | |
0e50663e | 2935 | create_all_type_units (objfile); |
7b9f3c50 DE |
2936 | dwarf2_per_objfile->quick_file_names_table = |
2937 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2938 | |
1fd400ff | 2939 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
d467dd73 | 2940 | + dwarf2_per_objfile->n_type_units); ++i) |
9291a0cd | 2941 | { |
e254ef6a | 2942 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2943 | |
e254ef6a DE |
2944 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2945 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2946 | } |
2947 | ||
2948 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2949 | these functions will be no-ops because we will have expanded | |
2950 | all symtabs. */ | |
2951 | return 1; | |
2952 | } | |
2953 | ||
2954 | if (dwarf2_read_index (objfile)) | |
2955 | return 1; | |
2956 | ||
9291a0cd TT |
2957 | return 0; |
2958 | } | |
2959 | ||
2960 | \f | |
2961 | ||
dce234bc PP |
2962 | /* Build a partial symbol table. */ |
2963 | ||
2964 | void | |
f29dff0a | 2965 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2966 | { |
f29dff0a | 2967 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2968 | { |
2969 | init_psymbol_list (objfile, 1024); | |
2970 | } | |
2971 | ||
d146bf1e | 2972 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2973 | } |
c906108c | 2974 | |
45452591 DE |
2975 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2976 | ||
2977 | static inline int | |
b64f50a1 | 2978 | offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset) |
45452591 | 2979 | { |
b64f50a1 JK |
2980 | sect_offset bottom = { cu_header->offset.sect_off }; |
2981 | sect_offset top = { (cu_header->offset.sect_off + cu_header->length | |
2982 | + cu_header->initial_length_size) }; | |
9a619af0 | 2983 | |
b64f50a1 | 2984 | return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off); |
45452591 DE |
2985 | } |
2986 | ||
93311388 DE |
2987 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2988 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2989 | by the caller. */ | |
107d2387 | 2990 | |
fe1b8b76 | 2991 | static gdb_byte * |
107d2387 | 2992 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2993 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2994 | { |
2995 | int signed_addr; | |
891d2f0b | 2996 | unsigned int bytes_read; |
c764a876 DE |
2997 | |
2998 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2999 | cu_header->initial_length_size = bytes_read; | |
3000 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 3001 | info_ptr += bytes_read; |
107d2387 AC |
3002 | cu_header->version = read_2_bytes (abfd, info_ptr); |
3003 | info_ptr += 2; | |
b64f50a1 JK |
3004 | cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header, |
3005 | &bytes_read); | |
613e1657 | 3006 | info_ptr += bytes_read; |
107d2387 AC |
3007 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
3008 | info_ptr += 1; | |
3009 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
3010 | if (signed_addr < 0) | |
8e65ff28 | 3011 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3012 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 3013 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 3014 | |
107d2387 AC |
3015 | return info_ptr; |
3016 | } | |
3017 | ||
9ff913ba DE |
3018 | /* Subroutine of read_and_check_comp_unit_head and |
3019 | read_and_check_type_unit_head to simplify them. | |
3020 | Perform various error checking on the header. */ | |
3021 | ||
3022 | static void | |
3023 | error_check_comp_unit_head (struct comp_unit_head *header, | |
3024 | struct dwarf2_section_info *section) | |
3025 | { | |
3026 | bfd *abfd = section->asection->owner; | |
3027 | const char *filename = bfd_get_filename (abfd); | |
3028 | ||
3029 | if (header->version != 2 && header->version != 3 && header->version != 4) | |
3030 | error (_("Dwarf Error: wrong version in compilation unit header " | |
3031 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, | |
3032 | filename); | |
3033 | ||
b64f50a1 | 3034 | if (header->abbrev_offset.sect_off |
9ff913ba DE |
3035 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, |
3036 | &dwarf2_per_objfile->abbrev)) | |
3037 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
3038 | "(offset 0x%lx + 6) [in module %s]"), | |
b64f50a1 | 3039 | (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off, |
9ff913ba DE |
3040 | filename); |
3041 | ||
3042 | /* Cast to unsigned long to use 64-bit arithmetic when possible to | |
3043 | avoid potential 32-bit overflow. */ | |
b64f50a1 | 3044 | if (((unsigned long) header->offset.sect_off |
9ff913ba DE |
3045 | + header->length + header->initial_length_size) |
3046 | > section->size) | |
3047 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
3048 | "(offset 0x%lx + 0) [in module %s]"), | |
b64f50a1 | 3049 | (long) header->length, (long) header->offset.sect_off, |
9ff913ba DE |
3050 | filename); |
3051 | } | |
3052 | ||
3053 | /* Read in a CU/TU header and perform some basic error checking. | |
3054 | The contents of the header are stored in HEADER. | |
3055 | The result is a pointer to the start of the first DIE. */ | |
adabb602 | 3056 | |
fe1b8b76 | 3057 | static gdb_byte * |
9ff913ba DE |
3058 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
3059 | struct dwarf2_section_info *section, | |
3060 | gdb_byte *info_ptr, | |
3061 | int is_debug_types_section) | |
72bf9492 | 3062 | { |
fe1b8b76 | 3063 | gdb_byte *beg_of_comp_unit = info_ptr; |
9ff913ba | 3064 | bfd *abfd = section->asection->owner; |
72bf9492 | 3065 | |
b64f50a1 | 3066 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
adabb602 | 3067 | |
72bf9492 DJ |
3068 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
3069 | ||
460c1c54 CC |
3070 | /* If we're reading a type unit, skip over the signature and |
3071 | type_offset fields. */ | |
b0df02fd | 3072 | if (is_debug_types_section) |
460c1c54 CC |
3073 | info_ptr += 8 /*signature*/ + header->offset_size; |
3074 | ||
b64f50a1 | 3075 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
adabb602 | 3076 | |
9ff913ba | 3077 | error_check_comp_unit_head (header, section); |
72bf9492 DJ |
3078 | |
3079 | return info_ptr; | |
3080 | } | |
3081 | ||
348e048f DE |
3082 | /* Read in the types comp unit header information from .debug_types entry at |
3083 | types_ptr. The result is a pointer to one past the end of the header. */ | |
3084 | ||
3085 | static gdb_byte * | |
9ff913ba DE |
3086 | read_and_check_type_unit_head (struct comp_unit_head *header, |
3087 | struct dwarf2_section_info *section, | |
3088 | gdb_byte *info_ptr, | |
dee91e82 DE |
3089 | ULONGEST *signature, |
3090 | cu_offset *type_offset_in_tu) | |
348e048f | 3091 | { |
9ff913ba DE |
3092 | gdb_byte *beg_of_comp_unit = info_ptr; |
3093 | bfd *abfd = section->asection->owner; | |
348e048f | 3094 | |
b64f50a1 | 3095 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
348e048f | 3096 | |
9ff913ba | 3097 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
348e048f | 3098 | |
9ff913ba DE |
3099 | /* If we're reading a type unit, skip over the signature and |
3100 | type_offset fields. */ | |
3101 | if (signature != NULL) | |
3102 | *signature = read_8_bytes (abfd, info_ptr); | |
3103 | info_ptr += 8; | |
dee91e82 DE |
3104 | if (type_offset_in_tu != NULL) |
3105 | type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr, | |
3106 | header->offset_size); | |
9ff913ba DE |
3107 | info_ptr += header->offset_size; |
3108 | ||
b64f50a1 | 3109 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
348e048f | 3110 | |
9ff913ba DE |
3111 | error_check_comp_unit_head (header, section); |
3112 | ||
3113 | return info_ptr; | |
348e048f DE |
3114 | } |
3115 | ||
aaa75496 JB |
3116 | /* Allocate a new partial symtab for file named NAME and mark this new |
3117 | partial symtab as being an include of PST. */ | |
3118 | ||
3119 | static void | |
3120 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
3121 | struct objfile *objfile) | |
3122 | { | |
3123 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
3124 | ||
3125 | subpst->section_offsets = pst->section_offsets; | |
3126 | subpst->textlow = 0; | |
3127 | subpst->texthigh = 0; | |
3128 | ||
3129 | subpst->dependencies = (struct partial_symtab **) | |
3130 | obstack_alloc (&objfile->objfile_obstack, | |
3131 | sizeof (struct partial_symtab *)); | |
3132 | subpst->dependencies[0] = pst; | |
3133 | subpst->number_of_dependencies = 1; | |
3134 | ||
3135 | subpst->globals_offset = 0; | |
3136 | subpst->n_global_syms = 0; | |
3137 | subpst->statics_offset = 0; | |
3138 | subpst->n_static_syms = 0; | |
3139 | subpst->symtab = NULL; | |
3140 | subpst->read_symtab = pst->read_symtab; | |
3141 | subpst->readin = 0; | |
3142 | ||
3143 | /* No private part is necessary for include psymtabs. This property | |
3144 | can be used to differentiate between such include psymtabs and | |
10b3939b | 3145 | the regular ones. */ |
58a9656e | 3146 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
3147 | } |
3148 | ||
3149 | /* Read the Line Number Program data and extract the list of files | |
3150 | included by the source file represented by PST. Build an include | |
d85a05f0 | 3151 | partial symtab for each of these included files. */ |
aaa75496 JB |
3152 | |
3153 | static void | |
3154 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
dee91e82 DE |
3155 | struct die_info *die, |
3156 | struct partial_symtab *pst) | |
aaa75496 JB |
3157 | { |
3158 | struct objfile *objfile = cu->objfile; | |
3159 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
3160 | struct line_header *lh = NULL; |
3161 | struct attribute *attr; | |
aaa75496 | 3162 | |
d85a05f0 DJ |
3163 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
3164 | if (attr) | |
3165 | { | |
3166 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 3167 | |
d85a05f0 DJ |
3168 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
3169 | } | |
aaa75496 JB |
3170 | if (lh == NULL) |
3171 | return; /* No linetable, so no includes. */ | |
3172 | ||
c6da4cef | 3173 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
f3f5162e | 3174 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
aaa75496 JB |
3175 | |
3176 | free_line_header (lh); | |
3177 | } | |
3178 | ||
348e048f | 3179 | static hashval_t |
52dc124a | 3180 | hash_signatured_type (const void *item) |
348e048f | 3181 | { |
52dc124a | 3182 | const struct signatured_type *sig_type = item; |
9a619af0 | 3183 | |
348e048f | 3184 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
52dc124a | 3185 | return sig_type->signature; |
348e048f DE |
3186 | } |
3187 | ||
3188 | static int | |
52dc124a | 3189 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
348e048f DE |
3190 | { |
3191 | const struct signatured_type *lhs = item_lhs; | |
3192 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 3193 | |
348e048f DE |
3194 | return lhs->signature == rhs->signature; |
3195 | } | |
3196 | ||
1fd400ff TT |
3197 | /* Allocate a hash table for signatured types. */ |
3198 | ||
3199 | static htab_t | |
673bfd45 | 3200 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3201 | { |
3202 | return htab_create_alloc_ex (41, | |
52dc124a DE |
3203 | hash_signatured_type, |
3204 | eq_signatured_type, | |
1fd400ff TT |
3205 | NULL, |
3206 | &objfile->objfile_obstack, | |
3207 | hashtab_obstack_allocate, | |
3208 | dummy_obstack_deallocate); | |
3209 | } | |
3210 | ||
d467dd73 | 3211 | /* A helper function to add a signatured type CU to a table. */ |
1fd400ff TT |
3212 | |
3213 | static int | |
d467dd73 | 3214 | add_signatured_type_cu_to_table (void **slot, void *datum) |
1fd400ff TT |
3215 | { |
3216 | struct signatured_type *sigt = *slot; | |
3217 | struct dwarf2_per_cu_data ***datap = datum; | |
3218 | ||
3219 | **datap = &sigt->per_cu; | |
3220 | ++*datap; | |
3221 | ||
3222 | return 1; | |
3223 | } | |
3224 | ||
d467dd73 | 3225 | /* Create the hash table of all entries in the .debug_types section(s). |
0e50663e DE |
3226 | The result is zero if there are no .debug_types sections, |
3227 | otherwise non-zero. */ | |
348e048f DE |
3228 | |
3229 | static int | |
0e50663e | 3230 | create_all_type_units (struct objfile *objfile) |
348e048f | 3231 | { |
dee91e82 | 3232 | struct bfd *abfd = objfile->obfd; |
8b70b953 | 3233 | htab_t types_htab = NULL; |
1fd400ff | 3234 | struct dwarf2_per_cu_data **iter; |
8b70b953 TT |
3235 | int ix; |
3236 | struct dwarf2_section_info *section; | |
348e048f | 3237 | |
8b70b953 | 3238 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
348e048f DE |
3239 | { |
3240 | dwarf2_per_objfile->signatured_types = NULL; | |
3241 | return 0; | |
3242 | } | |
3243 | ||
8b70b953 TT |
3244 | for (ix = 0; |
3245 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, | |
3246 | ix, section); | |
3247 | ++ix) | |
3248 | { | |
3249 | gdb_byte *info_ptr, *end_ptr; | |
348e048f | 3250 | |
8b70b953 TT |
3251 | dwarf2_read_section (objfile, section); |
3252 | info_ptr = section->buffer; | |
348e048f | 3253 | |
8b70b953 TT |
3254 | if (info_ptr == NULL) |
3255 | continue; | |
348e048f | 3256 | |
8b70b953 TT |
3257 | if (types_htab == NULL) |
3258 | types_htab = allocate_signatured_type_table (objfile); | |
348e048f | 3259 | |
8b70b953 | 3260 | if (dwarf2_die_debug) |
dee91e82 DE |
3261 | fprintf_unfiltered (gdb_stdlog, "Reading signatured types for %s:\n", |
3262 | bfd_get_filename (abfd)); | |
3263 | ||
3264 | /* We don't use init_cutu_and_read_dies_simple, or some such, here | |
3265 | because we don't need to read any dies: the signature is in the | |
3266 | header. */ | |
8b70b953 TT |
3267 | |
3268 | end_ptr = info_ptr + section->size; | |
3269 | while (info_ptr < end_ptr) | |
3270 | { | |
b64f50a1 JK |
3271 | sect_offset offset; |
3272 | cu_offset type_offset; | |
8b70b953 | 3273 | ULONGEST signature; |
52dc124a | 3274 | struct signatured_type *sig_type; |
8b70b953 TT |
3275 | void **slot; |
3276 | gdb_byte *ptr = info_ptr; | |
9ff913ba | 3277 | struct comp_unit_head header; |
dee91e82 | 3278 | unsigned int length; |
348e048f | 3279 | |
b64f50a1 | 3280 | offset.sect_off = ptr - section->buffer; |
348e048f | 3281 | |
8b70b953 | 3282 | /* We need to read the type's signature in order to build the hash |
9ff913ba | 3283 | table, but we don't need anything else just yet. */ |
348e048f | 3284 | |
9ff913ba DE |
3285 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
3286 | &signature, &type_offset); | |
6caca83c | 3287 | |
dee91e82 DE |
3288 | length = header.initial_length_size + header.length; |
3289 | ||
6caca83c | 3290 | /* Skip dummy type units. */ |
dee91e82 DE |
3291 | if (ptr >= info_ptr + length |
3292 | || peek_abbrev_code (abfd, ptr) == 0) | |
6caca83c | 3293 | { |
dee91e82 | 3294 | info_ptr += header.initial_length_size + header.length; |
6caca83c CC |
3295 | continue; |
3296 | } | |
8b70b953 | 3297 | |
52dc124a DE |
3298 | sig_type = obstack_alloc (&objfile->objfile_obstack, sizeof (*sig_type)); |
3299 | memset (sig_type, 0, sizeof (*sig_type)); | |
3300 | sig_type->signature = signature; | |
3301 | sig_type->type_offset = type_offset; | |
3302 | sig_type->per_cu.objfile = objfile; | |
3303 | sig_type->per_cu.debug_types_section = section; | |
3304 | sig_type->per_cu.offset = offset; | |
8b70b953 | 3305 | |
52dc124a | 3306 | slot = htab_find_slot (types_htab, sig_type, INSERT); |
8b70b953 TT |
3307 | gdb_assert (slot != NULL); |
3308 | if (*slot != NULL) | |
3309 | { | |
3310 | const struct signatured_type *dup_sig = *slot; | |
b3c8eb43 | 3311 | |
8b70b953 TT |
3312 | complaint (&symfile_complaints, |
3313 | _("debug type entry at offset 0x%x is duplicate to the " | |
3314 | "entry at offset 0x%x, signature 0x%s"), | |
b64f50a1 | 3315 | offset.sect_off, dup_sig->per_cu.offset.sect_off, |
8b70b953 TT |
3316 | phex (signature, sizeof (signature))); |
3317 | gdb_assert (signature == dup_sig->signature); | |
3318 | } | |
52dc124a | 3319 | *slot = sig_type; |
348e048f | 3320 | |
8b70b953 TT |
3321 | if (dwarf2_die_debug) |
3322 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
b64f50a1 JK |
3323 | offset.sect_off, |
3324 | phex (signature, sizeof (signature))); | |
348e048f | 3325 | |
dee91e82 | 3326 | info_ptr += length; |
8b70b953 | 3327 | } |
348e048f DE |
3328 | } |
3329 | ||
3330 | dwarf2_per_objfile->signatured_types = types_htab; | |
3331 | ||
d467dd73 DE |
3332 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
3333 | dwarf2_per_objfile->all_type_units | |
1fd400ff | 3334 | = obstack_alloc (&objfile->objfile_obstack, |
d467dd73 | 3335 | dwarf2_per_objfile->n_type_units |
1fd400ff | 3336 | * sizeof (struct dwarf2_per_cu_data *)); |
d467dd73 DE |
3337 | iter = &dwarf2_per_objfile->all_type_units[0]; |
3338 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); | |
3339 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] | |
3340 | == dwarf2_per_objfile->n_type_units); | |
1fd400ff | 3341 | |
348e048f DE |
3342 | return 1; |
3343 | } | |
3344 | ||
380bca97 | 3345 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
e319fa28 | 3346 | Returns NULL if signature SIG is not present in the table. */ |
348e048f DE |
3347 | |
3348 | static struct signatured_type * | |
e319fa28 | 3349 | lookup_signatured_type (ULONGEST sig) |
348e048f DE |
3350 | { |
3351 | struct signatured_type find_entry, *entry; | |
3352 | ||
3353 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3354 | { | |
3355 | complaint (&symfile_complaints, | |
55f1336d | 3356 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
dcc07052 | 3357 | return NULL; |
348e048f DE |
3358 | } |
3359 | ||
3360 | find_entry.signature = sig; | |
3361 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3362 | return entry; | |
3363 | } | |
3364 | ||
d85a05f0 DJ |
3365 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3366 | ||
3367 | static void | |
3368 | init_cu_die_reader (struct die_reader_specs *reader, | |
dee91e82 DE |
3369 | struct dwarf2_cu *cu, |
3370 | struct dwarf2_section_info *section) | |
d85a05f0 | 3371 | { |
dee91e82 DE |
3372 | gdb_assert (section->readin); |
3373 | reader->abfd = section->asection->owner; | |
d85a05f0 | 3374 | reader->cu = cu; |
dee91e82 DE |
3375 | reader->die_section = section; |
3376 | reader->buffer = section->buffer; | |
d85a05f0 DJ |
3377 | } |
3378 | ||
3379 | /* Find the base address of the compilation unit for range lists and | |
3380 | location lists. It will normally be specified by DW_AT_low_pc. | |
3381 | In DWARF-3 draft 4, the base address could be overridden by | |
3382 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3383 | compilation units with discontinuous ranges. */ | |
3384 | ||
3385 | static void | |
3386 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3387 | { | |
3388 | struct attribute *attr; | |
3389 | ||
3390 | cu->base_known = 0; | |
3391 | cu->base_address = 0; | |
3392 | ||
3393 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3394 | if (attr) | |
3395 | { | |
3396 | cu->base_address = DW_ADDR (attr); | |
3397 | cu->base_known = 1; | |
3398 | } | |
3399 | else | |
3400 | { | |
3401 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3402 | if (attr) | |
3403 | { | |
3404 | cu->base_address = DW_ADDR (attr); | |
3405 | cu->base_known = 1; | |
3406 | } | |
3407 | } | |
3408 | } | |
3409 | ||
dee91e82 DE |
3410 | /* Subroutine of init_{cu,tu}_and_read_dies. |
3411 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3412 | ||
3413 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. | |
3414 | Otherwise, a new CU is allocated with xmalloc. | |
3415 | ||
3416 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3417 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. | |
3418 | ||
3419 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
3420 | linker) then DIE_READER_FUNC will not get called. | |
3421 | ||
3422 | FIXME: As an implementation detail between our callers and us, | |
3423 | USE_EXISTING_CU and KEEP are OK. But bubbling them up into their callers | |
3424 | isn't as clean as I'd like. Having more callers with good names | |
3425 | may be the way to go. */ | |
aaa75496 | 3426 | |
70221824 | 3427 | static void |
dee91e82 DE |
3428 | init_and_read_dies_worker (struct dwarf2_per_cu_data *this_cu, |
3429 | int use_existing_cu, int keep, | |
3430 | die_reader_func_ftype *die_reader_func, | |
3431 | void *data) | |
c906108c | 3432 | { |
dee91e82 DE |
3433 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
3434 | struct dwarf2_section_info *section; | |
3435 | bfd *abfd; | |
3436 | struct dwarf2_cu *cu; | |
3437 | gdb_byte *begin_info_ptr, *info_ptr; | |
3438 | struct die_reader_specs reader; | |
d85a05f0 | 3439 | struct die_info *comp_unit_die; |
dee91e82 | 3440 | int has_children; |
d85a05f0 | 3441 | struct attribute *attr; |
dee91e82 DE |
3442 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
3443 | struct signatured_type *sig_type = NULL; | |
c906108c | 3444 | |
dee91e82 DE |
3445 | if (use_existing_cu) |
3446 | gdb_assert (keep); | |
3447 | if (this_cu->debug_types_section) | |
3448 | gdb_assert (! use_existing_cu); | |
23745b47 | 3449 | |
dee91e82 DE |
3450 | if (this_cu->debug_types_section) |
3451 | section = this_cu->debug_types_section; | |
3452 | else | |
3453 | section = &dwarf2_per_objfile->info; | |
3454 | abfd = section->asection->owner; | |
ae038cb0 | 3455 | |
dee91e82 DE |
3456 | cleanups = make_cleanup (null_cleanup, NULL); |
3457 | ||
3458 | /* This is cheap if the section is already read in. */ | |
3459 | dwarf2_read_section (objfile, section); | |
3460 | ||
3461 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
3462 | ||
3463 | if (use_existing_cu && this_cu->cu != NULL) | |
3464 | { | |
3465 | cu = this_cu->cu; | |
3466 | info_ptr += cu->header.first_die_offset.cu_off; | |
3467 | } | |
3468 | else | |
3469 | { | |
3470 | /* If !use_existing_cu, this_cu->cu must be NULL. */ | |
3471 | gdb_assert (this_cu->cu == NULL); | |
3472 | ||
3473 | cu = xmalloc (sizeof (*cu)); | |
3474 | init_one_comp_unit (cu, this_cu); | |
3475 | ||
3476 | /* If an error occurs while loading, release our storage. */ | |
3477 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); | |
3478 | ||
3479 | if (this_cu->debug_types_section) | |
3480 | { | |
3481 | ULONGEST signature; | |
3482 | ||
3483 | info_ptr = read_and_check_type_unit_head (&cu->header, | |
3484 | section, info_ptr, | |
3485 | &signature, NULL); | |
3486 | ||
3487 | /* There's no way to get from PER_CU to its containing | |
3488 | struct signatured_type. | |
3489 | But we have the signature so we can use that. */ | |
3490 | sig_type = lookup_signatured_type (signature); | |
3491 | /* We've already scanned all the signatured types, | |
3492 | this must succeed. */ | |
3493 | gdb_assert (sig_type != NULL); | |
3494 | gdb_assert (&sig_type->per_cu == this_cu); | |
3495 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3496 | ||
3497 | /* LENGTH has not been set yet for type units. */ | |
3498 | this_cu->length = cu->header.length + cu->header.initial_length_size; | |
3499 | } | |
3500 | else | |
3501 | { | |
3502 | info_ptr = read_and_check_comp_unit_head (&cu->header, | |
3503 | section, info_ptr, 0); | |
3504 | ||
3505 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); | |
3506 | gdb_assert (this_cu->length | |
3507 | == cu->header.length + cu->header.initial_length_size); | |
3508 | } | |
3509 | } | |
10b3939b | 3510 | |
6caca83c | 3511 | /* Skip dummy compilation units. */ |
dee91e82 | 3512 | if (info_ptr >= begin_info_ptr + this_cu->length |
6caca83c CC |
3513 | || peek_abbrev_code (abfd, info_ptr) == 0) |
3514 | { | |
dee91e82 | 3515 | do_cleanups (cleanups); |
21b2bd31 | 3516 | return; |
6caca83c CC |
3517 | } |
3518 | ||
93311388 | 3519 | /* Read the abbrevs for this compilation unit into a table. */ |
dee91e82 DE |
3520 | if (cu->dwarf2_abbrevs == NULL) |
3521 | { | |
3522 | dwarf2_read_abbrevs (cu, &dwarf2_per_objfile->abbrev); | |
3523 | make_cleanup (dwarf2_free_abbrev_table, cu); | |
3524 | } | |
af703f96 | 3525 | |
dee91e82 DE |
3526 | /* Read the top level CU/TU die. */ |
3527 | init_cu_die_reader (&reader, cu, section); | |
3528 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); | |
93311388 | 3529 | |
dee91e82 DE |
3530 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
3531 | ||
3532 | if (free_cu_cleanup != NULL) | |
348e048f | 3533 | { |
dee91e82 DE |
3534 | if (keep) |
3535 | { | |
3536 | /* We've successfully allocated this compilation unit. Let our | |
3537 | caller clean it up when finished with it. */ | |
3538 | discard_cleanups (free_cu_cleanup); | |
3539 | ||
3540 | /* We can only discard free_cu_cleanup and all subsequent cleanups. | |
3541 | So we have to manually free the abbrev table. */ | |
3542 | dwarf2_free_abbrev_table (cu); | |
3543 | ||
3544 | /* Link this CU into read_in_chain. */ | |
3545 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3546 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3547 | } | |
3548 | else | |
3549 | do_cleanups (free_cu_cleanup); | |
348e048f | 3550 | } |
dee91e82 DE |
3551 | |
3552 | do_cleanups (cleanups); | |
3553 | } | |
3554 | ||
3555 | /* Main entry point for reading a CU. | |
3556 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3557 | ||
3558 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. | |
3559 | Otherwise, a new CU is allocated with xmalloc. | |
3560 | ||
3561 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3562 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */ | |
3563 | ||
3564 | static void | |
3565 | init_cu_and_read_dies (struct dwarf2_per_cu_data *this_cu, | |
3566 | int use_existing_cu, int keep, | |
3567 | die_reader_func_ftype *die_reader_func, | |
3568 | void *data) | |
3569 | { | |
3570 | init_and_read_dies_worker (this_cu, use_existing_cu, keep, | |
3571 | die_reader_func, data); | |
3572 | } | |
3573 | ||
3574 | /* Main entry point for reading a TU. | |
3575 | Do all the work necessary to initialize THIS_CU->cu and read in its DIE(s). | |
3576 | ||
3577 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to | |
3578 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. */ | |
3579 | ||
3580 | static void | |
3581 | init_tu_and_read_dies (struct dwarf2_per_cu_data *this_cu, | |
3582 | int keep, | |
3583 | die_reader_func_ftype *die_reader_func, | |
3584 | void *data) | |
3585 | { | |
3586 | gdb_assert (this_cu->debug_types_section); | |
3587 | init_and_read_dies_worker (this_cu, 0, keep, die_reader_func, data); | |
3588 | } | |
3589 | ||
3590 | /* Read the CU/TU at OFFSET in section SECTION. | |
3591 | ||
3592 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and | |
3593 | THIS_CU->debug_types_section, but nothing else. | |
3594 | ||
3595 | We fill in THIS_CU->length. | |
3596 | ||
3597 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental | |
3598 | linker) then DIE_READER_FUNC will not get called. | |
3599 | ||
3600 | THIS_CU->cu is always freed when done. | |
3601 | [This is done for Fission reasons, to be specified.] */ | |
3602 | ||
3603 | static void | |
3604 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, | |
3605 | struct dwarf2_section_info *abbrev_section, | |
3606 | die_reader_func_ftype *die_reader_func, | |
3607 | void *data) | |
3608 | { | |
3609 | struct objfile *objfile = dwarf2_per_objfile->objfile; | |
3610 | struct dwarf2_section_info *section; | |
3611 | bfd *abfd; | |
3612 | struct dwarf2_cu cu; | |
3613 | gdb_byte *begin_info_ptr, *info_ptr; | |
3614 | struct die_reader_specs reader; | |
3615 | struct cleanup *cleanups; | |
3616 | struct die_info *comp_unit_die; | |
3617 | int has_children; | |
3618 | ||
3619 | gdb_assert (this_cu->cu == NULL); | |
3620 | ||
3621 | if (this_cu->debug_types_section) | |
3622 | section = this_cu->debug_types_section; | |
3623 | else | |
3624 | section = &dwarf2_per_objfile->info; | |
3625 | abfd = section->asection->owner; | |
3626 | ||
3627 | /* This is cheap if the section is already read in. */ | |
3628 | dwarf2_read_section (objfile, section); | |
3629 | ||
3630 | init_one_comp_unit (&cu, this_cu); | |
3631 | ||
3632 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
3633 | ||
3634 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; | |
3635 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, | |
3636 | this_cu->debug_types_section != NULL); | |
3637 | ||
3638 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
3639 | ||
3640 | /* Skip dummy compilation units. */ | |
3641 | if (info_ptr >= begin_info_ptr + this_cu->length | |
3642 | || peek_abbrev_code (abfd, info_ptr) == 0) | |
c906108c | 3643 | { |
dee91e82 | 3644 | do_cleanups (cleanups); |
21b2bd31 | 3645 | return; |
93311388 | 3646 | } |
72bf9492 | 3647 | |
dee91e82 DE |
3648 | dwarf2_read_abbrevs (&cu, abbrev_section); |
3649 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
3650 | ||
3651 | init_cu_die_reader (&reader, &cu, section); | |
3652 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); | |
3653 | ||
3654 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); | |
3655 | ||
3656 | do_cleanups (cleanups); | |
3657 | } | |
3658 | ||
3659 | /* Read a CU/TU. | |
3660 | [This is a separate routine for Fission, to be specified.] | |
3661 | ||
3662 | THIS_CU->cu is always freed when done. | |
3663 | [This is done for Fission reasons, to be specified.] */ | |
3664 | ||
3665 | static void | |
3666 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, | |
3667 | die_reader_func_ftype *die_reader_func, | |
3668 | void *data) | |
3669 | { | |
3670 | init_cutu_and_read_dies_no_follow (this_cu, | |
3671 | &dwarf2_per_objfile->abbrev, | |
3672 | die_reader_func, data); | |
3673 | } | |
3674 | ||
3675 | /* die_reader_func for process_psymtab_comp_unit. */ | |
3676 | ||
3677 | static void | |
3678 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, | |
3679 | gdb_byte *info_ptr, | |
3680 | struct die_info *comp_unit_die, | |
3681 | int has_children, | |
3682 | void *data) | |
3683 | { | |
3684 | struct dwarf2_cu *cu = reader->cu; | |
3685 | struct objfile *objfile = cu->objfile; | |
3686 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; | |
3687 | bfd *abfd = objfile->obfd; | |
3688 | struct attribute *attr; | |
3689 | CORE_ADDR baseaddr; | |
3690 | CORE_ADDR best_lowpc = 0, best_highpc = 0; | |
3691 | struct partial_symtab *pst; | |
3692 | int has_pc_info; | |
3693 | const char *filename; | |
3694 | ||
3695 | if (comp_unit_die->tag == DW_TAG_partial_unit) | |
3696 | return; | |
3697 | ||
3698 | prepare_one_comp_unit (cu, comp_unit_die); | |
3699 | ||
3700 | cu->list_in_scope = &file_symbols; | |
c906108c | 3701 | |
93311388 | 3702 | /* Allocate a new partial symbol table structure. */ |
dee91e82 | 3703 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
3e2a0cee TT |
3704 | if (attr == NULL || !DW_STRING (attr)) |
3705 | filename = ""; | |
3706 | else | |
3707 | filename = DW_STRING (attr); | |
93311388 | 3708 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3709 | filename, |
93311388 DE |
3710 | /* TEXTLOW and TEXTHIGH are set below. */ |
3711 | 0, | |
3712 | objfile->global_psymbols.next, | |
3713 | objfile->static_psymbols.next); | |
9750bca9 | 3714 | pst->psymtabs_addrmap_supported = 1; |
72bf9492 | 3715 | |
dee91e82 | 3716 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
d85a05f0 DJ |
3717 | if (attr != NULL) |
3718 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3719 | |
dee91e82 | 3720 | pst->read_symtab_private = per_cu; |
72bf9492 | 3721 | |
93311388 | 3722 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3723 | |
0963b4bd | 3724 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3725 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3726 | |
dee91e82 | 3727 | per_cu->v.psymtab = pst; |
c906108c | 3728 | |
dee91e82 | 3729 | dwarf2_find_base_address (comp_unit_die, cu); |
d85a05f0 | 3730 | |
93311388 DE |
3731 | /* Possibly set the default values of LOWPC and HIGHPC from |
3732 | `DW_AT_ranges'. */ | |
d85a05f0 | 3733 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
dee91e82 | 3734 | &best_highpc, cu, pst); |
d85a05f0 | 3735 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
93311388 DE |
3736 | /* Store the contiguous range if it is not empty; it can be empty for |
3737 | CUs with no code. */ | |
3738 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3739 | best_lowpc + baseaddr, |
3740 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3741 | |
3742 | /* Check if comp unit has_children. | |
3743 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3744 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3745 | if (has_children) |
93311388 DE |
3746 | { |
3747 | struct partial_die_info *first_die; | |
3748 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3749 | |
93311388 DE |
3750 | lowpc = ((CORE_ADDR) -1); |
3751 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3752 | |
dee91e82 | 3753 | first_die = load_partial_dies (reader, info_ptr, 1); |
c906108c | 3754 | |
93311388 | 3755 | scan_partial_symbols (first_die, &lowpc, &highpc, |
dee91e82 | 3756 | ! has_pc_info, cu); |
57c22c6c | 3757 | |
93311388 DE |
3758 | /* If we didn't find a lowpc, set it to highpc to avoid |
3759 | complaints from `maint check'. */ | |
3760 | if (lowpc == ((CORE_ADDR) -1)) | |
3761 | lowpc = highpc; | |
10b3939b | 3762 | |
93311388 DE |
3763 | /* If the compilation unit didn't have an explicit address range, |
3764 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3765 | if (! has_pc_info) |
93311388 | 3766 | { |
d85a05f0 DJ |
3767 | best_lowpc = lowpc; |
3768 | best_highpc = highpc; | |
93311388 DE |
3769 | } |
3770 | } | |
d85a05f0 DJ |
3771 | pst->textlow = best_lowpc + baseaddr; |
3772 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3773 | |
93311388 DE |
3774 | pst->n_global_syms = objfile->global_psymbols.next - |
3775 | (objfile->global_psymbols.list + pst->globals_offset); | |
3776 | pst->n_static_syms = objfile->static_psymbols.next - | |
3777 | (objfile->static_psymbols.list + pst->statics_offset); | |
3778 | sort_pst_symbols (pst); | |
c906108c | 3779 | |
dee91e82 | 3780 | if (per_cu->debug_types_section) |
348e048f DE |
3781 | { |
3782 | /* It's not clear we want to do anything with stmt lists here. | |
3783 | Waiting to see what gcc ultimately does. */ | |
3784 | } | |
d85a05f0 | 3785 | else |
93311388 DE |
3786 | { |
3787 | /* Get the list of files included in the current compilation unit, | |
3788 | and build a psymtab for each of them. */ | |
dee91e82 | 3789 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); |
93311388 | 3790 | } |
dee91e82 | 3791 | } |
ae038cb0 | 3792 | |
dee91e82 DE |
3793 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
3794 | Process compilation unit THIS_CU for a psymtab. */ | |
3795 | ||
3796 | static void | |
3797 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
3798 | { | |
3799 | /* If this compilation unit was already read in, free the | |
3800 | cached copy in order to read it in again. This is | |
3801 | necessary because we skipped some symbols when we first | |
3802 | read in the compilation unit (see load_partial_dies). | |
3803 | This problem could be avoided, but the benefit is unclear. */ | |
3804 | if (this_cu->cu != NULL) | |
3805 | free_one_cached_comp_unit (this_cu); | |
3806 | ||
3807 | gdb_assert (! this_cu->debug_types_section); | |
3808 | init_cu_and_read_dies (this_cu, 0, 0, process_psymtab_comp_unit_reader, | |
3809 | NULL); | |
3810 | ||
3811 | /* Age out any secondary CUs. */ | |
3812 | age_cached_comp_units (); | |
93311388 | 3813 | } |
ff013f42 | 3814 | |
348e048f DE |
3815 | /* Traversal function for htab_traverse_noresize. |
3816 | Process one .debug_types comp-unit. */ | |
3817 | ||
3818 | static int | |
dee91e82 | 3819 | process_psymtab_type_unit (void **slot, void *info) |
348e048f | 3820 | { |
dee91e82 DE |
3821 | struct signatured_type *sig_type = (struct signatured_type *) *slot; |
3822 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 3823 | |
a0f42c21 | 3824 | gdb_assert (info == NULL); |
348e048f | 3825 | |
dee91e82 DE |
3826 | /* If this compilation unit was already read in, free the |
3827 | cached copy in order to read it in again. This is | |
3828 | necessary because we skipped some symbols when we first | |
3829 | read in the compilation unit (see load_partial_dies). | |
3830 | This problem could be avoided, but the benefit is unclear. */ | |
3831 | if (per_cu->cu != NULL) | |
3832 | free_one_cached_comp_unit (per_cu); | |
3833 | ||
3834 | gdb_assert (per_cu->debug_types_section); | |
3835 | init_tu_and_read_dies (per_cu, 0, process_psymtab_comp_unit_reader, NULL); | |
3836 | ||
3837 | /* Age out any secondary CUs. */ | |
3838 | age_cached_comp_units (); | |
348e048f DE |
3839 | |
3840 | return 1; | |
3841 | } | |
3842 | ||
3843 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3844 | Build partial symbol tables for the .debug_types comp-units. */ | |
3845 | ||
3846 | static void | |
3847 | build_type_psymtabs (struct objfile *objfile) | |
3848 | { | |
0e50663e | 3849 | if (! create_all_type_units (objfile)) |
348e048f DE |
3850 | return; |
3851 | ||
3852 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
dee91e82 | 3853 | process_psymtab_type_unit, NULL); |
348e048f DE |
3854 | } |
3855 | ||
60606b2c TT |
3856 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3857 | ||
3858 | static void | |
3859 | psymtabs_addrmap_cleanup (void *o) | |
3860 | { | |
3861 | struct objfile *objfile = o; | |
ec61707d | 3862 | |
60606b2c TT |
3863 | objfile->psymtabs_addrmap = NULL; |
3864 | } | |
3865 | ||
93311388 DE |
3866 | /* Build the partial symbol table by doing a quick pass through the |
3867 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3868 | |
93311388 | 3869 | static void |
c67a9c90 | 3870 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3871 | { |
60606b2c TT |
3872 | struct cleanup *back_to, *addrmap_cleanup; |
3873 | struct obstack temp_obstack; | |
21b2bd31 | 3874 | int i; |
93311388 | 3875 | |
98bfdba5 PA |
3876 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3877 | ||
be391dca | 3878 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
91c24f0a | 3879 | |
93311388 DE |
3880 | /* Any cached compilation units will be linked by the per-objfile |
3881 | read_in_chain. Make sure to free them when we're done. */ | |
3882 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3883 | |
348e048f DE |
3884 | build_type_psymtabs (objfile); |
3885 | ||
93311388 | 3886 | create_all_comp_units (objfile); |
c906108c | 3887 | |
60606b2c TT |
3888 | /* Create a temporary address map on a temporary obstack. We later |
3889 | copy this to the final obstack. */ | |
3890 | obstack_init (&temp_obstack); | |
3891 | make_cleanup_obstack_free (&temp_obstack); | |
3892 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3893 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3894 | |
21b2bd31 | 3895 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
93311388 | 3896 | { |
21b2bd31 | 3897 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
aaa75496 | 3898 | |
dee91e82 | 3899 | process_psymtab_comp_unit (per_cu); |
c906108c | 3900 | } |
ff013f42 JK |
3901 | |
3902 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3903 | &objfile->objfile_obstack); | |
60606b2c | 3904 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3905 | |
ae038cb0 DJ |
3906 | do_cleanups (back_to); |
3907 | } | |
3908 | ||
93311388 | 3909 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3910 | |
3911 | static void | |
dee91e82 DE |
3912 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
3913 | gdb_byte *info_ptr, | |
3914 | struct die_info *comp_unit_die, | |
3915 | int has_children, | |
3916 | void *data) | |
ae038cb0 | 3917 | { |
dee91e82 | 3918 | struct dwarf2_cu *cu = reader->cu; |
ae038cb0 | 3919 | |
9816fde3 | 3920 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3921 | |
ae038cb0 DJ |
3922 | /* Check if comp unit has_children. |
3923 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3924 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3925 | if (has_children) |
dee91e82 DE |
3926 | load_partial_dies (reader, info_ptr, 0); |
3927 | } | |
98bfdba5 | 3928 | |
dee91e82 DE |
3929 | /* Load the partial DIEs for a secondary CU into memory. |
3930 | This is also used when rereading a primary CU with load_all_dies. */ | |
c5b7e1cb | 3931 | |
dee91e82 DE |
3932 | static void |
3933 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
3934 | { | |
3935 | if (this_cu->debug_types_section) | |
3936 | init_tu_and_read_dies (this_cu, 1, load_partial_comp_unit_reader, NULL); | |
3937 | else | |
3938 | init_cu_and_read_dies (this_cu, 0, 1, load_partial_comp_unit_reader, NULL); | |
ae038cb0 DJ |
3939 | } |
3940 | ||
9cdd5dbd DE |
3941 | /* Create a list of all compilation units in OBJFILE. |
3942 | This is only done for -readnow and building partial symtabs. */ | |
ae038cb0 DJ |
3943 | |
3944 | static void | |
3945 | create_all_comp_units (struct objfile *objfile) | |
3946 | { | |
3947 | int n_allocated; | |
3948 | int n_comp_units; | |
3949 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3950 | gdb_byte *info_ptr; |
3951 | ||
3952 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3953 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3954 | |
3955 | n_comp_units = 0; | |
3956 | n_allocated = 10; | |
3957 | all_comp_units = xmalloc (n_allocated | |
3958 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3959 | |
3e43a32a MS |
3960 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3961 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3962 | { |
c764a876 | 3963 | unsigned int length, initial_length_size; |
ae038cb0 | 3964 | struct dwarf2_per_cu_data *this_cu; |
b64f50a1 | 3965 | sect_offset offset; |
ae038cb0 | 3966 | |
b64f50a1 | 3967 | offset.sect_off = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3968 | |
3969 | /* Read just enough information to find out where the next | |
3970 | compilation unit is. */ | |
c764a876 DE |
3971 | length = read_initial_length (objfile->obfd, info_ptr, |
3972 | &initial_length_size); | |
ae038cb0 DJ |
3973 | |
3974 | /* Save the compilation unit for later lookup. */ | |
3975 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3976 | sizeof (struct dwarf2_per_cu_data)); | |
3977 | memset (this_cu, 0, sizeof (*this_cu)); | |
3978 | this_cu->offset = offset; | |
c764a876 | 3979 | this_cu->length = length + initial_length_size; |
9291a0cd | 3980 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3981 | |
3982 | if (n_comp_units == n_allocated) | |
3983 | { | |
3984 | n_allocated *= 2; | |
3985 | all_comp_units = xrealloc (all_comp_units, | |
3986 | n_allocated | |
3987 | * sizeof (struct dwarf2_per_cu_data *)); | |
3988 | } | |
3989 | all_comp_units[n_comp_units++] = this_cu; | |
3990 | ||
3991 | info_ptr = info_ptr + this_cu->length; | |
3992 | } | |
3993 | ||
3994 | dwarf2_per_objfile->all_comp_units | |
3995 | = obstack_alloc (&objfile->objfile_obstack, | |
3996 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3997 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3998 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3999 | xfree (all_comp_units); | |
4000 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
4001 | } |
4002 | ||
5734ee8b DJ |
4003 | /* Process all loaded DIEs for compilation unit CU, starting at |
4004 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
4005 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
4006 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
4007 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
4008 | and record the covered ranges in the addrmap. */ | |
c906108c | 4009 | |
72bf9492 DJ |
4010 | static void |
4011 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 4012 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 4013 | { |
72bf9492 | 4014 | struct partial_die_info *pdi; |
c906108c | 4015 | |
91c24f0a DC |
4016 | /* Now, march along the PDI's, descending into ones which have |
4017 | interesting children but skipping the children of the other ones, | |
4018 | until we reach the end of the compilation unit. */ | |
c906108c | 4019 | |
72bf9492 | 4020 | pdi = first_die; |
91c24f0a | 4021 | |
72bf9492 DJ |
4022 | while (pdi != NULL) |
4023 | { | |
4024 | fixup_partial_die (pdi, cu); | |
c906108c | 4025 | |
f55ee35c | 4026 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
4027 | children, so we need to look at them. Ditto for anonymous |
4028 | enums. */ | |
933c6fe4 | 4029 | |
72bf9492 | 4030 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 4031 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 4032 | { |
72bf9492 | 4033 | switch (pdi->tag) |
c906108c SS |
4034 | { |
4035 | case DW_TAG_subprogram: | |
5734ee8b | 4036 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 4037 | break; |
72929c62 | 4038 | case DW_TAG_constant: |
c906108c SS |
4039 | case DW_TAG_variable: |
4040 | case DW_TAG_typedef: | |
91c24f0a | 4041 | case DW_TAG_union_type: |
72bf9492 | 4042 | if (!pdi->is_declaration) |
63d06c5c | 4043 | { |
72bf9492 | 4044 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
4045 | } |
4046 | break; | |
c906108c | 4047 | case DW_TAG_class_type: |
680b30c7 | 4048 | case DW_TAG_interface_type: |
c906108c | 4049 | case DW_TAG_structure_type: |
72bf9492 | 4050 | if (!pdi->is_declaration) |
c906108c | 4051 | { |
72bf9492 | 4052 | add_partial_symbol (pdi, cu); |
c906108c SS |
4053 | } |
4054 | break; | |
91c24f0a | 4055 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
4056 | if (!pdi->is_declaration) |
4057 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
4058 | break; |
4059 | case DW_TAG_base_type: | |
a02abb62 | 4060 | case DW_TAG_subrange_type: |
c906108c | 4061 | /* File scope base type definitions are added to the partial |
c5aa993b | 4062 | symbol table. */ |
72bf9492 | 4063 | add_partial_symbol (pdi, cu); |
c906108c | 4064 | break; |
d9fa45fe | 4065 | case DW_TAG_namespace: |
5734ee8b | 4066 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 4067 | break; |
5d7cb8df JK |
4068 | case DW_TAG_module: |
4069 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
4070 | break; | |
c906108c SS |
4071 | default: |
4072 | break; | |
4073 | } | |
4074 | } | |
4075 | ||
72bf9492 DJ |
4076 | /* If the die has a sibling, skip to the sibling. */ |
4077 | ||
4078 | pdi = pdi->die_sibling; | |
4079 | } | |
4080 | } | |
4081 | ||
4082 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 4083 | |
72bf9492 | 4084 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
4085 | name is concatenated with "::" and the partial DIE's name. For |
4086 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
4087 | Enumerators are an exception; they use the scope of their parent |
4088 | enumeration type, i.e. the name of the enumeration type is not | |
4089 | prepended to the enumerator. | |
91c24f0a | 4090 | |
72bf9492 DJ |
4091 | There are two complexities. One is DW_AT_specification; in this |
4092 | case "parent" means the parent of the target of the specification, | |
4093 | instead of the direct parent of the DIE. The other is compilers | |
4094 | which do not emit DW_TAG_namespace; in this case we try to guess | |
4095 | the fully qualified name of structure types from their members' | |
4096 | linkage names. This must be done using the DIE's children rather | |
4097 | than the children of any DW_AT_specification target. We only need | |
4098 | to do this for structures at the top level, i.e. if the target of | |
4099 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
4100 | have a parent. */ | |
4101 | ||
4102 | /* Compute the scope prefix associated with PDI's parent, in | |
4103 | compilation unit CU. The result will be allocated on CU's | |
4104 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
4105 | field. NULL is returned if no prefix is necessary. */ | |
4106 | static char * | |
4107 | partial_die_parent_scope (struct partial_die_info *pdi, | |
4108 | struct dwarf2_cu *cu) | |
4109 | { | |
4110 | char *grandparent_scope; | |
4111 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 4112 | |
72bf9492 DJ |
4113 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
4114 | then this means the parent of the specification DIE. */ | |
4115 | ||
4116 | real_pdi = pdi; | |
72bf9492 | 4117 | while (real_pdi->has_specification) |
10b3939b | 4118 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
4119 | |
4120 | parent = real_pdi->die_parent; | |
4121 | if (parent == NULL) | |
4122 | return NULL; | |
4123 | ||
4124 | if (parent->scope_set) | |
4125 | return parent->scope; | |
4126 | ||
4127 | fixup_partial_die (parent, cu); | |
4128 | ||
10b3939b | 4129 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 4130 | |
acebe513 UW |
4131 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
4132 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
4133 | Work around this problem here. */ | |
4134 | if (cu->language == language_cplus | |
6e70227d | 4135 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
4136 | && strcmp (parent->name, "::") == 0 |
4137 | && grandparent_scope == NULL) | |
4138 | { | |
4139 | parent->scope = NULL; | |
4140 | parent->scope_set = 1; | |
4141 | return NULL; | |
4142 | } | |
4143 | ||
9c6c53f7 SA |
4144 | if (pdi->tag == DW_TAG_enumerator) |
4145 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
4146 | parent->scope = grandparent_scope; | |
4147 | else if (parent->tag == DW_TAG_namespace | |
f55ee35c | 4148 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
4149 | || parent->tag == DW_TAG_structure_type |
4150 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 4151 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
4152 | || parent->tag == DW_TAG_union_type |
4153 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
4154 | { |
4155 | if (grandparent_scope == NULL) | |
4156 | parent->scope = parent->name; | |
4157 | else | |
3e43a32a MS |
4158 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
4159 | grandparent_scope, | |
f55ee35c | 4160 | parent->name, 0, cu); |
72bf9492 | 4161 | } |
72bf9492 DJ |
4162 | else |
4163 | { | |
4164 | /* FIXME drow/2004-04-01: What should we be doing with | |
4165 | function-local names? For partial symbols, we should probably be | |
4166 | ignoring them. */ | |
4167 | complaint (&symfile_complaints, | |
e2e0b3e5 | 4168 | _("unhandled containing DIE tag %d for DIE at %d"), |
b64f50a1 | 4169 | parent->tag, pdi->offset.sect_off); |
72bf9492 | 4170 | parent->scope = grandparent_scope; |
c906108c SS |
4171 | } |
4172 | ||
72bf9492 DJ |
4173 | parent->scope_set = 1; |
4174 | return parent->scope; | |
4175 | } | |
4176 | ||
4177 | /* Return the fully scoped name associated with PDI, from compilation unit | |
4178 | CU. The result will be allocated with malloc. */ | |
4568ecf9 | 4179 | |
72bf9492 DJ |
4180 | static char * |
4181 | partial_die_full_name (struct partial_die_info *pdi, | |
4182 | struct dwarf2_cu *cu) | |
4183 | { | |
4184 | char *parent_scope; | |
4185 | ||
98bfdba5 PA |
4186 | /* If this is a template instantiation, we can not work out the |
4187 | template arguments from partial DIEs. So, unfortunately, we have | |
4188 | to go through the full DIEs. At least any work we do building | |
4189 | types here will be reused if full symbols are loaded later. */ | |
4190 | if (pdi->has_template_arguments) | |
4191 | { | |
4192 | fixup_partial_die (pdi, cu); | |
4193 | ||
4194 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
4195 | { | |
4196 | struct die_info *die; | |
4197 | struct attribute attr; | |
4198 | struct dwarf2_cu *ref_cu = cu; | |
4199 | ||
b64f50a1 | 4200 | /* DW_FORM_ref_addr is using section offset. */ |
98bfdba5 PA |
4201 | attr.name = 0; |
4202 | attr.form = DW_FORM_ref_addr; | |
4568ecf9 | 4203 | attr.u.unsnd = pdi->offset.sect_off; |
98bfdba5 PA |
4204 | die = follow_die_ref (NULL, &attr, &ref_cu); |
4205 | ||
4206 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
4207 | } | |
4208 | } | |
4209 | ||
72bf9492 DJ |
4210 | parent_scope = partial_die_parent_scope (pdi, cu); |
4211 | if (parent_scope == NULL) | |
4212 | return NULL; | |
4213 | else | |
f55ee35c | 4214 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
4215 | } |
4216 | ||
4217 | static void | |
72bf9492 | 4218 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 4219 | { |
e7c27a73 | 4220 | struct objfile *objfile = cu->objfile; |
c906108c | 4221 | CORE_ADDR addr = 0; |
decbce07 | 4222 | char *actual_name = NULL; |
e142c38c | 4223 | CORE_ADDR baseaddr; |
72bf9492 | 4224 | int built_actual_name = 0; |
e142c38c DJ |
4225 | |
4226 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 4227 | |
94af9270 KS |
4228 | actual_name = partial_die_full_name (pdi, cu); |
4229 | if (actual_name) | |
4230 | built_actual_name = 1; | |
63d06c5c | 4231 | |
72bf9492 DJ |
4232 | if (actual_name == NULL) |
4233 | actual_name = pdi->name; | |
4234 | ||
c906108c SS |
4235 | switch (pdi->tag) |
4236 | { | |
4237 | case DW_TAG_subprogram: | |
2cfa0c8d | 4238 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 4239 | { |
2cfa0c8d JB |
4240 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
4241 | of the global scope. But in Ada, we want to be able to access | |
4242 | nested procedures globally. So all Ada subprograms are stored | |
4243 | in the global scope. */ | |
f47fb265 | 4244 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4245 | mst_text, objfile); */ |
f47fb265 MS |
4246 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4247 | built_actual_name, | |
4248 | VAR_DOMAIN, LOC_BLOCK, | |
4249 | &objfile->global_psymbols, | |
4250 | 0, pdi->lowpc + baseaddr, | |
4251 | cu->language, objfile); | |
c906108c SS |
4252 | } |
4253 | else | |
4254 | { | |
f47fb265 | 4255 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 4256 | mst_file_text, objfile); */ |
f47fb265 MS |
4257 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4258 | built_actual_name, | |
4259 | VAR_DOMAIN, LOC_BLOCK, | |
4260 | &objfile->static_psymbols, | |
4261 | 0, pdi->lowpc + baseaddr, | |
4262 | cu->language, objfile); | |
c906108c SS |
4263 | } |
4264 | break; | |
72929c62 JB |
4265 | case DW_TAG_constant: |
4266 | { | |
4267 | struct psymbol_allocation_list *list; | |
4268 | ||
4269 | if (pdi->is_external) | |
4270 | list = &objfile->global_psymbols; | |
4271 | else | |
4272 | list = &objfile->static_psymbols; | |
f47fb265 MS |
4273 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4274 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
4275 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
4276 | } |
4277 | break; | |
c906108c | 4278 | case DW_TAG_variable: |
caac4577 JG |
4279 | if (pdi->locdesc) |
4280 | addr = decode_locdesc (pdi->locdesc, cu); | |
4281 | ||
4282 | if (pdi->locdesc | |
4283 | && addr == 0 | |
4284 | && !dwarf2_per_objfile->has_section_at_zero) | |
4285 | { | |
4286 | /* A global or static variable may also have been stripped | |
4287 | out by the linker if unused, in which case its address | |
4288 | will be nullified; do not add such variables into partial | |
4289 | symbol table then. */ | |
4290 | } | |
4291 | else if (pdi->is_external) | |
c906108c SS |
4292 | { |
4293 | /* Global Variable. | |
4294 | Don't enter into the minimal symbol tables as there is | |
4295 | a minimal symbol table entry from the ELF symbols already. | |
4296 | Enter into partial symbol table if it has a location | |
4297 | descriptor or a type. | |
4298 | If the location descriptor is missing, new_symbol will create | |
4299 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
4300 | be determined from the minimal symbol table whenever the variable | |
4301 | is referenced. | |
4302 | The address for the partial symbol table entry is not | |
4303 | used by GDB, but it comes in handy for debugging partial symbol | |
4304 | table building. */ | |
4305 | ||
c906108c | 4306 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
4307 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4308 | built_actual_name, | |
4309 | VAR_DOMAIN, LOC_STATIC, | |
4310 | &objfile->global_psymbols, | |
4311 | 0, addr + baseaddr, | |
4312 | cu->language, objfile); | |
c906108c SS |
4313 | } |
4314 | else | |
4315 | { | |
0963b4bd | 4316 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 4317 | if (pdi->locdesc == NULL) |
decbce07 MS |
4318 | { |
4319 | if (built_actual_name) | |
4320 | xfree (actual_name); | |
4321 | return; | |
4322 | } | |
f47fb265 | 4323 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 4324 | mst_file_data, objfile); */ |
f47fb265 MS |
4325 | add_psymbol_to_list (actual_name, strlen (actual_name), |
4326 | built_actual_name, | |
4327 | VAR_DOMAIN, LOC_STATIC, | |
4328 | &objfile->static_psymbols, | |
4329 | 0, addr + baseaddr, | |
4330 | cu->language, objfile); | |
c906108c SS |
4331 | } |
4332 | break; | |
4333 | case DW_TAG_typedef: | |
4334 | case DW_TAG_base_type: | |
a02abb62 | 4335 | case DW_TAG_subrange_type: |
38d518c9 | 4336 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4337 | built_actual_name, |
176620f1 | 4338 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 4339 | &objfile->static_psymbols, |
e142c38c | 4340 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4341 | break; |
72bf9492 DJ |
4342 | case DW_TAG_namespace: |
4343 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 4344 | built_actual_name, |
72bf9492 DJ |
4345 | VAR_DOMAIN, LOC_TYPEDEF, |
4346 | &objfile->global_psymbols, | |
4347 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
4348 | break; | |
c906108c | 4349 | case DW_TAG_class_type: |
680b30c7 | 4350 | case DW_TAG_interface_type: |
c906108c SS |
4351 | case DW_TAG_structure_type: |
4352 | case DW_TAG_union_type: | |
4353 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
4354 | /* Skip external references. The DWARF standard says in the section |
4355 | about "Structure, Union, and Class Type Entries": "An incomplete | |
4356 | structure, union or class type is represented by a structure, | |
4357 | union or class entry that does not have a byte size attribute | |
4358 | and that has a DW_AT_declaration attribute." */ | |
4359 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
4360 | { |
4361 | if (built_actual_name) | |
4362 | xfree (actual_name); | |
4363 | return; | |
4364 | } | |
fa4028e9 | 4365 | |
63d06c5c DC |
4366 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
4367 | static vs. global. */ | |
38d518c9 | 4368 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4369 | built_actual_name, |
176620f1 | 4370 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
4371 | (cu->language == language_cplus |
4372 | || cu->language == language_java) | |
63d06c5c DC |
4373 | ? &objfile->global_psymbols |
4374 | : &objfile->static_psymbols, | |
e142c38c | 4375 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4376 | |
c906108c SS |
4377 | break; |
4378 | case DW_TAG_enumerator: | |
38d518c9 | 4379 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4380 | built_actual_name, |
176620f1 | 4381 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4382 | (cu->language == language_cplus |
4383 | || cu->language == language_java) | |
f6fe98ef DJ |
4384 | ? &objfile->global_psymbols |
4385 | : &objfile->static_psymbols, | |
e142c38c | 4386 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4387 | break; |
4388 | default: | |
4389 | break; | |
4390 | } | |
5c4e30ca | 4391 | |
72bf9492 DJ |
4392 | if (built_actual_name) |
4393 | xfree (actual_name); | |
c906108c SS |
4394 | } |
4395 | ||
5c4e30ca DC |
4396 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4397 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4398 | the name of the enclosing namespace. */ | |
91c24f0a | 4399 | |
72bf9492 DJ |
4400 | static void |
4401 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4402 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4403 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4404 | { |
72bf9492 | 4405 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4406 | |
72bf9492 | 4407 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4408 | |
4409 | /* Now scan partial symbols in that namespace. */ | |
4410 | ||
91c24f0a | 4411 | if (pdi->has_children) |
5734ee8b | 4412 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4413 | } |
4414 | ||
5d7cb8df JK |
4415 | /* Read a partial die corresponding to a Fortran module. */ |
4416 | ||
4417 | static void | |
4418 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4419 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4420 | { | |
f55ee35c | 4421 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4422 | |
4423 | if (pdi->has_children) | |
4424 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4425 | } | |
4426 | ||
bc30ff58 JB |
4427 | /* Read a partial die corresponding to a subprogram and create a partial |
4428 | symbol for that subprogram. When the CU language allows it, this | |
4429 | routine also defines a partial symbol for each nested subprogram | |
4430 | that this subprogram contains. | |
6e70227d | 4431 | |
bc30ff58 JB |
4432 | DIE my also be a lexical block, in which case we simply search |
4433 | recursively for suprograms defined inside that lexical block. | |
4434 | Again, this is only performed when the CU language allows this | |
4435 | type of definitions. */ | |
4436 | ||
4437 | static void | |
4438 | add_partial_subprogram (struct partial_die_info *pdi, | |
4439 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4440 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4441 | { |
4442 | if (pdi->tag == DW_TAG_subprogram) | |
4443 | { | |
4444 | if (pdi->has_pc_info) | |
4445 | { | |
4446 | if (pdi->lowpc < *lowpc) | |
4447 | *lowpc = pdi->lowpc; | |
4448 | if (pdi->highpc > *highpc) | |
4449 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4450 | if (need_pc) |
4451 | { | |
4452 | CORE_ADDR baseaddr; | |
4453 | struct objfile *objfile = cu->objfile; | |
4454 | ||
4455 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4456 | SECT_OFF_TEXT (objfile)); | |
4457 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4458 | pdi->lowpc + baseaddr, |
4459 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4460 | cu->per_cu->v.psymtab); |
5734ee8b | 4461 | } |
481860b3 GB |
4462 | } |
4463 | ||
4464 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) | |
4465 | { | |
bc30ff58 | 4466 | if (!pdi->is_declaration) |
e8d05480 JB |
4467 | /* Ignore subprogram DIEs that do not have a name, they are |
4468 | illegal. Do not emit a complaint at this point, we will | |
4469 | do so when we convert this psymtab into a symtab. */ | |
4470 | if (pdi->name) | |
4471 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4472 | } |
4473 | } | |
6e70227d | 4474 | |
bc30ff58 JB |
4475 | if (! pdi->has_children) |
4476 | return; | |
4477 | ||
4478 | if (cu->language == language_ada) | |
4479 | { | |
4480 | pdi = pdi->die_child; | |
4481 | while (pdi != NULL) | |
4482 | { | |
4483 | fixup_partial_die (pdi, cu); | |
4484 | if (pdi->tag == DW_TAG_subprogram | |
4485 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4486 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4487 | pdi = pdi->die_sibling; |
4488 | } | |
4489 | } | |
4490 | } | |
4491 | ||
91c24f0a DC |
4492 | /* Read a partial die corresponding to an enumeration type. */ |
4493 | ||
72bf9492 DJ |
4494 | static void |
4495 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4496 | struct dwarf2_cu *cu) | |
91c24f0a | 4497 | { |
72bf9492 | 4498 | struct partial_die_info *pdi; |
91c24f0a DC |
4499 | |
4500 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4501 | add_partial_symbol (enum_pdi, cu); |
4502 | ||
4503 | pdi = enum_pdi->die_child; | |
4504 | while (pdi) | |
91c24f0a | 4505 | { |
72bf9492 | 4506 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4507 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4508 | else |
72bf9492 DJ |
4509 | add_partial_symbol (pdi, cu); |
4510 | pdi = pdi->die_sibling; | |
91c24f0a | 4511 | } |
91c24f0a DC |
4512 | } |
4513 | ||
6caca83c CC |
4514 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
4515 | ||
4516 | static unsigned int | |
4517 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) | |
4518 | { | |
4519 | unsigned int bytes_read; | |
4520 | ||
4521 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4522 | } | |
4523 | ||
4bb7a0a7 DJ |
4524 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4525 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4526 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4527 | the initial number. */ | |
4528 | ||
4529 | static struct abbrev_info * | |
fe1b8b76 | 4530 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4531 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4532 | { |
4533 | bfd *abfd = cu->objfile->obfd; | |
4534 | unsigned int abbrev_number; | |
4535 | struct abbrev_info *abbrev; | |
4536 | ||
4537 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4538 | ||
4539 | if (abbrev_number == 0) | |
4540 | return NULL; | |
4541 | ||
4542 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4543 | if (!abbrev) | |
4544 | { | |
3e43a32a MS |
4545 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4546 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4547 | } |
4548 | ||
4549 | return abbrev; | |
4550 | } | |
4551 | ||
93311388 DE |
4552 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4553 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4554 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4555 | ||
fe1b8b76 | 4556 | static gdb_byte * |
dee91e82 | 4557 | skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr) |
4bb7a0a7 | 4558 | { |
dee91e82 | 4559 | struct dwarf2_cu *cu = reader->cu; |
4bb7a0a7 DJ |
4560 | struct abbrev_info *abbrev; |
4561 | unsigned int bytes_read; | |
4562 | ||
4563 | while (1) | |
4564 | { | |
4565 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4566 | if (abbrev == NULL) | |
4567 | return info_ptr + bytes_read; | |
4568 | else | |
dee91e82 | 4569 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
4bb7a0a7 DJ |
4570 | } |
4571 | } | |
4572 | ||
93311388 DE |
4573 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4574 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4575 | abbrev corresponding to that skipped uleb128 should be passed in |
4576 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4577 | children. */ | |
4578 | ||
fe1b8b76 | 4579 | static gdb_byte * |
dee91e82 DE |
4580 | skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr, |
4581 | struct abbrev_info *abbrev) | |
4bb7a0a7 DJ |
4582 | { |
4583 | unsigned int bytes_read; | |
4584 | struct attribute attr; | |
dee91e82 DE |
4585 | bfd *abfd = reader->abfd; |
4586 | struct dwarf2_cu *cu = reader->cu; | |
4587 | gdb_byte *buffer = reader->buffer; | |
4bb7a0a7 DJ |
4588 | unsigned int form, i; |
4589 | ||
4590 | for (i = 0; i < abbrev->num_attrs; i++) | |
4591 | { | |
4592 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4593 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4594 | { | |
dee91e82 | 4595 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
4bb7a0a7 | 4596 | if (attr.form == DW_FORM_ref_addr) |
3e43a32a MS |
4597 | complaint (&symfile_complaints, |
4598 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4599 | else |
b64f50a1 | 4600 | return buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
4bb7a0a7 DJ |
4601 | } |
4602 | ||
4603 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4604 | form = abbrev->attrs[i].form; | |
4605 | skip_attribute: | |
4606 | switch (form) | |
4607 | { | |
4bb7a0a7 | 4608 | case DW_FORM_ref_addr: |
ae411497 TT |
4609 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4610 | and later it is offset sized. */ | |
4611 | if (cu->header.version == 2) | |
4612 | info_ptr += cu->header.addr_size; | |
4613 | else | |
4614 | info_ptr += cu->header.offset_size; | |
4615 | break; | |
4616 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4617 | info_ptr += cu->header.addr_size; |
4618 | break; | |
4619 | case DW_FORM_data1: | |
4620 | case DW_FORM_ref1: | |
4621 | case DW_FORM_flag: | |
4622 | info_ptr += 1; | |
4623 | break; | |
2dc7f7b3 TT |
4624 | case DW_FORM_flag_present: |
4625 | break; | |
4bb7a0a7 DJ |
4626 | case DW_FORM_data2: |
4627 | case DW_FORM_ref2: | |
4628 | info_ptr += 2; | |
4629 | break; | |
4630 | case DW_FORM_data4: | |
4631 | case DW_FORM_ref4: | |
4632 | info_ptr += 4; | |
4633 | break; | |
4634 | case DW_FORM_data8: | |
4635 | case DW_FORM_ref8: | |
55f1336d | 4636 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4637 | info_ptr += 8; |
4638 | break; | |
4639 | case DW_FORM_string: | |
9b1c24c8 | 4640 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4641 | info_ptr += bytes_read; |
4642 | break; | |
2dc7f7b3 | 4643 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4644 | case DW_FORM_strp: |
4645 | info_ptr += cu->header.offset_size; | |
4646 | break; | |
2dc7f7b3 | 4647 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4648 | case DW_FORM_block: |
4649 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4650 | info_ptr += bytes_read; | |
4651 | break; | |
4652 | case DW_FORM_block1: | |
4653 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4654 | break; | |
4655 | case DW_FORM_block2: | |
4656 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4657 | break; | |
4658 | case DW_FORM_block4: | |
4659 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4660 | break; | |
4661 | case DW_FORM_sdata: | |
4662 | case DW_FORM_udata: | |
4663 | case DW_FORM_ref_udata: | |
4664 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4665 | break; | |
4666 | case DW_FORM_indirect: | |
4667 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4668 | info_ptr += bytes_read; | |
4669 | /* We need to continue parsing from here, so just go back to | |
4670 | the top. */ | |
4671 | goto skip_attribute; | |
4672 | ||
4673 | default: | |
3e43a32a MS |
4674 | error (_("Dwarf Error: Cannot handle %s " |
4675 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4676 | dwarf_form_name (form), |
4677 | bfd_get_filename (abfd)); | |
4678 | } | |
4679 | } | |
4680 | ||
4681 | if (abbrev->has_children) | |
dee91e82 | 4682 | return skip_children (reader, info_ptr); |
4bb7a0a7 DJ |
4683 | else |
4684 | return info_ptr; | |
4685 | } | |
4686 | ||
93311388 | 4687 | /* Locate ORIG_PDI's sibling. |
dee91e82 | 4688 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
91c24f0a | 4689 | |
fe1b8b76 | 4690 | static gdb_byte * |
dee91e82 DE |
4691 | locate_pdi_sibling (const struct die_reader_specs *reader, |
4692 | struct partial_die_info *orig_pdi, | |
4693 | gdb_byte *info_ptr) | |
91c24f0a DC |
4694 | { |
4695 | /* Do we know the sibling already? */ | |
72bf9492 | 4696 | |
91c24f0a DC |
4697 | if (orig_pdi->sibling) |
4698 | return orig_pdi->sibling; | |
4699 | ||
4700 | /* Are there any children to deal with? */ | |
4701 | ||
4702 | if (!orig_pdi->has_children) | |
4703 | return info_ptr; | |
4704 | ||
4bb7a0a7 | 4705 | /* Skip the children the long way. */ |
91c24f0a | 4706 | |
dee91e82 | 4707 | return skip_children (reader, info_ptr); |
91c24f0a DC |
4708 | } |
4709 | ||
c906108c SS |
4710 | /* Expand this partial symbol table into a full symbol table. */ |
4711 | ||
4712 | static void | |
fba45db2 | 4713 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4714 | { |
c906108c SS |
4715 | if (pst != NULL) |
4716 | { | |
4717 | if (pst->readin) | |
4718 | { | |
3e43a32a MS |
4719 | warning (_("bug: psymtab for %s is already read in."), |
4720 | pst->filename); | |
c906108c SS |
4721 | } |
4722 | else | |
4723 | { | |
4724 | if (info_verbose) | |
4725 | { | |
3e43a32a MS |
4726 | printf_filtered (_("Reading in symbols for %s..."), |
4727 | pst->filename); | |
c906108c SS |
4728 | gdb_flush (gdb_stdout); |
4729 | } | |
4730 | ||
10b3939b DJ |
4731 | /* Restore our global data. */ |
4732 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4733 | dwarf2_objfile_data_key); | |
4734 | ||
b2ab525c KB |
4735 | /* If this psymtab is constructed from a debug-only objfile, the |
4736 | has_section_at_zero flag will not necessarily be correct. We | |
4737 | can get the correct value for this flag by looking at the data | |
4738 | associated with the (presumably stripped) associated objfile. */ | |
4739 | if (pst->objfile->separate_debug_objfile_backlink) | |
4740 | { | |
4741 | struct dwarf2_per_objfile *dpo_backlink | |
4742 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4743 | dwarf2_objfile_data_key); | |
9a619af0 | 4744 | |
b2ab525c KB |
4745 | dwarf2_per_objfile->has_section_at_zero |
4746 | = dpo_backlink->has_section_at_zero; | |
4747 | } | |
4748 | ||
98bfdba5 PA |
4749 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4750 | ||
c906108c SS |
4751 | psymtab_to_symtab_1 (pst); |
4752 | ||
4753 | /* Finish up the debug error message. */ | |
4754 | if (info_verbose) | |
a3f17187 | 4755 | printf_filtered (_("done.\n")); |
c906108c SS |
4756 | } |
4757 | } | |
4758 | } | |
9cdd5dbd DE |
4759 | \f |
4760 | /* Reading in full CUs. */ | |
c906108c | 4761 | |
10b3939b DJ |
4762 | /* Add PER_CU to the queue. */ |
4763 | ||
4764 | static void | |
a0f42c21 | 4765 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
10b3939b DJ |
4766 | { |
4767 | struct dwarf2_queue_item *item; | |
4768 | ||
4769 | per_cu->queued = 1; | |
4770 | item = xmalloc (sizeof (*item)); | |
4771 | item->per_cu = per_cu; | |
4772 | item->next = NULL; | |
4773 | ||
4774 | if (dwarf2_queue == NULL) | |
4775 | dwarf2_queue = item; | |
4776 | else | |
4777 | dwarf2_queue_tail->next = item; | |
4778 | ||
4779 | dwarf2_queue_tail = item; | |
4780 | } | |
4781 | ||
4782 | /* Process the queue. */ | |
4783 | ||
4784 | static void | |
a0f42c21 | 4785 | process_queue (void) |
10b3939b DJ |
4786 | { |
4787 | struct dwarf2_queue_item *item, *next_item; | |
4788 | ||
03dd20cc DJ |
4789 | /* The queue starts out with one item, but following a DIE reference |
4790 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4791 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4792 | { | |
9291a0cd TT |
4793 | if (dwarf2_per_objfile->using_index |
4794 | ? !item->per_cu->v.quick->symtab | |
4795 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4796 | process_full_comp_unit (item->per_cu); |
4797 | ||
4798 | item->per_cu->queued = 0; | |
4799 | next_item = item->next; | |
4800 | xfree (item); | |
4801 | } | |
4802 | ||
4803 | dwarf2_queue_tail = NULL; | |
4804 | } | |
4805 | ||
4806 | /* Free all allocated queue entries. This function only releases anything if | |
4807 | an error was thrown; if the queue was processed then it would have been | |
4808 | freed as we went along. */ | |
4809 | ||
4810 | static void | |
4811 | dwarf2_release_queue (void *dummy) | |
4812 | { | |
4813 | struct dwarf2_queue_item *item, *last; | |
4814 | ||
4815 | item = dwarf2_queue; | |
4816 | while (item) | |
4817 | { | |
4818 | /* Anything still marked queued is likely to be in an | |
4819 | inconsistent state, so discard it. */ | |
4820 | if (item->per_cu->queued) | |
4821 | { | |
4822 | if (item->per_cu->cu != NULL) | |
dee91e82 | 4823 | free_one_cached_comp_unit (item->per_cu); |
10b3939b DJ |
4824 | item->per_cu->queued = 0; |
4825 | } | |
4826 | ||
4827 | last = item; | |
4828 | item = item->next; | |
4829 | xfree (last); | |
4830 | } | |
4831 | ||
4832 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4833 | } | |
4834 | ||
4835 | /* Read in full symbols for PST, and anything it depends on. */ | |
4836 | ||
c906108c | 4837 | static void |
fba45db2 | 4838 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4839 | { |
10b3939b | 4840 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4841 | struct cleanup *back_to; |
aaa75496 JB |
4842 | int i; |
4843 | ||
4844 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4845 | if (!pst->dependencies[i]->readin) | |
4846 | { | |
4847 | /* Inform about additional files that need to be read in. */ | |
4848 | if (info_verbose) | |
4849 | { | |
a3f17187 | 4850 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4851 | fputs_filtered (" ", gdb_stdout); |
4852 | wrap_here (""); | |
4853 | fputs_filtered ("and ", gdb_stdout); | |
4854 | wrap_here (""); | |
4855 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4856 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4857 | gdb_flush (gdb_stdout); |
4858 | } | |
4859 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4860 | } | |
4861 | ||
e38df1d0 | 4862 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4863 | |
4864 | if (per_cu == NULL) | |
aaa75496 JB |
4865 | { |
4866 | /* It's an include file, no symbols to read for it. | |
4867 | Everything is in the parent symtab. */ | |
4868 | pst->readin = 1; | |
4869 | return; | |
4870 | } | |
c906108c | 4871 | |
a0f42c21 | 4872 | dw2_do_instantiate_symtab (per_cu); |
10b3939b DJ |
4873 | } |
4874 | ||
dee91e82 DE |
4875 | /* Trivial hash function for die_info: the hash value of a DIE |
4876 | is its offset in .debug_info for this objfile. */ | |
10b3939b | 4877 | |
dee91e82 DE |
4878 | static hashval_t |
4879 | die_hash (const void *item) | |
10b3939b | 4880 | { |
dee91e82 | 4881 | const struct die_info *die = item; |
6502dd73 | 4882 | |
dee91e82 DE |
4883 | return die->offset.sect_off; |
4884 | } | |
63d06c5c | 4885 | |
dee91e82 DE |
4886 | /* Trivial comparison function for die_info structures: two DIEs |
4887 | are equal if they have the same offset. */ | |
98bfdba5 | 4888 | |
dee91e82 DE |
4889 | static int |
4890 | die_eq (const void *item_lhs, const void *item_rhs) | |
4891 | { | |
4892 | const struct die_info *die_lhs = item_lhs; | |
4893 | const struct die_info *die_rhs = item_rhs; | |
c906108c | 4894 | |
dee91e82 DE |
4895 | return die_lhs->offset.sect_off == die_rhs->offset.sect_off; |
4896 | } | |
c906108c | 4897 | |
dee91e82 DE |
4898 | /* die_reader_func for load_full_comp_unit. |
4899 | This is identical to read_signatured_type_reader, | |
4900 | but is kept separate for now. */ | |
c906108c | 4901 | |
dee91e82 DE |
4902 | static void |
4903 | load_full_comp_unit_reader (const struct die_reader_specs *reader, | |
4904 | gdb_byte *info_ptr, | |
4905 | struct die_info *comp_unit_die, | |
4906 | int has_children, | |
4907 | void *data) | |
4908 | { | |
4909 | struct dwarf2_cu *cu = reader->cu; | |
4910 | struct attribute *attr; | |
6caca83c | 4911 | |
dee91e82 DE |
4912 | gdb_assert (cu->die_hash == NULL); |
4913 | cu->die_hash = | |
4914 | htab_create_alloc_ex (cu->header.length / 12, | |
4915 | die_hash, | |
4916 | die_eq, | |
4917 | NULL, | |
4918 | &cu->comp_unit_obstack, | |
4919 | hashtab_obstack_allocate, | |
4920 | dummy_obstack_deallocate); | |
e142c38c | 4921 | |
dee91e82 DE |
4922 | if (has_children) |
4923 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
4924 | &info_ptr, comp_unit_die); | |
4925 | cu->dies = comp_unit_die; | |
4926 | /* comp_unit_die is not stored in die_hash, no need. */ | |
10b3939b DJ |
4927 | |
4928 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 4929 | all CUs needed for references have been loaded yet, and symbol |
10b3939b | 4930 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
4931 | or we won't be able to build types correctly. |
4932 | Similarly, if we do not read the producer, we can not apply | |
4933 | producer-specific interpretation. */ | |
9816fde3 | 4934 | prepare_one_comp_unit (cu, cu->dies); |
dee91e82 | 4935 | } |
10b3939b | 4936 | |
dee91e82 | 4937 | /* Load the DIEs associated with PER_CU into memory. */ |
a6c727b2 | 4938 | |
dee91e82 DE |
4939 | static void |
4940 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu) | |
4941 | { | |
4942 | gdb_assert (! this_cu->debug_types_section); | |
c5b7e1cb | 4943 | |
dee91e82 | 4944 | init_cu_and_read_dies (this_cu, 1, 1, load_full_comp_unit_reader, NULL); |
10b3939b DJ |
4945 | } |
4946 | ||
3da10d80 KS |
4947 | /* Add a DIE to the delayed physname list. */ |
4948 | ||
4949 | static void | |
4950 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4951 | const char *name, struct die_info *die, | |
4952 | struct dwarf2_cu *cu) | |
4953 | { | |
4954 | struct delayed_method_info mi; | |
4955 | mi.type = type; | |
4956 | mi.fnfield_index = fnfield_index; | |
4957 | mi.index = index; | |
4958 | mi.name = name; | |
4959 | mi.die = die; | |
4960 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4961 | } | |
4962 | ||
4963 | /* A cleanup for freeing the delayed method list. */ | |
4964 | ||
4965 | static void | |
4966 | free_delayed_list (void *ptr) | |
4967 | { | |
4968 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4969 | if (cu->method_list != NULL) | |
4970 | { | |
4971 | VEC_free (delayed_method_info, cu->method_list); | |
4972 | cu->method_list = NULL; | |
4973 | } | |
4974 | } | |
4975 | ||
4976 | /* Compute the physnames of any methods on the CU's method list. | |
4977 | ||
4978 | The computation of method physnames is delayed in order to avoid the | |
4979 | (bad) condition that one of the method's formal parameters is of an as yet | |
4980 | incomplete type. */ | |
4981 | ||
4982 | static void | |
4983 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4984 | { | |
4985 | int i; | |
4986 | struct delayed_method_info *mi; | |
4987 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4988 | { | |
1d06ead6 | 4989 | const char *physname; |
3da10d80 KS |
4990 | struct fn_fieldlist *fn_flp |
4991 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
1d06ead6 | 4992 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
3da10d80 KS |
4993 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
4994 | } | |
4995 | } | |
4996 | ||
a766d390 DE |
4997 | /* Go objects should be embedded in a DW_TAG_module DIE, |
4998 | and it's not clear if/how imported objects will appear. | |
4999 | To keep Go support simple until that's worked out, | |
5000 | go back through what we've read and create something usable. | |
5001 | We could do this while processing each DIE, and feels kinda cleaner, | |
5002 | but that way is more invasive. | |
5003 | This is to, for example, allow the user to type "p var" or "b main" | |
5004 | without having to specify the package name, and allow lookups | |
5005 | of module.object to work in contexts that use the expression | |
5006 | parser. */ | |
5007 | ||
5008 | static void | |
5009 | fixup_go_packaging (struct dwarf2_cu *cu) | |
5010 | { | |
5011 | char *package_name = NULL; | |
5012 | struct pending *list; | |
5013 | int i; | |
5014 | ||
5015 | for (list = global_symbols; list != NULL; list = list->next) | |
5016 | { | |
5017 | for (i = 0; i < list->nsyms; ++i) | |
5018 | { | |
5019 | struct symbol *sym = list->symbol[i]; | |
5020 | ||
5021 | if (SYMBOL_LANGUAGE (sym) == language_go | |
5022 | && SYMBOL_CLASS (sym) == LOC_BLOCK) | |
5023 | { | |
5024 | char *this_package_name = go_symbol_package_name (sym); | |
5025 | ||
5026 | if (this_package_name == NULL) | |
5027 | continue; | |
5028 | if (package_name == NULL) | |
5029 | package_name = this_package_name; | |
5030 | else | |
5031 | { | |
5032 | if (strcmp (package_name, this_package_name) != 0) | |
5033 | complaint (&symfile_complaints, | |
5034 | _("Symtab %s has objects from two different Go packages: %s and %s"), | |
5035 | (sym->symtab && sym->symtab->filename | |
5036 | ? sym->symtab->filename | |
5037 | : cu->objfile->name), | |
5038 | this_package_name, package_name); | |
5039 | xfree (this_package_name); | |
5040 | } | |
5041 | } | |
5042 | } | |
5043 | } | |
5044 | ||
5045 | if (package_name != NULL) | |
5046 | { | |
5047 | struct objfile *objfile = cu->objfile; | |
5048 | struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, | |
5049 | package_name, objfile); | |
5050 | struct symbol *sym; | |
5051 | ||
5052 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
5053 | ||
5054 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
5055 | SYMBOL_SET_LANGUAGE (sym, language_go); | |
5056 | SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile); | |
5057 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, | |
5058 | e.g., "main" finds the "main" module and not C's main(). */ | |
5059 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; | |
5060 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
5061 | SYMBOL_TYPE (sym) = type; | |
5062 | ||
5063 | add_symbol_to_list (sym, &global_symbols); | |
5064 | ||
5065 | xfree (package_name); | |
5066 | } | |
5067 | } | |
5068 | ||
9cdd5dbd | 5069 | /* Generate full symbol information for PER_CU, whose DIEs have |
10b3939b DJ |
5070 | already been loaded into memory. */ |
5071 | ||
5072 | static void | |
5073 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
5074 | { | |
10b3939b | 5075 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 5076 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
5077 | CORE_ADDR lowpc, highpc; |
5078 | struct symtab *symtab; | |
3da10d80 | 5079 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
5080 | CORE_ADDR baseaddr; |
5081 | ||
5082 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5083 | ||
10b3939b DJ |
5084 | buildsym_init (); |
5085 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 5086 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
5087 | |
5088 | cu->list_in_scope = &file_symbols; | |
c906108c SS |
5089 | |
5090 | /* Do line number decoding in read_file_scope () */ | |
10b3939b | 5091 | process_die (cu->dies, cu); |
c906108c | 5092 | |
a766d390 DE |
5093 | /* For now fudge the Go package. */ |
5094 | if (cu->language == language_go) | |
5095 | fixup_go_packaging (cu); | |
5096 | ||
3da10d80 KS |
5097 | /* Now that we have processed all the DIEs in the CU, all the types |
5098 | should be complete, and it should now be safe to compute all of the | |
5099 | physnames. */ | |
5100 | compute_delayed_physnames (cu); | |
5101 | do_cleanups (delayed_list_cleanup); | |
5102 | ||
fae299cd DC |
5103 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
5104 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
5105 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 5106 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 5107 | |
613e1657 | 5108 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c | 5109 | |
8be455d7 | 5110 | if (symtab != NULL) |
c906108c | 5111 | { |
df15bd07 | 5112 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
4632c0d0 | 5113 | |
8be455d7 JK |
5114 | /* Set symtab language to language from DW_AT_language. If the |
5115 | compilation is from a C file generated by language preprocessors, do | |
5116 | not set the language if it was already deduced by start_subfile. */ | |
5117 | if (!(cu->language == language_c && symtab->language != language_c)) | |
5118 | symtab->language = cu->language; | |
5119 | ||
5120 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can | |
5121 | produce DW_AT_location with location lists but it can be possibly | |
ab260dad JK |
5122 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
5123 | there were bugs in prologue debug info, fixed later in GCC-4.5 | |
5124 | by "unwind info for epilogues" patch (which is not directly related). | |
8be455d7 JK |
5125 | |
5126 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not | |
5127 | needed, it would be wrong due to missing DW_AT_producer there. | |
5128 | ||
5129 | Still one can confuse GDB by using non-standard GCC compilation | |
5130 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). | |
5131 | */ | |
ab260dad | 5132 | if (cu->has_loclist && gcc_4_minor >= 5) |
8be455d7 | 5133 | symtab->locations_valid = 1; |
e0d00bc7 JK |
5134 | |
5135 | if (gcc_4_minor >= 5) | |
5136 | symtab->epilogue_unwind_valid = 1; | |
96408a79 SA |
5137 | |
5138 | symtab->call_site_htab = cu->call_site_htab; | |
c906108c | 5139 | } |
9291a0cd TT |
5140 | |
5141 | if (dwarf2_per_objfile->using_index) | |
5142 | per_cu->v.quick->symtab = symtab; | |
5143 | else | |
5144 | { | |
5145 | struct partial_symtab *pst = per_cu->v.psymtab; | |
5146 | pst->symtab = symtab; | |
5147 | pst->readin = 1; | |
5148 | } | |
c906108c SS |
5149 | |
5150 | do_cleanups (back_to); | |
5151 | } | |
5152 | ||
5153 | /* Process a die and its children. */ | |
5154 | ||
5155 | static void | |
e7c27a73 | 5156 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5157 | { |
5158 | switch (die->tag) | |
5159 | { | |
5160 | case DW_TAG_padding: | |
5161 | break; | |
5162 | case DW_TAG_compile_unit: | |
e7c27a73 | 5163 | read_file_scope (die, cu); |
c906108c | 5164 | break; |
348e048f DE |
5165 | case DW_TAG_type_unit: |
5166 | read_type_unit_scope (die, cu); | |
5167 | break; | |
c906108c | 5168 | case DW_TAG_subprogram: |
c906108c | 5169 | case DW_TAG_inlined_subroutine: |
edb3359d | 5170 | read_func_scope (die, cu); |
c906108c SS |
5171 | break; |
5172 | case DW_TAG_lexical_block: | |
14898363 L |
5173 | case DW_TAG_try_block: |
5174 | case DW_TAG_catch_block: | |
e7c27a73 | 5175 | read_lexical_block_scope (die, cu); |
c906108c | 5176 | break; |
96408a79 SA |
5177 | case DW_TAG_GNU_call_site: |
5178 | read_call_site_scope (die, cu); | |
5179 | break; | |
c906108c | 5180 | case DW_TAG_class_type: |
680b30c7 | 5181 | case DW_TAG_interface_type: |
c906108c SS |
5182 | case DW_TAG_structure_type: |
5183 | case DW_TAG_union_type: | |
134d01f1 | 5184 | process_structure_scope (die, cu); |
c906108c SS |
5185 | break; |
5186 | case DW_TAG_enumeration_type: | |
134d01f1 | 5187 | process_enumeration_scope (die, cu); |
c906108c | 5188 | break; |
134d01f1 | 5189 | |
f792889a DJ |
5190 | /* These dies have a type, but processing them does not create |
5191 | a symbol or recurse to process the children. Therefore we can | |
5192 | read them on-demand through read_type_die. */ | |
c906108c | 5193 | case DW_TAG_subroutine_type: |
72019c9c | 5194 | case DW_TAG_set_type: |
c906108c | 5195 | case DW_TAG_array_type: |
c906108c | 5196 | case DW_TAG_pointer_type: |
c906108c | 5197 | case DW_TAG_ptr_to_member_type: |
c906108c | 5198 | case DW_TAG_reference_type: |
c906108c | 5199 | case DW_TAG_string_type: |
c906108c | 5200 | break; |
134d01f1 | 5201 | |
c906108c | 5202 | case DW_TAG_base_type: |
a02abb62 | 5203 | case DW_TAG_subrange_type: |
cb249c71 | 5204 | case DW_TAG_typedef: |
134d01f1 DJ |
5205 | /* Add a typedef symbol for the type definition, if it has a |
5206 | DW_AT_name. */ | |
f792889a | 5207 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 5208 | break; |
c906108c | 5209 | case DW_TAG_common_block: |
e7c27a73 | 5210 | read_common_block (die, cu); |
c906108c SS |
5211 | break; |
5212 | case DW_TAG_common_inclusion: | |
5213 | break; | |
d9fa45fe | 5214 | case DW_TAG_namespace: |
63d06c5c | 5215 | processing_has_namespace_info = 1; |
e7c27a73 | 5216 | read_namespace (die, cu); |
d9fa45fe | 5217 | break; |
5d7cb8df | 5218 | case DW_TAG_module: |
f55ee35c | 5219 | processing_has_namespace_info = 1; |
5d7cb8df JK |
5220 | read_module (die, cu); |
5221 | break; | |
d9fa45fe DC |
5222 | case DW_TAG_imported_declaration: |
5223 | case DW_TAG_imported_module: | |
63d06c5c | 5224 | processing_has_namespace_info = 1; |
27aa8d6a SW |
5225 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
5226 | || cu->language != language_fortran)) | |
5227 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
5228 | dwarf_tag_name (die->tag)); | |
5229 | read_import_statement (die, cu); | |
d9fa45fe | 5230 | break; |
c906108c | 5231 | default: |
e7c27a73 | 5232 | new_symbol (die, NULL, cu); |
c906108c SS |
5233 | break; |
5234 | } | |
5235 | } | |
5236 | ||
94af9270 KS |
5237 | /* A helper function for dwarf2_compute_name which determines whether DIE |
5238 | needs to have the name of the scope prepended to the name listed in the | |
5239 | die. */ | |
5240 | ||
5241 | static int | |
5242 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
5243 | { | |
1c809c68 TT |
5244 | struct attribute *attr; |
5245 | ||
94af9270 KS |
5246 | switch (die->tag) |
5247 | { | |
5248 | case DW_TAG_namespace: | |
5249 | case DW_TAG_typedef: | |
5250 | case DW_TAG_class_type: | |
5251 | case DW_TAG_interface_type: | |
5252 | case DW_TAG_structure_type: | |
5253 | case DW_TAG_union_type: | |
5254 | case DW_TAG_enumeration_type: | |
5255 | case DW_TAG_enumerator: | |
5256 | case DW_TAG_subprogram: | |
5257 | case DW_TAG_member: | |
5258 | return 1; | |
5259 | ||
5260 | case DW_TAG_variable: | |
c2b0a229 | 5261 | case DW_TAG_constant: |
94af9270 KS |
5262 | /* We only need to prefix "globally" visible variables. These include |
5263 | any variable marked with DW_AT_external or any variable that | |
5264 | lives in a namespace. [Variables in anonymous namespaces | |
5265 | require prefixing, but they are not DW_AT_external.] */ | |
5266 | ||
5267 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
5268 | { | |
5269 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 5270 | |
94af9270 KS |
5271 | return die_needs_namespace (die_specification (die, &spec_cu), |
5272 | spec_cu); | |
5273 | } | |
5274 | ||
1c809c68 | 5275 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
5276 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
5277 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
5278 | return 0; |
5279 | /* A variable in a lexical block of some kind does not need a | |
5280 | namespace, even though in C++ such variables may be external | |
5281 | and have a mangled name. */ | |
5282 | if (die->parent->tag == DW_TAG_lexical_block | |
5283 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
5284 | || die->parent->tag == DW_TAG_catch_block |
5285 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
5286 | return 0; |
5287 | return 1; | |
94af9270 KS |
5288 | |
5289 | default: | |
5290 | return 0; | |
5291 | } | |
5292 | } | |
5293 | ||
98bfdba5 PA |
5294 | /* Retrieve the last character from a mem_file. */ |
5295 | ||
5296 | static void | |
5297 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
5298 | { | |
5299 | char *last_char_p = (char *) object; | |
5300 | ||
5301 | if (length > 0) | |
5302 | *last_char_p = buffer[length - 1]; | |
5303 | } | |
5304 | ||
94af9270 | 5305 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
a766d390 DE |
5306 | compute the physname for the object, which include a method's: |
5307 | - formal parameters (C++/Java), | |
5308 | - receiver type (Go), | |
5309 | - return type (Java). | |
5310 | ||
5311 | The term "physname" is a bit confusing. | |
5312 | For C++, for example, it is the demangled name. | |
5313 | For Go, for example, it's the mangled name. | |
94af9270 | 5314 | |
af6b7be1 JB |
5315 | For Ada, return the DIE's linkage name rather than the fully qualified |
5316 | name. PHYSNAME is ignored.. | |
5317 | ||
94af9270 KS |
5318 | The result is allocated on the objfile_obstack and canonicalized. */ |
5319 | ||
5320 | static const char * | |
5321 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
5322 | int physname) | |
5323 | { | |
bb5ed363 DE |
5324 | struct objfile *objfile = cu->objfile; |
5325 | ||
94af9270 KS |
5326 | if (name == NULL) |
5327 | name = dwarf2_name (die, cu); | |
5328 | ||
f55ee35c JK |
5329 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
5330 | compute it by typename_concat inside GDB. */ | |
5331 | if (cu->language == language_ada | |
5332 | || (cu->language == language_fortran && physname)) | |
5333 | { | |
5334 | /* For Ada unit, we prefer the linkage name over the name, as | |
5335 | the former contains the exported name, which the user expects | |
5336 | to be able to reference. Ideally, we want the user to be able | |
5337 | to reference this entity using either natural or linkage name, | |
5338 | but we haven't started looking at this enhancement yet. */ | |
5339 | struct attribute *attr; | |
5340 | ||
5341 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5342 | if (attr == NULL) | |
5343 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5344 | if (attr && DW_STRING (attr)) | |
5345 | return DW_STRING (attr); | |
5346 | } | |
5347 | ||
94af9270 KS |
5348 | /* These are the only languages we know how to qualify names in. */ |
5349 | if (name != NULL | |
f55ee35c JK |
5350 | && (cu->language == language_cplus || cu->language == language_java |
5351 | || cu->language == language_fortran)) | |
94af9270 KS |
5352 | { |
5353 | if (die_needs_namespace (die, cu)) | |
5354 | { | |
5355 | long length; | |
0d5cff50 | 5356 | const char *prefix; |
94af9270 KS |
5357 | struct ui_file *buf; |
5358 | ||
5359 | prefix = determine_prefix (die, cu); | |
5360 | buf = mem_fileopen (); | |
5361 | if (*prefix != '\0') | |
5362 | { | |
f55ee35c JK |
5363 | char *prefixed_name = typename_concat (NULL, prefix, name, |
5364 | physname, cu); | |
9a619af0 | 5365 | |
94af9270 KS |
5366 | fputs_unfiltered (prefixed_name, buf); |
5367 | xfree (prefixed_name); | |
5368 | } | |
5369 | else | |
62d5b8da | 5370 | fputs_unfiltered (name, buf); |
94af9270 | 5371 | |
98bfdba5 PA |
5372 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
5373 | as children with DW_TAG_template_type_param or | |
5374 | DW_TAG_value_type_param. If the latter, add them to the name | |
5375 | here. If the name already has template parameters, then | |
5376 | skip this step; some versions of GCC emit both, and | |
5377 | it is more efficient to use the pre-computed name. | |
5378 | ||
5379 | Something to keep in mind about this process: it is very | |
5380 | unlikely, or in some cases downright impossible, to produce | |
5381 | something that will match the mangled name of a function. | |
5382 | If the definition of the function has the same debug info, | |
5383 | we should be able to match up with it anyway. But fallbacks | |
5384 | using the minimal symbol, for instance to find a method | |
5385 | implemented in a stripped copy of libstdc++, will not work. | |
5386 | If we do not have debug info for the definition, we will have to | |
5387 | match them up some other way. | |
5388 | ||
5389 | When we do name matching there is a related problem with function | |
5390 | templates; two instantiated function templates are allowed to | |
5391 | differ only by their return types, which we do not add here. */ | |
5392 | ||
5393 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
5394 | { | |
5395 | struct attribute *attr; | |
5396 | struct die_info *child; | |
5397 | int first = 1; | |
5398 | ||
5399 | die->building_fullname = 1; | |
5400 | ||
5401 | for (child = die->child; child != NULL; child = child->sibling) | |
5402 | { | |
5403 | struct type *type; | |
12df843f | 5404 | LONGEST value; |
98bfdba5 PA |
5405 | gdb_byte *bytes; |
5406 | struct dwarf2_locexpr_baton *baton; | |
5407 | struct value *v; | |
5408 | ||
5409 | if (child->tag != DW_TAG_template_type_param | |
5410 | && child->tag != DW_TAG_template_value_param) | |
5411 | continue; | |
5412 | ||
5413 | if (first) | |
5414 | { | |
5415 | fputs_unfiltered ("<", buf); | |
5416 | first = 0; | |
5417 | } | |
5418 | else | |
5419 | fputs_unfiltered (", ", buf); | |
5420 | ||
5421 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
5422 | if (attr == NULL) | |
5423 | { | |
5424 | complaint (&symfile_complaints, | |
5425 | _("template parameter missing DW_AT_type")); | |
5426 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
5427 | continue; | |
5428 | } | |
5429 | type = die_type (child, cu); | |
5430 | ||
5431 | if (child->tag == DW_TAG_template_type_param) | |
5432 | { | |
5433 | c_print_type (type, "", buf, -1, 0); | |
5434 | continue; | |
5435 | } | |
5436 | ||
5437 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
5438 | if (attr == NULL) | |
5439 | { | |
5440 | complaint (&symfile_complaints, | |
3e43a32a MS |
5441 | _("template parameter missing " |
5442 | "DW_AT_const_value")); | |
98bfdba5 PA |
5443 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
5444 | continue; | |
5445 | } | |
5446 | ||
5447 | dwarf2_const_value_attr (attr, type, name, | |
5448 | &cu->comp_unit_obstack, cu, | |
5449 | &value, &bytes, &baton); | |
5450 | ||
5451 | if (TYPE_NOSIGN (type)) | |
5452 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
5453 | changed, this can use value_print instead. */ | |
5454 | c_printchar (value, type, buf); | |
5455 | else | |
5456 | { | |
5457 | struct value_print_options opts; | |
5458 | ||
5459 | if (baton != NULL) | |
5460 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
5461 | baton->data, | |
5462 | baton->size, | |
5463 | baton->per_cu); | |
5464 | else if (bytes != NULL) | |
5465 | { | |
5466 | v = allocate_value (type); | |
5467 | memcpy (value_contents_writeable (v), bytes, | |
5468 | TYPE_LENGTH (type)); | |
5469 | } | |
5470 | else | |
5471 | v = value_from_longest (type, value); | |
5472 | ||
3e43a32a MS |
5473 | /* Specify decimal so that we do not depend on |
5474 | the radix. */ | |
98bfdba5 PA |
5475 | get_formatted_print_options (&opts, 'd'); |
5476 | opts.raw = 1; | |
5477 | value_print (v, buf, &opts); | |
5478 | release_value (v); | |
5479 | value_free (v); | |
5480 | } | |
5481 | } | |
5482 | ||
5483 | die->building_fullname = 0; | |
5484 | ||
5485 | if (!first) | |
5486 | { | |
5487 | /* Close the argument list, with a space if necessary | |
5488 | (nested templates). */ | |
5489 | char last_char = '\0'; | |
5490 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5491 | if (last_char == '>') | |
5492 | fputs_unfiltered (" >", buf); | |
5493 | else | |
5494 | fputs_unfiltered (">", buf); | |
5495 | } | |
5496 | } | |
5497 | ||
94af9270 KS |
5498 | /* For Java and C++ methods, append formal parameter type |
5499 | information, if PHYSNAME. */ | |
6e70227d | 5500 | |
94af9270 KS |
5501 | if (physname && die->tag == DW_TAG_subprogram |
5502 | && (cu->language == language_cplus | |
5503 | || cu->language == language_java)) | |
5504 | { | |
5505 | struct type *type = read_type_die (die, cu); | |
5506 | ||
3167638f | 5507 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5508 | |
5509 | if (cu->language == language_java) | |
5510 | { | |
5511 | /* For java, we must append the return type to method | |
0963b4bd | 5512 | names. */ |
94af9270 KS |
5513 | if (die->tag == DW_TAG_subprogram) |
5514 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5515 | 0, 0); | |
5516 | } | |
5517 | else if (cu->language == language_cplus) | |
5518 | { | |
60430eff DJ |
5519 | /* Assume that an artificial first parameter is |
5520 | "this", but do not crash if it is not. RealView | |
5521 | marks unnamed (and thus unused) parameters as | |
5522 | artificial; there is no way to differentiate | |
5523 | the two cases. */ | |
94af9270 KS |
5524 | if (TYPE_NFIELDS (type) > 0 |
5525 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5526 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5527 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5528 | 0)))) | |
94af9270 KS |
5529 | fputs_unfiltered (" const", buf); |
5530 | } | |
5531 | } | |
5532 | ||
bb5ed363 | 5533 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
94af9270 KS |
5534 | &length); |
5535 | ui_file_delete (buf); | |
5536 | ||
5537 | if (cu->language == language_cplus) | |
5538 | { | |
5539 | char *cname | |
5540 | = dwarf2_canonicalize_name (name, cu, | |
bb5ed363 | 5541 | &objfile->objfile_obstack); |
9a619af0 | 5542 | |
94af9270 KS |
5543 | if (cname != NULL) |
5544 | name = cname; | |
5545 | } | |
5546 | } | |
5547 | } | |
5548 | ||
5549 | return name; | |
5550 | } | |
5551 | ||
0114d602 DJ |
5552 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5553 | If scope qualifiers are appropriate they will be added. The result | |
5554 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5555 | not have a name. NAME may either be from a previous call to |
5556 | dwarf2_name or NULL. | |
5557 | ||
0963b4bd | 5558 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5559 | |
5560 | static const char * | |
94af9270 | 5561 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5562 | { |
94af9270 KS |
5563 | return dwarf2_compute_name (name, die, cu, 0); |
5564 | } | |
0114d602 | 5565 | |
94af9270 KS |
5566 | /* Construct a physname for the given DIE in CU. NAME may either be |
5567 | from a previous call to dwarf2_name or NULL. The result will be | |
5568 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5569 | name. | |
0114d602 | 5570 | |
94af9270 | 5571 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5572 | |
94af9270 KS |
5573 | static const char * |
5574 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5575 | { | |
bb5ed363 | 5576 | struct objfile *objfile = cu->objfile; |
900e11f9 JK |
5577 | struct attribute *attr; |
5578 | const char *retval, *mangled = NULL, *canon = NULL; | |
5579 | struct cleanup *back_to; | |
5580 | int need_copy = 1; | |
5581 | ||
5582 | /* In this case dwarf2_compute_name is just a shortcut not building anything | |
5583 | on its own. */ | |
5584 | if (!die_needs_namespace (die, cu)) | |
5585 | return dwarf2_compute_name (name, die, cu, 1); | |
5586 | ||
5587 | back_to = make_cleanup (null_cleanup, NULL); | |
5588 | ||
5589 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
5590 | if (!attr) | |
5591 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
5592 | ||
5593 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB | |
5594 | has computed. */ | |
5595 | if (attr && DW_STRING (attr)) | |
5596 | { | |
5597 | char *demangled; | |
5598 | ||
5599 | mangled = DW_STRING (attr); | |
5600 | ||
5601 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return | |
5602 | type. It is easier for GDB users to search for such functions as | |
5603 | `name(params)' than `long name(params)'. In such case the minimal | |
5604 | symbol names do not match the full symbol names but for template | |
5605 | functions there is never a need to look up their definition from their | |
5606 | declaration so the only disadvantage remains the minimal symbol | |
5607 | variant `long name(params)' does not have the proper inferior type. | |
5608 | */ | |
5609 | ||
a766d390 DE |
5610 | if (cu->language == language_go) |
5611 | { | |
5612 | /* This is a lie, but we already lie to the caller new_symbol_full. | |
5613 | new_symbol_full assumes we return the mangled name. | |
5614 | This just undoes that lie until things are cleaned up. */ | |
5615 | demangled = NULL; | |
5616 | } | |
5617 | else | |
5618 | { | |
5619 | demangled = cplus_demangle (mangled, | |
5620 | (DMGL_PARAMS | DMGL_ANSI | |
5621 | | (cu->language == language_java | |
5622 | ? DMGL_JAVA | DMGL_RET_POSTFIX | |
5623 | : DMGL_RET_DROP))); | |
5624 | } | |
900e11f9 JK |
5625 | if (demangled) |
5626 | { | |
5627 | make_cleanup (xfree, demangled); | |
5628 | canon = demangled; | |
5629 | } | |
5630 | else | |
5631 | { | |
5632 | canon = mangled; | |
5633 | need_copy = 0; | |
5634 | } | |
5635 | } | |
5636 | ||
5637 | if (canon == NULL || check_physname) | |
5638 | { | |
5639 | const char *physname = dwarf2_compute_name (name, die, cu, 1); | |
5640 | ||
5641 | if (canon != NULL && strcmp (physname, canon) != 0) | |
5642 | { | |
5643 | /* It may not mean a bug in GDB. The compiler could also | |
5644 | compute DW_AT_linkage_name incorrectly. But in such case | |
5645 | GDB would need to be bug-to-bug compatible. */ | |
5646 | ||
5647 | complaint (&symfile_complaints, | |
5648 | _("Computed physname <%s> does not match demangled <%s> " | |
5649 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 5650 | physname, canon, mangled, die->offset.sect_off, objfile->name); |
900e11f9 JK |
5651 | |
5652 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it | |
5653 | is available here - over computed PHYSNAME. It is safer | |
5654 | against both buggy GDB and buggy compilers. */ | |
5655 | ||
5656 | retval = canon; | |
5657 | } | |
5658 | else | |
5659 | { | |
5660 | retval = physname; | |
5661 | need_copy = 0; | |
5662 | } | |
5663 | } | |
5664 | else | |
5665 | retval = canon; | |
5666 | ||
5667 | if (need_copy) | |
5668 | retval = obsavestring (retval, strlen (retval), | |
bb5ed363 | 5669 | &objfile->objfile_obstack); |
900e11f9 JK |
5670 | |
5671 | do_cleanups (back_to); | |
5672 | return retval; | |
0114d602 DJ |
5673 | } |
5674 | ||
27aa8d6a SW |
5675 | /* Read the import statement specified by the given die and record it. */ |
5676 | ||
5677 | static void | |
5678 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5679 | { | |
bb5ed363 | 5680 | struct objfile *objfile = cu->objfile; |
27aa8d6a | 5681 | struct attribute *import_attr; |
32019081 | 5682 | struct die_info *imported_die, *child_die; |
de4affc9 | 5683 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5684 | const char *imported_name; |
794684b6 | 5685 | const char *imported_name_prefix; |
13387711 SW |
5686 | const char *canonical_name; |
5687 | const char *import_alias; | |
5688 | const char *imported_declaration = NULL; | |
794684b6 | 5689 | const char *import_prefix; |
32019081 JK |
5690 | VEC (const_char_ptr) *excludes = NULL; |
5691 | struct cleanup *cleanups; | |
13387711 SW |
5692 | |
5693 | char *temp; | |
27aa8d6a SW |
5694 | |
5695 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5696 | if (import_attr == NULL) | |
5697 | { | |
5698 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5699 | dwarf_tag_name (die->tag)); | |
5700 | return; | |
5701 | } | |
5702 | ||
de4affc9 CC |
5703 | imported_cu = cu; |
5704 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5705 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5706 | if (imported_name == NULL) |
5707 | { | |
5708 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5709 | ||
5710 | The import in the following code: | |
5711 | namespace A | |
5712 | { | |
5713 | typedef int B; | |
5714 | } | |
5715 | ||
5716 | int main () | |
5717 | { | |
5718 | using A::B; | |
5719 | B b; | |
5720 | return b; | |
5721 | } | |
5722 | ||
5723 | ... | |
5724 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5725 | <52> DW_AT_decl_file : 1 | |
5726 | <53> DW_AT_decl_line : 6 | |
5727 | <54> DW_AT_import : <0x75> | |
5728 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5729 | <59> DW_AT_name : B | |
5730 | <5b> DW_AT_decl_file : 1 | |
5731 | <5c> DW_AT_decl_line : 2 | |
5732 | <5d> DW_AT_type : <0x6e> | |
5733 | ... | |
5734 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5735 | <76> DW_AT_byte_size : 4 | |
5736 | <77> DW_AT_encoding : 5 (signed) | |
5737 | ||
5738 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5739 | This case will be ignored until the gcc bug is fixed. */ | |
5740 | return; | |
5741 | } | |
5742 | ||
82856980 SW |
5743 | /* Figure out the local name after import. */ |
5744 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5745 | |
794684b6 SW |
5746 | /* Figure out where the statement is being imported to. */ |
5747 | import_prefix = determine_prefix (die, cu); | |
5748 | ||
5749 | /* Figure out what the scope of the imported die is and prepend it | |
5750 | to the name of the imported die. */ | |
de4affc9 | 5751 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5752 | |
f55ee35c JK |
5753 | if (imported_die->tag != DW_TAG_namespace |
5754 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5755 | { |
13387711 SW |
5756 | imported_declaration = imported_name; |
5757 | canonical_name = imported_name_prefix; | |
794684b6 | 5758 | } |
13387711 | 5759 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5760 | { |
13387711 SW |
5761 | temp = alloca (strlen (imported_name_prefix) |
5762 | + 2 + strlen (imported_name) + 1); | |
5763 | strcpy (temp, imported_name_prefix); | |
5764 | strcat (temp, "::"); | |
5765 | strcat (temp, imported_name); | |
5766 | canonical_name = temp; | |
794684b6 | 5767 | } |
13387711 SW |
5768 | else |
5769 | canonical_name = imported_name; | |
794684b6 | 5770 | |
32019081 JK |
5771 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
5772 | ||
5773 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) | |
5774 | for (child_die = die->child; child_die && child_die->tag; | |
5775 | child_die = sibling_die (child_die)) | |
5776 | { | |
5777 | /* DWARF-4: A Fortran use statement with a “rename list” may be | |
5778 | represented by an imported module entry with an import attribute | |
5779 | referring to the module and owned entries corresponding to those | |
5780 | entities that are renamed as part of being imported. */ | |
5781 | ||
5782 | if (child_die->tag != DW_TAG_imported_declaration) | |
5783 | { | |
5784 | complaint (&symfile_complaints, | |
5785 | _("child DW_TAG_imported_declaration expected " | |
5786 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 5787 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
5788 | continue; |
5789 | } | |
5790 | ||
5791 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); | |
5792 | if (import_attr == NULL) | |
5793 | { | |
5794 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5795 | dwarf_tag_name (child_die->tag)); | |
5796 | continue; | |
5797 | } | |
5798 | ||
5799 | imported_cu = cu; | |
5800 | imported_die = follow_die_ref_or_sig (child_die, import_attr, | |
5801 | &imported_cu); | |
5802 | imported_name = dwarf2_name (imported_die, imported_cu); | |
5803 | if (imported_name == NULL) | |
5804 | { | |
5805 | complaint (&symfile_complaints, | |
5806 | _("child DW_TAG_imported_declaration has unknown " | |
5807 | "imported name - DIE at 0x%x [in module %s]"), | |
b64f50a1 | 5808 | child_die->offset.sect_off, objfile->name); |
32019081 JK |
5809 | continue; |
5810 | } | |
5811 | ||
5812 | VEC_safe_push (const_char_ptr, excludes, imported_name); | |
5813 | ||
5814 | process_die (child_die, cu); | |
5815 | } | |
5816 | ||
c0cc3a76 SW |
5817 | cp_add_using_directive (import_prefix, |
5818 | canonical_name, | |
5819 | import_alias, | |
13387711 | 5820 | imported_declaration, |
32019081 | 5821 | excludes, |
bb5ed363 | 5822 | &objfile->objfile_obstack); |
32019081 JK |
5823 | |
5824 | do_cleanups (cleanups); | |
27aa8d6a SW |
5825 | } |
5826 | ||
ae2de4f8 DE |
5827 | /* Cleanup function for read_file_scope. */ |
5828 | ||
cb1df416 DJ |
5829 | static void |
5830 | free_cu_line_header (void *arg) | |
5831 | { | |
5832 | struct dwarf2_cu *cu = arg; | |
5833 | ||
5834 | free_line_header (cu->line_header); | |
5835 | cu->line_header = NULL; | |
5836 | } | |
5837 | ||
9291a0cd TT |
5838 | static void |
5839 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5840 | char **name, char **comp_dir) | |
5841 | { | |
5842 | struct attribute *attr; | |
5843 | ||
5844 | *name = NULL; | |
5845 | *comp_dir = NULL; | |
5846 | ||
5847 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5848 | is not a source language identifier. */ | |
5849 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5850 | if (attr) | |
5851 | { | |
5852 | *name = DW_STRING (attr); | |
5853 | } | |
5854 | ||
5855 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5856 | if (attr) | |
5857 | *comp_dir = DW_STRING (attr); | |
5858 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5859 | { | |
5860 | *comp_dir = ldirname (*name); | |
5861 | if (*comp_dir != NULL) | |
5862 | make_cleanup (xfree, *comp_dir); | |
5863 | } | |
5864 | if (*comp_dir != NULL) | |
5865 | { | |
5866 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5867 | directory, get rid of it. */ | |
5868 | char *cp = strchr (*comp_dir, ':'); | |
5869 | ||
5870 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5871 | *comp_dir = cp + 1; | |
5872 | } | |
5873 | ||
5874 | if (*name == NULL) | |
5875 | *name = "<unknown>"; | |
5876 | } | |
5877 | ||
f3f5162e DE |
5878 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
5879 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. | |
5880 | COMP_DIR is the compilation directory. | |
5881 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ | |
2ab95328 TT |
5882 | |
5883 | static void | |
5884 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, | |
f3f5162e | 5885 | const char *comp_dir, int want_line_info) |
2ab95328 TT |
5886 | { |
5887 | struct attribute *attr; | |
5888 | struct objfile *objfile = cu->objfile; | |
5889 | bfd *abfd = objfile->obfd; | |
5890 | ||
2ab95328 TT |
5891 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5892 | if (attr) | |
5893 | { | |
5894 | unsigned int line_offset = DW_UNSND (attr); | |
5895 | struct line_header *line_header | |
5896 | = dwarf_decode_line_header (line_offset, abfd, cu); | |
5897 | ||
5898 | if (line_header) | |
dee91e82 DE |
5899 | { |
5900 | cu->line_header = line_header; | |
5901 | make_cleanup (free_cu_line_header, cu); | |
f3f5162e | 5902 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
dee91e82 | 5903 | } |
2ab95328 TT |
5904 | } |
5905 | } | |
5906 | ||
ae2de4f8 DE |
5907 | /* Process DW_TAG_compile_unit. */ |
5908 | ||
c906108c | 5909 | static void |
e7c27a73 | 5910 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5911 | { |
dee91e82 | 5912 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
debd256d | 5913 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5914 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5915 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5916 | struct attribute *attr; | |
e1024ff1 | 5917 | char *name = NULL; |
c906108c SS |
5918 | char *comp_dir = NULL; |
5919 | struct die_info *child_die; | |
5920 | bfd *abfd = objfile->obfd; | |
e142c38c | 5921 | CORE_ADDR baseaddr; |
6e70227d | 5922 | |
e142c38c | 5923 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5924 | |
fae299cd | 5925 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5926 | |
5927 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5928 | from finish_block. */ | |
2acceee2 | 5929 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5930 | lowpc = highpc; |
5931 | lowpc += baseaddr; | |
5932 | highpc += baseaddr; | |
5933 | ||
9291a0cd | 5934 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5935 | |
dee91e82 | 5936 | prepare_one_comp_unit (cu, die); |
303b6f5d | 5937 | |
f4b8a18d KW |
5938 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5939 | standardised yet. As a workaround for the language detection we fall | |
5940 | back to the DW_AT_producer string. */ | |
5941 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5942 | cu->language = language_opencl; | |
5943 | ||
a766d390 DE |
5944 | /* Similar hack for Go. */ |
5945 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) | |
5946 | set_cu_language (DW_LANG_Go, cu); | |
5947 | ||
0963b4bd | 5948 | /* We assume that we're processing GCC output. */ |
c906108c | 5949 | processing_gcc_compilation = 2; |
c906108c | 5950 | |
df8a16a1 DJ |
5951 | processing_has_namespace_info = 0; |
5952 | ||
c906108c SS |
5953 | start_symtab (name, comp_dir, lowpc); |
5954 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5955 | record_producer (cu->producer); |
c906108c | 5956 | |
f3f5162e DE |
5957 | /* Decode line number information if present. We do this before |
5958 | processing child DIEs, so that the line header table is available | |
5959 | for DW_AT_decl_file. */ | |
5960 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); | |
debd256d | 5961 | |
cb1df416 DJ |
5962 | /* Process all dies in compilation unit. */ |
5963 | if (die->child != NULL) | |
5964 | { | |
5965 | child_die = die->child; | |
5966 | while (child_die && child_die->tag) | |
5967 | { | |
5968 | process_die (child_die, cu); | |
5969 | child_die = sibling_die (child_die); | |
5970 | } | |
5971 | } | |
5972 | ||
2e276125 JB |
5973 | /* Decode macro information, if present. Dwarf 2 macro information |
5974 | refers to information in the line number info statement program | |
5975 | header, so we can only read it if we've read the header | |
5976 | successfully. */ | |
cf2c3c16 | 5977 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
2ab95328 | 5978 | if (attr && cu->line_header) |
2e276125 | 5979 | { |
cf2c3c16 TT |
5980 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
5981 | complaint (&symfile_complaints, | |
5982 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); | |
5983 | ||
5984 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), | |
5985 | comp_dir, abfd, cu, | |
5986 | &dwarf2_per_objfile->macro, 1); | |
5987 | } | |
5988 | else | |
5989 | { | |
5990 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |
5991 | if (attr && cu->line_header) | |
5992 | { | |
5993 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5994 | |
cf2c3c16 TT |
5995 | dwarf_decode_macros (cu->line_header, macro_offset, |
5996 | comp_dir, abfd, cu, | |
5997 | &dwarf2_per_objfile->macinfo, 0); | |
5998 | } | |
2e276125 | 5999 | } |
9cdd5dbd | 6000 | |
debd256d | 6001 | do_cleanups (back_to); |
5fb290d7 DJ |
6002 | } |
6003 | ||
ae2de4f8 DE |
6004 | /* Process DW_TAG_type_unit. |
6005 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
6006 | actual type being defined by this TU. In this case the first top |
6007 | level sibling is there to provide context only. */ | |
6008 | ||
6009 | static void | |
6010 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6011 | { | |
6012 | struct objfile *objfile = cu->objfile; | |
6013 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
6014 | CORE_ADDR lowpc; | |
6015 | struct attribute *attr; | |
6016 | char *name = NULL; | |
6017 | char *comp_dir = NULL; | |
6018 | struct die_info *child_die; | |
6019 | bfd *abfd = objfile->obfd; | |
348e048f DE |
6020 | |
6021 | /* start_symtab needs a low pc, but we don't really have one. | |
6022 | Do what read_file_scope would do in the absence of such info. */ | |
6023 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6024 | ||
6025 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
6026 | is not a source language identifier. */ | |
6027 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
6028 | if (attr) | |
6029 | name = DW_STRING (attr); | |
6030 | ||
6031 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
6032 | if (attr) | |
6033 | comp_dir = DW_STRING (attr); | |
6034 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
6035 | { | |
6036 | comp_dir = ldirname (name); | |
6037 | if (comp_dir != NULL) | |
6038 | make_cleanup (xfree, comp_dir); | |
6039 | } | |
6040 | ||
6041 | if (name == NULL) | |
6042 | name = "<unknown>"; | |
6043 | ||
dee91e82 | 6044 | prepare_one_comp_unit (cu, die); |
348e048f | 6045 | |
0963b4bd | 6046 | /* We assume that we're processing GCC output. */ |
348e048f DE |
6047 | processing_gcc_compilation = 2; |
6048 | ||
6049 | processing_has_namespace_info = 0; | |
6050 | ||
6051 | start_symtab (name, comp_dir, lowpc); | |
6052 | record_debugformat ("DWARF 2"); | |
6053 | record_producer (cu->producer); | |
6054 | ||
f3f5162e DE |
6055 | /* Decode line number information if present. We do this before |
6056 | processing child DIEs, so that the line header table is available | |
6057 | for DW_AT_decl_file. | |
6058 | We don't need the pc/line-number mapping for type units. */ | |
6059 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); | |
2ab95328 | 6060 | |
348e048f DE |
6061 | /* Process the dies in the type unit. */ |
6062 | if (die->child == NULL) | |
6063 | { | |
6064 | dump_die_for_error (die); | |
6065 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
6066 | bfd_get_filename (abfd)); | |
6067 | } | |
6068 | ||
6069 | child_die = die->child; | |
6070 | ||
6071 | while (child_die && child_die->tag) | |
6072 | { | |
6073 | process_die (child_die, cu); | |
6074 | ||
6075 | child_die = sibling_die (child_die); | |
6076 | } | |
6077 | ||
6078 | do_cleanups (back_to); | |
6079 | } | |
6080 | ||
d389af10 JK |
6081 | /* qsort helper for inherit_abstract_dies. */ |
6082 | ||
6083 | static int | |
6084 | unsigned_int_compar (const void *ap, const void *bp) | |
6085 | { | |
6086 | unsigned int a = *(unsigned int *) ap; | |
6087 | unsigned int b = *(unsigned int *) bp; | |
6088 | ||
6089 | return (a > b) - (b > a); | |
6090 | } | |
6091 | ||
6092 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
6093 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
6094 | already referenced by DW_AT_abstract_origin from the children of the | |
6095 | current DIE. */ | |
d389af10 JK |
6096 | |
6097 | static void | |
6098 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
6099 | { | |
6100 | struct die_info *child_die; | |
6101 | unsigned die_children_count; | |
6102 | /* CU offsets which were referenced by children of the current DIE. */ | |
b64f50a1 JK |
6103 | sect_offset *offsets; |
6104 | sect_offset *offsets_end, *offsetp; | |
d389af10 JK |
6105 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
6106 | struct die_info *origin_die; | |
6107 | /* Iterator of the ORIGIN_DIE children. */ | |
6108 | struct die_info *origin_child_die; | |
6109 | struct cleanup *cleanups; | |
6110 | struct attribute *attr; | |
cd02d79d PA |
6111 | struct dwarf2_cu *origin_cu; |
6112 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
6113 | |
6114 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6115 | if (!attr) | |
6116 | return; | |
6117 | ||
cd02d79d PA |
6118 | /* Note that following die references may follow to a die in a |
6119 | different cu. */ | |
6120 | ||
6121 | origin_cu = cu; | |
6122 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
6123 | ||
6124 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
6125 | symbols in. */ | |
6126 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
6127 | origin_cu->list_in_scope = cu->list_in_scope; | |
6128 | ||
edb3359d DJ |
6129 | if (die->tag != origin_die->tag |
6130 | && !(die->tag == DW_TAG_inlined_subroutine | |
6131 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
6132 | complaint (&symfile_complaints, |
6133 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
b64f50a1 | 6134 | die->offset.sect_off, origin_die->offset.sect_off); |
d389af10 JK |
6135 | |
6136 | child_die = die->child; | |
6137 | die_children_count = 0; | |
6138 | while (child_die && child_die->tag) | |
6139 | { | |
6140 | child_die = sibling_die (child_die); | |
6141 | die_children_count++; | |
6142 | } | |
6143 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
6144 | cleanups = make_cleanup (xfree, offsets); | |
6145 | ||
6146 | offsets_end = offsets; | |
6147 | child_die = die->child; | |
6148 | while (child_die && child_die->tag) | |
6149 | { | |
c38f313d DJ |
6150 | /* For each CHILD_DIE, find the corresponding child of |
6151 | ORIGIN_DIE. If there is more than one layer of | |
6152 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
6153 | but GCC versions at least through 4.4 generate this (GCC PR | |
6154 | 40573). */ | |
6155 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 6156 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 6157 | |
c38f313d DJ |
6158 | while (1) |
6159 | { | |
cd02d79d PA |
6160 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
6161 | child_origin_cu); | |
c38f313d DJ |
6162 | if (attr == NULL) |
6163 | break; | |
cd02d79d PA |
6164 | child_origin_die = follow_die_ref (child_origin_die, attr, |
6165 | &child_origin_cu); | |
c38f313d DJ |
6166 | } |
6167 | ||
d389af10 JK |
6168 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
6169 | counterpart may exist. */ | |
c38f313d | 6170 | if (child_origin_die != child_die) |
d389af10 | 6171 | { |
edb3359d DJ |
6172 | if (child_die->tag != child_origin_die->tag |
6173 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
6174 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
6175 | complaint (&symfile_complaints, |
6176 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
6177 | "different tags"), child_die->offset.sect_off, |
6178 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
6179 | if (child_origin_die->parent != origin_die) |
6180 | complaint (&symfile_complaints, | |
6181 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
b64f50a1 JK |
6182 | "different parents"), child_die->offset.sect_off, |
6183 | child_origin_die->offset.sect_off); | |
c38f313d DJ |
6184 | else |
6185 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
6186 | } |
6187 | child_die = sibling_die (child_die); | |
6188 | } | |
6189 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
6190 | unsigned_int_compar); | |
6191 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
b64f50a1 | 6192 | if (offsetp[-1].sect_off == offsetp->sect_off) |
3e43a32a MS |
6193 | complaint (&symfile_complaints, |
6194 | _("Multiple children of DIE 0x%x refer " | |
6195 | "to DIE 0x%x as their abstract origin"), | |
b64f50a1 | 6196 | die->offset.sect_off, offsetp->sect_off); |
d389af10 JK |
6197 | |
6198 | offsetp = offsets; | |
6199 | origin_child_die = origin_die->child; | |
6200 | while (origin_child_die && origin_child_die->tag) | |
6201 | { | |
6202 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
b64f50a1 JK |
6203 | while (offsetp < offsets_end |
6204 | && offsetp->sect_off < origin_child_die->offset.sect_off) | |
d389af10 | 6205 | offsetp++; |
b64f50a1 JK |
6206 | if (offsetp >= offsets_end |
6207 | || offsetp->sect_off > origin_child_die->offset.sect_off) | |
d389af10 JK |
6208 | { |
6209 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 6210 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
6211 | } |
6212 | origin_child_die = sibling_die (origin_child_die); | |
6213 | } | |
cd02d79d | 6214 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
6215 | |
6216 | do_cleanups (cleanups); | |
6217 | } | |
6218 | ||
c906108c | 6219 | static void |
e7c27a73 | 6220 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6221 | { |
e7c27a73 | 6222 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6223 | struct context_stack *new; |
c906108c SS |
6224 | CORE_ADDR lowpc; |
6225 | CORE_ADDR highpc; | |
6226 | struct die_info *child_die; | |
edb3359d | 6227 | struct attribute *attr, *call_line, *call_file; |
c906108c | 6228 | char *name; |
e142c38c | 6229 | CORE_ADDR baseaddr; |
801e3a5b | 6230 | struct block *block; |
edb3359d | 6231 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
6232 | VEC (symbolp) *template_args = NULL; |
6233 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
6234 | |
6235 | if (inlined_func) | |
6236 | { | |
6237 | /* If we do not have call site information, we can't show the | |
6238 | caller of this inlined function. That's too confusing, so | |
6239 | only use the scope for local variables. */ | |
6240 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
6241 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
6242 | if (call_line == NULL || call_file == NULL) | |
6243 | { | |
6244 | read_lexical_block_scope (die, cu); | |
6245 | return; | |
6246 | } | |
6247 | } | |
c906108c | 6248 | |
e142c38c DJ |
6249 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
6250 | ||
94af9270 | 6251 | name = dwarf2_name (die, cu); |
c906108c | 6252 | |
e8d05480 JB |
6253 | /* Ignore functions with missing or empty names. These are actually |
6254 | illegal according to the DWARF standard. */ | |
6255 | if (name == NULL) | |
6256 | { | |
6257 | complaint (&symfile_complaints, | |
b64f50a1 JK |
6258 | _("missing name for subprogram DIE at %d"), |
6259 | die->offset.sect_off); | |
e8d05480 JB |
6260 | return; |
6261 | } | |
6262 | ||
6263 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
6264 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
6265 | { | |
ae4d0c03 PM |
6266 | attr = dwarf2_attr (die, DW_AT_external, cu); |
6267 | if (!attr || !DW_UNSND (attr)) | |
6268 | complaint (&symfile_complaints, | |
3e43a32a MS |
6269 | _("cannot get low and high bounds " |
6270 | "for subprogram DIE at %d"), | |
b64f50a1 | 6271 | die->offset.sect_off); |
e8d05480 JB |
6272 | return; |
6273 | } | |
c906108c SS |
6274 | |
6275 | lowpc += baseaddr; | |
6276 | highpc += baseaddr; | |
6277 | ||
34eaf542 TT |
6278 | /* If we have any template arguments, then we must allocate a |
6279 | different sort of symbol. */ | |
6280 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
6281 | { | |
6282 | if (child_die->tag == DW_TAG_template_type_param | |
6283 | || child_die->tag == DW_TAG_template_value_param) | |
6284 | { | |
6285 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
6286 | struct template_symbol); | |
6287 | templ_func->base.is_cplus_template_function = 1; | |
6288 | break; | |
6289 | } | |
6290 | } | |
6291 | ||
c906108c | 6292 | new = push_context (0, lowpc); |
34eaf542 TT |
6293 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
6294 | (struct symbol *) templ_func); | |
4c2df51b | 6295 | |
4cecd739 DJ |
6296 | /* If there is a location expression for DW_AT_frame_base, record |
6297 | it. */ | |
e142c38c | 6298 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 6299 | if (attr) |
c034e007 AC |
6300 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
6301 | expression is being recorded directly in the function's symbol | |
6302 | and not in a separate frame-base object. I guess this hack is | |
6303 | to avoid adding some sort of frame-base adjunct/annex to the | |
6304 | function's symbol :-(. The problem with doing this is that it | |
6305 | results in a function symbol with a location expression that | |
6306 | has nothing to do with the location of the function, ouch! The | |
6307 | relationship should be: a function's symbol has-a frame base; a | |
6308 | frame-base has-a location expression. */ | |
e7c27a73 | 6309 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 6310 | |
e142c38c | 6311 | cu->list_in_scope = &local_symbols; |
c906108c | 6312 | |
639d11d3 | 6313 | if (die->child != NULL) |
c906108c | 6314 | { |
639d11d3 | 6315 | child_die = die->child; |
c906108c SS |
6316 | while (child_die && child_die->tag) |
6317 | { | |
34eaf542 TT |
6318 | if (child_die->tag == DW_TAG_template_type_param |
6319 | || child_die->tag == DW_TAG_template_value_param) | |
6320 | { | |
6321 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
6322 | ||
f1078f66 DJ |
6323 | if (arg != NULL) |
6324 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
6325 | } |
6326 | else | |
6327 | process_die (child_die, cu); | |
c906108c SS |
6328 | child_die = sibling_die (child_die); |
6329 | } | |
6330 | } | |
6331 | ||
d389af10 JK |
6332 | inherit_abstract_dies (die, cu); |
6333 | ||
4a811a97 UW |
6334 | /* If we have a DW_AT_specification, we might need to import using |
6335 | directives from the context of the specification DIE. See the | |
6336 | comment in determine_prefix. */ | |
6337 | if (cu->language == language_cplus | |
6338 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
6339 | { | |
6340 | struct dwarf2_cu *spec_cu = cu; | |
6341 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
6342 | ||
6343 | while (spec_die) | |
6344 | { | |
6345 | child_die = spec_die->child; | |
6346 | while (child_die && child_die->tag) | |
6347 | { | |
6348 | if (child_die->tag == DW_TAG_imported_module) | |
6349 | process_die (child_die, spec_cu); | |
6350 | child_die = sibling_die (child_die); | |
6351 | } | |
6352 | ||
6353 | /* In some cases, GCC generates specification DIEs that | |
6354 | themselves contain DW_AT_specification attributes. */ | |
6355 | spec_die = die_specification (spec_die, &spec_cu); | |
6356 | } | |
6357 | } | |
6358 | ||
c906108c SS |
6359 | new = pop_context (); |
6360 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
6361 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
6362 | lowpc, highpc, objfile); | |
6363 | ||
df8a16a1 | 6364 | /* For C++, set the block's scope. */ |
f55ee35c | 6365 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 6366 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 6367 | determine_prefix (die, cu), |
df8a16a1 DJ |
6368 | processing_has_namespace_info); |
6369 | ||
801e3a5b JB |
6370 | /* If we have address ranges, record them. */ |
6371 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 6372 | |
34eaf542 TT |
6373 | /* Attach template arguments to function. */ |
6374 | if (! VEC_empty (symbolp, template_args)) | |
6375 | { | |
6376 | gdb_assert (templ_func != NULL); | |
6377 | ||
6378 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
6379 | templ_func->template_arguments | |
6380 | = obstack_alloc (&objfile->objfile_obstack, | |
6381 | (templ_func->n_template_arguments | |
6382 | * sizeof (struct symbol *))); | |
6383 | memcpy (templ_func->template_arguments, | |
6384 | VEC_address (symbolp, template_args), | |
6385 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
6386 | VEC_free (symbolp, template_args); | |
6387 | } | |
6388 | ||
208d8187 JB |
6389 | /* In C++, we can have functions nested inside functions (e.g., when |
6390 | a function declares a class that has methods). This means that | |
6391 | when we finish processing a function scope, we may need to go | |
6392 | back to building a containing block's symbol lists. */ | |
6393 | local_symbols = new->locals; | |
6394 | param_symbols = new->params; | |
27aa8d6a | 6395 | using_directives = new->using_directives; |
208d8187 | 6396 | |
921e78cf JB |
6397 | /* If we've finished processing a top-level function, subsequent |
6398 | symbols go in the file symbol list. */ | |
6399 | if (outermost_context_p ()) | |
e142c38c | 6400 | cu->list_in_scope = &file_symbols; |
c906108c SS |
6401 | } |
6402 | ||
6403 | /* Process all the DIES contained within a lexical block scope. Start | |
6404 | a new scope, process the dies, and then close the scope. */ | |
6405 | ||
6406 | static void | |
e7c27a73 | 6407 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6408 | { |
e7c27a73 | 6409 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 6410 | struct context_stack *new; |
c906108c SS |
6411 | CORE_ADDR lowpc, highpc; |
6412 | struct die_info *child_die; | |
e142c38c DJ |
6413 | CORE_ADDR baseaddr; |
6414 | ||
6415 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
6416 | |
6417 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
6418 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
6419 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 6420 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 6421 | describe ranges. */ |
d85a05f0 | 6422 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
6423 | return; |
6424 | lowpc += baseaddr; | |
6425 | highpc += baseaddr; | |
6426 | ||
6427 | push_context (0, lowpc); | |
639d11d3 | 6428 | if (die->child != NULL) |
c906108c | 6429 | { |
639d11d3 | 6430 | child_die = die->child; |
c906108c SS |
6431 | while (child_die && child_die->tag) |
6432 | { | |
e7c27a73 | 6433 | process_die (child_die, cu); |
c906108c SS |
6434 | child_die = sibling_die (child_die); |
6435 | } | |
6436 | } | |
6437 | new = pop_context (); | |
6438 | ||
8540c487 | 6439 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 6440 | { |
801e3a5b JB |
6441 | struct block *block |
6442 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
6443 | highpc, objfile); | |
6444 | ||
6445 | /* Note that recording ranges after traversing children, as we | |
6446 | do here, means that recording a parent's ranges entails | |
6447 | walking across all its children's ranges as they appear in | |
6448 | the address map, which is quadratic behavior. | |
6449 | ||
6450 | It would be nicer to record the parent's ranges before | |
6451 | traversing its children, simply overriding whatever you find | |
6452 | there. But since we don't even decide whether to create a | |
6453 | block until after we've traversed its children, that's hard | |
6454 | to do. */ | |
6455 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
6456 | } |
6457 | local_symbols = new->locals; | |
27aa8d6a | 6458 | using_directives = new->using_directives; |
c906108c SS |
6459 | } |
6460 | ||
96408a79 SA |
6461 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
6462 | ||
6463 | static void | |
6464 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6465 | { | |
6466 | struct objfile *objfile = cu->objfile; | |
6467 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6468 | CORE_ADDR pc, baseaddr; | |
6469 | struct attribute *attr; | |
6470 | struct call_site *call_site, call_site_local; | |
6471 | void **slot; | |
6472 | int nparams; | |
6473 | struct die_info *child_die; | |
6474 | ||
6475 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
6476 | ||
6477 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
6478 | if (!attr) | |
6479 | { | |
6480 | complaint (&symfile_complaints, | |
6481 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " | |
6482 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 6483 | die->offset.sect_off, objfile->name); |
96408a79 SA |
6484 | return; |
6485 | } | |
6486 | pc = DW_ADDR (attr) + baseaddr; | |
6487 | ||
6488 | if (cu->call_site_htab == NULL) | |
6489 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, | |
6490 | NULL, &objfile->objfile_obstack, | |
6491 | hashtab_obstack_allocate, NULL); | |
6492 | call_site_local.pc = pc; | |
6493 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); | |
6494 | if (*slot != NULL) | |
6495 | { | |
6496 | complaint (&symfile_complaints, | |
6497 | _("Duplicate PC %s for DW_TAG_GNU_call_site " | |
6498 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 6499 | paddress (gdbarch, pc), die->offset.sect_off, objfile->name); |
96408a79 SA |
6500 | return; |
6501 | } | |
6502 | ||
6503 | /* Count parameters at the caller. */ | |
6504 | ||
6505 | nparams = 0; | |
6506 | for (child_die = die->child; child_die && child_die->tag; | |
6507 | child_die = sibling_die (child_die)) | |
6508 | { | |
6509 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6510 | { | |
6511 | complaint (&symfile_complaints, | |
6512 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " | |
6513 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 6514 | child_die->tag, child_die->offset.sect_off, objfile->name); |
96408a79 SA |
6515 | continue; |
6516 | } | |
6517 | ||
6518 | nparams++; | |
6519 | } | |
6520 | ||
6521 | call_site = obstack_alloc (&objfile->objfile_obstack, | |
6522 | (sizeof (*call_site) | |
6523 | + (sizeof (*call_site->parameter) | |
6524 | * (nparams - 1)))); | |
6525 | *slot = call_site; | |
6526 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); | |
6527 | call_site->pc = pc; | |
6528 | ||
6529 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) | |
6530 | { | |
6531 | struct die_info *func_die; | |
6532 | ||
6533 | /* Skip also over DW_TAG_inlined_subroutine. */ | |
6534 | for (func_die = die->parent; | |
6535 | func_die && func_die->tag != DW_TAG_subprogram | |
6536 | && func_die->tag != DW_TAG_subroutine_type; | |
6537 | func_die = func_die->parent); | |
6538 | ||
6539 | /* DW_AT_GNU_all_call_sites is a superset | |
6540 | of DW_AT_GNU_all_tail_call_sites. */ | |
6541 | if (func_die | |
6542 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) | |
6543 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) | |
6544 | { | |
6545 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is | |
6546 | not complete. But keep CALL_SITE for look ups via call_site_htab, | |
6547 | both the initial caller containing the real return address PC and | |
6548 | the final callee containing the current PC of a chain of tail | |
6549 | calls do not need to have the tail call list complete. But any | |
6550 | function candidate for a virtual tail call frame searched via | |
6551 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be | |
6552 | determined unambiguously. */ | |
6553 | } | |
6554 | else | |
6555 | { | |
6556 | struct type *func_type = NULL; | |
6557 | ||
6558 | if (func_die) | |
6559 | func_type = get_die_type (func_die, cu); | |
6560 | if (func_type != NULL) | |
6561 | { | |
6562 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); | |
6563 | ||
6564 | /* Enlist this call site to the function. */ | |
6565 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); | |
6566 | TYPE_TAIL_CALL_LIST (func_type) = call_site; | |
6567 | } | |
6568 | else | |
6569 | complaint (&symfile_complaints, | |
6570 | _("Cannot find function owning DW_TAG_GNU_call_site " | |
6571 | "DIE 0x%x [in module %s]"), | |
b64f50a1 | 6572 | die->offset.sect_off, objfile->name); |
96408a79 SA |
6573 | } |
6574 | } | |
6575 | ||
6576 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); | |
6577 | if (attr == NULL) | |
6578 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
6579 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); | |
6580 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) | |
6581 | /* Keep NULL DWARF_BLOCK. */; | |
6582 | else if (attr_form_is_block (attr)) | |
6583 | { | |
6584 | struct dwarf2_locexpr_baton *dlbaton; | |
6585 | ||
6586 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); | |
6587 | dlbaton->data = DW_BLOCK (attr)->data; | |
6588 | dlbaton->size = DW_BLOCK (attr)->size; | |
6589 | dlbaton->per_cu = cu->per_cu; | |
6590 | ||
6591 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); | |
6592 | } | |
6593 | else if (is_ref_attr (attr)) | |
6594 | { | |
96408a79 SA |
6595 | struct dwarf2_cu *target_cu = cu; |
6596 | struct die_info *target_die; | |
6597 | ||
6598 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); | |
6599 | gdb_assert (target_cu->objfile == objfile); | |
6600 | if (die_is_declaration (target_die, target_cu)) | |
6601 | { | |
6602 | const char *target_physname; | |
6603 | ||
6604 | target_physname = dwarf2_physname (NULL, target_die, target_cu); | |
6605 | if (target_physname == NULL) | |
6606 | complaint (&symfile_complaints, | |
6607 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6608 | "physname, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 6609 | die->offset.sect_off, objfile->name); |
96408a79 SA |
6610 | else |
6611 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); | |
6612 | } | |
6613 | else | |
6614 | { | |
6615 | CORE_ADDR lowpc; | |
6616 | ||
6617 | /* DW_AT_entry_pc should be preferred. */ | |
6618 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) | |
6619 | complaint (&symfile_complaints, | |
6620 | _("DW_AT_GNU_call_site_target target DIE has invalid " | |
6621 | "low pc, for referencing DIE 0x%x [in module %s]"), | |
b64f50a1 | 6622 | die->offset.sect_off, objfile->name); |
96408a79 SA |
6623 | else |
6624 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); | |
6625 | } | |
6626 | } | |
6627 | else | |
6628 | complaint (&symfile_complaints, | |
6629 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " | |
6630 | "block nor reference, for DIE 0x%x [in module %s]"), | |
b64f50a1 | 6631 | die->offset.sect_off, objfile->name); |
96408a79 SA |
6632 | |
6633 | call_site->per_cu = cu->per_cu; | |
6634 | ||
6635 | for (child_die = die->child; | |
6636 | child_die && child_die->tag; | |
6637 | child_die = sibling_die (child_die)) | |
6638 | { | |
6639 | struct dwarf2_locexpr_baton *dlbaton; | |
6640 | struct call_site_parameter *parameter; | |
6641 | ||
6642 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) | |
6643 | { | |
6644 | /* Already printed the complaint above. */ | |
6645 | continue; | |
6646 | } | |
6647 | ||
6648 | gdb_assert (call_site->parameter_count < nparams); | |
6649 | parameter = &call_site->parameter[call_site->parameter_count]; | |
6650 | ||
6651 | /* DW_AT_location specifies the register number. Value of the data | |
6652 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ | |
6653 | ||
6654 | attr = dwarf2_attr (child_die, DW_AT_location, cu); | |
6655 | if (!attr || !attr_form_is_block (attr)) | |
6656 | { | |
6657 | complaint (&symfile_complaints, | |
6658 | _("No DW_FORM_block* DW_AT_location for " | |
6659 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 6660 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
6661 | continue; |
6662 | } | |
6663 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, | |
6664 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); | |
6665 | if (parameter->dwarf_reg == -1 | |
6666 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, | |
6667 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], | |
6668 | ¶meter->fb_offset)) | |
6669 | { | |
6670 | complaint (&symfile_complaints, | |
6671 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " | |
6672 | "for DW_FORM_block* DW_AT_location for " | |
6673 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 6674 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
6675 | continue; |
6676 | } | |
6677 | ||
6678 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); | |
6679 | if (!attr_form_is_block (attr)) | |
6680 | { | |
6681 | complaint (&symfile_complaints, | |
6682 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " | |
6683 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 6684 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
6685 | continue; |
6686 | } | |
6687 | parameter->value = DW_BLOCK (attr)->data; | |
6688 | parameter->value_size = DW_BLOCK (attr)->size; | |
6689 | ||
6690 | /* Parameters are not pre-cleared by memset above. */ | |
6691 | parameter->data_value = NULL; | |
6692 | parameter->data_value_size = 0; | |
6693 | call_site->parameter_count++; | |
6694 | ||
6695 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); | |
6696 | if (attr) | |
6697 | { | |
6698 | if (!attr_form_is_block (attr)) | |
6699 | complaint (&symfile_complaints, | |
6700 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " | |
6701 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), | |
b64f50a1 | 6702 | child_die->offset.sect_off, objfile->name); |
96408a79 SA |
6703 | else |
6704 | { | |
6705 | parameter->data_value = DW_BLOCK (attr)->data; | |
6706 | parameter->data_value_size = DW_BLOCK (attr)->size; | |
6707 | } | |
6708 | } | |
6709 | } | |
6710 | } | |
6711 | ||
43039443 | 6712 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
6713 | Return 1 if the attributes are present and valid, otherwise, return 0. |
6714 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
6715 | |
6716 | static int | |
6717 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
6718 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
6719 | struct partial_symtab *ranges_pst) | |
43039443 JK |
6720 | { |
6721 | struct objfile *objfile = cu->objfile; | |
6722 | struct comp_unit_head *cu_header = &cu->header; | |
6723 | bfd *obfd = objfile->obfd; | |
6724 | unsigned int addr_size = cu_header->addr_size; | |
6725 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6726 | /* Base address selection entry. */ | |
6727 | CORE_ADDR base; | |
6728 | int found_base; | |
6729 | unsigned int dummy; | |
6730 | gdb_byte *buffer; | |
6731 | CORE_ADDR marker; | |
6732 | int low_set; | |
6733 | CORE_ADDR low = 0; | |
6734 | CORE_ADDR high = 0; | |
ff013f42 | 6735 | CORE_ADDR baseaddr; |
43039443 | 6736 | |
d00adf39 DE |
6737 | found_base = cu->base_known; |
6738 | base = cu->base_address; | |
43039443 | 6739 | |
be391dca | 6740 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 6741 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
6742 | { |
6743 | complaint (&symfile_complaints, | |
6744 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
6745 | offset); | |
6746 | return 0; | |
6747 | } | |
dce234bc | 6748 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
6749 | |
6750 | /* Read in the largest possible address. */ | |
6751 | marker = read_address (obfd, buffer, cu, &dummy); | |
6752 | if ((marker & mask) == mask) | |
6753 | { | |
6754 | /* If we found the largest possible address, then | |
6755 | read the base address. */ | |
6756 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6757 | buffer += 2 * addr_size; | |
6758 | offset += 2 * addr_size; | |
6759 | found_base = 1; | |
6760 | } | |
6761 | ||
6762 | low_set = 0; | |
6763 | ||
e7030f15 | 6764 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 6765 | |
43039443 JK |
6766 | while (1) |
6767 | { | |
6768 | CORE_ADDR range_beginning, range_end; | |
6769 | ||
6770 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
6771 | buffer += addr_size; | |
6772 | range_end = read_address (obfd, buffer, cu, &dummy); | |
6773 | buffer += addr_size; | |
6774 | offset += 2 * addr_size; | |
6775 | ||
6776 | /* An end of list marker is a pair of zero addresses. */ | |
6777 | if (range_beginning == 0 && range_end == 0) | |
6778 | /* Found the end of list entry. */ | |
6779 | break; | |
6780 | ||
6781 | /* Each base address selection entry is a pair of 2 values. | |
6782 | The first is the largest possible address, the second is | |
6783 | the base address. Check for a base address here. */ | |
6784 | if ((range_beginning & mask) == mask) | |
6785 | { | |
6786 | /* If we found the largest possible address, then | |
6787 | read the base address. */ | |
6788 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
6789 | found_base = 1; | |
6790 | continue; | |
6791 | } | |
6792 | ||
6793 | if (!found_base) | |
6794 | { | |
6795 | /* We have no valid base address for the ranges | |
6796 | data. */ | |
6797 | complaint (&symfile_complaints, | |
6798 | _("Invalid .debug_ranges data (no base address)")); | |
6799 | return 0; | |
6800 | } | |
6801 | ||
9277c30c UW |
6802 | if (range_beginning > range_end) |
6803 | { | |
6804 | /* Inverted range entries are invalid. */ | |
6805 | complaint (&symfile_complaints, | |
6806 | _("Invalid .debug_ranges data (inverted range)")); | |
6807 | return 0; | |
6808 | } | |
6809 | ||
6810 | /* Empty range entries have no effect. */ | |
6811 | if (range_beginning == range_end) | |
6812 | continue; | |
6813 | ||
43039443 JK |
6814 | range_beginning += base; |
6815 | range_end += base; | |
6816 | ||
9277c30c | 6817 | if (ranges_pst != NULL) |
ff013f42 | 6818 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
6819 | range_beginning + baseaddr, |
6820 | range_end - 1 + baseaddr, | |
ff013f42 JK |
6821 | ranges_pst); |
6822 | ||
43039443 JK |
6823 | /* FIXME: This is recording everything as a low-high |
6824 | segment of consecutive addresses. We should have a | |
6825 | data structure for discontiguous block ranges | |
6826 | instead. */ | |
6827 | if (! low_set) | |
6828 | { | |
6829 | low = range_beginning; | |
6830 | high = range_end; | |
6831 | low_set = 1; | |
6832 | } | |
6833 | else | |
6834 | { | |
6835 | if (range_beginning < low) | |
6836 | low = range_beginning; | |
6837 | if (range_end > high) | |
6838 | high = range_end; | |
6839 | } | |
6840 | } | |
6841 | ||
6842 | if (! low_set) | |
6843 | /* If the first entry is an end-of-list marker, the range | |
6844 | describes an empty scope, i.e. no instructions. */ | |
6845 | return 0; | |
6846 | ||
6847 | if (low_return) | |
6848 | *low_return = low; | |
6849 | if (high_return) | |
6850 | *high_return = high; | |
6851 | return 1; | |
6852 | } | |
6853 | ||
af34e669 DJ |
6854 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
6855 | are present and valid, otherwise, return 0. Return -1 if the range is | |
6856 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
380bca97 | 6857 | |
c906108c | 6858 | static int |
af34e669 | 6859 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
6860 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
6861 | struct partial_symtab *pst) | |
c906108c SS |
6862 | { |
6863 | struct attribute *attr; | |
91da1414 | 6864 | struct attribute *attr_high; |
af34e669 DJ |
6865 | CORE_ADDR low = 0; |
6866 | CORE_ADDR high = 0; | |
6867 | int ret = 0; | |
c906108c | 6868 | |
91da1414 MW |
6869 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
6870 | if (attr_high) | |
af34e669 | 6871 | { |
e142c38c | 6872 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 | 6873 | if (attr) |
91da1414 MW |
6874 | { |
6875 | low = DW_ADDR (attr); | |
6876 | if (attr_high->form == DW_FORM_addr) | |
6877 | high = DW_ADDR (attr_high); | |
6878 | else | |
6879 | high = low + DW_UNSND (attr_high); | |
6880 | } | |
af34e669 DJ |
6881 | else |
6882 | /* Found high w/o low attribute. */ | |
6883 | return 0; | |
6884 | ||
6885 | /* Found consecutive range of addresses. */ | |
6886 | ret = 1; | |
6887 | } | |
c906108c | 6888 | else |
af34e669 | 6889 | { |
e142c38c | 6890 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6891 | if (attr != NULL) |
6892 | { | |
af34e669 | 6893 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6894 | .debug_ranges section. */ |
d85a05f0 | 6895 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6896 | return 0; |
43039443 | 6897 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6898 | ret = -1; |
6899 | } | |
6900 | } | |
c906108c | 6901 | |
9373cf26 JK |
6902 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6903 | if (high <= low) | |
c906108c SS |
6904 | return 0; |
6905 | ||
6906 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6907 | eliminate duplicate copies of functions and vtables and such. | |
6908 | The linker will arbitrarily choose one and discard the others. | |
6909 | The AT_*_pc values for such functions refer to local labels in | |
6910 | these sections. If the section from that file was discarded, the | |
6911 | labels are not in the output, so the relocs get a value of 0. | |
6912 | If this is a discarded function, mark the pc bounds as invalid, | |
6913 | so that GDB will ignore it. */ | |
72dca2f5 | 6914 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6915 | return 0; |
6916 | ||
6917 | *lowpc = low; | |
96408a79 SA |
6918 | if (highpc) |
6919 | *highpc = high; | |
af34e669 | 6920 | return ret; |
c906108c SS |
6921 | } |
6922 | ||
b084d499 JB |
6923 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6924 | its low and high PC addresses. Do nothing if these addresses could not | |
6925 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6926 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6927 | ||
6928 | static void | |
6929 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6930 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6931 | struct dwarf2_cu *cu) | |
6932 | { | |
6933 | CORE_ADDR low, high; | |
6934 | struct die_info *child = die->child; | |
6935 | ||
d85a05f0 | 6936 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6937 | { |
6938 | *lowpc = min (*lowpc, low); | |
6939 | *highpc = max (*highpc, high); | |
6940 | } | |
6941 | ||
6942 | /* If the language does not allow nested subprograms (either inside | |
6943 | subprograms or lexical blocks), we're done. */ | |
6944 | if (cu->language != language_ada) | |
6945 | return; | |
6e70227d | 6946 | |
b084d499 JB |
6947 | /* Check all the children of the given DIE. If it contains nested |
6948 | subprograms, then check their pc bounds. Likewise, we need to | |
6949 | check lexical blocks as well, as they may also contain subprogram | |
6950 | definitions. */ | |
6951 | while (child && child->tag) | |
6952 | { | |
6953 | if (child->tag == DW_TAG_subprogram | |
6954 | || child->tag == DW_TAG_lexical_block) | |
6955 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6956 | child = sibling_die (child); | |
6957 | } | |
6958 | } | |
6959 | ||
fae299cd DC |
6960 | /* Get the low and high pc's represented by the scope DIE, and store |
6961 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6962 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6963 | ||
6964 | static void | |
6965 | get_scope_pc_bounds (struct die_info *die, | |
6966 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6967 | struct dwarf2_cu *cu) | |
6968 | { | |
6969 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6970 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6971 | CORE_ADDR current_low, current_high; | |
6972 | ||
d85a05f0 | 6973 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6974 | { |
6975 | best_low = current_low; | |
6976 | best_high = current_high; | |
6977 | } | |
6978 | else | |
6979 | { | |
6980 | struct die_info *child = die->child; | |
6981 | ||
6982 | while (child && child->tag) | |
6983 | { | |
6984 | switch (child->tag) { | |
6985 | case DW_TAG_subprogram: | |
b084d499 | 6986 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6987 | break; |
6988 | case DW_TAG_namespace: | |
f55ee35c | 6989 | case DW_TAG_module: |
fae299cd DC |
6990 | /* FIXME: carlton/2004-01-16: Should we do this for |
6991 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6992 | that current GCC's always emit the DIEs corresponding | |
6993 | to definitions of methods of classes as children of a | |
6994 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6995 | the DIEs giving the declarations, which could be | |
6996 | anywhere). But I don't see any reason why the | |
6997 | standards says that they have to be there. */ | |
6998 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6999 | ||
7000 | if (current_low != ((CORE_ADDR) -1)) | |
7001 | { | |
7002 | best_low = min (best_low, current_low); | |
7003 | best_high = max (best_high, current_high); | |
7004 | } | |
7005 | break; | |
7006 | default: | |
0963b4bd | 7007 | /* Ignore. */ |
fae299cd DC |
7008 | break; |
7009 | } | |
7010 | ||
7011 | child = sibling_die (child); | |
7012 | } | |
7013 | } | |
7014 | ||
7015 | *lowpc = best_low; | |
7016 | *highpc = best_high; | |
7017 | } | |
7018 | ||
801e3a5b JB |
7019 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
7020 | in DIE. */ | |
380bca97 | 7021 | |
801e3a5b JB |
7022 | static void |
7023 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
7024 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
7025 | { | |
bb5ed363 | 7026 | struct objfile *objfile = cu->objfile; |
801e3a5b | 7027 | struct attribute *attr; |
91da1414 | 7028 | struct attribute *attr_high; |
801e3a5b | 7029 | |
91da1414 MW |
7030 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
7031 | if (attr_high) | |
801e3a5b | 7032 | { |
801e3a5b JB |
7033 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
7034 | if (attr) | |
7035 | { | |
7036 | CORE_ADDR low = DW_ADDR (attr); | |
91da1414 MW |
7037 | CORE_ADDR high; |
7038 | if (attr_high->form == DW_FORM_addr) | |
7039 | high = DW_ADDR (attr_high); | |
7040 | else | |
7041 | high = low + DW_UNSND (attr_high); | |
9a619af0 | 7042 | |
801e3a5b JB |
7043 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
7044 | } | |
7045 | } | |
7046 | ||
7047 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
7048 | if (attr) | |
7049 | { | |
bb5ed363 | 7050 | bfd *obfd = objfile->obfd; |
801e3a5b JB |
7051 | |
7052 | /* The value of the DW_AT_ranges attribute is the offset of the | |
7053 | address range list in the .debug_ranges section. */ | |
7054 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 7055 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
7056 | |
7057 | /* For some target architectures, but not others, the | |
7058 | read_address function sign-extends the addresses it returns. | |
7059 | To recognize base address selection entries, we need a | |
7060 | mask. */ | |
7061 | unsigned int addr_size = cu->header.addr_size; | |
7062 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
7063 | ||
7064 | /* The base address, to which the next pair is relative. Note | |
7065 | that this 'base' is a DWARF concept: most entries in a range | |
7066 | list are relative, to reduce the number of relocs against the | |
7067 | debugging information. This is separate from this function's | |
7068 | 'baseaddr' argument, which GDB uses to relocate debugging | |
7069 | information from a shared library based on the address at | |
7070 | which the library was loaded. */ | |
d00adf39 DE |
7071 | CORE_ADDR base = cu->base_address; |
7072 | int base_known = cu->base_known; | |
801e3a5b | 7073 | |
be391dca | 7074 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 7075 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
7076 | { |
7077 | complaint (&symfile_complaints, | |
7078 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
7079 | offset); | |
7080 | return; | |
7081 | } | |
7082 | ||
7083 | for (;;) | |
7084 | { | |
7085 | unsigned int bytes_read; | |
7086 | CORE_ADDR start, end; | |
7087 | ||
7088 | start = read_address (obfd, buffer, cu, &bytes_read); | |
7089 | buffer += bytes_read; | |
7090 | end = read_address (obfd, buffer, cu, &bytes_read); | |
7091 | buffer += bytes_read; | |
7092 | ||
7093 | /* Did we find the end of the range list? */ | |
7094 | if (start == 0 && end == 0) | |
7095 | break; | |
7096 | ||
7097 | /* Did we find a base address selection entry? */ | |
7098 | else if ((start & base_select_mask) == base_select_mask) | |
7099 | { | |
7100 | base = end; | |
7101 | base_known = 1; | |
7102 | } | |
7103 | ||
7104 | /* We found an ordinary address range. */ | |
7105 | else | |
7106 | { | |
7107 | if (!base_known) | |
7108 | { | |
7109 | complaint (&symfile_complaints, | |
3e43a32a MS |
7110 | _("Invalid .debug_ranges data " |
7111 | "(no base address)")); | |
801e3a5b JB |
7112 | return; |
7113 | } | |
7114 | ||
9277c30c UW |
7115 | if (start > end) |
7116 | { | |
7117 | /* Inverted range entries are invalid. */ | |
7118 | complaint (&symfile_complaints, | |
7119 | _("Invalid .debug_ranges data " | |
7120 | "(inverted range)")); | |
7121 | return; | |
7122 | } | |
7123 | ||
7124 | /* Empty range entries have no effect. */ | |
7125 | if (start == end) | |
7126 | continue; | |
7127 | ||
6e70227d DE |
7128 | record_block_range (block, |
7129 | baseaddr + base + start, | |
801e3a5b JB |
7130 | baseaddr + base + end - 1); |
7131 | } | |
7132 | } | |
7133 | } | |
7134 | } | |
7135 | ||
60d5a603 JK |
7136 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
7137 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed | |
7138 | during 4.6.0 experimental. */ | |
7139 | ||
7140 | static int | |
7141 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) | |
7142 | { | |
7143 | const char *cs; | |
7144 | int major, minor, release; | |
ba919b58 | 7145 | int result = 0; |
60d5a603 JK |
7146 | |
7147 | if (cu->producer == NULL) | |
7148 | { | |
7149 | /* For unknown compilers expect their behavior is DWARF version | |
7150 | compliant. | |
7151 | ||
7152 | GCC started to support .debug_types sections by -gdwarf-4 since | |
7153 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer | |
7154 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 | |
7155 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility | |
7156 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ | |
7157 | ||
7158 | return 0; | |
7159 | } | |
7160 | ||
ba919b58 TT |
7161 | if (cu->checked_producer) |
7162 | return cu->producer_is_gxx_lt_4_6; | |
7163 | ||
60d5a603 JK |
7164 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
7165 | ||
7166 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) | |
7167 | { | |
7168 | /* For non-GCC compilers expect their behavior is DWARF version | |
7169 | compliant. */ | |
60d5a603 | 7170 | } |
ba919b58 | 7171 | else |
60d5a603 | 7172 | { |
ba919b58 TT |
7173 | cs = &cu->producer[strlen ("GNU ")]; |
7174 | while (*cs && !isdigit (*cs)) | |
7175 | cs++; | |
7176 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) | |
7177 | { | |
7178 | /* Not recognized as GCC. */ | |
7179 | } | |
7180 | else | |
7181 | result = major < 4 || (major == 4 && minor < 6); | |
60d5a603 JK |
7182 | } |
7183 | ||
ba919b58 TT |
7184 | cu->checked_producer = 1; |
7185 | cu->producer_is_gxx_lt_4_6 = result; | |
7186 | ||
7187 | return result; | |
60d5a603 JK |
7188 | } |
7189 | ||
7190 | /* Return the default accessibility type if it is not overriden by | |
7191 | DW_AT_accessibility. */ | |
7192 | ||
7193 | static enum dwarf_access_attribute | |
7194 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) | |
7195 | { | |
7196 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) | |
7197 | { | |
7198 | /* The default DWARF 2 accessibility for members is public, the default | |
7199 | accessibility for inheritance is private. */ | |
7200 | ||
7201 | if (die->tag != DW_TAG_inheritance) | |
7202 | return DW_ACCESS_public; | |
7203 | else | |
7204 | return DW_ACCESS_private; | |
7205 | } | |
7206 | else | |
7207 | { | |
7208 | /* DWARF 3+ defines the default accessibility a different way. The same | |
7209 | rules apply now for DW_TAG_inheritance as for the members and it only | |
7210 | depends on the container kind. */ | |
7211 | ||
7212 | if (die->parent->tag == DW_TAG_class_type) | |
7213 | return DW_ACCESS_private; | |
7214 | else | |
7215 | return DW_ACCESS_public; | |
7216 | } | |
7217 | } | |
7218 | ||
74ac6d43 TT |
7219 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
7220 | offset. If the attribute was not found return 0, otherwise return | |
7221 | 1. If it was found but could not properly be handled, set *OFFSET | |
7222 | to 0. */ | |
7223 | ||
7224 | static int | |
7225 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, | |
7226 | LONGEST *offset) | |
7227 | { | |
7228 | struct attribute *attr; | |
7229 | ||
7230 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |
7231 | if (attr != NULL) | |
7232 | { | |
7233 | *offset = 0; | |
7234 | ||
7235 | /* Note that we do not check for a section offset first here. | |
7236 | This is because DW_AT_data_member_location is new in DWARF 4, | |
7237 | so if we see it, we can assume that a constant form is really | |
7238 | a constant and not a section offset. */ | |
7239 | if (attr_form_is_constant (attr)) | |
7240 | *offset = dwarf2_get_attr_constant_value (attr, 0); | |
7241 | else if (attr_form_is_section_offset (attr)) | |
7242 | dwarf2_complex_location_expr_complaint (); | |
7243 | else if (attr_form_is_block (attr)) | |
7244 | *offset = decode_locdesc (DW_BLOCK (attr), cu); | |
7245 | else | |
7246 | dwarf2_complex_location_expr_complaint (); | |
7247 | ||
7248 | return 1; | |
7249 | } | |
7250 | ||
7251 | return 0; | |
7252 | } | |
7253 | ||
c906108c SS |
7254 | /* Add an aggregate field to the field list. */ |
7255 | ||
7256 | static void | |
107d2387 | 7257 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7258 | struct dwarf2_cu *cu) |
6e70227d | 7259 | { |
e7c27a73 | 7260 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7261 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7262 | struct nextfield *new_field; |
7263 | struct attribute *attr; | |
7264 | struct field *fp; | |
7265 | char *fieldname = ""; | |
7266 | ||
7267 | /* Allocate a new field list entry and link it in. */ | |
7268 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 7269 | make_cleanup (xfree, new_field); |
c906108c | 7270 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
7271 | |
7272 | if (die->tag == DW_TAG_inheritance) | |
7273 | { | |
7274 | new_field->next = fip->baseclasses; | |
7275 | fip->baseclasses = new_field; | |
7276 | } | |
7277 | else | |
7278 | { | |
7279 | new_field->next = fip->fields; | |
7280 | fip->fields = new_field; | |
7281 | } | |
c906108c SS |
7282 | fip->nfields++; |
7283 | ||
e142c38c | 7284 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
7285 | if (attr) |
7286 | new_field->accessibility = DW_UNSND (attr); | |
60d5a603 JK |
7287 | else |
7288 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); | |
c906108c SS |
7289 | if (new_field->accessibility != DW_ACCESS_public) |
7290 | fip->non_public_fields = 1; | |
60d5a603 | 7291 | |
e142c38c | 7292 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
7293 | if (attr) |
7294 | new_field->virtuality = DW_UNSND (attr); | |
60d5a603 JK |
7295 | else |
7296 | new_field->virtuality = DW_VIRTUALITY_none; | |
c906108c SS |
7297 | |
7298 | fp = &new_field->field; | |
a9a9bd0f | 7299 | |
e142c38c | 7300 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 7301 | { |
74ac6d43 TT |
7302 | LONGEST offset; |
7303 | ||
a9a9bd0f | 7304 | /* Data member other than a C++ static data member. */ |
6e70227d | 7305 | |
c906108c | 7306 | /* Get type of field. */ |
e7c27a73 | 7307 | fp->type = die_type (die, cu); |
c906108c | 7308 | |
d6a843b5 | 7309 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 7310 | |
c906108c | 7311 | /* Get bit size of field (zero if none). */ |
e142c38c | 7312 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
7313 | if (attr) |
7314 | { | |
7315 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
7316 | } | |
7317 | else | |
7318 | { | |
7319 | FIELD_BITSIZE (*fp) = 0; | |
7320 | } | |
7321 | ||
7322 | /* Get bit offset of field. */ | |
74ac6d43 TT |
7323 | if (handle_data_member_location (die, cu, &offset)) |
7324 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
e142c38c | 7325 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
7326 | if (attr) |
7327 | { | |
5e2b427d | 7328 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
7329 | { |
7330 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
7331 | additional bit offset from the MSB of the containing |
7332 | anonymous object to the MSB of the field. We don't | |
7333 | have to do anything special since we don't need to | |
7334 | know the size of the anonymous object. */ | |
f41f5e61 | 7335 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
c906108c SS |
7336 | } |
7337 | else | |
7338 | { | |
7339 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
7340 | MSB of the anonymous object, subtract off the number of |
7341 | bits from the MSB of the field to the MSB of the | |
7342 | object, and then subtract off the number of bits of | |
7343 | the field itself. The result is the bit offset of | |
7344 | the LSB of the field. */ | |
c906108c SS |
7345 | int anonymous_size; |
7346 | int bit_offset = DW_UNSND (attr); | |
7347 | ||
e142c38c | 7348 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7349 | if (attr) |
7350 | { | |
7351 | /* The size of the anonymous object containing | |
7352 | the bit field is explicit, so use the | |
7353 | indicated size (in bytes). */ | |
7354 | anonymous_size = DW_UNSND (attr); | |
7355 | } | |
7356 | else | |
7357 | { | |
7358 | /* The size of the anonymous object containing | |
7359 | the bit field must be inferred from the type | |
7360 | attribute of the data member containing the | |
7361 | bit field. */ | |
7362 | anonymous_size = TYPE_LENGTH (fp->type); | |
7363 | } | |
f41f5e61 PA |
7364 | SET_FIELD_BITPOS (*fp, |
7365 | (FIELD_BITPOS (*fp) | |
7366 | + anonymous_size * bits_per_byte | |
7367 | - bit_offset - FIELD_BITSIZE (*fp))); | |
c906108c SS |
7368 | } |
7369 | } | |
7370 | ||
7371 | /* Get name of field. */ | |
39cbfefa DJ |
7372 | fieldname = dwarf2_name (die, cu); |
7373 | if (fieldname == NULL) | |
7374 | fieldname = ""; | |
d8151005 DJ |
7375 | |
7376 | /* The name is already allocated along with this objfile, so we don't | |
7377 | need to duplicate it for the type. */ | |
7378 | fp->name = fieldname; | |
c906108c SS |
7379 | |
7380 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 7381 | pointer or virtual base class pointer) to private. */ |
e142c38c | 7382 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 7383 | { |
d48cc9dd | 7384 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
7385 | new_field->accessibility = DW_ACCESS_private; |
7386 | fip->non_public_fields = 1; | |
7387 | } | |
7388 | } | |
a9a9bd0f | 7389 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 7390 | { |
a9a9bd0f DC |
7391 | /* C++ static member. */ |
7392 | ||
7393 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
7394 | is a declaration, but all versions of G++ as of this writing | |
7395 | (so through at least 3.2.1) incorrectly generate | |
7396 | DW_TAG_variable tags. */ | |
6e70227d | 7397 | |
ff355380 | 7398 | const char *physname; |
c906108c | 7399 | |
a9a9bd0f | 7400 | /* Get name of field. */ |
39cbfefa DJ |
7401 | fieldname = dwarf2_name (die, cu); |
7402 | if (fieldname == NULL) | |
c906108c SS |
7403 | return; |
7404 | ||
254e6b9e | 7405 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
7406 | if (attr |
7407 | /* Only create a symbol if this is an external value. | |
7408 | new_symbol checks this and puts the value in the global symbol | |
7409 | table, which we want. If it is not external, new_symbol | |
7410 | will try to put the value in cu->list_in_scope which is wrong. */ | |
7411 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
7412 | { |
7413 | /* A static const member, not much different than an enum as far as | |
7414 | we're concerned, except that we can support more types. */ | |
7415 | new_symbol (die, NULL, cu); | |
7416 | } | |
7417 | ||
2df3850c | 7418 | /* Get physical name. */ |
ff355380 | 7419 | physname = dwarf2_physname (fieldname, die, cu); |
c906108c | 7420 | |
d8151005 DJ |
7421 | /* The name is already allocated along with this objfile, so we don't |
7422 | need to duplicate it for the type. */ | |
7423 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 7424 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 7425 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
7426 | } |
7427 | else if (die->tag == DW_TAG_inheritance) | |
7428 | { | |
74ac6d43 | 7429 | LONGEST offset; |
d4b96c9a | 7430 | |
74ac6d43 TT |
7431 | /* C++ base class field. */ |
7432 | if (handle_data_member_location (die, cu, &offset)) | |
7433 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); | |
c906108c | 7434 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 7435 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
7436 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
7437 | fip->nbaseclasses++; | |
7438 | } | |
7439 | } | |
7440 | ||
98751a41 JK |
7441 | /* Add a typedef defined in the scope of the FIP's class. */ |
7442 | ||
7443 | static void | |
7444 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
7445 | struct dwarf2_cu *cu) | |
6e70227d | 7446 | { |
98751a41 | 7447 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
7448 | struct typedef_field_list *new_field; |
7449 | struct attribute *attr; | |
7450 | struct typedef_field *fp; | |
7451 | char *fieldname = ""; | |
7452 | ||
7453 | /* Allocate a new field list entry and link it in. */ | |
7454 | new_field = xzalloc (sizeof (*new_field)); | |
7455 | make_cleanup (xfree, new_field); | |
7456 | ||
7457 | gdb_assert (die->tag == DW_TAG_typedef); | |
7458 | ||
7459 | fp = &new_field->field; | |
7460 | ||
7461 | /* Get name of field. */ | |
7462 | fp->name = dwarf2_name (die, cu); | |
7463 | if (fp->name == NULL) | |
7464 | return; | |
7465 | ||
7466 | fp->type = read_type_die (die, cu); | |
7467 | ||
7468 | new_field->next = fip->typedef_field_list; | |
7469 | fip->typedef_field_list = new_field; | |
7470 | fip->typedef_field_list_count++; | |
7471 | } | |
7472 | ||
c906108c SS |
7473 | /* Create the vector of fields, and attach it to the type. */ |
7474 | ||
7475 | static void | |
fba45db2 | 7476 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7477 | struct dwarf2_cu *cu) |
c906108c SS |
7478 | { |
7479 | int nfields = fip->nfields; | |
7480 | ||
7481 | /* Record the field count, allocate space for the array of fields, | |
7482 | and create blank accessibility bitfields if necessary. */ | |
7483 | TYPE_NFIELDS (type) = nfields; | |
7484 | TYPE_FIELDS (type) = (struct field *) | |
7485 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
7486 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
7487 | ||
b4ba55a1 | 7488 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
7489 | { |
7490 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7491 | ||
7492 | TYPE_FIELD_PRIVATE_BITS (type) = | |
7493 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7494 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
7495 | ||
7496 | TYPE_FIELD_PROTECTED_BITS (type) = | |
7497 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7498 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
7499 | ||
774b6a14 TT |
7500 | TYPE_FIELD_IGNORE_BITS (type) = |
7501 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
7502 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
7503 | } |
7504 | ||
7505 | /* If the type has baseclasses, allocate and clear a bit vector for | |
7506 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 7507 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
7508 | { |
7509 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 7510 | unsigned char *pointer; |
c906108c SS |
7511 | |
7512 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
7513 | pointer = TYPE_ALLOC (type, num_bytes); |
7514 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
7515 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
7516 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
7517 | } | |
7518 | ||
3e43a32a MS |
7519 | /* Copy the saved-up fields into the field vector. Start from the head of |
7520 | the list, adding to the tail of the field array, so that they end up in | |
7521 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
7522 | while (nfields-- > 0) |
7523 | { | |
7d0ccb61 DJ |
7524 | struct nextfield *fieldp; |
7525 | ||
7526 | if (fip->fields) | |
7527 | { | |
7528 | fieldp = fip->fields; | |
7529 | fip->fields = fieldp->next; | |
7530 | } | |
7531 | else | |
7532 | { | |
7533 | fieldp = fip->baseclasses; | |
7534 | fip->baseclasses = fieldp->next; | |
7535 | } | |
7536 | ||
7537 | TYPE_FIELD (type, nfields) = fieldp->field; | |
7538 | switch (fieldp->accessibility) | |
c906108c | 7539 | { |
c5aa993b | 7540 | case DW_ACCESS_private: |
b4ba55a1 JB |
7541 | if (cu->language != language_ada) |
7542 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 7543 | break; |
c906108c | 7544 | |
c5aa993b | 7545 | case DW_ACCESS_protected: |
b4ba55a1 JB |
7546 | if (cu->language != language_ada) |
7547 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 7548 | break; |
c906108c | 7549 | |
c5aa993b JM |
7550 | case DW_ACCESS_public: |
7551 | break; | |
c906108c | 7552 | |
c5aa993b JM |
7553 | default: |
7554 | /* Unknown accessibility. Complain and treat it as public. */ | |
7555 | { | |
e2e0b3e5 | 7556 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 7557 | fieldp->accessibility); |
c5aa993b JM |
7558 | } |
7559 | break; | |
c906108c SS |
7560 | } |
7561 | if (nfields < fip->nbaseclasses) | |
7562 | { | |
7d0ccb61 | 7563 | switch (fieldp->virtuality) |
c906108c | 7564 | { |
c5aa993b JM |
7565 | case DW_VIRTUALITY_virtual: |
7566 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 7567 | if (cu->language == language_ada) |
a73c6dcd | 7568 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
7569 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
7570 | break; | |
c906108c SS |
7571 | } |
7572 | } | |
c906108c SS |
7573 | } |
7574 | } | |
7575 | ||
c906108c SS |
7576 | /* Add a member function to the proper fieldlist. */ |
7577 | ||
7578 | static void | |
107d2387 | 7579 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 7580 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 7581 | { |
e7c27a73 | 7582 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7583 | struct attribute *attr; |
7584 | struct fnfieldlist *flp; | |
7585 | int i; | |
7586 | struct fn_field *fnp; | |
7587 | char *fieldname; | |
c906108c | 7588 | struct nextfnfield *new_fnfield; |
f792889a | 7589 | struct type *this_type; |
60d5a603 | 7590 | enum dwarf_access_attribute accessibility; |
c906108c | 7591 | |
b4ba55a1 | 7592 | if (cu->language == language_ada) |
a73c6dcd | 7593 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 7594 | |
2df3850c | 7595 | /* Get name of member function. */ |
39cbfefa DJ |
7596 | fieldname = dwarf2_name (die, cu); |
7597 | if (fieldname == NULL) | |
2df3850c | 7598 | return; |
c906108c | 7599 | |
c906108c SS |
7600 | /* Look up member function name in fieldlist. */ |
7601 | for (i = 0; i < fip->nfnfields; i++) | |
7602 | { | |
27bfe10e | 7603 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
7604 | break; |
7605 | } | |
7606 | ||
7607 | /* Create new list element if necessary. */ | |
7608 | if (i < fip->nfnfields) | |
7609 | flp = &fip->fnfieldlists[i]; | |
7610 | else | |
7611 | { | |
7612 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7613 | { | |
7614 | fip->fnfieldlists = (struct fnfieldlist *) | |
7615 | xrealloc (fip->fnfieldlists, | |
7616 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7617 | * sizeof (struct fnfieldlist)); |
c906108c | 7618 | if (fip->nfnfields == 0) |
c13c43fd | 7619 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
7620 | } |
7621 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
7622 | flp->name = fieldname; | |
7623 | flp->length = 0; | |
7624 | flp->head = NULL; | |
3da10d80 | 7625 | i = fip->nfnfields++; |
c906108c SS |
7626 | } |
7627 | ||
7628 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 7629 | entry. */ |
c906108c | 7630 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 7631 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
7632 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
7633 | new_fnfield->next = flp->head; | |
7634 | flp->head = new_fnfield; | |
7635 | flp->length++; | |
7636 | ||
7637 | /* Fill in the member function field info. */ | |
7638 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
7639 | |
7640 | /* Delay processing of the physname until later. */ | |
7641 | if (cu->language == language_cplus || cu->language == language_java) | |
7642 | { | |
7643 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
7644 | die, cu); | |
7645 | } | |
7646 | else | |
7647 | { | |
1d06ead6 | 7648 | const char *physname = dwarf2_physname (fieldname, die, cu); |
3da10d80 KS |
7649 | fnp->physname = physname ? physname : ""; |
7650 | } | |
7651 | ||
c906108c | 7652 | fnp->type = alloc_type (objfile); |
f792889a DJ |
7653 | this_type = read_type_die (die, cu); |
7654 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 7655 | { |
f792889a | 7656 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 7657 | |
f792889a | 7658 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
7659 | of the method itself (TYPE_CODE_METHOD). */ |
7660 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
7661 | TYPE_TARGET_TYPE (this_type), |
7662 | TYPE_FIELDS (this_type), | |
7663 | TYPE_NFIELDS (this_type), | |
7664 | TYPE_VARARGS (this_type)); | |
c906108c SS |
7665 | |
7666 | /* Handle static member functions. | |
c5aa993b | 7667 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
7668 | member functions. G++ helps GDB by marking the first |
7669 | parameter for non-static member functions (which is the this | |
7670 | pointer) as artificial. We obtain this information from | |
7671 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 7672 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
7673 | fnp->voffset = VOFFSET_STATIC; |
7674 | } | |
7675 | else | |
e2e0b3e5 | 7676 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 7677 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
7678 | |
7679 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 7680 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 7681 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 7682 | |
3e43a32a MS |
7683 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
7684 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
7685 | |
7686 | /* Get accessibility. */ | |
e142c38c | 7687 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c | 7688 | if (attr) |
60d5a603 JK |
7689 | accessibility = DW_UNSND (attr); |
7690 | else | |
7691 | accessibility = dwarf2_default_access_attribute (die, cu); | |
7692 | switch (accessibility) | |
c906108c | 7693 | { |
60d5a603 JK |
7694 | case DW_ACCESS_private: |
7695 | fnp->is_private = 1; | |
7696 | break; | |
7697 | case DW_ACCESS_protected: | |
7698 | fnp->is_protected = 1; | |
7699 | break; | |
c906108c SS |
7700 | } |
7701 | ||
b02dede2 | 7702 | /* Check for artificial methods. */ |
e142c38c | 7703 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
7704 | if (attr && DW_UNSND (attr) != 0) |
7705 | fnp->is_artificial = 1; | |
7706 | ||
0d564a31 | 7707 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
7708 | function. For older versions of GCC, this is an offset in the |
7709 | appropriate virtual table, as specified by DW_AT_containing_type. | |
7710 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
7711 | to the object address. */ |
7712 | ||
e142c38c | 7713 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 7714 | if (attr) |
8e19ed76 | 7715 | { |
aec5aa8b | 7716 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 7717 | { |
aec5aa8b TT |
7718 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
7719 | { | |
7720 | /* Old-style GCC. */ | |
7721 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
7722 | } | |
7723 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7724 | || (DW_BLOCK (attr)->size > 1 | |
7725 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
7726 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
7727 | { | |
7728 | struct dwarf_block blk; | |
7729 | int offset; | |
7730 | ||
7731 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
7732 | ? 1 : 2); | |
7733 | blk.size = DW_BLOCK (attr)->size - offset; | |
7734 | blk.data = DW_BLOCK (attr)->data + offset; | |
7735 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
7736 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
7737 | dwarf2_complex_location_expr_complaint (); | |
7738 | else | |
7739 | fnp->voffset /= cu->header.addr_size; | |
7740 | fnp->voffset += 2; | |
7741 | } | |
7742 | else | |
7743 | dwarf2_complex_location_expr_complaint (); | |
7744 | ||
7745 | if (!fnp->fcontext) | |
7746 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
7747 | } | |
3690dd37 | 7748 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7749 | { |
4d3c2250 | 7750 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7751 | } |
7752 | else | |
7753 | { | |
4d3c2250 KB |
7754 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
7755 | fieldname); | |
8e19ed76 | 7756 | } |
0d564a31 | 7757 | } |
d48cc9dd DJ |
7758 | else |
7759 | { | |
7760 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
7761 | if (attr && DW_UNSND (attr)) | |
7762 | { | |
7763 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
7764 | complaint (&symfile_complaints, | |
3e43a32a MS |
7765 | _("Member function \"%s\" (offset %d) is virtual " |
7766 | "but the vtable offset is not specified"), | |
b64f50a1 | 7767 | fieldname, die->offset.sect_off); |
9655fd1a | 7768 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
7769 | TYPE_CPLUS_DYNAMIC (type) = 1; |
7770 | } | |
7771 | } | |
c906108c SS |
7772 | } |
7773 | ||
7774 | /* Create the vector of member function fields, and attach it to the type. */ | |
7775 | ||
7776 | static void | |
fba45db2 | 7777 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 7778 | struct dwarf2_cu *cu) |
c906108c SS |
7779 | { |
7780 | struct fnfieldlist *flp; | |
c906108c SS |
7781 | int i; |
7782 | ||
b4ba55a1 | 7783 | if (cu->language == language_ada) |
a73c6dcd | 7784 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 7785 | |
c906108c SS |
7786 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
7787 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
7788 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
7789 | ||
7790 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
7791 | { | |
7792 | struct nextfnfield *nfp = flp->head; | |
7793 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
7794 | int k; | |
7795 | ||
7796 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
7797 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
7798 | fn_flp->fn_fields = (struct fn_field *) | |
7799 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
7800 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 7801 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
7802 | } |
7803 | ||
7804 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
c906108c SS |
7805 | } |
7806 | ||
1168df01 JB |
7807 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
7808 | language, zero otherwise. */ | |
7809 | static int | |
7810 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
7811 | { | |
7812 | static const char vptr[] = "_vptr"; | |
987504bb | 7813 | static const char vtable[] = "vtable"; |
1168df01 | 7814 | |
987504bb JJ |
7815 | /* Look for the C++ and Java forms of the vtable. */ |
7816 | if ((cu->language == language_java | |
7817 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
7818 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
7819 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
7820 | return 1; |
7821 | ||
7822 | return 0; | |
7823 | } | |
7824 | ||
c0dd20ea | 7825 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
7826 | functions, with the ABI-specified layout. If TYPE describes |
7827 | such a structure, smash it into a member function type. | |
61049d3b DJ |
7828 | |
7829 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
7830 | This is GCC PR debug/28767. */ | |
c0dd20ea | 7831 | |
0b92b5bb TT |
7832 | static void |
7833 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 7834 | { |
0b92b5bb | 7835 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
7836 | |
7837 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
7838 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
7839 | return; | |
c0dd20ea DJ |
7840 | |
7841 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
7842 | if (TYPE_FIELD_NAME (type, 0) == NULL |
7843 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
7844 | || TYPE_FIELD_NAME (type, 1) == NULL | |
7845 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
7846 | return; | |
c0dd20ea DJ |
7847 | |
7848 | /* Find the type of the method. */ | |
0b92b5bb | 7849 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
7850 | if (pfn_type == NULL |
7851 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
7852 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 7853 | return; |
c0dd20ea DJ |
7854 | |
7855 | /* Look for the "this" argument. */ | |
7856 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
7857 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 7858 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 7859 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 7860 | return; |
c0dd20ea DJ |
7861 | |
7862 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
7863 | new_type = alloc_type (objfile); |
7864 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
7865 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
7866 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 7867 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 7868 | } |
1168df01 | 7869 | |
c906108c | 7870 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
7871 | (definition) to create a type for the structure or union. Fill in |
7872 | the type's name and general properties; the members will not be | |
7873 | processed until process_structure_type. | |
c906108c | 7874 | |
c767944b DJ |
7875 | NOTE: we need to call these functions regardless of whether or not the |
7876 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
7877 | structure or union. This gets the type entered into our set of |
7878 | user defined types. | |
7879 | ||
7880 | However, if the structure is incomplete (an opaque struct/union) | |
7881 | then suppress creating a symbol table entry for it since gdb only | |
7882 | wants to find the one with the complete definition. Note that if | |
7883 | it is complete, we just call new_symbol, which does it's own | |
7884 | checking about whether the struct/union is anonymous or not (and | |
7885 | suppresses creating a symbol table entry itself). */ | |
7886 | ||
f792889a | 7887 | static struct type * |
134d01f1 | 7888 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7889 | { |
e7c27a73 | 7890 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7891 | struct type *type; |
7892 | struct attribute *attr; | |
39cbfefa | 7893 | char *name; |
c906108c | 7894 | |
348e048f DE |
7895 | /* If the definition of this type lives in .debug_types, read that type. |
7896 | Don't follow DW_AT_specification though, that will take us back up | |
7897 | the chain and we want to go down. */ | |
7898 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7899 | if (attr) | |
7900 | { | |
7901 | struct dwarf2_cu *type_cu = cu; | |
7902 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7903 | |
348e048f DE |
7904 | /* We could just recurse on read_structure_type, but we need to call |
7905 | get_die_type to ensure only one type for this DIE is created. | |
7906 | This is important, for example, because for c++ classes we need | |
7907 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
7908 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
7909 | |
7910 | /* TYPE_CU may not be the same as CU. | |
7911 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7912 | return set_die_type (die, type, cu); |
7913 | } | |
7914 | ||
c0dd20ea | 7915 | type = alloc_type (objfile); |
c906108c | 7916 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 7917 | |
39cbfefa DJ |
7918 | name = dwarf2_name (die, cu); |
7919 | if (name != NULL) | |
c906108c | 7920 | { |
987504bb JJ |
7921 | if (cu->language == language_cplus |
7922 | || cu->language == language_java) | |
63d06c5c | 7923 | { |
3da10d80 KS |
7924 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
7925 | ||
7926 | /* dwarf2_full_name might have already finished building the DIE's | |
7927 | type. If so, there is no need to continue. */ | |
7928 | if (get_die_type (die, cu) != NULL) | |
7929 | return get_die_type (die, cu); | |
7930 | ||
7931 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
7932 | if (die->tag == DW_TAG_structure_type |
7933 | || die->tag == DW_TAG_class_type) | |
7934 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
7935 | } |
7936 | else | |
7937 | { | |
d8151005 DJ |
7938 | /* The name is already allocated along with this objfile, so |
7939 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
7940 | TYPE_TAG_NAME (type) = (char *) name; |
7941 | if (die->tag == DW_TAG_class_type) | |
7942 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 7943 | } |
c906108c SS |
7944 | } |
7945 | ||
7946 | if (die->tag == DW_TAG_structure_type) | |
7947 | { | |
7948 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
7949 | } | |
7950 | else if (die->tag == DW_TAG_union_type) | |
7951 | { | |
7952 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
7953 | } | |
7954 | else | |
7955 | { | |
c906108c SS |
7956 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
7957 | } | |
7958 | ||
0cc2414c TT |
7959 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
7960 | TYPE_DECLARED_CLASS (type) = 1; | |
7961 | ||
e142c38c | 7962 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7963 | if (attr) |
7964 | { | |
7965 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7966 | } | |
7967 | else | |
7968 | { | |
7969 | TYPE_LENGTH (type) = 0; | |
7970 | } | |
7971 | ||
876cecd0 | 7972 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 7973 | if (die_is_declaration (die, cu)) |
876cecd0 | 7974 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
7975 | else if (attr == NULL && die->child == NULL |
7976 | && producer_is_realview (cu->producer)) | |
7977 | /* RealView does not output the required DW_AT_declaration | |
7978 | on incomplete types. */ | |
7979 | TYPE_STUB (type) = 1; | |
dc718098 | 7980 | |
c906108c SS |
7981 | /* We need to add the type field to the die immediately so we don't |
7982 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 7983 | type within the structure itself. */ |
1c379e20 | 7984 | set_die_type (die, type, cu); |
c906108c | 7985 | |
7e314c57 JK |
7986 | /* set_die_type should be already done. */ |
7987 | set_descriptive_type (type, die, cu); | |
7988 | ||
c767944b DJ |
7989 | return type; |
7990 | } | |
7991 | ||
7992 | /* Finish creating a structure or union type, including filling in | |
7993 | its members and creating a symbol for it. */ | |
7994 | ||
7995 | static void | |
7996 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7997 | { | |
7998 | struct objfile *objfile = cu->objfile; | |
7999 | struct die_info *child_die = die->child; | |
8000 | struct type *type; | |
8001 | ||
8002 | type = get_die_type (die, cu); | |
8003 | if (type == NULL) | |
8004 | type = read_structure_type (die, cu); | |
8005 | ||
e142c38c | 8006 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
8007 | { |
8008 | struct field_info fi; | |
8009 | struct die_info *child_die; | |
34eaf542 | 8010 | VEC (symbolp) *template_args = NULL; |
c767944b | 8011 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
8012 | |
8013 | memset (&fi, 0, sizeof (struct field_info)); | |
8014 | ||
639d11d3 | 8015 | child_die = die->child; |
c906108c SS |
8016 | |
8017 | while (child_die && child_die->tag) | |
8018 | { | |
a9a9bd0f DC |
8019 | if (child_die->tag == DW_TAG_member |
8020 | || child_die->tag == DW_TAG_variable) | |
c906108c | 8021 | { |
a9a9bd0f DC |
8022 | /* NOTE: carlton/2002-11-05: A C++ static data member |
8023 | should be a DW_TAG_member that is a declaration, but | |
8024 | all versions of G++ as of this writing (so through at | |
8025 | least 3.2.1) incorrectly generate DW_TAG_variable | |
8026 | tags for them instead. */ | |
e7c27a73 | 8027 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 8028 | } |
8713b1b1 | 8029 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 8030 | { |
0963b4bd | 8031 | /* C++ member function. */ |
e7c27a73 | 8032 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
8033 | } |
8034 | else if (child_die->tag == DW_TAG_inheritance) | |
8035 | { | |
8036 | /* C++ base class field. */ | |
e7c27a73 | 8037 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 8038 | } |
98751a41 JK |
8039 | else if (child_die->tag == DW_TAG_typedef) |
8040 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
8041 | else if (child_die->tag == DW_TAG_template_type_param |
8042 | || child_die->tag == DW_TAG_template_value_param) | |
8043 | { | |
8044 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
8045 | ||
f1078f66 DJ |
8046 | if (arg != NULL) |
8047 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
8048 | } |
8049 | ||
c906108c SS |
8050 | child_die = sibling_die (child_die); |
8051 | } | |
8052 | ||
34eaf542 TT |
8053 | /* Attach template arguments to type. */ |
8054 | if (! VEC_empty (symbolp, template_args)) | |
8055 | { | |
8056 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
8057 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8058 | = VEC_length (symbolp, template_args); | |
8059 | TYPE_TEMPLATE_ARGUMENTS (type) | |
8060 | = obstack_alloc (&objfile->objfile_obstack, | |
8061 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8062 | * sizeof (struct symbol *))); | |
8063 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
8064 | VEC_address (symbolp, template_args), | |
8065 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
8066 | * sizeof (struct symbol *))); | |
8067 | VEC_free (symbolp, template_args); | |
8068 | } | |
8069 | ||
c906108c SS |
8070 | /* Attach fields and member functions to the type. */ |
8071 | if (fi.nfields) | |
e7c27a73 | 8072 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
8073 | if (fi.nfnfields) |
8074 | { | |
e7c27a73 | 8075 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 8076 | |
c5aa993b | 8077 | /* Get the type which refers to the base class (possibly this |
c906108c | 8078 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
8079 | class from the DW_AT_containing_type attribute. This use of |
8080 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 8081 | |
e142c38c | 8082 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 8083 | { |
e7c27a73 | 8084 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
8085 | |
8086 | TYPE_VPTR_BASETYPE (type) = t; | |
8087 | if (type == t) | |
8088 | { | |
c906108c SS |
8089 | int i; |
8090 | ||
8091 | /* Our own class provides vtbl ptr. */ | |
8092 | for (i = TYPE_NFIELDS (t) - 1; | |
8093 | i >= TYPE_N_BASECLASSES (t); | |
8094 | --i) | |
8095 | { | |
0d5cff50 | 8096 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
c906108c | 8097 | |
1168df01 | 8098 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
8099 | { |
8100 | TYPE_VPTR_FIELDNO (type) = i; | |
8101 | break; | |
8102 | } | |
8103 | } | |
8104 | ||
8105 | /* Complain if virtual function table field not found. */ | |
8106 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 8107 | complaint (&symfile_complaints, |
3e43a32a MS |
8108 | _("virtual function table pointer " |
8109 | "not found when defining class '%s'"), | |
4d3c2250 KB |
8110 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
8111 | ""); | |
c906108c SS |
8112 | } |
8113 | else | |
8114 | { | |
8115 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
8116 | } | |
8117 | } | |
f6235d4c EZ |
8118 | else if (cu->producer |
8119 | && strncmp (cu->producer, | |
8120 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
8121 | { | |
8122 | /* The IBM XLC compiler does not provide direct indication | |
8123 | of the containing type, but the vtable pointer is | |
8124 | always named __vfp. */ | |
8125 | ||
8126 | int i; | |
8127 | ||
8128 | for (i = TYPE_NFIELDS (type) - 1; | |
8129 | i >= TYPE_N_BASECLASSES (type); | |
8130 | --i) | |
8131 | { | |
8132 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
8133 | { | |
8134 | TYPE_VPTR_FIELDNO (type) = i; | |
8135 | TYPE_VPTR_BASETYPE (type) = type; | |
8136 | break; | |
8137 | } | |
8138 | } | |
8139 | } | |
c906108c | 8140 | } |
98751a41 JK |
8141 | |
8142 | /* Copy fi.typedef_field_list linked list elements content into the | |
8143 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
8144 | if (fi.typedef_field_list) | |
8145 | { | |
8146 | int i = fi.typedef_field_list_count; | |
8147 | ||
a0d7a4ff | 8148 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
8149 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
8150 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
8151 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
8152 | ||
8153 | /* Reverse the list order to keep the debug info elements order. */ | |
8154 | while (--i >= 0) | |
8155 | { | |
8156 | struct typedef_field *dest, *src; | |
6e70227d | 8157 | |
98751a41 JK |
8158 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
8159 | src = &fi.typedef_field_list->field; | |
8160 | fi.typedef_field_list = fi.typedef_field_list->next; | |
8161 | *dest = *src; | |
8162 | } | |
8163 | } | |
c767944b DJ |
8164 | |
8165 | do_cleanups (back_to); | |
eb2a6f42 TT |
8166 | |
8167 | if (HAVE_CPLUS_STRUCT (type)) | |
8168 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; | |
c906108c | 8169 | } |
63d06c5c | 8170 | |
bb5ed363 | 8171 | quirk_gcc_member_function_pointer (type, objfile); |
0b92b5bb | 8172 | |
90aeadfc DC |
8173 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
8174 | snapshots) has been known to create a die giving a declaration | |
8175 | for a class that has, as a child, a die giving a definition for a | |
8176 | nested class. So we have to process our children even if the | |
8177 | current die is a declaration. Normally, of course, a declaration | |
8178 | won't have any children at all. */ | |
134d01f1 | 8179 | |
90aeadfc DC |
8180 | while (child_die != NULL && child_die->tag) |
8181 | { | |
8182 | if (child_die->tag == DW_TAG_member | |
8183 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
8184 | || child_die->tag == DW_TAG_inheritance |
8185 | || child_die->tag == DW_TAG_template_value_param | |
8186 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 8187 | { |
90aeadfc | 8188 | /* Do nothing. */ |
134d01f1 | 8189 | } |
90aeadfc DC |
8190 | else |
8191 | process_die (child_die, cu); | |
134d01f1 | 8192 | |
90aeadfc | 8193 | child_die = sibling_die (child_die); |
134d01f1 DJ |
8194 | } |
8195 | ||
fa4028e9 JB |
8196 | /* Do not consider external references. According to the DWARF standard, |
8197 | these DIEs are identified by the fact that they have no byte_size | |
8198 | attribute, and a declaration attribute. */ | |
8199 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
8200 | || !die_is_declaration (die, cu)) | |
c767944b | 8201 | new_symbol (die, type, cu); |
134d01f1 DJ |
8202 | } |
8203 | ||
8204 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
8205 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 8206 | |
f792889a | 8207 | static struct type * |
134d01f1 | 8208 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8209 | { |
e7c27a73 | 8210 | struct objfile *objfile = cu->objfile; |
c906108c | 8211 | struct type *type; |
c906108c | 8212 | struct attribute *attr; |
0114d602 | 8213 | const char *name; |
134d01f1 | 8214 | |
348e048f DE |
8215 | /* If the definition of this type lives in .debug_types, read that type. |
8216 | Don't follow DW_AT_specification though, that will take us back up | |
8217 | the chain and we want to go down. */ | |
8218 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
8219 | if (attr) | |
8220 | { | |
8221 | struct dwarf2_cu *type_cu = cu; | |
8222 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 8223 | |
348e048f | 8224 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
8225 | |
8226 | /* TYPE_CU may not be the same as CU. | |
8227 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
8228 | return set_die_type (die, type, cu); |
8229 | } | |
8230 | ||
c906108c SS |
8231 | type = alloc_type (objfile); |
8232 | ||
8233 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 8234 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 8235 | if (name != NULL) |
0114d602 | 8236 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 8237 | |
e142c38c | 8238 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8239 | if (attr) |
8240 | { | |
8241 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8242 | } | |
8243 | else | |
8244 | { | |
8245 | TYPE_LENGTH (type) = 0; | |
8246 | } | |
8247 | ||
137033e9 JB |
8248 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
8249 | declared as private in the package spec, and then defined only | |
8250 | inside the package body. Such types are known as Taft Amendment | |
8251 | Types. When another package uses such a type, an incomplete DIE | |
8252 | may be generated by the compiler. */ | |
02eb380e | 8253 | if (die_is_declaration (die, cu)) |
876cecd0 | 8254 | TYPE_STUB (type) = 1; |
02eb380e | 8255 | |
f792889a | 8256 | return set_die_type (die, type, cu); |
134d01f1 DJ |
8257 | } |
8258 | ||
8259 | /* Given a pointer to a die which begins an enumeration, process all | |
8260 | the dies that define the members of the enumeration, and create the | |
8261 | symbol for the enumeration type. | |
8262 | ||
8263 | NOTE: We reverse the order of the element list. */ | |
8264 | ||
8265 | static void | |
8266 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
8267 | { | |
f792889a | 8268 | struct type *this_type; |
134d01f1 | 8269 | |
f792889a DJ |
8270 | this_type = get_die_type (die, cu); |
8271 | if (this_type == NULL) | |
8272 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 8273 | |
639d11d3 | 8274 | if (die->child != NULL) |
c906108c | 8275 | { |
9dc481d3 DE |
8276 | struct die_info *child_die; |
8277 | struct symbol *sym; | |
8278 | struct field *fields = NULL; | |
8279 | int num_fields = 0; | |
8280 | int unsigned_enum = 1; | |
8281 | char *name; | |
cafec441 TT |
8282 | int flag_enum = 1; |
8283 | ULONGEST mask = 0; | |
9dc481d3 | 8284 | |
639d11d3 | 8285 | child_die = die->child; |
c906108c SS |
8286 | while (child_die && child_die->tag) |
8287 | { | |
8288 | if (child_die->tag != DW_TAG_enumerator) | |
8289 | { | |
e7c27a73 | 8290 | process_die (child_die, cu); |
c906108c SS |
8291 | } |
8292 | else | |
8293 | { | |
39cbfefa DJ |
8294 | name = dwarf2_name (child_die, cu); |
8295 | if (name) | |
c906108c | 8296 | { |
f792889a | 8297 | sym = new_symbol (child_die, this_type, cu); |
c906108c | 8298 | if (SYMBOL_VALUE (sym) < 0) |
cafec441 TT |
8299 | { |
8300 | unsigned_enum = 0; | |
8301 | flag_enum = 0; | |
8302 | } | |
8303 | else if ((mask & SYMBOL_VALUE (sym)) != 0) | |
8304 | flag_enum = 0; | |
8305 | else | |
8306 | mask |= SYMBOL_VALUE (sym); | |
c906108c SS |
8307 | |
8308 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
8309 | { | |
8310 | fields = (struct field *) | |
8311 | xrealloc (fields, | |
8312 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 8313 | * sizeof (struct field)); |
c906108c SS |
8314 | } |
8315 | ||
3567439c | 8316 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 8317 | FIELD_TYPE (fields[num_fields]) = NULL; |
14e75d8e | 8318 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
8319 | FIELD_BITSIZE (fields[num_fields]) = 0; |
8320 | ||
8321 | num_fields++; | |
8322 | } | |
8323 | } | |
8324 | ||
8325 | child_die = sibling_die (child_die); | |
8326 | } | |
8327 | ||
8328 | if (num_fields) | |
8329 | { | |
f792889a DJ |
8330 | TYPE_NFIELDS (this_type) = num_fields; |
8331 | TYPE_FIELDS (this_type) = (struct field *) | |
8332 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
8333 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 8334 | sizeof (struct field) * num_fields); |
b8c9b27d | 8335 | xfree (fields); |
c906108c SS |
8336 | } |
8337 | if (unsigned_enum) | |
876cecd0 | 8338 | TYPE_UNSIGNED (this_type) = 1; |
cafec441 TT |
8339 | if (flag_enum) |
8340 | TYPE_FLAG_ENUM (this_type) = 1; | |
c906108c | 8341 | } |
134d01f1 | 8342 | |
6c83ed52 TT |
8343 | /* If we are reading an enum from a .debug_types unit, and the enum |
8344 | is a declaration, and the enum is not the signatured type in the | |
8345 | unit, then we do not want to add a symbol for it. Adding a | |
8346 | symbol would in some cases obscure the true definition of the | |
8347 | enum, giving users an incomplete type when the definition is | |
8348 | actually available. Note that we do not want to do this for all | |
8349 | enums which are just declarations, because C++0x allows forward | |
8350 | enum declarations. */ | |
b0df02fd | 8351 | if (cu->per_cu->debug_types_section |
6c83ed52 TT |
8352 | && die_is_declaration (die, cu)) |
8353 | { | |
52dc124a | 8354 | struct signatured_type *sig_type; |
6c83ed52 | 8355 | |
52dc124a | 8356 | sig_type |
6c83ed52 | 8357 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
b0df02fd | 8358 | cu->per_cu->debug_types_section, |
6c83ed52 | 8359 | cu->per_cu->offset); |
52dc124a | 8360 | if (sig_type->per_cu.offset.sect_off + sig_type->type_offset.cu_off |
b64f50a1 | 8361 | != die->offset.sect_off) |
6c83ed52 TT |
8362 | return; |
8363 | } | |
8364 | ||
f792889a | 8365 | new_symbol (die, this_type, cu); |
c906108c SS |
8366 | } |
8367 | ||
8368 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
8369 | the DIE's type field. For now, this only handles one dimensional | |
8370 | arrays. */ | |
8371 | ||
f792889a | 8372 | static struct type * |
e7c27a73 | 8373 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8374 | { |
e7c27a73 | 8375 | struct objfile *objfile = cu->objfile; |
c906108c | 8376 | struct die_info *child_die; |
7e314c57 | 8377 | struct type *type; |
c906108c SS |
8378 | struct type *element_type, *range_type, *index_type; |
8379 | struct type **range_types = NULL; | |
8380 | struct attribute *attr; | |
8381 | int ndim = 0; | |
8382 | struct cleanup *back_to; | |
39cbfefa | 8383 | char *name; |
c906108c | 8384 | |
e7c27a73 | 8385 | element_type = die_type (die, cu); |
c906108c | 8386 | |
7e314c57 JK |
8387 | /* The die_type call above may have already set the type for this DIE. */ |
8388 | type = get_die_type (die, cu); | |
8389 | if (type) | |
8390 | return type; | |
8391 | ||
c906108c SS |
8392 | /* Irix 6.2 native cc creates array types without children for |
8393 | arrays with unspecified length. */ | |
639d11d3 | 8394 | if (die->child == NULL) |
c906108c | 8395 | { |
46bf5051 | 8396 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8397 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
8398 | type = create_array_type (NULL, element_type, range_type); |
8399 | return set_die_type (die, type, cu); | |
c906108c SS |
8400 | } |
8401 | ||
8402 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 8403 | child_die = die->child; |
c906108c SS |
8404 | while (child_die && child_die->tag) |
8405 | { | |
8406 | if (child_die->tag == DW_TAG_subrange_type) | |
8407 | { | |
f792889a | 8408 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 8409 | |
f792889a | 8410 | if (child_type != NULL) |
a02abb62 | 8411 | { |
0963b4bd MS |
8412 | /* The range type was succesfully read. Save it for the |
8413 | array type creation. */ | |
a02abb62 JB |
8414 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
8415 | { | |
8416 | range_types = (struct type **) | |
8417 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
8418 | * sizeof (struct type *)); | |
8419 | if (ndim == 0) | |
8420 | make_cleanup (free_current_contents, &range_types); | |
8421 | } | |
f792889a | 8422 | range_types[ndim++] = child_type; |
a02abb62 | 8423 | } |
c906108c SS |
8424 | } |
8425 | child_die = sibling_die (child_die); | |
8426 | } | |
8427 | ||
8428 | /* Dwarf2 dimensions are output from left to right, create the | |
8429 | necessary array types in backwards order. */ | |
7ca2d3a3 | 8430 | |
c906108c | 8431 | type = element_type; |
7ca2d3a3 DL |
8432 | |
8433 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
8434 | { | |
8435 | int i = 0; | |
9a619af0 | 8436 | |
7ca2d3a3 DL |
8437 | while (i < ndim) |
8438 | type = create_array_type (NULL, type, range_types[i++]); | |
8439 | } | |
8440 | else | |
8441 | { | |
8442 | while (ndim-- > 0) | |
8443 | type = create_array_type (NULL, type, range_types[ndim]); | |
8444 | } | |
c906108c | 8445 | |
f5f8a009 EZ |
8446 | /* Understand Dwarf2 support for vector types (like they occur on |
8447 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
8448 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
8449 | custom vendor extension. The main difference between a regular | |
8450 | array and the vector variant is that vectors are passed by value | |
8451 | to functions. */ | |
e142c38c | 8452 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 8453 | if (attr) |
ea37ba09 | 8454 | make_vector_type (type); |
f5f8a009 | 8455 | |
dbc98a8b KW |
8456 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
8457 | implementation may choose to implement triple vectors using this | |
8458 | attribute. */ | |
8459 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
8460 | if (attr) | |
8461 | { | |
8462 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
8463 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8464 | else | |
3e43a32a MS |
8465 | complaint (&symfile_complaints, |
8466 | _("DW_AT_byte_size for array type smaller " | |
8467 | "than the total size of elements")); | |
dbc98a8b KW |
8468 | } |
8469 | ||
39cbfefa DJ |
8470 | name = dwarf2_name (die, cu); |
8471 | if (name) | |
8472 | TYPE_NAME (type) = name; | |
6e70227d | 8473 | |
0963b4bd | 8474 | /* Install the type in the die. */ |
7e314c57 JK |
8475 | set_die_type (die, type, cu); |
8476 | ||
8477 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8478 | set_descriptive_type (type, die, cu); |
8479 | ||
c906108c SS |
8480 | do_cleanups (back_to); |
8481 | ||
7e314c57 | 8482 | return type; |
c906108c SS |
8483 | } |
8484 | ||
7ca2d3a3 | 8485 | static enum dwarf_array_dim_ordering |
6e70227d | 8486 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
8487 | { |
8488 | struct attribute *attr; | |
8489 | ||
8490 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
8491 | ||
8492 | if (attr) return DW_SND (attr); | |
8493 | ||
0963b4bd MS |
8494 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
8495 | opposite order to the dwarf2 specification, but data is still | |
8496 | laid out as per normal fortran. | |
7ca2d3a3 | 8497 | |
0963b4bd MS |
8498 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
8499 | version checking. */ | |
7ca2d3a3 | 8500 | |
905e0470 PM |
8501 | if (cu->language == language_fortran |
8502 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
8503 | { |
8504 | return DW_ORD_row_major; | |
8505 | } | |
8506 | ||
6e70227d | 8507 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
8508 | { |
8509 | case array_column_major: | |
8510 | return DW_ORD_col_major; | |
8511 | case array_row_major: | |
8512 | default: | |
8513 | return DW_ORD_row_major; | |
8514 | }; | |
8515 | } | |
8516 | ||
72019c9c | 8517 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 8518 | the DIE's type field. */ |
72019c9c | 8519 | |
f792889a | 8520 | static struct type * |
72019c9c GM |
8521 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
8522 | { | |
7e314c57 JK |
8523 | struct type *domain_type, *set_type; |
8524 | struct attribute *attr; | |
f792889a | 8525 | |
7e314c57 JK |
8526 | domain_type = die_type (die, cu); |
8527 | ||
8528 | /* The die_type call above may have already set the type for this DIE. */ | |
8529 | set_type = get_die_type (die, cu); | |
8530 | if (set_type) | |
8531 | return set_type; | |
8532 | ||
8533 | set_type = create_set_type (NULL, domain_type); | |
8534 | ||
8535 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
8536 | if (attr) |
8537 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 8538 | |
f792889a | 8539 | return set_die_type (die, set_type, cu); |
72019c9c | 8540 | } |
7ca2d3a3 | 8541 | |
c906108c SS |
8542 | /* First cut: install each common block member as a global variable. */ |
8543 | ||
8544 | static void | |
e7c27a73 | 8545 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8546 | { |
8547 | struct die_info *child_die; | |
8548 | struct attribute *attr; | |
8549 | struct symbol *sym; | |
8550 | CORE_ADDR base = (CORE_ADDR) 0; | |
8551 | ||
e142c38c | 8552 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
8553 | if (attr) |
8554 | { | |
0963b4bd | 8555 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
8556 | if (attr_form_is_block (attr)) |
8557 | { | |
e7c27a73 | 8558 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 8559 | } |
3690dd37 | 8560 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 8561 | { |
4d3c2250 | 8562 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8563 | } |
8564 | else | |
8565 | { | |
4d3c2250 KB |
8566 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8567 | "common block member"); | |
8e19ed76 | 8568 | } |
c906108c | 8569 | } |
639d11d3 | 8570 | if (die->child != NULL) |
c906108c | 8571 | { |
639d11d3 | 8572 | child_die = die->child; |
c906108c SS |
8573 | while (child_die && child_die->tag) |
8574 | { | |
74ac6d43 TT |
8575 | LONGEST offset; |
8576 | ||
e7c27a73 | 8577 | sym = new_symbol (child_die, NULL, cu); |
e8d28ef4 TT |
8578 | if (sym != NULL |
8579 | && handle_data_member_location (child_die, cu, &offset)) | |
c906108c | 8580 | { |
74ac6d43 | 8581 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
c906108c SS |
8582 | add_symbol_to_list (sym, &global_symbols); |
8583 | } | |
8584 | child_die = sibling_die (child_die); | |
8585 | } | |
8586 | } | |
8587 | } | |
8588 | ||
0114d602 | 8589 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 8590 | |
0114d602 DJ |
8591 | static struct type * |
8592 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 8593 | { |
e7c27a73 | 8594 | struct objfile *objfile = cu->objfile; |
0114d602 | 8595 | const char *previous_prefix, *name; |
9219021c | 8596 | int is_anonymous; |
0114d602 DJ |
8597 | struct type *type; |
8598 | ||
8599 | /* For extensions, reuse the type of the original namespace. */ | |
8600 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
8601 | { | |
8602 | struct die_info *ext_die; | |
8603 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 8604 | |
0114d602 DJ |
8605 | ext_die = dwarf2_extension (die, &ext_cu); |
8606 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
8607 | |
8608 | /* EXT_CU may not be the same as CU. | |
8609 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
8610 | return set_die_type (die, type, cu); |
8611 | } | |
9219021c | 8612 | |
e142c38c | 8613 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
8614 | |
8615 | /* Now build the name of the current namespace. */ | |
8616 | ||
0114d602 DJ |
8617 | previous_prefix = determine_prefix (die, cu); |
8618 | if (previous_prefix[0] != '\0') | |
8619 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 8620 | previous_prefix, name, 0, cu); |
0114d602 DJ |
8621 | |
8622 | /* Create the type. */ | |
8623 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
8624 | objfile); | |
8625 | TYPE_NAME (type) = (char *) name; | |
8626 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8627 | ||
60531b24 | 8628 | return set_die_type (die, type, cu); |
0114d602 DJ |
8629 | } |
8630 | ||
8631 | /* Read a C++ namespace. */ | |
8632 | ||
8633 | static void | |
8634 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
8635 | { | |
8636 | struct objfile *objfile = cu->objfile; | |
0114d602 | 8637 | int is_anonymous; |
9219021c | 8638 | |
5c4e30ca DC |
8639 | /* Add a symbol associated to this if we haven't seen the namespace |
8640 | before. Also, add a using directive if it's an anonymous | |
8641 | namespace. */ | |
9219021c | 8642 | |
f2f0e013 | 8643 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
8644 | { |
8645 | struct type *type; | |
8646 | ||
0114d602 | 8647 | type = read_type_die (die, cu); |
e7c27a73 | 8648 | new_symbol (die, type, cu); |
5c4e30ca | 8649 | |
e8e80198 | 8650 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 8651 | if (is_anonymous) |
0114d602 DJ |
8652 | { |
8653 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 8654 | |
c0cc3a76 | 8655 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
32019081 | 8656 | NULL, NULL, &objfile->objfile_obstack); |
0114d602 | 8657 | } |
5c4e30ca | 8658 | } |
9219021c | 8659 | |
639d11d3 | 8660 | if (die->child != NULL) |
d9fa45fe | 8661 | { |
639d11d3 | 8662 | struct die_info *child_die = die->child; |
6e70227d | 8663 | |
d9fa45fe DC |
8664 | while (child_die && child_die->tag) |
8665 | { | |
e7c27a73 | 8666 | process_die (child_die, cu); |
d9fa45fe DC |
8667 | child_die = sibling_die (child_die); |
8668 | } | |
8669 | } | |
38d518c9 EZ |
8670 | } |
8671 | ||
f55ee35c JK |
8672 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
8673 | imported module. Still we need that type as local Fortran "use ... only" | |
8674 | declaration imports depend on the created type in determine_prefix. */ | |
8675 | ||
8676 | static struct type * | |
8677 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
8678 | { | |
8679 | struct objfile *objfile = cu->objfile; | |
8680 | char *module_name; | |
8681 | struct type *type; | |
8682 | ||
8683 | module_name = dwarf2_name (die, cu); | |
8684 | if (!module_name) | |
3e43a32a MS |
8685 | complaint (&symfile_complaints, |
8686 | _("DW_TAG_module has no name, offset 0x%x"), | |
b64f50a1 | 8687 | die->offset.sect_off); |
f55ee35c JK |
8688 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
8689 | ||
8690 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
8691 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
8692 | ||
8693 | return set_die_type (die, type, cu); | |
8694 | } | |
8695 | ||
5d7cb8df JK |
8696 | /* Read a Fortran module. */ |
8697 | ||
8698 | static void | |
8699 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
8700 | { | |
8701 | struct die_info *child_die = die->child; | |
8702 | ||
5d7cb8df JK |
8703 | while (child_die && child_die->tag) |
8704 | { | |
8705 | process_die (child_die, cu); | |
8706 | child_die = sibling_die (child_die); | |
8707 | } | |
8708 | } | |
8709 | ||
38d518c9 EZ |
8710 | /* Return the name of the namespace represented by DIE. Set |
8711 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
8712 | namespace. */ | |
8713 | ||
8714 | static const char * | |
e142c38c | 8715 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
8716 | { |
8717 | struct die_info *current_die; | |
8718 | const char *name = NULL; | |
8719 | ||
8720 | /* Loop through the extensions until we find a name. */ | |
8721 | ||
8722 | for (current_die = die; | |
8723 | current_die != NULL; | |
f2f0e013 | 8724 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 8725 | { |
e142c38c | 8726 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
8727 | if (name != NULL) |
8728 | break; | |
8729 | } | |
8730 | ||
8731 | /* Is it an anonymous namespace? */ | |
8732 | ||
8733 | *is_anonymous = (name == NULL); | |
8734 | if (*is_anonymous) | |
2b1dbab0 | 8735 | name = CP_ANONYMOUS_NAMESPACE_STR; |
38d518c9 EZ |
8736 | |
8737 | return name; | |
d9fa45fe DC |
8738 | } |
8739 | ||
c906108c SS |
8740 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
8741 | the user defined type vector. */ | |
8742 | ||
f792889a | 8743 | static struct type * |
e7c27a73 | 8744 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8745 | { |
5e2b427d | 8746 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 8747 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 8748 | struct type *type; |
8b2dbe47 KB |
8749 | struct attribute *attr_byte_size; |
8750 | struct attribute *attr_address_class; | |
8751 | int byte_size, addr_class; | |
7e314c57 JK |
8752 | struct type *target_type; |
8753 | ||
8754 | target_type = die_type (die, cu); | |
c906108c | 8755 | |
7e314c57 JK |
8756 | /* The die_type call above may have already set the type for this DIE. */ |
8757 | type = get_die_type (die, cu); | |
8758 | if (type) | |
8759 | return type; | |
8760 | ||
8761 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 8762 | |
e142c38c | 8763 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
8764 | if (attr_byte_size) |
8765 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 8766 | else |
8b2dbe47 KB |
8767 | byte_size = cu_header->addr_size; |
8768 | ||
e142c38c | 8769 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
8770 | if (attr_address_class) |
8771 | addr_class = DW_UNSND (attr_address_class); | |
8772 | else | |
8773 | addr_class = DW_ADDR_none; | |
8774 | ||
8775 | /* If the pointer size or address class is different than the | |
8776 | default, create a type variant marked as such and set the | |
8777 | length accordingly. */ | |
8778 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 8779 | { |
5e2b427d | 8780 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
8781 | { |
8782 | int type_flags; | |
8783 | ||
849957d9 | 8784 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 8785 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
8786 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
8787 | == 0); | |
8b2dbe47 KB |
8788 | type = make_type_with_address_space (type, type_flags); |
8789 | } | |
8790 | else if (TYPE_LENGTH (type) != byte_size) | |
8791 | { | |
3e43a32a MS |
8792 | complaint (&symfile_complaints, |
8793 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 8794 | } |
6e70227d | 8795 | else |
9a619af0 MS |
8796 | { |
8797 | /* Should we also complain about unhandled address classes? */ | |
8798 | } | |
c906108c | 8799 | } |
8b2dbe47 KB |
8800 | |
8801 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 8802 | return set_die_type (die, type, cu); |
c906108c SS |
8803 | } |
8804 | ||
8805 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
8806 | the user defined type vector. */ | |
8807 | ||
f792889a | 8808 | static struct type * |
e7c27a73 | 8809 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8810 | { |
8811 | struct type *type; | |
8812 | struct type *to_type; | |
8813 | struct type *domain; | |
8814 | ||
e7c27a73 DJ |
8815 | to_type = die_type (die, cu); |
8816 | domain = die_containing_type (die, cu); | |
0d5de010 | 8817 | |
7e314c57 JK |
8818 | /* The calls above may have already set the type for this DIE. */ |
8819 | type = get_die_type (die, cu); | |
8820 | if (type) | |
8821 | return type; | |
8822 | ||
0d5de010 DJ |
8823 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
8824 | type = lookup_methodptr_type (to_type); | |
8825 | else | |
8826 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 8827 | |
f792889a | 8828 | return set_die_type (die, type, cu); |
c906108c SS |
8829 | } |
8830 | ||
8831 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
8832 | the user defined type vector. */ | |
8833 | ||
f792889a | 8834 | static struct type * |
e7c27a73 | 8835 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8836 | { |
e7c27a73 | 8837 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 8838 | struct type *type, *target_type; |
c906108c SS |
8839 | struct attribute *attr; |
8840 | ||
7e314c57 JK |
8841 | target_type = die_type (die, cu); |
8842 | ||
8843 | /* The die_type call above may have already set the type for this DIE. */ | |
8844 | type = get_die_type (die, cu); | |
8845 | if (type) | |
8846 | return type; | |
8847 | ||
8848 | type = lookup_reference_type (target_type); | |
e142c38c | 8849 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8850 | if (attr) |
8851 | { | |
8852 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
8853 | } | |
8854 | else | |
8855 | { | |
107d2387 | 8856 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 8857 | } |
f792889a | 8858 | return set_die_type (die, type, cu); |
c906108c SS |
8859 | } |
8860 | ||
f792889a | 8861 | static struct type * |
e7c27a73 | 8862 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8863 | { |
f792889a | 8864 | struct type *base_type, *cv_type; |
c906108c | 8865 | |
e7c27a73 | 8866 | base_type = die_type (die, cu); |
7e314c57 JK |
8867 | |
8868 | /* The die_type call above may have already set the type for this DIE. */ | |
8869 | cv_type = get_die_type (die, cu); | |
8870 | if (cv_type) | |
8871 | return cv_type; | |
8872 | ||
2f608a3a KW |
8873 | /* In case the const qualifier is applied to an array type, the element type |
8874 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
8875 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
8876 | { | |
8877 | struct type *el_type, *inner_array; | |
8878 | ||
8879 | base_type = copy_type (base_type); | |
8880 | inner_array = base_type; | |
8881 | ||
8882 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
8883 | { | |
8884 | TYPE_TARGET_TYPE (inner_array) = | |
8885 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
8886 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
8887 | } | |
8888 | ||
8889 | el_type = TYPE_TARGET_TYPE (inner_array); | |
8890 | TYPE_TARGET_TYPE (inner_array) = | |
8891 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
8892 | ||
8893 | return set_die_type (die, base_type, cu); | |
8894 | } | |
8895 | ||
f792889a DJ |
8896 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
8897 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8898 | } |
8899 | ||
f792889a | 8900 | static struct type * |
e7c27a73 | 8901 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8902 | { |
f792889a | 8903 | struct type *base_type, *cv_type; |
c906108c | 8904 | |
e7c27a73 | 8905 | base_type = die_type (die, cu); |
7e314c57 JK |
8906 | |
8907 | /* The die_type call above may have already set the type for this DIE. */ | |
8908 | cv_type = get_die_type (die, cu); | |
8909 | if (cv_type) | |
8910 | return cv_type; | |
8911 | ||
f792889a DJ |
8912 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
8913 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
8914 | } |
8915 | ||
8916 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
8917 | the user defined type vector. It isn't really a user defined type, | |
8918 | but it behaves like one, with other DIE's using an AT_user_def_type | |
8919 | attribute to reference it. */ | |
8920 | ||
f792889a | 8921 | static struct type * |
e7c27a73 | 8922 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8923 | { |
e7c27a73 | 8924 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 8925 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
8926 | struct type *type, *range_type, *index_type, *char_type; |
8927 | struct attribute *attr; | |
8928 | unsigned int length; | |
8929 | ||
e142c38c | 8930 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
8931 | if (attr) |
8932 | { | |
8933 | length = DW_UNSND (attr); | |
8934 | } | |
8935 | else | |
8936 | { | |
0963b4bd | 8937 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 8938 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
8939 | if (attr) |
8940 | { | |
8941 | length = DW_UNSND (attr); | |
8942 | } | |
8943 | else | |
8944 | { | |
8945 | length = 1; | |
8946 | } | |
c906108c | 8947 | } |
6ccb9162 | 8948 | |
46bf5051 | 8949 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 8950 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
8951 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
8952 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 8953 | |
f792889a | 8954 | return set_die_type (die, type, cu); |
c906108c SS |
8955 | } |
8956 | ||
8957 | /* Handle DIES due to C code like: | |
8958 | ||
8959 | struct foo | |
c5aa993b JM |
8960 | { |
8961 | int (*funcp)(int a, long l); | |
8962 | int b; | |
8963 | }; | |
c906108c | 8964 | |
0963b4bd | 8965 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 8966 | |
f792889a | 8967 | static struct type * |
e7c27a73 | 8968 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8969 | { |
bb5ed363 | 8970 | struct objfile *objfile = cu->objfile; |
0963b4bd MS |
8971 | struct type *type; /* Type that this function returns. */ |
8972 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
8973 | struct attribute *attr; |
8974 | ||
e7c27a73 | 8975 | type = die_type (die, cu); |
7e314c57 JK |
8976 | |
8977 | /* The die_type call above may have already set the type for this DIE. */ | |
8978 | ftype = get_die_type (die, cu); | |
8979 | if (ftype) | |
8980 | return ftype; | |
8981 | ||
0c8b41f1 | 8982 | ftype = lookup_function_type (type); |
c906108c | 8983 | |
5b8101ae | 8984 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 8985 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 8986 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 8987 | || cu->language == language_cplus |
5b8101ae PM |
8988 | || cu->language == language_java |
8989 | || cu->language == language_pascal) | |
876cecd0 | 8990 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
8991 | else if (producer_is_realview (cu->producer)) |
8992 | /* RealView does not emit DW_AT_prototyped. We can not | |
8993 | distinguish prototyped and unprototyped functions; default to | |
8994 | prototyped, since that is more common in modern code (and | |
8995 | RealView warns about unprototyped functions). */ | |
8996 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 8997 | |
c055b101 CV |
8998 | /* Store the calling convention in the type if it's available in |
8999 | the subroutine die. Otherwise set the calling convention to | |
9000 | the default value DW_CC_normal. */ | |
9001 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
9002 | if (attr) |
9003 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
9004 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
9005 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
9006 | else | |
9007 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
9008 | |
9009 | /* We need to add the subroutine type to the die immediately so | |
9010 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 9011 | declared as the same subroutine type. */ |
76c10ea2 | 9012 | set_die_type (die, ftype, cu); |
6e70227d | 9013 | |
639d11d3 | 9014 | if (die->child != NULL) |
c906108c | 9015 | { |
bb5ed363 | 9016 | struct type *void_type = objfile_type (objfile)->builtin_void; |
c906108c | 9017 | struct die_info *child_die; |
8072405b | 9018 | int nparams, iparams; |
c906108c SS |
9019 | |
9020 | /* Count the number of parameters. | |
9021 | FIXME: GDB currently ignores vararg functions, but knows about | |
9022 | vararg member functions. */ | |
8072405b | 9023 | nparams = 0; |
639d11d3 | 9024 | child_die = die->child; |
c906108c SS |
9025 | while (child_die && child_die->tag) |
9026 | { | |
9027 | if (child_die->tag == DW_TAG_formal_parameter) | |
9028 | nparams++; | |
9029 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 9030 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
9031 | child_die = sibling_die (child_die); |
9032 | } | |
9033 | ||
9034 | /* Allocate storage for parameters and fill them in. */ | |
9035 | TYPE_NFIELDS (ftype) = nparams; | |
9036 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 9037 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 9038 | |
8072405b JK |
9039 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
9040 | even if we error out during the parameters reading below. */ | |
9041 | for (iparams = 0; iparams < nparams; iparams++) | |
9042 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
9043 | ||
9044 | iparams = 0; | |
639d11d3 | 9045 | child_die = die->child; |
c906108c SS |
9046 | while (child_die && child_die->tag) |
9047 | { | |
9048 | if (child_die->tag == DW_TAG_formal_parameter) | |
9049 | { | |
3ce3b1ba PA |
9050 | struct type *arg_type; |
9051 | ||
9052 | /* DWARF version 2 has no clean way to discern C++ | |
9053 | static and non-static member functions. G++ helps | |
9054 | GDB by marking the first parameter for non-static | |
9055 | member functions (which is the this pointer) as | |
9056 | artificial. We pass this information to | |
9057 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
9058 | ||
9059 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
9060 | 4.5 does not yet generate. */ | |
e142c38c | 9061 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
9062 | if (attr) |
9063 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
9064 | else | |
418835cc KS |
9065 | { |
9066 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
9067 | ||
9068 | /* GCC/43521: In java, the formal parameter | |
9069 | "this" is sometimes not marked with DW_AT_artificial. */ | |
9070 | if (cu->language == language_java) | |
9071 | { | |
9072 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 9073 | |
418835cc KS |
9074 | if (name && !strcmp (name, "this")) |
9075 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
9076 | } | |
9077 | } | |
3ce3b1ba PA |
9078 | arg_type = die_type (child_die, cu); |
9079 | ||
9080 | /* RealView does not mark THIS as const, which the testsuite | |
9081 | expects. GCC marks THIS as const in method definitions, | |
9082 | but not in the class specifications (GCC PR 43053). */ | |
9083 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
9084 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
9085 | { | |
9086 | int is_this = 0; | |
9087 | struct dwarf2_cu *arg_cu = cu; | |
9088 | const char *name = dwarf2_name (child_die, cu); | |
9089 | ||
9090 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
9091 | if (attr) | |
9092 | { | |
9093 | /* If the compiler emits this, use it. */ | |
9094 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
9095 | is_this = 1; | |
9096 | } | |
9097 | else if (name && strcmp (name, "this") == 0) | |
9098 | /* Function definitions will have the argument names. */ | |
9099 | is_this = 1; | |
9100 | else if (name == NULL && iparams == 0) | |
9101 | /* Declarations may not have the names, so like | |
9102 | elsewhere in GDB, assume an artificial first | |
9103 | argument is "this". */ | |
9104 | is_this = 1; | |
9105 | ||
9106 | if (is_this) | |
9107 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
9108 | arg_type, 0); | |
9109 | } | |
9110 | ||
9111 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
9112 | iparams++; |
9113 | } | |
9114 | child_die = sibling_die (child_die); | |
9115 | } | |
9116 | } | |
9117 | ||
76c10ea2 | 9118 | return ftype; |
c906108c SS |
9119 | } |
9120 | ||
f792889a | 9121 | static struct type * |
e7c27a73 | 9122 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9123 | { |
e7c27a73 | 9124 | struct objfile *objfile = cu->objfile; |
0114d602 | 9125 | const char *name = NULL; |
3c8e0968 | 9126 | struct type *this_type, *target_type; |
c906108c | 9127 | |
94af9270 | 9128 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 9129 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
9130 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
9131 | TYPE_NAME (this_type) = (char *) name; | |
f792889a | 9132 | set_die_type (die, this_type, cu); |
3c8e0968 DE |
9133 | target_type = die_type (die, cu); |
9134 | if (target_type != this_type) | |
9135 | TYPE_TARGET_TYPE (this_type) = target_type; | |
9136 | else | |
9137 | { | |
9138 | /* Self-referential typedefs are, it seems, not allowed by the DWARF | |
9139 | spec and cause infinite loops in GDB. */ | |
9140 | complaint (&symfile_complaints, | |
9141 | _("Self-referential DW_TAG_typedef " | |
9142 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 9143 | die->offset.sect_off, objfile->name); |
3c8e0968 DE |
9144 | TYPE_TARGET_TYPE (this_type) = NULL; |
9145 | } | |
f792889a | 9146 | return this_type; |
c906108c SS |
9147 | } |
9148 | ||
9149 | /* Find a representation of a given base type and install | |
9150 | it in the TYPE field of the die. */ | |
9151 | ||
f792889a | 9152 | static struct type * |
e7c27a73 | 9153 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9154 | { |
e7c27a73 | 9155 | struct objfile *objfile = cu->objfile; |
c906108c SS |
9156 | struct type *type; |
9157 | struct attribute *attr; | |
9158 | int encoding = 0, size = 0; | |
39cbfefa | 9159 | char *name; |
6ccb9162 UW |
9160 | enum type_code code = TYPE_CODE_INT; |
9161 | int type_flags = 0; | |
9162 | struct type *target_type = NULL; | |
c906108c | 9163 | |
e142c38c | 9164 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
9165 | if (attr) |
9166 | { | |
9167 | encoding = DW_UNSND (attr); | |
9168 | } | |
e142c38c | 9169 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
9170 | if (attr) |
9171 | { | |
9172 | size = DW_UNSND (attr); | |
9173 | } | |
39cbfefa | 9174 | name = dwarf2_name (die, cu); |
6ccb9162 | 9175 | if (!name) |
c906108c | 9176 | { |
6ccb9162 UW |
9177 | complaint (&symfile_complaints, |
9178 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 9179 | } |
6ccb9162 UW |
9180 | |
9181 | switch (encoding) | |
c906108c | 9182 | { |
6ccb9162 UW |
9183 | case DW_ATE_address: |
9184 | /* Turn DW_ATE_address into a void * pointer. */ | |
9185 | code = TYPE_CODE_PTR; | |
9186 | type_flags |= TYPE_FLAG_UNSIGNED; | |
9187 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
9188 | break; | |
9189 | case DW_ATE_boolean: | |
9190 | code = TYPE_CODE_BOOL; | |
9191 | type_flags |= TYPE_FLAG_UNSIGNED; | |
9192 | break; | |
9193 | case DW_ATE_complex_float: | |
9194 | code = TYPE_CODE_COMPLEX; | |
9195 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
9196 | break; | |
9197 | case DW_ATE_decimal_float: | |
9198 | code = TYPE_CODE_DECFLOAT; | |
9199 | break; | |
9200 | case DW_ATE_float: | |
9201 | code = TYPE_CODE_FLT; | |
9202 | break; | |
9203 | case DW_ATE_signed: | |
9204 | break; | |
9205 | case DW_ATE_unsigned: | |
9206 | type_flags |= TYPE_FLAG_UNSIGNED; | |
3b2b8fea TT |
9207 | if (cu->language == language_fortran |
9208 | && name | |
9209 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) | |
9210 | code = TYPE_CODE_CHAR; | |
6ccb9162 UW |
9211 | break; |
9212 | case DW_ATE_signed_char: | |
6e70227d | 9213 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
9214 | || cu->language == language_pascal |
9215 | || cu->language == language_fortran) | |
6ccb9162 UW |
9216 | code = TYPE_CODE_CHAR; |
9217 | break; | |
9218 | case DW_ATE_unsigned_char: | |
868a0084 | 9219 | if (cu->language == language_ada || cu->language == language_m2 |
3b2b8fea TT |
9220 | || cu->language == language_pascal |
9221 | || cu->language == language_fortran) | |
6ccb9162 UW |
9222 | code = TYPE_CODE_CHAR; |
9223 | type_flags |= TYPE_FLAG_UNSIGNED; | |
9224 | break; | |
75079b2b TT |
9225 | case DW_ATE_UTF: |
9226 | /* We just treat this as an integer and then recognize the | |
9227 | type by name elsewhere. */ | |
9228 | break; | |
9229 | ||
6ccb9162 UW |
9230 | default: |
9231 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
9232 | dwarf_type_encoding_name (encoding)); | |
9233 | break; | |
c906108c | 9234 | } |
6ccb9162 | 9235 | |
0114d602 DJ |
9236 | type = init_type (code, size, type_flags, NULL, objfile); |
9237 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
9238 | TYPE_TARGET_TYPE (type) = target_type; |
9239 | ||
0114d602 | 9240 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 9241 | TYPE_NOSIGN (type) = 1; |
0114d602 | 9242 | |
f792889a | 9243 | return set_die_type (die, type, cu); |
c906108c SS |
9244 | } |
9245 | ||
a02abb62 JB |
9246 | /* Read the given DW_AT_subrange DIE. */ |
9247 | ||
f792889a | 9248 | static struct type * |
a02abb62 JB |
9249 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
9250 | { | |
9251 | struct type *base_type; | |
9252 | struct type *range_type; | |
9253 | struct attribute *attr; | |
4fae6e18 JK |
9254 | LONGEST low, high; |
9255 | int low_default_is_valid; | |
39cbfefa | 9256 | char *name; |
43bbcdc2 | 9257 | LONGEST negative_mask; |
e77813c8 | 9258 | |
a02abb62 | 9259 | base_type = die_type (die, cu); |
953ac07e JK |
9260 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
9261 | check_typedef (base_type); | |
a02abb62 | 9262 | |
7e314c57 JK |
9263 | /* The die_type call above may have already set the type for this DIE. */ |
9264 | range_type = get_die_type (die, cu); | |
9265 | if (range_type) | |
9266 | return range_type; | |
9267 | ||
4fae6e18 JK |
9268 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
9269 | omitting DW_AT_lower_bound. */ | |
9270 | switch (cu->language) | |
6e70227d | 9271 | { |
4fae6e18 JK |
9272 | case language_c: |
9273 | case language_cplus: | |
9274 | low = 0; | |
9275 | low_default_is_valid = 1; | |
9276 | break; | |
9277 | case language_fortran: | |
9278 | low = 1; | |
9279 | low_default_is_valid = 1; | |
9280 | break; | |
9281 | case language_d: | |
9282 | case language_java: | |
9283 | case language_objc: | |
9284 | low = 0; | |
9285 | low_default_is_valid = (cu->header.version >= 4); | |
9286 | break; | |
9287 | case language_ada: | |
9288 | case language_m2: | |
9289 | case language_pascal: | |
a02abb62 | 9290 | low = 1; |
4fae6e18 JK |
9291 | low_default_is_valid = (cu->header.version >= 4); |
9292 | break; | |
9293 | default: | |
9294 | low = 0; | |
9295 | low_default_is_valid = 0; | |
9296 | break; | |
a02abb62 JB |
9297 | } |
9298 | ||
dd5e6932 DJ |
9299 | /* FIXME: For variable sized arrays either of these could be |
9300 | a variable rather than a constant value. We'll allow it, | |
9301 | but we don't know how to handle it. */ | |
e142c38c | 9302 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 | 9303 | if (attr) |
4fae6e18 JK |
9304 | low = dwarf2_get_attr_constant_value (attr, low); |
9305 | else if (!low_default_is_valid) | |
9306 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " | |
9307 | "- DIE at 0x%x [in module %s]"), | |
9308 | die->offset.sect_off, cu->objfile->name); | |
a02abb62 | 9309 | |
e142c38c | 9310 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 9311 | if (attr) |
6e70227d | 9312 | { |
d48323d8 | 9313 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
a02abb62 JB |
9314 | { |
9315 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 9316 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
9317 | FIXME: GDB does not yet know how to handle dynamic |
9318 | arrays properly, treat them as arrays with unspecified | |
9319 | length for now. | |
9320 | ||
9321 | FIXME: jimb/2003-09-22: GDB does not really know | |
9322 | how to handle arrays of unspecified length | |
9323 | either; we just represent them as zero-length | |
9324 | arrays. Choose an appropriate upper bound given | |
9325 | the lower bound we've computed above. */ | |
9326 | high = low - 1; | |
9327 | } | |
9328 | else | |
9329 | high = dwarf2_get_attr_constant_value (attr, 1); | |
9330 | } | |
e77813c8 PM |
9331 | else |
9332 | { | |
9333 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
9334 | if (attr) | |
9335 | { | |
9336 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
9337 | high = low + count - 1; | |
9338 | } | |
c2ff108b JK |
9339 | else |
9340 | { | |
9341 | /* Unspecified array length. */ | |
9342 | high = low - 1; | |
9343 | } | |
e77813c8 PM |
9344 | } |
9345 | ||
9346 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
9347 | without specifying a base type. | |
9348 | In that case, the base type must be set to the type of | |
9349 | the lower bound, upper bound or count, in that order, if any of these | |
9350 | three attributes references an object that has a type. | |
9351 | If no base type is found, the Dwarf-2 specifications say that | |
9352 | a signed integer type of size equal to the size of an address should | |
9353 | be used. | |
9354 | For the following C code: `extern char gdb_int [];' | |
9355 | GCC produces an empty range DIE. | |
9356 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 9357 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
9358 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
9359 | { | |
9360 | struct objfile *objfile = cu->objfile; | |
9361 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
9362 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
9363 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
9364 | ||
9365 | /* Test "int", "long int", and "long long int" objfile types, | |
9366 | and select the first one having a size above or equal to the | |
9367 | architecture address size. */ | |
9368 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9369 | base_type = int_type; | |
9370 | else | |
9371 | { | |
9372 | int_type = objfile_type (objfile)->builtin_long; | |
9373 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9374 | base_type = int_type; | |
9375 | else | |
9376 | { | |
9377 | int_type = objfile_type (objfile)->builtin_long_long; | |
9378 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
9379 | base_type = int_type; | |
9380 | } | |
9381 | } | |
9382 | } | |
a02abb62 | 9383 | |
6e70227d | 9384 | negative_mask = |
43bbcdc2 PH |
9385 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
9386 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
9387 | low |= negative_mask; | |
9388 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
9389 | high |= negative_mask; | |
9390 | ||
a02abb62 JB |
9391 | range_type = create_range_type (NULL, base_type, low, high); |
9392 | ||
bbb0eef6 JK |
9393 | /* Mark arrays with dynamic length at least as an array of unspecified |
9394 | length. GDB could check the boundary but before it gets implemented at | |
9395 | least allow accessing the array elements. */ | |
d48323d8 | 9396 | if (attr && attr_form_is_block (attr)) |
bbb0eef6 JK |
9397 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
9398 | ||
c2ff108b JK |
9399 | /* Ada expects an empty array on no boundary attributes. */ |
9400 | if (attr == NULL && cu->language != language_ada) | |
9401 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
9402 | ||
39cbfefa DJ |
9403 | name = dwarf2_name (die, cu); |
9404 | if (name) | |
9405 | TYPE_NAME (range_type) = name; | |
6e70227d | 9406 | |
e142c38c | 9407 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
9408 | if (attr) |
9409 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
9410 | ||
7e314c57 JK |
9411 | set_die_type (die, range_type, cu); |
9412 | ||
9413 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
9414 | set_descriptive_type (range_type, die, cu); |
9415 | ||
7e314c57 | 9416 | return range_type; |
a02abb62 | 9417 | } |
6e70227d | 9418 | |
f792889a | 9419 | static struct type * |
81a17f79 JB |
9420 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
9421 | { | |
9422 | struct type *type; | |
81a17f79 | 9423 | |
81a17f79 JB |
9424 | /* For now, we only support the C meaning of an unspecified type: void. */ |
9425 | ||
0114d602 DJ |
9426 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
9427 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 9428 | |
f792889a | 9429 | return set_die_type (die, type, cu); |
81a17f79 | 9430 | } |
a02abb62 | 9431 | |
639d11d3 DC |
9432 | /* Read a single die and all its descendents. Set the die's sibling |
9433 | field to NULL; set other fields in the die correctly, and set all | |
9434 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
9435 | location of the info_ptr after reading all of those dies. PARENT | |
9436 | is the parent of the die in question. */ | |
9437 | ||
9438 | static struct die_info * | |
dee91e82 DE |
9439 | read_die_and_children (const struct die_reader_specs *reader, |
9440 | gdb_byte *info_ptr, | |
9441 | gdb_byte **new_info_ptr, | |
9442 | struct die_info *parent) | |
639d11d3 DC |
9443 | { |
9444 | struct die_info *die; | |
fe1b8b76 | 9445 | gdb_byte *cur_ptr; |
639d11d3 DC |
9446 | int has_children; |
9447 | ||
93311388 | 9448 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
9449 | if (die == NULL) |
9450 | { | |
9451 | *new_info_ptr = cur_ptr; | |
9452 | return NULL; | |
9453 | } | |
93311388 | 9454 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
9455 | |
9456 | if (has_children) | |
348e048f | 9457 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
9458 | else |
9459 | { | |
9460 | die->child = NULL; | |
9461 | *new_info_ptr = cur_ptr; | |
9462 | } | |
9463 | ||
9464 | die->sibling = NULL; | |
9465 | die->parent = parent; | |
9466 | return die; | |
9467 | } | |
9468 | ||
9469 | /* Read a die, all of its descendents, and all of its siblings; set | |
9470 | all of the fields of all of the dies correctly. Arguments are as | |
9471 | in read_die_and_children. */ | |
9472 | ||
9473 | static struct die_info * | |
93311388 DE |
9474 | read_die_and_siblings (const struct die_reader_specs *reader, |
9475 | gdb_byte *info_ptr, | |
fe1b8b76 | 9476 | gdb_byte **new_info_ptr, |
639d11d3 DC |
9477 | struct die_info *parent) |
9478 | { | |
9479 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 9480 | gdb_byte *cur_ptr; |
639d11d3 | 9481 | |
c906108c | 9482 | cur_ptr = info_ptr; |
639d11d3 DC |
9483 | first_die = last_sibling = NULL; |
9484 | ||
9485 | while (1) | |
c906108c | 9486 | { |
639d11d3 | 9487 | struct die_info *die |
dee91e82 | 9488 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 9489 | |
1d325ec1 | 9490 | if (die == NULL) |
c906108c | 9491 | { |
639d11d3 DC |
9492 | *new_info_ptr = cur_ptr; |
9493 | return first_die; | |
c906108c | 9494 | } |
1d325ec1 DJ |
9495 | |
9496 | if (!first_die) | |
9497 | first_die = die; | |
c906108c | 9498 | else |
1d325ec1 DJ |
9499 | last_sibling->sibling = die; |
9500 | ||
9501 | last_sibling = die; | |
c906108c | 9502 | } |
c906108c SS |
9503 | } |
9504 | ||
93311388 DE |
9505 | /* Read the die from the .debug_info section buffer. Set DIEP to |
9506 | point to a newly allocated die with its information, except for its | |
9507 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
9508 | whether the die has children or not. */ | |
9509 | ||
9510 | static gdb_byte * | |
9511 | read_full_die (const struct die_reader_specs *reader, | |
9512 | struct die_info **diep, gdb_byte *info_ptr, | |
9513 | int *has_children) | |
9514 | { | |
b64f50a1 JK |
9515 | unsigned int abbrev_number, bytes_read, i; |
9516 | sect_offset offset; | |
93311388 DE |
9517 | struct abbrev_info *abbrev; |
9518 | struct die_info *die; | |
9519 | struct dwarf2_cu *cu = reader->cu; | |
9520 | bfd *abfd = reader->abfd; | |
9521 | ||
b64f50a1 | 9522 | offset.sect_off = info_ptr - reader->buffer; |
93311388 DE |
9523 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9524 | info_ptr += bytes_read; | |
9525 | if (!abbrev_number) | |
9526 | { | |
9527 | *diep = NULL; | |
9528 | *has_children = 0; | |
9529 | return info_ptr; | |
9530 | } | |
9531 | ||
9532 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
9533 | if (!abbrev) | |
348e048f DE |
9534 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
9535 | abbrev_number, | |
9536 | bfd_get_filename (abfd)); | |
9537 | ||
93311388 DE |
9538 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
9539 | die->offset = offset; | |
9540 | die->tag = abbrev->tag; | |
9541 | die->abbrev = abbrev_number; | |
9542 | ||
9543 | die->num_attrs = abbrev->num_attrs; | |
9544 | ||
9545 | for (i = 0; i < abbrev->num_attrs; ++i) | |
dee91e82 DE |
9546 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
9547 | info_ptr); | |
93311388 DE |
9548 | |
9549 | *diep = die; | |
9550 | *has_children = abbrev->has_children; | |
9551 | return info_ptr; | |
9552 | } | |
9553 | ||
c906108c SS |
9554 | /* In DWARF version 2, the description of the debugging information is |
9555 | stored in a separate .debug_abbrev section. Before we read any | |
9556 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
9557 | in a hash table. This function also sets flags in CU describing |
9558 | the data found in the abbrev table. */ | |
c906108c SS |
9559 | |
9560 | static void | |
dee91e82 DE |
9561 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, |
9562 | struct dwarf2_section_info *abbrev_section) | |
9563 | ||
c906108c | 9564 | { |
dee91e82 | 9565 | bfd *abfd = abbrev_section->asection->owner; |
e7c27a73 | 9566 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 9567 | gdb_byte *abbrev_ptr; |
c906108c SS |
9568 | struct abbrev_info *cur_abbrev; |
9569 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
9570 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
9571 | struct attr_abbrev *cur_attrs; |
9572 | unsigned int allocated_attrs; | |
c906108c | 9573 | |
0963b4bd | 9574 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
9575 | obstack_init (&cu->abbrev_obstack); |
9576 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
9577 | (ABBREV_HASH_SIZE | |
9578 | * sizeof (struct abbrev_info *))); | |
9579 | memset (cu->dwarf2_abbrevs, 0, | |
9580 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 9581 | |
dee91e82 DE |
9582 | dwarf2_read_section (cu->objfile, abbrev_section); |
9583 | abbrev_ptr = abbrev_section->buffer + cu_header->abbrev_offset.sect_off; | |
c906108c SS |
9584 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9585 | abbrev_ptr += bytes_read; | |
9586 | ||
f3dd6933 DJ |
9587 | allocated_attrs = ATTR_ALLOC_CHUNK; |
9588 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 9589 | |
0963b4bd | 9590 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
9591 | while (abbrev_number) |
9592 | { | |
f3dd6933 | 9593 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
9594 | |
9595 | /* read in abbrev header */ | |
9596 | cur_abbrev->number = abbrev_number; | |
9597 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9598 | abbrev_ptr += bytes_read; | |
9599 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
9600 | abbrev_ptr += 1; | |
9601 | ||
9602 | /* now read in declarations */ | |
9603 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9604 | abbrev_ptr += bytes_read; | |
9605 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9606 | abbrev_ptr += bytes_read; | |
9607 | while (abbrev_name) | |
9608 | { | |
f3dd6933 | 9609 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 9610 | { |
f3dd6933 DJ |
9611 | allocated_attrs += ATTR_ALLOC_CHUNK; |
9612 | cur_attrs | |
9613 | = xrealloc (cur_attrs, (allocated_attrs | |
9614 | * sizeof (struct attr_abbrev))); | |
c906108c | 9615 | } |
ae038cb0 | 9616 | |
f3dd6933 DJ |
9617 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
9618 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
9619 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
9620 | abbrev_ptr += bytes_read; | |
9621 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9622 | abbrev_ptr += bytes_read; | |
9623 | } | |
9624 | ||
f3dd6933 DJ |
9625 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
9626 | (cur_abbrev->num_attrs | |
9627 | * sizeof (struct attr_abbrev))); | |
9628 | memcpy (cur_abbrev->attrs, cur_attrs, | |
9629 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
9630 | ||
c906108c | 9631 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
9632 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
9633 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
9634 | |
9635 | /* Get next abbreviation. | |
9636 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
9637 | always properly terminated with an abbrev number of 0. |
9638 | Exit loop if we encounter an abbreviation which we have | |
9639 | already read (which means we are about to read the abbreviations | |
9640 | for the next compile unit) or if the end of the abbreviation | |
9641 | table is reached. */ | |
dee91e82 DE |
9642 | if ((unsigned int) (abbrev_ptr - abbrev_section->buffer) |
9643 | >= abbrev_section->size) | |
c906108c SS |
9644 | break; |
9645 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
9646 | abbrev_ptr += bytes_read; | |
e7c27a73 | 9647 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
9648 | break; |
9649 | } | |
f3dd6933 DJ |
9650 | |
9651 | xfree (cur_attrs); | |
c906108c SS |
9652 | } |
9653 | ||
f3dd6933 | 9654 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 9655 | |
c906108c | 9656 | static void |
f3dd6933 | 9657 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 9658 | { |
f3dd6933 | 9659 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 9660 | |
f3dd6933 DJ |
9661 | obstack_free (&cu->abbrev_obstack, NULL); |
9662 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
9663 | } |
9664 | ||
9665 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
9666 | ||
9667 | static struct abbrev_info * | |
e7c27a73 | 9668 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
9669 | { |
9670 | unsigned int hash_number; | |
9671 | struct abbrev_info *abbrev; | |
9672 | ||
9673 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 9674 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
9675 | |
9676 | while (abbrev) | |
9677 | { | |
9678 | if (abbrev->number == number) | |
9679 | return abbrev; | |
9680 | else | |
9681 | abbrev = abbrev->next; | |
9682 | } | |
9683 | return NULL; | |
9684 | } | |
9685 | ||
72bf9492 DJ |
9686 | /* Returns nonzero if TAG represents a type that we might generate a partial |
9687 | symbol for. */ | |
9688 | ||
9689 | static int | |
9690 | is_type_tag_for_partial (int tag) | |
9691 | { | |
9692 | switch (tag) | |
9693 | { | |
9694 | #if 0 | |
9695 | /* Some types that would be reasonable to generate partial symbols for, | |
9696 | that we don't at present. */ | |
9697 | case DW_TAG_array_type: | |
9698 | case DW_TAG_file_type: | |
9699 | case DW_TAG_ptr_to_member_type: | |
9700 | case DW_TAG_set_type: | |
9701 | case DW_TAG_string_type: | |
9702 | case DW_TAG_subroutine_type: | |
9703 | #endif | |
9704 | case DW_TAG_base_type: | |
9705 | case DW_TAG_class_type: | |
680b30c7 | 9706 | case DW_TAG_interface_type: |
72bf9492 DJ |
9707 | case DW_TAG_enumeration_type: |
9708 | case DW_TAG_structure_type: | |
9709 | case DW_TAG_subrange_type: | |
9710 | case DW_TAG_typedef: | |
9711 | case DW_TAG_union_type: | |
9712 | return 1; | |
9713 | default: | |
9714 | return 0; | |
9715 | } | |
9716 | } | |
9717 | ||
9718 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
9719 | ||
9720 | static struct partial_die_info * | |
dee91e82 DE |
9721 | load_partial_dies (const struct die_reader_specs *reader, |
9722 | gdb_byte *info_ptr, int building_psymtab) | |
72bf9492 | 9723 | { |
dee91e82 | 9724 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 9725 | struct objfile *objfile = cu->objfile; |
72bf9492 DJ |
9726 | struct partial_die_info *part_die; |
9727 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
9728 | struct abbrev_info *abbrev; | |
9729 | unsigned int bytes_read; | |
5afb4e99 | 9730 | unsigned int load_all = 0; |
72bf9492 DJ |
9731 | int nesting_level = 1; |
9732 | ||
9733 | parent_die = NULL; | |
9734 | last_die = NULL; | |
9735 | ||
7adf1e79 DE |
9736 | gdb_assert (cu->per_cu != NULL); |
9737 | if (cu->per_cu->load_all_dies) | |
5afb4e99 DJ |
9738 | load_all = 1; |
9739 | ||
72bf9492 DJ |
9740 | cu->partial_dies |
9741 | = htab_create_alloc_ex (cu->header.length / 12, | |
9742 | partial_die_hash, | |
9743 | partial_die_eq, | |
9744 | NULL, | |
9745 | &cu->comp_unit_obstack, | |
9746 | hashtab_obstack_allocate, | |
9747 | dummy_obstack_deallocate); | |
9748 | ||
9749 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9750 | sizeof (struct partial_die_info)); | |
9751 | ||
9752 | while (1) | |
9753 | { | |
9754 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
9755 | ||
9756 | /* A NULL abbrev means the end of a series of children. */ | |
9757 | if (abbrev == NULL) | |
9758 | { | |
9759 | if (--nesting_level == 0) | |
9760 | { | |
9761 | /* PART_DIE was probably the last thing allocated on the | |
9762 | comp_unit_obstack, so we could call obstack_free | |
9763 | here. We don't do that because the waste is small, | |
9764 | and will be cleaned up when we're done with this | |
9765 | compilation unit. This way, we're also more robust | |
9766 | against other users of the comp_unit_obstack. */ | |
9767 | return first_die; | |
9768 | } | |
9769 | info_ptr += bytes_read; | |
9770 | last_die = parent_die; | |
9771 | parent_die = parent_die->die_parent; | |
9772 | continue; | |
9773 | } | |
9774 | ||
98bfdba5 PA |
9775 | /* Check for template arguments. We never save these; if |
9776 | they're seen, we just mark the parent, and go on our way. */ | |
9777 | if (parent_die != NULL | |
9778 | && cu->language == language_cplus | |
9779 | && (abbrev->tag == DW_TAG_template_type_param | |
9780 | || abbrev->tag == DW_TAG_template_value_param)) | |
9781 | { | |
9782 | parent_die->has_template_arguments = 1; | |
9783 | ||
9784 | if (!load_all) | |
9785 | { | |
9786 | /* We don't need a partial DIE for the template argument. */ | |
dee91e82 | 9787 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
9788 | continue; |
9789 | } | |
9790 | } | |
9791 | ||
0d99eb77 | 9792 | /* We only recurse into c++ subprograms looking for template arguments. |
98bfdba5 PA |
9793 | Skip their other children. */ |
9794 | if (!load_all | |
9795 | && cu->language == language_cplus | |
9796 | && parent_die != NULL | |
9797 | && parent_die->tag == DW_TAG_subprogram) | |
9798 | { | |
dee91e82 | 9799 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
98bfdba5 PA |
9800 | continue; |
9801 | } | |
9802 | ||
5afb4e99 DJ |
9803 | /* Check whether this DIE is interesting enough to save. Normally |
9804 | we would not be interested in members here, but there may be | |
9805 | later variables referencing them via DW_AT_specification (for | |
9806 | static members). */ | |
9807 | if (!load_all | |
9808 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 9809 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
9810 | && abbrev->tag != DW_TAG_enumerator |
9811 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 9812 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 9813 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 9814 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 9815 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 9816 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
9817 | { |
9818 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 9819 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
72bf9492 DJ |
9820 | continue; |
9821 | } | |
9822 | ||
dee91e82 DE |
9823 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
9824 | info_ptr); | |
72bf9492 DJ |
9825 | |
9826 | /* This two-pass algorithm for processing partial symbols has a | |
9827 | high cost in cache pressure. Thus, handle some simple cases | |
9828 | here which cover the majority of C partial symbols. DIEs | |
9829 | which neither have specification tags in them, nor could have | |
9830 | specification tags elsewhere pointing at them, can simply be | |
9831 | processed and discarded. | |
9832 | ||
9833 | This segment is also optional; scan_partial_symbols and | |
9834 | add_partial_symbol will handle these DIEs if we chain | |
9835 | them in normally. When compilers which do not emit large | |
9836 | quantities of duplicate debug information are more common, | |
9837 | this code can probably be removed. */ | |
9838 | ||
9839 | /* Any complete simple types at the top level (pretty much all | |
9840 | of them, for a language without namespaces), can be processed | |
9841 | directly. */ | |
9842 | if (parent_die == NULL | |
9843 | && part_die->has_specification == 0 | |
9844 | && part_die->is_declaration == 0 | |
d8228535 | 9845 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
72bf9492 DJ |
9846 | || part_die->tag == DW_TAG_base_type |
9847 | || part_die->tag == DW_TAG_subrange_type)) | |
9848 | { | |
9849 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 9850 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9851 | VAR_DOMAIN, LOC_TYPEDEF, |
bb5ed363 DE |
9852 | &objfile->static_psymbols, |
9853 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
dee91e82 | 9854 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
9855 | continue; |
9856 | } | |
9857 | ||
d8228535 JK |
9858 | /* The exception for DW_TAG_typedef with has_children above is |
9859 | a workaround of GCC PR debug/47510. In the case of this complaint | |
9860 | type_name_no_tag_or_error will error on such types later. | |
9861 | ||
9862 | GDB skipped children of DW_TAG_typedef by the shortcut above and then | |
9863 | it could not find the child DIEs referenced later, this is checked | |
9864 | above. In correct DWARF DW_TAG_typedef should have no children. */ | |
9865 | ||
9866 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) | |
9867 | complaint (&symfile_complaints, | |
9868 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " | |
9869 | "- DIE at 0x%x [in module %s]"), | |
b64f50a1 | 9870 | part_die->offset.sect_off, objfile->name); |
d8228535 | 9871 | |
72bf9492 DJ |
9872 | /* If we're at the second level, and we're an enumerator, and |
9873 | our parent has no specification (meaning possibly lives in a | |
9874 | namespace elsewhere), then we can add the partial symbol now | |
9875 | instead of queueing it. */ | |
9876 | if (part_die->tag == DW_TAG_enumerator | |
9877 | && parent_die != NULL | |
9878 | && parent_die->die_parent == NULL | |
9879 | && parent_die->tag == DW_TAG_enumeration_type | |
9880 | && parent_die->has_specification == 0) | |
9881 | { | |
9882 | if (part_die->name == NULL) | |
3e43a32a MS |
9883 | complaint (&symfile_complaints, |
9884 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 9885 | else if (building_psymtab) |
04a679b8 | 9886 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 9887 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
9888 | (cu->language == language_cplus |
9889 | || cu->language == language_java) | |
bb5ed363 DE |
9890 | ? &objfile->global_psymbols |
9891 | : &objfile->static_psymbols, | |
9892 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
72bf9492 | 9893 | |
dee91e82 | 9894 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
72bf9492 DJ |
9895 | continue; |
9896 | } | |
9897 | ||
9898 | /* We'll save this DIE so link it in. */ | |
9899 | part_die->die_parent = parent_die; | |
9900 | part_die->die_sibling = NULL; | |
9901 | part_die->die_child = NULL; | |
9902 | ||
9903 | if (last_die && last_die == parent_die) | |
9904 | last_die->die_child = part_die; | |
9905 | else if (last_die) | |
9906 | last_die->die_sibling = part_die; | |
9907 | ||
9908 | last_die = part_die; | |
9909 | ||
9910 | if (first_die == NULL) | |
9911 | first_die = part_die; | |
9912 | ||
9913 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
9914 | find interesting need to be in the hash table, because we | |
9915 | also have the parent/sibling/child chains; only those that we | |
9916 | might refer to by offset later during partial symbol reading. | |
9917 | ||
9918 | For now this means things that might have be the target of a | |
9919 | DW_AT_specification, DW_AT_abstract_origin, or | |
9920 | DW_AT_extension. DW_AT_extension will refer only to | |
9921 | namespaces; DW_AT_abstract_origin refers to functions (and | |
9922 | many things under the function DIE, but we do not recurse | |
9923 | into function DIEs during partial symbol reading) and | |
9924 | possibly variables as well; DW_AT_specification refers to | |
9925 | declarations. Declarations ought to have the DW_AT_declaration | |
9926 | flag. It happens that GCC forgets to put it in sometimes, but | |
9927 | only for functions, not for types. | |
9928 | ||
9929 | Adding more things than necessary to the hash table is harmless | |
9930 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
9931 | wasted time in find_partial_die, when we reread the compilation |
9932 | unit with load_all_dies set. */ | |
72bf9492 | 9933 | |
5afb4e99 | 9934 | if (load_all |
72929c62 | 9935 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 9936 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
9937 | || abbrev->tag == DW_TAG_variable |
9938 | || abbrev->tag == DW_TAG_namespace | |
9939 | || part_die->is_declaration) | |
9940 | { | |
9941 | void **slot; | |
9942 | ||
9943 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
b64f50a1 | 9944 | part_die->offset.sect_off, INSERT); |
72bf9492 DJ |
9945 | *slot = part_die; |
9946 | } | |
9947 | ||
9948 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
9949 | sizeof (struct partial_die_info)); | |
9950 | ||
9951 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 9952 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
9953 | languages we have to, so that we can get at method physnames |
9954 | to infer fully qualified class names, for DW_AT_specification, | |
9955 | and for C++ template arguments. For C++, we also look one level | |
9956 | inside functions to find template arguments (if the name of the | |
9957 | function does not already contain the template arguments). | |
bc30ff58 JB |
9958 | |
9959 | For Ada, we need to scan the children of subprograms and lexical | |
9960 | blocks as well because Ada allows the definition of nested | |
9961 | entities that could be interesting for the debugger, such as | |
9962 | nested subprograms for instance. */ | |
72bf9492 | 9963 | if (last_die->has_children |
5afb4e99 DJ |
9964 | && (load_all |
9965 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 9966 | || last_die->tag == DW_TAG_module |
72bf9492 | 9967 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
9968 | || (cu->language == language_cplus |
9969 | && last_die->tag == DW_TAG_subprogram | |
9970 | && (last_die->name == NULL | |
9971 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
9972 | || (cu->language != language_c |
9973 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 9974 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 9975 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
9976 | || last_die->tag == DW_TAG_union_type)) |
9977 | || (cu->language == language_ada | |
9978 | && (last_die->tag == DW_TAG_subprogram | |
9979 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9980 | { |
9981 | nesting_level++; | |
9982 | parent_die = last_die; | |
9983 | continue; | |
9984 | } | |
9985 | ||
9986 | /* Otherwise we skip to the next sibling, if any. */ | |
dee91e82 | 9987 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
72bf9492 DJ |
9988 | |
9989 | /* Back to the top, do it again. */ | |
9990 | } | |
9991 | } | |
9992 | ||
c906108c SS |
9993 | /* Read a minimal amount of information into the minimal die structure. */ |
9994 | ||
fe1b8b76 | 9995 | static gdb_byte * |
dee91e82 DE |
9996 | read_partial_die (const struct die_reader_specs *reader, |
9997 | struct partial_die_info *part_die, | |
9998 | struct abbrev_info *abbrev, unsigned int abbrev_len, | |
9999 | gdb_byte *info_ptr) | |
c906108c | 10000 | { |
dee91e82 | 10001 | struct dwarf2_cu *cu = reader->cu; |
bb5ed363 | 10002 | struct objfile *objfile = cu->objfile; |
dee91e82 | 10003 | gdb_byte *buffer = reader->buffer; |
fa238c03 | 10004 | unsigned int i; |
c906108c | 10005 | struct attribute attr; |
c5aa993b | 10006 | int has_low_pc_attr = 0; |
c906108c | 10007 | int has_high_pc_attr = 0; |
91da1414 | 10008 | int high_pc_relative = 0; |
c906108c | 10009 | |
72bf9492 | 10010 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 10011 | |
b64f50a1 | 10012 | part_die->offset.sect_off = info_ptr - buffer; |
72bf9492 DJ |
10013 | |
10014 | info_ptr += abbrev_len; | |
10015 | ||
10016 | if (abbrev == NULL) | |
10017 | return info_ptr; | |
10018 | ||
c906108c SS |
10019 | part_die->tag = abbrev->tag; |
10020 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
10021 | |
10022 | for (i = 0; i < abbrev->num_attrs; ++i) | |
10023 | { | |
dee91e82 | 10024 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
c906108c SS |
10025 | |
10026 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 10027 | partial symbol table. */ |
c906108c SS |
10028 | switch (attr.name) |
10029 | { | |
10030 | case DW_AT_name: | |
71c25dea TT |
10031 | switch (part_die->tag) |
10032 | { | |
10033 | case DW_TAG_compile_unit: | |
348e048f | 10034 | case DW_TAG_type_unit: |
71c25dea TT |
10035 | /* Compilation units have a DW_AT_name that is a filename, not |
10036 | a source language identifier. */ | |
10037 | case DW_TAG_enumeration_type: | |
10038 | case DW_TAG_enumerator: | |
10039 | /* These tags always have simple identifiers already; no need | |
10040 | to canonicalize them. */ | |
10041 | part_die->name = DW_STRING (&attr); | |
10042 | break; | |
10043 | default: | |
10044 | part_die->name | |
10045 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
bb5ed363 | 10046 | &objfile->objfile_obstack); |
71c25dea TT |
10047 | break; |
10048 | } | |
c906108c | 10049 | break; |
31ef98ae | 10050 | case DW_AT_linkage_name: |
c906108c | 10051 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
10052 | /* Note that both forms of linkage name might appear. We |
10053 | assume they will be the same, and we only store the last | |
10054 | one we see. */ | |
94af9270 KS |
10055 | if (cu->language == language_ada) |
10056 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 10057 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
10058 | break; |
10059 | case DW_AT_low_pc: | |
10060 | has_low_pc_attr = 1; | |
10061 | part_die->lowpc = DW_ADDR (&attr); | |
10062 | break; | |
10063 | case DW_AT_high_pc: | |
10064 | has_high_pc_attr = 1; | |
91da1414 MW |
10065 | if (attr.form == DW_FORM_addr) |
10066 | part_die->highpc = DW_ADDR (&attr); | |
10067 | else | |
10068 | { | |
10069 | high_pc_relative = 1; | |
10070 | part_die->highpc = DW_UNSND (&attr); | |
10071 | } | |
c906108c SS |
10072 | break; |
10073 | case DW_AT_location: | |
0963b4bd | 10074 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
10075 | if (attr_form_is_block (&attr)) |
10076 | { | |
10077 | part_die->locdesc = DW_BLOCK (&attr); | |
10078 | } | |
3690dd37 | 10079 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 10080 | { |
4d3c2250 | 10081 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
10082 | } |
10083 | else | |
10084 | { | |
4d3c2250 KB |
10085 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
10086 | "partial symbol information"); | |
8e19ed76 | 10087 | } |
c906108c | 10088 | break; |
c906108c SS |
10089 | case DW_AT_external: |
10090 | part_die->is_external = DW_UNSND (&attr); | |
10091 | break; | |
10092 | case DW_AT_declaration: | |
10093 | part_die->is_declaration = DW_UNSND (&attr); | |
10094 | break; | |
10095 | case DW_AT_type: | |
10096 | part_die->has_type = 1; | |
10097 | break; | |
10098 | case DW_AT_abstract_origin: | |
10099 | case DW_AT_specification: | |
72bf9492 DJ |
10100 | case DW_AT_extension: |
10101 | part_die->has_specification = 1; | |
c764a876 | 10102 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
10103 | break; |
10104 | case DW_AT_sibling: | |
10105 | /* Ignore absolute siblings, they might point outside of | |
10106 | the current compile unit. */ | |
10107 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
10108 | complaint (&symfile_complaints, |
10109 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 10110 | else |
b64f50a1 | 10111 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
c906108c | 10112 | break; |
fa4028e9 JB |
10113 | case DW_AT_byte_size: |
10114 | part_die->has_byte_size = 1; | |
10115 | break; | |
68511cec CES |
10116 | case DW_AT_calling_convention: |
10117 | /* DWARF doesn't provide a way to identify a program's source-level | |
10118 | entry point. DW_AT_calling_convention attributes are only meant | |
10119 | to describe functions' calling conventions. | |
10120 | ||
10121 | However, because it's a necessary piece of information in | |
10122 | Fortran, and because DW_CC_program is the only piece of debugging | |
10123 | information whose definition refers to a 'main program' at all, | |
10124 | several compilers have begun marking Fortran main programs with | |
10125 | DW_CC_program --- even when those functions use the standard | |
10126 | calling conventions. | |
10127 | ||
10128 | So until DWARF specifies a way to provide this information and | |
10129 | compilers pick up the new representation, we'll support this | |
10130 | practice. */ | |
10131 | if (DW_UNSND (&attr) == DW_CC_program | |
10132 | && cu->language == language_fortran) | |
01f8c46d JK |
10133 | { |
10134 | set_main_name (part_die->name); | |
10135 | ||
10136 | /* As this DIE has a static linkage the name would be difficult | |
10137 | to look up later. */ | |
10138 | language_of_main = language_fortran; | |
10139 | } | |
68511cec | 10140 | break; |
481860b3 GB |
10141 | case DW_AT_inline: |
10142 | if (DW_UNSND (&attr) == DW_INL_inlined | |
10143 | || DW_UNSND (&attr) == DW_INL_declared_inlined) | |
10144 | part_die->may_be_inlined = 1; | |
10145 | break; | |
c906108c SS |
10146 | default: |
10147 | break; | |
10148 | } | |
10149 | } | |
10150 | ||
91da1414 MW |
10151 | if (high_pc_relative) |
10152 | part_die->highpc += part_die->lowpc; | |
10153 | ||
9373cf26 JK |
10154 | if (has_low_pc_attr && has_high_pc_attr) |
10155 | { | |
10156 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
10157 | eliminate duplicate copies of functions and vtables and such. | |
10158 | The linker will arbitrarily choose one and discard the others. | |
10159 | The AT_*_pc values for such functions refer to local labels in | |
10160 | these sections. If the section from that file was discarded, the | |
10161 | labels are not in the output, so the relocs get a value of 0. | |
10162 | If this is a discarded function, mark the pc bounds as invalid, | |
10163 | so that GDB will ignore it. */ | |
10164 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
10165 | { | |
bb5ed363 | 10166 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
10167 | |
10168 | complaint (&symfile_complaints, | |
10169 | _("DW_AT_low_pc %s is zero " | |
10170 | "for DIE at 0x%x [in module %s]"), | |
10171 | paddress (gdbarch, part_die->lowpc), | |
b64f50a1 | 10172 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
10173 | } |
10174 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
10175 | else if (part_die->lowpc >= part_die->highpc) | |
10176 | { | |
bb5ed363 | 10177 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
9373cf26 JK |
10178 | |
10179 | complaint (&symfile_complaints, | |
10180 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
10181 | "for DIE at 0x%x [in module %s]"), | |
10182 | paddress (gdbarch, part_die->lowpc), | |
10183 | paddress (gdbarch, part_die->highpc), | |
b64f50a1 | 10184 | part_die->offset.sect_off, objfile->name); |
9373cf26 JK |
10185 | } |
10186 | else | |
10187 | part_die->has_pc_info = 1; | |
10188 | } | |
85cbf3d3 | 10189 | |
c906108c SS |
10190 | return info_ptr; |
10191 | } | |
10192 | ||
72bf9492 DJ |
10193 | /* Find a cached partial DIE at OFFSET in CU. */ |
10194 | ||
10195 | static struct partial_die_info * | |
b64f50a1 | 10196 | find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
10197 | { |
10198 | struct partial_die_info *lookup_die = NULL; | |
10199 | struct partial_die_info part_die; | |
10200 | ||
10201 | part_die.offset = offset; | |
b64f50a1 JK |
10202 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, |
10203 | offset.sect_off); | |
72bf9492 | 10204 | |
72bf9492 DJ |
10205 | return lookup_die; |
10206 | } | |
10207 | ||
348e048f DE |
10208 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
10209 | except in the case of .debug_types DIEs which do not reference | |
10210 | outside their CU (they do however referencing other types via | |
55f1336d | 10211 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
10212 | |
10213 | static struct partial_die_info * | |
b64f50a1 | 10214 | find_partial_die (sect_offset offset, struct dwarf2_cu *cu) |
72bf9492 | 10215 | { |
bb5ed363 | 10216 | struct objfile *objfile = cu->objfile; |
5afb4e99 DJ |
10217 | struct dwarf2_per_cu_data *per_cu = NULL; |
10218 | struct partial_die_info *pd = NULL; | |
72bf9492 | 10219 | |
45452591 | 10220 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
10221 | { |
10222 | pd = find_partial_die_in_comp_unit (offset, cu); | |
10223 | if (pd != NULL) | |
10224 | return pd; | |
0d99eb77 DE |
10225 | /* We missed recording what we needed. |
10226 | Load all dies and try again. */ | |
10227 | per_cu = cu->per_cu; | |
5afb4e99 | 10228 | } |
0d99eb77 DE |
10229 | else |
10230 | { | |
10231 | /* TUs don't reference other CUs/TUs (except via type signatures). */ | |
10232 | if (cu->per_cu->debug_types_section) | |
10233 | { | |
10234 | error (_("Dwarf Error: Type Unit at offset 0x%lx contains" | |
10235 | " external reference to offset 0x%lx [in module %s].\n"), | |
10236 | (long) cu->header.offset.sect_off, (long) offset.sect_off, | |
10237 | bfd_get_filename (objfile->obfd)); | |
10238 | } | |
10239 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
72bf9492 | 10240 | |
0d99eb77 DE |
10241 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
10242 | load_partial_comp_unit (per_cu); | |
ae038cb0 | 10243 | |
0d99eb77 DE |
10244 | per_cu->cu->last_used = 0; |
10245 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
10246 | } | |
5afb4e99 | 10247 | |
dee91e82 DE |
10248 | /* If we didn't find it, and not all dies have been loaded, |
10249 | load them all and try again. */ | |
10250 | ||
5afb4e99 DJ |
10251 | if (pd == NULL && per_cu->load_all_dies == 0) |
10252 | { | |
dee91e82 DE |
10253 | /* FIXME: The testsuite doesn't trigger this code path. |
10254 | http://sourceware.org/bugzilla/show_bug.cgi?id=13961 */ | |
5afb4e99 | 10255 | |
dee91e82 | 10256 | free_one_cached_comp_unit (per_cu); |
5afb4e99 | 10257 | per_cu->load_all_dies = 1; |
dee91e82 | 10258 | load_partial_comp_unit (per_cu); |
5afb4e99 DJ |
10259 | |
10260 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
10261 | } | |
10262 | ||
10263 | if (pd == NULL) | |
10264 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
10265 | _("could not find partial DIE 0x%x " |
10266 | "in cache [from module %s]\n"), | |
b64f50a1 | 10267 | offset.sect_off, bfd_get_filename (objfile->obfd)); |
5afb4e99 | 10268 | return pd; |
72bf9492 DJ |
10269 | } |
10270 | ||
abc72ce4 DE |
10271 | /* See if we can figure out if the class lives in a namespace. We do |
10272 | this by looking for a member function; its demangled name will | |
10273 | contain namespace info, if there is any. */ | |
10274 | ||
10275 | static void | |
10276 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
10277 | struct dwarf2_cu *cu) | |
10278 | { | |
10279 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
10280 | what template types look like, because the demangler | |
10281 | frequently doesn't give the same name as the debug info. We | |
10282 | could fix this by only using the demangled name to get the | |
10283 | prefix (but see comment in read_structure_type). */ | |
10284 | ||
10285 | struct partial_die_info *real_pdi; | |
10286 | struct partial_die_info *child_pdi; | |
10287 | ||
10288 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
10289 | we should not do this. We'll prepend the parent's fully qualified | |
10290 | name when we create the partial symbol. */ | |
10291 | ||
10292 | real_pdi = struct_pdi; | |
10293 | while (real_pdi->has_specification) | |
10294 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
10295 | ||
10296 | if (real_pdi->die_parent != NULL) | |
10297 | return; | |
10298 | ||
10299 | for (child_pdi = struct_pdi->die_child; | |
10300 | child_pdi != NULL; | |
10301 | child_pdi = child_pdi->die_sibling) | |
10302 | { | |
10303 | if (child_pdi->tag == DW_TAG_subprogram | |
10304 | && child_pdi->linkage_name != NULL) | |
10305 | { | |
10306 | char *actual_class_name | |
10307 | = language_class_name_from_physname (cu->language_defn, | |
10308 | child_pdi->linkage_name); | |
10309 | if (actual_class_name != NULL) | |
10310 | { | |
10311 | struct_pdi->name | |
10312 | = obsavestring (actual_class_name, | |
10313 | strlen (actual_class_name), | |
10314 | &cu->objfile->objfile_obstack); | |
10315 | xfree (actual_class_name); | |
10316 | } | |
10317 | break; | |
10318 | } | |
10319 | } | |
10320 | } | |
10321 | ||
72bf9492 DJ |
10322 | /* Adjust PART_DIE before generating a symbol for it. This function |
10323 | may set the is_external flag or change the DIE's name. */ | |
10324 | ||
10325 | static void | |
10326 | fixup_partial_die (struct partial_die_info *part_die, | |
10327 | struct dwarf2_cu *cu) | |
10328 | { | |
abc72ce4 DE |
10329 | /* Once we've fixed up a die, there's no point in doing so again. |
10330 | This also avoids a memory leak if we were to call | |
10331 | guess_partial_die_structure_name multiple times. */ | |
10332 | if (part_die->fixup_called) | |
10333 | return; | |
10334 | ||
72bf9492 DJ |
10335 | /* If we found a reference attribute and the DIE has no name, try |
10336 | to find a name in the referred to DIE. */ | |
10337 | ||
10338 | if (part_die->name == NULL && part_die->has_specification) | |
10339 | { | |
10340 | struct partial_die_info *spec_die; | |
72bf9492 | 10341 | |
10b3939b | 10342 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 10343 | |
10b3939b | 10344 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
10345 | |
10346 | if (spec_die->name) | |
10347 | { | |
10348 | part_die->name = spec_die->name; | |
10349 | ||
10350 | /* Copy DW_AT_external attribute if it is set. */ | |
10351 | if (spec_die->is_external) | |
10352 | part_die->is_external = spec_die->is_external; | |
10353 | } | |
10354 | } | |
10355 | ||
10356 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
10357 | |
10358 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
2b1dbab0 | 10359 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
72bf9492 | 10360 | |
abc72ce4 DE |
10361 | /* If there is no parent die to provide a namespace, and there are |
10362 | children, see if we can determine the namespace from their linkage | |
122d1940 | 10363 | name. */ |
abc72ce4 | 10364 | if (cu->language == language_cplus |
8b70b953 | 10365 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
10366 | && part_die->die_parent == NULL |
10367 | && part_die->has_children | |
10368 | && (part_die->tag == DW_TAG_class_type | |
10369 | || part_die->tag == DW_TAG_structure_type | |
10370 | || part_die->tag == DW_TAG_union_type)) | |
10371 | guess_partial_die_structure_name (part_die, cu); | |
10372 | ||
53832f31 TT |
10373 | /* GCC might emit a nameless struct or union that has a linkage |
10374 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
10375 | if (part_die->name == NULL | |
96408a79 SA |
10376 | && (part_die->tag == DW_TAG_class_type |
10377 | || part_die->tag == DW_TAG_interface_type | |
10378 | || part_die->tag == DW_TAG_structure_type | |
10379 | || part_die->tag == DW_TAG_union_type) | |
53832f31 TT |
10380 | && part_die->linkage_name != NULL) |
10381 | { | |
10382 | char *demangled; | |
10383 | ||
10384 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
10385 | if (demangled) | |
10386 | { | |
96408a79 SA |
10387 | const char *base; |
10388 | ||
10389 | /* Strip any leading namespaces/classes, keep only the base name. | |
10390 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
10391 | base = strrchr (demangled, ':'); | |
10392 | if (base && base > demangled && base[-1] == ':') | |
10393 | base++; | |
10394 | else | |
10395 | base = demangled; | |
10396 | ||
10397 | part_die->name = obsavestring (base, strlen (base), | |
53832f31 TT |
10398 | &cu->objfile->objfile_obstack); |
10399 | xfree (demangled); | |
10400 | } | |
10401 | } | |
10402 | ||
abc72ce4 | 10403 | part_die->fixup_called = 1; |
72bf9492 DJ |
10404 | } |
10405 | ||
a8329558 | 10406 | /* Read an attribute value described by an attribute form. */ |
c906108c | 10407 | |
fe1b8b76 | 10408 | static gdb_byte * |
dee91e82 DE |
10409 | read_attribute_value (const struct die_reader_specs *reader, |
10410 | struct attribute *attr, unsigned form, | |
10411 | gdb_byte *info_ptr) | |
c906108c | 10412 | { |
dee91e82 DE |
10413 | struct dwarf2_cu *cu = reader->cu; |
10414 | bfd *abfd = reader->abfd; | |
e7c27a73 | 10415 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10416 | unsigned int bytes_read; |
10417 | struct dwarf_block *blk; | |
10418 | ||
a8329558 KW |
10419 | attr->form = form; |
10420 | switch (form) | |
c906108c | 10421 | { |
c906108c | 10422 | case DW_FORM_ref_addr: |
ae411497 | 10423 | if (cu->header.version == 2) |
4568ecf9 | 10424 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
ae411497 | 10425 | else |
4568ecf9 DE |
10426 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
10427 | &cu->header, &bytes_read); | |
ae411497 TT |
10428 | info_ptr += bytes_read; |
10429 | break; | |
10430 | case DW_FORM_addr: | |
e7c27a73 | 10431 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 10432 | info_ptr += bytes_read; |
c906108c SS |
10433 | break; |
10434 | case DW_FORM_block2: | |
7b5a2f43 | 10435 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10436 | blk->size = read_2_bytes (abfd, info_ptr); |
10437 | info_ptr += 2; | |
10438 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10439 | info_ptr += blk->size; | |
10440 | DW_BLOCK (attr) = blk; | |
10441 | break; | |
10442 | case DW_FORM_block4: | |
7b5a2f43 | 10443 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10444 | blk->size = read_4_bytes (abfd, info_ptr); |
10445 | info_ptr += 4; | |
10446 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10447 | info_ptr += blk->size; | |
10448 | DW_BLOCK (attr) = blk; | |
10449 | break; | |
10450 | case DW_FORM_data2: | |
10451 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
10452 | info_ptr += 2; | |
10453 | break; | |
10454 | case DW_FORM_data4: | |
10455 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
10456 | info_ptr += 4; | |
10457 | break; | |
10458 | case DW_FORM_data8: | |
10459 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
10460 | info_ptr += 8; | |
10461 | break; | |
2dc7f7b3 TT |
10462 | case DW_FORM_sec_offset: |
10463 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
10464 | info_ptr += bytes_read; | |
10465 | break; | |
c906108c | 10466 | case DW_FORM_string: |
9b1c24c8 | 10467 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 10468 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
10469 | info_ptr += bytes_read; |
10470 | break; | |
4bdf3d34 JJ |
10471 | case DW_FORM_strp: |
10472 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
10473 | &bytes_read); | |
8285870a | 10474 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
10475 | info_ptr += bytes_read; |
10476 | break; | |
2dc7f7b3 | 10477 | case DW_FORM_exprloc: |
c906108c | 10478 | case DW_FORM_block: |
7b5a2f43 | 10479 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10480 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10481 | info_ptr += bytes_read; | |
10482 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10483 | info_ptr += blk->size; | |
10484 | DW_BLOCK (attr) = blk; | |
10485 | break; | |
10486 | case DW_FORM_block1: | |
7b5a2f43 | 10487 | blk = dwarf_alloc_block (cu); |
c906108c SS |
10488 | blk->size = read_1_byte (abfd, info_ptr); |
10489 | info_ptr += 1; | |
10490 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
10491 | info_ptr += blk->size; | |
10492 | DW_BLOCK (attr) = blk; | |
10493 | break; | |
10494 | case DW_FORM_data1: | |
10495 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10496 | info_ptr += 1; | |
10497 | break; | |
10498 | case DW_FORM_flag: | |
10499 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
10500 | info_ptr += 1; | |
10501 | break; | |
2dc7f7b3 TT |
10502 | case DW_FORM_flag_present: |
10503 | DW_UNSND (attr) = 1; | |
10504 | break; | |
c906108c SS |
10505 | case DW_FORM_sdata: |
10506 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
10507 | info_ptr += bytes_read; | |
10508 | break; | |
10509 | case DW_FORM_udata: | |
10510 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
10511 | info_ptr += bytes_read; | |
10512 | break; | |
10513 | case DW_FORM_ref1: | |
4568ecf9 DE |
10514 | DW_UNSND (attr) = (cu->header.offset.sect_off |
10515 | + read_1_byte (abfd, info_ptr)); | |
c906108c SS |
10516 | info_ptr += 1; |
10517 | break; | |
10518 | case DW_FORM_ref2: | |
4568ecf9 DE |
10519 | DW_UNSND (attr) = (cu->header.offset.sect_off |
10520 | + read_2_bytes (abfd, info_ptr)); | |
c906108c SS |
10521 | info_ptr += 2; |
10522 | break; | |
10523 | case DW_FORM_ref4: | |
4568ecf9 DE |
10524 | DW_UNSND (attr) = (cu->header.offset.sect_off |
10525 | + read_4_bytes (abfd, info_ptr)); | |
c906108c SS |
10526 | info_ptr += 4; |
10527 | break; | |
613e1657 | 10528 | case DW_FORM_ref8: |
4568ecf9 DE |
10529 | DW_UNSND (attr) = (cu->header.offset.sect_off |
10530 | + read_8_bytes (abfd, info_ptr)); | |
613e1657 KB |
10531 | info_ptr += 8; |
10532 | break; | |
55f1336d | 10533 | case DW_FORM_ref_sig8: |
348e048f DE |
10534 | /* Convert the signature to something we can record in DW_UNSND |
10535 | for later lookup. | |
10536 | NOTE: This is NULL if the type wasn't found. */ | |
10537 | DW_SIGNATURED_TYPE (attr) = | |
e319fa28 | 10538 | lookup_signatured_type (read_8_bytes (abfd, info_ptr)); |
348e048f DE |
10539 | info_ptr += 8; |
10540 | break; | |
c906108c | 10541 | case DW_FORM_ref_udata: |
4568ecf9 DE |
10542 | DW_UNSND (attr) = (cu->header.offset.sect_off |
10543 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
10544 | info_ptr += bytes_read; |
10545 | break; | |
c906108c | 10546 | case DW_FORM_indirect: |
a8329558 KW |
10547 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
10548 | info_ptr += bytes_read; | |
dee91e82 | 10549 | info_ptr = read_attribute_value (reader, attr, form, info_ptr); |
a8329558 | 10550 | break; |
c906108c | 10551 | default: |
8a3fe4f8 | 10552 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
10553 | dwarf_form_name (form), |
10554 | bfd_get_filename (abfd)); | |
c906108c | 10555 | } |
28e94949 JB |
10556 | |
10557 | /* We have seen instances where the compiler tried to emit a byte | |
10558 | size attribute of -1 which ended up being encoded as an unsigned | |
10559 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
10560 | an object of this size seems pretty unlikely so we can relatively | |
10561 | safely treat these cases as if the size attribute was invalid and | |
10562 | treat them as zero by default. */ | |
10563 | if (attr->name == DW_AT_byte_size | |
10564 | && form == DW_FORM_data4 | |
10565 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
10566 | { |
10567 | complaint | |
10568 | (&symfile_complaints, | |
43bbcdc2 PH |
10569 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
10570 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
10571 | DW_UNSND (attr) = 0; |
10572 | } | |
28e94949 | 10573 | |
c906108c SS |
10574 | return info_ptr; |
10575 | } | |
10576 | ||
a8329558 KW |
10577 | /* Read an attribute described by an abbreviated attribute. */ |
10578 | ||
fe1b8b76 | 10579 | static gdb_byte * |
dee91e82 DE |
10580 | read_attribute (const struct die_reader_specs *reader, |
10581 | struct attribute *attr, struct attr_abbrev *abbrev, | |
10582 | gdb_byte *info_ptr) | |
a8329558 KW |
10583 | { |
10584 | attr->name = abbrev->name; | |
dee91e82 | 10585 | return read_attribute_value (reader, attr, abbrev->form, info_ptr); |
a8329558 KW |
10586 | } |
10587 | ||
0963b4bd | 10588 | /* Read dwarf information from a buffer. */ |
c906108c SS |
10589 | |
10590 | static unsigned int | |
fe1b8b76 | 10591 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10592 | { |
fe1b8b76 | 10593 | return bfd_get_8 (abfd, buf); |
c906108c SS |
10594 | } |
10595 | ||
10596 | static int | |
fe1b8b76 | 10597 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 10598 | { |
fe1b8b76 | 10599 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
10600 | } |
10601 | ||
10602 | static unsigned int | |
fe1b8b76 | 10603 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10604 | { |
fe1b8b76 | 10605 | return bfd_get_16 (abfd, buf); |
c906108c SS |
10606 | } |
10607 | ||
21ae7a4d JK |
10608 | static int |
10609 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10610 | { | |
10611 | return bfd_get_signed_16 (abfd, buf); | |
10612 | } | |
10613 | ||
c906108c | 10614 | static unsigned int |
fe1b8b76 | 10615 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10616 | { |
fe1b8b76 | 10617 | return bfd_get_32 (abfd, buf); |
c906108c SS |
10618 | } |
10619 | ||
21ae7a4d JK |
10620 | static int |
10621 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) | |
10622 | { | |
10623 | return bfd_get_signed_32 (abfd, buf); | |
10624 | } | |
10625 | ||
93311388 | 10626 | static ULONGEST |
fe1b8b76 | 10627 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 10628 | { |
fe1b8b76 | 10629 | return bfd_get_64 (abfd, buf); |
c906108c SS |
10630 | } |
10631 | ||
10632 | static CORE_ADDR | |
fe1b8b76 | 10633 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 10634 | unsigned int *bytes_read) |
c906108c | 10635 | { |
e7c27a73 | 10636 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
10637 | CORE_ADDR retval = 0; |
10638 | ||
107d2387 | 10639 | if (cu_header->signed_addr_p) |
c906108c | 10640 | { |
107d2387 AC |
10641 | switch (cu_header->addr_size) |
10642 | { | |
10643 | case 2: | |
fe1b8b76 | 10644 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
10645 | break; |
10646 | case 4: | |
fe1b8b76 | 10647 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
10648 | break; |
10649 | case 8: | |
fe1b8b76 | 10650 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
10651 | break; |
10652 | default: | |
8e65ff28 | 10653 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 10654 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 10655 | bfd_get_filename (abfd)); |
107d2387 AC |
10656 | } |
10657 | } | |
10658 | else | |
10659 | { | |
10660 | switch (cu_header->addr_size) | |
10661 | { | |
10662 | case 2: | |
fe1b8b76 | 10663 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
10664 | break; |
10665 | case 4: | |
fe1b8b76 | 10666 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
10667 | break; |
10668 | case 8: | |
fe1b8b76 | 10669 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
10670 | break; |
10671 | default: | |
8e65ff28 | 10672 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
10673 | _("read_address: bad switch, " |
10674 | "unsigned [in module %s]"), | |
659b0389 | 10675 | bfd_get_filename (abfd)); |
107d2387 | 10676 | } |
c906108c | 10677 | } |
64367e0a | 10678 | |
107d2387 AC |
10679 | *bytes_read = cu_header->addr_size; |
10680 | return retval; | |
c906108c SS |
10681 | } |
10682 | ||
f7ef9339 | 10683 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
10684 | specification allows the initial length to take up either 4 bytes |
10685 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
10686 | bytes describe the length and all offsets will be 8 bytes in length | |
10687 | instead of 4. | |
10688 | ||
f7ef9339 KB |
10689 | An older, non-standard 64-bit format is also handled by this |
10690 | function. The older format in question stores the initial length | |
10691 | as an 8-byte quantity without an escape value. Lengths greater | |
10692 | than 2^32 aren't very common which means that the initial 4 bytes | |
10693 | is almost always zero. Since a length value of zero doesn't make | |
10694 | sense for the 32-bit format, this initial zero can be considered to | |
10695 | be an escape value which indicates the presence of the older 64-bit | |
10696 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
10697 | greater than 4GB. If it becomes necessary to handle lengths |
10698 | somewhat larger than 4GB, we could allow other small values (such | |
10699 | as the non-sensical values of 1, 2, and 3) to also be used as | |
10700 | escape values indicating the presence of the old format. | |
f7ef9339 | 10701 | |
917c78fc MK |
10702 | The value returned via bytes_read should be used to increment the |
10703 | relevant pointer after calling read_initial_length(). | |
c764a876 | 10704 | |
613e1657 KB |
10705 | [ Note: read_initial_length() and read_offset() are based on the |
10706 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 10707 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
10708 | from: |
10709 | ||
f7ef9339 | 10710 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 10711 | |
613e1657 KB |
10712 | This document is only a draft and is subject to change. (So beware.) |
10713 | ||
f7ef9339 | 10714 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
10715 | determined empirically by examining 64-bit ELF files produced by |
10716 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
10717 | |
10718 | - Kevin, July 16, 2002 | |
613e1657 KB |
10719 | ] */ |
10720 | ||
10721 | static LONGEST | |
c764a876 | 10722 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 10723 | { |
fe1b8b76 | 10724 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 10725 | |
dd373385 | 10726 | if (length == 0xffffffff) |
613e1657 | 10727 | { |
fe1b8b76 | 10728 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 10729 | *bytes_read = 12; |
613e1657 | 10730 | } |
dd373385 | 10731 | else if (length == 0) |
f7ef9339 | 10732 | { |
dd373385 | 10733 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 10734 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 10735 | *bytes_read = 8; |
f7ef9339 | 10736 | } |
613e1657 KB |
10737 | else |
10738 | { | |
10739 | *bytes_read = 4; | |
613e1657 KB |
10740 | } |
10741 | ||
c764a876 DE |
10742 | return length; |
10743 | } | |
dd373385 | 10744 | |
c764a876 DE |
10745 | /* Cover function for read_initial_length. |
10746 | Returns the length of the object at BUF, and stores the size of the | |
10747 | initial length in *BYTES_READ and stores the size that offsets will be in | |
10748 | *OFFSET_SIZE. | |
10749 | If the initial length size is not equivalent to that specified in | |
10750 | CU_HEADER then issue a complaint. | |
10751 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 10752 | |
c764a876 DE |
10753 | static LONGEST |
10754 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
10755 | const struct comp_unit_head *cu_header, | |
10756 | unsigned int *bytes_read, | |
10757 | unsigned int *offset_size) | |
10758 | { | |
10759 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
10760 | ||
10761 | gdb_assert (cu_header->initial_length_size == 4 | |
10762 | || cu_header->initial_length_size == 8 | |
10763 | || cu_header->initial_length_size == 12); | |
10764 | ||
10765 | if (cu_header->initial_length_size != *bytes_read) | |
10766 | complaint (&symfile_complaints, | |
10767 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 10768 | |
c764a876 | 10769 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 10770 | return length; |
613e1657 KB |
10771 | } |
10772 | ||
10773 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 10774 | given by cu_header->offset_size. */ |
613e1657 KB |
10775 | |
10776 | static LONGEST | |
fe1b8b76 | 10777 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 10778 | unsigned int *bytes_read) |
c764a876 DE |
10779 | { |
10780 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 10781 | |
c764a876 DE |
10782 | *bytes_read = cu_header->offset_size; |
10783 | return offset; | |
10784 | } | |
10785 | ||
10786 | /* Read an offset from the data stream. */ | |
10787 | ||
10788 | static LONGEST | |
10789 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
10790 | { |
10791 | LONGEST retval = 0; | |
10792 | ||
c764a876 | 10793 | switch (offset_size) |
613e1657 KB |
10794 | { |
10795 | case 4: | |
fe1b8b76 | 10796 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
10797 | break; |
10798 | case 8: | |
fe1b8b76 | 10799 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
10800 | break; |
10801 | default: | |
8e65ff28 | 10802 | internal_error (__FILE__, __LINE__, |
c764a876 | 10803 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 10804 | bfd_get_filename (abfd)); |
613e1657 KB |
10805 | } |
10806 | ||
917c78fc | 10807 | return retval; |
613e1657 KB |
10808 | } |
10809 | ||
fe1b8b76 JB |
10810 | static gdb_byte * |
10811 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
10812 | { |
10813 | /* If the size of a host char is 8 bits, we can return a pointer | |
10814 | to the buffer, otherwise we have to copy the data to a buffer | |
10815 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10816 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 10817 | return buf; |
c906108c SS |
10818 | } |
10819 | ||
10820 | static char * | |
9b1c24c8 | 10821 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
10822 | { |
10823 | /* If the size of a host char is 8 bits, we can return a pointer | |
10824 | to the string, otherwise we have to copy the string to a buffer | |
10825 | allocated on the temporary obstack. */ | |
4bdf3d34 | 10826 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
10827 | if (*buf == '\0') |
10828 | { | |
10829 | *bytes_read_ptr = 1; | |
10830 | return NULL; | |
10831 | } | |
fe1b8b76 JB |
10832 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
10833 | return (char *) buf; | |
4bdf3d34 JJ |
10834 | } |
10835 | ||
10836 | static char * | |
cf2c3c16 | 10837 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
4bdf3d34 | 10838 | { |
be391dca | 10839 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 10840 | if (dwarf2_per_objfile->str.buffer == NULL) |
cf2c3c16 TT |
10841 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
10842 | bfd_get_filename (abfd)); | |
dce234bc | 10843 | if (str_offset >= dwarf2_per_objfile->str.size) |
cf2c3c16 TT |
10844 | error (_("DW_FORM_strp pointing outside of " |
10845 | ".debug_str section [in module %s]"), | |
10846 | bfd_get_filename (abfd)); | |
4bdf3d34 | 10847 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 10848 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 10849 | return NULL; |
dce234bc | 10850 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
10851 | } |
10852 | ||
cf2c3c16 TT |
10853 | static char * |
10854 | read_indirect_string (bfd *abfd, gdb_byte *buf, | |
10855 | const struct comp_unit_head *cu_header, | |
10856 | unsigned int *bytes_read_ptr) | |
10857 | { | |
10858 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); | |
10859 | ||
10860 | return read_indirect_string_at_offset (abfd, str_offset); | |
10861 | } | |
10862 | ||
12df843f | 10863 | static ULONGEST |
fe1b8b76 | 10864 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10865 | { |
12df843f | 10866 | ULONGEST result; |
ce5d95e1 | 10867 | unsigned int num_read; |
c906108c SS |
10868 | int i, shift; |
10869 | unsigned char byte; | |
10870 | ||
10871 | result = 0; | |
10872 | shift = 0; | |
10873 | num_read = 0; | |
10874 | i = 0; | |
10875 | while (1) | |
10876 | { | |
fe1b8b76 | 10877 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10878 | buf++; |
10879 | num_read++; | |
12df843f | 10880 | result |= ((ULONGEST) (byte & 127) << shift); |
c906108c SS |
10881 | if ((byte & 128) == 0) |
10882 | { | |
10883 | break; | |
10884 | } | |
10885 | shift += 7; | |
10886 | } | |
10887 | *bytes_read_ptr = num_read; | |
10888 | return result; | |
10889 | } | |
10890 | ||
12df843f | 10891 | static LONGEST |
fe1b8b76 | 10892 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 10893 | { |
12df843f | 10894 | LONGEST result; |
77e0b926 | 10895 | int i, shift, num_read; |
c906108c SS |
10896 | unsigned char byte; |
10897 | ||
10898 | result = 0; | |
10899 | shift = 0; | |
c906108c SS |
10900 | num_read = 0; |
10901 | i = 0; | |
10902 | while (1) | |
10903 | { | |
fe1b8b76 | 10904 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
10905 | buf++; |
10906 | num_read++; | |
12df843f | 10907 | result |= ((LONGEST) (byte & 127) << shift); |
c906108c SS |
10908 | shift += 7; |
10909 | if ((byte & 128) == 0) | |
10910 | { | |
10911 | break; | |
10912 | } | |
10913 | } | |
77e0b926 | 10914 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
12df843f | 10915 | result |= -(((LONGEST) 1) << shift); |
c906108c SS |
10916 | *bytes_read_ptr = num_read; |
10917 | return result; | |
10918 | } | |
10919 | ||
4bb7a0a7 DJ |
10920 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
10921 | ||
fe1b8b76 JB |
10922 | static gdb_byte * |
10923 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
10924 | { |
10925 | int byte; | |
10926 | ||
10927 | while (1) | |
10928 | { | |
fe1b8b76 | 10929 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
10930 | buf++; |
10931 | if ((byte & 128) == 0) | |
10932 | return buf; | |
10933 | } | |
10934 | } | |
10935 | ||
c906108c | 10936 | static void |
e142c38c | 10937 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
10938 | { |
10939 | switch (lang) | |
10940 | { | |
10941 | case DW_LANG_C89: | |
76bee0cc | 10942 | case DW_LANG_C99: |
c906108c | 10943 | case DW_LANG_C: |
e142c38c | 10944 | cu->language = language_c; |
c906108c SS |
10945 | break; |
10946 | case DW_LANG_C_plus_plus: | |
e142c38c | 10947 | cu->language = language_cplus; |
c906108c | 10948 | break; |
6aecb9c2 JB |
10949 | case DW_LANG_D: |
10950 | cu->language = language_d; | |
10951 | break; | |
c906108c SS |
10952 | case DW_LANG_Fortran77: |
10953 | case DW_LANG_Fortran90: | |
b21b22e0 | 10954 | case DW_LANG_Fortran95: |
e142c38c | 10955 | cu->language = language_fortran; |
c906108c | 10956 | break; |
a766d390 DE |
10957 | case DW_LANG_Go: |
10958 | cu->language = language_go; | |
10959 | break; | |
c906108c | 10960 | case DW_LANG_Mips_Assembler: |
e142c38c | 10961 | cu->language = language_asm; |
c906108c | 10962 | break; |
bebd888e | 10963 | case DW_LANG_Java: |
e142c38c | 10964 | cu->language = language_java; |
bebd888e | 10965 | break; |
c906108c | 10966 | case DW_LANG_Ada83: |
8aaf0b47 | 10967 | case DW_LANG_Ada95: |
bc5f45f8 JB |
10968 | cu->language = language_ada; |
10969 | break; | |
72019c9c GM |
10970 | case DW_LANG_Modula2: |
10971 | cu->language = language_m2; | |
10972 | break; | |
fe8e67fd PM |
10973 | case DW_LANG_Pascal83: |
10974 | cu->language = language_pascal; | |
10975 | break; | |
22566fbd DJ |
10976 | case DW_LANG_ObjC: |
10977 | cu->language = language_objc; | |
10978 | break; | |
c906108c SS |
10979 | case DW_LANG_Cobol74: |
10980 | case DW_LANG_Cobol85: | |
c906108c | 10981 | default: |
e142c38c | 10982 | cu->language = language_minimal; |
c906108c SS |
10983 | break; |
10984 | } | |
e142c38c | 10985 | cu->language_defn = language_def (cu->language); |
c906108c SS |
10986 | } |
10987 | ||
10988 | /* Return the named attribute or NULL if not there. */ | |
10989 | ||
10990 | static struct attribute * | |
e142c38c | 10991 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c | 10992 | { |
a48e046c | 10993 | for (;;) |
c906108c | 10994 | { |
a48e046c TT |
10995 | unsigned int i; |
10996 | struct attribute *spec = NULL; | |
10997 | ||
10998 | for (i = 0; i < die->num_attrs; ++i) | |
10999 | { | |
11000 | if (die->attrs[i].name == name) | |
11001 | return &die->attrs[i]; | |
11002 | if (die->attrs[i].name == DW_AT_specification | |
11003 | || die->attrs[i].name == DW_AT_abstract_origin) | |
11004 | spec = &die->attrs[i]; | |
11005 | } | |
11006 | ||
11007 | if (!spec) | |
11008 | break; | |
c906108c | 11009 | |
f2f0e013 | 11010 | die = follow_die_ref (die, spec, &cu); |
f2f0e013 | 11011 | } |
c5aa993b | 11012 | |
c906108c SS |
11013 | return NULL; |
11014 | } | |
11015 | ||
348e048f DE |
11016 | /* Return the named attribute or NULL if not there, |
11017 | but do not follow DW_AT_specification, etc. | |
11018 | This is for use in contexts where we're reading .debug_types dies. | |
11019 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
11020 | back up the chain, and we want to go down. */ | |
11021 | ||
11022 | static struct attribute * | |
11023 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
11024 | struct dwarf2_cu *cu) | |
11025 | { | |
11026 | unsigned int i; | |
11027 | ||
11028 | for (i = 0; i < die->num_attrs; ++i) | |
11029 | if (die->attrs[i].name == name) | |
11030 | return &die->attrs[i]; | |
11031 | ||
11032 | return NULL; | |
11033 | } | |
11034 | ||
05cf31d1 JB |
11035 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
11036 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 11037 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
11038 | |
11039 | static int | |
11040 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
11041 | { | |
11042 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
11043 | ||
11044 | return (attr && DW_UNSND (attr)); | |
11045 | } | |
11046 | ||
3ca72b44 | 11047 | static int |
e142c38c | 11048 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 11049 | { |
05cf31d1 JB |
11050 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
11051 | which value is non-zero. However, we have to be careful with | |
11052 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
11053 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
11054 | end up accidently finding a declaration attribute that belongs | |
11055 | to a different DIE referenced by the specification attribute, | |
11056 | even though the given DIE does not have a declaration attribute. */ | |
11057 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
11058 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
11059 | } |
11060 | ||
63d06c5c | 11061 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 11062 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
11063 | containing the return value on output. If there is no |
11064 | specification, but there is an abstract origin, that is | |
11065 | returned. */ | |
63d06c5c DC |
11066 | |
11067 | static struct die_info * | |
f2f0e013 | 11068 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 11069 | { |
f2f0e013 DJ |
11070 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
11071 | *spec_cu); | |
63d06c5c | 11072 | |
edb3359d DJ |
11073 | if (spec_attr == NULL) |
11074 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
11075 | ||
63d06c5c DC |
11076 | if (spec_attr == NULL) |
11077 | return NULL; | |
11078 | else | |
f2f0e013 | 11079 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 11080 | } |
c906108c | 11081 | |
debd256d | 11082 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
11083 | refers to. |
11084 | NOTE: This is also used as a "cleanup" function. */ | |
11085 | ||
debd256d JB |
11086 | static void |
11087 | free_line_header (struct line_header *lh) | |
11088 | { | |
11089 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 11090 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
11091 | |
11092 | /* Remember that all the lh->file_names[i].name pointers are | |
11093 | pointers into debug_line_buffer, and don't need to be freed. */ | |
11094 | if (lh->file_names) | |
a8bc7b56 | 11095 | xfree (lh->file_names); |
debd256d JB |
11096 | |
11097 | /* Similarly for the include directory names. */ | |
11098 | if (lh->include_dirs) | |
a8bc7b56 | 11099 | xfree (lh->include_dirs); |
debd256d | 11100 | |
a8bc7b56 | 11101 | xfree (lh); |
debd256d JB |
11102 | } |
11103 | ||
debd256d | 11104 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 11105 | |
debd256d JB |
11106 | static void |
11107 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 11108 | { |
debd256d JB |
11109 | /* Grow the array if necessary. */ |
11110 | if (lh->include_dirs_size == 0) | |
c5aa993b | 11111 | { |
debd256d JB |
11112 | lh->include_dirs_size = 1; /* for testing */ |
11113 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
11114 | * sizeof (*lh->include_dirs)); | |
11115 | } | |
11116 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
11117 | { | |
11118 | lh->include_dirs_size *= 2; | |
11119 | lh->include_dirs = xrealloc (lh->include_dirs, | |
11120 | (lh->include_dirs_size | |
11121 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 11122 | } |
c906108c | 11123 | |
debd256d JB |
11124 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
11125 | } | |
6e70227d | 11126 | |
debd256d | 11127 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 11128 | |
debd256d JB |
11129 | static void |
11130 | add_file_name (struct line_header *lh, | |
11131 | char *name, | |
11132 | unsigned int dir_index, | |
11133 | unsigned int mod_time, | |
11134 | unsigned int length) | |
11135 | { | |
11136 | struct file_entry *fe; | |
11137 | ||
11138 | /* Grow the array if necessary. */ | |
11139 | if (lh->file_names_size == 0) | |
11140 | { | |
11141 | lh->file_names_size = 1; /* for testing */ | |
11142 | lh->file_names = xmalloc (lh->file_names_size | |
11143 | * sizeof (*lh->file_names)); | |
11144 | } | |
11145 | else if (lh->num_file_names >= lh->file_names_size) | |
11146 | { | |
11147 | lh->file_names_size *= 2; | |
11148 | lh->file_names = xrealloc (lh->file_names, | |
11149 | (lh->file_names_size | |
11150 | * sizeof (*lh->file_names))); | |
11151 | } | |
11152 | ||
11153 | fe = &lh->file_names[lh->num_file_names++]; | |
11154 | fe->name = name; | |
11155 | fe->dir_index = dir_index; | |
11156 | fe->mod_time = mod_time; | |
11157 | fe->length = length; | |
aaa75496 | 11158 | fe->included_p = 0; |
cb1df416 | 11159 | fe->symtab = NULL; |
debd256d | 11160 | } |
6e70227d | 11161 | |
debd256d | 11162 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
11163 | .debug_line, according to the endianness of ABFD. Return a pointer |
11164 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
11165 | |
11166 | NOTE: the strings in the include directory and file name tables of | |
11167 | the returned object point into debug_line_buffer, and must not be | |
11168 | freed. */ | |
ae2de4f8 | 11169 | |
debd256d JB |
11170 | static struct line_header * |
11171 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 11172 | struct dwarf2_cu *cu) |
debd256d JB |
11173 | { |
11174 | struct cleanup *back_to; | |
11175 | struct line_header *lh; | |
fe1b8b76 | 11176 | gdb_byte *line_ptr; |
c764a876 | 11177 | unsigned int bytes_read, offset_size; |
debd256d JB |
11178 | int i; |
11179 | char *cur_dir, *cur_file; | |
11180 | ||
be391dca | 11181 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 11182 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 11183 | { |
e2e0b3e5 | 11184 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
11185 | return 0; |
11186 | } | |
11187 | ||
a738430d MK |
11188 | /* Make sure that at least there's room for the total_length field. |
11189 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 11190 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 11191 | { |
4d3c2250 | 11192 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
11193 | return 0; |
11194 | } | |
11195 | ||
11196 | lh = xmalloc (sizeof (*lh)); | |
11197 | memset (lh, 0, sizeof (*lh)); | |
11198 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
11199 | (void *) lh); | |
11200 | ||
dce234bc | 11201 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 11202 | |
a738430d | 11203 | /* Read in the header. */ |
6e70227d | 11204 | lh->total_length = |
c764a876 DE |
11205 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
11206 | &bytes_read, &offset_size); | |
debd256d | 11207 | line_ptr += bytes_read; |
dce234bc PP |
11208 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
11209 | + dwarf2_per_objfile->line.size)) | |
debd256d | 11210 | { |
4d3c2250 | 11211 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
11212 | return 0; |
11213 | } | |
11214 | lh->statement_program_end = line_ptr + lh->total_length; | |
11215 | lh->version = read_2_bytes (abfd, line_ptr); | |
11216 | line_ptr += 2; | |
c764a876 DE |
11217 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
11218 | line_ptr += offset_size; | |
debd256d JB |
11219 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
11220 | line_ptr += 1; | |
2dc7f7b3 TT |
11221 | if (lh->version >= 4) |
11222 | { | |
11223 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
11224 | line_ptr += 1; | |
11225 | } | |
11226 | else | |
11227 | lh->maximum_ops_per_instruction = 1; | |
11228 | ||
11229 | if (lh->maximum_ops_per_instruction == 0) | |
11230 | { | |
11231 | lh->maximum_ops_per_instruction = 1; | |
11232 | complaint (&symfile_complaints, | |
3e43a32a MS |
11233 | _("invalid maximum_ops_per_instruction " |
11234 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
11235 | } |
11236 | ||
debd256d JB |
11237 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
11238 | line_ptr += 1; | |
11239 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
11240 | line_ptr += 1; | |
11241 | lh->line_range = read_1_byte (abfd, line_ptr); | |
11242 | line_ptr += 1; | |
11243 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
11244 | line_ptr += 1; | |
11245 | lh->standard_opcode_lengths | |
fe1b8b76 | 11246 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
11247 | |
11248 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
11249 | for (i = 1; i < lh->opcode_base; ++i) | |
11250 | { | |
11251 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
11252 | line_ptr += 1; | |
11253 | } | |
11254 | ||
a738430d | 11255 | /* Read directory table. */ |
9b1c24c8 | 11256 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
11257 | { |
11258 | line_ptr += bytes_read; | |
11259 | add_include_dir (lh, cur_dir); | |
11260 | } | |
11261 | line_ptr += bytes_read; | |
11262 | ||
a738430d | 11263 | /* Read file name table. */ |
9b1c24c8 | 11264 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
11265 | { |
11266 | unsigned int dir_index, mod_time, length; | |
11267 | ||
11268 | line_ptr += bytes_read; | |
11269 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11270 | line_ptr += bytes_read; | |
11271 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11272 | line_ptr += bytes_read; | |
11273 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11274 | line_ptr += bytes_read; | |
11275 | ||
11276 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11277 | } | |
11278 | line_ptr += bytes_read; | |
6e70227d | 11279 | lh->statement_program_start = line_ptr; |
debd256d | 11280 | |
dce234bc PP |
11281 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
11282 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 11283 | complaint (&symfile_complaints, |
3e43a32a MS |
11284 | _("line number info header doesn't " |
11285 | "fit in `.debug_line' section")); | |
debd256d JB |
11286 | |
11287 | discard_cleanups (back_to); | |
11288 | return lh; | |
11289 | } | |
c906108c | 11290 | |
c6da4cef DE |
11291 | /* Subroutine of dwarf_decode_lines to simplify it. |
11292 | Return the file name of the psymtab for included file FILE_INDEX | |
11293 | in line header LH of PST. | |
11294 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11295 | If space for the result is malloc'd, it will be freed by a cleanup. | |
11296 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
11297 | ||
11298 | static char * | |
11299 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
11300 | const struct partial_symtab *pst, | |
11301 | const char *comp_dir) | |
11302 | { | |
11303 | const struct file_entry fe = lh->file_names [file_index]; | |
11304 | char *include_name = fe.name; | |
11305 | char *include_name_to_compare = include_name; | |
11306 | char *dir_name = NULL; | |
72b9f47f TT |
11307 | const char *pst_filename; |
11308 | char *copied_name = NULL; | |
c6da4cef DE |
11309 | int file_is_pst; |
11310 | ||
11311 | if (fe.dir_index) | |
11312 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
11313 | ||
11314 | if (!IS_ABSOLUTE_PATH (include_name) | |
11315 | && (dir_name != NULL || comp_dir != NULL)) | |
11316 | { | |
11317 | /* Avoid creating a duplicate psymtab for PST. | |
11318 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
11319 | Before we do the comparison, however, we need to account | |
11320 | for DIR_NAME and COMP_DIR. | |
11321 | First prepend dir_name (if non-NULL). If we still don't | |
11322 | have an absolute path prepend comp_dir (if non-NULL). | |
11323 | However, the directory we record in the include-file's | |
11324 | psymtab does not contain COMP_DIR (to match the | |
11325 | corresponding symtab(s)). | |
11326 | ||
11327 | Example: | |
11328 | ||
11329 | bash$ cd /tmp | |
11330 | bash$ gcc -g ./hello.c | |
11331 | include_name = "hello.c" | |
11332 | dir_name = "." | |
11333 | DW_AT_comp_dir = comp_dir = "/tmp" | |
11334 | DW_AT_name = "./hello.c" */ | |
11335 | ||
11336 | if (dir_name != NULL) | |
11337 | { | |
11338 | include_name = concat (dir_name, SLASH_STRING, | |
11339 | include_name, (char *)NULL); | |
11340 | include_name_to_compare = include_name; | |
11341 | make_cleanup (xfree, include_name); | |
11342 | } | |
11343 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
11344 | { | |
11345 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
11346 | include_name, (char *)NULL); | |
11347 | } | |
11348 | } | |
11349 | ||
11350 | pst_filename = pst->filename; | |
11351 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
11352 | { | |
72b9f47f TT |
11353 | copied_name = concat (pst->dirname, SLASH_STRING, |
11354 | pst_filename, (char *)NULL); | |
11355 | pst_filename = copied_name; | |
c6da4cef DE |
11356 | } |
11357 | ||
1e3fad37 | 11358 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
11359 | |
11360 | if (include_name_to_compare != include_name) | |
11361 | xfree (include_name_to_compare); | |
72b9f47f TT |
11362 | if (copied_name != NULL) |
11363 | xfree (copied_name); | |
c6da4cef DE |
11364 | |
11365 | if (file_is_pst) | |
11366 | return NULL; | |
11367 | return include_name; | |
11368 | } | |
11369 | ||
c91513d8 PP |
11370 | /* Ignore this record_line request. */ |
11371 | ||
11372 | static void | |
11373 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
11374 | { | |
11375 | return; | |
11376 | } | |
11377 | ||
f3f5162e DE |
11378 | /* Subroutine of dwarf_decode_lines to simplify it. |
11379 | Process the line number information in LH. */ | |
debd256d | 11380 | |
c906108c | 11381 | static void |
f3f5162e DE |
11382 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
11383 | struct dwarf2_cu *cu, struct partial_symtab *pst) | |
c906108c | 11384 | { |
a8c50c1f | 11385 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 11386 | gdb_byte *line_end; |
a8c50c1f | 11387 | unsigned int bytes_read, extended_len; |
c906108c | 11388 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
11389 | CORE_ADDR baseaddr; |
11390 | struct objfile *objfile = cu->objfile; | |
f3f5162e | 11391 | bfd *abfd = objfile->obfd; |
fbf65064 | 11392 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 11393 | const int decode_for_pst_p = (pst != NULL); |
f3f5162e | 11394 | struct subfile *last_subfile = NULL; |
c91513d8 PP |
11395 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
11396 | = record_line; | |
e142c38c DJ |
11397 | |
11398 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11399 | |
debd256d JB |
11400 | line_ptr = lh->statement_program_start; |
11401 | line_end = lh->statement_program_end; | |
c906108c SS |
11402 | |
11403 | /* Read the statement sequences until there's nothing left. */ | |
11404 | while (line_ptr < line_end) | |
11405 | { | |
11406 | /* state machine registers */ | |
11407 | CORE_ADDR address = 0; | |
11408 | unsigned int file = 1; | |
11409 | unsigned int line = 1; | |
11410 | unsigned int column = 0; | |
debd256d | 11411 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
11412 | int basic_block = 0; |
11413 | int end_sequence = 0; | |
fbf65064 | 11414 | CORE_ADDR addr; |
2dc7f7b3 | 11415 | unsigned char op_index = 0; |
c906108c | 11416 | |
aaa75496 | 11417 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 11418 | { |
aaa75496 | 11419 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
11420 | /* lh->include_dirs and lh->file_names are 0-based, but the |
11421 | directory and file name numbers in the statement program | |
11422 | are 1-based. */ | |
11423 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 11424 | char *dir = NULL; |
a738430d | 11425 | |
debd256d JB |
11426 | if (fe->dir_index) |
11427 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
11428 | |
11429 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
11430 | } |
11431 | ||
a738430d | 11432 | /* Decode the table. */ |
c5aa993b | 11433 | while (!end_sequence) |
c906108c SS |
11434 | { |
11435 | op_code = read_1_byte (abfd, line_ptr); | |
11436 | line_ptr += 1; | |
59205f5a JB |
11437 | if (line_ptr > line_end) |
11438 | { | |
11439 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
11440 | break; | |
11441 | } | |
9aa1fe7e | 11442 | |
debd256d | 11443 | if (op_code >= lh->opcode_base) |
6e70227d | 11444 | { |
a738430d | 11445 | /* Special operand. */ |
debd256d | 11446 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
11447 | address += (((op_index + (adj_opcode / lh->line_range)) |
11448 | / lh->maximum_ops_per_instruction) | |
11449 | * lh->minimum_instruction_length); | |
11450 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
11451 | % lh->maximum_ops_per_instruction); | |
debd256d | 11452 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 11453 | if (lh->num_file_names < file || file == 0) |
25e43795 | 11454 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
11455 | /* For now we ignore lines not starting on an |
11456 | instruction boundary. */ | |
11457 | else if (op_index == 0) | |
25e43795 DJ |
11458 | { |
11459 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 11460 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11461 | { |
11462 | if (last_subfile != current_subfile) | |
11463 | { | |
11464 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11465 | if (last_subfile) | |
c91513d8 | 11466 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11467 | last_subfile = current_subfile; |
11468 | } | |
25e43795 | 11469 | /* Append row to matrix using current values. */ |
7019d805 | 11470 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11471 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 11472 | } |
25e43795 | 11473 | } |
ca5f395d | 11474 | basic_block = 0; |
9aa1fe7e GK |
11475 | } |
11476 | else switch (op_code) | |
c906108c SS |
11477 | { |
11478 | case DW_LNS_extended_op: | |
3e43a32a MS |
11479 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
11480 | &bytes_read); | |
473b7be6 | 11481 | line_ptr += bytes_read; |
a8c50c1f | 11482 | extended_end = line_ptr + extended_len; |
c906108c SS |
11483 | extended_op = read_1_byte (abfd, line_ptr); |
11484 | line_ptr += 1; | |
11485 | switch (extended_op) | |
11486 | { | |
11487 | case DW_LNE_end_sequence: | |
c91513d8 | 11488 | p_record_line = record_line; |
c906108c | 11489 | end_sequence = 1; |
c906108c SS |
11490 | break; |
11491 | case DW_LNE_set_address: | |
e7c27a73 | 11492 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
11493 | |
11494 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
11495 | { | |
11496 | /* This line table is for a function which has been | |
11497 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
11498 | ||
11499 | long line_offset | |
11500 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
11501 | ||
11502 | complaint (&symfile_complaints, | |
11503 | _(".debug_line address at offset 0x%lx is 0 " | |
11504 | "[in module %s]"), | |
bb5ed363 | 11505 | line_offset, objfile->name); |
c91513d8 PP |
11506 | p_record_line = noop_record_line; |
11507 | } | |
11508 | ||
2dc7f7b3 | 11509 | op_index = 0; |
107d2387 AC |
11510 | line_ptr += bytes_read; |
11511 | address += baseaddr; | |
c906108c SS |
11512 | break; |
11513 | case DW_LNE_define_file: | |
debd256d JB |
11514 | { |
11515 | char *cur_file; | |
11516 | unsigned int dir_index, mod_time, length; | |
6e70227d | 11517 | |
3e43a32a MS |
11518 | cur_file = read_direct_string (abfd, line_ptr, |
11519 | &bytes_read); | |
debd256d JB |
11520 | line_ptr += bytes_read; |
11521 | dir_index = | |
11522 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11523 | line_ptr += bytes_read; | |
11524 | mod_time = | |
11525 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11526 | line_ptr += bytes_read; | |
11527 | length = | |
11528 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11529 | line_ptr += bytes_read; | |
11530 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
11531 | } | |
c906108c | 11532 | break; |
d0c6ba3d CC |
11533 | case DW_LNE_set_discriminator: |
11534 | /* The discriminator is not interesting to the debugger; | |
11535 | just ignore it. */ | |
11536 | line_ptr = extended_end; | |
11537 | break; | |
c906108c | 11538 | default: |
4d3c2250 | 11539 | complaint (&symfile_complaints, |
e2e0b3e5 | 11540 | _("mangled .debug_line section")); |
debd256d | 11541 | return; |
c906108c | 11542 | } |
a8c50c1f DJ |
11543 | /* Make sure that we parsed the extended op correctly. If e.g. |
11544 | we expected a different address size than the producer used, | |
11545 | we may have read the wrong number of bytes. */ | |
11546 | if (line_ptr != extended_end) | |
11547 | { | |
11548 | complaint (&symfile_complaints, | |
11549 | _("mangled .debug_line section")); | |
11550 | return; | |
11551 | } | |
c906108c SS |
11552 | break; |
11553 | case DW_LNS_copy: | |
59205f5a | 11554 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11555 | dwarf2_debug_line_missing_file_complaint (); |
11556 | else | |
366da635 | 11557 | { |
25e43795 | 11558 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 11559 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
11560 | { |
11561 | if (last_subfile != current_subfile) | |
11562 | { | |
11563 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
11564 | if (last_subfile) | |
c91513d8 | 11565 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
11566 | last_subfile = current_subfile; |
11567 | } | |
7019d805 | 11568 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
c91513d8 | 11569 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 11570 | } |
366da635 | 11571 | } |
c906108c SS |
11572 | basic_block = 0; |
11573 | break; | |
11574 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
11575 | { |
11576 | CORE_ADDR adjust | |
11577 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11578 | ||
11579 | address += (((op_index + adjust) | |
11580 | / lh->maximum_ops_per_instruction) | |
11581 | * lh->minimum_instruction_length); | |
11582 | op_index = ((op_index + adjust) | |
11583 | % lh->maximum_ops_per_instruction); | |
11584 | line_ptr += bytes_read; | |
11585 | } | |
c906108c SS |
11586 | break; |
11587 | case DW_LNS_advance_line: | |
11588 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
11589 | line_ptr += bytes_read; | |
11590 | break; | |
11591 | case DW_LNS_set_file: | |
debd256d | 11592 | { |
a738430d MK |
11593 | /* The arrays lh->include_dirs and lh->file_names are |
11594 | 0-based, but the directory and file name numbers in | |
11595 | the statement program are 1-based. */ | |
debd256d | 11596 | struct file_entry *fe; |
4f1520fb | 11597 | char *dir = NULL; |
a738430d | 11598 | |
debd256d JB |
11599 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
11600 | line_ptr += bytes_read; | |
59205f5a | 11601 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
11602 | dwarf2_debug_line_missing_file_complaint (); |
11603 | else | |
11604 | { | |
11605 | fe = &lh->file_names[file - 1]; | |
11606 | if (fe->dir_index) | |
11607 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11608 | if (!decode_for_pst_p) | |
11609 | { | |
11610 | last_subfile = current_subfile; | |
11611 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11612 | } | |
11613 | } | |
debd256d | 11614 | } |
c906108c SS |
11615 | break; |
11616 | case DW_LNS_set_column: | |
11617 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11618 | line_ptr += bytes_read; | |
11619 | break; | |
11620 | case DW_LNS_negate_stmt: | |
11621 | is_stmt = (!is_stmt); | |
11622 | break; | |
11623 | case DW_LNS_set_basic_block: | |
11624 | basic_block = 1; | |
11625 | break; | |
c2c6d25f JM |
11626 | /* Add to the address register of the state machine the |
11627 | address increment value corresponding to special opcode | |
a738430d MK |
11628 | 255. I.e., this value is scaled by the minimum |
11629 | instruction length since special opcode 255 would have | |
b021a221 | 11630 | scaled the increment. */ |
c906108c | 11631 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
11632 | { |
11633 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
11634 | ||
11635 | address += (((op_index + adjust) | |
11636 | / lh->maximum_ops_per_instruction) | |
11637 | * lh->minimum_instruction_length); | |
11638 | op_index = ((op_index + adjust) | |
11639 | % lh->maximum_ops_per_instruction); | |
11640 | } | |
c906108c SS |
11641 | break; |
11642 | case DW_LNS_fixed_advance_pc: | |
11643 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 11644 | op_index = 0; |
c906108c SS |
11645 | line_ptr += 2; |
11646 | break; | |
9aa1fe7e | 11647 | default: |
a738430d MK |
11648 | { |
11649 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 11650 | int i; |
a738430d | 11651 | |
debd256d | 11652 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
11653 | { |
11654 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
11655 | line_ptr += bytes_read; | |
11656 | } | |
11657 | } | |
c906108c SS |
11658 | } |
11659 | } | |
59205f5a JB |
11660 | if (lh->num_file_names < file || file == 0) |
11661 | dwarf2_debug_line_missing_file_complaint (); | |
11662 | else | |
11663 | { | |
11664 | lh->file_names[file - 1].included_p = 1; | |
11665 | if (!decode_for_pst_p) | |
fbf65064 UW |
11666 | { |
11667 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 11668 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 11669 | } |
59205f5a | 11670 | } |
c906108c | 11671 | } |
f3f5162e DE |
11672 | } |
11673 | ||
11674 | /* Decode the Line Number Program (LNP) for the given line_header | |
11675 | structure and CU. The actual information extracted and the type | |
11676 | of structures created from the LNP depends on the value of PST. | |
11677 | ||
11678 | 1. If PST is NULL, then this procedure uses the data from the program | |
11679 | to create all necessary symbol tables, and their linetables. | |
11680 | ||
11681 | 2. If PST is not NULL, this procedure reads the program to determine | |
11682 | the list of files included by the unit represented by PST, and | |
11683 | builds all the associated partial symbol tables. | |
11684 | ||
11685 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
11686 | It is used for relative paths in the line table. | |
11687 | NOTE: When processing partial symtabs (pst != NULL), | |
11688 | comp_dir == pst->dirname. | |
11689 | ||
11690 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
11691 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
11692 | symtab we don't use it in the name of the psymtabs we create. | |
11693 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
11694 | A good testcase for this is mb-inline.exp. */ | |
11695 | ||
11696 | static void | |
11697 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, | |
11698 | struct dwarf2_cu *cu, struct partial_symtab *pst, | |
11699 | int want_line_info) | |
11700 | { | |
11701 | struct objfile *objfile = cu->objfile; | |
11702 | const int decode_for_pst_p = (pst != NULL); | |
11703 | struct subfile *first_subfile = current_subfile; | |
11704 | ||
11705 | if (want_line_info) | |
11706 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); | |
aaa75496 JB |
11707 | |
11708 | if (decode_for_pst_p) | |
11709 | { | |
11710 | int file_index; | |
11711 | ||
11712 | /* Now that we're done scanning the Line Header Program, we can | |
11713 | create the psymtab of each included file. */ | |
11714 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
11715 | if (lh->file_names[file_index].included_p == 1) | |
11716 | { | |
c6da4cef DE |
11717 | char *include_name = |
11718 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
11719 | if (include_name != NULL) | |
aaa75496 JB |
11720 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
11721 | } | |
11722 | } | |
cb1df416 DJ |
11723 | else |
11724 | { | |
11725 | /* Make sure a symtab is created for every file, even files | |
11726 | which contain only variables (i.e. no code with associated | |
11727 | line numbers). */ | |
cb1df416 | 11728 | int i; |
cb1df416 DJ |
11729 | |
11730 | for (i = 0; i < lh->num_file_names; i++) | |
11731 | { | |
11732 | char *dir = NULL; | |
f3f5162e | 11733 | struct file_entry *fe; |
9a619af0 | 11734 | |
cb1df416 DJ |
11735 | fe = &lh->file_names[i]; |
11736 | if (fe->dir_index) | |
11737 | dir = lh->include_dirs[fe->dir_index - 1]; | |
11738 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
11739 | ||
11740 | /* Skip the main file; we don't need it, and it must be | |
11741 | allocated last, so that it will show up before the | |
11742 | non-primary symtabs in the objfile's symtab list. */ | |
11743 | if (current_subfile == first_subfile) | |
11744 | continue; | |
11745 | ||
11746 | if (current_subfile->symtab == NULL) | |
11747 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
bb5ed363 | 11748 | objfile); |
cb1df416 DJ |
11749 | fe->symtab = current_subfile->symtab; |
11750 | } | |
11751 | } | |
c906108c SS |
11752 | } |
11753 | ||
11754 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
11755 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
11756 | or NULL if not known. COMP_DIR is the compilation directory for the |
11757 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
11758 | This routine tries to keep line numbers from identical absolute and |
11759 | relative file names in a common subfile. | |
11760 | ||
11761 | Using the `list' example from the GDB testsuite, which resides in | |
11762 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
11763 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
11764 | ||
c5aa993b JM |
11765 | DW_AT_name: /srcdir/list0.c |
11766 | DW_AT_comp_dir: /compdir | |
357e46e7 | 11767 | files.files[0].name: list0.h |
c5aa993b | 11768 | files.files[0].dir: /srcdir |
357e46e7 | 11769 | files.files[1].name: list0.c |
c5aa993b | 11770 | files.files[1].dir: /srcdir |
c906108c SS |
11771 | |
11772 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
11773 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
11774 | start_subfile will ensure that this happens provided that we pass the | |
11775 | concatenation of files.files[1].dir and files.files[1].name as the | |
11776 | subfile's name. */ | |
c906108c SS |
11777 | |
11778 | static void | |
3e43a32a MS |
11779 | dwarf2_start_subfile (char *filename, const char *dirname, |
11780 | const char *comp_dir) | |
c906108c | 11781 | { |
4f1520fb FR |
11782 | char *fullname; |
11783 | ||
11784 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
11785 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
11786 | second argument to start_subfile. To be consistent, we do the | |
11787 | same here. In order not to lose the line information directory, | |
11788 | we concatenate it to the filename when it makes sense. | |
11789 | Note that the Dwarf3 standard says (speaking of filenames in line | |
11790 | information): ``The directory index is ignored for file names | |
11791 | that represent full path names''. Thus ignoring dirname in the | |
11792 | `else' branch below isn't an issue. */ | |
c906108c | 11793 | |
d5166ae1 | 11794 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
11795 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
11796 | else | |
11797 | fullname = filename; | |
c906108c | 11798 | |
4f1520fb FR |
11799 | start_subfile (fullname, comp_dir); |
11800 | ||
11801 | if (fullname != filename) | |
11802 | xfree (fullname); | |
c906108c SS |
11803 | } |
11804 | ||
4c2df51b DJ |
11805 | static void |
11806 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 11807 | struct dwarf2_cu *cu) |
4c2df51b | 11808 | { |
e7c27a73 DJ |
11809 | struct objfile *objfile = cu->objfile; |
11810 | struct comp_unit_head *cu_header = &cu->header; | |
11811 | ||
4c2df51b DJ |
11812 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
11813 | code here to turn a symbol with DW_AT_external and a | |
11814 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
11815 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
11816 | with some versions of binutils) where shared libraries could have | |
11817 | relocations against symbols in their debug information - the | |
11818 | minimal symbol would have the right address, but the debug info | |
11819 | would not. It's no longer necessary, because we will explicitly | |
11820 | apply relocations when we read in the debug information now. */ | |
11821 | ||
11822 | /* A DW_AT_location attribute with no contents indicates that a | |
11823 | variable has been optimized away. */ | |
11824 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
11825 | { | |
11826 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
11827 | return; | |
11828 | } | |
11829 | ||
11830 | /* Handle one degenerate form of location expression specially, to | |
11831 | preserve GDB's previous behavior when section offsets are | |
11832 | specified. If this is just a DW_OP_addr then mark this symbol | |
11833 | as LOC_STATIC. */ | |
11834 | ||
11835 | if (attr_form_is_block (attr) | |
11836 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
11837 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
11838 | { | |
891d2f0b | 11839 | unsigned int dummy; |
4c2df51b DJ |
11840 | |
11841 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 11842 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 11843 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
11844 | fixup_symbol_section (sym, objfile); |
11845 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
11846 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
11847 | return; |
11848 | } | |
11849 | ||
11850 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
11851 | expression evaluator, and use LOC_COMPUTED only when necessary | |
11852 | (i.e. when the value of a register or memory location is | |
11853 | referenced, or a thread-local block, etc.). Then again, it might | |
11854 | not be worthwhile. I'm assuming that it isn't unless performance | |
11855 | or memory numbers show me otherwise. */ | |
11856 | ||
e7c27a73 | 11857 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b | 11858 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
8be455d7 JK |
11859 | |
11860 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) | |
11861 | cu->has_loclist = 1; | |
4c2df51b DJ |
11862 | } |
11863 | ||
c906108c SS |
11864 | /* Given a pointer to a DWARF information entry, figure out if we need |
11865 | to make a symbol table entry for it, and if so, create a new entry | |
11866 | and return a pointer to it. | |
11867 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
11868 | used the passed type. |
11869 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
11870 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
11871 | |
11872 | static struct symbol * | |
34eaf542 TT |
11873 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
11874 | struct symbol *space) | |
c906108c | 11875 | { |
e7c27a73 | 11876 | struct objfile *objfile = cu->objfile; |
c906108c SS |
11877 | struct symbol *sym = NULL; |
11878 | char *name; | |
11879 | struct attribute *attr = NULL; | |
11880 | struct attribute *attr2 = NULL; | |
e142c38c | 11881 | CORE_ADDR baseaddr; |
e37fd15a SW |
11882 | struct pending **list_to_add = NULL; |
11883 | ||
edb3359d | 11884 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
11885 | |
11886 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 11887 | |
94af9270 | 11888 | name = dwarf2_name (die, cu); |
c906108c SS |
11889 | if (name) |
11890 | { | |
94af9270 | 11891 | const char *linkagename; |
34eaf542 | 11892 | int suppress_add = 0; |
94af9270 | 11893 | |
34eaf542 TT |
11894 | if (space) |
11895 | sym = space; | |
11896 | else | |
11897 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 11898 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
11899 | |
11900 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 11901 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
11902 | linkagename = dwarf2_physname (name, die, cu); |
11903 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 11904 | |
f55ee35c JK |
11905 | /* Fortran does not have mangling standard and the mangling does differ |
11906 | between gfortran, iFort etc. */ | |
11907 | if (cu->language == language_fortran | |
b250c185 | 11908 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
11909 | symbol_set_demangled_name (&(sym->ginfo), |
11910 | (char *) dwarf2_full_name (name, die, cu), | |
11911 | NULL); | |
f55ee35c | 11912 | |
c906108c | 11913 | /* Default assumptions. |
c5aa993b | 11914 | Use the passed type or decode it from the die. */ |
176620f1 | 11915 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 11916 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
11917 | if (type != NULL) |
11918 | SYMBOL_TYPE (sym) = type; | |
11919 | else | |
e7c27a73 | 11920 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
11921 | attr = dwarf2_attr (die, |
11922 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
11923 | cu); | |
c906108c SS |
11924 | if (attr) |
11925 | { | |
11926 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
11927 | } | |
cb1df416 | 11928 | |
edb3359d DJ |
11929 | attr = dwarf2_attr (die, |
11930 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
11931 | cu); | |
cb1df416 DJ |
11932 | if (attr) |
11933 | { | |
11934 | int file_index = DW_UNSND (attr); | |
9a619af0 | 11935 | |
cb1df416 DJ |
11936 | if (cu->line_header == NULL |
11937 | || file_index > cu->line_header->num_file_names) | |
11938 | complaint (&symfile_complaints, | |
11939 | _("file index out of range")); | |
1c3d648d | 11940 | else if (file_index > 0) |
cb1df416 DJ |
11941 | { |
11942 | struct file_entry *fe; | |
9a619af0 | 11943 | |
cb1df416 DJ |
11944 | fe = &cu->line_header->file_names[file_index - 1]; |
11945 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
11946 | } | |
11947 | } | |
11948 | ||
c906108c SS |
11949 | switch (die->tag) |
11950 | { | |
11951 | case DW_TAG_label: | |
e142c38c | 11952 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
11953 | if (attr) |
11954 | { | |
11955 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
11956 | } | |
0f5238ed TT |
11957 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
11958 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 11959 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 11960 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
11961 | break; |
11962 | case DW_TAG_subprogram: | |
11963 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11964 | finish_block. */ | |
11965 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 11966 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
11967 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
11968 | || cu->language == language_ada) | |
c906108c | 11969 | { |
2cfa0c8d JB |
11970 | /* Subprograms marked external are stored as a global symbol. |
11971 | Ada subprograms, whether marked external or not, are always | |
11972 | stored as a global symbol, because we want to be able to | |
11973 | access them globally. For instance, we want to be able | |
11974 | to break on a nested subprogram without having to | |
11975 | specify the context. */ | |
e37fd15a | 11976 | list_to_add = &global_symbols; |
c906108c SS |
11977 | } |
11978 | else | |
11979 | { | |
e37fd15a | 11980 | list_to_add = cu->list_in_scope; |
c906108c SS |
11981 | } |
11982 | break; | |
edb3359d DJ |
11983 | case DW_TAG_inlined_subroutine: |
11984 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11985 | finish_block. */ | |
11986 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11987 | SYMBOL_INLINED (sym) = 1; | |
481860b3 | 11988 | list_to_add = cu->list_in_scope; |
edb3359d | 11989 | break; |
34eaf542 TT |
11990 | case DW_TAG_template_value_param: |
11991 | suppress_add = 1; | |
11992 | /* Fall through. */ | |
72929c62 | 11993 | case DW_TAG_constant: |
c906108c | 11994 | case DW_TAG_variable: |
254e6b9e | 11995 | case DW_TAG_member: |
0963b4bd MS |
11996 | /* Compilation with minimal debug info may result in |
11997 | variables with missing type entries. Change the | |
11998 | misleading `void' type to something sensible. */ | |
c906108c | 11999 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 12000 | SYMBOL_TYPE (sym) |
46bf5051 | 12001 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 12002 | |
e142c38c | 12003 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
12004 | /* In the case of DW_TAG_member, we should only be called for |
12005 | static const members. */ | |
12006 | if (die->tag == DW_TAG_member) | |
12007 | { | |
3863f96c DE |
12008 | /* dwarf2_add_field uses die_is_declaration, |
12009 | so we do the same. */ | |
254e6b9e DE |
12010 | gdb_assert (die_is_declaration (die, cu)); |
12011 | gdb_assert (attr); | |
12012 | } | |
c906108c SS |
12013 | if (attr) |
12014 | { | |
e7c27a73 | 12015 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 12016 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 12017 | if (!suppress_add) |
34eaf542 TT |
12018 | { |
12019 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 12020 | list_to_add = &global_symbols; |
34eaf542 | 12021 | else |
e37fd15a | 12022 | list_to_add = cu->list_in_scope; |
34eaf542 | 12023 | } |
c906108c SS |
12024 | break; |
12025 | } | |
e142c38c | 12026 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
12027 | if (attr) |
12028 | { | |
e7c27a73 | 12029 | var_decode_location (attr, sym, cu); |
e142c38c | 12030 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
12031 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
12032 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
12033 | && !dwarf2_per_objfile->has_section_at_zero) | |
12034 | { | |
12035 | /* When a static variable is eliminated by the linker, | |
12036 | the corresponding debug information is not stripped | |
12037 | out, but the variable address is set to null; | |
12038 | do not add such variables into symbol table. */ | |
12039 | } | |
12040 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 12041 | { |
f55ee35c JK |
12042 | /* Workaround gfortran PR debug/40040 - it uses |
12043 | DW_AT_location for variables in -fPIC libraries which may | |
12044 | get overriden by other libraries/executable and get | |
12045 | a different address. Resolve it by the minimal symbol | |
12046 | which may come from inferior's executable using copy | |
12047 | relocation. Make this workaround only for gfortran as for | |
12048 | other compilers GDB cannot guess the minimal symbol | |
12049 | Fortran mangling kind. */ | |
12050 | if (cu->language == language_fortran && die->parent | |
12051 | && die->parent->tag == DW_TAG_module | |
12052 | && cu->producer | |
12053 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
12054 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
12055 | ||
1c809c68 TT |
12056 | /* A variable with DW_AT_external is never static, |
12057 | but it may be block-scoped. */ | |
12058 | list_to_add = (cu->list_in_scope == &file_symbols | |
12059 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 12060 | } |
c906108c | 12061 | else |
e37fd15a | 12062 | list_to_add = cu->list_in_scope; |
c906108c SS |
12063 | } |
12064 | else | |
12065 | { | |
12066 | /* We do not know the address of this symbol. | |
c5aa993b JM |
12067 | If it is an external symbol and we have type information |
12068 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
12069 | The address of the variable will then be determined from | |
12070 | the minimal symbol table whenever the variable is | |
12071 | referenced. */ | |
e142c38c | 12072 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 12073 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 12074 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 12075 | { |
0fe7935b DJ |
12076 | /* A variable with DW_AT_external is never static, but it |
12077 | may be block-scoped. */ | |
12078 | list_to_add = (cu->list_in_scope == &file_symbols | |
12079 | ? &global_symbols : cu->list_in_scope); | |
12080 | ||
c906108c | 12081 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 12082 | } |
442ddf59 JK |
12083 | else if (!die_is_declaration (die, cu)) |
12084 | { | |
12085 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
12086 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
12087 | if (!suppress_add) |
12088 | list_to_add = cu->list_in_scope; | |
442ddf59 | 12089 | } |
c906108c SS |
12090 | } |
12091 | break; | |
12092 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
12093 | /* If we are inside a function, mark this as an argument. If |
12094 | not, we might be looking at an argument to an inlined function | |
12095 | when we do not have enough information to show inlined frames; | |
12096 | pretend it's a local variable in that case so that the user can | |
12097 | still see it. */ | |
12098 | if (context_stack_depth > 0 | |
12099 | && context_stack[context_stack_depth - 1].name != NULL) | |
12100 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 12101 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
12102 | if (attr) |
12103 | { | |
e7c27a73 | 12104 | var_decode_location (attr, sym, cu); |
c906108c | 12105 | } |
e142c38c | 12106 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
12107 | if (attr) |
12108 | { | |
e7c27a73 | 12109 | dwarf2_const_value (attr, sym, cu); |
c906108c | 12110 | } |
f346a30d | 12111 | |
e37fd15a | 12112 | list_to_add = cu->list_in_scope; |
c906108c SS |
12113 | break; |
12114 | case DW_TAG_unspecified_parameters: | |
12115 | /* From varargs functions; gdb doesn't seem to have any | |
12116 | interest in this information, so just ignore it for now. | |
12117 | (FIXME?) */ | |
12118 | break; | |
34eaf542 TT |
12119 | case DW_TAG_template_type_param: |
12120 | suppress_add = 1; | |
12121 | /* Fall through. */ | |
c906108c | 12122 | case DW_TAG_class_type: |
680b30c7 | 12123 | case DW_TAG_interface_type: |
c906108c SS |
12124 | case DW_TAG_structure_type: |
12125 | case DW_TAG_union_type: | |
72019c9c | 12126 | case DW_TAG_set_type: |
c906108c SS |
12127 | case DW_TAG_enumeration_type: |
12128 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 12129 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 12130 | |
63d06c5c | 12131 | { |
987504bb | 12132 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
12133 | really ever be static objects: otherwise, if you try |
12134 | to, say, break of a class's method and you're in a file | |
12135 | which doesn't mention that class, it won't work unless | |
12136 | the check for all static symbols in lookup_symbol_aux | |
12137 | saves you. See the OtherFileClass tests in | |
12138 | gdb.c++/namespace.exp. */ | |
12139 | ||
e37fd15a | 12140 | if (!suppress_add) |
34eaf542 | 12141 | { |
34eaf542 TT |
12142 | list_to_add = (cu->list_in_scope == &file_symbols |
12143 | && (cu->language == language_cplus | |
12144 | || cu->language == language_java) | |
12145 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 12146 | |
64382290 TT |
12147 | /* The semantics of C++ state that "struct foo { |
12148 | ... }" also defines a typedef for "foo". A Java | |
12149 | class declaration also defines a typedef for the | |
12150 | class. */ | |
12151 | if (cu->language == language_cplus | |
12152 | || cu->language == language_java | |
12153 | || cu->language == language_ada) | |
12154 | { | |
12155 | /* The symbol's name is already allocated along | |
12156 | with this objfile, so we don't need to | |
12157 | duplicate it for the type. */ | |
12158 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
12159 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
12160 | } | |
63d06c5c DC |
12161 | } |
12162 | } | |
c906108c SS |
12163 | break; |
12164 | case DW_TAG_typedef: | |
63d06c5c DC |
12165 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
12166 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 12167 | list_to_add = cu->list_in_scope; |
63d06c5c | 12168 | break; |
c906108c | 12169 | case DW_TAG_base_type: |
a02abb62 | 12170 | case DW_TAG_subrange_type: |
c906108c | 12171 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 12172 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 12173 | list_to_add = cu->list_in_scope; |
c906108c SS |
12174 | break; |
12175 | case DW_TAG_enumerator: | |
e142c38c | 12176 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
12177 | if (attr) |
12178 | { | |
e7c27a73 | 12179 | dwarf2_const_value (attr, sym, cu); |
c906108c | 12180 | } |
63d06c5c DC |
12181 | { |
12182 | /* NOTE: carlton/2003-11-10: See comment above in the | |
12183 | DW_TAG_class_type, etc. block. */ | |
12184 | ||
e142c38c | 12185 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
12186 | && (cu->language == language_cplus |
12187 | || cu->language == language_java) | |
e142c38c | 12188 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 12189 | } |
c906108c | 12190 | break; |
5c4e30ca DC |
12191 | case DW_TAG_namespace: |
12192 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 12193 | list_to_add = &global_symbols; |
5c4e30ca | 12194 | break; |
c906108c SS |
12195 | default: |
12196 | /* Not a tag we recognize. Hopefully we aren't processing | |
12197 | trash data, but since we must specifically ignore things | |
12198 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 12199 | this point. */ |
e2e0b3e5 | 12200 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 12201 | dwarf_tag_name (die->tag)); |
c906108c SS |
12202 | break; |
12203 | } | |
df8a16a1 | 12204 | |
e37fd15a SW |
12205 | if (suppress_add) |
12206 | { | |
12207 | sym->hash_next = objfile->template_symbols; | |
12208 | objfile->template_symbols = sym; | |
12209 | list_to_add = NULL; | |
12210 | } | |
12211 | ||
12212 | if (list_to_add != NULL) | |
12213 | add_symbol_to_list (sym, list_to_add); | |
12214 | ||
df8a16a1 DJ |
12215 | /* For the benefit of old versions of GCC, check for anonymous |
12216 | namespaces based on the demangled name. */ | |
12217 | if (!processing_has_namespace_info | |
94af9270 | 12218 | && cu->language == language_cplus) |
a10964d1 | 12219 | cp_scan_for_anonymous_namespaces (sym, objfile); |
c906108c SS |
12220 | } |
12221 | return (sym); | |
12222 | } | |
12223 | ||
34eaf542 TT |
12224 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
12225 | ||
12226 | static struct symbol * | |
12227 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
12228 | { | |
12229 | return new_symbol_full (die, type, cu, NULL); | |
12230 | } | |
12231 | ||
98bfdba5 PA |
12232 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
12233 | zero-extend it as appropriate for the symbol's type. The DWARF | |
12234 | standard (v4) is not entirely clear about the meaning of using | |
12235 | DW_FORM_dataN for a constant with a signed type, where the type is | |
12236 | wider than the data. The conclusion of a discussion on the DWARF | |
12237 | list was that this is unspecified. We choose to always zero-extend | |
12238 | because that is the interpretation long in use by GCC. */ | |
c906108c | 12239 | |
98bfdba5 PA |
12240 | static gdb_byte * |
12241 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
12242 | const char *name, struct obstack *obstack, | |
12df843f | 12243 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
c906108c | 12244 | { |
e7c27a73 | 12245 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
12246 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
12247 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
12248 | LONGEST l = DW_UNSND (attr); |
12249 | ||
12250 | if (bits < sizeof (*value) * 8) | |
12251 | { | |
12252 | l &= ((LONGEST) 1 << bits) - 1; | |
12253 | *value = l; | |
12254 | } | |
12255 | else if (bits == sizeof (*value) * 8) | |
12256 | *value = l; | |
12257 | else | |
12258 | { | |
12259 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
12260 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
12261 | return bytes; | |
12262 | } | |
12263 | ||
12264 | return NULL; | |
12265 | } | |
12266 | ||
12267 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
12268 | the value does not fit in *VALUE, set *BYTES - either already | |
12269 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
12270 | or, set *BATON, if we translated the constant to a location | |
12271 | expression. */ | |
12272 | ||
12273 | static void | |
12274 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
12275 | const char *name, struct obstack *obstack, | |
12276 | struct dwarf2_cu *cu, | |
12df843f | 12277 | LONGEST *value, gdb_byte **bytes, |
98bfdba5 PA |
12278 | struct dwarf2_locexpr_baton **baton) |
12279 | { | |
12280 | struct objfile *objfile = cu->objfile; | |
12281 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 12282 | struct dwarf_block *blk; |
98bfdba5 PA |
12283 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
12284 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
12285 | ||
12286 | *value = 0; | |
12287 | *bytes = NULL; | |
12288 | *baton = NULL; | |
c906108c SS |
12289 | |
12290 | switch (attr->form) | |
12291 | { | |
12292 | case DW_FORM_addr: | |
ac56253d | 12293 | { |
ac56253d TT |
12294 | gdb_byte *data; |
12295 | ||
98bfdba5 PA |
12296 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
12297 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 12298 | cu_header->addr_size, |
98bfdba5 | 12299 | TYPE_LENGTH (type)); |
ac56253d TT |
12300 | /* Symbols of this form are reasonably rare, so we just |
12301 | piggyback on the existing location code rather than writing | |
12302 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
12303 | *baton = obstack_alloc (&objfile->objfile_obstack, |
12304 | sizeof (struct dwarf2_locexpr_baton)); | |
12305 | (*baton)->per_cu = cu->per_cu; | |
12306 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 12307 | |
98bfdba5 PA |
12308 | (*baton)->size = 2 + cu_header->addr_size; |
12309 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
12310 | (*baton)->data = data; | |
ac56253d TT |
12311 | |
12312 | data[0] = DW_OP_addr; | |
12313 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
12314 | byte_order, DW_ADDR (attr)); | |
12315 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 12316 | } |
c906108c | 12317 | break; |
4ac36638 | 12318 | case DW_FORM_string: |
93b5768b | 12319 | case DW_FORM_strp: |
98bfdba5 PA |
12320 | /* DW_STRING is already allocated on the objfile obstack, point |
12321 | directly to it. */ | |
12322 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 12323 | break; |
c906108c SS |
12324 | case DW_FORM_block1: |
12325 | case DW_FORM_block2: | |
12326 | case DW_FORM_block4: | |
12327 | case DW_FORM_block: | |
2dc7f7b3 | 12328 | case DW_FORM_exprloc: |
c906108c | 12329 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
12330 | if (TYPE_LENGTH (type) != blk->size) |
12331 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
12332 | TYPE_LENGTH (type)); | |
12333 | *bytes = blk->data; | |
c906108c | 12334 | break; |
2df3850c JM |
12335 | |
12336 | /* The DW_AT_const_value attributes are supposed to carry the | |
12337 | symbol's value "represented as it would be on the target | |
12338 | architecture." By the time we get here, it's already been | |
12339 | converted to host endianness, so we just need to sign- or | |
12340 | zero-extend it as appropriate. */ | |
12341 | case DW_FORM_data1: | |
3e43a32a MS |
12342 | *bytes = dwarf2_const_value_data (attr, type, name, |
12343 | obstack, cu, value, 8); | |
2df3850c | 12344 | break; |
c906108c | 12345 | case DW_FORM_data2: |
3e43a32a MS |
12346 | *bytes = dwarf2_const_value_data (attr, type, name, |
12347 | obstack, cu, value, 16); | |
2df3850c | 12348 | break; |
c906108c | 12349 | case DW_FORM_data4: |
3e43a32a MS |
12350 | *bytes = dwarf2_const_value_data (attr, type, name, |
12351 | obstack, cu, value, 32); | |
2df3850c | 12352 | break; |
c906108c | 12353 | case DW_FORM_data8: |
3e43a32a MS |
12354 | *bytes = dwarf2_const_value_data (attr, type, name, |
12355 | obstack, cu, value, 64); | |
2df3850c JM |
12356 | break; |
12357 | ||
c906108c | 12358 | case DW_FORM_sdata: |
98bfdba5 | 12359 | *value = DW_SND (attr); |
2df3850c JM |
12360 | break; |
12361 | ||
c906108c | 12362 | case DW_FORM_udata: |
98bfdba5 | 12363 | *value = DW_UNSND (attr); |
c906108c | 12364 | break; |
2df3850c | 12365 | |
c906108c | 12366 | default: |
4d3c2250 | 12367 | complaint (&symfile_complaints, |
e2e0b3e5 | 12368 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 12369 | dwarf_form_name (attr->form)); |
98bfdba5 | 12370 | *value = 0; |
c906108c SS |
12371 | break; |
12372 | } | |
12373 | } | |
12374 | ||
2df3850c | 12375 | |
98bfdba5 PA |
12376 | /* Copy constant value from an attribute to a symbol. */ |
12377 | ||
2df3850c | 12378 | static void |
98bfdba5 PA |
12379 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
12380 | struct dwarf2_cu *cu) | |
2df3850c | 12381 | { |
98bfdba5 PA |
12382 | struct objfile *objfile = cu->objfile; |
12383 | struct comp_unit_head *cu_header = &cu->header; | |
12df843f | 12384 | LONGEST value; |
98bfdba5 PA |
12385 | gdb_byte *bytes; |
12386 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 12387 | |
98bfdba5 PA |
12388 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
12389 | SYMBOL_PRINT_NAME (sym), | |
12390 | &objfile->objfile_obstack, cu, | |
12391 | &value, &bytes, &baton); | |
2df3850c | 12392 | |
98bfdba5 PA |
12393 | if (baton != NULL) |
12394 | { | |
12395 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
12396 | SYMBOL_LOCATION_BATON (sym) = baton; | |
12397 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
12398 | } | |
12399 | else if (bytes != NULL) | |
12400 | { | |
12401 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
12402 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
12403 | } | |
12404 | else | |
12405 | { | |
12406 | SYMBOL_VALUE (sym) = value; | |
12407 | SYMBOL_CLASS (sym) = LOC_CONST; | |
12408 | } | |
2df3850c JM |
12409 | } |
12410 | ||
c906108c SS |
12411 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
12412 | ||
12413 | static struct type * | |
e7c27a73 | 12414 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12415 | { |
c906108c | 12416 | struct attribute *type_attr; |
c906108c | 12417 | |
e142c38c | 12418 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
12419 | if (!type_attr) |
12420 | { | |
12421 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 12422 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 12423 | } |
348e048f | 12424 | |
673bfd45 | 12425 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12426 | } |
12427 | ||
b4ba55a1 JB |
12428 | /* True iff CU's producer generates GNAT Ada auxiliary information |
12429 | that allows to find parallel types through that information instead | |
12430 | of having to do expensive parallel lookups by type name. */ | |
12431 | ||
12432 | static int | |
12433 | need_gnat_info (struct dwarf2_cu *cu) | |
12434 | { | |
12435 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
12436 | of GNAT produces this auxiliary information, without any indication | |
12437 | that it is produced. Part of enhancing the FSF version of GNAT | |
12438 | to produce that information will be to put in place an indicator | |
12439 | that we can use in order to determine whether the descriptive type | |
12440 | info is available or not. One suggestion that has been made is | |
12441 | to use a new attribute, attached to the CU die. For now, assume | |
12442 | that the descriptive type info is not available. */ | |
12443 | return 0; | |
12444 | } | |
12445 | ||
b4ba55a1 JB |
12446 | /* Return the auxiliary type of the die in question using its |
12447 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
12448 | attribute is not present. */ | |
12449 | ||
12450 | static struct type * | |
12451 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
12452 | { | |
b4ba55a1 | 12453 | struct attribute *type_attr; |
b4ba55a1 JB |
12454 | |
12455 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
12456 | if (!type_attr) | |
12457 | return NULL; | |
12458 | ||
673bfd45 | 12459 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
12460 | } |
12461 | ||
12462 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
12463 | descriptive type accordingly. */ | |
12464 | ||
12465 | static void | |
12466 | set_descriptive_type (struct type *type, struct die_info *die, | |
12467 | struct dwarf2_cu *cu) | |
12468 | { | |
12469 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
12470 | ||
12471 | if (descriptive_type) | |
12472 | { | |
12473 | ALLOCATE_GNAT_AUX_TYPE (type); | |
12474 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
12475 | } | |
12476 | } | |
12477 | ||
c906108c SS |
12478 | /* Return the containing type of the die in question using its |
12479 | DW_AT_containing_type attribute. */ | |
12480 | ||
12481 | static struct type * | |
e7c27a73 | 12482 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12483 | { |
c906108c | 12484 | struct attribute *type_attr; |
c906108c | 12485 | |
e142c38c | 12486 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
12487 | if (!type_attr) |
12488 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
12489 | "[in module %s]"), cu->objfile->name); | |
12490 | ||
673bfd45 | 12491 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
12492 | } |
12493 | ||
673bfd45 DE |
12494 | /* Look up the type of DIE in CU using its type attribute ATTR. |
12495 | If there is no type substitute an error marker. */ | |
12496 | ||
c906108c | 12497 | static struct type * |
673bfd45 DE |
12498 | lookup_die_type (struct die_info *die, struct attribute *attr, |
12499 | struct dwarf2_cu *cu) | |
c906108c | 12500 | { |
bb5ed363 | 12501 | struct objfile *objfile = cu->objfile; |
f792889a DJ |
12502 | struct type *this_type; |
12503 | ||
673bfd45 DE |
12504 | /* First see if we have it cached. */ |
12505 | ||
12506 | if (is_ref_attr (attr)) | |
12507 | { | |
b64f50a1 | 12508 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
673bfd45 DE |
12509 | |
12510 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
12511 | } | |
55f1336d | 12512 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
12513 | { |
12514 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
b64f50a1 | 12515 | sect_offset offset; |
673bfd45 DE |
12516 | |
12517 | /* sig_type will be NULL if the signatured type is missing from | |
12518 | the debug info. */ | |
12519 | if (sig_type == NULL) | |
12520 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12521 | "at 0x%x [in module %s]"), | |
b64f50a1 | 12522 | die->offset.sect_off, objfile->name); |
673bfd45 | 12523 | |
b0df02fd | 12524 | gdb_assert (sig_type->per_cu.debug_types_section); |
b64f50a1 JK |
12525 | offset.sect_off = (sig_type->per_cu.offset.sect_off |
12526 | + sig_type->type_offset.cu_off); | |
673bfd45 DE |
12527 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
12528 | } | |
12529 | else | |
12530 | { | |
12531 | dump_die_for_error (die); | |
12532 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
bb5ed363 | 12533 | dwarf_attr_name (attr->name), objfile->name); |
673bfd45 DE |
12534 | } |
12535 | ||
12536 | /* If not cached we need to read it in. */ | |
12537 | ||
12538 | if (this_type == NULL) | |
12539 | { | |
12540 | struct die_info *type_die; | |
12541 | struct dwarf2_cu *type_cu = cu; | |
12542 | ||
12543 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
12544 | /* If the type is cached, we should have found it above. */ | |
12545 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
12546 | this_type = read_type_die_1 (type_die, type_cu); | |
12547 | } | |
12548 | ||
12549 | /* If we still don't have a type use an error marker. */ | |
12550 | ||
12551 | if (this_type == NULL) | |
c906108c | 12552 | { |
b00fdb78 TT |
12553 | char *message, *saved; |
12554 | ||
12555 | /* read_type_die already issued a complaint. */ | |
12556 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
bb5ed363 | 12557 | objfile->name, |
b64f50a1 JK |
12558 | cu->header.offset.sect_off, |
12559 | die->offset.sect_off); | |
bb5ed363 | 12560 | saved = obstack_copy0 (&objfile->objfile_obstack, |
b00fdb78 TT |
12561 | message, strlen (message)); |
12562 | xfree (message); | |
12563 | ||
bb5ed363 | 12564 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
c906108c | 12565 | } |
673bfd45 | 12566 | |
f792889a | 12567 | return this_type; |
c906108c SS |
12568 | } |
12569 | ||
673bfd45 DE |
12570 | /* Return the type in DIE, CU. |
12571 | Returns NULL for invalid types. | |
12572 | ||
12573 | This first does a lookup in the appropriate type_hash table, | |
12574 | and only reads the die in if necessary. | |
12575 | ||
12576 | NOTE: This can be called when reading in partial or full symbols. */ | |
12577 | ||
f792889a | 12578 | static struct type * |
e7c27a73 | 12579 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12580 | { |
f792889a DJ |
12581 | struct type *this_type; |
12582 | ||
12583 | this_type = get_die_type (die, cu); | |
12584 | if (this_type) | |
12585 | return this_type; | |
12586 | ||
673bfd45 DE |
12587 | return read_type_die_1 (die, cu); |
12588 | } | |
12589 | ||
12590 | /* Read the type in DIE, CU. | |
12591 | Returns NULL for invalid types. */ | |
12592 | ||
12593 | static struct type * | |
12594 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
12595 | { | |
12596 | struct type *this_type = NULL; | |
12597 | ||
c906108c SS |
12598 | switch (die->tag) |
12599 | { | |
12600 | case DW_TAG_class_type: | |
680b30c7 | 12601 | case DW_TAG_interface_type: |
c906108c SS |
12602 | case DW_TAG_structure_type: |
12603 | case DW_TAG_union_type: | |
f792889a | 12604 | this_type = read_structure_type (die, cu); |
c906108c SS |
12605 | break; |
12606 | case DW_TAG_enumeration_type: | |
f792889a | 12607 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
12608 | break; |
12609 | case DW_TAG_subprogram: | |
12610 | case DW_TAG_subroutine_type: | |
edb3359d | 12611 | case DW_TAG_inlined_subroutine: |
f792889a | 12612 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
12613 | break; |
12614 | case DW_TAG_array_type: | |
f792889a | 12615 | this_type = read_array_type (die, cu); |
c906108c | 12616 | break; |
72019c9c | 12617 | case DW_TAG_set_type: |
f792889a | 12618 | this_type = read_set_type (die, cu); |
72019c9c | 12619 | break; |
c906108c | 12620 | case DW_TAG_pointer_type: |
f792889a | 12621 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
12622 | break; |
12623 | case DW_TAG_ptr_to_member_type: | |
f792889a | 12624 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
12625 | break; |
12626 | case DW_TAG_reference_type: | |
f792889a | 12627 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
12628 | break; |
12629 | case DW_TAG_const_type: | |
f792889a | 12630 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
12631 | break; |
12632 | case DW_TAG_volatile_type: | |
f792889a | 12633 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
12634 | break; |
12635 | case DW_TAG_string_type: | |
f792889a | 12636 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
12637 | break; |
12638 | case DW_TAG_typedef: | |
f792889a | 12639 | this_type = read_typedef (die, cu); |
c906108c | 12640 | break; |
a02abb62 | 12641 | case DW_TAG_subrange_type: |
f792889a | 12642 | this_type = read_subrange_type (die, cu); |
a02abb62 | 12643 | break; |
c906108c | 12644 | case DW_TAG_base_type: |
f792889a | 12645 | this_type = read_base_type (die, cu); |
c906108c | 12646 | break; |
81a17f79 | 12647 | case DW_TAG_unspecified_type: |
f792889a | 12648 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 12649 | break; |
0114d602 DJ |
12650 | case DW_TAG_namespace: |
12651 | this_type = read_namespace_type (die, cu); | |
12652 | break; | |
f55ee35c JK |
12653 | case DW_TAG_module: |
12654 | this_type = read_module_type (die, cu); | |
12655 | break; | |
c906108c | 12656 | default: |
3e43a32a MS |
12657 | complaint (&symfile_complaints, |
12658 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 12659 | dwarf_tag_name (die->tag)); |
c906108c SS |
12660 | break; |
12661 | } | |
63d06c5c | 12662 | |
f792889a | 12663 | return this_type; |
63d06c5c DC |
12664 | } |
12665 | ||
abc72ce4 DE |
12666 | /* See if we can figure out if the class lives in a namespace. We do |
12667 | this by looking for a member function; its demangled name will | |
12668 | contain namespace info, if there is any. | |
12669 | Return the computed name or NULL. | |
12670 | Space for the result is allocated on the objfile's obstack. | |
12671 | This is the full-die version of guess_partial_die_structure_name. | |
12672 | In this case we know DIE has no useful parent. */ | |
12673 | ||
12674 | static char * | |
12675 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
12676 | { | |
12677 | struct die_info *spec_die; | |
12678 | struct dwarf2_cu *spec_cu; | |
12679 | struct die_info *child; | |
12680 | ||
12681 | spec_cu = cu; | |
12682 | spec_die = die_specification (die, &spec_cu); | |
12683 | if (spec_die != NULL) | |
12684 | { | |
12685 | die = spec_die; | |
12686 | cu = spec_cu; | |
12687 | } | |
12688 | ||
12689 | for (child = die->child; | |
12690 | child != NULL; | |
12691 | child = child->sibling) | |
12692 | { | |
12693 | if (child->tag == DW_TAG_subprogram) | |
12694 | { | |
12695 | struct attribute *attr; | |
12696 | ||
12697 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
12698 | if (attr == NULL) | |
12699 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
12700 | if (attr != NULL) | |
12701 | { | |
12702 | char *actual_name | |
12703 | = language_class_name_from_physname (cu->language_defn, | |
12704 | DW_STRING (attr)); | |
12705 | char *name = NULL; | |
12706 | ||
12707 | if (actual_name != NULL) | |
12708 | { | |
12709 | char *die_name = dwarf2_name (die, cu); | |
12710 | ||
12711 | if (die_name != NULL | |
12712 | && strcmp (die_name, actual_name) != 0) | |
12713 | { | |
12714 | /* Strip off the class name from the full name. | |
12715 | We want the prefix. */ | |
12716 | int die_name_len = strlen (die_name); | |
12717 | int actual_name_len = strlen (actual_name); | |
12718 | ||
12719 | /* Test for '::' as a sanity check. */ | |
12720 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
12721 | && actual_name[actual_name_len |
12722 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
12723 | name = |
12724 | obsavestring (actual_name, | |
12725 | actual_name_len - die_name_len - 2, | |
12726 | &cu->objfile->objfile_obstack); | |
12727 | } | |
12728 | } | |
12729 | xfree (actual_name); | |
12730 | return name; | |
12731 | } | |
12732 | } | |
12733 | } | |
12734 | ||
12735 | return NULL; | |
12736 | } | |
12737 | ||
96408a79 SA |
12738 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
12739 | prefix part in such case. See | |
12740 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12741 | ||
12742 | static char * | |
12743 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) | |
12744 | { | |
12745 | struct attribute *attr; | |
12746 | char *base; | |
12747 | ||
12748 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type | |
12749 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) | |
12750 | return NULL; | |
12751 | ||
12752 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
12753 | if (attr != NULL && DW_STRING (attr) != NULL) | |
12754 | return NULL; | |
12755 | ||
12756 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12757 | if (attr == NULL) | |
12758 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12759 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12760 | return NULL; | |
12761 | ||
12762 | /* dwarf2_name had to be already called. */ | |
12763 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); | |
12764 | ||
12765 | /* Strip the base name, keep any leading namespaces/classes. */ | |
12766 | base = strrchr (DW_STRING (attr), ':'); | |
12767 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') | |
12768 | return ""; | |
12769 | ||
12770 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), | |
12771 | &cu->objfile->objfile_obstack); | |
12772 | } | |
12773 | ||
fdde2d81 | 12774 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 12775 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 12776 | |
0114d602 DJ |
12777 | For example, if we're within the method foo() in the following |
12778 | code: | |
12779 | ||
12780 | namespace N { | |
12781 | class C { | |
12782 | void foo () { | |
12783 | } | |
12784 | }; | |
12785 | } | |
12786 | ||
12787 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 | 12788 | |
0d5cff50 | 12789 | static const char * |
e142c38c | 12790 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 12791 | { |
0114d602 DJ |
12792 | struct die_info *parent, *spec_die; |
12793 | struct dwarf2_cu *spec_cu; | |
12794 | struct type *parent_type; | |
96408a79 | 12795 | char *retval; |
63d06c5c | 12796 | |
f55ee35c JK |
12797 | if (cu->language != language_cplus && cu->language != language_java |
12798 | && cu->language != language_fortran) | |
0114d602 DJ |
12799 | return ""; |
12800 | ||
96408a79 SA |
12801 | retval = anonymous_struct_prefix (die, cu); |
12802 | if (retval) | |
12803 | return retval; | |
12804 | ||
0114d602 DJ |
12805 | /* We have to be careful in the presence of DW_AT_specification. |
12806 | For example, with GCC 3.4, given the code | |
12807 | ||
12808 | namespace N { | |
12809 | void foo() { | |
12810 | // Definition of N::foo. | |
12811 | } | |
12812 | } | |
12813 | ||
12814 | then we'll have a tree of DIEs like this: | |
12815 | ||
12816 | 1: DW_TAG_compile_unit | |
12817 | 2: DW_TAG_namespace // N | |
12818 | 3: DW_TAG_subprogram // declaration of N::foo | |
12819 | 4: DW_TAG_subprogram // definition of N::foo | |
12820 | DW_AT_specification // refers to die #3 | |
12821 | ||
12822 | Thus, when processing die #4, we have to pretend that we're in | |
12823 | the context of its DW_AT_specification, namely the contex of die | |
12824 | #3. */ | |
12825 | spec_cu = cu; | |
12826 | spec_die = die_specification (die, &spec_cu); | |
12827 | if (spec_die == NULL) | |
12828 | parent = die->parent; | |
12829 | else | |
63d06c5c | 12830 | { |
0114d602 DJ |
12831 | parent = spec_die->parent; |
12832 | cu = spec_cu; | |
63d06c5c | 12833 | } |
0114d602 DJ |
12834 | |
12835 | if (parent == NULL) | |
12836 | return ""; | |
98bfdba5 PA |
12837 | else if (parent->building_fullname) |
12838 | { | |
12839 | const char *name; | |
12840 | const char *parent_name; | |
12841 | ||
12842 | /* It has been seen on RealView 2.2 built binaries, | |
12843 | DW_TAG_template_type_param types actually _defined_ as | |
12844 | children of the parent class: | |
12845 | ||
12846 | enum E {}; | |
12847 | template class <class Enum> Class{}; | |
12848 | Class<enum E> class_e; | |
12849 | ||
12850 | 1: DW_TAG_class_type (Class) | |
12851 | 2: DW_TAG_enumeration_type (E) | |
12852 | 3: DW_TAG_enumerator (enum1:0) | |
12853 | 3: DW_TAG_enumerator (enum2:1) | |
12854 | ... | |
12855 | 2: DW_TAG_template_type_param | |
12856 | DW_AT_type DW_FORM_ref_udata (E) | |
12857 | ||
12858 | Besides being broken debug info, it can put GDB into an | |
12859 | infinite loop. Consider: | |
12860 | ||
12861 | When we're building the full name for Class<E>, we'll start | |
12862 | at Class, and go look over its template type parameters, | |
12863 | finding E. We'll then try to build the full name of E, and | |
12864 | reach here. We're now trying to build the full name of E, | |
12865 | and look over the parent DIE for containing scope. In the | |
12866 | broken case, if we followed the parent DIE of E, we'd again | |
12867 | find Class, and once again go look at its template type | |
12868 | arguments, etc., etc. Simply don't consider such parent die | |
12869 | as source-level parent of this die (it can't be, the language | |
12870 | doesn't allow it), and break the loop here. */ | |
12871 | name = dwarf2_name (die, cu); | |
12872 | parent_name = dwarf2_name (parent, cu); | |
12873 | complaint (&symfile_complaints, | |
12874 | _("template param type '%s' defined within parent '%s'"), | |
12875 | name ? name : "<unknown>", | |
12876 | parent_name ? parent_name : "<unknown>"); | |
12877 | return ""; | |
12878 | } | |
63d06c5c | 12879 | else |
0114d602 DJ |
12880 | switch (parent->tag) |
12881 | { | |
63d06c5c | 12882 | case DW_TAG_namespace: |
0114d602 | 12883 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
12884 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
12885 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
12886 | Work around this problem here. */ | |
12887 | if (cu->language == language_cplus | |
12888 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
12889 | return ""; | |
0114d602 DJ |
12890 | /* We give a name to even anonymous namespaces. */ |
12891 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 12892 | case DW_TAG_class_type: |
680b30c7 | 12893 | case DW_TAG_interface_type: |
63d06c5c | 12894 | case DW_TAG_structure_type: |
0114d602 | 12895 | case DW_TAG_union_type: |
f55ee35c | 12896 | case DW_TAG_module: |
0114d602 DJ |
12897 | parent_type = read_type_die (parent, cu); |
12898 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
12899 | return TYPE_TAG_NAME (parent_type); | |
12900 | else | |
12901 | /* An anonymous structure is only allowed non-static data | |
12902 | members; no typedefs, no member functions, et cetera. | |
12903 | So it does not need a prefix. */ | |
12904 | return ""; | |
abc72ce4 DE |
12905 | case DW_TAG_compile_unit: |
12906 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
12907 | if (cu->language == language_cplus | |
8b70b953 | 12908 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
abc72ce4 DE |
12909 | && die->child != NULL |
12910 | && (die->tag == DW_TAG_class_type | |
12911 | || die->tag == DW_TAG_structure_type | |
12912 | || die->tag == DW_TAG_union_type)) | |
12913 | { | |
12914 | char *name = guess_full_die_structure_name (die, cu); | |
12915 | if (name != NULL) | |
12916 | return name; | |
12917 | } | |
12918 | return ""; | |
63d06c5c | 12919 | default: |
8176b9b8 | 12920 | return determine_prefix (parent, cu); |
63d06c5c | 12921 | } |
63d06c5c DC |
12922 | } |
12923 | ||
3e43a32a MS |
12924 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
12925 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
12926 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
12927 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
12928 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 12929 | |
f55ee35c | 12930 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
12931 | |
12932 | static char * | |
f55ee35c JK |
12933 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
12934 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 12935 | { |
f55ee35c | 12936 | const char *lead = ""; |
5c315b68 | 12937 | const char *sep; |
63d06c5c | 12938 | |
3e43a32a MS |
12939 | if (suffix == NULL || suffix[0] == '\0' |
12940 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
12941 | sep = ""; |
12942 | else if (cu->language == language_java) | |
12943 | sep = "."; | |
f55ee35c JK |
12944 | else if (cu->language == language_fortran && physname) |
12945 | { | |
12946 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
12947 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
12948 | ||
12949 | lead = "__"; | |
12950 | sep = "_MOD_"; | |
12951 | } | |
987504bb JJ |
12952 | else |
12953 | sep = "::"; | |
63d06c5c | 12954 | |
6dd47d34 DE |
12955 | if (prefix == NULL) |
12956 | prefix = ""; | |
12957 | if (suffix == NULL) | |
12958 | suffix = ""; | |
12959 | ||
987504bb JJ |
12960 | if (obs == NULL) |
12961 | { | |
3e43a32a MS |
12962 | char *retval |
12963 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 12964 | |
f55ee35c JK |
12965 | strcpy (retval, lead); |
12966 | strcat (retval, prefix); | |
6dd47d34 DE |
12967 | strcat (retval, sep); |
12968 | strcat (retval, suffix); | |
63d06c5c DC |
12969 | return retval; |
12970 | } | |
987504bb JJ |
12971 | else |
12972 | { | |
12973 | /* We have an obstack. */ | |
f55ee35c | 12974 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 12975 | } |
63d06c5c DC |
12976 | } |
12977 | ||
c906108c SS |
12978 | /* Return sibling of die, NULL if no sibling. */ |
12979 | ||
f9aca02d | 12980 | static struct die_info * |
fba45db2 | 12981 | sibling_die (struct die_info *die) |
c906108c | 12982 | { |
639d11d3 | 12983 | return die->sibling; |
c906108c SS |
12984 | } |
12985 | ||
71c25dea TT |
12986 | /* Get name of a die, return NULL if not found. */ |
12987 | ||
12988 | static char * | |
12989 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
12990 | struct obstack *obstack) | |
12991 | { | |
12992 | if (name && cu->language == language_cplus) | |
12993 | { | |
12994 | char *canon_name = cp_canonicalize_string (name); | |
12995 | ||
12996 | if (canon_name != NULL) | |
12997 | { | |
12998 | if (strcmp (canon_name, name) != 0) | |
12999 | name = obsavestring (canon_name, strlen (canon_name), | |
13000 | obstack); | |
13001 | xfree (canon_name); | |
13002 | } | |
13003 | } | |
13004 | ||
13005 | return name; | |
c906108c SS |
13006 | } |
13007 | ||
9219021c DC |
13008 | /* Get name of a die, return NULL if not found. */ |
13009 | ||
13010 | static char * | |
e142c38c | 13011 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
13012 | { |
13013 | struct attribute *attr; | |
13014 | ||
e142c38c | 13015 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
13016 | if ((!attr || !DW_STRING (attr)) |
13017 | && die->tag != DW_TAG_class_type | |
13018 | && die->tag != DW_TAG_interface_type | |
13019 | && die->tag != DW_TAG_structure_type | |
13020 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
13021 | return NULL; |
13022 | ||
13023 | switch (die->tag) | |
13024 | { | |
13025 | case DW_TAG_compile_unit: | |
13026 | /* Compilation units have a DW_AT_name that is a filename, not | |
13027 | a source language identifier. */ | |
13028 | case DW_TAG_enumeration_type: | |
13029 | case DW_TAG_enumerator: | |
13030 | /* These tags always have simple identifiers already; no need | |
13031 | to canonicalize them. */ | |
13032 | return DW_STRING (attr); | |
907af001 | 13033 | |
418835cc KS |
13034 | case DW_TAG_subprogram: |
13035 | /* Java constructors will all be named "<init>", so return | |
13036 | the class name when we see this special case. */ | |
13037 | if (cu->language == language_java | |
13038 | && DW_STRING (attr) != NULL | |
13039 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
13040 | { | |
13041 | struct dwarf2_cu *spec_cu = cu; | |
13042 | struct die_info *spec_die; | |
13043 | ||
13044 | /* GCJ will output '<init>' for Java constructor names. | |
13045 | For this special case, return the name of the parent class. */ | |
13046 | ||
13047 | /* GCJ may output suprogram DIEs with AT_specification set. | |
13048 | If so, use the name of the specified DIE. */ | |
13049 | spec_die = die_specification (die, &spec_cu); | |
13050 | if (spec_die != NULL) | |
13051 | return dwarf2_name (spec_die, spec_cu); | |
13052 | ||
13053 | do | |
13054 | { | |
13055 | die = die->parent; | |
13056 | if (die->tag == DW_TAG_class_type) | |
13057 | return dwarf2_name (die, cu); | |
13058 | } | |
13059 | while (die->tag != DW_TAG_compile_unit); | |
13060 | } | |
907af001 UW |
13061 | break; |
13062 | ||
13063 | case DW_TAG_class_type: | |
13064 | case DW_TAG_interface_type: | |
13065 | case DW_TAG_structure_type: | |
13066 | case DW_TAG_union_type: | |
13067 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
13068 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
13069 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
13070 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
13071 | if (attr && DW_STRING (attr) |
13072 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
13073 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 13074 | return NULL; |
53832f31 TT |
13075 | |
13076 | /* GCC might emit a nameless typedef that has a linkage name. See | |
13077 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
13078 | if (!attr || DW_STRING (attr) == NULL) | |
13079 | { | |
df5c6c50 | 13080 | char *demangled = NULL; |
53832f31 TT |
13081 | |
13082 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
13083 | if (attr == NULL) | |
13084 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
13085 | ||
13086 | if (attr == NULL || DW_STRING (attr) == NULL) | |
13087 | return NULL; | |
13088 | ||
df5c6c50 JK |
13089 | /* Avoid demangling DW_STRING (attr) the second time on a second |
13090 | call for the same DIE. */ | |
13091 | if (!DW_STRING_IS_CANONICAL (attr)) | |
13092 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
13093 | |
13094 | if (demangled) | |
13095 | { | |
96408a79 SA |
13096 | char *base; |
13097 | ||
53832f31 | 13098 | /* FIXME: we already did this for the partial symbol... */ |
96408a79 SA |
13099 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
13100 | &cu->objfile->objfile_obstack); | |
53832f31 TT |
13101 | DW_STRING_IS_CANONICAL (attr) = 1; |
13102 | xfree (demangled); | |
96408a79 SA |
13103 | |
13104 | /* Strip any leading namespaces/classes, keep only the base name. | |
13105 | DW_AT_name for named DIEs does not contain the prefixes. */ | |
13106 | base = strrchr (DW_STRING (attr), ':'); | |
13107 | if (base && base > DW_STRING (attr) && base[-1] == ':') | |
13108 | return &base[1]; | |
13109 | else | |
13110 | return DW_STRING (attr); | |
53832f31 TT |
13111 | } |
13112 | } | |
907af001 UW |
13113 | break; |
13114 | ||
71c25dea | 13115 | default: |
907af001 UW |
13116 | break; |
13117 | } | |
13118 | ||
13119 | if (!DW_STRING_IS_CANONICAL (attr)) | |
13120 | { | |
13121 | DW_STRING (attr) | |
13122 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
13123 | &cu->objfile->objfile_obstack); | |
13124 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 13125 | } |
907af001 | 13126 | return DW_STRING (attr); |
9219021c DC |
13127 | } |
13128 | ||
13129 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
13130 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
13131 | containing the return value on output. */ | |
9219021c DC |
13132 | |
13133 | static struct die_info * | |
f2f0e013 | 13134 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
13135 | { |
13136 | struct attribute *attr; | |
9219021c | 13137 | |
f2f0e013 | 13138 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
13139 | if (attr == NULL) |
13140 | return NULL; | |
13141 | ||
f2f0e013 | 13142 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
13143 | } |
13144 | ||
c906108c SS |
13145 | /* Convert a DIE tag into its string name. */ |
13146 | ||
13147 | static char * | |
aa1ee363 | 13148 | dwarf_tag_name (unsigned tag) |
c906108c SS |
13149 | { |
13150 | switch (tag) | |
13151 | { | |
13152 | case DW_TAG_padding: | |
13153 | return "DW_TAG_padding"; | |
13154 | case DW_TAG_array_type: | |
13155 | return "DW_TAG_array_type"; | |
13156 | case DW_TAG_class_type: | |
13157 | return "DW_TAG_class_type"; | |
13158 | case DW_TAG_entry_point: | |
13159 | return "DW_TAG_entry_point"; | |
13160 | case DW_TAG_enumeration_type: | |
13161 | return "DW_TAG_enumeration_type"; | |
13162 | case DW_TAG_formal_parameter: | |
13163 | return "DW_TAG_formal_parameter"; | |
13164 | case DW_TAG_imported_declaration: | |
13165 | return "DW_TAG_imported_declaration"; | |
13166 | case DW_TAG_label: | |
13167 | return "DW_TAG_label"; | |
13168 | case DW_TAG_lexical_block: | |
13169 | return "DW_TAG_lexical_block"; | |
13170 | case DW_TAG_member: | |
13171 | return "DW_TAG_member"; | |
13172 | case DW_TAG_pointer_type: | |
13173 | return "DW_TAG_pointer_type"; | |
13174 | case DW_TAG_reference_type: | |
13175 | return "DW_TAG_reference_type"; | |
13176 | case DW_TAG_compile_unit: | |
13177 | return "DW_TAG_compile_unit"; | |
13178 | case DW_TAG_string_type: | |
13179 | return "DW_TAG_string_type"; | |
13180 | case DW_TAG_structure_type: | |
13181 | return "DW_TAG_structure_type"; | |
13182 | case DW_TAG_subroutine_type: | |
13183 | return "DW_TAG_subroutine_type"; | |
13184 | case DW_TAG_typedef: | |
13185 | return "DW_TAG_typedef"; | |
13186 | case DW_TAG_union_type: | |
13187 | return "DW_TAG_union_type"; | |
13188 | case DW_TAG_unspecified_parameters: | |
13189 | return "DW_TAG_unspecified_parameters"; | |
13190 | case DW_TAG_variant: | |
13191 | return "DW_TAG_variant"; | |
13192 | case DW_TAG_common_block: | |
13193 | return "DW_TAG_common_block"; | |
13194 | case DW_TAG_common_inclusion: | |
13195 | return "DW_TAG_common_inclusion"; | |
13196 | case DW_TAG_inheritance: | |
13197 | return "DW_TAG_inheritance"; | |
13198 | case DW_TAG_inlined_subroutine: | |
13199 | return "DW_TAG_inlined_subroutine"; | |
13200 | case DW_TAG_module: | |
13201 | return "DW_TAG_module"; | |
13202 | case DW_TAG_ptr_to_member_type: | |
13203 | return "DW_TAG_ptr_to_member_type"; | |
13204 | case DW_TAG_set_type: | |
13205 | return "DW_TAG_set_type"; | |
13206 | case DW_TAG_subrange_type: | |
13207 | return "DW_TAG_subrange_type"; | |
13208 | case DW_TAG_with_stmt: | |
13209 | return "DW_TAG_with_stmt"; | |
13210 | case DW_TAG_access_declaration: | |
13211 | return "DW_TAG_access_declaration"; | |
13212 | case DW_TAG_base_type: | |
13213 | return "DW_TAG_base_type"; | |
13214 | case DW_TAG_catch_block: | |
13215 | return "DW_TAG_catch_block"; | |
13216 | case DW_TAG_const_type: | |
13217 | return "DW_TAG_const_type"; | |
13218 | case DW_TAG_constant: | |
13219 | return "DW_TAG_constant"; | |
13220 | case DW_TAG_enumerator: | |
13221 | return "DW_TAG_enumerator"; | |
13222 | case DW_TAG_file_type: | |
13223 | return "DW_TAG_file_type"; | |
13224 | case DW_TAG_friend: | |
13225 | return "DW_TAG_friend"; | |
13226 | case DW_TAG_namelist: | |
13227 | return "DW_TAG_namelist"; | |
13228 | case DW_TAG_namelist_item: | |
13229 | return "DW_TAG_namelist_item"; | |
13230 | case DW_TAG_packed_type: | |
13231 | return "DW_TAG_packed_type"; | |
13232 | case DW_TAG_subprogram: | |
13233 | return "DW_TAG_subprogram"; | |
13234 | case DW_TAG_template_type_param: | |
13235 | return "DW_TAG_template_type_param"; | |
13236 | case DW_TAG_template_value_param: | |
13237 | return "DW_TAG_template_value_param"; | |
13238 | case DW_TAG_thrown_type: | |
13239 | return "DW_TAG_thrown_type"; | |
13240 | case DW_TAG_try_block: | |
13241 | return "DW_TAG_try_block"; | |
13242 | case DW_TAG_variant_part: | |
13243 | return "DW_TAG_variant_part"; | |
13244 | case DW_TAG_variable: | |
13245 | return "DW_TAG_variable"; | |
13246 | case DW_TAG_volatile_type: | |
13247 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
13248 | case DW_TAG_dwarf_procedure: |
13249 | return "DW_TAG_dwarf_procedure"; | |
13250 | case DW_TAG_restrict_type: | |
13251 | return "DW_TAG_restrict_type"; | |
13252 | case DW_TAG_interface_type: | |
13253 | return "DW_TAG_interface_type"; | |
13254 | case DW_TAG_namespace: | |
13255 | return "DW_TAG_namespace"; | |
13256 | case DW_TAG_imported_module: | |
13257 | return "DW_TAG_imported_module"; | |
13258 | case DW_TAG_unspecified_type: | |
13259 | return "DW_TAG_unspecified_type"; | |
13260 | case DW_TAG_partial_unit: | |
13261 | return "DW_TAG_partial_unit"; | |
13262 | case DW_TAG_imported_unit: | |
13263 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
13264 | case DW_TAG_condition: |
13265 | return "DW_TAG_condition"; | |
13266 | case DW_TAG_shared_type: | |
13267 | return "DW_TAG_shared_type"; | |
348e048f DE |
13268 | case DW_TAG_type_unit: |
13269 | return "DW_TAG_type_unit"; | |
c906108c SS |
13270 | case DW_TAG_MIPS_loop: |
13271 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
13272 | case DW_TAG_HP_array_descriptor: |
13273 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
13274 | case DW_TAG_format_label: |
13275 | return "DW_TAG_format_label"; | |
13276 | case DW_TAG_function_template: | |
13277 | return "DW_TAG_function_template"; | |
13278 | case DW_TAG_class_template: | |
13279 | return "DW_TAG_class_template"; | |
b7619582 GF |
13280 | case DW_TAG_GNU_BINCL: |
13281 | return "DW_TAG_GNU_BINCL"; | |
13282 | case DW_TAG_GNU_EINCL: | |
13283 | return "DW_TAG_GNU_EINCL"; | |
13284 | case DW_TAG_upc_shared_type: | |
13285 | return "DW_TAG_upc_shared_type"; | |
13286 | case DW_TAG_upc_strict_type: | |
13287 | return "DW_TAG_upc_strict_type"; | |
13288 | case DW_TAG_upc_relaxed_type: | |
13289 | return "DW_TAG_upc_relaxed_type"; | |
13290 | case DW_TAG_PGI_kanji_type: | |
13291 | return "DW_TAG_PGI_kanji_type"; | |
13292 | case DW_TAG_PGI_interface_block: | |
13293 | return "DW_TAG_PGI_interface_block"; | |
96408a79 SA |
13294 | case DW_TAG_GNU_call_site: |
13295 | return "DW_TAG_GNU_call_site"; | |
c906108c SS |
13296 | default: |
13297 | return "DW_TAG_<unknown>"; | |
13298 | } | |
13299 | } | |
13300 | ||
13301 | /* Convert a DWARF attribute code into its string name. */ | |
13302 | ||
13303 | static char * | |
aa1ee363 | 13304 | dwarf_attr_name (unsigned attr) |
c906108c SS |
13305 | { |
13306 | switch (attr) | |
13307 | { | |
13308 | case DW_AT_sibling: | |
13309 | return "DW_AT_sibling"; | |
13310 | case DW_AT_location: | |
13311 | return "DW_AT_location"; | |
13312 | case DW_AT_name: | |
13313 | return "DW_AT_name"; | |
13314 | case DW_AT_ordering: | |
13315 | return "DW_AT_ordering"; | |
13316 | case DW_AT_subscr_data: | |
13317 | return "DW_AT_subscr_data"; | |
13318 | case DW_AT_byte_size: | |
13319 | return "DW_AT_byte_size"; | |
13320 | case DW_AT_bit_offset: | |
13321 | return "DW_AT_bit_offset"; | |
13322 | case DW_AT_bit_size: | |
13323 | return "DW_AT_bit_size"; | |
13324 | case DW_AT_element_list: | |
13325 | return "DW_AT_element_list"; | |
13326 | case DW_AT_stmt_list: | |
13327 | return "DW_AT_stmt_list"; | |
13328 | case DW_AT_low_pc: | |
13329 | return "DW_AT_low_pc"; | |
13330 | case DW_AT_high_pc: | |
13331 | return "DW_AT_high_pc"; | |
13332 | case DW_AT_language: | |
13333 | return "DW_AT_language"; | |
13334 | case DW_AT_member: | |
13335 | return "DW_AT_member"; | |
13336 | case DW_AT_discr: | |
13337 | return "DW_AT_discr"; | |
13338 | case DW_AT_discr_value: | |
13339 | return "DW_AT_discr_value"; | |
13340 | case DW_AT_visibility: | |
13341 | return "DW_AT_visibility"; | |
13342 | case DW_AT_import: | |
13343 | return "DW_AT_import"; | |
13344 | case DW_AT_string_length: | |
13345 | return "DW_AT_string_length"; | |
13346 | case DW_AT_common_reference: | |
13347 | return "DW_AT_common_reference"; | |
13348 | case DW_AT_comp_dir: | |
13349 | return "DW_AT_comp_dir"; | |
13350 | case DW_AT_const_value: | |
13351 | return "DW_AT_const_value"; | |
13352 | case DW_AT_containing_type: | |
13353 | return "DW_AT_containing_type"; | |
13354 | case DW_AT_default_value: | |
13355 | return "DW_AT_default_value"; | |
13356 | case DW_AT_inline: | |
13357 | return "DW_AT_inline"; | |
13358 | case DW_AT_is_optional: | |
13359 | return "DW_AT_is_optional"; | |
13360 | case DW_AT_lower_bound: | |
13361 | return "DW_AT_lower_bound"; | |
13362 | case DW_AT_producer: | |
13363 | return "DW_AT_producer"; | |
13364 | case DW_AT_prototyped: | |
13365 | return "DW_AT_prototyped"; | |
13366 | case DW_AT_return_addr: | |
13367 | return "DW_AT_return_addr"; | |
13368 | case DW_AT_start_scope: | |
13369 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
13370 | case DW_AT_bit_stride: |
13371 | return "DW_AT_bit_stride"; | |
c906108c SS |
13372 | case DW_AT_upper_bound: |
13373 | return "DW_AT_upper_bound"; | |
13374 | case DW_AT_abstract_origin: | |
13375 | return "DW_AT_abstract_origin"; | |
13376 | case DW_AT_accessibility: | |
13377 | return "DW_AT_accessibility"; | |
13378 | case DW_AT_address_class: | |
13379 | return "DW_AT_address_class"; | |
13380 | case DW_AT_artificial: | |
13381 | return "DW_AT_artificial"; | |
13382 | case DW_AT_base_types: | |
13383 | return "DW_AT_base_types"; | |
13384 | case DW_AT_calling_convention: | |
13385 | return "DW_AT_calling_convention"; | |
13386 | case DW_AT_count: | |
13387 | return "DW_AT_count"; | |
13388 | case DW_AT_data_member_location: | |
13389 | return "DW_AT_data_member_location"; | |
13390 | case DW_AT_decl_column: | |
13391 | return "DW_AT_decl_column"; | |
13392 | case DW_AT_decl_file: | |
13393 | return "DW_AT_decl_file"; | |
13394 | case DW_AT_decl_line: | |
13395 | return "DW_AT_decl_line"; | |
13396 | case DW_AT_declaration: | |
13397 | return "DW_AT_declaration"; | |
13398 | case DW_AT_discr_list: | |
13399 | return "DW_AT_discr_list"; | |
13400 | case DW_AT_encoding: | |
13401 | return "DW_AT_encoding"; | |
13402 | case DW_AT_external: | |
13403 | return "DW_AT_external"; | |
13404 | case DW_AT_frame_base: | |
13405 | return "DW_AT_frame_base"; | |
13406 | case DW_AT_friend: | |
13407 | return "DW_AT_friend"; | |
13408 | case DW_AT_identifier_case: | |
13409 | return "DW_AT_identifier_case"; | |
13410 | case DW_AT_macro_info: | |
13411 | return "DW_AT_macro_info"; | |
13412 | case DW_AT_namelist_items: | |
13413 | return "DW_AT_namelist_items"; | |
13414 | case DW_AT_priority: | |
13415 | return "DW_AT_priority"; | |
13416 | case DW_AT_segment: | |
13417 | return "DW_AT_segment"; | |
13418 | case DW_AT_specification: | |
13419 | return "DW_AT_specification"; | |
13420 | case DW_AT_static_link: | |
13421 | return "DW_AT_static_link"; | |
13422 | case DW_AT_type: | |
13423 | return "DW_AT_type"; | |
13424 | case DW_AT_use_location: | |
13425 | return "DW_AT_use_location"; | |
13426 | case DW_AT_variable_parameter: | |
13427 | return "DW_AT_variable_parameter"; | |
13428 | case DW_AT_virtuality: | |
13429 | return "DW_AT_virtuality"; | |
13430 | case DW_AT_vtable_elem_location: | |
13431 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 13432 | /* DWARF 3 values. */ |
d9fa45fe DC |
13433 | case DW_AT_allocated: |
13434 | return "DW_AT_allocated"; | |
13435 | case DW_AT_associated: | |
13436 | return "DW_AT_associated"; | |
13437 | case DW_AT_data_location: | |
13438 | return "DW_AT_data_location"; | |
09fa0d7c JK |
13439 | case DW_AT_byte_stride: |
13440 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
13441 | case DW_AT_entry_pc: |
13442 | return "DW_AT_entry_pc"; | |
13443 | case DW_AT_use_UTF8: | |
13444 | return "DW_AT_use_UTF8"; | |
13445 | case DW_AT_extension: | |
13446 | return "DW_AT_extension"; | |
13447 | case DW_AT_ranges: | |
13448 | return "DW_AT_ranges"; | |
13449 | case DW_AT_trampoline: | |
13450 | return "DW_AT_trampoline"; | |
13451 | case DW_AT_call_column: | |
13452 | return "DW_AT_call_column"; | |
13453 | case DW_AT_call_file: | |
13454 | return "DW_AT_call_file"; | |
13455 | case DW_AT_call_line: | |
13456 | return "DW_AT_call_line"; | |
b7619582 GF |
13457 | case DW_AT_description: |
13458 | return "DW_AT_description"; | |
13459 | case DW_AT_binary_scale: | |
13460 | return "DW_AT_binary_scale"; | |
13461 | case DW_AT_decimal_scale: | |
13462 | return "DW_AT_decimal_scale"; | |
13463 | case DW_AT_small: | |
13464 | return "DW_AT_small"; | |
13465 | case DW_AT_decimal_sign: | |
13466 | return "DW_AT_decimal_sign"; | |
13467 | case DW_AT_digit_count: | |
13468 | return "DW_AT_digit_count"; | |
13469 | case DW_AT_picture_string: | |
13470 | return "DW_AT_picture_string"; | |
13471 | case DW_AT_mutable: | |
13472 | return "DW_AT_mutable"; | |
13473 | case DW_AT_threads_scaled: | |
13474 | return "DW_AT_threads_scaled"; | |
13475 | case DW_AT_explicit: | |
13476 | return "DW_AT_explicit"; | |
13477 | case DW_AT_object_pointer: | |
13478 | return "DW_AT_object_pointer"; | |
13479 | case DW_AT_endianity: | |
13480 | return "DW_AT_endianity"; | |
13481 | case DW_AT_elemental: | |
13482 | return "DW_AT_elemental"; | |
13483 | case DW_AT_pure: | |
13484 | return "DW_AT_pure"; | |
13485 | case DW_AT_recursive: | |
13486 | return "DW_AT_recursive"; | |
348e048f DE |
13487 | /* DWARF 4 values. */ |
13488 | case DW_AT_signature: | |
13489 | return "DW_AT_signature"; | |
31ef98ae TT |
13490 | case DW_AT_linkage_name: |
13491 | return "DW_AT_linkage_name"; | |
b7619582 | 13492 | /* SGI/MIPS extensions. */ |
c764a876 | 13493 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
13494 | case DW_AT_MIPS_fde: |
13495 | return "DW_AT_MIPS_fde"; | |
c764a876 | 13496 | #endif |
c906108c SS |
13497 | case DW_AT_MIPS_loop_begin: |
13498 | return "DW_AT_MIPS_loop_begin"; | |
13499 | case DW_AT_MIPS_tail_loop_begin: | |
13500 | return "DW_AT_MIPS_tail_loop_begin"; | |
13501 | case DW_AT_MIPS_epilog_begin: | |
13502 | return "DW_AT_MIPS_epilog_begin"; | |
13503 | case DW_AT_MIPS_loop_unroll_factor: | |
13504 | return "DW_AT_MIPS_loop_unroll_factor"; | |
13505 | case DW_AT_MIPS_software_pipeline_depth: | |
13506 | return "DW_AT_MIPS_software_pipeline_depth"; | |
13507 | case DW_AT_MIPS_linkage_name: | |
13508 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
13509 | case DW_AT_MIPS_stride: |
13510 | return "DW_AT_MIPS_stride"; | |
13511 | case DW_AT_MIPS_abstract_name: | |
13512 | return "DW_AT_MIPS_abstract_name"; | |
13513 | case DW_AT_MIPS_clone_origin: | |
13514 | return "DW_AT_MIPS_clone_origin"; | |
13515 | case DW_AT_MIPS_has_inlines: | |
13516 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 13517 | /* HP extensions. */ |
c764a876 | 13518 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
13519 | case DW_AT_HP_block_index: |
13520 | return "DW_AT_HP_block_index"; | |
c764a876 | 13521 | #endif |
b7619582 GF |
13522 | case DW_AT_HP_unmodifiable: |
13523 | return "DW_AT_HP_unmodifiable"; | |
13524 | case DW_AT_HP_actuals_stmt_list: | |
13525 | return "DW_AT_HP_actuals_stmt_list"; | |
13526 | case DW_AT_HP_proc_per_section: | |
13527 | return "DW_AT_HP_proc_per_section"; | |
13528 | case DW_AT_HP_raw_data_ptr: | |
13529 | return "DW_AT_HP_raw_data_ptr"; | |
13530 | case DW_AT_HP_pass_by_reference: | |
13531 | return "DW_AT_HP_pass_by_reference"; | |
13532 | case DW_AT_HP_opt_level: | |
13533 | return "DW_AT_HP_opt_level"; | |
13534 | case DW_AT_HP_prof_version_id: | |
13535 | return "DW_AT_HP_prof_version_id"; | |
13536 | case DW_AT_HP_opt_flags: | |
13537 | return "DW_AT_HP_opt_flags"; | |
13538 | case DW_AT_HP_cold_region_low_pc: | |
13539 | return "DW_AT_HP_cold_region_low_pc"; | |
13540 | case DW_AT_HP_cold_region_high_pc: | |
13541 | return "DW_AT_HP_cold_region_high_pc"; | |
13542 | case DW_AT_HP_all_variables_modifiable: | |
13543 | return "DW_AT_HP_all_variables_modifiable"; | |
13544 | case DW_AT_HP_linkage_name: | |
13545 | return "DW_AT_HP_linkage_name"; | |
13546 | case DW_AT_HP_prof_flags: | |
13547 | return "DW_AT_HP_prof_flags"; | |
13548 | /* GNU extensions. */ | |
c906108c SS |
13549 | case DW_AT_sf_names: |
13550 | return "DW_AT_sf_names"; | |
13551 | case DW_AT_src_info: | |
13552 | return "DW_AT_src_info"; | |
13553 | case DW_AT_mac_info: | |
13554 | return "DW_AT_mac_info"; | |
13555 | case DW_AT_src_coords: | |
13556 | return "DW_AT_src_coords"; | |
13557 | case DW_AT_body_begin: | |
13558 | return "DW_AT_body_begin"; | |
13559 | case DW_AT_body_end: | |
13560 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
13561 | case DW_AT_GNU_vector: |
13562 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
13563 | case DW_AT_GNU_odr_signature: |
13564 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
13565 | /* VMS extensions. */ |
13566 | case DW_AT_VMS_rtnbeg_pd_address: | |
13567 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
13568 | /* UPC extension. */ | |
13569 | case DW_AT_upc_threads_scaled: | |
13570 | return "DW_AT_upc_threads_scaled"; | |
13571 | /* PGI (STMicroelectronics) extensions. */ | |
13572 | case DW_AT_PGI_lbase: | |
13573 | return "DW_AT_PGI_lbase"; | |
13574 | case DW_AT_PGI_soffset: | |
13575 | return "DW_AT_PGI_soffset"; | |
13576 | case DW_AT_PGI_lstride: | |
13577 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
13578 | default: |
13579 | return "DW_AT_<unknown>"; | |
13580 | } | |
13581 | } | |
13582 | ||
13583 | /* Convert a DWARF value form code into its string name. */ | |
13584 | ||
13585 | static char * | |
aa1ee363 | 13586 | dwarf_form_name (unsigned form) |
c906108c SS |
13587 | { |
13588 | switch (form) | |
13589 | { | |
13590 | case DW_FORM_addr: | |
13591 | return "DW_FORM_addr"; | |
13592 | case DW_FORM_block2: | |
13593 | return "DW_FORM_block2"; | |
13594 | case DW_FORM_block4: | |
13595 | return "DW_FORM_block4"; | |
13596 | case DW_FORM_data2: | |
13597 | return "DW_FORM_data2"; | |
13598 | case DW_FORM_data4: | |
13599 | return "DW_FORM_data4"; | |
13600 | case DW_FORM_data8: | |
13601 | return "DW_FORM_data8"; | |
13602 | case DW_FORM_string: | |
13603 | return "DW_FORM_string"; | |
13604 | case DW_FORM_block: | |
13605 | return "DW_FORM_block"; | |
13606 | case DW_FORM_block1: | |
13607 | return "DW_FORM_block1"; | |
13608 | case DW_FORM_data1: | |
13609 | return "DW_FORM_data1"; | |
13610 | case DW_FORM_flag: | |
13611 | return "DW_FORM_flag"; | |
13612 | case DW_FORM_sdata: | |
13613 | return "DW_FORM_sdata"; | |
13614 | case DW_FORM_strp: | |
13615 | return "DW_FORM_strp"; | |
13616 | case DW_FORM_udata: | |
13617 | return "DW_FORM_udata"; | |
13618 | case DW_FORM_ref_addr: | |
13619 | return "DW_FORM_ref_addr"; | |
13620 | case DW_FORM_ref1: | |
13621 | return "DW_FORM_ref1"; | |
13622 | case DW_FORM_ref2: | |
13623 | return "DW_FORM_ref2"; | |
13624 | case DW_FORM_ref4: | |
13625 | return "DW_FORM_ref4"; | |
13626 | case DW_FORM_ref8: | |
13627 | return "DW_FORM_ref8"; | |
13628 | case DW_FORM_ref_udata: | |
13629 | return "DW_FORM_ref_udata"; | |
13630 | case DW_FORM_indirect: | |
13631 | return "DW_FORM_indirect"; | |
348e048f DE |
13632 | case DW_FORM_sec_offset: |
13633 | return "DW_FORM_sec_offset"; | |
13634 | case DW_FORM_exprloc: | |
13635 | return "DW_FORM_exprloc"; | |
13636 | case DW_FORM_flag_present: | |
13637 | return "DW_FORM_flag_present"; | |
55f1336d TT |
13638 | case DW_FORM_ref_sig8: |
13639 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
13640 | default: |
13641 | return "DW_FORM_<unknown>"; | |
13642 | } | |
13643 | } | |
13644 | ||
13645 | /* Convert a DWARF stack opcode into its string name. */ | |
13646 | ||
9eae7c52 | 13647 | const char * |
b1bfef65 | 13648 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
13649 | { |
13650 | switch (op) | |
13651 | { | |
13652 | case DW_OP_addr: | |
13653 | return "DW_OP_addr"; | |
13654 | case DW_OP_deref: | |
13655 | return "DW_OP_deref"; | |
13656 | case DW_OP_const1u: | |
13657 | return "DW_OP_const1u"; | |
13658 | case DW_OP_const1s: | |
13659 | return "DW_OP_const1s"; | |
13660 | case DW_OP_const2u: | |
13661 | return "DW_OP_const2u"; | |
13662 | case DW_OP_const2s: | |
13663 | return "DW_OP_const2s"; | |
13664 | case DW_OP_const4u: | |
13665 | return "DW_OP_const4u"; | |
13666 | case DW_OP_const4s: | |
13667 | return "DW_OP_const4s"; | |
13668 | case DW_OP_const8u: | |
13669 | return "DW_OP_const8u"; | |
13670 | case DW_OP_const8s: | |
13671 | return "DW_OP_const8s"; | |
13672 | case DW_OP_constu: | |
13673 | return "DW_OP_constu"; | |
13674 | case DW_OP_consts: | |
13675 | return "DW_OP_consts"; | |
13676 | case DW_OP_dup: | |
13677 | return "DW_OP_dup"; | |
13678 | case DW_OP_drop: | |
13679 | return "DW_OP_drop"; | |
13680 | case DW_OP_over: | |
13681 | return "DW_OP_over"; | |
13682 | case DW_OP_pick: | |
13683 | return "DW_OP_pick"; | |
13684 | case DW_OP_swap: | |
13685 | return "DW_OP_swap"; | |
13686 | case DW_OP_rot: | |
13687 | return "DW_OP_rot"; | |
13688 | case DW_OP_xderef: | |
13689 | return "DW_OP_xderef"; | |
13690 | case DW_OP_abs: | |
13691 | return "DW_OP_abs"; | |
13692 | case DW_OP_and: | |
13693 | return "DW_OP_and"; | |
13694 | case DW_OP_div: | |
13695 | return "DW_OP_div"; | |
13696 | case DW_OP_minus: | |
13697 | return "DW_OP_minus"; | |
13698 | case DW_OP_mod: | |
13699 | return "DW_OP_mod"; | |
13700 | case DW_OP_mul: | |
13701 | return "DW_OP_mul"; | |
13702 | case DW_OP_neg: | |
13703 | return "DW_OP_neg"; | |
13704 | case DW_OP_not: | |
13705 | return "DW_OP_not"; | |
13706 | case DW_OP_or: | |
13707 | return "DW_OP_or"; | |
13708 | case DW_OP_plus: | |
13709 | return "DW_OP_plus"; | |
13710 | case DW_OP_plus_uconst: | |
13711 | return "DW_OP_plus_uconst"; | |
13712 | case DW_OP_shl: | |
13713 | return "DW_OP_shl"; | |
13714 | case DW_OP_shr: | |
13715 | return "DW_OP_shr"; | |
13716 | case DW_OP_shra: | |
13717 | return "DW_OP_shra"; | |
13718 | case DW_OP_xor: | |
13719 | return "DW_OP_xor"; | |
13720 | case DW_OP_bra: | |
13721 | return "DW_OP_bra"; | |
13722 | case DW_OP_eq: | |
13723 | return "DW_OP_eq"; | |
13724 | case DW_OP_ge: | |
13725 | return "DW_OP_ge"; | |
13726 | case DW_OP_gt: | |
13727 | return "DW_OP_gt"; | |
13728 | case DW_OP_le: | |
13729 | return "DW_OP_le"; | |
13730 | case DW_OP_lt: | |
13731 | return "DW_OP_lt"; | |
13732 | case DW_OP_ne: | |
13733 | return "DW_OP_ne"; | |
13734 | case DW_OP_skip: | |
13735 | return "DW_OP_skip"; | |
13736 | case DW_OP_lit0: | |
13737 | return "DW_OP_lit0"; | |
13738 | case DW_OP_lit1: | |
13739 | return "DW_OP_lit1"; | |
13740 | case DW_OP_lit2: | |
13741 | return "DW_OP_lit2"; | |
13742 | case DW_OP_lit3: | |
13743 | return "DW_OP_lit3"; | |
13744 | case DW_OP_lit4: | |
13745 | return "DW_OP_lit4"; | |
13746 | case DW_OP_lit5: | |
13747 | return "DW_OP_lit5"; | |
13748 | case DW_OP_lit6: | |
13749 | return "DW_OP_lit6"; | |
13750 | case DW_OP_lit7: | |
13751 | return "DW_OP_lit7"; | |
13752 | case DW_OP_lit8: | |
13753 | return "DW_OP_lit8"; | |
13754 | case DW_OP_lit9: | |
13755 | return "DW_OP_lit9"; | |
13756 | case DW_OP_lit10: | |
13757 | return "DW_OP_lit10"; | |
13758 | case DW_OP_lit11: | |
13759 | return "DW_OP_lit11"; | |
13760 | case DW_OP_lit12: | |
13761 | return "DW_OP_lit12"; | |
13762 | case DW_OP_lit13: | |
13763 | return "DW_OP_lit13"; | |
13764 | case DW_OP_lit14: | |
13765 | return "DW_OP_lit14"; | |
13766 | case DW_OP_lit15: | |
13767 | return "DW_OP_lit15"; | |
13768 | case DW_OP_lit16: | |
13769 | return "DW_OP_lit16"; | |
13770 | case DW_OP_lit17: | |
13771 | return "DW_OP_lit17"; | |
13772 | case DW_OP_lit18: | |
13773 | return "DW_OP_lit18"; | |
13774 | case DW_OP_lit19: | |
13775 | return "DW_OP_lit19"; | |
13776 | case DW_OP_lit20: | |
13777 | return "DW_OP_lit20"; | |
13778 | case DW_OP_lit21: | |
13779 | return "DW_OP_lit21"; | |
13780 | case DW_OP_lit22: | |
13781 | return "DW_OP_lit22"; | |
13782 | case DW_OP_lit23: | |
13783 | return "DW_OP_lit23"; | |
13784 | case DW_OP_lit24: | |
13785 | return "DW_OP_lit24"; | |
13786 | case DW_OP_lit25: | |
13787 | return "DW_OP_lit25"; | |
13788 | case DW_OP_lit26: | |
13789 | return "DW_OP_lit26"; | |
13790 | case DW_OP_lit27: | |
13791 | return "DW_OP_lit27"; | |
13792 | case DW_OP_lit28: | |
13793 | return "DW_OP_lit28"; | |
13794 | case DW_OP_lit29: | |
13795 | return "DW_OP_lit29"; | |
13796 | case DW_OP_lit30: | |
13797 | return "DW_OP_lit30"; | |
13798 | case DW_OP_lit31: | |
13799 | return "DW_OP_lit31"; | |
13800 | case DW_OP_reg0: | |
13801 | return "DW_OP_reg0"; | |
13802 | case DW_OP_reg1: | |
13803 | return "DW_OP_reg1"; | |
13804 | case DW_OP_reg2: | |
13805 | return "DW_OP_reg2"; | |
13806 | case DW_OP_reg3: | |
13807 | return "DW_OP_reg3"; | |
13808 | case DW_OP_reg4: | |
13809 | return "DW_OP_reg4"; | |
13810 | case DW_OP_reg5: | |
13811 | return "DW_OP_reg5"; | |
13812 | case DW_OP_reg6: | |
13813 | return "DW_OP_reg6"; | |
13814 | case DW_OP_reg7: | |
13815 | return "DW_OP_reg7"; | |
13816 | case DW_OP_reg8: | |
13817 | return "DW_OP_reg8"; | |
13818 | case DW_OP_reg9: | |
13819 | return "DW_OP_reg9"; | |
13820 | case DW_OP_reg10: | |
13821 | return "DW_OP_reg10"; | |
13822 | case DW_OP_reg11: | |
13823 | return "DW_OP_reg11"; | |
13824 | case DW_OP_reg12: | |
13825 | return "DW_OP_reg12"; | |
13826 | case DW_OP_reg13: | |
13827 | return "DW_OP_reg13"; | |
13828 | case DW_OP_reg14: | |
13829 | return "DW_OP_reg14"; | |
13830 | case DW_OP_reg15: | |
13831 | return "DW_OP_reg15"; | |
13832 | case DW_OP_reg16: | |
13833 | return "DW_OP_reg16"; | |
13834 | case DW_OP_reg17: | |
13835 | return "DW_OP_reg17"; | |
13836 | case DW_OP_reg18: | |
13837 | return "DW_OP_reg18"; | |
13838 | case DW_OP_reg19: | |
13839 | return "DW_OP_reg19"; | |
13840 | case DW_OP_reg20: | |
13841 | return "DW_OP_reg20"; | |
13842 | case DW_OP_reg21: | |
13843 | return "DW_OP_reg21"; | |
13844 | case DW_OP_reg22: | |
13845 | return "DW_OP_reg22"; | |
13846 | case DW_OP_reg23: | |
13847 | return "DW_OP_reg23"; | |
13848 | case DW_OP_reg24: | |
13849 | return "DW_OP_reg24"; | |
13850 | case DW_OP_reg25: | |
13851 | return "DW_OP_reg25"; | |
13852 | case DW_OP_reg26: | |
13853 | return "DW_OP_reg26"; | |
13854 | case DW_OP_reg27: | |
13855 | return "DW_OP_reg27"; | |
13856 | case DW_OP_reg28: | |
13857 | return "DW_OP_reg28"; | |
13858 | case DW_OP_reg29: | |
13859 | return "DW_OP_reg29"; | |
13860 | case DW_OP_reg30: | |
13861 | return "DW_OP_reg30"; | |
13862 | case DW_OP_reg31: | |
13863 | return "DW_OP_reg31"; | |
13864 | case DW_OP_breg0: | |
13865 | return "DW_OP_breg0"; | |
13866 | case DW_OP_breg1: | |
13867 | return "DW_OP_breg1"; | |
13868 | case DW_OP_breg2: | |
13869 | return "DW_OP_breg2"; | |
13870 | case DW_OP_breg3: | |
13871 | return "DW_OP_breg3"; | |
13872 | case DW_OP_breg4: | |
13873 | return "DW_OP_breg4"; | |
13874 | case DW_OP_breg5: | |
13875 | return "DW_OP_breg5"; | |
13876 | case DW_OP_breg6: | |
13877 | return "DW_OP_breg6"; | |
13878 | case DW_OP_breg7: | |
13879 | return "DW_OP_breg7"; | |
13880 | case DW_OP_breg8: | |
13881 | return "DW_OP_breg8"; | |
13882 | case DW_OP_breg9: | |
13883 | return "DW_OP_breg9"; | |
13884 | case DW_OP_breg10: | |
13885 | return "DW_OP_breg10"; | |
13886 | case DW_OP_breg11: | |
13887 | return "DW_OP_breg11"; | |
13888 | case DW_OP_breg12: | |
13889 | return "DW_OP_breg12"; | |
13890 | case DW_OP_breg13: | |
13891 | return "DW_OP_breg13"; | |
13892 | case DW_OP_breg14: | |
13893 | return "DW_OP_breg14"; | |
13894 | case DW_OP_breg15: | |
13895 | return "DW_OP_breg15"; | |
13896 | case DW_OP_breg16: | |
13897 | return "DW_OP_breg16"; | |
13898 | case DW_OP_breg17: | |
13899 | return "DW_OP_breg17"; | |
13900 | case DW_OP_breg18: | |
13901 | return "DW_OP_breg18"; | |
13902 | case DW_OP_breg19: | |
13903 | return "DW_OP_breg19"; | |
13904 | case DW_OP_breg20: | |
13905 | return "DW_OP_breg20"; | |
13906 | case DW_OP_breg21: | |
13907 | return "DW_OP_breg21"; | |
13908 | case DW_OP_breg22: | |
13909 | return "DW_OP_breg22"; | |
13910 | case DW_OP_breg23: | |
13911 | return "DW_OP_breg23"; | |
13912 | case DW_OP_breg24: | |
13913 | return "DW_OP_breg24"; | |
13914 | case DW_OP_breg25: | |
13915 | return "DW_OP_breg25"; | |
13916 | case DW_OP_breg26: | |
13917 | return "DW_OP_breg26"; | |
13918 | case DW_OP_breg27: | |
13919 | return "DW_OP_breg27"; | |
13920 | case DW_OP_breg28: | |
13921 | return "DW_OP_breg28"; | |
13922 | case DW_OP_breg29: | |
13923 | return "DW_OP_breg29"; | |
13924 | case DW_OP_breg30: | |
13925 | return "DW_OP_breg30"; | |
13926 | case DW_OP_breg31: | |
13927 | return "DW_OP_breg31"; | |
13928 | case DW_OP_regx: | |
13929 | return "DW_OP_regx"; | |
13930 | case DW_OP_fbreg: | |
13931 | return "DW_OP_fbreg"; | |
13932 | case DW_OP_bregx: | |
13933 | return "DW_OP_bregx"; | |
13934 | case DW_OP_piece: | |
13935 | return "DW_OP_piece"; | |
13936 | case DW_OP_deref_size: | |
13937 | return "DW_OP_deref_size"; | |
13938 | case DW_OP_xderef_size: | |
13939 | return "DW_OP_xderef_size"; | |
13940 | case DW_OP_nop: | |
13941 | return "DW_OP_nop"; | |
b7619582 | 13942 | /* DWARF 3 extensions. */ |
ed348acc EZ |
13943 | case DW_OP_push_object_address: |
13944 | return "DW_OP_push_object_address"; | |
13945 | case DW_OP_call2: | |
13946 | return "DW_OP_call2"; | |
13947 | case DW_OP_call4: | |
13948 | return "DW_OP_call4"; | |
13949 | case DW_OP_call_ref: | |
13950 | return "DW_OP_call_ref"; | |
b7619582 GF |
13951 | case DW_OP_form_tls_address: |
13952 | return "DW_OP_form_tls_address"; | |
13953 | case DW_OP_call_frame_cfa: | |
13954 | return "DW_OP_call_frame_cfa"; | |
13955 | case DW_OP_bit_piece: | |
13956 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
13957 | /* DWARF 4 extensions. */ |
13958 | case DW_OP_implicit_value: | |
13959 | return "DW_OP_implicit_value"; | |
13960 | case DW_OP_stack_value: | |
13961 | return "DW_OP_stack_value"; | |
13962 | /* GNU extensions. */ | |
ed348acc EZ |
13963 | case DW_OP_GNU_push_tls_address: |
13964 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
13965 | case DW_OP_GNU_uninit: |
13966 | return "DW_OP_GNU_uninit"; | |
589b4a32 DE |
13967 | case DW_OP_GNU_encoded_addr: |
13968 | return "DW_OP_GNU_encoded_addr"; | |
8cf6f0b1 TT |
13969 | case DW_OP_GNU_implicit_pointer: |
13970 | return "DW_OP_GNU_implicit_pointer"; | |
8a9b8146 TT |
13971 | case DW_OP_GNU_entry_value: |
13972 | return "DW_OP_GNU_entry_value"; | |
13973 | case DW_OP_GNU_const_type: | |
13974 | return "DW_OP_GNU_const_type"; | |
13975 | case DW_OP_GNU_regval_type: | |
13976 | return "DW_OP_GNU_regval_type"; | |
13977 | case DW_OP_GNU_deref_type: | |
13978 | return "DW_OP_GNU_deref_type"; | |
13979 | case DW_OP_GNU_convert: | |
13980 | return "DW_OP_GNU_convert"; | |
13981 | case DW_OP_GNU_reinterpret: | |
13982 | return "DW_OP_GNU_reinterpret"; | |
589b4a32 DE |
13983 | case DW_OP_GNU_parameter_ref: |
13984 | return "DW_OP_GNU_parameter_ref"; | |
c906108c | 13985 | default: |
b1bfef65 | 13986 | return NULL; |
c906108c SS |
13987 | } |
13988 | } | |
13989 | ||
13990 | static char * | |
fba45db2 | 13991 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
13992 | { |
13993 | if (mybool) | |
13994 | return "TRUE"; | |
13995 | else | |
13996 | return "FALSE"; | |
13997 | } | |
13998 | ||
13999 | /* Convert a DWARF type code into its string name. */ | |
14000 | ||
14001 | static char * | |
aa1ee363 | 14002 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
14003 | { |
14004 | switch (enc) | |
14005 | { | |
b7619582 GF |
14006 | case DW_ATE_void: |
14007 | return "DW_ATE_void"; | |
c906108c SS |
14008 | case DW_ATE_address: |
14009 | return "DW_ATE_address"; | |
14010 | case DW_ATE_boolean: | |
14011 | return "DW_ATE_boolean"; | |
14012 | case DW_ATE_complex_float: | |
14013 | return "DW_ATE_complex_float"; | |
14014 | case DW_ATE_float: | |
14015 | return "DW_ATE_float"; | |
14016 | case DW_ATE_signed: | |
14017 | return "DW_ATE_signed"; | |
14018 | case DW_ATE_signed_char: | |
14019 | return "DW_ATE_signed_char"; | |
14020 | case DW_ATE_unsigned: | |
14021 | return "DW_ATE_unsigned"; | |
14022 | case DW_ATE_unsigned_char: | |
14023 | return "DW_ATE_unsigned_char"; | |
b7619582 | 14024 | /* DWARF 3. */ |
d9fa45fe DC |
14025 | case DW_ATE_imaginary_float: |
14026 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
14027 | case DW_ATE_packed_decimal: |
14028 | return "DW_ATE_packed_decimal"; | |
14029 | case DW_ATE_numeric_string: | |
14030 | return "DW_ATE_numeric_string"; | |
14031 | case DW_ATE_edited: | |
14032 | return "DW_ATE_edited"; | |
14033 | case DW_ATE_signed_fixed: | |
14034 | return "DW_ATE_signed_fixed"; | |
14035 | case DW_ATE_unsigned_fixed: | |
14036 | return "DW_ATE_unsigned_fixed"; | |
14037 | case DW_ATE_decimal_float: | |
14038 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
14039 | /* DWARF 4. */ |
14040 | case DW_ATE_UTF: | |
14041 | return "DW_ATE_UTF"; | |
b7619582 GF |
14042 | /* HP extensions. */ |
14043 | case DW_ATE_HP_float80: | |
14044 | return "DW_ATE_HP_float80"; | |
14045 | case DW_ATE_HP_complex_float80: | |
14046 | return "DW_ATE_HP_complex_float80"; | |
14047 | case DW_ATE_HP_float128: | |
14048 | return "DW_ATE_HP_float128"; | |
14049 | case DW_ATE_HP_complex_float128: | |
14050 | return "DW_ATE_HP_complex_float128"; | |
14051 | case DW_ATE_HP_floathpintel: | |
14052 | return "DW_ATE_HP_floathpintel"; | |
14053 | case DW_ATE_HP_imaginary_float80: | |
14054 | return "DW_ATE_HP_imaginary_float80"; | |
14055 | case DW_ATE_HP_imaginary_float128: | |
14056 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
14057 | default: |
14058 | return "DW_ATE_<unknown>"; | |
14059 | } | |
14060 | } | |
14061 | ||
0963b4bd | 14062 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
14063 | |
14064 | #if 0 | |
14065 | static char * | |
aa1ee363 | 14066 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
14067 | { |
14068 | switch (cfi_opc) | |
14069 | { | |
14070 | case DW_CFA_advance_loc: | |
14071 | return "DW_CFA_advance_loc"; | |
14072 | case DW_CFA_offset: | |
14073 | return "DW_CFA_offset"; | |
14074 | case DW_CFA_restore: | |
14075 | return "DW_CFA_restore"; | |
14076 | case DW_CFA_nop: | |
14077 | return "DW_CFA_nop"; | |
14078 | case DW_CFA_set_loc: | |
14079 | return "DW_CFA_set_loc"; | |
14080 | case DW_CFA_advance_loc1: | |
14081 | return "DW_CFA_advance_loc1"; | |
14082 | case DW_CFA_advance_loc2: | |
14083 | return "DW_CFA_advance_loc2"; | |
14084 | case DW_CFA_advance_loc4: | |
14085 | return "DW_CFA_advance_loc4"; | |
14086 | case DW_CFA_offset_extended: | |
14087 | return "DW_CFA_offset_extended"; | |
14088 | case DW_CFA_restore_extended: | |
14089 | return "DW_CFA_restore_extended"; | |
14090 | case DW_CFA_undefined: | |
14091 | return "DW_CFA_undefined"; | |
14092 | case DW_CFA_same_value: | |
14093 | return "DW_CFA_same_value"; | |
14094 | case DW_CFA_register: | |
14095 | return "DW_CFA_register"; | |
14096 | case DW_CFA_remember_state: | |
14097 | return "DW_CFA_remember_state"; | |
14098 | case DW_CFA_restore_state: | |
14099 | return "DW_CFA_restore_state"; | |
14100 | case DW_CFA_def_cfa: | |
14101 | return "DW_CFA_def_cfa"; | |
14102 | case DW_CFA_def_cfa_register: | |
14103 | return "DW_CFA_def_cfa_register"; | |
14104 | case DW_CFA_def_cfa_offset: | |
14105 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 14106 | /* DWARF 3. */ |
985cb1a3 JM |
14107 | case DW_CFA_def_cfa_expression: |
14108 | return "DW_CFA_def_cfa_expression"; | |
14109 | case DW_CFA_expression: | |
14110 | return "DW_CFA_expression"; | |
14111 | case DW_CFA_offset_extended_sf: | |
14112 | return "DW_CFA_offset_extended_sf"; | |
14113 | case DW_CFA_def_cfa_sf: | |
14114 | return "DW_CFA_def_cfa_sf"; | |
14115 | case DW_CFA_def_cfa_offset_sf: | |
14116 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
14117 | case DW_CFA_val_offset: |
14118 | return "DW_CFA_val_offset"; | |
14119 | case DW_CFA_val_offset_sf: | |
14120 | return "DW_CFA_val_offset_sf"; | |
14121 | case DW_CFA_val_expression: | |
14122 | return "DW_CFA_val_expression"; | |
14123 | /* SGI/MIPS specific. */ | |
c906108c SS |
14124 | case DW_CFA_MIPS_advance_loc8: |
14125 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 14126 | /* GNU extensions. */ |
985cb1a3 JM |
14127 | case DW_CFA_GNU_window_save: |
14128 | return "DW_CFA_GNU_window_save"; | |
14129 | case DW_CFA_GNU_args_size: | |
14130 | return "DW_CFA_GNU_args_size"; | |
14131 | case DW_CFA_GNU_negative_offset_extended: | |
14132 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
14133 | default: |
14134 | return "DW_CFA_<unknown>"; | |
14135 | } | |
14136 | } | |
14137 | #endif | |
14138 | ||
f9aca02d | 14139 | static void |
d97bc12b | 14140 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
14141 | { |
14142 | unsigned int i; | |
14143 | ||
d97bc12b DE |
14144 | print_spaces (indent, f); |
14145 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
b64f50a1 | 14146 | dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off); |
d97bc12b DE |
14147 | |
14148 | if (die->parent != NULL) | |
14149 | { | |
14150 | print_spaces (indent, f); | |
14151 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
b64f50a1 | 14152 | die->parent->offset.sect_off); |
d97bc12b DE |
14153 | } |
14154 | ||
14155 | print_spaces (indent, f); | |
14156 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 14157 | dwarf_bool_name (die->child != NULL)); |
c906108c | 14158 | |
d97bc12b DE |
14159 | print_spaces (indent, f); |
14160 | fprintf_unfiltered (f, " attributes:\n"); | |
14161 | ||
c906108c SS |
14162 | for (i = 0; i < die->num_attrs; ++i) |
14163 | { | |
d97bc12b DE |
14164 | print_spaces (indent, f); |
14165 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
14166 | dwarf_attr_name (die->attrs[i].name), |
14167 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 14168 | |
c906108c SS |
14169 | switch (die->attrs[i].form) |
14170 | { | |
c906108c | 14171 | case DW_FORM_addr: |
d97bc12b | 14172 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 14173 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
14174 | break; |
14175 | case DW_FORM_block2: | |
14176 | case DW_FORM_block4: | |
14177 | case DW_FORM_block: | |
14178 | case DW_FORM_block1: | |
3e43a32a MS |
14179 | fprintf_unfiltered (f, "block: size %d", |
14180 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 14181 | break; |
2dc7f7b3 TT |
14182 | case DW_FORM_exprloc: |
14183 | fprintf_unfiltered (f, "expression: size %u", | |
14184 | DW_BLOCK (&die->attrs[i])->size); | |
14185 | break; | |
4568ecf9 DE |
14186 | case DW_FORM_ref_addr: |
14187 | fprintf_unfiltered (f, "ref address: "); | |
14188 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); | |
14189 | break; | |
10b3939b DJ |
14190 | case DW_FORM_ref1: |
14191 | case DW_FORM_ref2: | |
14192 | case DW_FORM_ref4: | |
4568ecf9 DE |
14193 | case DW_FORM_ref8: |
14194 | case DW_FORM_ref_udata: | |
d97bc12b | 14195 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
4568ecf9 | 14196 | (long) (DW_UNSND (&die->attrs[i]))); |
10b3939b | 14197 | break; |
c906108c SS |
14198 | case DW_FORM_data1: |
14199 | case DW_FORM_data2: | |
14200 | case DW_FORM_data4: | |
ce5d95e1 | 14201 | case DW_FORM_data8: |
c906108c SS |
14202 | case DW_FORM_udata: |
14203 | case DW_FORM_sdata: | |
43bbcdc2 PH |
14204 | fprintf_unfiltered (f, "constant: %s", |
14205 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 14206 | break; |
2dc7f7b3 TT |
14207 | case DW_FORM_sec_offset: |
14208 | fprintf_unfiltered (f, "section offset: %s", | |
14209 | pulongest (DW_UNSND (&die->attrs[i]))); | |
14210 | break; | |
55f1336d | 14211 | case DW_FORM_ref_sig8: |
348e048f DE |
14212 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
14213 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
b64f50a1 | 14214 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off); |
348e048f DE |
14215 | else |
14216 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
14217 | break; | |
c906108c | 14218 | case DW_FORM_string: |
4bdf3d34 | 14219 | case DW_FORM_strp: |
8285870a | 14220 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 14221 | DW_STRING (&die->attrs[i]) |
8285870a JK |
14222 | ? DW_STRING (&die->attrs[i]) : "", |
14223 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
14224 | break; |
14225 | case DW_FORM_flag: | |
14226 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 14227 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 14228 | else |
d97bc12b | 14229 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 14230 | break; |
2dc7f7b3 TT |
14231 | case DW_FORM_flag_present: |
14232 | fprintf_unfiltered (f, "flag: TRUE"); | |
14233 | break; | |
a8329558 | 14234 | case DW_FORM_indirect: |
0963b4bd MS |
14235 | /* The reader will have reduced the indirect form to |
14236 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
14237 | fprintf_unfiltered (f, |
14238 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 14239 | break; |
c906108c | 14240 | default: |
d97bc12b | 14241 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 14242 | die->attrs[i].form); |
d97bc12b | 14243 | break; |
c906108c | 14244 | } |
d97bc12b | 14245 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
14246 | } |
14247 | } | |
14248 | ||
f9aca02d | 14249 | static void |
d97bc12b | 14250 | dump_die_for_error (struct die_info *die) |
c906108c | 14251 | { |
d97bc12b DE |
14252 | dump_die_shallow (gdb_stderr, 0, die); |
14253 | } | |
14254 | ||
14255 | static void | |
14256 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
14257 | { | |
14258 | int indent = level * 4; | |
14259 | ||
14260 | gdb_assert (die != NULL); | |
14261 | ||
14262 | if (level >= max_level) | |
14263 | return; | |
14264 | ||
14265 | dump_die_shallow (f, indent, die); | |
14266 | ||
14267 | if (die->child != NULL) | |
c906108c | 14268 | { |
d97bc12b DE |
14269 | print_spaces (indent, f); |
14270 | fprintf_unfiltered (f, " Children:"); | |
14271 | if (level + 1 < max_level) | |
14272 | { | |
14273 | fprintf_unfiltered (f, "\n"); | |
14274 | dump_die_1 (f, level + 1, max_level, die->child); | |
14275 | } | |
14276 | else | |
14277 | { | |
3e43a32a MS |
14278 | fprintf_unfiltered (f, |
14279 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
14280 | } |
14281 | } | |
14282 | ||
14283 | if (die->sibling != NULL && level > 0) | |
14284 | { | |
14285 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
14286 | } |
14287 | } | |
14288 | ||
d97bc12b DE |
14289 | /* This is called from the pdie macro in gdbinit.in. |
14290 | It's not static so gcc will keep a copy callable from gdb. */ | |
14291 | ||
14292 | void | |
14293 | dump_die (struct die_info *die, int max_level) | |
14294 | { | |
14295 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
14296 | } | |
14297 | ||
f9aca02d | 14298 | static void |
51545339 | 14299 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 14300 | { |
51545339 | 14301 | void **slot; |
c906108c | 14302 | |
b64f50a1 JK |
14303 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off, |
14304 | INSERT); | |
51545339 DJ |
14305 | |
14306 | *slot = die; | |
c906108c SS |
14307 | } |
14308 | ||
b64f50a1 JK |
14309 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
14310 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ | |
14311 | ||
93311388 DE |
14312 | static int |
14313 | is_ref_attr (struct attribute *attr) | |
c906108c | 14314 | { |
c906108c SS |
14315 | switch (attr->form) |
14316 | { | |
14317 | case DW_FORM_ref_addr: | |
c906108c SS |
14318 | case DW_FORM_ref1: |
14319 | case DW_FORM_ref2: | |
14320 | case DW_FORM_ref4: | |
613e1657 | 14321 | case DW_FORM_ref8: |
c906108c | 14322 | case DW_FORM_ref_udata: |
93311388 | 14323 | return 1; |
c906108c | 14324 | default: |
93311388 | 14325 | return 0; |
c906108c | 14326 | } |
93311388 DE |
14327 | } |
14328 | ||
b64f50a1 JK |
14329 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
14330 | required kind. */ | |
14331 | ||
14332 | static sect_offset | |
93311388 DE |
14333 | dwarf2_get_ref_die_offset (struct attribute *attr) |
14334 | { | |
4568ecf9 | 14335 | sect_offset retval = { DW_UNSND (attr) }; |
b64f50a1 | 14336 | |
93311388 | 14337 | if (is_ref_attr (attr)) |
b64f50a1 | 14338 | return retval; |
93311388 | 14339 | |
b64f50a1 | 14340 | retval.sect_off = 0; |
93311388 DE |
14341 | complaint (&symfile_complaints, |
14342 | _("unsupported die ref attribute form: '%s'"), | |
14343 | dwarf_form_name (attr->form)); | |
b64f50a1 | 14344 | return retval; |
c906108c SS |
14345 | } |
14346 | ||
43bbcdc2 PH |
14347 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
14348 | * the value held by the attribute is not constant. */ | |
a02abb62 | 14349 | |
43bbcdc2 | 14350 | static LONGEST |
a02abb62 JB |
14351 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
14352 | { | |
14353 | if (attr->form == DW_FORM_sdata) | |
14354 | return DW_SND (attr); | |
14355 | else if (attr->form == DW_FORM_udata | |
14356 | || attr->form == DW_FORM_data1 | |
14357 | || attr->form == DW_FORM_data2 | |
14358 | || attr->form == DW_FORM_data4 | |
14359 | || attr->form == DW_FORM_data8) | |
14360 | return DW_UNSND (attr); | |
14361 | else | |
14362 | { | |
3e43a32a MS |
14363 | complaint (&symfile_complaints, |
14364 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
14365 | dwarf_form_name (attr->form)); |
14366 | return default_value; | |
14367 | } | |
14368 | } | |
14369 | ||
03dd20cc | 14370 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
14371 | unit and add it to our queue. |
14372 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
14373 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 14374 | |
348e048f | 14375 | static int |
03dd20cc DJ |
14376 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
14377 | struct dwarf2_per_cu_data *per_cu) | |
14378 | { | |
98bfdba5 PA |
14379 | /* We may arrive here during partial symbol reading, if we need full |
14380 | DIEs to process an unusual case (e.g. template arguments). Do | |
14381 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
14382 | if (dwarf2_per_objfile->reading_partial_symbols) | |
14383 | { | |
14384 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
14385 | return 1; | |
14386 | return 0; | |
14387 | } | |
14388 | ||
03dd20cc DJ |
14389 | /* Mark the dependence relation so that we don't flush PER_CU |
14390 | too early. */ | |
14391 | dwarf2_add_dependence (this_cu, per_cu); | |
14392 | ||
14393 | /* If it's already on the queue, we have nothing to do. */ | |
14394 | if (per_cu->queued) | |
348e048f | 14395 | return 0; |
03dd20cc DJ |
14396 | |
14397 | /* If the compilation unit is already loaded, just mark it as | |
14398 | used. */ | |
14399 | if (per_cu->cu != NULL) | |
14400 | { | |
14401 | per_cu->cu->last_used = 0; | |
348e048f | 14402 | return 0; |
03dd20cc DJ |
14403 | } |
14404 | ||
14405 | /* Add it to the queue. */ | |
a0f42c21 | 14406 | queue_comp_unit (per_cu); |
348e048f DE |
14407 | |
14408 | return 1; | |
14409 | } | |
14410 | ||
14411 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
14412 | On entry *REF_CU is the CU of SRC_DIE. | |
14413 | On exit *REF_CU is the CU of the result. */ | |
14414 | ||
14415 | static struct die_info * | |
14416 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
14417 | struct dwarf2_cu **ref_cu) | |
14418 | { | |
14419 | struct die_info *die; | |
14420 | ||
14421 | if (is_ref_attr (attr)) | |
14422 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 14423 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
14424 | die = follow_die_sig (src_die, attr, ref_cu); |
14425 | else | |
14426 | { | |
14427 | dump_die_for_error (src_die); | |
14428 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
14429 | (*ref_cu)->objfile->name); | |
14430 | } | |
14431 | ||
14432 | return die; | |
03dd20cc DJ |
14433 | } |
14434 | ||
5c631832 | 14435 | /* Follow reference OFFSET. |
673bfd45 DE |
14436 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
14437 | On exit *REF_CU is the CU of the result. | |
14438 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 14439 | |
f9aca02d | 14440 | static struct die_info * |
b64f50a1 | 14441 | follow_die_offset (sect_offset offset, struct dwarf2_cu **ref_cu) |
c906108c | 14442 | { |
10b3939b | 14443 | struct die_info temp_die; |
f2f0e013 | 14444 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 14445 | |
348e048f DE |
14446 | gdb_assert (cu->per_cu != NULL); |
14447 | ||
98bfdba5 PA |
14448 | target_cu = cu; |
14449 | ||
b0df02fd | 14450 | if (cu->per_cu->debug_types_section) |
348e048f DE |
14451 | { |
14452 | /* .debug_types CUs cannot reference anything outside their CU. | |
14453 | If they need to, they have to reference a signatured type via | |
55f1336d | 14454 | DW_FORM_ref_sig8. */ |
348e048f | 14455 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 14456 | return NULL; |
348e048f DE |
14457 | } |
14458 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
14459 | { |
14460 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 14461 | |
45452591 | 14462 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
14463 | |
14464 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f | 14465 | if (maybe_queue_comp_unit (cu, per_cu)) |
a0f42c21 | 14466 | load_full_comp_unit (per_cu); |
03dd20cc | 14467 | |
10b3939b DJ |
14468 | target_cu = per_cu->cu; |
14469 | } | |
98bfdba5 PA |
14470 | else if (cu->dies == NULL) |
14471 | { | |
14472 | /* We're loading full DIEs during partial symbol reading. */ | |
14473 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
a0f42c21 | 14474 | load_full_comp_unit (cu->per_cu); |
98bfdba5 | 14475 | } |
c906108c | 14476 | |
f2f0e013 | 14477 | *ref_cu = target_cu; |
51545339 | 14478 | temp_die.offset = offset; |
b64f50a1 | 14479 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off); |
5c631832 | 14480 | } |
10b3939b | 14481 | |
5c631832 JK |
14482 | /* Follow reference attribute ATTR of SRC_DIE. |
14483 | On entry *REF_CU is the CU of SRC_DIE. | |
14484 | On exit *REF_CU is the CU of the result. */ | |
14485 | ||
14486 | static struct die_info * | |
14487 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
14488 | struct dwarf2_cu **ref_cu) | |
14489 | { | |
b64f50a1 | 14490 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
5c631832 JK |
14491 | struct dwarf2_cu *cu = *ref_cu; |
14492 | struct die_info *die; | |
14493 | ||
14494 | die = follow_die_offset (offset, ref_cu); | |
14495 | if (!die) | |
14496 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
14497 | "at 0x%x [in module %s]"), | |
b64f50a1 | 14498 | offset.sect_off, src_die->offset.sect_off, cu->objfile->name); |
348e048f | 14499 | |
5c631832 JK |
14500 | return die; |
14501 | } | |
14502 | ||
d83e736b JK |
14503 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
14504 | Returned value is intended for DW_OP_call*. Returned | |
14505 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ | |
5c631832 JK |
14506 | |
14507 | struct dwarf2_locexpr_baton | |
b64f50a1 | 14508 | dwarf2_fetch_die_location_block (cu_offset offset_in_cu, |
8cf6f0b1 TT |
14509 | struct dwarf2_per_cu_data *per_cu, |
14510 | CORE_ADDR (*get_frame_pc) (void *baton), | |
14511 | void *baton) | |
5c631832 | 14512 | { |
b64f50a1 | 14513 | sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off }; |
918dd910 | 14514 | struct dwarf2_cu *cu; |
5c631832 JK |
14515 | struct die_info *die; |
14516 | struct attribute *attr; | |
14517 | struct dwarf2_locexpr_baton retval; | |
14518 | ||
8cf6f0b1 TT |
14519 | dw2_setup (per_cu->objfile); |
14520 | ||
918dd910 JK |
14521 | if (per_cu->cu == NULL) |
14522 | load_cu (per_cu); | |
14523 | cu = per_cu->cu; | |
14524 | ||
5c631832 JK |
14525 | die = follow_die_offset (offset, &cu); |
14526 | if (!die) | |
14527 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
b64f50a1 | 14528 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
14529 | |
14530 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
14531 | if (!attr) | |
14532 | { | |
e103e986 JK |
14533 | /* DWARF: "If there is no such attribute, then there is no effect.". |
14534 | DATA is ignored if SIZE is 0. */ | |
5c631832 | 14535 | |
e103e986 | 14536 | retval.data = NULL; |
5c631832 JK |
14537 | retval.size = 0; |
14538 | } | |
8cf6f0b1 TT |
14539 | else if (attr_form_is_section_offset (attr)) |
14540 | { | |
14541 | struct dwarf2_loclist_baton loclist_baton; | |
14542 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
14543 | size_t size; | |
14544 | ||
14545 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
14546 | ||
14547 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
14548 | &size, pc); | |
14549 | retval.size = size; | |
14550 | } | |
5c631832 JK |
14551 | else |
14552 | { | |
14553 | if (!attr_form_is_block (attr)) | |
14554 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
14555 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
b64f50a1 | 14556 | offset.sect_off, per_cu->objfile->name); |
5c631832 JK |
14557 | |
14558 | retval.data = DW_BLOCK (attr)->data; | |
14559 | retval.size = DW_BLOCK (attr)->size; | |
14560 | } | |
14561 | retval.per_cu = cu->per_cu; | |
918dd910 | 14562 | |
918dd910 JK |
14563 | age_cached_comp_units (); |
14564 | ||
5c631832 | 14565 | return retval; |
348e048f DE |
14566 | } |
14567 | ||
8a9b8146 TT |
14568 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
14569 | PER_CU. */ | |
14570 | ||
14571 | struct type * | |
b64f50a1 | 14572 | dwarf2_get_die_type (cu_offset die_offset, |
8a9b8146 TT |
14573 | struct dwarf2_per_cu_data *per_cu) |
14574 | { | |
b64f50a1 JK |
14575 | sect_offset die_offset_sect; |
14576 | ||
8a9b8146 | 14577 | dw2_setup (per_cu->objfile); |
b64f50a1 JK |
14578 | |
14579 | die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off; | |
14580 | return get_die_type_at_offset (die_offset_sect, per_cu); | |
8a9b8146 TT |
14581 | } |
14582 | ||
348e048f DE |
14583 | /* Follow the signature attribute ATTR in SRC_DIE. |
14584 | On entry *REF_CU is the CU of SRC_DIE. | |
14585 | On exit *REF_CU is the CU of the result. */ | |
14586 | ||
14587 | static struct die_info * | |
14588 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
14589 | struct dwarf2_cu **ref_cu) | |
14590 | { | |
14591 | struct objfile *objfile = (*ref_cu)->objfile; | |
14592 | struct die_info temp_die; | |
14593 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
14594 | struct dwarf2_cu *sig_cu; | |
14595 | struct die_info *die; | |
14596 | ||
14597 | /* sig_type will be NULL if the signatured type is missing from | |
14598 | the debug info. */ | |
14599 | if (sig_type == NULL) | |
14600 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
14601 | "at 0x%x [in module %s]"), | |
b64f50a1 | 14602 | src_die->offset.sect_off, objfile->name); |
348e048f DE |
14603 | |
14604 | /* If necessary, add it to the queue and load its DIEs. */ | |
14605 | ||
14606 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
a0f42c21 | 14607 | read_signatured_type (sig_type); |
348e048f DE |
14608 | |
14609 | gdb_assert (sig_type->per_cu.cu != NULL); | |
14610 | ||
14611 | sig_cu = sig_type->per_cu.cu; | |
b64f50a1 JK |
14612 | temp_die.offset.sect_off = (sig_type->per_cu.offset.sect_off |
14613 | + sig_type->type_offset.cu_off); | |
14614 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, | |
14615 | temp_die.offset.sect_off); | |
348e048f DE |
14616 | if (die) |
14617 | { | |
14618 | *ref_cu = sig_cu; | |
14619 | return die; | |
14620 | } | |
14621 | ||
3e43a32a MS |
14622 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
14623 | "from DIE at 0x%x [in module %s]"), | |
b64f50a1 | 14624 | temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name); |
348e048f DE |
14625 | } |
14626 | ||
14627 | /* Given an offset of a signatured type, return its signatured_type. */ | |
14628 | ||
14629 | static struct signatured_type * | |
8b70b953 TT |
14630 | lookup_signatured_type_at_offset (struct objfile *objfile, |
14631 | struct dwarf2_section_info *section, | |
b64f50a1 | 14632 | sect_offset offset) |
348e048f | 14633 | { |
b64f50a1 | 14634 | gdb_byte *info_ptr = section->buffer + offset.sect_off; |
348e048f DE |
14635 | unsigned int length, initial_length_size; |
14636 | unsigned int sig_offset; | |
52dc124a | 14637 | struct signatured_type find_entry, *sig_type; |
348e048f DE |
14638 | |
14639 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
14640 | sig_offset = (initial_length_size | |
14641 | + 2 /*version*/ | |
14642 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
14643 | + 1 /*address_size*/); | |
14644 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
52dc124a | 14645 | sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
348e048f DE |
14646 | |
14647 | /* This is only used to lookup previously recorded types. | |
14648 | If we didn't find it, it's our bug. */ | |
52dc124a DE |
14649 | gdb_assert (sig_type != NULL); |
14650 | gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off); | |
348e048f | 14651 | |
52dc124a | 14652 | return sig_type; |
348e048f DE |
14653 | } |
14654 | ||
e5fe5e75 | 14655 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
348e048f DE |
14656 | |
14657 | static void | |
e5fe5e75 | 14658 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
348e048f | 14659 | { |
e5fe5e75 DE |
14660 | struct objfile *objfile = per_cu->objfile; |
14661 | struct dwarf2_section_info *sect = per_cu->debug_types_section; | |
b64f50a1 | 14662 | sect_offset offset = per_cu->offset; |
52dc124a | 14663 | struct signatured_type *sig_type; |
348e048f | 14664 | |
8b70b953 | 14665 | dwarf2_read_section (objfile, sect); |
be391dca | 14666 | |
348e048f | 14667 | /* We have the section offset, but we need the signature to do the |
e5fe5e75 DE |
14668 | hash table lookup. */ |
14669 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses | |
14670 | the signature to assert we found the right one. | |
14671 | Ok, but it's a lot of work. We should simplify things so any needed | |
14672 | assert doesn't require all this clumsiness. */ | |
52dc124a | 14673 | sig_type = lookup_signatured_type_at_offset (objfile, sect, offset); |
348e048f | 14674 | |
dee91e82 | 14675 | gdb_assert (&sig_type->per_cu == per_cu); |
52dc124a | 14676 | gdb_assert (sig_type->per_cu.cu == NULL); |
348e048f | 14677 | |
52dc124a | 14678 | read_signatured_type (sig_type); |
348e048f | 14679 | |
52dc124a | 14680 | gdb_assert (sig_type->per_cu.cu != NULL); |
348e048f DE |
14681 | } |
14682 | ||
dee91e82 DE |
14683 | /* die_reader_func for read_signatured_type. |
14684 | This is identical to load_full_comp_unit_reader, | |
14685 | but is kept separate for now. */ | |
348e048f DE |
14686 | |
14687 | static void | |
dee91e82 DE |
14688 | read_signatured_type_reader (const struct die_reader_specs *reader, |
14689 | gdb_byte *info_ptr, | |
14690 | struct die_info *comp_unit_die, | |
14691 | int has_children, | |
14692 | void *data) | |
348e048f | 14693 | { |
dee91e82 DE |
14694 | struct dwarf2_cu *cu = reader->cu; |
14695 | struct attribute *attr; | |
348e048f | 14696 | |
dee91e82 DE |
14697 | gdb_assert (cu->die_hash == NULL); |
14698 | cu->die_hash = | |
14699 | htab_create_alloc_ex (cu->header.length / 12, | |
14700 | die_hash, | |
14701 | die_eq, | |
14702 | NULL, | |
14703 | &cu->comp_unit_obstack, | |
14704 | hashtab_obstack_allocate, | |
14705 | dummy_obstack_deallocate); | |
348e048f | 14706 | |
dee91e82 DE |
14707 | if (has_children) |
14708 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, | |
14709 | &info_ptr, comp_unit_die); | |
14710 | cu->dies = comp_unit_die; | |
14711 | /* comp_unit_die is not stored in die_hash, no need. */ | |
348e048f DE |
14712 | |
14713 | /* We try not to read any attributes in this function, because not | |
9cdd5dbd | 14714 | all CUs needed for references have been loaded yet, and symbol |
348e048f | 14715 | table processing isn't initialized. But we have to set the CU language, |
dee91e82 DE |
14716 | or we won't be able to build types correctly. |
14717 | Similarly, if we do not read the producer, we can not apply | |
14718 | producer-specific interpretation. */ | |
9816fde3 | 14719 | prepare_one_comp_unit (cu, cu->dies); |
dee91e82 | 14720 | } |
348e048f | 14721 | |
dee91e82 DE |
14722 | /* Read in a signatured type and build its CU and DIEs. */ |
14723 | ||
14724 | static void | |
14725 | read_signatured_type (struct signatured_type *sig_type) | |
14726 | { | |
14727 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; | |
348e048f | 14728 | |
dee91e82 DE |
14729 | gdb_assert (per_cu->debug_types_section); |
14730 | gdb_assert (per_cu->cu == NULL); | |
348e048f | 14731 | |
dee91e82 | 14732 | init_tu_and_read_dies (per_cu, 1, read_signatured_type_reader, NULL); |
c906108c SS |
14733 | } |
14734 | ||
c906108c SS |
14735 | /* Decode simple location descriptions. |
14736 | Given a pointer to a dwarf block that defines a location, compute | |
14737 | the location and return the value. | |
14738 | ||
4cecd739 DJ |
14739 | NOTE drow/2003-11-18: This function is called in two situations |
14740 | now: for the address of static or global variables (partial symbols | |
14741 | only) and for offsets into structures which are expected to be | |
14742 | (more or less) constant. The partial symbol case should go away, | |
14743 | and only the constant case should remain. That will let this | |
14744 | function complain more accurately. A few special modes are allowed | |
14745 | without complaint for global variables (for instance, global | |
14746 | register values and thread-local values). | |
c906108c SS |
14747 | |
14748 | A location description containing no operations indicates that the | |
4cecd739 | 14749 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
14750 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
14751 | callers will only want a very basic result and this can become a | |
21ae7a4d JK |
14752 | complaint. |
14753 | ||
14754 | Note that stack[0] is unused except as a default error return. */ | |
c906108c SS |
14755 | |
14756 | static CORE_ADDR | |
e7c27a73 | 14757 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 14758 | { |
e7c27a73 | 14759 | struct objfile *objfile = cu->objfile; |
21ae7a4d JK |
14760 | int i; |
14761 | int size = blk->size; | |
14762 | gdb_byte *data = blk->data; | |
14763 | CORE_ADDR stack[64]; | |
14764 | int stacki; | |
14765 | unsigned int bytes_read, unsnd; | |
14766 | gdb_byte op; | |
c906108c | 14767 | |
21ae7a4d JK |
14768 | i = 0; |
14769 | stacki = 0; | |
14770 | stack[stacki] = 0; | |
14771 | stack[++stacki] = 0; | |
14772 | ||
14773 | while (i < size) | |
14774 | { | |
14775 | op = data[i++]; | |
14776 | switch (op) | |
14777 | { | |
14778 | case DW_OP_lit0: | |
14779 | case DW_OP_lit1: | |
14780 | case DW_OP_lit2: | |
14781 | case DW_OP_lit3: | |
14782 | case DW_OP_lit4: | |
14783 | case DW_OP_lit5: | |
14784 | case DW_OP_lit6: | |
14785 | case DW_OP_lit7: | |
14786 | case DW_OP_lit8: | |
14787 | case DW_OP_lit9: | |
14788 | case DW_OP_lit10: | |
14789 | case DW_OP_lit11: | |
14790 | case DW_OP_lit12: | |
14791 | case DW_OP_lit13: | |
14792 | case DW_OP_lit14: | |
14793 | case DW_OP_lit15: | |
14794 | case DW_OP_lit16: | |
14795 | case DW_OP_lit17: | |
14796 | case DW_OP_lit18: | |
14797 | case DW_OP_lit19: | |
14798 | case DW_OP_lit20: | |
14799 | case DW_OP_lit21: | |
14800 | case DW_OP_lit22: | |
14801 | case DW_OP_lit23: | |
14802 | case DW_OP_lit24: | |
14803 | case DW_OP_lit25: | |
14804 | case DW_OP_lit26: | |
14805 | case DW_OP_lit27: | |
14806 | case DW_OP_lit28: | |
14807 | case DW_OP_lit29: | |
14808 | case DW_OP_lit30: | |
14809 | case DW_OP_lit31: | |
14810 | stack[++stacki] = op - DW_OP_lit0; | |
14811 | break; | |
f1bea926 | 14812 | |
21ae7a4d JK |
14813 | case DW_OP_reg0: |
14814 | case DW_OP_reg1: | |
14815 | case DW_OP_reg2: | |
14816 | case DW_OP_reg3: | |
14817 | case DW_OP_reg4: | |
14818 | case DW_OP_reg5: | |
14819 | case DW_OP_reg6: | |
14820 | case DW_OP_reg7: | |
14821 | case DW_OP_reg8: | |
14822 | case DW_OP_reg9: | |
14823 | case DW_OP_reg10: | |
14824 | case DW_OP_reg11: | |
14825 | case DW_OP_reg12: | |
14826 | case DW_OP_reg13: | |
14827 | case DW_OP_reg14: | |
14828 | case DW_OP_reg15: | |
14829 | case DW_OP_reg16: | |
14830 | case DW_OP_reg17: | |
14831 | case DW_OP_reg18: | |
14832 | case DW_OP_reg19: | |
14833 | case DW_OP_reg20: | |
14834 | case DW_OP_reg21: | |
14835 | case DW_OP_reg22: | |
14836 | case DW_OP_reg23: | |
14837 | case DW_OP_reg24: | |
14838 | case DW_OP_reg25: | |
14839 | case DW_OP_reg26: | |
14840 | case DW_OP_reg27: | |
14841 | case DW_OP_reg28: | |
14842 | case DW_OP_reg29: | |
14843 | case DW_OP_reg30: | |
14844 | case DW_OP_reg31: | |
14845 | stack[++stacki] = op - DW_OP_reg0; | |
14846 | if (i < size) | |
14847 | dwarf2_complex_location_expr_complaint (); | |
14848 | break; | |
c906108c | 14849 | |
21ae7a4d JK |
14850 | case DW_OP_regx: |
14851 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
14852 | i += bytes_read; | |
14853 | stack[++stacki] = unsnd; | |
14854 | if (i < size) | |
14855 | dwarf2_complex_location_expr_complaint (); | |
14856 | break; | |
c906108c | 14857 | |
21ae7a4d JK |
14858 | case DW_OP_addr: |
14859 | stack[++stacki] = read_address (objfile->obfd, &data[i], | |
14860 | cu, &bytes_read); | |
14861 | i += bytes_read; | |
14862 | break; | |
d53d4ac5 | 14863 | |
21ae7a4d JK |
14864 | case DW_OP_const1u: |
14865 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
14866 | i += 1; | |
14867 | break; | |
14868 | ||
14869 | case DW_OP_const1s: | |
14870 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
14871 | i += 1; | |
14872 | break; | |
14873 | ||
14874 | case DW_OP_const2u: | |
14875 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
14876 | i += 2; | |
14877 | break; | |
14878 | ||
14879 | case DW_OP_const2s: | |
14880 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
14881 | i += 2; | |
14882 | break; | |
d53d4ac5 | 14883 | |
21ae7a4d JK |
14884 | case DW_OP_const4u: |
14885 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
14886 | i += 4; | |
14887 | break; | |
14888 | ||
14889 | case DW_OP_const4s: | |
14890 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
14891 | i += 4; | |
14892 | break; | |
14893 | ||
585861ea JK |
14894 | case DW_OP_const8u: |
14895 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); | |
14896 | i += 8; | |
14897 | break; | |
14898 | ||
21ae7a4d JK |
14899 | case DW_OP_constu: |
14900 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
14901 | &bytes_read); | |
14902 | i += bytes_read; | |
14903 | break; | |
14904 | ||
14905 | case DW_OP_consts: | |
14906 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
14907 | i += bytes_read; | |
14908 | break; | |
14909 | ||
14910 | case DW_OP_dup: | |
14911 | stack[stacki + 1] = stack[stacki]; | |
14912 | stacki++; | |
14913 | break; | |
14914 | ||
14915 | case DW_OP_plus: | |
14916 | stack[stacki - 1] += stack[stacki]; | |
14917 | stacki--; | |
14918 | break; | |
14919 | ||
14920 | case DW_OP_plus_uconst: | |
14921 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), | |
14922 | &bytes_read); | |
14923 | i += bytes_read; | |
14924 | break; | |
14925 | ||
14926 | case DW_OP_minus: | |
14927 | stack[stacki - 1] -= stack[stacki]; | |
14928 | stacki--; | |
14929 | break; | |
14930 | ||
14931 | case DW_OP_deref: | |
14932 | /* If we're not the last op, then we definitely can't encode | |
14933 | this using GDB's address_class enum. This is valid for partial | |
14934 | global symbols, although the variable's address will be bogus | |
14935 | in the psymtab. */ | |
14936 | if (i < size) | |
14937 | dwarf2_complex_location_expr_complaint (); | |
14938 | break; | |
14939 | ||
14940 | case DW_OP_GNU_push_tls_address: | |
14941 | /* The top of the stack has the offset from the beginning | |
14942 | of the thread control block at which the variable is located. */ | |
14943 | /* Nothing should follow this operator, so the top of stack would | |
14944 | be returned. */ | |
14945 | /* This is valid for partial global symbols, but the variable's | |
585861ea JK |
14946 | address will be bogus in the psymtab. Make it always at least |
14947 | non-zero to not look as a variable garbage collected by linker | |
14948 | which have DW_OP_addr 0. */ | |
21ae7a4d JK |
14949 | if (i < size) |
14950 | dwarf2_complex_location_expr_complaint (); | |
585861ea | 14951 | stack[stacki]++; |
21ae7a4d JK |
14952 | break; |
14953 | ||
14954 | case DW_OP_GNU_uninit: | |
14955 | break; | |
14956 | ||
14957 | default: | |
14958 | { | |
14959 | const char *name = dwarf_stack_op_name (op); | |
14960 | ||
14961 | if (name) | |
14962 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
14963 | name); | |
14964 | else | |
14965 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
14966 | op); | |
14967 | } | |
14968 | ||
14969 | return (stack[stacki]); | |
d53d4ac5 | 14970 | } |
3c6e0cb3 | 14971 | |
21ae7a4d JK |
14972 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
14973 | outside of the allocated space. Also enforce minimum>0. */ | |
14974 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
14975 | { | |
14976 | complaint (&symfile_complaints, | |
14977 | _("location description stack overflow")); | |
14978 | return 0; | |
14979 | } | |
14980 | ||
14981 | if (stacki <= 0) | |
14982 | { | |
14983 | complaint (&symfile_complaints, | |
14984 | _("location description stack underflow")); | |
14985 | return 0; | |
14986 | } | |
14987 | } | |
14988 | return (stack[stacki]); | |
c906108c SS |
14989 | } |
14990 | ||
14991 | /* memory allocation interface */ | |
14992 | ||
c906108c | 14993 | static struct dwarf_block * |
7b5a2f43 | 14994 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
14995 | { |
14996 | struct dwarf_block *blk; | |
14997 | ||
14998 | blk = (struct dwarf_block *) | |
7b5a2f43 | 14999 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
15000 | return (blk); |
15001 | } | |
15002 | ||
15003 | static struct abbrev_info * | |
f3dd6933 | 15004 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
15005 | { |
15006 | struct abbrev_info *abbrev; | |
15007 | ||
f3dd6933 DJ |
15008 | abbrev = (struct abbrev_info *) |
15009 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
15010 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
15011 | return (abbrev); | |
15012 | } | |
15013 | ||
15014 | static struct die_info * | |
b60c80d6 | 15015 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
15016 | { |
15017 | struct die_info *die; | |
b60c80d6 DJ |
15018 | size_t size = sizeof (struct die_info); |
15019 | ||
15020 | if (num_attrs > 1) | |
15021 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 15022 | |
b60c80d6 | 15023 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
15024 | memset (die, 0, sizeof (struct die_info)); |
15025 | return (die); | |
15026 | } | |
2e276125 JB |
15027 | |
15028 | \f | |
15029 | /* Macro support. */ | |
15030 | ||
2e276125 JB |
15031 | /* Return the full name of file number I in *LH's file name table. |
15032 | Use COMP_DIR as the name of the current directory of the | |
15033 | compilation. The result is allocated using xmalloc; the caller is | |
15034 | responsible for freeing it. */ | |
15035 | static char * | |
15036 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
15037 | { | |
6a83a1e6 EZ |
15038 | /* Is the file number a valid index into the line header's file name |
15039 | table? Remember that file numbers start with one, not zero. */ | |
15040 | if (1 <= file && file <= lh->num_file_names) | |
15041 | { | |
15042 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 15043 | |
6a83a1e6 EZ |
15044 | if (IS_ABSOLUTE_PATH (fe->name)) |
15045 | return xstrdup (fe->name); | |
15046 | else | |
15047 | { | |
15048 | const char *dir; | |
15049 | int dir_len; | |
15050 | char *full_name; | |
15051 | ||
15052 | if (fe->dir_index) | |
15053 | dir = lh->include_dirs[fe->dir_index - 1]; | |
15054 | else | |
15055 | dir = comp_dir; | |
15056 | ||
15057 | if (dir) | |
15058 | { | |
15059 | dir_len = strlen (dir); | |
15060 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
15061 | strcpy (full_name, dir); | |
15062 | full_name[dir_len] = '/'; | |
15063 | strcpy (full_name + dir_len + 1, fe->name); | |
15064 | return full_name; | |
15065 | } | |
15066 | else | |
15067 | return xstrdup (fe->name); | |
15068 | } | |
15069 | } | |
2e276125 JB |
15070 | else |
15071 | { | |
6a83a1e6 EZ |
15072 | /* The compiler produced a bogus file number. We can at least |
15073 | record the macro definitions made in the file, even if we | |
15074 | won't be able to find the file by name. */ | |
15075 | char fake_name[80]; | |
9a619af0 | 15076 | |
6a83a1e6 | 15077 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 15078 | |
6e70227d | 15079 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
15080 | _("bad file number in macro information (%d)"), |
15081 | file); | |
2e276125 | 15082 | |
6a83a1e6 | 15083 | return xstrdup (fake_name); |
2e276125 JB |
15084 | } |
15085 | } | |
15086 | ||
15087 | ||
15088 | static struct macro_source_file * | |
15089 | macro_start_file (int file, int line, | |
15090 | struct macro_source_file *current_file, | |
15091 | const char *comp_dir, | |
15092 | struct line_header *lh, struct objfile *objfile) | |
15093 | { | |
15094 | /* The full name of this source file. */ | |
15095 | char *full_name = file_full_name (file, lh, comp_dir); | |
15096 | ||
15097 | /* We don't create a macro table for this compilation unit | |
15098 | at all until we actually get a filename. */ | |
15099 | if (! pending_macros) | |
4a146b47 | 15100 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 15101 | objfile->macro_cache); |
2e276125 JB |
15102 | |
15103 | if (! current_file) | |
15104 | /* If we have no current file, then this must be the start_file | |
15105 | directive for the compilation unit's main source file. */ | |
15106 | current_file = macro_set_main (pending_macros, full_name); | |
15107 | else | |
15108 | current_file = macro_include (current_file, line, full_name); | |
15109 | ||
15110 | xfree (full_name); | |
6e70227d | 15111 | |
2e276125 JB |
15112 | return current_file; |
15113 | } | |
15114 | ||
15115 | ||
15116 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
15117 | followed by a null byte. */ | |
15118 | static char * | |
15119 | copy_string (const char *buf, int len) | |
15120 | { | |
15121 | char *s = xmalloc (len + 1); | |
9a619af0 | 15122 | |
2e276125 JB |
15123 | memcpy (s, buf, len); |
15124 | s[len] = '\0'; | |
2e276125 JB |
15125 | return s; |
15126 | } | |
15127 | ||
15128 | ||
15129 | static const char * | |
15130 | consume_improper_spaces (const char *p, const char *body) | |
15131 | { | |
15132 | if (*p == ' ') | |
15133 | { | |
4d3c2250 | 15134 | complaint (&symfile_complaints, |
3e43a32a MS |
15135 | _("macro definition contains spaces " |
15136 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 15137 | body); |
2e276125 JB |
15138 | |
15139 | while (*p == ' ') | |
15140 | p++; | |
15141 | } | |
15142 | ||
15143 | return p; | |
15144 | } | |
15145 | ||
15146 | ||
15147 | static void | |
15148 | parse_macro_definition (struct macro_source_file *file, int line, | |
15149 | const char *body) | |
15150 | { | |
15151 | const char *p; | |
15152 | ||
15153 | /* The body string takes one of two forms. For object-like macro | |
15154 | definitions, it should be: | |
15155 | ||
15156 | <macro name> " " <definition> | |
15157 | ||
15158 | For function-like macro definitions, it should be: | |
15159 | ||
15160 | <macro name> "() " <definition> | |
15161 | or | |
15162 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
15163 | ||
15164 | Spaces may appear only where explicitly indicated, and in the | |
15165 | <definition>. | |
15166 | ||
15167 | The Dwarf 2 spec says that an object-like macro's name is always | |
15168 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 15169 | the space when the macro's definition is the empty string. |
2e276125 JB |
15170 | |
15171 | The Dwarf 2 spec says that there should be no spaces between the | |
15172 | formal arguments in a function-like macro's formal argument list, | |
15173 | but versions of GCC around March 2002 include spaces after the | |
15174 | commas. */ | |
15175 | ||
15176 | ||
15177 | /* Find the extent of the macro name. The macro name is terminated | |
15178 | by either a space or null character (for an object-like macro) or | |
15179 | an opening paren (for a function-like macro). */ | |
15180 | for (p = body; *p; p++) | |
15181 | if (*p == ' ' || *p == '(') | |
15182 | break; | |
15183 | ||
15184 | if (*p == ' ' || *p == '\0') | |
15185 | { | |
15186 | /* It's an object-like macro. */ | |
15187 | int name_len = p - body; | |
15188 | char *name = copy_string (body, name_len); | |
15189 | const char *replacement; | |
15190 | ||
15191 | if (*p == ' ') | |
15192 | replacement = body + name_len + 1; | |
15193 | else | |
15194 | { | |
4d3c2250 | 15195 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15196 | replacement = body + name_len; |
15197 | } | |
6e70227d | 15198 | |
2e276125 JB |
15199 | macro_define_object (file, line, name, replacement); |
15200 | ||
15201 | xfree (name); | |
15202 | } | |
15203 | else if (*p == '(') | |
15204 | { | |
15205 | /* It's a function-like macro. */ | |
15206 | char *name = copy_string (body, p - body); | |
15207 | int argc = 0; | |
15208 | int argv_size = 1; | |
15209 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
15210 | ||
15211 | p++; | |
15212 | ||
15213 | p = consume_improper_spaces (p, body); | |
15214 | ||
15215 | /* Parse the formal argument list. */ | |
15216 | while (*p && *p != ')') | |
15217 | { | |
15218 | /* Find the extent of the current argument name. */ | |
15219 | const char *arg_start = p; | |
15220 | ||
15221 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
15222 | p++; | |
15223 | ||
15224 | if (! *p || p == arg_start) | |
4d3c2250 | 15225 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15226 | else |
15227 | { | |
15228 | /* Make sure argv has room for the new argument. */ | |
15229 | if (argc >= argv_size) | |
15230 | { | |
15231 | argv_size *= 2; | |
15232 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
15233 | } | |
15234 | ||
15235 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
15236 | } | |
15237 | ||
15238 | p = consume_improper_spaces (p, body); | |
15239 | ||
15240 | /* Consume the comma, if present. */ | |
15241 | if (*p == ',') | |
15242 | { | |
15243 | p++; | |
15244 | ||
15245 | p = consume_improper_spaces (p, body); | |
15246 | } | |
15247 | } | |
15248 | ||
15249 | if (*p == ')') | |
15250 | { | |
15251 | p++; | |
15252 | ||
15253 | if (*p == ' ') | |
15254 | /* Perfectly formed definition, no complaints. */ | |
15255 | macro_define_function (file, line, name, | |
6e70227d | 15256 | argc, (const char **) argv, |
2e276125 JB |
15257 | p + 1); |
15258 | else if (*p == '\0') | |
15259 | { | |
15260 | /* Complain, but do define it. */ | |
4d3c2250 | 15261 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 15262 | macro_define_function (file, line, name, |
6e70227d | 15263 | argc, (const char **) argv, |
2e276125 JB |
15264 | p); |
15265 | } | |
15266 | else | |
15267 | /* Just complain. */ | |
4d3c2250 | 15268 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15269 | } |
15270 | else | |
15271 | /* Just complain. */ | |
4d3c2250 | 15272 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15273 | |
15274 | xfree (name); | |
15275 | { | |
15276 | int i; | |
15277 | ||
15278 | for (i = 0; i < argc; i++) | |
15279 | xfree (argv[i]); | |
15280 | } | |
15281 | xfree (argv); | |
15282 | } | |
15283 | else | |
4d3c2250 | 15284 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
15285 | } |
15286 | ||
cf2c3c16 TT |
15287 | /* Skip some bytes from BYTES according to the form given in FORM. |
15288 | Returns the new pointer. */ | |
2e276125 | 15289 | |
cf2c3c16 TT |
15290 | static gdb_byte * |
15291 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, | |
15292 | enum dwarf_form form, | |
15293 | unsigned int offset_size, | |
15294 | struct dwarf2_section_info *section) | |
2e276125 | 15295 | { |
cf2c3c16 | 15296 | unsigned int bytes_read; |
2e276125 | 15297 | |
cf2c3c16 | 15298 | switch (form) |
2e276125 | 15299 | { |
cf2c3c16 TT |
15300 | case DW_FORM_data1: |
15301 | case DW_FORM_flag: | |
15302 | ++bytes; | |
15303 | break; | |
15304 | ||
15305 | case DW_FORM_data2: | |
15306 | bytes += 2; | |
15307 | break; | |
15308 | ||
15309 | case DW_FORM_data4: | |
15310 | bytes += 4; | |
15311 | break; | |
15312 | ||
15313 | case DW_FORM_data8: | |
15314 | bytes += 8; | |
15315 | break; | |
15316 | ||
15317 | case DW_FORM_string: | |
15318 | read_direct_string (abfd, bytes, &bytes_read); | |
15319 | bytes += bytes_read; | |
15320 | break; | |
15321 | ||
15322 | case DW_FORM_sec_offset: | |
15323 | case DW_FORM_strp: | |
15324 | bytes += offset_size; | |
15325 | break; | |
15326 | ||
15327 | case DW_FORM_block: | |
15328 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); | |
15329 | bytes += bytes_read; | |
15330 | break; | |
15331 | ||
15332 | case DW_FORM_block1: | |
15333 | bytes += 1 + read_1_byte (abfd, bytes); | |
15334 | break; | |
15335 | case DW_FORM_block2: | |
15336 | bytes += 2 + read_2_bytes (abfd, bytes); | |
15337 | break; | |
15338 | case DW_FORM_block4: | |
15339 | bytes += 4 + read_4_bytes (abfd, bytes); | |
15340 | break; | |
15341 | ||
15342 | case DW_FORM_sdata: | |
15343 | case DW_FORM_udata: | |
15344 | bytes = skip_leb128 (abfd, bytes); | |
15345 | break; | |
15346 | ||
15347 | default: | |
15348 | { | |
15349 | complain: | |
15350 | complaint (&symfile_complaints, | |
15351 | _("invalid form 0x%x in `%s'"), | |
15352 | form, | |
15353 | section->asection->name); | |
15354 | return NULL; | |
15355 | } | |
2e276125 JB |
15356 | } |
15357 | ||
cf2c3c16 TT |
15358 | return bytes; |
15359 | } | |
757a13d0 | 15360 | |
cf2c3c16 TT |
15361 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
15362 | opcode. Returns an updated pointer to the macro data buffer; or, | |
15363 | on error, issues a complaint and returns NULL. */ | |
757a13d0 | 15364 | |
cf2c3c16 TT |
15365 | static gdb_byte * |
15366 | skip_unknown_opcode (unsigned int opcode, | |
15367 | gdb_byte **opcode_definitions, | |
15368 | gdb_byte *mac_ptr, | |
15369 | bfd *abfd, | |
15370 | unsigned int offset_size, | |
15371 | struct dwarf2_section_info *section) | |
15372 | { | |
15373 | unsigned int bytes_read, i; | |
15374 | unsigned long arg; | |
15375 | gdb_byte *defn; | |
2e276125 | 15376 | |
cf2c3c16 | 15377 | if (opcode_definitions[opcode] == NULL) |
2e276125 | 15378 | { |
cf2c3c16 TT |
15379 | complaint (&symfile_complaints, |
15380 | _("unrecognized DW_MACFINO opcode 0x%x"), | |
15381 | opcode); | |
15382 | return NULL; | |
15383 | } | |
2e276125 | 15384 | |
cf2c3c16 TT |
15385 | defn = opcode_definitions[opcode]; |
15386 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); | |
15387 | defn += bytes_read; | |
2e276125 | 15388 | |
cf2c3c16 TT |
15389 | for (i = 0; i < arg; ++i) |
15390 | { | |
15391 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); | |
15392 | if (mac_ptr == NULL) | |
15393 | { | |
15394 | /* skip_form_bytes already issued the complaint. */ | |
15395 | return NULL; | |
15396 | } | |
15397 | } | |
757a13d0 | 15398 | |
cf2c3c16 TT |
15399 | return mac_ptr; |
15400 | } | |
757a13d0 | 15401 | |
cf2c3c16 TT |
15402 | /* A helper function which parses the header of a macro section. |
15403 | If the macro section is the extended (for now called "GNU") type, | |
15404 | then this updates *OFFSET_SIZE. Returns a pointer to just after | |
15405 | the header, or issues a complaint and returns NULL on error. */ | |
757a13d0 | 15406 | |
cf2c3c16 TT |
15407 | static gdb_byte * |
15408 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, | |
15409 | bfd *abfd, | |
15410 | gdb_byte *mac_ptr, | |
15411 | unsigned int *offset_size, | |
15412 | int section_is_gnu) | |
15413 | { | |
15414 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); | |
757a13d0 | 15415 | |
cf2c3c16 TT |
15416 | if (section_is_gnu) |
15417 | { | |
15418 | unsigned int version, flags; | |
757a13d0 | 15419 | |
cf2c3c16 TT |
15420 | version = read_2_bytes (abfd, mac_ptr); |
15421 | if (version != 4) | |
15422 | { | |
15423 | complaint (&symfile_complaints, | |
15424 | _("unrecognized version `%d' in .debug_macro section"), | |
15425 | version); | |
15426 | return NULL; | |
15427 | } | |
15428 | mac_ptr += 2; | |
757a13d0 | 15429 | |
cf2c3c16 TT |
15430 | flags = read_1_byte (abfd, mac_ptr); |
15431 | ++mac_ptr; | |
15432 | *offset_size = (flags & 1) ? 8 : 4; | |
757a13d0 | 15433 | |
cf2c3c16 TT |
15434 | if ((flags & 2) != 0) |
15435 | /* We don't need the line table offset. */ | |
15436 | mac_ptr += *offset_size; | |
757a13d0 | 15437 | |
cf2c3c16 TT |
15438 | /* Vendor opcode descriptions. */ |
15439 | if ((flags & 4) != 0) | |
15440 | { | |
15441 | unsigned int i, count; | |
757a13d0 | 15442 | |
cf2c3c16 TT |
15443 | count = read_1_byte (abfd, mac_ptr); |
15444 | ++mac_ptr; | |
15445 | for (i = 0; i < count; ++i) | |
15446 | { | |
15447 | unsigned int opcode, bytes_read; | |
15448 | unsigned long arg; | |
15449 | ||
15450 | opcode = read_1_byte (abfd, mac_ptr); | |
15451 | ++mac_ptr; | |
15452 | opcode_definitions[opcode] = mac_ptr; | |
15453 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15454 | mac_ptr += bytes_read; | |
15455 | mac_ptr += arg; | |
15456 | } | |
757a13d0 | 15457 | } |
cf2c3c16 | 15458 | } |
757a13d0 | 15459 | |
cf2c3c16 TT |
15460 | return mac_ptr; |
15461 | } | |
757a13d0 | 15462 | |
cf2c3c16 | 15463 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
8fc3fc34 | 15464 | including DW_MACRO_GNU_transparent_include. */ |
cf2c3c16 TT |
15465 | |
15466 | static void | |
15467 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, | |
15468 | struct macro_source_file *current_file, | |
15469 | struct line_header *lh, char *comp_dir, | |
15470 | struct dwarf2_section_info *section, | |
15471 | int section_is_gnu, | |
15472 | unsigned int offset_size, | |
8fc3fc34 TT |
15473 | struct objfile *objfile, |
15474 | htab_t include_hash) | |
cf2c3c16 TT |
15475 | { |
15476 | enum dwarf_macro_record_type macinfo_type; | |
15477 | int at_commandline; | |
15478 | gdb_byte *opcode_definitions[256]; | |
757a13d0 | 15479 | |
cf2c3c16 TT |
15480 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
15481 | &offset_size, section_is_gnu); | |
15482 | if (mac_ptr == NULL) | |
15483 | { | |
15484 | /* We already issued a complaint. */ | |
15485 | return; | |
15486 | } | |
757a13d0 JK |
15487 | |
15488 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
15489 | GDB is still reading the definitions from command line. First | |
15490 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
15491 | to create CURRENT_FILE for the main source holding also the command line | |
15492 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
15493 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
15494 | ||
15495 | at_commandline = 1; | |
15496 | ||
15497 | do | |
15498 | { | |
15499 | /* Do we at least have room for a macinfo type byte? */ | |
15500 | if (mac_ptr >= mac_end) | |
15501 | { | |
cf2c3c16 | 15502 | dwarf2_macros_too_long_complaint (section); |
757a13d0 JK |
15503 | break; |
15504 | } | |
15505 | ||
15506 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15507 | mac_ptr++; | |
15508 | ||
cf2c3c16 TT |
15509 | /* Note that we rely on the fact that the corresponding GNU and |
15510 | DWARF constants are the same. */ | |
757a13d0 JK |
15511 | switch (macinfo_type) |
15512 | { | |
15513 | /* A zero macinfo type indicates the end of the macro | |
15514 | information. */ | |
15515 | case 0: | |
15516 | break; | |
2e276125 | 15517 | |
cf2c3c16 TT |
15518 | case DW_MACRO_GNU_define: |
15519 | case DW_MACRO_GNU_undef: | |
15520 | case DW_MACRO_GNU_define_indirect: | |
15521 | case DW_MACRO_GNU_undef_indirect: | |
2e276125 | 15522 | { |
891d2f0b | 15523 | unsigned int bytes_read; |
2e276125 JB |
15524 | int line; |
15525 | char *body; | |
cf2c3c16 | 15526 | int is_define; |
2e276125 | 15527 | |
cf2c3c16 TT |
15528 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15529 | mac_ptr += bytes_read; | |
15530 | ||
15531 | if (macinfo_type == DW_MACRO_GNU_define | |
15532 | || macinfo_type == DW_MACRO_GNU_undef) | |
15533 | { | |
15534 | body = read_direct_string (abfd, mac_ptr, &bytes_read); | |
15535 | mac_ptr += bytes_read; | |
15536 | } | |
15537 | else | |
15538 | { | |
15539 | LONGEST str_offset; | |
15540 | ||
15541 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15542 | mac_ptr += offset_size; | |
2e276125 | 15543 | |
cf2c3c16 TT |
15544 | body = read_indirect_string_at_offset (abfd, str_offset); |
15545 | } | |
15546 | ||
15547 | is_define = (macinfo_type == DW_MACRO_GNU_define | |
15548 | || macinfo_type == DW_MACRO_GNU_define_indirect); | |
2e276125 | 15549 | if (! current_file) |
757a13d0 JK |
15550 | { |
15551 | /* DWARF violation as no main source is present. */ | |
15552 | complaint (&symfile_complaints, | |
15553 | _("debug info with no main source gives macro %s " | |
15554 | "on line %d: %s"), | |
cf2c3c16 TT |
15555 | is_define ? _("definition") : _("undefinition"), |
15556 | line, body); | |
757a13d0 JK |
15557 | break; |
15558 | } | |
3e43a32a MS |
15559 | if ((line == 0 && !at_commandline) |
15560 | || (line != 0 && at_commandline)) | |
4d3c2250 | 15561 | complaint (&symfile_complaints, |
757a13d0 JK |
15562 | _("debug info gives %s macro %s with %s line %d: %s"), |
15563 | at_commandline ? _("command-line") : _("in-file"), | |
cf2c3c16 | 15564 | is_define ? _("definition") : _("undefinition"), |
757a13d0 JK |
15565 | line == 0 ? _("zero") : _("non-zero"), line, body); |
15566 | ||
cf2c3c16 | 15567 | if (is_define) |
757a13d0 | 15568 | parse_macro_definition (current_file, line, body); |
cf2c3c16 TT |
15569 | else |
15570 | { | |
15571 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef | |
15572 | || macinfo_type == DW_MACRO_GNU_undef_indirect); | |
15573 | macro_undef (current_file, line, body); | |
15574 | } | |
2e276125 JB |
15575 | } |
15576 | break; | |
15577 | ||
cf2c3c16 | 15578 | case DW_MACRO_GNU_start_file: |
2e276125 | 15579 | { |
891d2f0b | 15580 | unsigned int bytes_read; |
2e276125 JB |
15581 | int line, file; |
15582 | ||
15583 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15584 | mac_ptr += bytes_read; | |
15585 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15586 | mac_ptr += bytes_read; | |
15587 | ||
3e43a32a MS |
15588 | if ((line == 0 && !at_commandline) |
15589 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
15590 | complaint (&symfile_complaints, |
15591 | _("debug info gives source %d included " | |
15592 | "from %s at %s line %d"), | |
15593 | file, at_commandline ? _("command-line") : _("file"), | |
15594 | line == 0 ? _("zero") : _("non-zero"), line); | |
15595 | ||
15596 | if (at_commandline) | |
15597 | { | |
cf2c3c16 TT |
15598 | /* This DW_MACRO_GNU_start_file was executed in the |
15599 | pass one. */ | |
757a13d0 JK |
15600 | at_commandline = 0; |
15601 | } | |
15602 | else | |
15603 | current_file = macro_start_file (file, line, | |
15604 | current_file, comp_dir, | |
cf2c3c16 | 15605 | lh, objfile); |
2e276125 JB |
15606 | } |
15607 | break; | |
15608 | ||
cf2c3c16 | 15609 | case DW_MACRO_GNU_end_file: |
2e276125 | 15610 | if (! current_file) |
4d3c2250 | 15611 | complaint (&symfile_complaints, |
3e43a32a MS |
15612 | _("macro debug info has an unmatched " |
15613 | "`close_file' directive")); | |
2e276125 JB |
15614 | else |
15615 | { | |
15616 | current_file = current_file->included_by; | |
15617 | if (! current_file) | |
15618 | { | |
cf2c3c16 | 15619 | enum dwarf_macro_record_type next_type; |
2e276125 JB |
15620 | |
15621 | /* GCC circa March 2002 doesn't produce the zero | |
15622 | type byte marking the end of the compilation | |
15623 | unit. Complain if it's not there, but exit no | |
15624 | matter what. */ | |
15625 | ||
15626 | /* Do we at least have room for a macinfo type byte? */ | |
15627 | if (mac_ptr >= mac_end) | |
15628 | { | |
cf2c3c16 | 15629 | dwarf2_macros_too_long_complaint (section); |
2e276125 JB |
15630 | return; |
15631 | } | |
15632 | ||
15633 | /* We don't increment mac_ptr here, so this is just | |
15634 | a look-ahead. */ | |
15635 | next_type = read_1_byte (abfd, mac_ptr); | |
15636 | if (next_type != 0) | |
4d3c2250 | 15637 | complaint (&symfile_complaints, |
3e43a32a MS |
15638 | _("no terminating 0-type entry for " |
15639 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
15640 | |
15641 | return; | |
15642 | } | |
15643 | } | |
15644 | break; | |
15645 | ||
cf2c3c16 TT |
15646 | case DW_MACRO_GNU_transparent_include: |
15647 | { | |
15648 | LONGEST offset; | |
8fc3fc34 | 15649 | void **slot; |
cf2c3c16 TT |
15650 | |
15651 | offset = read_offset_1 (abfd, mac_ptr, offset_size); | |
15652 | mac_ptr += offset_size; | |
15653 | ||
8fc3fc34 TT |
15654 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
15655 | if (*slot != NULL) | |
15656 | { | |
15657 | /* This has actually happened; see | |
15658 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ | |
15659 | complaint (&symfile_complaints, | |
15660 | _("recursive DW_MACRO_GNU_transparent_include in " | |
15661 | ".debug_macro section")); | |
15662 | } | |
15663 | else | |
15664 | { | |
15665 | *slot = mac_ptr; | |
15666 | ||
15667 | dwarf_decode_macro_bytes (abfd, | |
15668 | section->buffer + offset, | |
15669 | mac_end, current_file, | |
15670 | lh, comp_dir, | |
15671 | section, section_is_gnu, | |
15672 | offset_size, objfile, include_hash); | |
15673 | ||
15674 | htab_remove_elt (include_hash, mac_ptr); | |
15675 | } | |
cf2c3c16 TT |
15676 | } |
15677 | break; | |
15678 | ||
2e276125 | 15679 | case DW_MACINFO_vendor_ext: |
cf2c3c16 TT |
15680 | if (!section_is_gnu) |
15681 | { | |
15682 | unsigned int bytes_read; | |
15683 | int constant; | |
2e276125 | 15684 | |
cf2c3c16 TT |
15685 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
15686 | mac_ptr += bytes_read; | |
15687 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15688 | mac_ptr += bytes_read; | |
2e276125 | 15689 | |
cf2c3c16 TT |
15690 | /* We don't recognize any vendor extensions. */ |
15691 | break; | |
15692 | } | |
15693 | /* FALLTHROUGH */ | |
15694 | ||
15695 | default: | |
15696 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15697 | mac_ptr, abfd, offset_size, | |
15698 | section); | |
15699 | if (mac_ptr == NULL) | |
15700 | return; | |
15701 | break; | |
2e276125 | 15702 | } |
757a13d0 | 15703 | } while (macinfo_type != 0); |
2e276125 | 15704 | } |
8e19ed76 | 15705 | |
cf2c3c16 TT |
15706 | static void |
15707 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
15708 | char *comp_dir, bfd *abfd, | |
15709 | struct dwarf2_cu *cu, | |
15710 | struct dwarf2_section_info *section, | |
15711 | int section_is_gnu) | |
15712 | { | |
bb5ed363 | 15713 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
cf2c3c16 TT |
15714 | gdb_byte *mac_ptr, *mac_end; |
15715 | struct macro_source_file *current_file = 0; | |
15716 | enum dwarf_macro_record_type macinfo_type; | |
15717 | unsigned int offset_size = cu->header.offset_size; | |
15718 | gdb_byte *opcode_definitions[256]; | |
8fc3fc34 TT |
15719 | struct cleanup *cleanup; |
15720 | htab_t include_hash; | |
15721 | void **slot; | |
cf2c3c16 | 15722 | |
bb5ed363 | 15723 | dwarf2_read_section (objfile, section); |
cf2c3c16 TT |
15724 | if (section->buffer == NULL) |
15725 | { | |
15726 | complaint (&symfile_complaints, _("missing %s section"), | |
15727 | section->asection->name); | |
15728 | return; | |
15729 | } | |
15730 | ||
15731 | /* First pass: Find the name of the base filename. | |
15732 | This filename is needed in order to process all macros whose definition | |
15733 | (or undefinition) comes from the command line. These macros are defined | |
15734 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
15735 | associated to the base file. | |
15736 | ||
15737 | To determine the base file name, we scan the macro definitions until we | |
15738 | reach the first DW_MACINFO_start_file entry. We then initialize | |
15739 | CURRENT_FILE accordingly so that any macro definition found before the | |
15740 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
15741 | ||
15742 | mac_ptr = section->buffer + offset; | |
15743 | mac_end = section->buffer + section->size; | |
15744 | ||
15745 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, | |
15746 | &offset_size, section_is_gnu); | |
15747 | if (mac_ptr == NULL) | |
15748 | { | |
15749 | /* We already issued a complaint. */ | |
15750 | return; | |
15751 | } | |
15752 | ||
15753 | do | |
15754 | { | |
15755 | /* Do we at least have room for a macinfo type byte? */ | |
15756 | if (mac_ptr >= mac_end) | |
15757 | { | |
15758 | /* Complaint is printed during the second pass as GDB will probably | |
15759 | stop the first pass earlier upon finding | |
15760 | DW_MACINFO_start_file. */ | |
15761 | break; | |
15762 | } | |
15763 | ||
15764 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
15765 | mac_ptr++; | |
15766 | ||
15767 | /* Note that we rely on the fact that the corresponding GNU and | |
15768 | DWARF constants are the same. */ | |
15769 | switch (macinfo_type) | |
15770 | { | |
15771 | /* A zero macinfo type indicates the end of the macro | |
15772 | information. */ | |
15773 | case 0: | |
15774 | break; | |
15775 | ||
15776 | case DW_MACRO_GNU_define: | |
15777 | case DW_MACRO_GNU_undef: | |
15778 | /* Only skip the data by MAC_PTR. */ | |
15779 | { | |
15780 | unsigned int bytes_read; | |
15781 | ||
15782 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15783 | mac_ptr += bytes_read; | |
15784 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15785 | mac_ptr += bytes_read; | |
15786 | } | |
15787 | break; | |
15788 | ||
15789 | case DW_MACRO_GNU_start_file: | |
15790 | { | |
15791 | unsigned int bytes_read; | |
15792 | int line, file; | |
15793 | ||
15794 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15795 | mac_ptr += bytes_read; | |
15796 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15797 | mac_ptr += bytes_read; | |
15798 | ||
15799 | current_file = macro_start_file (file, line, current_file, | |
bb5ed363 | 15800 | comp_dir, lh, objfile); |
cf2c3c16 TT |
15801 | } |
15802 | break; | |
15803 | ||
15804 | case DW_MACRO_GNU_end_file: | |
15805 | /* No data to skip by MAC_PTR. */ | |
15806 | break; | |
15807 | ||
15808 | case DW_MACRO_GNU_define_indirect: | |
15809 | case DW_MACRO_GNU_undef_indirect: | |
15810 | { | |
15811 | unsigned int bytes_read; | |
15812 | ||
15813 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15814 | mac_ptr += bytes_read; | |
15815 | mac_ptr += offset_size; | |
15816 | } | |
15817 | break; | |
15818 | ||
15819 | case DW_MACRO_GNU_transparent_include: | |
15820 | /* Note that, according to the spec, a transparent include | |
15821 | chain cannot call DW_MACRO_GNU_start_file. So, we can just | |
15822 | skip this opcode. */ | |
15823 | mac_ptr += offset_size; | |
15824 | break; | |
15825 | ||
15826 | case DW_MACINFO_vendor_ext: | |
15827 | /* Only skip the data by MAC_PTR. */ | |
15828 | if (!section_is_gnu) | |
15829 | { | |
15830 | unsigned int bytes_read; | |
15831 | ||
15832 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
15833 | mac_ptr += bytes_read; | |
15834 | read_direct_string (abfd, mac_ptr, &bytes_read); | |
15835 | mac_ptr += bytes_read; | |
15836 | } | |
15837 | /* FALLTHROUGH */ | |
15838 | ||
15839 | default: | |
15840 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, | |
15841 | mac_ptr, abfd, offset_size, | |
15842 | section); | |
15843 | if (mac_ptr == NULL) | |
15844 | return; | |
15845 | break; | |
15846 | } | |
15847 | } while (macinfo_type != 0 && current_file == NULL); | |
15848 | ||
15849 | /* Second pass: Process all entries. | |
15850 | ||
15851 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
15852 | command-line macro definitions/undefinitions. This flag is unset when we | |
15853 | reach the first DW_MACINFO_start_file entry. */ | |
15854 | ||
8fc3fc34 TT |
15855 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
15856 | NULL, xcalloc, xfree); | |
15857 | cleanup = make_cleanup_htab_delete (include_hash); | |
15858 | mac_ptr = section->buffer + offset; | |
15859 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); | |
15860 | *slot = mac_ptr; | |
15861 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, | |
cf2c3c16 | 15862 | current_file, lh, comp_dir, section, section_is_gnu, |
8fc3fc34 TT |
15863 | offset_size, objfile, include_hash); |
15864 | do_cleanups (cleanup); | |
cf2c3c16 TT |
15865 | } |
15866 | ||
8e19ed76 | 15867 | /* Check if the attribute's form is a DW_FORM_block* |
0963b4bd | 15868 | if so return true else false. */ |
380bca97 | 15869 | |
8e19ed76 PS |
15870 | static int |
15871 | attr_form_is_block (struct attribute *attr) | |
15872 | { | |
15873 | return (attr == NULL ? 0 : | |
15874 | attr->form == DW_FORM_block1 | |
15875 | || attr->form == DW_FORM_block2 | |
15876 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
15877 | || attr->form == DW_FORM_block |
15878 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 15879 | } |
4c2df51b | 15880 | |
c6a0999f JB |
15881 | /* Return non-zero if ATTR's value is a section offset --- classes |
15882 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
15883 | You may use DW_UNSND (attr) to retrieve such offsets. | |
15884 | ||
15885 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
15886 | may have a value that belongs to more than one of these classes; it | |
15887 | would be ambiguous if we did, because we use the same forms for all | |
15888 | of them. */ | |
380bca97 | 15889 | |
3690dd37 JB |
15890 | static int |
15891 | attr_form_is_section_offset (struct attribute *attr) | |
15892 | { | |
15893 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
15894 | || attr->form == DW_FORM_data8 |
15895 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
15896 | } |
15897 | ||
3690dd37 JB |
15898 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
15899 | zero otherwise. When this function returns true, you can apply | |
15900 | dwarf2_get_attr_constant_value to it. | |
15901 | ||
15902 | However, note that for some attributes you must check | |
15903 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
15904 | and DW_FORM_data8 are members of both the constant class, and of | |
15905 | the classes that contain offsets into other debug sections | |
15906 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
15907 | that, if an attribute's can be either a constant or one of the | |
15908 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
15909 | taken as section offsets, not constants. */ | |
380bca97 | 15910 | |
3690dd37 JB |
15911 | static int |
15912 | attr_form_is_constant (struct attribute *attr) | |
15913 | { | |
15914 | switch (attr->form) | |
15915 | { | |
15916 | case DW_FORM_sdata: | |
15917 | case DW_FORM_udata: | |
15918 | case DW_FORM_data1: | |
15919 | case DW_FORM_data2: | |
15920 | case DW_FORM_data4: | |
15921 | case DW_FORM_data8: | |
15922 | return 1; | |
15923 | default: | |
15924 | return 0; | |
15925 | } | |
15926 | } | |
15927 | ||
8cf6f0b1 TT |
15928 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
15929 | ||
15930 | static void | |
15931 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
15932 | struct dwarf2_loclist_baton *baton, | |
15933 | struct attribute *attr) | |
15934 | { | |
15935 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
15936 | &dwarf2_per_objfile->loc); | |
15937 | ||
15938 | baton->per_cu = cu->per_cu; | |
15939 | gdb_assert (baton->per_cu); | |
15940 | /* We don't know how long the location list is, but make sure we | |
15941 | don't run off the edge of the section. */ | |
15942 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
15943 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
15944 | baton->base_address = cu->base_address; | |
15945 | } | |
15946 | ||
4c2df51b DJ |
15947 | static void |
15948 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 15949 | struct dwarf2_cu *cu) |
4c2df51b | 15950 | { |
bb5ed363 DE |
15951 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
15952 | ||
3690dd37 | 15953 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
15954 | /* ".debug_loc" may not exist at all, or the offset may be outside |
15955 | the section. If so, fall through to the complaint in the | |
15956 | other branch. */ | |
bb5ed363 | 15957 | && DW_UNSND (attr) < dwarf2_section_size (objfile, |
9e0ac564 | 15958 | &dwarf2_per_objfile->loc)) |
4c2df51b | 15959 | { |
0d53c4c4 | 15960 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 15961 | |
bb5ed363 | 15962 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15963 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 15964 | |
8cf6f0b1 | 15965 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 15966 | |
d00adf39 | 15967 | if (cu->base_known == 0) |
0d53c4c4 | 15968 | complaint (&symfile_complaints, |
3e43a32a MS |
15969 | _("Location list used without " |
15970 | "specifying the CU base address.")); | |
4c2df51b | 15971 | |
768a979c | 15972 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
15973 | SYMBOL_LOCATION_BATON (sym) = baton; |
15974 | } | |
15975 | else | |
15976 | { | |
15977 | struct dwarf2_locexpr_baton *baton; | |
15978 | ||
bb5ed363 | 15979 | baton = obstack_alloc (&objfile->objfile_obstack, |
0d53c4c4 | 15980 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
15981 | baton->per_cu = cu->per_cu; |
15982 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
15983 | |
15984 | if (attr_form_is_block (attr)) | |
15985 | { | |
15986 | /* Note that we're just copying the block's data pointer | |
15987 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
15988 | info_buffer for SYM's objfile; right now we never release |
15989 | that buffer, but when we do clean up properly this may | |
15990 | need to change. */ | |
0d53c4c4 DJ |
15991 | baton->size = DW_BLOCK (attr)->size; |
15992 | baton->data = DW_BLOCK (attr)->data; | |
15993 | } | |
15994 | else | |
15995 | { | |
15996 | dwarf2_invalid_attrib_class_complaint ("location description", | |
15997 | SYMBOL_NATURAL_NAME (sym)); | |
15998 | baton->size = 0; | |
0d53c4c4 | 15999 | } |
6e70227d | 16000 | |
768a979c | 16001 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
16002 | SYMBOL_LOCATION_BATON (sym) = baton; |
16003 | } | |
4c2df51b | 16004 | } |
6502dd73 | 16005 | |
9aa1f1e3 TT |
16006 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
16007 | came from a separate debuginfo file, then the master objfile is | |
16008 | returned. */ | |
ae0d2f24 UW |
16009 | |
16010 | struct objfile * | |
16011 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
16012 | { | |
9291a0cd | 16013 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
16014 | |
16015 | /* Return the master objfile, so that we can report and look up the | |
16016 | correct file containing this variable. */ | |
16017 | if (objfile->separate_debug_objfile_backlink) | |
16018 | objfile = objfile->separate_debug_objfile_backlink; | |
16019 | ||
16020 | return objfile; | |
16021 | } | |
16022 | ||
96408a79 SA |
16023 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
16024 | (CU_HEADERP is unused in such case) or prepare a temporary copy at | |
16025 | CU_HEADERP first. */ | |
16026 | ||
16027 | static const struct comp_unit_head * | |
16028 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, | |
16029 | struct dwarf2_per_cu_data *per_cu) | |
16030 | { | |
16031 | struct objfile *objfile; | |
16032 | struct dwarf2_per_objfile *per_objfile; | |
16033 | gdb_byte *info_ptr; | |
16034 | ||
16035 | if (per_cu->cu) | |
16036 | return &per_cu->cu->header; | |
16037 | ||
16038 | objfile = per_cu->objfile; | |
16039 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
b64f50a1 | 16040 | info_ptr = per_objfile->info.buffer + per_cu->offset.sect_off; |
96408a79 SA |
16041 | |
16042 | memset (cu_headerp, 0, sizeof (*cu_headerp)); | |
16043 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); | |
16044 | ||
16045 | return cu_headerp; | |
16046 | } | |
16047 | ||
ae0d2f24 UW |
16048 | /* Return the address size given in the compilation unit header for CU. */ |
16049 | ||
98714339 | 16050 | int |
ae0d2f24 UW |
16051 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
16052 | { | |
96408a79 SA |
16053 | struct comp_unit_head cu_header_local; |
16054 | const struct comp_unit_head *cu_headerp; | |
c471e790 | 16055 | |
96408a79 SA |
16056 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
16057 | ||
16058 | return cu_headerp->addr_size; | |
ae0d2f24 UW |
16059 | } |
16060 | ||
9eae7c52 TT |
16061 | /* Return the offset size given in the compilation unit header for CU. */ |
16062 | ||
16063 | int | |
16064 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
16065 | { | |
96408a79 SA |
16066 | struct comp_unit_head cu_header_local; |
16067 | const struct comp_unit_head *cu_headerp; | |
9c6c53f7 | 16068 | |
96408a79 SA |
16069 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
16070 | ||
16071 | return cu_headerp->offset_size; | |
16072 | } | |
16073 | ||
16074 | /* See its dwarf2loc.h declaration. */ | |
16075 | ||
16076 | int | |
16077 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) | |
16078 | { | |
16079 | struct comp_unit_head cu_header_local; | |
16080 | const struct comp_unit_head *cu_headerp; | |
16081 | ||
16082 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); | |
16083 | ||
16084 | if (cu_headerp->version == 2) | |
16085 | return cu_headerp->addr_size; | |
16086 | else | |
16087 | return cu_headerp->offset_size; | |
181cebd4 JK |
16088 | } |
16089 | ||
9aa1f1e3 TT |
16090 | /* Return the text offset of the CU. The returned offset comes from |
16091 | this CU's objfile. If this objfile came from a separate debuginfo | |
16092 | file, then the offset may be different from the corresponding | |
16093 | offset in the parent objfile. */ | |
16094 | ||
16095 | CORE_ADDR | |
16096 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
16097 | { | |
bb3fa9d0 | 16098 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
16099 | |
16100 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16101 | } | |
16102 | ||
348e048f DE |
16103 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
16104 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
16105 | |
16106 | static struct dwarf2_per_cu_data * | |
b64f50a1 | 16107 | dwarf2_find_containing_comp_unit (sect_offset offset, |
ae038cb0 DJ |
16108 | struct objfile *objfile) |
16109 | { | |
16110 | struct dwarf2_per_cu_data *this_cu; | |
16111 | int low, high; | |
16112 | ||
ae038cb0 DJ |
16113 | low = 0; |
16114 | high = dwarf2_per_objfile->n_comp_units - 1; | |
16115 | while (high > low) | |
16116 | { | |
16117 | int mid = low + (high - low) / 2; | |
9a619af0 | 16118 | |
b64f50a1 JK |
16119 | if (dwarf2_per_objfile->all_comp_units[mid]->offset.sect_off |
16120 | >= offset.sect_off) | |
ae038cb0 DJ |
16121 | high = mid; |
16122 | else | |
16123 | low = mid + 1; | |
16124 | } | |
16125 | gdb_assert (low == high); | |
b64f50a1 JK |
16126 | if (dwarf2_per_objfile->all_comp_units[low]->offset.sect_off |
16127 | > offset.sect_off) | |
ae038cb0 | 16128 | { |
10b3939b | 16129 | if (low == 0) |
8a3fe4f8 AC |
16130 | error (_("Dwarf Error: could not find partial DIE containing " |
16131 | "offset 0x%lx [in module %s]"), | |
b64f50a1 | 16132 | (long) offset.sect_off, bfd_get_filename (objfile->obfd)); |
10b3939b | 16133 | |
b64f50a1 JK |
16134 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off |
16135 | <= offset.sect_off); | |
ae038cb0 DJ |
16136 | return dwarf2_per_objfile->all_comp_units[low-1]; |
16137 | } | |
16138 | else | |
16139 | { | |
16140 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
16141 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
b64f50a1 JK |
16142 | && offset.sect_off >= this_cu->offset.sect_off + this_cu->length) |
16143 | error (_("invalid dwarf2 offset %u"), offset.sect_off); | |
16144 | gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length); | |
ae038cb0 DJ |
16145 | return this_cu; |
16146 | } | |
16147 | } | |
16148 | ||
23745b47 | 16149 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
93311388 | 16150 | |
9816fde3 | 16151 | static void |
23745b47 | 16152 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
93311388 | 16153 | { |
9816fde3 | 16154 | memset (cu, 0, sizeof (*cu)); |
23745b47 DE |
16155 | per_cu->cu = cu; |
16156 | cu->per_cu = per_cu; | |
16157 | cu->objfile = per_cu->objfile; | |
93311388 | 16158 | obstack_init (&cu->comp_unit_obstack); |
9816fde3 JK |
16159 | } |
16160 | ||
16161 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
16162 | ||
16163 | static void | |
16164 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
16165 | { | |
16166 | struct attribute *attr; | |
16167 | ||
16168 | /* Set the language we're debugging. */ | |
16169 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
16170 | if (attr) | |
16171 | set_cu_language (DW_UNSND (attr), cu); | |
16172 | else | |
9cded63f TT |
16173 | { |
16174 | cu->language = language_minimal; | |
16175 | cu->language_defn = language_def (cu->language); | |
16176 | } | |
dee91e82 DE |
16177 | |
16178 | attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu); | |
16179 | if (attr) | |
16180 | cu->producer = DW_STRING (attr); | |
93311388 DE |
16181 | } |
16182 | ||
ae038cb0 DJ |
16183 | /* Release one cached compilation unit, CU. We unlink it from the tree |
16184 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
16185 | the caller is responsible for that. |
16186 | NOTE: DATA is a void * because this function is also used as a | |
16187 | cleanup routine. */ | |
ae038cb0 DJ |
16188 | |
16189 | static void | |
68dc6402 | 16190 | free_heap_comp_unit (void *data) |
ae038cb0 DJ |
16191 | { |
16192 | struct dwarf2_cu *cu = data; | |
16193 | ||
23745b47 DE |
16194 | gdb_assert (cu->per_cu != NULL); |
16195 | cu->per_cu->cu = NULL; | |
ae038cb0 DJ |
16196 | cu->per_cu = NULL; |
16197 | ||
16198 | obstack_free (&cu->comp_unit_obstack, NULL); | |
16199 | ||
16200 | xfree (cu); | |
16201 | } | |
16202 | ||
72bf9492 | 16203 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 | 16204 | when we're finished with it. We can't free the pointer itself, but be |
dee91e82 | 16205 | sure to unlink it from the cache. Also release any associated storage. */ |
72bf9492 DJ |
16206 | |
16207 | static void | |
16208 | free_stack_comp_unit (void *data) | |
16209 | { | |
16210 | struct dwarf2_cu *cu = data; | |
16211 | ||
23745b47 DE |
16212 | gdb_assert (cu->per_cu != NULL); |
16213 | cu->per_cu->cu = NULL; | |
16214 | cu->per_cu = NULL; | |
16215 | ||
72bf9492 DJ |
16216 | obstack_free (&cu->comp_unit_obstack, NULL); |
16217 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
16218 | } |
16219 | ||
16220 | /* Free all cached compilation units. */ | |
16221 | ||
16222 | static void | |
16223 | free_cached_comp_units (void *data) | |
16224 | { | |
16225 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
16226 | ||
16227 | per_cu = dwarf2_per_objfile->read_in_chain; | |
16228 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
16229 | while (per_cu != NULL) | |
16230 | { | |
16231 | struct dwarf2_per_cu_data *next_cu; | |
16232 | ||
16233 | next_cu = per_cu->cu->read_in_chain; | |
16234 | ||
68dc6402 | 16235 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
16236 | *last_chain = next_cu; |
16237 | ||
16238 | per_cu = next_cu; | |
16239 | } | |
16240 | } | |
16241 | ||
16242 | /* Increase the age counter on each cached compilation unit, and free | |
16243 | any that are too old. */ | |
16244 | ||
16245 | static void | |
16246 | age_cached_comp_units (void) | |
16247 | { | |
16248 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
16249 | ||
16250 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
16251 | per_cu = dwarf2_per_objfile->read_in_chain; | |
16252 | while (per_cu != NULL) | |
16253 | { | |
16254 | per_cu->cu->last_used ++; | |
16255 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
16256 | dwarf2_mark (per_cu->cu); | |
16257 | per_cu = per_cu->cu->read_in_chain; | |
16258 | } | |
16259 | ||
16260 | per_cu = dwarf2_per_objfile->read_in_chain; | |
16261 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
16262 | while (per_cu != NULL) | |
16263 | { | |
16264 | struct dwarf2_per_cu_data *next_cu; | |
16265 | ||
16266 | next_cu = per_cu->cu->read_in_chain; | |
16267 | ||
16268 | if (!per_cu->cu->mark) | |
16269 | { | |
68dc6402 | 16270 | free_heap_comp_unit (per_cu->cu); |
ae038cb0 DJ |
16271 | *last_chain = next_cu; |
16272 | } | |
16273 | else | |
16274 | last_chain = &per_cu->cu->read_in_chain; | |
16275 | ||
16276 | per_cu = next_cu; | |
16277 | } | |
16278 | } | |
16279 | ||
16280 | /* Remove a single compilation unit from the cache. */ | |
16281 | ||
16282 | static void | |
dee91e82 | 16283 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
ae038cb0 DJ |
16284 | { |
16285 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
16286 | ||
16287 | per_cu = dwarf2_per_objfile->read_in_chain; | |
16288 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
16289 | while (per_cu != NULL) | |
16290 | { | |
16291 | struct dwarf2_per_cu_data *next_cu; | |
16292 | ||
16293 | next_cu = per_cu->cu->read_in_chain; | |
16294 | ||
dee91e82 | 16295 | if (per_cu == target_per_cu) |
ae038cb0 | 16296 | { |
68dc6402 | 16297 | free_heap_comp_unit (per_cu->cu); |
dee91e82 | 16298 | per_cu->cu = NULL; |
ae038cb0 DJ |
16299 | *last_chain = next_cu; |
16300 | break; | |
16301 | } | |
16302 | else | |
16303 | last_chain = &per_cu->cu->read_in_chain; | |
16304 | ||
16305 | per_cu = next_cu; | |
16306 | } | |
16307 | } | |
16308 | ||
fe3e1990 DJ |
16309 | /* Release all extra memory associated with OBJFILE. */ |
16310 | ||
16311 | void | |
16312 | dwarf2_free_objfile (struct objfile *objfile) | |
16313 | { | |
16314 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16315 | ||
16316 | if (dwarf2_per_objfile == NULL) | |
16317 | return; | |
16318 | ||
16319 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
16320 | free_cached_comp_units (NULL); | |
16321 | ||
7b9f3c50 DE |
16322 | if (dwarf2_per_objfile->quick_file_names_table) |
16323 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 16324 | |
fe3e1990 DJ |
16325 | /* Everything else should be on the objfile obstack. */ |
16326 | } | |
16327 | ||
dee91e82 DE |
16328 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
16329 | We store these in a hash table separate from the DIEs, and preserve them | |
16330 | when the DIEs are flushed out of cache. | |
16331 | ||
16332 | The CU "per_cu" pointer is needed because offset alone is not enough to | |
16333 | uniquely identify the type. A file may have multiple .debug_types sections. | |
16334 | We have to use something in dwarf2_per_cu_data (or the pointer to it) | |
16335 | because we can enter the lookup routine, get_die_type_at_offset, from | |
16336 | outside this file, and thus won't necessarily have PER_CU->cu. | |
16337 | Fortunately, PER_CU is stable for the life of the objfile. */ | |
1c379e20 | 16338 | |
dee91e82 | 16339 | struct dwarf2_per_cu_offset_and_type |
1c379e20 | 16340 | { |
dee91e82 | 16341 | const struct dwarf2_per_cu_data *per_cu; |
b64f50a1 | 16342 | sect_offset offset; |
1c379e20 DJ |
16343 | struct type *type; |
16344 | }; | |
16345 | ||
dee91e82 | 16346 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
16347 | |
16348 | static hashval_t | |
dee91e82 | 16349 | per_cu_offset_and_type_hash (const void *item) |
1c379e20 | 16350 | { |
dee91e82 | 16351 | const struct dwarf2_per_cu_offset_and_type *ofs = item; |
9a619af0 | 16352 | |
dee91e82 | 16353 | return (uintptr_t) ofs->per_cu + ofs->offset.sect_off; |
1c379e20 DJ |
16354 | } |
16355 | ||
dee91e82 | 16356 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
1c379e20 DJ |
16357 | |
16358 | static int | |
dee91e82 | 16359 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
1c379e20 | 16360 | { |
dee91e82 DE |
16361 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs; |
16362 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 16363 | |
dee91e82 DE |
16364 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
16365 | && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off); | |
1c379e20 DJ |
16366 | } |
16367 | ||
16368 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
16369 | table if necessary. For convenience, return TYPE. |
16370 | ||
16371 | The DIEs reading must have careful ordering to: | |
16372 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
16373 | reading current DIE. | |
16374 | * Not trying to dereference contents of still incompletely read in types | |
16375 | while reading in other DIEs. | |
16376 | * Enable referencing still incompletely read in types just by a pointer to | |
16377 | the type without accessing its fields. | |
16378 | ||
16379 | Therefore caller should follow these rules: | |
16380 | * Try to fetch any prerequisite types we may need to build this DIE type | |
16381 | before building the type and calling set_die_type. | |
e71ec853 | 16382 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
16383 | possible before fetching more types to complete the current type. |
16384 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 16385 | |
f792889a | 16386 | static struct type * |
1c379e20 DJ |
16387 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
16388 | { | |
dee91e82 | 16389 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
673bfd45 | 16390 | struct objfile *objfile = cu->objfile; |
1c379e20 | 16391 | |
b4ba55a1 JB |
16392 | /* For Ada types, make sure that the gnat-specific data is always |
16393 | initialized (if not already set). There are a few types where | |
16394 | we should not be doing so, because the type-specific area is | |
16395 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
16396 | where the type-specific area is used to store the floatformat). | |
16397 | But this is not a problem, because the gnat-specific information | |
16398 | is actually not needed for these types. */ | |
16399 | if (need_gnat_info (cu) | |
16400 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
16401 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
16402 | && !HAVE_GNAT_AUX_INFO (type)) | |
16403 | INIT_GNAT_SPECIFIC (type); | |
16404 | ||
dee91e82 | 16405 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 16406 | { |
dee91e82 DE |
16407 | dwarf2_per_objfile->die_type_hash = |
16408 | htab_create_alloc_ex (127, | |
16409 | per_cu_offset_and_type_hash, | |
16410 | per_cu_offset_and_type_eq, | |
16411 | NULL, | |
16412 | &objfile->objfile_obstack, | |
16413 | hashtab_obstack_allocate, | |
16414 | dummy_obstack_deallocate); | |
f792889a | 16415 | } |
1c379e20 | 16416 | |
dee91e82 | 16417 | ofs.per_cu = cu->per_cu; |
1c379e20 DJ |
16418 | ofs.offset = die->offset; |
16419 | ofs.type = type; | |
dee91e82 DE |
16420 | slot = (struct dwarf2_per_cu_offset_and_type **) |
16421 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); | |
7e314c57 JK |
16422 | if (*slot) |
16423 | complaint (&symfile_complaints, | |
16424 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
b64f50a1 | 16425 | die->offset.sect_off); |
673bfd45 | 16426 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 16427 | **slot = ofs; |
f792889a | 16428 | return type; |
1c379e20 DJ |
16429 | } |
16430 | ||
380bca97 | 16431 | /* Look up the type for the die at OFFSET in the appropriate type_hash |
673bfd45 | 16432 | table, or return NULL if the die does not have a saved type. */ |
1c379e20 DJ |
16433 | |
16434 | static struct type * | |
b64f50a1 | 16435 | get_die_type_at_offset (sect_offset offset, |
673bfd45 | 16436 | struct dwarf2_per_cu_data *per_cu) |
1c379e20 | 16437 | { |
dee91e82 | 16438 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
f792889a | 16439 | |
dee91e82 | 16440 | if (dwarf2_per_objfile->die_type_hash == NULL) |
f792889a | 16441 | return NULL; |
1c379e20 | 16442 | |
dee91e82 | 16443 | ofs.per_cu = per_cu; |
673bfd45 | 16444 | ofs.offset = offset; |
dee91e82 | 16445 | slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs); |
1c379e20 DJ |
16446 | if (slot) |
16447 | return slot->type; | |
16448 | else | |
16449 | return NULL; | |
16450 | } | |
16451 | ||
673bfd45 DE |
16452 | /* Look up the type for DIE in the appropriate type_hash table, |
16453 | or return NULL if DIE does not have a saved type. */ | |
16454 | ||
16455 | static struct type * | |
16456 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
16457 | { | |
16458 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
16459 | } | |
16460 | ||
10b3939b DJ |
16461 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
16462 | ||
16463 | static void | |
16464 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
16465 | struct dwarf2_per_cu_data *ref_per_cu) | |
16466 | { | |
16467 | void **slot; | |
16468 | ||
16469 | if (cu->dependencies == NULL) | |
16470 | cu->dependencies | |
16471 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
16472 | NULL, &cu->comp_unit_obstack, | |
16473 | hashtab_obstack_allocate, | |
16474 | dummy_obstack_deallocate); | |
16475 | ||
16476 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
16477 | if (*slot == NULL) | |
16478 | *slot = ref_per_cu; | |
16479 | } | |
1c379e20 | 16480 | |
f504f079 DE |
16481 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
16482 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
16483 | cache that we must keep because we are keeping CU. */ |
16484 | ||
10b3939b DJ |
16485 | static int |
16486 | dwarf2_mark_helper (void **slot, void *data) | |
16487 | { | |
16488 | struct dwarf2_per_cu_data *per_cu; | |
16489 | ||
16490 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
d07ed419 JK |
16491 | |
16492 | /* cu->dependencies references may not yet have been ever read if QUIT aborts | |
16493 | reading of the chain. As such dependencies remain valid it is not much | |
16494 | useful to track and undo them during QUIT cleanups. */ | |
16495 | if (per_cu->cu == NULL) | |
16496 | return 1; | |
16497 | ||
10b3939b DJ |
16498 | if (per_cu->cu->mark) |
16499 | return 1; | |
16500 | per_cu->cu->mark = 1; | |
16501 | ||
16502 | if (per_cu->cu->dependencies != NULL) | |
16503 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
16504 | ||
16505 | return 1; | |
16506 | } | |
16507 | ||
f504f079 DE |
16508 | /* Set the mark field in CU and in every other compilation unit in the |
16509 | cache that we must keep because we are keeping CU. */ | |
16510 | ||
ae038cb0 DJ |
16511 | static void |
16512 | dwarf2_mark (struct dwarf2_cu *cu) | |
16513 | { | |
16514 | if (cu->mark) | |
16515 | return; | |
16516 | cu->mark = 1; | |
10b3939b DJ |
16517 | if (cu->dependencies != NULL) |
16518 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
16519 | } |
16520 | ||
16521 | static void | |
16522 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
16523 | { | |
16524 | while (per_cu) | |
16525 | { | |
16526 | per_cu->cu->mark = 0; | |
16527 | per_cu = per_cu->cu->read_in_chain; | |
16528 | } | |
72bf9492 DJ |
16529 | } |
16530 | ||
72bf9492 DJ |
16531 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
16532 | is its offset in .debug_info for this objfile. */ | |
16533 | ||
16534 | static hashval_t | |
16535 | partial_die_hash (const void *item) | |
16536 | { | |
16537 | const struct partial_die_info *part_die = item; | |
9a619af0 | 16538 | |
b64f50a1 | 16539 | return part_die->offset.sect_off; |
72bf9492 DJ |
16540 | } |
16541 | ||
16542 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
16543 | are equal if they have the same offset. */ | |
16544 | ||
16545 | static int | |
16546 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
16547 | { | |
16548 | const struct partial_die_info *part_die_lhs = item_lhs; | |
16549 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 16550 | |
b64f50a1 | 16551 | return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off; |
72bf9492 DJ |
16552 | } |
16553 | ||
ae038cb0 DJ |
16554 | static struct cmd_list_element *set_dwarf2_cmdlist; |
16555 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
16556 | ||
16557 | static void | |
16558 | set_dwarf2_cmd (char *args, int from_tty) | |
16559 | { | |
16560 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
16561 | } | |
16562 | ||
16563 | static void | |
16564 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 16565 | { |
ae038cb0 DJ |
16566 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
16567 | } | |
16568 | ||
dce234bc PP |
16569 | /* If section described by INFO was mmapped, munmap it now. */ |
16570 | ||
16571 | static void | |
16572 | munmap_section_buffer (struct dwarf2_section_info *info) | |
16573 | { | |
b315ab21 | 16574 | if (info->map_addr != NULL) |
dce234bc PP |
16575 | { |
16576 | #ifdef HAVE_MMAP | |
b315ab21 | 16577 | int res; |
9a619af0 | 16578 | |
b315ab21 TG |
16579 | res = munmap (info->map_addr, info->map_len); |
16580 | gdb_assert (res == 0); | |
dce234bc PP |
16581 | #else |
16582 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 16583 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
16584 | #endif |
16585 | } | |
16586 | } | |
16587 | ||
16588 | /* munmap debug sections for OBJFILE, if necessary. */ | |
16589 | ||
16590 | static void | |
c1bd65d0 | 16591 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
16592 | { |
16593 | struct dwarf2_per_objfile *data = d; | |
8b70b953 TT |
16594 | int ix; |
16595 | struct dwarf2_section_info *section; | |
9a619af0 | 16596 | |
16be1145 DE |
16597 | /* This is sorted according to the order they're defined in to make it easier |
16598 | to keep in sync. */ | |
dce234bc PP |
16599 | munmap_section_buffer (&data->info); |
16600 | munmap_section_buffer (&data->abbrev); | |
16601 | munmap_section_buffer (&data->line); | |
16be1145 | 16602 | munmap_section_buffer (&data->loc); |
dce234bc | 16603 | munmap_section_buffer (&data->macinfo); |
cf2c3c16 | 16604 | munmap_section_buffer (&data->macro); |
16be1145 | 16605 | munmap_section_buffer (&data->str); |
dce234bc | 16606 | munmap_section_buffer (&data->ranges); |
dce234bc PP |
16607 | munmap_section_buffer (&data->frame); |
16608 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd | 16609 | munmap_section_buffer (&data->gdb_index); |
8b70b953 TT |
16610 | |
16611 | for (ix = 0; | |
16612 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); | |
16613 | ++ix) | |
16614 | munmap_section_buffer (section); | |
16615 | ||
16616 | VEC_free (dwarf2_section_info_def, data->types); | |
9291a0cd TT |
16617 | } |
16618 | ||
16619 | \f | |
ae2de4f8 | 16620 | /* The "save gdb-index" command. */ |
9291a0cd TT |
16621 | |
16622 | /* The contents of the hash table we create when building the string | |
16623 | table. */ | |
16624 | struct strtab_entry | |
16625 | { | |
16626 | offset_type offset; | |
16627 | const char *str; | |
16628 | }; | |
16629 | ||
559a7a62 JK |
16630 | /* Hash function for a strtab_entry. |
16631 | ||
16632 | Function is used only during write_hash_table so no index format backward | |
16633 | compatibility is needed. */ | |
b89be57b | 16634 | |
9291a0cd TT |
16635 | static hashval_t |
16636 | hash_strtab_entry (const void *e) | |
16637 | { | |
16638 | const struct strtab_entry *entry = e; | |
559a7a62 | 16639 | return mapped_index_string_hash (INT_MAX, entry->str); |
9291a0cd TT |
16640 | } |
16641 | ||
16642 | /* Equality function for a strtab_entry. */ | |
b89be57b | 16643 | |
9291a0cd TT |
16644 | static int |
16645 | eq_strtab_entry (const void *a, const void *b) | |
16646 | { | |
16647 | const struct strtab_entry *ea = a; | |
16648 | const struct strtab_entry *eb = b; | |
16649 | return !strcmp (ea->str, eb->str); | |
16650 | } | |
16651 | ||
16652 | /* Create a strtab_entry hash table. */ | |
b89be57b | 16653 | |
9291a0cd TT |
16654 | static htab_t |
16655 | create_strtab (void) | |
16656 | { | |
16657 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
16658 | xfree, xcalloc, xfree); | |
16659 | } | |
16660 | ||
16661 | /* Add a string to the constant pool. Return the string's offset in | |
16662 | host order. */ | |
b89be57b | 16663 | |
9291a0cd TT |
16664 | static offset_type |
16665 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
16666 | { | |
16667 | void **slot; | |
16668 | struct strtab_entry entry; | |
16669 | struct strtab_entry *result; | |
16670 | ||
16671 | entry.str = str; | |
16672 | slot = htab_find_slot (table, &entry, INSERT); | |
16673 | if (*slot) | |
16674 | result = *slot; | |
16675 | else | |
16676 | { | |
16677 | result = XNEW (struct strtab_entry); | |
16678 | result->offset = obstack_object_size (cpool); | |
16679 | result->str = str; | |
16680 | obstack_grow_str0 (cpool, str); | |
16681 | *slot = result; | |
16682 | } | |
16683 | return result->offset; | |
16684 | } | |
16685 | ||
16686 | /* An entry in the symbol table. */ | |
16687 | struct symtab_index_entry | |
16688 | { | |
16689 | /* The name of the symbol. */ | |
16690 | const char *name; | |
16691 | /* The offset of the name in the constant pool. */ | |
16692 | offset_type index_offset; | |
16693 | /* A sorted vector of the indices of all the CUs that hold an object | |
16694 | of this name. */ | |
16695 | VEC (offset_type) *cu_indices; | |
16696 | }; | |
16697 | ||
16698 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
16699 | struct mapped_symtab | |
16700 | { | |
16701 | offset_type n_elements; | |
16702 | offset_type size; | |
16703 | struct symtab_index_entry **data; | |
16704 | }; | |
16705 | ||
16706 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 16707 | |
9291a0cd TT |
16708 | static hashval_t |
16709 | hash_symtab_entry (const void *e) | |
16710 | { | |
16711 | const struct symtab_index_entry *entry = e; | |
16712 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
16713 | sizeof (offset_type) * VEC_length (offset_type, | |
16714 | entry->cu_indices), | |
16715 | 0); | |
16716 | } | |
16717 | ||
16718 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 16719 | |
9291a0cd TT |
16720 | static int |
16721 | eq_symtab_entry (const void *a, const void *b) | |
16722 | { | |
16723 | const struct symtab_index_entry *ea = a; | |
16724 | const struct symtab_index_entry *eb = b; | |
16725 | int len = VEC_length (offset_type, ea->cu_indices); | |
16726 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
16727 | return 0; | |
16728 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
16729 | VEC_address (offset_type, eb->cu_indices), | |
16730 | sizeof (offset_type) * len); | |
16731 | } | |
16732 | ||
16733 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 16734 | |
9291a0cd TT |
16735 | static void |
16736 | delete_symtab_entry (void *p) | |
16737 | { | |
16738 | struct symtab_index_entry *entry = p; | |
16739 | VEC_free (offset_type, entry->cu_indices); | |
16740 | xfree (entry); | |
16741 | } | |
16742 | ||
16743 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 16744 | |
9291a0cd | 16745 | static htab_t |
3876f04e | 16746 | create_symbol_hash_table (void) |
9291a0cd TT |
16747 | { |
16748 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
16749 | delete_symtab_entry, xcalloc, xfree); | |
16750 | } | |
16751 | ||
16752 | /* Create a new mapped symtab object. */ | |
b89be57b | 16753 | |
9291a0cd TT |
16754 | static struct mapped_symtab * |
16755 | create_mapped_symtab (void) | |
16756 | { | |
16757 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
16758 | symtab->n_elements = 0; | |
16759 | symtab->size = 1024; | |
16760 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16761 | return symtab; | |
16762 | } | |
16763 | ||
16764 | /* Destroy a mapped_symtab. */ | |
b89be57b | 16765 | |
9291a0cd TT |
16766 | static void |
16767 | cleanup_mapped_symtab (void *p) | |
16768 | { | |
16769 | struct mapped_symtab *symtab = p; | |
16770 | /* The contents of the array are freed when the other hash table is | |
16771 | destroyed. */ | |
16772 | xfree (symtab->data); | |
16773 | xfree (symtab); | |
16774 | } | |
16775 | ||
16776 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
559a7a62 JK |
16777 | the slot. |
16778 | ||
16779 | Function is used only during write_hash_table so no index format backward | |
16780 | compatibility is needed. */ | |
b89be57b | 16781 | |
9291a0cd TT |
16782 | static struct symtab_index_entry ** |
16783 | find_slot (struct mapped_symtab *symtab, const char *name) | |
16784 | { | |
559a7a62 | 16785 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
9291a0cd TT |
16786 | |
16787 | index = hash & (symtab->size - 1); | |
16788 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
16789 | ||
16790 | for (;;) | |
16791 | { | |
16792 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
16793 | return &symtab->data[index]; | |
16794 | index = (index + step) & (symtab->size - 1); | |
16795 | } | |
16796 | } | |
16797 | ||
16798 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 16799 | |
9291a0cd TT |
16800 | static void |
16801 | hash_expand (struct mapped_symtab *symtab) | |
16802 | { | |
16803 | offset_type old_size = symtab->size; | |
16804 | offset_type i; | |
16805 | struct symtab_index_entry **old_entries = symtab->data; | |
16806 | ||
16807 | symtab->size *= 2; | |
16808 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
16809 | ||
16810 | for (i = 0; i < old_size; ++i) | |
16811 | { | |
16812 | if (old_entries[i]) | |
16813 | { | |
16814 | struct symtab_index_entry **slot = find_slot (symtab, | |
16815 | old_entries[i]->name); | |
16816 | *slot = old_entries[i]; | |
16817 | } | |
16818 | } | |
16819 | ||
16820 | xfree (old_entries); | |
16821 | } | |
16822 | ||
16823 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
16824 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 16825 | |
9291a0cd TT |
16826 | static void |
16827 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
16828 | offset_type cu_index) | |
16829 | { | |
16830 | struct symtab_index_entry **slot; | |
16831 | ||
16832 | ++symtab->n_elements; | |
16833 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
16834 | hash_expand (symtab); | |
16835 | ||
16836 | slot = find_slot (symtab, name); | |
16837 | if (!*slot) | |
16838 | { | |
16839 | *slot = XNEW (struct symtab_index_entry); | |
16840 | (*slot)->name = name; | |
16841 | (*slot)->cu_indices = NULL; | |
16842 | } | |
16843 | /* Don't push an index twice. Due to how we add entries we only | |
16844 | have to check the last one. */ | |
16845 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
cf31e6f9 | 16846 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
9291a0cd TT |
16847 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
16848 | } | |
16849 | ||
16850 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 16851 | |
9291a0cd | 16852 | static offset_type |
3876f04e | 16853 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
16854 | struct symtab_index_entry *entry) |
16855 | { | |
16856 | void **slot; | |
16857 | ||
3876f04e | 16858 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
16859 | if (!*slot) |
16860 | { | |
16861 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
16862 | offset_type val = MAYBE_SWAP (len); | |
16863 | offset_type iter; | |
16864 | int i; | |
16865 | ||
16866 | *slot = entry; | |
16867 | entry->index_offset = obstack_object_size (cpool); | |
16868 | ||
16869 | obstack_grow (cpool, &val, sizeof (val)); | |
16870 | for (i = 0; | |
16871 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
16872 | ++i) | |
16873 | { | |
16874 | val = MAYBE_SWAP (iter); | |
16875 | obstack_grow (cpool, &val, sizeof (val)); | |
16876 | } | |
16877 | } | |
16878 | else | |
16879 | { | |
16880 | struct symtab_index_entry *old_entry = *slot; | |
16881 | entry->index_offset = old_entry->index_offset; | |
16882 | entry = old_entry; | |
16883 | } | |
16884 | return entry->index_offset; | |
16885 | } | |
16886 | ||
16887 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
16888 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 16889 | |
9291a0cd TT |
16890 | static void |
16891 | write_hash_table (struct mapped_symtab *symtab, | |
16892 | struct obstack *output, struct obstack *cpool) | |
16893 | { | |
16894 | offset_type i; | |
3876f04e | 16895 | htab_t symbol_hash_table; |
9291a0cd TT |
16896 | htab_t str_table; |
16897 | ||
3876f04e | 16898 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 16899 | str_table = create_strtab (); |
3876f04e | 16900 | |
9291a0cd TT |
16901 | /* We add all the index vectors to the constant pool first, to |
16902 | ensure alignment is ok. */ | |
16903 | for (i = 0; i < symtab->size; ++i) | |
16904 | { | |
16905 | if (symtab->data[i]) | |
3876f04e | 16906 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
16907 | } |
16908 | ||
16909 | /* Now write out the hash table. */ | |
16910 | for (i = 0; i < symtab->size; ++i) | |
16911 | { | |
16912 | offset_type str_off, vec_off; | |
16913 | ||
16914 | if (symtab->data[i]) | |
16915 | { | |
16916 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
16917 | vec_off = symtab->data[i]->index_offset; | |
16918 | } | |
16919 | else | |
16920 | { | |
16921 | /* While 0 is a valid constant pool index, it is not valid | |
16922 | to have 0 for both offsets. */ | |
16923 | str_off = 0; | |
16924 | vec_off = 0; | |
16925 | } | |
16926 | ||
16927 | str_off = MAYBE_SWAP (str_off); | |
16928 | vec_off = MAYBE_SWAP (vec_off); | |
16929 | ||
16930 | obstack_grow (output, &str_off, sizeof (str_off)); | |
16931 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
16932 | } | |
16933 | ||
16934 | htab_delete (str_table); | |
3876f04e | 16935 | htab_delete (symbol_hash_table); |
9291a0cd TT |
16936 | } |
16937 | ||
0a5429f6 DE |
16938 | /* Struct to map psymtab to CU index in the index file. */ |
16939 | struct psymtab_cu_index_map | |
16940 | { | |
16941 | struct partial_symtab *psymtab; | |
16942 | unsigned int cu_index; | |
16943 | }; | |
16944 | ||
16945 | static hashval_t | |
16946 | hash_psymtab_cu_index (const void *item) | |
16947 | { | |
16948 | const struct psymtab_cu_index_map *map = item; | |
16949 | ||
16950 | return htab_hash_pointer (map->psymtab); | |
16951 | } | |
16952 | ||
16953 | static int | |
16954 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
16955 | { | |
16956 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
16957 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
16958 | ||
16959 | return lhs->psymtab == rhs->psymtab; | |
16960 | } | |
16961 | ||
16962 | /* Helper struct for building the address table. */ | |
16963 | struct addrmap_index_data | |
16964 | { | |
16965 | struct objfile *objfile; | |
16966 | struct obstack *addr_obstack; | |
16967 | htab_t cu_index_htab; | |
16968 | ||
16969 | /* Non-zero if the previous_* fields are valid. | |
16970 | We can't write an entry until we see the next entry (since it is only then | |
16971 | that we know the end of the entry). */ | |
16972 | int previous_valid; | |
16973 | /* Index of the CU in the table of all CUs in the index file. */ | |
16974 | unsigned int previous_cu_index; | |
0963b4bd | 16975 | /* Start address of the CU. */ |
0a5429f6 DE |
16976 | CORE_ADDR previous_cu_start; |
16977 | }; | |
16978 | ||
16979 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 16980 | |
9291a0cd | 16981 | static void |
0a5429f6 DE |
16982 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
16983 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 16984 | { |
0a5429f6 | 16985 | offset_type cu_index_to_write; |
9291a0cd TT |
16986 | char addr[8]; |
16987 | CORE_ADDR baseaddr; | |
16988 | ||
16989 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
16990 | ||
0a5429f6 DE |
16991 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
16992 | obstack_grow (obstack, addr, 8); | |
16993 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
16994 | obstack_grow (obstack, addr, 8); | |
16995 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
16996 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
16997 | } | |
16998 | ||
16999 | /* Worker function for traversing an addrmap to build the address table. */ | |
17000 | ||
17001 | static int | |
17002 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
17003 | { | |
17004 | struct addrmap_index_data *data = datap; | |
17005 | struct partial_symtab *pst = obj; | |
17006 | offset_type cu_index; | |
17007 | void **slot; | |
17008 | ||
17009 | if (data->previous_valid) | |
17010 | add_address_entry (data->objfile, data->addr_obstack, | |
17011 | data->previous_cu_start, start_addr, | |
17012 | data->previous_cu_index); | |
17013 | ||
17014 | data->previous_cu_start = start_addr; | |
17015 | if (pst != NULL) | |
17016 | { | |
17017 | struct psymtab_cu_index_map find_map, *map; | |
17018 | find_map.psymtab = pst; | |
17019 | map = htab_find (data->cu_index_htab, &find_map); | |
17020 | gdb_assert (map != NULL); | |
17021 | data->previous_cu_index = map->cu_index; | |
17022 | data->previous_valid = 1; | |
17023 | } | |
17024 | else | |
17025 | data->previous_valid = 0; | |
17026 | ||
17027 | return 0; | |
17028 | } | |
17029 | ||
17030 | /* Write OBJFILE's address map to OBSTACK. | |
17031 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
17032 | in the index file. */ | |
17033 | ||
17034 | static void | |
17035 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
17036 | htab_t cu_index_htab) | |
17037 | { | |
17038 | struct addrmap_index_data addrmap_index_data; | |
17039 | ||
17040 | /* When writing the address table, we have to cope with the fact that | |
17041 | the addrmap iterator only provides the start of a region; we have to | |
17042 | wait until the next invocation to get the start of the next region. */ | |
17043 | ||
17044 | addrmap_index_data.objfile = objfile; | |
17045 | addrmap_index_data.addr_obstack = obstack; | |
17046 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
17047 | addrmap_index_data.previous_valid = 0; | |
17048 | ||
17049 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
17050 | &addrmap_index_data); | |
17051 | ||
17052 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
17053 | is valid, but we should still handle it. | |
17054 | The end address is recorded as the start of the next region, but that | |
17055 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
17056 | anyway. */ | |
17057 | if (addrmap_index_data.previous_valid) | |
17058 | add_address_entry (objfile, obstack, | |
17059 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
17060 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
17061 | } |
17062 | ||
17063 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 17064 | |
9291a0cd TT |
17065 | static void |
17066 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 17067 | htab_t psyms_seen, |
9291a0cd TT |
17068 | struct partial_symbol **psymp, |
17069 | int count, | |
987d643c TT |
17070 | offset_type cu_index, |
17071 | int is_static) | |
9291a0cd TT |
17072 | { |
17073 | for (; count-- > 0; ++psymp) | |
17074 | { | |
987d643c TT |
17075 | void **slot, *lookup; |
17076 | ||
9291a0cd TT |
17077 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
17078 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
17079 | |
17080 | /* We only want to add a given psymbol once. However, we also | |
17081 | want to account for whether it is global or static. So, we | |
17082 | may add it twice, using slightly different values. */ | |
17083 | if (is_static) | |
17084 | { | |
17085 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
17086 | ||
17087 | lookup = (void *) val; | |
17088 | } | |
17089 | else | |
17090 | lookup = *psymp; | |
17091 | ||
17092 | /* Only add a given psymbol once. */ | |
17093 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
17094 | if (!*slot) | |
17095 | { | |
17096 | *slot = lookup; | |
bb2f58dc | 17097 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
987d643c | 17098 | } |
9291a0cd TT |
17099 | } |
17100 | } | |
17101 | ||
17102 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
17103 | exception if there is an error. */ | |
b89be57b | 17104 | |
9291a0cd TT |
17105 | static void |
17106 | write_obstack (FILE *file, struct obstack *obstack) | |
17107 | { | |
17108 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
17109 | file) | |
17110 | != obstack_object_size (obstack)) | |
17111 | error (_("couldn't data write to file")); | |
17112 | } | |
17113 | ||
17114 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 17115 | |
9291a0cd TT |
17116 | static void |
17117 | unlink_if_set (void *p) | |
17118 | { | |
17119 | char **filename = p; | |
17120 | if (*filename) | |
17121 | unlink (*filename); | |
17122 | } | |
17123 | ||
1fd400ff TT |
17124 | /* A helper struct used when iterating over debug_types. */ |
17125 | struct signatured_type_index_data | |
17126 | { | |
17127 | struct objfile *objfile; | |
17128 | struct mapped_symtab *symtab; | |
17129 | struct obstack *types_list; | |
987d643c | 17130 | htab_t psyms_seen; |
1fd400ff TT |
17131 | int cu_index; |
17132 | }; | |
17133 | ||
17134 | /* A helper function that writes a single signatured_type to an | |
17135 | obstack. */ | |
b89be57b | 17136 | |
1fd400ff TT |
17137 | static int |
17138 | write_one_signatured_type (void **slot, void *d) | |
17139 | { | |
17140 | struct signatured_type_index_data *info = d; | |
17141 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
17142 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
17143 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
17144 | gdb_byte val[8]; |
17145 | ||
17146 | write_psymbols (info->symtab, | |
987d643c | 17147 | info->psyms_seen, |
3e43a32a MS |
17148 | info->objfile->global_psymbols.list |
17149 | + psymtab->globals_offset, | |
987d643c TT |
17150 | psymtab->n_global_syms, info->cu_index, |
17151 | 0); | |
1fd400ff | 17152 | write_psymbols (info->symtab, |
987d643c | 17153 | info->psyms_seen, |
3e43a32a MS |
17154 | info->objfile->static_psymbols.list |
17155 | + psymtab->statics_offset, | |
987d643c TT |
17156 | psymtab->n_static_syms, info->cu_index, |
17157 | 1); | |
1fd400ff | 17158 | |
b64f50a1 JK |
17159 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
17160 | entry->per_cu.offset.sect_off); | |
1fd400ff | 17161 | obstack_grow (info->types_list, val, 8); |
b64f50a1 | 17162 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset.cu_off); |
1fd400ff TT |
17163 | obstack_grow (info->types_list, val, 8); |
17164 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
17165 | obstack_grow (info->types_list, val, 8); | |
17166 | ||
17167 | ++info->cu_index; | |
17168 | ||
17169 | return 1; | |
17170 | } | |
17171 | ||
9291a0cd | 17172 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 17173 | |
9291a0cd TT |
17174 | static void |
17175 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
17176 | { | |
17177 | struct cleanup *cleanup; | |
17178 | char *filename, *cleanup_filename; | |
1fd400ff TT |
17179 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
17180 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
17181 | int i; |
17182 | FILE *out_file; | |
17183 | struct mapped_symtab *symtab; | |
17184 | offset_type val, size_of_contents, total_len; | |
17185 | struct stat st; | |
17186 | char buf[8]; | |
987d643c | 17187 | htab_t psyms_seen; |
0a5429f6 DE |
17188 | htab_t cu_index_htab; |
17189 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd | 17190 | |
b4f2f049 | 17191 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
9291a0cd | 17192 | return; |
b4f2f049 | 17193 | |
9291a0cd TT |
17194 | if (dwarf2_per_objfile->using_index) |
17195 | error (_("Cannot use an index to create the index")); | |
17196 | ||
8b70b953 TT |
17197 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
17198 | error (_("Cannot make an index when the file has multiple .debug_types sections")); | |
17199 | ||
9291a0cd | 17200 | if (stat (objfile->name, &st) < 0) |
7e17e088 | 17201 | perror_with_name (objfile->name); |
9291a0cd TT |
17202 | |
17203 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
17204 | INDEX_SUFFIX, (char *) NULL); | |
17205 | cleanup = make_cleanup (xfree, filename); | |
17206 | ||
17207 | out_file = fopen (filename, "wb"); | |
17208 | if (!out_file) | |
17209 | error (_("Can't open `%s' for writing"), filename); | |
17210 | ||
17211 | cleanup_filename = filename; | |
17212 | make_cleanup (unlink_if_set, &cleanup_filename); | |
17213 | ||
17214 | symtab = create_mapped_symtab (); | |
17215 | make_cleanup (cleanup_mapped_symtab, symtab); | |
17216 | ||
17217 | obstack_init (&addr_obstack); | |
17218 | make_cleanup_obstack_free (&addr_obstack); | |
17219 | ||
17220 | obstack_init (&cu_list); | |
17221 | make_cleanup_obstack_free (&cu_list); | |
17222 | ||
1fd400ff TT |
17223 | obstack_init (&types_cu_list); |
17224 | make_cleanup_obstack_free (&types_cu_list); | |
17225 | ||
987d643c TT |
17226 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
17227 | NULL, xcalloc, xfree); | |
96408a79 | 17228 | make_cleanup_htab_delete (psyms_seen); |
987d643c | 17229 | |
0a5429f6 DE |
17230 | /* While we're scanning CU's create a table that maps a psymtab pointer |
17231 | (which is what addrmap records) to its index (which is what is recorded | |
17232 | in the index file). This will later be needed to write the address | |
17233 | table. */ | |
17234 | cu_index_htab = htab_create_alloc (100, | |
17235 | hash_psymtab_cu_index, | |
17236 | eq_psymtab_cu_index, | |
17237 | NULL, xcalloc, xfree); | |
96408a79 | 17238 | make_cleanup_htab_delete (cu_index_htab); |
0a5429f6 DE |
17239 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
17240 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
17241 | * dwarf2_per_objfile->n_comp_units); | |
17242 | make_cleanup (xfree, psymtab_cu_index_map); | |
17243 | ||
17244 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
17245 | work here. Also, the debug_types entries do not appear in |
17246 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
17247 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
17248 | { | |
3e43a32a MS |
17249 | struct dwarf2_per_cu_data *per_cu |
17250 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 17251 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 17252 | gdb_byte val[8]; |
0a5429f6 DE |
17253 | struct psymtab_cu_index_map *map; |
17254 | void **slot; | |
9291a0cd TT |
17255 | |
17256 | write_psymbols (symtab, | |
987d643c | 17257 | psyms_seen, |
9291a0cd | 17258 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
17259 | psymtab->n_global_syms, i, |
17260 | 0); | |
9291a0cd | 17261 | write_psymbols (symtab, |
987d643c | 17262 | psyms_seen, |
9291a0cd | 17263 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
17264 | psymtab->n_static_syms, i, |
17265 | 1); | |
9291a0cd | 17266 | |
0a5429f6 DE |
17267 | map = &psymtab_cu_index_map[i]; |
17268 | map->psymtab = psymtab; | |
17269 | map->cu_index = i; | |
17270 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
17271 | gdb_assert (slot != NULL); | |
17272 | gdb_assert (*slot == NULL); | |
17273 | *slot = map; | |
9291a0cd | 17274 | |
b64f50a1 JK |
17275 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
17276 | per_cu->offset.sect_off); | |
9291a0cd | 17277 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 17278 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
17279 | obstack_grow (&cu_list, val, 8); |
17280 | } | |
17281 | ||
0a5429f6 DE |
17282 | /* Dump the address map. */ |
17283 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
17284 | ||
1fd400ff TT |
17285 | /* Write out the .debug_type entries, if any. */ |
17286 | if (dwarf2_per_objfile->signatured_types) | |
17287 | { | |
17288 | struct signatured_type_index_data sig_data; | |
17289 | ||
17290 | sig_data.objfile = objfile; | |
17291 | sig_data.symtab = symtab; | |
17292 | sig_data.types_list = &types_cu_list; | |
987d643c | 17293 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
17294 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
17295 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
17296 | write_one_signatured_type, &sig_data); | |
17297 | } | |
17298 | ||
9291a0cd TT |
17299 | obstack_init (&constant_pool); |
17300 | make_cleanup_obstack_free (&constant_pool); | |
17301 | obstack_init (&symtab_obstack); | |
17302 | make_cleanup_obstack_free (&symtab_obstack); | |
17303 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
17304 | ||
17305 | obstack_init (&contents); | |
17306 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 17307 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
17308 | total_len = size_of_contents; |
17309 | ||
17310 | /* The version number. */ | |
481860b3 | 17311 | val = MAYBE_SWAP (6); |
9291a0cd TT |
17312 | obstack_grow (&contents, &val, sizeof (val)); |
17313 | ||
17314 | /* The offset of the CU list from the start of the file. */ | |
17315 | val = MAYBE_SWAP (total_len); | |
17316 | obstack_grow (&contents, &val, sizeof (val)); | |
17317 | total_len += obstack_object_size (&cu_list); | |
17318 | ||
1fd400ff TT |
17319 | /* The offset of the types CU list from the start of the file. */ |
17320 | val = MAYBE_SWAP (total_len); | |
17321 | obstack_grow (&contents, &val, sizeof (val)); | |
17322 | total_len += obstack_object_size (&types_cu_list); | |
17323 | ||
9291a0cd TT |
17324 | /* The offset of the address table from the start of the file. */ |
17325 | val = MAYBE_SWAP (total_len); | |
17326 | obstack_grow (&contents, &val, sizeof (val)); | |
17327 | total_len += obstack_object_size (&addr_obstack); | |
17328 | ||
17329 | /* The offset of the symbol table from the start of the file. */ | |
17330 | val = MAYBE_SWAP (total_len); | |
17331 | obstack_grow (&contents, &val, sizeof (val)); | |
17332 | total_len += obstack_object_size (&symtab_obstack); | |
17333 | ||
17334 | /* The offset of the constant pool from the start of the file. */ | |
17335 | val = MAYBE_SWAP (total_len); | |
17336 | obstack_grow (&contents, &val, sizeof (val)); | |
17337 | total_len += obstack_object_size (&constant_pool); | |
17338 | ||
17339 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
17340 | ||
17341 | write_obstack (out_file, &contents); | |
17342 | write_obstack (out_file, &cu_list); | |
1fd400ff | 17343 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
17344 | write_obstack (out_file, &addr_obstack); |
17345 | write_obstack (out_file, &symtab_obstack); | |
17346 | write_obstack (out_file, &constant_pool); | |
17347 | ||
17348 | fclose (out_file); | |
17349 | ||
17350 | /* We want to keep the file, so we set cleanup_filename to NULL | |
17351 | here. See unlink_if_set. */ | |
17352 | cleanup_filename = NULL; | |
17353 | ||
17354 | do_cleanups (cleanup); | |
17355 | } | |
17356 | ||
90476074 TT |
17357 | /* Implementation of the `save gdb-index' command. |
17358 | ||
17359 | Note that the file format used by this command is documented in the | |
17360 | GDB manual. Any changes here must be documented there. */ | |
11570e71 | 17361 | |
9291a0cd TT |
17362 | static void |
17363 | save_gdb_index_command (char *arg, int from_tty) | |
17364 | { | |
17365 | struct objfile *objfile; | |
17366 | ||
17367 | if (!arg || !*arg) | |
96d19272 | 17368 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
17369 | |
17370 | ALL_OBJFILES (objfile) | |
17371 | { | |
17372 | struct stat st; | |
17373 | ||
17374 | /* If the objfile does not correspond to an actual file, skip it. */ | |
17375 | if (stat (objfile->name, &st) < 0) | |
17376 | continue; | |
17377 | ||
17378 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
17379 | if (dwarf2_per_objfile) | |
17380 | { | |
17381 | volatile struct gdb_exception except; | |
17382 | ||
17383 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
17384 | { | |
17385 | write_psymtabs_to_index (objfile, arg); | |
17386 | } | |
17387 | if (except.reason < 0) | |
17388 | exception_fprintf (gdb_stderr, except, | |
17389 | _("Error while writing index for `%s': "), | |
17390 | objfile->name); | |
17391 | } | |
17392 | } | |
dce234bc PP |
17393 | } |
17394 | ||
9291a0cd TT |
17395 | \f |
17396 | ||
9eae7c52 TT |
17397 | int dwarf2_always_disassemble; |
17398 | ||
17399 | static void | |
17400 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
17401 | struct cmd_list_element *c, const char *value) | |
17402 | { | |
3e43a32a MS |
17403 | fprintf_filtered (file, |
17404 | _("Whether to always disassemble " | |
17405 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
17406 | value); |
17407 | } | |
17408 | ||
900e11f9 JK |
17409 | static void |
17410 | show_check_physname (struct ui_file *file, int from_tty, | |
17411 | struct cmd_list_element *c, const char *value) | |
17412 | { | |
17413 | fprintf_filtered (file, | |
17414 | _("Whether to check \"physname\" is %s.\n"), | |
17415 | value); | |
17416 | } | |
17417 | ||
6502dd73 DJ |
17418 | void _initialize_dwarf2_read (void); |
17419 | ||
17420 | void | |
17421 | _initialize_dwarf2_read (void) | |
17422 | { | |
96d19272 JK |
17423 | struct cmd_list_element *c; |
17424 | ||
dce234bc | 17425 | dwarf2_objfile_data_key |
c1bd65d0 | 17426 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 17427 | |
1bedd215 AC |
17428 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
17429 | Set DWARF 2 specific variables.\n\ | |
17430 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17431 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
17432 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
17433 | ||
1bedd215 AC |
17434 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
17435 | Show DWARF 2 specific variables\n\ | |
17436 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
17437 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
17438 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
17439 | ||
17440 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
17441 | &dwarf2_max_cache_age, _("\ |
17442 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17443 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
17444 | A higher limit means that cached compilation units will be stored\n\ | |
17445 | in memory longer, and more total memory will be used. Zero disables\n\ | |
17446 | caching, which can slow down startup."), | |
2c5b56ce | 17447 | NULL, |
920d2a44 | 17448 | show_dwarf2_max_cache_age, |
2c5b56ce | 17449 | &set_dwarf2_cmdlist, |
ae038cb0 | 17450 | &show_dwarf2_cmdlist); |
d97bc12b | 17451 | |
9eae7c52 TT |
17452 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
17453 | &dwarf2_always_disassemble, _("\ | |
17454 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
17455 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
17456 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
17457 | syntax. When disabled, expressions will be printed in a more\n\ | |
17458 | conversational style, when possible."), | |
17459 | NULL, | |
17460 | show_dwarf2_always_disassemble, | |
17461 | &set_dwarf2_cmdlist, | |
17462 | &show_dwarf2_cmdlist); | |
17463 | ||
d97bc12b DE |
17464 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
17465 | Set debugging of the dwarf2 DIE reader."), _("\ | |
17466 | Show debugging of the dwarf2 DIE reader."), _("\ | |
17467 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
17468 | The value is the maximum depth to print."), | |
17469 | NULL, | |
17470 | NULL, | |
17471 | &setdebuglist, &showdebuglist); | |
9291a0cd | 17472 | |
900e11f9 JK |
17473 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
17474 | Set cross-checking of \"physname\" code against demangler."), _("\ | |
17475 | Show cross-checking of \"physname\" code against demangler."), _("\ | |
17476 | When enabled, GDB's internal \"physname\" code is checked against\n\ | |
17477 | the demangler."), | |
17478 | NULL, show_check_physname, | |
17479 | &setdebuglist, &showdebuglist); | |
17480 | ||
96d19272 | 17481 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 17482 | _("\ |
fc1a9d6e | 17483 | Save a gdb-index file.\n\ |
11570e71 | 17484 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
17485 | &save_cmdlist); |
17486 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 17487 | } |