Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
6aba47ca | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
4c38e0a4 | 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010 |
0fb0cc75 | 5 | Free Software Foundation, Inc. |
c906108c SS |
6 | |
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 12 | support. |
c906108c | 13 | |
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
18 | the Free Software Foundation; either version 3 of the License, or |
19 | (at your option) any later version. | |
c906108c | 20 | |
a9762ec7 JB |
21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
c906108c | 25 | |
c5aa993b | 26 | You should have received a copy of the GNU General Public License |
a9762ec7 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
28 | |
29 | #include "defs.h" | |
30 | #include "bfd.h" | |
c906108c SS |
31 | #include "symtab.h" |
32 | #include "gdbtypes.h" | |
c906108c | 33 | #include "objfiles.h" |
fa8f86ff | 34 | #include "dwarf2.h" |
c906108c SS |
35 | #include "buildsym.h" |
36 | #include "demangle.h" | |
37 | #include "expression.h" | |
d5166ae1 | 38 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 39 | #include "macrotab.h" |
c906108c SS |
40 | #include "language.h" |
41 | #include "complaints.h" | |
357e46e7 | 42 | #include "bcache.h" |
4c2df51b DJ |
43 | #include "dwarf2expr.h" |
44 | #include "dwarf2loc.h" | |
9219021c | 45 | #include "cp-support.h" |
72bf9492 | 46 | #include "hashtab.h" |
ae038cb0 DJ |
47 | #include "command.h" |
48 | #include "gdbcmd.h" | |
edb3359d | 49 | #include "block.h" |
ff013f42 | 50 | #include "addrmap.h" |
94af9270 KS |
51 | #include "typeprint.h" |
52 | #include "jv-lang.h" | |
ccefe4c4 | 53 | #include "psympriv.h" |
9291a0cd TT |
54 | #include "exceptions.h" |
55 | #include "gdb_stat.h" | |
96d19272 | 56 | #include "completer.h" |
34eaf542 | 57 | #include "vec.h" |
98bfdba5 PA |
58 | #include "c-lang.h" |
59 | #include "valprint.h" | |
4c2df51b | 60 | |
c906108c SS |
61 | #include <fcntl.h> |
62 | #include "gdb_string.h" | |
4bdf3d34 | 63 | #include "gdb_assert.h" |
c906108c | 64 | #include <sys/types.h> |
233a11ab CS |
65 | #ifdef HAVE_ZLIB_H |
66 | #include <zlib.h> | |
67 | #endif | |
dce234bc PP |
68 | #ifdef HAVE_MMAP |
69 | #include <sys/mman.h> | |
85d9bd0e TT |
70 | #ifndef MAP_FAILED |
71 | #define MAP_FAILED ((void *) -1) | |
72 | #endif | |
dce234bc | 73 | #endif |
d8151005 | 74 | |
34eaf542 TT |
75 | typedef struct symbol *symbolp; |
76 | DEF_VEC_P (symbolp); | |
77 | ||
107d2387 | 78 | #if 0 |
357e46e7 | 79 | /* .debug_info header for a compilation unit |
c906108c SS |
80 | Because of alignment constraints, this structure has padding and cannot |
81 | be mapped directly onto the beginning of the .debug_info section. */ | |
82 | typedef struct comp_unit_header | |
83 | { | |
84 | unsigned int length; /* length of the .debug_info | |
85 | contribution */ | |
86 | unsigned short version; /* version number -- 2 for DWARF | |
87 | version 2 */ | |
88 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
89 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
90 | } | |
91 | _COMP_UNIT_HEADER; | |
92 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 93 | #endif |
c906108c | 94 | |
c906108c SS |
95 | /* .debug_line statement program prologue |
96 | Because of alignment constraints, this structure has padding and cannot | |
97 | be mapped directly onto the beginning of the .debug_info section. */ | |
98 | typedef struct statement_prologue | |
99 | { | |
100 | unsigned int total_length; /* byte length of the statement | |
101 | information */ | |
102 | unsigned short version; /* version number -- 2 for DWARF | |
103 | version 2 */ | |
104 | unsigned int prologue_length; /* # bytes between prologue & | |
105 | stmt program */ | |
106 | unsigned char minimum_instruction_length; /* byte size of | |
107 | smallest instr */ | |
108 | unsigned char default_is_stmt; /* initial value of is_stmt | |
109 | register */ | |
110 | char line_base; | |
111 | unsigned char line_range; | |
112 | unsigned char opcode_base; /* number assigned to first special | |
113 | opcode */ | |
114 | unsigned char *standard_opcode_lengths; | |
115 | } | |
116 | _STATEMENT_PROLOGUE; | |
117 | ||
d97bc12b DE |
118 | /* When non-zero, dump DIEs after they are read in. */ |
119 | static int dwarf2_die_debug = 0; | |
120 | ||
dce234bc PP |
121 | static int pagesize; |
122 | ||
df8a16a1 DJ |
123 | /* When set, the file that we're processing is known to have debugging |
124 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
125 | but later versions do. */ | |
126 | ||
127 | static int processing_has_namespace_info; | |
128 | ||
6502dd73 DJ |
129 | static const struct objfile_data *dwarf2_objfile_data_key; |
130 | ||
dce234bc PP |
131 | struct dwarf2_section_info |
132 | { | |
133 | asection *asection; | |
134 | gdb_byte *buffer; | |
135 | bfd_size_type size; | |
136 | int was_mmapped; | |
be391dca TT |
137 | /* True if we have tried to read this section. */ |
138 | int readin; | |
dce234bc PP |
139 | }; |
140 | ||
9291a0cd TT |
141 | /* All offsets in the index are of this type. It must be |
142 | architecture-independent. */ | |
143 | typedef uint32_t offset_type; | |
144 | ||
145 | DEF_VEC_I (offset_type); | |
146 | ||
147 | /* A description of the mapped index. The file format is described in | |
148 | a comment by the code that writes the index. */ | |
149 | struct mapped_index | |
150 | { | |
151 | /* The total length of the buffer. */ | |
152 | off_t total_size; | |
153 | /* A pointer to the address table data. */ | |
154 | const gdb_byte *address_table; | |
155 | /* Size of the address table data in bytes. */ | |
156 | offset_type address_table_size; | |
157 | /* The hash table. */ | |
158 | const offset_type *index_table; | |
159 | /* Size in slots, each slot is 2 offset_types. */ | |
160 | offset_type index_table_slots; | |
161 | /* A pointer to the constant pool. */ | |
162 | const char *constant_pool; | |
163 | }; | |
164 | ||
6502dd73 DJ |
165 | struct dwarf2_per_objfile |
166 | { | |
dce234bc PP |
167 | struct dwarf2_section_info info; |
168 | struct dwarf2_section_info abbrev; | |
169 | struct dwarf2_section_info line; | |
dce234bc PP |
170 | struct dwarf2_section_info loc; |
171 | struct dwarf2_section_info macinfo; | |
172 | struct dwarf2_section_info str; | |
173 | struct dwarf2_section_info ranges; | |
348e048f | 174 | struct dwarf2_section_info types; |
dce234bc PP |
175 | struct dwarf2_section_info frame; |
176 | struct dwarf2_section_info eh_frame; | |
9291a0cd | 177 | struct dwarf2_section_info gdb_index; |
ae038cb0 | 178 | |
be391dca TT |
179 | /* Back link. */ |
180 | struct objfile *objfile; | |
181 | ||
10b3939b DJ |
182 | /* A list of all the compilation units. This is used to locate |
183 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
184 | struct dwarf2_per_cu_data **all_comp_units; |
185 | ||
186 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
187 | int n_comp_units; | |
188 | ||
1fd400ff TT |
189 | /* The number of .debug_types-related CUs. */ |
190 | int n_type_comp_units; | |
191 | ||
192 | /* The .debug_types-related CUs. */ | |
193 | struct dwarf2_per_cu_data **type_comp_units; | |
194 | ||
ae038cb0 DJ |
195 | /* A chain of compilation units that are currently read in, so that |
196 | they can be freed later. */ | |
197 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 | 198 | |
348e048f DE |
199 | /* A table mapping .debug_types signatures to its signatured_type entry. |
200 | This is NULL if the .debug_types section hasn't been read in yet. */ | |
201 | htab_t signatured_types; | |
202 | ||
72dca2f5 FR |
203 | /* A flag indicating wether this objfile has a section loaded at a |
204 | VMA of 0. */ | |
205 | int has_section_at_zero; | |
9291a0cd TT |
206 | |
207 | /* True if we are using the mapped index. */ | |
208 | unsigned char using_index; | |
209 | ||
210 | /* The mapped index. */ | |
211 | struct mapped_index *index_table; | |
98bfdba5 PA |
212 | |
213 | /* Set during partial symbol reading, to prevent queueing of full | |
214 | symbols. */ | |
215 | int reading_partial_symbols; | |
673bfd45 DE |
216 | |
217 | /* Table mapping type .debug_info DIE offsets to types. | |
218 | This is NULL if not allocated yet. | |
219 | It (currently) makes sense to allocate debug_types_type_hash lazily. | |
220 | To keep things simple we allocate both lazily. */ | |
221 | htab_t debug_info_type_hash; | |
222 | ||
223 | /* Table mapping type .debug_types DIE offsets to types. | |
224 | This is NULL if not allocated yet. */ | |
225 | htab_t debug_types_type_hash; | |
6502dd73 DJ |
226 | }; |
227 | ||
228 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
229 | |
230 | /* names of the debugging sections */ | |
231 | ||
233a11ab CS |
232 | /* Note that if the debugging section has been compressed, it might |
233 | have a name like .zdebug_info. */ | |
234 | ||
235 | #define INFO_SECTION "debug_info" | |
236 | #define ABBREV_SECTION "debug_abbrev" | |
237 | #define LINE_SECTION "debug_line" | |
233a11ab CS |
238 | #define LOC_SECTION "debug_loc" |
239 | #define MACINFO_SECTION "debug_macinfo" | |
240 | #define STR_SECTION "debug_str" | |
241 | #define RANGES_SECTION "debug_ranges" | |
348e048f | 242 | #define TYPES_SECTION "debug_types" |
233a11ab CS |
243 | #define FRAME_SECTION "debug_frame" |
244 | #define EH_FRAME_SECTION "eh_frame" | |
9291a0cd | 245 | #define GDB_INDEX_SECTION "gdb_index" |
c906108c SS |
246 | |
247 | /* local data types */ | |
248 | ||
57349743 JB |
249 | /* We hold several abbreviation tables in memory at the same time. */ |
250 | #ifndef ABBREV_HASH_SIZE | |
251 | #define ABBREV_HASH_SIZE 121 | |
252 | #endif | |
253 | ||
107d2387 AC |
254 | /* The data in a compilation unit header, after target2host |
255 | translation, looks like this. */ | |
c906108c | 256 | struct comp_unit_head |
a738430d | 257 | { |
c764a876 | 258 | unsigned int length; |
a738430d | 259 | short version; |
a738430d MK |
260 | unsigned char addr_size; |
261 | unsigned char signed_addr_p; | |
9cbfa09e | 262 | unsigned int abbrev_offset; |
57349743 | 263 | |
a738430d MK |
264 | /* Size of file offsets; either 4 or 8. */ |
265 | unsigned int offset_size; | |
57349743 | 266 | |
a738430d MK |
267 | /* Size of the length field; either 4 or 12. */ |
268 | unsigned int initial_length_size; | |
57349743 | 269 | |
a738430d MK |
270 | /* Offset to the first byte of this compilation unit header in the |
271 | .debug_info section, for resolving relative reference dies. */ | |
272 | unsigned int offset; | |
57349743 | 273 | |
d00adf39 DE |
274 | /* Offset to first die in this cu from the start of the cu. |
275 | This will be the first byte following the compilation unit header. */ | |
276 | unsigned int first_die_offset; | |
a738430d | 277 | }; |
c906108c | 278 | |
3da10d80 KS |
279 | /* Type used for delaying computation of method physnames. |
280 | See comments for compute_delayed_physnames. */ | |
281 | struct delayed_method_info | |
282 | { | |
283 | /* The type to which the method is attached, i.e., its parent class. */ | |
284 | struct type *type; | |
285 | ||
286 | /* The index of the method in the type's function fieldlists. */ | |
287 | int fnfield_index; | |
288 | ||
289 | /* The index of the method in the fieldlist. */ | |
290 | int index; | |
291 | ||
292 | /* The name of the DIE. */ | |
293 | const char *name; | |
294 | ||
295 | /* The DIE associated with this method. */ | |
296 | struct die_info *die; | |
297 | }; | |
298 | ||
299 | typedef struct delayed_method_info delayed_method_info; | |
300 | DEF_VEC_O (delayed_method_info); | |
301 | ||
e7c27a73 DJ |
302 | /* Internal state when decoding a particular compilation unit. */ |
303 | struct dwarf2_cu | |
304 | { | |
305 | /* The objfile containing this compilation unit. */ | |
306 | struct objfile *objfile; | |
307 | ||
d00adf39 | 308 | /* The header of the compilation unit. */ |
e7c27a73 | 309 | struct comp_unit_head header; |
e142c38c | 310 | |
d00adf39 DE |
311 | /* Base address of this compilation unit. */ |
312 | CORE_ADDR base_address; | |
313 | ||
314 | /* Non-zero if base_address has been set. */ | |
315 | int base_known; | |
316 | ||
e142c38c DJ |
317 | struct function_range *first_fn, *last_fn, *cached_fn; |
318 | ||
319 | /* The language we are debugging. */ | |
320 | enum language language; | |
321 | const struct language_defn *language_defn; | |
322 | ||
b0f35d58 DL |
323 | const char *producer; |
324 | ||
e142c38c DJ |
325 | /* The generic symbol table building routines have separate lists for |
326 | file scope symbols and all all other scopes (local scopes). So | |
327 | we need to select the right one to pass to add_symbol_to_list(). | |
328 | We do it by keeping a pointer to the correct list in list_in_scope. | |
329 | ||
330 | FIXME: The original dwarf code just treated the file scope as the | |
331 | first local scope, and all other local scopes as nested local | |
332 | scopes, and worked fine. Check to see if we really need to | |
333 | distinguish these in buildsym.c. */ | |
334 | struct pending **list_in_scope; | |
335 | ||
f3dd6933 DJ |
336 | /* DWARF abbreviation table associated with this compilation unit. */ |
337 | struct abbrev_info **dwarf2_abbrevs; | |
338 | ||
339 | /* Storage for the abbrev table. */ | |
340 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
341 | |
342 | /* Hash table holding all the loaded partial DIEs. */ | |
343 | htab_t partial_dies; | |
344 | ||
345 | /* Storage for things with the same lifetime as this read-in compilation | |
346 | unit, including partial DIEs. */ | |
347 | struct obstack comp_unit_obstack; | |
348 | ||
ae038cb0 DJ |
349 | /* When multiple dwarf2_cu structures are living in memory, this field |
350 | chains them all together, so that they can be released efficiently. | |
351 | We will probably also want a generation counter so that most-recently-used | |
352 | compilation units are cached... */ | |
353 | struct dwarf2_per_cu_data *read_in_chain; | |
354 | ||
355 | /* Backchain to our per_cu entry if the tree has been built. */ | |
356 | struct dwarf2_per_cu_data *per_cu; | |
357 | ||
358 | /* How many compilation units ago was this CU last referenced? */ | |
359 | int last_used; | |
360 | ||
10b3939b | 361 | /* A hash table of die offsets for following references. */ |
51545339 | 362 | htab_t die_hash; |
10b3939b DJ |
363 | |
364 | /* Full DIEs if read in. */ | |
365 | struct die_info *dies; | |
366 | ||
367 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
368 | units referenced by this one. Only set during full symbol processing; | |
369 | partial symbol tables do not have dependencies. */ | |
370 | htab_t dependencies; | |
371 | ||
cb1df416 DJ |
372 | /* Header data from the line table, during full symbol processing. */ |
373 | struct line_header *line_header; | |
374 | ||
3da10d80 KS |
375 | /* A list of methods which need to have physnames computed |
376 | after all type information has been read. */ | |
377 | VEC (delayed_method_info) *method_list; | |
378 | ||
ae038cb0 DJ |
379 | /* Mark used when releasing cached dies. */ |
380 | unsigned int mark : 1; | |
381 | ||
382 | /* This flag will be set if this compilation unit might include | |
383 | inter-compilation-unit references. */ | |
384 | unsigned int has_form_ref_addr : 1; | |
385 | ||
72bf9492 DJ |
386 | /* This flag will be set if this compilation unit includes any |
387 | DW_TAG_namespace DIEs. If we know that there are explicit | |
388 | DIEs for namespaces, we don't need to try to infer them | |
389 | from mangled names. */ | |
390 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
391 | }; |
392 | ||
9291a0cd TT |
393 | /* When using the index (and thus not using psymtabs), each CU has an |
394 | object of this type. This is used to hold information needed by | |
395 | the various "quick" methods. */ | |
396 | struct dwarf2_per_cu_quick_data | |
397 | { | |
398 | /* The line table. This can be NULL if there was no line table. */ | |
399 | struct line_header *lines; | |
400 | ||
401 | /* The file names from the line table. */ | |
402 | const char **file_names; | |
403 | /* The file names from the line table after being run through | |
404 | gdb_realpath. */ | |
405 | const char **full_names; | |
406 | ||
407 | /* The corresponding symbol table. This is NULL if symbols for this | |
408 | CU have not yet been read. */ | |
409 | struct symtab *symtab; | |
410 | ||
411 | /* A temporary mark bit used when iterating over all CUs in | |
412 | expand_symtabs_matching. */ | |
413 | unsigned int mark : 1; | |
414 | ||
415 | /* True if we've tried to read the line table. */ | |
416 | unsigned int read_lines : 1; | |
417 | }; | |
418 | ||
10b3939b DJ |
419 | /* Persistent data held for a compilation unit, even when not |
420 | processing it. We put a pointer to this structure in the | |
421 | read_symtab_private field of the psymtab. If we encounter | |
422 | inter-compilation-unit references, we also maintain a sorted | |
423 | list of all compilation units. */ | |
424 | ||
ae038cb0 DJ |
425 | struct dwarf2_per_cu_data |
426 | { | |
348e048f | 427 | /* The start offset and length of this compilation unit. 2**29-1 |
ae038cb0 | 428 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
429 | - if it doesn't, GDB will fall over anyway. |
430 | NOTE: Unlike comp_unit_head.length, this length includes | |
431 | initial_length_size. */ | |
c764a876 | 432 | unsigned int offset; |
348e048f | 433 | unsigned int length : 29; |
ae038cb0 DJ |
434 | |
435 | /* Flag indicating this compilation unit will be read in before | |
436 | any of the current compilation units are processed. */ | |
c764a876 | 437 | unsigned int queued : 1; |
ae038cb0 | 438 | |
5afb4e99 DJ |
439 | /* This flag will be set if we need to load absolutely all DIEs |
440 | for this compilation unit, instead of just the ones we think | |
441 | are interesting. It gets set if we look for a DIE in the | |
442 | hash table and don't find it. */ | |
443 | unsigned int load_all_dies : 1; | |
444 | ||
348e048f DE |
445 | /* Non-zero if this CU is from .debug_types. |
446 | Otherwise it's from .debug_info. */ | |
447 | unsigned int from_debug_types : 1; | |
448 | ||
17ea53c3 JK |
449 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
450 | of the CU cache it gets reset to NULL again. */ | |
ae038cb0 | 451 | struct dwarf2_cu *cu; |
1c379e20 | 452 | |
9291a0cd TT |
453 | /* The corresponding objfile. */ |
454 | struct objfile *objfile; | |
455 | ||
456 | /* When using partial symbol tables, the 'psymtab' field is active. | |
457 | Otherwise the 'quick' field is active. */ | |
458 | union | |
459 | { | |
460 | /* The partial symbol table associated with this compilation unit, | |
461 | or NULL for partial units (which do not have an associated | |
462 | symtab). */ | |
463 | struct partial_symtab *psymtab; | |
464 | ||
465 | /* Data needed by the "quick" functions. */ | |
466 | struct dwarf2_per_cu_quick_data *quick; | |
467 | } v; | |
ae038cb0 DJ |
468 | }; |
469 | ||
348e048f DE |
470 | /* Entry in the signatured_types hash table. */ |
471 | ||
472 | struct signatured_type | |
473 | { | |
474 | ULONGEST signature; | |
475 | ||
476 | /* Offset in .debug_types of the TU (type_unit) for this type. */ | |
477 | unsigned int offset; | |
478 | ||
479 | /* Offset in .debug_types of the type defined by this TU. */ | |
480 | unsigned int type_offset; | |
481 | ||
482 | /* The CU(/TU) of this type. */ | |
483 | struct dwarf2_per_cu_data per_cu; | |
484 | }; | |
485 | ||
93311388 DE |
486 | /* Struct used to pass misc. parameters to read_die_and_children, et. al. |
487 | which are used for both .debug_info and .debug_types dies. | |
488 | All parameters here are unchanging for the life of the call. | |
489 | This struct exists to abstract away the constant parameters of | |
490 | die reading. */ | |
491 | ||
492 | struct die_reader_specs | |
493 | { | |
494 | /* The bfd of this objfile. */ | |
495 | bfd* abfd; | |
496 | ||
497 | /* The CU of the DIE we are parsing. */ | |
498 | struct dwarf2_cu *cu; | |
499 | ||
500 | /* Pointer to start of section buffer. | |
501 | This is either the start of .debug_info or .debug_types. */ | |
502 | const gdb_byte *buffer; | |
503 | }; | |
504 | ||
debd256d JB |
505 | /* The line number information for a compilation unit (found in the |
506 | .debug_line section) begins with a "statement program header", | |
507 | which contains the following information. */ | |
508 | struct line_header | |
509 | { | |
510 | unsigned int total_length; | |
511 | unsigned short version; | |
512 | unsigned int header_length; | |
513 | unsigned char minimum_instruction_length; | |
2dc7f7b3 | 514 | unsigned char maximum_ops_per_instruction; |
debd256d JB |
515 | unsigned char default_is_stmt; |
516 | int line_base; | |
517 | unsigned char line_range; | |
518 | unsigned char opcode_base; | |
519 | ||
520 | /* standard_opcode_lengths[i] is the number of operands for the | |
521 | standard opcode whose value is i. This means that | |
522 | standard_opcode_lengths[0] is unused, and the last meaningful | |
523 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
524 | unsigned char *standard_opcode_lengths; | |
525 | ||
526 | /* The include_directories table. NOTE! These strings are not | |
527 | allocated with xmalloc; instead, they are pointers into | |
528 | debug_line_buffer. If you try to free them, `free' will get | |
529 | indigestion. */ | |
530 | unsigned int num_include_dirs, include_dirs_size; | |
531 | char **include_dirs; | |
532 | ||
533 | /* The file_names table. NOTE! These strings are not allocated | |
534 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
535 | Don't try to free them directly. */ | |
536 | unsigned int num_file_names, file_names_size; | |
537 | struct file_entry | |
c906108c | 538 | { |
debd256d JB |
539 | char *name; |
540 | unsigned int dir_index; | |
541 | unsigned int mod_time; | |
542 | unsigned int length; | |
aaa75496 | 543 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 544 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
545 | } *file_names; |
546 | ||
547 | /* The start and end of the statement program following this | |
6502dd73 | 548 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 549 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 550 | }; |
c906108c SS |
551 | |
552 | /* When we construct a partial symbol table entry we only | |
553 | need this much information. */ | |
554 | struct partial_die_info | |
555 | { | |
72bf9492 | 556 | /* Offset of this DIE. */ |
c906108c | 557 | unsigned int offset; |
72bf9492 DJ |
558 | |
559 | /* DWARF-2 tag for this DIE. */ | |
560 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
561 | ||
72bf9492 DJ |
562 | /* Assorted flags describing the data found in this DIE. */ |
563 | unsigned int has_children : 1; | |
564 | unsigned int is_external : 1; | |
565 | unsigned int is_declaration : 1; | |
566 | unsigned int has_type : 1; | |
567 | unsigned int has_specification : 1; | |
568 | unsigned int has_pc_info : 1; | |
569 | ||
570 | /* Flag set if the SCOPE field of this structure has been | |
571 | computed. */ | |
572 | unsigned int scope_set : 1; | |
573 | ||
fa4028e9 JB |
574 | /* Flag set if the DIE has a byte_size attribute. */ |
575 | unsigned int has_byte_size : 1; | |
576 | ||
98bfdba5 PA |
577 | /* Flag set if any of the DIE's children are template arguments. */ |
578 | unsigned int has_template_arguments : 1; | |
579 | ||
72bf9492 | 580 | /* The name of this DIE. Normally the value of DW_AT_name, but |
94af9270 | 581 | sometimes a default name for unnamed DIEs. */ |
c906108c | 582 | char *name; |
72bf9492 DJ |
583 | |
584 | /* The scope to prepend to our children. This is generally | |
585 | allocated on the comp_unit_obstack, so will disappear | |
586 | when this compilation unit leaves the cache. */ | |
587 | char *scope; | |
588 | ||
589 | /* The location description associated with this DIE, if any. */ | |
590 | struct dwarf_block *locdesc; | |
591 | ||
592 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
593 | CORE_ADDR lowpc; |
594 | CORE_ADDR highpc; | |
72bf9492 | 595 | |
93311388 | 596 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
72bf9492 | 597 | DW_AT_sibling, if any. */ |
fe1b8b76 | 598 | gdb_byte *sibling; |
72bf9492 DJ |
599 | |
600 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
601 | DW_AT_specification (or DW_AT_abstract_origin or | |
602 | DW_AT_extension). */ | |
603 | unsigned int spec_offset; | |
604 | ||
605 | /* Pointers to this DIE's parent, first child, and next sibling, | |
606 | if any. */ | |
607 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
608 | }; |
609 | ||
610 | /* This data structure holds the information of an abbrev. */ | |
611 | struct abbrev_info | |
612 | { | |
613 | unsigned int number; /* number identifying abbrev */ | |
614 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
615 | unsigned short has_children; /* boolean */ |
616 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
617 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
618 | struct abbrev_info *next; /* next in chain */ | |
619 | }; | |
620 | ||
621 | struct attr_abbrev | |
622 | { | |
9d25dd43 DE |
623 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
624 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
625 | }; |
626 | ||
b60c80d6 DJ |
627 | /* Attributes have a name and a value */ |
628 | struct attribute | |
629 | { | |
9d25dd43 | 630 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
8285870a JK |
631 | ENUM_BITFIELD(dwarf_form) form : 15; |
632 | ||
633 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This | |
634 | field should be in u.str (existing only for DW_STRING) but it is kept | |
635 | here for better struct attribute alignment. */ | |
636 | unsigned int string_is_canonical : 1; | |
637 | ||
b60c80d6 DJ |
638 | union |
639 | { | |
640 | char *str; | |
641 | struct dwarf_block *blk; | |
43bbcdc2 PH |
642 | ULONGEST unsnd; |
643 | LONGEST snd; | |
b60c80d6 | 644 | CORE_ADDR addr; |
348e048f | 645 | struct signatured_type *signatured_type; |
b60c80d6 DJ |
646 | } |
647 | u; | |
648 | }; | |
649 | ||
c906108c SS |
650 | /* This data structure holds a complete die structure. */ |
651 | struct die_info | |
652 | { | |
76815b17 DE |
653 | /* DWARF-2 tag for this DIE. */ |
654 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
655 | ||
656 | /* Number of attributes */ | |
98bfdba5 PA |
657 | unsigned char num_attrs; |
658 | ||
659 | /* True if we're presently building the full type name for the | |
660 | type derived from this DIE. */ | |
661 | unsigned char building_fullname : 1; | |
76815b17 DE |
662 | |
663 | /* Abbrev number */ | |
664 | unsigned int abbrev; | |
665 | ||
93311388 | 666 | /* Offset in .debug_info or .debug_types section. */ |
76815b17 | 667 | unsigned int offset; |
78ba4af6 JB |
668 | |
669 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
670 | points to this die's parent; CHILD points to the first child of | |
671 | this node; and all the children of a given node are chained | |
672 | together via their SIBLING fields, terminated by a die whose | |
673 | tag is zero. */ | |
639d11d3 DC |
674 | struct die_info *child; /* Its first child, if any. */ |
675 | struct die_info *sibling; /* Its next sibling, if any. */ | |
676 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 677 | |
b60c80d6 DJ |
678 | /* An array of attributes, with NUM_ATTRS elements. There may be |
679 | zero, but it's not common and zero-sized arrays are not | |
680 | sufficiently portable C. */ | |
681 | struct attribute attrs[1]; | |
c906108c SS |
682 | }; |
683 | ||
5fb290d7 DJ |
684 | struct function_range |
685 | { | |
686 | const char *name; | |
687 | CORE_ADDR lowpc, highpc; | |
688 | int seen_line; | |
689 | struct function_range *next; | |
690 | }; | |
691 | ||
c906108c SS |
692 | /* Get at parts of an attribute structure */ |
693 | ||
694 | #define DW_STRING(attr) ((attr)->u.str) | |
8285870a | 695 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
c906108c SS |
696 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
697 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
698 | #define DW_SND(attr) ((attr)->u.snd) | |
699 | #define DW_ADDR(attr) ((attr)->u.addr) | |
348e048f | 700 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
c906108c SS |
701 | |
702 | /* Blocks are a bunch of untyped bytes. */ | |
703 | struct dwarf_block | |
704 | { | |
705 | unsigned int size; | |
fe1b8b76 | 706 | gdb_byte *data; |
c906108c SS |
707 | }; |
708 | ||
c906108c SS |
709 | #ifndef ATTR_ALLOC_CHUNK |
710 | #define ATTR_ALLOC_CHUNK 4 | |
711 | #endif | |
712 | ||
c906108c SS |
713 | /* Allocate fields for structs, unions and enums in this size. */ |
714 | #ifndef DW_FIELD_ALLOC_CHUNK | |
715 | #define DW_FIELD_ALLOC_CHUNK 4 | |
716 | #endif | |
717 | ||
c906108c SS |
718 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
719 | but this would require a corresponding change in unpack_field_as_long | |
720 | and friends. */ | |
721 | static int bits_per_byte = 8; | |
722 | ||
723 | /* The routines that read and process dies for a C struct or C++ class | |
724 | pass lists of data member fields and lists of member function fields | |
725 | in an instance of a field_info structure, as defined below. */ | |
726 | struct field_info | |
c5aa993b JM |
727 | { |
728 | /* List of data member and baseclasses fields. */ | |
729 | struct nextfield | |
730 | { | |
731 | struct nextfield *next; | |
732 | int accessibility; | |
733 | int virtuality; | |
734 | struct field field; | |
735 | } | |
7d0ccb61 | 736 | *fields, *baseclasses; |
c906108c | 737 | |
7d0ccb61 | 738 | /* Number of fields (including baseclasses). */ |
c5aa993b | 739 | int nfields; |
c906108c | 740 | |
c5aa993b JM |
741 | /* Number of baseclasses. */ |
742 | int nbaseclasses; | |
c906108c | 743 | |
c5aa993b JM |
744 | /* Set if the accesibility of one of the fields is not public. */ |
745 | int non_public_fields; | |
c906108c | 746 | |
c5aa993b JM |
747 | /* Member function fields array, entries are allocated in the order they |
748 | are encountered in the object file. */ | |
749 | struct nextfnfield | |
750 | { | |
751 | struct nextfnfield *next; | |
752 | struct fn_field fnfield; | |
753 | } | |
754 | *fnfields; | |
c906108c | 755 | |
c5aa993b JM |
756 | /* Member function fieldlist array, contains name of possibly overloaded |
757 | member function, number of overloaded member functions and a pointer | |
758 | to the head of the member function field chain. */ | |
759 | struct fnfieldlist | |
760 | { | |
761 | char *name; | |
762 | int length; | |
763 | struct nextfnfield *head; | |
764 | } | |
765 | *fnfieldlists; | |
c906108c | 766 | |
c5aa993b JM |
767 | /* Number of entries in the fnfieldlists array. */ |
768 | int nfnfields; | |
98751a41 JK |
769 | |
770 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of | |
771 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ | |
772 | struct typedef_field_list | |
773 | { | |
774 | struct typedef_field field; | |
775 | struct typedef_field_list *next; | |
776 | } | |
777 | *typedef_field_list; | |
778 | unsigned typedef_field_list_count; | |
c5aa993b | 779 | }; |
c906108c | 780 | |
10b3939b DJ |
781 | /* One item on the queue of compilation units to read in full symbols |
782 | for. */ | |
783 | struct dwarf2_queue_item | |
784 | { | |
785 | struct dwarf2_per_cu_data *per_cu; | |
786 | struct dwarf2_queue_item *next; | |
787 | }; | |
788 | ||
789 | /* The current queue. */ | |
790 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
791 | ||
ae038cb0 DJ |
792 | /* Loaded secondary compilation units are kept in memory until they |
793 | have not been referenced for the processing of this many | |
794 | compilation units. Set this to zero to disable caching. Cache | |
795 | sizes of up to at least twenty will improve startup time for | |
796 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
797 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
798 | static void |
799 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
800 | struct cmd_list_element *c, const char *value) | |
801 | { | |
802 | fprintf_filtered (file, _("\ | |
803 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
804 | value); | |
805 | } | |
806 | ||
ae038cb0 | 807 | |
c906108c SS |
808 | /* Various complaints about symbol reading that don't abort the process */ |
809 | ||
4d3c2250 KB |
810 | static void |
811 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 812 | { |
4d3c2250 | 813 | complaint (&symfile_complaints, |
e2e0b3e5 | 814 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
815 | } |
816 | ||
25e43795 DJ |
817 | static void |
818 | dwarf2_debug_line_missing_file_complaint (void) | |
819 | { | |
820 | complaint (&symfile_complaints, | |
821 | _(".debug_line section has line data without a file")); | |
822 | } | |
823 | ||
59205f5a JB |
824 | static void |
825 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
826 | { | |
827 | complaint (&symfile_complaints, | |
828 | _(".debug_line section has line program sequence without an end")); | |
829 | } | |
830 | ||
4d3c2250 KB |
831 | static void |
832 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 833 | { |
e2e0b3e5 | 834 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
835 | } |
836 | ||
4d3c2250 KB |
837 | static void |
838 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
839 | int arg3) | |
2e276125 | 840 | { |
4d3c2250 | 841 | complaint (&symfile_complaints, |
e2e0b3e5 | 842 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
843 | arg2, arg3); |
844 | } | |
845 | ||
846 | static void | |
847 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 848 | { |
4d3c2250 | 849 | complaint (&symfile_complaints, |
e2e0b3e5 | 850 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
851 | } |
852 | ||
853 | static void | |
854 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 855 | { |
4d3c2250 | 856 | complaint (&symfile_complaints, |
e2e0b3e5 | 857 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
858 | arg1); |
859 | } | |
860 | ||
861 | static void | |
862 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 863 | { |
4d3c2250 | 864 | complaint (&symfile_complaints, |
e2e0b3e5 | 865 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 866 | } |
c906108c | 867 | |
c906108c SS |
868 | /* local function prototypes */ |
869 | ||
4efb68b1 | 870 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c | 871 | |
aaa75496 JB |
872 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
873 | struct objfile *); | |
874 | ||
c67a9c90 | 875 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
c906108c | 876 | |
72bf9492 DJ |
877 | static void scan_partial_symbols (struct partial_die_info *, |
878 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 879 | int, struct dwarf2_cu *); |
c906108c | 880 | |
72bf9492 DJ |
881 | static void add_partial_symbol (struct partial_die_info *, |
882 | struct dwarf2_cu *); | |
63d06c5c | 883 | |
72bf9492 DJ |
884 | static void add_partial_namespace (struct partial_die_info *pdi, |
885 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 886 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 887 | |
5d7cb8df JK |
888 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
889 | CORE_ADDR *highpc, int need_pc, | |
890 | struct dwarf2_cu *cu); | |
891 | ||
72bf9492 DJ |
892 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
893 | struct dwarf2_cu *cu); | |
91c24f0a | 894 | |
bc30ff58 JB |
895 | static void add_partial_subprogram (struct partial_die_info *pdi, |
896 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 897 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 898 | |
fe1b8b76 | 899 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
93311388 DE |
900 | gdb_byte *buffer, gdb_byte *info_ptr, |
901 | bfd *abfd, struct dwarf2_cu *cu); | |
91c24f0a | 902 | |
a14ed312 | 903 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 904 | |
a14ed312 | 905 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 906 | |
e7c27a73 | 907 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 908 | |
f3dd6933 | 909 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 910 | |
fe1b8b76 | 911 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 912 | struct dwarf2_cu *); |
72bf9492 | 913 | |
57349743 | 914 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 915 | struct dwarf2_cu *); |
c906108c | 916 | |
93311388 DE |
917 | static struct partial_die_info *load_partial_dies (bfd *, |
918 | gdb_byte *, gdb_byte *, | |
919 | int, struct dwarf2_cu *); | |
72bf9492 | 920 | |
fe1b8b76 | 921 | static gdb_byte *read_partial_die (struct partial_die_info *, |
93311388 DE |
922 | struct abbrev_info *abbrev, |
923 | unsigned int, bfd *, | |
924 | gdb_byte *, gdb_byte *, | |
925 | struct dwarf2_cu *); | |
c906108c | 926 | |
c764a876 | 927 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 928 | struct dwarf2_cu *); |
72bf9492 DJ |
929 | |
930 | static void fixup_partial_die (struct partial_die_info *, | |
931 | struct dwarf2_cu *); | |
932 | ||
fe1b8b76 JB |
933 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
934 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 935 | |
fe1b8b76 JB |
936 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
937 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 938 | |
fe1b8b76 | 939 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 940 | |
fe1b8b76 | 941 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 942 | |
fe1b8b76 | 943 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 944 | |
fe1b8b76 | 945 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 946 | |
93311388 | 947 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
c906108c | 948 | |
fe1b8b76 | 949 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 950 | unsigned int *); |
c906108c | 951 | |
c764a876 DE |
952 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
953 | ||
954 | static LONGEST read_checked_initial_length_and_offset | |
955 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
956 | unsigned int *, unsigned int *); | |
613e1657 | 957 | |
fe1b8b76 | 958 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
959 | unsigned int *); |
960 | ||
961 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 962 | |
fe1b8b76 | 963 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 964 | |
9b1c24c8 | 965 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 966 | |
fe1b8b76 JB |
967 | static char *read_indirect_string (bfd *, gdb_byte *, |
968 | const struct comp_unit_head *, | |
969 | unsigned int *); | |
4bdf3d34 | 970 | |
fe1b8b76 | 971 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 972 | |
fe1b8b76 | 973 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 974 | |
fe1b8b76 | 975 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 976 | |
e142c38c | 977 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 978 | |
e142c38c DJ |
979 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
980 | struct dwarf2_cu *); | |
c906108c | 981 | |
348e048f DE |
982 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
983 | unsigned int, | |
984 | struct dwarf2_cu *); | |
985 | ||
05cf31d1 JB |
986 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
987 | struct dwarf2_cu *cu); | |
988 | ||
e142c38c | 989 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 990 | |
e142c38c | 991 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 992 | struct dwarf2_cu **); |
63d06c5c | 993 | |
debd256d JB |
994 | static void free_line_header (struct line_header *lh); |
995 | ||
aaa75496 JB |
996 | static void add_file_name (struct line_header *, char *, unsigned int, |
997 | unsigned int, unsigned int); | |
998 | ||
debd256d JB |
999 | static struct line_header *(dwarf_decode_line_header |
1000 | (unsigned int offset, | |
e7c27a73 | 1001 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
1002 | |
1003 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 1004 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 1005 | |
4f1520fb | 1006 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 1007 | |
a14ed312 | 1008 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 1009 | struct dwarf2_cu *); |
c906108c | 1010 | |
34eaf542 TT |
1011 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
1012 | struct dwarf2_cu *, struct symbol *); | |
1013 | ||
a14ed312 | 1014 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 1015 | struct dwarf2_cu *); |
c906108c | 1016 | |
98bfdba5 PA |
1017 | static void dwarf2_const_value_attr (struct attribute *attr, |
1018 | struct type *type, | |
1019 | const char *name, | |
1020 | struct obstack *obstack, | |
1021 | struct dwarf2_cu *cu, long *value, | |
1022 | gdb_byte **bytes, | |
1023 | struct dwarf2_locexpr_baton **baton); | |
2df3850c | 1024 | |
e7c27a73 | 1025 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 1026 | |
b4ba55a1 JB |
1027 | static int need_gnat_info (struct dwarf2_cu *); |
1028 | ||
1029 | static struct type *die_descriptive_type (struct die_info *, struct dwarf2_cu *); | |
1030 | ||
1031 | static void set_descriptive_type (struct type *, struct die_info *, | |
1032 | struct dwarf2_cu *); | |
1033 | ||
e7c27a73 DJ |
1034 | static struct type *die_containing_type (struct die_info *, |
1035 | struct dwarf2_cu *); | |
c906108c | 1036 | |
673bfd45 DE |
1037 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
1038 | struct dwarf2_cu *); | |
c906108c | 1039 | |
f792889a | 1040 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1041 | |
673bfd45 DE |
1042 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
1043 | ||
086ed43d | 1044 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 1045 | |
6e70227d | 1046 | static char *typename_concat (struct obstack *obs, const char *prefix, |
f55ee35c JK |
1047 | const char *suffix, int physname, |
1048 | struct dwarf2_cu *cu); | |
63d06c5c | 1049 | |
e7c27a73 | 1050 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1051 | |
348e048f DE |
1052 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
1053 | ||
e7c27a73 | 1054 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1055 | |
e7c27a73 | 1056 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1057 | |
ff013f42 JK |
1058 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
1059 | struct dwarf2_cu *, struct partial_symtab *); | |
1060 | ||
a14ed312 | 1061 | static int dwarf2_get_pc_bounds (struct die_info *, |
d85a05f0 DJ |
1062 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
1063 | struct partial_symtab *); | |
c906108c | 1064 | |
fae299cd DC |
1065 | static void get_scope_pc_bounds (struct die_info *, |
1066 | CORE_ADDR *, CORE_ADDR *, | |
1067 | struct dwarf2_cu *); | |
1068 | ||
801e3a5b JB |
1069 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
1070 | CORE_ADDR, struct dwarf2_cu *); | |
1071 | ||
a14ed312 | 1072 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 1073 | struct dwarf2_cu *); |
c906108c | 1074 | |
a14ed312 | 1075 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 1076 | struct type *, struct dwarf2_cu *); |
c906108c | 1077 | |
a14ed312 | 1078 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 1079 | struct die_info *, struct type *, |
e7c27a73 | 1080 | struct dwarf2_cu *); |
c906108c | 1081 | |
a14ed312 | 1082 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 1083 | struct type *, struct dwarf2_cu *); |
c906108c | 1084 | |
134d01f1 | 1085 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1086 | |
e7c27a73 | 1087 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 1088 | |
e7c27a73 | 1089 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 1090 | |
5d7cb8df JK |
1091 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
1092 | ||
27aa8d6a SW |
1093 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
1094 | ||
f55ee35c JK |
1095 | static struct type *read_module_type (struct die_info *die, |
1096 | struct dwarf2_cu *cu); | |
1097 | ||
38d518c9 | 1098 | static const char *namespace_name (struct die_info *die, |
e142c38c | 1099 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 1100 | |
134d01f1 | 1101 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 1102 | |
e7c27a73 | 1103 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 1104 | |
6e70227d | 1105 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
7ca2d3a3 DL |
1106 | struct dwarf2_cu *); |
1107 | ||
93311388 | 1108 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
c906108c | 1109 | |
93311388 DE |
1110 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
1111 | gdb_byte *info_ptr, | |
d97bc12b DE |
1112 | gdb_byte **new_info_ptr, |
1113 | struct die_info *parent); | |
1114 | ||
93311388 DE |
1115 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
1116 | gdb_byte *info_ptr, | |
fe1b8b76 | 1117 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1118 | struct die_info *parent); |
1119 | ||
93311388 DE |
1120 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
1121 | gdb_byte *info_ptr, | |
fe1b8b76 | 1122 | gdb_byte **new_info_ptr, |
639d11d3 DC |
1123 | struct die_info *parent); |
1124 | ||
93311388 DE |
1125 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
1126 | struct die_info **, gdb_byte *, | |
1127 | int *); | |
1128 | ||
e7c27a73 | 1129 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 1130 | |
71c25dea TT |
1131 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
1132 | struct obstack *); | |
1133 | ||
e142c38c | 1134 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 1135 | |
98bfdba5 PA |
1136 | static const char *dwarf2_full_name (char *name, |
1137 | struct die_info *die, | |
1138 | struct dwarf2_cu *cu); | |
1139 | ||
e142c38c | 1140 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 1141 | struct dwarf2_cu **); |
9219021c | 1142 | |
a14ed312 | 1143 | static char *dwarf_tag_name (unsigned int); |
c906108c | 1144 | |
a14ed312 | 1145 | static char *dwarf_attr_name (unsigned int); |
c906108c | 1146 | |
a14ed312 | 1147 | static char *dwarf_form_name (unsigned int); |
c906108c | 1148 | |
a14ed312 | 1149 | static char *dwarf_bool_name (unsigned int); |
c906108c | 1150 | |
a14ed312 | 1151 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
1152 | |
1153 | #if 0 | |
a14ed312 | 1154 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1155 | #endif |
1156 | ||
f9aca02d | 1157 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1158 | |
d97bc12b DE |
1159 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1160 | ||
1161 | static void dump_die_for_error (struct die_info *); | |
1162 | ||
1163 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1164 | struct die_info *); | |
c906108c | 1165 | |
d97bc12b | 1166 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1167 | |
51545339 | 1168 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1169 | struct dwarf2_cu *); |
c906108c | 1170 | |
93311388 DE |
1171 | static int is_ref_attr (struct attribute *); |
1172 | ||
c764a876 | 1173 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1174 | |
43bbcdc2 | 1175 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
a02abb62 | 1176 | |
348e048f DE |
1177 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
1178 | struct attribute *, | |
1179 | struct dwarf2_cu **); | |
1180 | ||
10b3939b DJ |
1181 | static struct die_info *follow_die_ref (struct die_info *, |
1182 | struct attribute *, | |
f2f0e013 | 1183 | struct dwarf2_cu **); |
c906108c | 1184 | |
348e048f DE |
1185 | static struct die_info *follow_die_sig (struct die_info *, |
1186 | struct attribute *, | |
1187 | struct dwarf2_cu **); | |
1188 | ||
1189 | static void read_signatured_type_at_offset (struct objfile *objfile, | |
1190 | unsigned int offset); | |
1191 | ||
1192 | static void read_signatured_type (struct objfile *, | |
1193 | struct signatured_type *type_sig); | |
1194 | ||
c906108c SS |
1195 | /* memory allocation interface */ |
1196 | ||
7b5a2f43 | 1197 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1198 | |
f3dd6933 | 1199 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1200 | |
b60c80d6 | 1201 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1202 | |
e142c38c | 1203 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1204 | |
e142c38c DJ |
1205 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1206 | struct dwarf2_cu *); | |
5fb290d7 | 1207 | |
2e276125 | 1208 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1209 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1210 | |
8e19ed76 PS |
1211 | static int attr_form_is_block (struct attribute *); |
1212 | ||
3690dd37 JB |
1213 | static int attr_form_is_section_offset (struct attribute *); |
1214 | ||
1215 | static int attr_form_is_constant (struct attribute *); | |
1216 | ||
93e7bd98 DJ |
1217 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1218 | struct symbol *sym, | |
1219 | struct dwarf2_cu *cu); | |
4c2df51b | 1220 | |
93311388 DE |
1221 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
1222 | struct abbrev_info *abbrev, | |
1223 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1224 | |
72bf9492 DJ |
1225 | static void free_stack_comp_unit (void *); |
1226 | ||
72bf9492 DJ |
1227 | static hashval_t partial_die_hash (const void *item); |
1228 | ||
1229 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1230 | ||
ae038cb0 | 1231 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1232 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1233 | |
1234 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1235 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 | 1236 | |
93311388 DE |
1237 | static struct dwarf2_cu *alloc_one_comp_unit (struct objfile *objfile); |
1238 | ||
ae038cb0 DJ |
1239 | static void free_one_comp_unit (void *); |
1240 | ||
1241 | static void free_cached_comp_units (void *); | |
1242 | ||
1243 | static void age_cached_comp_units (void); | |
1244 | ||
1245 | static void free_one_cached_comp_unit (void *); | |
1246 | ||
f792889a DJ |
1247 | static struct type *set_die_type (struct die_info *, struct type *, |
1248 | struct dwarf2_cu *); | |
1c379e20 | 1249 | |
ae038cb0 DJ |
1250 | static void create_all_comp_units (struct objfile *); |
1251 | ||
1fd400ff TT |
1252 | static int create_debug_types_hash_table (struct objfile *objfile); |
1253 | ||
93311388 DE |
1254 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
1255 | struct objfile *); | |
10b3939b DJ |
1256 | |
1257 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1258 | ||
1259 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1260 | struct dwarf2_per_cu_data *); | |
1261 | ||
ae038cb0 DJ |
1262 | static void dwarf2_mark (struct dwarf2_cu *); |
1263 | ||
1264 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1265 | ||
673bfd45 DE |
1266 | static struct type *get_die_type_at_offset (unsigned int, |
1267 | struct dwarf2_per_cu_data *per_cu); | |
1268 | ||
f792889a | 1269 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1270 | |
9291a0cd TT |
1271 | static void dwarf2_release_queue (void *dummy); |
1272 | ||
1273 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, | |
1274 | struct objfile *objfile); | |
1275 | ||
1276 | static void process_queue (struct objfile *objfile); | |
1277 | ||
1278 | static void find_file_and_directory (struct die_info *die, | |
1279 | struct dwarf2_cu *cu, | |
1280 | char **name, char **comp_dir); | |
1281 | ||
1282 | static char *file_full_name (int file, struct line_header *lh, | |
1283 | const char *comp_dir); | |
1284 | ||
1285 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, | |
1286 | gdb_byte *info_ptr, | |
1287 | gdb_byte *buffer, | |
1288 | unsigned int buffer_size, | |
1289 | bfd *abfd); | |
1290 | ||
1291 | static void init_cu_die_reader (struct die_reader_specs *reader, | |
1292 | struct dwarf2_cu *cu); | |
1293 | ||
673bfd45 | 1294 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
1fd400ff | 1295 | |
9291a0cd TT |
1296 | #if WORDS_BIGENDIAN |
1297 | ||
1298 | /* Convert VALUE between big- and little-endian. */ | |
1299 | static offset_type | |
1300 | byte_swap (offset_type value) | |
1301 | { | |
1302 | offset_type result; | |
1303 | ||
1304 | result = (value & 0xff) << 24; | |
1305 | result |= (value & 0xff00) << 8; | |
1306 | result |= (value & 0xff0000) >> 8; | |
1307 | result |= (value & 0xff000000) >> 24; | |
1308 | return result; | |
1309 | } | |
1310 | ||
1311 | #define MAYBE_SWAP(V) byte_swap (V) | |
1312 | ||
1313 | #else | |
1314 | #define MAYBE_SWAP(V) (V) | |
1315 | #endif /* WORDS_BIGENDIAN */ | |
1316 | ||
1317 | /* The suffix for an index file. */ | |
1318 | #define INDEX_SUFFIX ".gdb-index" | |
1319 | ||
3da10d80 KS |
1320 | static const char *dwarf2_physname (char *name, struct die_info *die, |
1321 | struct dwarf2_cu *cu); | |
1322 | ||
c906108c SS |
1323 | /* Try to locate the sections we need for DWARF 2 debugging |
1324 | information and return true if we have enough to do something. */ | |
1325 | ||
1326 | int | |
6502dd73 | 1327 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1328 | { |
be391dca TT |
1329 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
1330 | if (!dwarf2_per_objfile) | |
1331 | { | |
1332 | /* Initialize per-objfile state. */ | |
1333 | struct dwarf2_per_objfile *data | |
1334 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
9a619af0 | 1335 | |
be391dca TT |
1336 | memset (data, 0, sizeof (*data)); |
1337 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1338 | dwarf2_per_objfile = data; | |
6502dd73 | 1339 | |
be391dca TT |
1340 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
1341 | dwarf2_per_objfile->objfile = objfile; | |
1342 | } | |
1343 | return (dwarf2_per_objfile->info.asection != NULL | |
1344 | && dwarf2_per_objfile->abbrev.asection != NULL); | |
c906108c SS |
1345 | } |
1346 | ||
233a11ab CS |
1347 | /* When loading sections, we can either look for ".<name>", or for |
1348 | * ".z<name>", which indicates a compressed section. */ | |
1349 | ||
1350 | static int | |
dce234bc | 1351 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1352 | { |
dce234bc PP |
1353 | return (section_name[0] == '.' |
1354 | && (strcmp (section_name + 1, name) == 0 | |
1355 | || (section_name[1] == 'z' | |
1356 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1357 | } |
1358 | ||
c906108c SS |
1359 | /* This function is mapped across the sections and remembers the |
1360 | offset and size of each of the debugging sections we are interested | |
1361 | in. */ | |
1362 | ||
1363 | static void | |
72dca2f5 | 1364 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1365 | { |
dce234bc | 1366 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1367 | { |
dce234bc PP |
1368 | dwarf2_per_objfile->info.asection = sectp; |
1369 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1370 | } |
dce234bc | 1371 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1372 | { |
dce234bc PP |
1373 | dwarf2_per_objfile->abbrev.asection = sectp; |
1374 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1375 | } |
dce234bc | 1376 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1377 | { |
dce234bc PP |
1378 | dwarf2_per_objfile->line.asection = sectp; |
1379 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1380 | } |
dce234bc | 1381 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1382 | { |
dce234bc PP |
1383 | dwarf2_per_objfile->loc.asection = sectp; |
1384 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1385 | } |
dce234bc | 1386 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1387 | { |
dce234bc PP |
1388 | dwarf2_per_objfile->macinfo.asection = sectp; |
1389 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1390 | } |
dce234bc | 1391 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1392 | { |
dce234bc PP |
1393 | dwarf2_per_objfile->str.asection = sectp; |
1394 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1395 | } |
dce234bc | 1396 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1397 | { |
dce234bc PP |
1398 | dwarf2_per_objfile->frame.asection = sectp; |
1399 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1400 | } |
dce234bc | 1401 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1402 | { |
3799ccc6 | 1403 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
9a619af0 | 1404 | |
3799ccc6 EZ |
1405 | if (aflag & SEC_HAS_CONTENTS) |
1406 | { | |
dce234bc PP |
1407 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1408 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1409 | } |
b6af0555 | 1410 | } |
dce234bc | 1411 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1412 | { |
dce234bc PP |
1413 | dwarf2_per_objfile->ranges.asection = sectp; |
1414 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1415 | } |
348e048f DE |
1416 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
1417 | { | |
1418 | dwarf2_per_objfile->types.asection = sectp; | |
1419 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); | |
1420 | } | |
9291a0cd TT |
1421 | else if (section_is_p (sectp->name, GDB_INDEX_SECTION)) |
1422 | { | |
1423 | dwarf2_per_objfile->gdb_index.asection = sectp; | |
1424 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); | |
1425 | } | |
dce234bc | 1426 | |
72dca2f5 FR |
1427 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1428 | && bfd_section_vma (abfd, sectp) == 0) | |
1429 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1430 | } |
1431 | ||
dce234bc PP |
1432 | /* Decompress a section that was compressed using zlib. Store the |
1433 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1434 | |
1435 | static void | |
dce234bc PP |
1436 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1437 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1438 | { | |
1439 | bfd *abfd = objfile->obfd; | |
1440 | #ifndef HAVE_ZLIB_H | |
1441 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1442 | "is disabled in this copy of GDB"), | |
1443 | bfd_get_filename (abfd)); | |
1444 | #else | |
1445 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1446 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
affddf13 | 1447 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
dce234bc PP |
1448 | bfd_size_type uncompressed_size; |
1449 | gdb_byte *uncompressed_buffer; | |
1450 | z_stream strm; | |
1451 | int rc; | |
1452 | int header_size = 12; | |
1453 | ||
1454 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1455 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1456 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1457 | bfd_get_filename (abfd)); | |
1458 | ||
1459 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1460 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1461 | if (compressed_size < header_size | |
1462 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1463 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1464 | bfd_get_filename (abfd)); | |
1465 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1466 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1467 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1468 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1469 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1470 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1471 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1472 | uncompressed_size += compressed_buffer[11]; | |
1473 | ||
1474 | /* It is possible the section consists of several compressed | |
1475 | buffers concatenated together, so we uncompress in a loop. */ | |
1476 | strm.zalloc = NULL; | |
1477 | strm.zfree = NULL; | |
1478 | strm.opaque = NULL; | |
1479 | strm.avail_in = compressed_size - header_size; | |
1480 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1481 | strm.avail_out = uncompressed_size; | |
1482 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1483 | uncompressed_size); | |
1484 | rc = inflateInit (&strm); | |
1485 | while (strm.avail_in > 0) | |
1486 | { | |
1487 | if (rc != Z_OK) | |
1488 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1489 | bfd_get_filename (abfd), rc); | |
1490 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1491 | + (uncompressed_size - strm.avail_out)); | |
1492 | rc = inflate (&strm, Z_FINISH); | |
1493 | if (rc != Z_STREAM_END) | |
1494 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1495 | bfd_get_filename (abfd), rc); | |
1496 | rc = inflateReset (&strm); | |
1497 | } | |
1498 | rc = inflateEnd (&strm); | |
1499 | if (rc != Z_OK | |
1500 | || strm.avail_out != 0) | |
1501 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1502 | bfd_get_filename (abfd), rc); | |
1503 | ||
affddf13 | 1504 | do_cleanups (cleanup); |
dce234bc PP |
1505 | *outbuf = uncompressed_buffer; |
1506 | *outsize = uncompressed_size; | |
1507 | #endif | |
233a11ab CS |
1508 | } |
1509 | ||
dce234bc PP |
1510 | /* Read the contents of the section SECTP from object file specified by |
1511 | OBJFILE, store info about the section into INFO. | |
1512 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1513 | |
dce234bc PP |
1514 | static void |
1515 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1516 | { |
dce234bc PP |
1517 | bfd *abfd = objfile->obfd; |
1518 | asection *sectp = info->asection; | |
1519 | gdb_byte *buf, *retbuf; | |
1520 | unsigned char header[4]; | |
c906108c | 1521 | |
be391dca TT |
1522 | if (info->readin) |
1523 | return; | |
dce234bc PP |
1524 | info->buffer = NULL; |
1525 | info->was_mmapped = 0; | |
be391dca | 1526 | info->readin = 1; |
188dd5d6 | 1527 | |
dce234bc PP |
1528 | if (info->asection == NULL || info->size == 0) |
1529 | return; | |
c906108c | 1530 | |
dce234bc PP |
1531 | /* Check if the file has a 4-byte header indicating compression. */ |
1532 | if (info->size > sizeof (header) | |
1533 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1534 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1535 | { | |
1536 | /* Upon decompression, update the buffer and its size. */ | |
1537 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1538 | { | |
1539 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1540 | &info->size); | |
1541 | return; | |
1542 | } | |
1543 | } | |
4bdf3d34 | 1544 | |
dce234bc PP |
1545 | #ifdef HAVE_MMAP |
1546 | if (pagesize == 0) | |
1547 | pagesize = getpagesize (); | |
2e276125 | 1548 | |
dce234bc PP |
1549 | /* Only try to mmap sections which are large enough: we don't want to |
1550 | waste space due to fragmentation. Also, only try mmap for sections | |
1551 | without relocations. */ | |
1552 | ||
1553 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1554 | { | |
1555 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1556 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1557 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1558 | MAP_PRIVATE, pg_offset); | |
1559 | ||
1560 | if (retbuf != MAP_FAILED) | |
1561 | { | |
1562 | info->was_mmapped = 1; | |
1563 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
be391dca TT |
1564 | #if HAVE_POSIX_MADVISE |
1565 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); | |
1566 | #endif | |
dce234bc PP |
1567 | return; |
1568 | } | |
1569 | } | |
1570 | #endif | |
1571 | ||
1572 | /* If we get here, we are a normal, not-compressed section. */ | |
1573 | info->buffer = buf | |
1574 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1575 | ||
1576 | /* When debugging .o files, we may need to apply relocations; see | |
1577 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1578 | We never compress sections in .o files, so we only need to | |
1579 | try this when the section is not compressed. */ | |
ac8035ab | 1580 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
dce234bc PP |
1581 | if (retbuf != NULL) |
1582 | { | |
1583 | info->buffer = retbuf; | |
1584 | return; | |
1585 | } | |
1586 | ||
1587 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1588 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1589 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1590 | bfd_get_filename (abfd)); | |
1591 | } | |
1592 | ||
1593 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1594 | SECTION_NAME. */ | |
af34e669 | 1595 | |
dce234bc PP |
1596 | void |
1597 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1598 | asection **sectp, gdb_byte **bufp, | |
1599 | bfd_size_type *sizep) | |
1600 | { | |
1601 | struct dwarf2_per_objfile *data | |
1602 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1603 | struct dwarf2_section_info *info; | |
a3b2a86b TT |
1604 | |
1605 | /* We may see an objfile without any DWARF, in which case we just | |
1606 | return nothing. */ | |
1607 | if (data == NULL) | |
1608 | { | |
1609 | *sectp = NULL; | |
1610 | *bufp = NULL; | |
1611 | *sizep = 0; | |
1612 | return; | |
1613 | } | |
dce234bc PP |
1614 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
1615 | info = &data->eh_frame; | |
1616 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1617 | info = &data->frame; | |
0d53c4c4 | 1618 | else |
f3574227 | 1619 | gdb_assert_not_reached ("unexpected section"); |
dce234bc PP |
1620 | |
1621 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1622 | /* We haven't read this section in yet. Do it now. */ | |
1623 | dwarf2_read_section (objfile, info); | |
1624 | ||
1625 | *sectp = info->asection; | |
1626 | *bufp = info->buffer; | |
1627 | *sizep = info->size; | |
1628 | } | |
1629 | ||
9291a0cd TT |
1630 | \f |
1631 | ||
1632 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which | |
1633 | this CU came. */ | |
1634 | static void | |
1635 | dw2_do_instantiate_symtab (struct objfile *objfile, | |
1636 | struct dwarf2_per_cu_data *per_cu) | |
1637 | { | |
1638 | struct cleanup *back_to; | |
1639 | ||
1640 | back_to = make_cleanup (dwarf2_release_queue, NULL); | |
1641 | ||
1642 | queue_comp_unit (per_cu, objfile); | |
1643 | ||
1644 | if (per_cu->from_debug_types) | |
1645 | read_signatured_type_at_offset (objfile, per_cu->offset); | |
1646 | else | |
1647 | load_full_comp_unit (per_cu, objfile); | |
1648 | ||
1649 | process_queue (objfile); | |
1650 | ||
1651 | /* Age the cache, releasing compilation units that have not | |
1652 | been used recently. */ | |
1653 | age_cached_comp_units (); | |
1654 | ||
1655 | do_cleanups (back_to); | |
1656 | } | |
1657 | ||
1658 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is | |
1659 | the objfile from which this CU came. Returns the resulting symbol | |
1660 | table. */ | |
1661 | static struct symtab * | |
1662 | dw2_instantiate_symtab (struct objfile *objfile, | |
1663 | struct dwarf2_per_cu_data *per_cu) | |
1664 | { | |
1665 | if (!per_cu->v.quick->symtab) | |
1666 | { | |
1667 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); | |
1668 | increment_reading_symtab (); | |
1669 | dw2_do_instantiate_symtab (objfile, per_cu); | |
1670 | do_cleanups (back_to); | |
1671 | } | |
1672 | return per_cu->v.quick->symtab; | |
1673 | } | |
1674 | ||
1fd400ff TT |
1675 | /* Return the CU given its index. */ |
1676 | static struct dwarf2_per_cu_data * | |
1677 | dw2_get_cu (int index) | |
1678 | { | |
1679 | if (index >= dwarf2_per_objfile->n_comp_units) | |
1680 | { | |
1681 | index -= dwarf2_per_objfile->n_comp_units; | |
1682 | return dwarf2_per_objfile->type_comp_units[index]; | |
1683 | } | |
1684 | return dwarf2_per_objfile->all_comp_units[index]; | |
1685 | } | |
1686 | ||
9291a0cd TT |
1687 | /* A helper function that knows how to read a 64-bit value in a way |
1688 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 | |
1689 | otherwise. */ | |
1690 | static int | |
1691 | extract_cu_value (const char *bytes, ULONGEST *result) | |
1692 | { | |
1693 | if (sizeof (ULONGEST) < 8) | |
1694 | { | |
1695 | int i; | |
1696 | ||
1697 | /* Ignore the upper 4 bytes if they are all zero. */ | |
1698 | for (i = 0; i < 4; ++i) | |
1699 | if (bytes[i + 4] != 0) | |
1700 | return 0; | |
1701 | ||
1702 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); | |
1703 | } | |
1704 | else | |
1705 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); | |
1706 | return 1; | |
1707 | } | |
1708 | ||
1709 | /* Read the CU list from the mapped index, and use it to create all | |
1710 | the CU objects for this objfile. Return 0 if something went wrong, | |
1711 | 1 if everything went ok. */ | |
1712 | static int | |
1fd400ff TT |
1713 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
1714 | offset_type cu_list_elements) | |
9291a0cd TT |
1715 | { |
1716 | offset_type i; | |
9291a0cd TT |
1717 | |
1718 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; | |
1719 | dwarf2_per_objfile->all_comp_units | |
1720 | = obstack_alloc (&objfile->objfile_obstack, | |
1721 | dwarf2_per_objfile->n_comp_units | |
1722 | * sizeof (struct dwarf2_per_cu_data *)); | |
1723 | ||
1724 | for (i = 0; i < cu_list_elements; i += 2) | |
1725 | { | |
1726 | struct dwarf2_per_cu_data *the_cu; | |
1727 | ULONGEST offset, length; | |
1728 | ||
1729 | if (!extract_cu_value (cu_list, &offset) | |
1730 | || !extract_cu_value (cu_list + 8, &length)) | |
1731 | return 0; | |
1732 | cu_list += 2 * 8; | |
1733 | ||
1734 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1735 | struct dwarf2_per_cu_data); | |
1736 | the_cu->offset = offset; | |
1737 | the_cu->length = length; | |
1738 | the_cu->objfile = objfile; | |
1739 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1740 | struct dwarf2_per_cu_quick_data); | |
1741 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; | |
1742 | } | |
1743 | ||
1744 | return 1; | |
1745 | } | |
1746 | ||
1fd400ff | 1747 | /* Create the signatured type hash table from the index. */ |
673bfd45 | 1748 | |
1fd400ff | 1749 | static int |
673bfd45 DE |
1750 | create_signatured_type_table_from_index (struct objfile *objfile, |
1751 | const gdb_byte *bytes, | |
1752 | offset_type elements) | |
1fd400ff TT |
1753 | { |
1754 | offset_type i; | |
673bfd45 | 1755 | htab_t sig_types_hash; |
1fd400ff TT |
1756 | |
1757 | dwarf2_per_objfile->n_type_comp_units = elements / 3; | |
1758 | dwarf2_per_objfile->type_comp_units | |
1759 | = obstack_alloc (&objfile->objfile_obstack, | |
1760 | dwarf2_per_objfile->n_type_comp_units | |
1761 | * sizeof (struct dwarf2_per_cu_data *)); | |
1762 | ||
673bfd45 | 1763 | sig_types_hash = allocate_signatured_type_table (objfile); |
1fd400ff TT |
1764 | |
1765 | for (i = 0; i < elements; i += 3) | |
1766 | { | |
1767 | struct signatured_type *type_sig; | |
1768 | ULONGEST offset, type_offset, signature; | |
1769 | void **slot; | |
1770 | ||
1771 | if (!extract_cu_value (bytes, &offset) | |
1772 | || !extract_cu_value (bytes + 8, &type_offset)) | |
1773 | return 0; | |
1774 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); | |
1775 | bytes += 3 * 8; | |
1776 | ||
1777 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1778 | struct signatured_type); | |
1779 | type_sig->signature = signature; | |
1780 | type_sig->offset = offset; | |
1781 | type_sig->type_offset = type_offset; | |
1782 | type_sig->per_cu.from_debug_types = 1; | |
1783 | type_sig->per_cu.offset = offset; | |
1784 | type_sig->per_cu.objfile = objfile; | |
1785 | type_sig->per_cu.v.quick | |
1786 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
1787 | struct dwarf2_per_cu_quick_data); | |
1788 | ||
673bfd45 | 1789 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
1fd400ff TT |
1790 | *slot = type_sig; |
1791 | ||
1792 | dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu; | |
1793 | } | |
1794 | ||
673bfd45 | 1795 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
1fd400ff TT |
1796 | |
1797 | return 1; | |
1798 | } | |
1799 | ||
9291a0cd TT |
1800 | /* Read the address map data from the mapped index, and use it to |
1801 | populate the objfile's psymtabs_addrmap. */ | |
1802 | static void | |
1803 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) | |
1804 | { | |
1805 | const gdb_byte *iter, *end; | |
1806 | struct obstack temp_obstack; | |
1807 | struct addrmap *mutable_map; | |
1808 | struct cleanup *cleanup; | |
1809 | CORE_ADDR baseaddr; | |
1810 | ||
1811 | obstack_init (&temp_obstack); | |
1812 | cleanup = make_cleanup_obstack_free (&temp_obstack); | |
1813 | mutable_map = addrmap_create_mutable (&temp_obstack); | |
1814 | ||
1815 | iter = index->address_table; | |
1816 | end = iter + index->address_table_size; | |
1817 | ||
1818 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
1819 | ||
1820 | while (iter < end) | |
1821 | { | |
1822 | ULONGEST hi, lo, cu_index; | |
1823 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1824 | iter += 8; | |
1825 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); | |
1826 | iter += 8; | |
1827 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); | |
1828 | iter += 4; | |
1829 | ||
1830 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, | |
1fd400ff | 1831 | dw2_get_cu (cu_index)); |
9291a0cd TT |
1832 | } |
1833 | ||
1834 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, | |
1835 | &objfile->objfile_obstack); | |
1836 | do_cleanups (cleanup); | |
1837 | } | |
1838 | ||
1839 | /* The hash function for strings in the mapped index. This is the | |
1840 | same as the hashtab.c hash function, but we keep a separate copy to | |
1841 | maintain control over the implementation. This is necessary | |
1842 | because the hash function is tied to the format of the mapped index | |
1843 | file. */ | |
1844 | static hashval_t | |
1845 | mapped_index_string_hash (const void *p) | |
1846 | { | |
1847 | const unsigned char *str = (const unsigned char *) p; | |
1848 | hashval_t r = 0; | |
1849 | unsigned char c; | |
1850 | ||
1851 | while ((c = *str++) != 0) | |
1852 | r = r * 67 + c - 113; | |
1853 | ||
1854 | return r; | |
1855 | } | |
1856 | ||
1857 | /* Find a slot in the mapped index INDEX for the object named NAME. | |
1858 | If NAME is found, set *VEC_OUT to point to the CU vector in the | |
1859 | constant pool and return 1. If NAME cannot be found, return 0. */ | |
1860 | static int | |
1861 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, | |
1862 | offset_type **vec_out) | |
1863 | { | |
1864 | offset_type hash = mapped_index_string_hash (name); | |
1865 | offset_type slot, step; | |
1866 | ||
1867 | slot = hash & (index->index_table_slots - 1); | |
1868 | step = ((hash * 17) & (index->index_table_slots - 1)) | 1; | |
1869 | ||
1870 | for (;;) | |
1871 | { | |
1872 | /* Convert a slot number to an offset into the table. */ | |
1873 | offset_type i = 2 * slot; | |
1874 | const char *str; | |
1875 | if (index->index_table[i] == 0 && index->index_table[i + 1] == 0) | |
1876 | return 0; | |
1877 | ||
1878 | str = index->constant_pool + MAYBE_SWAP (index->index_table[i]); | |
1879 | if (!strcmp (name, str)) | |
1880 | { | |
1881 | *vec_out = (offset_type *) (index->constant_pool | |
1882 | + MAYBE_SWAP (index->index_table[i + 1])); | |
1883 | return 1; | |
1884 | } | |
1885 | ||
1886 | slot = (slot + step) & (index->index_table_slots - 1); | |
1887 | } | |
1888 | } | |
1889 | ||
1890 | /* Read the index file. If everything went ok, initialize the "quick" | |
1891 | elements of all the CUs and return 1. Otherwise, return 0. */ | |
1892 | static int | |
1893 | dwarf2_read_index (struct objfile *objfile) | |
1894 | { | |
9291a0cd TT |
1895 | char *addr; |
1896 | struct mapped_index *map; | |
b3b272e1 | 1897 | offset_type *metadata; |
ac0b195c KW |
1898 | const gdb_byte *cu_list; |
1899 | const gdb_byte *types_list = NULL; | |
1900 | offset_type version, cu_list_elements; | |
1901 | offset_type types_list_elements = 0; | |
1fd400ff | 1902 | int i; |
9291a0cd TT |
1903 | |
1904 | if (dwarf2_per_objfile->gdb_index.asection == NULL | |
1905 | || dwarf2_per_objfile->gdb_index.size == 0) | |
1906 | return 0; | |
82430852 JK |
1907 | |
1908 | /* Older elfutils strip versions could keep the section in the main | |
1909 | executable while splitting it for the separate debug info file. */ | |
1910 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) | |
1911 | & SEC_HAS_CONTENTS) == 0) | |
1912 | return 0; | |
1913 | ||
9291a0cd TT |
1914 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
1915 | ||
1916 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
1917 | /* Version check. */ | |
1fd400ff TT |
1918 | version = MAYBE_SWAP (*(offset_type *) addr); |
1919 | if (version == 1) | |
1920 | { | |
1921 | /* Index version 1 neglected to account for .debug_types. So, | |
1922 | if we see .debug_types, we cannot use this index. */ | |
1923 | if (dwarf2_per_objfile->types.asection != NULL | |
1924 | && dwarf2_per_objfile->types.size != 0) | |
1925 | return 0; | |
1926 | } | |
1927 | else if (version != 2) | |
9291a0cd TT |
1928 | return 0; |
1929 | ||
1930 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
b3b272e1 | 1931 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
1932 | |
1933 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
1934 | |
1935 | i = 0; | |
1936 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
1937 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 1938 | / 8); |
1fd400ff TT |
1939 | ++i; |
1940 | ||
1941 | if (version == 2) | |
1942 | { | |
1943 | types_list = addr + MAYBE_SWAP (metadata[i]); | |
1944 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
1945 | - MAYBE_SWAP (metadata[i])) | |
1946 | / 8); | |
1947 | ++i; | |
1948 | } | |
1949 | ||
1950 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
1951 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
1952 | - MAYBE_SWAP (metadata[i])); | |
1953 | ++i; | |
1954 | ||
1955 | map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); | |
1956 | map->index_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
1957 | - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 1958 | / (2 * sizeof (offset_type))); |
1fd400ff | 1959 | ++i; |
9291a0cd | 1960 | |
1fd400ff TT |
1961 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
1962 | ||
1963 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
1964 | return 0; | |
1965 | ||
1966 | if (version == 2 | |
1967 | && types_list_elements | |
673bfd45 DE |
1968 | && !create_signatured_type_table_from_index (objfile, types_list, |
1969 | types_list_elements)) | |
9291a0cd TT |
1970 | return 0; |
1971 | ||
1972 | create_addrmap_from_index (objfile, map); | |
1973 | ||
1974 | dwarf2_per_objfile->index_table = map; | |
1975 | dwarf2_per_objfile->using_index = 1; | |
1976 | ||
1977 | return 1; | |
1978 | } | |
1979 | ||
1980 | /* A helper for the "quick" functions which sets the global | |
1981 | dwarf2_per_objfile according to OBJFILE. */ | |
1982 | static void | |
1983 | dw2_setup (struct objfile *objfile) | |
1984 | { | |
1985 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
1986 | gdb_assert (dwarf2_per_objfile); | |
1987 | } | |
1988 | ||
1989 | /* A helper for the "quick" functions which attempts to read the line | |
1990 | table for THIS_CU. */ | |
1991 | static void | |
1992 | dw2_require_line_header (struct objfile *objfile, | |
1993 | struct dwarf2_per_cu_data *this_cu) | |
1994 | { | |
1995 | bfd *abfd = objfile->obfd; | |
1996 | struct line_header *lh = NULL; | |
1997 | struct attribute *attr; | |
1998 | struct cleanup *cleanups; | |
1999 | struct die_info *comp_unit_die; | |
36374493 | 2000 | struct dwarf2_section_info* sec; |
9291a0cd TT |
2001 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; |
2002 | int has_children, i; | |
2003 | struct dwarf2_cu cu; | |
2004 | unsigned int bytes_read, buffer_size; | |
2005 | struct die_reader_specs reader_specs; | |
2006 | char *name, *comp_dir; | |
2007 | ||
2008 | if (this_cu->v.quick->read_lines) | |
2009 | return; | |
2010 | this_cu->v.quick->read_lines = 1; | |
2011 | ||
2012 | memset (&cu, 0, sizeof (cu)); | |
2013 | cu.objfile = objfile; | |
2014 | obstack_init (&cu.comp_unit_obstack); | |
2015 | ||
2016 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
2017 | ||
36374493 DE |
2018 | if (this_cu->from_debug_types) |
2019 | sec = &dwarf2_per_objfile->types; | |
2020 | else | |
2021 | sec = &dwarf2_per_objfile->info; | |
2022 | dwarf2_read_section (objfile, sec); | |
2023 | buffer_size = sec->size; | |
2024 | buffer = sec->buffer; | |
9291a0cd TT |
2025 | info_ptr = buffer + this_cu->offset; |
2026 | beg_of_comp_unit = info_ptr; | |
2027 | ||
2028 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
2029 | buffer, buffer_size, | |
2030 | abfd); | |
2031 | ||
2032 | /* Complete the cu_header. */ | |
2033 | cu.header.offset = beg_of_comp_unit - buffer; | |
2034 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
2035 | ||
2036 | this_cu->cu = &cu; | |
2037 | cu.per_cu = this_cu; | |
2038 | ||
2039 | dwarf2_read_abbrevs (abfd, &cu); | |
2040 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
2041 | ||
2042 | if (this_cu->from_debug_types) | |
2043 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
2044 | init_cu_die_reader (&reader_specs, &cu); | |
2045 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2046 | &has_children); | |
2047 | ||
2048 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); | |
2049 | if (attr) | |
2050 | { | |
2051 | unsigned int line_offset = DW_UNSND (attr); | |
2052 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); | |
2053 | } | |
2054 | if (lh == NULL) | |
2055 | { | |
2056 | do_cleanups (cleanups); | |
2057 | return; | |
2058 | } | |
2059 | ||
2060 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); | |
2061 | ||
2062 | this_cu->v.quick->lines = lh; | |
2063 | ||
2064 | this_cu->v.quick->file_names | |
2065 | = obstack_alloc (&objfile->objfile_obstack, | |
2066 | lh->num_file_names * sizeof (char *)); | |
2067 | for (i = 0; i < lh->num_file_names; ++i) | |
2068 | this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir); | |
2069 | ||
2070 | do_cleanups (cleanups); | |
2071 | } | |
2072 | ||
2073 | /* A helper for the "quick" functions which computes and caches the | |
2074 | real path for a given file name from the line table. | |
2075 | dw2_require_line_header must have been called before this is | |
2076 | invoked. */ | |
2077 | static const char * | |
2078 | dw2_require_full_path (struct objfile *objfile, | |
e254ef6a | 2079 | struct dwarf2_per_cu_data *per_cu, |
9291a0cd TT |
2080 | int index) |
2081 | { | |
e254ef6a DE |
2082 | if (!per_cu->v.quick->full_names) |
2083 | per_cu->v.quick->full_names | |
9291a0cd | 2084 | = OBSTACK_CALLOC (&objfile->objfile_obstack, |
e254ef6a | 2085 | per_cu->v.quick->lines->num_file_names, |
9291a0cd TT |
2086 | sizeof (char *)); |
2087 | ||
e254ef6a DE |
2088 | if (!per_cu->v.quick->full_names[index]) |
2089 | per_cu->v.quick->full_names[index] | |
2090 | = gdb_realpath (per_cu->v.quick->file_names[index]); | |
9291a0cd | 2091 | |
e254ef6a | 2092 | return per_cu->v.quick->full_names[index]; |
9291a0cd TT |
2093 | } |
2094 | ||
2095 | static struct symtab * | |
2096 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2097 | { | |
2098 | int index; | |
2099 | dw2_setup (objfile); | |
2100 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1fd400ff | 2101 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
9291a0cd TT |
2102 | } |
2103 | ||
2104 | static void | |
2105 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2106 | { | |
2107 | int i; | |
2108 | ||
2109 | dw2_setup (objfile); | |
1fd400ff TT |
2110 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2111 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2112 | { |
e254ef6a | 2113 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2114 | |
e254ef6a | 2115 | if (per_cu->v.quick->full_names) |
9291a0cd TT |
2116 | { |
2117 | int j; | |
2118 | ||
e254ef6a DE |
2119 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
2120 | xfree ((void *) per_cu->v.quick->full_names[j]); | |
9291a0cd TT |
2121 | } |
2122 | } | |
2123 | } | |
2124 | ||
2125 | static int | |
2126 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
2127 | const char *full_path, const char *real_path, | |
2128 | struct symtab **result) | |
2129 | { | |
2130 | int i; | |
2131 | int check_basename = lbasename (name) == name; | |
2132 | struct dwarf2_per_cu_data *base_cu = NULL; | |
2133 | ||
2134 | dw2_setup (objfile); | |
1fd400ff TT |
2135 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2136 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2137 | { |
2138 | int j; | |
e254ef6a | 2139 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2140 | |
e254ef6a | 2141 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2142 | continue; |
2143 | ||
e254ef6a DE |
2144 | dw2_require_line_header (objfile, per_cu); |
2145 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2146 | continue; |
2147 | ||
e254ef6a | 2148 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2149 | { |
e254ef6a | 2150 | const char *this_name = per_cu->v.quick->file_names[j]; |
9291a0cd TT |
2151 | |
2152 | if (FILENAME_CMP (name, this_name) == 0) | |
2153 | { | |
e254ef6a | 2154 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2155 | return 1; |
2156 | } | |
2157 | ||
2158 | if (check_basename && ! base_cu | |
2159 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2160 | base_cu = per_cu; |
9291a0cd TT |
2161 | |
2162 | if (full_path != NULL) | |
2163 | { | |
2164 | const char *this_full_name = dw2_require_full_path (objfile, | |
e254ef6a | 2165 | per_cu, j); |
9291a0cd TT |
2166 | |
2167 | if (this_full_name | |
2168 | && FILENAME_CMP (full_path, this_full_name) == 0) | |
2169 | { | |
e254ef6a | 2170 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2171 | return 1; |
2172 | } | |
2173 | } | |
2174 | ||
2175 | if (real_path != NULL) | |
2176 | { | |
2177 | const char *this_full_name = dw2_require_full_path (objfile, | |
e254ef6a | 2178 | per_cu, j); |
9291a0cd TT |
2179 | |
2180 | if (this_full_name != NULL) | |
2181 | { | |
2182 | char *rp = gdb_realpath (this_full_name); | |
2183 | if (rp != NULL && FILENAME_CMP (real_path, rp) == 0) | |
2184 | { | |
2185 | xfree (rp); | |
e254ef6a | 2186 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2187 | return 1; |
2188 | } | |
2189 | xfree (rp); | |
2190 | } | |
2191 | } | |
2192 | } | |
2193 | } | |
2194 | ||
2195 | if (base_cu) | |
2196 | { | |
2197 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2198 | return 1; | |
2199 | } | |
2200 | ||
2201 | return 0; | |
2202 | } | |
2203 | ||
2204 | static struct symtab * | |
2205 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2206 | const char *name, domain_enum domain) | |
2207 | { | |
774b6a14 | 2208 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2209 | instead. */ |
2210 | return NULL; | |
2211 | } | |
2212 | ||
2213 | /* A helper function that expands all symtabs that hold an object | |
2214 | named NAME. */ | |
2215 | static void | |
2216 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2217 | { | |
2218 | dw2_setup (objfile); | |
2219 | ||
2220 | if (dwarf2_per_objfile->index_table) | |
2221 | { | |
2222 | offset_type *vec; | |
2223 | ||
2224 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2225 | name, &vec)) | |
2226 | { | |
2227 | offset_type i, len = MAYBE_SWAP (*vec); | |
2228 | for (i = 0; i < len; ++i) | |
2229 | { | |
2230 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2231 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2232 | |
e254ef6a | 2233 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2234 | } |
2235 | } | |
2236 | } | |
2237 | } | |
2238 | ||
774b6a14 TT |
2239 | static void |
2240 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
2241 | int kind, const char *name, | |
2242 | domain_enum domain) | |
9291a0cd | 2243 | { |
774b6a14 | 2244 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2245 | } |
2246 | ||
2247 | static void | |
2248 | dw2_print_stats (struct objfile *objfile) | |
2249 | { | |
2250 | int i, count; | |
2251 | ||
2252 | dw2_setup (objfile); | |
2253 | count = 0; | |
1fd400ff TT |
2254 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2255 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2256 | { |
e254ef6a | 2257 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2258 | |
e254ef6a | 2259 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2260 | ++count; |
2261 | } | |
2262 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2263 | } | |
2264 | ||
2265 | static void | |
2266 | dw2_dump (struct objfile *objfile) | |
2267 | { | |
2268 | /* Nothing worth printing. */ | |
2269 | } | |
2270 | ||
2271 | static void | |
2272 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2273 | struct section_offsets *delta) | |
2274 | { | |
2275 | /* There's nothing to relocate here. */ | |
2276 | } | |
2277 | ||
2278 | static void | |
2279 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2280 | const char *func_name) | |
2281 | { | |
2282 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2283 | } | |
2284 | ||
2285 | static void | |
2286 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2287 | { | |
2288 | int i; | |
2289 | ||
2290 | dw2_setup (objfile); | |
1fd400ff TT |
2291 | |
2292 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2293 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2294 | { |
e254ef6a | 2295 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2296 | |
e254ef6a | 2297 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2298 | } |
2299 | } | |
2300 | ||
2301 | static void | |
2302 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2303 | const char *filename) | |
2304 | { | |
2305 | int i; | |
2306 | ||
2307 | dw2_setup (objfile); | |
1fd400ff TT |
2308 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2309 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2310 | { |
2311 | int j; | |
e254ef6a | 2312 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2313 | |
e254ef6a | 2314 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2315 | continue; |
2316 | ||
e254ef6a DE |
2317 | dw2_require_line_header (objfile, per_cu); |
2318 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2319 | continue; |
2320 | ||
e254ef6a | 2321 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2322 | { |
e254ef6a | 2323 | const char *this_name = per_cu->v.quick->file_names[j]; |
9291a0cd TT |
2324 | if (strcmp (this_name, filename) == 0) |
2325 | { | |
e254ef6a | 2326 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2327 | break; |
2328 | } | |
2329 | } | |
2330 | } | |
2331 | } | |
2332 | ||
dd786858 | 2333 | static const char * |
9291a0cd TT |
2334 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2335 | { | |
e254ef6a | 2336 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd TT |
2337 | offset_type *vec; |
2338 | ||
2339 | dw2_setup (objfile); | |
2340 | ||
2341 | if (!dwarf2_per_objfile->index_table) | |
2342 | return NULL; | |
2343 | ||
2344 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2345 | name, &vec)) | |
2346 | return NULL; | |
2347 | ||
2348 | /* Note that this just looks at the very first one named NAME -- but | |
2349 | actually we are looking for a function. find_main_filename | |
2350 | should be rewritten so that it doesn't require a custom hook. It | |
2351 | could just use the ordinary symbol tables. */ | |
2352 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2353 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2354 | |
e254ef6a DE |
2355 | dw2_require_line_header (objfile, per_cu); |
2356 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2357 | return NULL; |
2358 | ||
e254ef6a | 2359 | return per_cu->v.quick->file_names[per_cu->v.quick->lines->num_file_names - 1]; |
9291a0cd TT |
2360 | } |
2361 | ||
2362 | static void | |
2363 | dw2_map_ada_symtabs (struct objfile *objfile, | |
2364 | int (*wild_match) (const char *, int, const char *), | |
2365 | int (*is_name_suffix) (const char *), | |
2366 | void (*callback) (struct objfile *, | |
2367 | struct symtab *, void *), | |
2368 | const char *name, int global, | |
2369 | domain_enum namespace, int wild, | |
2370 | void *data) | |
2371 | { | |
2372 | /* For now, we don't support Ada, so this function can't be | |
2373 | reached. */ | |
2374 | internal_error (__FILE__, __LINE__, | |
2375 | _("map_ada_symtabs called via index method")); | |
2376 | } | |
2377 | ||
2378 | static void | |
2379 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2380 | int (*file_matcher) (const char *, void *), | |
2381 | int (*name_matcher) (const char *, void *), | |
2382 | domain_enum kind, | |
2383 | void *data) | |
2384 | { | |
2385 | int i; | |
2386 | offset_type iter; | |
2387 | ||
2388 | dw2_setup (objfile); | |
2389 | if (!dwarf2_per_objfile->index_table) | |
2390 | return; | |
2391 | ||
1fd400ff TT |
2392 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2393 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2394 | { |
2395 | int j; | |
e254ef6a | 2396 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2397 | |
e254ef6a DE |
2398 | per_cu->v.quick->mark = 0; |
2399 | if (per_cu->v.quick->symtab) | |
9291a0cd TT |
2400 | continue; |
2401 | ||
e254ef6a DE |
2402 | dw2_require_line_header (objfile, per_cu); |
2403 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2404 | continue; |
2405 | ||
e254ef6a | 2406 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2407 | { |
e254ef6a | 2408 | if (file_matcher (per_cu->v.quick->file_names[j], data)) |
9291a0cd | 2409 | { |
e254ef6a | 2410 | per_cu->v.quick->mark = 1; |
9291a0cd TT |
2411 | break; |
2412 | } | |
2413 | } | |
2414 | } | |
2415 | ||
2416 | for (iter = 0; | |
2417 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2418 | ++iter) | |
2419 | { | |
2420 | offset_type idx = 2 * iter; | |
2421 | const char *name; | |
2422 | offset_type *vec, vec_len, vec_idx; | |
2423 | ||
2424 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2425 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2426 | continue; | |
2427 | ||
2428 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2429 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2430 | ||
2431 | if (! (*name_matcher) (name, data)) | |
2432 | continue; | |
2433 | ||
2434 | /* The name was matched, now expand corresponding CUs that were | |
2435 | marked. */ | |
2436 | vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool | |
2437 | + dwarf2_per_objfile->index_table->index_table[idx + 1]); | |
2438 | vec_len = MAYBE_SWAP (vec[0]); | |
2439 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2440 | { | |
e254ef6a | 2441 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2442 | |
e254ef6a DE |
2443 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
2444 | if (per_cu->v.quick->mark) | |
2445 | dw2_instantiate_symtab (objfile, per_cu); | |
9291a0cd TT |
2446 | } |
2447 | } | |
2448 | } | |
2449 | ||
2450 | static struct symtab * | |
2451 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2452 | struct minimal_symbol *msymbol, | |
2453 | CORE_ADDR pc, | |
2454 | struct obj_section *section, | |
2455 | int warn_if_readin) | |
2456 | { | |
2457 | struct dwarf2_per_cu_data *data; | |
2458 | ||
2459 | dw2_setup (objfile); | |
2460 | ||
2461 | if (!objfile->psymtabs_addrmap) | |
2462 | return NULL; | |
2463 | ||
2464 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2465 | if (!data) | |
2466 | return NULL; | |
2467 | ||
2468 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2469 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2470 | paddress (get_objfile_arch (objfile), pc)); |
2471 | ||
2472 | return dw2_instantiate_symtab (objfile, data); | |
2473 | } | |
2474 | ||
2475 | static void | |
2476 | dw2_map_symbol_names (struct objfile *objfile, | |
2477 | void (*fun) (const char *, void *), | |
2478 | void *data) | |
2479 | { | |
2480 | offset_type iter; | |
2481 | dw2_setup (objfile); | |
2482 | ||
2483 | if (!dwarf2_per_objfile->index_table) | |
2484 | return; | |
2485 | ||
2486 | for (iter = 0; | |
2487 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2488 | ++iter) | |
2489 | { | |
2490 | offset_type idx = 2 * iter; | |
2491 | const char *name; | |
2492 | offset_type *vec, vec_len, vec_idx; | |
2493 | ||
2494 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2495 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2496 | continue; | |
2497 | ||
2498 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2499 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2500 | ||
2501 | (*fun) (name, data); | |
2502 | } | |
2503 | } | |
2504 | ||
2505 | static void | |
2506 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2507 | void (*fun) (const char *, const char *, void *), | |
2508 | void *data) | |
2509 | { | |
2510 | int i; | |
2511 | ||
2512 | dw2_setup (objfile); | |
1fd400ff TT |
2513 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2514 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2515 | { |
2516 | int j; | |
e254ef6a | 2517 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2518 | |
e254ef6a | 2519 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2520 | continue; |
2521 | ||
e254ef6a DE |
2522 | dw2_require_line_header (objfile, per_cu); |
2523 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2524 | continue; |
2525 | ||
e254ef6a | 2526 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2527 | { |
e254ef6a DE |
2528 | const char *this_full_name = dw2_require_full_path (objfile, per_cu, |
2529 | j); | |
2530 | (*fun) (per_cu->v.quick->file_names[j], this_full_name, data); | |
9291a0cd TT |
2531 | } |
2532 | } | |
2533 | } | |
2534 | ||
2535 | static int | |
2536 | dw2_has_symbols (struct objfile *objfile) | |
2537 | { | |
2538 | return 1; | |
2539 | } | |
2540 | ||
2541 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2542 | { | |
2543 | dw2_has_symbols, | |
2544 | dw2_find_last_source_symtab, | |
2545 | dw2_forget_cached_source_info, | |
2546 | dw2_lookup_symtab, | |
2547 | dw2_lookup_symbol, | |
774b6a14 | 2548 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2549 | dw2_print_stats, |
2550 | dw2_dump, | |
2551 | dw2_relocate, | |
2552 | dw2_expand_symtabs_for_function, | |
2553 | dw2_expand_all_symtabs, | |
2554 | dw2_expand_symtabs_with_filename, | |
2555 | dw2_find_symbol_file, | |
2556 | dw2_map_ada_symtabs, | |
2557 | dw2_expand_symtabs_matching, | |
2558 | dw2_find_pc_sect_symtab, | |
2559 | dw2_map_symbol_names, | |
2560 | dw2_map_symbol_filenames | |
2561 | }; | |
2562 | ||
2563 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2564 | file will use psymtabs, or 1 if using the GNU index. */ | |
2565 | ||
2566 | int | |
2567 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2568 | { | |
2569 | /* If we're about to read full symbols, don't bother with the | |
2570 | indices. In this case we also don't care if some other debug | |
2571 | format is making psymtabs, because they are all about to be | |
2572 | expanded anyway. */ | |
2573 | if ((objfile->flags & OBJF_READNOW)) | |
2574 | { | |
2575 | int i; | |
2576 | ||
2577 | dwarf2_per_objfile->using_index = 1; | |
2578 | create_all_comp_units (objfile); | |
1fd400ff | 2579 | create_debug_types_hash_table (objfile); |
9291a0cd | 2580 | |
1fd400ff TT |
2581 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2582 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2583 | { |
e254ef6a | 2584 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2585 | |
e254ef6a DE |
2586 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2587 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2588 | } |
2589 | ||
2590 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2591 | these functions will be no-ops because we will have expanded | |
2592 | all symtabs. */ | |
2593 | return 1; | |
2594 | } | |
2595 | ||
2596 | if (dwarf2_read_index (objfile)) | |
2597 | return 1; | |
2598 | ||
2599 | dwarf2_build_psymtabs (objfile); | |
2600 | return 0; | |
2601 | } | |
2602 | ||
2603 | \f | |
2604 | ||
dce234bc PP |
2605 | /* Build a partial symbol table. */ |
2606 | ||
2607 | void | |
f29dff0a | 2608 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2609 | { |
f29dff0a | 2610 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2611 | { |
2612 | init_psymbol_list (objfile, 1024); | |
2613 | } | |
2614 | ||
d146bf1e | 2615 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2616 | } |
c906108c | 2617 | |
45452591 DE |
2618 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2619 | ||
2620 | static inline int | |
2621 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2622 | { | |
2623 | unsigned int bottom = cu_header->offset; | |
2624 | unsigned int top = (cu_header->offset | |
2625 | + cu_header->length | |
2626 | + cu_header->initial_length_size); | |
9a619af0 | 2627 | |
45452591 DE |
2628 | return (offset >= bottom && offset < top); |
2629 | } | |
2630 | ||
93311388 DE |
2631 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2632 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2633 | by the caller. */ | |
107d2387 | 2634 | |
fe1b8b76 | 2635 | static gdb_byte * |
107d2387 | 2636 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2637 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2638 | { |
2639 | int signed_addr; | |
891d2f0b | 2640 | unsigned int bytes_read; |
c764a876 DE |
2641 | |
2642 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2643 | cu_header->initial_length_size = bytes_read; | |
2644 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2645 | info_ptr += bytes_read; |
107d2387 AC |
2646 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2647 | info_ptr += 2; | |
613e1657 | 2648 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2649 | &bytes_read); |
613e1657 | 2650 | info_ptr += bytes_read; |
107d2387 AC |
2651 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2652 | info_ptr += 1; | |
2653 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2654 | if (signed_addr < 0) | |
8e65ff28 | 2655 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2656 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2657 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2658 | |
107d2387 AC |
2659 | return info_ptr; |
2660 | } | |
2661 | ||
fe1b8b76 JB |
2662 | static gdb_byte * |
2663 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2664 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2665 | bfd *abfd) |
2666 | { | |
fe1b8b76 | 2667 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2668 | |
2669 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2670 | ||
2dc7f7b3 | 2671 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2672 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2673 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2674 | bfd_get_filename (abfd)); | |
72bf9492 | 2675 | |
dce234bc | 2676 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
2677 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2678 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2679 | (long) header->abbrev_offset, |
93311388 | 2680 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2681 | bfd_get_filename (abfd)); |
2682 | ||
2683 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2684 | > buffer + buffer_size) |
8a3fe4f8 AC |
2685 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2686 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2687 | (long) header->length, |
93311388 | 2688 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2689 | bfd_get_filename (abfd)); |
2690 | ||
2691 | return info_ptr; | |
2692 | } | |
2693 | ||
348e048f DE |
2694 | /* Read in the types comp unit header information from .debug_types entry at |
2695 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2696 | ||
2697 | static gdb_byte * | |
2698 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2699 | ULONGEST *signature, | |
2700 | gdb_byte *types_ptr, bfd *abfd) | |
2701 | { | |
348e048f DE |
2702 | gdb_byte *initial_types_ptr = types_ptr; |
2703 | ||
6e70227d | 2704 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2705 | &dwarf2_per_objfile->types); |
348e048f DE |
2706 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2707 | ||
2708 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2709 | ||
2710 | *signature = read_8_bytes (abfd, types_ptr); | |
2711 | types_ptr += 8; | |
2712 | types_ptr += cu_header->offset_size; | |
2713 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2714 | ||
2715 | return types_ptr; | |
2716 | } | |
2717 | ||
aaa75496 JB |
2718 | /* Allocate a new partial symtab for file named NAME and mark this new |
2719 | partial symtab as being an include of PST. */ | |
2720 | ||
2721 | static void | |
2722 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2723 | struct objfile *objfile) | |
2724 | { | |
2725 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2726 | ||
2727 | subpst->section_offsets = pst->section_offsets; | |
2728 | subpst->textlow = 0; | |
2729 | subpst->texthigh = 0; | |
2730 | ||
2731 | subpst->dependencies = (struct partial_symtab **) | |
2732 | obstack_alloc (&objfile->objfile_obstack, | |
2733 | sizeof (struct partial_symtab *)); | |
2734 | subpst->dependencies[0] = pst; | |
2735 | subpst->number_of_dependencies = 1; | |
2736 | ||
2737 | subpst->globals_offset = 0; | |
2738 | subpst->n_global_syms = 0; | |
2739 | subpst->statics_offset = 0; | |
2740 | subpst->n_static_syms = 0; | |
2741 | subpst->symtab = NULL; | |
2742 | subpst->read_symtab = pst->read_symtab; | |
2743 | subpst->readin = 0; | |
2744 | ||
2745 | /* No private part is necessary for include psymtabs. This property | |
2746 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2747 | the regular ones. */ |
58a9656e | 2748 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2749 | } |
2750 | ||
2751 | /* Read the Line Number Program data and extract the list of files | |
2752 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2753 | partial symtab for each of these included files. */ |
aaa75496 JB |
2754 | |
2755 | static void | |
2756 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2757 | struct die_info *die, |
aaa75496 JB |
2758 | struct partial_symtab *pst) |
2759 | { | |
2760 | struct objfile *objfile = cu->objfile; | |
2761 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2762 | struct line_header *lh = NULL; |
2763 | struct attribute *attr; | |
aaa75496 | 2764 | |
d85a05f0 DJ |
2765 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2766 | if (attr) | |
2767 | { | |
2768 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2769 | |
d85a05f0 DJ |
2770 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2771 | } | |
aaa75496 JB |
2772 | if (lh == NULL) |
2773 | return; /* No linetable, so no includes. */ | |
2774 | ||
c6da4cef DE |
2775 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
2776 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
2777 | |
2778 | free_line_header (lh); | |
2779 | } | |
2780 | ||
348e048f DE |
2781 | static hashval_t |
2782 | hash_type_signature (const void *item) | |
2783 | { | |
2784 | const struct signatured_type *type_sig = item; | |
9a619af0 | 2785 | |
348e048f DE |
2786 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
2787 | return type_sig->signature; | |
2788 | } | |
2789 | ||
2790 | static int | |
2791 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
2792 | { | |
2793 | const struct signatured_type *lhs = item_lhs; | |
2794 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 2795 | |
348e048f DE |
2796 | return lhs->signature == rhs->signature; |
2797 | } | |
2798 | ||
1fd400ff TT |
2799 | /* Allocate a hash table for signatured types. */ |
2800 | ||
2801 | static htab_t | |
673bfd45 | 2802 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
2803 | { |
2804 | return htab_create_alloc_ex (41, | |
2805 | hash_type_signature, | |
2806 | eq_type_signature, | |
2807 | NULL, | |
2808 | &objfile->objfile_obstack, | |
2809 | hashtab_obstack_allocate, | |
2810 | dummy_obstack_deallocate); | |
2811 | } | |
2812 | ||
2813 | /* A helper function to add a signatured type CU to a list. */ | |
2814 | ||
2815 | static int | |
2816 | add_signatured_type_cu_to_list (void **slot, void *datum) | |
2817 | { | |
2818 | struct signatured_type *sigt = *slot; | |
2819 | struct dwarf2_per_cu_data ***datap = datum; | |
2820 | ||
2821 | **datap = &sigt->per_cu; | |
2822 | ++*datap; | |
2823 | ||
2824 | return 1; | |
2825 | } | |
2826 | ||
348e048f DE |
2827 | /* Create the hash table of all entries in the .debug_types section. |
2828 | The result is zero if there is an error (e.g. missing .debug_types section), | |
2829 | otherwise non-zero. */ | |
2830 | ||
2831 | static int | |
2832 | create_debug_types_hash_table (struct objfile *objfile) | |
2833 | { | |
be391dca | 2834 | gdb_byte *info_ptr; |
348e048f | 2835 | htab_t types_htab; |
1fd400ff | 2836 | struct dwarf2_per_cu_data **iter; |
348e048f | 2837 | |
be391dca TT |
2838 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
2839 | info_ptr = dwarf2_per_objfile->types.buffer; | |
2840 | ||
348e048f DE |
2841 | if (info_ptr == NULL) |
2842 | { | |
2843 | dwarf2_per_objfile->signatured_types = NULL; | |
2844 | return 0; | |
2845 | } | |
2846 | ||
673bfd45 | 2847 | types_htab = allocate_signatured_type_table (objfile); |
348e048f DE |
2848 | |
2849 | if (dwarf2_die_debug) | |
2850 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
2851 | ||
2852 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2853 | { | |
2854 | unsigned int offset; | |
2855 | unsigned int offset_size; | |
2856 | unsigned int type_offset; | |
2857 | unsigned int length, initial_length_size; | |
2858 | unsigned short version; | |
2859 | ULONGEST signature; | |
2860 | struct signatured_type *type_sig; | |
2861 | void **slot; | |
2862 | gdb_byte *ptr = info_ptr; | |
2863 | ||
2864 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
2865 | ||
2866 | /* We need to read the type's signature in order to build the hash | |
2867 | table, but we don't need to read anything else just yet. */ | |
2868 | ||
2869 | /* Sanity check to ensure entire cu is present. */ | |
2870 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
2871 | if (ptr + length + initial_length_size | |
2872 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2873 | { | |
2874 | complaint (&symfile_complaints, | |
2875 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
2876 | break; | |
2877 | } | |
2878 | ||
2879 | offset_size = initial_length_size == 4 ? 4 : 8; | |
2880 | ptr += initial_length_size; | |
2881 | version = bfd_get_16 (objfile->obfd, ptr); | |
2882 | ptr += 2; | |
2883 | ptr += offset_size; /* abbrev offset */ | |
2884 | ptr += 1; /* address size */ | |
2885 | signature = bfd_get_64 (objfile->obfd, ptr); | |
2886 | ptr += 8; | |
2887 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
2888 | ||
2889 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
2890 | memset (type_sig, 0, sizeof (*type_sig)); | |
2891 | type_sig->signature = signature; | |
2892 | type_sig->offset = offset; | |
2893 | type_sig->type_offset = type_offset; | |
ca1f3406 | 2894 | type_sig->per_cu.objfile = objfile; |
1fd400ff | 2895 | type_sig->per_cu.from_debug_types = 1; |
348e048f DE |
2896 | |
2897 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
2898 | gdb_assert (slot != NULL); | |
2899 | *slot = type_sig; | |
2900 | ||
2901 | if (dwarf2_die_debug) | |
2902 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
2903 | offset, phex (signature, sizeof (signature))); | |
2904 | ||
2905 | info_ptr = info_ptr + initial_length_size + length; | |
2906 | } | |
2907 | ||
2908 | dwarf2_per_objfile->signatured_types = types_htab; | |
2909 | ||
1fd400ff TT |
2910 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
2911 | dwarf2_per_objfile->type_comp_units | |
2912 | = obstack_alloc (&objfile->objfile_obstack, | |
2913 | dwarf2_per_objfile->n_type_comp_units | |
2914 | * sizeof (struct dwarf2_per_cu_data *)); | |
2915 | iter = &dwarf2_per_objfile->type_comp_units[0]; | |
2916 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); | |
2917 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] | |
2918 | == dwarf2_per_objfile->n_type_comp_units); | |
2919 | ||
348e048f DE |
2920 | return 1; |
2921 | } | |
2922 | ||
2923 | /* Lookup a signature based type. | |
2924 | Returns NULL if SIG is not present in the table. */ | |
2925 | ||
2926 | static struct signatured_type * | |
2927 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
2928 | { | |
2929 | struct signatured_type find_entry, *entry; | |
2930 | ||
2931 | if (dwarf2_per_objfile->signatured_types == NULL) | |
2932 | { | |
2933 | complaint (&symfile_complaints, | |
2934 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
2935 | return 0; | |
2936 | } | |
2937 | ||
2938 | find_entry.signature = sig; | |
2939 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
2940 | return entry; | |
2941 | } | |
2942 | ||
d85a05f0 DJ |
2943 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
2944 | ||
2945 | static void | |
2946 | init_cu_die_reader (struct die_reader_specs *reader, | |
2947 | struct dwarf2_cu *cu) | |
2948 | { | |
2949 | reader->abfd = cu->objfile->obfd; | |
2950 | reader->cu = cu; | |
2951 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
2952 | { |
2953 | gdb_assert (dwarf2_per_objfile->types.readin); | |
2954 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
2955 | } | |
d85a05f0 | 2956 | else |
be391dca TT |
2957 | { |
2958 | gdb_assert (dwarf2_per_objfile->info.readin); | |
2959 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
2960 | } | |
d85a05f0 DJ |
2961 | } |
2962 | ||
2963 | /* Find the base address of the compilation unit for range lists and | |
2964 | location lists. It will normally be specified by DW_AT_low_pc. | |
2965 | In DWARF-3 draft 4, the base address could be overridden by | |
2966 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2967 | compilation units with discontinuous ranges. */ | |
2968 | ||
2969 | static void | |
2970 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
2971 | { | |
2972 | struct attribute *attr; | |
2973 | ||
2974 | cu->base_known = 0; | |
2975 | cu->base_address = 0; | |
2976 | ||
2977 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
2978 | if (attr) | |
2979 | { | |
2980 | cu->base_address = DW_ADDR (attr); | |
2981 | cu->base_known = 1; | |
2982 | } | |
2983 | else | |
2984 | { | |
2985 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
2986 | if (attr) | |
2987 | { | |
2988 | cu->base_address = DW_ADDR (attr); | |
2989 | cu->base_known = 1; | |
2990 | } | |
2991 | } | |
2992 | } | |
2993 | ||
348e048f DE |
2994 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
2995 | to combine the common parts. | |
93311388 | 2996 | Process a compilation unit for a psymtab. |
348e048f DE |
2997 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
2998 | either .debug_info or debug_types. | |
93311388 DE |
2999 | INFO_PTR is a pointer to the start of the CU. |
3000 | Returns a pointer to the next CU. */ | |
aaa75496 | 3001 | |
93311388 DE |
3002 | static gdb_byte * |
3003 | process_psymtab_comp_unit (struct objfile *objfile, | |
3004 | struct dwarf2_per_cu_data *this_cu, | |
3005 | gdb_byte *buffer, gdb_byte *info_ptr, | |
3006 | unsigned int buffer_size) | |
c906108c | 3007 | { |
c906108c | 3008 | bfd *abfd = objfile->obfd; |
93311388 | 3009 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3010 | struct die_info *comp_unit_die; |
c906108c | 3011 | struct partial_symtab *pst; |
5734ee8b | 3012 | CORE_ADDR baseaddr; |
93311388 DE |
3013 | struct cleanup *back_to_inner; |
3014 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3015 | int has_children, has_pc_info; |
3016 | struct attribute *attr; | |
d85a05f0 DJ |
3017 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3018 | struct die_reader_specs reader_specs; | |
c906108c | 3019 | |
93311388 DE |
3020 | memset (&cu, 0, sizeof (cu)); |
3021 | cu.objfile = objfile; | |
3022 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 3023 | |
93311388 | 3024 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3025 | |
93311388 DE |
3026 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
3027 | buffer, buffer_size, | |
3028 | abfd); | |
10b3939b | 3029 | |
93311388 DE |
3030 | /* Complete the cu_header. */ |
3031 | cu.header.offset = beg_of_comp_unit - buffer; | |
3032 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 3033 | |
93311388 | 3034 | cu.list_in_scope = &file_symbols; |
af703f96 | 3035 | |
328c9494 DJ |
3036 | /* If this compilation unit was already read in, free the |
3037 | cached copy in order to read it in again. This is | |
3038 | necessary because we skipped some symbols when we first | |
3039 | read in the compilation unit (see load_partial_dies). | |
3040 | This problem could be avoided, but the benefit is | |
3041 | unclear. */ | |
3042 | if (this_cu->cu != NULL) | |
3043 | free_one_cached_comp_unit (this_cu->cu); | |
3044 | ||
3045 | /* Note that this is a pointer to our stack frame, being | |
3046 | added to a global data structure. It will be cleaned up | |
3047 | in free_stack_comp_unit when we finish with this | |
3048 | compilation unit. */ | |
3049 | this_cu->cu = &cu; | |
d85a05f0 DJ |
3050 | cu.per_cu = this_cu; |
3051 | ||
93311388 DE |
3052 | /* Read the abbrevs for this compilation unit into a table. */ |
3053 | dwarf2_read_abbrevs (abfd, &cu); | |
3054 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 3055 | |
93311388 | 3056 | /* Read the compilation unit die. */ |
348e048f DE |
3057 | if (this_cu->from_debug_types) |
3058 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
3059 | init_cu_die_reader (&reader_specs, &cu); |
3060 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3061 | &has_children); | |
93311388 | 3062 | |
348e048f DE |
3063 | if (this_cu->from_debug_types) |
3064 | { | |
3065 | /* offset,length haven't been set yet for type units. */ | |
3066 | this_cu->offset = cu.header.offset; | |
3067 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
3068 | } | |
d85a05f0 | 3069 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3070 | { |
93311388 DE |
3071 | info_ptr = (beg_of_comp_unit + cu.header.length |
3072 | + cu.header.initial_length_size); | |
3073 | do_cleanups (back_to_inner); | |
3074 | return info_ptr; | |
3075 | } | |
72bf9492 | 3076 | |
93311388 | 3077 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
3078 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
3079 | if (attr) | |
3080 | set_cu_language (DW_UNSND (attr), &cu); | |
3081 | else | |
3082 | set_cu_language (language_minimal, &cu); | |
c906108c | 3083 | |
93311388 | 3084 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3085 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 3086 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 3087 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
3088 | /* TEXTLOW and TEXTHIGH are set below. */ |
3089 | 0, | |
3090 | objfile->global_psymbols.next, | |
3091 | objfile->static_psymbols.next); | |
72bf9492 | 3092 | |
d85a05f0 DJ |
3093 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3094 | if (attr != NULL) | |
3095 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3096 | |
e38df1d0 | 3097 | pst->read_symtab_private = this_cu; |
72bf9492 | 3098 | |
93311388 | 3099 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3100 | |
93311388 DE |
3101 | /* Store the function that reads in the rest of the symbol table */ |
3102 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 3103 | |
9291a0cd | 3104 | this_cu->v.psymtab = pst; |
c906108c | 3105 | |
d85a05f0 DJ |
3106 | dwarf2_find_base_address (comp_unit_die, &cu); |
3107 | ||
93311388 DE |
3108 | /* Possibly set the default values of LOWPC and HIGHPC from |
3109 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3110 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3111 | &best_highpc, &cu, pst); | |
3112 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3113 | /* Store the contiguous range if it is not empty; it can be empty for |
3114 | CUs with no code. */ | |
3115 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3116 | best_lowpc + baseaddr, |
3117 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3118 | |
3119 | /* Check if comp unit has_children. | |
3120 | If so, read the rest of the partial symbols from this comp unit. | |
3121 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3122 | if (has_children) |
93311388 DE |
3123 | { |
3124 | struct partial_die_info *first_die; | |
3125 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3126 | |
93311388 DE |
3127 | lowpc = ((CORE_ADDR) -1); |
3128 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3129 | |
93311388 | 3130 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3131 | |
93311388 | 3132 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3133 | ! has_pc_info, &cu); |
57c22c6c | 3134 | |
93311388 DE |
3135 | /* If we didn't find a lowpc, set it to highpc to avoid |
3136 | complaints from `maint check'. */ | |
3137 | if (lowpc == ((CORE_ADDR) -1)) | |
3138 | lowpc = highpc; | |
10b3939b | 3139 | |
93311388 DE |
3140 | /* If the compilation unit didn't have an explicit address range, |
3141 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3142 | if (! has_pc_info) |
93311388 | 3143 | { |
d85a05f0 DJ |
3144 | best_lowpc = lowpc; |
3145 | best_highpc = highpc; | |
93311388 DE |
3146 | } |
3147 | } | |
d85a05f0 DJ |
3148 | pst->textlow = best_lowpc + baseaddr; |
3149 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3150 | |
93311388 DE |
3151 | pst->n_global_syms = objfile->global_psymbols.next - |
3152 | (objfile->global_psymbols.list + pst->globals_offset); | |
3153 | pst->n_static_syms = objfile->static_psymbols.next - | |
3154 | (objfile->static_psymbols.list + pst->statics_offset); | |
3155 | sort_pst_symbols (pst); | |
c906108c | 3156 | |
93311388 DE |
3157 | info_ptr = (beg_of_comp_unit + cu.header.length |
3158 | + cu.header.initial_length_size); | |
ae038cb0 | 3159 | |
348e048f DE |
3160 | if (this_cu->from_debug_types) |
3161 | { | |
3162 | /* It's not clear we want to do anything with stmt lists here. | |
3163 | Waiting to see what gcc ultimately does. */ | |
3164 | } | |
d85a05f0 | 3165 | else |
93311388 DE |
3166 | { |
3167 | /* Get the list of files included in the current compilation unit, | |
3168 | and build a psymtab for each of them. */ | |
d85a05f0 | 3169 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3170 | } |
ae038cb0 | 3171 | |
93311388 | 3172 | do_cleanups (back_to_inner); |
ae038cb0 | 3173 | |
93311388 DE |
3174 | return info_ptr; |
3175 | } | |
ff013f42 | 3176 | |
348e048f DE |
3177 | /* Traversal function for htab_traverse_noresize. |
3178 | Process one .debug_types comp-unit. */ | |
3179 | ||
3180 | static int | |
3181 | process_type_comp_unit (void **slot, void *info) | |
3182 | { | |
3183 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
3184 | struct objfile *objfile = (struct objfile *) info; | |
3185 | struct dwarf2_per_cu_data *this_cu; | |
3186 | ||
3187 | this_cu = &entry->per_cu; | |
348e048f | 3188 | |
be391dca | 3189 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
3190 | process_psymtab_comp_unit (objfile, this_cu, |
3191 | dwarf2_per_objfile->types.buffer, | |
3192 | dwarf2_per_objfile->types.buffer + entry->offset, | |
3193 | dwarf2_per_objfile->types.size); | |
3194 | ||
3195 | return 1; | |
3196 | } | |
3197 | ||
3198 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3199 | Build partial symbol tables for the .debug_types comp-units. */ | |
3200 | ||
3201 | static void | |
3202 | build_type_psymtabs (struct objfile *objfile) | |
3203 | { | |
3204 | if (! create_debug_types_hash_table (objfile)) | |
3205 | return; | |
3206 | ||
3207 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
3208 | process_type_comp_unit, objfile); | |
3209 | } | |
3210 | ||
60606b2c TT |
3211 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3212 | ||
3213 | static void | |
3214 | psymtabs_addrmap_cleanup (void *o) | |
3215 | { | |
3216 | struct objfile *objfile = o; | |
ec61707d | 3217 | |
60606b2c TT |
3218 | objfile->psymtabs_addrmap = NULL; |
3219 | } | |
3220 | ||
93311388 DE |
3221 | /* Build the partial symbol table by doing a quick pass through the |
3222 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3223 | |
93311388 | 3224 | static void |
c67a9c90 | 3225 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3226 | { |
93311388 | 3227 | gdb_byte *info_ptr; |
60606b2c TT |
3228 | struct cleanup *back_to, *addrmap_cleanup; |
3229 | struct obstack temp_obstack; | |
93311388 | 3230 | |
98bfdba5 PA |
3231 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3232 | ||
be391dca | 3233 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3234 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3235 | |
93311388 DE |
3236 | /* Any cached compilation units will be linked by the per-objfile |
3237 | read_in_chain. Make sure to free them when we're done. */ | |
3238 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3239 | |
348e048f DE |
3240 | build_type_psymtabs (objfile); |
3241 | ||
93311388 | 3242 | create_all_comp_units (objfile); |
c906108c | 3243 | |
60606b2c TT |
3244 | /* Create a temporary address map on a temporary obstack. We later |
3245 | copy this to the final obstack. */ | |
3246 | obstack_init (&temp_obstack); | |
3247 | make_cleanup_obstack_free (&temp_obstack); | |
3248 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3249 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3250 | |
93311388 DE |
3251 | /* Since the objects we're extracting from .debug_info vary in |
3252 | length, only the individual functions to extract them (like | |
3253 | read_comp_unit_head and load_partial_die) can really know whether | |
3254 | the buffer is large enough to hold another complete object. | |
c906108c | 3255 | |
93311388 DE |
3256 | At the moment, they don't actually check that. If .debug_info |
3257 | holds just one extra byte after the last compilation unit's dies, | |
3258 | then read_comp_unit_head will happily read off the end of the | |
3259 | buffer. read_partial_die is similarly casual. Those functions | |
3260 | should be fixed. | |
c906108c | 3261 | |
93311388 DE |
3262 | For this loop condition, simply checking whether there's any data |
3263 | left at all should be sufficient. */ | |
c906108c | 3264 | |
93311388 DE |
3265 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3266 | + dwarf2_per_objfile->info.size)) | |
3267 | { | |
3268 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3269 | |
93311388 DE |
3270 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
3271 | objfile); | |
aaa75496 | 3272 | |
93311388 DE |
3273 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3274 | dwarf2_per_objfile->info.buffer, | |
3275 | info_ptr, | |
3276 | dwarf2_per_objfile->info.size); | |
c906108c | 3277 | } |
ff013f42 JK |
3278 | |
3279 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3280 | &objfile->objfile_obstack); | |
60606b2c | 3281 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3282 | |
ae038cb0 DJ |
3283 | do_cleanups (back_to); |
3284 | } | |
3285 | ||
93311388 | 3286 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3287 | |
3288 | static void | |
93311388 DE |
3289 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3290 | struct objfile *objfile) | |
ae038cb0 DJ |
3291 | { |
3292 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3293 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3294 | struct die_info *comp_unit_die; |
ae038cb0 | 3295 | struct dwarf2_cu *cu; |
1d9ec526 | 3296 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3297 | struct attribute *attr; |
3298 | int has_children; | |
3299 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3300 | int read_cu = 0; |
ae038cb0 | 3301 | |
348e048f DE |
3302 | gdb_assert (! this_cu->from_debug_types); |
3303 | ||
be391dca | 3304 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3305 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3306 | beg_of_comp_unit = info_ptr; |
3307 | ||
98bfdba5 PA |
3308 | if (this_cu->cu == NULL) |
3309 | { | |
3310 | cu = alloc_one_comp_unit (objfile); | |
ae038cb0 | 3311 | |
98bfdba5 | 3312 | read_cu = 1; |
ae038cb0 | 3313 | |
98bfdba5 PA |
3314 | /* If an error occurs while loading, release our storage. */ |
3315 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
328c9494 | 3316 | |
98bfdba5 PA |
3317 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3318 | dwarf2_per_objfile->info.buffer, | |
3319 | dwarf2_per_objfile->info.size, | |
3320 | abfd); | |
ae038cb0 | 3321 | |
98bfdba5 PA |
3322 | /* Complete the cu_header. */ |
3323 | cu->header.offset = this_cu->offset; | |
3324 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3325 | ||
3326 | /* Link this compilation unit into the compilation unit tree. */ | |
3327 | this_cu->cu = cu; | |
3328 | cu->per_cu = this_cu; | |
98bfdba5 PA |
3329 | |
3330 | /* Link this CU into read_in_chain. */ | |
3331 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3332 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3333 | } | |
3334 | else | |
3335 | { | |
3336 | cu = this_cu->cu; | |
3337 | info_ptr += cu->header.first_die_offset; | |
3338 | } | |
ae038cb0 DJ |
3339 | |
3340 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3341 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
ae038cb0 | 3342 | dwarf2_read_abbrevs (abfd, cu); |
98bfdba5 | 3343 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3344 | |
3345 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3346 | init_cu_die_reader (&reader_specs, cu); |
3347 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3348 | &has_children); | |
ae038cb0 DJ |
3349 | |
3350 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
3351 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
3352 | if (attr) | |
3353 | set_cu_language (DW_UNSND (attr), cu); | |
3354 | else | |
3355 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 3356 | |
ae038cb0 DJ |
3357 | /* Check if comp unit has_children. |
3358 | If so, read the rest of the partial symbols from this comp unit. | |
3359 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3360 | if (has_children) |
93311388 | 3361 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 | 3362 | |
98bfdba5 PA |
3363 | do_cleanups (free_abbrevs_cleanup); |
3364 | ||
3365 | if (read_cu) | |
3366 | { | |
3367 | /* We've successfully allocated this compilation unit. Let our | |
3368 | caller clean it up when finished with it. */ | |
3369 | discard_cleanups (free_cu_cleanup); | |
3370 | } | |
ae038cb0 DJ |
3371 | } |
3372 | ||
3373 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3374 | if an inter-comp-unit reference is found; presumably if there is one, | |
3375 | there will be many, and one will occur early in the .debug_info section. | |
3376 | So there's no point in building this list incrementally. */ | |
3377 | ||
3378 | static void | |
3379 | create_all_comp_units (struct objfile *objfile) | |
3380 | { | |
3381 | int n_allocated; | |
3382 | int n_comp_units; | |
3383 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3384 | gdb_byte *info_ptr; |
3385 | ||
3386 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3387 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3388 | |
3389 | n_comp_units = 0; | |
3390 | n_allocated = 10; | |
3391 | all_comp_units = xmalloc (n_allocated | |
3392 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3393 | |
dce234bc | 3394 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 3395 | { |
c764a876 | 3396 | unsigned int length, initial_length_size; |
ae038cb0 | 3397 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3398 | unsigned int offset; |
ae038cb0 | 3399 | |
dce234bc | 3400 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3401 | |
3402 | /* Read just enough information to find out where the next | |
3403 | compilation unit is. */ | |
c764a876 DE |
3404 | length = read_initial_length (objfile->obfd, info_ptr, |
3405 | &initial_length_size); | |
ae038cb0 DJ |
3406 | |
3407 | /* Save the compilation unit for later lookup. */ | |
3408 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3409 | sizeof (struct dwarf2_per_cu_data)); | |
3410 | memset (this_cu, 0, sizeof (*this_cu)); | |
3411 | this_cu->offset = offset; | |
c764a876 | 3412 | this_cu->length = length + initial_length_size; |
9291a0cd | 3413 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3414 | |
3415 | if (n_comp_units == n_allocated) | |
3416 | { | |
3417 | n_allocated *= 2; | |
3418 | all_comp_units = xrealloc (all_comp_units, | |
3419 | n_allocated | |
3420 | * sizeof (struct dwarf2_per_cu_data *)); | |
3421 | } | |
3422 | all_comp_units[n_comp_units++] = this_cu; | |
3423 | ||
3424 | info_ptr = info_ptr + this_cu->length; | |
3425 | } | |
3426 | ||
3427 | dwarf2_per_objfile->all_comp_units | |
3428 | = obstack_alloc (&objfile->objfile_obstack, | |
3429 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3430 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3431 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3432 | xfree (all_comp_units); | |
3433 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3434 | } |
3435 | ||
5734ee8b DJ |
3436 | /* Process all loaded DIEs for compilation unit CU, starting at |
3437 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3438 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3439 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3440 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3441 | and record the covered ranges in the addrmap. */ | |
c906108c | 3442 | |
72bf9492 DJ |
3443 | static void |
3444 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3445 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3446 | { |
72bf9492 | 3447 | struct partial_die_info *pdi; |
c906108c | 3448 | |
91c24f0a DC |
3449 | /* Now, march along the PDI's, descending into ones which have |
3450 | interesting children but skipping the children of the other ones, | |
3451 | until we reach the end of the compilation unit. */ | |
c906108c | 3452 | |
72bf9492 | 3453 | pdi = first_die; |
91c24f0a | 3454 | |
72bf9492 DJ |
3455 | while (pdi != NULL) |
3456 | { | |
3457 | fixup_partial_die (pdi, cu); | |
c906108c | 3458 | |
f55ee35c | 3459 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3460 | children, so we need to look at them. Ditto for anonymous |
3461 | enums. */ | |
933c6fe4 | 3462 | |
72bf9492 | 3463 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3464 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3465 | { |
72bf9492 | 3466 | switch (pdi->tag) |
c906108c SS |
3467 | { |
3468 | case DW_TAG_subprogram: | |
5734ee8b | 3469 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
3470 | break; |
3471 | case DW_TAG_variable: | |
3472 | case DW_TAG_typedef: | |
91c24f0a | 3473 | case DW_TAG_union_type: |
72bf9492 | 3474 | if (!pdi->is_declaration) |
63d06c5c | 3475 | { |
72bf9492 | 3476 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3477 | } |
3478 | break; | |
c906108c | 3479 | case DW_TAG_class_type: |
680b30c7 | 3480 | case DW_TAG_interface_type: |
c906108c | 3481 | case DW_TAG_structure_type: |
72bf9492 | 3482 | if (!pdi->is_declaration) |
c906108c | 3483 | { |
72bf9492 | 3484 | add_partial_symbol (pdi, cu); |
c906108c SS |
3485 | } |
3486 | break; | |
91c24f0a | 3487 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3488 | if (!pdi->is_declaration) |
3489 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3490 | break; |
3491 | case DW_TAG_base_type: | |
a02abb62 | 3492 | case DW_TAG_subrange_type: |
c906108c | 3493 | /* File scope base type definitions are added to the partial |
c5aa993b | 3494 | symbol table. */ |
72bf9492 | 3495 | add_partial_symbol (pdi, cu); |
c906108c | 3496 | break; |
d9fa45fe | 3497 | case DW_TAG_namespace: |
5734ee8b | 3498 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3499 | break; |
5d7cb8df JK |
3500 | case DW_TAG_module: |
3501 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3502 | break; | |
c906108c SS |
3503 | default: |
3504 | break; | |
3505 | } | |
3506 | } | |
3507 | ||
72bf9492 DJ |
3508 | /* If the die has a sibling, skip to the sibling. */ |
3509 | ||
3510 | pdi = pdi->die_sibling; | |
3511 | } | |
3512 | } | |
3513 | ||
3514 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3515 | |
72bf9492 | 3516 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3517 | name is concatenated with "::" and the partial DIE's name. For |
3518 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3519 | Enumerators are an exception; they use the scope of their parent |
3520 | enumeration type, i.e. the name of the enumeration type is not | |
3521 | prepended to the enumerator. | |
91c24f0a | 3522 | |
72bf9492 DJ |
3523 | There are two complexities. One is DW_AT_specification; in this |
3524 | case "parent" means the parent of the target of the specification, | |
3525 | instead of the direct parent of the DIE. The other is compilers | |
3526 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3527 | the fully qualified name of structure types from their members' | |
3528 | linkage names. This must be done using the DIE's children rather | |
3529 | than the children of any DW_AT_specification target. We only need | |
3530 | to do this for structures at the top level, i.e. if the target of | |
3531 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3532 | have a parent. */ | |
3533 | ||
3534 | /* Compute the scope prefix associated with PDI's parent, in | |
3535 | compilation unit CU. The result will be allocated on CU's | |
3536 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3537 | field. NULL is returned if no prefix is necessary. */ | |
3538 | static char * | |
3539 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3540 | struct dwarf2_cu *cu) | |
3541 | { | |
3542 | char *grandparent_scope; | |
3543 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3544 | |
72bf9492 DJ |
3545 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3546 | then this means the parent of the specification DIE. */ | |
3547 | ||
3548 | real_pdi = pdi; | |
72bf9492 | 3549 | while (real_pdi->has_specification) |
10b3939b | 3550 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3551 | |
3552 | parent = real_pdi->die_parent; | |
3553 | if (parent == NULL) | |
3554 | return NULL; | |
3555 | ||
3556 | if (parent->scope_set) | |
3557 | return parent->scope; | |
3558 | ||
3559 | fixup_partial_die (parent, cu); | |
3560 | ||
10b3939b | 3561 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3562 | |
acebe513 UW |
3563 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3564 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3565 | Work around this problem here. */ | |
3566 | if (cu->language == language_cplus | |
6e70227d | 3567 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3568 | && strcmp (parent->name, "::") == 0 |
3569 | && grandparent_scope == NULL) | |
3570 | { | |
3571 | parent->scope = NULL; | |
3572 | parent->scope_set = 1; | |
3573 | return NULL; | |
3574 | } | |
3575 | ||
72bf9492 | 3576 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3577 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3578 | || parent->tag == DW_TAG_structure_type |
3579 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3580 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3581 | || parent->tag == DW_TAG_union_type |
3582 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3583 | { |
3584 | if (grandparent_scope == NULL) | |
3585 | parent->scope = parent->name; | |
3586 | else | |
987504bb | 3587 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
f55ee35c | 3588 | parent->name, 0, cu); |
72bf9492 | 3589 | } |
ceeb3d5a | 3590 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3591 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3592 | parent->scope = grandparent_scope; | |
3593 | else | |
3594 | { | |
3595 | /* FIXME drow/2004-04-01: What should we be doing with | |
3596 | function-local names? For partial symbols, we should probably be | |
3597 | ignoring them. */ | |
3598 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3599 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3600 | parent->tag, pdi->offset); |
3601 | parent->scope = grandparent_scope; | |
c906108c SS |
3602 | } |
3603 | ||
72bf9492 DJ |
3604 | parent->scope_set = 1; |
3605 | return parent->scope; | |
3606 | } | |
3607 | ||
3608 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3609 | CU. The result will be allocated with malloc. */ | |
3610 | static char * | |
3611 | partial_die_full_name (struct partial_die_info *pdi, | |
3612 | struct dwarf2_cu *cu) | |
3613 | { | |
3614 | char *parent_scope; | |
3615 | ||
98bfdba5 PA |
3616 | /* If this is a template instantiation, we can not work out the |
3617 | template arguments from partial DIEs. So, unfortunately, we have | |
3618 | to go through the full DIEs. At least any work we do building | |
3619 | types here will be reused if full symbols are loaded later. */ | |
3620 | if (pdi->has_template_arguments) | |
3621 | { | |
3622 | fixup_partial_die (pdi, cu); | |
3623 | ||
3624 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3625 | { | |
3626 | struct die_info *die; | |
3627 | struct attribute attr; | |
3628 | struct dwarf2_cu *ref_cu = cu; | |
3629 | ||
3630 | attr.name = 0; | |
3631 | attr.form = DW_FORM_ref_addr; | |
3632 | attr.u.addr = pdi->offset; | |
3633 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3634 | ||
3635 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3636 | } | |
3637 | } | |
3638 | ||
72bf9492 DJ |
3639 | parent_scope = partial_die_parent_scope (pdi, cu); |
3640 | if (parent_scope == NULL) | |
3641 | return NULL; | |
3642 | else | |
f55ee35c | 3643 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3644 | } |
3645 | ||
3646 | static void | |
72bf9492 | 3647 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3648 | { |
e7c27a73 | 3649 | struct objfile *objfile = cu->objfile; |
c906108c | 3650 | CORE_ADDR addr = 0; |
decbce07 | 3651 | char *actual_name = NULL; |
5c4e30ca | 3652 | const struct partial_symbol *psym = NULL; |
e142c38c | 3653 | CORE_ADDR baseaddr; |
72bf9492 | 3654 | int built_actual_name = 0; |
e142c38c DJ |
3655 | |
3656 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3657 | |
94af9270 KS |
3658 | actual_name = partial_die_full_name (pdi, cu); |
3659 | if (actual_name) | |
3660 | built_actual_name = 1; | |
63d06c5c | 3661 | |
72bf9492 DJ |
3662 | if (actual_name == NULL) |
3663 | actual_name = pdi->name; | |
3664 | ||
c906108c SS |
3665 | switch (pdi->tag) |
3666 | { | |
3667 | case DW_TAG_subprogram: | |
2cfa0c8d | 3668 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3669 | { |
2cfa0c8d JB |
3670 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3671 | of the global scope. But in Ada, we want to be able to access | |
3672 | nested procedures globally. So all Ada subprograms are stored | |
3673 | in the global scope. */ | |
38d518c9 | 3674 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3675 | mst_text, objfile); */ |
38d518c9 | 3676 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3677 | built_actual_name, |
5c4e30ca DC |
3678 | VAR_DOMAIN, LOC_BLOCK, |
3679 | &objfile->global_psymbols, | |
3680 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3681 | cu->language, objfile); |
c906108c SS |
3682 | } |
3683 | else | |
3684 | { | |
38d518c9 | 3685 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3686 | mst_file_text, objfile); */ |
38d518c9 | 3687 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3688 | built_actual_name, |
5c4e30ca DC |
3689 | VAR_DOMAIN, LOC_BLOCK, |
3690 | &objfile->static_psymbols, | |
3691 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3692 | cu->language, objfile); |
c906108c SS |
3693 | } |
3694 | break; | |
3695 | case DW_TAG_variable: | |
caac4577 JG |
3696 | if (pdi->locdesc) |
3697 | addr = decode_locdesc (pdi->locdesc, cu); | |
3698 | ||
3699 | if (pdi->locdesc | |
3700 | && addr == 0 | |
3701 | && !dwarf2_per_objfile->has_section_at_zero) | |
3702 | { | |
3703 | /* A global or static variable may also have been stripped | |
3704 | out by the linker if unused, in which case its address | |
3705 | will be nullified; do not add such variables into partial | |
3706 | symbol table then. */ | |
3707 | } | |
3708 | else if (pdi->is_external) | |
c906108c SS |
3709 | { |
3710 | /* Global Variable. | |
3711 | Don't enter into the minimal symbol tables as there is | |
3712 | a minimal symbol table entry from the ELF symbols already. | |
3713 | Enter into partial symbol table if it has a location | |
3714 | descriptor or a type. | |
3715 | If the location descriptor is missing, new_symbol will create | |
3716 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3717 | be determined from the minimal symbol table whenever the variable | |
3718 | is referenced. | |
3719 | The address for the partial symbol table entry is not | |
3720 | used by GDB, but it comes in handy for debugging partial symbol | |
3721 | table building. */ | |
3722 | ||
c906108c | 3723 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 3724 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3725 | built_actual_name, |
5c4e30ca DC |
3726 | VAR_DOMAIN, LOC_STATIC, |
3727 | &objfile->global_psymbols, | |
3728 | 0, addr + baseaddr, | |
e142c38c | 3729 | cu->language, objfile); |
c906108c SS |
3730 | } |
3731 | else | |
3732 | { | |
3733 | /* Static Variable. Skip symbols without location descriptors. */ | |
3734 | if (pdi->locdesc == NULL) | |
decbce07 MS |
3735 | { |
3736 | if (built_actual_name) | |
3737 | xfree (actual_name); | |
3738 | return; | |
3739 | } | |
38d518c9 | 3740 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3741 | mst_file_data, objfile); */ |
38d518c9 | 3742 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3743 | built_actual_name, |
5c4e30ca DC |
3744 | VAR_DOMAIN, LOC_STATIC, |
3745 | &objfile->static_psymbols, | |
3746 | 0, addr + baseaddr, | |
e142c38c | 3747 | cu->language, objfile); |
c906108c SS |
3748 | } |
3749 | break; | |
3750 | case DW_TAG_typedef: | |
3751 | case DW_TAG_base_type: | |
a02abb62 | 3752 | case DW_TAG_subrange_type: |
38d518c9 | 3753 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3754 | built_actual_name, |
176620f1 | 3755 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3756 | &objfile->static_psymbols, |
e142c38c | 3757 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3758 | break; |
72bf9492 DJ |
3759 | case DW_TAG_namespace: |
3760 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 3761 | built_actual_name, |
72bf9492 DJ |
3762 | VAR_DOMAIN, LOC_TYPEDEF, |
3763 | &objfile->global_psymbols, | |
3764 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
3765 | break; | |
c906108c | 3766 | case DW_TAG_class_type: |
680b30c7 | 3767 | case DW_TAG_interface_type: |
c906108c SS |
3768 | case DW_TAG_structure_type: |
3769 | case DW_TAG_union_type: | |
3770 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
3771 | /* Skip external references. The DWARF standard says in the section |
3772 | about "Structure, Union, and Class Type Entries": "An incomplete | |
3773 | structure, union or class type is represented by a structure, | |
3774 | union or class entry that does not have a byte size attribute | |
3775 | and that has a DW_AT_declaration attribute." */ | |
3776 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
3777 | { |
3778 | if (built_actual_name) | |
3779 | xfree (actual_name); | |
3780 | return; | |
3781 | } | |
fa4028e9 | 3782 | |
63d06c5c DC |
3783 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
3784 | static vs. global. */ | |
38d518c9 | 3785 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3786 | built_actual_name, |
176620f1 | 3787 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
3788 | (cu->language == language_cplus |
3789 | || cu->language == language_java) | |
63d06c5c DC |
3790 | ? &objfile->global_psymbols |
3791 | : &objfile->static_psymbols, | |
e142c38c | 3792 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3793 | |
c906108c SS |
3794 | break; |
3795 | case DW_TAG_enumerator: | |
38d518c9 | 3796 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3797 | built_actual_name, |
176620f1 | 3798 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
3799 | (cu->language == language_cplus |
3800 | || cu->language == language_java) | |
f6fe98ef DJ |
3801 | ? &objfile->global_psymbols |
3802 | : &objfile->static_psymbols, | |
e142c38c | 3803 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
3804 | break; |
3805 | default: | |
3806 | break; | |
3807 | } | |
5c4e30ca | 3808 | |
72bf9492 DJ |
3809 | if (built_actual_name) |
3810 | xfree (actual_name); | |
c906108c SS |
3811 | } |
3812 | ||
5c4e30ca DC |
3813 | /* Read a partial die corresponding to a namespace; also, add a symbol |
3814 | corresponding to that namespace to the symbol table. NAMESPACE is | |
3815 | the name of the enclosing namespace. */ | |
91c24f0a | 3816 | |
72bf9492 DJ |
3817 | static void |
3818 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 3819 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 3820 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 3821 | { |
72bf9492 | 3822 | /* Add a symbol for the namespace. */ |
e7c27a73 | 3823 | |
72bf9492 | 3824 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
3825 | |
3826 | /* Now scan partial symbols in that namespace. */ | |
3827 | ||
91c24f0a | 3828 | if (pdi->has_children) |
5734ee8b | 3829 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
3830 | } |
3831 | ||
5d7cb8df JK |
3832 | /* Read a partial die corresponding to a Fortran module. */ |
3833 | ||
3834 | static void | |
3835 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
3836 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
3837 | { | |
f55ee35c | 3838 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
3839 | |
3840 | if (pdi->has_children) | |
3841 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
3842 | } | |
3843 | ||
bc30ff58 JB |
3844 | /* Read a partial die corresponding to a subprogram and create a partial |
3845 | symbol for that subprogram. When the CU language allows it, this | |
3846 | routine also defines a partial symbol for each nested subprogram | |
3847 | that this subprogram contains. | |
6e70227d | 3848 | |
bc30ff58 JB |
3849 | DIE my also be a lexical block, in which case we simply search |
3850 | recursively for suprograms defined inside that lexical block. | |
3851 | Again, this is only performed when the CU language allows this | |
3852 | type of definitions. */ | |
3853 | ||
3854 | static void | |
3855 | add_partial_subprogram (struct partial_die_info *pdi, | |
3856 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 3857 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
3858 | { |
3859 | if (pdi->tag == DW_TAG_subprogram) | |
3860 | { | |
3861 | if (pdi->has_pc_info) | |
3862 | { | |
3863 | if (pdi->lowpc < *lowpc) | |
3864 | *lowpc = pdi->lowpc; | |
3865 | if (pdi->highpc > *highpc) | |
3866 | *highpc = pdi->highpc; | |
5734ee8b DJ |
3867 | if (need_pc) |
3868 | { | |
3869 | CORE_ADDR baseaddr; | |
3870 | struct objfile *objfile = cu->objfile; | |
3871 | ||
3872 | baseaddr = ANOFFSET (objfile->section_offsets, | |
3873 | SECT_OFF_TEXT (objfile)); | |
3874 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
3875 | pdi->lowpc + baseaddr, |
3876 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 3877 | cu->per_cu->v.psymtab); |
5734ee8b | 3878 | } |
bc30ff58 | 3879 | if (!pdi->is_declaration) |
e8d05480 JB |
3880 | /* Ignore subprogram DIEs that do not have a name, they are |
3881 | illegal. Do not emit a complaint at this point, we will | |
3882 | do so when we convert this psymtab into a symtab. */ | |
3883 | if (pdi->name) | |
3884 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
3885 | } |
3886 | } | |
6e70227d | 3887 | |
bc30ff58 JB |
3888 | if (! pdi->has_children) |
3889 | return; | |
3890 | ||
3891 | if (cu->language == language_ada) | |
3892 | { | |
3893 | pdi = pdi->die_child; | |
3894 | while (pdi != NULL) | |
3895 | { | |
3896 | fixup_partial_die (pdi, cu); | |
3897 | if (pdi->tag == DW_TAG_subprogram | |
3898 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 3899 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
3900 | pdi = pdi->die_sibling; |
3901 | } | |
3902 | } | |
3903 | } | |
3904 | ||
72bf9492 DJ |
3905 | /* See if we can figure out if the class lives in a namespace. We do |
3906 | this by looking for a member function; its demangled name will | |
3907 | contain namespace info, if there is any. */ | |
63d06c5c | 3908 | |
72bf9492 DJ |
3909 | static void |
3910 | guess_structure_name (struct partial_die_info *struct_pdi, | |
3911 | struct dwarf2_cu *cu) | |
63d06c5c | 3912 | { |
987504bb JJ |
3913 | if ((cu->language == language_cplus |
3914 | || cu->language == language_java) | |
72bf9492 | 3915 | && cu->has_namespace_info == 0 |
63d06c5c DC |
3916 | && struct_pdi->has_children) |
3917 | { | |
63d06c5c DC |
3918 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
3919 | what template types look like, because the demangler | |
3920 | frequently doesn't give the same name as the debug info. We | |
3921 | could fix this by only using the demangled name to get the | |
134d01f1 | 3922 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 3923 | |
72bf9492 | 3924 | struct partial_die_info *real_pdi; |
5d51ca54 | 3925 | |
72bf9492 DJ |
3926 | /* If this DIE (this DIE's specification, if any) has a parent, then |
3927 | we should not do this. We'll prepend the parent's fully qualified | |
3928 | name when we create the partial symbol. */ | |
5d51ca54 | 3929 | |
72bf9492 | 3930 | real_pdi = struct_pdi; |
72bf9492 | 3931 | while (real_pdi->has_specification) |
10b3939b | 3932 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 3933 | |
72bf9492 DJ |
3934 | if (real_pdi->die_parent != NULL) |
3935 | return; | |
63d06c5c | 3936 | } |
63d06c5c DC |
3937 | } |
3938 | ||
91c24f0a DC |
3939 | /* Read a partial die corresponding to an enumeration type. */ |
3940 | ||
72bf9492 DJ |
3941 | static void |
3942 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
3943 | struct dwarf2_cu *cu) | |
91c24f0a | 3944 | { |
72bf9492 | 3945 | struct partial_die_info *pdi; |
91c24f0a DC |
3946 | |
3947 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
3948 | add_partial_symbol (enum_pdi, cu); |
3949 | ||
3950 | pdi = enum_pdi->die_child; | |
3951 | while (pdi) | |
91c24f0a | 3952 | { |
72bf9492 | 3953 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 3954 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 3955 | else |
72bf9492 DJ |
3956 | add_partial_symbol (pdi, cu); |
3957 | pdi = pdi->die_sibling; | |
91c24f0a | 3958 | } |
91c24f0a DC |
3959 | } |
3960 | ||
4bb7a0a7 DJ |
3961 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
3962 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
3963 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
3964 | the initial number. */ | |
3965 | ||
3966 | static struct abbrev_info * | |
fe1b8b76 | 3967 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 3968 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3969 | { |
3970 | bfd *abfd = cu->objfile->obfd; | |
3971 | unsigned int abbrev_number; | |
3972 | struct abbrev_info *abbrev; | |
3973 | ||
3974 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
3975 | ||
3976 | if (abbrev_number == 0) | |
3977 | return NULL; | |
3978 | ||
3979 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
3980 | if (!abbrev) | |
3981 | { | |
8a3fe4f8 | 3982 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
3983 | bfd_get_filename (abfd)); |
3984 | } | |
3985 | ||
3986 | return abbrev; | |
3987 | } | |
3988 | ||
93311388 DE |
3989 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3990 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
3991 | DIE. Any children of the skipped DIEs will also be skipped. */ |
3992 | ||
fe1b8b76 | 3993 | static gdb_byte * |
93311388 | 3994 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3995 | { |
3996 | struct abbrev_info *abbrev; | |
3997 | unsigned int bytes_read; | |
3998 | ||
3999 | while (1) | |
4000 | { | |
4001 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4002 | if (abbrev == NULL) | |
4003 | return info_ptr + bytes_read; | |
4004 | else | |
93311388 | 4005 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
4006 | } |
4007 | } | |
4008 | ||
93311388 DE |
4009 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4010 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4011 | abbrev corresponding to that skipped uleb128 should be passed in |
4012 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4013 | children. */ | |
4014 | ||
fe1b8b76 | 4015 | static gdb_byte * |
93311388 DE |
4016 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4017 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4018 | { |
4019 | unsigned int bytes_read; | |
4020 | struct attribute attr; | |
4021 | bfd *abfd = cu->objfile->obfd; | |
4022 | unsigned int form, i; | |
4023 | ||
4024 | for (i = 0; i < abbrev->num_attrs; i++) | |
4025 | { | |
4026 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4027 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4028 | { | |
4029 | read_attribute (&attr, &abbrev->attrs[i], | |
4030 | abfd, info_ptr, cu); | |
4031 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 4032 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 4033 | else |
93311388 | 4034 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4035 | } |
4036 | ||
4037 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4038 | form = abbrev->attrs[i].form; | |
4039 | skip_attribute: | |
4040 | switch (form) | |
4041 | { | |
4bb7a0a7 | 4042 | case DW_FORM_ref_addr: |
ae411497 TT |
4043 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4044 | and later it is offset sized. */ | |
4045 | if (cu->header.version == 2) | |
4046 | info_ptr += cu->header.addr_size; | |
4047 | else | |
4048 | info_ptr += cu->header.offset_size; | |
4049 | break; | |
4050 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4051 | info_ptr += cu->header.addr_size; |
4052 | break; | |
4053 | case DW_FORM_data1: | |
4054 | case DW_FORM_ref1: | |
4055 | case DW_FORM_flag: | |
4056 | info_ptr += 1; | |
4057 | break; | |
2dc7f7b3 TT |
4058 | case DW_FORM_flag_present: |
4059 | break; | |
4bb7a0a7 DJ |
4060 | case DW_FORM_data2: |
4061 | case DW_FORM_ref2: | |
4062 | info_ptr += 2; | |
4063 | break; | |
4064 | case DW_FORM_data4: | |
4065 | case DW_FORM_ref4: | |
4066 | info_ptr += 4; | |
4067 | break; | |
4068 | case DW_FORM_data8: | |
4069 | case DW_FORM_ref8: | |
348e048f | 4070 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
4071 | info_ptr += 8; |
4072 | break; | |
4073 | case DW_FORM_string: | |
9b1c24c8 | 4074 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4075 | info_ptr += bytes_read; |
4076 | break; | |
2dc7f7b3 | 4077 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4078 | case DW_FORM_strp: |
4079 | info_ptr += cu->header.offset_size; | |
4080 | break; | |
2dc7f7b3 | 4081 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4082 | case DW_FORM_block: |
4083 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4084 | info_ptr += bytes_read; | |
4085 | break; | |
4086 | case DW_FORM_block1: | |
4087 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4088 | break; | |
4089 | case DW_FORM_block2: | |
4090 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4091 | break; | |
4092 | case DW_FORM_block4: | |
4093 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4094 | break; | |
4095 | case DW_FORM_sdata: | |
4096 | case DW_FORM_udata: | |
4097 | case DW_FORM_ref_udata: | |
4098 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4099 | break; | |
4100 | case DW_FORM_indirect: | |
4101 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4102 | info_ptr += bytes_read; | |
4103 | /* We need to continue parsing from here, so just go back to | |
4104 | the top. */ | |
4105 | goto skip_attribute; | |
4106 | ||
4107 | default: | |
8a3fe4f8 | 4108 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
4109 | dwarf_form_name (form), |
4110 | bfd_get_filename (abfd)); | |
4111 | } | |
4112 | } | |
4113 | ||
4114 | if (abbrev->has_children) | |
93311388 | 4115 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4116 | else |
4117 | return info_ptr; | |
4118 | } | |
4119 | ||
93311388 DE |
4120 | /* Locate ORIG_PDI's sibling. |
4121 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4122 | in BUFFER. */ | |
91c24f0a | 4123 | |
fe1b8b76 | 4124 | static gdb_byte * |
93311388 DE |
4125 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4126 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4127 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4128 | { |
4129 | /* Do we know the sibling already? */ | |
72bf9492 | 4130 | |
91c24f0a DC |
4131 | if (orig_pdi->sibling) |
4132 | return orig_pdi->sibling; | |
4133 | ||
4134 | /* Are there any children to deal with? */ | |
4135 | ||
4136 | if (!orig_pdi->has_children) | |
4137 | return info_ptr; | |
4138 | ||
4bb7a0a7 | 4139 | /* Skip the children the long way. */ |
91c24f0a | 4140 | |
93311388 | 4141 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4142 | } |
4143 | ||
c906108c SS |
4144 | /* Expand this partial symbol table into a full symbol table. */ |
4145 | ||
4146 | static void | |
fba45db2 | 4147 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4148 | { |
c906108c SS |
4149 | if (pst != NULL) |
4150 | { | |
4151 | if (pst->readin) | |
4152 | { | |
8a3fe4f8 | 4153 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
4154 | } |
4155 | else | |
4156 | { | |
4157 | if (info_verbose) | |
4158 | { | |
a3f17187 | 4159 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
4160 | gdb_flush (gdb_stdout); |
4161 | } | |
4162 | ||
10b3939b DJ |
4163 | /* Restore our global data. */ |
4164 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4165 | dwarf2_objfile_data_key); | |
4166 | ||
b2ab525c KB |
4167 | /* If this psymtab is constructed from a debug-only objfile, the |
4168 | has_section_at_zero flag will not necessarily be correct. We | |
4169 | can get the correct value for this flag by looking at the data | |
4170 | associated with the (presumably stripped) associated objfile. */ | |
4171 | if (pst->objfile->separate_debug_objfile_backlink) | |
4172 | { | |
4173 | struct dwarf2_per_objfile *dpo_backlink | |
4174 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4175 | dwarf2_objfile_data_key); | |
9a619af0 | 4176 | |
b2ab525c KB |
4177 | dwarf2_per_objfile->has_section_at_zero |
4178 | = dpo_backlink->has_section_at_zero; | |
4179 | } | |
4180 | ||
98bfdba5 PA |
4181 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4182 | ||
c906108c SS |
4183 | psymtab_to_symtab_1 (pst); |
4184 | ||
4185 | /* Finish up the debug error message. */ | |
4186 | if (info_verbose) | |
a3f17187 | 4187 | printf_filtered (_("done.\n")); |
c906108c SS |
4188 | } |
4189 | } | |
4190 | } | |
4191 | ||
10b3939b DJ |
4192 | /* Add PER_CU to the queue. */ |
4193 | ||
4194 | static void | |
03dd20cc | 4195 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
4196 | { |
4197 | struct dwarf2_queue_item *item; | |
4198 | ||
4199 | per_cu->queued = 1; | |
4200 | item = xmalloc (sizeof (*item)); | |
4201 | item->per_cu = per_cu; | |
4202 | item->next = NULL; | |
4203 | ||
4204 | if (dwarf2_queue == NULL) | |
4205 | dwarf2_queue = item; | |
4206 | else | |
4207 | dwarf2_queue_tail->next = item; | |
4208 | ||
4209 | dwarf2_queue_tail = item; | |
4210 | } | |
4211 | ||
4212 | /* Process the queue. */ | |
4213 | ||
4214 | static void | |
4215 | process_queue (struct objfile *objfile) | |
4216 | { | |
4217 | struct dwarf2_queue_item *item, *next_item; | |
4218 | ||
03dd20cc DJ |
4219 | /* The queue starts out with one item, but following a DIE reference |
4220 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4221 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4222 | { | |
9291a0cd TT |
4223 | if (dwarf2_per_objfile->using_index |
4224 | ? !item->per_cu->v.quick->symtab | |
4225 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4226 | process_full_comp_unit (item->per_cu); |
4227 | ||
4228 | item->per_cu->queued = 0; | |
4229 | next_item = item->next; | |
4230 | xfree (item); | |
4231 | } | |
4232 | ||
4233 | dwarf2_queue_tail = NULL; | |
4234 | } | |
4235 | ||
4236 | /* Free all allocated queue entries. This function only releases anything if | |
4237 | an error was thrown; if the queue was processed then it would have been | |
4238 | freed as we went along. */ | |
4239 | ||
4240 | static void | |
4241 | dwarf2_release_queue (void *dummy) | |
4242 | { | |
4243 | struct dwarf2_queue_item *item, *last; | |
4244 | ||
4245 | item = dwarf2_queue; | |
4246 | while (item) | |
4247 | { | |
4248 | /* Anything still marked queued is likely to be in an | |
4249 | inconsistent state, so discard it. */ | |
4250 | if (item->per_cu->queued) | |
4251 | { | |
4252 | if (item->per_cu->cu != NULL) | |
4253 | free_one_cached_comp_unit (item->per_cu->cu); | |
4254 | item->per_cu->queued = 0; | |
4255 | } | |
4256 | ||
4257 | last = item; | |
4258 | item = item->next; | |
4259 | xfree (last); | |
4260 | } | |
4261 | ||
4262 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4263 | } | |
4264 | ||
4265 | /* Read in full symbols for PST, and anything it depends on. */ | |
4266 | ||
c906108c | 4267 | static void |
fba45db2 | 4268 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4269 | { |
10b3939b | 4270 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4271 | struct cleanup *back_to; |
aaa75496 JB |
4272 | int i; |
4273 | ||
4274 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4275 | if (!pst->dependencies[i]->readin) | |
4276 | { | |
4277 | /* Inform about additional files that need to be read in. */ | |
4278 | if (info_verbose) | |
4279 | { | |
a3f17187 | 4280 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4281 | fputs_filtered (" ", gdb_stdout); |
4282 | wrap_here (""); | |
4283 | fputs_filtered ("and ", gdb_stdout); | |
4284 | wrap_here (""); | |
4285 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
4286 | wrap_here (""); /* Flush output */ | |
4287 | gdb_flush (gdb_stdout); | |
4288 | } | |
4289 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4290 | } | |
4291 | ||
e38df1d0 | 4292 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4293 | |
4294 | if (per_cu == NULL) | |
aaa75496 JB |
4295 | { |
4296 | /* It's an include file, no symbols to read for it. | |
4297 | Everything is in the parent symtab. */ | |
4298 | pst->readin = 1; | |
4299 | return; | |
4300 | } | |
c906108c | 4301 | |
9291a0cd | 4302 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4303 | } |
4304 | ||
93311388 | 4305 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4306 | |
93311388 | 4307 | static void |
31ffec48 | 4308 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 4309 | { |
31ffec48 | 4310 | bfd *abfd = objfile->obfd; |
10b3939b | 4311 | struct dwarf2_cu *cu; |
c764a876 | 4312 | unsigned int offset; |
93311388 | 4313 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4314 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4315 | struct attribute *attr; |
98bfdba5 | 4316 | int read_cu = 0; |
6502dd73 | 4317 | |
348e048f DE |
4318 | gdb_assert (! per_cu->from_debug_types); |
4319 | ||
c906108c | 4320 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4321 | offset = per_cu->offset; |
6502dd73 | 4322 | |
be391dca | 4323 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4324 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4325 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4326 | |
98bfdba5 PA |
4327 | if (per_cu->cu == NULL) |
4328 | { | |
4329 | cu = alloc_one_comp_unit (objfile); | |
4330 | ||
4331 | read_cu = 1; | |
c906108c | 4332 | |
98bfdba5 PA |
4333 | /* If an error occurs while loading, release our storage. */ |
4334 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4335 | |
98bfdba5 PA |
4336 | /* Read in the comp_unit header. */ |
4337 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4338 | |
98bfdba5 PA |
4339 | /* Complete the cu_header. */ |
4340 | cu->header.offset = offset; | |
4341 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4342 | |
98bfdba5 PA |
4343 | /* Read the abbrevs for this compilation unit. */ |
4344 | dwarf2_read_abbrevs (abfd, cu); | |
4345 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10b3939b | 4346 | |
98bfdba5 PA |
4347 | /* Link this compilation unit into the compilation unit tree. */ |
4348 | per_cu->cu = cu; | |
4349 | cu->per_cu = per_cu; | |
98bfdba5 PA |
4350 | |
4351 | /* Link this CU into read_in_chain. */ | |
4352 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4353 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4354 | } | |
4355 | else | |
4356 | { | |
4357 | cu = per_cu->cu; | |
4358 | info_ptr += cu->header.first_die_offset; | |
4359 | } | |
e142c38c | 4360 | |
93311388 | 4361 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4362 | |
4363 | /* We try not to read any attributes in this function, because not | |
4364 | all objfiles needed for references have been loaded yet, and symbol | |
4365 | table processing isn't initialized. But we have to set the CU language, | |
4366 | or we won't be able to build types correctly. */ | |
4367 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
4368 | if (attr) | |
4369 | set_cu_language (DW_UNSND (attr), cu); | |
4370 | else | |
4371 | set_cu_language (language_minimal, cu); | |
4372 | ||
a6c727b2 DJ |
4373 | /* Similarly, if we do not read the producer, we can not apply |
4374 | producer-specific interpretation. */ | |
4375 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4376 | if (attr) | |
4377 | cu->producer = DW_STRING (attr); | |
4378 | ||
98bfdba5 PA |
4379 | if (read_cu) |
4380 | { | |
4381 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4382 | |
98bfdba5 PA |
4383 | /* We've successfully allocated this compilation unit. Let our |
4384 | caller clean it up when finished with it. */ | |
4385 | discard_cleanups (free_cu_cleanup); | |
4386 | } | |
10b3939b DJ |
4387 | } |
4388 | ||
3da10d80 KS |
4389 | /* Add a DIE to the delayed physname list. */ |
4390 | ||
4391 | static void | |
4392 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4393 | const char *name, struct die_info *die, | |
4394 | struct dwarf2_cu *cu) | |
4395 | { | |
4396 | struct delayed_method_info mi; | |
4397 | mi.type = type; | |
4398 | mi.fnfield_index = fnfield_index; | |
4399 | mi.index = index; | |
4400 | mi.name = name; | |
4401 | mi.die = die; | |
4402 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4403 | } | |
4404 | ||
4405 | /* A cleanup for freeing the delayed method list. */ | |
4406 | ||
4407 | static void | |
4408 | free_delayed_list (void *ptr) | |
4409 | { | |
4410 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4411 | if (cu->method_list != NULL) | |
4412 | { | |
4413 | VEC_free (delayed_method_info, cu->method_list); | |
4414 | cu->method_list = NULL; | |
4415 | } | |
4416 | } | |
4417 | ||
4418 | /* Compute the physnames of any methods on the CU's method list. | |
4419 | ||
4420 | The computation of method physnames is delayed in order to avoid the | |
4421 | (bad) condition that one of the method's formal parameters is of an as yet | |
4422 | incomplete type. */ | |
4423 | ||
4424 | static void | |
4425 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4426 | { | |
4427 | int i; | |
4428 | struct delayed_method_info *mi; | |
4429 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4430 | { | |
4431 | char *physname; | |
4432 | struct fn_fieldlist *fn_flp | |
4433 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
4434 | physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu); | |
4435 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; | |
4436 | } | |
4437 | } | |
4438 | ||
10b3939b DJ |
4439 | /* Generate full symbol information for PST and CU, whose DIEs have |
4440 | already been loaded into memory. */ | |
4441 | ||
4442 | static void | |
4443 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4444 | { | |
10b3939b | 4445 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4446 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4447 | CORE_ADDR lowpc, highpc; |
4448 | struct symtab *symtab; | |
3da10d80 | 4449 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4450 | CORE_ADDR baseaddr; |
4451 | ||
4452 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4453 | ||
10b3939b DJ |
4454 | buildsym_init (); |
4455 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4456 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4457 | |
4458 | cu->list_in_scope = &file_symbols; | |
c906108c | 4459 | |
d85a05f0 | 4460 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4461 | |
c906108c | 4462 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4463 | process_die (cu->dies, cu); |
c906108c | 4464 | |
3da10d80 KS |
4465 | /* Now that we have processed all the DIEs in the CU, all the types |
4466 | should be complete, and it should now be safe to compute all of the | |
4467 | physnames. */ | |
4468 | compute_delayed_physnames (cu); | |
4469 | do_cleanups (delayed_list_cleanup); | |
4470 | ||
fae299cd DC |
4471 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4472 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4473 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4474 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4475 | |
613e1657 | 4476 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
4477 | |
4478 | /* Set symtab language to language from DW_AT_language. | |
4479 | If the compilation is from a C file generated by language preprocessors, | |
4480 | do not set the language if it was already deduced by start_subfile. */ | |
4481 | if (symtab != NULL | |
10b3939b | 4482 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 4483 | { |
10b3939b | 4484 | symtab->language = cu->language; |
c906108c | 4485 | } |
9291a0cd TT |
4486 | |
4487 | if (dwarf2_per_objfile->using_index) | |
4488 | per_cu->v.quick->symtab = symtab; | |
4489 | else | |
4490 | { | |
4491 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4492 | pst->symtab = symtab; | |
4493 | pst->readin = 1; | |
4494 | } | |
c906108c SS |
4495 | |
4496 | do_cleanups (back_to); | |
4497 | } | |
4498 | ||
4499 | /* Process a die and its children. */ | |
4500 | ||
4501 | static void | |
e7c27a73 | 4502 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4503 | { |
4504 | switch (die->tag) | |
4505 | { | |
4506 | case DW_TAG_padding: | |
4507 | break; | |
4508 | case DW_TAG_compile_unit: | |
e7c27a73 | 4509 | read_file_scope (die, cu); |
c906108c | 4510 | break; |
348e048f DE |
4511 | case DW_TAG_type_unit: |
4512 | read_type_unit_scope (die, cu); | |
4513 | break; | |
c906108c | 4514 | case DW_TAG_subprogram: |
c906108c | 4515 | case DW_TAG_inlined_subroutine: |
edb3359d | 4516 | read_func_scope (die, cu); |
c906108c SS |
4517 | break; |
4518 | case DW_TAG_lexical_block: | |
14898363 L |
4519 | case DW_TAG_try_block: |
4520 | case DW_TAG_catch_block: | |
e7c27a73 | 4521 | read_lexical_block_scope (die, cu); |
c906108c SS |
4522 | break; |
4523 | case DW_TAG_class_type: | |
680b30c7 | 4524 | case DW_TAG_interface_type: |
c906108c SS |
4525 | case DW_TAG_structure_type: |
4526 | case DW_TAG_union_type: | |
134d01f1 | 4527 | process_structure_scope (die, cu); |
c906108c SS |
4528 | break; |
4529 | case DW_TAG_enumeration_type: | |
134d01f1 | 4530 | process_enumeration_scope (die, cu); |
c906108c | 4531 | break; |
134d01f1 | 4532 | |
f792889a DJ |
4533 | /* These dies have a type, but processing them does not create |
4534 | a symbol or recurse to process the children. Therefore we can | |
4535 | read them on-demand through read_type_die. */ | |
c906108c | 4536 | case DW_TAG_subroutine_type: |
72019c9c | 4537 | case DW_TAG_set_type: |
c906108c | 4538 | case DW_TAG_array_type: |
c906108c | 4539 | case DW_TAG_pointer_type: |
c906108c | 4540 | case DW_TAG_ptr_to_member_type: |
c906108c | 4541 | case DW_TAG_reference_type: |
c906108c | 4542 | case DW_TAG_string_type: |
c906108c | 4543 | break; |
134d01f1 | 4544 | |
c906108c | 4545 | case DW_TAG_base_type: |
a02abb62 | 4546 | case DW_TAG_subrange_type: |
cb249c71 | 4547 | case DW_TAG_typedef: |
134d01f1 DJ |
4548 | /* Add a typedef symbol for the type definition, if it has a |
4549 | DW_AT_name. */ | |
f792889a | 4550 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4551 | break; |
c906108c | 4552 | case DW_TAG_common_block: |
e7c27a73 | 4553 | read_common_block (die, cu); |
c906108c SS |
4554 | break; |
4555 | case DW_TAG_common_inclusion: | |
4556 | break; | |
d9fa45fe | 4557 | case DW_TAG_namespace: |
63d06c5c | 4558 | processing_has_namespace_info = 1; |
e7c27a73 | 4559 | read_namespace (die, cu); |
d9fa45fe | 4560 | break; |
5d7cb8df | 4561 | case DW_TAG_module: |
f55ee35c | 4562 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4563 | read_module (die, cu); |
4564 | break; | |
d9fa45fe DC |
4565 | case DW_TAG_imported_declaration: |
4566 | case DW_TAG_imported_module: | |
63d06c5c | 4567 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4568 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4569 | || cu->language != language_fortran)) | |
4570 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4571 | dwarf_tag_name (die->tag)); | |
4572 | read_import_statement (die, cu); | |
d9fa45fe | 4573 | break; |
c906108c | 4574 | default: |
e7c27a73 | 4575 | new_symbol (die, NULL, cu); |
c906108c SS |
4576 | break; |
4577 | } | |
4578 | } | |
4579 | ||
94af9270 KS |
4580 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4581 | needs to have the name of the scope prepended to the name listed in the | |
4582 | die. */ | |
4583 | ||
4584 | static int | |
4585 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4586 | { | |
1c809c68 TT |
4587 | struct attribute *attr; |
4588 | ||
94af9270 KS |
4589 | switch (die->tag) |
4590 | { | |
4591 | case DW_TAG_namespace: | |
4592 | case DW_TAG_typedef: | |
4593 | case DW_TAG_class_type: | |
4594 | case DW_TAG_interface_type: | |
4595 | case DW_TAG_structure_type: | |
4596 | case DW_TAG_union_type: | |
4597 | case DW_TAG_enumeration_type: | |
4598 | case DW_TAG_enumerator: | |
4599 | case DW_TAG_subprogram: | |
4600 | case DW_TAG_member: | |
4601 | return 1; | |
4602 | ||
4603 | case DW_TAG_variable: | |
4604 | /* We only need to prefix "globally" visible variables. These include | |
4605 | any variable marked with DW_AT_external or any variable that | |
4606 | lives in a namespace. [Variables in anonymous namespaces | |
4607 | require prefixing, but they are not DW_AT_external.] */ | |
4608 | ||
4609 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4610 | { | |
4611 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4612 | |
94af9270 KS |
4613 | return die_needs_namespace (die_specification (die, &spec_cu), |
4614 | spec_cu); | |
4615 | } | |
4616 | ||
1c809c68 | 4617 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4618 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4619 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4620 | return 0; |
4621 | /* A variable in a lexical block of some kind does not need a | |
4622 | namespace, even though in C++ such variables may be external | |
4623 | and have a mangled name. */ | |
4624 | if (die->parent->tag == DW_TAG_lexical_block | |
4625 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4626 | || die->parent->tag == DW_TAG_catch_block |
4627 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4628 | return 0; |
4629 | return 1; | |
94af9270 KS |
4630 | |
4631 | default: | |
4632 | return 0; | |
4633 | } | |
4634 | } | |
4635 | ||
98bfdba5 PA |
4636 | /* Retrieve the last character from a mem_file. */ |
4637 | ||
4638 | static void | |
4639 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4640 | { | |
4641 | char *last_char_p = (char *) object; | |
4642 | ||
4643 | if (length > 0) | |
4644 | *last_char_p = buffer[length - 1]; | |
4645 | } | |
4646 | ||
94af9270 KS |
4647 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4648 | compute the physname for the object, which include a method's | |
4649 | formal parameters (C++/Java) and return type (Java). | |
4650 | ||
af6b7be1 JB |
4651 | For Ada, return the DIE's linkage name rather than the fully qualified |
4652 | name. PHYSNAME is ignored.. | |
4653 | ||
94af9270 KS |
4654 | The result is allocated on the objfile_obstack and canonicalized. */ |
4655 | ||
4656 | static const char * | |
4657 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4658 | int physname) | |
4659 | { | |
4660 | if (name == NULL) | |
4661 | name = dwarf2_name (die, cu); | |
4662 | ||
f55ee35c JK |
4663 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4664 | compute it by typename_concat inside GDB. */ | |
4665 | if (cu->language == language_ada | |
4666 | || (cu->language == language_fortran && physname)) | |
4667 | { | |
4668 | /* For Ada unit, we prefer the linkage name over the name, as | |
4669 | the former contains the exported name, which the user expects | |
4670 | to be able to reference. Ideally, we want the user to be able | |
4671 | to reference this entity using either natural or linkage name, | |
4672 | but we haven't started looking at this enhancement yet. */ | |
4673 | struct attribute *attr; | |
4674 | ||
4675 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4676 | if (attr == NULL) | |
4677 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4678 | if (attr && DW_STRING (attr)) | |
4679 | return DW_STRING (attr); | |
4680 | } | |
4681 | ||
94af9270 KS |
4682 | /* These are the only languages we know how to qualify names in. */ |
4683 | if (name != NULL | |
f55ee35c JK |
4684 | && (cu->language == language_cplus || cu->language == language_java |
4685 | || cu->language == language_fortran)) | |
94af9270 KS |
4686 | { |
4687 | if (die_needs_namespace (die, cu)) | |
4688 | { | |
4689 | long length; | |
4690 | char *prefix; | |
4691 | struct ui_file *buf; | |
4692 | ||
4693 | prefix = determine_prefix (die, cu); | |
4694 | buf = mem_fileopen (); | |
4695 | if (*prefix != '\0') | |
4696 | { | |
f55ee35c JK |
4697 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4698 | physname, cu); | |
9a619af0 | 4699 | |
94af9270 KS |
4700 | fputs_unfiltered (prefixed_name, buf); |
4701 | xfree (prefixed_name); | |
4702 | } | |
4703 | else | |
4704 | fputs_unfiltered (name ? name : "", buf); | |
4705 | ||
98bfdba5 PA |
4706 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
4707 | as children with DW_TAG_template_type_param or | |
4708 | DW_TAG_value_type_param. If the latter, add them to the name | |
4709 | here. If the name already has template parameters, then | |
4710 | skip this step; some versions of GCC emit both, and | |
4711 | it is more efficient to use the pre-computed name. | |
4712 | ||
4713 | Something to keep in mind about this process: it is very | |
4714 | unlikely, or in some cases downright impossible, to produce | |
4715 | something that will match the mangled name of a function. | |
4716 | If the definition of the function has the same debug info, | |
4717 | we should be able to match up with it anyway. But fallbacks | |
4718 | using the minimal symbol, for instance to find a method | |
4719 | implemented in a stripped copy of libstdc++, will not work. | |
4720 | If we do not have debug info for the definition, we will have to | |
4721 | match them up some other way. | |
4722 | ||
4723 | When we do name matching there is a related problem with function | |
4724 | templates; two instantiated function templates are allowed to | |
4725 | differ only by their return types, which we do not add here. */ | |
4726 | ||
4727 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
4728 | { | |
4729 | struct attribute *attr; | |
4730 | struct die_info *child; | |
4731 | int first = 1; | |
4732 | ||
4733 | die->building_fullname = 1; | |
4734 | ||
4735 | for (child = die->child; child != NULL; child = child->sibling) | |
4736 | { | |
4737 | struct type *type; | |
4738 | long value; | |
4739 | gdb_byte *bytes; | |
4740 | struct dwarf2_locexpr_baton *baton; | |
4741 | struct value *v; | |
4742 | ||
4743 | if (child->tag != DW_TAG_template_type_param | |
4744 | && child->tag != DW_TAG_template_value_param) | |
4745 | continue; | |
4746 | ||
4747 | if (first) | |
4748 | { | |
4749 | fputs_unfiltered ("<", buf); | |
4750 | first = 0; | |
4751 | } | |
4752 | else | |
4753 | fputs_unfiltered (", ", buf); | |
4754 | ||
4755 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
4756 | if (attr == NULL) | |
4757 | { | |
4758 | complaint (&symfile_complaints, | |
4759 | _("template parameter missing DW_AT_type")); | |
4760 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
4761 | continue; | |
4762 | } | |
4763 | type = die_type (child, cu); | |
4764 | ||
4765 | if (child->tag == DW_TAG_template_type_param) | |
4766 | { | |
4767 | c_print_type (type, "", buf, -1, 0); | |
4768 | continue; | |
4769 | } | |
4770 | ||
4771 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
4772 | if (attr == NULL) | |
4773 | { | |
4774 | complaint (&symfile_complaints, | |
4775 | _("template parameter missing DW_AT_const_value")); | |
4776 | fputs_unfiltered ("UNKNOWN_VALUE", buf); | |
4777 | continue; | |
4778 | } | |
4779 | ||
4780 | dwarf2_const_value_attr (attr, type, name, | |
4781 | &cu->comp_unit_obstack, cu, | |
4782 | &value, &bytes, &baton); | |
4783 | ||
4784 | if (TYPE_NOSIGN (type)) | |
4785 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
4786 | changed, this can use value_print instead. */ | |
4787 | c_printchar (value, type, buf); | |
4788 | else | |
4789 | { | |
4790 | struct value_print_options opts; | |
4791 | ||
4792 | if (baton != NULL) | |
4793 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
4794 | baton->data, | |
4795 | baton->size, | |
4796 | baton->per_cu); | |
4797 | else if (bytes != NULL) | |
4798 | { | |
4799 | v = allocate_value (type); | |
4800 | memcpy (value_contents_writeable (v), bytes, | |
4801 | TYPE_LENGTH (type)); | |
4802 | } | |
4803 | else | |
4804 | v = value_from_longest (type, value); | |
4805 | ||
4806 | /* Specify decimal so that we do not depend on the radix. */ | |
4807 | get_formatted_print_options (&opts, 'd'); | |
4808 | opts.raw = 1; | |
4809 | value_print (v, buf, &opts); | |
4810 | release_value (v); | |
4811 | value_free (v); | |
4812 | } | |
4813 | } | |
4814 | ||
4815 | die->building_fullname = 0; | |
4816 | ||
4817 | if (!first) | |
4818 | { | |
4819 | /* Close the argument list, with a space if necessary | |
4820 | (nested templates). */ | |
4821 | char last_char = '\0'; | |
4822 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
4823 | if (last_char == '>') | |
4824 | fputs_unfiltered (" >", buf); | |
4825 | else | |
4826 | fputs_unfiltered (">", buf); | |
4827 | } | |
4828 | } | |
4829 | ||
94af9270 KS |
4830 | /* For Java and C++ methods, append formal parameter type |
4831 | information, if PHYSNAME. */ | |
6e70227d | 4832 | |
94af9270 KS |
4833 | if (physname && die->tag == DW_TAG_subprogram |
4834 | && (cu->language == language_cplus | |
4835 | || cu->language == language_java)) | |
4836 | { | |
4837 | struct type *type = read_type_die (die, cu); | |
4838 | ||
4839 | c_type_print_args (type, buf, 0, cu->language); | |
4840 | ||
4841 | if (cu->language == language_java) | |
4842 | { | |
4843 | /* For java, we must append the return type to method | |
4844 | names. */ | |
4845 | if (die->tag == DW_TAG_subprogram) | |
4846 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
4847 | 0, 0); | |
4848 | } | |
4849 | else if (cu->language == language_cplus) | |
4850 | { | |
60430eff DJ |
4851 | /* Assume that an artificial first parameter is |
4852 | "this", but do not crash if it is not. RealView | |
4853 | marks unnamed (and thus unused) parameters as | |
4854 | artificial; there is no way to differentiate | |
4855 | the two cases. */ | |
94af9270 KS |
4856 | if (TYPE_NFIELDS (type) > 0 |
4857 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
60430eff | 4858 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
94af9270 KS |
4859 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) |
4860 | fputs_unfiltered (" const", buf); | |
4861 | } | |
4862 | } | |
4863 | ||
4864 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
4865 | &length); | |
4866 | ui_file_delete (buf); | |
4867 | ||
4868 | if (cu->language == language_cplus) | |
4869 | { | |
4870 | char *cname | |
4871 | = dwarf2_canonicalize_name (name, cu, | |
4872 | &cu->objfile->objfile_obstack); | |
9a619af0 | 4873 | |
94af9270 KS |
4874 | if (cname != NULL) |
4875 | name = cname; | |
4876 | } | |
4877 | } | |
4878 | } | |
4879 | ||
4880 | return name; | |
4881 | } | |
4882 | ||
0114d602 DJ |
4883 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
4884 | If scope qualifiers are appropriate they will be added. The result | |
4885 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
4886 | not have a name. NAME may either be from a previous call to |
4887 | dwarf2_name or NULL. | |
4888 | ||
4889 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
4890 | |
4891 | static const char * | |
94af9270 | 4892 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 4893 | { |
94af9270 KS |
4894 | return dwarf2_compute_name (name, die, cu, 0); |
4895 | } | |
0114d602 | 4896 | |
94af9270 KS |
4897 | /* Construct a physname for the given DIE in CU. NAME may either be |
4898 | from a previous call to dwarf2_name or NULL. The result will be | |
4899 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
4900 | name. | |
0114d602 | 4901 | |
94af9270 | 4902 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 4903 | |
94af9270 KS |
4904 | static const char * |
4905 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
4906 | { | |
4907 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
4908 | } |
4909 | ||
27aa8d6a SW |
4910 | /* Read the import statement specified by the given die and record it. */ |
4911 | ||
4912 | static void | |
4913 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
4914 | { | |
4915 | struct attribute *import_attr; | |
4916 | struct die_info *imported_die; | |
de4affc9 | 4917 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 4918 | const char *imported_name; |
794684b6 | 4919 | const char *imported_name_prefix; |
13387711 SW |
4920 | const char *canonical_name; |
4921 | const char *import_alias; | |
4922 | const char *imported_declaration = NULL; | |
794684b6 | 4923 | const char *import_prefix; |
13387711 SW |
4924 | |
4925 | char *temp; | |
27aa8d6a SW |
4926 | |
4927 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
4928 | if (import_attr == NULL) | |
4929 | { | |
4930 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
4931 | dwarf_tag_name (die->tag)); | |
4932 | return; | |
4933 | } | |
4934 | ||
de4affc9 CC |
4935 | imported_cu = cu; |
4936 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
4937 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
4938 | if (imported_name == NULL) |
4939 | { | |
4940 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
4941 | ||
4942 | The import in the following code: | |
4943 | namespace A | |
4944 | { | |
4945 | typedef int B; | |
4946 | } | |
4947 | ||
4948 | int main () | |
4949 | { | |
4950 | using A::B; | |
4951 | B b; | |
4952 | return b; | |
4953 | } | |
4954 | ||
4955 | ... | |
4956 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
4957 | <52> DW_AT_decl_file : 1 | |
4958 | <53> DW_AT_decl_line : 6 | |
4959 | <54> DW_AT_import : <0x75> | |
4960 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
4961 | <59> DW_AT_name : B | |
4962 | <5b> DW_AT_decl_file : 1 | |
4963 | <5c> DW_AT_decl_line : 2 | |
4964 | <5d> DW_AT_type : <0x6e> | |
4965 | ... | |
4966 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
4967 | <76> DW_AT_byte_size : 4 | |
4968 | <77> DW_AT_encoding : 5 (signed) | |
4969 | ||
4970 | imports the wrong die ( 0x75 instead of 0x58 ). | |
4971 | This case will be ignored until the gcc bug is fixed. */ | |
4972 | return; | |
4973 | } | |
4974 | ||
82856980 SW |
4975 | /* Figure out the local name after import. */ |
4976 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 4977 | |
794684b6 SW |
4978 | /* Figure out where the statement is being imported to. */ |
4979 | import_prefix = determine_prefix (die, cu); | |
4980 | ||
4981 | /* Figure out what the scope of the imported die is and prepend it | |
4982 | to the name of the imported die. */ | |
de4affc9 | 4983 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 4984 | |
f55ee35c JK |
4985 | if (imported_die->tag != DW_TAG_namespace |
4986 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 4987 | { |
13387711 SW |
4988 | imported_declaration = imported_name; |
4989 | canonical_name = imported_name_prefix; | |
794684b6 | 4990 | } |
13387711 | 4991 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 4992 | { |
13387711 SW |
4993 | temp = alloca (strlen (imported_name_prefix) |
4994 | + 2 + strlen (imported_name) + 1); | |
4995 | strcpy (temp, imported_name_prefix); | |
4996 | strcat (temp, "::"); | |
4997 | strcat (temp, imported_name); | |
4998 | canonical_name = temp; | |
794684b6 | 4999 | } |
13387711 SW |
5000 | else |
5001 | canonical_name = imported_name; | |
794684b6 | 5002 | |
c0cc3a76 SW |
5003 | cp_add_using_directive (import_prefix, |
5004 | canonical_name, | |
5005 | import_alias, | |
13387711 | 5006 | imported_declaration, |
c0cc3a76 | 5007 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
5008 | } |
5009 | ||
5fb290d7 | 5010 | static void |
e142c38c | 5011 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 5012 | { |
e142c38c | 5013 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
5014 | } |
5015 | ||
cb1df416 DJ |
5016 | static void |
5017 | free_cu_line_header (void *arg) | |
5018 | { | |
5019 | struct dwarf2_cu *cu = arg; | |
5020 | ||
5021 | free_line_header (cu->line_header); | |
5022 | cu->line_header = NULL; | |
5023 | } | |
5024 | ||
9291a0cd TT |
5025 | static void |
5026 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5027 | char **name, char **comp_dir) | |
5028 | { | |
5029 | struct attribute *attr; | |
5030 | ||
5031 | *name = NULL; | |
5032 | *comp_dir = NULL; | |
5033 | ||
5034 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5035 | is not a source language identifier. */ | |
5036 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5037 | if (attr) | |
5038 | { | |
5039 | *name = DW_STRING (attr); | |
5040 | } | |
5041 | ||
5042 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5043 | if (attr) | |
5044 | *comp_dir = DW_STRING (attr); | |
5045 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5046 | { | |
5047 | *comp_dir = ldirname (*name); | |
5048 | if (*comp_dir != NULL) | |
5049 | make_cleanup (xfree, *comp_dir); | |
5050 | } | |
5051 | if (*comp_dir != NULL) | |
5052 | { | |
5053 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5054 | directory, get rid of it. */ | |
5055 | char *cp = strchr (*comp_dir, ':'); | |
5056 | ||
5057 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5058 | *comp_dir = cp + 1; | |
5059 | } | |
5060 | ||
5061 | if (*name == NULL) | |
5062 | *name = "<unknown>"; | |
5063 | } | |
5064 | ||
c906108c | 5065 | static void |
e7c27a73 | 5066 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5067 | { |
e7c27a73 | 5068 | struct objfile *objfile = cu->objfile; |
debd256d | 5069 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5070 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5071 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5072 | struct attribute *attr; | |
e1024ff1 | 5073 | char *name = NULL; |
c906108c SS |
5074 | char *comp_dir = NULL; |
5075 | struct die_info *child_die; | |
5076 | bfd *abfd = objfile->obfd; | |
debd256d | 5077 | struct line_header *line_header = 0; |
e142c38c | 5078 | CORE_ADDR baseaddr; |
6e70227d | 5079 | |
e142c38c | 5080 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5081 | |
fae299cd | 5082 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5083 | |
5084 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5085 | from finish_block. */ | |
2acceee2 | 5086 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5087 | lowpc = highpc; |
5088 | lowpc += baseaddr; | |
5089 | highpc += baseaddr; | |
5090 | ||
9291a0cd | 5091 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5092 | |
e142c38c | 5093 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5094 | if (attr) |
5095 | { | |
e142c38c | 5096 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5097 | } |
5098 | ||
b0f35d58 | 5099 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5100 | if (attr) |
b0f35d58 | 5101 | cu->producer = DW_STRING (attr); |
303b6f5d | 5102 | |
c906108c SS |
5103 | /* We assume that we're processing GCC output. */ |
5104 | processing_gcc_compilation = 2; | |
c906108c | 5105 | |
df8a16a1 DJ |
5106 | processing_has_namespace_info = 0; |
5107 | ||
c906108c SS |
5108 | start_symtab (name, comp_dir, lowpc); |
5109 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5110 | record_producer (cu->producer); |
c906108c | 5111 | |
e142c38c | 5112 | initialize_cu_func_list (cu); |
c906108c | 5113 | |
cb1df416 DJ |
5114 | /* Decode line number information if present. We do this before |
5115 | processing child DIEs, so that the line header table is available | |
5116 | for DW_AT_decl_file. */ | |
e142c38c | 5117 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
5118 | if (attr) |
5119 | { | |
debd256d | 5120 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 5121 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
5122 | if (line_header) |
5123 | { | |
cb1df416 DJ |
5124 | cu->line_header = line_header; |
5125 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 5126 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 5127 | } |
5fb290d7 | 5128 | } |
debd256d | 5129 | |
cb1df416 DJ |
5130 | /* Process all dies in compilation unit. */ |
5131 | if (die->child != NULL) | |
5132 | { | |
5133 | child_die = die->child; | |
5134 | while (child_die && child_die->tag) | |
5135 | { | |
5136 | process_die (child_die, cu); | |
5137 | child_die = sibling_die (child_die); | |
5138 | } | |
5139 | } | |
5140 | ||
2e276125 JB |
5141 | /* Decode macro information, if present. Dwarf 2 macro information |
5142 | refers to information in the line number info statement program | |
5143 | header, so we can only read it if we've read the header | |
5144 | successfully. */ | |
e142c38c | 5145 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 5146 | if (attr && line_header) |
2e276125 JB |
5147 | { |
5148 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5149 | |
2e276125 | 5150 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 5151 | comp_dir, abfd, cu); |
2e276125 | 5152 | } |
debd256d | 5153 | do_cleanups (back_to); |
5fb290d7 DJ |
5154 | } |
5155 | ||
348e048f DE |
5156 | /* For TUs we want to skip the first top level sibling if it's not the |
5157 | actual type being defined by this TU. In this case the first top | |
5158 | level sibling is there to provide context only. */ | |
5159 | ||
5160 | static void | |
5161 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5162 | { | |
5163 | struct objfile *objfile = cu->objfile; | |
5164 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5165 | CORE_ADDR lowpc; | |
5166 | struct attribute *attr; | |
5167 | char *name = NULL; | |
5168 | char *comp_dir = NULL; | |
5169 | struct die_info *child_die; | |
5170 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5171 | |
5172 | /* start_symtab needs a low pc, but we don't really have one. | |
5173 | Do what read_file_scope would do in the absence of such info. */ | |
5174 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5175 | ||
5176 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5177 | is not a source language identifier. */ | |
5178 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5179 | if (attr) | |
5180 | name = DW_STRING (attr); | |
5181 | ||
5182 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5183 | if (attr) | |
5184 | comp_dir = DW_STRING (attr); | |
5185 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5186 | { | |
5187 | comp_dir = ldirname (name); | |
5188 | if (comp_dir != NULL) | |
5189 | make_cleanup (xfree, comp_dir); | |
5190 | } | |
5191 | ||
5192 | if (name == NULL) | |
5193 | name = "<unknown>"; | |
5194 | ||
5195 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5196 | if (attr) | |
5197 | set_cu_language (DW_UNSND (attr), cu); | |
5198 | ||
5199 | /* This isn't technically needed today. It is done for symmetry | |
5200 | with read_file_scope. */ | |
5201 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5202 | if (attr) |
348e048f DE |
5203 | cu->producer = DW_STRING (attr); |
5204 | ||
5205 | /* We assume that we're processing GCC output. */ | |
5206 | processing_gcc_compilation = 2; | |
5207 | ||
5208 | processing_has_namespace_info = 0; | |
5209 | ||
5210 | start_symtab (name, comp_dir, lowpc); | |
5211 | record_debugformat ("DWARF 2"); | |
5212 | record_producer (cu->producer); | |
5213 | ||
5214 | /* Process the dies in the type unit. */ | |
5215 | if (die->child == NULL) | |
5216 | { | |
5217 | dump_die_for_error (die); | |
5218 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5219 | bfd_get_filename (abfd)); | |
5220 | } | |
5221 | ||
5222 | child_die = die->child; | |
5223 | ||
5224 | while (child_die && child_die->tag) | |
5225 | { | |
5226 | process_die (child_die, cu); | |
5227 | ||
5228 | child_die = sibling_die (child_die); | |
5229 | } | |
5230 | ||
5231 | do_cleanups (back_to); | |
5232 | } | |
5233 | ||
5fb290d7 | 5234 | static void |
e142c38c DJ |
5235 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
5236 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
5237 | { |
5238 | struct function_range *thisfn; | |
5239 | ||
5240 | thisfn = (struct function_range *) | |
7b5a2f43 | 5241 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
5242 | thisfn->name = name; |
5243 | thisfn->lowpc = lowpc; | |
5244 | thisfn->highpc = highpc; | |
5245 | thisfn->seen_line = 0; | |
5246 | thisfn->next = NULL; | |
5247 | ||
e142c38c DJ |
5248 | if (cu->last_fn == NULL) |
5249 | cu->first_fn = thisfn; | |
5fb290d7 | 5250 | else |
e142c38c | 5251 | cu->last_fn->next = thisfn; |
5fb290d7 | 5252 | |
e142c38c | 5253 | cu->last_fn = thisfn; |
c906108c SS |
5254 | } |
5255 | ||
d389af10 JK |
5256 | /* qsort helper for inherit_abstract_dies. */ |
5257 | ||
5258 | static int | |
5259 | unsigned_int_compar (const void *ap, const void *bp) | |
5260 | { | |
5261 | unsigned int a = *(unsigned int *) ap; | |
5262 | unsigned int b = *(unsigned int *) bp; | |
5263 | ||
5264 | return (a > b) - (b > a); | |
5265 | } | |
5266 | ||
5267 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
5268 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
5269 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
5270 | ||
5271 | static void | |
5272 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5273 | { | |
5274 | struct die_info *child_die; | |
5275 | unsigned die_children_count; | |
5276 | /* CU offsets which were referenced by children of the current DIE. */ | |
5277 | unsigned *offsets; | |
5278 | unsigned *offsets_end, *offsetp; | |
5279 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5280 | struct die_info *origin_die; | |
5281 | /* Iterator of the ORIGIN_DIE children. */ | |
5282 | struct die_info *origin_child_die; | |
5283 | struct cleanup *cleanups; | |
5284 | struct attribute *attr; | |
cd02d79d PA |
5285 | struct dwarf2_cu *origin_cu; |
5286 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5287 | |
5288 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5289 | if (!attr) | |
5290 | return; | |
5291 | ||
cd02d79d PA |
5292 | /* Note that following die references may follow to a die in a |
5293 | different cu. */ | |
5294 | ||
5295 | origin_cu = cu; | |
5296 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5297 | ||
5298 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5299 | symbols in. */ | |
5300 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5301 | origin_cu->list_in_scope = cu->list_in_scope; | |
5302 | ||
edb3359d DJ |
5303 | if (die->tag != origin_die->tag |
5304 | && !(die->tag == DW_TAG_inlined_subroutine | |
5305 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5306 | complaint (&symfile_complaints, |
5307 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5308 | die->offset, origin_die->offset); | |
5309 | ||
5310 | child_die = die->child; | |
5311 | die_children_count = 0; | |
5312 | while (child_die && child_die->tag) | |
5313 | { | |
5314 | child_die = sibling_die (child_die); | |
5315 | die_children_count++; | |
5316 | } | |
5317 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5318 | cleanups = make_cleanup (xfree, offsets); | |
5319 | ||
5320 | offsets_end = offsets; | |
5321 | child_die = die->child; | |
5322 | while (child_die && child_die->tag) | |
5323 | { | |
c38f313d DJ |
5324 | /* For each CHILD_DIE, find the corresponding child of |
5325 | ORIGIN_DIE. If there is more than one layer of | |
5326 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5327 | but GCC versions at least through 4.4 generate this (GCC PR | |
5328 | 40573). */ | |
5329 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5330 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5331 | |
c38f313d DJ |
5332 | while (1) |
5333 | { | |
cd02d79d PA |
5334 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5335 | child_origin_cu); | |
c38f313d DJ |
5336 | if (attr == NULL) |
5337 | break; | |
cd02d79d PA |
5338 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5339 | &child_origin_cu); | |
c38f313d DJ |
5340 | } |
5341 | ||
d389af10 JK |
5342 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5343 | counterpart may exist. */ | |
c38f313d | 5344 | if (child_origin_die != child_die) |
d389af10 | 5345 | { |
edb3359d DJ |
5346 | if (child_die->tag != child_origin_die->tag |
5347 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5348 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5349 | complaint (&symfile_complaints, |
5350 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5351 | "different tags"), child_die->offset, | |
5352 | child_origin_die->offset); | |
c38f313d DJ |
5353 | if (child_origin_die->parent != origin_die) |
5354 | complaint (&symfile_complaints, | |
5355 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5356 | "different parents"), child_die->offset, | |
5357 | child_origin_die->offset); | |
5358 | else | |
5359 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5360 | } |
5361 | child_die = sibling_die (child_die); | |
5362 | } | |
5363 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5364 | unsigned_int_compar); | |
5365 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5366 | if (offsetp[-1] == *offsetp) | |
5367 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
5368 | "to DIE 0x%x as their abstract origin"), | |
5369 | die->offset, *offsetp); | |
5370 | ||
5371 | offsetp = offsets; | |
5372 | origin_child_die = origin_die->child; | |
5373 | while (origin_child_die && origin_child_die->tag) | |
5374 | { | |
5375 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5376 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5377 | offsetp++; | |
5378 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5379 | { | |
5380 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5381 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5382 | } |
5383 | origin_child_die = sibling_die (origin_child_die); | |
5384 | } | |
cd02d79d | 5385 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5386 | |
5387 | do_cleanups (cleanups); | |
5388 | } | |
5389 | ||
c906108c | 5390 | static void |
e7c27a73 | 5391 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5392 | { |
e7c27a73 | 5393 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5394 | struct context_stack *new; |
c906108c SS |
5395 | CORE_ADDR lowpc; |
5396 | CORE_ADDR highpc; | |
5397 | struct die_info *child_die; | |
edb3359d | 5398 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5399 | char *name; |
e142c38c | 5400 | CORE_ADDR baseaddr; |
801e3a5b | 5401 | struct block *block; |
edb3359d | 5402 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5403 | VEC (symbolp) *template_args = NULL; |
5404 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5405 | |
5406 | if (inlined_func) | |
5407 | { | |
5408 | /* If we do not have call site information, we can't show the | |
5409 | caller of this inlined function. That's too confusing, so | |
5410 | only use the scope for local variables. */ | |
5411 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5412 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5413 | if (call_line == NULL || call_file == NULL) | |
5414 | { | |
5415 | read_lexical_block_scope (die, cu); | |
5416 | return; | |
5417 | } | |
5418 | } | |
c906108c | 5419 | |
e142c38c DJ |
5420 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5421 | ||
94af9270 | 5422 | name = dwarf2_name (die, cu); |
c906108c | 5423 | |
e8d05480 JB |
5424 | /* Ignore functions with missing or empty names. These are actually |
5425 | illegal according to the DWARF standard. */ | |
5426 | if (name == NULL) | |
5427 | { | |
5428 | complaint (&symfile_complaints, | |
5429 | _("missing name for subprogram DIE at %d"), die->offset); | |
5430 | return; | |
5431 | } | |
5432 | ||
5433 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5434 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5435 | { | |
ae4d0c03 PM |
5436 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5437 | if (!attr || !DW_UNSND (attr)) | |
5438 | complaint (&symfile_complaints, | |
5439 | _("cannot get low and high bounds for subprogram DIE at %d"), | |
5440 | die->offset); | |
e8d05480 JB |
5441 | return; |
5442 | } | |
c906108c SS |
5443 | |
5444 | lowpc += baseaddr; | |
5445 | highpc += baseaddr; | |
5446 | ||
5fb290d7 | 5447 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 5448 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 5449 | |
34eaf542 TT |
5450 | /* If we have any template arguments, then we must allocate a |
5451 | different sort of symbol. */ | |
5452 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5453 | { | |
5454 | if (child_die->tag == DW_TAG_template_type_param | |
5455 | || child_die->tag == DW_TAG_template_value_param) | |
5456 | { | |
5457 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5458 | struct template_symbol); | |
5459 | templ_func->base.is_cplus_template_function = 1; | |
5460 | break; | |
5461 | } | |
5462 | } | |
5463 | ||
c906108c | 5464 | new = push_context (0, lowpc); |
34eaf542 TT |
5465 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5466 | (struct symbol *) templ_func); | |
4c2df51b | 5467 | |
4cecd739 DJ |
5468 | /* If there is a location expression for DW_AT_frame_base, record |
5469 | it. */ | |
e142c38c | 5470 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5471 | if (attr) |
c034e007 AC |
5472 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5473 | expression is being recorded directly in the function's symbol | |
5474 | and not in a separate frame-base object. I guess this hack is | |
5475 | to avoid adding some sort of frame-base adjunct/annex to the | |
5476 | function's symbol :-(. The problem with doing this is that it | |
5477 | results in a function symbol with a location expression that | |
5478 | has nothing to do with the location of the function, ouch! The | |
5479 | relationship should be: a function's symbol has-a frame base; a | |
5480 | frame-base has-a location expression. */ | |
e7c27a73 | 5481 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5482 | |
e142c38c | 5483 | cu->list_in_scope = &local_symbols; |
c906108c | 5484 | |
639d11d3 | 5485 | if (die->child != NULL) |
c906108c | 5486 | { |
639d11d3 | 5487 | child_die = die->child; |
c906108c SS |
5488 | while (child_die && child_die->tag) |
5489 | { | |
34eaf542 TT |
5490 | if (child_die->tag == DW_TAG_template_type_param |
5491 | || child_die->tag == DW_TAG_template_value_param) | |
5492 | { | |
5493 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5494 | ||
f1078f66 DJ |
5495 | if (arg != NULL) |
5496 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
5497 | } |
5498 | else | |
5499 | process_die (child_die, cu); | |
c906108c SS |
5500 | child_die = sibling_die (child_die); |
5501 | } | |
5502 | } | |
5503 | ||
d389af10 JK |
5504 | inherit_abstract_dies (die, cu); |
5505 | ||
4a811a97 UW |
5506 | /* If we have a DW_AT_specification, we might need to import using |
5507 | directives from the context of the specification DIE. See the | |
5508 | comment in determine_prefix. */ | |
5509 | if (cu->language == language_cplus | |
5510 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5511 | { | |
5512 | struct dwarf2_cu *spec_cu = cu; | |
5513 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5514 | ||
5515 | while (spec_die) | |
5516 | { | |
5517 | child_die = spec_die->child; | |
5518 | while (child_die && child_die->tag) | |
5519 | { | |
5520 | if (child_die->tag == DW_TAG_imported_module) | |
5521 | process_die (child_die, spec_cu); | |
5522 | child_die = sibling_die (child_die); | |
5523 | } | |
5524 | ||
5525 | /* In some cases, GCC generates specification DIEs that | |
5526 | themselves contain DW_AT_specification attributes. */ | |
5527 | spec_die = die_specification (spec_die, &spec_cu); | |
5528 | } | |
5529 | } | |
5530 | ||
c906108c SS |
5531 | new = pop_context (); |
5532 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
5533 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
5534 | lowpc, highpc, objfile); | |
5535 | ||
df8a16a1 | 5536 | /* For C++, set the block's scope. */ |
f55ee35c | 5537 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5538 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5539 | determine_prefix (die, cu), |
df8a16a1 DJ |
5540 | processing_has_namespace_info); |
5541 | ||
801e3a5b JB |
5542 | /* If we have address ranges, record them. */ |
5543 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5544 | |
34eaf542 TT |
5545 | /* Attach template arguments to function. */ |
5546 | if (! VEC_empty (symbolp, template_args)) | |
5547 | { | |
5548 | gdb_assert (templ_func != NULL); | |
5549 | ||
5550 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
5551 | templ_func->template_arguments | |
5552 | = obstack_alloc (&objfile->objfile_obstack, | |
5553 | (templ_func->n_template_arguments | |
5554 | * sizeof (struct symbol *))); | |
5555 | memcpy (templ_func->template_arguments, | |
5556 | VEC_address (symbolp, template_args), | |
5557 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
5558 | VEC_free (symbolp, template_args); | |
5559 | } | |
5560 | ||
208d8187 JB |
5561 | /* In C++, we can have functions nested inside functions (e.g., when |
5562 | a function declares a class that has methods). This means that | |
5563 | when we finish processing a function scope, we may need to go | |
5564 | back to building a containing block's symbol lists. */ | |
5565 | local_symbols = new->locals; | |
5566 | param_symbols = new->params; | |
27aa8d6a | 5567 | using_directives = new->using_directives; |
208d8187 | 5568 | |
921e78cf JB |
5569 | /* If we've finished processing a top-level function, subsequent |
5570 | symbols go in the file symbol list. */ | |
5571 | if (outermost_context_p ()) | |
e142c38c | 5572 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5573 | } |
5574 | ||
5575 | /* Process all the DIES contained within a lexical block scope. Start | |
5576 | a new scope, process the dies, and then close the scope. */ | |
5577 | ||
5578 | static void | |
e7c27a73 | 5579 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5580 | { |
e7c27a73 | 5581 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5582 | struct context_stack *new; |
c906108c SS |
5583 | CORE_ADDR lowpc, highpc; |
5584 | struct die_info *child_die; | |
e142c38c DJ |
5585 | CORE_ADDR baseaddr; |
5586 | ||
5587 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5588 | |
5589 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5590 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5591 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5592 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5593 | describe ranges. */ |
d85a05f0 | 5594 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5595 | return; |
5596 | lowpc += baseaddr; | |
5597 | highpc += baseaddr; | |
5598 | ||
5599 | push_context (0, lowpc); | |
639d11d3 | 5600 | if (die->child != NULL) |
c906108c | 5601 | { |
639d11d3 | 5602 | child_die = die->child; |
c906108c SS |
5603 | while (child_die && child_die->tag) |
5604 | { | |
e7c27a73 | 5605 | process_die (child_die, cu); |
c906108c SS |
5606 | child_die = sibling_die (child_die); |
5607 | } | |
5608 | } | |
5609 | new = pop_context (); | |
5610 | ||
8540c487 | 5611 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5612 | { |
801e3a5b JB |
5613 | struct block *block |
5614 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5615 | highpc, objfile); | |
5616 | ||
5617 | /* Note that recording ranges after traversing children, as we | |
5618 | do here, means that recording a parent's ranges entails | |
5619 | walking across all its children's ranges as they appear in | |
5620 | the address map, which is quadratic behavior. | |
5621 | ||
5622 | It would be nicer to record the parent's ranges before | |
5623 | traversing its children, simply overriding whatever you find | |
5624 | there. But since we don't even decide whether to create a | |
5625 | block until after we've traversed its children, that's hard | |
5626 | to do. */ | |
5627 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5628 | } |
5629 | local_symbols = new->locals; | |
27aa8d6a | 5630 | using_directives = new->using_directives; |
c906108c SS |
5631 | } |
5632 | ||
43039443 | 5633 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5634 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5635 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5636 | |
5637 | static int | |
5638 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5639 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5640 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5641 | { |
5642 | struct objfile *objfile = cu->objfile; | |
5643 | struct comp_unit_head *cu_header = &cu->header; | |
5644 | bfd *obfd = objfile->obfd; | |
5645 | unsigned int addr_size = cu_header->addr_size; | |
5646 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5647 | /* Base address selection entry. */ | |
5648 | CORE_ADDR base; | |
5649 | int found_base; | |
5650 | unsigned int dummy; | |
5651 | gdb_byte *buffer; | |
5652 | CORE_ADDR marker; | |
5653 | int low_set; | |
5654 | CORE_ADDR low = 0; | |
5655 | CORE_ADDR high = 0; | |
ff013f42 | 5656 | CORE_ADDR baseaddr; |
43039443 | 5657 | |
d00adf39 DE |
5658 | found_base = cu->base_known; |
5659 | base = cu->base_address; | |
43039443 | 5660 | |
be391dca | 5661 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5662 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5663 | { |
5664 | complaint (&symfile_complaints, | |
5665 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5666 | offset); | |
5667 | return 0; | |
5668 | } | |
dce234bc | 5669 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5670 | |
5671 | /* Read in the largest possible address. */ | |
5672 | marker = read_address (obfd, buffer, cu, &dummy); | |
5673 | if ((marker & mask) == mask) | |
5674 | { | |
5675 | /* If we found the largest possible address, then | |
5676 | read the base address. */ | |
5677 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5678 | buffer += 2 * addr_size; | |
5679 | offset += 2 * addr_size; | |
5680 | found_base = 1; | |
5681 | } | |
5682 | ||
5683 | low_set = 0; | |
5684 | ||
e7030f15 | 5685 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5686 | |
43039443 JK |
5687 | while (1) |
5688 | { | |
5689 | CORE_ADDR range_beginning, range_end; | |
5690 | ||
5691 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5692 | buffer += addr_size; | |
5693 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5694 | buffer += addr_size; | |
5695 | offset += 2 * addr_size; | |
5696 | ||
5697 | /* An end of list marker is a pair of zero addresses. */ | |
5698 | if (range_beginning == 0 && range_end == 0) | |
5699 | /* Found the end of list entry. */ | |
5700 | break; | |
5701 | ||
5702 | /* Each base address selection entry is a pair of 2 values. | |
5703 | The first is the largest possible address, the second is | |
5704 | the base address. Check for a base address here. */ | |
5705 | if ((range_beginning & mask) == mask) | |
5706 | { | |
5707 | /* If we found the largest possible address, then | |
5708 | read the base address. */ | |
5709 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5710 | found_base = 1; | |
5711 | continue; | |
5712 | } | |
5713 | ||
5714 | if (!found_base) | |
5715 | { | |
5716 | /* We have no valid base address for the ranges | |
5717 | data. */ | |
5718 | complaint (&symfile_complaints, | |
5719 | _("Invalid .debug_ranges data (no base address)")); | |
5720 | return 0; | |
5721 | } | |
5722 | ||
5723 | range_beginning += base; | |
5724 | range_end += base; | |
5725 | ||
ff013f42 JK |
5726 | if (ranges_pst != NULL && range_beginning < range_end) |
5727 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
5728 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
5729 | ranges_pst); | |
5730 | ||
43039443 JK |
5731 | /* FIXME: This is recording everything as a low-high |
5732 | segment of consecutive addresses. We should have a | |
5733 | data structure for discontiguous block ranges | |
5734 | instead. */ | |
5735 | if (! low_set) | |
5736 | { | |
5737 | low = range_beginning; | |
5738 | high = range_end; | |
5739 | low_set = 1; | |
5740 | } | |
5741 | else | |
5742 | { | |
5743 | if (range_beginning < low) | |
5744 | low = range_beginning; | |
5745 | if (range_end > high) | |
5746 | high = range_end; | |
5747 | } | |
5748 | } | |
5749 | ||
5750 | if (! low_set) | |
5751 | /* If the first entry is an end-of-list marker, the range | |
5752 | describes an empty scope, i.e. no instructions. */ | |
5753 | return 0; | |
5754 | ||
5755 | if (low_return) | |
5756 | *low_return = low; | |
5757 | if (high_return) | |
5758 | *high_return = high; | |
5759 | return 1; | |
5760 | } | |
5761 | ||
af34e669 DJ |
5762 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
5763 | are present and valid, otherwise, return 0. Return -1 if the range is | |
5764 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 5765 | static int |
af34e669 | 5766 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
5767 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
5768 | struct partial_symtab *pst) | |
c906108c SS |
5769 | { |
5770 | struct attribute *attr; | |
af34e669 DJ |
5771 | CORE_ADDR low = 0; |
5772 | CORE_ADDR high = 0; | |
5773 | int ret = 0; | |
c906108c | 5774 | |
e142c38c | 5775 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 5776 | if (attr) |
af34e669 DJ |
5777 | { |
5778 | high = DW_ADDR (attr); | |
e142c38c | 5779 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
5780 | if (attr) |
5781 | low = DW_ADDR (attr); | |
5782 | else | |
5783 | /* Found high w/o low attribute. */ | |
5784 | return 0; | |
5785 | ||
5786 | /* Found consecutive range of addresses. */ | |
5787 | ret = 1; | |
5788 | } | |
c906108c | 5789 | else |
af34e669 | 5790 | { |
e142c38c | 5791 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
5792 | if (attr != NULL) |
5793 | { | |
af34e669 | 5794 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 5795 | .debug_ranges section. */ |
d85a05f0 | 5796 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 5797 | return 0; |
43039443 | 5798 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
5799 | ret = -1; |
5800 | } | |
5801 | } | |
c906108c SS |
5802 | |
5803 | if (high < low) | |
5804 | return 0; | |
5805 | ||
5806 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
5807 | eliminate duplicate copies of functions and vtables and such. | |
5808 | The linker will arbitrarily choose one and discard the others. | |
5809 | The AT_*_pc values for such functions refer to local labels in | |
5810 | these sections. If the section from that file was discarded, the | |
5811 | labels are not in the output, so the relocs get a value of 0. | |
5812 | If this is a discarded function, mark the pc bounds as invalid, | |
5813 | so that GDB will ignore it. */ | |
72dca2f5 | 5814 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
5815 | return 0; |
5816 | ||
5817 | *lowpc = low; | |
5818 | *highpc = high; | |
af34e669 | 5819 | return ret; |
c906108c SS |
5820 | } |
5821 | ||
b084d499 JB |
5822 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
5823 | its low and high PC addresses. Do nothing if these addresses could not | |
5824 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
5825 | and HIGHPC to the high address if greater than HIGHPC. */ | |
5826 | ||
5827 | static void | |
5828 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
5829 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5830 | struct dwarf2_cu *cu) | |
5831 | { | |
5832 | CORE_ADDR low, high; | |
5833 | struct die_info *child = die->child; | |
5834 | ||
d85a05f0 | 5835 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
5836 | { |
5837 | *lowpc = min (*lowpc, low); | |
5838 | *highpc = max (*highpc, high); | |
5839 | } | |
5840 | ||
5841 | /* If the language does not allow nested subprograms (either inside | |
5842 | subprograms or lexical blocks), we're done. */ | |
5843 | if (cu->language != language_ada) | |
5844 | return; | |
6e70227d | 5845 | |
b084d499 JB |
5846 | /* Check all the children of the given DIE. If it contains nested |
5847 | subprograms, then check their pc bounds. Likewise, we need to | |
5848 | check lexical blocks as well, as they may also contain subprogram | |
5849 | definitions. */ | |
5850 | while (child && child->tag) | |
5851 | { | |
5852 | if (child->tag == DW_TAG_subprogram | |
5853 | || child->tag == DW_TAG_lexical_block) | |
5854 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
5855 | child = sibling_die (child); | |
5856 | } | |
5857 | } | |
5858 | ||
fae299cd DC |
5859 | /* Get the low and high pc's represented by the scope DIE, and store |
5860 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
5861 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
5862 | ||
5863 | static void | |
5864 | get_scope_pc_bounds (struct die_info *die, | |
5865 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5866 | struct dwarf2_cu *cu) | |
5867 | { | |
5868 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
5869 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
5870 | CORE_ADDR current_low, current_high; | |
5871 | ||
d85a05f0 | 5872 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
5873 | { |
5874 | best_low = current_low; | |
5875 | best_high = current_high; | |
5876 | } | |
5877 | else | |
5878 | { | |
5879 | struct die_info *child = die->child; | |
5880 | ||
5881 | while (child && child->tag) | |
5882 | { | |
5883 | switch (child->tag) { | |
5884 | case DW_TAG_subprogram: | |
b084d499 | 5885 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
5886 | break; |
5887 | case DW_TAG_namespace: | |
f55ee35c | 5888 | case DW_TAG_module: |
fae299cd DC |
5889 | /* FIXME: carlton/2004-01-16: Should we do this for |
5890 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
5891 | that current GCC's always emit the DIEs corresponding | |
5892 | to definitions of methods of classes as children of a | |
5893 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
5894 | the DIEs giving the declarations, which could be | |
5895 | anywhere). But I don't see any reason why the | |
5896 | standards says that they have to be there. */ | |
5897 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
5898 | ||
5899 | if (current_low != ((CORE_ADDR) -1)) | |
5900 | { | |
5901 | best_low = min (best_low, current_low); | |
5902 | best_high = max (best_high, current_high); | |
5903 | } | |
5904 | break; | |
5905 | default: | |
5906 | /* Ignore. */ | |
5907 | break; | |
5908 | } | |
5909 | ||
5910 | child = sibling_die (child); | |
5911 | } | |
5912 | } | |
5913 | ||
5914 | *lowpc = best_low; | |
5915 | *highpc = best_high; | |
5916 | } | |
5917 | ||
801e3a5b JB |
5918 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
5919 | in DIE. */ | |
5920 | static void | |
5921 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
5922 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
5923 | { | |
5924 | struct attribute *attr; | |
5925 | ||
5926 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
5927 | if (attr) | |
5928 | { | |
5929 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 5930 | |
801e3a5b JB |
5931 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
5932 | if (attr) | |
5933 | { | |
5934 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 5935 | |
801e3a5b JB |
5936 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
5937 | } | |
5938 | } | |
5939 | ||
5940 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
5941 | if (attr) | |
5942 | { | |
5943 | bfd *obfd = cu->objfile->obfd; | |
5944 | ||
5945 | /* The value of the DW_AT_ranges attribute is the offset of the | |
5946 | address range list in the .debug_ranges section. */ | |
5947 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 5948 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
5949 | |
5950 | /* For some target architectures, but not others, the | |
5951 | read_address function sign-extends the addresses it returns. | |
5952 | To recognize base address selection entries, we need a | |
5953 | mask. */ | |
5954 | unsigned int addr_size = cu->header.addr_size; | |
5955 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5956 | ||
5957 | /* The base address, to which the next pair is relative. Note | |
5958 | that this 'base' is a DWARF concept: most entries in a range | |
5959 | list are relative, to reduce the number of relocs against the | |
5960 | debugging information. This is separate from this function's | |
5961 | 'baseaddr' argument, which GDB uses to relocate debugging | |
5962 | information from a shared library based on the address at | |
5963 | which the library was loaded. */ | |
d00adf39 DE |
5964 | CORE_ADDR base = cu->base_address; |
5965 | int base_known = cu->base_known; | |
801e3a5b | 5966 | |
be391dca | 5967 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 5968 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
5969 | { |
5970 | complaint (&symfile_complaints, | |
5971 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
5972 | offset); | |
5973 | return; | |
5974 | } | |
5975 | ||
5976 | for (;;) | |
5977 | { | |
5978 | unsigned int bytes_read; | |
5979 | CORE_ADDR start, end; | |
5980 | ||
5981 | start = read_address (obfd, buffer, cu, &bytes_read); | |
5982 | buffer += bytes_read; | |
5983 | end = read_address (obfd, buffer, cu, &bytes_read); | |
5984 | buffer += bytes_read; | |
5985 | ||
5986 | /* Did we find the end of the range list? */ | |
5987 | if (start == 0 && end == 0) | |
5988 | break; | |
5989 | ||
5990 | /* Did we find a base address selection entry? */ | |
5991 | else if ((start & base_select_mask) == base_select_mask) | |
5992 | { | |
5993 | base = end; | |
5994 | base_known = 1; | |
5995 | } | |
5996 | ||
5997 | /* We found an ordinary address range. */ | |
5998 | else | |
5999 | { | |
6000 | if (!base_known) | |
6001 | { | |
6002 | complaint (&symfile_complaints, | |
6003 | _("Invalid .debug_ranges data (no base address)")); | |
6004 | return; | |
6005 | } | |
6006 | ||
6e70227d DE |
6007 | record_block_range (block, |
6008 | baseaddr + base + start, | |
801e3a5b JB |
6009 | baseaddr + base + end - 1); |
6010 | } | |
6011 | } | |
6012 | } | |
6013 | } | |
6014 | ||
c906108c SS |
6015 | /* Add an aggregate field to the field list. */ |
6016 | ||
6017 | static void | |
107d2387 | 6018 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6019 | struct dwarf2_cu *cu) |
6e70227d | 6020 | { |
e7c27a73 | 6021 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6022 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6023 | struct nextfield *new_field; |
6024 | struct attribute *attr; | |
6025 | struct field *fp; | |
6026 | char *fieldname = ""; | |
6027 | ||
6028 | /* Allocate a new field list entry and link it in. */ | |
6029 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6030 | make_cleanup (xfree, new_field); |
c906108c | 6031 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6032 | |
6033 | if (die->tag == DW_TAG_inheritance) | |
6034 | { | |
6035 | new_field->next = fip->baseclasses; | |
6036 | fip->baseclasses = new_field; | |
6037 | } | |
6038 | else | |
6039 | { | |
6040 | new_field->next = fip->fields; | |
6041 | fip->fields = new_field; | |
6042 | } | |
c906108c SS |
6043 | fip->nfields++; |
6044 | ||
6045 | /* Handle accessibility and virtuality of field. | |
6046 | The default accessibility for members is public, the default | |
6047 | accessibility for inheritance is private. */ | |
6048 | if (die->tag != DW_TAG_inheritance) | |
6049 | new_field->accessibility = DW_ACCESS_public; | |
6050 | else | |
6051 | new_field->accessibility = DW_ACCESS_private; | |
6052 | new_field->virtuality = DW_VIRTUALITY_none; | |
6053 | ||
e142c38c | 6054 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6055 | if (attr) |
6056 | new_field->accessibility = DW_UNSND (attr); | |
6057 | if (new_field->accessibility != DW_ACCESS_public) | |
6058 | fip->non_public_fields = 1; | |
e142c38c | 6059 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6060 | if (attr) |
6061 | new_field->virtuality = DW_UNSND (attr); | |
6062 | ||
6063 | fp = &new_field->field; | |
a9a9bd0f | 6064 | |
e142c38c | 6065 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6066 | { |
a9a9bd0f | 6067 | /* Data member other than a C++ static data member. */ |
6e70227d | 6068 | |
c906108c | 6069 | /* Get type of field. */ |
e7c27a73 | 6070 | fp->type = die_type (die, cu); |
c906108c | 6071 | |
d6a843b5 | 6072 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6073 | |
c906108c | 6074 | /* Get bit size of field (zero if none). */ |
e142c38c | 6075 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6076 | if (attr) |
6077 | { | |
6078 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6079 | } | |
6080 | else | |
6081 | { | |
6082 | FIELD_BITSIZE (*fp) = 0; | |
6083 | } | |
6084 | ||
6085 | /* Get bit offset of field. */ | |
e142c38c | 6086 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
6087 | if (attr) |
6088 | { | |
d4b96c9a | 6089 | int byte_offset = 0; |
c6a0999f | 6090 | |
3690dd37 | 6091 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 6092 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 6093 | else if (attr_form_is_constant (attr)) |
c6a0999f | 6094 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 6095 | else if (attr_form_is_block (attr)) |
c6a0999f | 6096 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
6097 | else |
6098 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 6099 | |
d6a843b5 | 6100 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 6101 | } |
e142c38c | 6102 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6103 | if (attr) |
6104 | { | |
5e2b427d | 6105 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6106 | { |
6107 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6108 | additional bit offset from the MSB of the containing |
6109 | anonymous object to the MSB of the field. We don't | |
6110 | have to do anything special since we don't need to | |
6111 | know the size of the anonymous object. */ | |
c906108c SS |
6112 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6113 | } | |
6114 | else | |
6115 | { | |
6116 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6117 | MSB of the anonymous object, subtract off the number of |
6118 | bits from the MSB of the field to the MSB of the | |
6119 | object, and then subtract off the number of bits of | |
6120 | the field itself. The result is the bit offset of | |
6121 | the LSB of the field. */ | |
c906108c SS |
6122 | int anonymous_size; |
6123 | int bit_offset = DW_UNSND (attr); | |
6124 | ||
e142c38c | 6125 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6126 | if (attr) |
6127 | { | |
6128 | /* The size of the anonymous object containing | |
6129 | the bit field is explicit, so use the | |
6130 | indicated size (in bytes). */ | |
6131 | anonymous_size = DW_UNSND (attr); | |
6132 | } | |
6133 | else | |
6134 | { | |
6135 | /* The size of the anonymous object containing | |
6136 | the bit field must be inferred from the type | |
6137 | attribute of the data member containing the | |
6138 | bit field. */ | |
6139 | anonymous_size = TYPE_LENGTH (fp->type); | |
6140 | } | |
6141 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
6142 | - bit_offset - FIELD_BITSIZE (*fp); | |
6143 | } | |
6144 | } | |
6145 | ||
6146 | /* Get name of field. */ | |
39cbfefa DJ |
6147 | fieldname = dwarf2_name (die, cu); |
6148 | if (fieldname == NULL) | |
6149 | fieldname = ""; | |
d8151005 DJ |
6150 | |
6151 | /* The name is already allocated along with this objfile, so we don't | |
6152 | need to duplicate it for the type. */ | |
6153 | fp->name = fieldname; | |
c906108c SS |
6154 | |
6155 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 6156 | pointer or virtual base class pointer) to private. */ |
e142c38c | 6157 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 6158 | { |
d48cc9dd | 6159 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
6160 | new_field->accessibility = DW_ACCESS_private; |
6161 | fip->non_public_fields = 1; | |
6162 | } | |
6163 | } | |
a9a9bd0f | 6164 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 6165 | { |
a9a9bd0f DC |
6166 | /* C++ static member. */ |
6167 | ||
6168 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
6169 | is a declaration, but all versions of G++ as of this writing | |
6170 | (so through at least 3.2.1) incorrectly generate | |
6171 | DW_TAG_variable tags. */ | |
6e70227d | 6172 | |
c906108c | 6173 | char *physname; |
c906108c | 6174 | |
a9a9bd0f | 6175 | /* Get name of field. */ |
39cbfefa DJ |
6176 | fieldname = dwarf2_name (die, cu); |
6177 | if (fieldname == NULL) | |
c906108c SS |
6178 | return; |
6179 | ||
254e6b9e | 6180 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
6181 | if (attr |
6182 | /* Only create a symbol if this is an external value. | |
6183 | new_symbol checks this and puts the value in the global symbol | |
6184 | table, which we want. If it is not external, new_symbol | |
6185 | will try to put the value in cu->list_in_scope which is wrong. */ | |
6186 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
6187 | { |
6188 | /* A static const member, not much different than an enum as far as | |
6189 | we're concerned, except that we can support more types. */ | |
6190 | new_symbol (die, NULL, cu); | |
6191 | } | |
6192 | ||
2df3850c | 6193 | /* Get physical name. */ |
94af9270 | 6194 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 6195 | |
d8151005 DJ |
6196 | /* The name is already allocated along with this objfile, so we don't |
6197 | need to duplicate it for the type. */ | |
6198 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 6199 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 6200 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
6201 | } |
6202 | else if (die->tag == DW_TAG_inheritance) | |
6203 | { | |
6204 | /* C++ base class field. */ | |
e142c38c | 6205 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 6206 | if (attr) |
d4b96c9a JK |
6207 | { |
6208 | int byte_offset = 0; | |
6209 | ||
6210 | if (attr_form_is_section_offset (attr)) | |
6211 | dwarf2_complex_location_expr_complaint (); | |
6212 | else if (attr_form_is_constant (attr)) | |
6213 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
6214 | else if (attr_form_is_block (attr)) | |
6215 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6216 | else | |
6217 | dwarf2_complex_location_expr_complaint (); | |
6218 | ||
6219 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
6220 | } | |
c906108c | 6221 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 6222 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
6223 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
6224 | fip->nbaseclasses++; | |
6225 | } | |
6226 | } | |
6227 | ||
98751a41 JK |
6228 | /* Add a typedef defined in the scope of the FIP's class. */ |
6229 | ||
6230 | static void | |
6231 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
6232 | struct dwarf2_cu *cu) | |
6e70227d | 6233 | { |
98751a41 JK |
6234 | struct objfile *objfile = cu->objfile; |
6235 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6236 | struct typedef_field_list *new_field; | |
6237 | struct attribute *attr; | |
6238 | struct typedef_field *fp; | |
6239 | char *fieldname = ""; | |
6240 | ||
6241 | /* Allocate a new field list entry and link it in. */ | |
6242 | new_field = xzalloc (sizeof (*new_field)); | |
6243 | make_cleanup (xfree, new_field); | |
6244 | ||
6245 | gdb_assert (die->tag == DW_TAG_typedef); | |
6246 | ||
6247 | fp = &new_field->field; | |
6248 | ||
6249 | /* Get name of field. */ | |
6250 | fp->name = dwarf2_name (die, cu); | |
6251 | if (fp->name == NULL) | |
6252 | return; | |
6253 | ||
6254 | fp->type = read_type_die (die, cu); | |
6255 | ||
6256 | new_field->next = fip->typedef_field_list; | |
6257 | fip->typedef_field_list = new_field; | |
6258 | fip->typedef_field_list_count++; | |
6259 | } | |
6260 | ||
c906108c SS |
6261 | /* Create the vector of fields, and attach it to the type. */ |
6262 | ||
6263 | static void | |
fba45db2 | 6264 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6265 | struct dwarf2_cu *cu) |
c906108c SS |
6266 | { |
6267 | int nfields = fip->nfields; | |
6268 | ||
6269 | /* Record the field count, allocate space for the array of fields, | |
6270 | and create blank accessibility bitfields if necessary. */ | |
6271 | TYPE_NFIELDS (type) = nfields; | |
6272 | TYPE_FIELDS (type) = (struct field *) | |
6273 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
6274 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
6275 | ||
b4ba55a1 | 6276 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
6277 | { |
6278 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6279 | ||
6280 | TYPE_FIELD_PRIVATE_BITS (type) = | |
6281 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6282 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
6283 | ||
6284 | TYPE_FIELD_PROTECTED_BITS (type) = | |
6285 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6286 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
6287 | ||
774b6a14 TT |
6288 | TYPE_FIELD_IGNORE_BITS (type) = |
6289 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6290 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
6291 | } |
6292 | ||
6293 | /* If the type has baseclasses, allocate and clear a bit vector for | |
6294 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 6295 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
6296 | { |
6297 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 6298 | unsigned char *pointer; |
c906108c SS |
6299 | |
6300 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
6301 | pointer = TYPE_ALLOC (type, num_bytes); |
6302 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
6303 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
6304 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
6305 | } | |
6306 | ||
6307 | /* Copy the saved-up fields into the field vector. Start from the head | |
6308 | of the list, adding to the tail of the field array, so that they end | |
6309 | up in the same order in the array in which they were added to the list. */ | |
6310 | while (nfields-- > 0) | |
6311 | { | |
7d0ccb61 DJ |
6312 | struct nextfield *fieldp; |
6313 | ||
6314 | if (fip->fields) | |
6315 | { | |
6316 | fieldp = fip->fields; | |
6317 | fip->fields = fieldp->next; | |
6318 | } | |
6319 | else | |
6320 | { | |
6321 | fieldp = fip->baseclasses; | |
6322 | fip->baseclasses = fieldp->next; | |
6323 | } | |
6324 | ||
6325 | TYPE_FIELD (type, nfields) = fieldp->field; | |
6326 | switch (fieldp->accessibility) | |
c906108c | 6327 | { |
c5aa993b | 6328 | case DW_ACCESS_private: |
b4ba55a1 JB |
6329 | if (cu->language != language_ada) |
6330 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 6331 | break; |
c906108c | 6332 | |
c5aa993b | 6333 | case DW_ACCESS_protected: |
b4ba55a1 JB |
6334 | if (cu->language != language_ada) |
6335 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 6336 | break; |
c906108c | 6337 | |
c5aa993b JM |
6338 | case DW_ACCESS_public: |
6339 | break; | |
c906108c | 6340 | |
c5aa993b JM |
6341 | default: |
6342 | /* Unknown accessibility. Complain and treat it as public. */ | |
6343 | { | |
e2e0b3e5 | 6344 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 6345 | fieldp->accessibility); |
c5aa993b JM |
6346 | } |
6347 | break; | |
c906108c SS |
6348 | } |
6349 | if (nfields < fip->nbaseclasses) | |
6350 | { | |
7d0ccb61 | 6351 | switch (fieldp->virtuality) |
c906108c | 6352 | { |
c5aa993b JM |
6353 | case DW_VIRTUALITY_virtual: |
6354 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
6355 | if (cu->language == language_ada) |
6356 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
6357 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
6358 | break; | |
c906108c SS |
6359 | } |
6360 | } | |
c906108c SS |
6361 | } |
6362 | } | |
6363 | ||
c906108c SS |
6364 | /* Add a member function to the proper fieldlist. */ |
6365 | ||
6366 | static void | |
107d2387 | 6367 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6368 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 6369 | { |
e7c27a73 | 6370 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6371 | struct attribute *attr; |
6372 | struct fnfieldlist *flp; | |
6373 | int i; | |
6374 | struct fn_field *fnp; | |
6375 | char *fieldname; | |
c906108c | 6376 | struct nextfnfield *new_fnfield; |
f792889a | 6377 | struct type *this_type; |
c906108c | 6378 | |
b4ba55a1 JB |
6379 | if (cu->language == language_ada) |
6380 | error ("unexpected member function in Ada type"); | |
6381 | ||
2df3850c | 6382 | /* Get name of member function. */ |
39cbfefa DJ |
6383 | fieldname = dwarf2_name (die, cu); |
6384 | if (fieldname == NULL) | |
2df3850c | 6385 | return; |
c906108c | 6386 | |
c906108c SS |
6387 | /* Look up member function name in fieldlist. */ |
6388 | for (i = 0; i < fip->nfnfields; i++) | |
6389 | { | |
27bfe10e | 6390 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
6391 | break; |
6392 | } | |
6393 | ||
6394 | /* Create new list element if necessary. */ | |
6395 | if (i < fip->nfnfields) | |
6396 | flp = &fip->fnfieldlists[i]; | |
6397 | else | |
6398 | { | |
6399 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6400 | { | |
6401 | fip->fnfieldlists = (struct fnfieldlist *) | |
6402 | xrealloc (fip->fnfieldlists, | |
6403 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6404 | * sizeof (struct fnfieldlist)); |
c906108c | 6405 | if (fip->nfnfields == 0) |
c13c43fd | 6406 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
6407 | } |
6408 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
6409 | flp->name = fieldname; | |
6410 | flp->length = 0; | |
6411 | flp->head = NULL; | |
3da10d80 | 6412 | i = fip->nfnfields++; |
c906108c SS |
6413 | } |
6414 | ||
6415 | /* Create a new member function field and chain it to the field list | |
6416 | entry. */ | |
6417 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 6418 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
6419 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
6420 | new_fnfield->next = flp->head; | |
6421 | flp->head = new_fnfield; | |
6422 | flp->length++; | |
6423 | ||
6424 | /* Fill in the member function field info. */ | |
6425 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
6426 | |
6427 | /* Delay processing of the physname until later. */ | |
6428 | if (cu->language == language_cplus || cu->language == language_java) | |
6429 | { | |
6430 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
6431 | die, cu); | |
6432 | } | |
6433 | else | |
6434 | { | |
6435 | char *physname = (char *) dwarf2_physname (fieldname, die, cu); | |
6436 | fnp->physname = physname ? physname : ""; | |
6437 | } | |
6438 | ||
c906108c | 6439 | fnp->type = alloc_type (objfile); |
f792889a DJ |
6440 | this_type = read_type_die (die, cu); |
6441 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 6442 | { |
f792889a | 6443 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 6444 | |
f792889a | 6445 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
6446 | of the method itself (TYPE_CODE_METHOD). */ |
6447 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
6448 | TYPE_TARGET_TYPE (this_type), |
6449 | TYPE_FIELDS (this_type), | |
6450 | TYPE_NFIELDS (this_type), | |
6451 | TYPE_VARARGS (this_type)); | |
c906108c SS |
6452 | |
6453 | /* Handle static member functions. | |
c5aa993b JM |
6454 | Dwarf2 has no clean way to discern C++ static and non-static |
6455 | member functions. G++ helps GDB by marking the first | |
6456 | parameter for non-static member functions (which is the | |
6457 | this pointer) as artificial. We obtain this information | |
6458 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 6459 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
6460 | fnp->voffset = VOFFSET_STATIC; |
6461 | } | |
6462 | else | |
e2e0b3e5 | 6463 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 6464 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
6465 | |
6466 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 6467 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 6468 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
6469 | |
6470 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
6471 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
6472 | ||
6473 | /* Get accessibility. */ | |
e142c38c | 6474 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6475 | if (attr) |
6476 | { | |
6477 | switch (DW_UNSND (attr)) | |
6478 | { | |
c5aa993b JM |
6479 | case DW_ACCESS_private: |
6480 | fnp->is_private = 1; | |
6481 | break; | |
6482 | case DW_ACCESS_protected: | |
6483 | fnp->is_protected = 1; | |
6484 | break; | |
c906108c SS |
6485 | } |
6486 | } | |
6487 | ||
b02dede2 | 6488 | /* Check for artificial methods. */ |
e142c38c | 6489 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
6490 | if (attr && DW_UNSND (attr) != 0) |
6491 | fnp->is_artificial = 1; | |
6492 | ||
0d564a31 | 6493 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
6494 | function. For older versions of GCC, this is an offset in the |
6495 | appropriate virtual table, as specified by DW_AT_containing_type. | |
6496 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
6497 | to the object address. */ |
6498 | ||
e142c38c | 6499 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 6500 | if (attr) |
8e19ed76 | 6501 | { |
aec5aa8b | 6502 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 6503 | { |
aec5aa8b TT |
6504 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
6505 | { | |
6506 | /* Old-style GCC. */ | |
6507 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
6508 | } | |
6509 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6510 | || (DW_BLOCK (attr)->size > 1 | |
6511 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
6512 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
6513 | { | |
6514 | struct dwarf_block blk; | |
6515 | int offset; | |
6516 | ||
6517 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6518 | ? 1 : 2); | |
6519 | blk.size = DW_BLOCK (attr)->size - offset; | |
6520 | blk.data = DW_BLOCK (attr)->data + offset; | |
6521 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
6522 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
6523 | dwarf2_complex_location_expr_complaint (); | |
6524 | else | |
6525 | fnp->voffset /= cu->header.addr_size; | |
6526 | fnp->voffset += 2; | |
6527 | } | |
6528 | else | |
6529 | dwarf2_complex_location_expr_complaint (); | |
6530 | ||
6531 | if (!fnp->fcontext) | |
6532 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
6533 | } | |
3690dd37 | 6534 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6535 | { |
4d3c2250 | 6536 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6537 | } |
6538 | else | |
6539 | { | |
4d3c2250 KB |
6540 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
6541 | fieldname); | |
8e19ed76 | 6542 | } |
0d564a31 | 6543 | } |
d48cc9dd DJ |
6544 | else |
6545 | { | |
6546 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
6547 | if (attr && DW_UNSND (attr)) | |
6548 | { | |
6549 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
6550 | complaint (&symfile_complaints, | |
6551 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
6552 | fieldname, die->offset); | |
9655fd1a | 6553 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
6554 | TYPE_CPLUS_DYNAMIC (type) = 1; |
6555 | } | |
6556 | } | |
c906108c SS |
6557 | } |
6558 | ||
6559 | /* Create the vector of member function fields, and attach it to the type. */ | |
6560 | ||
6561 | static void | |
fba45db2 | 6562 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6563 | struct dwarf2_cu *cu) |
c906108c SS |
6564 | { |
6565 | struct fnfieldlist *flp; | |
6566 | int total_length = 0; | |
6567 | int i; | |
6568 | ||
b4ba55a1 JB |
6569 | if (cu->language == language_ada) |
6570 | error ("unexpected member functions in Ada type"); | |
6571 | ||
c906108c SS |
6572 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6573 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6574 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6575 | ||
6576 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6577 | { | |
6578 | struct nextfnfield *nfp = flp->head; | |
6579 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6580 | int k; | |
6581 | ||
6582 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6583 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6584 | fn_flp->fn_fields = (struct fn_field *) | |
6585 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6586 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6587 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6588 | |
6589 | total_length += flp->length; | |
6590 | } | |
6591 | ||
6592 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6593 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6594 | } | |
6595 | ||
1168df01 JB |
6596 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6597 | language, zero otherwise. */ | |
6598 | static int | |
6599 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6600 | { | |
6601 | static const char vptr[] = "_vptr"; | |
987504bb | 6602 | static const char vtable[] = "vtable"; |
1168df01 | 6603 | |
987504bb JJ |
6604 | /* Look for the C++ and Java forms of the vtable. */ |
6605 | if ((cu->language == language_java | |
6606 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6607 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
6608 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
6609 | return 1; |
6610 | ||
6611 | return 0; | |
6612 | } | |
6613 | ||
c0dd20ea | 6614 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
6615 | functions, with the ABI-specified layout. If TYPE describes |
6616 | such a structure, smash it into a member function type. | |
61049d3b DJ |
6617 | |
6618 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
6619 | This is GCC PR debug/28767. */ | |
c0dd20ea | 6620 | |
0b92b5bb TT |
6621 | static void |
6622 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 6623 | { |
0b92b5bb | 6624 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
6625 | |
6626 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
6627 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
6628 | return; | |
c0dd20ea DJ |
6629 | |
6630 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
6631 | if (TYPE_FIELD_NAME (type, 0) == NULL |
6632 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
6633 | || TYPE_FIELD_NAME (type, 1) == NULL | |
6634 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
6635 | return; | |
c0dd20ea DJ |
6636 | |
6637 | /* Find the type of the method. */ | |
0b92b5bb | 6638 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
6639 | if (pfn_type == NULL |
6640 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
6641 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 6642 | return; |
c0dd20ea DJ |
6643 | |
6644 | /* Look for the "this" argument. */ | |
6645 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
6646 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 6647 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 6648 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 6649 | return; |
c0dd20ea DJ |
6650 | |
6651 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
6652 | new_type = alloc_type (objfile); |
6653 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
6654 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
6655 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 6656 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 6657 | } |
1168df01 | 6658 | |
c906108c | 6659 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
6660 | (definition) to create a type for the structure or union. Fill in |
6661 | the type's name and general properties; the members will not be | |
6662 | processed until process_structure_type. | |
c906108c | 6663 | |
c767944b DJ |
6664 | NOTE: we need to call these functions regardless of whether or not the |
6665 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
6666 | structure or union. This gets the type entered into our set of |
6667 | user defined types. | |
6668 | ||
6669 | However, if the structure is incomplete (an opaque struct/union) | |
6670 | then suppress creating a symbol table entry for it since gdb only | |
6671 | wants to find the one with the complete definition. Note that if | |
6672 | it is complete, we just call new_symbol, which does it's own | |
6673 | checking about whether the struct/union is anonymous or not (and | |
6674 | suppresses creating a symbol table entry itself). */ | |
6675 | ||
f792889a | 6676 | static struct type * |
134d01f1 | 6677 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6678 | { |
e7c27a73 | 6679 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6680 | struct type *type; |
6681 | struct attribute *attr; | |
39cbfefa | 6682 | char *name; |
c906108c | 6683 | |
348e048f DE |
6684 | /* If the definition of this type lives in .debug_types, read that type. |
6685 | Don't follow DW_AT_specification though, that will take us back up | |
6686 | the chain and we want to go down. */ | |
6687 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6688 | if (attr) | |
6689 | { | |
6690 | struct dwarf2_cu *type_cu = cu; | |
6691 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6692 | |
348e048f DE |
6693 | /* We could just recurse on read_structure_type, but we need to call |
6694 | get_die_type to ensure only one type for this DIE is created. | |
6695 | This is important, for example, because for c++ classes we need | |
6696 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
6697 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
6698 | |
6699 | /* TYPE_CU may not be the same as CU. | |
6700 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
6701 | return set_die_type (die, type, cu); |
6702 | } | |
6703 | ||
c0dd20ea | 6704 | type = alloc_type (objfile); |
c906108c | 6705 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 6706 | |
39cbfefa DJ |
6707 | name = dwarf2_name (die, cu); |
6708 | if (name != NULL) | |
c906108c | 6709 | { |
987504bb JJ |
6710 | if (cu->language == language_cplus |
6711 | || cu->language == language_java) | |
63d06c5c | 6712 | { |
3da10d80 KS |
6713 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
6714 | ||
6715 | /* dwarf2_full_name might have already finished building the DIE's | |
6716 | type. If so, there is no need to continue. */ | |
6717 | if (get_die_type (die, cu) != NULL) | |
6718 | return get_die_type (die, cu); | |
6719 | ||
6720 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
6721 | if (die->tag == DW_TAG_structure_type |
6722 | || die->tag == DW_TAG_class_type) | |
6723 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
6724 | } |
6725 | else | |
6726 | { | |
d8151005 DJ |
6727 | /* The name is already allocated along with this objfile, so |
6728 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
6729 | TYPE_TAG_NAME (type) = (char *) name; |
6730 | if (die->tag == DW_TAG_class_type) | |
6731 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 6732 | } |
c906108c SS |
6733 | } |
6734 | ||
6735 | if (die->tag == DW_TAG_structure_type) | |
6736 | { | |
6737 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
6738 | } | |
6739 | else if (die->tag == DW_TAG_union_type) | |
6740 | { | |
6741 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
6742 | } | |
6743 | else | |
6744 | { | |
c906108c SS |
6745 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
6746 | } | |
6747 | ||
0cc2414c TT |
6748 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
6749 | TYPE_DECLARED_CLASS (type) = 1; | |
6750 | ||
e142c38c | 6751 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6752 | if (attr) |
6753 | { | |
6754 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6755 | } | |
6756 | else | |
6757 | { | |
6758 | TYPE_LENGTH (type) = 0; | |
6759 | } | |
6760 | ||
876cecd0 | 6761 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 6762 | if (die_is_declaration (die, cu)) |
876cecd0 | 6763 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
6764 | else if (attr == NULL && die->child == NULL |
6765 | && producer_is_realview (cu->producer)) | |
6766 | /* RealView does not output the required DW_AT_declaration | |
6767 | on incomplete types. */ | |
6768 | TYPE_STUB (type) = 1; | |
dc718098 | 6769 | |
c906108c SS |
6770 | /* We need to add the type field to the die immediately so we don't |
6771 | infinitely recurse when dealing with pointers to the structure | |
6772 | type within the structure itself. */ | |
1c379e20 | 6773 | set_die_type (die, type, cu); |
c906108c | 6774 | |
7e314c57 JK |
6775 | /* set_die_type should be already done. */ |
6776 | set_descriptive_type (type, die, cu); | |
6777 | ||
c767944b DJ |
6778 | return type; |
6779 | } | |
6780 | ||
6781 | /* Finish creating a structure or union type, including filling in | |
6782 | its members and creating a symbol for it. */ | |
6783 | ||
6784 | static void | |
6785 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6786 | { | |
6787 | struct objfile *objfile = cu->objfile; | |
6788 | struct die_info *child_die = die->child; | |
6789 | struct type *type; | |
6790 | ||
6791 | type = get_die_type (die, cu); | |
6792 | if (type == NULL) | |
6793 | type = read_structure_type (die, cu); | |
6794 | ||
e142c38c | 6795 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
6796 | { |
6797 | struct field_info fi; | |
6798 | struct die_info *child_die; | |
34eaf542 | 6799 | VEC (symbolp) *template_args = NULL; |
c767944b | 6800 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
6801 | |
6802 | memset (&fi, 0, sizeof (struct field_info)); | |
6803 | ||
639d11d3 | 6804 | child_die = die->child; |
c906108c SS |
6805 | |
6806 | while (child_die && child_die->tag) | |
6807 | { | |
a9a9bd0f DC |
6808 | if (child_die->tag == DW_TAG_member |
6809 | || child_die->tag == DW_TAG_variable) | |
c906108c | 6810 | { |
a9a9bd0f DC |
6811 | /* NOTE: carlton/2002-11-05: A C++ static data member |
6812 | should be a DW_TAG_member that is a declaration, but | |
6813 | all versions of G++ as of this writing (so through at | |
6814 | least 3.2.1) incorrectly generate DW_TAG_variable | |
6815 | tags for them instead. */ | |
e7c27a73 | 6816 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6817 | } |
8713b1b1 | 6818 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
6819 | { |
6820 | /* C++ member function. */ | |
e7c27a73 | 6821 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
6822 | } |
6823 | else if (child_die->tag == DW_TAG_inheritance) | |
6824 | { | |
6825 | /* C++ base class field. */ | |
e7c27a73 | 6826 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6827 | } |
98751a41 JK |
6828 | else if (child_die->tag == DW_TAG_typedef) |
6829 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
6830 | else if (child_die->tag == DW_TAG_template_type_param |
6831 | || child_die->tag == DW_TAG_template_value_param) | |
6832 | { | |
6833 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
6834 | ||
f1078f66 DJ |
6835 | if (arg != NULL) |
6836 | VEC_safe_push (symbolp, template_args, arg); | |
34eaf542 TT |
6837 | } |
6838 | ||
c906108c SS |
6839 | child_die = sibling_die (child_die); |
6840 | } | |
6841 | ||
34eaf542 TT |
6842 | /* Attach template arguments to type. */ |
6843 | if (! VEC_empty (symbolp, template_args)) | |
6844 | { | |
6845 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6846 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6847 | = VEC_length (symbolp, template_args); | |
6848 | TYPE_TEMPLATE_ARGUMENTS (type) | |
6849 | = obstack_alloc (&objfile->objfile_obstack, | |
6850 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6851 | * sizeof (struct symbol *))); | |
6852 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
6853 | VEC_address (symbolp, template_args), | |
6854 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6855 | * sizeof (struct symbol *))); | |
6856 | VEC_free (symbolp, template_args); | |
6857 | } | |
6858 | ||
c906108c SS |
6859 | /* Attach fields and member functions to the type. */ |
6860 | if (fi.nfields) | |
e7c27a73 | 6861 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
6862 | if (fi.nfnfields) |
6863 | { | |
e7c27a73 | 6864 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 6865 | |
c5aa993b | 6866 | /* Get the type which refers to the base class (possibly this |
c906108c | 6867 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
6868 | class from the DW_AT_containing_type attribute. This use of |
6869 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 6870 | |
e142c38c | 6871 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 6872 | { |
e7c27a73 | 6873 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
6874 | |
6875 | TYPE_VPTR_BASETYPE (type) = t; | |
6876 | if (type == t) | |
6877 | { | |
c906108c SS |
6878 | int i; |
6879 | ||
6880 | /* Our own class provides vtbl ptr. */ | |
6881 | for (i = TYPE_NFIELDS (t) - 1; | |
6882 | i >= TYPE_N_BASECLASSES (t); | |
6883 | --i) | |
6884 | { | |
6885 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
6886 | ||
1168df01 | 6887 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
6888 | { |
6889 | TYPE_VPTR_FIELDNO (type) = i; | |
6890 | break; | |
6891 | } | |
6892 | } | |
6893 | ||
6894 | /* Complain if virtual function table field not found. */ | |
6895 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 6896 | complaint (&symfile_complaints, |
e2e0b3e5 | 6897 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
6898 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
6899 | ""); | |
c906108c SS |
6900 | } |
6901 | else | |
6902 | { | |
6903 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
6904 | } | |
6905 | } | |
f6235d4c EZ |
6906 | else if (cu->producer |
6907 | && strncmp (cu->producer, | |
6908 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
6909 | { | |
6910 | /* The IBM XLC compiler does not provide direct indication | |
6911 | of the containing type, but the vtable pointer is | |
6912 | always named __vfp. */ | |
6913 | ||
6914 | int i; | |
6915 | ||
6916 | for (i = TYPE_NFIELDS (type) - 1; | |
6917 | i >= TYPE_N_BASECLASSES (type); | |
6918 | --i) | |
6919 | { | |
6920 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
6921 | { | |
6922 | TYPE_VPTR_FIELDNO (type) = i; | |
6923 | TYPE_VPTR_BASETYPE (type) = type; | |
6924 | break; | |
6925 | } | |
6926 | } | |
6927 | } | |
c906108c | 6928 | } |
98751a41 JK |
6929 | |
6930 | /* Copy fi.typedef_field_list linked list elements content into the | |
6931 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
6932 | if (fi.typedef_field_list) | |
6933 | { | |
6934 | int i = fi.typedef_field_list_count; | |
6935 | ||
a0d7a4ff | 6936 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
6937 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
6938 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
6939 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
6940 | ||
6941 | /* Reverse the list order to keep the debug info elements order. */ | |
6942 | while (--i >= 0) | |
6943 | { | |
6944 | struct typedef_field *dest, *src; | |
6e70227d | 6945 | |
98751a41 JK |
6946 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
6947 | src = &fi.typedef_field_list->field; | |
6948 | fi.typedef_field_list = fi.typedef_field_list->next; | |
6949 | *dest = *src; | |
6950 | } | |
6951 | } | |
c767944b DJ |
6952 | |
6953 | do_cleanups (back_to); | |
c906108c | 6954 | } |
63d06c5c | 6955 | |
0b92b5bb TT |
6956 | quirk_gcc_member_function_pointer (type, cu->objfile); |
6957 | ||
90aeadfc DC |
6958 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
6959 | snapshots) has been known to create a die giving a declaration | |
6960 | for a class that has, as a child, a die giving a definition for a | |
6961 | nested class. So we have to process our children even if the | |
6962 | current die is a declaration. Normally, of course, a declaration | |
6963 | won't have any children at all. */ | |
134d01f1 | 6964 | |
90aeadfc DC |
6965 | while (child_die != NULL && child_die->tag) |
6966 | { | |
6967 | if (child_die->tag == DW_TAG_member | |
6968 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
6969 | || child_die->tag == DW_TAG_inheritance |
6970 | || child_die->tag == DW_TAG_template_value_param | |
6971 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 6972 | { |
90aeadfc | 6973 | /* Do nothing. */ |
134d01f1 | 6974 | } |
90aeadfc DC |
6975 | else |
6976 | process_die (child_die, cu); | |
134d01f1 | 6977 | |
90aeadfc | 6978 | child_die = sibling_die (child_die); |
134d01f1 DJ |
6979 | } |
6980 | ||
fa4028e9 JB |
6981 | /* Do not consider external references. According to the DWARF standard, |
6982 | these DIEs are identified by the fact that they have no byte_size | |
6983 | attribute, and a declaration attribute. */ | |
6984 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
6985 | || !die_is_declaration (die, cu)) | |
c767944b | 6986 | new_symbol (die, type, cu); |
134d01f1 DJ |
6987 | } |
6988 | ||
6989 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
6990 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 6991 | |
f792889a | 6992 | static struct type * |
134d01f1 | 6993 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6994 | { |
e7c27a73 | 6995 | struct objfile *objfile = cu->objfile; |
c906108c | 6996 | struct type *type; |
c906108c | 6997 | struct attribute *attr; |
0114d602 | 6998 | const char *name; |
134d01f1 | 6999 | |
348e048f DE |
7000 | /* If the definition of this type lives in .debug_types, read that type. |
7001 | Don't follow DW_AT_specification though, that will take us back up | |
7002 | the chain and we want to go down. */ | |
7003 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
7004 | if (attr) | |
7005 | { | |
7006 | struct dwarf2_cu *type_cu = cu; | |
7007 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 7008 | |
348e048f | 7009 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
7010 | |
7011 | /* TYPE_CU may not be the same as CU. | |
7012 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
7013 | return set_die_type (die, type, cu); |
7014 | } | |
7015 | ||
c906108c SS |
7016 | type = alloc_type (objfile); |
7017 | ||
7018 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7019 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7020 | if (name != NULL) |
0114d602 | 7021 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7022 | |
e142c38c | 7023 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7024 | if (attr) |
7025 | { | |
7026 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7027 | } | |
7028 | else | |
7029 | { | |
7030 | TYPE_LENGTH (type) = 0; | |
7031 | } | |
7032 | ||
137033e9 JB |
7033 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7034 | declared as private in the package spec, and then defined only | |
7035 | inside the package body. Such types are known as Taft Amendment | |
7036 | Types. When another package uses such a type, an incomplete DIE | |
7037 | may be generated by the compiler. */ | |
02eb380e | 7038 | if (die_is_declaration (die, cu)) |
876cecd0 | 7039 | TYPE_STUB (type) = 1; |
02eb380e | 7040 | |
f792889a | 7041 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7042 | } |
7043 | ||
7044 | /* Given a pointer to a die which begins an enumeration, process all | |
7045 | the dies that define the members of the enumeration, and create the | |
7046 | symbol for the enumeration type. | |
7047 | ||
7048 | NOTE: We reverse the order of the element list. */ | |
7049 | ||
7050 | static void | |
7051 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7052 | { | |
f792889a | 7053 | struct type *this_type; |
134d01f1 | 7054 | |
f792889a DJ |
7055 | this_type = get_die_type (die, cu); |
7056 | if (this_type == NULL) | |
7057 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7058 | |
639d11d3 | 7059 | if (die->child != NULL) |
c906108c | 7060 | { |
9dc481d3 DE |
7061 | struct die_info *child_die; |
7062 | struct symbol *sym; | |
7063 | struct field *fields = NULL; | |
7064 | int num_fields = 0; | |
7065 | int unsigned_enum = 1; | |
7066 | char *name; | |
7067 | ||
639d11d3 | 7068 | child_die = die->child; |
c906108c SS |
7069 | while (child_die && child_die->tag) |
7070 | { | |
7071 | if (child_die->tag != DW_TAG_enumerator) | |
7072 | { | |
e7c27a73 | 7073 | process_die (child_die, cu); |
c906108c SS |
7074 | } |
7075 | else | |
7076 | { | |
39cbfefa DJ |
7077 | name = dwarf2_name (child_die, cu); |
7078 | if (name) | |
c906108c | 7079 | { |
f792889a | 7080 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7081 | if (SYMBOL_VALUE (sym) < 0) |
7082 | unsigned_enum = 0; | |
7083 | ||
7084 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7085 | { | |
7086 | fields = (struct field *) | |
7087 | xrealloc (fields, | |
7088 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7089 | * sizeof (struct field)); |
c906108c SS |
7090 | } |
7091 | ||
3567439c | 7092 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7093 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7094 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7095 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7096 | ||
7097 | num_fields++; | |
7098 | } | |
7099 | } | |
7100 | ||
7101 | child_die = sibling_die (child_die); | |
7102 | } | |
7103 | ||
7104 | if (num_fields) | |
7105 | { | |
f792889a DJ |
7106 | TYPE_NFIELDS (this_type) = num_fields; |
7107 | TYPE_FIELDS (this_type) = (struct field *) | |
7108 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7109 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7110 | sizeof (struct field) * num_fields); |
b8c9b27d | 7111 | xfree (fields); |
c906108c SS |
7112 | } |
7113 | if (unsigned_enum) | |
876cecd0 | 7114 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7115 | } |
134d01f1 | 7116 | |
f792889a | 7117 | new_symbol (die, this_type, cu); |
c906108c SS |
7118 | } |
7119 | ||
7120 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7121 | the DIE's type field. For now, this only handles one dimensional | |
7122 | arrays. */ | |
7123 | ||
f792889a | 7124 | static struct type * |
e7c27a73 | 7125 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7126 | { |
e7c27a73 | 7127 | struct objfile *objfile = cu->objfile; |
c906108c | 7128 | struct die_info *child_die; |
7e314c57 | 7129 | struct type *type; |
c906108c SS |
7130 | struct type *element_type, *range_type, *index_type; |
7131 | struct type **range_types = NULL; | |
7132 | struct attribute *attr; | |
7133 | int ndim = 0; | |
7134 | struct cleanup *back_to; | |
39cbfefa | 7135 | char *name; |
c906108c | 7136 | |
e7c27a73 | 7137 | element_type = die_type (die, cu); |
c906108c | 7138 | |
7e314c57 JK |
7139 | /* The die_type call above may have already set the type for this DIE. */ |
7140 | type = get_die_type (die, cu); | |
7141 | if (type) | |
7142 | return type; | |
7143 | ||
c906108c SS |
7144 | /* Irix 6.2 native cc creates array types without children for |
7145 | arrays with unspecified length. */ | |
639d11d3 | 7146 | if (die->child == NULL) |
c906108c | 7147 | { |
46bf5051 | 7148 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7149 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
7150 | type = create_array_type (NULL, element_type, range_type); |
7151 | return set_die_type (die, type, cu); | |
c906108c SS |
7152 | } |
7153 | ||
7154 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 7155 | child_die = die->child; |
c906108c SS |
7156 | while (child_die && child_die->tag) |
7157 | { | |
7158 | if (child_die->tag == DW_TAG_subrange_type) | |
7159 | { | |
f792889a | 7160 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 7161 | |
f792889a | 7162 | if (child_type != NULL) |
a02abb62 JB |
7163 | { |
7164 | /* The range type was succesfully read. Save it for | |
7165 | the array type creation. */ | |
7166 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
7167 | { | |
7168 | range_types = (struct type **) | |
7169 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
7170 | * sizeof (struct type *)); | |
7171 | if (ndim == 0) | |
7172 | make_cleanup (free_current_contents, &range_types); | |
7173 | } | |
f792889a | 7174 | range_types[ndim++] = child_type; |
a02abb62 | 7175 | } |
c906108c SS |
7176 | } |
7177 | child_die = sibling_die (child_die); | |
7178 | } | |
7179 | ||
7180 | /* Dwarf2 dimensions are output from left to right, create the | |
7181 | necessary array types in backwards order. */ | |
7ca2d3a3 | 7182 | |
c906108c | 7183 | type = element_type; |
7ca2d3a3 DL |
7184 | |
7185 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
7186 | { | |
7187 | int i = 0; | |
9a619af0 | 7188 | |
7ca2d3a3 DL |
7189 | while (i < ndim) |
7190 | type = create_array_type (NULL, type, range_types[i++]); | |
7191 | } | |
7192 | else | |
7193 | { | |
7194 | while (ndim-- > 0) | |
7195 | type = create_array_type (NULL, type, range_types[ndim]); | |
7196 | } | |
c906108c | 7197 | |
f5f8a009 EZ |
7198 | /* Understand Dwarf2 support for vector types (like they occur on |
7199 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
7200 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
7201 | custom vendor extension. The main difference between a regular | |
7202 | array and the vector variant is that vectors are passed by value | |
7203 | to functions. */ | |
e142c38c | 7204 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 7205 | if (attr) |
ea37ba09 | 7206 | make_vector_type (type); |
f5f8a009 | 7207 | |
39cbfefa DJ |
7208 | name = dwarf2_name (die, cu); |
7209 | if (name) | |
7210 | TYPE_NAME (type) = name; | |
6e70227d | 7211 | |
7e314c57 JK |
7212 | /* Install the type in the die. */ |
7213 | set_die_type (die, type, cu); | |
7214 | ||
7215 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7216 | set_descriptive_type (type, die, cu); |
7217 | ||
c906108c SS |
7218 | do_cleanups (back_to); |
7219 | ||
7e314c57 | 7220 | return type; |
c906108c SS |
7221 | } |
7222 | ||
7ca2d3a3 | 7223 | static enum dwarf_array_dim_ordering |
6e70227d | 7224 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
7225 | { |
7226 | struct attribute *attr; | |
7227 | ||
7228 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
7229 | ||
7230 | if (attr) return DW_SND (attr); | |
7231 | ||
7232 | /* | |
7233 | GNU F77 is a special case, as at 08/2004 array type info is the | |
6e70227d | 7234 | opposite order to the dwarf2 specification, but data is still |
7ca2d3a3 DL |
7235 | laid out as per normal fortran. |
7236 | ||
6e70227d | 7237 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7ca2d3a3 DL |
7238 | version checking. |
7239 | */ | |
7240 | ||
905e0470 PM |
7241 | if (cu->language == language_fortran |
7242 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
7243 | { |
7244 | return DW_ORD_row_major; | |
7245 | } | |
7246 | ||
6e70227d | 7247 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
7248 | { |
7249 | case array_column_major: | |
7250 | return DW_ORD_col_major; | |
7251 | case array_row_major: | |
7252 | default: | |
7253 | return DW_ORD_row_major; | |
7254 | }; | |
7255 | } | |
7256 | ||
72019c9c GM |
7257 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
7258 | the DIE's type field. */ | |
7259 | ||
f792889a | 7260 | static struct type * |
72019c9c GM |
7261 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
7262 | { | |
7e314c57 JK |
7263 | struct type *domain_type, *set_type; |
7264 | struct attribute *attr; | |
f792889a | 7265 | |
7e314c57 JK |
7266 | domain_type = die_type (die, cu); |
7267 | ||
7268 | /* The die_type call above may have already set the type for this DIE. */ | |
7269 | set_type = get_die_type (die, cu); | |
7270 | if (set_type) | |
7271 | return set_type; | |
7272 | ||
7273 | set_type = create_set_type (NULL, domain_type); | |
7274 | ||
7275 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
7276 | if (attr) |
7277 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 7278 | |
f792889a | 7279 | return set_die_type (die, set_type, cu); |
72019c9c | 7280 | } |
7ca2d3a3 | 7281 | |
c906108c SS |
7282 | /* First cut: install each common block member as a global variable. */ |
7283 | ||
7284 | static void | |
e7c27a73 | 7285 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7286 | { |
7287 | struct die_info *child_die; | |
7288 | struct attribute *attr; | |
7289 | struct symbol *sym; | |
7290 | CORE_ADDR base = (CORE_ADDR) 0; | |
7291 | ||
e142c38c | 7292 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7293 | if (attr) |
7294 | { | |
8e19ed76 PS |
7295 | /* Support the .debug_loc offsets */ |
7296 | if (attr_form_is_block (attr)) | |
7297 | { | |
e7c27a73 | 7298 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 7299 | } |
3690dd37 | 7300 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7301 | { |
4d3c2250 | 7302 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7303 | } |
7304 | else | |
7305 | { | |
4d3c2250 KB |
7306 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
7307 | "common block member"); | |
8e19ed76 | 7308 | } |
c906108c | 7309 | } |
639d11d3 | 7310 | if (die->child != NULL) |
c906108c | 7311 | { |
639d11d3 | 7312 | child_die = die->child; |
c906108c SS |
7313 | while (child_die && child_die->tag) |
7314 | { | |
e7c27a73 | 7315 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 7316 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
f1078f66 | 7317 | if (sym != NULL && attr != NULL) |
c906108c | 7318 | { |
d4b96c9a JK |
7319 | CORE_ADDR byte_offset = 0; |
7320 | ||
7321 | if (attr_form_is_section_offset (attr)) | |
7322 | dwarf2_complex_location_expr_complaint (); | |
7323 | else if (attr_form_is_constant (attr)) | |
7324 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
7325 | else if (attr_form_is_block (attr)) | |
7326 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
7327 | else | |
7328 | dwarf2_complex_location_expr_complaint (); | |
7329 | ||
7330 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
7331 | add_symbol_to_list (sym, &global_symbols); |
7332 | } | |
7333 | child_die = sibling_die (child_die); | |
7334 | } | |
7335 | } | |
7336 | } | |
7337 | ||
0114d602 | 7338 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 7339 | |
0114d602 DJ |
7340 | static struct type * |
7341 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 7342 | { |
e7c27a73 | 7343 | struct objfile *objfile = cu->objfile; |
0114d602 | 7344 | const char *previous_prefix, *name; |
9219021c | 7345 | int is_anonymous; |
0114d602 DJ |
7346 | struct type *type; |
7347 | ||
7348 | /* For extensions, reuse the type of the original namespace. */ | |
7349 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
7350 | { | |
7351 | struct die_info *ext_die; | |
7352 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 7353 | |
0114d602 DJ |
7354 | ext_die = dwarf2_extension (die, &ext_cu); |
7355 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
7356 | |
7357 | /* EXT_CU may not be the same as CU. | |
7358 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
7359 | return set_die_type (die, type, cu); |
7360 | } | |
9219021c | 7361 | |
e142c38c | 7362 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
7363 | |
7364 | /* Now build the name of the current namespace. */ | |
7365 | ||
0114d602 DJ |
7366 | previous_prefix = determine_prefix (die, cu); |
7367 | if (previous_prefix[0] != '\0') | |
7368 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 7369 | previous_prefix, name, 0, cu); |
0114d602 DJ |
7370 | |
7371 | /* Create the type. */ | |
7372 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
7373 | objfile); | |
7374 | TYPE_NAME (type) = (char *) name; | |
7375 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7376 | ||
60531b24 | 7377 | return set_die_type (die, type, cu); |
0114d602 DJ |
7378 | } |
7379 | ||
7380 | /* Read a C++ namespace. */ | |
7381 | ||
7382 | static void | |
7383 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
7384 | { | |
7385 | struct objfile *objfile = cu->objfile; | |
7386 | const char *name; | |
7387 | int is_anonymous; | |
9219021c | 7388 | |
5c4e30ca DC |
7389 | /* Add a symbol associated to this if we haven't seen the namespace |
7390 | before. Also, add a using directive if it's an anonymous | |
7391 | namespace. */ | |
9219021c | 7392 | |
f2f0e013 | 7393 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
7394 | { |
7395 | struct type *type; | |
7396 | ||
0114d602 | 7397 | type = read_type_die (die, cu); |
e7c27a73 | 7398 | new_symbol (die, type, cu); |
5c4e30ca | 7399 | |
0114d602 | 7400 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 7401 | if (is_anonymous) |
0114d602 DJ |
7402 | { |
7403 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 7404 | |
c0cc3a76 | 7405 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 7406 | NULL, &objfile->objfile_obstack); |
0114d602 | 7407 | } |
5c4e30ca | 7408 | } |
9219021c | 7409 | |
639d11d3 | 7410 | if (die->child != NULL) |
d9fa45fe | 7411 | { |
639d11d3 | 7412 | struct die_info *child_die = die->child; |
6e70227d | 7413 | |
d9fa45fe DC |
7414 | while (child_die && child_die->tag) |
7415 | { | |
e7c27a73 | 7416 | process_die (child_die, cu); |
d9fa45fe DC |
7417 | child_die = sibling_die (child_die); |
7418 | } | |
7419 | } | |
38d518c9 EZ |
7420 | } |
7421 | ||
f55ee35c JK |
7422 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
7423 | imported module. Still we need that type as local Fortran "use ... only" | |
7424 | declaration imports depend on the created type in determine_prefix. */ | |
7425 | ||
7426 | static struct type * | |
7427 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
7428 | { | |
7429 | struct objfile *objfile = cu->objfile; | |
7430 | char *module_name; | |
7431 | struct type *type; | |
7432 | ||
7433 | module_name = dwarf2_name (die, cu); | |
7434 | if (!module_name) | |
7435 | complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"), | |
7436 | die->offset); | |
7437 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
7438 | ||
7439 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
7440 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7441 | ||
7442 | return set_die_type (die, type, cu); | |
7443 | } | |
7444 | ||
5d7cb8df JK |
7445 | /* Read a Fortran module. */ |
7446 | ||
7447 | static void | |
7448 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
7449 | { | |
7450 | struct die_info *child_die = die->child; | |
7451 | ||
5d7cb8df JK |
7452 | while (child_die && child_die->tag) |
7453 | { | |
7454 | process_die (child_die, cu); | |
7455 | child_die = sibling_die (child_die); | |
7456 | } | |
7457 | } | |
7458 | ||
38d518c9 EZ |
7459 | /* Return the name of the namespace represented by DIE. Set |
7460 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
7461 | namespace. */ | |
7462 | ||
7463 | static const char * | |
e142c38c | 7464 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
7465 | { |
7466 | struct die_info *current_die; | |
7467 | const char *name = NULL; | |
7468 | ||
7469 | /* Loop through the extensions until we find a name. */ | |
7470 | ||
7471 | for (current_die = die; | |
7472 | current_die != NULL; | |
f2f0e013 | 7473 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 7474 | { |
e142c38c | 7475 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
7476 | if (name != NULL) |
7477 | break; | |
7478 | } | |
7479 | ||
7480 | /* Is it an anonymous namespace? */ | |
7481 | ||
7482 | *is_anonymous = (name == NULL); | |
7483 | if (*is_anonymous) | |
7484 | name = "(anonymous namespace)"; | |
7485 | ||
7486 | return name; | |
d9fa45fe DC |
7487 | } |
7488 | ||
c906108c SS |
7489 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
7490 | the user defined type vector. */ | |
7491 | ||
f792889a | 7492 | static struct type * |
e7c27a73 | 7493 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7494 | { |
5e2b427d | 7495 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 7496 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 7497 | struct type *type; |
8b2dbe47 KB |
7498 | struct attribute *attr_byte_size; |
7499 | struct attribute *attr_address_class; | |
7500 | int byte_size, addr_class; | |
7e314c57 JK |
7501 | struct type *target_type; |
7502 | ||
7503 | target_type = die_type (die, cu); | |
c906108c | 7504 | |
7e314c57 JK |
7505 | /* The die_type call above may have already set the type for this DIE. */ |
7506 | type = get_die_type (die, cu); | |
7507 | if (type) | |
7508 | return type; | |
7509 | ||
7510 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 7511 | |
e142c38c | 7512 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
7513 | if (attr_byte_size) |
7514 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 7515 | else |
8b2dbe47 KB |
7516 | byte_size = cu_header->addr_size; |
7517 | ||
e142c38c | 7518 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
7519 | if (attr_address_class) |
7520 | addr_class = DW_UNSND (attr_address_class); | |
7521 | else | |
7522 | addr_class = DW_ADDR_none; | |
7523 | ||
7524 | /* If the pointer size or address class is different than the | |
7525 | default, create a type variant marked as such and set the | |
7526 | length accordingly. */ | |
7527 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 7528 | { |
5e2b427d | 7529 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
7530 | { |
7531 | int type_flags; | |
7532 | ||
849957d9 | 7533 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 7534 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
7535 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
7536 | == 0); | |
8b2dbe47 KB |
7537 | type = make_type_with_address_space (type, type_flags); |
7538 | } | |
7539 | else if (TYPE_LENGTH (type) != byte_size) | |
7540 | { | |
e2e0b3e5 | 7541 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 | 7542 | } |
6e70227d | 7543 | else |
9a619af0 MS |
7544 | { |
7545 | /* Should we also complain about unhandled address classes? */ | |
7546 | } | |
c906108c | 7547 | } |
8b2dbe47 KB |
7548 | |
7549 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 7550 | return set_die_type (die, type, cu); |
c906108c SS |
7551 | } |
7552 | ||
7553 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
7554 | the user defined type vector. */ | |
7555 | ||
f792889a | 7556 | static struct type * |
e7c27a73 | 7557 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7558 | { |
7559 | struct type *type; | |
7560 | struct type *to_type; | |
7561 | struct type *domain; | |
7562 | ||
e7c27a73 DJ |
7563 | to_type = die_type (die, cu); |
7564 | domain = die_containing_type (die, cu); | |
0d5de010 | 7565 | |
7e314c57 JK |
7566 | /* The calls above may have already set the type for this DIE. */ |
7567 | type = get_die_type (die, cu); | |
7568 | if (type) | |
7569 | return type; | |
7570 | ||
0d5de010 DJ |
7571 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
7572 | type = lookup_methodptr_type (to_type); | |
7573 | else | |
7574 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 7575 | |
f792889a | 7576 | return set_die_type (die, type, cu); |
c906108c SS |
7577 | } |
7578 | ||
7579 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
7580 | the user defined type vector. */ | |
7581 | ||
f792889a | 7582 | static struct type * |
e7c27a73 | 7583 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7584 | { |
e7c27a73 | 7585 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 7586 | struct type *type, *target_type; |
c906108c SS |
7587 | struct attribute *attr; |
7588 | ||
7e314c57 JK |
7589 | target_type = die_type (die, cu); |
7590 | ||
7591 | /* The die_type call above may have already set the type for this DIE. */ | |
7592 | type = get_die_type (die, cu); | |
7593 | if (type) | |
7594 | return type; | |
7595 | ||
7596 | type = lookup_reference_type (target_type); | |
e142c38c | 7597 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7598 | if (attr) |
7599 | { | |
7600 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7601 | } | |
7602 | else | |
7603 | { | |
107d2387 | 7604 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 7605 | } |
f792889a | 7606 | return set_die_type (die, type, cu); |
c906108c SS |
7607 | } |
7608 | ||
f792889a | 7609 | static struct type * |
e7c27a73 | 7610 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7611 | { |
f792889a | 7612 | struct type *base_type, *cv_type; |
c906108c | 7613 | |
e7c27a73 | 7614 | base_type = die_type (die, cu); |
7e314c57 JK |
7615 | |
7616 | /* The die_type call above may have already set the type for this DIE. */ | |
7617 | cv_type = get_die_type (die, cu); | |
7618 | if (cv_type) | |
7619 | return cv_type; | |
7620 | ||
f792889a DJ |
7621 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
7622 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7623 | } |
7624 | ||
f792889a | 7625 | static struct type * |
e7c27a73 | 7626 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7627 | { |
f792889a | 7628 | struct type *base_type, *cv_type; |
c906108c | 7629 | |
e7c27a73 | 7630 | base_type = die_type (die, cu); |
7e314c57 JK |
7631 | |
7632 | /* The die_type call above may have already set the type for this DIE. */ | |
7633 | cv_type = get_die_type (die, cu); | |
7634 | if (cv_type) | |
7635 | return cv_type; | |
7636 | ||
f792889a DJ |
7637 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
7638 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7639 | } |
7640 | ||
7641 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
7642 | the user defined type vector. It isn't really a user defined type, | |
7643 | but it behaves like one, with other DIE's using an AT_user_def_type | |
7644 | attribute to reference it. */ | |
7645 | ||
f792889a | 7646 | static struct type * |
e7c27a73 | 7647 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7648 | { |
e7c27a73 | 7649 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 7650 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7651 | struct type *type, *range_type, *index_type, *char_type; |
7652 | struct attribute *attr; | |
7653 | unsigned int length; | |
7654 | ||
e142c38c | 7655 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
7656 | if (attr) |
7657 | { | |
7658 | length = DW_UNSND (attr); | |
7659 | } | |
7660 | else | |
7661 | { | |
b21b22e0 | 7662 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 7663 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
7664 | if (attr) |
7665 | { | |
7666 | length = DW_UNSND (attr); | |
7667 | } | |
7668 | else | |
7669 | { | |
7670 | length = 1; | |
7671 | } | |
c906108c | 7672 | } |
6ccb9162 | 7673 | |
46bf5051 | 7674 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7675 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
7676 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
7677 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 7678 | |
f792889a | 7679 | return set_die_type (die, type, cu); |
c906108c SS |
7680 | } |
7681 | ||
7682 | /* Handle DIES due to C code like: | |
7683 | ||
7684 | struct foo | |
c5aa993b JM |
7685 | { |
7686 | int (*funcp)(int a, long l); | |
7687 | int b; | |
7688 | }; | |
c906108c SS |
7689 | |
7690 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 7691 | */ |
c906108c | 7692 | |
f792889a | 7693 | static struct type * |
e7c27a73 | 7694 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7695 | { |
7696 | struct type *type; /* Type that this function returns */ | |
7697 | struct type *ftype; /* Function that returns above type */ | |
7698 | struct attribute *attr; | |
7699 | ||
e7c27a73 | 7700 | type = die_type (die, cu); |
7e314c57 JK |
7701 | |
7702 | /* The die_type call above may have already set the type for this DIE. */ | |
7703 | ftype = get_die_type (die, cu); | |
7704 | if (ftype) | |
7705 | return ftype; | |
7706 | ||
0c8b41f1 | 7707 | ftype = lookup_function_type (type); |
c906108c | 7708 | |
5b8101ae | 7709 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 7710 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 7711 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 7712 | || cu->language == language_cplus |
5b8101ae PM |
7713 | || cu->language == language_java |
7714 | || cu->language == language_pascal) | |
876cecd0 | 7715 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
7716 | else if (producer_is_realview (cu->producer)) |
7717 | /* RealView does not emit DW_AT_prototyped. We can not | |
7718 | distinguish prototyped and unprototyped functions; default to | |
7719 | prototyped, since that is more common in modern code (and | |
7720 | RealView warns about unprototyped functions). */ | |
7721 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 7722 | |
c055b101 CV |
7723 | /* Store the calling convention in the type if it's available in |
7724 | the subroutine die. Otherwise set the calling convention to | |
7725 | the default value DW_CC_normal. */ | |
7726 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
7727 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
7728 | |
7729 | /* We need to add the subroutine type to the die immediately so | |
7730 | we don't infinitely recurse when dealing with parameters | |
7731 | declared as the same subroutine type. */ | |
7732 | set_die_type (die, ftype, cu); | |
6e70227d | 7733 | |
639d11d3 | 7734 | if (die->child != NULL) |
c906108c | 7735 | { |
8072405b | 7736 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 7737 | struct die_info *child_die; |
8072405b | 7738 | int nparams, iparams; |
c906108c SS |
7739 | |
7740 | /* Count the number of parameters. | |
7741 | FIXME: GDB currently ignores vararg functions, but knows about | |
7742 | vararg member functions. */ | |
8072405b | 7743 | nparams = 0; |
639d11d3 | 7744 | child_die = die->child; |
c906108c SS |
7745 | while (child_die && child_die->tag) |
7746 | { | |
7747 | if (child_die->tag == DW_TAG_formal_parameter) | |
7748 | nparams++; | |
7749 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 7750 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
7751 | child_die = sibling_die (child_die); |
7752 | } | |
7753 | ||
7754 | /* Allocate storage for parameters and fill them in. */ | |
7755 | TYPE_NFIELDS (ftype) = nparams; | |
7756 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 7757 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 7758 | |
8072405b JK |
7759 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
7760 | even if we error out during the parameters reading below. */ | |
7761 | for (iparams = 0; iparams < nparams; iparams++) | |
7762 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
7763 | ||
7764 | iparams = 0; | |
639d11d3 | 7765 | child_die = die->child; |
c906108c SS |
7766 | while (child_die && child_die->tag) |
7767 | { | |
7768 | if (child_die->tag == DW_TAG_formal_parameter) | |
7769 | { | |
3ce3b1ba PA |
7770 | struct type *arg_type; |
7771 | ||
7772 | /* DWARF version 2 has no clean way to discern C++ | |
7773 | static and non-static member functions. G++ helps | |
7774 | GDB by marking the first parameter for non-static | |
7775 | member functions (which is the this pointer) as | |
7776 | artificial. We pass this information to | |
7777 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
7778 | ||
7779 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
7780 | 4.5 does not yet generate. */ | |
e142c38c | 7781 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
7782 | if (attr) |
7783 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
7784 | else | |
418835cc KS |
7785 | { |
7786 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
7787 | ||
7788 | /* GCC/43521: In java, the formal parameter | |
7789 | "this" is sometimes not marked with DW_AT_artificial. */ | |
7790 | if (cu->language == language_java) | |
7791 | { | |
7792 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 7793 | |
418835cc KS |
7794 | if (name && !strcmp (name, "this")) |
7795 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
7796 | } | |
7797 | } | |
3ce3b1ba PA |
7798 | arg_type = die_type (child_die, cu); |
7799 | ||
7800 | /* RealView does not mark THIS as const, which the testsuite | |
7801 | expects. GCC marks THIS as const in method definitions, | |
7802 | but not in the class specifications (GCC PR 43053). */ | |
7803 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
7804 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
7805 | { | |
7806 | int is_this = 0; | |
7807 | struct dwarf2_cu *arg_cu = cu; | |
7808 | const char *name = dwarf2_name (child_die, cu); | |
7809 | ||
7810 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
7811 | if (attr) | |
7812 | { | |
7813 | /* If the compiler emits this, use it. */ | |
7814 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
7815 | is_this = 1; | |
7816 | } | |
7817 | else if (name && strcmp (name, "this") == 0) | |
7818 | /* Function definitions will have the argument names. */ | |
7819 | is_this = 1; | |
7820 | else if (name == NULL && iparams == 0) | |
7821 | /* Declarations may not have the names, so like | |
7822 | elsewhere in GDB, assume an artificial first | |
7823 | argument is "this". */ | |
7824 | is_this = 1; | |
7825 | ||
7826 | if (is_this) | |
7827 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
7828 | arg_type, 0); | |
7829 | } | |
7830 | ||
7831 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
7832 | iparams++; |
7833 | } | |
7834 | child_die = sibling_die (child_die); | |
7835 | } | |
7836 | } | |
7837 | ||
76c10ea2 | 7838 | return ftype; |
c906108c SS |
7839 | } |
7840 | ||
f792889a | 7841 | static struct type * |
e7c27a73 | 7842 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7843 | { |
e7c27a73 | 7844 | struct objfile *objfile = cu->objfile; |
0114d602 | 7845 | const char *name = NULL; |
f792889a | 7846 | struct type *this_type; |
c906108c | 7847 | |
94af9270 | 7848 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 7849 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
7850 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
7851 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
7852 | set_die_type (die, this_type, cu); |
7853 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
7854 | return this_type; | |
c906108c SS |
7855 | } |
7856 | ||
7857 | /* Find a representation of a given base type and install | |
7858 | it in the TYPE field of the die. */ | |
7859 | ||
f792889a | 7860 | static struct type * |
e7c27a73 | 7861 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7862 | { |
e7c27a73 | 7863 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7864 | struct type *type; |
7865 | struct attribute *attr; | |
7866 | int encoding = 0, size = 0; | |
39cbfefa | 7867 | char *name; |
6ccb9162 UW |
7868 | enum type_code code = TYPE_CODE_INT; |
7869 | int type_flags = 0; | |
7870 | struct type *target_type = NULL; | |
c906108c | 7871 | |
e142c38c | 7872 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
7873 | if (attr) |
7874 | { | |
7875 | encoding = DW_UNSND (attr); | |
7876 | } | |
e142c38c | 7877 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7878 | if (attr) |
7879 | { | |
7880 | size = DW_UNSND (attr); | |
7881 | } | |
39cbfefa | 7882 | name = dwarf2_name (die, cu); |
6ccb9162 | 7883 | if (!name) |
c906108c | 7884 | { |
6ccb9162 UW |
7885 | complaint (&symfile_complaints, |
7886 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 7887 | } |
6ccb9162 UW |
7888 | |
7889 | switch (encoding) | |
c906108c | 7890 | { |
6ccb9162 UW |
7891 | case DW_ATE_address: |
7892 | /* Turn DW_ATE_address into a void * pointer. */ | |
7893 | code = TYPE_CODE_PTR; | |
7894 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7895 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
7896 | break; | |
7897 | case DW_ATE_boolean: | |
7898 | code = TYPE_CODE_BOOL; | |
7899 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7900 | break; | |
7901 | case DW_ATE_complex_float: | |
7902 | code = TYPE_CODE_COMPLEX; | |
7903 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
7904 | break; | |
7905 | case DW_ATE_decimal_float: | |
7906 | code = TYPE_CODE_DECFLOAT; | |
7907 | break; | |
7908 | case DW_ATE_float: | |
7909 | code = TYPE_CODE_FLT; | |
7910 | break; | |
7911 | case DW_ATE_signed: | |
7912 | break; | |
7913 | case DW_ATE_unsigned: | |
7914 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7915 | break; | |
7916 | case DW_ATE_signed_char: | |
6e70227d | 7917 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 7918 | || cu->language == language_pascal) |
6ccb9162 UW |
7919 | code = TYPE_CODE_CHAR; |
7920 | break; | |
7921 | case DW_ATE_unsigned_char: | |
868a0084 PM |
7922 | if (cu->language == language_ada || cu->language == language_m2 |
7923 | || cu->language == language_pascal) | |
6ccb9162 UW |
7924 | code = TYPE_CODE_CHAR; |
7925 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7926 | break; | |
75079b2b TT |
7927 | case DW_ATE_UTF: |
7928 | /* We just treat this as an integer and then recognize the | |
7929 | type by name elsewhere. */ | |
7930 | break; | |
7931 | ||
6ccb9162 UW |
7932 | default: |
7933 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
7934 | dwarf_type_encoding_name (encoding)); | |
7935 | break; | |
c906108c | 7936 | } |
6ccb9162 | 7937 | |
0114d602 DJ |
7938 | type = init_type (code, size, type_flags, NULL, objfile); |
7939 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
7940 | TYPE_TARGET_TYPE (type) = target_type; |
7941 | ||
0114d602 | 7942 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 7943 | TYPE_NOSIGN (type) = 1; |
0114d602 | 7944 | |
f792889a | 7945 | return set_die_type (die, type, cu); |
c906108c SS |
7946 | } |
7947 | ||
a02abb62 JB |
7948 | /* Read the given DW_AT_subrange DIE. */ |
7949 | ||
f792889a | 7950 | static struct type * |
a02abb62 JB |
7951 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
7952 | { | |
5e2b427d | 7953 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
7954 | struct type *base_type; |
7955 | struct type *range_type; | |
7956 | struct attribute *attr; | |
43bbcdc2 PH |
7957 | LONGEST low = 0; |
7958 | LONGEST high = -1; | |
39cbfefa | 7959 | char *name; |
43bbcdc2 | 7960 | LONGEST negative_mask; |
e77813c8 | 7961 | |
a02abb62 | 7962 | base_type = die_type (die, cu); |
953ac07e JK |
7963 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
7964 | check_typedef (base_type); | |
a02abb62 | 7965 | |
7e314c57 JK |
7966 | /* The die_type call above may have already set the type for this DIE. */ |
7967 | range_type = get_die_type (die, cu); | |
7968 | if (range_type) | |
7969 | return range_type; | |
7970 | ||
e142c38c | 7971 | if (cu->language == language_fortran) |
6e70227d | 7972 | { |
a02abb62 JB |
7973 | /* FORTRAN implies a lower bound of 1, if not given. */ |
7974 | low = 1; | |
7975 | } | |
7976 | ||
dd5e6932 DJ |
7977 | /* FIXME: For variable sized arrays either of these could be |
7978 | a variable rather than a constant value. We'll allow it, | |
7979 | but we don't know how to handle it. */ | |
e142c38c | 7980 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
7981 | if (attr) |
7982 | low = dwarf2_get_attr_constant_value (attr, 0); | |
7983 | ||
e142c38c | 7984 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 7985 | if (attr) |
6e70227d | 7986 | { |
e77813c8 | 7987 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
7988 | { |
7989 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 7990 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
7991 | FIXME: GDB does not yet know how to handle dynamic |
7992 | arrays properly, treat them as arrays with unspecified | |
7993 | length for now. | |
7994 | ||
7995 | FIXME: jimb/2003-09-22: GDB does not really know | |
7996 | how to handle arrays of unspecified length | |
7997 | either; we just represent them as zero-length | |
7998 | arrays. Choose an appropriate upper bound given | |
7999 | the lower bound we've computed above. */ | |
8000 | high = low - 1; | |
8001 | } | |
8002 | else | |
8003 | high = dwarf2_get_attr_constant_value (attr, 1); | |
8004 | } | |
e77813c8 PM |
8005 | else |
8006 | { | |
8007 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
8008 | if (attr) | |
8009 | { | |
8010 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
8011 | high = low + count - 1; | |
8012 | } | |
8013 | } | |
8014 | ||
8015 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8016 | without specifying a base type. | |
8017 | In that case, the base type must be set to the type of | |
8018 | the lower bound, upper bound or count, in that order, if any of these | |
8019 | three attributes references an object that has a type. | |
8020 | If no base type is found, the Dwarf-2 specifications say that | |
8021 | a signed integer type of size equal to the size of an address should | |
8022 | be used. | |
8023 | For the following C code: `extern char gdb_int [];' | |
8024 | GCC produces an empty range DIE. | |
8025 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
8026 | high bound or count are not yet handled by this code. | |
8027 | */ | |
8028 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
8029 | { | |
8030 | struct objfile *objfile = cu->objfile; | |
8031 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8032 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8033 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8034 | ||
8035 | /* Test "int", "long int", and "long long int" objfile types, | |
8036 | and select the first one having a size above or equal to the | |
8037 | architecture address size. */ | |
8038 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8039 | base_type = int_type; | |
8040 | else | |
8041 | { | |
8042 | int_type = objfile_type (objfile)->builtin_long; | |
8043 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8044 | base_type = int_type; | |
8045 | else | |
8046 | { | |
8047 | int_type = objfile_type (objfile)->builtin_long_long; | |
8048 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8049 | base_type = int_type; | |
8050 | } | |
8051 | } | |
8052 | } | |
a02abb62 | 8053 | |
6e70227d | 8054 | negative_mask = |
43bbcdc2 PH |
8055 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8056 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8057 | low |= negative_mask; | |
8058 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8059 | high |= negative_mask; | |
8060 | ||
a02abb62 JB |
8061 | range_type = create_range_type (NULL, base_type, low, high); |
8062 | ||
bbb0eef6 JK |
8063 | /* Mark arrays with dynamic length at least as an array of unspecified |
8064 | length. GDB could check the boundary but before it gets implemented at | |
8065 | least allow accessing the array elements. */ | |
8066 | if (attr && attr->form == DW_FORM_block1) | |
8067 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8068 | ||
39cbfefa DJ |
8069 | name = dwarf2_name (die, cu); |
8070 | if (name) | |
8071 | TYPE_NAME (range_type) = name; | |
6e70227d | 8072 | |
e142c38c | 8073 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
8074 | if (attr) |
8075 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
8076 | ||
7e314c57 JK |
8077 | set_die_type (die, range_type, cu); |
8078 | ||
8079 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8080 | set_descriptive_type (range_type, die, cu); |
8081 | ||
7e314c57 | 8082 | return range_type; |
a02abb62 | 8083 | } |
6e70227d | 8084 | |
f792889a | 8085 | static struct type * |
81a17f79 JB |
8086 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
8087 | { | |
8088 | struct type *type; | |
81a17f79 | 8089 | |
81a17f79 JB |
8090 | /* For now, we only support the C meaning of an unspecified type: void. */ |
8091 | ||
0114d602 DJ |
8092 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
8093 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 8094 | |
f792889a | 8095 | return set_die_type (die, type, cu); |
81a17f79 | 8096 | } |
a02abb62 | 8097 | |
51545339 DJ |
8098 | /* Trivial hash function for die_info: the hash value of a DIE |
8099 | is its offset in .debug_info for this objfile. */ | |
8100 | ||
8101 | static hashval_t | |
8102 | die_hash (const void *item) | |
8103 | { | |
8104 | const struct die_info *die = item; | |
9a619af0 | 8105 | |
51545339 DJ |
8106 | return die->offset; |
8107 | } | |
8108 | ||
8109 | /* Trivial comparison function for die_info structures: two DIEs | |
8110 | are equal if they have the same offset. */ | |
8111 | ||
8112 | static int | |
8113 | die_eq (const void *item_lhs, const void *item_rhs) | |
8114 | { | |
8115 | const struct die_info *die_lhs = item_lhs; | |
8116 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 8117 | |
51545339 DJ |
8118 | return die_lhs->offset == die_rhs->offset; |
8119 | } | |
8120 | ||
c906108c SS |
8121 | /* Read a whole compilation unit into a linked list of dies. */ |
8122 | ||
f9aca02d | 8123 | static struct die_info * |
93311388 | 8124 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 8125 | { |
93311388 | 8126 | struct die_reader_specs reader_specs; |
98bfdba5 | 8127 | int read_abbrevs = 0; |
1d9ec526 | 8128 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
8129 | struct die_info *die; |
8130 | ||
8131 | if (cu->dwarf2_abbrevs == NULL) | |
8132 | { | |
8133 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
8134 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
8135 | read_abbrevs = 1; | |
8136 | } | |
93311388 | 8137 | |
348e048f | 8138 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
8139 | cu->die_hash |
8140 | = htab_create_alloc_ex (cu->header.length / 12, | |
8141 | die_hash, | |
8142 | die_eq, | |
8143 | NULL, | |
8144 | &cu->comp_unit_obstack, | |
8145 | hashtab_obstack_allocate, | |
8146 | dummy_obstack_deallocate); | |
8147 | ||
93311388 DE |
8148 | init_cu_die_reader (&reader_specs, cu); |
8149 | ||
98bfdba5 PA |
8150 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
8151 | ||
8152 | if (read_abbrevs) | |
8153 | do_cleanups (back_to); | |
8154 | ||
8155 | return die; | |
639d11d3 DC |
8156 | } |
8157 | ||
d97bc12b DE |
8158 | /* Main entry point for reading a DIE and all children. |
8159 | Read the DIE and dump it if requested. */ | |
8160 | ||
8161 | static struct die_info * | |
93311388 DE |
8162 | read_die_and_children (const struct die_reader_specs *reader, |
8163 | gdb_byte *info_ptr, | |
d97bc12b DE |
8164 | gdb_byte **new_info_ptr, |
8165 | struct die_info *parent) | |
8166 | { | |
93311388 | 8167 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
8168 | new_info_ptr, parent); |
8169 | ||
8170 | if (dwarf2_die_debug) | |
8171 | { | |
348e048f DE |
8172 | fprintf_unfiltered (gdb_stdlog, |
8173 | "\nRead die from %s of %s:\n", | |
8174 | reader->buffer == dwarf2_per_objfile->info.buffer | |
8175 | ? ".debug_info" | |
8176 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
8177 | ? ".debug_types" | |
8178 | : "unknown section", | |
8179 | reader->abfd->filename); | |
d97bc12b DE |
8180 | dump_die (result, dwarf2_die_debug); |
8181 | } | |
8182 | ||
8183 | return result; | |
8184 | } | |
8185 | ||
639d11d3 DC |
8186 | /* Read a single die and all its descendents. Set the die's sibling |
8187 | field to NULL; set other fields in the die correctly, and set all | |
8188 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
8189 | location of the info_ptr after reading all of those dies. PARENT | |
8190 | is the parent of the die in question. */ | |
8191 | ||
8192 | static struct die_info * | |
93311388 DE |
8193 | read_die_and_children_1 (const struct die_reader_specs *reader, |
8194 | gdb_byte *info_ptr, | |
d97bc12b DE |
8195 | gdb_byte **new_info_ptr, |
8196 | struct die_info *parent) | |
639d11d3 DC |
8197 | { |
8198 | struct die_info *die; | |
fe1b8b76 | 8199 | gdb_byte *cur_ptr; |
639d11d3 DC |
8200 | int has_children; |
8201 | ||
93311388 | 8202 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
8203 | if (die == NULL) |
8204 | { | |
8205 | *new_info_ptr = cur_ptr; | |
8206 | return NULL; | |
8207 | } | |
93311388 | 8208 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
8209 | |
8210 | if (has_children) | |
348e048f | 8211 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
8212 | else |
8213 | { | |
8214 | die->child = NULL; | |
8215 | *new_info_ptr = cur_ptr; | |
8216 | } | |
8217 | ||
8218 | die->sibling = NULL; | |
8219 | die->parent = parent; | |
8220 | return die; | |
8221 | } | |
8222 | ||
8223 | /* Read a die, all of its descendents, and all of its siblings; set | |
8224 | all of the fields of all of the dies correctly. Arguments are as | |
8225 | in read_die_and_children. */ | |
8226 | ||
8227 | static struct die_info * | |
93311388 DE |
8228 | read_die_and_siblings (const struct die_reader_specs *reader, |
8229 | gdb_byte *info_ptr, | |
fe1b8b76 | 8230 | gdb_byte **new_info_ptr, |
639d11d3 DC |
8231 | struct die_info *parent) |
8232 | { | |
8233 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 8234 | gdb_byte *cur_ptr; |
639d11d3 | 8235 | |
c906108c | 8236 | cur_ptr = info_ptr; |
639d11d3 DC |
8237 | first_die = last_sibling = NULL; |
8238 | ||
8239 | while (1) | |
c906108c | 8240 | { |
639d11d3 | 8241 | struct die_info *die |
93311388 | 8242 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 8243 | |
1d325ec1 | 8244 | if (die == NULL) |
c906108c | 8245 | { |
639d11d3 DC |
8246 | *new_info_ptr = cur_ptr; |
8247 | return first_die; | |
c906108c | 8248 | } |
1d325ec1 DJ |
8249 | |
8250 | if (!first_die) | |
8251 | first_die = die; | |
c906108c | 8252 | else |
1d325ec1 DJ |
8253 | last_sibling->sibling = die; |
8254 | ||
8255 | last_sibling = die; | |
c906108c | 8256 | } |
c906108c SS |
8257 | } |
8258 | ||
93311388 DE |
8259 | /* Read the die from the .debug_info section buffer. Set DIEP to |
8260 | point to a newly allocated die with its information, except for its | |
8261 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
8262 | whether the die has children or not. */ | |
8263 | ||
8264 | static gdb_byte * | |
8265 | read_full_die (const struct die_reader_specs *reader, | |
8266 | struct die_info **diep, gdb_byte *info_ptr, | |
8267 | int *has_children) | |
8268 | { | |
8269 | unsigned int abbrev_number, bytes_read, i, offset; | |
8270 | struct abbrev_info *abbrev; | |
8271 | struct die_info *die; | |
8272 | struct dwarf2_cu *cu = reader->cu; | |
8273 | bfd *abfd = reader->abfd; | |
8274 | ||
8275 | offset = info_ptr - reader->buffer; | |
8276 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8277 | info_ptr += bytes_read; | |
8278 | if (!abbrev_number) | |
8279 | { | |
8280 | *diep = NULL; | |
8281 | *has_children = 0; | |
8282 | return info_ptr; | |
8283 | } | |
8284 | ||
8285 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
8286 | if (!abbrev) | |
348e048f DE |
8287 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
8288 | abbrev_number, | |
8289 | bfd_get_filename (abfd)); | |
8290 | ||
93311388 DE |
8291 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
8292 | die->offset = offset; | |
8293 | die->tag = abbrev->tag; | |
8294 | die->abbrev = abbrev_number; | |
8295 | ||
8296 | die->num_attrs = abbrev->num_attrs; | |
8297 | ||
8298 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8299 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
8300 | abfd, info_ptr, cu); | |
8301 | ||
8302 | *diep = die; | |
8303 | *has_children = abbrev->has_children; | |
8304 | return info_ptr; | |
8305 | } | |
8306 | ||
c906108c SS |
8307 | /* In DWARF version 2, the description of the debugging information is |
8308 | stored in a separate .debug_abbrev section. Before we read any | |
8309 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
8310 | in a hash table. This function also sets flags in CU describing |
8311 | the data found in the abbrev table. */ | |
c906108c SS |
8312 | |
8313 | static void | |
e7c27a73 | 8314 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 8315 | { |
e7c27a73 | 8316 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 8317 | gdb_byte *abbrev_ptr; |
c906108c SS |
8318 | struct abbrev_info *cur_abbrev; |
8319 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
8320 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
8321 | struct attr_abbrev *cur_attrs; |
8322 | unsigned int allocated_attrs; | |
c906108c | 8323 | |
57349743 | 8324 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
8325 | obstack_init (&cu->abbrev_obstack); |
8326 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
8327 | (ABBREV_HASH_SIZE | |
8328 | * sizeof (struct abbrev_info *))); | |
8329 | memset (cu->dwarf2_abbrevs, 0, | |
8330 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 8331 | |
be391dca TT |
8332 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
8333 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 8334 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
8335 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8336 | abbrev_ptr += bytes_read; | |
8337 | ||
f3dd6933 DJ |
8338 | allocated_attrs = ATTR_ALLOC_CHUNK; |
8339 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 8340 | |
c906108c SS |
8341 | /* loop until we reach an abbrev number of 0 */ |
8342 | while (abbrev_number) | |
8343 | { | |
f3dd6933 | 8344 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
8345 | |
8346 | /* read in abbrev header */ | |
8347 | cur_abbrev->number = abbrev_number; | |
8348 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8349 | abbrev_ptr += bytes_read; | |
8350 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
8351 | abbrev_ptr += 1; | |
8352 | ||
72bf9492 DJ |
8353 | if (cur_abbrev->tag == DW_TAG_namespace) |
8354 | cu->has_namespace_info = 1; | |
8355 | ||
c906108c SS |
8356 | /* now read in declarations */ |
8357 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8358 | abbrev_ptr += bytes_read; | |
8359 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8360 | abbrev_ptr += bytes_read; | |
8361 | while (abbrev_name) | |
8362 | { | |
f3dd6933 | 8363 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 8364 | { |
f3dd6933 DJ |
8365 | allocated_attrs += ATTR_ALLOC_CHUNK; |
8366 | cur_attrs | |
8367 | = xrealloc (cur_attrs, (allocated_attrs | |
8368 | * sizeof (struct attr_abbrev))); | |
c906108c | 8369 | } |
ae038cb0 DJ |
8370 | |
8371 | /* Record whether this compilation unit might have | |
8372 | inter-compilation-unit references. If we don't know what form | |
8373 | this attribute will have, then it might potentially be a | |
8374 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
8375 | references. */ | |
8376 | ||
8377 | if (abbrev_form == DW_FORM_ref_addr | |
8378 | || abbrev_form == DW_FORM_indirect) | |
8379 | cu->has_form_ref_addr = 1; | |
8380 | ||
f3dd6933 DJ |
8381 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
8382 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
8383 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8384 | abbrev_ptr += bytes_read; | |
8385 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8386 | abbrev_ptr += bytes_read; | |
8387 | } | |
8388 | ||
f3dd6933 DJ |
8389 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
8390 | (cur_abbrev->num_attrs | |
8391 | * sizeof (struct attr_abbrev))); | |
8392 | memcpy (cur_abbrev->attrs, cur_attrs, | |
8393 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
8394 | ||
c906108c | 8395 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
8396 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
8397 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
8398 | |
8399 | /* Get next abbreviation. | |
8400 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
8401 | always properly terminated with an abbrev number of 0. |
8402 | Exit loop if we encounter an abbreviation which we have | |
8403 | already read (which means we are about to read the abbreviations | |
8404 | for the next compile unit) or if the end of the abbreviation | |
8405 | table is reached. */ | |
dce234bc PP |
8406 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
8407 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
8408 | break; |
8409 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8410 | abbrev_ptr += bytes_read; | |
e7c27a73 | 8411 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
8412 | break; |
8413 | } | |
f3dd6933 DJ |
8414 | |
8415 | xfree (cur_attrs); | |
c906108c SS |
8416 | } |
8417 | ||
f3dd6933 | 8418 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 8419 | |
c906108c | 8420 | static void |
f3dd6933 | 8421 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 8422 | { |
f3dd6933 | 8423 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 8424 | |
f3dd6933 DJ |
8425 | obstack_free (&cu->abbrev_obstack, NULL); |
8426 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
8427 | } |
8428 | ||
8429 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
8430 | ||
8431 | static struct abbrev_info * | |
e7c27a73 | 8432 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
8433 | { |
8434 | unsigned int hash_number; | |
8435 | struct abbrev_info *abbrev; | |
8436 | ||
8437 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 8438 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
8439 | |
8440 | while (abbrev) | |
8441 | { | |
8442 | if (abbrev->number == number) | |
8443 | return abbrev; | |
8444 | else | |
8445 | abbrev = abbrev->next; | |
8446 | } | |
8447 | return NULL; | |
8448 | } | |
8449 | ||
72bf9492 DJ |
8450 | /* Returns nonzero if TAG represents a type that we might generate a partial |
8451 | symbol for. */ | |
8452 | ||
8453 | static int | |
8454 | is_type_tag_for_partial (int tag) | |
8455 | { | |
8456 | switch (tag) | |
8457 | { | |
8458 | #if 0 | |
8459 | /* Some types that would be reasonable to generate partial symbols for, | |
8460 | that we don't at present. */ | |
8461 | case DW_TAG_array_type: | |
8462 | case DW_TAG_file_type: | |
8463 | case DW_TAG_ptr_to_member_type: | |
8464 | case DW_TAG_set_type: | |
8465 | case DW_TAG_string_type: | |
8466 | case DW_TAG_subroutine_type: | |
8467 | #endif | |
8468 | case DW_TAG_base_type: | |
8469 | case DW_TAG_class_type: | |
680b30c7 | 8470 | case DW_TAG_interface_type: |
72bf9492 DJ |
8471 | case DW_TAG_enumeration_type: |
8472 | case DW_TAG_structure_type: | |
8473 | case DW_TAG_subrange_type: | |
8474 | case DW_TAG_typedef: | |
8475 | case DW_TAG_union_type: | |
8476 | return 1; | |
8477 | default: | |
8478 | return 0; | |
8479 | } | |
8480 | } | |
8481 | ||
8482 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
8483 | ||
8484 | static struct partial_die_info * | |
93311388 DE |
8485 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
8486 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
8487 | { |
8488 | struct partial_die_info *part_die; | |
8489 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
8490 | struct abbrev_info *abbrev; | |
8491 | unsigned int bytes_read; | |
5afb4e99 | 8492 | unsigned int load_all = 0; |
72bf9492 DJ |
8493 | |
8494 | int nesting_level = 1; | |
8495 | ||
8496 | parent_die = NULL; | |
8497 | last_die = NULL; | |
8498 | ||
5afb4e99 DJ |
8499 | if (cu->per_cu && cu->per_cu->load_all_dies) |
8500 | load_all = 1; | |
8501 | ||
72bf9492 DJ |
8502 | cu->partial_dies |
8503 | = htab_create_alloc_ex (cu->header.length / 12, | |
8504 | partial_die_hash, | |
8505 | partial_die_eq, | |
8506 | NULL, | |
8507 | &cu->comp_unit_obstack, | |
8508 | hashtab_obstack_allocate, | |
8509 | dummy_obstack_deallocate); | |
8510 | ||
8511 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8512 | sizeof (struct partial_die_info)); | |
8513 | ||
8514 | while (1) | |
8515 | { | |
8516 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
8517 | ||
8518 | /* A NULL abbrev means the end of a series of children. */ | |
8519 | if (abbrev == NULL) | |
8520 | { | |
8521 | if (--nesting_level == 0) | |
8522 | { | |
8523 | /* PART_DIE was probably the last thing allocated on the | |
8524 | comp_unit_obstack, so we could call obstack_free | |
8525 | here. We don't do that because the waste is small, | |
8526 | and will be cleaned up when we're done with this | |
8527 | compilation unit. This way, we're also more robust | |
8528 | against other users of the comp_unit_obstack. */ | |
8529 | return first_die; | |
8530 | } | |
8531 | info_ptr += bytes_read; | |
8532 | last_die = parent_die; | |
8533 | parent_die = parent_die->die_parent; | |
8534 | continue; | |
8535 | } | |
8536 | ||
98bfdba5 PA |
8537 | /* Check for template arguments. We never save these; if |
8538 | they're seen, we just mark the parent, and go on our way. */ | |
8539 | if (parent_die != NULL | |
8540 | && cu->language == language_cplus | |
8541 | && (abbrev->tag == DW_TAG_template_type_param | |
8542 | || abbrev->tag == DW_TAG_template_value_param)) | |
8543 | { | |
8544 | parent_die->has_template_arguments = 1; | |
8545 | ||
8546 | if (!load_all) | |
8547 | { | |
8548 | /* We don't need a partial DIE for the template argument. */ | |
8549 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
8550 | cu); | |
8551 | continue; | |
8552 | } | |
8553 | } | |
8554 | ||
8555 | /* We only recurse into subprograms looking for template arguments. | |
8556 | Skip their other children. */ | |
8557 | if (!load_all | |
8558 | && cu->language == language_cplus | |
8559 | && parent_die != NULL | |
8560 | && parent_die->tag == DW_TAG_subprogram) | |
8561 | { | |
8562 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
8563 | continue; | |
8564 | } | |
8565 | ||
5afb4e99 DJ |
8566 | /* Check whether this DIE is interesting enough to save. Normally |
8567 | we would not be interested in members here, but there may be | |
8568 | later variables referencing them via DW_AT_specification (for | |
8569 | static members). */ | |
8570 | if (!load_all | |
8571 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
8572 | && abbrev->tag != DW_TAG_enumerator |
8573 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 8574 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 8575 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 8576 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 8577 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 8578 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
8579 | { |
8580 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8581 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
8582 | continue; |
8583 | } | |
8584 | ||
93311388 DE |
8585 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
8586 | buffer, info_ptr, cu); | |
72bf9492 DJ |
8587 | |
8588 | /* This two-pass algorithm for processing partial symbols has a | |
8589 | high cost in cache pressure. Thus, handle some simple cases | |
8590 | here which cover the majority of C partial symbols. DIEs | |
8591 | which neither have specification tags in them, nor could have | |
8592 | specification tags elsewhere pointing at them, can simply be | |
8593 | processed and discarded. | |
8594 | ||
8595 | This segment is also optional; scan_partial_symbols and | |
8596 | add_partial_symbol will handle these DIEs if we chain | |
8597 | them in normally. When compilers which do not emit large | |
8598 | quantities of duplicate debug information are more common, | |
8599 | this code can probably be removed. */ | |
8600 | ||
8601 | /* Any complete simple types at the top level (pretty much all | |
8602 | of them, for a language without namespaces), can be processed | |
8603 | directly. */ | |
8604 | if (parent_die == NULL | |
8605 | && part_die->has_specification == 0 | |
8606 | && part_die->is_declaration == 0 | |
8607 | && (part_die->tag == DW_TAG_typedef | |
8608 | || part_die->tag == DW_TAG_base_type | |
8609 | || part_die->tag == DW_TAG_subrange_type)) | |
8610 | { | |
8611 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 8612 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
8613 | VAR_DOMAIN, LOC_TYPEDEF, |
8614 | &cu->objfile->static_psymbols, | |
8615 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 8616 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8617 | continue; |
8618 | } | |
8619 | ||
8620 | /* If we're at the second level, and we're an enumerator, and | |
8621 | our parent has no specification (meaning possibly lives in a | |
8622 | namespace elsewhere), then we can add the partial symbol now | |
8623 | instead of queueing it. */ | |
8624 | if (part_die->tag == DW_TAG_enumerator | |
8625 | && parent_die != NULL | |
8626 | && parent_die->die_parent == NULL | |
8627 | && parent_die->tag == DW_TAG_enumeration_type | |
8628 | && parent_die->has_specification == 0) | |
8629 | { | |
8630 | if (part_die->name == NULL) | |
e2e0b3e5 | 8631 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 8632 | else if (building_psymtab) |
04a679b8 | 8633 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 8634 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
8635 | (cu->language == language_cplus |
8636 | || cu->language == language_java) | |
72bf9492 DJ |
8637 | ? &cu->objfile->global_psymbols |
8638 | : &cu->objfile->static_psymbols, | |
8639 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
8640 | ||
93311388 | 8641 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8642 | continue; |
8643 | } | |
8644 | ||
8645 | /* We'll save this DIE so link it in. */ | |
8646 | part_die->die_parent = parent_die; | |
8647 | part_die->die_sibling = NULL; | |
8648 | part_die->die_child = NULL; | |
8649 | ||
8650 | if (last_die && last_die == parent_die) | |
8651 | last_die->die_child = part_die; | |
8652 | else if (last_die) | |
8653 | last_die->die_sibling = part_die; | |
8654 | ||
8655 | last_die = part_die; | |
8656 | ||
8657 | if (first_die == NULL) | |
8658 | first_die = part_die; | |
8659 | ||
8660 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
8661 | find interesting need to be in the hash table, because we | |
8662 | also have the parent/sibling/child chains; only those that we | |
8663 | might refer to by offset later during partial symbol reading. | |
8664 | ||
8665 | For now this means things that might have be the target of a | |
8666 | DW_AT_specification, DW_AT_abstract_origin, or | |
8667 | DW_AT_extension. DW_AT_extension will refer only to | |
8668 | namespaces; DW_AT_abstract_origin refers to functions (and | |
8669 | many things under the function DIE, but we do not recurse | |
8670 | into function DIEs during partial symbol reading) and | |
8671 | possibly variables as well; DW_AT_specification refers to | |
8672 | declarations. Declarations ought to have the DW_AT_declaration | |
8673 | flag. It happens that GCC forgets to put it in sometimes, but | |
8674 | only for functions, not for types. | |
8675 | ||
8676 | Adding more things than necessary to the hash table is harmless | |
8677 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
8678 | wasted time in find_partial_die, when we reread the compilation |
8679 | unit with load_all_dies set. */ | |
72bf9492 | 8680 | |
5afb4e99 DJ |
8681 | if (load_all |
8682 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
8683 | || abbrev->tag == DW_TAG_variable |
8684 | || abbrev->tag == DW_TAG_namespace | |
8685 | || part_die->is_declaration) | |
8686 | { | |
8687 | void **slot; | |
8688 | ||
8689 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
8690 | part_die->offset, INSERT); | |
8691 | *slot = part_die; | |
8692 | } | |
8693 | ||
8694 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8695 | sizeof (struct partial_die_info)); | |
8696 | ||
8697 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 8698 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
8699 | languages we have to, so that we can get at method physnames |
8700 | to infer fully qualified class names, for DW_AT_specification, | |
8701 | and for C++ template arguments. For C++, we also look one level | |
8702 | inside functions to find template arguments (if the name of the | |
8703 | function does not already contain the template arguments). | |
bc30ff58 JB |
8704 | |
8705 | For Ada, we need to scan the children of subprograms and lexical | |
8706 | blocks as well because Ada allows the definition of nested | |
8707 | entities that could be interesting for the debugger, such as | |
8708 | nested subprograms for instance. */ | |
72bf9492 | 8709 | if (last_die->has_children |
5afb4e99 DJ |
8710 | && (load_all |
8711 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 8712 | || last_die->tag == DW_TAG_module |
72bf9492 | 8713 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
8714 | || (cu->language == language_cplus |
8715 | && last_die->tag == DW_TAG_subprogram | |
8716 | && (last_die->name == NULL | |
8717 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
8718 | || (cu->language != language_c |
8719 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 8720 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 8721 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
8722 | || last_die->tag == DW_TAG_union_type)) |
8723 | || (cu->language == language_ada | |
8724 | && (last_die->tag == DW_TAG_subprogram | |
8725 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
8726 | { |
8727 | nesting_level++; | |
8728 | parent_die = last_die; | |
8729 | continue; | |
8730 | } | |
8731 | ||
8732 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8733 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8734 | |
8735 | /* Back to the top, do it again. */ | |
8736 | } | |
8737 | } | |
8738 | ||
c906108c SS |
8739 | /* Read a minimal amount of information into the minimal die structure. */ |
8740 | ||
fe1b8b76 | 8741 | static gdb_byte * |
72bf9492 DJ |
8742 | read_partial_die (struct partial_die_info *part_die, |
8743 | struct abbrev_info *abbrev, | |
8744 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
8745 | gdb_byte *buffer, gdb_byte *info_ptr, |
8746 | struct dwarf2_cu *cu) | |
c906108c | 8747 | { |
fa238c03 | 8748 | unsigned int i; |
c906108c | 8749 | struct attribute attr; |
c5aa993b | 8750 | int has_low_pc_attr = 0; |
c906108c SS |
8751 | int has_high_pc_attr = 0; |
8752 | ||
72bf9492 | 8753 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 8754 | |
93311388 | 8755 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
8756 | |
8757 | info_ptr += abbrev_len; | |
8758 | ||
8759 | if (abbrev == NULL) | |
8760 | return info_ptr; | |
8761 | ||
c906108c SS |
8762 | part_die->tag = abbrev->tag; |
8763 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
8764 | |
8765 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8766 | { | |
e7c27a73 | 8767 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
8768 | |
8769 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 8770 | partial symbol table. */ |
c906108c SS |
8771 | switch (attr.name) |
8772 | { | |
8773 | case DW_AT_name: | |
71c25dea TT |
8774 | switch (part_die->tag) |
8775 | { | |
8776 | case DW_TAG_compile_unit: | |
348e048f | 8777 | case DW_TAG_type_unit: |
71c25dea TT |
8778 | /* Compilation units have a DW_AT_name that is a filename, not |
8779 | a source language identifier. */ | |
8780 | case DW_TAG_enumeration_type: | |
8781 | case DW_TAG_enumerator: | |
8782 | /* These tags always have simple identifiers already; no need | |
8783 | to canonicalize them. */ | |
8784 | part_die->name = DW_STRING (&attr); | |
8785 | break; | |
8786 | default: | |
8787 | part_die->name | |
8788 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 8789 | &cu->objfile->objfile_obstack); |
71c25dea TT |
8790 | break; |
8791 | } | |
c906108c | 8792 | break; |
31ef98ae | 8793 | case DW_AT_linkage_name: |
c906108c | 8794 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
8795 | /* Note that both forms of linkage name might appear. We |
8796 | assume they will be the same, and we only store the last | |
8797 | one we see. */ | |
94af9270 KS |
8798 | if (cu->language == language_ada) |
8799 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
8800 | break; |
8801 | case DW_AT_low_pc: | |
8802 | has_low_pc_attr = 1; | |
8803 | part_die->lowpc = DW_ADDR (&attr); | |
8804 | break; | |
8805 | case DW_AT_high_pc: | |
8806 | has_high_pc_attr = 1; | |
8807 | part_die->highpc = DW_ADDR (&attr); | |
8808 | break; | |
8809 | case DW_AT_location: | |
8e19ed76 PS |
8810 | /* Support the .debug_loc offsets */ |
8811 | if (attr_form_is_block (&attr)) | |
8812 | { | |
8813 | part_die->locdesc = DW_BLOCK (&attr); | |
8814 | } | |
3690dd37 | 8815 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 8816 | { |
4d3c2250 | 8817 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8818 | } |
8819 | else | |
8820 | { | |
4d3c2250 KB |
8821 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8822 | "partial symbol information"); | |
8e19ed76 | 8823 | } |
c906108c | 8824 | break; |
c906108c SS |
8825 | case DW_AT_external: |
8826 | part_die->is_external = DW_UNSND (&attr); | |
8827 | break; | |
8828 | case DW_AT_declaration: | |
8829 | part_die->is_declaration = DW_UNSND (&attr); | |
8830 | break; | |
8831 | case DW_AT_type: | |
8832 | part_die->has_type = 1; | |
8833 | break; | |
8834 | case DW_AT_abstract_origin: | |
8835 | case DW_AT_specification: | |
72bf9492 DJ |
8836 | case DW_AT_extension: |
8837 | part_die->has_specification = 1; | |
c764a876 | 8838 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
8839 | break; |
8840 | case DW_AT_sibling: | |
8841 | /* Ignore absolute siblings, they might point outside of | |
8842 | the current compile unit. */ | |
8843 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 8844 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 8845 | else |
93311388 | 8846 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 8847 | break; |
fa4028e9 JB |
8848 | case DW_AT_byte_size: |
8849 | part_die->has_byte_size = 1; | |
8850 | break; | |
68511cec CES |
8851 | case DW_AT_calling_convention: |
8852 | /* DWARF doesn't provide a way to identify a program's source-level | |
8853 | entry point. DW_AT_calling_convention attributes are only meant | |
8854 | to describe functions' calling conventions. | |
8855 | ||
8856 | However, because it's a necessary piece of information in | |
8857 | Fortran, and because DW_CC_program is the only piece of debugging | |
8858 | information whose definition refers to a 'main program' at all, | |
8859 | several compilers have begun marking Fortran main programs with | |
8860 | DW_CC_program --- even when those functions use the standard | |
8861 | calling conventions. | |
8862 | ||
8863 | So until DWARF specifies a way to provide this information and | |
8864 | compilers pick up the new representation, we'll support this | |
8865 | practice. */ | |
8866 | if (DW_UNSND (&attr) == DW_CC_program | |
8867 | && cu->language == language_fortran) | |
8868 | set_main_name (part_die->name); | |
8869 | break; | |
c906108c SS |
8870 | default: |
8871 | break; | |
8872 | } | |
8873 | } | |
8874 | ||
c906108c SS |
8875 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
8876 | eliminate duplicate copies of functions and vtables and such. | |
8877 | The linker will arbitrarily choose one and discard the others. | |
8878 | The AT_*_pc values for such functions refer to local labels in | |
8879 | these sections. If the section from that file was discarded, the | |
8880 | labels are not in the output, so the relocs get a value of 0. | |
8881 | If this is a discarded function, mark the pc bounds as invalid, | |
8882 | so that GDB will ignore it. */ | |
8883 | if (has_low_pc_attr && has_high_pc_attr | |
8884 | && part_die->lowpc < part_die->highpc | |
8885 | && (part_die->lowpc != 0 | |
72dca2f5 | 8886 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 8887 | part_die->has_pc_info = 1; |
85cbf3d3 | 8888 | |
c906108c SS |
8889 | return info_ptr; |
8890 | } | |
8891 | ||
72bf9492 DJ |
8892 | /* Find a cached partial DIE at OFFSET in CU. */ |
8893 | ||
8894 | static struct partial_die_info * | |
c764a876 | 8895 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
8896 | { |
8897 | struct partial_die_info *lookup_die = NULL; | |
8898 | struct partial_die_info part_die; | |
8899 | ||
8900 | part_die.offset = offset; | |
8901 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
8902 | ||
72bf9492 DJ |
8903 | return lookup_die; |
8904 | } | |
8905 | ||
348e048f DE |
8906 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
8907 | except in the case of .debug_types DIEs which do not reference | |
8908 | outside their CU (they do however referencing other types via | |
8909 | DW_FORM_sig8). */ | |
72bf9492 DJ |
8910 | |
8911 | static struct partial_die_info * | |
c764a876 | 8912 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 8913 | { |
5afb4e99 DJ |
8914 | struct dwarf2_per_cu_data *per_cu = NULL; |
8915 | struct partial_die_info *pd = NULL; | |
72bf9492 | 8916 | |
348e048f DE |
8917 | if (cu->per_cu->from_debug_types) |
8918 | { | |
8919 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8920 | if (pd != NULL) | |
8921 | return pd; | |
8922 | goto not_found; | |
8923 | } | |
8924 | ||
45452591 | 8925 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
8926 | { |
8927 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8928 | if (pd != NULL) | |
8929 | return pd; | |
8930 | } | |
72bf9492 | 8931 | |
ae038cb0 DJ |
8932 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
8933 | ||
98bfdba5 PA |
8934 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
8935 | load_partial_comp_unit (per_cu, cu->objfile); | |
ae038cb0 DJ |
8936 | |
8937 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
8938 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
8939 | ||
8940 | if (pd == NULL && per_cu->load_all_dies == 0) | |
8941 | { | |
8942 | struct cleanup *back_to; | |
8943 | struct partial_die_info comp_unit_die; | |
8944 | struct abbrev_info *abbrev; | |
8945 | unsigned int bytes_read; | |
8946 | char *info_ptr; | |
8947 | ||
8948 | per_cu->load_all_dies = 1; | |
8949 | ||
8950 | /* Re-read the DIEs. */ | |
8951 | back_to = make_cleanup (null_cleanup, 0); | |
8952 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
8953 | { | |
8954 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 8955 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 8956 | } |
dce234bc | 8957 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
8958 | + per_cu->cu->header.offset |
8959 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
8960 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
8961 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
8962 | per_cu->cu->objfile->obfd, |
8963 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
8964 | per_cu->cu); |
8965 | if (comp_unit_die.has_children) | |
93311388 DE |
8966 | load_partial_dies (per_cu->cu->objfile->obfd, |
8967 | dwarf2_per_objfile->info.buffer, info_ptr, | |
8968 | 0, per_cu->cu); | |
5afb4e99 DJ |
8969 | do_cleanups (back_to); |
8970 | ||
8971 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
8972 | } | |
8973 | ||
348e048f DE |
8974 | not_found: |
8975 | ||
5afb4e99 DJ |
8976 | if (pd == NULL) |
8977 | internal_error (__FILE__, __LINE__, | |
c764a876 | 8978 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
8979 | offset, bfd_get_filename (cu->objfile->obfd)); |
8980 | return pd; | |
72bf9492 DJ |
8981 | } |
8982 | ||
8983 | /* Adjust PART_DIE before generating a symbol for it. This function | |
8984 | may set the is_external flag or change the DIE's name. */ | |
8985 | ||
8986 | static void | |
8987 | fixup_partial_die (struct partial_die_info *part_die, | |
8988 | struct dwarf2_cu *cu) | |
8989 | { | |
8990 | /* If we found a reference attribute and the DIE has no name, try | |
8991 | to find a name in the referred to DIE. */ | |
8992 | ||
8993 | if (part_die->name == NULL && part_die->has_specification) | |
8994 | { | |
8995 | struct partial_die_info *spec_die; | |
72bf9492 | 8996 | |
10b3939b | 8997 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 8998 | |
10b3939b | 8999 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
9000 | |
9001 | if (spec_die->name) | |
9002 | { | |
9003 | part_die->name = spec_die->name; | |
9004 | ||
9005 | /* Copy DW_AT_external attribute if it is set. */ | |
9006 | if (spec_die->is_external) | |
9007 | part_die->is_external = spec_die->is_external; | |
9008 | } | |
9009 | } | |
9010 | ||
9011 | /* Set default names for some unnamed DIEs. */ | |
72bf9492 DJ |
9012 | |
9013 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
9014 | part_die->name = "(anonymous namespace)"; | |
9015 | ||
9016 | if (part_die->tag == DW_TAG_structure_type | |
9017 | || part_die->tag == DW_TAG_class_type | |
9018 | || part_die->tag == DW_TAG_union_type) | |
9019 | guess_structure_name (part_die, cu); | |
9020 | } | |
9021 | ||
a8329558 | 9022 | /* Read an attribute value described by an attribute form. */ |
c906108c | 9023 | |
fe1b8b76 | 9024 | static gdb_byte * |
a8329558 | 9025 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 9026 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 9027 | struct dwarf2_cu *cu) |
c906108c | 9028 | { |
e7c27a73 | 9029 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9030 | unsigned int bytes_read; |
9031 | struct dwarf_block *blk; | |
9032 | ||
a8329558 KW |
9033 | attr->form = form; |
9034 | switch (form) | |
c906108c | 9035 | { |
c906108c | 9036 | case DW_FORM_ref_addr: |
ae411497 TT |
9037 | if (cu->header.version == 2) |
9038 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
9039 | else | |
9040 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9041 | info_ptr += bytes_read; | |
9042 | break; | |
9043 | case DW_FORM_addr: | |
e7c27a73 | 9044 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 9045 | info_ptr += bytes_read; |
c906108c SS |
9046 | break; |
9047 | case DW_FORM_block2: | |
7b5a2f43 | 9048 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9049 | blk->size = read_2_bytes (abfd, info_ptr); |
9050 | info_ptr += 2; | |
9051 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9052 | info_ptr += blk->size; | |
9053 | DW_BLOCK (attr) = blk; | |
9054 | break; | |
9055 | case DW_FORM_block4: | |
7b5a2f43 | 9056 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9057 | blk->size = read_4_bytes (abfd, info_ptr); |
9058 | info_ptr += 4; | |
9059 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9060 | info_ptr += blk->size; | |
9061 | DW_BLOCK (attr) = blk; | |
9062 | break; | |
9063 | case DW_FORM_data2: | |
9064 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
9065 | info_ptr += 2; | |
9066 | break; | |
9067 | case DW_FORM_data4: | |
9068 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
9069 | info_ptr += 4; | |
9070 | break; | |
9071 | case DW_FORM_data8: | |
9072 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
9073 | info_ptr += 8; | |
9074 | break; | |
2dc7f7b3 TT |
9075 | case DW_FORM_sec_offset: |
9076 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9077 | info_ptr += bytes_read; | |
9078 | break; | |
c906108c | 9079 | case DW_FORM_string: |
9b1c24c8 | 9080 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 9081 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
9082 | info_ptr += bytes_read; |
9083 | break; | |
4bdf3d34 JJ |
9084 | case DW_FORM_strp: |
9085 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
9086 | &bytes_read); | |
8285870a | 9087 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
9088 | info_ptr += bytes_read; |
9089 | break; | |
2dc7f7b3 | 9090 | case DW_FORM_exprloc: |
c906108c | 9091 | case DW_FORM_block: |
7b5a2f43 | 9092 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9093 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9094 | info_ptr += bytes_read; | |
9095 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9096 | info_ptr += blk->size; | |
9097 | DW_BLOCK (attr) = blk; | |
9098 | break; | |
9099 | case DW_FORM_block1: | |
7b5a2f43 | 9100 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9101 | blk->size = read_1_byte (abfd, info_ptr); |
9102 | info_ptr += 1; | |
9103 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9104 | info_ptr += blk->size; | |
9105 | DW_BLOCK (attr) = blk; | |
9106 | break; | |
9107 | case DW_FORM_data1: | |
9108 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9109 | info_ptr += 1; | |
9110 | break; | |
9111 | case DW_FORM_flag: | |
9112 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9113 | info_ptr += 1; | |
9114 | break; | |
2dc7f7b3 TT |
9115 | case DW_FORM_flag_present: |
9116 | DW_UNSND (attr) = 1; | |
9117 | break; | |
c906108c SS |
9118 | case DW_FORM_sdata: |
9119 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
9120 | info_ptr += bytes_read; | |
9121 | break; | |
9122 | case DW_FORM_udata: | |
9123 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9124 | info_ptr += bytes_read; | |
9125 | break; | |
9126 | case DW_FORM_ref1: | |
10b3939b | 9127 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
9128 | info_ptr += 1; |
9129 | break; | |
9130 | case DW_FORM_ref2: | |
10b3939b | 9131 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
9132 | info_ptr += 2; |
9133 | break; | |
9134 | case DW_FORM_ref4: | |
10b3939b | 9135 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
9136 | info_ptr += 4; |
9137 | break; | |
613e1657 | 9138 | case DW_FORM_ref8: |
10b3939b | 9139 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
9140 | info_ptr += 8; |
9141 | break; | |
348e048f DE |
9142 | case DW_FORM_sig8: |
9143 | /* Convert the signature to something we can record in DW_UNSND | |
9144 | for later lookup. | |
9145 | NOTE: This is NULL if the type wasn't found. */ | |
9146 | DW_SIGNATURED_TYPE (attr) = | |
9147 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
9148 | info_ptr += 8; | |
9149 | break; | |
c906108c | 9150 | case DW_FORM_ref_udata: |
10b3939b DJ |
9151 | DW_ADDR (attr) = (cu->header.offset |
9152 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
9153 | info_ptr += bytes_read; |
9154 | break; | |
c906108c | 9155 | case DW_FORM_indirect: |
a8329558 KW |
9156 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9157 | info_ptr += bytes_read; | |
e7c27a73 | 9158 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 9159 | break; |
c906108c | 9160 | default: |
8a3fe4f8 | 9161 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
9162 | dwarf_form_name (form), |
9163 | bfd_get_filename (abfd)); | |
c906108c | 9164 | } |
28e94949 JB |
9165 | |
9166 | /* We have seen instances where the compiler tried to emit a byte | |
9167 | size attribute of -1 which ended up being encoded as an unsigned | |
9168 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
9169 | an object of this size seems pretty unlikely so we can relatively | |
9170 | safely treat these cases as if the size attribute was invalid and | |
9171 | treat them as zero by default. */ | |
9172 | if (attr->name == DW_AT_byte_size | |
9173 | && form == DW_FORM_data4 | |
9174 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
9175 | { |
9176 | complaint | |
9177 | (&symfile_complaints, | |
43bbcdc2 PH |
9178 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
9179 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
9180 | DW_UNSND (attr) = 0; |
9181 | } | |
28e94949 | 9182 | |
c906108c SS |
9183 | return info_ptr; |
9184 | } | |
9185 | ||
a8329558 KW |
9186 | /* Read an attribute described by an abbreviated attribute. */ |
9187 | ||
fe1b8b76 | 9188 | static gdb_byte * |
a8329558 | 9189 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 9190 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
9191 | { |
9192 | attr->name = abbrev->name; | |
e7c27a73 | 9193 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
9194 | } |
9195 | ||
c906108c SS |
9196 | /* read dwarf information from a buffer */ |
9197 | ||
9198 | static unsigned int | |
fe1b8b76 | 9199 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9200 | { |
fe1b8b76 | 9201 | return bfd_get_8 (abfd, buf); |
c906108c SS |
9202 | } |
9203 | ||
9204 | static int | |
fe1b8b76 | 9205 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9206 | { |
fe1b8b76 | 9207 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
9208 | } |
9209 | ||
9210 | static unsigned int | |
fe1b8b76 | 9211 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9212 | { |
fe1b8b76 | 9213 | return bfd_get_16 (abfd, buf); |
c906108c SS |
9214 | } |
9215 | ||
9216 | static int | |
fe1b8b76 | 9217 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9218 | { |
fe1b8b76 | 9219 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
9220 | } |
9221 | ||
9222 | static unsigned int | |
fe1b8b76 | 9223 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9224 | { |
fe1b8b76 | 9225 | return bfd_get_32 (abfd, buf); |
c906108c SS |
9226 | } |
9227 | ||
9228 | static int | |
fe1b8b76 | 9229 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9230 | { |
fe1b8b76 | 9231 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
9232 | } |
9233 | ||
93311388 | 9234 | static ULONGEST |
fe1b8b76 | 9235 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9236 | { |
fe1b8b76 | 9237 | return bfd_get_64 (abfd, buf); |
c906108c SS |
9238 | } |
9239 | ||
9240 | static CORE_ADDR | |
fe1b8b76 | 9241 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 9242 | unsigned int *bytes_read) |
c906108c | 9243 | { |
e7c27a73 | 9244 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9245 | CORE_ADDR retval = 0; |
9246 | ||
107d2387 | 9247 | if (cu_header->signed_addr_p) |
c906108c | 9248 | { |
107d2387 AC |
9249 | switch (cu_header->addr_size) |
9250 | { | |
9251 | case 2: | |
fe1b8b76 | 9252 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
9253 | break; |
9254 | case 4: | |
fe1b8b76 | 9255 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
9256 | break; |
9257 | case 8: | |
fe1b8b76 | 9258 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
9259 | break; |
9260 | default: | |
8e65ff28 | 9261 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9262 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 9263 | bfd_get_filename (abfd)); |
107d2387 AC |
9264 | } |
9265 | } | |
9266 | else | |
9267 | { | |
9268 | switch (cu_header->addr_size) | |
9269 | { | |
9270 | case 2: | |
fe1b8b76 | 9271 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
9272 | break; |
9273 | case 4: | |
fe1b8b76 | 9274 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
9275 | break; |
9276 | case 8: | |
fe1b8b76 | 9277 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
9278 | break; |
9279 | default: | |
8e65ff28 | 9280 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9281 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 9282 | bfd_get_filename (abfd)); |
107d2387 | 9283 | } |
c906108c | 9284 | } |
64367e0a | 9285 | |
107d2387 AC |
9286 | *bytes_read = cu_header->addr_size; |
9287 | return retval; | |
c906108c SS |
9288 | } |
9289 | ||
f7ef9339 | 9290 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
9291 | specification allows the initial length to take up either 4 bytes |
9292 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
9293 | bytes describe the length and all offsets will be 8 bytes in length | |
9294 | instead of 4. | |
9295 | ||
f7ef9339 KB |
9296 | An older, non-standard 64-bit format is also handled by this |
9297 | function. The older format in question stores the initial length | |
9298 | as an 8-byte quantity without an escape value. Lengths greater | |
9299 | than 2^32 aren't very common which means that the initial 4 bytes | |
9300 | is almost always zero. Since a length value of zero doesn't make | |
9301 | sense for the 32-bit format, this initial zero can be considered to | |
9302 | be an escape value which indicates the presence of the older 64-bit | |
9303 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
9304 | greater than 4GB. If it becomes necessary to handle lengths |
9305 | somewhat larger than 4GB, we could allow other small values (such | |
9306 | as the non-sensical values of 1, 2, and 3) to also be used as | |
9307 | escape values indicating the presence of the old format. | |
f7ef9339 | 9308 | |
917c78fc MK |
9309 | The value returned via bytes_read should be used to increment the |
9310 | relevant pointer after calling read_initial_length(). | |
c764a876 | 9311 | |
613e1657 KB |
9312 | [ Note: read_initial_length() and read_offset() are based on the |
9313 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 9314 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
9315 | from: |
9316 | ||
f7ef9339 | 9317 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 9318 | |
613e1657 KB |
9319 | This document is only a draft and is subject to change. (So beware.) |
9320 | ||
f7ef9339 | 9321 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
9322 | determined empirically by examining 64-bit ELF files produced by |
9323 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
9324 | |
9325 | - Kevin, July 16, 2002 | |
613e1657 KB |
9326 | ] */ |
9327 | ||
9328 | static LONGEST | |
c764a876 | 9329 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 9330 | { |
fe1b8b76 | 9331 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 9332 | |
dd373385 | 9333 | if (length == 0xffffffff) |
613e1657 | 9334 | { |
fe1b8b76 | 9335 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 9336 | *bytes_read = 12; |
613e1657 | 9337 | } |
dd373385 | 9338 | else if (length == 0) |
f7ef9339 | 9339 | { |
dd373385 | 9340 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 9341 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 9342 | *bytes_read = 8; |
f7ef9339 | 9343 | } |
613e1657 KB |
9344 | else |
9345 | { | |
9346 | *bytes_read = 4; | |
613e1657 KB |
9347 | } |
9348 | ||
c764a876 DE |
9349 | return length; |
9350 | } | |
dd373385 | 9351 | |
c764a876 DE |
9352 | /* Cover function for read_initial_length. |
9353 | Returns the length of the object at BUF, and stores the size of the | |
9354 | initial length in *BYTES_READ and stores the size that offsets will be in | |
9355 | *OFFSET_SIZE. | |
9356 | If the initial length size is not equivalent to that specified in | |
9357 | CU_HEADER then issue a complaint. | |
9358 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 9359 | |
c764a876 DE |
9360 | static LONGEST |
9361 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
9362 | const struct comp_unit_head *cu_header, | |
9363 | unsigned int *bytes_read, | |
9364 | unsigned int *offset_size) | |
9365 | { | |
9366 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
9367 | ||
9368 | gdb_assert (cu_header->initial_length_size == 4 | |
9369 | || cu_header->initial_length_size == 8 | |
9370 | || cu_header->initial_length_size == 12); | |
9371 | ||
9372 | if (cu_header->initial_length_size != *bytes_read) | |
9373 | complaint (&symfile_complaints, | |
9374 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 9375 | |
c764a876 | 9376 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 9377 | return length; |
613e1657 KB |
9378 | } |
9379 | ||
9380 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 9381 | given by cu_header->offset_size. */ |
613e1657 KB |
9382 | |
9383 | static LONGEST | |
fe1b8b76 | 9384 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 9385 | unsigned int *bytes_read) |
c764a876 DE |
9386 | { |
9387 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 9388 | |
c764a876 DE |
9389 | *bytes_read = cu_header->offset_size; |
9390 | return offset; | |
9391 | } | |
9392 | ||
9393 | /* Read an offset from the data stream. */ | |
9394 | ||
9395 | static LONGEST | |
9396 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
9397 | { |
9398 | LONGEST retval = 0; | |
9399 | ||
c764a876 | 9400 | switch (offset_size) |
613e1657 KB |
9401 | { |
9402 | case 4: | |
fe1b8b76 | 9403 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
9404 | break; |
9405 | case 8: | |
fe1b8b76 | 9406 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
9407 | break; |
9408 | default: | |
8e65ff28 | 9409 | internal_error (__FILE__, __LINE__, |
c764a876 | 9410 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 9411 | bfd_get_filename (abfd)); |
613e1657 KB |
9412 | } |
9413 | ||
917c78fc | 9414 | return retval; |
613e1657 KB |
9415 | } |
9416 | ||
fe1b8b76 JB |
9417 | static gdb_byte * |
9418 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
9419 | { |
9420 | /* If the size of a host char is 8 bits, we can return a pointer | |
9421 | to the buffer, otherwise we have to copy the data to a buffer | |
9422 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9423 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 9424 | return buf; |
c906108c SS |
9425 | } |
9426 | ||
9427 | static char * | |
9b1c24c8 | 9428 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
9429 | { |
9430 | /* If the size of a host char is 8 bits, we can return a pointer | |
9431 | to the string, otherwise we have to copy the string to a buffer | |
9432 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9433 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
9434 | if (*buf == '\0') |
9435 | { | |
9436 | *bytes_read_ptr = 1; | |
9437 | return NULL; | |
9438 | } | |
fe1b8b76 JB |
9439 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
9440 | return (char *) buf; | |
4bdf3d34 JJ |
9441 | } |
9442 | ||
9443 | static char * | |
fe1b8b76 | 9444 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
9445 | const struct comp_unit_head *cu_header, |
9446 | unsigned int *bytes_read_ptr) | |
9447 | { | |
c764a876 | 9448 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 9449 | |
be391dca | 9450 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 9451 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 9452 | { |
8a3fe4f8 | 9453 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 9454 | bfd_get_filename (abfd)); |
4bdf3d34 | 9455 | return NULL; |
c906108c | 9456 | } |
dce234bc | 9457 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 9458 | { |
8a3fe4f8 | 9459 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 9460 | bfd_get_filename (abfd)); |
c906108c SS |
9461 | return NULL; |
9462 | } | |
4bdf3d34 | 9463 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 9464 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 9465 | return NULL; |
dce234bc | 9466 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
9467 | } |
9468 | ||
ce5d95e1 | 9469 | static unsigned long |
fe1b8b76 | 9470 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9471 | { |
ce5d95e1 JB |
9472 | unsigned long result; |
9473 | unsigned int num_read; | |
c906108c SS |
9474 | int i, shift; |
9475 | unsigned char byte; | |
9476 | ||
9477 | result = 0; | |
9478 | shift = 0; | |
9479 | num_read = 0; | |
9480 | i = 0; | |
9481 | while (1) | |
9482 | { | |
fe1b8b76 | 9483 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9484 | buf++; |
9485 | num_read++; | |
ce5d95e1 | 9486 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
9487 | if ((byte & 128) == 0) |
9488 | { | |
9489 | break; | |
9490 | } | |
9491 | shift += 7; | |
9492 | } | |
9493 | *bytes_read_ptr = num_read; | |
9494 | return result; | |
9495 | } | |
9496 | ||
ce5d95e1 | 9497 | static long |
fe1b8b76 | 9498 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9499 | { |
ce5d95e1 | 9500 | long result; |
77e0b926 | 9501 | int i, shift, num_read; |
c906108c SS |
9502 | unsigned char byte; |
9503 | ||
9504 | result = 0; | |
9505 | shift = 0; | |
c906108c SS |
9506 | num_read = 0; |
9507 | i = 0; | |
9508 | while (1) | |
9509 | { | |
fe1b8b76 | 9510 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9511 | buf++; |
9512 | num_read++; | |
ce5d95e1 | 9513 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
9514 | shift += 7; |
9515 | if ((byte & 128) == 0) | |
9516 | { | |
9517 | break; | |
9518 | } | |
9519 | } | |
77e0b926 DJ |
9520 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
9521 | result |= -(((long)1) << shift); | |
c906108c SS |
9522 | *bytes_read_ptr = num_read; |
9523 | return result; | |
9524 | } | |
9525 | ||
4bb7a0a7 DJ |
9526 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
9527 | ||
fe1b8b76 JB |
9528 | static gdb_byte * |
9529 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
9530 | { |
9531 | int byte; | |
9532 | ||
9533 | while (1) | |
9534 | { | |
fe1b8b76 | 9535 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
9536 | buf++; |
9537 | if ((byte & 128) == 0) | |
9538 | return buf; | |
9539 | } | |
9540 | } | |
9541 | ||
c906108c | 9542 | static void |
e142c38c | 9543 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
9544 | { |
9545 | switch (lang) | |
9546 | { | |
9547 | case DW_LANG_C89: | |
76bee0cc | 9548 | case DW_LANG_C99: |
c906108c | 9549 | case DW_LANG_C: |
e142c38c | 9550 | cu->language = language_c; |
c906108c SS |
9551 | break; |
9552 | case DW_LANG_C_plus_plus: | |
e142c38c | 9553 | cu->language = language_cplus; |
c906108c | 9554 | break; |
6aecb9c2 JB |
9555 | case DW_LANG_D: |
9556 | cu->language = language_d; | |
9557 | break; | |
c906108c SS |
9558 | case DW_LANG_Fortran77: |
9559 | case DW_LANG_Fortran90: | |
b21b22e0 | 9560 | case DW_LANG_Fortran95: |
e142c38c | 9561 | cu->language = language_fortran; |
c906108c SS |
9562 | break; |
9563 | case DW_LANG_Mips_Assembler: | |
e142c38c | 9564 | cu->language = language_asm; |
c906108c | 9565 | break; |
bebd888e | 9566 | case DW_LANG_Java: |
e142c38c | 9567 | cu->language = language_java; |
bebd888e | 9568 | break; |
c906108c | 9569 | case DW_LANG_Ada83: |
8aaf0b47 | 9570 | case DW_LANG_Ada95: |
bc5f45f8 JB |
9571 | cu->language = language_ada; |
9572 | break; | |
72019c9c GM |
9573 | case DW_LANG_Modula2: |
9574 | cu->language = language_m2; | |
9575 | break; | |
fe8e67fd PM |
9576 | case DW_LANG_Pascal83: |
9577 | cu->language = language_pascal; | |
9578 | break; | |
22566fbd DJ |
9579 | case DW_LANG_ObjC: |
9580 | cu->language = language_objc; | |
9581 | break; | |
c906108c SS |
9582 | case DW_LANG_Cobol74: |
9583 | case DW_LANG_Cobol85: | |
c906108c | 9584 | default: |
e142c38c | 9585 | cu->language = language_minimal; |
c906108c SS |
9586 | break; |
9587 | } | |
e142c38c | 9588 | cu->language_defn = language_def (cu->language); |
c906108c SS |
9589 | } |
9590 | ||
9591 | /* Return the named attribute or NULL if not there. */ | |
9592 | ||
9593 | static struct attribute * | |
e142c38c | 9594 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
9595 | { |
9596 | unsigned int i; | |
9597 | struct attribute *spec = NULL; | |
9598 | ||
9599 | for (i = 0; i < die->num_attrs; ++i) | |
9600 | { | |
9601 | if (die->attrs[i].name == name) | |
10b3939b | 9602 | return &die->attrs[i]; |
c906108c SS |
9603 | if (die->attrs[i].name == DW_AT_specification |
9604 | || die->attrs[i].name == DW_AT_abstract_origin) | |
9605 | spec = &die->attrs[i]; | |
9606 | } | |
c906108c | 9607 | |
10b3939b | 9608 | if (spec) |
f2f0e013 DJ |
9609 | { |
9610 | die = follow_die_ref (die, spec, &cu); | |
9611 | return dwarf2_attr (die, name, cu); | |
9612 | } | |
c5aa993b | 9613 | |
c906108c SS |
9614 | return NULL; |
9615 | } | |
9616 | ||
348e048f DE |
9617 | /* Return the named attribute or NULL if not there, |
9618 | but do not follow DW_AT_specification, etc. | |
9619 | This is for use in contexts where we're reading .debug_types dies. | |
9620 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
9621 | back up the chain, and we want to go down. */ | |
9622 | ||
9623 | static struct attribute * | |
9624 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
9625 | struct dwarf2_cu *cu) | |
9626 | { | |
9627 | unsigned int i; | |
9628 | ||
9629 | for (i = 0; i < die->num_attrs; ++i) | |
9630 | if (die->attrs[i].name == name) | |
9631 | return &die->attrs[i]; | |
9632 | ||
9633 | return NULL; | |
9634 | } | |
9635 | ||
05cf31d1 JB |
9636 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
9637 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 9638 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
9639 | |
9640 | static int | |
9641 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
9642 | { | |
9643 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
9644 | ||
9645 | return (attr && DW_UNSND (attr)); | |
9646 | } | |
9647 | ||
3ca72b44 | 9648 | static int |
e142c38c | 9649 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 9650 | { |
05cf31d1 JB |
9651 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
9652 | which value is non-zero. However, we have to be careful with | |
9653 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
9654 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
9655 | end up accidently finding a declaration attribute that belongs | |
9656 | to a different DIE referenced by the specification attribute, | |
9657 | even though the given DIE does not have a declaration attribute. */ | |
9658 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
9659 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
9660 | } |
9661 | ||
63d06c5c | 9662 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 9663 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
9664 | containing the return value on output. If there is no |
9665 | specification, but there is an abstract origin, that is | |
9666 | returned. */ | |
63d06c5c DC |
9667 | |
9668 | static struct die_info * | |
f2f0e013 | 9669 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 9670 | { |
f2f0e013 DJ |
9671 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
9672 | *spec_cu); | |
63d06c5c | 9673 | |
edb3359d DJ |
9674 | if (spec_attr == NULL) |
9675 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
9676 | ||
63d06c5c DC |
9677 | if (spec_attr == NULL) |
9678 | return NULL; | |
9679 | else | |
f2f0e013 | 9680 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 9681 | } |
c906108c | 9682 | |
debd256d JB |
9683 | /* Free the line_header structure *LH, and any arrays and strings it |
9684 | refers to. */ | |
9685 | static void | |
9686 | free_line_header (struct line_header *lh) | |
9687 | { | |
9688 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 9689 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
9690 | |
9691 | /* Remember that all the lh->file_names[i].name pointers are | |
9692 | pointers into debug_line_buffer, and don't need to be freed. */ | |
9693 | if (lh->file_names) | |
a8bc7b56 | 9694 | xfree (lh->file_names); |
debd256d JB |
9695 | |
9696 | /* Similarly for the include directory names. */ | |
9697 | if (lh->include_dirs) | |
a8bc7b56 | 9698 | xfree (lh->include_dirs); |
debd256d | 9699 | |
a8bc7b56 | 9700 | xfree (lh); |
debd256d JB |
9701 | } |
9702 | ||
9703 | ||
9704 | /* Add an entry to LH's include directory table. */ | |
9705 | static void | |
9706 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 9707 | { |
debd256d JB |
9708 | /* Grow the array if necessary. */ |
9709 | if (lh->include_dirs_size == 0) | |
c5aa993b | 9710 | { |
debd256d JB |
9711 | lh->include_dirs_size = 1; /* for testing */ |
9712 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
9713 | * sizeof (*lh->include_dirs)); | |
9714 | } | |
9715 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
9716 | { | |
9717 | lh->include_dirs_size *= 2; | |
9718 | lh->include_dirs = xrealloc (lh->include_dirs, | |
9719 | (lh->include_dirs_size | |
9720 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 9721 | } |
c906108c | 9722 | |
debd256d JB |
9723 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
9724 | } | |
6e70227d | 9725 | |
debd256d JB |
9726 | |
9727 | /* Add an entry to LH's file name table. */ | |
9728 | static void | |
9729 | add_file_name (struct line_header *lh, | |
9730 | char *name, | |
9731 | unsigned int dir_index, | |
9732 | unsigned int mod_time, | |
9733 | unsigned int length) | |
9734 | { | |
9735 | struct file_entry *fe; | |
9736 | ||
9737 | /* Grow the array if necessary. */ | |
9738 | if (lh->file_names_size == 0) | |
9739 | { | |
9740 | lh->file_names_size = 1; /* for testing */ | |
9741 | lh->file_names = xmalloc (lh->file_names_size | |
9742 | * sizeof (*lh->file_names)); | |
9743 | } | |
9744 | else if (lh->num_file_names >= lh->file_names_size) | |
9745 | { | |
9746 | lh->file_names_size *= 2; | |
9747 | lh->file_names = xrealloc (lh->file_names, | |
9748 | (lh->file_names_size | |
9749 | * sizeof (*lh->file_names))); | |
9750 | } | |
9751 | ||
9752 | fe = &lh->file_names[lh->num_file_names++]; | |
9753 | fe->name = name; | |
9754 | fe->dir_index = dir_index; | |
9755 | fe->mod_time = mod_time; | |
9756 | fe->length = length; | |
aaa75496 | 9757 | fe->included_p = 0; |
cb1df416 | 9758 | fe->symtab = NULL; |
debd256d | 9759 | } |
6e70227d | 9760 | |
debd256d JB |
9761 | |
9762 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
9763 | .debug_line, according to the endianness of ABFD. Return a pointer |
9764 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
9765 | |
9766 | NOTE: the strings in the include directory and file name tables of | |
9767 | the returned object point into debug_line_buffer, and must not be | |
9768 | freed. */ | |
9769 | static struct line_header * | |
9770 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 9771 | struct dwarf2_cu *cu) |
debd256d JB |
9772 | { |
9773 | struct cleanup *back_to; | |
9774 | struct line_header *lh; | |
fe1b8b76 | 9775 | gdb_byte *line_ptr; |
c764a876 | 9776 | unsigned int bytes_read, offset_size; |
debd256d JB |
9777 | int i; |
9778 | char *cur_dir, *cur_file; | |
9779 | ||
be391dca | 9780 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 9781 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 9782 | { |
e2e0b3e5 | 9783 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
9784 | return 0; |
9785 | } | |
9786 | ||
a738430d MK |
9787 | /* Make sure that at least there's room for the total_length field. |
9788 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 9789 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 9790 | { |
4d3c2250 | 9791 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9792 | return 0; |
9793 | } | |
9794 | ||
9795 | lh = xmalloc (sizeof (*lh)); | |
9796 | memset (lh, 0, sizeof (*lh)); | |
9797 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
9798 | (void *) lh); | |
9799 | ||
dce234bc | 9800 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 9801 | |
a738430d | 9802 | /* Read in the header. */ |
6e70227d | 9803 | lh->total_length = |
c764a876 DE |
9804 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
9805 | &bytes_read, &offset_size); | |
debd256d | 9806 | line_ptr += bytes_read; |
dce234bc PP |
9807 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
9808 | + dwarf2_per_objfile->line.size)) | |
debd256d | 9809 | { |
4d3c2250 | 9810 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9811 | return 0; |
9812 | } | |
9813 | lh->statement_program_end = line_ptr + lh->total_length; | |
9814 | lh->version = read_2_bytes (abfd, line_ptr); | |
9815 | line_ptr += 2; | |
c764a876 DE |
9816 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
9817 | line_ptr += offset_size; | |
debd256d JB |
9818 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
9819 | line_ptr += 1; | |
2dc7f7b3 TT |
9820 | if (lh->version >= 4) |
9821 | { | |
9822 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
9823 | line_ptr += 1; | |
9824 | } | |
9825 | else | |
9826 | lh->maximum_ops_per_instruction = 1; | |
9827 | ||
9828 | if (lh->maximum_ops_per_instruction == 0) | |
9829 | { | |
9830 | lh->maximum_ops_per_instruction = 1; | |
9831 | complaint (&symfile_complaints, | |
9832 | _("invalid maximum_ops_per_instruction in `.debug_line' section")); | |
9833 | } | |
9834 | ||
debd256d JB |
9835 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
9836 | line_ptr += 1; | |
9837 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
9838 | line_ptr += 1; | |
9839 | lh->line_range = read_1_byte (abfd, line_ptr); | |
9840 | line_ptr += 1; | |
9841 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
9842 | line_ptr += 1; | |
9843 | lh->standard_opcode_lengths | |
fe1b8b76 | 9844 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
9845 | |
9846 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
9847 | for (i = 1; i < lh->opcode_base; ++i) | |
9848 | { | |
9849 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
9850 | line_ptr += 1; | |
9851 | } | |
9852 | ||
a738430d | 9853 | /* Read directory table. */ |
9b1c24c8 | 9854 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
9855 | { |
9856 | line_ptr += bytes_read; | |
9857 | add_include_dir (lh, cur_dir); | |
9858 | } | |
9859 | line_ptr += bytes_read; | |
9860 | ||
a738430d | 9861 | /* Read file name table. */ |
9b1c24c8 | 9862 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
9863 | { |
9864 | unsigned int dir_index, mod_time, length; | |
9865 | ||
9866 | line_ptr += bytes_read; | |
9867 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9868 | line_ptr += bytes_read; | |
9869 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9870 | line_ptr += bytes_read; | |
9871 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9872 | line_ptr += bytes_read; | |
9873 | ||
9874 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9875 | } | |
9876 | line_ptr += bytes_read; | |
6e70227d | 9877 | lh->statement_program_start = line_ptr; |
debd256d | 9878 | |
dce234bc PP |
9879 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
9880 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 9881 | complaint (&symfile_complaints, |
e2e0b3e5 | 9882 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
9883 | |
9884 | discard_cleanups (back_to); | |
9885 | return lh; | |
9886 | } | |
c906108c | 9887 | |
5fb290d7 DJ |
9888 | /* This function exists to work around a bug in certain compilers |
9889 | (particularly GCC 2.95), in which the first line number marker of a | |
9890 | function does not show up until after the prologue, right before | |
9891 | the second line number marker. This function shifts ADDRESS down | |
9892 | to the beginning of the function if necessary, and is called on | |
9893 | addresses passed to record_line. */ | |
9894 | ||
9895 | static CORE_ADDR | |
e142c38c | 9896 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
9897 | { |
9898 | struct function_range *fn; | |
9899 | ||
9900 | /* Find the function_range containing address. */ | |
e142c38c | 9901 | if (!cu->first_fn) |
5fb290d7 DJ |
9902 | return address; |
9903 | ||
e142c38c DJ |
9904 | if (!cu->cached_fn) |
9905 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 9906 | |
e142c38c | 9907 | fn = cu->cached_fn; |
5fb290d7 DJ |
9908 | while (fn) |
9909 | if (fn->lowpc <= address && fn->highpc > address) | |
9910 | goto found; | |
9911 | else | |
9912 | fn = fn->next; | |
9913 | ||
e142c38c DJ |
9914 | fn = cu->first_fn; |
9915 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
9916 | if (fn->lowpc <= address && fn->highpc > address) |
9917 | goto found; | |
9918 | else | |
9919 | fn = fn->next; | |
9920 | ||
9921 | return address; | |
9922 | ||
9923 | found: | |
9924 | if (fn->seen_line) | |
9925 | return address; | |
9926 | if (address != fn->lowpc) | |
4d3c2250 | 9927 | complaint (&symfile_complaints, |
e2e0b3e5 | 9928 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 9929 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
9930 | fn->seen_line = 1; |
9931 | return fn->lowpc; | |
9932 | } | |
9933 | ||
c6da4cef DE |
9934 | /* Subroutine of dwarf_decode_lines to simplify it. |
9935 | Return the file name of the psymtab for included file FILE_INDEX | |
9936 | in line header LH of PST. | |
9937 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
9938 | If space for the result is malloc'd, it will be freed by a cleanup. | |
9939 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
9940 | ||
9941 | static char * | |
9942 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
9943 | const struct partial_symtab *pst, | |
9944 | const char *comp_dir) | |
9945 | { | |
9946 | const struct file_entry fe = lh->file_names [file_index]; | |
9947 | char *include_name = fe.name; | |
9948 | char *include_name_to_compare = include_name; | |
9949 | char *dir_name = NULL; | |
9950 | char *pst_filename; | |
9951 | int file_is_pst; | |
9952 | ||
9953 | if (fe.dir_index) | |
9954 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
9955 | ||
9956 | if (!IS_ABSOLUTE_PATH (include_name) | |
9957 | && (dir_name != NULL || comp_dir != NULL)) | |
9958 | { | |
9959 | /* Avoid creating a duplicate psymtab for PST. | |
9960 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
9961 | Before we do the comparison, however, we need to account | |
9962 | for DIR_NAME and COMP_DIR. | |
9963 | First prepend dir_name (if non-NULL). If we still don't | |
9964 | have an absolute path prepend comp_dir (if non-NULL). | |
9965 | However, the directory we record in the include-file's | |
9966 | psymtab does not contain COMP_DIR (to match the | |
9967 | corresponding symtab(s)). | |
9968 | ||
9969 | Example: | |
9970 | ||
9971 | bash$ cd /tmp | |
9972 | bash$ gcc -g ./hello.c | |
9973 | include_name = "hello.c" | |
9974 | dir_name = "." | |
9975 | DW_AT_comp_dir = comp_dir = "/tmp" | |
9976 | DW_AT_name = "./hello.c" */ | |
9977 | ||
9978 | if (dir_name != NULL) | |
9979 | { | |
9980 | include_name = concat (dir_name, SLASH_STRING, | |
9981 | include_name, (char *)NULL); | |
9982 | include_name_to_compare = include_name; | |
9983 | make_cleanup (xfree, include_name); | |
9984 | } | |
9985 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
9986 | { | |
9987 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
9988 | include_name, (char *)NULL); | |
9989 | } | |
9990 | } | |
9991 | ||
9992 | pst_filename = pst->filename; | |
9993 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
9994 | { | |
9995 | pst_filename = concat (pst->dirname, SLASH_STRING, | |
9996 | pst_filename, (char *)NULL); | |
9997 | } | |
9998 | ||
9999 | file_is_pst = strcmp (include_name_to_compare, pst_filename) == 0; | |
10000 | ||
10001 | if (include_name_to_compare != include_name) | |
10002 | xfree (include_name_to_compare); | |
10003 | if (pst_filename != pst->filename) | |
10004 | xfree (pst_filename); | |
10005 | ||
10006 | if (file_is_pst) | |
10007 | return NULL; | |
10008 | return include_name; | |
10009 | } | |
10010 | ||
aaa75496 JB |
10011 | /* Decode the Line Number Program (LNP) for the given line_header |
10012 | structure and CU. The actual information extracted and the type | |
10013 | of structures created from the LNP depends on the value of PST. | |
10014 | ||
10015 | 1. If PST is NULL, then this procedure uses the data from the program | |
10016 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 10017 | |
aaa75496 JB |
10018 | 2. If PST is not NULL, this procedure reads the program to determine |
10019 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
10020 | builds all the associated partial symbol tables. |
10021 | ||
10022 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10023 | It is used for relative paths in the line table. | |
10024 | NOTE: When processing partial symtabs (pst != NULL), | |
10025 | comp_dir == pst->dirname. | |
10026 | ||
10027 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
10028 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
10029 | symtab we don't use it in the name of the psymtabs we create. | |
10030 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
10031 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 10032 | |
c906108c | 10033 | static void |
debd256d | 10034 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 10035 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 10036 | { |
a8c50c1f | 10037 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 10038 | gdb_byte *line_end; |
a8c50c1f | 10039 | unsigned int bytes_read, extended_len; |
c906108c | 10040 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
10041 | CORE_ADDR baseaddr; |
10042 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 10043 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 10044 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 10045 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
10046 | |
10047 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10048 | |
debd256d JB |
10049 | line_ptr = lh->statement_program_start; |
10050 | line_end = lh->statement_program_end; | |
c906108c SS |
10051 | |
10052 | /* Read the statement sequences until there's nothing left. */ | |
10053 | while (line_ptr < line_end) | |
10054 | { | |
10055 | /* state machine registers */ | |
10056 | CORE_ADDR address = 0; | |
10057 | unsigned int file = 1; | |
10058 | unsigned int line = 1; | |
10059 | unsigned int column = 0; | |
debd256d | 10060 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
10061 | int basic_block = 0; |
10062 | int end_sequence = 0; | |
fbf65064 | 10063 | CORE_ADDR addr; |
2dc7f7b3 | 10064 | unsigned char op_index = 0; |
c906108c | 10065 | |
aaa75496 | 10066 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 10067 | { |
aaa75496 | 10068 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
10069 | /* lh->include_dirs and lh->file_names are 0-based, but the |
10070 | directory and file name numbers in the statement program | |
10071 | are 1-based. */ | |
10072 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 10073 | char *dir = NULL; |
a738430d | 10074 | |
debd256d JB |
10075 | if (fe->dir_index) |
10076 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
10077 | |
10078 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
10079 | } |
10080 | ||
a738430d | 10081 | /* Decode the table. */ |
c5aa993b | 10082 | while (!end_sequence) |
c906108c SS |
10083 | { |
10084 | op_code = read_1_byte (abfd, line_ptr); | |
10085 | line_ptr += 1; | |
59205f5a JB |
10086 | if (line_ptr > line_end) |
10087 | { | |
10088 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
10089 | break; | |
10090 | } | |
9aa1fe7e | 10091 | |
debd256d | 10092 | if (op_code >= lh->opcode_base) |
6e70227d | 10093 | { |
a738430d | 10094 | /* Special operand. */ |
debd256d | 10095 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
10096 | address += (((op_index + (adj_opcode / lh->line_range)) |
10097 | / lh->maximum_ops_per_instruction) | |
10098 | * lh->minimum_instruction_length); | |
10099 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
10100 | % lh->maximum_ops_per_instruction); | |
debd256d | 10101 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 10102 | if (lh->num_file_names < file || file == 0) |
25e43795 | 10103 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
10104 | /* For now we ignore lines not starting on an |
10105 | instruction boundary. */ | |
10106 | else if (op_index == 0) | |
25e43795 DJ |
10107 | { |
10108 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 10109 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10110 | { |
10111 | if (last_subfile != current_subfile) | |
10112 | { | |
10113 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10114 | if (last_subfile) | |
10115 | record_line (last_subfile, 0, addr); | |
10116 | last_subfile = current_subfile; | |
10117 | } | |
25e43795 | 10118 | /* Append row to matrix using current values. */ |
fbf65064 UW |
10119 | addr = check_cu_functions (address, cu); |
10120 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
10121 | record_line (current_subfile, line, addr); | |
366da635 | 10122 | } |
25e43795 | 10123 | } |
ca5f395d | 10124 | basic_block = 0; |
9aa1fe7e GK |
10125 | } |
10126 | else switch (op_code) | |
c906108c SS |
10127 | { |
10128 | case DW_LNS_extended_op: | |
a8c50c1f | 10129 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 10130 | line_ptr += bytes_read; |
a8c50c1f | 10131 | extended_end = line_ptr + extended_len; |
c906108c SS |
10132 | extended_op = read_1_byte (abfd, line_ptr); |
10133 | line_ptr += 1; | |
10134 | switch (extended_op) | |
10135 | { | |
10136 | case DW_LNE_end_sequence: | |
10137 | end_sequence = 1; | |
c906108c SS |
10138 | break; |
10139 | case DW_LNE_set_address: | |
e7c27a73 | 10140 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
2dc7f7b3 | 10141 | op_index = 0; |
107d2387 AC |
10142 | line_ptr += bytes_read; |
10143 | address += baseaddr; | |
c906108c SS |
10144 | break; |
10145 | case DW_LNE_define_file: | |
debd256d JB |
10146 | { |
10147 | char *cur_file; | |
10148 | unsigned int dir_index, mod_time, length; | |
6e70227d | 10149 | |
9b1c24c8 | 10150 | cur_file = read_direct_string (abfd, line_ptr, &bytes_read); |
debd256d JB |
10151 | line_ptr += bytes_read; |
10152 | dir_index = | |
10153 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10154 | line_ptr += bytes_read; | |
10155 | mod_time = | |
10156 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10157 | line_ptr += bytes_read; | |
10158 | length = | |
10159 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10160 | line_ptr += bytes_read; | |
10161 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10162 | } | |
c906108c | 10163 | break; |
d0c6ba3d CC |
10164 | case DW_LNE_set_discriminator: |
10165 | /* The discriminator is not interesting to the debugger; | |
10166 | just ignore it. */ | |
10167 | line_ptr = extended_end; | |
10168 | break; | |
c906108c | 10169 | default: |
4d3c2250 | 10170 | complaint (&symfile_complaints, |
e2e0b3e5 | 10171 | _("mangled .debug_line section")); |
debd256d | 10172 | return; |
c906108c | 10173 | } |
a8c50c1f DJ |
10174 | /* Make sure that we parsed the extended op correctly. If e.g. |
10175 | we expected a different address size than the producer used, | |
10176 | we may have read the wrong number of bytes. */ | |
10177 | if (line_ptr != extended_end) | |
10178 | { | |
10179 | complaint (&symfile_complaints, | |
10180 | _("mangled .debug_line section")); | |
10181 | return; | |
10182 | } | |
c906108c SS |
10183 | break; |
10184 | case DW_LNS_copy: | |
59205f5a | 10185 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10186 | dwarf2_debug_line_missing_file_complaint (); |
10187 | else | |
366da635 | 10188 | { |
25e43795 | 10189 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 10190 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10191 | { |
10192 | if (last_subfile != current_subfile) | |
10193 | { | |
10194 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10195 | if (last_subfile) | |
10196 | record_line (last_subfile, 0, addr); | |
10197 | last_subfile = current_subfile; | |
10198 | } | |
10199 | addr = check_cu_functions (address, cu); | |
10200 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
10201 | record_line (current_subfile, line, addr); | |
10202 | } | |
366da635 | 10203 | } |
c906108c SS |
10204 | basic_block = 0; |
10205 | break; | |
10206 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
10207 | { |
10208 | CORE_ADDR adjust | |
10209 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10210 | ||
10211 | address += (((op_index + adjust) | |
10212 | / lh->maximum_ops_per_instruction) | |
10213 | * lh->minimum_instruction_length); | |
10214 | op_index = ((op_index + adjust) | |
10215 | % lh->maximum_ops_per_instruction); | |
10216 | line_ptr += bytes_read; | |
10217 | } | |
c906108c SS |
10218 | break; |
10219 | case DW_LNS_advance_line: | |
10220 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
10221 | line_ptr += bytes_read; | |
10222 | break; | |
10223 | case DW_LNS_set_file: | |
debd256d | 10224 | { |
a738430d MK |
10225 | /* The arrays lh->include_dirs and lh->file_names are |
10226 | 0-based, but the directory and file name numbers in | |
10227 | the statement program are 1-based. */ | |
debd256d | 10228 | struct file_entry *fe; |
4f1520fb | 10229 | char *dir = NULL; |
a738430d | 10230 | |
debd256d JB |
10231 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
10232 | line_ptr += bytes_read; | |
59205f5a | 10233 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10234 | dwarf2_debug_line_missing_file_complaint (); |
10235 | else | |
10236 | { | |
10237 | fe = &lh->file_names[file - 1]; | |
10238 | if (fe->dir_index) | |
10239 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10240 | if (!decode_for_pst_p) | |
10241 | { | |
10242 | last_subfile = current_subfile; | |
10243 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10244 | } | |
10245 | } | |
debd256d | 10246 | } |
c906108c SS |
10247 | break; |
10248 | case DW_LNS_set_column: | |
10249 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10250 | line_ptr += bytes_read; | |
10251 | break; | |
10252 | case DW_LNS_negate_stmt: | |
10253 | is_stmt = (!is_stmt); | |
10254 | break; | |
10255 | case DW_LNS_set_basic_block: | |
10256 | basic_block = 1; | |
10257 | break; | |
c2c6d25f JM |
10258 | /* Add to the address register of the state machine the |
10259 | address increment value corresponding to special opcode | |
a738430d MK |
10260 | 255. I.e., this value is scaled by the minimum |
10261 | instruction length since special opcode 255 would have | |
10262 | scaled the the increment. */ | |
c906108c | 10263 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
10264 | { |
10265 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
10266 | ||
10267 | address += (((op_index + adjust) | |
10268 | / lh->maximum_ops_per_instruction) | |
10269 | * lh->minimum_instruction_length); | |
10270 | op_index = ((op_index + adjust) | |
10271 | % lh->maximum_ops_per_instruction); | |
10272 | } | |
c906108c SS |
10273 | break; |
10274 | case DW_LNS_fixed_advance_pc: | |
10275 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 10276 | op_index = 0; |
c906108c SS |
10277 | line_ptr += 2; |
10278 | break; | |
9aa1fe7e | 10279 | default: |
a738430d MK |
10280 | { |
10281 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 10282 | int i; |
a738430d | 10283 | |
debd256d | 10284 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
10285 | { |
10286 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10287 | line_ptr += bytes_read; | |
10288 | } | |
10289 | } | |
c906108c SS |
10290 | } |
10291 | } | |
59205f5a JB |
10292 | if (lh->num_file_names < file || file == 0) |
10293 | dwarf2_debug_line_missing_file_complaint (); | |
10294 | else | |
10295 | { | |
10296 | lh->file_names[file - 1].included_p = 1; | |
10297 | if (!decode_for_pst_p) | |
fbf65064 UW |
10298 | { |
10299 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10300 | record_line (current_subfile, 0, addr); | |
10301 | } | |
59205f5a | 10302 | } |
c906108c | 10303 | } |
aaa75496 JB |
10304 | |
10305 | if (decode_for_pst_p) | |
10306 | { | |
10307 | int file_index; | |
10308 | ||
10309 | /* Now that we're done scanning the Line Header Program, we can | |
10310 | create the psymtab of each included file. */ | |
10311 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
10312 | if (lh->file_names[file_index].included_p == 1) | |
10313 | { | |
c6da4cef DE |
10314 | char *include_name = |
10315 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
10316 | if (include_name != NULL) | |
aaa75496 JB |
10317 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
10318 | } | |
10319 | } | |
cb1df416 DJ |
10320 | else |
10321 | { | |
10322 | /* Make sure a symtab is created for every file, even files | |
10323 | which contain only variables (i.e. no code with associated | |
10324 | line numbers). */ | |
10325 | ||
10326 | int i; | |
10327 | struct file_entry *fe; | |
10328 | ||
10329 | for (i = 0; i < lh->num_file_names; i++) | |
10330 | { | |
10331 | char *dir = NULL; | |
9a619af0 | 10332 | |
cb1df416 DJ |
10333 | fe = &lh->file_names[i]; |
10334 | if (fe->dir_index) | |
10335 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10336 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10337 | ||
10338 | /* Skip the main file; we don't need it, and it must be | |
10339 | allocated last, so that it will show up before the | |
10340 | non-primary symtabs in the objfile's symtab list. */ | |
10341 | if (current_subfile == first_subfile) | |
10342 | continue; | |
10343 | ||
10344 | if (current_subfile->symtab == NULL) | |
10345 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
10346 | cu->objfile); | |
10347 | fe->symtab = current_subfile->symtab; | |
10348 | } | |
10349 | } | |
c906108c SS |
10350 | } |
10351 | ||
10352 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
10353 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
10354 | or NULL if not known. COMP_DIR is the compilation directory for the |
10355 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
10356 | This routine tries to keep line numbers from identical absolute and |
10357 | relative file names in a common subfile. | |
10358 | ||
10359 | Using the `list' example from the GDB testsuite, which resides in | |
10360 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
10361 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
10362 | ||
c5aa993b JM |
10363 | DW_AT_name: /srcdir/list0.c |
10364 | DW_AT_comp_dir: /compdir | |
357e46e7 | 10365 | files.files[0].name: list0.h |
c5aa993b | 10366 | files.files[0].dir: /srcdir |
357e46e7 | 10367 | files.files[1].name: list0.c |
c5aa993b | 10368 | files.files[1].dir: /srcdir |
c906108c SS |
10369 | |
10370 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
10371 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
10372 | start_subfile will ensure that this happens provided that we pass the | |
10373 | concatenation of files.files[1].dir and files.files[1].name as the | |
10374 | subfile's name. */ | |
c906108c SS |
10375 | |
10376 | static void | |
4f1520fb | 10377 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 10378 | { |
4f1520fb FR |
10379 | char *fullname; |
10380 | ||
10381 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
10382 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
10383 | second argument to start_subfile. To be consistent, we do the | |
10384 | same here. In order not to lose the line information directory, | |
10385 | we concatenate it to the filename when it makes sense. | |
10386 | Note that the Dwarf3 standard says (speaking of filenames in line | |
10387 | information): ``The directory index is ignored for file names | |
10388 | that represent full path names''. Thus ignoring dirname in the | |
10389 | `else' branch below isn't an issue. */ | |
c906108c | 10390 | |
d5166ae1 | 10391 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
10392 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
10393 | else | |
10394 | fullname = filename; | |
c906108c | 10395 | |
4f1520fb FR |
10396 | start_subfile (fullname, comp_dir); |
10397 | ||
10398 | if (fullname != filename) | |
10399 | xfree (fullname); | |
c906108c SS |
10400 | } |
10401 | ||
4c2df51b DJ |
10402 | static void |
10403 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 10404 | struct dwarf2_cu *cu) |
4c2df51b | 10405 | { |
e7c27a73 DJ |
10406 | struct objfile *objfile = cu->objfile; |
10407 | struct comp_unit_head *cu_header = &cu->header; | |
10408 | ||
4c2df51b DJ |
10409 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
10410 | code here to turn a symbol with DW_AT_external and a | |
10411 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
10412 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
10413 | with some versions of binutils) where shared libraries could have | |
10414 | relocations against symbols in their debug information - the | |
10415 | minimal symbol would have the right address, but the debug info | |
10416 | would not. It's no longer necessary, because we will explicitly | |
10417 | apply relocations when we read in the debug information now. */ | |
10418 | ||
10419 | /* A DW_AT_location attribute with no contents indicates that a | |
10420 | variable has been optimized away. */ | |
10421 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
10422 | { | |
10423 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
10424 | return; | |
10425 | } | |
10426 | ||
10427 | /* Handle one degenerate form of location expression specially, to | |
10428 | preserve GDB's previous behavior when section offsets are | |
10429 | specified. If this is just a DW_OP_addr then mark this symbol | |
10430 | as LOC_STATIC. */ | |
10431 | ||
10432 | if (attr_form_is_block (attr) | |
10433 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
10434 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
10435 | { | |
891d2f0b | 10436 | unsigned int dummy; |
4c2df51b DJ |
10437 | |
10438 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 10439 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 10440 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
10441 | fixup_symbol_section (sym, objfile); |
10442 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
10443 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
10444 | return; |
10445 | } | |
10446 | ||
10447 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
10448 | expression evaluator, and use LOC_COMPUTED only when necessary | |
10449 | (i.e. when the value of a register or memory location is | |
10450 | referenced, or a thread-local block, etc.). Then again, it might | |
10451 | not be worthwhile. I'm assuming that it isn't unless performance | |
10452 | or memory numbers show me otherwise. */ | |
10453 | ||
e7c27a73 | 10454 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
10455 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
10456 | } | |
10457 | ||
c906108c SS |
10458 | /* Given a pointer to a DWARF information entry, figure out if we need |
10459 | to make a symbol table entry for it, and if so, create a new entry | |
10460 | and return a pointer to it. | |
10461 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
10462 | used the passed type. |
10463 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
10464 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
10465 | |
10466 | static struct symbol * | |
34eaf542 TT |
10467 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
10468 | struct symbol *space) | |
c906108c | 10469 | { |
e7c27a73 | 10470 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10471 | struct symbol *sym = NULL; |
10472 | char *name; | |
10473 | struct attribute *attr = NULL; | |
10474 | struct attribute *attr2 = NULL; | |
e142c38c | 10475 | CORE_ADDR baseaddr; |
e37fd15a SW |
10476 | struct pending **list_to_add = NULL; |
10477 | ||
edb3359d | 10478 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
10479 | |
10480 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10481 | |
94af9270 | 10482 | name = dwarf2_name (die, cu); |
c906108c SS |
10483 | if (name) |
10484 | { | |
94af9270 | 10485 | const char *linkagename; |
34eaf542 | 10486 | int suppress_add = 0; |
94af9270 | 10487 | |
34eaf542 TT |
10488 | if (space) |
10489 | sym = space; | |
10490 | else | |
10491 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 10492 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
10493 | |
10494 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 10495 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
10496 | linkagename = dwarf2_physname (name, die, cu); |
10497 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 10498 | |
f55ee35c JK |
10499 | /* Fortran does not have mangling standard and the mangling does differ |
10500 | between gfortran, iFort etc. */ | |
10501 | if (cu->language == language_fortran | |
b250c185 | 10502 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
10503 | symbol_set_demangled_name (&(sym->ginfo), |
10504 | (char *) dwarf2_full_name (name, die, cu), | |
10505 | NULL); | |
f55ee35c | 10506 | |
c906108c | 10507 | /* Default assumptions. |
c5aa993b | 10508 | Use the passed type or decode it from the die. */ |
176620f1 | 10509 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 10510 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
10511 | if (type != NULL) |
10512 | SYMBOL_TYPE (sym) = type; | |
10513 | else | |
e7c27a73 | 10514 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
10515 | attr = dwarf2_attr (die, |
10516 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
10517 | cu); | |
c906108c SS |
10518 | if (attr) |
10519 | { | |
10520 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
10521 | } | |
cb1df416 | 10522 | |
edb3359d DJ |
10523 | attr = dwarf2_attr (die, |
10524 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
10525 | cu); | |
cb1df416 DJ |
10526 | if (attr) |
10527 | { | |
10528 | int file_index = DW_UNSND (attr); | |
9a619af0 | 10529 | |
cb1df416 DJ |
10530 | if (cu->line_header == NULL |
10531 | || file_index > cu->line_header->num_file_names) | |
10532 | complaint (&symfile_complaints, | |
10533 | _("file index out of range")); | |
1c3d648d | 10534 | else if (file_index > 0) |
cb1df416 DJ |
10535 | { |
10536 | struct file_entry *fe; | |
9a619af0 | 10537 | |
cb1df416 DJ |
10538 | fe = &cu->line_header->file_names[file_index - 1]; |
10539 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
10540 | } | |
10541 | } | |
10542 | ||
c906108c SS |
10543 | switch (die->tag) |
10544 | { | |
10545 | case DW_TAG_label: | |
e142c38c | 10546 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
10547 | if (attr) |
10548 | { | |
10549 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
10550 | } | |
0f5238ed TT |
10551 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
10552 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 10553 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 10554 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
10555 | break; |
10556 | case DW_TAG_subprogram: | |
10557 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
10558 | finish_block. */ | |
10559 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 10560 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
10561 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
10562 | || cu->language == language_ada) | |
c906108c | 10563 | { |
2cfa0c8d JB |
10564 | /* Subprograms marked external are stored as a global symbol. |
10565 | Ada subprograms, whether marked external or not, are always | |
10566 | stored as a global symbol, because we want to be able to | |
10567 | access them globally. For instance, we want to be able | |
10568 | to break on a nested subprogram without having to | |
10569 | specify the context. */ | |
e37fd15a | 10570 | list_to_add = &global_symbols; |
c906108c SS |
10571 | } |
10572 | else | |
10573 | { | |
e37fd15a | 10574 | list_to_add = cu->list_in_scope; |
c906108c SS |
10575 | } |
10576 | break; | |
edb3359d DJ |
10577 | case DW_TAG_inlined_subroutine: |
10578 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
10579 | finish_block. */ | |
10580 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
10581 | SYMBOL_INLINED (sym) = 1; | |
10582 | /* Do not add the symbol to any lists. It will be found via | |
10583 | BLOCK_FUNCTION from the blockvector. */ | |
10584 | break; | |
34eaf542 TT |
10585 | case DW_TAG_template_value_param: |
10586 | suppress_add = 1; | |
10587 | /* Fall through. */ | |
c906108c | 10588 | case DW_TAG_variable: |
254e6b9e | 10589 | case DW_TAG_member: |
c906108c SS |
10590 | /* Compilation with minimal debug info may result in variables |
10591 | with missing type entries. Change the misleading `void' type | |
10592 | to something sensible. */ | |
10593 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 10594 | SYMBOL_TYPE (sym) |
46bf5051 | 10595 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 10596 | |
e142c38c | 10597 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
10598 | /* In the case of DW_TAG_member, we should only be called for |
10599 | static const members. */ | |
10600 | if (die->tag == DW_TAG_member) | |
10601 | { | |
3863f96c DE |
10602 | /* dwarf2_add_field uses die_is_declaration, |
10603 | so we do the same. */ | |
254e6b9e DE |
10604 | gdb_assert (die_is_declaration (die, cu)); |
10605 | gdb_assert (attr); | |
10606 | } | |
c906108c SS |
10607 | if (attr) |
10608 | { | |
e7c27a73 | 10609 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 10610 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 10611 | if (!suppress_add) |
34eaf542 TT |
10612 | { |
10613 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 10614 | list_to_add = &global_symbols; |
34eaf542 | 10615 | else |
e37fd15a | 10616 | list_to_add = cu->list_in_scope; |
34eaf542 | 10617 | } |
c906108c SS |
10618 | break; |
10619 | } | |
e142c38c | 10620 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
10621 | if (attr) |
10622 | { | |
e7c27a73 | 10623 | var_decode_location (attr, sym, cu); |
e142c38c | 10624 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
10625 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
10626 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
10627 | && !dwarf2_per_objfile->has_section_at_zero) | |
10628 | { | |
10629 | /* When a static variable is eliminated by the linker, | |
10630 | the corresponding debug information is not stripped | |
10631 | out, but the variable address is set to null; | |
10632 | do not add such variables into symbol table. */ | |
10633 | } | |
10634 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 10635 | { |
f55ee35c JK |
10636 | /* Workaround gfortran PR debug/40040 - it uses |
10637 | DW_AT_location for variables in -fPIC libraries which may | |
10638 | get overriden by other libraries/executable and get | |
10639 | a different address. Resolve it by the minimal symbol | |
10640 | which may come from inferior's executable using copy | |
10641 | relocation. Make this workaround only for gfortran as for | |
10642 | other compilers GDB cannot guess the minimal symbol | |
10643 | Fortran mangling kind. */ | |
10644 | if (cu->language == language_fortran && die->parent | |
10645 | && die->parent->tag == DW_TAG_module | |
10646 | && cu->producer | |
10647 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
10648 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
10649 | ||
1c809c68 TT |
10650 | /* A variable with DW_AT_external is never static, |
10651 | but it may be block-scoped. */ | |
10652 | list_to_add = (cu->list_in_scope == &file_symbols | |
10653 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 10654 | } |
c906108c | 10655 | else |
e37fd15a | 10656 | list_to_add = cu->list_in_scope; |
c906108c SS |
10657 | } |
10658 | else | |
10659 | { | |
10660 | /* We do not know the address of this symbol. | |
c5aa993b JM |
10661 | If it is an external symbol and we have type information |
10662 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
10663 | The address of the variable will then be determined from | |
10664 | the minimal symbol table whenever the variable is | |
10665 | referenced. */ | |
e142c38c | 10666 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 10667 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 10668 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 10669 | { |
0fe7935b DJ |
10670 | /* A variable with DW_AT_external is never static, but it |
10671 | may be block-scoped. */ | |
10672 | list_to_add = (cu->list_in_scope == &file_symbols | |
10673 | ? &global_symbols : cu->list_in_scope); | |
10674 | ||
c906108c | 10675 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 10676 | } |
442ddf59 JK |
10677 | else if (!die_is_declaration (die, cu)) |
10678 | { | |
10679 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
10680 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
10681 | if (!suppress_add) |
10682 | list_to_add = cu->list_in_scope; | |
442ddf59 | 10683 | } |
c906108c SS |
10684 | } |
10685 | break; | |
10686 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
10687 | /* If we are inside a function, mark this as an argument. If |
10688 | not, we might be looking at an argument to an inlined function | |
10689 | when we do not have enough information to show inlined frames; | |
10690 | pretend it's a local variable in that case so that the user can | |
10691 | still see it. */ | |
10692 | if (context_stack_depth > 0 | |
10693 | && context_stack[context_stack_depth - 1].name != NULL) | |
10694 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 10695 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
10696 | if (attr) |
10697 | { | |
e7c27a73 | 10698 | var_decode_location (attr, sym, cu); |
c906108c | 10699 | } |
e142c38c | 10700 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10701 | if (attr) |
10702 | { | |
e7c27a73 | 10703 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10704 | } |
f346a30d PM |
10705 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
10706 | if (attr && DW_UNSND (attr)) | |
10707 | { | |
10708 | struct type *ref_type; | |
10709 | ||
10710 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
10711 | SYMBOL_TYPE (sym) = ref_type; | |
10712 | } | |
10713 | ||
e37fd15a | 10714 | list_to_add = cu->list_in_scope; |
c906108c SS |
10715 | break; |
10716 | case DW_TAG_unspecified_parameters: | |
10717 | /* From varargs functions; gdb doesn't seem to have any | |
10718 | interest in this information, so just ignore it for now. | |
10719 | (FIXME?) */ | |
10720 | break; | |
34eaf542 TT |
10721 | case DW_TAG_template_type_param: |
10722 | suppress_add = 1; | |
10723 | /* Fall through. */ | |
c906108c | 10724 | case DW_TAG_class_type: |
680b30c7 | 10725 | case DW_TAG_interface_type: |
c906108c SS |
10726 | case DW_TAG_structure_type: |
10727 | case DW_TAG_union_type: | |
72019c9c | 10728 | case DW_TAG_set_type: |
c906108c SS |
10729 | case DW_TAG_enumeration_type: |
10730 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 10731 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 10732 | |
63d06c5c | 10733 | { |
987504bb | 10734 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
10735 | really ever be static objects: otherwise, if you try |
10736 | to, say, break of a class's method and you're in a file | |
10737 | which doesn't mention that class, it won't work unless | |
10738 | the check for all static symbols in lookup_symbol_aux | |
10739 | saves you. See the OtherFileClass tests in | |
10740 | gdb.c++/namespace.exp. */ | |
10741 | ||
e37fd15a | 10742 | if (!suppress_add) |
34eaf542 | 10743 | { |
34eaf542 TT |
10744 | list_to_add = (cu->list_in_scope == &file_symbols |
10745 | && (cu->language == language_cplus | |
10746 | || cu->language == language_java) | |
10747 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 10748 | |
64382290 TT |
10749 | /* The semantics of C++ state that "struct foo { |
10750 | ... }" also defines a typedef for "foo". A Java | |
10751 | class declaration also defines a typedef for the | |
10752 | class. */ | |
10753 | if (cu->language == language_cplus | |
10754 | || cu->language == language_java | |
10755 | || cu->language == language_ada) | |
10756 | { | |
10757 | /* The symbol's name is already allocated along | |
10758 | with this objfile, so we don't need to | |
10759 | duplicate it for the type. */ | |
10760 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
10761 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
10762 | } | |
63d06c5c DC |
10763 | } |
10764 | } | |
c906108c SS |
10765 | break; |
10766 | case DW_TAG_typedef: | |
63d06c5c DC |
10767 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
10768 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 10769 | list_to_add = cu->list_in_scope; |
63d06c5c | 10770 | break; |
c906108c | 10771 | case DW_TAG_base_type: |
a02abb62 | 10772 | case DW_TAG_subrange_type: |
c906108c | 10773 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 10774 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 10775 | list_to_add = cu->list_in_scope; |
c906108c SS |
10776 | break; |
10777 | case DW_TAG_enumerator: | |
e142c38c | 10778 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10779 | if (attr) |
10780 | { | |
e7c27a73 | 10781 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10782 | } |
63d06c5c DC |
10783 | { |
10784 | /* NOTE: carlton/2003-11-10: See comment above in the | |
10785 | DW_TAG_class_type, etc. block. */ | |
10786 | ||
e142c38c | 10787 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
10788 | && (cu->language == language_cplus |
10789 | || cu->language == language_java) | |
e142c38c | 10790 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 10791 | } |
c906108c | 10792 | break; |
5c4e30ca DC |
10793 | case DW_TAG_namespace: |
10794 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 10795 | list_to_add = &global_symbols; |
5c4e30ca | 10796 | break; |
c906108c SS |
10797 | default: |
10798 | /* Not a tag we recognize. Hopefully we aren't processing | |
10799 | trash data, but since we must specifically ignore things | |
10800 | we don't recognize, there is nothing else we should do at | |
10801 | this point. */ | |
e2e0b3e5 | 10802 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 10803 | dwarf_tag_name (die->tag)); |
c906108c SS |
10804 | break; |
10805 | } | |
df8a16a1 | 10806 | |
e37fd15a SW |
10807 | if (suppress_add) |
10808 | { | |
10809 | sym->hash_next = objfile->template_symbols; | |
10810 | objfile->template_symbols = sym; | |
10811 | list_to_add = NULL; | |
10812 | } | |
10813 | ||
10814 | if (list_to_add != NULL) | |
10815 | add_symbol_to_list (sym, list_to_add); | |
10816 | ||
df8a16a1 DJ |
10817 | /* For the benefit of old versions of GCC, check for anonymous |
10818 | namespaces based on the demangled name. */ | |
10819 | if (!processing_has_namespace_info | |
94af9270 | 10820 | && cu->language == language_cplus) |
df8a16a1 | 10821 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
10822 | } |
10823 | return (sym); | |
10824 | } | |
10825 | ||
34eaf542 TT |
10826 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
10827 | ||
10828 | static struct symbol * | |
10829 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
10830 | { | |
10831 | return new_symbol_full (die, type, cu, NULL); | |
10832 | } | |
10833 | ||
98bfdba5 PA |
10834 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
10835 | zero-extend it as appropriate for the symbol's type. The DWARF | |
10836 | standard (v4) is not entirely clear about the meaning of using | |
10837 | DW_FORM_dataN for a constant with a signed type, where the type is | |
10838 | wider than the data. The conclusion of a discussion on the DWARF | |
10839 | list was that this is unspecified. We choose to always zero-extend | |
10840 | because that is the interpretation long in use by GCC. */ | |
c906108c | 10841 | |
98bfdba5 PA |
10842 | static gdb_byte * |
10843 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
10844 | const char *name, struct obstack *obstack, | |
10845 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 10846 | { |
e7c27a73 | 10847 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
10848 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
10849 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
10850 | LONGEST l = DW_UNSND (attr); |
10851 | ||
10852 | if (bits < sizeof (*value) * 8) | |
10853 | { | |
10854 | l &= ((LONGEST) 1 << bits) - 1; | |
10855 | *value = l; | |
10856 | } | |
10857 | else if (bits == sizeof (*value) * 8) | |
10858 | *value = l; | |
10859 | else | |
10860 | { | |
10861 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
10862 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
10863 | return bytes; | |
10864 | } | |
10865 | ||
10866 | return NULL; | |
10867 | } | |
10868 | ||
10869 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
10870 | the value does not fit in *VALUE, set *BYTES - either already | |
10871 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
10872 | or, set *BATON, if we translated the constant to a location | |
10873 | expression. */ | |
10874 | ||
10875 | static void | |
10876 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
10877 | const char *name, struct obstack *obstack, | |
10878 | struct dwarf2_cu *cu, | |
10879 | long *value, gdb_byte **bytes, | |
10880 | struct dwarf2_locexpr_baton **baton) | |
10881 | { | |
10882 | struct objfile *objfile = cu->objfile; | |
10883 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 10884 | struct dwarf_block *blk; |
98bfdba5 PA |
10885 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
10886 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
10887 | ||
10888 | *value = 0; | |
10889 | *bytes = NULL; | |
10890 | *baton = NULL; | |
c906108c SS |
10891 | |
10892 | switch (attr->form) | |
10893 | { | |
10894 | case DW_FORM_addr: | |
ac56253d | 10895 | { |
ac56253d TT |
10896 | gdb_byte *data; |
10897 | ||
98bfdba5 PA |
10898 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
10899 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 10900 | cu_header->addr_size, |
98bfdba5 | 10901 | TYPE_LENGTH (type)); |
ac56253d TT |
10902 | /* Symbols of this form are reasonably rare, so we just |
10903 | piggyback on the existing location code rather than writing | |
10904 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
10905 | *baton = obstack_alloc (&objfile->objfile_obstack, |
10906 | sizeof (struct dwarf2_locexpr_baton)); | |
10907 | (*baton)->per_cu = cu->per_cu; | |
10908 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 10909 | |
98bfdba5 PA |
10910 | (*baton)->size = 2 + cu_header->addr_size; |
10911 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
10912 | (*baton)->data = data; | |
ac56253d TT |
10913 | |
10914 | data[0] = DW_OP_addr; | |
10915 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
10916 | byte_order, DW_ADDR (attr)); | |
10917 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 10918 | } |
c906108c | 10919 | break; |
4ac36638 | 10920 | case DW_FORM_string: |
93b5768b | 10921 | case DW_FORM_strp: |
98bfdba5 PA |
10922 | /* DW_STRING is already allocated on the objfile obstack, point |
10923 | directly to it. */ | |
10924 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 10925 | break; |
c906108c SS |
10926 | case DW_FORM_block1: |
10927 | case DW_FORM_block2: | |
10928 | case DW_FORM_block4: | |
10929 | case DW_FORM_block: | |
2dc7f7b3 | 10930 | case DW_FORM_exprloc: |
c906108c | 10931 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
10932 | if (TYPE_LENGTH (type) != blk->size) |
10933 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
10934 | TYPE_LENGTH (type)); | |
10935 | *bytes = blk->data; | |
c906108c | 10936 | break; |
2df3850c JM |
10937 | |
10938 | /* The DW_AT_const_value attributes are supposed to carry the | |
10939 | symbol's value "represented as it would be on the target | |
10940 | architecture." By the time we get here, it's already been | |
10941 | converted to host endianness, so we just need to sign- or | |
10942 | zero-extend it as appropriate. */ | |
10943 | case DW_FORM_data1: | |
98bfdba5 | 10944 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 8); |
2df3850c | 10945 | break; |
c906108c | 10946 | case DW_FORM_data2: |
98bfdba5 | 10947 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 16); |
2df3850c | 10948 | break; |
c906108c | 10949 | case DW_FORM_data4: |
98bfdba5 | 10950 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 32); |
2df3850c | 10951 | break; |
c906108c | 10952 | case DW_FORM_data8: |
98bfdba5 | 10953 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 64); |
2df3850c JM |
10954 | break; |
10955 | ||
c906108c | 10956 | case DW_FORM_sdata: |
98bfdba5 | 10957 | *value = DW_SND (attr); |
2df3850c JM |
10958 | break; |
10959 | ||
c906108c | 10960 | case DW_FORM_udata: |
98bfdba5 | 10961 | *value = DW_UNSND (attr); |
c906108c | 10962 | break; |
2df3850c | 10963 | |
c906108c | 10964 | default: |
4d3c2250 | 10965 | complaint (&symfile_complaints, |
e2e0b3e5 | 10966 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 10967 | dwarf_form_name (attr->form)); |
98bfdba5 | 10968 | *value = 0; |
c906108c SS |
10969 | break; |
10970 | } | |
10971 | } | |
10972 | ||
2df3850c | 10973 | |
98bfdba5 PA |
10974 | /* Copy constant value from an attribute to a symbol. */ |
10975 | ||
2df3850c | 10976 | static void |
98bfdba5 PA |
10977 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
10978 | struct dwarf2_cu *cu) | |
2df3850c | 10979 | { |
98bfdba5 PA |
10980 | struct objfile *objfile = cu->objfile; |
10981 | struct comp_unit_head *cu_header = &cu->header; | |
10982 | long value; | |
10983 | gdb_byte *bytes; | |
10984 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 10985 | |
98bfdba5 PA |
10986 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
10987 | SYMBOL_PRINT_NAME (sym), | |
10988 | &objfile->objfile_obstack, cu, | |
10989 | &value, &bytes, &baton); | |
2df3850c | 10990 | |
98bfdba5 PA |
10991 | if (baton != NULL) |
10992 | { | |
10993 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
10994 | SYMBOL_LOCATION_BATON (sym) = baton; | |
10995 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
10996 | } | |
10997 | else if (bytes != NULL) | |
10998 | { | |
10999 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
11000 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
11001 | } | |
11002 | else | |
11003 | { | |
11004 | SYMBOL_VALUE (sym) = value; | |
11005 | SYMBOL_CLASS (sym) = LOC_CONST; | |
11006 | } | |
2df3850c JM |
11007 | } |
11008 | ||
c906108c SS |
11009 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
11010 | ||
11011 | static struct type * | |
e7c27a73 | 11012 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11013 | { |
c906108c | 11014 | struct attribute *type_attr; |
c906108c | 11015 | |
e142c38c | 11016 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
11017 | if (!type_attr) |
11018 | { | |
11019 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 11020 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 11021 | } |
348e048f | 11022 | |
673bfd45 | 11023 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11024 | } |
11025 | ||
b4ba55a1 JB |
11026 | /* True iff CU's producer generates GNAT Ada auxiliary information |
11027 | that allows to find parallel types through that information instead | |
11028 | of having to do expensive parallel lookups by type name. */ | |
11029 | ||
11030 | static int | |
11031 | need_gnat_info (struct dwarf2_cu *cu) | |
11032 | { | |
11033 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
11034 | of GNAT produces this auxiliary information, without any indication | |
11035 | that it is produced. Part of enhancing the FSF version of GNAT | |
11036 | to produce that information will be to put in place an indicator | |
11037 | that we can use in order to determine whether the descriptive type | |
11038 | info is available or not. One suggestion that has been made is | |
11039 | to use a new attribute, attached to the CU die. For now, assume | |
11040 | that the descriptive type info is not available. */ | |
11041 | return 0; | |
11042 | } | |
11043 | ||
b4ba55a1 JB |
11044 | /* Return the auxiliary type of the die in question using its |
11045 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
11046 | attribute is not present. */ | |
11047 | ||
11048 | static struct type * | |
11049 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
11050 | { | |
b4ba55a1 | 11051 | struct attribute *type_attr; |
b4ba55a1 JB |
11052 | |
11053 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
11054 | if (!type_attr) | |
11055 | return NULL; | |
11056 | ||
673bfd45 | 11057 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
11058 | } |
11059 | ||
11060 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
11061 | descriptive type accordingly. */ | |
11062 | ||
11063 | static void | |
11064 | set_descriptive_type (struct type *type, struct die_info *die, | |
11065 | struct dwarf2_cu *cu) | |
11066 | { | |
11067 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
11068 | ||
11069 | if (descriptive_type) | |
11070 | { | |
11071 | ALLOCATE_GNAT_AUX_TYPE (type); | |
11072 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
11073 | } | |
11074 | } | |
11075 | ||
c906108c SS |
11076 | /* Return the containing type of the die in question using its |
11077 | DW_AT_containing_type attribute. */ | |
11078 | ||
11079 | static struct type * | |
e7c27a73 | 11080 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11081 | { |
c906108c | 11082 | struct attribute *type_attr; |
c906108c | 11083 | |
e142c38c | 11084 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
11085 | if (!type_attr) |
11086 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
11087 | "[in module %s]"), cu->objfile->name); | |
11088 | ||
673bfd45 | 11089 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11090 | } |
11091 | ||
673bfd45 DE |
11092 | /* Look up the type of DIE in CU using its type attribute ATTR. |
11093 | If there is no type substitute an error marker. */ | |
11094 | ||
c906108c | 11095 | static struct type * |
673bfd45 DE |
11096 | lookup_die_type (struct die_info *die, struct attribute *attr, |
11097 | struct dwarf2_cu *cu) | |
c906108c | 11098 | { |
f792889a DJ |
11099 | struct type *this_type; |
11100 | ||
673bfd45 DE |
11101 | /* First see if we have it cached. */ |
11102 | ||
11103 | if (is_ref_attr (attr)) | |
11104 | { | |
11105 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11106 | ||
11107 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
11108 | } | |
11109 | else if (attr->form == DW_FORM_sig8) | |
11110 | { | |
11111 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11112 | struct dwarf2_cu *sig_cu; | |
11113 | unsigned int offset; | |
11114 | ||
11115 | /* sig_type will be NULL if the signatured type is missing from | |
11116 | the debug info. */ | |
11117 | if (sig_type == NULL) | |
11118 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
11119 | "at 0x%x [in module %s]"), | |
11120 | die->offset, cu->objfile->name); | |
11121 | ||
11122 | gdb_assert (sig_type->per_cu.from_debug_types); | |
11123 | offset = sig_type->offset + sig_type->type_offset; | |
11124 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); | |
11125 | } | |
11126 | else | |
11127 | { | |
11128 | dump_die_for_error (die); | |
11129 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
11130 | dwarf_attr_name (attr->name), cu->objfile->name); | |
11131 | } | |
11132 | ||
11133 | /* If not cached we need to read it in. */ | |
11134 | ||
11135 | if (this_type == NULL) | |
11136 | { | |
11137 | struct die_info *type_die; | |
11138 | struct dwarf2_cu *type_cu = cu; | |
11139 | ||
11140 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
11141 | /* If the type is cached, we should have found it above. */ | |
11142 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
11143 | this_type = read_type_die_1 (type_die, type_cu); | |
11144 | } | |
11145 | ||
11146 | /* If we still don't have a type use an error marker. */ | |
11147 | ||
11148 | if (this_type == NULL) | |
c906108c | 11149 | { |
b00fdb78 TT |
11150 | char *message, *saved; |
11151 | ||
11152 | /* read_type_die already issued a complaint. */ | |
11153 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
11154 | cu->objfile->name, | |
11155 | cu->header.offset, | |
11156 | die->offset); | |
11157 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
11158 | message, strlen (message)); | |
11159 | xfree (message); | |
11160 | ||
11161 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 11162 | } |
673bfd45 | 11163 | |
f792889a | 11164 | return this_type; |
c906108c SS |
11165 | } |
11166 | ||
673bfd45 DE |
11167 | /* Return the type in DIE, CU. |
11168 | Returns NULL for invalid types. | |
11169 | ||
11170 | This first does a lookup in the appropriate type_hash table, | |
11171 | and only reads the die in if necessary. | |
11172 | ||
11173 | NOTE: This can be called when reading in partial or full symbols. */ | |
11174 | ||
f792889a | 11175 | static struct type * |
e7c27a73 | 11176 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11177 | { |
f792889a DJ |
11178 | struct type *this_type; |
11179 | ||
11180 | this_type = get_die_type (die, cu); | |
11181 | if (this_type) | |
11182 | return this_type; | |
11183 | ||
673bfd45 DE |
11184 | return read_type_die_1 (die, cu); |
11185 | } | |
11186 | ||
11187 | /* Read the type in DIE, CU. | |
11188 | Returns NULL for invalid types. */ | |
11189 | ||
11190 | static struct type * | |
11191 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
11192 | { | |
11193 | struct type *this_type = NULL; | |
11194 | ||
c906108c SS |
11195 | switch (die->tag) |
11196 | { | |
11197 | case DW_TAG_class_type: | |
680b30c7 | 11198 | case DW_TAG_interface_type: |
c906108c SS |
11199 | case DW_TAG_structure_type: |
11200 | case DW_TAG_union_type: | |
f792889a | 11201 | this_type = read_structure_type (die, cu); |
c906108c SS |
11202 | break; |
11203 | case DW_TAG_enumeration_type: | |
f792889a | 11204 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
11205 | break; |
11206 | case DW_TAG_subprogram: | |
11207 | case DW_TAG_subroutine_type: | |
edb3359d | 11208 | case DW_TAG_inlined_subroutine: |
f792889a | 11209 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
11210 | break; |
11211 | case DW_TAG_array_type: | |
f792889a | 11212 | this_type = read_array_type (die, cu); |
c906108c | 11213 | break; |
72019c9c | 11214 | case DW_TAG_set_type: |
f792889a | 11215 | this_type = read_set_type (die, cu); |
72019c9c | 11216 | break; |
c906108c | 11217 | case DW_TAG_pointer_type: |
f792889a | 11218 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
11219 | break; |
11220 | case DW_TAG_ptr_to_member_type: | |
f792889a | 11221 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
11222 | break; |
11223 | case DW_TAG_reference_type: | |
f792889a | 11224 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
11225 | break; |
11226 | case DW_TAG_const_type: | |
f792889a | 11227 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
11228 | break; |
11229 | case DW_TAG_volatile_type: | |
f792889a | 11230 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
11231 | break; |
11232 | case DW_TAG_string_type: | |
f792889a | 11233 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
11234 | break; |
11235 | case DW_TAG_typedef: | |
f792889a | 11236 | this_type = read_typedef (die, cu); |
c906108c | 11237 | break; |
a02abb62 | 11238 | case DW_TAG_subrange_type: |
f792889a | 11239 | this_type = read_subrange_type (die, cu); |
a02abb62 | 11240 | break; |
c906108c | 11241 | case DW_TAG_base_type: |
f792889a | 11242 | this_type = read_base_type (die, cu); |
c906108c | 11243 | break; |
81a17f79 | 11244 | case DW_TAG_unspecified_type: |
f792889a | 11245 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 11246 | break; |
0114d602 DJ |
11247 | case DW_TAG_namespace: |
11248 | this_type = read_namespace_type (die, cu); | |
11249 | break; | |
f55ee35c JK |
11250 | case DW_TAG_module: |
11251 | this_type = read_module_type (die, cu); | |
11252 | break; | |
c906108c | 11253 | default: |
a1f5b845 | 11254 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 11255 | dwarf_tag_name (die->tag)); |
c906108c SS |
11256 | break; |
11257 | } | |
63d06c5c | 11258 | |
f792889a | 11259 | return this_type; |
63d06c5c DC |
11260 | } |
11261 | ||
fdde2d81 | 11262 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 11263 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 11264 | |
0114d602 DJ |
11265 | For example, if we're within the method foo() in the following |
11266 | code: | |
11267 | ||
11268 | namespace N { | |
11269 | class C { | |
11270 | void foo () { | |
11271 | } | |
11272 | }; | |
11273 | } | |
11274 | ||
11275 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
11276 | |
11277 | static char * | |
e142c38c | 11278 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 11279 | { |
0114d602 DJ |
11280 | struct die_info *parent, *spec_die; |
11281 | struct dwarf2_cu *spec_cu; | |
11282 | struct type *parent_type; | |
63d06c5c | 11283 | |
f55ee35c JK |
11284 | if (cu->language != language_cplus && cu->language != language_java |
11285 | && cu->language != language_fortran) | |
0114d602 DJ |
11286 | return ""; |
11287 | ||
11288 | /* We have to be careful in the presence of DW_AT_specification. | |
11289 | For example, with GCC 3.4, given the code | |
11290 | ||
11291 | namespace N { | |
11292 | void foo() { | |
11293 | // Definition of N::foo. | |
11294 | } | |
11295 | } | |
11296 | ||
11297 | then we'll have a tree of DIEs like this: | |
11298 | ||
11299 | 1: DW_TAG_compile_unit | |
11300 | 2: DW_TAG_namespace // N | |
11301 | 3: DW_TAG_subprogram // declaration of N::foo | |
11302 | 4: DW_TAG_subprogram // definition of N::foo | |
11303 | DW_AT_specification // refers to die #3 | |
11304 | ||
11305 | Thus, when processing die #4, we have to pretend that we're in | |
11306 | the context of its DW_AT_specification, namely the contex of die | |
11307 | #3. */ | |
11308 | spec_cu = cu; | |
11309 | spec_die = die_specification (die, &spec_cu); | |
11310 | if (spec_die == NULL) | |
11311 | parent = die->parent; | |
11312 | else | |
63d06c5c | 11313 | { |
0114d602 DJ |
11314 | parent = spec_die->parent; |
11315 | cu = spec_cu; | |
63d06c5c | 11316 | } |
0114d602 DJ |
11317 | |
11318 | if (parent == NULL) | |
11319 | return ""; | |
98bfdba5 PA |
11320 | else if (parent->building_fullname) |
11321 | { | |
11322 | const char *name; | |
11323 | const char *parent_name; | |
11324 | ||
11325 | /* It has been seen on RealView 2.2 built binaries, | |
11326 | DW_TAG_template_type_param types actually _defined_ as | |
11327 | children of the parent class: | |
11328 | ||
11329 | enum E {}; | |
11330 | template class <class Enum> Class{}; | |
11331 | Class<enum E> class_e; | |
11332 | ||
11333 | 1: DW_TAG_class_type (Class) | |
11334 | 2: DW_TAG_enumeration_type (E) | |
11335 | 3: DW_TAG_enumerator (enum1:0) | |
11336 | 3: DW_TAG_enumerator (enum2:1) | |
11337 | ... | |
11338 | 2: DW_TAG_template_type_param | |
11339 | DW_AT_type DW_FORM_ref_udata (E) | |
11340 | ||
11341 | Besides being broken debug info, it can put GDB into an | |
11342 | infinite loop. Consider: | |
11343 | ||
11344 | When we're building the full name for Class<E>, we'll start | |
11345 | at Class, and go look over its template type parameters, | |
11346 | finding E. We'll then try to build the full name of E, and | |
11347 | reach here. We're now trying to build the full name of E, | |
11348 | and look over the parent DIE for containing scope. In the | |
11349 | broken case, if we followed the parent DIE of E, we'd again | |
11350 | find Class, and once again go look at its template type | |
11351 | arguments, etc., etc. Simply don't consider such parent die | |
11352 | as source-level parent of this die (it can't be, the language | |
11353 | doesn't allow it), and break the loop here. */ | |
11354 | name = dwarf2_name (die, cu); | |
11355 | parent_name = dwarf2_name (parent, cu); | |
11356 | complaint (&symfile_complaints, | |
11357 | _("template param type '%s' defined within parent '%s'"), | |
11358 | name ? name : "<unknown>", | |
11359 | parent_name ? parent_name : "<unknown>"); | |
11360 | return ""; | |
11361 | } | |
63d06c5c | 11362 | else |
0114d602 DJ |
11363 | switch (parent->tag) |
11364 | { | |
63d06c5c | 11365 | case DW_TAG_namespace: |
0114d602 | 11366 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
11367 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
11368 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
11369 | Work around this problem here. */ | |
11370 | if (cu->language == language_cplus | |
11371 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
11372 | return ""; | |
0114d602 DJ |
11373 | /* We give a name to even anonymous namespaces. */ |
11374 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 11375 | case DW_TAG_class_type: |
680b30c7 | 11376 | case DW_TAG_interface_type: |
63d06c5c | 11377 | case DW_TAG_structure_type: |
0114d602 | 11378 | case DW_TAG_union_type: |
f55ee35c | 11379 | case DW_TAG_module: |
0114d602 DJ |
11380 | parent_type = read_type_die (parent, cu); |
11381 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
11382 | return TYPE_TAG_NAME (parent_type); | |
11383 | else | |
11384 | /* An anonymous structure is only allowed non-static data | |
11385 | members; no typedefs, no member functions, et cetera. | |
11386 | So it does not need a prefix. */ | |
11387 | return ""; | |
63d06c5c | 11388 | default: |
8176b9b8 | 11389 | return determine_prefix (parent, cu); |
63d06c5c | 11390 | } |
63d06c5c DC |
11391 | } |
11392 | ||
987504bb JJ |
11393 | /* Return a newly-allocated string formed by concatenating PREFIX and |
11394 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
11395 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
11396 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
11397 | is used to determine the language and hence, the appropriate separator. */ | |
11398 | ||
f55ee35c | 11399 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
11400 | |
11401 | static char * | |
f55ee35c JK |
11402 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
11403 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 11404 | { |
f55ee35c | 11405 | const char *lead = ""; |
5c315b68 | 11406 | const char *sep; |
63d06c5c | 11407 | |
987504bb JJ |
11408 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
11409 | sep = ""; | |
11410 | else if (cu->language == language_java) | |
11411 | sep = "."; | |
f55ee35c JK |
11412 | else if (cu->language == language_fortran && physname) |
11413 | { | |
11414 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
11415 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
11416 | ||
11417 | lead = "__"; | |
11418 | sep = "_MOD_"; | |
11419 | } | |
987504bb JJ |
11420 | else |
11421 | sep = "::"; | |
63d06c5c | 11422 | |
6dd47d34 DE |
11423 | if (prefix == NULL) |
11424 | prefix = ""; | |
11425 | if (suffix == NULL) | |
11426 | suffix = ""; | |
11427 | ||
987504bb JJ |
11428 | if (obs == NULL) |
11429 | { | |
11430 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 11431 | |
f55ee35c JK |
11432 | strcpy (retval, lead); |
11433 | strcat (retval, prefix); | |
6dd47d34 DE |
11434 | strcat (retval, sep); |
11435 | strcat (retval, suffix); | |
63d06c5c DC |
11436 | return retval; |
11437 | } | |
987504bb JJ |
11438 | else |
11439 | { | |
11440 | /* We have an obstack. */ | |
f55ee35c | 11441 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 11442 | } |
63d06c5c DC |
11443 | } |
11444 | ||
c906108c SS |
11445 | /* Return sibling of die, NULL if no sibling. */ |
11446 | ||
f9aca02d | 11447 | static struct die_info * |
fba45db2 | 11448 | sibling_die (struct die_info *die) |
c906108c | 11449 | { |
639d11d3 | 11450 | return die->sibling; |
c906108c SS |
11451 | } |
11452 | ||
71c25dea TT |
11453 | /* Get name of a die, return NULL if not found. */ |
11454 | ||
11455 | static char * | |
11456 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
11457 | struct obstack *obstack) | |
11458 | { | |
11459 | if (name && cu->language == language_cplus) | |
11460 | { | |
11461 | char *canon_name = cp_canonicalize_string (name); | |
11462 | ||
11463 | if (canon_name != NULL) | |
11464 | { | |
11465 | if (strcmp (canon_name, name) != 0) | |
11466 | name = obsavestring (canon_name, strlen (canon_name), | |
11467 | obstack); | |
11468 | xfree (canon_name); | |
11469 | } | |
11470 | } | |
11471 | ||
11472 | return name; | |
c906108c SS |
11473 | } |
11474 | ||
9219021c DC |
11475 | /* Get name of a die, return NULL if not found. */ |
11476 | ||
11477 | static char * | |
e142c38c | 11478 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
11479 | { |
11480 | struct attribute *attr; | |
11481 | ||
e142c38c | 11482 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
11483 | if (!attr || !DW_STRING (attr)) |
11484 | return NULL; | |
11485 | ||
11486 | switch (die->tag) | |
11487 | { | |
11488 | case DW_TAG_compile_unit: | |
11489 | /* Compilation units have a DW_AT_name that is a filename, not | |
11490 | a source language identifier. */ | |
11491 | case DW_TAG_enumeration_type: | |
11492 | case DW_TAG_enumerator: | |
11493 | /* These tags always have simple identifiers already; no need | |
11494 | to canonicalize them. */ | |
11495 | return DW_STRING (attr); | |
907af001 | 11496 | |
418835cc KS |
11497 | case DW_TAG_subprogram: |
11498 | /* Java constructors will all be named "<init>", so return | |
11499 | the class name when we see this special case. */ | |
11500 | if (cu->language == language_java | |
11501 | && DW_STRING (attr) != NULL | |
11502 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
11503 | { | |
11504 | struct dwarf2_cu *spec_cu = cu; | |
11505 | struct die_info *spec_die; | |
11506 | ||
11507 | /* GCJ will output '<init>' for Java constructor names. | |
11508 | For this special case, return the name of the parent class. */ | |
11509 | ||
11510 | /* GCJ may output suprogram DIEs with AT_specification set. | |
11511 | If so, use the name of the specified DIE. */ | |
11512 | spec_die = die_specification (die, &spec_cu); | |
11513 | if (spec_die != NULL) | |
11514 | return dwarf2_name (spec_die, spec_cu); | |
11515 | ||
11516 | do | |
11517 | { | |
11518 | die = die->parent; | |
11519 | if (die->tag == DW_TAG_class_type) | |
11520 | return dwarf2_name (die, cu); | |
11521 | } | |
11522 | while (die->tag != DW_TAG_compile_unit); | |
11523 | } | |
907af001 UW |
11524 | break; |
11525 | ||
11526 | case DW_TAG_class_type: | |
11527 | case DW_TAG_interface_type: | |
11528 | case DW_TAG_structure_type: | |
11529 | case DW_TAG_union_type: | |
11530 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
11531 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
11532 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
11533 | and GCC 4.4. We work around this problem by ignoring these. */ | |
11534 | if (strncmp (DW_STRING (attr), "._", 2) == 0 | |
11535 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) | |
11536 | return NULL; | |
11537 | break; | |
11538 | ||
71c25dea | 11539 | default: |
907af001 UW |
11540 | break; |
11541 | } | |
11542 | ||
11543 | if (!DW_STRING_IS_CANONICAL (attr)) | |
11544 | { | |
11545 | DW_STRING (attr) | |
11546 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
11547 | &cu->objfile->objfile_obstack); | |
11548 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 11549 | } |
907af001 | 11550 | return DW_STRING (attr); |
9219021c DC |
11551 | } |
11552 | ||
11553 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
11554 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
11555 | containing the return value on output. */ | |
9219021c DC |
11556 | |
11557 | static struct die_info * | |
f2f0e013 | 11558 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
11559 | { |
11560 | struct attribute *attr; | |
9219021c | 11561 | |
f2f0e013 | 11562 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
11563 | if (attr == NULL) |
11564 | return NULL; | |
11565 | ||
f2f0e013 | 11566 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
11567 | } |
11568 | ||
c906108c SS |
11569 | /* Convert a DIE tag into its string name. */ |
11570 | ||
11571 | static char * | |
aa1ee363 | 11572 | dwarf_tag_name (unsigned tag) |
c906108c SS |
11573 | { |
11574 | switch (tag) | |
11575 | { | |
11576 | case DW_TAG_padding: | |
11577 | return "DW_TAG_padding"; | |
11578 | case DW_TAG_array_type: | |
11579 | return "DW_TAG_array_type"; | |
11580 | case DW_TAG_class_type: | |
11581 | return "DW_TAG_class_type"; | |
11582 | case DW_TAG_entry_point: | |
11583 | return "DW_TAG_entry_point"; | |
11584 | case DW_TAG_enumeration_type: | |
11585 | return "DW_TAG_enumeration_type"; | |
11586 | case DW_TAG_formal_parameter: | |
11587 | return "DW_TAG_formal_parameter"; | |
11588 | case DW_TAG_imported_declaration: | |
11589 | return "DW_TAG_imported_declaration"; | |
11590 | case DW_TAG_label: | |
11591 | return "DW_TAG_label"; | |
11592 | case DW_TAG_lexical_block: | |
11593 | return "DW_TAG_lexical_block"; | |
11594 | case DW_TAG_member: | |
11595 | return "DW_TAG_member"; | |
11596 | case DW_TAG_pointer_type: | |
11597 | return "DW_TAG_pointer_type"; | |
11598 | case DW_TAG_reference_type: | |
11599 | return "DW_TAG_reference_type"; | |
11600 | case DW_TAG_compile_unit: | |
11601 | return "DW_TAG_compile_unit"; | |
11602 | case DW_TAG_string_type: | |
11603 | return "DW_TAG_string_type"; | |
11604 | case DW_TAG_structure_type: | |
11605 | return "DW_TAG_structure_type"; | |
11606 | case DW_TAG_subroutine_type: | |
11607 | return "DW_TAG_subroutine_type"; | |
11608 | case DW_TAG_typedef: | |
11609 | return "DW_TAG_typedef"; | |
11610 | case DW_TAG_union_type: | |
11611 | return "DW_TAG_union_type"; | |
11612 | case DW_TAG_unspecified_parameters: | |
11613 | return "DW_TAG_unspecified_parameters"; | |
11614 | case DW_TAG_variant: | |
11615 | return "DW_TAG_variant"; | |
11616 | case DW_TAG_common_block: | |
11617 | return "DW_TAG_common_block"; | |
11618 | case DW_TAG_common_inclusion: | |
11619 | return "DW_TAG_common_inclusion"; | |
11620 | case DW_TAG_inheritance: | |
11621 | return "DW_TAG_inheritance"; | |
11622 | case DW_TAG_inlined_subroutine: | |
11623 | return "DW_TAG_inlined_subroutine"; | |
11624 | case DW_TAG_module: | |
11625 | return "DW_TAG_module"; | |
11626 | case DW_TAG_ptr_to_member_type: | |
11627 | return "DW_TAG_ptr_to_member_type"; | |
11628 | case DW_TAG_set_type: | |
11629 | return "DW_TAG_set_type"; | |
11630 | case DW_TAG_subrange_type: | |
11631 | return "DW_TAG_subrange_type"; | |
11632 | case DW_TAG_with_stmt: | |
11633 | return "DW_TAG_with_stmt"; | |
11634 | case DW_TAG_access_declaration: | |
11635 | return "DW_TAG_access_declaration"; | |
11636 | case DW_TAG_base_type: | |
11637 | return "DW_TAG_base_type"; | |
11638 | case DW_TAG_catch_block: | |
11639 | return "DW_TAG_catch_block"; | |
11640 | case DW_TAG_const_type: | |
11641 | return "DW_TAG_const_type"; | |
11642 | case DW_TAG_constant: | |
11643 | return "DW_TAG_constant"; | |
11644 | case DW_TAG_enumerator: | |
11645 | return "DW_TAG_enumerator"; | |
11646 | case DW_TAG_file_type: | |
11647 | return "DW_TAG_file_type"; | |
11648 | case DW_TAG_friend: | |
11649 | return "DW_TAG_friend"; | |
11650 | case DW_TAG_namelist: | |
11651 | return "DW_TAG_namelist"; | |
11652 | case DW_TAG_namelist_item: | |
11653 | return "DW_TAG_namelist_item"; | |
11654 | case DW_TAG_packed_type: | |
11655 | return "DW_TAG_packed_type"; | |
11656 | case DW_TAG_subprogram: | |
11657 | return "DW_TAG_subprogram"; | |
11658 | case DW_TAG_template_type_param: | |
11659 | return "DW_TAG_template_type_param"; | |
11660 | case DW_TAG_template_value_param: | |
11661 | return "DW_TAG_template_value_param"; | |
11662 | case DW_TAG_thrown_type: | |
11663 | return "DW_TAG_thrown_type"; | |
11664 | case DW_TAG_try_block: | |
11665 | return "DW_TAG_try_block"; | |
11666 | case DW_TAG_variant_part: | |
11667 | return "DW_TAG_variant_part"; | |
11668 | case DW_TAG_variable: | |
11669 | return "DW_TAG_variable"; | |
11670 | case DW_TAG_volatile_type: | |
11671 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
11672 | case DW_TAG_dwarf_procedure: |
11673 | return "DW_TAG_dwarf_procedure"; | |
11674 | case DW_TAG_restrict_type: | |
11675 | return "DW_TAG_restrict_type"; | |
11676 | case DW_TAG_interface_type: | |
11677 | return "DW_TAG_interface_type"; | |
11678 | case DW_TAG_namespace: | |
11679 | return "DW_TAG_namespace"; | |
11680 | case DW_TAG_imported_module: | |
11681 | return "DW_TAG_imported_module"; | |
11682 | case DW_TAG_unspecified_type: | |
11683 | return "DW_TAG_unspecified_type"; | |
11684 | case DW_TAG_partial_unit: | |
11685 | return "DW_TAG_partial_unit"; | |
11686 | case DW_TAG_imported_unit: | |
11687 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
11688 | case DW_TAG_condition: |
11689 | return "DW_TAG_condition"; | |
11690 | case DW_TAG_shared_type: | |
11691 | return "DW_TAG_shared_type"; | |
348e048f DE |
11692 | case DW_TAG_type_unit: |
11693 | return "DW_TAG_type_unit"; | |
c906108c SS |
11694 | case DW_TAG_MIPS_loop: |
11695 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
11696 | case DW_TAG_HP_array_descriptor: |
11697 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
11698 | case DW_TAG_format_label: |
11699 | return "DW_TAG_format_label"; | |
11700 | case DW_TAG_function_template: | |
11701 | return "DW_TAG_function_template"; | |
11702 | case DW_TAG_class_template: | |
11703 | return "DW_TAG_class_template"; | |
b7619582 GF |
11704 | case DW_TAG_GNU_BINCL: |
11705 | return "DW_TAG_GNU_BINCL"; | |
11706 | case DW_TAG_GNU_EINCL: | |
11707 | return "DW_TAG_GNU_EINCL"; | |
11708 | case DW_TAG_upc_shared_type: | |
11709 | return "DW_TAG_upc_shared_type"; | |
11710 | case DW_TAG_upc_strict_type: | |
11711 | return "DW_TAG_upc_strict_type"; | |
11712 | case DW_TAG_upc_relaxed_type: | |
11713 | return "DW_TAG_upc_relaxed_type"; | |
11714 | case DW_TAG_PGI_kanji_type: | |
11715 | return "DW_TAG_PGI_kanji_type"; | |
11716 | case DW_TAG_PGI_interface_block: | |
11717 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
11718 | default: |
11719 | return "DW_TAG_<unknown>"; | |
11720 | } | |
11721 | } | |
11722 | ||
11723 | /* Convert a DWARF attribute code into its string name. */ | |
11724 | ||
11725 | static char * | |
aa1ee363 | 11726 | dwarf_attr_name (unsigned attr) |
c906108c SS |
11727 | { |
11728 | switch (attr) | |
11729 | { | |
11730 | case DW_AT_sibling: | |
11731 | return "DW_AT_sibling"; | |
11732 | case DW_AT_location: | |
11733 | return "DW_AT_location"; | |
11734 | case DW_AT_name: | |
11735 | return "DW_AT_name"; | |
11736 | case DW_AT_ordering: | |
11737 | return "DW_AT_ordering"; | |
11738 | case DW_AT_subscr_data: | |
11739 | return "DW_AT_subscr_data"; | |
11740 | case DW_AT_byte_size: | |
11741 | return "DW_AT_byte_size"; | |
11742 | case DW_AT_bit_offset: | |
11743 | return "DW_AT_bit_offset"; | |
11744 | case DW_AT_bit_size: | |
11745 | return "DW_AT_bit_size"; | |
11746 | case DW_AT_element_list: | |
11747 | return "DW_AT_element_list"; | |
11748 | case DW_AT_stmt_list: | |
11749 | return "DW_AT_stmt_list"; | |
11750 | case DW_AT_low_pc: | |
11751 | return "DW_AT_low_pc"; | |
11752 | case DW_AT_high_pc: | |
11753 | return "DW_AT_high_pc"; | |
11754 | case DW_AT_language: | |
11755 | return "DW_AT_language"; | |
11756 | case DW_AT_member: | |
11757 | return "DW_AT_member"; | |
11758 | case DW_AT_discr: | |
11759 | return "DW_AT_discr"; | |
11760 | case DW_AT_discr_value: | |
11761 | return "DW_AT_discr_value"; | |
11762 | case DW_AT_visibility: | |
11763 | return "DW_AT_visibility"; | |
11764 | case DW_AT_import: | |
11765 | return "DW_AT_import"; | |
11766 | case DW_AT_string_length: | |
11767 | return "DW_AT_string_length"; | |
11768 | case DW_AT_common_reference: | |
11769 | return "DW_AT_common_reference"; | |
11770 | case DW_AT_comp_dir: | |
11771 | return "DW_AT_comp_dir"; | |
11772 | case DW_AT_const_value: | |
11773 | return "DW_AT_const_value"; | |
11774 | case DW_AT_containing_type: | |
11775 | return "DW_AT_containing_type"; | |
11776 | case DW_AT_default_value: | |
11777 | return "DW_AT_default_value"; | |
11778 | case DW_AT_inline: | |
11779 | return "DW_AT_inline"; | |
11780 | case DW_AT_is_optional: | |
11781 | return "DW_AT_is_optional"; | |
11782 | case DW_AT_lower_bound: | |
11783 | return "DW_AT_lower_bound"; | |
11784 | case DW_AT_producer: | |
11785 | return "DW_AT_producer"; | |
11786 | case DW_AT_prototyped: | |
11787 | return "DW_AT_prototyped"; | |
11788 | case DW_AT_return_addr: | |
11789 | return "DW_AT_return_addr"; | |
11790 | case DW_AT_start_scope: | |
11791 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
11792 | case DW_AT_bit_stride: |
11793 | return "DW_AT_bit_stride"; | |
c906108c SS |
11794 | case DW_AT_upper_bound: |
11795 | return "DW_AT_upper_bound"; | |
11796 | case DW_AT_abstract_origin: | |
11797 | return "DW_AT_abstract_origin"; | |
11798 | case DW_AT_accessibility: | |
11799 | return "DW_AT_accessibility"; | |
11800 | case DW_AT_address_class: | |
11801 | return "DW_AT_address_class"; | |
11802 | case DW_AT_artificial: | |
11803 | return "DW_AT_artificial"; | |
11804 | case DW_AT_base_types: | |
11805 | return "DW_AT_base_types"; | |
11806 | case DW_AT_calling_convention: | |
11807 | return "DW_AT_calling_convention"; | |
11808 | case DW_AT_count: | |
11809 | return "DW_AT_count"; | |
11810 | case DW_AT_data_member_location: | |
11811 | return "DW_AT_data_member_location"; | |
11812 | case DW_AT_decl_column: | |
11813 | return "DW_AT_decl_column"; | |
11814 | case DW_AT_decl_file: | |
11815 | return "DW_AT_decl_file"; | |
11816 | case DW_AT_decl_line: | |
11817 | return "DW_AT_decl_line"; | |
11818 | case DW_AT_declaration: | |
11819 | return "DW_AT_declaration"; | |
11820 | case DW_AT_discr_list: | |
11821 | return "DW_AT_discr_list"; | |
11822 | case DW_AT_encoding: | |
11823 | return "DW_AT_encoding"; | |
11824 | case DW_AT_external: | |
11825 | return "DW_AT_external"; | |
11826 | case DW_AT_frame_base: | |
11827 | return "DW_AT_frame_base"; | |
11828 | case DW_AT_friend: | |
11829 | return "DW_AT_friend"; | |
11830 | case DW_AT_identifier_case: | |
11831 | return "DW_AT_identifier_case"; | |
11832 | case DW_AT_macro_info: | |
11833 | return "DW_AT_macro_info"; | |
11834 | case DW_AT_namelist_items: | |
11835 | return "DW_AT_namelist_items"; | |
11836 | case DW_AT_priority: | |
11837 | return "DW_AT_priority"; | |
11838 | case DW_AT_segment: | |
11839 | return "DW_AT_segment"; | |
11840 | case DW_AT_specification: | |
11841 | return "DW_AT_specification"; | |
11842 | case DW_AT_static_link: | |
11843 | return "DW_AT_static_link"; | |
11844 | case DW_AT_type: | |
11845 | return "DW_AT_type"; | |
11846 | case DW_AT_use_location: | |
11847 | return "DW_AT_use_location"; | |
11848 | case DW_AT_variable_parameter: | |
11849 | return "DW_AT_variable_parameter"; | |
11850 | case DW_AT_virtuality: | |
11851 | return "DW_AT_virtuality"; | |
11852 | case DW_AT_vtable_elem_location: | |
11853 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 11854 | /* DWARF 3 values. */ |
d9fa45fe DC |
11855 | case DW_AT_allocated: |
11856 | return "DW_AT_allocated"; | |
11857 | case DW_AT_associated: | |
11858 | return "DW_AT_associated"; | |
11859 | case DW_AT_data_location: | |
11860 | return "DW_AT_data_location"; | |
09fa0d7c JK |
11861 | case DW_AT_byte_stride: |
11862 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
11863 | case DW_AT_entry_pc: |
11864 | return "DW_AT_entry_pc"; | |
11865 | case DW_AT_use_UTF8: | |
11866 | return "DW_AT_use_UTF8"; | |
11867 | case DW_AT_extension: | |
11868 | return "DW_AT_extension"; | |
11869 | case DW_AT_ranges: | |
11870 | return "DW_AT_ranges"; | |
11871 | case DW_AT_trampoline: | |
11872 | return "DW_AT_trampoline"; | |
11873 | case DW_AT_call_column: | |
11874 | return "DW_AT_call_column"; | |
11875 | case DW_AT_call_file: | |
11876 | return "DW_AT_call_file"; | |
11877 | case DW_AT_call_line: | |
11878 | return "DW_AT_call_line"; | |
b7619582 GF |
11879 | case DW_AT_description: |
11880 | return "DW_AT_description"; | |
11881 | case DW_AT_binary_scale: | |
11882 | return "DW_AT_binary_scale"; | |
11883 | case DW_AT_decimal_scale: | |
11884 | return "DW_AT_decimal_scale"; | |
11885 | case DW_AT_small: | |
11886 | return "DW_AT_small"; | |
11887 | case DW_AT_decimal_sign: | |
11888 | return "DW_AT_decimal_sign"; | |
11889 | case DW_AT_digit_count: | |
11890 | return "DW_AT_digit_count"; | |
11891 | case DW_AT_picture_string: | |
11892 | return "DW_AT_picture_string"; | |
11893 | case DW_AT_mutable: | |
11894 | return "DW_AT_mutable"; | |
11895 | case DW_AT_threads_scaled: | |
11896 | return "DW_AT_threads_scaled"; | |
11897 | case DW_AT_explicit: | |
11898 | return "DW_AT_explicit"; | |
11899 | case DW_AT_object_pointer: | |
11900 | return "DW_AT_object_pointer"; | |
11901 | case DW_AT_endianity: | |
11902 | return "DW_AT_endianity"; | |
11903 | case DW_AT_elemental: | |
11904 | return "DW_AT_elemental"; | |
11905 | case DW_AT_pure: | |
11906 | return "DW_AT_pure"; | |
11907 | case DW_AT_recursive: | |
11908 | return "DW_AT_recursive"; | |
348e048f DE |
11909 | /* DWARF 4 values. */ |
11910 | case DW_AT_signature: | |
11911 | return "DW_AT_signature"; | |
31ef98ae TT |
11912 | case DW_AT_linkage_name: |
11913 | return "DW_AT_linkage_name"; | |
b7619582 | 11914 | /* SGI/MIPS extensions. */ |
c764a876 | 11915 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
11916 | case DW_AT_MIPS_fde: |
11917 | return "DW_AT_MIPS_fde"; | |
c764a876 | 11918 | #endif |
c906108c SS |
11919 | case DW_AT_MIPS_loop_begin: |
11920 | return "DW_AT_MIPS_loop_begin"; | |
11921 | case DW_AT_MIPS_tail_loop_begin: | |
11922 | return "DW_AT_MIPS_tail_loop_begin"; | |
11923 | case DW_AT_MIPS_epilog_begin: | |
11924 | return "DW_AT_MIPS_epilog_begin"; | |
11925 | case DW_AT_MIPS_loop_unroll_factor: | |
11926 | return "DW_AT_MIPS_loop_unroll_factor"; | |
11927 | case DW_AT_MIPS_software_pipeline_depth: | |
11928 | return "DW_AT_MIPS_software_pipeline_depth"; | |
11929 | case DW_AT_MIPS_linkage_name: | |
11930 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
11931 | case DW_AT_MIPS_stride: |
11932 | return "DW_AT_MIPS_stride"; | |
11933 | case DW_AT_MIPS_abstract_name: | |
11934 | return "DW_AT_MIPS_abstract_name"; | |
11935 | case DW_AT_MIPS_clone_origin: | |
11936 | return "DW_AT_MIPS_clone_origin"; | |
11937 | case DW_AT_MIPS_has_inlines: | |
11938 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 11939 | /* HP extensions. */ |
c764a876 | 11940 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
11941 | case DW_AT_HP_block_index: |
11942 | return "DW_AT_HP_block_index"; | |
c764a876 | 11943 | #endif |
b7619582 GF |
11944 | case DW_AT_HP_unmodifiable: |
11945 | return "DW_AT_HP_unmodifiable"; | |
11946 | case DW_AT_HP_actuals_stmt_list: | |
11947 | return "DW_AT_HP_actuals_stmt_list"; | |
11948 | case DW_AT_HP_proc_per_section: | |
11949 | return "DW_AT_HP_proc_per_section"; | |
11950 | case DW_AT_HP_raw_data_ptr: | |
11951 | return "DW_AT_HP_raw_data_ptr"; | |
11952 | case DW_AT_HP_pass_by_reference: | |
11953 | return "DW_AT_HP_pass_by_reference"; | |
11954 | case DW_AT_HP_opt_level: | |
11955 | return "DW_AT_HP_opt_level"; | |
11956 | case DW_AT_HP_prof_version_id: | |
11957 | return "DW_AT_HP_prof_version_id"; | |
11958 | case DW_AT_HP_opt_flags: | |
11959 | return "DW_AT_HP_opt_flags"; | |
11960 | case DW_AT_HP_cold_region_low_pc: | |
11961 | return "DW_AT_HP_cold_region_low_pc"; | |
11962 | case DW_AT_HP_cold_region_high_pc: | |
11963 | return "DW_AT_HP_cold_region_high_pc"; | |
11964 | case DW_AT_HP_all_variables_modifiable: | |
11965 | return "DW_AT_HP_all_variables_modifiable"; | |
11966 | case DW_AT_HP_linkage_name: | |
11967 | return "DW_AT_HP_linkage_name"; | |
11968 | case DW_AT_HP_prof_flags: | |
11969 | return "DW_AT_HP_prof_flags"; | |
11970 | /* GNU extensions. */ | |
c906108c SS |
11971 | case DW_AT_sf_names: |
11972 | return "DW_AT_sf_names"; | |
11973 | case DW_AT_src_info: | |
11974 | return "DW_AT_src_info"; | |
11975 | case DW_AT_mac_info: | |
11976 | return "DW_AT_mac_info"; | |
11977 | case DW_AT_src_coords: | |
11978 | return "DW_AT_src_coords"; | |
11979 | case DW_AT_body_begin: | |
11980 | return "DW_AT_body_begin"; | |
11981 | case DW_AT_body_end: | |
11982 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
11983 | case DW_AT_GNU_vector: |
11984 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
11985 | case DW_AT_GNU_odr_signature: |
11986 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
11987 | /* VMS extensions. */ |
11988 | case DW_AT_VMS_rtnbeg_pd_address: | |
11989 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
11990 | /* UPC extension. */ | |
11991 | case DW_AT_upc_threads_scaled: | |
11992 | return "DW_AT_upc_threads_scaled"; | |
11993 | /* PGI (STMicroelectronics) extensions. */ | |
11994 | case DW_AT_PGI_lbase: | |
11995 | return "DW_AT_PGI_lbase"; | |
11996 | case DW_AT_PGI_soffset: | |
11997 | return "DW_AT_PGI_soffset"; | |
11998 | case DW_AT_PGI_lstride: | |
11999 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
12000 | default: |
12001 | return "DW_AT_<unknown>"; | |
12002 | } | |
12003 | } | |
12004 | ||
12005 | /* Convert a DWARF value form code into its string name. */ | |
12006 | ||
12007 | static char * | |
aa1ee363 | 12008 | dwarf_form_name (unsigned form) |
c906108c SS |
12009 | { |
12010 | switch (form) | |
12011 | { | |
12012 | case DW_FORM_addr: | |
12013 | return "DW_FORM_addr"; | |
12014 | case DW_FORM_block2: | |
12015 | return "DW_FORM_block2"; | |
12016 | case DW_FORM_block4: | |
12017 | return "DW_FORM_block4"; | |
12018 | case DW_FORM_data2: | |
12019 | return "DW_FORM_data2"; | |
12020 | case DW_FORM_data4: | |
12021 | return "DW_FORM_data4"; | |
12022 | case DW_FORM_data8: | |
12023 | return "DW_FORM_data8"; | |
12024 | case DW_FORM_string: | |
12025 | return "DW_FORM_string"; | |
12026 | case DW_FORM_block: | |
12027 | return "DW_FORM_block"; | |
12028 | case DW_FORM_block1: | |
12029 | return "DW_FORM_block1"; | |
12030 | case DW_FORM_data1: | |
12031 | return "DW_FORM_data1"; | |
12032 | case DW_FORM_flag: | |
12033 | return "DW_FORM_flag"; | |
12034 | case DW_FORM_sdata: | |
12035 | return "DW_FORM_sdata"; | |
12036 | case DW_FORM_strp: | |
12037 | return "DW_FORM_strp"; | |
12038 | case DW_FORM_udata: | |
12039 | return "DW_FORM_udata"; | |
12040 | case DW_FORM_ref_addr: | |
12041 | return "DW_FORM_ref_addr"; | |
12042 | case DW_FORM_ref1: | |
12043 | return "DW_FORM_ref1"; | |
12044 | case DW_FORM_ref2: | |
12045 | return "DW_FORM_ref2"; | |
12046 | case DW_FORM_ref4: | |
12047 | return "DW_FORM_ref4"; | |
12048 | case DW_FORM_ref8: | |
12049 | return "DW_FORM_ref8"; | |
12050 | case DW_FORM_ref_udata: | |
12051 | return "DW_FORM_ref_udata"; | |
12052 | case DW_FORM_indirect: | |
12053 | return "DW_FORM_indirect"; | |
348e048f DE |
12054 | case DW_FORM_sec_offset: |
12055 | return "DW_FORM_sec_offset"; | |
12056 | case DW_FORM_exprloc: | |
12057 | return "DW_FORM_exprloc"; | |
12058 | case DW_FORM_flag_present: | |
12059 | return "DW_FORM_flag_present"; | |
12060 | case DW_FORM_sig8: | |
12061 | return "DW_FORM_sig8"; | |
c906108c SS |
12062 | default: |
12063 | return "DW_FORM_<unknown>"; | |
12064 | } | |
12065 | } | |
12066 | ||
12067 | /* Convert a DWARF stack opcode into its string name. */ | |
12068 | ||
9eae7c52 TT |
12069 | const char * |
12070 | dwarf_stack_op_name (unsigned op, int def) | |
c906108c SS |
12071 | { |
12072 | switch (op) | |
12073 | { | |
12074 | case DW_OP_addr: | |
12075 | return "DW_OP_addr"; | |
12076 | case DW_OP_deref: | |
12077 | return "DW_OP_deref"; | |
12078 | case DW_OP_const1u: | |
12079 | return "DW_OP_const1u"; | |
12080 | case DW_OP_const1s: | |
12081 | return "DW_OP_const1s"; | |
12082 | case DW_OP_const2u: | |
12083 | return "DW_OP_const2u"; | |
12084 | case DW_OP_const2s: | |
12085 | return "DW_OP_const2s"; | |
12086 | case DW_OP_const4u: | |
12087 | return "DW_OP_const4u"; | |
12088 | case DW_OP_const4s: | |
12089 | return "DW_OP_const4s"; | |
12090 | case DW_OP_const8u: | |
12091 | return "DW_OP_const8u"; | |
12092 | case DW_OP_const8s: | |
12093 | return "DW_OP_const8s"; | |
12094 | case DW_OP_constu: | |
12095 | return "DW_OP_constu"; | |
12096 | case DW_OP_consts: | |
12097 | return "DW_OP_consts"; | |
12098 | case DW_OP_dup: | |
12099 | return "DW_OP_dup"; | |
12100 | case DW_OP_drop: | |
12101 | return "DW_OP_drop"; | |
12102 | case DW_OP_over: | |
12103 | return "DW_OP_over"; | |
12104 | case DW_OP_pick: | |
12105 | return "DW_OP_pick"; | |
12106 | case DW_OP_swap: | |
12107 | return "DW_OP_swap"; | |
12108 | case DW_OP_rot: | |
12109 | return "DW_OP_rot"; | |
12110 | case DW_OP_xderef: | |
12111 | return "DW_OP_xderef"; | |
12112 | case DW_OP_abs: | |
12113 | return "DW_OP_abs"; | |
12114 | case DW_OP_and: | |
12115 | return "DW_OP_and"; | |
12116 | case DW_OP_div: | |
12117 | return "DW_OP_div"; | |
12118 | case DW_OP_minus: | |
12119 | return "DW_OP_minus"; | |
12120 | case DW_OP_mod: | |
12121 | return "DW_OP_mod"; | |
12122 | case DW_OP_mul: | |
12123 | return "DW_OP_mul"; | |
12124 | case DW_OP_neg: | |
12125 | return "DW_OP_neg"; | |
12126 | case DW_OP_not: | |
12127 | return "DW_OP_not"; | |
12128 | case DW_OP_or: | |
12129 | return "DW_OP_or"; | |
12130 | case DW_OP_plus: | |
12131 | return "DW_OP_plus"; | |
12132 | case DW_OP_plus_uconst: | |
12133 | return "DW_OP_plus_uconst"; | |
12134 | case DW_OP_shl: | |
12135 | return "DW_OP_shl"; | |
12136 | case DW_OP_shr: | |
12137 | return "DW_OP_shr"; | |
12138 | case DW_OP_shra: | |
12139 | return "DW_OP_shra"; | |
12140 | case DW_OP_xor: | |
12141 | return "DW_OP_xor"; | |
12142 | case DW_OP_bra: | |
12143 | return "DW_OP_bra"; | |
12144 | case DW_OP_eq: | |
12145 | return "DW_OP_eq"; | |
12146 | case DW_OP_ge: | |
12147 | return "DW_OP_ge"; | |
12148 | case DW_OP_gt: | |
12149 | return "DW_OP_gt"; | |
12150 | case DW_OP_le: | |
12151 | return "DW_OP_le"; | |
12152 | case DW_OP_lt: | |
12153 | return "DW_OP_lt"; | |
12154 | case DW_OP_ne: | |
12155 | return "DW_OP_ne"; | |
12156 | case DW_OP_skip: | |
12157 | return "DW_OP_skip"; | |
12158 | case DW_OP_lit0: | |
12159 | return "DW_OP_lit0"; | |
12160 | case DW_OP_lit1: | |
12161 | return "DW_OP_lit1"; | |
12162 | case DW_OP_lit2: | |
12163 | return "DW_OP_lit2"; | |
12164 | case DW_OP_lit3: | |
12165 | return "DW_OP_lit3"; | |
12166 | case DW_OP_lit4: | |
12167 | return "DW_OP_lit4"; | |
12168 | case DW_OP_lit5: | |
12169 | return "DW_OP_lit5"; | |
12170 | case DW_OP_lit6: | |
12171 | return "DW_OP_lit6"; | |
12172 | case DW_OP_lit7: | |
12173 | return "DW_OP_lit7"; | |
12174 | case DW_OP_lit8: | |
12175 | return "DW_OP_lit8"; | |
12176 | case DW_OP_lit9: | |
12177 | return "DW_OP_lit9"; | |
12178 | case DW_OP_lit10: | |
12179 | return "DW_OP_lit10"; | |
12180 | case DW_OP_lit11: | |
12181 | return "DW_OP_lit11"; | |
12182 | case DW_OP_lit12: | |
12183 | return "DW_OP_lit12"; | |
12184 | case DW_OP_lit13: | |
12185 | return "DW_OP_lit13"; | |
12186 | case DW_OP_lit14: | |
12187 | return "DW_OP_lit14"; | |
12188 | case DW_OP_lit15: | |
12189 | return "DW_OP_lit15"; | |
12190 | case DW_OP_lit16: | |
12191 | return "DW_OP_lit16"; | |
12192 | case DW_OP_lit17: | |
12193 | return "DW_OP_lit17"; | |
12194 | case DW_OP_lit18: | |
12195 | return "DW_OP_lit18"; | |
12196 | case DW_OP_lit19: | |
12197 | return "DW_OP_lit19"; | |
12198 | case DW_OP_lit20: | |
12199 | return "DW_OP_lit20"; | |
12200 | case DW_OP_lit21: | |
12201 | return "DW_OP_lit21"; | |
12202 | case DW_OP_lit22: | |
12203 | return "DW_OP_lit22"; | |
12204 | case DW_OP_lit23: | |
12205 | return "DW_OP_lit23"; | |
12206 | case DW_OP_lit24: | |
12207 | return "DW_OP_lit24"; | |
12208 | case DW_OP_lit25: | |
12209 | return "DW_OP_lit25"; | |
12210 | case DW_OP_lit26: | |
12211 | return "DW_OP_lit26"; | |
12212 | case DW_OP_lit27: | |
12213 | return "DW_OP_lit27"; | |
12214 | case DW_OP_lit28: | |
12215 | return "DW_OP_lit28"; | |
12216 | case DW_OP_lit29: | |
12217 | return "DW_OP_lit29"; | |
12218 | case DW_OP_lit30: | |
12219 | return "DW_OP_lit30"; | |
12220 | case DW_OP_lit31: | |
12221 | return "DW_OP_lit31"; | |
12222 | case DW_OP_reg0: | |
12223 | return "DW_OP_reg0"; | |
12224 | case DW_OP_reg1: | |
12225 | return "DW_OP_reg1"; | |
12226 | case DW_OP_reg2: | |
12227 | return "DW_OP_reg2"; | |
12228 | case DW_OP_reg3: | |
12229 | return "DW_OP_reg3"; | |
12230 | case DW_OP_reg4: | |
12231 | return "DW_OP_reg4"; | |
12232 | case DW_OP_reg5: | |
12233 | return "DW_OP_reg5"; | |
12234 | case DW_OP_reg6: | |
12235 | return "DW_OP_reg6"; | |
12236 | case DW_OP_reg7: | |
12237 | return "DW_OP_reg7"; | |
12238 | case DW_OP_reg8: | |
12239 | return "DW_OP_reg8"; | |
12240 | case DW_OP_reg9: | |
12241 | return "DW_OP_reg9"; | |
12242 | case DW_OP_reg10: | |
12243 | return "DW_OP_reg10"; | |
12244 | case DW_OP_reg11: | |
12245 | return "DW_OP_reg11"; | |
12246 | case DW_OP_reg12: | |
12247 | return "DW_OP_reg12"; | |
12248 | case DW_OP_reg13: | |
12249 | return "DW_OP_reg13"; | |
12250 | case DW_OP_reg14: | |
12251 | return "DW_OP_reg14"; | |
12252 | case DW_OP_reg15: | |
12253 | return "DW_OP_reg15"; | |
12254 | case DW_OP_reg16: | |
12255 | return "DW_OP_reg16"; | |
12256 | case DW_OP_reg17: | |
12257 | return "DW_OP_reg17"; | |
12258 | case DW_OP_reg18: | |
12259 | return "DW_OP_reg18"; | |
12260 | case DW_OP_reg19: | |
12261 | return "DW_OP_reg19"; | |
12262 | case DW_OP_reg20: | |
12263 | return "DW_OP_reg20"; | |
12264 | case DW_OP_reg21: | |
12265 | return "DW_OP_reg21"; | |
12266 | case DW_OP_reg22: | |
12267 | return "DW_OP_reg22"; | |
12268 | case DW_OP_reg23: | |
12269 | return "DW_OP_reg23"; | |
12270 | case DW_OP_reg24: | |
12271 | return "DW_OP_reg24"; | |
12272 | case DW_OP_reg25: | |
12273 | return "DW_OP_reg25"; | |
12274 | case DW_OP_reg26: | |
12275 | return "DW_OP_reg26"; | |
12276 | case DW_OP_reg27: | |
12277 | return "DW_OP_reg27"; | |
12278 | case DW_OP_reg28: | |
12279 | return "DW_OP_reg28"; | |
12280 | case DW_OP_reg29: | |
12281 | return "DW_OP_reg29"; | |
12282 | case DW_OP_reg30: | |
12283 | return "DW_OP_reg30"; | |
12284 | case DW_OP_reg31: | |
12285 | return "DW_OP_reg31"; | |
12286 | case DW_OP_breg0: | |
12287 | return "DW_OP_breg0"; | |
12288 | case DW_OP_breg1: | |
12289 | return "DW_OP_breg1"; | |
12290 | case DW_OP_breg2: | |
12291 | return "DW_OP_breg2"; | |
12292 | case DW_OP_breg3: | |
12293 | return "DW_OP_breg3"; | |
12294 | case DW_OP_breg4: | |
12295 | return "DW_OP_breg4"; | |
12296 | case DW_OP_breg5: | |
12297 | return "DW_OP_breg5"; | |
12298 | case DW_OP_breg6: | |
12299 | return "DW_OP_breg6"; | |
12300 | case DW_OP_breg7: | |
12301 | return "DW_OP_breg7"; | |
12302 | case DW_OP_breg8: | |
12303 | return "DW_OP_breg8"; | |
12304 | case DW_OP_breg9: | |
12305 | return "DW_OP_breg9"; | |
12306 | case DW_OP_breg10: | |
12307 | return "DW_OP_breg10"; | |
12308 | case DW_OP_breg11: | |
12309 | return "DW_OP_breg11"; | |
12310 | case DW_OP_breg12: | |
12311 | return "DW_OP_breg12"; | |
12312 | case DW_OP_breg13: | |
12313 | return "DW_OP_breg13"; | |
12314 | case DW_OP_breg14: | |
12315 | return "DW_OP_breg14"; | |
12316 | case DW_OP_breg15: | |
12317 | return "DW_OP_breg15"; | |
12318 | case DW_OP_breg16: | |
12319 | return "DW_OP_breg16"; | |
12320 | case DW_OP_breg17: | |
12321 | return "DW_OP_breg17"; | |
12322 | case DW_OP_breg18: | |
12323 | return "DW_OP_breg18"; | |
12324 | case DW_OP_breg19: | |
12325 | return "DW_OP_breg19"; | |
12326 | case DW_OP_breg20: | |
12327 | return "DW_OP_breg20"; | |
12328 | case DW_OP_breg21: | |
12329 | return "DW_OP_breg21"; | |
12330 | case DW_OP_breg22: | |
12331 | return "DW_OP_breg22"; | |
12332 | case DW_OP_breg23: | |
12333 | return "DW_OP_breg23"; | |
12334 | case DW_OP_breg24: | |
12335 | return "DW_OP_breg24"; | |
12336 | case DW_OP_breg25: | |
12337 | return "DW_OP_breg25"; | |
12338 | case DW_OP_breg26: | |
12339 | return "DW_OP_breg26"; | |
12340 | case DW_OP_breg27: | |
12341 | return "DW_OP_breg27"; | |
12342 | case DW_OP_breg28: | |
12343 | return "DW_OP_breg28"; | |
12344 | case DW_OP_breg29: | |
12345 | return "DW_OP_breg29"; | |
12346 | case DW_OP_breg30: | |
12347 | return "DW_OP_breg30"; | |
12348 | case DW_OP_breg31: | |
12349 | return "DW_OP_breg31"; | |
12350 | case DW_OP_regx: | |
12351 | return "DW_OP_regx"; | |
12352 | case DW_OP_fbreg: | |
12353 | return "DW_OP_fbreg"; | |
12354 | case DW_OP_bregx: | |
12355 | return "DW_OP_bregx"; | |
12356 | case DW_OP_piece: | |
12357 | return "DW_OP_piece"; | |
12358 | case DW_OP_deref_size: | |
12359 | return "DW_OP_deref_size"; | |
12360 | case DW_OP_xderef_size: | |
12361 | return "DW_OP_xderef_size"; | |
12362 | case DW_OP_nop: | |
12363 | return "DW_OP_nop"; | |
b7619582 | 12364 | /* DWARF 3 extensions. */ |
ed348acc EZ |
12365 | case DW_OP_push_object_address: |
12366 | return "DW_OP_push_object_address"; | |
12367 | case DW_OP_call2: | |
12368 | return "DW_OP_call2"; | |
12369 | case DW_OP_call4: | |
12370 | return "DW_OP_call4"; | |
12371 | case DW_OP_call_ref: | |
12372 | return "DW_OP_call_ref"; | |
b7619582 GF |
12373 | case DW_OP_form_tls_address: |
12374 | return "DW_OP_form_tls_address"; | |
12375 | case DW_OP_call_frame_cfa: | |
12376 | return "DW_OP_call_frame_cfa"; | |
12377 | case DW_OP_bit_piece: | |
12378 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
12379 | /* DWARF 4 extensions. */ |
12380 | case DW_OP_implicit_value: | |
12381 | return "DW_OP_implicit_value"; | |
12382 | case DW_OP_stack_value: | |
12383 | return "DW_OP_stack_value"; | |
12384 | /* GNU extensions. */ | |
ed348acc EZ |
12385 | case DW_OP_GNU_push_tls_address: |
12386 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
12387 | case DW_OP_GNU_uninit: |
12388 | return "DW_OP_GNU_uninit"; | |
c906108c | 12389 | default: |
9eae7c52 | 12390 | return def ? "OP_<unknown>" : NULL; |
c906108c SS |
12391 | } |
12392 | } | |
12393 | ||
12394 | static char * | |
fba45db2 | 12395 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
12396 | { |
12397 | if (mybool) | |
12398 | return "TRUE"; | |
12399 | else | |
12400 | return "FALSE"; | |
12401 | } | |
12402 | ||
12403 | /* Convert a DWARF type code into its string name. */ | |
12404 | ||
12405 | static char * | |
aa1ee363 | 12406 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
12407 | { |
12408 | switch (enc) | |
12409 | { | |
b7619582 GF |
12410 | case DW_ATE_void: |
12411 | return "DW_ATE_void"; | |
c906108c SS |
12412 | case DW_ATE_address: |
12413 | return "DW_ATE_address"; | |
12414 | case DW_ATE_boolean: | |
12415 | return "DW_ATE_boolean"; | |
12416 | case DW_ATE_complex_float: | |
12417 | return "DW_ATE_complex_float"; | |
12418 | case DW_ATE_float: | |
12419 | return "DW_ATE_float"; | |
12420 | case DW_ATE_signed: | |
12421 | return "DW_ATE_signed"; | |
12422 | case DW_ATE_signed_char: | |
12423 | return "DW_ATE_signed_char"; | |
12424 | case DW_ATE_unsigned: | |
12425 | return "DW_ATE_unsigned"; | |
12426 | case DW_ATE_unsigned_char: | |
12427 | return "DW_ATE_unsigned_char"; | |
b7619582 | 12428 | /* DWARF 3. */ |
d9fa45fe DC |
12429 | case DW_ATE_imaginary_float: |
12430 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
12431 | case DW_ATE_packed_decimal: |
12432 | return "DW_ATE_packed_decimal"; | |
12433 | case DW_ATE_numeric_string: | |
12434 | return "DW_ATE_numeric_string"; | |
12435 | case DW_ATE_edited: | |
12436 | return "DW_ATE_edited"; | |
12437 | case DW_ATE_signed_fixed: | |
12438 | return "DW_ATE_signed_fixed"; | |
12439 | case DW_ATE_unsigned_fixed: | |
12440 | return "DW_ATE_unsigned_fixed"; | |
12441 | case DW_ATE_decimal_float: | |
12442 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
12443 | /* DWARF 4. */ |
12444 | case DW_ATE_UTF: | |
12445 | return "DW_ATE_UTF"; | |
b7619582 GF |
12446 | /* HP extensions. */ |
12447 | case DW_ATE_HP_float80: | |
12448 | return "DW_ATE_HP_float80"; | |
12449 | case DW_ATE_HP_complex_float80: | |
12450 | return "DW_ATE_HP_complex_float80"; | |
12451 | case DW_ATE_HP_float128: | |
12452 | return "DW_ATE_HP_float128"; | |
12453 | case DW_ATE_HP_complex_float128: | |
12454 | return "DW_ATE_HP_complex_float128"; | |
12455 | case DW_ATE_HP_floathpintel: | |
12456 | return "DW_ATE_HP_floathpintel"; | |
12457 | case DW_ATE_HP_imaginary_float80: | |
12458 | return "DW_ATE_HP_imaginary_float80"; | |
12459 | case DW_ATE_HP_imaginary_float128: | |
12460 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
12461 | default: |
12462 | return "DW_ATE_<unknown>"; | |
12463 | } | |
12464 | } | |
12465 | ||
12466 | /* Convert a DWARF call frame info operation to its string name. */ | |
12467 | ||
12468 | #if 0 | |
12469 | static char * | |
aa1ee363 | 12470 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
12471 | { |
12472 | switch (cfi_opc) | |
12473 | { | |
12474 | case DW_CFA_advance_loc: | |
12475 | return "DW_CFA_advance_loc"; | |
12476 | case DW_CFA_offset: | |
12477 | return "DW_CFA_offset"; | |
12478 | case DW_CFA_restore: | |
12479 | return "DW_CFA_restore"; | |
12480 | case DW_CFA_nop: | |
12481 | return "DW_CFA_nop"; | |
12482 | case DW_CFA_set_loc: | |
12483 | return "DW_CFA_set_loc"; | |
12484 | case DW_CFA_advance_loc1: | |
12485 | return "DW_CFA_advance_loc1"; | |
12486 | case DW_CFA_advance_loc2: | |
12487 | return "DW_CFA_advance_loc2"; | |
12488 | case DW_CFA_advance_loc4: | |
12489 | return "DW_CFA_advance_loc4"; | |
12490 | case DW_CFA_offset_extended: | |
12491 | return "DW_CFA_offset_extended"; | |
12492 | case DW_CFA_restore_extended: | |
12493 | return "DW_CFA_restore_extended"; | |
12494 | case DW_CFA_undefined: | |
12495 | return "DW_CFA_undefined"; | |
12496 | case DW_CFA_same_value: | |
12497 | return "DW_CFA_same_value"; | |
12498 | case DW_CFA_register: | |
12499 | return "DW_CFA_register"; | |
12500 | case DW_CFA_remember_state: | |
12501 | return "DW_CFA_remember_state"; | |
12502 | case DW_CFA_restore_state: | |
12503 | return "DW_CFA_restore_state"; | |
12504 | case DW_CFA_def_cfa: | |
12505 | return "DW_CFA_def_cfa"; | |
12506 | case DW_CFA_def_cfa_register: | |
12507 | return "DW_CFA_def_cfa_register"; | |
12508 | case DW_CFA_def_cfa_offset: | |
12509 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 12510 | /* DWARF 3. */ |
985cb1a3 JM |
12511 | case DW_CFA_def_cfa_expression: |
12512 | return "DW_CFA_def_cfa_expression"; | |
12513 | case DW_CFA_expression: | |
12514 | return "DW_CFA_expression"; | |
12515 | case DW_CFA_offset_extended_sf: | |
12516 | return "DW_CFA_offset_extended_sf"; | |
12517 | case DW_CFA_def_cfa_sf: | |
12518 | return "DW_CFA_def_cfa_sf"; | |
12519 | case DW_CFA_def_cfa_offset_sf: | |
12520 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
12521 | case DW_CFA_val_offset: |
12522 | return "DW_CFA_val_offset"; | |
12523 | case DW_CFA_val_offset_sf: | |
12524 | return "DW_CFA_val_offset_sf"; | |
12525 | case DW_CFA_val_expression: | |
12526 | return "DW_CFA_val_expression"; | |
12527 | /* SGI/MIPS specific. */ | |
c906108c SS |
12528 | case DW_CFA_MIPS_advance_loc8: |
12529 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 12530 | /* GNU extensions. */ |
985cb1a3 JM |
12531 | case DW_CFA_GNU_window_save: |
12532 | return "DW_CFA_GNU_window_save"; | |
12533 | case DW_CFA_GNU_args_size: | |
12534 | return "DW_CFA_GNU_args_size"; | |
12535 | case DW_CFA_GNU_negative_offset_extended: | |
12536 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
12537 | default: |
12538 | return "DW_CFA_<unknown>"; | |
12539 | } | |
12540 | } | |
12541 | #endif | |
12542 | ||
f9aca02d | 12543 | static void |
d97bc12b | 12544 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
12545 | { |
12546 | unsigned int i; | |
12547 | ||
d97bc12b DE |
12548 | print_spaces (indent, f); |
12549 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 12550 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
12551 | |
12552 | if (die->parent != NULL) | |
12553 | { | |
12554 | print_spaces (indent, f); | |
12555 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
12556 | die->parent->offset); | |
12557 | } | |
12558 | ||
12559 | print_spaces (indent, f); | |
12560 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 12561 | dwarf_bool_name (die->child != NULL)); |
c906108c | 12562 | |
d97bc12b DE |
12563 | print_spaces (indent, f); |
12564 | fprintf_unfiltered (f, " attributes:\n"); | |
12565 | ||
c906108c SS |
12566 | for (i = 0; i < die->num_attrs; ++i) |
12567 | { | |
d97bc12b DE |
12568 | print_spaces (indent, f); |
12569 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
12570 | dwarf_attr_name (die->attrs[i].name), |
12571 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 12572 | |
c906108c SS |
12573 | switch (die->attrs[i].form) |
12574 | { | |
12575 | case DW_FORM_ref_addr: | |
12576 | case DW_FORM_addr: | |
d97bc12b | 12577 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 12578 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
12579 | break; |
12580 | case DW_FORM_block2: | |
12581 | case DW_FORM_block4: | |
12582 | case DW_FORM_block: | |
12583 | case DW_FORM_block1: | |
d97bc12b | 12584 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 12585 | break; |
2dc7f7b3 TT |
12586 | case DW_FORM_exprloc: |
12587 | fprintf_unfiltered (f, "expression: size %u", | |
12588 | DW_BLOCK (&die->attrs[i])->size); | |
12589 | break; | |
10b3939b DJ |
12590 | case DW_FORM_ref1: |
12591 | case DW_FORM_ref2: | |
12592 | case DW_FORM_ref4: | |
d97bc12b | 12593 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
12594 | (long) (DW_ADDR (&die->attrs[i]))); |
12595 | break; | |
c906108c SS |
12596 | case DW_FORM_data1: |
12597 | case DW_FORM_data2: | |
12598 | case DW_FORM_data4: | |
ce5d95e1 | 12599 | case DW_FORM_data8: |
c906108c SS |
12600 | case DW_FORM_udata: |
12601 | case DW_FORM_sdata: | |
43bbcdc2 PH |
12602 | fprintf_unfiltered (f, "constant: %s", |
12603 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 12604 | break; |
2dc7f7b3 TT |
12605 | case DW_FORM_sec_offset: |
12606 | fprintf_unfiltered (f, "section offset: %s", | |
12607 | pulongest (DW_UNSND (&die->attrs[i]))); | |
12608 | break; | |
348e048f DE |
12609 | case DW_FORM_sig8: |
12610 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
12611 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
12612 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
12613 | else | |
12614 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
12615 | break; | |
c906108c | 12616 | case DW_FORM_string: |
4bdf3d34 | 12617 | case DW_FORM_strp: |
8285870a | 12618 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 12619 | DW_STRING (&die->attrs[i]) |
8285870a JK |
12620 | ? DW_STRING (&die->attrs[i]) : "", |
12621 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
12622 | break; |
12623 | case DW_FORM_flag: | |
12624 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 12625 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 12626 | else |
d97bc12b | 12627 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 12628 | break; |
2dc7f7b3 TT |
12629 | case DW_FORM_flag_present: |
12630 | fprintf_unfiltered (f, "flag: TRUE"); | |
12631 | break; | |
a8329558 KW |
12632 | case DW_FORM_indirect: |
12633 | /* the reader will have reduced the indirect form to | |
12634 | the "base form" so this form should not occur */ | |
d97bc12b | 12635 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 12636 | break; |
c906108c | 12637 | default: |
d97bc12b | 12638 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 12639 | die->attrs[i].form); |
d97bc12b | 12640 | break; |
c906108c | 12641 | } |
d97bc12b | 12642 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
12643 | } |
12644 | } | |
12645 | ||
f9aca02d | 12646 | static void |
d97bc12b | 12647 | dump_die_for_error (struct die_info *die) |
c906108c | 12648 | { |
d97bc12b DE |
12649 | dump_die_shallow (gdb_stderr, 0, die); |
12650 | } | |
12651 | ||
12652 | static void | |
12653 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
12654 | { | |
12655 | int indent = level * 4; | |
12656 | ||
12657 | gdb_assert (die != NULL); | |
12658 | ||
12659 | if (level >= max_level) | |
12660 | return; | |
12661 | ||
12662 | dump_die_shallow (f, indent, die); | |
12663 | ||
12664 | if (die->child != NULL) | |
c906108c | 12665 | { |
d97bc12b DE |
12666 | print_spaces (indent, f); |
12667 | fprintf_unfiltered (f, " Children:"); | |
12668 | if (level + 1 < max_level) | |
12669 | { | |
12670 | fprintf_unfiltered (f, "\n"); | |
12671 | dump_die_1 (f, level + 1, max_level, die->child); | |
12672 | } | |
12673 | else | |
12674 | { | |
12675 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
12676 | } | |
12677 | } | |
12678 | ||
12679 | if (die->sibling != NULL && level > 0) | |
12680 | { | |
12681 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
12682 | } |
12683 | } | |
12684 | ||
d97bc12b DE |
12685 | /* This is called from the pdie macro in gdbinit.in. |
12686 | It's not static so gcc will keep a copy callable from gdb. */ | |
12687 | ||
12688 | void | |
12689 | dump_die (struct die_info *die, int max_level) | |
12690 | { | |
12691 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
12692 | } | |
12693 | ||
f9aca02d | 12694 | static void |
51545339 | 12695 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12696 | { |
51545339 | 12697 | void **slot; |
c906108c | 12698 | |
51545339 DJ |
12699 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
12700 | ||
12701 | *slot = die; | |
c906108c SS |
12702 | } |
12703 | ||
93311388 DE |
12704 | static int |
12705 | is_ref_attr (struct attribute *attr) | |
c906108c | 12706 | { |
c906108c SS |
12707 | switch (attr->form) |
12708 | { | |
12709 | case DW_FORM_ref_addr: | |
c906108c SS |
12710 | case DW_FORM_ref1: |
12711 | case DW_FORM_ref2: | |
12712 | case DW_FORM_ref4: | |
613e1657 | 12713 | case DW_FORM_ref8: |
c906108c | 12714 | case DW_FORM_ref_udata: |
93311388 | 12715 | return 1; |
c906108c | 12716 | default: |
93311388 | 12717 | return 0; |
c906108c | 12718 | } |
93311388 DE |
12719 | } |
12720 | ||
12721 | static unsigned int | |
12722 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
12723 | { | |
12724 | if (is_ref_attr (attr)) | |
12725 | return DW_ADDR (attr); | |
12726 | ||
12727 | complaint (&symfile_complaints, | |
12728 | _("unsupported die ref attribute form: '%s'"), | |
12729 | dwarf_form_name (attr->form)); | |
12730 | return 0; | |
c906108c SS |
12731 | } |
12732 | ||
43bbcdc2 PH |
12733 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
12734 | * the value held by the attribute is not constant. */ | |
a02abb62 | 12735 | |
43bbcdc2 | 12736 | static LONGEST |
a02abb62 JB |
12737 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
12738 | { | |
12739 | if (attr->form == DW_FORM_sdata) | |
12740 | return DW_SND (attr); | |
12741 | else if (attr->form == DW_FORM_udata | |
12742 | || attr->form == DW_FORM_data1 | |
12743 | || attr->form == DW_FORM_data2 | |
12744 | || attr->form == DW_FORM_data4 | |
12745 | || attr->form == DW_FORM_data8) | |
12746 | return DW_UNSND (attr); | |
12747 | else | |
12748 | { | |
e2e0b3e5 | 12749 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
12750 | dwarf_form_name (attr->form)); |
12751 | return default_value; | |
12752 | } | |
12753 | } | |
12754 | ||
03dd20cc | 12755 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
12756 | unit and add it to our queue. |
12757 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
12758 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 12759 | |
348e048f | 12760 | static int |
03dd20cc DJ |
12761 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
12762 | struct dwarf2_per_cu_data *per_cu) | |
12763 | { | |
98bfdba5 PA |
12764 | /* We may arrive here during partial symbol reading, if we need full |
12765 | DIEs to process an unusual case (e.g. template arguments). Do | |
12766 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
12767 | if (dwarf2_per_objfile->reading_partial_symbols) | |
12768 | { | |
12769 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
12770 | return 1; | |
12771 | return 0; | |
12772 | } | |
12773 | ||
03dd20cc DJ |
12774 | /* Mark the dependence relation so that we don't flush PER_CU |
12775 | too early. */ | |
12776 | dwarf2_add_dependence (this_cu, per_cu); | |
12777 | ||
12778 | /* If it's already on the queue, we have nothing to do. */ | |
12779 | if (per_cu->queued) | |
348e048f | 12780 | return 0; |
03dd20cc DJ |
12781 | |
12782 | /* If the compilation unit is already loaded, just mark it as | |
12783 | used. */ | |
12784 | if (per_cu->cu != NULL) | |
12785 | { | |
12786 | per_cu->cu->last_used = 0; | |
348e048f | 12787 | return 0; |
03dd20cc DJ |
12788 | } |
12789 | ||
12790 | /* Add it to the queue. */ | |
12791 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
12792 | |
12793 | return 1; | |
12794 | } | |
12795 | ||
12796 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
12797 | On entry *REF_CU is the CU of SRC_DIE. | |
12798 | On exit *REF_CU is the CU of the result. */ | |
12799 | ||
12800 | static struct die_info * | |
12801 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
12802 | struct dwarf2_cu **ref_cu) | |
12803 | { | |
12804 | struct die_info *die; | |
12805 | ||
12806 | if (is_ref_attr (attr)) | |
12807 | die = follow_die_ref (src_die, attr, ref_cu); | |
12808 | else if (attr->form == DW_FORM_sig8) | |
12809 | die = follow_die_sig (src_die, attr, ref_cu); | |
12810 | else | |
12811 | { | |
12812 | dump_die_for_error (src_die); | |
12813 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
12814 | (*ref_cu)->objfile->name); | |
12815 | } | |
12816 | ||
12817 | return die; | |
03dd20cc DJ |
12818 | } |
12819 | ||
5c631832 | 12820 | /* Follow reference OFFSET. |
673bfd45 DE |
12821 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
12822 | On exit *REF_CU is the CU of the result. | |
12823 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 12824 | |
f9aca02d | 12825 | static struct die_info * |
5c631832 | 12826 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 12827 | { |
10b3939b | 12828 | struct die_info temp_die; |
f2f0e013 | 12829 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 12830 | |
348e048f DE |
12831 | gdb_assert (cu->per_cu != NULL); |
12832 | ||
98bfdba5 PA |
12833 | target_cu = cu; |
12834 | ||
348e048f DE |
12835 | if (cu->per_cu->from_debug_types) |
12836 | { | |
12837 | /* .debug_types CUs cannot reference anything outside their CU. | |
12838 | If they need to, they have to reference a signatured type via | |
12839 | DW_FORM_sig8. */ | |
12840 | if (! offset_in_cu_p (&cu->header, offset)) | |
5c631832 | 12841 | return NULL; |
348e048f DE |
12842 | } |
12843 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
12844 | { |
12845 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 12846 | |
45452591 | 12847 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
12848 | |
12849 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
12850 | if (maybe_queue_comp_unit (cu, per_cu)) |
12851 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 12852 | |
10b3939b DJ |
12853 | target_cu = per_cu->cu; |
12854 | } | |
98bfdba5 PA |
12855 | else if (cu->dies == NULL) |
12856 | { | |
12857 | /* We're loading full DIEs during partial symbol reading. */ | |
12858 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
12859 | load_full_comp_unit (cu->per_cu, cu->objfile); | |
12860 | } | |
c906108c | 12861 | |
f2f0e013 | 12862 | *ref_cu = target_cu; |
51545339 | 12863 | temp_die.offset = offset; |
5c631832 JK |
12864 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
12865 | } | |
10b3939b | 12866 | |
5c631832 JK |
12867 | /* Follow reference attribute ATTR of SRC_DIE. |
12868 | On entry *REF_CU is the CU of SRC_DIE. | |
12869 | On exit *REF_CU is the CU of the result. */ | |
12870 | ||
12871 | static struct die_info * | |
12872 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
12873 | struct dwarf2_cu **ref_cu) | |
12874 | { | |
12875 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12876 | struct dwarf2_cu *cu = *ref_cu; | |
12877 | struct die_info *die; | |
12878 | ||
12879 | die = follow_die_offset (offset, ref_cu); | |
12880 | if (!die) | |
12881 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
12882 | "at 0x%x [in module %s]"), | |
12883 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 12884 | |
5c631832 JK |
12885 | return die; |
12886 | } | |
12887 | ||
12888 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
12889 | value is intended for DW_OP_call*. */ | |
12890 | ||
12891 | struct dwarf2_locexpr_baton | |
12892 | dwarf2_fetch_die_location_block (unsigned int offset, | |
12893 | struct dwarf2_per_cu_data *per_cu) | |
12894 | { | |
12895 | struct dwarf2_cu *cu = per_cu->cu; | |
12896 | struct die_info *die; | |
12897 | struct attribute *attr; | |
12898 | struct dwarf2_locexpr_baton retval; | |
12899 | ||
12900 | die = follow_die_offset (offset, &cu); | |
12901 | if (!die) | |
12902 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
12903 | offset, per_cu->cu->objfile->name); | |
12904 | ||
12905 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
12906 | if (!attr) | |
12907 | { | |
12908 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
12909 | ||
12910 | retval.data = NULL; | |
12911 | retval.size = 0; | |
12912 | } | |
12913 | else | |
12914 | { | |
12915 | if (!attr_form_is_block (attr)) | |
12916 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
12917 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
12918 | offset, per_cu->cu->objfile->name); | |
12919 | ||
12920 | retval.data = DW_BLOCK (attr)->data; | |
12921 | retval.size = DW_BLOCK (attr)->size; | |
12922 | } | |
12923 | retval.per_cu = cu->per_cu; | |
12924 | return retval; | |
348e048f DE |
12925 | } |
12926 | ||
12927 | /* Follow the signature attribute ATTR in SRC_DIE. | |
12928 | On entry *REF_CU is the CU of SRC_DIE. | |
12929 | On exit *REF_CU is the CU of the result. */ | |
12930 | ||
12931 | static struct die_info * | |
12932 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
12933 | struct dwarf2_cu **ref_cu) | |
12934 | { | |
12935 | struct objfile *objfile = (*ref_cu)->objfile; | |
12936 | struct die_info temp_die; | |
12937 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12938 | struct dwarf2_cu *sig_cu; | |
12939 | struct die_info *die; | |
12940 | ||
12941 | /* sig_type will be NULL if the signatured type is missing from | |
12942 | the debug info. */ | |
12943 | if (sig_type == NULL) | |
12944 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12945 | "at 0x%x [in module %s]"), | |
12946 | src_die->offset, objfile->name); | |
12947 | ||
12948 | /* If necessary, add it to the queue and load its DIEs. */ | |
12949 | ||
12950 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
12951 | read_signatured_type (objfile, sig_type); | |
12952 | ||
12953 | gdb_assert (sig_type->per_cu.cu != NULL); | |
12954 | ||
12955 | sig_cu = sig_type->per_cu.cu; | |
12956 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
12957 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
12958 | if (die) | |
12959 | { | |
12960 | *ref_cu = sig_cu; | |
12961 | return die; | |
12962 | } | |
12963 | ||
12964 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
12965 | "at 0x%x [in module %s]"), | |
12966 | sig_type->type_offset, src_die->offset, objfile->name); | |
12967 | } | |
12968 | ||
12969 | /* Given an offset of a signatured type, return its signatured_type. */ | |
12970 | ||
12971 | static struct signatured_type * | |
12972 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
12973 | { | |
12974 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
12975 | unsigned int length, initial_length_size; | |
12976 | unsigned int sig_offset; | |
12977 | struct signatured_type find_entry, *type_sig; | |
12978 | ||
12979 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
12980 | sig_offset = (initial_length_size | |
12981 | + 2 /*version*/ | |
12982 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
12983 | + 1 /*address_size*/); | |
12984 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
12985 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
12986 | ||
12987 | /* This is only used to lookup previously recorded types. | |
12988 | If we didn't find it, it's our bug. */ | |
12989 | gdb_assert (type_sig != NULL); | |
12990 | gdb_assert (offset == type_sig->offset); | |
12991 | ||
12992 | return type_sig; | |
12993 | } | |
12994 | ||
12995 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
12996 | ||
12997 | static void | |
12998 | read_signatured_type_at_offset (struct objfile *objfile, | |
12999 | unsigned int offset) | |
13000 | { | |
13001 | struct signatured_type *type_sig; | |
13002 | ||
be391dca TT |
13003 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13004 | ||
348e048f DE |
13005 | /* We have the section offset, but we need the signature to do the |
13006 | hash table lookup. */ | |
13007 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
13008 | ||
13009 | gdb_assert (type_sig->per_cu.cu == NULL); | |
13010 | ||
13011 | read_signatured_type (objfile, type_sig); | |
13012 | ||
13013 | gdb_assert (type_sig->per_cu.cu != NULL); | |
13014 | } | |
13015 | ||
13016 | /* Read in a signatured type and build its CU and DIEs. */ | |
13017 | ||
13018 | static void | |
13019 | read_signatured_type (struct objfile *objfile, | |
13020 | struct signatured_type *type_sig) | |
13021 | { | |
1fd400ff | 13022 | gdb_byte *types_ptr; |
348e048f DE |
13023 | struct die_reader_specs reader_specs; |
13024 | struct dwarf2_cu *cu; | |
13025 | ULONGEST signature; | |
13026 | struct cleanup *back_to, *free_cu_cleanup; | |
13027 | struct attribute *attr; | |
13028 | ||
1fd400ff TT |
13029 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13030 | types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
13031 | ||
348e048f DE |
13032 | gdb_assert (type_sig->per_cu.cu == NULL); |
13033 | ||
13034 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
13035 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
13036 | obstack_init (&cu->comp_unit_obstack); | |
13037 | cu->objfile = objfile; | |
13038 | type_sig->per_cu.cu = cu; | |
13039 | cu->per_cu = &type_sig->per_cu; | |
13040 | ||
13041 | /* If an error occurs while loading, release our storage. */ | |
13042 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
13043 | ||
13044 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
13045 | types_ptr, objfile->obfd); | |
13046 | gdb_assert (signature == type_sig->signature); | |
13047 | ||
13048 | cu->die_hash | |
13049 | = htab_create_alloc_ex (cu->header.length / 12, | |
13050 | die_hash, | |
13051 | die_eq, | |
13052 | NULL, | |
13053 | &cu->comp_unit_obstack, | |
13054 | hashtab_obstack_allocate, | |
13055 | dummy_obstack_deallocate); | |
13056 | ||
13057 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
13058 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
13059 | ||
13060 | init_cu_die_reader (&reader_specs, cu); | |
13061 | ||
13062 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
13063 | NULL /*parent*/); | |
13064 | ||
13065 | /* We try not to read any attributes in this function, because not | |
13066 | all objfiles needed for references have been loaded yet, and symbol | |
13067 | table processing isn't initialized. But we have to set the CU language, | |
13068 | or we won't be able to build types correctly. */ | |
13069 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
13070 | if (attr) | |
13071 | set_cu_language (DW_UNSND (attr), cu); | |
13072 | else | |
13073 | set_cu_language (language_minimal, cu); | |
13074 | ||
13075 | do_cleanups (back_to); | |
13076 | ||
13077 | /* We've successfully allocated this compilation unit. Let our caller | |
13078 | clean it up when finished with it. */ | |
13079 | discard_cleanups (free_cu_cleanup); | |
13080 | ||
13081 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
13082 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
13083 | } |
13084 | ||
c906108c SS |
13085 | /* Decode simple location descriptions. |
13086 | Given a pointer to a dwarf block that defines a location, compute | |
13087 | the location and return the value. | |
13088 | ||
4cecd739 DJ |
13089 | NOTE drow/2003-11-18: This function is called in two situations |
13090 | now: for the address of static or global variables (partial symbols | |
13091 | only) and for offsets into structures which are expected to be | |
13092 | (more or less) constant. The partial symbol case should go away, | |
13093 | and only the constant case should remain. That will let this | |
13094 | function complain more accurately. A few special modes are allowed | |
13095 | without complaint for global variables (for instance, global | |
13096 | register values and thread-local values). | |
c906108c SS |
13097 | |
13098 | A location description containing no operations indicates that the | |
4cecd739 | 13099 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
13100 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
13101 | callers will only want a very basic result and this can become a | |
13102 | complaint. | |
c906108c | 13103 | |
c906108c SS |
13104 | Note that stack[0] is unused except as a default error return. |
13105 | Note that stack overflow is not yet handled. */ | |
13106 | ||
13107 | static CORE_ADDR | |
e7c27a73 | 13108 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 13109 | { |
e7c27a73 | 13110 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13111 | int i; |
13112 | int size = blk->size; | |
fe1b8b76 | 13113 | gdb_byte *data = blk->data; |
c906108c SS |
13114 | CORE_ADDR stack[64]; |
13115 | int stacki; | |
13116 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 13117 | gdb_byte op; |
c906108c SS |
13118 | |
13119 | i = 0; | |
13120 | stacki = 0; | |
13121 | stack[stacki] = 0; | |
c906108c SS |
13122 | |
13123 | while (i < size) | |
13124 | { | |
c906108c SS |
13125 | op = data[i++]; |
13126 | switch (op) | |
13127 | { | |
f1bea926 JM |
13128 | case DW_OP_lit0: |
13129 | case DW_OP_lit1: | |
13130 | case DW_OP_lit2: | |
13131 | case DW_OP_lit3: | |
13132 | case DW_OP_lit4: | |
13133 | case DW_OP_lit5: | |
13134 | case DW_OP_lit6: | |
13135 | case DW_OP_lit7: | |
13136 | case DW_OP_lit8: | |
13137 | case DW_OP_lit9: | |
13138 | case DW_OP_lit10: | |
13139 | case DW_OP_lit11: | |
13140 | case DW_OP_lit12: | |
13141 | case DW_OP_lit13: | |
13142 | case DW_OP_lit14: | |
13143 | case DW_OP_lit15: | |
13144 | case DW_OP_lit16: | |
13145 | case DW_OP_lit17: | |
13146 | case DW_OP_lit18: | |
13147 | case DW_OP_lit19: | |
13148 | case DW_OP_lit20: | |
13149 | case DW_OP_lit21: | |
13150 | case DW_OP_lit22: | |
13151 | case DW_OP_lit23: | |
13152 | case DW_OP_lit24: | |
13153 | case DW_OP_lit25: | |
13154 | case DW_OP_lit26: | |
13155 | case DW_OP_lit27: | |
13156 | case DW_OP_lit28: | |
13157 | case DW_OP_lit29: | |
13158 | case DW_OP_lit30: | |
13159 | case DW_OP_lit31: | |
13160 | stack[++stacki] = op - DW_OP_lit0; | |
13161 | break; | |
13162 | ||
c906108c SS |
13163 | case DW_OP_reg0: |
13164 | case DW_OP_reg1: | |
13165 | case DW_OP_reg2: | |
13166 | case DW_OP_reg3: | |
13167 | case DW_OP_reg4: | |
13168 | case DW_OP_reg5: | |
13169 | case DW_OP_reg6: | |
13170 | case DW_OP_reg7: | |
13171 | case DW_OP_reg8: | |
13172 | case DW_OP_reg9: | |
13173 | case DW_OP_reg10: | |
13174 | case DW_OP_reg11: | |
13175 | case DW_OP_reg12: | |
13176 | case DW_OP_reg13: | |
13177 | case DW_OP_reg14: | |
13178 | case DW_OP_reg15: | |
13179 | case DW_OP_reg16: | |
13180 | case DW_OP_reg17: | |
13181 | case DW_OP_reg18: | |
13182 | case DW_OP_reg19: | |
13183 | case DW_OP_reg20: | |
13184 | case DW_OP_reg21: | |
13185 | case DW_OP_reg22: | |
13186 | case DW_OP_reg23: | |
13187 | case DW_OP_reg24: | |
13188 | case DW_OP_reg25: | |
13189 | case DW_OP_reg26: | |
13190 | case DW_OP_reg27: | |
13191 | case DW_OP_reg28: | |
13192 | case DW_OP_reg29: | |
13193 | case DW_OP_reg30: | |
13194 | case DW_OP_reg31: | |
c906108c | 13195 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
13196 | if (i < size) |
13197 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13198 | break; |
13199 | ||
13200 | case DW_OP_regx: | |
c906108c SS |
13201 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
13202 | i += bytes_read; | |
c906108c | 13203 | stack[++stacki] = unsnd; |
4cecd739 DJ |
13204 | if (i < size) |
13205 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13206 | break; |
13207 | ||
13208 | case DW_OP_addr: | |
107d2387 | 13209 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 13210 | cu, &bytes_read); |
107d2387 | 13211 | i += bytes_read; |
c906108c SS |
13212 | break; |
13213 | ||
13214 | case DW_OP_const1u: | |
13215 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
13216 | i += 1; | |
13217 | break; | |
13218 | ||
13219 | case DW_OP_const1s: | |
13220 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
13221 | i += 1; | |
13222 | break; | |
13223 | ||
13224 | case DW_OP_const2u: | |
13225 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
13226 | i += 2; | |
13227 | break; | |
13228 | ||
13229 | case DW_OP_const2s: | |
13230 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
13231 | i += 2; | |
13232 | break; | |
13233 | ||
13234 | case DW_OP_const4u: | |
13235 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
13236 | i += 4; | |
13237 | break; | |
13238 | ||
13239 | case DW_OP_const4s: | |
13240 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
13241 | i += 4; | |
13242 | break; | |
13243 | ||
13244 | case DW_OP_constu: | |
13245 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 13246 | &bytes_read); |
c906108c SS |
13247 | i += bytes_read; |
13248 | break; | |
13249 | ||
13250 | case DW_OP_consts: | |
13251 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
13252 | i += bytes_read; | |
13253 | break; | |
13254 | ||
f1bea926 JM |
13255 | case DW_OP_dup: |
13256 | stack[stacki + 1] = stack[stacki]; | |
13257 | stacki++; | |
13258 | break; | |
13259 | ||
c906108c SS |
13260 | case DW_OP_plus: |
13261 | stack[stacki - 1] += stack[stacki]; | |
13262 | stacki--; | |
13263 | break; | |
13264 | ||
13265 | case DW_OP_plus_uconst: | |
13266 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
13267 | i += bytes_read; | |
13268 | break; | |
13269 | ||
13270 | case DW_OP_minus: | |
f1bea926 | 13271 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
13272 | stacki--; |
13273 | break; | |
13274 | ||
7a292a7a | 13275 | case DW_OP_deref: |
7a292a7a | 13276 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
13277 | this using GDB's address_class enum. This is valid for partial |
13278 | global symbols, although the variable's address will be bogus | |
13279 | in the psymtab. */ | |
7a292a7a | 13280 | if (i < size) |
4d3c2250 | 13281 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
13282 | break; |
13283 | ||
9d774e44 | 13284 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
13285 | /* The top of the stack has the offset from the beginning |
13286 | of the thread control block at which the variable is located. */ | |
13287 | /* Nothing should follow this operator, so the top of stack would | |
13288 | be returned. */ | |
4cecd739 DJ |
13289 | /* This is valid for partial global symbols, but the variable's |
13290 | address will be bogus in the psymtab. */ | |
9d774e44 | 13291 | if (i < size) |
4d3c2250 | 13292 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
13293 | break; |
13294 | ||
42be36b3 CT |
13295 | case DW_OP_GNU_uninit: |
13296 | break; | |
13297 | ||
c906108c | 13298 | default: |
e2e0b3e5 | 13299 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
9eae7c52 | 13300 | dwarf_stack_op_name (op, 1)); |
c906108c SS |
13301 | return (stack[stacki]); |
13302 | } | |
13303 | } | |
13304 | return (stack[stacki]); | |
13305 | } | |
13306 | ||
13307 | /* memory allocation interface */ | |
13308 | ||
c906108c | 13309 | static struct dwarf_block * |
7b5a2f43 | 13310 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
13311 | { |
13312 | struct dwarf_block *blk; | |
13313 | ||
13314 | blk = (struct dwarf_block *) | |
7b5a2f43 | 13315 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
13316 | return (blk); |
13317 | } | |
13318 | ||
13319 | static struct abbrev_info * | |
f3dd6933 | 13320 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
13321 | { |
13322 | struct abbrev_info *abbrev; | |
13323 | ||
f3dd6933 DJ |
13324 | abbrev = (struct abbrev_info *) |
13325 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
13326 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
13327 | return (abbrev); | |
13328 | } | |
13329 | ||
13330 | static struct die_info * | |
b60c80d6 | 13331 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
13332 | { |
13333 | struct die_info *die; | |
b60c80d6 DJ |
13334 | size_t size = sizeof (struct die_info); |
13335 | ||
13336 | if (num_attrs > 1) | |
13337 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 13338 | |
b60c80d6 | 13339 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
13340 | memset (die, 0, sizeof (struct die_info)); |
13341 | return (die); | |
13342 | } | |
2e276125 JB |
13343 | |
13344 | \f | |
13345 | /* Macro support. */ | |
13346 | ||
13347 | ||
13348 | /* Return the full name of file number I in *LH's file name table. | |
13349 | Use COMP_DIR as the name of the current directory of the | |
13350 | compilation. The result is allocated using xmalloc; the caller is | |
13351 | responsible for freeing it. */ | |
13352 | static char * | |
13353 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
13354 | { | |
6a83a1e6 EZ |
13355 | /* Is the file number a valid index into the line header's file name |
13356 | table? Remember that file numbers start with one, not zero. */ | |
13357 | if (1 <= file && file <= lh->num_file_names) | |
13358 | { | |
13359 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 13360 | |
6a83a1e6 EZ |
13361 | if (IS_ABSOLUTE_PATH (fe->name)) |
13362 | return xstrdup (fe->name); | |
13363 | else | |
13364 | { | |
13365 | const char *dir; | |
13366 | int dir_len; | |
13367 | char *full_name; | |
13368 | ||
13369 | if (fe->dir_index) | |
13370 | dir = lh->include_dirs[fe->dir_index - 1]; | |
13371 | else | |
13372 | dir = comp_dir; | |
13373 | ||
13374 | if (dir) | |
13375 | { | |
13376 | dir_len = strlen (dir); | |
13377 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
13378 | strcpy (full_name, dir); | |
13379 | full_name[dir_len] = '/'; | |
13380 | strcpy (full_name + dir_len + 1, fe->name); | |
13381 | return full_name; | |
13382 | } | |
13383 | else | |
13384 | return xstrdup (fe->name); | |
13385 | } | |
13386 | } | |
2e276125 JB |
13387 | else |
13388 | { | |
6a83a1e6 EZ |
13389 | /* The compiler produced a bogus file number. We can at least |
13390 | record the macro definitions made in the file, even if we | |
13391 | won't be able to find the file by name. */ | |
13392 | char fake_name[80]; | |
9a619af0 | 13393 | |
6a83a1e6 | 13394 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 13395 | |
6e70227d | 13396 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
13397 | _("bad file number in macro information (%d)"), |
13398 | file); | |
2e276125 | 13399 | |
6a83a1e6 | 13400 | return xstrdup (fake_name); |
2e276125 JB |
13401 | } |
13402 | } | |
13403 | ||
13404 | ||
13405 | static struct macro_source_file * | |
13406 | macro_start_file (int file, int line, | |
13407 | struct macro_source_file *current_file, | |
13408 | const char *comp_dir, | |
13409 | struct line_header *lh, struct objfile *objfile) | |
13410 | { | |
13411 | /* The full name of this source file. */ | |
13412 | char *full_name = file_full_name (file, lh, comp_dir); | |
13413 | ||
13414 | /* We don't create a macro table for this compilation unit | |
13415 | at all until we actually get a filename. */ | |
13416 | if (! pending_macros) | |
4a146b47 | 13417 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 13418 | objfile->macro_cache); |
2e276125 JB |
13419 | |
13420 | if (! current_file) | |
13421 | /* If we have no current file, then this must be the start_file | |
13422 | directive for the compilation unit's main source file. */ | |
13423 | current_file = macro_set_main (pending_macros, full_name); | |
13424 | else | |
13425 | current_file = macro_include (current_file, line, full_name); | |
13426 | ||
13427 | xfree (full_name); | |
6e70227d | 13428 | |
2e276125 JB |
13429 | return current_file; |
13430 | } | |
13431 | ||
13432 | ||
13433 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
13434 | followed by a null byte. */ | |
13435 | static char * | |
13436 | copy_string (const char *buf, int len) | |
13437 | { | |
13438 | char *s = xmalloc (len + 1); | |
9a619af0 | 13439 | |
2e276125 JB |
13440 | memcpy (s, buf, len); |
13441 | s[len] = '\0'; | |
2e276125 JB |
13442 | return s; |
13443 | } | |
13444 | ||
13445 | ||
13446 | static const char * | |
13447 | consume_improper_spaces (const char *p, const char *body) | |
13448 | { | |
13449 | if (*p == ' ') | |
13450 | { | |
4d3c2250 | 13451 | complaint (&symfile_complaints, |
e2e0b3e5 | 13452 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 13453 | body); |
2e276125 JB |
13454 | |
13455 | while (*p == ' ') | |
13456 | p++; | |
13457 | } | |
13458 | ||
13459 | return p; | |
13460 | } | |
13461 | ||
13462 | ||
13463 | static void | |
13464 | parse_macro_definition (struct macro_source_file *file, int line, | |
13465 | const char *body) | |
13466 | { | |
13467 | const char *p; | |
13468 | ||
13469 | /* The body string takes one of two forms. For object-like macro | |
13470 | definitions, it should be: | |
13471 | ||
13472 | <macro name> " " <definition> | |
13473 | ||
13474 | For function-like macro definitions, it should be: | |
13475 | ||
13476 | <macro name> "() " <definition> | |
13477 | or | |
13478 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
13479 | ||
13480 | Spaces may appear only where explicitly indicated, and in the | |
13481 | <definition>. | |
13482 | ||
13483 | The Dwarf 2 spec says that an object-like macro's name is always | |
13484 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 13485 | the space when the macro's definition is the empty string. |
2e276125 JB |
13486 | |
13487 | The Dwarf 2 spec says that there should be no spaces between the | |
13488 | formal arguments in a function-like macro's formal argument list, | |
13489 | but versions of GCC around March 2002 include spaces after the | |
13490 | commas. */ | |
13491 | ||
13492 | ||
13493 | /* Find the extent of the macro name. The macro name is terminated | |
13494 | by either a space or null character (for an object-like macro) or | |
13495 | an opening paren (for a function-like macro). */ | |
13496 | for (p = body; *p; p++) | |
13497 | if (*p == ' ' || *p == '(') | |
13498 | break; | |
13499 | ||
13500 | if (*p == ' ' || *p == '\0') | |
13501 | { | |
13502 | /* It's an object-like macro. */ | |
13503 | int name_len = p - body; | |
13504 | char *name = copy_string (body, name_len); | |
13505 | const char *replacement; | |
13506 | ||
13507 | if (*p == ' ') | |
13508 | replacement = body + name_len + 1; | |
13509 | else | |
13510 | { | |
4d3c2250 | 13511 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13512 | replacement = body + name_len; |
13513 | } | |
6e70227d | 13514 | |
2e276125 JB |
13515 | macro_define_object (file, line, name, replacement); |
13516 | ||
13517 | xfree (name); | |
13518 | } | |
13519 | else if (*p == '(') | |
13520 | { | |
13521 | /* It's a function-like macro. */ | |
13522 | char *name = copy_string (body, p - body); | |
13523 | int argc = 0; | |
13524 | int argv_size = 1; | |
13525 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
13526 | ||
13527 | p++; | |
13528 | ||
13529 | p = consume_improper_spaces (p, body); | |
13530 | ||
13531 | /* Parse the formal argument list. */ | |
13532 | while (*p && *p != ')') | |
13533 | { | |
13534 | /* Find the extent of the current argument name. */ | |
13535 | const char *arg_start = p; | |
13536 | ||
13537 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
13538 | p++; | |
13539 | ||
13540 | if (! *p || p == arg_start) | |
4d3c2250 | 13541 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13542 | else |
13543 | { | |
13544 | /* Make sure argv has room for the new argument. */ | |
13545 | if (argc >= argv_size) | |
13546 | { | |
13547 | argv_size *= 2; | |
13548 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
13549 | } | |
13550 | ||
13551 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
13552 | } | |
13553 | ||
13554 | p = consume_improper_spaces (p, body); | |
13555 | ||
13556 | /* Consume the comma, if present. */ | |
13557 | if (*p == ',') | |
13558 | { | |
13559 | p++; | |
13560 | ||
13561 | p = consume_improper_spaces (p, body); | |
13562 | } | |
13563 | } | |
13564 | ||
13565 | if (*p == ')') | |
13566 | { | |
13567 | p++; | |
13568 | ||
13569 | if (*p == ' ') | |
13570 | /* Perfectly formed definition, no complaints. */ | |
13571 | macro_define_function (file, line, name, | |
6e70227d | 13572 | argc, (const char **) argv, |
2e276125 JB |
13573 | p + 1); |
13574 | else if (*p == '\0') | |
13575 | { | |
13576 | /* Complain, but do define it. */ | |
4d3c2250 | 13577 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 13578 | macro_define_function (file, line, name, |
6e70227d | 13579 | argc, (const char **) argv, |
2e276125 JB |
13580 | p); |
13581 | } | |
13582 | else | |
13583 | /* Just complain. */ | |
4d3c2250 | 13584 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13585 | } |
13586 | else | |
13587 | /* Just complain. */ | |
4d3c2250 | 13588 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13589 | |
13590 | xfree (name); | |
13591 | { | |
13592 | int i; | |
13593 | ||
13594 | for (i = 0; i < argc; i++) | |
13595 | xfree (argv[i]); | |
13596 | } | |
13597 | xfree (argv); | |
13598 | } | |
13599 | else | |
4d3c2250 | 13600 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13601 | } |
13602 | ||
13603 | ||
13604 | static void | |
13605 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
13606 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 13607 | struct dwarf2_cu *cu) |
2e276125 | 13608 | { |
fe1b8b76 | 13609 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 13610 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
13611 | enum dwarf_macinfo_record_type macinfo_type; |
13612 | int at_commandline; | |
2e276125 | 13613 | |
be391dca TT |
13614 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
13615 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 13616 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 13617 | { |
e2e0b3e5 | 13618 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
13619 | return; |
13620 | } | |
13621 | ||
757a13d0 JK |
13622 | /* First pass: Find the name of the base filename. |
13623 | This filename is needed in order to process all macros whose definition | |
13624 | (or undefinition) comes from the command line. These macros are defined | |
13625 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
13626 | associated to the base file. | |
13627 | ||
13628 | To determine the base file name, we scan the macro definitions until we | |
13629 | reach the first DW_MACINFO_start_file entry. We then initialize | |
13630 | CURRENT_FILE accordingly so that any macro definition found before the | |
13631 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
13632 | ||
dce234bc PP |
13633 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
13634 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
13635 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 13636 | |
757a13d0 | 13637 | do |
2e276125 | 13638 | { |
2e276125 JB |
13639 | /* Do we at least have room for a macinfo type byte? */ |
13640 | if (mac_ptr >= mac_end) | |
13641 | { | |
757a13d0 JK |
13642 | /* Complaint is printed during the second pass as GDB will probably |
13643 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
13644 | break; | |
2e276125 JB |
13645 | } |
13646 | ||
13647 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
13648 | mac_ptr++; | |
13649 | ||
13650 | switch (macinfo_type) | |
13651 | { | |
13652 | /* A zero macinfo type indicates the end of the macro | |
13653 | information. */ | |
13654 | case 0: | |
757a13d0 JK |
13655 | break; |
13656 | ||
13657 | case DW_MACINFO_define: | |
13658 | case DW_MACINFO_undef: | |
13659 | /* Only skip the data by MAC_PTR. */ | |
13660 | { | |
13661 | unsigned int bytes_read; | |
13662 | ||
13663 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13664 | mac_ptr += bytes_read; | |
9b1c24c8 | 13665 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
13666 | mac_ptr += bytes_read; |
13667 | } | |
13668 | break; | |
13669 | ||
13670 | case DW_MACINFO_start_file: | |
13671 | { | |
13672 | unsigned int bytes_read; | |
13673 | int line, file; | |
13674 | ||
13675 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13676 | mac_ptr += bytes_read; | |
13677 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13678 | mac_ptr += bytes_read; | |
13679 | ||
13680 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
13681 | lh, cu->objfile); | |
13682 | } | |
13683 | break; | |
13684 | ||
13685 | case DW_MACINFO_end_file: | |
13686 | /* No data to skip by MAC_PTR. */ | |
13687 | break; | |
13688 | ||
13689 | case DW_MACINFO_vendor_ext: | |
13690 | /* Only skip the data by MAC_PTR. */ | |
13691 | { | |
13692 | unsigned int bytes_read; | |
13693 | ||
13694 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13695 | mac_ptr += bytes_read; | |
9b1c24c8 | 13696 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
13697 | mac_ptr += bytes_read; |
13698 | } | |
13699 | break; | |
13700 | ||
13701 | default: | |
13702 | break; | |
13703 | } | |
13704 | } while (macinfo_type != 0 && current_file == NULL); | |
13705 | ||
13706 | /* Second pass: Process all entries. | |
13707 | ||
13708 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
13709 | command-line macro definitions/undefinitions. This flag is unset when we | |
13710 | reach the first DW_MACINFO_start_file entry. */ | |
13711 | ||
dce234bc | 13712 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
13713 | |
13714 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
13715 | GDB is still reading the definitions from command line. First | |
13716 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
13717 | to create CURRENT_FILE for the main source holding also the command line | |
13718 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
13719 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
13720 | ||
13721 | at_commandline = 1; | |
13722 | ||
13723 | do | |
13724 | { | |
13725 | /* Do we at least have room for a macinfo type byte? */ | |
13726 | if (mac_ptr >= mac_end) | |
13727 | { | |
13728 | dwarf2_macros_too_long_complaint (); | |
13729 | break; | |
13730 | } | |
13731 | ||
13732 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
13733 | mac_ptr++; | |
13734 | ||
13735 | switch (macinfo_type) | |
13736 | { | |
13737 | /* A zero macinfo type indicates the end of the macro | |
13738 | information. */ | |
13739 | case 0: | |
13740 | break; | |
2e276125 JB |
13741 | |
13742 | case DW_MACINFO_define: | |
13743 | case DW_MACINFO_undef: | |
13744 | { | |
891d2f0b | 13745 | unsigned int bytes_read; |
2e276125 JB |
13746 | int line; |
13747 | char *body; | |
13748 | ||
13749 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13750 | mac_ptr += bytes_read; | |
9b1c24c8 | 13751 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
13752 | mac_ptr += bytes_read; |
13753 | ||
13754 | if (! current_file) | |
757a13d0 JK |
13755 | { |
13756 | /* DWARF violation as no main source is present. */ | |
13757 | complaint (&symfile_complaints, | |
13758 | _("debug info with no main source gives macro %s " | |
13759 | "on line %d: %s"), | |
6e70227d DE |
13760 | macinfo_type == DW_MACINFO_define ? |
13761 | _("definition") : | |
905e0470 PM |
13762 | macinfo_type == DW_MACINFO_undef ? |
13763 | _("undefinition") : | |
13764 | _("something-or-other"), line, body); | |
757a13d0 JK |
13765 | break; |
13766 | } | |
13767 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 13768 | complaint (&symfile_complaints, |
757a13d0 JK |
13769 | _("debug info gives %s macro %s with %s line %d: %s"), |
13770 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 13771 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 13772 | _("definition") : |
905e0470 PM |
13773 | macinfo_type == DW_MACINFO_undef ? |
13774 | _("undefinition") : | |
13775 | _("something-or-other"), | |
757a13d0 JK |
13776 | line == 0 ? _("zero") : _("non-zero"), line, body); |
13777 | ||
13778 | if (macinfo_type == DW_MACINFO_define) | |
13779 | parse_macro_definition (current_file, line, body); | |
13780 | else if (macinfo_type == DW_MACINFO_undef) | |
13781 | macro_undef (current_file, line, body); | |
2e276125 JB |
13782 | } |
13783 | break; | |
13784 | ||
13785 | case DW_MACINFO_start_file: | |
13786 | { | |
891d2f0b | 13787 | unsigned int bytes_read; |
2e276125 JB |
13788 | int line, file; |
13789 | ||
13790 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13791 | mac_ptr += bytes_read; | |
13792 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13793 | mac_ptr += bytes_read; | |
13794 | ||
757a13d0 JK |
13795 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
13796 | complaint (&symfile_complaints, | |
13797 | _("debug info gives source %d included " | |
13798 | "from %s at %s line %d"), | |
13799 | file, at_commandline ? _("command-line") : _("file"), | |
13800 | line == 0 ? _("zero") : _("non-zero"), line); | |
13801 | ||
13802 | if (at_commandline) | |
13803 | { | |
13804 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
13805 | at_commandline = 0; | |
13806 | } | |
13807 | else | |
13808 | current_file = macro_start_file (file, line, | |
13809 | current_file, comp_dir, | |
13810 | lh, cu->objfile); | |
2e276125 JB |
13811 | } |
13812 | break; | |
13813 | ||
13814 | case DW_MACINFO_end_file: | |
13815 | if (! current_file) | |
4d3c2250 | 13816 | complaint (&symfile_complaints, |
e2e0b3e5 | 13817 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
13818 | else |
13819 | { | |
13820 | current_file = current_file->included_by; | |
13821 | if (! current_file) | |
13822 | { | |
13823 | enum dwarf_macinfo_record_type next_type; | |
13824 | ||
13825 | /* GCC circa March 2002 doesn't produce the zero | |
13826 | type byte marking the end of the compilation | |
13827 | unit. Complain if it's not there, but exit no | |
13828 | matter what. */ | |
13829 | ||
13830 | /* Do we at least have room for a macinfo type byte? */ | |
13831 | if (mac_ptr >= mac_end) | |
13832 | { | |
4d3c2250 | 13833 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
13834 | return; |
13835 | } | |
13836 | ||
13837 | /* We don't increment mac_ptr here, so this is just | |
13838 | a look-ahead. */ | |
13839 | next_type = read_1_byte (abfd, mac_ptr); | |
13840 | if (next_type != 0) | |
4d3c2250 | 13841 | complaint (&symfile_complaints, |
e2e0b3e5 | 13842 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
13843 | |
13844 | return; | |
13845 | } | |
13846 | } | |
13847 | break; | |
13848 | ||
13849 | case DW_MACINFO_vendor_ext: | |
13850 | { | |
891d2f0b | 13851 | unsigned int bytes_read; |
2e276125 JB |
13852 | int constant; |
13853 | char *string; | |
13854 | ||
13855 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13856 | mac_ptr += bytes_read; | |
9b1c24c8 | 13857 | string = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
13858 | mac_ptr += bytes_read; |
13859 | ||
13860 | /* We don't recognize any vendor extensions. */ | |
13861 | } | |
13862 | break; | |
13863 | } | |
757a13d0 | 13864 | } while (macinfo_type != 0); |
2e276125 | 13865 | } |
8e19ed76 PS |
13866 | |
13867 | /* Check if the attribute's form is a DW_FORM_block* | |
13868 | if so return true else false. */ | |
13869 | static int | |
13870 | attr_form_is_block (struct attribute *attr) | |
13871 | { | |
13872 | return (attr == NULL ? 0 : | |
13873 | attr->form == DW_FORM_block1 | |
13874 | || attr->form == DW_FORM_block2 | |
13875 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
13876 | || attr->form == DW_FORM_block |
13877 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 13878 | } |
4c2df51b | 13879 | |
c6a0999f JB |
13880 | /* Return non-zero if ATTR's value is a section offset --- classes |
13881 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
13882 | You may use DW_UNSND (attr) to retrieve such offsets. | |
13883 | ||
13884 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
13885 | may have a value that belongs to more than one of these classes; it | |
13886 | would be ambiguous if we did, because we use the same forms for all | |
13887 | of them. */ | |
3690dd37 JB |
13888 | static int |
13889 | attr_form_is_section_offset (struct attribute *attr) | |
13890 | { | |
13891 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
13892 | || attr->form == DW_FORM_data8 |
13893 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
13894 | } |
13895 | ||
13896 | ||
13897 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
13898 | zero otherwise. When this function returns true, you can apply | |
13899 | dwarf2_get_attr_constant_value to it. | |
13900 | ||
13901 | However, note that for some attributes you must check | |
13902 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
13903 | and DW_FORM_data8 are members of both the constant class, and of | |
13904 | the classes that contain offsets into other debug sections | |
13905 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
13906 | that, if an attribute's can be either a constant or one of the | |
13907 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
13908 | taken as section offsets, not constants. */ | |
13909 | static int | |
13910 | attr_form_is_constant (struct attribute *attr) | |
13911 | { | |
13912 | switch (attr->form) | |
13913 | { | |
13914 | case DW_FORM_sdata: | |
13915 | case DW_FORM_udata: | |
13916 | case DW_FORM_data1: | |
13917 | case DW_FORM_data2: | |
13918 | case DW_FORM_data4: | |
13919 | case DW_FORM_data8: | |
13920 | return 1; | |
13921 | default: | |
13922 | return 0; | |
13923 | } | |
13924 | } | |
13925 | ||
4c2df51b DJ |
13926 | static void |
13927 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 13928 | struct dwarf2_cu *cu) |
4c2df51b | 13929 | { |
3690dd37 | 13930 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
13931 | /* ".debug_loc" may not exist at all, or the offset may be outside |
13932 | the section. If so, fall through to the complaint in the | |
13933 | other branch. */ | |
dce234bc | 13934 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 13935 | { |
0d53c4c4 | 13936 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 13937 | |
4a146b47 | 13938 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13939 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
13940 | baton->per_cu = cu->per_cu; |
13941 | gdb_assert (baton->per_cu); | |
4c2df51b | 13942 | |
be391dca TT |
13943 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
13944 | &dwarf2_per_objfile->loc); | |
13945 | ||
0d53c4c4 DJ |
13946 | /* We don't know how long the location list is, but make sure we |
13947 | don't run off the edge of the section. */ | |
dce234bc PP |
13948 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
13949 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
13950 | baton->base_address = cu->base_address; |
13951 | if (cu->base_known == 0) | |
0d53c4c4 | 13952 | complaint (&symfile_complaints, |
e2e0b3e5 | 13953 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 13954 | |
768a979c | 13955 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
13956 | SYMBOL_LOCATION_BATON (sym) = baton; |
13957 | } | |
13958 | else | |
13959 | { | |
13960 | struct dwarf2_locexpr_baton *baton; | |
13961 | ||
4a146b47 | 13962 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13963 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
13964 | baton->per_cu = cu->per_cu; |
13965 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
13966 | |
13967 | if (attr_form_is_block (attr)) | |
13968 | { | |
13969 | /* Note that we're just copying the block's data pointer | |
13970 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
13971 | info_buffer for SYM's objfile; right now we never release |
13972 | that buffer, but when we do clean up properly this may | |
13973 | need to change. */ | |
0d53c4c4 DJ |
13974 | baton->size = DW_BLOCK (attr)->size; |
13975 | baton->data = DW_BLOCK (attr)->data; | |
13976 | } | |
13977 | else | |
13978 | { | |
13979 | dwarf2_invalid_attrib_class_complaint ("location description", | |
13980 | SYMBOL_NATURAL_NAME (sym)); | |
13981 | baton->size = 0; | |
13982 | baton->data = NULL; | |
13983 | } | |
6e70227d | 13984 | |
768a979c | 13985 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
13986 | SYMBOL_LOCATION_BATON (sym) = baton; |
13987 | } | |
4c2df51b | 13988 | } |
6502dd73 | 13989 | |
9aa1f1e3 TT |
13990 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
13991 | came from a separate debuginfo file, then the master objfile is | |
13992 | returned. */ | |
ae0d2f24 UW |
13993 | |
13994 | struct objfile * | |
13995 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
13996 | { | |
9291a0cd | 13997 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13998 | |
13999 | /* Return the master objfile, so that we can report and look up the | |
14000 | correct file containing this variable. */ | |
14001 | if (objfile->separate_debug_objfile_backlink) | |
14002 | objfile = objfile->separate_debug_objfile_backlink; | |
14003 | ||
14004 | return objfile; | |
14005 | } | |
14006 | ||
14007 | /* Return the address size given in the compilation unit header for CU. */ | |
14008 | ||
14009 | CORE_ADDR | |
14010 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
14011 | { | |
14012 | if (per_cu->cu) | |
14013 | return per_cu->cu->header.addr_size; | |
14014 | else | |
14015 | { | |
14016 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14017 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14018 | struct dwarf2_per_objfile *per_objfile |
14019 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 14020 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 14021 | struct comp_unit_head cu_header; |
9a619af0 | 14022 | |
ae0d2f24 UW |
14023 | memset (&cu_header, 0, sizeof cu_header); |
14024 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14025 | return cu_header.addr_size; | |
14026 | } | |
14027 | } | |
14028 | ||
9eae7c52 TT |
14029 | /* Return the offset size given in the compilation unit header for CU. */ |
14030 | ||
14031 | int | |
14032 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
14033 | { | |
14034 | if (per_cu->cu) | |
14035 | return per_cu->cu->header.offset_size; | |
14036 | else | |
14037 | { | |
14038 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14039 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
14040 | struct dwarf2_per_objfile *per_objfile |
14041 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
14042 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
14043 | struct comp_unit_head cu_header; | |
14044 | ||
14045 | memset (&cu_header, 0, sizeof cu_header); | |
14046 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14047 | return cu_header.offset_size; | |
14048 | } | |
14049 | } | |
14050 | ||
9aa1f1e3 TT |
14051 | /* Return the text offset of the CU. The returned offset comes from |
14052 | this CU's objfile. If this objfile came from a separate debuginfo | |
14053 | file, then the offset may be different from the corresponding | |
14054 | offset in the parent objfile. */ | |
14055 | ||
14056 | CORE_ADDR | |
14057 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
14058 | { | |
bb3fa9d0 | 14059 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
14060 | |
14061 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
14062 | } | |
14063 | ||
348e048f DE |
14064 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
14065 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
14066 | |
14067 | static struct dwarf2_per_cu_data * | |
c764a876 | 14068 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
14069 | struct objfile *objfile) |
14070 | { | |
14071 | struct dwarf2_per_cu_data *this_cu; | |
14072 | int low, high; | |
14073 | ||
ae038cb0 DJ |
14074 | low = 0; |
14075 | high = dwarf2_per_objfile->n_comp_units - 1; | |
14076 | while (high > low) | |
14077 | { | |
14078 | int mid = low + (high - low) / 2; | |
9a619af0 | 14079 | |
ae038cb0 DJ |
14080 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
14081 | high = mid; | |
14082 | else | |
14083 | low = mid + 1; | |
14084 | } | |
14085 | gdb_assert (low == high); | |
14086 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
14087 | { | |
10b3939b | 14088 | if (low == 0) |
8a3fe4f8 AC |
14089 | error (_("Dwarf Error: could not find partial DIE containing " |
14090 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
14091 | (long) offset, bfd_get_filename (objfile->obfd)); |
14092 | ||
ae038cb0 DJ |
14093 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
14094 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
14095 | } | |
14096 | else | |
14097 | { | |
14098 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
14099 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
14100 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 14101 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
14102 | gdb_assert (offset < this_cu->offset + this_cu->length); |
14103 | return this_cu; | |
14104 | } | |
14105 | } | |
14106 | ||
10b3939b DJ |
14107 | /* Locate the compilation unit from OBJFILE which is located at exactly |
14108 | OFFSET. Raises an error on failure. */ | |
14109 | ||
ae038cb0 | 14110 | static struct dwarf2_per_cu_data * |
c764a876 | 14111 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
14112 | { |
14113 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 14114 | |
ae038cb0 DJ |
14115 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
14116 | if (this_cu->offset != offset) | |
c764a876 | 14117 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
14118 | return this_cu; |
14119 | } | |
14120 | ||
93311388 DE |
14121 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
14122 | ||
14123 | static struct dwarf2_cu * | |
14124 | alloc_one_comp_unit (struct objfile *objfile) | |
14125 | { | |
14126 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
14127 | cu->objfile = objfile; | |
14128 | obstack_init (&cu->comp_unit_obstack); | |
14129 | return cu; | |
14130 | } | |
14131 | ||
ae038cb0 DJ |
14132 | /* Release one cached compilation unit, CU. We unlink it from the tree |
14133 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
14134 | the caller is responsible for that. |
14135 | NOTE: DATA is a void * because this function is also used as a | |
14136 | cleanup routine. */ | |
ae038cb0 DJ |
14137 | |
14138 | static void | |
14139 | free_one_comp_unit (void *data) | |
14140 | { | |
14141 | struct dwarf2_cu *cu = data; | |
14142 | ||
14143 | if (cu->per_cu != NULL) | |
14144 | cu->per_cu->cu = NULL; | |
14145 | cu->per_cu = NULL; | |
14146 | ||
14147 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14148 | ||
14149 | xfree (cu); | |
14150 | } | |
14151 | ||
72bf9492 | 14152 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
14153 | when we're finished with it. We can't free the pointer itself, but be |
14154 | sure to unlink it from the cache. Also release any associated storage | |
14155 | and perform cache maintenance. | |
72bf9492 DJ |
14156 | |
14157 | Only used during partial symbol parsing. */ | |
14158 | ||
14159 | static void | |
14160 | free_stack_comp_unit (void *data) | |
14161 | { | |
14162 | struct dwarf2_cu *cu = data; | |
14163 | ||
14164 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14165 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
14166 | |
14167 | if (cu->per_cu != NULL) | |
14168 | { | |
14169 | /* This compilation unit is on the stack in our caller, so we | |
14170 | should not xfree it. Just unlink it. */ | |
14171 | cu->per_cu->cu = NULL; | |
14172 | cu->per_cu = NULL; | |
14173 | ||
14174 | /* If we had a per-cu pointer, then we may have other compilation | |
14175 | units loaded, so age them now. */ | |
14176 | age_cached_comp_units (); | |
14177 | } | |
14178 | } | |
14179 | ||
14180 | /* Free all cached compilation units. */ | |
14181 | ||
14182 | static void | |
14183 | free_cached_comp_units (void *data) | |
14184 | { | |
14185 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14186 | ||
14187 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14188 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14189 | while (per_cu != NULL) | |
14190 | { | |
14191 | struct dwarf2_per_cu_data *next_cu; | |
14192 | ||
14193 | next_cu = per_cu->cu->read_in_chain; | |
14194 | ||
14195 | free_one_comp_unit (per_cu->cu); | |
14196 | *last_chain = next_cu; | |
14197 | ||
14198 | per_cu = next_cu; | |
14199 | } | |
14200 | } | |
14201 | ||
14202 | /* Increase the age counter on each cached compilation unit, and free | |
14203 | any that are too old. */ | |
14204 | ||
14205 | static void | |
14206 | age_cached_comp_units (void) | |
14207 | { | |
14208 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14209 | ||
14210 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
14211 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14212 | while (per_cu != NULL) | |
14213 | { | |
14214 | per_cu->cu->last_used ++; | |
14215 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
14216 | dwarf2_mark (per_cu->cu); | |
14217 | per_cu = per_cu->cu->read_in_chain; | |
14218 | } | |
14219 | ||
14220 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14221 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14222 | while (per_cu != NULL) | |
14223 | { | |
14224 | struct dwarf2_per_cu_data *next_cu; | |
14225 | ||
14226 | next_cu = per_cu->cu->read_in_chain; | |
14227 | ||
14228 | if (!per_cu->cu->mark) | |
14229 | { | |
14230 | free_one_comp_unit (per_cu->cu); | |
14231 | *last_chain = next_cu; | |
14232 | } | |
14233 | else | |
14234 | last_chain = &per_cu->cu->read_in_chain; | |
14235 | ||
14236 | per_cu = next_cu; | |
14237 | } | |
14238 | } | |
14239 | ||
14240 | /* Remove a single compilation unit from the cache. */ | |
14241 | ||
14242 | static void | |
14243 | free_one_cached_comp_unit (void *target_cu) | |
14244 | { | |
14245 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14246 | ||
14247 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14248 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14249 | while (per_cu != NULL) | |
14250 | { | |
14251 | struct dwarf2_per_cu_data *next_cu; | |
14252 | ||
14253 | next_cu = per_cu->cu->read_in_chain; | |
14254 | ||
14255 | if (per_cu->cu == target_cu) | |
14256 | { | |
14257 | free_one_comp_unit (per_cu->cu); | |
14258 | *last_chain = next_cu; | |
14259 | break; | |
14260 | } | |
14261 | else | |
14262 | last_chain = &per_cu->cu->read_in_chain; | |
14263 | ||
14264 | per_cu = next_cu; | |
14265 | } | |
14266 | } | |
14267 | ||
fe3e1990 DJ |
14268 | /* Release all extra memory associated with OBJFILE. */ |
14269 | ||
14270 | void | |
14271 | dwarf2_free_objfile (struct objfile *objfile) | |
14272 | { | |
14273 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
14274 | ||
14275 | if (dwarf2_per_objfile == NULL) | |
14276 | return; | |
14277 | ||
14278 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
14279 | free_cached_comp_units (NULL); | |
14280 | ||
9291a0cd TT |
14281 | if (dwarf2_per_objfile->using_index) |
14282 | { | |
14283 | int i; | |
14284 | ||
14285 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
14286 | { | |
14287 | int j; | |
e254ef6a DE |
14288 | struct dwarf2_per_cu_data *per_cu = |
14289 | dwarf2_per_objfile->all_comp_units[i]; | |
9291a0cd | 14290 | |
e254ef6a | 14291 | if (!per_cu->v.quick->lines) |
9291a0cd TT |
14292 | continue; |
14293 | ||
e254ef6a | 14294 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 14295 | { |
e254ef6a DE |
14296 | if (per_cu->v.quick->file_names) |
14297 | xfree ((void *) per_cu->v.quick->file_names[j]); | |
14298 | if (per_cu->v.quick->full_names) | |
14299 | xfree ((void *) per_cu->v.quick->full_names[j]); | |
9291a0cd TT |
14300 | } |
14301 | ||
e254ef6a | 14302 | free_line_header (per_cu->v.quick->lines); |
9291a0cd TT |
14303 | } |
14304 | } | |
14305 | ||
fe3e1990 DJ |
14306 | /* Everything else should be on the objfile obstack. */ |
14307 | } | |
14308 | ||
1c379e20 DJ |
14309 | /* A pair of DIE offset and GDB type pointer. We store these |
14310 | in a hash table separate from the DIEs, and preserve them | |
14311 | when the DIEs are flushed out of cache. */ | |
14312 | ||
14313 | struct dwarf2_offset_and_type | |
14314 | { | |
14315 | unsigned int offset; | |
14316 | struct type *type; | |
14317 | }; | |
14318 | ||
14319 | /* Hash function for a dwarf2_offset_and_type. */ | |
14320 | ||
14321 | static hashval_t | |
14322 | offset_and_type_hash (const void *item) | |
14323 | { | |
14324 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 14325 | |
1c379e20 DJ |
14326 | return ofs->offset; |
14327 | } | |
14328 | ||
14329 | /* Equality function for a dwarf2_offset_and_type. */ | |
14330 | ||
14331 | static int | |
14332 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
14333 | { | |
14334 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
14335 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 14336 | |
1c379e20 DJ |
14337 | return ofs_lhs->offset == ofs_rhs->offset; |
14338 | } | |
14339 | ||
14340 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
14341 | table if necessary. For convenience, return TYPE. |
14342 | ||
14343 | The DIEs reading must have careful ordering to: | |
14344 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
14345 | reading current DIE. | |
14346 | * Not trying to dereference contents of still incompletely read in types | |
14347 | while reading in other DIEs. | |
14348 | * Enable referencing still incompletely read in types just by a pointer to | |
14349 | the type without accessing its fields. | |
14350 | ||
14351 | Therefore caller should follow these rules: | |
14352 | * Try to fetch any prerequisite types we may need to build this DIE type | |
14353 | before building the type and calling set_die_type. | |
e71ec853 | 14354 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
14355 | possible before fetching more types to complete the current type. |
14356 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 14357 | |
f792889a | 14358 | static struct type * |
1c379e20 DJ |
14359 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
14360 | { | |
14361 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
14362 | struct objfile *objfile = cu->objfile; |
14363 | htab_t *type_hash_ptr; | |
1c379e20 | 14364 | |
b4ba55a1 JB |
14365 | /* For Ada types, make sure that the gnat-specific data is always |
14366 | initialized (if not already set). There are a few types where | |
14367 | we should not be doing so, because the type-specific area is | |
14368 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
14369 | where the type-specific area is used to store the floatformat). | |
14370 | But this is not a problem, because the gnat-specific information | |
14371 | is actually not needed for these types. */ | |
14372 | if (need_gnat_info (cu) | |
14373 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
14374 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
14375 | && !HAVE_GNAT_AUX_INFO (type)) | |
14376 | INIT_GNAT_SPECIFIC (type); | |
14377 | ||
673bfd45 DE |
14378 | if (cu->per_cu->from_debug_types) |
14379 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; | |
14380 | else | |
14381 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
14382 | ||
14383 | if (*type_hash_ptr == NULL) | |
f792889a | 14384 | { |
673bfd45 DE |
14385 | *type_hash_ptr |
14386 | = htab_create_alloc_ex (127, | |
f792889a DJ |
14387 | offset_and_type_hash, |
14388 | offset_and_type_eq, | |
14389 | NULL, | |
673bfd45 | 14390 | &objfile->objfile_obstack, |
f792889a DJ |
14391 | hashtab_obstack_allocate, |
14392 | dummy_obstack_deallocate); | |
f792889a | 14393 | } |
1c379e20 DJ |
14394 | |
14395 | ofs.offset = die->offset; | |
14396 | ofs.type = type; | |
14397 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 14398 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
14399 | if (*slot) |
14400 | complaint (&symfile_complaints, | |
14401 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
14402 | die->offset); | |
673bfd45 | 14403 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 14404 | **slot = ofs; |
f792889a | 14405 | return type; |
1c379e20 DJ |
14406 | } |
14407 | ||
673bfd45 DE |
14408 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
14409 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
14410 | |
14411 | static struct type * | |
673bfd45 DE |
14412 | get_die_type_at_offset (unsigned int offset, |
14413 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
14414 | { |
14415 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 14416 | htab_t type_hash; |
f792889a | 14417 | |
673bfd45 DE |
14418 | if (per_cu->from_debug_types) |
14419 | type_hash = dwarf2_per_objfile->debug_types_type_hash; | |
14420 | else | |
14421 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
14422 | if (type_hash == NULL) |
14423 | return NULL; | |
1c379e20 | 14424 | |
673bfd45 | 14425 | ofs.offset = offset; |
1c379e20 DJ |
14426 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
14427 | if (slot) | |
14428 | return slot->type; | |
14429 | else | |
14430 | return NULL; | |
14431 | } | |
14432 | ||
673bfd45 DE |
14433 | /* Look up the type for DIE in the appropriate type_hash table, |
14434 | or return NULL if DIE does not have a saved type. */ | |
14435 | ||
14436 | static struct type * | |
14437 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
14438 | { | |
14439 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
14440 | } | |
14441 | ||
10b3939b DJ |
14442 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
14443 | ||
14444 | static void | |
14445 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
14446 | struct dwarf2_per_cu_data *ref_per_cu) | |
14447 | { | |
14448 | void **slot; | |
14449 | ||
14450 | if (cu->dependencies == NULL) | |
14451 | cu->dependencies | |
14452 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
14453 | NULL, &cu->comp_unit_obstack, | |
14454 | hashtab_obstack_allocate, | |
14455 | dummy_obstack_deallocate); | |
14456 | ||
14457 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
14458 | if (*slot == NULL) | |
14459 | *slot = ref_per_cu; | |
14460 | } | |
1c379e20 | 14461 | |
f504f079 DE |
14462 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
14463 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
14464 | cache that we must keep because we are keeping CU. */ |
14465 | ||
10b3939b DJ |
14466 | static int |
14467 | dwarf2_mark_helper (void **slot, void *data) | |
14468 | { | |
14469 | struct dwarf2_per_cu_data *per_cu; | |
14470 | ||
14471 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
14472 | if (per_cu->cu->mark) | |
14473 | return 1; | |
14474 | per_cu->cu->mark = 1; | |
14475 | ||
14476 | if (per_cu->cu->dependencies != NULL) | |
14477 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
14478 | ||
14479 | return 1; | |
14480 | } | |
14481 | ||
f504f079 DE |
14482 | /* Set the mark field in CU and in every other compilation unit in the |
14483 | cache that we must keep because we are keeping CU. */ | |
14484 | ||
ae038cb0 DJ |
14485 | static void |
14486 | dwarf2_mark (struct dwarf2_cu *cu) | |
14487 | { | |
14488 | if (cu->mark) | |
14489 | return; | |
14490 | cu->mark = 1; | |
10b3939b DJ |
14491 | if (cu->dependencies != NULL) |
14492 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
14493 | } |
14494 | ||
14495 | static void | |
14496 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
14497 | { | |
14498 | while (per_cu) | |
14499 | { | |
14500 | per_cu->cu->mark = 0; | |
14501 | per_cu = per_cu->cu->read_in_chain; | |
14502 | } | |
72bf9492 DJ |
14503 | } |
14504 | ||
72bf9492 DJ |
14505 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
14506 | is its offset in .debug_info for this objfile. */ | |
14507 | ||
14508 | static hashval_t | |
14509 | partial_die_hash (const void *item) | |
14510 | { | |
14511 | const struct partial_die_info *part_die = item; | |
9a619af0 | 14512 | |
72bf9492 DJ |
14513 | return part_die->offset; |
14514 | } | |
14515 | ||
14516 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
14517 | are equal if they have the same offset. */ | |
14518 | ||
14519 | static int | |
14520 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
14521 | { | |
14522 | const struct partial_die_info *part_die_lhs = item_lhs; | |
14523 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 14524 | |
72bf9492 DJ |
14525 | return part_die_lhs->offset == part_die_rhs->offset; |
14526 | } | |
14527 | ||
ae038cb0 DJ |
14528 | static struct cmd_list_element *set_dwarf2_cmdlist; |
14529 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
14530 | ||
14531 | static void | |
14532 | set_dwarf2_cmd (char *args, int from_tty) | |
14533 | { | |
14534 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
14535 | } | |
14536 | ||
14537 | static void | |
14538 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 14539 | { |
ae038cb0 DJ |
14540 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
14541 | } | |
14542 | ||
dce234bc PP |
14543 | /* If section described by INFO was mmapped, munmap it now. */ |
14544 | ||
14545 | static void | |
14546 | munmap_section_buffer (struct dwarf2_section_info *info) | |
14547 | { | |
14548 | if (info->was_mmapped) | |
14549 | { | |
14550 | #ifdef HAVE_MMAP | |
14551 | intptr_t begin = (intptr_t) info->buffer; | |
14552 | intptr_t map_begin = begin & ~(pagesize - 1); | |
14553 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 14554 | |
dce234bc PP |
14555 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
14556 | #else | |
14557 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 14558 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
14559 | #endif |
14560 | } | |
14561 | } | |
14562 | ||
14563 | /* munmap debug sections for OBJFILE, if necessary. */ | |
14564 | ||
14565 | static void | |
c1bd65d0 | 14566 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
14567 | { |
14568 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 14569 | |
16be1145 DE |
14570 | /* This is sorted according to the order they're defined in to make it easier |
14571 | to keep in sync. */ | |
dce234bc PP |
14572 | munmap_section_buffer (&data->info); |
14573 | munmap_section_buffer (&data->abbrev); | |
14574 | munmap_section_buffer (&data->line); | |
16be1145 | 14575 | munmap_section_buffer (&data->loc); |
dce234bc | 14576 | munmap_section_buffer (&data->macinfo); |
16be1145 | 14577 | munmap_section_buffer (&data->str); |
dce234bc | 14578 | munmap_section_buffer (&data->ranges); |
16be1145 | 14579 | munmap_section_buffer (&data->types); |
dce234bc PP |
14580 | munmap_section_buffer (&data->frame); |
14581 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
14582 | munmap_section_buffer (&data->gdb_index); |
14583 | } | |
14584 | ||
14585 | \f | |
14586 | ||
14587 | /* The contents of the hash table we create when building the string | |
14588 | table. */ | |
14589 | struct strtab_entry | |
14590 | { | |
14591 | offset_type offset; | |
14592 | const char *str; | |
14593 | }; | |
14594 | ||
14595 | /* Hash function for a strtab_entry. */ | |
14596 | static hashval_t | |
14597 | hash_strtab_entry (const void *e) | |
14598 | { | |
14599 | const struct strtab_entry *entry = e; | |
14600 | return mapped_index_string_hash (entry->str); | |
14601 | } | |
14602 | ||
14603 | /* Equality function for a strtab_entry. */ | |
14604 | static int | |
14605 | eq_strtab_entry (const void *a, const void *b) | |
14606 | { | |
14607 | const struct strtab_entry *ea = a; | |
14608 | const struct strtab_entry *eb = b; | |
14609 | return !strcmp (ea->str, eb->str); | |
14610 | } | |
14611 | ||
14612 | /* Create a strtab_entry hash table. */ | |
14613 | static htab_t | |
14614 | create_strtab (void) | |
14615 | { | |
14616 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
14617 | xfree, xcalloc, xfree); | |
14618 | } | |
14619 | ||
14620 | /* Add a string to the constant pool. Return the string's offset in | |
14621 | host order. */ | |
14622 | static offset_type | |
14623 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
14624 | { | |
14625 | void **slot; | |
14626 | struct strtab_entry entry; | |
14627 | struct strtab_entry *result; | |
14628 | ||
14629 | entry.str = str; | |
14630 | slot = htab_find_slot (table, &entry, INSERT); | |
14631 | if (*slot) | |
14632 | result = *slot; | |
14633 | else | |
14634 | { | |
14635 | result = XNEW (struct strtab_entry); | |
14636 | result->offset = obstack_object_size (cpool); | |
14637 | result->str = str; | |
14638 | obstack_grow_str0 (cpool, str); | |
14639 | *slot = result; | |
14640 | } | |
14641 | return result->offset; | |
14642 | } | |
14643 | ||
14644 | /* An entry in the symbol table. */ | |
14645 | struct symtab_index_entry | |
14646 | { | |
14647 | /* The name of the symbol. */ | |
14648 | const char *name; | |
14649 | /* The offset of the name in the constant pool. */ | |
14650 | offset_type index_offset; | |
14651 | /* A sorted vector of the indices of all the CUs that hold an object | |
14652 | of this name. */ | |
14653 | VEC (offset_type) *cu_indices; | |
14654 | }; | |
14655 | ||
14656 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
14657 | struct mapped_symtab | |
14658 | { | |
14659 | offset_type n_elements; | |
14660 | offset_type size; | |
14661 | struct symtab_index_entry **data; | |
14662 | }; | |
14663 | ||
14664 | /* Hash function for a symtab_index_entry. */ | |
14665 | static hashval_t | |
14666 | hash_symtab_entry (const void *e) | |
14667 | { | |
14668 | const struct symtab_index_entry *entry = e; | |
14669 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
14670 | sizeof (offset_type) * VEC_length (offset_type, | |
14671 | entry->cu_indices), | |
14672 | 0); | |
14673 | } | |
14674 | ||
14675 | /* Equality function for a symtab_index_entry. */ | |
14676 | static int | |
14677 | eq_symtab_entry (const void *a, const void *b) | |
14678 | { | |
14679 | const struct symtab_index_entry *ea = a; | |
14680 | const struct symtab_index_entry *eb = b; | |
14681 | int len = VEC_length (offset_type, ea->cu_indices); | |
14682 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
14683 | return 0; | |
14684 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
14685 | VEC_address (offset_type, eb->cu_indices), | |
14686 | sizeof (offset_type) * len); | |
14687 | } | |
14688 | ||
14689 | /* Destroy a symtab_index_entry. */ | |
14690 | static void | |
14691 | delete_symtab_entry (void *p) | |
14692 | { | |
14693 | struct symtab_index_entry *entry = p; | |
14694 | VEC_free (offset_type, entry->cu_indices); | |
14695 | xfree (entry); | |
14696 | } | |
14697 | ||
14698 | /* Create a hash table holding symtab_index_entry objects. */ | |
14699 | static htab_t | |
14700 | create_index_table (void) | |
14701 | { | |
14702 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
14703 | delete_symtab_entry, xcalloc, xfree); | |
14704 | } | |
14705 | ||
14706 | /* Create a new mapped symtab object. */ | |
14707 | static struct mapped_symtab * | |
14708 | create_mapped_symtab (void) | |
14709 | { | |
14710 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
14711 | symtab->n_elements = 0; | |
14712 | symtab->size = 1024; | |
14713 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
14714 | return symtab; | |
14715 | } | |
14716 | ||
14717 | /* Destroy a mapped_symtab. */ | |
14718 | static void | |
14719 | cleanup_mapped_symtab (void *p) | |
14720 | { | |
14721 | struct mapped_symtab *symtab = p; | |
14722 | /* The contents of the array are freed when the other hash table is | |
14723 | destroyed. */ | |
14724 | xfree (symtab->data); | |
14725 | xfree (symtab); | |
14726 | } | |
14727 | ||
14728 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
14729 | the slot. */ | |
14730 | static struct symtab_index_entry ** | |
14731 | find_slot (struct mapped_symtab *symtab, const char *name) | |
14732 | { | |
14733 | offset_type index, step, hash = mapped_index_string_hash (name); | |
14734 | ||
14735 | index = hash & (symtab->size - 1); | |
14736 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
14737 | ||
14738 | for (;;) | |
14739 | { | |
14740 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
14741 | return &symtab->data[index]; | |
14742 | index = (index + step) & (symtab->size - 1); | |
14743 | } | |
14744 | } | |
14745 | ||
14746 | /* Expand SYMTAB's hash table. */ | |
14747 | static void | |
14748 | hash_expand (struct mapped_symtab *symtab) | |
14749 | { | |
14750 | offset_type old_size = symtab->size; | |
14751 | offset_type i; | |
14752 | struct symtab_index_entry **old_entries = symtab->data; | |
14753 | ||
14754 | symtab->size *= 2; | |
14755 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
14756 | ||
14757 | for (i = 0; i < old_size; ++i) | |
14758 | { | |
14759 | if (old_entries[i]) | |
14760 | { | |
14761 | struct symtab_index_entry **slot = find_slot (symtab, | |
14762 | old_entries[i]->name); | |
14763 | *slot = old_entries[i]; | |
14764 | } | |
14765 | } | |
14766 | ||
14767 | xfree (old_entries); | |
14768 | } | |
14769 | ||
14770 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
14771 | is the index of the CU in which the symbol appears. */ | |
14772 | static void | |
14773 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
14774 | offset_type cu_index) | |
14775 | { | |
14776 | struct symtab_index_entry **slot; | |
14777 | ||
14778 | ++symtab->n_elements; | |
14779 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
14780 | hash_expand (symtab); | |
14781 | ||
14782 | slot = find_slot (symtab, name); | |
14783 | if (!*slot) | |
14784 | { | |
14785 | *slot = XNEW (struct symtab_index_entry); | |
14786 | (*slot)->name = name; | |
14787 | (*slot)->cu_indices = NULL; | |
14788 | } | |
14789 | /* Don't push an index twice. Due to how we add entries we only | |
14790 | have to check the last one. */ | |
14791 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
14792 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) | |
14793 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); | |
14794 | } | |
14795 | ||
14796 | /* Add a vector of indices to the constant pool. */ | |
14797 | static offset_type | |
14798 | add_indices_to_cpool (htab_t index_table, struct obstack *cpool, | |
14799 | struct symtab_index_entry *entry) | |
14800 | { | |
14801 | void **slot; | |
14802 | ||
14803 | slot = htab_find_slot (index_table, entry, INSERT); | |
14804 | if (!*slot) | |
14805 | { | |
14806 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
14807 | offset_type val = MAYBE_SWAP (len); | |
14808 | offset_type iter; | |
14809 | int i; | |
14810 | ||
14811 | *slot = entry; | |
14812 | entry->index_offset = obstack_object_size (cpool); | |
14813 | ||
14814 | obstack_grow (cpool, &val, sizeof (val)); | |
14815 | for (i = 0; | |
14816 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
14817 | ++i) | |
14818 | { | |
14819 | val = MAYBE_SWAP (iter); | |
14820 | obstack_grow (cpool, &val, sizeof (val)); | |
14821 | } | |
14822 | } | |
14823 | else | |
14824 | { | |
14825 | struct symtab_index_entry *old_entry = *slot; | |
14826 | entry->index_offset = old_entry->index_offset; | |
14827 | entry = old_entry; | |
14828 | } | |
14829 | return entry->index_offset; | |
14830 | } | |
14831 | ||
14832 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
14833 | constant pool entries going into the obstack CPOOL. */ | |
14834 | static void | |
14835 | write_hash_table (struct mapped_symtab *symtab, | |
14836 | struct obstack *output, struct obstack *cpool) | |
14837 | { | |
14838 | offset_type i; | |
14839 | htab_t index_table; | |
14840 | htab_t str_table; | |
14841 | ||
14842 | index_table = create_index_table (); | |
14843 | str_table = create_strtab (); | |
14844 | /* We add all the index vectors to the constant pool first, to | |
14845 | ensure alignment is ok. */ | |
14846 | for (i = 0; i < symtab->size; ++i) | |
14847 | { | |
14848 | if (symtab->data[i]) | |
14849 | add_indices_to_cpool (index_table, cpool, symtab->data[i]); | |
14850 | } | |
14851 | ||
14852 | /* Now write out the hash table. */ | |
14853 | for (i = 0; i < symtab->size; ++i) | |
14854 | { | |
14855 | offset_type str_off, vec_off; | |
14856 | ||
14857 | if (symtab->data[i]) | |
14858 | { | |
14859 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
14860 | vec_off = symtab->data[i]->index_offset; | |
14861 | } | |
14862 | else | |
14863 | { | |
14864 | /* While 0 is a valid constant pool index, it is not valid | |
14865 | to have 0 for both offsets. */ | |
14866 | str_off = 0; | |
14867 | vec_off = 0; | |
14868 | } | |
14869 | ||
14870 | str_off = MAYBE_SWAP (str_off); | |
14871 | vec_off = MAYBE_SWAP (vec_off); | |
14872 | ||
14873 | obstack_grow (output, &str_off, sizeof (str_off)); | |
14874 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
14875 | } | |
14876 | ||
14877 | htab_delete (str_table); | |
14878 | htab_delete (index_table); | |
14879 | } | |
14880 | ||
14881 | /* Write an address entry to ADDR_OBSTACK. The addresses are taken | |
14882 | from PST; CU_INDEX is the index of the CU in the vector of all | |
14883 | CUs. */ | |
14884 | static void | |
14885 | add_address_entry (struct objfile *objfile, | |
14886 | struct obstack *addr_obstack, struct partial_symtab *pst, | |
14887 | unsigned int cu_index) | |
14888 | { | |
14889 | offset_type offset; | |
14890 | char addr[8]; | |
14891 | CORE_ADDR baseaddr; | |
14892 | ||
1fd400ff TT |
14893 | /* Don't bother recording empty ranges. */ |
14894 | if (pst->textlow == pst->texthigh) | |
14895 | return; | |
14896 | ||
9291a0cd TT |
14897 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
14898 | ||
14899 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr); | |
14900 | obstack_grow (addr_obstack, addr, 8); | |
14901 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr); | |
14902 | obstack_grow (addr_obstack, addr, 8); | |
14903 | offset = MAYBE_SWAP (cu_index); | |
14904 | obstack_grow (addr_obstack, &offset, sizeof (offset_type)); | |
14905 | } | |
14906 | ||
14907 | /* Add a list of partial symbols to SYMTAB. */ | |
14908 | static void | |
14909 | write_psymbols (struct mapped_symtab *symtab, | |
14910 | struct partial_symbol **psymp, | |
14911 | int count, | |
14912 | offset_type cu_index) | |
14913 | { | |
14914 | for (; count-- > 0; ++psymp) | |
14915 | { | |
14916 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) | |
14917 | error (_("Ada is not currently supported by the index")); | |
14918 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
14919 | } | |
14920 | } | |
14921 | ||
14922 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
14923 | exception if there is an error. */ | |
14924 | static void | |
14925 | write_obstack (FILE *file, struct obstack *obstack) | |
14926 | { | |
14927 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
14928 | file) | |
14929 | != obstack_object_size (obstack)) | |
14930 | error (_("couldn't data write to file")); | |
14931 | } | |
14932 | ||
14933 | /* Unlink a file if the argument is not NULL. */ | |
14934 | static void | |
14935 | unlink_if_set (void *p) | |
14936 | { | |
14937 | char **filename = p; | |
14938 | if (*filename) | |
14939 | unlink (*filename); | |
14940 | } | |
14941 | ||
1fd400ff TT |
14942 | /* A helper struct used when iterating over debug_types. */ |
14943 | struct signatured_type_index_data | |
14944 | { | |
14945 | struct objfile *objfile; | |
14946 | struct mapped_symtab *symtab; | |
14947 | struct obstack *types_list; | |
14948 | int cu_index; | |
14949 | }; | |
14950 | ||
14951 | /* A helper function that writes a single signatured_type to an | |
14952 | obstack. */ | |
14953 | static int | |
14954 | write_one_signatured_type (void **slot, void *d) | |
14955 | { | |
14956 | struct signatured_type_index_data *info = d; | |
14957 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
14958 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
14959 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
14960 | gdb_byte val[8]; |
14961 | ||
14962 | write_psymbols (info->symtab, | |
14963 | info->objfile->global_psymbols.list + psymtab->globals_offset, | |
14964 | psymtab->n_global_syms, info->cu_index); | |
14965 | write_psymbols (info->symtab, | |
14966 | info->objfile->static_psymbols.list + psymtab->statics_offset, | |
14967 | psymtab->n_static_syms, info->cu_index); | |
14968 | ||
14969 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset); | |
14970 | obstack_grow (info->types_list, val, 8); | |
14971 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
14972 | obstack_grow (info->types_list, val, 8); | |
14973 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
14974 | obstack_grow (info->types_list, val, 8); | |
14975 | ||
14976 | ++info->cu_index; | |
14977 | ||
14978 | return 1; | |
14979 | } | |
14980 | ||
9291a0cd TT |
14981 | /* Create an index file for OBJFILE in the directory DIR. */ |
14982 | static void | |
14983 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
14984 | { | |
14985 | struct cleanup *cleanup; | |
14986 | char *filename, *cleanup_filename; | |
1fd400ff TT |
14987 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
14988 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
14989 | int i; |
14990 | FILE *out_file; | |
14991 | struct mapped_symtab *symtab; | |
14992 | offset_type val, size_of_contents, total_len; | |
14993 | struct stat st; | |
14994 | char buf[8]; | |
14995 | ||
14996 | if (!objfile->psymtabs) | |
14997 | return; | |
14998 | if (dwarf2_per_objfile->using_index) | |
14999 | error (_("Cannot use an index to create the index")); | |
15000 | ||
15001 | if (stat (objfile->name, &st) < 0) | |
15002 | perror_with_name (_("Could not stat")); | |
15003 | ||
15004 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
15005 | INDEX_SUFFIX, (char *) NULL); | |
15006 | cleanup = make_cleanup (xfree, filename); | |
15007 | ||
15008 | out_file = fopen (filename, "wb"); | |
15009 | if (!out_file) | |
15010 | error (_("Can't open `%s' for writing"), filename); | |
15011 | ||
15012 | cleanup_filename = filename; | |
15013 | make_cleanup (unlink_if_set, &cleanup_filename); | |
15014 | ||
15015 | symtab = create_mapped_symtab (); | |
15016 | make_cleanup (cleanup_mapped_symtab, symtab); | |
15017 | ||
15018 | obstack_init (&addr_obstack); | |
15019 | make_cleanup_obstack_free (&addr_obstack); | |
15020 | ||
15021 | obstack_init (&cu_list); | |
15022 | make_cleanup_obstack_free (&cu_list); | |
15023 | ||
1fd400ff TT |
15024 | obstack_init (&types_cu_list); |
15025 | make_cleanup_obstack_free (&types_cu_list); | |
15026 | ||
15027 | /* The list is already sorted, so we don't need to do additional | |
15028 | work here. Also, the debug_types entries do not appear in | |
15029 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
15030 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
15031 | { | |
e254ef6a DE |
15032 | struct dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i]; |
15033 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
9291a0cd TT |
15034 | gdb_byte val[8]; |
15035 | ||
15036 | write_psymbols (symtab, | |
15037 | objfile->global_psymbols.list + psymtab->globals_offset, | |
15038 | psymtab->n_global_syms, i); | |
15039 | write_psymbols (symtab, | |
15040 | objfile->static_psymbols.list + psymtab->statics_offset, | |
15041 | psymtab->n_static_syms, i); | |
15042 | ||
15043 | add_address_entry (objfile, &addr_obstack, psymtab, i); | |
15044 | ||
e254ef6a | 15045 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 15046 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 15047 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
15048 | obstack_grow (&cu_list, val, 8); |
15049 | } | |
15050 | ||
1fd400ff TT |
15051 | /* Write out the .debug_type entries, if any. */ |
15052 | if (dwarf2_per_objfile->signatured_types) | |
15053 | { | |
15054 | struct signatured_type_index_data sig_data; | |
15055 | ||
15056 | sig_data.objfile = objfile; | |
15057 | sig_data.symtab = symtab; | |
15058 | sig_data.types_list = &types_cu_list; | |
15059 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; | |
15060 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
15061 | write_one_signatured_type, &sig_data); | |
15062 | } | |
15063 | ||
9291a0cd TT |
15064 | obstack_init (&constant_pool); |
15065 | make_cleanup_obstack_free (&constant_pool); | |
15066 | obstack_init (&symtab_obstack); | |
15067 | make_cleanup_obstack_free (&symtab_obstack); | |
15068 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
15069 | ||
15070 | obstack_init (&contents); | |
15071 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 15072 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
15073 | total_len = size_of_contents; |
15074 | ||
15075 | /* The version number. */ | |
1fd400ff | 15076 | val = MAYBE_SWAP (2); |
9291a0cd TT |
15077 | obstack_grow (&contents, &val, sizeof (val)); |
15078 | ||
15079 | /* The offset of the CU list from the start of the file. */ | |
15080 | val = MAYBE_SWAP (total_len); | |
15081 | obstack_grow (&contents, &val, sizeof (val)); | |
15082 | total_len += obstack_object_size (&cu_list); | |
15083 | ||
1fd400ff TT |
15084 | /* The offset of the types CU list from the start of the file. */ |
15085 | val = MAYBE_SWAP (total_len); | |
15086 | obstack_grow (&contents, &val, sizeof (val)); | |
15087 | total_len += obstack_object_size (&types_cu_list); | |
15088 | ||
9291a0cd TT |
15089 | /* The offset of the address table from the start of the file. */ |
15090 | val = MAYBE_SWAP (total_len); | |
15091 | obstack_grow (&contents, &val, sizeof (val)); | |
15092 | total_len += obstack_object_size (&addr_obstack); | |
15093 | ||
15094 | /* The offset of the symbol table from the start of the file. */ | |
15095 | val = MAYBE_SWAP (total_len); | |
15096 | obstack_grow (&contents, &val, sizeof (val)); | |
15097 | total_len += obstack_object_size (&symtab_obstack); | |
15098 | ||
15099 | /* The offset of the constant pool from the start of the file. */ | |
15100 | val = MAYBE_SWAP (total_len); | |
15101 | obstack_grow (&contents, &val, sizeof (val)); | |
15102 | total_len += obstack_object_size (&constant_pool); | |
15103 | ||
15104 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
15105 | ||
15106 | write_obstack (out_file, &contents); | |
15107 | write_obstack (out_file, &cu_list); | |
1fd400ff | 15108 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
15109 | write_obstack (out_file, &addr_obstack); |
15110 | write_obstack (out_file, &symtab_obstack); | |
15111 | write_obstack (out_file, &constant_pool); | |
15112 | ||
15113 | fclose (out_file); | |
15114 | ||
15115 | /* We want to keep the file, so we set cleanup_filename to NULL | |
15116 | here. See unlink_if_set. */ | |
15117 | cleanup_filename = NULL; | |
15118 | ||
15119 | do_cleanups (cleanup); | |
15120 | } | |
15121 | ||
15122 | /* The mapped index file format is designed to be directly mmap()able | |
15123 | on any architecture. In most cases, a datum is represented using a | |
15124 | little-endian 32-bit integer value, called an offset_type. Big | |
15125 | endian machines must byte-swap the values before using them. | |
15126 | Exceptions to this rule are noted. The data is laid out such that | |
15127 | alignment is always respected. | |
15128 | ||
15129 | A mapped index consists of several sections. | |
15130 | ||
15131 | 1. The file header. This is a sequence of values, of offset_type | |
15132 | unless otherwise noted: | |
1fd400ff TT |
15133 | [0] The version number. Currently 1 or 2. The differences are |
15134 | noted below. Version 1 did not account for .debug_types sections; | |
15135 | the presence of a .debug_types section invalidates any version 1 | |
15136 | index that may exist. | |
9291a0cd | 15137 | [1] The offset, from the start of the file, of the CU list. |
1fd400ff TT |
15138 | [1.5] In version 2, the offset, from the start of the file, of the |
15139 | types CU list. This offset does not appear in version 1. Note | |
15140 | that this can be empty, in which case this offset will be equal to | |
15141 | the next offset. | |
9291a0cd TT |
15142 | [2] The offset, from the start of the file, of the address section. |
15143 | [3] The offset, from the start of the file, of the symbol table. | |
15144 | [4] The offset, from the start of the file, of the constant pool. | |
15145 | ||
15146 | 2. The CU list. This is a sequence of pairs of 64-bit | |
1fd400ff TT |
15147 | little-endian values, sorted by the CU offset. The first element |
15148 | in each pair is the offset of a CU in the .debug_info section. The | |
15149 | second element in each pair is the length of that CU. References | |
15150 | to a CU elsewhere in the map are done using a CU index, which is | |
15151 | just the 0-based index into this table. Note that if there are | |
15152 | type CUs, then conceptually CUs and type CUs form a single list for | |
15153 | the purposes of CU indices. | |
15154 | ||
15155 | 2.5 The types CU list. This does not appear in a version 1 index. | |
15156 | This is a sequence of triplets of 64-bit little-endian values. In | |
15157 | a triplet, the first value is the CU offset, the second value is | |
15158 | the type offset in the CU, and the third value is the type | |
15159 | signature. The types CU list is not sorted. | |
9291a0cd TT |
15160 | |
15161 | 3. The address section. The address section consists of a sequence | |
15162 | of address entries. Each address entry has three elements. | |
15163 | [0] The low address. This is a 64-bit little-endian value. | |
15164 | [1] The high address. This is a 64-bit little-endian value. | |
15165 | [2] The CU index. This is an offset_type value. | |
15166 | ||
15167 | 4. The symbol table. This is a hash table. The size of the hash | |
15168 | table is always a power of 2. The initial hash and the step are | |
15169 | currently defined by the `find_slot' function. | |
15170 | ||
15171 | Each slot in the hash table consists of a pair of offset_type | |
15172 | values. The first value is the offset of the symbol's name in the | |
15173 | constant pool. The second value is the offset of the CU vector in | |
15174 | the constant pool. | |
15175 | ||
15176 | If both values are 0, then this slot in the hash table is empty. | |
15177 | This is ok because while 0 is a valid constant pool index, it | |
15178 | cannot be a valid index for both a string and a CU vector. | |
15179 | ||
15180 | A string in the constant pool is stored as a \0-terminated string, | |
15181 | as you'd expect. | |
15182 | ||
15183 | A CU vector in the constant pool is a sequence of offset_type | |
15184 | values. The first value is the number of CU indices in the vector. | |
15185 | Each subsequent value is the index of a CU in the CU list. This | |
15186 | element in the hash table is used to indicate which CUs define the | |
15187 | symbol. | |
15188 | ||
15189 | 5. The constant pool. This is simply a bunch of bytes. It is | |
15190 | organized so that alignment is correct: CU vectors are stored | |
15191 | first, followed by strings. */ | |
15192 | static void | |
15193 | save_gdb_index_command (char *arg, int from_tty) | |
15194 | { | |
15195 | struct objfile *objfile; | |
15196 | ||
15197 | if (!arg || !*arg) | |
96d19272 | 15198 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
15199 | |
15200 | ALL_OBJFILES (objfile) | |
15201 | { | |
15202 | struct stat st; | |
15203 | ||
15204 | /* If the objfile does not correspond to an actual file, skip it. */ | |
15205 | if (stat (objfile->name, &st) < 0) | |
15206 | continue; | |
15207 | ||
15208 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15209 | if (dwarf2_per_objfile) | |
15210 | { | |
15211 | volatile struct gdb_exception except; | |
15212 | ||
15213 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
15214 | { | |
15215 | write_psymtabs_to_index (objfile, arg); | |
15216 | } | |
15217 | if (except.reason < 0) | |
15218 | exception_fprintf (gdb_stderr, except, | |
15219 | _("Error while writing index for `%s': "), | |
15220 | objfile->name); | |
15221 | } | |
15222 | } | |
dce234bc PP |
15223 | } |
15224 | ||
9291a0cd TT |
15225 | \f |
15226 | ||
9eae7c52 TT |
15227 | int dwarf2_always_disassemble; |
15228 | ||
15229 | static void | |
15230 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
15231 | struct cmd_list_element *c, const char *value) | |
15232 | { | |
15233 | fprintf_filtered (file, _("\ | |
15234 | Whether to always disassemble DWARF expressions is %s.\n"), | |
15235 | value); | |
15236 | } | |
15237 | ||
6502dd73 DJ |
15238 | void _initialize_dwarf2_read (void); |
15239 | ||
15240 | void | |
15241 | _initialize_dwarf2_read (void) | |
15242 | { | |
96d19272 JK |
15243 | struct cmd_list_element *c; |
15244 | ||
dce234bc | 15245 | dwarf2_objfile_data_key |
c1bd65d0 | 15246 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 15247 | |
1bedd215 AC |
15248 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
15249 | Set DWARF 2 specific variables.\n\ | |
15250 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
15251 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
15252 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
15253 | ||
1bedd215 AC |
15254 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
15255 | Show DWARF 2 specific variables\n\ | |
15256 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
15257 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
15258 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
15259 | ||
15260 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
15261 | &dwarf2_max_cache_age, _("\ |
15262 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
15263 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
15264 | A higher limit means that cached compilation units will be stored\n\ | |
15265 | in memory longer, and more total memory will be used. Zero disables\n\ | |
15266 | caching, which can slow down startup."), | |
2c5b56ce | 15267 | NULL, |
920d2a44 | 15268 | show_dwarf2_max_cache_age, |
2c5b56ce | 15269 | &set_dwarf2_cmdlist, |
ae038cb0 | 15270 | &show_dwarf2_cmdlist); |
d97bc12b | 15271 | |
9eae7c52 TT |
15272 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
15273 | &dwarf2_always_disassemble, _("\ | |
15274 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
15275 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
15276 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
15277 | syntax. When disabled, expressions will be printed in a more\n\ | |
15278 | conversational style, when possible."), | |
15279 | NULL, | |
15280 | show_dwarf2_always_disassemble, | |
15281 | &set_dwarf2_cmdlist, | |
15282 | &show_dwarf2_cmdlist); | |
15283 | ||
d97bc12b DE |
15284 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
15285 | Set debugging of the dwarf2 DIE reader."), _("\ | |
15286 | Show debugging of the dwarf2 DIE reader."), _("\ | |
15287 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
15288 | The value is the maximum depth to print."), | |
15289 | NULL, | |
15290 | NULL, | |
15291 | &setdebuglist, &showdebuglist); | |
9291a0cd | 15292 | |
96d19272 JK |
15293 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
15294 | _("Save a .gdb-index file"), | |
15295 | &save_cmdlist); | |
15296 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 15297 | } |