]>
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, |
4c38e0a4 | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
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" |
4c2df51b | 57 | |
c906108c SS |
58 | #include <fcntl.h> |
59 | #include "gdb_string.h" | |
4bdf3d34 | 60 | #include "gdb_assert.h" |
c906108c | 61 | #include <sys/types.h> |
233a11ab CS |
62 | #ifdef HAVE_ZLIB_H |
63 | #include <zlib.h> | |
64 | #endif | |
dce234bc PP |
65 | #ifdef HAVE_MMAP |
66 | #include <sys/mman.h> | |
85d9bd0e TT |
67 | #ifndef MAP_FAILED |
68 | #define MAP_FAILED ((void *) -1) | |
69 | #endif | |
dce234bc | 70 | #endif |
d8151005 | 71 | |
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c | 88 | |
c906108c SS |
89 | /* .debug_line statement program prologue |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct statement_prologue | |
93 | { | |
94 | unsigned int total_length; /* byte length of the statement | |
95 | information */ | |
96 | unsigned short version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int prologue_length; /* # bytes between prologue & | |
99 | stmt program */ | |
100 | unsigned char minimum_instruction_length; /* byte size of | |
101 | smallest instr */ | |
102 | unsigned char default_is_stmt; /* initial value of is_stmt | |
103 | register */ | |
104 | char line_base; | |
105 | unsigned char line_range; | |
106 | unsigned char opcode_base; /* number assigned to first special | |
107 | opcode */ | |
108 | unsigned char *standard_opcode_lengths; | |
109 | } | |
110 | _STATEMENT_PROLOGUE; | |
111 | ||
d97bc12b DE |
112 | /* When non-zero, dump DIEs after they are read in. */ |
113 | static int dwarf2_die_debug = 0; | |
114 | ||
dce234bc PP |
115 | static int pagesize; |
116 | ||
df8a16a1 DJ |
117 | /* When set, the file that we're processing is known to have debugging |
118 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
119 | but later versions do. */ | |
120 | ||
121 | static int processing_has_namespace_info; | |
122 | ||
6502dd73 DJ |
123 | static const struct objfile_data *dwarf2_objfile_data_key; |
124 | ||
dce234bc PP |
125 | struct dwarf2_section_info |
126 | { | |
127 | asection *asection; | |
128 | gdb_byte *buffer; | |
129 | bfd_size_type size; | |
130 | int was_mmapped; | |
be391dca TT |
131 | /* True if we have tried to read this section. */ |
132 | int readin; | |
dce234bc PP |
133 | }; |
134 | ||
9291a0cd TT |
135 | /* All offsets in the index are of this type. It must be |
136 | architecture-independent. */ | |
137 | typedef uint32_t offset_type; | |
138 | ||
139 | DEF_VEC_I (offset_type); | |
140 | ||
141 | /* A description of the mapped index. The file format is described in | |
142 | a comment by the code that writes the index. */ | |
143 | struct mapped_index | |
144 | { | |
145 | /* The total length of the buffer. */ | |
146 | off_t total_size; | |
147 | /* A pointer to the address table data. */ | |
148 | const gdb_byte *address_table; | |
149 | /* Size of the address table data in bytes. */ | |
150 | offset_type address_table_size; | |
151 | /* The hash table. */ | |
152 | const offset_type *index_table; | |
153 | /* Size in slots, each slot is 2 offset_types. */ | |
154 | offset_type index_table_slots; | |
155 | /* A pointer to the constant pool. */ | |
156 | const char *constant_pool; | |
157 | }; | |
158 | ||
6502dd73 DJ |
159 | struct dwarf2_per_objfile |
160 | { | |
dce234bc PP |
161 | struct dwarf2_section_info info; |
162 | struct dwarf2_section_info abbrev; | |
163 | struct dwarf2_section_info line; | |
dce234bc PP |
164 | struct dwarf2_section_info loc; |
165 | struct dwarf2_section_info macinfo; | |
166 | struct dwarf2_section_info str; | |
167 | struct dwarf2_section_info ranges; | |
348e048f | 168 | struct dwarf2_section_info types; |
dce234bc PP |
169 | struct dwarf2_section_info frame; |
170 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 171 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 172 | |
be391dca TT |
173 | /* Back link. */ |
174 | struct objfile *objfile; | |
175 | ||
10b3939b DJ |
176 | /* A list of all the compilation units. This is used to locate |
177 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
178 | struct dwarf2_per_cu_data **all_comp_units; |
179 | ||
180 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
181 | int n_comp_units; | |
182 | ||
183 | /* A chain of compilation units that are currently read in, so that | |
184 | they can be freed later. */ | |
185 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 186 | |
348e048f DE |
187 | /* A table mapping .debug_types signatures to its signatured_type entry. |
188 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
189 | htab_t signatured_types; | |
190 | ||
72dca2f5 FR |
191 | /* A flag indicating wether this objfile has a section loaded at a |
192 | VMA of 0. */ | |
193 | int has_section_at_zero; | |
9291a0cd TT |
194 | |
195 | /* True if we are using the mapped index. */ | |
196 | unsigned char using_index; | |
197 | ||
198 | /* The mapped index. */ | |
199 | struct mapped_index *index_table; | |
6502dd73 DJ |
200 | }; |
201 | ||
202 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
203 | |
204 | /* names of the debugging sections */ | |
205 | ||
233a11ab CS |
206 | /* Note that if the debugging section has been compressed, it might |
207 | have a name like .zdebug_info. */ | |
208 | ||
209 | #define INFO_SECTION "debug_info" | |
210 | #define ABBREV_SECTION "debug_abbrev" | |
211 | #define LINE_SECTION "debug_line" | |
233a11ab CS |
212 | #define LOC_SECTION "debug_loc" |
213 | #define MACINFO_SECTION "debug_macinfo" | |
214 | #define STR_SECTION "debug_str" | |
215 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 216 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
217 | #define FRAME_SECTION "debug_frame" |
218 | #define EH_FRAME_SECTION "eh_frame" | |
9291a0cd | 219 | #define GDB_INDEX_SECTION "gdb_index" |
c906108c SS |
220 | |
221 | /* local data types */ | |
222 | ||
57349743 JB |
223 | /* We hold several abbreviation tables in memory at the same time. */ |
224 | #ifndef ABBREV_HASH_SIZE | |
225 | #define ABBREV_HASH_SIZE 121 | |
226 | #endif | |
227 | ||
107d2387 AC |
228 | /* The data in a compilation unit header, after target2host |
229 | translation, looks like this. */ | |
c906108c | 230 | struct comp_unit_head |
a738430d | 231 | { |
c764a876 | 232 | unsigned int length; |
a738430d | 233 | short version; |
a738430d MK |
234 | unsigned char addr_size; |
235 | unsigned char signed_addr_p; | |
9cbfa09e | 236 | unsigned int abbrev_offset; |
57349743 | 237 | |
a738430d MK |
238 | /* Size of file offsets; either 4 or 8. */ |
239 | unsigned int offset_size; | |
57349743 | 240 | |
a738430d MK |
241 | /* Size of the length field; either 4 or 12. */ |
242 | unsigned int initial_length_size; | |
57349743 | 243 | |
a738430d MK |
244 | /* Offset to the first byte of this compilation unit header in the |
245 | .debug_info section, for resolving relative reference dies. */ | |
246 | unsigned int offset; | |
57349743 | 247 | |
d00adf39 DE |
248 | /* Offset to first die in this cu from the start of the cu. |
249 | This will be the first byte following the compilation unit header. */ | |
250 | unsigned int first_die_offset; | |
a738430d | 251 | }; |
c906108c | 252 | |
e7c27a73 DJ |
253 | /* Internal state when decoding a particular compilation unit. */ |
254 | struct dwarf2_cu | |
255 | { | |
256 | /* The objfile containing this compilation unit. */ | |
257 | struct objfile *objfile; | |
258 | ||
d00adf39 | 259 | /* The header of the compilation unit. */ |
e7c27a73 | 260 | struct comp_unit_head header; |
e142c38c | 261 | |
d00adf39 DE |
262 | /* Base address of this compilation unit. */ |
263 | CORE_ADDR base_address; | |
264 | ||
265 | /* Non-zero if base_address has been set. */ | |
266 | int base_known; | |
267 | ||
e142c38c DJ |
268 | struct function_range *first_fn, *last_fn, *cached_fn; |
269 | ||
270 | /* The language we are debugging. */ | |
271 | enum language language; | |
272 | const struct language_defn *language_defn; | |
273 | ||
b0f35d58 DL |
274 | const char *producer; |
275 | ||
e142c38c DJ |
276 | /* The generic symbol table building routines have separate lists for |
277 | file scope symbols and all all other scopes (local scopes). So | |
278 | we need to select the right one to pass to add_symbol_to_list(). | |
279 | We do it by keeping a pointer to the correct list in list_in_scope. | |
280 | ||
281 | FIXME: The original dwarf code just treated the file scope as the | |
282 | first local scope, and all other local scopes as nested local | |
283 | scopes, and worked fine. Check to see if we really need to | |
284 | distinguish these in buildsym.c. */ | |
285 | struct pending **list_in_scope; | |
286 | ||
f3dd6933 DJ |
287 | /* DWARF abbreviation table associated with this compilation unit. */ |
288 | struct abbrev_info **dwarf2_abbrevs; | |
289 | ||
290 | /* Storage for the abbrev table. */ | |
291 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
292 | |
293 | /* Hash table holding all the loaded partial DIEs. */ | |
294 | htab_t partial_dies; | |
295 | ||
296 | /* Storage for things with the same lifetime as this read-in compilation | |
297 | unit, including partial DIEs. */ | |
298 | struct obstack comp_unit_obstack; | |
299 | ||
ae038cb0 DJ |
300 | /* When multiple dwarf2_cu structures are living in memory, this field |
301 | chains them all together, so that they can be released efficiently. | |
302 | We will probably also want a generation counter so that most-recently-used | |
303 | compilation units are cached... */ | |
304 | struct dwarf2_per_cu_data *read_in_chain; | |
305 | ||
306 | /* Backchain to our per_cu entry if the tree has been built. */ | |
307 | struct dwarf2_per_cu_data *per_cu; | |
308 | ||
f792889a DJ |
309 | /* Pointer to the die -> type map. Although it is stored |
310 | permanently in per_cu, we copy it here to avoid double | |
311 | indirection. */ | |
312 | htab_t type_hash; | |
313 | ||
ae038cb0 DJ |
314 | /* How many compilation units ago was this CU last referenced? */ |
315 | int last_used; | |
316 | ||
10b3939b | 317 | /* A hash table of die offsets for following references. */ |
51545339 | 318 | htab_t die_hash; |
10b3939b DJ |
319 | |
320 | /* Full DIEs if read in. */ | |
321 | struct die_info *dies; | |
322 | ||
323 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
324 | units referenced by this one. Only set during full symbol processing; | |
325 | partial symbol tables do not have dependencies. */ | |
326 | htab_t dependencies; | |
327 | ||
cb1df416 DJ |
328 | /* Header data from the line table, during full symbol processing. */ |
329 | struct line_header *line_header; | |
330 | ||
ae038cb0 DJ |
331 | /* Mark used when releasing cached dies. */ |
332 | unsigned int mark : 1; | |
333 | ||
334 | /* This flag will be set if this compilation unit might include | |
335 | inter-compilation-unit references. */ | |
336 | unsigned int has_form_ref_addr : 1; | |
337 | ||
72bf9492 DJ |
338 | /* This flag will be set if this compilation unit includes any |
339 | DW_TAG_namespace DIEs. If we know that there are explicit | |
340 | DIEs for namespaces, we don't need to try to infer them | |
341 | from mangled names. */ | |
342 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
343 | }; |
344 | ||
9291a0cd TT |
345 | /* When using the index (and thus not using psymtabs), each CU has an |
346 | object of this type. This is used to hold information needed by | |
347 | the various "quick" methods. */ | |
348 | struct dwarf2_per_cu_quick_data | |
349 | { | |
350 | /* The line table. This can be NULL if there was no line table. */ | |
351 | struct line_header *lines; | |
352 | ||
353 | /* The file names from the line table. */ | |
354 | const char **file_names; | |
355 | /* The file names from the line table after being run through | |
356 | gdb_realpath. */ | |
357 | const char **full_names; | |
358 | ||
359 | /* The corresponding symbol table. This is NULL if symbols for this | |
360 | CU have not yet been read. */ | |
361 | struct symtab *symtab; | |
362 | ||
363 | /* A temporary mark bit used when iterating over all CUs in | |
364 | expand_symtabs_matching. */ | |
365 | unsigned int mark : 1; | |
366 | ||
367 | /* True if we've tried to read the line table. */ | |
368 | unsigned int read_lines : 1; | |
369 | }; | |
370 | ||
10b3939b DJ |
371 | /* Persistent data held for a compilation unit, even when not |
372 | processing it. We put a pointer to this structure in the | |
373 | read_symtab_private field of the psymtab. If we encounter | |
374 | inter-compilation-unit references, we also maintain a sorted | |
375 | list of all compilation units. */ | |
376 | ||
ae038cb0 DJ |
377 | struct dwarf2_per_cu_data |
378 | { | |
348e048f | 379 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 380 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
381 | - if it doesn't, GDB will fall over anyway. |
382 | NOTE: Unlike comp_unit_head.length, this length includes | |
383 | initial_length_size. */ | |
c764a876 | 384 | unsigned int offset; |
348e048f | 385 | unsigned int length : 29; |
ae038cb0 DJ |
386 | |
387 | /* Flag indicating this compilation unit will be read in before | |
388 | any of the current compilation units are processed. */ | |
c764a876 | 389 | unsigned int queued : 1; |
ae038cb0 | 390 | |
5afb4e99 DJ |
391 | /* This flag will be set if we need to load absolutely all DIEs |
392 | for this compilation unit, instead of just the ones we think | |
393 | are interesting. It gets set if we look for a DIE in the | |
394 | hash table and don't find it. */ | |
395 | unsigned int load_all_dies : 1; | |
396 | ||
348e048f DE |
397 | /* Non-zero if this CU is from .debug_types. |
398 | Otherwise it's from .debug_info. */ | |
399 | unsigned int from_debug_types : 1; | |
400 | ||
17ea53c3 JK |
401 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
402 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 403 | struct dwarf2_cu *cu; |
1c379e20 DJ |
404 | |
405 | /* If full symbols for this CU have been read in, then this field | |
406 | holds a map of DIE offsets to types. It isn't always possible | |
407 | to reconstruct this information later, so we have to preserve | |
408 | it. */ | |
1c379e20 | 409 | htab_t type_hash; |
10b3939b | 410 | |
9291a0cd TT |
411 | /* The corresponding objfile. */ |
412 | struct objfile *objfile; | |
413 | ||
414 | /* When using partial symbol tables, the 'psymtab' field is active. | |
415 | Otherwise the 'quick' field is active. */ | |
416 | union | |
417 | { | |
418 | /* The partial symbol table associated with this compilation unit, | |
419 | or NULL for partial units (which do not have an associated | |
420 | symtab). */ | |
421 | struct partial_symtab *psymtab; | |
422 | ||
423 | /* Data needed by the "quick" functions. */ | |
424 | struct dwarf2_per_cu_quick_data *quick; | |
425 | } v; | |
ae038cb0 DJ |
426 | }; |
427 | ||
348e048f DE |
428 | /* Entry in the signatured_types hash table. */ |
429 | ||
430 | struct signatured_type | |
431 | { | |
432 | ULONGEST signature; | |
433 | ||
434 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
435 | unsigned int offset; | |
436 | ||
437 | /* Offset in .debug_types of the type defined by this TU. */ | |
438 | unsigned int type_offset; | |
439 | ||
440 | /* The CU(/TU) of this type. */ | |
441 | struct dwarf2_per_cu_data per_cu; | |
442 | }; | |
443 | ||
93311388 DE |
444 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
445 | which are used for both .debug_info and .debug_types dies. | |
446 | All parameters here are unchanging for the life of the call. | |
447 | This struct exists to abstract away the constant parameters of | |
448 | die reading. */ | |
449 | ||
450 | struct die_reader_specs | |
451 | { | |
452 | /* The bfd of this objfile. */ | |
453 | bfd* abfd; | |
454 | ||
455 | /* The CU of the DIE we are parsing. */ | |
456 | struct dwarf2_cu *cu; | |
457 | ||
458 | /* Pointer to start of section buffer. | |
459 | This is either the start of .debug_info or .debug_types. */ | |
460 | const gdb_byte *buffer; | |
461 | }; | |
462 | ||
debd256d JB |
463 | /* The line number information for a compilation unit (found in the |
464 | .debug_line section) begins with a "statement program header", | |
465 | which contains the following information. */ | |
466 | struct line_header | |
467 | { | |
468 | unsigned int total_length; | |
469 | unsigned short version; | |
470 | unsigned int header_length; | |
471 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 472 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
473 | unsigned char default_is_stmt; |
474 | int line_base; | |
475 | unsigned char line_range; | |
476 | unsigned char opcode_base; | |
477 | ||
478 | /* standard_opcode_lengths[i] is the number of operands for the | |
479 | standard opcode whose value is i. This means that | |
480 | standard_opcode_lengths[0] is unused, and the last meaningful | |
481 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
482 | unsigned char *standard_opcode_lengths; | |
483 | ||
484 | /* The include_directories table. NOTE! These strings are not | |
485 | allocated with xmalloc; instead, they are pointers into | |
486 | debug_line_buffer. If you try to free them, `free' will get | |
487 | indigestion. */ | |
488 | unsigned int num_include_dirs, include_dirs_size; | |
489 | char **include_dirs; | |
490 | ||
491 | /* The file_names table. NOTE! These strings are not allocated | |
492 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
493 | Don't try to free them directly. */ | |
494 | unsigned int num_file_names, file_names_size; | |
495 | struct file_entry | |
c906108c | 496 | { |
debd256d JB |
497 | char *name; |
498 | unsigned int dir_index; | |
499 | unsigned int mod_time; | |
500 | unsigned int length; | |
aaa75496 | 501 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 502 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
503 | } *file_names; |
504 | ||
505 | /* The start and end of the statement program following this | |
6502dd73 | 506 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 507 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 508 | }; |
c906108c SS |
509 | |
510 | /* When we construct a partial symbol table entry we only | |
511 | need this much information. */ | |
512 | struct partial_die_info | |
513 | { | |
72bf9492 | 514 | /* Offset of this DIE. */ |
c906108c | 515 | unsigned int offset; |
72bf9492 DJ |
516 | |
517 | /* DWARF-2 tag for this DIE. */ | |
518 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
519 | ||
72bf9492 DJ |
520 | /* Assorted flags describing the data found in this DIE. */ |
521 | unsigned int has_children : 1; | |
522 | unsigned int is_external : 1; | |
523 | unsigned int is_declaration : 1; | |
524 | unsigned int has_type : 1; | |
525 | unsigned int has_specification : 1; | |
526 | unsigned int has_pc_info : 1; | |
527 | ||
528 | /* Flag set if the SCOPE field of this structure has been | |
529 | computed. */ | |
530 | unsigned int scope_set : 1; | |
531 | ||
fa4028e9 JB |
532 | /* Flag set if the DIE has a byte_size attribute. */ |
533 | unsigned int has_byte_size : 1; | |
534 | ||
72bf9492 | 535 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 536 | sometimes a default name for unnamed DIEs. */ |
c906108c | 537 | char *name; |
72bf9492 DJ |
538 | |
539 | /* The scope to prepend to our children. This is generally | |
540 | allocated on the comp_unit_obstack, so will disappear | |
541 | when this compilation unit leaves the cache. */ | |
542 | char *scope; | |
543 | ||
544 | /* The location description associated with this DIE, if any. */ | |
545 | struct dwarf_block *locdesc; | |
546 | ||
547 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
548 | CORE_ADDR lowpc; |
549 | CORE_ADDR highpc; | |
72bf9492 | 550 | |
93311388 | 551 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 552 | DW_AT_sibling, if any. */ |
fe1b8b76 | 553 | gdb_byte *sibling; |
72bf9492 DJ |
554 | |
555 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
556 | DW_AT_specification (or DW_AT_abstract_origin or | |
557 | DW_AT_extension). */ | |
558 | unsigned int spec_offset; | |
559 | ||
560 | /* Pointers to this DIE's parent, first child, and next sibling, | |
561 | if any. */ | |
562 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
563 | }; |
564 | ||
565 | /* This data structure holds the information of an abbrev. */ | |
566 | struct abbrev_info | |
567 | { | |
568 | unsigned int number; /* number identifying abbrev */ | |
569 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
570 | unsigned short has_children; /* boolean */ |
571 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
572 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
573 | struct abbrev_info *next; /* next in chain */ | |
574 | }; | |
575 | ||
576 | struct attr_abbrev | |
577 | { | |
9d25dd43 DE |
578 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
579 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
580 | }; |
581 | ||
b60c80d6 DJ |
582 | /* Attributes have a name and a value */ |
583 | struct attribute | |
584 | { | |
9d25dd43 | 585 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
586 | ENUM_BITFIELD(dwarf_form) form : 15; |
587 | ||
588 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
589 | field should be in u.str (existing only for DW_STRING) but it is kept | |
590 | here for better struct attribute alignment. */ | |
591 | unsigned int string_is_canonical : 1; | |
592 | ||
b60c80d6 DJ |
593 | union |
594 | { | |
595 | char *str; | |
596 | struct dwarf_block *blk; | |
43bbcdc2 PH |
597 | ULONGEST unsnd; |
598 | LONGEST snd; | |
b60c80d6 | 599 | CORE_ADDR addr; |
348e048f | 600 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
601 | } |
602 | u; | |
603 | }; | |
604 | ||
c906108c SS |
605 | /* This data structure holds a complete die structure. */ |
606 | struct die_info | |
607 | { | |
76815b17 DE |
608 | /* DWARF-2 tag for this DIE. */ |
609 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
610 | ||
611 | /* Number of attributes */ | |
612 | unsigned short num_attrs; | |
613 | ||
614 | /* Abbrev number */ | |
615 | unsigned int abbrev; | |
616 | ||
93311388 | 617 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 618 | unsigned int offset; |
78ba4af6 JB |
619 | |
620 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
621 | points to this die's parent; CHILD points to the first child of | |
622 | this node; and all the children of a given node are chained | |
623 | together via their SIBLING fields, terminated by a die whose | |
624 | tag is zero. */ | |
639d11d3 DC |
625 | struct die_info *child; /* Its first child, if any. */ |
626 | struct die_info *sibling; /* Its next sibling, if any. */ | |
627 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 628 | |
b60c80d6 DJ |
629 | /* An array of attributes, with NUM_ATTRS elements. There may be |
630 | zero, but it's not common and zero-sized arrays are not | |
631 | sufficiently portable C. */ | |
632 | struct attribute attrs[1]; | |
c906108c SS |
633 | }; |
634 | ||
5fb290d7 DJ |
635 | struct function_range |
636 | { | |
637 | const char *name; | |
638 | CORE_ADDR lowpc, highpc; | |
639 | int seen_line; | |
640 | struct function_range *next; | |
641 | }; | |
642 | ||
c906108c SS |
643 | /* Get at parts of an attribute structure */ |
644 | ||
645 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 646 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
647 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
648 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
649 | #define DW_SND(attr) ((attr)->u.snd) | |
650 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 651 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
652 | |
653 | /* Blocks are a bunch of untyped bytes. */ | |
654 | struct dwarf_block | |
655 | { | |
656 | unsigned int size; | |
fe1b8b76 | 657 | gdb_byte *data; |
c906108c SS |
658 | }; |
659 | ||
c906108c SS |
660 | #ifndef ATTR_ALLOC_CHUNK |
661 | #define ATTR_ALLOC_CHUNK 4 | |
662 | #endif | |
663 | ||
c906108c SS |
664 | /* Allocate fields for structs, unions and enums in this size. */ |
665 | #ifndef DW_FIELD_ALLOC_CHUNK | |
666 | #define DW_FIELD_ALLOC_CHUNK 4 | |
667 | #endif | |
668 | ||
c906108c SS |
669 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
670 | but this would require a corresponding change in unpack_field_as_long | |
671 | and friends. */ | |
672 | static int bits_per_byte = 8; | |
673 | ||
674 | /* The routines that read and process dies for a C struct or C++ class | |
675 | pass lists of data member fields and lists of member function fields | |
676 | in an instance of a field_info structure, as defined below. */ | |
677 | struct field_info | |
c5aa993b JM |
678 | { |
679 | /* List of data member and baseclasses fields. */ | |
680 | struct nextfield | |
681 | { | |
682 | struct nextfield *next; | |
683 | int accessibility; | |
684 | int virtuality; | |
685 | struct field field; | |
686 | } | |
7d0ccb61 | 687 | *fields, *baseclasses; |
c906108c | 688 | |
7d0ccb61 | 689 | /* Number of fields (including baseclasses). */ |
c5aa993b | 690 | int nfields; |
c906108c | 691 | |
c5aa993b JM |
692 | /* Number of baseclasses. */ |
693 | int nbaseclasses; | |
c906108c | 694 | |
c5aa993b JM |
695 | /* Set if the accesibility of one of the fields is not public. */ |
696 | int non_public_fields; | |
c906108c | 697 | |
c5aa993b JM |
698 | /* Member function fields array, entries are allocated in the order they |
699 | are encountered in the object file. */ | |
700 | struct nextfnfield | |
701 | { | |
702 | struct nextfnfield *next; | |
703 | struct fn_field fnfield; | |
704 | } | |
705 | *fnfields; | |
c906108c | 706 | |
c5aa993b JM |
707 | /* Member function fieldlist array, contains name of possibly overloaded |
708 | member function, number of overloaded member functions and a pointer | |
709 | to the head of the member function field chain. */ | |
710 | struct fnfieldlist | |
711 | { | |
712 | char *name; | |
713 | int length; | |
714 | struct nextfnfield *head; | |
715 | } | |
716 | *fnfieldlists; | |
c906108c | 717 | |
c5aa993b JM |
718 | /* Number of entries in the fnfieldlists array. */ |
719 | int nfnfields; | |
98751a41 JK |
720 | |
721 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
722 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
723 | struct typedef_field_list | |
724 | { | |
725 | struct typedef_field field; | |
726 | struct typedef_field_list *next; | |
727 | } | |
728 | *typedef_field_list; | |
729 | unsigned typedef_field_list_count; | |
c5aa993b | 730 | }; |
c906108c | 731 | |
10b3939b DJ |
732 | /* One item on the queue of compilation units to read in full symbols |
733 | for. */ | |
734 | struct dwarf2_queue_item | |
735 | { | |
736 | struct dwarf2_per_cu_data *per_cu; | |
737 | struct dwarf2_queue_item *next; | |
738 | }; | |
739 | ||
740 | /* The current queue. */ | |
741 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
742 | ||
ae038cb0 DJ |
743 | /* Loaded secondary compilation units are kept in memory until they |
744 | have not been referenced for the processing of this many | |
745 | compilation units. Set this to zero to disable caching. Cache | |
746 | sizes of up to at least twenty will improve startup time for | |
747 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
748 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
749 | static void |
750 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
751 | struct cmd_list_element *c, const char *value) | |
752 | { | |
753 | fprintf_filtered (file, _("\ | |
754 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
755 | value); | |
756 | } | |
757 | ||
ae038cb0 | 758 | |
c906108c SS |
759 | /* Various complaints about symbol reading that don't abort the process */ |
760 | ||
4d3c2250 KB |
761 | static void |
762 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 763 | { |
4d3c2250 | 764 | complaint (&symfile_complaints, |
e2e0b3e5 | 765 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
766 | } |
767 | ||
25e43795 DJ |
768 | static void |
769 | dwarf2_debug_line_missing_file_complaint (void) | |
770 | { | |
771 | complaint (&symfile_complaints, | |
772 | _(".debug_line section has line data without a file")); | |
773 | } | |
774 | ||
59205f5a JB |
775 | static void |
776 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
777 | { | |
778 | complaint (&symfile_complaints, | |
779 | _(".debug_line section has line program sequence without an end")); | |
780 | } | |
781 | ||
4d3c2250 KB |
782 | static void |
783 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 784 | { |
e2e0b3e5 | 785 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
786 | } |
787 | ||
4d3c2250 KB |
788 | static void |
789 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
790 | int arg3) | |
2e276125 | 791 | { |
4d3c2250 | 792 | complaint (&symfile_complaints, |
e2e0b3e5 | 793 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
794 | arg2, arg3); |
795 | } | |
796 | ||
797 | static void | |
798 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 799 | { |
4d3c2250 | 800 | complaint (&symfile_complaints, |
e2e0b3e5 | 801 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
802 | } |
803 | ||
804 | static void | |
805 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 806 | { |
4d3c2250 | 807 | complaint (&symfile_complaints, |
e2e0b3e5 | 808 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
809 | arg1); |
810 | } | |
811 | ||
812 | static void | |
813 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 814 | { |
4d3c2250 | 815 | complaint (&symfile_complaints, |
e2e0b3e5 | 816 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 817 | } |
c906108c | 818 | |
c906108c SS |
819 | /* local function prototypes */ |
820 | ||
4efb68b1 | 821 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 822 | |
aaa75496 JB |
823 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
824 | struct objfile *); | |
825 | ||
826 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
d85a05f0 | 827 | struct die_info *, |
aaa75496 JB |
828 | struct partial_symtab *); |
829 | ||
c67a9c90 | 830 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 831 | |
72bf9492 DJ |
832 | static void scan_partial_symbols (struct partial_die_info *, |
833 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 834 | int, struct dwarf2_cu *); |
c906108c | 835 | |
72bf9492 DJ |
836 | static void add_partial_symbol (struct partial_die_info *, |
837 | struct dwarf2_cu *); | |
63d06c5c | 838 | |
72bf9492 DJ |
839 | static void add_partial_namespace (struct partial_die_info *pdi, |
840 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 841 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 842 | |
5d7cb8df JK |
843 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
844 | CORE_ADDR *highpc, int need_pc, | |
845 | struct dwarf2_cu *cu); | |
846 | ||
72bf9492 DJ |
847 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
848 | struct dwarf2_cu *cu); | |
91c24f0a | 849 | |
bc30ff58 JB |
850 | static void add_partial_subprogram (struct partial_die_info *pdi, |
851 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 852 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 853 | |
fe1b8b76 | 854 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
855 | gdb_byte *buffer, gdb_byte *info_ptr, |
856 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 857 | |
a14ed312 | 858 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 859 | |
a14ed312 | 860 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 861 | |
e7c27a73 | 862 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 863 | |
f3dd6933 | 864 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 865 | |
fe1b8b76 | 866 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 867 | struct dwarf2_cu *); |
72bf9492 | 868 | |
57349743 | 869 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 870 | struct dwarf2_cu *); |
c906108c | 871 | |
93311388 DE |
872 | static struct partial_die_info *load_partial_dies (bfd *, |
873 | gdb_byte *, gdb_byte *, | |
874 | int, struct dwarf2_cu *); | |
72bf9492 | 875 | |
fe1b8b76 | 876 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
877 | struct abbrev_info *abbrev, |
878 | unsigned int, bfd *, | |
879 | gdb_byte *, gdb_byte *, | |
880 | struct dwarf2_cu *); | |
c906108c | 881 | |
c764a876 | 882 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 883 | struct dwarf2_cu *); |
72bf9492 DJ |
884 | |
885 | static void fixup_partial_die (struct partial_die_info *, | |
886 | struct dwarf2_cu *); | |
887 | ||
fe1b8b76 JB |
888 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
889 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 890 | |
fe1b8b76 JB |
891 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
892 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 893 | |
fe1b8b76 | 894 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 895 | |
fe1b8b76 | 896 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 897 | |
fe1b8b76 | 898 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 899 | |
fe1b8b76 | 900 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 901 | |
93311388 | 902 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 903 | |
fe1b8b76 | 904 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 905 | unsigned int *); |
c906108c | 906 | |
c764a876 DE |
907 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
908 | ||
909 | static LONGEST read_checked_initial_length_and_offset | |
910 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
911 | unsigned int *, unsigned int *); | |
613e1657 | 912 | |
fe1b8b76 | 913 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
914 | unsigned int *); |
915 | ||
916 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 917 | |
fe1b8b76 | 918 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 919 | |
fe1b8b76 | 920 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 921 | |
fe1b8b76 JB |
922 | static char *read_indirect_string (bfd *, gdb_byte *, |
923 | const struct comp_unit_head *, | |
924 | unsigned int *); | |
4bdf3d34 | 925 | |
fe1b8b76 | 926 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 927 | |
fe1b8b76 | 928 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 929 | |
fe1b8b76 | 930 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 931 | |
e142c38c | 932 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 933 | |
e142c38c DJ |
934 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
935 | struct dwarf2_cu *); | |
c906108c | 936 | |
348e048f DE |
937 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
938 | unsigned int, | |
939 | struct dwarf2_cu *); | |
940 | ||
05cf31d1 JB |
941 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
942 | struct dwarf2_cu *cu); | |
943 | ||
e142c38c | 944 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 945 | |
e142c38c | 946 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 947 | struct dwarf2_cu **); |
63d06c5c | 948 | |
debd256d JB |
949 | static void free_line_header (struct line_header *lh); |
950 | ||
aaa75496 JB |
951 | static void add_file_name (struct line_header *, char *, unsigned int, |
952 | unsigned int, unsigned int); | |
953 | ||
debd256d JB |
954 | static struct line_header *(dwarf_decode_line_header |
955 | (unsigned int offset, | |
e7c27a73 | 956 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
957 | |
958 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 959 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 960 | |
4f1520fb | 961 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 962 | |
a14ed312 | 963 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 964 | struct dwarf2_cu *); |
c906108c | 965 | |
a14ed312 | 966 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 967 | struct dwarf2_cu *); |
c906108c | 968 | |
2df3850c JM |
969 | static void dwarf2_const_value_data (struct attribute *attr, |
970 | struct symbol *sym, | |
971 | int bits); | |
972 | ||
e7c27a73 | 973 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 974 | |
b4ba55a1 JB |
975 | static int need_gnat_info (struct dwarf2_cu *); |
976 | ||
977 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
978 | ||
979 | static void set_descriptive_type (struct type *, struct die_info *, | |
980 | struct dwarf2_cu *); | |
981 | ||
e7c27a73 DJ |
982 | static struct type *die_containing_type (struct die_info *, |
983 | struct dwarf2_cu *); | |
c906108c | 984 | |
e7c27a73 | 985 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 986 | |
f792889a | 987 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 988 | |
086ed43d | 989 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 990 | |
6e70227d | 991 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
992 | const char *suffix, int physname, |
993 | struct dwarf2_cu *cu); | |
63d06c5c | 994 | |
e7c27a73 | 995 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 996 | |
348e048f DE |
997 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
998 | ||
e7c27a73 | 999 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1000 | |
e7c27a73 | 1001 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1002 | |
ff013f42 JK |
1003 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1004 | struct dwarf2_cu *, struct partial_symtab *); | |
1005 | ||
a14ed312 | 1006 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1007 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1008 | struct partial_symtab *); | |
c906108c | 1009 | |
fae299cd DC |
1010 | static void get_scope_pc_bounds (struct die_info *, |
1011 | CORE_ADDR *, CORE_ADDR *, | |
1012 | struct dwarf2_cu *); | |
1013 | ||
801e3a5b JB |
1014 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1015 | CORE_ADDR, struct dwarf2_cu *); | |
1016 | ||
a14ed312 | 1017 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1018 | struct dwarf2_cu *); |
c906108c | 1019 | |
a14ed312 | 1020 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1021 | struct type *, struct dwarf2_cu *); |
c906108c | 1022 | |
a14ed312 | 1023 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1024 | struct die_info *, struct type *, |
e7c27a73 | 1025 | struct dwarf2_cu *); |
c906108c | 1026 | |
a14ed312 | 1027 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 1028 | struct type *, struct dwarf2_cu *); |
c906108c | 1029 | |
134d01f1 | 1030 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1031 | |
e7c27a73 | 1032 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1033 | |
e7c27a73 | 1034 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1035 | |
5d7cb8df JK |
1036 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1037 | ||
27aa8d6a SW |
1038 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1039 | ||
f55ee35c JK |
1040 | static struct type *read_module_type (struct die_info *die, |
1041 | struct dwarf2_cu *cu); | |
1042 | ||
38d518c9 | 1043 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1044 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1045 | |
134d01f1 | 1046 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1047 | |
e7c27a73 | 1048 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1049 | |
6e70227d | 1050 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1051 | struct dwarf2_cu *); |
1052 | ||
93311388 | 1053 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1054 | |
93311388 DE |
1055 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1056 | gdb_byte *info_ptr, | |
d97bc12b DE |
1057 | gdb_byte **new_info_ptr, |
1058 | struct die_info *parent); | |
1059 | ||
93311388 DE |
1060 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1061 | gdb_byte *info_ptr, | |
fe1b8b76 | 1062 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1063 | struct die_info *parent); |
1064 | ||
93311388 DE |
1065 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1066 | gdb_byte *info_ptr, | |
fe1b8b76 | 1067 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1068 | struct die_info *parent); |
1069 | ||
93311388 DE |
1070 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1071 | struct die_info **, gdb_byte *, | |
1072 | int *); | |
1073 | ||
e7c27a73 | 1074 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1075 | |
71c25dea TT |
1076 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1077 | struct obstack *); | |
1078 | ||
e142c38c | 1079 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1080 | |
e142c38c | 1081 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1082 | struct dwarf2_cu **); |
9219021c | 1083 | |
a14ed312 | 1084 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1085 | |
a14ed312 | 1086 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1087 | |
a14ed312 | 1088 | static char *dwarf_form_name (unsigned int); |
c906108c | 1089 | |
a14ed312 | 1090 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1091 | |
a14ed312 | 1092 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1093 | |
1094 | #if 0 | |
a14ed312 | 1095 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1096 | #endif |
1097 | ||
f9aca02d | 1098 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1099 | |
d97bc12b DE |
1100 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1101 | ||
1102 | static void dump_die_for_error (struct die_info *); | |
1103 | ||
1104 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1105 | struct die_info *); | |
c906108c | 1106 | |
d97bc12b | 1107 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1108 | |
51545339 | 1109 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1110 | struct dwarf2_cu *); |
c906108c | 1111 | |
93311388 DE |
1112 | static int is_ref_attr (struct attribute *); |
1113 | ||
c764a876 | 1114 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1115 | |
43bbcdc2 | 1116 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1117 | |
348e048f DE |
1118 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1119 | struct attribute *, | |
1120 | struct dwarf2_cu **); | |
1121 | ||
10b3939b DJ |
1122 | static struct die_info *follow_die_ref (struct die_info *, |
1123 | struct attribute *, | |
f2f0e013 | 1124 | struct dwarf2_cu **); |
c906108c | 1125 | |
348e048f DE |
1126 | static struct die_info *follow_die_sig (struct die_info *, |
1127 | struct attribute *, | |
1128 | struct dwarf2_cu **); | |
1129 | ||
1130 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1131 | unsigned int offset); | |
1132 | ||
1133 | static void read_signatured_type (struct objfile *, | |
1134 | struct signatured_type *type_sig); | |
1135 | ||
c906108c SS |
1136 | /* memory allocation interface */ |
1137 | ||
7b5a2f43 | 1138 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1139 | |
f3dd6933 | 1140 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1141 | |
b60c80d6 | 1142 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1143 | |
e142c38c | 1144 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1145 | |
e142c38c DJ |
1146 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1147 | struct dwarf2_cu *); | |
5fb290d7 | 1148 | |
2e276125 | 1149 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1150 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1151 | |
8e19ed76 PS |
1152 | static int attr_form_is_block (struct attribute *); |
1153 | ||
3690dd37 JB |
1154 | static int attr_form_is_section_offset (struct attribute *); |
1155 | ||
1156 | static int attr_form_is_constant (struct attribute *); | |
1157 | ||
93e7bd98 DJ |
1158 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1159 | struct symbol *sym, | |
1160 | struct dwarf2_cu *cu); | |
4c2df51b | 1161 | |
93311388 DE |
1162 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1163 | struct abbrev_info *abbrev, | |
1164 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1165 | |
72bf9492 DJ |
1166 | static void free_stack_comp_unit (void *); |
1167 | ||
72bf9492 DJ |
1168 | static hashval_t partial_die_hash (const void *item); |
1169 | ||
1170 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1171 | ||
ae038cb0 | 1172 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1173 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1174 | |
1175 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1176 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1177 | |
93311388 DE |
1178 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1179 | ||
ae038cb0 DJ |
1180 | static void free_one_comp_unit (void *); |
1181 | ||
1182 | static void free_cached_comp_units (void *); | |
1183 | ||
1184 | static void age_cached_comp_units (void); | |
1185 | ||
1186 | static void free_one_cached_comp_unit (void *); | |
1187 | ||
f792889a DJ |
1188 | static struct type *set_die_type (struct die_info *, struct type *, |
1189 | struct dwarf2_cu *); | |
1c379e20 | 1190 | |
ae038cb0 DJ |
1191 | static void create_all_comp_units (struct objfile *); |
1192 | ||
93311388 DE |
1193 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1194 | struct objfile *); | |
10b3939b DJ |
1195 | |
1196 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1197 | ||
1198 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1199 | struct dwarf2_per_cu_data *); | |
1200 | ||
ae038cb0 DJ |
1201 | static void dwarf2_mark (struct dwarf2_cu *); |
1202 | ||
1203 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1204 | ||
f792889a | 1205 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1206 | |
9291a0cd TT |
1207 | static void dwarf2_release_queue (void *dummy); |
1208 | ||
1209 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1210 | struct objfile *objfile); | |
1211 | ||
1212 | static void process_queue (struct objfile *objfile); | |
1213 | ||
1214 | static void find_file_and_directory (struct die_info *die, | |
1215 | struct dwarf2_cu *cu, | |
1216 | char **name, char **comp_dir); | |
1217 | ||
1218 | static char *file_full_name (int file, struct line_header *lh, | |
1219 | const char *comp_dir); | |
1220 | ||
1221 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1222 | gdb_byte *info_ptr, | |
1223 | gdb_byte *buffer, | |
1224 | unsigned int buffer_size, | |
1225 | bfd *abfd); | |
1226 | ||
1227 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1228 | struct dwarf2_cu *cu); | |
1229 | ||
1230 | #if WORDS_BIGENDIAN | |
1231 | ||
1232 | /* Convert VALUE between big- and little-endian. */ | |
1233 | static offset_type | |
1234 | byte_swap (offset_type value) | |
1235 | { | |
1236 | offset_type result; | |
1237 | ||
1238 | result = (value & 0xff) << 24; | |
1239 | result |= (value & 0xff00) << 8; | |
1240 | result |= (value & 0xff0000) >> 8; | |
1241 | result |= (value & 0xff000000) >> 24; | |
1242 | return result; | |
1243 | } | |
1244 | ||
1245 | #define MAYBE_SWAP(V) byte_swap (V) | |
1246 | ||
1247 | #else | |
1248 | #define MAYBE_SWAP(V) (V) | |
1249 | #endif /* WORDS_BIGENDIAN */ | |
1250 | ||
1251 | /* The suffix for an index file. */ | |
1252 | #define INDEX_SUFFIX ".gdb-index" | |
1253 | ||
c906108c SS |
1254 | /* Try to locate the sections we need for DWARF 2 debugging |
1255 | information and return true if we have enough to do something. */ | |
1256 | ||
1257 | int | |
6502dd73 | 1258 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1259 | { |
be391dca TT |
1260 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1261 | if (!dwarf2_per_objfile) | |
1262 | { | |
1263 | /* Initialize per-objfile state. */ | |
1264 | struct dwarf2_per_objfile *data | |
1265 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1266 | |
be391dca TT |
1267 | memset (data, 0, sizeof (*data)); |
1268 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1269 | dwarf2_per_objfile = data; | |
6502dd73 | 1270 | |
be391dca TT |
1271 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
1272 | dwarf2_per_objfile->objfile = objfile; | |
1273 | } | |
1274 | return (dwarf2_per_objfile->info.asection != NULL | |
1275 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1276 | } |
1277 | ||
233a11ab CS |
1278 | /* When loading sections, we can either look for ".<name>", or for |
1279 | * ".z<name>", which indicates a compressed section. */ | |
1280 | ||
1281 | static int | |
dce234bc | 1282 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1283 | { |
dce234bc PP |
1284 | return (section_name[0] == '.' |
1285 | && (strcmp (section_name + 1, name) == 0 | |
1286 | || (section_name[1] == 'z' | |
1287 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1288 | } |
1289 | ||
c906108c SS |
1290 | /* This function is mapped across the sections and remembers the |
1291 | offset and size of each of the debugging sections we are interested | |
1292 | in. */ | |
1293 | ||
1294 | static void | |
72dca2f5 | 1295 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1296 | { |
dce234bc | 1297 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1298 | { |
dce234bc PP |
1299 | dwarf2_per_objfile->info.asection = sectp; |
1300 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1301 | } |
dce234bc | 1302 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1303 | { |
dce234bc PP |
1304 | dwarf2_per_objfile->abbrev.asection = sectp; |
1305 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1306 | } |
dce234bc | 1307 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1308 | { |
dce234bc PP |
1309 | dwarf2_per_objfile->line.asection = sectp; |
1310 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1311 | } |
dce234bc | 1312 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1313 | { |
dce234bc PP |
1314 | dwarf2_per_objfile->loc.asection = sectp; |
1315 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1316 | } |
dce234bc | 1317 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1318 | { |
dce234bc PP |
1319 | dwarf2_per_objfile->macinfo.asection = sectp; |
1320 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1321 | } |
dce234bc | 1322 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1323 | { |
dce234bc PP |
1324 | dwarf2_per_objfile->str.asection = sectp; |
1325 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1326 | } |
dce234bc | 1327 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1328 | { |
dce234bc PP |
1329 | dwarf2_per_objfile->frame.asection = sectp; |
1330 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1331 | } |
dce234bc | 1332 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1333 | { |
3799ccc6 | 1334 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1335 | |
3799ccc6 EZ |
1336 | if (aflag & SEC_HAS_CONTENTS) |
1337 | { | |
dce234bc PP |
1338 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1339 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1340 | } |
b6af0555 | 1341 | } |
dce234bc | 1342 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1343 | { |
dce234bc PP |
1344 | dwarf2_per_objfile->ranges.asection = sectp; |
1345 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1346 | } |
348e048f DE |
1347 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1348 | { | |
1349 | dwarf2_per_objfile->types.asection = sectp; | |
1350 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1351 | } | |
9291a0cd TT |
1352 | else if (section_is_p (sectp->name, GDB_INDEX_SECTION)) |
1353 | { | |
1354 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1355 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1356 | } | |
dce234bc | 1357 | |
72dca2f5 FR |
1358 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1359 | && bfd_section_vma (abfd, sectp) == 0) | |
1360 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1361 | } |
1362 | ||
dce234bc PP |
1363 | /* Decompress a section that was compressed using zlib. Store the |
1364 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1365 | |
1366 | static void | |
dce234bc PP |
1367 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1368 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1369 | { | |
1370 | bfd *abfd = objfile->obfd; | |
1371 | #ifndef HAVE_ZLIB_H | |
1372 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1373 | "is disabled in this copy of GDB"), | |
1374 | bfd_get_filename (abfd)); | |
1375 | #else | |
1376 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1377 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1378 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1379 | bfd_size_type uncompressed_size; |
1380 | gdb_byte *uncompressed_buffer; | |
1381 | z_stream strm; | |
1382 | int rc; | |
1383 | int header_size = 12; | |
1384 | ||
1385 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1386 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1387 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1388 | bfd_get_filename (abfd)); | |
1389 | ||
1390 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1391 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1392 | if (compressed_size < header_size | |
1393 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1394 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1395 | bfd_get_filename (abfd)); | |
1396 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1397 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1398 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1399 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1400 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1401 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1402 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1403 | uncompressed_size += compressed_buffer[11]; | |
1404 | ||
1405 | /* It is possible the section consists of several compressed | |
1406 | buffers concatenated together, so we uncompress in a loop. */ | |
1407 | strm.zalloc = NULL; | |
1408 | strm.zfree = NULL; | |
1409 | strm.opaque = NULL; | |
1410 | strm.avail_in = compressed_size - header_size; | |
1411 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1412 | strm.avail_out = uncompressed_size; | |
1413 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1414 | uncompressed_size); | |
1415 | rc = inflateInit (&strm); | |
1416 | while (strm.avail_in > 0) | |
1417 | { | |
1418 | if (rc != Z_OK) | |
1419 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1420 | bfd_get_filename (abfd), rc); | |
1421 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1422 | + (uncompressed_size - strm.avail_out)); | |
1423 | rc = inflate (&strm, Z_FINISH); | |
1424 | if (rc != Z_STREAM_END) | |
1425 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1426 | bfd_get_filename (abfd), rc); | |
1427 | rc = inflateReset (&strm); | |
1428 | } | |
1429 | rc = inflateEnd (&strm); | |
1430 | if (rc != Z_OK | |
1431 | || strm.avail_out != 0) | |
1432 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1433 | bfd_get_filename (abfd), rc); | |
1434 | ||
affddf13 | 1435 | do_cleanups (cleanup); |
dce234bc PP |
1436 | *outbuf = uncompressed_buffer; |
1437 | *outsize = uncompressed_size; | |
1438 | #endif | |
233a11ab CS |
1439 | } |
1440 | ||
dce234bc PP |
1441 | /* Read the contents of the section SECTP from object file specified by |
1442 | OBJFILE, store info about the section into INFO. | |
1443 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1444 | |
dce234bc PP |
1445 | static void |
1446 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1447 | { |
dce234bc PP |
1448 | bfd *abfd = objfile->obfd; |
1449 | asection *sectp = info->asection; | |
1450 | gdb_byte *buf, *retbuf; | |
1451 | unsigned char header[4]; | |
c906108c | 1452 | |
be391dca TT |
1453 | if (info->readin) |
1454 | return; | |
dce234bc PP |
1455 | info->buffer = NULL; |
1456 | info->was_mmapped = 0; | |
be391dca | 1457 | info->readin = 1; |
188dd5d6 | 1458 | |
dce234bc PP |
1459 | if (info->asection == NULL || info->size == 0) |
1460 | return; | |
c906108c | 1461 | |
dce234bc PP |
1462 | /* Check if the file has a 4-byte header indicating compression. */ |
1463 | if (info->size > sizeof (header) | |
1464 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1465 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1466 | { | |
1467 | /* Upon decompression, update the buffer and its size. */ | |
1468 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1469 | { | |
1470 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1471 | &info->size); | |
1472 | return; | |
1473 | } | |
1474 | } | |
4bdf3d34 | 1475 | |
dce234bc PP |
1476 | #ifdef HAVE_MMAP |
1477 | if (pagesize == 0) | |
1478 | pagesize = getpagesize (); | |
2e276125 | 1479 | |
dce234bc PP |
1480 | /* Only try to mmap sections which are large enough: we don't want to |
1481 | waste space due to fragmentation. Also, only try mmap for sections | |
1482 | without relocations. */ | |
1483 | ||
1484 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1485 | { | |
1486 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1487 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1488 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1489 | MAP_PRIVATE, pg_offset); | |
1490 | ||
1491 | if (retbuf != MAP_FAILED) | |
1492 | { | |
1493 | info->was_mmapped = 1; | |
1494 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1495 | #if HAVE_POSIX_MADVISE |
1496 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1497 | #endif | |
dce234bc PP |
1498 | return; |
1499 | } | |
1500 | } | |
1501 | #endif | |
1502 | ||
1503 | /* If we get here, we are a normal, not-compressed section. */ | |
1504 | info->buffer = buf | |
1505 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1506 | ||
1507 | /* When debugging .o files, we may need to apply relocations; see | |
1508 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1509 | We never compress sections in .o files, so we only need to | |
1510 | try this when the section is not compressed. */ | |
ac8035ab | 1511 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1512 | if (retbuf != NULL) |
1513 | { | |
1514 | info->buffer = retbuf; | |
1515 | return; | |
1516 | } | |
1517 | ||
1518 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1519 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1520 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1521 | bfd_get_filename (abfd)); | |
1522 | } | |
1523 | ||
1524 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1525 | SECTION_NAME. */ | |
af34e669 | 1526 | |
dce234bc PP |
1527 | void |
1528 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1529 | asection **sectp, gdb_byte **bufp, | |
1530 | bfd_size_type *sizep) | |
1531 | { | |
1532 | struct dwarf2_per_objfile *data | |
1533 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1534 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1535 | |
1536 | /* We may see an objfile without any DWARF, in which case we just | |
1537 | return nothing. */ | |
1538 | if (data == NULL) | |
1539 | { | |
1540 | *sectp = NULL; | |
1541 | *bufp = NULL; | |
1542 | *sizep = 0; | |
1543 | return; | |
1544 | } | |
dce234bc PP |
1545 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
1546 | info = &data->eh_frame; | |
1547 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1548 | info = &data->frame; | |
0d53c4c4 | 1549 | else |
dce234bc PP |
1550 | gdb_assert (0); |
1551 | ||
1552 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1553 | /* We haven't read this section in yet. Do it now. */ | |
1554 | dwarf2_read_section (objfile, info); | |
1555 | ||
1556 | *sectp = info->asection; | |
1557 | *bufp = info->buffer; | |
1558 | *sizep = info->size; | |
1559 | } | |
1560 | ||
9291a0cd TT |
1561 | \f |
1562 | ||
1563 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which | |
1564 | this CU came. */ | |
1565 | static void | |
1566 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1567 | struct dwarf2_per_cu_data *per_cu) | |
1568 | { | |
1569 | struct cleanup *back_to; | |
1570 | ||
1571 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1572 | ||
1573 | queue_comp_unit (per_cu, objfile); | |
1574 | ||
1575 | if (per_cu->from_debug_types) | |
1576 | read_signatured_type_at_offset (objfile, per_cu->offset); | |
1577 | else | |
1578 | load_full_comp_unit (per_cu, objfile); | |
1579 | ||
1580 | process_queue (objfile); | |
1581 | ||
1582 | /* Age the cache, releasing compilation units that have not | |
1583 | been used recently. */ | |
1584 | age_cached_comp_units (); | |
1585 | ||
1586 | do_cleanups (back_to); | |
1587 | } | |
1588 | ||
1589 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1590 | the objfile from which this CU came. Returns the resulting symbol | |
1591 | table. */ | |
1592 | static struct symtab * | |
1593 | dw2_instantiate_symtab (struct objfile *objfile, | |
1594 | struct dwarf2_per_cu_data *per_cu) | |
1595 | { | |
1596 | if (!per_cu->v.quick->symtab) | |
1597 | { | |
1598 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1599 | increment_reading_symtab (); | |
1600 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1601 | do_cleanups (back_to); | |
1602 | } | |
1603 | return per_cu->v.quick->symtab; | |
1604 | } | |
1605 | ||
1606 | /* A helper function that knows how to read a 64-bit value in a way | |
1607 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1608 | otherwise. */ | |
1609 | static int | |
1610 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1611 | { | |
1612 | if (sizeof (ULONGEST) < 8) | |
1613 | { | |
1614 | int i; | |
1615 | ||
1616 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1617 | for (i = 0; i < 4; ++i) | |
1618 | if (bytes[i + 4] != 0) | |
1619 | return 0; | |
1620 | ||
1621 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1622 | } | |
1623 | else | |
1624 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1625 | return 1; | |
1626 | } | |
1627 | ||
1628 | /* Read the CU list from the mapped index, and use it to create all | |
1629 | the CU objects for this objfile. Return 0 if something went wrong, | |
1630 | 1 if everything went ok. */ | |
1631 | static int | |
1632 | create_cus_from_index (struct objfile *objfile, struct mapped_index *index, | |
1633 | const gdb_byte *cu_list, offset_type cu_list_elements) | |
1634 | { | |
1635 | offset_type i; | |
1636 | const char *entry; | |
1637 | ||
1638 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1639 | dwarf2_per_objfile->all_comp_units | |
1640 | = obstack_alloc (&objfile->objfile_obstack, | |
1641 | dwarf2_per_objfile->n_comp_units | |
1642 | * sizeof (struct dwarf2_per_cu_data *)); | |
1643 | ||
1644 | for (i = 0; i < cu_list_elements; i += 2) | |
1645 | { | |
1646 | struct dwarf2_per_cu_data *the_cu; | |
1647 | ULONGEST offset, length; | |
1648 | ||
1649 | if (!extract_cu_value (cu_list, &offset) | |
1650 | || !extract_cu_value (cu_list + 8, &length)) | |
1651 | return 0; | |
1652 | cu_list += 2 * 8; | |
1653 | ||
1654 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1655 | struct dwarf2_per_cu_data); | |
1656 | the_cu->offset = offset; | |
1657 | the_cu->length = length; | |
1658 | the_cu->objfile = objfile; | |
1659 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1660 | struct dwarf2_per_cu_quick_data); | |
1661 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1662 | } | |
1663 | ||
1664 | return 1; | |
1665 | } | |
1666 | ||
1667 | /* Read the address map data from the mapped index, and use it to | |
1668 | populate the objfile's psymtabs_addrmap. */ | |
1669 | static void | |
1670 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1671 | { | |
1672 | const gdb_byte *iter, *end; | |
1673 | struct obstack temp_obstack; | |
1674 | struct addrmap *mutable_map; | |
1675 | struct cleanup *cleanup; | |
1676 | CORE_ADDR baseaddr; | |
1677 | ||
1678 | obstack_init (&temp_obstack); | |
1679 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1680 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1681 | ||
1682 | iter = index->address_table; | |
1683 | end = iter + index->address_table_size; | |
1684 | ||
1685 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1686 | ||
1687 | while (iter < end) | |
1688 | { | |
1689 | ULONGEST hi, lo, cu_index; | |
1690 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1691 | iter += 8; | |
1692 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1693 | iter += 8; | |
1694 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1695 | iter += 4; | |
1696 | ||
1697 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1698 | dwarf2_per_objfile->all_comp_units[cu_index]); | |
1699 | } | |
1700 | ||
1701 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1702 | &objfile->objfile_obstack); | |
1703 | do_cleanups (cleanup); | |
1704 | } | |
1705 | ||
1706 | /* The hash function for strings in the mapped index. This is the | |
1707 | same as the hashtab.c hash function, but we keep a separate copy to | |
1708 | maintain control over the implementation. This is necessary | |
1709 | because the hash function is tied to the format of the mapped index | |
1710 | file. */ | |
1711 | static hashval_t | |
1712 | mapped_index_string_hash (const void *p) | |
1713 | { | |
1714 | const unsigned char *str = (const unsigned char *) p; | |
1715 | hashval_t r = 0; | |
1716 | unsigned char c; | |
1717 | ||
1718 | while ((c = *str++) != 0) | |
1719 | r = r * 67 + c - 113; | |
1720 | ||
1721 | return r; | |
1722 | } | |
1723 | ||
1724 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
1725 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
1726 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
1727 | static int | |
1728 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
1729 | offset_type **vec_out) | |
1730 | { | |
1731 | offset_type hash = mapped_index_string_hash (name); | |
1732 | offset_type slot, step; | |
1733 | ||
1734 | slot = hash & (index->index_table_slots - 1); | |
1735 | step = ((hash * 17) & (index->index_table_slots - 1)) | 1; | |
1736 | ||
1737 | for (;;) | |
1738 | { | |
1739 | /* Convert a slot number to an offset into the table. */ | |
1740 | offset_type i = 2 * slot; | |
1741 | const char *str; | |
1742 | if (index->index_table[i] == 0 && index->index_table[i + 1] == 0) | |
1743 | return 0; | |
1744 | ||
1745 | str = index->constant_pool + MAYBE_SWAP (index->index_table[i]); | |
1746 | if (!strcmp (name, str)) | |
1747 | { | |
1748 | *vec_out = (offset_type *) (index->constant_pool | |
1749 | + MAYBE_SWAP (index->index_table[i + 1])); | |
1750 | return 1; | |
1751 | } | |
1752 | ||
1753 | slot = (slot + step) & (index->index_table_slots - 1); | |
1754 | } | |
1755 | } | |
1756 | ||
1757 | /* Read the index file. If everything went ok, initialize the "quick" | |
1758 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
1759 | static int | |
1760 | dwarf2_read_index (struct objfile *objfile) | |
1761 | { | |
9291a0cd TT |
1762 | char *addr; |
1763 | struct mapped_index *map; | |
b3b272e1 | 1764 | offset_type *metadata; |
9291a0cd TT |
1765 | const gdb_byte *cu_list; |
1766 | offset_type cu_list_elements; | |
1767 | ||
1768 | if (dwarf2_per_objfile->gdb_index.asection == NULL | |
1769 | || dwarf2_per_objfile->gdb_index.size == 0) | |
1770 | return 0; | |
1771 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); | |
1772 | ||
1773 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
1774 | /* Version check. */ | |
1775 | if (MAYBE_SWAP (*(offset_type *) addr) != 1) | |
1776 | return 0; | |
1777 | ||
1778 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
b3b272e1 | 1779 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
1780 | |
1781 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1782 | cu_list = addr + MAYBE_SWAP (metadata[0]); | |
1783 | cu_list_elements = ((MAYBE_SWAP (metadata[1]) - MAYBE_SWAP (metadata[0])) | |
1784 | / 8); | |
1785 | map->address_table = addr + MAYBE_SWAP (metadata[1]); | |
1786 | map->address_table_size = (MAYBE_SWAP (metadata[2]) | |
1787 | - MAYBE_SWAP (metadata[1])); | |
1788 | map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[2])); | |
1789 | map->index_table_slots = ((MAYBE_SWAP (metadata[3]) | |
1790 | - MAYBE_SWAP (metadata[2])) | |
1791 | / (2 * sizeof (offset_type))); | |
1792 | map->constant_pool = addr + MAYBE_SWAP (metadata[3]); | |
1793 | ||
1794 | if (!create_cus_from_index (objfile, map, cu_list, cu_list_elements)) | |
1795 | return 0; | |
1796 | ||
1797 | create_addrmap_from_index (objfile, map); | |
1798 | ||
1799 | dwarf2_per_objfile->index_table = map; | |
1800 | dwarf2_per_objfile->using_index = 1; | |
1801 | ||
1802 | return 1; | |
1803 | } | |
1804 | ||
1805 | /* A helper for the "quick" functions which sets the global | |
1806 | dwarf2_per_objfile according to OBJFILE. */ | |
1807 | static void | |
1808 | dw2_setup (struct objfile *objfile) | |
1809 | { | |
1810 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
1811 | gdb_assert (dwarf2_per_objfile); | |
1812 | } | |
1813 | ||
1814 | /* A helper for the "quick" functions which attempts to read the line | |
1815 | table for THIS_CU. */ | |
1816 | static void | |
1817 | dw2_require_line_header (struct objfile *objfile, | |
1818 | struct dwarf2_per_cu_data *this_cu) | |
1819 | { | |
1820 | bfd *abfd = objfile->obfd; | |
1821 | struct line_header *lh = NULL; | |
1822 | struct attribute *attr; | |
1823 | struct cleanup *cleanups; | |
1824 | struct die_info *comp_unit_die; | |
1825 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; | |
1826 | int has_children, i; | |
1827 | struct dwarf2_cu cu; | |
1828 | unsigned int bytes_read, buffer_size; | |
1829 | struct die_reader_specs reader_specs; | |
1830 | char *name, *comp_dir; | |
1831 | ||
1832 | if (this_cu->v.quick->read_lines) | |
1833 | return; | |
1834 | this_cu->v.quick->read_lines = 1; | |
1835 | ||
1836 | memset (&cu, 0, sizeof (cu)); | |
1837 | cu.objfile = objfile; | |
1838 | obstack_init (&cu.comp_unit_obstack); | |
1839 | ||
1840 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
1841 | ||
1842 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
1843 | buffer_size = dwarf2_per_objfile->info.size; | |
1844 | buffer = dwarf2_per_objfile->info.buffer; | |
1845 | info_ptr = buffer + this_cu->offset; | |
1846 | beg_of_comp_unit = info_ptr; | |
1847 | ||
1848 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
1849 | buffer, buffer_size, | |
1850 | abfd); | |
1851 | ||
1852 | /* Complete the cu_header. */ | |
1853 | cu.header.offset = beg_of_comp_unit - buffer; | |
1854 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
1855 | ||
1856 | this_cu->cu = &cu; | |
1857 | cu.per_cu = this_cu; | |
1858 | ||
1859 | dwarf2_read_abbrevs (abfd, &cu); | |
1860 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
1861 | ||
1862 | if (this_cu->from_debug_types) | |
1863 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
1864 | init_cu_die_reader (&reader_specs, &cu); | |
1865 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
1866 | &has_children); | |
1867 | ||
1868 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); | |
1869 | if (attr) | |
1870 | { | |
1871 | unsigned int line_offset = DW_UNSND (attr); | |
1872 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); | |
1873 | } | |
1874 | if (lh == NULL) | |
1875 | { | |
1876 | do_cleanups (cleanups); | |
1877 | return; | |
1878 | } | |
1879 | ||
1880 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); | |
1881 | ||
1882 | this_cu->v.quick->lines = lh; | |
1883 | ||
1884 | this_cu->v.quick->file_names | |
1885 | = obstack_alloc (&objfile->objfile_obstack, | |
1886 | lh->num_file_names * sizeof (char *)); | |
1887 | for (i = 0; i < lh->num_file_names; ++i) | |
1888 | this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir); | |
1889 | ||
1890 | do_cleanups (cleanups); | |
1891 | } | |
1892 | ||
1893 | /* A helper for the "quick" functions which computes and caches the | |
1894 | real path for a given file name from the line table. | |
1895 | dw2_require_line_header must have been called before this is | |
1896 | invoked. */ | |
1897 | static const char * | |
1898 | dw2_require_full_path (struct objfile *objfile, | |
1899 | struct dwarf2_per_cu_data *cu, | |
1900 | int index) | |
1901 | { | |
1902 | if (!cu->v.quick->full_names) | |
1903 | cu->v.quick->full_names | |
1904 | = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
1905 | cu->v.quick->lines->num_file_names, | |
1906 | sizeof (char *)); | |
1907 | ||
1908 | if (!cu->v.quick->full_names[index]) | |
1909 | cu->v.quick->full_names[index] | |
1910 | = gdb_realpath (cu->v.quick->file_names[index]); | |
1911 | ||
1912 | return cu->v.quick->full_names[index]; | |
1913 | } | |
1914 | ||
1915 | static struct symtab * | |
1916 | dw2_find_last_source_symtab (struct objfile *objfile) | |
1917 | { | |
1918 | int index; | |
1919 | dw2_setup (objfile); | |
1920 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1921 | return dw2_instantiate_symtab (objfile, | |
1922 | dwarf2_per_objfile->all_comp_units[index]); | |
1923 | } | |
1924 | ||
1925 | static void | |
1926 | dw2_forget_cached_source_info (struct objfile *objfile) | |
1927 | { | |
1928 | int i; | |
1929 | ||
1930 | dw2_setup (objfile); | |
1931 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
1932 | { | |
1933 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
1934 | ||
1935 | if (cu->v.quick->full_names) | |
1936 | { | |
1937 | int j; | |
1938 | ||
1939 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
1940 | xfree ((void *) cu->v.quick->full_names[j]); | |
1941 | } | |
1942 | } | |
1943 | } | |
1944 | ||
1945 | static int | |
1946 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
1947 | const char *full_path, const char *real_path, | |
1948 | struct symtab **result) | |
1949 | { | |
1950 | int i; | |
1951 | int check_basename = lbasename (name) == name; | |
1952 | struct dwarf2_per_cu_data *base_cu = NULL; | |
1953 | ||
1954 | dw2_setup (objfile); | |
1955 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
1956 | { | |
1957 | int j; | |
1958 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
1959 | ||
1960 | if (cu->v.quick->symtab) | |
1961 | continue; | |
1962 | ||
1963 | dw2_require_line_header (objfile, cu); | |
1964 | if (!cu->v.quick->lines) | |
1965 | continue; | |
1966 | ||
1967 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
1968 | { | |
1969 | const char *this_name = cu->v.quick->file_names[j]; | |
1970 | ||
1971 | if (FILENAME_CMP (name, this_name) == 0) | |
1972 | { | |
1973 | *result = dw2_instantiate_symtab (objfile, cu); | |
1974 | return 1; | |
1975 | } | |
1976 | ||
1977 | if (check_basename && ! base_cu | |
1978 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
1979 | base_cu = cu; | |
1980 | ||
1981 | if (full_path != NULL) | |
1982 | { | |
1983 | const char *this_full_name = dw2_require_full_path (objfile, | |
1984 | cu, j); | |
1985 | ||
1986 | if (this_full_name | |
1987 | && FILENAME_CMP (full_path, this_full_name) == 0) | |
1988 | { | |
1989 | *result = dw2_instantiate_symtab (objfile, cu); | |
1990 | return 1; | |
1991 | } | |
1992 | } | |
1993 | ||
1994 | if (real_path != NULL) | |
1995 | { | |
1996 | const char *this_full_name = dw2_require_full_path (objfile, | |
1997 | cu, j); | |
1998 | ||
1999 | if (this_full_name != NULL) | |
2000 | { | |
2001 | char *rp = gdb_realpath (this_full_name); | |
2002 | if (rp != NULL && FILENAME_CMP (real_path, rp) == 0) | |
2003 | { | |
2004 | xfree (rp); | |
2005 | *result = dw2_instantiate_symtab (objfile, cu); | |
2006 | return 1; | |
2007 | } | |
2008 | xfree (rp); | |
2009 | } | |
2010 | } | |
2011 | } | |
2012 | } | |
2013 | ||
2014 | if (base_cu) | |
2015 | { | |
2016 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2017 | return 1; | |
2018 | } | |
2019 | ||
2020 | return 0; | |
2021 | } | |
2022 | ||
2023 | static struct symtab * | |
2024 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2025 | const char *name, domain_enum domain) | |
2026 | { | |
2027 | /* We do all the work in the pre_expand_symtabs_matching hook | |
2028 | instead. */ | |
2029 | return NULL; | |
2030 | } | |
2031 | ||
2032 | /* A helper function that expands all symtabs that hold an object | |
2033 | named NAME. */ | |
2034 | static void | |
2035 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2036 | { | |
2037 | dw2_setup (objfile); | |
2038 | ||
2039 | if (dwarf2_per_objfile->index_table) | |
2040 | { | |
2041 | offset_type *vec; | |
2042 | ||
2043 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2044 | name, &vec)) | |
2045 | { | |
2046 | offset_type i, len = MAYBE_SWAP (*vec); | |
2047 | for (i = 0; i < len; ++i) | |
2048 | { | |
2049 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
2050 | struct dwarf2_per_cu_data *cu; | |
2051 | cu = dwarf2_per_objfile->all_comp_units[cu_index]; | |
2052 | dw2_instantiate_symtab (objfile, cu); | |
2053 | } | |
2054 | } | |
2055 | } | |
2056 | } | |
2057 | ||
2058 | static void | |
2059 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
2060 | int kind, const char *name, | |
2061 | domain_enum domain) | |
2062 | { | |
2063 | dw2_do_expand_symtabs_matching (objfile, name); | |
2064 | } | |
2065 | ||
2066 | static void | |
2067 | dw2_print_stats (struct objfile *objfile) | |
2068 | { | |
2069 | int i, count; | |
2070 | ||
2071 | dw2_setup (objfile); | |
2072 | count = 0; | |
2073 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2074 | { | |
2075 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2076 | ||
2077 | if (!cu->v.quick->symtab) | |
2078 | ++count; | |
2079 | } | |
2080 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2081 | } | |
2082 | ||
2083 | static void | |
2084 | dw2_dump (struct objfile *objfile) | |
2085 | { | |
2086 | /* Nothing worth printing. */ | |
2087 | } | |
2088 | ||
2089 | static void | |
2090 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2091 | struct section_offsets *delta) | |
2092 | { | |
2093 | /* There's nothing to relocate here. */ | |
2094 | } | |
2095 | ||
2096 | static void | |
2097 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2098 | const char *func_name) | |
2099 | { | |
2100 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2101 | } | |
2102 | ||
2103 | static void | |
2104 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2105 | { | |
2106 | int i; | |
2107 | ||
2108 | dw2_setup (objfile); | |
2109 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2110 | { | |
2111 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2112 | ||
2113 | dw2_instantiate_symtab (objfile, cu); | |
2114 | } | |
2115 | } | |
2116 | ||
2117 | static void | |
2118 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2119 | const char *filename) | |
2120 | { | |
2121 | int i; | |
2122 | ||
2123 | dw2_setup (objfile); | |
2124 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2125 | { | |
2126 | int j; | |
2127 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2128 | ||
2129 | if (cu->v.quick->symtab) | |
2130 | continue; | |
2131 | ||
2132 | dw2_require_line_header (objfile, cu); | |
2133 | if (!cu->v.quick->lines) | |
2134 | continue; | |
2135 | ||
2136 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2137 | { | |
2138 | const char *this_name = cu->v.quick->file_names[j]; | |
2139 | if (strcmp (this_name, filename) == 0) | |
2140 | { | |
2141 | dw2_instantiate_symtab (objfile, cu); | |
2142 | break; | |
2143 | } | |
2144 | } | |
2145 | } | |
2146 | } | |
2147 | ||
dd786858 | 2148 | static const char * |
9291a0cd TT |
2149 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2150 | { | |
2151 | struct dwarf2_per_cu_data *cu; | |
2152 | offset_type *vec; | |
2153 | ||
2154 | dw2_setup (objfile); | |
2155 | ||
2156 | if (!dwarf2_per_objfile->index_table) | |
2157 | return NULL; | |
2158 | ||
2159 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2160 | name, &vec)) | |
2161 | return NULL; | |
2162 | ||
2163 | /* Note that this just looks at the very first one named NAME -- but | |
2164 | actually we are looking for a function. find_main_filename | |
2165 | should be rewritten so that it doesn't require a custom hook. It | |
2166 | could just use the ordinary symbol tables. */ | |
2167 | /* vec[0] is the length, which must always be >0. */ | |
2168 | cu = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[1])]; | |
2169 | ||
2170 | dw2_require_line_header (objfile, cu); | |
2171 | if (!cu->v.quick->lines) | |
2172 | return NULL; | |
2173 | ||
dd786858 | 2174 | return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1]; |
9291a0cd TT |
2175 | } |
2176 | ||
2177 | static void | |
2178 | dw2_map_ada_symtabs (struct objfile *objfile, | |
2179 | int (*wild_match) (const char *, int, const char *), | |
2180 | int (*is_name_suffix) (const char *), | |
2181 | void (*callback) (struct objfile *, | |
2182 | struct symtab *, void *), | |
2183 | const char *name, int global, | |
2184 | domain_enum namespace, int wild, | |
2185 | void *data) | |
2186 | { | |
2187 | /* For now, we don't support Ada, so this function can't be | |
2188 | reached. */ | |
2189 | internal_error (__FILE__, __LINE__, | |
2190 | _("map_ada_symtabs called via index method")); | |
2191 | } | |
2192 | ||
2193 | static void | |
2194 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2195 | int (*file_matcher) (const char *, void *), | |
2196 | int (*name_matcher) (const char *, void *), | |
2197 | domain_enum kind, | |
2198 | void *data) | |
2199 | { | |
2200 | int i; | |
2201 | offset_type iter; | |
2202 | ||
2203 | dw2_setup (objfile); | |
2204 | if (!dwarf2_per_objfile->index_table) | |
2205 | return; | |
2206 | ||
2207 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2208 | { | |
2209 | int j; | |
2210 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2211 | ||
2212 | cu->v.quick->mark = 0; | |
2213 | if (cu->v.quick->symtab) | |
2214 | continue; | |
2215 | ||
2216 | dw2_require_line_header (objfile, cu); | |
2217 | if (!cu->v.quick->lines) | |
2218 | continue; | |
2219 | ||
2220 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2221 | { | |
2222 | if (file_matcher (cu->v.quick->file_names[j], data)) | |
2223 | { | |
2224 | cu->v.quick->mark = 1; | |
2225 | break; | |
2226 | } | |
2227 | } | |
2228 | } | |
2229 | ||
2230 | for (iter = 0; | |
2231 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2232 | ++iter) | |
2233 | { | |
2234 | offset_type idx = 2 * iter; | |
2235 | const char *name; | |
2236 | offset_type *vec, vec_len, vec_idx; | |
2237 | ||
2238 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2239 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2240 | continue; | |
2241 | ||
2242 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2243 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2244 | ||
2245 | if (! (*name_matcher) (name, data)) | |
2246 | continue; | |
2247 | ||
2248 | /* The name was matched, now expand corresponding CUs that were | |
2249 | marked. */ | |
2250 | vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool | |
2251 | + dwarf2_per_objfile->index_table->index_table[idx + 1]); | |
2252 | vec_len = MAYBE_SWAP (vec[0]); | |
2253 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2254 | { | |
2255 | struct dwarf2_per_cu_data *cu | |
2256 | = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[vec_idx + 1])]; | |
2257 | if (cu->v.quick->mark) | |
2258 | dw2_instantiate_symtab (objfile, cu); | |
2259 | } | |
2260 | } | |
2261 | } | |
2262 | ||
2263 | static struct symtab * | |
2264 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2265 | struct minimal_symbol *msymbol, | |
2266 | CORE_ADDR pc, | |
2267 | struct obj_section *section, | |
2268 | int warn_if_readin) | |
2269 | { | |
2270 | struct dwarf2_per_cu_data *data; | |
2271 | ||
2272 | dw2_setup (objfile); | |
2273 | ||
2274 | if (!objfile->psymtabs_addrmap) | |
2275 | return NULL; | |
2276 | ||
2277 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2278 | if (!data) | |
2279 | return NULL; | |
2280 | ||
2281 | if (warn_if_readin && data->v.quick->symtab) | |
2282 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"), | |
2283 | paddress (get_objfile_arch (objfile), pc)); | |
2284 | ||
2285 | return dw2_instantiate_symtab (objfile, data); | |
2286 | } | |
2287 | ||
2288 | static void | |
2289 | dw2_map_symbol_names (struct objfile *objfile, | |
2290 | void (*fun) (const char *, void *), | |
2291 | void *data) | |
2292 | { | |
2293 | offset_type iter; | |
2294 | dw2_setup (objfile); | |
2295 | ||
2296 | if (!dwarf2_per_objfile->index_table) | |
2297 | return; | |
2298 | ||
2299 | for (iter = 0; | |
2300 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2301 | ++iter) | |
2302 | { | |
2303 | offset_type idx = 2 * iter; | |
2304 | const char *name; | |
2305 | offset_type *vec, vec_len, vec_idx; | |
2306 | ||
2307 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2308 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2309 | continue; | |
2310 | ||
2311 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2312 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2313 | ||
2314 | (*fun) (name, data); | |
2315 | } | |
2316 | } | |
2317 | ||
2318 | static void | |
2319 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2320 | void (*fun) (const char *, const char *, void *), | |
2321 | void *data) | |
2322 | { | |
2323 | int i; | |
2324 | ||
2325 | dw2_setup (objfile); | |
2326 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2327 | { | |
2328 | int j; | |
2329 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2330 | ||
2331 | if (cu->v.quick->symtab) | |
2332 | continue; | |
2333 | ||
2334 | dw2_require_line_header (objfile, cu); | |
2335 | if (!cu->v.quick->lines) | |
2336 | continue; | |
2337 | ||
2338 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2339 | { | |
2340 | const char *this_full_name = dw2_require_full_path (objfile, cu, j); | |
2341 | (*fun) (cu->v.quick->file_names[j], this_full_name, data); | |
2342 | } | |
2343 | } | |
2344 | } | |
2345 | ||
2346 | static int | |
2347 | dw2_has_symbols (struct objfile *objfile) | |
2348 | { | |
2349 | return 1; | |
2350 | } | |
2351 | ||
2352 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2353 | { | |
2354 | dw2_has_symbols, | |
2355 | dw2_find_last_source_symtab, | |
2356 | dw2_forget_cached_source_info, | |
2357 | dw2_lookup_symtab, | |
2358 | dw2_lookup_symbol, | |
2359 | dw2_pre_expand_symtabs_matching, | |
2360 | dw2_print_stats, | |
2361 | dw2_dump, | |
2362 | dw2_relocate, | |
2363 | dw2_expand_symtabs_for_function, | |
2364 | dw2_expand_all_symtabs, | |
2365 | dw2_expand_symtabs_with_filename, | |
2366 | dw2_find_symbol_file, | |
2367 | dw2_map_ada_symtabs, | |
2368 | dw2_expand_symtabs_matching, | |
2369 | dw2_find_pc_sect_symtab, | |
2370 | dw2_map_symbol_names, | |
2371 | dw2_map_symbol_filenames | |
2372 | }; | |
2373 | ||
2374 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2375 | file will use psymtabs, or 1 if using the GNU index. */ | |
2376 | ||
2377 | int | |
2378 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2379 | { | |
2380 | /* If we're about to read full symbols, don't bother with the | |
2381 | indices. In this case we also don't care if some other debug | |
2382 | format is making psymtabs, because they are all about to be | |
2383 | expanded anyway. */ | |
2384 | if ((objfile->flags & OBJF_READNOW)) | |
2385 | { | |
2386 | int i; | |
2387 | ||
2388 | dwarf2_per_objfile->using_index = 1; | |
2389 | create_all_comp_units (objfile); | |
2390 | ||
2391 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2392 | { | |
2393 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2394 | ||
2395 | cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2396 | struct dwarf2_per_cu_quick_data); | |
2397 | } | |
2398 | ||
2399 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2400 | these functions will be no-ops because we will have expanded | |
2401 | all symtabs. */ | |
2402 | return 1; | |
2403 | } | |
2404 | ||
2405 | if (dwarf2_read_index (objfile)) | |
2406 | return 1; | |
2407 | ||
2408 | dwarf2_build_psymtabs (objfile); | |
2409 | return 0; | |
2410 | } | |
2411 | ||
2412 | \f | |
2413 | ||
dce234bc PP |
2414 | /* Build a partial symbol table. */ |
2415 | ||
2416 | void | |
f29dff0a | 2417 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2418 | { |
f29dff0a | 2419 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2420 | { |
2421 | init_psymbol_list (objfile, 1024); | |
2422 | } | |
2423 | ||
d146bf1e | 2424 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2425 | } |
c906108c | 2426 | |
45452591 DE |
2427 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2428 | ||
2429 | static inline int | |
2430 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2431 | { | |
2432 | unsigned int bottom = cu_header->offset; | |
2433 | unsigned int top = (cu_header->offset | |
2434 | + cu_header->length | |
2435 | + cu_header->initial_length_size); | |
9a619af0 | 2436 | |
45452591 DE |
2437 | return (offset >= bottom && offset < top); |
2438 | } | |
2439 | ||
93311388 DE |
2440 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2441 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2442 | by the caller. */ | |
107d2387 | 2443 | |
fe1b8b76 | 2444 | static gdb_byte * |
107d2387 | 2445 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2446 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2447 | { |
2448 | int signed_addr; | |
891d2f0b | 2449 | unsigned int bytes_read; |
c764a876 DE |
2450 | |
2451 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2452 | cu_header->initial_length_size = bytes_read; | |
2453 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2454 | info_ptr += bytes_read; |
107d2387 AC |
2455 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2456 | info_ptr += 2; | |
613e1657 | 2457 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2458 | &bytes_read); |
613e1657 | 2459 | info_ptr += bytes_read; |
107d2387 AC |
2460 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2461 | info_ptr += 1; | |
2462 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2463 | if (signed_addr < 0) | |
8e65ff28 | 2464 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2465 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2466 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2467 | |
107d2387 AC |
2468 | return info_ptr; |
2469 | } | |
2470 | ||
fe1b8b76 JB |
2471 | static gdb_byte * |
2472 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2473 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2474 | bfd *abfd) |
2475 | { | |
fe1b8b76 | 2476 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2477 | |
2478 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2479 | ||
2dc7f7b3 | 2480 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2481 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2482 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2483 | bfd_get_filename (abfd)); | |
72bf9492 | 2484 | |
dce234bc | 2485 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
2486 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2487 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2488 | (long) header->abbrev_offset, |
93311388 | 2489 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2490 | bfd_get_filename (abfd)); |
2491 | ||
2492 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2493 | > buffer + buffer_size) |
8a3fe4f8 AC |
2494 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2495 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2496 | (long) header->length, |
93311388 | 2497 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2498 | bfd_get_filename (abfd)); |
2499 | ||
2500 | return info_ptr; | |
2501 | } | |
2502 | ||
348e048f DE |
2503 | /* Read in the types comp unit header information from .debug_types entry at |
2504 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2505 | ||
2506 | static gdb_byte * | |
2507 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2508 | ULONGEST *signature, | |
2509 | gdb_byte *types_ptr, bfd *abfd) | |
2510 | { | |
348e048f DE |
2511 | gdb_byte *initial_types_ptr = types_ptr; |
2512 | ||
6e70227d | 2513 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2514 | &dwarf2_per_objfile->types); |
348e048f DE |
2515 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2516 | ||
2517 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2518 | ||
2519 | *signature = read_8_bytes (abfd, types_ptr); | |
2520 | types_ptr += 8; | |
2521 | types_ptr += cu_header->offset_size; | |
2522 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2523 | ||
2524 | return types_ptr; | |
2525 | } | |
2526 | ||
aaa75496 JB |
2527 | /* Allocate a new partial symtab for file named NAME and mark this new |
2528 | partial symtab as being an include of PST. */ | |
2529 | ||
2530 | static void | |
2531 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2532 | struct objfile *objfile) | |
2533 | { | |
2534 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2535 | ||
2536 | subpst->section_offsets = pst->section_offsets; | |
2537 | subpst->textlow = 0; | |
2538 | subpst->texthigh = 0; | |
2539 | ||
2540 | subpst->dependencies = (struct partial_symtab **) | |
2541 | obstack_alloc (&objfile->objfile_obstack, | |
2542 | sizeof (struct partial_symtab *)); | |
2543 | subpst->dependencies[0] = pst; | |
2544 | subpst->number_of_dependencies = 1; | |
2545 | ||
2546 | subpst->globals_offset = 0; | |
2547 | subpst->n_global_syms = 0; | |
2548 | subpst->statics_offset = 0; | |
2549 | subpst->n_static_syms = 0; | |
2550 | subpst->symtab = NULL; | |
2551 | subpst->read_symtab = pst->read_symtab; | |
2552 | subpst->readin = 0; | |
2553 | ||
2554 | /* No private part is necessary for include psymtabs. This property | |
2555 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2556 | the regular ones. */ |
58a9656e | 2557 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2558 | } |
2559 | ||
2560 | /* Read the Line Number Program data and extract the list of files | |
2561 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2562 | partial symtab for each of these included files. */ |
aaa75496 JB |
2563 | |
2564 | static void | |
2565 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2566 | struct die_info *die, |
aaa75496 JB |
2567 | struct partial_symtab *pst) |
2568 | { | |
2569 | struct objfile *objfile = cu->objfile; | |
2570 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2571 | struct line_header *lh = NULL; |
2572 | struct attribute *attr; | |
aaa75496 | 2573 | |
d85a05f0 DJ |
2574 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2575 | if (attr) | |
2576 | { | |
2577 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2578 | |
d85a05f0 DJ |
2579 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2580 | } | |
aaa75496 JB |
2581 | if (lh == NULL) |
2582 | return; /* No linetable, so no includes. */ | |
2583 | ||
2584 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
2585 | ||
2586 | free_line_header (lh); | |
2587 | } | |
2588 | ||
348e048f DE |
2589 | static hashval_t |
2590 | hash_type_signature (const void *item) | |
2591 | { | |
2592 | const struct signatured_type *type_sig = item; | |
9a619af0 | 2593 | |
348e048f DE |
2594 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
2595 | return type_sig->signature; | |
2596 | } | |
2597 | ||
2598 | static int | |
2599 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
2600 | { | |
2601 | const struct signatured_type *lhs = item_lhs; | |
2602 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 2603 | |
348e048f DE |
2604 | return lhs->signature == rhs->signature; |
2605 | } | |
2606 | ||
2607 | /* Create the hash table of all entries in the .debug_types section. | |
2608 | The result is zero if there is an error (e.g. missing .debug_types section), | |
2609 | otherwise non-zero. */ | |
2610 | ||
2611 | static int | |
2612 | create_debug_types_hash_table (struct objfile *objfile) | |
2613 | { | |
be391dca | 2614 | gdb_byte *info_ptr; |
348e048f DE |
2615 | htab_t types_htab; |
2616 | ||
be391dca TT |
2617 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
2618 | info_ptr = dwarf2_per_objfile->types.buffer; | |
2619 | ||
348e048f DE |
2620 | if (info_ptr == NULL) |
2621 | { | |
2622 | dwarf2_per_objfile->signatured_types = NULL; | |
2623 | return 0; | |
2624 | } | |
2625 | ||
2626 | types_htab = htab_create_alloc_ex (41, | |
2627 | hash_type_signature, | |
2628 | eq_type_signature, | |
2629 | NULL, | |
2630 | &objfile->objfile_obstack, | |
2631 | hashtab_obstack_allocate, | |
2632 | dummy_obstack_deallocate); | |
2633 | ||
2634 | if (dwarf2_die_debug) | |
2635 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
2636 | ||
2637 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2638 | { | |
2639 | unsigned int offset; | |
2640 | unsigned int offset_size; | |
2641 | unsigned int type_offset; | |
2642 | unsigned int length, initial_length_size; | |
2643 | unsigned short version; | |
2644 | ULONGEST signature; | |
2645 | struct signatured_type *type_sig; | |
2646 | void **slot; | |
2647 | gdb_byte *ptr = info_ptr; | |
2648 | ||
2649 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
2650 | ||
2651 | /* We need to read the type's signature in order to build the hash | |
2652 | table, but we don't need to read anything else just yet. */ | |
2653 | ||
2654 | /* Sanity check to ensure entire cu is present. */ | |
2655 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
2656 | if (ptr + length + initial_length_size | |
2657 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2658 | { | |
2659 | complaint (&symfile_complaints, | |
2660 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
2661 | break; | |
2662 | } | |
2663 | ||
2664 | offset_size = initial_length_size == 4 ? 4 : 8; | |
2665 | ptr += initial_length_size; | |
2666 | version = bfd_get_16 (objfile->obfd, ptr); | |
2667 | ptr += 2; | |
2668 | ptr += offset_size; /* abbrev offset */ | |
2669 | ptr += 1; /* address size */ | |
2670 | signature = bfd_get_64 (objfile->obfd, ptr); | |
2671 | ptr += 8; | |
2672 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
2673 | ||
2674 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
2675 | memset (type_sig, 0, sizeof (*type_sig)); | |
2676 | type_sig->signature = signature; | |
2677 | type_sig->offset = offset; | |
2678 | type_sig->type_offset = type_offset; | |
ca1f3406 | 2679 | type_sig->per_cu.objfile = objfile; |
348e048f DE |
2680 | |
2681 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
2682 | gdb_assert (slot != NULL); | |
2683 | *slot = type_sig; | |
2684 | ||
2685 | if (dwarf2_die_debug) | |
2686 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
2687 | offset, phex (signature, sizeof (signature))); | |
2688 | ||
2689 | info_ptr = info_ptr + initial_length_size + length; | |
2690 | } | |
2691 | ||
2692 | dwarf2_per_objfile->signatured_types = types_htab; | |
2693 | ||
2694 | return 1; | |
2695 | } | |
2696 | ||
2697 | /* Lookup a signature based type. | |
2698 | Returns NULL if SIG is not present in the table. */ | |
2699 | ||
2700 | static struct signatured_type * | |
2701 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
2702 | { | |
2703 | struct signatured_type find_entry, *entry; | |
2704 | ||
2705 | if (dwarf2_per_objfile->signatured_types == NULL) | |
2706 | { | |
2707 | complaint (&symfile_complaints, | |
2708 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
2709 | return 0; | |
2710 | } | |
2711 | ||
2712 | find_entry.signature = sig; | |
2713 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
2714 | return entry; | |
2715 | } | |
2716 | ||
d85a05f0 DJ |
2717 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
2718 | ||
2719 | static void | |
2720 | init_cu_die_reader (struct die_reader_specs *reader, | |
2721 | struct dwarf2_cu *cu) | |
2722 | { | |
2723 | reader->abfd = cu->objfile->obfd; | |
2724 | reader->cu = cu; | |
2725 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
2726 | { |
2727 | gdb_assert (dwarf2_per_objfile->types.readin); | |
2728 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
2729 | } | |
d85a05f0 | 2730 | else |
be391dca TT |
2731 | { |
2732 | gdb_assert (dwarf2_per_objfile->info.readin); | |
2733 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
2734 | } | |
d85a05f0 DJ |
2735 | } |
2736 | ||
2737 | /* Find the base address of the compilation unit for range lists and | |
2738 | location lists. It will normally be specified by DW_AT_low_pc. | |
2739 | In DWARF-3 draft 4, the base address could be overridden by | |
2740 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2741 | compilation units with discontinuous ranges. */ | |
2742 | ||
2743 | static void | |
2744 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
2745 | { | |
2746 | struct attribute *attr; | |
2747 | ||
2748 | cu->base_known = 0; | |
2749 | cu->base_address = 0; | |
2750 | ||
2751 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
2752 | if (attr) | |
2753 | { | |
2754 | cu->base_address = DW_ADDR (attr); | |
2755 | cu->base_known = 1; | |
2756 | } | |
2757 | else | |
2758 | { | |
2759 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
2760 | if (attr) | |
2761 | { | |
2762 | cu->base_address = DW_ADDR (attr); | |
2763 | cu->base_known = 1; | |
2764 | } | |
2765 | } | |
2766 | } | |
2767 | ||
348e048f DE |
2768 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
2769 | to combine the common parts. | |
93311388 | 2770 | Process a compilation unit for a psymtab. |
348e048f DE |
2771 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
2772 | either .debug_info or debug_types. | |
93311388 DE |
2773 | INFO_PTR is a pointer to the start of the CU. |
2774 | Returns a pointer to the next CU. */ | |
aaa75496 | 2775 | |
93311388 DE |
2776 | static gdb_byte * |
2777 | process_psymtab_comp_unit (struct objfile *objfile, | |
2778 | struct dwarf2_per_cu_data *this_cu, | |
2779 | gdb_byte *buffer, gdb_byte *info_ptr, | |
2780 | unsigned int buffer_size) | |
c906108c | 2781 | { |
c906108c | 2782 | bfd *abfd = objfile->obfd; |
93311388 | 2783 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 2784 | struct die_info *comp_unit_die; |
c906108c | 2785 | struct partial_symtab *pst; |
5734ee8b | 2786 | CORE_ADDR baseaddr; |
93311388 DE |
2787 | struct cleanup *back_to_inner; |
2788 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
2789 | int has_children, has_pc_info; |
2790 | struct attribute *attr; | |
d85a05f0 DJ |
2791 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
2792 | struct die_reader_specs reader_specs; | |
c906108c | 2793 | |
93311388 DE |
2794 | memset (&cu, 0, sizeof (cu)); |
2795 | cu.objfile = objfile; | |
2796 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 2797 | |
93311388 | 2798 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 2799 | |
93311388 DE |
2800 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
2801 | buffer, buffer_size, | |
2802 | abfd); | |
10b3939b | 2803 | |
93311388 DE |
2804 | /* Complete the cu_header. */ |
2805 | cu.header.offset = beg_of_comp_unit - buffer; | |
2806 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 2807 | |
93311388 | 2808 | cu.list_in_scope = &file_symbols; |
af703f96 | 2809 | |
328c9494 DJ |
2810 | /* If this compilation unit was already read in, free the |
2811 | cached copy in order to read it in again. This is | |
2812 | necessary because we skipped some symbols when we first | |
2813 | read in the compilation unit (see load_partial_dies). | |
2814 | This problem could be avoided, but the benefit is | |
2815 | unclear. */ | |
2816 | if (this_cu->cu != NULL) | |
2817 | free_one_cached_comp_unit (this_cu->cu); | |
2818 | ||
2819 | /* Note that this is a pointer to our stack frame, being | |
2820 | added to a global data structure. It will be cleaned up | |
2821 | in free_stack_comp_unit when we finish with this | |
2822 | compilation unit. */ | |
2823 | this_cu->cu = &cu; | |
d85a05f0 DJ |
2824 | cu.per_cu = this_cu; |
2825 | ||
93311388 DE |
2826 | /* Read the abbrevs for this compilation unit into a table. */ |
2827 | dwarf2_read_abbrevs (abfd, &cu); | |
2828 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 2829 | |
93311388 | 2830 | /* Read the compilation unit die. */ |
348e048f DE |
2831 | if (this_cu->from_debug_types) |
2832 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
2833 | init_cu_die_reader (&reader_specs, &cu); |
2834 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2835 | &has_children); | |
93311388 | 2836 | |
348e048f DE |
2837 | if (this_cu->from_debug_types) |
2838 | { | |
2839 | /* offset,length haven't been set yet for type units. */ | |
2840 | this_cu->offset = cu.header.offset; | |
2841 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
2842 | } | |
d85a05f0 | 2843 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 2844 | { |
93311388 DE |
2845 | info_ptr = (beg_of_comp_unit + cu.header.length |
2846 | + cu.header.initial_length_size); | |
2847 | do_cleanups (back_to_inner); | |
2848 | return info_ptr; | |
2849 | } | |
72bf9492 | 2850 | |
93311388 | 2851 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
2852 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
2853 | if (attr) | |
2854 | set_cu_language (DW_UNSND (attr), &cu); | |
2855 | else | |
2856 | set_cu_language (language_minimal, &cu); | |
c906108c | 2857 | |
93311388 | 2858 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 2859 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 2860 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 2861 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
2862 | /* TEXTLOW and TEXTHIGH are set below. */ |
2863 | 0, | |
2864 | objfile->global_psymbols.next, | |
2865 | objfile->static_psymbols.next); | |
72bf9492 | 2866 | |
d85a05f0 DJ |
2867 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
2868 | if (attr != NULL) | |
2869 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 2870 | |
e38df1d0 | 2871 | pst->read_symtab_private = this_cu; |
72bf9492 | 2872 | |
93311388 | 2873 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 2874 | |
93311388 DE |
2875 | /* Store the function that reads in the rest of the symbol table */ |
2876 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 2877 | |
9291a0cd | 2878 | this_cu->v.psymtab = pst; |
c906108c | 2879 | |
d85a05f0 DJ |
2880 | dwarf2_find_base_address (comp_unit_die, &cu); |
2881 | ||
93311388 DE |
2882 | /* Possibly set the default values of LOWPC and HIGHPC from |
2883 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
2884 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
2885 | &best_highpc, &cu, pst); | |
2886 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
2887 | /* Store the contiguous range if it is not empty; it can be empty for |
2888 | CUs with no code. */ | |
2889 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
2890 | best_lowpc + baseaddr, |
2891 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
2892 | |
2893 | /* Check if comp unit has_children. | |
2894 | If so, read the rest of the partial symbols from this comp unit. | |
2895 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 2896 | if (has_children) |
93311388 DE |
2897 | { |
2898 | struct partial_die_info *first_die; | |
2899 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 2900 | |
93311388 DE |
2901 | lowpc = ((CORE_ADDR) -1); |
2902 | highpc = ((CORE_ADDR) 0); | |
c906108c | 2903 | |
93311388 | 2904 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 2905 | |
93311388 | 2906 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 2907 | ! has_pc_info, &cu); |
57c22c6c | 2908 | |
93311388 DE |
2909 | /* If we didn't find a lowpc, set it to highpc to avoid |
2910 | complaints from `maint check'. */ | |
2911 | if (lowpc == ((CORE_ADDR) -1)) | |
2912 | lowpc = highpc; | |
10b3939b | 2913 | |
93311388 DE |
2914 | /* If the compilation unit didn't have an explicit address range, |
2915 | then use the information extracted from its child dies. */ | |
d85a05f0 | 2916 | if (! has_pc_info) |
93311388 | 2917 | { |
d85a05f0 DJ |
2918 | best_lowpc = lowpc; |
2919 | best_highpc = highpc; | |
93311388 DE |
2920 | } |
2921 | } | |
d85a05f0 DJ |
2922 | pst->textlow = best_lowpc + baseaddr; |
2923 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 2924 | |
93311388 DE |
2925 | pst->n_global_syms = objfile->global_psymbols.next - |
2926 | (objfile->global_psymbols.list + pst->globals_offset); | |
2927 | pst->n_static_syms = objfile->static_psymbols.next - | |
2928 | (objfile->static_psymbols.list + pst->statics_offset); | |
2929 | sort_pst_symbols (pst); | |
c906108c | 2930 | |
93311388 DE |
2931 | info_ptr = (beg_of_comp_unit + cu.header.length |
2932 | + cu.header.initial_length_size); | |
ae038cb0 | 2933 | |
348e048f DE |
2934 | if (this_cu->from_debug_types) |
2935 | { | |
2936 | /* It's not clear we want to do anything with stmt lists here. | |
2937 | Waiting to see what gcc ultimately does. */ | |
2938 | } | |
d85a05f0 | 2939 | else |
93311388 DE |
2940 | { |
2941 | /* Get the list of files included in the current compilation unit, | |
2942 | and build a psymtab for each of them. */ | |
d85a05f0 | 2943 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 2944 | } |
ae038cb0 | 2945 | |
93311388 | 2946 | do_cleanups (back_to_inner); |
ae038cb0 | 2947 | |
93311388 DE |
2948 | return info_ptr; |
2949 | } | |
ff013f42 | 2950 | |
348e048f DE |
2951 | /* Traversal function for htab_traverse_noresize. |
2952 | Process one .debug_types comp-unit. */ | |
2953 | ||
2954 | static int | |
2955 | process_type_comp_unit (void **slot, void *info) | |
2956 | { | |
2957 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
2958 | struct objfile *objfile = (struct objfile *) info; | |
2959 | struct dwarf2_per_cu_data *this_cu; | |
2960 | ||
2961 | this_cu = &entry->per_cu; | |
2962 | this_cu->from_debug_types = 1; | |
2963 | ||
be391dca | 2964 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
2965 | process_psymtab_comp_unit (objfile, this_cu, |
2966 | dwarf2_per_objfile->types.buffer, | |
2967 | dwarf2_per_objfile->types.buffer + entry->offset, | |
2968 | dwarf2_per_objfile->types.size); | |
2969 | ||
2970 | return 1; | |
2971 | } | |
2972 | ||
2973 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
2974 | Build partial symbol tables for the .debug_types comp-units. */ | |
2975 | ||
2976 | static void | |
2977 | build_type_psymtabs (struct objfile *objfile) | |
2978 | { | |
2979 | if (! create_debug_types_hash_table (objfile)) | |
2980 | return; | |
2981 | ||
2982 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
2983 | process_type_comp_unit, objfile); | |
2984 | } | |
2985 | ||
60606b2c TT |
2986 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
2987 | ||
2988 | static void | |
2989 | psymtabs_addrmap_cleanup (void *o) | |
2990 | { | |
2991 | struct objfile *objfile = o; | |
ec61707d | 2992 | |
60606b2c TT |
2993 | objfile->psymtabs_addrmap = NULL; |
2994 | } | |
2995 | ||
93311388 DE |
2996 | /* Build the partial symbol table by doing a quick pass through the |
2997 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 2998 | |
93311388 | 2999 | static void |
c67a9c90 | 3000 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3001 | { |
93311388 | 3002 | gdb_byte *info_ptr; |
60606b2c TT |
3003 | struct cleanup *back_to, *addrmap_cleanup; |
3004 | struct obstack temp_obstack; | |
93311388 | 3005 | |
be391dca | 3006 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3007 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3008 | |
93311388 DE |
3009 | /* Any cached compilation units will be linked by the per-objfile |
3010 | read_in_chain. Make sure to free them when we're done. */ | |
3011 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3012 | |
348e048f DE |
3013 | build_type_psymtabs (objfile); |
3014 | ||
93311388 | 3015 | create_all_comp_units (objfile); |
c906108c | 3016 | |
60606b2c TT |
3017 | /* Create a temporary address map on a temporary obstack. We later |
3018 | copy this to the final obstack. */ | |
3019 | obstack_init (&temp_obstack); | |
3020 | make_cleanup_obstack_free (&temp_obstack); | |
3021 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3022 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3023 | |
93311388 DE |
3024 | /* Since the objects we're extracting from .debug_info vary in |
3025 | length, only the individual functions to extract them (like | |
3026 | read_comp_unit_head and load_partial_die) can really know whether | |
3027 | the buffer is large enough to hold another complete object. | |
c906108c | 3028 | |
93311388 DE |
3029 | At the moment, they don't actually check that. If .debug_info |
3030 | holds just one extra byte after the last compilation unit's dies, | |
3031 | then read_comp_unit_head will happily read off the end of the | |
3032 | buffer. read_partial_die is similarly casual. Those functions | |
3033 | should be fixed. | |
c906108c | 3034 | |
93311388 DE |
3035 | For this loop condition, simply checking whether there's any data |
3036 | left at all should be sufficient. */ | |
c906108c | 3037 | |
93311388 DE |
3038 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3039 | + dwarf2_per_objfile->info.size)) | |
3040 | { | |
3041 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3042 | |
93311388 DE |
3043 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
3044 | objfile); | |
aaa75496 | 3045 | |
93311388 DE |
3046 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3047 | dwarf2_per_objfile->info.buffer, | |
3048 | info_ptr, | |
3049 | dwarf2_per_objfile->info.size); | |
c906108c | 3050 | } |
ff013f42 JK |
3051 | |
3052 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3053 | &objfile->objfile_obstack); | |
60606b2c | 3054 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3055 | |
ae038cb0 DJ |
3056 | do_cleanups (back_to); |
3057 | } | |
3058 | ||
93311388 | 3059 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3060 | |
3061 | static void | |
93311388 DE |
3062 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3063 | struct objfile *objfile) | |
ae038cb0 DJ |
3064 | { |
3065 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3066 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3067 | struct die_info *comp_unit_die; |
ae038cb0 | 3068 | struct dwarf2_cu *cu; |
ae038cb0 | 3069 | struct cleanup *back_to; |
d85a05f0 DJ |
3070 | struct attribute *attr; |
3071 | int has_children; | |
3072 | struct die_reader_specs reader_specs; | |
ae038cb0 | 3073 | |
348e048f DE |
3074 | gdb_assert (! this_cu->from_debug_types); |
3075 | ||
be391dca | 3076 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3077 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3078 | beg_of_comp_unit = info_ptr; |
3079 | ||
93311388 | 3080 | cu = alloc_one_comp_unit (objfile); |
ae038cb0 | 3081 | |
93311388 | 3082 | /* ??? Missing cleanup for CU? */ |
ae038cb0 | 3083 | |
328c9494 DJ |
3084 | /* Link this compilation unit into the compilation unit tree. */ |
3085 | this_cu->cu = cu; | |
3086 | cu->per_cu = this_cu; | |
3087 | cu->type_hash = this_cu->type_hash; | |
3088 | ||
93311388 DE |
3089 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3090 | dwarf2_per_objfile->info.buffer, | |
3091 | dwarf2_per_objfile->info.size, | |
3092 | abfd); | |
ae038cb0 DJ |
3093 | |
3094 | /* Complete the cu_header. */ | |
93311388 | 3095 | cu->header.offset = this_cu->offset; |
d00adf39 | 3096 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
3097 | |
3098 | /* Read the abbrevs for this compilation unit into a table. */ | |
3099 | dwarf2_read_abbrevs (abfd, cu); | |
3100 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3101 | ||
3102 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3103 | init_cu_die_reader (&reader_specs, cu); |
3104 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3105 | &has_children); | |
ae038cb0 DJ |
3106 | |
3107 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
3108 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
3109 | if (attr) | |
3110 | set_cu_language (DW_UNSND (attr), cu); | |
3111 | else | |
3112 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 3113 | |
ae038cb0 DJ |
3114 | /* Check if comp unit has_children. |
3115 | If so, read the rest of the partial symbols from this comp unit. | |
3116 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3117 | if (has_children) |
93311388 | 3118 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 DJ |
3119 | |
3120 | do_cleanups (back_to); | |
3121 | } | |
3122 | ||
3123 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3124 | if an inter-comp-unit reference is found; presumably if there is one, | |
3125 | there will be many, and one will occur early in the .debug_info section. | |
3126 | So there's no point in building this list incrementally. */ | |
3127 | ||
3128 | static void | |
3129 | create_all_comp_units (struct objfile *objfile) | |
3130 | { | |
3131 | int n_allocated; | |
3132 | int n_comp_units; | |
3133 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3134 | gdb_byte *info_ptr; |
3135 | ||
3136 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3137 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3138 | |
3139 | n_comp_units = 0; | |
3140 | n_allocated = 10; | |
3141 | all_comp_units = xmalloc (n_allocated | |
3142 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3143 | |
dce234bc | 3144 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 3145 | { |
c764a876 | 3146 | unsigned int length, initial_length_size; |
ae038cb0 | 3147 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3148 | unsigned int offset; |
ae038cb0 | 3149 | |
dce234bc | 3150 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3151 | |
3152 | /* Read just enough information to find out where the next | |
3153 | compilation unit is. */ | |
c764a876 DE |
3154 | length = read_initial_length (objfile->obfd, info_ptr, |
3155 | &initial_length_size); | |
ae038cb0 DJ |
3156 | |
3157 | /* Save the compilation unit for later lookup. */ | |
3158 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3159 | sizeof (struct dwarf2_per_cu_data)); | |
3160 | memset (this_cu, 0, sizeof (*this_cu)); | |
3161 | this_cu->offset = offset; | |
c764a876 | 3162 | this_cu->length = length + initial_length_size; |
9291a0cd | 3163 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3164 | |
3165 | if (n_comp_units == n_allocated) | |
3166 | { | |
3167 | n_allocated *= 2; | |
3168 | all_comp_units = xrealloc (all_comp_units, | |
3169 | n_allocated | |
3170 | * sizeof (struct dwarf2_per_cu_data *)); | |
3171 | } | |
3172 | all_comp_units[n_comp_units++] = this_cu; | |
3173 | ||
3174 | info_ptr = info_ptr + this_cu->length; | |
3175 | } | |
3176 | ||
3177 | dwarf2_per_objfile->all_comp_units | |
3178 | = obstack_alloc (&objfile->objfile_obstack, | |
3179 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3180 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3181 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3182 | xfree (all_comp_units); | |
3183 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3184 | } |
3185 | ||
5734ee8b DJ |
3186 | /* Process all loaded DIEs for compilation unit CU, starting at |
3187 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3188 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3189 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3190 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3191 | and record the covered ranges in the addrmap. */ | |
c906108c | 3192 | |
72bf9492 DJ |
3193 | static void |
3194 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3195 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3196 | { |
72bf9492 | 3197 | struct partial_die_info *pdi; |
c906108c | 3198 | |
91c24f0a DC |
3199 | /* Now, march along the PDI's, descending into ones which have |
3200 | interesting children but skipping the children of the other ones, | |
3201 | until we reach the end of the compilation unit. */ | |
c906108c | 3202 | |
72bf9492 | 3203 | pdi = first_die; |
91c24f0a | 3204 | |
72bf9492 DJ |
3205 | while (pdi != NULL) |
3206 | { | |
3207 | fixup_partial_die (pdi, cu); | |
c906108c | 3208 | |
f55ee35c | 3209 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3210 | children, so we need to look at them. Ditto for anonymous |
3211 | enums. */ | |
933c6fe4 | 3212 | |
72bf9492 | 3213 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3214 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3215 | { |
72bf9492 | 3216 | switch (pdi->tag) |
c906108c SS |
3217 | { |
3218 | case DW_TAG_subprogram: | |
5734ee8b | 3219 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
3220 | break; |
3221 | case DW_TAG_variable: | |
3222 | case DW_TAG_typedef: | |
91c24f0a | 3223 | case DW_TAG_union_type: |
72bf9492 | 3224 | if (!pdi->is_declaration) |
63d06c5c | 3225 | { |
72bf9492 | 3226 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3227 | } |
3228 | break; | |
c906108c | 3229 | case DW_TAG_class_type: |
680b30c7 | 3230 | case DW_TAG_interface_type: |
c906108c | 3231 | case DW_TAG_structure_type: |
72bf9492 | 3232 | if (!pdi->is_declaration) |
c906108c | 3233 | { |
72bf9492 | 3234 | add_partial_symbol (pdi, cu); |
c906108c SS |
3235 | } |
3236 | break; | |
91c24f0a | 3237 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3238 | if (!pdi->is_declaration) |
3239 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3240 | break; |
3241 | case DW_TAG_base_type: | |
a02abb62 | 3242 | case DW_TAG_subrange_type: |
c906108c | 3243 | /* File scope base type definitions are added to the partial |
c5aa993b | 3244 | symbol table. */ |
72bf9492 | 3245 | add_partial_symbol (pdi, cu); |
c906108c | 3246 | break; |
d9fa45fe | 3247 | case DW_TAG_namespace: |
5734ee8b | 3248 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3249 | break; |
5d7cb8df JK |
3250 | case DW_TAG_module: |
3251 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3252 | break; | |
c906108c SS |
3253 | default: |
3254 | break; | |
3255 | } | |
3256 | } | |
3257 | ||
72bf9492 DJ |
3258 | /* If the die has a sibling, skip to the sibling. */ |
3259 | ||
3260 | pdi = pdi->die_sibling; | |
3261 | } | |
3262 | } | |
3263 | ||
3264 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3265 | |
72bf9492 | 3266 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3267 | name is concatenated with "::" and the partial DIE's name. For |
3268 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3269 | Enumerators are an exception; they use the scope of their parent |
3270 | enumeration type, i.e. the name of the enumeration type is not | |
3271 | prepended to the enumerator. | |
91c24f0a | 3272 | |
72bf9492 DJ |
3273 | There are two complexities. One is DW_AT_specification; in this |
3274 | case "parent" means the parent of the target of the specification, | |
3275 | instead of the direct parent of the DIE. The other is compilers | |
3276 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3277 | the fully qualified name of structure types from their members' | |
3278 | linkage names. This must be done using the DIE's children rather | |
3279 | than the children of any DW_AT_specification target. We only need | |
3280 | to do this for structures at the top level, i.e. if the target of | |
3281 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3282 | have a parent. */ | |
3283 | ||
3284 | /* Compute the scope prefix associated with PDI's parent, in | |
3285 | compilation unit CU. The result will be allocated on CU's | |
3286 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3287 | field. NULL is returned if no prefix is necessary. */ | |
3288 | static char * | |
3289 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3290 | struct dwarf2_cu *cu) | |
3291 | { | |
3292 | char *grandparent_scope; | |
3293 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3294 | |
72bf9492 DJ |
3295 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3296 | then this means the parent of the specification DIE. */ | |
3297 | ||
3298 | real_pdi = pdi; | |
72bf9492 | 3299 | while (real_pdi->has_specification) |
10b3939b | 3300 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3301 | |
3302 | parent = real_pdi->die_parent; | |
3303 | if (parent == NULL) | |
3304 | return NULL; | |
3305 | ||
3306 | if (parent->scope_set) | |
3307 | return parent->scope; | |
3308 | ||
3309 | fixup_partial_die (parent, cu); | |
3310 | ||
10b3939b | 3311 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3312 | |
acebe513 UW |
3313 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3314 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3315 | Work around this problem here. */ | |
3316 | if (cu->language == language_cplus | |
6e70227d | 3317 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3318 | && strcmp (parent->name, "::") == 0 |
3319 | && grandparent_scope == NULL) | |
3320 | { | |
3321 | parent->scope = NULL; | |
3322 | parent->scope_set = 1; | |
3323 | return NULL; | |
3324 | } | |
3325 | ||
72bf9492 | 3326 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3327 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3328 | || parent->tag == DW_TAG_structure_type |
3329 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3330 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3331 | || parent->tag == DW_TAG_union_type |
3332 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3333 | { |
3334 | if (grandparent_scope == NULL) | |
3335 | parent->scope = parent->name; | |
3336 | else | |
987504bb | 3337 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
f55ee35c | 3338 | parent->name, 0, cu); |
72bf9492 | 3339 | } |
ceeb3d5a | 3340 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3341 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3342 | parent->scope = grandparent_scope; | |
3343 | else | |
3344 | { | |
3345 | /* FIXME drow/2004-04-01: What should we be doing with | |
3346 | function-local names? For partial symbols, we should probably be | |
3347 | ignoring them. */ | |
3348 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3349 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3350 | parent->tag, pdi->offset); |
3351 | parent->scope = grandparent_scope; | |
c906108c SS |
3352 | } |
3353 | ||
72bf9492 DJ |
3354 | parent->scope_set = 1; |
3355 | return parent->scope; | |
3356 | } | |
3357 | ||
3358 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3359 | CU. The result will be allocated with malloc. */ | |
3360 | static char * | |
3361 | partial_die_full_name (struct partial_die_info *pdi, | |
3362 | struct dwarf2_cu *cu) | |
3363 | { | |
3364 | char *parent_scope; | |
3365 | ||
3366 | parent_scope = partial_die_parent_scope (pdi, cu); | |
3367 | if (parent_scope == NULL) | |
3368 | return NULL; | |
3369 | else | |
f55ee35c | 3370 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3371 | } |
3372 | ||
3373 | static void | |
72bf9492 | 3374 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3375 | { |
e7c27a73 | 3376 | struct objfile *objfile = cu->objfile; |
c906108c | 3377 | CORE_ADDR addr = 0; |
decbce07 | 3378 | char *actual_name = NULL; |
5c4e30ca | 3379 | const struct partial_symbol *psym = NULL; |
e142c38c | 3380 | CORE_ADDR baseaddr; |
72bf9492 | 3381 | int built_actual_name = 0; |
e142c38c DJ |
3382 | |
3383 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3384 | |
94af9270 KS |
3385 | actual_name = partial_die_full_name (pdi, cu); |
3386 | if (actual_name) | |
3387 | built_actual_name = 1; | |
63d06c5c | 3388 | |
72bf9492 DJ |
3389 | if (actual_name == NULL) |
3390 | actual_name = pdi->name; | |
3391 | ||
c906108c SS |
3392 | switch (pdi->tag) |
3393 | { | |
3394 | case DW_TAG_subprogram: | |
2cfa0c8d | 3395 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3396 | { |
2cfa0c8d JB |
3397 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3398 | of the global scope. But in Ada, we want to be able to access | |
3399 | nested procedures globally. So all Ada subprograms are stored | |
3400 | in the global scope. */ | |
38d518c9 | 3401 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3402 | mst_text, objfile); */ |
38d518c9 | 3403 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3404 | built_actual_name, |
5c4e30ca DC |
3405 | VAR_DOMAIN, LOC_BLOCK, |
3406 | &objfile->global_psymbols, | |
3407 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3408 | cu->language, objfile); |
c906108c SS |
3409 | } |
3410 | else | |
3411 | { | |
38d518c9 | 3412 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3413 | mst_file_text, objfile); */ |
38d518c9 | 3414 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3415 | built_actual_name, |
5c4e30ca DC |
3416 | VAR_DOMAIN, LOC_BLOCK, |
3417 | &objfile->static_psymbols, | |
3418 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3419 | cu->language, objfile); |
c906108c SS |
3420 | } |
3421 | break; | |
3422 | case DW_TAG_variable: | |
3423 | if (pdi->is_external) | |
3424 | { | |
3425 | /* Global Variable. | |
3426 | Don't enter into the minimal symbol tables as there is | |
3427 | a minimal symbol table entry from the ELF symbols already. | |
3428 | Enter into partial symbol table if it has a location | |
3429 | descriptor or a type. | |
3430 | If the location descriptor is missing, new_symbol will create | |
3431 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3432 | be determined from the minimal symbol table whenever the variable | |
3433 | is referenced. | |
3434 | The address for the partial symbol table entry is not | |
3435 | used by GDB, but it comes in handy for debugging partial symbol | |
3436 | table building. */ | |
3437 | ||
3438 | if (pdi->locdesc) | |
e7c27a73 | 3439 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 3440 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 3441 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3442 | built_actual_name, |
5c4e30ca DC |
3443 | VAR_DOMAIN, LOC_STATIC, |
3444 | &objfile->global_psymbols, | |
3445 | 0, addr + baseaddr, | |
e142c38c | 3446 | cu->language, objfile); |
c906108c SS |
3447 | } |
3448 | else | |
3449 | { | |
3450 | /* Static Variable. Skip symbols without location descriptors. */ | |
3451 | if (pdi->locdesc == NULL) | |
decbce07 MS |
3452 | { |
3453 | if (built_actual_name) | |
3454 | xfree (actual_name); | |
3455 | return; | |
3456 | } | |
e7c27a73 | 3457 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 3458 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3459 | mst_file_data, objfile); */ |
38d518c9 | 3460 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3461 | built_actual_name, |
5c4e30ca DC |
3462 | VAR_DOMAIN, LOC_STATIC, |
3463 | &objfile->static_psymbols, | |
3464 | 0, addr + baseaddr, | |
e142c38c | 3465 | cu->language, objfile); |
c906108c SS |
3466 | } |
3467 | break; | |
3468 | case DW_TAG_typedef: | |
3469 | case DW_TAG_base_type: | |
a02abb62 | 3470 | case DW_TAG_subrange_type: |
38d518c9 | 3471 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3472 | built_actual_name, |
176620f1 | 3473 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3474 | &objfile->static_psymbols, |
e142c38c | 3475 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3476 | break; |
72bf9492 DJ |
3477 | case DW_TAG_namespace: |
3478 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 3479 | built_actual_name, |
72bf9492 DJ |
3480 | VAR_DOMAIN, LOC_TYPEDEF, |
3481 | &objfile->global_psymbols, | |
3482 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
3483 | break; | |
c906108c | 3484 | case DW_TAG_class_type: |
680b30c7 | 3485 | case DW_TAG_interface_type: |
c906108c SS |
3486 | case DW_TAG_structure_type: |
3487 | case DW_TAG_union_type: | |
3488 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
3489 | /* Skip external references. The DWARF standard says in the section |
3490 | about "Structure, Union, and Class Type Entries": "An incomplete | |
3491 | structure, union or class type is represented by a structure, | |
3492 | union or class entry that does not have a byte size attribute | |
3493 | and that has a DW_AT_declaration attribute." */ | |
3494 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
3495 | { |
3496 | if (built_actual_name) | |
3497 | xfree (actual_name); | |
3498 | return; | |
3499 | } | |
fa4028e9 | 3500 | |
63d06c5c DC |
3501 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
3502 | static vs. global. */ | |
38d518c9 | 3503 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3504 | built_actual_name, |
176620f1 | 3505 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
3506 | (cu->language == language_cplus |
3507 | || cu->language == language_java) | |
63d06c5c DC |
3508 | ? &objfile->global_psymbols |
3509 | : &objfile->static_psymbols, | |
e142c38c | 3510 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3511 | |
c906108c SS |
3512 | break; |
3513 | case DW_TAG_enumerator: | |
38d518c9 | 3514 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3515 | built_actual_name, |
176620f1 | 3516 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
3517 | (cu->language == language_cplus |
3518 | || cu->language == language_java) | |
f6fe98ef DJ |
3519 | ? &objfile->global_psymbols |
3520 | : &objfile->static_psymbols, | |
e142c38c | 3521 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
3522 | break; |
3523 | default: | |
3524 | break; | |
3525 | } | |
5c4e30ca | 3526 | |
72bf9492 DJ |
3527 | if (built_actual_name) |
3528 | xfree (actual_name); | |
c906108c SS |
3529 | } |
3530 | ||
5c4e30ca DC |
3531 | /* Read a partial die corresponding to a namespace; also, add a symbol |
3532 | corresponding to that namespace to the symbol table. NAMESPACE is | |
3533 | the name of the enclosing namespace. */ | |
91c24f0a | 3534 | |
72bf9492 DJ |
3535 | static void |
3536 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 3537 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 3538 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 3539 | { |
72bf9492 | 3540 | /* Add a symbol for the namespace. */ |
e7c27a73 | 3541 | |
72bf9492 | 3542 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
3543 | |
3544 | /* Now scan partial symbols in that namespace. */ | |
3545 | ||
91c24f0a | 3546 | if (pdi->has_children) |
5734ee8b | 3547 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
3548 | } |
3549 | ||
5d7cb8df JK |
3550 | /* Read a partial die corresponding to a Fortran module. */ |
3551 | ||
3552 | static void | |
3553 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
3554 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
3555 | { | |
f55ee35c | 3556 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
3557 | |
3558 | if (pdi->has_children) | |
3559 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
3560 | } | |
3561 | ||
bc30ff58 JB |
3562 | /* Read a partial die corresponding to a subprogram and create a partial |
3563 | symbol for that subprogram. When the CU language allows it, this | |
3564 | routine also defines a partial symbol for each nested subprogram | |
3565 | that this subprogram contains. | |
6e70227d | 3566 | |
bc30ff58 JB |
3567 | DIE my also be a lexical block, in which case we simply search |
3568 | recursively for suprograms defined inside that lexical block. | |
3569 | Again, this is only performed when the CU language allows this | |
3570 | type of definitions. */ | |
3571 | ||
3572 | static void | |
3573 | add_partial_subprogram (struct partial_die_info *pdi, | |
3574 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 3575 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
3576 | { |
3577 | if (pdi->tag == DW_TAG_subprogram) | |
3578 | { | |
3579 | if (pdi->has_pc_info) | |
3580 | { | |
3581 | if (pdi->lowpc < *lowpc) | |
3582 | *lowpc = pdi->lowpc; | |
3583 | if (pdi->highpc > *highpc) | |
3584 | *highpc = pdi->highpc; | |
5734ee8b DJ |
3585 | if (need_pc) |
3586 | { | |
3587 | CORE_ADDR baseaddr; | |
3588 | struct objfile *objfile = cu->objfile; | |
3589 | ||
3590 | baseaddr = ANOFFSET (objfile->section_offsets, | |
3591 | SECT_OFF_TEXT (objfile)); | |
3592 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
3593 | pdi->lowpc + baseaddr, |
3594 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 3595 | cu->per_cu->v.psymtab); |
5734ee8b | 3596 | } |
bc30ff58 | 3597 | if (!pdi->is_declaration) |
e8d05480 JB |
3598 | /* Ignore subprogram DIEs that do not have a name, they are |
3599 | illegal. Do not emit a complaint at this point, we will | |
3600 | do so when we convert this psymtab into a symtab. */ | |
3601 | if (pdi->name) | |
3602 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
3603 | } |
3604 | } | |
6e70227d | 3605 | |
bc30ff58 JB |
3606 | if (! pdi->has_children) |
3607 | return; | |
3608 | ||
3609 | if (cu->language == language_ada) | |
3610 | { | |
3611 | pdi = pdi->die_child; | |
3612 | while (pdi != NULL) | |
3613 | { | |
3614 | fixup_partial_die (pdi, cu); | |
3615 | if (pdi->tag == DW_TAG_subprogram | |
3616 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 3617 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
3618 | pdi = pdi->die_sibling; |
3619 | } | |
3620 | } | |
3621 | } | |
3622 | ||
72bf9492 DJ |
3623 | /* See if we can figure out if the class lives in a namespace. We do |
3624 | this by looking for a member function; its demangled name will | |
3625 | contain namespace info, if there is any. */ | |
63d06c5c | 3626 | |
72bf9492 DJ |
3627 | static void |
3628 | guess_structure_name (struct partial_die_info *struct_pdi, | |
3629 | struct dwarf2_cu *cu) | |
63d06c5c | 3630 | { |
987504bb JJ |
3631 | if ((cu->language == language_cplus |
3632 | || cu->language == language_java) | |
72bf9492 | 3633 | && cu->has_namespace_info == 0 |
63d06c5c DC |
3634 | && struct_pdi->has_children) |
3635 | { | |
63d06c5c DC |
3636 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
3637 | what template types look like, because the demangler | |
3638 | frequently doesn't give the same name as the debug info. We | |
3639 | could fix this by only using the demangled name to get the | |
134d01f1 | 3640 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 3641 | |
72bf9492 | 3642 | struct partial_die_info *real_pdi; |
5d51ca54 | 3643 | |
72bf9492 DJ |
3644 | /* If this DIE (this DIE's specification, if any) has a parent, then |
3645 | we should not do this. We'll prepend the parent's fully qualified | |
3646 | name when we create the partial symbol. */ | |
5d51ca54 | 3647 | |
72bf9492 | 3648 | real_pdi = struct_pdi; |
72bf9492 | 3649 | while (real_pdi->has_specification) |
10b3939b | 3650 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 3651 | |
72bf9492 DJ |
3652 | if (real_pdi->die_parent != NULL) |
3653 | return; | |
63d06c5c | 3654 | } |
63d06c5c DC |
3655 | } |
3656 | ||
91c24f0a DC |
3657 | /* Read a partial die corresponding to an enumeration type. */ |
3658 | ||
72bf9492 DJ |
3659 | static void |
3660 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
3661 | struct dwarf2_cu *cu) | |
91c24f0a | 3662 | { |
72bf9492 | 3663 | struct partial_die_info *pdi; |
91c24f0a DC |
3664 | |
3665 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
3666 | add_partial_symbol (enum_pdi, cu); |
3667 | ||
3668 | pdi = enum_pdi->die_child; | |
3669 | while (pdi) | |
91c24f0a | 3670 | { |
72bf9492 | 3671 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 3672 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 3673 | else |
72bf9492 DJ |
3674 | add_partial_symbol (pdi, cu); |
3675 | pdi = pdi->die_sibling; | |
91c24f0a | 3676 | } |
91c24f0a DC |
3677 | } |
3678 | ||
4bb7a0a7 DJ |
3679 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
3680 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
3681 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
3682 | the initial number. */ | |
3683 | ||
3684 | static struct abbrev_info * | |
fe1b8b76 | 3685 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 3686 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3687 | { |
3688 | bfd *abfd = cu->objfile->obfd; | |
3689 | unsigned int abbrev_number; | |
3690 | struct abbrev_info *abbrev; | |
3691 | ||
3692 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
3693 | ||
3694 | if (abbrev_number == 0) | |
3695 | return NULL; | |
3696 | ||
3697 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
3698 | if (!abbrev) | |
3699 | { | |
8a3fe4f8 | 3700 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
3701 | bfd_get_filename (abfd)); |
3702 | } | |
3703 | ||
3704 | return abbrev; | |
3705 | } | |
3706 | ||
93311388 DE |
3707 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3708 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
3709 | DIE. Any children of the skipped DIEs will also be skipped. */ |
3710 | ||
fe1b8b76 | 3711 | static gdb_byte * |
93311388 | 3712 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3713 | { |
3714 | struct abbrev_info *abbrev; | |
3715 | unsigned int bytes_read; | |
3716 | ||
3717 | while (1) | |
3718 | { | |
3719 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
3720 | if (abbrev == NULL) | |
3721 | return info_ptr + bytes_read; | |
3722 | else | |
93311388 | 3723 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
3724 | } |
3725 | } | |
3726 | ||
93311388 DE |
3727 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3728 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
3729 | abbrev corresponding to that skipped uleb128 should be passed in |
3730 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
3731 | children. */ | |
3732 | ||
fe1b8b76 | 3733 | static gdb_byte * |
93311388 DE |
3734 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
3735 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
3736 | { |
3737 | unsigned int bytes_read; | |
3738 | struct attribute attr; | |
3739 | bfd *abfd = cu->objfile->obfd; | |
3740 | unsigned int form, i; | |
3741 | ||
3742 | for (i = 0; i < abbrev->num_attrs; i++) | |
3743 | { | |
3744 | /* The only abbrev we care about is DW_AT_sibling. */ | |
3745 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
3746 | { | |
3747 | read_attribute (&attr, &abbrev->attrs[i], | |
3748 | abfd, info_ptr, cu); | |
3749 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 3750 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 3751 | else |
93311388 | 3752 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
3753 | } |
3754 | ||
3755 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
3756 | form = abbrev->attrs[i].form; | |
3757 | skip_attribute: | |
3758 | switch (form) | |
3759 | { | |
4bb7a0a7 | 3760 | case DW_FORM_ref_addr: |
ae411497 TT |
3761 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
3762 | and later it is offset sized. */ | |
3763 | if (cu->header.version == 2) | |
3764 | info_ptr += cu->header.addr_size; | |
3765 | else | |
3766 | info_ptr += cu->header.offset_size; | |
3767 | break; | |
3768 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
3769 | info_ptr += cu->header.addr_size; |
3770 | break; | |
3771 | case DW_FORM_data1: | |
3772 | case DW_FORM_ref1: | |
3773 | case DW_FORM_flag: | |
3774 | info_ptr += 1; | |
3775 | break; | |
2dc7f7b3 TT |
3776 | case DW_FORM_flag_present: |
3777 | break; | |
4bb7a0a7 DJ |
3778 | case DW_FORM_data2: |
3779 | case DW_FORM_ref2: | |
3780 | info_ptr += 2; | |
3781 | break; | |
3782 | case DW_FORM_data4: | |
3783 | case DW_FORM_ref4: | |
3784 | info_ptr += 4; | |
3785 | break; | |
3786 | case DW_FORM_data8: | |
3787 | case DW_FORM_ref8: | |
348e048f | 3788 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
3789 | info_ptr += 8; |
3790 | break; | |
3791 | case DW_FORM_string: | |
3792 | read_string (abfd, info_ptr, &bytes_read); | |
3793 | info_ptr += bytes_read; | |
3794 | break; | |
2dc7f7b3 | 3795 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
3796 | case DW_FORM_strp: |
3797 | info_ptr += cu->header.offset_size; | |
3798 | break; | |
2dc7f7b3 | 3799 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
3800 | case DW_FORM_block: |
3801 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3802 | info_ptr += bytes_read; | |
3803 | break; | |
3804 | case DW_FORM_block1: | |
3805 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
3806 | break; | |
3807 | case DW_FORM_block2: | |
3808 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
3809 | break; | |
3810 | case DW_FORM_block4: | |
3811 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
3812 | break; | |
3813 | case DW_FORM_sdata: | |
3814 | case DW_FORM_udata: | |
3815 | case DW_FORM_ref_udata: | |
3816 | info_ptr = skip_leb128 (abfd, info_ptr); | |
3817 | break; | |
3818 | case DW_FORM_indirect: | |
3819 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3820 | info_ptr += bytes_read; | |
3821 | /* We need to continue parsing from here, so just go back to | |
3822 | the top. */ | |
3823 | goto skip_attribute; | |
3824 | ||
3825 | default: | |
8a3fe4f8 | 3826 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
3827 | dwarf_form_name (form), |
3828 | bfd_get_filename (abfd)); | |
3829 | } | |
3830 | } | |
3831 | ||
3832 | if (abbrev->has_children) | |
93311388 | 3833 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
3834 | else |
3835 | return info_ptr; | |
3836 | } | |
3837 | ||
93311388 DE |
3838 | /* Locate ORIG_PDI's sibling. |
3839 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
3840 | in BUFFER. */ | |
91c24f0a | 3841 | |
fe1b8b76 | 3842 | static gdb_byte * |
93311388 DE |
3843 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
3844 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 3845 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
3846 | { |
3847 | /* Do we know the sibling already? */ | |
72bf9492 | 3848 | |
91c24f0a DC |
3849 | if (orig_pdi->sibling) |
3850 | return orig_pdi->sibling; | |
3851 | ||
3852 | /* Are there any children to deal with? */ | |
3853 | ||
3854 | if (!orig_pdi->has_children) | |
3855 | return info_ptr; | |
3856 | ||
4bb7a0a7 | 3857 | /* Skip the children the long way. */ |
91c24f0a | 3858 | |
93311388 | 3859 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
3860 | } |
3861 | ||
c906108c SS |
3862 | /* Expand this partial symbol table into a full symbol table. */ |
3863 | ||
3864 | static void | |
fba45db2 | 3865 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 3866 | { |
c906108c SS |
3867 | if (pst != NULL) |
3868 | { | |
3869 | if (pst->readin) | |
3870 | { | |
8a3fe4f8 | 3871 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
3872 | } |
3873 | else | |
3874 | { | |
3875 | if (info_verbose) | |
3876 | { | |
a3f17187 | 3877 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
3878 | gdb_flush (gdb_stdout); |
3879 | } | |
3880 | ||
10b3939b DJ |
3881 | /* Restore our global data. */ |
3882 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
3883 | dwarf2_objfile_data_key); | |
3884 | ||
b2ab525c KB |
3885 | /* If this psymtab is constructed from a debug-only objfile, the |
3886 | has_section_at_zero flag will not necessarily be correct. We | |
3887 | can get the correct value for this flag by looking at the data | |
3888 | associated with the (presumably stripped) associated objfile. */ | |
3889 | if (pst->objfile->separate_debug_objfile_backlink) | |
3890 | { | |
3891 | struct dwarf2_per_objfile *dpo_backlink | |
3892 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
3893 | dwarf2_objfile_data_key); | |
9a619af0 | 3894 | |
b2ab525c KB |
3895 | dwarf2_per_objfile->has_section_at_zero |
3896 | = dpo_backlink->has_section_at_zero; | |
3897 | } | |
3898 | ||
c906108c SS |
3899 | psymtab_to_symtab_1 (pst); |
3900 | ||
3901 | /* Finish up the debug error message. */ | |
3902 | if (info_verbose) | |
a3f17187 | 3903 | printf_filtered (_("done.\n")); |
c906108c SS |
3904 | } |
3905 | } | |
3906 | } | |
3907 | ||
10b3939b DJ |
3908 | /* Add PER_CU to the queue. */ |
3909 | ||
3910 | static void | |
03dd20cc | 3911 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
3912 | { |
3913 | struct dwarf2_queue_item *item; | |
3914 | ||
3915 | per_cu->queued = 1; | |
3916 | item = xmalloc (sizeof (*item)); | |
3917 | item->per_cu = per_cu; | |
3918 | item->next = NULL; | |
3919 | ||
3920 | if (dwarf2_queue == NULL) | |
3921 | dwarf2_queue = item; | |
3922 | else | |
3923 | dwarf2_queue_tail->next = item; | |
3924 | ||
3925 | dwarf2_queue_tail = item; | |
3926 | } | |
3927 | ||
3928 | /* Process the queue. */ | |
3929 | ||
3930 | static void | |
3931 | process_queue (struct objfile *objfile) | |
3932 | { | |
3933 | struct dwarf2_queue_item *item, *next_item; | |
3934 | ||
03dd20cc DJ |
3935 | /* The queue starts out with one item, but following a DIE reference |
3936 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
3937 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
3938 | { | |
9291a0cd TT |
3939 | if (dwarf2_per_objfile->using_index |
3940 | ? !item->per_cu->v.quick->symtab | |
3941 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
3942 | process_full_comp_unit (item->per_cu); |
3943 | ||
3944 | item->per_cu->queued = 0; | |
3945 | next_item = item->next; | |
3946 | xfree (item); | |
3947 | } | |
3948 | ||
3949 | dwarf2_queue_tail = NULL; | |
3950 | } | |
3951 | ||
3952 | /* Free all allocated queue entries. This function only releases anything if | |
3953 | an error was thrown; if the queue was processed then it would have been | |
3954 | freed as we went along. */ | |
3955 | ||
3956 | static void | |
3957 | dwarf2_release_queue (void *dummy) | |
3958 | { | |
3959 | struct dwarf2_queue_item *item, *last; | |
3960 | ||
3961 | item = dwarf2_queue; | |
3962 | while (item) | |
3963 | { | |
3964 | /* Anything still marked queued is likely to be in an | |
3965 | inconsistent state, so discard it. */ | |
3966 | if (item->per_cu->queued) | |
3967 | { | |
3968 | if (item->per_cu->cu != NULL) | |
3969 | free_one_cached_comp_unit (item->per_cu->cu); | |
3970 | item->per_cu->queued = 0; | |
3971 | } | |
3972 | ||
3973 | last = item; | |
3974 | item = item->next; | |
3975 | xfree (last); | |
3976 | } | |
3977 | ||
3978 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
3979 | } | |
3980 | ||
3981 | /* Read in full symbols for PST, and anything it depends on. */ | |
3982 | ||
c906108c | 3983 | static void |
fba45db2 | 3984 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 3985 | { |
10b3939b | 3986 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 3987 | struct cleanup *back_to; |
aaa75496 JB |
3988 | int i; |
3989 | ||
3990 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3991 | if (!pst->dependencies[i]->readin) | |
3992 | { | |
3993 | /* Inform about additional files that need to be read in. */ | |
3994 | if (info_verbose) | |
3995 | { | |
a3f17187 | 3996 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
3997 | fputs_filtered (" ", gdb_stdout); |
3998 | wrap_here (""); | |
3999 | fputs_filtered ("and ", gdb_stdout); | |
4000 | wrap_here (""); | |
4001 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
4002 | wrap_here (""); /* Flush output */ | |
4003 | gdb_flush (gdb_stdout); | |
4004 | } | |
4005 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4006 | } | |
4007 | ||
e38df1d0 | 4008 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4009 | |
4010 | if (per_cu == NULL) | |
aaa75496 JB |
4011 | { |
4012 | /* It's an include file, no symbols to read for it. | |
4013 | Everything is in the parent symtab. */ | |
4014 | pst->readin = 1; | |
4015 | return; | |
4016 | } | |
c906108c | 4017 | |
9291a0cd | 4018 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4019 | } |
4020 | ||
93311388 | 4021 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4022 | |
93311388 | 4023 | static void |
31ffec48 | 4024 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 4025 | { |
31ffec48 | 4026 | bfd *abfd = objfile->obfd; |
10b3939b | 4027 | struct dwarf2_cu *cu; |
c764a876 | 4028 | unsigned int offset; |
93311388 | 4029 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
4030 | struct cleanup *back_to, *free_cu_cleanup; |
4031 | struct attribute *attr; | |
6502dd73 | 4032 | |
348e048f DE |
4033 | gdb_assert (! per_cu->from_debug_types); |
4034 | ||
c906108c | 4035 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4036 | offset = per_cu->offset; |
6502dd73 | 4037 | |
be391dca | 4038 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4039 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4040 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4041 | |
93311388 | 4042 | cu = alloc_one_comp_unit (objfile); |
c906108c | 4043 | |
10b3939b DJ |
4044 | /* If an error occurs while loading, release our storage. */ |
4045 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4046 | |
93311388 | 4047 | /* Read in the comp_unit header. */ |
10b3939b | 4048 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 4049 | |
93311388 DE |
4050 | /* Complete the cu_header. */ |
4051 | cu->header.offset = offset; | |
4052 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
4053 | ||
4054 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
4055 | dwarf2_read_abbrevs (abfd, cu); |
4056 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
4057 | ||
93311388 | 4058 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 4059 | per_cu->cu = cu; |
93311388 | 4060 | cu->per_cu = per_cu; |
f792889a | 4061 | cu->type_hash = per_cu->type_hash; |
e142c38c | 4062 | |
93311388 | 4063 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4064 | |
4065 | /* We try not to read any attributes in this function, because not | |
4066 | all objfiles needed for references have been loaded yet, and symbol | |
4067 | table processing isn't initialized. But we have to set the CU language, | |
4068 | or we won't be able to build types correctly. */ | |
4069 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
4070 | if (attr) | |
4071 | set_cu_language (DW_UNSND (attr), cu); | |
4072 | else | |
4073 | set_cu_language (language_minimal, cu); | |
4074 | ||
a6c727b2 DJ |
4075 | /* Similarly, if we do not read the producer, we can not apply |
4076 | producer-specific interpretation. */ | |
4077 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4078 | if (attr) | |
4079 | cu->producer = DW_STRING (attr); | |
4080 | ||
348e048f DE |
4081 | /* Link this CU into read_in_chain. */ |
4082 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4083 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4084 | ||
10b3939b | 4085 | do_cleanups (back_to); |
e142c38c | 4086 | |
10b3939b DJ |
4087 | /* We've successfully allocated this compilation unit. Let our caller |
4088 | clean it up when finished with it. */ | |
4089 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
4090 | } |
4091 | ||
4092 | /* Generate full symbol information for PST and CU, whose DIEs have | |
4093 | already been loaded into memory. */ | |
4094 | ||
4095 | static void | |
4096 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4097 | { | |
10b3939b | 4098 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4099 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4100 | CORE_ADDR lowpc, highpc; |
4101 | struct symtab *symtab; | |
4102 | struct cleanup *back_to; | |
10b3939b DJ |
4103 | CORE_ADDR baseaddr; |
4104 | ||
4105 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4106 | ||
10b3939b DJ |
4107 | buildsym_init (); |
4108 | back_to = make_cleanup (really_free_pendings, NULL); | |
4109 | ||
4110 | cu->list_in_scope = &file_symbols; | |
c906108c | 4111 | |
d85a05f0 | 4112 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4113 | |
c906108c | 4114 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4115 | process_die (cu->dies, cu); |
c906108c | 4116 | |
fae299cd DC |
4117 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4118 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4119 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4120 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4121 | |
613e1657 | 4122 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
4123 | |
4124 | /* Set symtab language to language from DW_AT_language. | |
4125 | If the compilation is from a C file generated by language preprocessors, | |
4126 | do not set the language if it was already deduced by start_subfile. */ | |
4127 | if (symtab != NULL | |
10b3939b | 4128 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 4129 | { |
10b3939b | 4130 | symtab->language = cu->language; |
c906108c | 4131 | } |
9291a0cd TT |
4132 | |
4133 | if (dwarf2_per_objfile->using_index) | |
4134 | per_cu->v.quick->symtab = symtab; | |
4135 | else | |
4136 | { | |
4137 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4138 | pst->symtab = symtab; | |
4139 | pst->readin = 1; | |
4140 | } | |
c906108c SS |
4141 | |
4142 | do_cleanups (back_to); | |
4143 | } | |
4144 | ||
4145 | /* Process a die and its children. */ | |
4146 | ||
4147 | static void | |
e7c27a73 | 4148 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4149 | { |
4150 | switch (die->tag) | |
4151 | { | |
4152 | case DW_TAG_padding: | |
4153 | break; | |
4154 | case DW_TAG_compile_unit: | |
e7c27a73 | 4155 | read_file_scope (die, cu); |
c906108c | 4156 | break; |
348e048f DE |
4157 | case DW_TAG_type_unit: |
4158 | read_type_unit_scope (die, cu); | |
4159 | break; | |
c906108c | 4160 | case DW_TAG_subprogram: |
c906108c | 4161 | case DW_TAG_inlined_subroutine: |
edb3359d | 4162 | read_func_scope (die, cu); |
c906108c SS |
4163 | break; |
4164 | case DW_TAG_lexical_block: | |
14898363 L |
4165 | case DW_TAG_try_block: |
4166 | case DW_TAG_catch_block: | |
e7c27a73 | 4167 | read_lexical_block_scope (die, cu); |
c906108c SS |
4168 | break; |
4169 | case DW_TAG_class_type: | |
680b30c7 | 4170 | case DW_TAG_interface_type: |
c906108c SS |
4171 | case DW_TAG_structure_type: |
4172 | case DW_TAG_union_type: | |
134d01f1 | 4173 | process_structure_scope (die, cu); |
c906108c SS |
4174 | break; |
4175 | case DW_TAG_enumeration_type: | |
134d01f1 | 4176 | process_enumeration_scope (die, cu); |
c906108c | 4177 | break; |
134d01f1 | 4178 | |
f792889a DJ |
4179 | /* These dies have a type, but processing them does not create |
4180 | a symbol or recurse to process the children. Therefore we can | |
4181 | read them on-demand through read_type_die. */ | |
c906108c | 4182 | case DW_TAG_subroutine_type: |
72019c9c | 4183 | case DW_TAG_set_type: |
c906108c | 4184 | case DW_TAG_array_type: |
c906108c | 4185 | case DW_TAG_pointer_type: |
c906108c | 4186 | case DW_TAG_ptr_to_member_type: |
c906108c | 4187 | case DW_TAG_reference_type: |
c906108c | 4188 | case DW_TAG_string_type: |
c906108c | 4189 | break; |
134d01f1 | 4190 | |
c906108c | 4191 | case DW_TAG_base_type: |
a02abb62 | 4192 | case DW_TAG_subrange_type: |
cb249c71 | 4193 | case DW_TAG_typedef: |
134d01f1 DJ |
4194 | /* Add a typedef symbol for the type definition, if it has a |
4195 | DW_AT_name. */ | |
f792889a | 4196 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4197 | break; |
c906108c | 4198 | case DW_TAG_common_block: |
e7c27a73 | 4199 | read_common_block (die, cu); |
c906108c SS |
4200 | break; |
4201 | case DW_TAG_common_inclusion: | |
4202 | break; | |
d9fa45fe | 4203 | case DW_TAG_namespace: |
63d06c5c | 4204 | processing_has_namespace_info = 1; |
e7c27a73 | 4205 | read_namespace (die, cu); |
d9fa45fe | 4206 | break; |
5d7cb8df | 4207 | case DW_TAG_module: |
f55ee35c | 4208 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4209 | read_module (die, cu); |
4210 | break; | |
d9fa45fe DC |
4211 | case DW_TAG_imported_declaration: |
4212 | case DW_TAG_imported_module: | |
63d06c5c | 4213 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4214 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4215 | || cu->language != language_fortran)) | |
4216 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4217 | dwarf_tag_name (die->tag)); | |
4218 | read_import_statement (die, cu); | |
d9fa45fe | 4219 | break; |
c906108c | 4220 | default: |
e7c27a73 | 4221 | new_symbol (die, NULL, cu); |
c906108c SS |
4222 | break; |
4223 | } | |
4224 | } | |
4225 | ||
94af9270 KS |
4226 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4227 | needs to have the name of the scope prepended to the name listed in the | |
4228 | die. */ | |
4229 | ||
4230 | static int | |
4231 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4232 | { | |
1c809c68 TT |
4233 | struct attribute *attr; |
4234 | ||
94af9270 KS |
4235 | switch (die->tag) |
4236 | { | |
4237 | case DW_TAG_namespace: | |
4238 | case DW_TAG_typedef: | |
4239 | case DW_TAG_class_type: | |
4240 | case DW_TAG_interface_type: | |
4241 | case DW_TAG_structure_type: | |
4242 | case DW_TAG_union_type: | |
4243 | case DW_TAG_enumeration_type: | |
4244 | case DW_TAG_enumerator: | |
4245 | case DW_TAG_subprogram: | |
4246 | case DW_TAG_member: | |
4247 | return 1; | |
4248 | ||
4249 | case DW_TAG_variable: | |
4250 | /* We only need to prefix "globally" visible variables. These include | |
4251 | any variable marked with DW_AT_external or any variable that | |
4252 | lives in a namespace. [Variables in anonymous namespaces | |
4253 | require prefixing, but they are not DW_AT_external.] */ | |
4254 | ||
4255 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4256 | { | |
4257 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4258 | |
94af9270 KS |
4259 | return die_needs_namespace (die_specification (die, &spec_cu), |
4260 | spec_cu); | |
4261 | } | |
4262 | ||
1c809c68 | 4263 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4264 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4265 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4266 | return 0; |
4267 | /* A variable in a lexical block of some kind does not need a | |
4268 | namespace, even though in C++ such variables may be external | |
4269 | and have a mangled name. */ | |
4270 | if (die->parent->tag == DW_TAG_lexical_block | |
4271 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4272 | || die->parent->tag == DW_TAG_catch_block |
4273 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4274 | return 0; |
4275 | return 1; | |
94af9270 KS |
4276 | |
4277 | default: | |
4278 | return 0; | |
4279 | } | |
4280 | } | |
4281 | ||
4282 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, | |
4283 | compute the physname for the object, which include a method's | |
4284 | formal parameters (C++/Java) and return type (Java). | |
4285 | ||
af6b7be1 JB |
4286 | For Ada, return the DIE's linkage name rather than the fully qualified |
4287 | name. PHYSNAME is ignored.. | |
4288 | ||
94af9270 KS |
4289 | The result is allocated on the objfile_obstack and canonicalized. */ |
4290 | ||
4291 | static const char * | |
4292 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4293 | int physname) | |
4294 | { | |
4295 | if (name == NULL) | |
4296 | name = dwarf2_name (die, cu); | |
4297 | ||
f55ee35c JK |
4298 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4299 | compute it by typename_concat inside GDB. */ | |
4300 | if (cu->language == language_ada | |
4301 | || (cu->language == language_fortran && physname)) | |
4302 | { | |
4303 | /* For Ada unit, we prefer the linkage name over the name, as | |
4304 | the former contains the exported name, which the user expects | |
4305 | to be able to reference. Ideally, we want the user to be able | |
4306 | to reference this entity using either natural or linkage name, | |
4307 | but we haven't started looking at this enhancement yet. */ | |
4308 | struct attribute *attr; | |
4309 | ||
4310 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4311 | if (attr == NULL) | |
4312 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4313 | if (attr && DW_STRING (attr)) | |
4314 | return DW_STRING (attr); | |
4315 | } | |
4316 | ||
94af9270 KS |
4317 | /* These are the only languages we know how to qualify names in. */ |
4318 | if (name != NULL | |
f55ee35c JK |
4319 | && (cu->language == language_cplus || cu->language == language_java |
4320 | || cu->language == language_fortran)) | |
94af9270 KS |
4321 | { |
4322 | if (die_needs_namespace (die, cu)) | |
4323 | { | |
4324 | long length; | |
4325 | char *prefix; | |
4326 | struct ui_file *buf; | |
4327 | ||
4328 | prefix = determine_prefix (die, cu); | |
4329 | buf = mem_fileopen (); | |
4330 | if (*prefix != '\0') | |
4331 | { | |
f55ee35c JK |
4332 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4333 | physname, cu); | |
9a619af0 | 4334 | |
94af9270 KS |
4335 | fputs_unfiltered (prefixed_name, buf); |
4336 | xfree (prefixed_name); | |
4337 | } | |
4338 | else | |
4339 | fputs_unfiltered (name ? name : "", buf); | |
4340 | ||
4341 | /* For Java and C++ methods, append formal parameter type | |
4342 | information, if PHYSNAME. */ | |
6e70227d | 4343 | |
94af9270 KS |
4344 | if (physname && die->tag == DW_TAG_subprogram |
4345 | && (cu->language == language_cplus | |
4346 | || cu->language == language_java)) | |
4347 | { | |
4348 | struct type *type = read_type_die (die, cu); | |
4349 | ||
4350 | c_type_print_args (type, buf, 0, cu->language); | |
4351 | ||
4352 | if (cu->language == language_java) | |
4353 | { | |
4354 | /* For java, we must append the return type to method | |
4355 | names. */ | |
4356 | if (die->tag == DW_TAG_subprogram) | |
4357 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
4358 | 0, 0); | |
4359 | } | |
4360 | else if (cu->language == language_cplus) | |
4361 | { | |
4362 | if (TYPE_NFIELDS (type) > 0 | |
4363 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
4364 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) | |
4365 | fputs_unfiltered (" const", buf); | |
4366 | } | |
4367 | } | |
4368 | ||
4369 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
4370 | &length); | |
4371 | ui_file_delete (buf); | |
4372 | ||
4373 | if (cu->language == language_cplus) | |
4374 | { | |
4375 | char *cname | |
4376 | = dwarf2_canonicalize_name (name, cu, | |
4377 | &cu->objfile->objfile_obstack); | |
9a619af0 | 4378 | |
94af9270 KS |
4379 | if (cname != NULL) |
4380 | name = cname; | |
4381 | } | |
4382 | } | |
4383 | } | |
4384 | ||
4385 | return name; | |
4386 | } | |
4387 | ||
0114d602 DJ |
4388 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
4389 | If scope qualifiers are appropriate they will be added. The result | |
4390 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
4391 | not have a name. NAME may either be from a previous call to |
4392 | dwarf2_name or NULL. | |
4393 | ||
4394 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
4395 | |
4396 | static const char * | |
94af9270 | 4397 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 4398 | { |
94af9270 KS |
4399 | return dwarf2_compute_name (name, die, cu, 0); |
4400 | } | |
0114d602 | 4401 | |
94af9270 KS |
4402 | /* Construct a physname for the given DIE in CU. NAME may either be |
4403 | from a previous call to dwarf2_name or NULL. The result will be | |
4404 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
4405 | name. | |
0114d602 | 4406 | |
94af9270 | 4407 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 4408 | |
94af9270 KS |
4409 | static const char * |
4410 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
4411 | { | |
4412 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
4413 | } |
4414 | ||
27aa8d6a SW |
4415 | /* Read the import statement specified by the given die and record it. */ |
4416 | ||
4417 | static void | |
4418 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
4419 | { | |
4420 | struct attribute *import_attr; | |
4421 | struct die_info *imported_die; | |
de4affc9 | 4422 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 4423 | const char *imported_name; |
794684b6 | 4424 | const char *imported_name_prefix; |
13387711 SW |
4425 | const char *canonical_name; |
4426 | const char *import_alias; | |
4427 | const char *imported_declaration = NULL; | |
794684b6 | 4428 | const char *import_prefix; |
13387711 SW |
4429 | |
4430 | char *temp; | |
27aa8d6a SW |
4431 | |
4432 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
4433 | if (import_attr == NULL) | |
4434 | { | |
4435 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
4436 | dwarf_tag_name (die->tag)); | |
4437 | return; | |
4438 | } | |
4439 | ||
de4affc9 CC |
4440 | imported_cu = cu; |
4441 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
4442 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
4443 | if (imported_name == NULL) |
4444 | { | |
4445 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
4446 | ||
4447 | The import in the following code: | |
4448 | namespace A | |
4449 | { | |
4450 | typedef int B; | |
4451 | } | |
4452 | ||
4453 | int main () | |
4454 | { | |
4455 | using A::B; | |
4456 | B b; | |
4457 | return b; | |
4458 | } | |
4459 | ||
4460 | ... | |
4461 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
4462 | <52> DW_AT_decl_file : 1 | |
4463 | <53> DW_AT_decl_line : 6 | |
4464 | <54> DW_AT_import : <0x75> | |
4465 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
4466 | <59> DW_AT_name : B | |
4467 | <5b> DW_AT_decl_file : 1 | |
4468 | <5c> DW_AT_decl_line : 2 | |
4469 | <5d> DW_AT_type : <0x6e> | |
4470 | ... | |
4471 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
4472 | <76> DW_AT_byte_size : 4 | |
4473 | <77> DW_AT_encoding : 5 (signed) | |
4474 | ||
4475 | imports the wrong die ( 0x75 instead of 0x58 ). | |
4476 | This case will be ignored until the gcc bug is fixed. */ | |
4477 | return; | |
4478 | } | |
4479 | ||
82856980 SW |
4480 | /* Figure out the local name after import. */ |
4481 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 4482 | |
794684b6 SW |
4483 | /* Figure out where the statement is being imported to. */ |
4484 | import_prefix = determine_prefix (die, cu); | |
4485 | ||
4486 | /* Figure out what the scope of the imported die is and prepend it | |
4487 | to the name of the imported die. */ | |
de4affc9 | 4488 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 4489 | |
f55ee35c JK |
4490 | if (imported_die->tag != DW_TAG_namespace |
4491 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 4492 | { |
13387711 SW |
4493 | imported_declaration = imported_name; |
4494 | canonical_name = imported_name_prefix; | |
794684b6 | 4495 | } |
13387711 | 4496 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 4497 | { |
13387711 SW |
4498 | temp = alloca (strlen (imported_name_prefix) |
4499 | + 2 + strlen (imported_name) + 1); | |
4500 | strcpy (temp, imported_name_prefix); | |
4501 | strcat (temp, "::"); | |
4502 | strcat (temp, imported_name); | |
4503 | canonical_name = temp; | |
794684b6 | 4504 | } |
13387711 SW |
4505 | else |
4506 | canonical_name = imported_name; | |
794684b6 | 4507 | |
c0cc3a76 SW |
4508 | cp_add_using_directive (import_prefix, |
4509 | canonical_name, | |
4510 | import_alias, | |
13387711 | 4511 | imported_declaration, |
c0cc3a76 | 4512 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
4513 | } |
4514 | ||
5fb290d7 | 4515 | static void |
e142c38c | 4516 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 4517 | { |
e142c38c | 4518 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
4519 | } |
4520 | ||
cb1df416 DJ |
4521 | static void |
4522 | free_cu_line_header (void *arg) | |
4523 | { | |
4524 | struct dwarf2_cu *cu = arg; | |
4525 | ||
4526 | free_line_header (cu->line_header); | |
4527 | cu->line_header = NULL; | |
4528 | } | |
4529 | ||
9291a0cd TT |
4530 | static void |
4531 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
4532 | char **name, char **comp_dir) | |
4533 | { | |
4534 | struct attribute *attr; | |
4535 | ||
4536 | *name = NULL; | |
4537 | *comp_dir = NULL; | |
4538 | ||
4539 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
4540 | is not a source language identifier. */ | |
4541 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
4542 | if (attr) | |
4543 | { | |
4544 | *name = DW_STRING (attr); | |
4545 | } | |
4546 | ||
4547 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
4548 | if (attr) | |
4549 | *comp_dir = DW_STRING (attr); | |
4550 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
4551 | { | |
4552 | *comp_dir = ldirname (*name); | |
4553 | if (*comp_dir != NULL) | |
4554 | make_cleanup (xfree, *comp_dir); | |
4555 | } | |
4556 | if (*comp_dir != NULL) | |
4557 | { | |
4558 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
4559 | directory, get rid of it. */ | |
4560 | char *cp = strchr (*comp_dir, ':'); | |
4561 | ||
4562 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
4563 | *comp_dir = cp + 1; | |
4564 | } | |
4565 | ||
4566 | if (*name == NULL) | |
4567 | *name = "<unknown>"; | |
4568 | } | |
4569 | ||
c906108c | 4570 | static void |
e7c27a73 | 4571 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4572 | { |
e7c27a73 | 4573 | struct objfile *objfile = cu->objfile; |
debd256d | 4574 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 4575 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
4576 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
4577 | struct attribute *attr; | |
e1024ff1 | 4578 | char *name = NULL; |
c906108c SS |
4579 | char *comp_dir = NULL; |
4580 | struct die_info *child_die; | |
4581 | bfd *abfd = objfile->obfd; | |
debd256d | 4582 | struct line_header *line_header = 0; |
e142c38c | 4583 | CORE_ADDR baseaddr; |
6e70227d | 4584 | |
e142c38c | 4585 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 4586 | |
fae299cd | 4587 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
4588 | |
4589 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
4590 | from finish_block. */ | |
2acceee2 | 4591 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
4592 | lowpc = highpc; |
4593 | lowpc += baseaddr; | |
4594 | highpc += baseaddr; | |
4595 | ||
9291a0cd | 4596 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 4597 | |
e142c38c | 4598 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
4599 | if (attr) |
4600 | { | |
e142c38c | 4601 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
4602 | } |
4603 | ||
b0f35d58 | 4604 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 4605 | if (attr) |
b0f35d58 | 4606 | cu->producer = DW_STRING (attr); |
303b6f5d | 4607 | |
c906108c SS |
4608 | /* We assume that we're processing GCC output. */ |
4609 | processing_gcc_compilation = 2; | |
c906108c | 4610 | |
df8a16a1 DJ |
4611 | processing_has_namespace_info = 0; |
4612 | ||
c906108c SS |
4613 | start_symtab (name, comp_dir, lowpc); |
4614 | record_debugformat ("DWARF 2"); | |
303b6f5d | 4615 | record_producer (cu->producer); |
c906108c | 4616 | |
e142c38c | 4617 | initialize_cu_func_list (cu); |
c906108c | 4618 | |
cb1df416 DJ |
4619 | /* Decode line number information if present. We do this before |
4620 | processing child DIEs, so that the line header table is available | |
4621 | for DW_AT_decl_file. */ | |
e142c38c | 4622 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
4623 | if (attr) |
4624 | { | |
debd256d | 4625 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 4626 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
4627 | if (line_header) |
4628 | { | |
cb1df416 DJ |
4629 | cu->line_header = line_header; |
4630 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 4631 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 4632 | } |
5fb290d7 | 4633 | } |
debd256d | 4634 | |
cb1df416 DJ |
4635 | /* Process all dies in compilation unit. */ |
4636 | if (die->child != NULL) | |
4637 | { | |
4638 | child_die = die->child; | |
4639 | while (child_die && child_die->tag) | |
4640 | { | |
4641 | process_die (child_die, cu); | |
4642 | child_die = sibling_die (child_die); | |
4643 | } | |
4644 | } | |
4645 | ||
2e276125 JB |
4646 | /* Decode macro information, if present. Dwarf 2 macro information |
4647 | refers to information in the line number info statement program | |
4648 | header, so we can only read it if we've read the header | |
4649 | successfully. */ | |
e142c38c | 4650 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 4651 | if (attr && line_header) |
2e276125 JB |
4652 | { |
4653 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 4654 | |
2e276125 | 4655 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 4656 | comp_dir, abfd, cu); |
2e276125 | 4657 | } |
debd256d | 4658 | do_cleanups (back_to); |
5fb290d7 DJ |
4659 | } |
4660 | ||
348e048f DE |
4661 | /* For TUs we want to skip the first top level sibling if it's not the |
4662 | actual type being defined by this TU. In this case the first top | |
4663 | level sibling is there to provide context only. */ | |
4664 | ||
4665 | static void | |
4666 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4667 | { | |
4668 | struct objfile *objfile = cu->objfile; | |
4669 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
4670 | CORE_ADDR lowpc; | |
4671 | struct attribute *attr; | |
4672 | char *name = NULL; | |
4673 | char *comp_dir = NULL; | |
4674 | struct die_info *child_die; | |
4675 | bfd *abfd = objfile->obfd; | |
348e048f DE |
4676 | |
4677 | /* start_symtab needs a low pc, but we don't really have one. | |
4678 | Do what read_file_scope would do in the absence of such info. */ | |
4679 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4680 | ||
4681 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
4682 | is not a source language identifier. */ | |
4683 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
4684 | if (attr) | |
4685 | name = DW_STRING (attr); | |
4686 | ||
4687 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
4688 | if (attr) | |
4689 | comp_dir = DW_STRING (attr); | |
4690 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
4691 | { | |
4692 | comp_dir = ldirname (name); | |
4693 | if (comp_dir != NULL) | |
4694 | make_cleanup (xfree, comp_dir); | |
4695 | } | |
4696 | ||
4697 | if (name == NULL) | |
4698 | name = "<unknown>"; | |
4699 | ||
4700 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
4701 | if (attr) | |
4702 | set_cu_language (DW_UNSND (attr), cu); | |
4703 | ||
4704 | /* This isn't technically needed today. It is done for symmetry | |
4705 | with read_file_scope. */ | |
4706 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 4707 | if (attr) |
348e048f DE |
4708 | cu->producer = DW_STRING (attr); |
4709 | ||
4710 | /* We assume that we're processing GCC output. */ | |
4711 | processing_gcc_compilation = 2; | |
4712 | ||
4713 | processing_has_namespace_info = 0; | |
4714 | ||
4715 | start_symtab (name, comp_dir, lowpc); | |
4716 | record_debugformat ("DWARF 2"); | |
4717 | record_producer (cu->producer); | |
4718 | ||
4719 | /* Process the dies in the type unit. */ | |
4720 | if (die->child == NULL) | |
4721 | { | |
4722 | dump_die_for_error (die); | |
4723 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
4724 | bfd_get_filename (abfd)); | |
4725 | } | |
4726 | ||
4727 | child_die = die->child; | |
4728 | ||
4729 | while (child_die && child_die->tag) | |
4730 | { | |
4731 | process_die (child_die, cu); | |
4732 | ||
4733 | child_die = sibling_die (child_die); | |
4734 | } | |
4735 | ||
4736 | do_cleanups (back_to); | |
4737 | } | |
4738 | ||
5fb290d7 | 4739 | static void |
e142c38c DJ |
4740 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
4741 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
4742 | { |
4743 | struct function_range *thisfn; | |
4744 | ||
4745 | thisfn = (struct function_range *) | |
7b5a2f43 | 4746 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
4747 | thisfn->name = name; |
4748 | thisfn->lowpc = lowpc; | |
4749 | thisfn->highpc = highpc; | |
4750 | thisfn->seen_line = 0; | |
4751 | thisfn->next = NULL; | |
4752 | ||
e142c38c DJ |
4753 | if (cu->last_fn == NULL) |
4754 | cu->first_fn = thisfn; | |
5fb290d7 | 4755 | else |
e142c38c | 4756 | cu->last_fn->next = thisfn; |
5fb290d7 | 4757 | |
e142c38c | 4758 | cu->last_fn = thisfn; |
c906108c SS |
4759 | } |
4760 | ||
d389af10 JK |
4761 | /* qsort helper for inherit_abstract_dies. */ |
4762 | ||
4763 | static int | |
4764 | unsigned_int_compar (const void *ap, const void *bp) | |
4765 | { | |
4766 | unsigned int a = *(unsigned int *) ap; | |
4767 | unsigned int b = *(unsigned int *) bp; | |
4768 | ||
4769 | return (a > b) - (b > a); | |
4770 | } | |
4771 | ||
4772 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
4773 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
4774 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
4775 | ||
4776 | static void | |
4777 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
4778 | { | |
4779 | struct die_info *child_die; | |
4780 | unsigned die_children_count; | |
4781 | /* CU offsets which were referenced by children of the current DIE. */ | |
4782 | unsigned *offsets; | |
4783 | unsigned *offsets_end, *offsetp; | |
4784 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
4785 | struct die_info *origin_die; | |
4786 | /* Iterator of the ORIGIN_DIE children. */ | |
4787 | struct die_info *origin_child_die; | |
4788 | struct cleanup *cleanups; | |
4789 | struct attribute *attr; | |
4790 | ||
4791 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
4792 | if (!attr) | |
4793 | return; | |
4794 | ||
4795 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
4796 | if (die->tag != origin_die->tag |
4797 | && !(die->tag == DW_TAG_inlined_subroutine | |
4798 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
4799 | complaint (&symfile_complaints, |
4800 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
4801 | die->offset, origin_die->offset); | |
4802 | ||
4803 | child_die = die->child; | |
4804 | die_children_count = 0; | |
4805 | while (child_die && child_die->tag) | |
4806 | { | |
4807 | child_die = sibling_die (child_die); | |
4808 | die_children_count++; | |
4809 | } | |
4810 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
4811 | cleanups = make_cleanup (xfree, offsets); | |
4812 | ||
4813 | offsets_end = offsets; | |
4814 | child_die = die->child; | |
4815 | while (child_die && child_die->tag) | |
4816 | { | |
c38f313d DJ |
4817 | /* For each CHILD_DIE, find the corresponding child of |
4818 | ORIGIN_DIE. If there is more than one layer of | |
4819 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
4820 | but GCC versions at least through 4.4 generate this (GCC PR | |
4821 | 40573). */ | |
4822 | struct die_info *child_origin_die = child_die; | |
9a619af0 | 4823 | |
c38f313d DJ |
4824 | while (1) |
4825 | { | |
4826 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
4827 | if (attr == NULL) | |
4828 | break; | |
4829 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
4830 | } | |
4831 | ||
d389af10 JK |
4832 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
4833 | counterpart may exist. */ | |
c38f313d | 4834 | if (child_origin_die != child_die) |
d389af10 | 4835 | { |
edb3359d DJ |
4836 | if (child_die->tag != child_origin_die->tag |
4837 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
4838 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
4839 | complaint (&symfile_complaints, |
4840 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
4841 | "different tags"), child_die->offset, | |
4842 | child_origin_die->offset); | |
c38f313d DJ |
4843 | if (child_origin_die->parent != origin_die) |
4844 | complaint (&symfile_complaints, | |
4845 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
4846 | "different parents"), child_die->offset, | |
4847 | child_origin_die->offset); | |
4848 | else | |
4849 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
4850 | } |
4851 | child_die = sibling_die (child_die); | |
4852 | } | |
4853 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
4854 | unsigned_int_compar); | |
4855 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
4856 | if (offsetp[-1] == *offsetp) | |
4857 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
4858 | "to DIE 0x%x as their abstract origin"), | |
4859 | die->offset, *offsetp); | |
4860 | ||
4861 | offsetp = offsets; | |
4862 | origin_child_die = origin_die->child; | |
4863 | while (origin_child_die && origin_child_die->tag) | |
4864 | { | |
4865 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
4866 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
4867 | offsetp++; | |
4868 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
4869 | { | |
4870 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
4871 | process_die (origin_child_die, cu); | |
4872 | } | |
4873 | origin_child_die = sibling_die (origin_child_die); | |
4874 | } | |
4875 | ||
4876 | do_cleanups (cleanups); | |
4877 | } | |
4878 | ||
c906108c | 4879 | static void |
e7c27a73 | 4880 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4881 | { |
e7c27a73 | 4882 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 4883 | struct context_stack *new; |
c906108c SS |
4884 | CORE_ADDR lowpc; |
4885 | CORE_ADDR highpc; | |
4886 | struct die_info *child_die; | |
edb3359d | 4887 | struct attribute *attr, *call_line, *call_file; |
c906108c | 4888 | char *name; |
e142c38c | 4889 | CORE_ADDR baseaddr; |
801e3a5b | 4890 | struct block *block; |
edb3359d DJ |
4891 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
4892 | ||
4893 | if (inlined_func) | |
4894 | { | |
4895 | /* If we do not have call site information, we can't show the | |
4896 | caller of this inlined function. That's too confusing, so | |
4897 | only use the scope for local variables. */ | |
4898 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
4899 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
4900 | if (call_line == NULL || call_file == NULL) | |
4901 | { | |
4902 | read_lexical_block_scope (die, cu); | |
4903 | return; | |
4904 | } | |
4905 | } | |
c906108c | 4906 | |
e142c38c DJ |
4907 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
4908 | ||
94af9270 | 4909 | name = dwarf2_name (die, cu); |
c906108c | 4910 | |
e8d05480 JB |
4911 | /* Ignore functions with missing or empty names. These are actually |
4912 | illegal according to the DWARF standard. */ | |
4913 | if (name == NULL) | |
4914 | { | |
4915 | complaint (&symfile_complaints, | |
4916 | _("missing name for subprogram DIE at %d"), die->offset); | |
4917 | return; | |
4918 | } | |
4919 | ||
4920 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
4921 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
4922 | { | |
ae4d0c03 PM |
4923 | attr = dwarf2_attr (die, DW_AT_external, cu); |
4924 | if (!attr || !DW_UNSND (attr)) | |
4925 | complaint (&symfile_complaints, | |
4926 | _("cannot get low and high bounds for subprogram DIE at %d"), | |
4927 | die->offset); | |
e8d05480 JB |
4928 | return; |
4929 | } | |
c906108c SS |
4930 | |
4931 | lowpc += baseaddr; | |
4932 | highpc += baseaddr; | |
4933 | ||
5fb290d7 | 4934 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 4935 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 4936 | |
c906108c | 4937 | new = push_context (0, lowpc); |
f792889a | 4938 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 4939 | |
4cecd739 DJ |
4940 | /* If there is a location expression for DW_AT_frame_base, record |
4941 | it. */ | |
e142c38c | 4942 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 4943 | if (attr) |
c034e007 AC |
4944 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
4945 | expression is being recorded directly in the function's symbol | |
4946 | and not in a separate frame-base object. I guess this hack is | |
4947 | to avoid adding some sort of frame-base adjunct/annex to the | |
4948 | function's symbol :-(. The problem with doing this is that it | |
4949 | results in a function symbol with a location expression that | |
4950 | has nothing to do with the location of the function, ouch! The | |
4951 | relationship should be: a function's symbol has-a frame base; a | |
4952 | frame-base has-a location expression. */ | |
e7c27a73 | 4953 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 4954 | |
e142c38c | 4955 | cu->list_in_scope = &local_symbols; |
c906108c | 4956 | |
639d11d3 | 4957 | if (die->child != NULL) |
c906108c | 4958 | { |
639d11d3 | 4959 | child_die = die->child; |
c906108c SS |
4960 | while (child_die && child_die->tag) |
4961 | { | |
e7c27a73 | 4962 | process_die (child_die, cu); |
c906108c SS |
4963 | child_die = sibling_die (child_die); |
4964 | } | |
4965 | } | |
4966 | ||
d389af10 JK |
4967 | inherit_abstract_dies (die, cu); |
4968 | ||
4a811a97 UW |
4969 | /* If we have a DW_AT_specification, we might need to import using |
4970 | directives from the context of the specification DIE. See the | |
4971 | comment in determine_prefix. */ | |
4972 | if (cu->language == language_cplus | |
4973 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
4974 | { | |
4975 | struct dwarf2_cu *spec_cu = cu; | |
4976 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
4977 | ||
4978 | while (spec_die) | |
4979 | { | |
4980 | child_die = spec_die->child; | |
4981 | while (child_die && child_die->tag) | |
4982 | { | |
4983 | if (child_die->tag == DW_TAG_imported_module) | |
4984 | process_die (child_die, spec_cu); | |
4985 | child_die = sibling_die (child_die); | |
4986 | } | |
4987 | ||
4988 | /* In some cases, GCC generates specification DIEs that | |
4989 | themselves contain DW_AT_specification attributes. */ | |
4990 | spec_die = die_specification (spec_die, &spec_cu); | |
4991 | } | |
4992 | } | |
4993 | ||
c906108c SS |
4994 | new = pop_context (); |
4995 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
4996 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
4997 | lowpc, highpc, objfile); | |
4998 | ||
df8a16a1 | 4999 | /* For C++, set the block's scope. */ |
f55ee35c | 5000 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5001 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5002 | determine_prefix (die, cu), |
df8a16a1 DJ |
5003 | processing_has_namespace_info); |
5004 | ||
801e3a5b JB |
5005 | /* If we have address ranges, record them. */ |
5006 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5007 | |
208d8187 JB |
5008 | /* In C++, we can have functions nested inside functions (e.g., when |
5009 | a function declares a class that has methods). This means that | |
5010 | when we finish processing a function scope, we may need to go | |
5011 | back to building a containing block's symbol lists. */ | |
5012 | local_symbols = new->locals; | |
5013 | param_symbols = new->params; | |
27aa8d6a | 5014 | using_directives = new->using_directives; |
208d8187 | 5015 | |
921e78cf JB |
5016 | /* If we've finished processing a top-level function, subsequent |
5017 | symbols go in the file symbol list. */ | |
5018 | if (outermost_context_p ()) | |
e142c38c | 5019 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5020 | } |
5021 | ||
5022 | /* Process all the DIES contained within a lexical block scope. Start | |
5023 | a new scope, process the dies, and then close the scope. */ | |
5024 | ||
5025 | static void | |
e7c27a73 | 5026 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5027 | { |
e7c27a73 | 5028 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5029 | struct context_stack *new; |
c906108c SS |
5030 | CORE_ADDR lowpc, highpc; |
5031 | struct die_info *child_die; | |
e142c38c DJ |
5032 | CORE_ADDR baseaddr; |
5033 | ||
5034 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5035 | |
5036 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5037 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5038 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5039 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5040 | describe ranges. */ |
d85a05f0 | 5041 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5042 | return; |
5043 | lowpc += baseaddr; | |
5044 | highpc += baseaddr; | |
5045 | ||
5046 | push_context (0, lowpc); | |
639d11d3 | 5047 | if (die->child != NULL) |
c906108c | 5048 | { |
639d11d3 | 5049 | child_die = die->child; |
c906108c SS |
5050 | while (child_die && child_die->tag) |
5051 | { | |
e7c27a73 | 5052 | process_die (child_die, cu); |
c906108c SS |
5053 | child_die = sibling_die (child_die); |
5054 | } | |
5055 | } | |
5056 | new = pop_context (); | |
5057 | ||
8540c487 | 5058 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5059 | { |
801e3a5b JB |
5060 | struct block *block |
5061 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5062 | highpc, objfile); | |
5063 | ||
5064 | /* Note that recording ranges after traversing children, as we | |
5065 | do here, means that recording a parent's ranges entails | |
5066 | walking across all its children's ranges as they appear in | |
5067 | the address map, which is quadratic behavior. | |
5068 | ||
5069 | It would be nicer to record the parent's ranges before | |
5070 | traversing its children, simply overriding whatever you find | |
5071 | there. But since we don't even decide whether to create a | |
5072 | block until after we've traversed its children, that's hard | |
5073 | to do. */ | |
5074 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5075 | } |
5076 | local_symbols = new->locals; | |
27aa8d6a | 5077 | using_directives = new->using_directives; |
c906108c SS |
5078 | } |
5079 | ||
43039443 | 5080 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5081 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5082 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5083 | |
5084 | static int | |
5085 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5086 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5087 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5088 | { |
5089 | struct objfile *objfile = cu->objfile; | |
5090 | struct comp_unit_head *cu_header = &cu->header; | |
5091 | bfd *obfd = objfile->obfd; | |
5092 | unsigned int addr_size = cu_header->addr_size; | |
5093 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5094 | /* Base address selection entry. */ | |
5095 | CORE_ADDR base; | |
5096 | int found_base; | |
5097 | unsigned int dummy; | |
5098 | gdb_byte *buffer; | |
5099 | CORE_ADDR marker; | |
5100 | int low_set; | |
5101 | CORE_ADDR low = 0; | |
5102 | CORE_ADDR high = 0; | |
ff013f42 | 5103 | CORE_ADDR baseaddr; |
43039443 | 5104 | |
d00adf39 DE |
5105 | found_base = cu->base_known; |
5106 | base = cu->base_address; | |
43039443 | 5107 | |
be391dca | 5108 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5109 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5110 | { |
5111 | complaint (&symfile_complaints, | |
5112 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5113 | offset); | |
5114 | return 0; | |
5115 | } | |
dce234bc | 5116 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5117 | |
5118 | /* Read in the largest possible address. */ | |
5119 | marker = read_address (obfd, buffer, cu, &dummy); | |
5120 | if ((marker & mask) == mask) | |
5121 | { | |
5122 | /* If we found the largest possible address, then | |
5123 | read the base address. */ | |
5124 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5125 | buffer += 2 * addr_size; | |
5126 | offset += 2 * addr_size; | |
5127 | found_base = 1; | |
5128 | } | |
5129 | ||
5130 | low_set = 0; | |
5131 | ||
e7030f15 | 5132 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5133 | |
43039443 JK |
5134 | while (1) |
5135 | { | |
5136 | CORE_ADDR range_beginning, range_end; | |
5137 | ||
5138 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5139 | buffer += addr_size; | |
5140 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5141 | buffer += addr_size; | |
5142 | offset += 2 * addr_size; | |
5143 | ||
5144 | /* An end of list marker is a pair of zero addresses. */ | |
5145 | if (range_beginning == 0 && range_end == 0) | |
5146 | /* Found the end of list entry. */ | |
5147 | break; | |
5148 | ||
5149 | /* Each base address selection entry is a pair of 2 values. | |
5150 | The first is the largest possible address, the second is | |
5151 | the base address. Check for a base address here. */ | |
5152 | if ((range_beginning & mask) == mask) | |
5153 | { | |
5154 | /* If we found the largest possible address, then | |
5155 | read the base address. */ | |
5156 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5157 | found_base = 1; | |
5158 | continue; | |
5159 | } | |
5160 | ||
5161 | if (!found_base) | |
5162 | { | |
5163 | /* We have no valid base address for the ranges | |
5164 | data. */ | |
5165 | complaint (&symfile_complaints, | |
5166 | _("Invalid .debug_ranges data (no base address)")); | |
5167 | return 0; | |
5168 | } | |
5169 | ||
5170 | range_beginning += base; | |
5171 | range_end += base; | |
5172 | ||
ff013f42 JK |
5173 | if (ranges_pst != NULL && range_beginning < range_end) |
5174 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
5175 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
5176 | ranges_pst); | |
5177 | ||
43039443 JK |
5178 | /* FIXME: This is recording everything as a low-high |
5179 | segment of consecutive addresses. We should have a | |
5180 | data structure for discontiguous block ranges | |
5181 | instead. */ | |
5182 | if (! low_set) | |
5183 | { | |
5184 | low = range_beginning; | |
5185 | high = range_end; | |
5186 | low_set = 1; | |
5187 | } | |
5188 | else | |
5189 | { | |
5190 | if (range_beginning < low) | |
5191 | low = range_beginning; | |
5192 | if (range_end > high) | |
5193 | high = range_end; | |
5194 | } | |
5195 | } | |
5196 | ||
5197 | if (! low_set) | |
5198 | /* If the first entry is an end-of-list marker, the range | |
5199 | describes an empty scope, i.e. no instructions. */ | |
5200 | return 0; | |
5201 | ||
5202 | if (low_return) | |
5203 | *low_return = low; | |
5204 | if (high_return) | |
5205 | *high_return = high; | |
5206 | return 1; | |
5207 | } | |
5208 | ||
af34e669 DJ |
5209 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
5210 | are present and valid, otherwise, return 0. Return -1 if the range is | |
5211 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 5212 | static int |
af34e669 | 5213 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
5214 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
5215 | struct partial_symtab *pst) | |
c906108c SS |
5216 | { |
5217 | struct attribute *attr; | |
af34e669 DJ |
5218 | CORE_ADDR low = 0; |
5219 | CORE_ADDR high = 0; | |
5220 | int ret = 0; | |
c906108c | 5221 | |
e142c38c | 5222 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 5223 | if (attr) |
af34e669 DJ |
5224 | { |
5225 | high = DW_ADDR (attr); | |
e142c38c | 5226 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
5227 | if (attr) |
5228 | low = DW_ADDR (attr); | |
5229 | else | |
5230 | /* Found high w/o low attribute. */ | |
5231 | return 0; | |
5232 | ||
5233 | /* Found consecutive range of addresses. */ | |
5234 | ret = 1; | |
5235 | } | |
c906108c | 5236 | else |
af34e669 | 5237 | { |
e142c38c | 5238 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
5239 | if (attr != NULL) |
5240 | { | |
af34e669 | 5241 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 5242 | .debug_ranges section. */ |
d85a05f0 | 5243 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 5244 | return 0; |
43039443 | 5245 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
5246 | ret = -1; |
5247 | } | |
5248 | } | |
c906108c SS |
5249 | |
5250 | if (high < low) | |
5251 | return 0; | |
5252 | ||
5253 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
5254 | eliminate duplicate copies of functions and vtables and such. | |
5255 | The linker will arbitrarily choose one and discard the others. | |
5256 | The AT_*_pc values for such functions refer to local labels in | |
5257 | these sections. If the section from that file was discarded, the | |
5258 | labels are not in the output, so the relocs get a value of 0. | |
5259 | If this is a discarded function, mark the pc bounds as invalid, | |
5260 | so that GDB will ignore it. */ | |
72dca2f5 | 5261 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
5262 | return 0; |
5263 | ||
5264 | *lowpc = low; | |
5265 | *highpc = high; | |
af34e669 | 5266 | return ret; |
c906108c SS |
5267 | } |
5268 | ||
b084d499 JB |
5269 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
5270 | its low and high PC addresses. Do nothing if these addresses could not | |
5271 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
5272 | and HIGHPC to the high address if greater than HIGHPC. */ | |
5273 | ||
5274 | static void | |
5275 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
5276 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5277 | struct dwarf2_cu *cu) | |
5278 | { | |
5279 | CORE_ADDR low, high; | |
5280 | struct die_info *child = die->child; | |
5281 | ||
d85a05f0 | 5282 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
5283 | { |
5284 | *lowpc = min (*lowpc, low); | |
5285 | *highpc = max (*highpc, high); | |
5286 | } | |
5287 | ||
5288 | /* If the language does not allow nested subprograms (either inside | |
5289 | subprograms or lexical blocks), we're done. */ | |
5290 | if (cu->language != language_ada) | |
5291 | return; | |
6e70227d | 5292 | |
b084d499 JB |
5293 | /* Check all the children of the given DIE. If it contains nested |
5294 | subprograms, then check their pc bounds. Likewise, we need to | |
5295 | check lexical blocks as well, as they may also contain subprogram | |
5296 | definitions. */ | |
5297 | while (child && child->tag) | |
5298 | { | |
5299 | if (child->tag == DW_TAG_subprogram | |
5300 | || child->tag == DW_TAG_lexical_block) | |
5301 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
5302 | child = sibling_die (child); | |
5303 | } | |
5304 | } | |
5305 | ||
fae299cd DC |
5306 | /* Get the low and high pc's represented by the scope DIE, and store |
5307 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
5308 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
5309 | ||
5310 | static void | |
5311 | get_scope_pc_bounds (struct die_info *die, | |
5312 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5313 | struct dwarf2_cu *cu) | |
5314 | { | |
5315 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
5316 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
5317 | CORE_ADDR current_low, current_high; | |
5318 | ||
d85a05f0 | 5319 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
5320 | { |
5321 | best_low = current_low; | |
5322 | best_high = current_high; | |
5323 | } | |
5324 | else | |
5325 | { | |
5326 | struct die_info *child = die->child; | |
5327 | ||
5328 | while (child && child->tag) | |
5329 | { | |
5330 | switch (child->tag) { | |
5331 | case DW_TAG_subprogram: | |
b084d499 | 5332 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
5333 | break; |
5334 | case DW_TAG_namespace: | |
f55ee35c | 5335 | case DW_TAG_module: |
fae299cd DC |
5336 | /* FIXME: carlton/2004-01-16: Should we do this for |
5337 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
5338 | that current GCC's always emit the DIEs corresponding | |
5339 | to definitions of methods of classes as children of a | |
5340 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
5341 | the DIEs giving the declarations, which could be | |
5342 | anywhere). But I don't see any reason why the | |
5343 | standards says that they have to be there. */ | |
5344 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
5345 | ||
5346 | if (current_low != ((CORE_ADDR) -1)) | |
5347 | { | |
5348 | best_low = min (best_low, current_low); | |
5349 | best_high = max (best_high, current_high); | |
5350 | } | |
5351 | break; | |
5352 | default: | |
5353 | /* Ignore. */ | |
5354 | break; | |
5355 | } | |
5356 | ||
5357 | child = sibling_die (child); | |
5358 | } | |
5359 | } | |
5360 | ||
5361 | *lowpc = best_low; | |
5362 | *highpc = best_high; | |
5363 | } | |
5364 | ||
801e3a5b JB |
5365 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
5366 | in DIE. */ | |
5367 | static void | |
5368 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
5369 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
5370 | { | |
5371 | struct attribute *attr; | |
5372 | ||
5373 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
5374 | if (attr) | |
5375 | { | |
5376 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 5377 | |
801e3a5b JB |
5378 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
5379 | if (attr) | |
5380 | { | |
5381 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 5382 | |
801e3a5b JB |
5383 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
5384 | } | |
5385 | } | |
5386 | ||
5387 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
5388 | if (attr) | |
5389 | { | |
5390 | bfd *obfd = cu->objfile->obfd; | |
5391 | ||
5392 | /* The value of the DW_AT_ranges attribute is the offset of the | |
5393 | address range list in the .debug_ranges section. */ | |
5394 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 5395 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
5396 | |
5397 | /* For some target architectures, but not others, the | |
5398 | read_address function sign-extends the addresses it returns. | |
5399 | To recognize base address selection entries, we need a | |
5400 | mask. */ | |
5401 | unsigned int addr_size = cu->header.addr_size; | |
5402 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5403 | ||
5404 | /* The base address, to which the next pair is relative. Note | |
5405 | that this 'base' is a DWARF concept: most entries in a range | |
5406 | list are relative, to reduce the number of relocs against the | |
5407 | debugging information. This is separate from this function's | |
5408 | 'baseaddr' argument, which GDB uses to relocate debugging | |
5409 | information from a shared library based on the address at | |
5410 | which the library was loaded. */ | |
d00adf39 DE |
5411 | CORE_ADDR base = cu->base_address; |
5412 | int base_known = cu->base_known; | |
801e3a5b | 5413 | |
be391dca | 5414 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 5415 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
5416 | { |
5417 | complaint (&symfile_complaints, | |
5418 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
5419 | offset); | |
5420 | return; | |
5421 | } | |
5422 | ||
5423 | for (;;) | |
5424 | { | |
5425 | unsigned int bytes_read; | |
5426 | CORE_ADDR start, end; | |
5427 | ||
5428 | start = read_address (obfd, buffer, cu, &bytes_read); | |
5429 | buffer += bytes_read; | |
5430 | end = read_address (obfd, buffer, cu, &bytes_read); | |
5431 | buffer += bytes_read; | |
5432 | ||
5433 | /* Did we find the end of the range list? */ | |
5434 | if (start == 0 && end == 0) | |
5435 | break; | |
5436 | ||
5437 | /* Did we find a base address selection entry? */ | |
5438 | else if ((start & base_select_mask) == base_select_mask) | |
5439 | { | |
5440 | base = end; | |
5441 | base_known = 1; | |
5442 | } | |
5443 | ||
5444 | /* We found an ordinary address range. */ | |
5445 | else | |
5446 | { | |
5447 | if (!base_known) | |
5448 | { | |
5449 | complaint (&symfile_complaints, | |
5450 | _("Invalid .debug_ranges data (no base address)")); | |
5451 | return; | |
5452 | } | |
5453 | ||
6e70227d DE |
5454 | record_block_range (block, |
5455 | baseaddr + base + start, | |
801e3a5b JB |
5456 | baseaddr + base + end - 1); |
5457 | } | |
5458 | } | |
5459 | } | |
5460 | } | |
5461 | ||
c906108c SS |
5462 | /* Add an aggregate field to the field list. */ |
5463 | ||
5464 | static void | |
107d2387 | 5465 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 5466 | struct dwarf2_cu *cu) |
6e70227d | 5467 | { |
e7c27a73 | 5468 | struct objfile *objfile = cu->objfile; |
5e2b427d | 5469 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5470 | struct nextfield *new_field; |
5471 | struct attribute *attr; | |
5472 | struct field *fp; | |
5473 | char *fieldname = ""; | |
5474 | ||
5475 | /* Allocate a new field list entry and link it in. */ | |
5476 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 5477 | make_cleanup (xfree, new_field); |
c906108c | 5478 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
5479 | |
5480 | if (die->tag == DW_TAG_inheritance) | |
5481 | { | |
5482 | new_field->next = fip->baseclasses; | |
5483 | fip->baseclasses = new_field; | |
5484 | } | |
5485 | else | |
5486 | { | |
5487 | new_field->next = fip->fields; | |
5488 | fip->fields = new_field; | |
5489 | } | |
c906108c SS |
5490 | fip->nfields++; |
5491 | ||
5492 | /* Handle accessibility and virtuality of field. | |
5493 | The default accessibility for members is public, the default | |
5494 | accessibility for inheritance is private. */ | |
5495 | if (die->tag != DW_TAG_inheritance) | |
5496 | new_field->accessibility = DW_ACCESS_public; | |
5497 | else | |
5498 | new_field->accessibility = DW_ACCESS_private; | |
5499 | new_field->virtuality = DW_VIRTUALITY_none; | |
5500 | ||
e142c38c | 5501 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
5502 | if (attr) |
5503 | new_field->accessibility = DW_UNSND (attr); | |
5504 | if (new_field->accessibility != DW_ACCESS_public) | |
5505 | fip->non_public_fields = 1; | |
e142c38c | 5506 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
5507 | if (attr) |
5508 | new_field->virtuality = DW_UNSND (attr); | |
5509 | ||
5510 | fp = &new_field->field; | |
a9a9bd0f | 5511 | |
e142c38c | 5512 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 5513 | { |
a9a9bd0f | 5514 | /* Data member other than a C++ static data member. */ |
6e70227d | 5515 | |
c906108c | 5516 | /* Get type of field. */ |
e7c27a73 | 5517 | fp->type = die_type (die, cu); |
c906108c | 5518 | |
d6a843b5 | 5519 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 5520 | |
c906108c | 5521 | /* Get bit size of field (zero if none). */ |
e142c38c | 5522 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
5523 | if (attr) |
5524 | { | |
5525 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
5526 | } | |
5527 | else | |
5528 | { | |
5529 | FIELD_BITSIZE (*fp) = 0; | |
5530 | } | |
5531 | ||
5532 | /* Get bit offset of field. */ | |
e142c38c | 5533 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
5534 | if (attr) |
5535 | { | |
d4b96c9a | 5536 | int byte_offset = 0; |
c6a0999f | 5537 | |
3690dd37 | 5538 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 5539 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 5540 | else if (attr_form_is_constant (attr)) |
c6a0999f | 5541 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 5542 | else if (attr_form_is_block (attr)) |
c6a0999f | 5543 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
5544 | else |
5545 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 5546 | |
d6a843b5 | 5547 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 5548 | } |
e142c38c | 5549 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
5550 | if (attr) |
5551 | { | |
5e2b427d | 5552 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
5553 | { |
5554 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
5555 | additional bit offset from the MSB of the containing |
5556 | anonymous object to the MSB of the field. We don't | |
5557 | have to do anything special since we don't need to | |
5558 | know the size of the anonymous object. */ | |
c906108c SS |
5559 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
5560 | } | |
5561 | else | |
5562 | { | |
5563 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
5564 | MSB of the anonymous object, subtract off the number of |
5565 | bits from the MSB of the field to the MSB of the | |
5566 | object, and then subtract off the number of bits of | |
5567 | the field itself. The result is the bit offset of | |
5568 | the LSB of the field. */ | |
c906108c SS |
5569 | int anonymous_size; |
5570 | int bit_offset = DW_UNSND (attr); | |
5571 | ||
e142c38c | 5572 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5573 | if (attr) |
5574 | { | |
5575 | /* The size of the anonymous object containing | |
5576 | the bit field is explicit, so use the | |
5577 | indicated size (in bytes). */ | |
5578 | anonymous_size = DW_UNSND (attr); | |
5579 | } | |
5580 | else | |
5581 | { | |
5582 | /* The size of the anonymous object containing | |
5583 | the bit field must be inferred from the type | |
5584 | attribute of the data member containing the | |
5585 | bit field. */ | |
5586 | anonymous_size = TYPE_LENGTH (fp->type); | |
5587 | } | |
5588 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
5589 | - bit_offset - FIELD_BITSIZE (*fp); | |
5590 | } | |
5591 | } | |
5592 | ||
5593 | /* Get name of field. */ | |
39cbfefa DJ |
5594 | fieldname = dwarf2_name (die, cu); |
5595 | if (fieldname == NULL) | |
5596 | fieldname = ""; | |
d8151005 DJ |
5597 | |
5598 | /* The name is already allocated along with this objfile, so we don't | |
5599 | need to duplicate it for the type. */ | |
5600 | fp->name = fieldname; | |
c906108c SS |
5601 | |
5602 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 5603 | pointer or virtual base class pointer) to private. */ |
e142c38c | 5604 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 5605 | { |
d48cc9dd | 5606 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
5607 | new_field->accessibility = DW_ACCESS_private; |
5608 | fip->non_public_fields = 1; | |
5609 | } | |
5610 | } | |
a9a9bd0f | 5611 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 5612 | { |
a9a9bd0f DC |
5613 | /* C++ static member. */ |
5614 | ||
5615 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
5616 | is a declaration, but all versions of G++ as of this writing | |
5617 | (so through at least 3.2.1) incorrectly generate | |
5618 | DW_TAG_variable tags. */ | |
6e70227d | 5619 | |
c906108c | 5620 | char *physname; |
c906108c | 5621 | |
a9a9bd0f | 5622 | /* Get name of field. */ |
39cbfefa DJ |
5623 | fieldname = dwarf2_name (die, cu); |
5624 | if (fieldname == NULL) | |
c906108c SS |
5625 | return; |
5626 | ||
254e6b9e | 5627 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
5628 | if (attr |
5629 | /* Only create a symbol if this is an external value. | |
5630 | new_symbol checks this and puts the value in the global symbol | |
5631 | table, which we want. If it is not external, new_symbol | |
5632 | will try to put the value in cu->list_in_scope which is wrong. */ | |
5633 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
5634 | { |
5635 | /* A static const member, not much different than an enum as far as | |
5636 | we're concerned, except that we can support more types. */ | |
5637 | new_symbol (die, NULL, cu); | |
5638 | } | |
5639 | ||
2df3850c | 5640 | /* Get physical name. */ |
94af9270 | 5641 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 5642 | |
d8151005 DJ |
5643 | /* The name is already allocated along with this objfile, so we don't |
5644 | need to duplicate it for the type. */ | |
5645 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 5646 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 5647 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
5648 | } |
5649 | else if (die->tag == DW_TAG_inheritance) | |
5650 | { | |
5651 | /* C++ base class field. */ | |
e142c38c | 5652 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 5653 | if (attr) |
d4b96c9a JK |
5654 | { |
5655 | int byte_offset = 0; | |
5656 | ||
5657 | if (attr_form_is_section_offset (attr)) | |
5658 | dwarf2_complex_location_expr_complaint (); | |
5659 | else if (attr_form_is_constant (attr)) | |
5660 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5661 | else if (attr_form_is_block (attr)) | |
5662 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5663 | else | |
5664 | dwarf2_complex_location_expr_complaint (); | |
5665 | ||
5666 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
5667 | } | |
c906108c | 5668 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 5669 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
5670 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
5671 | fip->nbaseclasses++; | |
5672 | } | |
5673 | } | |
5674 | ||
98751a41 JK |
5675 | /* Add a typedef defined in the scope of the FIP's class. */ |
5676 | ||
5677 | static void | |
5678 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
5679 | struct dwarf2_cu *cu) | |
6e70227d | 5680 | { |
98751a41 JK |
5681 | struct objfile *objfile = cu->objfile; |
5682 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
5683 | struct typedef_field_list *new_field; | |
5684 | struct attribute *attr; | |
5685 | struct typedef_field *fp; | |
5686 | char *fieldname = ""; | |
5687 | ||
5688 | /* Allocate a new field list entry and link it in. */ | |
5689 | new_field = xzalloc (sizeof (*new_field)); | |
5690 | make_cleanup (xfree, new_field); | |
5691 | ||
5692 | gdb_assert (die->tag == DW_TAG_typedef); | |
5693 | ||
5694 | fp = &new_field->field; | |
5695 | ||
5696 | /* Get name of field. */ | |
5697 | fp->name = dwarf2_name (die, cu); | |
5698 | if (fp->name == NULL) | |
5699 | return; | |
5700 | ||
5701 | fp->type = read_type_die (die, cu); | |
5702 | ||
5703 | new_field->next = fip->typedef_field_list; | |
5704 | fip->typedef_field_list = new_field; | |
5705 | fip->typedef_field_list_count++; | |
5706 | } | |
5707 | ||
c906108c SS |
5708 | /* Create the vector of fields, and attach it to the type. */ |
5709 | ||
5710 | static void | |
fba45db2 | 5711 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 5712 | struct dwarf2_cu *cu) |
c906108c SS |
5713 | { |
5714 | int nfields = fip->nfields; | |
5715 | ||
5716 | /* Record the field count, allocate space for the array of fields, | |
5717 | and create blank accessibility bitfields if necessary. */ | |
5718 | TYPE_NFIELDS (type) = nfields; | |
5719 | TYPE_FIELDS (type) = (struct field *) | |
5720 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
5721 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
5722 | ||
b4ba55a1 | 5723 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
5724 | { |
5725 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
5726 | ||
5727 | TYPE_FIELD_PRIVATE_BITS (type) = | |
5728 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5729 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
5730 | ||
5731 | TYPE_FIELD_PROTECTED_BITS (type) = | |
5732 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5733 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
5734 | ||
5735 | TYPE_FIELD_IGNORE_BITS (type) = | |
5736 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5737 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
5738 | } | |
5739 | ||
5740 | /* If the type has baseclasses, allocate and clear a bit vector for | |
5741 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 5742 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
5743 | { |
5744 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 5745 | unsigned char *pointer; |
c906108c SS |
5746 | |
5747 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
5748 | pointer = TYPE_ALLOC (type, num_bytes); |
5749 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
5750 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
5751 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
5752 | } | |
5753 | ||
5754 | /* Copy the saved-up fields into the field vector. Start from the head | |
5755 | of the list, adding to the tail of the field array, so that they end | |
5756 | up in the same order in the array in which they were added to the list. */ | |
5757 | while (nfields-- > 0) | |
5758 | { | |
7d0ccb61 DJ |
5759 | struct nextfield *fieldp; |
5760 | ||
5761 | if (fip->fields) | |
5762 | { | |
5763 | fieldp = fip->fields; | |
5764 | fip->fields = fieldp->next; | |
5765 | } | |
5766 | else | |
5767 | { | |
5768 | fieldp = fip->baseclasses; | |
5769 | fip->baseclasses = fieldp->next; | |
5770 | } | |
5771 | ||
5772 | TYPE_FIELD (type, nfields) = fieldp->field; | |
5773 | switch (fieldp->accessibility) | |
c906108c | 5774 | { |
c5aa993b | 5775 | case DW_ACCESS_private: |
b4ba55a1 JB |
5776 | if (cu->language != language_ada) |
5777 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 5778 | break; |
c906108c | 5779 | |
c5aa993b | 5780 | case DW_ACCESS_protected: |
b4ba55a1 JB |
5781 | if (cu->language != language_ada) |
5782 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 5783 | break; |
c906108c | 5784 | |
c5aa993b JM |
5785 | case DW_ACCESS_public: |
5786 | break; | |
c906108c | 5787 | |
c5aa993b JM |
5788 | default: |
5789 | /* Unknown accessibility. Complain and treat it as public. */ | |
5790 | { | |
e2e0b3e5 | 5791 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 5792 | fieldp->accessibility); |
c5aa993b JM |
5793 | } |
5794 | break; | |
c906108c SS |
5795 | } |
5796 | if (nfields < fip->nbaseclasses) | |
5797 | { | |
7d0ccb61 | 5798 | switch (fieldp->virtuality) |
c906108c | 5799 | { |
c5aa993b JM |
5800 | case DW_VIRTUALITY_virtual: |
5801 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
5802 | if (cu->language == language_ada) |
5803 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
5804 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
5805 | break; | |
c906108c SS |
5806 | } |
5807 | } | |
c906108c SS |
5808 | } |
5809 | } | |
5810 | ||
c906108c SS |
5811 | /* Add a member function to the proper fieldlist. */ |
5812 | ||
5813 | static void | |
107d2387 | 5814 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 5815 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 5816 | { |
e7c27a73 | 5817 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5818 | struct attribute *attr; |
5819 | struct fnfieldlist *flp; | |
5820 | int i; | |
5821 | struct fn_field *fnp; | |
5822 | char *fieldname; | |
5823 | char *physname; | |
5824 | struct nextfnfield *new_fnfield; | |
f792889a | 5825 | struct type *this_type; |
c906108c | 5826 | |
b4ba55a1 JB |
5827 | if (cu->language == language_ada) |
5828 | error ("unexpected member function in Ada type"); | |
5829 | ||
2df3850c | 5830 | /* Get name of member function. */ |
39cbfefa DJ |
5831 | fieldname = dwarf2_name (die, cu); |
5832 | if (fieldname == NULL) | |
2df3850c | 5833 | return; |
c906108c | 5834 | |
2df3850c | 5835 | /* Get the mangled name. */ |
94af9270 | 5836 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c SS |
5837 | |
5838 | /* Look up member function name in fieldlist. */ | |
5839 | for (i = 0; i < fip->nfnfields; i++) | |
5840 | { | |
27bfe10e | 5841 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
5842 | break; |
5843 | } | |
5844 | ||
5845 | /* Create new list element if necessary. */ | |
5846 | if (i < fip->nfnfields) | |
5847 | flp = &fip->fnfieldlists[i]; | |
5848 | else | |
5849 | { | |
5850 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5851 | { | |
5852 | fip->fnfieldlists = (struct fnfieldlist *) | |
5853 | xrealloc (fip->fnfieldlists, | |
5854 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5855 | * sizeof (struct fnfieldlist)); |
c906108c | 5856 | if (fip->nfnfields == 0) |
c13c43fd | 5857 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
5858 | } |
5859 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
5860 | flp->name = fieldname; | |
5861 | flp->length = 0; | |
5862 | flp->head = NULL; | |
5863 | fip->nfnfields++; | |
5864 | } | |
5865 | ||
5866 | /* Create a new member function field and chain it to the field list | |
5867 | entry. */ | |
5868 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 5869 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
5870 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
5871 | new_fnfield->next = flp->head; | |
5872 | flp->head = new_fnfield; | |
5873 | flp->length++; | |
5874 | ||
5875 | /* Fill in the member function field info. */ | |
5876 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
5877 | /* The name is already allocated along with this objfile, so we don't |
5878 | need to duplicate it for the type. */ | |
5879 | fnp->physname = physname ? physname : ""; | |
c906108c | 5880 | fnp->type = alloc_type (objfile); |
f792889a DJ |
5881 | this_type = read_type_die (die, cu); |
5882 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 5883 | { |
f792889a | 5884 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 5885 | |
f792889a | 5886 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
5887 | of the method itself (TYPE_CODE_METHOD). */ |
5888 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
5889 | TYPE_TARGET_TYPE (this_type), |
5890 | TYPE_FIELDS (this_type), | |
5891 | TYPE_NFIELDS (this_type), | |
5892 | TYPE_VARARGS (this_type)); | |
c906108c SS |
5893 | |
5894 | /* Handle static member functions. | |
c5aa993b JM |
5895 | Dwarf2 has no clean way to discern C++ static and non-static |
5896 | member functions. G++ helps GDB by marking the first | |
5897 | parameter for non-static member functions (which is the | |
5898 | this pointer) as artificial. We obtain this information | |
5899 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 5900 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
5901 | fnp->voffset = VOFFSET_STATIC; |
5902 | } | |
5903 | else | |
e2e0b3e5 | 5904 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 5905 | physname); |
c906108c SS |
5906 | |
5907 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 5908 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 5909 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
5910 | |
5911 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
5912 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
5913 | ||
5914 | /* Get accessibility. */ | |
e142c38c | 5915 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
5916 | if (attr) |
5917 | { | |
5918 | switch (DW_UNSND (attr)) | |
5919 | { | |
c5aa993b JM |
5920 | case DW_ACCESS_private: |
5921 | fnp->is_private = 1; | |
5922 | break; | |
5923 | case DW_ACCESS_protected: | |
5924 | fnp->is_protected = 1; | |
5925 | break; | |
c906108c SS |
5926 | } |
5927 | } | |
5928 | ||
b02dede2 | 5929 | /* Check for artificial methods. */ |
e142c38c | 5930 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
5931 | if (attr && DW_UNSND (attr) != 0) |
5932 | fnp->is_artificial = 1; | |
5933 | ||
0d564a31 | 5934 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
5935 | function. For older versions of GCC, this is an offset in the |
5936 | appropriate virtual table, as specified by DW_AT_containing_type. | |
5937 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
5938 | to the object address. */ |
5939 | ||
e142c38c | 5940 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 5941 | if (attr) |
8e19ed76 | 5942 | { |
aec5aa8b | 5943 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 5944 | { |
aec5aa8b TT |
5945 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
5946 | { | |
5947 | /* Old-style GCC. */ | |
5948 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
5949 | } | |
5950 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
5951 | || (DW_BLOCK (attr)->size > 1 | |
5952 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
5953 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
5954 | { | |
5955 | struct dwarf_block blk; | |
5956 | int offset; | |
5957 | ||
5958 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
5959 | ? 1 : 2); | |
5960 | blk.size = DW_BLOCK (attr)->size - offset; | |
5961 | blk.data = DW_BLOCK (attr)->data + offset; | |
5962 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
5963 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
5964 | dwarf2_complex_location_expr_complaint (); | |
5965 | else | |
5966 | fnp->voffset /= cu->header.addr_size; | |
5967 | fnp->voffset += 2; | |
5968 | } | |
5969 | else | |
5970 | dwarf2_complex_location_expr_complaint (); | |
5971 | ||
5972 | if (!fnp->fcontext) | |
5973 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
5974 | } | |
3690dd37 | 5975 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5976 | { |
4d3c2250 | 5977 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5978 | } |
5979 | else | |
5980 | { | |
4d3c2250 KB |
5981 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
5982 | fieldname); | |
8e19ed76 | 5983 | } |
0d564a31 | 5984 | } |
d48cc9dd DJ |
5985 | else |
5986 | { | |
5987 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
5988 | if (attr && DW_UNSND (attr)) | |
5989 | { | |
5990 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
5991 | complaint (&symfile_complaints, | |
5992 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
5993 | fieldname, die->offset); | |
9655fd1a | 5994 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
5995 | TYPE_CPLUS_DYNAMIC (type) = 1; |
5996 | } | |
5997 | } | |
c906108c SS |
5998 | } |
5999 | ||
6000 | /* Create the vector of member function fields, and attach it to the type. */ | |
6001 | ||
6002 | static void | |
fba45db2 | 6003 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6004 | struct dwarf2_cu *cu) |
c906108c SS |
6005 | { |
6006 | struct fnfieldlist *flp; | |
6007 | int total_length = 0; | |
6008 | int i; | |
6009 | ||
b4ba55a1 JB |
6010 | if (cu->language == language_ada) |
6011 | error ("unexpected member functions in Ada type"); | |
6012 | ||
c906108c SS |
6013 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6014 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6015 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6016 | ||
6017 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6018 | { | |
6019 | struct nextfnfield *nfp = flp->head; | |
6020 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6021 | int k; | |
6022 | ||
6023 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6024 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6025 | fn_flp->fn_fields = (struct fn_field *) | |
6026 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6027 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6028 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6029 | |
6030 | total_length += flp->length; | |
6031 | } | |
6032 | ||
6033 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6034 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6035 | } | |
6036 | ||
1168df01 JB |
6037 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6038 | language, zero otherwise. */ | |
6039 | static int | |
6040 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6041 | { | |
6042 | static const char vptr[] = "_vptr"; | |
987504bb | 6043 | static const char vtable[] = "vtable"; |
1168df01 | 6044 | |
987504bb JJ |
6045 | /* Look for the C++ and Java forms of the vtable. */ |
6046 | if ((cu->language == language_java | |
6047 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6048 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
6049 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
6050 | return 1; |
6051 | ||
6052 | return 0; | |
6053 | } | |
6054 | ||
c0dd20ea | 6055 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
6056 | functions, with the ABI-specified layout. If TYPE describes |
6057 | such a structure, smash it into a member function type. | |
61049d3b DJ |
6058 | |
6059 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
6060 | This is GCC PR debug/28767. */ | |
c0dd20ea | 6061 | |
0b92b5bb TT |
6062 | static void |
6063 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 6064 | { |
0b92b5bb | 6065 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
6066 | |
6067 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
6068 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
6069 | return; | |
c0dd20ea DJ |
6070 | |
6071 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
6072 | if (TYPE_FIELD_NAME (type, 0) == NULL |
6073 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
6074 | || TYPE_FIELD_NAME (type, 1) == NULL | |
6075 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
6076 | return; | |
c0dd20ea DJ |
6077 | |
6078 | /* Find the type of the method. */ | |
0b92b5bb | 6079 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
6080 | if (pfn_type == NULL |
6081 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
6082 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 6083 | return; |
c0dd20ea DJ |
6084 | |
6085 | /* Look for the "this" argument. */ | |
6086 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
6087 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 6088 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 6089 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 6090 | return; |
c0dd20ea DJ |
6091 | |
6092 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
6093 | new_type = alloc_type (objfile); |
6094 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
6095 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
6096 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 6097 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 6098 | } |
1168df01 | 6099 | |
c906108c SS |
6100 | /* Called when we find the DIE that starts a structure or union scope |
6101 | (definition) to process all dies that define the members of the | |
6102 | structure or union. | |
6103 | ||
6104 | NOTE: we need to call struct_type regardless of whether or not the | |
6105 | DIE has an at_name attribute, since it might be an anonymous | |
6106 | structure or union. This gets the type entered into our set of | |
6107 | user defined types. | |
6108 | ||
6109 | However, if the structure is incomplete (an opaque struct/union) | |
6110 | then suppress creating a symbol table entry for it since gdb only | |
6111 | wants to find the one with the complete definition. Note that if | |
6112 | it is complete, we just call new_symbol, which does it's own | |
6113 | checking about whether the struct/union is anonymous or not (and | |
6114 | suppresses creating a symbol table entry itself). */ | |
6115 | ||
f792889a | 6116 | static struct type * |
134d01f1 | 6117 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6118 | { |
e7c27a73 | 6119 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6120 | struct type *type; |
6121 | struct attribute *attr; | |
39cbfefa | 6122 | char *name; |
d3f41bb1 | 6123 | struct cleanup *back_to; |
c906108c | 6124 | |
348e048f DE |
6125 | /* If the definition of this type lives in .debug_types, read that type. |
6126 | Don't follow DW_AT_specification though, that will take us back up | |
6127 | the chain and we want to go down. */ | |
6128 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6129 | if (attr) | |
6130 | { | |
6131 | struct dwarf2_cu *type_cu = cu; | |
6132 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6133 | |
348e048f DE |
6134 | /* We could just recurse on read_structure_type, but we need to call |
6135 | get_die_type to ensure only one type for this DIE is created. | |
6136 | This is important, for example, because for c++ classes we need | |
6137 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
6138 | type = read_type_die (type_die, type_cu); | |
6139 | return set_die_type (die, type, cu); | |
6140 | } | |
6141 | ||
d3f41bb1 TT |
6142 | back_to = make_cleanup (null_cleanup, 0); |
6143 | ||
c0dd20ea | 6144 | type = alloc_type (objfile); |
c906108c | 6145 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 6146 | |
39cbfefa DJ |
6147 | name = dwarf2_name (die, cu); |
6148 | if (name != NULL) | |
c906108c | 6149 | { |
987504bb JJ |
6150 | if (cu->language == language_cplus |
6151 | || cu->language == language_java) | |
63d06c5c | 6152 | { |
94af9270 KS |
6153 | TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu); |
6154 | if (die->tag == DW_TAG_structure_type | |
6155 | || die->tag == DW_TAG_class_type) | |
6156 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
6157 | } |
6158 | else | |
6159 | { | |
d8151005 DJ |
6160 | /* The name is already allocated along with this objfile, so |
6161 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
6162 | TYPE_TAG_NAME (type) = (char *) name; |
6163 | if (die->tag == DW_TAG_class_type) | |
6164 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 6165 | } |
c906108c SS |
6166 | } |
6167 | ||
6168 | if (die->tag == DW_TAG_structure_type) | |
6169 | { | |
6170 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
6171 | } | |
6172 | else if (die->tag == DW_TAG_union_type) | |
6173 | { | |
6174 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
6175 | } | |
6176 | else | |
6177 | { | |
c906108c SS |
6178 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
6179 | } | |
6180 | ||
0cc2414c TT |
6181 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
6182 | TYPE_DECLARED_CLASS (type) = 1; | |
6183 | ||
e142c38c | 6184 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6185 | if (attr) |
6186 | { | |
6187 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6188 | } | |
6189 | else | |
6190 | { | |
6191 | TYPE_LENGTH (type) = 0; | |
6192 | } | |
6193 | ||
876cecd0 | 6194 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 6195 | if (die_is_declaration (die, cu)) |
876cecd0 | 6196 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
6197 | else if (attr == NULL && die->child == NULL |
6198 | && producer_is_realview (cu->producer)) | |
6199 | /* RealView does not output the required DW_AT_declaration | |
6200 | on incomplete types. */ | |
6201 | TYPE_STUB (type) = 1; | |
dc718098 | 6202 | |
c906108c SS |
6203 | /* We need to add the type field to the die immediately so we don't |
6204 | infinitely recurse when dealing with pointers to the structure | |
6205 | type within the structure itself. */ | |
1c379e20 | 6206 | set_die_type (die, type, cu); |
c906108c | 6207 | |
7e314c57 JK |
6208 | /* set_die_type should be already done. */ |
6209 | set_descriptive_type (type, die, cu); | |
6210 | ||
e142c38c | 6211 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
6212 | { |
6213 | struct field_info fi; | |
6214 | struct die_info *child_die; | |
c906108c SS |
6215 | |
6216 | memset (&fi, 0, sizeof (struct field_info)); | |
6217 | ||
639d11d3 | 6218 | child_die = die->child; |
c906108c SS |
6219 | |
6220 | while (child_die && child_die->tag) | |
6221 | { | |
a9a9bd0f DC |
6222 | if (child_die->tag == DW_TAG_member |
6223 | || child_die->tag == DW_TAG_variable) | |
c906108c | 6224 | { |
a9a9bd0f DC |
6225 | /* NOTE: carlton/2002-11-05: A C++ static data member |
6226 | should be a DW_TAG_member that is a declaration, but | |
6227 | all versions of G++ as of this writing (so through at | |
6228 | least 3.2.1) incorrectly generate DW_TAG_variable | |
6229 | tags for them instead. */ | |
e7c27a73 | 6230 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6231 | } |
8713b1b1 | 6232 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
6233 | { |
6234 | /* C++ member function. */ | |
e7c27a73 | 6235 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
6236 | } |
6237 | else if (child_die->tag == DW_TAG_inheritance) | |
6238 | { | |
6239 | /* C++ base class field. */ | |
e7c27a73 | 6240 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6241 | } |
98751a41 JK |
6242 | else if (child_die->tag == DW_TAG_typedef) |
6243 | dwarf2_add_typedef (&fi, child_die, cu); | |
c906108c SS |
6244 | child_die = sibling_die (child_die); |
6245 | } | |
6246 | ||
6247 | /* Attach fields and member functions to the type. */ | |
6248 | if (fi.nfields) | |
e7c27a73 | 6249 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
6250 | if (fi.nfnfields) |
6251 | { | |
e7c27a73 | 6252 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 6253 | |
c5aa993b | 6254 | /* Get the type which refers to the base class (possibly this |
c906108c | 6255 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
6256 | class from the DW_AT_containing_type attribute. This use of |
6257 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 6258 | |
e142c38c | 6259 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 6260 | { |
e7c27a73 | 6261 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
6262 | |
6263 | TYPE_VPTR_BASETYPE (type) = t; | |
6264 | if (type == t) | |
6265 | { | |
c906108c SS |
6266 | int i; |
6267 | ||
6268 | /* Our own class provides vtbl ptr. */ | |
6269 | for (i = TYPE_NFIELDS (t) - 1; | |
6270 | i >= TYPE_N_BASECLASSES (t); | |
6271 | --i) | |
6272 | { | |
6273 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
6274 | ||
1168df01 | 6275 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
6276 | { |
6277 | TYPE_VPTR_FIELDNO (type) = i; | |
6278 | break; | |
6279 | } | |
6280 | } | |
6281 | ||
6282 | /* Complain if virtual function table field not found. */ | |
6283 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 6284 | complaint (&symfile_complaints, |
e2e0b3e5 | 6285 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
6286 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
6287 | ""); | |
c906108c SS |
6288 | } |
6289 | else | |
6290 | { | |
6291 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
6292 | } | |
6293 | } | |
f6235d4c EZ |
6294 | else if (cu->producer |
6295 | && strncmp (cu->producer, | |
6296 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
6297 | { | |
6298 | /* The IBM XLC compiler does not provide direct indication | |
6299 | of the containing type, but the vtable pointer is | |
6300 | always named __vfp. */ | |
6301 | ||
6302 | int i; | |
6303 | ||
6304 | for (i = TYPE_NFIELDS (type) - 1; | |
6305 | i >= TYPE_N_BASECLASSES (type); | |
6306 | --i) | |
6307 | { | |
6308 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
6309 | { | |
6310 | TYPE_VPTR_FIELDNO (type) = i; | |
6311 | TYPE_VPTR_BASETYPE (type) = type; | |
6312 | break; | |
6313 | } | |
6314 | } | |
6315 | } | |
c906108c | 6316 | } |
98751a41 JK |
6317 | |
6318 | /* Copy fi.typedef_field_list linked list elements content into the | |
6319 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
6320 | if (fi.typedef_field_list) | |
6321 | { | |
6322 | int i = fi.typedef_field_list_count; | |
6323 | ||
a0d7a4ff | 6324 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
6325 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
6326 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
6327 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
6328 | ||
6329 | /* Reverse the list order to keep the debug info elements order. */ | |
6330 | while (--i >= 0) | |
6331 | { | |
6332 | struct typedef_field *dest, *src; | |
6e70227d | 6333 | |
98751a41 JK |
6334 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
6335 | src = &fi.typedef_field_list->field; | |
6336 | fi.typedef_field_list = fi.typedef_field_list->next; | |
6337 | *dest = *src; | |
6338 | } | |
6339 | } | |
c906108c | 6340 | } |
63d06c5c | 6341 | |
0b92b5bb TT |
6342 | quirk_gcc_member_function_pointer (type, cu->objfile); |
6343 | ||
0114d602 | 6344 | do_cleanups (back_to); |
f792889a | 6345 | return type; |
c906108c SS |
6346 | } |
6347 | ||
134d01f1 DJ |
6348 | static void |
6349 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6350 | { | |
90aeadfc | 6351 | struct die_info *child_die = die->child; |
f792889a | 6352 | struct type *this_type; |
c906108c | 6353 | |
f792889a DJ |
6354 | this_type = get_die_type (die, cu); |
6355 | if (this_type == NULL) | |
6356 | this_type = read_structure_type (die, cu); | |
c906108c | 6357 | |
90aeadfc DC |
6358 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
6359 | snapshots) has been known to create a die giving a declaration | |
6360 | for a class that has, as a child, a die giving a definition for a | |
6361 | nested class. So we have to process our children even if the | |
6362 | current die is a declaration. Normally, of course, a declaration | |
6363 | won't have any children at all. */ | |
134d01f1 | 6364 | |
90aeadfc DC |
6365 | while (child_die != NULL && child_die->tag) |
6366 | { | |
6367 | if (child_die->tag == DW_TAG_member | |
6368 | || child_die->tag == DW_TAG_variable | |
6369 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 6370 | { |
90aeadfc | 6371 | /* Do nothing. */ |
134d01f1 | 6372 | } |
90aeadfc DC |
6373 | else |
6374 | process_die (child_die, cu); | |
134d01f1 | 6375 | |
90aeadfc | 6376 | child_die = sibling_die (child_die); |
134d01f1 DJ |
6377 | } |
6378 | ||
fa4028e9 JB |
6379 | /* Do not consider external references. According to the DWARF standard, |
6380 | these DIEs are identified by the fact that they have no byte_size | |
6381 | attribute, and a declaration attribute. */ | |
6382 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
6383 | || !die_is_declaration (die, cu)) | |
f792889a | 6384 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
6385 | } |
6386 | ||
6387 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
6388 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 6389 | |
f792889a | 6390 | static struct type * |
134d01f1 | 6391 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6392 | { |
e7c27a73 | 6393 | struct objfile *objfile = cu->objfile; |
c906108c | 6394 | struct type *type; |
c906108c | 6395 | struct attribute *attr; |
0114d602 | 6396 | const char *name; |
134d01f1 | 6397 | |
348e048f DE |
6398 | /* If the definition of this type lives in .debug_types, read that type. |
6399 | Don't follow DW_AT_specification though, that will take us back up | |
6400 | the chain and we want to go down. */ | |
6401 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6402 | if (attr) | |
6403 | { | |
6404 | struct dwarf2_cu *type_cu = cu; | |
6405 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6406 | |
348e048f DE |
6407 | type = read_type_die (type_die, type_cu); |
6408 | return set_die_type (die, type, cu); | |
6409 | } | |
6410 | ||
c906108c SS |
6411 | type = alloc_type (objfile); |
6412 | ||
6413 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 6414 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 6415 | if (name != NULL) |
0114d602 | 6416 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 6417 | |
e142c38c | 6418 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6419 | if (attr) |
6420 | { | |
6421 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6422 | } | |
6423 | else | |
6424 | { | |
6425 | TYPE_LENGTH (type) = 0; | |
6426 | } | |
6427 | ||
137033e9 JB |
6428 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
6429 | declared as private in the package spec, and then defined only | |
6430 | inside the package body. Such types are known as Taft Amendment | |
6431 | Types. When another package uses such a type, an incomplete DIE | |
6432 | may be generated by the compiler. */ | |
02eb380e | 6433 | if (die_is_declaration (die, cu)) |
876cecd0 | 6434 | TYPE_STUB (type) = 1; |
02eb380e | 6435 | |
f792889a | 6436 | return set_die_type (die, type, cu); |
134d01f1 DJ |
6437 | } |
6438 | ||
6439 | /* Given a pointer to a die which begins an enumeration, process all | |
6440 | the dies that define the members of the enumeration, and create the | |
6441 | symbol for the enumeration type. | |
6442 | ||
6443 | NOTE: We reverse the order of the element list. */ | |
6444 | ||
6445 | static void | |
6446 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6447 | { | |
134d01f1 DJ |
6448 | struct die_info *child_die; |
6449 | struct field *fields; | |
134d01f1 DJ |
6450 | struct symbol *sym; |
6451 | int num_fields; | |
6452 | int unsigned_enum = 1; | |
39cbfefa | 6453 | char *name; |
f792889a | 6454 | struct type *this_type; |
134d01f1 | 6455 | |
c906108c SS |
6456 | num_fields = 0; |
6457 | fields = NULL; | |
f792889a DJ |
6458 | this_type = get_die_type (die, cu); |
6459 | if (this_type == NULL) | |
6460 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 6461 | if (die->child != NULL) |
c906108c | 6462 | { |
639d11d3 | 6463 | child_die = die->child; |
c906108c SS |
6464 | while (child_die && child_die->tag) |
6465 | { | |
6466 | if (child_die->tag != DW_TAG_enumerator) | |
6467 | { | |
e7c27a73 | 6468 | process_die (child_die, cu); |
c906108c SS |
6469 | } |
6470 | else | |
6471 | { | |
39cbfefa DJ |
6472 | name = dwarf2_name (child_die, cu); |
6473 | if (name) | |
c906108c | 6474 | { |
f792889a | 6475 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
6476 | if (SYMBOL_VALUE (sym) < 0) |
6477 | unsigned_enum = 0; | |
6478 | ||
6479 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6480 | { | |
6481 | fields = (struct field *) | |
6482 | xrealloc (fields, | |
6483 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6484 | * sizeof (struct field)); |
c906108c SS |
6485 | } |
6486 | ||
3567439c | 6487 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 6488 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 6489 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
6490 | FIELD_BITSIZE (fields[num_fields]) = 0; |
6491 | ||
6492 | num_fields++; | |
6493 | } | |
6494 | } | |
6495 | ||
6496 | child_die = sibling_die (child_die); | |
6497 | } | |
6498 | ||
6499 | if (num_fields) | |
6500 | { | |
f792889a DJ |
6501 | TYPE_NFIELDS (this_type) = num_fields; |
6502 | TYPE_FIELDS (this_type) = (struct field *) | |
6503 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
6504 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 6505 | sizeof (struct field) * num_fields); |
b8c9b27d | 6506 | xfree (fields); |
c906108c SS |
6507 | } |
6508 | if (unsigned_enum) | |
876cecd0 | 6509 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 6510 | } |
134d01f1 | 6511 | |
f792889a | 6512 | new_symbol (die, this_type, cu); |
c906108c SS |
6513 | } |
6514 | ||
6515 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
6516 | the DIE's type field. For now, this only handles one dimensional | |
6517 | arrays. */ | |
6518 | ||
f792889a | 6519 | static struct type * |
e7c27a73 | 6520 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6521 | { |
e7c27a73 | 6522 | struct objfile *objfile = cu->objfile; |
c906108c | 6523 | struct die_info *child_die; |
7e314c57 | 6524 | struct type *type; |
c906108c SS |
6525 | struct type *element_type, *range_type, *index_type; |
6526 | struct type **range_types = NULL; | |
6527 | struct attribute *attr; | |
6528 | int ndim = 0; | |
6529 | struct cleanup *back_to; | |
39cbfefa | 6530 | char *name; |
c906108c | 6531 | |
e7c27a73 | 6532 | element_type = die_type (die, cu); |
c906108c | 6533 | |
7e314c57 JK |
6534 | /* The die_type call above may have already set the type for this DIE. */ |
6535 | type = get_die_type (die, cu); | |
6536 | if (type) | |
6537 | return type; | |
6538 | ||
c906108c SS |
6539 | /* Irix 6.2 native cc creates array types without children for |
6540 | arrays with unspecified length. */ | |
639d11d3 | 6541 | if (die->child == NULL) |
c906108c | 6542 | { |
46bf5051 | 6543 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 6544 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
6545 | type = create_array_type (NULL, element_type, range_type); |
6546 | return set_die_type (die, type, cu); | |
c906108c SS |
6547 | } |
6548 | ||
6549 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 6550 | child_die = die->child; |
c906108c SS |
6551 | while (child_die && child_die->tag) |
6552 | { | |
6553 | if (child_die->tag == DW_TAG_subrange_type) | |
6554 | { | |
f792889a | 6555 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 6556 | |
f792889a | 6557 | if (child_type != NULL) |
a02abb62 JB |
6558 | { |
6559 | /* The range type was succesfully read. Save it for | |
6560 | the array type creation. */ | |
6561 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
6562 | { | |
6563 | range_types = (struct type **) | |
6564 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
6565 | * sizeof (struct type *)); | |
6566 | if (ndim == 0) | |
6567 | make_cleanup (free_current_contents, &range_types); | |
6568 | } | |
f792889a | 6569 | range_types[ndim++] = child_type; |
a02abb62 | 6570 | } |
c906108c SS |
6571 | } |
6572 | child_die = sibling_die (child_die); | |
6573 | } | |
6574 | ||
6575 | /* Dwarf2 dimensions are output from left to right, create the | |
6576 | necessary array types in backwards order. */ | |
7ca2d3a3 | 6577 | |
c906108c | 6578 | type = element_type; |
7ca2d3a3 DL |
6579 | |
6580 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
6581 | { | |
6582 | int i = 0; | |
9a619af0 | 6583 | |
7ca2d3a3 DL |
6584 | while (i < ndim) |
6585 | type = create_array_type (NULL, type, range_types[i++]); | |
6586 | } | |
6587 | else | |
6588 | { | |
6589 | while (ndim-- > 0) | |
6590 | type = create_array_type (NULL, type, range_types[ndim]); | |
6591 | } | |
c906108c | 6592 | |
f5f8a009 EZ |
6593 | /* Understand Dwarf2 support for vector types (like they occur on |
6594 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
6595 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
6596 | custom vendor extension. The main difference between a regular | |
6597 | array and the vector variant is that vectors are passed by value | |
6598 | to functions. */ | |
e142c38c | 6599 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 6600 | if (attr) |
ea37ba09 | 6601 | make_vector_type (type); |
f5f8a009 | 6602 | |
39cbfefa DJ |
6603 | name = dwarf2_name (die, cu); |
6604 | if (name) | |
6605 | TYPE_NAME (type) = name; | |
6e70227d | 6606 | |
7e314c57 JK |
6607 | /* Install the type in the die. */ |
6608 | set_die_type (die, type, cu); | |
6609 | ||
6610 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
6611 | set_descriptive_type (type, die, cu); |
6612 | ||
c906108c SS |
6613 | do_cleanups (back_to); |
6614 | ||
7e314c57 | 6615 | return type; |
c906108c SS |
6616 | } |
6617 | ||
7ca2d3a3 | 6618 | static enum dwarf_array_dim_ordering |
6e70227d | 6619 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
6620 | { |
6621 | struct attribute *attr; | |
6622 | ||
6623 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
6624 | ||
6625 | if (attr) return DW_SND (attr); | |
6626 | ||
6627 | /* | |
6628 | GNU F77 is a special case, as at 08/2004 array type info is the | |
6e70227d | 6629 | opposite order to the dwarf2 specification, but data is still |
7ca2d3a3 DL |
6630 | laid out as per normal fortran. |
6631 | ||
6e70227d | 6632 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7ca2d3a3 DL |
6633 | version checking. |
6634 | */ | |
6635 | ||
905e0470 PM |
6636 | if (cu->language == language_fortran |
6637 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
6638 | { |
6639 | return DW_ORD_row_major; | |
6640 | } | |
6641 | ||
6e70227d | 6642 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
6643 | { |
6644 | case array_column_major: | |
6645 | return DW_ORD_col_major; | |
6646 | case array_row_major: | |
6647 | default: | |
6648 | return DW_ORD_row_major; | |
6649 | }; | |
6650 | } | |
6651 | ||
72019c9c GM |
6652 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
6653 | the DIE's type field. */ | |
6654 | ||
f792889a | 6655 | static struct type * |
72019c9c GM |
6656 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
6657 | { | |
7e314c57 JK |
6658 | struct type *domain_type, *set_type; |
6659 | struct attribute *attr; | |
f792889a | 6660 | |
7e314c57 JK |
6661 | domain_type = die_type (die, cu); |
6662 | ||
6663 | /* The die_type call above may have already set the type for this DIE. */ | |
6664 | set_type = get_die_type (die, cu); | |
6665 | if (set_type) | |
6666 | return set_type; | |
6667 | ||
6668 | set_type = create_set_type (NULL, domain_type); | |
6669 | ||
6670 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
6671 | if (attr) |
6672 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 6673 | |
f792889a | 6674 | return set_die_type (die, set_type, cu); |
72019c9c | 6675 | } |
7ca2d3a3 | 6676 | |
c906108c SS |
6677 | /* First cut: install each common block member as a global variable. */ |
6678 | ||
6679 | static void | |
e7c27a73 | 6680 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6681 | { |
6682 | struct die_info *child_die; | |
6683 | struct attribute *attr; | |
6684 | struct symbol *sym; | |
6685 | CORE_ADDR base = (CORE_ADDR) 0; | |
6686 | ||
e142c38c | 6687 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6688 | if (attr) |
6689 | { | |
8e19ed76 PS |
6690 | /* Support the .debug_loc offsets */ |
6691 | if (attr_form_is_block (attr)) | |
6692 | { | |
e7c27a73 | 6693 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 6694 | } |
3690dd37 | 6695 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6696 | { |
4d3c2250 | 6697 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6698 | } |
6699 | else | |
6700 | { | |
4d3c2250 KB |
6701 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6702 | "common block member"); | |
8e19ed76 | 6703 | } |
c906108c | 6704 | } |
639d11d3 | 6705 | if (die->child != NULL) |
c906108c | 6706 | { |
639d11d3 | 6707 | child_die = die->child; |
c906108c SS |
6708 | while (child_die && child_die->tag) |
6709 | { | |
e7c27a73 | 6710 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 6711 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
6712 | if (attr) |
6713 | { | |
d4b96c9a JK |
6714 | CORE_ADDR byte_offset = 0; |
6715 | ||
6716 | if (attr_form_is_section_offset (attr)) | |
6717 | dwarf2_complex_location_expr_complaint (); | |
6718 | else if (attr_form_is_constant (attr)) | |
6719 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
6720 | else if (attr_form_is_block (attr)) | |
6721 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6722 | else | |
6723 | dwarf2_complex_location_expr_complaint (); | |
6724 | ||
6725 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
6726 | add_symbol_to_list (sym, &global_symbols); |
6727 | } | |
6728 | child_die = sibling_die (child_die); | |
6729 | } | |
6730 | } | |
6731 | } | |
6732 | ||
0114d602 | 6733 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 6734 | |
0114d602 DJ |
6735 | static struct type * |
6736 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 6737 | { |
e7c27a73 | 6738 | struct objfile *objfile = cu->objfile; |
0114d602 | 6739 | const char *previous_prefix, *name; |
9219021c | 6740 | int is_anonymous; |
0114d602 DJ |
6741 | struct type *type; |
6742 | ||
6743 | /* For extensions, reuse the type of the original namespace. */ | |
6744 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
6745 | { | |
6746 | struct die_info *ext_die; | |
6747 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 6748 | |
0114d602 DJ |
6749 | ext_die = dwarf2_extension (die, &ext_cu); |
6750 | type = read_type_die (ext_die, ext_cu); | |
6751 | return set_die_type (die, type, cu); | |
6752 | } | |
9219021c | 6753 | |
e142c38c | 6754 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
6755 | |
6756 | /* Now build the name of the current namespace. */ | |
6757 | ||
0114d602 DJ |
6758 | previous_prefix = determine_prefix (die, cu); |
6759 | if (previous_prefix[0] != '\0') | |
6760 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 6761 | previous_prefix, name, 0, cu); |
0114d602 DJ |
6762 | |
6763 | /* Create the type. */ | |
6764 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
6765 | objfile); | |
6766 | TYPE_NAME (type) = (char *) name; | |
6767 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
6768 | ||
60531b24 | 6769 | return set_die_type (die, type, cu); |
0114d602 DJ |
6770 | } |
6771 | ||
6772 | /* Read a C++ namespace. */ | |
6773 | ||
6774 | static void | |
6775 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
6776 | { | |
6777 | struct objfile *objfile = cu->objfile; | |
6778 | const char *name; | |
6779 | int is_anonymous; | |
9219021c | 6780 | |
5c4e30ca DC |
6781 | /* Add a symbol associated to this if we haven't seen the namespace |
6782 | before. Also, add a using directive if it's an anonymous | |
6783 | namespace. */ | |
9219021c | 6784 | |
f2f0e013 | 6785 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
6786 | { |
6787 | struct type *type; | |
6788 | ||
0114d602 | 6789 | type = read_type_die (die, cu); |
e7c27a73 | 6790 | new_symbol (die, type, cu); |
5c4e30ca | 6791 | |
0114d602 | 6792 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 6793 | if (is_anonymous) |
0114d602 DJ |
6794 | { |
6795 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 6796 | |
c0cc3a76 | 6797 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 6798 | NULL, &objfile->objfile_obstack); |
0114d602 | 6799 | } |
5c4e30ca | 6800 | } |
9219021c | 6801 | |
639d11d3 | 6802 | if (die->child != NULL) |
d9fa45fe | 6803 | { |
639d11d3 | 6804 | struct die_info *child_die = die->child; |
6e70227d | 6805 | |
d9fa45fe DC |
6806 | while (child_die && child_die->tag) |
6807 | { | |
e7c27a73 | 6808 | process_die (child_die, cu); |
d9fa45fe DC |
6809 | child_die = sibling_die (child_die); |
6810 | } | |
6811 | } | |
38d518c9 EZ |
6812 | } |
6813 | ||
f55ee35c JK |
6814 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
6815 | imported module. Still we need that type as local Fortran "use ... only" | |
6816 | declaration imports depend on the created type in determine_prefix. */ | |
6817 | ||
6818 | static struct type * | |
6819 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
6820 | { | |
6821 | struct objfile *objfile = cu->objfile; | |
6822 | char *module_name; | |
6823 | struct type *type; | |
6824 | ||
6825 | module_name = dwarf2_name (die, cu); | |
6826 | if (!module_name) | |
6827 | complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"), | |
6828 | die->offset); | |
6829 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
6830 | ||
6831 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
6832 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
6833 | ||
6834 | return set_die_type (die, type, cu); | |
6835 | } | |
6836 | ||
5d7cb8df JK |
6837 | /* Read a Fortran module. */ |
6838 | ||
6839 | static void | |
6840 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
6841 | { | |
6842 | struct die_info *child_die = die->child; | |
6843 | ||
5d7cb8df JK |
6844 | while (child_die && child_die->tag) |
6845 | { | |
6846 | process_die (child_die, cu); | |
6847 | child_die = sibling_die (child_die); | |
6848 | } | |
6849 | } | |
6850 | ||
38d518c9 EZ |
6851 | /* Return the name of the namespace represented by DIE. Set |
6852 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
6853 | namespace. */ | |
6854 | ||
6855 | static const char * | |
e142c38c | 6856 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
6857 | { |
6858 | struct die_info *current_die; | |
6859 | const char *name = NULL; | |
6860 | ||
6861 | /* Loop through the extensions until we find a name. */ | |
6862 | ||
6863 | for (current_die = die; | |
6864 | current_die != NULL; | |
f2f0e013 | 6865 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 6866 | { |
e142c38c | 6867 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
6868 | if (name != NULL) |
6869 | break; | |
6870 | } | |
6871 | ||
6872 | /* Is it an anonymous namespace? */ | |
6873 | ||
6874 | *is_anonymous = (name == NULL); | |
6875 | if (*is_anonymous) | |
6876 | name = "(anonymous namespace)"; | |
6877 | ||
6878 | return name; | |
d9fa45fe DC |
6879 | } |
6880 | ||
c906108c SS |
6881 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
6882 | the user defined type vector. */ | |
6883 | ||
f792889a | 6884 | static struct type * |
e7c27a73 | 6885 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6886 | { |
5e2b427d | 6887 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 6888 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 6889 | struct type *type; |
8b2dbe47 KB |
6890 | struct attribute *attr_byte_size; |
6891 | struct attribute *attr_address_class; | |
6892 | int byte_size, addr_class; | |
7e314c57 JK |
6893 | struct type *target_type; |
6894 | ||
6895 | target_type = die_type (die, cu); | |
c906108c | 6896 | |
7e314c57 JK |
6897 | /* The die_type call above may have already set the type for this DIE. */ |
6898 | type = get_die_type (die, cu); | |
6899 | if (type) | |
6900 | return type; | |
6901 | ||
6902 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 6903 | |
e142c38c | 6904 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
6905 | if (attr_byte_size) |
6906 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 6907 | else |
8b2dbe47 KB |
6908 | byte_size = cu_header->addr_size; |
6909 | ||
e142c38c | 6910 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
6911 | if (attr_address_class) |
6912 | addr_class = DW_UNSND (attr_address_class); | |
6913 | else | |
6914 | addr_class = DW_ADDR_none; | |
6915 | ||
6916 | /* If the pointer size or address class is different than the | |
6917 | default, create a type variant marked as such and set the | |
6918 | length accordingly. */ | |
6919 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 6920 | { |
5e2b427d | 6921 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
6922 | { |
6923 | int type_flags; | |
6924 | ||
849957d9 | 6925 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 6926 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
6927 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
6928 | == 0); | |
8b2dbe47 KB |
6929 | type = make_type_with_address_space (type, type_flags); |
6930 | } | |
6931 | else if (TYPE_LENGTH (type) != byte_size) | |
6932 | { | |
e2e0b3e5 | 6933 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 | 6934 | } |
6e70227d | 6935 | else |
9a619af0 MS |
6936 | { |
6937 | /* Should we also complain about unhandled address classes? */ | |
6938 | } | |
c906108c | 6939 | } |
8b2dbe47 KB |
6940 | |
6941 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 6942 | return set_die_type (die, type, cu); |
c906108c SS |
6943 | } |
6944 | ||
6945 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
6946 | the user defined type vector. */ | |
6947 | ||
f792889a | 6948 | static struct type * |
e7c27a73 | 6949 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6950 | { |
6951 | struct type *type; | |
6952 | struct type *to_type; | |
6953 | struct type *domain; | |
6954 | ||
e7c27a73 DJ |
6955 | to_type = die_type (die, cu); |
6956 | domain = die_containing_type (die, cu); | |
0d5de010 | 6957 | |
7e314c57 JK |
6958 | /* The calls above may have already set the type for this DIE. */ |
6959 | type = get_die_type (die, cu); | |
6960 | if (type) | |
6961 | return type; | |
6962 | ||
0d5de010 DJ |
6963 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
6964 | type = lookup_methodptr_type (to_type); | |
6965 | else | |
6966 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 6967 | |
f792889a | 6968 | return set_die_type (die, type, cu); |
c906108c SS |
6969 | } |
6970 | ||
6971 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
6972 | the user defined type vector. */ | |
6973 | ||
f792889a | 6974 | static struct type * |
e7c27a73 | 6975 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6976 | { |
e7c27a73 | 6977 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 6978 | struct type *type, *target_type; |
c906108c SS |
6979 | struct attribute *attr; |
6980 | ||
7e314c57 JK |
6981 | target_type = die_type (die, cu); |
6982 | ||
6983 | /* The die_type call above may have already set the type for this DIE. */ | |
6984 | type = get_die_type (die, cu); | |
6985 | if (type) | |
6986 | return type; | |
6987 | ||
6988 | type = lookup_reference_type (target_type); | |
e142c38c | 6989 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6990 | if (attr) |
6991 | { | |
6992 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6993 | } | |
6994 | else | |
6995 | { | |
107d2387 | 6996 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 6997 | } |
f792889a | 6998 | return set_die_type (die, type, cu); |
c906108c SS |
6999 | } |
7000 | ||
f792889a | 7001 | static struct type * |
e7c27a73 | 7002 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7003 | { |
f792889a | 7004 | struct type *base_type, *cv_type; |
c906108c | 7005 | |
e7c27a73 | 7006 | base_type = die_type (die, cu); |
7e314c57 JK |
7007 | |
7008 | /* The die_type call above may have already set the type for this DIE. */ | |
7009 | cv_type = get_die_type (die, cu); | |
7010 | if (cv_type) | |
7011 | return cv_type; | |
7012 | ||
f792889a DJ |
7013 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
7014 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7015 | } |
7016 | ||
f792889a | 7017 | static struct type * |
e7c27a73 | 7018 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7019 | { |
f792889a | 7020 | struct type *base_type, *cv_type; |
c906108c | 7021 | |
e7c27a73 | 7022 | base_type = die_type (die, cu); |
7e314c57 JK |
7023 | |
7024 | /* The die_type call above may have already set the type for this DIE. */ | |
7025 | cv_type = get_die_type (die, cu); | |
7026 | if (cv_type) | |
7027 | return cv_type; | |
7028 | ||
f792889a DJ |
7029 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
7030 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7031 | } |
7032 | ||
7033 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
7034 | the user defined type vector. It isn't really a user defined type, | |
7035 | but it behaves like one, with other DIE's using an AT_user_def_type | |
7036 | attribute to reference it. */ | |
7037 | ||
f792889a | 7038 | static struct type * |
e7c27a73 | 7039 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7040 | { |
e7c27a73 | 7041 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 7042 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7043 | struct type *type, *range_type, *index_type, *char_type; |
7044 | struct attribute *attr; | |
7045 | unsigned int length; | |
7046 | ||
e142c38c | 7047 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
7048 | if (attr) |
7049 | { | |
7050 | length = DW_UNSND (attr); | |
7051 | } | |
7052 | else | |
7053 | { | |
b21b22e0 | 7054 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 7055 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
7056 | if (attr) |
7057 | { | |
7058 | length = DW_UNSND (attr); | |
7059 | } | |
7060 | else | |
7061 | { | |
7062 | length = 1; | |
7063 | } | |
c906108c | 7064 | } |
6ccb9162 | 7065 | |
46bf5051 | 7066 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7067 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
7068 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
7069 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 7070 | |
f792889a | 7071 | return set_die_type (die, type, cu); |
c906108c SS |
7072 | } |
7073 | ||
7074 | /* Handle DIES due to C code like: | |
7075 | ||
7076 | struct foo | |
c5aa993b JM |
7077 | { |
7078 | int (*funcp)(int a, long l); | |
7079 | int b; | |
7080 | }; | |
c906108c SS |
7081 | |
7082 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 7083 | */ |
c906108c | 7084 | |
f792889a | 7085 | static struct type * |
e7c27a73 | 7086 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7087 | { |
7088 | struct type *type; /* Type that this function returns */ | |
7089 | struct type *ftype; /* Function that returns above type */ | |
7090 | struct attribute *attr; | |
7091 | ||
e7c27a73 | 7092 | type = die_type (die, cu); |
7e314c57 JK |
7093 | |
7094 | /* The die_type call above may have already set the type for this DIE. */ | |
7095 | ftype = get_die_type (die, cu); | |
7096 | if (ftype) | |
7097 | return ftype; | |
7098 | ||
0c8b41f1 | 7099 | ftype = lookup_function_type (type); |
c906108c | 7100 | |
5b8101ae | 7101 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 7102 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 7103 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 7104 | || cu->language == language_cplus |
5b8101ae PM |
7105 | || cu->language == language_java |
7106 | || cu->language == language_pascal) | |
876cecd0 | 7107 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
7108 | else if (producer_is_realview (cu->producer)) |
7109 | /* RealView does not emit DW_AT_prototyped. We can not | |
7110 | distinguish prototyped and unprototyped functions; default to | |
7111 | prototyped, since that is more common in modern code (and | |
7112 | RealView warns about unprototyped functions). */ | |
7113 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 7114 | |
c055b101 CV |
7115 | /* Store the calling convention in the type if it's available in |
7116 | the subroutine die. Otherwise set the calling convention to | |
7117 | the default value DW_CC_normal. */ | |
7118 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
7119 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
7120 | |
7121 | /* We need to add the subroutine type to the die immediately so | |
7122 | we don't infinitely recurse when dealing with parameters | |
7123 | declared as the same subroutine type. */ | |
7124 | set_die_type (die, ftype, cu); | |
6e70227d | 7125 | |
639d11d3 | 7126 | if (die->child != NULL) |
c906108c | 7127 | { |
8072405b | 7128 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 7129 | struct die_info *child_die; |
8072405b | 7130 | int nparams, iparams; |
c906108c SS |
7131 | |
7132 | /* Count the number of parameters. | |
7133 | FIXME: GDB currently ignores vararg functions, but knows about | |
7134 | vararg member functions. */ | |
8072405b | 7135 | nparams = 0; |
639d11d3 | 7136 | child_die = die->child; |
c906108c SS |
7137 | while (child_die && child_die->tag) |
7138 | { | |
7139 | if (child_die->tag == DW_TAG_formal_parameter) | |
7140 | nparams++; | |
7141 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 7142 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
7143 | child_die = sibling_die (child_die); |
7144 | } | |
7145 | ||
7146 | /* Allocate storage for parameters and fill them in. */ | |
7147 | TYPE_NFIELDS (ftype) = nparams; | |
7148 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 7149 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 7150 | |
8072405b JK |
7151 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
7152 | even if we error out during the parameters reading below. */ | |
7153 | for (iparams = 0; iparams < nparams; iparams++) | |
7154 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
7155 | ||
7156 | iparams = 0; | |
639d11d3 | 7157 | child_die = die->child; |
c906108c SS |
7158 | while (child_die && child_die->tag) |
7159 | { | |
7160 | if (child_die->tag == DW_TAG_formal_parameter) | |
7161 | { | |
7162 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
7163 | member functions. G++ helps GDB by marking the first |
7164 | parameter for non-static member functions (which is the | |
7165 | this pointer) as artificial. We pass this information | |
7166 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 7167 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
7168 | if (attr) |
7169 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
7170 | else | |
418835cc KS |
7171 | { |
7172 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
7173 | ||
7174 | /* GCC/43521: In java, the formal parameter | |
7175 | "this" is sometimes not marked with DW_AT_artificial. */ | |
7176 | if (cu->language == language_java) | |
7177 | { | |
7178 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 7179 | |
418835cc KS |
7180 | if (name && !strcmp (name, "this")) |
7181 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
7182 | } | |
7183 | } | |
e7c27a73 | 7184 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
7185 | iparams++; |
7186 | } | |
7187 | child_die = sibling_die (child_die); | |
7188 | } | |
7189 | } | |
7190 | ||
76c10ea2 | 7191 | return ftype; |
c906108c SS |
7192 | } |
7193 | ||
f792889a | 7194 | static struct type * |
e7c27a73 | 7195 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7196 | { |
e7c27a73 | 7197 | struct objfile *objfile = cu->objfile; |
0114d602 | 7198 | const char *name = NULL; |
f792889a | 7199 | struct type *this_type; |
c906108c | 7200 | |
94af9270 | 7201 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 7202 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
7203 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
7204 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
7205 | set_die_type (die, this_type, cu); |
7206 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
7207 | return this_type; | |
c906108c SS |
7208 | } |
7209 | ||
7210 | /* Find a representation of a given base type and install | |
7211 | it in the TYPE field of the die. */ | |
7212 | ||
f792889a | 7213 | static struct type * |
e7c27a73 | 7214 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7215 | { |
e7c27a73 | 7216 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7217 | struct type *type; |
7218 | struct attribute *attr; | |
7219 | int encoding = 0, size = 0; | |
39cbfefa | 7220 | char *name; |
6ccb9162 UW |
7221 | enum type_code code = TYPE_CODE_INT; |
7222 | int type_flags = 0; | |
7223 | struct type *target_type = NULL; | |
c906108c | 7224 | |
e142c38c | 7225 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
7226 | if (attr) |
7227 | { | |
7228 | encoding = DW_UNSND (attr); | |
7229 | } | |
e142c38c | 7230 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7231 | if (attr) |
7232 | { | |
7233 | size = DW_UNSND (attr); | |
7234 | } | |
39cbfefa | 7235 | name = dwarf2_name (die, cu); |
6ccb9162 | 7236 | if (!name) |
c906108c | 7237 | { |
6ccb9162 UW |
7238 | complaint (&symfile_complaints, |
7239 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 7240 | } |
6ccb9162 UW |
7241 | |
7242 | switch (encoding) | |
c906108c | 7243 | { |
6ccb9162 UW |
7244 | case DW_ATE_address: |
7245 | /* Turn DW_ATE_address into a void * pointer. */ | |
7246 | code = TYPE_CODE_PTR; | |
7247 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7248 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
7249 | break; | |
7250 | case DW_ATE_boolean: | |
7251 | code = TYPE_CODE_BOOL; | |
7252 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7253 | break; | |
7254 | case DW_ATE_complex_float: | |
7255 | code = TYPE_CODE_COMPLEX; | |
7256 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
7257 | break; | |
7258 | case DW_ATE_decimal_float: | |
7259 | code = TYPE_CODE_DECFLOAT; | |
7260 | break; | |
7261 | case DW_ATE_float: | |
7262 | code = TYPE_CODE_FLT; | |
7263 | break; | |
7264 | case DW_ATE_signed: | |
7265 | break; | |
7266 | case DW_ATE_unsigned: | |
7267 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7268 | break; | |
7269 | case DW_ATE_signed_char: | |
6e70227d | 7270 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 7271 | || cu->language == language_pascal) |
6ccb9162 UW |
7272 | code = TYPE_CODE_CHAR; |
7273 | break; | |
7274 | case DW_ATE_unsigned_char: | |
868a0084 PM |
7275 | if (cu->language == language_ada || cu->language == language_m2 |
7276 | || cu->language == language_pascal) | |
6ccb9162 UW |
7277 | code = TYPE_CODE_CHAR; |
7278 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7279 | break; | |
75079b2b TT |
7280 | case DW_ATE_UTF: |
7281 | /* We just treat this as an integer and then recognize the | |
7282 | type by name elsewhere. */ | |
7283 | break; | |
7284 | ||
6ccb9162 UW |
7285 | default: |
7286 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
7287 | dwarf_type_encoding_name (encoding)); | |
7288 | break; | |
c906108c | 7289 | } |
6ccb9162 | 7290 | |
0114d602 DJ |
7291 | type = init_type (code, size, type_flags, NULL, objfile); |
7292 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
7293 | TYPE_TARGET_TYPE (type) = target_type; |
7294 | ||
0114d602 | 7295 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 7296 | TYPE_NOSIGN (type) = 1; |
0114d602 | 7297 | |
f792889a | 7298 | return set_die_type (die, type, cu); |
c906108c SS |
7299 | } |
7300 | ||
a02abb62 JB |
7301 | /* Read the given DW_AT_subrange DIE. */ |
7302 | ||
f792889a | 7303 | static struct type * |
a02abb62 JB |
7304 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
7305 | { | |
5e2b427d | 7306 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
7307 | struct type *base_type; |
7308 | struct type *range_type; | |
7309 | struct attribute *attr; | |
43bbcdc2 PH |
7310 | LONGEST low = 0; |
7311 | LONGEST high = -1; | |
39cbfefa | 7312 | char *name; |
43bbcdc2 | 7313 | LONGEST negative_mask; |
e77813c8 | 7314 | |
a02abb62 | 7315 | base_type = die_type (die, cu); |
953ac07e JK |
7316 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
7317 | check_typedef (base_type); | |
a02abb62 | 7318 | |
7e314c57 JK |
7319 | /* The die_type call above may have already set the type for this DIE. */ |
7320 | range_type = get_die_type (die, cu); | |
7321 | if (range_type) | |
7322 | return range_type; | |
7323 | ||
e142c38c | 7324 | if (cu->language == language_fortran) |
6e70227d | 7325 | { |
a02abb62 JB |
7326 | /* FORTRAN implies a lower bound of 1, if not given. */ |
7327 | low = 1; | |
7328 | } | |
7329 | ||
dd5e6932 DJ |
7330 | /* FIXME: For variable sized arrays either of these could be |
7331 | a variable rather than a constant value. We'll allow it, | |
7332 | but we don't know how to handle it. */ | |
e142c38c | 7333 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
7334 | if (attr) |
7335 | low = dwarf2_get_attr_constant_value (attr, 0); | |
7336 | ||
e142c38c | 7337 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 7338 | if (attr) |
6e70227d | 7339 | { |
e77813c8 | 7340 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
7341 | { |
7342 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 7343 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
7344 | FIXME: GDB does not yet know how to handle dynamic |
7345 | arrays properly, treat them as arrays with unspecified | |
7346 | length for now. | |
7347 | ||
7348 | FIXME: jimb/2003-09-22: GDB does not really know | |
7349 | how to handle arrays of unspecified length | |
7350 | either; we just represent them as zero-length | |
7351 | arrays. Choose an appropriate upper bound given | |
7352 | the lower bound we've computed above. */ | |
7353 | high = low - 1; | |
7354 | } | |
7355 | else | |
7356 | high = dwarf2_get_attr_constant_value (attr, 1); | |
7357 | } | |
e77813c8 PM |
7358 | else |
7359 | { | |
7360 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
7361 | if (attr) | |
7362 | { | |
7363 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
7364 | high = low + count - 1; | |
7365 | } | |
7366 | } | |
7367 | ||
7368 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
7369 | without specifying a base type. | |
7370 | In that case, the base type must be set to the type of | |
7371 | the lower bound, upper bound or count, in that order, if any of these | |
7372 | three attributes references an object that has a type. | |
7373 | If no base type is found, the Dwarf-2 specifications say that | |
7374 | a signed integer type of size equal to the size of an address should | |
7375 | be used. | |
7376 | For the following C code: `extern char gdb_int [];' | |
7377 | GCC produces an empty range DIE. | |
7378 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
7379 | high bound or count are not yet handled by this code. | |
7380 | */ | |
7381 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
7382 | { | |
7383 | struct objfile *objfile = cu->objfile; | |
7384 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
7385 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
7386 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
7387 | ||
7388 | /* Test "int", "long int", and "long long int" objfile types, | |
7389 | and select the first one having a size above or equal to the | |
7390 | architecture address size. */ | |
7391 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7392 | base_type = int_type; | |
7393 | else | |
7394 | { | |
7395 | int_type = objfile_type (objfile)->builtin_long; | |
7396 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7397 | base_type = int_type; | |
7398 | else | |
7399 | { | |
7400 | int_type = objfile_type (objfile)->builtin_long_long; | |
7401 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7402 | base_type = int_type; | |
7403 | } | |
7404 | } | |
7405 | } | |
a02abb62 | 7406 | |
6e70227d | 7407 | negative_mask = |
43bbcdc2 PH |
7408 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
7409 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
7410 | low |= negative_mask; | |
7411 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
7412 | high |= negative_mask; | |
7413 | ||
a02abb62 JB |
7414 | range_type = create_range_type (NULL, base_type, low, high); |
7415 | ||
bbb0eef6 JK |
7416 | /* Mark arrays with dynamic length at least as an array of unspecified |
7417 | length. GDB could check the boundary but before it gets implemented at | |
7418 | least allow accessing the array elements. */ | |
7419 | if (attr && attr->form == DW_FORM_block1) | |
7420 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
7421 | ||
39cbfefa DJ |
7422 | name = dwarf2_name (die, cu); |
7423 | if (name) | |
7424 | TYPE_NAME (range_type) = name; | |
6e70227d | 7425 | |
e142c38c | 7426 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
7427 | if (attr) |
7428 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
7429 | ||
7e314c57 JK |
7430 | set_die_type (die, range_type, cu); |
7431 | ||
7432 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7433 | set_descriptive_type (range_type, die, cu); |
7434 | ||
7e314c57 | 7435 | return range_type; |
a02abb62 | 7436 | } |
6e70227d | 7437 | |
f792889a | 7438 | static struct type * |
81a17f79 JB |
7439 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
7440 | { | |
7441 | struct type *type; | |
81a17f79 | 7442 | |
81a17f79 JB |
7443 | /* For now, we only support the C meaning of an unspecified type: void. */ |
7444 | ||
0114d602 DJ |
7445 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
7446 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 7447 | |
f792889a | 7448 | return set_die_type (die, type, cu); |
81a17f79 | 7449 | } |
a02abb62 | 7450 | |
51545339 DJ |
7451 | /* Trivial hash function for die_info: the hash value of a DIE |
7452 | is its offset in .debug_info for this objfile. */ | |
7453 | ||
7454 | static hashval_t | |
7455 | die_hash (const void *item) | |
7456 | { | |
7457 | const struct die_info *die = item; | |
9a619af0 | 7458 | |
51545339 DJ |
7459 | return die->offset; |
7460 | } | |
7461 | ||
7462 | /* Trivial comparison function for die_info structures: two DIEs | |
7463 | are equal if they have the same offset. */ | |
7464 | ||
7465 | static int | |
7466 | die_eq (const void *item_lhs, const void *item_rhs) | |
7467 | { | |
7468 | const struct die_info *die_lhs = item_lhs; | |
7469 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 7470 | |
51545339 DJ |
7471 | return die_lhs->offset == die_rhs->offset; |
7472 | } | |
7473 | ||
c906108c SS |
7474 | /* Read a whole compilation unit into a linked list of dies. */ |
7475 | ||
f9aca02d | 7476 | static struct die_info * |
93311388 | 7477 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 7478 | { |
93311388 DE |
7479 | struct die_reader_specs reader_specs; |
7480 | ||
348e048f | 7481 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
7482 | cu->die_hash |
7483 | = htab_create_alloc_ex (cu->header.length / 12, | |
7484 | die_hash, | |
7485 | die_eq, | |
7486 | NULL, | |
7487 | &cu->comp_unit_obstack, | |
7488 | hashtab_obstack_allocate, | |
7489 | dummy_obstack_deallocate); | |
7490 | ||
93311388 DE |
7491 | init_cu_die_reader (&reader_specs, cu); |
7492 | ||
7493 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
7494 | } |
7495 | ||
d97bc12b DE |
7496 | /* Main entry point for reading a DIE and all children. |
7497 | Read the DIE and dump it if requested. */ | |
7498 | ||
7499 | static struct die_info * | |
93311388 DE |
7500 | read_die_and_children (const struct die_reader_specs *reader, |
7501 | gdb_byte *info_ptr, | |
d97bc12b DE |
7502 | gdb_byte **new_info_ptr, |
7503 | struct die_info *parent) | |
7504 | { | |
93311388 | 7505 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
7506 | new_info_ptr, parent); |
7507 | ||
7508 | if (dwarf2_die_debug) | |
7509 | { | |
348e048f DE |
7510 | fprintf_unfiltered (gdb_stdlog, |
7511 | "\nRead die from %s of %s:\n", | |
7512 | reader->buffer == dwarf2_per_objfile->info.buffer | |
7513 | ? ".debug_info" | |
7514 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
7515 | ? ".debug_types" | |
7516 | : "unknown section", | |
7517 | reader->abfd->filename); | |
d97bc12b DE |
7518 | dump_die (result, dwarf2_die_debug); |
7519 | } | |
7520 | ||
7521 | return result; | |
7522 | } | |
7523 | ||
639d11d3 DC |
7524 | /* Read a single die and all its descendents. Set the die's sibling |
7525 | field to NULL; set other fields in the die correctly, and set all | |
7526 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
7527 | location of the info_ptr after reading all of those dies. PARENT | |
7528 | is the parent of the die in question. */ | |
7529 | ||
7530 | static struct die_info * | |
93311388 DE |
7531 | read_die_and_children_1 (const struct die_reader_specs *reader, |
7532 | gdb_byte *info_ptr, | |
d97bc12b DE |
7533 | gdb_byte **new_info_ptr, |
7534 | struct die_info *parent) | |
639d11d3 DC |
7535 | { |
7536 | struct die_info *die; | |
fe1b8b76 | 7537 | gdb_byte *cur_ptr; |
639d11d3 DC |
7538 | int has_children; |
7539 | ||
93311388 | 7540 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
7541 | if (die == NULL) |
7542 | { | |
7543 | *new_info_ptr = cur_ptr; | |
7544 | return NULL; | |
7545 | } | |
93311388 | 7546 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
7547 | |
7548 | if (has_children) | |
348e048f | 7549 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
7550 | else |
7551 | { | |
7552 | die->child = NULL; | |
7553 | *new_info_ptr = cur_ptr; | |
7554 | } | |
7555 | ||
7556 | die->sibling = NULL; | |
7557 | die->parent = parent; | |
7558 | return die; | |
7559 | } | |
7560 | ||
7561 | /* Read a die, all of its descendents, and all of its siblings; set | |
7562 | all of the fields of all of the dies correctly. Arguments are as | |
7563 | in read_die_and_children. */ | |
7564 | ||
7565 | static struct die_info * | |
93311388 DE |
7566 | read_die_and_siblings (const struct die_reader_specs *reader, |
7567 | gdb_byte *info_ptr, | |
fe1b8b76 | 7568 | gdb_byte **new_info_ptr, |
639d11d3 DC |
7569 | struct die_info *parent) |
7570 | { | |
7571 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 7572 | gdb_byte *cur_ptr; |
639d11d3 | 7573 | |
c906108c | 7574 | cur_ptr = info_ptr; |
639d11d3 DC |
7575 | first_die = last_sibling = NULL; |
7576 | ||
7577 | while (1) | |
c906108c | 7578 | { |
639d11d3 | 7579 | struct die_info *die |
93311388 | 7580 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 7581 | |
1d325ec1 | 7582 | if (die == NULL) |
c906108c | 7583 | { |
639d11d3 DC |
7584 | *new_info_ptr = cur_ptr; |
7585 | return first_die; | |
c906108c | 7586 | } |
1d325ec1 DJ |
7587 | |
7588 | if (!first_die) | |
7589 | first_die = die; | |
c906108c | 7590 | else |
1d325ec1 DJ |
7591 | last_sibling->sibling = die; |
7592 | ||
7593 | last_sibling = die; | |
c906108c | 7594 | } |
c906108c SS |
7595 | } |
7596 | ||
93311388 DE |
7597 | /* Read the die from the .debug_info section buffer. Set DIEP to |
7598 | point to a newly allocated die with its information, except for its | |
7599 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
7600 | whether the die has children or not. */ | |
7601 | ||
7602 | static gdb_byte * | |
7603 | read_full_die (const struct die_reader_specs *reader, | |
7604 | struct die_info **diep, gdb_byte *info_ptr, | |
7605 | int *has_children) | |
7606 | { | |
7607 | unsigned int abbrev_number, bytes_read, i, offset; | |
7608 | struct abbrev_info *abbrev; | |
7609 | struct die_info *die; | |
7610 | struct dwarf2_cu *cu = reader->cu; | |
7611 | bfd *abfd = reader->abfd; | |
7612 | ||
7613 | offset = info_ptr - reader->buffer; | |
7614 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7615 | info_ptr += bytes_read; | |
7616 | if (!abbrev_number) | |
7617 | { | |
7618 | *diep = NULL; | |
7619 | *has_children = 0; | |
7620 | return info_ptr; | |
7621 | } | |
7622 | ||
7623 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
7624 | if (!abbrev) | |
348e048f DE |
7625 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
7626 | abbrev_number, | |
7627 | bfd_get_filename (abfd)); | |
7628 | ||
93311388 DE |
7629 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
7630 | die->offset = offset; | |
7631 | die->tag = abbrev->tag; | |
7632 | die->abbrev = abbrev_number; | |
7633 | ||
7634 | die->num_attrs = abbrev->num_attrs; | |
7635 | ||
7636 | for (i = 0; i < abbrev->num_attrs; ++i) | |
7637 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
7638 | abfd, info_ptr, cu); | |
7639 | ||
7640 | *diep = die; | |
7641 | *has_children = abbrev->has_children; | |
7642 | return info_ptr; | |
7643 | } | |
7644 | ||
c906108c SS |
7645 | /* In DWARF version 2, the description of the debugging information is |
7646 | stored in a separate .debug_abbrev section. Before we read any | |
7647 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
7648 | in a hash table. This function also sets flags in CU describing |
7649 | the data found in the abbrev table. */ | |
c906108c SS |
7650 | |
7651 | static void | |
e7c27a73 | 7652 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 7653 | { |
e7c27a73 | 7654 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 7655 | gdb_byte *abbrev_ptr; |
c906108c SS |
7656 | struct abbrev_info *cur_abbrev; |
7657 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
7658 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
7659 | struct attr_abbrev *cur_attrs; |
7660 | unsigned int allocated_attrs; | |
c906108c | 7661 | |
57349743 | 7662 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
7663 | obstack_init (&cu->abbrev_obstack); |
7664 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
7665 | (ABBREV_HASH_SIZE | |
7666 | * sizeof (struct abbrev_info *))); | |
7667 | memset (cu->dwarf2_abbrevs, 0, | |
7668 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 7669 | |
be391dca TT |
7670 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
7671 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 7672 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
7673 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
7674 | abbrev_ptr += bytes_read; | |
7675 | ||
f3dd6933 DJ |
7676 | allocated_attrs = ATTR_ALLOC_CHUNK; |
7677 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 7678 | |
c906108c SS |
7679 | /* loop until we reach an abbrev number of 0 */ |
7680 | while (abbrev_number) | |
7681 | { | |
f3dd6933 | 7682 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
7683 | |
7684 | /* read in abbrev header */ | |
7685 | cur_abbrev->number = abbrev_number; | |
7686 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7687 | abbrev_ptr += bytes_read; | |
7688 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
7689 | abbrev_ptr += 1; | |
7690 | ||
72bf9492 DJ |
7691 | if (cur_abbrev->tag == DW_TAG_namespace) |
7692 | cu->has_namespace_info = 1; | |
7693 | ||
c906108c SS |
7694 | /* now read in declarations */ |
7695 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7696 | abbrev_ptr += bytes_read; | |
7697 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7698 | abbrev_ptr += bytes_read; | |
7699 | while (abbrev_name) | |
7700 | { | |
f3dd6933 | 7701 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 7702 | { |
f3dd6933 DJ |
7703 | allocated_attrs += ATTR_ALLOC_CHUNK; |
7704 | cur_attrs | |
7705 | = xrealloc (cur_attrs, (allocated_attrs | |
7706 | * sizeof (struct attr_abbrev))); | |
c906108c | 7707 | } |
ae038cb0 DJ |
7708 | |
7709 | /* Record whether this compilation unit might have | |
7710 | inter-compilation-unit references. If we don't know what form | |
7711 | this attribute will have, then it might potentially be a | |
7712 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
7713 | references. */ | |
7714 | ||
7715 | if (abbrev_form == DW_FORM_ref_addr | |
7716 | || abbrev_form == DW_FORM_indirect) | |
7717 | cu->has_form_ref_addr = 1; | |
7718 | ||
f3dd6933 DJ |
7719 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
7720 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
7721 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
7722 | abbrev_ptr += bytes_read; | |
7723 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7724 | abbrev_ptr += bytes_read; | |
7725 | } | |
7726 | ||
f3dd6933 DJ |
7727 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
7728 | (cur_abbrev->num_attrs | |
7729 | * sizeof (struct attr_abbrev))); | |
7730 | memcpy (cur_abbrev->attrs, cur_attrs, | |
7731 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
7732 | ||
c906108c | 7733 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
7734 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
7735 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
7736 | |
7737 | /* Get next abbreviation. | |
7738 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
7739 | always properly terminated with an abbrev number of 0. |
7740 | Exit loop if we encounter an abbreviation which we have | |
7741 | already read (which means we are about to read the abbreviations | |
7742 | for the next compile unit) or if the end of the abbreviation | |
7743 | table is reached. */ | |
dce234bc PP |
7744 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
7745 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
7746 | break; |
7747 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7748 | abbrev_ptr += bytes_read; | |
e7c27a73 | 7749 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
7750 | break; |
7751 | } | |
f3dd6933 DJ |
7752 | |
7753 | xfree (cur_attrs); | |
c906108c SS |
7754 | } |
7755 | ||
f3dd6933 | 7756 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 7757 | |
c906108c | 7758 | static void |
f3dd6933 | 7759 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 7760 | { |
f3dd6933 | 7761 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 7762 | |
f3dd6933 DJ |
7763 | obstack_free (&cu->abbrev_obstack, NULL); |
7764 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
7765 | } |
7766 | ||
7767 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
7768 | ||
7769 | static struct abbrev_info * | |
e7c27a73 | 7770 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
7771 | { |
7772 | unsigned int hash_number; | |
7773 | struct abbrev_info *abbrev; | |
7774 | ||
7775 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 7776 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
7777 | |
7778 | while (abbrev) | |
7779 | { | |
7780 | if (abbrev->number == number) | |
7781 | return abbrev; | |
7782 | else | |
7783 | abbrev = abbrev->next; | |
7784 | } | |
7785 | return NULL; | |
7786 | } | |
7787 | ||
72bf9492 DJ |
7788 | /* Returns nonzero if TAG represents a type that we might generate a partial |
7789 | symbol for. */ | |
7790 | ||
7791 | static int | |
7792 | is_type_tag_for_partial (int tag) | |
7793 | { | |
7794 | switch (tag) | |
7795 | { | |
7796 | #if 0 | |
7797 | /* Some types that would be reasonable to generate partial symbols for, | |
7798 | that we don't at present. */ | |
7799 | case DW_TAG_array_type: | |
7800 | case DW_TAG_file_type: | |
7801 | case DW_TAG_ptr_to_member_type: | |
7802 | case DW_TAG_set_type: | |
7803 | case DW_TAG_string_type: | |
7804 | case DW_TAG_subroutine_type: | |
7805 | #endif | |
7806 | case DW_TAG_base_type: | |
7807 | case DW_TAG_class_type: | |
680b30c7 | 7808 | case DW_TAG_interface_type: |
72bf9492 DJ |
7809 | case DW_TAG_enumeration_type: |
7810 | case DW_TAG_structure_type: | |
7811 | case DW_TAG_subrange_type: | |
7812 | case DW_TAG_typedef: | |
7813 | case DW_TAG_union_type: | |
7814 | return 1; | |
7815 | default: | |
7816 | return 0; | |
7817 | } | |
7818 | } | |
7819 | ||
7820 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
7821 | ||
7822 | static struct partial_die_info * | |
93311388 DE |
7823 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
7824 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
7825 | { |
7826 | struct partial_die_info *part_die; | |
7827 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
7828 | struct abbrev_info *abbrev; | |
7829 | unsigned int bytes_read; | |
5afb4e99 | 7830 | unsigned int load_all = 0; |
72bf9492 DJ |
7831 | |
7832 | int nesting_level = 1; | |
7833 | ||
7834 | parent_die = NULL; | |
7835 | last_die = NULL; | |
7836 | ||
5afb4e99 DJ |
7837 | if (cu->per_cu && cu->per_cu->load_all_dies) |
7838 | load_all = 1; | |
7839 | ||
72bf9492 DJ |
7840 | cu->partial_dies |
7841 | = htab_create_alloc_ex (cu->header.length / 12, | |
7842 | partial_die_hash, | |
7843 | partial_die_eq, | |
7844 | NULL, | |
7845 | &cu->comp_unit_obstack, | |
7846 | hashtab_obstack_allocate, | |
7847 | dummy_obstack_deallocate); | |
7848 | ||
7849 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
7850 | sizeof (struct partial_die_info)); | |
7851 | ||
7852 | while (1) | |
7853 | { | |
7854 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
7855 | ||
7856 | /* A NULL abbrev means the end of a series of children. */ | |
7857 | if (abbrev == NULL) | |
7858 | { | |
7859 | if (--nesting_level == 0) | |
7860 | { | |
7861 | /* PART_DIE was probably the last thing allocated on the | |
7862 | comp_unit_obstack, so we could call obstack_free | |
7863 | here. We don't do that because the waste is small, | |
7864 | and will be cleaned up when we're done with this | |
7865 | compilation unit. This way, we're also more robust | |
7866 | against other users of the comp_unit_obstack. */ | |
7867 | return first_die; | |
7868 | } | |
7869 | info_ptr += bytes_read; | |
7870 | last_die = parent_die; | |
7871 | parent_die = parent_die->die_parent; | |
7872 | continue; | |
7873 | } | |
7874 | ||
5afb4e99 DJ |
7875 | /* Check whether this DIE is interesting enough to save. Normally |
7876 | we would not be interested in members here, but there may be | |
7877 | later variables referencing them via DW_AT_specification (for | |
7878 | static members). */ | |
7879 | if (!load_all | |
7880 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
7881 | && abbrev->tag != DW_TAG_enumerator |
7882 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 7883 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 7884 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 7885 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 7886 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 7887 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
7888 | { |
7889 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 7890 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
7891 | continue; |
7892 | } | |
7893 | ||
93311388 DE |
7894 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
7895 | buffer, info_ptr, cu); | |
72bf9492 DJ |
7896 | |
7897 | /* This two-pass algorithm for processing partial symbols has a | |
7898 | high cost in cache pressure. Thus, handle some simple cases | |
7899 | here which cover the majority of C partial symbols. DIEs | |
7900 | which neither have specification tags in them, nor could have | |
7901 | specification tags elsewhere pointing at them, can simply be | |
7902 | processed and discarded. | |
7903 | ||
7904 | This segment is also optional; scan_partial_symbols and | |
7905 | add_partial_symbol will handle these DIEs if we chain | |
7906 | them in normally. When compilers which do not emit large | |
7907 | quantities of duplicate debug information are more common, | |
7908 | this code can probably be removed. */ | |
7909 | ||
7910 | /* Any complete simple types at the top level (pretty much all | |
7911 | of them, for a language without namespaces), can be processed | |
7912 | directly. */ | |
7913 | if (parent_die == NULL | |
7914 | && part_die->has_specification == 0 | |
7915 | && part_die->is_declaration == 0 | |
7916 | && (part_die->tag == DW_TAG_typedef | |
7917 | || part_die->tag == DW_TAG_base_type | |
7918 | || part_die->tag == DW_TAG_subrange_type)) | |
7919 | { | |
7920 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 7921 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
7922 | VAR_DOMAIN, LOC_TYPEDEF, |
7923 | &cu->objfile->static_psymbols, | |
7924 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 7925 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
7926 | continue; |
7927 | } | |
7928 | ||
7929 | /* If we're at the second level, and we're an enumerator, and | |
7930 | our parent has no specification (meaning possibly lives in a | |
7931 | namespace elsewhere), then we can add the partial symbol now | |
7932 | instead of queueing it. */ | |
7933 | if (part_die->tag == DW_TAG_enumerator | |
7934 | && parent_die != NULL | |
7935 | && parent_die->die_parent == NULL | |
7936 | && parent_die->tag == DW_TAG_enumeration_type | |
7937 | && parent_die->has_specification == 0) | |
7938 | { | |
7939 | if (part_die->name == NULL) | |
e2e0b3e5 | 7940 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 7941 | else if (building_psymtab) |
04a679b8 | 7942 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 7943 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
7944 | (cu->language == language_cplus |
7945 | || cu->language == language_java) | |
72bf9492 DJ |
7946 | ? &cu->objfile->global_psymbols |
7947 | : &cu->objfile->static_psymbols, | |
7948 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
7949 | ||
93311388 | 7950 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
7951 | continue; |
7952 | } | |
7953 | ||
7954 | /* We'll save this DIE so link it in. */ | |
7955 | part_die->die_parent = parent_die; | |
7956 | part_die->die_sibling = NULL; | |
7957 | part_die->die_child = NULL; | |
7958 | ||
7959 | if (last_die && last_die == parent_die) | |
7960 | last_die->die_child = part_die; | |
7961 | else if (last_die) | |
7962 | last_die->die_sibling = part_die; | |
7963 | ||
7964 | last_die = part_die; | |
7965 | ||
7966 | if (first_die == NULL) | |
7967 | first_die = part_die; | |
7968 | ||
7969 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
7970 | find interesting need to be in the hash table, because we | |
7971 | also have the parent/sibling/child chains; only those that we | |
7972 | might refer to by offset later during partial symbol reading. | |
7973 | ||
7974 | For now this means things that might have be the target of a | |
7975 | DW_AT_specification, DW_AT_abstract_origin, or | |
7976 | DW_AT_extension. DW_AT_extension will refer only to | |
7977 | namespaces; DW_AT_abstract_origin refers to functions (and | |
7978 | many things under the function DIE, but we do not recurse | |
7979 | into function DIEs during partial symbol reading) and | |
7980 | possibly variables as well; DW_AT_specification refers to | |
7981 | declarations. Declarations ought to have the DW_AT_declaration | |
7982 | flag. It happens that GCC forgets to put it in sometimes, but | |
7983 | only for functions, not for types. | |
7984 | ||
7985 | Adding more things than necessary to the hash table is harmless | |
7986 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
7987 | wasted time in find_partial_die, when we reread the compilation |
7988 | unit with load_all_dies set. */ | |
72bf9492 | 7989 | |
5afb4e99 DJ |
7990 | if (load_all |
7991 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
7992 | || abbrev->tag == DW_TAG_variable |
7993 | || abbrev->tag == DW_TAG_namespace | |
7994 | || part_die->is_declaration) | |
7995 | { | |
7996 | void **slot; | |
7997 | ||
7998 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
7999 | part_die->offset, INSERT); | |
8000 | *slot = part_die; | |
8001 | } | |
8002 | ||
8003 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8004 | sizeof (struct partial_die_info)); | |
8005 | ||
8006 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 8007 | we have no reason to follow the children of structures; for other |
72bf9492 | 8008 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
8009 | to infer fully qualified class names, and for DW_AT_specification. |
8010 | ||
8011 | For Ada, we need to scan the children of subprograms and lexical | |
8012 | blocks as well because Ada allows the definition of nested | |
8013 | entities that could be interesting for the debugger, such as | |
8014 | nested subprograms for instance. */ | |
72bf9492 | 8015 | if (last_die->has_children |
5afb4e99 DJ |
8016 | && (load_all |
8017 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 8018 | || last_die->tag == DW_TAG_module |
72bf9492 DJ |
8019 | || last_die->tag == DW_TAG_enumeration_type |
8020 | || (cu->language != language_c | |
8021 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 8022 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 8023 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
8024 | || last_die->tag == DW_TAG_union_type)) |
8025 | || (cu->language == language_ada | |
8026 | && (last_die->tag == DW_TAG_subprogram | |
8027 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
8028 | { |
8029 | nesting_level++; | |
8030 | parent_die = last_die; | |
8031 | continue; | |
8032 | } | |
8033 | ||
8034 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8035 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8036 | |
8037 | /* Back to the top, do it again. */ | |
8038 | } | |
8039 | } | |
8040 | ||
c906108c SS |
8041 | /* Read a minimal amount of information into the minimal die structure. */ |
8042 | ||
fe1b8b76 | 8043 | static gdb_byte * |
72bf9492 DJ |
8044 | read_partial_die (struct partial_die_info *part_die, |
8045 | struct abbrev_info *abbrev, | |
8046 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
8047 | gdb_byte *buffer, gdb_byte *info_ptr, |
8048 | struct dwarf2_cu *cu) | |
c906108c | 8049 | { |
fa238c03 | 8050 | unsigned int i; |
c906108c | 8051 | struct attribute attr; |
c5aa993b | 8052 | int has_low_pc_attr = 0; |
c906108c SS |
8053 | int has_high_pc_attr = 0; |
8054 | ||
72bf9492 | 8055 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 8056 | |
93311388 | 8057 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
8058 | |
8059 | info_ptr += abbrev_len; | |
8060 | ||
8061 | if (abbrev == NULL) | |
8062 | return info_ptr; | |
8063 | ||
c906108c SS |
8064 | part_die->tag = abbrev->tag; |
8065 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
8066 | |
8067 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8068 | { | |
e7c27a73 | 8069 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
8070 | |
8071 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 8072 | partial symbol table. */ |
c906108c SS |
8073 | switch (attr.name) |
8074 | { | |
8075 | case DW_AT_name: | |
71c25dea TT |
8076 | switch (part_die->tag) |
8077 | { | |
8078 | case DW_TAG_compile_unit: | |
348e048f | 8079 | case DW_TAG_type_unit: |
71c25dea TT |
8080 | /* Compilation units have a DW_AT_name that is a filename, not |
8081 | a source language identifier. */ | |
8082 | case DW_TAG_enumeration_type: | |
8083 | case DW_TAG_enumerator: | |
8084 | /* These tags always have simple identifiers already; no need | |
8085 | to canonicalize them. */ | |
8086 | part_die->name = DW_STRING (&attr); | |
8087 | break; | |
8088 | default: | |
8089 | part_die->name | |
8090 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 8091 | &cu->objfile->objfile_obstack); |
71c25dea TT |
8092 | break; |
8093 | } | |
c906108c | 8094 | break; |
31ef98ae | 8095 | case DW_AT_linkage_name: |
c906108c | 8096 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
8097 | /* Note that both forms of linkage name might appear. We |
8098 | assume they will be the same, and we only store the last | |
8099 | one we see. */ | |
94af9270 KS |
8100 | if (cu->language == language_ada) |
8101 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
8102 | break; |
8103 | case DW_AT_low_pc: | |
8104 | has_low_pc_attr = 1; | |
8105 | part_die->lowpc = DW_ADDR (&attr); | |
8106 | break; | |
8107 | case DW_AT_high_pc: | |
8108 | has_high_pc_attr = 1; | |
8109 | part_die->highpc = DW_ADDR (&attr); | |
8110 | break; | |
8111 | case DW_AT_location: | |
8e19ed76 PS |
8112 | /* Support the .debug_loc offsets */ |
8113 | if (attr_form_is_block (&attr)) | |
8114 | { | |
8115 | part_die->locdesc = DW_BLOCK (&attr); | |
8116 | } | |
3690dd37 | 8117 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 8118 | { |
4d3c2250 | 8119 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8120 | } |
8121 | else | |
8122 | { | |
4d3c2250 KB |
8123 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8124 | "partial symbol information"); | |
8e19ed76 | 8125 | } |
c906108c | 8126 | break; |
c906108c SS |
8127 | case DW_AT_external: |
8128 | part_die->is_external = DW_UNSND (&attr); | |
8129 | break; | |
8130 | case DW_AT_declaration: | |
8131 | part_die->is_declaration = DW_UNSND (&attr); | |
8132 | break; | |
8133 | case DW_AT_type: | |
8134 | part_die->has_type = 1; | |
8135 | break; | |
8136 | case DW_AT_abstract_origin: | |
8137 | case DW_AT_specification: | |
72bf9492 DJ |
8138 | case DW_AT_extension: |
8139 | part_die->has_specification = 1; | |
c764a876 | 8140 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
8141 | break; |
8142 | case DW_AT_sibling: | |
8143 | /* Ignore absolute siblings, they might point outside of | |
8144 | the current compile unit. */ | |
8145 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 8146 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 8147 | else |
93311388 | 8148 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 8149 | break; |
fa4028e9 JB |
8150 | case DW_AT_byte_size: |
8151 | part_die->has_byte_size = 1; | |
8152 | break; | |
68511cec CES |
8153 | case DW_AT_calling_convention: |
8154 | /* DWARF doesn't provide a way to identify a program's source-level | |
8155 | entry point. DW_AT_calling_convention attributes are only meant | |
8156 | to describe functions' calling conventions. | |
8157 | ||
8158 | However, because it's a necessary piece of information in | |
8159 | Fortran, and because DW_CC_program is the only piece of debugging | |
8160 | information whose definition refers to a 'main program' at all, | |
8161 | several compilers have begun marking Fortran main programs with | |
8162 | DW_CC_program --- even when those functions use the standard | |
8163 | calling conventions. | |
8164 | ||
8165 | So until DWARF specifies a way to provide this information and | |
8166 | compilers pick up the new representation, we'll support this | |
8167 | practice. */ | |
8168 | if (DW_UNSND (&attr) == DW_CC_program | |
8169 | && cu->language == language_fortran) | |
8170 | set_main_name (part_die->name); | |
8171 | break; | |
c906108c SS |
8172 | default: |
8173 | break; | |
8174 | } | |
8175 | } | |
8176 | ||
c906108c SS |
8177 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
8178 | eliminate duplicate copies of functions and vtables and such. | |
8179 | The linker will arbitrarily choose one and discard the others. | |
8180 | The AT_*_pc values for such functions refer to local labels in | |
8181 | these sections. If the section from that file was discarded, the | |
8182 | labels are not in the output, so the relocs get a value of 0. | |
8183 | If this is a discarded function, mark the pc bounds as invalid, | |
8184 | so that GDB will ignore it. */ | |
8185 | if (has_low_pc_attr && has_high_pc_attr | |
8186 | && part_die->lowpc < part_die->highpc | |
8187 | && (part_die->lowpc != 0 | |
72dca2f5 | 8188 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 8189 | part_die->has_pc_info = 1; |
85cbf3d3 | 8190 | |
c906108c SS |
8191 | return info_ptr; |
8192 | } | |
8193 | ||
72bf9492 DJ |
8194 | /* Find a cached partial DIE at OFFSET in CU. */ |
8195 | ||
8196 | static struct partial_die_info * | |
c764a876 | 8197 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
8198 | { |
8199 | struct partial_die_info *lookup_die = NULL; | |
8200 | struct partial_die_info part_die; | |
8201 | ||
8202 | part_die.offset = offset; | |
8203 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
8204 | ||
72bf9492 DJ |
8205 | return lookup_die; |
8206 | } | |
8207 | ||
348e048f DE |
8208 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
8209 | except in the case of .debug_types DIEs which do not reference | |
8210 | outside their CU (they do however referencing other types via | |
8211 | DW_FORM_sig8). */ | |
72bf9492 DJ |
8212 | |
8213 | static struct partial_die_info * | |
c764a876 | 8214 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 8215 | { |
5afb4e99 DJ |
8216 | struct dwarf2_per_cu_data *per_cu = NULL; |
8217 | struct partial_die_info *pd = NULL; | |
72bf9492 | 8218 | |
348e048f DE |
8219 | if (cu->per_cu->from_debug_types) |
8220 | { | |
8221 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8222 | if (pd != NULL) | |
8223 | return pd; | |
8224 | goto not_found; | |
8225 | } | |
8226 | ||
45452591 | 8227 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
8228 | { |
8229 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8230 | if (pd != NULL) | |
8231 | return pd; | |
8232 | } | |
72bf9492 | 8233 | |
ae038cb0 DJ |
8234 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
8235 | ||
ae038cb0 DJ |
8236 | if (per_cu->cu == NULL) |
8237 | { | |
93311388 | 8238 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
8239 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
8240 | dwarf2_per_objfile->read_in_chain = per_cu; | |
8241 | } | |
8242 | ||
8243 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
8244 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
8245 | ||
8246 | if (pd == NULL && per_cu->load_all_dies == 0) | |
8247 | { | |
8248 | struct cleanup *back_to; | |
8249 | struct partial_die_info comp_unit_die; | |
8250 | struct abbrev_info *abbrev; | |
8251 | unsigned int bytes_read; | |
8252 | char *info_ptr; | |
8253 | ||
8254 | per_cu->load_all_dies = 1; | |
8255 | ||
8256 | /* Re-read the DIEs. */ | |
8257 | back_to = make_cleanup (null_cleanup, 0); | |
8258 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
8259 | { | |
8260 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 8261 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 8262 | } |
dce234bc | 8263 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
8264 | + per_cu->cu->header.offset |
8265 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
8266 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
8267 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
8268 | per_cu->cu->objfile->obfd, |
8269 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
8270 | per_cu->cu); |
8271 | if (comp_unit_die.has_children) | |
93311388 DE |
8272 | load_partial_dies (per_cu->cu->objfile->obfd, |
8273 | dwarf2_per_objfile->info.buffer, info_ptr, | |
8274 | 0, per_cu->cu); | |
5afb4e99 DJ |
8275 | do_cleanups (back_to); |
8276 | ||
8277 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
8278 | } | |
8279 | ||
348e048f DE |
8280 | not_found: |
8281 | ||
5afb4e99 DJ |
8282 | if (pd == NULL) |
8283 | internal_error (__FILE__, __LINE__, | |
c764a876 | 8284 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
8285 | offset, bfd_get_filename (cu->objfile->obfd)); |
8286 | return pd; | |
72bf9492 DJ |
8287 | } |
8288 | ||
8289 | /* Adjust PART_DIE before generating a symbol for it. This function | |
8290 | may set the is_external flag or change the DIE's name. */ | |
8291 | ||
8292 | static void | |
8293 | fixup_partial_die (struct partial_die_info *part_die, | |
8294 | struct dwarf2_cu *cu) | |
8295 | { | |
8296 | /* If we found a reference attribute and the DIE has no name, try | |
8297 | to find a name in the referred to DIE. */ | |
8298 | ||
8299 | if (part_die->name == NULL && part_die->has_specification) | |
8300 | { | |
8301 | struct partial_die_info *spec_die; | |
72bf9492 | 8302 | |
10b3939b | 8303 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 8304 | |
10b3939b | 8305 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
8306 | |
8307 | if (spec_die->name) | |
8308 | { | |
8309 | part_die->name = spec_die->name; | |
8310 | ||
8311 | /* Copy DW_AT_external attribute if it is set. */ | |
8312 | if (spec_die->is_external) | |
8313 | part_die->is_external = spec_die->is_external; | |
8314 | } | |
8315 | } | |
8316 | ||
8317 | /* Set default names for some unnamed DIEs. */ | |
8318 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
8319 | || part_die->tag == DW_TAG_class_type)) | |
8320 | part_die->name = "(anonymous class)"; | |
8321 | ||
8322 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
8323 | part_die->name = "(anonymous namespace)"; | |
8324 | ||
8325 | if (part_die->tag == DW_TAG_structure_type | |
8326 | || part_die->tag == DW_TAG_class_type | |
8327 | || part_die->tag == DW_TAG_union_type) | |
8328 | guess_structure_name (part_die, cu); | |
8329 | } | |
8330 | ||
a8329558 | 8331 | /* Read an attribute value described by an attribute form. */ |
c906108c | 8332 | |
fe1b8b76 | 8333 | static gdb_byte * |
a8329558 | 8334 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 8335 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 8336 | struct dwarf2_cu *cu) |
c906108c | 8337 | { |
e7c27a73 | 8338 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
8339 | unsigned int bytes_read; |
8340 | struct dwarf_block *blk; | |
8341 | ||
a8329558 KW |
8342 | attr->form = form; |
8343 | switch (form) | |
c906108c | 8344 | { |
c906108c | 8345 | case DW_FORM_ref_addr: |
ae411497 TT |
8346 | if (cu->header.version == 2) |
8347 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
8348 | else | |
8349 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
8350 | info_ptr += bytes_read; | |
8351 | break; | |
8352 | case DW_FORM_addr: | |
e7c27a73 | 8353 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 8354 | info_ptr += bytes_read; |
c906108c SS |
8355 | break; |
8356 | case DW_FORM_block2: | |
7b5a2f43 | 8357 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8358 | blk->size = read_2_bytes (abfd, info_ptr); |
8359 | info_ptr += 2; | |
8360 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8361 | info_ptr += blk->size; | |
8362 | DW_BLOCK (attr) = blk; | |
8363 | break; | |
8364 | case DW_FORM_block4: | |
7b5a2f43 | 8365 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8366 | blk->size = read_4_bytes (abfd, info_ptr); |
8367 | info_ptr += 4; | |
8368 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8369 | info_ptr += blk->size; | |
8370 | DW_BLOCK (attr) = blk; | |
8371 | break; | |
8372 | case DW_FORM_data2: | |
8373 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
8374 | info_ptr += 2; | |
8375 | break; | |
8376 | case DW_FORM_data4: | |
8377 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
8378 | info_ptr += 4; | |
8379 | break; | |
8380 | case DW_FORM_data8: | |
8381 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
8382 | info_ptr += 8; | |
8383 | break; | |
2dc7f7b3 TT |
8384 | case DW_FORM_sec_offset: |
8385 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
8386 | info_ptr += bytes_read; | |
8387 | break; | |
c906108c SS |
8388 | case DW_FORM_string: |
8389 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 8390 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
8391 | info_ptr += bytes_read; |
8392 | break; | |
4bdf3d34 JJ |
8393 | case DW_FORM_strp: |
8394 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
8395 | &bytes_read); | |
8285870a | 8396 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
8397 | info_ptr += bytes_read; |
8398 | break; | |
2dc7f7b3 | 8399 | case DW_FORM_exprloc: |
c906108c | 8400 | case DW_FORM_block: |
7b5a2f43 | 8401 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8402 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
8403 | info_ptr += bytes_read; | |
8404 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8405 | info_ptr += blk->size; | |
8406 | DW_BLOCK (attr) = blk; | |
8407 | break; | |
8408 | case DW_FORM_block1: | |
7b5a2f43 | 8409 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8410 | blk->size = read_1_byte (abfd, info_ptr); |
8411 | info_ptr += 1; | |
8412 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8413 | info_ptr += blk->size; | |
8414 | DW_BLOCK (attr) = blk; | |
8415 | break; | |
8416 | case DW_FORM_data1: | |
8417 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
8418 | info_ptr += 1; | |
8419 | break; | |
8420 | case DW_FORM_flag: | |
8421 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
8422 | info_ptr += 1; | |
8423 | break; | |
2dc7f7b3 TT |
8424 | case DW_FORM_flag_present: |
8425 | DW_UNSND (attr) = 1; | |
8426 | break; | |
c906108c SS |
8427 | case DW_FORM_sdata: |
8428 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
8429 | info_ptr += bytes_read; | |
8430 | break; | |
8431 | case DW_FORM_udata: | |
8432 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8433 | info_ptr += bytes_read; | |
8434 | break; | |
8435 | case DW_FORM_ref1: | |
10b3939b | 8436 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
8437 | info_ptr += 1; |
8438 | break; | |
8439 | case DW_FORM_ref2: | |
10b3939b | 8440 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
8441 | info_ptr += 2; |
8442 | break; | |
8443 | case DW_FORM_ref4: | |
10b3939b | 8444 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
8445 | info_ptr += 4; |
8446 | break; | |
613e1657 | 8447 | case DW_FORM_ref8: |
10b3939b | 8448 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
8449 | info_ptr += 8; |
8450 | break; | |
348e048f DE |
8451 | case DW_FORM_sig8: |
8452 | /* Convert the signature to something we can record in DW_UNSND | |
8453 | for later lookup. | |
8454 | NOTE: This is NULL if the type wasn't found. */ | |
8455 | DW_SIGNATURED_TYPE (attr) = | |
8456 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
8457 | info_ptr += 8; | |
8458 | break; | |
c906108c | 8459 | case DW_FORM_ref_udata: |
10b3939b DJ |
8460 | DW_ADDR (attr) = (cu->header.offset |
8461 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
8462 | info_ptr += bytes_read; |
8463 | break; | |
c906108c | 8464 | case DW_FORM_indirect: |
a8329558 KW |
8465 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
8466 | info_ptr += bytes_read; | |
e7c27a73 | 8467 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 8468 | break; |
c906108c | 8469 | default: |
8a3fe4f8 | 8470 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
8471 | dwarf_form_name (form), |
8472 | bfd_get_filename (abfd)); | |
c906108c | 8473 | } |
28e94949 JB |
8474 | |
8475 | /* We have seen instances where the compiler tried to emit a byte | |
8476 | size attribute of -1 which ended up being encoded as an unsigned | |
8477 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
8478 | an object of this size seems pretty unlikely so we can relatively | |
8479 | safely treat these cases as if the size attribute was invalid and | |
8480 | treat them as zero by default. */ | |
8481 | if (attr->name == DW_AT_byte_size | |
8482 | && form == DW_FORM_data4 | |
8483 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
8484 | { |
8485 | complaint | |
8486 | (&symfile_complaints, | |
43bbcdc2 PH |
8487 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
8488 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
8489 | DW_UNSND (attr) = 0; |
8490 | } | |
28e94949 | 8491 | |
c906108c SS |
8492 | return info_ptr; |
8493 | } | |
8494 | ||
a8329558 KW |
8495 | /* Read an attribute described by an abbreviated attribute. */ |
8496 | ||
fe1b8b76 | 8497 | static gdb_byte * |
a8329558 | 8498 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 8499 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
8500 | { |
8501 | attr->name = abbrev->name; | |
e7c27a73 | 8502 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
8503 | } |
8504 | ||
c906108c SS |
8505 | /* read dwarf information from a buffer */ |
8506 | ||
8507 | static unsigned int | |
fe1b8b76 | 8508 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 8509 | { |
fe1b8b76 | 8510 | return bfd_get_8 (abfd, buf); |
c906108c SS |
8511 | } |
8512 | ||
8513 | static int | |
fe1b8b76 | 8514 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 8515 | { |
fe1b8b76 | 8516 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
8517 | } |
8518 | ||
8519 | static unsigned int | |
fe1b8b76 | 8520 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8521 | { |
fe1b8b76 | 8522 | return bfd_get_16 (abfd, buf); |
c906108c SS |
8523 | } |
8524 | ||
8525 | static int | |
fe1b8b76 | 8526 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8527 | { |
fe1b8b76 | 8528 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
8529 | } |
8530 | ||
8531 | static unsigned int | |
fe1b8b76 | 8532 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8533 | { |
fe1b8b76 | 8534 | return bfd_get_32 (abfd, buf); |
c906108c SS |
8535 | } |
8536 | ||
8537 | static int | |
fe1b8b76 | 8538 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8539 | { |
fe1b8b76 | 8540 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
8541 | } |
8542 | ||
93311388 | 8543 | static ULONGEST |
fe1b8b76 | 8544 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8545 | { |
fe1b8b76 | 8546 | return bfd_get_64 (abfd, buf); |
c906108c SS |
8547 | } |
8548 | ||
8549 | static CORE_ADDR | |
fe1b8b76 | 8550 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 8551 | unsigned int *bytes_read) |
c906108c | 8552 | { |
e7c27a73 | 8553 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
8554 | CORE_ADDR retval = 0; |
8555 | ||
107d2387 | 8556 | if (cu_header->signed_addr_p) |
c906108c | 8557 | { |
107d2387 AC |
8558 | switch (cu_header->addr_size) |
8559 | { | |
8560 | case 2: | |
fe1b8b76 | 8561 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
8562 | break; |
8563 | case 4: | |
fe1b8b76 | 8564 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
8565 | break; |
8566 | case 8: | |
fe1b8b76 | 8567 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
8568 | break; |
8569 | default: | |
8e65ff28 | 8570 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 8571 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 8572 | bfd_get_filename (abfd)); |
107d2387 AC |
8573 | } |
8574 | } | |
8575 | else | |
8576 | { | |
8577 | switch (cu_header->addr_size) | |
8578 | { | |
8579 | case 2: | |
fe1b8b76 | 8580 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
8581 | break; |
8582 | case 4: | |
fe1b8b76 | 8583 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
8584 | break; |
8585 | case 8: | |
fe1b8b76 | 8586 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
8587 | break; |
8588 | default: | |
8e65ff28 | 8589 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 8590 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 8591 | bfd_get_filename (abfd)); |
107d2387 | 8592 | } |
c906108c | 8593 | } |
64367e0a | 8594 | |
107d2387 AC |
8595 | *bytes_read = cu_header->addr_size; |
8596 | return retval; | |
c906108c SS |
8597 | } |
8598 | ||
f7ef9339 | 8599 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
8600 | specification allows the initial length to take up either 4 bytes |
8601 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
8602 | bytes describe the length and all offsets will be 8 bytes in length | |
8603 | instead of 4. | |
8604 | ||
f7ef9339 KB |
8605 | An older, non-standard 64-bit format is also handled by this |
8606 | function. The older format in question stores the initial length | |
8607 | as an 8-byte quantity without an escape value. Lengths greater | |
8608 | than 2^32 aren't very common which means that the initial 4 bytes | |
8609 | is almost always zero. Since a length value of zero doesn't make | |
8610 | sense for the 32-bit format, this initial zero can be considered to | |
8611 | be an escape value which indicates the presence of the older 64-bit | |
8612 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
8613 | greater than 4GB. If it becomes necessary to handle lengths |
8614 | somewhat larger than 4GB, we could allow other small values (such | |
8615 | as the non-sensical values of 1, 2, and 3) to also be used as | |
8616 | escape values indicating the presence of the old format. | |
f7ef9339 | 8617 | |
917c78fc MK |
8618 | The value returned via bytes_read should be used to increment the |
8619 | relevant pointer after calling read_initial_length(). | |
c764a876 | 8620 | |
613e1657 KB |
8621 | [ Note: read_initial_length() and read_offset() are based on the |
8622 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 8623 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
8624 | from: |
8625 | ||
f7ef9339 | 8626 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 8627 | |
613e1657 KB |
8628 | This document is only a draft and is subject to change. (So beware.) |
8629 | ||
f7ef9339 | 8630 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
8631 | determined empirically by examining 64-bit ELF files produced by |
8632 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
8633 | |
8634 | - Kevin, July 16, 2002 | |
613e1657 KB |
8635 | ] */ |
8636 | ||
8637 | static LONGEST | |
c764a876 | 8638 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 8639 | { |
fe1b8b76 | 8640 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 8641 | |
dd373385 | 8642 | if (length == 0xffffffff) |
613e1657 | 8643 | { |
fe1b8b76 | 8644 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 8645 | *bytes_read = 12; |
613e1657 | 8646 | } |
dd373385 | 8647 | else if (length == 0) |
f7ef9339 | 8648 | { |
dd373385 | 8649 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 8650 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 8651 | *bytes_read = 8; |
f7ef9339 | 8652 | } |
613e1657 KB |
8653 | else |
8654 | { | |
8655 | *bytes_read = 4; | |
613e1657 KB |
8656 | } |
8657 | ||
c764a876 DE |
8658 | return length; |
8659 | } | |
dd373385 | 8660 | |
c764a876 DE |
8661 | /* Cover function for read_initial_length. |
8662 | Returns the length of the object at BUF, and stores the size of the | |
8663 | initial length in *BYTES_READ and stores the size that offsets will be in | |
8664 | *OFFSET_SIZE. | |
8665 | If the initial length size is not equivalent to that specified in | |
8666 | CU_HEADER then issue a complaint. | |
8667 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 8668 | |
c764a876 DE |
8669 | static LONGEST |
8670 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
8671 | const struct comp_unit_head *cu_header, | |
8672 | unsigned int *bytes_read, | |
8673 | unsigned int *offset_size) | |
8674 | { | |
8675 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
8676 | ||
8677 | gdb_assert (cu_header->initial_length_size == 4 | |
8678 | || cu_header->initial_length_size == 8 | |
8679 | || cu_header->initial_length_size == 12); | |
8680 | ||
8681 | if (cu_header->initial_length_size != *bytes_read) | |
8682 | complaint (&symfile_complaints, | |
8683 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 8684 | |
c764a876 | 8685 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 8686 | return length; |
613e1657 KB |
8687 | } |
8688 | ||
8689 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 8690 | given by cu_header->offset_size. */ |
613e1657 KB |
8691 | |
8692 | static LONGEST | |
fe1b8b76 | 8693 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 8694 | unsigned int *bytes_read) |
c764a876 DE |
8695 | { |
8696 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 8697 | |
c764a876 DE |
8698 | *bytes_read = cu_header->offset_size; |
8699 | return offset; | |
8700 | } | |
8701 | ||
8702 | /* Read an offset from the data stream. */ | |
8703 | ||
8704 | static LONGEST | |
8705 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
8706 | { |
8707 | LONGEST retval = 0; | |
8708 | ||
c764a876 | 8709 | switch (offset_size) |
613e1657 KB |
8710 | { |
8711 | case 4: | |
fe1b8b76 | 8712 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
8713 | break; |
8714 | case 8: | |
fe1b8b76 | 8715 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
8716 | break; |
8717 | default: | |
8e65ff28 | 8718 | internal_error (__FILE__, __LINE__, |
c764a876 | 8719 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 8720 | bfd_get_filename (abfd)); |
613e1657 KB |
8721 | } |
8722 | ||
917c78fc | 8723 | return retval; |
613e1657 KB |
8724 | } |
8725 | ||
fe1b8b76 JB |
8726 | static gdb_byte * |
8727 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
8728 | { |
8729 | /* If the size of a host char is 8 bits, we can return a pointer | |
8730 | to the buffer, otherwise we have to copy the data to a buffer | |
8731 | allocated on the temporary obstack. */ | |
4bdf3d34 | 8732 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 8733 | return buf; |
c906108c SS |
8734 | } |
8735 | ||
8736 | static char * | |
fe1b8b76 | 8737 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
8738 | { |
8739 | /* If the size of a host char is 8 bits, we can return a pointer | |
8740 | to the string, otherwise we have to copy the string to a buffer | |
8741 | allocated on the temporary obstack. */ | |
4bdf3d34 | 8742 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
8743 | if (*buf == '\0') |
8744 | { | |
8745 | *bytes_read_ptr = 1; | |
8746 | return NULL; | |
8747 | } | |
fe1b8b76 JB |
8748 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
8749 | return (char *) buf; | |
4bdf3d34 JJ |
8750 | } |
8751 | ||
8752 | static char * | |
fe1b8b76 | 8753 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
8754 | const struct comp_unit_head *cu_header, |
8755 | unsigned int *bytes_read_ptr) | |
8756 | { | |
c764a876 | 8757 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 8758 | |
be391dca | 8759 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 8760 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 8761 | { |
8a3fe4f8 | 8762 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 8763 | bfd_get_filename (abfd)); |
4bdf3d34 | 8764 | return NULL; |
c906108c | 8765 | } |
dce234bc | 8766 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 8767 | { |
8a3fe4f8 | 8768 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 8769 | bfd_get_filename (abfd)); |
c906108c SS |
8770 | return NULL; |
8771 | } | |
4bdf3d34 | 8772 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 8773 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 8774 | return NULL; |
dce234bc | 8775 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
8776 | } |
8777 | ||
ce5d95e1 | 8778 | static unsigned long |
fe1b8b76 | 8779 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 8780 | { |
ce5d95e1 JB |
8781 | unsigned long result; |
8782 | unsigned int num_read; | |
c906108c SS |
8783 | int i, shift; |
8784 | unsigned char byte; | |
8785 | ||
8786 | result = 0; | |
8787 | shift = 0; | |
8788 | num_read = 0; | |
8789 | i = 0; | |
8790 | while (1) | |
8791 | { | |
fe1b8b76 | 8792 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
8793 | buf++; |
8794 | num_read++; | |
ce5d95e1 | 8795 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
8796 | if ((byte & 128) == 0) |
8797 | { | |
8798 | break; | |
8799 | } | |
8800 | shift += 7; | |
8801 | } | |
8802 | *bytes_read_ptr = num_read; | |
8803 | return result; | |
8804 | } | |
8805 | ||
ce5d95e1 | 8806 | static long |
fe1b8b76 | 8807 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 8808 | { |
ce5d95e1 | 8809 | long result; |
77e0b926 | 8810 | int i, shift, num_read; |
c906108c SS |
8811 | unsigned char byte; |
8812 | ||
8813 | result = 0; | |
8814 | shift = 0; | |
c906108c SS |
8815 | num_read = 0; |
8816 | i = 0; | |
8817 | while (1) | |
8818 | { | |
fe1b8b76 | 8819 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
8820 | buf++; |
8821 | num_read++; | |
ce5d95e1 | 8822 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
8823 | shift += 7; |
8824 | if ((byte & 128) == 0) | |
8825 | { | |
8826 | break; | |
8827 | } | |
8828 | } | |
77e0b926 DJ |
8829 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
8830 | result |= -(((long)1) << shift); | |
c906108c SS |
8831 | *bytes_read_ptr = num_read; |
8832 | return result; | |
8833 | } | |
8834 | ||
4bb7a0a7 DJ |
8835 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
8836 | ||
fe1b8b76 JB |
8837 | static gdb_byte * |
8838 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
8839 | { |
8840 | int byte; | |
8841 | ||
8842 | while (1) | |
8843 | { | |
fe1b8b76 | 8844 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
8845 | buf++; |
8846 | if ((byte & 128) == 0) | |
8847 | return buf; | |
8848 | } | |
8849 | } | |
8850 | ||
c906108c | 8851 | static void |
e142c38c | 8852 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
8853 | { |
8854 | switch (lang) | |
8855 | { | |
8856 | case DW_LANG_C89: | |
76bee0cc | 8857 | case DW_LANG_C99: |
c906108c | 8858 | case DW_LANG_C: |
e142c38c | 8859 | cu->language = language_c; |
c906108c SS |
8860 | break; |
8861 | case DW_LANG_C_plus_plus: | |
e142c38c | 8862 | cu->language = language_cplus; |
c906108c | 8863 | break; |
6aecb9c2 JB |
8864 | case DW_LANG_D: |
8865 | cu->language = language_d; | |
8866 | break; | |
c906108c SS |
8867 | case DW_LANG_Fortran77: |
8868 | case DW_LANG_Fortran90: | |
b21b22e0 | 8869 | case DW_LANG_Fortran95: |
e142c38c | 8870 | cu->language = language_fortran; |
c906108c SS |
8871 | break; |
8872 | case DW_LANG_Mips_Assembler: | |
e142c38c | 8873 | cu->language = language_asm; |
c906108c | 8874 | break; |
bebd888e | 8875 | case DW_LANG_Java: |
e142c38c | 8876 | cu->language = language_java; |
bebd888e | 8877 | break; |
c906108c | 8878 | case DW_LANG_Ada83: |
8aaf0b47 | 8879 | case DW_LANG_Ada95: |
bc5f45f8 JB |
8880 | cu->language = language_ada; |
8881 | break; | |
72019c9c GM |
8882 | case DW_LANG_Modula2: |
8883 | cu->language = language_m2; | |
8884 | break; | |
fe8e67fd PM |
8885 | case DW_LANG_Pascal83: |
8886 | cu->language = language_pascal; | |
8887 | break; | |
22566fbd DJ |
8888 | case DW_LANG_ObjC: |
8889 | cu->language = language_objc; | |
8890 | break; | |
c906108c SS |
8891 | case DW_LANG_Cobol74: |
8892 | case DW_LANG_Cobol85: | |
c906108c | 8893 | default: |
e142c38c | 8894 | cu->language = language_minimal; |
c906108c SS |
8895 | break; |
8896 | } | |
e142c38c | 8897 | cu->language_defn = language_def (cu->language); |
c906108c SS |
8898 | } |
8899 | ||
8900 | /* Return the named attribute or NULL if not there. */ | |
8901 | ||
8902 | static struct attribute * | |
e142c38c | 8903 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
8904 | { |
8905 | unsigned int i; | |
8906 | struct attribute *spec = NULL; | |
8907 | ||
8908 | for (i = 0; i < die->num_attrs; ++i) | |
8909 | { | |
8910 | if (die->attrs[i].name == name) | |
10b3939b | 8911 | return &die->attrs[i]; |
c906108c SS |
8912 | if (die->attrs[i].name == DW_AT_specification |
8913 | || die->attrs[i].name == DW_AT_abstract_origin) | |
8914 | spec = &die->attrs[i]; | |
8915 | } | |
c906108c | 8916 | |
10b3939b | 8917 | if (spec) |
f2f0e013 DJ |
8918 | { |
8919 | die = follow_die_ref (die, spec, &cu); | |
8920 | return dwarf2_attr (die, name, cu); | |
8921 | } | |
c5aa993b | 8922 | |
c906108c SS |
8923 | return NULL; |
8924 | } | |
8925 | ||
348e048f DE |
8926 | /* Return the named attribute or NULL if not there, |
8927 | but do not follow DW_AT_specification, etc. | |
8928 | This is for use in contexts where we're reading .debug_types dies. | |
8929 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
8930 | back up the chain, and we want to go down. */ | |
8931 | ||
8932 | static struct attribute * | |
8933 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
8934 | struct dwarf2_cu *cu) | |
8935 | { | |
8936 | unsigned int i; | |
8937 | ||
8938 | for (i = 0; i < die->num_attrs; ++i) | |
8939 | if (die->attrs[i].name == name) | |
8940 | return &die->attrs[i]; | |
8941 | ||
8942 | return NULL; | |
8943 | } | |
8944 | ||
05cf31d1 JB |
8945 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
8946 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 8947 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
8948 | |
8949 | static int | |
8950 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
8951 | { | |
8952 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
8953 | ||
8954 | return (attr && DW_UNSND (attr)); | |
8955 | } | |
8956 | ||
3ca72b44 | 8957 | static int |
e142c38c | 8958 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 8959 | { |
05cf31d1 JB |
8960 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
8961 | which value is non-zero. However, we have to be careful with | |
8962 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
8963 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
8964 | end up accidently finding a declaration attribute that belongs | |
8965 | to a different DIE referenced by the specification attribute, | |
8966 | even though the given DIE does not have a declaration attribute. */ | |
8967 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
8968 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
8969 | } |
8970 | ||
63d06c5c | 8971 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 8972 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
8973 | containing the return value on output. If there is no |
8974 | specification, but there is an abstract origin, that is | |
8975 | returned. */ | |
63d06c5c DC |
8976 | |
8977 | static struct die_info * | |
f2f0e013 | 8978 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 8979 | { |
f2f0e013 DJ |
8980 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
8981 | *spec_cu); | |
63d06c5c | 8982 | |
edb3359d DJ |
8983 | if (spec_attr == NULL) |
8984 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
8985 | ||
63d06c5c DC |
8986 | if (spec_attr == NULL) |
8987 | return NULL; | |
8988 | else | |
f2f0e013 | 8989 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 8990 | } |
c906108c | 8991 | |
debd256d JB |
8992 | /* Free the line_header structure *LH, and any arrays and strings it |
8993 | refers to. */ | |
8994 | static void | |
8995 | free_line_header (struct line_header *lh) | |
8996 | { | |
8997 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 8998 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
8999 | |
9000 | /* Remember that all the lh->file_names[i].name pointers are | |
9001 | pointers into debug_line_buffer, and don't need to be freed. */ | |
9002 | if (lh->file_names) | |
a8bc7b56 | 9003 | xfree (lh->file_names); |
debd256d JB |
9004 | |
9005 | /* Similarly for the include directory names. */ | |
9006 | if (lh->include_dirs) | |
a8bc7b56 | 9007 | xfree (lh->include_dirs); |
debd256d | 9008 | |
a8bc7b56 | 9009 | xfree (lh); |
debd256d JB |
9010 | } |
9011 | ||
9012 | ||
9013 | /* Add an entry to LH's include directory table. */ | |
9014 | static void | |
9015 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 9016 | { |
debd256d JB |
9017 | /* Grow the array if necessary. */ |
9018 | if (lh->include_dirs_size == 0) | |
c5aa993b | 9019 | { |
debd256d JB |
9020 | lh->include_dirs_size = 1; /* for testing */ |
9021 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
9022 | * sizeof (*lh->include_dirs)); | |
9023 | } | |
9024 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
9025 | { | |
9026 | lh->include_dirs_size *= 2; | |
9027 | lh->include_dirs = xrealloc (lh->include_dirs, | |
9028 | (lh->include_dirs_size | |
9029 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 9030 | } |
c906108c | 9031 | |
debd256d JB |
9032 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
9033 | } | |
6e70227d | 9034 | |
debd256d JB |
9035 | |
9036 | /* Add an entry to LH's file name table. */ | |
9037 | static void | |
9038 | add_file_name (struct line_header *lh, | |
9039 | char *name, | |
9040 | unsigned int dir_index, | |
9041 | unsigned int mod_time, | |
9042 | unsigned int length) | |
9043 | { | |
9044 | struct file_entry *fe; | |
9045 | ||
9046 | /* Grow the array if necessary. */ | |
9047 | if (lh->file_names_size == 0) | |
9048 | { | |
9049 | lh->file_names_size = 1; /* for testing */ | |
9050 | lh->file_names = xmalloc (lh->file_names_size | |
9051 | * sizeof (*lh->file_names)); | |
9052 | } | |
9053 | else if (lh->num_file_names >= lh->file_names_size) | |
9054 | { | |
9055 | lh->file_names_size *= 2; | |
9056 | lh->file_names = xrealloc (lh->file_names, | |
9057 | (lh->file_names_size | |
9058 | * sizeof (*lh->file_names))); | |
9059 | } | |
9060 | ||
9061 | fe = &lh->file_names[lh->num_file_names++]; | |
9062 | fe->name = name; | |
9063 | fe->dir_index = dir_index; | |
9064 | fe->mod_time = mod_time; | |
9065 | fe->length = length; | |
aaa75496 | 9066 | fe->included_p = 0; |
cb1df416 | 9067 | fe->symtab = NULL; |
debd256d | 9068 | } |
6e70227d | 9069 | |
debd256d JB |
9070 | |
9071 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
9072 | .debug_line, according to the endianness of ABFD. Return a pointer |
9073 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
9074 | |
9075 | NOTE: the strings in the include directory and file name tables of | |
9076 | the returned object point into debug_line_buffer, and must not be | |
9077 | freed. */ | |
9078 | static struct line_header * | |
9079 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 9080 | struct dwarf2_cu *cu) |
debd256d JB |
9081 | { |
9082 | struct cleanup *back_to; | |
9083 | struct line_header *lh; | |
fe1b8b76 | 9084 | gdb_byte *line_ptr; |
c764a876 | 9085 | unsigned int bytes_read, offset_size; |
debd256d JB |
9086 | int i; |
9087 | char *cur_dir, *cur_file; | |
9088 | ||
be391dca | 9089 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 9090 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 9091 | { |
e2e0b3e5 | 9092 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
9093 | return 0; |
9094 | } | |
9095 | ||
a738430d MK |
9096 | /* Make sure that at least there's room for the total_length field. |
9097 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 9098 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 9099 | { |
4d3c2250 | 9100 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9101 | return 0; |
9102 | } | |
9103 | ||
9104 | lh = xmalloc (sizeof (*lh)); | |
9105 | memset (lh, 0, sizeof (*lh)); | |
9106 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
9107 | (void *) lh); | |
9108 | ||
dce234bc | 9109 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 9110 | |
a738430d | 9111 | /* Read in the header. */ |
6e70227d | 9112 | lh->total_length = |
c764a876 DE |
9113 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
9114 | &bytes_read, &offset_size); | |
debd256d | 9115 | line_ptr += bytes_read; |
dce234bc PP |
9116 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
9117 | + dwarf2_per_objfile->line.size)) | |
debd256d | 9118 | { |
4d3c2250 | 9119 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9120 | return 0; |
9121 | } | |
9122 | lh->statement_program_end = line_ptr + lh->total_length; | |
9123 | lh->version = read_2_bytes (abfd, line_ptr); | |
9124 | line_ptr += 2; | |
c764a876 DE |
9125 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
9126 | line_ptr += offset_size; | |
debd256d JB |
9127 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
9128 | line_ptr += 1; | |
2dc7f7b3 TT |
9129 | if (lh->version >= 4) |
9130 | { | |
9131 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
9132 | line_ptr += 1; | |
9133 | } | |
9134 | else | |
9135 | lh->maximum_ops_per_instruction = 1; | |
9136 | ||
9137 | if (lh->maximum_ops_per_instruction == 0) | |
9138 | { | |
9139 | lh->maximum_ops_per_instruction = 1; | |
9140 | complaint (&symfile_complaints, | |
9141 | _("invalid maximum_ops_per_instruction in `.debug_line' section")); | |
9142 | } | |
9143 | ||
debd256d JB |
9144 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
9145 | line_ptr += 1; | |
9146 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
9147 | line_ptr += 1; | |
9148 | lh->line_range = read_1_byte (abfd, line_ptr); | |
9149 | line_ptr += 1; | |
9150 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
9151 | line_ptr += 1; | |
9152 | lh->standard_opcode_lengths | |
fe1b8b76 | 9153 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
9154 | |
9155 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
9156 | for (i = 1; i < lh->opcode_base; ++i) | |
9157 | { | |
9158 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
9159 | line_ptr += 1; | |
9160 | } | |
9161 | ||
a738430d | 9162 | /* Read directory table. */ |
debd256d JB |
9163 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
9164 | { | |
9165 | line_ptr += bytes_read; | |
9166 | add_include_dir (lh, cur_dir); | |
9167 | } | |
9168 | line_ptr += bytes_read; | |
9169 | ||
a738430d | 9170 | /* Read file name table. */ |
debd256d JB |
9171 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
9172 | { | |
9173 | unsigned int dir_index, mod_time, length; | |
9174 | ||
9175 | line_ptr += bytes_read; | |
9176 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9177 | line_ptr += bytes_read; | |
9178 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9179 | line_ptr += bytes_read; | |
9180 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9181 | line_ptr += bytes_read; | |
9182 | ||
9183 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9184 | } | |
9185 | line_ptr += bytes_read; | |
6e70227d | 9186 | lh->statement_program_start = line_ptr; |
debd256d | 9187 | |
dce234bc PP |
9188 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
9189 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 9190 | complaint (&symfile_complaints, |
e2e0b3e5 | 9191 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
9192 | |
9193 | discard_cleanups (back_to); | |
9194 | return lh; | |
9195 | } | |
c906108c | 9196 | |
5fb290d7 DJ |
9197 | /* This function exists to work around a bug in certain compilers |
9198 | (particularly GCC 2.95), in which the first line number marker of a | |
9199 | function does not show up until after the prologue, right before | |
9200 | the second line number marker. This function shifts ADDRESS down | |
9201 | to the beginning of the function if necessary, and is called on | |
9202 | addresses passed to record_line. */ | |
9203 | ||
9204 | static CORE_ADDR | |
e142c38c | 9205 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
9206 | { |
9207 | struct function_range *fn; | |
9208 | ||
9209 | /* Find the function_range containing address. */ | |
e142c38c | 9210 | if (!cu->first_fn) |
5fb290d7 DJ |
9211 | return address; |
9212 | ||
e142c38c DJ |
9213 | if (!cu->cached_fn) |
9214 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 9215 | |
e142c38c | 9216 | fn = cu->cached_fn; |
5fb290d7 DJ |
9217 | while (fn) |
9218 | if (fn->lowpc <= address && fn->highpc > address) | |
9219 | goto found; | |
9220 | else | |
9221 | fn = fn->next; | |
9222 | ||
e142c38c DJ |
9223 | fn = cu->first_fn; |
9224 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
9225 | if (fn->lowpc <= address && fn->highpc > address) |
9226 | goto found; | |
9227 | else | |
9228 | fn = fn->next; | |
9229 | ||
9230 | return address; | |
9231 | ||
9232 | found: | |
9233 | if (fn->seen_line) | |
9234 | return address; | |
9235 | if (address != fn->lowpc) | |
4d3c2250 | 9236 | complaint (&symfile_complaints, |
e2e0b3e5 | 9237 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 9238 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
9239 | fn->seen_line = 1; |
9240 | return fn->lowpc; | |
9241 | } | |
9242 | ||
aaa75496 JB |
9243 | /* Decode the Line Number Program (LNP) for the given line_header |
9244 | structure and CU. The actual information extracted and the type | |
9245 | of structures created from the LNP depends on the value of PST. | |
9246 | ||
9247 | 1. If PST is NULL, then this procedure uses the data from the program | |
9248 | to create all necessary symbol tables, and their linetables. | |
9249 | The compilation directory of the file is passed in COMP_DIR, | |
9250 | and must not be NULL. | |
6e70227d | 9251 | |
aaa75496 JB |
9252 | 2. If PST is not NULL, this procedure reads the program to determine |
9253 | the list of files included by the unit represented by PST, and | |
9254 | builds all the associated partial symbol tables. In this case, | |
9255 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
9256 | is not used to compute the full name of the symtab, and therefore | |
9257 | omitting it when building the partial symtab does not introduce | |
9258 | the potential for inconsistency - a partial symtab and its associated | |
9259 | symbtab having a different fullname -). */ | |
debd256d | 9260 | |
c906108c | 9261 | static void |
debd256d | 9262 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 9263 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 9264 | { |
a8c50c1f | 9265 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 9266 | gdb_byte *line_end; |
a8c50c1f | 9267 | unsigned int bytes_read, extended_len; |
c906108c | 9268 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
9269 | CORE_ADDR baseaddr; |
9270 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 9271 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 9272 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 9273 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
9274 | |
9275 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 9276 | |
debd256d JB |
9277 | line_ptr = lh->statement_program_start; |
9278 | line_end = lh->statement_program_end; | |
c906108c SS |
9279 | |
9280 | /* Read the statement sequences until there's nothing left. */ | |
9281 | while (line_ptr < line_end) | |
9282 | { | |
9283 | /* state machine registers */ | |
9284 | CORE_ADDR address = 0; | |
9285 | unsigned int file = 1; | |
9286 | unsigned int line = 1; | |
9287 | unsigned int column = 0; | |
debd256d | 9288 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
9289 | int basic_block = 0; |
9290 | int end_sequence = 0; | |
fbf65064 | 9291 | CORE_ADDR addr; |
2dc7f7b3 | 9292 | unsigned char op_index = 0; |
c906108c | 9293 | |
aaa75496 | 9294 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 9295 | { |
aaa75496 | 9296 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
9297 | /* lh->include_dirs and lh->file_names are 0-based, but the |
9298 | directory and file name numbers in the statement program | |
9299 | are 1-based. */ | |
9300 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 9301 | char *dir = NULL; |
a738430d | 9302 | |
debd256d JB |
9303 | if (fe->dir_index) |
9304 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
9305 | |
9306 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
9307 | } |
9308 | ||
a738430d | 9309 | /* Decode the table. */ |
c5aa993b | 9310 | while (!end_sequence) |
c906108c SS |
9311 | { |
9312 | op_code = read_1_byte (abfd, line_ptr); | |
9313 | line_ptr += 1; | |
59205f5a JB |
9314 | if (line_ptr > line_end) |
9315 | { | |
9316 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
9317 | break; | |
9318 | } | |
9aa1fe7e | 9319 | |
debd256d | 9320 | if (op_code >= lh->opcode_base) |
6e70227d | 9321 | { |
a738430d | 9322 | /* Special operand. */ |
debd256d | 9323 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
9324 | address += (((op_index + (adj_opcode / lh->line_range)) |
9325 | / lh->maximum_ops_per_instruction) | |
9326 | * lh->minimum_instruction_length); | |
9327 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
9328 | % lh->maximum_ops_per_instruction); | |
debd256d | 9329 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 9330 | if (lh->num_file_names < file || file == 0) |
25e43795 | 9331 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
9332 | /* For now we ignore lines not starting on an |
9333 | instruction boundary. */ | |
9334 | else if (op_index == 0) | |
25e43795 DJ |
9335 | { |
9336 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 9337 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
9338 | { |
9339 | if (last_subfile != current_subfile) | |
9340 | { | |
9341 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9342 | if (last_subfile) | |
9343 | record_line (last_subfile, 0, addr); | |
9344 | last_subfile = current_subfile; | |
9345 | } | |
25e43795 | 9346 | /* Append row to matrix using current values. */ |
fbf65064 UW |
9347 | addr = check_cu_functions (address, cu); |
9348 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
9349 | record_line (current_subfile, line, addr); | |
366da635 | 9350 | } |
25e43795 | 9351 | } |
ca5f395d | 9352 | basic_block = 0; |
9aa1fe7e GK |
9353 | } |
9354 | else switch (op_code) | |
c906108c SS |
9355 | { |
9356 | case DW_LNS_extended_op: | |
a8c50c1f | 9357 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 9358 | line_ptr += bytes_read; |
a8c50c1f | 9359 | extended_end = line_ptr + extended_len; |
c906108c SS |
9360 | extended_op = read_1_byte (abfd, line_ptr); |
9361 | line_ptr += 1; | |
9362 | switch (extended_op) | |
9363 | { | |
9364 | case DW_LNE_end_sequence: | |
9365 | end_sequence = 1; | |
c906108c SS |
9366 | break; |
9367 | case DW_LNE_set_address: | |
e7c27a73 | 9368 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
2dc7f7b3 | 9369 | op_index = 0; |
107d2387 AC |
9370 | line_ptr += bytes_read; |
9371 | address += baseaddr; | |
c906108c SS |
9372 | break; |
9373 | case DW_LNE_define_file: | |
debd256d JB |
9374 | { |
9375 | char *cur_file; | |
9376 | unsigned int dir_index, mod_time, length; | |
6e70227d | 9377 | |
debd256d JB |
9378 | cur_file = read_string (abfd, line_ptr, &bytes_read); |
9379 | line_ptr += bytes_read; | |
9380 | dir_index = | |
9381 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9382 | line_ptr += bytes_read; | |
9383 | mod_time = | |
9384 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9385 | line_ptr += bytes_read; | |
9386 | length = | |
9387 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9388 | line_ptr += bytes_read; | |
9389 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9390 | } | |
c906108c | 9391 | break; |
d0c6ba3d CC |
9392 | case DW_LNE_set_discriminator: |
9393 | /* The discriminator is not interesting to the debugger; | |
9394 | just ignore it. */ | |
9395 | line_ptr = extended_end; | |
9396 | break; | |
c906108c | 9397 | default: |
4d3c2250 | 9398 | complaint (&symfile_complaints, |
e2e0b3e5 | 9399 | _("mangled .debug_line section")); |
debd256d | 9400 | return; |
c906108c | 9401 | } |
a8c50c1f DJ |
9402 | /* Make sure that we parsed the extended op correctly. If e.g. |
9403 | we expected a different address size than the producer used, | |
9404 | we may have read the wrong number of bytes. */ | |
9405 | if (line_ptr != extended_end) | |
9406 | { | |
9407 | complaint (&symfile_complaints, | |
9408 | _("mangled .debug_line section")); | |
9409 | return; | |
9410 | } | |
c906108c SS |
9411 | break; |
9412 | case DW_LNS_copy: | |
59205f5a | 9413 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
9414 | dwarf2_debug_line_missing_file_complaint (); |
9415 | else | |
366da635 | 9416 | { |
25e43795 | 9417 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 9418 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
9419 | { |
9420 | if (last_subfile != current_subfile) | |
9421 | { | |
9422 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9423 | if (last_subfile) | |
9424 | record_line (last_subfile, 0, addr); | |
9425 | last_subfile = current_subfile; | |
9426 | } | |
9427 | addr = check_cu_functions (address, cu); | |
9428 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
9429 | record_line (current_subfile, line, addr); | |
9430 | } | |
366da635 | 9431 | } |
c906108c SS |
9432 | basic_block = 0; |
9433 | break; | |
9434 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
9435 | { |
9436 | CORE_ADDR adjust | |
9437 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9438 | ||
9439 | address += (((op_index + adjust) | |
9440 | / lh->maximum_ops_per_instruction) | |
9441 | * lh->minimum_instruction_length); | |
9442 | op_index = ((op_index + adjust) | |
9443 | % lh->maximum_ops_per_instruction); | |
9444 | line_ptr += bytes_read; | |
9445 | } | |
c906108c SS |
9446 | break; |
9447 | case DW_LNS_advance_line: | |
9448 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
9449 | line_ptr += bytes_read; | |
9450 | break; | |
9451 | case DW_LNS_set_file: | |
debd256d | 9452 | { |
a738430d MK |
9453 | /* The arrays lh->include_dirs and lh->file_names are |
9454 | 0-based, but the directory and file name numbers in | |
9455 | the statement program are 1-based. */ | |
debd256d | 9456 | struct file_entry *fe; |
4f1520fb | 9457 | char *dir = NULL; |
a738430d | 9458 | |
debd256d JB |
9459 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
9460 | line_ptr += bytes_read; | |
59205f5a | 9461 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
9462 | dwarf2_debug_line_missing_file_complaint (); |
9463 | else | |
9464 | { | |
9465 | fe = &lh->file_names[file - 1]; | |
9466 | if (fe->dir_index) | |
9467 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9468 | if (!decode_for_pst_p) | |
9469 | { | |
9470 | last_subfile = current_subfile; | |
9471 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
9472 | } | |
9473 | } | |
debd256d | 9474 | } |
c906108c SS |
9475 | break; |
9476 | case DW_LNS_set_column: | |
9477 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9478 | line_ptr += bytes_read; | |
9479 | break; | |
9480 | case DW_LNS_negate_stmt: | |
9481 | is_stmt = (!is_stmt); | |
9482 | break; | |
9483 | case DW_LNS_set_basic_block: | |
9484 | basic_block = 1; | |
9485 | break; | |
c2c6d25f JM |
9486 | /* Add to the address register of the state machine the |
9487 | address increment value corresponding to special opcode | |
a738430d MK |
9488 | 255. I.e., this value is scaled by the minimum |
9489 | instruction length since special opcode 255 would have | |
9490 | scaled the the increment. */ | |
c906108c | 9491 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
9492 | { |
9493 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
9494 | ||
9495 | address += (((op_index + adjust) | |
9496 | / lh->maximum_ops_per_instruction) | |
9497 | * lh->minimum_instruction_length); | |
9498 | op_index = ((op_index + adjust) | |
9499 | % lh->maximum_ops_per_instruction); | |
9500 | } | |
c906108c SS |
9501 | break; |
9502 | case DW_LNS_fixed_advance_pc: | |
9503 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 9504 | op_index = 0; |
c906108c SS |
9505 | line_ptr += 2; |
9506 | break; | |
9aa1fe7e | 9507 | default: |
a738430d MK |
9508 | { |
9509 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 9510 | int i; |
a738430d | 9511 | |
debd256d | 9512 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
9513 | { |
9514 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9515 | line_ptr += bytes_read; | |
9516 | } | |
9517 | } | |
c906108c SS |
9518 | } |
9519 | } | |
59205f5a JB |
9520 | if (lh->num_file_names < file || file == 0) |
9521 | dwarf2_debug_line_missing_file_complaint (); | |
9522 | else | |
9523 | { | |
9524 | lh->file_names[file - 1].included_p = 1; | |
9525 | if (!decode_for_pst_p) | |
fbf65064 UW |
9526 | { |
9527 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9528 | record_line (current_subfile, 0, addr); | |
9529 | } | |
59205f5a | 9530 | } |
c906108c | 9531 | } |
aaa75496 JB |
9532 | |
9533 | if (decode_for_pst_p) | |
9534 | { | |
9535 | int file_index; | |
9536 | ||
9537 | /* Now that we're done scanning the Line Header Program, we can | |
9538 | create the psymtab of each included file. */ | |
9539 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
9540 | if (lh->file_names[file_index].included_p == 1) | |
9541 | { | |
5b5464ad JB |
9542 | const struct file_entry fe = lh->file_names [file_index]; |
9543 | char *include_name = fe.name; | |
9544 | char *dir_name = NULL; | |
9545 | char *pst_filename = pst->filename; | |
9546 | ||
9547 | if (fe.dir_index) | |
9548 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
9549 | ||
9550 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
9551 | { | |
1754f103 MK |
9552 | include_name = concat (dir_name, SLASH_STRING, |
9553 | include_name, (char *)NULL); | |
5b5464ad JB |
9554 | make_cleanup (xfree, include_name); |
9555 | } | |
9556 | ||
9557 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
9558 | { | |
1754f103 MK |
9559 | pst_filename = concat (pst->dirname, SLASH_STRING, |
9560 | pst_filename, (char *)NULL); | |
5b5464ad JB |
9561 | make_cleanup (xfree, pst_filename); |
9562 | } | |
9563 | ||
9564 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
9565 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
9566 | } | |
9567 | } | |
cb1df416 DJ |
9568 | else |
9569 | { | |
9570 | /* Make sure a symtab is created for every file, even files | |
9571 | which contain only variables (i.e. no code with associated | |
9572 | line numbers). */ | |
9573 | ||
9574 | int i; | |
9575 | struct file_entry *fe; | |
9576 | ||
9577 | for (i = 0; i < lh->num_file_names; i++) | |
9578 | { | |
9579 | char *dir = NULL; | |
9a619af0 | 9580 | |
cb1df416 DJ |
9581 | fe = &lh->file_names[i]; |
9582 | if (fe->dir_index) | |
9583 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9584 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
9585 | ||
9586 | /* Skip the main file; we don't need it, and it must be | |
9587 | allocated last, so that it will show up before the | |
9588 | non-primary symtabs in the objfile's symtab list. */ | |
9589 | if (current_subfile == first_subfile) | |
9590 | continue; | |
9591 | ||
9592 | if (current_subfile->symtab == NULL) | |
9593 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
9594 | cu->objfile); | |
9595 | fe->symtab = current_subfile->symtab; | |
9596 | } | |
9597 | } | |
c906108c SS |
9598 | } |
9599 | ||
9600 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
9601 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
9602 | or NULL if not known. COMP_DIR is the compilation directory for the |
9603 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
9604 | This routine tries to keep line numbers from identical absolute and |
9605 | relative file names in a common subfile. | |
9606 | ||
9607 | Using the `list' example from the GDB testsuite, which resides in | |
9608 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
9609 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
9610 | ||
c5aa993b JM |
9611 | DW_AT_name: /srcdir/list0.c |
9612 | DW_AT_comp_dir: /compdir | |
357e46e7 | 9613 | files.files[0].name: list0.h |
c5aa993b | 9614 | files.files[0].dir: /srcdir |
357e46e7 | 9615 | files.files[1].name: list0.c |
c5aa993b | 9616 | files.files[1].dir: /srcdir |
c906108c SS |
9617 | |
9618 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
9619 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
9620 | start_subfile will ensure that this happens provided that we pass the | |
9621 | concatenation of files.files[1].dir and files.files[1].name as the | |
9622 | subfile's name. */ | |
c906108c SS |
9623 | |
9624 | static void | |
4f1520fb | 9625 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 9626 | { |
4f1520fb FR |
9627 | char *fullname; |
9628 | ||
9629 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
9630 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
9631 | second argument to start_subfile. To be consistent, we do the | |
9632 | same here. In order not to lose the line information directory, | |
9633 | we concatenate it to the filename when it makes sense. | |
9634 | Note that the Dwarf3 standard says (speaking of filenames in line | |
9635 | information): ``The directory index is ignored for file names | |
9636 | that represent full path names''. Thus ignoring dirname in the | |
9637 | `else' branch below isn't an issue. */ | |
c906108c | 9638 | |
d5166ae1 | 9639 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
9640 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
9641 | else | |
9642 | fullname = filename; | |
c906108c | 9643 | |
4f1520fb FR |
9644 | start_subfile (fullname, comp_dir); |
9645 | ||
9646 | if (fullname != filename) | |
9647 | xfree (fullname); | |
c906108c SS |
9648 | } |
9649 | ||
4c2df51b DJ |
9650 | static void |
9651 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9652 | struct dwarf2_cu *cu) |
4c2df51b | 9653 | { |
e7c27a73 DJ |
9654 | struct objfile *objfile = cu->objfile; |
9655 | struct comp_unit_head *cu_header = &cu->header; | |
9656 | ||
4c2df51b DJ |
9657 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
9658 | code here to turn a symbol with DW_AT_external and a | |
9659 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
9660 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
9661 | with some versions of binutils) where shared libraries could have | |
9662 | relocations against symbols in their debug information - the | |
9663 | minimal symbol would have the right address, but the debug info | |
9664 | would not. It's no longer necessary, because we will explicitly | |
9665 | apply relocations when we read in the debug information now. */ | |
9666 | ||
9667 | /* A DW_AT_location attribute with no contents indicates that a | |
9668 | variable has been optimized away. */ | |
9669 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
9670 | { | |
9671 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
9672 | return; | |
9673 | } | |
9674 | ||
9675 | /* Handle one degenerate form of location expression specially, to | |
9676 | preserve GDB's previous behavior when section offsets are | |
9677 | specified. If this is just a DW_OP_addr then mark this symbol | |
9678 | as LOC_STATIC. */ | |
9679 | ||
9680 | if (attr_form_is_block (attr) | |
9681 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
9682 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
9683 | { | |
891d2f0b | 9684 | unsigned int dummy; |
4c2df51b DJ |
9685 | |
9686 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 9687 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 9688 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
9689 | fixup_symbol_section (sym, objfile); |
9690 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
9691 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
9692 | return; |
9693 | } | |
9694 | ||
9695 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
9696 | expression evaluator, and use LOC_COMPUTED only when necessary | |
9697 | (i.e. when the value of a register or memory location is | |
9698 | referenced, or a thread-local block, etc.). Then again, it might | |
9699 | not be worthwhile. I'm assuming that it isn't unless performance | |
9700 | or memory numbers show me otherwise. */ | |
9701 | ||
e7c27a73 | 9702 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
9703 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
9704 | } | |
9705 | ||
c906108c SS |
9706 | /* Given a pointer to a DWARF information entry, figure out if we need |
9707 | to make a symbol table entry for it, and if so, create a new entry | |
9708 | and return a pointer to it. | |
9709 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 9710 | used the passed type. */ |
c906108c SS |
9711 | |
9712 | static struct symbol * | |
e7c27a73 | 9713 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 9714 | { |
e7c27a73 | 9715 | struct objfile *objfile = cu->objfile; |
c906108c SS |
9716 | struct symbol *sym = NULL; |
9717 | char *name; | |
9718 | struct attribute *attr = NULL; | |
9719 | struct attribute *attr2 = NULL; | |
e142c38c | 9720 | CORE_ADDR baseaddr; |
edb3359d | 9721 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
9722 | |
9723 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 9724 | |
94af9270 | 9725 | name = dwarf2_name (die, cu); |
c906108c SS |
9726 | if (name) |
9727 | { | |
94af9270 KS |
9728 | const char *linkagename; |
9729 | ||
4a146b47 | 9730 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
9731 | sizeof (struct symbol)); |
9732 | OBJSTAT (objfile, n_syms++); | |
9733 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
9734 | |
9735 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 9736 | SYMBOL_LANGUAGE (sym) = cu->language; |
94af9270 KS |
9737 | linkagename = dwarf2_physname (name, die, cu); |
9738 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 9739 | |
f55ee35c JK |
9740 | /* Fortran does not have mangling standard and the mangling does differ |
9741 | between gfortran, iFort etc. */ | |
9742 | if (cu->language == language_fortran | |
b250c185 | 9743 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
9744 | symbol_set_demangled_name (&(sym->ginfo), |
9745 | (char *) dwarf2_full_name (name, die, cu), | |
9746 | NULL); | |
f55ee35c | 9747 | |
c906108c | 9748 | /* Default assumptions. |
c5aa993b | 9749 | Use the passed type or decode it from the die. */ |
176620f1 | 9750 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 9751 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
9752 | if (type != NULL) |
9753 | SYMBOL_TYPE (sym) = type; | |
9754 | else | |
e7c27a73 | 9755 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
9756 | attr = dwarf2_attr (die, |
9757 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
9758 | cu); | |
c906108c SS |
9759 | if (attr) |
9760 | { | |
9761 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
9762 | } | |
cb1df416 | 9763 | |
edb3359d DJ |
9764 | attr = dwarf2_attr (die, |
9765 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
9766 | cu); | |
cb1df416 DJ |
9767 | if (attr) |
9768 | { | |
9769 | int file_index = DW_UNSND (attr); | |
9a619af0 | 9770 | |
cb1df416 DJ |
9771 | if (cu->line_header == NULL |
9772 | || file_index > cu->line_header->num_file_names) | |
9773 | complaint (&symfile_complaints, | |
9774 | _("file index out of range")); | |
1c3d648d | 9775 | else if (file_index > 0) |
cb1df416 DJ |
9776 | { |
9777 | struct file_entry *fe; | |
9a619af0 | 9778 | |
cb1df416 DJ |
9779 | fe = &cu->line_header->file_names[file_index - 1]; |
9780 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
9781 | } | |
9782 | } | |
9783 | ||
c906108c SS |
9784 | switch (die->tag) |
9785 | { | |
9786 | case DW_TAG_label: | |
e142c38c | 9787 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
9788 | if (attr) |
9789 | { | |
9790 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
9791 | } | |
0f5238ed TT |
9792 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
9793 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 9794 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 9795 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9796 | break; |
9797 | case DW_TAG_subprogram: | |
9798 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
9799 | finish_block. */ | |
9800 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 9801 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
9802 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
9803 | || cu->language == language_ada) | |
c906108c | 9804 | { |
2cfa0c8d JB |
9805 | /* Subprograms marked external are stored as a global symbol. |
9806 | Ada subprograms, whether marked external or not, are always | |
9807 | stored as a global symbol, because we want to be able to | |
9808 | access them globally. For instance, we want to be able | |
9809 | to break on a nested subprogram without having to | |
9810 | specify the context. */ | |
c906108c SS |
9811 | add_symbol_to_list (sym, &global_symbols); |
9812 | } | |
9813 | else | |
9814 | { | |
e142c38c | 9815 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9816 | } |
9817 | break; | |
edb3359d DJ |
9818 | case DW_TAG_inlined_subroutine: |
9819 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
9820 | finish_block. */ | |
9821 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
9822 | SYMBOL_INLINED (sym) = 1; | |
9823 | /* Do not add the symbol to any lists. It will be found via | |
9824 | BLOCK_FUNCTION from the blockvector. */ | |
9825 | break; | |
c906108c | 9826 | case DW_TAG_variable: |
254e6b9e | 9827 | case DW_TAG_member: |
c906108c SS |
9828 | /* Compilation with minimal debug info may result in variables |
9829 | with missing type entries. Change the misleading `void' type | |
9830 | to something sensible. */ | |
9831 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 9832 | SYMBOL_TYPE (sym) |
46bf5051 | 9833 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 9834 | |
e142c38c | 9835 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
9836 | /* In the case of DW_TAG_member, we should only be called for |
9837 | static const members. */ | |
9838 | if (die->tag == DW_TAG_member) | |
9839 | { | |
3863f96c DE |
9840 | /* dwarf2_add_field uses die_is_declaration, |
9841 | so we do the same. */ | |
254e6b9e DE |
9842 | gdb_assert (die_is_declaration (die, cu)); |
9843 | gdb_assert (attr); | |
9844 | } | |
c906108c SS |
9845 | if (attr) |
9846 | { | |
e7c27a73 | 9847 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 9848 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
9849 | if (attr2 && (DW_UNSND (attr2) != 0)) |
9850 | add_symbol_to_list (sym, &global_symbols); | |
9851 | else | |
e142c38c | 9852 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9853 | break; |
9854 | } | |
e142c38c | 9855 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9856 | if (attr) |
9857 | { | |
e7c27a73 | 9858 | var_decode_location (attr, sym, cu); |
e142c38c | 9859 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 9860 | if (attr2 && (DW_UNSND (attr2) != 0)) |
1c809c68 TT |
9861 | { |
9862 | struct pending **list_to_add; | |
9863 | ||
f55ee35c JK |
9864 | /* Workaround gfortran PR debug/40040 - it uses |
9865 | DW_AT_location for variables in -fPIC libraries which may | |
9866 | get overriden by other libraries/executable and get | |
9867 | a different address. Resolve it by the minimal symbol | |
9868 | which may come from inferior's executable using copy | |
9869 | relocation. Make this workaround only for gfortran as for | |
9870 | other compilers GDB cannot guess the minimal symbol | |
9871 | Fortran mangling kind. */ | |
9872 | if (cu->language == language_fortran && die->parent | |
9873 | && die->parent->tag == DW_TAG_module | |
9874 | && cu->producer | |
9875 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
9876 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
9877 | ||
1c809c68 TT |
9878 | /* A variable with DW_AT_external is never static, |
9879 | but it may be block-scoped. */ | |
9880 | list_to_add = (cu->list_in_scope == &file_symbols | |
9881 | ? &global_symbols : cu->list_in_scope); | |
9882 | add_symbol_to_list (sym, list_to_add); | |
9883 | } | |
c906108c | 9884 | else |
e142c38c | 9885 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9886 | } |
9887 | else | |
9888 | { | |
9889 | /* We do not know the address of this symbol. | |
c5aa993b JM |
9890 | If it is an external symbol and we have type information |
9891 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
9892 | The address of the variable will then be determined from | |
9893 | the minimal symbol table whenever the variable is | |
9894 | referenced. */ | |
e142c38c | 9895 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 9896 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 9897 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 9898 | { |
0fe7935b DJ |
9899 | struct pending **list_to_add; |
9900 | ||
9901 | /* A variable with DW_AT_external is never static, but it | |
9902 | may be block-scoped. */ | |
9903 | list_to_add = (cu->list_in_scope == &file_symbols | |
9904 | ? &global_symbols : cu->list_in_scope); | |
9905 | ||
c906108c | 9906 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 9907 | add_symbol_to_list (sym, list_to_add); |
c906108c | 9908 | } |
442ddf59 JK |
9909 | else if (!die_is_declaration (die, cu)) |
9910 | { | |
9911 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
9912 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
9913 | add_symbol_to_list (sym, cu->list_in_scope); | |
9914 | } | |
c906108c SS |
9915 | } |
9916 | break; | |
9917 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
9918 | /* If we are inside a function, mark this as an argument. If |
9919 | not, we might be looking at an argument to an inlined function | |
9920 | when we do not have enough information to show inlined frames; | |
9921 | pretend it's a local variable in that case so that the user can | |
9922 | still see it. */ | |
9923 | if (context_stack_depth > 0 | |
9924 | && context_stack[context_stack_depth - 1].name != NULL) | |
9925 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 9926 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9927 | if (attr) |
9928 | { | |
e7c27a73 | 9929 | var_decode_location (attr, sym, cu); |
c906108c | 9930 | } |
e142c38c | 9931 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
9932 | if (attr) |
9933 | { | |
e7c27a73 | 9934 | dwarf2_const_value (attr, sym, cu); |
c906108c | 9935 | } |
f346a30d PM |
9936 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
9937 | if (attr && DW_UNSND (attr)) | |
9938 | { | |
9939 | struct type *ref_type; | |
9940 | ||
9941 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
9942 | SYMBOL_TYPE (sym) = ref_type; | |
9943 | } | |
9944 | ||
e142c38c | 9945 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9946 | break; |
9947 | case DW_TAG_unspecified_parameters: | |
9948 | /* From varargs functions; gdb doesn't seem to have any | |
9949 | interest in this information, so just ignore it for now. | |
9950 | (FIXME?) */ | |
9951 | break; | |
9952 | case DW_TAG_class_type: | |
680b30c7 | 9953 | case DW_TAG_interface_type: |
c906108c SS |
9954 | case DW_TAG_structure_type: |
9955 | case DW_TAG_union_type: | |
72019c9c | 9956 | case DW_TAG_set_type: |
c906108c SS |
9957 | case DW_TAG_enumeration_type: |
9958 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 9959 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 9960 | |
63d06c5c | 9961 | { |
987504bb | 9962 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
9963 | really ever be static objects: otherwise, if you try |
9964 | to, say, break of a class's method and you're in a file | |
9965 | which doesn't mention that class, it won't work unless | |
9966 | the check for all static symbols in lookup_symbol_aux | |
9967 | saves you. See the OtherFileClass tests in | |
9968 | gdb.c++/namespace.exp. */ | |
9969 | ||
9970 | struct pending **list_to_add; | |
9971 | ||
e142c38c | 9972 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
9973 | && (cu->language == language_cplus |
9974 | || cu->language == language_java) | |
e142c38c | 9975 | ? &global_symbols : cu->list_in_scope); |
6e70227d | 9976 | |
63d06c5c DC |
9977 | add_symbol_to_list (sym, list_to_add); |
9978 | ||
9979 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 9980 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 9981 | defines a typedef for the class. */ |
987504bb | 9982 | if (cu->language == language_cplus |
8c6860bb JB |
9983 | || cu->language == language_java |
9984 | || cu->language == language_ada) | |
63d06c5c | 9985 | { |
d8151005 DJ |
9986 | /* The symbol's name is already allocated along with |
9987 | this objfile, so we don't need to duplicate it for | |
9988 | the type. */ | |
63d06c5c | 9989 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 9990 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
9991 | } |
9992 | } | |
c906108c SS |
9993 | break; |
9994 | case DW_TAG_typedef: | |
63d06c5c DC |
9995 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
9996 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 9997 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 9998 | break; |
c906108c | 9999 | case DW_TAG_base_type: |
a02abb62 | 10000 | case DW_TAG_subrange_type: |
c906108c | 10001 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 10002 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 10003 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
10004 | break; |
10005 | case DW_TAG_enumerator: | |
e142c38c | 10006 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10007 | if (attr) |
10008 | { | |
e7c27a73 | 10009 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10010 | } |
63d06c5c DC |
10011 | { |
10012 | /* NOTE: carlton/2003-11-10: See comment above in the | |
10013 | DW_TAG_class_type, etc. block. */ | |
10014 | ||
10015 | struct pending **list_to_add; | |
10016 | ||
e142c38c | 10017 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
10018 | && (cu->language == language_cplus |
10019 | || cu->language == language_java) | |
e142c38c | 10020 | ? &global_symbols : cu->list_in_scope); |
6e70227d | 10021 | |
63d06c5c DC |
10022 | add_symbol_to_list (sym, list_to_add); |
10023 | } | |
c906108c | 10024 | break; |
5c4e30ca DC |
10025 | case DW_TAG_namespace: |
10026 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
10027 | add_symbol_to_list (sym, &global_symbols); | |
10028 | break; | |
c906108c SS |
10029 | default: |
10030 | /* Not a tag we recognize. Hopefully we aren't processing | |
10031 | trash data, but since we must specifically ignore things | |
10032 | we don't recognize, there is nothing else we should do at | |
10033 | this point. */ | |
e2e0b3e5 | 10034 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 10035 | dwarf_tag_name (die->tag)); |
c906108c SS |
10036 | break; |
10037 | } | |
df8a16a1 DJ |
10038 | |
10039 | /* For the benefit of old versions of GCC, check for anonymous | |
10040 | namespaces based on the demangled name. */ | |
10041 | if (!processing_has_namespace_info | |
94af9270 | 10042 | && cu->language == language_cplus) |
df8a16a1 | 10043 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
10044 | } |
10045 | return (sym); | |
10046 | } | |
10047 | ||
10048 | /* Copy constant value from an attribute to a symbol. */ | |
10049 | ||
10050 | static void | |
107d2387 | 10051 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 10052 | struct dwarf2_cu *cu) |
c906108c | 10053 | { |
e7c27a73 DJ |
10054 | struct objfile *objfile = cu->objfile; |
10055 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
10056 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
10057 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
10058 | struct dwarf_block *blk; |
10059 | ||
10060 | switch (attr->form) | |
10061 | { | |
10062 | case DW_FORM_addr: | |
ac56253d TT |
10063 | { |
10064 | struct dwarf2_locexpr_baton *baton; | |
10065 | gdb_byte *data; | |
10066 | ||
10067 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) | |
10068 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), | |
10069 | cu_header->addr_size, | |
10070 | TYPE_LENGTH (SYMBOL_TYPE | |
10071 | (sym))); | |
10072 | /* Symbols of this form are reasonably rare, so we just | |
10073 | piggyback on the existing location code rather than writing | |
10074 | a new implementation of symbol_computed_ops. */ | |
10075 | baton = obstack_alloc (&objfile->objfile_obstack, | |
10076 | sizeof (struct dwarf2_locexpr_baton)); | |
10077 | baton->per_cu = cu->per_cu; | |
10078 | gdb_assert (baton->per_cu); | |
10079 | ||
10080 | baton->size = 2 + cu_header->addr_size; | |
10081 | data = obstack_alloc (&objfile->objfile_obstack, baton->size); | |
10082 | baton->data = data; | |
10083 | ||
10084 | data[0] = DW_OP_addr; | |
10085 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
10086 | byte_order, DW_ADDR (attr)); | |
10087 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
10088 | ||
10089 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
10090 | SYMBOL_LOCATION_BATON (sym) = baton; | |
10091 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
10092 | } | |
c906108c | 10093 | break; |
4ac36638 | 10094 | case DW_FORM_string: |
93b5768b PA |
10095 | case DW_FORM_strp: |
10096 | /* DW_STRING is already allocated on the obstack, point directly | |
10097 | to it. */ | |
10098 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
10099 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
10100 | break; | |
c906108c SS |
10101 | case DW_FORM_block1: |
10102 | case DW_FORM_block2: | |
10103 | case DW_FORM_block4: | |
10104 | case DW_FORM_block: | |
2dc7f7b3 | 10105 | case DW_FORM_exprloc: |
c906108c SS |
10106 | blk = DW_BLOCK (attr); |
10107 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 10108 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
10109 | blk->size, |
10110 | TYPE_LENGTH (SYMBOL_TYPE | |
10111 | (sym))); | |
4e38b386 | 10112 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 10113 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
10114 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
10115 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
10116 | break; | |
2df3850c JM |
10117 | |
10118 | /* The DW_AT_const_value attributes are supposed to carry the | |
10119 | symbol's value "represented as it would be on the target | |
10120 | architecture." By the time we get here, it's already been | |
10121 | converted to host endianness, so we just need to sign- or | |
10122 | zero-extend it as appropriate. */ | |
10123 | case DW_FORM_data1: | |
10124 | dwarf2_const_value_data (attr, sym, 8); | |
10125 | break; | |
c906108c | 10126 | case DW_FORM_data2: |
2df3850c JM |
10127 | dwarf2_const_value_data (attr, sym, 16); |
10128 | break; | |
c906108c | 10129 | case DW_FORM_data4: |
2df3850c JM |
10130 | dwarf2_const_value_data (attr, sym, 32); |
10131 | break; | |
c906108c | 10132 | case DW_FORM_data8: |
2df3850c JM |
10133 | dwarf2_const_value_data (attr, sym, 64); |
10134 | break; | |
10135 | ||
c906108c | 10136 | case DW_FORM_sdata: |
2df3850c JM |
10137 | SYMBOL_VALUE (sym) = DW_SND (attr); |
10138 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10139 | break; | |
10140 | ||
c906108c SS |
10141 | case DW_FORM_udata: |
10142 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
10143 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10144 | break; | |
2df3850c | 10145 | |
c906108c | 10146 | default: |
4d3c2250 | 10147 | complaint (&symfile_complaints, |
e2e0b3e5 | 10148 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 10149 | dwarf_form_name (attr->form)); |
c906108c SS |
10150 | SYMBOL_VALUE (sym) = 0; |
10151 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10152 | break; | |
10153 | } | |
10154 | } | |
10155 | ||
2df3850c JM |
10156 | |
10157 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
10158 | or zero-extend it as appropriate for the symbol's type. */ | |
10159 | static void | |
10160 | dwarf2_const_value_data (struct attribute *attr, | |
10161 | struct symbol *sym, | |
10162 | int bits) | |
10163 | { | |
10164 | LONGEST l = DW_UNSND (attr); | |
10165 | ||
10166 | if (bits < sizeof (l) * 8) | |
10167 | { | |
10168 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
10169 | l &= ((LONGEST) 1 << bits) - 1; | |
10170 | else | |
bf9198f1 | 10171 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
10172 | } |
10173 | ||
10174 | SYMBOL_VALUE (sym) = l; | |
10175 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10176 | } | |
10177 | ||
10178 | ||
c906108c SS |
10179 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
10180 | ||
10181 | static struct type * | |
e7c27a73 | 10182 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10183 | { |
c906108c SS |
10184 | struct attribute *type_attr; |
10185 | struct die_info *type_die; | |
c906108c | 10186 | |
e142c38c | 10187 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
10188 | if (!type_attr) |
10189 | { | |
10190 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 10191 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 10192 | } |
348e048f DE |
10193 | |
10194 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 10195 | |
33ac96f0 | 10196 | return tag_type_to_type (type_die, cu); |
c906108c SS |
10197 | } |
10198 | ||
b4ba55a1 JB |
10199 | /* True iff CU's producer generates GNAT Ada auxiliary information |
10200 | that allows to find parallel types through that information instead | |
10201 | of having to do expensive parallel lookups by type name. */ | |
10202 | ||
10203 | static int | |
10204 | need_gnat_info (struct dwarf2_cu *cu) | |
10205 | { | |
10206 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
10207 | of GNAT produces this auxiliary information, without any indication | |
10208 | that it is produced. Part of enhancing the FSF version of GNAT | |
10209 | to produce that information will be to put in place an indicator | |
10210 | that we can use in order to determine whether the descriptive type | |
10211 | info is available or not. One suggestion that has been made is | |
10212 | to use a new attribute, attached to the CU die. For now, assume | |
10213 | that the descriptive type info is not available. */ | |
10214 | return 0; | |
10215 | } | |
10216 | ||
10217 | ||
10218 | /* Return the auxiliary type of the die in question using its | |
10219 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
10220 | attribute is not present. */ | |
10221 | ||
10222 | static struct type * | |
10223 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
10224 | { | |
b4ba55a1 JB |
10225 | struct attribute *type_attr; |
10226 | struct die_info *type_die; | |
10227 | ||
10228 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
10229 | if (!type_attr) | |
10230 | return NULL; | |
10231 | ||
10232 | type_die = follow_die_ref (die, type_attr, &cu); | |
33ac96f0 | 10233 | return tag_type_to_type (type_die, cu); |
b4ba55a1 JB |
10234 | } |
10235 | ||
10236 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
10237 | descriptive type accordingly. */ | |
10238 | ||
10239 | static void | |
10240 | set_descriptive_type (struct type *type, struct die_info *die, | |
10241 | struct dwarf2_cu *cu) | |
10242 | { | |
10243 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
10244 | ||
10245 | if (descriptive_type) | |
10246 | { | |
10247 | ALLOCATE_GNAT_AUX_TYPE (type); | |
10248 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
10249 | } | |
10250 | } | |
10251 | ||
c906108c SS |
10252 | /* Return the containing type of the die in question using its |
10253 | DW_AT_containing_type attribute. */ | |
10254 | ||
10255 | static struct type * | |
e7c27a73 | 10256 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10257 | { |
c906108c | 10258 | struct attribute *type_attr; |
33ac96f0 | 10259 | struct die_info *type_die; |
c906108c | 10260 | |
e142c38c | 10261 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
10262 | if (!type_attr) |
10263 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
10264 | "[in module %s]"), cu->objfile->name); | |
10265 | ||
10266 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10267 | return tag_type_to_type (type_die, cu); | |
c906108c SS |
10268 | } |
10269 | ||
c906108c | 10270 | static struct type * |
e7c27a73 | 10271 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10272 | { |
f792889a DJ |
10273 | struct type *this_type; |
10274 | ||
10275 | this_type = read_type_die (die, cu); | |
10276 | if (!this_type) | |
c906108c | 10277 | { |
b00fdb78 TT |
10278 | char *message, *saved; |
10279 | ||
10280 | /* read_type_die already issued a complaint. */ | |
10281 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
10282 | cu->objfile->name, | |
10283 | cu->header.offset, | |
10284 | die->offset); | |
10285 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
10286 | message, strlen (message)); | |
10287 | xfree (message); | |
10288 | ||
10289 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 10290 | } |
f792889a | 10291 | return this_type; |
c906108c SS |
10292 | } |
10293 | ||
f792889a | 10294 | static struct type * |
e7c27a73 | 10295 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10296 | { |
f792889a DJ |
10297 | struct type *this_type; |
10298 | ||
10299 | this_type = get_die_type (die, cu); | |
10300 | if (this_type) | |
10301 | return this_type; | |
10302 | ||
c906108c SS |
10303 | switch (die->tag) |
10304 | { | |
10305 | case DW_TAG_class_type: | |
680b30c7 | 10306 | case DW_TAG_interface_type: |
c906108c SS |
10307 | case DW_TAG_structure_type: |
10308 | case DW_TAG_union_type: | |
f792889a | 10309 | this_type = read_structure_type (die, cu); |
c906108c SS |
10310 | break; |
10311 | case DW_TAG_enumeration_type: | |
f792889a | 10312 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
10313 | break; |
10314 | case DW_TAG_subprogram: | |
10315 | case DW_TAG_subroutine_type: | |
edb3359d | 10316 | case DW_TAG_inlined_subroutine: |
f792889a | 10317 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
10318 | break; |
10319 | case DW_TAG_array_type: | |
f792889a | 10320 | this_type = read_array_type (die, cu); |
c906108c | 10321 | break; |
72019c9c | 10322 | case DW_TAG_set_type: |
f792889a | 10323 | this_type = read_set_type (die, cu); |
72019c9c | 10324 | break; |
c906108c | 10325 | case DW_TAG_pointer_type: |
f792889a | 10326 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
10327 | break; |
10328 | case DW_TAG_ptr_to_member_type: | |
f792889a | 10329 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
10330 | break; |
10331 | case DW_TAG_reference_type: | |
f792889a | 10332 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
10333 | break; |
10334 | case DW_TAG_const_type: | |
f792889a | 10335 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
10336 | break; |
10337 | case DW_TAG_volatile_type: | |
f792889a | 10338 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
10339 | break; |
10340 | case DW_TAG_string_type: | |
f792889a | 10341 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
10342 | break; |
10343 | case DW_TAG_typedef: | |
f792889a | 10344 | this_type = read_typedef (die, cu); |
c906108c | 10345 | break; |
a02abb62 | 10346 | case DW_TAG_subrange_type: |
f792889a | 10347 | this_type = read_subrange_type (die, cu); |
a02abb62 | 10348 | break; |
c906108c | 10349 | case DW_TAG_base_type: |
f792889a | 10350 | this_type = read_base_type (die, cu); |
c906108c | 10351 | break; |
81a17f79 | 10352 | case DW_TAG_unspecified_type: |
f792889a | 10353 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 10354 | break; |
0114d602 DJ |
10355 | case DW_TAG_namespace: |
10356 | this_type = read_namespace_type (die, cu); | |
10357 | break; | |
f55ee35c JK |
10358 | case DW_TAG_module: |
10359 | this_type = read_module_type (die, cu); | |
10360 | break; | |
c906108c | 10361 | default: |
a1f5b845 | 10362 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 10363 | dwarf_tag_name (die->tag)); |
c906108c SS |
10364 | break; |
10365 | } | |
63d06c5c | 10366 | |
f792889a | 10367 | return this_type; |
63d06c5c DC |
10368 | } |
10369 | ||
fdde2d81 | 10370 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 10371 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 10372 | |
0114d602 DJ |
10373 | For example, if we're within the method foo() in the following |
10374 | code: | |
10375 | ||
10376 | namespace N { | |
10377 | class C { | |
10378 | void foo () { | |
10379 | } | |
10380 | }; | |
10381 | } | |
10382 | ||
10383 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
10384 | |
10385 | static char * | |
e142c38c | 10386 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 10387 | { |
0114d602 DJ |
10388 | struct die_info *parent, *spec_die; |
10389 | struct dwarf2_cu *spec_cu; | |
10390 | struct type *parent_type; | |
63d06c5c | 10391 | |
f55ee35c JK |
10392 | if (cu->language != language_cplus && cu->language != language_java |
10393 | && cu->language != language_fortran) | |
0114d602 DJ |
10394 | return ""; |
10395 | ||
10396 | /* We have to be careful in the presence of DW_AT_specification. | |
10397 | For example, with GCC 3.4, given the code | |
10398 | ||
10399 | namespace N { | |
10400 | void foo() { | |
10401 | // Definition of N::foo. | |
10402 | } | |
10403 | } | |
10404 | ||
10405 | then we'll have a tree of DIEs like this: | |
10406 | ||
10407 | 1: DW_TAG_compile_unit | |
10408 | 2: DW_TAG_namespace // N | |
10409 | 3: DW_TAG_subprogram // declaration of N::foo | |
10410 | 4: DW_TAG_subprogram // definition of N::foo | |
10411 | DW_AT_specification // refers to die #3 | |
10412 | ||
10413 | Thus, when processing die #4, we have to pretend that we're in | |
10414 | the context of its DW_AT_specification, namely the contex of die | |
10415 | #3. */ | |
10416 | spec_cu = cu; | |
10417 | spec_die = die_specification (die, &spec_cu); | |
10418 | if (spec_die == NULL) | |
10419 | parent = die->parent; | |
10420 | else | |
63d06c5c | 10421 | { |
0114d602 DJ |
10422 | parent = spec_die->parent; |
10423 | cu = spec_cu; | |
63d06c5c | 10424 | } |
0114d602 DJ |
10425 | |
10426 | if (parent == NULL) | |
10427 | return ""; | |
63d06c5c | 10428 | else |
0114d602 DJ |
10429 | switch (parent->tag) |
10430 | { | |
63d06c5c | 10431 | case DW_TAG_namespace: |
0114d602 | 10432 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
10433 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
10434 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
10435 | Work around this problem here. */ | |
10436 | if (cu->language == language_cplus | |
10437 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
10438 | return ""; | |
0114d602 DJ |
10439 | /* We give a name to even anonymous namespaces. */ |
10440 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 10441 | case DW_TAG_class_type: |
680b30c7 | 10442 | case DW_TAG_interface_type: |
63d06c5c | 10443 | case DW_TAG_structure_type: |
0114d602 | 10444 | case DW_TAG_union_type: |
f55ee35c | 10445 | case DW_TAG_module: |
0114d602 DJ |
10446 | parent_type = read_type_die (parent, cu); |
10447 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
10448 | return TYPE_TAG_NAME (parent_type); | |
10449 | else | |
10450 | /* An anonymous structure is only allowed non-static data | |
10451 | members; no typedefs, no member functions, et cetera. | |
10452 | So it does not need a prefix. */ | |
10453 | return ""; | |
63d06c5c | 10454 | default: |
8176b9b8 | 10455 | return determine_prefix (parent, cu); |
63d06c5c | 10456 | } |
63d06c5c DC |
10457 | } |
10458 | ||
987504bb JJ |
10459 | /* Return a newly-allocated string formed by concatenating PREFIX and |
10460 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
10461 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
10462 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
10463 | is used to determine the language and hence, the appropriate separator. */ | |
10464 | ||
f55ee35c | 10465 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
10466 | |
10467 | static char * | |
f55ee35c JK |
10468 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
10469 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 10470 | { |
f55ee35c | 10471 | const char *lead = ""; |
5c315b68 | 10472 | const char *sep; |
63d06c5c | 10473 | |
987504bb JJ |
10474 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
10475 | sep = ""; | |
10476 | else if (cu->language == language_java) | |
10477 | sep = "."; | |
f55ee35c JK |
10478 | else if (cu->language == language_fortran && physname) |
10479 | { | |
10480 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
10481 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
10482 | ||
10483 | lead = "__"; | |
10484 | sep = "_MOD_"; | |
10485 | } | |
987504bb JJ |
10486 | else |
10487 | sep = "::"; | |
63d06c5c | 10488 | |
6dd47d34 DE |
10489 | if (prefix == NULL) |
10490 | prefix = ""; | |
10491 | if (suffix == NULL) | |
10492 | suffix = ""; | |
10493 | ||
987504bb JJ |
10494 | if (obs == NULL) |
10495 | { | |
10496 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 10497 | |
f55ee35c JK |
10498 | strcpy (retval, lead); |
10499 | strcat (retval, prefix); | |
6dd47d34 DE |
10500 | strcat (retval, sep); |
10501 | strcat (retval, suffix); | |
63d06c5c DC |
10502 | return retval; |
10503 | } | |
987504bb JJ |
10504 | else |
10505 | { | |
10506 | /* We have an obstack. */ | |
f55ee35c | 10507 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 10508 | } |
63d06c5c DC |
10509 | } |
10510 | ||
c906108c SS |
10511 | /* Return sibling of die, NULL if no sibling. */ |
10512 | ||
f9aca02d | 10513 | static struct die_info * |
fba45db2 | 10514 | sibling_die (struct die_info *die) |
c906108c | 10515 | { |
639d11d3 | 10516 | return die->sibling; |
c906108c SS |
10517 | } |
10518 | ||
71c25dea TT |
10519 | /* Get name of a die, return NULL if not found. */ |
10520 | ||
10521 | static char * | |
10522 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
10523 | struct obstack *obstack) | |
10524 | { | |
10525 | if (name && cu->language == language_cplus) | |
10526 | { | |
10527 | char *canon_name = cp_canonicalize_string (name); | |
10528 | ||
10529 | if (canon_name != NULL) | |
10530 | { | |
10531 | if (strcmp (canon_name, name) != 0) | |
10532 | name = obsavestring (canon_name, strlen (canon_name), | |
10533 | obstack); | |
10534 | xfree (canon_name); | |
10535 | } | |
10536 | } | |
10537 | ||
10538 | return name; | |
c906108c SS |
10539 | } |
10540 | ||
9219021c DC |
10541 | /* Get name of a die, return NULL if not found. */ |
10542 | ||
10543 | static char * | |
e142c38c | 10544 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
10545 | { |
10546 | struct attribute *attr; | |
10547 | ||
e142c38c | 10548 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
10549 | if (!attr || !DW_STRING (attr)) |
10550 | return NULL; | |
10551 | ||
10552 | switch (die->tag) | |
10553 | { | |
10554 | case DW_TAG_compile_unit: | |
10555 | /* Compilation units have a DW_AT_name that is a filename, not | |
10556 | a source language identifier. */ | |
10557 | case DW_TAG_enumeration_type: | |
10558 | case DW_TAG_enumerator: | |
10559 | /* These tags always have simple identifiers already; no need | |
10560 | to canonicalize them. */ | |
10561 | return DW_STRING (attr); | |
907af001 | 10562 | |
418835cc KS |
10563 | case DW_TAG_subprogram: |
10564 | /* Java constructors will all be named "<init>", so return | |
10565 | the class name when we see this special case. */ | |
10566 | if (cu->language == language_java | |
10567 | && DW_STRING (attr) != NULL | |
10568 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
10569 | { | |
10570 | struct dwarf2_cu *spec_cu = cu; | |
10571 | struct die_info *spec_die; | |
10572 | ||
10573 | /* GCJ will output '<init>' for Java constructor names. | |
10574 | For this special case, return the name of the parent class. */ | |
10575 | ||
10576 | /* GCJ may output suprogram DIEs with AT_specification set. | |
10577 | If so, use the name of the specified DIE. */ | |
10578 | spec_die = die_specification (die, &spec_cu); | |
10579 | if (spec_die != NULL) | |
10580 | return dwarf2_name (spec_die, spec_cu); | |
10581 | ||
10582 | do | |
10583 | { | |
10584 | die = die->parent; | |
10585 | if (die->tag == DW_TAG_class_type) | |
10586 | return dwarf2_name (die, cu); | |
10587 | } | |
10588 | while (die->tag != DW_TAG_compile_unit); | |
10589 | } | |
907af001 UW |
10590 | break; |
10591 | ||
10592 | case DW_TAG_class_type: | |
10593 | case DW_TAG_interface_type: | |
10594 | case DW_TAG_structure_type: | |
10595 | case DW_TAG_union_type: | |
10596 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
10597 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
10598 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
10599 | and GCC 4.4. We work around this problem by ignoring these. */ | |
10600 | if (strncmp (DW_STRING (attr), "._", 2) == 0 | |
10601 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) | |
10602 | return NULL; | |
10603 | break; | |
10604 | ||
71c25dea | 10605 | default: |
907af001 UW |
10606 | break; |
10607 | } | |
10608 | ||
10609 | if (!DW_STRING_IS_CANONICAL (attr)) | |
10610 | { | |
10611 | DW_STRING (attr) | |
10612 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
10613 | &cu->objfile->objfile_obstack); | |
10614 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 10615 | } |
907af001 | 10616 | return DW_STRING (attr); |
9219021c DC |
10617 | } |
10618 | ||
10619 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
10620 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
10621 | containing the return value on output. */ | |
9219021c DC |
10622 | |
10623 | static struct die_info * | |
f2f0e013 | 10624 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
10625 | { |
10626 | struct attribute *attr; | |
9219021c | 10627 | |
f2f0e013 | 10628 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
10629 | if (attr == NULL) |
10630 | return NULL; | |
10631 | ||
f2f0e013 | 10632 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
10633 | } |
10634 | ||
c906108c SS |
10635 | /* Convert a DIE tag into its string name. */ |
10636 | ||
10637 | static char * | |
aa1ee363 | 10638 | dwarf_tag_name (unsigned tag) |
c906108c SS |
10639 | { |
10640 | switch (tag) | |
10641 | { | |
10642 | case DW_TAG_padding: | |
10643 | return "DW_TAG_padding"; | |
10644 | case DW_TAG_array_type: | |
10645 | return "DW_TAG_array_type"; | |
10646 | case DW_TAG_class_type: | |
10647 | return "DW_TAG_class_type"; | |
10648 | case DW_TAG_entry_point: | |
10649 | return "DW_TAG_entry_point"; | |
10650 | case DW_TAG_enumeration_type: | |
10651 | return "DW_TAG_enumeration_type"; | |
10652 | case DW_TAG_formal_parameter: | |
10653 | return "DW_TAG_formal_parameter"; | |
10654 | case DW_TAG_imported_declaration: | |
10655 | return "DW_TAG_imported_declaration"; | |
10656 | case DW_TAG_label: | |
10657 | return "DW_TAG_label"; | |
10658 | case DW_TAG_lexical_block: | |
10659 | return "DW_TAG_lexical_block"; | |
10660 | case DW_TAG_member: | |
10661 | return "DW_TAG_member"; | |
10662 | case DW_TAG_pointer_type: | |
10663 | return "DW_TAG_pointer_type"; | |
10664 | case DW_TAG_reference_type: | |
10665 | return "DW_TAG_reference_type"; | |
10666 | case DW_TAG_compile_unit: | |
10667 | return "DW_TAG_compile_unit"; | |
10668 | case DW_TAG_string_type: | |
10669 | return "DW_TAG_string_type"; | |
10670 | case DW_TAG_structure_type: | |
10671 | return "DW_TAG_structure_type"; | |
10672 | case DW_TAG_subroutine_type: | |
10673 | return "DW_TAG_subroutine_type"; | |
10674 | case DW_TAG_typedef: | |
10675 | return "DW_TAG_typedef"; | |
10676 | case DW_TAG_union_type: | |
10677 | return "DW_TAG_union_type"; | |
10678 | case DW_TAG_unspecified_parameters: | |
10679 | return "DW_TAG_unspecified_parameters"; | |
10680 | case DW_TAG_variant: | |
10681 | return "DW_TAG_variant"; | |
10682 | case DW_TAG_common_block: | |
10683 | return "DW_TAG_common_block"; | |
10684 | case DW_TAG_common_inclusion: | |
10685 | return "DW_TAG_common_inclusion"; | |
10686 | case DW_TAG_inheritance: | |
10687 | return "DW_TAG_inheritance"; | |
10688 | case DW_TAG_inlined_subroutine: | |
10689 | return "DW_TAG_inlined_subroutine"; | |
10690 | case DW_TAG_module: | |
10691 | return "DW_TAG_module"; | |
10692 | case DW_TAG_ptr_to_member_type: | |
10693 | return "DW_TAG_ptr_to_member_type"; | |
10694 | case DW_TAG_set_type: | |
10695 | return "DW_TAG_set_type"; | |
10696 | case DW_TAG_subrange_type: | |
10697 | return "DW_TAG_subrange_type"; | |
10698 | case DW_TAG_with_stmt: | |
10699 | return "DW_TAG_with_stmt"; | |
10700 | case DW_TAG_access_declaration: | |
10701 | return "DW_TAG_access_declaration"; | |
10702 | case DW_TAG_base_type: | |
10703 | return "DW_TAG_base_type"; | |
10704 | case DW_TAG_catch_block: | |
10705 | return "DW_TAG_catch_block"; | |
10706 | case DW_TAG_const_type: | |
10707 | return "DW_TAG_const_type"; | |
10708 | case DW_TAG_constant: | |
10709 | return "DW_TAG_constant"; | |
10710 | case DW_TAG_enumerator: | |
10711 | return "DW_TAG_enumerator"; | |
10712 | case DW_TAG_file_type: | |
10713 | return "DW_TAG_file_type"; | |
10714 | case DW_TAG_friend: | |
10715 | return "DW_TAG_friend"; | |
10716 | case DW_TAG_namelist: | |
10717 | return "DW_TAG_namelist"; | |
10718 | case DW_TAG_namelist_item: | |
10719 | return "DW_TAG_namelist_item"; | |
10720 | case DW_TAG_packed_type: | |
10721 | return "DW_TAG_packed_type"; | |
10722 | case DW_TAG_subprogram: | |
10723 | return "DW_TAG_subprogram"; | |
10724 | case DW_TAG_template_type_param: | |
10725 | return "DW_TAG_template_type_param"; | |
10726 | case DW_TAG_template_value_param: | |
10727 | return "DW_TAG_template_value_param"; | |
10728 | case DW_TAG_thrown_type: | |
10729 | return "DW_TAG_thrown_type"; | |
10730 | case DW_TAG_try_block: | |
10731 | return "DW_TAG_try_block"; | |
10732 | case DW_TAG_variant_part: | |
10733 | return "DW_TAG_variant_part"; | |
10734 | case DW_TAG_variable: | |
10735 | return "DW_TAG_variable"; | |
10736 | case DW_TAG_volatile_type: | |
10737 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
10738 | case DW_TAG_dwarf_procedure: |
10739 | return "DW_TAG_dwarf_procedure"; | |
10740 | case DW_TAG_restrict_type: | |
10741 | return "DW_TAG_restrict_type"; | |
10742 | case DW_TAG_interface_type: | |
10743 | return "DW_TAG_interface_type"; | |
10744 | case DW_TAG_namespace: | |
10745 | return "DW_TAG_namespace"; | |
10746 | case DW_TAG_imported_module: | |
10747 | return "DW_TAG_imported_module"; | |
10748 | case DW_TAG_unspecified_type: | |
10749 | return "DW_TAG_unspecified_type"; | |
10750 | case DW_TAG_partial_unit: | |
10751 | return "DW_TAG_partial_unit"; | |
10752 | case DW_TAG_imported_unit: | |
10753 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
10754 | case DW_TAG_condition: |
10755 | return "DW_TAG_condition"; | |
10756 | case DW_TAG_shared_type: | |
10757 | return "DW_TAG_shared_type"; | |
348e048f DE |
10758 | case DW_TAG_type_unit: |
10759 | return "DW_TAG_type_unit"; | |
c906108c SS |
10760 | case DW_TAG_MIPS_loop: |
10761 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
10762 | case DW_TAG_HP_array_descriptor: |
10763 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
10764 | case DW_TAG_format_label: |
10765 | return "DW_TAG_format_label"; | |
10766 | case DW_TAG_function_template: | |
10767 | return "DW_TAG_function_template"; | |
10768 | case DW_TAG_class_template: | |
10769 | return "DW_TAG_class_template"; | |
b7619582 GF |
10770 | case DW_TAG_GNU_BINCL: |
10771 | return "DW_TAG_GNU_BINCL"; | |
10772 | case DW_TAG_GNU_EINCL: | |
10773 | return "DW_TAG_GNU_EINCL"; | |
10774 | case DW_TAG_upc_shared_type: | |
10775 | return "DW_TAG_upc_shared_type"; | |
10776 | case DW_TAG_upc_strict_type: | |
10777 | return "DW_TAG_upc_strict_type"; | |
10778 | case DW_TAG_upc_relaxed_type: | |
10779 | return "DW_TAG_upc_relaxed_type"; | |
10780 | case DW_TAG_PGI_kanji_type: | |
10781 | return "DW_TAG_PGI_kanji_type"; | |
10782 | case DW_TAG_PGI_interface_block: | |
10783 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
10784 | default: |
10785 | return "DW_TAG_<unknown>"; | |
10786 | } | |
10787 | } | |
10788 | ||
10789 | /* Convert a DWARF attribute code into its string name. */ | |
10790 | ||
10791 | static char * | |
aa1ee363 | 10792 | dwarf_attr_name (unsigned attr) |
c906108c SS |
10793 | { |
10794 | switch (attr) | |
10795 | { | |
10796 | case DW_AT_sibling: | |
10797 | return "DW_AT_sibling"; | |
10798 | case DW_AT_location: | |
10799 | return "DW_AT_location"; | |
10800 | case DW_AT_name: | |
10801 | return "DW_AT_name"; | |
10802 | case DW_AT_ordering: | |
10803 | return "DW_AT_ordering"; | |
10804 | case DW_AT_subscr_data: | |
10805 | return "DW_AT_subscr_data"; | |
10806 | case DW_AT_byte_size: | |
10807 | return "DW_AT_byte_size"; | |
10808 | case DW_AT_bit_offset: | |
10809 | return "DW_AT_bit_offset"; | |
10810 | case DW_AT_bit_size: | |
10811 | return "DW_AT_bit_size"; | |
10812 | case DW_AT_element_list: | |
10813 | return "DW_AT_element_list"; | |
10814 | case DW_AT_stmt_list: | |
10815 | return "DW_AT_stmt_list"; | |
10816 | case DW_AT_low_pc: | |
10817 | return "DW_AT_low_pc"; | |
10818 | case DW_AT_high_pc: | |
10819 | return "DW_AT_high_pc"; | |
10820 | case DW_AT_language: | |
10821 | return "DW_AT_language"; | |
10822 | case DW_AT_member: | |
10823 | return "DW_AT_member"; | |
10824 | case DW_AT_discr: | |
10825 | return "DW_AT_discr"; | |
10826 | case DW_AT_discr_value: | |
10827 | return "DW_AT_discr_value"; | |
10828 | case DW_AT_visibility: | |
10829 | return "DW_AT_visibility"; | |
10830 | case DW_AT_import: | |
10831 | return "DW_AT_import"; | |
10832 | case DW_AT_string_length: | |
10833 | return "DW_AT_string_length"; | |
10834 | case DW_AT_common_reference: | |
10835 | return "DW_AT_common_reference"; | |
10836 | case DW_AT_comp_dir: | |
10837 | return "DW_AT_comp_dir"; | |
10838 | case DW_AT_const_value: | |
10839 | return "DW_AT_const_value"; | |
10840 | case DW_AT_containing_type: | |
10841 | return "DW_AT_containing_type"; | |
10842 | case DW_AT_default_value: | |
10843 | return "DW_AT_default_value"; | |
10844 | case DW_AT_inline: | |
10845 | return "DW_AT_inline"; | |
10846 | case DW_AT_is_optional: | |
10847 | return "DW_AT_is_optional"; | |
10848 | case DW_AT_lower_bound: | |
10849 | return "DW_AT_lower_bound"; | |
10850 | case DW_AT_producer: | |
10851 | return "DW_AT_producer"; | |
10852 | case DW_AT_prototyped: | |
10853 | return "DW_AT_prototyped"; | |
10854 | case DW_AT_return_addr: | |
10855 | return "DW_AT_return_addr"; | |
10856 | case DW_AT_start_scope: | |
10857 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
10858 | case DW_AT_bit_stride: |
10859 | return "DW_AT_bit_stride"; | |
c906108c SS |
10860 | case DW_AT_upper_bound: |
10861 | return "DW_AT_upper_bound"; | |
10862 | case DW_AT_abstract_origin: | |
10863 | return "DW_AT_abstract_origin"; | |
10864 | case DW_AT_accessibility: | |
10865 | return "DW_AT_accessibility"; | |
10866 | case DW_AT_address_class: | |
10867 | return "DW_AT_address_class"; | |
10868 | case DW_AT_artificial: | |
10869 | return "DW_AT_artificial"; | |
10870 | case DW_AT_base_types: | |
10871 | return "DW_AT_base_types"; | |
10872 | case DW_AT_calling_convention: | |
10873 | return "DW_AT_calling_convention"; | |
10874 | case DW_AT_count: | |
10875 | return "DW_AT_count"; | |
10876 | case DW_AT_data_member_location: | |
10877 | return "DW_AT_data_member_location"; | |
10878 | case DW_AT_decl_column: | |
10879 | return "DW_AT_decl_column"; | |
10880 | case DW_AT_decl_file: | |
10881 | return "DW_AT_decl_file"; | |
10882 | case DW_AT_decl_line: | |
10883 | return "DW_AT_decl_line"; | |
10884 | case DW_AT_declaration: | |
10885 | return "DW_AT_declaration"; | |
10886 | case DW_AT_discr_list: | |
10887 | return "DW_AT_discr_list"; | |
10888 | case DW_AT_encoding: | |
10889 | return "DW_AT_encoding"; | |
10890 | case DW_AT_external: | |
10891 | return "DW_AT_external"; | |
10892 | case DW_AT_frame_base: | |
10893 | return "DW_AT_frame_base"; | |
10894 | case DW_AT_friend: | |
10895 | return "DW_AT_friend"; | |
10896 | case DW_AT_identifier_case: | |
10897 | return "DW_AT_identifier_case"; | |
10898 | case DW_AT_macro_info: | |
10899 | return "DW_AT_macro_info"; | |
10900 | case DW_AT_namelist_items: | |
10901 | return "DW_AT_namelist_items"; | |
10902 | case DW_AT_priority: | |
10903 | return "DW_AT_priority"; | |
10904 | case DW_AT_segment: | |
10905 | return "DW_AT_segment"; | |
10906 | case DW_AT_specification: | |
10907 | return "DW_AT_specification"; | |
10908 | case DW_AT_static_link: | |
10909 | return "DW_AT_static_link"; | |
10910 | case DW_AT_type: | |
10911 | return "DW_AT_type"; | |
10912 | case DW_AT_use_location: | |
10913 | return "DW_AT_use_location"; | |
10914 | case DW_AT_variable_parameter: | |
10915 | return "DW_AT_variable_parameter"; | |
10916 | case DW_AT_virtuality: | |
10917 | return "DW_AT_virtuality"; | |
10918 | case DW_AT_vtable_elem_location: | |
10919 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 10920 | /* DWARF 3 values. */ |
d9fa45fe DC |
10921 | case DW_AT_allocated: |
10922 | return "DW_AT_allocated"; | |
10923 | case DW_AT_associated: | |
10924 | return "DW_AT_associated"; | |
10925 | case DW_AT_data_location: | |
10926 | return "DW_AT_data_location"; | |
09fa0d7c JK |
10927 | case DW_AT_byte_stride: |
10928 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
10929 | case DW_AT_entry_pc: |
10930 | return "DW_AT_entry_pc"; | |
10931 | case DW_AT_use_UTF8: | |
10932 | return "DW_AT_use_UTF8"; | |
10933 | case DW_AT_extension: | |
10934 | return "DW_AT_extension"; | |
10935 | case DW_AT_ranges: | |
10936 | return "DW_AT_ranges"; | |
10937 | case DW_AT_trampoline: | |
10938 | return "DW_AT_trampoline"; | |
10939 | case DW_AT_call_column: | |
10940 | return "DW_AT_call_column"; | |
10941 | case DW_AT_call_file: | |
10942 | return "DW_AT_call_file"; | |
10943 | case DW_AT_call_line: | |
10944 | return "DW_AT_call_line"; | |
b7619582 GF |
10945 | case DW_AT_description: |
10946 | return "DW_AT_description"; | |
10947 | case DW_AT_binary_scale: | |
10948 | return "DW_AT_binary_scale"; | |
10949 | case DW_AT_decimal_scale: | |
10950 | return "DW_AT_decimal_scale"; | |
10951 | case DW_AT_small: | |
10952 | return "DW_AT_small"; | |
10953 | case DW_AT_decimal_sign: | |
10954 | return "DW_AT_decimal_sign"; | |
10955 | case DW_AT_digit_count: | |
10956 | return "DW_AT_digit_count"; | |
10957 | case DW_AT_picture_string: | |
10958 | return "DW_AT_picture_string"; | |
10959 | case DW_AT_mutable: | |
10960 | return "DW_AT_mutable"; | |
10961 | case DW_AT_threads_scaled: | |
10962 | return "DW_AT_threads_scaled"; | |
10963 | case DW_AT_explicit: | |
10964 | return "DW_AT_explicit"; | |
10965 | case DW_AT_object_pointer: | |
10966 | return "DW_AT_object_pointer"; | |
10967 | case DW_AT_endianity: | |
10968 | return "DW_AT_endianity"; | |
10969 | case DW_AT_elemental: | |
10970 | return "DW_AT_elemental"; | |
10971 | case DW_AT_pure: | |
10972 | return "DW_AT_pure"; | |
10973 | case DW_AT_recursive: | |
10974 | return "DW_AT_recursive"; | |
348e048f DE |
10975 | /* DWARF 4 values. */ |
10976 | case DW_AT_signature: | |
10977 | return "DW_AT_signature"; | |
31ef98ae TT |
10978 | case DW_AT_linkage_name: |
10979 | return "DW_AT_linkage_name"; | |
b7619582 | 10980 | /* SGI/MIPS extensions. */ |
c764a876 | 10981 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
10982 | case DW_AT_MIPS_fde: |
10983 | return "DW_AT_MIPS_fde"; | |
c764a876 | 10984 | #endif |
c906108c SS |
10985 | case DW_AT_MIPS_loop_begin: |
10986 | return "DW_AT_MIPS_loop_begin"; | |
10987 | case DW_AT_MIPS_tail_loop_begin: | |
10988 | return "DW_AT_MIPS_tail_loop_begin"; | |
10989 | case DW_AT_MIPS_epilog_begin: | |
10990 | return "DW_AT_MIPS_epilog_begin"; | |
10991 | case DW_AT_MIPS_loop_unroll_factor: | |
10992 | return "DW_AT_MIPS_loop_unroll_factor"; | |
10993 | case DW_AT_MIPS_software_pipeline_depth: | |
10994 | return "DW_AT_MIPS_software_pipeline_depth"; | |
10995 | case DW_AT_MIPS_linkage_name: | |
10996 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
10997 | case DW_AT_MIPS_stride: |
10998 | return "DW_AT_MIPS_stride"; | |
10999 | case DW_AT_MIPS_abstract_name: | |
11000 | return "DW_AT_MIPS_abstract_name"; | |
11001 | case DW_AT_MIPS_clone_origin: | |
11002 | return "DW_AT_MIPS_clone_origin"; | |
11003 | case DW_AT_MIPS_has_inlines: | |
11004 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 11005 | /* HP extensions. */ |
c764a876 | 11006 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
11007 | case DW_AT_HP_block_index: |
11008 | return "DW_AT_HP_block_index"; | |
c764a876 | 11009 | #endif |
b7619582 GF |
11010 | case DW_AT_HP_unmodifiable: |
11011 | return "DW_AT_HP_unmodifiable"; | |
11012 | case DW_AT_HP_actuals_stmt_list: | |
11013 | return "DW_AT_HP_actuals_stmt_list"; | |
11014 | case DW_AT_HP_proc_per_section: | |
11015 | return "DW_AT_HP_proc_per_section"; | |
11016 | case DW_AT_HP_raw_data_ptr: | |
11017 | return "DW_AT_HP_raw_data_ptr"; | |
11018 | case DW_AT_HP_pass_by_reference: | |
11019 | return "DW_AT_HP_pass_by_reference"; | |
11020 | case DW_AT_HP_opt_level: | |
11021 | return "DW_AT_HP_opt_level"; | |
11022 | case DW_AT_HP_prof_version_id: | |
11023 | return "DW_AT_HP_prof_version_id"; | |
11024 | case DW_AT_HP_opt_flags: | |
11025 | return "DW_AT_HP_opt_flags"; | |
11026 | case DW_AT_HP_cold_region_low_pc: | |
11027 | return "DW_AT_HP_cold_region_low_pc"; | |
11028 | case DW_AT_HP_cold_region_high_pc: | |
11029 | return "DW_AT_HP_cold_region_high_pc"; | |
11030 | case DW_AT_HP_all_variables_modifiable: | |
11031 | return "DW_AT_HP_all_variables_modifiable"; | |
11032 | case DW_AT_HP_linkage_name: | |
11033 | return "DW_AT_HP_linkage_name"; | |
11034 | case DW_AT_HP_prof_flags: | |
11035 | return "DW_AT_HP_prof_flags"; | |
11036 | /* GNU extensions. */ | |
c906108c SS |
11037 | case DW_AT_sf_names: |
11038 | return "DW_AT_sf_names"; | |
11039 | case DW_AT_src_info: | |
11040 | return "DW_AT_src_info"; | |
11041 | case DW_AT_mac_info: | |
11042 | return "DW_AT_mac_info"; | |
11043 | case DW_AT_src_coords: | |
11044 | return "DW_AT_src_coords"; | |
11045 | case DW_AT_body_begin: | |
11046 | return "DW_AT_body_begin"; | |
11047 | case DW_AT_body_end: | |
11048 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
11049 | case DW_AT_GNU_vector: |
11050 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
11051 | /* VMS extensions. */ |
11052 | case DW_AT_VMS_rtnbeg_pd_address: | |
11053 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
11054 | /* UPC extension. */ | |
11055 | case DW_AT_upc_threads_scaled: | |
11056 | return "DW_AT_upc_threads_scaled"; | |
11057 | /* PGI (STMicroelectronics) extensions. */ | |
11058 | case DW_AT_PGI_lbase: | |
11059 | return "DW_AT_PGI_lbase"; | |
11060 | case DW_AT_PGI_soffset: | |
11061 | return "DW_AT_PGI_soffset"; | |
11062 | case DW_AT_PGI_lstride: | |
11063 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
11064 | default: |
11065 | return "DW_AT_<unknown>"; | |
11066 | } | |
11067 | } | |
11068 | ||
11069 | /* Convert a DWARF value form code into its string name. */ | |
11070 | ||
11071 | static char * | |
aa1ee363 | 11072 | dwarf_form_name (unsigned form) |
c906108c SS |
11073 | { |
11074 | switch (form) | |
11075 | { | |
11076 | case DW_FORM_addr: | |
11077 | return "DW_FORM_addr"; | |
11078 | case DW_FORM_block2: | |
11079 | return "DW_FORM_block2"; | |
11080 | case DW_FORM_block4: | |
11081 | return "DW_FORM_block4"; | |
11082 | case DW_FORM_data2: | |
11083 | return "DW_FORM_data2"; | |
11084 | case DW_FORM_data4: | |
11085 | return "DW_FORM_data4"; | |
11086 | case DW_FORM_data8: | |
11087 | return "DW_FORM_data8"; | |
11088 | case DW_FORM_string: | |
11089 | return "DW_FORM_string"; | |
11090 | case DW_FORM_block: | |
11091 | return "DW_FORM_block"; | |
11092 | case DW_FORM_block1: | |
11093 | return "DW_FORM_block1"; | |
11094 | case DW_FORM_data1: | |
11095 | return "DW_FORM_data1"; | |
11096 | case DW_FORM_flag: | |
11097 | return "DW_FORM_flag"; | |
11098 | case DW_FORM_sdata: | |
11099 | return "DW_FORM_sdata"; | |
11100 | case DW_FORM_strp: | |
11101 | return "DW_FORM_strp"; | |
11102 | case DW_FORM_udata: | |
11103 | return "DW_FORM_udata"; | |
11104 | case DW_FORM_ref_addr: | |
11105 | return "DW_FORM_ref_addr"; | |
11106 | case DW_FORM_ref1: | |
11107 | return "DW_FORM_ref1"; | |
11108 | case DW_FORM_ref2: | |
11109 | return "DW_FORM_ref2"; | |
11110 | case DW_FORM_ref4: | |
11111 | return "DW_FORM_ref4"; | |
11112 | case DW_FORM_ref8: | |
11113 | return "DW_FORM_ref8"; | |
11114 | case DW_FORM_ref_udata: | |
11115 | return "DW_FORM_ref_udata"; | |
11116 | case DW_FORM_indirect: | |
11117 | return "DW_FORM_indirect"; | |
348e048f DE |
11118 | case DW_FORM_sec_offset: |
11119 | return "DW_FORM_sec_offset"; | |
11120 | case DW_FORM_exprloc: | |
11121 | return "DW_FORM_exprloc"; | |
11122 | case DW_FORM_flag_present: | |
11123 | return "DW_FORM_flag_present"; | |
11124 | case DW_FORM_sig8: | |
11125 | return "DW_FORM_sig8"; | |
c906108c SS |
11126 | default: |
11127 | return "DW_FORM_<unknown>"; | |
11128 | } | |
11129 | } | |
11130 | ||
11131 | /* Convert a DWARF stack opcode into its string name. */ | |
11132 | ||
9eae7c52 TT |
11133 | const char * |
11134 | dwarf_stack_op_name (unsigned op, int def) | |
c906108c SS |
11135 | { |
11136 | switch (op) | |
11137 | { | |
11138 | case DW_OP_addr: | |
11139 | return "DW_OP_addr"; | |
11140 | case DW_OP_deref: | |
11141 | return "DW_OP_deref"; | |
11142 | case DW_OP_const1u: | |
11143 | return "DW_OP_const1u"; | |
11144 | case DW_OP_const1s: | |
11145 | return "DW_OP_const1s"; | |
11146 | case DW_OP_const2u: | |
11147 | return "DW_OP_const2u"; | |
11148 | case DW_OP_const2s: | |
11149 | return "DW_OP_const2s"; | |
11150 | case DW_OP_const4u: | |
11151 | return "DW_OP_const4u"; | |
11152 | case DW_OP_const4s: | |
11153 | return "DW_OP_const4s"; | |
11154 | case DW_OP_const8u: | |
11155 | return "DW_OP_const8u"; | |
11156 | case DW_OP_const8s: | |
11157 | return "DW_OP_const8s"; | |
11158 | case DW_OP_constu: | |
11159 | return "DW_OP_constu"; | |
11160 | case DW_OP_consts: | |
11161 | return "DW_OP_consts"; | |
11162 | case DW_OP_dup: | |
11163 | return "DW_OP_dup"; | |
11164 | case DW_OP_drop: | |
11165 | return "DW_OP_drop"; | |
11166 | case DW_OP_over: | |
11167 | return "DW_OP_over"; | |
11168 | case DW_OP_pick: | |
11169 | return "DW_OP_pick"; | |
11170 | case DW_OP_swap: | |
11171 | return "DW_OP_swap"; | |
11172 | case DW_OP_rot: | |
11173 | return "DW_OP_rot"; | |
11174 | case DW_OP_xderef: | |
11175 | return "DW_OP_xderef"; | |
11176 | case DW_OP_abs: | |
11177 | return "DW_OP_abs"; | |
11178 | case DW_OP_and: | |
11179 | return "DW_OP_and"; | |
11180 | case DW_OP_div: | |
11181 | return "DW_OP_div"; | |
11182 | case DW_OP_minus: | |
11183 | return "DW_OP_minus"; | |
11184 | case DW_OP_mod: | |
11185 | return "DW_OP_mod"; | |
11186 | case DW_OP_mul: | |
11187 | return "DW_OP_mul"; | |
11188 | case DW_OP_neg: | |
11189 | return "DW_OP_neg"; | |
11190 | case DW_OP_not: | |
11191 | return "DW_OP_not"; | |
11192 | case DW_OP_or: | |
11193 | return "DW_OP_or"; | |
11194 | case DW_OP_plus: | |
11195 | return "DW_OP_plus"; | |
11196 | case DW_OP_plus_uconst: | |
11197 | return "DW_OP_plus_uconst"; | |
11198 | case DW_OP_shl: | |
11199 | return "DW_OP_shl"; | |
11200 | case DW_OP_shr: | |
11201 | return "DW_OP_shr"; | |
11202 | case DW_OP_shra: | |
11203 | return "DW_OP_shra"; | |
11204 | case DW_OP_xor: | |
11205 | return "DW_OP_xor"; | |
11206 | case DW_OP_bra: | |
11207 | return "DW_OP_bra"; | |
11208 | case DW_OP_eq: | |
11209 | return "DW_OP_eq"; | |
11210 | case DW_OP_ge: | |
11211 | return "DW_OP_ge"; | |
11212 | case DW_OP_gt: | |
11213 | return "DW_OP_gt"; | |
11214 | case DW_OP_le: | |
11215 | return "DW_OP_le"; | |
11216 | case DW_OP_lt: | |
11217 | return "DW_OP_lt"; | |
11218 | case DW_OP_ne: | |
11219 | return "DW_OP_ne"; | |
11220 | case DW_OP_skip: | |
11221 | return "DW_OP_skip"; | |
11222 | case DW_OP_lit0: | |
11223 | return "DW_OP_lit0"; | |
11224 | case DW_OP_lit1: | |
11225 | return "DW_OP_lit1"; | |
11226 | case DW_OP_lit2: | |
11227 | return "DW_OP_lit2"; | |
11228 | case DW_OP_lit3: | |
11229 | return "DW_OP_lit3"; | |
11230 | case DW_OP_lit4: | |
11231 | return "DW_OP_lit4"; | |
11232 | case DW_OP_lit5: | |
11233 | return "DW_OP_lit5"; | |
11234 | case DW_OP_lit6: | |
11235 | return "DW_OP_lit6"; | |
11236 | case DW_OP_lit7: | |
11237 | return "DW_OP_lit7"; | |
11238 | case DW_OP_lit8: | |
11239 | return "DW_OP_lit8"; | |
11240 | case DW_OP_lit9: | |
11241 | return "DW_OP_lit9"; | |
11242 | case DW_OP_lit10: | |
11243 | return "DW_OP_lit10"; | |
11244 | case DW_OP_lit11: | |
11245 | return "DW_OP_lit11"; | |
11246 | case DW_OP_lit12: | |
11247 | return "DW_OP_lit12"; | |
11248 | case DW_OP_lit13: | |
11249 | return "DW_OP_lit13"; | |
11250 | case DW_OP_lit14: | |
11251 | return "DW_OP_lit14"; | |
11252 | case DW_OP_lit15: | |
11253 | return "DW_OP_lit15"; | |
11254 | case DW_OP_lit16: | |
11255 | return "DW_OP_lit16"; | |
11256 | case DW_OP_lit17: | |
11257 | return "DW_OP_lit17"; | |
11258 | case DW_OP_lit18: | |
11259 | return "DW_OP_lit18"; | |
11260 | case DW_OP_lit19: | |
11261 | return "DW_OP_lit19"; | |
11262 | case DW_OP_lit20: | |
11263 | return "DW_OP_lit20"; | |
11264 | case DW_OP_lit21: | |
11265 | return "DW_OP_lit21"; | |
11266 | case DW_OP_lit22: | |
11267 | return "DW_OP_lit22"; | |
11268 | case DW_OP_lit23: | |
11269 | return "DW_OP_lit23"; | |
11270 | case DW_OP_lit24: | |
11271 | return "DW_OP_lit24"; | |
11272 | case DW_OP_lit25: | |
11273 | return "DW_OP_lit25"; | |
11274 | case DW_OP_lit26: | |
11275 | return "DW_OP_lit26"; | |
11276 | case DW_OP_lit27: | |
11277 | return "DW_OP_lit27"; | |
11278 | case DW_OP_lit28: | |
11279 | return "DW_OP_lit28"; | |
11280 | case DW_OP_lit29: | |
11281 | return "DW_OP_lit29"; | |
11282 | case DW_OP_lit30: | |
11283 | return "DW_OP_lit30"; | |
11284 | case DW_OP_lit31: | |
11285 | return "DW_OP_lit31"; | |
11286 | case DW_OP_reg0: | |
11287 | return "DW_OP_reg0"; | |
11288 | case DW_OP_reg1: | |
11289 | return "DW_OP_reg1"; | |
11290 | case DW_OP_reg2: | |
11291 | return "DW_OP_reg2"; | |
11292 | case DW_OP_reg3: | |
11293 | return "DW_OP_reg3"; | |
11294 | case DW_OP_reg4: | |
11295 | return "DW_OP_reg4"; | |
11296 | case DW_OP_reg5: | |
11297 | return "DW_OP_reg5"; | |
11298 | case DW_OP_reg6: | |
11299 | return "DW_OP_reg6"; | |
11300 | case DW_OP_reg7: | |
11301 | return "DW_OP_reg7"; | |
11302 | case DW_OP_reg8: | |
11303 | return "DW_OP_reg8"; | |
11304 | case DW_OP_reg9: | |
11305 | return "DW_OP_reg9"; | |
11306 | case DW_OP_reg10: | |
11307 | return "DW_OP_reg10"; | |
11308 | case DW_OP_reg11: | |
11309 | return "DW_OP_reg11"; | |
11310 | case DW_OP_reg12: | |
11311 | return "DW_OP_reg12"; | |
11312 | case DW_OP_reg13: | |
11313 | return "DW_OP_reg13"; | |
11314 | case DW_OP_reg14: | |
11315 | return "DW_OP_reg14"; | |
11316 | case DW_OP_reg15: | |
11317 | return "DW_OP_reg15"; | |
11318 | case DW_OP_reg16: | |
11319 | return "DW_OP_reg16"; | |
11320 | case DW_OP_reg17: | |
11321 | return "DW_OP_reg17"; | |
11322 | case DW_OP_reg18: | |
11323 | return "DW_OP_reg18"; | |
11324 | case DW_OP_reg19: | |
11325 | return "DW_OP_reg19"; | |
11326 | case DW_OP_reg20: | |
11327 | return "DW_OP_reg20"; | |
11328 | case DW_OP_reg21: | |
11329 | return "DW_OP_reg21"; | |
11330 | case DW_OP_reg22: | |
11331 | return "DW_OP_reg22"; | |
11332 | case DW_OP_reg23: | |
11333 | return "DW_OP_reg23"; | |
11334 | case DW_OP_reg24: | |
11335 | return "DW_OP_reg24"; | |
11336 | case DW_OP_reg25: | |
11337 | return "DW_OP_reg25"; | |
11338 | case DW_OP_reg26: | |
11339 | return "DW_OP_reg26"; | |
11340 | case DW_OP_reg27: | |
11341 | return "DW_OP_reg27"; | |
11342 | case DW_OP_reg28: | |
11343 | return "DW_OP_reg28"; | |
11344 | case DW_OP_reg29: | |
11345 | return "DW_OP_reg29"; | |
11346 | case DW_OP_reg30: | |
11347 | return "DW_OP_reg30"; | |
11348 | case DW_OP_reg31: | |
11349 | return "DW_OP_reg31"; | |
11350 | case DW_OP_breg0: | |
11351 | return "DW_OP_breg0"; | |
11352 | case DW_OP_breg1: | |
11353 | return "DW_OP_breg1"; | |
11354 | case DW_OP_breg2: | |
11355 | return "DW_OP_breg2"; | |
11356 | case DW_OP_breg3: | |
11357 | return "DW_OP_breg3"; | |
11358 | case DW_OP_breg4: | |
11359 | return "DW_OP_breg4"; | |
11360 | case DW_OP_breg5: | |
11361 | return "DW_OP_breg5"; | |
11362 | case DW_OP_breg6: | |
11363 | return "DW_OP_breg6"; | |
11364 | case DW_OP_breg7: | |
11365 | return "DW_OP_breg7"; | |
11366 | case DW_OP_breg8: | |
11367 | return "DW_OP_breg8"; | |
11368 | case DW_OP_breg9: | |
11369 | return "DW_OP_breg9"; | |
11370 | case DW_OP_breg10: | |
11371 | return "DW_OP_breg10"; | |
11372 | case DW_OP_breg11: | |
11373 | return "DW_OP_breg11"; | |
11374 | case DW_OP_breg12: | |
11375 | return "DW_OP_breg12"; | |
11376 | case DW_OP_breg13: | |
11377 | return "DW_OP_breg13"; | |
11378 | case DW_OP_breg14: | |
11379 | return "DW_OP_breg14"; | |
11380 | case DW_OP_breg15: | |
11381 | return "DW_OP_breg15"; | |
11382 | case DW_OP_breg16: | |
11383 | return "DW_OP_breg16"; | |
11384 | case DW_OP_breg17: | |
11385 | return "DW_OP_breg17"; | |
11386 | case DW_OP_breg18: | |
11387 | return "DW_OP_breg18"; | |
11388 | case DW_OP_breg19: | |
11389 | return "DW_OP_breg19"; | |
11390 | case DW_OP_breg20: | |
11391 | return "DW_OP_breg20"; | |
11392 | case DW_OP_breg21: | |
11393 | return "DW_OP_breg21"; | |
11394 | case DW_OP_breg22: | |
11395 | return "DW_OP_breg22"; | |
11396 | case DW_OP_breg23: | |
11397 | return "DW_OP_breg23"; | |
11398 | case DW_OP_breg24: | |
11399 | return "DW_OP_breg24"; | |
11400 | case DW_OP_breg25: | |
11401 | return "DW_OP_breg25"; | |
11402 | case DW_OP_breg26: | |
11403 | return "DW_OP_breg26"; | |
11404 | case DW_OP_breg27: | |
11405 | return "DW_OP_breg27"; | |
11406 | case DW_OP_breg28: | |
11407 | return "DW_OP_breg28"; | |
11408 | case DW_OP_breg29: | |
11409 | return "DW_OP_breg29"; | |
11410 | case DW_OP_breg30: | |
11411 | return "DW_OP_breg30"; | |
11412 | case DW_OP_breg31: | |
11413 | return "DW_OP_breg31"; | |
11414 | case DW_OP_regx: | |
11415 | return "DW_OP_regx"; | |
11416 | case DW_OP_fbreg: | |
11417 | return "DW_OP_fbreg"; | |
11418 | case DW_OP_bregx: | |
11419 | return "DW_OP_bregx"; | |
11420 | case DW_OP_piece: | |
11421 | return "DW_OP_piece"; | |
11422 | case DW_OP_deref_size: | |
11423 | return "DW_OP_deref_size"; | |
11424 | case DW_OP_xderef_size: | |
11425 | return "DW_OP_xderef_size"; | |
11426 | case DW_OP_nop: | |
11427 | return "DW_OP_nop"; | |
b7619582 | 11428 | /* DWARF 3 extensions. */ |
ed348acc EZ |
11429 | case DW_OP_push_object_address: |
11430 | return "DW_OP_push_object_address"; | |
11431 | case DW_OP_call2: | |
11432 | return "DW_OP_call2"; | |
11433 | case DW_OP_call4: | |
11434 | return "DW_OP_call4"; | |
11435 | case DW_OP_call_ref: | |
11436 | return "DW_OP_call_ref"; | |
b7619582 GF |
11437 | case DW_OP_form_tls_address: |
11438 | return "DW_OP_form_tls_address"; | |
11439 | case DW_OP_call_frame_cfa: | |
11440 | return "DW_OP_call_frame_cfa"; | |
11441 | case DW_OP_bit_piece: | |
11442 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
11443 | /* DWARF 4 extensions. */ |
11444 | case DW_OP_implicit_value: | |
11445 | return "DW_OP_implicit_value"; | |
11446 | case DW_OP_stack_value: | |
11447 | return "DW_OP_stack_value"; | |
11448 | /* GNU extensions. */ | |
ed348acc EZ |
11449 | case DW_OP_GNU_push_tls_address: |
11450 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
11451 | case DW_OP_GNU_uninit: |
11452 | return "DW_OP_GNU_uninit"; | |
c906108c | 11453 | default: |
9eae7c52 | 11454 | return def ? "OP_<unknown>" : NULL; |
c906108c SS |
11455 | } |
11456 | } | |
11457 | ||
11458 | static char * | |
fba45db2 | 11459 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
11460 | { |
11461 | if (mybool) | |
11462 | return "TRUE"; | |
11463 | else | |
11464 | return "FALSE"; | |
11465 | } | |
11466 | ||
11467 | /* Convert a DWARF type code into its string name. */ | |
11468 | ||
11469 | static char * | |
aa1ee363 | 11470 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
11471 | { |
11472 | switch (enc) | |
11473 | { | |
b7619582 GF |
11474 | case DW_ATE_void: |
11475 | return "DW_ATE_void"; | |
c906108c SS |
11476 | case DW_ATE_address: |
11477 | return "DW_ATE_address"; | |
11478 | case DW_ATE_boolean: | |
11479 | return "DW_ATE_boolean"; | |
11480 | case DW_ATE_complex_float: | |
11481 | return "DW_ATE_complex_float"; | |
11482 | case DW_ATE_float: | |
11483 | return "DW_ATE_float"; | |
11484 | case DW_ATE_signed: | |
11485 | return "DW_ATE_signed"; | |
11486 | case DW_ATE_signed_char: | |
11487 | return "DW_ATE_signed_char"; | |
11488 | case DW_ATE_unsigned: | |
11489 | return "DW_ATE_unsigned"; | |
11490 | case DW_ATE_unsigned_char: | |
11491 | return "DW_ATE_unsigned_char"; | |
b7619582 | 11492 | /* DWARF 3. */ |
d9fa45fe DC |
11493 | case DW_ATE_imaginary_float: |
11494 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
11495 | case DW_ATE_packed_decimal: |
11496 | return "DW_ATE_packed_decimal"; | |
11497 | case DW_ATE_numeric_string: | |
11498 | return "DW_ATE_numeric_string"; | |
11499 | case DW_ATE_edited: | |
11500 | return "DW_ATE_edited"; | |
11501 | case DW_ATE_signed_fixed: | |
11502 | return "DW_ATE_signed_fixed"; | |
11503 | case DW_ATE_unsigned_fixed: | |
11504 | return "DW_ATE_unsigned_fixed"; | |
11505 | case DW_ATE_decimal_float: | |
11506 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
11507 | /* DWARF 4. */ |
11508 | case DW_ATE_UTF: | |
11509 | return "DW_ATE_UTF"; | |
b7619582 GF |
11510 | /* HP extensions. */ |
11511 | case DW_ATE_HP_float80: | |
11512 | return "DW_ATE_HP_float80"; | |
11513 | case DW_ATE_HP_complex_float80: | |
11514 | return "DW_ATE_HP_complex_float80"; | |
11515 | case DW_ATE_HP_float128: | |
11516 | return "DW_ATE_HP_float128"; | |
11517 | case DW_ATE_HP_complex_float128: | |
11518 | return "DW_ATE_HP_complex_float128"; | |
11519 | case DW_ATE_HP_floathpintel: | |
11520 | return "DW_ATE_HP_floathpintel"; | |
11521 | case DW_ATE_HP_imaginary_float80: | |
11522 | return "DW_ATE_HP_imaginary_float80"; | |
11523 | case DW_ATE_HP_imaginary_float128: | |
11524 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
11525 | default: |
11526 | return "DW_ATE_<unknown>"; | |
11527 | } | |
11528 | } | |
11529 | ||
11530 | /* Convert a DWARF call frame info operation to its string name. */ | |
11531 | ||
11532 | #if 0 | |
11533 | static char * | |
aa1ee363 | 11534 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
11535 | { |
11536 | switch (cfi_opc) | |
11537 | { | |
11538 | case DW_CFA_advance_loc: | |
11539 | return "DW_CFA_advance_loc"; | |
11540 | case DW_CFA_offset: | |
11541 | return "DW_CFA_offset"; | |
11542 | case DW_CFA_restore: | |
11543 | return "DW_CFA_restore"; | |
11544 | case DW_CFA_nop: | |
11545 | return "DW_CFA_nop"; | |
11546 | case DW_CFA_set_loc: | |
11547 | return "DW_CFA_set_loc"; | |
11548 | case DW_CFA_advance_loc1: | |
11549 | return "DW_CFA_advance_loc1"; | |
11550 | case DW_CFA_advance_loc2: | |
11551 | return "DW_CFA_advance_loc2"; | |
11552 | case DW_CFA_advance_loc4: | |
11553 | return "DW_CFA_advance_loc4"; | |
11554 | case DW_CFA_offset_extended: | |
11555 | return "DW_CFA_offset_extended"; | |
11556 | case DW_CFA_restore_extended: | |
11557 | return "DW_CFA_restore_extended"; | |
11558 | case DW_CFA_undefined: | |
11559 | return "DW_CFA_undefined"; | |
11560 | case DW_CFA_same_value: | |
11561 | return "DW_CFA_same_value"; | |
11562 | case DW_CFA_register: | |
11563 | return "DW_CFA_register"; | |
11564 | case DW_CFA_remember_state: | |
11565 | return "DW_CFA_remember_state"; | |
11566 | case DW_CFA_restore_state: | |
11567 | return "DW_CFA_restore_state"; | |
11568 | case DW_CFA_def_cfa: | |
11569 | return "DW_CFA_def_cfa"; | |
11570 | case DW_CFA_def_cfa_register: | |
11571 | return "DW_CFA_def_cfa_register"; | |
11572 | case DW_CFA_def_cfa_offset: | |
11573 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 11574 | /* DWARF 3. */ |
985cb1a3 JM |
11575 | case DW_CFA_def_cfa_expression: |
11576 | return "DW_CFA_def_cfa_expression"; | |
11577 | case DW_CFA_expression: | |
11578 | return "DW_CFA_expression"; | |
11579 | case DW_CFA_offset_extended_sf: | |
11580 | return "DW_CFA_offset_extended_sf"; | |
11581 | case DW_CFA_def_cfa_sf: | |
11582 | return "DW_CFA_def_cfa_sf"; | |
11583 | case DW_CFA_def_cfa_offset_sf: | |
11584 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
11585 | case DW_CFA_val_offset: |
11586 | return "DW_CFA_val_offset"; | |
11587 | case DW_CFA_val_offset_sf: | |
11588 | return "DW_CFA_val_offset_sf"; | |
11589 | case DW_CFA_val_expression: | |
11590 | return "DW_CFA_val_expression"; | |
11591 | /* SGI/MIPS specific. */ | |
c906108c SS |
11592 | case DW_CFA_MIPS_advance_loc8: |
11593 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 11594 | /* GNU extensions. */ |
985cb1a3 JM |
11595 | case DW_CFA_GNU_window_save: |
11596 | return "DW_CFA_GNU_window_save"; | |
11597 | case DW_CFA_GNU_args_size: | |
11598 | return "DW_CFA_GNU_args_size"; | |
11599 | case DW_CFA_GNU_negative_offset_extended: | |
11600 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
11601 | default: |
11602 | return "DW_CFA_<unknown>"; | |
11603 | } | |
11604 | } | |
11605 | #endif | |
11606 | ||
f9aca02d | 11607 | static void |
d97bc12b | 11608 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
11609 | { |
11610 | unsigned int i; | |
11611 | ||
d97bc12b DE |
11612 | print_spaces (indent, f); |
11613 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 11614 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
11615 | |
11616 | if (die->parent != NULL) | |
11617 | { | |
11618 | print_spaces (indent, f); | |
11619 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
11620 | die->parent->offset); | |
11621 | } | |
11622 | ||
11623 | print_spaces (indent, f); | |
11624 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 11625 | dwarf_bool_name (die->child != NULL)); |
c906108c | 11626 | |
d97bc12b DE |
11627 | print_spaces (indent, f); |
11628 | fprintf_unfiltered (f, " attributes:\n"); | |
11629 | ||
c906108c SS |
11630 | for (i = 0; i < die->num_attrs; ++i) |
11631 | { | |
d97bc12b DE |
11632 | print_spaces (indent, f); |
11633 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
11634 | dwarf_attr_name (die->attrs[i].name), |
11635 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 11636 | |
c906108c SS |
11637 | switch (die->attrs[i].form) |
11638 | { | |
11639 | case DW_FORM_ref_addr: | |
11640 | case DW_FORM_addr: | |
d97bc12b | 11641 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 11642 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
11643 | break; |
11644 | case DW_FORM_block2: | |
11645 | case DW_FORM_block4: | |
11646 | case DW_FORM_block: | |
11647 | case DW_FORM_block1: | |
d97bc12b | 11648 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 11649 | break; |
2dc7f7b3 TT |
11650 | case DW_FORM_exprloc: |
11651 | fprintf_unfiltered (f, "expression: size %u", | |
11652 | DW_BLOCK (&die->attrs[i])->size); | |
11653 | break; | |
10b3939b DJ |
11654 | case DW_FORM_ref1: |
11655 | case DW_FORM_ref2: | |
11656 | case DW_FORM_ref4: | |
d97bc12b | 11657 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
11658 | (long) (DW_ADDR (&die->attrs[i]))); |
11659 | break; | |
c906108c SS |
11660 | case DW_FORM_data1: |
11661 | case DW_FORM_data2: | |
11662 | case DW_FORM_data4: | |
ce5d95e1 | 11663 | case DW_FORM_data8: |
c906108c SS |
11664 | case DW_FORM_udata: |
11665 | case DW_FORM_sdata: | |
43bbcdc2 PH |
11666 | fprintf_unfiltered (f, "constant: %s", |
11667 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 11668 | break; |
2dc7f7b3 TT |
11669 | case DW_FORM_sec_offset: |
11670 | fprintf_unfiltered (f, "section offset: %s", | |
11671 | pulongest (DW_UNSND (&die->attrs[i]))); | |
11672 | break; | |
348e048f DE |
11673 | case DW_FORM_sig8: |
11674 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
11675 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
11676 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
11677 | else | |
11678 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
11679 | break; | |
c906108c | 11680 | case DW_FORM_string: |
4bdf3d34 | 11681 | case DW_FORM_strp: |
8285870a | 11682 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 11683 | DW_STRING (&die->attrs[i]) |
8285870a JK |
11684 | ? DW_STRING (&die->attrs[i]) : "", |
11685 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
11686 | break; |
11687 | case DW_FORM_flag: | |
11688 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 11689 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 11690 | else |
d97bc12b | 11691 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 11692 | break; |
2dc7f7b3 TT |
11693 | case DW_FORM_flag_present: |
11694 | fprintf_unfiltered (f, "flag: TRUE"); | |
11695 | break; | |
a8329558 KW |
11696 | case DW_FORM_indirect: |
11697 | /* the reader will have reduced the indirect form to | |
11698 | the "base form" so this form should not occur */ | |
d97bc12b | 11699 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 11700 | break; |
c906108c | 11701 | default: |
d97bc12b | 11702 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 11703 | die->attrs[i].form); |
d97bc12b | 11704 | break; |
c906108c | 11705 | } |
d97bc12b | 11706 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
11707 | } |
11708 | } | |
11709 | ||
f9aca02d | 11710 | static void |
d97bc12b | 11711 | dump_die_for_error (struct die_info *die) |
c906108c | 11712 | { |
d97bc12b DE |
11713 | dump_die_shallow (gdb_stderr, 0, die); |
11714 | } | |
11715 | ||
11716 | static void | |
11717 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
11718 | { | |
11719 | int indent = level * 4; | |
11720 | ||
11721 | gdb_assert (die != NULL); | |
11722 | ||
11723 | if (level >= max_level) | |
11724 | return; | |
11725 | ||
11726 | dump_die_shallow (f, indent, die); | |
11727 | ||
11728 | if (die->child != NULL) | |
c906108c | 11729 | { |
d97bc12b DE |
11730 | print_spaces (indent, f); |
11731 | fprintf_unfiltered (f, " Children:"); | |
11732 | if (level + 1 < max_level) | |
11733 | { | |
11734 | fprintf_unfiltered (f, "\n"); | |
11735 | dump_die_1 (f, level + 1, max_level, die->child); | |
11736 | } | |
11737 | else | |
11738 | { | |
11739 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
11740 | } | |
11741 | } | |
11742 | ||
11743 | if (die->sibling != NULL && level > 0) | |
11744 | { | |
11745 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
11746 | } |
11747 | } | |
11748 | ||
d97bc12b DE |
11749 | /* This is called from the pdie macro in gdbinit.in. |
11750 | It's not static so gcc will keep a copy callable from gdb. */ | |
11751 | ||
11752 | void | |
11753 | dump_die (struct die_info *die, int max_level) | |
11754 | { | |
11755 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
11756 | } | |
11757 | ||
f9aca02d | 11758 | static void |
51545339 | 11759 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11760 | { |
51545339 | 11761 | void **slot; |
c906108c | 11762 | |
51545339 DJ |
11763 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
11764 | ||
11765 | *slot = die; | |
c906108c SS |
11766 | } |
11767 | ||
93311388 DE |
11768 | static int |
11769 | is_ref_attr (struct attribute *attr) | |
c906108c | 11770 | { |
c906108c SS |
11771 | switch (attr->form) |
11772 | { | |
11773 | case DW_FORM_ref_addr: | |
c906108c SS |
11774 | case DW_FORM_ref1: |
11775 | case DW_FORM_ref2: | |
11776 | case DW_FORM_ref4: | |
613e1657 | 11777 | case DW_FORM_ref8: |
c906108c | 11778 | case DW_FORM_ref_udata: |
93311388 | 11779 | return 1; |
c906108c | 11780 | default: |
93311388 | 11781 | return 0; |
c906108c | 11782 | } |
93311388 DE |
11783 | } |
11784 | ||
11785 | static unsigned int | |
11786 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
11787 | { | |
11788 | if (is_ref_attr (attr)) | |
11789 | return DW_ADDR (attr); | |
11790 | ||
11791 | complaint (&symfile_complaints, | |
11792 | _("unsupported die ref attribute form: '%s'"), | |
11793 | dwarf_form_name (attr->form)); | |
11794 | return 0; | |
c906108c SS |
11795 | } |
11796 | ||
43bbcdc2 PH |
11797 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
11798 | * the value held by the attribute is not constant. */ | |
a02abb62 | 11799 | |
43bbcdc2 | 11800 | static LONGEST |
a02abb62 JB |
11801 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
11802 | { | |
11803 | if (attr->form == DW_FORM_sdata) | |
11804 | return DW_SND (attr); | |
11805 | else if (attr->form == DW_FORM_udata | |
11806 | || attr->form == DW_FORM_data1 | |
11807 | || attr->form == DW_FORM_data2 | |
11808 | || attr->form == DW_FORM_data4 | |
11809 | || attr->form == DW_FORM_data8) | |
11810 | return DW_UNSND (attr); | |
11811 | else | |
11812 | { | |
e2e0b3e5 | 11813 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
11814 | dwarf_form_name (attr->form)); |
11815 | return default_value; | |
11816 | } | |
11817 | } | |
11818 | ||
03dd20cc | 11819 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
11820 | unit and add it to our queue. |
11821 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
11822 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 11823 | |
348e048f | 11824 | static int |
03dd20cc DJ |
11825 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
11826 | struct dwarf2_per_cu_data *per_cu) | |
11827 | { | |
11828 | /* Mark the dependence relation so that we don't flush PER_CU | |
11829 | too early. */ | |
11830 | dwarf2_add_dependence (this_cu, per_cu); | |
11831 | ||
11832 | /* If it's already on the queue, we have nothing to do. */ | |
11833 | if (per_cu->queued) | |
348e048f | 11834 | return 0; |
03dd20cc DJ |
11835 | |
11836 | /* If the compilation unit is already loaded, just mark it as | |
11837 | used. */ | |
11838 | if (per_cu->cu != NULL) | |
11839 | { | |
11840 | per_cu->cu->last_used = 0; | |
348e048f | 11841 | return 0; |
03dd20cc DJ |
11842 | } |
11843 | ||
11844 | /* Add it to the queue. */ | |
11845 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
11846 | |
11847 | return 1; | |
11848 | } | |
11849 | ||
11850 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
11851 | On entry *REF_CU is the CU of SRC_DIE. | |
11852 | On exit *REF_CU is the CU of the result. */ | |
11853 | ||
11854 | static struct die_info * | |
11855 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
11856 | struct dwarf2_cu **ref_cu) | |
11857 | { | |
11858 | struct die_info *die; | |
11859 | ||
11860 | if (is_ref_attr (attr)) | |
11861 | die = follow_die_ref (src_die, attr, ref_cu); | |
11862 | else if (attr->form == DW_FORM_sig8) | |
11863 | die = follow_die_sig (src_die, attr, ref_cu); | |
11864 | else | |
11865 | { | |
11866 | dump_die_for_error (src_die); | |
11867 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
11868 | (*ref_cu)->objfile->name); | |
11869 | } | |
11870 | ||
11871 | return die; | |
03dd20cc DJ |
11872 | } |
11873 | ||
5c631832 JK |
11874 | /* Follow reference OFFSET. |
11875 | On entry *REF_CU is the CU of source DIE referencing OFFSET. | |
f504f079 DE |
11876 | On exit *REF_CU is the CU of the result. */ |
11877 | ||
f9aca02d | 11878 | static struct die_info * |
5c631832 | 11879 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 11880 | { |
10b3939b | 11881 | struct die_info temp_die; |
f2f0e013 | 11882 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 11883 | |
348e048f DE |
11884 | gdb_assert (cu->per_cu != NULL); |
11885 | ||
348e048f DE |
11886 | if (cu->per_cu->from_debug_types) |
11887 | { | |
11888 | /* .debug_types CUs cannot reference anything outside their CU. | |
11889 | If they need to, they have to reference a signatured type via | |
11890 | DW_FORM_sig8. */ | |
11891 | if (! offset_in_cu_p (&cu->header, offset)) | |
5c631832 | 11892 | return NULL; |
348e048f DE |
11893 | target_cu = cu; |
11894 | } | |
11895 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
11896 | { |
11897 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 11898 | |
45452591 | 11899 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
11900 | |
11901 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
11902 | if (maybe_queue_comp_unit (cu, per_cu)) |
11903 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 11904 | |
10b3939b DJ |
11905 | target_cu = per_cu->cu; |
11906 | } | |
11907 | else | |
11908 | target_cu = cu; | |
c906108c | 11909 | |
f2f0e013 | 11910 | *ref_cu = target_cu; |
51545339 | 11911 | temp_die.offset = offset; |
5c631832 JK |
11912 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
11913 | } | |
10b3939b | 11914 | |
5c631832 JK |
11915 | /* Follow reference attribute ATTR of SRC_DIE. |
11916 | On entry *REF_CU is the CU of SRC_DIE. | |
11917 | On exit *REF_CU is the CU of the result. */ | |
11918 | ||
11919 | static struct die_info * | |
11920 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
11921 | struct dwarf2_cu **ref_cu) | |
11922 | { | |
11923 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11924 | struct dwarf2_cu *cu = *ref_cu; | |
11925 | struct die_info *die; | |
11926 | ||
11927 | die = follow_die_offset (offset, ref_cu); | |
11928 | if (!die) | |
11929 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
11930 | "at 0x%x [in module %s]"), | |
11931 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 11932 | |
5c631832 JK |
11933 | return die; |
11934 | } | |
11935 | ||
11936 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
11937 | value is intended for DW_OP_call*. */ | |
11938 | ||
11939 | struct dwarf2_locexpr_baton | |
11940 | dwarf2_fetch_die_location_block (unsigned int offset, | |
11941 | struct dwarf2_per_cu_data *per_cu) | |
11942 | { | |
11943 | struct dwarf2_cu *cu = per_cu->cu; | |
11944 | struct die_info *die; | |
11945 | struct attribute *attr; | |
11946 | struct dwarf2_locexpr_baton retval; | |
11947 | ||
11948 | die = follow_die_offset (offset, &cu); | |
11949 | if (!die) | |
11950 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
11951 | offset, per_cu->cu->objfile->name); | |
11952 | ||
11953 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
11954 | if (!attr) | |
11955 | { | |
11956 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
11957 | ||
11958 | retval.data = NULL; | |
11959 | retval.size = 0; | |
11960 | } | |
11961 | else | |
11962 | { | |
11963 | if (!attr_form_is_block (attr)) | |
11964 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
11965 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
11966 | offset, per_cu->cu->objfile->name); | |
11967 | ||
11968 | retval.data = DW_BLOCK (attr)->data; | |
11969 | retval.size = DW_BLOCK (attr)->size; | |
11970 | } | |
11971 | retval.per_cu = cu->per_cu; | |
11972 | return retval; | |
348e048f DE |
11973 | } |
11974 | ||
11975 | /* Follow the signature attribute ATTR in SRC_DIE. | |
11976 | On entry *REF_CU is the CU of SRC_DIE. | |
11977 | On exit *REF_CU is the CU of the result. */ | |
11978 | ||
11979 | static struct die_info * | |
11980 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
11981 | struct dwarf2_cu **ref_cu) | |
11982 | { | |
11983 | struct objfile *objfile = (*ref_cu)->objfile; | |
11984 | struct die_info temp_die; | |
11985 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11986 | struct dwarf2_cu *sig_cu; | |
11987 | struct die_info *die; | |
11988 | ||
11989 | /* sig_type will be NULL if the signatured type is missing from | |
11990 | the debug info. */ | |
11991 | if (sig_type == NULL) | |
11992 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
11993 | "at 0x%x [in module %s]"), | |
11994 | src_die->offset, objfile->name); | |
11995 | ||
11996 | /* If necessary, add it to the queue and load its DIEs. */ | |
11997 | ||
11998 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
11999 | read_signatured_type (objfile, sig_type); | |
12000 | ||
12001 | gdb_assert (sig_type->per_cu.cu != NULL); | |
12002 | ||
12003 | sig_cu = sig_type->per_cu.cu; | |
12004 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
12005 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
12006 | if (die) | |
12007 | { | |
12008 | *ref_cu = sig_cu; | |
12009 | return die; | |
12010 | } | |
12011 | ||
12012 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
12013 | "at 0x%x [in module %s]"), | |
12014 | sig_type->type_offset, src_die->offset, objfile->name); | |
12015 | } | |
12016 | ||
12017 | /* Given an offset of a signatured type, return its signatured_type. */ | |
12018 | ||
12019 | static struct signatured_type * | |
12020 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
12021 | { | |
12022 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
12023 | unsigned int length, initial_length_size; | |
12024 | unsigned int sig_offset; | |
12025 | struct signatured_type find_entry, *type_sig; | |
12026 | ||
12027 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
12028 | sig_offset = (initial_length_size | |
12029 | + 2 /*version*/ | |
12030 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
12031 | + 1 /*address_size*/); | |
12032 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
12033 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
12034 | ||
12035 | /* This is only used to lookup previously recorded types. | |
12036 | If we didn't find it, it's our bug. */ | |
12037 | gdb_assert (type_sig != NULL); | |
12038 | gdb_assert (offset == type_sig->offset); | |
12039 | ||
12040 | return type_sig; | |
12041 | } | |
12042 | ||
12043 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
12044 | ||
12045 | static void | |
12046 | read_signatured_type_at_offset (struct objfile *objfile, | |
12047 | unsigned int offset) | |
12048 | { | |
12049 | struct signatured_type *type_sig; | |
12050 | ||
be391dca TT |
12051 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
12052 | ||
348e048f DE |
12053 | /* We have the section offset, but we need the signature to do the |
12054 | hash table lookup. */ | |
12055 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
12056 | ||
12057 | gdb_assert (type_sig->per_cu.cu == NULL); | |
12058 | ||
12059 | read_signatured_type (objfile, type_sig); | |
12060 | ||
12061 | gdb_assert (type_sig->per_cu.cu != NULL); | |
12062 | } | |
12063 | ||
12064 | /* Read in a signatured type and build its CU and DIEs. */ | |
12065 | ||
12066 | static void | |
12067 | read_signatured_type (struct objfile *objfile, | |
12068 | struct signatured_type *type_sig) | |
12069 | { | |
12070 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
12071 | struct die_reader_specs reader_specs; | |
12072 | struct dwarf2_cu *cu; | |
12073 | ULONGEST signature; | |
12074 | struct cleanup *back_to, *free_cu_cleanup; | |
12075 | struct attribute *attr; | |
12076 | ||
12077 | gdb_assert (type_sig->per_cu.cu == NULL); | |
12078 | ||
12079 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
12080 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
12081 | obstack_init (&cu->comp_unit_obstack); | |
12082 | cu->objfile = objfile; | |
12083 | type_sig->per_cu.cu = cu; | |
12084 | cu->per_cu = &type_sig->per_cu; | |
12085 | ||
12086 | /* If an error occurs while loading, release our storage. */ | |
12087 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
12088 | ||
12089 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
12090 | types_ptr, objfile->obfd); | |
12091 | gdb_assert (signature == type_sig->signature); | |
12092 | ||
12093 | cu->die_hash | |
12094 | = htab_create_alloc_ex (cu->header.length / 12, | |
12095 | die_hash, | |
12096 | die_eq, | |
12097 | NULL, | |
12098 | &cu->comp_unit_obstack, | |
12099 | hashtab_obstack_allocate, | |
12100 | dummy_obstack_deallocate); | |
12101 | ||
12102 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
12103 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
12104 | ||
12105 | init_cu_die_reader (&reader_specs, cu); | |
12106 | ||
12107 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
12108 | NULL /*parent*/); | |
12109 | ||
12110 | /* We try not to read any attributes in this function, because not | |
12111 | all objfiles needed for references have been loaded yet, and symbol | |
12112 | table processing isn't initialized. But we have to set the CU language, | |
12113 | or we won't be able to build types correctly. */ | |
12114 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
12115 | if (attr) | |
12116 | set_cu_language (DW_UNSND (attr), cu); | |
12117 | else | |
12118 | set_cu_language (language_minimal, cu); | |
12119 | ||
12120 | do_cleanups (back_to); | |
12121 | ||
12122 | /* We've successfully allocated this compilation unit. Let our caller | |
12123 | clean it up when finished with it. */ | |
12124 | discard_cleanups (free_cu_cleanup); | |
12125 | ||
12126 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
12127 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
12128 | } |
12129 | ||
c906108c SS |
12130 | /* Decode simple location descriptions. |
12131 | Given a pointer to a dwarf block that defines a location, compute | |
12132 | the location and return the value. | |
12133 | ||
4cecd739 DJ |
12134 | NOTE drow/2003-11-18: This function is called in two situations |
12135 | now: for the address of static or global variables (partial symbols | |
12136 | only) and for offsets into structures which are expected to be | |
12137 | (more or less) constant. The partial symbol case should go away, | |
12138 | and only the constant case should remain. That will let this | |
12139 | function complain more accurately. A few special modes are allowed | |
12140 | without complaint for global variables (for instance, global | |
12141 | register values and thread-local values). | |
c906108c SS |
12142 | |
12143 | A location description containing no operations indicates that the | |
4cecd739 | 12144 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
12145 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
12146 | callers will only want a very basic result and this can become a | |
12147 | complaint. | |
c906108c | 12148 | |
c906108c SS |
12149 | Note that stack[0] is unused except as a default error return. |
12150 | Note that stack overflow is not yet handled. */ | |
12151 | ||
12152 | static CORE_ADDR | |
e7c27a73 | 12153 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 12154 | { |
e7c27a73 | 12155 | struct objfile *objfile = cu->objfile; |
c906108c SS |
12156 | int i; |
12157 | int size = blk->size; | |
fe1b8b76 | 12158 | gdb_byte *data = blk->data; |
c906108c SS |
12159 | CORE_ADDR stack[64]; |
12160 | int stacki; | |
12161 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 12162 | gdb_byte op; |
c906108c SS |
12163 | |
12164 | i = 0; | |
12165 | stacki = 0; | |
12166 | stack[stacki] = 0; | |
c906108c SS |
12167 | |
12168 | while (i < size) | |
12169 | { | |
c906108c SS |
12170 | op = data[i++]; |
12171 | switch (op) | |
12172 | { | |
f1bea926 JM |
12173 | case DW_OP_lit0: |
12174 | case DW_OP_lit1: | |
12175 | case DW_OP_lit2: | |
12176 | case DW_OP_lit3: | |
12177 | case DW_OP_lit4: | |
12178 | case DW_OP_lit5: | |
12179 | case DW_OP_lit6: | |
12180 | case DW_OP_lit7: | |
12181 | case DW_OP_lit8: | |
12182 | case DW_OP_lit9: | |
12183 | case DW_OP_lit10: | |
12184 | case DW_OP_lit11: | |
12185 | case DW_OP_lit12: | |
12186 | case DW_OP_lit13: | |
12187 | case DW_OP_lit14: | |
12188 | case DW_OP_lit15: | |
12189 | case DW_OP_lit16: | |
12190 | case DW_OP_lit17: | |
12191 | case DW_OP_lit18: | |
12192 | case DW_OP_lit19: | |
12193 | case DW_OP_lit20: | |
12194 | case DW_OP_lit21: | |
12195 | case DW_OP_lit22: | |
12196 | case DW_OP_lit23: | |
12197 | case DW_OP_lit24: | |
12198 | case DW_OP_lit25: | |
12199 | case DW_OP_lit26: | |
12200 | case DW_OP_lit27: | |
12201 | case DW_OP_lit28: | |
12202 | case DW_OP_lit29: | |
12203 | case DW_OP_lit30: | |
12204 | case DW_OP_lit31: | |
12205 | stack[++stacki] = op - DW_OP_lit0; | |
12206 | break; | |
12207 | ||
c906108c SS |
12208 | case DW_OP_reg0: |
12209 | case DW_OP_reg1: | |
12210 | case DW_OP_reg2: | |
12211 | case DW_OP_reg3: | |
12212 | case DW_OP_reg4: | |
12213 | case DW_OP_reg5: | |
12214 | case DW_OP_reg6: | |
12215 | case DW_OP_reg7: | |
12216 | case DW_OP_reg8: | |
12217 | case DW_OP_reg9: | |
12218 | case DW_OP_reg10: | |
12219 | case DW_OP_reg11: | |
12220 | case DW_OP_reg12: | |
12221 | case DW_OP_reg13: | |
12222 | case DW_OP_reg14: | |
12223 | case DW_OP_reg15: | |
12224 | case DW_OP_reg16: | |
12225 | case DW_OP_reg17: | |
12226 | case DW_OP_reg18: | |
12227 | case DW_OP_reg19: | |
12228 | case DW_OP_reg20: | |
12229 | case DW_OP_reg21: | |
12230 | case DW_OP_reg22: | |
12231 | case DW_OP_reg23: | |
12232 | case DW_OP_reg24: | |
12233 | case DW_OP_reg25: | |
12234 | case DW_OP_reg26: | |
12235 | case DW_OP_reg27: | |
12236 | case DW_OP_reg28: | |
12237 | case DW_OP_reg29: | |
12238 | case DW_OP_reg30: | |
12239 | case DW_OP_reg31: | |
c906108c | 12240 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
12241 | if (i < size) |
12242 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
12243 | break; |
12244 | ||
12245 | case DW_OP_regx: | |
c906108c SS |
12246 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
12247 | i += bytes_read; | |
c906108c | 12248 | stack[++stacki] = unsnd; |
4cecd739 DJ |
12249 | if (i < size) |
12250 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
12251 | break; |
12252 | ||
12253 | case DW_OP_addr: | |
107d2387 | 12254 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 12255 | cu, &bytes_read); |
107d2387 | 12256 | i += bytes_read; |
c906108c SS |
12257 | break; |
12258 | ||
12259 | case DW_OP_const1u: | |
12260 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
12261 | i += 1; | |
12262 | break; | |
12263 | ||
12264 | case DW_OP_const1s: | |
12265 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
12266 | i += 1; | |
12267 | break; | |
12268 | ||
12269 | case DW_OP_const2u: | |
12270 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
12271 | i += 2; | |
12272 | break; | |
12273 | ||
12274 | case DW_OP_const2s: | |
12275 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
12276 | i += 2; | |
12277 | break; | |
12278 | ||
12279 | case DW_OP_const4u: | |
12280 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
12281 | i += 4; | |
12282 | break; | |
12283 | ||
12284 | case DW_OP_const4s: | |
12285 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
12286 | i += 4; | |
12287 | break; | |
12288 | ||
12289 | case DW_OP_constu: | |
12290 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 12291 | &bytes_read); |
c906108c SS |
12292 | i += bytes_read; |
12293 | break; | |
12294 | ||
12295 | case DW_OP_consts: | |
12296 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
12297 | i += bytes_read; | |
12298 | break; | |
12299 | ||
f1bea926 JM |
12300 | case DW_OP_dup: |
12301 | stack[stacki + 1] = stack[stacki]; | |
12302 | stacki++; | |
12303 | break; | |
12304 | ||
c906108c SS |
12305 | case DW_OP_plus: |
12306 | stack[stacki - 1] += stack[stacki]; | |
12307 | stacki--; | |
12308 | break; | |
12309 | ||
12310 | case DW_OP_plus_uconst: | |
12311 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
12312 | i += bytes_read; | |
12313 | break; | |
12314 | ||
12315 | case DW_OP_minus: | |
f1bea926 | 12316 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
12317 | stacki--; |
12318 | break; | |
12319 | ||
7a292a7a | 12320 | case DW_OP_deref: |
7a292a7a | 12321 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
12322 | this using GDB's address_class enum. This is valid for partial |
12323 | global symbols, although the variable's address will be bogus | |
12324 | in the psymtab. */ | |
7a292a7a | 12325 | if (i < size) |
4d3c2250 | 12326 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
12327 | break; |
12328 | ||
9d774e44 | 12329 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
12330 | /* The top of the stack has the offset from the beginning |
12331 | of the thread control block at which the variable is located. */ | |
12332 | /* Nothing should follow this operator, so the top of stack would | |
12333 | be returned. */ | |
4cecd739 DJ |
12334 | /* This is valid for partial global symbols, but the variable's |
12335 | address will be bogus in the psymtab. */ | |
9d774e44 | 12336 | if (i < size) |
4d3c2250 | 12337 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
12338 | break; |
12339 | ||
42be36b3 CT |
12340 | case DW_OP_GNU_uninit: |
12341 | break; | |
12342 | ||
c906108c | 12343 | default: |
e2e0b3e5 | 12344 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
9eae7c52 | 12345 | dwarf_stack_op_name (op, 1)); |
c906108c SS |
12346 | return (stack[stacki]); |
12347 | } | |
12348 | } | |
12349 | return (stack[stacki]); | |
12350 | } | |
12351 | ||
12352 | /* memory allocation interface */ | |
12353 | ||
c906108c | 12354 | static struct dwarf_block * |
7b5a2f43 | 12355 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
12356 | { |
12357 | struct dwarf_block *blk; | |
12358 | ||
12359 | blk = (struct dwarf_block *) | |
7b5a2f43 | 12360 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
12361 | return (blk); |
12362 | } | |
12363 | ||
12364 | static struct abbrev_info * | |
f3dd6933 | 12365 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
12366 | { |
12367 | struct abbrev_info *abbrev; | |
12368 | ||
f3dd6933 DJ |
12369 | abbrev = (struct abbrev_info *) |
12370 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
12371 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
12372 | return (abbrev); | |
12373 | } | |
12374 | ||
12375 | static struct die_info * | |
b60c80d6 | 12376 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
12377 | { |
12378 | struct die_info *die; | |
b60c80d6 DJ |
12379 | size_t size = sizeof (struct die_info); |
12380 | ||
12381 | if (num_attrs > 1) | |
12382 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 12383 | |
b60c80d6 | 12384 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
12385 | memset (die, 0, sizeof (struct die_info)); |
12386 | return (die); | |
12387 | } | |
2e276125 JB |
12388 | |
12389 | \f | |
12390 | /* Macro support. */ | |
12391 | ||
12392 | ||
12393 | /* Return the full name of file number I in *LH's file name table. | |
12394 | Use COMP_DIR as the name of the current directory of the | |
12395 | compilation. The result is allocated using xmalloc; the caller is | |
12396 | responsible for freeing it. */ | |
12397 | static char * | |
12398 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
12399 | { | |
6a83a1e6 EZ |
12400 | /* Is the file number a valid index into the line header's file name |
12401 | table? Remember that file numbers start with one, not zero. */ | |
12402 | if (1 <= file && file <= lh->num_file_names) | |
12403 | { | |
12404 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 12405 | |
6a83a1e6 EZ |
12406 | if (IS_ABSOLUTE_PATH (fe->name)) |
12407 | return xstrdup (fe->name); | |
12408 | else | |
12409 | { | |
12410 | const char *dir; | |
12411 | int dir_len; | |
12412 | char *full_name; | |
12413 | ||
12414 | if (fe->dir_index) | |
12415 | dir = lh->include_dirs[fe->dir_index - 1]; | |
12416 | else | |
12417 | dir = comp_dir; | |
12418 | ||
12419 | if (dir) | |
12420 | { | |
12421 | dir_len = strlen (dir); | |
12422 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
12423 | strcpy (full_name, dir); | |
12424 | full_name[dir_len] = '/'; | |
12425 | strcpy (full_name + dir_len + 1, fe->name); | |
12426 | return full_name; | |
12427 | } | |
12428 | else | |
12429 | return xstrdup (fe->name); | |
12430 | } | |
12431 | } | |
2e276125 JB |
12432 | else |
12433 | { | |
6a83a1e6 EZ |
12434 | /* The compiler produced a bogus file number. We can at least |
12435 | record the macro definitions made in the file, even if we | |
12436 | won't be able to find the file by name. */ | |
12437 | char fake_name[80]; | |
9a619af0 | 12438 | |
6a83a1e6 | 12439 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 12440 | |
6e70227d | 12441 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
12442 | _("bad file number in macro information (%d)"), |
12443 | file); | |
2e276125 | 12444 | |
6a83a1e6 | 12445 | return xstrdup (fake_name); |
2e276125 JB |
12446 | } |
12447 | } | |
12448 | ||
12449 | ||
12450 | static struct macro_source_file * | |
12451 | macro_start_file (int file, int line, | |
12452 | struct macro_source_file *current_file, | |
12453 | const char *comp_dir, | |
12454 | struct line_header *lh, struct objfile *objfile) | |
12455 | { | |
12456 | /* The full name of this source file. */ | |
12457 | char *full_name = file_full_name (file, lh, comp_dir); | |
12458 | ||
12459 | /* We don't create a macro table for this compilation unit | |
12460 | at all until we actually get a filename. */ | |
12461 | if (! pending_macros) | |
4a146b47 | 12462 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 12463 | objfile->macro_cache); |
2e276125 JB |
12464 | |
12465 | if (! current_file) | |
12466 | /* If we have no current file, then this must be the start_file | |
12467 | directive for the compilation unit's main source file. */ | |
12468 | current_file = macro_set_main (pending_macros, full_name); | |
12469 | else | |
12470 | current_file = macro_include (current_file, line, full_name); | |
12471 | ||
12472 | xfree (full_name); | |
6e70227d | 12473 | |
2e276125 JB |
12474 | return current_file; |
12475 | } | |
12476 | ||
12477 | ||
12478 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
12479 | followed by a null byte. */ | |
12480 | static char * | |
12481 | copy_string (const char *buf, int len) | |
12482 | { | |
12483 | char *s = xmalloc (len + 1); | |
9a619af0 | 12484 | |
2e276125 JB |
12485 | memcpy (s, buf, len); |
12486 | s[len] = '\0'; | |
2e276125 JB |
12487 | return s; |
12488 | } | |
12489 | ||
12490 | ||
12491 | static const char * | |
12492 | consume_improper_spaces (const char *p, const char *body) | |
12493 | { | |
12494 | if (*p == ' ') | |
12495 | { | |
4d3c2250 | 12496 | complaint (&symfile_complaints, |
e2e0b3e5 | 12497 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 12498 | body); |
2e276125 JB |
12499 | |
12500 | while (*p == ' ') | |
12501 | p++; | |
12502 | } | |
12503 | ||
12504 | return p; | |
12505 | } | |
12506 | ||
12507 | ||
12508 | static void | |
12509 | parse_macro_definition (struct macro_source_file *file, int line, | |
12510 | const char *body) | |
12511 | { | |
12512 | const char *p; | |
12513 | ||
12514 | /* The body string takes one of two forms. For object-like macro | |
12515 | definitions, it should be: | |
12516 | ||
12517 | <macro name> " " <definition> | |
12518 | ||
12519 | For function-like macro definitions, it should be: | |
12520 | ||
12521 | <macro name> "() " <definition> | |
12522 | or | |
12523 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
12524 | ||
12525 | Spaces may appear only where explicitly indicated, and in the | |
12526 | <definition>. | |
12527 | ||
12528 | The Dwarf 2 spec says that an object-like macro's name is always | |
12529 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 12530 | the space when the macro's definition is the empty string. |
2e276125 JB |
12531 | |
12532 | The Dwarf 2 spec says that there should be no spaces between the | |
12533 | formal arguments in a function-like macro's formal argument list, | |
12534 | but versions of GCC around March 2002 include spaces after the | |
12535 | commas. */ | |
12536 | ||
12537 | ||
12538 | /* Find the extent of the macro name. The macro name is terminated | |
12539 | by either a space or null character (for an object-like macro) or | |
12540 | an opening paren (for a function-like macro). */ | |
12541 | for (p = body; *p; p++) | |
12542 | if (*p == ' ' || *p == '(') | |
12543 | break; | |
12544 | ||
12545 | if (*p == ' ' || *p == '\0') | |
12546 | { | |
12547 | /* It's an object-like macro. */ | |
12548 | int name_len = p - body; | |
12549 | char *name = copy_string (body, name_len); | |
12550 | const char *replacement; | |
12551 | ||
12552 | if (*p == ' ') | |
12553 | replacement = body + name_len + 1; | |
12554 | else | |
12555 | { | |
4d3c2250 | 12556 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12557 | replacement = body + name_len; |
12558 | } | |
6e70227d | 12559 | |
2e276125 JB |
12560 | macro_define_object (file, line, name, replacement); |
12561 | ||
12562 | xfree (name); | |
12563 | } | |
12564 | else if (*p == '(') | |
12565 | { | |
12566 | /* It's a function-like macro. */ | |
12567 | char *name = copy_string (body, p - body); | |
12568 | int argc = 0; | |
12569 | int argv_size = 1; | |
12570 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
12571 | ||
12572 | p++; | |
12573 | ||
12574 | p = consume_improper_spaces (p, body); | |
12575 | ||
12576 | /* Parse the formal argument list. */ | |
12577 | while (*p && *p != ')') | |
12578 | { | |
12579 | /* Find the extent of the current argument name. */ | |
12580 | const char *arg_start = p; | |
12581 | ||
12582 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
12583 | p++; | |
12584 | ||
12585 | if (! *p || p == arg_start) | |
4d3c2250 | 12586 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12587 | else |
12588 | { | |
12589 | /* Make sure argv has room for the new argument. */ | |
12590 | if (argc >= argv_size) | |
12591 | { | |
12592 | argv_size *= 2; | |
12593 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
12594 | } | |
12595 | ||
12596 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
12597 | } | |
12598 | ||
12599 | p = consume_improper_spaces (p, body); | |
12600 | ||
12601 | /* Consume the comma, if present. */ | |
12602 | if (*p == ',') | |
12603 | { | |
12604 | p++; | |
12605 | ||
12606 | p = consume_improper_spaces (p, body); | |
12607 | } | |
12608 | } | |
12609 | ||
12610 | if (*p == ')') | |
12611 | { | |
12612 | p++; | |
12613 | ||
12614 | if (*p == ' ') | |
12615 | /* Perfectly formed definition, no complaints. */ | |
12616 | macro_define_function (file, line, name, | |
6e70227d | 12617 | argc, (const char **) argv, |
2e276125 JB |
12618 | p + 1); |
12619 | else if (*p == '\0') | |
12620 | { | |
12621 | /* Complain, but do define it. */ | |
4d3c2250 | 12622 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 12623 | macro_define_function (file, line, name, |
6e70227d | 12624 | argc, (const char **) argv, |
2e276125 JB |
12625 | p); |
12626 | } | |
12627 | else | |
12628 | /* Just complain. */ | |
4d3c2250 | 12629 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12630 | } |
12631 | else | |
12632 | /* Just complain. */ | |
4d3c2250 | 12633 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12634 | |
12635 | xfree (name); | |
12636 | { | |
12637 | int i; | |
12638 | ||
12639 | for (i = 0; i < argc; i++) | |
12640 | xfree (argv[i]); | |
12641 | } | |
12642 | xfree (argv); | |
12643 | } | |
12644 | else | |
4d3c2250 | 12645 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12646 | } |
12647 | ||
12648 | ||
12649 | static void | |
12650 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
12651 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 12652 | struct dwarf2_cu *cu) |
2e276125 | 12653 | { |
fe1b8b76 | 12654 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 12655 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
12656 | enum dwarf_macinfo_record_type macinfo_type; |
12657 | int at_commandline; | |
2e276125 | 12658 | |
be391dca TT |
12659 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
12660 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 12661 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 12662 | { |
e2e0b3e5 | 12663 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
12664 | return; |
12665 | } | |
12666 | ||
757a13d0 JK |
12667 | /* First pass: Find the name of the base filename. |
12668 | This filename is needed in order to process all macros whose definition | |
12669 | (or undefinition) comes from the command line. These macros are defined | |
12670 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
12671 | associated to the base file. | |
12672 | ||
12673 | To determine the base file name, we scan the macro definitions until we | |
12674 | reach the first DW_MACINFO_start_file entry. We then initialize | |
12675 | CURRENT_FILE accordingly so that any macro definition found before the | |
12676 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
12677 | ||
dce234bc PP |
12678 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
12679 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
12680 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 12681 | |
757a13d0 | 12682 | do |
2e276125 | 12683 | { |
2e276125 JB |
12684 | /* Do we at least have room for a macinfo type byte? */ |
12685 | if (mac_ptr >= mac_end) | |
12686 | { | |
757a13d0 JK |
12687 | /* Complaint is printed during the second pass as GDB will probably |
12688 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
12689 | break; | |
2e276125 JB |
12690 | } |
12691 | ||
12692 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
12693 | mac_ptr++; | |
12694 | ||
12695 | switch (macinfo_type) | |
12696 | { | |
12697 | /* A zero macinfo type indicates the end of the macro | |
12698 | information. */ | |
12699 | case 0: | |
757a13d0 JK |
12700 | break; |
12701 | ||
12702 | case DW_MACINFO_define: | |
12703 | case DW_MACINFO_undef: | |
12704 | /* Only skip the data by MAC_PTR. */ | |
12705 | { | |
12706 | unsigned int bytes_read; | |
12707 | ||
12708 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12709 | mac_ptr += bytes_read; | |
12710 | read_string (abfd, mac_ptr, &bytes_read); | |
12711 | mac_ptr += bytes_read; | |
12712 | } | |
12713 | break; | |
12714 | ||
12715 | case DW_MACINFO_start_file: | |
12716 | { | |
12717 | unsigned int bytes_read; | |
12718 | int line, file; | |
12719 | ||
12720 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12721 | mac_ptr += bytes_read; | |
12722 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12723 | mac_ptr += bytes_read; | |
12724 | ||
12725 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
12726 | lh, cu->objfile); | |
12727 | } | |
12728 | break; | |
12729 | ||
12730 | case DW_MACINFO_end_file: | |
12731 | /* No data to skip by MAC_PTR. */ | |
12732 | break; | |
12733 | ||
12734 | case DW_MACINFO_vendor_ext: | |
12735 | /* Only skip the data by MAC_PTR. */ | |
12736 | { | |
12737 | unsigned int bytes_read; | |
12738 | ||
12739 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12740 | mac_ptr += bytes_read; | |
12741 | read_string (abfd, mac_ptr, &bytes_read); | |
12742 | mac_ptr += bytes_read; | |
12743 | } | |
12744 | break; | |
12745 | ||
12746 | default: | |
12747 | break; | |
12748 | } | |
12749 | } while (macinfo_type != 0 && current_file == NULL); | |
12750 | ||
12751 | /* Second pass: Process all entries. | |
12752 | ||
12753 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
12754 | command-line macro definitions/undefinitions. This flag is unset when we | |
12755 | reach the first DW_MACINFO_start_file entry. */ | |
12756 | ||
dce234bc | 12757 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
12758 | |
12759 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
12760 | GDB is still reading the definitions from command line. First | |
12761 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
12762 | to create CURRENT_FILE for the main source holding also the command line | |
12763 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
12764 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
12765 | ||
12766 | at_commandline = 1; | |
12767 | ||
12768 | do | |
12769 | { | |
12770 | /* Do we at least have room for a macinfo type byte? */ | |
12771 | if (mac_ptr >= mac_end) | |
12772 | { | |
12773 | dwarf2_macros_too_long_complaint (); | |
12774 | break; | |
12775 | } | |
12776 | ||
12777 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
12778 | mac_ptr++; | |
12779 | ||
12780 | switch (macinfo_type) | |
12781 | { | |
12782 | /* A zero macinfo type indicates the end of the macro | |
12783 | information. */ | |
12784 | case 0: | |
12785 | break; | |
2e276125 JB |
12786 | |
12787 | case DW_MACINFO_define: | |
12788 | case DW_MACINFO_undef: | |
12789 | { | |
891d2f0b | 12790 | unsigned int bytes_read; |
2e276125 JB |
12791 | int line; |
12792 | char *body; | |
12793 | ||
12794 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12795 | mac_ptr += bytes_read; | |
12796 | body = read_string (abfd, mac_ptr, &bytes_read); | |
12797 | mac_ptr += bytes_read; | |
12798 | ||
12799 | if (! current_file) | |
757a13d0 JK |
12800 | { |
12801 | /* DWARF violation as no main source is present. */ | |
12802 | complaint (&symfile_complaints, | |
12803 | _("debug info with no main source gives macro %s " | |
12804 | "on line %d: %s"), | |
6e70227d DE |
12805 | macinfo_type == DW_MACINFO_define ? |
12806 | _("definition") : | |
905e0470 PM |
12807 | macinfo_type == DW_MACINFO_undef ? |
12808 | _("undefinition") : | |
12809 | _("something-or-other"), line, body); | |
757a13d0 JK |
12810 | break; |
12811 | } | |
12812 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 12813 | complaint (&symfile_complaints, |
757a13d0 JK |
12814 | _("debug info gives %s macro %s with %s line %d: %s"), |
12815 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 12816 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 12817 | _("definition") : |
905e0470 PM |
12818 | macinfo_type == DW_MACINFO_undef ? |
12819 | _("undefinition") : | |
12820 | _("something-or-other"), | |
757a13d0 JK |
12821 | line == 0 ? _("zero") : _("non-zero"), line, body); |
12822 | ||
12823 | if (macinfo_type == DW_MACINFO_define) | |
12824 | parse_macro_definition (current_file, line, body); | |
12825 | else if (macinfo_type == DW_MACINFO_undef) | |
12826 | macro_undef (current_file, line, body); | |
2e276125 JB |
12827 | } |
12828 | break; | |
12829 | ||
12830 | case DW_MACINFO_start_file: | |
12831 | { | |
891d2f0b | 12832 | unsigned int bytes_read; |
2e276125 JB |
12833 | int line, file; |
12834 | ||
12835 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12836 | mac_ptr += bytes_read; | |
12837 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12838 | mac_ptr += bytes_read; | |
12839 | ||
757a13d0 JK |
12840 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
12841 | complaint (&symfile_complaints, | |
12842 | _("debug info gives source %d included " | |
12843 | "from %s at %s line %d"), | |
12844 | file, at_commandline ? _("command-line") : _("file"), | |
12845 | line == 0 ? _("zero") : _("non-zero"), line); | |
12846 | ||
12847 | if (at_commandline) | |
12848 | { | |
12849 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
12850 | at_commandline = 0; | |
12851 | } | |
12852 | else | |
12853 | current_file = macro_start_file (file, line, | |
12854 | current_file, comp_dir, | |
12855 | lh, cu->objfile); | |
2e276125 JB |
12856 | } |
12857 | break; | |
12858 | ||
12859 | case DW_MACINFO_end_file: | |
12860 | if (! current_file) | |
4d3c2250 | 12861 | complaint (&symfile_complaints, |
e2e0b3e5 | 12862 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
12863 | else |
12864 | { | |
12865 | current_file = current_file->included_by; | |
12866 | if (! current_file) | |
12867 | { | |
12868 | enum dwarf_macinfo_record_type next_type; | |
12869 | ||
12870 | /* GCC circa March 2002 doesn't produce the zero | |
12871 | type byte marking the end of the compilation | |
12872 | unit. Complain if it's not there, but exit no | |
12873 | matter what. */ | |
12874 | ||
12875 | /* Do we at least have room for a macinfo type byte? */ | |
12876 | if (mac_ptr >= mac_end) | |
12877 | { | |
4d3c2250 | 12878 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
12879 | return; |
12880 | } | |
12881 | ||
12882 | /* We don't increment mac_ptr here, so this is just | |
12883 | a look-ahead. */ | |
12884 | next_type = read_1_byte (abfd, mac_ptr); | |
12885 | if (next_type != 0) | |
4d3c2250 | 12886 | complaint (&symfile_complaints, |
e2e0b3e5 | 12887 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
12888 | |
12889 | return; | |
12890 | } | |
12891 | } | |
12892 | break; | |
12893 | ||
12894 | case DW_MACINFO_vendor_ext: | |
12895 | { | |
891d2f0b | 12896 | unsigned int bytes_read; |
2e276125 JB |
12897 | int constant; |
12898 | char *string; | |
12899 | ||
12900 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12901 | mac_ptr += bytes_read; | |
12902 | string = read_string (abfd, mac_ptr, &bytes_read); | |
12903 | mac_ptr += bytes_read; | |
12904 | ||
12905 | /* We don't recognize any vendor extensions. */ | |
12906 | } | |
12907 | break; | |
12908 | } | |
757a13d0 | 12909 | } while (macinfo_type != 0); |
2e276125 | 12910 | } |
8e19ed76 PS |
12911 | |
12912 | /* Check if the attribute's form is a DW_FORM_block* | |
12913 | if so return true else false. */ | |
12914 | static int | |
12915 | attr_form_is_block (struct attribute *attr) | |
12916 | { | |
12917 | return (attr == NULL ? 0 : | |
12918 | attr->form == DW_FORM_block1 | |
12919 | || attr->form == DW_FORM_block2 | |
12920 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
12921 | || attr->form == DW_FORM_block |
12922 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 12923 | } |
4c2df51b | 12924 | |
c6a0999f JB |
12925 | /* Return non-zero if ATTR's value is a section offset --- classes |
12926 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
12927 | You may use DW_UNSND (attr) to retrieve such offsets. | |
12928 | ||
12929 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
12930 | may have a value that belongs to more than one of these classes; it | |
12931 | would be ambiguous if we did, because we use the same forms for all | |
12932 | of them. */ | |
3690dd37 JB |
12933 | static int |
12934 | attr_form_is_section_offset (struct attribute *attr) | |
12935 | { | |
12936 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
12937 | || attr->form == DW_FORM_data8 |
12938 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
12939 | } |
12940 | ||
12941 | ||
12942 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
12943 | zero otherwise. When this function returns true, you can apply | |
12944 | dwarf2_get_attr_constant_value to it. | |
12945 | ||
12946 | However, note that for some attributes you must check | |
12947 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
12948 | and DW_FORM_data8 are members of both the constant class, and of | |
12949 | the classes that contain offsets into other debug sections | |
12950 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
12951 | that, if an attribute's can be either a constant or one of the | |
12952 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
12953 | taken as section offsets, not constants. */ | |
12954 | static int | |
12955 | attr_form_is_constant (struct attribute *attr) | |
12956 | { | |
12957 | switch (attr->form) | |
12958 | { | |
12959 | case DW_FORM_sdata: | |
12960 | case DW_FORM_udata: | |
12961 | case DW_FORM_data1: | |
12962 | case DW_FORM_data2: | |
12963 | case DW_FORM_data4: | |
12964 | case DW_FORM_data8: | |
12965 | return 1; | |
12966 | default: | |
12967 | return 0; | |
12968 | } | |
12969 | } | |
12970 | ||
4c2df51b DJ |
12971 | static void |
12972 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 12973 | struct dwarf2_cu *cu) |
4c2df51b | 12974 | { |
3690dd37 | 12975 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
12976 | /* ".debug_loc" may not exist at all, or the offset may be outside |
12977 | the section. If so, fall through to the complaint in the | |
12978 | other branch. */ | |
dce234bc | 12979 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 12980 | { |
0d53c4c4 | 12981 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 12982 | |
4a146b47 | 12983 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 12984 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
12985 | baton->per_cu = cu->per_cu; |
12986 | gdb_assert (baton->per_cu); | |
4c2df51b | 12987 | |
be391dca TT |
12988 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
12989 | &dwarf2_per_objfile->loc); | |
12990 | ||
0d53c4c4 DJ |
12991 | /* We don't know how long the location list is, but make sure we |
12992 | don't run off the edge of the section. */ | |
dce234bc PP |
12993 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
12994 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
12995 | baton->base_address = cu->base_address; |
12996 | if (cu->base_known == 0) | |
0d53c4c4 | 12997 | complaint (&symfile_complaints, |
e2e0b3e5 | 12998 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 12999 | |
768a979c | 13000 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
13001 | SYMBOL_LOCATION_BATON (sym) = baton; |
13002 | } | |
13003 | else | |
13004 | { | |
13005 | struct dwarf2_locexpr_baton *baton; | |
13006 | ||
4a146b47 | 13007 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13008 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
13009 | baton->per_cu = cu->per_cu; |
13010 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
13011 | |
13012 | if (attr_form_is_block (attr)) | |
13013 | { | |
13014 | /* Note that we're just copying the block's data pointer | |
13015 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
13016 | info_buffer for SYM's objfile; right now we never release |
13017 | that buffer, but when we do clean up properly this may | |
13018 | need to change. */ | |
0d53c4c4 DJ |
13019 | baton->size = DW_BLOCK (attr)->size; |
13020 | baton->data = DW_BLOCK (attr)->data; | |
13021 | } | |
13022 | else | |
13023 | { | |
13024 | dwarf2_invalid_attrib_class_complaint ("location description", | |
13025 | SYMBOL_NATURAL_NAME (sym)); | |
13026 | baton->size = 0; | |
13027 | baton->data = NULL; | |
13028 | } | |
6e70227d | 13029 | |
768a979c | 13030 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
13031 | SYMBOL_LOCATION_BATON (sym) = baton; |
13032 | } | |
4c2df51b | 13033 | } |
6502dd73 | 13034 | |
9aa1f1e3 TT |
13035 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
13036 | came from a separate debuginfo file, then the master objfile is | |
13037 | returned. */ | |
ae0d2f24 UW |
13038 | |
13039 | struct objfile * | |
13040 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
13041 | { | |
9291a0cd | 13042 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13043 | |
13044 | /* Return the master objfile, so that we can report and look up the | |
13045 | correct file containing this variable. */ | |
13046 | if (objfile->separate_debug_objfile_backlink) | |
13047 | objfile = objfile->separate_debug_objfile_backlink; | |
13048 | ||
13049 | return objfile; | |
13050 | } | |
13051 | ||
13052 | /* Return the address size given in the compilation unit header for CU. */ | |
13053 | ||
13054 | CORE_ADDR | |
13055 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
13056 | { | |
13057 | if (per_cu->cu) | |
13058 | return per_cu->cu->header.addr_size; | |
13059 | else | |
13060 | { | |
13061 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 13062 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13063 | struct dwarf2_per_objfile *per_objfile |
13064 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 13065 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 13066 | struct comp_unit_head cu_header; |
9a619af0 | 13067 | |
ae0d2f24 UW |
13068 | memset (&cu_header, 0, sizeof cu_header); |
13069 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
13070 | return cu_header.addr_size; | |
13071 | } | |
13072 | } | |
13073 | ||
9eae7c52 TT |
13074 | /* Return the offset size given in the compilation unit header for CU. */ |
13075 | ||
13076 | int | |
13077 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
13078 | { | |
13079 | if (per_cu->cu) | |
13080 | return per_cu->cu->header.offset_size; | |
13081 | else | |
13082 | { | |
13083 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 13084 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
13085 | struct dwarf2_per_objfile *per_objfile |
13086 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
13087 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
13088 | struct comp_unit_head cu_header; | |
13089 | ||
13090 | memset (&cu_header, 0, sizeof cu_header); | |
13091 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
13092 | return cu_header.offset_size; | |
13093 | } | |
13094 | } | |
13095 | ||
9aa1f1e3 TT |
13096 | /* Return the text offset of the CU. The returned offset comes from |
13097 | this CU's objfile. If this objfile came from a separate debuginfo | |
13098 | file, then the offset may be different from the corresponding | |
13099 | offset in the parent objfile. */ | |
13100 | ||
13101 | CORE_ADDR | |
13102 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
13103 | { | |
bb3fa9d0 | 13104 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
13105 | |
13106 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
13107 | } | |
13108 | ||
348e048f DE |
13109 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
13110 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
13111 | |
13112 | static struct dwarf2_per_cu_data * | |
c764a876 | 13113 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
13114 | struct objfile *objfile) |
13115 | { | |
13116 | struct dwarf2_per_cu_data *this_cu; | |
13117 | int low, high; | |
13118 | ||
ae038cb0 DJ |
13119 | low = 0; |
13120 | high = dwarf2_per_objfile->n_comp_units - 1; | |
13121 | while (high > low) | |
13122 | { | |
13123 | int mid = low + (high - low) / 2; | |
9a619af0 | 13124 | |
ae038cb0 DJ |
13125 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
13126 | high = mid; | |
13127 | else | |
13128 | low = mid + 1; | |
13129 | } | |
13130 | gdb_assert (low == high); | |
13131 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
13132 | { | |
10b3939b | 13133 | if (low == 0) |
8a3fe4f8 AC |
13134 | error (_("Dwarf Error: could not find partial DIE containing " |
13135 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
13136 | (long) offset, bfd_get_filename (objfile->obfd)); |
13137 | ||
ae038cb0 DJ |
13138 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
13139 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
13140 | } | |
13141 | else | |
13142 | { | |
13143 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
13144 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
13145 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 13146 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
13147 | gdb_assert (offset < this_cu->offset + this_cu->length); |
13148 | return this_cu; | |
13149 | } | |
13150 | } | |
13151 | ||
10b3939b DJ |
13152 | /* Locate the compilation unit from OBJFILE which is located at exactly |
13153 | OFFSET. Raises an error on failure. */ | |
13154 | ||
ae038cb0 | 13155 | static struct dwarf2_per_cu_data * |
c764a876 | 13156 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
13157 | { |
13158 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 13159 | |
ae038cb0 DJ |
13160 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
13161 | if (this_cu->offset != offset) | |
c764a876 | 13162 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
13163 | return this_cu; |
13164 | } | |
13165 | ||
93311388 DE |
13166 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
13167 | ||
13168 | static struct dwarf2_cu * | |
13169 | alloc_one_comp_unit (struct objfile *objfile) | |
13170 | { | |
13171 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
13172 | cu->objfile = objfile; | |
13173 | obstack_init (&cu->comp_unit_obstack); | |
13174 | return cu; | |
13175 | } | |
13176 | ||
ae038cb0 DJ |
13177 | /* Release one cached compilation unit, CU. We unlink it from the tree |
13178 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
13179 | the caller is responsible for that. |
13180 | NOTE: DATA is a void * because this function is also used as a | |
13181 | cleanup routine. */ | |
ae038cb0 DJ |
13182 | |
13183 | static void | |
13184 | free_one_comp_unit (void *data) | |
13185 | { | |
13186 | struct dwarf2_cu *cu = data; | |
13187 | ||
13188 | if (cu->per_cu != NULL) | |
13189 | cu->per_cu->cu = NULL; | |
13190 | cu->per_cu = NULL; | |
13191 | ||
13192 | obstack_free (&cu->comp_unit_obstack, NULL); | |
13193 | ||
13194 | xfree (cu); | |
13195 | } | |
13196 | ||
72bf9492 | 13197 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
13198 | when we're finished with it. We can't free the pointer itself, but be |
13199 | sure to unlink it from the cache. Also release any associated storage | |
13200 | and perform cache maintenance. | |
72bf9492 DJ |
13201 | |
13202 | Only used during partial symbol parsing. */ | |
13203 | ||
13204 | static void | |
13205 | free_stack_comp_unit (void *data) | |
13206 | { | |
13207 | struct dwarf2_cu *cu = data; | |
13208 | ||
13209 | obstack_free (&cu->comp_unit_obstack, NULL); | |
13210 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
13211 | |
13212 | if (cu->per_cu != NULL) | |
13213 | { | |
13214 | /* This compilation unit is on the stack in our caller, so we | |
13215 | should not xfree it. Just unlink it. */ | |
13216 | cu->per_cu->cu = NULL; | |
13217 | cu->per_cu = NULL; | |
13218 | ||
13219 | /* If we had a per-cu pointer, then we may have other compilation | |
13220 | units loaded, so age them now. */ | |
13221 | age_cached_comp_units (); | |
13222 | } | |
13223 | } | |
13224 | ||
13225 | /* Free all cached compilation units. */ | |
13226 | ||
13227 | static void | |
13228 | free_cached_comp_units (void *data) | |
13229 | { | |
13230 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13231 | ||
13232 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13233 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13234 | while (per_cu != NULL) | |
13235 | { | |
13236 | struct dwarf2_per_cu_data *next_cu; | |
13237 | ||
13238 | next_cu = per_cu->cu->read_in_chain; | |
13239 | ||
13240 | free_one_comp_unit (per_cu->cu); | |
13241 | *last_chain = next_cu; | |
13242 | ||
13243 | per_cu = next_cu; | |
13244 | } | |
13245 | } | |
13246 | ||
13247 | /* Increase the age counter on each cached compilation unit, and free | |
13248 | any that are too old. */ | |
13249 | ||
13250 | static void | |
13251 | age_cached_comp_units (void) | |
13252 | { | |
13253 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13254 | ||
13255 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
13256 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13257 | while (per_cu != NULL) | |
13258 | { | |
13259 | per_cu->cu->last_used ++; | |
13260 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
13261 | dwarf2_mark (per_cu->cu); | |
13262 | per_cu = per_cu->cu->read_in_chain; | |
13263 | } | |
13264 | ||
13265 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13266 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13267 | while (per_cu != NULL) | |
13268 | { | |
13269 | struct dwarf2_per_cu_data *next_cu; | |
13270 | ||
13271 | next_cu = per_cu->cu->read_in_chain; | |
13272 | ||
13273 | if (!per_cu->cu->mark) | |
13274 | { | |
13275 | free_one_comp_unit (per_cu->cu); | |
13276 | *last_chain = next_cu; | |
13277 | } | |
13278 | else | |
13279 | last_chain = &per_cu->cu->read_in_chain; | |
13280 | ||
13281 | per_cu = next_cu; | |
13282 | } | |
13283 | } | |
13284 | ||
13285 | /* Remove a single compilation unit from the cache. */ | |
13286 | ||
13287 | static void | |
13288 | free_one_cached_comp_unit (void *target_cu) | |
13289 | { | |
13290 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13291 | ||
13292 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13293 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13294 | while (per_cu != NULL) | |
13295 | { | |
13296 | struct dwarf2_per_cu_data *next_cu; | |
13297 | ||
13298 | next_cu = per_cu->cu->read_in_chain; | |
13299 | ||
13300 | if (per_cu->cu == target_cu) | |
13301 | { | |
13302 | free_one_comp_unit (per_cu->cu); | |
13303 | *last_chain = next_cu; | |
13304 | break; | |
13305 | } | |
13306 | else | |
13307 | last_chain = &per_cu->cu->read_in_chain; | |
13308 | ||
13309 | per_cu = next_cu; | |
13310 | } | |
13311 | } | |
13312 | ||
fe3e1990 DJ |
13313 | /* Release all extra memory associated with OBJFILE. */ |
13314 | ||
13315 | void | |
13316 | dwarf2_free_objfile (struct objfile *objfile) | |
13317 | { | |
13318 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
13319 | ||
13320 | if (dwarf2_per_objfile == NULL) | |
13321 | return; | |
13322 | ||
13323 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
13324 | free_cached_comp_units (NULL); | |
13325 | ||
9291a0cd TT |
13326 | if (dwarf2_per_objfile->using_index) |
13327 | { | |
13328 | int i; | |
13329 | ||
13330 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
13331 | { | |
13332 | int j; | |
13333 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
13334 | ||
13335 | if (!cu->v.quick->lines) | |
13336 | continue; | |
13337 | ||
13338 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
13339 | { | |
13340 | if (cu->v.quick->file_names) | |
13341 | xfree ((void *) cu->v.quick->file_names[j]); | |
13342 | if (cu->v.quick->full_names) | |
13343 | xfree ((void *) cu->v.quick->full_names[j]); | |
13344 | } | |
13345 | ||
13346 | free_line_header (cu->v.quick->lines); | |
13347 | } | |
13348 | } | |
13349 | ||
fe3e1990 DJ |
13350 | /* Everything else should be on the objfile obstack. */ |
13351 | } | |
13352 | ||
1c379e20 DJ |
13353 | /* A pair of DIE offset and GDB type pointer. We store these |
13354 | in a hash table separate from the DIEs, and preserve them | |
13355 | when the DIEs are flushed out of cache. */ | |
13356 | ||
13357 | struct dwarf2_offset_and_type | |
13358 | { | |
13359 | unsigned int offset; | |
13360 | struct type *type; | |
13361 | }; | |
13362 | ||
13363 | /* Hash function for a dwarf2_offset_and_type. */ | |
13364 | ||
13365 | static hashval_t | |
13366 | offset_and_type_hash (const void *item) | |
13367 | { | |
13368 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 13369 | |
1c379e20 DJ |
13370 | return ofs->offset; |
13371 | } | |
13372 | ||
13373 | /* Equality function for a dwarf2_offset_and_type. */ | |
13374 | ||
13375 | static int | |
13376 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
13377 | { | |
13378 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
13379 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 13380 | |
1c379e20 DJ |
13381 | return ofs_lhs->offset == ofs_rhs->offset; |
13382 | } | |
13383 | ||
13384 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
13385 | table if necessary. For convenience, return TYPE. |
13386 | ||
13387 | The DIEs reading must have careful ordering to: | |
13388 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
13389 | reading current DIE. | |
13390 | * Not trying to dereference contents of still incompletely read in types | |
13391 | while reading in other DIEs. | |
13392 | * Enable referencing still incompletely read in types just by a pointer to | |
13393 | the type without accessing its fields. | |
13394 | ||
13395 | Therefore caller should follow these rules: | |
13396 | * Try to fetch any prerequisite types we may need to build this DIE type | |
13397 | before building the type and calling set_die_type. | |
13398 | * After building typer call set_die_type for current DIE as soon as | |
13399 | possible before fetching more types to complete the current type. | |
13400 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 13401 | |
f792889a | 13402 | static struct type * |
1c379e20 DJ |
13403 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
13404 | { | |
13405 | struct dwarf2_offset_and_type **slot, ofs; | |
13406 | ||
b4ba55a1 JB |
13407 | /* For Ada types, make sure that the gnat-specific data is always |
13408 | initialized (if not already set). There are a few types where | |
13409 | we should not be doing so, because the type-specific area is | |
13410 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
13411 | where the type-specific area is used to store the floatformat). | |
13412 | But this is not a problem, because the gnat-specific information | |
13413 | is actually not needed for these types. */ | |
13414 | if (need_gnat_info (cu) | |
13415 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
13416 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
13417 | && !HAVE_GNAT_AUX_INFO (type)) | |
13418 | INIT_GNAT_SPECIFIC (type); | |
13419 | ||
f792889a DJ |
13420 | if (cu->type_hash == NULL) |
13421 | { | |
13422 | gdb_assert (cu->per_cu != NULL); | |
13423 | cu->per_cu->type_hash | |
13424 | = htab_create_alloc_ex (cu->header.length / 24, | |
13425 | offset_and_type_hash, | |
13426 | offset_and_type_eq, | |
13427 | NULL, | |
13428 | &cu->objfile->objfile_obstack, | |
13429 | hashtab_obstack_allocate, | |
13430 | dummy_obstack_deallocate); | |
13431 | cu->type_hash = cu->per_cu->type_hash; | |
13432 | } | |
1c379e20 DJ |
13433 | |
13434 | ofs.offset = die->offset; | |
13435 | ofs.type = type; | |
13436 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 13437 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
13438 | if (*slot) |
13439 | complaint (&symfile_complaints, | |
13440 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
13441 | die->offset); | |
1c379e20 DJ |
13442 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
13443 | **slot = ofs; | |
f792889a | 13444 | return type; |
1c379e20 DJ |
13445 | } |
13446 | ||
f792889a DJ |
13447 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
13448 | not have a saved type. */ | |
1c379e20 DJ |
13449 | |
13450 | static struct type * | |
f792889a | 13451 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
13452 | { |
13453 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
13454 | htab_t type_hash = cu->type_hash; |
13455 | ||
13456 | if (type_hash == NULL) | |
13457 | return NULL; | |
1c379e20 DJ |
13458 | |
13459 | ofs.offset = die->offset; | |
13460 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
13461 | if (slot) | |
13462 | return slot->type; | |
13463 | else | |
13464 | return NULL; | |
13465 | } | |
13466 | ||
10b3939b DJ |
13467 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
13468 | ||
13469 | static void | |
13470 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
13471 | struct dwarf2_per_cu_data *ref_per_cu) | |
13472 | { | |
13473 | void **slot; | |
13474 | ||
13475 | if (cu->dependencies == NULL) | |
13476 | cu->dependencies | |
13477 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
13478 | NULL, &cu->comp_unit_obstack, | |
13479 | hashtab_obstack_allocate, | |
13480 | dummy_obstack_deallocate); | |
13481 | ||
13482 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
13483 | if (*slot == NULL) | |
13484 | *slot = ref_per_cu; | |
13485 | } | |
1c379e20 | 13486 | |
f504f079 DE |
13487 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
13488 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
13489 | cache that we must keep because we are keeping CU. */ |
13490 | ||
10b3939b DJ |
13491 | static int |
13492 | dwarf2_mark_helper (void **slot, void *data) | |
13493 | { | |
13494 | struct dwarf2_per_cu_data *per_cu; | |
13495 | ||
13496 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
13497 | if (per_cu->cu->mark) | |
13498 | return 1; | |
13499 | per_cu->cu->mark = 1; | |
13500 | ||
13501 | if (per_cu->cu->dependencies != NULL) | |
13502 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
13503 | ||
13504 | return 1; | |
13505 | } | |
13506 | ||
f504f079 DE |
13507 | /* Set the mark field in CU and in every other compilation unit in the |
13508 | cache that we must keep because we are keeping CU. */ | |
13509 | ||
ae038cb0 DJ |
13510 | static void |
13511 | dwarf2_mark (struct dwarf2_cu *cu) | |
13512 | { | |
13513 | if (cu->mark) | |
13514 | return; | |
13515 | cu->mark = 1; | |
10b3939b DJ |
13516 | if (cu->dependencies != NULL) |
13517 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
13518 | } |
13519 | ||
13520 | static void | |
13521 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
13522 | { | |
13523 | while (per_cu) | |
13524 | { | |
13525 | per_cu->cu->mark = 0; | |
13526 | per_cu = per_cu->cu->read_in_chain; | |
13527 | } | |
72bf9492 DJ |
13528 | } |
13529 | ||
72bf9492 DJ |
13530 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
13531 | is its offset in .debug_info for this objfile. */ | |
13532 | ||
13533 | static hashval_t | |
13534 | partial_die_hash (const void *item) | |
13535 | { | |
13536 | const struct partial_die_info *part_die = item; | |
9a619af0 | 13537 | |
72bf9492 DJ |
13538 | return part_die->offset; |
13539 | } | |
13540 | ||
13541 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
13542 | are equal if they have the same offset. */ | |
13543 | ||
13544 | static int | |
13545 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
13546 | { | |
13547 | const struct partial_die_info *part_die_lhs = item_lhs; | |
13548 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 13549 | |
72bf9492 DJ |
13550 | return part_die_lhs->offset == part_die_rhs->offset; |
13551 | } | |
13552 | ||
ae038cb0 DJ |
13553 | static struct cmd_list_element *set_dwarf2_cmdlist; |
13554 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
13555 | ||
13556 | static void | |
13557 | set_dwarf2_cmd (char *args, int from_tty) | |
13558 | { | |
13559 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
13560 | } | |
13561 | ||
13562 | static void | |
13563 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 13564 | { |
ae038cb0 DJ |
13565 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
13566 | } | |
13567 | ||
dce234bc PP |
13568 | /* If section described by INFO was mmapped, munmap it now. */ |
13569 | ||
13570 | static void | |
13571 | munmap_section_buffer (struct dwarf2_section_info *info) | |
13572 | { | |
13573 | if (info->was_mmapped) | |
13574 | { | |
13575 | #ifdef HAVE_MMAP | |
13576 | intptr_t begin = (intptr_t) info->buffer; | |
13577 | intptr_t map_begin = begin & ~(pagesize - 1); | |
13578 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 13579 | |
dce234bc PP |
13580 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
13581 | #else | |
13582 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
13583 | gdb_assert (0); | |
13584 | #endif | |
13585 | } | |
13586 | } | |
13587 | ||
13588 | /* munmap debug sections for OBJFILE, if necessary. */ | |
13589 | ||
13590 | static void | |
c1bd65d0 | 13591 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
13592 | { |
13593 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 13594 | |
dce234bc PP |
13595 | munmap_section_buffer (&data->info); |
13596 | munmap_section_buffer (&data->abbrev); | |
13597 | munmap_section_buffer (&data->line); | |
13598 | munmap_section_buffer (&data->str); | |
13599 | munmap_section_buffer (&data->macinfo); | |
13600 | munmap_section_buffer (&data->ranges); | |
13601 | munmap_section_buffer (&data->loc); | |
13602 | munmap_section_buffer (&data->frame); | |
13603 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
13604 | munmap_section_buffer (&data->gdb_index); |
13605 | } | |
13606 | ||
13607 | \f | |
13608 | ||
13609 | /* The contents of the hash table we create when building the string | |
13610 | table. */ | |
13611 | struct strtab_entry | |
13612 | { | |
13613 | offset_type offset; | |
13614 | const char *str; | |
13615 | }; | |
13616 | ||
13617 | /* Hash function for a strtab_entry. */ | |
13618 | static hashval_t | |
13619 | hash_strtab_entry (const void *e) | |
13620 | { | |
13621 | const struct strtab_entry *entry = e; | |
13622 | return mapped_index_string_hash (entry->str); | |
13623 | } | |
13624 | ||
13625 | /* Equality function for a strtab_entry. */ | |
13626 | static int | |
13627 | eq_strtab_entry (const void *a, const void *b) | |
13628 | { | |
13629 | const struct strtab_entry *ea = a; | |
13630 | const struct strtab_entry *eb = b; | |
13631 | return !strcmp (ea->str, eb->str); | |
13632 | } | |
13633 | ||
13634 | /* Create a strtab_entry hash table. */ | |
13635 | static htab_t | |
13636 | create_strtab (void) | |
13637 | { | |
13638 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
13639 | xfree, xcalloc, xfree); | |
13640 | } | |
13641 | ||
13642 | /* Add a string to the constant pool. Return the string's offset in | |
13643 | host order. */ | |
13644 | static offset_type | |
13645 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
13646 | { | |
13647 | void **slot; | |
13648 | struct strtab_entry entry; | |
13649 | struct strtab_entry *result; | |
13650 | ||
13651 | entry.str = str; | |
13652 | slot = htab_find_slot (table, &entry, INSERT); | |
13653 | if (*slot) | |
13654 | result = *slot; | |
13655 | else | |
13656 | { | |
13657 | result = XNEW (struct strtab_entry); | |
13658 | result->offset = obstack_object_size (cpool); | |
13659 | result->str = str; | |
13660 | obstack_grow_str0 (cpool, str); | |
13661 | *slot = result; | |
13662 | } | |
13663 | return result->offset; | |
13664 | } | |
13665 | ||
13666 | /* An entry in the symbol table. */ | |
13667 | struct symtab_index_entry | |
13668 | { | |
13669 | /* The name of the symbol. */ | |
13670 | const char *name; | |
13671 | /* The offset of the name in the constant pool. */ | |
13672 | offset_type index_offset; | |
13673 | /* A sorted vector of the indices of all the CUs that hold an object | |
13674 | of this name. */ | |
13675 | VEC (offset_type) *cu_indices; | |
13676 | }; | |
13677 | ||
13678 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
13679 | struct mapped_symtab | |
13680 | { | |
13681 | offset_type n_elements; | |
13682 | offset_type size; | |
13683 | struct symtab_index_entry **data; | |
13684 | }; | |
13685 | ||
13686 | /* Hash function for a symtab_index_entry. */ | |
13687 | static hashval_t | |
13688 | hash_symtab_entry (const void *e) | |
13689 | { | |
13690 | const struct symtab_index_entry *entry = e; | |
13691 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
13692 | sizeof (offset_type) * VEC_length (offset_type, | |
13693 | entry->cu_indices), | |
13694 | 0); | |
13695 | } | |
13696 | ||
13697 | /* Equality function for a symtab_index_entry. */ | |
13698 | static int | |
13699 | eq_symtab_entry (const void *a, const void *b) | |
13700 | { | |
13701 | const struct symtab_index_entry *ea = a; | |
13702 | const struct symtab_index_entry *eb = b; | |
13703 | int len = VEC_length (offset_type, ea->cu_indices); | |
13704 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
13705 | return 0; | |
13706 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
13707 | VEC_address (offset_type, eb->cu_indices), | |
13708 | sizeof (offset_type) * len); | |
13709 | } | |
13710 | ||
13711 | /* Destroy a symtab_index_entry. */ | |
13712 | static void | |
13713 | delete_symtab_entry (void *p) | |
13714 | { | |
13715 | struct symtab_index_entry *entry = p; | |
13716 | VEC_free (offset_type, entry->cu_indices); | |
13717 | xfree (entry); | |
13718 | } | |
13719 | ||
13720 | /* Create a hash table holding symtab_index_entry objects. */ | |
13721 | static htab_t | |
13722 | create_index_table (void) | |
13723 | { | |
13724 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
13725 | delete_symtab_entry, xcalloc, xfree); | |
13726 | } | |
13727 | ||
13728 | /* Create a new mapped symtab object. */ | |
13729 | static struct mapped_symtab * | |
13730 | create_mapped_symtab (void) | |
13731 | { | |
13732 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
13733 | symtab->n_elements = 0; | |
13734 | symtab->size = 1024; | |
13735 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
13736 | return symtab; | |
13737 | } | |
13738 | ||
13739 | /* Destroy a mapped_symtab. */ | |
13740 | static void | |
13741 | cleanup_mapped_symtab (void *p) | |
13742 | { | |
13743 | struct mapped_symtab *symtab = p; | |
13744 | /* The contents of the array are freed when the other hash table is | |
13745 | destroyed. */ | |
13746 | xfree (symtab->data); | |
13747 | xfree (symtab); | |
13748 | } | |
13749 | ||
13750 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
13751 | the slot. */ | |
13752 | static struct symtab_index_entry ** | |
13753 | find_slot (struct mapped_symtab *symtab, const char *name) | |
13754 | { | |
13755 | offset_type index, step, hash = mapped_index_string_hash (name); | |
13756 | ||
13757 | index = hash & (symtab->size - 1); | |
13758 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
13759 | ||
13760 | for (;;) | |
13761 | { | |
13762 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
13763 | return &symtab->data[index]; | |
13764 | index = (index + step) & (symtab->size - 1); | |
13765 | } | |
13766 | } | |
13767 | ||
13768 | /* Expand SYMTAB's hash table. */ | |
13769 | static void | |
13770 | hash_expand (struct mapped_symtab *symtab) | |
13771 | { | |
13772 | offset_type old_size = symtab->size; | |
13773 | offset_type i; | |
13774 | struct symtab_index_entry **old_entries = symtab->data; | |
13775 | ||
13776 | symtab->size *= 2; | |
13777 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
13778 | ||
13779 | for (i = 0; i < old_size; ++i) | |
13780 | { | |
13781 | if (old_entries[i]) | |
13782 | { | |
13783 | struct symtab_index_entry **slot = find_slot (symtab, | |
13784 | old_entries[i]->name); | |
13785 | *slot = old_entries[i]; | |
13786 | } | |
13787 | } | |
13788 | ||
13789 | xfree (old_entries); | |
13790 | } | |
13791 | ||
13792 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
13793 | is the index of the CU in which the symbol appears. */ | |
13794 | static void | |
13795 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
13796 | offset_type cu_index) | |
13797 | { | |
13798 | struct symtab_index_entry **slot; | |
13799 | ||
13800 | ++symtab->n_elements; | |
13801 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
13802 | hash_expand (symtab); | |
13803 | ||
13804 | slot = find_slot (symtab, name); | |
13805 | if (!*slot) | |
13806 | { | |
13807 | *slot = XNEW (struct symtab_index_entry); | |
13808 | (*slot)->name = name; | |
13809 | (*slot)->cu_indices = NULL; | |
13810 | } | |
13811 | /* Don't push an index twice. Due to how we add entries we only | |
13812 | have to check the last one. */ | |
13813 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
13814 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) | |
13815 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); | |
13816 | } | |
13817 | ||
13818 | /* Add a vector of indices to the constant pool. */ | |
13819 | static offset_type | |
13820 | add_indices_to_cpool (htab_t index_table, struct obstack *cpool, | |
13821 | struct symtab_index_entry *entry) | |
13822 | { | |
13823 | void **slot; | |
13824 | ||
13825 | slot = htab_find_slot (index_table, entry, INSERT); | |
13826 | if (!*slot) | |
13827 | { | |
13828 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
13829 | offset_type val = MAYBE_SWAP (len); | |
13830 | offset_type iter; | |
13831 | int i; | |
13832 | ||
13833 | *slot = entry; | |
13834 | entry->index_offset = obstack_object_size (cpool); | |
13835 | ||
13836 | obstack_grow (cpool, &val, sizeof (val)); | |
13837 | for (i = 0; | |
13838 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
13839 | ++i) | |
13840 | { | |
13841 | val = MAYBE_SWAP (iter); | |
13842 | obstack_grow (cpool, &val, sizeof (val)); | |
13843 | } | |
13844 | } | |
13845 | else | |
13846 | { | |
13847 | struct symtab_index_entry *old_entry = *slot; | |
13848 | entry->index_offset = old_entry->index_offset; | |
13849 | entry = old_entry; | |
13850 | } | |
13851 | return entry->index_offset; | |
13852 | } | |
13853 | ||
13854 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
13855 | constant pool entries going into the obstack CPOOL. */ | |
13856 | static void | |
13857 | write_hash_table (struct mapped_symtab *symtab, | |
13858 | struct obstack *output, struct obstack *cpool) | |
13859 | { | |
13860 | offset_type i; | |
13861 | htab_t index_table; | |
13862 | htab_t str_table; | |
13863 | ||
13864 | index_table = create_index_table (); | |
13865 | str_table = create_strtab (); | |
13866 | /* We add all the index vectors to the constant pool first, to | |
13867 | ensure alignment is ok. */ | |
13868 | for (i = 0; i < symtab->size; ++i) | |
13869 | { | |
13870 | if (symtab->data[i]) | |
13871 | add_indices_to_cpool (index_table, cpool, symtab->data[i]); | |
13872 | } | |
13873 | ||
13874 | /* Now write out the hash table. */ | |
13875 | for (i = 0; i < symtab->size; ++i) | |
13876 | { | |
13877 | offset_type str_off, vec_off; | |
13878 | ||
13879 | if (symtab->data[i]) | |
13880 | { | |
13881 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
13882 | vec_off = symtab->data[i]->index_offset; | |
13883 | } | |
13884 | else | |
13885 | { | |
13886 | /* While 0 is a valid constant pool index, it is not valid | |
13887 | to have 0 for both offsets. */ | |
13888 | str_off = 0; | |
13889 | vec_off = 0; | |
13890 | } | |
13891 | ||
13892 | str_off = MAYBE_SWAP (str_off); | |
13893 | vec_off = MAYBE_SWAP (vec_off); | |
13894 | ||
13895 | obstack_grow (output, &str_off, sizeof (str_off)); | |
13896 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
13897 | } | |
13898 | ||
13899 | htab_delete (str_table); | |
13900 | htab_delete (index_table); | |
13901 | } | |
13902 | ||
13903 | /* Write an address entry to ADDR_OBSTACK. The addresses are taken | |
13904 | from PST; CU_INDEX is the index of the CU in the vector of all | |
13905 | CUs. */ | |
13906 | static void | |
13907 | add_address_entry (struct objfile *objfile, | |
13908 | struct obstack *addr_obstack, struct partial_symtab *pst, | |
13909 | unsigned int cu_index) | |
13910 | { | |
13911 | offset_type offset; | |
13912 | char addr[8]; | |
13913 | CORE_ADDR baseaddr; | |
13914 | ||
13915 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
13916 | ||
13917 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr); | |
13918 | obstack_grow (addr_obstack, addr, 8); | |
13919 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr); | |
13920 | obstack_grow (addr_obstack, addr, 8); | |
13921 | offset = MAYBE_SWAP (cu_index); | |
13922 | obstack_grow (addr_obstack, &offset, sizeof (offset_type)); | |
13923 | } | |
13924 | ||
13925 | /* Add a list of partial symbols to SYMTAB. */ | |
13926 | static void | |
13927 | write_psymbols (struct mapped_symtab *symtab, | |
13928 | struct partial_symbol **psymp, | |
13929 | int count, | |
13930 | offset_type cu_index) | |
13931 | { | |
13932 | for (; count-- > 0; ++psymp) | |
13933 | { | |
13934 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) | |
13935 | error (_("Ada is not currently supported by the index")); | |
13936 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
13937 | } | |
13938 | } | |
13939 | ||
13940 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
13941 | exception if there is an error. */ | |
13942 | static void | |
13943 | write_obstack (FILE *file, struct obstack *obstack) | |
13944 | { | |
13945 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
13946 | file) | |
13947 | != obstack_object_size (obstack)) | |
13948 | error (_("couldn't data write to file")); | |
13949 | } | |
13950 | ||
13951 | /* Unlink a file if the argument is not NULL. */ | |
13952 | static void | |
13953 | unlink_if_set (void *p) | |
13954 | { | |
13955 | char **filename = p; | |
13956 | if (*filename) | |
13957 | unlink (*filename); | |
13958 | } | |
13959 | ||
13960 | /* Create an index file for OBJFILE in the directory DIR. */ | |
13961 | static void | |
13962 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
13963 | { | |
13964 | struct cleanup *cleanup; | |
13965 | char *filename, *cleanup_filename; | |
13966 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack, cu_list; | |
13967 | int i; | |
13968 | FILE *out_file; | |
13969 | struct mapped_symtab *symtab; | |
13970 | offset_type val, size_of_contents, total_len; | |
13971 | struct stat st; | |
13972 | char buf[8]; | |
13973 | ||
13974 | if (!objfile->psymtabs) | |
13975 | return; | |
13976 | if (dwarf2_per_objfile->using_index) | |
13977 | error (_("Cannot use an index to create the index")); | |
13978 | ||
13979 | if (stat (objfile->name, &st) < 0) | |
13980 | perror_with_name (_("Could not stat")); | |
13981 | ||
13982 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
13983 | INDEX_SUFFIX, (char *) NULL); | |
13984 | cleanup = make_cleanup (xfree, filename); | |
13985 | ||
13986 | out_file = fopen (filename, "wb"); | |
13987 | if (!out_file) | |
13988 | error (_("Can't open `%s' for writing"), filename); | |
13989 | ||
13990 | cleanup_filename = filename; | |
13991 | make_cleanup (unlink_if_set, &cleanup_filename); | |
13992 | ||
13993 | symtab = create_mapped_symtab (); | |
13994 | make_cleanup (cleanup_mapped_symtab, symtab); | |
13995 | ||
13996 | obstack_init (&addr_obstack); | |
13997 | make_cleanup_obstack_free (&addr_obstack); | |
13998 | ||
13999 | obstack_init (&cu_list); | |
14000 | make_cleanup_obstack_free (&cu_list); | |
14001 | ||
14002 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
14003 | { | |
14004 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
14005 | struct partial_symtab *psymtab = cu->v.psymtab; | |
14006 | gdb_byte val[8]; | |
14007 | ||
14008 | write_psymbols (symtab, | |
14009 | objfile->global_psymbols.list + psymtab->globals_offset, | |
14010 | psymtab->n_global_syms, i); | |
14011 | write_psymbols (symtab, | |
14012 | objfile->static_psymbols.list + psymtab->statics_offset, | |
14013 | psymtab->n_static_syms, i); | |
14014 | ||
14015 | add_address_entry (objfile, &addr_obstack, psymtab, i); | |
14016 | ||
14017 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset); | |
14018 | obstack_grow (&cu_list, val, 8); | |
14019 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length); | |
14020 | obstack_grow (&cu_list, val, 8); | |
14021 | } | |
14022 | ||
14023 | obstack_init (&constant_pool); | |
14024 | make_cleanup_obstack_free (&constant_pool); | |
14025 | obstack_init (&symtab_obstack); | |
14026 | make_cleanup_obstack_free (&symtab_obstack); | |
14027 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
14028 | ||
14029 | obstack_init (&contents); | |
14030 | make_cleanup_obstack_free (&contents); | |
14031 | size_of_contents = 5 * sizeof (offset_type); | |
14032 | total_len = size_of_contents; | |
14033 | ||
14034 | /* The version number. */ | |
14035 | val = MAYBE_SWAP (1); | |
14036 | obstack_grow (&contents, &val, sizeof (val)); | |
14037 | ||
14038 | /* The offset of the CU list from the start of the file. */ | |
14039 | val = MAYBE_SWAP (total_len); | |
14040 | obstack_grow (&contents, &val, sizeof (val)); | |
14041 | total_len += obstack_object_size (&cu_list); | |
14042 | ||
14043 | /* The offset of the address table from the start of the file. */ | |
14044 | val = MAYBE_SWAP (total_len); | |
14045 | obstack_grow (&contents, &val, sizeof (val)); | |
14046 | total_len += obstack_object_size (&addr_obstack); | |
14047 | ||
14048 | /* The offset of the symbol table from the start of the file. */ | |
14049 | val = MAYBE_SWAP (total_len); | |
14050 | obstack_grow (&contents, &val, sizeof (val)); | |
14051 | total_len += obstack_object_size (&symtab_obstack); | |
14052 | ||
14053 | /* The offset of the constant pool from the start of the file. */ | |
14054 | val = MAYBE_SWAP (total_len); | |
14055 | obstack_grow (&contents, &val, sizeof (val)); | |
14056 | total_len += obstack_object_size (&constant_pool); | |
14057 | ||
14058 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
14059 | ||
14060 | write_obstack (out_file, &contents); | |
14061 | write_obstack (out_file, &cu_list); | |
14062 | write_obstack (out_file, &addr_obstack); | |
14063 | write_obstack (out_file, &symtab_obstack); | |
14064 | write_obstack (out_file, &constant_pool); | |
14065 | ||
14066 | fclose (out_file); | |
14067 | ||
14068 | /* We want to keep the file, so we set cleanup_filename to NULL | |
14069 | here. See unlink_if_set. */ | |
14070 | cleanup_filename = NULL; | |
14071 | ||
14072 | do_cleanups (cleanup); | |
14073 | } | |
14074 | ||
14075 | /* The mapped index file format is designed to be directly mmap()able | |
14076 | on any architecture. In most cases, a datum is represented using a | |
14077 | little-endian 32-bit integer value, called an offset_type. Big | |
14078 | endian machines must byte-swap the values before using them. | |
14079 | Exceptions to this rule are noted. The data is laid out such that | |
14080 | alignment is always respected. | |
14081 | ||
14082 | A mapped index consists of several sections. | |
14083 | ||
14084 | 1. The file header. This is a sequence of values, of offset_type | |
14085 | unless otherwise noted: | |
14086 | [0] The version number. Currently 1. | |
14087 | [1] The offset, from the start of the file, of the CU list. | |
14088 | [2] The offset, from the start of the file, of the address section. | |
14089 | [3] The offset, from the start of the file, of the symbol table. | |
14090 | [4] The offset, from the start of the file, of the constant pool. | |
14091 | ||
14092 | 2. The CU list. This is a sequence of pairs of 64-bit | |
14093 | little-endian values. The first element in each pair is the offset | |
14094 | of a CU in the .debug_info section. The second element in each | |
14095 | pair is the length of that CU. References to a CU elsewhere in the | |
14096 | map are done using a CU index, which is just the 0-based index into | |
14097 | this table. | |
14098 | ||
14099 | 3. The address section. The address section consists of a sequence | |
14100 | of address entries. Each address entry has three elements. | |
14101 | [0] The low address. This is a 64-bit little-endian value. | |
14102 | [1] The high address. This is a 64-bit little-endian value. | |
14103 | [2] The CU index. This is an offset_type value. | |
14104 | ||
14105 | 4. The symbol table. This is a hash table. The size of the hash | |
14106 | table is always a power of 2. The initial hash and the step are | |
14107 | currently defined by the `find_slot' function. | |
14108 | ||
14109 | Each slot in the hash table consists of a pair of offset_type | |
14110 | values. The first value is the offset of the symbol's name in the | |
14111 | constant pool. The second value is the offset of the CU vector in | |
14112 | the constant pool. | |
14113 | ||
14114 | If both values are 0, then this slot in the hash table is empty. | |
14115 | This is ok because while 0 is a valid constant pool index, it | |
14116 | cannot be a valid index for both a string and a CU vector. | |
14117 | ||
14118 | A string in the constant pool is stored as a \0-terminated string, | |
14119 | as you'd expect. | |
14120 | ||
14121 | A CU vector in the constant pool is a sequence of offset_type | |
14122 | values. The first value is the number of CU indices in the vector. | |
14123 | Each subsequent value is the index of a CU in the CU list. This | |
14124 | element in the hash table is used to indicate which CUs define the | |
14125 | symbol. | |
14126 | ||
14127 | 5. The constant pool. This is simply a bunch of bytes. It is | |
14128 | organized so that alignment is correct: CU vectors are stored | |
14129 | first, followed by strings. */ | |
14130 | static void | |
14131 | save_gdb_index_command (char *arg, int from_tty) | |
14132 | { | |
14133 | struct objfile *objfile; | |
14134 | ||
14135 | if (!arg || !*arg) | |
96d19272 | 14136 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
14137 | |
14138 | ALL_OBJFILES (objfile) | |
14139 | { | |
14140 | struct stat st; | |
14141 | ||
14142 | /* If the objfile does not correspond to an actual file, skip it. */ | |
14143 | if (stat (objfile->name, &st) < 0) | |
14144 | continue; | |
14145 | ||
14146 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
14147 | if (dwarf2_per_objfile) | |
14148 | { | |
14149 | volatile struct gdb_exception except; | |
14150 | ||
14151 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
14152 | { | |
14153 | write_psymtabs_to_index (objfile, arg); | |
14154 | } | |
14155 | if (except.reason < 0) | |
14156 | exception_fprintf (gdb_stderr, except, | |
14157 | _("Error while writing index for `%s': "), | |
14158 | objfile->name); | |
14159 | } | |
14160 | } | |
dce234bc PP |
14161 | } |
14162 | ||
9291a0cd TT |
14163 | \f |
14164 | ||
9eae7c52 TT |
14165 | int dwarf2_always_disassemble; |
14166 | ||
14167 | static void | |
14168 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
14169 | struct cmd_list_element *c, const char *value) | |
14170 | { | |
14171 | fprintf_filtered (file, _("\ | |
14172 | Whether to always disassemble DWARF expressions is %s.\n"), | |
14173 | value); | |
14174 | } | |
14175 | ||
6502dd73 DJ |
14176 | void _initialize_dwarf2_read (void); |
14177 | ||
14178 | void | |
14179 | _initialize_dwarf2_read (void) | |
14180 | { | |
96d19272 JK |
14181 | struct cmd_list_element *c; |
14182 | ||
dce234bc | 14183 | dwarf2_objfile_data_key |
c1bd65d0 | 14184 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 14185 | |
1bedd215 AC |
14186 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
14187 | Set DWARF 2 specific variables.\n\ | |
14188 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
14189 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
14190 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
14191 | ||
1bedd215 AC |
14192 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
14193 | Show DWARF 2 specific variables\n\ | |
14194 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
14195 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
14196 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
14197 | ||
14198 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
14199 | &dwarf2_max_cache_age, _("\ |
14200 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
14201 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
14202 | A higher limit means that cached compilation units will be stored\n\ | |
14203 | in memory longer, and more total memory will be used. Zero disables\n\ | |
14204 | caching, which can slow down startup."), | |
2c5b56ce | 14205 | NULL, |
920d2a44 | 14206 | show_dwarf2_max_cache_age, |
2c5b56ce | 14207 | &set_dwarf2_cmdlist, |
ae038cb0 | 14208 | &show_dwarf2_cmdlist); |
d97bc12b | 14209 | |
9eae7c52 TT |
14210 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
14211 | &dwarf2_always_disassemble, _("\ | |
14212 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
14213 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
14214 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
14215 | syntax. When disabled, expressions will be printed in a more\n\ | |
14216 | conversational style, when possible."), | |
14217 | NULL, | |
14218 | show_dwarf2_always_disassemble, | |
14219 | &set_dwarf2_cmdlist, | |
14220 | &show_dwarf2_cmdlist); | |
14221 | ||
d97bc12b DE |
14222 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
14223 | Set debugging of the dwarf2 DIE reader."), _("\ | |
14224 | Show debugging of the dwarf2 DIE reader."), _("\ | |
14225 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
14226 | The value is the maximum depth to print."), | |
14227 | NULL, | |
14228 | NULL, | |
14229 | &setdebuglist, &showdebuglist); | |
9291a0cd | 14230 | |
96d19272 JK |
14231 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
14232 | _("Save a .gdb-index file"), | |
14233 | &save_cmdlist); | |
14234 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 14235 | } |