Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
6aba47ca | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
7b6bb8da | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
0fb0cc75 | 5 | Free Software Foundation, Inc. |
c906108c SS |
6 | |
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 12 | support. |
c906108c | 13 | |
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
18 | the Free Software Foundation; either version 3 of the License, or |
19 | (at your option) any later version. | |
c906108c | 20 | |
a9762ec7 JB |
21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
c906108c | 25 | |
c5aa993b | 26 | You should have received a copy of the GNU General Public License |
a9762ec7 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
28 | |
29 | #include "defs.h" | |
30 | #include "bfd.h" | |
c906108c SS |
31 | #include "symtab.h" |
32 | #include "gdbtypes.h" | |
c906108c | 33 | #include "objfiles.h" |
fa8f86ff | 34 | #include "dwarf2.h" |
c906108c SS |
35 | #include "buildsym.h" |
36 | #include "demangle.h" | |
37 | #include "expression.h" | |
d5166ae1 | 38 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 39 | #include "macrotab.h" |
c906108c SS |
40 | #include "language.h" |
41 | #include "complaints.h" | |
357e46e7 | 42 | #include "bcache.h" |
4c2df51b DJ |
43 | #include "dwarf2expr.h" |
44 | #include "dwarf2loc.h" | |
9219021c | 45 | #include "cp-support.h" |
72bf9492 | 46 | #include "hashtab.h" |
ae038cb0 DJ |
47 | #include "command.h" |
48 | #include "gdbcmd.h" | |
edb3359d | 49 | #include "block.h" |
ff013f42 | 50 | #include "addrmap.h" |
94af9270 KS |
51 | #include "typeprint.h" |
52 | #include "jv-lang.h" | |
ccefe4c4 | 53 | #include "psympriv.h" |
9291a0cd TT |
54 | #include "exceptions.h" |
55 | #include "gdb_stat.h" | |
96d19272 | 56 | #include "completer.h" |
34eaf542 | 57 | #include "vec.h" |
98bfdba5 PA |
58 | #include "c-lang.h" |
59 | #include "valprint.h" | |
4c2df51b | 60 | |
c906108c SS |
61 | #include <fcntl.h> |
62 | #include "gdb_string.h" | |
4bdf3d34 | 63 | #include "gdb_assert.h" |
c906108c | 64 | #include <sys/types.h> |
233a11ab CS |
65 | #ifdef HAVE_ZLIB_H |
66 | #include <zlib.h> | |
67 | #endif | |
dce234bc PP |
68 | #ifdef HAVE_MMAP |
69 | #include <sys/mman.h> | |
85d9bd0e TT |
70 | #ifndef MAP_FAILED |
71 | #define MAP_FAILED ((void *) -1) | |
72 | #endif | |
dce234bc | 73 | #endif |
d8151005 | 74 | |
34eaf542 TT |
75 | typedef struct symbol *symbolp; |
76 | DEF_VEC_P (symbolp); | |
77 | ||
107d2387 | 78 | #if 0 |
357e46e7 | 79 | /* .debug_info header for a compilation unit |
c906108c SS |
80 | Because of alignment constraints, this structure has padding and cannot |
81 | be mapped directly onto the beginning of the .debug_info section. */ | |
82 | typedef struct comp_unit_header | |
83 | { | |
84 | unsigned int length; /* length of the .debug_info | |
85 | contribution */ | |
86 | unsigned short version; /* version number -- 2 for DWARF | |
87 | version 2 */ | |
88 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
89 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
90 | } | |
91 | _COMP_UNIT_HEADER; | |
92 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 93 | #endif |
c906108c | 94 | |
c906108c SS |
95 | /* .debug_line statement program prologue |
96 | Because of alignment constraints, this structure has padding and cannot | |
97 | be mapped directly onto the beginning of the .debug_info section. */ | |
98 | typedef struct statement_prologue | |
99 | { | |
100 | unsigned int total_length; /* byte length of the statement | |
101 | information */ | |
102 | unsigned short version; /* version number -- 2 for DWARF | |
103 | version 2 */ | |
104 | unsigned int prologue_length; /* # bytes between prologue & | |
105 | stmt program */ | |
106 | unsigned char minimum_instruction_length; /* byte size of | |
107 | smallest instr */ | |
108 | unsigned char default_is_stmt; /* initial value of is_stmt | |
109 | register */ | |
110 | char line_base; | |
111 | unsigned char line_range; | |
112 | unsigned char opcode_base; /* number assigned to first special | |
113 | opcode */ | |
114 | unsigned char *standard_opcode_lengths; | |
115 | } | |
116 | _STATEMENT_PROLOGUE; | |
117 | ||
d97bc12b DE |
118 | /* When non-zero, dump DIEs after they are read in. */ |
119 | static int dwarf2_die_debug = 0; | |
120 | ||
dce234bc PP |
121 | static int pagesize; |
122 | ||
df8a16a1 DJ |
123 | /* When set, the file that we're processing is known to have debugging |
124 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
125 | but later versions do. */ | |
126 | ||
127 | static int processing_has_namespace_info; | |
128 | ||
6502dd73 DJ |
129 | static const struct objfile_data *dwarf2_objfile_data_key; |
130 | ||
dce234bc PP |
131 | struct dwarf2_section_info |
132 | { | |
133 | asection *asection; | |
134 | gdb_byte *buffer; | |
135 | bfd_size_type size; | |
136 | int was_mmapped; | |
be391dca TT |
137 | /* True if we have tried to read this section. */ |
138 | int readin; | |
dce234bc PP |
139 | }; |
140 | ||
9291a0cd TT |
141 | /* All offsets in the index are of this type. It must be |
142 | architecture-independent. */ | |
143 | typedef uint32_t offset_type; | |
144 | ||
145 | DEF_VEC_I (offset_type); | |
146 | ||
147 | /* A description of the mapped index. The file format is described in | |
148 | a comment by the code that writes the index. */ | |
149 | struct mapped_index | |
150 | { | |
151 | /* The total length of the buffer. */ | |
152 | off_t total_size; | |
153 | /* A pointer to the address table data. */ | |
154 | const gdb_byte *address_table; | |
155 | /* Size of the address table data in bytes. */ | |
156 | offset_type address_table_size; | |
3876f04e DE |
157 | /* The symbol table, implemented as a hash table. */ |
158 | const offset_type *symbol_table; | |
9291a0cd | 159 | /* Size in slots, each slot is 2 offset_types. */ |
3876f04e | 160 | offset_type symbol_table_slots; |
9291a0cd TT |
161 | /* A pointer to the constant pool. */ |
162 | const char *constant_pool; | |
163 | }; | |
164 | ||
6502dd73 DJ |
165 | struct dwarf2_per_objfile |
166 | { | |
dce234bc PP |
167 | struct dwarf2_section_info info; |
168 | struct dwarf2_section_info abbrev; | |
169 | struct dwarf2_section_info line; | |
dce234bc PP |
170 | struct dwarf2_section_info loc; |
171 | struct dwarf2_section_info macinfo; | |
172 | struct dwarf2_section_info str; | |
173 | struct dwarf2_section_info ranges; | |
348e048f | 174 | struct dwarf2_section_info types; |
dce234bc PP |
175 | struct dwarf2_section_info frame; |
176 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 177 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 178 | |
be391dca TT |
179 | /* Back link. */ |
180 | struct objfile *objfile; | |
181 | ||
10b3939b DJ |
182 | /* A list of all the compilation units. This is used to locate |
183 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
184 | struct dwarf2_per_cu_data **all_comp_units; |
185 | ||
186 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
187 | int n_comp_units; | |
188 | ||
1fd400ff TT |
189 | /* The number of .debug_types-related CUs. */ |
190 | int n_type_comp_units; | |
191 | ||
192 | /* The .debug_types-related CUs. */ | |
193 | struct dwarf2_per_cu_data **type_comp_units; | |
194 | ||
ae038cb0 DJ |
195 | /* A chain of compilation units that are currently read in, so that |
196 | they can be freed later. */ | |
197 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 198 | |
348e048f DE |
199 | /* A table mapping .debug_types signatures to its signatured_type entry. |
200 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
201 | htab_t signatured_types; | |
202 | ||
72dca2f5 FR |
203 | /* A flag indicating wether this objfile has a section loaded at a |
204 | VMA of 0. */ | |
205 | int has_section_at_zero; | |
9291a0cd | 206 | |
ae2de4f8 DE |
207 | /* True if we are using the mapped index, |
208 | or we are faking it for OBJF_READNOW's sake. */ | |
9291a0cd TT |
209 | unsigned char using_index; |
210 | ||
ae2de4f8 | 211 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
9291a0cd | 212 | struct mapped_index *index_table; |
98bfdba5 | 213 | |
7b9f3c50 DE |
214 | /* When using index_table, this keeps track of all quick_file_names entries. |
215 | TUs can share line table entries with CUs or other TUs, and there can be | |
216 | a lot more TUs than unique line tables, so we maintain a separate table | |
217 | of all line table entries to support the sharing. */ | |
218 | htab_t quick_file_names_table; | |
219 | ||
98bfdba5 PA |
220 | /* Set during partial symbol reading, to prevent queueing of full |
221 | symbols. */ | |
222 | int reading_partial_symbols; | |
673bfd45 DE |
223 | |
224 | /* Table mapping type .debug_info DIE offsets to types. | |
225 | This is NULL if not allocated yet. | |
226 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
227 | To keep things simple we allocate both lazily. */ | |
228 | htab_t debug_info_type_hash; | |
229 | ||
230 | /* Table mapping type .debug_types DIE offsets to types. | |
231 | This is NULL if not allocated yet. */ | |
232 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
233 | }; |
234 | ||
235 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
236 | |
237 | /* names of the debugging sections */ | |
238 | ||
233a11ab CS |
239 | /* Note that if the debugging section has been compressed, it might |
240 | have a name like .zdebug_info. */ | |
241 | ||
242 | #define INFO_SECTION "debug_info" | |
243 | #define ABBREV_SECTION "debug_abbrev" | |
244 | #define LINE_SECTION "debug_line" | |
233a11ab CS |
245 | #define LOC_SECTION "debug_loc" |
246 | #define MACINFO_SECTION "debug_macinfo" | |
247 | #define STR_SECTION "debug_str" | |
248 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 249 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
250 | #define FRAME_SECTION "debug_frame" |
251 | #define EH_FRAME_SECTION "eh_frame" | |
9291a0cd | 252 | #define GDB_INDEX_SECTION "gdb_index" |
c906108c SS |
253 | |
254 | /* local data types */ | |
255 | ||
0963b4bd | 256 | /* We hold several abbreviation tables in memory at the same time. */ |
57349743 JB |
257 | #ifndef ABBREV_HASH_SIZE |
258 | #define ABBREV_HASH_SIZE 121 | |
259 | #endif | |
260 | ||
107d2387 AC |
261 | /* The data in a compilation unit header, after target2host |
262 | translation, looks like this. */ | |
c906108c | 263 | struct comp_unit_head |
a738430d | 264 | { |
c764a876 | 265 | unsigned int length; |
a738430d | 266 | short version; |
a738430d MK |
267 | unsigned char addr_size; |
268 | unsigned char signed_addr_p; | |
9cbfa09e | 269 | unsigned int abbrev_offset; |
57349743 | 270 | |
a738430d MK |
271 | /* Size of file offsets; either 4 or 8. */ |
272 | unsigned int offset_size; | |
57349743 | 273 | |
a738430d MK |
274 | /* Size of the length field; either 4 or 12. */ |
275 | unsigned int initial_length_size; | |
57349743 | 276 | |
a738430d MK |
277 | /* Offset to the first byte of this compilation unit header in the |
278 | .debug_info section, for resolving relative reference dies. */ | |
279 | unsigned int offset; | |
57349743 | 280 | |
d00adf39 DE |
281 | /* Offset to first die in this cu from the start of the cu. |
282 | This will be the first byte following the compilation unit header. */ | |
283 | unsigned int first_die_offset; | |
a738430d | 284 | }; |
c906108c | 285 | |
3da10d80 KS |
286 | /* Type used for delaying computation of method physnames. |
287 | See comments for compute_delayed_physnames. */ | |
288 | struct delayed_method_info | |
289 | { | |
290 | /* The type to which the method is attached, i.e., its parent class. */ | |
291 | struct type *type; | |
292 | ||
293 | /* The index of the method in the type's function fieldlists. */ | |
294 | int fnfield_index; | |
295 | ||
296 | /* The index of the method in the fieldlist. */ | |
297 | int index; | |
298 | ||
299 | /* The name of the DIE. */ | |
300 | const char *name; | |
301 | ||
302 | /* The DIE associated with this method. */ | |
303 | struct die_info *die; | |
304 | }; | |
305 | ||
306 | typedef struct delayed_method_info delayed_method_info; | |
307 | DEF_VEC_O (delayed_method_info); | |
308 | ||
e7c27a73 DJ |
309 | /* Internal state when decoding a particular compilation unit. */ |
310 | struct dwarf2_cu | |
311 | { | |
312 | /* The objfile containing this compilation unit. */ | |
313 | struct objfile *objfile; | |
314 | ||
d00adf39 | 315 | /* The header of the compilation unit. */ |
e7c27a73 | 316 | struct comp_unit_head header; |
e142c38c | 317 | |
d00adf39 DE |
318 | /* Base address of this compilation unit. */ |
319 | CORE_ADDR base_address; | |
320 | ||
321 | /* Non-zero if base_address has been set. */ | |
322 | int base_known; | |
323 | ||
e142c38c DJ |
324 | struct function_range *first_fn, *last_fn, *cached_fn; |
325 | ||
326 | /* The language we are debugging. */ | |
327 | enum language language; | |
328 | const struct language_defn *language_defn; | |
329 | ||
b0f35d58 DL |
330 | const char *producer; |
331 | ||
e142c38c DJ |
332 | /* The generic symbol table building routines have separate lists for |
333 | file scope symbols and all all other scopes (local scopes). So | |
334 | we need to select the right one to pass to add_symbol_to_list(). | |
335 | We do it by keeping a pointer to the correct list in list_in_scope. | |
336 | ||
337 | FIXME: The original dwarf code just treated the file scope as the | |
338 | first local scope, and all other local scopes as nested local | |
339 | scopes, and worked fine. Check to see if we really need to | |
340 | distinguish these in buildsym.c. */ | |
341 | struct pending **list_in_scope; | |
342 | ||
f3dd6933 DJ |
343 | /* DWARF abbreviation table associated with this compilation unit. */ |
344 | struct abbrev_info **dwarf2_abbrevs; | |
345 | ||
346 | /* Storage for the abbrev table. */ | |
347 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
348 | |
349 | /* Hash table holding all the loaded partial DIEs. */ | |
350 | htab_t partial_dies; | |
351 | ||
352 | /* Storage for things with the same lifetime as this read-in compilation | |
353 | unit, including partial DIEs. */ | |
354 | struct obstack comp_unit_obstack; | |
355 | ||
ae038cb0 DJ |
356 | /* When multiple dwarf2_cu structures are living in memory, this field |
357 | chains them all together, so that they can be released efficiently. | |
358 | We will probably also want a generation counter so that most-recently-used | |
359 | compilation units are cached... */ | |
360 | struct dwarf2_per_cu_data *read_in_chain; | |
361 | ||
362 | /* Backchain to our per_cu entry if the tree has been built. */ | |
363 | struct dwarf2_per_cu_data *per_cu; | |
364 | ||
365 | /* How many compilation units ago was this CU last referenced? */ | |
366 | int last_used; | |
367 | ||
10b3939b | 368 | /* A hash table of die offsets for following references. */ |
51545339 | 369 | htab_t die_hash; |
10b3939b DJ |
370 | |
371 | /* Full DIEs if read in. */ | |
372 | struct die_info *dies; | |
373 | ||
374 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
375 | units referenced by this one. Only set during full symbol processing; | |
376 | partial symbol tables do not have dependencies. */ | |
377 | htab_t dependencies; | |
378 | ||
cb1df416 DJ |
379 | /* Header data from the line table, during full symbol processing. */ |
380 | struct line_header *line_header; | |
381 | ||
3da10d80 KS |
382 | /* A list of methods which need to have physnames computed |
383 | after all type information has been read. */ | |
384 | VEC (delayed_method_info) *method_list; | |
385 | ||
ae038cb0 DJ |
386 | /* Mark used when releasing cached dies. */ |
387 | unsigned int mark : 1; | |
388 | ||
389 | /* This flag will be set if this compilation unit might include | |
390 | inter-compilation-unit references. */ | |
391 | unsigned int has_form_ref_addr : 1; | |
392 | ||
72bf9492 DJ |
393 | /* This flag will be set if this compilation unit includes any |
394 | DW_TAG_namespace DIEs. If we know that there are explicit | |
395 | DIEs for namespaces, we don't need to try to infer them | |
396 | from mangled names. */ | |
397 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
398 | }; |
399 | ||
10b3939b DJ |
400 | /* Persistent data held for a compilation unit, even when not |
401 | processing it. We put a pointer to this structure in the | |
402 | read_symtab_private field of the psymtab. If we encounter | |
403 | inter-compilation-unit references, we also maintain a sorted | |
404 | list of all compilation units. */ | |
405 | ||
ae038cb0 DJ |
406 | struct dwarf2_per_cu_data |
407 | { | |
348e048f | 408 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 409 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
410 | - if it doesn't, GDB will fall over anyway. |
411 | NOTE: Unlike comp_unit_head.length, this length includes | |
412 | initial_length_size. */ | |
c764a876 | 413 | unsigned int offset; |
348e048f | 414 | unsigned int length : 29; |
ae038cb0 DJ |
415 | |
416 | /* Flag indicating this compilation unit will be read in before | |
417 | any of the current compilation units are processed. */ | |
c764a876 | 418 | unsigned int queued : 1; |
ae038cb0 | 419 | |
5afb4e99 DJ |
420 | /* This flag will be set if we need to load absolutely all DIEs |
421 | for this compilation unit, instead of just the ones we think | |
422 | are interesting. It gets set if we look for a DIE in the | |
423 | hash table and don't find it. */ | |
424 | unsigned int load_all_dies : 1; | |
425 | ||
348e048f DE |
426 | /* Non-zero if this CU is from .debug_types. |
427 | Otherwise it's from .debug_info. */ | |
428 | unsigned int from_debug_types : 1; | |
429 | ||
17ea53c3 JK |
430 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
431 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 432 | struct dwarf2_cu *cu; |
1c379e20 | 433 | |
9291a0cd TT |
434 | /* The corresponding objfile. */ |
435 | struct objfile *objfile; | |
436 | ||
437 | /* When using partial symbol tables, the 'psymtab' field is active. | |
438 | Otherwise the 'quick' field is active. */ | |
439 | union | |
440 | { | |
441 | /* The partial symbol table associated with this compilation unit, | |
442 | or NULL for partial units (which do not have an associated | |
443 | symtab). */ | |
444 | struct partial_symtab *psymtab; | |
445 | ||
446 | /* Data needed by the "quick" functions. */ | |
447 | struct dwarf2_per_cu_quick_data *quick; | |
448 | } v; | |
ae038cb0 DJ |
449 | }; |
450 | ||
348e048f DE |
451 | /* Entry in the signatured_types hash table. */ |
452 | ||
453 | struct signatured_type | |
454 | { | |
455 | ULONGEST signature; | |
456 | ||
457 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
458 | unsigned int offset; | |
459 | ||
460 | /* Offset in .debug_types of the type defined by this TU. */ | |
461 | unsigned int type_offset; | |
462 | ||
463 | /* The CU(/TU) of this type. */ | |
464 | struct dwarf2_per_cu_data per_cu; | |
465 | }; | |
466 | ||
0963b4bd MS |
467 | /* Struct used to pass misc. parameters to read_die_and_children, et |
468 | al. which are used for both .debug_info and .debug_types dies. | |
469 | All parameters here are unchanging for the life of the call. This | |
470 | struct exists to abstract away the constant parameters of die | |
471 | reading. */ | |
93311388 DE |
472 | |
473 | struct die_reader_specs | |
474 | { | |
475 | /* The bfd of this objfile. */ | |
476 | bfd* abfd; | |
477 | ||
478 | /* The CU of the DIE we are parsing. */ | |
479 | struct dwarf2_cu *cu; | |
480 | ||
481 | /* Pointer to start of section buffer. | |
482 | This is either the start of .debug_info or .debug_types. */ | |
483 | const gdb_byte *buffer; | |
484 | }; | |
485 | ||
debd256d JB |
486 | /* The line number information for a compilation unit (found in the |
487 | .debug_line section) begins with a "statement program header", | |
488 | which contains the following information. */ | |
489 | struct line_header | |
490 | { | |
491 | unsigned int total_length; | |
492 | unsigned short version; | |
493 | unsigned int header_length; | |
494 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 495 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
496 | unsigned char default_is_stmt; |
497 | int line_base; | |
498 | unsigned char line_range; | |
499 | unsigned char opcode_base; | |
500 | ||
501 | /* standard_opcode_lengths[i] is the number of operands for the | |
502 | standard opcode whose value is i. This means that | |
503 | standard_opcode_lengths[0] is unused, and the last meaningful | |
504 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
505 | unsigned char *standard_opcode_lengths; | |
506 | ||
507 | /* The include_directories table. NOTE! These strings are not | |
508 | allocated with xmalloc; instead, they are pointers into | |
509 | debug_line_buffer. If you try to free them, `free' will get | |
510 | indigestion. */ | |
511 | unsigned int num_include_dirs, include_dirs_size; | |
512 | char **include_dirs; | |
513 | ||
514 | /* The file_names table. NOTE! These strings are not allocated | |
515 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
516 | Don't try to free them directly. */ | |
517 | unsigned int num_file_names, file_names_size; | |
518 | struct file_entry | |
c906108c | 519 | { |
debd256d JB |
520 | char *name; |
521 | unsigned int dir_index; | |
522 | unsigned int mod_time; | |
523 | unsigned int length; | |
aaa75496 | 524 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 525 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
526 | } *file_names; |
527 | ||
528 | /* The start and end of the statement program following this | |
6502dd73 | 529 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 530 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 531 | }; |
c906108c SS |
532 | |
533 | /* When we construct a partial symbol table entry we only | |
0963b4bd | 534 | need this much information. */ |
c906108c SS |
535 | struct partial_die_info |
536 | { | |
72bf9492 | 537 | /* Offset of this DIE. */ |
c906108c | 538 | unsigned int offset; |
72bf9492 DJ |
539 | |
540 | /* DWARF-2 tag for this DIE. */ | |
541 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
542 | ||
72bf9492 DJ |
543 | /* Assorted flags describing the data found in this DIE. */ |
544 | unsigned int has_children : 1; | |
545 | unsigned int is_external : 1; | |
546 | unsigned int is_declaration : 1; | |
547 | unsigned int has_type : 1; | |
548 | unsigned int has_specification : 1; | |
549 | unsigned int has_pc_info : 1; | |
550 | ||
551 | /* Flag set if the SCOPE field of this structure has been | |
552 | computed. */ | |
553 | unsigned int scope_set : 1; | |
554 | ||
fa4028e9 JB |
555 | /* Flag set if the DIE has a byte_size attribute. */ |
556 | unsigned int has_byte_size : 1; | |
557 | ||
98bfdba5 PA |
558 | /* Flag set if any of the DIE's children are template arguments. */ |
559 | unsigned int has_template_arguments : 1; | |
560 | ||
abc72ce4 DE |
561 | /* Flag set if fixup_partial_die has been called on this die. */ |
562 | unsigned int fixup_called : 1; | |
563 | ||
72bf9492 | 564 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 565 | sometimes a default name for unnamed DIEs. */ |
c906108c | 566 | char *name; |
72bf9492 | 567 | |
abc72ce4 DE |
568 | /* The linkage name, if present. */ |
569 | const char *linkage_name; | |
570 | ||
72bf9492 DJ |
571 | /* The scope to prepend to our children. This is generally |
572 | allocated on the comp_unit_obstack, so will disappear | |
573 | when this compilation unit leaves the cache. */ | |
574 | char *scope; | |
575 | ||
576 | /* The location description associated with this DIE, if any. */ | |
577 | struct dwarf_block *locdesc; | |
578 | ||
579 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
580 | CORE_ADDR lowpc; |
581 | CORE_ADDR highpc; | |
72bf9492 | 582 | |
93311388 | 583 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 584 | DW_AT_sibling, if any. */ |
abc72ce4 DE |
585 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
586 | return DW_AT_sibling values to its caller load_partial_dies. */ | |
fe1b8b76 | 587 | gdb_byte *sibling; |
72bf9492 DJ |
588 | |
589 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
590 | DW_AT_specification (or DW_AT_abstract_origin or | |
591 | DW_AT_extension). */ | |
592 | unsigned int spec_offset; | |
593 | ||
594 | /* Pointers to this DIE's parent, first child, and next sibling, | |
595 | if any. */ | |
596 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
597 | }; |
598 | ||
0963b4bd | 599 | /* This data structure holds the information of an abbrev. */ |
c906108c SS |
600 | struct abbrev_info |
601 | { | |
602 | unsigned int number; /* number identifying abbrev */ | |
603 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
604 | unsigned short has_children; /* boolean */ |
605 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
606 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
607 | struct abbrev_info *next; /* next in chain */ | |
608 | }; | |
609 | ||
610 | struct attr_abbrev | |
611 | { | |
9d25dd43 DE |
612 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
613 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
614 | }; |
615 | ||
0963b4bd | 616 | /* Attributes have a name and a value. */ |
b60c80d6 DJ |
617 | struct attribute |
618 | { | |
9d25dd43 | 619 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
620 | ENUM_BITFIELD(dwarf_form) form : 15; |
621 | ||
622 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
623 | field should be in u.str (existing only for DW_STRING) but it is kept | |
624 | here for better struct attribute alignment. */ | |
625 | unsigned int string_is_canonical : 1; | |
626 | ||
b60c80d6 DJ |
627 | union |
628 | { | |
629 | char *str; | |
630 | struct dwarf_block *blk; | |
43bbcdc2 PH |
631 | ULONGEST unsnd; |
632 | LONGEST snd; | |
b60c80d6 | 633 | CORE_ADDR addr; |
348e048f | 634 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
635 | } |
636 | u; | |
637 | }; | |
638 | ||
0963b4bd | 639 | /* This data structure holds a complete die structure. */ |
c906108c SS |
640 | struct die_info |
641 | { | |
76815b17 DE |
642 | /* DWARF-2 tag for this DIE. */ |
643 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
644 | ||
645 | /* Number of attributes */ | |
98bfdba5 PA |
646 | unsigned char num_attrs; |
647 | ||
648 | /* True if we're presently building the full type name for the | |
649 | type derived from this DIE. */ | |
650 | unsigned char building_fullname : 1; | |
76815b17 DE |
651 | |
652 | /* Abbrev number */ | |
653 | unsigned int abbrev; | |
654 | ||
93311388 | 655 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 656 | unsigned int offset; |
78ba4af6 JB |
657 | |
658 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
659 | points to this die's parent; CHILD points to the first child of | |
660 | this node; and all the children of a given node are chained | |
4950bc1c | 661 | together via their SIBLING fields. */ |
639d11d3 DC |
662 | struct die_info *child; /* Its first child, if any. */ |
663 | struct die_info *sibling; /* Its next sibling, if any. */ | |
664 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 665 | |
b60c80d6 DJ |
666 | /* An array of attributes, with NUM_ATTRS elements. There may be |
667 | zero, but it's not common and zero-sized arrays are not | |
668 | sufficiently portable C. */ | |
669 | struct attribute attrs[1]; | |
c906108c SS |
670 | }; |
671 | ||
5fb290d7 DJ |
672 | struct function_range |
673 | { | |
674 | const char *name; | |
675 | CORE_ADDR lowpc, highpc; | |
676 | int seen_line; | |
677 | struct function_range *next; | |
678 | }; | |
679 | ||
0963b4bd | 680 | /* Get at parts of an attribute structure. */ |
c906108c SS |
681 | |
682 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 683 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
684 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
685 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
686 | #define DW_SND(attr) ((attr)->u.snd) | |
687 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 688 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c | 689 | |
0963b4bd | 690 | /* Blocks are a bunch of untyped bytes. */ |
c906108c SS |
691 | struct dwarf_block |
692 | { | |
693 | unsigned int size; | |
fe1b8b76 | 694 | gdb_byte *data; |
c906108c SS |
695 | }; |
696 | ||
c906108c SS |
697 | #ifndef ATTR_ALLOC_CHUNK |
698 | #define ATTR_ALLOC_CHUNK 4 | |
699 | #endif | |
700 | ||
c906108c SS |
701 | /* Allocate fields for structs, unions and enums in this size. */ |
702 | #ifndef DW_FIELD_ALLOC_CHUNK | |
703 | #define DW_FIELD_ALLOC_CHUNK 4 | |
704 | #endif | |
705 | ||
c906108c SS |
706 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
707 | but this would require a corresponding change in unpack_field_as_long | |
708 | and friends. */ | |
709 | static int bits_per_byte = 8; | |
710 | ||
711 | /* The routines that read and process dies for a C struct or C++ class | |
712 | pass lists of data member fields and lists of member function fields | |
713 | in an instance of a field_info structure, as defined below. */ | |
714 | struct field_info | |
c5aa993b | 715 | { |
0963b4bd | 716 | /* List of data member and baseclasses fields. */ |
c5aa993b JM |
717 | struct nextfield |
718 | { | |
719 | struct nextfield *next; | |
720 | int accessibility; | |
721 | int virtuality; | |
722 | struct field field; | |
723 | } | |
7d0ccb61 | 724 | *fields, *baseclasses; |
c906108c | 725 | |
7d0ccb61 | 726 | /* Number of fields (including baseclasses). */ |
c5aa993b | 727 | int nfields; |
c906108c | 728 | |
c5aa993b JM |
729 | /* Number of baseclasses. */ |
730 | int nbaseclasses; | |
c906108c | 731 | |
c5aa993b JM |
732 | /* Set if the accesibility of one of the fields is not public. */ |
733 | int non_public_fields; | |
c906108c | 734 | |
c5aa993b JM |
735 | /* Member function fields array, entries are allocated in the order they |
736 | are encountered in the object file. */ | |
737 | struct nextfnfield | |
738 | { | |
739 | struct nextfnfield *next; | |
740 | struct fn_field fnfield; | |
741 | } | |
742 | *fnfields; | |
c906108c | 743 | |
c5aa993b JM |
744 | /* Member function fieldlist array, contains name of possibly overloaded |
745 | member function, number of overloaded member functions and a pointer | |
746 | to the head of the member function field chain. */ | |
747 | struct fnfieldlist | |
748 | { | |
749 | char *name; | |
750 | int length; | |
751 | struct nextfnfield *head; | |
752 | } | |
753 | *fnfieldlists; | |
c906108c | 754 | |
c5aa993b JM |
755 | /* Number of entries in the fnfieldlists array. */ |
756 | int nfnfields; | |
98751a41 JK |
757 | |
758 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
759 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
760 | struct typedef_field_list | |
761 | { | |
762 | struct typedef_field field; | |
763 | struct typedef_field_list *next; | |
764 | } | |
765 | *typedef_field_list; | |
766 | unsigned typedef_field_list_count; | |
c5aa993b | 767 | }; |
c906108c | 768 | |
10b3939b DJ |
769 | /* One item on the queue of compilation units to read in full symbols |
770 | for. */ | |
771 | struct dwarf2_queue_item | |
772 | { | |
773 | struct dwarf2_per_cu_data *per_cu; | |
774 | struct dwarf2_queue_item *next; | |
775 | }; | |
776 | ||
777 | /* The current queue. */ | |
778 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
779 | ||
ae038cb0 DJ |
780 | /* Loaded secondary compilation units are kept in memory until they |
781 | have not been referenced for the processing of this many | |
782 | compilation units. Set this to zero to disable caching. Cache | |
783 | sizes of up to at least twenty will improve startup time for | |
784 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
785 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
786 | static void |
787 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
788 | struct cmd_list_element *c, const char *value) | |
789 | { | |
3e43a32a MS |
790 | fprintf_filtered (file, _("The upper bound on the age of cached " |
791 | "dwarf2 compilation units is %s.\n"), | |
920d2a44 AC |
792 | value); |
793 | } | |
794 | ||
ae038cb0 | 795 | |
0963b4bd | 796 | /* Various complaints about symbol reading that don't abort the process. */ |
c906108c | 797 | |
4d3c2250 KB |
798 | static void |
799 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 800 | { |
4d3c2250 | 801 | complaint (&symfile_complaints, |
e2e0b3e5 | 802 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
803 | } |
804 | ||
25e43795 DJ |
805 | static void |
806 | dwarf2_debug_line_missing_file_complaint (void) | |
807 | { | |
808 | complaint (&symfile_complaints, | |
809 | _(".debug_line section has line data without a file")); | |
810 | } | |
811 | ||
59205f5a JB |
812 | static void |
813 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
814 | { | |
815 | complaint (&symfile_complaints, | |
3e43a32a MS |
816 | _(".debug_line section has line " |
817 | "program sequence without an end")); | |
59205f5a JB |
818 | } |
819 | ||
4d3c2250 KB |
820 | static void |
821 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 822 | { |
e2e0b3e5 | 823 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
824 | } |
825 | ||
4d3c2250 KB |
826 | static void |
827 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
828 | int arg3) | |
2e276125 | 829 | { |
4d3c2250 | 830 | complaint (&symfile_complaints, |
3e43a32a MS |
831 | _("const value length mismatch for '%s', got %d, expected %d"), |
832 | arg1, arg2, arg3); | |
4d3c2250 KB |
833 | } |
834 | ||
835 | static void | |
836 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 837 | { |
4d3c2250 | 838 | complaint (&symfile_complaints, |
e2e0b3e5 | 839 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
840 | } |
841 | ||
842 | static void | |
843 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 844 | { |
4d3c2250 | 845 | complaint (&symfile_complaints, |
3e43a32a MS |
846 | _("macro debug info contains a " |
847 | "malformed macro definition:\n`%s'"), | |
4d3c2250 KB |
848 | arg1); |
849 | } | |
850 | ||
851 | static void | |
852 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 853 | { |
4d3c2250 | 854 | complaint (&symfile_complaints, |
3e43a32a MS |
855 | _("invalid attribute class or form for '%s' in '%s'"), |
856 | arg1, arg2); | |
4d3c2250 | 857 | } |
c906108c | 858 | |
c906108c SS |
859 | /* local function prototypes */ |
860 | ||
4efb68b1 | 861 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 862 | |
aaa75496 JB |
863 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
864 | struct objfile *); | |
865 | ||
c67a9c90 | 866 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 867 | |
72bf9492 DJ |
868 | static void scan_partial_symbols (struct partial_die_info *, |
869 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 870 | int, struct dwarf2_cu *); |
c906108c | 871 | |
72bf9492 DJ |
872 | static void add_partial_symbol (struct partial_die_info *, |
873 | struct dwarf2_cu *); | |
63d06c5c | 874 | |
72bf9492 DJ |
875 | static void add_partial_namespace (struct partial_die_info *pdi, |
876 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 877 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 878 | |
5d7cb8df JK |
879 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
880 | CORE_ADDR *highpc, int need_pc, | |
881 | struct dwarf2_cu *cu); | |
882 | ||
72bf9492 DJ |
883 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
884 | struct dwarf2_cu *cu); | |
91c24f0a | 885 | |
bc30ff58 JB |
886 | static void add_partial_subprogram (struct partial_die_info *pdi, |
887 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 888 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 889 | |
fe1b8b76 | 890 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
891 | gdb_byte *buffer, gdb_byte *info_ptr, |
892 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 893 | |
a14ed312 | 894 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 895 | |
a14ed312 | 896 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 897 | |
e7c27a73 | 898 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 899 | |
f3dd6933 | 900 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 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 | |
93311388 DE |
908 | static struct partial_die_info *load_partial_dies (bfd *, |
909 | gdb_byte *, gdb_byte *, | |
910 | int, struct dwarf2_cu *); | |
72bf9492 | 911 | |
fe1b8b76 | 912 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
913 | struct abbrev_info *abbrev, |
914 | unsigned int, bfd *, | |
915 | gdb_byte *, gdb_byte *, | |
916 | struct dwarf2_cu *); | |
c906108c | 917 | |
c764a876 | 918 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 919 | struct dwarf2_cu *); |
72bf9492 DJ |
920 | |
921 | static void fixup_partial_die (struct partial_die_info *, | |
922 | struct dwarf2_cu *); | |
923 | ||
fe1b8b76 JB |
924 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
925 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 926 | |
fe1b8b76 JB |
927 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
928 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 929 | |
fe1b8b76 | 930 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 931 | |
fe1b8b76 | 932 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 933 | |
fe1b8b76 | 934 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 935 | |
fe1b8b76 | 936 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 937 | |
93311388 | 938 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 939 | |
fe1b8b76 | 940 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 941 | unsigned int *); |
c906108c | 942 | |
c764a876 DE |
943 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
944 | ||
945 | static LONGEST read_checked_initial_length_and_offset | |
946 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
947 | unsigned int *, unsigned int *); | |
613e1657 | 948 | |
fe1b8b76 | 949 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
950 | unsigned int *); |
951 | ||
952 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 953 | |
fe1b8b76 | 954 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 955 | |
9b1c24c8 | 956 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 957 | |
fe1b8b76 JB |
958 | static char *read_indirect_string (bfd *, gdb_byte *, |
959 | const struct comp_unit_head *, | |
960 | unsigned int *); | |
4bdf3d34 | 961 | |
fe1b8b76 | 962 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 963 | |
fe1b8b76 | 964 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 965 | |
fe1b8b76 | 966 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 967 | |
e142c38c | 968 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 969 | |
e142c38c DJ |
970 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
971 | struct dwarf2_cu *); | |
c906108c | 972 | |
348e048f DE |
973 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
974 | unsigned int, | |
975 | struct dwarf2_cu *); | |
976 | ||
05cf31d1 JB |
977 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
978 | struct dwarf2_cu *cu); | |
979 | ||
e142c38c | 980 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 981 | |
e142c38c | 982 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 983 | struct dwarf2_cu **); |
63d06c5c | 984 | |
debd256d JB |
985 | static void free_line_header (struct line_header *lh); |
986 | ||
aaa75496 JB |
987 | static void add_file_name (struct line_header *, char *, unsigned int, |
988 | unsigned int, unsigned int); | |
989 | ||
debd256d JB |
990 | static struct line_header *(dwarf_decode_line_header |
991 | (unsigned int offset, | |
e7c27a73 | 992 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d | 993 | |
72b9f47f | 994 | static void dwarf_decode_lines (struct line_header *, const char *, bfd *, |
aaa75496 | 995 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 996 | |
72b9f47f | 997 | static void dwarf2_start_subfile (char *, const char *, const char *); |
c906108c | 998 | |
a14ed312 | 999 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1000 | struct dwarf2_cu *); |
c906108c | 1001 | |
34eaf542 TT |
1002 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1003 | struct dwarf2_cu *, struct symbol *); | |
1004 | ||
a14ed312 | 1005 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1006 | struct dwarf2_cu *); |
c906108c | 1007 | |
98bfdba5 PA |
1008 | static void dwarf2_const_value_attr (struct attribute *attr, |
1009 | struct type *type, | |
1010 | const char *name, | |
1011 | struct obstack *obstack, | |
1012 | struct dwarf2_cu *cu, long *value, | |
1013 | gdb_byte **bytes, | |
1014 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1015 | |
e7c27a73 | 1016 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1017 | |
b4ba55a1 JB |
1018 | static int need_gnat_info (struct dwarf2_cu *); |
1019 | ||
3e43a32a MS |
1020 | static struct type *die_descriptive_type (struct die_info *, |
1021 | struct dwarf2_cu *); | |
b4ba55a1 JB |
1022 | |
1023 | static void set_descriptive_type (struct type *, struct die_info *, | |
1024 | struct dwarf2_cu *); | |
1025 | ||
e7c27a73 DJ |
1026 | static struct type *die_containing_type (struct die_info *, |
1027 | struct dwarf2_cu *); | |
c906108c | 1028 | |
673bfd45 DE |
1029 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1030 | struct dwarf2_cu *); | |
c906108c | 1031 | |
f792889a | 1032 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1033 | |
673bfd45 DE |
1034 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1035 | ||
086ed43d | 1036 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1037 | |
6e70227d | 1038 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1039 | const char *suffix, int physname, |
1040 | struct dwarf2_cu *cu); | |
63d06c5c | 1041 | |
e7c27a73 | 1042 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1043 | |
348e048f DE |
1044 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1045 | ||
e7c27a73 | 1046 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1047 | |
e7c27a73 | 1048 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 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 | ||
93311388 | 1101 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1102 | |
93311388 DE |
1103 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1104 | gdb_byte *info_ptr, | |
d97bc12b DE |
1105 | gdb_byte **new_info_ptr, |
1106 | struct die_info *parent); | |
1107 | ||
93311388 DE |
1108 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1109 | gdb_byte *info_ptr, | |
fe1b8b76 | 1110 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1111 | struct die_info *parent); |
1112 | ||
93311388 DE |
1113 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1114 | gdb_byte *info_ptr, | |
fe1b8b76 | 1115 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1116 | struct die_info *parent); |
1117 | ||
93311388 DE |
1118 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1119 | struct die_info **, gdb_byte *, | |
1120 | int *); | |
1121 | ||
e7c27a73 | 1122 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1123 | |
71c25dea TT |
1124 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1125 | struct obstack *); | |
1126 | ||
e142c38c | 1127 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1128 | |
98bfdba5 PA |
1129 | static const char *dwarf2_full_name (char *name, |
1130 | struct die_info *die, | |
1131 | struct dwarf2_cu *cu); | |
1132 | ||
e142c38c | 1133 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1134 | struct dwarf2_cu **); |
9219021c | 1135 | |
a14ed312 | 1136 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1137 | |
a14ed312 | 1138 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1139 | |
a14ed312 | 1140 | static char *dwarf_form_name (unsigned int); |
c906108c | 1141 | |
a14ed312 | 1142 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1143 | |
a14ed312 | 1144 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1145 | |
1146 | #if 0 | |
a14ed312 | 1147 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1148 | #endif |
1149 | ||
f9aca02d | 1150 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1151 | |
d97bc12b DE |
1152 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1153 | ||
1154 | static void dump_die_for_error (struct die_info *); | |
1155 | ||
1156 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1157 | struct die_info *); | |
c906108c | 1158 | |
d97bc12b | 1159 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1160 | |
51545339 | 1161 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1162 | struct dwarf2_cu *); |
c906108c | 1163 | |
93311388 DE |
1164 | static int is_ref_attr (struct attribute *); |
1165 | ||
c764a876 | 1166 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1167 | |
43bbcdc2 | 1168 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1169 | |
348e048f DE |
1170 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1171 | struct attribute *, | |
1172 | struct dwarf2_cu **); | |
1173 | ||
10b3939b DJ |
1174 | static struct die_info *follow_die_ref (struct die_info *, |
1175 | struct attribute *, | |
f2f0e013 | 1176 | struct dwarf2_cu **); |
c906108c | 1177 | |
348e048f DE |
1178 | static struct die_info *follow_die_sig (struct die_info *, |
1179 | struct attribute *, | |
1180 | struct dwarf2_cu **); | |
1181 | ||
1182 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1183 | unsigned int offset); | |
1184 | ||
1185 | static void read_signatured_type (struct objfile *, | |
1186 | struct signatured_type *type_sig); | |
1187 | ||
c906108c SS |
1188 | /* memory allocation interface */ |
1189 | ||
7b5a2f43 | 1190 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1191 | |
f3dd6933 | 1192 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1193 | |
b60c80d6 | 1194 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1195 | |
e142c38c | 1196 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1197 | |
e142c38c DJ |
1198 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1199 | struct dwarf2_cu *); | |
5fb290d7 | 1200 | |
2e276125 | 1201 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1202 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1203 | |
8e19ed76 PS |
1204 | static int attr_form_is_block (struct attribute *); |
1205 | ||
3690dd37 JB |
1206 | static int attr_form_is_section_offset (struct attribute *); |
1207 | ||
1208 | static int attr_form_is_constant (struct attribute *); | |
1209 | ||
8cf6f0b1 TT |
1210 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
1211 | struct dwarf2_loclist_baton *baton, | |
1212 | struct attribute *attr); | |
1213 | ||
93e7bd98 DJ |
1214 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1215 | struct symbol *sym, | |
1216 | struct dwarf2_cu *cu); | |
4c2df51b | 1217 | |
93311388 DE |
1218 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1219 | struct abbrev_info *abbrev, | |
1220 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1221 | |
72bf9492 DJ |
1222 | static void free_stack_comp_unit (void *); |
1223 | ||
72bf9492 DJ |
1224 | static hashval_t partial_die_hash (const void *item); |
1225 | ||
1226 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1227 | ||
ae038cb0 | 1228 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1229 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1230 | |
1231 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1232 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1233 | |
9816fde3 JK |
1234 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
1235 | struct objfile *objfile); | |
1236 | ||
1237 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, | |
1238 | struct die_info *comp_unit_die); | |
93311388 | 1239 | |
ae038cb0 DJ |
1240 | static void free_one_comp_unit (void *); |
1241 | ||
1242 | static void free_cached_comp_units (void *); | |
1243 | ||
1244 | static void age_cached_comp_units (void); | |
1245 | ||
1246 | static void free_one_cached_comp_unit (void *); | |
1247 | ||
f792889a DJ |
1248 | static struct type *set_die_type (struct die_info *, struct type *, |
1249 | struct dwarf2_cu *); | |
1c379e20 | 1250 | |
ae038cb0 DJ |
1251 | static void create_all_comp_units (struct objfile *); |
1252 | ||
1fd400ff TT |
1253 | static int create_debug_types_hash_table (struct objfile *objfile); |
1254 | ||
93311388 DE |
1255 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1256 | struct objfile *); | |
10b3939b DJ |
1257 | |
1258 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1259 | ||
1260 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1261 | struct dwarf2_per_cu_data *); | |
1262 | ||
ae038cb0 DJ |
1263 | static void dwarf2_mark (struct dwarf2_cu *); |
1264 | ||
1265 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1266 | ||
673bfd45 DE |
1267 | static struct type *get_die_type_at_offset (unsigned int, |
1268 | struct dwarf2_per_cu_data *per_cu); | |
1269 | ||
f792889a | 1270 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1271 | |
9291a0cd TT |
1272 | static void dwarf2_release_queue (void *dummy); |
1273 | ||
1274 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1275 | struct objfile *objfile); | |
1276 | ||
1277 | static void process_queue (struct objfile *objfile); | |
1278 | ||
1279 | static void find_file_and_directory (struct die_info *die, | |
1280 | struct dwarf2_cu *cu, | |
1281 | char **name, char **comp_dir); | |
1282 | ||
1283 | static char *file_full_name (int file, struct line_header *lh, | |
1284 | const char *comp_dir); | |
1285 | ||
1286 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1287 | gdb_byte *info_ptr, | |
1288 | gdb_byte *buffer, | |
1289 | unsigned int buffer_size, | |
1290 | bfd *abfd); | |
1291 | ||
1292 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1293 | struct dwarf2_cu *cu); | |
1294 | ||
673bfd45 | 1295 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1296 | |
9291a0cd TT |
1297 | #if WORDS_BIGENDIAN |
1298 | ||
1299 | /* Convert VALUE between big- and little-endian. */ | |
1300 | static offset_type | |
1301 | byte_swap (offset_type value) | |
1302 | { | |
1303 | offset_type result; | |
1304 | ||
1305 | result = (value & 0xff) << 24; | |
1306 | result |= (value & 0xff00) << 8; | |
1307 | result |= (value & 0xff0000) >> 8; | |
1308 | result |= (value & 0xff000000) >> 24; | |
1309 | return result; | |
1310 | } | |
1311 | ||
1312 | #define MAYBE_SWAP(V) byte_swap (V) | |
1313 | ||
1314 | #else | |
1315 | #define MAYBE_SWAP(V) (V) | |
1316 | #endif /* WORDS_BIGENDIAN */ | |
1317 | ||
1318 | /* The suffix for an index file. */ | |
1319 | #define INDEX_SUFFIX ".gdb-index" | |
1320 | ||
3da10d80 KS |
1321 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1322 | struct dwarf2_cu *cu); | |
1323 | ||
c906108c SS |
1324 | /* Try to locate the sections we need for DWARF 2 debugging |
1325 | information and return true if we have enough to do something. */ | |
1326 | ||
1327 | int | |
6502dd73 | 1328 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1329 | { |
be391dca TT |
1330 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1331 | if (!dwarf2_per_objfile) | |
1332 | { | |
1333 | /* Initialize per-objfile state. */ | |
1334 | struct dwarf2_per_objfile *data | |
1335 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1336 | |
be391dca TT |
1337 | memset (data, 0, sizeof (*data)); |
1338 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1339 | dwarf2_per_objfile = data; | |
6502dd73 | 1340 | |
be391dca TT |
1341 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
1342 | dwarf2_per_objfile->objfile = objfile; | |
1343 | } | |
1344 | return (dwarf2_per_objfile->info.asection != NULL | |
1345 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1346 | } |
1347 | ||
233a11ab CS |
1348 | /* When loading sections, we can either look for ".<name>", or for |
1349 | * ".z<name>", which indicates a compressed section. */ | |
1350 | ||
1351 | static int | |
dce234bc | 1352 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1353 | { |
dce234bc PP |
1354 | return (section_name[0] == '.' |
1355 | && (strcmp (section_name + 1, name) == 0 | |
1356 | || (section_name[1] == 'z' | |
1357 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1358 | } |
1359 | ||
c906108c SS |
1360 | /* This function is mapped across the sections and remembers the |
1361 | offset and size of each of the debugging sections we are interested | |
1362 | in. */ | |
1363 | ||
1364 | static void | |
72dca2f5 | 1365 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1366 | { |
dce234bc | 1367 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1368 | { |
dce234bc PP |
1369 | dwarf2_per_objfile->info.asection = sectp; |
1370 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1371 | } |
dce234bc | 1372 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1373 | { |
dce234bc PP |
1374 | dwarf2_per_objfile->abbrev.asection = sectp; |
1375 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1376 | } |
dce234bc | 1377 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1378 | { |
dce234bc PP |
1379 | dwarf2_per_objfile->line.asection = sectp; |
1380 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1381 | } |
dce234bc | 1382 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1383 | { |
dce234bc PP |
1384 | dwarf2_per_objfile->loc.asection = sectp; |
1385 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1386 | } |
dce234bc | 1387 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1388 | { |
dce234bc PP |
1389 | dwarf2_per_objfile->macinfo.asection = sectp; |
1390 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1391 | } |
dce234bc | 1392 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1393 | { |
dce234bc PP |
1394 | dwarf2_per_objfile->str.asection = sectp; |
1395 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1396 | } |
dce234bc | 1397 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1398 | { |
dce234bc PP |
1399 | dwarf2_per_objfile->frame.asection = sectp; |
1400 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1401 | } |
dce234bc | 1402 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1403 | { |
3799ccc6 | 1404 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1405 | |
3799ccc6 EZ |
1406 | if (aflag & SEC_HAS_CONTENTS) |
1407 | { | |
dce234bc PP |
1408 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1409 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1410 | } |
b6af0555 | 1411 | } |
dce234bc | 1412 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1413 | { |
dce234bc PP |
1414 | dwarf2_per_objfile->ranges.asection = sectp; |
1415 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1416 | } |
348e048f DE |
1417 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1418 | { | |
1419 | dwarf2_per_objfile->types.asection = sectp; | |
1420 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1421 | } | |
9291a0cd TT |
1422 | else if (section_is_p (sectp->name, GDB_INDEX_SECTION)) |
1423 | { | |
1424 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1425 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1426 | } | |
dce234bc | 1427 | |
72dca2f5 FR |
1428 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1429 | && bfd_section_vma (abfd, sectp) == 0) | |
1430 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1431 | } |
1432 | ||
dce234bc PP |
1433 | /* Decompress a section that was compressed using zlib. Store the |
1434 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1435 | |
1436 | static void | |
dce234bc PP |
1437 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1438 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1439 | { | |
1440 | bfd *abfd = objfile->obfd; | |
1441 | #ifndef HAVE_ZLIB_H | |
1442 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1443 | "is disabled in this copy of GDB"), | |
1444 | bfd_get_filename (abfd)); | |
1445 | #else | |
1446 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1447 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1448 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1449 | bfd_size_type uncompressed_size; |
1450 | gdb_byte *uncompressed_buffer; | |
1451 | z_stream strm; | |
1452 | int rc; | |
1453 | int header_size = 12; | |
1454 | ||
1455 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
3e43a32a MS |
1456 | || bfd_bread (compressed_buffer, |
1457 | compressed_size, abfd) != compressed_size) | |
dce234bc PP |
1458 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
1459 | bfd_get_filename (abfd)); | |
1460 | ||
1461 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1462 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1463 | if (compressed_size < header_size | |
1464 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1465 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1466 | bfd_get_filename (abfd)); | |
1467 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1468 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1469 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1470 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1471 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1472 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1473 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1474 | uncompressed_size += compressed_buffer[11]; | |
1475 | ||
1476 | /* It is possible the section consists of several compressed | |
1477 | buffers concatenated together, so we uncompress in a loop. */ | |
1478 | strm.zalloc = NULL; | |
1479 | strm.zfree = NULL; | |
1480 | strm.opaque = NULL; | |
1481 | strm.avail_in = compressed_size - header_size; | |
1482 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1483 | strm.avail_out = uncompressed_size; | |
1484 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1485 | uncompressed_size); | |
1486 | rc = inflateInit (&strm); | |
1487 | while (strm.avail_in > 0) | |
1488 | { | |
1489 | if (rc != Z_OK) | |
1490 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1491 | bfd_get_filename (abfd), rc); | |
1492 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1493 | + (uncompressed_size - strm.avail_out)); | |
1494 | rc = inflate (&strm, Z_FINISH); | |
1495 | if (rc != Z_STREAM_END) | |
1496 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1497 | bfd_get_filename (abfd), rc); | |
1498 | rc = inflateReset (&strm); | |
1499 | } | |
1500 | rc = inflateEnd (&strm); | |
1501 | if (rc != Z_OK | |
1502 | || strm.avail_out != 0) | |
1503 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1504 | bfd_get_filename (abfd), rc); | |
1505 | ||
affddf13 | 1506 | do_cleanups (cleanup); |
dce234bc PP |
1507 | *outbuf = uncompressed_buffer; |
1508 | *outsize = uncompressed_size; | |
1509 | #endif | |
233a11ab CS |
1510 | } |
1511 | ||
9e0ac564 TT |
1512 | /* A helper function that decides whether a section is empty. */ |
1513 | ||
1514 | static int | |
1515 | dwarf2_section_empty_p (struct dwarf2_section_info *info) | |
1516 | { | |
1517 | return info->asection == NULL || info->size == 0; | |
1518 | } | |
1519 | ||
dce234bc PP |
1520 | /* Read the contents of the section SECTP from object file specified by |
1521 | OBJFILE, store info about the section into INFO. | |
1522 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1523 | |
dce234bc PP |
1524 | static void |
1525 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1526 | { |
dce234bc PP |
1527 | bfd *abfd = objfile->obfd; |
1528 | asection *sectp = info->asection; | |
1529 | gdb_byte *buf, *retbuf; | |
1530 | unsigned char header[4]; | |
c906108c | 1531 | |
be391dca TT |
1532 | if (info->readin) |
1533 | return; | |
dce234bc PP |
1534 | info->buffer = NULL; |
1535 | info->was_mmapped = 0; | |
be391dca | 1536 | info->readin = 1; |
188dd5d6 | 1537 | |
9e0ac564 | 1538 | if (dwarf2_section_empty_p (info)) |
dce234bc | 1539 | return; |
c906108c | 1540 | |
dce234bc PP |
1541 | /* Check if the file has a 4-byte header indicating compression. */ |
1542 | if (info->size > sizeof (header) | |
1543 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1544 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1545 | { | |
1546 | /* Upon decompression, update the buffer and its size. */ | |
1547 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1548 | { | |
1549 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1550 | &info->size); | |
1551 | return; | |
1552 | } | |
1553 | } | |
4bdf3d34 | 1554 | |
dce234bc PP |
1555 | #ifdef HAVE_MMAP |
1556 | if (pagesize == 0) | |
1557 | pagesize = getpagesize (); | |
2e276125 | 1558 | |
dce234bc PP |
1559 | /* Only try to mmap sections which are large enough: we don't want to |
1560 | waste space due to fragmentation. Also, only try mmap for sections | |
1561 | without relocations. */ | |
1562 | ||
1563 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1564 | { | |
1565 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1566 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1567 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1568 | MAP_PRIVATE, pg_offset); | |
1569 | ||
1570 | if (retbuf != MAP_FAILED) | |
1571 | { | |
1572 | info->was_mmapped = 1; | |
1573 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1574 | #if HAVE_POSIX_MADVISE |
1575 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1576 | #endif | |
dce234bc PP |
1577 | return; |
1578 | } | |
1579 | } | |
1580 | #endif | |
1581 | ||
1582 | /* If we get here, we are a normal, not-compressed section. */ | |
1583 | info->buffer = buf | |
1584 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1585 | ||
1586 | /* When debugging .o files, we may need to apply relocations; see | |
1587 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1588 | We never compress sections in .o files, so we only need to | |
1589 | try this when the section is not compressed. */ | |
ac8035ab | 1590 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1591 | if (retbuf != NULL) |
1592 | { | |
1593 | info->buffer = retbuf; | |
1594 | return; | |
1595 | } | |
1596 | ||
1597 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1598 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1599 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1600 | bfd_get_filename (abfd)); | |
1601 | } | |
1602 | ||
9e0ac564 TT |
1603 | /* A helper function that returns the size of a section in a safe way. |
1604 | If you are positive that the section has been read before using the | |
1605 | size, then it is safe to refer to the dwarf2_section_info object's | |
1606 | "size" field directly. In other cases, you must call this | |
1607 | function, because for compressed sections the size field is not set | |
1608 | correctly until the section has been read. */ | |
1609 | ||
1610 | static bfd_size_type | |
1611 | dwarf2_section_size (struct objfile *objfile, | |
1612 | struct dwarf2_section_info *info) | |
1613 | { | |
1614 | if (!info->readin) | |
1615 | dwarf2_read_section (objfile, info); | |
1616 | return info->size; | |
1617 | } | |
1618 | ||
dce234bc | 1619 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
0963b4bd | 1620 | SECTION_NAME. */ |
af34e669 | 1621 | |
dce234bc PP |
1622 | void |
1623 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1624 | asection **sectp, gdb_byte **bufp, | |
1625 | bfd_size_type *sizep) | |
1626 | { | |
1627 | struct dwarf2_per_objfile *data | |
1628 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1629 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1630 | |
1631 | /* We may see an objfile without any DWARF, in which case we just | |
1632 | return nothing. */ | |
1633 | if (data == NULL) | |
1634 | { | |
1635 | *sectp = NULL; | |
1636 | *bufp = NULL; | |
1637 | *sizep = 0; | |
1638 | return; | |
1639 | } | |
dce234bc PP |
1640 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
1641 | info = &data->eh_frame; | |
1642 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1643 | info = &data->frame; | |
0d53c4c4 | 1644 | else |
f3574227 | 1645 | gdb_assert_not_reached ("unexpected section"); |
dce234bc | 1646 | |
9e0ac564 | 1647 | dwarf2_read_section (objfile, info); |
dce234bc PP |
1648 | |
1649 | *sectp = info->asection; | |
1650 | *bufp = info->buffer; | |
1651 | *sizep = info->size; | |
1652 | } | |
1653 | ||
9291a0cd | 1654 | \f |
7b9f3c50 DE |
1655 | /* DWARF quick_symbols_functions support. */ |
1656 | ||
1657 | /* TUs can share .debug_line entries, and there can be a lot more TUs than | |
1658 | unique line tables, so we maintain a separate table of all .debug_line | |
1659 | derived entries to support the sharing. | |
1660 | All the quick functions need is the list of file names. We discard the | |
1661 | line_header when we're done and don't need to record it here. */ | |
1662 | struct quick_file_names | |
1663 | { | |
1664 | /* The offset in .debug_line of the line table. We hash on this. */ | |
1665 | unsigned int offset; | |
1666 | ||
1667 | /* The number of entries in file_names, real_names. */ | |
1668 | unsigned int num_file_names; | |
1669 | ||
1670 | /* The file names from the line table, after being run through | |
1671 | file_full_name. */ | |
1672 | const char **file_names; | |
1673 | ||
1674 | /* The file names from the line table after being run through | |
1675 | gdb_realpath. These are computed lazily. */ | |
1676 | const char **real_names; | |
1677 | }; | |
1678 | ||
1679 | /* When using the index (and thus not using psymtabs), each CU has an | |
1680 | object of this type. This is used to hold information needed by | |
1681 | the various "quick" methods. */ | |
1682 | struct dwarf2_per_cu_quick_data | |
1683 | { | |
1684 | /* The file table. This can be NULL if there was no file table | |
1685 | or it's currently not read in. | |
1686 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ | |
1687 | struct quick_file_names *file_names; | |
1688 | ||
1689 | /* The corresponding symbol table. This is NULL if symbols for this | |
1690 | CU have not yet been read. */ | |
1691 | struct symtab *symtab; | |
1692 | ||
1693 | /* A temporary mark bit used when iterating over all CUs in | |
1694 | expand_symtabs_matching. */ | |
1695 | unsigned int mark : 1; | |
1696 | ||
1697 | /* True if we've tried to read the file table and found there isn't one. | |
1698 | There will be no point in trying to read it again next time. */ | |
1699 | unsigned int no_file_data : 1; | |
1700 | }; | |
1701 | ||
1702 | /* Hash function for a quick_file_names. */ | |
1703 | ||
1704 | static hashval_t | |
1705 | hash_file_name_entry (const void *e) | |
1706 | { | |
1707 | const struct quick_file_names *file_data = e; | |
1708 | ||
1709 | return file_data->offset; | |
1710 | } | |
1711 | ||
1712 | /* Equality function for a quick_file_names. */ | |
1713 | ||
1714 | static int | |
1715 | eq_file_name_entry (const void *a, const void *b) | |
1716 | { | |
1717 | const struct quick_file_names *ea = a; | |
1718 | const struct quick_file_names *eb = b; | |
1719 | ||
1720 | return ea->offset == eb->offset; | |
1721 | } | |
1722 | ||
1723 | /* Delete function for a quick_file_names. */ | |
1724 | ||
1725 | static void | |
1726 | delete_file_name_entry (void *e) | |
1727 | { | |
1728 | struct quick_file_names *file_data = e; | |
1729 | int i; | |
1730 | ||
1731 | for (i = 0; i < file_data->num_file_names; ++i) | |
1732 | { | |
1733 | xfree ((void*) file_data->file_names[i]); | |
1734 | if (file_data->real_names) | |
1735 | xfree ((void*) file_data->real_names[i]); | |
1736 | } | |
1737 | ||
1738 | /* The space for the struct itself lives on objfile_obstack, | |
1739 | so we don't free it here. */ | |
1740 | } | |
1741 | ||
1742 | /* Create a quick_file_names hash table. */ | |
1743 | ||
1744 | static htab_t | |
1745 | create_quick_file_names_table (unsigned int nr_initial_entries) | |
1746 | { | |
1747 | return htab_create_alloc (nr_initial_entries, | |
1748 | hash_file_name_entry, eq_file_name_entry, | |
1749 | delete_file_name_entry, xcalloc, xfree); | |
1750 | } | |
9291a0cd TT |
1751 | |
1752 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which | |
1753 | this CU came. */ | |
2fdf6df6 | 1754 | |
9291a0cd TT |
1755 | static void |
1756 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1757 | struct dwarf2_per_cu_data *per_cu) | |
1758 | { | |
1759 | struct cleanup *back_to; | |
1760 | ||
1761 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1762 | ||
1763 | queue_comp_unit (per_cu, objfile); | |
1764 | ||
1765 | if (per_cu->from_debug_types) | |
1766 | read_signatured_type_at_offset (objfile, per_cu->offset); | |
1767 | else | |
1768 | load_full_comp_unit (per_cu, objfile); | |
1769 | ||
1770 | process_queue (objfile); | |
1771 | ||
1772 | /* Age the cache, releasing compilation units that have not | |
1773 | been used recently. */ | |
1774 | age_cached_comp_units (); | |
1775 | ||
1776 | do_cleanups (back_to); | |
1777 | } | |
1778 | ||
1779 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1780 | the objfile from which this CU came. Returns the resulting symbol | |
1781 | table. */ | |
2fdf6df6 | 1782 | |
9291a0cd TT |
1783 | static struct symtab * |
1784 | dw2_instantiate_symtab (struct objfile *objfile, | |
1785 | struct dwarf2_per_cu_data *per_cu) | |
1786 | { | |
1787 | if (!per_cu->v.quick->symtab) | |
1788 | { | |
1789 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1790 | increment_reading_symtab (); | |
1791 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1792 | do_cleanups (back_to); | |
1793 | } | |
1794 | return per_cu->v.quick->symtab; | |
1795 | } | |
1796 | ||
1fd400ff | 1797 | /* Return the CU given its index. */ |
2fdf6df6 | 1798 | |
1fd400ff TT |
1799 | static struct dwarf2_per_cu_data * |
1800 | dw2_get_cu (int index) | |
1801 | { | |
1802 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1803 | { | |
1804 | index -= dwarf2_per_objfile->n_comp_units; | |
1805 | return dwarf2_per_objfile->type_comp_units[index]; | |
1806 | } | |
1807 | return dwarf2_per_objfile->all_comp_units[index]; | |
1808 | } | |
1809 | ||
9291a0cd TT |
1810 | /* A helper function that knows how to read a 64-bit value in a way |
1811 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1812 | otherwise. */ | |
2fdf6df6 | 1813 | |
9291a0cd TT |
1814 | static int |
1815 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1816 | { | |
1817 | if (sizeof (ULONGEST) < 8) | |
1818 | { | |
1819 | int i; | |
1820 | ||
1821 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1822 | for (i = 0; i < 4; ++i) | |
1823 | if (bytes[i + 4] != 0) | |
1824 | return 0; | |
1825 | ||
1826 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1827 | } | |
1828 | else | |
1829 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1830 | return 1; | |
1831 | } | |
1832 | ||
1833 | /* Read the CU list from the mapped index, and use it to create all | |
1834 | the CU objects for this objfile. Return 0 if something went wrong, | |
1835 | 1 if everything went ok. */ | |
2fdf6df6 | 1836 | |
9291a0cd | 1837 | static int |
1fd400ff TT |
1838 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1839 | offset_type cu_list_elements) | |
9291a0cd TT |
1840 | { |
1841 | offset_type i; | |
9291a0cd TT |
1842 | |
1843 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1844 | dwarf2_per_objfile->all_comp_units | |
1845 | = obstack_alloc (&objfile->objfile_obstack, | |
1846 | dwarf2_per_objfile->n_comp_units | |
1847 | * sizeof (struct dwarf2_per_cu_data *)); | |
1848 | ||
1849 | for (i = 0; i < cu_list_elements; i += 2) | |
1850 | { | |
1851 | struct dwarf2_per_cu_data *the_cu; | |
1852 | ULONGEST offset, length; | |
1853 | ||
1854 | if (!extract_cu_value (cu_list, &offset) | |
1855 | || !extract_cu_value (cu_list + 8, &length)) | |
1856 | return 0; | |
1857 | cu_list += 2 * 8; | |
1858 | ||
1859 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1860 | struct dwarf2_per_cu_data); | |
1861 | the_cu->offset = offset; | |
1862 | the_cu->length = length; | |
1863 | the_cu->objfile = objfile; | |
1864 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1865 | struct dwarf2_per_cu_quick_data); | |
1866 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1867 | } | |
1868 | ||
1869 | return 1; | |
1870 | } | |
1871 | ||
1fd400ff | 1872 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1873 | |
1fd400ff | 1874 | static int |
673bfd45 DE |
1875 | create_signatured_type_table_from_index (struct objfile *objfile, |
1876 | const gdb_byte *bytes, | |
1877 | offset_type elements) | |
1fd400ff TT |
1878 | { |
1879 | offset_type i; | |
673bfd45 | 1880 | htab_t sig_types_hash; |
1fd400ff TT |
1881 | |
1882 | dwarf2_per_objfile->n_type_comp_units = elements / 3; | |
1883 | dwarf2_per_objfile->type_comp_units | |
1884 | = obstack_alloc (&objfile->objfile_obstack, | |
1885 | dwarf2_per_objfile->n_type_comp_units | |
1886 | * sizeof (struct dwarf2_per_cu_data *)); | |
1887 | ||
673bfd45 | 1888 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1889 | |
1890 | for (i = 0; i < elements; i += 3) | |
1891 | { | |
1892 | struct signatured_type *type_sig; | |
1893 | ULONGEST offset, type_offset, signature; | |
1894 | void **slot; | |
1895 | ||
1896 | if (!extract_cu_value (bytes, &offset) | |
1897 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1898 | return 0; | |
1899 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1900 | bytes += 3 * 8; | |
1901 | ||
1902 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1903 | struct signatured_type); | |
1904 | type_sig->signature = signature; | |
1905 | type_sig->offset = offset; | |
1906 | type_sig->type_offset = type_offset; | |
1907 | type_sig->per_cu.from_debug_types = 1; | |
1908 | type_sig->per_cu.offset = offset; | |
1909 | type_sig->per_cu.objfile = objfile; | |
1910 | type_sig->per_cu.v.quick | |
1911 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1912 | struct dwarf2_per_cu_quick_data); | |
1913 | ||
673bfd45 | 1914 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1915 | *slot = type_sig; |
1916 | ||
1917 | dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu; | |
1918 | } | |
1919 | ||
673bfd45 | 1920 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1921 | |
1922 | return 1; | |
1923 | } | |
1924 | ||
9291a0cd TT |
1925 | /* Read the address map data from the mapped index, and use it to |
1926 | populate the objfile's psymtabs_addrmap. */ | |
2fdf6df6 | 1927 | |
9291a0cd TT |
1928 | static void |
1929 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1930 | { | |
1931 | const gdb_byte *iter, *end; | |
1932 | struct obstack temp_obstack; | |
1933 | struct addrmap *mutable_map; | |
1934 | struct cleanup *cleanup; | |
1935 | CORE_ADDR baseaddr; | |
1936 | ||
1937 | obstack_init (&temp_obstack); | |
1938 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1939 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1940 | ||
1941 | iter = index->address_table; | |
1942 | end = iter + index->address_table_size; | |
1943 | ||
1944 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1945 | ||
1946 | while (iter < end) | |
1947 | { | |
1948 | ULONGEST hi, lo, cu_index; | |
1949 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1950 | iter += 8; | |
1951 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1952 | iter += 8; | |
1953 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1954 | iter += 4; | |
1955 | ||
1956 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1957 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1958 | } |
1959 | ||
1960 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1961 | &objfile->objfile_obstack); | |
1962 | do_cleanups (cleanup); | |
1963 | } | |
1964 | ||
59d7bcaf JK |
1965 | /* The hash function for strings in the mapped index. This is the same as |
1966 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the | |
1967 | implementation. This is necessary because the hash function is tied to the | |
1968 | format of the mapped index file. The hash values do not have to match with | |
1969 | SYMBOL_HASH_NEXT. */ | |
2fdf6df6 | 1970 | |
9291a0cd TT |
1971 | static hashval_t |
1972 | mapped_index_string_hash (const void *p) | |
1973 | { | |
1974 | const unsigned char *str = (const unsigned char *) p; | |
1975 | hashval_t r = 0; | |
1976 | unsigned char c; | |
1977 | ||
1978 | while ((c = *str++) != 0) | |
1979 | r = r * 67 + c - 113; | |
1980 | ||
1981 | return r; | |
1982 | } | |
1983 | ||
1984 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
1985 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
1986 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
2fdf6df6 | 1987 | |
9291a0cd TT |
1988 | static int |
1989 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
1990 | offset_type **vec_out) | |
1991 | { | |
0cf03b49 JK |
1992 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
1993 | offset_type hash; | |
9291a0cd TT |
1994 | offset_type slot, step; |
1995 | ||
0cf03b49 JK |
1996 | if (current_language->la_language == language_cplus |
1997 | || current_language->la_language == language_java | |
1998 | || current_language->la_language == language_fortran) | |
1999 | { | |
2000 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does | |
2001 | not contain any. */ | |
2002 | const char *paren = strchr (name, '('); | |
2003 | ||
2004 | if (paren) | |
2005 | { | |
2006 | char *dup; | |
2007 | ||
2008 | dup = xmalloc (paren - name + 1); | |
2009 | memcpy (dup, name, paren - name); | |
2010 | dup[paren - name] = 0; | |
2011 | ||
2012 | make_cleanup (xfree, dup); | |
2013 | name = dup; | |
2014 | } | |
2015 | } | |
2016 | ||
2017 | hash = mapped_index_string_hash (name); | |
3876f04e DE |
2018 | slot = hash & (index->symbol_table_slots - 1); |
2019 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; | |
9291a0cd TT |
2020 | |
2021 | for (;;) | |
2022 | { | |
2023 | /* Convert a slot number to an offset into the table. */ | |
2024 | offset_type i = 2 * slot; | |
2025 | const char *str; | |
3876f04e | 2026 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
0cf03b49 JK |
2027 | { |
2028 | do_cleanups (back_to); | |
2029 | return 0; | |
2030 | } | |
9291a0cd | 2031 | |
3876f04e | 2032 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
9291a0cd TT |
2033 | if (!strcmp (name, str)) |
2034 | { | |
2035 | *vec_out = (offset_type *) (index->constant_pool | |
3876f04e | 2036 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
0cf03b49 | 2037 | do_cleanups (back_to); |
9291a0cd TT |
2038 | return 1; |
2039 | } | |
2040 | ||
3876f04e | 2041 | slot = (slot + step) & (index->symbol_table_slots - 1); |
9291a0cd TT |
2042 | } |
2043 | } | |
2044 | ||
2045 | /* Read the index file. If everything went ok, initialize the "quick" | |
2046 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
2fdf6df6 | 2047 | |
9291a0cd TT |
2048 | static int |
2049 | dwarf2_read_index (struct objfile *objfile) | |
2050 | { | |
9291a0cd TT |
2051 | char *addr; |
2052 | struct mapped_index *map; | |
b3b272e1 | 2053 | offset_type *metadata; |
ac0b195c KW |
2054 | const gdb_byte *cu_list; |
2055 | const gdb_byte *types_list = NULL; | |
2056 | offset_type version, cu_list_elements; | |
2057 | offset_type types_list_elements = 0; | |
1fd400ff | 2058 | int i; |
9291a0cd | 2059 | |
9e0ac564 | 2060 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
9291a0cd | 2061 | return 0; |
82430852 JK |
2062 | |
2063 | /* Older elfutils strip versions could keep the section in the main | |
2064 | executable while splitting it for the separate debug info file. */ | |
2065 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
2066 | & SEC_HAS_CONTENTS) == 0) | |
2067 | return 0; | |
2068 | ||
9291a0cd TT |
2069 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
2070 | ||
2071 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
2072 | /* Version check. */ | |
1fd400ff | 2073 | version = MAYBE_SWAP (*(offset_type *) addr); |
987d643c | 2074 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
a6e293d1 | 2075 | causes the index to behave very poorly for certain requests. Version 3 |
831adc1f JK |
2076 | contained incomplete addrmap. So, it seems better to just ignore such |
2077 | indices. */ | |
2078 | if (version < 4) | |
9291a0cd | 2079 | return 0; |
594e8718 JK |
2080 | /* Indexes with higher version than the one supported by GDB may be no |
2081 | longer backward compatible. */ | |
831adc1f | 2082 | if (version > 4) |
594e8718 | 2083 | return 0; |
9291a0cd TT |
2084 | |
2085 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
b3b272e1 | 2086 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
2087 | |
2088 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
2089 | |
2090 | i = 0; | |
2091 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
2092 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 2093 | / 8); |
1fd400ff TT |
2094 | ++i; |
2095 | ||
987d643c TT |
2096 | types_list = addr + MAYBE_SWAP (metadata[i]); |
2097 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
2098 | - MAYBE_SWAP (metadata[i])) | |
2099 | / 8); | |
2100 | ++i; | |
1fd400ff TT |
2101 | |
2102 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
2103 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
2104 | - MAYBE_SWAP (metadata[i])); | |
2105 | ++i; | |
2106 | ||
3876f04e DE |
2107 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
2108 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
2109 | - MAYBE_SWAP (metadata[i])) | |
2110 | / (2 * sizeof (offset_type))); | |
1fd400ff | 2111 | ++i; |
9291a0cd | 2112 | |
1fd400ff TT |
2113 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
2114 | ||
2115 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
2116 | return 0; | |
2117 | ||
987d643c | 2118 | if (types_list_elements |
673bfd45 DE |
2119 | && !create_signatured_type_table_from_index (objfile, types_list, |
2120 | types_list_elements)) | |
9291a0cd TT |
2121 | return 0; |
2122 | ||
2123 | create_addrmap_from_index (objfile, map); | |
2124 | ||
2125 | dwarf2_per_objfile->index_table = map; | |
2126 | dwarf2_per_objfile->using_index = 1; | |
7b9f3c50 DE |
2127 | dwarf2_per_objfile->quick_file_names_table = |
2128 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd TT |
2129 | |
2130 | return 1; | |
2131 | } | |
2132 | ||
2133 | /* A helper for the "quick" functions which sets the global | |
2134 | dwarf2_per_objfile according to OBJFILE. */ | |
2fdf6df6 | 2135 | |
9291a0cd TT |
2136 | static void |
2137 | dw2_setup (struct objfile *objfile) | |
2138 | { | |
2139 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
2140 | gdb_assert (dwarf2_per_objfile); | |
2141 | } | |
2142 | ||
2143 | /* A helper for the "quick" functions which attempts to read the line | |
2144 | table for THIS_CU. */ | |
2fdf6df6 | 2145 | |
7b9f3c50 DE |
2146 | static struct quick_file_names * |
2147 | dw2_get_file_names (struct objfile *objfile, | |
2148 | struct dwarf2_per_cu_data *this_cu) | |
9291a0cd TT |
2149 | { |
2150 | bfd *abfd = objfile->obfd; | |
7b9f3c50 | 2151 | struct line_header *lh; |
9291a0cd TT |
2152 | struct attribute *attr; |
2153 | struct cleanup *cleanups; | |
2154 | struct die_info *comp_unit_die; | |
36374493 | 2155 | struct dwarf2_section_info* sec; |
9291a0cd TT |
2156 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; |
2157 | int has_children, i; | |
2158 | struct dwarf2_cu cu; | |
2159 | unsigned int bytes_read, buffer_size; | |
2160 | struct die_reader_specs reader_specs; | |
2161 | char *name, *comp_dir; | |
7b9f3c50 DE |
2162 | void **slot; |
2163 | struct quick_file_names *qfn; | |
2164 | unsigned int line_offset; | |
9291a0cd | 2165 | |
7b9f3c50 DE |
2166 | if (this_cu->v.quick->file_names != NULL) |
2167 | return this_cu->v.quick->file_names; | |
2168 | /* If we know there is no line data, no point in looking again. */ | |
2169 | if (this_cu->v.quick->no_file_data) | |
2170 | return NULL; | |
9291a0cd | 2171 | |
9816fde3 | 2172 | init_one_comp_unit (&cu, objfile); |
9291a0cd TT |
2173 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
2174 | ||
36374493 DE |
2175 | if (this_cu->from_debug_types) |
2176 | sec = &dwarf2_per_objfile->types; | |
2177 | else | |
2178 | sec = &dwarf2_per_objfile->info; | |
2179 | dwarf2_read_section (objfile, sec); | |
2180 | buffer_size = sec->size; | |
2181 | buffer = sec->buffer; | |
9291a0cd TT |
2182 | info_ptr = buffer + this_cu->offset; |
2183 | beg_of_comp_unit = info_ptr; | |
2184 | ||
2185 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
2186 | buffer, buffer_size, | |
2187 | abfd); | |
2188 | ||
2189 | /* Complete the cu_header. */ | |
2190 | cu.header.offset = beg_of_comp_unit - buffer; | |
2191 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
2192 | ||
2193 | this_cu->cu = &cu; | |
2194 | cu.per_cu = this_cu; | |
2195 | ||
2196 | dwarf2_read_abbrevs (abfd, &cu); | |
2197 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
2198 | ||
2199 | if (this_cu->from_debug_types) | |
2200 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
2201 | init_cu_die_reader (&reader_specs, &cu); | |
e8e80198 MS |
2202 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
2203 | &has_children); | |
9291a0cd | 2204 | |
7b9f3c50 DE |
2205 | lh = NULL; |
2206 | slot = NULL; | |
2207 | line_offset = 0; | |
9291a0cd TT |
2208 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
2209 | if (attr) | |
2210 | { | |
7b9f3c50 DE |
2211 | struct quick_file_names find_entry; |
2212 | ||
2213 | line_offset = DW_UNSND (attr); | |
2214 | ||
2215 | /* We may have already read in this line header (TU line header sharing). | |
2216 | If we have we're done. */ | |
2217 | find_entry.offset = line_offset; | |
2218 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, | |
2219 | &find_entry, INSERT); | |
2220 | if (*slot != NULL) | |
2221 | { | |
2222 | do_cleanups (cleanups); | |
2223 | this_cu->v.quick->file_names = *slot; | |
2224 | return *slot; | |
2225 | } | |
2226 | ||
9291a0cd TT |
2227 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
2228 | } | |
2229 | if (lh == NULL) | |
2230 | { | |
2231 | do_cleanups (cleanups); | |
7b9f3c50 DE |
2232 | this_cu->v.quick->no_file_data = 1; |
2233 | return NULL; | |
9291a0cd TT |
2234 | } |
2235 | ||
7b9f3c50 DE |
2236 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
2237 | qfn->offset = line_offset; | |
2238 | gdb_assert (slot != NULL); | |
2239 | *slot = qfn; | |
9291a0cd | 2240 | |
7b9f3c50 | 2241 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
9291a0cd | 2242 | |
7b9f3c50 DE |
2243 | qfn->num_file_names = lh->num_file_names; |
2244 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, | |
2245 | lh->num_file_names * sizeof (char *)); | |
9291a0cd | 2246 | for (i = 0; i < lh->num_file_names; ++i) |
7b9f3c50 DE |
2247 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
2248 | qfn->real_names = NULL; | |
9291a0cd | 2249 | |
7b9f3c50 | 2250 | free_line_header (lh); |
9291a0cd | 2251 | do_cleanups (cleanups); |
7b9f3c50 DE |
2252 | |
2253 | this_cu->v.quick->file_names = qfn; | |
2254 | return qfn; | |
9291a0cd TT |
2255 | } |
2256 | ||
2257 | /* A helper for the "quick" functions which computes and caches the | |
7b9f3c50 | 2258 | real path for a given file name from the line table. */ |
2fdf6df6 | 2259 | |
9291a0cd | 2260 | static const char * |
7b9f3c50 DE |
2261 | dw2_get_real_path (struct objfile *objfile, |
2262 | struct quick_file_names *qfn, int index) | |
9291a0cd | 2263 | { |
7b9f3c50 DE |
2264 | if (qfn->real_names == NULL) |
2265 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
2266 | qfn->num_file_names, sizeof (char *)); | |
9291a0cd | 2267 | |
7b9f3c50 DE |
2268 | if (qfn->real_names[index] == NULL) |
2269 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); | |
9291a0cd | 2270 | |
7b9f3c50 | 2271 | return qfn->real_names[index]; |
9291a0cd TT |
2272 | } |
2273 | ||
2274 | static struct symtab * | |
2275 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2276 | { | |
2277 | int index; | |
ae2de4f8 | 2278 | |
9291a0cd TT |
2279 | dw2_setup (objfile); |
2280 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1fd400ff | 2281 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
9291a0cd TT |
2282 | } |
2283 | ||
7b9f3c50 DE |
2284 | /* Traversal function for dw2_forget_cached_source_info. */ |
2285 | ||
2286 | static int | |
2287 | dw2_free_cached_file_names (void **slot, void *info) | |
9291a0cd | 2288 | { |
7b9f3c50 | 2289 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
9291a0cd | 2290 | |
7b9f3c50 | 2291 | if (file_data->real_names) |
9291a0cd | 2292 | { |
7b9f3c50 | 2293 | int i; |
9291a0cd | 2294 | |
7b9f3c50 | 2295 | for (i = 0; i < file_data->num_file_names; ++i) |
9291a0cd | 2296 | { |
7b9f3c50 DE |
2297 | xfree ((void*) file_data->real_names[i]); |
2298 | file_data->real_names[i] = NULL; | |
9291a0cd TT |
2299 | } |
2300 | } | |
7b9f3c50 DE |
2301 | |
2302 | return 1; | |
2303 | } | |
2304 | ||
2305 | static void | |
2306 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2307 | { | |
2308 | dw2_setup (objfile); | |
2309 | ||
2310 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, | |
2311 | dw2_free_cached_file_names, NULL); | |
9291a0cd TT |
2312 | } |
2313 | ||
2314 | static int | |
2315 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
2316 | const char *full_path, const char *real_path, | |
2317 | struct symtab **result) | |
2318 | { | |
2319 | int i; | |
2320 | int check_basename = lbasename (name) == name; | |
2321 | struct dwarf2_per_cu_data *base_cu = NULL; | |
2322 | ||
2323 | dw2_setup (objfile); | |
ae2de4f8 | 2324 | |
1fd400ff TT |
2325 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2326 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2327 | { |
2328 | int j; | |
e254ef6a | 2329 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2330 | struct quick_file_names *file_data; |
9291a0cd | 2331 | |
e254ef6a | 2332 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2333 | continue; |
2334 | ||
7b9f3c50 DE |
2335 | file_data = dw2_get_file_names (objfile, per_cu); |
2336 | if (file_data == NULL) | |
9291a0cd TT |
2337 | continue; |
2338 | ||
7b9f3c50 | 2339 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2340 | { |
7b9f3c50 | 2341 | const char *this_name = file_data->file_names[j]; |
9291a0cd TT |
2342 | |
2343 | if (FILENAME_CMP (name, this_name) == 0) | |
2344 | { | |
e254ef6a | 2345 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2346 | return 1; |
2347 | } | |
2348 | ||
2349 | if (check_basename && ! base_cu | |
2350 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2351 | base_cu = per_cu; |
9291a0cd TT |
2352 | |
2353 | if (full_path != NULL) | |
2354 | { | |
7b9f3c50 DE |
2355 | const char *this_real_name = dw2_get_real_path (objfile, |
2356 | file_data, j); | |
9291a0cd | 2357 | |
7b9f3c50 DE |
2358 | if (this_real_name != NULL |
2359 | && FILENAME_CMP (full_path, this_real_name) == 0) | |
9291a0cd | 2360 | { |
e254ef6a | 2361 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2362 | return 1; |
2363 | } | |
2364 | } | |
2365 | ||
2366 | if (real_path != NULL) | |
2367 | { | |
7b9f3c50 DE |
2368 | const char *this_real_name = dw2_get_real_path (objfile, |
2369 | file_data, j); | |
9291a0cd | 2370 | |
7b9f3c50 DE |
2371 | if (this_real_name != NULL |
2372 | && FILENAME_CMP (real_path, this_real_name) == 0) | |
9291a0cd | 2373 | { |
74dd2ca6 DE |
2374 | *result = dw2_instantiate_symtab (objfile, per_cu); |
2375 | return 1; | |
9291a0cd TT |
2376 | } |
2377 | } | |
2378 | } | |
2379 | } | |
2380 | ||
2381 | if (base_cu) | |
2382 | { | |
2383 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2384 | return 1; | |
2385 | } | |
2386 | ||
2387 | return 0; | |
2388 | } | |
2389 | ||
2390 | static struct symtab * | |
2391 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2392 | const char *name, domain_enum domain) | |
2393 | { | |
774b6a14 | 2394 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2395 | instead. */ |
2396 | return NULL; | |
2397 | } | |
2398 | ||
2399 | /* A helper function that expands all symtabs that hold an object | |
2400 | named NAME. */ | |
2fdf6df6 | 2401 | |
9291a0cd TT |
2402 | static void |
2403 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2404 | { | |
2405 | dw2_setup (objfile); | |
2406 | ||
ae2de4f8 | 2407 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2408 | if (dwarf2_per_objfile->index_table) |
2409 | { | |
2410 | offset_type *vec; | |
2411 | ||
2412 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2413 | name, &vec)) | |
2414 | { | |
2415 | offset_type i, len = MAYBE_SWAP (*vec); | |
2416 | for (i = 0; i < len; ++i) | |
2417 | { | |
2418 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2419 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2420 | |
e254ef6a | 2421 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2422 | } |
2423 | } | |
2424 | } | |
2425 | } | |
2426 | ||
774b6a14 TT |
2427 | static void |
2428 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
8903c50d | 2429 | enum block_enum block_kind, const char *name, |
774b6a14 | 2430 | domain_enum domain) |
9291a0cd | 2431 | { |
774b6a14 | 2432 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2433 | } |
2434 | ||
2435 | static void | |
2436 | dw2_print_stats (struct objfile *objfile) | |
2437 | { | |
2438 | int i, count; | |
2439 | ||
2440 | dw2_setup (objfile); | |
2441 | count = 0; | |
1fd400ff TT |
2442 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2443 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2444 | { |
e254ef6a | 2445 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2446 | |
e254ef6a | 2447 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2448 | ++count; |
2449 | } | |
2450 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2451 | } | |
2452 | ||
2453 | static void | |
2454 | dw2_dump (struct objfile *objfile) | |
2455 | { | |
2456 | /* Nothing worth printing. */ | |
2457 | } | |
2458 | ||
2459 | static void | |
2460 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2461 | struct section_offsets *delta) | |
2462 | { | |
2463 | /* There's nothing to relocate here. */ | |
2464 | } | |
2465 | ||
2466 | static void | |
2467 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2468 | const char *func_name) | |
2469 | { | |
2470 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2471 | } | |
2472 | ||
2473 | static void | |
2474 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2475 | { | |
2476 | int i; | |
2477 | ||
2478 | dw2_setup (objfile); | |
1fd400ff TT |
2479 | |
2480 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2481 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2482 | { |
e254ef6a | 2483 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2484 | |
e254ef6a | 2485 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2486 | } |
2487 | } | |
2488 | ||
2489 | static void | |
2490 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2491 | const char *filename) | |
2492 | { | |
2493 | int i; | |
2494 | ||
2495 | dw2_setup (objfile); | |
d4637a04 DE |
2496 | |
2497 | /* We don't need to consider type units here. | |
2498 | This is only called for examining code, e.g. expand_line_sal. | |
2499 | There can be an order of magnitude (or more) more type units | |
2500 | than comp units, and we avoid them if we can. */ | |
2501 | ||
2502 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
9291a0cd TT |
2503 | { |
2504 | int j; | |
e254ef6a | 2505 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2506 | struct quick_file_names *file_data; |
9291a0cd | 2507 | |
e254ef6a | 2508 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2509 | continue; |
2510 | ||
7b9f3c50 DE |
2511 | file_data = dw2_get_file_names (objfile, per_cu); |
2512 | if (file_data == NULL) | |
9291a0cd TT |
2513 | continue; |
2514 | ||
7b9f3c50 | 2515 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2516 | { |
7b9f3c50 | 2517 | const char *this_name = file_data->file_names[j]; |
1ef75ecc | 2518 | if (FILENAME_CMP (this_name, filename) == 0) |
9291a0cd | 2519 | { |
e254ef6a | 2520 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2521 | break; |
2522 | } | |
2523 | } | |
2524 | } | |
2525 | } | |
2526 | ||
dd786858 | 2527 | static const char * |
9291a0cd TT |
2528 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2529 | { | |
e254ef6a | 2530 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd | 2531 | offset_type *vec; |
7b9f3c50 | 2532 | struct quick_file_names *file_data; |
9291a0cd TT |
2533 | |
2534 | dw2_setup (objfile); | |
2535 | ||
ae2de4f8 | 2536 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2537 | if (!dwarf2_per_objfile->index_table) |
2538 | return NULL; | |
2539 | ||
2540 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2541 | name, &vec)) | |
2542 | return NULL; | |
2543 | ||
2544 | /* Note that this just looks at the very first one named NAME -- but | |
2545 | actually we are looking for a function. find_main_filename | |
2546 | should be rewritten so that it doesn't require a custom hook. It | |
2547 | could just use the ordinary symbol tables. */ | |
2548 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2549 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2550 | |
7b9f3c50 DE |
2551 | file_data = dw2_get_file_names (objfile, per_cu); |
2552 | if (file_data == NULL) | |
9291a0cd TT |
2553 | return NULL; |
2554 | ||
7b9f3c50 | 2555 | return file_data->file_names[file_data->num_file_names - 1]; |
9291a0cd TT |
2556 | } |
2557 | ||
2558 | static void | |
40658b94 PH |
2559 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
2560 | struct objfile *objfile, int global, | |
2561 | int (*callback) (struct block *, | |
2562 | struct symbol *, void *), | |
2edb89d3 JK |
2563 | void *data, symbol_compare_ftype *match, |
2564 | symbol_compare_ftype *ordered_compare) | |
9291a0cd | 2565 | { |
40658b94 | 2566 | /* Currently unimplemented; used for Ada. The function can be called if the |
a9e6a4bb JK |
2567 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
2568 | does not look for non-Ada symbols this function should just return. */ | |
9291a0cd TT |
2569 | } |
2570 | ||
2571 | static void | |
2572 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2573 | int (*file_matcher) (const char *, void *), | |
2574 | int (*name_matcher) (const char *, void *), | |
8903c50d | 2575 | enum search_domain kind, |
9291a0cd TT |
2576 | void *data) |
2577 | { | |
2578 | int i; | |
2579 | offset_type iter; | |
4b5246aa | 2580 | struct mapped_index *index; |
9291a0cd TT |
2581 | |
2582 | dw2_setup (objfile); | |
ae2de4f8 DE |
2583 | |
2584 | /* index_table is NULL if OBJF_READNOW. */ | |
9291a0cd TT |
2585 | if (!dwarf2_per_objfile->index_table) |
2586 | return; | |
4b5246aa | 2587 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2588 | |
1fd400ff TT |
2589 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2590 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2591 | { |
2592 | int j; | |
e254ef6a | 2593 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2594 | struct quick_file_names *file_data; |
9291a0cd | 2595 | |
e254ef6a DE |
2596 | per_cu->v.quick->mark = 0; |
2597 | if (per_cu->v.quick->symtab) | |
9291a0cd TT |
2598 | continue; |
2599 | ||
7b9f3c50 DE |
2600 | file_data = dw2_get_file_names (objfile, per_cu); |
2601 | if (file_data == NULL) | |
9291a0cd TT |
2602 | continue; |
2603 | ||
7b9f3c50 | 2604 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2605 | { |
7b9f3c50 | 2606 | if (file_matcher (file_data->file_names[j], data)) |
9291a0cd | 2607 | { |
e254ef6a | 2608 | per_cu->v.quick->mark = 1; |
9291a0cd TT |
2609 | break; |
2610 | } | |
2611 | } | |
2612 | } | |
2613 | ||
3876f04e | 2614 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2615 | { |
2616 | offset_type idx = 2 * iter; | |
2617 | const char *name; | |
2618 | offset_type *vec, vec_len, vec_idx; | |
2619 | ||
3876f04e | 2620 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2621 | continue; |
2622 | ||
3876f04e | 2623 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
9291a0cd TT |
2624 | |
2625 | if (! (*name_matcher) (name, data)) | |
2626 | continue; | |
2627 | ||
2628 | /* The name was matched, now expand corresponding CUs that were | |
2629 | marked. */ | |
4b5246aa | 2630 | vec = (offset_type *) (index->constant_pool |
3876f04e | 2631 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
9291a0cd TT |
2632 | vec_len = MAYBE_SWAP (vec[0]); |
2633 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2634 | { | |
e254ef6a | 2635 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2636 | |
e254ef6a DE |
2637 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
2638 | if (per_cu->v.quick->mark) | |
2639 | dw2_instantiate_symtab (objfile, per_cu); | |
9291a0cd TT |
2640 | } |
2641 | } | |
2642 | } | |
2643 | ||
2644 | static struct symtab * | |
2645 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2646 | struct minimal_symbol *msymbol, | |
2647 | CORE_ADDR pc, | |
2648 | struct obj_section *section, | |
2649 | int warn_if_readin) | |
2650 | { | |
2651 | struct dwarf2_per_cu_data *data; | |
2652 | ||
2653 | dw2_setup (objfile); | |
2654 | ||
2655 | if (!objfile->psymtabs_addrmap) | |
2656 | return NULL; | |
2657 | ||
2658 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2659 | if (!data) | |
2660 | return NULL; | |
2661 | ||
2662 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2663 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2664 | paddress (get_objfile_arch (objfile), pc)); |
2665 | ||
2666 | return dw2_instantiate_symtab (objfile, data); | |
2667 | } | |
2668 | ||
2669 | static void | |
2670 | dw2_map_symbol_names (struct objfile *objfile, | |
2671 | void (*fun) (const char *, void *), | |
2672 | void *data) | |
2673 | { | |
2674 | offset_type iter; | |
4b5246aa TT |
2675 | struct mapped_index *index; |
2676 | ||
9291a0cd TT |
2677 | dw2_setup (objfile); |
2678 | ||
ae2de4f8 | 2679 | /* index_table is NULL if OBJF_READNOW. */ |
9291a0cd TT |
2680 | if (!dwarf2_per_objfile->index_table) |
2681 | return; | |
4b5246aa | 2682 | index = dwarf2_per_objfile->index_table; |
9291a0cd | 2683 | |
3876f04e | 2684 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
9291a0cd TT |
2685 | { |
2686 | offset_type idx = 2 * iter; | |
2687 | const char *name; | |
2688 | offset_type *vec, vec_len, vec_idx; | |
2689 | ||
3876f04e | 2690 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
9291a0cd TT |
2691 | continue; |
2692 | ||
3876f04e | 2693 | name = (index->constant_pool + MAYBE_SWAP (index->symbol_table[idx])); |
9291a0cd TT |
2694 | |
2695 | (*fun) (name, data); | |
2696 | } | |
2697 | } | |
2698 | ||
2699 | static void | |
2700 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2701 | void (*fun) (const char *, const char *, void *), | |
2702 | void *data) | |
2703 | { | |
2704 | int i; | |
2705 | ||
2706 | dw2_setup (objfile); | |
ae2de4f8 | 2707 | |
1fd400ff TT |
2708 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2709 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2710 | { |
2711 | int j; | |
e254ef6a | 2712 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
7b9f3c50 | 2713 | struct quick_file_names *file_data; |
9291a0cd | 2714 | |
e254ef6a | 2715 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2716 | continue; |
2717 | ||
7b9f3c50 DE |
2718 | file_data = dw2_get_file_names (objfile, per_cu); |
2719 | if (file_data == NULL) | |
9291a0cd TT |
2720 | continue; |
2721 | ||
7b9f3c50 | 2722 | for (j = 0; j < file_data->num_file_names; ++j) |
9291a0cd | 2723 | { |
7b9f3c50 DE |
2724 | const char *this_real_name = dw2_get_real_path (objfile, file_data, |
2725 | j); | |
2726 | (*fun) (file_data->file_names[j], this_real_name, data); | |
9291a0cd TT |
2727 | } |
2728 | } | |
2729 | } | |
2730 | ||
2731 | static int | |
2732 | dw2_has_symbols (struct objfile *objfile) | |
2733 | { | |
2734 | return 1; | |
2735 | } | |
2736 | ||
2737 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2738 | { | |
2739 | dw2_has_symbols, | |
2740 | dw2_find_last_source_symtab, | |
2741 | dw2_forget_cached_source_info, | |
2742 | dw2_lookup_symtab, | |
2743 | dw2_lookup_symbol, | |
774b6a14 | 2744 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2745 | dw2_print_stats, |
2746 | dw2_dump, | |
2747 | dw2_relocate, | |
2748 | dw2_expand_symtabs_for_function, | |
2749 | dw2_expand_all_symtabs, | |
2750 | dw2_expand_symtabs_with_filename, | |
2751 | dw2_find_symbol_file, | |
40658b94 | 2752 | dw2_map_matching_symbols, |
9291a0cd TT |
2753 | dw2_expand_symtabs_matching, |
2754 | dw2_find_pc_sect_symtab, | |
2755 | dw2_map_symbol_names, | |
2756 | dw2_map_symbol_filenames | |
2757 | }; | |
2758 | ||
2759 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2760 | file will use psymtabs, or 1 if using the GNU index. */ | |
2761 | ||
2762 | int | |
2763 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2764 | { | |
2765 | /* If we're about to read full symbols, don't bother with the | |
2766 | indices. In this case we also don't care if some other debug | |
2767 | format is making psymtabs, because they are all about to be | |
2768 | expanded anyway. */ | |
2769 | if ((objfile->flags & OBJF_READNOW)) | |
2770 | { | |
2771 | int i; | |
2772 | ||
2773 | dwarf2_per_objfile->using_index = 1; | |
2774 | create_all_comp_units (objfile); | |
1fd400ff | 2775 | create_debug_types_hash_table (objfile); |
7b9f3c50 DE |
2776 | dwarf2_per_objfile->quick_file_names_table = |
2777 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); | |
9291a0cd | 2778 | |
1fd400ff TT |
2779 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2780 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2781 | { |
e254ef6a | 2782 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2783 | |
e254ef6a DE |
2784 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2785 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2786 | } |
2787 | ||
2788 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2789 | these functions will be no-ops because we will have expanded | |
2790 | all symtabs. */ | |
2791 | return 1; | |
2792 | } | |
2793 | ||
2794 | if (dwarf2_read_index (objfile)) | |
2795 | return 1; | |
2796 | ||
9291a0cd TT |
2797 | return 0; |
2798 | } | |
2799 | ||
2800 | \f | |
2801 | ||
dce234bc PP |
2802 | /* Build a partial symbol table. */ |
2803 | ||
2804 | void | |
f29dff0a | 2805 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2806 | { |
f29dff0a | 2807 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2808 | { |
2809 | init_psymbol_list (objfile, 1024); | |
2810 | } | |
2811 | ||
d146bf1e | 2812 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2813 | } |
c906108c | 2814 | |
45452591 DE |
2815 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2816 | ||
2817 | static inline int | |
2818 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2819 | { | |
2820 | unsigned int bottom = cu_header->offset; | |
2821 | unsigned int top = (cu_header->offset | |
2822 | + cu_header->length | |
2823 | + cu_header->initial_length_size); | |
9a619af0 | 2824 | |
45452591 DE |
2825 | return (offset >= bottom && offset < top); |
2826 | } | |
2827 | ||
93311388 DE |
2828 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2829 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2830 | by the caller. */ | |
107d2387 | 2831 | |
fe1b8b76 | 2832 | static gdb_byte * |
107d2387 | 2833 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2834 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2835 | { |
2836 | int signed_addr; | |
891d2f0b | 2837 | unsigned int bytes_read; |
c764a876 DE |
2838 | |
2839 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2840 | cu_header->initial_length_size = bytes_read; | |
2841 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2842 | info_ptr += bytes_read; |
107d2387 AC |
2843 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2844 | info_ptr += 2; | |
613e1657 | 2845 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2846 | &bytes_read); |
613e1657 | 2847 | info_ptr += bytes_read; |
107d2387 AC |
2848 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2849 | info_ptr += 1; | |
2850 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2851 | if (signed_addr < 0) | |
8e65ff28 | 2852 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2853 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2854 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2855 | |
107d2387 AC |
2856 | return info_ptr; |
2857 | } | |
2858 | ||
fe1b8b76 JB |
2859 | static gdb_byte * |
2860 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2861 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2862 | bfd *abfd) |
2863 | { | |
fe1b8b76 | 2864 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2865 | |
2866 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2867 | ||
2dc7f7b3 | 2868 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2869 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2870 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2871 | bfd_get_filename (abfd)); | |
72bf9492 | 2872 | |
9e0ac564 TT |
2873 | if (header->abbrev_offset |
2874 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, | |
2875 | &dwarf2_per_objfile->abbrev)) | |
8a3fe4f8 AC |
2876 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2877 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2878 | (long) header->abbrev_offset, |
93311388 | 2879 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2880 | bfd_get_filename (abfd)); |
2881 | ||
2882 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2883 | > buffer + buffer_size) |
8a3fe4f8 AC |
2884 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2885 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2886 | (long) header->length, |
93311388 | 2887 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2888 | bfd_get_filename (abfd)); |
2889 | ||
2890 | return info_ptr; | |
2891 | } | |
2892 | ||
348e048f DE |
2893 | /* Read in the types comp unit header information from .debug_types entry at |
2894 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2895 | ||
2896 | static gdb_byte * | |
2897 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2898 | ULONGEST *signature, | |
2899 | gdb_byte *types_ptr, bfd *abfd) | |
2900 | { | |
348e048f DE |
2901 | gdb_byte *initial_types_ptr = types_ptr; |
2902 | ||
6e70227d | 2903 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2904 | &dwarf2_per_objfile->types); |
348e048f DE |
2905 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2906 | ||
2907 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2908 | ||
2909 | *signature = read_8_bytes (abfd, types_ptr); | |
2910 | types_ptr += 8; | |
2911 | types_ptr += cu_header->offset_size; | |
2912 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2913 | ||
2914 | return types_ptr; | |
2915 | } | |
2916 | ||
aaa75496 JB |
2917 | /* Allocate a new partial symtab for file named NAME and mark this new |
2918 | partial symtab as being an include of PST. */ | |
2919 | ||
2920 | static void | |
2921 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2922 | struct objfile *objfile) | |
2923 | { | |
2924 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2925 | ||
2926 | subpst->section_offsets = pst->section_offsets; | |
2927 | subpst->textlow = 0; | |
2928 | subpst->texthigh = 0; | |
2929 | ||
2930 | subpst->dependencies = (struct partial_symtab **) | |
2931 | obstack_alloc (&objfile->objfile_obstack, | |
2932 | sizeof (struct partial_symtab *)); | |
2933 | subpst->dependencies[0] = pst; | |
2934 | subpst->number_of_dependencies = 1; | |
2935 | ||
2936 | subpst->globals_offset = 0; | |
2937 | subpst->n_global_syms = 0; | |
2938 | subpst->statics_offset = 0; | |
2939 | subpst->n_static_syms = 0; | |
2940 | subpst->symtab = NULL; | |
2941 | subpst->read_symtab = pst->read_symtab; | |
2942 | subpst->readin = 0; | |
2943 | ||
2944 | /* No private part is necessary for include psymtabs. This property | |
2945 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2946 | the regular ones. */ |
58a9656e | 2947 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2948 | } |
2949 | ||
2950 | /* Read the Line Number Program data and extract the list of files | |
2951 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2952 | partial symtab for each of these included files. */ |
aaa75496 JB |
2953 | |
2954 | static void | |
2955 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2956 | struct die_info *die, |
aaa75496 JB |
2957 | struct partial_symtab *pst) |
2958 | { | |
2959 | struct objfile *objfile = cu->objfile; | |
2960 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2961 | struct line_header *lh = NULL; |
2962 | struct attribute *attr; | |
aaa75496 | 2963 | |
d85a05f0 DJ |
2964 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2965 | if (attr) | |
2966 | { | |
2967 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2968 | |
d85a05f0 DJ |
2969 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2970 | } | |
aaa75496 JB |
2971 | if (lh == NULL) |
2972 | return; /* No linetable, so no includes. */ | |
2973 | ||
c6da4cef DE |
2974 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
2975 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
2976 | |
2977 | free_line_header (lh); | |
2978 | } | |
2979 | ||
348e048f DE |
2980 | static hashval_t |
2981 | hash_type_signature (const void *item) | |
2982 | { | |
2983 | const struct signatured_type *type_sig = item; | |
9a619af0 | 2984 | |
348e048f DE |
2985 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
2986 | return type_sig->signature; | |
2987 | } | |
2988 | ||
2989 | static int | |
2990 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
2991 | { | |
2992 | const struct signatured_type *lhs = item_lhs; | |
2993 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 2994 | |
348e048f DE |
2995 | return lhs->signature == rhs->signature; |
2996 | } | |
2997 | ||
1fd400ff TT |
2998 | /* Allocate a hash table for signatured types. */ |
2999 | ||
3000 | static htab_t | |
673bfd45 | 3001 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
3002 | { |
3003 | return htab_create_alloc_ex (41, | |
3004 | hash_type_signature, | |
3005 | eq_type_signature, | |
3006 | NULL, | |
3007 | &objfile->objfile_obstack, | |
3008 | hashtab_obstack_allocate, | |
3009 | dummy_obstack_deallocate); | |
3010 | } | |
3011 | ||
3012 | /* A helper function to add a signatured type CU to a list. */ | |
3013 | ||
3014 | static int | |
3015 | add_signatured_type_cu_to_list (void **slot, void *datum) | |
3016 | { | |
3017 | struct signatured_type *sigt = *slot; | |
3018 | struct dwarf2_per_cu_data ***datap = datum; | |
3019 | ||
3020 | **datap = &sigt->per_cu; | |
3021 | ++*datap; | |
3022 | ||
3023 | return 1; | |
3024 | } | |
3025 | ||
348e048f DE |
3026 | /* Create the hash table of all entries in the .debug_types section. |
3027 | The result is zero if there is an error (e.g. missing .debug_types section), | |
3028 | otherwise non-zero. */ | |
3029 | ||
3030 | static int | |
3031 | create_debug_types_hash_table (struct objfile *objfile) | |
3032 | { | |
be391dca | 3033 | gdb_byte *info_ptr; |
348e048f | 3034 | htab_t types_htab; |
1fd400ff | 3035 | struct dwarf2_per_cu_data **iter; |
348e048f | 3036 | |
be391dca TT |
3037 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
3038 | info_ptr = dwarf2_per_objfile->types.buffer; | |
3039 | ||
348e048f DE |
3040 | if (info_ptr == NULL) |
3041 | { | |
3042 | dwarf2_per_objfile->signatured_types = NULL; | |
3043 | return 0; | |
3044 | } | |
3045 | ||
673bfd45 | 3046 | types_htab = allocate_signatured_type_table (objfile); |
348e048f DE |
3047 | |
3048 | if (dwarf2_die_debug) | |
3049 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
3050 | ||
3e43a32a MS |
3051 | while (info_ptr < dwarf2_per_objfile->types.buffer |
3052 | + dwarf2_per_objfile->types.size) | |
348e048f DE |
3053 | { |
3054 | unsigned int offset; | |
3055 | unsigned int offset_size; | |
3056 | unsigned int type_offset; | |
3057 | unsigned int length, initial_length_size; | |
3058 | unsigned short version; | |
3059 | ULONGEST signature; | |
3060 | struct signatured_type *type_sig; | |
3061 | void **slot; | |
3062 | gdb_byte *ptr = info_ptr; | |
3063 | ||
3064 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
3065 | ||
3066 | /* We need to read the type's signature in order to build the hash | |
3067 | table, but we don't need to read anything else just yet. */ | |
3068 | ||
3069 | /* Sanity check to ensure entire cu is present. */ | |
3070 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
3071 | if (ptr + length + initial_length_size | |
3072 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
3073 | { | |
3074 | complaint (&symfile_complaints, | |
3e43a32a MS |
3075 | _("debug type entry runs off end " |
3076 | "of `.debug_types' section, ignored")); | |
348e048f DE |
3077 | break; |
3078 | } | |
3079 | ||
3080 | offset_size = initial_length_size == 4 ? 4 : 8; | |
3081 | ptr += initial_length_size; | |
3082 | version = bfd_get_16 (objfile->obfd, ptr); | |
3083 | ptr += 2; | |
3084 | ptr += offset_size; /* abbrev offset */ | |
3085 | ptr += 1; /* address size */ | |
3086 | signature = bfd_get_64 (objfile->obfd, ptr); | |
3087 | ptr += 8; | |
3088 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
3089 | ||
3090 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
3091 | memset (type_sig, 0, sizeof (*type_sig)); | |
3092 | type_sig->signature = signature; | |
3093 | type_sig->offset = offset; | |
3094 | type_sig->type_offset = type_offset; | |
ca1f3406 | 3095 | type_sig->per_cu.objfile = objfile; |
1fd400ff | 3096 | type_sig->per_cu.from_debug_types = 1; |
348e048f DE |
3097 | |
3098 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
3099 | gdb_assert (slot != NULL); | |
3100 | *slot = type_sig; | |
3101 | ||
3102 | if (dwarf2_die_debug) | |
3103 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
3104 | offset, phex (signature, sizeof (signature))); | |
3105 | ||
3106 | info_ptr = info_ptr + initial_length_size + length; | |
3107 | } | |
3108 | ||
3109 | dwarf2_per_objfile->signatured_types = types_htab; | |
3110 | ||
1fd400ff TT |
3111 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
3112 | dwarf2_per_objfile->type_comp_units | |
3113 | = obstack_alloc (&objfile->objfile_obstack, | |
3114 | dwarf2_per_objfile->n_type_comp_units | |
3115 | * sizeof (struct dwarf2_per_cu_data *)); | |
3116 | iter = &dwarf2_per_objfile->type_comp_units[0]; | |
3117 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); | |
3118 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] | |
3119 | == dwarf2_per_objfile->n_type_comp_units); | |
3120 | ||
348e048f DE |
3121 | return 1; |
3122 | } | |
3123 | ||
3124 | /* Lookup a signature based type. | |
3125 | Returns NULL if SIG is not present in the table. */ | |
3126 | ||
3127 | static struct signatured_type * | |
3128 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
3129 | { | |
3130 | struct signatured_type find_entry, *entry; | |
3131 | ||
3132 | if (dwarf2_per_objfile->signatured_types == NULL) | |
3133 | { | |
3134 | complaint (&symfile_complaints, | |
55f1336d | 3135 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
348e048f DE |
3136 | return 0; |
3137 | } | |
3138 | ||
3139 | find_entry.signature = sig; | |
3140 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
3141 | return entry; | |
3142 | } | |
3143 | ||
d85a05f0 DJ |
3144 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
3145 | ||
3146 | static void | |
3147 | init_cu_die_reader (struct die_reader_specs *reader, | |
3148 | struct dwarf2_cu *cu) | |
3149 | { | |
3150 | reader->abfd = cu->objfile->obfd; | |
3151 | reader->cu = cu; | |
3152 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
3153 | { |
3154 | gdb_assert (dwarf2_per_objfile->types.readin); | |
3155 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
3156 | } | |
d85a05f0 | 3157 | else |
be391dca TT |
3158 | { |
3159 | gdb_assert (dwarf2_per_objfile->info.readin); | |
3160 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
3161 | } | |
d85a05f0 DJ |
3162 | } |
3163 | ||
3164 | /* Find the base address of the compilation unit for range lists and | |
3165 | location lists. It will normally be specified by DW_AT_low_pc. | |
3166 | In DWARF-3 draft 4, the base address could be overridden by | |
3167 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
3168 | compilation units with discontinuous ranges. */ | |
3169 | ||
3170 | static void | |
3171 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
3172 | { | |
3173 | struct attribute *attr; | |
3174 | ||
3175 | cu->base_known = 0; | |
3176 | cu->base_address = 0; | |
3177 | ||
3178 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
3179 | if (attr) | |
3180 | { | |
3181 | cu->base_address = DW_ADDR (attr); | |
3182 | cu->base_known = 1; | |
3183 | } | |
3184 | else | |
3185 | { | |
3186 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3187 | if (attr) | |
3188 | { | |
3189 | cu->base_address = DW_ADDR (attr); | |
3190 | cu->base_known = 1; | |
3191 | } | |
3192 | } | |
3193 | } | |
3194 | ||
348e048f DE |
3195 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
3196 | to combine the common parts. | |
93311388 | 3197 | Process a compilation unit for a psymtab. |
348e048f DE |
3198 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
3199 | either .debug_info or debug_types. | |
93311388 DE |
3200 | INFO_PTR is a pointer to the start of the CU. |
3201 | Returns a pointer to the next CU. */ | |
aaa75496 | 3202 | |
93311388 DE |
3203 | static gdb_byte * |
3204 | process_psymtab_comp_unit (struct objfile *objfile, | |
3205 | struct dwarf2_per_cu_data *this_cu, | |
3206 | gdb_byte *buffer, gdb_byte *info_ptr, | |
3207 | unsigned int buffer_size) | |
c906108c | 3208 | { |
c906108c | 3209 | bfd *abfd = objfile->obfd; |
93311388 | 3210 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3211 | struct die_info *comp_unit_die; |
c906108c | 3212 | struct partial_symtab *pst; |
5734ee8b | 3213 | CORE_ADDR baseaddr; |
93311388 DE |
3214 | struct cleanup *back_to_inner; |
3215 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3216 | int has_children, has_pc_info; |
3217 | struct attribute *attr; | |
d85a05f0 DJ |
3218 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3219 | struct die_reader_specs reader_specs; | |
3e2a0cee | 3220 | const char *filename; |
c906108c | 3221 | |
9816fde3 | 3222 | init_one_comp_unit (&cu, objfile); |
93311388 | 3223 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3224 | |
93311388 DE |
3225 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
3226 | buffer, buffer_size, | |
3227 | abfd); | |
10b3939b | 3228 | |
93311388 DE |
3229 | /* Complete the cu_header. */ |
3230 | cu.header.offset = beg_of_comp_unit - buffer; | |
3231 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 3232 | |
93311388 | 3233 | cu.list_in_scope = &file_symbols; |
af703f96 | 3234 | |
328c9494 DJ |
3235 | /* If this compilation unit was already read in, free the |
3236 | cached copy in order to read it in again. This is | |
3237 | necessary because we skipped some symbols when we first | |
3238 | read in the compilation unit (see load_partial_dies). | |
3239 | This problem could be avoided, but the benefit is | |
3240 | unclear. */ | |
3241 | if (this_cu->cu != NULL) | |
3242 | free_one_cached_comp_unit (this_cu->cu); | |
3243 | ||
3244 | /* Note that this is a pointer to our stack frame, being | |
3245 | added to a global data structure. It will be cleaned up | |
3246 | in free_stack_comp_unit when we finish with this | |
3247 | compilation unit. */ | |
3248 | this_cu->cu = &cu; | |
d85a05f0 DJ |
3249 | cu.per_cu = this_cu; |
3250 | ||
93311388 DE |
3251 | /* Read the abbrevs for this compilation unit into a table. */ |
3252 | dwarf2_read_abbrevs (abfd, &cu); | |
3253 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 3254 | |
93311388 | 3255 | /* Read the compilation unit die. */ |
348e048f DE |
3256 | if (this_cu->from_debug_types) |
3257 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
3258 | init_cu_die_reader (&reader_specs, &cu); |
3259 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3260 | &has_children); | |
93311388 | 3261 | |
348e048f DE |
3262 | if (this_cu->from_debug_types) |
3263 | { | |
3264 | /* offset,length haven't been set yet for type units. */ | |
3265 | this_cu->offset = cu.header.offset; | |
3266 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
3267 | } | |
d85a05f0 | 3268 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3269 | { |
93311388 DE |
3270 | info_ptr = (beg_of_comp_unit + cu.header.length |
3271 | + cu.header.initial_length_size); | |
3272 | do_cleanups (back_to_inner); | |
3273 | return info_ptr; | |
3274 | } | |
72bf9492 | 3275 | |
9816fde3 | 3276 | prepare_one_comp_unit (&cu, comp_unit_die); |
c906108c | 3277 | |
93311388 | 3278 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3279 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
3e2a0cee TT |
3280 | if (attr == NULL || !DW_STRING (attr)) |
3281 | filename = ""; | |
3282 | else | |
3283 | filename = DW_STRING (attr); | |
93311388 | 3284 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
3e2a0cee | 3285 | filename, |
93311388 DE |
3286 | /* TEXTLOW and TEXTHIGH are set below. */ |
3287 | 0, | |
3288 | objfile->global_psymbols.next, | |
3289 | objfile->static_psymbols.next); | |
72bf9492 | 3290 | |
d85a05f0 DJ |
3291 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3292 | if (attr != NULL) | |
3293 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3294 | |
e38df1d0 | 3295 | pst->read_symtab_private = this_cu; |
72bf9492 | 3296 | |
93311388 | 3297 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3298 | |
0963b4bd | 3299 | /* Store the function that reads in the rest of the symbol table. */ |
93311388 | 3300 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
57349743 | 3301 | |
9291a0cd | 3302 | this_cu->v.psymtab = pst; |
c906108c | 3303 | |
d85a05f0 DJ |
3304 | dwarf2_find_base_address (comp_unit_die, &cu); |
3305 | ||
93311388 DE |
3306 | /* Possibly set the default values of LOWPC and HIGHPC from |
3307 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3308 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3309 | &best_highpc, &cu, pst); | |
3310 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3311 | /* Store the contiguous range if it is not empty; it can be empty for |
3312 | CUs with no code. */ | |
3313 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3314 | best_lowpc + baseaddr, |
3315 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3316 | |
3317 | /* Check if comp unit has_children. | |
3318 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3319 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3320 | if (has_children) |
93311388 DE |
3321 | { |
3322 | struct partial_die_info *first_die; | |
3323 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3324 | |
93311388 DE |
3325 | lowpc = ((CORE_ADDR) -1); |
3326 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3327 | |
93311388 | 3328 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3329 | |
93311388 | 3330 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3331 | ! has_pc_info, &cu); |
57c22c6c | 3332 | |
93311388 DE |
3333 | /* If we didn't find a lowpc, set it to highpc to avoid |
3334 | complaints from `maint check'. */ | |
3335 | if (lowpc == ((CORE_ADDR) -1)) | |
3336 | lowpc = highpc; | |
10b3939b | 3337 | |
93311388 DE |
3338 | /* If the compilation unit didn't have an explicit address range, |
3339 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3340 | if (! has_pc_info) |
93311388 | 3341 | { |
d85a05f0 DJ |
3342 | best_lowpc = lowpc; |
3343 | best_highpc = highpc; | |
93311388 DE |
3344 | } |
3345 | } | |
d85a05f0 DJ |
3346 | pst->textlow = best_lowpc + baseaddr; |
3347 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3348 | |
93311388 DE |
3349 | pst->n_global_syms = objfile->global_psymbols.next - |
3350 | (objfile->global_psymbols.list + pst->globals_offset); | |
3351 | pst->n_static_syms = objfile->static_psymbols.next - | |
3352 | (objfile->static_psymbols.list + pst->statics_offset); | |
3353 | sort_pst_symbols (pst); | |
c906108c | 3354 | |
93311388 DE |
3355 | info_ptr = (beg_of_comp_unit + cu.header.length |
3356 | + cu.header.initial_length_size); | |
ae038cb0 | 3357 | |
348e048f DE |
3358 | if (this_cu->from_debug_types) |
3359 | { | |
3360 | /* It's not clear we want to do anything with stmt lists here. | |
3361 | Waiting to see what gcc ultimately does. */ | |
3362 | } | |
d85a05f0 | 3363 | else |
93311388 DE |
3364 | { |
3365 | /* Get the list of files included in the current compilation unit, | |
3366 | and build a psymtab for each of them. */ | |
d85a05f0 | 3367 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3368 | } |
ae038cb0 | 3369 | |
93311388 | 3370 | do_cleanups (back_to_inner); |
ae038cb0 | 3371 | |
93311388 DE |
3372 | return info_ptr; |
3373 | } | |
ff013f42 | 3374 | |
348e048f DE |
3375 | /* Traversal function for htab_traverse_noresize. |
3376 | Process one .debug_types comp-unit. */ | |
3377 | ||
3378 | static int | |
3379 | process_type_comp_unit (void **slot, void *info) | |
3380 | { | |
3381 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
3382 | struct objfile *objfile = (struct objfile *) info; | |
3383 | struct dwarf2_per_cu_data *this_cu; | |
3384 | ||
3385 | this_cu = &entry->per_cu; | |
348e048f | 3386 | |
be391dca | 3387 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
3388 | process_psymtab_comp_unit (objfile, this_cu, |
3389 | dwarf2_per_objfile->types.buffer, | |
3390 | dwarf2_per_objfile->types.buffer + entry->offset, | |
3391 | dwarf2_per_objfile->types.size); | |
3392 | ||
3393 | return 1; | |
3394 | } | |
3395 | ||
3396 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3397 | Build partial symbol tables for the .debug_types comp-units. */ | |
3398 | ||
3399 | static void | |
3400 | build_type_psymtabs (struct objfile *objfile) | |
3401 | { | |
3402 | if (! create_debug_types_hash_table (objfile)) | |
3403 | return; | |
3404 | ||
3405 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
3406 | process_type_comp_unit, objfile); | |
3407 | } | |
3408 | ||
60606b2c TT |
3409 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3410 | ||
3411 | static void | |
3412 | psymtabs_addrmap_cleanup (void *o) | |
3413 | { | |
3414 | struct objfile *objfile = o; | |
ec61707d | 3415 | |
60606b2c TT |
3416 | objfile->psymtabs_addrmap = NULL; |
3417 | } | |
3418 | ||
93311388 DE |
3419 | /* Build the partial symbol table by doing a quick pass through the |
3420 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3421 | |
93311388 | 3422 | static void |
c67a9c90 | 3423 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3424 | { |
93311388 | 3425 | gdb_byte *info_ptr; |
60606b2c TT |
3426 | struct cleanup *back_to, *addrmap_cleanup; |
3427 | struct obstack temp_obstack; | |
93311388 | 3428 | |
98bfdba5 PA |
3429 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3430 | ||
be391dca | 3431 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3432 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3433 | |
93311388 DE |
3434 | /* Any cached compilation units will be linked by the per-objfile |
3435 | read_in_chain. Make sure to free them when we're done. */ | |
3436 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3437 | |
348e048f DE |
3438 | build_type_psymtabs (objfile); |
3439 | ||
93311388 | 3440 | create_all_comp_units (objfile); |
c906108c | 3441 | |
60606b2c TT |
3442 | /* Create a temporary address map on a temporary obstack. We later |
3443 | copy this to the final obstack. */ | |
3444 | obstack_init (&temp_obstack); | |
3445 | make_cleanup_obstack_free (&temp_obstack); | |
3446 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3447 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3448 | |
93311388 DE |
3449 | /* Since the objects we're extracting from .debug_info vary in |
3450 | length, only the individual functions to extract them (like | |
3451 | read_comp_unit_head and load_partial_die) can really know whether | |
3452 | the buffer is large enough to hold another complete object. | |
c906108c | 3453 | |
93311388 DE |
3454 | At the moment, they don't actually check that. If .debug_info |
3455 | holds just one extra byte after the last compilation unit's dies, | |
3456 | then read_comp_unit_head will happily read off the end of the | |
3457 | buffer. read_partial_die is similarly casual. Those functions | |
3458 | should be fixed. | |
c906108c | 3459 | |
93311388 DE |
3460 | For this loop condition, simply checking whether there's any data |
3461 | left at all should be sufficient. */ | |
c906108c | 3462 | |
93311388 DE |
3463 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3464 | + dwarf2_per_objfile->info.size)) | |
3465 | { | |
3466 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3467 | |
3e43a32a MS |
3468 | this_cu = dwarf2_find_comp_unit (info_ptr |
3469 | - dwarf2_per_objfile->info.buffer, | |
93311388 | 3470 | objfile); |
aaa75496 | 3471 | |
93311388 DE |
3472 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3473 | dwarf2_per_objfile->info.buffer, | |
3474 | info_ptr, | |
3475 | dwarf2_per_objfile->info.size); | |
c906108c | 3476 | } |
ff013f42 JK |
3477 | |
3478 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3479 | &objfile->objfile_obstack); | |
60606b2c | 3480 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3481 | |
ae038cb0 DJ |
3482 | do_cleanups (back_to); |
3483 | } | |
3484 | ||
93311388 | 3485 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3486 | |
3487 | static void | |
93311388 DE |
3488 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3489 | struct objfile *objfile) | |
ae038cb0 DJ |
3490 | { |
3491 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3492 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3493 | struct die_info *comp_unit_die; |
ae038cb0 | 3494 | struct dwarf2_cu *cu; |
1d9ec526 | 3495 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3496 | int has_children; |
3497 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3498 | int read_cu = 0; |
ae038cb0 | 3499 | |
348e048f DE |
3500 | gdb_assert (! this_cu->from_debug_types); |
3501 | ||
be391dca | 3502 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3503 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3504 | beg_of_comp_unit = info_ptr; |
3505 | ||
98bfdba5 PA |
3506 | if (this_cu->cu == NULL) |
3507 | { | |
9816fde3 JK |
3508 | cu = xmalloc (sizeof (*cu)); |
3509 | init_one_comp_unit (cu, objfile); | |
ae038cb0 | 3510 | |
98bfdba5 | 3511 | read_cu = 1; |
ae038cb0 | 3512 | |
98bfdba5 PA |
3513 | /* If an error occurs while loading, release our storage. */ |
3514 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
328c9494 | 3515 | |
98bfdba5 PA |
3516 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3517 | dwarf2_per_objfile->info.buffer, | |
3518 | dwarf2_per_objfile->info.size, | |
3519 | abfd); | |
ae038cb0 | 3520 | |
98bfdba5 PA |
3521 | /* Complete the cu_header. */ |
3522 | cu->header.offset = this_cu->offset; | |
3523 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3524 | ||
3525 | /* Link this compilation unit into the compilation unit tree. */ | |
3526 | this_cu->cu = cu; | |
3527 | cu->per_cu = this_cu; | |
98bfdba5 PA |
3528 | |
3529 | /* Link this CU into read_in_chain. */ | |
3530 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3531 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3532 | } | |
3533 | else | |
3534 | { | |
3535 | cu = this_cu->cu; | |
3536 | info_ptr += cu->header.first_die_offset; | |
3537 | } | |
ae038cb0 DJ |
3538 | |
3539 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3540 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
ae038cb0 | 3541 | dwarf2_read_abbrevs (abfd, cu); |
98bfdba5 | 3542 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3543 | |
3544 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3545 | init_cu_die_reader (&reader_specs, cu); |
3546 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3547 | &has_children); | |
ae038cb0 | 3548 | |
9816fde3 | 3549 | prepare_one_comp_unit (cu, comp_unit_die); |
ae038cb0 | 3550 | |
ae038cb0 DJ |
3551 | /* Check if comp unit has_children. |
3552 | If so, read the rest of the partial symbols from this comp unit. | |
0963b4bd | 3553 | If not, there's no more debug_info for this comp unit. */ |
d85a05f0 | 3554 | if (has_children) |
93311388 | 3555 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 | 3556 | |
98bfdba5 PA |
3557 | do_cleanups (free_abbrevs_cleanup); |
3558 | ||
3559 | if (read_cu) | |
3560 | { | |
3561 | /* We've successfully allocated this compilation unit. Let our | |
3562 | caller clean it up when finished with it. */ | |
3563 | discard_cleanups (free_cu_cleanup); | |
3564 | } | |
ae038cb0 DJ |
3565 | } |
3566 | ||
3567 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3568 | if an inter-comp-unit reference is found; presumably if there is one, | |
3569 | there will be many, and one will occur early in the .debug_info section. | |
3570 | So there's no point in building this list incrementally. */ | |
3571 | ||
3572 | static void | |
3573 | create_all_comp_units (struct objfile *objfile) | |
3574 | { | |
3575 | int n_allocated; | |
3576 | int n_comp_units; | |
3577 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3578 | gdb_byte *info_ptr; |
3579 | ||
3580 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3581 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3582 | |
3583 | n_comp_units = 0; | |
3584 | n_allocated = 10; | |
3585 | all_comp_units = xmalloc (n_allocated | |
3586 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3587 | |
3e43a32a MS |
3588 | while (info_ptr < dwarf2_per_objfile->info.buffer |
3589 | + dwarf2_per_objfile->info.size) | |
ae038cb0 | 3590 | { |
c764a876 | 3591 | unsigned int length, initial_length_size; |
ae038cb0 | 3592 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3593 | unsigned int offset; |
ae038cb0 | 3594 | |
dce234bc | 3595 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3596 | |
3597 | /* Read just enough information to find out where the next | |
3598 | compilation unit is. */ | |
c764a876 DE |
3599 | length = read_initial_length (objfile->obfd, info_ptr, |
3600 | &initial_length_size); | |
ae038cb0 DJ |
3601 | |
3602 | /* Save the compilation unit for later lookup. */ | |
3603 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3604 | sizeof (struct dwarf2_per_cu_data)); | |
3605 | memset (this_cu, 0, sizeof (*this_cu)); | |
3606 | this_cu->offset = offset; | |
c764a876 | 3607 | this_cu->length = length + initial_length_size; |
9291a0cd | 3608 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3609 | |
3610 | if (n_comp_units == n_allocated) | |
3611 | { | |
3612 | n_allocated *= 2; | |
3613 | all_comp_units = xrealloc (all_comp_units, | |
3614 | n_allocated | |
3615 | * sizeof (struct dwarf2_per_cu_data *)); | |
3616 | } | |
3617 | all_comp_units[n_comp_units++] = this_cu; | |
3618 | ||
3619 | info_ptr = info_ptr + this_cu->length; | |
3620 | } | |
3621 | ||
3622 | dwarf2_per_objfile->all_comp_units | |
3623 | = obstack_alloc (&objfile->objfile_obstack, | |
3624 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3625 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3626 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3627 | xfree (all_comp_units); | |
3628 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3629 | } |
3630 | ||
5734ee8b DJ |
3631 | /* Process all loaded DIEs for compilation unit CU, starting at |
3632 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3633 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3634 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3635 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3636 | and record the covered ranges in the addrmap. */ | |
c906108c | 3637 | |
72bf9492 DJ |
3638 | static void |
3639 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3640 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3641 | { |
72bf9492 | 3642 | struct partial_die_info *pdi; |
c906108c | 3643 | |
91c24f0a DC |
3644 | /* Now, march along the PDI's, descending into ones which have |
3645 | interesting children but skipping the children of the other ones, | |
3646 | until we reach the end of the compilation unit. */ | |
c906108c | 3647 | |
72bf9492 | 3648 | pdi = first_die; |
91c24f0a | 3649 | |
72bf9492 DJ |
3650 | while (pdi != NULL) |
3651 | { | |
3652 | fixup_partial_die (pdi, cu); | |
c906108c | 3653 | |
f55ee35c | 3654 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3655 | children, so we need to look at them. Ditto for anonymous |
3656 | enums. */ | |
933c6fe4 | 3657 | |
72bf9492 | 3658 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3659 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3660 | { |
72bf9492 | 3661 | switch (pdi->tag) |
c906108c SS |
3662 | { |
3663 | case DW_TAG_subprogram: | |
5734ee8b | 3664 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c | 3665 | break; |
72929c62 | 3666 | case DW_TAG_constant: |
c906108c SS |
3667 | case DW_TAG_variable: |
3668 | case DW_TAG_typedef: | |
91c24f0a | 3669 | case DW_TAG_union_type: |
72bf9492 | 3670 | if (!pdi->is_declaration) |
63d06c5c | 3671 | { |
72bf9492 | 3672 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3673 | } |
3674 | break; | |
c906108c | 3675 | case DW_TAG_class_type: |
680b30c7 | 3676 | case DW_TAG_interface_type: |
c906108c | 3677 | case DW_TAG_structure_type: |
72bf9492 | 3678 | if (!pdi->is_declaration) |
c906108c | 3679 | { |
72bf9492 | 3680 | add_partial_symbol (pdi, cu); |
c906108c SS |
3681 | } |
3682 | break; | |
91c24f0a | 3683 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3684 | if (!pdi->is_declaration) |
3685 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3686 | break; |
3687 | case DW_TAG_base_type: | |
a02abb62 | 3688 | case DW_TAG_subrange_type: |
c906108c | 3689 | /* File scope base type definitions are added to the partial |
c5aa993b | 3690 | symbol table. */ |
72bf9492 | 3691 | add_partial_symbol (pdi, cu); |
c906108c | 3692 | break; |
d9fa45fe | 3693 | case DW_TAG_namespace: |
5734ee8b | 3694 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3695 | break; |
5d7cb8df JK |
3696 | case DW_TAG_module: |
3697 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3698 | break; | |
c906108c SS |
3699 | default: |
3700 | break; | |
3701 | } | |
3702 | } | |
3703 | ||
72bf9492 DJ |
3704 | /* If the die has a sibling, skip to the sibling. */ |
3705 | ||
3706 | pdi = pdi->die_sibling; | |
3707 | } | |
3708 | } | |
3709 | ||
3710 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3711 | |
72bf9492 | 3712 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3713 | name is concatenated with "::" and the partial DIE's name. For |
3714 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3715 | Enumerators are an exception; they use the scope of their parent |
3716 | enumeration type, i.e. the name of the enumeration type is not | |
3717 | prepended to the enumerator. | |
91c24f0a | 3718 | |
72bf9492 DJ |
3719 | There are two complexities. One is DW_AT_specification; in this |
3720 | case "parent" means the parent of the target of the specification, | |
3721 | instead of the direct parent of the DIE. The other is compilers | |
3722 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3723 | the fully qualified name of structure types from their members' | |
3724 | linkage names. This must be done using the DIE's children rather | |
3725 | than the children of any DW_AT_specification target. We only need | |
3726 | to do this for structures at the top level, i.e. if the target of | |
3727 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3728 | have a parent. */ | |
3729 | ||
3730 | /* Compute the scope prefix associated with PDI's parent, in | |
3731 | compilation unit CU. The result will be allocated on CU's | |
3732 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3733 | field. NULL is returned if no prefix is necessary. */ | |
3734 | static char * | |
3735 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3736 | struct dwarf2_cu *cu) | |
3737 | { | |
3738 | char *grandparent_scope; | |
3739 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3740 | |
72bf9492 DJ |
3741 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3742 | then this means the parent of the specification DIE. */ | |
3743 | ||
3744 | real_pdi = pdi; | |
72bf9492 | 3745 | while (real_pdi->has_specification) |
10b3939b | 3746 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3747 | |
3748 | parent = real_pdi->die_parent; | |
3749 | if (parent == NULL) | |
3750 | return NULL; | |
3751 | ||
3752 | if (parent->scope_set) | |
3753 | return parent->scope; | |
3754 | ||
3755 | fixup_partial_die (parent, cu); | |
3756 | ||
10b3939b | 3757 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3758 | |
acebe513 UW |
3759 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3760 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3761 | Work around this problem here. */ | |
3762 | if (cu->language == language_cplus | |
6e70227d | 3763 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3764 | && strcmp (parent->name, "::") == 0 |
3765 | && grandparent_scope == NULL) | |
3766 | { | |
3767 | parent->scope = NULL; | |
3768 | parent->scope_set = 1; | |
3769 | return NULL; | |
3770 | } | |
3771 | ||
72bf9492 | 3772 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3773 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3774 | || parent->tag == DW_TAG_structure_type |
3775 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3776 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3777 | || parent->tag == DW_TAG_union_type |
3778 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3779 | { |
3780 | if (grandparent_scope == NULL) | |
3781 | parent->scope = parent->name; | |
3782 | else | |
3e43a32a MS |
3783 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
3784 | grandparent_scope, | |
f55ee35c | 3785 | parent->name, 0, cu); |
72bf9492 | 3786 | } |
ceeb3d5a | 3787 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3788 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3789 | parent->scope = grandparent_scope; | |
3790 | else | |
3791 | { | |
3792 | /* FIXME drow/2004-04-01: What should we be doing with | |
3793 | function-local names? For partial symbols, we should probably be | |
3794 | ignoring them. */ | |
3795 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3796 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3797 | parent->tag, pdi->offset); |
3798 | parent->scope = grandparent_scope; | |
c906108c SS |
3799 | } |
3800 | ||
72bf9492 DJ |
3801 | parent->scope_set = 1; |
3802 | return parent->scope; | |
3803 | } | |
3804 | ||
3805 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3806 | CU. The result will be allocated with malloc. */ | |
3807 | static char * | |
3808 | partial_die_full_name (struct partial_die_info *pdi, | |
3809 | struct dwarf2_cu *cu) | |
3810 | { | |
3811 | char *parent_scope; | |
3812 | ||
98bfdba5 PA |
3813 | /* If this is a template instantiation, we can not work out the |
3814 | template arguments from partial DIEs. So, unfortunately, we have | |
3815 | to go through the full DIEs. At least any work we do building | |
3816 | types here will be reused if full symbols are loaded later. */ | |
3817 | if (pdi->has_template_arguments) | |
3818 | { | |
3819 | fixup_partial_die (pdi, cu); | |
3820 | ||
3821 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3822 | { | |
3823 | struct die_info *die; | |
3824 | struct attribute attr; | |
3825 | struct dwarf2_cu *ref_cu = cu; | |
3826 | ||
3827 | attr.name = 0; | |
3828 | attr.form = DW_FORM_ref_addr; | |
3829 | attr.u.addr = pdi->offset; | |
3830 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3831 | ||
3832 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3833 | } | |
3834 | } | |
3835 | ||
72bf9492 DJ |
3836 | parent_scope = partial_die_parent_scope (pdi, cu); |
3837 | if (parent_scope == NULL) | |
3838 | return NULL; | |
3839 | else | |
f55ee35c | 3840 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3841 | } |
3842 | ||
3843 | static void | |
72bf9492 | 3844 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3845 | { |
e7c27a73 | 3846 | struct objfile *objfile = cu->objfile; |
c906108c | 3847 | CORE_ADDR addr = 0; |
decbce07 | 3848 | char *actual_name = NULL; |
5c4e30ca | 3849 | const struct partial_symbol *psym = NULL; |
e142c38c | 3850 | CORE_ADDR baseaddr; |
72bf9492 | 3851 | int built_actual_name = 0; |
e142c38c DJ |
3852 | |
3853 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3854 | |
94af9270 KS |
3855 | actual_name = partial_die_full_name (pdi, cu); |
3856 | if (actual_name) | |
3857 | built_actual_name = 1; | |
63d06c5c | 3858 | |
72bf9492 DJ |
3859 | if (actual_name == NULL) |
3860 | actual_name = pdi->name; | |
3861 | ||
c906108c SS |
3862 | switch (pdi->tag) |
3863 | { | |
3864 | case DW_TAG_subprogram: | |
2cfa0c8d | 3865 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3866 | { |
2cfa0c8d JB |
3867 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3868 | of the global scope. But in Ada, we want to be able to access | |
3869 | nested procedures globally. So all Ada subprograms are stored | |
3870 | in the global scope. */ | |
f47fb265 | 3871 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3872 | mst_text, objfile); */ |
f47fb265 MS |
3873 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3874 | built_actual_name, | |
3875 | VAR_DOMAIN, LOC_BLOCK, | |
3876 | &objfile->global_psymbols, | |
3877 | 0, pdi->lowpc + baseaddr, | |
3878 | cu->language, objfile); | |
c906108c SS |
3879 | } |
3880 | else | |
3881 | { | |
f47fb265 | 3882 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3883 | mst_file_text, objfile); */ |
f47fb265 MS |
3884 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3885 | built_actual_name, | |
3886 | VAR_DOMAIN, LOC_BLOCK, | |
3887 | &objfile->static_psymbols, | |
3888 | 0, pdi->lowpc + baseaddr, | |
3889 | cu->language, objfile); | |
c906108c SS |
3890 | } |
3891 | break; | |
72929c62 JB |
3892 | case DW_TAG_constant: |
3893 | { | |
3894 | struct psymbol_allocation_list *list; | |
3895 | ||
3896 | if (pdi->is_external) | |
3897 | list = &objfile->global_psymbols; | |
3898 | else | |
3899 | list = &objfile->static_psymbols; | |
f47fb265 MS |
3900 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3901 | built_actual_name, VAR_DOMAIN, LOC_STATIC, | |
3902 | list, 0, 0, cu->language, objfile); | |
72929c62 JB |
3903 | } |
3904 | break; | |
c906108c | 3905 | case DW_TAG_variable: |
caac4577 JG |
3906 | if (pdi->locdesc) |
3907 | addr = decode_locdesc (pdi->locdesc, cu); | |
3908 | ||
3909 | if (pdi->locdesc | |
3910 | && addr == 0 | |
3911 | && !dwarf2_per_objfile->has_section_at_zero) | |
3912 | { | |
3913 | /* A global or static variable may also have been stripped | |
3914 | out by the linker if unused, in which case its address | |
3915 | will be nullified; do not add such variables into partial | |
3916 | symbol table then. */ | |
3917 | } | |
3918 | else if (pdi->is_external) | |
c906108c SS |
3919 | { |
3920 | /* Global Variable. | |
3921 | Don't enter into the minimal symbol tables as there is | |
3922 | a minimal symbol table entry from the ELF symbols already. | |
3923 | Enter into partial symbol table if it has a location | |
3924 | descriptor or a type. | |
3925 | If the location descriptor is missing, new_symbol will create | |
3926 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3927 | be determined from the minimal symbol table whenever the variable | |
3928 | is referenced. | |
3929 | The address for the partial symbol table entry is not | |
3930 | used by GDB, but it comes in handy for debugging partial symbol | |
3931 | table building. */ | |
3932 | ||
c906108c | 3933 | if (pdi->locdesc || pdi->has_type) |
f47fb265 MS |
3934 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3935 | built_actual_name, | |
3936 | VAR_DOMAIN, LOC_STATIC, | |
3937 | &objfile->global_psymbols, | |
3938 | 0, addr + baseaddr, | |
3939 | cu->language, objfile); | |
c906108c SS |
3940 | } |
3941 | else | |
3942 | { | |
0963b4bd | 3943 | /* Static Variable. Skip symbols without location descriptors. */ |
c906108c | 3944 | if (pdi->locdesc == NULL) |
decbce07 MS |
3945 | { |
3946 | if (built_actual_name) | |
3947 | xfree (actual_name); | |
3948 | return; | |
3949 | } | |
f47fb265 | 3950 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3951 | mst_file_data, objfile); */ |
f47fb265 MS |
3952 | add_psymbol_to_list (actual_name, strlen (actual_name), |
3953 | built_actual_name, | |
3954 | VAR_DOMAIN, LOC_STATIC, | |
3955 | &objfile->static_psymbols, | |
3956 | 0, addr + baseaddr, | |
3957 | cu->language, objfile); | |
c906108c SS |
3958 | } |
3959 | break; | |
3960 | case DW_TAG_typedef: | |
3961 | case DW_TAG_base_type: | |
a02abb62 | 3962 | case DW_TAG_subrange_type: |
38d518c9 | 3963 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3964 | built_actual_name, |
176620f1 | 3965 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3966 | &objfile->static_psymbols, |
e142c38c | 3967 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3968 | break; |
72bf9492 DJ |
3969 | case DW_TAG_namespace: |
3970 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 3971 | built_actual_name, |
72bf9492 DJ |
3972 | VAR_DOMAIN, LOC_TYPEDEF, |
3973 | &objfile->global_psymbols, | |
3974 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
3975 | break; | |
c906108c | 3976 | case DW_TAG_class_type: |
680b30c7 | 3977 | case DW_TAG_interface_type: |
c906108c SS |
3978 | case DW_TAG_structure_type: |
3979 | case DW_TAG_union_type: | |
3980 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
3981 | /* Skip external references. The DWARF standard says in the section |
3982 | about "Structure, Union, and Class Type Entries": "An incomplete | |
3983 | structure, union or class type is represented by a structure, | |
3984 | union or class entry that does not have a byte size attribute | |
3985 | and that has a DW_AT_declaration attribute." */ | |
3986 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
3987 | { |
3988 | if (built_actual_name) | |
3989 | xfree (actual_name); | |
3990 | return; | |
3991 | } | |
fa4028e9 | 3992 | |
63d06c5c DC |
3993 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
3994 | static vs. global. */ | |
38d518c9 | 3995 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3996 | built_actual_name, |
176620f1 | 3997 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
3998 | (cu->language == language_cplus |
3999 | || cu->language == language_java) | |
63d06c5c DC |
4000 | ? &objfile->global_psymbols |
4001 | : &objfile->static_psymbols, | |
e142c38c | 4002 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 4003 | |
c906108c SS |
4004 | break; |
4005 | case DW_TAG_enumerator: | |
38d518c9 | 4006 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 4007 | built_actual_name, |
176620f1 | 4008 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
4009 | (cu->language == language_cplus |
4010 | || cu->language == language_java) | |
f6fe98ef DJ |
4011 | ? &objfile->global_psymbols |
4012 | : &objfile->static_psymbols, | |
e142c38c | 4013 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
4014 | break; |
4015 | default: | |
4016 | break; | |
4017 | } | |
5c4e30ca | 4018 | |
72bf9492 DJ |
4019 | if (built_actual_name) |
4020 | xfree (actual_name); | |
c906108c SS |
4021 | } |
4022 | ||
5c4e30ca DC |
4023 | /* Read a partial die corresponding to a namespace; also, add a symbol |
4024 | corresponding to that namespace to the symbol table. NAMESPACE is | |
4025 | the name of the enclosing namespace. */ | |
91c24f0a | 4026 | |
72bf9492 DJ |
4027 | static void |
4028 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 4029 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 4030 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 4031 | { |
72bf9492 | 4032 | /* Add a symbol for the namespace. */ |
e7c27a73 | 4033 | |
72bf9492 | 4034 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
4035 | |
4036 | /* Now scan partial symbols in that namespace. */ | |
4037 | ||
91c24f0a | 4038 | if (pdi->has_children) |
5734ee8b | 4039 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
4040 | } |
4041 | ||
5d7cb8df JK |
4042 | /* Read a partial die corresponding to a Fortran module. */ |
4043 | ||
4044 | static void | |
4045 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
4046 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
4047 | { | |
f55ee35c | 4048 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
4049 | |
4050 | if (pdi->has_children) | |
4051 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
4052 | } | |
4053 | ||
bc30ff58 JB |
4054 | /* Read a partial die corresponding to a subprogram and create a partial |
4055 | symbol for that subprogram. When the CU language allows it, this | |
4056 | routine also defines a partial symbol for each nested subprogram | |
4057 | that this subprogram contains. | |
6e70227d | 4058 | |
bc30ff58 JB |
4059 | DIE my also be a lexical block, in which case we simply search |
4060 | recursively for suprograms defined inside that lexical block. | |
4061 | Again, this is only performed when the CU language allows this | |
4062 | type of definitions. */ | |
4063 | ||
4064 | static void | |
4065 | add_partial_subprogram (struct partial_die_info *pdi, | |
4066 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 4067 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
4068 | { |
4069 | if (pdi->tag == DW_TAG_subprogram) | |
4070 | { | |
4071 | if (pdi->has_pc_info) | |
4072 | { | |
4073 | if (pdi->lowpc < *lowpc) | |
4074 | *lowpc = pdi->lowpc; | |
4075 | if (pdi->highpc > *highpc) | |
4076 | *highpc = pdi->highpc; | |
5734ee8b DJ |
4077 | if (need_pc) |
4078 | { | |
4079 | CORE_ADDR baseaddr; | |
4080 | struct objfile *objfile = cu->objfile; | |
4081 | ||
4082 | baseaddr = ANOFFSET (objfile->section_offsets, | |
4083 | SECT_OFF_TEXT (objfile)); | |
4084 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
4085 | pdi->lowpc + baseaddr, |
4086 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 4087 | cu->per_cu->v.psymtab); |
5734ee8b | 4088 | } |
bc30ff58 | 4089 | if (!pdi->is_declaration) |
e8d05480 JB |
4090 | /* Ignore subprogram DIEs that do not have a name, they are |
4091 | illegal. Do not emit a complaint at this point, we will | |
4092 | do so when we convert this psymtab into a symtab. */ | |
4093 | if (pdi->name) | |
4094 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
4095 | } |
4096 | } | |
6e70227d | 4097 | |
bc30ff58 JB |
4098 | if (! pdi->has_children) |
4099 | return; | |
4100 | ||
4101 | if (cu->language == language_ada) | |
4102 | { | |
4103 | pdi = pdi->die_child; | |
4104 | while (pdi != NULL) | |
4105 | { | |
4106 | fixup_partial_die (pdi, cu); | |
4107 | if (pdi->tag == DW_TAG_subprogram | |
4108 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 4109 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
4110 | pdi = pdi->die_sibling; |
4111 | } | |
4112 | } | |
4113 | } | |
4114 | ||
91c24f0a DC |
4115 | /* Read a partial die corresponding to an enumeration type. */ |
4116 | ||
72bf9492 DJ |
4117 | static void |
4118 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
4119 | struct dwarf2_cu *cu) | |
91c24f0a | 4120 | { |
72bf9492 | 4121 | struct partial_die_info *pdi; |
91c24f0a DC |
4122 | |
4123 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
4124 | add_partial_symbol (enum_pdi, cu); |
4125 | ||
4126 | pdi = enum_pdi->die_child; | |
4127 | while (pdi) | |
91c24f0a | 4128 | { |
72bf9492 | 4129 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 4130 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 4131 | else |
72bf9492 DJ |
4132 | add_partial_symbol (pdi, cu); |
4133 | pdi = pdi->die_sibling; | |
91c24f0a | 4134 | } |
91c24f0a DC |
4135 | } |
4136 | ||
4bb7a0a7 DJ |
4137 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
4138 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
4139 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
4140 | the initial number. */ | |
4141 | ||
4142 | static struct abbrev_info * | |
fe1b8b76 | 4143 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 4144 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4145 | { |
4146 | bfd *abfd = cu->objfile->obfd; | |
4147 | unsigned int abbrev_number; | |
4148 | struct abbrev_info *abbrev; | |
4149 | ||
4150 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
4151 | ||
4152 | if (abbrev_number == 0) | |
4153 | return NULL; | |
4154 | ||
4155 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
4156 | if (!abbrev) | |
4157 | { | |
3e43a32a MS |
4158 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
4159 | abbrev_number, bfd_get_filename (abfd)); | |
4bb7a0a7 DJ |
4160 | } |
4161 | ||
4162 | return abbrev; | |
4163 | } | |
4164 | ||
93311388 DE |
4165 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4166 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
4167 | DIE. Any children of the skipped DIEs will also be skipped. */ |
4168 | ||
fe1b8b76 | 4169 | static gdb_byte * |
93311388 | 4170 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
4171 | { |
4172 | struct abbrev_info *abbrev; | |
4173 | unsigned int bytes_read; | |
4174 | ||
4175 | while (1) | |
4176 | { | |
4177 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4178 | if (abbrev == NULL) | |
4179 | return info_ptr + bytes_read; | |
4180 | else | |
93311388 | 4181 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4182 | } |
4183 | } | |
4184 | ||
93311388 DE |
4185 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4186 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4187 | abbrev corresponding to that skipped uleb128 should be passed in |
4188 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4189 | children. */ | |
4190 | ||
fe1b8b76 | 4191 | static gdb_byte * |
93311388 DE |
4192 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4193 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4194 | { |
4195 | unsigned int bytes_read; | |
4196 | struct attribute attr; | |
4197 | bfd *abfd = cu->objfile->obfd; | |
4198 | unsigned int form, i; | |
4199 | ||
4200 | for (i = 0; i < abbrev->num_attrs; i++) | |
4201 | { | |
4202 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4203 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4204 | { | |
4205 | read_attribute (&attr, &abbrev->attrs[i], | |
4206 | abfd, info_ptr, cu); | |
4207 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
4208 | complaint (&symfile_complaints, |
4209 | _("ignoring absolute DW_AT_sibling")); | |
4bb7a0a7 | 4210 | else |
93311388 | 4211 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4212 | } |
4213 | ||
4214 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4215 | form = abbrev->attrs[i].form; | |
4216 | skip_attribute: | |
4217 | switch (form) | |
4218 | { | |
4bb7a0a7 | 4219 | case DW_FORM_ref_addr: |
ae411497 TT |
4220 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4221 | and later it is offset sized. */ | |
4222 | if (cu->header.version == 2) | |
4223 | info_ptr += cu->header.addr_size; | |
4224 | else | |
4225 | info_ptr += cu->header.offset_size; | |
4226 | break; | |
4227 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4228 | info_ptr += cu->header.addr_size; |
4229 | break; | |
4230 | case DW_FORM_data1: | |
4231 | case DW_FORM_ref1: | |
4232 | case DW_FORM_flag: | |
4233 | info_ptr += 1; | |
4234 | break; | |
2dc7f7b3 TT |
4235 | case DW_FORM_flag_present: |
4236 | break; | |
4bb7a0a7 DJ |
4237 | case DW_FORM_data2: |
4238 | case DW_FORM_ref2: | |
4239 | info_ptr += 2; | |
4240 | break; | |
4241 | case DW_FORM_data4: | |
4242 | case DW_FORM_ref4: | |
4243 | info_ptr += 4; | |
4244 | break; | |
4245 | case DW_FORM_data8: | |
4246 | case DW_FORM_ref8: | |
55f1336d | 4247 | case DW_FORM_ref_sig8: |
4bb7a0a7 DJ |
4248 | info_ptr += 8; |
4249 | break; | |
4250 | case DW_FORM_string: | |
9b1c24c8 | 4251 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4252 | info_ptr += bytes_read; |
4253 | break; | |
2dc7f7b3 | 4254 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4255 | case DW_FORM_strp: |
4256 | info_ptr += cu->header.offset_size; | |
4257 | break; | |
2dc7f7b3 | 4258 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4259 | case DW_FORM_block: |
4260 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4261 | info_ptr += bytes_read; | |
4262 | break; | |
4263 | case DW_FORM_block1: | |
4264 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4265 | break; | |
4266 | case DW_FORM_block2: | |
4267 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4268 | break; | |
4269 | case DW_FORM_block4: | |
4270 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4271 | break; | |
4272 | case DW_FORM_sdata: | |
4273 | case DW_FORM_udata: | |
4274 | case DW_FORM_ref_udata: | |
4275 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4276 | break; | |
4277 | case DW_FORM_indirect: | |
4278 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4279 | info_ptr += bytes_read; | |
4280 | /* We need to continue parsing from here, so just go back to | |
4281 | the top. */ | |
4282 | goto skip_attribute; | |
4283 | ||
4284 | default: | |
3e43a32a MS |
4285 | error (_("Dwarf Error: Cannot handle %s " |
4286 | "in DWARF reader [in module %s]"), | |
4bb7a0a7 DJ |
4287 | dwarf_form_name (form), |
4288 | bfd_get_filename (abfd)); | |
4289 | } | |
4290 | } | |
4291 | ||
4292 | if (abbrev->has_children) | |
93311388 | 4293 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4294 | else |
4295 | return info_ptr; | |
4296 | } | |
4297 | ||
93311388 DE |
4298 | /* Locate ORIG_PDI's sibling. |
4299 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4300 | in BUFFER. */ | |
91c24f0a | 4301 | |
fe1b8b76 | 4302 | static gdb_byte * |
93311388 DE |
4303 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4304 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4305 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4306 | { |
4307 | /* Do we know the sibling already? */ | |
72bf9492 | 4308 | |
91c24f0a DC |
4309 | if (orig_pdi->sibling) |
4310 | return orig_pdi->sibling; | |
4311 | ||
4312 | /* Are there any children to deal with? */ | |
4313 | ||
4314 | if (!orig_pdi->has_children) | |
4315 | return info_ptr; | |
4316 | ||
4bb7a0a7 | 4317 | /* Skip the children the long way. */ |
91c24f0a | 4318 | |
93311388 | 4319 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4320 | } |
4321 | ||
c906108c SS |
4322 | /* Expand this partial symbol table into a full symbol table. */ |
4323 | ||
4324 | static void | |
fba45db2 | 4325 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4326 | { |
c906108c SS |
4327 | if (pst != NULL) |
4328 | { | |
4329 | if (pst->readin) | |
4330 | { | |
3e43a32a MS |
4331 | warning (_("bug: psymtab for %s is already read in."), |
4332 | pst->filename); | |
c906108c SS |
4333 | } |
4334 | else | |
4335 | { | |
4336 | if (info_verbose) | |
4337 | { | |
3e43a32a MS |
4338 | printf_filtered (_("Reading in symbols for %s..."), |
4339 | pst->filename); | |
c906108c SS |
4340 | gdb_flush (gdb_stdout); |
4341 | } | |
4342 | ||
10b3939b DJ |
4343 | /* Restore our global data. */ |
4344 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4345 | dwarf2_objfile_data_key); | |
4346 | ||
b2ab525c KB |
4347 | /* If this psymtab is constructed from a debug-only objfile, the |
4348 | has_section_at_zero flag will not necessarily be correct. We | |
4349 | can get the correct value for this flag by looking at the data | |
4350 | associated with the (presumably stripped) associated objfile. */ | |
4351 | if (pst->objfile->separate_debug_objfile_backlink) | |
4352 | { | |
4353 | struct dwarf2_per_objfile *dpo_backlink | |
4354 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4355 | dwarf2_objfile_data_key); | |
9a619af0 | 4356 | |
b2ab525c KB |
4357 | dwarf2_per_objfile->has_section_at_zero |
4358 | = dpo_backlink->has_section_at_zero; | |
4359 | } | |
4360 | ||
98bfdba5 PA |
4361 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4362 | ||
c906108c SS |
4363 | psymtab_to_symtab_1 (pst); |
4364 | ||
4365 | /* Finish up the debug error message. */ | |
4366 | if (info_verbose) | |
a3f17187 | 4367 | printf_filtered (_("done.\n")); |
c906108c SS |
4368 | } |
4369 | } | |
4370 | } | |
4371 | ||
10b3939b DJ |
4372 | /* Add PER_CU to the queue. */ |
4373 | ||
4374 | static void | |
03dd20cc | 4375 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
4376 | { |
4377 | struct dwarf2_queue_item *item; | |
4378 | ||
4379 | per_cu->queued = 1; | |
4380 | item = xmalloc (sizeof (*item)); | |
4381 | item->per_cu = per_cu; | |
4382 | item->next = NULL; | |
4383 | ||
4384 | if (dwarf2_queue == NULL) | |
4385 | dwarf2_queue = item; | |
4386 | else | |
4387 | dwarf2_queue_tail->next = item; | |
4388 | ||
4389 | dwarf2_queue_tail = item; | |
4390 | } | |
4391 | ||
4392 | /* Process the queue. */ | |
4393 | ||
4394 | static void | |
4395 | process_queue (struct objfile *objfile) | |
4396 | { | |
4397 | struct dwarf2_queue_item *item, *next_item; | |
4398 | ||
03dd20cc DJ |
4399 | /* The queue starts out with one item, but following a DIE reference |
4400 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4401 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4402 | { | |
9291a0cd TT |
4403 | if (dwarf2_per_objfile->using_index |
4404 | ? !item->per_cu->v.quick->symtab | |
4405 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4406 | process_full_comp_unit (item->per_cu); |
4407 | ||
4408 | item->per_cu->queued = 0; | |
4409 | next_item = item->next; | |
4410 | xfree (item); | |
4411 | } | |
4412 | ||
4413 | dwarf2_queue_tail = NULL; | |
4414 | } | |
4415 | ||
4416 | /* Free all allocated queue entries. This function only releases anything if | |
4417 | an error was thrown; if the queue was processed then it would have been | |
4418 | freed as we went along. */ | |
4419 | ||
4420 | static void | |
4421 | dwarf2_release_queue (void *dummy) | |
4422 | { | |
4423 | struct dwarf2_queue_item *item, *last; | |
4424 | ||
4425 | item = dwarf2_queue; | |
4426 | while (item) | |
4427 | { | |
4428 | /* Anything still marked queued is likely to be in an | |
4429 | inconsistent state, so discard it. */ | |
4430 | if (item->per_cu->queued) | |
4431 | { | |
4432 | if (item->per_cu->cu != NULL) | |
4433 | free_one_cached_comp_unit (item->per_cu->cu); | |
4434 | item->per_cu->queued = 0; | |
4435 | } | |
4436 | ||
4437 | last = item; | |
4438 | item = item->next; | |
4439 | xfree (last); | |
4440 | } | |
4441 | ||
4442 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4443 | } | |
4444 | ||
4445 | /* Read in full symbols for PST, and anything it depends on. */ | |
4446 | ||
c906108c | 4447 | static void |
fba45db2 | 4448 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4449 | { |
10b3939b | 4450 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4451 | struct cleanup *back_to; |
aaa75496 JB |
4452 | int i; |
4453 | ||
4454 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4455 | if (!pst->dependencies[i]->readin) | |
4456 | { | |
4457 | /* Inform about additional files that need to be read in. */ | |
4458 | if (info_verbose) | |
4459 | { | |
a3f17187 | 4460 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4461 | fputs_filtered (" ", gdb_stdout); |
4462 | wrap_here (""); | |
4463 | fputs_filtered ("and ", gdb_stdout); | |
4464 | wrap_here (""); | |
4465 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
0963b4bd | 4466 | wrap_here (""); /* Flush output. */ |
aaa75496 JB |
4467 | gdb_flush (gdb_stdout); |
4468 | } | |
4469 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4470 | } | |
4471 | ||
e38df1d0 | 4472 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4473 | |
4474 | if (per_cu == NULL) | |
aaa75496 JB |
4475 | { |
4476 | /* It's an include file, no symbols to read for it. | |
4477 | Everything is in the parent symtab. */ | |
4478 | pst->readin = 1; | |
4479 | return; | |
4480 | } | |
c906108c | 4481 | |
9291a0cd | 4482 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4483 | } |
4484 | ||
93311388 | 4485 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4486 | |
93311388 | 4487 | static void |
3e43a32a MS |
4488 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
4489 | struct objfile *objfile) | |
10b3939b | 4490 | { |
31ffec48 | 4491 | bfd *abfd = objfile->obfd; |
10b3939b | 4492 | struct dwarf2_cu *cu; |
c764a876 | 4493 | unsigned int offset; |
93311388 | 4494 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4495 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4496 | struct attribute *attr; |
98bfdba5 | 4497 | int read_cu = 0; |
6502dd73 | 4498 | |
348e048f DE |
4499 | gdb_assert (! per_cu->from_debug_types); |
4500 | ||
c906108c | 4501 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4502 | offset = per_cu->offset; |
6502dd73 | 4503 | |
be391dca | 4504 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4505 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4506 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4507 | |
98bfdba5 PA |
4508 | if (per_cu->cu == NULL) |
4509 | { | |
9816fde3 JK |
4510 | cu = xmalloc (sizeof (*cu)); |
4511 | init_one_comp_unit (cu, objfile); | |
98bfdba5 PA |
4512 | |
4513 | read_cu = 1; | |
c906108c | 4514 | |
98bfdba5 PA |
4515 | /* If an error occurs while loading, release our storage. */ |
4516 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4517 | |
98bfdba5 PA |
4518 | /* Read in the comp_unit header. */ |
4519 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4520 | |
98bfdba5 PA |
4521 | /* Complete the cu_header. */ |
4522 | cu->header.offset = offset; | |
4523 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4524 | |
98bfdba5 PA |
4525 | /* Read the abbrevs for this compilation unit. */ |
4526 | dwarf2_read_abbrevs (abfd, cu); | |
4527 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10b3939b | 4528 | |
98bfdba5 PA |
4529 | /* Link this compilation unit into the compilation unit tree. */ |
4530 | per_cu->cu = cu; | |
4531 | cu->per_cu = per_cu; | |
98bfdba5 PA |
4532 | |
4533 | /* Link this CU into read_in_chain. */ | |
4534 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4535 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4536 | } | |
4537 | else | |
4538 | { | |
4539 | cu = per_cu->cu; | |
4540 | info_ptr += cu->header.first_die_offset; | |
4541 | } | |
e142c38c | 4542 | |
93311388 | 4543 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4544 | |
4545 | /* We try not to read any attributes in this function, because not | |
4546 | all objfiles needed for references have been loaded yet, and symbol | |
4547 | table processing isn't initialized. But we have to set the CU language, | |
4548 | or we won't be able to build types correctly. */ | |
9816fde3 | 4549 | prepare_one_comp_unit (cu, cu->dies); |
10b3939b | 4550 | |
a6c727b2 DJ |
4551 | /* Similarly, if we do not read the producer, we can not apply |
4552 | producer-specific interpretation. */ | |
4553 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4554 | if (attr) | |
4555 | cu->producer = DW_STRING (attr); | |
4556 | ||
98bfdba5 PA |
4557 | if (read_cu) |
4558 | { | |
4559 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4560 | |
98bfdba5 PA |
4561 | /* We've successfully allocated this compilation unit. Let our |
4562 | caller clean it up when finished with it. */ | |
4563 | discard_cleanups (free_cu_cleanup); | |
4564 | } | |
10b3939b DJ |
4565 | } |
4566 | ||
3da10d80 KS |
4567 | /* Add a DIE to the delayed physname list. */ |
4568 | ||
4569 | static void | |
4570 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4571 | const char *name, struct die_info *die, | |
4572 | struct dwarf2_cu *cu) | |
4573 | { | |
4574 | struct delayed_method_info mi; | |
4575 | mi.type = type; | |
4576 | mi.fnfield_index = fnfield_index; | |
4577 | mi.index = index; | |
4578 | mi.name = name; | |
4579 | mi.die = die; | |
4580 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4581 | } | |
4582 | ||
4583 | /* A cleanup for freeing the delayed method list. */ | |
4584 | ||
4585 | static void | |
4586 | free_delayed_list (void *ptr) | |
4587 | { | |
4588 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4589 | if (cu->method_list != NULL) | |
4590 | { | |
4591 | VEC_free (delayed_method_info, cu->method_list); | |
4592 | cu->method_list = NULL; | |
4593 | } | |
4594 | } | |
4595 | ||
4596 | /* Compute the physnames of any methods on the CU's method list. | |
4597 | ||
4598 | The computation of method physnames is delayed in order to avoid the | |
4599 | (bad) condition that one of the method's formal parameters is of an as yet | |
4600 | incomplete type. */ | |
4601 | ||
4602 | static void | |
4603 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4604 | { | |
4605 | int i; | |
4606 | struct delayed_method_info *mi; | |
4607 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4608 | { | |
4609 | char *physname; | |
4610 | struct fn_fieldlist *fn_flp | |
4611 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
4612 | physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu); | |
4613 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; | |
4614 | } | |
4615 | } | |
4616 | ||
10b3939b DJ |
4617 | /* Generate full symbol information for PST and CU, whose DIEs have |
4618 | already been loaded into memory. */ | |
4619 | ||
4620 | static void | |
4621 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4622 | { | |
10b3939b | 4623 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4624 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4625 | CORE_ADDR lowpc, highpc; |
4626 | struct symtab *symtab; | |
3da10d80 | 4627 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4628 | CORE_ADDR baseaddr; |
4629 | ||
4630 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4631 | ||
10b3939b DJ |
4632 | buildsym_init (); |
4633 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4634 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4635 | |
4636 | cu->list_in_scope = &file_symbols; | |
c906108c | 4637 | |
d85a05f0 | 4638 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4639 | |
c906108c | 4640 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4641 | process_die (cu->dies, cu); |
c906108c | 4642 | |
3da10d80 KS |
4643 | /* Now that we have processed all the DIEs in the CU, all the types |
4644 | should be complete, and it should now be safe to compute all of the | |
4645 | physnames. */ | |
4646 | compute_delayed_physnames (cu); | |
4647 | do_cleanups (delayed_list_cleanup); | |
4648 | ||
fae299cd DC |
4649 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4650 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4651 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4652 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4653 | |
613e1657 | 4654 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
4655 | |
4656 | /* Set symtab language to language from DW_AT_language. | |
4657 | If the compilation is from a C file generated by language preprocessors, | |
4658 | do not set the language if it was already deduced by start_subfile. */ | |
4659 | if (symtab != NULL | |
10b3939b | 4660 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 4661 | { |
10b3939b | 4662 | symtab->language = cu->language; |
c906108c | 4663 | } |
9291a0cd TT |
4664 | |
4665 | if (dwarf2_per_objfile->using_index) | |
4666 | per_cu->v.quick->symtab = symtab; | |
4667 | else | |
4668 | { | |
4669 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4670 | pst->symtab = symtab; | |
4671 | pst->readin = 1; | |
4672 | } | |
c906108c SS |
4673 | |
4674 | do_cleanups (back_to); | |
4675 | } | |
4676 | ||
4677 | /* Process a die and its children. */ | |
4678 | ||
4679 | static void | |
e7c27a73 | 4680 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4681 | { |
4682 | switch (die->tag) | |
4683 | { | |
4684 | case DW_TAG_padding: | |
4685 | break; | |
4686 | case DW_TAG_compile_unit: | |
e7c27a73 | 4687 | read_file_scope (die, cu); |
c906108c | 4688 | break; |
348e048f DE |
4689 | case DW_TAG_type_unit: |
4690 | read_type_unit_scope (die, cu); | |
4691 | break; | |
c906108c | 4692 | case DW_TAG_subprogram: |
c906108c | 4693 | case DW_TAG_inlined_subroutine: |
edb3359d | 4694 | read_func_scope (die, cu); |
c906108c SS |
4695 | break; |
4696 | case DW_TAG_lexical_block: | |
14898363 L |
4697 | case DW_TAG_try_block: |
4698 | case DW_TAG_catch_block: | |
e7c27a73 | 4699 | read_lexical_block_scope (die, cu); |
c906108c SS |
4700 | break; |
4701 | case DW_TAG_class_type: | |
680b30c7 | 4702 | case DW_TAG_interface_type: |
c906108c SS |
4703 | case DW_TAG_structure_type: |
4704 | case DW_TAG_union_type: | |
134d01f1 | 4705 | process_structure_scope (die, cu); |
c906108c SS |
4706 | break; |
4707 | case DW_TAG_enumeration_type: | |
134d01f1 | 4708 | process_enumeration_scope (die, cu); |
c906108c | 4709 | break; |
134d01f1 | 4710 | |
f792889a DJ |
4711 | /* These dies have a type, but processing them does not create |
4712 | a symbol or recurse to process the children. Therefore we can | |
4713 | read them on-demand through read_type_die. */ | |
c906108c | 4714 | case DW_TAG_subroutine_type: |
72019c9c | 4715 | case DW_TAG_set_type: |
c906108c | 4716 | case DW_TAG_array_type: |
c906108c | 4717 | case DW_TAG_pointer_type: |
c906108c | 4718 | case DW_TAG_ptr_to_member_type: |
c906108c | 4719 | case DW_TAG_reference_type: |
c906108c | 4720 | case DW_TAG_string_type: |
c906108c | 4721 | break; |
134d01f1 | 4722 | |
c906108c | 4723 | case DW_TAG_base_type: |
a02abb62 | 4724 | case DW_TAG_subrange_type: |
cb249c71 | 4725 | case DW_TAG_typedef: |
134d01f1 DJ |
4726 | /* Add a typedef symbol for the type definition, if it has a |
4727 | DW_AT_name. */ | |
f792889a | 4728 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4729 | break; |
c906108c | 4730 | case DW_TAG_common_block: |
e7c27a73 | 4731 | read_common_block (die, cu); |
c906108c SS |
4732 | break; |
4733 | case DW_TAG_common_inclusion: | |
4734 | break; | |
d9fa45fe | 4735 | case DW_TAG_namespace: |
63d06c5c | 4736 | processing_has_namespace_info = 1; |
e7c27a73 | 4737 | read_namespace (die, cu); |
d9fa45fe | 4738 | break; |
5d7cb8df | 4739 | case DW_TAG_module: |
f55ee35c | 4740 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4741 | read_module (die, cu); |
4742 | break; | |
d9fa45fe DC |
4743 | case DW_TAG_imported_declaration: |
4744 | case DW_TAG_imported_module: | |
63d06c5c | 4745 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4746 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4747 | || cu->language != language_fortran)) | |
4748 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4749 | dwarf_tag_name (die->tag)); | |
4750 | read_import_statement (die, cu); | |
d9fa45fe | 4751 | break; |
c906108c | 4752 | default: |
e7c27a73 | 4753 | new_symbol (die, NULL, cu); |
c906108c SS |
4754 | break; |
4755 | } | |
4756 | } | |
4757 | ||
94af9270 KS |
4758 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4759 | needs to have the name of the scope prepended to the name listed in the | |
4760 | die. */ | |
4761 | ||
4762 | static int | |
4763 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4764 | { | |
1c809c68 TT |
4765 | struct attribute *attr; |
4766 | ||
94af9270 KS |
4767 | switch (die->tag) |
4768 | { | |
4769 | case DW_TAG_namespace: | |
4770 | case DW_TAG_typedef: | |
4771 | case DW_TAG_class_type: | |
4772 | case DW_TAG_interface_type: | |
4773 | case DW_TAG_structure_type: | |
4774 | case DW_TAG_union_type: | |
4775 | case DW_TAG_enumeration_type: | |
4776 | case DW_TAG_enumerator: | |
4777 | case DW_TAG_subprogram: | |
4778 | case DW_TAG_member: | |
4779 | return 1; | |
4780 | ||
4781 | case DW_TAG_variable: | |
c2b0a229 | 4782 | case DW_TAG_constant: |
94af9270 KS |
4783 | /* We only need to prefix "globally" visible variables. These include |
4784 | any variable marked with DW_AT_external or any variable that | |
4785 | lives in a namespace. [Variables in anonymous namespaces | |
4786 | require prefixing, but they are not DW_AT_external.] */ | |
4787 | ||
4788 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4789 | { | |
4790 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4791 | |
94af9270 KS |
4792 | return die_needs_namespace (die_specification (die, &spec_cu), |
4793 | spec_cu); | |
4794 | } | |
4795 | ||
1c809c68 | 4796 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4797 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4798 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4799 | return 0; |
4800 | /* A variable in a lexical block of some kind does not need a | |
4801 | namespace, even though in C++ such variables may be external | |
4802 | and have a mangled name. */ | |
4803 | if (die->parent->tag == DW_TAG_lexical_block | |
4804 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4805 | || die->parent->tag == DW_TAG_catch_block |
4806 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4807 | return 0; |
4808 | return 1; | |
94af9270 KS |
4809 | |
4810 | default: | |
4811 | return 0; | |
4812 | } | |
4813 | } | |
4814 | ||
98bfdba5 PA |
4815 | /* Retrieve the last character from a mem_file. */ |
4816 | ||
4817 | static void | |
4818 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4819 | { | |
4820 | char *last_char_p = (char *) object; | |
4821 | ||
4822 | if (length > 0) | |
4823 | *last_char_p = buffer[length - 1]; | |
4824 | } | |
4825 | ||
94af9270 KS |
4826 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4827 | compute the physname for the object, which include a method's | |
4828 | formal parameters (C++/Java) and return type (Java). | |
4829 | ||
af6b7be1 JB |
4830 | For Ada, return the DIE's linkage name rather than the fully qualified |
4831 | name. PHYSNAME is ignored.. | |
4832 | ||
94af9270 KS |
4833 | The result is allocated on the objfile_obstack and canonicalized. */ |
4834 | ||
4835 | static const char * | |
4836 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4837 | int physname) | |
4838 | { | |
4839 | if (name == NULL) | |
4840 | name = dwarf2_name (die, cu); | |
4841 | ||
f55ee35c JK |
4842 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4843 | compute it by typename_concat inside GDB. */ | |
4844 | if (cu->language == language_ada | |
4845 | || (cu->language == language_fortran && physname)) | |
4846 | { | |
4847 | /* For Ada unit, we prefer the linkage name over the name, as | |
4848 | the former contains the exported name, which the user expects | |
4849 | to be able to reference. Ideally, we want the user to be able | |
4850 | to reference this entity using either natural or linkage name, | |
4851 | but we haven't started looking at this enhancement yet. */ | |
4852 | struct attribute *attr; | |
4853 | ||
4854 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4855 | if (attr == NULL) | |
4856 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4857 | if (attr && DW_STRING (attr)) | |
4858 | return DW_STRING (attr); | |
4859 | } | |
4860 | ||
94af9270 KS |
4861 | /* These are the only languages we know how to qualify names in. */ |
4862 | if (name != NULL | |
f55ee35c JK |
4863 | && (cu->language == language_cplus || cu->language == language_java |
4864 | || cu->language == language_fortran)) | |
94af9270 KS |
4865 | { |
4866 | if (die_needs_namespace (die, cu)) | |
4867 | { | |
4868 | long length; | |
4869 | char *prefix; | |
4870 | struct ui_file *buf; | |
4871 | ||
4872 | prefix = determine_prefix (die, cu); | |
4873 | buf = mem_fileopen (); | |
4874 | if (*prefix != '\0') | |
4875 | { | |
f55ee35c JK |
4876 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4877 | physname, cu); | |
9a619af0 | 4878 | |
94af9270 KS |
4879 | fputs_unfiltered (prefixed_name, buf); |
4880 | xfree (prefixed_name); | |
4881 | } | |
4882 | else | |
62d5b8da | 4883 | fputs_unfiltered (name, buf); |
94af9270 | 4884 | |
98bfdba5 PA |
4885 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
4886 | as children with DW_TAG_template_type_param or | |
4887 | DW_TAG_value_type_param. If the latter, add them to the name | |
4888 | here. If the name already has template parameters, then | |
4889 | skip this step; some versions of GCC emit both, and | |
4890 | it is more efficient to use the pre-computed name. | |
4891 | ||
4892 | Something to keep in mind about this process: it is very | |
4893 | unlikely, or in some cases downright impossible, to produce | |
4894 | something that will match the mangled name of a function. | |
4895 | If the definition of the function has the same debug info, | |
4896 | we should be able to match up with it anyway. But fallbacks | |
4897 | using the minimal symbol, for instance to find a method | |
4898 | implemented in a stripped copy of libstdc++, will not work. | |
4899 | If we do not have debug info for the definition, we will have to | |
4900 | match them up some other way. | |
4901 | ||
4902 | When we do name matching there is a related problem with function | |
4903 | templates; two instantiated function templates are allowed to | |
4904 | differ only by their return types, which we do not add here. */ | |
4905 | ||
4906 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
4907 | { | |
4908 | struct attribute *attr; | |
4909 | struct die_info *child; | |
4910 | int first = 1; | |
4911 | ||
4912 | die->building_fullname = 1; | |
4913 | ||
4914 | for (child = die->child; child != NULL; child = child->sibling) | |
4915 | { | |
4916 | struct type *type; | |
4917 | long value; | |
4918 | gdb_byte *bytes; | |
4919 | struct dwarf2_locexpr_baton *baton; | |
4920 | struct value *v; | |
4921 | ||
4922 | if (child->tag != DW_TAG_template_type_param | |
4923 | && child->tag != DW_TAG_template_value_param) | |
4924 | continue; | |
4925 | ||
4926 | if (first) | |
4927 | { | |
4928 | fputs_unfiltered ("<", buf); | |
4929 | first = 0; | |
4930 | } | |
4931 | else | |
4932 | fputs_unfiltered (", ", buf); | |
4933 | ||
4934 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
4935 | if (attr == NULL) | |
4936 | { | |
4937 | complaint (&symfile_complaints, | |
4938 | _("template parameter missing DW_AT_type")); | |
4939 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
4940 | continue; | |
4941 | } | |
4942 | type = die_type (child, cu); | |
4943 | ||
4944 | if (child->tag == DW_TAG_template_type_param) | |
4945 | { | |
4946 | c_print_type (type, "", buf, -1, 0); | |
4947 | continue; | |
4948 | } | |
4949 | ||
4950 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
4951 | if (attr == NULL) | |
4952 | { | |
4953 | complaint (&symfile_complaints, | |
3e43a32a MS |
4954 | _("template parameter missing " |
4955 | "DW_AT_const_value")); | |
98bfdba5 PA |
4956 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
4957 | continue; | |
4958 | } | |
4959 | ||
4960 | dwarf2_const_value_attr (attr, type, name, | |
4961 | &cu->comp_unit_obstack, cu, | |
4962 | &value, &bytes, &baton); | |
4963 | ||
4964 | if (TYPE_NOSIGN (type)) | |
4965 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
4966 | changed, this can use value_print instead. */ | |
4967 | c_printchar (value, type, buf); | |
4968 | else | |
4969 | { | |
4970 | struct value_print_options opts; | |
4971 | ||
4972 | if (baton != NULL) | |
4973 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
4974 | baton->data, | |
4975 | baton->size, | |
4976 | baton->per_cu); | |
4977 | else if (bytes != NULL) | |
4978 | { | |
4979 | v = allocate_value (type); | |
4980 | memcpy (value_contents_writeable (v), bytes, | |
4981 | TYPE_LENGTH (type)); | |
4982 | } | |
4983 | else | |
4984 | v = value_from_longest (type, value); | |
4985 | ||
3e43a32a MS |
4986 | /* Specify decimal so that we do not depend on |
4987 | the radix. */ | |
98bfdba5 PA |
4988 | get_formatted_print_options (&opts, 'd'); |
4989 | opts.raw = 1; | |
4990 | value_print (v, buf, &opts); | |
4991 | release_value (v); | |
4992 | value_free (v); | |
4993 | } | |
4994 | } | |
4995 | ||
4996 | die->building_fullname = 0; | |
4997 | ||
4998 | if (!first) | |
4999 | { | |
5000 | /* Close the argument list, with a space if necessary | |
5001 | (nested templates). */ | |
5002 | char last_char = '\0'; | |
5003 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
5004 | if (last_char == '>') | |
5005 | fputs_unfiltered (" >", buf); | |
5006 | else | |
5007 | fputs_unfiltered (">", buf); | |
5008 | } | |
5009 | } | |
5010 | ||
94af9270 KS |
5011 | /* For Java and C++ methods, append formal parameter type |
5012 | information, if PHYSNAME. */ | |
6e70227d | 5013 | |
94af9270 KS |
5014 | if (physname && die->tag == DW_TAG_subprogram |
5015 | && (cu->language == language_cplus | |
5016 | || cu->language == language_java)) | |
5017 | { | |
5018 | struct type *type = read_type_die (die, cu); | |
5019 | ||
3167638f | 5020 | c_type_print_args (type, buf, 1, cu->language); |
94af9270 KS |
5021 | |
5022 | if (cu->language == language_java) | |
5023 | { | |
5024 | /* For java, we must append the return type to method | |
0963b4bd | 5025 | names. */ |
94af9270 KS |
5026 | if (die->tag == DW_TAG_subprogram) |
5027 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
5028 | 0, 0); | |
5029 | } | |
5030 | else if (cu->language == language_cplus) | |
5031 | { | |
60430eff DJ |
5032 | /* Assume that an artificial first parameter is |
5033 | "this", but do not crash if it is not. RealView | |
5034 | marks unnamed (and thus unused) parameters as | |
5035 | artificial; there is no way to differentiate | |
5036 | the two cases. */ | |
94af9270 KS |
5037 | if (TYPE_NFIELDS (type) > 0 |
5038 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 5039 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
3e43a32a MS |
5040 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
5041 | 0)))) | |
94af9270 KS |
5042 | fputs_unfiltered (" const", buf); |
5043 | } | |
5044 | } | |
5045 | ||
5046 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
5047 | &length); | |
5048 | ui_file_delete (buf); | |
5049 | ||
5050 | if (cu->language == language_cplus) | |
5051 | { | |
5052 | char *cname | |
5053 | = dwarf2_canonicalize_name (name, cu, | |
5054 | &cu->objfile->objfile_obstack); | |
9a619af0 | 5055 | |
94af9270 KS |
5056 | if (cname != NULL) |
5057 | name = cname; | |
5058 | } | |
5059 | } | |
5060 | } | |
5061 | ||
5062 | return name; | |
5063 | } | |
5064 | ||
0114d602 DJ |
5065 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
5066 | If scope qualifiers are appropriate they will be added. The result | |
5067 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
5068 | not have a name. NAME may either be from a previous call to |
5069 | dwarf2_name or NULL. | |
5070 | ||
0963b4bd | 5071 | The output string will be canonicalized (if C++/Java). */ |
0114d602 DJ |
5072 | |
5073 | static const char * | |
94af9270 | 5074 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 5075 | { |
94af9270 KS |
5076 | return dwarf2_compute_name (name, die, cu, 0); |
5077 | } | |
0114d602 | 5078 | |
94af9270 KS |
5079 | /* Construct a physname for the given DIE in CU. NAME may either be |
5080 | from a previous call to dwarf2_name or NULL. The result will be | |
5081 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
5082 | name. | |
0114d602 | 5083 | |
94af9270 | 5084 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 5085 | |
94af9270 KS |
5086 | static const char * |
5087 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
5088 | { | |
5089 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
5090 | } |
5091 | ||
27aa8d6a SW |
5092 | /* Read the import statement specified by the given die and record it. */ |
5093 | ||
5094 | static void | |
5095 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
5096 | { | |
5097 | struct attribute *import_attr; | |
5098 | struct die_info *imported_die; | |
de4affc9 | 5099 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 5100 | const char *imported_name; |
794684b6 | 5101 | const char *imported_name_prefix; |
13387711 SW |
5102 | const char *canonical_name; |
5103 | const char *import_alias; | |
5104 | const char *imported_declaration = NULL; | |
794684b6 | 5105 | const char *import_prefix; |
13387711 SW |
5106 | |
5107 | char *temp; | |
27aa8d6a SW |
5108 | |
5109 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
5110 | if (import_attr == NULL) | |
5111 | { | |
5112 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
5113 | dwarf_tag_name (die->tag)); | |
5114 | return; | |
5115 | } | |
5116 | ||
de4affc9 CC |
5117 | imported_cu = cu; |
5118 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
5119 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
5120 | if (imported_name == NULL) |
5121 | { | |
5122 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
5123 | ||
5124 | The import in the following code: | |
5125 | namespace A | |
5126 | { | |
5127 | typedef int B; | |
5128 | } | |
5129 | ||
5130 | int main () | |
5131 | { | |
5132 | using A::B; | |
5133 | B b; | |
5134 | return b; | |
5135 | } | |
5136 | ||
5137 | ... | |
5138 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
5139 | <52> DW_AT_decl_file : 1 | |
5140 | <53> DW_AT_decl_line : 6 | |
5141 | <54> DW_AT_import : <0x75> | |
5142 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
5143 | <59> DW_AT_name : B | |
5144 | <5b> DW_AT_decl_file : 1 | |
5145 | <5c> DW_AT_decl_line : 2 | |
5146 | <5d> DW_AT_type : <0x6e> | |
5147 | ... | |
5148 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
5149 | <76> DW_AT_byte_size : 4 | |
5150 | <77> DW_AT_encoding : 5 (signed) | |
5151 | ||
5152 | imports the wrong die ( 0x75 instead of 0x58 ). | |
5153 | This case will be ignored until the gcc bug is fixed. */ | |
5154 | return; | |
5155 | } | |
5156 | ||
82856980 SW |
5157 | /* Figure out the local name after import. */ |
5158 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 5159 | |
794684b6 SW |
5160 | /* Figure out where the statement is being imported to. */ |
5161 | import_prefix = determine_prefix (die, cu); | |
5162 | ||
5163 | /* Figure out what the scope of the imported die is and prepend it | |
5164 | to the name of the imported die. */ | |
de4affc9 | 5165 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 5166 | |
f55ee35c JK |
5167 | if (imported_die->tag != DW_TAG_namespace |
5168 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 5169 | { |
13387711 SW |
5170 | imported_declaration = imported_name; |
5171 | canonical_name = imported_name_prefix; | |
794684b6 | 5172 | } |
13387711 | 5173 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 5174 | { |
13387711 SW |
5175 | temp = alloca (strlen (imported_name_prefix) |
5176 | + 2 + strlen (imported_name) + 1); | |
5177 | strcpy (temp, imported_name_prefix); | |
5178 | strcat (temp, "::"); | |
5179 | strcat (temp, imported_name); | |
5180 | canonical_name = temp; | |
794684b6 | 5181 | } |
13387711 SW |
5182 | else |
5183 | canonical_name = imported_name; | |
794684b6 | 5184 | |
c0cc3a76 SW |
5185 | cp_add_using_directive (import_prefix, |
5186 | canonical_name, | |
5187 | import_alias, | |
13387711 | 5188 | imported_declaration, |
c0cc3a76 | 5189 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
5190 | } |
5191 | ||
5fb290d7 | 5192 | static void |
e142c38c | 5193 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 5194 | { |
e142c38c | 5195 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
5196 | } |
5197 | ||
ae2de4f8 DE |
5198 | /* Cleanup function for read_file_scope. */ |
5199 | ||
cb1df416 DJ |
5200 | static void |
5201 | free_cu_line_header (void *arg) | |
5202 | { | |
5203 | struct dwarf2_cu *cu = arg; | |
5204 | ||
5205 | free_line_header (cu->line_header); | |
5206 | cu->line_header = NULL; | |
5207 | } | |
5208 | ||
9291a0cd TT |
5209 | static void |
5210 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5211 | char **name, char **comp_dir) | |
5212 | { | |
5213 | struct attribute *attr; | |
5214 | ||
5215 | *name = NULL; | |
5216 | *comp_dir = NULL; | |
5217 | ||
5218 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5219 | is not a source language identifier. */ | |
5220 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5221 | if (attr) | |
5222 | { | |
5223 | *name = DW_STRING (attr); | |
5224 | } | |
5225 | ||
5226 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5227 | if (attr) | |
5228 | *comp_dir = DW_STRING (attr); | |
5229 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5230 | { | |
5231 | *comp_dir = ldirname (*name); | |
5232 | if (*comp_dir != NULL) | |
5233 | make_cleanup (xfree, *comp_dir); | |
5234 | } | |
5235 | if (*comp_dir != NULL) | |
5236 | { | |
5237 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5238 | directory, get rid of it. */ | |
5239 | char *cp = strchr (*comp_dir, ':'); | |
5240 | ||
5241 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5242 | *comp_dir = cp + 1; | |
5243 | } | |
5244 | ||
5245 | if (*name == NULL) | |
5246 | *name = "<unknown>"; | |
5247 | } | |
5248 | ||
ae2de4f8 DE |
5249 | /* Process DW_TAG_compile_unit. */ |
5250 | ||
c906108c | 5251 | static void |
e7c27a73 | 5252 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5253 | { |
e7c27a73 | 5254 | struct objfile *objfile = cu->objfile; |
debd256d | 5255 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5256 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5257 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5258 | struct attribute *attr; | |
e1024ff1 | 5259 | char *name = NULL; |
c906108c SS |
5260 | char *comp_dir = NULL; |
5261 | struct die_info *child_die; | |
5262 | bfd *abfd = objfile->obfd; | |
debd256d | 5263 | struct line_header *line_header = 0; |
e142c38c | 5264 | CORE_ADDR baseaddr; |
6e70227d | 5265 | |
e142c38c | 5266 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5267 | |
fae299cd | 5268 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5269 | |
5270 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5271 | from finish_block. */ | |
2acceee2 | 5272 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5273 | lowpc = highpc; |
5274 | lowpc += baseaddr; | |
5275 | highpc += baseaddr; | |
5276 | ||
9291a0cd | 5277 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5278 | |
e142c38c | 5279 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5280 | if (attr) |
5281 | { | |
e142c38c | 5282 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5283 | } |
5284 | ||
b0f35d58 | 5285 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5286 | if (attr) |
b0f35d58 | 5287 | cu->producer = DW_STRING (attr); |
303b6f5d | 5288 | |
f4b8a18d KW |
5289 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
5290 | standardised yet. As a workaround for the language detection we fall | |
5291 | back to the DW_AT_producer string. */ | |
5292 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) | |
5293 | cu->language = language_opencl; | |
5294 | ||
0963b4bd | 5295 | /* We assume that we're processing GCC output. */ |
c906108c | 5296 | processing_gcc_compilation = 2; |
c906108c | 5297 | |
df8a16a1 DJ |
5298 | processing_has_namespace_info = 0; |
5299 | ||
c906108c SS |
5300 | start_symtab (name, comp_dir, lowpc); |
5301 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5302 | record_producer (cu->producer); |
c906108c | 5303 | |
e142c38c | 5304 | initialize_cu_func_list (cu); |
c906108c | 5305 | |
cb1df416 DJ |
5306 | /* Decode line number information if present. We do this before |
5307 | processing child DIEs, so that the line header table is available | |
5308 | for DW_AT_decl_file. */ | |
e142c38c | 5309 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
5310 | if (attr) |
5311 | { | |
debd256d | 5312 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 5313 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
5314 | if (line_header) |
5315 | { | |
cb1df416 DJ |
5316 | cu->line_header = line_header; |
5317 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 5318 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 5319 | } |
5fb290d7 | 5320 | } |
debd256d | 5321 | |
cb1df416 DJ |
5322 | /* Process all dies in compilation unit. */ |
5323 | if (die->child != NULL) | |
5324 | { | |
5325 | child_die = die->child; | |
5326 | while (child_die && child_die->tag) | |
5327 | { | |
5328 | process_die (child_die, cu); | |
5329 | child_die = sibling_die (child_die); | |
5330 | } | |
5331 | } | |
5332 | ||
2e276125 JB |
5333 | /* Decode macro information, if present. Dwarf 2 macro information |
5334 | refers to information in the line number info statement program | |
5335 | header, so we can only read it if we've read the header | |
5336 | successfully. */ | |
e142c38c | 5337 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 5338 | if (attr && line_header) |
2e276125 JB |
5339 | { |
5340 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5341 | |
2e276125 | 5342 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 5343 | comp_dir, abfd, cu); |
2e276125 | 5344 | } |
debd256d | 5345 | do_cleanups (back_to); |
5fb290d7 DJ |
5346 | } |
5347 | ||
ae2de4f8 DE |
5348 | /* Process DW_TAG_type_unit. |
5349 | For TUs we want to skip the first top level sibling if it's not the | |
348e048f DE |
5350 | actual type being defined by this TU. In this case the first top |
5351 | level sibling is there to provide context only. */ | |
5352 | ||
5353 | static void | |
5354 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5355 | { | |
5356 | struct objfile *objfile = cu->objfile; | |
5357 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5358 | CORE_ADDR lowpc; | |
5359 | struct attribute *attr; | |
5360 | char *name = NULL; | |
5361 | char *comp_dir = NULL; | |
5362 | struct die_info *child_die; | |
5363 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5364 | |
5365 | /* start_symtab needs a low pc, but we don't really have one. | |
5366 | Do what read_file_scope would do in the absence of such info. */ | |
5367 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5368 | ||
5369 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5370 | is not a source language identifier. */ | |
5371 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5372 | if (attr) | |
5373 | name = DW_STRING (attr); | |
5374 | ||
5375 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5376 | if (attr) | |
5377 | comp_dir = DW_STRING (attr); | |
5378 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5379 | { | |
5380 | comp_dir = ldirname (name); | |
5381 | if (comp_dir != NULL) | |
5382 | make_cleanup (xfree, comp_dir); | |
5383 | } | |
5384 | ||
5385 | if (name == NULL) | |
5386 | name = "<unknown>"; | |
5387 | ||
5388 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5389 | if (attr) | |
5390 | set_cu_language (DW_UNSND (attr), cu); | |
5391 | ||
5392 | /* This isn't technically needed today. It is done for symmetry | |
5393 | with read_file_scope. */ | |
5394 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5395 | if (attr) |
348e048f DE |
5396 | cu->producer = DW_STRING (attr); |
5397 | ||
0963b4bd | 5398 | /* We assume that we're processing GCC output. */ |
348e048f DE |
5399 | processing_gcc_compilation = 2; |
5400 | ||
5401 | processing_has_namespace_info = 0; | |
5402 | ||
5403 | start_symtab (name, comp_dir, lowpc); | |
5404 | record_debugformat ("DWARF 2"); | |
5405 | record_producer (cu->producer); | |
5406 | ||
5407 | /* Process the dies in the type unit. */ | |
5408 | if (die->child == NULL) | |
5409 | { | |
5410 | dump_die_for_error (die); | |
5411 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5412 | bfd_get_filename (abfd)); | |
5413 | } | |
5414 | ||
5415 | child_die = die->child; | |
5416 | ||
5417 | while (child_die && child_die->tag) | |
5418 | { | |
5419 | process_die (child_die, cu); | |
5420 | ||
5421 | child_die = sibling_die (child_die); | |
5422 | } | |
5423 | ||
5424 | do_cleanups (back_to); | |
5425 | } | |
5426 | ||
5fb290d7 | 5427 | static void |
e142c38c DJ |
5428 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
5429 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
5430 | { |
5431 | struct function_range *thisfn; | |
5432 | ||
5433 | thisfn = (struct function_range *) | |
7b5a2f43 | 5434 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
5435 | thisfn->name = name; |
5436 | thisfn->lowpc = lowpc; | |
5437 | thisfn->highpc = highpc; | |
5438 | thisfn->seen_line = 0; | |
5439 | thisfn->next = NULL; | |
5440 | ||
e142c38c DJ |
5441 | if (cu->last_fn == NULL) |
5442 | cu->first_fn = thisfn; | |
5fb290d7 | 5443 | else |
e142c38c | 5444 | cu->last_fn->next = thisfn; |
5fb290d7 | 5445 | |
e142c38c | 5446 | cu->last_fn = thisfn; |
c906108c SS |
5447 | } |
5448 | ||
d389af10 JK |
5449 | /* qsort helper for inherit_abstract_dies. */ |
5450 | ||
5451 | static int | |
5452 | unsigned_int_compar (const void *ap, const void *bp) | |
5453 | { | |
5454 | unsigned int a = *(unsigned int *) ap; | |
5455 | unsigned int b = *(unsigned int *) bp; | |
5456 | ||
5457 | return (a > b) - (b > a); | |
5458 | } | |
5459 | ||
5460 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3e43a32a MS |
5461 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
5462 | already referenced by DW_AT_abstract_origin from the children of the | |
5463 | current DIE. */ | |
d389af10 JK |
5464 | |
5465 | static void | |
5466 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5467 | { | |
5468 | struct die_info *child_die; | |
5469 | unsigned die_children_count; | |
5470 | /* CU offsets which were referenced by children of the current DIE. */ | |
5471 | unsigned *offsets; | |
5472 | unsigned *offsets_end, *offsetp; | |
5473 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5474 | struct die_info *origin_die; | |
5475 | /* Iterator of the ORIGIN_DIE children. */ | |
5476 | struct die_info *origin_child_die; | |
5477 | struct cleanup *cleanups; | |
5478 | struct attribute *attr; | |
cd02d79d PA |
5479 | struct dwarf2_cu *origin_cu; |
5480 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5481 | |
5482 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5483 | if (!attr) | |
5484 | return; | |
5485 | ||
cd02d79d PA |
5486 | /* Note that following die references may follow to a die in a |
5487 | different cu. */ | |
5488 | ||
5489 | origin_cu = cu; | |
5490 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5491 | ||
5492 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5493 | symbols in. */ | |
5494 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5495 | origin_cu->list_in_scope = cu->list_in_scope; | |
5496 | ||
edb3359d DJ |
5497 | if (die->tag != origin_die->tag |
5498 | && !(die->tag == DW_TAG_inlined_subroutine | |
5499 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5500 | complaint (&symfile_complaints, |
5501 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5502 | die->offset, origin_die->offset); | |
5503 | ||
5504 | child_die = die->child; | |
5505 | die_children_count = 0; | |
5506 | while (child_die && child_die->tag) | |
5507 | { | |
5508 | child_die = sibling_die (child_die); | |
5509 | die_children_count++; | |
5510 | } | |
5511 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5512 | cleanups = make_cleanup (xfree, offsets); | |
5513 | ||
5514 | offsets_end = offsets; | |
5515 | child_die = die->child; | |
5516 | while (child_die && child_die->tag) | |
5517 | { | |
c38f313d DJ |
5518 | /* For each CHILD_DIE, find the corresponding child of |
5519 | ORIGIN_DIE. If there is more than one layer of | |
5520 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5521 | but GCC versions at least through 4.4 generate this (GCC PR | |
5522 | 40573). */ | |
5523 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5524 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5525 | |
c38f313d DJ |
5526 | while (1) |
5527 | { | |
cd02d79d PA |
5528 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5529 | child_origin_cu); | |
c38f313d DJ |
5530 | if (attr == NULL) |
5531 | break; | |
cd02d79d PA |
5532 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5533 | &child_origin_cu); | |
c38f313d DJ |
5534 | } |
5535 | ||
d389af10 JK |
5536 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5537 | counterpart may exist. */ | |
c38f313d | 5538 | if (child_origin_die != child_die) |
d389af10 | 5539 | { |
edb3359d DJ |
5540 | if (child_die->tag != child_origin_die->tag |
5541 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5542 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5543 | complaint (&symfile_complaints, |
5544 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5545 | "different tags"), child_die->offset, | |
5546 | child_origin_die->offset); | |
c38f313d DJ |
5547 | if (child_origin_die->parent != origin_die) |
5548 | complaint (&symfile_complaints, | |
5549 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5550 | "different parents"), child_die->offset, | |
5551 | child_origin_die->offset); | |
5552 | else | |
5553 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5554 | } |
5555 | child_die = sibling_die (child_die); | |
5556 | } | |
5557 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5558 | unsigned_int_compar); | |
5559 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5560 | if (offsetp[-1] == *offsetp) | |
3e43a32a MS |
5561 | complaint (&symfile_complaints, |
5562 | _("Multiple children of DIE 0x%x refer " | |
5563 | "to DIE 0x%x as their abstract origin"), | |
d389af10 JK |
5564 | die->offset, *offsetp); |
5565 | ||
5566 | offsetp = offsets; | |
5567 | origin_child_die = origin_die->child; | |
5568 | while (origin_child_die && origin_child_die->tag) | |
5569 | { | |
5570 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5571 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5572 | offsetp++; | |
5573 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5574 | { | |
5575 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5576 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5577 | } |
5578 | origin_child_die = sibling_die (origin_child_die); | |
5579 | } | |
cd02d79d | 5580 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5581 | |
5582 | do_cleanups (cleanups); | |
5583 | } | |
5584 | ||
c906108c | 5585 | static void |
e7c27a73 | 5586 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5587 | { |
e7c27a73 | 5588 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5589 | struct context_stack *new; |
c906108c SS |
5590 | CORE_ADDR lowpc; |
5591 | CORE_ADDR highpc; | |
5592 | struct die_info *child_die; | |
edb3359d | 5593 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5594 | char *name; |
e142c38c | 5595 | CORE_ADDR baseaddr; |
801e3a5b | 5596 | struct block *block; |
edb3359d | 5597 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5598 | VEC (symbolp) *template_args = NULL; |
5599 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5600 | |
5601 | if (inlined_func) | |
5602 | { | |
5603 | /* If we do not have call site information, we can't show the | |
5604 | caller of this inlined function. That's too confusing, so | |
5605 | only use the scope for local variables. */ | |
5606 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5607 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5608 | if (call_line == NULL || call_file == NULL) | |
5609 | { | |
5610 | read_lexical_block_scope (die, cu); | |
5611 | return; | |
5612 | } | |
5613 | } | |
c906108c | 5614 | |
e142c38c DJ |
5615 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5616 | ||
94af9270 | 5617 | name = dwarf2_name (die, cu); |
c906108c | 5618 | |
e8d05480 JB |
5619 | /* Ignore functions with missing or empty names. These are actually |
5620 | illegal according to the DWARF standard. */ | |
5621 | if (name == NULL) | |
5622 | { | |
5623 | complaint (&symfile_complaints, | |
5624 | _("missing name for subprogram DIE at %d"), die->offset); | |
5625 | return; | |
5626 | } | |
5627 | ||
5628 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5629 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5630 | { | |
ae4d0c03 PM |
5631 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5632 | if (!attr || !DW_UNSND (attr)) | |
5633 | complaint (&symfile_complaints, | |
3e43a32a MS |
5634 | _("cannot get low and high bounds " |
5635 | "for subprogram DIE at %d"), | |
ae4d0c03 | 5636 | die->offset); |
e8d05480 JB |
5637 | return; |
5638 | } | |
c906108c SS |
5639 | |
5640 | lowpc += baseaddr; | |
5641 | highpc += baseaddr; | |
5642 | ||
5fb290d7 | 5643 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 5644 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 5645 | |
34eaf542 TT |
5646 | /* If we have any template arguments, then we must allocate a |
5647 | different sort of symbol. */ | |
5648 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5649 | { | |
5650 | if (child_die->tag == DW_TAG_template_type_param | |
5651 | || child_die->tag == DW_TAG_template_value_param) | |
5652 | { | |
5653 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5654 | struct template_symbol); | |
5655 | templ_func->base.is_cplus_template_function = 1; | |
5656 | break; | |
5657 | } | |
5658 | } | |
5659 | ||
c906108c | 5660 | new = push_context (0, lowpc); |
34eaf542 TT |
5661 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5662 | (struct symbol *) templ_func); | |
4c2df51b | 5663 | |
4cecd739 DJ |
5664 | /* If there is a location expression for DW_AT_frame_base, record |
5665 | it. */ | |
e142c38c | 5666 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5667 | if (attr) |
c034e007 AC |
5668 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5669 | expression is being recorded directly in the function's symbol | |
5670 | and not in a separate frame-base object. I guess this hack is | |
5671 | to avoid adding some sort of frame-base adjunct/annex to the | |
5672 | function's symbol :-(. The problem with doing this is that it | |
5673 | results in a function symbol with a location expression that | |
5674 | has nothing to do with the location of the function, ouch! The | |
5675 | relationship should be: a function's symbol has-a frame base; a | |
5676 | frame-base has-a location expression. */ | |
e7c27a73 | 5677 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5678 | |
e142c38c | 5679 | cu->list_in_scope = &local_symbols; |
c906108c | 5680 | |
639d11d3 | 5681 | if (die->child != NULL) |
c906108c | 5682 | { |
639d11d3 | 5683 | child_die = die->child; |
c906108c SS |
5684 | while (child_die && child_die->tag) |
5685 | { | |
34eaf542 TT |
5686 | if (child_die->tag == DW_TAG_template_type_param |
5687 | || child_die->tag == DW_TAG_template_value_param) | |
5688 | { | |
5689 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5690 | ||
f1078f66 DJ |
5691 | if (arg != NULL) |
5692 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
5693 | } |
5694 | else | |
5695 | process_die (child_die, cu); | |
c906108c SS |
5696 | child_die = sibling_die (child_die); |
5697 | } | |
5698 | } | |
5699 | ||
d389af10 JK |
5700 | inherit_abstract_dies (die, cu); |
5701 | ||
4a811a97 UW |
5702 | /* If we have a DW_AT_specification, we might need to import using |
5703 | directives from the context of the specification DIE. See the | |
5704 | comment in determine_prefix. */ | |
5705 | if (cu->language == language_cplus | |
5706 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5707 | { | |
5708 | struct dwarf2_cu *spec_cu = cu; | |
5709 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5710 | ||
5711 | while (spec_die) | |
5712 | { | |
5713 | child_die = spec_die->child; | |
5714 | while (child_die && child_die->tag) | |
5715 | { | |
5716 | if (child_die->tag == DW_TAG_imported_module) | |
5717 | process_die (child_die, spec_cu); | |
5718 | child_die = sibling_die (child_die); | |
5719 | } | |
5720 | ||
5721 | /* In some cases, GCC generates specification DIEs that | |
5722 | themselves contain DW_AT_specification attributes. */ | |
5723 | spec_die = die_specification (spec_die, &spec_cu); | |
5724 | } | |
5725 | } | |
5726 | ||
c906108c SS |
5727 | new = pop_context (); |
5728 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
5729 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
5730 | lowpc, highpc, objfile); | |
5731 | ||
df8a16a1 | 5732 | /* For C++, set the block's scope. */ |
f55ee35c | 5733 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5734 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5735 | determine_prefix (die, cu), |
df8a16a1 DJ |
5736 | processing_has_namespace_info); |
5737 | ||
801e3a5b JB |
5738 | /* If we have address ranges, record them. */ |
5739 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5740 | |
34eaf542 TT |
5741 | /* Attach template arguments to function. */ |
5742 | if (! VEC_empty (symbolp, template_args)) | |
5743 | { | |
5744 | gdb_assert (templ_func != NULL); | |
5745 | ||
5746 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
5747 | templ_func->template_arguments | |
5748 | = obstack_alloc (&objfile->objfile_obstack, | |
5749 | (templ_func->n_template_arguments | |
5750 | * sizeof (struct symbol *))); | |
5751 | memcpy (templ_func->template_arguments, | |
5752 | VEC_address (symbolp, template_args), | |
5753 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
5754 | VEC_free (symbolp, template_args); | |
5755 | } | |
5756 | ||
208d8187 JB |
5757 | /* In C++, we can have functions nested inside functions (e.g., when |
5758 | a function declares a class that has methods). This means that | |
5759 | when we finish processing a function scope, we may need to go | |
5760 | back to building a containing block's symbol lists. */ | |
5761 | local_symbols = new->locals; | |
5762 | param_symbols = new->params; | |
27aa8d6a | 5763 | using_directives = new->using_directives; |
208d8187 | 5764 | |
921e78cf JB |
5765 | /* If we've finished processing a top-level function, subsequent |
5766 | symbols go in the file symbol list. */ | |
5767 | if (outermost_context_p ()) | |
e142c38c | 5768 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5769 | } |
5770 | ||
5771 | /* Process all the DIES contained within a lexical block scope. Start | |
5772 | a new scope, process the dies, and then close the scope. */ | |
5773 | ||
5774 | static void | |
e7c27a73 | 5775 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5776 | { |
e7c27a73 | 5777 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5778 | struct context_stack *new; |
c906108c SS |
5779 | CORE_ADDR lowpc, highpc; |
5780 | struct die_info *child_die; | |
e142c38c DJ |
5781 | CORE_ADDR baseaddr; |
5782 | ||
5783 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5784 | |
5785 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5786 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5787 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5788 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5789 | describe ranges. */ |
d85a05f0 | 5790 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5791 | return; |
5792 | lowpc += baseaddr; | |
5793 | highpc += baseaddr; | |
5794 | ||
5795 | push_context (0, lowpc); | |
639d11d3 | 5796 | if (die->child != NULL) |
c906108c | 5797 | { |
639d11d3 | 5798 | child_die = die->child; |
c906108c SS |
5799 | while (child_die && child_die->tag) |
5800 | { | |
e7c27a73 | 5801 | process_die (child_die, cu); |
c906108c SS |
5802 | child_die = sibling_die (child_die); |
5803 | } | |
5804 | } | |
5805 | new = pop_context (); | |
5806 | ||
8540c487 | 5807 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5808 | { |
801e3a5b JB |
5809 | struct block *block |
5810 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5811 | highpc, objfile); | |
5812 | ||
5813 | /* Note that recording ranges after traversing children, as we | |
5814 | do here, means that recording a parent's ranges entails | |
5815 | walking across all its children's ranges as they appear in | |
5816 | the address map, which is quadratic behavior. | |
5817 | ||
5818 | It would be nicer to record the parent's ranges before | |
5819 | traversing its children, simply overriding whatever you find | |
5820 | there. But since we don't even decide whether to create a | |
5821 | block until after we've traversed its children, that's hard | |
5822 | to do. */ | |
5823 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5824 | } |
5825 | local_symbols = new->locals; | |
27aa8d6a | 5826 | using_directives = new->using_directives; |
c906108c SS |
5827 | } |
5828 | ||
43039443 | 5829 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5830 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5831 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5832 | |
5833 | static int | |
5834 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5835 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5836 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5837 | { |
5838 | struct objfile *objfile = cu->objfile; | |
5839 | struct comp_unit_head *cu_header = &cu->header; | |
5840 | bfd *obfd = objfile->obfd; | |
5841 | unsigned int addr_size = cu_header->addr_size; | |
5842 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5843 | /* Base address selection entry. */ | |
5844 | CORE_ADDR base; | |
5845 | int found_base; | |
5846 | unsigned int dummy; | |
5847 | gdb_byte *buffer; | |
5848 | CORE_ADDR marker; | |
5849 | int low_set; | |
5850 | CORE_ADDR low = 0; | |
5851 | CORE_ADDR high = 0; | |
ff013f42 | 5852 | CORE_ADDR baseaddr; |
43039443 | 5853 | |
d00adf39 DE |
5854 | found_base = cu->base_known; |
5855 | base = cu->base_address; | |
43039443 | 5856 | |
be391dca | 5857 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5858 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5859 | { |
5860 | complaint (&symfile_complaints, | |
5861 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5862 | offset); | |
5863 | return 0; | |
5864 | } | |
dce234bc | 5865 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5866 | |
5867 | /* Read in the largest possible address. */ | |
5868 | marker = read_address (obfd, buffer, cu, &dummy); | |
5869 | if ((marker & mask) == mask) | |
5870 | { | |
5871 | /* If we found the largest possible address, then | |
5872 | read the base address. */ | |
5873 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5874 | buffer += 2 * addr_size; | |
5875 | offset += 2 * addr_size; | |
5876 | found_base = 1; | |
5877 | } | |
5878 | ||
5879 | low_set = 0; | |
5880 | ||
e7030f15 | 5881 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5882 | |
43039443 JK |
5883 | while (1) |
5884 | { | |
5885 | CORE_ADDR range_beginning, range_end; | |
5886 | ||
5887 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5888 | buffer += addr_size; | |
5889 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5890 | buffer += addr_size; | |
5891 | offset += 2 * addr_size; | |
5892 | ||
5893 | /* An end of list marker is a pair of zero addresses. */ | |
5894 | if (range_beginning == 0 && range_end == 0) | |
5895 | /* Found the end of list entry. */ | |
5896 | break; | |
5897 | ||
5898 | /* Each base address selection entry is a pair of 2 values. | |
5899 | The first is the largest possible address, the second is | |
5900 | the base address. Check for a base address here. */ | |
5901 | if ((range_beginning & mask) == mask) | |
5902 | { | |
5903 | /* If we found the largest possible address, then | |
5904 | read the base address. */ | |
5905 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5906 | found_base = 1; | |
5907 | continue; | |
5908 | } | |
5909 | ||
5910 | if (!found_base) | |
5911 | { | |
5912 | /* We have no valid base address for the ranges | |
5913 | data. */ | |
5914 | complaint (&symfile_complaints, | |
5915 | _("Invalid .debug_ranges data (no base address)")); | |
5916 | return 0; | |
5917 | } | |
5918 | ||
9277c30c UW |
5919 | if (range_beginning > range_end) |
5920 | { | |
5921 | /* Inverted range entries are invalid. */ | |
5922 | complaint (&symfile_complaints, | |
5923 | _("Invalid .debug_ranges data (inverted range)")); | |
5924 | return 0; | |
5925 | } | |
5926 | ||
5927 | /* Empty range entries have no effect. */ | |
5928 | if (range_beginning == range_end) | |
5929 | continue; | |
5930 | ||
43039443 JK |
5931 | range_beginning += base; |
5932 | range_end += base; | |
5933 | ||
9277c30c | 5934 | if (ranges_pst != NULL) |
ff013f42 | 5935 | addrmap_set_empty (objfile->psymtabs_addrmap, |
3e43a32a MS |
5936 | range_beginning + baseaddr, |
5937 | range_end - 1 + baseaddr, | |
ff013f42 JK |
5938 | ranges_pst); |
5939 | ||
43039443 JK |
5940 | /* FIXME: This is recording everything as a low-high |
5941 | segment of consecutive addresses. We should have a | |
5942 | data structure for discontiguous block ranges | |
5943 | instead. */ | |
5944 | if (! low_set) | |
5945 | { | |
5946 | low = range_beginning; | |
5947 | high = range_end; | |
5948 | low_set = 1; | |
5949 | } | |
5950 | else | |
5951 | { | |
5952 | if (range_beginning < low) | |
5953 | low = range_beginning; | |
5954 | if (range_end > high) | |
5955 | high = range_end; | |
5956 | } | |
5957 | } | |
5958 | ||
5959 | if (! low_set) | |
5960 | /* If the first entry is an end-of-list marker, the range | |
5961 | describes an empty scope, i.e. no instructions. */ | |
5962 | return 0; | |
5963 | ||
5964 | if (low_return) | |
5965 | *low_return = low; | |
5966 | if (high_return) | |
5967 | *high_return = high; | |
5968 | return 1; | |
5969 | } | |
5970 | ||
af34e669 DJ |
5971 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
5972 | are present and valid, otherwise, return 0. Return -1 if the range is | |
5973 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 5974 | static int |
af34e669 | 5975 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
5976 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
5977 | struct partial_symtab *pst) | |
c906108c SS |
5978 | { |
5979 | struct attribute *attr; | |
af34e669 DJ |
5980 | CORE_ADDR low = 0; |
5981 | CORE_ADDR high = 0; | |
5982 | int ret = 0; | |
c906108c | 5983 | |
e142c38c | 5984 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 5985 | if (attr) |
af34e669 DJ |
5986 | { |
5987 | high = DW_ADDR (attr); | |
e142c38c | 5988 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
5989 | if (attr) |
5990 | low = DW_ADDR (attr); | |
5991 | else | |
5992 | /* Found high w/o low attribute. */ | |
5993 | return 0; | |
5994 | ||
5995 | /* Found consecutive range of addresses. */ | |
5996 | ret = 1; | |
5997 | } | |
c906108c | 5998 | else |
af34e669 | 5999 | { |
e142c38c | 6000 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
6001 | if (attr != NULL) |
6002 | { | |
af34e669 | 6003 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 6004 | .debug_ranges section. */ |
d85a05f0 | 6005 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 6006 | return 0; |
43039443 | 6007 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
6008 | ret = -1; |
6009 | } | |
6010 | } | |
c906108c | 6011 | |
9373cf26 JK |
6012 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
6013 | if (high <= low) | |
c906108c SS |
6014 | return 0; |
6015 | ||
6016 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
6017 | eliminate duplicate copies of functions and vtables and such. | |
6018 | The linker will arbitrarily choose one and discard the others. | |
6019 | The AT_*_pc values for such functions refer to local labels in | |
6020 | these sections. If the section from that file was discarded, the | |
6021 | labels are not in the output, so the relocs get a value of 0. | |
6022 | If this is a discarded function, mark the pc bounds as invalid, | |
6023 | so that GDB will ignore it. */ | |
72dca2f5 | 6024 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
6025 | return 0; |
6026 | ||
6027 | *lowpc = low; | |
6028 | *highpc = high; | |
af34e669 | 6029 | return ret; |
c906108c SS |
6030 | } |
6031 | ||
b084d499 JB |
6032 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
6033 | its low and high PC addresses. Do nothing if these addresses could not | |
6034 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
6035 | and HIGHPC to the high address if greater than HIGHPC. */ | |
6036 | ||
6037 | static void | |
6038 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
6039 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6040 | struct dwarf2_cu *cu) | |
6041 | { | |
6042 | CORE_ADDR low, high; | |
6043 | struct die_info *child = die->child; | |
6044 | ||
d85a05f0 | 6045 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
6046 | { |
6047 | *lowpc = min (*lowpc, low); | |
6048 | *highpc = max (*highpc, high); | |
6049 | } | |
6050 | ||
6051 | /* If the language does not allow nested subprograms (either inside | |
6052 | subprograms or lexical blocks), we're done. */ | |
6053 | if (cu->language != language_ada) | |
6054 | return; | |
6e70227d | 6055 | |
b084d499 JB |
6056 | /* Check all the children of the given DIE. If it contains nested |
6057 | subprograms, then check their pc bounds. Likewise, we need to | |
6058 | check lexical blocks as well, as they may also contain subprogram | |
6059 | definitions. */ | |
6060 | while (child && child->tag) | |
6061 | { | |
6062 | if (child->tag == DW_TAG_subprogram | |
6063 | || child->tag == DW_TAG_lexical_block) | |
6064 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
6065 | child = sibling_die (child); | |
6066 | } | |
6067 | } | |
6068 | ||
fae299cd DC |
6069 | /* Get the low and high pc's represented by the scope DIE, and store |
6070 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
6071 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
6072 | ||
6073 | static void | |
6074 | get_scope_pc_bounds (struct die_info *die, | |
6075 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
6076 | struct dwarf2_cu *cu) | |
6077 | { | |
6078 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
6079 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
6080 | CORE_ADDR current_low, current_high; | |
6081 | ||
d85a05f0 | 6082 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
6083 | { |
6084 | best_low = current_low; | |
6085 | best_high = current_high; | |
6086 | } | |
6087 | else | |
6088 | { | |
6089 | struct die_info *child = die->child; | |
6090 | ||
6091 | while (child && child->tag) | |
6092 | { | |
6093 | switch (child->tag) { | |
6094 | case DW_TAG_subprogram: | |
b084d499 | 6095 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
6096 | break; |
6097 | case DW_TAG_namespace: | |
f55ee35c | 6098 | case DW_TAG_module: |
fae299cd DC |
6099 | /* FIXME: carlton/2004-01-16: Should we do this for |
6100 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
6101 | that current GCC's always emit the DIEs corresponding | |
6102 | to definitions of methods of classes as children of a | |
6103 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
6104 | the DIEs giving the declarations, which could be | |
6105 | anywhere). But I don't see any reason why the | |
6106 | standards says that they have to be there. */ | |
6107 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
6108 | ||
6109 | if (current_low != ((CORE_ADDR) -1)) | |
6110 | { | |
6111 | best_low = min (best_low, current_low); | |
6112 | best_high = max (best_high, current_high); | |
6113 | } | |
6114 | break; | |
6115 | default: | |
0963b4bd | 6116 | /* Ignore. */ |
fae299cd DC |
6117 | break; |
6118 | } | |
6119 | ||
6120 | child = sibling_die (child); | |
6121 | } | |
6122 | } | |
6123 | ||
6124 | *lowpc = best_low; | |
6125 | *highpc = best_high; | |
6126 | } | |
6127 | ||
801e3a5b JB |
6128 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
6129 | in DIE. */ | |
6130 | static void | |
6131 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
6132 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
6133 | { | |
6134 | struct attribute *attr; | |
6135 | ||
6136 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
6137 | if (attr) | |
6138 | { | |
6139 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 6140 | |
801e3a5b JB |
6141 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
6142 | if (attr) | |
6143 | { | |
6144 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 6145 | |
801e3a5b JB |
6146 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
6147 | } | |
6148 | } | |
6149 | ||
6150 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
6151 | if (attr) | |
6152 | { | |
6153 | bfd *obfd = cu->objfile->obfd; | |
6154 | ||
6155 | /* The value of the DW_AT_ranges attribute is the offset of the | |
6156 | address range list in the .debug_ranges section. */ | |
6157 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 6158 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
6159 | |
6160 | /* For some target architectures, but not others, the | |
6161 | read_address function sign-extends the addresses it returns. | |
6162 | To recognize base address selection entries, we need a | |
6163 | mask. */ | |
6164 | unsigned int addr_size = cu->header.addr_size; | |
6165 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
6166 | ||
6167 | /* The base address, to which the next pair is relative. Note | |
6168 | that this 'base' is a DWARF concept: most entries in a range | |
6169 | list are relative, to reduce the number of relocs against the | |
6170 | debugging information. This is separate from this function's | |
6171 | 'baseaddr' argument, which GDB uses to relocate debugging | |
6172 | information from a shared library based on the address at | |
6173 | which the library was loaded. */ | |
d00adf39 DE |
6174 | CORE_ADDR base = cu->base_address; |
6175 | int base_known = cu->base_known; | |
801e3a5b | 6176 | |
be391dca | 6177 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 6178 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
6179 | { |
6180 | complaint (&symfile_complaints, | |
6181 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
6182 | offset); | |
6183 | return; | |
6184 | } | |
6185 | ||
6186 | for (;;) | |
6187 | { | |
6188 | unsigned int bytes_read; | |
6189 | CORE_ADDR start, end; | |
6190 | ||
6191 | start = read_address (obfd, buffer, cu, &bytes_read); | |
6192 | buffer += bytes_read; | |
6193 | end = read_address (obfd, buffer, cu, &bytes_read); | |
6194 | buffer += bytes_read; | |
6195 | ||
6196 | /* Did we find the end of the range list? */ | |
6197 | if (start == 0 && end == 0) | |
6198 | break; | |
6199 | ||
6200 | /* Did we find a base address selection entry? */ | |
6201 | else if ((start & base_select_mask) == base_select_mask) | |
6202 | { | |
6203 | base = end; | |
6204 | base_known = 1; | |
6205 | } | |
6206 | ||
6207 | /* We found an ordinary address range. */ | |
6208 | else | |
6209 | { | |
6210 | if (!base_known) | |
6211 | { | |
6212 | complaint (&symfile_complaints, | |
3e43a32a MS |
6213 | _("Invalid .debug_ranges data " |
6214 | "(no base address)")); | |
801e3a5b JB |
6215 | return; |
6216 | } | |
6217 | ||
9277c30c UW |
6218 | if (start > end) |
6219 | { | |
6220 | /* Inverted range entries are invalid. */ | |
6221 | complaint (&symfile_complaints, | |
6222 | _("Invalid .debug_ranges data " | |
6223 | "(inverted range)")); | |
6224 | return; | |
6225 | } | |
6226 | ||
6227 | /* Empty range entries have no effect. */ | |
6228 | if (start == end) | |
6229 | continue; | |
6230 | ||
6e70227d DE |
6231 | record_block_range (block, |
6232 | baseaddr + base + start, | |
801e3a5b JB |
6233 | baseaddr + base + end - 1); |
6234 | } | |
6235 | } | |
6236 | } | |
6237 | } | |
6238 | ||
c906108c SS |
6239 | /* Add an aggregate field to the field list. */ |
6240 | ||
6241 | static void | |
107d2387 | 6242 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6243 | struct dwarf2_cu *cu) |
6e70227d | 6244 | { |
e7c27a73 | 6245 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6246 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6247 | struct nextfield *new_field; |
6248 | struct attribute *attr; | |
6249 | struct field *fp; | |
6250 | char *fieldname = ""; | |
6251 | ||
6252 | /* Allocate a new field list entry and link it in. */ | |
6253 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6254 | make_cleanup (xfree, new_field); |
c906108c | 6255 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6256 | |
6257 | if (die->tag == DW_TAG_inheritance) | |
6258 | { | |
6259 | new_field->next = fip->baseclasses; | |
6260 | fip->baseclasses = new_field; | |
6261 | } | |
6262 | else | |
6263 | { | |
6264 | new_field->next = fip->fields; | |
6265 | fip->fields = new_field; | |
6266 | } | |
c906108c SS |
6267 | fip->nfields++; |
6268 | ||
29e0eb9c JK |
6269 | /* Handle accessibility and virtuality of field. |
6270 | The default accessibility for members is public, the default | |
6271 | accessibility for inheritance is private. */ | |
6272 | if (die->tag != DW_TAG_inheritance) | |
6273 | new_field->accessibility = DW_ACCESS_public; | |
c906108c | 6274 | else |
29e0eb9c | 6275 | new_field->accessibility = DW_ACCESS_private; |
c906108c SS |
6276 | new_field->virtuality = DW_VIRTUALITY_none; |
6277 | ||
e142c38c | 6278 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6279 | if (attr) |
6280 | new_field->accessibility = DW_UNSND (attr); | |
6281 | if (new_field->accessibility != DW_ACCESS_public) | |
6282 | fip->non_public_fields = 1; | |
e142c38c | 6283 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6284 | if (attr) |
6285 | new_field->virtuality = DW_UNSND (attr); | |
6286 | ||
6287 | fp = &new_field->field; | |
a9a9bd0f | 6288 | |
e142c38c | 6289 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6290 | { |
a9a9bd0f | 6291 | /* Data member other than a C++ static data member. */ |
6e70227d | 6292 | |
c906108c | 6293 | /* Get type of field. */ |
e7c27a73 | 6294 | fp->type = die_type (die, cu); |
c906108c | 6295 | |
d6a843b5 | 6296 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6297 | |
c906108c | 6298 | /* Get bit size of field (zero if none). */ |
e142c38c | 6299 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6300 | if (attr) |
6301 | { | |
6302 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6303 | } | |
6304 | else | |
6305 | { | |
6306 | FIELD_BITSIZE (*fp) = 0; | |
6307 | } | |
6308 | ||
6309 | /* Get bit offset of field. */ | |
e142c38c | 6310 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
6311 | if (attr) |
6312 | { | |
d4b96c9a | 6313 | int byte_offset = 0; |
c6a0999f | 6314 | |
3690dd37 | 6315 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 6316 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 6317 | else if (attr_form_is_constant (attr)) |
c6a0999f | 6318 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 6319 | else if (attr_form_is_block (attr)) |
c6a0999f | 6320 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
6321 | else |
6322 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 6323 | |
d6a843b5 | 6324 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 6325 | } |
e142c38c | 6326 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6327 | if (attr) |
6328 | { | |
5e2b427d | 6329 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6330 | { |
6331 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6332 | additional bit offset from the MSB of the containing |
6333 | anonymous object to the MSB of the field. We don't | |
6334 | have to do anything special since we don't need to | |
6335 | know the size of the anonymous object. */ | |
c906108c SS |
6336 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6337 | } | |
6338 | else | |
6339 | { | |
6340 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6341 | MSB of the anonymous object, subtract off the number of |
6342 | bits from the MSB of the field to the MSB of the | |
6343 | object, and then subtract off the number of bits of | |
6344 | the field itself. The result is the bit offset of | |
6345 | the LSB of the field. */ | |
c906108c SS |
6346 | int anonymous_size; |
6347 | int bit_offset = DW_UNSND (attr); | |
6348 | ||
e142c38c | 6349 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6350 | if (attr) |
6351 | { | |
6352 | /* The size of the anonymous object containing | |
6353 | the bit field is explicit, so use the | |
6354 | indicated size (in bytes). */ | |
6355 | anonymous_size = DW_UNSND (attr); | |
6356 | } | |
6357 | else | |
6358 | { | |
6359 | /* The size of the anonymous object containing | |
6360 | the bit field must be inferred from the type | |
6361 | attribute of the data member containing the | |
6362 | bit field. */ | |
6363 | anonymous_size = TYPE_LENGTH (fp->type); | |
6364 | } | |
6365 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
6366 | - bit_offset - FIELD_BITSIZE (*fp); | |
6367 | } | |
6368 | } | |
6369 | ||
6370 | /* Get name of field. */ | |
39cbfefa DJ |
6371 | fieldname = dwarf2_name (die, cu); |
6372 | if (fieldname == NULL) | |
6373 | fieldname = ""; | |
d8151005 DJ |
6374 | |
6375 | /* The name is already allocated along with this objfile, so we don't | |
6376 | need to duplicate it for the type. */ | |
6377 | fp->name = fieldname; | |
c906108c SS |
6378 | |
6379 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 6380 | pointer or virtual base class pointer) to private. */ |
e142c38c | 6381 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 6382 | { |
d48cc9dd | 6383 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
6384 | new_field->accessibility = DW_ACCESS_private; |
6385 | fip->non_public_fields = 1; | |
6386 | } | |
6387 | } | |
a9a9bd0f | 6388 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 6389 | { |
a9a9bd0f DC |
6390 | /* C++ static member. */ |
6391 | ||
6392 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
6393 | is a declaration, but all versions of G++ as of this writing | |
6394 | (so through at least 3.2.1) incorrectly generate | |
6395 | DW_TAG_variable tags. */ | |
6e70227d | 6396 | |
c906108c | 6397 | char *physname; |
c906108c | 6398 | |
a9a9bd0f | 6399 | /* Get name of field. */ |
39cbfefa DJ |
6400 | fieldname = dwarf2_name (die, cu); |
6401 | if (fieldname == NULL) | |
c906108c SS |
6402 | return; |
6403 | ||
254e6b9e | 6404 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
6405 | if (attr |
6406 | /* Only create a symbol if this is an external value. | |
6407 | new_symbol checks this and puts the value in the global symbol | |
6408 | table, which we want. If it is not external, new_symbol | |
6409 | will try to put the value in cu->list_in_scope which is wrong. */ | |
6410 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
6411 | { |
6412 | /* A static const member, not much different than an enum as far as | |
6413 | we're concerned, except that we can support more types. */ | |
6414 | new_symbol (die, NULL, cu); | |
6415 | } | |
6416 | ||
2df3850c | 6417 | /* Get physical name. */ |
94af9270 | 6418 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 6419 | |
d8151005 DJ |
6420 | /* The name is already allocated along with this objfile, so we don't |
6421 | need to duplicate it for the type. */ | |
6422 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 6423 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 6424 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
6425 | } |
6426 | else if (die->tag == DW_TAG_inheritance) | |
6427 | { | |
6428 | /* C++ base class field. */ | |
e142c38c | 6429 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 6430 | if (attr) |
d4b96c9a JK |
6431 | { |
6432 | int byte_offset = 0; | |
6433 | ||
6434 | if (attr_form_is_section_offset (attr)) | |
6435 | dwarf2_complex_location_expr_complaint (); | |
6436 | else if (attr_form_is_constant (attr)) | |
6437 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
6438 | else if (attr_form_is_block (attr)) | |
6439 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6440 | else | |
6441 | dwarf2_complex_location_expr_complaint (); | |
6442 | ||
6443 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
6444 | } | |
c906108c | 6445 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 6446 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
6447 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
6448 | fip->nbaseclasses++; | |
6449 | } | |
6450 | } | |
6451 | ||
98751a41 JK |
6452 | /* Add a typedef defined in the scope of the FIP's class. */ |
6453 | ||
6454 | static void | |
6455 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
6456 | struct dwarf2_cu *cu) | |
6e70227d | 6457 | { |
98751a41 | 6458 | struct objfile *objfile = cu->objfile; |
98751a41 JK |
6459 | struct typedef_field_list *new_field; |
6460 | struct attribute *attr; | |
6461 | struct typedef_field *fp; | |
6462 | char *fieldname = ""; | |
6463 | ||
6464 | /* Allocate a new field list entry and link it in. */ | |
6465 | new_field = xzalloc (sizeof (*new_field)); | |
6466 | make_cleanup (xfree, new_field); | |
6467 | ||
6468 | gdb_assert (die->tag == DW_TAG_typedef); | |
6469 | ||
6470 | fp = &new_field->field; | |
6471 | ||
6472 | /* Get name of field. */ | |
6473 | fp->name = dwarf2_name (die, cu); | |
6474 | if (fp->name == NULL) | |
6475 | return; | |
6476 | ||
6477 | fp->type = read_type_die (die, cu); | |
6478 | ||
6479 | new_field->next = fip->typedef_field_list; | |
6480 | fip->typedef_field_list = new_field; | |
6481 | fip->typedef_field_list_count++; | |
6482 | } | |
6483 | ||
c906108c SS |
6484 | /* Create the vector of fields, and attach it to the type. */ |
6485 | ||
6486 | static void | |
fba45db2 | 6487 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6488 | struct dwarf2_cu *cu) |
c906108c SS |
6489 | { |
6490 | int nfields = fip->nfields; | |
6491 | ||
6492 | /* Record the field count, allocate space for the array of fields, | |
6493 | and create blank accessibility bitfields if necessary. */ | |
6494 | TYPE_NFIELDS (type) = nfields; | |
6495 | TYPE_FIELDS (type) = (struct field *) | |
6496 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
6497 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
6498 | ||
b4ba55a1 | 6499 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
6500 | { |
6501 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6502 | ||
6503 | TYPE_FIELD_PRIVATE_BITS (type) = | |
6504 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6505 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
6506 | ||
6507 | TYPE_FIELD_PROTECTED_BITS (type) = | |
6508 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6509 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
6510 | ||
774b6a14 TT |
6511 | TYPE_FIELD_IGNORE_BITS (type) = |
6512 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6513 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
6514 | } |
6515 | ||
6516 | /* If the type has baseclasses, allocate and clear a bit vector for | |
6517 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 6518 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
6519 | { |
6520 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 6521 | unsigned char *pointer; |
c906108c SS |
6522 | |
6523 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
6524 | pointer = TYPE_ALLOC (type, num_bytes); |
6525 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
6526 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
6527 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
6528 | } | |
6529 | ||
3e43a32a MS |
6530 | /* Copy the saved-up fields into the field vector. Start from the head of |
6531 | the list, adding to the tail of the field array, so that they end up in | |
6532 | the same order in the array in which they were added to the list. */ | |
c906108c SS |
6533 | while (nfields-- > 0) |
6534 | { | |
7d0ccb61 DJ |
6535 | struct nextfield *fieldp; |
6536 | ||
6537 | if (fip->fields) | |
6538 | { | |
6539 | fieldp = fip->fields; | |
6540 | fip->fields = fieldp->next; | |
6541 | } | |
6542 | else | |
6543 | { | |
6544 | fieldp = fip->baseclasses; | |
6545 | fip->baseclasses = fieldp->next; | |
6546 | } | |
6547 | ||
6548 | TYPE_FIELD (type, nfields) = fieldp->field; | |
6549 | switch (fieldp->accessibility) | |
c906108c | 6550 | { |
c5aa993b | 6551 | case DW_ACCESS_private: |
b4ba55a1 JB |
6552 | if (cu->language != language_ada) |
6553 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 6554 | break; |
c906108c | 6555 | |
c5aa993b | 6556 | case DW_ACCESS_protected: |
b4ba55a1 JB |
6557 | if (cu->language != language_ada) |
6558 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 6559 | break; |
c906108c | 6560 | |
c5aa993b JM |
6561 | case DW_ACCESS_public: |
6562 | break; | |
c906108c | 6563 | |
c5aa993b JM |
6564 | default: |
6565 | /* Unknown accessibility. Complain and treat it as public. */ | |
6566 | { | |
e2e0b3e5 | 6567 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 6568 | fieldp->accessibility); |
c5aa993b JM |
6569 | } |
6570 | break; | |
c906108c SS |
6571 | } |
6572 | if (nfields < fip->nbaseclasses) | |
6573 | { | |
7d0ccb61 | 6574 | switch (fieldp->virtuality) |
c906108c | 6575 | { |
c5aa993b JM |
6576 | case DW_VIRTUALITY_virtual: |
6577 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 | 6578 | if (cu->language == language_ada) |
a73c6dcd | 6579 | error (_("unexpected virtuality in component of Ada type")); |
c5aa993b JM |
6580 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
6581 | break; | |
c906108c SS |
6582 | } |
6583 | } | |
c906108c SS |
6584 | } |
6585 | } | |
6586 | ||
c906108c SS |
6587 | /* Add a member function to the proper fieldlist. */ |
6588 | ||
6589 | static void | |
107d2387 | 6590 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6591 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 6592 | { |
e7c27a73 | 6593 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6594 | struct attribute *attr; |
6595 | struct fnfieldlist *flp; | |
6596 | int i; | |
6597 | struct fn_field *fnp; | |
6598 | char *fieldname; | |
c906108c | 6599 | struct nextfnfield *new_fnfield; |
f792889a | 6600 | struct type *this_type; |
c906108c | 6601 | |
b4ba55a1 | 6602 | if (cu->language == language_ada) |
a73c6dcd | 6603 | error (_("unexpected member function in Ada type")); |
b4ba55a1 | 6604 | |
2df3850c | 6605 | /* Get name of member function. */ |
39cbfefa DJ |
6606 | fieldname = dwarf2_name (die, cu); |
6607 | if (fieldname == NULL) | |
2df3850c | 6608 | return; |
c906108c | 6609 | |
c906108c SS |
6610 | /* Look up member function name in fieldlist. */ |
6611 | for (i = 0; i < fip->nfnfields; i++) | |
6612 | { | |
27bfe10e | 6613 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
6614 | break; |
6615 | } | |
6616 | ||
6617 | /* Create new list element if necessary. */ | |
6618 | if (i < fip->nfnfields) | |
6619 | flp = &fip->fnfieldlists[i]; | |
6620 | else | |
6621 | { | |
6622 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6623 | { | |
6624 | fip->fnfieldlists = (struct fnfieldlist *) | |
6625 | xrealloc (fip->fnfieldlists, | |
6626 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6627 | * sizeof (struct fnfieldlist)); |
c906108c | 6628 | if (fip->nfnfields == 0) |
c13c43fd | 6629 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
6630 | } |
6631 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
6632 | flp->name = fieldname; | |
6633 | flp->length = 0; | |
6634 | flp->head = NULL; | |
3da10d80 | 6635 | i = fip->nfnfields++; |
c906108c SS |
6636 | } |
6637 | ||
6638 | /* Create a new member function field and chain it to the field list | |
0963b4bd | 6639 | entry. */ |
c906108c | 6640 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
b8c9b27d | 6641 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
6642 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
6643 | new_fnfield->next = flp->head; | |
6644 | flp->head = new_fnfield; | |
6645 | flp->length++; | |
6646 | ||
6647 | /* Fill in the member function field info. */ | |
6648 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
6649 | |
6650 | /* Delay processing of the physname until later. */ | |
6651 | if (cu->language == language_cplus || cu->language == language_java) | |
6652 | { | |
6653 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
6654 | die, cu); | |
6655 | } | |
6656 | else | |
6657 | { | |
6658 | char *physname = (char *) dwarf2_physname (fieldname, die, cu); | |
6659 | fnp->physname = physname ? physname : ""; | |
6660 | } | |
6661 | ||
c906108c | 6662 | fnp->type = alloc_type (objfile); |
f792889a DJ |
6663 | this_type = read_type_die (die, cu); |
6664 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 6665 | { |
f792889a | 6666 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 6667 | |
f792889a | 6668 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
6669 | of the method itself (TYPE_CODE_METHOD). */ |
6670 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
6671 | TYPE_TARGET_TYPE (this_type), |
6672 | TYPE_FIELDS (this_type), | |
6673 | TYPE_NFIELDS (this_type), | |
6674 | TYPE_VARARGS (this_type)); | |
c906108c SS |
6675 | |
6676 | /* Handle static member functions. | |
c5aa993b | 6677 | Dwarf2 has no clean way to discern C++ static and non-static |
0963b4bd MS |
6678 | member functions. G++ helps GDB by marking the first |
6679 | parameter for non-static member functions (which is the this | |
6680 | pointer) as artificial. We obtain this information from | |
6681 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 6682 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
6683 | fnp->voffset = VOFFSET_STATIC; |
6684 | } | |
6685 | else | |
e2e0b3e5 | 6686 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 6687 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
6688 | |
6689 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 6690 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 6691 | fnp->fcontext = die_containing_type (die, cu); |
c906108c | 6692 | |
3e43a32a MS |
6693 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
6694 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
c906108c SS |
6695 | |
6696 | /* Get accessibility. */ | |
e142c38c | 6697 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6698 | if (attr) |
6699 | { | |
6700 | switch (DW_UNSND (attr)) | |
6701 | { | |
c5aa993b JM |
6702 | case DW_ACCESS_private: |
6703 | fnp->is_private = 1; | |
6704 | break; | |
6705 | case DW_ACCESS_protected: | |
6706 | fnp->is_protected = 1; | |
6707 | break; | |
c906108c SS |
6708 | } |
6709 | } | |
6710 | ||
b02dede2 | 6711 | /* Check for artificial methods. */ |
e142c38c | 6712 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
6713 | if (attr && DW_UNSND (attr) != 0) |
6714 | fnp->is_artificial = 1; | |
6715 | ||
0d564a31 | 6716 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
6717 | function. For older versions of GCC, this is an offset in the |
6718 | appropriate virtual table, as specified by DW_AT_containing_type. | |
6719 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
6720 | to the object address. */ |
6721 | ||
e142c38c | 6722 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 6723 | if (attr) |
8e19ed76 | 6724 | { |
aec5aa8b | 6725 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 6726 | { |
aec5aa8b TT |
6727 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
6728 | { | |
6729 | /* Old-style GCC. */ | |
6730 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
6731 | } | |
6732 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6733 | || (DW_BLOCK (attr)->size > 1 | |
6734 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
6735 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
6736 | { | |
6737 | struct dwarf_block blk; | |
6738 | int offset; | |
6739 | ||
6740 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6741 | ? 1 : 2); | |
6742 | blk.size = DW_BLOCK (attr)->size - offset; | |
6743 | blk.data = DW_BLOCK (attr)->data + offset; | |
6744 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
6745 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
6746 | dwarf2_complex_location_expr_complaint (); | |
6747 | else | |
6748 | fnp->voffset /= cu->header.addr_size; | |
6749 | fnp->voffset += 2; | |
6750 | } | |
6751 | else | |
6752 | dwarf2_complex_location_expr_complaint (); | |
6753 | ||
6754 | if (!fnp->fcontext) | |
6755 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
6756 | } | |
3690dd37 | 6757 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6758 | { |
4d3c2250 | 6759 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6760 | } |
6761 | else | |
6762 | { | |
4d3c2250 KB |
6763 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
6764 | fieldname); | |
8e19ed76 | 6765 | } |
0d564a31 | 6766 | } |
d48cc9dd DJ |
6767 | else |
6768 | { | |
6769 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
6770 | if (attr && DW_UNSND (attr)) | |
6771 | { | |
6772 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
6773 | complaint (&symfile_complaints, | |
3e43a32a MS |
6774 | _("Member function \"%s\" (offset %d) is virtual " |
6775 | "but the vtable offset is not specified"), | |
d48cc9dd | 6776 | fieldname, die->offset); |
9655fd1a | 6777 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
6778 | TYPE_CPLUS_DYNAMIC (type) = 1; |
6779 | } | |
6780 | } | |
c906108c SS |
6781 | } |
6782 | ||
6783 | /* Create the vector of member function fields, and attach it to the type. */ | |
6784 | ||
6785 | static void | |
fba45db2 | 6786 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6787 | struct dwarf2_cu *cu) |
c906108c SS |
6788 | { |
6789 | struct fnfieldlist *flp; | |
6790 | int total_length = 0; | |
6791 | int i; | |
6792 | ||
b4ba55a1 | 6793 | if (cu->language == language_ada) |
a73c6dcd | 6794 | error (_("unexpected member functions in Ada type")); |
b4ba55a1 | 6795 | |
c906108c SS |
6796 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6797 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6798 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6799 | ||
6800 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6801 | { | |
6802 | struct nextfnfield *nfp = flp->head; | |
6803 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6804 | int k; | |
6805 | ||
6806 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6807 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6808 | fn_flp->fn_fields = (struct fn_field *) | |
6809 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6810 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6811 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6812 | |
6813 | total_length += flp->length; | |
6814 | } | |
6815 | ||
6816 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6817 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6818 | } | |
6819 | ||
1168df01 JB |
6820 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6821 | language, zero otherwise. */ | |
6822 | static int | |
6823 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6824 | { | |
6825 | static const char vptr[] = "_vptr"; | |
987504bb | 6826 | static const char vtable[] = "vtable"; |
1168df01 | 6827 | |
987504bb JJ |
6828 | /* Look for the C++ and Java forms of the vtable. */ |
6829 | if ((cu->language == language_java | |
6830 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6831 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
6832 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
6833 | return 1; |
6834 | ||
6835 | return 0; | |
6836 | } | |
6837 | ||
c0dd20ea | 6838 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
6839 | functions, with the ABI-specified layout. If TYPE describes |
6840 | such a structure, smash it into a member function type. | |
61049d3b DJ |
6841 | |
6842 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
6843 | This is GCC PR debug/28767. */ | |
c0dd20ea | 6844 | |
0b92b5bb TT |
6845 | static void |
6846 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 6847 | { |
0b92b5bb | 6848 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
6849 | |
6850 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
6851 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
6852 | return; | |
c0dd20ea DJ |
6853 | |
6854 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
6855 | if (TYPE_FIELD_NAME (type, 0) == NULL |
6856 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
6857 | || TYPE_FIELD_NAME (type, 1) == NULL | |
6858 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
6859 | return; | |
c0dd20ea DJ |
6860 | |
6861 | /* Find the type of the method. */ | |
0b92b5bb | 6862 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
6863 | if (pfn_type == NULL |
6864 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
6865 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 6866 | return; |
c0dd20ea DJ |
6867 | |
6868 | /* Look for the "this" argument. */ | |
6869 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
6870 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 6871 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 6872 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 6873 | return; |
c0dd20ea DJ |
6874 | |
6875 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
6876 | new_type = alloc_type (objfile); |
6877 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
6878 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
6879 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 6880 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 6881 | } |
1168df01 | 6882 | |
c906108c | 6883 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
6884 | (definition) to create a type for the structure or union. Fill in |
6885 | the type's name and general properties; the members will not be | |
6886 | processed until process_structure_type. | |
c906108c | 6887 | |
c767944b DJ |
6888 | NOTE: we need to call these functions regardless of whether or not the |
6889 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
6890 | structure or union. This gets the type entered into our set of |
6891 | user defined types. | |
6892 | ||
6893 | However, if the structure is incomplete (an opaque struct/union) | |
6894 | then suppress creating a symbol table entry for it since gdb only | |
6895 | wants to find the one with the complete definition. Note that if | |
6896 | it is complete, we just call new_symbol, which does it's own | |
6897 | checking about whether the struct/union is anonymous or not (and | |
6898 | suppresses creating a symbol table entry itself). */ | |
6899 | ||
f792889a | 6900 | static struct type * |
134d01f1 | 6901 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6902 | { |
e7c27a73 | 6903 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6904 | struct type *type; |
6905 | struct attribute *attr; | |
39cbfefa | 6906 | char *name; |
c906108c | 6907 | |
348e048f DE |
6908 | /* If the definition of this type lives in .debug_types, read that type. |
6909 | Don't follow DW_AT_specification though, that will take us back up | |
6910 | the chain and we want to go down. */ | |
6911 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6912 | if (attr) | |
6913 | { | |
6914 | struct dwarf2_cu *type_cu = cu; | |
6915 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6916 | |
348e048f DE |
6917 | /* We could just recurse on read_structure_type, but we need to call |
6918 | get_die_type to ensure only one type for this DIE is created. | |
6919 | This is important, for example, because for c++ classes we need | |
6920 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
6921 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
6922 | |
6923 | /* TYPE_CU may not be the same as CU. | |
6924 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
6925 | return set_die_type (die, type, cu); |
6926 | } | |
6927 | ||
c0dd20ea | 6928 | type = alloc_type (objfile); |
c906108c | 6929 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 6930 | |
39cbfefa DJ |
6931 | name = dwarf2_name (die, cu); |
6932 | if (name != NULL) | |
c906108c | 6933 | { |
987504bb JJ |
6934 | if (cu->language == language_cplus |
6935 | || cu->language == language_java) | |
63d06c5c | 6936 | { |
3da10d80 KS |
6937 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
6938 | ||
6939 | /* dwarf2_full_name might have already finished building the DIE's | |
6940 | type. If so, there is no need to continue. */ | |
6941 | if (get_die_type (die, cu) != NULL) | |
6942 | return get_die_type (die, cu); | |
6943 | ||
6944 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
6945 | if (die->tag == DW_TAG_structure_type |
6946 | || die->tag == DW_TAG_class_type) | |
6947 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
6948 | } |
6949 | else | |
6950 | { | |
d8151005 DJ |
6951 | /* The name is already allocated along with this objfile, so |
6952 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
6953 | TYPE_TAG_NAME (type) = (char *) name; |
6954 | if (die->tag == DW_TAG_class_type) | |
6955 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 6956 | } |
c906108c SS |
6957 | } |
6958 | ||
6959 | if (die->tag == DW_TAG_structure_type) | |
6960 | { | |
6961 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
6962 | } | |
6963 | else if (die->tag == DW_TAG_union_type) | |
6964 | { | |
6965 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
6966 | } | |
6967 | else | |
6968 | { | |
c906108c SS |
6969 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
6970 | } | |
6971 | ||
0cc2414c TT |
6972 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
6973 | TYPE_DECLARED_CLASS (type) = 1; | |
6974 | ||
e142c38c | 6975 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6976 | if (attr) |
6977 | { | |
6978 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6979 | } | |
6980 | else | |
6981 | { | |
6982 | TYPE_LENGTH (type) = 0; | |
6983 | } | |
6984 | ||
876cecd0 | 6985 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 6986 | if (die_is_declaration (die, cu)) |
876cecd0 | 6987 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
6988 | else if (attr == NULL && die->child == NULL |
6989 | && producer_is_realview (cu->producer)) | |
6990 | /* RealView does not output the required DW_AT_declaration | |
6991 | on incomplete types. */ | |
6992 | TYPE_STUB (type) = 1; | |
dc718098 | 6993 | |
c906108c SS |
6994 | /* We need to add the type field to the die immediately so we don't |
6995 | infinitely recurse when dealing with pointers to the structure | |
0963b4bd | 6996 | type within the structure itself. */ |
1c379e20 | 6997 | set_die_type (die, type, cu); |
c906108c | 6998 | |
7e314c57 JK |
6999 | /* set_die_type should be already done. */ |
7000 | set_descriptive_type (type, die, cu); | |
7001 | ||
c767944b DJ |
7002 | return type; |
7003 | } | |
7004 | ||
7005 | /* Finish creating a structure or union type, including filling in | |
7006 | its members and creating a symbol for it. */ | |
7007 | ||
7008 | static void | |
7009 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7010 | { | |
7011 | struct objfile *objfile = cu->objfile; | |
7012 | struct die_info *child_die = die->child; | |
7013 | struct type *type; | |
7014 | ||
7015 | type = get_die_type (die, cu); | |
7016 | if (type == NULL) | |
7017 | type = read_structure_type (die, cu); | |
7018 | ||
e142c38c | 7019 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
7020 | { |
7021 | struct field_info fi; | |
7022 | struct die_info *child_die; | |
34eaf542 | 7023 | VEC (symbolp) *template_args = NULL; |
c767944b | 7024 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
7025 | |
7026 | memset (&fi, 0, sizeof (struct field_info)); | |
7027 | ||
639d11d3 | 7028 | child_die = die->child; |
c906108c SS |
7029 | |
7030 | while (child_die && child_die->tag) | |
7031 | { | |
a9a9bd0f DC |
7032 | if (child_die->tag == DW_TAG_member |
7033 | || child_die->tag == DW_TAG_variable) | |
c906108c | 7034 | { |
a9a9bd0f DC |
7035 | /* NOTE: carlton/2002-11-05: A C++ static data member |
7036 | should be a DW_TAG_member that is a declaration, but | |
7037 | all versions of G++ as of this writing (so through at | |
7038 | least 3.2.1) incorrectly generate DW_TAG_variable | |
7039 | tags for them instead. */ | |
e7c27a73 | 7040 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7041 | } |
8713b1b1 | 7042 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c | 7043 | { |
0963b4bd | 7044 | /* C++ member function. */ |
e7c27a73 | 7045 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
7046 | } |
7047 | else if (child_die->tag == DW_TAG_inheritance) | |
7048 | { | |
7049 | /* C++ base class field. */ | |
e7c27a73 | 7050 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 7051 | } |
98751a41 JK |
7052 | else if (child_die->tag == DW_TAG_typedef) |
7053 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
7054 | else if (child_die->tag == DW_TAG_template_type_param |
7055 | || child_die->tag == DW_TAG_template_value_param) | |
7056 | { | |
7057 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
7058 | ||
f1078f66 DJ |
7059 | if (arg != NULL) |
7060 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
7061 | } |
7062 | ||
c906108c SS |
7063 | child_die = sibling_die (child_die); |
7064 | } | |
7065 | ||
34eaf542 TT |
7066 | /* Attach template arguments to type. */ |
7067 | if (! VEC_empty (symbolp, template_args)) | |
7068 | { | |
7069 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
7070 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7071 | = VEC_length (symbolp, template_args); | |
7072 | TYPE_TEMPLATE_ARGUMENTS (type) | |
7073 | = obstack_alloc (&objfile->objfile_obstack, | |
7074 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7075 | * sizeof (struct symbol *))); | |
7076 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
7077 | VEC_address (symbolp, template_args), | |
7078 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
7079 | * sizeof (struct symbol *))); | |
7080 | VEC_free (symbolp, template_args); | |
7081 | } | |
7082 | ||
c906108c SS |
7083 | /* Attach fields and member functions to the type. */ |
7084 | if (fi.nfields) | |
e7c27a73 | 7085 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
7086 | if (fi.nfnfields) |
7087 | { | |
e7c27a73 | 7088 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 7089 | |
c5aa993b | 7090 | /* Get the type which refers to the base class (possibly this |
c906108c | 7091 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
7092 | class from the DW_AT_containing_type attribute. This use of |
7093 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 7094 | |
e142c38c | 7095 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 7096 | { |
e7c27a73 | 7097 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
7098 | |
7099 | TYPE_VPTR_BASETYPE (type) = t; | |
7100 | if (type == t) | |
7101 | { | |
c906108c SS |
7102 | int i; |
7103 | ||
7104 | /* Our own class provides vtbl ptr. */ | |
7105 | for (i = TYPE_NFIELDS (t) - 1; | |
7106 | i >= TYPE_N_BASECLASSES (t); | |
7107 | --i) | |
7108 | { | |
7109 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
7110 | ||
1168df01 | 7111 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
7112 | { |
7113 | TYPE_VPTR_FIELDNO (type) = i; | |
7114 | break; | |
7115 | } | |
7116 | } | |
7117 | ||
7118 | /* Complain if virtual function table field not found. */ | |
7119 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 7120 | complaint (&symfile_complaints, |
3e43a32a MS |
7121 | _("virtual function table pointer " |
7122 | "not found when defining class '%s'"), | |
4d3c2250 KB |
7123 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
7124 | ""); | |
c906108c SS |
7125 | } |
7126 | else | |
7127 | { | |
7128 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
7129 | } | |
7130 | } | |
f6235d4c EZ |
7131 | else if (cu->producer |
7132 | && strncmp (cu->producer, | |
7133 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
7134 | { | |
7135 | /* The IBM XLC compiler does not provide direct indication | |
7136 | of the containing type, but the vtable pointer is | |
7137 | always named __vfp. */ | |
7138 | ||
7139 | int i; | |
7140 | ||
7141 | for (i = TYPE_NFIELDS (type) - 1; | |
7142 | i >= TYPE_N_BASECLASSES (type); | |
7143 | --i) | |
7144 | { | |
7145 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
7146 | { | |
7147 | TYPE_VPTR_FIELDNO (type) = i; | |
7148 | TYPE_VPTR_BASETYPE (type) = type; | |
7149 | break; | |
7150 | } | |
7151 | } | |
7152 | } | |
c906108c | 7153 | } |
98751a41 JK |
7154 | |
7155 | /* Copy fi.typedef_field_list linked list elements content into the | |
7156 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
7157 | if (fi.typedef_field_list) | |
7158 | { | |
7159 | int i = fi.typedef_field_list_count; | |
7160 | ||
a0d7a4ff | 7161 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
7162 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
7163 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
7164 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
7165 | ||
7166 | /* Reverse the list order to keep the debug info elements order. */ | |
7167 | while (--i >= 0) | |
7168 | { | |
7169 | struct typedef_field *dest, *src; | |
6e70227d | 7170 | |
98751a41 JK |
7171 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
7172 | src = &fi.typedef_field_list->field; | |
7173 | fi.typedef_field_list = fi.typedef_field_list->next; | |
7174 | *dest = *src; | |
7175 | } | |
7176 | } | |
c767944b DJ |
7177 | |
7178 | do_cleanups (back_to); | |
c906108c | 7179 | } |
63d06c5c | 7180 | |
0b92b5bb TT |
7181 | quirk_gcc_member_function_pointer (type, cu->objfile); |
7182 | ||
90aeadfc DC |
7183 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
7184 | snapshots) has been known to create a die giving a declaration | |
7185 | for a class that has, as a child, a die giving a definition for a | |
7186 | nested class. So we have to process our children even if the | |
7187 | current die is a declaration. Normally, of course, a declaration | |
7188 | won't have any children at all. */ | |
134d01f1 | 7189 | |
90aeadfc DC |
7190 | while (child_die != NULL && child_die->tag) |
7191 | { | |
7192 | if (child_die->tag == DW_TAG_member | |
7193 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
7194 | || child_die->tag == DW_TAG_inheritance |
7195 | || child_die->tag == DW_TAG_template_value_param | |
7196 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 7197 | { |
90aeadfc | 7198 | /* Do nothing. */ |
134d01f1 | 7199 | } |
90aeadfc DC |
7200 | else |
7201 | process_die (child_die, cu); | |
134d01f1 | 7202 | |
90aeadfc | 7203 | child_die = sibling_die (child_die); |
134d01f1 DJ |
7204 | } |
7205 | ||
fa4028e9 JB |
7206 | /* Do not consider external references. According to the DWARF standard, |
7207 | these DIEs are identified by the fact that they have no byte_size | |
7208 | attribute, and a declaration attribute. */ | |
7209 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
7210 | || !die_is_declaration (die, cu)) | |
c767944b | 7211 | new_symbol (die, type, cu); |
134d01f1 DJ |
7212 | } |
7213 | ||
7214 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
7215 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 7216 | |
f792889a | 7217 | static struct type * |
134d01f1 | 7218 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7219 | { |
e7c27a73 | 7220 | struct objfile *objfile = cu->objfile; |
c906108c | 7221 | struct type *type; |
c906108c | 7222 | struct attribute *attr; |
0114d602 | 7223 | const char *name; |
134d01f1 | 7224 | |
348e048f DE |
7225 | /* If the definition of this type lives in .debug_types, read that type. |
7226 | Don't follow DW_AT_specification though, that will take us back up | |
7227 | the chain and we want to go down. */ | |
7228 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7229 | if (attr) | |
7230 | { | |
7231 | struct dwarf2_cu *type_cu = cu; | |
7232 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7233 | |
348e048f | 7234 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7235 | |
7236 | /* TYPE_CU may not be the same as CU. | |
7237 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7238 | return set_die_type (die, type, cu); |
7239 | } | |
7240 | ||
c906108c SS |
7241 | type = alloc_type (objfile); |
7242 | ||
7243 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7244 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7245 | if (name != NULL) |
0114d602 | 7246 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7247 | |
e142c38c | 7248 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7249 | if (attr) |
7250 | { | |
7251 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7252 | } | |
7253 | else | |
7254 | { | |
7255 | TYPE_LENGTH (type) = 0; | |
7256 | } | |
7257 | ||
137033e9 JB |
7258 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7259 | declared as private in the package spec, and then defined only | |
7260 | inside the package body. Such types are known as Taft Amendment | |
7261 | Types. When another package uses such a type, an incomplete DIE | |
7262 | may be generated by the compiler. */ | |
02eb380e | 7263 | if (die_is_declaration (die, cu)) |
876cecd0 | 7264 | TYPE_STUB (type) = 1; |
02eb380e | 7265 | |
f792889a | 7266 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7267 | } |
7268 | ||
7269 | /* Given a pointer to a die which begins an enumeration, process all | |
7270 | the dies that define the members of the enumeration, and create the | |
7271 | symbol for the enumeration type. | |
7272 | ||
7273 | NOTE: We reverse the order of the element list. */ | |
7274 | ||
7275 | static void | |
7276 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7277 | { | |
f792889a | 7278 | struct type *this_type; |
134d01f1 | 7279 | |
f792889a DJ |
7280 | this_type = get_die_type (die, cu); |
7281 | if (this_type == NULL) | |
7282 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7283 | |
639d11d3 | 7284 | if (die->child != NULL) |
c906108c | 7285 | { |
9dc481d3 DE |
7286 | struct die_info *child_die; |
7287 | struct symbol *sym; | |
7288 | struct field *fields = NULL; | |
7289 | int num_fields = 0; | |
7290 | int unsigned_enum = 1; | |
7291 | char *name; | |
7292 | ||
639d11d3 | 7293 | child_die = die->child; |
c906108c SS |
7294 | while (child_die && child_die->tag) |
7295 | { | |
7296 | if (child_die->tag != DW_TAG_enumerator) | |
7297 | { | |
e7c27a73 | 7298 | process_die (child_die, cu); |
c906108c SS |
7299 | } |
7300 | else | |
7301 | { | |
39cbfefa DJ |
7302 | name = dwarf2_name (child_die, cu); |
7303 | if (name) | |
c906108c | 7304 | { |
f792889a | 7305 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7306 | if (SYMBOL_VALUE (sym) < 0) |
7307 | unsigned_enum = 0; | |
7308 | ||
7309 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7310 | { | |
7311 | fields = (struct field *) | |
7312 | xrealloc (fields, | |
7313 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7314 | * sizeof (struct field)); |
c906108c SS |
7315 | } |
7316 | ||
3567439c | 7317 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7318 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7319 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7320 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7321 | ||
7322 | num_fields++; | |
7323 | } | |
7324 | } | |
7325 | ||
7326 | child_die = sibling_die (child_die); | |
7327 | } | |
7328 | ||
7329 | if (num_fields) | |
7330 | { | |
f792889a DJ |
7331 | TYPE_NFIELDS (this_type) = num_fields; |
7332 | TYPE_FIELDS (this_type) = (struct field *) | |
7333 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7334 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7335 | sizeof (struct field) * num_fields); |
b8c9b27d | 7336 | xfree (fields); |
c906108c SS |
7337 | } |
7338 | if (unsigned_enum) | |
876cecd0 | 7339 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7340 | } |
134d01f1 | 7341 | |
f792889a | 7342 | new_symbol (die, this_type, cu); |
c906108c SS |
7343 | } |
7344 | ||
7345 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7346 | the DIE's type field. For now, this only handles one dimensional | |
7347 | arrays. */ | |
7348 | ||
f792889a | 7349 | static struct type * |
e7c27a73 | 7350 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7351 | { |
e7c27a73 | 7352 | struct objfile *objfile = cu->objfile; |
c906108c | 7353 | struct die_info *child_die; |
7e314c57 | 7354 | struct type *type; |
c906108c SS |
7355 | struct type *element_type, *range_type, *index_type; |
7356 | struct type **range_types = NULL; | |
7357 | struct attribute *attr; | |
7358 | int ndim = 0; | |
7359 | struct cleanup *back_to; | |
39cbfefa | 7360 | char *name; |
c906108c | 7361 | |
e7c27a73 | 7362 | element_type = die_type (die, cu); |
c906108c | 7363 | |
7e314c57 JK |
7364 | /* The die_type call above may have already set the type for this DIE. */ |
7365 | type = get_die_type (die, cu); | |
7366 | if (type) | |
7367 | return type; | |
7368 | ||
c906108c SS |
7369 | /* Irix 6.2 native cc creates array types without children for |
7370 | arrays with unspecified length. */ | |
639d11d3 | 7371 | if (die->child == NULL) |
c906108c | 7372 | { |
46bf5051 | 7373 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7374 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
7375 | type = create_array_type (NULL, element_type, range_type); |
7376 | return set_die_type (die, type, cu); | |
c906108c SS |
7377 | } |
7378 | ||
7379 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 7380 | child_die = die->child; |
c906108c SS |
7381 | while (child_die && child_die->tag) |
7382 | { | |
7383 | if (child_die->tag == DW_TAG_subrange_type) | |
7384 | { | |
f792889a | 7385 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 7386 | |
f792889a | 7387 | if (child_type != NULL) |
a02abb62 | 7388 | { |
0963b4bd MS |
7389 | /* The range type was succesfully read. Save it for the |
7390 | array type creation. */ | |
a02abb62 JB |
7391 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
7392 | { | |
7393 | range_types = (struct type **) | |
7394 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
7395 | * sizeof (struct type *)); | |
7396 | if (ndim == 0) | |
7397 | make_cleanup (free_current_contents, &range_types); | |
7398 | } | |
f792889a | 7399 | range_types[ndim++] = child_type; |
a02abb62 | 7400 | } |
c906108c SS |
7401 | } |
7402 | child_die = sibling_die (child_die); | |
7403 | } | |
7404 | ||
7405 | /* Dwarf2 dimensions are output from left to right, create the | |
7406 | necessary array types in backwards order. */ | |
7ca2d3a3 | 7407 | |
c906108c | 7408 | type = element_type; |
7ca2d3a3 DL |
7409 | |
7410 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
7411 | { | |
7412 | int i = 0; | |
9a619af0 | 7413 | |
7ca2d3a3 DL |
7414 | while (i < ndim) |
7415 | type = create_array_type (NULL, type, range_types[i++]); | |
7416 | } | |
7417 | else | |
7418 | { | |
7419 | while (ndim-- > 0) | |
7420 | type = create_array_type (NULL, type, range_types[ndim]); | |
7421 | } | |
c906108c | 7422 | |
f5f8a009 EZ |
7423 | /* Understand Dwarf2 support for vector types (like they occur on |
7424 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
7425 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
7426 | custom vendor extension. The main difference between a regular | |
7427 | array and the vector variant is that vectors are passed by value | |
7428 | to functions. */ | |
e142c38c | 7429 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 7430 | if (attr) |
ea37ba09 | 7431 | make_vector_type (type); |
f5f8a009 | 7432 | |
dbc98a8b KW |
7433 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
7434 | implementation may choose to implement triple vectors using this | |
7435 | attribute. */ | |
7436 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
7437 | if (attr) | |
7438 | { | |
7439 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) | |
7440 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7441 | else | |
3e43a32a MS |
7442 | complaint (&symfile_complaints, |
7443 | _("DW_AT_byte_size for array type smaller " | |
7444 | "than the total size of elements")); | |
dbc98a8b KW |
7445 | } |
7446 | ||
39cbfefa DJ |
7447 | name = dwarf2_name (die, cu); |
7448 | if (name) | |
7449 | TYPE_NAME (type) = name; | |
6e70227d | 7450 | |
0963b4bd | 7451 | /* Install the type in the die. */ |
7e314c57 JK |
7452 | set_die_type (die, type, cu); |
7453 | ||
7454 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7455 | set_descriptive_type (type, die, cu); |
7456 | ||
c906108c SS |
7457 | do_cleanups (back_to); |
7458 | ||
7e314c57 | 7459 | return type; |
c906108c SS |
7460 | } |
7461 | ||
7ca2d3a3 | 7462 | static enum dwarf_array_dim_ordering |
6e70227d | 7463 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
7464 | { |
7465 | struct attribute *attr; | |
7466 | ||
7467 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
7468 | ||
7469 | if (attr) return DW_SND (attr); | |
7470 | ||
0963b4bd MS |
7471 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
7472 | opposite order to the dwarf2 specification, but data is still | |
7473 | laid out as per normal fortran. | |
7ca2d3a3 | 7474 | |
0963b4bd MS |
7475 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7476 | version checking. */ | |
7ca2d3a3 | 7477 | |
905e0470 PM |
7478 | if (cu->language == language_fortran |
7479 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
7480 | { |
7481 | return DW_ORD_row_major; | |
7482 | } | |
7483 | ||
6e70227d | 7484 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
7485 | { |
7486 | case array_column_major: | |
7487 | return DW_ORD_col_major; | |
7488 | case array_row_major: | |
7489 | default: | |
7490 | return DW_ORD_row_major; | |
7491 | }; | |
7492 | } | |
7493 | ||
72019c9c | 7494 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
0963b4bd | 7495 | the DIE's type field. */ |
72019c9c | 7496 | |
f792889a | 7497 | static struct type * |
72019c9c GM |
7498 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
7499 | { | |
7e314c57 JK |
7500 | struct type *domain_type, *set_type; |
7501 | struct attribute *attr; | |
f792889a | 7502 | |
7e314c57 JK |
7503 | domain_type = die_type (die, cu); |
7504 | ||
7505 | /* The die_type call above may have already set the type for this DIE. */ | |
7506 | set_type = get_die_type (die, cu); | |
7507 | if (set_type) | |
7508 | return set_type; | |
7509 | ||
7510 | set_type = create_set_type (NULL, domain_type); | |
7511 | ||
7512 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
7513 | if (attr) |
7514 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 7515 | |
f792889a | 7516 | return set_die_type (die, set_type, cu); |
72019c9c | 7517 | } |
7ca2d3a3 | 7518 | |
c906108c SS |
7519 | /* First cut: install each common block member as a global variable. */ |
7520 | ||
7521 | static void | |
e7c27a73 | 7522 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7523 | { |
7524 | struct die_info *child_die; | |
7525 | struct attribute *attr; | |
7526 | struct symbol *sym; | |
7527 | CORE_ADDR base = (CORE_ADDR) 0; | |
7528 | ||
e142c38c | 7529 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7530 | if (attr) |
7531 | { | |
0963b4bd | 7532 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
7533 | if (attr_form_is_block (attr)) |
7534 | { | |
e7c27a73 | 7535 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 7536 | } |
3690dd37 | 7537 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7538 | { |
4d3c2250 | 7539 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7540 | } |
7541 | else | |
7542 | { | |
4d3c2250 KB |
7543 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
7544 | "common block member"); | |
8e19ed76 | 7545 | } |
c906108c | 7546 | } |
639d11d3 | 7547 | if (die->child != NULL) |
c906108c | 7548 | { |
639d11d3 | 7549 | child_die = die->child; |
c906108c SS |
7550 | while (child_die && child_die->tag) |
7551 | { | |
e7c27a73 | 7552 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 7553 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
f1078f66 | 7554 | if (sym != NULL && attr != NULL) |
c906108c | 7555 | { |
d4b96c9a JK |
7556 | CORE_ADDR byte_offset = 0; |
7557 | ||
7558 | if (attr_form_is_section_offset (attr)) | |
7559 | dwarf2_complex_location_expr_complaint (); | |
7560 | else if (attr_form_is_constant (attr)) | |
7561 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
7562 | else if (attr_form_is_block (attr)) | |
7563 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
7564 | else | |
7565 | dwarf2_complex_location_expr_complaint (); | |
7566 | ||
7567 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
7568 | add_symbol_to_list (sym, &global_symbols); |
7569 | } | |
7570 | child_die = sibling_die (child_die); | |
7571 | } | |
7572 | } | |
7573 | } | |
7574 | ||
0114d602 | 7575 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 7576 | |
0114d602 DJ |
7577 | static struct type * |
7578 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 7579 | { |
e7c27a73 | 7580 | struct objfile *objfile = cu->objfile; |
0114d602 | 7581 | const char *previous_prefix, *name; |
9219021c | 7582 | int is_anonymous; |
0114d602 DJ |
7583 | struct type *type; |
7584 | ||
7585 | /* For extensions, reuse the type of the original namespace. */ | |
7586 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
7587 | { | |
7588 | struct die_info *ext_die; | |
7589 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 7590 | |
0114d602 DJ |
7591 | ext_die = dwarf2_extension (die, &ext_cu); |
7592 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
7593 | |
7594 | /* EXT_CU may not be the same as CU. | |
7595 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
7596 | return set_die_type (die, type, cu); |
7597 | } | |
9219021c | 7598 | |
e142c38c | 7599 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
7600 | |
7601 | /* Now build the name of the current namespace. */ | |
7602 | ||
0114d602 DJ |
7603 | previous_prefix = determine_prefix (die, cu); |
7604 | if (previous_prefix[0] != '\0') | |
7605 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 7606 | previous_prefix, name, 0, cu); |
0114d602 DJ |
7607 | |
7608 | /* Create the type. */ | |
7609 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
7610 | objfile); | |
7611 | TYPE_NAME (type) = (char *) name; | |
7612 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7613 | ||
60531b24 | 7614 | return set_die_type (die, type, cu); |
0114d602 DJ |
7615 | } |
7616 | ||
7617 | /* Read a C++ namespace. */ | |
7618 | ||
7619 | static void | |
7620 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
7621 | { | |
7622 | struct objfile *objfile = cu->objfile; | |
0114d602 | 7623 | int is_anonymous; |
9219021c | 7624 | |
5c4e30ca DC |
7625 | /* Add a symbol associated to this if we haven't seen the namespace |
7626 | before. Also, add a using directive if it's an anonymous | |
7627 | namespace. */ | |
9219021c | 7628 | |
f2f0e013 | 7629 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
7630 | { |
7631 | struct type *type; | |
7632 | ||
0114d602 | 7633 | type = read_type_die (die, cu); |
e7c27a73 | 7634 | new_symbol (die, type, cu); |
5c4e30ca | 7635 | |
e8e80198 | 7636 | namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 7637 | if (is_anonymous) |
0114d602 DJ |
7638 | { |
7639 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 7640 | |
c0cc3a76 | 7641 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 7642 | NULL, &objfile->objfile_obstack); |
0114d602 | 7643 | } |
5c4e30ca | 7644 | } |
9219021c | 7645 | |
639d11d3 | 7646 | if (die->child != NULL) |
d9fa45fe | 7647 | { |
639d11d3 | 7648 | struct die_info *child_die = die->child; |
6e70227d | 7649 | |
d9fa45fe DC |
7650 | while (child_die && child_die->tag) |
7651 | { | |
e7c27a73 | 7652 | process_die (child_die, cu); |
d9fa45fe DC |
7653 | child_die = sibling_die (child_die); |
7654 | } | |
7655 | } | |
38d518c9 EZ |
7656 | } |
7657 | ||
f55ee35c JK |
7658 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
7659 | imported module. Still we need that type as local Fortran "use ... only" | |
7660 | declaration imports depend on the created type in determine_prefix. */ | |
7661 | ||
7662 | static struct type * | |
7663 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
7664 | { | |
7665 | struct objfile *objfile = cu->objfile; | |
7666 | char *module_name; | |
7667 | struct type *type; | |
7668 | ||
7669 | module_name = dwarf2_name (die, cu); | |
7670 | if (!module_name) | |
3e43a32a MS |
7671 | complaint (&symfile_complaints, |
7672 | _("DW_TAG_module has no name, offset 0x%x"), | |
f55ee35c JK |
7673 | die->offset); |
7674 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
7675 | ||
7676 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
7677 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7678 | ||
7679 | return set_die_type (die, type, cu); | |
7680 | } | |
7681 | ||
5d7cb8df JK |
7682 | /* Read a Fortran module. */ |
7683 | ||
7684 | static void | |
7685 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
7686 | { | |
7687 | struct die_info *child_die = die->child; | |
7688 | ||
5d7cb8df JK |
7689 | while (child_die && child_die->tag) |
7690 | { | |
7691 | process_die (child_die, cu); | |
7692 | child_die = sibling_die (child_die); | |
7693 | } | |
7694 | } | |
7695 | ||
38d518c9 EZ |
7696 | /* Return the name of the namespace represented by DIE. Set |
7697 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
7698 | namespace. */ | |
7699 | ||
7700 | static const char * | |
e142c38c | 7701 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
7702 | { |
7703 | struct die_info *current_die; | |
7704 | const char *name = NULL; | |
7705 | ||
7706 | /* Loop through the extensions until we find a name. */ | |
7707 | ||
7708 | for (current_die = die; | |
7709 | current_die != NULL; | |
f2f0e013 | 7710 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 7711 | { |
e142c38c | 7712 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
7713 | if (name != NULL) |
7714 | break; | |
7715 | } | |
7716 | ||
7717 | /* Is it an anonymous namespace? */ | |
7718 | ||
7719 | *is_anonymous = (name == NULL); | |
7720 | if (*is_anonymous) | |
7721 | name = "(anonymous namespace)"; | |
7722 | ||
7723 | return name; | |
d9fa45fe DC |
7724 | } |
7725 | ||
c906108c SS |
7726 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
7727 | the user defined type vector. */ | |
7728 | ||
f792889a | 7729 | static struct type * |
e7c27a73 | 7730 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7731 | { |
5e2b427d | 7732 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 7733 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 7734 | struct type *type; |
8b2dbe47 KB |
7735 | struct attribute *attr_byte_size; |
7736 | struct attribute *attr_address_class; | |
7737 | int byte_size, addr_class; | |
7e314c57 JK |
7738 | struct type *target_type; |
7739 | ||
7740 | target_type = die_type (die, cu); | |
c906108c | 7741 | |
7e314c57 JK |
7742 | /* The die_type call above may have already set the type for this DIE. */ |
7743 | type = get_die_type (die, cu); | |
7744 | if (type) | |
7745 | return type; | |
7746 | ||
7747 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 7748 | |
e142c38c | 7749 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
7750 | if (attr_byte_size) |
7751 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 7752 | else |
8b2dbe47 KB |
7753 | byte_size = cu_header->addr_size; |
7754 | ||
e142c38c | 7755 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
7756 | if (attr_address_class) |
7757 | addr_class = DW_UNSND (attr_address_class); | |
7758 | else | |
7759 | addr_class = DW_ADDR_none; | |
7760 | ||
7761 | /* If the pointer size or address class is different than the | |
7762 | default, create a type variant marked as such and set the | |
7763 | length accordingly. */ | |
7764 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 7765 | { |
5e2b427d | 7766 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
7767 | { |
7768 | int type_flags; | |
7769 | ||
849957d9 | 7770 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 7771 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
7772 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
7773 | == 0); | |
8b2dbe47 KB |
7774 | type = make_type_with_address_space (type, type_flags); |
7775 | } | |
7776 | else if (TYPE_LENGTH (type) != byte_size) | |
7777 | { | |
3e43a32a MS |
7778 | complaint (&symfile_complaints, |
7779 | _("invalid pointer size %d"), byte_size); | |
8b2dbe47 | 7780 | } |
6e70227d | 7781 | else |
9a619af0 MS |
7782 | { |
7783 | /* Should we also complain about unhandled address classes? */ | |
7784 | } | |
c906108c | 7785 | } |
8b2dbe47 KB |
7786 | |
7787 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 7788 | return set_die_type (die, type, cu); |
c906108c SS |
7789 | } |
7790 | ||
7791 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
7792 | the user defined type vector. */ | |
7793 | ||
f792889a | 7794 | static struct type * |
e7c27a73 | 7795 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7796 | { |
7797 | struct type *type; | |
7798 | struct type *to_type; | |
7799 | struct type *domain; | |
7800 | ||
e7c27a73 DJ |
7801 | to_type = die_type (die, cu); |
7802 | domain = die_containing_type (die, cu); | |
0d5de010 | 7803 | |
7e314c57 JK |
7804 | /* The calls above may have already set the type for this DIE. */ |
7805 | type = get_die_type (die, cu); | |
7806 | if (type) | |
7807 | return type; | |
7808 | ||
0d5de010 DJ |
7809 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
7810 | type = lookup_methodptr_type (to_type); | |
7811 | else | |
7812 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 7813 | |
f792889a | 7814 | return set_die_type (die, type, cu); |
c906108c SS |
7815 | } |
7816 | ||
7817 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
7818 | the user defined type vector. */ | |
7819 | ||
f792889a | 7820 | static struct type * |
e7c27a73 | 7821 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7822 | { |
e7c27a73 | 7823 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 7824 | struct type *type, *target_type; |
c906108c SS |
7825 | struct attribute *attr; |
7826 | ||
7e314c57 JK |
7827 | target_type = die_type (die, cu); |
7828 | ||
7829 | /* The die_type call above may have already set the type for this DIE. */ | |
7830 | type = get_die_type (die, cu); | |
7831 | if (type) | |
7832 | return type; | |
7833 | ||
7834 | type = lookup_reference_type (target_type); | |
e142c38c | 7835 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7836 | if (attr) |
7837 | { | |
7838 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7839 | } | |
7840 | else | |
7841 | { | |
107d2387 | 7842 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 7843 | } |
f792889a | 7844 | return set_die_type (die, type, cu); |
c906108c SS |
7845 | } |
7846 | ||
f792889a | 7847 | static struct type * |
e7c27a73 | 7848 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7849 | { |
f792889a | 7850 | struct type *base_type, *cv_type; |
c906108c | 7851 | |
e7c27a73 | 7852 | base_type = die_type (die, cu); |
7e314c57 JK |
7853 | |
7854 | /* The die_type call above may have already set the type for this DIE. */ | |
7855 | cv_type = get_die_type (die, cu); | |
7856 | if (cv_type) | |
7857 | return cv_type; | |
7858 | ||
2f608a3a KW |
7859 | /* In case the const qualifier is applied to an array type, the element type |
7860 | is so qualified, not the array type (section 6.7.3 of C99). */ | |
7861 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) | |
7862 | { | |
7863 | struct type *el_type, *inner_array; | |
7864 | ||
7865 | base_type = copy_type (base_type); | |
7866 | inner_array = base_type; | |
7867 | ||
7868 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) | |
7869 | { | |
7870 | TYPE_TARGET_TYPE (inner_array) = | |
7871 | copy_type (TYPE_TARGET_TYPE (inner_array)); | |
7872 | inner_array = TYPE_TARGET_TYPE (inner_array); | |
7873 | } | |
7874 | ||
7875 | el_type = TYPE_TARGET_TYPE (inner_array); | |
7876 | TYPE_TARGET_TYPE (inner_array) = | |
7877 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); | |
7878 | ||
7879 | return set_die_type (die, base_type, cu); | |
7880 | } | |
7881 | ||
f792889a DJ |
7882 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
7883 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7884 | } |
7885 | ||
f792889a | 7886 | static struct type * |
e7c27a73 | 7887 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7888 | { |
f792889a | 7889 | struct type *base_type, *cv_type; |
c906108c | 7890 | |
e7c27a73 | 7891 | base_type = die_type (die, cu); |
7e314c57 JK |
7892 | |
7893 | /* The die_type call above may have already set the type for this DIE. */ | |
7894 | cv_type = get_die_type (die, cu); | |
7895 | if (cv_type) | |
7896 | return cv_type; | |
7897 | ||
f792889a DJ |
7898 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
7899 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7900 | } |
7901 | ||
7902 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
7903 | the user defined type vector. It isn't really a user defined type, | |
7904 | but it behaves like one, with other DIE's using an AT_user_def_type | |
7905 | attribute to reference it. */ | |
7906 | ||
f792889a | 7907 | static struct type * |
e7c27a73 | 7908 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7909 | { |
e7c27a73 | 7910 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 7911 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7912 | struct type *type, *range_type, *index_type, *char_type; |
7913 | struct attribute *attr; | |
7914 | unsigned int length; | |
7915 | ||
e142c38c | 7916 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
7917 | if (attr) |
7918 | { | |
7919 | length = DW_UNSND (attr); | |
7920 | } | |
7921 | else | |
7922 | { | |
0963b4bd | 7923 | /* Check for the DW_AT_byte_size attribute. */ |
e142c38c | 7924 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
7925 | if (attr) |
7926 | { | |
7927 | length = DW_UNSND (attr); | |
7928 | } | |
7929 | else | |
7930 | { | |
7931 | length = 1; | |
7932 | } | |
c906108c | 7933 | } |
6ccb9162 | 7934 | |
46bf5051 | 7935 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7936 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
7937 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
7938 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 7939 | |
f792889a | 7940 | return set_die_type (die, type, cu); |
c906108c SS |
7941 | } |
7942 | ||
7943 | /* Handle DIES due to C code like: | |
7944 | ||
7945 | struct foo | |
c5aa993b JM |
7946 | { |
7947 | int (*funcp)(int a, long l); | |
7948 | int b; | |
7949 | }; | |
c906108c | 7950 | |
0963b4bd | 7951 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
c906108c | 7952 | |
f792889a | 7953 | static struct type * |
e7c27a73 | 7954 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7955 | { |
0963b4bd MS |
7956 | struct type *type; /* Type that this function returns. */ |
7957 | struct type *ftype; /* Function that returns above type. */ | |
c906108c SS |
7958 | struct attribute *attr; |
7959 | ||
e7c27a73 | 7960 | type = die_type (die, cu); |
7e314c57 JK |
7961 | |
7962 | /* The die_type call above may have already set the type for this DIE. */ | |
7963 | ftype = get_die_type (die, cu); | |
7964 | if (ftype) | |
7965 | return ftype; | |
7966 | ||
0c8b41f1 | 7967 | ftype = lookup_function_type (type); |
c906108c | 7968 | |
5b8101ae | 7969 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 7970 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 7971 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 7972 | || cu->language == language_cplus |
5b8101ae PM |
7973 | || cu->language == language_java |
7974 | || cu->language == language_pascal) | |
876cecd0 | 7975 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
7976 | else if (producer_is_realview (cu->producer)) |
7977 | /* RealView does not emit DW_AT_prototyped. We can not | |
7978 | distinguish prototyped and unprototyped functions; default to | |
7979 | prototyped, since that is more common in modern code (and | |
7980 | RealView warns about unprototyped functions). */ | |
7981 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 7982 | |
c055b101 CV |
7983 | /* Store the calling convention in the type if it's available in |
7984 | the subroutine die. Otherwise set the calling convention to | |
7985 | the default value DW_CC_normal. */ | |
7986 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
54fcddd0 UW |
7987 | if (attr) |
7988 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); | |
7989 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) | |
7990 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; | |
7991 | else | |
7992 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; | |
76c10ea2 GM |
7993 | |
7994 | /* We need to add the subroutine type to the die immediately so | |
7995 | we don't infinitely recurse when dealing with parameters | |
0963b4bd | 7996 | declared as the same subroutine type. */ |
76c10ea2 | 7997 | set_die_type (die, ftype, cu); |
6e70227d | 7998 | |
639d11d3 | 7999 | if (die->child != NULL) |
c906108c | 8000 | { |
8072405b | 8001 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 8002 | struct die_info *child_die; |
8072405b | 8003 | int nparams, iparams; |
c906108c SS |
8004 | |
8005 | /* Count the number of parameters. | |
8006 | FIXME: GDB currently ignores vararg functions, but knows about | |
8007 | vararg member functions. */ | |
8072405b | 8008 | nparams = 0; |
639d11d3 | 8009 | child_die = die->child; |
c906108c SS |
8010 | while (child_die && child_die->tag) |
8011 | { | |
8012 | if (child_die->tag == DW_TAG_formal_parameter) | |
8013 | nparams++; | |
8014 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 8015 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
8016 | child_die = sibling_die (child_die); |
8017 | } | |
8018 | ||
8019 | /* Allocate storage for parameters and fill them in. */ | |
8020 | TYPE_NFIELDS (ftype) = nparams; | |
8021 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 8022 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 8023 | |
8072405b JK |
8024 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
8025 | even if we error out during the parameters reading below. */ | |
8026 | for (iparams = 0; iparams < nparams; iparams++) | |
8027 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
8028 | ||
8029 | iparams = 0; | |
639d11d3 | 8030 | child_die = die->child; |
c906108c SS |
8031 | while (child_die && child_die->tag) |
8032 | { | |
8033 | if (child_die->tag == DW_TAG_formal_parameter) | |
8034 | { | |
3ce3b1ba PA |
8035 | struct type *arg_type; |
8036 | ||
8037 | /* DWARF version 2 has no clean way to discern C++ | |
8038 | static and non-static member functions. G++ helps | |
8039 | GDB by marking the first parameter for non-static | |
8040 | member functions (which is the this pointer) as | |
8041 | artificial. We pass this information to | |
8042 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
8043 | ||
8044 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
8045 | 4.5 does not yet generate. */ | |
e142c38c | 8046 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
8047 | if (attr) |
8048 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
8049 | else | |
418835cc KS |
8050 | { |
8051 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
8052 | ||
8053 | /* GCC/43521: In java, the formal parameter | |
8054 | "this" is sometimes not marked with DW_AT_artificial. */ | |
8055 | if (cu->language == language_java) | |
8056 | { | |
8057 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 8058 | |
418835cc KS |
8059 | if (name && !strcmp (name, "this")) |
8060 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
8061 | } | |
8062 | } | |
3ce3b1ba PA |
8063 | arg_type = die_type (child_die, cu); |
8064 | ||
8065 | /* RealView does not mark THIS as const, which the testsuite | |
8066 | expects. GCC marks THIS as const in method definitions, | |
8067 | but not in the class specifications (GCC PR 43053). */ | |
8068 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
8069 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
8070 | { | |
8071 | int is_this = 0; | |
8072 | struct dwarf2_cu *arg_cu = cu; | |
8073 | const char *name = dwarf2_name (child_die, cu); | |
8074 | ||
8075 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
8076 | if (attr) | |
8077 | { | |
8078 | /* If the compiler emits this, use it. */ | |
8079 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
8080 | is_this = 1; | |
8081 | } | |
8082 | else if (name && strcmp (name, "this") == 0) | |
8083 | /* Function definitions will have the argument names. */ | |
8084 | is_this = 1; | |
8085 | else if (name == NULL && iparams == 0) | |
8086 | /* Declarations may not have the names, so like | |
8087 | elsewhere in GDB, assume an artificial first | |
8088 | argument is "this". */ | |
8089 | is_this = 1; | |
8090 | ||
8091 | if (is_this) | |
8092 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
8093 | arg_type, 0); | |
8094 | } | |
8095 | ||
8096 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
8097 | iparams++; |
8098 | } | |
8099 | child_die = sibling_die (child_die); | |
8100 | } | |
8101 | } | |
8102 | ||
76c10ea2 | 8103 | return ftype; |
c906108c SS |
8104 | } |
8105 | ||
f792889a | 8106 | static struct type * |
e7c27a73 | 8107 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8108 | { |
e7c27a73 | 8109 | struct objfile *objfile = cu->objfile; |
0114d602 | 8110 | const char *name = NULL; |
f792889a | 8111 | struct type *this_type; |
c906108c | 8112 | |
94af9270 | 8113 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 8114 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
8115 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
8116 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
8117 | set_die_type (die, this_type, cu); |
8118 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
8119 | return this_type; | |
c906108c SS |
8120 | } |
8121 | ||
8122 | /* Find a representation of a given base type and install | |
8123 | it in the TYPE field of the die. */ | |
8124 | ||
f792889a | 8125 | static struct type * |
e7c27a73 | 8126 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8127 | { |
e7c27a73 | 8128 | struct objfile *objfile = cu->objfile; |
c906108c SS |
8129 | struct type *type; |
8130 | struct attribute *attr; | |
8131 | int encoding = 0, size = 0; | |
39cbfefa | 8132 | char *name; |
6ccb9162 UW |
8133 | enum type_code code = TYPE_CODE_INT; |
8134 | int type_flags = 0; | |
8135 | struct type *target_type = NULL; | |
c906108c | 8136 | |
e142c38c | 8137 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
8138 | if (attr) |
8139 | { | |
8140 | encoding = DW_UNSND (attr); | |
8141 | } | |
e142c38c | 8142 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
8143 | if (attr) |
8144 | { | |
8145 | size = DW_UNSND (attr); | |
8146 | } | |
39cbfefa | 8147 | name = dwarf2_name (die, cu); |
6ccb9162 | 8148 | if (!name) |
c906108c | 8149 | { |
6ccb9162 UW |
8150 | complaint (&symfile_complaints, |
8151 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 8152 | } |
6ccb9162 UW |
8153 | |
8154 | switch (encoding) | |
c906108c | 8155 | { |
6ccb9162 UW |
8156 | case DW_ATE_address: |
8157 | /* Turn DW_ATE_address into a void * pointer. */ | |
8158 | code = TYPE_CODE_PTR; | |
8159 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8160 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
8161 | break; | |
8162 | case DW_ATE_boolean: | |
8163 | code = TYPE_CODE_BOOL; | |
8164 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8165 | break; | |
8166 | case DW_ATE_complex_float: | |
8167 | code = TYPE_CODE_COMPLEX; | |
8168 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
8169 | break; | |
8170 | case DW_ATE_decimal_float: | |
8171 | code = TYPE_CODE_DECFLOAT; | |
8172 | break; | |
8173 | case DW_ATE_float: | |
8174 | code = TYPE_CODE_FLT; | |
8175 | break; | |
8176 | case DW_ATE_signed: | |
8177 | break; | |
8178 | case DW_ATE_unsigned: | |
8179 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8180 | break; | |
8181 | case DW_ATE_signed_char: | |
6e70227d | 8182 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 8183 | || cu->language == language_pascal) |
6ccb9162 UW |
8184 | code = TYPE_CODE_CHAR; |
8185 | break; | |
8186 | case DW_ATE_unsigned_char: | |
868a0084 PM |
8187 | if (cu->language == language_ada || cu->language == language_m2 |
8188 | || cu->language == language_pascal) | |
6ccb9162 UW |
8189 | code = TYPE_CODE_CHAR; |
8190 | type_flags |= TYPE_FLAG_UNSIGNED; | |
8191 | break; | |
75079b2b TT |
8192 | case DW_ATE_UTF: |
8193 | /* We just treat this as an integer and then recognize the | |
8194 | type by name elsewhere. */ | |
8195 | break; | |
8196 | ||
6ccb9162 UW |
8197 | default: |
8198 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
8199 | dwarf_type_encoding_name (encoding)); | |
8200 | break; | |
c906108c | 8201 | } |
6ccb9162 | 8202 | |
0114d602 DJ |
8203 | type = init_type (code, size, type_flags, NULL, objfile); |
8204 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
8205 | TYPE_TARGET_TYPE (type) = target_type; |
8206 | ||
0114d602 | 8207 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 8208 | TYPE_NOSIGN (type) = 1; |
0114d602 | 8209 | |
f792889a | 8210 | return set_die_type (die, type, cu); |
c906108c SS |
8211 | } |
8212 | ||
a02abb62 JB |
8213 | /* Read the given DW_AT_subrange DIE. */ |
8214 | ||
f792889a | 8215 | static struct type * |
a02abb62 JB |
8216 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
8217 | { | |
8218 | struct type *base_type; | |
8219 | struct type *range_type; | |
8220 | struct attribute *attr; | |
43bbcdc2 PH |
8221 | LONGEST low = 0; |
8222 | LONGEST high = -1; | |
39cbfefa | 8223 | char *name; |
43bbcdc2 | 8224 | LONGEST negative_mask; |
e77813c8 | 8225 | |
a02abb62 | 8226 | base_type = die_type (die, cu); |
953ac07e JK |
8227 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
8228 | check_typedef (base_type); | |
a02abb62 | 8229 | |
7e314c57 JK |
8230 | /* The die_type call above may have already set the type for this DIE. */ |
8231 | range_type = get_die_type (die, cu); | |
8232 | if (range_type) | |
8233 | return range_type; | |
8234 | ||
e142c38c | 8235 | if (cu->language == language_fortran) |
6e70227d | 8236 | { |
a02abb62 JB |
8237 | /* FORTRAN implies a lower bound of 1, if not given. */ |
8238 | low = 1; | |
8239 | } | |
8240 | ||
dd5e6932 DJ |
8241 | /* FIXME: For variable sized arrays either of these could be |
8242 | a variable rather than a constant value. We'll allow it, | |
8243 | but we don't know how to handle it. */ | |
e142c38c | 8244 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
8245 | if (attr) |
8246 | low = dwarf2_get_attr_constant_value (attr, 0); | |
8247 | ||
e142c38c | 8248 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 8249 | if (attr) |
6e70227d | 8250 | { |
e77813c8 | 8251 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
8252 | { |
8253 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 8254 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
8255 | FIXME: GDB does not yet know how to handle dynamic |
8256 | arrays properly, treat them as arrays with unspecified | |
8257 | length for now. | |
8258 | ||
8259 | FIXME: jimb/2003-09-22: GDB does not really know | |
8260 | how to handle arrays of unspecified length | |
8261 | either; we just represent them as zero-length | |
8262 | arrays. Choose an appropriate upper bound given | |
8263 | the lower bound we've computed above. */ | |
8264 | high = low - 1; | |
8265 | } | |
8266 | else | |
8267 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8268 | } | |
e77813c8 PM |
8269 | else |
8270 | { | |
8271 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8272 | if (attr) | |
8273 | { | |
8274 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8275 | high = low + count - 1; | |
8276 | } | |
c2ff108b JK |
8277 | else |
8278 | { | |
8279 | /* Unspecified array length. */ | |
8280 | high = low - 1; | |
8281 | } | |
e77813c8 PM |
8282 | } |
8283 | ||
8284 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8285 | without specifying a base type. | |
8286 | In that case, the base type must be set to the type of | |
8287 | the lower bound, upper bound or count, in that order, if any of these | |
8288 | three attributes references an object that has a type. | |
8289 | If no base type is found, the Dwarf-2 specifications say that | |
8290 | a signed integer type of size equal to the size of an address should | |
8291 | be used. | |
8292 | For the following C code: `extern char gdb_int [];' | |
8293 | GCC produces an empty range DIE. | |
8294 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
0963b4bd | 8295 | high bound or count are not yet handled by this code. */ |
e77813c8 PM |
8296 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
8297 | { | |
8298 | struct objfile *objfile = cu->objfile; | |
8299 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8300 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8301 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8302 | ||
8303 | /* Test "int", "long int", and "long long int" objfile types, | |
8304 | and select the first one having a size above or equal to the | |
8305 | architecture address size. */ | |
8306 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8307 | base_type = int_type; | |
8308 | else | |
8309 | { | |
8310 | int_type = objfile_type (objfile)->builtin_long; | |
8311 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8312 | base_type = int_type; | |
8313 | else | |
8314 | { | |
8315 | int_type = objfile_type (objfile)->builtin_long_long; | |
8316 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8317 | base_type = int_type; | |
8318 | } | |
8319 | } | |
8320 | } | |
a02abb62 | 8321 | |
6e70227d | 8322 | negative_mask = |
43bbcdc2 PH |
8323 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8324 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8325 | low |= negative_mask; | |
8326 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8327 | high |= negative_mask; | |
8328 | ||
a02abb62 JB |
8329 | range_type = create_range_type (NULL, base_type, low, high); |
8330 | ||
bbb0eef6 JK |
8331 | /* Mark arrays with dynamic length at least as an array of unspecified |
8332 | length. GDB could check the boundary but before it gets implemented at | |
8333 | least allow accessing the array elements. */ | |
8334 | if (attr && attr->form == DW_FORM_block1) | |
8335 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8336 | ||
c2ff108b JK |
8337 | /* Ada expects an empty array on no boundary attributes. */ |
8338 | if (attr == NULL && cu->language != language_ada) | |
8339 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8340 | ||
39cbfefa DJ |
8341 | name = dwarf2_name (die, cu); |
8342 | if (name) | |
8343 | TYPE_NAME (range_type) = name; | |
6e70227d | 8344 | |
e142c38c | 8345 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
8346 | if (attr) |
8347 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
8348 | ||
7e314c57 JK |
8349 | set_die_type (die, range_type, cu); |
8350 | ||
8351 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8352 | set_descriptive_type (range_type, die, cu); |
8353 | ||
7e314c57 | 8354 | return range_type; |
a02abb62 | 8355 | } |
6e70227d | 8356 | |
f792889a | 8357 | static struct type * |
81a17f79 JB |
8358 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
8359 | { | |
8360 | struct type *type; | |
81a17f79 | 8361 | |
81a17f79 JB |
8362 | /* For now, we only support the C meaning of an unspecified type: void. */ |
8363 | ||
0114d602 DJ |
8364 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
8365 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 8366 | |
f792889a | 8367 | return set_die_type (die, type, cu); |
81a17f79 | 8368 | } |
a02abb62 | 8369 | |
51545339 DJ |
8370 | /* Trivial hash function for die_info: the hash value of a DIE |
8371 | is its offset in .debug_info for this objfile. */ | |
8372 | ||
8373 | static hashval_t | |
8374 | die_hash (const void *item) | |
8375 | { | |
8376 | const struct die_info *die = item; | |
9a619af0 | 8377 | |
51545339 DJ |
8378 | return die->offset; |
8379 | } | |
8380 | ||
8381 | /* Trivial comparison function for die_info structures: two DIEs | |
8382 | are equal if they have the same offset. */ | |
8383 | ||
8384 | static int | |
8385 | die_eq (const void *item_lhs, const void *item_rhs) | |
8386 | { | |
8387 | const struct die_info *die_lhs = item_lhs; | |
8388 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 8389 | |
51545339 DJ |
8390 | return die_lhs->offset == die_rhs->offset; |
8391 | } | |
8392 | ||
c906108c SS |
8393 | /* Read a whole compilation unit into a linked list of dies. */ |
8394 | ||
f9aca02d | 8395 | static struct die_info * |
93311388 | 8396 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 8397 | { |
93311388 | 8398 | struct die_reader_specs reader_specs; |
98bfdba5 | 8399 | int read_abbrevs = 0; |
1d9ec526 | 8400 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
8401 | struct die_info *die; |
8402 | ||
8403 | if (cu->dwarf2_abbrevs == NULL) | |
8404 | { | |
8405 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
8406 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
8407 | read_abbrevs = 1; | |
8408 | } | |
93311388 | 8409 | |
348e048f | 8410 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
8411 | cu->die_hash |
8412 | = htab_create_alloc_ex (cu->header.length / 12, | |
8413 | die_hash, | |
8414 | die_eq, | |
8415 | NULL, | |
8416 | &cu->comp_unit_obstack, | |
8417 | hashtab_obstack_allocate, | |
8418 | dummy_obstack_deallocate); | |
8419 | ||
93311388 DE |
8420 | init_cu_die_reader (&reader_specs, cu); |
8421 | ||
98bfdba5 PA |
8422 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
8423 | ||
8424 | if (read_abbrevs) | |
8425 | do_cleanups (back_to); | |
8426 | ||
8427 | return die; | |
639d11d3 DC |
8428 | } |
8429 | ||
d97bc12b DE |
8430 | /* Main entry point for reading a DIE and all children. |
8431 | Read the DIE and dump it if requested. */ | |
8432 | ||
8433 | static struct die_info * | |
93311388 DE |
8434 | read_die_and_children (const struct die_reader_specs *reader, |
8435 | gdb_byte *info_ptr, | |
d97bc12b DE |
8436 | gdb_byte **new_info_ptr, |
8437 | struct die_info *parent) | |
8438 | { | |
93311388 | 8439 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
8440 | new_info_ptr, parent); |
8441 | ||
8442 | if (dwarf2_die_debug) | |
8443 | { | |
348e048f DE |
8444 | fprintf_unfiltered (gdb_stdlog, |
8445 | "\nRead die from %s of %s:\n", | |
8446 | reader->buffer == dwarf2_per_objfile->info.buffer | |
8447 | ? ".debug_info" | |
8448 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
8449 | ? ".debug_types" | |
8450 | : "unknown section", | |
8451 | reader->abfd->filename); | |
d97bc12b DE |
8452 | dump_die (result, dwarf2_die_debug); |
8453 | } | |
8454 | ||
8455 | return result; | |
8456 | } | |
8457 | ||
639d11d3 DC |
8458 | /* Read a single die and all its descendents. Set the die's sibling |
8459 | field to NULL; set other fields in the die correctly, and set all | |
8460 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
8461 | location of the info_ptr after reading all of those dies. PARENT | |
8462 | is the parent of the die in question. */ | |
8463 | ||
8464 | static struct die_info * | |
93311388 DE |
8465 | read_die_and_children_1 (const struct die_reader_specs *reader, |
8466 | gdb_byte *info_ptr, | |
d97bc12b DE |
8467 | gdb_byte **new_info_ptr, |
8468 | struct die_info *parent) | |
639d11d3 DC |
8469 | { |
8470 | struct die_info *die; | |
fe1b8b76 | 8471 | gdb_byte *cur_ptr; |
639d11d3 DC |
8472 | int has_children; |
8473 | ||
93311388 | 8474 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
8475 | if (die == NULL) |
8476 | { | |
8477 | *new_info_ptr = cur_ptr; | |
8478 | return NULL; | |
8479 | } | |
93311388 | 8480 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
8481 | |
8482 | if (has_children) | |
348e048f | 8483 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
8484 | else |
8485 | { | |
8486 | die->child = NULL; | |
8487 | *new_info_ptr = cur_ptr; | |
8488 | } | |
8489 | ||
8490 | die->sibling = NULL; | |
8491 | die->parent = parent; | |
8492 | return die; | |
8493 | } | |
8494 | ||
8495 | /* Read a die, all of its descendents, and all of its siblings; set | |
8496 | all of the fields of all of the dies correctly. Arguments are as | |
8497 | in read_die_and_children. */ | |
8498 | ||
8499 | static struct die_info * | |
93311388 DE |
8500 | read_die_and_siblings (const struct die_reader_specs *reader, |
8501 | gdb_byte *info_ptr, | |
fe1b8b76 | 8502 | gdb_byte **new_info_ptr, |
639d11d3 DC |
8503 | struct die_info *parent) |
8504 | { | |
8505 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 8506 | gdb_byte *cur_ptr; |
639d11d3 | 8507 | |
c906108c | 8508 | cur_ptr = info_ptr; |
639d11d3 DC |
8509 | first_die = last_sibling = NULL; |
8510 | ||
8511 | while (1) | |
c906108c | 8512 | { |
639d11d3 | 8513 | struct die_info *die |
93311388 | 8514 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 8515 | |
1d325ec1 | 8516 | if (die == NULL) |
c906108c | 8517 | { |
639d11d3 DC |
8518 | *new_info_ptr = cur_ptr; |
8519 | return first_die; | |
c906108c | 8520 | } |
1d325ec1 DJ |
8521 | |
8522 | if (!first_die) | |
8523 | first_die = die; | |
c906108c | 8524 | else |
1d325ec1 DJ |
8525 | last_sibling->sibling = die; |
8526 | ||
8527 | last_sibling = die; | |
c906108c | 8528 | } |
c906108c SS |
8529 | } |
8530 | ||
93311388 DE |
8531 | /* Read the die from the .debug_info section buffer. Set DIEP to |
8532 | point to a newly allocated die with its information, except for its | |
8533 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
8534 | whether the die has children or not. */ | |
8535 | ||
8536 | static gdb_byte * | |
8537 | read_full_die (const struct die_reader_specs *reader, | |
8538 | struct die_info **diep, gdb_byte *info_ptr, | |
8539 | int *has_children) | |
8540 | { | |
8541 | unsigned int abbrev_number, bytes_read, i, offset; | |
8542 | struct abbrev_info *abbrev; | |
8543 | struct die_info *die; | |
8544 | struct dwarf2_cu *cu = reader->cu; | |
8545 | bfd *abfd = reader->abfd; | |
8546 | ||
8547 | offset = info_ptr - reader->buffer; | |
8548 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8549 | info_ptr += bytes_read; | |
8550 | if (!abbrev_number) | |
8551 | { | |
8552 | *diep = NULL; | |
8553 | *has_children = 0; | |
8554 | return info_ptr; | |
8555 | } | |
8556 | ||
8557 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
8558 | if (!abbrev) | |
348e048f DE |
8559 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
8560 | abbrev_number, | |
8561 | bfd_get_filename (abfd)); | |
8562 | ||
93311388 DE |
8563 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
8564 | die->offset = offset; | |
8565 | die->tag = abbrev->tag; | |
8566 | die->abbrev = abbrev_number; | |
8567 | ||
8568 | die->num_attrs = abbrev->num_attrs; | |
8569 | ||
8570 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8571 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
8572 | abfd, info_ptr, cu); | |
8573 | ||
8574 | *diep = die; | |
8575 | *has_children = abbrev->has_children; | |
8576 | return info_ptr; | |
8577 | } | |
8578 | ||
c906108c SS |
8579 | /* In DWARF version 2, the description of the debugging information is |
8580 | stored in a separate .debug_abbrev section. Before we read any | |
8581 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
8582 | in a hash table. This function also sets flags in CU describing |
8583 | the data found in the abbrev table. */ | |
c906108c SS |
8584 | |
8585 | static void | |
e7c27a73 | 8586 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 8587 | { |
e7c27a73 | 8588 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 8589 | gdb_byte *abbrev_ptr; |
c906108c SS |
8590 | struct abbrev_info *cur_abbrev; |
8591 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
8592 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
8593 | struct attr_abbrev *cur_attrs; |
8594 | unsigned int allocated_attrs; | |
c906108c | 8595 | |
0963b4bd | 8596 | /* Initialize dwarf2 abbrevs. */ |
f3dd6933 DJ |
8597 | obstack_init (&cu->abbrev_obstack); |
8598 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
8599 | (ABBREV_HASH_SIZE | |
8600 | * sizeof (struct abbrev_info *))); | |
8601 | memset (cu->dwarf2_abbrevs, 0, | |
8602 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 8603 | |
be391dca TT |
8604 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
8605 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 8606 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
8607 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8608 | abbrev_ptr += bytes_read; | |
8609 | ||
f3dd6933 DJ |
8610 | allocated_attrs = ATTR_ALLOC_CHUNK; |
8611 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 8612 | |
0963b4bd | 8613 | /* Loop until we reach an abbrev number of 0. */ |
c906108c SS |
8614 | while (abbrev_number) |
8615 | { | |
f3dd6933 | 8616 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
8617 | |
8618 | /* read in abbrev header */ | |
8619 | cur_abbrev->number = abbrev_number; | |
8620 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8621 | abbrev_ptr += bytes_read; | |
8622 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
8623 | abbrev_ptr += 1; | |
8624 | ||
72bf9492 DJ |
8625 | if (cur_abbrev->tag == DW_TAG_namespace) |
8626 | cu->has_namespace_info = 1; | |
8627 | ||
c906108c SS |
8628 | /* now read in declarations */ |
8629 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8630 | abbrev_ptr += bytes_read; | |
8631 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8632 | abbrev_ptr += bytes_read; | |
8633 | while (abbrev_name) | |
8634 | { | |
f3dd6933 | 8635 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 8636 | { |
f3dd6933 DJ |
8637 | allocated_attrs += ATTR_ALLOC_CHUNK; |
8638 | cur_attrs | |
8639 | = xrealloc (cur_attrs, (allocated_attrs | |
8640 | * sizeof (struct attr_abbrev))); | |
c906108c | 8641 | } |
ae038cb0 DJ |
8642 | |
8643 | /* Record whether this compilation unit might have | |
8644 | inter-compilation-unit references. If we don't know what form | |
8645 | this attribute will have, then it might potentially be a | |
8646 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
8647 | references. */ | |
8648 | ||
8649 | if (abbrev_form == DW_FORM_ref_addr | |
8650 | || abbrev_form == DW_FORM_indirect) | |
8651 | cu->has_form_ref_addr = 1; | |
8652 | ||
f3dd6933 DJ |
8653 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
8654 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
8655 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8656 | abbrev_ptr += bytes_read; | |
8657 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8658 | abbrev_ptr += bytes_read; | |
8659 | } | |
8660 | ||
f3dd6933 DJ |
8661 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
8662 | (cur_abbrev->num_attrs | |
8663 | * sizeof (struct attr_abbrev))); | |
8664 | memcpy (cur_abbrev->attrs, cur_attrs, | |
8665 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
8666 | ||
c906108c | 8667 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
8668 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
8669 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
8670 | |
8671 | /* Get next abbreviation. | |
8672 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
8673 | always properly terminated with an abbrev number of 0. |
8674 | Exit loop if we encounter an abbreviation which we have | |
8675 | already read (which means we are about to read the abbreviations | |
8676 | for the next compile unit) or if the end of the abbreviation | |
8677 | table is reached. */ | |
dce234bc PP |
8678 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
8679 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
8680 | break; |
8681 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8682 | abbrev_ptr += bytes_read; | |
e7c27a73 | 8683 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
8684 | break; |
8685 | } | |
f3dd6933 DJ |
8686 | |
8687 | xfree (cur_attrs); | |
c906108c SS |
8688 | } |
8689 | ||
f3dd6933 | 8690 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 8691 | |
c906108c | 8692 | static void |
f3dd6933 | 8693 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 8694 | { |
f3dd6933 | 8695 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 8696 | |
f3dd6933 DJ |
8697 | obstack_free (&cu->abbrev_obstack, NULL); |
8698 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
8699 | } |
8700 | ||
8701 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
8702 | ||
8703 | static struct abbrev_info * | |
e7c27a73 | 8704 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
8705 | { |
8706 | unsigned int hash_number; | |
8707 | struct abbrev_info *abbrev; | |
8708 | ||
8709 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 8710 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
8711 | |
8712 | while (abbrev) | |
8713 | { | |
8714 | if (abbrev->number == number) | |
8715 | return abbrev; | |
8716 | else | |
8717 | abbrev = abbrev->next; | |
8718 | } | |
8719 | return NULL; | |
8720 | } | |
8721 | ||
72bf9492 DJ |
8722 | /* Returns nonzero if TAG represents a type that we might generate a partial |
8723 | symbol for. */ | |
8724 | ||
8725 | static int | |
8726 | is_type_tag_for_partial (int tag) | |
8727 | { | |
8728 | switch (tag) | |
8729 | { | |
8730 | #if 0 | |
8731 | /* Some types that would be reasonable to generate partial symbols for, | |
8732 | that we don't at present. */ | |
8733 | case DW_TAG_array_type: | |
8734 | case DW_TAG_file_type: | |
8735 | case DW_TAG_ptr_to_member_type: | |
8736 | case DW_TAG_set_type: | |
8737 | case DW_TAG_string_type: | |
8738 | case DW_TAG_subroutine_type: | |
8739 | #endif | |
8740 | case DW_TAG_base_type: | |
8741 | case DW_TAG_class_type: | |
680b30c7 | 8742 | case DW_TAG_interface_type: |
72bf9492 DJ |
8743 | case DW_TAG_enumeration_type: |
8744 | case DW_TAG_structure_type: | |
8745 | case DW_TAG_subrange_type: | |
8746 | case DW_TAG_typedef: | |
8747 | case DW_TAG_union_type: | |
8748 | return 1; | |
8749 | default: | |
8750 | return 0; | |
8751 | } | |
8752 | } | |
8753 | ||
8754 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
8755 | ||
8756 | static struct partial_die_info * | |
93311388 DE |
8757 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
8758 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
8759 | { |
8760 | struct partial_die_info *part_die; | |
8761 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
8762 | struct abbrev_info *abbrev; | |
8763 | unsigned int bytes_read; | |
5afb4e99 | 8764 | unsigned int load_all = 0; |
72bf9492 DJ |
8765 | |
8766 | int nesting_level = 1; | |
8767 | ||
8768 | parent_die = NULL; | |
8769 | last_die = NULL; | |
8770 | ||
5afb4e99 DJ |
8771 | if (cu->per_cu && cu->per_cu->load_all_dies) |
8772 | load_all = 1; | |
8773 | ||
72bf9492 DJ |
8774 | cu->partial_dies |
8775 | = htab_create_alloc_ex (cu->header.length / 12, | |
8776 | partial_die_hash, | |
8777 | partial_die_eq, | |
8778 | NULL, | |
8779 | &cu->comp_unit_obstack, | |
8780 | hashtab_obstack_allocate, | |
8781 | dummy_obstack_deallocate); | |
8782 | ||
8783 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8784 | sizeof (struct partial_die_info)); | |
8785 | ||
8786 | while (1) | |
8787 | { | |
8788 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
8789 | ||
8790 | /* A NULL abbrev means the end of a series of children. */ | |
8791 | if (abbrev == NULL) | |
8792 | { | |
8793 | if (--nesting_level == 0) | |
8794 | { | |
8795 | /* PART_DIE was probably the last thing allocated on the | |
8796 | comp_unit_obstack, so we could call obstack_free | |
8797 | here. We don't do that because the waste is small, | |
8798 | and will be cleaned up when we're done with this | |
8799 | compilation unit. This way, we're also more robust | |
8800 | against other users of the comp_unit_obstack. */ | |
8801 | return first_die; | |
8802 | } | |
8803 | info_ptr += bytes_read; | |
8804 | last_die = parent_die; | |
8805 | parent_die = parent_die->die_parent; | |
8806 | continue; | |
8807 | } | |
8808 | ||
98bfdba5 PA |
8809 | /* Check for template arguments. We never save these; if |
8810 | they're seen, we just mark the parent, and go on our way. */ | |
8811 | if (parent_die != NULL | |
8812 | && cu->language == language_cplus | |
8813 | && (abbrev->tag == DW_TAG_template_type_param | |
8814 | || abbrev->tag == DW_TAG_template_value_param)) | |
8815 | { | |
8816 | parent_die->has_template_arguments = 1; | |
8817 | ||
8818 | if (!load_all) | |
8819 | { | |
8820 | /* We don't need a partial DIE for the template argument. */ | |
8821 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
8822 | cu); | |
8823 | continue; | |
8824 | } | |
8825 | } | |
8826 | ||
8827 | /* We only recurse into subprograms looking for template arguments. | |
8828 | Skip their other children. */ | |
8829 | if (!load_all | |
8830 | && cu->language == language_cplus | |
8831 | && parent_die != NULL | |
8832 | && parent_die->tag == DW_TAG_subprogram) | |
8833 | { | |
8834 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
8835 | continue; | |
8836 | } | |
8837 | ||
5afb4e99 DJ |
8838 | /* Check whether this DIE is interesting enough to save. Normally |
8839 | we would not be interested in members here, but there may be | |
8840 | later variables referencing them via DW_AT_specification (for | |
8841 | static members). */ | |
8842 | if (!load_all | |
8843 | && !is_type_tag_for_partial (abbrev->tag) | |
72929c62 | 8844 | && abbrev->tag != DW_TAG_constant |
72bf9492 DJ |
8845 | && abbrev->tag != DW_TAG_enumerator |
8846 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 8847 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 8848 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 8849 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 8850 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 8851 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
8852 | { |
8853 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8854 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
8855 | continue; |
8856 | } | |
8857 | ||
93311388 DE |
8858 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
8859 | buffer, info_ptr, cu); | |
72bf9492 DJ |
8860 | |
8861 | /* This two-pass algorithm for processing partial symbols has a | |
8862 | high cost in cache pressure. Thus, handle some simple cases | |
8863 | here which cover the majority of C partial symbols. DIEs | |
8864 | which neither have specification tags in them, nor could have | |
8865 | specification tags elsewhere pointing at them, can simply be | |
8866 | processed and discarded. | |
8867 | ||
8868 | This segment is also optional; scan_partial_symbols and | |
8869 | add_partial_symbol will handle these DIEs if we chain | |
8870 | them in normally. When compilers which do not emit large | |
8871 | quantities of duplicate debug information are more common, | |
8872 | this code can probably be removed. */ | |
8873 | ||
8874 | /* Any complete simple types at the top level (pretty much all | |
8875 | of them, for a language without namespaces), can be processed | |
8876 | directly. */ | |
8877 | if (parent_die == NULL | |
8878 | && part_die->has_specification == 0 | |
8879 | && part_die->is_declaration == 0 | |
8880 | && (part_die->tag == DW_TAG_typedef | |
8881 | || part_die->tag == DW_TAG_base_type | |
8882 | || part_die->tag == DW_TAG_subrange_type)) | |
8883 | { | |
8884 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 8885 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
8886 | VAR_DOMAIN, LOC_TYPEDEF, |
8887 | &cu->objfile->static_psymbols, | |
8888 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 8889 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8890 | continue; |
8891 | } | |
8892 | ||
8893 | /* If we're at the second level, and we're an enumerator, and | |
8894 | our parent has no specification (meaning possibly lives in a | |
8895 | namespace elsewhere), then we can add the partial symbol now | |
8896 | instead of queueing it. */ | |
8897 | if (part_die->tag == DW_TAG_enumerator | |
8898 | && parent_die != NULL | |
8899 | && parent_die->die_parent == NULL | |
8900 | && parent_die->tag == DW_TAG_enumeration_type | |
8901 | && parent_die->has_specification == 0) | |
8902 | { | |
8903 | if (part_die->name == NULL) | |
3e43a32a MS |
8904 | complaint (&symfile_complaints, |
8905 | _("malformed enumerator DIE ignored")); | |
72bf9492 | 8906 | else if (building_psymtab) |
04a679b8 | 8907 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 8908 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
8909 | (cu->language == language_cplus |
8910 | || cu->language == language_java) | |
72bf9492 DJ |
8911 | ? &cu->objfile->global_psymbols |
8912 | : &cu->objfile->static_psymbols, | |
8913 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
8914 | ||
93311388 | 8915 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8916 | continue; |
8917 | } | |
8918 | ||
8919 | /* We'll save this DIE so link it in. */ | |
8920 | part_die->die_parent = parent_die; | |
8921 | part_die->die_sibling = NULL; | |
8922 | part_die->die_child = NULL; | |
8923 | ||
8924 | if (last_die && last_die == parent_die) | |
8925 | last_die->die_child = part_die; | |
8926 | else if (last_die) | |
8927 | last_die->die_sibling = part_die; | |
8928 | ||
8929 | last_die = part_die; | |
8930 | ||
8931 | if (first_die == NULL) | |
8932 | first_die = part_die; | |
8933 | ||
8934 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
8935 | find interesting need to be in the hash table, because we | |
8936 | also have the parent/sibling/child chains; only those that we | |
8937 | might refer to by offset later during partial symbol reading. | |
8938 | ||
8939 | For now this means things that might have be the target of a | |
8940 | DW_AT_specification, DW_AT_abstract_origin, or | |
8941 | DW_AT_extension. DW_AT_extension will refer only to | |
8942 | namespaces; DW_AT_abstract_origin refers to functions (and | |
8943 | many things under the function DIE, but we do not recurse | |
8944 | into function DIEs during partial symbol reading) and | |
8945 | possibly variables as well; DW_AT_specification refers to | |
8946 | declarations. Declarations ought to have the DW_AT_declaration | |
8947 | flag. It happens that GCC forgets to put it in sometimes, but | |
8948 | only for functions, not for types. | |
8949 | ||
8950 | Adding more things than necessary to the hash table is harmless | |
8951 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
8952 | wasted time in find_partial_die, when we reread the compilation |
8953 | unit with load_all_dies set. */ | |
72bf9492 | 8954 | |
5afb4e99 | 8955 | if (load_all |
72929c62 | 8956 | || abbrev->tag == DW_TAG_constant |
5afb4e99 | 8957 | || abbrev->tag == DW_TAG_subprogram |
72bf9492 DJ |
8958 | || abbrev->tag == DW_TAG_variable |
8959 | || abbrev->tag == DW_TAG_namespace | |
8960 | || part_die->is_declaration) | |
8961 | { | |
8962 | void **slot; | |
8963 | ||
8964 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
8965 | part_die->offset, INSERT); | |
8966 | *slot = part_die; | |
8967 | } | |
8968 | ||
8969 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8970 | sizeof (struct partial_die_info)); | |
8971 | ||
8972 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 8973 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
8974 | languages we have to, so that we can get at method physnames |
8975 | to infer fully qualified class names, for DW_AT_specification, | |
8976 | and for C++ template arguments. For C++, we also look one level | |
8977 | inside functions to find template arguments (if the name of the | |
8978 | function does not already contain the template arguments). | |
bc30ff58 JB |
8979 | |
8980 | For Ada, we need to scan the children of subprograms and lexical | |
8981 | blocks as well because Ada allows the definition of nested | |
8982 | entities that could be interesting for the debugger, such as | |
8983 | nested subprograms for instance. */ | |
72bf9492 | 8984 | if (last_die->has_children |
5afb4e99 DJ |
8985 | && (load_all |
8986 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 8987 | || last_die->tag == DW_TAG_module |
72bf9492 | 8988 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
8989 | || (cu->language == language_cplus |
8990 | && last_die->tag == DW_TAG_subprogram | |
8991 | && (last_die->name == NULL | |
8992 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
8993 | || (cu->language != language_c |
8994 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 8995 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 8996 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
8997 | || last_die->tag == DW_TAG_union_type)) |
8998 | || (cu->language == language_ada | |
8999 | && (last_die->tag == DW_TAG_subprogram | |
9000 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
9001 | { |
9002 | nesting_level++; | |
9003 | parent_die = last_die; | |
9004 | continue; | |
9005 | } | |
9006 | ||
9007 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 9008 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
9009 | |
9010 | /* Back to the top, do it again. */ | |
9011 | } | |
9012 | } | |
9013 | ||
c906108c SS |
9014 | /* Read a minimal amount of information into the minimal die structure. */ |
9015 | ||
fe1b8b76 | 9016 | static gdb_byte * |
72bf9492 DJ |
9017 | read_partial_die (struct partial_die_info *part_die, |
9018 | struct abbrev_info *abbrev, | |
9019 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
9020 | gdb_byte *buffer, gdb_byte *info_ptr, |
9021 | struct dwarf2_cu *cu) | |
c906108c | 9022 | { |
fa238c03 | 9023 | unsigned int i; |
c906108c | 9024 | struct attribute attr; |
c5aa993b | 9025 | int has_low_pc_attr = 0; |
c906108c SS |
9026 | int has_high_pc_attr = 0; |
9027 | ||
72bf9492 | 9028 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 9029 | |
93311388 | 9030 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
9031 | |
9032 | info_ptr += abbrev_len; | |
9033 | ||
9034 | if (abbrev == NULL) | |
9035 | return info_ptr; | |
9036 | ||
c906108c SS |
9037 | part_die->tag = abbrev->tag; |
9038 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
9039 | |
9040 | for (i = 0; i < abbrev->num_attrs; ++i) | |
9041 | { | |
e7c27a73 | 9042 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
9043 | |
9044 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 9045 | partial symbol table. */ |
c906108c SS |
9046 | switch (attr.name) |
9047 | { | |
9048 | case DW_AT_name: | |
71c25dea TT |
9049 | switch (part_die->tag) |
9050 | { | |
9051 | case DW_TAG_compile_unit: | |
348e048f | 9052 | case DW_TAG_type_unit: |
71c25dea TT |
9053 | /* Compilation units have a DW_AT_name that is a filename, not |
9054 | a source language identifier. */ | |
9055 | case DW_TAG_enumeration_type: | |
9056 | case DW_TAG_enumerator: | |
9057 | /* These tags always have simple identifiers already; no need | |
9058 | to canonicalize them. */ | |
9059 | part_die->name = DW_STRING (&attr); | |
9060 | break; | |
9061 | default: | |
9062 | part_die->name | |
9063 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 9064 | &cu->objfile->objfile_obstack); |
71c25dea TT |
9065 | break; |
9066 | } | |
c906108c | 9067 | break; |
31ef98ae | 9068 | case DW_AT_linkage_name: |
c906108c | 9069 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
9070 | /* Note that both forms of linkage name might appear. We |
9071 | assume they will be the same, and we only store the last | |
9072 | one we see. */ | |
94af9270 KS |
9073 | if (cu->language == language_ada) |
9074 | part_die->name = DW_STRING (&attr); | |
abc72ce4 | 9075 | part_die->linkage_name = DW_STRING (&attr); |
c906108c SS |
9076 | break; |
9077 | case DW_AT_low_pc: | |
9078 | has_low_pc_attr = 1; | |
9079 | part_die->lowpc = DW_ADDR (&attr); | |
9080 | break; | |
9081 | case DW_AT_high_pc: | |
9082 | has_high_pc_attr = 1; | |
9083 | part_die->highpc = DW_ADDR (&attr); | |
9084 | break; | |
9085 | case DW_AT_location: | |
0963b4bd | 9086 | /* Support the .debug_loc offsets. */ |
8e19ed76 PS |
9087 | if (attr_form_is_block (&attr)) |
9088 | { | |
9089 | part_die->locdesc = DW_BLOCK (&attr); | |
9090 | } | |
3690dd37 | 9091 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 9092 | { |
4d3c2250 | 9093 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
9094 | } |
9095 | else | |
9096 | { | |
4d3c2250 KB |
9097 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
9098 | "partial symbol information"); | |
8e19ed76 | 9099 | } |
c906108c | 9100 | break; |
c906108c SS |
9101 | case DW_AT_external: |
9102 | part_die->is_external = DW_UNSND (&attr); | |
9103 | break; | |
9104 | case DW_AT_declaration: | |
9105 | part_die->is_declaration = DW_UNSND (&attr); | |
9106 | break; | |
9107 | case DW_AT_type: | |
9108 | part_die->has_type = 1; | |
9109 | break; | |
9110 | case DW_AT_abstract_origin: | |
9111 | case DW_AT_specification: | |
72bf9492 DJ |
9112 | case DW_AT_extension: |
9113 | part_die->has_specification = 1; | |
c764a876 | 9114 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
9115 | break; |
9116 | case DW_AT_sibling: | |
9117 | /* Ignore absolute siblings, they might point outside of | |
9118 | the current compile unit. */ | |
9119 | if (attr.form == DW_FORM_ref_addr) | |
3e43a32a MS |
9120 | complaint (&symfile_complaints, |
9121 | _("ignoring absolute DW_AT_sibling")); | |
c906108c | 9122 | else |
93311388 | 9123 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 9124 | break; |
fa4028e9 JB |
9125 | case DW_AT_byte_size: |
9126 | part_die->has_byte_size = 1; | |
9127 | break; | |
68511cec CES |
9128 | case DW_AT_calling_convention: |
9129 | /* DWARF doesn't provide a way to identify a program's source-level | |
9130 | entry point. DW_AT_calling_convention attributes are only meant | |
9131 | to describe functions' calling conventions. | |
9132 | ||
9133 | However, because it's a necessary piece of information in | |
9134 | Fortran, and because DW_CC_program is the only piece of debugging | |
9135 | information whose definition refers to a 'main program' at all, | |
9136 | several compilers have begun marking Fortran main programs with | |
9137 | DW_CC_program --- even when those functions use the standard | |
9138 | calling conventions. | |
9139 | ||
9140 | So until DWARF specifies a way to provide this information and | |
9141 | compilers pick up the new representation, we'll support this | |
9142 | practice. */ | |
9143 | if (DW_UNSND (&attr) == DW_CC_program | |
9144 | && cu->language == language_fortran) | |
01f8c46d JK |
9145 | { |
9146 | set_main_name (part_die->name); | |
9147 | ||
9148 | /* As this DIE has a static linkage the name would be difficult | |
9149 | to look up later. */ | |
9150 | language_of_main = language_fortran; | |
9151 | } | |
68511cec | 9152 | break; |
c906108c SS |
9153 | default: |
9154 | break; | |
9155 | } | |
9156 | } | |
9157 | ||
9373cf26 JK |
9158 | if (has_low_pc_attr && has_high_pc_attr) |
9159 | { | |
9160 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
9161 | eliminate duplicate copies of functions and vtables and such. | |
9162 | The linker will arbitrarily choose one and discard the others. | |
9163 | The AT_*_pc values for such functions refer to local labels in | |
9164 | these sections. If the section from that file was discarded, the | |
9165 | labels are not in the output, so the relocs get a value of 0. | |
9166 | If this is a discarded function, mark the pc bounds as invalid, | |
9167 | so that GDB will ignore it. */ | |
9168 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
9169 | { | |
9170 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9171 | ||
9172 | complaint (&symfile_complaints, | |
9173 | _("DW_AT_low_pc %s is zero " | |
9174 | "for DIE at 0x%x [in module %s]"), | |
9175 | paddress (gdbarch, part_die->lowpc), | |
9176 | part_die->offset, cu->objfile->name); | |
9177 | } | |
9178 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ | |
9179 | else if (part_die->lowpc >= part_die->highpc) | |
9180 | { | |
9181 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); | |
9182 | ||
9183 | complaint (&symfile_complaints, | |
9184 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " | |
9185 | "for DIE at 0x%x [in module %s]"), | |
9186 | paddress (gdbarch, part_die->lowpc), | |
9187 | paddress (gdbarch, part_die->highpc), | |
9188 | part_die->offset, cu->objfile->name); | |
9189 | } | |
9190 | else | |
9191 | part_die->has_pc_info = 1; | |
9192 | } | |
85cbf3d3 | 9193 | |
c906108c SS |
9194 | return info_ptr; |
9195 | } | |
9196 | ||
72bf9492 DJ |
9197 | /* Find a cached partial DIE at OFFSET in CU. */ |
9198 | ||
9199 | static struct partial_die_info * | |
c764a876 | 9200 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
9201 | { |
9202 | struct partial_die_info *lookup_die = NULL; | |
9203 | struct partial_die_info part_die; | |
9204 | ||
9205 | part_die.offset = offset; | |
9206 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
9207 | ||
72bf9492 DJ |
9208 | return lookup_die; |
9209 | } | |
9210 | ||
348e048f DE |
9211 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
9212 | except in the case of .debug_types DIEs which do not reference | |
9213 | outside their CU (they do however referencing other types via | |
55f1336d | 9214 | DW_FORM_ref_sig8). */ |
72bf9492 DJ |
9215 | |
9216 | static struct partial_die_info * | |
c764a876 | 9217 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 9218 | { |
5afb4e99 DJ |
9219 | struct dwarf2_per_cu_data *per_cu = NULL; |
9220 | struct partial_die_info *pd = NULL; | |
72bf9492 | 9221 | |
348e048f DE |
9222 | if (cu->per_cu->from_debug_types) |
9223 | { | |
9224 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9225 | if (pd != NULL) | |
9226 | return pd; | |
9227 | goto not_found; | |
9228 | } | |
9229 | ||
45452591 | 9230 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
9231 | { |
9232 | pd = find_partial_die_in_comp_unit (offset, cu); | |
9233 | if (pd != NULL) | |
9234 | return pd; | |
9235 | } | |
72bf9492 | 9236 | |
ae038cb0 DJ |
9237 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
9238 | ||
98bfdba5 PA |
9239 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
9240 | load_partial_comp_unit (per_cu, cu->objfile); | |
ae038cb0 DJ |
9241 | |
9242 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
9243 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
9244 | ||
9245 | if (pd == NULL && per_cu->load_all_dies == 0) | |
9246 | { | |
9247 | struct cleanup *back_to; | |
9248 | struct partial_die_info comp_unit_die; | |
9249 | struct abbrev_info *abbrev; | |
9250 | unsigned int bytes_read; | |
9251 | char *info_ptr; | |
9252 | ||
9253 | per_cu->load_all_dies = 1; | |
9254 | ||
9255 | /* Re-read the DIEs. */ | |
9256 | back_to = make_cleanup (null_cleanup, 0); | |
9257 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
9258 | { | |
9259 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 9260 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 9261 | } |
dce234bc | 9262 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
9263 | + per_cu->cu->header.offset |
9264 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
9265 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
9266 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
9267 | per_cu->cu->objfile->obfd, |
9268 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
9269 | per_cu->cu); |
9270 | if (comp_unit_die.has_children) | |
93311388 DE |
9271 | load_partial_dies (per_cu->cu->objfile->obfd, |
9272 | dwarf2_per_objfile->info.buffer, info_ptr, | |
9273 | 0, per_cu->cu); | |
5afb4e99 DJ |
9274 | do_cleanups (back_to); |
9275 | ||
9276 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
9277 | } | |
9278 | ||
348e048f DE |
9279 | not_found: |
9280 | ||
5afb4e99 DJ |
9281 | if (pd == NULL) |
9282 | internal_error (__FILE__, __LINE__, | |
3e43a32a MS |
9283 | _("could not find partial DIE 0x%x " |
9284 | "in cache [from module %s]\n"), | |
5afb4e99 DJ |
9285 | offset, bfd_get_filename (cu->objfile->obfd)); |
9286 | return pd; | |
72bf9492 DJ |
9287 | } |
9288 | ||
abc72ce4 DE |
9289 | /* See if we can figure out if the class lives in a namespace. We do |
9290 | this by looking for a member function; its demangled name will | |
9291 | contain namespace info, if there is any. */ | |
9292 | ||
9293 | static void | |
9294 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, | |
9295 | struct dwarf2_cu *cu) | |
9296 | { | |
9297 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |
9298 | what template types look like, because the demangler | |
9299 | frequently doesn't give the same name as the debug info. We | |
9300 | could fix this by only using the demangled name to get the | |
9301 | prefix (but see comment in read_structure_type). */ | |
9302 | ||
9303 | struct partial_die_info *real_pdi; | |
9304 | struct partial_die_info *child_pdi; | |
9305 | ||
9306 | /* If this DIE (this DIE's specification, if any) has a parent, then | |
9307 | we should not do this. We'll prepend the parent's fully qualified | |
9308 | name when we create the partial symbol. */ | |
9309 | ||
9310 | real_pdi = struct_pdi; | |
9311 | while (real_pdi->has_specification) | |
9312 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |
9313 | ||
9314 | if (real_pdi->die_parent != NULL) | |
9315 | return; | |
9316 | ||
9317 | for (child_pdi = struct_pdi->die_child; | |
9318 | child_pdi != NULL; | |
9319 | child_pdi = child_pdi->die_sibling) | |
9320 | { | |
9321 | if (child_pdi->tag == DW_TAG_subprogram | |
9322 | && child_pdi->linkage_name != NULL) | |
9323 | { | |
9324 | char *actual_class_name | |
9325 | = language_class_name_from_physname (cu->language_defn, | |
9326 | child_pdi->linkage_name); | |
9327 | if (actual_class_name != NULL) | |
9328 | { | |
9329 | struct_pdi->name | |
9330 | = obsavestring (actual_class_name, | |
9331 | strlen (actual_class_name), | |
9332 | &cu->objfile->objfile_obstack); | |
9333 | xfree (actual_class_name); | |
9334 | } | |
9335 | break; | |
9336 | } | |
9337 | } | |
9338 | } | |
9339 | ||
72bf9492 DJ |
9340 | /* Adjust PART_DIE before generating a symbol for it. This function |
9341 | may set the is_external flag or change the DIE's name. */ | |
9342 | ||
9343 | static void | |
9344 | fixup_partial_die (struct partial_die_info *part_die, | |
9345 | struct dwarf2_cu *cu) | |
9346 | { | |
abc72ce4 DE |
9347 | /* Once we've fixed up a die, there's no point in doing so again. |
9348 | This also avoids a memory leak if we were to call | |
9349 | guess_partial_die_structure_name multiple times. */ | |
9350 | if (part_die->fixup_called) | |
9351 | return; | |
9352 | ||
72bf9492 DJ |
9353 | /* If we found a reference attribute and the DIE has no name, try |
9354 | to find a name in the referred to DIE. */ | |
9355 | ||
9356 | if (part_die->name == NULL && part_die->has_specification) | |
9357 | { | |
9358 | struct partial_die_info *spec_die; | |
72bf9492 | 9359 | |
10b3939b | 9360 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 9361 | |
10b3939b | 9362 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
9363 | |
9364 | if (spec_die->name) | |
9365 | { | |
9366 | part_die->name = spec_die->name; | |
9367 | ||
9368 | /* Copy DW_AT_external attribute if it is set. */ | |
9369 | if (spec_die->is_external) | |
9370 | part_die->is_external = spec_die->is_external; | |
9371 | } | |
9372 | } | |
9373 | ||
9374 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
9375 | |
9376 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
9377 | part_die->name = "(anonymous namespace)"; | |
9378 | ||
abc72ce4 DE |
9379 | /* If there is no parent die to provide a namespace, and there are |
9380 | children, see if we can determine the namespace from their linkage | |
9381 | name. | |
9382 | NOTE: We need to do this even if cu->has_namespace_info != 0. | |
9383 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ | |
9384 | if (cu->language == language_cplus | |
9385 | && dwarf2_per_objfile->types.asection != NULL | |
9386 | && part_die->die_parent == NULL | |
9387 | && part_die->has_children | |
9388 | && (part_die->tag == DW_TAG_class_type | |
9389 | || part_die->tag == DW_TAG_structure_type | |
9390 | || part_die->tag == DW_TAG_union_type)) | |
9391 | guess_partial_die_structure_name (part_die, cu); | |
9392 | ||
53832f31 TT |
9393 | /* GCC might emit a nameless struct or union that has a linkage |
9394 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
9395 | if (part_die->name == NULL | |
9396 | && (part_die->tag == DW_TAG_structure_type | |
9397 | || part_die->tag == DW_TAG_union_type | |
9398 | || part_die->tag == DW_TAG_class_type) | |
9399 | && part_die->linkage_name != NULL) | |
9400 | { | |
9401 | char *demangled; | |
9402 | ||
9403 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); | |
9404 | if (demangled) | |
9405 | { | |
9406 | part_die->name = obsavestring (demangled, strlen (demangled), | |
9407 | &cu->objfile->objfile_obstack); | |
9408 | xfree (demangled); | |
9409 | } | |
9410 | } | |
9411 | ||
abc72ce4 | 9412 | part_die->fixup_called = 1; |
72bf9492 DJ |
9413 | } |
9414 | ||
a8329558 | 9415 | /* Read an attribute value described by an attribute form. */ |
c906108c | 9416 | |
fe1b8b76 | 9417 | static gdb_byte * |
a8329558 | 9418 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 9419 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 9420 | struct dwarf2_cu *cu) |
c906108c | 9421 | { |
e7c27a73 | 9422 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9423 | unsigned int bytes_read; |
9424 | struct dwarf_block *blk; | |
9425 | ||
a8329558 KW |
9426 | attr->form = form; |
9427 | switch (form) | |
c906108c | 9428 | { |
c906108c | 9429 | case DW_FORM_ref_addr: |
ae411497 TT |
9430 | if (cu->header.version == 2) |
9431 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
9432 | else | |
3e43a32a MS |
9433 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
9434 | &cu->header, &bytes_read); | |
ae411497 TT |
9435 | info_ptr += bytes_read; |
9436 | break; | |
9437 | case DW_FORM_addr: | |
e7c27a73 | 9438 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 9439 | info_ptr += bytes_read; |
c906108c SS |
9440 | break; |
9441 | case DW_FORM_block2: | |
7b5a2f43 | 9442 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9443 | blk->size = read_2_bytes (abfd, info_ptr); |
9444 | info_ptr += 2; | |
9445 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9446 | info_ptr += blk->size; | |
9447 | DW_BLOCK (attr) = blk; | |
9448 | break; | |
9449 | case DW_FORM_block4: | |
7b5a2f43 | 9450 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9451 | blk->size = read_4_bytes (abfd, info_ptr); |
9452 | info_ptr += 4; | |
9453 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9454 | info_ptr += blk->size; | |
9455 | DW_BLOCK (attr) = blk; | |
9456 | break; | |
9457 | case DW_FORM_data2: | |
9458 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
9459 | info_ptr += 2; | |
9460 | break; | |
9461 | case DW_FORM_data4: | |
9462 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
9463 | info_ptr += 4; | |
9464 | break; | |
9465 | case DW_FORM_data8: | |
9466 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
9467 | info_ptr += 8; | |
9468 | break; | |
2dc7f7b3 TT |
9469 | case DW_FORM_sec_offset: |
9470 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9471 | info_ptr += bytes_read; | |
9472 | break; | |
c906108c | 9473 | case DW_FORM_string: |
9b1c24c8 | 9474 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 9475 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
9476 | info_ptr += bytes_read; |
9477 | break; | |
4bdf3d34 JJ |
9478 | case DW_FORM_strp: |
9479 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
9480 | &bytes_read); | |
8285870a | 9481 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
9482 | info_ptr += bytes_read; |
9483 | break; | |
2dc7f7b3 | 9484 | case DW_FORM_exprloc: |
c906108c | 9485 | case DW_FORM_block: |
7b5a2f43 | 9486 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9487 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9488 | info_ptr += bytes_read; | |
9489 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9490 | info_ptr += blk->size; | |
9491 | DW_BLOCK (attr) = blk; | |
9492 | break; | |
9493 | case DW_FORM_block1: | |
7b5a2f43 | 9494 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9495 | blk->size = read_1_byte (abfd, info_ptr); |
9496 | info_ptr += 1; | |
9497 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9498 | info_ptr += blk->size; | |
9499 | DW_BLOCK (attr) = blk; | |
9500 | break; | |
9501 | case DW_FORM_data1: | |
9502 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9503 | info_ptr += 1; | |
9504 | break; | |
9505 | case DW_FORM_flag: | |
9506 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9507 | info_ptr += 1; | |
9508 | break; | |
2dc7f7b3 TT |
9509 | case DW_FORM_flag_present: |
9510 | DW_UNSND (attr) = 1; | |
9511 | break; | |
c906108c SS |
9512 | case DW_FORM_sdata: |
9513 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
9514 | info_ptr += bytes_read; | |
9515 | break; | |
9516 | case DW_FORM_udata: | |
9517 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9518 | info_ptr += bytes_read; | |
9519 | break; | |
9520 | case DW_FORM_ref1: | |
10b3939b | 9521 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
9522 | info_ptr += 1; |
9523 | break; | |
9524 | case DW_FORM_ref2: | |
10b3939b | 9525 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
9526 | info_ptr += 2; |
9527 | break; | |
9528 | case DW_FORM_ref4: | |
10b3939b | 9529 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
9530 | info_ptr += 4; |
9531 | break; | |
613e1657 | 9532 | case DW_FORM_ref8: |
10b3939b | 9533 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
9534 | info_ptr += 8; |
9535 | break; | |
55f1336d | 9536 | case DW_FORM_ref_sig8: |
348e048f DE |
9537 | /* Convert the signature to something we can record in DW_UNSND |
9538 | for later lookup. | |
9539 | NOTE: This is NULL if the type wasn't found. */ | |
9540 | DW_SIGNATURED_TYPE (attr) = | |
9541 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
9542 | info_ptr += 8; | |
9543 | break; | |
c906108c | 9544 | case DW_FORM_ref_udata: |
10b3939b DJ |
9545 | DW_ADDR (attr) = (cu->header.offset |
9546 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
9547 | info_ptr += bytes_read; |
9548 | break; | |
c906108c | 9549 | case DW_FORM_indirect: |
a8329558 KW |
9550 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9551 | info_ptr += bytes_read; | |
e7c27a73 | 9552 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 9553 | break; |
c906108c | 9554 | default: |
8a3fe4f8 | 9555 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
9556 | dwarf_form_name (form), |
9557 | bfd_get_filename (abfd)); | |
c906108c | 9558 | } |
28e94949 JB |
9559 | |
9560 | /* We have seen instances where the compiler tried to emit a byte | |
9561 | size attribute of -1 which ended up being encoded as an unsigned | |
9562 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
9563 | an object of this size seems pretty unlikely so we can relatively | |
9564 | safely treat these cases as if the size attribute was invalid and | |
9565 | treat them as zero by default. */ | |
9566 | if (attr->name == DW_AT_byte_size | |
9567 | && form == DW_FORM_data4 | |
9568 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
9569 | { |
9570 | complaint | |
9571 | (&symfile_complaints, | |
43bbcdc2 PH |
9572 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
9573 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
9574 | DW_UNSND (attr) = 0; |
9575 | } | |
28e94949 | 9576 | |
c906108c SS |
9577 | return info_ptr; |
9578 | } | |
9579 | ||
a8329558 KW |
9580 | /* Read an attribute described by an abbreviated attribute. */ |
9581 | ||
fe1b8b76 | 9582 | static gdb_byte * |
a8329558 | 9583 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 9584 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
9585 | { |
9586 | attr->name = abbrev->name; | |
e7c27a73 | 9587 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
9588 | } |
9589 | ||
0963b4bd | 9590 | /* Read dwarf information from a buffer. */ |
c906108c SS |
9591 | |
9592 | static unsigned int | |
fe1b8b76 | 9593 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9594 | { |
fe1b8b76 | 9595 | return bfd_get_8 (abfd, buf); |
c906108c SS |
9596 | } |
9597 | ||
9598 | static int | |
fe1b8b76 | 9599 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9600 | { |
fe1b8b76 | 9601 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
9602 | } |
9603 | ||
9604 | static unsigned int | |
fe1b8b76 | 9605 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9606 | { |
fe1b8b76 | 9607 | return bfd_get_16 (abfd, buf); |
c906108c SS |
9608 | } |
9609 | ||
9610 | static int | |
fe1b8b76 | 9611 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9612 | { |
fe1b8b76 | 9613 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
9614 | } |
9615 | ||
9616 | static unsigned int | |
fe1b8b76 | 9617 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9618 | { |
fe1b8b76 | 9619 | return bfd_get_32 (abfd, buf); |
c906108c SS |
9620 | } |
9621 | ||
9622 | static int | |
fe1b8b76 | 9623 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9624 | { |
fe1b8b76 | 9625 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
9626 | } |
9627 | ||
93311388 | 9628 | static ULONGEST |
fe1b8b76 | 9629 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9630 | { |
fe1b8b76 | 9631 | return bfd_get_64 (abfd, buf); |
c906108c SS |
9632 | } |
9633 | ||
9634 | static CORE_ADDR | |
fe1b8b76 | 9635 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 9636 | unsigned int *bytes_read) |
c906108c | 9637 | { |
e7c27a73 | 9638 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9639 | CORE_ADDR retval = 0; |
9640 | ||
107d2387 | 9641 | if (cu_header->signed_addr_p) |
c906108c | 9642 | { |
107d2387 AC |
9643 | switch (cu_header->addr_size) |
9644 | { | |
9645 | case 2: | |
fe1b8b76 | 9646 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
9647 | break; |
9648 | case 4: | |
fe1b8b76 | 9649 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
9650 | break; |
9651 | case 8: | |
fe1b8b76 | 9652 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
9653 | break; |
9654 | default: | |
8e65ff28 | 9655 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9656 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 9657 | bfd_get_filename (abfd)); |
107d2387 AC |
9658 | } |
9659 | } | |
9660 | else | |
9661 | { | |
9662 | switch (cu_header->addr_size) | |
9663 | { | |
9664 | case 2: | |
fe1b8b76 | 9665 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
9666 | break; |
9667 | case 4: | |
fe1b8b76 | 9668 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
9669 | break; |
9670 | case 8: | |
fe1b8b76 | 9671 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
9672 | break; |
9673 | default: | |
8e65ff28 | 9674 | internal_error (__FILE__, __LINE__, |
a73c6dcd MS |
9675 | _("read_address: bad switch, " |
9676 | "unsigned [in module %s]"), | |
659b0389 | 9677 | bfd_get_filename (abfd)); |
107d2387 | 9678 | } |
c906108c | 9679 | } |
64367e0a | 9680 | |
107d2387 AC |
9681 | *bytes_read = cu_header->addr_size; |
9682 | return retval; | |
c906108c SS |
9683 | } |
9684 | ||
f7ef9339 | 9685 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
9686 | specification allows the initial length to take up either 4 bytes |
9687 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
9688 | bytes describe the length and all offsets will be 8 bytes in length | |
9689 | instead of 4. | |
9690 | ||
f7ef9339 KB |
9691 | An older, non-standard 64-bit format is also handled by this |
9692 | function. The older format in question stores the initial length | |
9693 | as an 8-byte quantity without an escape value. Lengths greater | |
9694 | than 2^32 aren't very common which means that the initial 4 bytes | |
9695 | is almost always zero. Since a length value of zero doesn't make | |
9696 | sense for the 32-bit format, this initial zero can be considered to | |
9697 | be an escape value which indicates the presence of the older 64-bit | |
9698 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
9699 | greater than 4GB. If it becomes necessary to handle lengths |
9700 | somewhat larger than 4GB, we could allow other small values (such | |
9701 | as the non-sensical values of 1, 2, and 3) to also be used as | |
9702 | escape values indicating the presence of the old format. | |
f7ef9339 | 9703 | |
917c78fc MK |
9704 | The value returned via bytes_read should be used to increment the |
9705 | relevant pointer after calling read_initial_length(). | |
c764a876 | 9706 | |
613e1657 KB |
9707 | [ Note: read_initial_length() and read_offset() are based on the |
9708 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 9709 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
9710 | from: |
9711 | ||
f7ef9339 | 9712 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 9713 | |
613e1657 KB |
9714 | This document is only a draft and is subject to change. (So beware.) |
9715 | ||
f7ef9339 | 9716 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
9717 | determined empirically by examining 64-bit ELF files produced by |
9718 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
9719 | |
9720 | - Kevin, July 16, 2002 | |
613e1657 KB |
9721 | ] */ |
9722 | ||
9723 | static LONGEST | |
c764a876 | 9724 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 9725 | { |
fe1b8b76 | 9726 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 9727 | |
dd373385 | 9728 | if (length == 0xffffffff) |
613e1657 | 9729 | { |
fe1b8b76 | 9730 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 9731 | *bytes_read = 12; |
613e1657 | 9732 | } |
dd373385 | 9733 | else if (length == 0) |
f7ef9339 | 9734 | { |
dd373385 | 9735 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 9736 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 9737 | *bytes_read = 8; |
f7ef9339 | 9738 | } |
613e1657 KB |
9739 | else |
9740 | { | |
9741 | *bytes_read = 4; | |
613e1657 KB |
9742 | } |
9743 | ||
c764a876 DE |
9744 | return length; |
9745 | } | |
dd373385 | 9746 | |
c764a876 DE |
9747 | /* Cover function for read_initial_length. |
9748 | Returns the length of the object at BUF, and stores the size of the | |
9749 | initial length in *BYTES_READ and stores the size that offsets will be in | |
9750 | *OFFSET_SIZE. | |
9751 | If the initial length size is not equivalent to that specified in | |
9752 | CU_HEADER then issue a complaint. | |
9753 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 9754 | |
c764a876 DE |
9755 | static LONGEST |
9756 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
9757 | const struct comp_unit_head *cu_header, | |
9758 | unsigned int *bytes_read, | |
9759 | unsigned int *offset_size) | |
9760 | { | |
9761 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
9762 | ||
9763 | gdb_assert (cu_header->initial_length_size == 4 | |
9764 | || cu_header->initial_length_size == 8 | |
9765 | || cu_header->initial_length_size == 12); | |
9766 | ||
9767 | if (cu_header->initial_length_size != *bytes_read) | |
9768 | complaint (&symfile_complaints, | |
9769 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 9770 | |
c764a876 | 9771 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 9772 | return length; |
613e1657 KB |
9773 | } |
9774 | ||
9775 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 9776 | given by cu_header->offset_size. */ |
613e1657 KB |
9777 | |
9778 | static LONGEST | |
fe1b8b76 | 9779 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 9780 | unsigned int *bytes_read) |
c764a876 DE |
9781 | { |
9782 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 9783 | |
c764a876 DE |
9784 | *bytes_read = cu_header->offset_size; |
9785 | return offset; | |
9786 | } | |
9787 | ||
9788 | /* Read an offset from the data stream. */ | |
9789 | ||
9790 | static LONGEST | |
9791 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
9792 | { |
9793 | LONGEST retval = 0; | |
9794 | ||
c764a876 | 9795 | switch (offset_size) |
613e1657 KB |
9796 | { |
9797 | case 4: | |
fe1b8b76 | 9798 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
9799 | break; |
9800 | case 8: | |
fe1b8b76 | 9801 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
9802 | break; |
9803 | default: | |
8e65ff28 | 9804 | internal_error (__FILE__, __LINE__, |
c764a876 | 9805 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 9806 | bfd_get_filename (abfd)); |
613e1657 KB |
9807 | } |
9808 | ||
917c78fc | 9809 | return retval; |
613e1657 KB |
9810 | } |
9811 | ||
fe1b8b76 JB |
9812 | static gdb_byte * |
9813 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
9814 | { |
9815 | /* If the size of a host char is 8 bits, we can return a pointer | |
9816 | to the buffer, otherwise we have to copy the data to a buffer | |
9817 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9818 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 9819 | return buf; |
c906108c SS |
9820 | } |
9821 | ||
9822 | static char * | |
9b1c24c8 | 9823 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
9824 | { |
9825 | /* If the size of a host char is 8 bits, we can return a pointer | |
9826 | to the string, otherwise we have to copy the string to a buffer | |
9827 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9828 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
9829 | if (*buf == '\0') |
9830 | { | |
9831 | *bytes_read_ptr = 1; | |
9832 | return NULL; | |
9833 | } | |
fe1b8b76 JB |
9834 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
9835 | return (char *) buf; | |
4bdf3d34 JJ |
9836 | } |
9837 | ||
9838 | static char * | |
fe1b8b76 | 9839 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
9840 | const struct comp_unit_head *cu_header, |
9841 | unsigned int *bytes_read_ptr) | |
9842 | { | |
c764a876 | 9843 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 9844 | |
be391dca | 9845 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 9846 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 9847 | { |
8a3fe4f8 | 9848 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 9849 | bfd_get_filename (abfd)); |
4bdf3d34 | 9850 | return NULL; |
c906108c | 9851 | } |
dce234bc | 9852 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 9853 | { |
3e43a32a MS |
9854 | error (_("DW_FORM_strp pointing outside of " |
9855 | ".debug_str section [in module %s]"), | |
9856 | bfd_get_filename (abfd)); | |
c906108c SS |
9857 | return NULL; |
9858 | } | |
4bdf3d34 | 9859 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 9860 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 9861 | return NULL; |
dce234bc | 9862 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
9863 | } |
9864 | ||
ce5d95e1 | 9865 | static unsigned long |
fe1b8b76 | 9866 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9867 | { |
ce5d95e1 JB |
9868 | unsigned long result; |
9869 | unsigned int num_read; | |
c906108c SS |
9870 | int i, shift; |
9871 | unsigned char byte; | |
9872 | ||
9873 | result = 0; | |
9874 | shift = 0; | |
9875 | num_read = 0; | |
9876 | i = 0; | |
9877 | while (1) | |
9878 | { | |
fe1b8b76 | 9879 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9880 | buf++; |
9881 | num_read++; | |
ce5d95e1 | 9882 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
9883 | if ((byte & 128) == 0) |
9884 | { | |
9885 | break; | |
9886 | } | |
9887 | shift += 7; | |
9888 | } | |
9889 | *bytes_read_ptr = num_read; | |
9890 | return result; | |
9891 | } | |
9892 | ||
ce5d95e1 | 9893 | static long |
fe1b8b76 | 9894 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9895 | { |
ce5d95e1 | 9896 | long result; |
77e0b926 | 9897 | int i, shift, num_read; |
c906108c SS |
9898 | unsigned char byte; |
9899 | ||
9900 | result = 0; | |
9901 | shift = 0; | |
c906108c SS |
9902 | num_read = 0; |
9903 | i = 0; | |
9904 | while (1) | |
9905 | { | |
fe1b8b76 | 9906 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9907 | buf++; |
9908 | num_read++; | |
ce5d95e1 | 9909 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
9910 | shift += 7; |
9911 | if ((byte & 128) == 0) | |
9912 | { | |
9913 | break; | |
9914 | } | |
9915 | } | |
77e0b926 DJ |
9916 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
9917 | result |= -(((long)1) << shift); | |
c906108c SS |
9918 | *bytes_read_ptr = num_read; |
9919 | return result; | |
9920 | } | |
9921 | ||
4bb7a0a7 DJ |
9922 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
9923 | ||
fe1b8b76 JB |
9924 | static gdb_byte * |
9925 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
9926 | { |
9927 | int byte; | |
9928 | ||
9929 | while (1) | |
9930 | { | |
fe1b8b76 | 9931 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
9932 | buf++; |
9933 | if ((byte & 128) == 0) | |
9934 | return buf; | |
9935 | } | |
9936 | } | |
9937 | ||
c906108c | 9938 | static void |
e142c38c | 9939 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
9940 | { |
9941 | switch (lang) | |
9942 | { | |
9943 | case DW_LANG_C89: | |
76bee0cc | 9944 | case DW_LANG_C99: |
c906108c | 9945 | case DW_LANG_C: |
e142c38c | 9946 | cu->language = language_c; |
c906108c SS |
9947 | break; |
9948 | case DW_LANG_C_plus_plus: | |
e142c38c | 9949 | cu->language = language_cplus; |
c906108c | 9950 | break; |
6aecb9c2 JB |
9951 | case DW_LANG_D: |
9952 | cu->language = language_d; | |
9953 | break; | |
c906108c SS |
9954 | case DW_LANG_Fortran77: |
9955 | case DW_LANG_Fortran90: | |
b21b22e0 | 9956 | case DW_LANG_Fortran95: |
e142c38c | 9957 | cu->language = language_fortran; |
c906108c SS |
9958 | break; |
9959 | case DW_LANG_Mips_Assembler: | |
e142c38c | 9960 | cu->language = language_asm; |
c906108c | 9961 | break; |
bebd888e | 9962 | case DW_LANG_Java: |
e142c38c | 9963 | cu->language = language_java; |
bebd888e | 9964 | break; |
c906108c | 9965 | case DW_LANG_Ada83: |
8aaf0b47 | 9966 | case DW_LANG_Ada95: |
bc5f45f8 JB |
9967 | cu->language = language_ada; |
9968 | break; | |
72019c9c GM |
9969 | case DW_LANG_Modula2: |
9970 | cu->language = language_m2; | |
9971 | break; | |
fe8e67fd PM |
9972 | case DW_LANG_Pascal83: |
9973 | cu->language = language_pascal; | |
9974 | break; | |
22566fbd DJ |
9975 | case DW_LANG_ObjC: |
9976 | cu->language = language_objc; | |
9977 | break; | |
c906108c SS |
9978 | case DW_LANG_Cobol74: |
9979 | case DW_LANG_Cobol85: | |
c906108c | 9980 | default: |
e142c38c | 9981 | cu->language = language_minimal; |
c906108c SS |
9982 | break; |
9983 | } | |
e142c38c | 9984 | cu->language_defn = language_def (cu->language); |
c906108c SS |
9985 | } |
9986 | ||
9987 | /* Return the named attribute or NULL if not there. */ | |
9988 | ||
9989 | static struct attribute * | |
e142c38c | 9990 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
9991 | { |
9992 | unsigned int i; | |
9993 | struct attribute *spec = NULL; | |
9994 | ||
9995 | for (i = 0; i < die->num_attrs; ++i) | |
9996 | { | |
9997 | if (die->attrs[i].name == name) | |
10b3939b | 9998 | return &die->attrs[i]; |
c906108c SS |
9999 | if (die->attrs[i].name == DW_AT_specification |
10000 | || die->attrs[i].name == DW_AT_abstract_origin) | |
10001 | spec = &die->attrs[i]; | |
10002 | } | |
c906108c | 10003 | |
10b3939b | 10004 | if (spec) |
f2f0e013 DJ |
10005 | { |
10006 | die = follow_die_ref (die, spec, &cu); | |
10007 | return dwarf2_attr (die, name, cu); | |
10008 | } | |
c5aa993b | 10009 | |
c906108c SS |
10010 | return NULL; |
10011 | } | |
10012 | ||
348e048f DE |
10013 | /* Return the named attribute or NULL if not there, |
10014 | but do not follow DW_AT_specification, etc. | |
10015 | This is for use in contexts where we're reading .debug_types dies. | |
10016 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
10017 | back up the chain, and we want to go down. */ | |
10018 | ||
10019 | static struct attribute * | |
10020 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
10021 | struct dwarf2_cu *cu) | |
10022 | { | |
10023 | unsigned int i; | |
10024 | ||
10025 | for (i = 0; i < die->num_attrs; ++i) | |
10026 | if (die->attrs[i].name == name) | |
10027 | return &die->attrs[i]; | |
10028 | ||
10029 | return NULL; | |
10030 | } | |
10031 | ||
05cf31d1 JB |
10032 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
10033 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 10034 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
10035 | |
10036 | static int | |
10037 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
10038 | { | |
10039 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
10040 | ||
10041 | return (attr && DW_UNSND (attr)); | |
10042 | } | |
10043 | ||
3ca72b44 | 10044 | static int |
e142c38c | 10045 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 10046 | { |
05cf31d1 JB |
10047 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
10048 | which value is non-zero. However, we have to be careful with | |
10049 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
10050 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
10051 | end up accidently finding a declaration attribute that belongs | |
10052 | to a different DIE referenced by the specification attribute, | |
10053 | even though the given DIE does not have a declaration attribute. */ | |
10054 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
10055 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
10056 | } |
10057 | ||
63d06c5c | 10058 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 10059 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
10060 | containing the return value on output. If there is no |
10061 | specification, but there is an abstract origin, that is | |
10062 | returned. */ | |
63d06c5c DC |
10063 | |
10064 | static struct die_info * | |
f2f0e013 | 10065 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 10066 | { |
f2f0e013 DJ |
10067 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
10068 | *spec_cu); | |
63d06c5c | 10069 | |
edb3359d DJ |
10070 | if (spec_attr == NULL) |
10071 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
10072 | ||
63d06c5c DC |
10073 | if (spec_attr == NULL) |
10074 | return NULL; | |
10075 | else | |
f2f0e013 | 10076 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 10077 | } |
c906108c | 10078 | |
debd256d | 10079 | /* Free the line_header structure *LH, and any arrays and strings it |
ae2de4f8 DE |
10080 | refers to. |
10081 | NOTE: This is also used as a "cleanup" function. */ | |
10082 | ||
debd256d JB |
10083 | static void |
10084 | free_line_header (struct line_header *lh) | |
10085 | { | |
10086 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 10087 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
10088 | |
10089 | /* Remember that all the lh->file_names[i].name pointers are | |
10090 | pointers into debug_line_buffer, and don't need to be freed. */ | |
10091 | if (lh->file_names) | |
a8bc7b56 | 10092 | xfree (lh->file_names); |
debd256d JB |
10093 | |
10094 | /* Similarly for the include directory names. */ | |
10095 | if (lh->include_dirs) | |
a8bc7b56 | 10096 | xfree (lh->include_dirs); |
debd256d | 10097 | |
a8bc7b56 | 10098 | xfree (lh); |
debd256d JB |
10099 | } |
10100 | ||
debd256d | 10101 | /* Add an entry to LH's include directory table. */ |
ae2de4f8 | 10102 | |
debd256d JB |
10103 | static void |
10104 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 10105 | { |
debd256d JB |
10106 | /* Grow the array if necessary. */ |
10107 | if (lh->include_dirs_size == 0) | |
c5aa993b | 10108 | { |
debd256d JB |
10109 | lh->include_dirs_size = 1; /* for testing */ |
10110 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
10111 | * sizeof (*lh->include_dirs)); | |
10112 | } | |
10113 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
10114 | { | |
10115 | lh->include_dirs_size *= 2; | |
10116 | lh->include_dirs = xrealloc (lh->include_dirs, | |
10117 | (lh->include_dirs_size | |
10118 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 10119 | } |
c906108c | 10120 | |
debd256d JB |
10121 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
10122 | } | |
6e70227d | 10123 | |
debd256d | 10124 | /* Add an entry to LH's file name table. */ |
ae2de4f8 | 10125 | |
debd256d JB |
10126 | static void |
10127 | add_file_name (struct line_header *lh, | |
10128 | char *name, | |
10129 | unsigned int dir_index, | |
10130 | unsigned int mod_time, | |
10131 | unsigned int length) | |
10132 | { | |
10133 | struct file_entry *fe; | |
10134 | ||
10135 | /* Grow the array if necessary. */ | |
10136 | if (lh->file_names_size == 0) | |
10137 | { | |
10138 | lh->file_names_size = 1; /* for testing */ | |
10139 | lh->file_names = xmalloc (lh->file_names_size | |
10140 | * sizeof (*lh->file_names)); | |
10141 | } | |
10142 | else if (lh->num_file_names >= lh->file_names_size) | |
10143 | { | |
10144 | lh->file_names_size *= 2; | |
10145 | lh->file_names = xrealloc (lh->file_names, | |
10146 | (lh->file_names_size | |
10147 | * sizeof (*lh->file_names))); | |
10148 | } | |
10149 | ||
10150 | fe = &lh->file_names[lh->num_file_names++]; | |
10151 | fe->name = name; | |
10152 | fe->dir_index = dir_index; | |
10153 | fe->mod_time = mod_time; | |
10154 | fe->length = length; | |
aaa75496 | 10155 | fe->included_p = 0; |
cb1df416 | 10156 | fe->symtab = NULL; |
debd256d | 10157 | } |
6e70227d | 10158 | |
debd256d | 10159 | /* Read the statement program header starting at OFFSET in |
6502dd73 DJ |
10160 | .debug_line, according to the endianness of ABFD. Return a pointer |
10161 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
10162 | |
10163 | NOTE: the strings in the include directory and file name tables of | |
10164 | the returned object point into debug_line_buffer, and must not be | |
10165 | freed. */ | |
ae2de4f8 | 10166 | |
debd256d JB |
10167 | static struct line_header * |
10168 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 10169 | struct dwarf2_cu *cu) |
debd256d JB |
10170 | { |
10171 | struct cleanup *back_to; | |
10172 | struct line_header *lh; | |
fe1b8b76 | 10173 | gdb_byte *line_ptr; |
c764a876 | 10174 | unsigned int bytes_read, offset_size; |
debd256d JB |
10175 | int i; |
10176 | char *cur_dir, *cur_file; | |
10177 | ||
be391dca | 10178 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 10179 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 10180 | { |
e2e0b3e5 | 10181 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
10182 | return 0; |
10183 | } | |
10184 | ||
a738430d MK |
10185 | /* Make sure that at least there's room for the total_length field. |
10186 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 10187 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 10188 | { |
4d3c2250 | 10189 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10190 | return 0; |
10191 | } | |
10192 | ||
10193 | lh = xmalloc (sizeof (*lh)); | |
10194 | memset (lh, 0, sizeof (*lh)); | |
10195 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
10196 | (void *) lh); | |
10197 | ||
dce234bc | 10198 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 10199 | |
a738430d | 10200 | /* Read in the header. */ |
6e70227d | 10201 | lh->total_length = |
c764a876 DE |
10202 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
10203 | &bytes_read, &offset_size); | |
debd256d | 10204 | line_ptr += bytes_read; |
dce234bc PP |
10205 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
10206 | + dwarf2_per_objfile->line.size)) | |
debd256d | 10207 | { |
4d3c2250 | 10208 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
10209 | return 0; |
10210 | } | |
10211 | lh->statement_program_end = line_ptr + lh->total_length; | |
10212 | lh->version = read_2_bytes (abfd, line_ptr); | |
10213 | line_ptr += 2; | |
c764a876 DE |
10214 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
10215 | line_ptr += offset_size; | |
debd256d JB |
10216 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
10217 | line_ptr += 1; | |
2dc7f7b3 TT |
10218 | if (lh->version >= 4) |
10219 | { | |
10220 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
10221 | line_ptr += 1; | |
10222 | } | |
10223 | else | |
10224 | lh->maximum_ops_per_instruction = 1; | |
10225 | ||
10226 | if (lh->maximum_ops_per_instruction == 0) | |
10227 | { | |
10228 | lh->maximum_ops_per_instruction = 1; | |
10229 | complaint (&symfile_complaints, | |
3e43a32a MS |
10230 | _("invalid maximum_ops_per_instruction " |
10231 | "in `.debug_line' section")); | |
2dc7f7b3 TT |
10232 | } |
10233 | ||
debd256d JB |
10234 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
10235 | line_ptr += 1; | |
10236 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
10237 | line_ptr += 1; | |
10238 | lh->line_range = read_1_byte (abfd, line_ptr); | |
10239 | line_ptr += 1; | |
10240 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
10241 | line_ptr += 1; | |
10242 | lh->standard_opcode_lengths | |
fe1b8b76 | 10243 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
10244 | |
10245 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
10246 | for (i = 1; i < lh->opcode_base; ++i) | |
10247 | { | |
10248 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
10249 | line_ptr += 1; | |
10250 | } | |
10251 | ||
a738430d | 10252 | /* Read directory table. */ |
9b1c24c8 | 10253 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10254 | { |
10255 | line_ptr += bytes_read; | |
10256 | add_include_dir (lh, cur_dir); | |
10257 | } | |
10258 | line_ptr += bytes_read; | |
10259 | ||
a738430d | 10260 | /* Read file name table. */ |
9b1c24c8 | 10261 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
10262 | { |
10263 | unsigned int dir_index, mod_time, length; | |
10264 | ||
10265 | line_ptr += bytes_read; | |
10266 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10267 | line_ptr += bytes_read; | |
10268 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10269 | line_ptr += bytes_read; | |
10270 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10271 | line_ptr += bytes_read; | |
10272 | ||
10273 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10274 | } | |
10275 | line_ptr += bytes_read; | |
6e70227d | 10276 | lh->statement_program_start = line_ptr; |
debd256d | 10277 | |
dce234bc PP |
10278 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
10279 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 10280 | complaint (&symfile_complaints, |
3e43a32a MS |
10281 | _("line number info header doesn't " |
10282 | "fit in `.debug_line' section")); | |
debd256d JB |
10283 | |
10284 | discard_cleanups (back_to); | |
10285 | return lh; | |
10286 | } | |
c906108c | 10287 | |
5fb290d7 DJ |
10288 | /* This function exists to work around a bug in certain compilers |
10289 | (particularly GCC 2.95), in which the first line number marker of a | |
10290 | function does not show up until after the prologue, right before | |
10291 | the second line number marker. This function shifts ADDRESS down | |
10292 | to the beginning of the function if necessary, and is called on | |
10293 | addresses passed to record_line. */ | |
10294 | ||
10295 | static CORE_ADDR | |
e142c38c | 10296 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
10297 | { |
10298 | struct function_range *fn; | |
10299 | ||
10300 | /* Find the function_range containing address. */ | |
e142c38c | 10301 | if (!cu->first_fn) |
5fb290d7 DJ |
10302 | return address; |
10303 | ||
e142c38c DJ |
10304 | if (!cu->cached_fn) |
10305 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 10306 | |
e142c38c | 10307 | fn = cu->cached_fn; |
5fb290d7 DJ |
10308 | while (fn) |
10309 | if (fn->lowpc <= address && fn->highpc > address) | |
10310 | goto found; | |
10311 | else | |
10312 | fn = fn->next; | |
10313 | ||
e142c38c DJ |
10314 | fn = cu->first_fn; |
10315 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
10316 | if (fn->lowpc <= address && fn->highpc > address) |
10317 | goto found; | |
10318 | else | |
10319 | fn = fn->next; | |
10320 | ||
10321 | return address; | |
10322 | ||
10323 | found: | |
10324 | if (fn->seen_line) | |
10325 | return address; | |
10326 | if (address != fn->lowpc) | |
4d3c2250 | 10327 | complaint (&symfile_complaints, |
e2e0b3e5 | 10328 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 10329 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
10330 | fn->seen_line = 1; |
10331 | return fn->lowpc; | |
10332 | } | |
10333 | ||
c6da4cef DE |
10334 | /* Subroutine of dwarf_decode_lines to simplify it. |
10335 | Return the file name of the psymtab for included file FILE_INDEX | |
10336 | in line header LH of PST. | |
10337 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10338 | If space for the result is malloc'd, it will be freed by a cleanup. | |
10339 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
10340 | ||
10341 | static char * | |
10342 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
10343 | const struct partial_symtab *pst, | |
10344 | const char *comp_dir) | |
10345 | { | |
10346 | const struct file_entry fe = lh->file_names [file_index]; | |
10347 | char *include_name = fe.name; | |
10348 | char *include_name_to_compare = include_name; | |
10349 | char *dir_name = NULL; | |
72b9f47f TT |
10350 | const char *pst_filename; |
10351 | char *copied_name = NULL; | |
c6da4cef DE |
10352 | int file_is_pst; |
10353 | ||
10354 | if (fe.dir_index) | |
10355 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
10356 | ||
10357 | if (!IS_ABSOLUTE_PATH (include_name) | |
10358 | && (dir_name != NULL || comp_dir != NULL)) | |
10359 | { | |
10360 | /* Avoid creating a duplicate psymtab for PST. | |
10361 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
10362 | Before we do the comparison, however, we need to account | |
10363 | for DIR_NAME and COMP_DIR. | |
10364 | First prepend dir_name (if non-NULL). If we still don't | |
10365 | have an absolute path prepend comp_dir (if non-NULL). | |
10366 | However, the directory we record in the include-file's | |
10367 | psymtab does not contain COMP_DIR (to match the | |
10368 | corresponding symtab(s)). | |
10369 | ||
10370 | Example: | |
10371 | ||
10372 | bash$ cd /tmp | |
10373 | bash$ gcc -g ./hello.c | |
10374 | include_name = "hello.c" | |
10375 | dir_name = "." | |
10376 | DW_AT_comp_dir = comp_dir = "/tmp" | |
10377 | DW_AT_name = "./hello.c" */ | |
10378 | ||
10379 | if (dir_name != NULL) | |
10380 | { | |
10381 | include_name = concat (dir_name, SLASH_STRING, | |
10382 | include_name, (char *)NULL); | |
10383 | include_name_to_compare = include_name; | |
10384 | make_cleanup (xfree, include_name); | |
10385 | } | |
10386 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
10387 | { | |
10388 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
10389 | include_name, (char *)NULL); | |
10390 | } | |
10391 | } | |
10392 | ||
10393 | pst_filename = pst->filename; | |
10394 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
10395 | { | |
72b9f47f TT |
10396 | copied_name = concat (pst->dirname, SLASH_STRING, |
10397 | pst_filename, (char *)NULL); | |
10398 | pst_filename = copied_name; | |
c6da4cef DE |
10399 | } |
10400 | ||
1e3fad37 | 10401 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
c6da4cef DE |
10402 | |
10403 | if (include_name_to_compare != include_name) | |
10404 | xfree (include_name_to_compare); | |
72b9f47f TT |
10405 | if (copied_name != NULL) |
10406 | xfree (copied_name); | |
c6da4cef DE |
10407 | |
10408 | if (file_is_pst) | |
10409 | return NULL; | |
10410 | return include_name; | |
10411 | } | |
10412 | ||
c91513d8 PP |
10413 | /* Ignore this record_line request. */ |
10414 | ||
10415 | static void | |
10416 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) | |
10417 | { | |
10418 | return; | |
10419 | } | |
10420 | ||
aaa75496 JB |
10421 | /* Decode the Line Number Program (LNP) for the given line_header |
10422 | structure and CU. The actual information extracted and the type | |
10423 | of structures created from the LNP depends on the value of PST. | |
10424 | ||
10425 | 1. If PST is NULL, then this procedure uses the data from the program | |
10426 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 10427 | |
aaa75496 JB |
10428 | 2. If PST is not NULL, this procedure reads the program to determine |
10429 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
10430 | builds all the associated partial symbol tables. |
10431 | ||
10432 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10433 | It is used for relative paths in the line table. | |
10434 | NOTE: When processing partial symtabs (pst != NULL), | |
10435 | comp_dir == pst->dirname. | |
10436 | ||
10437 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
10438 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
10439 | symtab we don't use it in the name of the psymtabs we create. | |
10440 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
10441 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 10442 | |
c906108c | 10443 | static void |
72b9f47f | 10444 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd, |
aaa75496 | 10445 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 10446 | { |
a8c50c1f | 10447 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 10448 | gdb_byte *line_end; |
a8c50c1f | 10449 | unsigned int bytes_read, extended_len; |
c906108c | 10450 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
10451 | CORE_ADDR baseaddr; |
10452 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 10453 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 10454 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 10455 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
c91513d8 PP |
10456 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
10457 | = record_line; | |
e142c38c DJ |
10458 | |
10459 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10460 | |
debd256d JB |
10461 | line_ptr = lh->statement_program_start; |
10462 | line_end = lh->statement_program_end; | |
c906108c SS |
10463 | |
10464 | /* Read the statement sequences until there's nothing left. */ | |
10465 | while (line_ptr < line_end) | |
10466 | { | |
10467 | /* state machine registers */ | |
10468 | CORE_ADDR address = 0; | |
10469 | unsigned int file = 1; | |
10470 | unsigned int line = 1; | |
10471 | unsigned int column = 0; | |
debd256d | 10472 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
10473 | int basic_block = 0; |
10474 | int end_sequence = 0; | |
fbf65064 | 10475 | CORE_ADDR addr; |
2dc7f7b3 | 10476 | unsigned char op_index = 0; |
c906108c | 10477 | |
aaa75496 | 10478 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 10479 | { |
aaa75496 | 10480 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
10481 | /* lh->include_dirs and lh->file_names are 0-based, but the |
10482 | directory and file name numbers in the statement program | |
10483 | are 1-based. */ | |
10484 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 10485 | char *dir = NULL; |
a738430d | 10486 | |
debd256d JB |
10487 | if (fe->dir_index) |
10488 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
10489 | |
10490 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
10491 | } |
10492 | ||
a738430d | 10493 | /* Decode the table. */ |
c5aa993b | 10494 | while (!end_sequence) |
c906108c SS |
10495 | { |
10496 | op_code = read_1_byte (abfd, line_ptr); | |
10497 | line_ptr += 1; | |
59205f5a JB |
10498 | if (line_ptr > line_end) |
10499 | { | |
10500 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
10501 | break; | |
10502 | } | |
9aa1fe7e | 10503 | |
debd256d | 10504 | if (op_code >= lh->opcode_base) |
6e70227d | 10505 | { |
a738430d | 10506 | /* Special operand. */ |
debd256d | 10507 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
10508 | address += (((op_index + (adj_opcode / lh->line_range)) |
10509 | / lh->maximum_ops_per_instruction) | |
10510 | * lh->minimum_instruction_length); | |
10511 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
10512 | % lh->maximum_ops_per_instruction); | |
debd256d | 10513 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 10514 | if (lh->num_file_names < file || file == 0) |
25e43795 | 10515 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
10516 | /* For now we ignore lines not starting on an |
10517 | instruction boundary. */ | |
10518 | else if (op_index == 0) | |
25e43795 DJ |
10519 | { |
10520 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 10521 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10522 | { |
10523 | if (last_subfile != current_subfile) | |
10524 | { | |
10525 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10526 | if (last_subfile) | |
c91513d8 | 10527 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
10528 | last_subfile = current_subfile; |
10529 | } | |
25e43795 | 10530 | /* Append row to matrix using current values. */ |
fbf65064 UW |
10531 | addr = check_cu_functions (address, cu); |
10532 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 10533 | (*p_record_line) (current_subfile, line, addr); |
366da635 | 10534 | } |
25e43795 | 10535 | } |
ca5f395d | 10536 | basic_block = 0; |
9aa1fe7e GK |
10537 | } |
10538 | else switch (op_code) | |
c906108c SS |
10539 | { |
10540 | case DW_LNS_extended_op: | |
3e43a32a MS |
10541 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
10542 | &bytes_read); | |
473b7be6 | 10543 | line_ptr += bytes_read; |
a8c50c1f | 10544 | extended_end = line_ptr + extended_len; |
c906108c SS |
10545 | extended_op = read_1_byte (abfd, line_ptr); |
10546 | line_ptr += 1; | |
10547 | switch (extended_op) | |
10548 | { | |
10549 | case DW_LNE_end_sequence: | |
c91513d8 | 10550 | p_record_line = record_line; |
c906108c | 10551 | end_sequence = 1; |
c906108c SS |
10552 | break; |
10553 | case DW_LNE_set_address: | |
e7c27a73 | 10554 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
c91513d8 PP |
10555 | |
10556 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) | |
10557 | { | |
10558 | /* This line table is for a function which has been | |
10559 | GCd by the linker. Ignore it. PR gdb/12528 */ | |
10560 | ||
10561 | long line_offset | |
10562 | = line_ptr - dwarf2_per_objfile->line.buffer; | |
10563 | ||
10564 | complaint (&symfile_complaints, | |
10565 | _(".debug_line address at offset 0x%lx is 0 " | |
10566 | "[in module %s]"), | |
10567 | line_offset, cu->objfile->name); | |
10568 | p_record_line = noop_record_line; | |
10569 | } | |
10570 | ||
2dc7f7b3 | 10571 | op_index = 0; |
107d2387 AC |
10572 | line_ptr += bytes_read; |
10573 | address += baseaddr; | |
c906108c SS |
10574 | break; |
10575 | case DW_LNE_define_file: | |
debd256d JB |
10576 | { |
10577 | char *cur_file; | |
10578 | unsigned int dir_index, mod_time, length; | |
6e70227d | 10579 | |
3e43a32a MS |
10580 | cur_file = read_direct_string (abfd, line_ptr, |
10581 | &bytes_read); | |
debd256d JB |
10582 | line_ptr += bytes_read; |
10583 | dir_index = | |
10584 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10585 | line_ptr += bytes_read; | |
10586 | mod_time = | |
10587 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10588 | line_ptr += bytes_read; | |
10589 | length = | |
10590 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10591 | line_ptr += bytes_read; | |
10592 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10593 | } | |
c906108c | 10594 | break; |
d0c6ba3d CC |
10595 | case DW_LNE_set_discriminator: |
10596 | /* The discriminator is not interesting to the debugger; | |
10597 | just ignore it. */ | |
10598 | line_ptr = extended_end; | |
10599 | break; | |
c906108c | 10600 | default: |
4d3c2250 | 10601 | complaint (&symfile_complaints, |
e2e0b3e5 | 10602 | _("mangled .debug_line section")); |
debd256d | 10603 | return; |
c906108c | 10604 | } |
a8c50c1f DJ |
10605 | /* Make sure that we parsed the extended op correctly. If e.g. |
10606 | we expected a different address size than the producer used, | |
10607 | we may have read the wrong number of bytes. */ | |
10608 | if (line_ptr != extended_end) | |
10609 | { | |
10610 | complaint (&symfile_complaints, | |
10611 | _("mangled .debug_line section")); | |
10612 | return; | |
10613 | } | |
c906108c SS |
10614 | break; |
10615 | case DW_LNS_copy: | |
59205f5a | 10616 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10617 | dwarf2_debug_line_missing_file_complaint (); |
10618 | else | |
366da635 | 10619 | { |
25e43795 | 10620 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 10621 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10622 | { |
10623 | if (last_subfile != current_subfile) | |
10624 | { | |
10625 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10626 | if (last_subfile) | |
c91513d8 | 10627 | (*p_record_line) (last_subfile, 0, addr); |
fbf65064 UW |
10628 | last_subfile = current_subfile; |
10629 | } | |
10630 | addr = check_cu_functions (address, cu); | |
10631 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
c91513d8 | 10632 | (*p_record_line) (current_subfile, line, addr); |
fbf65064 | 10633 | } |
366da635 | 10634 | } |
c906108c SS |
10635 | basic_block = 0; |
10636 | break; | |
10637 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
10638 | { |
10639 | CORE_ADDR adjust | |
10640 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10641 | ||
10642 | address += (((op_index + adjust) | |
10643 | / lh->maximum_ops_per_instruction) | |
10644 | * lh->minimum_instruction_length); | |
10645 | op_index = ((op_index + adjust) | |
10646 | % lh->maximum_ops_per_instruction); | |
10647 | line_ptr += bytes_read; | |
10648 | } | |
c906108c SS |
10649 | break; |
10650 | case DW_LNS_advance_line: | |
10651 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
10652 | line_ptr += bytes_read; | |
10653 | break; | |
10654 | case DW_LNS_set_file: | |
debd256d | 10655 | { |
a738430d MK |
10656 | /* The arrays lh->include_dirs and lh->file_names are |
10657 | 0-based, but the directory and file name numbers in | |
10658 | the statement program are 1-based. */ | |
debd256d | 10659 | struct file_entry *fe; |
4f1520fb | 10660 | char *dir = NULL; |
a738430d | 10661 | |
debd256d JB |
10662 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
10663 | line_ptr += bytes_read; | |
59205f5a | 10664 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10665 | dwarf2_debug_line_missing_file_complaint (); |
10666 | else | |
10667 | { | |
10668 | fe = &lh->file_names[file - 1]; | |
10669 | if (fe->dir_index) | |
10670 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10671 | if (!decode_for_pst_p) | |
10672 | { | |
10673 | last_subfile = current_subfile; | |
10674 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10675 | } | |
10676 | } | |
debd256d | 10677 | } |
c906108c SS |
10678 | break; |
10679 | case DW_LNS_set_column: | |
10680 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10681 | line_ptr += bytes_read; | |
10682 | break; | |
10683 | case DW_LNS_negate_stmt: | |
10684 | is_stmt = (!is_stmt); | |
10685 | break; | |
10686 | case DW_LNS_set_basic_block: | |
10687 | basic_block = 1; | |
10688 | break; | |
c2c6d25f JM |
10689 | /* Add to the address register of the state machine the |
10690 | address increment value corresponding to special opcode | |
a738430d MK |
10691 | 255. I.e., this value is scaled by the minimum |
10692 | instruction length since special opcode 255 would have | |
b021a221 | 10693 | scaled the increment. */ |
c906108c | 10694 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
10695 | { |
10696 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
10697 | ||
10698 | address += (((op_index + adjust) | |
10699 | / lh->maximum_ops_per_instruction) | |
10700 | * lh->minimum_instruction_length); | |
10701 | op_index = ((op_index + adjust) | |
10702 | % lh->maximum_ops_per_instruction); | |
10703 | } | |
c906108c SS |
10704 | break; |
10705 | case DW_LNS_fixed_advance_pc: | |
10706 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 10707 | op_index = 0; |
c906108c SS |
10708 | line_ptr += 2; |
10709 | break; | |
9aa1fe7e | 10710 | default: |
a738430d MK |
10711 | { |
10712 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 10713 | int i; |
a738430d | 10714 | |
debd256d | 10715 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
10716 | { |
10717 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10718 | line_ptr += bytes_read; | |
10719 | } | |
10720 | } | |
c906108c SS |
10721 | } |
10722 | } | |
59205f5a JB |
10723 | if (lh->num_file_names < file || file == 0) |
10724 | dwarf2_debug_line_missing_file_complaint (); | |
10725 | else | |
10726 | { | |
10727 | lh->file_names[file - 1].included_p = 1; | |
10728 | if (!decode_for_pst_p) | |
fbf65064 UW |
10729 | { |
10730 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
c91513d8 | 10731 | (*p_record_line) (current_subfile, 0, addr); |
fbf65064 | 10732 | } |
59205f5a | 10733 | } |
c906108c | 10734 | } |
aaa75496 JB |
10735 | |
10736 | if (decode_for_pst_p) | |
10737 | { | |
10738 | int file_index; | |
10739 | ||
10740 | /* Now that we're done scanning the Line Header Program, we can | |
10741 | create the psymtab of each included file. */ | |
10742 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
10743 | if (lh->file_names[file_index].included_p == 1) | |
10744 | { | |
c6da4cef DE |
10745 | char *include_name = |
10746 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
10747 | if (include_name != NULL) | |
aaa75496 JB |
10748 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
10749 | } | |
10750 | } | |
cb1df416 DJ |
10751 | else |
10752 | { | |
10753 | /* Make sure a symtab is created for every file, even files | |
10754 | which contain only variables (i.e. no code with associated | |
10755 | line numbers). */ | |
10756 | ||
10757 | int i; | |
10758 | struct file_entry *fe; | |
10759 | ||
10760 | for (i = 0; i < lh->num_file_names; i++) | |
10761 | { | |
10762 | char *dir = NULL; | |
9a619af0 | 10763 | |
cb1df416 DJ |
10764 | fe = &lh->file_names[i]; |
10765 | if (fe->dir_index) | |
10766 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10767 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10768 | ||
10769 | /* Skip the main file; we don't need it, and it must be | |
10770 | allocated last, so that it will show up before the | |
10771 | non-primary symtabs in the objfile's symtab list. */ | |
10772 | if (current_subfile == first_subfile) | |
10773 | continue; | |
10774 | ||
10775 | if (current_subfile->symtab == NULL) | |
10776 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
10777 | cu->objfile); | |
10778 | fe->symtab = current_subfile->symtab; | |
10779 | } | |
10780 | } | |
c906108c SS |
10781 | } |
10782 | ||
10783 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
10784 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
10785 | or NULL if not known. COMP_DIR is the compilation directory for the |
10786 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
10787 | This routine tries to keep line numbers from identical absolute and |
10788 | relative file names in a common subfile. | |
10789 | ||
10790 | Using the `list' example from the GDB testsuite, which resides in | |
10791 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
10792 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
10793 | ||
c5aa993b JM |
10794 | DW_AT_name: /srcdir/list0.c |
10795 | DW_AT_comp_dir: /compdir | |
357e46e7 | 10796 | files.files[0].name: list0.h |
c5aa993b | 10797 | files.files[0].dir: /srcdir |
357e46e7 | 10798 | files.files[1].name: list0.c |
c5aa993b | 10799 | files.files[1].dir: /srcdir |
c906108c SS |
10800 | |
10801 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
10802 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
10803 | start_subfile will ensure that this happens provided that we pass the | |
10804 | concatenation of files.files[1].dir and files.files[1].name as the | |
10805 | subfile's name. */ | |
c906108c SS |
10806 | |
10807 | static void | |
3e43a32a MS |
10808 | dwarf2_start_subfile (char *filename, const char *dirname, |
10809 | const char *comp_dir) | |
c906108c | 10810 | { |
4f1520fb FR |
10811 | char *fullname; |
10812 | ||
10813 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
10814 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
10815 | second argument to start_subfile. To be consistent, we do the | |
10816 | same here. In order not to lose the line information directory, | |
10817 | we concatenate it to the filename when it makes sense. | |
10818 | Note that the Dwarf3 standard says (speaking of filenames in line | |
10819 | information): ``The directory index is ignored for file names | |
10820 | that represent full path names''. Thus ignoring dirname in the | |
10821 | `else' branch below isn't an issue. */ | |
c906108c | 10822 | |
d5166ae1 | 10823 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
10824 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
10825 | else | |
10826 | fullname = filename; | |
c906108c | 10827 | |
4f1520fb FR |
10828 | start_subfile (fullname, comp_dir); |
10829 | ||
10830 | if (fullname != filename) | |
10831 | xfree (fullname); | |
c906108c SS |
10832 | } |
10833 | ||
4c2df51b DJ |
10834 | static void |
10835 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 10836 | struct dwarf2_cu *cu) |
4c2df51b | 10837 | { |
e7c27a73 DJ |
10838 | struct objfile *objfile = cu->objfile; |
10839 | struct comp_unit_head *cu_header = &cu->header; | |
10840 | ||
4c2df51b DJ |
10841 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
10842 | code here to turn a symbol with DW_AT_external and a | |
10843 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
10844 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
10845 | with some versions of binutils) where shared libraries could have | |
10846 | relocations against symbols in their debug information - the | |
10847 | minimal symbol would have the right address, but the debug info | |
10848 | would not. It's no longer necessary, because we will explicitly | |
10849 | apply relocations when we read in the debug information now. */ | |
10850 | ||
10851 | /* A DW_AT_location attribute with no contents indicates that a | |
10852 | variable has been optimized away. */ | |
10853 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
10854 | { | |
10855 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
10856 | return; | |
10857 | } | |
10858 | ||
10859 | /* Handle one degenerate form of location expression specially, to | |
10860 | preserve GDB's previous behavior when section offsets are | |
10861 | specified. If this is just a DW_OP_addr then mark this symbol | |
10862 | as LOC_STATIC. */ | |
10863 | ||
10864 | if (attr_form_is_block (attr) | |
10865 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
10866 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
10867 | { | |
891d2f0b | 10868 | unsigned int dummy; |
4c2df51b DJ |
10869 | |
10870 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 10871 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 10872 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
10873 | fixup_symbol_section (sym, objfile); |
10874 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
10875 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
10876 | return; |
10877 | } | |
10878 | ||
10879 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
10880 | expression evaluator, and use LOC_COMPUTED only when necessary | |
10881 | (i.e. when the value of a register or memory location is | |
10882 | referenced, or a thread-local block, etc.). Then again, it might | |
10883 | not be worthwhile. I'm assuming that it isn't unless performance | |
10884 | or memory numbers show me otherwise. */ | |
10885 | ||
e7c27a73 | 10886 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
10887 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
10888 | } | |
10889 | ||
c906108c SS |
10890 | /* Given a pointer to a DWARF information entry, figure out if we need |
10891 | to make a symbol table entry for it, and if so, create a new entry | |
10892 | and return a pointer to it. | |
10893 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
10894 | used the passed type. |
10895 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
10896 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
10897 | |
10898 | static struct symbol * | |
34eaf542 TT |
10899 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
10900 | struct symbol *space) | |
c906108c | 10901 | { |
e7c27a73 | 10902 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10903 | struct symbol *sym = NULL; |
10904 | char *name; | |
10905 | struct attribute *attr = NULL; | |
10906 | struct attribute *attr2 = NULL; | |
e142c38c | 10907 | CORE_ADDR baseaddr; |
e37fd15a SW |
10908 | struct pending **list_to_add = NULL; |
10909 | ||
edb3359d | 10910 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
10911 | |
10912 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10913 | |
94af9270 | 10914 | name = dwarf2_name (die, cu); |
c906108c SS |
10915 | if (name) |
10916 | { | |
94af9270 | 10917 | const char *linkagename; |
34eaf542 | 10918 | int suppress_add = 0; |
94af9270 | 10919 | |
34eaf542 TT |
10920 | if (space) |
10921 | sym = space; | |
10922 | else | |
10923 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 10924 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
10925 | |
10926 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 10927 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
10928 | linkagename = dwarf2_physname (name, die, cu); |
10929 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 10930 | |
f55ee35c JK |
10931 | /* Fortran does not have mangling standard and the mangling does differ |
10932 | between gfortran, iFort etc. */ | |
10933 | if (cu->language == language_fortran | |
b250c185 | 10934 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
10935 | symbol_set_demangled_name (&(sym->ginfo), |
10936 | (char *) dwarf2_full_name (name, die, cu), | |
10937 | NULL); | |
f55ee35c | 10938 | |
c906108c | 10939 | /* Default assumptions. |
c5aa993b | 10940 | Use the passed type or decode it from the die. */ |
176620f1 | 10941 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 10942 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
10943 | if (type != NULL) |
10944 | SYMBOL_TYPE (sym) = type; | |
10945 | else | |
e7c27a73 | 10946 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
10947 | attr = dwarf2_attr (die, |
10948 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
10949 | cu); | |
c906108c SS |
10950 | if (attr) |
10951 | { | |
10952 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
10953 | } | |
cb1df416 | 10954 | |
edb3359d DJ |
10955 | attr = dwarf2_attr (die, |
10956 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
10957 | cu); | |
cb1df416 DJ |
10958 | if (attr) |
10959 | { | |
10960 | int file_index = DW_UNSND (attr); | |
9a619af0 | 10961 | |
cb1df416 DJ |
10962 | if (cu->line_header == NULL |
10963 | || file_index > cu->line_header->num_file_names) | |
10964 | complaint (&symfile_complaints, | |
10965 | _("file index out of range")); | |
1c3d648d | 10966 | else if (file_index > 0) |
cb1df416 DJ |
10967 | { |
10968 | struct file_entry *fe; | |
9a619af0 | 10969 | |
cb1df416 DJ |
10970 | fe = &cu->line_header->file_names[file_index - 1]; |
10971 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
10972 | } | |
10973 | } | |
10974 | ||
c906108c SS |
10975 | switch (die->tag) |
10976 | { | |
10977 | case DW_TAG_label: | |
e142c38c | 10978 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
10979 | if (attr) |
10980 | { | |
10981 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
10982 | } | |
0f5238ed TT |
10983 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
10984 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 10985 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 10986 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
10987 | break; |
10988 | case DW_TAG_subprogram: | |
10989 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
10990 | finish_block. */ | |
10991 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 10992 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
10993 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
10994 | || cu->language == language_ada) | |
c906108c | 10995 | { |
2cfa0c8d JB |
10996 | /* Subprograms marked external are stored as a global symbol. |
10997 | Ada subprograms, whether marked external or not, are always | |
10998 | stored as a global symbol, because we want to be able to | |
10999 | access them globally. For instance, we want to be able | |
11000 | to break on a nested subprogram without having to | |
11001 | specify the context. */ | |
e37fd15a | 11002 | list_to_add = &global_symbols; |
c906108c SS |
11003 | } |
11004 | else | |
11005 | { | |
e37fd15a | 11006 | list_to_add = cu->list_in_scope; |
c906108c SS |
11007 | } |
11008 | break; | |
edb3359d DJ |
11009 | case DW_TAG_inlined_subroutine: |
11010 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
11011 | finish_block. */ | |
11012 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
11013 | SYMBOL_INLINED (sym) = 1; | |
11014 | /* Do not add the symbol to any lists. It will be found via | |
11015 | BLOCK_FUNCTION from the blockvector. */ | |
11016 | break; | |
34eaf542 TT |
11017 | case DW_TAG_template_value_param: |
11018 | suppress_add = 1; | |
11019 | /* Fall through. */ | |
72929c62 | 11020 | case DW_TAG_constant: |
c906108c | 11021 | case DW_TAG_variable: |
254e6b9e | 11022 | case DW_TAG_member: |
0963b4bd MS |
11023 | /* Compilation with minimal debug info may result in |
11024 | variables with missing type entries. Change the | |
11025 | misleading `void' type to something sensible. */ | |
c906108c | 11026 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
64c50499 | 11027 | SYMBOL_TYPE (sym) |
46bf5051 | 11028 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 11029 | |
e142c38c | 11030 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
11031 | /* In the case of DW_TAG_member, we should only be called for |
11032 | static const members. */ | |
11033 | if (die->tag == DW_TAG_member) | |
11034 | { | |
3863f96c DE |
11035 | /* dwarf2_add_field uses die_is_declaration, |
11036 | so we do the same. */ | |
254e6b9e DE |
11037 | gdb_assert (die_is_declaration (die, cu)); |
11038 | gdb_assert (attr); | |
11039 | } | |
c906108c SS |
11040 | if (attr) |
11041 | { | |
e7c27a73 | 11042 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 11043 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 11044 | if (!suppress_add) |
34eaf542 TT |
11045 | { |
11046 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 11047 | list_to_add = &global_symbols; |
34eaf542 | 11048 | else |
e37fd15a | 11049 | list_to_add = cu->list_in_scope; |
34eaf542 | 11050 | } |
c906108c SS |
11051 | break; |
11052 | } | |
e142c38c | 11053 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11054 | if (attr) |
11055 | { | |
e7c27a73 | 11056 | var_decode_location (attr, sym, cu); |
e142c38c | 11057 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
11058 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
11059 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
11060 | && !dwarf2_per_objfile->has_section_at_zero) | |
11061 | { | |
11062 | /* When a static variable is eliminated by the linker, | |
11063 | the corresponding debug information is not stripped | |
11064 | out, but the variable address is set to null; | |
11065 | do not add such variables into symbol table. */ | |
11066 | } | |
11067 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 11068 | { |
f55ee35c JK |
11069 | /* Workaround gfortran PR debug/40040 - it uses |
11070 | DW_AT_location for variables in -fPIC libraries which may | |
11071 | get overriden by other libraries/executable and get | |
11072 | a different address. Resolve it by the minimal symbol | |
11073 | which may come from inferior's executable using copy | |
11074 | relocation. Make this workaround only for gfortran as for | |
11075 | other compilers GDB cannot guess the minimal symbol | |
11076 | Fortran mangling kind. */ | |
11077 | if (cu->language == language_fortran && die->parent | |
11078 | && die->parent->tag == DW_TAG_module | |
11079 | && cu->producer | |
11080 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
11081 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
11082 | ||
1c809c68 TT |
11083 | /* A variable with DW_AT_external is never static, |
11084 | but it may be block-scoped. */ | |
11085 | list_to_add = (cu->list_in_scope == &file_symbols | |
11086 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 11087 | } |
c906108c | 11088 | else |
e37fd15a | 11089 | list_to_add = cu->list_in_scope; |
c906108c SS |
11090 | } |
11091 | else | |
11092 | { | |
11093 | /* We do not know the address of this symbol. | |
c5aa993b JM |
11094 | If it is an external symbol and we have type information |
11095 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
11096 | The address of the variable will then be determined from | |
11097 | the minimal symbol table whenever the variable is | |
11098 | referenced. */ | |
e142c38c | 11099 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 11100 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 11101 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 11102 | { |
0fe7935b DJ |
11103 | /* A variable with DW_AT_external is never static, but it |
11104 | may be block-scoped. */ | |
11105 | list_to_add = (cu->list_in_scope == &file_symbols | |
11106 | ? &global_symbols : cu->list_in_scope); | |
11107 | ||
c906108c | 11108 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 11109 | } |
442ddf59 JK |
11110 | else if (!die_is_declaration (die, cu)) |
11111 | { | |
11112 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
11113 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
11114 | if (!suppress_add) |
11115 | list_to_add = cu->list_in_scope; | |
442ddf59 | 11116 | } |
c906108c SS |
11117 | } |
11118 | break; | |
11119 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
11120 | /* If we are inside a function, mark this as an argument. If |
11121 | not, we might be looking at an argument to an inlined function | |
11122 | when we do not have enough information to show inlined frames; | |
11123 | pretend it's a local variable in that case so that the user can | |
11124 | still see it. */ | |
11125 | if (context_stack_depth > 0 | |
11126 | && context_stack[context_stack_depth - 1].name != NULL) | |
11127 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 11128 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
11129 | if (attr) |
11130 | { | |
e7c27a73 | 11131 | var_decode_location (attr, sym, cu); |
c906108c | 11132 | } |
e142c38c | 11133 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11134 | if (attr) |
11135 | { | |
e7c27a73 | 11136 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11137 | } |
f346a30d PM |
11138 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
11139 | if (attr && DW_UNSND (attr)) | |
11140 | { | |
11141 | struct type *ref_type; | |
11142 | ||
11143 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
11144 | SYMBOL_TYPE (sym) = ref_type; | |
11145 | } | |
11146 | ||
e37fd15a | 11147 | list_to_add = cu->list_in_scope; |
c906108c SS |
11148 | break; |
11149 | case DW_TAG_unspecified_parameters: | |
11150 | /* From varargs functions; gdb doesn't seem to have any | |
11151 | interest in this information, so just ignore it for now. | |
11152 | (FIXME?) */ | |
11153 | break; | |
34eaf542 TT |
11154 | case DW_TAG_template_type_param: |
11155 | suppress_add = 1; | |
11156 | /* Fall through. */ | |
c906108c | 11157 | case DW_TAG_class_type: |
680b30c7 | 11158 | case DW_TAG_interface_type: |
c906108c SS |
11159 | case DW_TAG_structure_type: |
11160 | case DW_TAG_union_type: | |
72019c9c | 11161 | case DW_TAG_set_type: |
c906108c SS |
11162 | case DW_TAG_enumeration_type: |
11163 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 11164 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 11165 | |
63d06c5c | 11166 | { |
987504bb | 11167 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
11168 | really ever be static objects: otherwise, if you try |
11169 | to, say, break of a class's method and you're in a file | |
11170 | which doesn't mention that class, it won't work unless | |
11171 | the check for all static symbols in lookup_symbol_aux | |
11172 | saves you. See the OtherFileClass tests in | |
11173 | gdb.c++/namespace.exp. */ | |
11174 | ||
e37fd15a | 11175 | if (!suppress_add) |
34eaf542 | 11176 | { |
34eaf542 TT |
11177 | list_to_add = (cu->list_in_scope == &file_symbols |
11178 | && (cu->language == language_cplus | |
11179 | || cu->language == language_java) | |
11180 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 11181 | |
64382290 TT |
11182 | /* The semantics of C++ state that "struct foo { |
11183 | ... }" also defines a typedef for "foo". A Java | |
11184 | class declaration also defines a typedef for the | |
11185 | class. */ | |
11186 | if (cu->language == language_cplus | |
11187 | || cu->language == language_java | |
11188 | || cu->language == language_ada) | |
11189 | { | |
11190 | /* The symbol's name is already allocated along | |
11191 | with this objfile, so we don't need to | |
11192 | duplicate it for the type. */ | |
11193 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
11194 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
11195 | } | |
63d06c5c DC |
11196 | } |
11197 | } | |
c906108c SS |
11198 | break; |
11199 | case DW_TAG_typedef: | |
63d06c5c DC |
11200 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
11201 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 11202 | list_to_add = cu->list_in_scope; |
63d06c5c | 11203 | break; |
c906108c | 11204 | case DW_TAG_base_type: |
a02abb62 | 11205 | case DW_TAG_subrange_type: |
c906108c | 11206 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 11207 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 11208 | list_to_add = cu->list_in_scope; |
c906108c SS |
11209 | break; |
11210 | case DW_TAG_enumerator: | |
e142c38c | 11211 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
11212 | if (attr) |
11213 | { | |
e7c27a73 | 11214 | dwarf2_const_value (attr, sym, cu); |
c906108c | 11215 | } |
63d06c5c DC |
11216 | { |
11217 | /* NOTE: carlton/2003-11-10: See comment above in the | |
11218 | DW_TAG_class_type, etc. block. */ | |
11219 | ||
e142c38c | 11220 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
11221 | && (cu->language == language_cplus |
11222 | || cu->language == language_java) | |
e142c38c | 11223 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 11224 | } |
c906108c | 11225 | break; |
5c4e30ca DC |
11226 | case DW_TAG_namespace: |
11227 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 11228 | list_to_add = &global_symbols; |
5c4e30ca | 11229 | break; |
c906108c SS |
11230 | default: |
11231 | /* Not a tag we recognize. Hopefully we aren't processing | |
11232 | trash data, but since we must specifically ignore things | |
11233 | we don't recognize, there is nothing else we should do at | |
0963b4bd | 11234 | this point. */ |
e2e0b3e5 | 11235 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 11236 | dwarf_tag_name (die->tag)); |
c906108c SS |
11237 | break; |
11238 | } | |
df8a16a1 | 11239 | |
e37fd15a SW |
11240 | if (suppress_add) |
11241 | { | |
11242 | sym->hash_next = objfile->template_symbols; | |
11243 | objfile->template_symbols = sym; | |
11244 | list_to_add = NULL; | |
11245 | } | |
11246 | ||
11247 | if (list_to_add != NULL) | |
11248 | add_symbol_to_list (sym, list_to_add); | |
11249 | ||
df8a16a1 DJ |
11250 | /* For the benefit of old versions of GCC, check for anonymous |
11251 | namespaces based on the demangled name. */ | |
11252 | if (!processing_has_namespace_info | |
94af9270 | 11253 | && cu->language == language_cplus) |
df8a16a1 | 11254 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
11255 | } |
11256 | return (sym); | |
11257 | } | |
11258 | ||
34eaf542 TT |
11259 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
11260 | ||
11261 | static struct symbol * | |
11262 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
11263 | { | |
11264 | return new_symbol_full (die, type, cu, NULL); | |
11265 | } | |
11266 | ||
98bfdba5 PA |
11267 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
11268 | zero-extend it as appropriate for the symbol's type. The DWARF | |
11269 | standard (v4) is not entirely clear about the meaning of using | |
11270 | DW_FORM_dataN for a constant with a signed type, where the type is | |
11271 | wider than the data. The conclusion of a discussion on the DWARF | |
11272 | list was that this is unspecified. We choose to always zero-extend | |
11273 | because that is the interpretation long in use by GCC. */ | |
c906108c | 11274 | |
98bfdba5 PA |
11275 | static gdb_byte * |
11276 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
11277 | const char *name, struct obstack *obstack, | |
11278 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 11279 | { |
e7c27a73 | 11280 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
11281 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
11282 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
11283 | LONGEST l = DW_UNSND (attr); |
11284 | ||
11285 | if (bits < sizeof (*value) * 8) | |
11286 | { | |
11287 | l &= ((LONGEST) 1 << bits) - 1; | |
11288 | *value = l; | |
11289 | } | |
11290 | else if (bits == sizeof (*value) * 8) | |
11291 | *value = l; | |
11292 | else | |
11293 | { | |
11294 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
11295 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
11296 | return bytes; | |
11297 | } | |
11298 | ||
11299 | return NULL; | |
11300 | } | |
11301 | ||
11302 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
11303 | the value does not fit in *VALUE, set *BYTES - either already | |
11304 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
11305 | or, set *BATON, if we translated the constant to a location | |
11306 | expression. */ | |
11307 | ||
11308 | static void | |
11309 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
11310 | const char *name, struct obstack *obstack, | |
11311 | struct dwarf2_cu *cu, | |
11312 | long *value, gdb_byte **bytes, | |
11313 | struct dwarf2_locexpr_baton **baton) | |
11314 | { | |
11315 | struct objfile *objfile = cu->objfile; | |
11316 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 11317 | struct dwarf_block *blk; |
98bfdba5 PA |
11318 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
11319 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
11320 | ||
11321 | *value = 0; | |
11322 | *bytes = NULL; | |
11323 | *baton = NULL; | |
c906108c SS |
11324 | |
11325 | switch (attr->form) | |
11326 | { | |
11327 | case DW_FORM_addr: | |
ac56253d | 11328 | { |
ac56253d TT |
11329 | gdb_byte *data; |
11330 | ||
98bfdba5 PA |
11331 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
11332 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 11333 | cu_header->addr_size, |
98bfdba5 | 11334 | TYPE_LENGTH (type)); |
ac56253d TT |
11335 | /* Symbols of this form are reasonably rare, so we just |
11336 | piggyback on the existing location code rather than writing | |
11337 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
11338 | *baton = obstack_alloc (&objfile->objfile_obstack, |
11339 | sizeof (struct dwarf2_locexpr_baton)); | |
11340 | (*baton)->per_cu = cu->per_cu; | |
11341 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 11342 | |
98bfdba5 PA |
11343 | (*baton)->size = 2 + cu_header->addr_size; |
11344 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
11345 | (*baton)->data = data; | |
ac56253d TT |
11346 | |
11347 | data[0] = DW_OP_addr; | |
11348 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
11349 | byte_order, DW_ADDR (attr)); | |
11350 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 11351 | } |
c906108c | 11352 | break; |
4ac36638 | 11353 | case DW_FORM_string: |
93b5768b | 11354 | case DW_FORM_strp: |
98bfdba5 PA |
11355 | /* DW_STRING is already allocated on the objfile obstack, point |
11356 | directly to it. */ | |
11357 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 11358 | break; |
c906108c SS |
11359 | case DW_FORM_block1: |
11360 | case DW_FORM_block2: | |
11361 | case DW_FORM_block4: | |
11362 | case DW_FORM_block: | |
2dc7f7b3 | 11363 | case DW_FORM_exprloc: |
c906108c | 11364 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
11365 | if (TYPE_LENGTH (type) != blk->size) |
11366 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
11367 | TYPE_LENGTH (type)); | |
11368 | *bytes = blk->data; | |
c906108c | 11369 | break; |
2df3850c JM |
11370 | |
11371 | /* The DW_AT_const_value attributes are supposed to carry the | |
11372 | symbol's value "represented as it would be on the target | |
11373 | architecture." By the time we get here, it's already been | |
11374 | converted to host endianness, so we just need to sign- or | |
11375 | zero-extend it as appropriate. */ | |
11376 | case DW_FORM_data1: | |
3e43a32a MS |
11377 | *bytes = dwarf2_const_value_data (attr, type, name, |
11378 | obstack, cu, value, 8); | |
2df3850c | 11379 | break; |
c906108c | 11380 | case DW_FORM_data2: |
3e43a32a MS |
11381 | *bytes = dwarf2_const_value_data (attr, type, name, |
11382 | obstack, cu, value, 16); | |
2df3850c | 11383 | break; |
c906108c | 11384 | case DW_FORM_data4: |
3e43a32a MS |
11385 | *bytes = dwarf2_const_value_data (attr, type, name, |
11386 | obstack, cu, value, 32); | |
2df3850c | 11387 | break; |
c906108c | 11388 | case DW_FORM_data8: |
3e43a32a MS |
11389 | *bytes = dwarf2_const_value_data (attr, type, name, |
11390 | obstack, cu, value, 64); | |
2df3850c JM |
11391 | break; |
11392 | ||
c906108c | 11393 | case DW_FORM_sdata: |
98bfdba5 | 11394 | *value = DW_SND (attr); |
2df3850c JM |
11395 | break; |
11396 | ||
c906108c | 11397 | case DW_FORM_udata: |
98bfdba5 | 11398 | *value = DW_UNSND (attr); |
c906108c | 11399 | break; |
2df3850c | 11400 | |
c906108c | 11401 | default: |
4d3c2250 | 11402 | complaint (&symfile_complaints, |
e2e0b3e5 | 11403 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 11404 | dwarf_form_name (attr->form)); |
98bfdba5 | 11405 | *value = 0; |
c906108c SS |
11406 | break; |
11407 | } | |
11408 | } | |
11409 | ||
2df3850c | 11410 | |
98bfdba5 PA |
11411 | /* Copy constant value from an attribute to a symbol. */ |
11412 | ||
2df3850c | 11413 | static void |
98bfdba5 PA |
11414 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
11415 | struct dwarf2_cu *cu) | |
2df3850c | 11416 | { |
98bfdba5 PA |
11417 | struct objfile *objfile = cu->objfile; |
11418 | struct comp_unit_head *cu_header = &cu->header; | |
11419 | long value; | |
11420 | gdb_byte *bytes; | |
11421 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 11422 | |
98bfdba5 PA |
11423 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
11424 | SYMBOL_PRINT_NAME (sym), | |
11425 | &objfile->objfile_obstack, cu, | |
11426 | &value, &bytes, &baton); | |
2df3850c | 11427 | |
98bfdba5 PA |
11428 | if (baton != NULL) |
11429 | { | |
11430 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
11431 | SYMBOL_LOCATION_BATON (sym) = baton; | |
11432 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
11433 | } | |
11434 | else if (bytes != NULL) | |
11435 | { | |
11436 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
11437 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
11438 | } | |
11439 | else | |
11440 | { | |
11441 | SYMBOL_VALUE (sym) = value; | |
11442 | SYMBOL_CLASS (sym) = LOC_CONST; | |
11443 | } | |
2df3850c JM |
11444 | } |
11445 | ||
c906108c SS |
11446 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
11447 | ||
11448 | static struct type * | |
e7c27a73 | 11449 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11450 | { |
c906108c | 11451 | struct attribute *type_attr; |
c906108c | 11452 | |
e142c38c | 11453 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
11454 | if (!type_attr) |
11455 | { | |
11456 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 11457 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 11458 | } |
348e048f | 11459 | |
673bfd45 | 11460 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11461 | } |
11462 | ||
b4ba55a1 JB |
11463 | /* True iff CU's producer generates GNAT Ada auxiliary information |
11464 | that allows to find parallel types through that information instead | |
11465 | of having to do expensive parallel lookups by type name. */ | |
11466 | ||
11467 | static int | |
11468 | need_gnat_info (struct dwarf2_cu *cu) | |
11469 | { | |
11470 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
11471 | of GNAT produces this auxiliary information, without any indication | |
11472 | that it is produced. Part of enhancing the FSF version of GNAT | |
11473 | to produce that information will be to put in place an indicator | |
11474 | that we can use in order to determine whether the descriptive type | |
11475 | info is available or not. One suggestion that has been made is | |
11476 | to use a new attribute, attached to the CU die. For now, assume | |
11477 | that the descriptive type info is not available. */ | |
11478 | return 0; | |
11479 | } | |
11480 | ||
b4ba55a1 JB |
11481 | /* Return the auxiliary type of the die in question using its |
11482 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
11483 | attribute is not present. */ | |
11484 | ||
11485 | static struct type * | |
11486 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
11487 | { | |
b4ba55a1 | 11488 | struct attribute *type_attr; |
b4ba55a1 JB |
11489 | |
11490 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
11491 | if (!type_attr) | |
11492 | return NULL; | |
11493 | ||
673bfd45 | 11494 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
11495 | } |
11496 | ||
11497 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
11498 | descriptive type accordingly. */ | |
11499 | ||
11500 | static void | |
11501 | set_descriptive_type (struct type *type, struct die_info *die, | |
11502 | struct dwarf2_cu *cu) | |
11503 | { | |
11504 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
11505 | ||
11506 | if (descriptive_type) | |
11507 | { | |
11508 | ALLOCATE_GNAT_AUX_TYPE (type); | |
11509 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
11510 | } | |
11511 | } | |
11512 | ||
c906108c SS |
11513 | /* Return the containing type of the die in question using its |
11514 | DW_AT_containing_type attribute. */ | |
11515 | ||
11516 | static struct type * | |
e7c27a73 | 11517 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11518 | { |
c906108c | 11519 | struct attribute *type_attr; |
c906108c | 11520 | |
e142c38c | 11521 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
11522 | if (!type_attr) |
11523 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
11524 | "[in module %s]"), cu->objfile->name); | |
11525 | ||
673bfd45 | 11526 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11527 | } |
11528 | ||
673bfd45 DE |
11529 | /* Look up the type of DIE in CU using its type attribute ATTR. |
11530 | If there is no type substitute an error marker. */ | |
11531 | ||
c906108c | 11532 | static struct type * |
673bfd45 DE |
11533 | lookup_die_type (struct die_info *die, struct attribute *attr, |
11534 | struct dwarf2_cu *cu) | |
c906108c | 11535 | { |
f792889a DJ |
11536 | struct type *this_type; |
11537 | ||
673bfd45 DE |
11538 | /* First see if we have it cached. */ |
11539 | ||
11540 | if (is_ref_attr (attr)) | |
11541 | { | |
11542 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11543 | ||
11544 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
11545 | } | |
55f1336d | 11546 | else if (attr->form == DW_FORM_ref_sig8) |
673bfd45 DE |
11547 | { |
11548 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11549 | struct dwarf2_cu *sig_cu; | |
11550 | unsigned int offset; | |
11551 | ||
11552 | /* sig_type will be NULL if the signatured type is missing from | |
11553 | the debug info. */ | |
11554 | if (sig_type == NULL) | |
11555 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
11556 | "at 0x%x [in module %s]"), | |
11557 | die->offset, cu->objfile->name); | |
11558 | ||
11559 | gdb_assert (sig_type->per_cu.from_debug_types); | |
11560 | offset = sig_type->offset + sig_type->type_offset; | |
11561 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); | |
11562 | } | |
11563 | else | |
11564 | { | |
11565 | dump_die_for_error (die); | |
11566 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
11567 | dwarf_attr_name (attr->name), cu->objfile->name); | |
11568 | } | |
11569 | ||
11570 | /* If not cached we need to read it in. */ | |
11571 | ||
11572 | if (this_type == NULL) | |
11573 | { | |
11574 | struct die_info *type_die; | |
11575 | struct dwarf2_cu *type_cu = cu; | |
11576 | ||
11577 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
11578 | /* If the type is cached, we should have found it above. */ | |
11579 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
11580 | this_type = read_type_die_1 (type_die, type_cu); | |
11581 | } | |
11582 | ||
11583 | /* If we still don't have a type use an error marker. */ | |
11584 | ||
11585 | if (this_type == NULL) | |
c906108c | 11586 | { |
b00fdb78 TT |
11587 | char *message, *saved; |
11588 | ||
11589 | /* read_type_die already issued a complaint. */ | |
11590 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
11591 | cu->objfile->name, | |
11592 | cu->header.offset, | |
11593 | die->offset); | |
11594 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
11595 | message, strlen (message)); | |
11596 | xfree (message); | |
11597 | ||
11598 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 11599 | } |
673bfd45 | 11600 | |
f792889a | 11601 | return this_type; |
c906108c SS |
11602 | } |
11603 | ||
673bfd45 DE |
11604 | /* Return the type in DIE, CU. |
11605 | Returns NULL for invalid types. | |
11606 | ||
11607 | This first does a lookup in the appropriate type_hash table, | |
11608 | and only reads the die in if necessary. | |
11609 | ||
11610 | NOTE: This can be called when reading in partial or full symbols. */ | |
11611 | ||
f792889a | 11612 | static struct type * |
e7c27a73 | 11613 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11614 | { |
f792889a DJ |
11615 | struct type *this_type; |
11616 | ||
11617 | this_type = get_die_type (die, cu); | |
11618 | if (this_type) | |
11619 | return this_type; | |
11620 | ||
673bfd45 DE |
11621 | return read_type_die_1 (die, cu); |
11622 | } | |
11623 | ||
11624 | /* Read the type in DIE, CU. | |
11625 | Returns NULL for invalid types. */ | |
11626 | ||
11627 | static struct type * | |
11628 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
11629 | { | |
11630 | struct type *this_type = NULL; | |
11631 | ||
c906108c SS |
11632 | switch (die->tag) |
11633 | { | |
11634 | case DW_TAG_class_type: | |
680b30c7 | 11635 | case DW_TAG_interface_type: |
c906108c SS |
11636 | case DW_TAG_structure_type: |
11637 | case DW_TAG_union_type: | |
f792889a | 11638 | this_type = read_structure_type (die, cu); |
c906108c SS |
11639 | break; |
11640 | case DW_TAG_enumeration_type: | |
f792889a | 11641 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
11642 | break; |
11643 | case DW_TAG_subprogram: | |
11644 | case DW_TAG_subroutine_type: | |
edb3359d | 11645 | case DW_TAG_inlined_subroutine: |
f792889a | 11646 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
11647 | break; |
11648 | case DW_TAG_array_type: | |
f792889a | 11649 | this_type = read_array_type (die, cu); |
c906108c | 11650 | break; |
72019c9c | 11651 | case DW_TAG_set_type: |
f792889a | 11652 | this_type = read_set_type (die, cu); |
72019c9c | 11653 | break; |
c906108c | 11654 | case DW_TAG_pointer_type: |
f792889a | 11655 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
11656 | break; |
11657 | case DW_TAG_ptr_to_member_type: | |
f792889a | 11658 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
11659 | break; |
11660 | case DW_TAG_reference_type: | |
f792889a | 11661 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
11662 | break; |
11663 | case DW_TAG_const_type: | |
f792889a | 11664 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
11665 | break; |
11666 | case DW_TAG_volatile_type: | |
f792889a | 11667 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
11668 | break; |
11669 | case DW_TAG_string_type: | |
f792889a | 11670 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
11671 | break; |
11672 | case DW_TAG_typedef: | |
f792889a | 11673 | this_type = read_typedef (die, cu); |
c906108c | 11674 | break; |
a02abb62 | 11675 | case DW_TAG_subrange_type: |
f792889a | 11676 | this_type = read_subrange_type (die, cu); |
a02abb62 | 11677 | break; |
c906108c | 11678 | case DW_TAG_base_type: |
f792889a | 11679 | this_type = read_base_type (die, cu); |
c906108c | 11680 | break; |
81a17f79 | 11681 | case DW_TAG_unspecified_type: |
f792889a | 11682 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 11683 | break; |
0114d602 DJ |
11684 | case DW_TAG_namespace: |
11685 | this_type = read_namespace_type (die, cu); | |
11686 | break; | |
f55ee35c JK |
11687 | case DW_TAG_module: |
11688 | this_type = read_module_type (die, cu); | |
11689 | break; | |
c906108c | 11690 | default: |
3e43a32a MS |
11691 | complaint (&symfile_complaints, |
11692 | _("unexpected tag in read_type_die: '%s'"), | |
4d3c2250 | 11693 | dwarf_tag_name (die->tag)); |
c906108c SS |
11694 | break; |
11695 | } | |
63d06c5c | 11696 | |
f792889a | 11697 | return this_type; |
63d06c5c DC |
11698 | } |
11699 | ||
abc72ce4 DE |
11700 | /* See if we can figure out if the class lives in a namespace. We do |
11701 | this by looking for a member function; its demangled name will | |
11702 | contain namespace info, if there is any. | |
11703 | Return the computed name or NULL. | |
11704 | Space for the result is allocated on the objfile's obstack. | |
11705 | This is the full-die version of guess_partial_die_structure_name. | |
11706 | In this case we know DIE has no useful parent. */ | |
11707 | ||
11708 | static char * | |
11709 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) | |
11710 | { | |
11711 | struct die_info *spec_die; | |
11712 | struct dwarf2_cu *spec_cu; | |
11713 | struct die_info *child; | |
11714 | ||
11715 | spec_cu = cu; | |
11716 | spec_die = die_specification (die, &spec_cu); | |
11717 | if (spec_die != NULL) | |
11718 | { | |
11719 | die = spec_die; | |
11720 | cu = spec_cu; | |
11721 | } | |
11722 | ||
11723 | for (child = die->child; | |
11724 | child != NULL; | |
11725 | child = child->sibling) | |
11726 | { | |
11727 | if (child->tag == DW_TAG_subprogram) | |
11728 | { | |
11729 | struct attribute *attr; | |
11730 | ||
11731 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); | |
11732 | if (attr == NULL) | |
11733 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); | |
11734 | if (attr != NULL) | |
11735 | { | |
11736 | char *actual_name | |
11737 | = language_class_name_from_physname (cu->language_defn, | |
11738 | DW_STRING (attr)); | |
11739 | char *name = NULL; | |
11740 | ||
11741 | if (actual_name != NULL) | |
11742 | { | |
11743 | char *die_name = dwarf2_name (die, cu); | |
11744 | ||
11745 | if (die_name != NULL | |
11746 | && strcmp (die_name, actual_name) != 0) | |
11747 | { | |
11748 | /* Strip off the class name from the full name. | |
11749 | We want the prefix. */ | |
11750 | int die_name_len = strlen (die_name); | |
11751 | int actual_name_len = strlen (actual_name); | |
11752 | ||
11753 | /* Test for '::' as a sanity check. */ | |
11754 | if (actual_name_len > die_name_len + 2 | |
3e43a32a MS |
11755 | && actual_name[actual_name_len |
11756 | - die_name_len - 1] == ':') | |
abc72ce4 DE |
11757 | name = |
11758 | obsavestring (actual_name, | |
11759 | actual_name_len - die_name_len - 2, | |
11760 | &cu->objfile->objfile_obstack); | |
11761 | } | |
11762 | } | |
11763 | xfree (actual_name); | |
11764 | return name; | |
11765 | } | |
11766 | } | |
11767 | } | |
11768 | ||
11769 | return NULL; | |
11770 | } | |
11771 | ||
fdde2d81 | 11772 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 11773 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 11774 | |
0114d602 DJ |
11775 | For example, if we're within the method foo() in the following |
11776 | code: | |
11777 | ||
11778 | namespace N { | |
11779 | class C { | |
11780 | void foo () { | |
11781 | } | |
11782 | }; | |
11783 | } | |
11784 | ||
11785 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
11786 | |
11787 | static char * | |
e142c38c | 11788 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 11789 | { |
0114d602 DJ |
11790 | struct die_info *parent, *spec_die; |
11791 | struct dwarf2_cu *spec_cu; | |
11792 | struct type *parent_type; | |
63d06c5c | 11793 | |
f55ee35c JK |
11794 | if (cu->language != language_cplus && cu->language != language_java |
11795 | && cu->language != language_fortran) | |
0114d602 DJ |
11796 | return ""; |
11797 | ||
11798 | /* We have to be careful in the presence of DW_AT_specification. | |
11799 | For example, with GCC 3.4, given the code | |
11800 | ||
11801 | namespace N { | |
11802 | void foo() { | |
11803 | // Definition of N::foo. | |
11804 | } | |
11805 | } | |
11806 | ||
11807 | then we'll have a tree of DIEs like this: | |
11808 | ||
11809 | 1: DW_TAG_compile_unit | |
11810 | 2: DW_TAG_namespace // N | |
11811 | 3: DW_TAG_subprogram // declaration of N::foo | |
11812 | 4: DW_TAG_subprogram // definition of N::foo | |
11813 | DW_AT_specification // refers to die #3 | |
11814 | ||
11815 | Thus, when processing die #4, we have to pretend that we're in | |
11816 | the context of its DW_AT_specification, namely the contex of die | |
11817 | #3. */ | |
11818 | spec_cu = cu; | |
11819 | spec_die = die_specification (die, &spec_cu); | |
11820 | if (spec_die == NULL) | |
11821 | parent = die->parent; | |
11822 | else | |
63d06c5c | 11823 | { |
0114d602 DJ |
11824 | parent = spec_die->parent; |
11825 | cu = spec_cu; | |
63d06c5c | 11826 | } |
0114d602 DJ |
11827 | |
11828 | if (parent == NULL) | |
11829 | return ""; | |
98bfdba5 PA |
11830 | else if (parent->building_fullname) |
11831 | { | |
11832 | const char *name; | |
11833 | const char *parent_name; | |
11834 | ||
11835 | /* It has been seen on RealView 2.2 built binaries, | |
11836 | DW_TAG_template_type_param types actually _defined_ as | |
11837 | children of the parent class: | |
11838 | ||
11839 | enum E {}; | |
11840 | template class <class Enum> Class{}; | |
11841 | Class<enum E> class_e; | |
11842 | ||
11843 | 1: DW_TAG_class_type (Class) | |
11844 | 2: DW_TAG_enumeration_type (E) | |
11845 | 3: DW_TAG_enumerator (enum1:0) | |
11846 | 3: DW_TAG_enumerator (enum2:1) | |
11847 | ... | |
11848 | 2: DW_TAG_template_type_param | |
11849 | DW_AT_type DW_FORM_ref_udata (E) | |
11850 | ||
11851 | Besides being broken debug info, it can put GDB into an | |
11852 | infinite loop. Consider: | |
11853 | ||
11854 | When we're building the full name for Class<E>, we'll start | |
11855 | at Class, and go look over its template type parameters, | |
11856 | finding E. We'll then try to build the full name of E, and | |
11857 | reach here. We're now trying to build the full name of E, | |
11858 | and look over the parent DIE for containing scope. In the | |
11859 | broken case, if we followed the parent DIE of E, we'd again | |
11860 | find Class, and once again go look at its template type | |
11861 | arguments, etc., etc. Simply don't consider such parent die | |
11862 | as source-level parent of this die (it can't be, the language | |
11863 | doesn't allow it), and break the loop here. */ | |
11864 | name = dwarf2_name (die, cu); | |
11865 | parent_name = dwarf2_name (parent, cu); | |
11866 | complaint (&symfile_complaints, | |
11867 | _("template param type '%s' defined within parent '%s'"), | |
11868 | name ? name : "<unknown>", | |
11869 | parent_name ? parent_name : "<unknown>"); | |
11870 | return ""; | |
11871 | } | |
63d06c5c | 11872 | else |
0114d602 DJ |
11873 | switch (parent->tag) |
11874 | { | |
63d06c5c | 11875 | case DW_TAG_namespace: |
0114d602 | 11876 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
11877 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
11878 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
11879 | Work around this problem here. */ | |
11880 | if (cu->language == language_cplus | |
11881 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
11882 | return ""; | |
0114d602 DJ |
11883 | /* We give a name to even anonymous namespaces. */ |
11884 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 11885 | case DW_TAG_class_type: |
680b30c7 | 11886 | case DW_TAG_interface_type: |
63d06c5c | 11887 | case DW_TAG_structure_type: |
0114d602 | 11888 | case DW_TAG_union_type: |
f55ee35c | 11889 | case DW_TAG_module: |
0114d602 DJ |
11890 | parent_type = read_type_die (parent, cu); |
11891 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
11892 | return TYPE_TAG_NAME (parent_type); | |
11893 | else | |
11894 | /* An anonymous structure is only allowed non-static data | |
11895 | members; no typedefs, no member functions, et cetera. | |
11896 | So it does not need a prefix. */ | |
11897 | return ""; | |
abc72ce4 DE |
11898 | case DW_TAG_compile_unit: |
11899 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ | |
11900 | if (cu->language == language_cplus | |
11901 | && dwarf2_per_objfile->types.asection != NULL | |
11902 | && die->child != NULL | |
11903 | && (die->tag == DW_TAG_class_type | |
11904 | || die->tag == DW_TAG_structure_type | |
11905 | || die->tag == DW_TAG_union_type)) | |
11906 | { | |
11907 | char *name = guess_full_die_structure_name (die, cu); | |
11908 | if (name != NULL) | |
11909 | return name; | |
11910 | } | |
11911 | return ""; | |
63d06c5c | 11912 | default: |
8176b9b8 | 11913 | return determine_prefix (parent, cu); |
63d06c5c | 11914 | } |
63d06c5c DC |
11915 | } |
11916 | ||
3e43a32a MS |
11917 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
11918 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
11919 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform | |
11920 | an obconcat, otherwise allocate storage for the result. The CU argument is | |
11921 | used to determine the language and hence, the appropriate separator. */ | |
987504bb | 11922 | |
f55ee35c | 11923 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
11924 | |
11925 | static char * | |
f55ee35c JK |
11926 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
11927 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 11928 | { |
f55ee35c | 11929 | const char *lead = ""; |
5c315b68 | 11930 | const char *sep; |
63d06c5c | 11931 | |
3e43a32a MS |
11932 | if (suffix == NULL || suffix[0] == '\0' |
11933 | || prefix == NULL || prefix[0] == '\0') | |
987504bb JJ |
11934 | sep = ""; |
11935 | else if (cu->language == language_java) | |
11936 | sep = "."; | |
f55ee35c JK |
11937 | else if (cu->language == language_fortran && physname) |
11938 | { | |
11939 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
11940 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
11941 | ||
11942 | lead = "__"; | |
11943 | sep = "_MOD_"; | |
11944 | } | |
987504bb JJ |
11945 | else |
11946 | sep = "::"; | |
63d06c5c | 11947 | |
6dd47d34 DE |
11948 | if (prefix == NULL) |
11949 | prefix = ""; | |
11950 | if (suffix == NULL) | |
11951 | suffix = ""; | |
11952 | ||
987504bb JJ |
11953 | if (obs == NULL) |
11954 | { | |
3e43a32a MS |
11955 | char *retval |
11956 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 11957 | |
f55ee35c JK |
11958 | strcpy (retval, lead); |
11959 | strcat (retval, prefix); | |
6dd47d34 DE |
11960 | strcat (retval, sep); |
11961 | strcat (retval, suffix); | |
63d06c5c DC |
11962 | return retval; |
11963 | } | |
987504bb JJ |
11964 | else |
11965 | { | |
11966 | /* We have an obstack. */ | |
f55ee35c | 11967 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 11968 | } |
63d06c5c DC |
11969 | } |
11970 | ||
c906108c SS |
11971 | /* Return sibling of die, NULL if no sibling. */ |
11972 | ||
f9aca02d | 11973 | static struct die_info * |
fba45db2 | 11974 | sibling_die (struct die_info *die) |
c906108c | 11975 | { |
639d11d3 | 11976 | return die->sibling; |
c906108c SS |
11977 | } |
11978 | ||
71c25dea TT |
11979 | /* Get name of a die, return NULL if not found. */ |
11980 | ||
11981 | static char * | |
11982 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
11983 | struct obstack *obstack) | |
11984 | { | |
11985 | if (name && cu->language == language_cplus) | |
11986 | { | |
11987 | char *canon_name = cp_canonicalize_string (name); | |
11988 | ||
11989 | if (canon_name != NULL) | |
11990 | { | |
11991 | if (strcmp (canon_name, name) != 0) | |
11992 | name = obsavestring (canon_name, strlen (canon_name), | |
11993 | obstack); | |
11994 | xfree (canon_name); | |
11995 | } | |
11996 | } | |
11997 | ||
11998 | return name; | |
c906108c SS |
11999 | } |
12000 | ||
9219021c DC |
12001 | /* Get name of a die, return NULL if not found. */ |
12002 | ||
12003 | static char * | |
e142c38c | 12004 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
12005 | { |
12006 | struct attribute *attr; | |
12007 | ||
e142c38c | 12008 | attr = dwarf2_attr (die, DW_AT_name, cu); |
53832f31 TT |
12009 | if ((!attr || !DW_STRING (attr)) |
12010 | && die->tag != DW_TAG_class_type | |
12011 | && die->tag != DW_TAG_interface_type | |
12012 | && die->tag != DW_TAG_structure_type | |
12013 | && die->tag != DW_TAG_union_type) | |
71c25dea TT |
12014 | return NULL; |
12015 | ||
12016 | switch (die->tag) | |
12017 | { | |
12018 | case DW_TAG_compile_unit: | |
12019 | /* Compilation units have a DW_AT_name that is a filename, not | |
12020 | a source language identifier. */ | |
12021 | case DW_TAG_enumeration_type: | |
12022 | case DW_TAG_enumerator: | |
12023 | /* These tags always have simple identifiers already; no need | |
12024 | to canonicalize them. */ | |
12025 | return DW_STRING (attr); | |
907af001 | 12026 | |
418835cc KS |
12027 | case DW_TAG_subprogram: |
12028 | /* Java constructors will all be named "<init>", so return | |
12029 | the class name when we see this special case. */ | |
12030 | if (cu->language == language_java | |
12031 | && DW_STRING (attr) != NULL | |
12032 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
12033 | { | |
12034 | struct dwarf2_cu *spec_cu = cu; | |
12035 | struct die_info *spec_die; | |
12036 | ||
12037 | /* GCJ will output '<init>' for Java constructor names. | |
12038 | For this special case, return the name of the parent class. */ | |
12039 | ||
12040 | /* GCJ may output suprogram DIEs with AT_specification set. | |
12041 | If so, use the name of the specified DIE. */ | |
12042 | spec_die = die_specification (die, &spec_cu); | |
12043 | if (spec_die != NULL) | |
12044 | return dwarf2_name (spec_die, spec_cu); | |
12045 | ||
12046 | do | |
12047 | { | |
12048 | die = die->parent; | |
12049 | if (die->tag == DW_TAG_class_type) | |
12050 | return dwarf2_name (die, cu); | |
12051 | } | |
12052 | while (die->tag != DW_TAG_compile_unit); | |
12053 | } | |
907af001 UW |
12054 | break; |
12055 | ||
12056 | case DW_TAG_class_type: | |
12057 | case DW_TAG_interface_type: | |
12058 | case DW_TAG_structure_type: | |
12059 | case DW_TAG_union_type: | |
12060 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
12061 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
12062 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
12063 | and GCC 4.4. We work around this problem by ignoring these. */ | |
53832f31 TT |
12064 | if (attr && DW_STRING (attr) |
12065 | && (strncmp (DW_STRING (attr), "._", 2) == 0 | |
12066 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) | |
907af001 | 12067 | return NULL; |
53832f31 TT |
12068 | |
12069 | /* GCC might emit a nameless typedef that has a linkage name. See | |
12070 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ | |
12071 | if (!attr || DW_STRING (attr) == NULL) | |
12072 | { | |
df5c6c50 | 12073 | char *demangled = NULL; |
53832f31 TT |
12074 | |
12075 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
12076 | if (attr == NULL) | |
12077 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
12078 | ||
12079 | if (attr == NULL || DW_STRING (attr) == NULL) | |
12080 | return NULL; | |
12081 | ||
df5c6c50 JK |
12082 | /* Avoid demangling DW_STRING (attr) the second time on a second |
12083 | call for the same DIE. */ | |
12084 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12085 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); | |
53832f31 TT |
12086 | |
12087 | if (demangled) | |
12088 | { | |
12089 | /* FIXME: we already did this for the partial symbol... */ | |
12090 | DW_STRING (attr) | |
12091 | = obsavestring (demangled, strlen (demangled), | |
12092 | &cu->objfile->objfile_obstack); | |
12093 | DW_STRING_IS_CANONICAL (attr) = 1; | |
12094 | xfree (demangled); | |
12095 | } | |
12096 | } | |
907af001 UW |
12097 | break; |
12098 | ||
71c25dea | 12099 | default: |
907af001 UW |
12100 | break; |
12101 | } | |
12102 | ||
12103 | if (!DW_STRING_IS_CANONICAL (attr)) | |
12104 | { | |
12105 | DW_STRING (attr) | |
12106 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
12107 | &cu->objfile->objfile_obstack); | |
12108 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 12109 | } |
907af001 | 12110 | return DW_STRING (attr); |
9219021c DC |
12111 | } |
12112 | ||
12113 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
12114 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
12115 | containing the return value on output. */ | |
9219021c DC |
12116 | |
12117 | static struct die_info * | |
f2f0e013 | 12118 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
12119 | { |
12120 | struct attribute *attr; | |
9219021c | 12121 | |
f2f0e013 | 12122 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
12123 | if (attr == NULL) |
12124 | return NULL; | |
12125 | ||
f2f0e013 | 12126 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
12127 | } |
12128 | ||
c906108c SS |
12129 | /* Convert a DIE tag into its string name. */ |
12130 | ||
12131 | static char * | |
aa1ee363 | 12132 | dwarf_tag_name (unsigned tag) |
c906108c SS |
12133 | { |
12134 | switch (tag) | |
12135 | { | |
12136 | case DW_TAG_padding: | |
12137 | return "DW_TAG_padding"; | |
12138 | case DW_TAG_array_type: | |
12139 | return "DW_TAG_array_type"; | |
12140 | case DW_TAG_class_type: | |
12141 | return "DW_TAG_class_type"; | |
12142 | case DW_TAG_entry_point: | |
12143 | return "DW_TAG_entry_point"; | |
12144 | case DW_TAG_enumeration_type: | |
12145 | return "DW_TAG_enumeration_type"; | |
12146 | case DW_TAG_formal_parameter: | |
12147 | return "DW_TAG_formal_parameter"; | |
12148 | case DW_TAG_imported_declaration: | |
12149 | return "DW_TAG_imported_declaration"; | |
12150 | case DW_TAG_label: | |
12151 | return "DW_TAG_label"; | |
12152 | case DW_TAG_lexical_block: | |
12153 | return "DW_TAG_lexical_block"; | |
12154 | case DW_TAG_member: | |
12155 | return "DW_TAG_member"; | |
12156 | case DW_TAG_pointer_type: | |
12157 | return "DW_TAG_pointer_type"; | |
12158 | case DW_TAG_reference_type: | |
12159 | return "DW_TAG_reference_type"; | |
12160 | case DW_TAG_compile_unit: | |
12161 | return "DW_TAG_compile_unit"; | |
12162 | case DW_TAG_string_type: | |
12163 | return "DW_TAG_string_type"; | |
12164 | case DW_TAG_structure_type: | |
12165 | return "DW_TAG_structure_type"; | |
12166 | case DW_TAG_subroutine_type: | |
12167 | return "DW_TAG_subroutine_type"; | |
12168 | case DW_TAG_typedef: | |
12169 | return "DW_TAG_typedef"; | |
12170 | case DW_TAG_union_type: | |
12171 | return "DW_TAG_union_type"; | |
12172 | case DW_TAG_unspecified_parameters: | |
12173 | return "DW_TAG_unspecified_parameters"; | |
12174 | case DW_TAG_variant: | |
12175 | return "DW_TAG_variant"; | |
12176 | case DW_TAG_common_block: | |
12177 | return "DW_TAG_common_block"; | |
12178 | case DW_TAG_common_inclusion: | |
12179 | return "DW_TAG_common_inclusion"; | |
12180 | case DW_TAG_inheritance: | |
12181 | return "DW_TAG_inheritance"; | |
12182 | case DW_TAG_inlined_subroutine: | |
12183 | return "DW_TAG_inlined_subroutine"; | |
12184 | case DW_TAG_module: | |
12185 | return "DW_TAG_module"; | |
12186 | case DW_TAG_ptr_to_member_type: | |
12187 | return "DW_TAG_ptr_to_member_type"; | |
12188 | case DW_TAG_set_type: | |
12189 | return "DW_TAG_set_type"; | |
12190 | case DW_TAG_subrange_type: | |
12191 | return "DW_TAG_subrange_type"; | |
12192 | case DW_TAG_with_stmt: | |
12193 | return "DW_TAG_with_stmt"; | |
12194 | case DW_TAG_access_declaration: | |
12195 | return "DW_TAG_access_declaration"; | |
12196 | case DW_TAG_base_type: | |
12197 | return "DW_TAG_base_type"; | |
12198 | case DW_TAG_catch_block: | |
12199 | return "DW_TAG_catch_block"; | |
12200 | case DW_TAG_const_type: | |
12201 | return "DW_TAG_const_type"; | |
12202 | case DW_TAG_constant: | |
12203 | return "DW_TAG_constant"; | |
12204 | case DW_TAG_enumerator: | |
12205 | return "DW_TAG_enumerator"; | |
12206 | case DW_TAG_file_type: | |
12207 | return "DW_TAG_file_type"; | |
12208 | case DW_TAG_friend: | |
12209 | return "DW_TAG_friend"; | |
12210 | case DW_TAG_namelist: | |
12211 | return "DW_TAG_namelist"; | |
12212 | case DW_TAG_namelist_item: | |
12213 | return "DW_TAG_namelist_item"; | |
12214 | case DW_TAG_packed_type: | |
12215 | return "DW_TAG_packed_type"; | |
12216 | case DW_TAG_subprogram: | |
12217 | return "DW_TAG_subprogram"; | |
12218 | case DW_TAG_template_type_param: | |
12219 | return "DW_TAG_template_type_param"; | |
12220 | case DW_TAG_template_value_param: | |
12221 | return "DW_TAG_template_value_param"; | |
12222 | case DW_TAG_thrown_type: | |
12223 | return "DW_TAG_thrown_type"; | |
12224 | case DW_TAG_try_block: | |
12225 | return "DW_TAG_try_block"; | |
12226 | case DW_TAG_variant_part: | |
12227 | return "DW_TAG_variant_part"; | |
12228 | case DW_TAG_variable: | |
12229 | return "DW_TAG_variable"; | |
12230 | case DW_TAG_volatile_type: | |
12231 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
12232 | case DW_TAG_dwarf_procedure: |
12233 | return "DW_TAG_dwarf_procedure"; | |
12234 | case DW_TAG_restrict_type: | |
12235 | return "DW_TAG_restrict_type"; | |
12236 | case DW_TAG_interface_type: | |
12237 | return "DW_TAG_interface_type"; | |
12238 | case DW_TAG_namespace: | |
12239 | return "DW_TAG_namespace"; | |
12240 | case DW_TAG_imported_module: | |
12241 | return "DW_TAG_imported_module"; | |
12242 | case DW_TAG_unspecified_type: | |
12243 | return "DW_TAG_unspecified_type"; | |
12244 | case DW_TAG_partial_unit: | |
12245 | return "DW_TAG_partial_unit"; | |
12246 | case DW_TAG_imported_unit: | |
12247 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
12248 | case DW_TAG_condition: |
12249 | return "DW_TAG_condition"; | |
12250 | case DW_TAG_shared_type: | |
12251 | return "DW_TAG_shared_type"; | |
348e048f DE |
12252 | case DW_TAG_type_unit: |
12253 | return "DW_TAG_type_unit"; | |
c906108c SS |
12254 | case DW_TAG_MIPS_loop: |
12255 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
12256 | case DW_TAG_HP_array_descriptor: |
12257 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
12258 | case DW_TAG_format_label: |
12259 | return "DW_TAG_format_label"; | |
12260 | case DW_TAG_function_template: | |
12261 | return "DW_TAG_function_template"; | |
12262 | case DW_TAG_class_template: | |
12263 | return "DW_TAG_class_template"; | |
b7619582 GF |
12264 | case DW_TAG_GNU_BINCL: |
12265 | return "DW_TAG_GNU_BINCL"; | |
12266 | case DW_TAG_GNU_EINCL: | |
12267 | return "DW_TAG_GNU_EINCL"; | |
12268 | case DW_TAG_upc_shared_type: | |
12269 | return "DW_TAG_upc_shared_type"; | |
12270 | case DW_TAG_upc_strict_type: | |
12271 | return "DW_TAG_upc_strict_type"; | |
12272 | case DW_TAG_upc_relaxed_type: | |
12273 | return "DW_TAG_upc_relaxed_type"; | |
12274 | case DW_TAG_PGI_kanji_type: | |
12275 | return "DW_TAG_PGI_kanji_type"; | |
12276 | case DW_TAG_PGI_interface_block: | |
12277 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
12278 | default: |
12279 | return "DW_TAG_<unknown>"; | |
12280 | } | |
12281 | } | |
12282 | ||
12283 | /* Convert a DWARF attribute code into its string name. */ | |
12284 | ||
12285 | static char * | |
aa1ee363 | 12286 | dwarf_attr_name (unsigned attr) |
c906108c SS |
12287 | { |
12288 | switch (attr) | |
12289 | { | |
12290 | case DW_AT_sibling: | |
12291 | return "DW_AT_sibling"; | |
12292 | case DW_AT_location: | |
12293 | return "DW_AT_location"; | |
12294 | case DW_AT_name: | |
12295 | return "DW_AT_name"; | |
12296 | case DW_AT_ordering: | |
12297 | return "DW_AT_ordering"; | |
12298 | case DW_AT_subscr_data: | |
12299 | return "DW_AT_subscr_data"; | |
12300 | case DW_AT_byte_size: | |
12301 | return "DW_AT_byte_size"; | |
12302 | case DW_AT_bit_offset: | |
12303 | return "DW_AT_bit_offset"; | |
12304 | case DW_AT_bit_size: | |
12305 | return "DW_AT_bit_size"; | |
12306 | case DW_AT_element_list: | |
12307 | return "DW_AT_element_list"; | |
12308 | case DW_AT_stmt_list: | |
12309 | return "DW_AT_stmt_list"; | |
12310 | case DW_AT_low_pc: | |
12311 | return "DW_AT_low_pc"; | |
12312 | case DW_AT_high_pc: | |
12313 | return "DW_AT_high_pc"; | |
12314 | case DW_AT_language: | |
12315 | return "DW_AT_language"; | |
12316 | case DW_AT_member: | |
12317 | return "DW_AT_member"; | |
12318 | case DW_AT_discr: | |
12319 | return "DW_AT_discr"; | |
12320 | case DW_AT_discr_value: | |
12321 | return "DW_AT_discr_value"; | |
12322 | case DW_AT_visibility: | |
12323 | return "DW_AT_visibility"; | |
12324 | case DW_AT_import: | |
12325 | return "DW_AT_import"; | |
12326 | case DW_AT_string_length: | |
12327 | return "DW_AT_string_length"; | |
12328 | case DW_AT_common_reference: | |
12329 | return "DW_AT_common_reference"; | |
12330 | case DW_AT_comp_dir: | |
12331 | return "DW_AT_comp_dir"; | |
12332 | case DW_AT_const_value: | |
12333 | return "DW_AT_const_value"; | |
12334 | case DW_AT_containing_type: | |
12335 | return "DW_AT_containing_type"; | |
12336 | case DW_AT_default_value: | |
12337 | return "DW_AT_default_value"; | |
12338 | case DW_AT_inline: | |
12339 | return "DW_AT_inline"; | |
12340 | case DW_AT_is_optional: | |
12341 | return "DW_AT_is_optional"; | |
12342 | case DW_AT_lower_bound: | |
12343 | return "DW_AT_lower_bound"; | |
12344 | case DW_AT_producer: | |
12345 | return "DW_AT_producer"; | |
12346 | case DW_AT_prototyped: | |
12347 | return "DW_AT_prototyped"; | |
12348 | case DW_AT_return_addr: | |
12349 | return "DW_AT_return_addr"; | |
12350 | case DW_AT_start_scope: | |
12351 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
12352 | case DW_AT_bit_stride: |
12353 | return "DW_AT_bit_stride"; | |
c906108c SS |
12354 | case DW_AT_upper_bound: |
12355 | return "DW_AT_upper_bound"; | |
12356 | case DW_AT_abstract_origin: | |
12357 | return "DW_AT_abstract_origin"; | |
12358 | case DW_AT_accessibility: | |
12359 | return "DW_AT_accessibility"; | |
12360 | case DW_AT_address_class: | |
12361 | return "DW_AT_address_class"; | |
12362 | case DW_AT_artificial: | |
12363 | return "DW_AT_artificial"; | |
12364 | case DW_AT_base_types: | |
12365 | return "DW_AT_base_types"; | |
12366 | case DW_AT_calling_convention: | |
12367 | return "DW_AT_calling_convention"; | |
12368 | case DW_AT_count: | |
12369 | return "DW_AT_count"; | |
12370 | case DW_AT_data_member_location: | |
12371 | return "DW_AT_data_member_location"; | |
12372 | case DW_AT_decl_column: | |
12373 | return "DW_AT_decl_column"; | |
12374 | case DW_AT_decl_file: | |
12375 | return "DW_AT_decl_file"; | |
12376 | case DW_AT_decl_line: | |
12377 | return "DW_AT_decl_line"; | |
12378 | case DW_AT_declaration: | |
12379 | return "DW_AT_declaration"; | |
12380 | case DW_AT_discr_list: | |
12381 | return "DW_AT_discr_list"; | |
12382 | case DW_AT_encoding: | |
12383 | return "DW_AT_encoding"; | |
12384 | case DW_AT_external: | |
12385 | return "DW_AT_external"; | |
12386 | case DW_AT_frame_base: | |
12387 | return "DW_AT_frame_base"; | |
12388 | case DW_AT_friend: | |
12389 | return "DW_AT_friend"; | |
12390 | case DW_AT_identifier_case: | |
12391 | return "DW_AT_identifier_case"; | |
12392 | case DW_AT_macro_info: | |
12393 | return "DW_AT_macro_info"; | |
12394 | case DW_AT_namelist_items: | |
12395 | return "DW_AT_namelist_items"; | |
12396 | case DW_AT_priority: | |
12397 | return "DW_AT_priority"; | |
12398 | case DW_AT_segment: | |
12399 | return "DW_AT_segment"; | |
12400 | case DW_AT_specification: | |
12401 | return "DW_AT_specification"; | |
12402 | case DW_AT_static_link: | |
12403 | return "DW_AT_static_link"; | |
12404 | case DW_AT_type: | |
12405 | return "DW_AT_type"; | |
12406 | case DW_AT_use_location: | |
12407 | return "DW_AT_use_location"; | |
12408 | case DW_AT_variable_parameter: | |
12409 | return "DW_AT_variable_parameter"; | |
12410 | case DW_AT_virtuality: | |
12411 | return "DW_AT_virtuality"; | |
12412 | case DW_AT_vtable_elem_location: | |
12413 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 12414 | /* DWARF 3 values. */ |
d9fa45fe DC |
12415 | case DW_AT_allocated: |
12416 | return "DW_AT_allocated"; | |
12417 | case DW_AT_associated: | |
12418 | return "DW_AT_associated"; | |
12419 | case DW_AT_data_location: | |
12420 | return "DW_AT_data_location"; | |
09fa0d7c JK |
12421 | case DW_AT_byte_stride: |
12422 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
12423 | case DW_AT_entry_pc: |
12424 | return "DW_AT_entry_pc"; | |
12425 | case DW_AT_use_UTF8: | |
12426 | return "DW_AT_use_UTF8"; | |
12427 | case DW_AT_extension: | |
12428 | return "DW_AT_extension"; | |
12429 | case DW_AT_ranges: | |
12430 | return "DW_AT_ranges"; | |
12431 | case DW_AT_trampoline: | |
12432 | return "DW_AT_trampoline"; | |
12433 | case DW_AT_call_column: | |
12434 | return "DW_AT_call_column"; | |
12435 | case DW_AT_call_file: | |
12436 | return "DW_AT_call_file"; | |
12437 | case DW_AT_call_line: | |
12438 | return "DW_AT_call_line"; | |
b7619582 GF |
12439 | case DW_AT_description: |
12440 | return "DW_AT_description"; | |
12441 | case DW_AT_binary_scale: | |
12442 | return "DW_AT_binary_scale"; | |
12443 | case DW_AT_decimal_scale: | |
12444 | return "DW_AT_decimal_scale"; | |
12445 | case DW_AT_small: | |
12446 | return "DW_AT_small"; | |
12447 | case DW_AT_decimal_sign: | |
12448 | return "DW_AT_decimal_sign"; | |
12449 | case DW_AT_digit_count: | |
12450 | return "DW_AT_digit_count"; | |
12451 | case DW_AT_picture_string: | |
12452 | return "DW_AT_picture_string"; | |
12453 | case DW_AT_mutable: | |
12454 | return "DW_AT_mutable"; | |
12455 | case DW_AT_threads_scaled: | |
12456 | return "DW_AT_threads_scaled"; | |
12457 | case DW_AT_explicit: | |
12458 | return "DW_AT_explicit"; | |
12459 | case DW_AT_object_pointer: | |
12460 | return "DW_AT_object_pointer"; | |
12461 | case DW_AT_endianity: | |
12462 | return "DW_AT_endianity"; | |
12463 | case DW_AT_elemental: | |
12464 | return "DW_AT_elemental"; | |
12465 | case DW_AT_pure: | |
12466 | return "DW_AT_pure"; | |
12467 | case DW_AT_recursive: | |
12468 | return "DW_AT_recursive"; | |
348e048f DE |
12469 | /* DWARF 4 values. */ |
12470 | case DW_AT_signature: | |
12471 | return "DW_AT_signature"; | |
31ef98ae TT |
12472 | case DW_AT_linkage_name: |
12473 | return "DW_AT_linkage_name"; | |
b7619582 | 12474 | /* SGI/MIPS extensions. */ |
c764a876 | 12475 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
12476 | case DW_AT_MIPS_fde: |
12477 | return "DW_AT_MIPS_fde"; | |
c764a876 | 12478 | #endif |
c906108c SS |
12479 | case DW_AT_MIPS_loop_begin: |
12480 | return "DW_AT_MIPS_loop_begin"; | |
12481 | case DW_AT_MIPS_tail_loop_begin: | |
12482 | return "DW_AT_MIPS_tail_loop_begin"; | |
12483 | case DW_AT_MIPS_epilog_begin: | |
12484 | return "DW_AT_MIPS_epilog_begin"; | |
12485 | case DW_AT_MIPS_loop_unroll_factor: | |
12486 | return "DW_AT_MIPS_loop_unroll_factor"; | |
12487 | case DW_AT_MIPS_software_pipeline_depth: | |
12488 | return "DW_AT_MIPS_software_pipeline_depth"; | |
12489 | case DW_AT_MIPS_linkage_name: | |
12490 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
12491 | case DW_AT_MIPS_stride: |
12492 | return "DW_AT_MIPS_stride"; | |
12493 | case DW_AT_MIPS_abstract_name: | |
12494 | return "DW_AT_MIPS_abstract_name"; | |
12495 | case DW_AT_MIPS_clone_origin: | |
12496 | return "DW_AT_MIPS_clone_origin"; | |
12497 | case DW_AT_MIPS_has_inlines: | |
12498 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 12499 | /* HP extensions. */ |
c764a876 | 12500 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
12501 | case DW_AT_HP_block_index: |
12502 | return "DW_AT_HP_block_index"; | |
c764a876 | 12503 | #endif |
b7619582 GF |
12504 | case DW_AT_HP_unmodifiable: |
12505 | return "DW_AT_HP_unmodifiable"; | |
12506 | case DW_AT_HP_actuals_stmt_list: | |
12507 | return "DW_AT_HP_actuals_stmt_list"; | |
12508 | case DW_AT_HP_proc_per_section: | |
12509 | return "DW_AT_HP_proc_per_section"; | |
12510 | case DW_AT_HP_raw_data_ptr: | |
12511 | return "DW_AT_HP_raw_data_ptr"; | |
12512 | case DW_AT_HP_pass_by_reference: | |
12513 | return "DW_AT_HP_pass_by_reference"; | |
12514 | case DW_AT_HP_opt_level: | |
12515 | return "DW_AT_HP_opt_level"; | |
12516 | case DW_AT_HP_prof_version_id: | |
12517 | return "DW_AT_HP_prof_version_id"; | |
12518 | case DW_AT_HP_opt_flags: | |
12519 | return "DW_AT_HP_opt_flags"; | |
12520 | case DW_AT_HP_cold_region_low_pc: | |
12521 | return "DW_AT_HP_cold_region_low_pc"; | |
12522 | case DW_AT_HP_cold_region_high_pc: | |
12523 | return "DW_AT_HP_cold_region_high_pc"; | |
12524 | case DW_AT_HP_all_variables_modifiable: | |
12525 | return "DW_AT_HP_all_variables_modifiable"; | |
12526 | case DW_AT_HP_linkage_name: | |
12527 | return "DW_AT_HP_linkage_name"; | |
12528 | case DW_AT_HP_prof_flags: | |
12529 | return "DW_AT_HP_prof_flags"; | |
12530 | /* GNU extensions. */ | |
c906108c SS |
12531 | case DW_AT_sf_names: |
12532 | return "DW_AT_sf_names"; | |
12533 | case DW_AT_src_info: | |
12534 | return "DW_AT_src_info"; | |
12535 | case DW_AT_mac_info: | |
12536 | return "DW_AT_mac_info"; | |
12537 | case DW_AT_src_coords: | |
12538 | return "DW_AT_src_coords"; | |
12539 | case DW_AT_body_begin: | |
12540 | return "DW_AT_body_begin"; | |
12541 | case DW_AT_body_end: | |
12542 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
12543 | case DW_AT_GNU_vector: |
12544 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
12545 | case DW_AT_GNU_odr_signature: |
12546 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
12547 | /* VMS extensions. */ |
12548 | case DW_AT_VMS_rtnbeg_pd_address: | |
12549 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
12550 | /* UPC extension. */ | |
12551 | case DW_AT_upc_threads_scaled: | |
12552 | return "DW_AT_upc_threads_scaled"; | |
12553 | /* PGI (STMicroelectronics) extensions. */ | |
12554 | case DW_AT_PGI_lbase: | |
12555 | return "DW_AT_PGI_lbase"; | |
12556 | case DW_AT_PGI_soffset: | |
12557 | return "DW_AT_PGI_soffset"; | |
12558 | case DW_AT_PGI_lstride: | |
12559 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
12560 | default: |
12561 | return "DW_AT_<unknown>"; | |
12562 | } | |
12563 | } | |
12564 | ||
12565 | /* Convert a DWARF value form code into its string name. */ | |
12566 | ||
12567 | static char * | |
aa1ee363 | 12568 | dwarf_form_name (unsigned form) |
c906108c SS |
12569 | { |
12570 | switch (form) | |
12571 | { | |
12572 | case DW_FORM_addr: | |
12573 | return "DW_FORM_addr"; | |
12574 | case DW_FORM_block2: | |
12575 | return "DW_FORM_block2"; | |
12576 | case DW_FORM_block4: | |
12577 | return "DW_FORM_block4"; | |
12578 | case DW_FORM_data2: | |
12579 | return "DW_FORM_data2"; | |
12580 | case DW_FORM_data4: | |
12581 | return "DW_FORM_data4"; | |
12582 | case DW_FORM_data8: | |
12583 | return "DW_FORM_data8"; | |
12584 | case DW_FORM_string: | |
12585 | return "DW_FORM_string"; | |
12586 | case DW_FORM_block: | |
12587 | return "DW_FORM_block"; | |
12588 | case DW_FORM_block1: | |
12589 | return "DW_FORM_block1"; | |
12590 | case DW_FORM_data1: | |
12591 | return "DW_FORM_data1"; | |
12592 | case DW_FORM_flag: | |
12593 | return "DW_FORM_flag"; | |
12594 | case DW_FORM_sdata: | |
12595 | return "DW_FORM_sdata"; | |
12596 | case DW_FORM_strp: | |
12597 | return "DW_FORM_strp"; | |
12598 | case DW_FORM_udata: | |
12599 | return "DW_FORM_udata"; | |
12600 | case DW_FORM_ref_addr: | |
12601 | return "DW_FORM_ref_addr"; | |
12602 | case DW_FORM_ref1: | |
12603 | return "DW_FORM_ref1"; | |
12604 | case DW_FORM_ref2: | |
12605 | return "DW_FORM_ref2"; | |
12606 | case DW_FORM_ref4: | |
12607 | return "DW_FORM_ref4"; | |
12608 | case DW_FORM_ref8: | |
12609 | return "DW_FORM_ref8"; | |
12610 | case DW_FORM_ref_udata: | |
12611 | return "DW_FORM_ref_udata"; | |
12612 | case DW_FORM_indirect: | |
12613 | return "DW_FORM_indirect"; | |
348e048f DE |
12614 | case DW_FORM_sec_offset: |
12615 | return "DW_FORM_sec_offset"; | |
12616 | case DW_FORM_exprloc: | |
12617 | return "DW_FORM_exprloc"; | |
12618 | case DW_FORM_flag_present: | |
12619 | return "DW_FORM_flag_present"; | |
55f1336d TT |
12620 | case DW_FORM_ref_sig8: |
12621 | return "DW_FORM_ref_sig8"; | |
c906108c SS |
12622 | default: |
12623 | return "DW_FORM_<unknown>"; | |
12624 | } | |
12625 | } | |
12626 | ||
12627 | /* Convert a DWARF stack opcode into its string name. */ | |
12628 | ||
9eae7c52 | 12629 | const char * |
b1bfef65 | 12630 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
12631 | { |
12632 | switch (op) | |
12633 | { | |
12634 | case DW_OP_addr: | |
12635 | return "DW_OP_addr"; | |
12636 | case DW_OP_deref: | |
12637 | return "DW_OP_deref"; | |
12638 | case DW_OP_const1u: | |
12639 | return "DW_OP_const1u"; | |
12640 | case DW_OP_const1s: | |
12641 | return "DW_OP_const1s"; | |
12642 | case DW_OP_const2u: | |
12643 | return "DW_OP_const2u"; | |
12644 | case DW_OP_const2s: | |
12645 | return "DW_OP_const2s"; | |
12646 | case DW_OP_const4u: | |
12647 | return "DW_OP_const4u"; | |
12648 | case DW_OP_const4s: | |
12649 | return "DW_OP_const4s"; | |
12650 | case DW_OP_const8u: | |
12651 | return "DW_OP_const8u"; | |
12652 | case DW_OP_const8s: | |
12653 | return "DW_OP_const8s"; | |
12654 | case DW_OP_constu: | |
12655 | return "DW_OP_constu"; | |
12656 | case DW_OP_consts: | |
12657 | return "DW_OP_consts"; | |
12658 | case DW_OP_dup: | |
12659 | return "DW_OP_dup"; | |
12660 | case DW_OP_drop: | |
12661 | return "DW_OP_drop"; | |
12662 | case DW_OP_over: | |
12663 | return "DW_OP_over"; | |
12664 | case DW_OP_pick: | |
12665 | return "DW_OP_pick"; | |
12666 | case DW_OP_swap: | |
12667 | return "DW_OP_swap"; | |
12668 | case DW_OP_rot: | |
12669 | return "DW_OP_rot"; | |
12670 | case DW_OP_xderef: | |
12671 | return "DW_OP_xderef"; | |
12672 | case DW_OP_abs: | |
12673 | return "DW_OP_abs"; | |
12674 | case DW_OP_and: | |
12675 | return "DW_OP_and"; | |
12676 | case DW_OP_div: | |
12677 | return "DW_OP_div"; | |
12678 | case DW_OP_minus: | |
12679 | return "DW_OP_minus"; | |
12680 | case DW_OP_mod: | |
12681 | return "DW_OP_mod"; | |
12682 | case DW_OP_mul: | |
12683 | return "DW_OP_mul"; | |
12684 | case DW_OP_neg: | |
12685 | return "DW_OP_neg"; | |
12686 | case DW_OP_not: | |
12687 | return "DW_OP_not"; | |
12688 | case DW_OP_or: | |
12689 | return "DW_OP_or"; | |
12690 | case DW_OP_plus: | |
12691 | return "DW_OP_plus"; | |
12692 | case DW_OP_plus_uconst: | |
12693 | return "DW_OP_plus_uconst"; | |
12694 | case DW_OP_shl: | |
12695 | return "DW_OP_shl"; | |
12696 | case DW_OP_shr: | |
12697 | return "DW_OP_shr"; | |
12698 | case DW_OP_shra: | |
12699 | return "DW_OP_shra"; | |
12700 | case DW_OP_xor: | |
12701 | return "DW_OP_xor"; | |
12702 | case DW_OP_bra: | |
12703 | return "DW_OP_bra"; | |
12704 | case DW_OP_eq: | |
12705 | return "DW_OP_eq"; | |
12706 | case DW_OP_ge: | |
12707 | return "DW_OP_ge"; | |
12708 | case DW_OP_gt: | |
12709 | return "DW_OP_gt"; | |
12710 | case DW_OP_le: | |
12711 | return "DW_OP_le"; | |
12712 | case DW_OP_lt: | |
12713 | return "DW_OP_lt"; | |
12714 | case DW_OP_ne: | |
12715 | return "DW_OP_ne"; | |
12716 | case DW_OP_skip: | |
12717 | return "DW_OP_skip"; | |
12718 | case DW_OP_lit0: | |
12719 | return "DW_OP_lit0"; | |
12720 | case DW_OP_lit1: | |
12721 | return "DW_OP_lit1"; | |
12722 | case DW_OP_lit2: | |
12723 | return "DW_OP_lit2"; | |
12724 | case DW_OP_lit3: | |
12725 | return "DW_OP_lit3"; | |
12726 | case DW_OP_lit4: | |
12727 | return "DW_OP_lit4"; | |
12728 | case DW_OP_lit5: | |
12729 | return "DW_OP_lit5"; | |
12730 | case DW_OP_lit6: | |
12731 | return "DW_OP_lit6"; | |
12732 | case DW_OP_lit7: | |
12733 | return "DW_OP_lit7"; | |
12734 | case DW_OP_lit8: | |
12735 | return "DW_OP_lit8"; | |
12736 | case DW_OP_lit9: | |
12737 | return "DW_OP_lit9"; | |
12738 | case DW_OP_lit10: | |
12739 | return "DW_OP_lit10"; | |
12740 | case DW_OP_lit11: | |
12741 | return "DW_OP_lit11"; | |
12742 | case DW_OP_lit12: | |
12743 | return "DW_OP_lit12"; | |
12744 | case DW_OP_lit13: | |
12745 | return "DW_OP_lit13"; | |
12746 | case DW_OP_lit14: | |
12747 | return "DW_OP_lit14"; | |
12748 | case DW_OP_lit15: | |
12749 | return "DW_OP_lit15"; | |
12750 | case DW_OP_lit16: | |
12751 | return "DW_OP_lit16"; | |
12752 | case DW_OP_lit17: | |
12753 | return "DW_OP_lit17"; | |
12754 | case DW_OP_lit18: | |
12755 | return "DW_OP_lit18"; | |
12756 | case DW_OP_lit19: | |
12757 | return "DW_OP_lit19"; | |
12758 | case DW_OP_lit20: | |
12759 | return "DW_OP_lit20"; | |
12760 | case DW_OP_lit21: | |
12761 | return "DW_OP_lit21"; | |
12762 | case DW_OP_lit22: | |
12763 | return "DW_OP_lit22"; | |
12764 | case DW_OP_lit23: | |
12765 | return "DW_OP_lit23"; | |
12766 | case DW_OP_lit24: | |
12767 | return "DW_OP_lit24"; | |
12768 | case DW_OP_lit25: | |
12769 | return "DW_OP_lit25"; | |
12770 | case DW_OP_lit26: | |
12771 | return "DW_OP_lit26"; | |
12772 | case DW_OP_lit27: | |
12773 | return "DW_OP_lit27"; | |
12774 | case DW_OP_lit28: | |
12775 | return "DW_OP_lit28"; | |
12776 | case DW_OP_lit29: | |
12777 | return "DW_OP_lit29"; | |
12778 | case DW_OP_lit30: | |
12779 | return "DW_OP_lit30"; | |
12780 | case DW_OP_lit31: | |
12781 | return "DW_OP_lit31"; | |
12782 | case DW_OP_reg0: | |
12783 | return "DW_OP_reg0"; | |
12784 | case DW_OP_reg1: | |
12785 | return "DW_OP_reg1"; | |
12786 | case DW_OP_reg2: | |
12787 | return "DW_OP_reg2"; | |
12788 | case DW_OP_reg3: | |
12789 | return "DW_OP_reg3"; | |
12790 | case DW_OP_reg4: | |
12791 | return "DW_OP_reg4"; | |
12792 | case DW_OP_reg5: | |
12793 | return "DW_OP_reg5"; | |
12794 | case DW_OP_reg6: | |
12795 | return "DW_OP_reg6"; | |
12796 | case DW_OP_reg7: | |
12797 | return "DW_OP_reg7"; | |
12798 | case DW_OP_reg8: | |
12799 | return "DW_OP_reg8"; | |
12800 | case DW_OP_reg9: | |
12801 | return "DW_OP_reg9"; | |
12802 | case DW_OP_reg10: | |
12803 | return "DW_OP_reg10"; | |
12804 | case DW_OP_reg11: | |
12805 | return "DW_OP_reg11"; | |
12806 | case DW_OP_reg12: | |
12807 | return "DW_OP_reg12"; | |
12808 | case DW_OP_reg13: | |
12809 | return "DW_OP_reg13"; | |
12810 | case DW_OP_reg14: | |
12811 | return "DW_OP_reg14"; | |
12812 | case DW_OP_reg15: | |
12813 | return "DW_OP_reg15"; | |
12814 | case DW_OP_reg16: | |
12815 | return "DW_OP_reg16"; | |
12816 | case DW_OP_reg17: | |
12817 | return "DW_OP_reg17"; | |
12818 | case DW_OP_reg18: | |
12819 | return "DW_OP_reg18"; | |
12820 | case DW_OP_reg19: | |
12821 | return "DW_OP_reg19"; | |
12822 | case DW_OP_reg20: | |
12823 | return "DW_OP_reg20"; | |
12824 | case DW_OP_reg21: | |
12825 | return "DW_OP_reg21"; | |
12826 | case DW_OP_reg22: | |
12827 | return "DW_OP_reg22"; | |
12828 | case DW_OP_reg23: | |
12829 | return "DW_OP_reg23"; | |
12830 | case DW_OP_reg24: | |
12831 | return "DW_OP_reg24"; | |
12832 | case DW_OP_reg25: | |
12833 | return "DW_OP_reg25"; | |
12834 | case DW_OP_reg26: | |
12835 | return "DW_OP_reg26"; | |
12836 | case DW_OP_reg27: | |
12837 | return "DW_OP_reg27"; | |
12838 | case DW_OP_reg28: | |
12839 | return "DW_OP_reg28"; | |
12840 | case DW_OP_reg29: | |
12841 | return "DW_OP_reg29"; | |
12842 | case DW_OP_reg30: | |
12843 | return "DW_OP_reg30"; | |
12844 | case DW_OP_reg31: | |
12845 | return "DW_OP_reg31"; | |
12846 | case DW_OP_breg0: | |
12847 | return "DW_OP_breg0"; | |
12848 | case DW_OP_breg1: | |
12849 | return "DW_OP_breg1"; | |
12850 | case DW_OP_breg2: | |
12851 | return "DW_OP_breg2"; | |
12852 | case DW_OP_breg3: | |
12853 | return "DW_OP_breg3"; | |
12854 | case DW_OP_breg4: | |
12855 | return "DW_OP_breg4"; | |
12856 | case DW_OP_breg5: | |
12857 | return "DW_OP_breg5"; | |
12858 | case DW_OP_breg6: | |
12859 | return "DW_OP_breg6"; | |
12860 | case DW_OP_breg7: | |
12861 | return "DW_OP_breg7"; | |
12862 | case DW_OP_breg8: | |
12863 | return "DW_OP_breg8"; | |
12864 | case DW_OP_breg9: | |
12865 | return "DW_OP_breg9"; | |
12866 | case DW_OP_breg10: | |
12867 | return "DW_OP_breg10"; | |
12868 | case DW_OP_breg11: | |
12869 | return "DW_OP_breg11"; | |
12870 | case DW_OP_breg12: | |
12871 | return "DW_OP_breg12"; | |
12872 | case DW_OP_breg13: | |
12873 | return "DW_OP_breg13"; | |
12874 | case DW_OP_breg14: | |
12875 | return "DW_OP_breg14"; | |
12876 | case DW_OP_breg15: | |
12877 | return "DW_OP_breg15"; | |
12878 | case DW_OP_breg16: | |
12879 | return "DW_OP_breg16"; | |
12880 | case DW_OP_breg17: | |
12881 | return "DW_OP_breg17"; | |
12882 | case DW_OP_breg18: | |
12883 | return "DW_OP_breg18"; | |
12884 | case DW_OP_breg19: | |
12885 | return "DW_OP_breg19"; | |
12886 | case DW_OP_breg20: | |
12887 | return "DW_OP_breg20"; | |
12888 | case DW_OP_breg21: | |
12889 | return "DW_OP_breg21"; | |
12890 | case DW_OP_breg22: | |
12891 | return "DW_OP_breg22"; | |
12892 | case DW_OP_breg23: | |
12893 | return "DW_OP_breg23"; | |
12894 | case DW_OP_breg24: | |
12895 | return "DW_OP_breg24"; | |
12896 | case DW_OP_breg25: | |
12897 | return "DW_OP_breg25"; | |
12898 | case DW_OP_breg26: | |
12899 | return "DW_OP_breg26"; | |
12900 | case DW_OP_breg27: | |
12901 | return "DW_OP_breg27"; | |
12902 | case DW_OP_breg28: | |
12903 | return "DW_OP_breg28"; | |
12904 | case DW_OP_breg29: | |
12905 | return "DW_OP_breg29"; | |
12906 | case DW_OP_breg30: | |
12907 | return "DW_OP_breg30"; | |
12908 | case DW_OP_breg31: | |
12909 | return "DW_OP_breg31"; | |
12910 | case DW_OP_regx: | |
12911 | return "DW_OP_regx"; | |
12912 | case DW_OP_fbreg: | |
12913 | return "DW_OP_fbreg"; | |
12914 | case DW_OP_bregx: | |
12915 | return "DW_OP_bregx"; | |
12916 | case DW_OP_piece: | |
12917 | return "DW_OP_piece"; | |
12918 | case DW_OP_deref_size: | |
12919 | return "DW_OP_deref_size"; | |
12920 | case DW_OP_xderef_size: | |
12921 | return "DW_OP_xderef_size"; | |
12922 | case DW_OP_nop: | |
12923 | return "DW_OP_nop"; | |
b7619582 | 12924 | /* DWARF 3 extensions. */ |
ed348acc EZ |
12925 | case DW_OP_push_object_address: |
12926 | return "DW_OP_push_object_address"; | |
12927 | case DW_OP_call2: | |
12928 | return "DW_OP_call2"; | |
12929 | case DW_OP_call4: | |
12930 | return "DW_OP_call4"; | |
12931 | case DW_OP_call_ref: | |
12932 | return "DW_OP_call_ref"; | |
b7619582 GF |
12933 | case DW_OP_form_tls_address: |
12934 | return "DW_OP_form_tls_address"; | |
12935 | case DW_OP_call_frame_cfa: | |
12936 | return "DW_OP_call_frame_cfa"; | |
12937 | case DW_OP_bit_piece: | |
12938 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
12939 | /* DWARF 4 extensions. */ |
12940 | case DW_OP_implicit_value: | |
12941 | return "DW_OP_implicit_value"; | |
12942 | case DW_OP_stack_value: | |
12943 | return "DW_OP_stack_value"; | |
12944 | /* GNU extensions. */ | |
ed348acc EZ |
12945 | case DW_OP_GNU_push_tls_address: |
12946 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
12947 | case DW_OP_GNU_uninit: |
12948 | return "DW_OP_GNU_uninit"; | |
8cf6f0b1 TT |
12949 | case DW_OP_GNU_implicit_pointer: |
12950 | return "DW_OP_GNU_implicit_pointer"; | |
c906108c | 12951 | default: |
b1bfef65 | 12952 | return NULL; |
c906108c SS |
12953 | } |
12954 | } | |
12955 | ||
12956 | static char * | |
fba45db2 | 12957 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
12958 | { |
12959 | if (mybool) | |
12960 | return "TRUE"; | |
12961 | else | |
12962 | return "FALSE"; | |
12963 | } | |
12964 | ||
12965 | /* Convert a DWARF type code into its string name. */ | |
12966 | ||
12967 | static char * | |
aa1ee363 | 12968 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
12969 | { |
12970 | switch (enc) | |
12971 | { | |
b7619582 GF |
12972 | case DW_ATE_void: |
12973 | return "DW_ATE_void"; | |
c906108c SS |
12974 | case DW_ATE_address: |
12975 | return "DW_ATE_address"; | |
12976 | case DW_ATE_boolean: | |
12977 | return "DW_ATE_boolean"; | |
12978 | case DW_ATE_complex_float: | |
12979 | return "DW_ATE_complex_float"; | |
12980 | case DW_ATE_float: | |
12981 | return "DW_ATE_float"; | |
12982 | case DW_ATE_signed: | |
12983 | return "DW_ATE_signed"; | |
12984 | case DW_ATE_signed_char: | |
12985 | return "DW_ATE_signed_char"; | |
12986 | case DW_ATE_unsigned: | |
12987 | return "DW_ATE_unsigned"; | |
12988 | case DW_ATE_unsigned_char: | |
12989 | return "DW_ATE_unsigned_char"; | |
b7619582 | 12990 | /* DWARF 3. */ |
d9fa45fe DC |
12991 | case DW_ATE_imaginary_float: |
12992 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
12993 | case DW_ATE_packed_decimal: |
12994 | return "DW_ATE_packed_decimal"; | |
12995 | case DW_ATE_numeric_string: | |
12996 | return "DW_ATE_numeric_string"; | |
12997 | case DW_ATE_edited: | |
12998 | return "DW_ATE_edited"; | |
12999 | case DW_ATE_signed_fixed: | |
13000 | return "DW_ATE_signed_fixed"; | |
13001 | case DW_ATE_unsigned_fixed: | |
13002 | return "DW_ATE_unsigned_fixed"; | |
13003 | case DW_ATE_decimal_float: | |
13004 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
13005 | /* DWARF 4. */ |
13006 | case DW_ATE_UTF: | |
13007 | return "DW_ATE_UTF"; | |
b7619582 GF |
13008 | /* HP extensions. */ |
13009 | case DW_ATE_HP_float80: | |
13010 | return "DW_ATE_HP_float80"; | |
13011 | case DW_ATE_HP_complex_float80: | |
13012 | return "DW_ATE_HP_complex_float80"; | |
13013 | case DW_ATE_HP_float128: | |
13014 | return "DW_ATE_HP_float128"; | |
13015 | case DW_ATE_HP_complex_float128: | |
13016 | return "DW_ATE_HP_complex_float128"; | |
13017 | case DW_ATE_HP_floathpintel: | |
13018 | return "DW_ATE_HP_floathpintel"; | |
13019 | case DW_ATE_HP_imaginary_float80: | |
13020 | return "DW_ATE_HP_imaginary_float80"; | |
13021 | case DW_ATE_HP_imaginary_float128: | |
13022 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
13023 | default: |
13024 | return "DW_ATE_<unknown>"; | |
13025 | } | |
13026 | } | |
13027 | ||
0963b4bd | 13028 | /* Convert a DWARF call frame info operation to its string name. */ |
c906108c SS |
13029 | |
13030 | #if 0 | |
13031 | static char * | |
aa1ee363 | 13032 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
13033 | { |
13034 | switch (cfi_opc) | |
13035 | { | |
13036 | case DW_CFA_advance_loc: | |
13037 | return "DW_CFA_advance_loc"; | |
13038 | case DW_CFA_offset: | |
13039 | return "DW_CFA_offset"; | |
13040 | case DW_CFA_restore: | |
13041 | return "DW_CFA_restore"; | |
13042 | case DW_CFA_nop: | |
13043 | return "DW_CFA_nop"; | |
13044 | case DW_CFA_set_loc: | |
13045 | return "DW_CFA_set_loc"; | |
13046 | case DW_CFA_advance_loc1: | |
13047 | return "DW_CFA_advance_loc1"; | |
13048 | case DW_CFA_advance_loc2: | |
13049 | return "DW_CFA_advance_loc2"; | |
13050 | case DW_CFA_advance_loc4: | |
13051 | return "DW_CFA_advance_loc4"; | |
13052 | case DW_CFA_offset_extended: | |
13053 | return "DW_CFA_offset_extended"; | |
13054 | case DW_CFA_restore_extended: | |
13055 | return "DW_CFA_restore_extended"; | |
13056 | case DW_CFA_undefined: | |
13057 | return "DW_CFA_undefined"; | |
13058 | case DW_CFA_same_value: | |
13059 | return "DW_CFA_same_value"; | |
13060 | case DW_CFA_register: | |
13061 | return "DW_CFA_register"; | |
13062 | case DW_CFA_remember_state: | |
13063 | return "DW_CFA_remember_state"; | |
13064 | case DW_CFA_restore_state: | |
13065 | return "DW_CFA_restore_state"; | |
13066 | case DW_CFA_def_cfa: | |
13067 | return "DW_CFA_def_cfa"; | |
13068 | case DW_CFA_def_cfa_register: | |
13069 | return "DW_CFA_def_cfa_register"; | |
13070 | case DW_CFA_def_cfa_offset: | |
13071 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 13072 | /* DWARF 3. */ |
985cb1a3 JM |
13073 | case DW_CFA_def_cfa_expression: |
13074 | return "DW_CFA_def_cfa_expression"; | |
13075 | case DW_CFA_expression: | |
13076 | return "DW_CFA_expression"; | |
13077 | case DW_CFA_offset_extended_sf: | |
13078 | return "DW_CFA_offset_extended_sf"; | |
13079 | case DW_CFA_def_cfa_sf: | |
13080 | return "DW_CFA_def_cfa_sf"; | |
13081 | case DW_CFA_def_cfa_offset_sf: | |
13082 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
13083 | case DW_CFA_val_offset: |
13084 | return "DW_CFA_val_offset"; | |
13085 | case DW_CFA_val_offset_sf: | |
13086 | return "DW_CFA_val_offset_sf"; | |
13087 | case DW_CFA_val_expression: | |
13088 | return "DW_CFA_val_expression"; | |
13089 | /* SGI/MIPS specific. */ | |
c906108c SS |
13090 | case DW_CFA_MIPS_advance_loc8: |
13091 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 13092 | /* GNU extensions. */ |
985cb1a3 JM |
13093 | case DW_CFA_GNU_window_save: |
13094 | return "DW_CFA_GNU_window_save"; | |
13095 | case DW_CFA_GNU_args_size: | |
13096 | return "DW_CFA_GNU_args_size"; | |
13097 | case DW_CFA_GNU_negative_offset_extended: | |
13098 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
13099 | default: |
13100 | return "DW_CFA_<unknown>"; | |
13101 | } | |
13102 | } | |
13103 | #endif | |
13104 | ||
f9aca02d | 13105 | static void |
d97bc12b | 13106 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
13107 | { |
13108 | unsigned int i; | |
13109 | ||
d97bc12b DE |
13110 | print_spaces (indent, f); |
13111 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 13112 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
13113 | |
13114 | if (die->parent != NULL) | |
13115 | { | |
13116 | print_spaces (indent, f); | |
13117 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
13118 | die->parent->offset); | |
13119 | } | |
13120 | ||
13121 | print_spaces (indent, f); | |
13122 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 13123 | dwarf_bool_name (die->child != NULL)); |
c906108c | 13124 | |
d97bc12b DE |
13125 | print_spaces (indent, f); |
13126 | fprintf_unfiltered (f, " attributes:\n"); | |
13127 | ||
c906108c SS |
13128 | for (i = 0; i < die->num_attrs; ++i) |
13129 | { | |
d97bc12b DE |
13130 | print_spaces (indent, f); |
13131 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
13132 | dwarf_attr_name (die->attrs[i].name), |
13133 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 13134 | |
c906108c SS |
13135 | switch (die->attrs[i].form) |
13136 | { | |
13137 | case DW_FORM_ref_addr: | |
13138 | case DW_FORM_addr: | |
d97bc12b | 13139 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 13140 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
13141 | break; |
13142 | case DW_FORM_block2: | |
13143 | case DW_FORM_block4: | |
13144 | case DW_FORM_block: | |
13145 | case DW_FORM_block1: | |
3e43a32a MS |
13146 | fprintf_unfiltered (f, "block: size %d", |
13147 | DW_BLOCK (&die->attrs[i])->size); | |
c906108c | 13148 | break; |
2dc7f7b3 TT |
13149 | case DW_FORM_exprloc: |
13150 | fprintf_unfiltered (f, "expression: size %u", | |
13151 | DW_BLOCK (&die->attrs[i])->size); | |
13152 | break; | |
10b3939b DJ |
13153 | case DW_FORM_ref1: |
13154 | case DW_FORM_ref2: | |
13155 | case DW_FORM_ref4: | |
d97bc12b | 13156 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
13157 | (long) (DW_ADDR (&die->attrs[i]))); |
13158 | break; | |
c906108c SS |
13159 | case DW_FORM_data1: |
13160 | case DW_FORM_data2: | |
13161 | case DW_FORM_data4: | |
ce5d95e1 | 13162 | case DW_FORM_data8: |
c906108c SS |
13163 | case DW_FORM_udata: |
13164 | case DW_FORM_sdata: | |
43bbcdc2 PH |
13165 | fprintf_unfiltered (f, "constant: %s", |
13166 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 13167 | break; |
2dc7f7b3 TT |
13168 | case DW_FORM_sec_offset: |
13169 | fprintf_unfiltered (f, "section offset: %s", | |
13170 | pulongest (DW_UNSND (&die->attrs[i]))); | |
13171 | break; | |
55f1336d | 13172 | case DW_FORM_ref_sig8: |
348e048f DE |
13173 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
13174 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
13175 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
13176 | else | |
13177 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
13178 | break; | |
c906108c | 13179 | case DW_FORM_string: |
4bdf3d34 | 13180 | case DW_FORM_strp: |
8285870a | 13181 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 13182 | DW_STRING (&die->attrs[i]) |
8285870a JK |
13183 | ? DW_STRING (&die->attrs[i]) : "", |
13184 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
13185 | break; |
13186 | case DW_FORM_flag: | |
13187 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 13188 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 13189 | else |
d97bc12b | 13190 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 13191 | break; |
2dc7f7b3 TT |
13192 | case DW_FORM_flag_present: |
13193 | fprintf_unfiltered (f, "flag: TRUE"); | |
13194 | break; | |
a8329558 | 13195 | case DW_FORM_indirect: |
0963b4bd MS |
13196 | /* The reader will have reduced the indirect form to |
13197 | the "base form" so this form should not occur. */ | |
3e43a32a MS |
13198 | fprintf_unfiltered (f, |
13199 | "unexpected attribute form: DW_FORM_indirect"); | |
a8329558 | 13200 | break; |
c906108c | 13201 | default: |
d97bc12b | 13202 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 13203 | die->attrs[i].form); |
d97bc12b | 13204 | break; |
c906108c | 13205 | } |
d97bc12b | 13206 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
13207 | } |
13208 | } | |
13209 | ||
f9aca02d | 13210 | static void |
d97bc12b | 13211 | dump_die_for_error (struct die_info *die) |
c906108c | 13212 | { |
d97bc12b DE |
13213 | dump_die_shallow (gdb_stderr, 0, die); |
13214 | } | |
13215 | ||
13216 | static void | |
13217 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
13218 | { | |
13219 | int indent = level * 4; | |
13220 | ||
13221 | gdb_assert (die != NULL); | |
13222 | ||
13223 | if (level >= max_level) | |
13224 | return; | |
13225 | ||
13226 | dump_die_shallow (f, indent, die); | |
13227 | ||
13228 | if (die->child != NULL) | |
c906108c | 13229 | { |
d97bc12b DE |
13230 | print_spaces (indent, f); |
13231 | fprintf_unfiltered (f, " Children:"); | |
13232 | if (level + 1 < max_level) | |
13233 | { | |
13234 | fprintf_unfiltered (f, "\n"); | |
13235 | dump_die_1 (f, level + 1, max_level, die->child); | |
13236 | } | |
13237 | else | |
13238 | { | |
3e43a32a MS |
13239 | fprintf_unfiltered (f, |
13240 | " [not printed, max nesting level reached]\n"); | |
d97bc12b DE |
13241 | } |
13242 | } | |
13243 | ||
13244 | if (die->sibling != NULL && level > 0) | |
13245 | { | |
13246 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
13247 | } |
13248 | } | |
13249 | ||
d97bc12b DE |
13250 | /* This is called from the pdie macro in gdbinit.in. |
13251 | It's not static so gcc will keep a copy callable from gdb. */ | |
13252 | ||
13253 | void | |
13254 | dump_die (struct die_info *die, int max_level) | |
13255 | { | |
13256 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
13257 | } | |
13258 | ||
f9aca02d | 13259 | static void |
51545339 | 13260 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 13261 | { |
51545339 | 13262 | void **slot; |
c906108c | 13263 | |
51545339 DJ |
13264 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
13265 | ||
13266 | *slot = die; | |
c906108c SS |
13267 | } |
13268 | ||
93311388 DE |
13269 | static int |
13270 | is_ref_attr (struct attribute *attr) | |
c906108c | 13271 | { |
c906108c SS |
13272 | switch (attr->form) |
13273 | { | |
13274 | case DW_FORM_ref_addr: | |
c906108c SS |
13275 | case DW_FORM_ref1: |
13276 | case DW_FORM_ref2: | |
13277 | case DW_FORM_ref4: | |
613e1657 | 13278 | case DW_FORM_ref8: |
c906108c | 13279 | case DW_FORM_ref_udata: |
93311388 | 13280 | return 1; |
c906108c | 13281 | default: |
93311388 | 13282 | return 0; |
c906108c | 13283 | } |
93311388 DE |
13284 | } |
13285 | ||
13286 | static unsigned int | |
13287 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
13288 | { | |
13289 | if (is_ref_attr (attr)) | |
13290 | return DW_ADDR (attr); | |
13291 | ||
13292 | complaint (&symfile_complaints, | |
13293 | _("unsupported die ref attribute form: '%s'"), | |
13294 | dwarf_form_name (attr->form)); | |
13295 | return 0; | |
c906108c SS |
13296 | } |
13297 | ||
43bbcdc2 PH |
13298 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
13299 | * the value held by the attribute is not constant. */ | |
a02abb62 | 13300 | |
43bbcdc2 | 13301 | static LONGEST |
a02abb62 JB |
13302 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
13303 | { | |
13304 | if (attr->form == DW_FORM_sdata) | |
13305 | return DW_SND (attr); | |
13306 | else if (attr->form == DW_FORM_udata | |
13307 | || attr->form == DW_FORM_data1 | |
13308 | || attr->form == DW_FORM_data2 | |
13309 | || attr->form == DW_FORM_data4 | |
13310 | || attr->form == DW_FORM_data8) | |
13311 | return DW_UNSND (attr); | |
13312 | else | |
13313 | { | |
3e43a32a MS |
13314 | complaint (&symfile_complaints, |
13315 | _("Attribute value is not a constant (%s)"), | |
a02abb62 JB |
13316 | dwarf_form_name (attr->form)); |
13317 | return default_value; | |
13318 | } | |
13319 | } | |
13320 | ||
03dd20cc | 13321 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
13322 | unit and add it to our queue. |
13323 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
13324 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 13325 | |
348e048f | 13326 | static int |
03dd20cc DJ |
13327 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
13328 | struct dwarf2_per_cu_data *per_cu) | |
13329 | { | |
98bfdba5 PA |
13330 | /* We may arrive here during partial symbol reading, if we need full |
13331 | DIEs to process an unusual case (e.g. template arguments). Do | |
13332 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
13333 | if (dwarf2_per_objfile->reading_partial_symbols) | |
13334 | { | |
13335 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
13336 | return 1; | |
13337 | return 0; | |
13338 | } | |
13339 | ||
03dd20cc DJ |
13340 | /* Mark the dependence relation so that we don't flush PER_CU |
13341 | too early. */ | |
13342 | dwarf2_add_dependence (this_cu, per_cu); | |
13343 | ||
13344 | /* If it's already on the queue, we have nothing to do. */ | |
13345 | if (per_cu->queued) | |
348e048f | 13346 | return 0; |
03dd20cc DJ |
13347 | |
13348 | /* If the compilation unit is already loaded, just mark it as | |
13349 | used. */ | |
13350 | if (per_cu->cu != NULL) | |
13351 | { | |
13352 | per_cu->cu->last_used = 0; | |
348e048f | 13353 | return 0; |
03dd20cc DJ |
13354 | } |
13355 | ||
13356 | /* Add it to the queue. */ | |
13357 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
13358 | |
13359 | return 1; | |
13360 | } | |
13361 | ||
13362 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
13363 | On entry *REF_CU is the CU of SRC_DIE. | |
13364 | On exit *REF_CU is the CU of the result. */ | |
13365 | ||
13366 | static struct die_info * | |
13367 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
13368 | struct dwarf2_cu **ref_cu) | |
13369 | { | |
13370 | struct die_info *die; | |
13371 | ||
13372 | if (is_ref_attr (attr)) | |
13373 | die = follow_die_ref (src_die, attr, ref_cu); | |
55f1336d | 13374 | else if (attr->form == DW_FORM_ref_sig8) |
348e048f DE |
13375 | die = follow_die_sig (src_die, attr, ref_cu); |
13376 | else | |
13377 | { | |
13378 | dump_die_for_error (src_die); | |
13379 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
13380 | (*ref_cu)->objfile->name); | |
13381 | } | |
13382 | ||
13383 | return die; | |
03dd20cc DJ |
13384 | } |
13385 | ||
5c631832 | 13386 | /* Follow reference OFFSET. |
673bfd45 DE |
13387 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
13388 | On exit *REF_CU is the CU of the result. | |
13389 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 13390 | |
f9aca02d | 13391 | static struct die_info * |
5c631832 | 13392 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 13393 | { |
10b3939b | 13394 | struct die_info temp_die; |
f2f0e013 | 13395 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 13396 | |
348e048f DE |
13397 | gdb_assert (cu->per_cu != NULL); |
13398 | ||
98bfdba5 PA |
13399 | target_cu = cu; |
13400 | ||
348e048f DE |
13401 | if (cu->per_cu->from_debug_types) |
13402 | { | |
13403 | /* .debug_types CUs cannot reference anything outside their CU. | |
13404 | If they need to, they have to reference a signatured type via | |
55f1336d | 13405 | DW_FORM_ref_sig8. */ |
348e048f | 13406 | if (! offset_in_cu_p (&cu->header, offset)) |
5c631832 | 13407 | return NULL; |
348e048f DE |
13408 | } |
13409 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
13410 | { |
13411 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 13412 | |
45452591 | 13413 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
13414 | |
13415 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
13416 | if (maybe_queue_comp_unit (cu, per_cu)) |
13417 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 13418 | |
10b3939b DJ |
13419 | target_cu = per_cu->cu; |
13420 | } | |
98bfdba5 PA |
13421 | else if (cu->dies == NULL) |
13422 | { | |
13423 | /* We're loading full DIEs during partial symbol reading. */ | |
13424 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
13425 | load_full_comp_unit (cu->per_cu, cu->objfile); | |
13426 | } | |
c906108c | 13427 | |
f2f0e013 | 13428 | *ref_cu = target_cu; |
51545339 | 13429 | temp_die.offset = offset; |
5c631832 JK |
13430 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
13431 | } | |
10b3939b | 13432 | |
5c631832 JK |
13433 | /* Follow reference attribute ATTR of SRC_DIE. |
13434 | On entry *REF_CU is the CU of SRC_DIE. | |
13435 | On exit *REF_CU is the CU of the result. */ | |
13436 | ||
13437 | static struct die_info * | |
13438 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
13439 | struct dwarf2_cu **ref_cu) | |
13440 | { | |
13441 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
13442 | struct dwarf2_cu *cu = *ref_cu; | |
13443 | struct die_info *die; | |
13444 | ||
13445 | die = follow_die_offset (offset, ref_cu); | |
13446 | if (!die) | |
13447 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
13448 | "at 0x%x [in module %s]"), | |
13449 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 13450 | |
5c631832 JK |
13451 | return die; |
13452 | } | |
13453 | ||
13454 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
13455 | value is intended for DW_OP_call*. */ | |
13456 | ||
13457 | struct dwarf2_locexpr_baton | |
13458 | dwarf2_fetch_die_location_block (unsigned int offset, | |
8cf6f0b1 TT |
13459 | struct dwarf2_per_cu_data *per_cu, |
13460 | CORE_ADDR (*get_frame_pc) (void *baton), | |
13461 | void *baton) | |
5c631832 JK |
13462 | { |
13463 | struct dwarf2_cu *cu = per_cu->cu; | |
13464 | struct die_info *die; | |
13465 | struct attribute *attr; | |
13466 | struct dwarf2_locexpr_baton retval; | |
13467 | ||
8cf6f0b1 TT |
13468 | dw2_setup (per_cu->objfile); |
13469 | ||
5c631832 JK |
13470 | die = follow_die_offset (offset, &cu); |
13471 | if (!die) | |
13472 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
13473 | offset, per_cu->cu->objfile->name); | |
13474 | ||
13475 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
13476 | if (!attr) | |
13477 | { | |
13478 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
13479 | ||
13480 | retval.data = NULL; | |
13481 | retval.size = 0; | |
13482 | } | |
8cf6f0b1 TT |
13483 | else if (attr_form_is_section_offset (attr)) |
13484 | { | |
13485 | struct dwarf2_loclist_baton loclist_baton; | |
13486 | CORE_ADDR pc = (*get_frame_pc) (baton); | |
13487 | size_t size; | |
13488 | ||
13489 | fill_in_loclist_baton (cu, &loclist_baton, attr); | |
13490 | ||
13491 | retval.data = dwarf2_find_location_expression (&loclist_baton, | |
13492 | &size, pc); | |
13493 | retval.size = size; | |
13494 | } | |
5c631832 JK |
13495 | else |
13496 | { | |
13497 | if (!attr_form_is_block (attr)) | |
13498 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
13499 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
13500 | offset, per_cu->cu->objfile->name); | |
13501 | ||
13502 | retval.data = DW_BLOCK (attr)->data; | |
13503 | retval.size = DW_BLOCK (attr)->size; | |
13504 | } | |
13505 | retval.per_cu = cu->per_cu; | |
13506 | return retval; | |
348e048f DE |
13507 | } |
13508 | ||
13509 | /* Follow the signature attribute ATTR in SRC_DIE. | |
13510 | On entry *REF_CU is the CU of SRC_DIE. | |
13511 | On exit *REF_CU is the CU of the result. */ | |
13512 | ||
13513 | static struct die_info * | |
13514 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
13515 | struct dwarf2_cu **ref_cu) | |
13516 | { | |
13517 | struct objfile *objfile = (*ref_cu)->objfile; | |
13518 | struct die_info temp_die; | |
13519 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
13520 | struct dwarf2_cu *sig_cu; | |
13521 | struct die_info *die; | |
13522 | ||
13523 | /* sig_type will be NULL if the signatured type is missing from | |
13524 | the debug info. */ | |
13525 | if (sig_type == NULL) | |
13526 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
13527 | "at 0x%x [in module %s]"), | |
13528 | src_die->offset, objfile->name); | |
13529 | ||
13530 | /* If necessary, add it to the queue and load its DIEs. */ | |
13531 | ||
13532 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
13533 | read_signatured_type (objfile, sig_type); | |
13534 | ||
13535 | gdb_assert (sig_type->per_cu.cu != NULL); | |
13536 | ||
13537 | sig_cu = sig_type->per_cu.cu; | |
13538 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
13539 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
13540 | if (die) | |
13541 | { | |
13542 | *ref_cu = sig_cu; | |
13543 | return die; | |
13544 | } | |
13545 | ||
3e43a32a MS |
13546 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
13547 | "from DIE at 0x%x [in module %s]"), | |
348e048f DE |
13548 | sig_type->type_offset, src_die->offset, objfile->name); |
13549 | } | |
13550 | ||
13551 | /* Given an offset of a signatured type, return its signatured_type. */ | |
13552 | ||
13553 | static struct signatured_type * | |
13554 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
13555 | { | |
13556 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
13557 | unsigned int length, initial_length_size; | |
13558 | unsigned int sig_offset; | |
13559 | struct signatured_type find_entry, *type_sig; | |
13560 | ||
13561 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
13562 | sig_offset = (initial_length_size | |
13563 | + 2 /*version*/ | |
13564 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
13565 | + 1 /*address_size*/); | |
13566 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
13567 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
13568 | ||
13569 | /* This is only used to lookup previously recorded types. | |
13570 | If we didn't find it, it's our bug. */ | |
13571 | gdb_assert (type_sig != NULL); | |
13572 | gdb_assert (offset == type_sig->offset); | |
13573 | ||
13574 | return type_sig; | |
13575 | } | |
13576 | ||
13577 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
13578 | ||
13579 | static void | |
13580 | read_signatured_type_at_offset (struct objfile *objfile, | |
13581 | unsigned int offset) | |
13582 | { | |
13583 | struct signatured_type *type_sig; | |
13584 | ||
be391dca TT |
13585 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13586 | ||
348e048f DE |
13587 | /* We have the section offset, but we need the signature to do the |
13588 | hash table lookup. */ | |
13589 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
13590 | ||
13591 | gdb_assert (type_sig->per_cu.cu == NULL); | |
13592 | ||
13593 | read_signatured_type (objfile, type_sig); | |
13594 | ||
13595 | gdb_assert (type_sig->per_cu.cu != NULL); | |
13596 | } | |
13597 | ||
13598 | /* Read in a signatured type and build its CU and DIEs. */ | |
13599 | ||
13600 | static void | |
13601 | read_signatured_type (struct objfile *objfile, | |
13602 | struct signatured_type *type_sig) | |
13603 | { | |
1fd400ff | 13604 | gdb_byte *types_ptr; |
348e048f DE |
13605 | struct die_reader_specs reader_specs; |
13606 | struct dwarf2_cu *cu; | |
13607 | ULONGEST signature; | |
13608 | struct cleanup *back_to, *free_cu_cleanup; | |
348e048f | 13609 | |
1fd400ff TT |
13610 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13611 | types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
13612 | ||
348e048f DE |
13613 | gdb_assert (type_sig->per_cu.cu == NULL); |
13614 | ||
9816fde3 JK |
13615 | cu = xmalloc (sizeof (*cu)); |
13616 | init_one_comp_unit (cu, objfile); | |
13617 | ||
348e048f DE |
13618 | type_sig->per_cu.cu = cu; |
13619 | cu->per_cu = &type_sig->per_cu; | |
13620 | ||
13621 | /* If an error occurs while loading, release our storage. */ | |
13622 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
13623 | ||
13624 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
13625 | types_ptr, objfile->obfd); | |
13626 | gdb_assert (signature == type_sig->signature); | |
13627 | ||
13628 | cu->die_hash | |
13629 | = htab_create_alloc_ex (cu->header.length / 12, | |
13630 | die_hash, | |
13631 | die_eq, | |
13632 | NULL, | |
13633 | &cu->comp_unit_obstack, | |
13634 | hashtab_obstack_allocate, | |
13635 | dummy_obstack_deallocate); | |
13636 | ||
13637 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
13638 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
13639 | ||
13640 | init_cu_die_reader (&reader_specs, cu); | |
13641 | ||
13642 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
13643 | NULL /*parent*/); | |
13644 | ||
13645 | /* We try not to read any attributes in this function, because not | |
13646 | all objfiles needed for references have been loaded yet, and symbol | |
13647 | table processing isn't initialized. But we have to set the CU language, | |
13648 | or we won't be able to build types correctly. */ | |
9816fde3 | 13649 | prepare_one_comp_unit (cu, cu->dies); |
348e048f DE |
13650 | |
13651 | do_cleanups (back_to); | |
13652 | ||
13653 | /* We've successfully allocated this compilation unit. Let our caller | |
13654 | clean it up when finished with it. */ | |
13655 | discard_cleanups (free_cu_cleanup); | |
13656 | ||
13657 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
13658 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
13659 | } |
13660 | ||
c906108c SS |
13661 | /* Decode simple location descriptions. |
13662 | Given a pointer to a dwarf block that defines a location, compute | |
13663 | the location and return the value. | |
13664 | ||
4cecd739 DJ |
13665 | NOTE drow/2003-11-18: This function is called in two situations |
13666 | now: for the address of static or global variables (partial symbols | |
13667 | only) and for offsets into structures which are expected to be | |
13668 | (more or less) constant. The partial symbol case should go away, | |
13669 | and only the constant case should remain. That will let this | |
13670 | function complain more accurately. A few special modes are allowed | |
13671 | without complaint for global variables (for instance, global | |
13672 | register values and thread-local values). | |
c906108c SS |
13673 | |
13674 | A location description containing no operations indicates that the | |
4cecd739 | 13675 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
13676 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
13677 | callers will only want a very basic result and this can become a | |
13678 | complaint. | |
c906108c | 13679 | |
d53d4ac5 | 13680 | Note that stack[0] is unused except as a default error return. */ |
c906108c SS |
13681 | |
13682 | static CORE_ADDR | |
e7c27a73 | 13683 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 13684 | { |
e7c27a73 | 13685 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13686 | int i; |
13687 | int size = blk->size; | |
fe1b8b76 | 13688 | gdb_byte *data = blk->data; |
c906108c SS |
13689 | CORE_ADDR stack[64]; |
13690 | int stacki; | |
13691 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 13692 | gdb_byte op; |
c906108c SS |
13693 | |
13694 | i = 0; | |
13695 | stacki = 0; | |
13696 | stack[stacki] = 0; | |
d53d4ac5 | 13697 | stack[++stacki] = 0; |
c906108c SS |
13698 | |
13699 | while (i < size) | |
13700 | { | |
c906108c SS |
13701 | op = data[i++]; |
13702 | switch (op) | |
13703 | { | |
f1bea926 JM |
13704 | case DW_OP_lit0: |
13705 | case DW_OP_lit1: | |
13706 | case DW_OP_lit2: | |
13707 | case DW_OP_lit3: | |
13708 | case DW_OP_lit4: | |
13709 | case DW_OP_lit5: | |
13710 | case DW_OP_lit6: | |
13711 | case DW_OP_lit7: | |
13712 | case DW_OP_lit8: | |
13713 | case DW_OP_lit9: | |
13714 | case DW_OP_lit10: | |
13715 | case DW_OP_lit11: | |
13716 | case DW_OP_lit12: | |
13717 | case DW_OP_lit13: | |
13718 | case DW_OP_lit14: | |
13719 | case DW_OP_lit15: | |
13720 | case DW_OP_lit16: | |
13721 | case DW_OP_lit17: | |
13722 | case DW_OP_lit18: | |
13723 | case DW_OP_lit19: | |
13724 | case DW_OP_lit20: | |
13725 | case DW_OP_lit21: | |
13726 | case DW_OP_lit22: | |
13727 | case DW_OP_lit23: | |
13728 | case DW_OP_lit24: | |
13729 | case DW_OP_lit25: | |
13730 | case DW_OP_lit26: | |
13731 | case DW_OP_lit27: | |
13732 | case DW_OP_lit28: | |
13733 | case DW_OP_lit29: | |
13734 | case DW_OP_lit30: | |
13735 | case DW_OP_lit31: | |
13736 | stack[++stacki] = op - DW_OP_lit0; | |
13737 | break; | |
13738 | ||
c906108c SS |
13739 | case DW_OP_reg0: |
13740 | case DW_OP_reg1: | |
13741 | case DW_OP_reg2: | |
13742 | case DW_OP_reg3: | |
13743 | case DW_OP_reg4: | |
13744 | case DW_OP_reg5: | |
13745 | case DW_OP_reg6: | |
13746 | case DW_OP_reg7: | |
13747 | case DW_OP_reg8: | |
13748 | case DW_OP_reg9: | |
13749 | case DW_OP_reg10: | |
13750 | case DW_OP_reg11: | |
13751 | case DW_OP_reg12: | |
13752 | case DW_OP_reg13: | |
13753 | case DW_OP_reg14: | |
13754 | case DW_OP_reg15: | |
13755 | case DW_OP_reg16: | |
13756 | case DW_OP_reg17: | |
13757 | case DW_OP_reg18: | |
13758 | case DW_OP_reg19: | |
13759 | case DW_OP_reg20: | |
13760 | case DW_OP_reg21: | |
13761 | case DW_OP_reg22: | |
13762 | case DW_OP_reg23: | |
13763 | case DW_OP_reg24: | |
13764 | case DW_OP_reg25: | |
13765 | case DW_OP_reg26: | |
13766 | case DW_OP_reg27: | |
13767 | case DW_OP_reg28: | |
13768 | case DW_OP_reg29: | |
13769 | case DW_OP_reg30: | |
13770 | case DW_OP_reg31: | |
c906108c | 13771 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
13772 | if (i < size) |
13773 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13774 | break; |
13775 | ||
13776 | case DW_OP_regx: | |
c906108c SS |
13777 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
13778 | i += bytes_read; | |
c906108c | 13779 | stack[++stacki] = unsnd; |
4cecd739 DJ |
13780 | if (i < size) |
13781 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13782 | break; |
13783 | ||
13784 | case DW_OP_addr: | |
107d2387 | 13785 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 13786 | cu, &bytes_read); |
107d2387 | 13787 | i += bytes_read; |
c906108c SS |
13788 | break; |
13789 | ||
13790 | case DW_OP_const1u: | |
13791 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
13792 | i += 1; | |
13793 | break; | |
13794 | ||
13795 | case DW_OP_const1s: | |
13796 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
13797 | i += 1; | |
13798 | break; | |
13799 | ||
13800 | case DW_OP_const2u: | |
13801 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
13802 | i += 2; | |
13803 | break; | |
13804 | ||
13805 | case DW_OP_const2s: | |
13806 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
13807 | i += 2; | |
13808 | break; | |
13809 | ||
13810 | case DW_OP_const4u: | |
13811 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
13812 | i += 4; | |
13813 | break; | |
13814 | ||
13815 | case DW_OP_const4s: | |
13816 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
13817 | i += 4; | |
13818 | break; | |
13819 | ||
13820 | case DW_OP_constu: | |
13821 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 13822 | &bytes_read); |
c906108c SS |
13823 | i += bytes_read; |
13824 | break; | |
13825 | ||
13826 | case DW_OP_consts: | |
13827 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
13828 | i += bytes_read; | |
13829 | break; | |
13830 | ||
f1bea926 JM |
13831 | case DW_OP_dup: |
13832 | stack[stacki + 1] = stack[stacki]; | |
13833 | stacki++; | |
13834 | break; | |
13835 | ||
c906108c SS |
13836 | case DW_OP_plus: |
13837 | stack[stacki - 1] += stack[stacki]; | |
13838 | stacki--; | |
13839 | break; | |
13840 | ||
13841 | case DW_OP_plus_uconst: | |
3e43a32a MS |
13842 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), |
13843 | &bytes_read); | |
c906108c SS |
13844 | i += bytes_read; |
13845 | break; | |
13846 | ||
13847 | case DW_OP_minus: | |
f1bea926 | 13848 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
13849 | stacki--; |
13850 | break; | |
13851 | ||
7a292a7a | 13852 | case DW_OP_deref: |
7a292a7a | 13853 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
13854 | this using GDB's address_class enum. This is valid for partial |
13855 | global symbols, although the variable's address will be bogus | |
13856 | in the psymtab. */ | |
7a292a7a | 13857 | if (i < size) |
4d3c2250 | 13858 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
13859 | break; |
13860 | ||
9d774e44 | 13861 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
13862 | /* The top of the stack has the offset from the beginning |
13863 | of the thread control block at which the variable is located. */ | |
13864 | /* Nothing should follow this operator, so the top of stack would | |
13865 | be returned. */ | |
4cecd739 DJ |
13866 | /* This is valid for partial global symbols, but the variable's |
13867 | address will be bogus in the psymtab. */ | |
9d774e44 | 13868 | if (i < size) |
4d3c2250 | 13869 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
13870 | break; |
13871 | ||
42be36b3 CT |
13872 | case DW_OP_GNU_uninit: |
13873 | break; | |
13874 | ||
c906108c | 13875 | default: |
b1bfef65 TT |
13876 | { |
13877 | const char *name = dwarf_stack_op_name (op); | |
13878 | ||
13879 | if (name) | |
13880 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), | |
13881 | name); | |
13882 | else | |
13883 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), | |
13884 | op); | |
13885 | } | |
13886 | ||
c906108c SS |
13887 | return (stack[stacki]); |
13888 | } | |
d53d4ac5 TT |
13889 | |
13890 | /* Enforce maximum stack depth of SIZE-1 to avoid writing | |
13891 | outside of the allocated space. Also enforce minimum>0. */ | |
13892 | if (stacki >= ARRAY_SIZE (stack) - 1) | |
13893 | { | |
13894 | complaint (&symfile_complaints, | |
13895 | _("location description stack overflow")); | |
13896 | return 0; | |
13897 | } | |
13898 | ||
13899 | if (stacki <= 0) | |
13900 | { | |
13901 | complaint (&symfile_complaints, | |
13902 | _("location description stack underflow")); | |
13903 | return 0; | |
13904 | } | |
c906108c SS |
13905 | } |
13906 | return (stack[stacki]); | |
13907 | } | |
13908 | ||
13909 | /* memory allocation interface */ | |
13910 | ||
c906108c | 13911 | static struct dwarf_block * |
7b5a2f43 | 13912 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
13913 | { |
13914 | struct dwarf_block *blk; | |
13915 | ||
13916 | blk = (struct dwarf_block *) | |
7b5a2f43 | 13917 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
13918 | return (blk); |
13919 | } | |
13920 | ||
13921 | static struct abbrev_info * | |
f3dd6933 | 13922 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
13923 | { |
13924 | struct abbrev_info *abbrev; | |
13925 | ||
f3dd6933 DJ |
13926 | abbrev = (struct abbrev_info *) |
13927 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
13928 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
13929 | return (abbrev); | |
13930 | } | |
13931 | ||
13932 | static struct die_info * | |
b60c80d6 | 13933 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
13934 | { |
13935 | struct die_info *die; | |
b60c80d6 DJ |
13936 | size_t size = sizeof (struct die_info); |
13937 | ||
13938 | if (num_attrs > 1) | |
13939 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 13940 | |
b60c80d6 | 13941 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
13942 | memset (die, 0, sizeof (struct die_info)); |
13943 | return (die); | |
13944 | } | |
2e276125 JB |
13945 | |
13946 | \f | |
13947 | /* Macro support. */ | |
13948 | ||
2e276125 JB |
13949 | /* Return the full name of file number I in *LH's file name table. |
13950 | Use COMP_DIR as the name of the current directory of the | |
13951 | compilation. The result is allocated using xmalloc; the caller is | |
13952 | responsible for freeing it. */ | |
13953 | static char * | |
13954 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
13955 | { | |
6a83a1e6 EZ |
13956 | /* Is the file number a valid index into the line header's file name |
13957 | table? Remember that file numbers start with one, not zero. */ | |
13958 | if (1 <= file && file <= lh->num_file_names) | |
13959 | { | |
13960 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 13961 | |
6a83a1e6 EZ |
13962 | if (IS_ABSOLUTE_PATH (fe->name)) |
13963 | return xstrdup (fe->name); | |
13964 | else | |
13965 | { | |
13966 | const char *dir; | |
13967 | int dir_len; | |
13968 | char *full_name; | |
13969 | ||
13970 | if (fe->dir_index) | |
13971 | dir = lh->include_dirs[fe->dir_index - 1]; | |
13972 | else | |
13973 | dir = comp_dir; | |
13974 | ||
13975 | if (dir) | |
13976 | { | |
13977 | dir_len = strlen (dir); | |
13978 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
13979 | strcpy (full_name, dir); | |
13980 | full_name[dir_len] = '/'; | |
13981 | strcpy (full_name + dir_len + 1, fe->name); | |
13982 | return full_name; | |
13983 | } | |
13984 | else | |
13985 | return xstrdup (fe->name); | |
13986 | } | |
13987 | } | |
2e276125 JB |
13988 | else |
13989 | { | |
6a83a1e6 EZ |
13990 | /* The compiler produced a bogus file number. We can at least |
13991 | record the macro definitions made in the file, even if we | |
13992 | won't be able to find the file by name. */ | |
13993 | char fake_name[80]; | |
9a619af0 | 13994 | |
6a83a1e6 | 13995 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 13996 | |
6e70227d | 13997 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
13998 | _("bad file number in macro information (%d)"), |
13999 | file); | |
2e276125 | 14000 | |
6a83a1e6 | 14001 | return xstrdup (fake_name); |
2e276125 JB |
14002 | } |
14003 | } | |
14004 | ||
14005 | ||
14006 | static struct macro_source_file * | |
14007 | macro_start_file (int file, int line, | |
14008 | struct macro_source_file *current_file, | |
14009 | const char *comp_dir, | |
14010 | struct line_header *lh, struct objfile *objfile) | |
14011 | { | |
14012 | /* The full name of this source file. */ | |
14013 | char *full_name = file_full_name (file, lh, comp_dir); | |
14014 | ||
14015 | /* We don't create a macro table for this compilation unit | |
14016 | at all until we actually get a filename. */ | |
14017 | if (! pending_macros) | |
4a146b47 | 14018 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 14019 | objfile->macro_cache); |
2e276125 JB |
14020 | |
14021 | if (! current_file) | |
14022 | /* If we have no current file, then this must be the start_file | |
14023 | directive for the compilation unit's main source file. */ | |
14024 | current_file = macro_set_main (pending_macros, full_name); | |
14025 | else | |
14026 | current_file = macro_include (current_file, line, full_name); | |
14027 | ||
14028 | xfree (full_name); | |
6e70227d | 14029 | |
2e276125 JB |
14030 | return current_file; |
14031 | } | |
14032 | ||
14033 | ||
14034 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
14035 | followed by a null byte. */ | |
14036 | static char * | |
14037 | copy_string (const char *buf, int len) | |
14038 | { | |
14039 | char *s = xmalloc (len + 1); | |
9a619af0 | 14040 | |
2e276125 JB |
14041 | memcpy (s, buf, len); |
14042 | s[len] = '\0'; | |
2e276125 JB |
14043 | return s; |
14044 | } | |
14045 | ||
14046 | ||
14047 | static const char * | |
14048 | consume_improper_spaces (const char *p, const char *body) | |
14049 | { | |
14050 | if (*p == ' ') | |
14051 | { | |
4d3c2250 | 14052 | complaint (&symfile_complaints, |
3e43a32a MS |
14053 | _("macro definition contains spaces " |
14054 | "in formal argument list:\n`%s'"), | |
4d3c2250 | 14055 | body); |
2e276125 JB |
14056 | |
14057 | while (*p == ' ') | |
14058 | p++; | |
14059 | } | |
14060 | ||
14061 | return p; | |
14062 | } | |
14063 | ||
14064 | ||
14065 | static void | |
14066 | parse_macro_definition (struct macro_source_file *file, int line, | |
14067 | const char *body) | |
14068 | { | |
14069 | const char *p; | |
14070 | ||
14071 | /* The body string takes one of two forms. For object-like macro | |
14072 | definitions, it should be: | |
14073 | ||
14074 | <macro name> " " <definition> | |
14075 | ||
14076 | For function-like macro definitions, it should be: | |
14077 | ||
14078 | <macro name> "() " <definition> | |
14079 | or | |
14080 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
14081 | ||
14082 | Spaces may appear only where explicitly indicated, and in the | |
14083 | <definition>. | |
14084 | ||
14085 | The Dwarf 2 spec says that an object-like macro's name is always | |
14086 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 14087 | the space when the macro's definition is the empty string. |
2e276125 JB |
14088 | |
14089 | The Dwarf 2 spec says that there should be no spaces between the | |
14090 | formal arguments in a function-like macro's formal argument list, | |
14091 | but versions of GCC around March 2002 include spaces after the | |
14092 | commas. */ | |
14093 | ||
14094 | ||
14095 | /* Find the extent of the macro name. The macro name is terminated | |
14096 | by either a space or null character (for an object-like macro) or | |
14097 | an opening paren (for a function-like macro). */ | |
14098 | for (p = body; *p; p++) | |
14099 | if (*p == ' ' || *p == '(') | |
14100 | break; | |
14101 | ||
14102 | if (*p == ' ' || *p == '\0') | |
14103 | { | |
14104 | /* It's an object-like macro. */ | |
14105 | int name_len = p - body; | |
14106 | char *name = copy_string (body, name_len); | |
14107 | const char *replacement; | |
14108 | ||
14109 | if (*p == ' ') | |
14110 | replacement = body + name_len + 1; | |
14111 | else | |
14112 | { | |
4d3c2250 | 14113 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14114 | replacement = body + name_len; |
14115 | } | |
6e70227d | 14116 | |
2e276125 JB |
14117 | macro_define_object (file, line, name, replacement); |
14118 | ||
14119 | xfree (name); | |
14120 | } | |
14121 | else if (*p == '(') | |
14122 | { | |
14123 | /* It's a function-like macro. */ | |
14124 | char *name = copy_string (body, p - body); | |
14125 | int argc = 0; | |
14126 | int argv_size = 1; | |
14127 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
14128 | ||
14129 | p++; | |
14130 | ||
14131 | p = consume_improper_spaces (p, body); | |
14132 | ||
14133 | /* Parse the formal argument list. */ | |
14134 | while (*p && *p != ')') | |
14135 | { | |
14136 | /* Find the extent of the current argument name. */ | |
14137 | const char *arg_start = p; | |
14138 | ||
14139 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
14140 | p++; | |
14141 | ||
14142 | if (! *p || p == arg_start) | |
4d3c2250 | 14143 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14144 | else |
14145 | { | |
14146 | /* Make sure argv has room for the new argument. */ | |
14147 | if (argc >= argv_size) | |
14148 | { | |
14149 | argv_size *= 2; | |
14150 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
14151 | } | |
14152 | ||
14153 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
14154 | } | |
14155 | ||
14156 | p = consume_improper_spaces (p, body); | |
14157 | ||
14158 | /* Consume the comma, if present. */ | |
14159 | if (*p == ',') | |
14160 | { | |
14161 | p++; | |
14162 | ||
14163 | p = consume_improper_spaces (p, body); | |
14164 | } | |
14165 | } | |
14166 | ||
14167 | if (*p == ')') | |
14168 | { | |
14169 | p++; | |
14170 | ||
14171 | if (*p == ' ') | |
14172 | /* Perfectly formed definition, no complaints. */ | |
14173 | macro_define_function (file, line, name, | |
6e70227d | 14174 | argc, (const char **) argv, |
2e276125 JB |
14175 | p + 1); |
14176 | else if (*p == '\0') | |
14177 | { | |
14178 | /* Complain, but do define it. */ | |
4d3c2250 | 14179 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 14180 | macro_define_function (file, line, name, |
6e70227d | 14181 | argc, (const char **) argv, |
2e276125 JB |
14182 | p); |
14183 | } | |
14184 | else | |
14185 | /* Just complain. */ | |
4d3c2250 | 14186 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14187 | } |
14188 | else | |
14189 | /* Just complain. */ | |
4d3c2250 | 14190 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14191 | |
14192 | xfree (name); | |
14193 | { | |
14194 | int i; | |
14195 | ||
14196 | for (i = 0; i < argc; i++) | |
14197 | xfree (argv[i]); | |
14198 | } | |
14199 | xfree (argv); | |
14200 | } | |
14201 | else | |
4d3c2250 | 14202 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
14203 | } |
14204 | ||
14205 | ||
14206 | static void | |
14207 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
14208 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 14209 | struct dwarf2_cu *cu) |
2e276125 | 14210 | { |
fe1b8b76 | 14211 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 14212 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
14213 | enum dwarf_macinfo_record_type macinfo_type; |
14214 | int at_commandline; | |
2e276125 | 14215 | |
be391dca TT |
14216 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
14217 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 14218 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 14219 | { |
e2e0b3e5 | 14220 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
14221 | return; |
14222 | } | |
14223 | ||
757a13d0 JK |
14224 | /* First pass: Find the name of the base filename. |
14225 | This filename is needed in order to process all macros whose definition | |
14226 | (or undefinition) comes from the command line. These macros are defined | |
14227 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
14228 | associated to the base file. | |
14229 | ||
14230 | To determine the base file name, we scan the macro definitions until we | |
14231 | reach the first DW_MACINFO_start_file entry. We then initialize | |
14232 | CURRENT_FILE accordingly so that any macro definition found before the | |
14233 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
14234 | ||
dce234bc PP |
14235 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
14236 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
14237 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 14238 | |
757a13d0 | 14239 | do |
2e276125 | 14240 | { |
2e276125 JB |
14241 | /* Do we at least have room for a macinfo type byte? */ |
14242 | if (mac_ptr >= mac_end) | |
14243 | { | |
757a13d0 | 14244 | /* Complaint is printed during the second pass as GDB will probably |
3e43a32a MS |
14245 | stop the first pass earlier upon finding |
14246 | DW_MACINFO_start_file. */ | |
757a13d0 | 14247 | break; |
2e276125 JB |
14248 | } |
14249 | ||
14250 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
14251 | mac_ptr++; | |
14252 | ||
14253 | switch (macinfo_type) | |
14254 | { | |
14255 | /* A zero macinfo type indicates the end of the macro | |
14256 | information. */ | |
14257 | case 0: | |
757a13d0 JK |
14258 | break; |
14259 | ||
14260 | case DW_MACINFO_define: | |
14261 | case DW_MACINFO_undef: | |
14262 | /* Only skip the data by MAC_PTR. */ | |
14263 | { | |
14264 | unsigned int bytes_read; | |
14265 | ||
14266 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14267 | mac_ptr += bytes_read; | |
9b1c24c8 | 14268 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
14269 | mac_ptr += bytes_read; |
14270 | } | |
14271 | break; | |
14272 | ||
14273 | case DW_MACINFO_start_file: | |
14274 | { | |
14275 | unsigned int bytes_read; | |
14276 | int line, file; | |
14277 | ||
14278 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14279 | mac_ptr += bytes_read; | |
14280 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14281 | mac_ptr += bytes_read; | |
14282 | ||
3e43a32a MS |
14283 | current_file = macro_start_file (file, line, current_file, |
14284 | comp_dir, lh, cu->objfile); | |
757a13d0 JK |
14285 | } |
14286 | break; | |
14287 | ||
14288 | case DW_MACINFO_end_file: | |
14289 | /* No data to skip by MAC_PTR. */ | |
14290 | break; | |
14291 | ||
14292 | case DW_MACINFO_vendor_ext: | |
14293 | /* Only skip the data by MAC_PTR. */ | |
14294 | { | |
14295 | unsigned int bytes_read; | |
14296 | ||
14297 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14298 | mac_ptr += bytes_read; | |
9b1c24c8 | 14299 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
14300 | mac_ptr += bytes_read; |
14301 | } | |
14302 | break; | |
14303 | ||
14304 | default: | |
14305 | break; | |
14306 | } | |
14307 | } while (macinfo_type != 0 && current_file == NULL); | |
14308 | ||
14309 | /* Second pass: Process all entries. | |
14310 | ||
14311 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
14312 | command-line macro definitions/undefinitions. This flag is unset when we | |
14313 | reach the first DW_MACINFO_start_file entry. */ | |
14314 | ||
dce234bc | 14315 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
14316 | |
14317 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
14318 | GDB is still reading the definitions from command line. First | |
14319 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
14320 | to create CURRENT_FILE for the main source holding also the command line | |
14321 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
14322 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
14323 | ||
14324 | at_commandline = 1; | |
14325 | ||
14326 | do | |
14327 | { | |
14328 | /* Do we at least have room for a macinfo type byte? */ | |
14329 | if (mac_ptr >= mac_end) | |
14330 | { | |
14331 | dwarf2_macros_too_long_complaint (); | |
14332 | break; | |
14333 | } | |
14334 | ||
14335 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
14336 | mac_ptr++; | |
14337 | ||
14338 | switch (macinfo_type) | |
14339 | { | |
14340 | /* A zero macinfo type indicates the end of the macro | |
14341 | information. */ | |
14342 | case 0: | |
14343 | break; | |
2e276125 JB |
14344 | |
14345 | case DW_MACINFO_define: | |
14346 | case DW_MACINFO_undef: | |
14347 | { | |
891d2f0b | 14348 | unsigned int bytes_read; |
2e276125 JB |
14349 | int line; |
14350 | char *body; | |
14351 | ||
14352 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14353 | mac_ptr += bytes_read; | |
9b1c24c8 | 14354 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
14355 | mac_ptr += bytes_read; |
14356 | ||
14357 | if (! current_file) | |
757a13d0 JK |
14358 | { |
14359 | /* DWARF violation as no main source is present. */ | |
14360 | complaint (&symfile_complaints, | |
14361 | _("debug info with no main source gives macro %s " | |
14362 | "on line %d: %s"), | |
6e70227d DE |
14363 | macinfo_type == DW_MACINFO_define ? |
14364 | _("definition") : | |
905e0470 PM |
14365 | macinfo_type == DW_MACINFO_undef ? |
14366 | _("undefinition") : | |
14367 | _("something-or-other"), line, body); | |
757a13d0 JK |
14368 | break; |
14369 | } | |
3e43a32a MS |
14370 | if ((line == 0 && !at_commandline) |
14371 | || (line != 0 && at_commandline)) | |
4d3c2250 | 14372 | complaint (&symfile_complaints, |
757a13d0 JK |
14373 | _("debug info gives %s macro %s with %s line %d: %s"), |
14374 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 14375 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 14376 | _("definition") : |
905e0470 PM |
14377 | macinfo_type == DW_MACINFO_undef ? |
14378 | _("undefinition") : | |
14379 | _("something-or-other"), | |
757a13d0 JK |
14380 | line == 0 ? _("zero") : _("non-zero"), line, body); |
14381 | ||
14382 | if (macinfo_type == DW_MACINFO_define) | |
14383 | parse_macro_definition (current_file, line, body); | |
14384 | else if (macinfo_type == DW_MACINFO_undef) | |
14385 | macro_undef (current_file, line, body); | |
2e276125 JB |
14386 | } |
14387 | break; | |
14388 | ||
14389 | case DW_MACINFO_start_file: | |
14390 | { | |
891d2f0b | 14391 | unsigned int bytes_read; |
2e276125 JB |
14392 | int line, file; |
14393 | ||
14394 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14395 | mac_ptr += bytes_read; | |
14396 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14397 | mac_ptr += bytes_read; | |
14398 | ||
3e43a32a MS |
14399 | if ((line == 0 && !at_commandline) |
14400 | || (line != 0 && at_commandline)) | |
757a13d0 JK |
14401 | complaint (&symfile_complaints, |
14402 | _("debug info gives source %d included " | |
14403 | "from %s at %s line %d"), | |
14404 | file, at_commandline ? _("command-line") : _("file"), | |
14405 | line == 0 ? _("zero") : _("non-zero"), line); | |
14406 | ||
14407 | if (at_commandline) | |
14408 | { | |
14409 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
14410 | at_commandline = 0; | |
14411 | } | |
14412 | else | |
14413 | current_file = macro_start_file (file, line, | |
14414 | current_file, comp_dir, | |
14415 | lh, cu->objfile); | |
2e276125 JB |
14416 | } |
14417 | break; | |
14418 | ||
14419 | case DW_MACINFO_end_file: | |
14420 | if (! current_file) | |
4d3c2250 | 14421 | complaint (&symfile_complaints, |
3e43a32a MS |
14422 | _("macro debug info has an unmatched " |
14423 | "`close_file' directive")); | |
2e276125 JB |
14424 | else |
14425 | { | |
14426 | current_file = current_file->included_by; | |
14427 | if (! current_file) | |
14428 | { | |
14429 | enum dwarf_macinfo_record_type next_type; | |
14430 | ||
14431 | /* GCC circa March 2002 doesn't produce the zero | |
14432 | type byte marking the end of the compilation | |
14433 | unit. Complain if it's not there, but exit no | |
14434 | matter what. */ | |
14435 | ||
14436 | /* Do we at least have room for a macinfo type byte? */ | |
14437 | if (mac_ptr >= mac_end) | |
14438 | { | |
4d3c2250 | 14439 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
14440 | return; |
14441 | } | |
14442 | ||
14443 | /* We don't increment mac_ptr here, so this is just | |
14444 | a look-ahead. */ | |
14445 | next_type = read_1_byte (abfd, mac_ptr); | |
14446 | if (next_type != 0) | |
4d3c2250 | 14447 | complaint (&symfile_complaints, |
3e43a32a MS |
14448 | _("no terminating 0-type entry for " |
14449 | "macros in `.debug_macinfo' section")); | |
2e276125 JB |
14450 | |
14451 | return; | |
14452 | } | |
14453 | } | |
14454 | break; | |
14455 | ||
14456 | case DW_MACINFO_vendor_ext: | |
14457 | { | |
891d2f0b | 14458 | unsigned int bytes_read; |
2e276125 | 14459 | int constant; |
2e276125 JB |
14460 | |
14461 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
14462 | mac_ptr += bytes_read; | |
e8e80198 | 14463 | read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
14464 | mac_ptr += bytes_read; |
14465 | ||
14466 | /* We don't recognize any vendor extensions. */ | |
14467 | } | |
14468 | break; | |
14469 | } | |
757a13d0 | 14470 | } while (macinfo_type != 0); |
2e276125 | 14471 | } |
8e19ed76 PS |
14472 | |
14473 | /* Check if the attribute's form is a DW_FORM_block* | |
0963b4bd | 14474 | if so return true else false. */ |
8e19ed76 PS |
14475 | static int |
14476 | attr_form_is_block (struct attribute *attr) | |
14477 | { | |
14478 | return (attr == NULL ? 0 : | |
14479 | attr->form == DW_FORM_block1 | |
14480 | || attr->form == DW_FORM_block2 | |
14481 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
14482 | || attr->form == DW_FORM_block |
14483 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 14484 | } |
4c2df51b | 14485 | |
c6a0999f JB |
14486 | /* Return non-zero if ATTR's value is a section offset --- classes |
14487 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
14488 | You may use DW_UNSND (attr) to retrieve such offsets. | |
14489 | ||
14490 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
14491 | may have a value that belongs to more than one of these classes; it | |
14492 | would be ambiguous if we did, because we use the same forms for all | |
14493 | of them. */ | |
3690dd37 JB |
14494 | static int |
14495 | attr_form_is_section_offset (struct attribute *attr) | |
14496 | { | |
14497 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
14498 | || attr->form == DW_FORM_data8 |
14499 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
14500 | } |
14501 | ||
14502 | ||
14503 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
14504 | zero otherwise. When this function returns true, you can apply | |
14505 | dwarf2_get_attr_constant_value to it. | |
14506 | ||
14507 | However, note that for some attributes you must check | |
14508 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
14509 | and DW_FORM_data8 are members of both the constant class, and of | |
14510 | the classes that contain offsets into other debug sections | |
14511 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
14512 | that, if an attribute's can be either a constant or one of the | |
14513 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
14514 | taken as section offsets, not constants. */ | |
14515 | static int | |
14516 | attr_form_is_constant (struct attribute *attr) | |
14517 | { | |
14518 | switch (attr->form) | |
14519 | { | |
14520 | case DW_FORM_sdata: | |
14521 | case DW_FORM_udata: | |
14522 | case DW_FORM_data1: | |
14523 | case DW_FORM_data2: | |
14524 | case DW_FORM_data4: | |
14525 | case DW_FORM_data8: | |
14526 | return 1; | |
14527 | default: | |
14528 | return 0; | |
14529 | } | |
14530 | } | |
14531 | ||
8cf6f0b1 TT |
14532 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
14533 | ||
14534 | static void | |
14535 | fill_in_loclist_baton (struct dwarf2_cu *cu, | |
14536 | struct dwarf2_loclist_baton *baton, | |
14537 | struct attribute *attr) | |
14538 | { | |
14539 | dwarf2_read_section (dwarf2_per_objfile->objfile, | |
14540 | &dwarf2_per_objfile->loc); | |
14541 | ||
14542 | baton->per_cu = cu->per_cu; | |
14543 | gdb_assert (baton->per_cu); | |
14544 | /* We don't know how long the location list is, but make sure we | |
14545 | don't run off the edge of the section. */ | |
14546 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); | |
14547 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
14548 | baton->base_address = cu->base_address; | |
14549 | } | |
14550 | ||
4c2df51b DJ |
14551 | static void |
14552 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 14553 | struct dwarf2_cu *cu) |
4c2df51b | 14554 | { |
3690dd37 | 14555 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
14556 | /* ".debug_loc" may not exist at all, or the offset may be outside |
14557 | the section. If so, fall through to the complaint in the | |
14558 | other branch. */ | |
9e0ac564 TT |
14559 | && DW_UNSND (attr) < dwarf2_section_size (dwarf2_per_objfile->objfile, |
14560 | &dwarf2_per_objfile->loc)) | |
4c2df51b | 14561 | { |
0d53c4c4 | 14562 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 14563 | |
4a146b47 | 14564 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 14565 | sizeof (struct dwarf2_loclist_baton)); |
4c2df51b | 14566 | |
8cf6f0b1 | 14567 | fill_in_loclist_baton (cu, baton, attr); |
be391dca | 14568 | |
d00adf39 | 14569 | if (cu->base_known == 0) |
0d53c4c4 | 14570 | complaint (&symfile_complaints, |
3e43a32a MS |
14571 | _("Location list used without " |
14572 | "specifying the CU base address.")); | |
4c2df51b | 14573 | |
768a979c | 14574 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
14575 | SYMBOL_LOCATION_BATON (sym) = baton; |
14576 | } | |
14577 | else | |
14578 | { | |
14579 | struct dwarf2_locexpr_baton *baton; | |
14580 | ||
4a146b47 | 14581 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 14582 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
14583 | baton->per_cu = cu->per_cu; |
14584 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
14585 | |
14586 | if (attr_form_is_block (attr)) | |
14587 | { | |
14588 | /* Note that we're just copying the block's data pointer | |
14589 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
14590 | info_buffer for SYM's objfile; right now we never release |
14591 | that buffer, but when we do clean up properly this may | |
14592 | need to change. */ | |
0d53c4c4 DJ |
14593 | baton->size = DW_BLOCK (attr)->size; |
14594 | baton->data = DW_BLOCK (attr)->data; | |
14595 | } | |
14596 | else | |
14597 | { | |
14598 | dwarf2_invalid_attrib_class_complaint ("location description", | |
14599 | SYMBOL_NATURAL_NAME (sym)); | |
14600 | baton->size = 0; | |
14601 | baton->data = NULL; | |
14602 | } | |
6e70227d | 14603 | |
768a979c | 14604 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
14605 | SYMBOL_LOCATION_BATON (sym) = baton; |
14606 | } | |
4c2df51b | 14607 | } |
6502dd73 | 14608 | |
9aa1f1e3 TT |
14609 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
14610 | came from a separate debuginfo file, then the master objfile is | |
14611 | returned. */ | |
ae0d2f24 UW |
14612 | |
14613 | struct objfile * | |
14614 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
14615 | { | |
9291a0cd | 14616 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14617 | |
14618 | /* Return the master objfile, so that we can report and look up the | |
14619 | correct file containing this variable. */ | |
14620 | if (objfile->separate_debug_objfile_backlink) | |
14621 | objfile = objfile->separate_debug_objfile_backlink; | |
14622 | ||
14623 | return objfile; | |
14624 | } | |
14625 | ||
14626 | /* Return the address size given in the compilation unit header for CU. */ | |
14627 | ||
14628 | CORE_ADDR | |
14629 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
14630 | { | |
14631 | if (per_cu->cu) | |
14632 | return per_cu->cu->header.addr_size; | |
14633 | else | |
14634 | { | |
14635 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14636 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14637 | struct dwarf2_per_objfile *per_objfile |
14638 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 14639 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 14640 | struct comp_unit_head cu_header; |
9a619af0 | 14641 | |
ae0d2f24 UW |
14642 | memset (&cu_header, 0, sizeof cu_header); |
14643 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14644 | return cu_header.addr_size; | |
14645 | } | |
14646 | } | |
14647 | ||
9eae7c52 TT |
14648 | /* Return the offset size given in the compilation unit header for CU. */ |
14649 | ||
14650 | int | |
14651 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
14652 | { | |
14653 | if (per_cu->cu) | |
14654 | return per_cu->cu->header.offset_size; | |
14655 | else | |
14656 | { | |
14657 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14658 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
14659 | struct dwarf2_per_objfile *per_objfile |
14660 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
14661 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
14662 | struct comp_unit_head cu_header; | |
14663 | ||
14664 | memset (&cu_header, 0, sizeof cu_header); | |
14665 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14666 | return cu_header.offset_size; | |
14667 | } | |
14668 | } | |
14669 | ||
9aa1f1e3 TT |
14670 | /* Return the text offset of the CU. The returned offset comes from |
14671 | this CU's objfile. If this objfile came from a separate debuginfo | |
14672 | file, then the offset may be different from the corresponding | |
14673 | offset in the parent objfile. */ | |
14674 | ||
14675 | CORE_ADDR | |
14676 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
14677 | { | |
bb3fa9d0 | 14678 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
14679 | |
14680 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
14681 | } | |
14682 | ||
348e048f DE |
14683 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
14684 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
14685 | |
14686 | static struct dwarf2_per_cu_data * | |
c764a876 | 14687 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
14688 | struct objfile *objfile) |
14689 | { | |
14690 | struct dwarf2_per_cu_data *this_cu; | |
14691 | int low, high; | |
14692 | ||
ae038cb0 DJ |
14693 | low = 0; |
14694 | high = dwarf2_per_objfile->n_comp_units - 1; | |
14695 | while (high > low) | |
14696 | { | |
14697 | int mid = low + (high - low) / 2; | |
9a619af0 | 14698 | |
ae038cb0 DJ |
14699 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
14700 | high = mid; | |
14701 | else | |
14702 | low = mid + 1; | |
14703 | } | |
14704 | gdb_assert (low == high); | |
14705 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
14706 | { | |
10b3939b | 14707 | if (low == 0) |
8a3fe4f8 AC |
14708 | error (_("Dwarf Error: could not find partial DIE containing " |
14709 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
14710 | (long) offset, bfd_get_filename (objfile->obfd)); |
14711 | ||
ae038cb0 DJ |
14712 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
14713 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
14714 | } | |
14715 | else | |
14716 | { | |
14717 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
14718 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
14719 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 14720 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
14721 | gdb_assert (offset < this_cu->offset + this_cu->length); |
14722 | return this_cu; | |
14723 | } | |
14724 | } | |
14725 | ||
10b3939b DJ |
14726 | /* Locate the compilation unit from OBJFILE which is located at exactly |
14727 | OFFSET. Raises an error on failure. */ | |
14728 | ||
ae038cb0 | 14729 | static struct dwarf2_per_cu_data * |
c764a876 | 14730 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
14731 | { |
14732 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 14733 | |
ae038cb0 DJ |
14734 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
14735 | if (this_cu->offset != offset) | |
c764a876 | 14736 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
14737 | return this_cu; |
14738 | } | |
14739 | ||
9816fde3 | 14740 | /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */ |
93311388 | 14741 | |
9816fde3 JK |
14742 | static void |
14743 | init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile) | |
93311388 | 14744 | { |
9816fde3 | 14745 | memset (cu, 0, sizeof (*cu)); |
93311388 DE |
14746 | cu->objfile = objfile; |
14747 | obstack_init (&cu->comp_unit_obstack); | |
9816fde3 JK |
14748 | } |
14749 | ||
14750 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ | |
14751 | ||
14752 | static void | |
14753 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) | |
14754 | { | |
14755 | struct attribute *attr; | |
14756 | ||
14757 | /* Set the language we're debugging. */ | |
14758 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); | |
14759 | if (attr) | |
14760 | set_cu_language (DW_UNSND (attr), cu); | |
14761 | else | |
9cded63f TT |
14762 | { |
14763 | cu->language = language_minimal; | |
14764 | cu->language_defn = language_def (cu->language); | |
14765 | } | |
93311388 DE |
14766 | } |
14767 | ||
ae038cb0 DJ |
14768 | /* Release one cached compilation unit, CU. We unlink it from the tree |
14769 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
14770 | the caller is responsible for that. |
14771 | NOTE: DATA is a void * because this function is also used as a | |
14772 | cleanup routine. */ | |
ae038cb0 DJ |
14773 | |
14774 | static void | |
14775 | free_one_comp_unit (void *data) | |
14776 | { | |
14777 | struct dwarf2_cu *cu = data; | |
14778 | ||
14779 | if (cu->per_cu != NULL) | |
14780 | cu->per_cu->cu = NULL; | |
14781 | cu->per_cu = NULL; | |
14782 | ||
14783 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14784 | ||
14785 | xfree (cu); | |
14786 | } | |
14787 | ||
72bf9492 | 14788 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
14789 | when we're finished with it. We can't free the pointer itself, but be |
14790 | sure to unlink it from the cache. Also release any associated storage | |
14791 | and perform cache maintenance. | |
72bf9492 DJ |
14792 | |
14793 | Only used during partial symbol parsing. */ | |
14794 | ||
14795 | static void | |
14796 | free_stack_comp_unit (void *data) | |
14797 | { | |
14798 | struct dwarf2_cu *cu = data; | |
14799 | ||
14800 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14801 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
14802 | |
14803 | if (cu->per_cu != NULL) | |
14804 | { | |
14805 | /* This compilation unit is on the stack in our caller, so we | |
14806 | should not xfree it. Just unlink it. */ | |
14807 | cu->per_cu->cu = NULL; | |
14808 | cu->per_cu = NULL; | |
14809 | ||
14810 | /* If we had a per-cu pointer, then we may have other compilation | |
14811 | units loaded, so age them now. */ | |
14812 | age_cached_comp_units (); | |
14813 | } | |
14814 | } | |
14815 | ||
14816 | /* Free all cached compilation units. */ | |
14817 | ||
14818 | static void | |
14819 | free_cached_comp_units (void *data) | |
14820 | { | |
14821 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14822 | ||
14823 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14824 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14825 | while (per_cu != NULL) | |
14826 | { | |
14827 | struct dwarf2_per_cu_data *next_cu; | |
14828 | ||
14829 | next_cu = per_cu->cu->read_in_chain; | |
14830 | ||
14831 | free_one_comp_unit (per_cu->cu); | |
14832 | *last_chain = next_cu; | |
14833 | ||
14834 | per_cu = next_cu; | |
14835 | } | |
14836 | } | |
14837 | ||
14838 | /* Increase the age counter on each cached compilation unit, and free | |
14839 | any that are too old. */ | |
14840 | ||
14841 | static void | |
14842 | age_cached_comp_units (void) | |
14843 | { | |
14844 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14845 | ||
14846 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
14847 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14848 | while (per_cu != NULL) | |
14849 | { | |
14850 | per_cu->cu->last_used ++; | |
14851 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
14852 | dwarf2_mark (per_cu->cu); | |
14853 | per_cu = per_cu->cu->read_in_chain; | |
14854 | } | |
14855 | ||
14856 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14857 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14858 | while (per_cu != NULL) | |
14859 | { | |
14860 | struct dwarf2_per_cu_data *next_cu; | |
14861 | ||
14862 | next_cu = per_cu->cu->read_in_chain; | |
14863 | ||
14864 | if (!per_cu->cu->mark) | |
14865 | { | |
14866 | free_one_comp_unit (per_cu->cu); | |
14867 | *last_chain = next_cu; | |
14868 | } | |
14869 | else | |
14870 | last_chain = &per_cu->cu->read_in_chain; | |
14871 | ||
14872 | per_cu = next_cu; | |
14873 | } | |
14874 | } | |
14875 | ||
14876 | /* Remove a single compilation unit from the cache. */ | |
14877 | ||
14878 | static void | |
14879 | free_one_cached_comp_unit (void *target_cu) | |
14880 | { | |
14881 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14882 | ||
14883 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14884 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14885 | while (per_cu != NULL) | |
14886 | { | |
14887 | struct dwarf2_per_cu_data *next_cu; | |
14888 | ||
14889 | next_cu = per_cu->cu->read_in_chain; | |
14890 | ||
14891 | if (per_cu->cu == target_cu) | |
14892 | { | |
14893 | free_one_comp_unit (per_cu->cu); | |
14894 | *last_chain = next_cu; | |
14895 | break; | |
14896 | } | |
14897 | else | |
14898 | last_chain = &per_cu->cu->read_in_chain; | |
14899 | ||
14900 | per_cu = next_cu; | |
14901 | } | |
14902 | } | |
14903 | ||
fe3e1990 DJ |
14904 | /* Release all extra memory associated with OBJFILE. */ |
14905 | ||
14906 | void | |
14907 | dwarf2_free_objfile (struct objfile *objfile) | |
14908 | { | |
14909 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
14910 | ||
14911 | if (dwarf2_per_objfile == NULL) | |
14912 | return; | |
14913 | ||
14914 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
14915 | free_cached_comp_units (NULL); | |
14916 | ||
7b9f3c50 DE |
14917 | if (dwarf2_per_objfile->quick_file_names_table) |
14918 | htab_delete (dwarf2_per_objfile->quick_file_names_table); | |
9291a0cd | 14919 | |
fe3e1990 DJ |
14920 | /* Everything else should be on the objfile obstack. */ |
14921 | } | |
14922 | ||
1c379e20 DJ |
14923 | /* A pair of DIE offset and GDB type pointer. We store these |
14924 | in a hash table separate from the DIEs, and preserve them | |
14925 | when the DIEs are flushed out of cache. */ | |
14926 | ||
14927 | struct dwarf2_offset_and_type | |
14928 | { | |
14929 | unsigned int offset; | |
14930 | struct type *type; | |
14931 | }; | |
14932 | ||
14933 | /* Hash function for a dwarf2_offset_and_type. */ | |
14934 | ||
14935 | static hashval_t | |
14936 | offset_and_type_hash (const void *item) | |
14937 | { | |
14938 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 14939 | |
1c379e20 DJ |
14940 | return ofs->offset; |
14941 | } | |
14942 | ||
14943 | /* Equality function for a dwarf2_offset_and_type. */ | |
14944 | ||
14945 | static int | |
14946 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
14947 | { | |
14948 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
14949 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 14950 | |
1c379e20 DJ |
14951 | return ofs_lhs->offset == ofs_rhs->offset; |
14952 | } | |
14953 | ||
14954 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
14955 | table if necessary. For convenience, return TYPE. |
14956 | ||
14957 | The DIEs reading must have careful ordering to: | |
14958 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
14959 | reading current DIE. | |
14960 | * Not trying to dereference contents of still incompletely read in types | |
14961 | while reading in other DIEs. | |
14962 | * Enable referencing still incompletely read in types just by a pointer to | |
14963 | the type without accessing its fields. | |
14964 | ||
14965 | Therefore caller should follow these rules: | |
14966 | * Try to fetch any prerequisite types we may need to build this DIE type | |
14967 | before building the type and calling set_die_type. | |
e71ec853 | 14968 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
14969 | possible before fetching more types to complete the current type. |
14970 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 14971 | |
f792889a | 14972 | static struct type * |
1c379e20 DJ |
14973 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
14974 | { | |
14975 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
14976 | struct objfile *objfile = cu->objfile; |
14977 | htab_t *type_hash_ptr; | |
1c379e20 | 14978 | |
b4ba55a1 JB |
14979 | /* For Ada types, make sure that the gnat-specific data is always |
14980 | initialized (if not already set). There are a few types where | |
14981 | we should not be doing so, because the type-specific area is | |
14982 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
14983 | where the type-specific area is used to store the floatformat). | |
14984 | But this is not a problem, because the gnat-specific information | |
14985 | is actually not needed for these types. */ | |
14986 | if (need_gnat_info (cu) | |
14987 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
14988 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
14989 | && !HAVE_GNAT_AUX_INFO (type)) | |
14990 | INIT_GNAT_SPECIFIC (type); | |
14991 | ||
673bfd45 DE |
14992 | if (cu->per_cu->from_debug_types) |
14993 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; | |
14994 | else | |
14995 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
14996 | ||
14997 | if (*type_hash_ptr == NULL) | |
f792889a | 14998 | { |
673bfd45 DE |
14999 | *type_hash_ptr |
15000 | = htab_create_alloc_ex (127, | |
f792889a DJ |
15001 | offset_and_type_hash, |
15002 | offset_and_type_eq, | |
15003 | NULL, | |
673bfd45 | 15004 | &objfile->objfile_obstack, |
f792889a DJ |
15005 | hashtab_obstack_allocate, |
15006 | dummy_obstack_deallocate); | |
f792889a | 15007 | } |
1c379e20 DJ |
15008 | |
15009 | ofs.offset = die->offset; | |
15010 | ofs.type = type; | |
15011 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 15012 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
15013 | if (*slot) |
15014 | complaint (&symfile_complaints, | |
15015 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
15016 | die->offset); | |
673bfd45 | 15017 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 15018 | **slot = ofs; |
f792889a | 15019 | return type; |
1c379e20 DJ |
15020 | } |
15021 | ||
673bfd45 DE |
15022 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
15023 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
15024 | |
15025 | static struct type * | |
673bfd45 DE |
15026 | get_die_type_at_offset (unsigned int offset, |
15027 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
15028 | { |
15029 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 15030 | htab_t type_hash; |
f792889a | 15031 | |
673bfd45 DE |
15032 | if (per_cu->from_debug_types) |
15033 | type_hash = dwarf2_per_objfile->debug_types_type_hash; | |
15034 | else | |
15035 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
15036 | if (type_hash == NULL) |
15037 | return NULL; | |
1c379e20 | 15038 | |
673bfd45 | 15039 | ofs.offset = offset; |
1c379e20 DJ |
15040 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
15041 | if (slot) | |
15042 | return slot->type; | |
15043 | else | |
15044 | return NULL; | |
15045 | } | |
15046 | ||
673bfd45 DE |
15047 | /* Look up the type for DIE in the appropriate type_hash table, |
15048 | or return NULL if DIE does not have a saved type. */ | |
15049 | ||
15050 | static struct type * | |
15051 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
15052 | { | |
15053 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
15054 | } | |
15055 | ||
10b3939b DJ |
15056 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
15057 | ||
15058 | static void | |
15059 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
15060 | struct dwarf2_per_cu_data *ref_per_cu) | |
15061 | { | |
15062 | void **slot; | |
15063 | ||
15064 | if (cu->dependencies == NULL) | |
15065 | cu->dependencies | |
15066 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
15067 | NULL, &cu->comp_unit_obstack, | |
15068 | hashtab_obstack_allocate, | |
15069 | dummy_obstack_deallocate); | |
15070 | ||
15071 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
15072 | if (*slot == NULL) | |
15073 | *slot = ref_per_cu; | |
15074 | } | |
1c379e20 | 15075 | |
f504f079 DE |
15076 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
15077 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
15078 | cache that we must keep because we are keeping CU. */ |
15079 | ||
10b3939b DJ |
15080 | static int |
15081 | dwarf2_mark_helper (void **slot, void *data) | |
15082 | { | |
15083 | struct dwarf2_per_cu_data *per_cu; | |
15084 | ||
15085 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
15086 | if (per_cu->cu->mark) | |
15087 | return 1; | |
15088 | per_cu->cu->mark = 1; | |
15089 | ||
15090 | if (per_cu->cu->dependencies != NULL) | |
15091 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
15092 | ||
15093 | return 1; | |
15094 | } | |
15095 | ||
f504f079 DE |
15096 | /* Set the mark field in CU and in every other compilation unit in the |
15097 | cache that we must keep because we are keeping CU. */ | |
15098 | ||
ae038cb0 DJ |
15099 | static void |
15100 | dwarf2_mark (struct dwarf2_cu *cu) | |
15101 | { | |
15102 | if (cu->mark) | |
15103 | return; | |
15104 | cu->mark = 1; | |
10b3939b DJ |
15105 | if (cu->dependencies != NULL) |
15106 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
15107 | } |
15108 | ||
15109 | static void | |
15110 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
15111 | { | |
15112 | while (per_cu) | |
15113 | { | |
15114 | per_cu->cu->mark = 0; | |
15115 | per_cu = per_cu->cu->read_in_chain; | |
15116 | } | |
72bf9492 DJ |
15117 | } |
15118 | ||
72bf9492 DJ |
15119 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
15120 | is its offset in .debug_info for this objfile. */ | |
15121 | ||
15122 | static hashval_t | |
15123 | partial_die_hash (const void *item) | |
15124 | { | |
15125 | const struct partial_die_info *part_die = item; | |
9a619af0 | 15126 | |
72bf9492 DJ |
15127 | return part_die->offset; |
15128 | } | |
15129 | ||
15130 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
15131 | are equal if they have the same offset. */ | |
15132 | ||
15133 | static int | |
15134 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
15135 | { | |
15136 | const struct partial_die_info *part_die_lhs = item_lhs; | |
15137 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 15138 | |
72bf9492 DJ |
15139 | return part_die_lhs->offset == part_die_rhs->offset; |
15140 | } | |
15141 | ||
ae038cb0 DJ |
15142 | static struct cmd_list_element *set_dwarf2_cmdlist; |
15143 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
15144 | ||
15145 | static void | |
15146 | set_dwarf2_cmd (char *args, int from_tty) | |
15147 | { | |
15148 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
15149 | } | |
15150 | ||
15151 | static void | |
15152 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 15153 | { |
ae038cb0 DJ |
15154 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
15155 | } | |
15156 | ||
dce234bc PP |
15157 | /* If section described by INFO was mmapped, munmap it now. */ |
15158 | ||
15159 | static void | |
15160 | munmap_section_buffer (struct dwarf2_section_info *info) | |
15161 | { | |
15162 | if (info->was_mmapped) | |
15163 | { | |
15164 | #ifdef HAVE_MMAP | |
15165 | intptr_t begin = (intptr_t) info->buffer; | |
15166 | intptr_t map_begin = begin & ~(pagesize - 1); | |
15167 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 15168 | |
dce234bc PP |
15169 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
15170 | #else | |
15171 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 15172 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
15173 | #endif |
15174 | } | |
15175 | } | |
15176 | ||
15177 | /* munmap debug sections for OBJFILE, if necessary. */ | |
15178 | ||
15179 | static void | |
c1bd65d0 | 15180 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
15181 | { |
15182 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 15183 | |
16be1145 DE |
15184 | /* This is sorted according to the order they're defined in to make it easier |
15185 | to keep in sync. */ | |
dce234bc PP |
15186 | munmap_section_buffer (&data->info); |
15187 | munmap_section_buffer (&data->abbrev); | |
15188 | munmap_section_buffer (&data->line); | |
16be1145 | 15189 | munmap_section_buffer (&data->loc); |
dce234bc | 15190 | munmap_section_buffer (&data->macinfo); |
16be1145 | 15191 | munmap_section_buffer (&data->str); |
dce234bc | 15192 | munmap_section_buffer (&data->ranges); |
16be1145 | 15193 | munmap_section_buffer (&data->types); |
dce234bc PP |
15194 | munmap_section_buffer (&data->frame); |
15195 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
15196 | munmap_section_buffer (&data->gdb_index); |
15197 | } | |
15198 | ||
15199 | \f | |
ae2de4f8 | 15200 | /* The "save gdb-index" command. */ |
9291a0cd TT |
15201 | |
15202 | /* The contents of the hash table we create when building the string | |
15203 | table. */ | |
15204 | struct strtab_entry | |
15205 | { | |
15206 | offset_type offset; | |
15207 | const char *str; | |
15208 | }; | |
15209 | ||
15210 | /* Hash function for a strtab_entry. */ | |
b89be57b | 15211 | |
9291a0cd TT |
15212 | static hashval_t |
15213 | hash_strtab_entry (const void *e) | |
15214 | { | |
15215 | const struct strtab_entry *entry = e; | |
15216 | return mapped_index_string_hash (entry->str); | |
15217 | } | |
15218 | ||
15219 | /* Equality function for a strtab_entry. */ | |
b89be57b | 15220 | |
9291a0cd TT |
15221 | static int |
15222 | eq_strtab_entry (const void *a, const void *b) | |
15223 | { | |
15224 | const struct strtab_entry *ea = a; | |
15225 | const struct strtab_entry *eb = b; | |
15226 | return !strcmp (ea->str, eb->str); | |
15227 | } | |
15228 | ||
15229 | /* Create a strtab_entry hash table. */ | |
b89be57b | 15230 | |
9291a0cd TT |
15231 | static htab_t |
15232 | create_strtab (void) | |
15233 | { | |
15234 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
15235 | xfree, xcalloc, xfree); | |
15236 | } | |
15237 | ||
15238 | /* Add a string to the constant pool. Return the string's offset in | |
15239 | host order. */ | |
b89be57b | 15240 | |
9291a0cd TT |
15241 | static offset_type |
15242 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
15243 | { | |
15244 | void **slot; | |
15245 | struct strtab_entry entry; | |
15246 | struct strtab_entry *result; | |
15247 | ||
15248 | entry.str = str; | |
15249 | slot = htab_find_slot (table, &entry, INSERT); | |
15250 | if (*slot) | |
15251 | result = *slot; | |
15252 | else | |
15253 | { | |
15254 | result = XNEW (struct strtab_entry); | |
15255 | result->offset = obstack_object_size (cpool); | |
15256 | result->str = str; | |
15257 | obstack_grow_str0 (cpool, str); | |
15258 | *slot = result; | |
15259 | } | |
15260 | return result->offset; | |
15261 | } | |
15262 | ||
15263 | /* An entry in the symbol table. */ | |
15264 | struct symtab_index_entry | |
15265 | { | |
15266 | /* The name of the symbol. */ | |
15267 | const char *name; | |
15268 | /* The offset of the name in the constant pool. */ | |
15269 | offset_type index_offset; | |
15270 | /* A sorted vector of the indices of all the CUs that hold an object | |
15271 | of this name. */ | |
15272 | VEC (offset_type) *cu_indices; | |
15273 | }; | |
15274 | ||
15275 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
15276 | struct mapped_symtab | |
15277 | { | |
15278 | offset_type n_elements; | |
15279 | offset_type size; | |
15280 | struct symtab_index_entry **data; | |
15281 | }; | |
15282 | ||
15283 | /* Hash function for a symtab_index_entry. */ | |
b89be57b | 15284 | |
9291a0cd TT |
15285 | static hashval_t |
15286 | hash_symtab_entry (const void *e) | |
15287 | { | |
15288 | const struct symtab_index_entry *entry = e; | |
15289 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
15290 | sizeof (offset_type) * VEC_length (offset_type, | |
15291 | entry->cu_indices), | |
15292 | 0); | |
15293 | } | |
15294 | ||
15295 | /* Equality function for a symtab_index_entry. */ | |
b89be57b | 15296 | |
9291a0cd TT |
15297 | static int |
15298 | eq_symtab_entry (const void *a, const void *b) | |
15299 | { | |
15300 | const struct symtab_index_entry *ea = a; | |
15301 | const struct symtab_index_entry *eb = b; | |
15302 | int len = VEC_length (offset_type, ea->cu_indices); | |
15303 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
15304 | return 0; | |
15305 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
15306 | VEC_address (offset_type, eb->cu_indices), | |
15307 | sizeof (offset_type) * len); | |
15308 | } | |
15309 | ||
15310 | /* Destroy a symtab_index_entry. */ | |
b89be57b | 15311 | |
9291a0cd TT |
15312 | static void |
15313 | delete_symtab_entry (void *p) | |
15314 | { | |
15315 | struct symtab_index_entry *entry = p; | |
15316 | VEC_free (offset_type, entry->cu_indices); | |
15317 | xfree (entry); | |
15318 | } | |
15319 | ||
15320 | /* Create a hash table holding symtab_index_entry objects. */ | |
b89be57b | 15321 | |
9291a0cd | 15322 | static htab_t |
3876f04e | 15323 | create_symbol_hash_table (void) |
9291a0cd TT |
15324 | { |
15325 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
15326 | delete_symtab_entry, xcalloc, xfree); | |
15327 | } | |
15328 | ||
15329 | /* Create a new mapped symtab object. */ | |
b89be57b | 15330 | |
9291a0cd TT |
15331 | static struct mapped_symtab * |
15332 | create_mapped_symtab (void) | |
15333 | { | |
15334 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
15335 | symtab->n_elements = 0; | |
15336 | symtab->size = 1024; | |
15337 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
15338 | return symtab; | |
15339 | } | |
15340 | ||
15341 | /* Destroy a mapped_symtab. */ | |
b89be57b | 15342 | |
9291a0cd TT |
15343 | static void |
15344 | cleanup_mapped_symtab (void *p) | |
15345 | { | |
15346 | struct mapped_symtab *symtab = p; | |
15347 | /* The contents of the array are freed when the other hash table is | |
15348 | destroyed. */ | |
15349 | xfree (symtab->data); | |
15350 | xfree (symtab); | |
15351 | } | |
15352 | ||
15353 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
15354 | the slot. */ | |
b89be57b | 15355 | |
9291a0cd TT |
15356 | static struct symtab_index_entry ** |
15357 | find_slot (struct mapped_symtab *symtab, const char *name) | |
15358 | { | |
15359 | offset_type index, step, hash = mapped_index_string_hash (name); | |
15360 | ||
15361 | index = hash & (symtab->size - 1); | |
15362 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
15363 | ||
15364 | for (;;) | |
15365 | { | |
15366 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
15367 | return &symtab->data[index]; | |
15368 | index = (index + step) & (symtab->size - 1); | |
15369 | } | |
15370 | } | |
15371 | ||
15372 | /* Expand SYMTAB's hash table. */ | |
b89be57b | 15373 | |
9291a0cd TT |
15374 | static void |
15375 | hash_expand (struct mapped_symtab *symtab) | |
15376 | { | |
15377 | offset_type old_size = symtab->size; | |
15378 | offset_type i; | |
15379 | struct symtab_index_entry **old_entries = symtab->data; | |
15380 | ||
15381 | symtab->size *= 2; | |
15382 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
15383 | ||
15384 | for (i = 0; i < old_size; ++i) | |
15385 | { | |
15386 | if (old_entries[i]) | |
15387 | { | |
15388 | struct symtab_index_entry **slot = find_slot (symtab, | |
15389 | old_entries[i]->name); | |
15390 | *slot = old_entries[i]; | |
15391 | } | |
15392 | } | |
15393 | ||
15394 | xfree (old_entries); | |
15395 | } | |
15396 | ||
15397 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
15398 | is the index of the CU in which the symbol appears. */ | |
b89be57b | 15399 | |
9291a0cd TT |
15400 | static void |
15401 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
15402 | offset_type cu_index) | |
15403 | { | |
15404 | struct symtab_index_entry **slot; | |
15405 | ||
15406 | ++symtab->n_elements; | |
15407 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
15408 | hash_expand (symtab); | |
15409 | ||
15410 | slot = find_slot (symtab, name); | |
15411 | if (!*slot) | |
15412 | { | |
15413 | *slot = XNEW (struct symtab_index_entry); | |
15414 | (*slot)->name = name; | |
15415 | (*slot)->cu_indices = NULL; | |
15416 | } | |
15417 | /* Don't push an index twice. Due to how we add entries we only | |
15418 | have to check the last one. */ | |
15419 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
15420 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) | |
15421 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); | |
15422 | } | |
15423 | ||
15424 | /* Add a vector of indices to the constant pool. */ | |
b89be57b | 15425 | |
9291a0cd | 15426 | static offset_type |
3876f04e | 15427 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
9291a0cd TT |
15428 | struct symtab_index_entry *entry) |
15429 | { | |
15430 | void **slot; | |
15431 | ||
3876f04e | 15432 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
9291a0cd TT |
15433 | if (!*slot) |
15434 | { | |
15435 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
15436 | offset_type val = MAYBE_SWAP (len); | |
15437 | offset_type iter; | |
15438 | int i; | |
15439 | ||
15440 | *slot = entry; | |
15441 | entry->index_offset = obstack_object_size (cpool); | |
15442 | ||
15443 | obstack_grow (cpool, &val, sizeof (val)); | |
15444 | for (i = 0; | |
15445 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
15446 | ++i) | |
15447 | { | |
15448 | val = MAYBE_SWAP (iter); | |
15449 | obstack_grow (cpool, &val, sizeof (val)); | |
15450 | } | |
15451 | } | |
15452 | else | |
15453 | { | |
15454 | struct symtab_index_entry *old_entry = *slot; | |
15455 | entry->index_offset = old_entry->index_offset; | |
15456 | entry = old_entry; | |
15457 | } | |
15458 | return entry->index_offset; | |
15459 | } | |
15460 | ||
15461 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
15462 | constant pool entries going into the obstack CPOOL. */ | |
b89be57b | 15463 | |
9291a0cd TT |
15464 | static void |
15465 | write_hash_table (struct mapped_symtab *symtab, | |
15466 | struct obstack *output, struct obstack *cpool) | |
15467 | { | |
15468 | offset_type i; | |
3876f04e | 15469 | htab_t symbol_hash_table; |
9291a0cd TT |
15470 | htab_t str_table; |
15471 | ||
3876f04e | 15472 | symbol_hash_table = create_symbol_hash_table (); |
9291a0cd | 15473 | str_table = create_strtab (); |
3876f04e | 15474 | |
9291a0cd TT |
15475 | /* We add all the index vectors to the constant pool first, to |
15476 | ensure alignment is ok. */ | |
15477 | for (i = 0; i < symtab->size; ++i) | |
15478 | { | |
15479 | if (symtab->data[i]) | |
3876f04e | 15480 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
9291a0cd TT |
15481 | } |
15482 | ||
15483 | /* Now write out the hash table. */ | |
15484 | for (i = 0; i < symtab->size; ++i) | |
15485 | { | |
15486 | offset_type str_off, vec_off; | |
15487 | ||
15488 | if (symtab->data[i]) | |
15489 | { | |
15490 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
15491 | vec_off = symtab->data[i]->index_offset; | |
15492 | } | |
15493 | else | |
15494 | { | |
15495 | /* While 0 is a valid constant pool index, it is not valid | |
15496 | to have 0 for both offsets. */ | |
15497 | str_off = 0; | |
15498 | vec_off = 0; | |
15499 | } | |
15500 | ||
15501 | str_off = MAYBE_SWAP (str_off); | |
15502 | vec_off = MAYBE_SWAP (vec_off); | |
15503 | ||
15504 | obstack_grow (output, &str_off, sizeof (str_off)); | |
15505 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
15506 | } | |
15507 | ||
15508 | htab_delete (str_table); | |
3876f04e | 15509 | htab_delete (symbol_hash_table); |
9291a0cd TT |
15510 | } |
15511 | ||
0a5429f6 DE |
15512 | /* Struct to map psymtab to CU index in the index file. */ |
15513 | struct psymtab_cu_index_map | |
15514 | { | |
15515 | struct partial_symtab *psymtab; | |
15516 | unsigned int cu_index; | |
15517 | }; | |
15518 | ||
15519 | static hashval_t | |
15520 | hash_psymtab_cu_index (const void *item) | |
15521 | { | |
15522 | const struct psymtab_cu_index_map *map = item; | |
15523 | ||
15524 | return htab_hash_pointer (map->psymtab); | |
15525 | } | |
15526 | ||
15527 | static int | |
15528 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) | |
15529 | { | |
15530 | const struct psymtab_cu_index_map *lhs = item_lhs; | |
15531 | const struct psymtab_cu_index_map *rhs = item_rhs; | |
15532 | ||
15533 | return lhs->psymtab == rhs->psymtab; | |
15534 | } | |
15535 | ||
15536 | /* Helper struct for building the address table. */ | |
15537 | struct addrmap_index_data | |
15538 | { | |
15539 | struct objfile *objfile; | |
15540 | struct obstack *addr_obstack; | |
15541 | htab_t cu_index_htab; | |
15542 | ||
15543 | /* Non-zero if the previous_* fields are valid. | |
15544 | We can't write an entry until we see the next entry (since it is only then | |
15545 | that we know the end of the entry). */ | |
15546 | int previous_valid; | |
15547 | /* Index of the CU in the table of all CUs in the index file. */ | |
15548 | unsigned int previous_cu_index; | |
0963b4bd | 15549 | /* Start address of the CU. */ |
0a5429f6 DE |
15550 | CORE_ADDR previous_cu_start; |
15551 | }; | |
15552 | ||
15553 | /* Write an address entry to OBSTACK. */ | |
b89be57b | 15554 | |
9291a0cd | 15555 | static void |
0a5429f6 DE |
15556 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
15557 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) | |
9291a0cd | 15558 | { |
0a5429f6 | 15559 | offset_type cu_index_to_write; |
9291a0cd TT |
15560 | char addr[8]; |
15561 | CORE_ADDR baseaddr; | |
15562 | ||
15563 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
15564 | ||
0a5429f6 DE |
15565 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
15566 | obstack_grow (obstack, addr, 8); | |
15567 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); | |
15568 | obstack_grow (obstack, addr, 8); | |
15569 | cu_index_to_write = MAYBE_SWAP (cu_index); | |
15570 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); | |
15571 | } | |
15572 | ||
15573 | /* Worker function for traversing an addrmap to build the address table. */ | |
15574 | ||
15575 | static int | |
15576 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) | |
15577 | { | |
15578 | struct addrmap_index_data *data = datap; | |
15579 | struct partial_symtab *pst = obj; | |
15580 | offset_type cu_index; | |
15581 | void **slot; | |
15582 | ||
15583 | if (data->previous_valid) | |
15584 | add_address_entry (data->objfile, data->addr_obstack, | |
15585 | data->previous_cu_start, start_addr, | |
15586 | data->previous_cu_index); | |
15587 | ||
15588 | data->previous_cu_start = start_addr; | |
15589 | if (pst != NULL) | |
15590 | { | |
15591 | struct psymtab_cu_index_map find_map, *map; | |
15592 | find_map.psymtab = pst; | |
15593 | map = htab_find (data->cu_index_htab, &find_map); | |
15594 | gdb_assert (map != NULL); | |
15595 | data->previous_cu_index = map->cu_index; | |
15596 | data->previous_valid = 1; | |
15597 | } | |
15598 | else | |
15599 | data->previous_valid = 0; | |
15600 | ||
15601 | return 0; | |
15602 | } | |
15603 | ||
15604 | /* Write OBJFILE's address map to OBSTACK. | |
15605 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices | |
15606 | in the index file. */ | |
15607 | ||
15608 | static void | |
15609 | write_address_map (struct objfile *objfile, struct obstack *obstack, | |
15610 | htab_t cu_index_htab) | |
15611 | { | |
15612 | struct addrmap_index_data addrmap_index_data; | |
15613 | ||
15614 | /* When writing the address table, we have to cope with the fact that | |
15615 | the addrmap iterator only provides the start of a region; we have to | |
15616 | wait until the next invocation to get the start of the next region. */ | |
15617 | ||
15618 | addrmap_index_data.objfile = objfile; | |
15619 | addrmap_index_data.addr_obstack = obstack; | |
15620 | addrmap_index_data.cu_index_htab = cu_index_htab; | |
15621 | addrmap_index_data.previous_valid = 0; | |
15622 | ||
15623 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, | |
15624 | &addrmap_index_data); | |
15625 | ||
15626 | /* It's highly unlikely the last entry (end address = 0xff...ff) | |
15627 | is valid, but we should still handle it. | |
15628 | The end address is recorded as the start of the next region, but that | |
15629 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation | |
15630 | anyway. */ | |
15631 | if (addrmap_index_data.previous_valid) | |
15632 | add_address_entry (objfile, obstack, | |
15633 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, | |
15634 | addrmap_index_data.previous_cu_index); | |
9291a0cd TT |
15635 | } |
15636 | ||
15637 | /* Add a list of partial symbols to SYMTAB. */ | |
b89be57b | 15638 | |
9291a0cd TT |
15639 | static void |
15640 | write_psymbols (struct mapped_symtab *symtab, | |
987d643c | 15641 | htab_t psyms_seen, |
9291a0cd TT |
15642 | struct partial_symbol **psymp, |
15643 | int count, | |
987d643c TT |
15644 | offset_type cu_index, |
15645 | int is_static) | |
9291a0cd TT |
15646 | { |
15647 | for (; count-- > 0; ++psymp) | |
15648 | { | |
987d643c TT |
15649 | void **slot, *lookup; |
15650 | ||
9291a0cd TT |
15651 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
15652 | error (_("Ada is not currently supported by the index")); | |
987d643c TT |
15653 | |
15654 | /* We only want to add a given psymbol once. However, we also | |
15655 | want to account for whether it is global or static. So, we | |
15656 | may add it twice, using slightly different values. */ | |
15657 | if (is_static) | |
15658 | { | |
15659 | uintptr_t val = 1 | (uintptr_t) *psymp; | |
15660 | ||
15661 | lookup = (void *) val; | |
15662 | } | |
15663 | else | |
15664 | lookup = *psymp; | |
15665 | ||
15666 | /* Only add a given psymbol once. */ | |
15667 | slot = htab_find_slot (psyms_seen, lookup, INSERT); | |
15668 | if (!*slot) | |
15669 | { | |
15670 | *slot = lookup; | |
15671 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
15672 | } | |
9291a0cd TT |
15673 | } |
15674 | } | |
15675 | ||
15676 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
15677 | exception if there is an error. */ | |
b89be57b | 15678 | |
9291a0cd TT |
15679 | static void |
15680 | write_obstack (FILE *file, struct obstack *obstack) | |
15681 | { | |
15682 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
15683 | file) | |
15684 | != obstack_object_size (obstack)) | |
15685 | error (_("couldn't data write to file")); | |
15686 | } | |
15687 | ||
15688 | /* Unlink a file if the argument is not NULL. */ | |
b89be57b | 15689 | |
9291a0cd TT |
15690 | static void |
15691 | unlink_if_set (void *p) | |
15692 | { | |
15693 | char **filename = p; | |
15694 | if (*filename) | |
15695 | unlink (*filename); | |
15696 | } | |
15697 | ||
1fd400ff TT |
15698 | /* A helper struct used when iterating over debug_types. */ |
15699 | struct signatured_type_index_data | |
15700 | { | |
15701 | struct objfile *objfile; | |
15702 | struct mapped_symtab *symtab; | |
15703 | struct obstack *types_list; | |
987d643c | 15704 | htab_t psyms_seen; |
1fd400ff TT |
15705 | int cu_index; |
15706 | }; | |
15707 | ||
15708 | /* A helper function that writes a single signatured_type to an | |
15709 | obstack. */ | |
b89be57b | 15710 | |
1fd400ff TT |
15711 | static int |
15712 | write_one_signatured_type (void **slot, void *d) | |
15713 | { | |
15714 | struct signatured_type_index_data *info = d; | |
15715 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
15716 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
15717 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
15718 | gdb_byte val[8]; |
15719 | ||
15720 | write_psymbols (info->symtab, | |
987d643c | 15721 | info->psyms_seen, |
3e43a32a MS |
15722 | info->objfile->global_psymbols.list |
15723 | + psymtab->globals_offset, | |
987d643c TT |
15724 | psymtab->n_global_syms, info->cu_index, |
15725 | 0); | |
1fd400ff | 15726 | write_psymbols (info->symtab, |
987d643c | 15727 | info->psyms_seen, |
3e43a32a MS |
15728 | info->objfile->static_psymbols.list |
15729 | + psymtab->statics_offset, | |
987d643c TT |
15730 | psymtab->n_static_syms, info->cu_index, |
15731 | 1); | |
1fd400ff TT |
15732 | |
15733 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset); | |
15734 | obstack_grow (info->types_list, val, 8); | |
15735 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
15736 | obstack_grow (info->types_list, val, 8); | |
15737 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
15738 | obstack_grow (info->types_list, val, 8); | |
15739 | ||
15740 | ++info->cu_index; | |
15741 | ||
15742 | return 1; | |
15743 | } | |
15744 | ||
987d643c TT |
15745 | /* A cleanup function for an htab_t. */ |
15746 | ||
15747 | static void | |
15748 | cleanup_htab (void *arg) | |
15749 | { | |
15750 | htab_delete (arg); | |
15751 | } | |
15752 | ||
9291a0cd | 15753 | /* Create an index file for OBJFILE in the directory DIR. */ |
b89be57b | 15754 | |
9291a0cd TT |
15755 | static void |
15756 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
15757 | { | |
15758 | struct cleanup *cleanup; | |
15759 | char *filename, *cleanup_filename; | |
1fd400ff TT |
15760 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
15761 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
15762 | int i; |
15763 | FILE *out_file; | |
15764 | struct mapped_symtab *symtab; | |
15765 | offset_type val, size_of_contents, total_len; | |
15766 | struct stat st; | |
15767 | char buf[8]; | |
987d643c | 15768 | htab_t psyms_seen; |
0a5429f6 DE |
15769 | htab_t cu_index_htab; |
15770 | struct psymtab_cu_index_map *psymtab_cu_index_map; | |
9291a0cd TT |
15771 | |
15772 | if (!objfile->psymtabs) | |
15773 | return; | |
15774 | if (dwarf2_per_objfile->using_index) | |
15775 | error (_("Cannot use an index to create the index")); | |
15776 | ||
15777 | if (stat (objfile->name, &st) < 0) | |
7e17e088 | 15778 | perror_with_name (objfile->name); |
9291a0cd TT |
15779 | |
15780 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
15781 | INDEX_SUFFIX, (char *) NULL); | |
15782 | cleanup = make_cleanup (xfree, filename); | |
15783 | ||
15784 | out_file = fopen (filename, "wb"); | |
15785 | if (!out_file) | |
15786 | error (_("Can't open `%s' for writing"), filename); | |
15787 | ||
15788 | cleanup_filename = filename; | |
15789 | make_cleanup (unlink_if_set, &cleanup_filename); | |
15790 | ||
15791 | symtab = create_mapped_symtab (); | |
15792 | make_cleanup (cleanup_mapped_symtab, symtab); | |
15793 | ||
15794 | obstack_init (&addr_obstack); | |
15795 | make_cleanup_obstack_free (&addr_obstack); | |
15796 | ||
15797 | obstack_init (&cu_list); | |
15798 | make_cleanup_obstack_free (&cu_list); | |
15799 | ||
1fd400ff TT |
15800 | obstack_init (&types_cu_list); |
15801 | make_cleanup_obstack_free (&types_cu_list); | |
15802 | ||
987d643c TT |
15803 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
15804 | NULL, xcalloc, xfree); | |
15805 | make_cleanup (cleanup_htab, psyms_seen); | |
15806 | ||
0a5429f6 DE |
15807 | /* While we're scanning CU's create a table that maps a psymtab pointer |
15808 | (which is what addrmap records) to its index (which is what is recorded | |
15809 | in the index file). This will later be needed to write the address | |
15810 | table. */ | |
15811 | cu_index_htab = htab_create_alloc (100, | |
15812 | hash_psymtab_cu_index, | |
15813 | eq_psymtab_cu_index, | |
15814 | NULL, xcalloc, xfree); | |
15815 | make_cleanup (cleanup_htab, cu_index_htab); | |
15816 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) | |
15817 | xmalloc (sizeof (struct psymtab_cu_index_map) | |
15818 | * dwarf2_per_objfile->n_comp_units); | |
15819 | make_cleanup (xfree, psymtab_cu_index_map); | |
15820 | ||
15821 | /* The CU list is already sorted, so we don't need to do additional | |
1fd400ff TT |
15822 | work here. Also, the debug_types entries do not appear in |
15823 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
15824 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
15825 | { | |
3e43a32a MS |
15826 | struct dwarf2_per_cu_data *per_cu |
15827 | = dwarf2_per_objfile->all_comp_units[i]; | |
e254ef6a | 15828 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
9291a0cd | 15829 | gdb_byte val[8]; |
0a5429f6 DE |
15830 | struct psymtab_cu_index_map *map; |
15831 | void **slot; | |
9291a0cd TT |
15832 | |
15833 | write_psymbols (symtab, | |
987d643c | 15834 | psyms_seen, |
9291a0cd | 15835 | objfile->global_psymbols.list + psymtab->globals_offset, |
987d643c TT |
15836 | psymtab->n_global_syms, i, |
15837 | 0); | |
9291a0cd | 15838 | write_psymbols (symtab, |
987d643c | 15839 | psyms_seen, |
9291a0cd | 15840 | objfile->static_psymbols.list + psymtab->statics_offset, |
987d643c TT |
15841 | psymtab->n_static_syms, i, |
15842 | 1); | |
9291a0cd | 15843 | |
0a5429f6 DE |
15844 | map = &psymtab_cu_index_map[i]; |
15845 | map->psymtab = psymtab; | |
15846 | map->cu_index = i; | |
15847 | slot = htab_find_slot (cu_index_htab, map, INSERT); | |
15848 | gdb_assert (slot != NULL); | |
15849 | gdb_assert (*slot == NULL); | |
15850 | *slot = map; | |
9291a0cd | 15851 | |
e254ef6a | 15852 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 15853 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 15854 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
15855 | obstack_grow (&cu_list, val, 8); |
15856 | } | |
15857 | ||
0a5429f6 DE |
15858 | /* Dump the address map. */ |
15859 | write_address_map (objfile, &addr_obstack, cu_index_htab); | |
15860 | ||
1fd400ff TT |
15861 | /* Write out the .debug_type entries, if any. */ |
15862 | if (dwarf2_per_objfile->signatured_types) | |
15863 | { | |
15864 | struct signatured_type_index_data sig_data; | |
15865 | ||
15866 | sig_data.objfile = objfile; | |
15867 | sig_data.symtab = symtab; | |
15868 | sig_data.types_list = &types_cu_list; | |
987d643c | 15869 | sig_data.psyms_seen = psyms_seen; |
1fd400ff TT |
15870 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
15871 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
15872 | write_one_signatured_type, &sig_data); | |
15873 | } | |
15874 | ||
9291a0cd TT |
15875 | obstack_init (&constant_pool); |
15876 | make_cleanup_obstack_free (&constant_pool); | |
15877 | obstack_init (&symtab_obstack); | |
15878 | make_cleanup_obstack_free (&symtab_obstack); | |
15879 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
15880 | ||
15881 | obstack_init (&contents); | |
15882 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 15883 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
15884 | total_len = size_of_contents; |
15885 | ||
15886 | /* The version number. */ | |
831adc1f | 15887 | val = MAYBE_SWAP (4); |
9291a0cd TT |
15888 | obstack_grow (&contents, &val, sizeof (val)); |
15889 | ||
15890 | /* The offset of the CU list from the start of the file. */ | |
15891 | val = MAYBE_SWAP (total_len); | |
15892 | obstack_grow (&contents, &val, sizeof (val)); | |
15893 | total_len += obstack_object_size (&cu_list); | |
15894 | ||
1fd400ff TT |
15895 | /* The offset of the types CU list from the start of the file. */ |
15896 | val = MAYBE_SWAP (total_len); | |
15897 | obstack_grow (&contents, &val, sizeof (val)); | |
15898 | total_len += obstack_object_size (&types_cu_list); | |
15899 | ||
9291a0cd TT |
15900 | /* The offset of the address table from the start of the file. */ |
15901 | val = MAYBE_SWAP (total_len); | |
15902 | obstack_grow (&contents, &val, sizeof (val)); | |
15903 | total_len += obstack_object_size (&addr_obstack); | |
15904 | ||
15905 | /* The offset of the symbol table from the start of the file. */ | |
15906 | val = MAYBE_SWAP (total_len); | |
15907 | obstack_grow (&contents, &val, sizeof (val)); | |
15908 | total_len += obstack_object_size (&symtab_obstack); | |
15909 | ||
15910 | /* The offset of the constant pool from the start of the file. */ | |
15911 | val = MAYBE_SWAP (total_len); | |
15912 | obstack_grow (&contents, &val, sizeof (val)); | |
15913 | total_len += obstack_object_size (&constant_pool); | |
15914 | ||
15915 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
15916 | ||
15917 | write_obstack (out_file, &contents); | |
15918 | write_obstack (out_file, &cu_list); | |
1fd400ff | 15919 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
15920 | write_obstack (out_file, &addr_obstack); |
15921 | write_obstack (out_file, &symtab_obstack); | |
15922 | write_obstack (out_file, &constant_pool); | |
15923 | ||
15924 | fclose (out_file); | |
15925 | ||
15926 | /* We want to keep the file, so we set cleanup_filename to NULL | |
15927 | here. See unlink_if_set. */ | |
15928 | cleanup_filename = NULL; | |
15929 | ||
15930 | do_cleanups (cleanup); | |
15931 | } | |
15932 | ||
15933 | /* The mapped index file format is designed to be directly mmap()able | |
15934 | on any architecture. In most cases, a datum is represented using a | |
15935 | little-endian 32-bit integer value, called an offset_type. Big | |
15936 | endian machines must byte-swap the values before using them. | |
15937 | Exceptions to this rule are noted. The data is laid out such that | |
15938 | alignment is always respected. | |
15939 | ||
15940 | A mapped index consists of several sections. | |
15941 | ||
15942 | 1. The file header. This is a sequence of values, of offset_type | |
15943 | unless otherwise noted: | |
987d643c | 15944 | |
831adc1f | 15945 | [0] The version number, currently 4. Versions 1, 2 and 3 are |
987d643c | 15946 | obsolete. |
9291a0cd | 15947 | [1] The offset, from the start of the file, of the CU list. |
987d643c TT |
15948 | [2] The offset, from the start of the file, of the types CU list. |
15949 | Note that this section can be empty, in which case this offset will | |
15950 | be equal to the next offset. | |
15951 | [3] The offset, from the start of the file, of the address section. | |
15952 | [4] The offset, from the start of the file, of the symbol table. | |
15953 | [5] The offset, from the start of the file, of the constant pool. | |
9291a0cd TT |
15954 | |
15955 | 2. The CU list. This is a sequence of pairs of 64-bit | |
1fd400ff TT |
15956 | little-endian values, sorted by the CU offset. The first element |
15957 | in each pair is the offset of a CU in the .debug_info section. The | |
15958 | second element in each pair is the length of that CU. References | |
15959 | to a CU elsewhere in the map are done using a CU index, which is | |
15960 | just the 0-based index into this table. Note that if there are | |
15961 | type CUs, then conceptually CUs and type CUs form a single list for | |
15962 | the purposes of CU indices. | |
15963 | ||
987d643c TT |
15964 | 3. The types CU list. This is a sequence of triplets of 64-bit |
15965 | little-endian values. In a triplet, the first value is the CU | |
15966 | offset, the second value is the type offset in the CU, and the | |
15967 | third value is the type signature. The types CU list is not | |
15968 | sorted. | |
9291a0cd | 15969 | |
987d643c | 15970 | 4. The address section. The address section consists of a sequence |
9291a0cd TT |
15971 | of address entries. Each address entry has three elements. |
15972 | [0] The low address. This is a 64-bit little-endian value. | |
15973 | [1] The high address. This is a 64-bit little-endian value. | |
148c11bf | 15974 | Like DW_AT_high_pc, the value is one byte beyond the end. |
9291a0cd TT |
15975 | [2] The CU index. This is an offset_type value. |
15976 | ||
987d643c | 15977 | 5. The symbol table. This is a hash table. The size of the hash |
9291a0cd TT |
15978 | table is always a power of 2. The initial hash and the step are |
15979 | currently defined by the `find_slot' function. | |
15980 | ||
15981 | Each slot in the hash table consists of a pair of offset_type | |
15982 | values. The first value is the offset of the symbol's name in the | |
15983 | constant pool. The second value is the offset of the CU vector in | |
15984 | the constant pool. | |
15985 | ||
15986 | If both values are 0, then this slot in the hash table is empty. | |
15987 | This is ok because while 0 is a valid constant pool index, it | |
15988 | cannot be a valid index for both a string and a CU vector. | |
15989 | ||
15990 | A string in the constant pool is stored as a \0-terminated string, | |
15991 | as you'd expect. | |
15992 | ||
15993 | A CU vector in the constant pool is a sequence of offset_type | |
15994 | values. The first value is the number of CU indices in the vector. | |
15995 | Each subsequent value is the index of a CU in the CU list. This | |
15996 | element in the hash table is used to indicate which CUs define the | |
15997 | symbol. | |
15998 | ||
987d643c | 15999 | 6. The constant pool. This is simply a bunch of bytes. It is |
9291a0cd TT |
16000 | organized so that alignment is correct: CU vectors are stored |
16001 | first, followed by strings. */ | |
11570e71 | 16002 | |
9291a0cd TT |
16003 | static void |
16004 | save_gdb_index_command (char *arg, int from_tty) | |
16005 | { | |
16006 | struct objfile *objfile; | |
16007 | ||
16008 | if (!arg || !*arg) | |
96d19272 | 16009 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
16010 | |
16011 | ALL_OBJFILES (objfile) | |
16012 | { | |
16013 | struct stat st; | |
16014 | ||
16015 | /* If the objfile does not correspond to an actual file, skip it. */ | |
16016 | if (stat (objfile->name, &st) < 0) | |
16017 | continue; | |
16018 | ||
16019 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
16020 | if (dwarf2_per_objfile) | |
16021 | { | |
16022 | volatile struct gdb_exception except; | |
16023 | ||
16024 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
16025 | { | |
16026 | write_psymtabs_to_index (objfile, arg); | |
16027 | } | |
16028 | if (except.reason < 0) | |
16029 | exception_fprintf (gdb_stderr, except, | |
16030 | _("Error while writing index for `%s': "), | |
16031 | objfile->name); | |
16032 | } | |
16033 | } | |
dce234bc PP |
16034 | } |
16035 | ||
9291a0cd TT |
16036 | \f |
16037 | ||
9eae7c52 TT |
16038 | int dwarf2_always_disassemble; |
16039 | ||
16040 | static void | |
16041 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
16042 | struct cmd_list_element *c, const char *value) | |
16043 | { | |
3e43a32a MS |
16044 | fprintf_filtered (file, |
16045 | _("Whether to always disassemble " | |
16046 | "DWARF expressions is %s.\n"), | |
9eae7c52 TT |
16047 | value); |
16048 | } | |
16049 | ||
6502dd73 DJ |
16050 | void _initialize_dwarf2_read (void); |
16051 | ||
16052 | void | |
16053 | _initialize_dwarf2_read (void) | |
16054 | { | |
96d19272 JK |
16055 | struct cmd_list_element *c; |
16056 | ||
dce234bc | 16057 | dwarf2_objfile_data_key |
c1bd65d0 | 16058 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 16059 | |
1bedd215 AC |
16060 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
16061 | Set DWARF 2 specific variables.\n\ | |
16062 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16063 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
16064 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
16065 | ||
1bedd215 AC |
16066 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
16067 | Show DWARF 2 specific variables\n\ | |
16068 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
16069 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
16070 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
16071 | ||
16072 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
16073 | &dwarf2_max_cache_age, _("\ |
16074 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16075 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
16076 | A higher limit means that cached compilation units will be stored\n\ | |
16077 | in memory longer, and more total memory will be used. Zero disables\n\ | |
16078 | caching, which can slow down startup."), | |
2c5b56ce | 16079 | NULL, |
920d2a44 | 16080 | show_dwarf2_max_cache_age, |
2c5b56ce | 16081 | &set_dwarf2_cmdlist, |
ae038cb0 | 16082 | &show_dwarf2_cmdlist); |
d97bc12b | 16083 | |
9eae7c52 TT |
16084 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
16085 | &dwarf2_always_disassemble, _("\ | |
16086 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
16087 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
16088 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
16089 | syntax. When disabled, expressions will be printed in a more\n\ | |
16090 | conversational style, when possible."), | |
16091 | NULL, | |
16092 | show_dwarf2_always_disassemble, | |
16093 | &set_dwarf2_cmdlist, | |
16094 | &show_dwarf2_cmdlist); | |
16095 | ||
d97bc12b DE |
16096 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
16097 | Set debugging of the dwarf2 DIE reader."), _("\ | |
16098 | Show debugging of the dwarf2 DIE reader."), _("\ | |
16099 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
16100 | The value is the maximum depth to print."), | |
16101 | NULL, | |
16102 | NULL, | |
16103 | &setdebuglist, &showdebuglist); | |
9291a0cd | 16104 | |
96d19272 | 16105 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
11570e71 | 16106 | _("\ |
fc1a9d6e | 16107 | Save a gdb-index file.\n\ |
11570e71 | 16108 | Usage: save gdb-index DIRECTORY"), |
96d19272 JK |
16109 | &save_cmdlist); |
16110 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 16111 | } |