]>
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" | |
4c2df51b | 56 | |
c906108c SS |
57 | #include <fcntl.h> |
58 | #include "gdb_string.h" | |
4bdf3d34 | 59 | #include "gdb_assert.h" |
c906108c | 60 | #include <sys/types.h> |
233a11ab CS |
61 | #ifdef HAVE_ZLIB_H |
62 | #include <zlib.h> | |
63 | #endif | |
dce234bc PP |
64 | #ifdef HAVE_MMAP |
65 | #include <sys/mman.h> | |
85d9bd0e TT |
66 | #ifndef MAP_FAILED |
67 | #define MAP_FAILED ((void *) -1) | |
68 | #endif | |
dce234bc | 69 | #endif |
d8151005 | 70 | |
107d2387 | 71 | #if 0 |
357e46e7 | 72 | /* .debug_info header for a compilation unit |
c906108c SS |
73 | Because of alignment constraints, this structure has padding and cannot |
74 | be mapped directly onto the beginning of the .debug_info section. */ | |
75 | typedef struct comp_unit_header | |
76 | { | |
77 | unsigned int length; /* length of the .debug_info | |
78 | contribution */ | |
79 | unsigned short version; /* version number -- 2 for DWARF | |
80 | version 2 */ | |
81 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
82 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
83 | } | |
84 | _COMP_UNIT_HEADER; | |
85 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 86 | #endif |
c906108c | 87 | |
c906108c SS |
88 | /* .debug_line statement program prologue |
89 | Because of alignment constraints, this structure has padding and cannot | |
90 | be mapped directly onto the beginning of the .debug_info section. */ | |
91 | typedef struct statement_prologue | |
92 | { | |
93 | unsigned int total_length; /* byte length of the statement | |
94 | information */ | |
95 | unsigned short version; /* version number -- 2 for DWARF | |
96 | version 2 */ | |
97 | unsigned int prologue_length; /* # bytes between prologue & | |
98 | stmt program */ | |
99 | unsigned char minimum_instruction_length; /* byte size of | |
100 | smallest instr */ | |
101 | unsigned char default_is_stmt; /* initial value of is_stmt | |
102 | register */ | |
103 | char line_base; | |
104 | unsigned char line_range; | |
105 | unsigned char opcode_base; /* number assigned to first special | |
106 | opcode */ | |
107 | unsigned char *standard_opcode_lengths; | |
108 | } | |
109 | _STATEMENT_PROLOGUE; | |
110 | ||
d97bc12b DE |
111 | /* When non-zero, dump DIEs after they are read in. */ |
112 | static int dwarf2_die_debug = 0; | |
113 | ||
dce234bc PP |
114 | static int pagesize; |
115 | ||
df8a16a1 DJ |
116 | /* When set, the file that we're processing is known to have debugging |
117 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
118 | but later versions do. */ | |
119 | ||
120 | static int processing_has_namespace_info; | |
121 | ||
6502dd73 DJ |
122 | static const struct objfile_data *dwarf2_objfile_data_key; |
123 | ||
dce234bc PP |
124 | struct dwarf2_section_info |
125 | { | |
126 | asection *asection; | |
127 | gdb_byte *buffer; | |
128 | bfd_size_type size; | |
129 | int was_mmapped; | |
be391dca TT |
130 | /* True if we have tried to read this section. */ |
131 | int readin; | |
dce234bc PP |
132 | }; |
133 | ||
9291a0cd TT |
134 | /* All offsets in the index are of this type. It must be |
135 | architecture-independent. */ | |
136 | typedef uint32_t offset_type; | |
137 | ||
138 | DEF_VEC_I (offset_type); | |
139 | ||
140 | /* A description of the mapped index. The file format is described in | |
141 | a comment by the code that writes the index. */ | |
142 | struct mapped_index | |
143 | { | |
144 | /* The total length of the buffer. */ | |
145 | off_t total_size; | |
146 | /* A pointer to the address table data. */ | |
147 | const gdb_byte *address_table; | |
148 | /* Size of the address table data in bytes. */ | |
149 | offset_type address_table_size; | |
150 | /* The hash table. */ | |
151 | const offset_type *index_table; | |
152 | /* Size in slots, each slot is 2 offset_types. */ | |
153 | offset_type index_table_slots; | |
154 | /* A pointer to the constant pool. */ | |
155 | const char *constant_pool; | |
156 | }; | |
157 | ||
158 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_data_ptr; | |
159 | DEF_VEC_P (dwarf2_per_cu_data_ptr); | |
160 | ||
6502dd73 DJ |
161 | struct dwarf2_per_objfile |
162 | { | |
dce234bc PP |
163 | struct dwarf2_section_info info; |
164 | struct dwarf2_section_info abbrev; | |
165 | struct dwarf2_section_info line; | |
dce234bc PP |
166 | struct dwarf2_section_info loc; |
167 | struct dwarf2_section_info macinfo; | |
168 | struct dwarf2_section_info str; | |
169 | struct dwarf2_section_info ranges; | |
348e048f | 170 | struct dwarf2_section_info types; |
dce234bc PP |
171 | struct dwarf2_section_info frame; |
172 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 173 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 174 | |
be391dca TT |
175 | /* Back link. */ |
176 | struct objfile *objfile; | |
177 | ||
10b3939b DJ |
178 | /* A list of all the compilation units. This is used to locate |
179 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
180 | struct dwarf2_per_cu_data **all_comp_units; |
181 | ||
182 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
183 | int n_comp_units; | |
184 | ||
185 | /* A chain of compilation units that are currently read in, so that | |
186 | they can be freed later. */ | |
187 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 188 | |
348e048f DE |
189 | /* A table mapping .debug_types signatures to its signatured_type entry. |
190 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
191 | htab_t signatured_types; | |
192 | ||
72dca2f5 FR |
193 | /* A flag indicating wether this objfile has a section loaded at a |
194 | VMA of 0. */ | |
195 | int has_section_at_zero; | |
9291a0cd TT |
196 | |
197 | /* True if we are using the mapped index. */ | |
198 | unsigned char using_index; | |
199 | ||
200 | /* The mapped index. */ | |
201 | struct mapped_index *index_table; | |
6502dd73 DJ |
202 | }; |
203 | ||
204 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
205 | |
206 | /* names of the debugging sections */ | |
207 | ||
233a11ab CS |
208 | /* Note that if the debugging section has been compressed, it might |
209 | have a name like .zdebug_info. */ | |
210 | ||
211 | #define INFO_SECTION "debug_info" | |
212 | #define ABBREV_SECTION "debug_abbrev" | |
213 | #define LINE_SECTION "debug_line" | |
233a11ab CS |
214 | #define LOC_SECTION "debug_loc" |
215 | #define MACINFO_SECTION "debug_macinfo" | |
216 | #define STR_SECTION "debug_str" | |
217 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 218 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
219 | #define FRAME_SECTION "debug_frame" |
220 | #define EH_FRAME_SECTION "eh_frame" | |
9291a0cd | 221 | #define GDB_INDEX_SECTION "gdb_index" |
c906108c SS |
222 | |
223 | /* local data types */ | |
224 | ||
57349743 JB |
225 | /* We hold several abbreviation tables in memory at the same time. */ |
226 | #ifndef ABBREV_HASH_SIZE | |
227 | #define ABBREV_HASH_SIZE 121 | |
228 | #endif | |
229 | ||
107d2387 AC |
230 | /* The data in a compilation unit header, after target2host |
231 | translation, looks like this. */ | |
c906108c | 232 | struct comp_unit_head |
a738430d | 233 | { |
c764a876 | 234 | unsigned int length; |
a738430d | 235 | short version; |
a738430d MK |
236 | unsigned char addr_size; |
237 | unsigned char signed_addr_p; | |
9cbfa09e | 238 | unsigned int abbrev_offset; |
57349743 | 239 | |
a738430d MK |
240 | /* Size of file offsets; either 4 or 8. */ |
241 | unsigned int offset_size; | |
57349743 | 242 | |
a738430d MK |
243 | /* Size of the length field; either 4 or 12. */ |
244 | unsigned int initial_length_size; | |
57349743 | 245 | |
a738430d MK |
246 | /* Offset to the first byte of this compilation unit header in the |
247 | .debug_info section, for resolving relative reference dies. */ | |
248 | unsigned int offset; | |
57349743 | 249 | |
d00adf39 DE |
250 | /* Offset to first die in this cu from the start of the cu. |
251 | This will be the first byte following the compilation unit header. */ | |
252 | unsigned int first_die_offset; | |
a738430d | 253 | }; |
c906108c | 254 | |
e7c27a73 DJ |
255 | /* Internal state when decoding a particular compilation unit. */ |
256 | struct dwarf2_cu | |
257 | { | |
258 | /* The objfile containing this compilation unit. */ | |
259 | struct objfile *objfile; | |
260 | ||
d00adf39 | 261 | /* The header of the compilation unit. */ |
e7c27a73 | 262 | struct comp_unit_head header; |
e142c38c | 263 | |
d00adf39 DE |
264 | /* Base address of this compilation unit. */ |
265 | CORE_ADDR base_address; | |
266 | ||
267 | /* Non-zero if base_address has been set. */ | |
268 | int base_known; | |
269 | ||
e142c38c DJ |
270 | struct function_range *first_fn, *last_fn, *cached_fn; |
271 | ||
272 | /* The language we are debugging. */ | |
273 | enum language language; | |
274 | const struct language_defn *language_defn; | |
275 | ||
b0f35d58 DL |
276 | const char *producer; |
277 | ||
e142c38c DJ |
278 | /* The generic symbol table building routines have separate lists for |
279 | file scope symbols and all all other scopes (local scopes). So | |
280 | we need to select the right one to pass to add_symbol_to_list(). | |
281 | We do it by keeping a pointer to the correct list in list_in_scope. | |
282 | ||
283 | FIXME: The original dwarf code just treated the file scope as the | |
284 | first local scope, and all other local scopes as nested local | |
285 | scopes, and worked fine. Check to see if we really need to | |
286 | distinguish these in buildsym.c. */ | |
287 | struct pending **list_in_scope; | |
288 | ||
f3dd6933 DJ |
289 | /* DWARF abbreviation table associated with this compilation unit. */ |
290 | struct abbrev_info **dwarf2_abbrevs; | |
291 | ||
292 | /* Storage for the abbrev table. */ | |
293 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
294 | |
295 | /* Hash table holding all the loaded partial DIEs. */ | |
296 | htab_t partial_dies; | |
297 | ||
298 | /* Storage for things with the same lifetime as this read-in compilation | |
299 | unit, including partial DIEs. */ | |
300 | struct obstack comp_unit_obstack; | |
301 | ||
ae038cb0 DJ |
302 | /* When multiple dwarf2_cu structures are living in memory, this field |
303 | chains them all together, so that they can be released efficiently. | |
304 | We will probably also want a generation counter so that most-recently-used | |
305 | compilation units are cached... */ | |
306 | struct dwarf2_per_cu_data *read_in_chain; | |
307 | ||
308 | /* Backchain to our per_cu entry if the tree has been built. */ | |
309 | struct dwarf2_per_cu_data *per_cu; | |
310 | ||
f792889a DJ |
311 | /* Pointer to the die -> type map. Although it is stored |
312 | permanently in per_cu, we copy it here to avoid double | |
313 | indirection. */ | |
314 | htab_t type_hash; | |
315 | ||
ae038cb0 DJ |
316 | /* How many compilation units ago was this CU last referenced? */ |
317 | int last_used; | |
318 | ||
10b3939b | 319 | /* A hash table of die offsets for following references. */ |
51545339 | 320 | htab_t die_hash; |
10b3939b DJ |
321 | |
322 | /* Full DIEs if read in. */ | |
323 | struct die_info *dies; | |
324 | ||
325 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
326 | units referenced by this one. Only set during full symbol processing; | |
327 | partial symbol tables do not have dependencies. */ | |
328 | htab_t dependencies; | |
329 | ||
cb1df416 DJ |
330 | /* Header data from the line table, during full symbol processing. */ |
331 | struct line_header *line_header; | |
332 | ||
ae038cb0 DJ |
333 | /* Mark used when releasing cached dies. */ |
334 | unsigned int mark : 1; | |
335 | ||
336 | /* This flag will be set if this compilation unit might include | |
337 | inter-compilation-unit references. */ | |
338 | unsigned int has_form_ref_addr : 1; | |
339 | ||
72bf9492 DJ |
340 | /* This flag will be set if this compilation unit includes any |
341 | DW_TAG_namespace DIEs. If we know that there are explicit | |
342 | DIEs for namespaces, we don't need to try to infer them | |
343 | from mangled names. */ | |
344 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
345 | }; |
346 | ||
9291a0cd TT |
347 | /* When using the index (and thus not using psymtabs), each CU has an |
348 | object of this type. This is used to hold information needed by | |
349 | the various "quick" methods. */ | |
350 | struct dwarf2_per_cu_quick_data | |
351 | { | |
352 | /* The line table. This can be NULL if there was no line table. */ | |
353 | struct line_header *lines; | |
354 | ||
355 | /* The file names from the line table. */ | |
356 | const char **file_names; | |
357 | /* The file names from the line table after being run through | |
358 | gdb_realpath. */ | |
359 | const char **full_names; | |
360 | ||
361 | /* The corresponding symbol table. This is NULL if symbols for this | |
362 | CU have not yet been read. */ | |
363 | struct symtab *symtab; | |
364 | ||
365 | /* A temporary mark bit used when iterating over all CUs in | |
366 | expand_symtabs_matching. */ | |
367 | unsigned int mark : 1; | |
368 | ||
369 | /* True if we've tried to read the line table. */ | |
370 | unsigned int read_lines : 1; | |
371 | }; | |
372 | ||
10b3939b DJ |
373 | /* Persistent data held for a compilation unit, even when not |
374 | processing it. We put a pointer to this structure in the | |
375 | read_symtab_private field of the psymtab. If we encounter | |
376 | inter-compilation-unit references, we also maintain a sorted | |
377 | list of all compilation units. */ | |
378 | ||
ae038cb0 DJ |
379 | struct dwarf2_per_cu_data |
380 | { | |
348e048f | 381 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 382 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
383 | - if it doesn't, GDB will fall over anyway. |
384 | NOTE: Unlike comp_unit_head.length, this length includes | |
385 | initial_length_size. */ | |
c764a876 | 386 | unsigned int offset; |
348e048f | 387 | unsigned int length : 29; |
ae038cb0 DJ |
388 | |
389 | /* Flag indicating this compilation unit will be read in before | |
390 | any of the current compilation units are processed. */ | |
c764a876 | 391 | unsigned int queued : 1; |
ae038cb0 | 392 | |
5afb4e99 DJ |
393 | /* This flag will be set if we need to load absolutely all DIEs |
394 | for this compilation unit, instead of just the ones we think | |
395 | are interesting. It gets set if we look for a DIE in the | |
396 | hash table and don't find it. */ | |
397 | unsigned int load_all_dies : 1; | |
398 | ||
348e048f DE |
399 | /* Non-zero if this CU is from .debug_types. |
400 | Otherwise it's from .debug_info. */ | |
401 | unsigned int from_debug_types : 1; | |
402 | ||
17ea53c3 JK |
403 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
404 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 405 | struct dwarf2_cu *cu; |
1c379e20 DJ |
406 | |
407 | /* If full symbols for this CU have been read in, then this field | |
408 | holds a map of DIE offsets to types. It isn't always possible | |
409 | to reconstruct this information later, so we have to preserve | |
410 | it. */ | |
1c379e20 | 411 | htab_t type_hash; |
10b3939b | 412 | |
9291a0cd TT |
413 | /* The corresponding objfile. */ |
414 | struct objfile *objfile; | |
415 | ||
416 | /* When using partial symbol tables, the 'psymtab' field is active. | |
417 | Otherwise the 'quick' field is active. */ | |
418 | union | |
419 | { | |
420 | /* The partial symbol table associated with this compilation unit, | |
421 | or NULL for partial units (which do not have an associated | |
422 | symtab). */ | |
423 | struct partial_symtab *psymtab; | |
424 | ||
425 | /* Data needed by the "quick" functions. */ | |
426 | struct dwarf2_per_cu_quick_data *quick; | |
427 | } v; | |
ae038cb0 DJ |
428 | }; |
429 | ||
348e048f DE |
430 | /* Entry in the signatured_types hash table. */ |
431 | ||
432 | struct signatured_type | |
433 | { | |
434 | ULONGEST signature; | |
435 | ||
436 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
437 | unsigned int offset; | |
438 | ||
439 | /* Offset in .debug_types of the type defined by this TU. */ | |
440 | unsigned int type_offset; | |
441 | ||
442 | /* The CU(/TU) of this type. */ | |
443 | struct dwarf2_per_cu_data per_cu; | |
444 | }; | |
445 | ||
93311388 DE |
446 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
447 | which are used for both .debug_info and .debug_types dies. | |
448 | All parameters here are unchanging for the life of the call. | |
449 | This struct exists to abstract away the constant parameters of | |
450 | die reading. */ | |
451 | ||
452 | struct die_reader_specs | |
453 | { | |
454 | /* The bfd of this objfile. */ | |
455 | bfd* abfd; | |
456 | ||
457 | /* The CU of the DIE we are parsing. */ | |
458 | struct dwarf2_cu *cu; | |
459 | ||
460 | /* Pointer to start of section buffer. | |
461 | This is either the start of .debug_info or .debug_types. */ | |
462 | const gdb_byte *buffer; | |
463 | }; | |
464 | ||
debd256d JB |
465 | /* The line number information for a compilation unit (found in the |
466 | .debug_line section) begins with a "statement program header", | |
467 | which contains the following information. */ | |
468 | struct line_header | |
469 | { | |
470 | unsigned int total_length; | |
471 | unsigned short version; | |
472 | unsigned int header_length; | |
473 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 474 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
475 | unsigned char default_is_stmt; |
476 | int line_base; | |
477 | unsigned char line_range; | |
478 | unsigned char opcode_base; | |
479 | ||
480 | /* standard_opcode_lengths[i] is the number of operands for the | |
481 | standard opcode whose value is i. This means that | |
482 | standard_opcode_lengths[0] is unused, and the last meaningful | |
483 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
484 | unsigned char *standard_opcode_lengths; | |
485 | ||
486 | /* The include_directories table. NOTE! These strings are not | |
487 | allocated with xmalloc; instead, they are pointers into | |
488 | debug_line_buffer. If you try to free them, `free' will get | |
489 | indigestion. */ | |
490 | unsigned int num_include_dirs, include_dirs_size; | |
491 | char **include_dirs; | |
492 | ||
493 | /* The file_names table. NOTE! These strings are not allocated | |
494 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
495 | Don't try to free them directly. */ | |
496 | unsigned int num_file_names, file_names_size; | |
497 | struct file_entry | |
c906108c | 498 | { |
debd256d JB |
499 | char *name; |
500 | unsigned int dir_index; | |
501 | unsigned int mod_time; | |
502 | unsigned int length; | |
aaa75496 | 503 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 504 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
505 | } *file_names; |
506 | ||
507 | /* The start and end of the statement program following this | |
6502dd73 | 508 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 509 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 510 | }; |
c906108c SS |
511 | |
512 | /* When we construct a partial symbol table entry we only | |
513 | need this much information. */ | |
514 | struct partial_die_info | |
515 | { | |
72bf9492 | 516 | /* Offset of this DIE. */ |
c906108c | 517 | unsigned int offset; |
72bf9492 DJ |
518 | |
519 | /* DWARF-2 tag for this DIE. */ | |
520 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
521 | ||
72bf9492 DJ |
522 | /* Assorted flags describing the data found in this DIE. */ |
523 | unsigned int has_children : 1; | |
524 | unsigned int is_external : 1; | |
525 | unsigned int is_declaration : 1; | |
526 | unsigned int has_type : 1; | |
527 | unsigned int has_specification : 1; | |
528 | unsigned int has_pc_info : 1; | |
529 | ||
530 | /* Flag set if the SCOPE field of this structure has been | |
531 | computed. */ | |
532 | unsigned int scope_set : 1; | |
533 | ||
fa4028e9 JB |
534 | /* Flag set if the DIE has a byte_size attribute. */ |
535 | unsigned int has_byte_size : 1; | |
536 | ||
72bf9492 | 537 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 538 | sometimes a default name for unnamed DIEs. */ |
c906108c | 539 | char *name; |
72bf9492 DJ |
540 | |
541 | /* The scope to prepend to our children. This is generally | |
542 | allocated on the comp_unit_obstack, so will disappear | |
543 | when this compilation unit leaves the cache. */ | |
544 | char *scope; | |
545 | ||
546 | /* The location description associated with this DIE, if any. */ | |
547 | struct dwarf_block *locdesc; | |
548 | ||
549 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
550 | CORE_ADDR lowpc; |
551 | CORE_ADDR highpc; | |
72bf9492 | 552 | |
93311388 | 553 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 554 | DW_AT_sibling, if any. */ |
fe1b8b76 | 555 | gdb_byte *sibling; |
72bf9492 DJ |
556 | |
557 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
558 | DW_AT_specification (or DW_AT_abstract_origin or | |
559 | DW_AT_extension). */ | |
560 | unsigned int spec_offset; | |
561 | ||
562 | /* Pointers to this DIE's parent, first child, and next sibling, | |
563 | if any. */ | |
564 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
565 | }; |
566 | ||
567 | /* This data structure holds the information of an abbrev. */ | |
568 | struct abbrev_info | |
569 | { | |
570 | unsigned int number; /* number identifying abbrev */ | |
571 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
572 | unsigned short has_children; /* boolean */ |
573 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
574 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
575 | struct abbrev_info *next; /* next in chain */ | |
576 | }; | |
577 | ||
578 | struct attr_abbrev | |
579 | { | |
9d25dd43 DE |
580 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
581 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
582 | }; |
583 | ||
b60c80d6 DJ |
584 | /* Attributes have a name and a value */ |
585 | struct attribute | |
586 | { | |
9d25dd43 | 587 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
588 | ENUM_BITFIELD(dwarf_form) form : 15; |
589 | ||
590 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
591 | field should be in u.str (existing only for DW_STRING) but it is kept | |
592 | here for better struct attribute alignment. */ | |
593 | unsigned int string_is_canonical : 1; | |
594 | ||
b60c80d6 DJ |
595 | union |
596 | { | |
597 | char *str; | |
598 | struct dwarf_block *blk; | |
43bbcdc2 PH |
599 | ULONGEST unsnd; |
600 | LONGEST snd; | |
b60c80d6 | 601 | CORE_ADDR addr; |
348e048f | 602 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
603 | } |
604 | u; | |
605 | }; | |
606 | ||
c906108c SS |
607 | /* This data structure holds a complete die structure. */ |
608 | struct die_info | |
609 | { | |
76815b17 DE |
610 | /* DWARF-2 tag for this DIE. */ |
611 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
612 | ||
613 | /* Number of attributes */ | |
614 | unsigned short num_attrs; | |
615 | ||
616 | /* Abbrev number */ | |
617 | unsigned int abbrev; | |
618 | ||
93311388 | 619 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 620 | unsigned int offset; |
78ba4af6 JB |
621 | |
622 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
623 | points to this die's parent; CHILD points to the first child of | |
624 | this node; and all the children of a given node are chained | |
625 | together via their SIBLING fields, terminated by a die whose | |
626 | tag is zero. */ | |
639d11d3 DC |
627 | struct die_info *child; /* Its first child, if any. */ |
628 | struct die_info *sibling; /* Its next sibling, if any. */ | |
629 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 630 | |
b60c80d6 DJ |
631 | /* An array of attributes, with NUM_ATTRS elements. There may be |
632 | zero, but it's not common and zero-sized arrays are not | |
633 | sufficiently portable C. */ | |
634 | struct attribute attrs[1]; | |
c906108c SS |
635 | }; |
636 | ||
5fb290d7 DJ |
637 | struct function_range |
638 | { | |
639 | const char *name; | |
640 | CORE_ADDR lowpc, highpc; | |
641 | int seen_line; | |
642 | struct function_range *next; | |
643 | }; | |
644 | ||
c906108c SS |
645 | /* Get at parts of an attribute structure */ |
646 | ||
647 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 648 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
649 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
650 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
651 | #define DW_SND(attr) ((attr)->u.snd) | |
652 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 653 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
654 | |
655 | /* Blocks are a bunch of untyped bytes. */ | |
656 | struct dwarf_block | |
657 | { | |
658 | unsigned int size; | |
fe1b8b76 | 659 | gdb_byte *data; |
c906108c SS |
660 | }; |
661 | ||
c906108c SS |
662 | #ifndef ATTR_ALLOC_CHUNK |
663 | #define ATTR_ALLOC_CHUNK 4 | |
664 | #endif | |
665 | ||
c906108c SS |
666 | /* Allocate fields for structs, unions and enums in this size. */ |
667 | #ifndef DW_FIELD_ALLOC_CHUNK | |
668 | #define DW_FIELD_ALLOC_CHUNK 4 | |
669 | #endif | |
670 | ||
c906108c SS |
671 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
672 | but this would require a corresponding change in unpack_field_as_long | |
673 | and friends. */ | |
674 | static int bits_per_byte = 8; | |
675 | ||
676 | /* The routines that read and process dies for a C struct or C++ class | |
677 | pass lists of data member fields and lists of member function fields | |
678 | in an instance of a field_info structure, as defined below. */ | |
679 | struct field_info | |
c5aa993b JM |
680 | { |
681 | /* List of data member and baseclasses fields. */ | |
682 | struct nextfield | |
683 | { | |
684 | struct nextfield *next; | |
685 | int accessibility; | |
686 | int virtuality; | |
687 | struct field field; | |
688 | } | |
7d0ccb61 | 689 | *fields, *baseclasses; |
c906108c | 690 | |
7d0ccb61 | 691 | /* Number of fields (including baseclasses). */ |
c5aa993b | 692 | int nfields; |
c906108c | 693 | |
c5aa993b JM |
694 | /* Number of baseclasses. */ |
695 | int nbaseclasses; | |
c906108c | 696 | |
c5aa993b JM |
697 | /* Set if the accesibility of one of the fields is not public. */ |
698 | int non_public_fields; | |
c906108c | 699 | |
c5aa993b JM |
700 | /* Member function fields array, entries are allocated in the order they |
701 | are encountered in the object file. */ | |
702 | struct nextfnfield | |
703 | { | |
704 | struct nextfnfield *next; | |
705 | struct fn_field fnfield; | |
706 | } | |
707 | *fnfields; | |
c906108c | 708 | |
c5aa993b JM |
709 | /* Member function fieldlist array, contains name of possibly overloaded |
710 | member function, number of overloaded member functions and a pointer | |
711 | to the head of the member function field chain. */ | |
712 | struct fnfieldlist | |
713 | { | |
714 | char *name; | |
715 | int length; | |
716 | struct nextfnfield *head; | |
717 | } | |
718 | *fnfieldlists; | |
c906108c | 719 | |
c5aa993b JM |
720 | /* Number of entries in the fnfieldlists array. */ |
721 | int nfnfields; | |
98751a41 JK |
722 | |
723 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
724 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
725 | struct typedef_field_list | |
726 | { | |
727 | struct typedef_field field; | |
728 | struct typedef_field_list *next; | |
729 | } | |
730 | *typedef_field_list; | |
731 | unsigned typedef_field_list_count; | |
c5aa993b | 732 | }; |
c906108c | 733 | |
10b3939b DJ |
734 | /* One item on the queue of compilation units to read in full symbols |
735 | for. */ | |
736 | struct dwarf2_queue_item | |
737 | { | |
738 | struct dwarf2_per_cu_data *per_cu; | |
739 | struct dwarf2_queue_item *next; | |
740 | }; | |
741 | ||
742 | /* The current queue. */ | |
743 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
744 | ||
ae038cb0 DJ |
745 | /* Loaded secondary compilation units are kept in memory until they |
746 | have not been referenced for the processing of this many | |
747 | compilation units. Set this to zero to disable caching. Cache | |
748 | sizes of up to at least twenty will improve startup time for | |
749 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
750 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
751 | static void |
752 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
753 | struct cmd_list_element *c, const char *value) | |
754 | { | |
755 | fprintf_filtered (file, _("\ | |
756 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
757 | value); | |
758 | } | |
759 | ||
ae038cb0 | 760 | |
c906108c SS |
761 | /* Various complaints about symbol reading that don't abort the process */ |
762 | ||
4d3c2250 KB |
763 | static void |
764 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 765 | { |
4d3c2250 | 766 | complaint (&symfile_complaints, |
e2e0b3e5 | 767 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
768 | } |
769 | ||
25e43795 DJ |
770 | static void |
771 | dwarf2_debug_line_missing_file_complaint (void) | |
772 | { | |
773 | complaint (&symfile_complaints, | |
774 | _(".debug_line section has line data without a file")); | |
775 | } | |
776 | ||
59205f5a JB |
777 | static void |
778 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
779 | { | |
780 | complaint (&symfile_complaints, | |
781 | _(".debug_line section has line program sequence without an end")); | |
782 | } | |
783 | ||
4d3c2250 KB |
784 | static void |
785 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 786 | { |
e2e0b3e5 | 787 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
788 | } |
789 | ||
4d3c2250 KB |
790 | static void |
791 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
792 | int arg3) | |
2e276125 | 793 | { |
4d3c2250 | 794 | complaint (&symfile_complaints, |
e2e0b3e5 | 795 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
796 | arg2, arg3); |
797 | } | |
798 | ||
799 | static void | |
800 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 801 | { |
4d3c2250 | 802 | complaint (&symfile_complaints, |
e2e0b3e5 | 803 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
804 | } |
805 | ||
806 | static void | |
807 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 808 | { |
4d3c2250 | 809 | complaint (&symfile_complaints, |
e2e0b3e5 | 810 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
811 | arg1); |
812 | } | |
813 | ||
814 | static void | |
815 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 816 | { |
4d3c2250 | 817 | complaint (&symfile_complaints, |
e2e0b3e5 | 818 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 819 | } |
c906108c | 820 | |
c906108c SS |
821 | /* local function prototypes */ |
822 | ||
4efb68b1 | 823 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 824 | |
aaa75496 JB |
825 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
826 | struct objfile *); | |
827 | ||
828 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
d85a05f0 | 829 | struct die_info *, |
aaa75496 JB |
830 | struct partial_symtab *); |
831 | ||
c67a9c90 | 832 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 833 | |
72bf9492 DJ |
834 | static void scan_partial_symbols (struct partial_die_info *, |
835 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 836 | int, struct dwarf2_cu *); |
c906108c | 837 | |
72bf9492 DJ |
838 | static void add_partial_symbol (struct partial_die_info *, |
839 | struct dwarf2_cu *); | |
63d06c5c | 840 | |
72bf9492 DJ |
841 | static void add_partial_namespace (struct partial_die_info *pdi, |
842 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 843 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 844 | |
5d7cb8df JK |
845 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
846 | CORE_ADDR *highpc, int need_pc, | |
847 | struct dwarf2_cu *cu); | |
848 | ||
72bf9492 DJ |
849 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
850 | struct dwarf2_cu *cu); | |
91c24f0a | 851 | |
bc30ff58 JB |
852 | static void add_partial_subprogram (struct partial_die_info *pdi, |
853 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 854 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 855 | |
fe1b8b76 | 856 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
857 | gdb_byte *buffer, gdb_byte *info_ptr, |
858 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 859 | |
a14ed312 | 860 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 861 | |
a14ed312 | 862 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 863 | |
e7c27a73 | 864 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 865 | |
f3dd6933 | 866 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 867 | |
fe1b8b76 | 868 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 869 | struct dwarf2_cu *); |
72bf9492 | 870 | |
57349743 | 871 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 872 | struct dwarf2_cu *); |
c906108c | 873 | |
93311388 DE |
874 | static struct partial_die_info *load_partial_dies (bfd *, |
875 | gdb_byte *, gdb_byte *, | |
876 | int, struct dwarf2_cu *); | |
72bf9492 | 877 | |
fe1b8b76 | 878 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
879 | struct abbrev_info *abbrev, |
880 | unsigned int, bfd *, | |
881 | gdb_byte *, gdb_byte *, | |
882 | struct dwarf2_cu *); | |
c906108c | 883 | |
c764a876 | 884 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 885 | struct dwarf2_cu *); |
72bf9492 DJ |
886 | |
887 | static void fixup_partial_die (struct partial_die_info *, | |
888 | struct dwarf2_cu *); | |
889 | ||
fe1b8b76 JB |
890 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
891 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 892 | |
fe1b8b76 JB |
893 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
894 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 895 | |
fe1b8b76 | 896 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 897 | |
fe1b8b76 | 898 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 899 | |
fe1b8b76 | 900 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 901 | |
fe1b8b76 | 902 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 903 | |
93311388 | 904 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 905 | |
fe1b8b76 | 906 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 907 | unsigned int *); |
c906108c | 908 | |
c764a876 DE |
909 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
910 | ||
911 | static LONGEST read_checked_initial_length_and_offset | |
912 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
913 | unsigned int *, unsigned int *); | |
613e1657 | 914 | |
fe1b8b76 | 915 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
916 | unsigned int *); |
917 | ||
918 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 919 | |
fe1b8b76 | 920 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 921 | |
fe1b8b76 | 922 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 923 | |
fe1b8b76 JB |
924 | static char *read_indirect_string (bfd *, gdb_byte *, |
925 | const struct comp_unit_head *, | |
926 | unsigned int *); | |
4bdf3d34 | 927 | |
fe1b8b76 | 928 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 929 | |
fe1b8b76 | 930 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 931 | |
fe1b8b76 | 932 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 933 | |
e142c38c | 934 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 935 | |
e142c38c DJ |
936 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
937 | struct dwarf2_cu *); | |
c906108c | 938 | |
348e048f DE |
939 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
940 | unsigned int, | |
941 | struct dwarf2_cu *); | |
942 | ||
05cf31d1 JB |
943 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
944 | struct dwarf2_cu *cu); | |
945 | ||
e142c38c | 946 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 947 | |
e142c38c | 948 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 949 | struct dwarf2_cu **); |
63d06c5c | 950 | |
debd256d JB |
951 | static void free_line_header (struct line_header *lh); |
952 | ||
aaa75496 JB |
953 | static void add_file_name (struct line_header *, char *, unsigned int, |
954 | unsigned int, unsigned int); | |
955 | ||
debd256d JB |
956 | static struct line_header *(dwarf_decode_line_header |
957 | (unsigned int offset, | |
e7c27a73 | 958 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
959 | |
960 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 961 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 962 | |
4f1520fb | 963 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 964 | |
a14ed312 | 965 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 966 | struct dwarf2_cu *); |
c906108c | 967 | |
a14ed312 | 968 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 969 | struct dwarf2_cu *); |
c906108c | 970 | |
2df3850c JM |
971 | static void dwarf2_const_value_data (struct attribute *attr, |
972 | struct symbol *sym, | |
973 | int bits); | |
974 | ||
e7c27a73 | 975 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 976 | |
b4ba55a1 JB |
977 | static int need_gnat_info (struct dwarf2_cu *); |
978 | ||
979 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
980 | ||
981 | static void set_descriptive_type (struct type *, struct die_info *, | |
982 | struct dwarf2_cu *); | |
983 | ||
e7c27a73 DJ |
984 | static struct type *die_containing_type (struct die_info *, |
985 | struct dwarf2_cu *); | |
c906108c | 986 | |
e7c27a73 | 987 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 988 | |
f792889a | 989 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 990 | |
086ed43d | 991 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 992 | |
6e70227d | 993 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
994 | const char *suffix, int physname, |
995 | struct dwarf2_cu *cu); | |
63d06c5c | 996 | |
e7c27a73 | 997 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 998 | |
348e048f DE |
999 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1000 | ||
e7c27a73 | 1001 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1002 | |
e7c27a73 | 1003 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1004 | |
ff013f42 JK |
1005 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1006 | struct dwarf2_cu *, struct partial_symtab *); | |
1007 | ||
a14ed312 | 1008 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1009 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1010 | struct partial_symtab *); | |
c906108c | 1011 | |
fae299cd DC |
1012 | static void get_scope_pc_bounds (struct die_info *, |
1013 | CORE_ADDR *, CORE_ADDR *, | |
1014 | struct dwarf2_cu *); | |
1015 | ||
801e3a5b JB |
1016 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1017 | CORE_ADDR, struct dwarf2_cu *); | |
1018 | ||
a14ed312 | 1019 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1020 | struct dwarf2_cu *); |
c906108c | 1021 | |
a14ed312 | 1022 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1023 | struct type *, struct dwarf2_cu *); |
c906108c | 1024 | |
a14ed312 | 1025 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1026 | struct die_info *, struct type *, |
e7c27a73 | 1027 | struct dwarf2_cu *); |
c906108c | 1028 | |
a14ed312 | 1029 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 1030 | struct type *, struct dwarf2_cu *); |
c906108c | 1031 | |
134d01f1 | 1032 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1033 | |
e7c27a73 | 1034 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1035 | |
e7c27a73 | 1036 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1037 | |
5d7cb8df JK |
1038 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1039 | ||
27aa8d6a SW |
1040 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1041 | ||
f55ee35c JK |
1042 | static struct type *read_module_type (struct die_info *die, |
1043 | struct dwarf2_cu *cu); | |
1044 | ||
38d518c9 | 1045 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1046 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1047 | |
134d01f1 | 1048 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1049 | |
e7c27a73 | 1050 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1051 | |
6e70227d | 1052 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1053 | struct dwarf2_cu *); |
1054 | ||
93311388 | 1055 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1056 | |
93311388 DE |
1057 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1058 | gdb_byte *info_ptr, | |
d97bc12b DE |
1059 | gdb_byte **new_info_ptr, |
1060 | struct die_info *parent); | |
1061 | ||
93311388 DE |
1062 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1063 | gdb_byte *info_ptr, | |
fe1b8b76 | 1064 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1065 | struct die_info *parent); |
1066 | ||
93311388 DE |
1067 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1068 | gdb_byte *info_ptr, | |
fe1b8b76 | 1069 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1070 | struct die_info *parent); |
1071 | ||
93311388 DE |
1072 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1073 | struct die_info **, gdb_byte *, | |
1074 | int *); | |
1075 | ||
e7c27a73 | 1076 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1077 | |
71c25dea TT |
1078 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1079 | struct obstack *); | |
1080 | ||
e142c38c | 1081 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1082 | |
e142c38c | 1083 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1084 | struct dwarf2_cu **); |
9219021c | 1085 | |
a14ed312 | 1086 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1087 | |
a14ed312 | 1088 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1089 | |
a14ed312 | 1090 | static char *dwarf_form_name (unsigned int); |
c906108c | 1091 | |
a14ed312 | 1092 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1093 | |
a14ed312 | 1094 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1095 | |
1096 | #if 0 | |
a14ed312 | 1097 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1098 | #endif |
1099 | ||
f9aca02d | 1100 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1101 | |
d97bc12b DE |
1102 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1103 | ||
1104 | static void dump_die_for_error (struct die_info *); | |
1105 | ||
1106 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1107 | struct die_info *); | |
c906108c | 1108 | |
d97bc12b | 1109 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1110 | |
51545339 | 1111 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1112 | struct dwarf2_cu *); |
c906108c | 1113 | |
93311388 DE |
1114 | static int is_ref_attr (struct attribute *); |
1115 | ||
c764a876 | 1116 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1117 | |
43bbcdc2 | 1118 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1119 | |
348e048f DE |
1120 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1121 | struct attribute *, | |
1122 | struct dwarf2_cu **); | |
1123 | ||
10b3939b DJ |
1124 | static struct die_info *follow_die_ref (struct die_info *, |
1125 | struct attribute *, | |
f2f0e013 | 1126 | struct dwarf2_cu **); |
c906108c | 1127 | |
348e048f DE |
1128 | static struct die_info *follow_die_sig (struct die_info *, |
1129 | struct attribute *, | |
1130 | struct dwarf2_cu **); | |
1131 | ||
1132 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1133 | unsigned int offset); | |
1134 | ||
1135 | static void read_signatured_type (struct objfile *, | |
1136 | struct signatured_type *type_sig); | |
1137 | ||
c906108c SS |
1138 | /* memory allocation interface */ |
1139 | ||
7b5a2f43 | 1140 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1141 | |
f3dd6933 | 1142 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1143 | |
b60c80d6 | 1144 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1145 | |
e142c38c | 1146 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1147 | |
e142c38c DJ |
1148 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1149 | struct dwarf2_cu *); | |
5fb290d7 | 1150 | |
2e276125 | 1151 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1152 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1153 | |
8e19ed76 PS |
1154 | static int attr_form_is_block (struct attribute *); |
1155 | ||
3690dd37 JB |
1156 | static int attr_form_is_section_offset (struct attribute *); |
1157 | ||
1158 | static int attr_form_is_constant (struct attribute *); | |
1159 | ||
93e7bd98 DJ |
1160 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1161 | struct symbol *sym, | |
1162 | struct dwarf2_cu *cu); | |
4c2df51b | 1163 | |
93311388 DE |
1164 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1165 | struct abbrev_info *abbrev, | |
1166 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1167 | |
72bf9492 DJ |
1168 | static void free_stack_comp_unit (void *); |
1169 | ||
72bf9492 DJ |
1170 | static hashval_t partial_die_hash (const void *item); |
1171 | ||
1172 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1173 | ||
ae038cb0 | 1174 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1175 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1176 | |
1177 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1178 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1179 | |
93311388 DE |
1180 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1181 | ||
ae038cb0 DJ |
1182 | static void free_one_comp_unit (void *); |
1183 | ||
1184 | static void free_cached_comp_units (void *); | |
1185 | ||
1186 | static void age_cached_comp_units (void); | |
1187 | ||
1188 | static void free_one_cached_comp_unit (void *); | |
1189 | ||
f792889a DJ |
1190 | static struct type *set_die_type (struct die_info *, struct type *, |
1191 | struct dwarf2_cu *); | |
1c379e20 | 1192 | |
ae038cb0 DJ |
1193 | static void create_all_comp_units (struct objfile *); |
1194 | ||
93311388 DE |
1195 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1196 | struct objfile *); | |
10b3939b DJ |
1197 | |
1198 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1199 | ||
1200 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1201 | struct dwarf2_per_cu_data *); | |
1202 | ||
ae038cb0 DJ |
1203 | static void dwarf2_mark (struct dwarf2_cu *); |
1204 | ||
1205 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1206 | ||
f792889a | 1207 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1208 | |
9291a0cd TT |
1209 | static void dwarf2_release_queue (void *dummy); |
1210 | ||
1211 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1212 | struct objfile *objfile); | |
1213 | ||
1214 | static void process_queue (struct objfile *objfile); | |
1215 | ||
1216 | static void find_file_and_directory (struct die_info *die, | |
1217 | struct dwarf2_cu *cu, | |
1218 | char **name, char **comp_dir); | |
1219 | ||
1220 | static char *file_full_name (int file, struct line_header *lh, | |
1221 | const char *comp_dir); | |
1222 | ||
1223 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1224 | gdb_byte *info_ptr, | |
1225 | gdb_byte *buffer, | |
1226 | unsigned int buffer_size, | |
1227 | bfd *abfd); | |
1228 | ||
1229 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1230 | struct dwarf2_cu *cu); | |
1231 | ||
1232 | #if WORDS_BIGENDIAN | |
1233 | ||
1234 | /* Convert VALUE between big- and little-endian. */ | |
1235 | static offset_type | |
1236 | byte_swap (offset_type value) | |
1237 | { | |
1238 | offset_type result; | |
1239 | ||
1240 | result = (value & 0xff) << 24; | |
1241 | result |= (value & 0xff00) << 8; | |
1242 | result |= (value & 0xff0000) >> 8; | |
1243 | result |= (value & 0xff000000) >> 24; | |
1244 | return result; | |
1245 | } | |
1246 | ||
1247 | #define MAYBE_SWAP(V) byte_swap (V) | |
1248 | ||
1249 | #else | |
1250 | #define MAYBE_SWAP(V) (V) | |
1251 | #endif /* WORDS_BIGENDIAN */ | |
1252 | ||
1253 | /* The suffix for an index file. */ | |
1254 | #define INDEX_SUFFIX ".gdb-index" | |
1255 | ||
c906108c SS |
1256 | /* Try to locate the sections we need for DWARF 2 debugging |
1257 | information and return true if we have enough to do something. */ | |
1258 | ||
1259 | int | |
6502dd73 | 1260 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1261 | { |
be391dca TT |
1262 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1263 | if (!dwarf2_per_objfile) | |
1264 | { | |
1265 | /* Initialize per-objfile state. */ | |
1266 | struct dwarf2_per_objfile *data | |
1267 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1268 | |
be391dca TT |
1269 | memset (data, 0, sizeof (*data)); |
1270 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1271 | dwarf2_per_objfile = data; | |
6502dd73 | 1272 | |
be391dca TT |
1273 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
1274 | dwarf2_per_objfile->objfile = objfile; | |
1275 | } | |
1276 | return (dwarf2_per_objfile->info.asection != NULL | |
1277 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1278 | } |
1279 | ||
233a11ab CS |
1280 | /* When loading sections, we can either look for ".<name>", or for |
1281 | * ".z<name>", which indicates a compressed section. */ | |
1282 | ||
1283 | static int | |
dce234bc | 1284 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1285 | { |
dce234bc PP |
1286 | return (section_name[0] == '.' |
1287 | && (strcmp (section_name + 1, name) == 0 | |
1288 | || (section_name[1] == 'z' | |
1289 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1290 | } |
1291 | ||
c906108c SS |
1292 | /* This function is mapped across the sections and remembers the |
1293 | offset and size of each of the debugging sections we are interested | |
1294 | in. */ | |
1295 | ||
1296 | static void | |
72dca2f5 | 1297 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1298 | { |
dce234bc | 1299 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1300 | { |
dce234bc PP |
1301 | dwarf2_per_objfile->info.asection = sectp; |
1302 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1303 | } |
dce234bc | 1304 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1305 | { |
dce234bc PP |
1306 | dwarf2_per_objfile->abbrev.asection = sectp; |
1307 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1308 | } |
dce234bc | 1309 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1310 | { |
dce234bc PP |
1311 | dwarf2_per_objfile->line.asection = sectp; |
1312 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1313 | } |
dce234bc | 1314 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1315 | { |
dce234bc PP |
1316 | dwarf2_per_objfile->loc.asection = sectp; |
1317 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1318 | } |
dce234bc | 1319 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1320 | { |
dce234bc PP |
1321 | dwarf2_per_objfile->macinfo.asection = sectp; |
1322 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1323 | } |
dce234bc | 1324 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1325 | { |
dce234bc PP |
1326 | dwarf2_per_objfile->str.asection = sectp; |
1327 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1328 | } |
dce234bc | 1329 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1330 | { |
dce234bc PP |
1331 | dwarf2_per_objfile->frame.asection = sectp; |
1332 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1333 | } |
dce234bc | 1334 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1335 | { |
3799ccc6 | 1336 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1337 | |
3799ccc6 EZ |
1338 | if (aflag & SEC_HAS_CONTENTS) |
1339 | { | |
dce234bc PP |
1340 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1341 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1342 | } |
b6af0555 | 1343 | } |
dce234bc | 1344 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1345 | { |
dce234bc PP |
1346 | dwarf2_per_objfile->ranges.asection = sectp; |
1347 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1348 | } |
348e048f DE |
1349 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1350 | { | |
1351 | dwarf2_per_objfile->types.asection = sectp; | |
1352 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1353 | } | |
9291a0cd TT |
1354 | else if (section_is_p (sectp->name, GDB_INDEX_SECTION)) |
1355 | { | |
1356 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1357 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1358 | } | |
dce234bc | 1359 | |
72dca2f5 FR |
1360 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1361 | && bfd_section_vma (abfd, sectp) == 0) | |
1362 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1363 | } |
1364 | ||
dce234bc PP |
1365 | /* Decompress a section that was compressed using zlib. Store the |
1366 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1367 | |
1368 | static void | |
dce234bc PP |
1369 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1370 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1371 | { | |
1372 | bfd *abfd = objfile->obfd; | |
1373 | #ifndef HAVE_ZLIB_H | |
1374 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1375 | "is disabled in this copy of GDB"), | |
1376 | bfd_get_filename (abfd)); | |
1377 | #else | |
1378 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1379 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1380 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1381 | bfd_size_type uncompressed_size; |
1382 | gdb_byte *uncompressed_buffer; | |
1383 | z_stream strm; | |
1384 | int rc; | |
1385 | int header_size = 12; | |
1386 | ||
1387 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1388 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1389 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1390 | bfd_get_filename (abfd)); | |
1391 | ||
1392 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1393 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1394 | if (compressed_size < header_size | |
1395 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1396 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1397 | bfd_get_filename (abfd)); | |
1398 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1399 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1400 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1401 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1402 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1403 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1404 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1405 | uncompressed_size += compressed_buffer[11]; | |
1406 | ||
1407 | /* It is possible the section consists of several compressed | |
1408 | buffers concatenated together, so we uncompress in a loop. */ | |
1409 | strm.zalloc = NULL; | |
1410 | strm.zfree = NULL; | |
1411 | strm.opaque = NULL; | |
1412 | strm.avail_in = compressed_size - header_size; | |
1413 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1414 | strm.avail_out = uncompressed_size; | |
1415 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1416 | uncompressed_size); | |
1417 | rc = inflateInit (&strm); | |
1418 | while (strm.avail_in > 0) | |
1419 | { | |
1420 | if (rc != Z_OK) | |
1421 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1422 | bfd_get_filename (abfd), rc); | |
1423 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1424 | + (uncompressed_size - strm.avail_out)); | |
1425 | rc = inflate (&strm, Z_FINISH); | |
1426 | if (rc != Z_STREAM_END) | |
1427 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1428 | bfd_get_filename (abfd), rc); | |
1429 | rc = inflateReset (&strm); | |
1430 | } | |
1431 | rc = inflateEnd (&strm); | |
1432 | if (rc != Z_OK | |
1433 | || strm.avail_out != 0) | |
1434 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1435 | bfd_get_filename (abfd), rc); | |
1436 | ||
affddf13 | 1437 | do_cleanups (cleanup); |
dce234bc PP |
1438 | *outbuf = uncompressed_buffer; |
1439 | *outsize = uncompressed_size; | |
1440 | #endif | |
233a11ab CS |
1441 | } |
1442 | ||
dce234bc PP |
1443 | /* Read the contents of the section SECTP from object file specified by |
1444 | OBJFILE, store info about the section into INFO. | |
1445 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1446 | |
dce234bc PP |
1447 | static void |
1448 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1449 | { |
dce234bc PP |
1450 | bfd *abfd = objfile->obfd; |
1451 | asection *sectp = info->asection; | |
1452 | gdb_byte *buf, *retbuf; | |
1453 | unsigned char header[4]; | |
c906108c | 1454 | |
be391dca TT |
1455 | if (info->readin) |
1456 | return; | |
dce234bc PP |
1457 | info->buffer = NULL; |
1458 | info->was_mmapped = 0; | |
be391dca | 1459 | info->readin = 1; |
188dd5d6 | 1460 | |
dce234bc PP |
1461 | if (info->asection == NULL || info->size == 0) |
1462 | return; | |
c906108c | 1463 | |
dce234bc PP |
1464 | /* Check if the file has a 4-byte header indicating compression. */ |
1465 | if (info->size > sizeof (header) | |
1466 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1467 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1468 | { | |
1469 | /* Upon decompression, update the buffer and its size. */ | |
1470 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1471 | { | |
1472 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1473 | &info->size); | |
1474 | return; | |
1475 | } | |
1476 | } | |
4bdf3d34 | 1477 | |
dce234bc PP |
1478 | #ifdef HAVE_MMAP |
1479 | if (pagesize == 0) | |
1480 | pagesize = getpagesize (); | |
2e276125 | 1481 | |
dce234bc PP |
1482 | /* Only try to mmap sections which are large enough: we don't want to |
1483 | waste space due to fragmentation. Also, only try mmap for sections | |
1484 | without relocations. */ | |
1485 | ||
1486 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1487 | { | |
1488 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1489 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1490 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1491 | MAP_PRIVATE, pg_offset); | |
1492 | ||
1493 | if (retbuf != MAP_FAILED) | |
1494 | { | |
1495 | info->was_mmapped = 1; | |
1496 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1497 | #if HAVE_POSIX_MADVISE |
1498 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1499 | #endif | |
dce234bc PP |
1500 | return; |
1501 | } | |
1502 | } | |
1503 | #endif | |
1504 | ||
1505 | /* If we get here, we are a normal, not-compressed section. */ | |
1506 | info->buffer = buf | |
1507 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1508 | ||
1509 | /* When debugging .o files, we may need to apply relocations; see | |
1510 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1511 | We never compress sections in .o files, so we only need to | |
1512 | try this when the section is not compressed. */ | |
ac8035ab | 1513 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1514 | if (retbuf != NULL) |
1515 | { | |
1516 | info->buffer = retbuf; | |
1517 | return; | |
1518 | } | |
1519 | ||
1520 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1521 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1522 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1523 | bfd_get_filename (abfd)); | |
1524 | } | |
1525 | ||
1526 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1527 | SECTION_NAME. */ | |
af34e669 | 1528 | |
dce234bc PP |
1529 | void |
1530 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1531 | asection **sectp, gdb_byte **bufp, | |
1532 | bfd_size_type *sizep) | |
1533 | { | |
1534 | struct dwarf2_per_objfile *data | |
1535 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1536 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1537 | |
1538 | /* We may see an objfile without any DWARF, in which case we just | |
1539 | return nothing. */ | |
1540 | if (data == NULL) | |
1541 | { | |
1542 | *sectp = NULL; | |
1543 | *bufp = NULL; | |
1544 | *sizep = 0; | |
1545 | return; | |
1546 | } | |
dce234bc PP |
1547 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
1548 | info = &data->eh_frame; | |
1549 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1550 | info = &data->frame; | |
0d53c4c4 | 1551 | else |
dce234bc PP |
1552 | gdb_assert (0); |
1553 | ||
1554 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1555 | /* We haven't read this section in yet. Do it now. */ | |
1556 | dwarf2_read_section (objfile, info); | |
1557 | ||
1558 | *sectp = info->asection; | |
1559 | *bufp = info->buffer; | |
1560 | *sizep = info->size; | |
1561 | } | |
1562 | ||
9291a0cd TT |
1563 | \f |
1564 | ||
1565 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which | |
1566 | this CU came. */ | |
1567 | static void | |
1568 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1569 | struct dwarf2_per_cu_data *per_cu) | |
1570 | { | |
1571 | struct cleanup *back_to; | |
1572 | ||
1573 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1574 | ||
1575 | queue_comp_unit (per_cu, objfile); | |
1576 | ||
1577 | if (per_cu->from_debug_types) | |
1578 | read_signatured_type_at_offset (objfile, per_cu->offset); | |
1579 | else | |
1580 | load_full_comp_unit (per_cu, objfile); | |
1581 | ||
1582 | process_queue (objfile); | |
1583 | ||
1584 | /* Age the cache, releasing compilation units that have not | |
1585 | been used recently. */ | |
1586 | age_cached_comp_units (); | |
1587 | ||
1588 | do_cleanups (back_to); | |
1589 | } | |
1590 | ||
1591 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1592 | the objfile from which this CU came. Returns the resulting symbol | |
1593 | table. */ | |
1594 | static struct symtab * | |
1595 | dw2_instantiate_symtab (struct objfile *objfile, | |
1596 | struct dwarf2_per_cu_data *per_cu) | |
1597 | { | |
1598 | if (!per_cu->v.quick->symtab) | |
1599 | { | |
1600 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1601 | increment_reading_symtab (); | |
1602 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1603 | do_cleanups (back_to); | |
1604 | } | |
1605 | return per_cu->v.quick->symtab; | |
1606 | } | |
1607 | ||
1608 | /* A helper function that knows how to read a 64-bit value in a way | |
1609 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1610 | otherwise. */ | |
1611 | static int | |
1612 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1613 | { | |
1614 | if (sizeof (ULONGEST) < 8) | |
1615 | { | |
1616 | int i; | |
1617 | ||
1618 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1619 | for (i = 0; i < 4; ++i) | |
1620 | if (bytes[i + 4] != 0) | |
1621 | return 0; | |
1622 | ||
1623 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1624 | } | |
1625 | else | |
1626 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1627 | return 1; | |
1628 | } | |
1629 | ||
1630 | /* Read the CU list from the mapped index, and use it to create all | |
1631 | the CU objects for this objfile. Return 0 if something went wrong, | |
1632 | 1 if everything went ok. */ | |
1633 | static int | |
1634 | create_cus_from_index (struct objfile *objfile, struct mapped_index *index, | |
1635 | const gdb_byte *cu_list, offset_type cu_list_elements) | |
1636 | { | |
1637 | offset_type i; | |
1638 | const char *entry; | |
1639 | ||
1640 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1641 | dwarf2_per_objfile->all_comp_units | |
1642 | = obstack_alloc (&objfile->objfile_obstack, | |
1643 | dwarf2_per_objfile->n_comp_units | |
1644 | * sizeof (struct dwarf2_per_cu_data *)); | |
1645 | ||
1646 | for (i = 0; i < cu_list_elements; i += 2) | |
1647 | { | |
1648 | struct dwarf2_per_cu_data *the_cu; | |
1649 | ULONGEST offset, length; | |
1650 | ||
1651 | if (!extract_cu_value (cu_list, &offset) | |
1652 | || !extract_cu_value (cu_list + 8, &length)) | |
1653 | return 0; | |
1654 | cu_list += 2 * 8; | |
1655 | ||
1656 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1657 | struct dwarf2_per_cu_data); | |
1658 | the_cu->offset = offset; | |
1659 | the_cu->length = length; | |
1660 | the_cu->objfile = objfile; | |
1661 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1662 | struct dwarf2_per_cu_quick_data); | |
1663 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1664 | } | |
1665 | ||
1666 | return 1; | |
1667 | } | |
1668 | ||
1669 | /* Read the address map data from the mapped index, and use it to | |
1670 | populate the objfile's psymtabs_addrmap. */ | |
1671 | static void | |
1672 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1673 | { | |
1674 | const gdb_byte *iter, *end; | |
1675 | struct obstack temp_obstack; | |
1676 | struct addrmap *mutable_map; | |
1677 | struct cleanup *cleanup; | |
1678 | CORE_ADDR baseaddr; | |
1679 | ||
1680 | obstack_init (&temp_obstack); | |
1681 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1682 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1683 | ||
1684 | iter = index->address_table; | |
1685 | end = iter + index->address_table_size; | |
1686 | ||
1687 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1688 | ||
1689 | while (iter < end) | |
1690 | { | |
1691 | ULONGEST hi, lo, cu_index; | |
1692 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1693 | iter += 8; | |
1694 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1695 | iter += 8; | |
1696 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1697 | iter += 4; | |
1698 | ||
1699 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1700 | dwarf2_per_objfile->all_comp_units[cu_index]); | |
1701 | } | |
1702 | ||
1703 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1704 | &objfile->objfile_obstack); | |
1705 | do_cleanups (cleanup); | |
1706 | } | |
1707 | ||
1708 | /* The hash function for strings in the mapped index. This is the | |
1709 | same as the hashtab.c hash function, but we keep a separate copy to | |
1710 | maintain control over the implementation. This is necessary | |
1711 | because the hash function is tied to the format of the mapped index | |
1712 | file. */ | |
1713 | static hashval_t | |
1714 | mapped_index_string_hash (const void *p) | |
1715 | { | |
1716 | const unsigned char *str = (const unsigned char *) p; | |
1717 | hashval_t r = 0; | |
1718 | unsigned char c; | |
1719 | ||
1720 | while ((c = *str++) != 0) | |
1721 | r = r * 67 + c - 113; | |
1722 | ||
1723 | return r; | |
1724 | } | |
1725 | ||
1726 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
1727 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
1728 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
1729 | static int | |
1730 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
1731 | offset_type **vec_out) | |
1732 | { | |
1733 | offset_type hash = mapped_index_string_hash (name); | |
1734 | offset_type slot, step; | |
1735 | ||
1736 | slot = hash & (index->index_table_slots - 1); | |
1737 | step = ((hash * 17) & (index->index_table_slots - 1)) | 1; | |
1738 | ||
1739 | for (;;) | |
1740 | { | |
1741 | /* Convert a slot number to an offset into the table. */ | |
1742 | offset_type i = 2 * slot; | |
1743 | const char *str; | |
1744 | if (index->index_table[i] == 0 && index->index_table[i + 1] == 0) | |
1745 | return 0; | |
1746 | ||
1747 | str = index->constant_pool + MAYBE_SWAP (index->index_table[i]); | |
1748 | if (!strcmp (name, str)) | |
1749 | { | |
1750 | *vec_out = (offset_type *) (index->constant_pool | |
1751 | + MAYBE_SWAP (index->index_table[i + 1])); | |
1752 | return 1; | |
1753 | } | |
1754 | ||
1755 | slot = (slot + step) & (index->index_table_slots - 1); | |
1756 | } | |
1757 | } | |
1758 | ||
1759 | /* Read the index file. If everything went ok, initialize the "quick" | |
1760 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
1761 | static int | |
1762 | dwarf2_read_index (struct objfile *objfile) | |
1763 | { | |
1764 | struct stat st, obstat; | |
1765 | int fd; | |
1766 | char *addr; | |
1767 | struct mapped_index *map; | |
1768 | offset_type val, *metadata; | |
1769 | char buf1[8], buf2[8]; | |
1770 | const gdb_byte *cu_list; | |
1771 | offset_type cu_list_elements; | |
1772 | ||
1773 | if (dwarf2_per_objfile->gdb_index.asection == NULL | |
1774 | || dwarf2_per_objfile->gdb_index.size == 0) | |
1775 | return 0; | |
1776 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); | |
1777 | ||
1778 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
1779 | /* Version check. */ | |
1780 | if (MAYBE_SWAP (*(offset_type *) addr) != 1) | |
1781 | return 0; | |
1782 | ||
1783 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
1784 | map->total_size = st.st_size; | |
1785 | ||
1786 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1787 | cu_list = addr + MAYBE_SWAP (metadata[0]); | |
1788 | cu_list_elements = ((MAYBE_SWAP (metadata[1]) - MAYBE_SWAP (metadata[0])) | |
1789 | / 8); | |
1790 | map->address_table = addr + MAYBE_SWAP (metadata[1]); | |
1791 | map->address_table_size = (MAYBE_SWAP (metadata[2]) | |
1792 | - MAYBE_SWAP (metadata[1])); | |
1793 | map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[2])); | |
1794 | map->index_table_slots = ((MAYBE_SWAP (metadata[3]) | |
1795 | - MAYBE_SWAP (metadata[2])) | |
1796 | / (2 * sizeof (offset_type))); | |
1797 | map->constant_pool = addr + MAYBE_SWAP (metadata[3]); | |
1798 | ||
1799 | if (!create_cus_from_index (objfile, map, cu_list, cu_list_elements)) | |
1800 | return 0; | |
1801 | ||
1802 | create_addrmap_from_index (objfile, map); | |
1803 | ||
1804 | dwarf2_per_objfile->index_table = map; | |
1805 | dwarf2_per_objfile->using_index = 1; | |
1806 | ||
1807 | return 1; | |
1808 | } | |
1809 | ||
1810 | /* A helper for the "quick" functions which sets the global | |
1811 | dwarf2_per_objfile according to OBJFILE. */ | |
1812 | static void | |
1813 | dw2_setup (struct objfile *objfile) | |
1814 | { | |
1815 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
1816 | gdb_assert (dwarf2_per_objfile); | |
1817 | } | |
1818 | ||
1819 | /* A helper for the "quick" functions which attempts to read the line | |
1820 | table for THIS_CU. */ | |
1821 | static void | |
1822 | dw2_require_line_header (struct objfile *objfile, | |
1823 | struct dwarf2_per_cu_data *this_cu) | |
1824 | { | |
1825 | bfd *abfd = objfile->obfd; | |
1826 | struct line_header *lh = NULL; | |
1827 | struct attribute *attr; | |
1828 | struct cleanup *cleanups; | |
1829 | struct die_info *comp_unit_die; | |
1830 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; | |
1831 | int has_children, i; | |
1832 | struct dwarf2_cu cu; | |
1833 | unsigned int bytes_read, buffer_size; | |
1834 | struct die_reader_specs reader_specs; | |
1835 | char *name, *comp_dir; | |
1836 | ||
1837 | if (this_cu->v.quick->read_lines) | |
1838 | return; | |
1839 | this_cu->v.quick->read_lines = 1; | |
1840 | ||
1841 | memset (&cu, 0, sizeof (cu)); | |
1842 | cu.objfile = objfile; | |
1843 | obstack_init (&cu.comp_unit_obstack); | |
1844 | ||
1845 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
1846 | ||
1847 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
1848 | buffer_size = dwarf2_per_objfile->info.size; | |
1849 | buffer = dwarf2_per_objfile->info.buffer; | |
1850 | info_ptr = buffer + this_cu->offset; | |
1851 | beg_of_comp_unit = info_ptr; | |
1852 | ||
1853 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
1854 | buffer, buffer_size, | |
1855 | abfd); | |
1856 | ||
1857 | /* Complete the cu_header. */ | |
1858 | cu.header.offset = beg_of_comp_unit - buffer; | |
1859 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
1860 | ||
1861 | this_cu->cu = &cu; | |
1862 | cu.per_cu = this_cu; | |
1863 | ||
1864 | dwarf2_read_abbrevs (abfd, &cu); | |
1865 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
1866 | ||
1867 | if (this_cu->from_debug_types) | |
1868 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
1869 | init_cu_die_reader (&reader_specs, &cu); | |
1870 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
1871 | &has_children); | |
1872 | ||
1873 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); | |
1874 | if (attr) | |
1875 | { | |
1876 | unsigned int line_offset = DW_UNSND (attr); | |
1877 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); | |
1878 | } | |
1879 | if (lh == NULL) | |
1880 | { | |
1881 | do_cleanups (cleanups); | |
1882 | return; | |
1883 | } | |
1884 | ||
1885 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); | |
1886 | ||
1887 | this_cu->v.quick->lines = lh; | |
1888 | ||
1889 | this_cu->v.quick->file_names | |
1890 | = obstack_alloc (&objfile->objfile_obstack, | |
1891 | lh->num_file_names * sizeof (char *)); | |
1892 | for (i = 0; i < lh->num_file_names; ++i) | |
1893 | this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir); | |
1894 | ||
1895 | do_cleanups (cleanups); | |
1896 | } | |
1897 | ||
1898 | /* A helper for the "quick" functions which computes and caches the | |
1899 | real path for a given file name from the line table. | |
1900 | dw2_require_line_header must have been called before this is | |
1901 | invoked. */ | |
1902 | static const char * | |
1903 | dw2_require_full_path (struct objfile *objfile, | |
1904 | struct dwarf2_per_cu_data *cu, | |
1905 | int index) | |
1906 | { | |
1907 | if (!cu->v.quick->full_names) | |
1908 | cu->v.quick->full_names | |
1909 | = OBSTACK_CALLOC (&objfile->objfile_obstack, | |
1910 | cu->v.quick->lines->num_file_names, | |
1911 | sizeof (char *)); | |
1912 | ||
1913 | if (!cu->v.quick->full_names[index]) | |
1914 | cu->v.quick->full_names[index] | |
1915 | = gdb_realpath (cu->v.quick->file_names[index]); | |
1916 | ||
1917 | return cu->v.quick->full_names[index]; | |
1918 | } | |
1919 | ||
1920 | static struct symtab * | |
1921 | dw2_find_last_source_symtab (struct objfile *objfile) | |
1922 | { | |
1923 | int index; | |
1924 | dw2_setup (objfile); | |
1925 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1926 | return dw2_instantiate_symtab (objfile, | |
1927 | dwarf2_per_objfile->all_comp_units[index]); | |
1928 | } | |
1929 | ||
1930 | static void | |
1931 | dw2_forget_cached_source_info (struct objfile *objfile) | |
1932 | { | |
1933 | int i; | |
1934 | ||
1935 | dw2_setup (objfile); | |
1936 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
1937 | { | |
1938 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
1939 | ||
1940 | if (cu->v.quick->full_names) | |
1941 | { | |
1942 | int j; | |
1943 | ||
1944 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
1945 | xfree ((void *) cu->v.quick->full_names[j]); | |
1946 | } | |
1947 | } | |
1948 | } | |
1949 | ||
1950 | static int | |
1951 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
1952 | const char *full_path, const char *real_path, | |
1953 | struct symtab **result) | |
1954 | { | |
1955 | int i; | |
1956 | int check_basename = lbasename (name) == name; | |
1957 | struct dwarf2_per_cu_data *base_cu = NULL; | |
1958 | ||
1959 | dw2_setup (objfile); | |
1960 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
1961 | { | |
1962 | int j; | |
1963 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
1964 | ||
1965 | if (cu->v.quick->symtab) | |
1966 | continue; | |
1967 | ||
1968 | dw2_require_line_header (objfile, cu); | |
1969 | if (!cu->v.quick->lines) | |
1970 | continue; | |
1971 | ||
1972 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
1973 | { | |
1974 | const char *this_name = cu->v.quick->file_names[j]; | |
1975 | ||
1976 | if (FILENAME_CMP (name, this_name) == 0) | |
1977 | { | |
1978 | *result = dw2_instantiate_symtab (objfile, cu); | |
1979 | return 1; | |
1980 | } | |
1981 | ||
1982 | if (check_basename && ! base_cu | |
1983 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
1984 | base_cu = cu; | |
1985 | ||
1986 | if (full_path != NULL) | |
1987 | { | |
1988 | const char *this_full_name = dw2_require_full_path (objfile, | |
1989 | cu, j); | |
1990 | ||
1991 | if (this_full_name | |
1992 | && FILENAME_CMP (full_path, this_full_name) == 0) | |
1993 | { | |
1994 | *result = dw2_instantiate_symtab (objfile, cu); | |
1995 | return 1; | |
1996 | } | |
1997 | } | |
1998 | ||
1999 | if (real_path != NULL) | |
2000 | { | |
2001 | const char *this_full_name = dw2_require_full_path (objfile, | |
2002 | cu, j); | |
2003 | ||
2004 | if (this_full_name != NULL) | |
2005 | { | |
2006 | char *rp = gdb_realpath (this_full_name); | |
2007 | if (rp != NULL && FILENAME_CMP (real_path, rp) == 0) | |
2008 | { | |
2009 | xfree (rp); | |
2010 | *result = dw2_instantiate_symtab (objfile, cu); | |
2011 | return 1; | |
2012 | } | |
2013 | xfree (rp); | |
2014 | } | |
2015 | } | |
2016 | } | |
2017 | } | |
2018 | ||
2019 | if (base_cu) | |
2020 | { | |
2021 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2022 | return 1; | |
2023 | } | |
2024 | ||
2025 | return 0; | |
2026 | } | |
2027 | ||
2028 | static struct symtab * | |
2029 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2030 | const char *name, domain_enum domain) | |
2031 | { | |
2032 | /* We do all the work in the pre_expand_symtabs_matching hook | |
2033 | instead. */ | |
2034 | return NULL; | |
2035 | } | |
2036 | ||
2037 | /* A helper function that expands all symtabs that hold an object | |
2038 | named NAME. */ | |
2039 | static void | |
2040 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2041 | { | |
2042 | dw2_setup (objfile); | |
2043 | ||
2044 | if (dwarf2_per_objfile->index_table) | |
2045 | { | |
2046 | offset_type *vec; | |
2047 | ||
2048 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2049 | name, &vec)) | |
2050 | { | |
2051 | offset_type i, len = MAYBE_SWAP (*vec); | |
2052 | for (i = 0; i < len; ++i) | |
2053 | { | |
2054 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
2055 | struct dwarf2_per_cu_data *cu; | |
2056 | cu = dwarf2_per_objfile->all_comp_units[cu_index]; | |
2057 | dw2_instantiate_symtab (objfile, cu); | |
2058 | } | |
2059 | } | |
2060 | } | |
2061 | } | |
2062 | ||
2063 | static void | |
2064 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
2065 | int kind, const char *name, | |
2066 | domain_enum domain) | |
2067 | { | |
2068 | dw2_do_expand_symtabs_matching (objfile, name); | |
2069 | } | |
2070 | ||
2071 | static void | |
2072 | dw2_print_stats (struct objfile *objfile) | |
2073 | { | |
2074 | int i, count; | |
2075 | ||
2076 | dw2_setup (objfile); | |
2077 | count = 0; | |
2078 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2079 | { | |
2080 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2081 | ||
2082 | if (!cu->v.quick->symtab) | |
2083 | ++count; | |
2084 | } | |
2085 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2086 | } | |
2087 | ||
2088 | static void | |
2089 | dw2_dump (struct objfile *objfile) | |
2090 | { | |
2091 | /* Nothing worth printing. */ | |
2092 | } | |
2093 | ||
2094 | static void | |
2095 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2096 | struct section_offsets *delta) | |
2097 | { | |
2098 | /* There's nothing to relocate here. */ | |
2099 | } | |
2100 | ||
2101 | static void | |
2102 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2103 | const char *func_name) | |
2104 | { | |
2105 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2106 | } | |
2107 | ||
2108 | static void | |
2109 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2110 | { | |
2111 | int i; | |
2112 | ||
2113 | dw2_setup (objfile); | |
2114 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2115 | { | |
2116 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2117 | ||
2118 | dw2_instantiate_symtab (objfile, cu); | |
2119 | } | |
2120 | } | |
2121 | ||
2122 | static void | |
2123 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2124 | const char *filename) | |
2125 | { | |
2126 | int i; | |
2127 | ||
2128 | dw2_setup (objfile); | |
2129 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2130 | { | |
2131 | int j; | |
2132 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2133 | ||
2134 | if (cu->v.quick->symtab) | |
2135 | continue; | |
2136 | ||
2137 | dw2_require_line_header (objfile, cu); | |
2138 | if (!cu->v.quick->lines) | |
2139 | continue; | |
2140 | ||
2141 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2142 | { | |
2143 | const char *this_name = cu->v.quick->file_names[j]; | |
2144 | if (strcmp (this_name, filename) == 0) | |
2145 | { | |
2146 | dw2_instantiate_symtab (objfile, cu); | |
2147 | break; | |
2148 | } | |
2149 | } | |
2150 | } | |
2151 | } | |
2152 | ||
dd786858 | 2153 | static const char * |
9291a0cd TT |
2154 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2155 | { | |
2156 | struct dwarf2_per_cu_data *cu; | |
2157 | offset_type *vec; | |
2158 | ||
2159 | dw2_setup (objfile); | |
2160 | ||
2161 | if (!dwarf2_per_objfile->index_table) | |
2162 | return NULL; | |
2163 | ||
2164 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2165 | name, &vec)) | |
2166 | return NULL; | |
2167 | ||
2168 | /* Note that this just looks at the very first one named NAME -- but | |
2169 | actually we are looking for a function. find_main_filename | |
2170 | should be rewritten so that it doesn't require a custom hook. It | |
2171 | could just use the ordinary symbol tables. */ | |
2172 | /* vec[0] is the length, which must always be >0. */ | |
2173 | cu = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[1])]; | |
2174 | ||
2175 | dw2_require_line_header (objfile, cu); | |
2176 | if (!cu->v.quick->lines) | |
2177 | return NULL; | |
2178 | ||
dd786858 | 2179 | return cu->v.quick->file_names[cu->v.quick->lines->num_file_names - 1]; |
9291a0cd TT |
2180 | } |
2181 | ||
2182 | static void | |
2183 | dw2_map_ada_symtabs (struct objfile *objfile, | |
2184 | int (*wild_match) (const char *, int, const char *), | |
2185 | int (*is_name_suffix) (const char *), | |
2186 | void (*callback) (struct objfile *, | |
2187 | struct symtab *, void *), | |
2188 | const char *name, int global, | |
2189 | domain_enum namespace, int wild, | |
2190 | void *data) | |
2191 | { | |
2192 | /* For now, we don't support Ada, so this function can't be | |
2193 | reached. */ | |
2194 | internal_error (__FILE__, __LINE__, | |
2195 | _("map_ada_symtabs called via index method")); | |
2196 | } | |
2197 | ||
2198 | static void | |
2199 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2200 | int (*file_matcher) (const char *, void *), | |
2201 | int (*name_matcher) (const char *, void *), | |
2202 | domain_enum kind, | |
2203 | void *data) | |
2204 | { | |
2205 | int i; | |
2206 | offset_type iter; | |
2207 | ||
2208 | dw2_setup (objfile); | |
2209 | if (!dwarf2_per_objfile->index_table) | |
2210 | return; | |
2211 | ||
2212 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2213 | { | |
2214 | int j; | |
2215 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2216 | ||
2217 | cu->v.quick->mark = 0; | |
2218 | if (cu->v.quick->symtab) | |
2219 | continue; | |
2220 | ||
2221 | dw2_require_line_header (objfile, cu); | |
2222 | if (!cu->v.quick->lines) | |
2223 | continue; | |
2224 | ||
2225 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2226 | { | |
2227 | if (file_matcher (cu->v.quick->file_names[j], data)) | |
2228 | { | |
2229 | cu->v.quick->mark = 1; | |
2230 | break; | |
2231 | } | |
2232 | } | |
2233 | } | |
2234 | ||
2235 | for (iter = 0; | |
2236 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2237 | ++iter) | |
2238 | { | |
2239 | offset_type idx = 2 * iter; | |
2240 | const char *name; | |
2241 | offset_type *vec, vec_len, vec_idx; | |
2242 | ||
2243 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2244 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2245 | continue; | |
2246 | ||
2247 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2248 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2249 | ||
2250 | if (! (*name_matcher) (name, data)) | |
2251 | continue; | |
2252 | ||
2253 | /* The name was matched, now expand corresponding CUs that were | |
2254 | marked. */ | |
2255 | vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool | |
2256 | + dwarf2_per_objfile->index_table->index_table[idx + 1]); | |
2257 | vec_len = MAYBE_SWAP (vec[0]); | |
2258 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2259 | { | |
2260 | struct dwarf2_per_cu_data *cu | |
2261 | = dwarf2_per_objfile->all_comp_units[MAYBE_SWAP (vec[vec_idx + 1])]; | |
2262 | if (cu->v.quick->mark) | |
2263 | dw2_instantiate_symtab (objfile, cu); | |
2264 | } | |
2265 | } | |
2266 | } | |
2267 | ||
2268 | static struct symtab * | |
2269 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2270 | struct minimal_symbol *msymbol, | |
2271 | CORE_ADDR pc, | |
2272 | struct obj_section *section, | |
2273 | int warn_if_readin) | |
2274 | { | |
2275 | struct dwarf2_per_cu_data *data; | |
2276 | ||
2277 | dw2_setup (objfile); | |
2278 | ||
2279 | if (!objfile->psymtabs_addrmap) | |
2280 | return NULL; | |
2281 | ||
2282 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2283 | if (!data) | |
2284 | return NULL; | |
2285 | ||
2286 | if (warn_if_readin && data->v.quick->symtab) | |
2287 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)\n"), | |
2288 | paddress (get_objfile_arch (objfile), pc)); | |
2289 | ||
2290 | return dw2_instantiate_symtab (objfile, data); | |
2291 | } | |
2292 | ||
2293 | static void | |
2294 | dw2_map_symbol_names (struct objfile *objfile, | |
2295 | void (*fun) (const char *, void *), | |
2296 | void *data) | |
2297 | { | |
2298 | offset_type iter; | |
2299 | dw2_setup (objfile); | |
2300 | ||
2301 | if (!dwarf2_per_objfile->index_table) | |
2302 | return; | |
2303 | ||
2304 | for (iter = 0; | |
2305 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2306 | ++iter) | |
2307 | { | |
2308 | offset_type idx = 2 * iter; | |
2309 | const char *name; | |
2310 | offset_type *vec, vec_len, vec_idx; | |
2311 | ||
2312 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2313 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2314 | continue; | |
2315 | ||
2316 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2317 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2318 | ||
2319 | (*fun) (name, data); | |
2320 | } | |
2321 | } | |
2322 | ||
2323 | static void | |
2324 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2325 | void (*fun) (const char *, const char *, void *), | |
2326 | void *data) | |
2327 | { | |
2328 | int i; | |
2329 | ||
2330 | dw2_setup (objfile); | |
2331 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2332 | { | |
2333 | int j; | |
2334 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2335 | ||
2336 | if (cu->v.quick->symtab) | |
2337 | continue; | |
2338 | ||
2339 | dw2_require_line_header (objfile, cu); | |
2340 | if (!cu->v.quick->lines) | |
2341 | continue; | |
2342 | ||
2343 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
2344 | { | |
2345 | const char *this_full_name = dw2_require_full_path (objfile, cu, j); | |
2346 | (*fun) (cu->v.quick->file_names[j], this_full_name, data); | |
2347 | } | |
2348 | } | |
2349 | } | |
2350 | ||
2351 | static int | |
2352 | dw2_has_symbols (struct objfile *objfile) | |
2353 | { | |
2354 | return 1; | |
2355 | } | |
2356 | ||
2357 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2358 | { | |
2359 | dw2_has_symbols, | |
2360 | dw2_find_last_source_symtab, | |
2361 | dw2_forget_cached_source_info, | |
2362 | dw2_lookup_symtab, | |
2363 | dw2_lookup_symbol, | |
2364 | dw2_pre_expand_symtabs_matching, | |
2365 | dw2_print_stats, | |
2366 | dw2_dump, | |
2367 | dw2_relocate, | |
2368 | dw2_expand_symtabs_for_function, | |
2369 | dw2_expand_all_symtabs, | |
2370 | dw2_expand_symtabs_with_filename, | |
2371 | dw2_find_symbol_file, | |
2372 | dw2_map_ada_symtabs, | |
2373 | dw2_expand_symtabs_matching, | |
2374 | dw2_find_pc_sect_symtab, | |
2375 | dw2_map_symbol_names, | |
2376 | dw2_map_symbol_filenames | |
2377 | }; | |
2378 | ||
2379 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2380 | file will use psymtabs, or 1 if using the GNU index. */ | |
2381 | ||
2382 | int | |
2383 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2384 | { | |
2385 | /* If we're about to read full symbols, don't bother with the | |
2386 | indices. In this case we also don't care if some other debug | |
2387 | format is making psymtabs, because they are all about to be | |
2388 | expanded anyway. */ | |
2389 | if ((objfile->flags & OBJF_READNOW)) | |
2390 | { | |
2391 | int i; | |
2392 | ||
2393 | dwarf2_per_objfile->using_index = 1; | |
2394 | create_all_comp_units (objfile); | |
2395 | ||
2396 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
2397 | { | |
2398 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
2399 | ||
2400 | cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
2401 | struct dwarf2_per_cu_quick_data); | |
2402 | } | |
2403 | ||
2404 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2405 | these functions will be no-ops because we will have expanded | |
2406 | all symtabs. */ | |
2407 | return 1; | |
2408 | } | |
2409 | ||
2410 | if (dwarf2_read_index (objfile)) | |
2411 | return 1; | |
2412 | ||
2413 | dwarf2_build_psymtabs (objfile); | |
2414 | return 0; | |
2415 | } | |
2416 | ||
2417 | \f | |
2418 | ||
dce234bc PP |
2419 | /* Build a partial symbol table. */ |
2420 | ||
2421 | void | |
f29dff0a | 2422 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2423 | { |
f29dff0a | 2424 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2425 | { |
2426 | init_psymbol_list (objfile, 1024); | |
2427 | } | |
2428 | ||
d146bf1e | 2429 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2430 | } |
c906108c | 2431 | |
45452591 DE |
2432 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2433 | ||
2434 | static inline int | |
2435 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2436 | { | |
2437 | unsigned int bottom = cu_header->offset; | |
2438 | unsigned int top = (cu_header->offset | |
2439 | + cu_header->length | |
2440 | + cu_header->initial_length_size); | |
9a619af0 | 2441 | |
45452591 DE |
2442 | return (offset >= bottom && offset < top); |
2443 | } | |
2444 | ||
93311388 DE |
2445 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2446 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2447 | by the caller. */ | |
107d2387 | 2448 | |
fe1b8b76 | 2449 | static gdb_byte * |
107d2387 | 2450 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2451 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2452 | { |
2453 | int signed_addr; | |
891d2f0b | 2454 | unsigned int bytes_read; |
c764a876 DE |
2455 | |
2456 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2457 | cu_header->initial_length_size = bytes_read; | |
2458 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2459 | info_ptr += bytes_read; |
107d2387 AC |
2460 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2461 | info_ptr += 2; | |
613e1657 | 2462 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2463 | &bytes_read); |
613e1657 | 2464 | info_ptr += bytes_read; |
107d2387 AC |
2465 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2466 | info_ptr += 1; | |
2467 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2468 | if (signed_addr < 0) | |
8e65ff28 | 2469 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2470 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2471 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2472 | |
107d2387 AC |
2473 | return info_ptr; |
2474 | } | |
2475 | ||
fe1b8b76 JB |
2476 | static gdb_byte * |
2477 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2478 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2479 | bfd *abfd) |
2480 | { | |
fe1b8b76 | 2481 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2482 | |
2483 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2484 | ||
2dc7f7b3 | 2485 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2486 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2487 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2488 | bfd_get_filename (abfd)); | |
72bf9492 | 2489 | |
dce234bc | 2490 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
2491 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2492 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2493 | (long) header->abbrev_offset, |
93311388 | 2494 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2495 | bfd_get_filename (abfd)); |
2496 | ||
2497 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2498 | > buffer + buffer_size) |
8a3fe4f8 AC |
2499 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2500 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2501 | (long) header->length, |
93311388 | 2502 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2503 | bfd_get_filename (abfd)); |
2504 | ||
2505 | return info_ptr; | |
2506 | } | |
2507 | ||
348e048f DE |
2508 | /* Read in the types comp unit header information from .debug_types entry at |
2509 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2510 | ||
2511 | static gdb_byte * | |
2512 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2513 | ULONGEST *signature, | |
2514 | gdb_byte *types_ptr, bfd *abfd) | |
2515 | { | |
348e048f DE |
2516 | gdb_byte *initial_types_ptr = types_ptr; |
2517 | ||
6e70227d | 2518 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2519 | &dwarf2_per_objfile->types); |
348e048f DE |
2520 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2521 | ||
2522 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2523 | ||
2524 | *signature = read_8_bytes (abfd, types_ptr); | |
2525 | types_ptr += 8; | |
2526 | types_ptr += cu_header->offset_size; | |
2527 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2528 | ||
2529 | return types_ptr; | |
2530 | } | |
2531 | ||
aaa75496 JB |
2532 | /* Allocate a new partial symtab for file named NAME and mark this new |
2533 | partial symtab as being an include of PST. */ | |
2534 | ||
2535 | static void | |
2536 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2537 | struct objfile *objfile) | |
2538 | { | |
2539 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2540 | ||
2541 | subpst->section_offsets = pst->section_offsets; | |
2542 | subpst->textlow = 0; | |
2543 | subpst->texthigh = 0; | |
2544 | ||
2545 | subpst->dependencies = (struct partial_symtab **) | |
2546 | obstack_alloc (&objfile->objfile_obstack, | |
2547 | sizeof (struct partial_symtab *)); | |
2548 | subpst->dependencies[0] = pst; | |
2549 | subpst->number_of_dependencies = 1; | |
2550 | ||
2551 | subpst->globals_offset = 0; | |
2552 | subpst->n_global_syms = 0; | |
2553 | subpst->statics_offset = 0; | |
2554 | subpst->n_static_syms = 0; | |
2555 | subpst->symtab = NULL; | |
2556 | subpst->read_symtab = pst->read_symtab; | |
2557 | subpst->readin = 0; | |
2558 | ||
2559 | /* No private part is necessary for include psymtabs. This property | |
2560 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2561 | the regular ones. */ |
58a9656e | 2562 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2563 | } |
2564 | ||
2565 | /* Read the Line Number Program data and extract the list of files | |
2566 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2567 | partial symtab for each of these included files. */ |
aaa75496 JB |
2568 | |
2569 | static void | |
2570 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2571 | struct die_info *die, |
aaa75496 JB |
2572 | struct partial_symtab *pst) |
2573 | { | |
2574 | struct objfile *objfile = cu->objfile; | |
2575 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2576 | struct line_header *lh = NULL; |
2577 | struct attribute *attr; | |
aaa75496 | 2578 | |
d85a05f0 DJ |
2579 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2580 | if (attr) | |
2581 | { | |
2582 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2583 | |
d85a05f0 DJ |
2584 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2585 | } | |
aaa75496 JB |
2586 | if (lh == NULL) |
2587 | return; /* No linetable, so no includes. */ | |
2588 | ||
2589 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
2590 | ||
2591 | free_line_header (lh); | |
2592 | } | |
2593 | ||
348e048f DE |
2594 | static hashval_t |
2595 | hash_type_signature (const void *item) | |
2596 | { | |
2597 | const struct signatured_type *type_sig = item; | |
9a619af0 | 2598 | |
348e048f DE |
2599 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
2600 | return type_sig->signature; | |
2601 | } | |
2602 | ||
2603 | static int | |
2604 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
2605 | { | |
2606 | const struct signatured_type *lhs = item_lhs; | |
2607 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 2608 | |
348e048f DE |
2609 | return lhs->signature == rhs->signature; |
2610 | } | |
2611 | ||
2612 | /* Create the hash table of all entries in the .debug_types section. | |
2613 | The result is zero if there is an error (e.g. missing .debug_types section), | |
2614 | otherwise non-zero. */ | |
2615 | ||
2616 | static int | |
2617 | create_debug_types_hash_table (struct objfile *objfile) | |
2618 | { | |
be391dca | 2619 | gdb_byte *info_ptr; |
348e048f DE |
2620 | htab_t types_htab; |
2621 | ||
be391dca TT |
2622 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
2623 | info_ptr = dwarf2_per_objfile->types.buffer; | |
2624 | ||
348e048f DE |
2625 | if (info_ptr == NULL) |
2626 | { | |
2627 | dwarf2_per_objfile->signatured_types = NULL; | |
2628 | return 0; | |
2629 | } | |
2630 | ||
2631 | types_htab = htab_create_alloc_ex (41, | |
2632 | hash_type_signature, | |
2633 | eq_type_signature, | |
2634 | NULL, | |
2635 | &objfile->objfile_obstack, | |
2636 | hashtab_obstack_allocate, | |
2637 | dummy_obstack_deallocate); | |
2638 | ||
2639 | if (dwarf2_die_debug) | |
2640 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
2641 | ||
2642 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2643 | { | |
2644 | unsigned int offset; | |
2645 | unsigned int offset_size; | |
2646 | unsigned int type_offset; | |
2647 | unsigned int length, initial_length_size; | |
2648 | unsigned short version; | |
2649 | ULONGEST signature; | |
2650 | struct signatured_type *type_sig; | |
2651 | void **slot; | |
2652 | gdb_byte *ptr = info_ptr; | |
2653 | ||
2654 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
2655 | ||
2656 | /* We need to read the type's signature in order to build the hash | |
2657 | table, but we don't need to read anything else just yet. */ | |
2658 | ||
2659 | /* Sanity check to ensure entire cu is present. */ | |
2660 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
2661 | if (ptr + length + initial_length_size | |
2662 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2663 | { | |
2664 | complaint (&symfile_complaints, | |
2665 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
2666 | break; | |
2667 | } | |
2668 | ||
2669 | offset_size = initial_length_size == 4 ? 4 : 8; | |
2670 | ptr += initial_length_size; | |
2671 | version = bfd_get_16 (objfile->obfd, ptr); | |
2672 | ptr += 2; | |
2673 | ptr += offset_size; /* abbrev offset */ | |
2674 | ptr += 1; /* address size */ | |
2675 | signature = bfd_get_64 (objfile->obfd, ptr); | |
2676 | ptr += 8; | |
2677 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
2678 | ||
2679 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
2680 | memset (type_sig, 0, sizeof (*type_sig)); | |
2681 | type_sig->signature = signature; | |
2682 | type_sig->offset = offset; | |
2683 | type_sig->type_offset = type_offset; | |
2684 | ||
2685 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
2686 | gdb_assert (slot != NULL); | |
2687 | *slot = type_sig; | |
2688 | ||
2689 | if (dwarf2_die_debug) | |
2690 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
2691 | offset, phex (signature, sizeof (signature))); | |
2692 | ||
2693 | info_ptr = info_ptr + initial_length_size + length; | |
2694 | } | |
2695 | ||
2696 | dwarf2_per_objfile->signatured_types = types_htab; | |
2697 | ||
2698 | return 1; | |
2699 | } | |
2700 | ||
2701 | /* Lookup a signature based type. | |
2702 | Returns NULL if SIG is not present in the table. */ | |
2703 | ||
2704 | static struct signatured_type * | |
2705 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
2706 | { | |
2707 | struct signatured_type find_entry, *entry; | |
2708 | ||
2709 | if (dwarf2_per_objfile->signatured_types == NULL) | |
2710 | { | |
2711 | complaint (&symfile_complaints, | |
2712 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
2713 | return 0; | |
2714 | } | |
2715 | ||
2716 | find_entry.signature = sig; | |
2717 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
2718 | return entry; | |
2719 | } | |
2720 | ||
d85a05f0 DJ |
2721 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
2722 | ||
2723 | static void | |
2724 | init_cu_die_reader (struct die_reader_specs *reader, | |
2725 | struct dwarf2_cu *cu) | |
2726 | { | |
2727 | reader->abfd = cu->objfile->obfd; | |
2728 | reader->cu = cu; | |
2729 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
2730 | { |
2731 | gdb_assert (dwarf2_per_objfile->types.readin); | |
2732 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
2733 | } | |
d85a05f0 | 2734 | else |
be391dca TT |
2735 | { |
2736 | gdb_assert (dwarf2_per_objfile->info.readin); | |
2737 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
2738 | } | |
d85a05f0 DJ |
2739 | } |
2740 | ||
2741 | /* Find the base address of the compilation unit for range lists and | |
2742 | location lists. It will normally be specified by DW_AT_low_pc. | |
2743 | In DWARF-3 draft 4, the base address could be overridden by | |
2744 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2745 | compilation units with discontinuous ranges. */ | |
2746 | ||
2747 | static void | |
2748 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
2749 | { | |
2750 | struct attribute *attr; | |
2751 | ||
2752 | cu->base_known = 0; | |
2753 | cu->base_address = 0; | |
2754 | ||
2755 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
2756 | if (attr) | |
2757 | { | |
2758 | cu->base_address = DW_ADDR (attr); | |
2759 | cu->base_known = 1; | |
2760 | } | |
2761 | else | |
2762 | { | |
2763 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
2764 | if (attr) | |
2765 | { | |
2766 | cu->base_address = DW_ADDR (attr); | |
2767 | cu->base_known = 1; | |
2768 | } | |
2769 | } | |
2770 | } | |
2771 | ||
348e048f DE |
2772 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
2773 | to combine the common parts. | |
93311388 | 2774 | Process a compilation unit for a psymtab. |
348e048f DE |
2775 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
2776 | either .debug_info or debug_types. | |
93311388 DE |
2777 | INFO_PTR is a pointer to the start of the CU. |
2778 | Returns a pointer to the next CU. */ | |
aaa75496 | 2779 | |
93311388 DE |
2780 | static gdb_byte * |
2781 | process_psymtab_comp_unit (struct objfile *objfile, | |
2782 | struct dwarf2_per_cu_data *this_cu, | |
2783 | gdb_byte *buffer, gdb_byte *info_ptr, | |
2784 | unsigned int buffer_size) | |
c906108c | 2785 | { |
c906108c | 2786 | bfd *abfd = objfile->obfd; |
93311388 | 2787 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 2788 | struct die_info *comp_unit_die; |
c906108c | 2789 | struct partial_symtab *pst; |
5734ee8b | 2790 | CORE_ADDR baseaddr; |
93311388 DE |
2791 | struct cleanup *back_to_inner; |
2792 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
2793 | int has_children, has_pc_info; |
2794 | struct attribute *attr; | |
d85a05f0 DJ |
2795 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
2796 | struct die_reader_specs reader_specs; | |
c906108c | 2797 | |
93311388 DE |
2798 | memset (&cu, 0, sizeof (cu)); |
2799 | cu.objfile = objfile; | |
2800 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 2801 | |
93311388 | 2802 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 2803 | |
93311388 DE |
2804 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
2805 | buffer, buffer_size, | |
2806 | abfd); | |
10b3939b | 2807 | |
93311388 DE |
2808 | /* Complete the cu_header. */ |
2809 | cu.header.offset = beg_of_comp_unit - buffer; | |
2810 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 2811 | |
93311388 | 2812 | cu.list_in_scope = &file_symbols; |
af703f96 | 2813 | |
328c9494 DJ |
2814 | /* If this compilation unit was already read in, free the |
2815 | cached copy in order to read it in again. This is | |
2816 | necessary because we skipped some symbols when we first | |
2817 | read in the compilation unit (see load_partial_dies). | |
2818 | This problem could be avoided, but the benefit is | |
2819 | unclear. */ | |
2820 | if (this_cu->cu != NULL) | |
2821 | free_one_cached_comp_unit (this_cu->cu); | |
2822 | ||
2823 | /* Note that this is a pointer to our stack frame, being | |
2824 | added to a global data structure. It will be cleaned up | |
2825 | in free_stack_comp_unit when we finish with this | |
2826 | compilation unit. */ | |
2827 | this_cu->cu = &cu; | |
d85a05f0 DJ |
2828 | cu.per_cu = this_cu; |
2829 | ||
93311388 DE |
2830 | /* Read the abbrevs for this compilation unit into a table. */ |
2831 | dwarf2_read_abbrevs (abfd, &cu); | |
2832 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 2833 | |
93311388 | 2834 | /* Read the compilation unit die. */ |
348e048f DE |
2835 | if (this_cu->from_debug_types) |
2836 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
2837 | init_cu_die_reader (&reader_specs, &cu); |
2838 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2839 | &has_children); | |
93311388 | 2840 | |
348e048f DE |
2841 | if (this_cu->from_debug_types) |
2842 | { | |
2843 | /* offset,length haven't been set yet for type units. */ | |
2844 | this_cu->offset = cu.header.offset; | |
2845 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
2846 | } | |
d85a05f0 | 2847 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 2848 | { |
93311388 DE |
2849 | info_ptr = (beg_of_comp_unit + cu.header.length |
2850 | + cu.header.initial_length_size); | |
2851 | do_cleanups (back_to_inner); | |
2852 | return info_ptr; | |
2853 | } | |
72bf9492 | 2854 | |
93311388 | 2855 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
2856 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
2857 | if (attr) | |
2858 | set_cu_language (DW_UNSND (attr), &cu); | |
2859 | else | |
2860 | set_cu_language (language_minimal, &cu); | |
c906108c | 2861 | |
93311388 | 2862 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 2863 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 2864 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 2865 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
2866 | /* TEXTLOW and TEXTHIGH are set below. */ |
2867 | 0, | |
2868 | objfile->global_psymbols.next, | |
2869 | objfile->static_psymbols.next); | |
72bf9492 | 2870 | |
d85a05f0 DJ |
2871 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
2872 | if (attr != NULL) | |
2873 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 2874 | |
e38df1d0 | 2875 | pst->read_symtab_private = this_cu; |
72bf9492 | 2876 | |
93311388 | 2877 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 2878 | |
93311388 DE |
2879 | /* Store the function that reads in the rest of the symbol table */ |
2880 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 2881 | |
9291a0cd | 2882 | this_cu->v.psymtab = pst; |
c906108c | 2883 | |
d85a05f0 DJ |
2884 | dwarf2_find_base_address (comp_unit_die, &cu); |
2885 | ||
93311388 DE |
2886 | /* Possibly set the default values of LOWPC and HIGHPC from |
2887 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
2888 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
2889 | &best_highpc, &cu, pst); | |
2890 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
2891 | /* Store the contiguous range if it is not empty; it can be empty for |
2892 | CUs with no code. */ | |
2893 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
2894 | best_lowpc + baseaddr, |
2895 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
2896 | |
2897 | /* Check if comp unit has_children. | |
2898 | If so, read the rest of the partial symbols from this comp unit. | |
2899 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 2900 | if (has_children) |
93311388 DE |
2901 | { |
2902 | struct partial_die_info *first_die; | |
2903 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 2904 | |
93311388 DE |
2905 | lowpc = ((CORE_ADDR) -1); |
2906 | highpc = ((CORE_ADDR) 0); | |
c906108c | 2907 | |
93311388 | 2908 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 2909 | |
93311388 | 2910 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 2911 | ! has_pc_info, &cu); |
57c22c6c | 2912 | |
93311388 DE |
2913 | /* If we didn't find a lowpc, set it to highpc to avoid |
2914 | complaints from `maint check'. */ | |
2915 | if (lowpc == ((CORE_ADDR) -1)) | |
2916 | lowpc = highpc; | |
10b3939b | 2917 | |
93311388 DE |
2918 | /* If the compilation unit didn't have an explicit address range, |
2919 | then use the information extracted from its child dies. */ | |
d85a05f0 | 2920 | if (! has_pc_info) |
93311388 | 2921 | { |
d85a05f0 DJ |
2922 | best_lowpc = lowpc; |
2923 | best_highpc = highpc; | |
93311388 DE |
2924 | } |
2925 | } | |
d85a05f0 DJ |
2926 | pst->textlow = best_lowpc + baseaddr; |
2927 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 2928 | |
93311388 DE |
2929 | pst->n_global_syms = objfile->global_psymbols.next - |
2930 | (objfile->global_psymbols.list + pst->globals_offset); | |
2931 | pst->n_static_syms = objfile->static_psymbols.next - | |
2932 | (objfile->static_psymbols.list + pst->statics_offset); | |
2933 | sort_pst_symbols (pst); | |
c906108c | 2934 | |
93311388 DE |
2935 | info_ptr = (beg_of_comp_unit + cu.header.length |
2936 | + cu.header.initial_length_size); | |
ae038cb0 | 2937 | |
348e048f DE |
2938 | if (this_cu->from_debug_types) |
2939 | { | |
2940 | /* It's not clear we want to do anything with stmt lists here. | |
2941 | Waiting to see what gcc ultimately does. */ | |
2942 | } | |
d85a05f0 | 2943 | else |
93311388 DE |
2944 | { |
2945 | /* Get the list of files included in the current compilation unit, | |
2946 | and build a psymtab for each of them. */ | |
d85a05f0 | 2947 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 2948 | } |
ae038cb0 | 2949 | |
93311388 | 2950 | do_cleanups (back_to_inner); |
ae038cb0 | 2951 | |
93311388 DE |
2952 | return info_ptr; |
2953 | } | |
ff013f42 | 2954 | |
348e048f DE |
2955 | /* Traversal function for htab_traverse_noresize. |
2956 | Process one .debug_types comp-unit. */ | |
2957 | ||
2958 | static int | |
2959 | process_type_comp_unit (void **slot, void *info) | |
2960 | { | |
2961 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
2962 | struct objfile *objfile = (struct objfile *) info; | |
2963 | struct dwarf2_per_cu_data *this_cu; | |
2964 | ||
2965 | this_cu = &entry->per_cu; | |
2966 | this_cu->from_debug_types = 1; | |
2967 | ||
be391dca | 2968 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
2969 | process_psymtab_comp_unit (objfile, this_cu, |
2970 | dwarf2_per_objfile->types.buffer, | |
2971 | dwarf2_per_objfile->types.buffer + entry->offset, | |
2972 | dwarf2_per_objfile->types.size); | |
2973 | ||
2974 | return 1; | |
2975 | } | |
2976 | ||
2977 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
2978 | Build partial symbol tables for the .debug_types comp-units. */ | |
2979 | ||
2980 | static void | |
2981 | build_type_psymtabs (struct objfile *objfile) | |
2982 | { | |
2983 | if (! create_debug_types_hash_table (objfile)) | |
2984 | return; | |
2985 | ||
2986 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
2987 | process_type_comp_unit, objfile); | |
2988 | } | |
2989 | ||
60606b2c TT |
2990 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
2991 | ||
2992 | static void | |
2993 | psymtabs_addrmap_cleanup (void *o) | |
2994 | { | |
2995 | struct objfile *objfile = o; | |
ec61707d | 2996 | |
60606b2c TT |
2997 | objfile->psymtabs_addrmap = NULL; |
2998 | } | |
2999 | ||
93311388 DE |
3000 | /* Build the partial symbol table by doing a quick pass through the |
3001 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3002 | |
93311388 | 3003 | static void |
c67a9c90 | 3004 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3005 | { |
93311388 | 3006 | gdb_byte *info_ptr; |
60606b2c TT |
3007 | struct cleanup *back_to, *addrmap_cleanup; |
3008 | struct obstack temp_obstack; | |
93311388 | 3009 | |
be391dca | 3010 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3011 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3012 | |
93311388 DE |
3013 | /* Any cached compilation units will be linked by the per-objfile |
3014 | read_in_chain. Make sure to free them when we're done. */ | |
3015 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3016 | |
348e048f DE |
3017 | build_type_psymtabs (objfile); |
3018 | ||
93311388 | 3019 | create_all_comp_units (objfile); |
c906108c | 3020 | |
60606b2c TT |
3021 | /* Create a temporary address map on a temporary obstack. We later |
3022 | copy this to the final obstack. */ | |
3023 | obstack_init (&temp_obstack); | |
3024 | make_cleanup_obstack_free (&temp_obstack); | |
3025 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3026 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3027 | |
93311388 DE |
3028 | /* Since the objects we're extracting from .debug_info vary in |
3029 | length, only the individual functions to extract them (like | |
3030 | read_comp_unit_head and load_partial_die) can really know whether | |
3031 | the buffer is large enough to hold another complete object. | |
c906108c | 3032 | |
93311388 DE |
3033 | At the moment, they don't actually check that. If .debug_info |
3034 | holds just one extra byte after the last compilation unit's dies, | |
3035 | then read_comp_unit_head will happily read off the end of the | |
3036 | buffer. read_partial_die is similarly casual. Those functions | |
3037 | should be fixed. | |
c906108c | 3038 | |
93311388 DE |
3039 | For this loop condition, simply checking whether there's any data |
3040 | left at all should be sufficient. */ | |
c906108c | 3041 | |
93311388 DE |
3042 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3043 | + dwarf2_per_objfile->info.size)) | |
3044 | { | |
3045 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3046 | |
93311388 DE |
3047 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
3048 | objfile); | |
aaa75496 | 3049 | |
93311388 DE |
3050 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3051 | dwarf2_per_objfile->info.buffer, | |
3052 | info_ptr, | |
3053 | dwarf2_per_objfile->info.size); | |
c906108c | 3054 | } |
ff013f42 JK |
3055 | |
3056 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3057 | &objfile->objfile_obstack); | |
60606b2c | 3058 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3059 | |
ae038cb0 DJ |
3060 | do_cleanups (back_to); |
3061 | } | |
3062 | ||
93311388 | 3063 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3064 | |
3065 | static void | |
93311388 DE |
3066 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3067 | struct objfile *objfile) | |
ae038cb0 DJ |
3068 | { |
3069 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3070 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3071 | struct die_info *comp_unit_die; |
ae038cb0 | 3072 | struct dwarf2_cu *cu; |
ae038cb0 | 3073 | struct cleanup *back_to; |
d85a05f0 DJ |
3074 | struct attribute *attr; |
3075 | int has_children; | |
3076 | struct die_reader_specs reader_specs; | |
ae038cb0 | 3077 | |
348e048f DE |
3078 | gdb_assert (! this_cu->from_debug_types); |
3079 | ||
be391dca | 3080 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3081 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3082 | beg_of_comp_unit = info_ptr; |
3083 | ||
93311388 | 3084 | cu = alloc_one_comp_unit (objfile); |
ae038cb0 | 3085 | |
93311388 | 3086 | /* ??? Missing cleanup for CU? */ |
ae038cb0 | 3087 | |
328c9494 DJ |
3088 | /* Link this compilation unit into the compilation unit tree. */ |
3089 | this_cu->cu = cu; | |
3090 | cu->per_cu = this_cu; | |
3091 | cu->type_hash = this_cu->type_hash; | |
3092 | ||
93311388 DE |
3093 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3094 | dwarf2_per_objfile->info.buffer, | |
3095 | dwarf2_per_objfile->info.size, | |
3096 | abfd); | |
ae038cb0 DJ |
3097 | |
3098 | /* Complete the cu_header. */ | |
93311388 | 3099 | cu->header.offset = this_cu->offset; |
d00adf39 | 3100 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
3101 | |
3102 | /* Read the abbrevs for this compilation unit into a table. */ | |
3103 | dwarf2_read_abbrevs (abfd, cu); | |
3104 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
3105 | ||
3106 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3107 | init_cu_die_reader (&reader_specs, cu); |
3108 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3109 | &has_children); | |
ae038cb0 DJ |
3110 | |
3111 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
3112 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
3113 | if (attr) | |
3114 | set_cu_language (DW_UNSND (attr), cu); | |
3115 | else | |
3116 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 3117 | |
ae038cb0 DJ |
3118 | /* Check if comp unit has_children. |
3119 | If so, read the rest of the partial symbols from this comp unit. | |
3120 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3121 | if (has_children) |
93311388 | 3122 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 DJ |
3123 | |
3124 | do_cleanups (back_to); | |
3125 | } | |
3126 | ||
3127 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3128 | if an inter-comp-unit reference is found; presumably if there is one, | |
3129 | there will be many, and one will occur early in the .debug_info section. | |
3130 | So there's no point in building this list incrementally. */ | |
3131 | ||
3132 | static void | |
3133 | create_all_comp_units (struct objfile *objfile) | |
3134 | { | |
3135 | int n_allocated; | |
3136 | int n_comp_units; | |
3137 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3138 | gdb_byte *info_ptr; |
3139 | ||
3140 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3141 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3142 | |
3143 | n_comp_units = 0; | |
3144 | n_allocated = 10; | |
3145 | all_comp_units = xmalloc (n_allocated | |
3146 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3147 | |
dce234bc | 3148 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 3149 | { |
c764a876 | 3150 | unsigned int length, initial_length_size; |
ae038cb0 | 3151 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3152 | unsigned int offset; |
ae038cb0 | 3153 | |
dce234bc | 3154 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3155 | |
3156 | /* Read just enough information to find out where the next | |
3157 | compilation unit is. */ | |
c764a876 DE |
3158 | length = read_initial_length (objfile->obfd, info_ptr, |
3159 | &initial_length_size); | |
ae038cb0 DJ |
3160 | |
3161 | /* Save the compilation unit for later lookup. */ | |
3162 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3163 | sizeof (struct dwarf2_per_cu_data)); | |
3164 | memset (this_cu, 0, sizeof (*this_cu)); | |
3165 | this_cu->offset = offset; | |
c764a876 | 3166 | this_cu->length = length + initial_length_size; |
9291a0cd | 3167 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3168 | |
3169 | if (n_comp_units == n_allocated) | |
3170 | { | |
3171 | n_allocated *= 2; | |
3172 | all_comp_units = xrealloc (all_comp_units, | |
3173 | n_allocated | |
3174 | * sizeof (struct dwarf2_per_cu_data *)); | |
3175 | } | |
3176 | all_comp_units[n_comp_units++] = this_cu; | |
3177 | ||
3178 | info_ptr = info_ptr + this_cu->length; | |
3179 | } | |
3180 | ||
3181 | dwarf2_per_objfile->all_comp_units | |
3182 | = obstack_alloc (&objfile->objfile_obstack, | |
3183 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3184 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3185 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3186 | xfree (all_comp_units); | |
3187 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3188 | } |
3189 | ||
5734ee8b DJ |
3190 | /* Process all loaded DIEs for compilation unit CU, starting at |
3191 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3192 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3193 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3194 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3195 | and record the covered ranges in the addrmap. */ | |
c906108c | 3196 | |
72bf9492 DJ |
3197 | static void |
3198 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3199 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3200 | { |
72bf9492 | 3201 | struct partial_die_info *pdi; |
c906108c | 3202 | |
91c24f0a DC |
3203 | /* Now, march along the PDI's, descending into ones which have |
3204 | interesting children but skipping the children of the other ones, | |
3205 | until we reach the end of the compilation unit. */ | |
c906108c | 3206 | |
72bf9492 | 3207 | pdi = first_die; |
91c24f0a | 3208 | |
72bf9492 DJ |
3209 | while (pdi != NULL) |
3210 | { | |
3211 | fixup_partial_die (pdi, cu); | |
c906108c | 3212 | |
f55ee35c | 3213 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3214 | children, so we need to look at them. Ditto for anonymous |
3215 | enums. */ | |
933c6fe4 | 3216 | |
72bf9492 | 3217 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3218 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3219 | { |
72bf9492 | 3220 | switch (pdi->tag) |
c906108c SS |
3221 | { |
3222 | case DW_TAG_subprogram: | |
5734ee8b | 3223 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
3224 | break; |
3225 | case DW_TAG_variable: | |
3226 | case DW_TAG_typedef: | |
91c24f0a | 3227 | case DW_TAG_union_type: |
72bf9492 | 3228 | if (!pdi->is_declaration) |
63d06c5c | 3229 | { |
72bf9492 | 3230 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3231 | } |
3232 | break; | |
c906108c | 3233 | case DW_TAG_class_type: |
680b30c7 | 3234 | case DW_TAG_interface_type: |
c906108c | 3235 | case DW_TAG_structure_type: |
72bf9492 | 3236 | if (!pdi->is_declaration) |
c906108c | 3237 | { |
72bf9492 | 3238 | add_partial_symbol (pdi, cu); |
c906108c SS |
3239 | } |
3240 | break; | |
91c24f0a | 3241 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3242 | if (!pdi->is_declaration) |
3243 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3244 | break; |
3245 | case DW_TAG_base_type: | |
a02abb62 | 3246 | case DW_TAG_subrange_type: |
c906108c | 3247 | /* File scope base type definitions are added to the partial |
c5aa993b | 3248 | symbol table. */ |
72bf9492 | 3249 | add_partial_symbol (pdi, cu); |
c906108c | 3250 | break; |
d9fa45fe | 3251 | case DW_TAG_namespace: |
5734ee8b | 3252 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3253 | break; |
5d7cb8df JK |
3254 | case DW_TAG_module: |
3255 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3256 | break; | |
c906108c SS |
3257 | default: |
3258 | break; | |
3259 | } | |
3260 | } | |
3261 | ||
72bf9492 DJ |
3262 | /* If the die has a sibling, skip to the sibling. */ |
3263 | ||
3264 | pdi = pdi->die_sibling; | |
3265 | } | |
3266 | } | |
3267 | ||
3268 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3269 | |
72bf9492 | 3270 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3271 | name is concatenated with "::" and the partial DIE's name. For |
3272 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3273 | Enumerators are an exception; they use the scope of their parent |
3274 | enumeration type, i.e. the name of the enumeration type is not | |
3275 | prepended to the enumerator. | |
91c24f0a | 3276 | |
72bf9492 DJ |
3277 | There are two complexities. One is DW_AT_specification; in this |
3278 | case "parent" means the parent of the target of the specification, | |
3279 | instead of the direct parent of the DIE. The other is compilers | |
3280 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3281 | the fully qualified name of structure types from their members' | |
3282 | linkage names. This must be done using the DIE's children rather | |
3283 | than the children of any DW_AT_specification target. We only need | |
3284 | to do this for structures at the top level, i.e. if the target of | |
3285 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3286 | have a parent. */ | |
3287 | ||
3288 | /* Compute the scope prefix associated with PDI's parent, in | |
3289 | compilation unit CU. The result will be allocated on CU's | |
3290 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3291 | field. NULL is returned if no prefix is necessary. */ | |
3292 | static char * | |
3293 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3294 | struct dwarf2_cu *cu) | |
3295 | { | |
3296 | char *grandparent_scope; | |
3297 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3298 | |
72bf9492 DJ |
3299 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3300 | then this means the parent of the specification DIE. */ | |
3301 | ||
3302 | real_pdi = pdi; | |
72bf9492 | 3303 | while (real_pdi->has_specification) |
10b3939b | 3304 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3305 | |
3306 | parent = real_pdi->die_parent; | |
3307 | if (parent == NULL) | |
3308 | return NULL; | |
3309 | ||
3310 | if (parent->scope_set) | |
3311 | return parent->scope; | |
3312 | ||
3313 | fixup_partial_die (parent, cu); | |
3314 | ||
10b3939b | 3315 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3316 | |
acebe513 UW |
3317 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3318 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3319 | Work around this problem here. */ | |
3320 | if (cu->language == language_cplus | |
6e70227d | 3321 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3322 | && strcmp (parent->name, "::") == 0 |
3323 | && grandparent_scope == NULL) | |
3324 | { | |
3325 | parent->scope = NULL; | |
3326 | parent->scope_set = 1; | |
3327 | return NULL; | |
3328 | } | |
3329 | ||
72bf9492 | 3330 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3331 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3332 | || parent->tag == DW_TAG_structure_type |
3333 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3334 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3335 | || parent->tag == DW_TAG_union_type |
3336 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3337 | { |
3338 | if (grandparent_scope == NULL) | |
3339 | parent->scope = parent->name; | |
3340 | else | |
987504bb | 3341 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
f55ee35c | 3342 | parent->name, 0, cu); |
72bf9492 | 3343 | } |
ceeb3d5a | 3344 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3345 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3346 | parent->scope = grandparent_scope; | |
3347 | else | |
3348 | { | |
3349 | /* FIXME drow/2004-04-01: What should we be doing with | |
3350 | function-local names? For partial symbols, we should probably be | |
3351 | ignoring them. */ | |
3352 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3353 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3354 | parent->tag, pdi->offset); |
3355 | parent->scope = grandparent_scope; | |
c906108c SS |
3356 | } |
3357 | ||
72bf9492 DJ |
3358 | parent->scope_set = 1; |
3359 | return parent->scope; | |
3360 | } | |
3361 | ||
3362 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3363 | CU. The result will be allocated with malloc. */ | |
3364 | static char * | |
3365 | partial_die_full_name (struct partial_die_info *pdi, | |
3366 | struct dwarf2_cu *cu) | |
3367 | { | |
3368 | char *parent_scope; | |
3369 | ||
3370 | parent_scope = partial_die_parent_scope (pdi, cu); | |
3371 | if (parent_scope == NULL) | |
3372 | return NULL; | |
3373 | else | |
f55ee35c | 3374 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3375 | } |
3376 | ||
3377 | static void | |
72bf9492 | 3378 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3379 | { |
e7c27a73 | 3380 | struct objfile *objfile = cu->objfile; |
c906108c | 3381 | CORE_ADDR addr = 0; |
decbce07 | 3382 | char *actual_name = NULL; |
5c4e30ca | 3383 | const struct partial_symbol *psym = NULL; |
e142c38c | 3384 | CORE_ADDR baseaddr; |
72bf9492 | 3385 | int built_actual_name = 0; |
e142c38c DJ |
3386 | |
3387 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3388 | |
94af9270 KS |
3389 | actual_name = partial_die_full_name (pdi, cu); |
3390 | if (actual_name) | |
3391 | built_actual_name = 1; | |
63d06c5c | 3392 | |
72bf9492 DJ |
3393 | if (actual_name == NULL) |
3394 | actual_name = pdi->name; | |
3395 | ||
c906108c SS |
3396 | switch (pdi->tag) |
3397 | { | |
3398 | case DW_TAG_subprogram: | |
2cfa0c8d | 3399 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3400 | { |
2cfa0c8d JB |
3401 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3402 | of the global scope. But in Ada, we want to be able to access | |
3403 | nested procedures globally. So all Ada subprograms are stored | |
3404 | in the global scope. */ | |
38d518c9 | 3405 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3406 | mst_text, objfile); */ |
38d518c9 | 3407 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3408 | built_actual_name, |
5c4e30ca DC |
3409 | VAR_DOMAIN, LOC_BLOCK, |
3410 | &objfile->global_psymbols, | |
3411 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3412 | cu->language, objfile); |
c906108c SS |
3413 | } |
3414 | else | |
3415 | { | |
38d518c9 | 3416 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3417 | mst_file_text, objfile); */ |
38d518c9 | 3418 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3419 | built_actual_name, |
5c4e30ca DC |
3420 | VAR_DOMAIN, LOC_BLOCK, |
3421 | &objfile->static_psymbols, | |
3422 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3423 | cu->language, objfile); |
c906108c SS |
3424 | } |
3425 | break; | |
3426 | case DW_TAG_variable: | |
3427 | if (pdi->is_external) | |
3428 | { | |
3429 | /* Global Variable. | |
3430 | Don't enter into the minimal symbol tables as there is | |
3431 | a minimal symbol table entry from the ELF symbols already. | |
3432 | Enter into partial symbol table if it has a location | |
3433 | descriptor or a type. | |
3434 | If the location descriptor is missing, new_symbol will create | |
3435 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3436 | be determined from the minimal symbol table whenever the variable | |
3437 | is referenced. | |
3438 | The address for the partial symbol table entry is not | |
3439 | used by GDB, but it comes in handy for debugging partial symbol | |
3440 | table building. */ | |
3441 | ||
3442 | if (pdi->locdesc) | |
e7c27a73 | 3443 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 3444 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 3445 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3446 | built_actual_name, |
5c4e30ca DC |
3447 | VAR_DOMAIN, LOC_STATIC, |
3448 | &objfile->global_psymbols, | |
3449 | 0, addr + baseaddr, | |
e142c38c | 3450 | cu->language, objfile); |
c906108c SS |
3451 | } |
3452 | else | |
3453 | { | |
3454 | /* Static Variable. Skip symbols without location descriptors. */ | |
3455 | if (pdi->locdesc == NULL) | |
decbce07 MS |
3456 | { |
3457 | if (built_actual_name) | |
3458 | xfree (actual_name); | |
3459 | return; | |
3460 | } | |
e7c27a73 | 3461 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 3462 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3463 | mst_file_data, objfile); */ |
38d518c9 | 3464 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3465 | built_actual_name, |
5c4e30ca DC |
3466 | VAR_DOMAIN, LOC_STATIC, |
3467 | &objfile->static_psymbols, | |
3468 | 0, addr + baseaddr, | |
e142c38c | 3469 | cu->language, objfile); |
c906108c SS |
3470 | } |
3471 | break; | |
3472 | case DW_TAG_typedef: | |
3473 | case DW_TAG_base_type: | |
a02abb62 | 3474 | case DW_TAG_subrange_type: |
38d518c9 | 3475 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3476 | built_actual_name, |
176620f1 | 3477 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3478 | &objfile->static_psymbols, |
e142c38c | 3479 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3480 | break; |
72bf9492 DJ |
3481 | case DW_TAG_namespace: |
3482 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 3483 | built_actual_name, |
72bf9492 DJ |
3484 | VAR_DOMAIN, LOC_TYPEDEF, |
3485 | &objfile->global_psymbols, | |
3486 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
3487 | break; | |
c906108c | 3488 | case DW_TAG_class_type: |
680b30c7 | 3489 | case DW_TAG_interface_type: |
c906108c SS |
3490 | case DW_TAG_structure_type: |
3491 | case DW_TAG_union_type: | |
3492 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
3493 | /* Skip external references. The DWARF standard says in the section |
3494 | about "Structure, Union, and Class Type Entries": "An incomplete | |
3495 | structure, union or class type is represented by a structure, | |
3496 | union or class entry that does not have a byte size attribute | |
3497 | and that has a DW_AT_declaration attribute." */ | |
3498 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
3499 | { |
3500 | if (built_actual_name) | |
3501 | xfree (actual_name); | |
3502 | return; | |
3503 | } | |
fa4028e9 | 3504 | |
63d06c5c DC |
3505 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
3506 | static vs. global. */ | |
38d518c9 | 3507 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3508 | built_actual_name, |
176620f1 | 3509 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
3510 | (cu->language == language_cplus |
3511 | || cu->language == language_java) | |
63d06c5c DC |
3512 | ? &objfile->global_psymbols |
3513 | : &objfile->static_psymbols, | |
e142c38c | 3514 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3515 | |
c906108c SS |
3516 | break; |
3517 | case DW_TAG_enumerator: | |
38d518c9 | 3518 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3519 | built_actual_name, |
176620f1 | 3520 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
3521 | (cu->language == language_cplus |
3522 | || cu->language == language_java) | |
f6fe98ef DJ |
3523 | ? &objfile->global_psymbols |
3524 | : &objfile->static_psymbols, | |
e142c38c | 3525 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
3526 | break; |
3527 | default: | |
3528 | break; | |
3529 | } | |
5c4e30ca | 3530 | |
72bf9492 DJ |
3531 | if (built_actual_name) |
3532 | xfree (actual_name); | |
c906108c SS |
3533 | } |
3534 | ||
5c4e30ca DC |
3535 | /* Read a partial die corresponding to a namespace; also, add a symbol |
3536 | corresponding to that namespace to the symbol table. NAMESPACE is | |
3537 | the name of the enclosing namespace. */ | |
91c24f0a | 3538 | |
72bf9492 DJ |
3539 | static void |
3540 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 3541 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 3542 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 3543 | { |
72bf9492 | 3544 | /* Add a symbol for the namespace. */ |
e7c27a73 | 3545 | |
72bf9492 | 3546 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
3547 | |
3548 | /* Now scan partial symbols in that namespace. */ | |
3549 | ||
91c24f0a | 3550 | if (pdi->has_children) |
5734ee8b | 3551 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
3552 | } |
3553 | ||
5d7cb8df JK |
3554 | /* Read a partial die corresponding to a Fortran module. */ |
3555 | ||
3556 | static void | |
3557 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
3558 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
3559 | { | |
f55ee35c | 3560 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
3561 | |
3562 | if (pdi->has_children) | |
3563 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
3564 | } | |
3565 | ||
bc30ff58 JB |
3566 | /* Read a partial die corresponding to a subprogram and create a partial |
3567 | symbol for that subprogram. When the CU language allows it, this | |
3568 | routine also defines a partial symbol for each nested subprogram | |
3569 | that this subprogram contains. | |
6e70227d | 3570 | |
bc30ff58 JB |
3571 | DIE my also be a lexical block, in which case we simply search |
3572 | recursively for suprograms defined inside that lexical block. | |
3573 | Again, this is only performed when the CU language allows this | |
3574 | type of definitions. */ | |
3575 | ||
3576 | static void | |
3577 | add_partial_subprogram (struct partial_die_info *pdi, | |
3578 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 3579 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
3580 | { |
3581 | if (pdi->tag == DW_TAG_subprogram) | |
3582 | { | |
3583 | if (pdi->has_pc_info) | |
3584 | { | |
3585 | if (pdi->lowpc < *lowpc) | |
3586 | *lowpc = pdi->lowpc; | |
3587 | if (pdi->highpc > *highpc) | |
3588 | *highpc = pdi->highpc; | |
5734ee8b DJ |
3589 | if (need_pc) |
3590 | { | |
3591 | CORE_ADDR baseaddr; | |
3592 | struct objfile *objfile = cu->objfile; | |
3593 | ||
3594 | baseaddr = ANOFFSET (objfile->section_offsets, | |
3595 | SECT_OFF_TEXT (objfile)); | |
3596 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
3597 | pdi->lowpc + baseaddr, |
3598 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 3599 | cu->per_cu->v.psymtab); |
5734ee8b | 3600 | } |
bc30ff58 | 3601 | if (!pdi->is_declaration) |
e8d05480 JB |
3602 | /* Ignore subprogram DIEs that do not have a name, they are |
3603 | illegal. Do not emit a complaint at this point, we will | |
3604 | do so when we convert this psymtab into a symtab. */ | |
3605 | if (pdi->name) | |
3606 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
3607 | } |
3608 | } | |
6e70227d | 3609 | |
bc30ff58 JB |
3610 | if (! pdi->has_children) |
3611 | return; | |
3612 | ||
3613 | if (cu->language == language_ada) | |
3614 | { | |
3615 | pdi = pdi->die_child; | |
3616 | while (pdi != NULL) | |
3617 | { | |
3618 | fixup_partial_die (pdi, cu); | |
3619 | if (pdi->tag == DW_TAG_subprogram | |
3620 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 3621 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
3622 | pdi = pdi->die_sibling; |
3623 | } | |
3624 | } | |
3625 | } | |
3626 | ||
72bf9492 DJ |
3627 | /* See if we can figure out if the class lives in a namespace. We do |
3628 | this by looking for a member function; its demangled name will | |
3629 | contain namespace info, if there is any. */ | |
63d06c5c | 3630 | |
72bf9492 DJ |
3631 | static void |
3632 | guess_structure_name (struct partial_die_info *struct_pdi, | |
3633 | struct dwarf2_cu *cu) | |
63d06c5c | 3634 | { |
987504bb JJ |
3635 | if ((cu->language == language_cplus |
3636 | || cu->language == language_java) | |
72bf9492 | 3637 | && cu->has_namespace_info == 0 |
63d06c5c DC |
3638 | && struct_pdi->has_children) |
3639 | { | |
63d06c5c DC |
3640 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
3641 | what template types look like, because the demangler | |
3642 | frequently doesn't give the same name as the debug info. We | |
3643 | could fix this by only using the demangled name to get the | |
134d01f1 | 3644 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 3645 | |
72bf9492 | 3646 | struct partial_die_info *real_pdi; |
5d51ca54 | 3647 | |
72bf9492 DJ |
3648 | /* If this DIE (this DIE's specification, if any) has a parent, then |
3649 | we should not do this. We'll prepend the parent's fully qualified | |
3650 | name when we create the partial symbol. */ | |
5d51ca54 | 3651 | |
72bf9492 | 3652 | real_pdi = struct_pdi; |
72bf9492 | 3653 | while (real_pdi->has_specification) |
10b3939b | 3654 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 3655 | |
72bf9492 DJ |
3656 | if (real_pdi->die_parent != NULL) |
3657 | return; | |
63d06c5c | 3658 | } |
63d06c5c DC |
3659 | } |
3660 | ||
91c24f0a DC |
3661 | /* Read a partial die corresponding to an enumeration type. */ |
3662 | ||
72bf9492 DJ |
3663 | static void |
3664 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
3665 | struct dwarf2_cu *cu) | |
91c24f0a | 3666 | { |
72bf9492 | 3667 | struct partial_die_info *pdi; |
91c24f0a DC |
3668 | |
3669 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
3670 | add_partial_symbol (enum_pdi, cu); |
3671 | ||
3672 | pdi = enum_pdi->die_child; | |
3673 | while (pdi) | |
91c24f0a | 3674 | { |
72bf9492 | 3675 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 3676 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 3677 | else |
72bf9492 DJ |
3678 | add_partial_symbol (pdi, cu); |
3679 | pdi = pdi->die_sibling; | |
91c24f0a | 3680 | } |
91c24f0a DC |
3681 | } |
3682 | ||
4bb7a0a7 DJ |
3683 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
3684 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
3685 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
3686 | the initial number. */ | |
3687 | ||
3688 | static struct abbrev_info * | |
fe1b8b76 | 3689 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 3690 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3691 | { |
3692 | bfd *abfd = cu->objfile->obfd; | |
3693 | unsigned int abbrev_number; | |
3694 | struct abbrev_info *abbrev; | |
3695 | ||
3696 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
3697 | ||
3698 | if (abbrev_number == 0) | |
3699 | return NULL; | |
3700 | ||
3701 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
3702 | if (!abbrev) | |
3703 | { | |
8a3fe4f8 | 3704 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
3705 | bfd_get_filename (abfd)); |
3706 | } | |
3707 | ||
3708 | return abbrev; | |
3709 | } | |
3710 | ||
93311388 DE |
3711 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3712 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
3713 | DIE. Any children of the skipped DIEs will also be skipped. */ |
3714 | ||
fe1b8b76 | 3715 | static gdb_byte * |
93311388 | 3716 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3717 | { |
3718 | struct abbrev_info *abbrev; | |
3719 | unsigned int bytes_read; | |
3720 | ||
3721 | while (1) | |
3722 | { | |
3723 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
3724 | if (abbrev == NULL) | |
3725 | return info_ptr + bytes_read; | |
3726 | else | |
93311388 | 3727 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
3728 | } |
3729 | } | |
3730 | ||
93311388 DE |
3731 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3732 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
3733 | abbrev corresponding to that skipped uleb128 should be passed in |
3734 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
3735 | children. */ | |
3736 | ||
fe1b8b76 | 3737 | static gdb_byte * |
93311388 DE |
3738 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
3739 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
3740 | { |
3741 | unsigned int bytes_read; | |
3742 | struct attribute attr; | |
3743 | bfd *abfd = cu->objfile->obfd; | |
3744 | unsigned int form, i; | |
3745 | ||
3746 | for (i = 0; i < abbrev->num_attrs; i++) | |
3747 | { | |
3748 | /* The only abbrev we care about is DW_AT_sibling. */ | |
3749 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
3750 | { | |
3751 | read_attribute (&attr, &abbrev->attrs[i], | |
3752 | abfd, info_ptr, cu); | |
3753 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 3754 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 3755 | else |
93311388 | 3756 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
3757 | } |
3758 | ||
3759 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
3760 | form = abbrev->attrs[i].form; | |
3761 | skip_attribute: | |
3762 | switch (form) | |
3763 | { | |
4bb7a0a7 | 3764 | case DW_FORM_ref_addr: |
ae411497 TT |
3765 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
3766 | and later it is offset sized. */ | |
3767 | if (cu->header.version == 2) | |
3768 | info_ptr += cu->header.addr_size; | |
3769 | else | |
3770 | info_ptr += cu->header.offset_size; | |
3771 | break; | |
3772 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
3773 | info_ptr += cu->header.addr_size; |
3774 | break; | |
3775 | case DW_FORM_data1: | |
3776 | case DW_FORM_ref1: | |
3777 | case DW_FORM_flag: | |
3778 | info_ptr += 1; | |
3779 | break; | |
2dc7f7b3 TT |
3780 | case DW_FORM_flag_present: |
3781 | break; | |
4bb7a0a7 DJ |
3782 | case DW_FORM_data2: |
3783 | case DW_FORM_ref2: | |
3784 | info_ptr += 2; | |
3785 | break; | |
3786 | case DW_FORM_data4: | |
3787 | case DW_FORM_ref4: | |
3788 | info_ptr += 4; | |
3789 | break; | |
3790 | case DW_FORM_data8: | |
3791 | case DW_FORM_ref8: | |
348e048f | 3792 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
3793 | info_ptr += 8; |
3794 | break; | |
3795 | case DW_FORM_string: | |
3796 | read_string (abfd, info_ptr, &bytes_read); | |
3797 | info_ptr += bytes_read; | |
3798 | break; | |
2dc7f7b3 | 3799 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
3800 | case DW_FORM_strp: |
3801 | info_ptr += cu->header.offset_size; | |
3802 | break; | |
2dc7f7b3 | 3803 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
3804 | case DW_FORM_block: |
3805 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3806 | info_ptr += bytes_read; | |
3807 | break; | |
3808 | case DW_FORM_block1: | |
3809 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
3810 | break; | |
3811 | case DW_FORM_block2: | |
3812 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
3813 | break; | |
3814 | case DW_FORM_block4: | |
3815 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
3816 | break; | |
3817 | case DW_FORM_sdata: | |
3818 | case DW_FORM_udata: | |
3819 | case DW_FORM_ref_udata: | |
3820 | info_ptr = skip_leb128 (abfd, info_ptr); | |
3821 | break; | |
3822 | case DW_FORM_indirect: | |
3823 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
3824 | info_ptr += bytes_read; | |
3825 | /* We need to continue parsing from here, so just go back to | |
3826 | the top. */ | |
3827 | goto skip_attribute; | |
3828 | ||
3829 | default: | |
8a3fe4f8 | 3830 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
3831 | dwarf_form_name (form), |
3832 | bfd_get_filename (abfd)); | |
3833 | } | |
3834 | } | |
3835 | ||
3836 | if (abbrev->has_children) | |
93311388 | 3837 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
3838 | else |
3839 | return info_ptr; | |
3840 | } | |
3841 | ||
93311388 DE |
3842 | /* Locate ORIG_PDI's sibling. |
3843 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
3844 | in BUFFER. */ | |
91c24f0a | 3845 | |
fe1b8b76 | 3846 | static gdb_byte * |
93311388 DE |
3847 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
3848 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 3849 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
3850 | { |
3851 | /* Do we know the sibling already? */ | |
72bf9492 | 3852 | |
91c24f0a DC |
3853 | if (orig_pdi->sibling) |
3854 | return orig_pdi->sibling; | |
3855 | ||
3856 | /* Are there any children to deal with? */ | |
3857 | ||
3858 | if (!orig_pdi->has_children) | |
3859 | return info_ptr; | |
3860 | ||
4bb7a0a7 | 3861 | /* Skip the children the long way. */ |
91c24f0a | 3862 | |
93311388 | 3863 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
3864 | } |
3865 | ||
c906108c SS |
3866 | /* Expand this partial symbol table into a full symbol table. */ |
3867 | ||
3868 | static void | |
fba45db2 | 3869 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 3870 | { |
c906108c SS |
3871 | if (pst != NULL) |
3872 | { | |
3873 | if (pst->readin) | |
3874 | { | |
8a3fe4f8 | 3875 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
3876 | } |
3877 | else | |
3878 | { | |
3879 | if (info_verbose) | |
3880 | { | |
a3f17187 | 3881 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
3882 | gdb_flush (gdb_stdout); |
3883 | } | |
3884 | ||
10b3939b DJ |
3885 | /* Restore our global data. */ |
3886 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
3887 | dwarf2_objfile_data_key); | |
3888 | ||
b2ab525c KB |
3889 | /* If this psymtab is constructed from a debug-only objfile, the |
3890 | has_section_at_zero flag will not necessarily be correct. We | |
3891 | can get the correct value for this flag by looking at the data | |
3892 | associated with the (presumably stripped) associated objfile. */ | |
3893 | if (pst->objfile->separate_debug_objfile_backlink) | |
3894 | { | |
3895 | struct dwarf2_per_objfile *dpo_backlink | |
3896 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
3897 | dwarf2_objfile_data_key); | |
9a619af0 | 3898 | |
b2ab525c KB |
3899 | dwarf2_per_objfile->has_section_at_zero |
3900 | = dpo_backlink->has_section_at_zero; | |
3901 | } | |
3902 | ||
c906108c SS |
3903 | psymtab_to_symtab_1 (pst); |
3904 | ||
3905 | /* Finish up the debug error message. */ | |
3906 | if (info_verbose) | |
a3f17187 | 3907 | printf_filtered (_("done.\n")); |
c906108c SS |
3908 | } |
3909 | } | |
3910 | } | |
3911 | ||
10b3939b DJ |
3912 | /* Add PER_CU to the queue. */ |
3913 | ||
3914 | static void | |
03dd20cc | 3915 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
3916 | { |
3917 | struct dwarf2_queue_item *item; | |
3918 | ||
3919 | per_cu->queued = 1; | |
3920 | item = xmalloc (sizeof (*item)); | |
3921 | item->per_cu = per_cu; | |
3922 | item->next = NULL; | |
3923 | ||
3924 | if (dwarf2_queue == NULL) | |
3925 | dwarf2_queue = item; | |
3926 | else | |
3927 | dwarf2_queue_tail->next = item; | |
3928 | ||
3929 | dwarf2_queue_tail = item; | |
3930 | } | |
3931 | ||
3932 | /* Process the queue. */ | |
3933 | ||
3934 | static void | |
3935 | process_queue (struct objfile *objfile) | |
3936 | { | |
3937 | struct dwarf2_queue_item *item, *next_item; | |
3938 | ||
03dd20cc DJ |
3939 | /* The queue starts out with one item, but following a DIE reference |
3940 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
3941 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
3942 | { | |
9291a0cd TT |
3943 | if (dwarf2_per_objfile->using_index |
3944 | ? !item->per_cu->v.quick->symtab | |
3945 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
3946 | process_full_comp_unit (item->per_cu); |
3947 | ||
3948 | item->per_cu->queued = 0; | |
3949 | next_item = item->next; | |
3950 | xfree (item); | |
3951 | } | |
3952 | ||
3953 | dwarf2_queue_tail = NULL; | |
3954 | } | |
3955 | ||
3956 | /* Free all allocated queue entries. This function only releases anything if | |
3957 | an error was thrown; if the queue was processed then it would have been | |
3958 | freed as we went along. */ | |
3959 | ||
3960 | static void | |
3961 | dwarf2_release_queue (void *dummy) | |
3962 | { | |
3963 | struct dwarf2_queue_item *item, *last; | |
3964 | ||
3965 | item = dwarf2_queue; | |
3966 | while (item) | |
3967 | { | |
3968 | /* Anything still marked queued is likely to be in an | |
3969 | inconsistent state, so discard it. */ | |
3970 | if (item->per_cu->queued) | |
3971 | { | |
3972 | if (item->per_cu->cu != NULL) | |
3973 | free_one_cached_comp_unit (item->per_cu->cu); | |
3974 | item->per_cu->queued = 0; | |
3975 | } | |
3976 | ||
3977 | last = item; | |
3978 | item = item->next; | |
3979 | xfree (last); | |
3980 | } | |
3981 | ||
3982 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
3983 | } | |
3984 | ||
3985 | /* Read in full symbols for PST, and anything it depends on. */ | |
3986 | ||
c906108c | 3987 | static void |
fba45db2 | 3988 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 3989 | { |
10b3939b | 3990 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 3991 | struct cleanup *back_to; |
aaa75496 JB |
3992 | int i; |
3993 | ||
3994 | for (i = 0; i < pst->number_of_dependencies; i++) | |
3995 | if (!pst->dependencies[i]->readin) | |
3996 | { | |
3997 | /* Inform about additional files that need to be read in. */ | |
3998 | if (info_verbose) | |
3999 | { | |
a3f17187 | 4000 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4001 | fputs_filtered (" ", gdb_stdout); |
4002 | wrap_here (""); | |
4003 | fputs_filtered ("and ", gdb_stdout); | |
4004 | wrap_here (""); | |
4005 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
4006 | wrap_here (""); /* Flush output */ | |
4007 | gdb_flush (gdb_stdout); | |
4008 | } | |
4009 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4010 | } | |
4011 | ||
e38df1d0 | 4012 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4013 | |
4014 | if (per_cu == NULL) | |
aaa75496 JB |
4015 | { |
4016 | /* It's an include file, no symbols to read for it. | |
4017 | Everything is in the parent symtab. */ | |
4018 | pst->readin = 1; | |
4019 | return; | |
4020 | } | |
c906108c | 4021 | |
9291a0cd | 4022 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4023 | } |
4024 | ||
93311388 | 4025 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4026 | |
93311388 | 4027 | static void |
31ffec48 | 4028 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 4029 | { |
31ffec48 | 4030 | bfd *abfd = objfile->obfd; |
10b3939b | 4031 | struct dwarf2_cu *cu; |
c764a876 | 4032 | unsigned int offset; |
93311388 | 4033 | gdb_byte *info_ptr, *beg_of_comp_unit; |
10b3939b DJ |
4034 | struct cleanup *back_to, *free_cu_cleanup; |
4035 | struct attribute *attr; | |
6502dd73 | 4036 | |
348e048f DE |
4037 | gdb_assert (! per_cu->from_debug_types); |
4038 | ||
c906108c | 4039 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4040 | offset = per_cu->offset; |
6502dd73 | 4041 | |
be391dca | 4042 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4043 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4044 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4045 | |
93311388 | 4046 | cu = alloc_one_comp_unit (objfile); |
c906108c | 4047 | |
10b3939b DJ |
4048 | /* If an error occurs while loading, release our storage. */ |
4049 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4050 | |
93311388 | 4051 | /* Read in the comp_unit header. */ |
10b3939b | 4052 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c | 4053 | |
93311388 DE |
4054 | /* Complete the cu_header. */ |
4055 | cu->header.offset = offset; | |
4056 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
4057 | ||
4058 | /* Read the abbrevs for this compilation unit. */ | |
10b3939b DJ |
4059 | dwarf2_read_abbrevs (abfd, cu); |
4060 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
4061 | ||
93311388 | 4062 | /* Link this compilation unit into the compilation unit tree. */ |
10b3939b | 4063 | per_cu->cu = cu; |
93311388 | 4064 | cu->per_cu = per_cu; |
f792889a | 4065 | cu->type_hash = per_cu->type_hash; |
e142c38c | 4066 | |
93311388 | 4067 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4068 | |
4069 | /* We try not to read any attributes in this function, because not | |
4070 | all objfiles needed for references have been loaded yet, and symbol | |
4071 | table processing isn't initialized. But we have to set the CU language, | |
4072 | or we won't be able to build types correctly. */ | |
4073 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
4074 | if (attr) | |
4075 | set_cu_language (DW_UNSND (attr), cu); | |
4076 | else | |
4077 | set_cu_language (language_minimal, cu); | |
4078 | ||
a6c727b2 DJ |
4079 | /* Similarly, if we do not read the producer, we can not apply |
4080 | producer-specific interpretation. */ | |
4081 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4082 | if (attr) | |
4083 | cu->producer = DW_STRING (attr); | |
4084 | ||
348e048f DE |
4085 | /* Link this CU into read_in_chain. */ |
4086 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4087 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4088 | ||
10b3939b | 4089 | do_cleanups (back_to); |
e142c38c | 4090 | |
10b3939b DJ |
4091 | /* We've successfully allocated this compilation unit. Let our caller |
4092 | clean it up when finished with it. */ | |
4093 | discard_cleanups (free_cu_cleanup); | |
10b3939b DJ |
4094 | } |
4095 | ||
4096 | /* Generate full symbol information for PST and CU, whose DIEs have | |
4097 | already been loaded into memory. */ | |
4098 | ||
4099 | static void | |
4100 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4101 | { | |
10b3939b | 4102 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4103 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4104 | CORE_ADDR lowpc, highpc; |
4105 | struct symtab *symtab; | |
4106 | struct cleanup *back_to; | |
10b3939b DJ |
4107 | CORE_ADDR baseaddr; |
4108 | ||
4109 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4110 | ||
10b3939b DJ |
4111 | buildsym_init (); |
4112 | back_to = make_cleanup (really_free_pendings, NULL); | |
4113 | ||
4114 | cu->list_in_scope = &file_symbols; | |
c906108c | 4115 | |
d85a05f0 | 4116 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4117 | |
c906108c | 4118 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4119 | process_die (cu->dies, cu); |
c906108c | 4120 | |
fae299cd DC |
4121 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4122 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4123 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4124 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4125 | |
613e1657 | 4126 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
4127 | |
4128 | /* Set symtab language to language from DW_AT_language. | |
4129 | If the compilation is from a C file generated by language preprocessors, | |
4130 | do not set the language if it was already deduced by start_subfile. */ | |
4131 | if (symtab != NULL | |
10b3939b | 4132 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 4133 | { |
10b3939b | 4134 | symtab->language = cu->language; |
c906108c | 4135 | } |
9291a0cd TT |
4136 | |
4137 | if (dwarf2_per_objfile->using_index) | |
4138 | per_cu->v.quick->symtab = symtab; | |
4139 | else | |
4140 | { | |
4141 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4142 | pst->symtab = symtab; | |
4143 | pst->readin = 1; | |
4144 | } | |
c906108c SS |
4145 | |
4146 | do_cleanups (back_to); | |
4147 | } | |
4148 | ||
4149 | /* Process a die and its children. */ | |
4150 | ||
4151 | static void | |
e7c27a73 | 4152 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4153 | { |
4154 | switch (die->tag) | |
4155 | { | |
4156 | case DW_TAG_padding: | |
4157 | break; | |
4158 | case DW_TAG_compile_unit: | |
e7c27a73 | 4159 | read_file_scope (die, cu); |
c906108c | 4160 | break; |
348e048f DE |
4161 | case DW_TAG_type_unit: |
4162 | read_type_unit_scope (die, cu); | |
4163 | break; | |
c906108c | 4164 | case DW_TAG_subprogram: |
c906108c | 4165 | case DW_TAG_inlined_subroutine: |
edb3359d | 4166 | read_func_scope (die, cu); |
c906108c SS |
4167 | break; |
4168 | case DW_TAG_lexical_block: | |
14898363 L |
4169 | case DW_TAG_try_block: |
4170 | case DW_TAG_catch_block: | |
e7c27a73 | 4171 | read_lexical_block_scope (die, cu); |
c906108c SS |
4172 | break; |
4173 | case DW_TAG_class_type: | |
680b30c7 | 4174 | case DW_TAG_interface_type: |
c906108c SS |
4175 | case DW_TAG_structure_type: |
4176 | case DW_TAG_union_type: | |
134d01f1 | 4177 | process_structure_scope (die, cu); |
c906108c SS |
4178 | break; |
4179 | case DW_TAG_enumeration_type: | |
134d01f1 | 4180 | process_enumeration_scope (die, cu); |
c906108c | 4181 | break; |
134d01f1 | 4182 | |
f792889a DJ |
4183 | /* These dies have a type, but processing them does not create |
4184 | a symbol or recurse to process the children. Therefore we can | |
4185 | read them on-demand through read_type_die. */ | |
c906108c | 4186 | case DW_TAG_subroutine_type: |
72019c9c | 4187 | case DW_TAG_set_type: |
c906108c | 4188 | case DW_TAG_array_type: |
c906108c | 4189 | case DW_TAG_pointer_type: |
c906108c | 4190 | case DW_TAG_ptr_to_member_type: |
c906108c | 4191 | case DW_TAG_reference_type: |
c906108c | 4192 | case DW_TAG_string_type: |
c906108c | 4193 | break; |
134d01f1 | 4194 | |
c906108c | 4195 | case DW_TAG_base_type: |
a02abb62 | 4196 | case DW_TAG_subrange_type: |
cb249c71 | 4197 | case DW_TAG_typedef: |
90e7c2c5 PM |
4198 | case DW_TAG_const_type: |
4199 | case DW_TAG_volatile_type: | |
134d01f1 DJ |
4200 | /* Add a typedef symbol for the type definition, if it has a |
4201 | DW_AT_name. */ | |
f792889a | 4202 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4203 | break; |
c906108c | 4204 | case DW_TAG_common_block: |
e7c27a73 | 4205 | read_common_block (die, cu); |
c906108c SS |
4206 | break; |
4207 | case DW_TAG_common_inclusion: | |
4208 | break; | |
d9fa45fe | 4209 | case DW_TAG_namespace: |
63d06c5c | 4210 | processing_has_namespace_info = 1; |
e7c27a73 | 4211 | read_namespace (die, cu); |
d9fa45fe | 4212 | break; |
5d7cb8df | 4213 | case DW_TAG_module: |
f55ee35c | 4214 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4215 | read_module (die, cu); |
4216 | break; | |
d9fa45fe DC |
4217 | case DW_TAG_imported_declaration: |
4218 | case DW_TAG_imported_module: | |
63d06c5c | 4219 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4220 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4221 | || cu->language != language_fortran)) | |
4222 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4223 | dwarf_tag_name (die->tag)); | |
4224 | read_import_statement (die, cu); | |
d9fa45fe | 4225 | break; |
c906108c | 4226 | default: |
e7c27a73 | 4227 | new_symbol (die, NULL, cu); |
c906108c SS |
4228 | break; |
4229 | } | |
4230 | } | |
4231 | ||
94af9270 KS |
4232 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4233 | needs to have the name of the scope prepended to the name listed in the | |
4234 | die. */ | |
4235 | ||
4236 | static int | |
4237 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4238 | { | |
1c809c68 TT |
4239 | struct attribute *attr; |
4240 | ||
94af9270 KS |
4241 | switch (die->tag) |
4242 | { | |
4243 | case DW_TAG_namespace: | |
4244 | case DW_TAG_typedef: | |
4245 | case DW_TAG_class_type: | |
4246 | case DW_TAG_interface_type: | |
4247 | case DW_TAG_structure_type: | |
4248 | case DW_TAG_union_type: | |
4249 | case DW_TAG_enumeration_type: | |
4250 | case DW_TAG_enumerator: | |
4251 | case DW_TAG_subprogram: | |
4252 | case DW_TAG_member: | |
4253 | return 1; | |
4254 | ||
4255 | case DW_TAG_variable: | |
4256 | /* We only need to prefix "globally" visible variables. These include | |
4257 | any variable marked with DW_AT_external or any variable that | |
4258 | lives in a namespace. [Variables in anonymous namespaces | |
4259 | require prefixing, but they are not DW_AT_external.] */ | |
4260 | ||
4261 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4262 | { | |
4263 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4264 | |
94af9270 KS |
4265 | return die_needs_namespace (die_specification (die, &spec_cu), |
4266 | spec_cu); | |
4267 | } | |
4268 | ||
1c809c68 | 4269 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4270 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4271 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4272 | return 0; |
4273 | /* A variable in a lexical block of some kind does not need a | |
4274 | namespace, even though in C++ such variables may be external | |
4275 | and have a mangled name. */ | |
4276 | if (die->parent->tag == DW_TAG_lexical_block | |
4277 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4278 | || die->parent->tag == DW_TAG_catch_block |
4279 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4280 | return 0; |
4281 | return 1; | |
94af9270 KS |
4282 | |
4283 | default: | |
4284 | return 0; | |
4285 | } | |
4286 | } | |
4287 | ||
4288 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, | |
4289 | compute the physname for the object, which include a method's | |
4290 | formal parameters (C++/Java) and return type (Java). | |
4291 | ||
af6b7be1 JB |
4292 | For Ada, return the DIE's linkage name rather than the fully qualified |
4293 | name. PHYSNAME is ignored.. | |
4294 | ||
94af9270 KS |
4295 | The result is allocated on the objfile_obstack and canonicalized. */ |
4296 | ||
4297 | static const char * | |
4298 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4299 | int physname) | |
4300 | { | |
4301 | if (name == NULL) | |
4302 | name = dwarf2_name (die, cu); | |
4303 | ||
f55ee35c JK |
4304 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4305 | compute it by typename_concat inside GDB. */ | |
4306 | if (cu->language == language_ada | |
4307 | || (cu->language == language_fortran && physname)) | |
4308 | { | |
4309 | /* For Ada unit, we prefer the linkage name over the name, as | |
4310 | the former contains the exported name, which the user expects | |
4311 | to be able to reference. Ideally, we want the user to be able | |
4312 | to reference this entity using either natural or linkage name, | |
4313 | but we haven't started looking at this enhancement yet. */ | |
4314 | struct attribute *attr; | |
4315 | ||
4316 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4317 | if (attr == NULL) | |
4318 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4319 | if (attr && DW_STRING (attr)) | |
4320 | return DW_STRING (attr); | |
4321 | } | |
4322 | ||
94af9270 KS |
4323 | /* These are the only languages we know how to qualify names in. */ |
4324 | if (name != NULL | |
f55ee35c JK |
4325 | && (cu->language == language_cplus || cu->language == language_java |
4326 | || cu->language == language_fortran)) | |
94af9270 KS |
4327 | { |
4328 | if (die_needs_namespace (die, cu)) | |
4329 | { | |
4330 | long length; | |
4331 | char *prefix; | |
4332 | struct ui_file *buf; | |
4333 | ||
4334 | prefix = determine_prefix (die, cu); | |
4335 | buf = mem_fileopen (); | |
4336 | if (*prefix != '\0') | |
4337 | { | |
f55ee35c JK |
4338 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4339 | physname, cu); | |
9a619af0 | 4340 | |
94af9270 KS |
4341 | fputs_unfiltered (prefixed_name, buf); |
4342 | xfree (prefixed_name); | |
4343 | } | |
4344 | else | |
4345 | fputs_unfiltered (name ? name : "", buf); | |
4346 | ||
4347 | /* For Java and C++ methods, append formal parameter type | |
4348 | information, if PHYSNAME. */ | |
6e70227d | 4349 | |
94af9270 KS |
4350 | if (physname && die->tag == DW_TAG_subprogram |
4351 | && (cu->language == language_cplus | |
4352 | || cu->language == language_java)) | |
4353 | { | |
4354 | struct type *type = read_type_die (die, cu); | |
4355 | ||
4356 | c_type_print_args (type, buf, 0, cu->language); | |
4357 | ||
4358 | if (cu->language == language_java) | |
4359 | { | |
4360 | /* For java, we must append the return type to method | |
4361 | names. */ | |
4362 | if (die->tag == DW_TAG_subprogram) | |
4363 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
4364 | 0, 0); | |
4365 | } | |
4366 | else if (cu->language == language_cplus) | |
4367 | { | |
4368 | if (TYPE_NFIELDS (type) > 0 | |
4369 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
4370 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) | |
4371 | fputs_unfiltered (" const", buf); | |
4372 | } | |
4373 | } | |
4374 | ||
4375 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
4376 | &length); | |
4377 | ui_file_delete (buf); | |
4378 | ||
4379 | if (cu->language == language_cplus) | |
4380 | { | |
4381 | char *cname | |
4382 | = dwarf2_canonicalize_name (name, cu, | |
4383 | &cu->objfile->objfile_obstack); | |
9a619af0 | 4384 | |
94af9270 KS |
4385 | if (cname != NULL) |
4386 | name = cname; | |
4387 | } | |
4388 | } | |
4389 | } | |
4390 | ||
4391 | return name; | |
4392 | } | |
4393 | ||
0114d602 DJ |
4394 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
4395 | If scope qualifiers are appropriate they will be added. The result | |
4396 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
4397 | not have a name. NAME may either be from a previous call to |
4398 | dwarf2_name or NULL. | |
4399 | ||
4400 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
4401 | |
4402 | static const char * | |
94af9270 | 4403 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 4404 | { |
94af9270 KS |
4405 | return dwarf2_compute_name (name, die, cu, 0); |
4406 | } | |
0114d602 | 4407 | |
94af9270 KS |
4408 | /* Construct a physname for the given DIE in CU. NAME may either be |
4409 | from a previous call to dwarf2_name or NULL. The result will be | |
4410 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
4411 | name. | |
0114d602 | 4412 | |
94af9270 | 4413 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 4414 | |
94af9270 KS |
4415 | static const char * |
4416 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
4417 | { | |
4418 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
4419 | } |
4420 | ||
27aa8d6a SW |
4421 | /* Read the import statement specified by the given die and record it. */ |
4422 | ||
4423 | static void | |
4424 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
4425 | { | |
4426 | struct attribute *import_attr; | |
4427 | struct die_info *imported_die; | |
de4affc9 | 4428 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 4429 | const char *imported_name; |
794684b6 | 4430 | const char *imported_name_prefix; |
13387711 SW |
4431 | const char *canonical_name; |
4432 | const char *import_alias; | |
4433 | const char *imported_declaration = NULL; | |
794684b6 | 4434 | const char *import_prefix; |
13387711 SW |
4435 | |
4436 | char *temp; | |
27aa8d6a SW |
4437 | |
4438 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
4439 | if (import_attr == NULL) | |
4440 | { | |
4441 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
4442 | dwarf_tag_name (die->tag)); | |
4443 | return; | |
4444 | } | |
4445 | ||
de4affc9 CC |
4446 | imported_cu = cu; |
4447 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
4448 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
4449 | if (imported_name == NULL) |
4450 | { | |
4451 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
4452 | ||
4453 | The import in the following code: | |
4454 | namespace A | |
4455 | { | |
4456 | typedef int B; | |
4457 | } | |
4458 | ||
4459 | int main () | |
4460 | { | |
4461 | using A::B; | |
4462 | B b; | |
4463 | return b; | |
4464 | } | |
4465 | ||
4466 | ... | |
4467 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
4468 | <52> DW_AT_decl_file : 1 | |
4469 | <53> DW_AT_decl_line : 6 | |
4470 | <54> DW_AT_import : <0x75> | |
4471 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
4472 | <59> DW_AT_name : B | |
4473 | <5b> DW_AT_decl_file : 1 | |
4474 | <5c> DW_AT_decl_line : 2 | |
4475 | <5d> DW_AT_type : <0x6e> | |
4476 | ... | |
4477 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
4478 | <76> DW_AT_byte_size : 4 | |
4479 | <77> DW_AT_encoding : 5 (signed) | |
4480 | ||
4481 | imports the wrong die ( 0x75 instead of 0x58 ). | |
4482 | This case will be ignored until the gcc bug is fixed. */ | |
4483 | return; | |
4484 | } | |
4485 | ||
82856980 SW |
4486 | /* Figure out the local name after import. */ |
4487 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 4488 | |
794684b6 SW |
4489 | /* Figure out where the statement is being imported to. */ |
4490 | import_prefix = determine_prefix (die, cu); | |
4491 | ||
4492 | /* Figure out what the scope of the imported die is and prepend it | |
4493 | to the name of the imported die. */ | |
de4affc9 | 4494 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 4495 | |
f55ee35c JK |
4496 | if (imported_die->tag != DW_TAG_namespace |
4497 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 4498 | { |
13387711 SW |
4499 | imported_declaration = imported_name; |
4500 | canonical_name = imported_name_prefix; | |
794684b6 | 4501 | } |
13387711 | 4502 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 4503 | { |
13387711 SW |
4504 | temp = alloca (strlen (imported_name_prefix) |
4505 | + 2 + strlen (imported_name) + 1); | |
4506 | strcpy (temp, imported_name_prefix); | |
4507 | strcat (temp, "::"); | |
4508 | strcat (temp, imported_name); | |
4509 | canonical_name = temp; | |
794684b6 | 4510 | } |
13387711 SW |
4511 | else |
4512 | canonical_name = imported_name; | |
794684b6 | 4513 | |
c0cc3a76 SW |
4514 | cp_add_using_directive (import_prefix, |
4515 | canonical_name, | |
4516 | import_alias, | |
13387711 | 4517 | imported_declaration, |
c0cc3a76 | 4518 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
4519 | } |
4520 | ||
5fb290d7 | 4521 | static void |
e142c38c | 4522 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 4523 | { |
e142c38c | 4524 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
4525 | } |
4526 | ||
cb1df416 DJ |
4527 | static void |
4528 | free_cu_line_header (void *arg) | |
4529 | { | |
4530 | struct dwarf2_cu *cu = arg; | |
4531 | ||
4532 | free_line_header (cu->line_header); | |
4533 | cu->line_header = NULL; | |
4534 | } | |
4535 | ||
9291a0cd TT |
4536 | static void |
4537 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
4538 | char **name, char **comp_dir) | |
4539 | { | |
4540 | struct attribute *attr; | |
4541 | ||
4542 | *name = NULL; | |
4543 | *comp_dir = NULL; | |
4544 | ||
4545 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
4546 | is not a source language identifier. */ | |
4547 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
4548 | if (attr) | |
4549 | { | |
4550 | *name = DW_STRING (attr); | |
4551 | } | |
4552 | ||
4553 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
4554 | if (attr) | |
4555 | *comp_dir = DW_STRING (attr); | |
4556 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
4557 | { | |
4558 | *comp_dir = ldirname (*name); | |
4559 | if (*comp_dir != NULL) | |
4560 | make_cleanup (xfree, *comp_dir); | |
4561 | } | |
4562 | if (*comp_dir != NULL) | |
4563 | { | |
4564 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
4565 | directory, get rid of it. */ | |
4566 | char *cp = strchr (*comp_dir, ':'); | |
4567 | ||
4568 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
4569 | *comp_dir = cp + 1; | |
4570 | } | |
4571 | ||
4572 | if (*name == NULL) | |
4573 | *name = "<unknown>"; | |
4574 | } | |
4575 | ||
c906108c | 4576 | static void |
e7c27a73 | 4577 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4578 | { |
e7c27a73 | 4579 | struct objfile *objfile = cu->objfile; |
debd256d | 4580 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 4581 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
4582 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
4583 | struct attribute *attr; | |
e1024ff1 | 4584 | char *name = NULL; |
c906108c SS |
4585 | char *comp_dir = NULL; |
4586 | struct die_info *child_die; | |
4587 | bfd *abfd = objfile->obfd; | |
debd256d | 4588 | struct line_header *line_header = 0; |
e142c38c | 4589 | CORE_ADDR baseaddr; |
6e70227d | 4590 | |
e142c38c | 4591 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 4592 | |
fae299cd | 4593 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
4594 | |
4595 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
4596 | from finish_block. */ | |
2acceee2 | 4597 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
4598 | lowpc = highpc; |
4599 | lowpc += baseaddr; | |
4600 | highpc += baseaddr; | |
4601 | ||
9291a0cd | 4602 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 4603 | |
e142c38c | 4604 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
4605 | if (attr) |
4606 | { | |
e142c38c | 4607 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
4608 | } |
4609 | ||
b0f35d58 | 4610 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 4611 | if (attr) |
b0f35d58 | 4612 | cu->producer = DW_STRING (attr); |
303b6f5d | 4613 | |
c906108c SS |
4614 | /* We assume that we're processing GCC output. */ |
4615 | processing_gcc_compilation = 2; | |
c906108c | 4616 | |
df8a16a1 DJ |
4617 | processing_has_namespace_info = 0; |
4618 | ||
c906108c SS |
4619 | start_symtab (name, comp_dir, lowpc); |
4620 | record_debugformat ("DWARF 2"); | |
303b6f5d | 4621 | record_producer (cu->producer); |
c906108c | 4622 | |
e142c38c | 4623 | initialize_cu_func_list (cu); |
c906108c | 4624 | |
cb1df416 DJ |
4625 | /* Decode line number information if present. We do this before |
4626 | processing child DIEs, so that the line header table is available | |
4627 | for DW_AT_decl_file. */ | |
e142c38c | 4628 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
4629 | if (attr) |
4630 | { | |
debd256d | 4631 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 4632 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
4633 | if (line_header) |
4634 | { | |
cb1df416 DJ |
4635 | cu->line_header = line_header; |
4636 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 4637 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 4638 | } |
5fb290d7 | 4639 | } |
debd256d | 4640 | |
cb1df416 DJ |
4641 | /* Process all dies in compilation unit. */ |
4642 | if (die->child != NULL) | |
4643 | { | |
4644 | child_die = die->child; | |
4645 | while (child_die && child_die->tag) | |
4646 | { | |
4647 | process_die (child_die, cu); | |
4648 | child_die = sibling_die (child_die); | |
4649 | } | |
4650 | } | |
4651 | ||
2e276125 JB |
4652 | /* Decode macro information, if present. Dwarf 2 macro information |
4653 | refers to information in the line number info statement program | |
4654 | header, so we can only read it if we've read the header | |
4655 | successfully. */ | |
e142c38c | 4656 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 4657 | if (attr && line_header) |
2e276125 JB |
4658 | { |
4659 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 4660 | |
2e276125 | 4661 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 4662 | comp_dir, abfd, cu); |
2e276125 | 4663 | } |
debd256d | 4664 | do_cleanups (back_to); |
5fb290d7 DJ |
4665 | } |
4666 | ||
348e048f DE |
4667 | /* For TUs we want to skip the first top level sibling if it's not the |
4668 | actual type being defined by this TU. In this case the first top | |
4669 | level sibling is there to provide context only. */ | |
4670 | ||
4671 | static void | |
4672 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4673 | { | |
4674 | struct objfile *objfile = cu->objfile; | |
4675 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
4676 | CORE_ADDR lowpc; | |
4677 | struct attribute *attr; | |
4678 | char *name = NULL; | |
4679 | char *comp_dir = NULL; | |
4680 | struct die_info *child_die; | |
4681 | bfd *abfd = objfile->obfd; | |
348e048f DE |
4682 | |
4683 | /* start_symtab needs a low pc, but we don't really have one. | |
4684 | Do what read_file_scope would do in the absence of such info. */ | |
4685 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4686 | ||
4687 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
4688 | is not a source language identifier. */ | |
4689 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
4690 | if (attr) | |
4691 | name = DW_STRING (attr); | |
4692 | ||
4693 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
4694 | if (attr) | |
4695 | comp_dir = DW_STRING (attr); | |
4696 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
4697 | { | |
4698 | comp_dir = ldirname (name); | |
4699 | if (comp_dir != NULL) | |
4700 | make_cleanup (xfree, comp_dir); | |
4701 | } | |
4702 | ||
4703 | if (name == NULL) | |
4704 | name = "<unknown>"; | |
4705 | ||
4706 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
4707 | if (attr) | |
4708 | set_cu_language (DW_UNSND (attr), cu); | |
4709 | ||
4710 | /* This isn't technically needed today. It is done for symmetry | |
4711 | with read_file_scope. */ | |
4712 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 4713 | if (attr) |
348e048f DE |
4714 | cu->producer = DW_STRING (attr); |
4715 | ||
4716 | /* We assume that we're processing GCC output. */ | |
4717 | processing_gcc_compilation = 2; | |
4718 | ||
4719 | processing_has_namespace_info = 0; | |
4720 | ||
4721 | start_symtab (name, comp_dir, lowpc); | |
4722 | record_debugformat ("DWARF 2"); | |
4723 | record_producer (cu->producer); | |
4724 | ||
4725 | /* Process the dies in the type unit. */ | |
4726 | if (die->child == NULL) | |
4727 | { | |
4728 | dump_die_for_error (die); | |
4729 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
4730 | bfd_get_filename (abfd)); | |
4731 | } | |
4732 | ||
4733 | child_die = die->child; | |
4734 | ||
4735 | while (child_die && child_die->tag) | |
4736 | { | |
4737 | process_die (child_die, cu); | |
4738 | ||
4739 | child_die = sibling_die (child_die); | |
4740 | } | |
4741 | ||
4742 | do_cleanups (back_to); | |
4743 | } | |
4744 | ||
5fb290d7 | 4745 | static void |
e142c38c DJ |
4746 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
4747 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
4748 | { |
4749 | struct function_range *thisfn; | |
4750 | ||
4751 | thisfn = (struct function_range *) | |
7b5a2f43 | 4752 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
4753 | thisfn->name = name; |
4754 | thisfn->lowpc = lowpc; | |
4755 | thisfn->highpc = highpc; | |
4756 | thisfn->seen_line = 0; | |
4757 | thisfn->next = NULL; | |
4758 | ||
e142c38c DJ |
4759 | if (cu->last_fn == NULL) |
4760 | cu->first_fn = thisfn; | |
5fb290d7 | 4761 | else |
e142c38c | 4762 | cu->last_fn->next = thisfn; |
5fb290d7 | 4763 | |
e142c38c | 4764 | cu->last_fn = thisfn; |
c906108c SS |
4765 | } |
4766 | ||
d389af10 JK |
4767 | /* qsort helper for inherit_abstract_dies. */ |
4768 | ||
4769 | static int | |
4770 | unsigned_int_compar (const void *ap, const void *bp) | |
4771 | { | |
4772 | unsigned int a = *(unsigned int *) ap; | |
4773 | unsigned int b = *(unsigned int *) bp; | |
4774 | ||
4775 | return (a > b) - (b > a); | |
4776 | } | |
4777 | ||
4778 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
4779 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
4780 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
4781 | ||
4782 | static void | |
4783 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
4784 | { | |
4785 | struct die_info *child_die; | |
4786 | unsigned die_children_count; | |
4787 | /* CU offsets which were referenced by children of the current DIE. */ | |
4788 | unsigned *offsets; | |
4789 | unsigned *offsets_end, *offsetp; | |
4790 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
4791 | struct die_info *origin_die; | |
4792 | /* Iterator of the ORIGIN_DIE children. */ | |
4793 | struct die_info *origin_child_die; | |
4794 | struct cleanup *cleanups; | |
4795 | struct attribute *attr; | |
4796 | ||
4797 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
4798 | if (!attr) | |
4799 | return; | |
4800 | ||
4801 | origin_die = follow_die_ref (die, attr, &cu); | |
edb3359d DJ |
4802 | if (die->tag != origin_die->tag |
4803 | && !(die->tag == DW_TAG_inlined_subroutine | |
4804 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
4805 | complaint (&symfile_complaints, |
4806 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
4807 | die->offset, origin_die->offset); | |
4808 | ||
4809 | child_die = die->child; | |
4810 | die_children_count = 0; | |
4811 | while (child_die && child_die->tag) | |
4812 | { | |
4813 | child_die = sibling_die (child_die); | |
4814 | die_children_count++; | |
4815 | } | |
4816 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
4817 | cleanups = make_cleanup (xfree, offsets); | |
4818 | ||
4819 | offsets_end = offsets; | |
4820 | child_die = die->child; | |
4821 | while (child_die && child_die->tag) | |
4822 | { | |
c38f313d DJ |
4823 | /* For each CHILD_DIE, find the corresponding child of |
4824 | ORIGIN_DIE. If there is more than one layer of | |
4825 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
4826 | but GCC versions at least through 4.4 generate this (GCC PR | |
4827 | 40573). */ | |
4828 | struct die_info *child_origin_die = child_die; | |
9a619af0 | 4829 | |
c38f313d DJ |
4830 | while (1) |
4831 | { | |
4832 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); | |
4833 | if (attr == NULL) | |
4834 | break; | |
4835 | child_origin_die = follow_die_ref (child_origin_die, attr, &cu); | |
4836 | } | |
4837 | ||
d389af10 JK |
4838 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
4839 | counterpart may exist. */ | |
c38f313d | 4840 | if (child_origin_die != child_die) |
d389af10 | 4841 | { |
edb3359d DJ |
4842 | if (child_die->tag != child_origin_die->tag |
4843 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
4844 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
4845 | complaint (&symfile_complaints, |
4846 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
4847 | "different tags"), child_die->offset, | |
4848 | child_origin_die->offset); | |
c38f313d DJ |
4849 | if (child_origin_die->parent != origin_die) |
4850 | complaint (&symfile_complaints, | |
4851 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
4852 | "different parents"), child_die->offset, | |
4853 | child_origin_die->offset); | |
4854 | else | |
4855 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
4856 | } |
4857 | child_die = sibling_die (child_die); | |
4858 | } | |
4859 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
4860 | unsigned_int_compar); | |
4861 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
4862 | if (offsetp[-1] == *offsetp) | |
4863 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
4864 | "to DIE 0x%x as their abstract origin"), | |
4865 | die->offset, *offsetp); | |
4866 | ||
4867 | offsetp = offsets; | |
4868 | origin_child_die = origin_die->child; | |
4869 | while (origin_child_die && origin_child_die->tag) | |
4870 | { | |
4871 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
4872 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
4873 | offsetp++; | |
4874 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
4875 | { | |
4876 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
4877 | process_die (origin_child_die, cu); | |
4878 | } | |
4879 | origin_child_die = sibling_die (origin_child_die); | |
4880 | } | |
4881 | ||
4882 | do_cleanups (cleanups); | |
4883 | } | |
4884 | ||
c906108c | 4885 | static void |
e7c27a73 | 4886 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4887 | { |
e7c27a73 | 4888 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 4889 | struct context_stack *new; |
c906108c SS |
4890 | CORE_ADDR lowpc; |
4891 | CORE_ADDR highpc; | |
4892 | struct die_info *child_die; | |
edb3359d | 4893 | struct attribute *attr, *call_line, *call_file; |
c906108c | 4894 | char *name; |
e142c38c | 4895 | CORE_ADDR baseaddr; |
801e3a5b | 4896 | struct block *block; |
edb3359d DJ |
4897 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
4898 | ||
4899 | if (inlined_func) | |
4900 | { | |
4901 | /* If we do not have call site information, we can't show the | |
4902 | caller of this inlined function. That's too confusing, so | |
4903 | only use the scope for local variables. */ | |
4904 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
4905 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
4906 | if (call_line == NULL || call_file == NULL) | |
4907 | { | |
4908 | read_lexical_block_scope (die, cu); | |
4909 | return; | |
4910 | } | |
4911 | } | |
c906108c | 4912 | |
e142c38c DJ |
4913 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
4914 | ||
94af9270 | 4915 | name = dwarf2_name (die, cu); |
c906108c | 4916 | |
e8d05480 JB |
4917 | /* Ignore functions with missing or empty names. These are actually |
4918 | illegal according to the DWARF standard. */ | |
4919 | if (name == NULL) | |
4920 | { | |
4921 | complaint (&symfile_complaints, | |
4922 | _("missing name for subprogram DIE at %d"), die->offset); | |
4923 | return; | |
4924 | } | |
4925 | ||
4926 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
4927 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
4928 | { | |
ae4d0c03 PM |
4929 | attr = dwarf2_attr (die, DW_AT_external, cu); |
4930 | if (!attr || !DW_UNSND (attr)) | |
4931 | complaint (&symfile_complaints, | |
4932 | _("cannot get low and high bounds for subprogram DIE at %d"), | |
4933 | die->offset); | |
e8d05480 JB |
4934 | return; |
4935 | } | |
c906108c SS |
4936 | |
4937 | lowpc += baseaddr; | |
4938 | highpc += baseaddr; | |
4939 | ||
5fb290d7 | 4940 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 4941 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 4942 | |
c906108c | 4943 | new = push_context (0, lowpc); |
f792889a | 4944 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 4945 | |
4cecd739 DJ |
4946 | /* If there is a location expression for DW_AT_frame_base, record |
4947 | it. */ | |
e142c38c | 4948 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 4949 | if (attr) |
c034e007 AC |
4950 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
4951 | expression is being recorded directly in the function's symbol | |
4952 | and not in a separate frame-base object. I guess this hack is | |
4953 | to avoid adding some sort of frame-base adjunct/annex to the | |
4954 | function's symbol :-(. The problem with doing this is that it | |
4955 | results in a function symbol with a location expression that | |
4956 | has nothing to do with the location of the function, ouch! The | |
4957 | relationship should be: a function's symbol has-a frame base; a | |
4958 | frame-base has-a location expression. */ | |
e7c27a73 | 4959 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 4960 | |
e142c38c | 4961 | cu->list_in_scope = &local_symbols; |
c906108c | 4962 | |
639d11d3 | 4963 | if (die->child != NULL) |
c906108c | 4964 | { |
639d11d3 | 4965 | child_die = die->child; |
c906108c SS |
4966 | while (child_die && child_die->tag) |
4967 | { | |
e7c27a73 | 4968 | process_die (child_die, cu); |
c906108c SS |
4969 | child_die = sibling_die (child_die); |
4970 | } | |
4971 | } | |
4972 | ||
d389af10 JK |
4973 | inherit_abstract_dies (die, cu); |
4974 | ||
4a811a97 UW |
4975 | /* If we have a DW_AT_specification, we might need to import using |
4976 | directives from the context of the specification DIE. See the | |
4977 | comment in determine_prefix. */ | |
4978 | if (cu->language == language_cplus | |
4979 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
4980 | { | |
4981 | struct dwarf2_cu *spec_cu = cu; | |
4982 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
4983 | ||
4984 | while (spec_die) | |
4985 | { | |
4986 | child_die = spec_die->child; | |
4987 | while (child_die && child_die->tag) | |
4988 | { | |
4989 | if (child_die->tag == DW_TAG_imported_module) | |
4990 | process_die (child_die, spec_cu); | |
4991 | child_die = sibling_die (child_die); | |
4992 | } | |
4993 | ||
4994 | /* In some cases, GCC generates specification DIEs that | |
4995 | themselves contain DW_AT_specification attributes. */ | |
4996 | spec_die = die_specification (spec_die, &spec_cu); | |
4997 | } | |
4998 | } | |
4999 | ||
c906108c SS |
5000 | new = pop_context (); |
5001 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
5002 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
5003 | lowpc, highpc, objfile); | |
5004 | ||
df8a16a1 | 5005 | /* For C++, set the block's scope. */ |
f55ee35c | 5006 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5007 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5008 | determine_prefix (die, cu), |
df8a16a1 DJ |
5009 | processing_has_namespace_info); |
5010 | ||
801e3a5b JB |
5011 | /* If we have address ranges, record them. */ |
5012 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5013 | |
208d8187 JB |
5014 | /* In C++, we can have functions nested inside functions (e.g., when |
5015 | a function declares a class that has methods). This means that | |
5016 | when we finish processing a function scope, we may need to go | |
5017 | back to building a containing block's symbol lists. */ | |
5018 | local_symbols = new->locals; | |
5019 | param_symbols = new->params; | |
27aa8d6a | 5020 | using_directives = new->using_directives; |
208d8187 | 5021 | |
921e78cf JB |
5022 | /* If we've finished processing a top-level function, subsequent |
5023 | symbols go in the file symbol list. */ | |
5024 | if (outermost_context_p ()) | |
e142c38c | 5025 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5026 | } |
5027 | ||
5028 | /* Process all the DIES contained within a lexical block scope. Start | |
5029 | a new scope, process the dies, and then close the scope. */ | |
5030 | ||
5031 | static void | |
e7c27a73 | 5032 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5033 | { |
e7c27a73 | 5034 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5035 | struct context_stack *new; |
c906108c SS |
5036 | CORE_ADDR lowpc, highpc; |
5037 | struct die_info *child_die; | |
e142c38c DJ |
5038 | CORE_ADDR baseaddr; |
5039 | ||
5040 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5041 | |
5042 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5043 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5044 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5045 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5046 | describe ranges. */ |
d85a05f0 | 5047 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5048 | return; |
5049 | lowpc += baseaddr; | |
5050 | highpc += baseaddr; | |
5051 | ||
5052 | push_context (0, lowpc); | |
639d11d3 | 5053 | if (die->child != NULL) |
c906108c | 5054 | { |
639d11d3 | 5055 | child_die = die->child; |
c906108c SS |
5056 | while (child_die && child_die->tag) |
5057 | { | |
e7c27a73 | 5058 | process_die (child_die, cu); |
c906108c SS |
5059 | child_die = sibling_die (child_die); |
5060 | } | |
5061 | } | |
5062 | new = pop_context (); | |
5063 | ||
8540c487 | 5064 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5065 | { |
801e3a5b JB |
5066 | struct block *block |
5067 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5068 | highpc, objfile); | |
5069 | ||
5070 | /* Note that recording ranges after traversing children, as we | |
5071 | do here, means that recording a parent's ranges entails | |
5072 | walking across all its children's ranges as they appear in | |
5073 | the address map, which is quadratic behavior. | |
5074 | ||
5075 | It would be nicer to record the parent's ranges before | |
5076 | traversing its children, simply overriding whatever you find | |
5077 | there. But since we don't even decide whether to create a | |
5078 | block until after we've traversed its children, that's hard | |
5079 | to do. */ | |
5080 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5081 | } |
5082 | local_symbols = new->locals; | |
27aa8d6a | 5083 | using_directives = new->using_directives; |
c906108c SS |
5084 | } |
5085 | ||
43039443 | 5086 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5087 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5088 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5089 | |
5090 | static int | |
5091 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5092 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5093 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5094 | { |
5095 | struct objfile *objfile = cu->objfile; | |
5096 | struct comp_unit_head *cu_header = &cu->header; | |
5097 | bfd *obfd = objfile->obfd; | |
5098 | unsigned int addr_size = cu_header->addr_size; | |
5099 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5100 | /* Base address selection entry. */ | |
5101 | CORE_ADDR base; | |
5102 | int found_base; | |
5103 | unsigned int dummy; | |
5104 | gdb_byte *buffer; | |
5105 | CORE_ADDR marker; | |
5106 | int low_set; | |
5107 | CORE_ADDR low = 0; | |
5108 | CORE_ADDR high = 0; | |
ff013f42 | 5109 | CORE_ADDR baseaddr; |
43039443 | 5110 | |
d00adf39 DE |
5111 | found_base = cu->base_known; |
5112 | base = cu->base_address; | |
43039443 | 5113 | |
be391dca | 5114 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5115 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5116 | { |
5117 | complaint (&symfile_complaints, | |
5118 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5119 | offset); | |
5120 | return 0; | |
5121 | } | |
dce234bc | 5122 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5123 | |
5124 | /* Read in the largest possible address. */ | |
5125 | marker = read_address (obfd, buffer, cu, &dummy); | |
5126 | if ((marker & mask) == mask) | |
5127 | { | |
5128 | /* If we found the largest possible address, then | |
5129 | read the base address. */ | |
5130 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5131 | buffer += 2 * addr_size; | |
5132 | offset += 2 * addr_size; | |
5133 | found_base = 1; | |
5134 | } | |
5135 | ||
5136 | low_set = 0; | |
5137 | ||
e7030f15 | 5138 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5139 | |
43039443 JK |
5140 | while (1) |
5141 | { | |
5142 | CORE_ADDR range_beginning, range_end; | |
5143 | ||
5144 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5145 | buffer += addr_size; | |
5146 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5147 | buffer += addr_size; | |
5148 | offset += 2 * addr_size; | |
5149 | ||
5150 | /* An end of list marker is a pair of zero addresses. */ | |
5151 | if (range_beginning == 0 && range_end == 0) | |
5152 | /* Found the end of list entry. */ | |
5153 | break; | |
5154 | ||
5155 | /* Each base address selection entry is a pair of 2 values. | |
5156 | The first is the largest possible address, the second is | |
5157 | the base address. Check for a base address here. */ | |
5158 | if ((range_beginning & mask) == mask) | |
5159 | { | |
5160 | /* If we found the largest possible address, then | |
5161 | read the base address. */ | |
5162 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5163 | found_base = 1; | |
5164 | continue; | |
5165 | } | |
5166 | ||
5167 | if (!found_base) | |
5168 | { | |
5169 | /* We have no valid base address for the ranges | |
5170 | data. */ | |
5171 | complaint (&symfile_complaints, | |
5172 | _("Invalid .debug_ranges data (no base address)")); | |
5173 | return 0; | |
5174 | } | |
5175 | ||
5176 | range_beginning += base; | |
5177 | range_end += base; | |
5178 | ||
ff013f42 JK |
5179 | if (ranges_pst != NULL && range_beginning < range_end) |
5180 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
5181 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
5182 | ranges_pst); | |
5183 | ||
43039443 JK |
5184 | /* FIXME: This is recording everything as a low-high |
5185 | segment of consecutive addresses. We should have a | |
5186 | data structure for discontiguous block ranges | |
5187 | instead. */ | |
5188 | if (! low_set) | |
5189 | { | |
5190 | low = range_beginning; | |
5191 | high = range_end; | |
5192 | low_set = 1; | |
5193 | } | |
5194 | else | |
5195 | { | |
5196 | if (range_beginning < low) | |
5197 | low = range_beginning; | |
5198 | if (range_end > high) | |
5199 | high = range_end; | |
5200 | } | |
5201 | } | |
5202 | ||
5203 | if (! low_set) | |
5204 | /* If the first entry is an end-of-list marker, the range | |
5205 | describes an empty scope, i.e. no instructions. */ | |
5206 | return 0; | |
5207 | ||
5208 | if (low_return) | |
5209 | *low_return = low; | |
5210 | if (high_return) | |
5211 | *high_return = high; | |
5212 | return 1; | |
5213 | } | |
5214 | ||
af34e669 DJ |
5215 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
5216 | are present and valid, otherwise, return 0. Return -1 if the range is | |
5217 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 5218 | static int |
af34e669 | 5219 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
5220 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
5221 | struct partial_symtab *pst) | |
c906108c SS |
5222 | { |
5223 | struct attribute *attr; | |
af34e669 DJ |
5224 | CORE_ADDR low = 0; |
5225 | CORE_ADDR high = 0; | |
5226 | int ret = 0; | |
c906108c | 5227 | |
e142c38c | 5228 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 5229 | if (attr) |
af34e669 DJ |
5230 | { |
5231 | high = DW_ADDR (attr); | |
e142c38c | 5232 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
5233 | if (attr) |
5234 | low = DW_ADDR (attr); | |
5235 | else | |
5236 | /* Found high w/o low attribute. */ | |
5237 | return 0; | |
5238 | ||
5239 | /* Found consecutive range of addresses. */ | |
5240 | ret = 1; | |
5241 | } | |
c906108c | 5242 | else |
af34e669 | 5243 | { |
e142c38c | 5244 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
5245 | if (attr != NULL) |
5246 | { | |
af34e669 | 5247 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 5248 | .debug_ranges section. */ |
d85a05f0 | 5249 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 5250 | return 0; |
43039443 | 5251 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
5252 | ret = -1; |
5253 | } | |
5254 | } | |
c906108c SS |
5255 | |
5256 | if (high < low) | |
5257 | return 0; | |
5258 | ||
5259 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
5260 | eliminate duplicate copies of functions and vtables and such. | |
5261 | The linker will arbitrarily choose one and discard the others. | |
5262 | The AT_*_pc values for such functions refer to local labels in | |
5263 | these sections. If the section from that file was discarded, the | |
5264 | labels are not in the output, so the relocs get a value of 0. | |
5265 | If this is a discarded function, mark the pc bounds as invalid, | |
5266 | so that GDB will ignore it. */ | |
72dca2f5 | 5267 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
5268 | return 0; |
5269 | ||
5270 | *lowpc = low; | |
5271 | *highpc = high; | |
af34e669 | 5272 | return ret; |
c906108c SS |
5273 | } |
5274 | ||
b084d499 JB |
5275 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
5276 | its low and high PC addresses. Do nothing if these addresses could not | |
5277 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
5278 | and HIGHPC to the high address if greater than HIGHPC. */ | |
5279 | ||
5280 | static void | |
5281 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
5282 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5283 | struct dwarf2_cu *cu) | |
5284 | { | |
5285 | CORE_ADDR low, high; | |
5286 | struct die_info *child = die->child; | |
5287 | ||
d85a05f0 | 5288 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
5289 | { |
5290 | *lowpc = min (*lowpc, low); | |
5291 | *highpc = max (*highpc, high); | |
5292 | } | |
5293 | ||
5294 | /* If the language does not allow nested subprograms (either inside | |
5295 | subprograms or lexical blocks), we're done. */ | |
5296 | if (cu->language != language_ada) | |
5297 | return; | |
6e70227d | 5298 | |
b084d499 JB |
5299 | /* Check all the children of the given DIE. If it contains nested |
5300 | subprograms, then check their pc bounds. Likewise, we need to | |
5301 | check lexical blocks as well, as they may also contain subprogram | |
5302 | definitions. */ | |
5303 | while (child && child->tag) | |
5304 | { | |
5305 | if (child->tag == DW_TAG_subprogram | |
5306 | || child->tag == DW_TAG_lexical_block) | |
5307 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
5308 | child = sibling_die (child); | |
5309 | } | |
5310 | } | |
5311 | ||
fae299cd DC |
5312 | /* Get the low and high pc's represented by the scope DIE, and store |
5313 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
5314 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
5315 | ||
5316 | static void | |
5317 | get_scope_pc_bounds (struct die_info *die, | |
5318 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5319 | struct dwarf2_cu *cu) | |
5320 | { | |
5321 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
5322 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
5323 | CORE_ADDR current_low, current_high; | |
5324 | ||
d85a05f0 | 5325 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
5326 | { |
5327 | best_low = current_low; | |
5328 | best_high = current_high; | |
5329 | } | |
5330 | else | |
5331 | { | |
5332 | struct die_info *child = die->child; | |
5333 | ||
5334 | while (child && child->tag) | |
5335 | { | |
5336 | switch (child->tag) { | |
5337 | case DW_TAG_subprogram: | |
b084d499 | 5338 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
5339 | break; |
5340 | case DW_TAG_namespace: | |
f55ee35c | 5341 | case DW_TAG_module: |
fae299cd DC |
5342 | /* FIXME: carlton/2004-01-16: Should we do this for |
5343 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
5344 | that current GCC's always emit the DIEs corresponding | |
5345 | to definitions of methods of classes as children of a | |
5346 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
5347 | the DIEs giving the declarations, which could be | |
5348 | anywhere). But I don't see any reason why the | |
5349 | standards says that they have to be there. */ | |
5350 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
5351 | ||
5352 | if (current_low != ((CORE_ADDR) -1)) | |
5353 | { | |
5354 | best_low = min (best_low, current_low); | |
5355 | best_high = max (best_high, current_high); | |
5356 | } | |
5357 | break; | |
5358 | default: | |
5359 | /* Ignore. */ | |
5360 | break; | |
5361 | } | |
5362 | ||
5363 | child = sibling_die (child); | |
5364 | } | |
5365 | } | |
5366 | ||
5367 | *lowpc = best_low; | |
5368 | *highpc = best_high; | |
5369 | } | |
5370 | ||
801e3a5b JB |
5371 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
5372 | in DIE. */ | |
5373 | static void | |
5374 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
5375 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
5376 | { | |
5377 | struct attribute *attr; | |
5378 | ||
5379 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
5380 | if (attr) | |
5381 | { | |
5382 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 5383 | |
801e3a5b JB |
5384 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
5385 | if (attr) | |
5386 | { | |
5387 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 5388 | |
801e3a5b JB |
5389 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
5390 | } | |
5391 | } | |
5392 | ||
5393 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
5394 | if (attr) | |
5395 | { | |
5396 | bfd *obfd = cu->objfile->obfd; | |
5397 | ||
5398 | /* The value of the DW_AT_ranges attribute is the offset of the | |
5399 | address range list in the .debug_ranges section. */ | |
5400 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 5401 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
5402 | |
5403 | /* For some target architectures, but not others, the | |
5404 | read_address function sign-extends the addresses it returns. | |
5405 | To recognize base address selection entries, we need a | |
5406 | mask. */ | |
5407 | unsigned int addr_size = cu->header.addr_size; | |
5408 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5409 | ||
5410 | /* The base address, to which the next pair is relative. Note | |
5411 | that this 'base' is a DWARF concept: most entries in a range | |
5412 | list are relative, to reduce the number of relocs against the | |
5413 | debugging information. This is separate from this function's | |
5414 | 'baseaddr' argument, which GDB uses to relocate debugging | |
5415 | information from a shared library based on the address at | |
5416 | which the library was loaded. */ | |
d00adf39 DE |
5417 | CORE_ADDR base = cu->base_address; |
5418 | int base_known = cu->base_known; | |
801e3a5b | 5419 | |
be391dca | 5420 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 5421 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
5422 | { |
5423 | complaint (&symfile_complaints, | |
5424 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
5425 | offset); | |
5426 | return; | |
5427 | } | |
5428 | ||
5429 | for (;;) | |
5430 | { | |
5431 | unsigned int bytes_read; | |
5432 | CORE_ADDR start, end; | |
5433 | ||
5434 | start = read_address (obfd, buffer, cu, &bytes_read); | |
5435 | buffer += bytes_read; | |
5436 | end = read_address (obfd, buffer, cu, &bytes_read); | |
5437 | buffer += bytes_read; | |
5438 | ||
5439 | /* Did we find the end of the range list? */ | |
5440 | if (start == 0 && end == 0) | |
5441 | break; | |
5442 | ||
5443 | /* Did we find a base address selection entry? */ | |
5444 | else if ((start & base_select_mask) == base_select_mask) | |
5445 | { | |
5446 | base = end; | |
5447 | base_known = 1; | |
5448 | } | |
5449 | ||
5450 | /* We found an ordinary address range. */ | |
5451 | else | |
5452 | { | |
5453 | if (!base_known) | |
5454 | { | |
5455 | complaint (&symfile_complaints, | |
5456 | _("Invalid .debug_ranges data (no base address)")); | |
5457 | return; | |
5458 | } | |
5459 | ||
6e70227d DE |
5460 | record_block_range (block, |
5461 | baseaddr + base + start, | |
801e3a5b JB |
5462 | baseaddr + base + end - 1); |
5463 | } | |
5464 | } | |
5465 | } | |
5466 | } | |
5467 | ||
c906108c SS |
5468 | /* Add an aggregate field to the field list. */ |
5469 | ||
5470 | static void | |
107d2387 | 5471 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 5472 | struct dwarf2_cu *cu) |
6e70227d | 5473 | { |
e7c27a73 | 5474 | struct objfile *objfile = cu->objfile; |
5e2b427d | 5475 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5476 | struct nextfield *new_field; |
5477 | struct attribute *attr; | |
5478 | struct field *fp; | |
5479 | char *fieldname = ""; | |
5480 | ||
5481 | /* Allocate a new field list entry and link it in. */ | |
5482 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 5483 | make_cleanup (xfree, new_field); |
c906108c | 5484 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
5485 | |
5486 | if (die->tag == DW_TAG_inheritance) | |
5487 | { | |
5488 | new_field->next = fip->baseclasses; | |
5489 | fip->baseclasses = new_field; | |
5490 | } | |
5491 | else | |
5492 | { | |
5493 | new_field->next = fip->fields; | |
5494 | fip->fields = new_field; | |
5495 | } | |
c906108c SS |
5496 | fip->nfields++; |
5497 | ||
5498 | /* Handle accessibility and virtuality of field. | |
5499 | The default accessibility for members is public, the default | |
5500 | accessibility for inheritance is private. */ | |
5501 | if (die->tag != DW_TAG_inheritance) | |
5502 | new_field->accessibility = DW_ACCESS_public; | |
5503 | else | |
5504 | new_field->accessibility = DW_ACCESS_private; | |
5505 | new_field->virtuality = DW_VIRTUALITY_none; | |
5506 | ||
e142c38c | 5507 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
5508 | if (attr) |
5509 | new_field->accessibility = DW_UNSND (attr); | |
5510 | if (new_field->accessibility != DW_ACCESS_public) | |
5511 | fip->non_public_fields = 1; | |
e142c38c | 5512 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
5513 | if (attr) |
5514 | new_field->virtuality = DW_UNSND (attr); | |
5515 | ||
5516 | fp = &new_field->field; | |
a9a9bd0f | 5517 | |
e142c38c | 5518 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 5519 | { |
a9a9bd0f | 5520 | /* Data member other than a C++ static data member. */ |
6e70227d | 5521 | |
c906108c | 5522 | /* Get type of field. */ |
e7c27a73 | 5523 | fp->type = die_type (die, cu); |
c906108c | 5524 | |
d6a843b5 | 5525 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 5526 | |
c906108c | 5527 | /* Get bit size of field (zero if none). */ |
e142c38c | 5528 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
5529 | if (attr) |
5530 | { | |
5531 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
5532 | } | |
5533 | else | |
5534 | { | |
5535 | FIELD_BITSIZE (*fp) = 0; | |
5536 | } | |
5537 | ||
5538 | /* Get bit offset of field. */ | |
e142c38c | 5539 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
5540 | if (attr) |
5541 | { | |
d4b96c9a | 5542 | int byte_offset = 0; |
c6a0999f | 5543 | |
3690dd37 | 5544 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 5545 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 5546 | else if (attr_form_is_constant (attr)) |
c6a0999f | 5547 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 5548 | else if (attr_form_is_block (attr)) |
c6a0999f | 5549 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
5550 | else |
5551 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 5552 | |
d6a843b5 | 5553 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 5554 | } |
e142c38c | 5555 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
5556 | if (attr) |
5557 | { | |
5e2b427d | 5558 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
5559 | { |
5560 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
5561 | additional bit offset from the MSB of the containing |
5562 | anonymous object to the MSB of the field. We don't | |
5563 | have to do anything special since we don't need to | |
5564 | know the size of the anonymous object. */ | |
c906108c SS |
5565 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
5566 | } | |
5567 | else | |
5568 | { | |
5569 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
5570 | MSB of the anonymous object, subtract off the number of |
5571 | bits from the MSB of the field to the MSB of the | |
5572 | object, and then subtract off the number of bits of | |
5573 | the field itself. The result is the bit offset of | |
5574 | the LSB of the field. */ | |
c906108c SS |
5575 | int anonymous_size; |
5576 | int bit_offset = DW_UNSND (attr); | |
5577 | ||
e142c38c | 5578 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5579 | if (attr) |
5580 | { | |
5581 | /* The size of the anonymous object containing | |
5582 | the bit field is explicit, so use the | |
5583 | indicated size (in bytes). */ | |
5584 | anonymous_size = DW_UNSND (attr); | |
5585 | } | |
5586 | else | |
5587 | { | |
5588 | /* The size of the anonymous object containing | |
5589 | the bit field must be inferred from the type | |
5590 | attribute of the data member containing the | |
5591 | bit field. */ | |
5592 | anonymous_size = TYPE_LENGTH (fp->type); | |
5593 | } | |
5594 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
5595 | - bit_offset - FIELD_BITSIZE (*fp); | |
5596 | } | |
5597 | } | |
5598 | ||
5599 | /* Get name of field. */ | |
39cbfefa DJ |
5600 | fieldname = dwarf2_name (die, cu); |
5601 | if (fieldname == NULL) | |
5602 | fieldname = ""; | |
d8151005 DJ |
5603 | |
5604 | /* The name is already allocated along with this objfile, so we don't | |
5605 | need to duplicate it for the type. */ | |
5606 | fp->name = fieldname; | |
c906108c SS |
5607 | |
5608 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 5609 | pointer or virtual base class pointer) to private. */ |
e142c38c | 5610 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 5611 | { |
d48cc9dd | 5612 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
5613 | new_field->accessibility = DW_ACCESS_private; |
5614 | fip->non_public_fields = 1; | |
5615 | } | |
5616 | } | |
a9a9bd0f | 5617 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 5618 | { |
a9a9bd0f DC |
5619 | /* C++ static member. */ |
5620 | ||
5621 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
5622 | is a declaration, but all versions of G++ as of this writing | |
5623 | (so through at least 3.2.1) incorrectly generate | |
5624 | DW_TAG_variable tags. */ | |
6e70227d | 5625 | |
c906108c | 5626 | char *physname; |
c906108c | 5627 | |
a9a9bd0f | 5628 | /* Get name of field. */ |
39cbfefa DJ |
5629 | fieldname = dwarf2_name (die, cu); |
5630 | if (fieldname == NULL) | |
c906108c SS |
5631 | return; |
5632 | ||
254e6b9e | 5633 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
5634 | if (attr |
5635 | /* Only create a symbol if this is an external value. | |
5636 | new_symbol checks this and puts the value in the global symbol | |
5637 | table, which we want. If it is not external, new_symbol | |
5638 | will try to put the value in cu->list_in_scope which is wrong. */ | |
5639 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
5640 | { |
5641 | /* A static const member, not much different than an enum as far as | |
5642 | we're concerned, except that we can support more types. */ | |
5643 | new_symbol (die, NULL, cu); | |
5644 | } | |
5645 | ||
2df3850c | 5646 | /* Get physical name. */ |
94af9270 | 5647 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 5648 | |
d8151005 DJ |
5649 | /* The name is already allocated along with this objfile, so we don't |
5650 | need to duplicate it for the type. */ | |
5651 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 5652 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 5653 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
5654 | } |
5655 | else if (die->tag == DW_TAG_inheritance) | |
5656 | { | |
5657 | /* C++ base class field. */ | |
e142c38c | 5658 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 5659 | if (attr) |
d4b96c9a JK |
5660 | { |
5661 | int byte_offset = 0; | |
5662 | ||
5663 | if (attr_form_is_section_offset (attr)) | |
5664 | dwarf2_complex_location_expr_complaint (); | |
5665 | else if (attr_form_is_constant (attr)) | |
5666 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
5667 | else if (attr_form_is_block (attr)) | |
5668 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
5669 | else | |
5670 | dwarf2_complex_location_expr_complaint (); | |
5671 | ||
5672 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
5673 | } | |
c906108c | 5674 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 5675 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
5676 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
5677 | fip->nbaseclasses++; | |
5678 | } | |
5679 | } | |
5680 | ||
98751a41 JK |
5681 | /* Add a typedef defined in the scope of the FIP's class. */ |
5682 | ||
5683 | static void | |
5684 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
5685 | struct dwarf2_cu *cu) | |
6e70227d | 5686 | { |
98751a41 JK |
5687 | struct objfile *objfile = cu->objfile; |
5688 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
5689 | struct typedef_field_list *new_field; | |
5690 | struct attribute *attr; | |
5691 | struct typedef_field *fp; | |
5692 | char *fieldname = ""; | |
5693 | ||
5694 | /* Allocate a new field list entry and link it in. */ | |
5695 | new_field = xzalloc (sizeof (*new_field)); | |
5696 | make_cleanup (xfree, new_field); | |
5697 | ||
5698 | gdb_assert (die->tag == DW_TAG_typedef); | |
5699 | ||
5700 | fp = &new_field->field; | |
5701 | ||
5702 | /* Get name of field. */ | |
5703 | fp->name = dwarf2_name (die, cu); | |
5704 | if (fp->name == NULL) | |
5705 | return; | |
5706 | ||
5707 | fp->type = read_type_die (die, cu); | |
5708 | ||
5709 | new_field->next = fip->typedef_field_list; | |
5710 | fip->typedef_field_list = new_field; | |
5711 | fip->typedef_field_list_count++; | |
5712 | } | |
5713 | ||
c906108c SS |
5714 | /* Create the vector of fields, and attach it to the type. */ |
5715 | ||
5716 | static void | |
fba45db2 | 5717 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 5718 | struct dwarf2_cu *cu) |
c906108c SS |
5719 | { |
5720 | int nfields = fip->nfields; | |
5721 | ||
5722 | /* Record the field count, allocate space for the array of fields, | |
5723 | and create blank accessibility bitfields if necessary. */ | |
5724 | TYPE_NFIELDS (type) = nfields; | |
5725 | TYPE_FIELDS (type) = (struct field *) | |
5726 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
5727 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
5728 | ||
b4ba55a1 | 5729 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
5730 | { |
5731 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
5732 | ||
5733 | TYPE_FIELD_PRIVATE_BITS (type) = | |
5734 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5735 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
5736 | ||
5737 | TYPE_FIELD_PROTECTED_BITS (type) = | |
5738 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5739 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
5740 | ||
5741 | TYPE_FIELD_IGNORE_BITS (type) = | |
5742 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
5743 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
5744 | } | |
5745 | ||
5746 | /* If the type has baseclasses, allocate and clear a bit vector for | |
5747 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 5748 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
5749 | { |
5750 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 5751 | unsigned char *pointer; |
c906108c SS |
5752 | |
5753 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
5754 | pointer = TYPE_ALLOC (type, num_bytes); |
5755 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
5756 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
5757 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
5758 | } | |
5759 | ||
5760 | /* Copy the saved-up fields into the field vector. Start from the head | |
5761 | of the list, adding to the tail of the field array, so that they end | |
5762 | up in the same order in the array in which they were added to the list. */ | |
5763 | while (nfields-- > 0) | |
5764 | { | |
7d0ccb61 DJ |
5765 | struct nextfield *fieldp; |
5766 | ||
5767 | if (fip->fields) | |
5768 | { | |
5769 | fieldp = fip->fields; | |
5770 | fip->fields = fieldp->next; | |
5771 | } | |
5772 | else | |
5773 | { | |
5774 | fieldp = fip->baseclasses; | |
5775 | fip->baseclasses = fieldp->next; | |
5776 | } | |
5777 | ||
5778 | TYPE_FIELD (type, nfields) = fieldp->field; | |
5779 | switch (fieldp->accessibility) | |
c906108c | 5780 | { |
c5aa993b | 5781 | case DW_ACCESS_private: |
b4ba55a1 JB |
5782 | if (cu->language != language_ada) |
5783 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 5784 | break; |
c906108c | 5785 | |
c5aa993b | 5786 | case DW_ACCESS_protected: |
b4ba55a1 JB |
5787 | if (cu->language != language_ada) |
5788 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 5789 | break; |
c906108c | 5790 | |
c5aa993b JM |
5791 | case DW_ACCESS_public: |
5792 | break; | |
c906108c | 5793 | |
c5aa993b JM |
5794 | default: |
5795 | /* Unknown accessibility. Complain and treat it as public. */ | |
5796 | { | |
e2e0b3e5 | 5797 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 5798 | fieldp->accessibility); |
c5aa993b JM |
5799 | } |
5800 | break; | |
c906108c SS |
5801 | } |
5802 | if (nfields < fip->nbaseclasses) | |
5803 | { | |
7d0ccb61 | 5804 | switch (fieldp->virtuality) |
c906108c | 5805 | { |
c5aa993b JM |
5806 | case DW_VIRTUALITY_virtual: |
5807 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
5808 | if (cu->language == language_ada) |
5809 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
5810 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
5811 | break; | |
c906108c SS |
5812 | } |
5813 | } | |
c906108c SS |
5814 | } |
5815 | } | |
5816 | ||
c906108c SS |
5817 | /* Add a member function to the proper fieldlist. */ |
5818 | ||
5819 | static void | |
107d2387 | 5820 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 5821 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 5822 | { |
e7c27a73 | 5823 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5824 | struct attribute *attr; |
5825 | struct fnfieldlist *flp; | |
5826 | int i; | |
5827 | struct fn_field *fnp; | |
5828 | char *fieldname; | |
5829 | char *physname; | |
5830 | struct nextfnfield *new_fnfield; | |
f792889a | 5831 | struct type *this_type; |
c906108c | 5832 | |
b4ba55a1 JB |
5833 | if (cu->language == language_ada) |
5834 | error ("unexpected member function in Ada type"); | |
5835 | ||
2df3850c | 5836 | /* Get name of member function. */ |
39cbfefa DJ |
5837 | fieldname = dwarf2_name (die, cu); |
5838 | if (fieldname == NULL) | |
2df3850c | 5839 | return; |
c906108c | 5840 | |
2df3850c | 5841 | /* Get the mangled name. */ |
94af9270 | 5842 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c SS |
5843 | |
5844 | /* Look up member function name in fieldlist. */ | |
5845 | for (i = 0; i < fip->nfnfields; i++) | |
5846 | { | |
27bfe10e | 5847 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
5848 | break; |
5849 | } | |
5850 | ||
5851 | /* Create new list element if necessary. */ | |
5852 | if (i < fip->nfnfields) | |
5853 | flp = &fip->fnfieldlists[i]; | |
5854 | else | |
5855 | { | |
5856 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
5857 | { | |
5858 | fip->fnfieldlists = (struct fnfieldlist *) | |
5859 | xrealloc (fip->fnfieldlists, | |
5860 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 5861 | * sizeof (struct fnfieldlist)); |
c906108c | 5862 | if (fip->nfnfields == 0) |
c13c43fd | 5863 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
5864 | } |
5865 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
5866 | flp->name = fieldname; | |
5867 | flp->length = 0; | |
5868 | flp->head = NULL; | |
5869 | fip->nfnfields++; | |
5870 | } | |
5871 | ||
5872 | /* Create a new member function field and chain it to the field list | |
5873 | entry. */ | |
5874 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 5875 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
5876 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
5877 | new_fnfield->next = flp->head; | |
5878 | flp->head = new_fnfield; | |
5879 | flp->length++; | |
5880 | ||
5881 | /* Fill in the member function field info. */ | |
5882 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
5883 | /* The name is already allocated along with this objfile, so we don't |
5884 | need to duplicate it for the type. */ | |
5885 | fnp->physname = physname ? physname : ""; | |
c906108c | 5886 | fnp->type = alloc_type (objfile); |
f792889a DJ |
5887 | this_type = read_type_die (die, cu); |
5888 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 5889 | { |
f792889a | 5890 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 5891 | |
f792889a | 5892 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
5893 | of the method itself (TYPE_CODE_METHOD). */ |
5894 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
5895 | TYPE_TARGET_TYPE (this_type), |
5896 | TYPE_FIELDS (this_type), | |
5897 | TYPE_NFIELDS (this_type), | |
5898 | TYPE_VARARGS (this_type)); | |
c906108c SS |
5899 | |
5900 | /* Handle static member functions. | |
c5aa993b JM |
5901 | Dwarf2 has no clean way to discern C++ static and non-static |
5902 | member functions. G++ helps GDB by marking the first | |
5903 | parameter for non-static member functions (which is the | |
5904 | this pointer) as artificial. We obtain this information | |
5905 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 5906 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
5907 | fnp->voffset = VOFFSET_STATIC; |
5908 | } | |
5909 | else | |
e2e0b3e5 | 5910 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 5911 | physname); |
c906108c SS |
5912 | |
5913 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 5914 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 5915 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
5916 | |
5917 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
5918 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
5919 | ||
5920 | /* Get accessibility. */ | |
e142c38c | 5921 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
5922 | if (attr) |
5923 | { | |
5924 | switch (DW_UNSND (attr)) | |
5925 | { | |
c5aa993b JM |
5926 | case DW_ACCESS_private: |
5927 | fnp->is_private = 1; | |
5928 | break; | |
5929 | case DW_ACCESS_protected: | |
5930 | fnp->is_protected = 1; | |
5931 | break; | |
c906108c SS |
5932 | } |
5933 | } | |
5934 | ||
b02dede2 | 5935 | /* Check for artificial methods. */ |
e142c38c | 5936 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
5937 | if (attr && DW_UNSND (attr) != 0) |
5938 | fnp->is_artificial = 1; | |
5939 | ||
0d564a31 | 5940 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
5941 | function. For older versions of GCC, this is an offset in the |
5942 | appropriate virtual table, as specified by DW_AT_containing_type. | |
5943 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
5944 | to the object address. */ |
5945 | ||
e142c38c | 5946 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 5947 | if (attr) |
8e19ed76 | 5948 | { |
aec5aa8b | 5949 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 5950 | { |
aec5aa8b TT |
5951 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
5952 | { | |
5953 | /* Old-style GCC. */ | |
5954 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
5955 | } | |
5956 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
5957 | || (DW_BLOCK (attr)->size > 1 | |
5958 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
5959 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
5960 | { | |
5961 | struct dwarf_block blk; | |
5962 | int offset; | |
5963 | ||
5964 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
5965 | ? 1 : 2); | |
5966 | blk.size = DW_BLOCK (attr)->size - offset; | |
5967 | blk.data = DW_BLOCK (attr)->data + offset; | |
5968 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
5969 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
5970 | dwarf2_complex_location_expr_complaint (); | |
5971 | else | |
5972 | fnp->voffset /= cu->header.addr_size; | |
5973 | fnp->voffset += 2; | |
5974 | } | |
5975 | else | |
5976 | dwarf2_complex_location_expr_complaint (); | |
5977 | ||
5978 | if (!fnp->fcontext) | |
5979 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
5980 | } | |
3690dd37 | 5981 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 5982 | { |
4d3c2250 | 5983 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5984 | } |
5985 | else | |
5986 | { | |
4d3c2250 KB |
5987 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
5988 | fieldname); | |
8e19ed76 | 5989 | } |
0d564a31 | 5990 | } |
d48cc9dd DJ |
5991 | else |
5992 | { | |
5993 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
5994 | if (attr && DW_UNSND (attr)) | |
5995 | { | |
5996 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
5997 | complaint (&symfile_complaints, | |
5998 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
5999 | fieldname, die->offset); | |
9655fd1a | 6000 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
6001 | TYPE_CPLUS_DYNAMIC (type) = 1; |
6002 | } | |
6003 | } | |
c906108c SS |
6004 | } |
6005 | ||
6006 | /* Create the vector of member function fields, and attach it to the type. */ | |
6007 | ||
6008 | static void | |
fba45db2 | 6009 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6010 | struct dwarf2_cu *cu) |
c906108c SS |
6011 | { |
6012 | struct fnfieldlist *flp; | |
6013 | int total_length = 0; | |
6014 | int i; | |
6015 | ||
b4ba55a1 JB |
6016 | if (cu->language == language_ada) |
6017 | error ("unexpected member functions in Ada type"); | |
6018 | ||
c906108c SS |
6019 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6020 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6021 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6022 | ||
6023 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6024 | { | |
6025 | struct nextfnfield *nfp = flp->head; | |
6026 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6027 | int k; | |
6028 | ||
6029 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6030 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6031 | fn_flp->fn_fields = (struct fn_field *) | |
6032 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6033 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6034 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6035 | |
6036 | total_length += flp->length; | |
6037 | } | |
6038 | ||
6039 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6040 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6041 | } | |
6042 | ||
1168df01 JB |
6043 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6044 | language, zero otherwise. */ | |
6045 | static int | |
6046 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6047 | { | |
6048 | static const char vptr[] = "_vptr"; | |
987504bb | 6049 | static const char vtable[] = "vtable"; |
1168df01 | 6050 | |
987504bb JJ |
6051 | /* Look for the C++ and Java forms of the vtable. */ |
6052 | if ((cu->language == language_java | |
6053 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6054 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
6055 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
6056 | return 1; |
6057 | ||
6058 | return 0; | |
6059 | } | |
6060 | ||
c0dd20ea | 6061 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
6062 | functions, with the ABI-specified layout. If TYPE describes |
6063 | such a structure, smash it into a member function type. | |
61049d3b DJ |
6064 | |
6065 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
6066 | This is GCC PR debug/28767. */ | |
c0dd20ea | 6067 | |
0b92b5bb TT |
6068 | static void |
6069 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 6070 | { |
0b92b5bb | 6071 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
6072 | |
6073 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
6074 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
6075 | return; | |
c0dd20ea DJ |
6076 | |
6077 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
6078 | if (TYPE_FIELD_NAME (type, 0) == NULL |
6079 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
6080 | || TYPE_FIELD_NAME (type, 1) == NULL | |
6081 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
6082 | return; | |
c0dd20ea DJ |
6083 | |
6084 | /* Find the type of the method. */ | |
0b92b5bb | 6085 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
6086 | if (pfn_type == NULL |
6087 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
6088 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 6089 | return; |
c0dd20ea DJ |
6090 | |
6091 | /* Look for the "this" argument. */ | |
6092 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
6093 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 6094 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 6095 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 6096 | return; |
c0dd20ea DJ |
6097 | |
6098 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
6099 | new_type = alloc_type (objfile); |
6100 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
6101 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
6102 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 6103 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 6104 | } |
1168df01 | 6105 | |
c906108c SS |
6106 | /* Called when we find the DIE that starts a structure or union scope |
6107 | (definition) to process all dies that define the members of the | |
6108 | structure or union. | |
6109 | ||
6110 | NOTE: we need to call struct_type regardless of whether or not the | |
6111 | DIE has an at_name attribute, since it might be an anonymous | |
6112 | structure or union. This gets the type entered into our set of | |
6113 | user defined types. | |
6114 | ||
6115 | However, if the structure is incomplete (an opaque struct/union) | |
6116 | then suppress creating a symbol table entry for it since gdb only | |
6117 | wants to find the one with the complete definition. Note that if | |
6118 | it is complete, we just call new_symbol, which does it's own | |
6119 | checking about whether the struct/union is anonymous or not (and | |
6120 | suppresses creating a symbol table entry itself). */ | |
6121 | ||
f792889a | 6122 | static struct type * |
134d01f1 | 6123 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6124 | { |
e7c27a73 | 6125 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6126 | struct type *type; |
6127 | struct attribute *attr; | |
39cbfefa | 6128 | char *name; |
d3f41bb1 | 6129 | struct cleanup *back_to; |
c906108c | 6130 | |
348e048f DE |
6131 | /* If the definition of this type lives in .debug_types, read that type. |
6132 | Don't follow DW_AT_specification though, that will take us back up | |
6133 | the chain and we want to go down. */ | |
6134 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6135 | if (attr) | |
6136 | { | |
6137 | struct dwarf2_cu *type_cu = cu; | |
6138 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6139 | |
348e048f DE |
6140 | /* We could just recurse on read_structure_type, but we need to call |
6141 | get_die_type to ensure only one type for this DIE is created. | |
6142 | This is important, for example, because for c++ classes we need | |
6143 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
6144 | type = read_type_die (type_die, type_cu); | |
6145 | return set_die_type (die, type, cu); | |
6146 | } | |
6147 | ||
d3f41bb1 TT |
6148 | back_to = make_cleanup (null_cleanup, 0); |
6149 | ||
c0dd20ea | 6150 | type = alloc_type (objfile); |
c906108c | 6151 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 6152 | |
39cbfefa DJ |
6153 | name = dwarf2_name (die, cu); |
6154 | if (name != NULL) | |
c906108c | 6155 | { |
987504bb JJ |
6156 | if (cu->language == language_cplus |
6157 | || cu->language == language_java) | |
63d06c5c | 6158 | { |
94af9270 KS |
6159 | TYPE_TAG_NAME (type) = (char *) dwarf2_full_name (name, die, cu); |
6160 | if (die->tag == DW_TAG_structure_type | |
6161 | || die->tag == DW_TAG_class_type) | |
6162 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
6163 | } |
6164 | else | |
6165 | { | |
d8151005 DJ |
6166 | /* The name is already allocated along with this objfile, so |
6167 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
6168 | TYPE_TAG_NAME (type) = (char *) name; |
6169 | if (die->tag == DW_TAG_class_type) | |
6170 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 6171 | } |
c906108c SS |
6172 | } |
6173 | ||
6174 | if (die->tag == DW_TAG_structure_type) | |
6175 | { | |
6176 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
6177 | } | |
6178 | else if (die->tag == DW_TAG_union_type) | |
6179 | { | |
6180 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
6181 | } | |
6182 | else | |
6183 | { | |
c906108c SS |
6184 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
6185 | } | |
6186 | ||
0cc2414c TT |
6187 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
6188 | TYPE_DECLARED_CLASS (type) = 1; | |
6189 | ||
e142c38c | 6190 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6191 | if (attr) |
6192 | { | |
6193 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6194 | } | |
6195 | else | |
6196 | { | |
6197 | TYPE_LENGTH (type) = 0; | |
6198 | } | |
6199 | ||
876cecd0 | 6200 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 6201 | if (die_is_declaration (die, cu)) |
876cecd0 | 6202 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
6203 | else if (attr == NULL && die->child == NULL |
6204 | && producer_is_realview (cu->producer)) | |
6205 | /* RealView does not output the required DW_AT_declaration | |
6206 | on incomplete types. */ | |
6207 | TYPE_STUB (type) = 1; | |
dc718098 | 6208 | |
c906108c SS |
6209 | /* We need to add the type field to the die immediately so we don't |
6210 | infinitely recurse when dealing with pointers to the structure | |
6211 | type within the structure itself. */ | |
1c379e20 | 6212 | set_die_type (die, type, cu); |
c906108c | 6213 | |
7e314c57 JK |
6214 | /* set_die_type should be already done. */ |
6215 | set_descriptive_type (type, die, cu); | |
6216 | ||
e142c38c | 6217 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
6218 | { |
6219 | struct field_info fi; | |
6220 | struct die_info *child_die; | |
c906108c SS |
6221 | |
6222 | memset (&fi, 0, sizeof (struct field_info)); | |
6223 | ||
639d11d3 | 6224 | child_die = die->child; |
c906108c SS |
6225 | |
6226 | while (child_die && child_die->tag) | |
6227 | { | |
a9a9bd0f DC |
6228 | if (child_die->tag == DW_TAG_member |
6229 | || child_die->tag == DW_TAG_variable) | |
c906108c | 6230 | { |
a9a9bd0f DC |
6231 | /* NOTE: carlton/2002-11-05: A C++ static data member |
6232 | should be a DW_TAG_member that is a declaration, but | |
6233 | all versions of G++ as of this writing (so through at | |
6234 | least 3.2.1) incorrectly generate DW_TAG_variable | |
6235 | tags for them instead. */ | |
e7c27a73 | 6236 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6237 | } |
8713b1b1 | 6238 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
6239 | { |
6240 | /* C++ member function. */ | |
e7c27a73 | 6241 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
6242 | } |
6243 | else if (child_die->tag == DW_TAG_inheritance) | |
6244 | { | |
6245 | /* C++ base class field. */ | |
e7c27a73 | 6246 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6247 | } |
98751a41 JK |
6248 | else if (child_die->tag == DW_TAG_typedef) |
6249 | dwarf2_add_typedef (&fi, child_die, cu); | |
c906108c SS |
6250 | child_die = sibling_die (child_die); |
6251 | } | |
6252 | ||
6253 | /* Attach fields and member functions to the type. */ | |
6254 | if (fi.nfields) | |
e7c27a73 | 6255 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
6256 | if (fi.nfnfields) |
6257 | { | |
e7c27a73 | 6258 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 6259 | |
c5aa993b | 6260 | /* Get the type which refers to the base class (possibly this |
c906108c | 6261 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
6262 | class from the DW_AT_containing_type attribute. This use of |
6263 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 6264 | |
e142c38c | 6265 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 6266 | { |
e7c27a73 | 6267 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
6268 | |
6269 | TYPE_VPTR_BASETYPE (type) = t; | |
6270 | if (type == t) | |
6271 | { | |
c906108c SS |
6272 | int i; |
6273 | ||
6274 | /* Our own class provides vtbl ptr. */ | |
6275 | for (i = TYPE_NFIELDS (t) - 1; | |
6276 | i >= TYPE_N_BASECLASSES (t); | |
6277 | --i) | |
6278 | { | |
6279 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
6280 | ||
1168df01 | 6281 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
6282 | { |
6283 | TYPE_VPTR_FIELDNO (type) = i; | |
6284 | break; | |
6285 | } | |
6286 | } | |
6287 | ||
6288 | /* Complain if virtual function table field not found. */ | |
6289 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 6290 | complaint (&symfile_complaints, |
e2e0b3e5 | 6291 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
6292 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
6293 | ""); | |
c906108c SS |
6294 | } |
6295 | else | |
6296 | { | |
6297 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
6298 | } | |
6299 | } | |
f6235d4c EZ |
6300 | else if (cu->producer |
6301 | && strncmp (cu->producer, | |
6302 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
6303 | { | |
6304 | /* The IBM XLC compiler does not provide direct indication | |
6305 | of the containing type, but the vtable pointer is | |
6306 | always named __vfp. */ | |
6307 | ||
6308 | int i; | |
6309 | ||
6310 | for (i = TYPE_NFIELDS (type) - 1; | |
6311 | i >= TYPE_N_BASECLASSES (type); | |
6312 | --i) | |
6313 | { | |
6314 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
6315 | { | |
6316 | TYPE_VPTR_FIELDNO (type) = i; | |
6317 | TYPE_VPTR_BASETYPE (type) = type; | |
6318 | break; | |
6319 | } | |
6320 | } | |
6321 | } | |
c906108c | 6322 | } |
98751a41 JK |
6323 | |
6324 | /* Copy fi.typedef_field_list linked list elements content into the | |
6325 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
6326 | if (fi.typedef_field_list) | |
6327 | { | |
6328 | int i = fi.typedef_field_list_count; | |
6329 | ||
a0d7a4ff | 6330 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
6331 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
6332 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
6333 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
6334 | ||
6335 | /* Reverse the list order to keep the debug info elements order. */ | |
6336 | while (--i >= 0) | |
6337 | { | |
6338 | struct typedef_field *dest, *src; | |
6e70227d | 6339 | |
98751a41 JK |
6340 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
6341 | src = &fi.typedef_field_list->field; | |
6342 | fi.typedef_field_list = fi.typedef_field_list->next; | |
6343 | *dest = *src; | |
6344 | } | |
6345 | } | |
c906108c | 6346 | } |
63d06c5c | 6347 | |
0b92b5bb TT |
6348 | quirk_gcc_member_function_pointer (type, cu->objfile); |
6349 | ||
0114d602 | 6350 | do_cleanups (back_to); |
f792889a | 6351 | return type; |
c906108c SS |
6352 | } |
6353 | ||
134d01f1 DJ |
6354 | static void |
6355 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6356 | { | |
90aeadfc | 6357 | struct die_info *child_die = die->child; |
f792889a | 6358 | struct type *this_type; |
c906108c | 6359 | |
f792889a DJ |
6360 | this_type = get_die_type (die, cu); |
6361 | if (this_type == NULL) | |
6362 | this_type = read_structure_type (die, cu); | |
c906108c | 6363 | |
90aeadfc DC |
6364 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
6365 | snapshots) has been known to create a die giving a declaration | |
6366 | for a class that has, as a child, a die giving a definition for a | |
6367 | nested class. So we have to process our children even if the | |
6368 | current die is a declaration. Normally, of course, a declaration | |
6369 | won't have any children at all. */ | |
134d01f1 | 6370 | |
90aeadfc DC |
6371 | while (child_die != NULL && child_die->tag) |
6372 | { | |
6373 | if (child_die->tag == DW_TAG_member | |
6374 | || child_die->tag == DW_TAG_variable | |
6375 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 6376 | { |
90aeadfc | 6377 | /* Do nothing. */ |
134d01f1 | 6378 | } |
90aeadfc DC |
6379 | else |
6380 | process_die (child_die, cu); | |
134d01f1 | 6381 | |
90aeadfc | 6382 | child_die = sibling_die (child_die); |
134d01f1 DJ |
6383 | } |
6384 | ||
fa4028e9 JB |
6385 | /* Do not consider external references. According to the DWARF standard, |
6386 | these DIEs are identified by the fact that they have no byte_size | |
6387 | attribute, and a declaration attribute. */ | |
6388 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
6389 | || !die_is_declaration (die, cu)) | |
f792889a | 6390 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
6391 | } |
6392 | ||
6393 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
6394 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 6395 | |
f792889a | 6396 | static struct type * |
134d01f1 | 6397 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6398 | { |
e7c27a73 | 6399 | struct objfile *objfile = cu->objfile; |
c906108c | 6400 | struct type *type; |
c906108c | 6401 | struct attribute *attr; |
0114d602 | 6402 | const char *name; |
134d01f1 | 6403 | |
348e048f DE |
6404 | /* If the definition of this type lives in .debug_types, read that type. |
6405 | Don't follow DW_AT_specification though, that will take us back up | |
6406 | the chain and we want to go down. */ | |
6407 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6408 | if (attr) | |
6409 | { | |
6410 | struct dwarf2_cu *type_cu = cu; | |
6411 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6412 | |
348e048f DE |
6413 | type = read_type_die (type_die, type_cu); |
6414 | return set_die_type (die, type, cu); | |
6415 | } | |
6416 | ||
c906108c SS |
6417 | type = alloc_type (objfile); |
6418 | ||
6419 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 6420 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 6421 | if (name != NULL) |
0114d602 | 6422 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 6423 | |
e142c38c | 6424 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6425 | if (attr) |
6426 | { | |
6427 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6428 | } | |
6429 | else | |
6430 | { | |
6431 | TYPE_LENGTH (type) = 0; | |
6432 | } | |
6433 | ||
137033e9 JB |
6434 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
6435 | declared as private in the package spec, and then defined only | |
6436 | inside the package body. Such types are known as Taft Amendment | |
6437 | Types. When another package uses such a type, an incomplete DIE | |
6438 | may be generated by the compiler. */ | |
02eb380e | 6439 | if (die_is_declaration (die, cu)) |
876cecd0 | 6440 | TYPE_STUB (type) = 1; |
02eb380e | 6441 | |
f792889a | 6442 | return set_die_type (die, type, cu); |
134d01f1 DJ |
6443 | } |
6444 | ||
6445 | /* Given a pointer to a die which begins an enumeration, process all | |
6446 | the dies that define the members of the enumeration, and create the | |
6447 | symbol for the enumeration type. | |
6448 | ||
6449 | NOTE: We reverse the order of the element list. */ | |
6450 | ||
6451 | static void | |
6452 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6453 | { | |
134d01f1 DJ |
6454 | struct die_info *child_die; |
6455 | struct field *fields; | |
134d01f1 DJ |
6456 | struct symbol *sym; |
6457 | int num_fields; | |
6458 | int unsigned_enum = 1; | |
39cbfefa | 6459 | char *name; |
f792889a | 6460 | struct type *this_type; |
134d01f1 | 6461 | |
c906108c SS |
6462 | num_fields = 0; |
6463 | fields = NULL; | |
f792889a DJ |
6464 | this_type = get_die_type (die, cu); |
6465 | if (this_type == NULL) | |
6466 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 6467 | if (die->child != NULL) |
c906108c | 6468 | { |
639d11d3 | 6469 | child_die = die->child; |
c906108c SS |
6470 | while (child_die && child_die->tag) |
6471 | { | |
6472 | if (child_die->tag != DW_TAG_enumerator) | |
6473 | { | |
e7c27a73 | 6474 | process_die (child_die, cu); |
c906108c SS |
6475 | } |
6476 | else | |
6477 | { | |
39cbfefa DJ |
6478 | name = dwarf2_name (child_die, cu); |
6479 | if (name) | |
c906108c | 6480 | { |
f792889a | 6481 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
6482 | if (SYMBOL_VALUE (sym) < 0) |
6483 | unsigned_enum = 0; | |
6484 | ||
6485 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6486 | { | |
6487 | fields = (struct field *) | |
6488 | xrealloc (fields, | |
6489 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6490 | * sizeof (struct field)); |
c906108c SS |
6491 | } |
6492 | ||
3567439c | 6493 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 6494 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 6495 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
6496 | FIELD_BITSIZE (fields[num_fields]) = 0; |
6497 | ||
6498 | num_fields++; | |
6499 | } | |
6500 | } | |
6501 | ||
6502 | child_die = sibling_die (child_die); | |
6503 | } | |
6504 | ||
6505 | if (num_fields) | |
6506 | { | |
f792889a DJ |
6507 | TYPE_NFIELDS (this_type) = num_fields; |
6508 | TYPE_FIELDS (this_type) = (struct field *) | |
6509 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
6510 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 6511 | sizeof (struct field) * num_fields); |
b8c9b27d | 6512 | xfree (fields); |
c906108c SS |
6513 | } |
6514 | if (unsigned_enum) | |
876cecd0 | 6515 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 6516 | } |
134d01f1 | 6517 | |
f792889a | 6518 | new_symbol (die, this_type, cu); |
c906108c SS |
6519 | } |
6520 | ||
6521 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
6522 | the DIE's type field. For now, this only handles one dimensional | |
6523 | arrays. */ | |
6524 | ||
f792889a | 6525 | static struct type * |
e7c27a73 | 6526 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6527 | { |
e7c27a73 | 6528 | struct objfile *objfile = cu->objfile; |
c906108c | 6529 | struct die_info *child_die; |
7e314c57 | 6530 | struct type *type; |
c906108c SS |
6531 | struct type *element_type, *range_type, *index_type; |
6532 | struct type **range_types = NULL; | |
6533 | struct attribute *attr; | |
6534 | int ndim = 0; | |
6535 | struct cleanup *back_to; | |
39cbfefa | 6536 | char *name; |
c906108c | 6537 | |
e7c27a73 | 6538 | element_type = die_type (die, cu); |
c906108c | 6539 | |
7e314c57 JK |
6540 | /* The die_type call above may have already set the type for this DIE. */ |
6541 | type = get_die_type (die, cu); | |
6542 | if (type) | |
6543 | return type; | |
6544 | ||
c906108c SS |
6545 | /* Irix 6.2 native cc creates array types without children for |
6546 | arrays with unspecified length. */ | |
639d11d3 | 6547 | if (die->child == NULL) |
c906108c | 6548 | { |
46bf5051 | 6549 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 6550 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
6551 | type = create_array_type (NULL, element_type, range_type); |
6552 | return set_die_type (die, type, cu); | |
c906108c SS |
6553 | } |
6554 | ||
6555 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 6556 | child_die = die->child; |
c906108c SS |
6557 | while (child_die && child_die->tag) |
6558 | { | |
6559 | if (child_die->tag == DW_TAG_subrange_type) | |
6560 | { | |
f792889a | 6561 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 6562 | |
f792889a | 6563 | if (child_type != NULL) |
a02abb62 JB |
6564 | { |
6565 | /* The range type was succesfully read. Save it for | |
6566 | the array type creation. */ | |
6567 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
6568 | { | |
6569 | range_types = (struct type **) | |
6570 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
6571 | * sizeof (struct type *)); | |
6572 | if (ndim == 0) | |
6573 | make_cleanup (free_current_contents, &range_types); | |
6574 | } | |
f792889a | 6575 | range_types[ndim++] = child_type; |
a02abb62 | 6576 | } |
c906108c SS |
6577 | } |
6578 | child_die = sibling_die (child_die); | |
6579 | } | |
6580 | ||
6581 | /* Dwarf2 dimensions are output from left to right, create the | |
6582 | necessary array types in backwards order. */ | |
7ca2d3a3 | 6583 | |
c906108c | 6584 | type = element_type; |
7ca2d3a3 DL |
6585 | |
6586 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
6587 | { | |
6588 | int i = 0; | |
9a619af0 | 6589 | |
7ca2d3a3 DL |
6590 | while (i < ndim) |
6591 | type = create_array_type (NULL, type, range_types[i++]); | |
6592 | } | |
6593 | else | |
6594 | { | |
6595 | while (ndim-- > 0) | |
6596 | type = create_array_type (NULL, type, range_types[ndim]); | |
6597 | } | |
c906108c | 6598 | |
f5f8a009 EZ |
6599 | /* Understand Dwarf2 support for vector types (like they occur on |
6600 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
6601 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
6602 | custom vendor extension. The main difference between a regular | |
6603 | array and the vector variant is that vectors are passed by value | |
6604 | to functions. */ | |
e142c38c | 6605 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 6606 | if (attr) |
ea37ba09 | 6607 | make_vector_type (type); |
f5f8a009 | 6608 | |
39cbfefa DJ |
6609 | name = dwarf2_name (die, cu); |
6610 | if (name) | |
6611 | TYPE_NAME (type) = name; | |
6e70227d | 6612 | |
7e314c57 JK |
6613 | /* Install the type in the die. */ |
6614 | set_die_type (die, type, cu); | |
6615 | ||
6616 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
6617 | set_descriptive_type (type, die, cu); |
6618 | ||
c906108c SS |
6619 | do_cleanups (back_to); |
6620 | ||
7e314c57 | 6621 | return type; |
c906108c SS |
6622 | } |
6623 | ||
7ca2d3a3 | 6624 | static enum dwarf_array_dim_ordering |
6e70227d | 6625 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
6626 | { |
6627 | struct attribute *attr; | |
6628 | ||
6629 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
6630 | ||
6631 | if (attr) return DW_SND (attr); | |
6632 | ||
6633 | /* | |
6634 | GNU F77 is a special case, as at 08/2004 array type info is the | |
6e70227d | 6635 | opposite order to the dwarf2 specification, but data is still |
7ca2d3a3 DL |
6636 | laid out as per normal fortran. |
6637 | ||
6e70227d | 6638 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7ca2d3a3 DL |
6639 | version checking. |
6640 | */ | |
6641 | ||
905e0470 PM |
6642 | if (cu->language == language_fortran |
6643 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
6644 | { |
6645 | return DW_ORD_row_major; | |
6646 | } | |
6647 | ||
6e70227d | 6648 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
6649 | { |
6650 | case array_column_major: | |
6651 | return DW_ORD_col_major; | |
6652 | case array_row_major: | |
6653 | default: | |
6654 | return DW_ORD_row_major; | |
6655 | }; | |
6656 | } | |
6657 | ||
72019c9c GM |
6658 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
6659 | the DIE's type field. */ | |
6660 | ||
f792889a | 6661 | static struct type * |
72019c9c GM |
6662 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
6663 | { | |
7e314c57 JK |
6664 | struct type *domain_type, *set_type; |
6665 | struct attribute *attr; | |
f792889a | 6666 | |
7e314c57 JK |
6667 | domain_type = die_type (die, cu); |
6668 | ||
6669 | /* The die_type call above may have already set the type for this DIE. */ | |
6670 | set_type = get_die_type (die, cu); | |
6671 | if (set_type) | |
6672 | return set_type; | |
6673 | ||
6674 | set_type = create_set_type (NULL, domain_type); | |
6675 | ||
6676 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
6677 | if (attr) |
6678 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 6679 | |
f792889a | 6680 | return set_die_type (die, set_type, cu); |
72019c9c | 6681 | } |
7ca2d3a3 | 6682 | |
c906108c SS |
6683 | /* First cut: install each common block member as a global variable. */ |
6684 | ||
6685 | static void | |
e7c27a73 | 6686 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6687 | { |
6688 | struct die_info *child_die; | |
6689 | struct attribute *attr; | |
6690 | struct symbol *sym; | |
6691 | CORE_ADDR base = (CORE_ADDR) 0; | |
6692 | ||
e142c38c | 6693 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6694 | if (attr) |
6695 | { | |
8e19ed76 PS |
6696 | /* Support the .debug_loc offsets */ |
6697 | if (attr_form_is_block (attr)) | |
6698 | { | |
e7c27a73 | 6699 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 6700 | } |
3690dd37 | 6701 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6702 | { |
4d3c2250 | 6703 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6704 | } |
6705 | else | |
6706 | { | |
4d3c2250 KB |
6707 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6708 | "common block member"); | |
8e19ed76 | 6709 | } |
c906108c | 6710 | } |
639d11d3 | 6711 | if (die->child != NULL) |
c906108c | 6712 | { |
639d11d3 | 6713 | child_die = die->child; |
c906108c SS |
6714 | while (child_die && child_die->tag) |
6715 | { | |
e7c27a73 | 6716 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 6717 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
6718 | if (attr) |
6719 | { | |
d4b96c9a JK |
6720 | CORE_ADDR byte_offset = 0; |
6721 | ||
6722 | if (attr_form_is_section_offset (attr)) | |
6723 | dwarf2_complex_location_expr_complaint (); | |
6724 | else if (attr_form_is_constant (attr)) | |
6725 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
6726 | else if (attr_form_is_block (attr)) | |
6727 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6728 | else | |
6729 | dwarf2_complex_location_expr_complaint (); | |
6730 | ||
6731 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
6732 | add_symbol_to_list (sym, &global_symbols); |
6733 | } | |
6734 | child_die = sibling_die (child_die); | |
6735 | } | |
6736 | } | |
6737 | } | |
6738 | ||
0114d602 | 6739 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 6740 | |
0114d602 DJ |
6741 | static struct type * |
6742 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 6743 | { |
e7c27a73 | 6744 | struct objfile *objfile = cu->objfile; |
0114d602 | 6745 | const char *previous_prefix, *name; |
9219021c | 6746 | int is_anonymous; |
0114d602 DJ |
6747 | struct type *type; |
6748 | ||
6749 | /* For extensions, reuse the type of the original namespace. */ | |
6750 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
6751 | { | |
6752 | struct die_info *ext_die; | |
6753 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 6754 | |
0114d602 DJ |
6755 | ext_die = dwarf2_extension (die, &ext_cu); |
6756 | type = read_type_die (ext_die, ext_cu); | |
6757 | return set_die_type (die, type, cu); | |
6758 | } | |
9219021c | 6759 | |
e142c38c | 6760 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
6761 | |
6762 | /* Now build the name of the current namespace. */ | |
6763 | ||
0114d602 DJ |
6764 | previous_prefix = determine_prefix (die, cu); |
6765 | if (previous_prefix[0] != '\0') | |
6766 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 6767 | previous_prefix, name, 0, cu); |
0114d602 DJ |
6768 | |
6769 | /* Create the type. */ | |
6770 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
6771 | objfile); | |
6772 | TYPE_NAME (type) = (char *) name; | |
6773 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
6774 | ||
60531b24 | 6775 | return set_die_type (die, type, cu); |
0114d602 DJ |
6776 | } |
6777 | ||
6778 | /* Read a C++ namespace. */ | |
6779 | ||
6780 | static void | |
6781 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
6782 | { | |
6783 | struct objfile *objfile = cu->objfile; | |
6784 | const char *name; | |
6785 | int is_anonymous; | |
9219021c | 6786 | |
5c4e30ca DC |
6787 | /* Add a symbol associated to this if we haven't seen the namespace |
6788 | before. Also, add a using directive if it's an anonymous | |
6789 | namespace. */ | |
9219021c | 6790 | |
f2f0e013 | 6791 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
6792 | { |
6793 | struct type *type; | |
6794 | ||
0114d602 | 6795 | type = read_type_die (die, cu); |
e7c27a73 | 6796 | new_symbol (die, type, cu); |
5c4e30ca | 6797 | |
0114d602 | 6798 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 6799 | if (is_anonymous) |
0114d602 DJ |
6800 | { |
6801 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 6802 | |
c0cc3a76 | 6803 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 6804 | NULL, &objfile->objfile_obstack); |
0114d602 | 6805 | } |
5c4e30ca | 6806 | } |
9219021c | 6807 | |
639d11d3 | 6808 | if (die->child != NULL) |
d9fa45fe | 6809 | { |
639d11d3 | 6810 | struct die_info *child_die = die->child; |
6e70227d | 6811 | |
d9fa45fe DC |
6812 | while (child_die && child_die->tag) |
6813 | { | |
e7c27a73 | 6814 | process_die (child_die, cu); |
d9fa45fe DC |
6815 | child_die = sibling_die (child_die); |
6816 | } | |
6817 | } | |
38d518c9 EZ |
6818 | } |
6819 | ||
f55ee35c JK |
6820 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
6821 | imported module. Still we need that type as local Fortran "use ... only" | |
6822 | declaration imports depend on the created type in determine_prefix. */ | |
6823 | ||
6824 | static struct type * | |
6825 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
6826 | { | |
6827 | struct objfile *objfile = cu->objfile; | |
6828 | char *module_name; | |
6829 | struct type *type; | |
6830 | ||
6831 | module_name = dwarf2_name (die, cu); | |
6832 | if (!module_name) | |
6833 | complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"), | |
6834 | die->offset); | |
6835 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
6836 | ||
6837 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
6838 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
6839 | ||
6840 | return set_die_type (die, type, cu); | |
6841 | } | |
6842 | ||
5d7cb8df JK |
6843 | /* Read a Fortran module. */ |
6844 | ||
6845 | static void | |
6846 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
6847 | { | |
6848 | struct die_info *child_die = die->child; | |
6849 | ||
5d7cb8df JK |
6850 | while (child_die && child_die->tag) |
6851 | { | |
6852 | process_die (child_die, cu); | |
6853 | child_die = sibling_die (child_die); | |
6854 | } | |
6855 | } | |
6856 | ||
38d518c9 EZ |
6857 | /* Return the name of the namespace represented by DIE. Set |
6858 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
6859 | namespace. */ | |
6860 | ||
6861 | static const char * | |
e142c38c | 6862 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
6863 | { |
6864 | struct die_info *current_die; | |
6865 | const char *name = NULL; | |
6866 | ||
6867 | /* Loop through the extensions until we find a name. */ | |
6868 | ||
6869 | for (current_die = die; | |
6870 | current_die != NULL; | |
f2f0e013 | 6871 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 6872 | { |
e142c38c | 6873 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
6874 | if (name != NULL) |
6875 | break; | |
6876 | } | |
6877 | ||
6878 | /* Is it an anonymous namespace? */ | |
6879 | ||
6880 | *is_anonymous = (name == NULL); | |
6881 | if (*is_anonymous) | |
6882 | name = "(anonymous namespace)"; | |
6883 | ||
6884 | return name; | |
d9fa45fe DC |
6885 | } |
6886 | ||
c906108c SS |
6887 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
6888 | the user defined type vector. */ | |
6889 | ||
f792889a | 6890 | static struct type * |
e7c27a73 | 6891 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6892 | { |
5e2b427d | 6893 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 6894 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 6895 | struct type *type; |
8b2dbe47 KB |
6896 | struct attribute *attr_byte_size; |
6897 | struct attribute *attr_address_class; | |
6898 | int byte_size, addr_class; | |
7e314c57 JK |
6899 | struct type *target_type; |
6900 | ||
6901 | target_type = die_type (die, cu); | |
c906108c | 6902 | |
7e314c57 JK |
6903 | /* The die_type call above may have already set the type for this DIE. */ |
6904 | type = get_die_type (die, cu); | |
6905 | if (type) | |
6906 | return type; | |
6907 | ||
6908 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 6909 | |
e142c38c | 6910 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
6911 | if (attr_byte_size) |
6912 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 6913 | else |
8b2dbe47 KB |
6914 | byte_size = cu_header->addr_size; |
6915 | ||
e142c38c | 6916 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
6917 | if (attr_address_class) |
6918 | addr_class = DW_UNSND (attr_address_class); | |
6919 | else | |
6920 | addr_class = DW_ADDR_none; | |
6921 | ||
6922 | /* If the pointer size or address class is different than the | |
6923 | default, create a type variant marked as such and set the | |
6924 | length accordingly. */ | |
6925 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 6926 | { |
5e2b427d | 6927 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
6928 | { |
6929 | int type_flags; | |
6930 | ||
849957d9 | 6931 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 6932 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
6933 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
6934 | == 0); | |
8b2dbe47 KB |
6935 | type = make_type_with_address_space (type, type_flags); |
6936 | } | |
6937 | else if (TYPE_LENGTH (type) != byte_size) | |
6938 | { | |
e2e0b3e5 | 6939 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 | 6940 | } |
6e70227d | 6941 | else |
9a619af0 MS |
6942 | { |
6943 | /* Should we also complain about unhandled address classes? */ | |
6944 | } | |
c906108c | 6945 | } |
8b2dbe47 KB |
6946 | |
6947 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 6948 | return set_die_type (die, type, cu); |
c906108c SS |
6949 | } |
6950 | ||
6951 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
6952 | the user defined type vector. */ | |
6953 | ||
f792889a | 6954 | static struct type * |
e7c27a73 | 6955 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6956 | { |
6957 | struct type *type; | |
6958 | struct type *to_type; | |
6959 | struct type *domain; | |
6960 | ||
e7c27a73 DJ |
6961 | to_type = die_type (die, cu); |
6962 | domain = die_containing_type (die, cu); | |
0d5de010 | 6963 | |
7e314c57 JK |
6964 | /* The calls above may have already set the type for this DIE. */ |
6965 | type = get_die_type (die, cu); | |
6966 | if (type) | |
6967 | return type; | |
6968 | ||
0d5de010 DJ |
6969 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
6970 | type = lookup_methodptr_type (to_type); | |
6971 | else | |
6972 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 6973 | |
f792889a | 6974 | return set_die_type (die, type, cu); |
c906108c SS |
6975 | } |
6976 | ||
6977 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
6978 | the user defined type vector. */ | |
6979 | ||
f792889a | 6980 | static struct type * |
e7c27a73 | 6981 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6982 | { |
e7c27a73 | 6983 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 6984 | struct type *type, *target_type; |
c906108c SS |
6985 | struct attribute *attr; |
6986 | ||
7e314c57 JK |
6987 | target_type = die_type (die, cu); |
6988 | ||
6989 | /* The die_type call above may have already set the type for this DIE. */ | |
6990 | type = get_die_type (die, cu); | |
6991 | if (type) | |
6992 | return type; | |
6993 | ||
6994 | type = lookup_reference_type (target_type); | |
e142c38c | 6995 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6996 | if (attr) |
6997 | { | |
6998 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6999 | } | |
7000 | else | |
7001 | { | |
107d2387 | 7002 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 7003 | } |
f792889a | 7004 | return set_die_type (die, type, cu); |
c906108c SS |
7005 | } |
7006 | ||
f792889a | 7007 | static struct type * |
e7c27a73 | 7008 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7009 | { |
f792889a | 7010 | struct type *base_type, *cv_type; |
c906108c | 7011 | |
e7c27a73 | 7012 | base_type = die_type (die, cu); |
7e314c57 JK |
7013 | |
7014 | /* The die_type call above may have already set the type for this DIE. */ | |
7015 | cv_type = get_die_type (die, cu); | |
7016 | if (cv_type) | |
7017 | return cv_type; | |
7018 | ||
f792889a DJ |
7019 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
7020 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7021 | } |
7022 | ||
f792889a | 7023 | static struct type * |
e7c27a73 | 7024 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7025 | { |
f792889a | 7026 | struct type *base_type, *cv_type; |
c906108c | 7027 | |
e7c27a73 | 7028 | base_type = die_type (die, cu); |
7e314c57 JK |
7029 | |
7030 | /* The die_type call above may have already set the type for this DIE. */ | |
7031 | cv_type = get_die_type (die, cu); | |
7032 | if (cv_type) | |
7033 | return cv_type; | |
7034 | ||
f792889a DJ |
7035 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
7036 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7037 | } |
7038 | ||
7039 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
7040 | the user defined type vector. It isn't really a user defined type, | |
7041 | but it behaves like one, with other DIE's using an AT_user_def_type | |
7042 | attribute to reference it. */ | |
7043 | ||
f792889a | 7044 | static struct type * |
e7c27a73 | 7045 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7046 | { |
e7c27a73 | 7047 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 7048 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7049 | struct type *type, *range_type, *index_type, *char_type; |
7050 | struct attribute *attr; | |
7051 | unsigned int length; | |
7052 | ||
e142c38c | 7053 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
7054 | if (attr) |
7055 | { | |
7056 | length = DW_UNSND (attr); | |
7057 | } | |
7058 | else | |
7059 | { | |
b21b22e0 | 7060 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 7061 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
7062 | if (attr) |
7063 | { | |
7064 | length = DW_UNSND (attr); | |
7065 | } | |
7066 | else | |
7067 | { | |
7068 | length = 1; | |
7069 | } | |
c906108c | 7070 | } |
6ccb9162 | 7071 | |
46bf5051 | 7072 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7073 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
7074 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
7075 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 7076 | |
f792889a | 7077 | return set_die_type (die, type, cu); |
c906108c SS |
7078 | } |
7079 | ||
7080 | /* Handle DIES due to C code like: | |
7081 | ||
7082 | struct foo | |
c5aa993b JM |
7083 | { |
7084 | int (*funcp)(int a, long l); | |
7085 | int b; | |
7086 | }; | |
c906108c SS |
7087 | |
7088 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 7089 | */ |
c906108c | 7090 | |
f792889a | 7091 | static struct type * |
e7c27a73 | 7092 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7093 | { |
7094 | struct type *type; /* Type that this function returns */ | |
7095 | struct type *ftype; /* Function that returns above type */ | |
7096 | struct attribute *attr; | |
7097 | ||
e7c27a73 | 7098 | type = die_type (die, cu); |
7e314c57 JK |
7099 | |
7100 | /* The die_type call above may have already set the type for this DIE. */ | |
7101 | ftype = get_die_type (die, cu); | |
7102 | if (ftype) | |
7103 | return ftype; | |
7104 | ||
0c8b41f1 | 7105 | ftype = lookup_function_type (type); |
c906108c | 7106 | |
5b8101ae | 7107 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 7108 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 7109 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 7110 | || cu->language == language_cplus |
5b8101ae PM |
7111 | || cu->language == language_java |
7112 | || cu->language == language_pascal) | |
876cecd0 | 7113 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
7114 | else if (producer_is_realview (cu->producer)) |
7115 | /* RealView does not emit DW_AT_prototyped. We can not | |
7116 | distinguish prototyped and unprototyped functions; default to | |
7117 | prototyped, since that is more common in modern code (and | |
7118 | RealView warns about unprototyped functions). */ | |
7119 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 7120 | |
c055b101 CV |
7121 | /* Store the calling convention in the type if it's available in |
7122 | the subroutine die. Otherwise set the calling convention to | |
7123 | the default value DW_CC_normal. */ | |
7124 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
7125 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
7126 | |
7127 | /* We need to add the subroutine type to the die immediately so | |
7128 | we don't infinitely recurse when dealing with parameters | |
7129 | declared as the same subroutine type. */ | |
7130 | set_die_type (die, ftype, cu); | |
6e70227d | 7131 | |
639d11d3 | 7132 | if (die->child != NULL) |
c906108c | 7133 | { |
8072405b | 7134 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 7135 | struct die_info *child_die; |
8072405b | 7136 | int nparams, iparams; |
c906108c SS |
7137 | |
7138 | /* Count the number of parameters. | |
7139 | FIXME: GDB currently ignores vararg functions, but knows about | |
7140 | vararg member functions. */ | |
8072405b | 7141 | nparams = 0; |
639d11d3 | 7142 | child_die = die->child; |
c906108c SS |
7143 | while (child_die && child_die->tag) |
7144 | { | |
7145 | if (child_die->tag == DW_TAG_formal_parameter) | |
7146 | nparams++; | |
7147 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 7148 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
7149 | child_die = sibling_die (child_die); |
7150 | } | |
7151 | ||
7152 | /* Allocate storage for parameters and fill them in. */ | |
7153 | TYPE_NFIELDS (ftype) = nparams; | |
7154 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 7155 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 7156 | |
8072405b JK |
7157 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
7158 | even if we error out during the parameters reading below. */ | |
7159 | for (iparams = 0; iparams < nparams; iparams++) | |
7160 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
7161 | ||
7162 | iparams = 0; | |
639d11d3 | 7163 | child_die = die->child; |
c906108c SS |
7164 | while (child_die && child_die->tag) |
7165 | { | |
7166 | if (child_die->tag == DW_TAG_formal_parameter) | |
7167 | { | |
7168 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
7169 | member functions. G++ helps GDB by marking the first |
7170 | parameter for non-static member functions (which is the | |
7171 | this pointer) as artificial. We pass this information | |
7172 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 7173 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
7174 | if (attr) |
7175 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
7176 | else | |
418835cc KS |
7177 | { |
7178 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
7179 | ||
7180 | /* GCC/43521: In java, the formal parameter | |
7181 | "this" is sometimes not marked with DW_AT_artificial. */ | |
7182 | if (cu->language == language_java) | |
7183 | { | |
7184 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 7185 | |
418835cc KS |
7186 | if (name && !strcmp (name, "this")) |
7187 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
7188 | } | |
7189 | } | |
e7c27a73 | 7190 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
7191 | iparams++; |
7192 | } | |
7193 | child_die = sibling_die (child_die); | |
7194 | } | |
7195 | } | |
7196 | ||
76c10ea2 | 7197 | return ftype; |
c906108c SS |
7198 | } |
7199 | ||
f792889a | 7200 | static struct type * |
e7c27a73 | 7201 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7202 | { |
e7c27a73 | 7203 | struct objfile *objfile = cu->objfile; |
0114d602 | 7204 | const char *name = NULL; |
f792889a | 7205 | struct type *this_type; |
c906108c | 7206 | |
94af9270 | 7207 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 7208 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
7209 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
7210 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
7211 | set_die_type (die, this_type, cu); |
7212 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
7213 | return this_type; | |
c906108c SS |
7214 | } |
7215 | ||
7216 | /* Find a representation of a given base type and install | |
7217 | it in the TYPE field of the die. */ | |
7218 | ||
f792889a | 7219 | static struct type * |
e7c27a73 | 7220 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7221 | { |
e7c27a73 | 7222 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7223 | struct type *type; |
7224 | struct attribute *attr; | |
7225 | int encoding = 0, size = 0; | |
39cbfefa | 7226 | char *name; |
6ccb9162 UW |
7227 | enum type_code code = TYPE_CODE_INT; |
7228 | int type_flags = 0; | |
7229 | struct type *target_type = NULL; | |
c906108c | 7230 | |
e142c38c | 7231 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
7232 | if (attr) |
7233 | { | |
7234 | encoding = DW_UNSND (attr); | |
7235 | } | |
e142c38c | 7236 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7237 | if (attr) |
7238 | { | |
7239 | size = DW_UNSND (attr); | |
7240 | } | |
39cbfefa | 7241 | name = dwarf2_name (die, cu); |
6ccb9162 | 7242 | if (!name) |
c906108c | 7243 | { |
6ccb9162 UW |
7244 | complaint (&symfile_complaints, |
7245 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 7246 | } |
6ccb9162 UW |
7247 | |
7248 | switch (encoding) | |
c906108c | 7249 | { |
6ccb9162 UW |
7250 | case DW_ATE_address: |
7251 | /* Turn DW_ATE_address into a void * pointer. */ | |
7252 | code = TYPE_CODE_PTR; | |
7253 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7254 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
7255 | break; | |
7256 | case DW_ATE_boolean: | |
7257 | code = TYPE_CODE_BOOL; | |
7258 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7259 | break; | |
7260 | case DW_ATE_complex_float: | |
7261 | code = TYPE_CODE_COMPLEX; | |
7262 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
7263 | break; | |
7264 | case DW_ATE_decimal_float: | |
7265 | code = TYPE_CODE_DECFLOAT; | |
7266 | break; | |
7267 | case DW_ATE_float: | |
7268 | code = TYPE_CODE_FLT; | |
7269 | break; | |
7270 | case DW_ATE_signed: | |
7271 | break; | |
7272 | case DW_ATE_unsigned: | |
7273 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7274 | break; | |
7275 | case DW_ATE_signed_char: | |
6e70227d | 7276 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 7277 | || cu->language == language_pascal) |
6ccb9162 UW |
7278 | code = TYPE_CODE_CHAR; |
7279 | break; | |
7280 | case DW_ATE_unsigned_char: | |
868a0084 PM |
7281 | if (cu->language == language_ada || cu->language == language_m2 |
7282 | || cu->language == language_pascal) | |
6ccb9162 UW |
7283 | code = TYPE_CODE_CHAR; |
7284 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7285 | break; | |
75079b2b TT |
7286 | case DW_ATE_UTF: |
7287 | /* We just treat this as an integer and then recognize the | |
7288 | type by name elsewhere. */ | |
7289 | break; | |
7290 | ||
6ccb9162 UW |
7291 | default: |
7292 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
7293 | dwarf_type_encoding_name (encoding)); | |
7294 | break; | |
c906108c | 7295 | } |
6ccb9162 | 7296 | |
0114d602 DJ |
7297 | type = init_type (code, size, type_flags, NULL, objfile); |
7298 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
7299 | TYPE_TARGET_TYPE (type) = target_type; |
7300 | ||
0114d602 | 7301 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 7302 | TYPE_NOSIGN (type) = 1; |
0114d602 | 7303 | |
f792889a | 7304 | return set_die_type (die, type, cu); |
c906108c SS |
7305 | } |
7306 | ||
a02abb62 JB |
7307 | /* Read the given DW_AT_subrange DIE. */ |
7308 | ||
f792889a | 7309 | static struct type * |
a02abb62 JB |
7310 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
7311 | { | |
5e2b427d | 7312 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
7313 | struct type *base_type; |
7314 | struct type *range_type; | |
7315 | struct attribute *attr; | |
43bbcdc2 PH |
7316 | LONGEST low = 0; |
7317 | LONGEST high = -1; | |
39cbfefa | 7318 | char *name; |
43bbcdc2 | 7319 | LONGEST negative_mask; |
e77813c8 | 7320 | |
a02abb62 | 7321 | base_type = die_type (die, cu); |
953ac07e JK |
7322 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
7323 | check_typedef (base_type); | |
a02abb62 | 7324 | |
7e314c57 JK |
7325 | /* The die_type call above may have already set the type for this DIE. */ |
7326 | range_type = get_die_type (die, cu); | |
7327 | if (range_type) | |
7328 | return range_type; | |
7329 | ||
e142c38c | 7330 | if (cu->language == language_fortran) |
6e70227d | 7331 | { |
a02abb62 JB |
7332 | /* FORTRAN implies a lower bound of 1, if not given. */ |
7333 | low = 1; | |
7334 | } | |
7335 | ||
dd5e6932 DJ |
7336 | /* FIXME: For variable sized arrays either of these could be |
7337 | a variable rather than a constant value. We'll allow it, | |
7338 | but we don't know how to handle it. */ | |
e142c38c | 7339 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
7340 | if (attr) |
7341 | low = dwarf2_get_attr_constant_value (attr, 0); | |
7342 | ||
e142c38c | 7343 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 7344 | if (attr) |
6e70227d | 7345 | { |
e77813c8 | 7346 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
7347 | { |
7348 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 7349 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
7350 | FIXME: GDB does not yet know how to handle dynamic |
7351 | arrays properly, treat them as arrays with unspecified | |
7352 | length for now. | |
7353 | ||
7354 | FIXME: jimb/2003-09-22: GDB does not really know | |
7355 | how to handle arrays of unspecified length | |
7356 | either; we just represent them as zero-length | |
7357 | arrays. Choose an appropriate upper bound given | |
7358 | the lower bound we've computed above. */ | |
7359 | high = low - 1; | |
7360 | } | |
7361 | else | |
7362 | high = dwarf2_get_attr_constant_value (attr, 1); | |
7363 | } | |
e77813c8 PM |
7364 | else |
7365 | { | |
7366 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
7367 | if (attr) | |
7368 | { | |
7369 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
7370 | high = low + count - 1; | |
7371 | } | |
7372 | } | |
7373 | ||
7374 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
7375 | without specifying a base type. | |
7376 | In that case, the base type must be set to the type of | |
7377 | the lower bound, upper bound or count, in that order, if any of these | |
7378 | three attributes references an object that has a type. | |
7379 | If no base type is found, the Dwarf-2 specifications say that | |
7380 | a signed integer type of size equal to the size of an address should | |
7381 | be used. | |
7382 | For the following C code: `extern char gdb_int [];' | |
7383 | GCC produces an empty range DIE. | |
7384 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
7385 | high bound or count are not yet handled by this code. | |
7386 | */ | |
7387 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
7388 | { | |
7389 | struct objfile *objfile = cu->objfile; | |
7390 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
7391 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
7392 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
7393 | ||
7394 | /* Test "int", "long int", and "long long int" objfile types, | |
7395 | and select the first one having a size above or equal to the | |
7396 | architecture address size. */ | |
7397 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7398 | base_type = int_type; | |
7399 | else | |
7400 | { | |
7401 | int_type = objfile_type (objfile)->builtin_long; | |
7402 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7403 | base_type = int_type; | |
7404 | else | |
7405 | { | |
7406 | int_type = objfile_type (objfile)->builtin_long_long; | |
7407 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
7408 | base_type = int_type; | |
7409 | } | |
7410 | } | |
7411 | } | |
a02abb62 | 7412 | |
6e70227d | 7413 | negative_mask = |
43bbcdc2 PH |
7414 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
7415 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
7416 | low |= negative_mask; | |
7417 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
7418 | high |= negative_mask; | |
7419 | ||
a02abb62 JB |
7420 | range_type = create_range_type (NULL, base_type, low, high); |
7421 | ||
bbb0eef6 JK |
7422 | /* Mark arrays with dynamic length at least as an array of unspecified |
7423 | length. GDB could check the boundary but before it gets implemented at | |
7424 | least allow accessing the array elements. */ | |
7425 | if (attr && attr->form == DW_FORM_block1) | |
7426 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
7427 | ||
39cbfefa DJ |
7428 | name = dwarf2_name (die, cu); |
7429 | if (name) | |
7430 | TYPE_NAME (range_type) = name; | |
6e70227d | 7431 | |
e142c38c | 7432 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
7433 | if (attr) |
7434 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
7435 | ||
7e314c57 JK |
7436 | set_die_type (die, range_type, cu); |
7437 | ||
7438 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7439 | set_descriptive_type (range_type, die, cu); |
7440 | ||
7e314c57 | 7441 | return range_type; |
a02abb62 | 7442 | } |
6e70227d | 7443 | |
f792889a | 7444 | static struct type * |
81a17f79 JB |
7445 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
7446 | { | |
7447 | struct type *type; | |
81a17f79 | 7448 | |
81a17f79 JB |
7449 | /* For now, we only support the C meaning of an unspecified type: void. */ |
7450 | ||
0114d602 DJ |
7451 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
7452 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 7453 | |
f792889a | 7454 | return set_die_type (die, type, cu); |
81a17f79 | 7455 | } |
a02abb62 | 7456 | |
51545339 DJ |
7457 | /* Trivial hash function for die_info: the hash value of a DIE |
7458 | is its offset in .debug_info for this objfile. */ | |
7459 | ||
7460 | static hashval_t | |
7461 | die_hash (const void *item) | |
7462 | { | |
7463 | const struct die_info *die = item; | |
9a619af0 | 7464 | |
51545339 DJ |
7465 | return die->offset; |
7466 | } | |
7467 | ||
7468 | /* Trivial comparison function for die_info structures: two DIEs | |
7469 | are equal if they have the same offset. */ | |
7470 | ||
7471 | static int | |
7472 | die_eq (const void *item_lhs, const void *item_rhs) | |
7473 | { | |
7474 | const struct die_info *die_lhs = item_lhs; | |
7475 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 7476 | |
51545339 DJ |
7477 | return die_lhs->offset == die_rhs->offset; |
7478 | } | |
7479 | ||
c906108c SS |
7480 | /* Read a whole compilation unit into a linked list of dies. */ |
7481 | ||
f9aca02d | 7482 | static struct die_info * |
93311388 | 7483 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 7484 | { |
93311388 DE |
7485 | struct die_reader_specs reader_specs; |
7486 | ||
348e048f | 7487 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
7488 | cu->die_hash |
7489 | = htab_create_alloc_ex (cu->header.length / 12, | |
7490 | die_hash, | |
7491 | die_eq, | |
7492 | NULL, | |
7493 | &cu->comp_unit_obstack, | |
7494 | hashtab_obstack_allocate, | |
7495 | dummy_obstack_deallocate); | |
7496 | ||
93311388 DE |
7497 | init_cu_die_reader (&reader_specs, cu); |
7498 | ||
7499 | return read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); | |
639d11d3 DC |
7500 | } |
7501 | ||
d97bc12b DE |
7502 | /* Main entry point for reading a DIE and all children. |
7503 | Read the DIE and dump it if requested. */ | |
7504 | ||
7505 | static struct die_info * | |
93311388 DE |
7506 | read_die_and_children (const struct die_reader_specs *reader, |
7507 | gdb_byte *info_ptr, | |
d97bc12b DE |
7508 | gdb_byte **new_info_ptr, |
7509 | struct die_info *parent) | |
7510 | { | |
93311388 | 7511 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
7512 | new_info_ptr, parent); |
7513 | ||
7514 | if (dwarf2_die_debug) | |
7515 | { | |
348e048f DE |
7516 | fprintf_unfiltered (gdb_stdlog, |
7517 | "\nRead die from %s of %s:\n", | |
7518 | reader->buffer == dwarf2_per_objfile->info.buffer | |
7519 | ? ".debug_info" | |
7520 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
7521 | ? ".debug_types" | |
7522 | : "unknown section", | |
7523 | reader->abfd->filename); | |
d97bc12b DE |
7524 | dump_die (result, dwarf2_die_debug); |
7525 | } | |
7526 | ||
7527 | return result; | |
7528 | } | |
7529 | ||
639d11d3 DC |
7530 | /* Read a single die and all its descendents. Set the die's sibling |
7531 | field to NULL; set other fields in the die correctly, and set all | |
7532 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
7533 | location of the info_ptr after reading all of those dies. PARENT | |
7534 | is the parent of the die in question. */ | |
7535 | ||
7536 | static struct die_info * | |
93311388 DE |
7537 | read_die_and_children_1 (const struct die_reader_specs *reader, |
7538 | gdb_byte *info_ptr, | |
d97bc12b DE |
7539 | gdb_byte **new_info_ptr, |
7540 | struct die_info *parent) | |
639d11d3 DC |
7541 | { |
7542 | struct die_info *die; | |
fe1b8b76 | 7543 | gdb_byte *cur_ptr; |
639d11d3 DC |
7544 | int has_children; |
7545 | ||
93311388 | 7546 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
7547 | if (die == NULL) |
7548 | { | |
7549 | *new_info_ptr = cur_ptr; | |
7550 | return NULL; | |
7551 | } | |
93311388 | 7552 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
7553 | |
7554 | if (has_children) | |
348e048f | 7555 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
7556 | else |
7557 | { | |
7558 | die->child = NULL; | |
7559 | *new_info_ptr = cur_ptr; | |
7560 | } | |
7561 | ||
7562 | die->sibling = NULL; | |
7563 | die->parent = parent; | |
7564 | return die; | |
7565 | } | |
7566 | ||
7567 | /* Read a die, all of its descendents, and all of its siblings; set | |
7568 | all of the fields of all of the dies correctly. Arguments are as | |
7569 | in read_die_and_children. */ | |
7570 | ||
7571 | static struct die_info * | |
93311388 DE |
7572 | read_die_and_siblings (const struct die_reader_specs *reader, |
7573 | gdb_byte *info_ptr, | |
fe1b8b76 | 7574 | gdb_byte **new_info_ptr, |
639d11d3 DC |
7575 | struct die_info *parent) |
7576 | { | |
7577 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 7578 | gdb_byte *cur_ptr; |
639d11d3 | 7579 | |
c906108c | 7580 | cur_ptr = info_ptr; |
639d11d3 DC |
7581 | first_die = last_sibling = NULL; |
7582 | ||
7583 | while (1) | |
c906108c | 7584 | { |
639d11d3 | 7585 | struct die_info *die |
93311388 | 7586 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 7587 | |
1d325ec1 | 7588 | if (die == NULL) |
c906108c | 7589 | { |
639d11d3 DC |
7590 | *new_info_ptr = cur_ptr; |
7591 | return first_die; | |
c906108c | 7592 | } |
1d325ec1 DJ |
7593 | |
7594 | if (!first_die) | |
7595 | first_die = die; | |
c906108c | 7596 | else |
1d325ec1 DJ |
7597 | last_sibling->sibling = die; |
7598 | ||
7599 | last_sibling = die; | |
c906108c | 7600 | } |
c906108c SS |
7601 | } |
7602 | ||
93311388 DE |
7603 | /* Read the die from the .debug_info section buffer. Set DIEP to |
7604 | point to a newly allocated die with its information, except for its | |
7605 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
7606 | whether the die has children or not. */ | |
7607 | ||
7608 | static gdb_byte * | |
7609 | read_full_die (const struct die_reader_specs *reader, | |
7610 | struct die_info **diep, gdb_byte *info_ptr, | |
7611 | int *has_children) | |
7612 | { | |
7613 | unsigned int abbrev_number, bytes_read, i, offset; | |
7614 | struct abbrev_info *abbrev; | |
7615 | struct die_info *die; | |
7616 | struct dwarf2_cu *cu = reader->cu; | |
7617 | bfd *abfd = reader->abfd; | |
7618 | ||
7619 | offset = info_ptr - reader->buffer; | |
7620 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
7621 | info_ptr += bytes_read; | |
7622 | if (!abbrev_number) | |
7623 | { | |
7624 | *diep = NULL; | |
7625 | *has_children = 0; | |
7626 | return info_ptr; | |
7627 | } | |
7628 | ||
7629 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
7630 | if (!abbrev) | |
348e048f DE |
7631 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
7632 | abbrev_number, | |
7633 | bfd_get_filename (abfd)); | |
7634 | ||
93311388 DE |
7635 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
7636 | die->offset = offset; | |
7637 | die->tag = abbrev->tag; | |
7638 | die->abbrev = abbrev_number; | |
7639 | ||
7640 | die->num_attrs = abbrev->num_attrs; | |
7641 | ||
7642 | for (i = 0; i < abbrev->num_attrs; ++i) | |
7643 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
7644 | abfd, info_ptr, cu); | |
7645 | ||
7646 | *diep = die; | |
7647 | *has_children = abbrev->has_children; | |
7648 | return info_ptr; | |
7649 | } | |
7650 | ||
c906108c SS |
7651 | /* In DWARF version 2, the description of the debugging information is |
7652 | stored in a separate .debug_abbrev section. Before we read any | |
7653 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
7654 | in a hash table. This function also sets flags in CU describing |
7655 | the data found in the abbrev table. */ | |
c906108c SS |
7656 | |
7657 | static void | |
e7c27a73 | 7658 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 7659 | { |
e7c27a73 | 7660 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 7661 | gdb_byte *abbrev_ptr; |
c906108c SS |
7662 | struct abbrev_info *cur_abbrev; |
7663 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
7664 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
7665 | struct attr_abbrev *cur_attrs; |
7666 | unsigned int allocated_attrs; | |
c906108c | 7667 | |
57349743 | 7668 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
7669 | obstack_init (&cu->abbrev_obstack); |
7670 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
7671 | (ABBREV_HASH_SIZE | |
7672 | * sizeof (struct abbrev_info *))); | |
7673 | memset (cu->dwarf2_abbrevs, 0, | |
7674 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 7675 | |
be391dca TT |
7676 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
7677 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 7678 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
7679 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
7680 | abbrev_ptr += bytes_read; | |
7681 | ||
f3dd6933 DJ |
7682 | allocated_attrs = ATTR_ALLOC_CHUNK; |
7683 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 7684 | |
c906108c SS |
7685 | /* loop until we reach an abbrev number of 0 */ |
7686 | while (abbrev_number) | |
7687 | { | |
f3dd6933 | 7688 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
7689 | |
7690 | /* read in abbrev header */ | |
7691 | cur_abbrev->number = abbrev_number; | |
7692 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7693 | abbrev_ptr += bytes_read; | |
7694 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
7695 | abbrev_ptr += 1; | |
7696 | ||
72bf9492 DJ |
7697 | if (cur_abbrev->tag == DW_TAG_namespace) |
7698 | cu->has_namespace_info = 1; | |
7699 | ||
c906108c SS |
7700 | /* now read in declarations */ |
7701 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7702 | abbrev_ptr += bytes_read; | |
7703 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7704 | abbrev_ptr += bytes_read; | |
7705 | while (abbrev_name) | |
7706 | { | |
f3dd6933 | 7707 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 7708 | { |
f3dd6933 DJ |
7709 | allocated_attrs += ATTR_ALLOC_CHUNK; |
7710 | cur_attrs | |
7711 | = xrealloc (cur_attrs, (allocated_attrs | |
7712 | * sizeof (struct attr_abbrev))); | |
c906108c | 7713 | } |
ae038cb0 DJ |
7714 | |
7715 | /* Record whether this compilation unit might have | |
7716 | inter-compilation-unit references. If we don't know what form | |
7717 | this attribute will have, then it might potentially be a | |
7718 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
7719 | references. */ | |
7720 | ||
7721 | if (abbrev_form == DW_FORM_ref_addr | |
7722 | || abbrev_form == DW_FORM_indirect) | |
7723 | cu->has_form_ref_addr = 1; | |
7724 | ||
f3dd6933 DJ |
7725 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
7726 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
7727 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
7728 | abbrev_ptr += bytes_read; | |
7729 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7730 | abbrev_ptr += bytes_read; | |
7731 | } | |
7732 | ||
f3dd6933 DJ |
7733 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
7734 | (cur_abbrev->num_attrs | |
7735 | * sizeof (struct attr_abbrev))); | |
7736 | memcpy (cur_abbrev->attrs, cur_attrs, | |
7737 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
7738 | ||
c906108c | 7739 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
7740 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
7741 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
7742 | |
7743 | /* Get next abbreviation. | |
7744 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
7745 | always properly terminated with an abbrev number of 0. |
7746 | Exit loop if we encounter an abbreviation which we have | |
7747 | already read (which means we are about to read the abbreviations | |
7748 | for the next compile unit) or if the end of the abbreviation | |
7749 | table is reached. */ | |
dce234bc PP |
7750 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
7751 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
7752 | break; |
7753 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
7754 | abbrev_ptr += bytes_read; | |
e7c27a73 | 7755 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
7756 | break; |
7757 | } | |
f3dd6933 DJ |
7758 | |
7759 | xfree (cur_attrs); | |
c906108c SS |
7760 | } |
7761 | ||
f3dd6933 | 7762 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 7763 | |
c906108c | 7764 | static void |
f3dd6933 | 7765 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 7766 | { |
f3dd6933 | 7767 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 7768 | |
f3dd6933 DJ |
7769 | obstack_free (&cu->abbrev_obstack, NULL); |
7770 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
7771 | } |
7772 | ||
7773 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
7774 | ||
7775 | static struct abbrev_info * | |
e7c27a73 | 7776 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
7777 | { |
7778 | unsigned int hash_number; | |
7779 | struct abbrev_info *abbrev; | |
7780 | ||
7781 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 7782 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
7783 | |
7784 | while (abbrev) | |
7785 | { | |
7786 | if (abbrev->number == number) | |
7787 | return abbrev; | |
7788 | else | |
7789 | abbrev = abbrev->next; | |
7790 | } | |
7791 | return NULL; | |
7792 | } | |
7793 | ||
72bf9492 DJ |
7794 | /* Returns nonzero if TAG represents a type that we might generate a partial |
7795 | symbol for. */ | |
7796 | ||
7797 | static int | |
7798 | is_type_tag_for_partial (int tag) | |
7799 | { | |
7800 | switch (tag) | |
7801 | { | |
7802 | #if 0 | |
7803 | /* Some types that would be reasonable to generate partial symbols for, | |
7804 | that we don't at present. */ | |
7805 | case DW_TAG_array_type: | |
7806 | case DW_TAG_file_type: | |
7807 | case DW_TAG_ptr_to_member_type: | |
7808 | case DW_TAG_set_type: | |
7809 | case DW_TAG_string_type: | |
7810 | case DW_TAG_subroutine_type: | |
7811 | #endif | |
7812 | case DW_TAG_base_type: | |
7813 | case DW_TAG_class_type: | |
680b30c7 | 7814 | case DW_TAG_interface_type: |
72bf9492 DJ |
7815 | case DW_TAG_enumeration_type: |
7816 | case DW_TAG_structure_type: | |
7817 | case DW_TAG_subrange_type: | |
7818 | case DW_TAG_typedef: | |
7819 | case DW_TAG_union_type: | |
7820 | return 1; | |
7821 | default: | |
7822 | return 0; | |
7823 | } | |
7824 | } | |
7825 | ||
7826 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
7827 | ||
7828 | static struct partial_die_info * | |
93311388 DE |
7829 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
7830 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
7831 | { |
7832 | struct partial_die_info *part_die; | |
7833 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
7834 | struct abbrev_info *abbrev; | |
7835 | unsigned int bytes_read; | |
5afb4e99 | 7836 | unsigned int load_all = 0; |
72bf9492 DJ |
7837 | |
7838 | int nesting_level = 1; | |
7839 | ||
7840 | parent_die = NULL; | |
7841 | last_die = NULL; | |
7842 | ||
5afb4e99 DJ |
7843 | if (cu->per_cu && cu->per_cu->load_all_dies) |
7844 | load_all = 1; | |
7845 | ||
72bf9492 DJ |
7846 | cu->partial_dies |
7847 | = htab_create_alloc_ex (cu->header.length / 12, | |
7848 | partial_die_hash, | |
7849 | partial_die_eq, | |
7850 | NULL, | |
7851 | &cu->comp_unit_obstack, | |
7852 | hashtab_obstack_allocate, | |
7853 | dummy_obstack_deallocate); | |
7854 | ||
7855 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
7856 | sizeof (struct partial_die_info)); | |
7857 | ||
7858 | while (1) | |
7859 | { | |
7860 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
7861 | ||
7862 | /* A NULL abbrev means the end of a series of children. */ | |
7863 | if (abbrev == NULL) | |
7864 | { | |
7865 | if (--nesting_level == 0) | |
7866 | { | |
7867 | /* PART_DIE was probably the last thing allocated on the | |
7868 | comp_unit_obstack, so we could call obstack_free | |
7869 | here. We don't do that because the waste is small, | |
7870 | and will be cleaned up when we're done with this | |
7871 | compilation unit. This way, we're also more robust | |
7872 | against other users of the comp_unit_obstack. */ | |
7873 | return first_die; | |
7874 | } | |
7875 | info_ptr += bytes_read; | |
7876 | last_die = parent_die; | |
7877 | parent_die = parent_die->die_parent; | |
7878 | continue; | |
7879 | } | |
7880 | ||
5afb4e99 DJ |
7881 | /* Check whether this DIE is interesting enough to save. Normally |
7882 | we would not be interested in members here, but there may be | |
7883 | later variables referencing them via DW_AT_specification (for | |
7884 | static members). */ | |
7885 | if (!load_all | |
7886 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
7887 | && abbrev->tag != DW_TAG_enumerator |
7888 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 7889 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 7890 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 7891 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 7892 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 7893 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
7894 | { |
7895 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 7896 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
7897 | continue; |
7898 | } | |
7899 | ||
93311388 DE |
7900 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
7901 | buffer, info_ptr, cu); | |
72bf9492 DJ |
7902 | |
7903 | /* This two-pass algorithm for processing partial symbols has a | |
7904 | high cost in cache pressure. Thus, handle some simple cases | |
7905 | here which cover the majority of C partial symbols. DIEs | |
7906 | which neither have specification tags in them, nor could have | |
7907 | specification tags elsewhere pointing at them, can simply be | |
7908 | processed and discarded. | |
7909 | ||
7910 | This segment is also optional; scan_partial_symbols and | |
7911 | add_partial_symbol will handle these DIEs if we chain | |
7912 | them in normally. When compilers which do not emit large | |
7913 | quantities of duplicate debug information are more common, | |
7914 | this code can probably be removed. */ | |
7915 | ||
7916 | /* Any complete simple types at the top level (pretty much all | |
7917 | of them, for a language without namespaces), can be processed | |
7918 | directly. */ | |
7919 | if (parent_die == NULL | |
7920 | && part_die->has_specification == 0 | |
7921 | && part_die->is_declaration == 0 | |
7922 | && (part_die->tag == DW_TAG_typedef | |
7923 | || part_die->tag == DW_TAG_base_type | |
7924 | || part_die->tag == DW_TAG_subrange_type)) | |
7925 | { | |
7926 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 7927 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
7928 | VAR_DOMAIN, LOC_TYPEDEF, |
7929 | &cu->objfile->static_psymbols, | |
7930 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 7931 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
7932 | continue; |
7933 | } | |
7934 | ||
7935 | /* If we're at the second level, and we're an enumerator, and | |
7936 | our parent has no specification (meaning possibly lives in a | |
7937 | namespace elsewhere), then we can add the partial symbol now | |
7938 | instead of queueing it. */ | |
7939 | if (part_die->tag == DW_TAG_enumerator | |
7940 | && parent_die != NULL | |
7941 | && parent_die->die_parent == NULL | |
7942 | && parent_die->tag == DW_TAG_enumeration_type | |
7943 | && parent_die->has_specification == 0) | |
7944 | { | |
7945 | if (part_die->name == NULL) | |
e2e0b3e5 | 7946 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 7947 | else if (building_psymtab) |
04a679b8 | 7948 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 7949 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
7950 | (cu->language == language_cplus |
7951 | || cu->language == language_java) | |
72bf9492 DJ |
7952 | ? &cu->objfile->global_psymbols |
7953 | : &cu->objfile->static_psymbols, | |
7954 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
7955 | ||
93311388 | 7956 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
7957 | continue; |
7958 | } | |
7959 | ||
7960 | /* We'll save this DIE so link it in. */ | |
7961 | part_die->die_parent = parent_die; | |
7962 | part_die->die_sibling = NULL; | |
7963 | part_die->die_child = NULL; | |
7964 | ||
7965 | if (last_die && last_die == parent_die) | |
7966 | last_die->die_child = part_die; | |
7967 | else if (last_die) | |
7968 | last_die->die_sibling = part_die; | |
7969 | ||
7970 | last_die = part_die; | |
7971 | ||
7972 | if (first_die == NULL) | |
7973 | first_die = part_die; | |
7974 | ||
7975 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
7976 | find interesting need to be in the hash table, because we | |
7977 | also have the parent/sibling/child chains; only those that we | |
7978 | might refer to by offset later during partial symbol reading. | |
7979 | ||
7980 | For now this means things that might have be the target of a | |
7981 | DW_AT_specification, DW_AT_abstract_origin, or | |
7982 | DW_AT_extension. DW_AT_extension will refer only to | |
7983 | namespaces; DW_AT_abstract_origin refers to functions (and | |
7984 | many things under the function DIE, but we do not recurse | |
7985 | into function DIEs during partial symbol reading) and | |
7986 | possibly variables as well; DW_AT_specification refers to | |
7987 | declarations. Declarations ought to have the DW_AT_declaration | |
7988 | flag. It happens that GCC forgets to put it in sometimes, but | |
7989 | only for functions, not for types. | |
7990 | ||
7991 | Adding more things than necessary to the hash table is harmless | |
7992 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
7993 | wasted time in find_partial_die, when we reread the compilation |
7994 | unit with load_all_dies set. */ | |
72bf9492 | 7995 | |
5afb4e99 DJ |
7996 | if (load_all |
7997 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
7998 | || abbrev->tag == DW_TAG_variable |
7999 | || abbrev->tag == DW_TAG_namespace | |
8000 | || part_die->is_declaration) | |
8001 | { | |
8002 | void **slot; | |
8003 | ||
8004 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
8005 | part_die->offset, INSERT); | |
8006 | *slot = part_die; | |
8007 | } | |
8008 | ||
8009 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8010 | sizeof (struct partial_die_info)); | |
8011 | ||
8012 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 8013 | we have no reason to follow the children of structures; for other |
72bf9492 | 8014 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
8015 | to infer fully qualified class names, and for DW_AT_specification. |
8016 | ||
8017 | For Ada, we need to scan the children of subprograms and lexical | |
8018 | blocks as well because Ada allows the definition of nested | |
8019 | entities that could be interesting for the debugger, such as | |
8020 | nested subprograms for instance. */ | |
72bf9492 | 8021 | if (last_die->has_children |
5afb4e99 DJ |
8022 | && (load_all |
8023 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 8024 | || last_die->tag == DW_TAG_module |
72bf9492 DJ |
8025 | || last_die->tag == DW_TAG_enumeration_type |
8026 | || (cu->language != language_c | |
8027 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 8028 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 8029 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
8030 | || last_die->tag == DW_TAG_union_type)) |
8031 | || (cu->language == language_ada | |
8032 | && (last_die->tag == DW_TAG_subprogram | |
8033 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
8034 | { |
8035 | nesting_level++; | |
8036 | parent_die = last_die; | |
8037 | continue; | |
8038 | } | |
8039 | ||
8040 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8041 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8042 | |
8043 | /* Back to the top, do it again. */ | |
8044 | } | |
8045 | } | |
8046 | ||
c906108c SS |
8047 | /* Read a minimal amount of information into the minimal die structure. */ |
8048 | ||
fe1b8b76 | 8049 | static gdb_byte * |
72bf9492 DJ |
8050 | read_partial_die (struct partial_die_info *part_die, |
8051 | struct abbrev_info *abbrev, | |
8052 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
8053 | gdb_byte *buffer, gdb_byte *info_ptr, |
8054 | struct dwarf2_cu *cu) | |
c906108c | 8055 | { |
fa238c03 | 8056 | unsigned int i; |
c906108c | 8057 | struct attribute attr; |
c5aa993b | 8058 | int has_low_pc_attr = 0; |
c906108c SS |
8059 | int has_high_pc_attr = 0; |
8060 | ||
72bf9492 | 8061 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 8062 | |
93311388 | 8063 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
8064 | |
8065 | info_ptr += abbrev_len; | |
8066 | ||
8067 | if (abbrev == NULL) | |
8068 | return info_ptr; | |
8069 | ||
c906108c SS |
8070 | part_die->tag = abbrev->tag; |
8071 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
8072 | |
8073 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8074 | { | |
e7c27a73 | 8075 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
8076 | |
8077 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 8078 | partial symbol table. */ |
c906108c SS |
8079 | switch (attr.name) |
8080 | { | |
8081 | case DW_AT_name: | |
71c25dea TT |
8082 | switch (part_die->tag) |
8083 | { | |
8084 | case DW_TAG_compile_unit: | |
348e048f | 8085 | case DW_TAG_type_unit: |
71c25dea TT |
8086 | /* Compilation units have a DW_AT_name that is a filename, not |
8087 | a source language identifier. */ | |
8088 | case DW_TAG_enumeration_type: | |
8089 | case DW_TAG_enumerator: | |
8090 | /* These tags always have simple identifiers already; no need | |
8091 | to canonicalize them. */ | |
8092 | part_die->name = DW_STRING (&attr); | |
8093 | break; | |
8094 | default: | |
8095 | part_die->name | |
8096 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 8097 | &cu->objfile->objfile_obstack); |
71c25dea TT |
8098 | break; |
8099 | } | |
c906108c | 8100 | break; |
31ef98ae | 8101 | case DW_AT_linkage_name: |
c906108c | 8102 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
8103 | /* Note that both forms of linkage name might appear. We |
8104 | assume they will be the same, and we only store the last | |
8105 | one we see. */ | |
94af9270 KS |
8106 | if (cu->language == language_ada) |
8107 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
8108 | break; |
8109 | case DW_AT_low_pc: | |
8110 | has_low_pc_attr = 1; | |
8111 | part_die->lowpc = DW_ADDR (&attr); | |
8112 | break; | |
8113 | case DW_AT_high_pc: | |
8114 | has_high_pc_attr = 1; | |
8115 | part_die->highpc = DW_ADDR (&attr); | |
8116 | break; | |
8117 | case DW_AT_location: | |
8e19ed76 PS |
8118 | /* Support the .debug_loc offsets */ |
8119 | if (attr_form_is_block (&attr)) | |
8120 | { | |
8121 | part_die->locdesc = DW_BLOCK (&attr); | |
8122 | } | |
3690dd37 | 8123 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 8124 | { |
4d3c2250 | 8125 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8126 | } |
8127 | else | |
8128 | { | |
4d3c2250 KB |
8129 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8130 | "partial symbol information"); | |
8e19ed76 | 8131 | } |
c906108c | 8132 | break; |
c906108c SS |
8133 | case DW_AT_external: |
8134 | part_die->is_external = DW_UNSND (&attr); | |
8135 | break; | |
8136 | case DW_AT_declaration: | |
8137 | part_die->is_declaration = DW_UNSND (&attr); | |
8138 | break; | |
8139 | case DW_AT_type: | |
8140 | part_die->has_type = 1; | |
8141 | break; | |
8142 | case DW_AT_abstract_origin: | |
8143 | case DW_AT_specification: | |
72bf9492 DJ |
8144 | case DW_AT_extension: |
8145 | part_die->has_specification = 1; | |
c764a876 | 8146 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
8147 | break; |
8148 | case DW_AT_sibling: | |
8149 | /* Ignore absolute siblings, they might point outside of | |
8150 | the current compile unit. */ | |
8151 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 8152 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 8153 | else |
93311388 | 8154 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 8155 | break; |
fa4028e9 JB |
8156 | case DW_AT_byte_size: |
8157 | part_die->has_byte_size = 1; | |
8158 | break; | |
68511cec CES |
8159 | case DW_AT_calling_convention: |
8160 | /* DWARF doesn't provide a way to identify a program's source-level | |
8161 | entry point. DW_AT_calling_convention attributes are only meant | |
8162 | to describe functions' calling conventions. | |
8163 | ||
8164 | However, because it's a necessary piece of information in | |
8165 | Fortran, and because DW_CC_program is the only piece of debugging | |
8166 | information whose definition refers to a 'main program' at all, | |
8167 | several compilers have begun marking Fortran main programs with | |
8168 | DW_CC_program --- even when those functions use the standard | |
8169 | calling conventions. | |
8170 | ||
8171 | So until DWARF specifies a way to provide this information and | |
8172 | compilers pick up the new representation, we'll support this | |
8173 | practice. */ | |
8174 | if (DW_UNSND (&attr) == DW_CC_program | |
8175 | && cu->language == language_fortran) | |
8176 | set_main_name (part_die->name); | |
8177 | break; | |
c906108c SS |
8178 | default: |
8179 | break; | |
8180 | } | |
8181 | } | |
8182 | ||
c906108c SS |
8183 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
8184 | eliminate duplicate copies of functions and vtables and such. | |
8185 | The linker will arbitrarily choose one and discard the others. | |
8186 | The AT_*_pc values for such functions refer to local labels in | |
8187 | these sections. If the section from that file was discarded, the | |
8188 | labels are not in the output, so the relocs get a value of 0. | |
8189 | If this is a discarded function, mark the pc bounds as invalid, | |
8190 | so that GDB will ignore it. */ | |
8191 | if (has_low_pc_attr && has_high_pc_attr | |
8192 | && part_die->lowpc < part_die->highpc | |
8193 | && (part_die->lowpc != 0 | |
72dca2f5 | 8194 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 8195 | part_die->has_pc_info = 1; |
85cbf3d3 | 8196 | |
c906108c SS |
8197 | return info_ptr; |
8198 | } | |
8199 | ||
72bf9492 DJ |
8200 | /* Find a cached partial DIE at OFFSET in CU. */ |
8201 | ||
8202 | static struct partial_die_info * | |
c764a876 | 8203 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
8204 | { |
8205 | struct partial_die_info *lookup_die = NULL; | |
8206 | struct partial_die_info part_die; | |
8207 | ||
8208 | part_die.offset = offset; | |
8209 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
8210 | ||
72bf9492 DJ |
8211 | return lookup_die; |
8212 | } | |
8213 | ||
348e048f DE |
8214 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
8215 | except in the case of .debug_types DIEs which do not reference | |
8216 | outside their CU (they do however referencing other types via | |
8217 | DW_FORM_sig8). */ | |
72bf9492 DJ |
8218 | |
8219 | static struct partial_die_info * | |
c764a876 | 8220 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 8221 | { |
5afb4e99 DJ |
8222 | struct dwarf2_per_cu_data *per_cu = NULL; |
8223 | struct partial_die_info *pd = NULL; | |
72bf9492 | 8224 | |
348e048f DE |
8225 | if (cu->per_cu->from_debug_types) |
8226 | { | |
8227 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8228 | if (pd != NULL) | |
8229 | return pd; | |
8230 | goto not_found; | |
8231 | } | |
8232 | ||
45452591 | 8233 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
8234 | { |
8235 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8236 | if (pd != NULL) | |
8237 | return pd; | |
8238 | } | |
72bf9492 | 8239 | |
ae038cb0 DJ |
8240 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
8241 | ||
ae038cb0 DJ |
8242 | if (per_cu->cu == NULL) |
8243 | { | |
93311388 | 8244 | load_partial_comp_unit (per_cu, cu->objfile); |
ae038cb0 DJ |
8245 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
8246 | dwarf2_per_objfile->read_in_chain = per_cu; | |
8247 | } | |
8248 | ||
8249 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
8250 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
8251 | ||
8252 | if (pd == NULL && per_cu->load_all_dies == 0) | |
8253 | { | |
8254 | struct cleanup *back_to; | |
8255 | struct partial_die_info comp_unit_die; | |
8256 | struct abbrev_info *abbrev; | |
8257 | unsigned int bytes_read; | |
8258 | char *info_ptr; | |
8259 | ||
8260 | per_cu->load_all_dies = 1; | |
8261 | ||
8262 | /* Re-read the DIEs. */ | |
8263 | back_to = make_cleanup (null_cleanup, 0); | |
8264 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
8265 | { | |
8266 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 8267 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 8268 | } |
dce234bc | 8269 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
8270 | + per_cu->cu->header.offset |
8271 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
8272 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
8273 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
8274 | per_cu->cu->objfile->obfd, |
8275 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
8276 | per_cu->cu); |
8277 | if (comp_unit_die.has_children) | |
93311388 DE |
8278 | load_partial_dies (per_cu->cu->objfile->obfd, |
8279 | dwarf2_per_objfile->info.buffer, info_ptr, | |
8280 | 0, per_cu->cu); | |
5afb4e99 DJ |
8281 | do_cleanups (back_to); |
8282 | ||
8283 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
8284 | } | |
8285 | ||
348e048f DE |
8286 | not_found: |
8287 | ||
5afb4e99 DJ |
8288 | if (pd == NULL) |
8289 | internal_error (__FILE__, __LINE__, | |
c764a876 | 8290 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
8291 | offset, bfd_get_filename (cu->objfile->obfd)); |
8292 | return pd; | |
72bf9492 DJ |
8293 | } |
8294 | ||
8295 | /* Adjust PART_DIE before generating a symbol for it. This function | |
8296 | may set the is_external flag or change the DIE's name. */ | |
8297 | ||
8298 | static void | |
8299 | fixup_partial_die (struct partial_die_info *part_die, | |
8300 | struct dwarf2_cu *cu) | |
8301 | { | |
8302 | /* If we found a reference attribute and the DIE has no name, try | |
8303 | to find a name in the referred to DIE. */ | |
8304 | ||
8305 | if (part_die->name == NULL && part_die->has_specification) | |
8306 | { | |
8307 | struct partial_die_info *spec_die; | |
72bf9492 | 8308 | |
10b3939b | 8309 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 8310 | |
10b3939b | 8311 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
8312 | |
8313 | if (spec_die->name) | |
8314 | { | |
8315 | part_die->name = spec_die->name; | |
8316 | ||
8317 | /* Copy DW_AT_external attribute if it is set. */ | |
8318 | if (spec_die->is_external) | |
8319 | part_die->is_external = spec_die->is_external; | |
8320 | } | |
8321 | } | |
8322 | ||
8323 | /* Set default names for some unnamed DIEs. */ | |
8324 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
8325 | || part_die->tag == DW_TAG_class_type)) | |
8326 | part_die->name = "(anonymous class)"; | |
8327 | ||
8328 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
8329 | part_die->name = "(anonymous namespace)"; | |
8330 | ||
8331 | if (part_die->tag == DW_TAG_structure_type | |
8332 | || part_die->tag == DW_TAG_class_type | |
8333 | || part_die->tag == DW_TAG_union_type) | |
8334 | guess_structure_name (part_die, cu); | |
8335 | } | |
8336 | ||
a8329558 | 8337 | /* Read an attribute value described by an attribute form. */ |
c906108c | 8338 | |
fe1b8b76 | 8339 | static gdb_byte * |
a8329558 | 8340 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 8341 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 8342 | struct dwarf2_cu *cu) |
c906108c | 8343 | { |
e7c27a73 | 8344 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
8345 | unsigned int bytes_read; |
8346 | struct dwarf_block *blk; | |
8347 | ||
a8329558 KW |
8348 | attr->form = form; |
8349 | switch (form) | |
c906108c | 8350 | { |
c906108c | 8351 | case DW_FORM_ref_addr: |
ae411497 TT |
8352 | if (cu->header.version == 2) |
8353 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
8354 | else | |
8355 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
8356 | info_ptr += bytes_read; | |
8357 | break; | |
8358 | case DW_FORM_addr: | |
e7c27a73 | 8359 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 8360 | info_ptr += bytes_read; |
c906108c SS |
8361 | break; |
8362 | case DW_FORM_block2: | |
7b5a2f43 | 8363 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8364 | blk->size = read_2_bytes (abfd, info_ptr); |
8365 | info_ptr += 2; | |
8366 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8367 | info_ptr += blk->size; | |
8368 | DW_BLOCK (attr) = blk; | |
8369 | break; | |
8370 | case DW_FORM_block4: | |
7b5a2f43 | 8371 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8372 | blk->size = read_4_bytes (abfd, info_ptr); |
8373 | info_ptr += 4; | |
8374 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8375 | info_ptr += blk->size; | |
8376 | DW_BLOCK (attr) = blk; | |
8377 | break; | |
8378 | case DW_FORM_data2: | |
8379 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
8380 | info_ptr += 2; | |
8381 | break; | |
8382 | case DW_FORM_data4: | |
8383 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
8384 | info_ptr += 4; | |
8385 | break; | |
8386 | case DW_FORM_data8: | |
8387 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
8388 | info_ptr += 8; | |
8389 | break; | |
2dc7f7b3 TT |
8390 | case DW_FORM_sec_offset: |
8391 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
8392 | info_ptr += bytes_read; | |
8393 | break; | |
c906108c SS |
8394 | case DW_FORM_string: |
8395 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
8285870a | 8396 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
8397 | info_ptr += bytes_read; |
8398 | break; | |
4bdf3d34 JJ |
8399 | case DW_FORM_strp: |
8400 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
8401 | &bytes_read); | |
8285870a | 8402 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
8403 | info_ptr += bytes_read; |
8404 | break; | |
2dc7f7b3 | 8405 | case DW_FORM_exprloc: |
c906108c | 8406 | case DW_FORM_block: |
7b5a2f43 | 8407 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8408 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
8409 | info_ptr += bytes_read; | |
8410 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8411 | info_ptr += blk->size; | |
8412 | DW_BLOCK (attr) = blk; | |
8413 | break; | |
8414 | case DW_FORM_block1: | |
7b5a2f43 | 8415 | blk = dwarf_alloc_block (cu); |
c906108c SS |
8416 | blk->size = read_1_byte (abfd, info_ptr); |
8417 | info_ptr += 1; | |
8418 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
8419 | info_ptr += blk->size; | |
8420 | DW_BLOCK (attr) = blk; | |
8421 | break; | |
8422 | case DW_FORM_data1: | |
8423 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
8424 | info_ptr += 1; | |
8425 | break; | |
8426 | case DW_FORM_flag: | |
8427 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
8428 | info_ptr += 1; | |
8429 | break; | |
2dc7f7b3 TT |
8430 | case DW_FORM_flag_present: |
8431 | DW_UNSND (attr) = 1; | |
8432 | break; | |
c906108c SS |
8433 | case DW_FORM_sdata: |
8434 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
8435 | info_ptr += bytes_read; | |
8436 | break; | |
8437 | case DW_FORM_udata: | |
8438 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8439 | info_ptr += bytes_read; | |
8440 | break; | |
8441 | case DW_FORM_ref1: | |
10b3939b | 8442 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
8443 | info_ptr += 1; |
8444 | break; | |
8445 | case DW_FORM_ref2: | |
10b3939b | 8446 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
8447 | info_ptr += 2; |
8448 | break; | |
8449 | case DW_FORM_ref4: | |
10b3939b | 8450 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
8451 | info_ptr += 4; |
8452 | break; | |
613e1657 | 8453 | case DW_FORM_ref8: |
10b3939b | 8454 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
8455 | info_ptr += 8; |
8456 | break; | |
348e048f DE |
8457 | case DW_FORM_sig8: |
8458 | /* Convert the signature to something we can record in DW_UNSND | |
8459 | for later lookup. | |
8460 | NOTE: This is NULL if the type wasn't found. */ | |
8461 | DW_SIGNATURED_TYPE (attr) = | |
8462 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
8463 | info_ptr += 8; | |
8464 | break; | |
c906108c | 8465 | case DW_FORM_ref_udata: |
10b3939b DJ |
8466 | DW_ADDR (attr) = (cu->header.offset |
8467 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
8468 | info_ptr += bytes_read; |
8469 | break; | |
c906108c | 8470 | case DW_FORM_indirect: |
a8329558 KW |
8471 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
8472 | info_ptr += bytes_read; | |
e7c27a73 | 8473 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 8474 | break; |
c906108c | 8475 | default: |
8a3fe4f8 | 8476 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
8477 | dwarf_form_name (form), |
8478 | bfd_get_filename (abfd)); | |
c906108c | 8479 | } |
28e94949 JB |
8480 | |
8481 | /* We have seen instances where the compiler tried to emit a byte | |
8482 | size attribute of -1 which ended up being encoded as an unsigned | |
8483 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
8484 | an object of this size seems pretty unlikely so we can relatively | |
8485 | safely treat these cases as if the size attribute was invalid and | |
8486 | treat them as zero by default. */ | |
8487 | if (attr->name == DW_AT_byte_size | |
8488 | && form == DW_FORM_data4 | |
8489 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
8490 | { |
8491 | complaint | |
8492 | (&symfile_complaints, | |
43bbcdc2 PH |
8493 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
8494 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
8495 | DW_UNSND (attr) = 0; |
8496 | } | |
28e94949 | 8497 | |
c906108c SS |
8498 | return info_ptr; |
8499 | } | |
8500 | ||
a8329558 KW |
8501 | /* Read an attribute described by an abbreviated attribute. */ |
8502 | ||
fe1b8b76 | 8503 | static gdb_byte * |
a8329558 | 8504 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 8505 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
8506 | { |
8507 | attr->name = abbrev->name; | |
e7c27a73 | 8508 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
8509 | } |
8510 | ||
c906108c SS |
8511 | /* read dwarf information from a buffer */ |
8512 | ||
8513 | static unsigned int | |
fe1b8b76 | 8514 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 8515 | { |
fe1b8b76 | 8516 | return bfd_get_8 (abfd, buf); |
c906108c SS |
8517 | } |
8518 | ||
8519 | static int | |
fe1b8b76 | 8520 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 8521 | { |
fe1b8b76 | 8522 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
8523 | } |
8524 | ||
8525 | static unsigned int | |
fe1b8b76 | 8526 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8527 | { |
fe1b8b76 | 8528 | return bfd_get_16 (abfd, buf); |
c906108c SS |
8529 | } |
8530 | ||
8531 | static int | |
fe1b8b76 | 8532 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8533 | { |
fe1b8b76 | 8534 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
8535 | } |
8536 | ||
8537 | static unsigned int | |
fe1b8b76 | 8538 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8539 | { |
fe1b8b76 | 8540 | return bfd_get_32 (abfd, buf); |
c906108c SS |
8541 | } |
8542 | ||
8543 | static int | |
fe1b8b76 | 8544 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8545 | { |
fe1b8b76 | 8546 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
8547 | } |
8548 | ||
93311388 | 8549 | static ULONGEST |
fe1b8b76 | 8550 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 8551 | { |
fe1b8b76 | 8552 | return bfd_get_64 (abfd, buf); |
c906108c SS |
8553 | } |
8554 | ||
8555 | static CORE_ADDR | |
fe1b8b76 | 8556 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 8557 | unsigned int *bytes_read) |
c906108c | 8558 | { |
e7c27a73 | 8559 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
8560 | CORE_ADDR retval = 0; |
8561 | ||
107d2387 | 8562 | if (cu_header->signed_addr_p) |
c906108c | 8563 | { |
107d2387 AC |
8564 | switch (cu_header->addr_size) |
8565 | { | |
8566 | case 2: | |
fe1b8b76 | 8567 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
8568 | break; |
8569 | case 4: | |
fe1b8b76 | 8570 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
8571 | break; |
8572 | case 8: | |
fe1b8b76 | 8573 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
8574 | break; |
8575 | default: | |
8e65ff28 | 8576 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 8577 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 8578 | bfd_get_filename (abfd)); |
107d2387 AC |
8579 | } |
8580 | } | |
8581 | else | |
8582 | { | |
8583 | switch (cu_header->addr_size) | |
8584 | { | |
8585 | case 2: | |
fe1b8b76 | 8586 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
8587 | break; |
8588 | case 4: | |
fe1b8b76 | 8589 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
8590 | break; |
8591 | case 8: | |
fe1b8b76 | 8592 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
8593 | break; |
8594 | default: | |
8e65ff28 | 8595 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 8596 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 8597 | bfd_get_filename (abfd)); |
107d2387 | 8598 | } |
c906108c | 8599 | } |
64367e0a | 8600 | |
107d2387 AC |
8601 | *bytes_read = cu_header->addr_size; |
8602 | return retval; | |
c906108c SS |
8603 | } |
8604 | ||
f7ef9339 | 8605 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
8606 | specification allows the initial length to take up either 4 bytes |
8607 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
8608 | bytes describe the length and all offsets will be 8 bytes in length | |
8609 | instead of 4. | |
8610 | ||
f7ef9339 KB |
8611 | An older, non-standard 64-bit format is also handled by this |
8612 | function. The older format in question stores the initial length | |
8613 | as an 8-byte quantity without an escape value. Lengths greater | |
8614 | than 2^32 aren't very common which means that the initial 4 bytes | |
8615 | is almost always zero. Since a length value of zero doesn't make | |
8616 | sense for the 32-bit format, this initial zero can be considered to | |
8617 | be an escape value which indicates the presence of the older 64-bit | |
8618 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
8619 | greater than 4GB. If it becomes necessary to handle lengths |
8620 | somewhat larger than 4GB, we could allow other small values (such | |
8621 | as the non-sensical values of 1, 2, and 3) to also be used as | |
8622 | escape values indicating the presence of the old format. | |
f7ef9339 | 8623 | |
917c78fc MK |
8624 | The value returned via bytes_read should be used to increment the |
8625 | relevant pointer after calling read_initial_length(). | |
c764a876 | 8626 | |
613e1657 KB |
8627 | [ Note: read_initial_length() and read_offset() are based on the |
8628 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 8629 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
8630 | from: |
8631 | ||
f7ef9339 | 8632 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 8633 | |
613e1657 KB |
8634 | This document is only a draft and is subject to change. (So beware.) |
8635 | ||
f7ef9339 | 8636 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
8637 | determined empirically by examining 64-bit ELF files produced by |
8638 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
8639 | |
8640 | - Kevin, July 16, 2002 | |
613e1657 KB |
8641 | ] */ |
8642 | ||
8643 | static LONGEST | |
c764a876 | 8644 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 8645 | { |
fe1b8b76 | 8646 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 8647 | |
dd373385 | 8648 | if (length == 0xffffffff) |
613e1657 | 8649 | { |
fe1b8b76 | 8650 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 8651 | *bytes_read = 12; |
613e1657 | 8652 | } |
dd373385 | 8653 | else if (length == 0) |
f7ef9339 | 8654 | { |
dd373385 | 8655 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 8656 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 8657 | *bytes_read = 8; |
f7ef9339 | 8658 | } |
613e1657 KB |
8659 | else |
8660 | { | |
8661 | *bytes_read = 4; | |
613e1657 KB |
8662 | } |
8663 | ||
c764a876 DE |
8664 | return length; |
8665 | } | |
dd373385 | 8666 | |
c764a876 DE |
8667 | /* Cover function for read_initial_length. |
8668 | Returns the length of the object at BUF, and stores the size of the | |
8669 | initial length in *BYTES_READ and stores the size that offsets will be in | |
8670 | *OFFSET_SIZE. | |
8671 | If the initial length size is not equivalent to that specified in | |
8672 | CU_HEADER then issue a complaint. | |
8673 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 8674 | |
c764a876 DE |
8675 | static LONGEST |
8676 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
8677 | const struct comp_unit_head *cu_header, | |
8678 | unsigned int *bytes_read, | |
8679 | unsigned int *offset_size) | |
8680 | { | |
8681 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
8682 | ||
8683 | gdb_assert (cu_header->initial_length_size == 4 | |
8684 | || cu_header->initial_length_size == 8 | |
8685 | || cu_header->initial_length_size == 12); | |
8686 | ||
8687 | if (cu_header->initial_length_size != *bytes_read) | |
8688 | complaint (&symfile_complaints, | |
8689 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 8690 | |
c764a876 | 8691 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 8692 | return length; |
613e1657 KB |
8693 | } |
8694 | ||
8695 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 8696 | given by cu_header->offset_size. */ |
613e1657 KB |
8697 | |
8698 | static LONGEST | |
fe1b8b76 | 8699 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 8700 | unsigned int *bytes_read) |
c764a876 DE |
8701 | { |
8702 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 8703 | |
c764a876 DE |
8704 | *bytes_read = cu_header->offset_size; |
8705 | return offset; | |
8706 | } | |
8707 | ||
8708 | /* Read an offset from the data stream. */ | |
8709 | ||
8710 | static LONGEST | |
8711 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
8712 | { |
8713 | LONGEST retval = 0; | |
8714 | ||
c764a876 | 8715 | switch (offset_size) |
613e1657 KB |
8716 | { |
8717 | case 4: | |
fe1b8b76 | 8718 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
8719 | break; |
8720 | case 8: | |
fe1b8b76 | 8721 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
8722 | break; |
8723 | default: | |
8e65ff28 | 8724 | internal_error (__FILE__, __LINE__, |
c764a876 | 8725 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 8726 | bfd_get_filename (abfd)); |
613e1657 KB |
8727 | } |
8728 | ||
917c78fc | 8729 | return retval; |
613e1657 KB |
8730 | } |
8731 | ||
fe1b8b76 JB |
8732 | static gdb_byte * |
8733 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
8734 | { |
8735 | /* If the size of a host char is 8 bits, we can return a pointer | |
8736 | to the buffer, otherwise we have to copy the data to a buffer | |
8737 | allocated on the temporary obstack. */ | |
4bdf3d34 | 8738 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 8739 | return buf; |
c906108c SS |
8740 | } |
8741 | ||
8742 | static char * | |
fe1b8b76 | 8743 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
8744 | { |
8745 | /* If the size of a host char is 8 bits, we can return a pointer | |
8746 | to the string, otherwise we have to copy the string to a buffer | |
8747 | allocated on the temporary obstack. */ | |
4bdf3d34 | 8748 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
8749 | if (*buf == '\0') |
8750 | { | |
8751 | *bytes_read_ptr = 1; | |
8752 | return NULL; | |
8753 | } | |
fe1b8b76 JB |
8754 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
8755 | return (char *) buf; | |
4bdf3d34 JJ |
8756 | } |
8757 | ||
8758 | static char * | |
fe1b8b76 | 8759 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
8760 | const struct comp_unit_head *cu_header, |
8761 | unsigned int *bytes_read_ptr) | |
8762 | { | |
c764a876 | 8763 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 8764 | |
be391dca | 8765 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 8766 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 8767 | { |
8a3fe4f8 | 8768 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 8769 | bfd_get_filename (abfd)); |
4bdf3d34 | 8770 | return NULL; |
c906108c | 8771 | } |
dce234bc | 8772 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 8773 | { |
8a3fe4f8 | 8774 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 8775 | bfd_get_filename (abfd)); |
c906108c SS |
8776 | return NULL; |
8777 | } | |
4bdf3d34 | 8778 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 8779 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 8780 | return NULL; |
dce234bc | 8781 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
8782 | } |
8783 | ||
ce5d95e1 | 8784 | static unsigned long |
fe1b8b76 | 8785 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 8786 | { |
ce5d95e1 JB |
8787 | unsigned long result; |
8788 | unsigned int num_read; | |
c906108c SS |
8789 | int i, shift; |
8790 | unsigned char byte; | |
8791 | ||
8792 | result = 0; | |
8793 | shift = 0; | |
8794 | num_read = 0; | |
8795 | i = 0; | |
8796 | while (1) | |
8797 | { | |
fe1b8b76 | 8798 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
8799 | buf++; |
8800 | num_read++; | |
ce5d95e1 | 8801 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
8802 | if ((byte & 128) == 0) |
8803 | { | |
8804 | break; | |
8805 | } | |
8806 | shift += 7; | |
8807 | } | |
8808 | *bytes_read_ptr = num_read; | |
8809 | return result; | |
8810 | } | |
8811 | ||
ce5d95e1 | 8812 | static long |
fe1b8b76 | 8813 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 8814 | { |
ce5d95e1 | 8815 | long result; |
77e0b926 | 8816 | int i, shift, num_read; |
c906108c SS |
8817 | unsigned char byte; |
8818 | ||
8819 | result = 0; | |
8820 | shift = 0; | |
c906108c SS |
8821 | num_read = 0; |
8822 | i = 0; | |
8823 | while (1) | |
8824 | { | |
fe1b8b76 | 8825 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
8826 | buf++; |
8827 | num_read++; | |
ce5d95e1 | 8828 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
8829 | shift += 7; |
8830 | if ((byte & 128) == 0) | |
8831 | { | |
8832 | break; | |
8833 | } | |
8834 | } | |
77e0b926 DJ |
8835 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
8836 | result |= -(((long)1) << shift); | |
c906108c SS |
8837 | *bytes_read_ptr = num_read; |
8838 | return result; | |
8839 | } | |
8840 | ||
4bb7a0a7 DJ |
8841 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
8842 | ||
fe1b8b76 JB |
8843 | static gdb_byte * |
8844 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
8845 | { |
8846 | int byte; | |
8847 | ||
8848 | while (1) | |
8849 | { | |
fe1b8b76 | 8850 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
8851 | buf++; |
8852 | if ((byte & 128) == 0) | |
8853 | return buf; | |
8854 | } | |
8855 | } | |
8856 | ||
c906108c | 8857 | static void |
e142c38c | 8858 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
8859 | { |
8860 | switch (lang) | |
8861 | { | |
8862 | case DW_LANG_C89: | |
76bee0cc | 8863 | case DW_LANG_C99: |
c906108c | 8864 | case DW_LANG_C: |
e142c38c | 8865 | cu->language = language_c; |
c906108c SS |
8866 | break; |
8867 | case DW_LANG_C_plus_plus: | |
e142c38c | 8868 | cu->language = language_cplus; |
c906108c | 8869 | break; |
6aecb9c2 JB |
8870 | case DW_LANG_D: |
8871 | cu->language = language_d; | |
8872 | break; | |
c906108c SS |
8873 | case DW_LANG_Fortran77: |
8874 | case DW_LANG_Fortran90: | |
b21b22e0 | 8875 | case DW_LANG_Fortran95: |
e142c38c | 8876 | cu->language = language_fortran; |
c906108c SS |
8877 | break; |
8878 | case DW_LANG_Mips_Assembler: | |
e142c38c | 8879 | cu->language = language_asm; |
c906108c | 8880 | break; |
bebd888e | 8881 | case DW_LANG_Java: |
e142c38c | 8882 | cu->language = language_java; |
bebd888e | 8883 | break; |
c906108c | 8884 | case DW_LANG_Ada83: |
8aaf0b47 | 8885 | case DW_LANG_Ada95: |
bc5f45f8 JB |
8886 | cu->language = language_ada; |
8887 | break; | |
72019c9c GM |
8888 | case DW_LANG_Modula2: |
8889 | cu->language = language_m2; | |
8890 | break; | |
fe8e67fd PM |
8891 | case DW_LANG_Pascal83: |
8892 | cu->language = language_pascal; | |
8893 | break; | |
22566fbd DJ |
8894 | case DW_LANG_ObjC: |
8895 | cu->language = language_objc; | |
8896 | break; | |
c906108c SS |
8897 | case DW_LANG_Cobol74: |
8898 | case DW_LANG_Cobol85: | |
c906108c | 8899 | default: |
e142c38c | 8900 | cu->language = language_minimal; |
c906108c SS |
8901 | break; |
8902 | } | |
e142c38c | 8903 | cu->language_defn = language_def (cu->language); |
c906108c SS |
8904 | } |
8905 | ||
8906 | /* Return the named attribute or NULL if not there. */ | |
8907 | ||
8908 | static struct attribute * | |
e142c38c | 8909 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
8910 | { |
8911 | unsigned int i; | |
8912 | struct attribute *spec = NULL; | |
8913 | ||
8914 | for (i = 0; i < die->num_attrs; ++i) | |
8915 | { | |
8916 | if (die->attrs[i].name == name) | |
10b3939b | 8917 | return &die->attrs[i]; |
c906108c SS |
8918 | if (die->attrs[i].name == DW_AT_specification |
8919 | || die->attrs[i].name == DW_AT_abstract_origin) | |
8920 | spec = &die->attrs[i]; | |
8921 | } | |
c906108c | 8922 | |
10b3939b | 8923 | if (spec) |
f2f0e013 DJ |
8924 | { |
8925 | die = follow_die_ref (die, spec, &cu); | |
8926 | return dwarf2_attr (die, name, cu); | |
8927 | } | |
c5aa993b | 8928 | |
c906108c SS |
8929 | return NULL; |
8930 | } | |
8931 | ||
348e048f DE |
8932 | /* Return the named attribute or NULL if not there, |
8933 | but do not follow DW_AT_specification, etc. | |
8934 | This is for use in contexts where we're reading .debug_types dies. | |
8935 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
8936 | back up the chain, and we want to go down. */ | |
8937 | ||
8938 | static struct attribute * | |
8939 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
8940 | struct dwarf2_cu *cu) | |
8941 | { | |
8942 | unsigned int i; | |
8943 | ||
8944 | for (i = 0; i < die->num_attrs; ++i) | |
8945 | if (die->attrs[i].name == name) | |
8946 | return &die->attrs[i]; | |
8947 | ||
8948 | return NULL; | |
8949 | } | |
8950 | ||
05cf31d1 JB |
8951 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
8952 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 8953 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
8954 | |
8955 | static int | |
8956 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
8957 | { | |
8958 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
8959 | ||
8960 | return (attr && DW_UNSND (attr)); | |
8961 | } | |
8962 | ||
3ca72b44 | 8963 | static int |
e142c38c | 8964 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 8965 | { |
05cf31d1 JB |
8966 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
8967 | which value is non-zero. However, we have to be careful with | |
8968 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
8969 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
8970 | end up accidently finding a declaration attribute that belongs | |
8971 | to a different DIE referenced by the specification attribute, | |
8972 | even though the given DIE does not have a declaration attribute. */ | |
8973 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
8974 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
8975 | } |
8976 | ||
63d06c5c | 8977 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 8978 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
8979 | containing the return value on output. If there is no |
8980 | specification, but there is an abstract origin, that is | |
8981 | returned. */ | |
63d06c5c DC |
8982 | |
8983 | static struct die_info * | |
f2f0e013 | 8984 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 8985 | { |
f2f0e013 DJ |
8986 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
8987 | *spec_cu); | |
63d06c5c | 8988 | |
edb3359d DJ |
8989 | if (spec_attr == NULL) |
8990 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
8991 | ||
63d06c5c DC |
8992 | if (spec_attr == NULL) |
8993 | return NULL; | |
8994 | else | |
f2f0e013 | 8995 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 8996 | } |
c906108c | 8997 | |
debd256d JB |
8998 | /* Free the line_header structure *LH, and any arrays and strings it |
8999 | refers to. */ | |
9000 | static void | |
9001 | free_line_header (struct line_header *lh) | |
9002 | { | |
9003 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 9004 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
9005 | |
9006 | /* Remember that all the lh->file_names[i].name pointers are | |
9007 | pointers into debug_line_buffer, and don't need to be freed. */ | |
9008 | if (lh->file_names) | |
a8bc7b56 | 9009 | xfree (lh->file_names); |
debd256d JB |
9010 | |
9011 | /* Similarly for the include directory names. */ | |
9012 | if (lh->include_dirs) | |
a8bc7b56 | 9013 | xfree (lh->include_dirs); |
debd256d | 9014 | |
a8bc7b56 | 9015 | xfree (lh); |
debd256d JB |
9016 | } |
9017 | ||
9018 | ||
9019 | /* Add an entry to LH's include directory table. */ | |
9020 | static void | |
9021 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 9022 | { |
debd256d JB |
9023 | /* Grow the array if necessary. */ |
9024 | if (lh->include_dirs_size == 0) | |
c5aa993b | 9025 | { |
debd256d JB |
9026 | lh->include_dirs_size = 1; /* for testing */ |
9027 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
9028 | * sizeof (*lh->include_dirs)); | |
9029 | } | |
9030 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
9031 | { | |
9032 | lh->include_dirs_size *= 2; | |
9033 | lh->include_dirs = xrealloc (lh->include_dirs, | |
9034 | (lh->include_dirs_size | |
9035 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 9036 | } |
c906108c | 9037 | |
debd256d JB |
9038 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
9039 | } | |
6e70227d | 9040 | |
debd256d JB |
9041 | |
9042 | /* Add an entry to LH's file name table. */ | |
9043 | static void | |
9044 | add_file_name (struct line_header *lh, | |
9045 | char *name, | |
9046 | unsigned int dir_index, | |
9047 | unsigned int mod_time, | |
9048 | unsigned int length) | |
9049 | { | |
9050 | struct file_entry *fe; | |
9051 | ||
9052 | /* Grow the array if necessary. */ | |
9053 | if (lh->file_names_size == 0) | |
9054 | { | |
9055 | lh->file_names_size = 1; /* for testing */ | |
9056 | lh->file_names = xmalloc (lh->file_names_size | |
9057 | * sizeof (*lh->file_names)); | |
9058 | } | |
9059 | else if (lh->num_file_names >= lh->file_names_size) | |
9060 | { | |
9061 | lh->file_names_size *= 2; | |
9062 | lh->file_names = xrealloc (lh->file_names, | |
9063 | (lh->file_names_size | |
9064 | * sizeof (*lh->file_names))); | |
9065 | } | |
9066 | ||
9067 | fe = &lh->file_names[lh->num_file_names++]; | |
9068 | fe->name = name; | |
9069 | fe->dir_index = dir_index; | |
9070 | fe->mod_time = mod_time; | |
9071 | fe->length = length; | |
aaa75496 | 9072 | fe->included_p = 0; |
cb1df416 | 9073 | fe->symtab = NULL; |
debd256d | 9074 | } |
6e70227d | 9075 | |
debd256d JB |
9076 | |
9077 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
9078 | .debug_line, according to the endianness of ABFD. Return a pointer |
9079 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
9080 | |
9081 | NOTE: the strings in the include directory and file name tables of | |
9082 | the returned object point into debug_line_buffer, and must not be | |
9083 | freed. */ | |
9084 | static struct line_header * | |
9085 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 9086 | struct dwarf2_cu *cu) |
debd256d JB |
9087 | { |
9088 | struct cleanup *back_to; | |
9089 | struct line_header *lh; | |
fe1b8b76 | 9090 | gdb_byte *line_ptr; |
c764a876 | 9091 | unsigned int bytes_read, offset_size; |
debd256d JB |
9092 | int i; |
9093 | char *cur_dir, *cur_file; | |
9094 | ||
be391dca | 9095 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 9096 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 9097 | { |
e2e0b3e5 | 9098 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
9099 | return 0; |
9100 | } | |
9101 | ||
a738430d MK |
9102 | /* Make sure that at least there's room for the total_length field. |
9103 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 9104 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 9105 | { |
4d3c2250 | 9106 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9107 | return 0; |
9108 | } | |
9109 | ||
9110 | lh = xmalloc (sizeof (*lh)); | |
9111 | memset (lh, 0, sizeof (*lh)); | |
9112 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
9113 | (void *) lh); | |
9114 | ||
dce234bc | 9115 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 9116 | |
a738430d | 9117 | /* Read in the header. */ |
6e70227d | 9118 | lh->total_length = |
c764a876 DE |
9119 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
9120 | &bytes_read, &offset_size); | |
debd256d | 9121 | line_ptr += bytes_read; |
dce234bc PP |
9122 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
9123 | + dwarf2_per_objfile->line.size)) | |
debd256d | 9124 | { |
4d3c2250 | 9125 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9126 | return 0; |
9127 | } | |
9128 | lh->statement_program_end = line_ptr + lh->total_length; | |
9129 | lh->version = read_2_bytes (abfd, line_ptr); | |
9130 | line_ptr += 2; | |
c764a876 DE |
9131 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
9132 | line_ptr += offset_size; | |
debd256d JB |
9133 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
9134 | line_ptr += 1; | |
2dc7f7b3 TT |
9135 | if (lh->version >= 4) |
9136 | { | |
9137 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
9138 | line_ptr += 1; | |
9139 | } | |
9140 | else | |
9141 | lh->maximum_ops_per_instruction = 1; | |
9142 | ||
9143 | if (lh->maximum_ops_per_instruction == 0) | |
9144 | { | |
9145 | lh->maximum_ops_per_instruction = 1; | |
9146 | complaint (&symfile_complaints, | |
9147 | _("invalid maximum_ops_per_instruction in `.debug_line' section")); | |
9148 | } | |
9149 | ||
debd256d JB |
9150 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
9151 | line_ptr += 1; | |
9152 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
9153 | line_ptr += 1; | |
9154 | lh->line_range = read_1_byte (abfd, line_ptr); | |
9155 | line_ptr += 1; | |
9156 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
9157 | line_ptr += 1; | |
9158 | lh->standard_opcode_lengths | |
fe1b8b76 | 9159 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
9160 | |
9161 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
9162 | for (i = 1; i < lh->opcode_base; ++i) | |
9163 | { | |
9164 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
9165 | line_ptr += 1; | |
9166 | } | |
9167 | ||
a738430d | 9168 | /* Read directory table. */ |
debd256d JB |
9169 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
9170 | { | |
9171 | line_ptr += bytes_read; | |
9172 | add_include_dir (lh, cur_dir); | |
9173 | } | |
9174 | line_ptr += bytes_read; | |
9175 | ||
a738430d | 9176 | /* Read file name table. */ |
debd256d JB |
9177 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
9178 | { | |
9179 | unsigned int dir_index, mod_time, length; | |
9180 | ||
9181 | line_ptr += bytes_read; | |
9182 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9183 | line_ptr += bytes_read; | |
9184 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9185 | line_ptr += bytes_read; | |
9186 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9187 | line_ptr += bytes_read; | |
9188 | ||
9189 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9190 | } | |
9191 | line_ptr += bytes_read; | |
6e70227d | 9192 | lh->statement_program_start = line_ptr; |
debd256d | 9193 | |
dce234bc PP |
9194 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
9195 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 9196 | complaint (&symfile_complaints, |
e2e0b3e5 | 9197 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
9198 | |
9199 | discard_cleanups (back_to); | |
9200 | return lh; | |
9201 | } | |
c906108c | 9202 | |
5fb290d7 DJ |
9203 | /* This function exists to work around a bug in certain compilers |
9204 | (particularly GCC 2.95), in which the first line number marker of a | |
9205 | function does not show up until after the prologue, right before | |
9206 | the second line number marker. This function shifts ADDRESS down | |
9207 | to the beginning of the function if necessary, and is called on | |
9208 | addresses passed to record_line. */ | |
9209 | ||
9210 | static CORE_ADDR | |
e142c38c | 9211 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
9212 | { |
9213 | struct function_range *fn; | |
9214 | ||
9215 | /* Find the function_range containing address. */ | |
e142c38c | 9216 | if (!cu->first_fn) |
5fb290d7 DJ |
9217 | return address; |
9218 | ||
e142c38c DJ |
9219 | if (!cu->cached_fn) |
9220 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 9221 | |
e142c38c | 9222 | fn = cu->cached_fn; |
5fb290d7 DJ |
9223 | while (fn) |
9224 | if (fn->lowpc <= address && fn->highpc > address) | |
9225 | goto found; | |
9226 | else | |
9227 | fn = fn->next; | |
9228 | ||
e142c38c DJ |
9229 | fn = cu->first_fn; |
9230 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
9231 | if (fn->lowpc <= address && fn->highpc > address) |
9232 | goto found; | |
9233 | else | |
9234 | fn = fn->next; | |
9235 | ||
9236 | return address; | |
9237 | ||
9238 | found: | |
9239 | if (fn->seen_line) | |
9240 | return address; | |
9241 | if (address != fn->lowpc) | |
4d3c2250 | 9242 | complaint (&symfile_complaints, |
e2e0b3e5 | 9243 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 9244 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
9245 | fn->seen_line = 1; |
9246 | return fn->lowpc; | |
9247 | } | |
9248 | ||
aaa75496 JB |
9249 | /* Decode the Line Number Program (LNP) for the given line_header |
9250 | structure and CU. The actual information extracted and the type | |
9251 | of structures created from the LNP depends on the value of PST. | |
9252 | ||
9253 | 1. If PST is NULL, then this procedure uses the data from the program | |
9254 | to create all necessary symbol tables, and their linetables. | |
9255 | The compilation directory of the file is passed in COMP_DIR, | |
9256 | and must not be NULL. | |
6e70227d | 9257 | |
aaa75496 JB |
9258 | 2. If PST is not NULL, this procedure reads the program to determine |
9259 | the list of files included by the unit represented by PST, and | |
9260 | builds all the associated partial symbol tables. In this case, | |
9261 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
9262 | is not used to compute the full name of the symtab, and therefore | |
9263 | omitting it when building the partial symtab does not introduce | |
9264 | the potential for inconsistency - a partial symtab and its associated | |
9265 | symbtab having a different fullname -). */ | |
debd256d | 9266 | |
c906108c | 9267 | static void |
debd256d | 9268 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 9269 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 9270 | { |
a8c50c1f | 9271 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 9272 | gdb_byte *line_end; |
a8c50c1f | 9273 | unsigned int bytes_read, extended_len; |
c906108c | 9274 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
9275 | CORE_ADDR baseaddr; |
9276 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 9277 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 9278 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 9279 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
9280 | |
9281 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 9282 | |
debd256d JB |
9283 | line_ptr = lh->statement_program_start; |
9284 | line_end = lh->statement_program_end; | |
c906108c SS |
9285 | |
9286 | /* Read the statement sequences until there's nothing left. */ | |
9287 | while (line_ptr < line_end) | |
9288 | { | |
9289 | /* state machine registers */ | |
9290 | CORE_ADDR address = 0; | |
9291 | unsigned int file = 1; | |
9292 | unsigned int line = 1; | |
9293 | unsigned int column = 0; | |
debd256d | 9294 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
9295 | int basic_block = 0; |
9296 | int end_sequence = 0; | |
fbf65064 | 9297 | CORE_ADDR addr; |
2dc7f7b3 | 9298 | unsigned char op_index = 0; |
c906108c | 9299 | |
aaa75496 | 9300 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 9301 | { |
aaa75496 | 9302 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
9303 | /* lh->include_dirs and lh->file_names are 0-based, but the |
9304 | directory and file name numbers in the statement program | |
9305 | are 1-based. */ | |
9306 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 9307 | char *dir = NULL; |
a738430d | 9308 | |
debd256d JB |
9309 | if (fe->dir_index) |
9310 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
9311 | |
9312 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
9313 | } |
9314 | ||
a738430d | 9315 | /* Decode the table. */ |
c5aa993b | 9316 | while (!end_sequence) |
c906108c SS |
9317 | { |
9318 | op_code = read_1_byte (abfd, line_ptr); | |
9319 | line_ptr += 1; | |
59205f5a JB |
9320 | if (line_ptr > line_end) |
9321 | { | |
9322 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
9323 | break; | |
9324 | } | |
9aa1fe7e | 9325 | |
debd256d | 9326 | if (op_code >= lh->opcode_base) |
6e70227d | 9327 | { |
a738430d | 9328 | /* Special operand. */ |
debd256d | 9329 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
9330 | address += (((op_index + (adj_opcode / lh->line_range)) |
9331 | / lh->maximum_ops_per_instruction) | |
9332 | * lh->minimum_instruction_length); | |
9333 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
9334 | % lh->maximum_ops_per_instruction); | |
debd256d | 9335 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 9336 | if (lh->num_file_names < file || file == 0) |
25e43795 | 9337 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
9338 | /* For now we ignore lines not starting on an |
9339 | instruction boundary. */ | |
9340 | else if (op_index == 0) | |
25e43795 DJ |
9341 | { |
9342 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 9343 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
9344 | { |
9345 | if (last_subfile != current_subfile) | |
9346 | { | |
9347 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9348 | if (last_subfile) | |
9349 | record_line (last_subfile, 0, addr); | |
9350 | last_subfile = current_subfile; | |
9351 | } | |
25e43795 | 9352 | /* Append row to matrix using current values. */ |
fbf65064 UW |
9353 | addr = check_cu_functions (address, cu); |
9354 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
9355 | record_line (current_subfile, line, addr); | |
366da635 | 9356 | } |
25e43795 | 9357 | } |
ca5f395d | 9358 | basic_block = 0; |
9aa1fe7e GK |
9359 | } |
9360 | else switch (op_code) | |
c906108c SS |
9361 | { |
9362 | case DW_LNS_extended_op: | |
a8c50c1f | 9363 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 9364 | line_ptr += bytes_read; |
a8c50c1f | 9365 | extended_end = line_ptr + extended_len; |
c906108c SS |
9366 | extended_op = read_1_byte (abfd, line_ptr); |
9367 | line_ptr += 1; | |
9368 | switch (extended_op) | |
9369 | { | |
9370 | case DW_LNE_end_sequence: | |
9371 | end_sequence = 1; | |
c906108c SS |
9372 | break; |
9373 | case DW_LNE_set_address: | |
e7c27a73 | 9374 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
2dc7f7b3 | 9375 | op_index = 0; |
107d2387 AC |
9376 | line_ptr += bytes_read; |
9377 | address += baseaddr; | |
c906108c SS |
9378 | break; |
9379 | case DW_LNE_define_file: | |
debd256d JB |
9380 | { |
9381 | char *cur_file; | |
9382 | unsigned int dir_index, mod_time, length; | |
6e70227d | 9383 | |
debd256d JB |
9384 | cur_file = read_string (abfd, line_ptr, &bytes_read); |
9385 | line_ptr += bytes_read; | |
9386 | dir_index = | |
9387 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9388 | line_ptr += bytes_read; | |
9389 | mod_time = | |
9390 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9391 | line_ptr += bytes_read; | |
9392 | length = | |
9393 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9394 | line_ptr += bytes_read; | |
9395 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9396 | } | |
c906108c | 9397 | break; |
d0c6ba3d CC |
9398 | case DW_LNE_set_discriminator: |
9399 | /* The discriminator is not interesting to the debugger; | |
9400 | just ignore it. */ | |
9401 | line_ptr = extended_end; | |
9402 | break; | |
c906108c | 9403 | default: |
4d3c2250 | 9404 | complaint (&symfile_complaints, |
e2e0b3e5 | 9405 | _("mangled .debug_line section")); |
debd256d | 9406 | return; |
c906108c | 9407 | } |
a8c50c1f DJ |
9408 | /* Make sure that we parsed the extended op correctly. If e.g. |
9409 | we expected a different address size than the producer used, | |
9410 | we may have read the wrong number of bytes. */ | |
9411 | if (line_ptr != extended_end) | |
9412 | { | |
9413 | complaint (&symfile_complaints, | |
9414 | _("mangled .debug_line section")); | |
9415 | return; | |
9416 | } | |
c906108c SS |
9417 | break; |
9418 | case DW_LNS_copy: | |
59205f5a | 9419 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
9420 | dwarf2_debug_line_missing_file_complaint (); |
9421 | else | |
366da635 | 9422 | { |
25e43795 | 9423 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 9424 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
9425 | { |
9426 | if (last_subfile != current_subfile) | |
9427 | { | |
9428 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9429 | if (last_subfile) | |
9430 | record_line (last_subfile, 0, addr); | |
9431 | last_subfile = current_subfile; | |
9432 | } | |
9433 | addr = check_cu_functions (address, cu); | |
9434 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
9435 | record_line (current_subfile, line, addr); | |
9436 | } | |
366da635 | 9437 | } |
c906108c SS |
9438 | basic_block = 0; |
9439 | break; | |
9440 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
9441 | { |
9442 | CORE_ADDR adjust | |
9443 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9444 | ||
9445 | address += (((op_index + adjust) | |
9446 | / lh->maximum_ops_per_instruction) | |
9447 | * lh->minimum_instruction_length); | |
9448 | op_index = ((op_index + adjust) | |
9449 | % lh->maximum_ops_per_instruction); | |
9450 | line_ptr += bytes_read; | |
9451 | } | |
c906108c SS |
9452 | break; |
9453 | case DW_LNS_advance_line: | |
9454 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
9455 | line_ptr += bytes_read; | |
9456 | break; | |
9457 | case DW_LNS_set_file: | |
debd256d | 9458 | { |
a738430d MK |
9459 | /* The arrays lh->include_dirs and lh->file_names are |
9460 | 0-based, but the directory and file name numbers in | |
9461 | the statement program are 1-based. */ | |
debd256d | 9462 | struct file_entry *fe; |
4f1520fb | 9463 | char *dir = NULL; |
a738430d | 9464 | |
debd256d JB |
9465 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
9466 | line_ptr += bytes_read; | |
59205f5a | 9467 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
9468 | dwarf2_debug_line_missing_file_complaint (); |
9469 | else | |
9470 | { | |
9471 | fe = &lh->file_names[file - 1]; | |
9472 | if (fe->dir_index) | |
9473 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9474 | if (!decode_for_pst_p) | |
9475 | { | |
9476 | last_subfile = current_subfile; | |
9477 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
9478 | } | |
9479 | } | |
debd256d | 9480 | } |
c906108c SS |
9481 | break; |
9482 | case DW_LNS_set_column: | |
9483 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9484 | line_ptr += bytes_read; | |
9485 | break; | |
9486 | case DW_LNS_negate_stmt: | |
9487 | is_stmt = (!is_stmt); | |
9488 | break; | |
9489 | case DW_LNS_set_basic_block: | |
9490 | basic_block = 1; | |
9491 | break; | |
c2c6d25f JM |
9492 | /* Add to the address register of the state machine the |
9493 | address increment value corresponding to special opcode | |
a738430d MK |
9494 | 255. I.e., this value is scaled by the minimum |
9495 | instruction length since special opcode 255 would have | |
9496 | scaled the the increment. */ | |
c906108c | 9497 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
9498 | { |
9499 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
9500 | ||
9501 | address += (((op_index + adjust) | |
9502 | / lh->maximum_ops_per_instruction) | |
9503 | * lh->minimum_instruction_length); | |
9504 | op_index = ((op_index + adjust) | |
9505 | % lh->maximum_ops_per_instruction); | |
9506 | } | |
c906108c SS |
9507 | break; |
9508 | case DW_LNS_fixed_advance_pc: | |
9509 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 9510 | op_index = 0; |
c906108c SS |
9511 | line_ptr += 2; |
9512 | break; | |
9aa1fe7e | 9513 | default: |
a738430d MK |
9514 | { |
9515 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 9516 | int i; |
a738430d | 9517 | |
debd256d | 9518 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
9519 | { |
9520 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9521 | line_ptr += bytes_read; | |
9522 | } | |
9523 | } | |
c906108c SS |
9524 | } |
9525 | } | |
59205f5a JB |
9526 | if (lh->num_file_names < file || file == 0) |
9527 | dwarf2_debug_line_missing_file_complaint (); | |
9528 | else | |
9529 | { | |
9530 | lh->file_names[file - 1].included_p = 1; | |
9531 | if (!decode_for_pst_p) | |
fbf65064 UW |
9532 | { |
9533 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
9534 | record_line (current_subfile, 0, addr); | |
9535 | } | |
59205f5a | 9536 | } |
c906108c | 9537 | } |
aaa75496 JB |
9538 | |
9539 | if (decode_for_pst_p) | |
9540 | { | |
9541 | int file_index; | |
9542 | ||
9543 | /* Now that we're done scanning the Line Header Program, we can | |
9544 | create the psymtab of each included file. */ | |
9545 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
9546 | if (lh->file_names[file_index].included_p == 1) | |
9547 | { | |
5b5464ad JB |
9548 | const struct file_entry fe = lh->file_names [file_index]; |
9549 | char *include_name = fe.name; | |
9550 | char *dir_name = NULL; | |
9551 | char *pst_filename = pst->filename; | |
9552 | ||
9553 | if (fe.dir_index) | |
9554 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
9555 | ||
9556 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
9557 | { | |
1754f103 MK |
9558 | include_name = concat (dir_name, SLASH_STRING, |
9559 | include_name, (char *)NULL); | |
5b5464ad JB |
9560 | make_cleanup (xfree, include_name); |
9561 | } | |
9562 | ||
9563 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
9564 | { | |
1754f103 MK |
9565 | pst_filename = concat (pst->dirname, SLASH_STRING, |
9566 | pst_filename, (char *)NULL); | |
5b5464ad JB |
9567 | make_cleanup (xfree, pst_filename); |
9568 | } | |
9569 | ||
9570 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
9571 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
9572 | } | |
9573 | } | |
cb1df416 DJ |
9574 | else |
9575 | { | |
9576 | /* Make sure a symtab is created for every file, even files | |
9577 | which contain only variables (i.e. no code with associated | |
9578 | line numbers). */ | |
9579 | ||
9580 | int i; | |
9581 | struct file_entry *fe; | |
9582 | ||
9583 | for (i = 0; i < lh->num_file_names; i++) | |
9584 | { | |
9585 | char *dir = NULL; | |
9a619af0 | 9586 | |
cb1df416 DJ |
9587 | fe = &lh->file_names[i]; |
9588 | if (fe->dir_index) | |
9589 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9590 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
9591 | ||
9592 | /* Skip the main file; we don't need it, and it must be | |
9593 | allocated last, so that it will show up before the | |
9594 | non-primary symtabs in the objfile's symtab list. */ | |
9595 | if (current_subfile == first_subfile) | |
9596 | continue; | |
9597 | ||
9598 | if (current_subfile->symtab == NULL) | |
9599 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
9600 | cu->objfile); | |
9601 | fe->symtab = current_subfile->symtab; | |
9602 | } | |
9603 | } | |
c906108c SS |
9604 | } |
9605 | ||
9606 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
9607 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
9608 | or NULL if not known. COMP_DIR is the compilation directory for the |
9609 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
9610 | This routine tries to keep line numbers from identical absolute and |
9611 | relative file names in a common subfile. | |
9612 | ||
9613 | Using the `list' example from the GDB testsuite, which resides in | |
9614 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
9615 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
9616 | ||
c5aa993b JM |
9617 | DW_AT_name: /srcdir/list0.c |
9618 | DW_AT_comp_dir: /compdir | |
357e46e7 | 9619 | files.files[0].name: list0.h |
c5aa993b | 9620 | files.files[0].dir: /srcdir |
357e46e7 | 9621 | files.files[1].name: list0.c |
c5aa993b | 9622 | files.files[1].dir: /srcdir |
c906108c SS |
9623 | |
9624 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
9625 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
9626 | start_subfile will ensure that this happens provided that we pass the | |
9627 | concatenation of files.files[1].dir and files.files[1].name as the | |
9628 | subfile's name. */ | |
c906108c SS |
9629 | |
9630 | static void | |
4f1520fb | 9631 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 9632 | { |
4f1520fb FR |
9633 | char *fullname; |
9634 | ||
9635 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
9636 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
9637 | second argument to start_subfile. To be consistent, we do the | |
9638 | same here. In order not to lose the line information directory, | |
9639 | we concatenate it to the filename when it makes sense. | |
9640 | Note that the Dwarf3 standard says (speaking of filenames in line | |
9641 | information): ``The directory index is ignored for file names | |
9642 | that represent full path names''. Thus ignoring dirname in the | |
9643 | `else' branch below isn't an issue. */ | |
c906108c | 9644 | |
d5166ae1 | 9645 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
9646 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
9647 | else | |
9648 | fullname = filename; | |
c906108c | 9649 | |
4f1520fb FR |
9650 | start_subfile (fullname, comp_dir); |
9651 | ||
9652 | if (fullname != filename) | |
9653 | xfree (fullname); | |
c906108c SS |
9654 | } |
9655 | ||
4c2df51b DJ |
9656 | static void |
9657 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9658 | struct dwarf2_cu *cu) |
4c2df51b | 9659 | { |
e7c27a73 DJ |
9660 | struct objfile *objfile = cu->objfile; |
9661 | struct comp_unit_head *cu_header = &cu->header; | |
9662 | ||
4c2df51b DJ |
9663 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
9664 | code here to turn a symbol with DW_AT_external and a | |
9665 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
9666 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
9667 | with some versions of binutils) where shared libraries could have | |
9668 | relocations against symbols in their debug information - the | |
9669 | minimal symbol would have the right address, but the debug info | |
9670 | would not. It's no longer necessary, because we will explicitly | |
9671 | apply relocations when we read in the debug information now. */ | |
9672 | ||
9673 | /* A DW_AT_location attribute with no contents indicates that a | |
9674 | variable has been optimized away. */ | |
9675 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
9676 | { | |
9677 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
9678 | return; | |
9679 | } | |
9680 | ||
9681 | /* Handle one degenerate form of location expression specially, to | |
9682 | preserve GDB's previous behavior when section offsets are | |
9683 | specified. If this is just a DW_OP_addr then mark this symbol | |
9684 | as LOC_STATIC. */ | |
9685 | ||
9686 | if (attr_form_is_block (attr) | |
9687 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
9688 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
9689 | { | |
891d2f0b | 9690 | unsigned int dummy; |
4c2df51b DJ |
9691 | |
9692 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 9693 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 9694 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
9695 | fixup_symbol_section (sym, objfile); |
9696 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
9697 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
9698 | return; |
9699 | } | |
9700 | ||
9701 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
9702 | expression evaluator, and use LOC_COMPUTED only when necessary | |
9703 | (i.e. when the value of a register or memory location is | |
9704 | referenced, or a thread-local block, etc.). Then again, it might | |
9705 | not be worthwhile. I'm assuming that it isn't unless performance | |
9706 | or memory numbers show me otherwise. */ | |
9707 | ||
e7c27a73 | 9708 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
9709 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
9710 | } | |
9711 | ||
c906108c SS |
9712 | /* Given a pointer to a DWARF information entry, figure out if we need |
9713 | to make a symbol table entry for it, and if so, create a new entry | |
9714 | and return a pointer to it. | |
9715 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 9716 | used the passed type. */ |
c906108c SS |
9717 | |
9718 | static struct symbol * | |
e7c27a73 | 9719 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 9720 | { |
e7c27a73 | 9721 | struct objfile *objfile = cu->objfile; |
c906108c SS |
9722 | struct symbol *sym = NULL; |
9723 | char *name; | |
9724 | struct attribute *attr = NULL; | |
9725 | struct attribute *attr2 = NULL; | |
e142c38c | 9726 | CORE_ADDR baseaddr; |
edb3359d | 9727 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
9728 | |
9729 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 9730 | |
94af9270 | 9731 | name = dwarf2_name (die, cu); |
c906108c SS |
9732 | if (name) |
9733 | { | |
94af9270 KS |
9734 | const char *linkagename; |
9735 | ||
4a146b47 | 9736 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
9737 | sizeof (struct symbol)); |
9738 | OBJSTAT (objfile, n_syms++); | |
9739 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
9740 | |
9741 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 9742 | SYMBOL_LANGUAGE (sym) = cu->language; |
94af9270 KS |
9743 | linkagename = dwarf2_physname (name, die, cu); |
9744 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 9745 | |
f55ee35c JK |
9746 | /* Fortran does not have mangling standard and the mangling does differ |
9747 | between gfortran, iFort etc. */ | |
9748 | if (cu->language == language_fortran | |
9749 | && sym->ginfo.language_specific.cplus_specific.demangled_name == NULL) | |
9750 | sym->ginfo.language_specific.cplus_specific.demangled_name | |
9751 | = (char *) dwarf2_full_name (name, die, cu); | |
9752 | ||
c906108c | 9753 | /* Default assumptions. |
c5aa993b | 9754 | Use the passed type or decode it from the die. */ |
176620f1 | 9755 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 9756 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
9757 | if (type != NULL) |
9758 | SYMBOL_TYPE (sym) = type; | |
9759 | else | |
e7c27a73 | 9760 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
9761 | attr = dwarf2_attr (die, |
9762 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
9763 | cu); | |
c906108c SS |
9764 | if (attr) |
9765 | { | |
9766 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
9767 | } | |
cb1df416 | 9768 | |
edb3359d DJ |
9769 | attr = dwarf2_attr (die, |
9770 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
9771 | cu); | |
cb1df416 DJ |
9772 | if (attr) |
9773 | { | |
9774 | int file_index = DW_UNSND (attr); | |
9a619af0 | 9775 | |
cb1df416 DJ |
9776 | if (cu->line_header == NULL |
9777 | || file_index > cu->line_header->num_file_names) | |
9778 | complaint (&symfile_complaints, | |
9779 | _("file index out of range")); | |
1c3d648d | 9780 | else if (file_index > 0) |
cb1df416 DJ |
9781 | { |
9782 | struct file_entry *fe; | |
9a619af0 | 9783 | |
cb1df416 DJ |
9784 | fe = &cu->line_header->file_names[file_index - 1]; |
9785 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
9786 | } | |
9787 | } | |
9788 | ||
c906108c SS |
9789 | switch (die->tag) |
9790 | { | |
9791 | case DW_TAG_label: | |
e142c38c | 9792 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
9793 | if (attr) |
9794 | { | |
9795 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
9796 | } | |
0f5238ed TT |
9797 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
9798 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 9799 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 9800 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9801 | break; |
9802 | case DW_TAG_subprogram: | |
9803 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
9804 | finish_block. */ | |
9805 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 9806 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
9807 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
9808 | || cu->language == language_ada) | |
c906108c | 9809 | { |
2cfa0c8d JB |
9810 | /* Subprograms marked external are stored as a global symbol. |
9811 | Ada subprograms, whether marked external or not, are always | |
9812 | stored as a global symbol, because we want to be able to | |
9813 | access them globally. For instance, we want to be able | |
9814 | to break on a nested subprogram without having to | |
9815 | specify the context. */ | |
c906108c SS |
9816 | add_symbol_to_list (sym, &global_symbols); |
9817 | } | |
9818 | else | |
9819 | { | |
e142c38c | 9820 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9821 | } |
9822 | break; | |
edb3359d DJ |
9823 | case DW_TAG_inlined_subroutine: |
9824 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
9825 | finish_block. */ | |
9826 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
9827 | SYMBOL_INLINED (sym) = 1; | |
9828 | /* Do not add the symbol to any lists. It will be found via | |
9829 | BLOCK_FUNCTION from the blockvector. */ | |
9830 | break; | |
c906108c | 9831 | case DW_TAG_variable: |
254e6b9e | 9832 | case DW_TAG_member: |
c906108c SS |
9833 | /* Compilation with minimal debug info may result in variables |
9834 | with missing type entries. Change the misleading `void' type | |
9835 | to something sensible. */ | |
9836 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 9837 | SYMBOL_TYPE (sym) |
46bf5051 | 9838 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 9839 | |
e142c38c | 9840 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
9841 | /* In the case of DW_TAG_member, we should only be called for |
9842 | static const members. */ | |
9843 | if (die->tag == DW_TAG_member) | |
9844 | { | |
3863f96c DE |
9845 | /* dwarf2_add_field uses die_is_declaration, |
9846 | so we do the same. */ | |
254e6b9e DE |
9847 | gdb_assert (die_is_declaration (die, cu)); |
9848 | gdb_assert (attr); | |
9849 | } | |
c906108c SS |
9850 | if (attr) |
9851 | { | |
e7c27a73 | 9852 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 9853 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
9854 | if (attr2 && (DW_UNSND (attr2) != 0)) |
9855 | add_symbol_to_list (sym, &global_symbols); | |
9856 | else | |
e142c38c | 9857 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9858 | break; |
9859 | } | |
e142c38c | 9860 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9861 | if (attr) |
9862 | { | |
e7c27a73 | 9863 | var_decode_location (attr, sym, cu); |
e142c38c | 9864 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 9865 | if (attr2 && (DW_UNSND (attr2) != 0)) |
1c809c68 TT |
9866 | { |
9867 | struct pending **list_to_add; | |
9868 | ||
f55ee35c JK |
9869 | /* Workaround gfortran PR debug/40040 - it uses |
9870 | DW_AT_location for variables in -fPIC libraries which may | |
9871 | get overriden by other libraries/executable and get | |
9872 | a different address. Resolve it by the minimal symbol | |
9873 | which may come from inferior's executable using copy | |
9874 | relocation. Make this workaround only for gfortran as for | |
9875 | other compilers GDB cannot guess the minimal symbol | |
9876 | Fortran mangling kind. */ | |
9877 | if (cu->language == language_fortran && die->parent | |
9878 | && die->parent->tag == DW_TAG_module | |
9879 | && cu->producer | |
9880 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
9881 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
9882 | ||
1c809c68 TT |
9883 | /* A variable with DW_AT_external is never static, |
9884 | but it may be block-scoped. */ | |
9885 | list_to_add = (cu->list_in_scope == &file_symbols | |
9886 | ? &global_symbols : cu->list_in_scope); | |
9887 | add_symbol_to_list (sym, list_to_add); | |
9888 | } | |
c906108c | 9889 | else |
e142c38c | 9890 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9891 | } |
9892 | else | |
9893 | { | |
9894 | /* We do not know the address of this symbol. | |
c5aa993b JM |
9895 | If it is an external symbol and we have type information |
9896 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
9897 | The address of the variable will then be determined from | |
9898 | the minimal symbol table whenever the variable is | |
9899 | referenced. */ | |
e142c38c | 9900 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 9901 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 9902 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 9903 | { |
0fe7935b DJ |
9904 | struct pending **list_to_add; |
9905 | ||
9906 | /* A variable with DW_AT_external is never static, but it | |
9907 | may be block-scoped. */ | |
9908 | list_to_add = (cu->list_in_scope == &file_symbols | |
9909 | ? &global_symbols : cu->list_in_scope); | |
9910 | ||
c906108c | 9911 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
0fe7935b | 9912 | add_symbol_to_list (sym, list_to_add); |
c906108c | 9913 | } |
442ddf59 JK |
9914 | else if (!die_is_declaration (die, cu)) |
9915 | { | |
9916 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
9917 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
9918 | add_symbol_to_list (sym, cu->list_in_scope); | |
9919 | } | |
c906108c SS |
9920 | } |
9921 | break; | |
9922 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
9923 | /* If we are inside a function, mark this as an argument. If |
9924 | not, we might be looking at an argument to an inlined function | |
9925 | when we do not have enough information to show inlined frames; | |
9926 | pretend it's a local variable in that case so that the user can | |
9927 | still see it. */ | |
9928 | if (context_stack_depth > 0 | |
9929 | && context_stack[context_stack_depth - 1].name != NULL) | |
9930 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 9931 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
9932 | if (attr) |
9933 | { | |
e7c27a73 | 9934 | var_decode_location (attr, sym, cu); |
c906108c | 9935 | } |
e142c38c | 9936 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
9937 | if (attr) |
9938 | { | |
e7c27a73 | 9939 | dwarf2_const_value (attr, sym, cu); |
c906108c | 9940 | } |
f346a30d PM |
9941 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
9942 | if (attr && DW_UNSND (attr)) | |
9943 | { | |
9944 | struct type *ref_type; | |
9945 | ||
9946 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
9947 | SYMBOL_TYPE (sym) = ref_type; | |
9948 | } | |
9949 | ||
e142c38c | 9950 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
9951 | break; |
9952 | case DW_TAG_unspecified_parameters: | |
9953 | /* From varargs functions; gdb doesn't seem to have any | |
9954 | interest in this information, so just ignore it for now. | |
9955 | (FIXME?) */ | |
9956 | break; | |
9957 | case DW_TAG_class_type: | |
680b30c7 | 9958 | case DW_TAG_interface_type: |
c906108c SS |
9959 | case DW_TAG_structure_type: |
9960 | case DW_TAG_union_type: | |
72019c9c | 9961 | case DW_TAG_set_type: |
c906108c SS |
9962 | case DW_TAG_enumeration_type: |
9963 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 9964 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 9965 | |
63d06c5c | 9966 | { |
987504bb | 9967 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
9968 | really ever be static objects: otherwise, if you try |
9969 | to, say, break of a class's method and you're in a file | |
9970 | which doesn't mention that class, it won't work unless | |
9971 | the check for all static symbols in lookup_symbol_aux | |
9972 | saves you. See the OtherFileClass tests in | |
9973 | gdb.c++/namespace.exp. */ | |
9974 | ||
9975 | struct pending **list_to_add; | |
9976 | ||
e142c38c | 9977 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
9978 | && (cu->language == language_cplus |
9979 | || cu->language == language_java) | |
e142c38c | 9980 | ? &global_symbols : cu->list_in_scope); |
6e70227d | 9981 | |
63d06c5c DC |
9982 | add_symbol_to_list (sym, list_to_add); |
9983 | ||
9984 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 9985 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 9986 | defines a typedef for the class. */ |
987504bb | 9987 | if (cu->language == language_cplus |
8c6860bb JB |
9988 | || cu->language == language_java |
9989 | || cu->language == language_ada) | |
63d06c5c | 9990 | { |
d8151005 DJ |
9991 | /* The symbol's name is already allocated along with |
9992 | this objfile, so we don't need to duplicate it for | |
9993 | the type. */ | |
63d06c5c | 9994 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 9995 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
9996 | } |
9997 | } | |
c906108c SS |
9998 | break; |
9999 | case DW_TAG_typedef: | |
63d06c5c DC |
10000 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
10001 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 10002 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 10003 | break; |
c906108c | 10004 | case DW_TAG_base_type: |
a02abb62 | 10005 | case DW_TAG_subrange_type: |
90e7c2c5 PM |
10006 | case DW_TAG_const_type: |
10007 | case DW_TAG_volatile_type: | |
c906108c | 10008 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 10009 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 10010 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
10011 | break; |
10012 | case DW_TAG_enumerator: | |
e142c38c | 10013 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10014 | if (attr) |
10015 | { | |
e7c27a73 | 10016 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10017 | } |
63d06c5c DC |
10018 | { |
10019 | /* NOTE: carlton/2003-11-10: See comment above in the | |
10020 | DW_TAG_class_type, etc. block. */ | |
10021 | ||
10022 | struct pending **list_to_add; | |
10023 | ||
e142c38c | 10024 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
10025 | && (cu->language == language_cplus |
10026 | || cu->language == language_java) | |
e142c38c | 10027 | ? &global_symbols : cu->list_in_scope); |
6e70227d | 10028 | |
63d06c5c DC |
10029 | add_symbol_to_list (sym, list_to_add); |
10030 | } | |
c906108c | 10031 | break; |
5c4e30ca DC |
10032 | case DW_TAG_namespace: |
10033 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
10034 | add_symbol_to_list (sym, &global_symbols); | |
10035 | break; | |
c906108c SS |
10036 | default: |
10037 | /* Not a tag we recognize. Hopefully we aren't processing | |
10038 | trash data, but since we must specifically ignore things | |
10039 | we don't recognize, there is nothing else we should do at | |
10040 | this point. */ | |
e2e0b3e5 | 10041 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 10042 | dwarf_tag_name (die->tag)); |
c906108c SS |
10043 | break; |
10044 | } | |
df8a16a1 DJ |
10045 | |
10046 | /* For the benefit of old versions of GCC, check for anonymous | |
10047 | namespaces based on the demangled name. */ | |
10048 | if (!processing_has_namespace_info | |
94af9270 | 10049 | && cu->language == language_cplus) |
df8a16a1 | 10050 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
10051 | } |
10052 | return (sym); | |
10053 | } | |
10054 | ||
10055 | /* Copy constant value from an attribute to a symbol. */ | |
10056 | ||
10057 | static void | |
107d2387 | 10058 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 10059 | struct dwarf2_cu *cu) |
c906108c | 10060 | { |
e7c27a73 DJ |
10061 | struct objfile *objfile = cu->objfile; |
10062 | struct comp_unit_head *cu_header = &cu->header; | |
e17a4113 UW |
10063 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
10064 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
c906108c SS |
10065 | struct dwarf_block *blk; |
10066 | ||
10067 | switch (attr->form) | |
10068 | { | |
10069 | case DW_FORM_addr: | |
ac56253d TT |
10070 | { |
10071 | struct dwarf2_locexpr_baton *baton; | |
10072 | gdb_byte *data; | |
10073 | ||
10074 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) | |
10075 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), | |
10076 | cu_header->addr_size, | |
10077 | TYPE_LENGTH (SYMBOL_TYPE | |
10078 | (sym))); | |
10079 | /* Symbols of this form are reasonably rare, so we just | |
10080 | piggyback on the existing location code rather than writing | |
10081 | a new implementation of symbol_computed_ops. */ | |
10082 | baton = obstack_alloc (&objfile->objfile_obstack, | |
10083 | sizeof (struct dwarf2_locexpr_baton)); | |
10084 | baton->per_cu = cu->per_cu; | |
10085 | gdb_assert (baton->per_cu); | |
10086 | ||
10087 | baton->size = 2 + cu_header->addr_size; | |
10088 | data = obstack_alloc (&objfile->objfile_obstack, baton->size); | |
10089 | baton->data = data; | |
10090 | ||
10091 | data[0] = DW_OP_addr; | |
10092 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
10093 | byte_order, DW_ADDR (attr)); | |
10094 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
10095 | ||
10096 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
10097 | SYMBOL_LOCATION_BATON (sym) = baton; | |
10098 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
10099 | } | |
c906108c | 10100 | break; |
4ac36638 | 10101 | case DW_FORM_string: |
93b5768b PA |
10102 | case DW_FORM_strp: |
10103 | /* DW_STRING is already allocated on the obstack, point directly | |
10104 | to it. */ | |
10105 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
10106 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
10107 | break; | |
c906108c SS |
10108 | case DW_FORM_block1: |
10109 | case DW_FORM_block2: | |
10110 | case DW_FORM_block4: | |
10111 | case DW_FORM_block: | |
2dc7f7b3 | 10112 | case DW_FORM_exprloc: |
c906108c SS |
10113 | blk = DW_BLOCK (attr); |
10114 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 10115 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
10116 | blk->size, |
10117 | TYPE_LENGTH (SYMBOL_TYPE | |
10118 | (sym))); | |
4e38b386 | 10119 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 10120 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
10121 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
10122 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
10123 | break; | |
2df3850c JM |
10124 | |
10125 | /* The DW_AT_const_value attributes are supposed to carry the | |
10126 | symbol's value "represented as it would be on the target | |
10127 | architecture." By the time we get here, it's already been | |
10128 | converted to host endianness, so we just need to sign- or | |
10129 | zero-extend it as appropriate. */ | |
10130 | case DW_FORM_data1: | |
10131 | dwarf2_const_value_data (attr, sym, 8); | |
10132 | break; | |
c906108c | 10133 | case DW_FORM_data2: |
2df3850c JM |
10134 | dwarf2_const_value_data (attr, sym, 16); |
10135 | break; | |
c906108c | 10136 | case DW_FORM_data4: |
2df3850c JM |
10137 | dwarf2_const_value_data (attr, sym, 32); |
10138 | break; | |
c906108c | 10139 | case DW_FORM_data8: |
2df3850c JM |
10140 | dwarf2_const_value_data (attr, sym, 64); |
10141 | break; | |
10142 | ||
c906108c | 10143 | case DW_FORM_sdata: |
2df3850c JM |
10144 | SYMBOL_VALUE (sym) = DW_SND (attr); |
10145 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10146 | break; | |
10147 | ||
c906108c SS |
10148 | case DW_FORM_udata: |
10149 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
10150 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10151 | break; | |
2df3850c | 10152 | |
c906108c | 10153 | default: |
4d3c2250 | 10154 | complaint (&symfile_complaints, |
e2e0b3e5 | 10155 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 10156 | dwarf_form_name (attr->form)); |
c906108c SS |
10157 | SYMBOL_VALUE (sym) = 0; |
10158 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10159 | break; | |
10160 | } | |
10161 | } | |
10162 | ||
2df3850c JM |
10163 | |
10164 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
10165 | or zero-extend it as appropriate for the symbol's type. */ | |
10166 | static void | |
10167 | dwarf2_const_value_data (struct attribute *attr, | |
10168 | struct symbol *sym, | |
10169 | int bits) | |
10170 | { | |
10171 | LONGEST l = DW_UNSND (attr); | |
10172 | ||
10173 | if (bits < sizeof (l) * 8) | |
10174 | { | |
10175 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
10176 | l &= ((LONGEST) 1 << bits) - 1; | |
10177 | else | |
bf9198f1 | 10178 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
10179 | } |
10180 | ||
10181 | SYMBOL_VALUE (sym) = l; | |
10182 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10183 | } | |
10184 | ||
10185 | ||
c906108c SS |
10186 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
10187 | ||
10188 | static struct type * | |
e7c27a73 | 10189 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10190 | { |
c906108c SS |
10191 | struct attribute *type_attr; |
10192 | struct die_info *type_die; | |
c906108c | 10193 | |
e142c38c | 10194 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
10195 | if (!type_attr) |
10196 | { | |
10197 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 10198 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 10199 | } |
348e048f DE |
10200 | |
10201 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10b3939b | 10202 | |
33ac96f0 | 10203 | return tag_type_to_type (type_die, cu); |
c906108c SS |
10204 | } |
10205 | ||
b4ba55a1 JB |
10206 | /* True iff CU's producer generates GNAT Ada auxiliary information |
10207 | that allows to find parallel types through that information instead | |
10208 | of having to do expensive parallel lookups by type name. */ | |
10209 | ||
10210 | static int | |
10211 | need_gnat_info (struct dwarf2_cu *cu) | |
10212 | { | |
10213 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
10214 | of GNAT produces this auxiliary information, without any indication | |
10215 | that it is produced. Part of enhancing the FSF version of GNAT | |
10216 | to produce that information will be to put in place an indicator | |
10217 | that we can use in order to determine whether the descriptive type | |
10218 | info is available or not. One suggestion that has been made is | |
10219 | to use a new attribute, attached to the CU die. For now, assume | |
10220 | that the descriptive type info is not available. */ | |
10221 | return 0; | |
10222 | } | |
10223 | ||
10224 | ||
10225 | /* Return the auxiliary type of the die in question using its | |
10226 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
10227 | attribute is not present. */ | |
10228 | ||
10229 | static struct type * | |
10230 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
10231 | { | |
b4ba55a1 JB |
10232 | struct attribute *type_attr; |
10233 | struct die_info *type_die; | |
10234 | ||
10235 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
10236 | if (!type_attr) | |
10237 | return NULL; | |
10238 | ||
10239 | type_die = follow_die_ref (die, type_attr, &cu); | |
33ac96f0 | 10240 | return tag_type_to_type (type_die, cu); |
b4ba55a1 JB |
10241 | } |
10242 | ||
10243 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
10244 | descriptive type accordingly. */ | |
10245 | ||
10246 | static void | |
10247 | set_descriptive_type (struct type *type, struct die_info *die, | |
10248 | struct dwarf2_cu *cu) | |
10249 | { | |
10250 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
10251 | ||
10252 | if (descriptive_type) | |
10253 | { | |
10254 | ALLOCATE_GNAT_AUX_TYPE (type); | |
10255 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
10256 | } | |
10257 | } | |
10258 | ||
c906108c SS |
10259 | /* Return the containing type of the die in question using its |
10260 | DW_AT_containing_type attribute. */ | |
10261 | ||
10262 | static struct type * | |
e7c27a73 | 10263 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10264 | { |
c906108c | 10265 | struct attribute *type_attr; |
33ac96f0 | 10266 | struct die_info *type_die; |
c906108c | 10267 | |
e142c38c | 10268 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
10269 | if (!type_attr) |
10270 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
10271 | "[in module %s]"), cu->objfile->name); | |
10272 | ||
10273 | type_die = follow_die_ref_or_sig (die, type_attr, &cu); | |
10274 | return tag_type_to_type (type_die, cu); | |
c906108c SS |
10275 | } |
10276 | ||
c906108c | 10277 | static struct type * |
e7c27a73 | 10278 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10279 | { |
f792889a DJ |
10280 | struct type *this_type; |
10281 | ||
10282 | this_type = read_type_die (die, cu); | |
10283 | if (!this_type) | |
c906108c | 10284 | { |
b00fdb78 TT |
10285 | char *message, *saved; |
10286 | ||
10287 | /* read_type_die already issued a complaint. */ | |
10288 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
10289 | cu->objfile->name, | |
10290 | cu->header.offset, | |
10291 | die->offset); | |
10292 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
10293 | message, strlen (message)); | |
10294 | xfree (message); | |
10295 | ||
10296 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 10297 | } |
f792889a | 10298 | return this_type; |
c906108c SS |
10299 | } |
10300 | ||
f792889a | 10301 | static struct type * |
e7c27a73 | 10302 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 10303 | { |
f792889a DJ |
10304 | struct type *this_type; |
10305 | ||
10306 | this_type = get_die_type (die, cu); | |
10307 | if (this_type) | |
10308 | return this_type; | |
10309 | ||
c906108c SS |
10310 | switch (die->tag) |
10311 | { | |
10312 | case DW_TAG_class_type: | |
680b30c7 | 10313 | case DW_TAG_interface_type: |
c906108c SS |
10314 | case DW_TAG_structure_type: |
10315 | case DW_TAG_union_type: | |
f792889a | 10316 | this_type = read_structure_type (die, cu); |
c906108c SS |
10317 | break; |
10318 | case DW_TAG_enumeration_type: | |
f792889a | 10319 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
10320 | break; |
10321 | case DW_TAG_subprogram: | |
10322 | case DW_TAG_subroutine_type: | |
edb3359d | 10323 | case DW_TAG_inlined_subroutine: |
f792889a | 10324 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
10325 | break; |
10326 | case DW_TAG_array_type: | |
f792889a | 10327 | this_type = read_array_type (die, cu); |
c906108c | 10328 | break; |
72019c9c | 10329 | case DW_TAG_set_type: |
f792889a | 10330 | this_type = read_set_type (die, cu); |
72019c9c | 10331 | break; |
c906108c | 10332 | case DW_TAG_pointer_type: |
f792889a | 10333 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
10334 | break; |
10335 | case DW_TAG_ptr_to_member_type: | |
f792889a | 10336 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
10337 | break; |
10338 | case DW_TAG_reference_type: | |
f792889a | 10339 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
10340 | break; |
10341 | case DW_TAG_const_type: | |
f792889a | 10342 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
10343 | break; |
10344 | case DW_TAG_volatile_type: | |
f792889a | 10345 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
10346 | break; |
10347 | case DW_TAG_string_type: | |
f792889a | 10348 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
10349 | break; |
10350 | case DW_TAG_typedef: | |
f792889a | 10351 | this_type = read_typedef (die, cu); |
c906108c | 10352 | break; |
a02abb62 | 10353 | case DW_TAG_subrange_type: |
f792889a | 10354 | this_type = read_subrange_type (die, cu); |
a02abb62 | 10355 | break; |
c906108c | 10356 | case DW_TAG_base_type: |
f792889a | 10357 | this_type = read_base_type (die, cu); |
c906108c | 10358 | break; |
81a17f79 | 10359 | case DW_TAG_unspecified_type: |
f792889a | 10360 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 10361 | break; |
0114d602 DJ |
10362 | case DW_TAG_namespace: |
10363 | this_type = read_namespace_type (die, cu); | |
10364 | break; | |
f55ee35c JK |
10365 | case DW_TAG_module: |
10366 | this_type = read_module_type (die, cu); | |
10367 | break; | |
c906108c | 10368 | default: |
a1f5b845 | 10369 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 10370 | dwarf_tag_name (die->tag)); |
c906108c SS |
10371 | break; |
10372 | } | |
63d06c5c | 10373 | |
f792889a | 10374 | return this_type; |
63d06c5c DC |
10375 | } |
10376 | ||
fdde2d81 | 10377 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 10378 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 10379 | |
0114d602 DJ |
10380 | For example, if we're within the method foo() in the following |
10381 | code: | |
10382 | ||
10383 | namespace N { | |
10384 | class C { | |
10385 | void foo () { | |
10386 | } | |
10387 | }; | |
10388 | } | |
10389 | ||
10390 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
10391 | |
10392 | static char * | |
e142c38c | 10393 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 10394 | { |
0114d602 DJ |
10395 | struct die_info *parent, *spec_die; |
10396 | struct dwarf2_cu *spec_cu; | |
10397 | struct type *parent_type; | |
63d06c5c | 10398 | |
f55ee35c JK |
10399 | if (cu->language != language_cplus && cu->language != language_java |
10400 | && cu->language != language_fortran) | |
0114d602 DJ |
10401 | return ""; |
10402 | ||
10403 | /* We have to be careful in the presence of DW_AT_specification. | |
10404 | For example, with GCC 3.4, given the code | |
10405 | ||
10406 | namespace N { | |
10407 | void foo() { | |
10408 | // Definition of N::foo. | |
10409 | } | |
10410 | } | |
10411 | ||
10412 | then we'll have a tree of DIEs like this: | |
10413 | ||
10414 | 1: DW_TAG_compile_unit | |
10415 | 2: DW_TAG_namespace // N | |
10416 | 3: DW_TAG_subprogram // declaration of N::foo | |
10417 | 4: DW_TAG_subprogram // definition of N::foo | |
10418 | DW_AT_specification // refers to die #3 | |
10419 | ||
10420 | Thus, when processing die #4, we have to pretend that we're in | |
10421 | the context of its DW_AT_specification, namely the contex of die | |
10422 | #3. */ | |
10423 | spec_cu = cu; | |
10424 | spec_die = die_specification (die, &spec_cu); | |
10425 | if (spec_die == NULL) | |
10426 | parent = die->parent; | |
10427 | else | |
63d06c5c | 10428 | { |
0114d602 DJ |
10429 | parent = spec_die->parent; |
10430 | cu = spec_cu; | |
63d06c5c | 10431 | } |
0114d602 DJ |
10432 | |
10433 | if (parent == NULL) | |
10434 | return ""; | |
63d06c5c | 10435 | else |
0114d602 DJ |
10436 | switch (parent->tag) |
10437 | { | |
63d06c5c | 10438 | case DW_TAG_namespace: |
0114d602 | 10439 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
10440 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
10441 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
10442 | Work around this problem here. */ | |
10443 | if (cu->language == language_cplus | |
10444 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
10445 | return ""; | |
0114d602 DJ |
10446 | /* We give a name to even anonymous namespaces. */ |
10447 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 10448 | case DW_TAG_class_type: |
680b30c7 | 10449 | case DW_TAG_interface_type: |
63d06c5c | 10450 | case DW_TAG_structure_type: |
0114d602 | 10451 | case DW_TAG_union_type: |
f55ee35c | 10452 | case DW_TAG_module: |
0114d602 DJ |
10453 | parent_type = read_type_die (parent, cu); |
10454 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
10455 | return TYPE_TAG_NAME (parent_type); | |
10456 | else | |
10457 | /* An anonymous structure is only allowed non-static data | |
10458 | members; no typedefs, no member functions, et cetera. | |
10459 | So it does not need a prefix. */ | |
10460 | return ""; | |
63d06c5c | 10461 | default: |
8176b9b8 | 10462 | return determine_prefix (parent, cu); |
63d06c5c | 10463 | } |
63d06c5c DC |
10464 | } |
10465 | ||
987504bb JJ |
10466 | /* Return a newly-allocated string formed by concatenating PREFIX and |
10467 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
10468 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
10469 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
10470 | is used to determine the language and hence, the appropriate separator. */ | |
10471 | ||
f55ee35c | 10472 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
10473 | |
10474 | static char * | |
f55ee35c JK |
10475 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
10476 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 10477 | { |
f55ee35c | 10478 | const char *lead = ""; |
5c315b68 | 10479 | const char *sep; |
63d06c5c | 10480 | |
987504bb JJ |
10481 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
10482 | sep = ""; | |
10483 | else if (cu->language == language_java) | |
10484 | sep = "."; | |
f55ee35c JK |
10485 | else if (cu->language == language_fortran && physname) |
10486 | { | |
10487 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
10488 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
10489 | ||
10490 | lead = "__"; | |
10491 | sep = "_MOD_"; | |
10492 | } | |
987504bb JJ |
10493 | else |
10494 | sep = "::"; | |
63d06c5c | 10495 | |
6dd47d34 DE |
10496 | if (prefix == NULL) |
10497 | prefix = ""; | |
10498 | if (suffix == NULL) | |
10499 | suffix = ""; | |
10500 | ||
987504bb JJ |
10501 | if (obs == NULL) |
10502 | { | |
10503 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 10504 | |
f55ee35c JK |
10505 | strcpy (retval, lead); |
10506 | strcat (retval, prefix); | |
6dd47d34 DE |
10507 | strcat (retval, sep); |
10508 | strcat (retval, suffix); | |
63d06c5c DC |
10509 | return retval; |
10510 | } | |
987504bb JJ |
10511 | else |
10512 | { | |
10513 | /* We have an obstack. */ | |
f55ee35c | 10514 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 10515 | } |
63d06c5c DC |
10516 | } |
10517 | ||
c906108c SS |
10518 | /* Return sibling of die, NULL if no sibling. */ |
10519 | ||
f9aca02d | 10520 | static struct die_info * |
fba45db2 | 10521 | sibling_die (struct die_info *die) |
c906108c | 10522 | { |
639d11d3 | 10523 | return die->sibling; |
c906108c SS |
10524 | } |
10525 | ||
71c25dea TT |
10526 | /* Get name of a die, return NULL if not found. */ |
10527 | ||
10528 | static char * | |
10529 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
10530 | struct obstack *obstack) | |
10531 | { | |
10532 | if (name && cu->language == language_cplus) | |
10533 | { | |
10534 | char *canon_name = cp_canonicalize_string (name); | |
10535 | ||
10536 | if (canon_name != NULL) | |
10537 | { | |
10538 | if (strcmp (canon_name, name) != 0) | |
10539 | name = obsavestring (canon_name, strlen (canon_name), | |
10540 | obstack); | |
10541 | xfree (canon_name); | |
10542 | } | |
10543 | } | |
10544 | ||
10545 | return name; | |
c906108c SS |
10546 | } |
10547 | ||
9219021c DC |
10548 | /* Get name of a die, return NULL if not found. */ |
10549 | ||
10550 | static char * | |
e142c38c | 10551 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
10552 | { |
10553 | struct attribute *attr; | |
10554 | ||
e142c38c | 10555 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
10556 | if (!attr || !DW_STRING (attr)) |
10557 | return NULL; | |
10558 | ||
10559 | switch (die->tag) | |
10560 | { | |
10561 | case DW_TAG_compile_unit: | |
10562 | /* Compilation units have a DW_AT_name that is a filename, not | |
10563 | a source language identifier. */ | |
10564 | case DW_TAG_enumeration_type: | |
10565 | case DW_TAG_enumerator: | |
10566 | /* These tags always have simple identifiers already; no need | |
10567 | to canonicalize them. */ | |
10568 | return DW_STRING (attr); | |
907af001 | 10569 | |
418835cc KS |
10570 | case DW_TAG_subprogram: |
10571 | /* Java constructors will all be named "<init>", so return | |
10572 | the class name when we see this special case. */ | |
10573 | if (cu->language == language_java | |
10574 | && DW_STRING (attr) != NULL | |
10575 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
10576 | { | |
10577 | struct dwarf2_cu *spec_cu = cu; | |
10578 | struct die_info *spec_die; | |
10579 | ||
10580 | /* GCJ will output '<init>' for Java constructor names. | |
10581 | For this special case, return the name of the parent class. */ | |
10582 | ||
10583 | /* GCJ may output suprogram DIEs with AT_specification set. | |
10584 | If so, use the name of the specified DIE. */ | |
10585 | spec_die = die_specification (die, &spec_cu); | |
10586 | if (spec_die != NULL) | |
10587 | return dwarf2_name (spec_die, spec_cu); | |
10588 | ||
10589 | do | |
10590 | { | |
10591 | die = die->parent; | |
10592 | if (die->tag == DW_TAG_class_type) | |
10593 | return dwarf2_name (die, cu); | |
10594 | } | |
10595 | while (die->tag != DW_TAG_compile_unit); | |
10596 | } | |
907af001 UW |
10597 | break; |
10598 | ||
10599 | case DW_TAG_class_type: | |
10600 | case DW_TAG_interface_type: | |
10601 | case DW_TAG_structure_type: | |
10602 | case DW_TAG_union_type: | |
10603 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
10604 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
10605 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
10606 | and GCC 4.4. We work around this problem by ignoring these. */ | |
10607 | if (strncmp (DW_STRING (attr), "._", 2) == 0 | |
10608 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) | |
10609 | return NULL; | |
10610 | break; | |
10611 | ||
71c25dea | 10612 | default: |
907af001 UW |
10613 | break; |
10614 | } | |
10615 | ||
10616 | if (!DW_STRING_IS_CANONICAL (attr)) | |
10617 | { | |
10618 | DW_STRING (attr) | |
10619 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
10620 | &cu->objfile->objfile_obstack); | |
10621 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 10622 | } |
907af001 | 10623 | return DW_STRING (attr); |
9219021c DC |
10624 | } |
10625 | ||
10626 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
10627 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
10628 | containing the return value on output. */ | |
9219021c DC |
10629 | |
10630 | static struct die_info * | |
f2f0e013 | 10631 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
10632 | { |
10633 | struct attribute *attr; | |
9219021c | 10634 | |
f2f0e013 | 10635 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
10636 | if (attr == NULL) |
10637 | return NULL; | |
10638 | ||
f2f0e013 | 10639 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
10640 | } |
10641 | ||
c906108c SS |
10642 | /* Convert a DIE tag into its string name. */ |
10643 | ||
10644 | static char * | |
aa1ee363 | 10645 | dwarf_tag_name (unsigned tag) |
c906108c SS |
10646 | { |
10647 | switch (tag) | |
10648 | { | |
10649 | case DW_TAG_padding: | |
10650 | return "DW_TAG_padding"; | |
10651 | case DW_TAG_array_type: | |
10652 | return "DW_TAG_array_type"; | |
10653 | case DW_TAG_class_type: | |
10654 | return "DW_TAG_class_type"; | |
10655 | case DW_TAG_entry_point: | |
10656 | return "DW_TAG_entry_point"; | |
10657 | case DW_TAG_enumeration_type: | |
10658 | return "DW_TAG_enumeration_type"; | |
10659 | case DW_TAG_formal_parameter: | |
10660 | return "DW_TAG_formal_parameter"; | |
10661 | case DW_TAG_imported_declaration: | |
10662 | return "DW_TAG_imported_declaration"; | |
10663 | case DW_TAG_label: | |
10664 | return "DW_TAG_label"; | |
10665 | case DW_TAG_lexical_block: | |
10666 | return "DW_TAG_lexical_block"; | |
10667 | case DW_TAG_member: | |
10668 | return "DW_TAG_member"; | |
10669 | case DW_TAG_pointer_type: | |
10670 | return "DW_TAG_pointer_type"; | |
10671 | case DW_TAG_reference_type: | |
10672 | return "DW_TAG_reference_type"; | |
10673 | case DW_TAG_compile_unit: | |
10674 | return "DW_TAG_compile_unit"; | |
10675 | case DW_TAG_string_type: | |
10676 | return "DW_TAG_string_type"; | |
10677 | case DW_TAG_structure_type: | |
10678 | return "DW_TAG_structure_type"; | |
10679 | case DW_TAG_subroutine_type: | |
10680 | return "DW_TAG_subroutine_type"; | |
10681 | case DW_TAG_typedef: | |
10682 | return "DW_TAG_typedef"; | |
10683 | case DW_TAG_union_type: | |
10684 | return "DW_TAG_union_type"; | |
10685 | case DW_TAG_unspecified_parameters: | |
10686 | return "DW_TAG_unspecified_parameters"; | |
10687 | case DW_TAG_variant: | |
10688 | return "DW_TAG_variant"; | |
10689 | case DW_TAG_common_block: | |
10690 | return "DW_TAG_common_block"; | |
10691 | case DW_TAG_common_inclusion: | |
10692 | return "DW_TAG_common_inclusion"; | |
10693 | case DW_TAG_inheritance: | |
10694 | return "DW_TAG_inheritance"; | |
10695 | case DW_TAG_inlined_subroutine: | |
10696 | return "DW_TAG_inlined_subroutine"; | |
10697 | case DW_TAG_module: | |
10698 | return "DW_TAG_module"; | |
10699 | case DW_TAG_ptr_to_member_type: | |
10700 | return "DW_TAG_ptr_to_member_type"; | |
10701 | case DW_TAG_set_type: | |
10702 | return "DW_TAG_set_type"; | |
10703 | case DW_TAG_subrange_type: | |
10704 | return "DW_TAG_subrange_type"; | |
10705 | case DW_TAG_with_stmt: | |
10706 | return "DW_TAG_with_stmt"; | |
10707 | case DW_TAG_access_declaration: | |
10708 | return "DW_TAG_access_declaration"; | |
10709 | case DW_TAG_base_type: | |
10710 | return "DW_TAG_base_type"; | |
10711 | case DW_TAG_catch_block: | |
10712 | return "DW_TAG_catch_block"; | |
10713 | case DW_TAG_const_type: | |
10714 | return "DW_TAG_const_type"; | |
10715 | case DW_TAG_constant: | |
10716 | return "DW_TAG_constant"; | |
10717 | case DW_TAG_enumerator: | |
10718 | return "DW_TAG_enumerator"; | |
10719 | case DW_TAG_file_type: | |
10720 | return "DW_TAG_file_type"; | |
10721 | case DW_TAG_friend: | |
10722 | return "DW_TAG_friend"; | |
10723 | case DW_TAG_namelist: | |
10724 | return "DW_TAG_namelist"; | |
10725 | case DW_TAG_namelist_item: | |
10726 | return "DW_TAG_namelist_item"; | |
10727 | case DW_TAG_packed_type: | |
10728 | return "DW_TAG_packed_type"; | |
10729 | case DW_TAG_subprogram: | |
10730 | return "DW_TAG_subprogram"; | |
10731 | case DW_TAG_template_type_param: | |
10732 | return "DW_TAG_template_type_param"; | |
10733 | case DW_TAG_template_value_param: | |
10734 | return "DW_TAG_template_value_param"; | |
10735 | case DW_TAG_thrown_type: | |
10736 | return "DW_TAG_thrown_type"; | |
10737 | case DW_TAG_try_block: | |
10738 | return "DW_TAG_try_block"; | |
10739 | case DW_TAG_variant_part: | |
10740 | return "DW_TAG_variant_part"; | |
10741 | case DW_TAG_variable: | |
10742 | return "DW_TAG_variable"; | |
10743 | case DW_TAG_volatile_type: | |
10744 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
10745 | case DW_TAG_dwarf_procedure: |
10746 | return "DW_TAG_dwarf_procedure"; | |
10747 | case DW_TAG_restrict_type: | |
10748 | return "DW_TAG_restrict_type"; | |
10749 | case DW_TAG_interface_type: | |
10750 | return "DW_TAG_interface_type"; | |
10751 | case DW_TAG_namespace: | |
10752 | return "DW_TAG_namespace"; | |
10753 | case DW_TAG_imported_module: | |
10754 | return "DW_TAG_imported_module"; | |
10755 | case DW_TAG_unspecified_type: | |
10756 | return "DW_TAG_unspecified_type"; | |
10757 | case DW_TAG_partial_unit: | |
10758 | return "DW_TAG_partial_unit"; | |
10759 | case DW_TAG_imported_unit: | |
10760 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
10761 | case DW_TAG_condition: |
10762 | return "DW_TAG_condition"; | |
10763 | case DW_TAG_shared_type: | |
10764 | return "DW_TAG_shared_type"; | |
348e048f DE |
10765 | case DW_TAG_type_unit: |
10766 | return "DW_TAG_type_unit"; | |
c906108c SS |
10767 | case DW_TAG_MIPS_loop: |
10768 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
10769 | case DW_TAG_HP_array_descriptor: |
10770 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
10771 | case DW_TAG_format_label: |
10772 | return "DW_TAG_format_label"; | |
10773 | case DW_TAG_function_template: | |
10774 | return "DW_TAG_function_template"; | |
10775 | case DW_TAG_class_template: | |
10776 | return "DW_TAG_class_template"; | |
b7619582 GF |
10777 | case DW_TAG_GNU_BINCL: |
10778 | return "DW_TAG_GNU_BINCL"; | |
10779 | case DW_TAG_GNU_EINCL: | |
10780 | return "DW_TAG_GNU_EINCL"; | |
10781 | case DW_TAG_upc_shared_type: | |
10782 | return "DW_TAG_upc_shared_type"; | |
10783 | case DW_TAG_upc_strict_type: | |
10784 | return "DW_TAG_upc_strict_type"; | |
10785 | case DW_TAG_upc_relaxed_type: | |
10786 | return "DW_TAG_upc_relaxed_type"; | |
10787 | case DW_TAG_PGI_kanji_type: | |
10788 | return "DW_TAG_PGI_kanji_type"; | |
10789 | case DW_TAG_PGI_interface_block: | |
10790 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
10791 | default: |
10792 | return "DW_TAG_<unknown>"; | |
10793 | } | |
10794 | } | |
10795 | ||
10796 | /* Convert a DWARF attribute code into its string name. */ | |
10797 | ||
10798 | static char * | |
aa1ee363 | 10799 | dwarf_attr_name (unsigned attr) |
c906108c SS |
10800 | { |
10801 | switch (attr) | |
10802 | { | |
10803 | case DW_AT_sibling: | |
10804 | return "DW_AT_sibling"; | |
10805 | case DW_AT_location: | |
10806 | return "DW_AT_location"; | |
10807 | case DW_AT_name: | |
10808 | return "DW_AT_name"; | |
10809 | case DW_AT_ordering: | |
10810 | return "DW_AT_ordering"; | |
10811 | case DW_AT_subscr_data: | |
10812 | return "DW_AT_subscr_data"; | |
10813 | case DW_AT_byte_size: | |
10814 | return "DW_AT_byte_size"; | |
10815 | case DW_AT_bit_offset: | |
10816 | return "DW_AT_bit_offset"; | |
10817 | case DW_AT_bit_size: | |
10818 | return "DW_AT_bit_size"; | |
10819 | case DW_AT_element_list: | |
10820 | return "DW_AT_element_list"; | |
10821 | case DW_AT_stmt_list: | |
10822 | return "DW_AT_stmt_list"; | |
10823 | case DW_AT_low_pc: | |
10824 | return "DW_AT_low_pc"; | |
10825 | case DW_AT_high_pc: | |
10826 | return "DW_AT_high_pc"; | |
10827 | case DW_AT_language: | |
10828 | return "DW_AT_language"; | |
10829 | case DW_AT_member: | |
10830 | return "DW_AT_member"; | |
10831 | case DW_AT_discr: | |
10832 | return "DW_AT_discr"; | |
10833 | case DW_AT_discr_value: | |
10834 | return "DW_AT_discr_value"; | |
10835 | case DW_AT_visibility: | |
10836 | return "DW_AT_visibility"; | |
10837 | case DW_AT_import: | |
10838 | return "DW_AT_import"; | |
10839 | case DW_AT_string_length: | |
10840 | return "DW_AT_string_length"; | |
10841 | case DW_AT_common_reference: | |
10842 | return "DW_AT_common_reference"; | |
10843 | case DW_AT_comp_dir: | |
10844 | return "DW_AT_comp_dir"; | |
10845 | case DW_AT_const_value: | |
10846 | return "DW_AT_const_value"; | |
10847 | case DW_AT_containing_type: | |
10848 | return "DW_AT_containing_type"; | |
10849 | case DW_AT_default_value: | |
10850 | return "DW_AT_default_value"; | |
10851 | case DW_AT_inline: | |
10852 | return "DW_AT_inline"; | |
10853 | case DW_AT_is_optional: | |
10854 | return "DW_AT_is_optional"; | |
10855 | case DW_AT_lower_bound: | |
10856 | return "DW_AT_lower_bound"; | |
10857 | case DW_AT_producer: | |
10858 | return "DW_AT_producer"; | |
10859 | case DW_AT_prototyped: | |
10860 | return "DW_AT_prototyped"; | |
10861 | case DW_AT_return_addr: | |
10862 | return "DW_AT_return_addr"; | |
10863 | case DW_AT_start_scope: | |
10864 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
10865 | case DW_AT_bit_stride: |
10866 | return "DW_AT_bit_stride"; | |
c906108c SS |
10867 | case DW_AT_upper_bound: |
10868 | return "DW_AT_upper_bound"; | |
10869 | case DW_AT_abstract_origin: | |
10870 | return "DW_AT_abstract_origin"; | |
10871 | case DW_AT_accessibility: | |
10872 | return "DW_AT_accessibility"; | |
10873 | case DW_AT_address_class: | |
10874 | return "DW_AT_address_class"; | |
10875 | case DW_AT_artificial: | |
10876 | return "DW_AT_artificial"; | |
10877 | case DW_AT_base_types: | |
10878 | return "DW_AT_base_types"; | |
10879 | case DW_AT_calling_convention: | |
10880 | return "DW_AT_calling_convention"; | |
10881 | case DW_AT_count: | |
10882 | return "DW_AT_count"; | |
10883 | case DW_AT_data_member_location: | |
10884 | return "DW_AT_data_member_location"; | |
10885 | case DW_AT_decl_column: | |
10886 | return "DW_AT_decl_column"; | |
10887 | case DW_AT_decl_file: | |
10888 | return "DW_AT_decl_file"; | |
10889 | case DW_AT_decl_line: | |
10890 | return "DW_AT_decl_line"; | |
10891 | case DW_AT_declaration: | |
10892 | return "DW_AT_declaration"; | |
10893 | case DW_AT_discr_list: | |
10894 | return "DW_AT_discr_list"; | |
10895 | case DW_AT_encoding: | |
10896 | return "DW_AT_encoding"; | |
10897 | case DW_AT_external: | |
10898 | return "DW_AT_external"; | |
10899 | case DW_AT_frame_base: | |
10900 | return "DW_AT_frame_base"; | |
10901 | case DW_AT_friend: | |
10902 | return "DW_AT_friend"; | |
10903 | case DW_AT_identifier_case: | |
10904 | return "DW_AT_identifier_case"; | |
10905 | case DW_AT_macro_info: | |
10906 | return "DW_AT_macro_info"; | |
10907 | case DW_AT_namelist_items: | |
10908 | return "DW_AT_namelist_items"; | |
10909 | case DW_AT_priority: | |
10910 | return "DW_AT_priority"; | |
10911 | case DW_AT_segment: | |
10912 | return "DW_AT_segment"; | |
10913 | case DW_AT_specification: | |
10914 | return "DW_AT_specification"; | |
10915 | case DW_AT_static_link: | |
10916 | return "DW_AT_static_link"; | |
10917 | case DW_AT_type: | |
10918 | return "DW_AT_type"; | |
10919 | case DW_AT_use_location: | |
10920 | return "DW_AT_use_location"; | |
10921 | case DW_AT_variable_parameter: | |
10922 | return "DW_AT_variable_parameter"; | |
10923 | case DW_AT_virtuality: | |
10924 | return "DW_AT_virtuality"; | |
10925 | case DW_AT_vtable_elem_location: | |
10926 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 10927 | /* DWARF 3 values. */ |
d9fa45fe DC |
10928 | case DW_AT_allocated: |
10929 | return "DW_AT_allocated"; | |
10930 | case DW_AT_associated: | |
10931 | return "DW_AT_associated"; | |
10932 | case DW_AT_data_location: | |
10933 | return "DW_AT_data_location"; | |
09fa0d7c JK |
10934 | case DW_AT_byte_stride: |
10935 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
10936 | case DW_AT_entry_pc: |
10937 | return "DW_AT_entry_pc"; | |
10938 | case DW_AT_use_UTF8: | |
10939 | return "DW_AT_use_UTF8"; | |
10940 | case DW_AT_extension: | |
10941 | return "DW_AT_extension"; | |
10942 | case DW_AT_ranges: | |
10943 | return "DW_AT_ranges"; | |
10944 | case DW_AT_trampoline: | |
10945 | return "DW_AT_trampoline"; | |
10946 | case DW_AT_call_column: | |
10947 | return "DW_AT_call_column"; | |
10948 | case DW_AT_call_file: | |
10949 | return "DW_AT_call_file"; | |
10950 | case DW_AT_call_line: | |
10951 | return "DW_AT_call_line"; | |
b7619582 GF |
10952 | case DW_AT_description: |
10953 | return "DW_AT_description"; | |
10954 | case DW_AT_binary_scale: | |
10955 | return "DW_AT_binary_scale"; | |
10956 | case DW_AT_decimal_scale: | |
10957 | return "DW_AT_decimal_scale"; | |
10958 | case DW_AT_small: | |
10959 | return "DW_AT_small"; | |
10960 | case DW_AT_decimal_sign: | |
10961 | return "DW_AT_decimal_sign"; | |
10962 | case DW_AT_digit_count: | |
10963 | return "DW_AT_digit_count"; | |
10964 | case DW_AT_picture_string: | |
10965 | return "DW_AT_picture_string"; | |
10966 | case DW_AT_mutable: | |
10967 | return "DW_AT_mutable"; | |
10968 | case DW_AT_threads_scaled: | |
10969 | return "DW_AT_threads_scaled"; | |
10970 | case DW_AT_explicit: | |
10971 | return "DW_AT_explicit"; | |
10972 | case DW_AT_object_pointer: | |
10973 | return "DW_AT_object_pointer"; | |
10974 | case DW_AT_endianity: | |
10975 | return "DW_AT_endianity"; | |
10976 | case DW_AT_elemental: | |
10977 | return "DW_AT_elemental"; | |
10978 | case DW_AT_pure: | |
10979 | return "DW_AT_pure"; | |
10980 | case DW_AT_recursive: | |
10981 | return "DW_AT_recursive"; | |
348e048f DE |
10982 | /* DWARF 4 values. */ |
10983 | case DW_AT_signature: | |
10984 | return "DW_AT_signature"; | |
31ef98ae TT |
10985 | case DW_AT_linkage_name: |
10986 | return "DW_AT_linkage_name"; | |
b7619582 | 10987 | /* SGI/MIPS extensions. */ |
c764a876 | 10988 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
10989 | case DW_AT_MIPS_fde: |
10990 | return "DW_AT_MIPS_fde"; | |
c764a876 | 10991 | #endif |
c906108c SS |
10992 | case DW_AT_MIPS_loop_begin: |
10993 | return "DW_AT_MIPS_loop_begin"; | |
10994 | case DW_AT_MIPS_tail_loop_begin: | |
10995 | return "DW_AT_MIPS_tail_loop_begin"; | |
10996 | case DW_AT_MIPS_epilog_begin: | |
10997 | return "DW_AT_MIPS_epilog_begin"; | |
10998 | case DW_AT_MIPS_loop_unroll_factor: | |
10999 | return "DW_AT_MIPS_loop_unroll_factor"; | |
11000 | case DW_AT_MIPS_software_pipeline_depth: | |
11001 | return "DW_AT_MIPS_software_pipeline_depth"; | |
11002 | case DW_AT_MIPS_linkage_name: | |
11003 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
11004 | case DW_AT_MIPS_stride: |
11005 | return "DW_AT_MIPS_stride"; | |
11006 | case DW_AT_MIPS_abstract_name: | |
11007 | return "DW_AT_MIPS_abstract_name"; | |
11008 | case DW_AT_MIPS_clone_origin: | |
11009 | return "DW_AT_MIPS_clone_origin"; | |
11010 | case DW_AT_MIPS_has_inlines: | |
11011 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 11012 | /* HP extensions. */ |
c764a876 | 11013 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
11014 | case DW_AT_HP_block_index: |
11015 | return "DW_AT_HP_block_index"; | |
c764a876 | 11016 | #endif |
b7619582 GF |
11017 | case DW_AT_HP_unmodifiable: |
11018 | return "DW_AT_HP_unmodifiable"; | |
11019 | case DW_AT_HP_actuals_stmt_list: | |
11020 | return "DW_AT_HP_actuals_stmt_list"; | |
11021 | case DW_AT_HP_proc_per_section: | |
11022 | return "DW_AT_HP_proc_per_section"; | |
11023 | case DW_AT_HP_raw_data_ptr: | |
11024 | return "DW_AT_HP_raw_data_ptr"; | |
11025 | case DW_AT_HP_pass_by_reference: | |
11026 | return "DW_AT_HP_pass_by_reference"; | |
11027 | case DW_AT_HP_opt_level: | |
11028 | return "DW_AT_HP_opt_level"; | |
11029 | case DW_AT_HP_prof_version_id: | |
11030 | return "DW_AT_HP_prof_version_id"; | |
11031 | case DW_AT_HP_opt_flags: | |
11032 | return "DW_AT_HP_opt_flags"; | |
11033 | case DW_AT_HP_cold_region_low_pc: | |
11034 | return "DW_AT_HP_cold_region_low_pc"; | |
11035 | case DW_AT_HP_cold_region_high_pc: | |
11036 | return "DW_AT_HP_cold_region_high_pc"; | |
11037 | case DW_AT_HP_all_variables_modifiable: | |
11038 | return "DW_AT_HP_all_variables_modifiable"; | |
11039 | case DW_AT_HP_linkage_name: | |
11040 | return "DW_AT_HP_linkage_name"; | |
11041 | case DW_AT_HP_prof_flags: | |
11042 | return "DW_AT_HP_prof_flags"; | |
11043 | /* GNU extensions. */ | |
c906108c SS |
11044 | case DW_AT_sf_names: |
11045 | return "DW_AT_sf_names"; | |
11046 | case DW_AT_src_info: | |
11047 | return "DW_AT_src_info"; | |
11048 | case DW_AT_mac_info: | |
11049 | return "DW_AT_mac_info"; | |
11050 | case DW_AT_src_coords: | |
11051 | return "DW_AT_src_coords"; | |
11052 | case DW_AT_body_begin: | |
11053 | return "DW_AT_body_begin"; | |
11054 | case DW_AT_body_end: | |
11055 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
11056 | case DW_AT_GNU_vector: |
11057 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
11058 | /* VMS extensions. */ |
11059 | case DW_AT_VMS_rtnbeg_pd_address: | |
11060 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
11061 | /* UPC extension. */ | |
11062 | case DW_AT_upc_threads_scaled: | |
11063 | return "DW_AT_upc_threads_scaled"; | |
11064 | /* PGI (STMicroelectronics) extensions. */ | |
11065 | case DW_AT_PGI_lbase: | |
11066 | return "DW_AT_PGI_lbase"; | |
11067 | case DW_AT_PGI_soffset: | |
11068 | return "DW_AT_PGI_soffset"; | |
11069 | case DW_AT_PGI_lstride: | |
11070 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
11071 | default: |
11072 | return "DW_AT_<unknown>"; | |
11073 | } | |
11074 | } | |
11075 | ||
11076 | /* Convert a DWARF value form code into its string name. */ | |
11077 | ||
11078 | static char * | |
aa1ee363 | 11079 | dwarf_form_name (unsigned form) |
c906108c SS |
11080 | { |
11081 | switch (form) | |
11082 | { | |
11083 | case DW_FORM_addr: | |
11084 | return "DW_FORM_addr"; | |
11085 | case DW_FORM_block2: | |
11086 | return "DW_FORM_block2"; | |
11087 | case DW_FORM_block4: | |
11088 | return "DW_FORM_block4"; | |
11089 | case DW_FORM_data2: | |
11090 | return "DW_FORM_data2"; | |
11091 | case DW_FORM_data4: | |
11092 | return "DW_FORM_data4"; | |
11093 | case DW_FORM_data8: | |
11094 | return "DW_FORM_data8"; | |
11095 | case DW_FORM_string: | |
11096 | return "DW_FORM_string"; | |
11097 | case DW_FORM_block: | |
11098 | return "DW_FORM_block"; | |
11099 | case DW_FORM_block1: | |
11100 | return "DW_FORM_block1"; | |
11101 | case DW_FORM_data1: | |
11102 | return "DW_FORM_data1"; | |
11103 | case DW_FORM_flag: | |
11104 | return "DW_FORM_flag"; | |
11105 | case DW_FORM_sdata: | |
11106 | return "DW_FORM_sdata"; | |
11107 | case DW_FORM_strp: | |
11108 | return "DW_FORM_strp"; | |
11109 | case DW_FORM_udata: | |
11110 | return "DW_FORM_udata"; | |
11111 | case DW_FORM_ref_addr: | |
11112 | return "DW_FORM_ref_addr"; | |
11113 | case DW_FORM_ref1: | |
11114 | return "DW_FORM_ref1"; | |
11115 | case DW_FORM_ref2: | |
11116 | return "DW_FORM_ref2"; | |
11117 | case DW_FORM_ref4: | |
11118 | return "DW_FORM_ref4"; | |
11119 | case DW_FORM_ref8: | |
11120 | return "DW_FORM_ref8"; | |
11121 | case DW_FORM_ref_udata: | |
11122 | return "DW_FORM_ref_udata"; | |
11123 | case DW_FORM_indirect: | |
11124 | return "DW_FORM_indirect"; | |
348e048f DE |
11125 | case DW_FORM_sec_offset: |
11126 | return "DW_FORM_sec_offset"; | |
11127 | case DW_FORM_exprloc: | |
11128 | return "DW_FORM_exprloc"; | |
11129 | case DW_FORM_flag_present: | |
11130 | return "DW_FORM_flag_present"; | |
11131 | case DW_FORM_sig8: | |
11132 | return "DW_FORM_sig8"; | |
c906108c SS |
11133 | default: |
11134 | return "DW_FORM_<unknown>"; | |
11135 | } | |
11136 | } | |
11137 | ||
11138 | /* Convert a DWARF stack opcode into its string name. */ | |
11139 | ||
9eae7c52 TT |
11140 | const char * |
11141 | dwarf_stack_op_name (unsigned op, int def) | |
c906108c SS |
11142 | { |
11143 | switch (op) | |
11144 | { | |
11145 | case DW_OP_addr: | |
11146 | return "DW_OP_addr"; | |
11147 | case DW_OP_deref: | |
11148 | return "DW_OP_deref"; | |
11149 | case DW_OP_const1u: | |
11150 | return "DW_OP_const1u"; | |
11151 | case DW_OP_const1s: | |
11152 | return "DW_OP_const1s"; | |
11153 | case DW_OP_const2u: | |
11154 | return "DW_OP_const2u"; | |
11155 | case DW_OP_const2s: | |
11156 | return "DW_OP_const2s"; | |
11157 | case DW_OP_const4u: | |
11158 | return "DW_OP_const4u"; | |
11159 | case DW_OP_const4s: | |
11160 | return "DW_OP_const4s"; | |
11161 | case DW_OP_const8u: | |
11162 | return "DW_OP_const8u"; | |
11163 | case DW_OP_const8s: | |
11164 | return "DW_OP_const8s"; | |
11165 | case DW_OP_constu: | |
11166 | return "DW_OP_constu"; | |
11167 | case DW_OP_consts: | |
11168 | return "DW_OP_consts"; | |
11169 | case DW_OP_dup: | |
11170 | return "DW_OP_dup"; | |
11171 | case DW_OP_drop: | |
11172 | return "DW_OP_drop"; | |
11173 | case DW_OP_over: | |
11174 | return "DW_OP_over"; | |
11175 | case DW_OP_pick: | |
11176 | return "DW_OP_pick"; | |
11177 | case DW_OP_swap: | |
11178 | return "DW_OP_swap"; | |
11179 | case DW_OP_rot: | |
11180 | return "DW_OP_rot"; | |
11181 | case DW_OP_xderef: | |
11182 | return "DW_OP_xderef"; | |
11183 | case DW_OP_abs: | |
11184 | return "DW_OP_abs"; | |
11185 | case DW_OP_and: | |
11186 | return "DW_OP_and"; | |
11187 | case DW_OP_div: | |
11188 | return "DW_OP_div"; | |
11189 | case DW_OP_minus: | |
11190 | return "DW_OP_minus"; | |
11191 | case DW_OP_mod: | |
11192 | return "DW_OP_mod"; | |
11193 | case DW_OP_mul: | |
11194 | return "DW_OP_mul"; | |
11195 | case DW_OP_neg: | |
11196 | return "DW_OP_neg"; | |
11197 | case DW_OP_not: | |
11198 | return "DW_OP_not"; | |
11199 | case DW_OP_or: | |
11200 | return "DW_OP_or"; | |
11201 | case DW_OP_plus: | |
11202 | return "DW_OP_plus"; | |
11203 | case DW_OP_plus_uconst: | |
11204 | return "DW_OP_plus_uconst"; | |
11205 | case DW_OP_shl: | |
11206 | return "DW_OP_shl"; | |
11207 | case DW_OP_shr: | |
11208 | return "DW_OP_shr"; | |
11209 | case DW_OP_shra: | |
11210 | return "DW_OP_shra"; | |
11211 | case DW_OP_xor: | |
11212 | return "DW_OP_xor"; | |
11213 | case DW_OP_bra: | |
11214 | return "DW_OP_bra"; | |
11215 | case DW_OP_eq: | |
11216 | return "DW_OP_eq"; | |
11217 | case DW_OP_ge: | |
11218 | return "DW_OP_ge"; | |
11219 | case DW_OP_gt: | |
11220 | return "DW_OP_gt"; | |
11221 | case DW_OP_le: | |
11222 | return "DW_OP_le"; | |
11223 | case DW_OP_lt: | |
11224 | return "DW_OP_lt"; | |
11225 | case DW_OP_ne: | |
11226 | return "DW_OP_ne"; | |
11227 | case DW_OP_skip: | |
11228 | return "DW_OP_skip"; | |
11229 | case DW_OP_lit0: | |
11230 | return "DW_OP_lit0"; | |
11231 | case DW_OP_lit1: | |
11232 | return "DW_OP_lit1"; | |
11233 | case DW_OP_lit2: | |
11234 | return "DW_OP_lit2"; | |
11235 | case DW_OP_lit3: | |
11236 | return "DW_OP_lit3"; | |
11237 | case DW_OP_lit4: | |
11238 | return "DW_OP_lit4"; | |
11239 | case DW_OP_lit5: | |
11240 | return "DW_OP_lit5"; | |
11241 | case DW_OP_lit6: | |
11242 | return "DW_OP_lit6"; | |
11243 | case DW_OP_lit7: | |
11244 | return "DW_OP_lit7"; | |
11245 | case DW_OP_lit8: | |
11246 | return "DW_OP_lit8"; | |
11247 | case DW_OP_lit9: | |
11248 | return "DW_OP_lit9"; | |
11249 | case DW_OP_lit10: | |
11250 | return "DW_OP_lit10"; | |
11251 | case DW_OP_lit11: | |
11252 | return "DW_OP_lit11"; | |
11253 | case DW_OP_lit12: | |
11254 | return "DW_OP_lit12"; | |
11255 | case DW_OP_lit13: | |
11256 | return "DW_OP_lit13"; | |
11257 | case DW_OP_lit14: | |
11258 | return "DW_OP_lit14"; | |
11259 | case DW_OP_lit15: | |
11260 | return "DW_OP_lit15"; | |
11261 | case DW_OP_lit16: | |
11262 | return "DW_OP_lit16"; | |
11263 | case DW_OP_lit17: | |
11264 | return "DW_OP_lit17"; | |
11265 | case DW_OP_lit18: | |
11266 | return "DW_OP_lit18"; | |
11267 | case DW_OP_lit19: | |
11268 | return "DW_OP_lit19"; | |
11269 | case DW_OP_lit20: | |
11270 | return "DW_OP_lit20"; | |
11271 | case DW_OP_lit21: | |
11272 | return "DW_OP_lit21"; | |
11273 | case DW_OP_lit22: | |
11274 | return "DW_OP_lit22"; | |
11275 | case DW_OP_lit23: | |
11276 | return "DW_OP_lit23"; | |
11277 | case DW_OP_lit24: | |
11278 | return "DW_OP_lit24"; | |
11279 | case DW_OP_lit25: | |
11280 | return "DW_OP_lit25"; | |
11281 | case DW_OP_lit26: | |
11282 | return "DW_OP_lit26"; | |
11283 | case DW_OP_lit27: | |
11284 | return "DW_OP_lit27"; | |
11285 | case DW_OP_lit28: | |
11286 | return "DW_OP_lit28"; | |
11287 | case DW_OP_lit29: | |
11288 | return "DW_OP_lit29"; | |
11289 | case DW_OP_lit30: | |
11290 | return "DW_OP_lit30"; | |
11291 | case DW_OP_lit31: | |
11292 | return "DW_OP_lit31"; | |
11293 | case DW_OP_reg0: | |
11294 | return "DW_OP_reg0"; | |
11295 | case DW_OP_reg1: | |
11296 | return "DW_OP_reg1"; | |
11297 | case DW_OP_reg2: | |
11298 | return "DW_OP_reg2"; | |
11299 | case DW_OP_reg3: | |
11300 | return "DW_OP_reg3"; | |
11301 | case DW_OP_reg4: | |
11302 | return "DW_OP_reg4"; | |
11303 | case DW_OP_reg5: | |
11304 | return "DW_OP_reg5"; | |
11305 | case DW_OP_reg6: | |
11306 | return "DW_OP_reg6"; | |
11307 | case DW_OP_reg7: | |
11308 | return "DW_OP_reg7"; | |
11309 | case DW_OP_reg8: | |
11310 | return "DW_OP_reg8"; | |
11311 | case DW_OP_reg9: | |
11312 | return "DW_OP_reg9"; | |
11313 | case DW_OP_reg10: | |
11314 | return "DW_OP_reg10"; | |
11315 | case DW_OP_reg11: | |
11316 | return "DW_OP_reg11"; | |
11317 | case DW_OP_reg12: | |
11318 | return "DW_OP_reg12"; | |
11319 | case DW_OP_reg13: | |
11320 | return "DW_OP_reg13"; | |
11321 | case DW_OP_reg14: | |
11322 | return "DW_OP_reg14"; | |
11323 | case DW_OP_reg15: | |
11324 | return "DW_OP_reg15"; | |
11325 | case DW_OP_reg16: | |
11326 | return "DW_OP_reg16"; | |
11327 | case DW_OP_reg17: | |
11328 | return "DW_OP_reg17"; | |
11329 | case DW_OP_reg18: | |
11330 | return "DW_OP_reg18"; | |
11331 | case DW_OP_reg19: | |
11332 | return "DW_OP_reg19"; | |
11333 | case DW_OP_reg20: | |
11334 | return "DW_OP_reg20"; | |
11335 | case DW_OP_reg21: | |
11336 | return "DW_OP_reg21"; | |
11337 | case DW_OP_reg22: | |
11338 | return "DW_OP_reg22"; | |
11339 | case DW_OP_reg23: | |
11340 | return "DW_OP_reg23"; | |
11341 | case DW_OP_reg24: | |
11342 | return "DW_OP_reg24"; | |
11343 | case DW_OP_reg25: | |
11344 | return "DW_OP_reg25"; | |
11345 | case DW_OP_reg26: | |
11346 | return "DW_OP_reg26"; | |
11347 | case DW_OP_reg27: | |
11348 | return "DW_OP_reg27"; | |
11349 | case DW_OP_reg28: | |
11350 | return "DW_OP_reg28"; | |
11351 | case DW_OP_reg29: | |
11352 | return "DW_OP_reg29"; | |
11353 | case DW_OP_reg30: | |
11354 | return "DW_OP_reg30"; | |
11355 | case DW_OP_reg31: | |
11356 | return "DW_OP_reg31"; | |
11357 | case DW_OP_breg0: | |
11358 | return "DW_OP_breg0"; | |
11359 | case DW_OP_breg1: | |
11360 | return "DW_OP_breg1"; | |
11361 | case DW_OP_breg2: | |
11362 | return "DW_OP_breg2"; | |
11363 | case DW_OP_breg3: | |
11364 | return "DW_OP_breg3"; | |
11365 | case DW_OP_breg4: | |
11366 | return "DW_OP_breg4"; | |
11367 | case DW_OP_breg5: | |
11368 | return "DW_OP_breg5"; | |
11369 | case DW_OP_breg6: | |
11370 | return "DW_OP_breg6"; | |
11371 | case DW_OP_breg7: | |
11372 | return "DW_OP_breg7"; | |
11373 | case DW_OP_breg8: | |
11374 | return "DW_OP_breg8"; | |
11375 | case DW_OP_breg9: | |
11376 | return "DW_OP_breg9"; | |
11377 | case DW_OP_breg10: | |
11378 | return "DW_OP_breg10"; | |
11379 | case DW_OP_breg11: | |
11380 | return "DW_OP_breg11"; | |
11381 | case DW_OP_breg12: | |
11382 | return "DW_OP_breg12"; | |
11383 | case DW_OP_breg13: | |
11384 | return "DW_OP_breg13"; | |
11385 | case DW_OP_breg14: | |
11386 | return "DW_OP_breg14"; | |
11387 | case DW_OP_breg15: | |
11388 | return "DW_OP_breg15"; | |
11389 | case DW_OP_breg16: | |
11390 | return "DW_OP_breg16"; | |
11391 | case DW_OP_breg17: | |
11392 | return "DW_OP_breg17"; | |
11393 | case DW_OP_breg18: | |
11394 | return "DW_OP_breg18"; | |
11395 | case DW_OP_breg19: | |
11396 | return "DW_OP_breg19"; | |
11397 | case DW_OP_breg20: | |
11398 | return "DW_OP_breg20"; | |
11399 | case DW_OP_breg21: | |
11400 | return "DW_OP_breg21"; | |
11401 | case DW_OP_breg22: | |
11402 | return "DW_OP_breg22"; | |
11403 | case DW_OP_breg23: | |
11404 | return "DW_OP_breg23"; | |
11405 | case DW_OP_breg24: | |
11406 | return "DW_OP_breg24"; | |
11407 | case DW_OP_breg25: | |
11408 | return "DW_OP_breg25"; | |
11409 | case DW_OP_breg26: | |
11410 | return "DW_OP_breg26"; | |
11411 | case DW_OP_breg27: | |
11412 | return "DW_OP_breg27"; | |
11413 | case DW_OP_breg28: | |
11414 | return "DW_OP_breg28"; | |
11415 | case DW_OP_breg29: | |
11416 | return "DW_OP_breg29"; | |
11417 | case DW_OP_breg30: | |
11418 | return "DW_OP_breg30"; | |
11419 | case DW_OP_breg31: | |
11420 | return "DW_OP_breg31"; | |
11421 | case DW_OP_regx: | |
11422 | return "DW_OP_regx"; | |
11423 | case DW_OP_fbreg: | |
11424 | return "DW_OP_fbreg"; | |
11425 | case DW_OP_bregx: | |
11426 | return "DW_OP_bregx"; | |
11427 | case DW_OP_piece: | |
11428 | return "DW_OP_piece"; | |
11429 | case DW_OP_deref_size: | |
11430 | return "DW_OP_deref_size"; | |
11431 | case DW_OP_xderef_size: | |
11432 | return "DW_OP_xderef_size"; | |
11433 | case DW_OP_nop: | |
11434 | return "DW_OP_nop"; | |
b7619582 | 11435 | /* DWARF 3 extensions. */ |
ed348acc EZ |
11436 | case DW_OP_push_object_address: |
11437 | return "DW_OP_push_object_address"; | |
11438 | case DW_OP_call2: | |
11439 | return "DW_OP_call2"; | |
11440 | case DW_OP_call4: | |
11441 | return "DW_OP_call4"; | |
11442 | case DW_OP_call_ref: | |
11443 | return "DW_OP_call_ref"; | |
b7619582 GF |
11444 | case DW_OP_form_tls_address: |
11445 | return "DW_OP_form_tls_address"; | |
11446 | case DW_OP_call_frame_cfa: | |
11447 | return "DW_OP_call_frame_cfa"; | |
11448 | case DW_OP_bit_piece: | |
11449 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
11450 | /* DWARF 4 extensions. */ |
11451 | case DW_OP_implicit_value: | |
11452 | return "DW_OP_implicit_value"; | |
11453 | case DW_OP_stack_value: | |
11454 | return "DW_OP_stack_value"; | |
11455 | /* GNU extensions. */ | |
ed348acc EZ |
11456 | case DW_OP_GNU_push_tls_address: |
11457 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
11458 | case DW_OP_GNU_uninit: |
11459 | return "DW_OP_GNU_uninit"; | |
c906108c | 11460 | default: |
9eae7c52 | 11461 | return def ? "OP_<unknown>" : NULL; |
c906108c SS |
11462 | } |
11463 | } | |
11464 | ||
11465 | static char * | |
fba45db2 | 11466 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
11467 | { |
11468 | if (mybool) | |
11469 | return "TRUE"; | |
11470 | else | |
11471 | return "FALSE"; | |
11472 | } | |
11473 | ||
11474 | /* Convert a DWARF type code into its string name. */ | |
11475 | ||
11476 | static char * | |
aa1ee363 | 11477 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
11478 | { |
11479 | switch (enc) | |
11480 | { | |
b7619582 GF |
11481 | case DW_ATE_void: |
11482 | return "DW_ATE_void"; | |
c906108c SS |
11483 | case DW_ATE_address: |
11484 | return "DW_ATE_address"; | |
11485 | case DW_ATE_boolean: | |
11486 | return "DW_ATE_boolean"; | |
11487 | case DW_ATE_complex_float: | |
11488 | return "DW_ATE_complex_float"; | |
11489 | case DW_ATE_float: | |
11490 | return "DW_ATE_float"; | |
11491 | case DW_ATE_signed: | |
11492 | return "DW_ATE_signed"; | |
11493 | case DW_ATE_signed_char: | |
11494 | return "DW_ATE_signed_char"; | |
11495 | case DW_ATE_unsigned: | |
11496 | return "DW_ATE_unsigned"; | |
11497 | case DW_ATE_unsigned_char: | |
11498 | return "DW_ATE_unsigned_char"; | |
b7619582 | 11499 | /* DWARF 3. */ |
d9fa45fe DC |
11500 | case DW_ATE_imaginary_float: |
11501 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
11502 | case DW_ATE_packed_decimal: |
11503 | return "DW_ATE_packed_decimal"; | |
11504 | case DW_ATE_numeric_string: | |
11505 | return "DW_ATE_numeric_string"; | |
11506 | case DW_ATE_edited: | |
11507 | return "DW_ATE_edited"; | |
11508 | case DW_ATE_signed_fixed: | |
11509 | return "DW_ATE_signed_fixed"; | |
11510 | case DW_ATE_unsigned_fixed: | |
11511 | return "DW_ATE_unsigned_fixed"; | |
11512 | case DW_ATE_decimal_float: | |
11513 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
11514 | /* DWARF 4. */ |
11515 | case DW_ATE_UTF: | |
11516 | return "DW_ATE_UTF"; | |
b7619582 GF |
11517 | /* HP extensions. */ |
11518 | case DW_ATE_HP_float80: | |
11519 | return "DW_ATE_HP_float80"; | |
11520 | case DW_ATE_HP_complex_float80: | |
11521 | return "DW_ATE_HP_complex_float80"; | |
11522 | case DW_ATE_HP_float128: | |
11523 | return "DW_ATE_HP_float128"; | |
11524 | case DW_ATE_HP_complex_float128: | |
11525 | return "DW_ATE_HP_complex_float128"; | |
11526 | case DW_ATE_HP_floathpintel: | |
11527 | return "DW_ATE_HP_floathpintel"; | |
11528 | case DW_ATE_HP_imaginary_float80: | |
11529 | return "DW_ATE_HP_imaginary_float80"; | |
11530 | case DW_ATE_HP_imaginary_float128: | |
11531 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
11532 | default: |
11533 | return "DW_ATE_<unknown>"; | |
11534 | } | |
11535 | } | |
11536 | ||
11537 | /* Convert a DWARF call frame info operation to its string name. */ | |
11538 | ||
11539 | #if 0 | |
11540 | static char * | |
aa1ee363 | 11541 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
11542 | { |
11543 | switch (cfi_opc) | |
11544 | { | |
11545 | case DW_CFA_advance_loc: | |
11546 | return "DW_CFA_advance_loc"; | |
11547 | case DW_CFA_offset: | |
11548 | return "DW_CFA_offset"; | |
11549 | case DW_CFA_restore: | |
11550 | return "DW_CFA_restore"; | |
11551 | case DW_CFA_nop: | |
11552 | return "DW_CFA_nop"; | |
11553 | case DW_CFA_set_loc: | |
11554 | return "DW_CFA_set_loc"; | |
11555 | case DW_CFA_advance_loc1: | |
11556 | return "DW_CFA_advance_loc1"; | |
11557 | case DW_CFA_advance_loc2: | |
11558 | return "DW_CFA_advance_loc2"; | |
11559 | case DW_CFA_advance_loc4: | |
11560 | return "DW_CFA_advance_loc4"; | |
11561 | case DW_CFA_offset_extended: | |
11562 | return "DW_CFA_offset_extended"; | |
11563 | case DW_CFA_restore_extended: | |
11564 | return "DW_CFA_restore_extended"; | |
11565 | case DW_CFA_undefined: | |
11566 | return "DW_CFA_undefined"; | |
11567 | case DW_CFA_same_value: | |
11568 | return "DW_CFA_same_value"; | |
11569 | case DW_CFA_register: | |
11570 | return "DW_CFA_register"; | |
11571 | case DW_CFA_remember_state: | |
11572 | return "DW_CFA_remember_state"; | |
11573 | case DW_CFA_restore_state: | |
11574 | return "DW_CFA_restore_state"; | |
11575 | case DW_CFA_def_cfa: | |
11576 | return "DW_CFA_def_cfa"; | |
11577 | case DW_CFA_def_cfa_register: | |
11578 | return "DW_CFA_def_cfa_register"; | |
11579 | case DW_CFA_def_cfa_offset: | |
11580 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 11581 | /* DWARF 3. */ |
985cb1a3 JM |
11582 | case DW_CFA_def_cfa_expression: |
11583 | return "DW_CFA_def_cfa_expression"; | |
11584 | case DW_CFA_expression: | |
11585 | return "DW_CFA_expression"; | |
11586 | case DW_CFA_offset_extended_sf: | |
11587 | return "DW_CFA_offset_extended_sf"; | |
11588 | case DW_CFA_def_cfa_sf: | |
11589 | return "DW_CFA_def_cfa_sf"; | |
11590 | case DW_CFA_def_cfa_offset_sf: | |
11591 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
11592 | case DW_CFA_val_offset: |
11593 | return "DW_CFA_val_offset"; | |
11594 | case DW_CFA_val_offset_sf: | |
11595 | return "DW_CFA_val_offset_sf"; | |
11596 | case DW_CFA_val_expression: | |
11597 | return "DW_CFA_val_expression"; | |
11598 | /* SGI/MIPS specific. */ | |
c906108c SS |
11599 | case DW_CFA_MIPS_advance_loc8: |
11600 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 11601 | /* GNU extensions. */ |
985cb1a3 JM |
11602 | case DW_CFA_GNU_window_save: |
11603 | return "DW_CFA_GNU_window_save"; | |
11604 | case DW_CFA_GNU_args_size: | |
11605 | return "DW_CFA_GNU_args_size"; | |
11606 | case DW_CFA_GNU_negative_offset_extended: | |
11607 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
11608 | default: |
11609 | return "DW_CFA_<unknown>"; | |
11610 | } | |
11611 | } | |
11612 | #endif | |
11613 | ||
f9aca02d | 11614 | static void |
d97bc12b | 11615 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
11616 | { |
11617 | unsigned int i; | |
11618 | ||
d97bc12b DE |
11619 | print_spaces (indent, f); |
11620 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 11621 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
11622 | |
11623 | if (die->parent != NULL) | |
11624 | { | |
11625 | print_spaces (indent, f); | |
11626 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
11627 | die->parent->offset); | |
11628 | } | |
11629 | ||
11630 | print_spaces (indent, f); | |
11631 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 11632 | dwarf_bool_name (die->child != NULL)); |
c906108c | 11633 | |
d97bc12b DE |
11634 | print_spaces (indent, f); |
11635 | fprintf_unfiltered (f, " attributes:\n"); | |
11636 | ||
c906108c SS |
11637 | for (i = 0; i < die->num_attrs; ++i) |
11638 | { | |
d97bc12b DE |
11639 | print_spaces (indent, f); |
11640 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
11641 | dwarf_attr_name (die->attrs[i].name), |
11642 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 11643 | |
c906108c SS |
11644 | switch (die->attrs[i].form) |
11645 | { | |
11646 | case DW_FORM_ref_addr: | |
11647 | case DW_FORM_addr: | |
d97bc12b | 11648 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 11649 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
11650 | break; |
11651 | case DW_FORM_block2: | |
11652 | case DW_FORM_block4: | |
11653 | case DW_FORM_block: | |
11654 | case DW_FORM_block1: | |
d97bc12b | 11655 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 11656 | break; |
2dc7f7b3 TT |
11657 | case DW_FORM_exprloc: |
11658 | fprintf_unfiltered (f, "expression: size %u", | |
11659 | DW_BLOCK (&die->attrs[i])->size); | |
11660 | break; | |
10b3939b DJ |
11661 | case DW_FORM_ref1: |
11662 | case DW_FORM_ref2: | |
11663 | case DW_FORM_ref4: | |
d97bc12b | 11664 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
11665 | (long) (DW_ADDR (&die->attrs[i]))); |
11666 | break; | |
c906108c SS |
11667 | case DW_FORM_data1: |
11668 | case DW_FORM_data2: | |
11669 | case DW_FORM_data4: | |
ce5d95e1 | 11670 | case DW_FORM_data8: |
c906108c SS |
11671 | case DW_FORM_udata: |
11672 | case DW_FORM_sdata: | |
43bbcdc2 PH |
11673 | fprintf_unfiltered (f, "constant: %s", |
11674 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 11675 | break; |
2dc7f7b3 TT |
11676 | case DW_FORM_sec_offset: |
11677 | fprintf_unfiltered (f, "section offset: %s", | |
11678 | pulongest (DW_UNSND (&die->attrs[i]))); | |
11679 | break; | |
348e048f DE |
11680 | case DW_FORM_sig8: |
11681 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
11682 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
11683 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
11684 | else | |
11685 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
11686 | break; | |
c906108c | 11687 | case DW_FORM_string: |
4bdf3d34 | 11688 | case DW_FORM_strp: |
8285870a | 11689 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 11690 | DW_STRING (&die->attrs[i]) |
8285870a JK |
11691 | ? DW_STRING (&die->attrs[i]) : "", |
11692 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
11693 | break; |
11694 | case DW_FORM_flag: | |
11695 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 11696 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 11697 | else |
d97bc12b | 11698 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 11699 | break; |
2dc7f7b3 TT |
11700 | case DW_FORM_flag_present: |
11701 | fprintf_unfiltered (f, "flag: TRUE"); | |
11702 | break; | |
a8329558 KW |
11703 | case DW_FORM_indirect: |
11704 | /* the reader will have reduced the indirect form to | |
11705 | the "base form" so this form should not occur */ | |
d97bc12b | 11706 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 11707 | break; |
c906108c | 11708 | default: |
d97bc12b | 11709 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 11710 | die->attrs[i].form); |
d97bc12b | 11711 | break; |
c906108c | 11712 | } |
d97bc12b | 11713 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
11714 | } |
11715 | } | |
11716 | ||
f9aca02d | 11717 | static void |
d97bc12b | 11718 | dump_die_for_error (struct die_info *die) |
c906108c | 11719 | { |
d97bc12b DE |
11720 | dump_die_shallow (gdb_stderr, 0, die); |
11721 | } | |
11722 | ||
11723 | static void | |
11724 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
11725 | { | |
11726 | int indent = level * 4; | |
11727 | ||
11728 | gdb_assert (die != NULL); | |
11729 | ||
11730 | if (level >= max_level) | |
11731 | return; | |
11732 | ||
11733 | dump_die_shallow (f, indent, die); | |
11734 | ||
11735 | if (die->child != NULL) | |
c906108c | 11736 | { |
d97bc12b DE |
11737 | print_spaces (indent, f); |
11738 | fprintf_unfiltered (f, " Children:"); | |
11739 | if (level + 1 < max_level) | |
11740 | { | |
11741 | fprintf_unfiltered (f, "\n"); | |
11742 | dump_die_1 (f, level + 1, max_level, die->child); | |
11743 | } | |
11744 | else | |
11745 | { | |
11746 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
11747 | } | |
11748 | } | |
11749 | ||
11750 | if (die->sibling != NULL && level > 0) | |
11751 | { | |
11752 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
11753 | } |
11754 | } | |
11755 | ||
d97bc12b DE |
11756 | /* This is called from the pdie macro in gdbinit.in. |
11757 | It's not static so gcc will keep a copy callable from gdb. */ | |
11758 | ||
11759 | void | |
11760 | dump_die (struct die_info *die, int max_level) | |
11761 | { | |
11762 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
11763 | } | |
11764 | ||
f9aca02d | 11765 | static void |
51545339 | 11766 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11767 | { |
51545339 | 11768 | void **slot; |
c906108c | 11769 | |
51545339 DJ |
11770 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
11771 | ||
11772 | *slot = die; | |
c906108c SS |
11773 | } |
11774 | ||
93311388 DE |
11775 | static int |
11776 | is_ref_attr (struct attribute *attr) | |
c906108c | 11777 | { |
c906108c SS |
11778 | switch (attr->form) |
11779 | { | |
11780 | case DW_FORM_ref_addr: | |
c906108c SS |
11781 | case DW_FORM_ref1: |
11782 | case DW_FORM_ref2: | |
11783 | case DW_FORM_ref4: | |
613e1657 | 11784 | case DW_FORM_ref8: |
c906108c | 11785 | case DW_FORM_ref_udata: |
93311388 | 11786 | return 1; |
c906108c | 11787 | default: |
93311388 | 11788 | return 0; |
c906108c | 11789 | } |
93311388 DE |
11790 | } |
11791 | ||
11792 | static unsigned int | |
11793 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
11794 | { | |
11795 | if (is_ref_attr (attr)) | |
11796 | return DW_ADDR (attr); | |
11797 | ||
11798 | complaint (&symfile_complaints, | |
11799 | _("unsupported die ref attribute form: '%s'"), | |
11800 | dwarf_form_name (attr->form)); | |
11801 | return 0; | |
c906108c SS |
11802 | } |
11803 | ||
43bbcdc2 PH |
11804 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
11805 | * the value held by the attribute is not constant. */ | |
a02abb62 | 11806 | |
43bbcdc2 | 11807 | static LONGEST |
a02abb62 JB |
11808 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
11809 | { | |
11810 | if (attr->form == DW_FORM_sdata) | |
11811 | return DW_SND (attr); | |
11812 | else if (attr->form == DW_FORM_udata | |
11813 | || attr->form == DW_FORM_data1 | |
11814 | || attr->form == DW_FORM_data2 | |
11815 | || attr->form == DW_FORM_data4 | |
11816 | || attr->form == DW_FORM_data8) | |
11817 | return DW_UNSND (attr); | |
11818 | else | |
11819 | { | |
e2e0b3e5 | 11820 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
11821 | dwarf_form_name (attr->form)); |
11822 | return default_value; | |
11823 | } | |
11824 | } | |
11825 | ||
03dd20cc | 11826 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
11827 | unit and add it to our queue. |
11828 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
11829 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 11830 | |
348e048f | 11831 | static int |
03dd20cc DJ |
11832 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
11833 | struct dwarf2_per_cu_data *per_cu) | |
11834 | { | |
11835 | /* Mark the dependence relation so that we don't flush PER_CU | |
11836 | too early. */ | |
11837 | dwarf2_add_dependence (this_cu, per_cu); | |
11838 | ||
11839 | /* If it's already on the queue, we have nothing to do. */ | |
11840 | if (per_cu->queued) | |
348e048f | 11841 | return 0; |
03dd20cc DJ |
11842 | |
11843 | /* If the compilation unit is already loaded, just mark it as | |
11844 | used. */ | |
11845 | if (per_cu->cu != NULL) | |
11846 | { | |
11847 | per_cu->cu->last_used = 0; | |
348e048f | 11848 | return 0; |
03dd20cc DJ |
11849 | } |
11850 | ||
11851 | /* Add it to the queue. */ | |
11852 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
11853 | |
11854 | return 1; | |
11855 | } | |
11856 | ||
11857 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
11858 | On entry *REF_CU is the CU of SRC_DIE. | |
11859 | On exit *REF_CU is the CU of the result. */ | |
11860 | ||
11861 | static struct die_info * | |
11862 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
11863 | struct dwarf2_cu **ref_cu) | |
11864 | { | |
11865 | struct die_info *die; | |
11866 | ||
11867 | if (is_ref_attr (attr)) | |
11868 | die = follow_die_ref (src_die, attr, ref_cu); | |
11869 | else if (attr->form == DW_FORM_sig8) | |
11870 | die = follow_die_sig (src_die, attr, ref_cu); | |
11871 | else | |
11872 | { | |
11873 | dump_die_for_error (src_die); | |
11874 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
11875 | (*ref_cu)->objfile->name); | |
11876 | } | |
11877 | ||
11878 | return die; | |
03dd20cc DJ |
11879 | } |
11880 | ||
5c631832 JK |
11881 | /* Follow reference OFFSET. |
11882 | On entry *REF_CU is the CU of source DIE referencing OFFSET. | |
f504f079 DE |
11883 | On exit *REF_CU is the CU of the result. */ |
11884 | ||
f9aca02d | 11885 | static struct die_info * |
5c631832 | 11886 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 11887 | { |
10b3939b | 11888 | struct die_info temp_die; |
f2f0e013 | 11889 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 11890 | |
348e048f DE |
11891 | gdb_assert (cu->per_cu != NULL); |
11892 | ||
348e048f DE |
11893 | if (cu->per_cu->from_debug_types) |
11894 | { | |
11895 | /* .debug_types CUs cannot reference anything outside their CU. | |
11896 | If they need to, they have to reference a signatured type via | |
11897 | DW_FORM_sig8. */ | |
11898 | if (! offset_in_cu_p (&cu->header, offset)) | |
5c631832 | 11899 | return NULL; |
348e048f DE |
11900 | target_cu = cu; |
11901 | } | |
11902 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
11903 | { |
11904 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 11905 | |
45452591 | 11906 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
11907 | |
11908 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
11909 | if (maybe_queue_comp_unit (cu, per_cu)) |
11910 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 11911 | |
10b3939b DJ |
11912 | target_cu = per_cu->cu; |
11913 | } | |
11914 | else | |
11915 | target_cu = cu; | |
c906108c | 11916 | |
f2f0e013 | 11917 | *ref_cu = target_cu; |
51545339 | 11918 | temp_die.offset = offset; |
5c631832 JK |
11919 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
11920 | } | |
10b3939b | 11921 | |
5c631832 JK |
11922 | /* Follow reference attribute ATTR of SRC_DIE. |
11923 | On entry *REF_CU is the CU of SRC_DIE. | |
11924 | On exit *REF_CU is the CU of the result. */ | |
11925 | ||
11926 | static struct die_info * | |
11927 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
11928 | struct dwarf2_cu **ref_cu) | |
11929 | { | |
11930 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11931 | struct dwarf2_cu *cu = *ref_cu; | |
11932 | struct die_info *die; | |
11933 | ||
11934 | die = follow_die_offset (offset, ref_cu); | |
11935 | if (!die) | |
11936 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
11937 | "at 0x%x [in module %s]"), | |
11938 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 11939 | |
5c631832 JK |
11940 | return die; |
11941 | } | |
11942 | ||
11943 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
11944 | value is intended for DW_OP_call*. */ | |
11945 | ||
11946 | struct dwarf2_locexpr_baton | |
11947 | dwarf2_fetch_die_location_block (unsigned int offset, | |
11948 | struct dwarf2_per_cu_data *per_cu) | |
11949 | { | |
11950 | struct dwarf2_cu *cu = per_cu->cu; | |
11951 | struct die_info *die; | |
11952 | struct attribute *attr; | |
11953 | struct dwarf2_locexpr_baton retval; | |
11954 | ||
11955 | die = follow_die_offset (offset, &cu); | |
11956 | if (!die) | |
11957 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
11958 | offset, per_cu->cu->objfile->name); | |
11959 | ||
11960 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
11961 | if (!attr) | |
11962 | { | |
11963 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
11964 | ||
11965 | retval.data = NULL; | |
11966 | retval.size = 0; | |
11967 | } | |
11968 | else | |
11969 | { | |
11970 | if (!attr_form_is_block (attr)) | |
11971 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
11972 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
11973 | offset, per_cu->cu->objfile->name); | |
11974 | ||
11975 | retval.data = DW_BLOCK (attr)->data; | |
11976 | retval.size = DW_BLOCK (attr)->size; | |
11977 | } | |
11978 | retval.per_cu = cu->per_cu; | |
11979 | return retval; | |
348e048f DE |
11980 | } |
11981 | ||
11982 | /* Follow the signature attribute ATTR in SRC_DIE. | |
11983 | On entry *REF_CU is the CU of SRC_DIE. | |
11984 | On exit *REF_CU is the CU of the result. */ | |
11985 | ||
11986 | static struct die_info * | |
11987 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
11988 | struct dwarf2_cu **ref_cu) | |
11989 | { | |
11990 | struct objfile *objfile = (*ref_cu)->objfile; | |
11991 | struct die_info temp_die; | |
11992 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11993 | struct dwarf2_cu *sig_cu; | |
11994 | struct die_info *die; | |
11995 | ||
11996 | /* sig_type will be NULL if the signatured type is missing from | |
11997 | the debug info. */ | |
11998 | if (sig_type == NULL) | |
11999 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12000 | "at 0x%x [in module %s]"), | |
12001 | src_die->offset, objfile->name); | |
12002 | ||
12003 | /* If necessary, add it to the queue and load its DIEs. */ | |
12004 | ||
12005 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
12006 | read_signatured_type (objfile, sig_type); | |
12007 | ||
12008 | gdb_assert (sig_type->per_cu.cu != NULL); | |
12009 | ||
12010 | sig_cu = sig_type->per_cu.cu; | |
12011 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
12012 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
12013 | if (die) | |
12014 | { | |
12015 | *ref_cu = sig_cu; | |
12016 | return die; | |
12017 | } | |
12018 | ||
12019 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
12020 | "at 0x%x [in module %s]"), | |
12021 | sig_type->type_offset, src_die->offset, objfile->name); | |
12022 | } | |
12023 | ||
12024 | /* Given an offset of a signatured type, return its signatured_type. */ | |
12025 | ||
12026 | static struct signatured_type * | |
12027 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
12028 | { | |
12029 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
12030 | unsigned int length, initial_length_size; | |
12031 | unsigned int sig_offset; | |
12032 | struct signatured_type find_entry, *type_sig; | |
12033 | ||
12034 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
12035 | sig_offset = (initial_length_size | |
12036 | + 2 /*version*/ | |
12037 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
12038 | + 1 /*address_size*/); | |
12039 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
12040 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
12041 | ||
12042 | /* This is only used to lookup previously recorded types. | |
12043 | If we didn't find it, it's our bug. */ | |
12044 | gdb_assert (type_sig != NULL); | |
12045 | gdb_assert (offset == type_sig->offset); | |
12046 | ||
12047 | return type_sig; | |
12048 | } | |
12049 | ||
12050 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
12051 | ||
12052 | static void | |
12053 | read_signatured_type_at_offset (struct objfile *objfile, | |
12054 | unsigned int offset) | |
12055 | { | |
12056 | struct signatured_type *type_sig; | |
12057 | ||
be391dca TT |
12058 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
12059 | ||
348e048f DE |
12060 | /* We have the section offset, but we need the signature to do the |
12061 | hash table lookup. */ | |
12062 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
12063 | ||
12064 | gdb_assert (type_sig->per_cu.cu == NULL); | |
12065 | ||
12066 | read_signatured_type (objfile, type_sig); | |
12067 | ||
12068 | gdb_assert (type_sig->per_cu.cu != NULL); | |
12069 | } | |
12070 | ||
12071 | /* Read in a signatured type and build its CU and DIEs. */ | |
12072 | ||
12073 | static void | |
12074 | read_signatured_type (struct objfile *objfile, | |
12075 | struct signatured_type *type_sig) | |
12076 | { | |
12077 | gdb_byte *types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
12078 | struct die_reader_specs reader_specs; | |
12079 | struct dwarf2_cu *cu; | |
12080 | ULONGEST signature; | |
12081 | struct cleanup *back_to, *free_cu_cleanup; | |
12082 | struct attribute *attr; | |
12083 | ||
12084 | gdb_assert (type_sig->per_cu.cu == NULL); | |
12085 | ||
12086 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
12087 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
12088 | obstack_init (&cu->comp_unit_obstack); | |
12089 | cu->objfile = objfile; | |
12090 | type_sig->per_cu.cu = cu; | |
12091 | cu->per_cu = &type_sig->per_cu; | |
12092 | ||
12093 | /* If an error occurs while loading, release our storage. */ | |
12094 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
12095 | ||
12096 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
12097 | types_ptr, objfile->obfd); | |
12098 | gdb_assert (signature == type_sig->signature); | |
12099 | ||
12100 | cu->die_hash | |
12101 | = htab_create_alloc_ex (cu->header.length / 12, | |
12102 | die_hash, | |
12103 | die_eq, | |
12104 | NULL, | |
12105 | &cu->comp_unit_obstack, | |
12106 | hashtab_obstack_allocate, | |
12107 | dummy_obstack_deallocate); | |
12108 | ||
12109 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
12110 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
12111 | ||
12112 | init_cu_die_reader (&reader_specs, cu); | |
12113 | ||
12114 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
12115 | NULL /*parent*/); | |
12116 | ||
12117 | /* We try not to read any attributes in this function, because not | |
12118 | all objfiles needed for references have been loaded yet, and symbol | |
12119 | table processing isn't initialized. But we have to set the CU language, | |
12120 | or we won't be able to build types correctly. */ | |
12121 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
12122 | if (attr) | |
12123 | set_cu_language (DW_UNSND (attr), cu); | |
12124 | else | |
12125 | set_cu_language (language_minimal, cu); | |
12126 | ||
12127 | do_cleanups (back_to); | |
12128 | ||
12129 | /* We've successfully allocated this compilation unit. Let our caller | |
12130 | clean it up when finished with it. */ | |
12131 | discard_cleanups (free_cu_cleanup); | |
12132 | ||
12133 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
12134 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
12135 | } |
12136 | ||
c906108c SS |
12137 | /* Decode simple location descriptions. |
12138 | Given a pointer to a dwarf block that defines a location, compute | |
12139 | the location and return the value. | |
12140 | ||
4cecd739 DJ |
12141 | NOTE drow/2003-11-18: This function is called in two situations |
12142 | now: for the address of static or global variables (partial symbols | |
12143 | only) and for offsets into structures which are expected to be | |
12144 | (more or less) constant. The partial symbol case should go away, | |
12145 | and only the constant case should remain. That will let this | |
12146 | function complain more accurately. A few special modes are allowed | |
12147 | without complaint for global variables (for instance, global | |
12148 | register values and thread-local values). | |
c906108c SS |
12149 | |
12150 | A location description containing no operations indicates that the | |
4cecd739 | 12151 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
12152 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
12153 | callers will only want a very basic result and this can become a | |
12154 | complaint. | |
c906108c | 12155 | |
c906108c SS |
12156 | Note that stack[0] is unused except as a default error return. |
12157 | Note that stack overflow is not yet handled. */ | |
12158 | ||
12159 | static CORE_ADDR | |
e7c27a73 | 12160 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 12161 | { |
e7c27a73 | 12162 | struct objfile *objfile = cu->objfile; |
c906108c SS |
12163 | int i; |
12164 | int size = blk->size; | |
fe1b8b76 | 12165 | gdb_byte *data = blk->data; |
c906108c SS |
12166 | CORE_ADDR stack[64]; |
12167 | int stacki; | |
12168 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 12169 | gdb_byte op; |
c906108c SS |
12170 | |
12171 | i = 0; | |
12172 | stacki = 0; | |
12173 | stack[stacki] = 0; | |
c906108c SS |
12174 | |
12175 | while (i < size) | |
12176 | { | |
c906108c SS |
12177 | op = data[i++]; |
12178 | switch (op) | |
12179 | { | |
f1bea926 JM |
12180 | case DW_OP_lit0: |
12181 | case DW_OP_lit1: | |
12182 | case DW_OP_lit2: | |
12183 | case DW_OP_lit3: | |
12184 | case DW_OP_lit4: | |
12185 | case DW_OP_lit5: | |
12186 | case DW_OP_lit6: | |
12187 | case DW_OP_lit7: | |
12188 | case DW_OP_lit8: | |
12189 | case DW_OP_lit9: | |
12190 | case DW_OP_lit10: | |
12191 | case DW_OP_lit11: | |
12192 | case DW_OP_lit12: | |
12193 | case DW_OP_lit13: | |
12194 | case DW_OP_lit14: | |
12195 | case DW_OP_lit15: | |
12196 | case DW_OP_lit16: | |
12197 | case DW_OP_lit17: | |
12198 | case DW_OP_lit18: | |
12199 | case DW_OP_lit19: | |
12200 | case DW_OP_lit20: | |
12201 | case DW_OP_lit21: | |
12202 | case DW_OP_lit22: | |
12203 | case DW_OP_lit23: | |
12204 | case DW_OP_lit24: | |
12205 | case DW_OP_lit25: | |
12206 | case DW_OP_lit26: | |
12207 | case DW_OP_lit27: | |
12208 | case DW_OP_lit28: | |
12209 | case DW_OP_lit29: | |
12210 | case DW_OP_lit30: | |
12211 | case DW_OP_lit31: | |
12212 | stack[++stacki] = op - DW_OP_lit0; | |
12213 | break; | |
12214 | ||
c906108c SS |
12215 | case DW_OP_reg0: |
12216 | case DW_OP_reg1: | |
12217 | case DW_OP_reg2: | |
12218 | case DW_OP_reg3: | |
12219 | case DW_OP_reg4: | |
12220 | case DW_OP_reg5: | |
12221 | case DW_OP_reg6: | |
12222 | case DW_OP_reg7: | |
12223 | case DW_OP_reg8: | |
12224 | case DW_OP_reg9: | |
12225 | case DW_OP_reg10: | |
12226 | case DW_OP_reg11: | |
12227 | case DW_OP_reg12: | |
12228 | case DW_OP_reg13: | |
12229 | case DW_OP_reg14: | |
12230 | case DW_OP_reg15: | |
12231 | case DW_OP_reg16: | |
12232 | case DW_OP_reg17: | |
12233 | case DW_OP_reg18: | |
12234 | case DW_OP_reg19: | |
12235 | case DW_OP_reg20: | |
12236 | case DW_OP_reg21: | |
12237 | case DW_OP_reg22: | |
12238 | case DW_OP_reg23: | |
12239 | case DW_OP_reg24: | |
12240 | case DW_OP_reg25: | |
12241 | case DW_OP_reg26: | |
12242 | case DW_OP_reg27: | |
12243 | case DW_OP_reg28: | |
12244 | case DW_OP_reg29: | |
12245 | case DW_OP_reg30: | |
12246 | case DW_OP_reg31: | |
c906108c | 12247 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
12248 | if (i < size) |
12249 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
12250 | break; |
12251 | ||
12252 | case DW_OP_regx: | |
c906108c SS |
12253 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
12254 | i += bytes_read; | |
c906108c | 12255 | stack[++stacki] = unsnd; |
4cecd739 DJ |
12256 | if (i < size) |
12257 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
12258 | break; |
12259 | ||
12260 | case DW_OP_addr: | |
107d2387 | 12261 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 12262 | cu, &bytes_read); |
107d2387 | 12263 | i += bytes_read; |
c906108c SS |
12264 | break; |
12265 | ||
12266 | case DW_OP_const1u: | |
12267 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
12268 | i += 1; | |
12269 | break; | |
12270 | ||
12271 | case DW_OP_const1s: | |
12272 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
12273 | i += 1; | |
12274 | break; | |
12275 | ||
12276 | case DW_OP_const2u: | |
12277 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
12278 | i += 2; | |
12279 | break; | |
12280 | ||
12281 | case DW_OP_const2s: | |
12282 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
12283 | i += 2; | |
12284 | break; | |
12285 | ||
12286 | case DW_OP_const4u: | |
12287 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
12288 | i += 4; | |
12289 | break; | |
12290 | ||
12291 | case DW_OP_const4s: | |
12292 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
12293 | i += 4; | |
12294 | break; | |
12295 | ||
12296 | case DW_OP_constu: | |
12297 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 12298 | &bytes_read); |
c906108c SS |
12299 | i += bytes_read; |
12300 | break; | |
12301 | ||
12302 | case DW_OP_consts: | |
12303 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
12304 | i += bytes_read; | |
12305 | break; | |
12306 | ||
f1bea926 JM |
12307 | case DW_OP_dup: |
12308 | stack[stacki + 1] = stack[stacki]; | |
12309 | stacki++; | |
12310 | break; | |
12311 | ||
c906108c SS |
12312 | case DW_OP_plus: |
12313 | stack[stacki - 1] += stack[stacki]; | |
12314 | stacki--; | |
12315 | break; | |
12316 | ||
12317 | case DW_OP_plus_uconst: | |
12318 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
12319 | i += bytes_read; | |
12320 | break; | |
12321 | ||
12322 | case DW_OP_minus: | |
f1bea926 | 12323 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
12324 | stacki--; |
12325 | break; | |
12326 | ||
7a292a7a | 12327 | case DW_OP_deref: |
7a292a7a | 12328 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
12329 | this using GDB's address_class enum. This is valid for partial |
12330 | global symbols, although the variable's address will be bogus | |
12331 | in the psymtab. */ | |
7a292a7a | 12332 | if (i < size) |
4d3c2250 | 12333 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
12334 | break; |
12335 | ||
9d774e44 | 12336 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
12337 | /* The top of the stack has the offset from the beginning |
12338 | of the thread control block at which the variable is located. */ | |
12339 | /* Nothing should follow this operator, so the top of stack would | |
12340 | be returned. */ | |
4cecd739 DJ |
12341 | /* This is valid for partial global symbols, but the variable's |
12342 | address will be bogus in the psymtab. */ | |
9d774e44 | 12343 | if (i < size) |
4d3c2250 | 12344 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
12345 | break; |
12346 | ||
42be36b3 CT |
12347 | case DW_OP_GNU_uninit: |
12348 | break; | |
12349 | ||
c906108c | 12350 | default: |
e2e0b3e5 | 12351 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
9eae7c52 | 12352 | dwarf_stack_op_name (op, 1)); |
c906108c SS |
12353 | return (stack[stacki]); |
12354 | } | |
12355 | } | |
12356 | return (stack[stacki]); | |
12357 | } | |
12358 | ||
12359 | /* memory allocation interface */ | |
12360 | ||
c906108c | 12361 | static struct dwarf_block * |
7b5a2f43 | 12362 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
12363 | { |
12364 | struct dwarf_block *blk; | |
12365 | ||
12366 | blk = (struct dwarf_block *) | |
7b5a2f43 | 12367 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
12368 | return (blk); |
12369 | } | |
12370 | ||
12371 | static struct abbrev_info * | |
f3dd6933 | 12372 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
12373 | { |
12374 | struct abbrev_info *abbrev; | |
12375 | ||
f3dd6933 DJ |
12376 | abbrev = (struct abbrev_info *) |
12377 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
12378 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
12379 | return (abbrev); | |
12380 | } | |
12381 | ||
12382 | static struct die_info * | |
b60c80d6 | 12383 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
12384 | { |
12385 | struct die_info *die; | |
b60c80d6 DJ |
12386 | size_t size = sizeof (struct die_info); |
12387 | ||
12388 | if (num_attrs > 1) | |
12389 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 12390 | |
b60c80d6 | 12391 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
12392 | memset (die, 0, sizeof (struct die_info)); |
12393 | return (die); | |
12394 | } | |
2e276125 JB |
12395 | |
12396 | \f | |
12397 | /* Macro support. */ | |
12398 | ||
12399 | ||
12400 | /* Return the full name of file number I in *LH's file name table. | |
12401 | Use COMP_DIR as the name of the current directory of the | |
12402 | compilation. The result is allocated using xmalloc; the caller is | |
12403 | responsible for freeing it. */ | |
12404 | static char * | |
12405 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
12406 | { | |
6a83a1e6 EZ |
12407 | /* Is the file number a valid index into the line header's file name |
12408 | table? Remember that file numbers start with one, not zero. */ | |
12409 | if (1 <= file && file <= lh->num_file_names) | |
12410 | { | |
12411 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 12412 | |
6a83a1e6 EZ |
12413 | if (IS_ABSOLUTE_PATH (fe->name)) |
12414 | return xstrdup (fe->name); | |
12415 | else | |
12416 | { | |
12417 | const char *dir; | |
12418 | int dir_len; | |
12419 | char *full_name; | |
12420 | ||
12421 | if (fe->dir_index) | |
12422 | dir = lh->include_dirs[fe->dir_index - 1]; | |
12423 | else | |
12424 | dir = comp_dir; | |
12425 | ||
12426 | if (dir) | |
12427 | { | |
12428 | dir_len = strlen (dir); | |
12429 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
12430 | strcpy (full_name, dir); | |
12431 | full_name[dir_len] = '/'; | |
12432 | strcpy (full_name + dir_len + 1, fe->name); | |
12433 | return full_name; | |
12434 | } | |
12435 | else | |
12436 | return xstrdup (fe->name); | |
12437 | } | |
12438 | } | |
2e276125 JB |
12439 | else |
12440 | { | |
6a83a1e6 EZ |
12441 | /* The compiler produced a bogus file number. We can at least |
12442 | record the macro definitions made in the file, even if we | |
12443 | won't be able to find the file by name. */ | |
12444 | char fake_name[80]; | |
9a619af0 | 12445 | |
6a83a1e6 | 12446 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 12447 | |
6e70227d | 12448 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
12449 | _("bad file number in macro information (%d)"), |
12450 | file); | |
2e276125 | 12451 | |
6a83a1e6 | 12452 | return xstrdup (fake_name); |
2e276125 JB |
12453 | } |
12454 | } | |
12455 | ||
12456 | ||
12457 | static struct macro_source_file * | |
12458 | macro_start_file (int file, int line, | |
12459 | struct macro_source_file *current_file, | |
12460 | const char *comp_dir, | |
12461 | struct line_header *lh, struct objfile *objfile) | |
12462 | { | |
12463 | /* The full name of this source file. */ | |
12464 | char *full_name = file_full_name (file, lh, comp_dir); | |
12465 | ||
12466 | /* We don't create a macro table for this compilation unit | |
12467 | at all until we actually get a filename. */ | |
12468 | if (! pending_macros) | |
4a146b47 | 12469 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 12470 | objfile->macro_cache); |
2e276125 JB |
12471 | |
12472 | if (! current_file) | |
12473 | /* If we have no current file, then this must be the start_file | |
12474 | directive for the compilation unit's main source file. */ | |
12475 | current_file = macro_set_main (pending_macros, full_name); | |
12476 | else | |
12477 | current_file = macro_include (current_file, line, full_name); | |
12478 | ||
12479 | xfree (full_name); | |
6e70227d | 12480 | |
2e276125 JB |
12481 | return current_file; |
12482 | } | |
12483 | ||
12484 | ||
12485 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
12486 | followed by a null byte. */ | |
12487 | static char * | |
12488 | copy_string (const char *buf, int len) | |
12489 | { | |
12490 | char *s = xmalloc (len + 1); | |
9a619af0 | 12491 | |
2e276125 JB |
12492 | memcpy (s, buf, len); |
12493 | s[len] = '\0'; | |
2e276125 JB |
12494 | return s; |
12495 | } | |
12496 | ||
12497 | ||
12498 | static const char * | |
12499 | consume_improper_spaces (const char *p, const char *body) | |
12500 | { | |
12501 | if (*p == ' ') | |
12502 | { | |
4d3c2250 | 12503 | complaint (&symfile_complaints, |
e2e0b3e5 | 12504 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 12505 | body); |
2e276125 JB |
12506 | |
12507 | while (*p == ' ') | |
12508 | p++; | |
12509 | } | |
12510 | ||
12511 | return p; | |
12512 | } | |
12513 | ||
12514 | ||
12515 | static void | |
12516 | parse_macro_definition (struct macro_source_file *file, int line, | |
12517 | const char *body) | |
12518 | { | |
12519 | const char *p; | |
12520 | ||
12521 | /* The body string takes one of two forms. For object-like macro | |
12522 | definitions, it should be: | |
12523 | ||
12524 | <macro name> " " <definition> | |
12525 | ||
12526 | For function-like macro definitions, it should be: | |
12527 | ||
12528 | <macro name> "() " <definition> | |
12529 | or | |
12530 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
12531 | ||
12532 | Spaces may appear only where explicitly indicated, and in the | |
12533 | <definition>. | |
12534 | ||
12535 | The Dwarf 2 spec says that an object-like macro's name is always | |
12536 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 12537 | the space when the macro's definition is the empty string. |
2e276125 JB |
12538 | |
12539 | The Dwarf 2 spec says that there should be no spaces between the | |
12540 | formal arguments in a function-like macro's formal argument list, | |
12541 | but versions of GCC around March 2002 include spaces after the | |
12542 | commas. */ | |
12543 | ||
12544 | ||
12545 | /* Find the extent of the macro name. The macro name is terminated | |
12546 | by either a space or null character (for an object-like macro) or | |
12547 | an opening paren (for a function-like macro). */ | |
12548 | for (p = body; *p; p++) | |
12549 | if (*p == ' ' || *p == '(') | |
12550 | break; | |
12551 | ||
12552 | if (*p == ' ' || *p == '\0') | |
12553 | { | |
12554 | /* It's an object-like macro. */ | |
12555 | int name_len = p - body; | |
12556 | char *name = copy_string (body, name_len); | |
12557 | const char *replacement; | |
12558 | ||
12559 | if (*p == ' ') | |
12560 | replacement = body + name_len + 1; | |
12561 | else | |
12562 | { | |
4d3c2250 | 12563 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12564 | replacement = body + name_len; |
12565 | } | |
6e70227d | 12566 | |
2e276125 JB |
12567 | macro_define_object (file, line, name, replacement); |
12568 | ||
12569 | xfree (name); | |
12570 | } | |
12571 | else if (*p == '(') | |
12572 | { | |
12573 | /* It's a function-like macro. */ | |
12574 | char *name = copy_string (body, p - body); | |
12575 | int argc = 0; | |
12576 | int argv_size = 1; | |
12577 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
12578 | ||
12579 | p++; | |
12580 | ||
12581 | p = consume_improper_spaces (p, body); | |
12582 | ||
12583 | /* Parse the formal argument list. */ | |
12584 | while (*p && *p != ')') | |
12585 | { | |
12586 | /* Find the extent of the current argument name. */ | |
12587 | const char *arg_start = p; | |
12588 | ||
12589 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
12590 | p++; | |
12591 | ||
12592 | if (! *p || p == arg_start) | |
4d3c2250 | 12593 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12594 | else |
12595 | { | |
12596 | /* Make sure argv has room for the new argument. */ | |
12597 | if (argc >= argv_size) | |
12598 | { | |
12599 | argv_size *= 2; | |
12600 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
12601 | } | |
12602 | ||
12603 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
12604 | } | |
12605 | ||
12606 | p = consume_improper_spaces (p, body); | |
12607 | ||
12608 | /* Consume the comma, if present. */ | |
12609 | if (*p == ',') | |
12610 | { | |
12611 | p++; | |
12612 | ||
12613 | p = consume_improper_spaces (p, body); | |
12614 | } | |
12615 | } | |
12616 | ||
12617 | if (*p == ')') | |
12618 | { | |
12619 | p++; | |
12620 | ||
12621 | if (*p == ' ') | |
12622 | /* Perfectly formed definition, no complaints. */ | |
12623 | macro_define_function (file, line, name, | |
6e70227d | 12624 | argc, (const char **) argv, |
2e276125 JB |
12625 | p + 1); |
12626 | else if (*p == '\0') | |
12627 | { | |
12628 | /* Complain, but do define it. */ | |
4d3c2250 | 12629 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 12630 | macro_define_function (file, line, name, |
6e70227d | 12631 | argc, (const char **) argv, |
2e276125 JB |
12632 | p); |
12633 | } | |
12634 | else | |
12635 | /* Just complain. */ | |
4d3c2250 | 12636 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12637 | } |
12638 | else | |
12639 | /* Just complain. */ | |
4d3c2250 | 12640 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12641 | |
12642 | xfree (name); | |
12643 | { | |
12644 | int i; | |
12645 | ||
12646 | for (i = 0; i < argc; i++) | |
12647 | xfree (argv[i]); | |
12648 | } | |
12649 | xfree (argv); | |
12650 | } | |
12651 | else | |
4d3c2250 | 12652 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
12653 | } |
12654 | ||
12655 | ||
12656 | static void | |
12657 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
12658 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 12659 | struct dwarf2_cu *cu) |
2e276125 | 12660 | { |
fe1b8b76 | 12661 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 12662 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
12663 | enum dwarf_macinfo_record_type macinfo_type; |
12664 | int at_commandline; | |
2e276125 | 12665 | |
be391dca TT |
12666 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
12667 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 12668 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 12669 | { |
e2e0b3e5 | 12670 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
12671 | return; |
12672 | } | |
12673 | ||
757a13d0 JK |
12674 | /* First pass: Find the name of the base filename. |
12675 | This filename is needed in order to process all macros whose definition | |
12676 | (or undefinition) comes from the command line. These macros are defined | |
12677 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
12678 | associated to the base file. | |
12679 | ||
12680 | To determine the base file name, we scan the macro definitions until we | |
12681 | reach the first DW_MACINFO_start_file entry. We then initialize | |
12682 | CURRENT_FILE accordingly so that any macro definition found before the | |
12683 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
12684 | ||
dce234bc PP |
12685 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
12686 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
12687 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 12688 | |
757a13d0 | 12689 | do |
2e276125 | 12690 | { |
2e276125 JB |
12691 | /* Do we at least have room for a macinfo type byte? */ |
12692 | if (mac_ptr >= mac_end) | |
12693 | { | |
757a13d0 JK |
12694 | /* Complaint is printed during the second pass as GDB will probably |
12695 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
12696 | break; | |
2e276125 JB |
12697 | } |
12698 | ||
12699 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
12700 | mac_ptr++; | |
12701 | ||
12702 | switch (macinfo_type) | |
12703 | { | |
12704 | /* A zero macinfo type indicates the end of the macro | |
12705 | information. */ | |
12706 | case 0: | |
757a13d0 JK |
12707 | break; |
12708 | ||
12709 | case DW_MACINFO_define: | |
12710 | case DW_MACINFO_undef: | |
12711 | /* Only skip the data by MAC_PTR. */ | |
12712 | { | |
12713 | unsigned int bytes_read; | |
12714 | ||
12715 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12716 | mac_ptr += bytes_read; | |
12717 | read_string (abfd, mac_ptr, &bytes_read); | |
12718 | mac_ptr += bytes_read; | |
12719 | } | |
12720 | break; | |
12721 | ||
12722 | case DW_MACINFO_start_file: | |
12723 | { | |
12724 | unsigned int bytes_read; | |
12725 | int line, file; | |
12726 | ||
12727 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12728 | mac_ptr += bytes_read; | |
12729 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12730 | mac_ptr += bytes_read; | |
12731 | ||
12732 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
12733 | lh, cu->objfile); | |
12734 | } | |
12735 | break; | |
12736 | ||
12737 | case DW_MACINFO_end_file: | |
12738 | /* No data to skip by MAC_PTR. */ | |
12739 | break; | |
12740 | ||
12741 | case DW_MACINFO_vendor_ext: | |
12742 | /* Only skip the data by MAC_PTR. */ | |
12743 | { | |
12744 | unsigned int bytes_read; | |
12745 | ||
12746 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12747 | mac_ptr += bytes_read; | |
12748 | read_string (abfd, mac_ptr, &bytes_read); | |
12749 | mac_ptr += bytes_read; | |
12750 | } | |
12751 | break; | |
12752 | ||
12753 | default: | |
12754 | break; | |
12755 | } | |
12756 | } while (macinfo_type != 0 && current_file == NULL); | |
12757 | ||
12758 | /* Second pass: Process all entries. | |
12759 | ||
12760 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
12761 | command-line macro definitions/undefinitions. This flag is unset when we | |
12762 | reach the first DW_MACINFO_start_file entry. */ | |
12763 | ||
dce234bc | 12764 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
12765 | |
12766 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
12767 | GDB is still reading the definitions from command line. First | |
12768 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
12769 | to create CURRENT_FILE for the main source holding also the command line | |
12770 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
12771 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
12772 | ||
12773 | at_commandline = 1; | |
12774 | ||
12775 | do | |
12776 | { | |
12777 | /* Do we at least have room for a macinfo type byte? */ | |
12778 | if (mac_ptr >= mac_end) | |
12779 | { | |
12780 | dwarf2_macros_too_long_complaint (); | |
12781 | break; | |
12782 | } | |
12783 | ||
12784 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
12785 | mac_ptr++; | |
12786 | ||
12787 | switch (macinfo_type) | |
12788 | { | |
12789 | /* A zero macinfo type indicates the end of the macro | |
12790 | information. */ | |
12791 | case 0: | |
12792 | break; | |
2e276125 JB |
12793 | |
12794 | case DW_MACINFO_define: | |
12795 | case DW_MACINFO_undef: | |
12796 | { | |
891d2f0b | 12797 | unsigned int bytes_read; |
2e276125 JB |
12798 | int line; |
12799 | char *body; | |
12800 | ||
12801 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12802 | mac_ptr += bytes_read; | |
12803 | body = read_string (abfd, mac_ptr, &bytes_read); | |
12804 | mac_ptr += bytes_read; | |
12805 | ||
12806 | if (! current_file) | |
757a13d0 JK |
12807 | { |
12808 | /* DWARF violation as no main source is present. */ | |
12809 | complaint (&symfile_complaints, | |
12810 | _("debug info with no main source gives macro %s " | |
12811 | "on line %d: %s"), | |
6e70227d DE |
12812 | macinfo_type == DW_MACINFO_define ? |
12813 | _("definition") : | |
905e0470 PM |
12814 | macinfo_type == DW_MACINFO_undef ? |
12815 | _("undefinition") : | |
12816 | _("something-or-other"), line, body); | |
757a13d0 JK |
12817 | break; |
12818 | } | |
12819 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 12820 | complaint (&symfile_complaints, |
757a13d0 JK |
12821 | _("debug info gives %s macro %s with %s line %d: %s"), |
12822 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 12823 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 12824 | _("definition") : |
905e0470 PM |
12825 | macinfo_type == DW_MACINFO_undef ? |
12826 | _("undefinition") : | |
12827 | _("something-or-other"), | |
757a13d0 JK |
12828 | line == 0 ? _("zero") : _("non-zero"), line, body); |
12829 | ||
12830 | if (macinfo_type == DW_MACINFO_define) | |
12831 | parse_macro_definition (current_file, line, body); | |
12832 | else if (macinfo_type == DW_MACINFO_undef) | |
12833 | macro_undef (current_file, line, body); | |
2e276125 JB |
12834 | } |
12835 | break; | |
12836 | ||
12837 | case DW_MACINFO_start_file: | |
12838 | { | |
891d2f0b | 12839 | unsigned int bytes_read; |
2e276125 JB |
12840 | int line, file; |
12841 | ||
12842 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12843 | mac_ptr += bytes_read; | |
12844 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12845 | mac_ptr += bytes_read; | |
12846 | ||
757a13d0 JK |
12847 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
12848 | complaint (&symfile_complaints, | |
12849 | _("debug info gives source %d included " | |
12850 | "from %s at %s line %d"), | |
12851 | file, at_commandline ? _("command-line") : _("file"), | |
12852 | line == 0 ? _("zero") : _("non-zero"), line); | |
12853 | ||
12854 | if (at_commandline) | |
12855 | { | |
12856 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
12857 | at_commandline = 0; | |
12858 | } | |
12859 | else | |
12860 | current_file = macro_start_file (file, line, | |
12861 | current_file, comp_dir, | |
12862 | lh, cu->objfile); | |
2e276125 JB |
12863 | } |
12864 | break; | |
12865 | ||
12866 | case DW_MACINFO_end_file: | |
12867 | if (! current_file) | |
4d3c2250 | 12868 | complaint (&symfile_complaints, |
e2e0b3e5 | 12869 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
12870 | else |
12871 | { | |
12872 | current_file = current_file->included_by; | |
12873 | if (! current_file) | |
12874 | { | |
12875 | enum dwarf_macinfo_record_type next_type; | |
12876 | ||
12877 | /* GCC circa March 2002 doesn't produce the zero | |
12878 | type byte marking the end of the compilation | |
12879 | unit. Complain if it's not there, but exit no | |
12880 | matter what. */ | |
12881 | ||
12882 | /* Do we at least have room for a macinfo type byte? */ | |
12883 | if (mac_ptr >= mac_end) | |
12884 | { | |
4d3c2250 | 12885 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
12886 | return; |
12887 | } | |
12888 | ||
12889 | /* We don't increment mac_ptr here, so this is just | |
12890 | a look-ahead. */ | |
12891 | next_type = read_1_byte (abfd, mac_ptr); | |
12892 | if (next_type != 0) | |
4d3c2250 | 12893 | complaint (&symfile_complaints, |
e2e0b3e5 | 12894 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
12895 | |
12896 | return; | |
12897 | } | |
12898 | } | |
12899 | break; | |
12900 | ||
12901 | case DW_MACINFO_vendor_ext: | |
12902 | { | |
891d2f0b | 12903 | unsigned int bytes_read; |
2e276125 JB |
12904 | int constant; |
12905 | char *string; | |
12906 | ||
12907 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
12908 | mac_ptr += bytes_read; | |
12909 | string = read_string (abfd, mac_ptr, &bytes_read); | |
12910 | mac_ptr += bytes_read; | |
12911 | ||
12912 | /* We don't recognize any vendor extensions. */ | |
12913 | } | |
12914 | break; | |
12915 | } | |
757a13d0 | 12916 | } while (macinfo_type != 0); |
2e276125 | 12917 | } |
8e19ed76 PS |
12918 | |
12919 | /* Check if the attribute's form is a DW_FORM_block* | |
12920 | if so return true else false. */ | |
12921 | static int | |
12922 | attr_form_is_block (struct attribute *attr) | |
12923 | { | |
12924 | return (attr == NULL ? 0 : | |
12925 | attr->form == DW_FORM_block1 | |
12926 | || attr->form == DW_FORM_block2 | |
12927 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
12928 | || attr->form == DW_FORM_block |
12929 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 12930 | } |
4c2df51b | 12931 | |
c6a0999f JB |
12932 | /* Return non-zero if ATTR's value is a section offset --- classes |
12933 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
12934 | You may use DW_UNSND (attr) to retrieve such offsets. | |
12935 | ||
12936 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
12937 | may have a value that belongs to more than one of these classes; it | |
12938 | would be ambiguous if we did, because we use the same forms for all | |
12939 | of them. */ | |
3690dd37 JB |
12940 | static int |
12941 | attr_form_is_section_offset (struct attribute *attr) | |
12942 | { | |
12943 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
12944 | || attr->form == DW_FORM_data8 |
12945 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
12946 | } |
12947 | ||
12948 | ||
12949 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
12950 | zero otherwise. When this function returns true, you can apply | |
12951 | dwarf2_get_attr_constant_value to it. | |
12952 | ||
12953 | However, note that for some attributes you must check | |
12954 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
12955 | and DW_FORM_data8 are members of both the constant class, and of | |
12956 | the classes that contain offsets into other debug sections | |
12957 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
12958 | that, if an attribute's can be either a constant or one of the | |
12959 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
12960 | taken as section offsets, not constants. */ | |
12961 | static int | |
12962 | attr_form_is_constant (struct attribute *attr) | |
12963 | { | |
12964 | switch (attr->form) | |
12965 | { | |
12966 | case DW_FORM_sdata: | |
12967 | case DW_FORM_udata: | |
12968 | case DW_FORM_data1: | |
12969 | case DW_FORM_data2: | |
12970 | case DW_FORM_data4: | |
12971 | case DW_FORM_data8: | |
12972 | return 1; | |
12973 | default: | |
12974 | return 0; | |
12975 | } | |
12976 | } | |
12977 | ||
4c2df51b DJ |
12978 | static void |
12979 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 12980 | struct dwarf2_cu *cu) |
4c2df51b | 12981 | { |
3690dd37 | 12982 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
12983 | /* ".debug_loc" may not exist at all, or the offset may be outside |
12984 | the section. If so, fall through to the complaint in the | |
12985 | other branch. */ | |
dce234bc | 12986 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 12987 | { |
0d53c4c4 | 12988 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 12989 | |
4a146b47 | 12990 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 12991 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
12992 | baton->per_cu = cu->per_cu; |
12993 | gdb_assert (baton->per_cu); | |
4c2df51b | 12994 | |
be391dca TT |
12995 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
12996 | &dwarf2_per_objfile->loc); | |
12997 | ||
0d53c4c4 DJ |
12998 | /* We don't know how long the location list is, but make sure we |
12999 | don't run off the edge of the section. */ | |
dce234bc PP |
13000 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
13001 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
13002 | baton->base_address = cu->base_address; |
13003 | if (cu->base_known == 0) | |
0d53c4c4 | 13004 | complaint (&symfile_complaints, |
e2e0b3e5 | 13005 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 13006 | |
768a979c | 13007 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
13008 | SYMBOL_LOCATION_BATON (sym) = baton; |
13009 | } | |
13010 | else | |
13011 | { | |
13012 | struct dwarf2_locexpr_baton *baton; | |
13013 | ||
4a146b47 | 13014 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13015 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
13016 | baton->per_cu = cu->per_cu; |
13017 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
13018 | |
13019 | if (attr_form_is_block (attr)) | |
13020 | { | |
13021 | /* Note that we're just copying the block's data pointer | |
13022 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
13023 | info_buffer for SYM's objfile; right now we never release |
13024 | that buffer, but when we do clean up properly this may | |
13025 | need to change. */ | |
0d53c4c4 DJ |
13026 | baton->size = DW_BLOCK (attr)->size; |
13027 | baton->data = DW_BLOCK (attr)->data; | |
13028 | } | |
13029 | else | |
13030 | { | |
13031 | dwarf2_invalid_attrib_class_complaint ("location description", | |
13032 | SYMBOL_NATURAL_NAME (sym)); | |
13033 | baton->size = 0; | |
13034 | baton->data = NULL; | |
13035 | } | |
6e70227d | 13036 | |
768a979c | 13037 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
13038 | SYMBOL_LOCATION_BATON (sym) = baton; |
13039 | } | |
4c2df51b | 13040 | } |
6502dd73 | 13041 | |
9aa1f1e3 TT |
13042 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
13043 | came from a separate debuginfo file, then the master objfile is | |
13044 | returned. */ | |
ae0d2f24 UW |
13045 | |
13046 | struct objfile * | |
13047 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
13048 | { | |
9291a0cd | 13049 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13050 | |
13051 | /* Return the master objfile, so that we can report and look up the | |
13052 | correct file containing this variable. */ | |
13053 | if (objfile->separate_debug_objfile_backlink) | |
13054 | objfile = objfile->separate_debug_objfile_backlink; | |
13055 | ||
13056 | return objfile; | |
13057 | } | |
13058 | ||
13059 | /* Return the address size given in the compilation unit header for CU. */ | |
13060 | ||
13061 | CORE_ADDR | |
13062 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
13063 | { | |
13064 | if (per_cu->cu) | |
13065 | return per_cu->cu->header.addr_size; | |
13066 | else | |
13067 | { | |
13068 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 13069 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13070 | struct dwarf2_per_objfile *per_objfile |
13071 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 13072 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 13073 | struct comp_unit_head cu_header; |
9a619af0 | 13074 | |
ae0d2f24 UW |
13075 | memset (&cu_header, 0, sizeof cu_header); |
13076 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
13077 | return cu_header.addr_size; | |
13078 | } | |
13079 | } | |
13080 | ||
9eae7c52 TT |
13081 | /* Return the offset size given in the compilation unit header for CU. */ |
13082 | ||
13083 | int | |
13084 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
13085 | { | |
13086 | if (per_cu->cu) | |
13087 | return per_cu->cu->header.offset_size; | |
13088 | else | |
13089 | { | |
13090 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 13091 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
13092 | struct dwarf2_per_objfile *per_objfile |
13093 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
13094 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
13095 | struct comp_unit_head cu_header; | |
13096 | ||
13097 | memset (&cu_header, 0, sizeof cu_header); | |
13098 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
13099 | return cu_header.offset_size; | |
13100 | } | |
13101 | } | |
13102 | ||
9aa1f1e3 TT |
13103 | /* Return the text offset of the CU. The returned offset comes from |
13104 | this CU's objfile. If this objfile came from a separate debuginfo | |
13105 | file, then the offset may be different from the corresponding | |
13106 | offset in the parent objfile. */ | |
13107 | ||
13108 | CORE_ADDR | |
13109 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
13110 | { | |
13111 | struct objfile *objfile = per_cu->psymtab->objfile; | |
13112 | ||
13113 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
13114 | } | |
13115 | ||
348e048f DE |
13116 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
13117 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
13118 | |
13119 | static struct dwarf2_per_cu_data * | |
c764a876 | 13120 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
13121 | struct objfile *objfile) |
13122 | { | |
13123 | struct dwarf2_per_cu_data *this_cu; | |
13124 | int low, high; | |
13125 | ||
ae038cb0 DJ |
13126 | low = 0; |
13127 | high = dwarf2_per_objfile->n_comp_units - 1; | |
13128 | while (high > low) | |
13129 | { | |
13130 | int mid = low + (high - low) / 2; | |
9a619af0 | 13131 | |
ae038cb0 DJ |
13132 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
13133 | high = mid; | |
13134 | else | |
13135 | low = mid + 1; | |
13136 | } | |
13137 | gdb_assert (low == high); | |
13138 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
13139 | { | |
10b3939b | 13140 | if (low == 0) |
8a3fe4f8 AC |
13141 | error (_("Dwarf Error: could not find partial DIE containing " |
13142 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
13143 | (long) offset, bfd_get_filename (objfile->obfd)); |
13144 | ||
ae038cb0 DJ |
13145 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
13146 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
13147 | } | |
13148 | else | |
13149 | { | |
13150 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
13151 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
13152 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 13153 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
13154 | gdb_assert (offset < this_cu->offset + this_cu->length); |
13155 | return this_cu; | |
13156 | } | |
13157 | } | |
13158 | ||
10b3939b DJ |
13159 | /* Locate the compilation unit from OBJFILE which is located at exactly |
13160 | OFFSET. Raises an error on failure. */ | |
13161 | ||
ae038cb0 | 13162 | static struct dwarf2_per_cu_data * |
c764a876 | 13163 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
13164 | { |
13165 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 13166 | |
ae038cb0 DJ |
13167 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
13168 | if (this_cu->offset != offset) | |
c764a876 | 13169 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
13170 | return this_cu; |
13171 | } | |
13172 | ||
93311388 DE |
13173 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
13174 | ||
13175 | static struct dwarf2_cu * | |
13176 | alloc_one_comp_unit (struct objfile *objfile) | |
13177 | { | |
13178 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
13179 | cu->objfile = objfile; | |
13180 | obstack_init (&cu->comp_unit_obstack); | |
13181 | return cu; | |
13182 | } | |
13183 | ||
ae038cb0 DJ |
13184 | /* Release one cached compilation unit, CU. We unlink it from the tree |
13185 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
13186 | the caller is responsible for that. |
13187 | NOTE: DATA is a void * because this function is also used as a | |
13188 | cleanup routine. */ | |
ae038cb0 DJ |
13189 | |
13190 | static void | |
13191 | free_one_comp_unit (void *data) | |
13192 | { | |
13193 | struct dwarf2_cu *cu = data; | |
13194 | ||
13195 | if (cu->per_cu != NULL) | |
13196 | cu->per_cu->cu = NULL; | |
13197 | cu->per_cu = NULL; | |
13198 | ||
13199 | obstack_free (&cu->comp_unit_obstack, NULL); | |
13200 | ||
13201 | xfree (cu); | |
13202 | } | |
13203 | ||
72bf9492 | 13204 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
13205 | when we're finished with it. We can't free the pointer itself, but be |
13206 | sure to unlink it from the cache. Also release any associated storage | |
13207 | and perform cache maintenance. | |
72bf9492 DJ |
13208 | |
13209 | Only used during partial symbol parsing. */ | |
13210 | ||
13211 | static void | |
13212 | free_stack_comp_unit (void *data) | |
13213 | { | |
13214 | struct dwarf2_cu *cu = data; | |
13215 | ||
13216 | obstack_free (&cu->comp_unit_obstack, NULL); | |
13217 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
13218 | |
13219 | if (cu->per_cu != NULL) | |
13220 | { | |
13221 | /* This compilation unit is on the stack in our caller, so we | |
13222 | should not xfree it. Just unlink it. */ | |
13223 | cu->per_cu->cu = NULL; | |
13224 | cu->per_cu = NULL; | |
13225 | ||
13226 | /* If we had a per-cu pointer, then we may have other compilation | |
13227 | units loaded, so age them now. */ | |
13228 | age_cached_comp_units (); | |
13229 | } | |
13230 | } | |
13231 | ||
13232 | /* Free all cached compilation units. */ | |
13233 | ||
13234 | static void | |
13235 | free_cached_comp_units (void *data) | |
13236 | { | |
13237 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13238 | ||
13239 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13240 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13241 | while (per_cu != NULL) | |
13242 | { | |
13243 | struct dwarf2_per_cu_data *next_cu; | |
13244 | ||
13245 | next_cu = per_cu->cu->read_in_chain; | |
13246 | ||
13247 | free_one_comp_unit (per_cu->cu); | |
13248 | *last_chain = next_cu; | |
13249 | ||
13250 | per_cu = next_cu; | |
13251 | } | |
13252 | } | |
13253 | ||
13254 | /* Increase the age counter on each cached compilation unit, and free | |
13255 | any that are too old. */ | |
13256 | ||
13257 | static void | |
13258 | age_cached_comp_units (void) | |
13259 | { | |
13260 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13261 | ||
13262 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
13263 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13264 | while (per_cu != NULL) | |
13265 | { | |
13266 | per_cu->cu->last_used ++; | |
13267 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
13268 | dwarf2_mark (per_cu->cu); | |
13269 | per_cu = per_cu->cu->read_in_chain; | |
13270 | } | |
13271 | ||
13272 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13273 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13274 | while (per_cu != NULL) | |
13275 | { | |
13276 | struct dwarf2_per_cu_data *next_cu; | |
13277 | ||
13278 | next_cu = per_cu->cu->read_in_chain; | |
13279 | ||
13280 | if (!per_cu->cu->mark) | |
13281 | { | |
13282 | free_one_comp_unit (per_cu->cu); | |
13283 | *last_chain = next_cu; | |
13284 | } | |
13285 | else | |
13286 | last_chain = &per_cu->cu->read_in_chain; | |
13287 | ||
13288 | per_cu = next_cu; | |
13289 | } | |
13290 | } | |
13291 | ||
13292 | /* Remove a single compilation unit from the cache. */ | |
13293 | ||
13294 | static void | |
13295 | free_one_cached_comp_unit (void *target_cu) | |
13296 | { | |
13297 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
13298 | ||
13299 | per_cu = dwarf2_per_objfile->read_in_chain; | |
13300 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
13301 | while (per_cu != NULL) | |
13302 | { | |
13303 | struct dwarf2_per_cu_data *next_cu; | |
13304 | ||
13305 | next_cu = per_cu->cu->read_in_chain; | |
13306 | ||
13307 | if (per_cu->cu == target_cu) | |
13308 | { | |
13309 | free_one_comp_unit (per_cu->cu); | |
13310 | *last_chain = next_cu; | |
13311 | break; | |
13312 | } | |
13313 | else | |
13314 | last_chain = &per_cu->cu->read_in_chain; | |
13315 | ||
13316 | per_cu = next_cu; | |
13317 | } | |
13318 | } | |
13319 | ||
fe3e1990 DJ |
13320 | /* Release all extra memory associated with OBJFILE. */ |
13321 | ||
13322 | void | |
13323 | dwarf2_free_objfile (struct objfile *objfile) | |
13324 | { | |
13325 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
13326 | ||
13327 | if (dwarf2_per_objfile == NULL) | |
13328 | return; | |
13329 | ||
13330 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
13331 | free_cached_comp_units (NULL); | |
13332 | ||
9291a0cd TT |
13333 | if (dwarf2_per_objfile->using_index) |
13334 | { | |
13335 | int i; | |
13336 | ||
13337 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
13338 | { | |
13339 | int j; | |
13340 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
13341 | ||
13342 | if (!cu->v.quick->lines) | |
13343 | continue; | |
13344 | ||
13345 | for (j = 0; j < cu->v.quick->lines->num_file_names; ++j) | |
13346 | { | |
13347 | if (cu->v.quick->file_names) | |
13348 | xfree ((void *) cu->v.quick->file_names[j]); | |
13349 | if (cu->v.quick->full_names) | |
13350 | xfree ((void *) cu->v.quick->full_names[j]); | |
13351 | } | |
13352 | ||
13353 | free_line_header (cu->v.quick->lines); | |
13354 | } | |
13355 | } | |
13356 | ||
fe3e1990 DJ |
13357 | /* Everything else should be on the objfile obstack. */ |
13358 | } | |
13359 | ||
1c379e20 DJ |
13360 | /* A pair of DIE offset and GDB type pointer. We store these |
13361 | in a hash table separate from the DIEs, and preserve them | |
13362 | when the DIEs are flushed out of cache. */ | |
13363 | ||
13364 | struct dwarf2_offset_and_type | |
13365 | { | |
13366 | unsigned int offset; | |
13367 | struct type *type; | |
13368 | }; | |
13369 | ||
13370 | /* Hash function for a dwarf2_offset_and_type. */ | |
13371 | ||
13372 | static hashval_t | |
13373 | offset_and_type_hash (const void *item) | |
13374 | { | |
13375 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 13376 | |
1c379e20 DJ |
13377 | return ofs->offset; |
13378 | } | |
13379 | ||
13380 | /* Equality function for a dwarf2_offset_and_type. */ | |
13381 | ||
13382 | static int | |
13383 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
13384 | { | |
13385 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
13386 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 13387 | |
1c379e20 DJ |
13388 | return ofs_lhs->offset == ofs_rhs->offset; |
13389 | } | |
13390 | ||
13391 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
13392 | table if necessary. For convenience, return TYPE. |
13393 | ||
13394 | The DIEs reading must have careful ordering to: | |
13395 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
13396 | reading current DIE. | |
13397 | * Not trying to dereference contents of still incompletely read in types | |
13398 | while reading in other DIEs. | |
13399 | * Enable referencing still incompletely read in types just by a pointer to | |
13400 | the type without accessing its fields. | |
13401 | ||
13402 | Therefore caller should follow these rules: | |
13403 | * Try to fetch any prerequisite types we may need to build this DIE type | |
13404 | before building the type and calling set_die_type. | |
13405 | * After building typer call set_die_type for current DIE as soon as | |
13406 | possible before fetching more types to complete the current type. | |
13407 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 13408 | |
f792889a | 13409 | static struct type * |
1c379e20 DJ |
13410 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
13411 | { | |
13412 | struct dwarf2_offset_and_type **slot, ofs; | |
13413 | ||
b4ba55a1 JB |
13414 | /* For Ada types, make sure that the gnat-specific data is always |
13415 | initialized (if not already set). There are a few types where | |
13416 | we should not be doing so, because the type-specific area is | |
13417 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
13418 | where the type-specific area is used to store the floatformat). | |
13419 | But this is not a problem, because the gnat-specific information | |
13420 | is actually not needed for these types. */ | |
13421 | if (need_gnat_info (cu) | |
13422 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
13423 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
13424 | && !HAVE_GNAT_AUX_INFO (type)) | |
13425 | INIT_GNAT_SPECIFIC (type); | |
13426 | ||
f792889a DJ |
13427 | if (cu->type_hash == NULL) |
13428 | { | |
13429 | gdb_assert (cu->per_cu != NULL); | |
13430 | cu->per_cu->type_hash | |
13431 | = htab_create_alloc_ex (cu->header.length / 24, | |
13432 | offset_and_type_hash, | |
13433 | offset_and_type_eq, | |
13434 | NULL, | |
13435 | &cu->objfile->objfile_obstack, | |
13436 | hashtab_obstack_allocate, | |
13437 | dummy_obstack_deallocate); | |
13438 | cu->type_hash = cu->per_cu->type_hash; | |
13439 | } | |
1c379e20 DJ |
13440 | |
13441 | ofs.offset = die->offset; | |
13442 | ofs.type = type; | |
13443 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 13444 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
13445 | if (*slot) |
13446 | complaint (&symfile_complaints, | |
13447 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
13448 | die->offset); | |
1c379e20 DJ |
13449 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
13450 | **slot = ofs; | |
f792889a | 13451 | return type; |
1c379e20 DJ |
13452 | } |
13453 | ||
f792889a DJ |
13454 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
13455 | not have a saved type. */ | |
1c379e20 DJ |
13456 | |
13457 | static struct type * | |
f792889a | 13458 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
13459 | { |
13460 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
13461 | htab_t type_hash = cu->type_hash; |
13462 | ||
13463 | if (type_hash == NULL) | |
13464 | return NULL; | |
1c379e20 DJ |
13465 | |
13466 | ofs.offset = die->offset; | |
13467 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
13468 | if (slot) | |
13469 | return slot->type; | |
13470 | else | |
13471 | return NULL; | |
13472 | } | |
13473 | ||
10b3939b DJ |
13474 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
13475 | ||
13476 | static void | |
13477 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
13478 | struct dwarf2_per_cu_data *ref_per_cu) | |
13479 | { | |
13480 | void **slot; | |
13481 | ||
13482 | if (cu->dependencies == NULL) | |
13483 | cu->dependencies | |
13484 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
13485 | NULL, &cu->comp_unit_obstack, | |
13486 | hashtab_obstack_allocate, | |
13487 | dummy_obstack_deallocate); | |
13488 | ||
13489 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
13490 | if (*slot == NULL) | |
13491 | *slot = ref_per_cu; | |
13492 | } | |
1c379e20 | 13493 | |
f504f079 DE |
13494 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
13495 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
13496 | cache that we must keep because we are keeping CU. */ |
13497 | ||
10b3939b DJ |
13498 | static int |
13499 | dwarf2_mark_helper (void **slot, void *data) | |
13500 | { | |
13501 | struct dwarf2_per_cu_data *per_cu; | |
13502 | ||
13503 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
13504 | if (per_cu->cu->mark) | |
13505 | return 1; | |
13506 | per_cu->cu->mark = 1; | |
13507 | ||
13508 | if (per_cu->cu->dependencies != NULL) | |
13509 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
13510 | ||
13511 | return 1; | |
13512 | } | |
13513 | ||
f504f079 DE |
13514 | /* Set the mark field in CU and in every other compilation unit in the |
13515 | cache that we must keep because we are keeping CU. */ | |
13516 | ||
ae038cb0 DJ |
13517 | static void |
13518 | dwarf2_mark (struct dwarf2_cu *cu) | |
13519 | { | |
13520 | if (cu->mark) | |
13521 | return; | |
13522 | cu->mark = 1; | |
10b3939b DJ |
13523 | if (cu->dependencies != NULL) |
13524 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
13525 | } |
13526 | ||
13527 | static void | |
13528 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
13529 | { | |
13530 | while (per_cu) | |
13531 | { | |
13532 | per_cu->cu->mark = 0; | |
13533 | per_cu = per_cu->cu->read_in_chain; | |
13534 | } | |
72bf9492 DJ |
13535 | } |
13536 | ||
72bf9492 DJ |
13537 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
13538 | is its offset in .debug_info for this objfile. */ | |
13539 | ||
13540 | static hashval_t | |
13541 | partial_die_hash (const void *item) | |
13542 | { | |
13543 | const struct partial_die_info *part_die = item; | |
9a619af0 | 13544 | |
72bf9492 DJ |
13545 | return part_die->offset; |
13546 | } | |
13547 | ||
13548 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
13549 | are equal if they have the same offset. */ | |
13550 | ||
13551 | static int | |
13552 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
13553 | { | |
13554 | const struct partial_die_info *part_die_lhs = item_lhs; | |
13555 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 13556 | |
72bf9492 DJ |
13557 | return part_die_lhs->offset == part_die_rhs->offset; |
13558 | } | |
13559 | ||
ae038cb0 DJ |
13560 | static struct cmd_list_element *set_dwarf2_cmdlist; |
13561 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
13562 | ||
13563 | static void | |
13564 | set_dwarf2_cmd (char *args, int from_tty) | |
13565 | { | |
13566 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
13567 | } | |
13568 | ||
13569 | static void | |
13570 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 13571 | { |
ae038cb0 DJ |
13572 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
13573 | } | |
13574 | ||
dce234bc PP |
13575 | /* If section described by INFO was mmapped, munmap it now. */ |
13576 | ||
13577 | static void | |
13578 | munmap_section_buffer (struct dwarf2_section_info *info) | |
13579 | { | |
13580 | if (info->was_mmapped) | |
13581 | { | |
13582 | #ifdef HAVE_MMAP | |
13583 | intptr_t begin = (intptr_t) info->buffer; | |
13584 | intptr_t map_begin = begin & ~(pagesize - 1); | |
13585 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 13586 | |
dce234bc PP |
13587 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
13588 | #else | |
13589 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
13590 | gdb_assert (0); | |
13591 | #endif | |
13592 | } | |
13593 | } | |
13594 | ||
13595 | /* munmap debug sections for OBJFILE, if necessary. */ | |
13596 | ||
13597 | static void | |
c1bd65d0 | 13598 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
13599 | { |
13600 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 13601 | |
dce234bc PP |
13602 | munmap_section_buffer (&data->info); |
13603 | munmap_section_buffer (&data->abbrev); | |
13604 | munmap_section_buffer (&data->line); | |
13605 | munmap_section_buffer (&data->str); | |
13606 | munmap_section_buffer (&data->macinfo); | |
13607 | munmap_section_buffer (&data->ranges); | |
13608 | munmap_section_buffer (&data->loc); | |
13609 | munmap_section_buffer (&data->frame); | |
13610 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
13611 | munmap_section_buffer (&data->gdb_index); |
13612 | } | |
13613 | ||
13614 | \f | |
13615 | ||
13616 | /* The contents of the hash table we create when building the string | |
13617 | table. */ | |
13618 | struct strtab_entry | |
13619 | { | |
13620 | offset_type offset; | |
13621 | const char *str; | |
13622 | }; | |
13623 | ||
13624 | /* Hash function for a strtab_entry. */ | |
13625 | static hashval_t | |
13626 | hash_strtab_entry (const void *e) | |
13627 | { | |
13628 | const struct strtab_entry *entry = e; | |
13629 | return mapped_index_string_hash (entry->str); | |
13630 | } | |
13631 | ||
13632 | /* Equality function for a strtab_entry. */ | |
13633 | static int | |
13634 | eq_strtab_entry (const void *a, const void *b) | |
13635 | { | |
13636 | const struct strtab_entry *ea = a; | |
13637 | const struct strtab_entry *eb = b; | |
13638 | return !strcmp (ea->str, eb->str); | |
13639 | } | |
13640 | ||
13641 | /* Create a strtab_entry hash table. */ | |
13642 | static htab_t | |
13643 | create_strtab (void) | |
13644 | { | |
13645 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
13646 | xfree, xcalloc, xfree); | |
13647 | } | |
13648 | ||
13649 | /* Add a string to the constant pool. Return the string's offset in | |
13650 | host order. */ | |
13651 | static offset_type | |
13652 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
13653 | { | |
13654 | void **slot; | |
13655 | struct strtab_entry entry; | |
13656 | struct strtab_entry *result; | |
13657 | ||
13658 | entry.str = str; | |
13659 | slot = htab_find_slot (table, &entry, INSERT); | |
13660 | if (*slot) | |
13661 | result = *slot; | |
13662 | else | |
13663 | { | |
13664 | result = XNEW (struct strtab_entry); | |
13665 | result->offset = obstack_object_size (cpool); | |
13666 | result->str = str; | |
13667 | obstack_grow_str0 (cpool, str); | |
13668 | *slot = result; | |
13669 | } | |
13670 | return result->offset; | |
13671 | } | |
13672 | ||
13673 | /* An entry in the symbol table. */ | |
13674 | struct symtab_index_entry | |
13675 | { | |
13676 | /* The name of the symbol. */ | |
13677 | const char *name; | |
13678 | /* The offset of the name in the constant pool. */ | |
13679 | offset_type index_offset; | |
13680 | /* A sorted vector of the indices of all the CUs that hold an object | |
13681 | of this name. */ | |
13682 | VEC (offset_type) *cu_indices; | |
13683 | }; | |
13684 | ||
13685 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
13686 | struct mapped_symtab | |
13687 | { | |
13688 | offset_type n_elements; | |
13689 | offset_type size; | |
13690 | struct symtab_index_entry **data; | |
13691 | }; | |
13692 | ||
13693 | /* Hash function for a symtab_index_entry. */ | |
13694 | static hashval_t | |
13695 | hash_symtab_entry (const void *e) | |
13696 | { | |
13697 | const struct symtab_index_entry *entry = e; | |
13698 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
13699 | sizeof (offset_type) * VEC_length (offset_type, | |
13700 | entry->cu_indices), | |
13701 | 0); | |
13702 | } | |
13703 | ||
13704 | /* Equality function for a symtab_index_entry. */ | |
13705 | static int | |
13706 | eq_symtab_entry (const void *a, const void *b) | |
13707 | { | |
13708 | const struct symtab_index_entry *ea = a; | |
13709 | const struct symtab_index_entry *eb = b; | |
13710 | int len = VEC_length (offset_type, ea->cu_indices); | |
13711 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
13712 | return 0; | |
13713 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
13714 | VEC_address (offset_type, eb->cu_indices), | |
13715 | sizeof (offset_type) * len); | |
13716 | } | |
13717 | ||
13718 | /* Destroy a symtab_index_entry. */ | |
13719 | static void | |
13720 | delete_symtab_entry (void *p) | |
13721 | { | |
13722 | struct symtab_index_entry *entry = p; | |
13723 | VEC_free (offset_type, entry->cu_indices); | |
13724 | xfree (entry); | |
13725 | } | |
13726 | ||
13727 | /* Create a hash table holding symtab_index_entry objects. */ | |
13728 | static htab_t | |
13729 | create_index_table (void) | |
13730 | { | |
13731 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
13732 | delete_symtab_entry, xcalloc, xfree); | |
13733 | } | |
13734 | ||
13735 | /* Create a new mapped symtab object. */ | |
13736 | static struct mapped_symtab * | |
13737 | create_mapped_symtab (void) | |
13738 | { | |
13739 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
13740 | symtab->n_elements = 0; | |
13741 | symtab->size = 1024; | |
13742 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
13743 | return symtab; | |
13744 | } | |
13745 | ||
13746 | /* Destroy a mapped_symtab. */ | |
13747 | static void | |
13748 | cleanup_mapped_symtab (void *p) | |
13749 | { | |
13750 | struct mapped_symtab *symtab = p; | |
13751 | /* The contents of the array are freed when the other hash table is | |
13752 | destroyed. */ | |
13753 | xfree (symtab->data); | |
13754 | xfree (symtab); | |
13755 | } | |
13756 | ||
13757 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
13758 | the slot. */ | |
13759 | static struct symtab_index_entry ** | |
13760 | find_slot (struct mapped_symtab *symtab, const char *name) | |
13761 | { | |
13762 | offset_type index, step, hash = mapped_index_string_hash (name); | |
13763 | ||
13764 | index = hash & (symtab->size - 1); | |
13765 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
13766 | ||
13767 | for (;;) | |
13768 | { | |
13769 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
13770 | return &symtab->data[index]; | |
13771 | index = (index + step) & (symtab->size - 1); | |
13772 | } | |
13773 | } | |
13774 | ||
13775 | /* Expand SYMTAB's hash table. */ | |
13776 | static void | |
13777 | hash_expand (struct mapped_symtab *symtab) | |
13778 | { | |
13779 | offset_type old_size = symtab->size; | |
13780 | offset_type i; | |
13781 | struct symtab_index_entry **old_entries = symtab->data; | |
13782 | ||
13783 | symtab->size *= 2; | |
13784 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
13785 | ||
13786 | for (i = 0; i < old_size; ++i) | |
13787 | { | |
13788 | if (old_entries[i]) | |
13789 | { | |
13790 | struct symtab_index_entry **slot = find_slot (symtab, | |
13791 | old_entries[i]->name); | |
13792 | *slot = old_entries[i]; | |
13793 | } | |
13794 | } | |
13795 | ||
13796 | xfree (old_entries); | |
13797 | } | |
13798 | ||
13799 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
13800 | is the index of the CU in which the symbol appears. */ | |
13801 | static void | |
13802 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
13803 | offset_type cu_index) | |
13804 | { | |
13805 | struct symtab_index_entry **slot; | |
13806 | ||
13807 | ++symtab->n_elements; | |
13808 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
13809 | hash_expand (symtab); | |
13810 | ||
13811 | slot = find_slot (symtab, name); | |
13812 | if (!*slot) | |
13813 | { | |
13814 | *slot = XNEW (struct symtab_index_entry); | |
13815 | (*slot)->name = name; | |
13816 | (*slot)->cu_indices = NULL; | |
13817 | } | |
13818 | /* Don't push an index twice. Due to how we add entries we only | |
13819 | have to check the last one. */ | |
13820 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
13821 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) | |
13822 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); | |
13823 | } | |
13824 | ||
13825 | /* Add a vector of indices to the constant pool. */ | |
13826 | static offset_type | |
13827 | add_indices_to_cpool (htab_t index_table, struct obstack *cpool, | |
13828 | struct symtab_index_entry *entry) | |
13829 | { | |
13830 | void **slot; | |
13831 | ||
13832 | slot = htab_find_slot (index_table, entry, INSERT); | |
13833 | if (!*slot) | |
13834 | { | |
13835 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
13836 | offset_type val = MAYBE_SWAP (len); | |
13837 | offset_type iter; | |
13838 | int i; | |
13839 | ||
13840 | *slot = entry; | |
13841 | entry->index_offset = obstack_object_size (cpool); | |
13842 | ||
13843 | obstack_grow (cpool, &val, sizeof (val)); | |
13844 | for (i = 0; | |
13845 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
13846 | ++i) | |
13847 | { | |
13848 | val = MAYBE_SWAP (iter); | |
13849 | obstack_grow (cpool, &val, sizeof (val)); | |
13850 | } | |
13851 | } | |
13852 | else | |
13853 | { | |
13854 | struct symtab_index_entry *old_entry = *slot; | |
13855 | entry->index_offset = old_entry->index_offset; | |
13856 | entry = old_entry; | |
13857 | } | |
13858 | return entry->index_offset; | |
13859 | } | |
13860 | ||
13861 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
13862 | constant pool entries going into the obstack CPOOL. */ | |
13863 | static void | |
13864 | write_hash_table (struct mapped_symtab *symtab, | |
13865 | struct obstack *output, struct obstack *cpool) | |
13866 | { | |
13867 | offset_type i; | |
13868 | htab_t index_table; | |
13869 | htab_t str_table; | |
13870 | ||
13871 | index_table = create_index_table (); | |
13872 | str_table = create_strtab (); | |
13873 | /* We add all the index vectors to the constant pool first, to | |
13874 | ensure alignment is ok. */ | |
13875 | for (i = 0; i < symtab->size; ++i) | |
13876 | { | |
13877 | if (symtab->data[i]) | |
13878 | add_indices_to_cpool (index_table, cpool, symtab->data[i]); | |
13879 | } | |
13880 | ||
13881 | /* Now write out the hash table. */ | |
13882 | for (i = 0; i < symtab->size; ++i) | |
13883 | { | |
13884 | offset_type str_off, vec_off; | |
13885 | ||
13886 | if (symtab->data[i]) | |
13887 | { | |
13888 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
13889 | vec_off = symtab->data[i]->index_offset; | |
13890 | } | |
13891 | else | |
13892 | { | |
13893 | /* While 0 is a valid constant pool index, it is not valid | |
13894 | to have 0 for both offsets. */ | |
13895 | str_off = 0; | |
13896 | vec_off = 0; | |
13897 | } | |
13898 | ||
13899 | str_off = MAYBE_SWAP (str_off); | |
13900 | vec_off = MAYBE_SWAP (vec_off); | |
13901 | ||
13902 | obstack_grow (output, &str_off, sizeof (str_off)); | |
13903 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
13904 | } | |
13905 | ||
13906 | htab_delete (str_table); | |
13907 | htab_delete (index_table); | |
13908 | } | |
13909 | ||
13910 | /* Write an address entry to ADDR_OBSTACK. The addresses are taken | |
13911 | from PST; CU_INDEX is the index of the CU in the vector of all | |
13912 | CUs. */ | |
13913 | static void | |
13914 | add_address_entry (struct objfile *objfile, | |
13915 | struct obstack *addr_obstack, struct partial_symtab *pst, | |
13916 | unsigned int cu_index) | |
13917 | { | |
13918 | offset_type offset; | |
13919 | char addr[8]; | |
13920 | CORE_ADDR baseaddr; | |
13921 | ||
13922 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
13923 | ||
13924 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr); | |
13925 | obstack_grow (addr_obstack, addr, 8); | |
13926 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr); | |
13927 | obstack_grow (addr_obstack, addr, 8); | |
13928 | offset = MAYBE_SWAP (cu_index); | |
13929 | obstack_grow (addr_obstack, &offset, sizeof (offset_type)); | |
13930 | } | |
13931 | ||
13932 | /* Add a list of partial symbols to SYMTAB. */ | |
13933 | static void | |
13934 | write_psymbols (struct mapped_symtab *symtab, | |
13935 | struct partial_symbol **psymp, | |
13936 | int count, | |
13937 | offset_type cu_index) | |
13938 | { | |
13939 | for (; count-- > 0; ++psymp) | |
13940 | { | |
13941 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) | |
13942 | error (_("Ada is not currently supported by the index")); | |
13943 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
13944 | } | |
13945 | } | |
13946 | ||
13947 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
13948 | exception if there is an error. */ | |
13949 | static void | |
13950 | write_obstack (FILE *file, struct obstack *obstack) | |
13951 | { | |
13952 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
13953 | file) | |
13954 | != obstack_object_size (obstack)) | |
13955 | error (_("couldn't data write to file")); | |
13956 | } | |
13957 | ||
13958 | /* Unlink a file if the argument is not NULL. */ | |
13959 | static void | |
13960 | unlink_if_set (void *p) | |
13961 | { | |
13962 | char **filename = p; | |
13963 | if (*filename) | |
13964 | unlink (*filename); | |
13965 | } | |
13966 | ||
13967 | /* Create an index file for OBJFILE in the directory DIR. */ | |
13968 | static void | |
13969 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
13970 | { | |
13971 | struct cleanup *cleanup; | |
13972 | char *filename, *cleanup_filename; | |
13973 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack, cu_list; | |
13974 | int i; | |
13975 | FILE *out_file; | |
13976 | struct mapped_symtab *symtab; | |
13977 | offset_type val, size_of_contents, total_len; | |
13978 | struct stat st; | |
13979 | char buf[8]; | |
13980 | ||
13981 | if (!objfile->psymtabs) | |
13982 | return; | |
13983 | if (dwarf2_per_objfile->using_index) | |
13984 | error (_("Cannot use an index to create the index")); | |
13985 | ||
13986 | if (stat (objfile->name, &st) < 0) | |
13987 | perror_with_name (_("Could not stat")); | |
13988 | ||
13989 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
13990 | INDEX_SUFFIX, (char *) NULL); | |
13991 | cleanup = make_cleanup (xfree, filename); | |
13992 | ||
13993 | out_file = fopen (filename, "wb"); | |
13994 | if (!out_file) | |
13995 | error (_("Can't open `%s' for writing"), filename); | |
13996 | ||
13997 | cleanup_filename = filename; | |
13998 | make_cleanup (unlink_if_set, &cleanup_filename); | |
13999 | ||
14000 | symtab = create_mapped_symtab (); | |
14001 | make_cleanup (cleanup_mapped_symtab, symtab); | |
14002 | ||
14003 | obstack_init (&addr_obstack); | |
14004 | make_cleanup_obstack_free (&addr_obstack); | |
14005 | ||
14006 | obstack_init (&cu_list); | |
14007 | make_cleanup_obstack_free (&cu_list); | |
14008 | ||
14009 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
14010 | { | |
14011 | struct dwarf2_per_cu_data *cu = dwarf2_per_objfile->all_comp_units[i]; | |
14012 | struct partial_symtab *psymtab = cu->v.psymtab; | |
14013 | gdb_byte val[8]; | |
14014 | ||
14015 | write_psymbols (symtab, | |
14016 | objfile->global_psymbols.list + psymtab->globals_offset, | |
14017 | psymtab->n_global_syms, i); | |
14018 | write_psymbols (symtab, | |
14019 | objfile->static_psymbols.list + psymtab->statics_offset, | |
14020 | psymtab->n_static_syms, i); | |
14021 | ||
14022 | add_address_entry (objfile, &addr_obstack, psymtab, i); | |
14023 | ||
14024 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->offset); | |
14025 | obstack_grow (&cu_list, val, 8); | |
14026 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, cu->length); | |
14027 | obstack_grow (&cu_list, val, 8); | |
14028 | } | |
14029 | ||
14030 | obstack_init (&constant_pool); | |
14031 | make_cleanup_obstack_free (&constant_pool); | |
14032 | obstack_init (&symtab_obstack); | |
14033 | make_cleanup_obstack_free (&symtab_obstack); | |
14034 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
14035 | ||
14036 | obstack_init (&contents); | |
14037 | make_cleanup_obstack_free (&contents); | |
14038 | size_of_contents = 5 * sizeof (offset_type); | |
14039 | total_len = size_of_contents; | |
14040 | ||
14041 | /* The version number. */ | |
14042 | val = MAYBE_SWAP (1); | |
14043 | obstack_grow (&contents, &val, sizeof (val)); | |
14044 | ||
14045 | /* The offset of the CU list from the start of the file. */ | |
14046 | val = MAYBE_SWAP (total_len); | |
14047 | obstack_grow (&contents, &val, sizeof (val)); | |
14048 | total_len += obstack_object_size (&cu_list); | |
14049 | ||
14050 | /* The offset of the address table from the start of the file. */ | |
14051 | val = MAYBE_SWAP (total_len); | |
14052 | obstack_grow (&contents, &val, sizeof (val)); | |
14053 | total_len += obstack_object_size (&addr_obstack); | |
14054 | ||
14055 | /* The offset of the symbol table from the start of the file. */ | |
14056 | val = MAYBE_SWAP (total_len); | |
14057 | obstack_grow (&contents, &val, sizeof (val)); | |
14058 | total_len += obstack_object_size (&symtab_obstack); | |
14059 | ||
14060 | /* The offset of the constant pool from the start of the file. */ | |
14061 | val = MAYBE_SWAP (total_len); | |
14062 | obstack_grow (&contents, &val, sizeof (val)); | |
14063 | total_len += obstack_object_size (&constant_pool); | |
14064 | ||
14065 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
14066 | ||
14067 | write_obstack (out_file, &contents); | |
14068 | write_obstack (out_file, &cu_list); | |
14069 | write_obstack (out_file, &addr_obstack); | |
14070 | write_obstack (out_file, &symtab_obstack); | |
14071 | write_obstack (out_file, &constant_pool); | |
14072 | ||
14073 | fclose (out_file); | |
14074 | ||
14075 | /* We want to keep the file, so we set cleanup_filename to NULL | |
14076 | here. See unlink_if_set. */ | |
14077 | cleanup_filename = NULL; | |
14078 | ||
14079 | do_cleanups (cleanup); | |
14080 | } | |
14081 | ||
14082 | /* The mapped index file format is designed to be directly mmap()able | |
14083 | on any architecture. In most cases, a datum is represented using a | |
14084 | little-endian 32-bit integer value, called an offset_type. Big | |
14085 | endian machines must byte-swap the values before using them. | |
14086 | Exceptions to this rule are noted. The data is laid out such that | |
14087 | alignment is always respected. | |
14088 | ||
14089 | A mapped index consists of several sections. | |
14090 | ||
14091 | 1. The file header. This is a sequence of values, of offset_type | |
14092 | unless otherwise noted: | |
14093 | [0] The version number. Currently 1. | |
14094 | [1] The offset, from the start of the file, of the CU list. | |
14095 | [2] The offset, from the start of the file, of the address section. | |
14096 | [3] The offset, from the start of the file, of the symbol table. | |
14097 | [4] The offset, from the start of the file, of the constant pool. | |
14098 | ||
14099 | 2. The CU list. This is a sequence of pairs of 64-bit | |
14100 | little-endian values. The first element in each pair is the offset | |
14101 | of a CU in the .debug_info section. The second element in each | |
14102 | pair is the length of that CU. References to a CU elsewhere in the | |
14103 | map are done using a CU index, which is just the 0-based index into | |
14104 | this table. | |
14105 | ||
14106 | 3. The address section. The address section consists of a sequence | |
14107 | of address entries. Each address entry has three elements. | |
14108 | [0] The low address. This is a 64-bit little-endian value. | |
14109 | [1] The high address. This is a 64-bit little-endian value. | |
14110 | [2] The CU index. This is an offset_type value. | |
14111 | ||
14112 | 4. The symbol table. This is a hash table. The size of the hash | |
14113 | table is always a power of 2. The initial hash and the step are | |
14114 | currently defined by the `find_slot' function. | |
14115 | ||
14116 | Each slot in the hash table consists of a pair of offset_type | |
14117 | values. The first value is the offset of the symbol's name in the | |
14118 | constant pool. The second value is the offset of the CU vector in | |
14119 | the constant pool. | |
14120 | ||
14121 | If both values are 0, then this slot in the hash table is empty. | |
14122 | This is ok because while 0 is a valid constant pool index, it | |
14123 | cannot be a valid index for both a string and a CU vector. | |
14124 | ||
14125 | A string in the constant pool is stored as a \0-terminated string, | |
14126 | as you'd expect. | |
14127 | ||
14128 | A CU vector in the constant pool is a sequence of offset_type | |
14129 | values. The first value is the number of CU indices in the vector. | |
14130 | Each subsequent value is the index of a CU in the CU list. This | |
14131 | element in the hash table is used to indicate which CUs define the | |
14132 | symbol. | |
14133 | ||
14134 | 5. The constant pool. This is simply a bunch of bytes. It is | |
14135 | organized so that alignment is correct: CU vectors are stored | |
14136 | first, followed by strings. */ | |
14137 | static void | |
14138 | save_gdb_index_command (char *arg, int from_tty) | |
14139 | { | |
14140 | struct objfile *objfile; | |
14141 | ||
14142 | if (!arg || !*arg) | |
14143 | error (_("usage: maintenance save-gdb-index DIRECTORY")); | |
14144 | ||
14145 | ALL_OBJFILES (objfile) | |
14146 | { | |
14147 | struct stat st; | |
14148 | ||
14149 | /* If the objfile does not correspond to an actual file, skip it. */ | |
14150 | if (stat (objfile->name, &st) < 0) | |
14151 | continue; | |
14152 | ||
14153 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
14154 | if (dwarf2_per_objfile) | |
14155 | { | |
14156 | volatile struct gdb_exception except; | |
14157 | ||
14158 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
14159 | { | |
14160 | write_psymtabs_to_index (objfile, arg); | |
14161 | } | |
14162 | if (except.reason < 0) | |
14163 | exception_fprintf (gdb_stderr, except, | |
14164 | _("Error while writing index for `%s': "), | |
14165 | objfile->name); | |
14166 | } | |
14167 | } | |
dce234bc PP |
14168 | } |
14169 | ||
9291a0cd TT |
14170 | \f |
14171 | ||
9eae7c52 TT |
14172 | int dwarf2_always_disassemble; |
14173 | ||
14174 | static void | |
14175 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
14176 | struct cmd_list_element *c, const char *value) | |
14177 | { | |
14178 | fprintf_filtered (file, _("\ | |
14179 | Whether to always disassemble DWARF expressions is %s.\n"), | |
14180 | value); | |
14181 | } | |
14182 | ||
6502dd73 DJ |
14183 | void _initialize_dwarf2_read (void); |
14184 | ||
14185 | void | |
14186 | _initialize_dwarf2_read (void) | |
14187 | { | |
dce234bc | 14188 | dwarf2_objfile_data_key |
c1bd65d0 | 14189 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 14190 | |
1bedd215 AC |
14191 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
14192 | Set DWARF 2 specific variables.\n\ | |
14193 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
14194 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
14195 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
14196 | ||
1bedd215 AC |
14197 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
14198 | Show DWARF 2 specific variables\n\ | |
14199 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
14200 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
14201 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
14202 | ||
14203 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
14204 | &dwarf2_max_cache_age, _("\ |
14205 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
14206 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
14207 | A higher limit means that cached compilation units will be stored\n\ | |
14208 | in memory longer, and more total memory will be used. Zero disables\n\ | |
14209 | caching, which can slow down startup."), | |
2c5b56ce | 14210 | NULL, |
920d2a44 | 14211 | show_dwarf2_max_cache_age, |
2c5b56ce | 14212 | &set_dwarf2_cmdlist, |
ae038cb0 | 14213 | &show_dwarf2_cmdlist); |
d97bc12b | 14214 | |
9eae7c52 TT |
14215 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
14216 | &dwarf2_always_disassemble, _("\ | |
14217 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
14218 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
14219 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
14220 | syntax. When disabled, expressions will be printed in a more\n\ | |
14221 | conversational style, when possible."), | |
14222 | NULL, | |
14223 | show_dwarf2_always_disassemble, | |
14224 | &set_dwarf2_cmdlist, | |
14225 | &show_dwarf2_cmdlist); | |
14226 | ||
d97bc12b DE |
14227 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
14228 | Set debugging of the dwarf2 DIE reader."), _("\ | |
14229 | Show debugging of the dwarf2 DIE reader."), _("\ | |
14230 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
14231 | The value is the maximum depth to print."), | |
14232 | NULL, | |
14233 | NULL, | |
14234 | &setdebuglist, &showdebuglist); | |
9291a0cd TT |
14235 | |
14236 | add_cmd ("gdb-index", class_files, save_gdb_index_command, | |
14237 | _("Save a .gdb-index file"), | |
14238 | &save_cmdlist); | |
6502dd73 | 14239 | } |