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; | |
1907 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); | |
1908 | ||
1909 | addr = dwarf2_per_objfile->gdb_index.buffer; | |
1910 | /* Version check. */ | |
1fd400ff TT |
1911 | version = MAYBE_SWAP (*(offset_type *) addr); |
1912 | if (version == 1) | |
1913 | { | |
1914 | /* Index version 1 neglected to account for .debug_types. So, | |
1915 | if we see .debug_types, we cannot use this index. */ | |
1916 | if (dwarf2_per_objfile->types.asection != NULL | |
1917 | && dwarf2_per_objfile->types.size != 0) | |
1918 | return 0; | |
1919 | } | |
1920 | else if (version != 2) | |
9291a0cd TT |
1921 | return 0; |
1922 | ||
1923 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); | |
b3b272e1 | 1924 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
9291a0cd TT |
1925 | |
1926 | metadata = (offset_type *) (addr + sizeof (offset_type)); | |
1fd400ff TT |
1927 | |
1928 | i = 0; | |
1929 | cu_list = addr + MAYBE_SWAP (metadata[i]); | |
1930 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 1931 | / 8); |
1fd400ff TT |
1932 | ++i; |
1933 | ||
1934 | if (version == 2) | |
1935 | { | |
1936 | types_list = addr + MAYBE_SWAP (metadata[i]); | |
1937 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) | |
1938 | - MAYBE_SWAP (metadata[i])) | |
1939 | / 8); | |
1940 | ++i; | |
1941 | } | |
1942 | ||
1943 | map->address_table = addr + MAYBE_SWAP (metadata[i]); | |
1944 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) | |
1945 | - MAYBE_SWAP (metadata[i])); | |
1946 | ++i; | |
1947 | ||
1948 | map->index_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); | |
1949 | map->index_table_slots = ((MAYBE_SWAP (metadata[i + 1]) | |
1950 | - MAYBE_SWAP (metadata[i])) | |
9291a0cd | 1951 | / (2 * sizeof (offset_type))); |
1fd400ff | 1952 | ++i; |
9291a0cd | 1953 | |
1fd400ff TT |
1954 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
1955 | ||
1956 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) | |
1957 | return 0; | |
1958 | ||
1959 | if (version == 2 | |
1960 | && types_list_elements | |
673bfd45 DE |
1961 | && !create_signatured_type_table_from_index (objfile, types_list, |
1962 | types_list_elements)) | |
9291a0cd TT |
1963 | return 0; |
1964 | ||
1965 | create_addrmap_from_index (objfile, map); | |
1966 | ||
1967 | dwarf2_per_objfile->index_table = map; | |
1968 | dwarf2_per_objfile->using_index = 1; | |
1969 | ||
1970 | return 1; | |
1971 | } | |
1972 | ||
1973 | /* A helper for the "quick" functions which sets the global | |
1974 | dwarf2_per_objfile according to OBJFILE. */ | |
1975 | static void | |
1976 | dw2_setup (struct objfile *objfile) | |
1977 | { | |
1978 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
1979 | gdb_assert (dwarf2_per_objfile); | |
1980 | } | |
1981 | ||
1982 | /* A helper for the "quick" functions which attempts to read the line | |
1983 | table for THIS_CU. */ | |
1984 | static void | |
1985 | dw2_require_line_header (struct objfile *objfile, | |
1986 | struct dwarf2_per_cu_data *this_cu) | |
1987 | { | |
1988 | bfd *abfd = objfile->obfd; | |
1989 | struct line_header *lh = NULL; | |
1990 | struct attribute *attr; | |
1991 | struct cleanup *cleanups; | |
1992 | struct die_info *comp_unit_die; | |
36374493 | 1993 | struct dwarf2_section_info* sec; |
9291a0cd TT |
1994 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; |
1995 | int has_children, i; | |
1996 | struct dwarf2_cu cu; | |
1997 | unsigned int bytes_read, buffer_size; | |
1998 | struct die_reader_specs reader_specs; | |
1999 | char *name, *comp_dir; | |
2000 | ||
2001 | if (this_cu->v.quick->read_lines) | |
2002 | return; | |
2003 | this_cu->v.quick->read_lines = 1; | |
2004 | ||
2005 | memset (&cu, 0, sizeof (cu)); | |
2006 | cu.objfile = objfile; | |
2007 | obstack_init (&cu.comp_unit_obstack); | |
2008 | ||
2009 | cleanups = make_cleanup (free_stack_comp_unit, &cu); | |
2010 | ||
36374493 DE |
2011 | if (this_cu->from_debug_types) |
2012 | sec = &dwarf2_per_objfile->types; | |
2013 | else | |
2014 | sec = &dwarf2_per_objfile->info; | |
2015 | dwarf2_read_section (objfile, sec); | |
2016 | buffer_size = sec->size; | |
2017 | buffer = sec->buffer; | |
9291a0cd TT |
2018 | info_ptr = buffer + this_cu->offset; |
2019 | beg_of_comp_unit = info_ptr; | |
2020 | ||
2021 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, | |
2022 | buffer, buffer_size, | |
2023 | abfd); | |
2024 | ||
2025 | /* Complete the cu_header. */ | |
2026 | cu.header.offset = beg_of_comp_unit - buffer; | |
2027 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
2028 | ||
2029 | this_cu->cu = &cu; | |
2030 | cu.per_cu = this_cu; | |
2031 | ||
2032 | dwarf2_read_abbrevs (abfd, &cu); | |
2033 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
2034 | ||
2035 | if (this_cu->from_debug_types) | |
2036 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
2037 | init_cu_die_reader (&reader_specs, &cu); | |
2038 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
2039 | &has_children); | |
2040 | ||
2041 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); | |
2042 | if (attr) | |
2043 | { | |
2044 | unsigned int line_offset = DW_UNSND (attr); | |
2045 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); | |
2046 | } | |
2047 | if (lh == NULL) | |
2048 | { | |
2049 | do_cleanups (cleanups); | |
2050 | return; | |
2051 | } | |
2052 | ||
2053 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); | |
2054 | ||
2055 | this_cu->v.quick->lines = lh; | |
2056 | ||
2057 | this_cu->v.quick->file_names | |
2058 | = obstack_alloc (&objfile->objfile_obstack, | |
2059 | lh->num_file_names * sizeof (char *)); | |
2060 | for (i = 0; i < lh->num_file_names; ++i) | |
2061 | this_cu->v.quick->file_names[i] = file_full_name (i + 1, lh, comp_dir); | |
2062 | ||
2063 | do_cleanups (cleanups); | |
2064 | } | |
2065 | ||
2066 | /* A helper for the "quick" functions which computes and caches the | |
2067 | real path for a given file name from the line table. | |
2068 | dw2_require_line_header must have been called before this is | |
2069 | invoked. */ | |
2070 | static const char * | |
2071 | dw2_require_full_path (struct objfile *objfile, | |
e254ef6a | 2072 | struct dwarf2_per_cu_data *per_cu, |
9291a0cd TT |
2073 | int index) |
2074 | { | |
e254ef6a DE |
2075 | if (!per_cu->v.quick->full_names) |
2076 | per_cu->v.quick->full_names | |
9291a0cd | 2077 | = OBSTACK_CALLOC (&objfile->objfile_obstack, |
e254ef6a | 2078 | per_cu->v.quick->lines->num_file_names, |
9291a0cd TT |
2079 | sizeof (char *)); |
2080 | ||
e254ef6a DE |
2081 | if (!per_cu->v.quick->full_names[index]) |
2082 | per_cu->v.quick->full_names[index] | |
2083 | = gdb_realpath (per_cu->v.quick->file_names[index]); | |
9291a0cd | 2084 | |
e254ef6a | 2085 | return per_cu->v.quick->full_names[index]; |
9291a0cd TT |
2086 | } |
2087 | ||
2088 | static struct symtab * | |
2089 | dw2_find_last_source_symtab (struct objfile *objfile) | |
2090 | { | |
2091 | int index; | |
2092 | dw2_setup (objfile); | |
2093 | index = dwarf2_per_objfile->n_comp_units - 1; | |
1fd400ff | 2094 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
9291a0cd TT |
2095 | } |
2096 | ||
2097 | static void | |
2098 | dw2_forget_cached_source_info (struct objfile *objfile) | |
2099 | { | |
2100 | int i; | |
2101 | ||
2102 | dw2_setup (objfile); | |
1fd400ff TT |
2103 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2104 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2105 | { |
e254ef6a | 2106 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2107 | |
e254ef6a | 2108 | if (per_cu->v.quick->full_names) |
9291a0cd TT |
2109 | { |
2110 | int j; | |
2111 | ||
e254ef6a DE |
2112 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
2113 | xfree ((void *) per_cu->v.quick->full_names[j]); | |
9291a0cd TT |
2114 | } |
2115 | } | |
2116 | } | |
2117 | ||
2118 | static int | |
2119 | dw2_lookup_symtab (struct objfile *objfile, const char *name, | |
2120 | const char *full_path, const char *real_path, | |
2121 | struct symtab **result) | |
2122 | { | |
2123 | int i; | |
2124 | int check_basename = lbasename (name) == name; | |
2125 | struct dwarf2_per_cu_data *base_cu = NULL; | |
2126 | ||
2127 | dw2_setup (objfile); | |
1fd400ff TT |
2128 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2129 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2130 | { |
2131 | int j; | |
e254ef6a | 2132 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2133 | |
e254ef6a | 2134 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2135 | continue; |
2136 | ||
e254ef6a DE |
2137 | dw2_require_line_header (objfile, per_cu); |
2138 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2139 | continue; |
2140 | ||
e254ef6a | 2141 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2142 | { |
e254ef6a | 2143 | const char *this_name = per_cu->v.quick->file_names[j]; |
9291a0cd TT |
2144 | |
2145 | if (FILENAME_CMP (name, this_name) == 0) | |
2146 | { | |
e254ef6a | 2147 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2148 | return 1; |
2149 | } | |
2150 | ||
2151 | if (check_basename && ! base_cu | |
2152 | && FILENAME_CMP (lbasename (this_name), name) == 0) | |
e254ef6a | 2153 | base_cu = per_cu; |
9291a0cd TT |
2154 | |
2155 | if (full_path != NULL) | |
2156 | { | |
2157 | const char *this_full_name = dw2_require_full_path (objfile, | |
e254ef6a | 2158 | per_cu, j); |
9291a0cd TT |
2159 | |
2160 | if (this_full_name | |
2161 | && FILENAME_CMP (full_path, this_full_name) == 0) | |
2162 | { | |
e254ef6a | 2163 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2164 | return 1; |
2165 | } | |
2166 | } | |
2167 | ||
2168 | if (real_path != NULL) | |
2169 | { | |
2170 | const char *this_full_name = dw2_require_full_path (objfile, | |
e254ef6a | 2171 | per_cu, j); |
9291a0cd TT |
2172 | |
2173 | if (this_full_name != NULL) | |
2174 | { | |
2175 | char *rp = gdb_realpath (this_full_name); | |
2176 | if (rp != NULL && FILENAME_CMP (real_path, rp) == 0) | |
2177 | { | |
2178 | xfree (rp); | |
e254ef6a | 2179 | *result = dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2180 | return 1; |
2181 | } | |
2182 | xfree (rp); | |
2183 | } | |
2184 | } | |
2185 | } | |
2186 | } | |
2187 | ||
2188 | if (base_cu) | |
2189 | { | |
2190 | *result = dw2_instantiate_symtab (objfile, base_cu); | |
2191 | return 1; | |
2192 | } | |
2193 | ||
2194 | return 0; | |
2195 | } | |
2196 | ||
2197 | static struct symtab * | |
2198 | dw2_lookup_symbol (struct objfile *objfile, int block_index, | |
2199 | const char *name, domain_enum domain) | |
2200 | { | |
774b6a14 | 2201 | /* We do all the work in the pre_expand_symtabs_matching hook |
9291a0cd TT |
2202 | instead. */ |
2203 | return NULL; | |
2204 | } | |
2205 | ||
2206 | /* A helper function that expands all symtabs that hold an object | |
2207 | named NAME. */ | |
2208 | static void | |
2209 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) | |
2210 | { | |
2211 | dw2_setup (objfile); | |
2212 | ||
2213 | if (dwarf2_per_objfile->index_table) | |
2214 | { | |
2215 | offset_type *vec; | |
2216 | ||
2217 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2218 | name, &vec)) | |
2219 | { | |
2220 | offset_type i, len = MAYBE_SWAP (*vec); | |
2221 | for (i = 0; i < len; ++i) | |
2222 | { | |
2223 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); | |
e254ef6a | 2224 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
1fd400ff | 2225 | |
e254ef6a | 2226 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2227 | } |
2228 | } | |
2229 | } | |
2230 | } | |
2231 | ||
774b6a14 TT |
2232 | static void |
2233 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, | |
2234 | int kind, const char *name, | |
2235 | domain_enum domain) | |
9291a0cd | 2236 | { |
774b6a14 | 2237 | dw2_do_expand_symtabs_matching (objfile, name); |
9291a0cd TT |
2238 | } |
2239 | ||
2240 | static void | |
2241 | dw2_print_stats (struct objfile *objfile) | |
2242 | { | |
2243 | int i, count; | |
2244 | ||
2245 | dw2_setup (objfile); | |
2246 | count = 0; | |
1fd400ff TT |
2247 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2248 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2249 | { |
e254ef6a | 2250 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2251 | |
e254ef6a | 2252 | if (!per_cu->v.quick->symtab) |
9291a0cd TT |
2253 | ++count; |
2254 | } | |
2255 | printf_filtered (_(" Number of unread CUs: %d\n"), count); | |
2256 | } | |
2257 | ||
2258 | static void | |
2259 | dw2_dump (struct objfile *objfile) | |
2260 | { | |
2261 | /* Nothing worth printing. */ | |
2262 | } | |
2263 | ||
2264 | static void | |
2265 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, | |
2266 | struct section_offsets *delta) | |
2267 | { | |
2268 | /* There's nothing to relocate here. */ | |
2269 | } | |
2270 | ||
2271 | static void | |
2272 | dw2_expand_symtabs_for_function (struct objfile *objfile, | |
2273 | const char *func_name) | |
2274 | { | |
2275 | dw2_do_expand_symtabs_matching (objfile, func_name); | |
2276 | } | |
2277 | ||
2278 | static void | |
2279 | dw2_expand_all_symtabs (struct objfile *objfile) | |
2280 | { | |
2281 | int i; | |
2282 | ||
2283 | dw2_setup (objfile); | |
1fd400ff TT |
2284 | |
2285 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units | |
2286 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2287 | { |
e254ef6a | 2288 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2289 | |
e254ef6a | 2290 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2291 | } |
2292 | } | |
2293 | ||
2294 | static void | |
2295 | dw2_expand_symtabs_with_filename (struct objfile *objfile, | |
2296 | const char *filename) | |
2297 | { | |
2298 | int i; | |
2299 | ||
2300 | dw2_setup (objfile); | |
1fd400ff TT |
2301 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2302 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2303 | { |
2304 | int j; | |
e254ef6a | 2305 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2306 | |
e254ef6a | 2307 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2308 | continue; |
2309 | ||
e254ef6a DE |
2310 | dw2_require_line_header (objfile, per_cu); |
2311 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2312 | continue; |
2313 | ||
e254ef6a | 2314 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2315 | { |
e254ef6a | 2316 | const char *this_name = per_cu->v.quick->file_names[j]; |
9291a0cd TT |
2317 | if (strcmp (this_name, filename) == 0) |
2318 | { | |
e254ef6a | 2319 | dw2_instantiate_symtab (objfile, per_cu); |
9291a0cd TT |
2320 | break; |
2321 | } | |
2322 | } | |
2323 | } | |
2324 | } | |
2325 | ||
dd786858 | 2326 | static const char * |
9291a0cd TT |
2327 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
2328 | { | |
e254ef6a | 2329 | struct dwarf2_per_cu_data *per_cu; |
9291a0cd TT |
2330 | offset_type *vec; |
2331 | ||
2332 | dw2_setup (objfile); | |
2333 | ||
2334 | if (!dwarf2_per_objfile->index_table) | |
2335 | return NULL; | |
2336 | ||
2337 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, | |
2338 | name, &vec)) | |
2339 | return NULL; | |
2340 | ||
2341 | /* Note that this just looks at the very first one named NAME -- but | |
2342 | actually we are looking for a function. find_main_filename | |
2343 | should be rewritten so that it doesn't require a custom hook. It | |
2344 | could just use the ordinary symbol tables. */ | |
2345 | /* vec[0] is the length, which must always be >0. */ | |
e254ef6a | 2346 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
9291a0cd | 2347 | |
e254ef6a DE |
2348 | dw2_require_line_header (objfile, per_cu); |
2349 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2350 | return NULL; |
2351 | ||
e254ef6a | 2352 | return per_cu->v.quick->file_names[per_cu->v.quick->lines->num_file_names - 1]; |
9291a0cd TT |
2353 | } |
2354 | ||
2355 | static void | |
2356 | dw2_map_ada_symtabs (struct objfile *objfile, | |
2357 | int (*wild_match) (const char *, int, const char *), | |
2358 | int (*is_name_suffix) (const char *), | |
2359 | void (*callback) (struct objfile *, | |
2360 | struct symtab *, void *), | |
2361 | const char *name, int global, | |
2362 | domain_enum namespace, int wild, | |
2363 | void *data) | |
2364 | { | |
2365 | /* For now, we don't support Ada, so this function can't be | |
2366 | reached. */ | |
2367 | internal_error (__FILE__, __LINE__, | |
2368 | _("map_ada_symtabs called via index method")); | |
2369 | } | |
2370 | ||
2371 | static void | |
2372 | dw2_expand_symtabs_matching (struct objfile *objfile, | |
2373 | int (*file_matcher) (const char *, void *), | |
2374 | int (*name_matcher) (const char *, void *), | |
2375 | domain_enum kind, | |
2376 | void *data) | |
2377 | { | |
2378 | int i; | |
2379 | offset_type iter; | |
2380 | ||
2381 | dw2_setup (objfile); | |
2382 | if (!dwarf2_per_objfile->index_table) | |
2383 | return; | |
2384 | ||
1fd400ff TT |
2385 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2386 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2387 | { |
2388 | int j; | |
e254ef6a | 2389 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2390 | |
e254ef6a DE |
2391 | per_cu->v.quick->mark = 0; |
2392 | if (per_cu->v.quick->symtab) | |
9291a0cd TT |
2393 | continue; |
2394 | ||
e254ef6a DE |
2395 | dw2_require_line_header (objfile, per_cu); |
2396 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2397 | continue; |
2398 | ||
e254ef6a | 2399 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2400 | { |
e254ef6a | 2401 | if (file_matcher (per_cu->v.quick->file_names[j], data)) |
9291a0cd | 2402 | { |
e254ef6a | 2403 | per_cu->v.quick->mark = 1; |
9291a0cd TT |
2404 | break; |
2405 | } | |
2406 | } | |
2407 | } | |
2408 | ||
2409 | for (iter = 0; | |
2410 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2411 | ++iter) | |
2412 | { | |
2413 | offset_type idx = 2 * iter; | |
2414 | const char *name; | |
2415 | offset_type *vec, vec_len, vec_idx; | |
2416 | ||
2417 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2418 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2419 | continue; | |
2420 | ||
2421 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2422 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2423 | ||
2424 | if (! (*name_matcher) (name, data)) | |
2425 | continue; | |
2426 | ||
2427 | /* The name was matched, now expand corresponding CUs that were | |
2428 | marked. */ | |
2429 | vec = (offset_type *) (dwarf2_per_objfile->index_table->constant_pool | |
2430 | + dwarf2_per_objfile->index_table->index_table[idx + 1]); | |
2431 | vec_len = MAYBE_SWAP (vec[0]); | |
2432 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) | |
2433 | { | |
e254ef6a | 2434 | struct dwarf2_per_cu_data *per_cu; |
1fd400ff | 2435 | |
e254ef6a DE |
2436 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
2437 | if (per_cu->v.quick->mark) | |
2438 | dw2_instantiate_symtab (objfile, per_cu); | |
9291a0cd TT |
2439 | } |
2440 | } | |
2441 | } | |
2442 | ||
2443 | static struct symtab * | |
2444 | dw2_find_pc_sect_symtab (struct objfile *objfile, | |
2445 | struct minimal_symbol *msymbol, | |
2446 | CORE_ADDR pc, | |
2447 | struct obj_section *section, | |
2448 | int warn_if_readin) | |
2449 | { | |
2450 | struct dwarf2_per_cu_data *data; | |
2451 | ||
2452 | dw2_setup (objfile); | |
2453 | ||
2454 | if (!objfile->psymtabs_addrmap) | |
2455 | return NULL; | |
2456 | ||
2457 | data = addrmap_find (objfile->psymtabs_addrmap, pc); | |
2458 | if (!data) | |
2459 | return NULL; | |
2460 | ||
2461 | if (warn_if_readin && data->v.quick->symtab) | |
abebb8b0 | 2462 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
9291a0cd TT |
2463 | paddress (get_objfile_arch (objfile), pc)); |
2464 | ||
2465 | return dw2_instantiate_symtab (objfile, data); | |
2466 | } | |
2467 | ||
2468 | static void | |
2469 | dw2_map_symbol_names (struct objfile *objfile, | |
2470 | void (*fun) (const char *, void *), | |
2471 | void *data) | |
2472 | { | |
2473 | offset_type iter; | |
2474 | dw2_setup (objfile); | |
2475 | ||
2476 | if (!dwarf2_per_objfile->index_table) | |
2477 | return; | |
2478 | ||
2479 | for (iter = 0; | |
2480 | iter < dwarf2_per_objfile->index_table->index_table_slots; | |
2481 | ++iter) | |
2482 | { | |
2483 | offset_type idx = 2 * iter; | |
2484 | const char *name; | |
2485 | offset_type *vec, vec_len, vec_idx; | |
2486 | ||
2487 | if (dwarf2_per_objfile->index_table->index_table[idx] == 0 | |
2488 | && dwarf2_per_objfile->index_table->index_table[idx + 1] == 0) | |
2489 | continue; | |
2490 | ||
2491 | name = (dwarf2_per_objfile->index_table->constant_pool | |
2492 | + dwarf2_per_objfile->index_table->index_table[idx]); | |
2493 | ||
2494 | (*fun) (name, data); | |
2495 | } | |
2496 | } | |
2497 | ||
2498 | static void | |
2499 | dw2_map_symbol_filenames (struct objfile *objfile, | |
2500 | void (*fun) (const char *, const char *, void *), | |
2501 | void *data) | |
2502 | { | |
2503 | int i; | |
2504 | ||
2505 | dw2_setup (objfile); | |
1fd400ff TT |
2506 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2507 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd TT |
2508 | { |
2509 | int j; | |
e254ef6a | 2510 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2511 | |
e254ef6a | 2512 | if (per_cu->v.quick->symtab) |
9291a0cd TT |
2513 | continue; |
2514 | ||
e254ef6a DE |
2515 | dw2_require_line_header (objfile, per_cu); |
2516 | if (!per_cu->v.quick->lines) | |
9291a0cd TT |
2517 | continue; |
2518 | ||
e254ef6a | 2519 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 2520 | { |
e254ef6a DE |
2521 | const char *this_full_name = dw2_require_full_path (objfile, per_cu, |
2522 | j); | |
2523 | (*fun) (per_cu->v.quick->file_names[j], this_full_name, data); | |
9291a0cd TT |
2524 | } |
2525 | } | |
2526 | } | |
2527 | ||
2528 | static int | |
2529 | dw2_has_symbols (struct objfile *objfile) | |
2530 | { | |
2531 | return 1; | |
2532 | } | |
2533 | ||
2534 | const struct quick_symbol_functions dwarf2_gdb_index_functions = | |
2535 | { | |
2536 | dw2_has_symbols, | |
2537 | dw2_find_last_source_symtab, | |
2538 | dw2_forget_cached_source_info, | |
2539 | dw2_lookup_symtab, | |
2540 | dw2_lookup_symbol, | |
774b6a14 | 2541 | dw2_pre_expand_symtabs_matching, |
9291a0cd TT |
2542 | dw2_print_stats, |
2543 | dw2_dump, | |
2544 | dw2_relocate, | |
2545 | dw2_expand_symtabs_for_function, | |
2546 | dw2_expand_all_symtabs, | |
2547 | dw2_expand_symtabs_with_filename, | |
2548 | dw2_find_symbol_file, | |
2549 | dw2_map_ada_symtabs, | |
2550 | dw2_expand_symtabs_matching, | |
2551 | dw2_find_pc_sect_symtab, | |
2552 | dw2_map_symbol_names, | |
2553 | dw2_map_symbol_filenames | |
2554 | }; | |
2555 | ||
2556 | /* Initialize for reading DWARF for this objfile. Return 0 if this | |
2557 | file will use psymtabs, or 1 if using the GNU index. */ | |
2558 | ||
2559 | int | |
2560 | dwarf2_initialize_objfile (struct objfile *objfile) | |
2561 | { | |
2562 | /* If we're about to read full symbols, don't bother with the | |
2563 | indices. In this case we also don't care if some other debug | |
2564 | format is making psymtabs, because they are all about to be | |
2565 | expanded anyway. */ | |
2566 | if ((objfile->flags & OBJF_READNOW)) | |
2567 | { | |
2568 | int i; | |
2569 | ||
2570 | dwarf2_per_objfile->using_index = 1; | |
2571 | create_all_comp_units (objfile); | |
1fd400ff | 2572 | create_debug_types_hash_table (objfile); |
9291a0cd | 2573 | |
1fd400ff TT |
2574 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
2575 | + dwarf2_per_objfile->n_type_comp_units); ++i) | |
9291a0cd | 2576 | { |
e254ef6a | 2577 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
9291a0cd | 2578 | |
e254ef6a DE |
2579 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
2580 | struct dwarf2_per_cu_quick_data); | |
9291a0cd TT |
2581 | } |
2582 | ||
2583 | /* Return 1 so that gdb sees the "quick" functions. However, | |
2584 | these functions will be no-ops because we will have expanded | |
2585 | all symtabs. */ | |
2586 | return 1; | |
2587 | } | |
2588 | ||
2589 | if (dwarf2_read_index (objfile)) | |
2590 | return 1; | |
2591 | ||
2592 | dwarf2_build_psymtabs (objfile); | |
2593 | return 0; | |
2594 | } | |
2595 | ||
2596 | \f | |
2597 | ||
dce234bc PP |
2598 | /* Build a partial symbol table. */ |
2599 | ||
2600 | void | |
f29dff0a | 2601 | dwarf2_build_psymtabs (struct objfile *objfile) |
dce234bc | 2602 | { |
f29dff0a | 2603 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
c906108c SS |
2604 | { |
2605 | init_psymbol_list (objfile, 1024); | |
2606 | } | |
2607 | ||
d146bf1e | 2608 | dwarf2_build_psymtabs_hard (objfile); |
c906108c | 2609 | } |
c906108c | 2610 | |
45452591 DE |
2611 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
2612 | ||
2613 | static inline int | |
2614 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
2615 | { | |
2616 | unsigned int bottom = cu_header->offset; | |
2617 | unsigned int top = (cu_header->offset | |
2618 | + cu_header->length | |
2619 | + cu_header->initial_length_size); | |
9a619af0 | 2620 | |
45452591 DE |
2621 | return (offset >= bottom && offset < top); |
2622 | } | |
2623 | ||
93311388 DE |
2624 | /* Read in the comp unit header information from the debug_info at info_ptr. |
2625 | NOTE: This leaves members offset, first_die_offset to be filled in | |
2626 | by the caller. */ | |
107d2387 | 2627 | |
fe1b8b76 | 2628 | static gdb_byte * |
107d2387 | 2629 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 2630 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
2631 | { |
2632 | int signed_addr; | |
891d2f0b | 2633 | unsigned int bytes_read; |
c764a876 DE |
2634 | |
2635 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
2636 | cu_header->initial_length_size = bytes_read; | |
2637 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 2638 | info_ptr += bytes_read; |
107d2387 AC |
2639 | cu_header->version = read_2_bytes (abfd, info_ptr); |
2640 | info_ptr += 2; | |
613e1657 | 2641 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 2642 | &bytes_read); |
613e1657 | 2643 | info_ptr += bytes_read; |
107d2387 AC |
2644 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
2645 | info_ptr += 1; | |
2646 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
2647 | if (signed_addr < 0) | |
8e65ff28 | 2648 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2649 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 2650 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 2651 | |
107d2387 AC |
2652 | return info_ptr; |
2653 | } | |
2654 | ||
fe1b8b76 JB |
2655 | static gdb_byte * |
2656 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
93311388 | 2657 | gdb_byte *buffer, unsigned int buffer_size, |
72bf9492 DJ |
2658 | bfd *abfd) |
2659 | { | |
fe1b8b76 | 2660 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
2661 | |
2662 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
2663 | ||
2dc7f7b3 | 2664 | if (header->version != 2 && header->version != 3 && header->version != 4) |
8a3fe4f8 | 2665 | error (_("Dwarf Error: wrong version in compilation unit header " |
2dc7f7b3 TT |
2666 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
2667 | bfd_get_filename (abfd)); | |
72bf9492 | 2668 | |
dce234bc | 2669 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
2670 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
2671 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 2672 | (long) header->abbrev_offset, |
93311388 | 2673 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2674 | bfd_get_filename (abfd)); |
2675 | ||
2676 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
93311388 | 2677 | > buffer + buffer_size) |
8a3fe4f8 AC |
2678 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
2679 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 2680 | (long) header->length, |
93311388 | 2681 | (long) (beg_of_comp_unit - buffer), |
72bf9492 DJ |
2682 | bfd_get_filename (abfd)); |
2683 | ||
2684 | return info_ptr; | |
2685 | } | |
2686 | ||
348e048f DE |
2687 | /* Read in the types comp unit header information from .debug_types entry at |
2688 | types_ptr. The result is a pointer to one past the end of the header. */ | |
2689 | ||
2690 | static gdb_byte * | |
2691 | read_type_comp_unit_head (struct comp_unit_head *cu_header, | |
2692 | ULONGEST *signature, | |
2693 | gdb_byte *types_ptr, bfd *abfd) | |
2694 | { | |
348e048f DE |
2695 | gdb_byte *initial_types_ptr = types_ptr; |
2696 | ||
6e70227d | 2697 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
fa238c03 | 2698 | &dwarf2_per_objfile->types); |
348e048f DE |
2699 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
2700 | ||
2701 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); | |
2702 | ||
2703 | *signature = read_8_bytes (abfd, types_ptr); | |
2704 | types_ptr += 8; | |
2705 | types_ptr += cu_header->offset_size; | |
2706 | cu_header->first_die_offset = types_ptr - initial_types_ptr; | |
2707 | ||
2708 | return types_ptr; | |
2709 | } | |
2710 | ||
aaa75496 JB |
2711 | /* Allocate a new partial symtab for file named NAME and mark this new |
2712 | partial symtab as being an include of PST. */ | |
2713 | ||
2714 | static void | |
2715 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
2716 | struct objfile *objfile) | |
2717 | { | |
2718 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
2719 | ||
2720 | subpst->section_offsets = pst->section_offsets; | |
2721 | subpst->textlow = 0; | |
2722 | subpst->texthigh = 0; | |
2723 | ||
2724 | subpst->dependencies = (struct partial_symtab **) | |
2725 | obstack_alloc (&objfile->objfile_obstack, | |
2726 | sizeof (struct partial_symtab *)); | |
2727 | subpst->dependencies[0] = pst; | |
2728 | subpst->number_of_dependencies = 1; | |
2729 | ||
2730 | subpst->globals_offset = 0; | |
2731 | subpst->n_global_syms = 0; | |
2732 | subpst->statics_offset = 0; | |
2733 | subpst->n_static_syms = 0; | |
2734 | subpst->symtab = NULL; | |
2735 | subpst->read_symtab = pst->read_symtab; | |
2736 | subpst->readin = 0; | |
2737 | ||
2738 | /* No private part is necessary for include psymtabs. This property | |
2739 | can be used to differentiate between such include psymtabs and | |
10b3939b | 2740 | the regular ones. */ |
58a9656e | 2741 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
2742 | } |
2743 | ||
2744 | /* Read the Line Number Program data and extract the list of files | |
2745 | included by the source file represented by PST. Build an include | |
d85a05f0 | 2746 | partial symtab for each of these included files. */ |
aaa75496 JB |
2747 | |
2748 | static void | |
2749 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
d85a05f0 | 2750 | struct die_info *die, |
aaa75496 JB |
2751 | struct partial_symtab *pst) |
2752 | { | |
2753 | struct objfile *objfile = cu->objfile; | |
2754 | bfd *abfd = objfile->obfd; | |
d85a05f0 DJ |
2755 | struct line_header *lh = NULL; |
2756 | struct attribute *attr; | |
aaa75496 | 2757 | |
d85a05f0 DJ |
2758 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
2759 | if (attr) | |
2760 | { | |
2761 | unsigned int line_offset = DW_UNSND (attr); | |
9a619af0 | 2762 | |
d85a05f0 DJ |
2763 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
2764 | } | |
aaa75496 JB |
2765 | if (lh == NULL) |
2766 | return; /* No linetable, so no includes. */ | |
2767 | ||
c6da4cef DE |
2768 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
2769 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); | |
aaa75496 JB |
2770 | |
2771 | free_line_header (lh); | |
2772 | } | |
2773 | ||
348e048f DE |
2774 | static hashval_t |
2775 | hash_type_signature (const void *item) | |
2776 | { | |
2777 | const struct signatured_type *type_sig = item; | |
9a619af0 | 2778 | |
348e048f DE |
2779 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
2780 | return type_sig->signature; | |
2781 | } | |
2782 | ||
2783 | static int | |
2784 | eq_type_signature (const void *item_lhs, const void *item_rhs) | |
2785 | { | |
2786 | const struct signatured_type *lhs = item_lhs; | |
2787 | const struct signatured_type *rhs = item_rhs; | |
9a619af0 | 2788 | |
348e048f DE |
2789 | return lhs->signature == rhs->signature; |
2790 | } | |
2791 | ||
1fd400ff TT |
2792 | /* Allocate a hash table for signatured types. */ |
2793 | ||
2794 | static htab_t | |
673bfd45 | 2795 | allocate_signatured_type_table (struct objfile *objfile) |
1fd400ff TT |
2796 | { |
2797 | return htab_create_alloc_ex (41, | |
2798 | hash_type_signature, | |
2799 | eq_type_signature, | |
2800 | NULL, | |
2801 | &objfile->objfile_obstack, | |
2802 | hashtab_obstack_allocate, | |
2803 | dummy_obstack_deallocate); | |
2804 | } | |
2805 | ||
2806 | /* A helper function to add a signatured type CU to a list. */ | |
2807 | ||
2808 | static int | |
2809 | add_signatured_type_cu_to_list (void **slot, void *datum) | |
2810 | { | |
2811 | struct signatured_type *sigt = *slot; | |
2812 | struct dwarf2_per_cu_data ***datap = datum; | |
2813 | ||
2814 | **datap = &sigt->per_cu; | |
2815 | ++*datap; | |
2816 | ||
2817 | return 1; | |
2818 | } | |
2819 | ||
348e048f DE |
2820 | /* Create the hash table of all entries in the .debug_types section. |
2821 | The result is zero if there is an error (e.g. missing .debug_types section), | |
2822 | otherwise non-zero. */ | |
2823 | ||
2824 | static int | |
2825 | create_debug_types_hash_table (struct objfile *objfile) | |
2826 | { | |
be391dca | 2827 | gdb_byte *info_ptr; |
348e048f | 2828 | htab_t types_htab; |
1fd400ff | 2829 | struct dwarf2_per_cu_data **iter; |
348e048f | 2830 | |
be391dca TT |
2831 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
2832 | info_ptr = dwarf2_per_objfile->types.buffer; | |
2833 | ||
348e048f DE |
2834 | if (info_ptr == NULL) |
2835 | { | |
2836 | dwarf2_per_objfile->signatured_types = NULL; | |
2837 | return 0; | |
2838 | } | |
2839 | ||
673bfd45 | 2840 | types_htab = allocate_signatured_type_table (objfile); |
348e048f DE |
2841 | |
2842 | if (dwarf2_die_debug) | |
2843 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); | |
2844 | ||
2845 | while (info_ptr < dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2846 | { | |
2847 | unsigned int offset; | |
2848 | unsigned int offset_size; | |
2849 | unsigned int type_offset; | |
2850 | unsigned int length, initial_length_size; | |
2851 | unsigned short version; | |
2852 | ULONGEST signature; | |
2853 | struct signatured_type *type_sig; | |
2854 | void **slot; | |
2855 | gdb_byte *ptr = info_ptr; | |
2856 | ||
2857 | offset = ptr - dwarf2_per_objfile->types.buffer; | |
2858 | ||
2859 | /* We need to read the type's signature in order to build the hash | |
2860 | table, but we don't need to read anything else just yet. */ | |
2861 | ||
2862 | /* Sanity check to ensure entire cu is present. */ | |
2863 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); | |
2864 | if (ptr + length + initial_length_size | |
2865 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) | |
2866 | { | |
2867 | complaint (&symfile_complaints, | |
2868 | _("debug type entry runs off end of `.debug_types' section, ignored")); | |
2869 | break; | |
2870 | } | |
2871 | ||
2872 | offset_size = initial_length_size == 4 ? 4 : 8; | |
2873 | ptr += initial_length_size; | |
2874 | version = bfd_get_16 (objfile->obfd, ptr); | |
2875 | ptr += 2; | |
2876 | ptr += offset_size; /* abbrev offset */ | |
2877 | ptr += 1; /* address size */ | |
2878 | signature = bfd_get_64 (objfile->obfd, ptr); | |
2879 | ptr += 8; | |
2880 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); | |
2881 | ||
2882 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); | |
2883 | memset (type_sig, 0, sizeof (*type_sig)); | |
2884 | type_sig->signature = signature; | |
2885 | type_sig->offset = offset; | |
2886 | type_sig->type_offset = type_offset; | |
ca1f3406 | 2887 | type_sig->per_cu.objfile = objfile; |
1fd400ff | 2888 | type_sig->per_cu.from_debug_types = 1; |
348e048f DE |
2889 | |
2890 | slot = htab_find_slot (types_htab, type_sig, INSERT); | |
2891 | gdb_assert (slot != NULL); | |
2892 | *slot = type_sig; | |
2893 | ||
2894 | if (dwarf2_die_debug) | |
2895 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", | |
2896 | offset, phex (signature, sizeof (signature))); | |
2897 | ||
2898 | info_ptr = info_ptr + initial_length_size + length; | |
2899 | } | |
2900 | ||
2901 | dwarf2_per_objfile->signatured_types = types_htab; | |
2902 | ||
1fd400ff TT |
2903 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
2904 | dwarf2_per_objfile->type_comp_units | |
2905 | = obstack_alloc (&objfile->objfile_obstack, | |
2906 | dwarf2_per_objfile->n_type_comp_units | |
2907 | * sizeof (struct dwarf2_per_cu_data *)); | |
2908 | iter = &dwarf2_per_objfile->type_comp_units[0]; | |
2909 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); | |
2910 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] | |
2911 | == dwarf2_per_objfile->n_type_comp_units); | |
2912 | ||
348e048f DE |
2913 | return 1; |
2914 | } | |
2915 | ||
2916 | /* Lookup a signature based type. | |
2917 | Returns NULL if SIG is not present in the table. */ | |
2918 | ||
2919 | static struct signatured_type * | |
2920 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) | |
2921 | { | |
2922 | struct signatured_type find_entry, *entry; | |
2923 | ||
2924 | if (dwarf2_per_objfile->signatured_types == NULL) | |
2925 | { | |
2926 | complaint (&symfile_complaints, | |
2927 | _("missing `.debug_types' section for DW_FORM_sig8 die")); | |
2928 | return 0; | |
2929 | } | |
2930 | ||
2931 | find_entry.signature = sig; | |
2932 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
2933 | return entry; | |
2934 | } | |
2935 | ||
d85a05f0 DJ |
2936 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
2937 | ||
2938 | static void | |
2939 | init_cu_die_reader (struct die_reader_specs *reader, | |
2940 | struct dwarf2_cu *cu) | |
2941 | { | |
2942 | reader->abfd = cu->objfile->obfd; | |
2943 | reader->cu = cu; | |
2944 | if (cu->per_cu->from_debug_types) | |
be391dca TT |
2945 | { |
2946 | gdb_assert (dwarf2_per_objfile->types.readin); | |
2947 | reader->buffer = dwarf2_per_objfile->types.buffer; | |
2948 | } | |
d85a05f0 | 2949 | else |
be391dca TT |
2950 | { |
2951 | gdb_assert (dwarf2_per_objfile->info.readin); | |
2952 | reader->buffer = dwarf2_per_objfile->info.buffer; | |
2953 | } | |
d85a05f0 DJ |
2954 | } |
2955 | ||
2956 | /* Find the base address of the compilation unit for range lists and | |
2957 | location lists. It will normally be specified by DW_AT_low_pc. | |
2958 | In DWARF-3 draft 4, the base address could be overridden by | |
2959 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2960 | compilation units with discontinuous ranges. */ | |
2961 | ||
2962 | static void | |
2963 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) | |
2964 | { | |
2965 | struct attribute *attr; | |
2966 | ||
2967 | cu->base_known = 0; | |
2968 | cu->base_address = 0; | |
2969 | ||
2970 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); | |
2971 | if (attr) | |
2972 | { | |
2973 | cu->base_address = DW_ADDR (attr); | |
2974 | cu->base_known = 1; | |
2975 | } | |
2976 | else | |
2977 | { | |
2978 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
2979 | if (attr) | |
2980 | { | |
2981 | cu->base_address = DW_ADDR (attr); | |
2982 | cu->base_known = 1; | |
2983 | } | |
2984 | } | |
2985 | } | |
2986 | ||
348e048f DE |
2987 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
2988 | to combine the common parts. | |
93311388 | 2989 | Process a compilation unit for a psymtab. |
348e048f DE |
2990 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
2991 | either .debug_info or debug_types. | |
93311388 DE |
2992 | INFO_PTR is a pointer to the start of the CU. |
2993 | Returns a pointer to the next CU. */ | |
aaa75496 | 2994 | |
93311388 DE |
2995 | static gdb_byte * |
2996 | process_psymtab_comp_unit (struct objfile *objfile, | |
2997 | struct dwarf2_per_cu_data *this_cu, | |
2998 | gdb_byte *buffer, gdb_byte *info_ptr, | |
2999 | unsigned int buffer_size) | |
c906108c | 3000 | { |
c906108c | 3001 | bfd *abfd = objfile->obfd; |
93311388 | 3002 | gdb_byte *beg_of_comp_unit = info_ptr; |
d85a05f0 | 3003 | struct die_info *comp_unit_die; |
c906108c | 3004 | struct partial_symtab *pst; |
5734ee8b | 3005 | CORE_ADDR baseaddr; |
93311388 DE |
3006 | struct cleanup *back_to_inner; |
3007 | struct dwarf2_cu cu; | |
d85a05f0 DJ |
3008 | int has_children, has_pc_info; |
3009 | struct attribute *attr; | |
d85a05f0 DJ |
3010 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
3011 | struct die_reader_specs reader_specs; | |
c906108c | 3012 | |
93311388 DE |
3013 | memset (&cu, 0, sizeof (cu)); |
3014 | cu.objfile = objfile; | |
3015 | obstack_init (&cu.comp_unit_obstack); | |
c906108c | 3016 | |
93311388 | 3017 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
ae038cb0 | 3018 | |
93311388 DE |
3019 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
3020 | buffer, buffer_size, | |
3021 | abfd); | |
10b3939b | 3022 | |
93311388 DE |
3023 | /* Complete the cu_header. */ |
3024 | cu.header.offset = beg_of_comp_unit - buffer; | |
3025 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; | |
ff013f42 | 3026 | |
93311388 | 3027 | cu.list_in_scope = &file_symbols; |
af703f96 | 3028 | |
328c9494 DJ |
3029 | /* If this compilation unit was already read in, free the |
3030 | cached copy in order to read it in again. This is | |
3031 | necessary because we skipped some symbols when we first | |
3032 | read in the compilation unit (see load_partial_dies). | |
3033 | This problem could be avoided, but the benefit is | |
3034 | unclear. */ | |
3035 | if (this_cu->cu != NULL) | |
3036 | free_one_cached_comp_unit (this_cu->cu); | |
3037 | ||
3038 | /* Note that this is a pointer to our stack frame, being | |
3039 | added to a global data structure. It will be cleaned up | |
3040 | in free_stack_comp_unit when we finish with this | |
3041 | compilation unit. */ | |
3042 | this_cu->cu = &cu; | |
d85a05f0 DJ |
3043 | cu.per_cu = this_cu; |
3044 | ||
93311388 DE |
3045 | /* Read the abbrevs for this compilation unit into a table. */ |
3046 | dwarf2_read_abbrevs (abfd, &cu); | |
3047 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |
af703f96 | 3048 | |
93311388 | 3049 | /* Read the compilation unit die. */ |
348e048f DE |
3050 | if (this_cu->from_debug_types) |
3051 | info_ptr += 8 /*signature*/ + cu.header.offset_size; | |
d85a05f0 DJ |
3052 | init_cu_die_reader (&reader_specs, &cu); |
3053 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3054 | &has_children); | |
93311388 | 3055 | |
348e048f DE |
3056 | if (this_cu->from_debug_types) |
3057 | { | |
3058 | /* offset,length haven't been set yet for type units. */ | |
3059 | this_cu->offset = cu.header.offset; | |
3060 | this_cu->length = cu.header.length + cu.header.initial_length_size; | |
3061 | } | |
d85a05f0 | 3062 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
c906108c | 3063 | { |
93311388 DE |
3064 | info_ptr = (beg_of_comp_unit + cu.header.length |
3065 | + cu.header.initial_length_size); | |
3066 | do_cleanups (back_to_inner); | |
3067 | return info_ptr; | |
3068 | } | |
72bf9492 | 3069 | |
93311388 | 3070 | /* Set the language we're debugging. */ |
d85a05f0 DJ |
3071 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, &cu); |
3072 | if (attr) | |
3073 | set_cu_language (DW_UNSND (attr), &cu); | |
3074 | else | |
3075 | set_cu_language (language_minimal, &cu); | |
c906108c | 3076 | |
93311388 | 3077 | /* Allocate a new partial symbol table structure. */ |
d85a05f0 | 3078 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
93311388 | 3079 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
d85a05f0 | 3080 | (attr != NULL) ? DW_STRING (attr) : "", |
93311388 DE |
3081 | /* TEXTLOW and TEXTHIGH are set below. */ |
3082 | 0, | |
3083 | objfile->global_psymbols.next, | |
3084 | objfile->static_psymbols.next); | |
72bf9492 | 3085 | |
d85a05f0 DJ |
3086 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
3087 | if (attr != NULL) | |
3088 | pst->dirname = DW_STRING (attr); | |
72bf9492 | 3089 | |
e38df1d0 | 3090 | pst->read_symtab_private = this_cu; |
72bf9492 | 3091 | |
93311388 | 3092 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
e7c27a73 | 3093 | |
93311388 DE |
3094 | /* Store the function that reads in the rest of the symbol table */ |
3095 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
57349743 | 3096 | |
9291a0cd | 3097 | this_cu->v.psymtab = pst; |
c906108c | 3098 | |
d85a05f0 DJ |
3099 | dwarf2_find_base_address (comp_unit_die, &cu); |
3100 | ||
93311388 DE |
3101 | /* Possibly set the default values of LOWPC and HIGHPC from |
3102 | `DW_AT_ranges'. */ | |
d85a05f0 DJ |
3103 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
3104 | &best_highpc, &cu, pst); | |
3105 | if (has_pc_info == 1 && best_lowpc < best_highpc) | |
93311388 DE |
3106 | /* Store the contiguous range if it is not empty; it can be empty for |
3107 | CUs with no code. */ | |
3108 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
d85a05f0 DJ |
3109 | best_lowpc + baseaddr, |
3110 | best_highpc + baseaddr - 1, pst); | |
93311388 DE |
3111 | |
3112 | /* Check if comp unit has_children. | |
3113 | If so, read the rest of the partial symbols from this comp unit. | |
3114 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3115 | if (has_children) |
93311388 DE |
3116 | { |
3117 | struct partial_die_info *first_die; | |
3118 | CORE_ADDR lowpc, highpc; | |
31ffec48 | 3119 | |
93311388 DE |
3120 | lowpc = ((CORE_ADDR) -1); |
3121 | highpc = ((CORE_ADDR) 0); | |
c906108c | 3122 | |
93311388 | 3123 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
c906108c | 3124 | |
93311388 | 3125 | scan_partial_symbols (first_die, &lowpc, &highpc, |
d85a05f0 | 3126 | ! has_pc_info, &cu); |
57c22c6c | 3127 | |
93311388 DE |
3128 | /* If we didn't find a lowpc, set it to highpc to avoid |
3129 | complaints from `maint check'. */ | |
3130 | if (lowpc == ((CORE_ADDR) -1)) | |
3131 | lowpc = highpc; | |
10b3939b | 3132 | |
93311388 DE |
3133 | /* If the compilation unit didn't have an explicit address range, |
3134 | then use the information extracted from its child dies. */ | |
d85a05f0 | 3135 | if (! has_pc_info) |
93311388 | 3136 | { |
d85a05f0 DJ |
3137 | best_lowpc = lowpc; |
3138 | best_highpc = highpc; | |
93311388 DE |
3139 | } |
3140 | } | |
d85a05f0 DJ |
3141 | pst->textlow = best_lowpc + baseaddr; |
3142 | pst->texthigh = best_highpc + baseaddr; | |
c906108c | 3143 | |
93311388 DE |
3144 | pst->n_global_syms = objfile->global_psymbols.next - |
3145 | (objfile->global_psymbols.list + pst->globals_offset); | |
3146 | pst->n_static_syms = objfile->static_psymbols.next - | |
3147 | (objfile->static_psymbols.list + pst->statics_offset); | |
3148 | sort_pst_symbols (pst); | |
c906108c | 3149 | |
93311388 DE |
3150 | info_ptr = (beg_of_comp_unit + cu.header.length |
3151 | + cu.header.initial_length_size); | |
ae038cb0 | 3152 | |
348e048f DE |
3153 | if (this_cu->from_debug_types) |
3154 | { | |
3155 | /* It's not clear we want to do anything with stmt lists here. | |
3156 | Waiting to see what gcc ultimately does. */ | |
3157 | } | |
d85a05f0 | 3158 | else |
93311388 DE |
3159 | { |
3160 | /* Get the list of files included in the current compilation unit, | |
3161 | and build a psymtab for each of them. */ | |
d85a05f0 | 3162 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
93311388 | 3163 | } |
ae038cb0 | 3164 | |
93311388 | 3165 | do_cleanups (back_to_inner); |
ae038cb0 | 3166 | |
93311388 DE |
3167 | return info_ptr; |
3168 | } | |
ff013f42 | 3169 | |
348e048f DE |
3170 | /* Traversal function for htab_traverse_noresize. |
3171 | Process one .debug_types comp-unit. */ | |
3172 | ||
3173 | static int | |
3174 | process_type_comp_unit (void **slot, void *info) | |
3175 | { | |
3176 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
3177 | struct objfile *objfile = (struct objfile *) info; | |
3178 | struct dwarf2_per_cu_data *this_cu; | |
3179 | ||
3180 | this_cu = &entry->per_cu; | |
348e048f | 3181 | |
be391dca | 3182 | gdb_assert (dwarf2_per_objfile->types.readin); |
348e048f DE |
3183 | process_psymtab_comp_unit (objfile, this_cu, |
3184 | dwarf2_per_objfile->types.buffer, | |
3185 | dwarf2_per_objfile->types.buffer + entry->offset, | |
3186 | dwarf2_per_objfile->types.size); | |
3187 | ||
3188 | return 1; | |
3189 | } | |
3190 | ||
3191 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. | |
3192 | Build partial symbol tables for the .debug_types comp-units. */ | |
3193 | ||
3194 | static void | |
3195 | build_type_psymtabs (struct objfile *objfile) | |
3196 | { | |
3197 | if (! create_debug_types_hash_table (objfile)) | |
3198 | return; | |
3199 | ||
3200 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
3201 | process_type_comp_unit, objfile); | |
3202 | } | |
3203 | ||
60606b2c TT |
3204 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
3205 | ||
3206 | static void | |
3207 | psymtabs_addrmap_cleanup (void *o) | |
3208 | { | |
3209 | struct objfile *objfile = o; | |
ec61707d | 3210 | |
60606b2c TT |
3211 | objfile->psymtabs_addrmap = NULL; |
3212 | } | |
3213 | ||
93311388 DE |
3214 | /* Build the partial symbol table by doing a quick pass through the |
3215 | .debug_info and .debug_abbrev sections. */ | |
72bf9492 | 3216 | |
93311388 | 3217 | static void |
c67a9c90 | 3218 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
93311388 | 3219 | { |
93311388 | 3220 | gdb_byte *info_ptr; |
60606b2c TT |
3221 | struct cleanup *back_to, *addrmap_cleanup; |
3222 | struct obstack temp_obstack; | |
93311388 | 3223 | |
98bfdba5 PA |
3224 | dwarf2_per_objfile->reading_partial_symbols = 1; |
3225 | ||
be391dca | 3226 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
93311388 | 3227 | info_ptr = dwarf2_per_objfile->info.buffer; |
91c24f0a | 3228 | |
93311388 DE |
3229 | /* Any cached compilation units will be linked by the per-objfile |
3230 | read_in_chain. Make sure to free them when we're done. */ | |
3231 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
72bf9492 | 3232 | |
348e048f DE |
3233 | build_type_psymtabs (objfile); |
3234 | ||
93311388 | 3235 | create_all_comp_units (objfile); |
c906108c | 3236 | |
60606b2c TT |
3237 | /* Create a temporary address map on a temporary obstack. We later |
3238 | copy this to the final obstack. */ | |
3239 | obstack_init (&temp_obstack); | |
3240 | make_cleanup_obstack_free (&temp_obstack); | |
3241 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); | |
3242 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); | |
72bf9492 | 3243 | |
93311388 DE |
3244 | /* Since the objects we're extracting from .debug_info vary in |
3245 | length, only the individual functions to extract them (like | |
3246 | read_comp_unit_head and load_partial_die) can really know whether | |
3247 | the buffer is large enough to hold another complete object. | |
c906108c | 3248 | |
93311388 DE |
3249 | At the moment, they don't actually check that. If .debug_info |
3250 | holds just one extra byte after the last compilation unit's dies, | |
3251 | then read_comp_unit_head will happily read off the end of the | |
3252 | buffer. read_partial_die is similarly casual. Those functions | |
3253 | should be fixed. | |
c906108c | 3254 | |
93311388 DE |
3255 | For this loop condition, simply checking whether there's any data |
3256 | left at all should be sufficient. */ | |
c906108c | 3257 | |
93311388 DE |
3258 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
3259 | + dwarf2_per_objfile->info.size)) | |
3260 | { | |
3261 | struct dwarf2_per_cu_data *this_cu; | |
dd373385 | 3262 | |
93311388 DE |
3263 | this_cu = dwarf2_find_comp_unit (info_ptr - dwarf2_per_objfile->info.buffer, |
3264 | objfile); | |
aaa75496 | 3265 | |
93311388 DE |
3266 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
3267 | dwarf2_per_objfile->info.buffer, | |
3268 | info_ptr, | |
3269 | dwarf2_per_objfile->info.size); | |
c906108c | 3270 | } |
ff013f42 JK |
3271 | |
3272 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
3273 | &objfile->objfile_obstack); | |
60606b2c | 3274 | discard_cleanups (addrmap_cleanup); |
ff013f42 | 3275 | |
ae038cb0 DJ |
3276 | do_cleanups (back_to); |
3277 | } | |
3278 | ||
93311388 | 3279 | /* Load the partial DIEs for a secondary CU into memory. */ |
ae038cb0 DJ |
3280 | |
3281 | static void | |
93311388 DE |
3282 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
3283 | struct objfile *objfile) | |
ae038cb0 DJ |
3284 | { |
3285 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 3286 | gdb_byte *info_ptr, *beg_of_comp_unit; |
d85a05f0 | 3287 | struct die_info *comp_unit_die; |
ae038cb0 | 3288 | struct dwarf2_cu *cu; |
1d9ec526 | 3289 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
d85a05f0 DJ |
3290 | struct attribute *attr; |
3291 | int has_children; | |
3292 | struct die_reader_specs reader_specs; | |
98bfdba5 | 3293 | int read_cu = 0; |
ae038cb0 | 3294 | |
348e048f DE |
3295 | gdb_assert (! this_cu->from_debug_types); |
3296 | ||
be391dca | 3297 | gdb_assert (dwarf2_per_objfile->info.readin); |
dce234bc | 3298 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
3299 | beg_of_comp_unit = info_ptr; |
3300 | ||
98bfdba5 PA |
3301 | if (this_cu->cu == NULL) |
3302 | { | |
3303 | cu = alloc_one_comp_unit (objfile); | |
ae038cb0 | 3304 | |
98bfdba5 | 3305 | read_cu = 1; |
ae038cb0 | 3306 | |
98bfdba5 PA |
3307 | /* If an error occurs while loading, release our storage. */ |
3308 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
328c9494 | 3309 | |
98bfdba5 PA |
3310 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
3311 | dwarf2_per_objfile->info.buffer, | |
3312 | dwarf2_per_objfile->info.size, | |
3313 | abfd); | |
ae038cb0 | 3314 | |
98bfdba5 PA |
3315 | /* Complete the cu_header. */ |
3316 | cu->header.offset = this_cu->offset; | |
3317 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
3318 | ||
3319 | /* Link this compilation unit into the compilation unit tree. */ | |
3320 | this_cu->cu = cu; | |
3321 | cu->per_cu = this_cu; | |
98bfdba5 PA |
3322 | |
3323 | /* Link this CU into read_in_chain. */ | |
3324 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
3325 | dwarf2_per_objfile->read_in_chain = this_cu; | |
3326 | } | |
3327 | else | |
3328 | { | |
3329 | cu = this_cu->cu; | |
3330 | info_ptr += cu->header.first_die_offset; | |
3331 | } | |
ae038cb0 DJ |
3332 | |
3333 | /* Read the abbrevs for this compilation unit into a table. */ | |
98bfdba5 | 3334 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
ae038cb0 | 3335 | dwarf2_read_abbrevs (abfd, cu); |
98bfdba5 | 3336 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
ae038cb0 DJ |
3337 | |
3338 | /* Read the compilation unit die. */ | |
d85a05f0 DJ |
3339 | init_cu_die_reader (&reader_specs, cu); |
3340 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, | |
3341 | &has_children); | |
ae038cb0 DJ |
3342 | |
3343 | /* Set the language we're debugging. */ | |
d85a05f0 DJ |
3344 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
3345 | if (attr) | |
3346 | set_cu_language (DW_UNSND (attr), cu); | |
3347 | else | |
3348 | set_cu_language (language_minimal, cu); | |
ae038cb0 | 3349 | |
ae038cb0 DJ |
3350 | /* Check if comp unit has_children. |
3351 | If so, read the rest of the partial symbols from this comp unit. | |
3352 | If not, there's no more debug_info for this comp unit. */ | |
d85a05f0 | 3353 | if (has_children) |
93311388 | 3354 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
ae038cb0 | 3355 | |
98bfdba5 PA |
3356 | do_cleanups (free_abbrevs_cleanup); |
3357 | ||
3358 | if (read_cu) | |
3359 | { | |
3360 | /* We've successfully allocated this compilation unit. Let our | |
3361 | caller clean it up when finished with it. */ | |
3362 | discard_cleanups (free_cu_cleanup); | |
3363 | } | |
ae038cb0 DJ |
3364 | } |
3365 | ||
3366 | /* Create a list of all compilation units in OBJFILE. We do this only | |
3367 | if an inter-comp-unit reference is found; presumably if there is one, | |
3368 | there will be many, and one will occur early in the .debug_info section. | |
3369 | So there's no point in building this list incrementally. */ | |
3370 | ||
3371 | static void | |
3372 | create_all_comp_units (struct objfile *objfile) | |
3373 | { | |
3374 | int n_allocated; | |
3375 | int n_comp_units; | |
3376 | struct dwarf2_per_cu_data **all_comp_units; | |
be391dca TT |
3377 | gdb_byte *info_ptr; |
3378 | ||
3379 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
3380 | info_ptr = dwarf2_per_objfile->info.buffer; | |
ae038cb0 DJ |
3381 | |
3382 | n_comp_units = 0; | |
3383 | n_allocated = 10; | |
3384 | all_comp_units = xmalloc (n_allocated | |
3385 | * sizeof (struct dwarf2_per_cu_data *)); | |
6e70227d | 3386 | |
dce234bc | 3387 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 3388 | { |
c764a876 | 3389 | unsigned int length, initial_length_size; |
ae038cb0 | 3390 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 3391 | unsigned int offset; |
ae038cb0 | 3392 | |
dce234bc | 3393 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
3394 | |
3395 | /* Read just enough information to find out where the next | |
3396 | compilation unit is. */ | |
c764a876 DE |
3397 | length = read_initial_length (objfile->obfd, info_ptr, |
3398 | &initial_length_size); | |
ae038cb0 DJ |
3399 | |
3400 | /* Save the compilation unit for later lookup. */ | |
3401 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
3402 | sizeof (struct dwarf2_per_cu_data)); | |
3403 | memset (this_cu, 0, sizeof (*this_cu)); | |
3404 | this_cu->offset = offset; | |
c764a876 | 3405 | this_cu->length = length + initial_length_size; |
9291a0cd | 3406 | this_cu->objfile = objfile; |
ae038cb0 DJ |
3407 | |
3408 | if (n_comp_units == n_allocated) | |
3409 | { | |
3410 | n_allocated *= 2; | |
3411 | all_comp_units = xrealloc (all_comp_units, | |
3412 | n_allocated | |
3413 | * sizeof (struct dwarf2_per_cu_data *)); | |
3414 | } | |
3415 | all_comp_units[n_comp_units++] = this_cu; | |
3416 | ||
3417 | info_ptr = info_ptr + this_cu->length; | |
3418 | } | |
3419 | ||
3420 | dwarf2_per_objfile->all_comp_units | |
3421 | = obstack_alloc (&objfile->objfile_obstack, | |
3422 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3423 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
3424 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
3425 | xfree (all_comp_units); | |
3426 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
3427 | } |
3428 | ||
5734ee8b DJ |
3429 | /* Process all loaded DIEs for compilation unit CU, starting at |
3430 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
3431 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
3432 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
3433 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
3434 | and record the covered ranges in the addrmap. */ | |
c906108c | 3435 | |
72bf9492 DJ |
3436 | static void |
3437 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 3438 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 3439 | { |
72bf9492 | 3440 | struct partial_die_info *pdi; |
c906108c | 3441 | |
91c24f0a DC |
3442 | /* Now, march along the PDI's, descending into ones which have |
3443 | interesting children but skipping the children of the other ones, | |
3444 | until we reach the end of the compilation unit. */ | |
c906108c | 3445 | |
72bf9492 | 3446 | pdi = first_die; |
91c24f0a | 3447 | |
72bf9492 DJ |
3448 | while (pdi != NULL) |
3449 | { | |
3450 | fixup_partial_die (pdi, cu); | |
c906108c | 3451 | |
f55ee35c | 3452 | /* Anonymous namespaces or modules have no name but have interesting |
91c24f0a DC |
3453 | children, so we need to look at them. Ditto for anonymous |
3454 | enums. */ | |
933c6fe4 | 3455 | |
72bf9492 | 3456 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
f55ee35c | 3457 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
c906108c | 3458 | { |
72bf9492 | 3459 | switch (pdi->tag) |
c906108c SS |
3460 | { |
3461 | case DW_TAG_subprogram: | |
5734ee8b | 3462 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
3463 | break; |
3464 | case DW_TAG_variable: | |
3465 | case DW_TAG_typedef: | |
91c24f0a | 3466 | case DW_TAG_union_type: |
72bf9492 | 3467 | if (!pdi->is_declaration) |
63d06c5c | 3468 | { |
72bf9492 | 3469 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
3470 | } |
3471 | break; | |
c906108c | 3472 | case DW_TAG_class_type: |
680b30c7 | 3473 | case DW_TAG_interface_type: |
c906108c | 3474 | case DW_TAG_structure_type: |
72bf9492 | 3475 | if (!pdi->is_declaration) |
c906108c | 3476 | { |
72bf9492 | 3477 | add_partial_symbol (pdi, cu); |
c906108c SS |
3478 | } |
3479 | break; | |
91c24f0a | 3480 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
3481 | if (!pdi->is_declaration) |
3482 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
3483 | break; |
3484 | case DW_TAG_base_type: | |
a02abb62 | 3485 | case DW_TAG_subrange_type: |
c906108c | 3486 | /* File scope base type definitions are added to the partial |
c5aa993b | 3487 | symbol table. */ |
72bf9492 | 3488 | add_partial_symbol (pdi, cu); |
c906108c | 3489 | break; |
d9fa45fe | 3490 | case DW_TAG_namespace: |
5734ee8b | 3491 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 3492 | break; |
5d7cb8df JK |
3493 | case DW_TAG_module: |
3494 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
3495 | break; | |
c906108c SS |
3496 | default: |
3497 | break; | |
3498 | } | |
3499 | } | |
3500 | ||
72bf9492 DJ |
3501 | /* If the die has a sibling, skip to the sibling. */ |
3502 | ||
3503 | pdi = pdi->die_sibling; | |
3504 | } | |
3505 | } | |
3506 | ||
3507 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 3508 | |
72bf9492 | 3509 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
3510 | name is concatenated with "::" and the partial DIE's name. For |
3511 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
3512 | Enumerators are an exception; they use the scope of their parent |
3513 | enumeration type, i.e. the name of the enumeration type is not | |
3514 | prepended to the enumerator. | |
91c24f0a | 3515 | |
72bf9492 DJ |
3516 | There are two complexities. One is DW_AT_specification; in this |
3517 | case "parent" means the parent of the target of the specification, | |
3518 | instead of the direct parent of the DIE. The other is compilers | |
3519 | which do not emit DW_TAG_namespace; in this case we try to guess | |
3520 | the fully qualified name of structure types from their members' | |
3521 | linkage names. This must be done using the DIE's children rather | |
3522 | than the children of any DW_AT_specification target. We only need | |
3523 | to do this for structures at the top level, i.e. if the target of | |
3524 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
3525 | have a parent. */ | |
3526 | ||
3527 | /* Compute the scope prefix associated with PDI's parent, in | |
3528 | compilation unit CU. The result will be allocated on CU's | |
3529 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
3530 | field. NULL is returned if no prefix is necessary. */ | |
3531 | static char * | |
3532 | partial_die_parent_scope (struct partial_die_info *pdi, | |
3533 | struct dwarf2_cu *cu) | |
3534 | { | |
3535 | char *grandparent_scope; | |
3536 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 3537 | |
72bf9492 DJ |
3538 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
3539 | then this means the parent of the specification DIE. */ | |
3540 | ||
3541 | real_pdi = pdi; | |
72bf9492 | 3542 | while (real_pdi->has_specification) |
10b3939b | 3543 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
3544 | |
3545 | parent = real_pdi->die_parent; | |
3546 | if (parent == NULL) | |
3547 | return NULL; | |
3548 | ||
3549 | if (parent->scope_set) | |
3550 | return parent->scope; | |
3551 | ||
3552 | fixup_partial_die (parent, cu); | |
3553 | ||
10b3939b | 3554 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 | 3555 | |
acebe513 UW |
3556 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
3557 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
3558 | Work around this problem here. */ | |
3559 | if (cu->language == language_cplus | |
6e70227d | 3560 | && parent->tag == DW_TAG_namespace |
acebe513 UW |
3561 | && strcmp (parent->name, "::") == 0 |
3562 | && grandparent_scope == NULL) | |
3563 | { | |
3564 | parent->scope = NULL; | |
3565 | parent->scope_set = 1; | |
3566 | return NULL; | |
3567 | } | |
3568 | ||
72bf9492 | 3569 | if (parent->tag == DW_TAG_namespace |
f55ee35c | 3570 | || parent->tag == DW_TAG_module |
72bf9492 DJ |
3571 | || parent->tag == DW_TAG_structure_type |
3572 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 3573 | || parent->tag == DW_TAG_interface_type |
ceeb3d5a TT |
3574 | || parent->tag == DW_TAG_union_type |
3575 | || parent->tag == DW_TAG_enumeration_type) | |
72bf9492 DJ |
3576 | { |
3577 | if (grandparent_scope == NULL) | |
3578 | parent->scope = parent->name; | |
3579 | else | |
987504bb | 3580 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
f55ee35c | 3581 | parent->name, 0, cu); |
72bf9492 | 3582 | } |
ceeb3d5a | 3583 | else if (parent->tag == DW_TAG_enumerator) |
72bf9492 DJ |
3584 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
3585 | parent->scope = grandparent_scope; | |
3586 | else | |
3587 | { | |
3588 | /* FIXME drow/2004-04-01: What should we be doing with | |
3589 | function-local names? For partial symbols, we should probably be | |
3590 | ignoring them. */ | |
3591 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3592 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
3593 | parent->tag, pdi->offset); |
3594 | parent->scope = grandparent_scope; | |
c906108c SS |
3595 | } |
3596 | ||
72bf9492 DJ |
3597 | parent->scope_set = 1; |
3598 | return parent->scope; | |
3599 | } | |
3600 | ||
3601 | /* Return the fully scoped name associated with PDI, from compilation unit | |
3602 | CU. The result will be allocated with malloc. */ | |
3603 | static char * | |
3604 | partial_die_full_name (struct partial_die_info *pdi, | |
3605 | struct dwarf2_cu *cu) | |
3606 | { | |
3607 | char *parent_scope; | |
3608 | ||
98bfdba5 PA |
3609 | /* If this is a template instantiation, we can not work out the |
3610 | template arguments from partial DIEs. So, unfortunately, we have | |
3611 | to go through the full DIEs. At least any work we do building | |
3612 | types here will be reused if full symbols are loaded later. */ | |
3613 | if (pdi->has_template_arguments) | |
3614 | { | |
3615 | fixup_partial_die (pdi, cu); | |
3616 | ||
3617 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) | |
3618 | { | |
3619 | struct die_info *die; | |
3620 | struct attribute attr; | |
3621 | struct dwarf2_cu *ref_cu = cu; | |
3622 | ||
3623 | attr.name = 0; | |
3624 | attr.form = DW_FORM_ref_addr; | |
3625 | attr.u.addr = pdi->offset; | |
3626 | die = follow_die_ref (NULL, &attr, &ref_cu); | |
3627 | ||
3628 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); | |
3629 | } | |
3630 | } | |
3631 | ||
72bf9492 DJ |
3632 | parent_scope = partial_die_parent_scope (pdi, cu); |
3633 | if (parent_scope == NULL) | |
3634 | return NULL; | |
3635 | else | |
f55ee35c | 3636 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
c906108c SS |
3637 | } |
3638 | ||
3639 | static void | |
72bf9492 | 3640 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 3641 | { |
e7c27a73 | 3642 | struct objfile *objfile = cu->objfile; |
c906108c | 3643 | CORE_ADDR addr = 0; |
decbce07 | 3644 | char *actual_name = NULL; |
5c4e30ca | 3645 | const struct partial_symbol *psym = NULL; |
e142c38c | 3646 | CORE_ADDR baseaddr; |
72bf9492 | 3647 | int built_actual_name = 0; |
e142c38c DJ |
3648 | |
3649 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3650 | |
94af9270 KS |
3651 | actual_name = partial_die_full_name (pdi, cu); |
3652 | if (actual_name) | |
3653 | built_actual_name = 1; | |
63d06c5c | 3654 | |
72bf9492 DJ |
3655 | if (actual_name == NULL) |
3656 | actual_name = pdi->name; | |
3657 | ||
c906108c SS |
3658 | switch (pdi->tag) |
3659 | { | |
3660 | case DW_TAG_subprogram: | |
2cfa0c8d | 3661 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 3662 | { |
2cfa0c8d JB |
3663 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
3664 | of the global scope. But in Ada, we want to be able to access | |
3665 | nested procedures globally. So all Ada subprograms are stored | |
3666 | in the global scope. */ | |
38d518c9 | 3667 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3668 | mst_text, objfile); */ |
38d518c9 | 3669 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3670 | built_actual_name, |
5c4e30ca DC |
3671 | VAR_DOMAIN, LOC_BLOCK, |
3672 | &objfile->global_psymbols, | |
3673 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3674 | cu->language, objfile); |
c906108c SS |
3675 | } |
3676 | else | |
3677 | { | |
38d518c9 | 3678 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 3679 | mst_file_text, objfile); */ |
38d518c9 | 3680 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3681 | built_actual_name, |
5c4e30ca DC |
3682 | VAR_DOMAIN, LOC_BLOCK, |
3683 | &objfile->static_psymbols, | |
3684 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 3685 | cu->language, objfile); |
c906108c SS |
3686 | } |
3687 | break; | |
3688 | case DW_TAG_variable: | |
caac4577 JG |
3689 | if (pdi->locdesc) |
3690 | addr = decode_locdesc (pdi->locdesc, cu); | |
3691 | ||
3692 | if (pdi->locdesc | |
3693 | && addr == 0 | |
3694 | && !dwarf2_per_objfile->has_section_at_zero) | |
3695 | { | |
3696 | /* A global or static variable may also have been stripped | |
3697 | out by the linker if unused, in which case its address | |
3698 | will be nullified; do not add such variables into partial | |
3699 | symbol table then. */ | |
3700 | } | |
3701 | else if (pdi->is_external) | |
c906108c SS |
3702 | { |
3703 | /* Global Variable. | |
3704 | Don't enter into the minimal symbol tables as there is | |
3705 | a minimal symbol table entry from the ELF symbols already. | |
3706 | Enter into partial symbol table if it has a location | |
3707 | descriptor or a type. | |
3708 | If the location descriptor is missing, new_symbol will create | |
3709 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
3710 | be determined from the minimal symbol table whenever the variable | |
3711 | is referenced. | |
3712 | The address for the partial symbol table entry is not | |
3713 | used by GDB, but it comes in handy for debugging partial symbol | |
3714 | table building. */ | |
3715 | ||
c906108c | 3716 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 3717 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3718 | built_actual_name, |
5c4e30ca DC |
3719 | VAR_DOMAIN, LOC_STATIC, |
3720 | &objfile->global_psymbols, | |
3721 | 0, addr + baseaddr, | |
e142c38c | 3722 | cu->language, objfile); |
c906108c SS |
3723 | } |
3724 | else | |
3725 | { | |
3726 | /* Static Variable. Skip symbols without location descriptors. */ | |
3727 | if (pdi->locdesc == NULL) | |
decbce07 MS |
3728 | { |
3729 | if (built_actual_name) | |
3730 | xfree (actual_name); | |
3731 | return; | |
3732 | } | |
38d518c9 | 3733 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 3734 | mst_file_data, objfile); */ |
38d518c9 | 3735 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3736 | built_actual_name, |
5c4e30ca DC |
3737 | VAR_DOMAIN, LOC_STATIC, |
3738 | &objfile->static_psymbols, | |
3739 | 0, addr + baseaddr, | |
e142c38c | 3740 | cu->language, objfile); |
c906108c SS |
3741 | } |
3742 | break; | |
3743 | case DW_TAG_typedef: | |
3744 | case DW_TAG_base_type: | |
a02abb62 | 3745 | case DW_TAG_subrange_type: |
38d518c9 | 3746 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3747 | built_actual_name, |
176620f1 | 3748 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 3749 | &objfile->static_psymbols, |
e142c38c | 3750 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3751 | break; |
72bf9492 DJ |
3752 | case DW_TAG_namespace: |
3753 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
04a679b8 | 3754 | built_actual_name, |
72bf9492 DJ |
3755 | VAR_DOMAIN, LOC_TYPEDEF, |
3756 | &objfile->global_psymbols, | |
3757 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
3758 | break; | |
c906108c | 3759 | case DW_TAG_class_type: |
680b30c7 | 3760 | case DW_TAG_interface_type: |
c906108c SS |
3761 | case DW_TAG_structure_type: |
3762 | case DW_TAG_union_type: | |
3763 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
3764 | /* Skip external references. The DWARF standard says in the section |
3765 | about "Structure, Union, and Class Type Entries": "An incomplete | |
3766 | structure, union or class type is represented by a structure, | |
3767 | union or class entry that does not have a byte size attribute | |
3768 | and that has a DW_AT_declaration attribute." */ | |
3769 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
3770 | { |
3771 | if (built_actual_name) | |
3772 | xfree (actual_name); | |
3773 | return; | |
3774 | } | |
fa4028e9 | 3775 | |
63d06c5c DC |
3776 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
3777 | static vs. global. */ | |
38d518c9 | 3778 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3779 | built_actual_name, |
176620f1 | 3780 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
3781 | (cu->language == language_cplus |
3782 | || cu->language == language_java) | |
63d06c5c DC |
3783 | ? &objfile->global_psymbols |
3784 | : &objfile->static_psymbols, | |
e142c38c | 3785 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 3786 | |
c906108c SS |
3787 | break; |
3788 | case DW_TAG_enumerator: | |
38d518c9 | 3789 | add_psymbol_to_list (actual_name, strlen (actual_name), |
04a679b8 | 3790 | built_actual_name, |
176620f1 | 3791 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
3792 | (cu->language == language_cplus |
3793 | || cu->language == language_java) | |
f6fe98ef DJ |
3794 | ? &objfile->global_psymbols |
3795 | : &objfile->static_psymbols, | |
e142c38c | 3796 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
3797 | break; |
3798 | default: | |
3799 | break; | |
3800 | } | |
5c4e30ca | 3801 | |
72bf9492 DJ |
3802 | if (built_actual_name) |
3803 | xfree (actual_name); | |
c906108c SS |
3804 | } |
3805 | ||
5c4e30ca DC |
3806 | /* Read a partial die corresponding to a namespace; also, add a symbol |
3807 | corresponding to that namespace to the symbol table. NAMESPACE is | |
3808 | the name of the enclosing namespace. */ | |
91c24f0a | 3809 | |
72bf9492 DJ |
3810 | static void |
3811 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 3812 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 3813 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 3814 | { |
72bf9492 | 3815 | /* Add a symbol for the namespace. */ |
e7c27a73 | 3816 | |
72bf9492 | 3817 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
3818 | |
3819 | /* Now scan partial symbols in that namespace. */ | |
3820 | ||
91c24f0a | 3821 | if (pdi->has_children) |
5734ee8b | 3822 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
3823 | } |
3824 | ||
5d7cb8df JK |
3825 | /* Read a partial die corresponding to a Fortran module. */ |
3826 | ||
3827 | static void | |
3828 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
3829 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
3830 | { | |
f55ee35c | 3831 | /* Now scan partial symbols in that module. */ |
5d7cb8df JK |
3832 | |
3833 | if (pdi->has_children) | |
3834 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
3835 | } | |
3836 | ||
bc30ff58 JB |
3837 | /* Read a partial die corresponding to a subprogram and create a partial |
3838 | symbol for that subprogram. When the CU language allows it, this | |
3839 | routine also defines a partial symbol for each nested subprogram | |
3840 | that this subprogram contains. | |
6e70227d | 3841 | |
bc30ff58 JB |
3842 | DIE my also be a lexical block, in which case we simply search |
3843 | recursively for suprograms defined inside that lexical block. | |
3844 | Again, this is only performed when the CU language allows this | |
3845 | type of definitions. */ | |
3846 | ||
3847 | static void | |
3848 | add_partial_subprogram (struct partial_die_info *pdi, | |
3849 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 3850 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
3851 | { |
3852 | if (pdi->tag == DW_TAG_subprogram) | |
3853 | { | |
3854 | if (pdi->has_pc_info) | |
3855 | { | |
3856 | if (pdi->lowpc < *lowpc) | |
3857 | *lowpc = pdi->lowpc; | |
3858 | if (pdi->highpc > *highpc) | |
3859 | *highpc = pdi->highpc; | |
5734ee8b DJ |
3860 | if (need_pc) |
3861 | { | |
3862 | CORE_ADDR baseaddr; | |
3863 | struct objfile *objfile = cu->objfile; | |
3864 | ||
3865 | baseaddr = ANOFFSET (objfile->section_offsets, | |
3866 | SECT_OFF_TEXT (objfile)); | |
3867 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
01637564 DE |
3868 | pdi->lowpc + baseaddr, |
3869 | pdi->highpc - 1 + baseaddr, | |
9291a0cd | 3870 | cu->per_cu->v.psymtab); |
5734ee8b | 3871 | } |
bc30ff58 | 3872 | if (!pdi->is_declaration) |
e8d05480 JB |
3873 | /* Ignore subprogram DIEs that do not have a name, they are |
3874 | illegal. Do not emit a complaint at this point, we will | |
3875 | do so when we convert this psymtab into a symtab. */ | |
3876 | if (pdi->name) | |
3877 | add_partial_symbol (pdi, cu); | |
bc30ff58 JB |
3878 | } |
3879 | } | |
6e70227d | 3880 | |
bc30ff58 JB |
3881 | if (! pdi->has_children) |
3882 | return; | |
3883 | ||
3884 | if (cu->language == language_ada) | |
3885 | { | |
3886 | pdi = pdi->die_child; | |
3887 | while (pdi != NULL) | |
3888 | { | |
3889 | fixup_partial_die (pdi, cu); | |
3890 | if (pdi->tag == DW_TAG_subprogram | |
3891 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 3892 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
3893 | pdi = pdi->die_sibling; |
3894 | } | |
3895 | } | |
3896 | } | |
3897 | ||
72bf9492 DJ |
3898 | /* See if we can figure out if the class lives in a namespace. We do |
3899 | this by looking for a member function; its demangled name will | |
3900 | contain namespace info, if there is any. */ | |
63d06c5c | 3901 | |
72bf9492 DJ |
3902 | static void |
3903 | guess_structure_name (struct partial_die_info *struct_pdi, | |
3904 | struct dwarf2_cu *cu) | |
63d06c5c | 3905 | { |
987504bb JJ |
3906 | if ((cu->language == language_cplus |
3907 | || cu->language == language_java) | |
72bf9492 | 3908 | && cu->has_namespace_info == 0 |
63d06c5c DC |
3909 | && struct_pdi->has_children) |
3910 | { | |
63d06c5c DC |
3911 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
3912 | what template types look like, because the demangler | |
3913 | frequently doesn't give the same name as the debug info. We | |
3914 | could fix this by only using the demangled name to get the | |
134d01f1 | 3915 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 3916 | |
72bf9492 | 3917 | struct partial_die_info *real_pdi; |
5d51ca54 | 3918 | |
72bf9492 DJ |
3919 | /* If this DIE (this DIE's specification, if any) has a parent, then |
3920 | we should not do this. We'll prepend the parent's fully qualified | |
3921 | name when we create the partial symbol. */ | |
5d51ca54 | 3922 | |
72bf9492 | 3923 | real_pdi = struct_pdi; |
72bf9492 | 3924 | while (real_pdi->has_specification) |
10b3939b | 3925 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 3926 | |
72bf9492 DJ |
3927 | if (real_pdi->die_parent != NULL) |
3928 | return; | |
63d06c5c | 3929 | } |
63d06c5c DC |
3930 | } |
3931 | ||
91c24f0a DC |
3932 | /* Read a partial die corresponding to an enumeration type. */ |
3933 | ||
72bf9492 DJ |
3934 | static void |
3935 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
3936 | struct dwarf2_cu *cu) | |
91c24f0a | 3937 | { |
72bf9492 | 3938 | struct partial_die_info *pdi; |
91c24f0a DC |
3939 | |
3940 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
3941 | add_partial_symbol (enum_pdi, cu); |
3942 | ||
3943 | pdi = enum_pdi->die_child; | |
3944 | while (pdi) | |
91c24f0a | 3945 | { |
72bf9492 | 3946 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 3947 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 3948 | else |
72bf9492 DJ |
3949 | add_partial_symbol (pdi, cu); |
3950 | pdi = pdi->die_sibling; | |
91c24f0a | 3951 | } |
91c24f0a DC |
3952 | } |
3953 | ||
4bb7a0a7 DJ |
3954 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
3955 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
3956 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
3957 | the initial number. */ | |
3958 | ||
3959 | static struct abbrev_info * | |
fe1b8b76 | 3960 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 3961 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3962 | { |
3963 | bfd *abfd = cu->objfile->obfd; | |
3964 | unsigned int abbrev_number; | |
3965 | struct abbrev_info *abbrev; | |
3966 | ||
3967 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
3968 | ||
3969 | if (abbrev_number == 0) | |
3970 | return NULL; | |
3971 | ||
3972 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
3973 | if (!abbrev) | |
3974 | { | |
8a3fe4f8 | 3975 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
3976 | bfd_get_filename (abfd)); |
3977 | } | |
3978 | ||
3979 | return abbrev; | |
3980 | } | |
3981 | ||
93311388 DE |
3982 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
3983 | Returns a pointer to the end of a series of DIEs, terminated by an empty | |
4bb7a0a7 DJ |
3984 | DIE. Any children of the skipped DIEs will also be skipped. */ |
3985 | ||
fe1b8b76 | 3986 | static gdb_byte * |
93311388 | 3987 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
3988 | { |
3989 | struct abbrev_info *abbrev; | |
3990 | unsigned int bytes_read; | |
3991 | ||
3992 | while (1) | |
3993 | { | |
3994 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
3995 | if (abbrev == NULL) | |
3996 | return info_ptr + bytes_read; | |
3997 | else | |
93311388 | 3998 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
4bb7a0a7 DJ |
3999 | } |
4000 | } | |
4001 | ||
93311388 DE |
4002 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
4003 | INFO_PTR should point just after the initial uleb128 of a DIE, and the | |
4bb7a0a7 DJ |
4004 | abbrev corresponding to that skipped uleb128 should be passed in |
4005 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
4006 | children. */ | |
4007 | ||
fe1b8b76 | 4008 | static gdb_byte * |
93311388 DE |
4009 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
4010 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
4011 | { |
4012 | unsigned int bytes_read; | |
4013 | struct attribute attr; | |
4014 | bfd *abfd = cu->objfile->obfd; | |
4015 | unsigned int form, i; | |
4016 | ||
4017 | for (i = 0; i < abbrev->num_attrs; i++) | |
4018 | { | |
4019 | /* The only abbrev we care about is DW_AT_sibling. */ | |
4020 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
4021 | { | |
4022 | read_attribute (&attr, &abbrev->attrs[i], | |
4023 | abfd, info_ptr, cu); | |
4024 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 4025 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 4026 | else |
93311388 | 4027 | return buffer + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
4028 | } |
4029 | ||
4030 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
4031 | form = abbrev->attrs[i].form; | |
4032 | skip_attribute: | |
4033 | switch (form) | |
4034 | { | |
4bb7a0a7 | 4035 | case DW_FORM_ref_addr: |
ae411497 TT |
4036 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
4037 | and later it is offset sized. */ | |
4038 | if (cu->header.version == 2) | |
4039 | info_ptr += cu->header.addr_size; | |
4040 | else | |
4041 | info_ptr += cu->header.offset_size; | |
4042 | break; | |
4043 | case DW_FORM_addr: | |
4bb7a0a7 DJ |
4044 | info_ptr += cu->header.addr_size; |
4045 | break; | |
4046 | case DW_FORM_data1: | |
4047 | case DW_FORM_ref1: | |
4048 | case DW_FORM_flag: | |
4049 | info_ptr += 1; | |
4050 | break; | |
2dc7f7b3 TT |
4051 | case DW_FORM_flag_present: |
4052 | break; | |
4bb7a0a7 DJ |
4053 | case DW_FORM_data2: |
4054 | case DW_FORM_ref2: | |
4055 | info_ptr += 2; | |
4056 | break; | |
4057 | case DW_FORM_data4: | |
4058 | case DW_FORM_ref4: | |
4059 | info_ptr += 4; | |
4060 | break; | |
4061 | case DW_FORM_data8: | |
4062 | case DW_FORM_ref8: | |
348e048f | 4063 | case DW_FORM_sig8: |
4bb7a0a7 DJ |
4064 | info_ptr += 8; |
4065 | break; | |
4066 | case DW_FORM_string: | |
9b1c24c8 | 4067 | read_direct_string (abfd, info_ptr, &bytes_read); |
4bb7a0a7 DJ |
4068 | info_ptr += bytes_read; |
4069 | break; | |
2dc7f7b3 | 4070 | case DW_FORM_sec_offset: |
4bb7a0a7 DJ |
4071 | case DW_FORM_strp: |
4072 | info_ptr += cu->header.offset_size; | |
4073 | break; | |
2dc7f7b3 | 4074 | case DW_FORM_exprloc: |
4bb7a0a7 DJ |
4075 | case DW_FORM_block: |
4076 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4077 | info_ptr += bytes_read; | |
4078 | break; | |
4079 | case DW_FORM_block1: | |
4080 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
4081 | break; | |
4082 | case DW_FORM_block2: | |
4083 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
4084 | break; | |
4085 | case DW_FORM_block4: | |
4086 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
4087 | break; | |
4088 | case DW_FORM_sdata: | |
4089 | case DW_FORM_udata: | |
4090 | case DW_FORM_ref_udata: | |
4091 | info_ptr = skip_leb128 (abfd, info_ptr); | |
4092 | break; | |
4093 | case DW_FORM_indirect: | |
4094 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
4095 | info_ptr += bytes_read; | |
4096 | /* We need to continue parsing from here, so just go back to | |
4097 | the top. */ | |
4098 | goto skip_attribute; | |
4099 | ||
4100 | default: | |
8a3fe4f8 | 4101 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
4102 | dwarf_form_name (form), |
4103 | bfd_get_filename (abfd)); | |
4104 | } | |
4105 | } | |
4106 | ||
4107 | if (abbrev->has_children) | |
93311388 | 4108 | return skip_children (buffer, info_ptr, cu); |
4bb7a0a7 DJ |
4109 | else |
4110 | return info_ptr; | |
4111 | } | |
4112 | ||
93311388 DE |
4113 | /* Locate ORIG_PDI's sibling. |
4114 | INFO_PTR should point to the start of the next DIE after ORIG_PDI | |
4115 | in BUFFER. */ | |
91c24f0a | 4116 | |
fe1b8b76 | 4117 | static gdb_byte * |
93311388 DE |
4118 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
4119 | gdb_byte *buffer, gdb_byte *info_ptr, | |
e7c27a73 | 4120 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
4121 | { |
4122 | /* Do we know the sibling already? */ | |
72bf9492 | 4123 | |
91c24f0a DC |
4124 | if (orig_pdi->sibling) |
4125 | return orig_pdi->sibling; | |
4126 | ||
4127 | /* Are there any children to deal with? */ | |
4128 | ||
4129 | if (!orig_pdi->has_children) | |
4130 | return info_ptr; | |
4131 | ||
4bb7a0a7 | 4132 | /* Skip the children the long way. */ |
91c24f0a | 4133 | |
93311388 | 4134 | return skip_children (buffer, info_ptr, cu); |
91c24f0a DC |
4135 | } |
4136 | ||
c906108c SS |
4137 | /* Expand this partial symbol table into a full symbol table. */ |
4138 | ||
4139 | static void | |
fba45db2 | 4140 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c | 4141 | { |
c906108c SS |
4142 | if (pst != NULL) |
4143 | { | |
4144 | if (pst->readin) | |
4145 | { | |
8a3fe4f8 | 4146 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
4147 | } |
4148 | else | |
4149 | { | |
4150 | if (info_verbose) | |
4151 | { | |
a3f17187 | 4152 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
4153 | gdb_flush (gdb_stdout); |
4154 | } | |
4155 | ||
10b3939b DJ |
4156 | /* Restore our global data. */ |
4157 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
4158 | dwarf2_objfile_data_key); | |
4159 | ||
b2ab525c KB |
4160 | /* If this psymtab is constructed from a debug-only objfile, the |
4161 | has_section_at_zero flag will not necessarily be correct. We | |
4162 | can get the correct value for this flag by looking at the data | |
4163 | associated with the (presumably stripped) associated objfile. */ | |
4164 | if (pst->objfile->separate_debug_objfile_backlink) | |
4165 | { | |
4166 | struct dwarf2_per_objfile *dpo_backlink | |
4167 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
4168 | dwarf2_objfile_data_key); | |
9a619af0 | 4169 | |
b2ab525c KB |
4170 | dwarf2_per_objfile->has_section_at_zero |
4171 | = dpo_backlink->has_section_at_zero; | |
4172 | } | |
4173 | ||
98bfdba5 PA |
4174 | dwarf2_per_objfile->reading_partial_symbols = 0; |
4175 | ||
c906108c SS |
4176 | psymtab_to_symtab_1 (pst); |
4177 | ||
4178 | /* Finish up the debug error message. */ | |
4179 | if (info_verbose) | |
a3f17187 | 4180 | printf_filtered (_("done.\n")); |
c906108c SS |
4181 | } |
4182 | } | |
4183 | } | |
4184 | ||
10b3939b DJ |
4185 | /* Add PER_CU to the queue. */ |
4186 | ||
4187 | static void | |
03dd20cc | 4188 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
4189 | { |
4190 | struct dwarf2_queue_item *item; | |
4191 | ||
4192 | per_cu->queued = 1; | |
4193 | item = xmalloc (sizeof (*item)); | |
4194 | item->per_cu = per_cu; | |
4195 | item->next = NULL; | |
4196 | ||
4197 | if (dwarf2_queue == NULL) | |
4198 | dwarf2_queue = item; | |
4199 | else | |
4200 | dwarf2_queue_tail->next = item; | |
4201 | ||
4202 | dwarf2_queue_tail = item; | |
4203 | } | |
4204 | ||
4205 | /* Process the queue. */ | |
4206 | ||
4207 | static void | |
4208 | process_queue (struct objfile *objfile) | |
4209 | { | |
4210 | struct dwarf2_queue_item *item, *next_item; | |
4211 | ||
03dd20cc DJ |
4212 | /* The queue starts out with one item, but following a DIE reference |
4213 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
4214 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
4215 | { | |
9291a0cd TT |
4216 | if (dwarf2_per_objfile->using_index |
4217 | ? !item->per_cu->v.quick->symtab | |
4218 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) | |
10b3939b DJ |
4219 | process_full_comp_unit (item->per_cu); |
4220 | ||
4221 | item->per_cu->queued = 0; | |
4222 | next_item = item->next; | |
4223 | xfree (item); | |
4224 | } | |
4225 | ||
4226 | dwarf2_queue_tail = NULL; | |
4227 | } | |
4228 | ||
4229 | /* Free all allocated queue entries. This function only releases anything if | |
4230 | an error was thrown; if the queue was processed then it would have been | |
4231 | freed as we went along. */ | |
4232 | ||
4233 | static void | |
4234 | dwarf2_release_queue (void *dummy) | |
4235 | { | |
4236 | struct dwarf2_queue_item *item, *last; | |
4237 | ||
4238 | item = dwarf2_queue; | |
4239 | while (item) | |
4240 | { | |
4241 | /* Anything still marked queued is likely to be in an | |
4242 | inconsistent state, so discard it. */ | |
4243 | if (item->per_cu->queued) | |
4244 | { | |
4245 | if (item->per_cu->cu != NULL) | |
4246 | free_one_cached_comp_unit (item->per_cu->cu); | |
4247 | item->per_cu->queued = 0; | |
4248 | } | |
4249 | ||
4250 | last = item; | |
4251 | item = item->next; | |
4252 | xfree (last); | |
4253 | } | |
4254 | ||
4255 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
4256 | } | |
4257 | ||
4258 | /* Read in full symbols for PST, and anything it depends on. */ | |
4259 | ||
c906108c | 4260 | static void |
fba45db2 | 4261 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 4262 | { |
10b3939b | 4263 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 4264 | struct cleanup *back_to; |
aaa75496 JB |
4265 | int i; |
4266 | ||
4267 | for (i = 0; i < pst->number_of_dependencies; i++) | |
4268 | if (!pst->dependencies[i]->readin) | |
4269 | { | |
4270 | /* Inform about additional files that need to be read in. */ | |
4271 | if (info_verbose) | |
4272 | { | |
a3f17187 | 4273 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
4274 | fputs_filtered (" ", gdb_stdout); |
4275 | wrap_here (""); | |
4276 | fputs_filtered ("and ", gdb_stdout); | |
4277 | wrap_here (""); | |
4278 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
4279 | wrap_here (""); /* Flush output */ | |
4280 | gdb_flush (gdb_stdout); | |
4281 | } | |
4282 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
4283 | } | |
4284 | ||
e38df1d0 | 4285 | per_cu = pst->read_symtab_private; |
10b3939b DJ |
4286 | |
4287 | if (per_cu == NULL) | |
aaa75496 JB |
4288 | { |
4289 | /* It's an include file, no symbols to read for it. | |
4290 | Everything is in the parent symtab. */ | |
4291 | pst->readin = 1; | |
4292 | return; | |
4293 | } | |
c906108c | 4294 | |
9291a0cd | 4295 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
10b3939b DJ |
4296 | } |
4297 | ||
93311388 | 4298 | /* Load the DIEs associated with PER_CU into memory. */ |
10b3939b | 4299 | |
93311388 | 4300 | static void |
31ffec48 | 4301 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 4302 | { |
31ffec48 | 4303 | bfd *abfd = objfile->obfd; |
10b3939b | 4304 | struct dwarf2_cu *cu; |
c764a876 | 4305 | unsigned int offset; |
93311388 | 4306 | gdb_byte *info_ptr, *beg_of_comp_unit; |
98bfdba5 | 4307 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
10b3939b | 4308 | struct attribute *attr; |
98bfdba5 | 4309 | int read_cu = 0; |
6502dd73 | 4310 | |
348e048f DE |
4311 | gdb_assert (! per_cu->from_debug_types); |
4312 | ||
c906108c | 4313 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 4314 | offset = per_cu->offset; |
6502dd73 | 4315 | |
be391dca | 4316 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
dce234bc | 4317 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
93311388 | 4318 | beg_of_comp_unit = info_ptr; |
63d06c5c | 4319 | |
98bfdba5 PA |
4320 | if (per_cu->cu == NULL) |
4321 | { | |
4322 | cu = alloc_one_comp_unit (objfile); | |
4323 | ||
4324 | read_cu = 1; | |
c906108c | 4325 | |
98bfdba5 PA |
4326 | /* If an error occurs while loading, release our storage. */ |
4327 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 4328 | |
98bfdba5 PA |
4329 | /* Read in the comp_unit header. */ |
4330 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |
c906108c | 4331 | |
98bfdba5 PA |
4332 | /* Complete the cu_header. */ |
4333 | cu->header.offset = offset; | |
4334 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; | |
93311388 | 4335 | |
98bfdba5 PA |
4336 | /* Read the abbrevs for this compilation unit. */ |
4337 | dwarf2_read_abbrevs (abfd, cu); | |
4338 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); | |
10b3939b | 4339 | |
98bfdba5 PA |
4340 | /* Link this compilation unit into the compilation unit tree. */ |
4341 | per_cu->cu = cu; | |
4342 | cu->per_cu = per_cu; | |
98bfdba5 PA |
4343 | |
4344 | /* Link this CU into read_in_chain. */ | |
4345 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
4346 | dwarf2_per_objfile->read_in_chain = per_cu; | |
4347 | } | |
4348 | else | |
4349 | { | |
4350 | cu = per_cu->cu; | |
4351 | info_ptr += cu->header.first_die_offset; | |
4352 | } | |
e142c38c | 4353 | |
93311388 | 4354 | cu->dies = read_comp_unit (info_ptr, cu); |
10b3939b DJ |
4355 | |
4356 | /* We try not to read any attributes in this function, because not | |
4357 | all objfiles needed for references have been loaded yet, and symbol | |
4358 | table processing isn't initialized. But we have to set the CU language, | |
4359 | or we won't be able to build types correctly. */ | |
4360 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
4361 | if (attr) | |
4362 | set_cu_language (DW_UNSND (attr), cu); | |
4363 | else | |
4364 | set_cu_language (language_minimal, cu); | |
4365 | ||
a6c727b2 DJ |
4366 | /* Similarly, if we do not read the producer, we can not apply |
4367 | producer-specific interpretation. */ | |
4368 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); | |
4369 | if (attr) | |
4370 | cu->producer = DW_STRING (attr); | |
4371 | ||
98bfdba5 PA |
4372 | if (read_cu) |
4373 | { | |
4374 | do_cleanups (free_abbrevs_cleanup); | |
e142c38c | 4375 | |
98bfdba5 PA |
4376 | /* We've successfully allocated this compilation unit. Let our |
4377 | caller clean it up when finished with it. */ | |
4378 | discard_cleanups (free_cu_cleanup); | |
4379 | } | |
10b3939b DJ |
4380 | } |
4381 | ||
3da10d80 KS |
4382 | /* Add a DIE to the delayed physname list. */ |
4383 | ||
4384 | static void | |
4385 | add_to_method_list (struct type *type, int fnfield_index, int index, | |
4386 | const char *name, struct die_info *die, | |
4387 | struct dwarf2_cu *cu) | |
4388 | { | |
4389 | struct delayed_method_info mi; | |
4390 | mi.type = type; | |
4391 | mi.fnfield_index = fnfield_index; | |
4392 | mi.index = index; | |
4393 | mi.name = name; | |
4394 | mi.die = die; | |
4395 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); | |
4396 | } | |
4397 | ||
4398 | /* A cleanup for freeing the delayed method list. */ | |
4399 | ||
4400 | static void | |
4401 | free_delayed_list (void *ptr) | |
4402 | { | |
4403 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; | |
4404 | if (cu->method_list != NULL) | |
4405 | { | |
4406 | VEC_free (delayed_method_info, cu->method_list); | |
4407 | cu->method_list = NULL; | |
4408 | } | |
4409 | } | |
4410 | ||
4411 | /* Compute the physnames of any methods on the CU's method list. | |
4412 | ||
4413 | The computation of method physnames is delayed in order to avoid the | |
4414 | (bad) condition that one of the method's formal parameters is of an as yet | |
4415 | incomplete type. */ | |
4416 | ||
4417 | static void | |
4418 | compute_delayed_physnames (struct dwarf2_cu *cu) | |
4419 | { | |
4420 | int i; | |
4421 | struct delayed_method_info *mi; | |
4422 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) | |
4423 | { | |
4424 | char *physname; | |
4425 | struct fn_fieldlist *fn_flp | |
4426 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); | |
4427 | physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu); | |
4428 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; | |
4429 | } | |
4430 | } | |
4431 | ||
10b3939b DJ |
4432 | /* Generate full symbol information for PST and CU, whose DIEs have |
4433 | already been loaded into memory. */ | |
4434 | ||
4435 | static void | |
4436 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
4437 | { | |
10b3939b | 4438 | struct dwarf2_cu *cu = per_cu->cu; |
9291a0cd | 4439 | struct objfile *objfile = per_cu->objfile; |
10b3939b DJ |
4440 | CORE_ADDR lowpc, highpc; |
4441 | struct symtab *symtab; | |
3da10d80 | 4442 | struct cleanup *back_to, *delayed_list_cleanup; |
10b3939b DJ |
4443 | CORE_ADDR baseaddr; |
4444 | ||
4445 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
4446 | ||
10b3939b DJ |
4447 | buildsym_init (); |
4448 | back_to = make_cleanup (really_free_pendings, NULL); | |
3da10d80 | 4449 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
10b3939b DJ |
4450 | |
4451 | cu->list_in_scope = &file_symbols; | |
c906108c | 4452 | |
d85a05f0 | 4453 | dwarf2_find_base_address (cu->dies, cu); |
0d53c4c4 | 4454 | |
c906108c | 4455 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 4456 | process_die (cu->dies, cu); |
c906108c | 4457 | |
3da10d80 KS |
4458 | /* Now that we have processed all the DIEs in the CU, all the types |
4459 | should be complete, and it should now be safe to compute all of the | |
4460 | physnames. */ | |
4461 | compute_delayed_physnames (cu); | |
4462 | do_cleanups (delayed_list_cleanup); | |
4463 | ||
fae299cd DC |
4464 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
4465 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
4466 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 4467 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 4468 | |
613e1657 | 4469 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
4470 | |
4471 | /* Set symtab language to language from DW_AT_language. | |
4472 | If the compilation is from a C file generated by language preprocessors, | |
4473 | do not set the language if it was already deduced by start_subfile. */ | |
4474 | if (symtab != NULL | |
10b3939b | 4475 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 4476 | { |
10b3939b | 4477 | symtab->language = cu->language; |
c906108c | 4478 | } |
9291a0cd TT |
4479 | |
4480 | if (dwarf2_per_objfile->using_index) | |
4481 | per_cu->v.quick->symtab = symtab; | |
4482 | else | |
4483 | { | |
4484 | struct partial_symtab *pst = per_cu->v.psymtab; | |
4485 | pst->symtab = symtab; | |
4486 | pst->readin = 1; | |
4487 | } | |
c906108c SS |
4488 | |
4489 | do_cleanups (back_to); | |
4490 | } | |
4491 | ||
4492 | /* Process a die and its children. */ | |
4493 | ||
4494 | static void | |
e7c27a73 | 4495 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4496 | { |
4497 | switch (die->tag) | |
4498 | { | |
4499 | case DW_TAG_padding: | |
4500 | break; | |
4501 | case DW_TAG_compile_unit: | |
e7c27a73 | 4502 | read_file_scope (die, cu); |
c906108c | 4503 | break; |
348e048f DE |
4504 | case DW_TAG_type_unit: |
4505 | read_type_unit_scope (die, cu); | |
4506 | break; | |
c906108c | 4507 | case DW_TAG_subprogram: |
c906108c | 4508 | case DW_TAG_inlined_subroutine: |
edb3359d | 4509 | read_func_scope (die, cu); |
c906108c SS |
4510 | break; |
4511 | case DW_TAG_lexical_block: | |
14898363 L |
4512 | case DW_TAG_try_block: |
4513 | case DW_TAG_catch_block: | |
e7c27a73 | 4514 | read_lexical_block_scope (die, cu); |
c906108c SS |
4515 | break; |
4516 | case DW_TAG_class_type: | |
680b30c7 | 4517 | case DW_TAG_interface_type: |
c906108c SS |
4518 | case DW_TAG_structure_type: |
4519 | case DW_TAG_union_type: | |
134d01f1 | 4520 | process_structure_scope (die, cu); |
c906108c SS |
4521 | break; |
4522 | case DW_TAG_enumeration_type: | |
134d01f1 | 4523 | process_enumeration_scope (die, cu); |
c906108c | 4524 | break; |
134d01f1 | 4525 | |
f792889a DJ |
4526 | /* These dies have a type, but processing them does not create |
4527 | a symbol or recurse to process the children. Therefore we can | |
4528 | read them on-demand through read_type_die. */ | |
c906108c | 4529 | case DW_TAG_subroutine_type: |
72019c9c | 4530 | case DW_TAG_set_type: |
c906108c | 4531 | case DW_TAG_array_type: |
c906108c | 4532 | case DW_TAG_pointer_type: |
c906108c | 4533 | case DW_TAG_ptr_to_member_type: |
c906108c | 4534 | case DW_TAG_reference_type: |
c906108c | 4535 | case DW_TAG_string_type: |
c906108c | 4536 | break; |
134d01f1 | 4537 | |
c906108c | 4538 | case DW_TAG_base_type: |
a02abb62 | 4539 | case DW_TAG_subrange_type: |
cb249c71 | 4540 | case DW_TAG_typedef: |
134d01f1 DJ |
4541 | /* Add a typedef symbol for the type definition, if it has a |
4542 | DW_AT_name. */ | |
f792889a | 4543 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 4544 | break; |
c906108c | 4545 | case DW_TAG_common_block: |
e7c27a73 | 4546 | read_common_block (die, cu); |
c906108c SS |
4547 | break; |
4548 | case DW_TAG_common_inclusion: | |
4549 | break; | |
d9fa45fe | 4550 | case DW_TAG_namespace: |
63d06c5c | 4551 | processing_has_namespace_info = 1; |
e7c27a73 | 4552 | read_namespace (die, cu); |
d9fa45fe | 4553 | break; |
5d7cb8df | 4554 | case DW_TAG_module: |
f55ee35c | 4555 | processing_has_namespace_info = 1; |
5d7cb8df JK |
4556 | read_module (die, cu); |
4557 | break; | |
d9fa45fe DC |
4558 | case DW_TAG_imported_declaration: |
4559 | case DW_TAG_imported_module: | |
63d06c5c | 4560 | processing_has_namespace_info = 1; |
27aa8d6a SW |
4561 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
4562 | || cu->language != language_fortran)) | |
4563 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), | |
4564 | dwarf_tag_name (die->tag)); | |
4565 | read_import_statement (die, cu); | |
d9fa45fe | 4566 | break; |
c906108c | 4567 | default: |
e7c27a73 | 4568 | new_symbol (die, NULL, cu); |
c906108c SS |
4569 | break; |
4570 | } | |
4571 | } | |
4572 | ||
94af9270 KS |
4573 | /* A helper function for dwarf2_compute_name which determines whether DIE |
4574 | needs to have the name of the scope prepended to the name listed in the | |
4575 | die. */ | |
4576 | ||
4577 | static int | |
4578 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4579 | { | |
1c809c68 TT |
4580 | struct attribute *attr; |
4581 | ||
94af9270 KS |
4582 | switch (die->tag) |
4583 | { | |
4584 | case DW_TAG_namespace: | |
4585 | case DW_TAG_typedef: | |
4586 | case DW_TAG_class_type: | |
4587 | case DW_TAG_interface_type: | |
4588 | case DW_TAG_structure_type: | |
4589 | case DW_TAG_union_type: | |
4590 | case DW_TAG_enumeration_type: | |
4591 | case DW_TAG_enumerator: | |
4592 | case DW_TAG_subprogram: | |
4593 | case DW_TAG_member: | |
4594 | return 1; | |
4595 | ||
4596 | case DW_TAG_variable: | |
4597 | /* We only need to prefix "globally" visible variables. These include | |
4598 | any variable marked with DW_AT_external or any variable that | |
4599 | lives in a namespace. [Variables in anonymous namespaces | |
4600 | require prefixing, but they are not DW_AT_external.] */ | |
4601 | ||
4602 | if (dwarf2_attr (die, DW_AT_specification, cu)) | |
4603 | { | |
4604 | struct dwarf2_cu *spec_cu = cu; | |
9a619af0 | 4605 | |
94af9270 KS |
4606 | return die_needs_namespace (die_specification (die, &spec_cu), |
4607 | spec_cu); | |
4608 | } | |
4609 | ||
1c809c68 | 4610 | attr = dwarf2_attr (die, DW_AT_external, cu); |
f55ee35c JK |
4611 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
4612 | && die->parent->tag != DW_TAG_module) | |
1c809c68 TT |
4613 | return 0; |
4614 | /* A variable in a lexical block of some kind does not need a | |
4615 | namespace, even though in C++ such variables may be external | |
4616 | and have a mangled name. */ | |
4617 | if (die->parent->tag == DW_TAG_lexical_block | |
4618 | || die->parent->tag == DW_TAG_try_block | |
1054b214 TT |
4619 | || die->parent->tag == DW_TAG_catch_block |
4620 | || die->parent->tag == DW_TAG_subprogram) | |
1c809c68 TT |
4621 | return 0; |
4622 | return 1; | |
94af9270 KS |
4623 | |
4624 | default: | |
4625 | return 0; | |
4626 | } | |
4627 | } | |
4628 | ||
98bfdba5 PA |
4629 | /* Retrieve the last character from a mem_file. */ |
4630 | ||
4631 | static void | |
4632 | do_ui_file_peek_last (void *object, const char *buffer, long length) | |
4633 | { | |
4634 | char *last_char_p = (char *) object; | |
4635 | ||
4636 | if (length > 0) | |
4637 | *last_char_p = buffer[length - 1]; | |
4638 | } | |
4639 | ||
94af9270 KS |
4640 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
4641 | compute the physname for the object, which include a method's | |
4642 | formal parameters (C++/Java) and return type (Java). | |
4643 | ||
af6b7be1 JB |
4644 | For Ada, return the DIE's linkage name rather than the fully qualified |
4645 | name. PHYSNAME is ignored.. | |
4646 | ||
94af9270 KS |
4647 | The result is allocated on the objfile_obstack and canonicalized. */ |
4648 | ||
4649 | static const char * | |
4650 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, | |
4651 | int physname) | |
4652 | { | |
4653 | if (name == NULL) | |
4654 | name = dwarf2_name (die, cu); | |
4655 | ||
f55ee35c JK |
4656 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
4657 | compute it by typename_concat inside GDB. */ | |
4658 | if (cu->language == language_ada | |
4659 | || (cu->language == language_fortran && physname)) | |
4660 | { | |
4661 | /* For Ada unit, we prefer the linkage name over the name, as | |
4662 | the former contains the exported name, which the user expects | |
4663 | to be able to reference. Ideally, we want the user to be able | |
4664 | to reference this entity using either natural or linkage name, | |
4665 | but we haven't started looking at this enhancement yet. */ | |
4666 | struct attribute *attr; | |
4667 | ||
4668 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); | |
4669 | if (attr == NULL) | |
4670 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); | |
4671 | if (attr && DW_STRING (attr)) | |
4672 | return DW_STRING (attr); | |
4673 | } | |
4674 | ||
94af9270 KS |
4675 | /* These are the only languages we know how to qualify names in. */ |
4676 | if (name != NULL | |
f55ee35c JK |
4677 | && (cu->language == language_cplus || cu->language == language_java |
4678 | || cu->language == language_fortran)) | |
94af9270 KS |
4679 | { |
4680 | if (die_needs_namespace (die, cu)) | |
4681 | { | |
4682 | long length; | |
4683 | char *prefix; | |
4684 | struct ui_file *buf; | |
4685 | ||
4686 | prefix = determine_prefix (die, cu); | |
4687 | buf = mem_fileopen (); | |
4688 | if (*prefix != '\0') | |
4689 | { | |
f55ee35c JK |
4690 | char *prefixed_name = typename_concat (NULL, prefix, name, |
4691 | physname, cu); | |
9a619af0 | 4692 | |
94af9270 KS |
4693 | fputs_unfiltered (prefixed_name, buf); |
4694 | xfree (prefixed_name); | |
4695 | } | |
4696 | else | |
4697 | fputs_unfiltered (name ? name : "", buf); | |
4698 | ||
98bfdba5 PA |
4699 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
4700 | as children with DW_TAG_template_type_param or | |
4701 | DW_TAG_value_type_param. If the latter, add them to the name | |
4702 | here. If the name already has template parameters, then | |
4703 | skip this step; some versions of GCC emit both, and | |
4704 | it is more efficient to use the pre-computed name. | |
4705 | ||
4706 | Something to keep in mind about this process: it is very | |
4707 | unlikely, or in some cases downright impossible, to produce | |
4708 | something that will match the mangled name of a function. | |
4709 | If the definition of the function has the same debug info, | |
4710 | we should be able to match up with it anyway. But fallbacks | |
4711 | using the minimal symbol, for instance to find a method | |
4712 | implemented in a stripped copy of libstdc++, will not work. | |
4713 | If we do not have debug info for the definition, we will have to | |
4714 | match them up some other way. | |
4715 | ||
4716 | When we do name matching there is a related problem with function | |
4717 | templates; two instantiated function templates are allowed to | |
4718 | differ only by their return types, which we do not add here. */ | |
4719 | ||
4720 | if (cu->language == language_cplus && strchr (name, '<') == NULL) | |
4721 | { | |
4722 | struct attribute *attr; | |
4723 | struct die_info *child; | |
4724 | int first = 1; | |
4725 | ||
4726 | die->building_fullname = 1; | |
4727 | ||
4728 | for (child = die->child; child != NULL; child = child->sibling) | |
4729 | { | |
4730 | struct type *type; | |
4731 | long value; | |
4732 | gdb_byte *bytes; | |
4733 | struct dwarf2_locexpr_baton *baton; | |
4734 | struct value *v; | |
4735 | ||
4736 | if (child->tag != DW_TAG_template_type_param | |
4737 | && child->tag != DW_TAG_template_value_param) | |
4738 | continue; | |
4739 | ||
4740 | if (first) | |
4741 | { | |
4742 | fputs_unfiltered ("<", buf); | |
4743 | first = 0; | |
4744 | } | |
4745 | else | |
4746 | fputs_unfiltered (", ", buf); | |
4747 | ||
4748 | attr = dwarf2_attr (child, DW_AT_type, cu); | |
4749 | if (attr == NULL) | |
4750 | { | |
4751 | complaint (&symfile_complaints, | |
4752 | _("template parameter missing DW_AT_type")); | |
4753 | fputs_unfiltered ("UNKNOWN_TYPE", buf); | |
4754 | continue; | |
4755 | } | |
4756 | type = die_type (child, cu); | |
4757 | ||
4758 | if (child->tag == DW_TAG_template_type_param) | |
4759 | { | |
4760 | c_print_type (type, "", buf, -1, 0); | |
4761 | continue; | |
4762 | } | |
4763 | ||
4764 | attr = dwarf2_attr (child, DW_AT_const_value, cu); | |
4765 | if (attr == NULL) | |
4766 | { | |
4767 | complaint (&symfile_complaints, | |
4768 | _("template parameter missing DW_AT_const_value")); | |
4769 | fputs_unfiltered ("UNKNOWN_VALUE", buf); | |
4770 | continue; | |
4771 | } | |
4772 | ||
4773 | dwarf2_const_value_attr (attr, type, name, | |
4774 | &cu->comp_unit_obstack, cu, | |
4775 | &value, &bytes, &baton); | |
4776 | ||
4777 | if (TYPE_NOSIGN (type)) | |
4778 | /* GDB prints characters as NUMBER 'CHAR'. If that's | |
4779 | changed, this can use value_print instead. */ | |
4780 | c_printchar (value, type, buf); | |
4781 | else | |
4782 | { | |
4783 | struct value_print_options opts; | |
4784 | ||
4785 | if (baton != NULL) | |
4786 | v = dwarf2_evaluate_loc_desc (type, NULL, | |
4787 | baton->data, | |
4788 | baton->size, | |
4789 | baton->per_cu); | |
4790 | else if (bytes != NULL) | |
4791 | { | |
4792 | v = allocate_value (type); | |
4793 | memcpy (value_contents_writeable (v), bytes, | |
4794 | TYPE_LENGTH (type)); | |
4795 | } | |
4796 | else | |
4797 | v = value_from_longest (type, value); | |
4798 | ||
4799 | /* Specify decimal so that we do not depend on the radix. */ | |
4800 | get_formatted_print_options (&opts, 'd'); | |
4801 | opts.raw = 1; | |
4802 | value_print (v, buf, &opts); | |
4803 | release_value (v); | |
4804 | value_free (v); | |
4805 | } | |
4806 | } | |
4807 | ||
4808 | die->building_fullname = 0; | |
4809 | ||
4810 | if (!first) | |
4811 | { | |
4812 | /* Close the argument list, with a space if necessary | |
4813 | (nested templates). */ | |
4814 | char last_char = '\0'; | |
4815 | ui_file_put (buf, do_ui_file_peek_last, &last_char); | |
4816 | if (last_char == '>') | |
4817 | fputs_unfiltered (" >", buf); | |
4818 | else | |
4819 | fputs_unfiltered (">", buf); | |
4820 | } | |
4821 | } | |
4822 | ||
94af9270 KS |
4823 | /* For Java and C++ methods, append formal parameter type |
4824 | information, if PHYSNAME. */ | |
6e70227d | 4825 | |
94af9270 KS |
4826 | if (physname && die->tag == DW_TAG_subprogram |
4827 | && (cu->language == language_cplus | |
4828 | || cu->language == language_java)) | |
4829 | { | |
4830 | struct type *type = read_type_die (die, cu); | |
4831 | ||
4832 | c_type_print_args (type, buf, 0, cu->language); | |
4833 | ||
4834 | if (cu->language == language_java) | |
4835 | { | |
4836 | /* For java, we must append the return type to method | |
4837 | names. */ | |
4838 | if (die->tag == DW_TAG_subprogram) | |
4839 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, | |
4840 | 0, 0); | |
4841 | } | |
4842 | else if (cu->language == language_cplus) | |
4843 | { | |
4844 | if (TYPE_NFIELDS (type) > 0 | |
4845 | && TYPE_FIELD_ARTIFICIAL (type, 0) | |
4846 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, 0)))) | |
4847 | fputs_unfiltered (" const", buf); | |
4848 | } | |
4849 | } | |
4850 | ||
4851 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, | |
4852 | &length); | |
4853 | ui_file_delete (buf); | |
4854 | ||
4855 | if (cu->language == language_cplus) | |
4856 | { | |
4857 | char *cname | |
4858 | = dwarf2_canonicalize_name (name, cu, | |
4859 | &cu->objfile->objfile_obstack); | |
9a619af0 | 4860 | |
94af9270 KS |
4861 | if (cname != NULL) |
4862 | name = cname; | |
4863 | } | |
4864 | } | |
4865 | } | |
4866 | ||
4867 | return name; | |
4868 | } | |
4869 | ||
0114d602 DJ |
4870 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
4871 | If scope qualifiers are appropriate they will be added. The result | |
4872 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
94af9270 KS |
4873 | not have a name. NAME may either be from a previous call to |
4874 | dwarf2_name or NULL. | |
4875 | ||
4876 | The output string will be canonicalized (if C++/Java). */ | |
0114d602 DJ |
4877 | |
4878 | static const char * | |
94af9270 | 4879 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
0114d602 | 4880 | { |
94af9270 KS |
4881 | return dwarf2_compute_name (name, die, cu, 0); |
4882 | } | |
0114d602 | 4883 | |
94af9270 KS |
4884 | /* Construct a physname for the given DIE in CU. NAME may either be |
4885 | from a previous call to dwarf2_name or NULL. The result will be | |
4886 | allocated on the objfile_objstack or NULL if the DIE does not have a | |
4887 | name. | |
0114d602 | 4888 | |
94af9270 | 4889 | The output string will be canonicalized (if C++/Java). */ |
0114d602 | 4890 | |
94af9270 KS |
4891 | static const char * |
4892 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) | |
4893 | { | |
4894 | return dwarf2_compute_name (name, die, cu, 1); | |
0114d602 DJ |
4895 | } |
4896 | ||
27aa8d6a SW |
4897 | /* Read the import statement specified by the given die and record it. */ |
4898 | ||
4899 | static void | |
4900 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) | |
4901 | { | |
4902 | struct attribute *import_attr; | |
4903 | struct die_info *imported_die; | |
de4affc9 | 4904 | struct dwarf2_cu *imported_cu; |
27aa8d6a | 4905 | const char *imported_name; |
794684b6 | 4906 | const char *imported_name_prefix; |
13387711 SW |
4907 | const char *canonical_name; |
4908 | const char *import_alias; | |
4909 | const char *imported_declaration = NULL; | |
794684b6 | 4910 | const char *import_prefix; |
13387711 SW |
4911 | |
4912 | char *temp; | |
27aa8d6a SW |
4913 | |
4914 | import_attr = dwarf2_attr (die, DW_AT_import, cu); | |
4915 | if (import_attr == NULL) | |
4916 | { | |
4917 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), | |
4918 | dwarf_tag_name (die->tag)); | |
4919 | return; | |
4920 | } | |
4921 | ||
de4affc9 CC |
4922 | imported_cu = cu; |
4923 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); | |
4924 | imported_name = dwarf2_name (imported_die, imported_cu); | |
27aa8d6a SW |
4925 | if (imported_name == NULL) |
4926 | { | |
4927 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 | |
4928 | ||
4929 | The import in the following code: | |
4930 | namespace A | |
4931 | { | |
4932 | typedef int B; | |
4933 | } | |
4934 | ||
4935 | int main () | |
4936 | { | |
4937 | using A::B; | |
4938 | B b; | |
4939 | return b; | |
4940 | } | |
4941 | ||
4942 | ... | |
4943 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) | |
4944 | <52> DW_AT_decl_file : 1 | |
4945 | <53> DW_AT_decl_line : 6 | |
4946 | <54> DW_AT_import : <0x75> | |
4947 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) | |
4948 | <59> DW_AT_name : B | |
4949 | <5b> DW_AT_decl_file : 1 | |
4950 | <5c> DW_AT_decl_line : 2 | |
4951 | <5d> DW_AT_type : <0x6e> | |
4952 | ... | |
4953 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) | |
4954 | <76> DW_AT_byte_size : 4 | |
4955 | <77> DW_AT_encoding : 5 (signed) | |
4956 | ||
4957 | imports the wrong die ( 0x75 instead of 0x58 ). | |
4958 | This case will be ignored until the gcc bug is fixed. */ | |
4959 | return; | |
4960 | } | |
4961 | ||
82856980 SW |
4962 | /* Figure out the local name after import. */ |
4963 | import_alias = dwarf2_name (die, cu); | |
27aa8d6a | 4964 | |
794684b6 SW |
4965 | /* Figure out where the statement is being imported to. */ |
4966 | import_prefix = determine_prefix (die, cu); | |
4967 | ||
4968 | /* Figure out what the scope of the imported die is and prepend it | |
4969 | to the name of the imported die. */ | |
de4affc9 | 4970 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
794684b6 | 4971 | |
f55ee35c JK |
4972 | if (imported_die->tag != DW_TAG_namespace |
4973 | && imported_die->tag != DW_TAG_module) | |
794684b6 | 4974 | { |
13387711 SW |
4975 | imported_declaration = imported_name; |
4976 | canonical_name = imported_name_prefix; | |
794684b6 | 4977 | } |
13387711 | 4978 | else if (strlen (imported_name_prefix) > 0) |
794684b6 | 4979 | { |
13387711 SW |
4980 | temp = alloca (strlen (imported_name_prefix) |
4981 | + 2 + strlen (imported_name) + 1); | |
4982 | strcpy (temp, imported_name_prefix); | |
4983 | strcat (temp, "::"); | |
4984 | strcat (temp, imported_name); | |
4985 | canonical_name = temp; | |
794684b6 | 4986 | } |
13387711 SW |
4987 | else |
4988 | canonical_name = imported_name; | |
794684b6 | 4989 | |
c0cc3a76 SW |
4990 | cp_add_using_directive (import_prefix, |
4991 | canonical_name, | |
4992 | import_alias, | |
13387711 | 4993 | imported_declaration, |
c0cc3a76 | 4994 | &cu->objfile->objfile_obstack); |
27aa8d6a SW |
4995 | } |
4996 | ||
5fb290d7 | 4997 | static void |
e142c38c | 4998 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 4999 | { |
e142c38c | 5000 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
5001 | } |
5002 | ||
cb1df416 DJ |
5003 | static void |
5004 | free_cu_line_header (void *arg) | |
5005 | { | |
5006 | struct dwarf2_cu *cu = arg; | |
5007 | ||
5008 | free_line_header (cu->line_header); | |
5009 | cu->line_header = NULL; | |
5010 | } | |
5011 | ||
9291a0cd TT |
5012 | static void |
5013 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, | |
5014 | char **name, char **comp_dir) | |
5015 | { | |
5016 | struct attribute *attr; | |
5017 | ||
5018 | *name = NULL; | |
5019 | *comp_dir = NULL; | |
5020 | ||
5021 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5022 | is not a source language identifier. */ | |
5023 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5024 | if (attr) | |
5025 | { | |
5026 | *name = DW_STRING (attr); | |
5027 | } | |
5028 | ||
5029 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5030 | if (attr) | |
5031 | *comp_dir = DW_STRING (attr); | |
5032 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) | |
5033 | { | |
5034 | *comp_dir = ldirname (*name); | |
5035 | if (*comp_dir != NULL) | |
5036 | make_cleanup (xfree, *comp_dir); | |
5037 | } | |
5038 | if (*comp_dir != NULL) | |
5039 | { | |
5040 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
5041 | directory, get rid of it. */ | |
5042 | char *cp = strchr (*comp_dir, ':'); | |
5043 | ||
5044 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') | |
5045 | *comp_dir = cp + 1; | |
5046 | } | |
5047 | ||
5048 | if (*name == NULL) | |
5049 | *name = "<unknown>"; | |
5050 | } | |
5051 | ||
c906108c | 5052 | static void |
e7c27a73 | 5053 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5054 | { |
e7c27a73 | 5055 | struct objfile *objfile = cu->objfile; |
debd256d | 5056 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 5057 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
5058 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
5059 | struct attribute *attr; | |
e1024ff1 | 5060 | char *name = NULL; |
c906108c SS |
5061 | char *comp_dir = NULL; |
5062 | struct die_info *child_die; | |
5063 | bfd *abfd = objfile->obfd; | |
debd256d | 5064 | struct line_header *line_header = 0; |
e142c38c | 5065 | CORE_ADDR baseaddr; |
6e70227d | 5066 | |
e142c38c | 5067 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 5068 | |
fae299cd | 5069 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
5070 | |
5071 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
5072 | from finish_block. */ | |
2acceee2 | 5073 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
5074 | lowpc = highpc; |
5075 | lowpc += baseaddr; | |
5076 | highpc += baseaddr; | |
5077 | ||
9291a0cd | 5078 | find_file_and_directory (die, cu, &name, &comp_dir); |
e1024ff1 | 5079 | |
e142c38c | 5080 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
5081 | if (attr) |
5082 | { | |
e142c38c | 5083 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
5084 | } |
5085 | ||
b0f35d58 | 5086 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
6e70227d | 5087 | if (attr) |
b0f35d58 | 5088 | cu->producer = DW_STRING (attr); |
303b6f5d | 5089 | |
c906108c SS |
5090 | /* We assume that we're processing GCC output. */ |
5091 | processing_gcc_compilation = 2; | |
c906108c | 5092 | |
df8a16a1 DJ |
5093 | processing_has_namespace_info = 0; |
5094 | ||
c906108c SS |
5095 | start_symtab (name, comp_dir, lowpc); |
5096 | record_debugformat ("DWARF 2"); | |
303b6f5d | 5097 | record_producer (cu->producer); |
c906108c | 5098 | |
e142c38c | 5099 | initialize_cu_func_list (cu); |
c906108c | 5100 | |
cb1df416 DJ |
5101 | /* Decode line number information if present. We do this before |
5102 | processing child DIEs, so that the line header table is available | |
5103 | for DW_AT_decl_file. */ | |
e142c38c | 5104 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
5105 | if (attr) |
5106 | { | |
debd256d | 5107 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 5108 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
5109 | if (line_header) |
5110 | { | |
cb1df416 DJ |
5111 | cu->line_header = line_header; |
5112 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 5113 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 5114 | } |
5fb290d7 | 5115 | } |
debd256d | 5116 | |
cb1df416 DJ |
5117 | /* Process all dies in compilation unit. */ |
5118 | if (die->child != NULL) | |
5119 | { | |
5120 | child_die = die->child; | |
5121 | while (child_die && child_die->tag) | |
5122 | { | |
5123 | process_die (child_die, cu); | |
5124 | child_die = sibling_die (child_die); | |
5125 | } | |
5126 | } | |
5127 | ||
2e276125 JB |
5128 | /* Decode macro information, if present. Dwarf 2 macro information |
5129 | refers to information in the line number info statement program | |
5130 | header, so we can only read it if we've read the header | |
5131 | successfully. */ | |
e142c38c | 5132 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 5133 | if (attr && line_header) |
2e276125 JB |
5134 | { |
5135 | unsigned int macro_offset = DW_UNSND (attr); | |
9a619af0 | 5136 | |
2e276125 | 5137 | dwarf_decode_macros (line_header, macro_offset, |
e7c27a73 | 5138 | comp_dir, abfd, cu); |
2e276125 | 5139 | } |
debd256d | 5140 | do_cleanups (back_to); |
5fb290d7 DJ |
5141 | } |
5142 | ||
348e048f DE |
5143 | /* For TUs we want to skip the first top level sibling if it's not the |
5144 | actual type being defined by this TU. In this case the first top | |
5145 | level sibling is there to provide context only. */ | |
5146 | ||
5147 | static void | |
5148 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) | |
5149 | { | |
5150 | struct objfile *objfile = cu->objfile; | |
5151 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |
5152 | CORE_ADDR lowpc; | |
5153 | struct attribute *attr; | |
5154 | char *name = NULL; | |
5155 | char *comp_dir = NULL; | |
5156 | struct die_info *child_die; | |
5157 | bfd *abfd = objfile->obfd; | |
348e048f DE |
5158 | |
5159 | /* start_symtab needs a low pc, but we don't really have one. | |
5160 | Do what read_file_scope would do in the absence of such info. */ | |
5161 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
5162 | ||
5163 | /* Find the filename. Do not use dwarf2_name here, since the filename | |
5164 | is not a source language identifier. */ | |
5165 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
5166 | if (attr) | |
5167 | name = DW_STRING (attr); | |
5168 | ||
5169 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |
5170 | if (attr) | |
5171 | comp_dir = DW_STRING (attr); | |
5172 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
5173 | { | |
5174 | comp_dir = ldirname (name); | |
5175 | if (comp_dir != NULL) | |
5176 | make_cleanup (xfree, comp_dir); | |
5177 | } | |
5178 | ||
5179 | if (name == NULL) | |
5180 | name = "<unknown>"; | |
5181 | ||
5182 | attr = dwarf2_attr (die, DW_AT_language, cu); | |
5183 | if (attr) | |
5184 | set_cu_language (DW_UNSND (attr), cu); | |
5185 | ||
5186 | /* This isn't technically needed today. It is done for symmetry | |
5187 | with read_file_scope. */ | |
5188 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |
6e70227d | 5189 | if (attr) |
348e048f DE |
5190 | cu->producer = DW_STRING (attr); |
5191 | ||
5192 | /* We assume that we're processing GCC output. */ | |
5193 | processing_gcc_compilation = 2; | |
5194 | ||
5195 | processing_has_namespace_info = 0; | |
5196 | ||
5197 | start_symtab (name, comp_dir, lowpc); | |
5198 | record_debugformat ("DWARF 2"); | |
5199 | record_producer (cu->producer); | |
5200 | ||
5201 | /* Process the dies in the type unit. */ | |
5202 | if (die->child == NULL) | |
5203 | { | |
5204 | dump_die_for_error (die); | |
5205 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), | |
5206 | bfd_get_filename (abfd)); | |
5207 | } | |
5208 | ||
5209 | child_die = die->child; | |
5210 | ||
5211 | while (child_die && child_die->tag) | |
5212 | { | |
5213 | process_die (child_die, cu); | |
5214 | ||
5215 | child_die = sibling_die (child_die); | |
5216 | } | |
5217 | ||
5218 | do_cleanups (back_to); | |
5219 | } | |
5220 | ||
5fb290d7 | 5221 | static void |
e142c38c DJ |
5222 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
5223 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
5224 | { |
5225 | struct function_range *thisfn; | |
5226 | ||
5227 | thisfn = (struct function_range *) | |
7b5a2f43 | 5228 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
5229 | thisfn->name = name; |
5230 | thisfn->lowpc = lowpc; | |
5231 | thisfn->highpc = highpc; | |
5232 | thisfn->seen_line = 0; | |
5233 | thisfn->next = NULL; | |
5234 | ||
e142c38c DJ |
5235 | if (cu->last_fn == NULL) |
5236 | cu->first_fn = thisfn; | |
5fb290d7 | 5237 | else |
e142c38c | 5238 | cu->last_fn->next = thisfn; |
5fb290d7 | 5239 | |
e142c38c | 5240 | cu->last_fn = thisfn; |
c906108c SS |
5241 | } |
5242 | ||
d389af10 JK |
5243 | /* qsort helper for inherit_abstract_dies. */ |
5244 | ||
5245 | static int | |
5246 | unsigned_int_compar (const void *ap, const void *bp) | |
5247 | { | |
5248 | unsigned int a = *(unsigned int *) ap; | |
5249 | unsigned int b = *(unsigned int *) bp; | |
5250 | ||
5251 | return (a > b) - (b > a); | |
5252 | } | |
5253 | ||
5254 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
5255 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
5256 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
5257 | ||
5258 | static void | |
5259 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
5260 | { | |
5261 | struct die_info *child_die; | |
5262 | unsigned die_children_count; | |
5263 | /* CU offsets which were referenced by children of the current DIE. */ | |
5264 | unsigned *offsets; | |
5265 | unsigned *offsets_end, *offsetp; | |
5266 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
5267 | struct die_info *origin_die; | |
5268 | /* Iterator of the ORIGIN_DIE children. */ | |
5269 | struct die_info *origin_child_die; | |
5270 | struct cleanup *cleanups; | |
5271 | struct attribute *attr; | |
cd02d79d PA |
5272 | struct dwarf2_cu *origin_cu; |
5273 | struct pending **origin_previous_list_in_scope; | |
d389af10 JK |
5274 | |
5275 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
5276 | if (!attr) | |
5277 | return; | |
5278 | ||
cd02d79d PA |
5279 | /* Note that following die references may follow to a die in a |
5280 | different cu. */ | |
5281 | ||
5282 | origin_cu = cu; | |
5283 | origin_die = follow_die_ref (die, attr, &origin_cu); | |
5284 | ||
5285 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's | |
5286 | symbols in. */ | |
5287 | origin_previous_list_in_scope = origin_cu->list_in_scope; | |
5288 | origin_cu->list_in_scope = cu->list_in_scope; | |
5289 | ||
edb3359d DJ |
5290 | if (die->tag != origin_die->tag |
5291 | && !(die->tag == DW_TAG_inlined_subroutine | |
5292 | && origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5293 | complaint (&symfile_complaints, |
5294 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
5295 | die->offset, origin_die->offset); | |
5296 | ||
5297 | child_die = die->child; | |
5298 | die_children_count = 0; | |
5299 | while (child_die && child_die->tag) | |
5300 | { | |
5301 | child_die = sibling_die (child_die); | |
5302 | die_children_count++; | |
5303 | } | |
5304 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
5305 | cleanups = make_cleanup (xfree, offsets); | |
5306 | ||
5307 | offsets_end = offsets; | |
5308 | child_die = die->child; | |
5309 | while (child_die && child_die->tag) | |
5310 | { | |
c38f313d DJ |
5311 | /* For each CHILD_DIE, find the corresponding child of |
5312 | ORIGIN_DIE. If there is more than one layer of | |
5313 | DW_AT_abstract_origin, follow them all; there shouldn't be, | |
5314 | but GCC versions at least through 4.4 generate this (GCC PR | |
5315 | 40573). */ | |
5316 | struct die_info *child_origin_die = child_die; | |
cd02d79d | 5317 | struct dwarf2_cu *child_origin_cu = cu; |
9a619af0 | 5318 | |
c38f313d DJ |
5319 | while (1) |
5320 | { | |
cd02d79d PA |
5321 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
5322 | child_origin_cu); | |
c38f313d DJ |
5323 | if (attr == NULL) |
5324 | break; | |
cd02d79d PA |
5325 | child_origin_die = follow_die_ref (child_origin_die, attr, |
5326 | &child_origin_cu); | |
c38f313d DJ |
5327 | } |
5328 | ||
d389af10 JK |
5329 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
5330 | counterpart may exist. */ | |
c38f313d | 5331 | if (child_origin_die != child_die) |
d389af10 | 5332 | { |
edb3359d DJ |
5333 | if (child_die->tag != child_origin_die->tag |
5334 | && !(child_die->tag == DW_TAG_inlined_subroutine | |
5335 | && child_origin_die->tag == DW_TAG_subprogram)) | |
d389af10 JK |
5336 | complaint (&symfile_complaints, |
5337 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5338 | "different tags"), child_die->offset, | |
5339 | child_origin_die->offset); | |
c38f313d DJ |
5340 | if (child_origin_die->parent != origin_die) |
5341 | complaint (&symfile_complaints, | |
5342 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
5343 | "different parents"), child_die->offset, | |
5344 | child_origin_die->offset); | |
5345 | else | |
5346 | *offsets_end++ = child_origin_die->offset; | |
d389af10 JK |
5347 | } |
5348 | child_die = sibling_die (child_die); | |
5349 | } | |
5350 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
5351 | unsigned_int_compar); | |
5352 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
5353 | if (offsetp[-1] == *offsetp) | |
5354 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
5355 | "to DIE 0x%x as their abstract origin"), | |
5356 | die->offset, *offsetp); | |
5357 | ||
5358 | offsetp = offsets; | |
5359 | origin_child_die = origin_die->child; | |
5360 | while (origin_child_die && origin_child_die->tag) | |
5361 | { | |
5362 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
5363 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
5364 | offsetp++; | |
5365 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
5366 | { | |
5367 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
cd02d79d | 5368 | process_die (origin_child_die, origin_cu); |
d389af10 JK |
5369 | } |
5370 | origin_child_die = sibling_die (origin_child_die); | |
5371 | } | |
cd02d79d | 5372 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
d389af10 JK |
5373 | |
5374 | do_cleanups (cleanups); | |
5375 | } | |
5376 | ||
c906108c | 5377 | static void |
e7c27a73 | 5378 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5379 | { |
e7c27a73 | 5380 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5381 | struct context_stack *new; |
c906108c SS |
5382 | CORE_ADDR lowpc; |
5383 | CORE_ADDR highpc; | |
5384 | struct die_info *child_die; | |
edb3359d | 5385 | struct attribute *attr, *call_line, *call_file; |
c906108c | 5386 | char *name; |
e142c38c | 5387 | CORE_ADDR baseaddr; |
801e3a5b | 5388 | struct block *block; |
edb3359d | 5389 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
34eaf542 TT |
5390 | VEC (symbolp) *template_args = NULL; |
5391 | struct template_symbol *templ_func = NULL; | |
edb3359d DJ |
5392 | |
5393 | if (inlined_func) | |
5394 | { | |
5395 | /* If we do not have call site information, we can't show the | |
5396 | caller of this inlined function. That's too confusing, so | |
5397 | only use the scope for local variables. */ | |
5398 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); | |
5399 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); | |
5400 | if (call_line == NULL || call_file == NULL) | |
5401 | { | |
5402 | read_lexical_block_scope (die, cu); | |
5403 | return; | |
5404 | } | |
5405 | } | |
c906108c | 5406 | |
e142c38c DJ |
5407 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
5408 | ||
94af9270 | 5409 | name = dwarf2_name (die, cu); |
c906108c | 5410 | |
e8d05480 JB |
5411 | /* Ignore functions with missing or empty names. These are actually |
5412 | illegal according to the DWARF standard. */ | |
5413 | if (name == NULL) | |
5414 | { | |
5415 | complaint (&symfile_complaints, | |
5416 | _("missing name for subprogram DIE at %d"), die->offset); | |
5417 | return; | |
5418 | } | |
5419 | ||
5420 | /* Ignore functions with missing or invalid low and high pc attributes. */ | |
5421 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) | |
5422 | { | |
ae4d0c03 PM |
5423 | attr = dwarf2_attr (die, DW_AT_external, cu); |
5424 | if (!attr || !DW_UNSND (attr)) | |
5425 | complaint (&symfile_complaints, | |
5426 | _("cannot get low and high bounds for subprogram DIE at %d"), | |
5427 | die->offset); | |
e8d05480 JB |
5428 | return; |
5429 | } | |
c906108c SS |
5430 | |
5431 | lowpc += baseaddr; | |
5432 | highpc += baseaddr; | |
5433 | ||
5fb290d7 | 5434 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 5435 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 5436 | |
34eaf542 TT |
5437 | /* If we have any template arguments, then we must allocate a |
5438 | different sort of symbol. */ | |
5439 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) | |
5440 | { | |
5441 | if (child_die->tag == DW_TAG_template_type_param | |
5442 | || child_die->tag == DW_TAG_template_value_param) | |
5443 | { | |
5444 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, | |
5445 | struct template_symbol); | |
5446 | templ_func->base.is_cplus_template_function = 1; | |
5447 | break; | |
5448 | } | |
5449 | } | |
5450 | ||
c906108c | 5451 | new = push_context (0, lowpc); |
34eaf542 TT |
5452 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
5453 | (struct symbol *) templ_func); | |
4c2df51b | 5454 | |
4cecd739 DJ |
5455 | /* If there is a location expression for DW_AT_frame_base, record |
5456 | it. */ | |
e142c38c | 5457 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 5458 | if (attr) |
c034e007 AC |
5459 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
5460 | expression is being recorded directly in the function's symbol | |
5461 | and not in a separate frame-base object. I guess this hack is | |
5462 | to avoid adding some sort of frame-base adjunct/annex to the | |
5463 | function's symbol :-(. The problem with doing this is that it | |
5464 | results in a function symbol with a location expression that | |
5465 | has nothing to do with the location of the function, ouch! The | |
5466 | relationship should be: a function's symbol has-a frame base; a | |
5467 | frame-base has-a location expression. */ | |
e7c27a73 | 5468 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 5469 | |
e142c38c | 5470 | cu->list_in_scope = &local_symbols; |
c906108c | 5471 | |
639d11d3 | 5472 | if (die->child != NULL) |
c906108c | 5473 | { |
639d11d3 | 5474 | child_die = die->child; |
c906108c SS |
5475 | while (child_die && child_die->tag) |
5476 | { | |
34eaf542 TT |
5477 | if (child_die->tag == DW_TAG_template_type_param |
5478 | || child_die->tag == DW_TAG_template_value_param) | |
5479 | { | |
5480 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
5481 | ||
5482 | VEC_safe_push (symbolp, template_args, arg); | |
5483 | } | |
5484 | else | |
5485 | process_die (child_die, cu); | |
c906108c SS |
5486 | child_die = sibling_die (child_die); |
5487 | } | |
5488 | } | |
5489 | ||
d389af10 JK |
5490 | inherit_abstract_dies (die, cu); |
5491 | ||
4a811a97 UW |
5492 | /* If we have a DW_AT_specification, we might need to import using |
5493 | directives from the context of the specification DIE. See the | |
5494 | comment in determine_prefix. */ | |
5495 | if (cu->language == language_cplus | |
5496 | && dwarf2_attr (die, DW_AT_specification, cu)) | |
5497 | { | |
5498 | struct dwarf2_cu *spec_cu = cu; | |
5499 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
5500 | ||
5501 | while (spec_die) | |
5502 | { | |
5503 | child_die = spec_die->child; | |
5504 | while (child_die && child_die->tag) | |
5505 | { | |
5506 | if (child_die->tag == DW_TAG_imported_module) | |
5507 | process_die (child_die, spec_cu); | |
5508 | child_die = sibling_die (child_die); | |
5509 | } | |
5510 | ||
5511 | /* In some cases, GCC generates specification DIEs that | |
5512 | themselves contain DW_AT_specification attributes. */ | |
5513 | spec_die = die_specification (spec_die, &spec_cu); | |
5514 | } | |
5515 | } | |
5516 | ||
c906108c SS |
5517 | new = pop_context (); |
5518 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
5519 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
5520 | lowpc, highpc, objfile); | |
5521 | ||
df8a16a1 | 5522 | /* For C++, set the block's scope. */ |
f55ee35c | 5523 | if (cu->language == language_cplus || cu->language == language_fortran) |
df8a16a1 | 5524 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
0114d602 | 5525 | determine_prefix (die, cu), |
df8a16a1 DJ |
5526 | processing_has_namespace_info); |
5527 | ||
801e3a5b JB |
5528 | /* If we have address ranges, record them. */ |
5529 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
6e70227d | 5530 | |
34eaf542 TT |
5531 | /* Attach template arguments to function. */ |
5532 | if (! VEC_empty (symbolp, template_args)) | |
5533 | { | |
5534 | gdb_assert (templ_func != NULL); | |
5535 | ||
5536 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); | |
5537 | templ_func->template_arguments | |
5538 | = obstack_alloc (&objfile->objfile_obstack, | |
5539 | (templ_func->n_template_arguments | |
5540 | * sizeof (struct symbol *))); | |
5541 | memcpy (templ_func->template_arguments, | |
5542 | VEC_address (symbolp, template_args), | |
5543 | (templ_func->n_template_arguments * sizeof (struct symbol *))); | |
5544 | VEC_free (symbolp, template_args); | |
5545 | } | |
5546 | ||
208d8187 JB |
5547 | /* In C++, we can have functions nested inside functions (e.g., when |
5548 | a function declares a class that has methods). This means that | |
5549 | when we finish processing a function scope, we may need to go | |
5550 | back to building a containing block's symbol lists. */ | |
5551 | local_symbols = new->locals; | |
5552 | param_symbols = new->params; | |
27aa8d6a | 5553 | using_directives = new->using_directives; |
208d8187 | 5554 | |
921e78cf JB |
5555 | /* If we've finished processing a top-level function, subsequent |
5556 | symbols go in the file symbol list. */ | |
5557 | if (outermost_context_p ()) | |
e142c38c | 5558 | cu->list_in_scope = &file_symbols; |
c906108c SS |
5559 | } |
5560 | ||
5561 | /* Process all the DIES contained within a lexical block scope. Start | |
5562 | a new scope, process the dies, and then close the scope. */ | |
5563 | ||
5564 | static void | |
e7c27a73 | 5565 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5566 | { |
e7c27a73 | 5567 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 5568 | struct context_stack *new; |
c906108c SS |
5569 | CORE_ADDR lowpc, highpc; |
5570 | struct die_info *child_die; | |
e142c38c DJ |
5571 | CORE_ADDR baseaddr; |
5572 | ||
5573 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
5574 | |
5575 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
5576 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
5577 | as multiple lexical blocks? Handling children in a sane way would | |
6e70227d | 5578 | be nasty. Might be easier to properly extend generic blocks to |
af34e669 | 5579 | describe ranges. */ |
d85a05f0 | 5580 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
c906108c SS |
5581 | return; |
5582 | lowpc += baseaddr; | |
5583 | highpc += baseaddr; | |
5584 | ||
5585 | push_context (0, lowpc); | |
639d11d3 | 5586 | if (die->child != NULL) |
c906108c | 5587 | { |
639d11d3 | 5588 | child_die = die->child; |
c906108c SS |
5589 | while (child_die && child_die->tag) |
5590 | { | |
e7c27a73 | 5591 | process_die (child_die, cu); |
c906108c SS |
5592 | child_die = sibling_die (child_die); |
5593 | } | |
5594 | } | |
5595 | new = pop_context (); | |
5596 | ||
8540c487 | 5597 | if (local_symbols != NULL || using_directives != NULL) |
c906108c | 5598 | { |
801e3a5b JB |
5599 | struct block *block |
5600 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
5601 | highpc, objfile); | |
5602 | ||
5603 | /* Note that recording ranges after traversing children, as we | |
5604 | do here, means that recording a parent's ranges entails | |
5605 | walking across all its children's ranges as they appear in | |
5606 | the address map, which is quadratic behavior. | |
5607 | ||
5608 | It would be nicer to record the parent's ranges before | |
5609 | traversing its children, simply overriding whatever you find | |
5610 | there. But since we don't even decide whether to create a | |
5611 | block until after we've traversed its children, that's hard | |
5612 | to do. */ | |
5613 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
5614 | } |
5615 | local_symbols = new->locals; | |
27aa8d6a | 5616 | using_directives = new->using_directives; |
c906108c SS |
5617 | } |
5618 | ||
43039443 | 5619 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
5620 | Return 1 if the attributes are present and valid, otherwise, return 0. |
5621 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
5622 | |
5623 | static int | |
5624 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
5625 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
5626 | struct partial_symtab *ranges_pst) | |
43039443 JK |
5627 | { |
5628 | struct objfile *objfile = cu->objfile; | |
5629 | struct comp_unit_head *cu_header = &cu->header; | |
5630 | bfd *obfd = objfile->obfd; | |
5631 | unsigned int addr_size = cu_header->addr_size; | |
5632 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5633 | /* Base address selection entry. */ | |
5634 | CORE_ADDR base; | |
5635 | int found_base; | |
5636 | unsigned int dummy; | |
5637 | gdb_byte *buffer; | |
5638 | CORE_ADDR marker; | |
5639 | int low_set; | |
5640 | CORE_ADDR low = 0; | |
5641 | CORE_ADDR high = 0; | |
ff013f42 | 5642 | CORE_ADDR baseaddr; |
43039443 | 5643 | |
d00adf39 DE |
5644 | found_base = cu->base_known; |
5645 | base = cu->base_address; | |
43039443 | 5646 | |
be391dca | 5647 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
dce234bc | 5648 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
5649 | { |
5650 | complaint (&symfile_complaints, | |
5651 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
5652 | offset); | |
5653 | return 0; | |
5654 | } | |
dce234bc | 5655 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
5656 | |
5657 | /* Read in the largest possible address. */ | |
5658 | marker = read_address (obfd, buffer, cu, &dummy); | |
5659 | if ((marker & mask) == mask) | |
5660 | { | |
5661 | /* If we found the largest possible address, then | |
5662 | read the base address. */ | |
5663 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5664 | buffer += 2 * addr_size; | |
5665 | offset += 2 * addr_size; | |
5666 | found_base = 1; | |
5667 | } | |
5668 | ||
5669 | low_set = 0; | |
5670 | ||
e7030f15 | 5671 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 5672 | |
43039443 JK |
5673 | while (1) |
5674 | { | |
5675 | CORE_ADDR range_beginning, range_end; | |
5676 | ||
5677 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
5678 | buffer += addr_size; | |
5679 | range_end = read_address (obfd, buffer, cu, &dummy); | |
5680 | buffer += addr_size; | |
5681 | offset += 2 * addr_size; | |
5682 | ||
5683 | /* An end of list marker is a pair of zero addresses. */ | |
5684 | if (range_beginning == 0 && range_end == 0) | |
5685 | /* Found the end of list entry. */ | |
5686 | break; | |
5687 | ||
5688 | /* Each base address selection entry is a pair of 2 values. | |
5689 | The first is the largest possible address, the second is | |
5690 | the base address. Check for a base address here. */ | |
5691 | if ((range_beginning & mask) == mask) | |
5692 | { | |
5693 | /* If we found the largest possible address, then | |
5694 | read the base address. */ | |
5695 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
5696 | found_base = 1; | |
5697 | continue; | |
5698 | } | |
5699 | ||
5700 | if (!found_base) | |
5701 | { | |
5702 | /* We have no valid base address for the ranges | |
5703 | data. */ | |
5704 | complaint (&symfile_complaints, | |
5705 | _("Invalid .debug_ranges data (no base address)")); | |
5706 | return 0; | |
5707 | } | |
5708 | ||
5709 | range_beginning += base; | |
5710 | range_end += base; | |
5711 | ||
ff013f42 JK |
5712 | if (ranges_pst != NULL && range_beginning < range_end) |
5713 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
5714 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
5715 | ranges_pst); | |
5716 | ||
43039443 JK |
5717 | /* FIXME: This is recording everything as a low-high |
5718 | segment of consecutive addresses. We should have a | |
5719 | data structure for discontiguous block ranges | |
5720 | instead. */ | |
5721 | if (! low_set) | |
5722 | { | |
5723 | low = range_beginning; | |
5724 | high = range_end; | |
5725 | low_set = 1; | |
5726 | } | |
5727 | else | |
5728 | { | |
5729 | if (range_beginning < low) | |
5730 | low = range_beginning; | |
5731 | if (range_end > high) | |
5732 | high = range_end; | |
5733 | } | |
5734 | } | |
5735 | ||
5736 | if (! low_set) | |
5737 | /* If the first entry is an end-of-list marker, the range | |
5738 | describes an empty scope, i.e. no instructions. */ | |
5739 | return 0; | |
5740 | ||
5741 | if (low_return) | |
5742 | *low_return = low; | |
5743 | if (high_return) | |
5744 | *high_return = high; | |
5745 | return 1; | |
5746 | } | |
5747 | ||
af34e669 DJ |
5748 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
5749 | are present and valid, otherwise, return 0. Return -1 if the range is | |
5750 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 5751 | static int |
af34e669 | 5752 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
d85a05f0 DJ |
5753 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
5754 | struct partial_symtab *pst) | |
c906108c SS |
5755 | { |
5756 | struct attribute *attr; | |
af34e669 DJ |
5757 | CORE_ADDR low = 0; |
5758 | CORE_ADDR high = 0; | |
5759 | int ret = 0; | |
c906108c | 5760 | |
e142c38c | 5761 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 5762 | if (attr) |
af34e669 DJ |
5763 | { |
5764 | high = DW_ADDR (attr); | |
e142c38c | 5765 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
5766 | if (attr) |
5767 | low = DW_ADDR (attr); | |
5768 | else | |
5769 | /* Found high w/o low attribute. */ | |
5770 | return 0; | |
5771 | ||
5772 | /* Found consecutive range of addresses. */ | |
5773 | ret = 1; | |
5774 | } | |
c906108c | 5775 | else |
af34e669 | 5776 | { |
e142c38c | 5777 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
5778 | if (attr != NULL) |
5779 | { | |
af34e669 | 5780 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 5781 | .debug_ranges section. */ |
d85a05f0 | 5782 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
af34e669 | 5783 | return 0; |
43039443 | 5784 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
5785 | ret = -1; |
5786 | } | |
5787 | } | |
c906108c SS |
5788 | |
5789 | if (high < low) | |
5790 | return 0; | |
5791 | ||
5792 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
5793 | eliminate duplicate copies of functions and vtables and such. | |
5794 | The linker will arbitrarily choose one and discard the others. | |
5795 | The AT_*_pc values for such functions refer to local labels in | |
5796 | these sections. If the section from that file was discarded, the | |
5797 | labels are not in the output, so the relocs get a value of 0. | |
5798 | If this is a discarded function, mark the pc bounds as invalid, | |
5799 | so that GDB will ignore it. */ | |
72dca2f5 | 5800 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
5801 | return 0; |
5802 | ||
5803 | *lowpc = low; | |
5804 | *highpc = high; | |
af34e669 | 5805 | return ret; |
c906108c SS |
5806 | } |
5807 | ||
b084d499 JB |
5808 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
5809 | its low and high PC addresses. Do nothing if these addresses could not | |
5810 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
5811 | and HIGHPC to the high address if greater than HIGHPC. */ | |
5812 | ||
5813 | static void | |
5814 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
5815 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5816 | struct dwarf2_cu *cu) | |
5817 | { | |
5818 | CORE_ADDR low, high; | |
5819 | struct die_info *child = die->child; | |
5820 | ||
d85a05f0 | 5821 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
b084d499 JB |
5822 | { |
5823 | *lowpc = min (*lowpc, low); | |
5824 | *highpc = max (*highpc, high); | |
5825 | } | |
5826 | ||
5827 | /* If the language does not allow nested subprograms (either inside | |
5828 | subprograms or lexical blocks), we're done. */ | |
5829 | if (cu->language != language_ada) | |
5830 | return; | |
6e70227d | 5831 | |
b084d499 JB |
5832 | /* Check all the children of the given DIE. If it contains nested |
5833 | subprograms, then check their pc bounds. Likewise, we need to | |
5834 | check lexical blocks as well, as they may also contain subprogram | |
5835 | definitions. */ | |
5836 | while (child && child->tag) | |
5837 | { | |
5838 | if (child->tag == DW_TAG_subprogram | |
5839 | || child->tag == DW_TAG_lexical_block) | |
5840 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
5841 | child = sibling_die (child); | |
5842 | } | |
5843 | } | |
5844 | ||
fae299cd DC |
5845 | /* Get the low and high pc's represented by the scope DIE, and store |
5846 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
5847 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
5848 | ||
5849 | static void | |
5850 | get_scope_pc_bounds (struct die_info *die, | |
5851 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5852 | struct dwarf2_cu *cu) | |
5853 | { | |
5854 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
5855 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
5856 | CORE_ADDR current_low, current_high; | |
5857 | ||
d85a05f0 | 5858 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
fae299cd DC |
5859 | { |
5860 | best_low = current_low; | |
5861 | best_high = current_high; | |
5862 | } | |
5863 | else | |
5864 | { | |
5865 | struct die_info *child = die->child; | |
5866 | ||
5867 | while (child && child->tag) | |
5868 | { | |
5869 | switch (child->tag) { | |
5870 | case DW_TAG_subprogram: | |
b084d499 | 5871 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
5872 | break; |
5873 | case DW_TAG_namespace: | |
f55ee35c | 5874 | case DW_TAG_module: |
fae299cd DC |
5875 | /* FIXME: carlton/2004-01-16: Should we do this for |
5876 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
5877 | that current GCC's always emit the DIEs corresponding | |
5878 | to definitions of methods of classes as children of a | |
5879 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
5880 | the DIEs giving the declarations, which could be | |
5881 | anywhere). But I don't see any reason why the | |
5882 | standards says that they have to be there. */ | |
5883 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
5884 | ||
5885 | if (current_low != ((CORE_ADDR) -1)) | |
5886 | { | |
5887 | best_low = min (best_low, current_low); | |
5888 | best_high = max (best_high, current_high); | |
5889 | } | |
5890 | break; | |
5891 | default: | |
5892 | /* Ignore. */ | |
5893 | break; | |
5894 | } | |
5895 | ||
5896 | child = sibling_die (child); | |
5897 | } | |
5898 | } | |
5899 | ||
5900 | *lowpc = best_low; | |
5901 | *highpc = best_high; | |
5902 | } | |
5903 | ||
801e3a5b JB |
5904 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
5905 | in DIE. */ | |
5906 | static void | |
5907 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
5908 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
5909 | { | |
5910 | struct attribute *attr; | |
5911 | ||
5912 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
5913 | if (attr) | |
5914 | { | |
5915 | CORE_ADDR high = DW_ADDR (attr); | |
9a619af0 | 5916 | |
801e3a5b JB |
5917 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
5918 | if (attr) | |
5919 | { | |
5920 | CORE_ADDR low = DW_ADDR (attr); | |
9a619af0 | 5921 | |
801e3a5b JB |
5922 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
5923 | } | |
5924 | } | |
5925 | ||
5926 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
5927 | if (attr) | |
5928 | { | |
5929 | bfd *obfd = cu->objfile->obfd; | |
5930 | ||
5931 | /* The value of the DW_AT_ranges attribute is the offset of the | |
5932 | address range list in the .debug_ranges section. */ | |
5933 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 5934 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
5935 | |
5936 | /* For some target architectures, but not others, the | |
5937 | read_address function sign-extends the addresses it returns. | |
5938 | To recognize base address selection entries, we need a | |
5939 | mask. */ | |
5940 | unsigned int addr_size = cu->header.addr_size; | |
5941 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
5942 | ||
5943 | /* The base address, to which the next pair is relative. Note | |
5944 | that this 'base' is a DWARF concept: most entries in a range | |
5945 | list are relative, to reduce the number of relocs against the | |
5946 | debugging information. This is separate from this function's | |
5947 | 'baseaddr' argument, which GDB uses to relocate debugging | |
5948 | information from a shared library based on the address at | |
5949 | which the library was loaded. */ | |
d00adf39 DE |
5950 | CORE_ADDR base = cu->base_address; |
5951 | int base_known = cu->base_known; | |
801e3a5b | 5952 | |
be391dca | 5953 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
dce234bc | 5954 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
5955 | { |
5956 | complaint (&symfile_complaints, | |
5957 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
5958 | offset); | |
5959 | return; | |
5960 | } | |
5961 | ||
5962 | for (;;) | |
5963 | { | |
5964 | unsigned int bytes_read; | |
5965 | CORE_ADDR start, end; | |
5966 | ||
5967 | start = read_address (obfd, buffer, cu, &bytes_read); | |
5968 | buffer += bytes_read; | |
5969 | end = read_address (obfd, buffer, cu, &bytes_read); | |
5970 | buffer += bytes_read; | |
5971 | ||
5972 | /* Did we find the end of the range list? */ | |
5973 | if (start == 0 && end == 0) | |
5974 | break; | |
5975 | ||
5976 | /* Did we find a base address selection entry? */ | |
5977 | else if ((start & base_select_mask) == base_select_mask) | |
5978 | { | |
5979 | base = end; | |
5980 | base_known = 1; | |
5981 | } | |
5982 | ||
5983 | /* We found an ordinary address range. */ | |
5984 | else | |
5985 | { | |
5986 | if (!base_known) | |
5987 | { | |
5988 | complaint (&symfile_complaints, | |
5989 | _("Invalid .debug_ranges data (no base address)")); | |
5990 | return; | |
5991 | } | |
5992 | ||
6e70227d DE |
5993 | record_block_range (block, |
5994 | baseaddr + base + start, | |
801e3a5b JB |
5995 | baseaddr + base + end - 1); |
5996 | } | |
5997 | } | |
5998 | } | |
5999 | } | |
6000 | ||
c906108c SS |
6001 | /* Add an aggregate field to the field list. */ |
6002 | ||
6003 | static void | |
107d2387 | 6004 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6005 | struct dwarf2_cu *cu) |
6e70227d | 6006 | { |
e7c27a73 | 6007 | struct objfile *objfile = cu->objfile; |
5e2b427d | 6008 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
6009 | struct nextfield *new_field; |
6010 | struct attribute *attr; | |
6011 | struct field *fp; | |
6012 | char *fieldname = ""; | |
6013 | ||
6014 | /* Allocate a new field list entry and link it in. */ | |
6015 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 6016 | make_cleanup (xfree, new_field); |
c906108c | 6017 | memset (new_field, 0, sizeof (struct nextfield)); |
7d0ccb61 DJ |
6018 | |
6019 | if (die->tag == DW_TAG_inheritance) | |
6020 | { | |
6021 | new_field->next = fip->baseclasses; | |
6022 | fip->baseclasses = new_field; | |
6023 | } | |
6024 | else | |
6025 | { | |
6026 | new_field->next = fip->fields; | |
6027 | fip->fields = new_field; | |
6028 | } | |
c906108c SS |
6029 | fip->nfields++; |
6030 | ||
6031 | /* Handle accessibility and virtuality of field. | |
6032 | The default accessibility for members is public, the default | |
6033 | accessibility for inheritance is private. */ | |
6034 | if (die->tag != DW_TAG_inheritance) | |
6035 | new_field->accessibility = DW_ACCESS_public; | |
6036 | else | |
6037 | new_field->accessibility = DW_ACCESS_private; | |
6038 | new_field->virtuality = DW_VIRTUALITY_none; | |
6039 | ||
e142c38c | 6040 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6041 | if (attr) |
6042 | new_field->accessibility = DW_UNSND (attr); | |
6043 | if (new_field->accessibility != DW_ACCESS_public) | |
6044 | fip->non_public_fields = 1; | |
e142c38c | 6045 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
6046 | if (attr) |
6047 | new_field->virtuality = DW_UNSND (attr); | |
6048 | ||
6049 | fp = &new_field->field; | |
a9a9bd0f | 6050 | |
e142c38c | 6051 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 6052 | { |
a9a9bd0f | 6053 | /* Data member other than a C++ static data member. */ |
6e70227d | 6054 | |
c906108c | 6055 | /* Get type of field. */ |
e7c27a73 | 6056 | fp->type = die_type (die, cu); |
c906108c | 6057 | |
d6a843b5 | 6058 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 6059 | |
c906108c | 6060 | /* Get bit size of field (zero if none). */ |
e142c38c | 6061 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
6062 | if (attr) |
6063 | { | |
6064 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
6065 | } | |
6066 | else | |
6067 | { | |
6068 | FIELD_BITSIZE (*fp) = 0; | |
6069 | } | |
6070 | ||
6071 | /* Get bit offset of field. */ | |
e142c38c | 6072 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
6073 | if (attr) |
6074 | { | |
d4b96c9a | 6075 | int byte_offset = 0; |
c6a0999f | 6076 | |
3690dd37 | 6077 | if (attr_form_is_section_offset (attr)) |
d4b96c9a | 6078 | dwarf2_complex_location_expr_complaint (); |
3690dd37 | 6079 | else if (attr_form_is_constant (attr)) |
c6a0999f | 6080 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
d4b96c9a | 6081 | else if (attr_form_is_block (attr)) |
c6a0999f | 6082 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
d4b96c9a JK |
6083 | else |
6084 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 6085 | |
d6a843b5 | 6086 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 6087 | } |
e142c38c | 6088 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
6089 | if (attr) |
6090 | { | |
5e2b427d | 6091 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
6092 | { |
6093 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
6094 | additional bit offset from the MSB of the containing |
6095 | anonymous object to the MSB of the field. We don't | |
6096 | have to do anything special since we don't need to | |
6097 | know the size of the anonymous object. */ | |
c906108c SS |
6098 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
6099 | } | |
6100 | else | |
6101 | { | |
6102 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
6103 | MSB of the anonymous object, subtract off the number of |
6104 | bits from the MSB of the field to the MSB of the | |
6105 | object, and then subtract off the number of bits of | |
6106 | the field itself. The result is the bit offset of | |
6107 | the LSB of the field. */ | |
c906108c SS |
6108 | int anonymous_size; |
6109 | int bit_offset = DW_UNSND (attr); | |
6110 | ||
e142c38c | 6111 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6112 | if (attr) |
6113 | { | |
6114 | /* The size of the anonymous object containing | |
6115 | the bit field is explicit, so use the | |
6116 | indicated size (in bytes). */ | |
6117 | anonymous_size = DW_UNSND (attr); | |
6118 | } | |
6119 | else | |
6120 | { | |
6121 | /* The size of the anonymous object containing | |
6122 | the bit field must be inferred from the type | |
6123 | attribute of the data member containing the | |
6124 | bit field. */ | |
6125 | anonymous_size = TYPE_LENGTH (fp->type); | |
6126 | } | |
6127 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
6128 | - bit_offset - FIELD_BITSIZE (*fp); | |
6129 | } | |
6130 | } | |
6131 | ||
6132 | /* Get name of field. */ | |
39cbfefa DJ |
6133 | fieldname = dwarf2_name (die, cu); |
6134 | if (fieldname == NULL) | |
6135 | fieldname = ""; | |
d8151005 DJ |
6136 | |
6137 | /* The name is already allocated along with this objfile, so we don't | |
6138 | need to duplicate it for the type. */ | |
6139 | fp->name = fieldname; | |
c906108c SS |
6140 | |
6141 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 6142 | pointer or virtual base class pointer) to private. */ |
e142c38c | 6143 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c | 6144 | { |
d48cc9dd | 6145 | FIELD_ARTIFICIAL (*fp) = 1; |
c906108c SS |
6146 | new_field->accessibility = DW_ACCESS_private; |
6147 | fip->non_public_fields = 1; | |
6148 | } | |
6149 | } | |
a9a9bd0f | 6150 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 6151 | { |
a9a9bd0f DC |
6152 | /* C++ static member. */ |
6153 | ||
6154 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
6155 | is a declaration, but all versions of G++ as of this writing | |
6156 | (so through at least 3.2.1) incorrectly generate | |
6157 | DW_TAG_variable tags. */ | |
6e70227d | 6158 | |
c906108c | 6159 | char *physname; |
c906108c | 6160 | |
a9a9bd0f | 6161 | /* Get name of field. */ |
39cbfefa DJ |
6162 | fieldname = dwarf2_name (die, cu); |
6163 | if (fieldname == NULL) | |
c906108c SS |
6164 | return; |
6165 | ||
254e6b9e | 6166 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
3863f96c DE |
6167 | if (attr |
6168 | /* Only create a symbol if this is an external value. | |
6169 | new_symbol checks this and puts the value in the global symbol | |
6170 | table, which we want. If it is not external, new_symbol | |
6171 | will try to put the value in cu->list_in_scope which is wrong. */ | |
6172 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) | |
254e6b9e DE |
6173 | { |
6174 | /* A static const member, not much different than an enum as far as | |
6175 | we're concerned, except that we can support more types. */ | |
6176 | new_symbol (die, NULL, cu); | |
6177 | } | |
6178 | ||
2df3850c | 6179 | /* Get physical name. */ |
94af9270 | 6180 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
c906108c | 6181 | |
d8151005 DJ |
6182 | /* The name is already allocated along with this objfile, so we don't |
6183 | need to duplicate it for the type. */ | |
6184 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 6185 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 6186 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
6187 | } |
6188 | else if (die->tag == DW_TAG_inheritance) | |
6189 | { | |
6190 | /* C++ base class field. */ | |
e142c38c | 6191 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 6192 | if (attr) |
d4b96c9a JK |
6193 | { |
6194 | int byte_offset = 0; | |
6195 | ||
6196 | if (attr_form_is_section_offset (attr)) | |
6197 | dwarf2_complex_location_expr_complaint (); | |
6198 | else if (attr_form_is_constant (attr)) | |
6199 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
6200 | else if (attr_form_is_block (attr)) | |
6201 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
6202 | else | |
6203 | dwarf2_complex_location_expr_complaint (); | |
6204 | ||
6205 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); | |
6206 | } | |
c906108c | 6207 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 6208 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
6209 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
6210 | fip->nbaseclasses++; | |
6211 | } | |
6212 | } | |
6213 | ||
98751a41 JK |
6214 | /* Add a typedef defined in the scope of the FIP's class. */ |
6215 | ||
6216 | static void | |
6217 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, | |
6218 | struct dwarf2_cu *cu) | |
6e70227d | 6219 | { |
98751a41 JK |
6220 | struct objfile *objfile = cu->objfile; |
6221 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
6222 | struct typedef_field_list *new_field; | |
6223 | struct attribute *attr; | |
6224 | struct typedef_field *fp; | |
6225 | char *fieldname = ""; | |
6226 | ||
6227 | /* Allocate a new field list entry and link it in. */ | |
6228 | new_field = xzalloc (sizeof (*new_field)); | |
6229 | make_cleanup (xfree, new_field); | |
6230 | ||
6231 | gdb_assert (die->tag == DW_TAG_typedef); | |
6232 | ||
6233 | fp = &new_field->field; | |
6234 | ||
6235 | /* Get name of field. */ | |
6236 | fp->name = dwarf2_name (die, cu); | |
6237 | if (fp->name == NULL) | |
6238 | return; | |
6239 | ||
6240 | fp->type = read_type_die (die, cu); | |
6241 | ||
6242 | new_field->next = fip->typedef_field_list; | |
6243 | fip->typedef_field_list = new_field; | |
6244 | fip->typedef_field_list_count++; | |
6245 | } | |
6246 | ||
c906108c SS |
6247 | /* Create the vector of fields, and attach it to the type. */ |
6248 | ||
6249 | static void | |
fba45db2 | 6250 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6251 | struct dwarf2_cu *cu) |
c906108c SS |
6252 | { |
6253 | int nfields = fip->nfields; | |
6254 | ||
6255 | /* Record the field count, allocate space for the array of fields, | |
6256 | and create blank accessibility bitfields if necessary. */ | |
6257 | TYPE_NFIELDS (type) = nfields; | |
6258 | TYPE_FIELDS (type) = (struct field *) | |
6259 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
6260 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
6261 | ||
b4ba55a1 | 6262 | if (fip->non_public_fields && cu->language != language_ada) |
c906108c SS |
6263 | { |
6264 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6265 | ||
6266 | TYPE_FIELD_PRIVATE_BITS (type) = | |
6267 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6268 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
6269 | ||
6270 | TYPE_FIELD_PROTECTED_BITS (type) = | |
6271 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6272 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
6273 | ||
774b6a14 TT |
6274 | TYPE_FIELD_IGNORE_BITS (type) = |
6275 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
6276 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
c906108c SS |
6277 | } |
6278 | ||
6279 | /* If the type has baseclasses, allocate and clear a bit vector for | |
6280 | TYPE_FIELD_VIRTUAL_BITS. */ | |
b4ba55a1 | 6281 | if (fip->nbaseclasses && cu->language != language_ada) |
c906108c SS |
6282 | { |
6283 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 6284 | unsigned char *pointer; |
c906108c SS |
6285 | |
6286 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
6287 | pointer = TYPE_ALLOC (type, num_bytes); |
6288 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
6289 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
6290 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
6291 | } | |
6292 | ||
6293 | /* Copy the saved-up fields into the field vector. Start from the head | |
6294 | of the list, adding to the tail of the field array, so that they end | |
6295 | up in the same order in the array in which they were added to the list. */ | |
6296 | while (nfields-- > 0) | |
6297 | { | |
7d0ccb61 DJ |
6298 | struct nextfield *fieldp; |
6299 | ||
6300 | if (fip->fields) | |
6301 | { | |
6302 | fieldp = fip->fields; | |
6303 | fip->fields = fieldp->next; | |
6304 | } | |
6305 | else | |
6306 | { | |
6307 | fieldp = fip->baseclasses; | |
6308 | fip->baseclasses = fieldp->next; | |
6309 | } | |
6310 | ||
6311 | TYPE_FIELD (type, nfields) = fieldp->field; | |
6312 | switch (fieldp->accessibility) | |
c906108c | 6313 | { |
c5aa993b | 6314 | case DW_ACCESS_private: |
b4ba55a1 JB |
6315 | if (cu->language != language_ada) |
6316 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
c5aa993b | 6317 | break; |
c906108c | 6318 | |
c5aa993b | 6319 | case DW_ACCESS_protected: |
b4ba55a1 JB |
6320 | if (cu->language != language_ada) |
6321 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
c5aa993b | 6322 | break; |
c906108c | 6323 | |
c5aa993b JM |
6324 | case DW_ACCESS_public: |
6325 | break; | |
c906108c | 6326 | |
c5aa993b JM |
6327 | default: |
6328 | /* Unknown accessibility. Complain and treat it as public. */ | |
6329 | { | |
e2e0b3e5 | 6330 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
7d0ccb61 | 6331 | fieldp->accessibility); |
c5aa993b JM |
6332 | } |
6333 | break; | |
c906108c SS |
6334 | } |
6335 | if (nfields < fip->nbaseclasses) | |
6336 | { | |
7d0ccb61 | 6337 | switch (fieldp->virtuality) |
c906108c | 6338 | { |
c5aa993b JM |
6339 | case DW_VIRTUALITY_virtual: |
6340 | case DW_VIRTUALITY_pure_virtual: | |
b4ba55a1 JB |
6341 | if (cu->language == language_ada) |
6342 | error ("unexpected virtuality in component of Ada type"); | |
c5aa993b JM |
6343 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
6344 | break; | |
c906108c SS |
6345 | } |
6346 | } | |
c906108c SS |
6347 | } |
6348 | } | |
6349 | ||
c906108c SS |
6350 | /* Add a member function to the proper fieldlist. */ |
6351 | ||
6352 | static void | |
107d2387 | 6353 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 6354 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 6355 | { |
e7c27a73 | 6356 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6357 | struct attribute *attr; |
6358 | struct fnfieldlist *flp; | |
6359 | int i; | |
6360 | struct fn_field *fnp; | |
6361 | char *fieldname; | |
c906108c | 6362 | struct nextfnfield *new_fnfield; |
f792889a | 6363 | struct type *this_type; |
c906108c | 6364 | |
b4ba55a1 JB |
6365 | if (cu->language == language_ada) |
6366 | error ("unexpected member function in Ada type"); | |
6367 | ||
2df3850c | 6368 | /* Get name of member function. */ |
39cbfefa DJ |
6369 | fieldname = dwarf2_name (die, cu); |
6370 | if (fieldname == NULL) | |
2df3850c | 6371 | return; |
c906108c | 6372 | |
c906108c SS |
6373 | /* Look up member function name in fieldlist. */ |
6374 | for (i = 0; i < fip->nfnfields; i++) | |
6375 | { | |
27bfe10e | 6376 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
6377 | break; |
6378 | } | |
6379 | ||
6380 | /* Create new list element if necessary. */ | |
6381 | if (i < fip->nfnfields) | |
6382 | flp = &fip->fnfieldlists[i]; | |
6383 | else | |
6384 | { | |
6385 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
6386 | { | |
6387 | fip->fnfieldlists = (struct fnfieldlist *) | |
6388 | xrealloc (fip->fnfieldlists, | |
6389 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 6390 | * sizeof (struct fnfieldlist)); |
c906108c | 6391 | if (fip->nfnfields == 0) |
c13c43fd | 6392 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
6393 | } |
6394 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
6395 | flp->name = fieldname; | |
6396 | flp->length = 0; | |
6397 | flp->head = NULL; | |
3da10d80 | 6398 | i = fip->nfnfields++; |
c906108c SS |
6399 | } |
6400 | ||
6401 | /* Create a new member function field and chain it to the field list | |
6402 | entry. */ | |
6403 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 6404 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
6405 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
6406 | new_fnfield->next = flp->head; | |
6407 | flp->head = new_fnfield; | |
6408 | flp->length++; | |
6409 | ||
6410 | /* Fill in the member function field info. */ | |
6411 | fnp = &new_fnfield->fnfield; | |
3da10d80 KS |
6412 | |
6413 | /* Delay processing of the physname until later. */ | |
6414 | if (cu->language == language_cplus || cu->language == language_java) | |
6415 | { | |
6416 | add_to_method_list (type, i, flp->length - 1, fieldname, | |
6417 | die, cu); | |
6418 | } | |
6419 | else | |
6420 | { | |
6421 | char *physname = (char *) dwarf2_physname (fieldname, die, cu); | |
6422 | fnp->physname = physname ? physname : ""; | |
6423 | } | |
6424 | ||
c906108c | 6425 | fnp->type = alloc_type (objfile); |
f792889a DJ |
6426 | this_type = read_type_die (die, cu); |
6427 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 6428 | { |
f792889a | 6429 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 6430 | |
f792889a | 6431 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
6432 | of the method itself (TYPE_CODE_METHOD). */ |
6433 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
6434 | TYPE_TARGET_TYPE (this_type), |
6435 | TYPE_FIELDS (this_type), | |
6436 | TYPE_NFIELDS (this_type), | |
6437 | TYPE_VARARGS (this_type)); | |
c906108c SS |
6438 | |
6439 | /* Handle static member functions. | |
c5aa993b JM |
6440 | Dwarf2 has no clean way to discern C++ static and non-static |
6441 | member functions. G++ helps GDB by marking the first | |
6442 | parameter for non-static member functions (which is the | |
6443 | this pointer) as artificial. We obtain this information | |
6444 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 6445 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
6446 | fnp->voffset = VOFFSET_STATIC; |
6447 | } | |
6448 | else | |
e2e0b3e5 | 6449 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
3da10d80 | 6450 | dwarf2_full_name (fieldname, die, cu)); |
c906108c SS |
6451 | |
6452 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 6453 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 6454 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
6455 | |
6456 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
6457 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
6458 | ||
6459 | /* Get accessibility. */ | |
e142c38c | 6460 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
6461 | if (attr) |
6462 | { | |
6463 | switch (DW_UNSND (attr)) | |
6464 | { | |
c5aa993b JM |
6465 | case DW_ACCESS_private: |
6466 | fnp->is_private = 1; | |
6467 | break; | |
6468 | case DW_ACCESS_protected: | |
6469 | fnp->is_protected = 1; | |
6470 | break; | |
c906108c SS |
6471 | } |
6472 | } | |
6473 | ||
b02dede2 | 6474 | /* Check for artificial methods. */ |
e142c38c | 6475 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
6476 | if (attr && DW_UNSND (attr) != 0) |
6477 | fnp->is_artificial = 1; | |
6478 | ||
0d564a31 | 6479 | /* Get index in virtual function table if it is a virtual member |
aec5aa8b TT |
6480 | function. For older versions of GCC, this is an offset in the |
6481 | appropriate virtual table, as specified by DW_AT_containing_type. | |
6482 | For everyone else, it is an expression to be evaluated relative | |
0d564a31 DJ |
6483 | to the object address. */ |
6484 | ||
e142c38c | 6485 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
aec5aa8b | 6486 | if (attr) |
8e19ed76 | 6487 | { |
aec5aa8b | 6488 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
8e19ed76 | 6489 | { |
aec5aa8b TT |
6490 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
6491 | { | |
6492 | /* Old-style GCC. */ | |
6493 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; | |
6494 | } | |
6495 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6496 | || (DW_BLOCK (attr)->size > 1 | |
6497 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size | |
6498 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) | |
6499 | { | |
6500 | struct dwarf_block blk; | |
6501 | int offset; | |
6502 | ||
6503 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref | |
6504 | ? 1 : 2); | |
6505 | blk.size = DW_BLOCK (attr)->size - offset; | |
6506 | blk.data = DW_BLOCK (attr)->data + offset; | |
6507 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); | |
6508 | if ((fnp->voffset % cu->header.addr_size) != 0) | |
6509 | dwarf2_complex_location_expr_complaint (); | |
6510 | else | |
6511 | fnp->voffset /= cu->header.addr_size; | |
6512 | fnp->voffset += 2; | |
6513 | } | |
6514 | else | |
6515 | dwarf2_complex_location_expr_complaint (); | |
6516 | ||
6517 | if (!fnp->fcontext) | |
6518 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); | |
6519 | } | |
3690dd37 | 6520 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 6521 | { |
4d3c2250 | 6522 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6523 | } |
6524 | else | |
6525 | { | |
4d3c2250 KB |
6526 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
6527 | fieldname); | |
8e19ed76 | 6528 | } |
0d564a31 | 6529 | } |
d48cc9dd DJ |
6530 | else |
6531 | { | |
6532 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |
6533 | if (attr && DW_UNSND (attr)) | |
6534 | { | |
6535 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ | |
6536 | complaint (&symfile_complaints, | |
6537 | _("Member function \"%s\" (offset %d) is virtual but the vtable offset is not specified"), | |
6538 | fieldname, die->offset); | |
9655fd1a | 6539 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
d48cc9dd DJ |
6540 | TYPE_CPLUS_DYNAMIC (type) = 1; |
6541 | } | |
6542 | } | |
c906108c SS |
6543 | } |
6544 | ||
6545 | /* Create the vector of member function fields, and attach it to the type. */ | |
6546 | ||
6547 | static void | |
fba45db2 | 6548 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 6549 | struct dwarf2_cu *cu) |
c906108c SS |
6550 | { |
6551 | struct fnfieldlist *flp; | |
6552 | int total_length = 0; | |
6553 | int i; | |
6554 | ||
b4ba55a1 JB |
6555 | if (cu->language == language_ada) |
6556 | error ("unexpected member functions in Ada type"); | |
6557 | ||
c906108c SS |
6558 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
6559 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
6560 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
6561 | ||
6562 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
6563 | { | |
6564 | struct nextfnfield *nfp = flp->head; | |
6565 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
6566 | int k; | |
6567 | ||
6568 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
6569 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
6570 | fn_flp->fn_fields = (struct fn_field *) | |
6571 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
6572 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 6573 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
6574 | |
6575 | total_length += flp->length; | |
6576 | } | |
6577 | ||
6578 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
6579 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
6580 | } | |
6581 | ||
1168df01 JB |
6582 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
6583 | language, zero otherwise. */ | |
6584 | static int | |
6585 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
6586 | { | |
6587 | static const char vptr[] = "_vptr"; | |
987504bb | 6588 | static const char vtable[] = "vtable"; |
1168df01 | 6589 | |
987504bb JJ |
6590 | /* Look for the C++ and Java forms of the vtable. */ |
6591 | if ((cu->language == language_java | |
6592 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
6593 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
6594 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
6595 | return 1; |
6596 | ||
6597 | return 0; | |
6598 | } | |
6599 | ||
c0dd20ea | 6600 | /* GCC outputs unnamed structures that are really pointers to member |
0b92b5bb TT |
6601 | functions, with the ABI-specified layout. If TYPE describes |
6602 | such a structure, smash it into a member function type. | |
61049d3b DJ |
6603 | |
6604 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
6605 | This is GCC PR debug/28767. */ | |
c0dd20ea | 6606 | |
0b92b5bb TT |
6607 | static void |
6608 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) | |
c0dd20ea | 6609 | { |
0b92b5bb | 6610 | struct type *pfn_type, *domain_type, *new_type; |
c0dd20ea DJ |
6611 | |
6612 | /* Check for a structure with no name and two children. */ | |
0b92b5bb TT |
6613 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
6614 | return; | |
c0dd20ea DJ |
6615 | |
6616 | /* Check for __pfn and __delta members. */ | |
0b92b5bb TT |
6617 | if (TYPE_FIELD_NAME (type, 0) == NULL |
6618 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 | |
6619 | || TYPE_FIELD_NAME (type, 1) == NULL | |
6620 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) | |
6621 | return; | |
c0dd20ea DJ |
6622 | |
6623 | /* Find the type of the method. */ | |
0b92b5bb | 6624 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
c0dd20ea DJ |
6625 | if (pfn_type == NULL |
6626 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
6627 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
0b92b5bb | 6628 | return; |
c0dd20ea DJ |
6629 | |
6630 | /* Look for the "this" argument. */ | |
6631 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
6632 | if (TYPE_NFIELDS (pfn_type) == 0 | |
0b92b5bb | 6633 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
c0dd20ea | 6634 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
0b92b5bb | 6635 | return; |
c0dd20ea DJ |
6636 | |
6637 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
0b92b5bb TT |
6638 | new_type = alloc_type (objfile); |
6639 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
c0dd20ea DJ |
6640 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
6641 | TYPE_VARARGS (pfn_type)); | |
0b92b5bb | 6642 | smash_to_methodptr_type (type, new_type); |
c0dd20ea | 6643 | } |
1168df01 | 6644 | |
c906108c | 6645 | /* Called when we find the DIE that starts a structure or union scope |
c767944b DJ |
6646 | (definition) to create a type for the structure or union. Fill in |
6647 | the type's name and general properties; the members will not be | |
6648 | processed until process_structure_type. | |
c906108c | 6649 | |
c767944b DJ |
6650 | NOTE: we need to call these functions regardless of whether or not the |
6651 | DIE has a DW_AT_name attribute, since it might be an anonymous | |
c906108c SS |
6652 | structure or union. This gets the type entered into our set of |
6653 | user defined types. | |
6654 | ||
6655 | However, if the structure is incomplete (an opaque struct/union) | |
6656 | then suppress creating a symbol table entry for it since gdb only | |
6657 | wants to find the one with the complete definition. Note that if | |
6658 | it is complete, we just call new_symbol, which does it's own | |
6659 | checking about whether the struct/union is anonymous or not (and | |
6660 | suppresses creating a symbol table entry itself). */ | |
6661 | ||
f792889a | 6662 | static struct type * |
134d01f1 | 6663 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6664 | { |
e7c27a73 | 6665 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6666 | struct type *type; |
6667 | struct attribute *attr; | |
39cbfefa | 6668 | char *name; |
c906108c | 6669 | |
348e048f DE |
6670 | /* If the definition of this type lives in .debug_types, read that type. |
6671 | Don't follow DW_AT_specification though, that will take us back up | |
6672 | the chain and we want to go down. */ | |
6673 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6674 | if (attr) | |
6675 | { | |
6676 | struct dwarf2_cu *type_cu = cu; | |
6677 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6678 | |
348e048f DE |
6679 | /* We could just recurse on read_structure_type, but we need to call |
6680 | get_die_type to ensure only one type for this DIE is created. | |
6681 | This is important, for example, because for c++ classes we need | |
6682 | TYPE_NAME set which is only done by new_symbol. Blech. */ | |
6683 | type = read_type_die (type_die, type_cu); | |
9dc481d3 DE |
6684 | |
6685 | /* TYPE_CU may not be the same as CU. | |
6686 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
6687 | return set_die_type (die, type, cu); |
6688 | } | |
6689 | ||
c0dd20ea | 6690 | type = alloc_type (objfile); |
c906108c | 6691 | INIT_CPLUS_SPECIFIC (type); |
93311388 | 6692 | |
39cbfefa DJ |
6693 | name = dwarf2_name (die, cu); |
6694 | if (name != NULL) | |
c906108c | 6695 | { |
987504bb JJ |
6696 | if (cu->language == language_cplus |
6697 | || cu->language == language_java) | |
63d06c5c | 6698 | { |
3da10d80 KS |
6699 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
6700 | ||
6701 | /* dwarf2_full_name might have already finished building the DIE's | |
6702 | type. If so, there is no need to continue. */ | |
6703 | if (get_die_type (die, cu) != NULL) | |
6704 | return get_die_type (die, cu); | |
6705 | ||
6706 | TYPE_TAG_NAME (type) = full_name; | |
94af9270 KS |
6707 | if (die->tag == DW_TAG_structure_type |
6708 | || die->tag == DW_TAG_class_type) | |
6709 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c DC |
6710 | } |
6711 | else | |
6712 | { | |
d8151005 DJ |
6713 | /* The name is already allocated along with this objfile, so |
6714 | we don't need to duplicate it for the type. */ | |
94af9270 KS |
6715 | TYPE_TAG_NAME (type) = (char *) name; |
6716 | if (die->tag == DW_TAG_class_type) | |
6717 | TYPE_NAME (type) = TYPE_TAG_NAME (type); | |
63d06c5c | 6718 | } |
c906108c SS |
6719 | } |
6720 | ||
6721 | if (die->tag == DW_TAG_structure_type) | |
6722 | { | |
6723 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
6724 | } | |
6725 | else if (die->tag == DW_TAG_union_type) | |
6726 | { | |
6727 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
6728 | } | |
6729 | else | |
6730 | { | |
c906108c SS |
6731 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
6732 | } | |
6733 | ||
0cc2414c TT |
6734 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
6735 | TYPE_DECLARED_CLASS (type) = 1; | |
6736 | ||
e142c38c | 6737 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
6738 | if (attr) |
6739 | { | |
6740 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
6741 | } | |
6742 | else | |
6743 | { | |
6744 | TYPE_LENGTH (type) = 0; | |
6745 | } | |
6746 | ||
876cecd0 | 6747 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 6748 | if (die_is_declaration (die, cu)) |
876cecd0 | 6749 | TYPE_STUB (type) = 1; |
a6c727b2 DJ |
6750 | else if (attr == NULL && die->child == NULL |
6751 | && producer_is_realview (cu->producer)) | |
6752 | /* RealView does not output the required DW_AT_declaration | |
6753 | on incomplete types. */ | |
6754 | TYPE_STUB (type) = 1; | |
dc718098 | 6755 | |
c906108c SS |
6756 | /* We need to add the type field to the die immediately so we don't |
6757 | infinitely recurse when dealing with pointers to the structure | |
6758 | type within the structure itself. */ | |
1c379e20 | 6759 | set_die_type (die, type, cu); |
c906108c | 6760 | |
7e314c57 JK |
6761 | /* set_die_type should be already done. */ |
6762 | set_descriptive_type (type, die, cu); | |
6763 | ||
c767944b DJ |
6764 | return type; |
6765 | } | |
6766 | ||
6767 | /* Finish creating a structure or union type, including filling in | |
6768 | its members and creating a symbol for it. */ | |
6769 | ||
6770 | static void | |
6771 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
6772 | { | |
6773 | struct objfile *objfile = cu->objfile; | |
6774 | struct die_info *child_die = die->child; | |
6775 | struct type *type; | |
6776 | ||
6777 | type = get_die_type (die, cu); | |
6778 | if (type == NULL) | |
6779 | type = read_structure_type (die, cu); | |
6780 | ||
e142c38c | 6781 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
6782 | { |
6783 | struct field_info fi; | |
6784 | struct die_info *child_die; | |
34eaf542 | 6785 | VEC (symbolp) *template_args = NULL; |
c767944b | 6786 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c SS |
6787 | |
6788 | memset (&fi, 0, sizeof (struct field_info)); | |
6789 | ||
639d11d3 | 6790 | child_die = die->child; |
c906108c SS |
6791 | |
6792 | while (child_die && child_die->tag) | |
6793 | { | |
a9a9bd0f DC |
6794 | if (child_die->tag == DW_TAG_member |
6795 | || child_die->tag == DW_TAG_variable) | |
c906108c | 6796 | { |
a9a9bd0f DC |
6797 | /* NOTE: carlton/2002-11-05: A C++ static data member |
6798 | should be a DW_TAG_member that is a declaration, but | |
6799 | all versions of G++ as of this writing (so through at | |
6800 | least 3.2.1) incorrectly generate DW_TAG_variable | |
6801 | tags for them instead. */ | |
e7c27a73 | 6802 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6803 | } |
8713b1b1 | 6804 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
6805 | { |
6806 | /* C++ member function. */ | |
e7c27a73 | 6807 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
6808 | } |
6809 | else if (child_die->tag == DW_TAG_inheritance) | |
6810 | { | |
6811 | /* C++ base class field. */ | |
e7c27a73 | 6812 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 6813 | } |
98751a41 JK |
6814 | else if (child_die->tag == DW_TAG_typedef) |
6815 | dwarf2_add_typedef (&fi, child_die, cu); | |
34eaf542 TT |
6816 | else if (child_die->tag == DW_TAG_template_type_param |
6817 | || child_die->tag == DW_TAG_template_value_param) | |
6818 | { | |
6819 | struct symbol *arg = new_symbol (child_die, NULL, cu); | |
6820 | ||
6821 | VEC_safe_push (symbolp, template_args, arg); | |
6822 | } | |
6823 | ||
c906108c SS |
6824 | child_die = sibling_die (child_die); |
6825 | } | |
6826 | ||
34eaf542 TT |
6827 | /* Attach template arguments to type. */ |
6828 | if (! VEC_empty (symbolp, template_args)) | |
6829 | { | |
6830 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
6831 | TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6832 | = VEC_length (symbolp, template_args); | |
6833 | TYPE_TEMPLATE_ARGUMENTS (type) | |
6834 | = obstack_alloc (&objfile->objfile_obstack, | |
6835 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6836 | * sizeof (struct symbol *))); | |
6837 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), | |
6838 | VEC_address (symbolp, template_args), | |
6839 | (TYPE_N_TEMPLATE_ARGUMENTS (type) | |
6840 | * sizeof (struct symbol *))); | |
6841 | VEC_free (symbolp, template_args); | |
6842 | } | |
6843 | ||
c906108c SS |
6844 | /* Attach fields and member functions to the type. */ |
6845 | if (fi.nfields) | |
e7c27a73 | 6846 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
6847 | if (fi.nfnfields) |
6848 | { | |
e7c27a73 | 6849 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 6850 | |
c5aa993b | 6851 | /* Get the type which refers to the base class (possibly this |
c906108c | 6852 | class itself) which contains the vtable pointer for the current |
0d564a31 DJ |
6853 | class from the DW_AT_containing_type attribute. This use of |
6854 | DW_AT_containing_type is a GNU extension. */ | |
c906108c | 6855 | |
e142c38c | 6856 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 6857 | { |
e7c27a73 | 6858 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
6859 | |
6860 | TYPE_VPTR_BASETYPE (type) = t; | |
6861 | if (type == t) | |
6862 | { | |
c906108c SS |
6863 | int i; |
6864 | ||
6865 | /* Our own class provides vtbl ptr. */ | |
6866 | for (i = TYPE_NFIELDS (t) - 1; | |
6867 | i >= TYPE_N_BASECLASSES (t); | |
6868 | --i) | |
6869 | { | |
6870 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
6871 | ||
1168df01 | 6872 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
6873 | { |
6874 | TYPE_VPTR_FIELDNO (type) = i; | |
6875 | break; | |
6876 | } | |
6877 | } | |
6878 | ||
6879 | /* Complain if virtual function table field not found. */ | |
6880 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 6881 | complaint (&symfile_complaints, |
e2e0b3e5 | 6882 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
6883 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
6884 | ""); | |
c906108c SS |
6885 | } |
6886 | else | |
6887 | { | |
6888 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
6889 | } | |
6890 | } | |
f6235d4c EZ |
6891 | else if (cu->producer |
6892 | && strncmp (cu->producer, | |
6893 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
6894 | { | |
6895 | /* The IBM XLC compiler does not provide direct indication | |
6896 | of the containing type, but the vtable pointer is | |
6897 | always named __vfp. */ | |
6898 | ||
6899 | int i; | |
6900 | ||
6901 | for (i = TYPE_NFIELDS (type) - 1; | |
6902 | i >= TYPE_N_BASECLASSES (type); | |
6903 | --i) | |
6904 | { | |
6905 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
6906 | { | |
6907 | TYPE_VPTR_FIELDNO (type) = i; | |
6908 | TYPE_VPTR_BASETYPE (type) = type; | |
6909 | break; | |
6910 | } | |
6911 | } | |
6912 | } | |
c906108c | 6913 | } |
98751a41 JK |
6914 | |
6915 | /* Copy fi.typedef_field_list linked list elements content into the | |
6916 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ | |
6917 | if (fi.typedef_field_list) | |
6918 | { | |
6919 | int i = fi.typedef_field_list_count; | |
6920 | ||
a0d7a4ff | 6921 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
98751a41 JK |
6922 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
6923 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); | |
6924 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; | |
6925 | ||
6926 | /* Reverse the list order to keep the debug info elements order. */ | |
6927 | while (--i >= 0) | |
6928 | { | |
6929 | struct typedef_field *dest, *src; | |
6e70227d | 6930 | |
98751a41 JK |
6931 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
6932 | src = &fi.typedef_field_list->field; | |
6933 | fi.typedef_field_list = fi.typedef_field_list->next; | |
6934 | *dest = *src; | |
6935 | } | |
6936 | } | |
c767944b DJ |
6937 | |
6938 | do_cleanups (back_to); | |
c906108c | 6939 | } |
63d06c5c | 6940 | |
0b92b5bb TT |
6941 | quirk_gcc_member_function_pointer (type, cu->objfile); |
6942 | ||
90aeadfc DC |
6943 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
6944 | snapshots) has been known to create a die giving a declaration | |
6945 | for a class that has, as a child, a die giving a definition for a | |
6946 | nested class. So we have to process our children even if the | |
6947 | current die is a declaration. Normally, of course, a declaration | |
6948 | won't have any children at all. */ | |
134d01f1 | 6949 | |
90aeadfc DC |
6950 | while (child_die != NULL && child_die->tag) |
6951 | { | |
6952 | if (child_die->tag == DW_TAG_member | |
6953 | || child_die->tag == DW_TAG_variable | |
34eaf542 TT |
6954 | || child_die->tag == DW_TAG_inheritance |
6955 | || child_die->tag == DW_TAG_template_value_param | |
6956 | || child_die->tag == DW_TAG_template_type_param) | |
134d01f1 | 6957 | { |
90aeadfc | 6958 | /* Do nothing. */ |
134d01f1 | 6959 | } |
90aeadfc DC |
6960 | else |
6961 | process_die (child_die, cu); | |
134d01f1 | 6962 | |
90aeadfc | 6963 | child_die = sibling_die (child_die); |
134d01f1 DJ |
6964 | } |
6965 | ||
fa4028e9 JB |
6966 | /* Do not consider external references. According to the DWARF standard, |
6967 | these DIEs are identified by the fact that they have no byte_size | |
6968 | attribute, and a declaration attribute. */ | |
6969 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
6970 | || !die_is_declaration (die, cu)) | |
c767944b | 6971 | new_symbol (die, type, cu); |
134d01f1 DJ |
6972 | } |
6973 | ||
6974 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
6975 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 6976 | |
f792889a | 6977 | static struct type * |
134d01f1 | 6978 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6979 | { |
e7c27a73 | 6980 | struct objfile *objfile = cu->objfile; |
c906108c | 6981 | struct type *type; |
c906108c | 6982 | struct attribute *attr; |
0114d602 | 6983 | const char *name; |
134d01f1 | 6984 | |
348e048f DE |
6985 | /* If the definition of this type lives in .debug_types, read that type. |
6986 | Don't follow DW_AT_specification though, that will take us back up | |
6987 | the chain and we want to go down. */ | |
6988 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); | |
6989 | if (attr) | |
6990 | { | |
6991 | struct dwarf2_cu *type_cu = cu; | |
6992 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
9a619af0 | 6993 | |
348e048f | 6994 | type = read_type_die (type_die, type_cu); |
9dc481d3 DE |
6995 | |
6996 | /* TYPE_CU may not be the same as CU. | |
6997 | Ensure TYPE is recorded in CU's type_hash table. */ | |
348e048f DE |
6998 | return set_die_type (die, type, cu); |
6999 | } | |
7000 | ||
c906108c SS |
7001 | type = alloc_type (objfile); |
7002 | ||
7003 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
94af9270 | 7004 | name = dwarf2_full_name (NULL, die, cu); |
39cbfefa | 7005 | if (name != NULL) |
0114d602 | 7006 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 7007 | |
e142c38c | 7008 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7009 | if (attr) |
7010 | { | |
7011 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7012 | } | |
7013 | else | |
7014 | { | |
7015 | TYPE_LENGTH (type) = 0; | |
7016 | } | |
7017 | ||
137033e9 JB |
7018 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
7019 | declared as private in the package spec, and then defined only | |
7020 | inside the package body. Such types are known as Taft Amendment | |
7021 | Types. When another package uses such a type, an incomplete DIE | |
7022 | may be generated by the compiler. */ | |
02eb380e | 7023 | if (die_is_declaration (die, cu)) |
876cecd0 | 7024 | TYPE_STUB (type) = 1; |
02eb380e | 7025 | |
f792889a | 7026 | return set_die_type (die, type, cu); |
134d01f1 DJ |
7027 | } |
7028 | ||
7029 | /* Given a pointer to a die which begins an enumeration, process all | |
7030 | the dies that define the members of the enumeration, and create the | |
7031 | symbol for the enumeration type. | |
7032 | ||
7033 | NOTE: We reverse the order of the element list. */ | |
7034 | ||
7035 | static void | |
7036 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
7037 | { | |
f792889a | 7038 | struct type *this_type; |
134d01f1 | 7039 | |
f792889a DJ |
7040 | this_type = get_die_type (die, cu); |
7041 | if (this_type == NULL) | |
7042 | this_type = read_enumeration_type (die, cu); | |
9dc481d3 | 7043 | |
639d11d3 | 7044 | if (die->child != NULL) |
c906108c | 7045 | { |
9dc481d3 DE |
7046 | struct die_info *child_die; |
7047 | struct symbol *sym; | |
7048 | struct field *fields = NULL; | |
7049 | int num_fields = 0; | |
7050 | int unsigned_enum = 1; | |
7051 | char *name; | |
7052 | ||
639d11d3 | 7053 | child_die = die->child; |
c906108c SS |
7054 | while (child_die && child_die->tag) |
7055 | { | |
7056 | if (child_die->tag != DW_TAG_enumerator) | |
7057 | { | |
e7c27a73 | 7058 | process_die (child_die, cu); |
c906108c SS |
7059 | } |
7060 | else | |
7061 | { | |
39cbfefa DJ |
7062 | name = dwarf2_name (child_die, cu); |
7063 | if (name) | |
c906108c | 7064 | { |
f792889a | 7065 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
7066 | if (SYMBOL_VALUE (sym) < 0) |
7067 | unsigned_enum = 0; | |
7068 | ||
7069 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
7070 | { | |
7071 | fields = (struct field *) | |
7072 | xrealloc (fields, | |
7073 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 7074 | * sizeof (struct field)); |
c906108c SS |
7075 | } |
7076 | ||
3567439c | 7077 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 7078 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 7079 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
7080 | FIELD_BITSIZE (fields[num_fields]) = 0; |
7081 | ||
7082 | num_fields++; | |
7083 | } | |
7084 | } | |
7085 | ||
7086 | child_die = sibling_die (child_die); | |
7087 | } | |
7088 | ||
7089 | if (num_fields) | |
7090 | { | |
f792889a DJ |
7091 | TYPE_NFIELDS (this_type) = num_fields; |
7092 | TYPE_FIELDS (this_type) = (struct field *) | |
7093 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
7094 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 7095 | sizeof (struct field) * num_fields); |
b8c9b27d | 7096 | xfree (fields); |
c906108c SS |
7097 | } |
7098 | if (unsigned_enum) | |
876cecd0 | 7099 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 7100 | } |
134d01f1 | 7101 | |
f792889a | 7102 | new_symbol (die, this_type, cu); |
c906108c SS |
7103 | } |
7104 | ||
7105 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
7106 | the DIE's type field. For now, this only handles one dimensional | |
7107 | arrays. */ | |
7108 | ||
f792889a | 7109 | static struct type * |
e7c27a73 | 7110 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7111 | { |
e7c27a73 | 7112 | struct objfile *objfile = cu->objfile; |
c906108c | 7113 | struct die_info *child_die; |
7e314c57 | 7114 | struct type *type; |
c906108c SS |
7115 | struct type *element_type, *range_type, *index_type; |
7116 | struct type **range_types = NULL; | |
7117 | struct attribute *attr; | |
7118 | int ndim = 0; | |
7119 | struct cleanup *back_to; | |
39cbfefa | 7120 | char *name; |
c906108c | 7121 | |
e7c27a73 | 7122 | element_type = die_type (die, cu); |
c906108c | 7123 | |
7e314c57 JK |
7124 | /* The die_type call above may have already set the type for this DIE. */ |
7125 | type = get_die_type (die, cu); | |
7126 | if (type) | |
7127 | return type; | |
7128 | ||
c906108c SS |
7129 | /* Irix 6.2 native cc creates array types without children for |
7130 | arrays with unspecified length. */ | |
639d11d3 | 7131 | if (die->child == NULL) |
c906108c | 7132 | { |
46bf5051 | 7133 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7134 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
7135 | type = create_array_type (NULL, element_type, range_type); |
7136 | return set_die_type (die, type, cu); | |
c906108c SS |
7137 | } |
7138 | ||
7139 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 7140 | child_die = die->child; |
c906108c SS |
7141 | while (child_die && child_die->tag) |
7142 | { | |
7143 | if (child_die->tag == DW_TAG_subrange_type) | |
7144 | { | |
f792889a | 7145 | struct type *child_type = read_type_die (child_die, cu); |
9a619af0 | 7146 | |
f792889a | 7147 | if (child_type != NULL) |
a02abb62 JB |
7148 | { |
7149 | /* The range type was succesfully read. Save it for | |
7150 | the array type creation. */ | |
7151 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
7152 | { | |
7153 | range_types = (struct type **) | |
7154 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
7155 | * sizeof (struct type *)); | |
7156 | if (ndim == 0) | |
7157 | make_cleanup (free_current_contents, &range_types); | |
7158 | } | |
f792889a | 7159 | range_types[ndim++] = child_type; |
a02abb62 | 7160 | } |
c906108c SS |
7161 | } |
7162 | child_die = sibling_die (child_die); | |
7163 | } | |
7164 | ||
7165 | /* Dwarf2 dimensions are output from left to right, create the | |
7166 | necessary array types in backwards order. */ | |
7ca2d3a3 | 7167 | |
c906108c | 7168 | type = element_type; |
7ca2d3a3 DL |
7169 | |
7170 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
7171 | { | |
7172 | int i = 0; | |
9a619af0 | 7173 | |
7ca2d3a3 DL |
7174 | while (i < ndim) |
7175 | type = create_array_type (NULL, type, range_types[i++]); | |
7176 | } | |
7177 | else | |
7178 | { | |
7179 | while (ndim-- > 0) | |
7180 | type = create_array_type (NULL, type, range_types[ndim]); | |
7181 | } | |
c906108c | 7182 | |
f5f8a009 EZ |
7183 | /* Understand Dwarf2 support for vector types (like they occur on |
7184 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
7185 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
7186 | custom vendor extension. The main difference between a regular | |
7187 | array and the vector variant is that vectors are passed by value | |
7188 | to functions. */ | |
e142c38c | 7189 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 7190 | if (attr) |
ea37ba09 | 7191 | make_vector_type (type); |
f5f8a009 | 7192 | |
39cbfefa DJ |
7193 | name = dwarf2_name (die, cu); |
7194 | if (name) | |
7195 | TYPE_NAME (type) = name; | |
6e70227d | 7196 | |
7e314c57 JK |
7197 | /* Install the type in the die. */ |
7198 | set_die_type (die, type, cu); | |
7199 | ||
7200 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
7201 | set_descriptive_type (type, die, cu); |
7202 | ||
c906108c SS |
7203 | do_cleanups (back_to); |
7204 | ||
7e314c57 | 7205 | return type; |
c906108c SS |
7206 | } |
7207 | ||
7ca2d3a3 | 7208 | static enum dwarf_array_dim_ordering |
6e70227d | 7209 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
7ca2d3a3 DL |
7210 | { |
7211 | struct attribute *attr; | |
7212 | ||
7213 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
7214 | ||
7215 | if (attr) return DW_SND (attr); | |
7216 | ||
7217 | /* | |
7218 | GNU F77 is a special case, as at 08/2004 array type info is the | |
6e70227d | 7219 | opposite order to the dwarf2 specification, but data is still |
7ca2d3a3 DL |
7220 | laid out as per normal fortran. |
7221 | ||
6e70227d | 7222 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
7ca2d3a3 DL |
7223 | version checking. |
7224 | */ | |
7225 | ||
905e0470 PM |
7226 | if (cu->language == language_fortran |
7227 | && cu->producer && strstr (cu->producer, "GNU F77")) | |
7ca2d3a3 DL |
7228 | { |
7229 | return DW_ORD_row_major; | |
7230 | } | |
7231 | ||
6e70227d | 7232 | switch (cu->language_defn->la_array_ordering) |
7ca2d3a3 DL |
7233 | { |
7234 | case array_column_major: | |
7235 | return DW_ORD_col_major; | |
7236 | case array_row_major: | |
7237 | default: | |
7238 | return DW_ORD_row_major; | |
7239 | }; | |
7240 | } | |
7241 | ||
72019c9c GM |
7242 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
7243 | the DIE's type field. */ | |
7244 | ||
f792889a | 7245 | static struct type * |
72019c9c GM |
7246 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
7247 | { | |
7e314c57 JK |
7248 | struct type *domain_type, *set_type; |
7249 | struct attribute *attr; | |
f792889a | 7250 | |
7e314c57 JK |
7251 | domain_type = die_type (die, cu); |
7252 | ||
7253 | /* The die_type call above may have already set the type for this DIE. */ | |
7254 | set_type = get_die_type (die, cu); | |
7255 | if (set_type) | |
7256 | return set_type; | |
7257 | ||
7258 | set_type = create_set_type (NULL, domain_type); | |
7259 | ||
7260 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |
d09039dd PM |
7261 | if (attr) |
7262 | TYPE_LENGTH (set_type) = DW_UNSND (attr); | |
7e314c57 | 7263 | |
f792889a | 7264 | return set_die_type (die, set_type, cu); |
72019c9c | 7265 | } |
7ca2d3a3 | 7266 | |
c906108c SS |
7267 | /* First cut: install each common block member as a global variable. */ |
7268 | ||
7269 | static void | |
e7c27a73 | 7270 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7271 | { |
7272 | struct die_info *child_die; | |
7273 | struct attribute *attr; | |
7274 | struct symbol *sym; | |
7275 | CORE_ADDR base = (CORE_ADDR) 0; | |
7276 | ||
e142c38c | 7277 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7278 | if (attr) |
7279 | { | |
8e19ed76 PS |
7280 | /* Support the .debug_loc offsets */ |
7281 | if (attr_form_is_block (attr)) | |
7282 | { | |
e7c27a73 | 7283 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 7284 | } |
3690dd37 | 7285 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 7286 | { |
4d3c2250 | 7287 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
7288 | } |
7289 | else | |
7290 | { | |
4d3c2250 KB |
7291 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
7292 | "common block member"); | |
8e19ed76 | 7293 | } |
c906108c | 7294 | } |
639d11d3 | 7295 | if (die->child != NULL) |
c906108c | 7296 | { |
639d11d3 | 7297 | child_die = die->child; |
c906108c SS |
7298 | while (child_die && child_die->tag) |
7299 | { | |
e7c27a73 | 7300 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 7301 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
7302 | if (attr) |
7303 | { | |
d4b96c9a JK |
7304 | CORE_ADDR byte_offset = 0; |
7305 | ||
7306 | if (attr_form_is_section_offset (attr)) | |
7307 | dwarf2_complex_location_expr_complaint (); | |
7308 | else if (attr_form_is_constant (attr)) | |
7309 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); | |
7310 | else if (attr_form_is_block (attr)) | |
7311 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); | |
7312 | else | |
7313 | dwarf2_complex_location_expr_complaint (); | |
7314 | ||
7315 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; | |
c906108c SS |
7316 | add_symbol_to_list (sym, &global_symbols); |
7317 | } | |
7318 | child_die = sibling_die (child_die); | |
7319 | } | |
7320 | } | |
7321 | } | |
7322 | ||
0114d602 | 7323 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 7324 | |
0114d602 DJ |
7325 | static struct type * |
7326 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 7327 | { |
e7c27a73 | 7328 | struct objfile *objfile = cu->objfile; |
0114d602 | 7329 | const char *previous_prefix, *name; |
9219021c | 7330 | int is_anonymous; |
0114d602 DJ |
7331 | struct type *type; |
7332 | ||
7333 | /* For extensions, reuse the type of the original namespace. */ | |
7334 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
7335 | { | |
7336 | struct die_info *ext_die; | |
7337 | struct dwarf2_cu *ext_cu = cu; | |
9a619af0 | 7338 | |
0114d602 DJ |
7339 | ext_die = dwarf2_extension (die, &ext_cu); |
7340 | type = read_type_die (ext_die, ext_cu); | |
9dc481d3 DE |
7341 | |
7342 | /* EXT_CU may not be the same as CU. | |
7343 | Ensure TYPE is recorded in CU's type_hash table. */ | |
0114d602 DJ |
7344 | return set_die_type (die, type, cu); |
7345 | } | |
9219021c | 7346 | |
e142c38c | 7347 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
7348 | |
7349 | /* Now build the name of the current namespace. */ | |
7350 | ||
0114d602 DJ |
7351 | previous_prefix = determine_prefix (die, cu); |
7352 | if (previous_prefix[0] != '\0') | |
7353 | name = typename_concat (&objfile->objfile_obstack, | |
f55ee35c | 7354 | previous_prefix, name, 0, cu); |
0114d602 DJ |
7355 | |
7356 | /* Create the type. */ | |
7357 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
7358 | objfile); | |
7359 | TYPE_NAME (type) = (char *) name; | |
7360 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7361 | ||
60531b24 | 7362 | return set_die_type (die, type, cu); |
0114d602 DJ |
7363 | } |
7364 | ||
7365 | /* Read a C++ namespace. */ | |
7366 | ||
7367 | static void | |
7368 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
7369 | { | |
7370 | struct objfile *objfile = cu->objfile; | |
7371 | const char *name; | |
7372 | int is_anonymous; | |
9219021c | 7373 | |
5c4e30ca DC |
7374 | /* Add a symbol associated to this if we haven't seen the namespace |
7375 | before. Also, add a using directive if it's an anonymous | |
7376 | namespace. */ | |
9219021c | 7377 | |
f2f0e013 | 7378 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
7379 | { |
7380 | struct type *type; | |
7381 | ||
0114d602 | 7382 | type = read_type_die (die, cu); |
e7c27a73 | 7383 | new_symbol (die, type, cu); |
5c4e30ca | 7384 | |
0114d602 | 7385 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 7386 | if (is_anonymous) |
0114d602 DJ |
7387 | { |
7388 | const char *previous_prefix = determine_prefix (die, cu); | |
9a619af0 | 7389 | |
c0cc3a76 | 7390 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
13387711 | 7391 | NULL, &objfile->objfile_obstack); |
0114d602 | 7392 | } |
5c4e30ca | 7393 | } |
9219021c | 7394 | |
639d11d3 | 7395 | if (die->child != NULL) |
d9fa45fe | 7396 | { |
639d11d3 | 7397 | struct die_info *child_die = die->child; |
6e70227d | 7398 | |
d9fa45fe DC |
7399 | while (child_die && child_die->tag) |
7400 | { | |
e7c27a73 | 7401 | process_die (child_die, cu); |
d9fa45fe DC |
7402 | child_die = sibling_die (child_die); |
7403 | } | |
7404 | } | |
38d518c9 EZ |
7405 | } |
7406 | ||
f55ee35c JK |
7407 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
7408 | imported module. Still we need that type as local Fortran "use ... only" | |
7409 | declaration imports depend on the created type in determine_prefix. */ | |
7410 | ||
7411 | static struct type * | |
7412 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) | |
7413 | { | |
7414 | struct objfile *objfile = cu->objfile; | |
7415 | char *module_name; | |
7416 | struct type *type; | |
7417 | ||
7418 | module_name = dwarf2_name (die, cu); | |
7419 | if (!module_name) | |
7420 | complaint (&symfile_complaints, _("DW_TAG_module has no name, offset 0x%x"), | |
7421 | die->offset); | |
7422 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); | |
7423 | ||
7424 | /* determine_prefix uses TYPE_TAG_NAME. */ | |
7425 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
7426 | ||
7427 | return set_die_type (die, type, cu); | |
7428 | } | |
7429 | ||
5d7cb8df JK |
7430 | /* Read a Fortran module. */ |
7431 | ||
7432 | static void | |
7433 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
7434 | { | |
7435 | struct die_info *child_die = die->child; | |
7436 | ||
5d7cb8df JK |
7437 | while (child_die && child_die->tag) |
7438 | { | |
7439 | process_die (child_die, cu); | |
7440 | child_die = sibling_die (child_die); | |
7441 | } | |
7442 | } | |
7443 | ||
38d518c9 EZ |
7444 | /* Return the name of the namespace represented by DIE. Set |
7445 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
7446 | namespace. */ | |
7447 | ||
7448 | static const char * | |
e142c38c | 7449 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
7450 | { |
7451 | struct die_info *current_die; | |
7452 | const char *name = NULL; | |
7453 | ||
7454 | /* Loop through the extensions until we find a name. */ | |
7455 | ||
7456 | for (current_die = die; | |
7457 | current_die != NULL; | |
f2f0e013 | 7458 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 7459 | { |
e142c38c | 7460 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
7461 | if (name != NULL) |
7462 | break; | |
7463 | } | |
7464 | ||
7465 | /* Is it an anonymous namespace? */ | |
7466 | ||
7467 | *is_anonymous = (name == NULL); | |
7468 | if (*is_anonymous) | |
7469 | name = "(anonymous namespace)"; | |
7470 | ||
7471 | return name; | |
d9fa45fe DC |
7472 | } |
7473 | ||
c906108c SS |
7474 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
7475 | the user defined type vector. */ | |
7476 | ||
f792889a | 7477 | static struct type * |
e7c27a73 | 7478 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7479 | { |
5e2b427d | 7480 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 7481 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 7482 | struct type *type; |
8b2dbe47 KB |
7483 | struct attribute *attr_byte_size; |
7484 | struct attribute *attr_address_class; | |
7485 | int byte_size, addr_class; | |
7e314c57 JK |
7486 | struct type *target_type; |
7487 | ||
7488 | target_type = die_type (die, cu); | |
c906108c | 7489 | |
7e314c57 JK |
7490 | /* The die_type call above may have already set the type for this DIE. */ |
7491 | type = get_die_type (die, cu); | |
7492 | if (type) | |
7493 | return type; | |
7494 | ||
7495 | type = lookup_pointer_type (target_type); | |
8b2dbe47 | 7496 | |
e142c38c | 7497 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
7498 | if (attr_byte_size) |
7499 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 7500 | else |
8b2dbe47 KB |
7501 | byte_size = cu_header->addr_size; |
7502 | ||
e142c38c | 7503 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
7504 | if (attr_address_class) |
7505 | addr_class = DW_UNSND (attr_address_class); | |
7506 | else | |
7507 | addr_class = DW_ADDR_none; | |
7508 | ||
7509 | /* If the pointer size or address class is different than the | |
7510 | default, create a type variant marked as such and set the | |
7511 | length accordingly. */ | |
7512 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 7513 | { |
5e2b427d | 7514 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
7515 | { |
7516 | int type_flags; | |
7517 | ||
849957d9 | 7518 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 7519 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
7520 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
7521 | == 0); | |
8b2dbe47 KB |
7522 | type = make_type_with_address_space (type, type_flags); |
7523 | } | |
7524 | else if (TYPE_LENGTH (type) != byte_size) | |
7525 | { | |
e2e0b3e5 | 7526 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 | 7527 | } |
6e70227d | 7528 | else |
9a619af0 MS |
7529 | { |
7530 | /* Should we also complain about unhandled address classes? */ | |
7531 | } | |
c906108c | 7532 | } |
8b2dbe47 KB |
7533 | |
7534 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 7535 | return set_die_type (die, type, cu); |
c906108c SS |
7536 | } |
7537 | ||
7538 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
7539 | the user defined type vector. */ | |
7540 | ||
f792889a | 7541 | static struct type * |
e7c27a73 | 7542 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7543 | { |
7544 | struct type *type; | |
7545 | struct type *to_type; | |
7546 | struct type *domain; | |
7547 | ||
e7c27a73 DJ |
7548 | to_type = die_type (die, cu); |
7549 | domain = die_containing_type (die, cu); | |
0d5de010 | 7550 | |
7e314c57 JK |
7551 | /* The calls above may have already set the type for this DIE. */ |
7552 | type = get_die_type (die, cu); | |
7553 | if (type) | |
7554 | return type; | |
7555 | ||
0d5de010 DJ |
7556 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
7557 | type = lookup_methodptr_type (to_type); | |
7558 | else | |
7559 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 7560 | |
f792889a | 7561 | return set_die_type (die, type, cu); |
c906108c SS |
7562 | } |
7563 | ||
7564 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
7565 | the user defined type vector. */ | |
7566 | ||
f792889a | 7567 | static struct type * |
e7c27a73 | 7568 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7569 | { |
e7c27a73 | 7570 | struct comp_unit_head *cu_header = &cu->header; |
7e314c57 | 7571 | struct type *type, *target_type; |
c906108c SS |
7572 | struct attribute *attr; |
7573 | ||
7e314c57 JK |
7574 | target_type = die_type (die, cu); |
7575 | ||
7576 | /* The die_type call above may have already set the type for this DIE. */ | |
7577 | type = get_die_type (die, cu); | |
7578 | if (type) | |
7579 | return type; | |
7580 | ||
7581 | type = lookup_reference_type (target_type); | |
e142c38c | 7582 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7583 | if (attr) |
7584 | { | |
7585 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
7586 | } | |
7587 | else | |
7588 | { | |
107d2387 | 7589 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 7590 | } |
f792889a | 7591 | return set_die_type (die, type, cu); |
c906108c SS |
7592 | } |
7593 | ||
f792889a | 7594 | static struct type * |
e7c27a73 | 7595 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7596 | { |
f792889a | 7597 | struct type *base_type, *cv_type; |
c906108c | 7598 | |
e7c27a73 | 7599 | base_type = die_type (die, cu); |
7e314c57 JK |
7600 | |
7601 | /* The die_type call above may have already set the type for this DIE. */ | |
7602 | cv_type = get_die_type (die, cu); | |
7603 | if (cv_type) | |
7604 | return cv_type; | |
7605 | ||
f792889a DJ |
7606 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
7607 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7608 | } |
7609 | ||
f792889a | 7610 | static struct type * |
e7c27a73 | 7611 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7612 | { |
f792889a | 7613 | struct type *base_type, *cv_type; |
c906108c | 7614 | |
e7c27a73 | 7615 | base_type = die_type (die, cu); |
7e314c57 JK |
7616 | |
7617 | /* The die_type call above may have already set the type for this DIE. */ | |
7618 | cv_type = get_die_type (die, cu); | |
7619 | if (cv_type) | |
7620 | return cv_type; | |
7621 | ||
f792889a DJ |
7622 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
7623 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
7624 | } |
7625 | ||
7626 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
7627 | the user defined type vector. It isn't really a user defined type, | |
7628 | but it behaves like one, with other DIE's using an AT_user_def_type | |
7629 | attribute to reference it. */ | |
7630 | ||
f792889a | 7631 | static struct type * |
e7c27a73 | 7632 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7633 | { |
e7c27a73 | 7634 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 7635 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7636 | struct type *type, *range_type, *index_type, *char_type; |
7637 | struct attribute *attr; | |
7638 | unsigned int length; | |
7639 | ||
e142c38c | 7640 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
7641 | if (attr) |
7642 | { | |
7643 | length = DW_UNSND (attr); | |
7644 | } | |
7645 | else | |
7646 | { | |
b21b22e0 | 7647 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 7648 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
7649 | if (attr) |
7650 | { | |
7651 | length = DW_UNSND (attr); | |
7652 | } | |
7653 | else | |
7654 | { | |
7655 | length = 1; | |
7656 | } | |
c906108c | 7657 | } |
6ccb9162 | 7658 | |
46bf5051 | 7659 | index_type = objfile_type (objfile)->builtin_int; |
c906108c | 7660 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
7661 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
7662 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 7663 | |
f792889a | 7664 | return set_die_type (die, type, cu); |
c906108c SS |
7665 | } |
7666 | ||
7667 | /* Handle DIES due to C code like: | |
7668 | ||
7669 | struct foo | |
c5aa993b JM |
7670 | { |
7671 | int (*funcp)(int a, long l); | |
7672 | int b; | |
7673 | }; | |
c906108c SS |
7674 | |
7675 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 7676 | */ |
c906108c | 7677 | |
f792889a | 7678 | static struct type * |
e7c27a73 | 7679 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7680 | { |
7681 | struct type *type; /* Type that this function returns */ | |
7682 | struct type *ftype; /* Function that returns above type */ | |
7683 | struct attribute *attr; | |
7684 | ||
e7c27a73 | 7685 | type = die_type (die, cu); |
7e314c57 JK |
7686 | |
7687 | /* The die_type call above may have already set the type for this DIE. */ | |
7688 | ftype = get_die_type (die, cu); | |
7689 | if (ftype) | |
7690 | return ftype; | |
7691 | ||
0c8b41f1 | 7692 | ftype = lookup_function_type (type); |
c906108c | 7693 | |
5b8101ae | 7694 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 7695 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 7696 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 7697 | || cu->language == language_cplus |
5b8101ae PM |
7698 | || cu->language == language_java |
7699 | || cu->language == language_pascal) | |
876cecd0 | 7700 | TYPE_PROTOTYPED (ftype) = 1; |
a6c727b2 DJ |
7701 | else if (producer_is_realview (cu->producer)) |
7702 | /* RealView does not emit DW_AT_prototyped. We can not | |
7703 | distinguish prototyped and unprototyped functions; default to | |
7704 | prototyped, since that is more common in modern code (and | |
7705 | RealView warns about unprototyped functions). */ | |
7706 | TYPE_PROTOTYPED (ftype) = 1; | |
c906108c | 7707 | |
c055b101 CV |
7708 | /* Store the calling convention in the type if it's available in |
7709 | the subroutine die. Otherwise set the calling convention to | |
7710 | the default value DW_CC_normal. */ | |
7711 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
7712 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
76c10ea2 GM |
7713 | |
7714 | /* We need to add the subroutine type to the die immediately so | |
7715 | we don't infinitely recurse when dealing with parameters | |
7716 | declared as the same subroutine type. */ | |
7717 | set_die_type (die, ftype, cu); | |
6e70227d | 7718 | |
639d11d3 | 7719 | if (die->child != NULL) |
c906108c | 7720 | { |
8072405b | 7721 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
c906108c | 7722 | struct die_info *child_die; |
8072405b | 7723 | int nparams, iparams; |
c906108c SS |
7724 | |
7725 | /* Count the number of parameters. | |
7726 | FIXME: GDB currently ignores vararg functions, but knows about | |
7727 | vararg member functions. */ | |
8072405b | 7728 | nparams = 0; |
639d11d3 | 7729 | child_die = die->child; |
c906108c SS |
7730 | while (child_die && child_die->tag) |
7731 | { | |
7732 | if (child_die->tag == DW_TAG_formal_parameter) | |
7733 | nparams++; | |
7734 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 7735 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
7736 | child_die = sibling_die (child_die); |
7737 | } | |
7738 | ||
7739 | /* Allocate storage for parameters and fill them in. */ | |
7740 | TYPE_NFIELDS (ftype) = nparams; | |
7741 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 7742 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 7743 | |
8072405b JK |
7744 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
7745 | even if we error out during the parameters reading below. */ | |
7746 | for (iparams = 0; iparams < nparams; iparams++) | |
7747 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; | |
7748 | ||
7749 | iparams = 0; | |
639d11d3 | 7750 | child_die = die->child; |
c906108c SS |
7751 | while (child_die && child_die->tag) |
7752 | { | |
7753 | if (child_die->tag == DW_TAG_formal_parameter) | |
7754 | { | |
3ce3b1ba PA |
7755 | struct type *arg_type; |
7756 | ||
7757 | /* DWARF version 2 has no clean way to discern C++ | |
7758 | static and non-static member functions. G++ helps | |
7759 | GDB by marking the first parameter for non-static | |
7760 | member functions (which is the this pointer) as | |
7761 | artificial. We pass this information to | |
7762 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. | |
7763 | ||
7764 | DWARF version 3 added DW_AT_object_pointer, which GCC | |
7765 | 4.5 does not yet generate. */ | |
e142c38c | 7766 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
7767 | if (attr) |
7768 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
7769 | else | |
418835cc KS |
7770 | { |
7771 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
7772 | ||
7773 | /* GCC/43521: In java, the formal parameter | |
7774 | "this" is sometimes not marked with DW_AT_artificial. */ | |
7775 | if (cu->language == language_java) | |
7776 | { | |
7777 | const char *name = dwarf2_name (child_die, cu); | |
9a619af0 | 7778 | |
418835cc KS |
7779 | if (name && !strcmp (name, "this")) |
7780 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; | |
7781 | } | |
7782 | } | |
3ce3b1ba PA |
7783 | arg_type = die_type (child_die, cu); |
7784 | ||
7785 | /* RealView does not mark THIS as const, which the testsuite | |
7786 | expects. GCC marks THIS as const in method definitions, | |
7787 | but not in the class specifications (GCC PR 43053). */ | |
7788 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) | |
7789 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) | |
7790 | { | |
7791 | int is_this = 0; | |
7792 | struct dwarf2_cu *arg_cu = cu; | |
7793 | const char *name = dwarf2_name (child_die, cu); | |
7794 | ||
7795 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); | |
7796 | if (attr) | |
7797 | { | |
7798 | /* If the compiler emits this, use it. */ | |
7799 | if (follow_die_ref (die, attr, &arg_cu) == child_die) | |
7800 | is_this = 1; | |
7801 | } | |
7802 | else if (name && strcmp (name, "this") == 0) | |
7803 | /* Function definitions will have the argument names. */ | |
7804 | is_this = 1; | |
7805 | else if (name == NULL && iparams == 0) | |
7806 | /* Declarations may not have the names, so like | |
7807 | elsewhere in GDB, assume an artificial first | |
7808 | argument is "this". */ | |
7809 | is_this = 1; | |
7810 | ||
7811 | if (is_this) | |
7812 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), | |
7813 | arg_type, 0); | |
7814 | } | |
7815 | ||
7816 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; | |
c906108c SS |
7817 | iparams++; |
7818 | } | |
7819 | child_die = sibling_die (child_die); | |
7820 | } | |
7821 | } | |
7822 | ||
76c10ea2 | 7823 | return ftype; |
c906108c SS |
7824 | } |
7825 | ||
f792889a | 7826 | static struct type * |
e7c27a73 | 7827 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7828 | { |
e7c27a73 | 7829 | struct objfile *objfile = cu->objfile; |
0114d602 | 7830 | const char *name = NULL; |
f792889a | 7831 | struct type *this_type; |
c906108c | 7832 | |
94af9270 | 7833 | name = dwarf2_full_name (NULL, die, cu); |
f792889a | 7834 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
7835 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
7836 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
7837 | set_die_type (die, this_type, cu); |
7838 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
7839 | return this_type; | |
c906108c SS |
7840 | } |
7841 | ||
7842 | /* Find a representation of a given base type and install | |
7843 | it in the TYPE field of the die. */ | |
7844 | ||
f792889a | 7845 | static struct type * |
e7c27a73 | 7846 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7847 | { |
e7c27a73 | 7848 | struct objfile *objfile = cu->objfile; |
c906108c SS |
7849 | struct type *type; |
7850 | struct attribute *attr; | |
7851 | int encoding = 0, size = 0; | |
39cbfefa | 7852 | char *name; |
6ccb9162 UW |
7853 | enum type_code code = TYPE_CODE_INT; |
7854 | int type_flags = 0; | |
7855 | struct type *target_type = NULL; | |
c906108c | 7856 | |
e142c38c | 7857 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
7858 | if (attr) |
7859 | { | |
7860 | encoding = DW_UNSND (attr); | |
7861 | } | |
e142c38c | 7862 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
7863 | if (attr) |
7864 | { | |
7865 | size = DW_UNSND (attr); | |
7866 | } | |
39cbfefa | 7867 | name = dwarf2_name (die, cu); |
6ccb9162 | 7868 | if (!name) |
c906108c | 7869 | { |
6ccb9162 UW |
7870 | complaint (&symfile_complaints, |
7871 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 7872 | } |
6ccb9162 UW |
7873 | |
7874 | switch (encoding) | |
c906108c | 7875 | { |
6ccb9162 UW |
7876 | case DW_ATE_address: |
7877 | /* Turn DW_ATE_address into a void * pointer. */ | |
7878 | code = TYPE_CODE_PTR; | |
7879 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7880 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
7881 | break; | |
7882 | case DW_ATE_boolean: | |
7883 | code = TYPE_CODE_BOOL; | |
7884 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7885 | break; | |
7886 | case DW_ATE_complex_float: | |
7887 | code = TYPE_CODE_COMPLEX; | |
7888 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
7889 | break; | |
7890 | case DW_ATE_decimal_float: | |
7891 | code = TYPE_CODE_DECFLOAT; | |
7892 | break; | |
7893 | case DW_ATE_float: | |
7894 | code = TYPE_CODE_FLT; | |
7895 | break; | |
7896 | case DW_ATE_signed: | |
7897 | break; | |
7898 | case DW_ATE_unsigned: | |
7899 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7900 | break; | |
7901 | case DW_ATE_signed_char: | |
6e70227d | 7902 | if (cu->language == language_ada || cu->language == language_m2 |
868a0084 | 7903 | || cu->language == language_pascal) |
6ccb9162 UW |
7904 | code = TYPE_CODE_CHAR; |
7905 | break; | |
7906 | case DW_ATE_unsigned_char: | |
868a0084 PM |
7907 | if (cu->language == language_ada || cu->language == language_m2 |
7908 | || cu->language == language_pascal) | |
6ccb9162 UW |
7909 | code = TYPE_CODE_CHAR; |
7910 | type_flags |= TYPE_FLAG_UNSIGNED; | |
7911 | break; | |
75079b2b TT |
7912 | case DW_ATE_UTF: |
7913 | /* We just treat this as an integer and then recognize the | |
7914 | type by name elsewhere. */ | |
7915 | break; | |
7916 | ||
6ccb9162 UW |
7917 | default: |
7918 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
7919 | dwarf_type_encoding_name (encoding)); | |
7920 | break; | |
c906108c | 7921 | } |
6ccb9162 | 7922 | |
0114d602 DJ |
7923 | type = init_type (code, size, type_flags, NULL, objfile); |
7924 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
7925 | TYPE_TARGET_TYPE (type) = target_type; |
7926 | ||
0114d602 | 7927 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 7928 | TYPE_NOSIGN (type) = 1; |
0114d602 | 7929 | |
f792889a | 7930 | return set_die_type (die, type, cu); |
c906108c SS |
7931 | } |
7932 | ||
a02abb62 JB |
7933 | /* Read the given DW_AT_subrange DIE. */ |
7934 | ||
f792889a | 7935 | static struct type * |
a02abb62 JB |
7936 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
7937 | { | |
5e2b427d | 7938 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
7939 | struct type *base_type; |
7940 | struct type *range_type; | |
7941 | struct attribute *attr; | |
43bbcdc2 PH |
7942 | LONGEST low = 0; |
7943 | LONGEST high = -1; | |
39cbfefa | 7944 | char *name; |
43bbcdc2 | 7945 | LONGEST negative_mask; |
e77813c8 | 7946 | |
a02abb62 | 7947 | base_type = die_type (die, cu); |
953ac07e JK |
7948 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
7949 | check_typedef (base_type); | |
a02abb62 | 7950 | |
7e314c57 JK |
7951 | /* The die_type call above may have already set the type for this DIE. */ |
7952 | range_type = get_die_type (die, cu); | |
7953 | if (range_type) | |
7954 | return range_type; | |
7955 | ||
e142c38c | 7956 | if (cu->language == language_fortran) |
6e70227d | 7957 | { |
a02abb62 JB |
7958 | /* FORTRAN implies a lower bound of 1, if not given. */ |
7959 | low = 1; | |
7960 | } | |
7961 | ||
dd5e6932 DJ |
7962 | /* FIXME: For variable sized arrays either of these could be |
7963 | a variable rather than a constant value. We'll allow it, | |
7964 | but we don't know how to handle it. */ | |
e142c38c | 7965 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
7966 | if (attr) |
7967 | low = dwarf2_get_attr_constant_value (attr, 0); | |
7968 | ||
e142c38c | 7969 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 | 7970 | if (attr) |
6e70227d | 7971 | { |
e77813c8 | 7972 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
a02abb62 JB |
7973 | { |
7974 | /* GCC encodes arrays with unspecified or dynamic length | |
e77813c8 | 7975 | with a DW_FORM_block1 attribute or a reference attribute. |
a02abb62 JB |
7976 | FIXME: GDB does not yet know how to handle dynamic |
7977 | arrays properly, treat them as arrays with unspecified | |
7978 | length for now. | |
7979 | ||
7980 | FIXME: jimb/2003-09-22: GDB does not really know | |
7981 | how to handle arrays of unspecified length | |
7982 | either; we just represent them as zero-length | |
7983 | arrays. Choose an appropriate upper bound given | |
7984 | the lower bound we've computed above. */ | |
7985 | high = low - 1; | |
7986 | } | |
7987 | else | |
7988 | high = dwarf2_get_attr_constant_value (attr, 1); | |
7989 | } | |
e77813c8 PM |
7990 | else |
7991 | { | |
7992 | attr = dwarf2_attr (die, DW_AT_count, cu); | |
7993 | if (attr) | |
7994 | { | |
7995 | int count = dwarf2_get_attr_constant_value (attr, 1); | |
7996 | high = low + count - 1; | |
7997 | } | |
7998 | } | |
7999 | ||
8000 | /* Dwarf-2 specifications explicitly allows to create subrange types | |
8001 | without specifying a base type. | |
8002 | In that case, the base type must be set to the type of | |
8003 | the lower bound, upper bound or count, in that order, if any of these | |
8004 | three attributes references an object that has a type. | |
8005 | If no base type is found, the Dwarf-2 specifications say that | |
8006 | a signed integer type of size equal to the size of an address should | |
8007 | be used. | |
8008 | For the following C code: `extern char gdb_int [];' | |
8009 | GCC produces an empty range DIE. | |
8010 | FIXME: muller/2010-05-28: Possible references to object for low bound, | |
8011 | high bound or count are not yet handled by this code. | |
8012 | */ | |
8013 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
8014 | { | |
8015 | struct objfile *objfile = cu->objfile; | |
8016 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
8017 | int addr_size = gdbarch_addr_bit (gdbarch) /8; | |
8018 | struct type *int_type = objfile_type (objfile)->builtin_int; | |
8019 | ||
8020 | /* Test "int", "long int", and "long long int" objfile types, | |
8021 | and select the first one having a size above or equal to the | |
8022 | architecture address size. */ | |
8023 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8024 | base_type = int_type; | |
8025 | else | |
8026 | { | |
8027 | int_type = objfile_type (objfile)->builtin_long; | |
8028 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8029 | base_type = int_type; | |
8030 | else | |
8031 | { | |
8032 | int_type = objfile_type (objfile)->builtin_long_long; | |
8033 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) | |
8034 | base_type = int_type; | |
8035 | } | |
8036 | } | |
8037 | } | |
a02abb62 | 8038 | |
6e70227d | 8039 | negative_mask = |
43bbcdc2 PH |
8040 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
8041 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) | |
8042 | low |= negative_mask; | |
8043 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) | |
8044 | high |= negative_mask; | |
8045 | ||
a02abb62 JB |
8046 | range_type = create_range_type (NULL, base_type, low, high); |
8047 | ||
bbb0eef6 JK |
8048 | /* Mark arrays with dynamic length at least as an array of unspecified |
8049 | length. GDB could check the boundary but before it gets implemented at | |
8050 | least allow accessing the array elements. */ | |
8051 | if (attr && attr->form == DW_FORM_block1) | |
8052 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; | |
8053 | ||
39cbfefa DJ |
8054 | name = dwarf2_name (die, cu); |
8055 | if (name) | |
8056 | TYPE_NAME (range_type) = name; | |
6e70227d | 8057 | |
e142c38c | 8058 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
8059 | if (attr) |
8060 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
8061 | ||
7e314c57 JK |
8062 | set_die_type (die, range_type, cu); |
8063 | ||
8064 | /* set_die_type should be already done. */ | |
b4ba55a1 JB |
8065 | set_descriptive_type (range_type, die, cu); |
8066 | ||
7e314c57 | 8067 | return range_type; |
a02abb62 | 8068 | } |
6e70227d | 8069 | |
f792889a | 8070 | static struct type * |
81a17f79 JB |
8071 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
8072 | { | |
8073 | struct type *type; | |
81a17f79 | 8074 | |
81a17f79 JB |
8075 | /* For now, we only support the C meaning of an unspecified type: void. */ |
8076 | ||
0114d602 DJ |
8077 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
8078 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 8079 | |
f792889a | 8080 | return set_die_type (die, type, cu); |
81a17f79 | 8081 | } |
a02abb62 | 8082 | |
51545339 DJ |
8083 | /* Trivial hash function for die_info: the hash value of a DIE |
8084 | is its offset in .debug_info for this objfile. */ | |
8085 | ||
8086 | static hashval_t | |
8087 | die_hash (const void *item) | |
8088 | { | |
8089 | const struct die_info *die = item; | |
9a619af0 | 8090 | |
51545339 DJ |
8091 | return die->offset; |
8092 | } | |
8093 | ||
8094 | /* Trivial comparison function for die_info structures: two DIEs | |
8095 | are equal if they have the same offset. */ | |
8096 | ||
8097 | static int | |
8098 | die_eq (const void *item_lhs, const void *item_rhs) | |
8099 | { | |
8100 | const struct die_info *die_lhs = item_lhs; | |
8101 | const struct die_info *die_rhs = item_rhs; | |
9a619af0 | 8102 | |
51545339 DJ |
8103 | return die_lhs->offset == die_rhs->offset; |
8104 | } | |
8105 | ||
c906108c SS |
8106 | /* Read a whole compilation unit into a linked list of dies. */ |
8107 | ||
f9aca02d | 8108 | static struct die_info * |
93311388 | 8109 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 8110 | { |
93311388 | 8111 | struct die_reader_specs reader_specs; |
98bfdba5 | 8112 | int read_abbrevs = 0; |
1d9ec526 | 8113 | struct cleanup *back_to = NULL; |
98bfdba5 PA |
8114 | struct die_info *die; |
8115 | ||
8116 | if (cu->dwarf2_abbrevs == NULL) | |
8117 | { | |
8118 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
8119 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
8120 | read_abbrevs = 1; | |
8121 | } | |
93311388 | 8122 | |
348e048f | 8123 | gdb_assert (cu->die_hash == NULL); |
51545339 DJ |
8124 | cu->die_hash |
8125 | = htab_create_alloc_ex (cu->header.length / 12, | |
8126 | die_hash, | |
8127 | die_eq, | |
8128 | NULL, | |
8129 | &cu->comp_unit_obstack, | |
8130 | hashtab_obstack_allocate, | |
8131 | dummy_obstack_deallocate); | |
8132 | ||
93311388 DE |
8133 | init_cu_die_reader (&reader_specs, cu); |
8134 | ||
98bfdba5 PA |
8135 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
8136 | ||
8137 | if (read_abbrevs) | |
8138 | do_cleanups (back_to); | |
8139 | ||
8140 | return die; | |
639d11d3 DC |
8141 | } |
8142 | ||
d97bc12b DE |
8143 | /* Main entry point for reading a DIE and all children. |
8144 | Read the DIE and dump it if requested. */ | |
8145 | ||
8146 | static struct die_info * | |
93311388 DE |
8147 | read_die_and_children (const struct die_reader_specs *reader, |
8148 | gdb_byte *info_ptr, | |
d97bc12b DE |
8149 | gdb_byte **new_info_ptr, |
8150 | struct die_info *parent) | |
8151 | { | |
93311388 | 8152 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
d97bc12b DE |
8153 | new_info_ptr, parent); |
8154 | ||
8155 | if (dwarf2_die_debug) | |
8156 | { | |
348e048f DE |
8157 | fprintf_unfiltered (gdb_stdlog, |
8158 | "\nRead die from %s of %s:\n", | |
8159 | reader->buffer == dwarf2_per_objfile->info.buffer | |
8160 | ? ".debug_info" | |
8161 | : reader->buffer == dwarf2_per_objfile->types.buffer | |
8162 | ? ".debug_types" | |
8163 | : "unknown section", | |
8164 | reader->abfd->filename); | |
d97bc12b DE |
8165 | dump_die (result, dwarf2_die_debug); |
8166 | } | |
8167 | ||
8168 | return result; | |
8169 | } | |
8170 | ||
639d11d3 DC |
8171 | /* Read a single die and all its descendents. Set the die's sibling |
8172 | field to NULL; set other fields in the die correctly, and set all | |
8173 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
8174 | location of the info_ptr after reading all of those dies. PARENT | |
8175 | is the parent of the die in question. */ | |
8176 | ||
8177 | static struct die_info * | |
93311388 DE |
8178 | read_die_and_children_1 (const struct die_reader_specs *reader, |
8179 | gdb_byte *info_ptr, | |
d97bc12b DE |
8180 | gdb_byte **new_info_ptr, |
8181 | struct die_info *parent) | |
639d11d3 DC |
8182 | { |
8183 | struct die_info *die; | |
fe1b8b76 | 8184 | gdb_byte *cur_ptr; |
639d11d3 DC |
8185 | int has_children; |
8186 | ||
93311388 | 8187 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
1d325ec1 DJ |
8188 | if (die == NULL) |
8189 | { | |
8190 | *new_info_ptr = cur_ptr; | |
8191 | return NULL; | |
8192 | } | |
93311388 | 8193 | store_in_ref_table (die, reader->cu); |
639d11d3 DC |
8194 | |
8195 | if (has_children) | |
348e048f | 8196 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
639d11d3 DC |
8197 | else |
8198 | { | |
8199 | die->child = NULL; | |
8200 | *new_info_ptr = cur_ptr; | |
8201 | } | |
8202 | ||
8203 | die->sibling = NULL; | |
8204 | die->parent = parent; | |
8205 | return die; | |
8206 | } | |
8207 | ||
8208 | /* Read a die, all of its descendents, and all of its siblings; set | |
8209 | all of the fields of all of the dies correctly. Arguments are as | |
8210 | in read_die_and_children. */ | |
8211 | ||
8212 | static struct die_info * | |
93311388 DE |
8213 | read_die_and_siblings (const struct die_reader_specs *reader, |
8214 | gdb_byte *info_ptr, | |
fe1b8b76 | 8215 | gdb_byte **new_info_ptr, |
639d11d3 DC |
8216 | struct die_info *parent) |
8217 | { | |
8218 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 8219 | gdb_byte *cur_ptr; |
639d11d3 | 8220 | |
c906108c | 8221 | cur_ptr = info_ptr; |
639d11d3 DC |
8222 | first_die = last_sibling = NULL; |
8223 | ||
8224 | while (1) | |
c906108c | 8225 | { |
639d11d3 | 8226 | struct die_info *die |
93311388 | 8227 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
639d11d3 | 8228 | |
1d325ec1 | 8229 | if (die == NULL) |
c906108c | 8230 | { |
639d11d3 DC |
8231 | *new_info_ptr = cur_ptr; |
8232 | return first_die; | |
c906108c | 8233 | } |
1d325ec1 DJ |
8234 | |
8235 | if (!first_die) | |
8236 | first_die = die; | |
c906108c | 8237 | else |
1d325ec1 DJ |
8238 | last_sibling->sibling = die; |
8239 | ||
8240 | last_sibling = die; | |
c906108c | 8241 | } |
c906108c SS |
8242 | } |
8243 | ||
93311388 DE |
8244 | /* Read the die from the .debug_info section buffer. Set DIEP to |
8245 | point to a newly allocated die with its information, except for its | |
8246 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
8247 | whether the die has children or not. */ | |
8248 | ||
8249 | static gdb_byte * | |
8250 | read_full_die (const struct die_reader_specs *reader, | |
8251 | struct die_info **diep, gdb_byte *info_ptr, | |
8252 | int *has_children) | |
8253 | { | |
8254 | unsigned int abbrev_number, bytes_read, i, offset; | |
8255 | struct abbrev_info *abbrev; | |
8256 | struct die_info *die; | |
8257 | struct dwarf2_cu *cu = reader->cu; | |
8258 | bfd *abfd = reader->abfd; | |
8259 | ||
8260 | offset = info_ptr - reader->buffer; | |
8261 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
8262 | info_ptr += bytes_read; | |
8263 | if (!abbrev_number) | |
8264 | { | |
8265 | *diep = NULL; | |
8266 | *has_children = 0; | |
8267 | return info_ptr; | |
8268 | } | |
8269 | ||
8270 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
8271 | if (!abbrev) | |
348e048f DE |
8272 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
8273 | abbrev_number, | |
8274 | bfd_get_filename (abfd)); | |
8275 | ||
93311388 DE |
8276 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
8277 | die->offset = offset; | |
8278 | die->tag = abbrev->tag; | |
8279 | die->abbrev = abbrev_number; | |
8280 | ||
8281 | die->num_attrs = abbrev->num_attrs; | |
8282 | ||
8283 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8284 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
8285 | abfd, info_ptr, cu); | |
8286 | ||
8287 | *diep = die; | |
8288 | *has_children = abbrev->has_children; | |
8289 | return info_ptr; | |
8290 | } | |
8291 | ||
c906108c SS |
8292 | /* In DWARF version 2, the description of the debugging information is |
8293 | stored in a separate .debug_abbrev section. Before we read any | |
8294 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
8295 | in a hash table. This function also sets flags in CU describing |
8296 | the data found in the abbrev table. */ | |
c906108c SS |
8297 | |
8298 | static void | |
e7c27a73 | 8299 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 8300 | { |
e7c27a73 | 8301 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 8302 | gdb_byte *abbrev_ptr; |
c906108c SS |
8303 | struct abbrev_info *cur_abbrev; |
8304 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
8305 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
8306 | struct attr_abbrev *cur_attrs; |
8307 | unsigned int allocated_attrs; | |
c906108c | 8308 | |
57349743 | 8309 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
8310 | obstack_init (&cu->abbrev_obstack); |
8311 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
8312 | (ABBREV_HASH_SIZE | |
8313 | * sizeof (struct abbrev_info *))); | |
8314 | memset (cu->dwarf2_abbrevs, 0, | |
8315 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 8316 | |
be391dca TT |
8317 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
8318 | &dwarf2_per_objfile->abbrev); | |
dce234bc | 8319 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
8320 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8321 | abbrev_ptr += bytes_read; | |
8322 | ||
f3dd6933 DJ |
8323 | allocated_attrs = ATTR_ALLOC_CHUNK; |
8324 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
6e70227d | 8325 | |
c906108c SS |
8326 | /* loop until we reach an abbrev number of 0 */ |
8327 | while (abbrev_number) | |
8328 | { | |
f3dd6933 | 8329 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
8330 | |
8331 | /* read in abbrev header */ | |
8332 | cur_abbrev->number = abbrev_number; | |
8333 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8334 | abbrev_ptr += bytes_read; | |
8335 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
8336 | abbrev_ptr += 1; | |
8337 | ||
72bf9492 DJ |
8338 | if (cur_abbrev->tag == DW_TAG_namespace) |
8339 | cu->has_namespace_info = 1; | |
8340 | ||
c906108c SS |
8341 | /* now read in declarations */ |
8342 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8343 | abbrev_ptr += bytes_read; | |
8344 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8345 | abbrev_ptr += bytes_read; | |
8346 | while (abbrev_name) | |
8347 | { | |
f3dd6933 | 8348 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 8349 | { |
f3dd6933 DJ |
8350 | allocated_attrs += ATTR_ALLOC_CHUNK; |
8351 | cur_attrs | |
8352 | = xrealloc (cur_attrs, (allocated_attrs | |
8353 | * sizeof (struct attr_abbrev))); | |
c906108c | 8354 | } |
ae038cb0 DJ |
8355 | |
8356 | /* Record whether this compilation unit might have | |
8357 | inter-compilation-unit references. If we don't know what form | |
8358 | this attribute will have, then it might potentially be a | |
8359 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
8360 | references. */ | |
8361 | ||
8362 | if (abbrev_form == DW_FORM_ref_addr | |
8363 | || abbrev_form == DW_FORM_indirect) | |
8364 | cu->has_form_ref_addr = 1; | |
8365 | ||
f3dd6933 DJ |
8366 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
8367 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
8368 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
8369 | abbrev_ptr += bytes_read; | |
8370 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8371 | abbrev_ptr += bytes_read; | |
8372 | } | |
8373 | ||
f3dd6933 DJ |
8374 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
8375 | (cur_abbrev->num_attrs | |
8376 | * sizeof (struct attr_abbrev))); | |
8377 | memcpy (cur_abbrev->attrs, cur_attrs, | |
8378 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
8379 | ||
c906108c | 8380 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
8381 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
8382 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
8383 | |
8384 | /* Get next abbreviation. | |
8385 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
8386 | always properly terminated with an abbrev number of 0. |
8387 | Exit loop if we encounter an abbreviation which we have | |
8388 | already read (which means we are about to read the abbreviations | |
8389 | for the next compile unit) or if the end of the abbreviation | |
8390 | table is reached. */ | |
dce234bc PP |
8391 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
8392 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
8393 | break; |
8394 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
8395 | abbrev_ptr += bytes_read; | |
e7c27a73 | 8396 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
8397 | break; |
8398 | } | |
f3dd6933 DJ |
8399 | |
8400 | xfree (cur_attrs); | |
c906108c SS |
8401 | } |
8402 | ||
f3dd6933 | 8403 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 8404 | |
c906108c | 8405 | static void |
f3dd6933 | 8406 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 8407 | { |
f3dd6933 | 8408 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 8409 | |
f3dd6933 DJ |
8410 | obstack_free (&cu->abbrev_obstack, NULL); |
8411 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
8412 | } |
8413 | ||
8414 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
8415 | ||
8416 | static struct abbrev_info * | |
e7c27a73 | 8417 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
8418 | { |
8419 | unsigned int hash_number; | |
8420 | struct abbrev_info *abbrev; | |
8421 | ||
8422 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 8423 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
8424 | |
8425 | while (abbrev) | |
8426 | { | |
8427 | if (abbrev->number == number) | |
8428 | return abbrev; | |
8429 | else | |
8430 | abbrev = abbrev->next; | |
8431 | } | |
8432 | return NULL; | |
8433 | } | |
8434 | ||
72bf9492 DJ |
8435 | /* Returns nonzero if TAG represents a type that we might generate a partial |
8436 | symbol for. */ | |
8437 | ||
8438 | static int | |
8439 | is_type_tag_for_partial (int tag) | |
8440 | { | |
8441 | switch (tag) | |
8442 | { | |
8443 | #if 0 | |
8444 | /* Some types that would be reasonable to generate partial symbols for, | |
8445 | that we don't at present. */ | |
8446 | case DW_TAG_array_type: | |
8447 | case DW_TAG_file_type: | |
8448 | case DW_TAG_ptr_to_member_type: | |
8449 | case DW_TAG_set_type: | |
8450 | case DW_TAG_string_type: | |
8451 | case DW_TAG_subroutine_type: | |
8452 | #endif | |
8453 | case DW_TAG_base_type: | |
8454 | case DW_TAG_class_type: | |
680b30c7 | 8455 | case DW_TAG_interface_type: |
72bf9492 DJ |
8456 | case DW_TAG_enumeration_type: |
8457 | case DW_TAG_structure_type: | |
8458 | case DW_TAG_subrange_type: | |
8459 | case DW_TAG_typedef: | |
8460 | case DW_TAG_union_type: | |
8461 | return 1; | |
8462 | default: | |
8463 | return 0; | |
8464 | } | |
8465 | } | |
8466 | ||
8467 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
8468 | ||
8469 | static struct partial_die_info * | |
93311388 DE |
8470 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
8471 | int building_psymtab, struct dwarf2_cu *cu) | |
72bf9492 DJ |
8472 | { |
8473 | struct partial_die_info *part_die; | |
8474 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
8475 | struct abbrev_info *abbrev; | |
8476 | unsigned int bytes_read; | |
5afb4e99 | 8477 | unsigned int load_all = 0; |
72bf9492 DJ |
8478 | |
8479 | int nesting_level = 1; | |
8480 | ||
8481 | parent_die = NULL; | |
8482 | last_die = NULL; | |
8483 | ||
5afb4e99 DJ |
8484 | if (cu->per_cu && cu->per_cu->load_all_dies) |
8485 | load_all = 1; | |
8486 | ||
72bf9492 DJ |
8487 | cu->partial_dies |
8488 | = htab_create_alloc_ex (cu->header.length / 12, | |
8489 | partial_die_hash, | |
8490 | partial_die_eq, | |
8491 | NULL, | |
8492 | &cu->comp_unit_obstack, | |
8493 | hashtab_obstack_allocate, | |
8494 | dummy_obstack_deallocate); | |
8495 | ||
8496 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8497 | sizeof (struct partial_die_info)); | |
8498 | ||
8499 | while (1) | |
8500 | { | |
8501 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
8502 | ||
8503 | /* A NULL abbrev means the end of a series of children. */ | |
8504 | if (abbrev == NULL) | |
8505 | { | |
8506 | if (--nesting_level == 0) | |
8507 | { | |
8508 | /* PART_DIE was probably the last thing allocated on the | |
8509 | comp_unit_obstack, so we could call obstack_free | |
8510 | here. We don't do that because the waste is small, | |
8511 | and will be cleaned up when we're done with this | |
8512 | compilation unit. This way, we're also more robust | |
8513 | against other users of the comp_unit_obstack. */ | |
8514 | return first_die; | |
8515 | } | |
8516 | info_ptr += bytes_read; | |
8517 | last_die = parent_die; | |
8518 | parent_die = parent_die->die_parent; | |
8519 | continue; | |
8520 | } | |
8521 | ||
98bfdba5 PA |
8522 | /* Check for template arguments. We never save these; if |
8523 | they're seen, we just mark the parent, and go on our way. */ | |
8524 | if (parent_die != NULL | |
8525 | && cu->language == language_cplus | |
8526 | && (abbrev->tag == DW_TAG_template_type_param | |
8527 | || abbrev->tag == DW_TAG_template_value_param)) | |
8528 | { | |
8529 | parent_die->has_template_arguments = 1; | |
8530 | ||
8531 | if (!load_all) | |
8532 | { | |
8533 | /* We don't need a partial DIE for the template argument. */ | |
8534 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, | |
8535 | cu); | |
8536 | continue; | |
8537 | } | |
8538 | } | |
8539 | ||
8540 | /* We only recurse into subprograms looking for template arguments. | |
8541 | Skip their other children. */ | |
8542 | if (!load_all | |
8543 | && cu->language == language_cplus | |
8544 | && parent_die != NULL | |
8545 | && parent_die->tag == DW_TAG_subprogram) | |
8546 | { | |
8547 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); | |
8548 | continue; | |
8549 | } | |
8550 | ||
5afb4e99 DJ |
8551 | /* Check whether this DIE is interesting enough to save. Normally |
8552 | we would not be interested in members here, but there may be | |
8553 | later variables referencing them via DW_AT_specification (for | |
8554 | static members). */ | |
8555 | if (!load_all | |
8556 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
8557 | && abbrev->tag != DW_TAG_enumerator |
8558 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 8559 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 8560 | && abbrev->tag != DW_TAG_variable |
5afb4e99 | 8561 | && abbrev->tag != DW_TAG_namespace |
f55ee35c | 8562 | && abbrev->tag != DW_TAG_module |
5afb4e99 | 8563 | && abbrev->tag != DW_TAG_member) |
72bf9492 DJ |
8564 | { |
8565 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8566 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
72bf9492 DJ |
8567 | continue; |
8568 | } | |
8569 | ||
93311388 DE |
8570 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
8571 | buffer, info_ptr, cu); | |
72bf9492 DJ |
8572 | |
8573 | /* This two-pass algorithm for processing partial symbols has a | |
8574 | high cost in cache pressure. Thus, handle some simple cases | |
8575 | here which cover the majority of C partial symbols. DIEs | |
8576 | which neither have specification tags in them, nor could have | |
8577 | specification tags elsewhere pointing at them, can simply be | |
8578 | processed and discarded. | |
8579 | ||
8580 | This segment is also optional; scan_partial_symbols and | |
8581 | add_partial_symbol will handle these DIEs if we chain | |
8582 | them in normally. When compilers which do not emit large | |
8583 | quantities of duplicate debug information are more common, | |
8584 | this code can probably be removed. */ | |
8585 | ||
8586 | /* Any complete simple types at the top level (pretty much all | |
8587 | of them, for a language without namespaces), can be processed | |
8588 | directly. */ | |
8589 | if (parent_die == NULL | |
8590 | && part_die->has_specification == 0 | |
8591 | && part_die->is_declaration == 0 | |
8592 | && (part_die->tag == DW_TAG_typedef | |
8593 | || part_die->tag == DW_TAG_base_type | |
8594 | || part_die->tag == DW_TAG_subrange_type)) | |
8595 | { | |
8596 | if (building_psymtab && part_die->name != NULL) | |
04a679b8 | 8597 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 DJ |
8598 | VAR_DOMAIN, LOC_TYPEDEF, |
8599 | &cu->objfile->static_psymbols, | |
8600 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
93311388 | 8601 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8602 | continue; |
8603 | } | |
8604 | ||
8605 | /* If we're at the second level, and we're an enumerator, and | |
8606 | our parent has no specification (meaning possibly lives in a | |
8607 | namespace elsewhere), then we can add the partial symbol now | |
8608 | instead of queueing it. */ | |
8609 | if (part_die->tag == DW_TAG_enumerator | |
8610 | && parent_die != NULL | |
8611 | && parent_die->die_parent == NULL | |
8612 | && parent_die->tag == DW_TAG_enumeration_type | |
8613 | && parent_die->has_specification == 0) | |
8614 | { | |
8615 | if (part_die->name == NULL) | |
e2e0b3e5 | 8616 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 | 8617 | else if (building_psymtab) |
04a679b8 | 8618 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
72bf9492 | 8619 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
8620 | (cu->language == language_cplus |
8621 | || cu->language == language_java) | |
72bf9492 DJ |
8622 | ? &cu->objfile->global_psymbols |
8623 | : &cu->objfile->static_psymbols, | |
8624 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
8625 | ||
93311388 | 8626 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8627 | continue; |
8628 | } | |
8629 | ||
8630 | /* We'll save this DIE so link it in. */ | |
8631 | part_die->die_parent = parent_die; | |
8632 | part_die->die_sibling = NULL; | |
8633 | part_die->die_child = NULL; | |
8634 | ||
8635 | if (last_die && last_die == parent_die) | |
8636 | last_die->die_child = part_die; | |
8637 | else if (last_die) | |
8638 | last_die->die_sibling = part_die; | |
8639 | ||
8640 | last_die = part_die; | |
8641 | ||
8642 | if (first_die == NULL) | |
8643 | first_die = part_die; | |
8644 | ||
8645 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
8646 | find interesting need to be in the hash table, because we | |
8647 | also have the parent/sibling/child chains; only those that we | |
8648 | might refer to by offset later during partial symbol reading. | |
8649 | ||
8650 | For now this means things that might have be the target of a | |
8651 | DW_AT_specification, DW_AT_abstract_origin, or | |
8652 | DW_AT_extension. DW_AT_extension will refer only to | |
8653 | namespaces; DW_AT_abstract_origin refers to functions (and | |
8654 | many things under the function DIE, but we do not recurse | |
8655 | into function DIEs during partial symbol reading) and | |
8656 | possibly variables as well; DW_AT_specification refers to | |
8657 | declarations. Declarations ought to have the DW_AT_declaration | |
8658 | flag. It happens that GCC forgets to put it in sometimes, but | |
8659 | only for functions, not for types. | |
8660 | ||
8661 | Adding more things than necessary to the hash table is harmless | |
8662 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
8663 | wasted time in find_partial_die, when we reread the compilation |
8664 | unit with load_all_dies set. */ | |
72bf9492 | 8665 | |
5afb4e99 DJ |
8666 | if (load_all |
8667 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
8668 | || abbrev->tag == DW_TAG_variable |
8669 | || abbrev->tag == DW_TAG_namespace | |
8670 | || part_die->is_declaration) | |
8671 | { | |
8672 | void **slot; | |
8673 | ||
8674 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
8675 | part_die->offset, INSERT); | |
8676 | *slot = part_die; | |
8677 | } | |
8678 | ||
8679 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
8680 | sizeof (struct partial_die_info)); | |
8681 | ||
8682 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 8683 | we have no reason to follow the children of structures; for other |
98bfdba5 PA |
8684 | languages we have to, so that we can get at method physnames |
8685 | to infer fully qualified class names, for DW_AT_specification, | |
8686 | and for C++ template arguments. For C++, we also look one level | |
8687 | inside functions to find template arguments (if the name of the | |
8688 | function does not already contain the template arguments). | |
bc30ff58 JB |
8689 | |
8690 | For Ada, we need to scan the children of subprograms and lexical | |
8691 | blocks as well because Ada allows the definition of nested | |
8692 | entities that could be interesting for the debugger, such as | |
8693 | nested subprograms for instance. */ | |
72bf9492 | 8694 | if (last_die->has_children |
5afb4e99 DJ |
8695 | && (load_all |
8696 | || last_die->tag == DW_TAG_namespace | |
f55ee35c | 8697 | || last_die->tag == DW_TAG_module |
72bf9492 | 8698 | || last_die->tag == DW_TAG_enumeration_type |
98bfdba5 PA |
8699 | || (cu->language == language_cplus |
8700 | && last_die->tag == DW_TAG_subprogram | |
8701 | && (last_die->name == NULL | |
8702 | || strchr (last_die->name, '<') == NULL)) | |
72bf9492 DJ |
8703 | || (cu->language != language_c |
8704 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 8705 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 8706 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
8707 | || last_die->tag == DW_TAG_union_type)) |
8708 | || (cu->language == language_ada | |
8709 | && (last_die->tag == DW_TAG_subprogram | |
8710 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
8711 | { |
8712 | nesting_level++; | |
8713 | parent_die = last_die; | |
8714 | continue; | |
8715 | } | |
8716 | ||
8717 | /* Otherwise we skip to the next sibling, if any. */ | |
93311388 | 8718 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
72bf9492 DJ |
8719 | |
8720 | /* Back to the top, do it again. */ | |
8721 | } | |
8722 | } | |
8723 | ||
c906108c SS |
8724 | /* Read a minimal amount of information into the minimal die structure. */ |
8725 | ||
fe1b8b76 | 8726 | static gdb_byte * |
72bf9492 DJ |
8727 | read_partial_die (struct partial_die_info *part_die, |
8728 | struct abbrev_info *abbrev, | |
8729 | unsigned int abbrev_len, bfd *abfd, | |
93311388 DE |
8730 | gdb_byte *buffer, gdb_byte *info_ptr, |
8731 | struct dwarf2_cu *cu) | |
c906108c | 8732 | { |
fa238c03 | 8733 | unsigned int i; |
c906108c | 8734 | struct attribute attr; |
c5aa993b | 8735 | int has_low_pc_attr = 0; |
c906108c SS |
8736 | int has_high_pc_attr = 0; |
8737 | ||
72bf9492 | 8738 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 8739 | |
93311388 | 8740 | part_die->offset = info_ptr - buffer; |
72bf9492 DJ |
8741 | |
8742 | info_ptr += abbrev_len; | |
8743 | ||
8744 | if (abbrev == NULL) | |
8745 | return info_ptr; | |
8746 | ||
c906108c SS |
8747 | part_die->tag = abbrev->tag; |
8748 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
8749 | |
8750 | for (i = 0; i < abbrev->num_attrs; ++i) | |
8751 | { | |
e7c27a73 | 8752 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
8753 | |
8754 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 8755 | partial symbol table. */ |
c906108c SS |
8756 | switch (attr.name) |
8757 | { | |
8758 | case DW_AT_name: | |
71c25dea TT |
8759 | switch (part_die->tag) |
8760 | { | |
8761 | case DW_TAG_compile_unit: | |
348e048f | 8762 | case DW_TAG_type_unit: |
71c25dea TT |
8763 | /* Compilation units have a DW_AT_name that is a filename, not |
8764 | a source language identifier. */ | |
8765 | case DW_TAG_enumeration_type: | |
8766 | case DW_TAG_enumerator: | |
8767 | /* These tags always have simple identifiers already; no need | |
8768 | to canonicalize them. */ | |
8769 | part_die->name = DW_STRING (&attr); | |
8770 | break; | |
8771 | default: | |
8772 | part_die->name | |
8773 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
95519e0e | 8774 | &cu->objfile->objfile_obstack); |
71c25dea TT |
8775 | break; |
8776 | } | |
c906108c | 8777 | break; |
31ef98ae | 8778 | case DW_AT_linkage_name: |
c906108c | 8779 | case DW_AT_MIPS_linkage_name: |
31ef98ae TT |
8780 | /* Note that both forms of linkage name might appear. We |
8781 | assume they will be the same, and we only store the last | |
8782 | one we see. */ | |
94af9270 KS |
8783 | if (cu->language == language_ada) |
8784 | part_die->name = DW_STRING (&attr); | |
c906108c SS |
8785 | break; |
8786 | case DW_AT_low_pc: | |
8787 | has_low_pc_attr = 1; | |
8788 | part_die->lowpc = DW_ADDR (&attr); | |
8789 | break; | |
8790 | case DW_AT_high_pc: | |
8791 | has_high_pc_attr = 1; | |
8792 | part_die->highpc = DW_ADDR (&attr); | |
8793 | break; | |
8794 | case DW_AT_location: | |
8e19ed76 PS |
8795 | /* Support the .debug_loc offsets */ |
8796 | if (attr_form_is_block (&attr)) | |
8797 | { | |
8798 | part_die->locdesc = DW_BLOCK (&attr); | |
8799 | } | |
3690dd37 | 8800 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 8801 | { |
4d3c2250 | 8802 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
8803 | } |
8804 | else | |
8805 | { | |
4d3c2250 KB |
8806 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
8807 | "partial symbol information"); | |
8e19ed76 | 8808 | } |
c906108c | 8809 | break; |
c906108c SS |
8810 | case DW_AT_external: |
8811 | part_die->is_external = DW_UNSND (&attr); | |
8812 | break; | |
8813 | case DW_AT_declaration: | |
8814 | part_die->is_declaration = DW_UNSND (&attr); | |
8815 | break; | |
8816 | case DW_AT_type: | |
8817 | part_die->has_type = 1; | |
8818 | break; | |
8819 | case DW_AT_abstract_origin: | |
8820 | case DW_AT_specification: | |
72bf9492 DJ |
8821 | case DW_AT_extension: |
8822 | part_die->has_specification = 1; | |
c764a876 | 8823 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
8824 | break; |
8825 | case DW_AT_sibling: | |
8826 | /* Ignore absolute siblings, they might point outside of | |
8827 | the current compile unit. */ | |
8828 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 8829 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 8830 | else |
93311388 | 8831 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
c906108c | 8832 | break; |
fa4028e9 JB |
8833 | case DW_AT_byte_size: |
8834 | part_die->has_byte_size = 1; | |
8835 | break; | |
68511cec CES |
8836 | case DW_AT_calling_convention: |
8837 | /* DWARF doesn't provide a way to identify a program's source-level | |
8838 | entry point. DW_AT_calling_convention attributes are only meant | |
8839 | to describe functions' calling conventions. | |
8840 | ||
8841 | However, because it's a necessary piece of information in | |
8842 | Fortran, and because DW_CC_program is the only piece of debugging | |
8843 | information whose definition refers to a 'main program' at all, | |
8844 | several compilers have begun marking Fortran main programs with | |
8845 | DW_CC_program --- even when those functions use the standard | |
8846 | calling conventions. | |
8847 | ||
8848 | So until DWARF specifies a way to provide this information and | |
8849 | compilers pick up the new representation, we'll support this | |
8850 | practice. */ | |
8851 | if (DW_UNSND (&attr) == DW_CC_program | |
8852 | && cu->language == language_fortran) | |
8853 | set_main_name (part_die->name); | |
8854 | break; | |
c906108c SS |
8855 | default: |
8856 | break; | |
8857 | } | |
8858 | } | |
8859 | ||
c906108c SS |
8860 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
8861 | eliminate duplicate copies of functions and vtables and such. | |
8862 | The linker will arbitrarily choose one and discard the others. | |
8863 | The AT_*_pc values for such functions refer to local labels in | |
8864 | these sections. If the section from that file was discarded, the | |
8865 | labels are not in the output, so the relocs get a value of 0. | |
8866 | If this is a discarded function, mark the pc bounds as invalid, | |
8867 | so that GDB will ignore it. */ | |
8868 | if (has_low_pc_attr && has_high_pc_attr | |
8869 | && part_die->lowpc < part_die->highpc | |
8870 | && (part_die->lowpc != 0 | |
72dca2f5 | 8871 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 8872 | part_die->has_pc_info = 1; |
85cbf3d3 | 8873 | |
c906108c SS |
8874 | return info_ptr; |
8875 | } | |
8876 | ||
72bf9492 DJ |
8877 | /* Find a cached partial DIE at OFFSET in CU. */ |
8878 | ||
8879 | static struct partial_die_info * | |
c764a876 | 8880 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
8881 | { |
8882 | struct partial_die_info *lookup_die = NULL; | |
8883 | struct partial_die_info part_die; | |
8884 | ||
8885 | part_die.offset = offset; | |
8886 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
8887 | ||
72bf9492 DJ |
8888 | return lookup_die; |
8889 | } | |
8890 | ||
348e048f DE |
8891 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
8892 | except in the case of .debug_types DIEs which do not reference | |
8893 | outside their CU (they do however referencing other types via | |
8894 | DW_FORM_sig8). */ | |
72bf9492 DJ |
8895 | |
8896 | static struct partial_die_info * | |
c764a876 | 8897 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 8898 | { |
5afb4e99 DJ |
8899 | struct dwarf2_per_cu_data *per_cu = NULL; |
8900 | struct partial_die_info *pd = NULL; | |
72bf9492 | 8901 | |
348e048f DE |
8902 | if (cu->per_cu->from_debug_types) |
8903 | { | |
8904 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8905 | if (pd != NULL) | |
8906 | return pd; | |
8907 | goto not_found; | |
8908 | } | |
8909 | ||
45452591 | 8910 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
8911 | { |
8912 | pd = find_partial_die_in_comp_unit (offset, cu); | |
8913 | if (pd != NULL) | |
8914 | return pd; | |
8915 | } | |
72bf9492 | 8916 | |
ae038cb0 DJ |
8917 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
8918 | ||
98bfdba5 PA |
8919 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
8920 | load_partial_comp_unit (per_cu, cu->objfile); | |
ae038cb0 DJ |
8921 | |
8922 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
8923 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
8924 | ||
8925 | if (pd == NULL && per_cu->load_all_dies == 0) | |
8926 | { | |
8927 | struct cleanup *back_to; | |
8928 | struct partial_die_info comp_unit_die; | |
8929 | struct abbrev_info *abbrev; | |
8930 | unsigned int bytes_read; | |
8931 | char *info_ptr; | |
8932 | ||
8933 | per_cu->load_all_dies = 1; | |
8934 | ||
8935 | /* Re-read the DIEs. */ | |
8936 | back_to = make_cleanup (null_cleanup, 0); | |
8937 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
8938 | { | |
8939 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
53d72f98 | 8940 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
5afb4e99 | 8941 | } |
dce234bc | 8942 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
8943 | + per_cu->cu->header.offset |
8944 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
8945 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
8946 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
93311388 DE |
8947 | per_cu->cu->objfile->obfd, |
8948 | dwarf2_per_objfile->info.buffer, info_ptr, | |
5afb4e99 DJ |
8949 | per_cu->cu); |
8950 | if (comp_unit_die.has_children) | |
93311388 DE |
8951 | load_partial_dies (per_cu->cu->objfile->obfd, |
8952 | dwarf2_per_objfile->info.buffer, info_ptr, | |
8953 | 0, per_cu->cu); | |
5afb4e99 DJ |
8954 | do_cleanups (back_to); |
8955 | ||
8956 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
8957 | } | |
8958 | ||
348e048f DE |
8959 | not_found: |
8960 | ||
5afb4e99 DJ |
8961 | if (pd == NULL) |
8962 | internal_error (__FILE__, __LINE__, | |
c764a876 | 8963 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
8964 | offset, bfd_get_filename (cu->objfile->obfd)); |
8965 | return pd; | |
72bf9492 DJ |
8966 | } |
8967 | ||
8968 | /* Adjust PART_DIE before generating a symbol for it. This function | |
8969 | may set the is_external flag or change the DIE's name. */ | |
8970 | ||
8971 | static void | |
8972 | fixup_partial_die (struct partial_die_info *part_die, | |
8973 | struct dwarf2_cu *cu) | |
8974 | { | |
8975 | /* If we found a reference attribute and the DIE has no name, try | |
8976 | to find a name in the referred to DIE. */ | |
8977 | ||
8978 | if (part_die->name == NULL && part_die->has_specification) | |
8979 | { | |
8980 | struct partial_die_info *spec_die; | |
72bf9492 | 8981 | |
10b3939b | 8982 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 8983 | |
10b3939b | 8984 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
8985 | |
8986 | if (spec_die->name) | |
8987 | { | |
8988 | part_die->name = spec_die->name; | |
8989 | ||
8990 | /* Copy DW_AT_external attribute if it is set. */ | |
8991 | if (spec_die->is_external) | |
8992 | part_die->is_external = spec_die->is_external; | |
8993 | } | |
8994 | } | |
8995 | ||
8996 | /* Set default names for some unnamed DIEs. */ | |
8997 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
8998 | || part_die->tag == DW_TAG_class_type)) | |
8999 | part_die->name = "(anonymous class)"; | |
9000 | ||
9001 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
9002 | part_die->name = "(anonymous namespace)"; | |
9003 | ||
9004 | if (part_die->tag == DW_TAG_structure_type | |
9005 | || part_die->tag == DW_TAG_class_type | |
9006 | || part_die->tag == DW_TAG_union_type) | |
9007 | guess_structure_name (part_die, cu); | |
9008 | } | |
9009 | ||
a8329558 | 9010 | /* Read an attribute value described by an attribute form. */ |
c906108c | 9011 | |
fe1b8b76 | 9012 | static gdb_byte * |
a8329558 | 9013 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 9014 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 9015 | struct dwarf2_cu *cu) |
c906108c | 9016 | { |
e7c27a73 | 9017 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9018 | unsigned int bytes_read; |
9019 | struct dwarf_block *blk; | |
9020 | ||
a8329558 KW |
9021 | attr->form = form; |
9022 | switch (form) | |
c906108c | 9023 | { |
c906108c | 9024 | case DW_FORM_ref_addr: |
ae411497 TT |
9025 | if (cu->header.version == 2) |
9026 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); | |
9027 | else | |
9028 | DW_ADDR (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9029 | info_ptr += bytes_read; | |
9030 | break; | |
9031 | case DW_FORM_addr: | |
e7c27a73 | 9032 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 9033 | info_ptr += bytes_read; |
c906108c SS |
9034 | break; |
9035 | case DW_FORM_block2: | |
7b5a2f43 | 9036 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9037 | blk->size = read_2_bytes (abfd, info_ptr); |
9038 | info_ptr += 2; | |
9039 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9040 | info_ptr += blk->size; | |
9041 | DW_BLOCK (attr) = blk; | |
9042 | break; | |
9043 | case DW_FORM_block4: | |
7b5a2f43 | 9044 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9045 | blk->size = read_4_bytes (abfd, info_ptr); |
9046 | info_ptr += 4; | |
9047 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9048 | info_ptr += blk->size; | |
9049 | DW_BLOCK (attr) = blk; | |
9050 | break; | |
9051 | case DW_FORM_data2: | |
9052 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
9053 | info_ptr += 2; | |
9054 | break; | |
9055 | case DW_FORM_data4: | |
9056 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
9057 | info_ptr += 4; | |
9058 | break; | |
9059 | case DW_FORM_data8: | |
9060 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
9061 | info_ptr += 8; | |
9062 | break; | |
2dc7f7b3 TT |
9063 | case DW_FORM_sec_offset: |
9064 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); | |
9065 | info_ptr += bytes_read; | |
9066 | break; | |
c906108c | 9067 | case DW_FORM_string: |
9b1c24c8 | 9068 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
8285870a | 9069 | DW_STRING_IS_CANONICAL (attr) = 0; |
c906108c SS |
9070 | info_ptr += bytes_read; |
9071 | break; | |
4bdf3d34 JJ |
9072 | case DW_FORM_strp: |
9073 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
9074 | &bytes_read); | |
8285870a | 9075 | DW_STRING_IS_CANONICAL (attr) = 0; |
4bdf3d34 JJ |
9076 | info_ptr += bytes_read; |
9077 | break; | |
2dc7f7b3 | 9078 | case DW_FORM_exprloc: |
c906108c | 9079 | case DW_FORM_block: |
7b5a2f43 | 9080 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9081 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9082 | info_ptr += bytes_read; | |
9083 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9084 | info_ptr += blk->size; | |
9085 | DW_BLOCK (attr) = blk; | |
9086 | break; | |
9087 | case DW_FORM_block1: | |
7b5a2f43 | 9088 | blk = dwarf_alloc_block (cu); |
c906108c SS |
9089 | blk->size = read_1_byte (abfd, info_ptr); |
9090 | info_ptr += 1; | |
9091 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
9092 | info_ptr += blk->size; | |
9093 | DW_BLOCK (attr) = blk; | |
9094 | break; | |
9095 | case DW_FORM_data1: | |
9096 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9097 | info_ptr += 1; | |
9098 | break; | |
9099 | case DW_FORM_flag: | |
9100 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
9101 | info_ptr += 1; | |
9102 | break; | |
2dc7f7b3 TT |
9103 | case DW_FORM_flag_present: |
9104 | DW_UNSND (attr) = 1; | |
9105 | break; | |
c906108c SS |
9106 | case DW_FORM_sdata: |
9107 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
9108 | info_ptr += bytes_read; | |
9109 | break; | |
9110 | case DW_FORM_udata: | |
9111 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
9112 | info_ptr += bytes_read; | |
9113 | break; | |
9114 | case DW_FORM_ref1: | |
10b3939b | 9115 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
9116 | info_ptr += 1; |
9117 | break; | |
9118 | case DW_FORM_ref2: | |
10b3939b | 9119 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
9120 | info_ptr += 2; |
9121 | break; | |
9122 | case DW_FORM_ref4: | |
10b3939b | 9123 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
9124 | info_ptr += 4; |
9125 | break; | |
613e1657 | 9126 | case DW_FORM_ref8: |
10b3939b | 9127 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
9128 | info_ptr += 8; |
9129 | break; | |
348e048f DE |
9130 | case DW_FORM_sig8: |
9131 | /* Convert the signature to something we can record in DW_UNSND | |
9132 | for later lookup. | |
9133 | NOTE: This is NULL if the type wasn't found. */ | |
9134 | DW_SIGNATURED_TYPE (attr) = | |
9135 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); | |
9136 | info_ptr += 8; | |
9137 | break; | |
c906108c | 9138 | case DW_FORM_ref_udata: |
10b3939b DJ |
9139 | DW_ADDR (attr) = (cu->header.offset |
9140 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
9141 | info_ptr += bytes_read; |
9142 | break; | |
c906108c | 9143 | case DW_FORM_indirect: |
a8329558 KW |
9144 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
9145 | info_ptr += bytes_read; | |
e7c27a73 | 9146 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 9147 | break; |
c906108c | 9148 | default: |
8a3fe4f8 | 9149 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
9150 | dwarf_form_name (form), |
9151 | bfd_get_filename (abfd)); | |
c906108c | 9152 | } |
28e94949 JB |
9153 | |
9154 | /* We have seen instances where the compiler tried to emit a byte | |
9155 | size attribute of -1 which ended up being encoded as an unsigned | |
9156 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
9157 | an object of this size seems pretty unlikely so we can relatively | |
9158 | safely treat these cases as if the size attribute was invalid and | |
9159 | treat them as zero by default. */ | |
9160 | if (attr->name == DW_AT_byte_size | |
9161 | && form == DW_FORM_data4 | |
9162 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
9163 | { |
9164 | complaint | |
9165 | (&symfile_complaints, | |
43bbcdc2 PH |
9166 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
9167 | hex_string (DW_UNSND (attr))); | |
01c66ae6 JB |
9168 | DW_UNSND (attr) = 0; |
9169 | } | |
28e94949 | 9170 | |
c906108c SS |
9171 | return info_ptr; |
9172 | } | |
9173 | ||
a8329558 KW |
9174 | /* Read an attribute described by an abbreviated attribute. */ |
9175 | ||
fe1b8b76 | 9176 | static gdb_byte * |
a8329558 | 9177 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 9178 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
9179 | { |
9180 | attr->name = abbrev->name; | |
e7c27a73 | 9181 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
9182 | } |
9183 | ||
c906108c SS |
9184 | /* read dwarf information from a buffer */ |
9185 | ||
9186 | static unsigned int | |
fe1b8b76 | 9187 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9188 | { |
fe1b8b76 | 9189 | return bfd_get_8 (abfd, buf); |
c906108c SS |
9190 | } |
9191 | ||
9192 | static int | |
fe1b8b76 | 9193 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 9194 | { |
fe1b8b76 | 9195 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
9196 | } |
9197 | ||
9198 | static unsigned int | |
fe1b8b76 | 9199 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9200 | { |
fe1b8b76 | 9201 | return bfd_get_16 (abfd, buf); |
c906108c SS |
9202 | } |
9203 | ||
9204 | static int | |
fe1b8b76 | 9205 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9206 | { |
fe1b8b76 | 9207 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
9208 | } |
9209 | ||
9210 | static unsigned int | |
fe1b8b76 | 9211 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9212 | { |
fe1b8b76 | 9213 | return bfd_get_32 (abfd, buf); |
c906108c SS |
9214 | } |
9215 | ||
9216 | static int | |
fe1b8b76 | 9217 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9218 | { |
fe1b8b76 | 9219 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
9220 | } |
9221 | ||
93311388 | 9222 | static ULONGEST |
fe1b8b76 | 9223 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 9224 | { |
fe1b8b76 | 9225 | return bfd_get_64 (abfd, buf); |
c906108c SS |
9226 | } |
9227 | ||
9228 | static CORE_ADDR | |
fe1b8b76 | 9229 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 9230 | unsigned int *bytes_read) |
c906108c | 9231 | { |
e7c27a73 | 9232 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
9233 | CORE_ADDR retval = 0; |
9234 | ||
107d2387 | 9235 | if (cu_header->signed_addr_p) |
c906108c | 9236 | { |
107d2387 AC |
9237 | switch (cu_header->addr_size) |
9238 | { | |
9239 | case 2: | |
fe1b8b76 | 9240 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
9241 | break; |
9242 | case 4: | |
fe1b8b76 | 9243 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
9244 | break; |
9245 | case 8: | |
fe1b8b76 | 9246 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
9247 | break; |
9248 | default: | |
8e65ff28 | 9249 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9250 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 9251 | bfd_get_filename (abfd)); |
107d2387 AC |
9252 | } |
9253 | } | |
9254 | else | |
9255 | { | |
9256 | switch (cu_header->addr_size) | |
9257 | { | |
9258 | case 2: | |
fe1b8b76 | 9259 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
9260 | break; |
9261 | case 4: | |
fe1b8b76 | 9262 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
9263 | break; |
9264 | case 8: | |
fe1b8b76 | 9265 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
9266 | break; |
9267 | default: | |
8e65ff28 | 9268 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 9269 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 9270 | bfd_get_filename (abfd)); |
107d2387 | 9271 | } |
c906108c | 9272 | } |
64367e0a | 9273 | |
107d2387 AC |
9274 | *bytes_read = cu_header->addr_size; |
9275 | return retval; | |
c906108c SS |
9276 | } |
9277 | ||
f7ef9339 | 9278 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
9279 | specification allows the initial length to take up either 4 bytes |
9280 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
9281 | bytes describe the length and all offsets will be 8 bytes in length | |
9282 | instead of 4. | |
9283 | ||
f7ef9339 KB |
9284 | An older, non-standard 64-bit format is also handled by this |
9285 | function. The older format in question stores the initial length | |
9286 | as an 8-byte quantity without an escape value. Lengths greater | |
9287 | than 2^32 aren't very common which means that the initial 4 bytes | |
9288 | is almost always zero. Since a length value of zero doesn't make | |
9289 | sense for the 32-bit format, this initial zero can be considered to | |
9290 | be an escape value which indicates the presence of the older 64-bit | |
9291 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
9292 | greater than 4GB. If it becomes necessary to handle lengths |
9293 | somewhat larger than 4GB, we could allow other small values (such | |
9294 | as the non-sensical values of 1, 2, and 3) to also be used as | |
9295 | escape values indicating the presence of the old format. | |
f7ef9339 | 9296 | |
917c78fc MK |
9297 | The value returned via bytes_read should be used to increment the |
9298 | relevant pointer after calling read_initial_length(). | |
c764a876 | 9299 | |
613e1657 KB |
9300 | [ Note: read_initial_length() and read_offset() are based on the |
9301 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 9302 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
9303 | from: |
9304 | ||
f7ef9339 | 9305 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
6e70227d | 9306 | |
613e1657 KB |
9307 | This document is only a draft and is subject to change. (So beware.) |
9308 | ||
f7ef9339 | 9309 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
9310 | determined empirically by examining 64-bit ELF files produced by |
9311 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
9312 | |
9313 | - Kevin, July 16, 2002 | |
613e1657 KB |
9314 | ] */ |
9315 | ||
9316 | static LONGEST | |
c764a876 | 9317 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 9318 | { |
fe1b8b76 | 9319 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 9320 | |
dd373385 | 9321 | if (length == 0xffffffff) |
613e1657 | 9322 | { |
fe1b8b76 | 9323 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 9324 | *bytes_read = 12; |
613e1657 | 9325 | } |
dd373385 | 9326 | else if (length == 0) |
f7ef9339 | 9327 | { |
dd373385 | 9328 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 9329 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 9330 | *bytes_read = 8; |
f7ef9339 | 9331 | } |
613e1657 KB |
9332 | else |
9333 | { | |
9334 | *bytes_read = 4; | |
613e1657 KB |
9335 | } |
9336 | ||
c764a876 DE |
9337 | return length; |
9338 | } | |
dd373385 | 9339 | |
c764a876 DE |
9340 | /* Cover function for read_initial_length. |
9341 | Returns the length of the object at BUF, and stores the size of the | |
9342 | initial length in *BYTES_READ and stores the size that offsets will be in | |
9343 | *OFFSET_SIZE. | |
9344 | If the initial length size is not equivalent to that specified in | |
9345 | CU_HEADER then issue a complaint. | |
9346 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 9347 | |
c764a876 DE |
9348 | static LONGEST |
9349 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
9350 | const struct comp_unit_head *cu_header, | |
9351 | unsigned int *bytes_read, | |
9352 | unsigned int *offset_size) | |
9353 | { | |
9354 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
9355 | ||
9356 | gdb_assert (cu_header->initial_length_size == 4 | |
9357 | || cu_header->initial_length_size == 8 | |
9358 | || cu_header->initial_length_size == 12); | |
9359 | ||
9360 | if (cu_header->initial_length_size != *bytes_read) | |
9361 | complaint (&symfile_complaints, | |
9362 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 9363 | |
c764a876 | 9364 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 9365 | return length; |
613e1657 KB |
9366 | } |
9367 | ||
9368 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 9369 | given by cu_header->offset_size. */ |
613e1657 KB |
9370 | |
9371 | static LONGEST | |
fe1b8b76 | 9372 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 9373 | unsigned int *bytes_read) |
c764a876 DE |
9374 | { |
9375 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
9a619af0 | 9376 | |
c764a876 DE |
9377 | *bytes_read = cu_header->offset_size; |
9378 | return offset; | |
9379 | } | |
9380 | ||
9381 | /* Read an offset from the data stream. */ | |
9382 | ||
9383 | static LONGEST | |
9384 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
9385 | { |
9386 | LONGEST retval = 0; | |
9387 | ||
c764a876 | 9388 | switch (offset_size) |
613e1657 KB |
9389 | { |
9390 | case 4: | |
fe1b8b76 | 9391 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
9392 | break; |
9393 | case 8: | |
fe1b8b76 | 9394 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
9395 | break; |
9396 | default: | |
8e65ff28 | 9397 | internal_error (__FILE__, __LINE__, |
c764a876 | 9398 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 9399 | bfd_get_filename (abfd)); |
613e1657 KB |
9400 | } |
9401 | ||
917c78fc | 9402 | return retval; |
613e1657 KB |
9403 | } |
9404 | ||
fe1b8b76 JB |
9405 | static gdb_byte * |
9406 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
9407 | { |
9408 | /* If the size of a host char is 8 bits, we can return a pointer | |
9409 | to the buffer, otherwise we have to copy the data to a buffer | |
9410 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9411 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 9412 | return buf; |
c906108c SS |
9413 | } |
9414 | ||
9415 | static char * | |
9b1c24c8 | 9416 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
9417 | { |
9418 | /* If the size of a host char is 8 bits, we can return a pointer | |
9419 | to the string, otherwise we have to copy the string to a buffer | |
9420 | allocated on the temporary obstack. */ | |
4bdf3d34 | 9421 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
9422 | if (*buf == '\0') |
9423 | { | |
9424 | *bytes_read_ptr = 1; | |
9425 | return NULL; | |
9426 | } | |
fe1b8b76 JB |
9427 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
9428 | return (char *) buf; | |
4bdf3d34 JJ |
9429 | } |
9430 | ||
9431 | static char * | |
fe1b8b76 | 9432 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
9433 | const struct comp_unit_head *cu_header, |
9434 | unsigned int *bytes_read_ptr) | |
9435 | { | |
c764a876 | 9436 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 9437 | |
be391dca | 9438 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
dce234bc | 9439 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 9440 | { |
8a3fe4f8 | 9441 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 9442 | bfd_get_filename (abfd)); |
4bdf3d34 | 9443 | return NULL; |
c906108c | 9444 | } |
dce234bc | 9445 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 9446 | { |
8a3fe4f8 | 9447 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 9448 | bfd_get_filename (abfd)); |
c906108c SS |
9449 | return NULL; |
9450 | } | |
4bdf3d34 | 9451 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 9452 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 9453 | return NULL; |
dce234bc | 9454 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
9455 | } |
9456 | ||
ce5d95e1 | 9457 | static unsigned long |
fe1b8b76 | 9458 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9459 | { |
ce5d95e1 JB |
9460 | unsigned long result; |
9461 | unsigned int num_read; | |
c906108c SS |
9462 | int i, shift; |
9463 | unsigned char byte; | |
9464 | ||
9465 | result = 0; | |
9466 | shift = 0; | |
9467 | num_read = 0; | |
9468 | i = 0; | |
9469 | while (1) | |
9470 | { | |
fe1b8b76 | 9471 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9472 | buf++; |
9473 | num_read++; | |
ce5d95e1 | 9474 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
9475 | if ((byte & 128) == 0) |
9476 | { | |
9477 | break; | |
9478 | } | |
9479 | shift += 7; | |
9480 | } | |
9481 | *bytes_read_ptr = num_read; | |
9482 | return result; | |
9483 | } | |
9484 | ||
ce5d95e1 | 9485 | static long |
fe1b8b76 | 9486 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 9487 | { |
ce5d95e1 | 9488 | long result; |
77e0b926 | 9489 | int i, shift, num_read; |
c906108c SS |
9490 | unsigned char byte; |
9491 | ||
9492 | result = 0; | |
9493 | shift = 0; | |
c906108c SS |
9494 | num_read = 0; |
9495 | i = 0; | |
9496 | while (1) | |
9497 | { | |
fe1b8b76 | 9498 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
9499 | buf++; |
9500 | num_read++; | |
ce5d95e1 | 9501 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
9502 | shift += 7; |
9503 | if ((byte & 128) == 0) | |
9504 | { | |
9505 | break; | |
9506 | } | |
9507 | } | |
77e0b926 DJ |
9508 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
9509 | result |= -(((long)1) << shift); | |
c906108c SS |
9510 | *bytes_read_ptr = num_read; |
9511 | return result; | |
9512 | } | |
9513 | ||
4bb7a0a7 DJ |
9514 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
9515 | ||
fe1b8b76 JB |
9516 | static gdb_byte * |
9517 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
9518 | { |
9519 | int byte; | |
9520 | ||
9521 | while (1) | |
9522 | { | |
fe1b8b76 | 9523 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
9524 | buf++; |
9525 | if ((byte & 128) == 0) | |
9526 | return buf; | |
9527 | } | |
9528 | } | |
9529 | ||
c906108c | 9530 | static void |
e142c38c | 9531 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
9532 | { |
9533 | switch (lang) | |
9534 | { | |
9535 | case DW_LANG_C89: | |
76bee0cc | 9536 | case DW_LANG_C99: |
c906108c | 9537 | case DW_LANG_C: |
e142c38c | 9538 | cu->language = language_c; |
c906108c SS |
9539 | break; |
9540 | case DW_LANG_C_plus_plus: | |
e142c38c | 9541 | cu->language = language_cplus; |
c906108c | 9542 | break; |
6aecb9c2 JB |
9543 | case DW_LANG_D: |
9544 | cu->language = language_d; | |
9545 | break; | |
c906108c SS |
9546 | case DW_LANG_Fortran77: |
9547 | case DW_LANG_Fortran90: | |
b21b22e0 | 9548 | case DW_LANG_Fortran95: |
e142c38c | 9549 | cu->language = language_fortran; |
c906108c SS |
9550 | break; |
9551 | case DW_LANG_Mips_Assembler: | |
e142c38c | 9552 | cu->language = language_asm; |
c906108c | 9553 | break; |
bebd888e | 9554 | case DW_LANG_Java: |
e142c38c | 9555 | cu->language = language_java; |
bebd888e | 9556 | break; |
c906108c | 9557 | case DW_LANG_Ada83: |
8aaf0b47 | 9558 | case DW_LANG_Ada95: |
bc5f45f8 JB |
9559 | cu->language = language_ada; |
9560 | break; | |
72019c9c GM |
9561 | case DW_LANG_Modula2: |
9562 | cu->language = language_m2; | |
9563 | break; | |
fe8e67fd PM |
9564 | case DW_LANG_Pascal83: |
9565 | cu->language = language_pascal; | |
9566 | break; | |
22566fbd DJ |
9567 | case DW_LANG_ObjC: |
9568 | cu->language = language_objc; | |
9569 | break; | |
c906108c SS |
9570 | case DW_LANG_Cobol74: |
9571 | case DW_LANG_Cobol85: | |
c906108c | 9572 | default: |
e142c38c | 9573 | cu->language = language_minimal; |
c906108c SS |
9574 | break; |
9575 | } | |
e142c38c | 9576 | cu->language_defn = language_def (cu->language); |
c906108c SS |
9577 | } |
9578 | ||
9579 | /* Return the named attribute or NULL if not there. */ | |
9580 | ||
9581 | static struct attribute * | |
e142c38c | 9582 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
9583 | { |
9584 | unsigned int i; | |
9585 | struct attribute *spec = NULL; | |
9586 | ||
9587 | for (i = 0; i < die->num_attrs; ++i) | |
9588 | { | |
9589 | if (die->attrs[i].name == name) | |
10b3939b | 9590 | return &die->attrs[i]; |
c906108c SS |
9591 | if (die->attrs[i].name == DW_AT_specification |
9592 | || die->attrs[i].name == DW_AT_abstract_origin) | |
9593 | spec = &die->attrs[i]; | |
9594 | } | |
c906108c | 9595 | |
10b3939b | 9596 | if (spec) |
f2f0e013 DJ |
9597 | { |
9598 | die = follow_die_ref (die, spec, &cu); | |
9599 | return dwarf2_attr (die, name, cu); | |
9600 | } | |
c5aa993b | 9601 | |
c906108c SS |
9602 | return NULL; |
9603 | } | |
9604 | ||
348e048f DE |
9605 | /* Return the named attribute or NULL if not there, |
9606 | but do not follow DW_AT_specification, etc. | |
9607 | This is for use in contexts where we're reading .debug_types dies. | |
9608 | Following DW_AT_specification, DW_AT_abstract_origin will take us | |
9609 | back up the chain, and we want to go down. */ | |
9610 | ||
9611 | static struct attribute * | |
9612 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, | |
9613 | struct dwarf2_cu *cu) | |
9614 | { | |
9615 | unsigned int i; | |
9616 | ||
9617 | for (i = 0; i < die->num_attrs; ++i) | |
9618 | if (die->attrs[i].name == name) | |
9619 | return &die->attrs[i]; | |
9620 | ||
9621 | return NULL; | |
9622 | } | |
9623 | ||
05cf31d1 JB |
9624 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
9625 | and holds a non-zero value. This function should only be used for | |
2dc7f7b3 | 9626 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
05cf31d1 JB |
9627 | |
9628 | static int | |
9629 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
9630 | { | |
9631 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
9632 | ||
9633 | return (attr && DW_UNSND (attr)); | |
9634 | } | |
9635 | ||
3ca72b44 | 9636 | static int |
e142c38c | 9637 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 9638 | { |
05cf31d1 JB |
9639 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
9640 | which value is non-zero. However, we have to be careful with | |
9641 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
9642 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
9643 | end up accidently finding a declaration attribute that belongs | |
9644 | to a different DIE referenced by the specification attribute, | |
9645 | even though the given DIE does not have a declaration attribute. */ | |
9646 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
9647 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
9648 | } |
9649 | ||
63d06c5c | 9650 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 | 9651 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
edb3359d DJ |
9652 | containing the return value on output. If there is no |
9653 | specification, but there is an abstract origin, that is | |
9654 | returned. */ | |
63d06c5c DC |
9655 | |
9656 | static struct die_info * | |
f2f0e013 | 9657 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 9658 | { |
f2f0e013 DJ |
9659 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
9660 | *spec_cu); | |
63d06c5c | 9661 | |
edb3359d DJ |
9662 | if (spec_attr == NULL) |
9663 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); | |
9664 | ||
63d06c5c DC |
9665 | if (spec_attr == NULL) |
9666 | return NULL; | |
9667 | else | |
f2f0e013 | 9668 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 9669 | } |
c906108c | 9670 | |
debd256d JB |
9671 | /* Free the line_header structure *LH, and any arrays and strings it |
9672 | refers to. */ | |
9673 | static void | |
9674 | free_line_header (struct line_header *lh) | |
9675 | { | |
9676 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 9677 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
9678 | |
9679 | /* Remember that all the lh->file_names[i].name pointers are | |
9680 | pointers into debug_line_buffer, and don't need to be freed. */ | |
9681 | if (lh->file_names) | |
a8bc7b56 | 9682 | xfree (lh->file_names); |
debd256d JB |
9683 | |
9684 | /* Similarly for the include directory names. */ | |
9685 | if (lh->include_dirs) | |
a8bc7b56 | 9686 | xfree (lh->include_dirs); |
debd256d | 9687 | |
a8bc7b56 | 9688 | xfree (lh); |
debd256d JB |
9689 | } |
9690 | ||
9691 | ||
9692 | /* Add an entry to LH's include directory table. */ | |
9693 | static void | |
9694 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 9695 | { |
debd256d JB |
9696 | /* Grow the array if necessary. */ |
9697 | if (lh->include_dirs_size == 0) | |
c5aa993b | 9698 | { |
debd256d JB |
9699 | lh->include_dirs_size = 1; /* for testing */ |
9700 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
9701 | * sizeof (*lh->include_dirs)); | |
9702 | } | |
9703 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
9704 | { | |
9705 | lh->include_dirs_size *= 2; | |
9706 | lh->include_dirs = xrealloc (lh->include_dirs, | |
9707 | (lh->include_dirs_size | |
9708 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 9709 | } |
c906108c | 9710 | |
debd256d JB |
9711 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
9712 | } | |
6e70227d | 9713 | |
debd256d JB |
9714 | |
9715 | /* Add an entry to LH's file name table. */ | |
9716 | static void | |
9717 | add_file_name (struct line_header *lh, | |
9718 | char *name, | |
9719 | unsigned int dir_index, | |
9720 | unsigned int mod_time, | |
9721 | unsigned int length) | |
9722 | { | |
9723 | struct file_entry *fe; | |
9724 | ||
9725 | /* Grow the array if necessary. */ | |
9726 | if (lh->file_names_size == 0) | |
9727 | { | |
9728 | lh->file_names_size = 1; /* for testing */ | |
9729 | lh->file_names = xmalloc (lh->file_names_size | |
9730 | * sizeof (*lh->file_names)); | |
9731 | } | |
9732 | else if (lh->num_file_names >= lh->file_names_size) | |
9733 | { | |
9734 | lh->file_names_size *= 2; | |
9735 | lh->file_names = xrealloc (lh->file_names, | |
9736 | (lh->file_names_size | |
9737 | * sizeof (*lh->file_names))); | |
9738 | } | |
9739 | ||
9740 | fe = &lh->file_names[lh->num_file_names++]; | |
9741 | fe->name = name; | |
9742 | fe->dir_index = dir_index; | |
9743 | fe->mod_time = mod_time; | |
9744 | fe->length = length; | |
aaa75496 | 9745 | fe->included_p = 0; |
cb1df416 | 9746 | fe->symtab = NULL; |
debd256d | 9747 | } |
6e70227d | 9748 | |
debd256d JB |
9749 | |
9750 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
9751 | .debug_line, according to the endianness of ABFD. Return a pointer |
9752 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
9753 | |
9754 | NOTE: the strings in the include directory and file name tables of | |
9755 | the returned object point into debug_line_buffer, and must not be | |
9756 | freed. */ | |
9757 | static struct line_header * | |
9758 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 9759 | struct dwarf2_cu *cu) |
debd256d JB |
9760 | { |
9761 | struct cleanup *back_to; | |
9762 | struct line_header *lh; | |
fe1b8b76 | 9763 | gdb_byte *line_ptr; |
c764a876 | 9764 | unsigned int bytes_read, offset_size; |
debd256d JB |
9765 | int i; |
9766 | char *cur_dir, *cur_file; | |
9767 | ||
be391dca | 9768 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
dce234bc | 9769 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 9770 | { |
e2e0b3e5 | 9771 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
9772 | return 0; |
9773 | } | |
9774 | ||
a738430d MK |
9775 | /* Make sure that at least there's room for the total_length field. |
9776 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 9777 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 9778 | { |
4d3c2250 | 9779 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9780 | return 0; |
9781 | } | |
9782 | ||
9783 | lh = xmalloc (sizeof (*lh)); | |
9784 | memset (lh, 0, sizeof (*lh)); | |
9785 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
9786 | (void *) lh); | |
9787 | ||
dce234bc | 9788 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 9789 | |
a738430d | 9790 | /* Read in the header. */ |
6e70227d | 9791 | lh->total_length = |
c764a876 DE |
9792 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
9793 | &bytes_read, &offset_size); | |
debd256d | 9794 | line_ptr += bytes_read; |
dce234bc PP |
9795 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
9796 | + dwarf2_per_objfile->line.size)) | |
debd256d | 9797 | { |
4d3c2250 | 9798 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
9799 | return 0; |
9800 | } | |
9801 | lh->statement_program_end = line_ptr + lh->total_length; | |
9802 | lh->version = read_2_bytes (abfd, line_ptr); | |
9803 | line_ptr += 2; | |
c764a876 DE |
9804 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
9805 | line_ptr += offset_size; | |
debd256d JB |
9806 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
9807 | line_ptr += 1; | |
2dc7f7b3 TT |
9808 | if (lh->version >= 4) |
9809 | { | |
9810 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); | |
9811 | line_ptr += 1; | |
9812 | } | |
9813 | else | |
9814 | lh->maximum_ops_per_instruction = 1; | |
9815 | ||
9816 | if (lh->maximum_ops_per_instruction == 0) | |
9817 | { | |
9818 | lh->maximum_ops_per_instruction = 1; | |
9819 | complaint (&symfile_complaints, | |
9820 | _("invalid maximum_ops_per_instruction in `.debug_line' section")); | |
9821 | } | |
9822 | ||
debd256d JB |
9823 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
9824 | line_ptr += 1; | |
9825 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
9826 | line_ptr += 1; | |
9827 | lh->line_range = read_1_byte (abfd, line_ptr); | |
9828 | line_ptr += 1; | |
9829 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
9830 | line_ptr += 1; | |
9831 | lh->standard_opcode_lengths | |
fe1b8b76 | 9832 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
9833 | |
9834 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
9835 | for (i = 1; i < lh->opcode_base; ++i) | |
9836 | { | |
9837 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
9838 | line_ptr += 1; | |
9839 | } | |
9840 | ||
a738430d | 9841 | /* Read directory table. */ |
9b1c24c8 | 9842 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
9843 | { |
9844 | line_ptr += bytes_read; | |
9845 | add_include_dir (lh, cur_dir); | |
9846 | } | |
9847 | line_ptr += bytes_read; | |
9848 | ||
a738430d | 9849 | /* Read file name table. */ |
9b1c24c8 | 9850 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
debd256d JB |
9851 | { |
9852 | unsigned int dir_index, mod_time, length; | |
9853 | ||
9854 | line_ptr += bytes_read; | |
9855 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9856 | line_ptr += bytes_read; | |
9857 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9858 | line_ptr += bytes_read; | |
9859 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
9860 | line_ptr += bytes_read; | |
9861 | ||
9862 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
9863 | } | |
9864 | line_ptr += bytes_read; | |
6e70227d | 9865 | lh->statement_program_start = line_ptr; |
debd256d | 9866 | |
dce234bc PP |
9867 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
9868 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 9869 | complaint (&symfile_complaints, |
e2e0b3e5 | 9870 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
9871 | |
9872 | discard_cleanups (back_to); | |
9873 | return lh; | |
9874 | } | |
c906108c | 9875 | |
5fb290d7 DJ |
9876 | /* This function exists to work around a bug in certain compilers |
9877 | (particularly GCC 2.95), in which the first line number marker of a | |
9878 | function does not show up until after the prologue, right before | |
9879 | the second line number marker. This function shifts ADDRESS down | |
9880 | to the beginning of the function if necessary, and is called on | |
9881 | addresses passed to record_line. */ | |
9882 | ||
9883 | static CORE_ADDR | |
e142c38c | 9884 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
9885 | { |
9886 | struct function_range *fn; | |
9887 | ||
9888 | /* Find the function_range containing address. */ | |
e142c38c | 9889 | if (!cu->first_fn) |
5fb290d7 DJ |
9890 | return address; |
9891 | ||
e142c38c DJ |
9892 | if (!cu->cached_fn) |
9893 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 9894 | |
e142c38c | 9895 | fn = cu->cached_fn; |
5fb290d7 DJ |
9896 | while (fn) |
9897 | if (fn->lowpc <= address && fn->highpc > address) | |
9898 | goto found; | |
9899 | else | |
9900 | fn = fn->next; | |
9901 | ||
e142c38c DJ |
9902 | fn = cu->first_fn; |
9903 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
9904 | if (fn->lowpc <= address && fn->highpc > address) |
9905 | goto found; | |
9906 | else | |
9907 | fn = fn->next; | |
9908 | ||
9909 | return address; | |
9910 | ||
9911 | found: | |
9912 | if (fn->seen_line) | |
9913 | return address; | |
9914 | if (address != fn->lowpc) | |
4d3c2250 | 9915 | complaint (&symfile_complaints, |
e2e0b3e5 | 9916 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 9917 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
9918 | fn->seen_line = 1; |
9919 | return fn->lowpc; | |
9920 | } | |
9921 | ||
c6da4cef DE |
9922 | /* Subroutine of dwarf_decode_lines to simplify it. |
9923 | Return the file name of the psymtab for included file FILE_INDEX | |
9924 | in line header LH of PST. | |
9925 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
9926 | If space for the result is malloc'd, it will be freed by a cleanup. | |
9927 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ | |
9928 | ||
9929 | static char * | |
9930 | psymtab_include_file_name (const struct line_header *lh, int file_index, | |
9931 | const struct partial_symtab *pst, | |
9932 | const char *comp_dir) | |
9933 | { | |
9934 | const struct file_entry fe = lh->file_names [file_index]; | |
9935 | char *include_name = fe.name; | |
9936 | char *include_name_to_compare = include_name; | |
9937 | char *dir_name = NULL; | |
9938 | char *pst_filename; | |
9939 | int file_is_pst; | |
9940 | ||
9941 | if (fe.dir_index) | |
9942 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
9943 | ||
9944 | if (!IS_ABSOLUTE_PATH (include_name) | |
9945 | && (dir_name != NULL || comp_dir != NULL)) | |
9946 | { | |
9947 | /* Avoid creating a duplicate psymtab for PST. | |
9948 | We do this by comparing INCLUDE_NAME and PST_FILENAME. | |
9949 | Before we do the comparison, however, we need to account | |
9950 | for DIR_NAME and COMP_DIR. | |
9951 | First prepend dir_name (if non-NULL). If we still don't | |
9952 | have an absolute path prepend comp_dir (if non-NULL). | |
9953 | However, the directory we record in the include-file's | |
9954 | psymtab does not contain COMP_DIR (to match the | |
9955 | corresponding symtab(s)). | |
9956 | ||
9957 | Example: | |
9958 | ||
9959 | bash$ cd /tmp | |
9960 | bash$ gcc -g ./hello.c | |
9961 | include_name = "hello.c" | |
9962 | dir_name = "." | |
9963 | DW_AT_comp_dir = comp_dir = "/tmp" | |
9964 | DW_AT_name = "./hello.c" */ | |
9965 | ||
9966 | if (dir_name != NULL) | |
9967 | { | |
9968 | include_name = concat (dir_name, SLASH_STRING, | |
9969 | include_name, (char *)NULL); | |
9970 | include_name_to_compare = include_name; | |
9971 | make_cleanup (xfree, include_name); | |
9972 | } | |
9973 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) | |
9974 | { | |
9975 | include_name_to_compare = concat (comp_dir, SLASH_STRING, | |
9976 | include_name, (char *)NULL); | |
9977 | } | |
9978 | } | |
9979 | ||
9980 | pst_filename = pst->filename; | |
9981 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
9982 | { | |
9983 | pst_filename = concat (pst->dirname, SLASH_STRING, | |
9984 | pst_filename, (char *)NULL); | |
9985 | } | |
9986 | ||
9987 | file_is_pst = strcmp (include_name_to_compare, pst_filename) == 0; | |
9988 | ||
9989 | if (include_name_to_compare != include_name) | |
9990 | xfree (include_name_to_compare); | |
9991 | if (pst_filename != pst->filename) | |
9992 | xfree (pst_filename); | |
9993 | ||
9994 | if (file_is_pst) | |
9995 | return NULL; | |
9996 | return include_name; | |
9997 | } | |
9998 | ||
aaa75496 JB |
9999 | /* Decode the Line Number Program (LNP) for the given line_header |
10000 | structure and CU. The actual information extracted and the type | |
10001 | of structures created from the LNP depends on the value of PST. | |
10002 | ||
10003 | 1. If PST is NULL, then this procedure uses the data from the program | |
10004 | to create all necessary symbol tables, and their linetables. | |
6e70227d | 10005 | |
aaa75496 JB |
10006 | 2. If PST is not NULL, this procedure reads the program to determine |
10007 | the list of files included by the unit represented by PST, and | |
c6da4cef DE |
10008 | builds all the associated partial symbol tables. |
10009 | ||
10010 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. | |
10011 | It is used for relative paths in the line table. | |
10012 | NOTE: When processing partial symtabs (pst != NULL), | |
10013 | comp_dir == pst->dirname. | |
10014 | ||
10015 | NOTE: It is important that psymtabs have the same file name (via strcmp) | |
10016 | as the corresponding symtab. Since COMP_DIR is not used in the name of the | |
10017 | symtab we don't use it in the name of the psymtabs we create. | |
10018 | E.g. expand_line_sal requires this when finding psymtabs to expand. | |
10019 | A good testcase for this is mb-inline.exp. */ | |
debd256d | 10020 | |
c906108c | 10021 | static void |
debd256d | 10022 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 10023 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 10024 | { |
a8c50c1f | 10025 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 10026 | gdb_byte *line_end; |
a8c50c1f | 10027 | unsigned int bytes_read, extended_len; |
c906108c | 10028 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
10029 | CORE_ADDR baseaddr; |
10030 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 10031 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 10032 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 10033 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
10034 | |
10035 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10036 | |
debd256d JB |
10037 | line_ptr = lh->statement_program_start; |
10038 | line_end = lh->statement_program_end; | |
c906108c SS |
10039 | |
10040 | /* Read the statement sequences until there's nothing left. */ | |
10041 | while (line_ptr < line_end) | |
10042 | { | |
10043 | /* state machine registers */ | |
10044 | CORE_ADDR address = 0; | |
10045 | unsigned int file = 1; | |
10046 | unsigned int line = 1; | |
10047 | unsigned int column = 0; | |
debd256d | 10048 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
10049 | int basic_block = 0; |
10050 | int end_sequence = 0; | |
fbf65064 | 10051 | CORE_ADDR addr; |
2dc7f7b3 | 10052 | unsigned char op_index = 0; |
c906108c | 10053 | |
aaa75496 | 10054 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 10055 | { |
aaa75496 | 10056 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
10057 | /* lh->include_dirs and lh->file_names are 0-based, but the |
10058 | directory and file name numbers in the statement program | |
10059 | are 1-based. */ | |
10060 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 10061 | char *dir = NULL; |
a738430d | 10062 | |
debd256d JB |
10063 | if (fe->dir_index) |
10064 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
10065 | |
10066 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
10067 | } |
10068 | ||
a738430d | 10069 | /* Decode the table. */ |
c5aa993b | 10070 | while (!end_sequence) |
c906108c SS |
10071 | { |
10072 | op_code = read_1_byte (abfd, line_ptr); | |
10073 | line_ptr += 1; | |
59205f5a JB |
10074 | if (line_ptr > line_end) |
10075 | { | |
10076 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
10077 | break; | |
10078 | } | |
9aa1fe7e | 10079 | |
debd256d | 10080 | if (op_code >= lh->opcode_base) |
6e70227d | 10081 | { |
a738430d | 10082 | /* Special operand. */ |
debd256d | 10083 | adj_opcode = op_code - lh->opcode_base; |
2dc7f7b3 TT |
10084 | address += (((op_index + (adj_opcode / lh->line_range)) |
10085 | / lh->maximum_ops_per_instruction) | |
10086 | * lh->minimum_instruction_length); | |
10087 | op_index = ((op_index + (adj_opcode / lh->line_range)) | |
10088 | % lh->maximum_ops_per_instruction); | |
debd256d | 10089 | line += lh->line_base + (adj_opcode % lh->line_range); |
59205f5a | 10090 | if (lh->num_file_names < file || file == 0) |
25e43795 | 10091 | dwarf2_debug_line_missing_file_complaint (); |
2dc7f7b3 TT |
10092 | /* For now we ignore lines not starting on an |
10093 | instruction boundary. */ | |
10094 | else if (op_index == 0) | |
25e43795 DJ |
10095 | { |
10096 | lh->file_names[file - 1].included_p = 1; | |
ca5f395d | 10097 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10098 | { |
10099 | if (last_subfile != current_subfile) | |
10100 | { | |
10101 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10102 | if (last_subfile) | |
10103 | record_line (last_subfile, 0, addr); | |
10104 | last_subfile = current_subfile; | |
10105 | } | |
25e43795 | 10106 | /* Append row to matrix using current values. */ |
fbf65064 UW |
10107 | addr = check_cu_functions (address, cu); |
10108 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
10109 | record_line (current_subfile, line, addr); | |
366da635 | 10110 | } |
25e43795 | 10111 | } |
ca5f395d | 10112 | basic_block = 0; |
9aa1fe7e GK |
10113 | } |
10114 | else switch (op_code) | |
c906108c SS |
10115 | { |
10116 | case DW_LNS_extended_op: | |
a8c50c1f | 10117 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 10118 | line_ptr += bytes_read; |
a8c50c1f | 10119 | extended_end = line_ptr + extended_len; |
c906108c SS |
10120 | extended_op = read_1_byte (abfd, line_ptr); |
10121 | line_ptr += 1; | |
10122 | switch (extended_op) | |
10123 | { | |
10124 | case DW_LNE_end_sequence: | |
10125 | end_sequence = 1; | |
c906108c SS |
10126 | break; |
10127 | case DW_LNE_set_address: | |
e7c27a73 | 10128 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
2dc7f7b3 | 10129 | op_index = 0; |
107d2387 AC |
10130 | line_ptr += bytes_read; |
10131 | address += baseaddr; | |
c906108c SS |
10132 | break; |
10133 | case DW_LNE_define_file: | |
debd256d JB |
10134 | { |
10135 | char *cur_file; | |
10136 | unsigned int dir_index, mod_time, length; | |
6e70227d | 10137 | |
9b1c24c8 | 10138 | cur_file = read_direct_string (abfd, line_ptr, &bytes_read); |
debd256d JB |
10139 | line_ptr += bytes_read; |
10140 | dir_index = | |
10141 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10142 | line_ptr += bytes_read; | |
10143 | mod_time = | |
10144 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10145 | line_ptr += bytes_read; | |
10146 | length = | |
10147 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10148 | line_ptr += bytes_read; | |
10149 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
10150 | } | |
c906108c | 10151 | break; |
d0c6ba3d CC |
10152 | case DW_LNE_set_discriminator: |
10153 | /* The discriminator is not interesting to the debugger; | |
10154 | just ignore it. */ | |
10155 | line_ptr = extended_end; | |
10156 | break; | |
c906108c | 10157 | default: |
4d3c2250 | 10158 | complaint (&symfile_complaints, |
e2e0b3e5 | 10159 | _("mangled .debug_line section")); |
debd256d | 10160 | return; |
c906108c | 10161 | } |
a8c50c1f DJ |
10162 | /* Make sure that we parsed the extended op correctly. If e.g. |
10163 | we expected a different address size than the producer used, | |
10164 | we may have read the wrong number of bytes. */ | |
10165 | if (line_ptr != extended_end) | |
10166 | { | |
10167 | complaint (&symfile_complaints, | |
10168 | _("mangled .debug_line section")); | |
10169 | return; | |
10170 | } | |
c906108c SS |
10171 | break; |
10172 | case DW_LNS_copy: | |
59205f5a | 10173 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10174 | dwarf2_debug_line_missing_file_complaint (); |
10175 | else | |
366da635 | 10176 | { |
25e43795 | 10177 | lh->file_names[file - 1].included_p = 1; |
ca5f395d | 10178 | if (!decode_for_pst_p && is_stmt) |
fbf65064 UW |
10179 | { |
10180 | if (last_subfile != current_subfile) | |
10181 | { | |
10182 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10183 | if (last_subfile) | |
10184 | record_line (last_subfile, 0, addr); | |
10185 | last_subfile = current_subfile; | |
10186 | } | |
10187 | addr = check_cu_functions (address, cu); | |
10188 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
10189 | record_line (current_subfile, line, addr); | |
10190 | } | |
366da635 | 10191 | } |
c906108c SS |
10192 | basic_block = 0; |
10193 | break; | |
10194 | case DW_LNS_advance_pc: | |
2dc7f7b3 TT |
10195 | { |
10196 | CORE_ADDR adjust | |
10197 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10198 | ||
10199 | address += (((op_index + adjust) | |
10200 | / lh->maximum_ops_per_instruction) | |
10201 | * lh->minimum_instruction_length); | |
10202 | op_index = ((op_index + adjust) | |
10203 | % lh->maximum_ops_per_instruction); | |
10204 | line_ptr += bytes_read; | |
10205 | } | |
c906108c SS |
10206 | break; |
10207 | case DW_LNS_advance_line: | |
10208 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
10209 | line_ptr += bytes_read; | |
10210 | break; | |
10211 | case DW_LNS_set_file: | |
debd256d | 10212 | { |
a738430d MK |
10213 | /* The arrays lh->include_dirs and lh->file_names are |
10214 | 0-based, but the directory and file name numbers in | |
10215 | the statement program are 1-based. */ | |
debd256d | 10216 | struct file_entry *fe; |
4f1520fb | 10217 | char *dir = NULL; |
a738430d | 10218 | |
debd256d JB |
10219 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
10220 | line_ptr += bytes_read; | |
59205f5a | 10221 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
10222 | dwarf2_debug_line_missing_file_complaint (); |
10223 | else | |
10224 | { | |
10225 | fe = &lh->file_names[file - 1]; | |
10226 | if (fe->dir_index) | |
10227 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10228 | if (!decode_for_pst_p) | |
10229 | { | |
10230 | last_subfile = current_subfile; | |
10231 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10232 | } | |
10233 | } | |
debd256d | 10234 | } |
c906108c SS |
10235 | break; |
10236 | case DW_LNS_set_column: | |
10237 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10238 | line_ptr += bytes_read; | |
10239 | break; | |
10240 | case DW_LNS_negate_stmt: | |
10241 | is_stmt = (!is_stmt); | |
10242 | break; | |
10243 | case DW_LNS_set_basic_block: | |
10244 | basic_block = 1; | |
10245 | break; | |
c2c6d25f JM |
10246 | /* Add to the address register of the state machine the |
10247 | address increment value corresponding to special opcode | |
a738430d MK |
10248 | 255. I.e., this value is scaled by the minimum |
10249 | instruction length since special opcode 255 would have | |
10250 | scaled the the increment. */ | |
c906108c | 10251 | case DW_LNS_const_add_pc: |
2dc7f7b3 TT |
10252 | { |
10253 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; | |
10254 | ||
10255 | address += (((op_index + adjust) | |
10256 | / lh->maximum_ops_per_instruction) | |
10257 | * lh->minimum_instruction_length); | |
10258 | op_index = ((op_index + adjust) | |
10259 | % lh->maximum_ops_per_instruction); | |
10260 | } | |
c906108c SS |
10261 | break; |
10262 | case DW_LNS_fixed_advance_pc: | |
10263 | address += read_2_bytes (abfd, line_ptr); | |
2dc7f7b3 | 10264 | op_index = 0; |
c906108c SS |
10265 | line_ptr += 2; |
10266 | break; | |
9aa1fe7e | 10267 | default: |
a738430d MK |
10268 | { |
10269 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 10270 | int i; |
a738430d | 10271 | |
debd256d | 10272 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
10273 | { |
10274 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
10275 | line_ptr += bytes_read; | |
10276 | } | |
10277 | } | |
c906108c SS |
10278 | } |
10279 | } | |
59205f5a JB |
10280 | if (lh->num_file_names < file || file == 0) |
10281 | dwarf2_debug_line_missing_file_complaint (); | |
10282 | else | |
10283 | { | |
10284 | lh->file_names[file - 1].included_p = 1; | |
10285 | if (!decode_for_pst_p) | |
fbf65064 UW |
10286 | { |
10287 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
10288 | record_line (current_subfile, 0, addr); | |
10289 | } | |
59205f5a | 10290 | } |
c906108c | 10291 | } |
aaa75496 JB |
10292 | |
10293 | if (decode_for_pst_p) | |
10294 | { | |
10295 | int file_index; | |
10296 | ||
10297 | /* Now that we're done scanning the Line Header Program, we can | |
10298 | create the psymtab of each included file. */ | |
10299 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
10300 | if (lh->file_names[file_index].included_p == 1) | |
10301 | { | |
c6da4cef DE |
10302 | char *include_name = |
10303 | psymtab_include_file_name (lh, file_index, pst, comp_dir); | |
10304 | if (include_name != NULL) | |
aaa75496 JB |
10305 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
10306 | } | |
10307 | } | |
cb1df416 DJ |
10308 | else |
10309 | { | |
10310 | /* Make sure a symtab is created for every file, even files | |
10311 | which contain only variables (i.e. no code with associated | |
10312 | line numbers). */ | |
10313 | ||
10314 | int i; | |
10315 | struct file_entry *fe; | |
10316 | ||
10317 | for (i = 0; i < lh->num_file_names; i++) | |
10318 | { | |
10319 | char *dir = NULL; | |
9a619af0 | 10320 | |
cb1df416 DJ |
10321 | fe = &lh->file_names[i]; |
10322 | if (fe->dir_index) | |
10323 | dir = lh->include_dirs[fe->dir_index - 1]; | |
10324 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
10325 | ||
10326 | /* Skip the main file; we don't need it, and it must be | |
10327 | allocated last, so that it will show up before the | |
10328 | non-primary symtabs in the objfile's symtab list. */ | |
10329 | if (current_subfile == first_subfile) | |
10330 | continue; | |
10331 | ||
10332 | if (current_subfile->symtab == NULL) | |
10333 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
10334 | cu->objfile); | |
10335 | fe->symtab = current_subfile->symtab; | |
10336 | } | |
10337 | } | |
c906108c SS |
10338 | } |
10339 | ||
10340 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
10341 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
10342 | or NULL if not known. COMP_DIR is the compilation directory for the |
10343 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
10344 | This routine tries to keep line numbers from identical absolute and |
10345 | relative file names in a common subfile. | |
10346 | ||
10347 | Using the `list' example from the GDB testsuite, which resides in | |
10348 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
10349 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
10350 | ||
c5aa993b JM |
10351 | DW_AT_name: /srcdir/list0.c |
10352 | DW_AT_comp_dir: /compdir | |
357e46e7 | 10353 | files.files[0].name: list0.h |
c5aa993b | 10354 | files.files[0].dir: /srcdir |
357e46e7 | 10355 | files.files[1].name: list0.c |
c5aa993b | 10356 | files.files[1].dir: /srcdir |
c906108c SS |
10357 | |
10358 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
10359 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
10360 | start_subfile will ensure that this happens provided that we pass the | |
10361 | concatenation of files.files[1].dir and files.files[1].name as the | |
10362 | subfile's name. */ | |
c906108c SS |
10363 | |
10364 | static void | |
4f1520fb | 10365 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 10366 | { |
4f1520fb FR |
10367 | char *fullname; |
10368 | ||
10369 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
10370 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
10371 | second argument to start_subfile. To be consistent, we do the | |
10372 | same here. In order not to lose the line information directory, | |
10373 | we concatenate it to the filename when it makes sense. | |
10374 | Note that the Dwarf3 standard says (speaking of filenames in line | |
10375 | information): ``The directory index is ignored for file names | |
10376 | that represent full path names''. Thus ignoring dirname in the | |
10377 | `else' branch below isn't an issue. */ | |
c906108c | 10378 | |
d5166ae1 | 10379 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
10380 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
10381 | else | |
10382 | fullname = filename; | |
c906108c | 10383 | |
4f1520fb FR |
10384 | start_subfile (fullname, comp_dir); |
10385 | ||
10386 | if (fullname != filename) | |
10387 | xfree (fullname); | |
c906108c SS |
10388 | } |
10389 | ||
4c2df51b DJ |
10390 | static void |
10391 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 10392 | struct dwarf2_cu *cu) |
4c2df51b | 10393 | { |
e7c27a73 DJ |
10394 | struct objfile *objfile = cu->objfile; |
10395 | struct comp_unit_head *cu_header = &cu->header; | |
10396 | ||
4c2df51b DJ |
10397 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
10398 | code here to turn a symbol with DW_AT_external and a | |
10399 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
10400 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
10401 | with some versions of binutils) where shared libraries could have | |
10402 | relocations against symbols in their debug information - the | |
10403 | minimal symbol would have the right address, but the debug info | |
10404 | would not. It's no longer necessary, because we will explicitly | |
10405 | apply relocations when we read in the debug information now. */ | |
10406 | ||
10407 | /* A DW_AT_location attribute with no contents indicates that a | |
10408 | variable has been optimized away. */ | |
10409 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
10410 | { | |
10411 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
10412 | return; | |
10413 | } | |
10414 | ||
10415 | /* Handle one degenerate form of location expression specially, to | |
10416 | preserve GDB's previous behavior when section offsets are | |
10417 | specified. If this is just a DW_OP_addr then mark this symbol | |
10418 | as LOC_STATIC. */ | |
10419 | ||
10420 | if (attr_form_is_block (attr) | |
10421 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
10422 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
10423 | { | |
891d2f0b | 10424 | unsigned int dummy; |
4c2df51b DJ |
10425 | |
10426 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 10427 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 10428 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
10429 | fixup_symbol_section (sym, objfile); |
10430 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
10431 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
10432 | return; |
10433 | } | |
10434 | ||
10435 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
10436 | expression evaluator, and use LOC_COMPUTED only when necessary | |
10437 | (i.e. when the value of a register or memory location is | |
10438 | referenced, or a thread-local block, etc.). Then again, it might | |
10439 | not be worthwhile. I'm assuming that it isn't unless performance | |
10440 | or memory numbers show me otherwise. */ | |
10441 | ||
e7c27a73 | 10442 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
10443 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
10444 | } | |
10445 | ||
c906108c SS |
10446 | /* Given a pointer to a DWARF information entry, figure out if we need |
10447 | to make a symbol table entry for it, and if so, create a new entry | |
10448 | and return a pointer to it. | |
10449 | If TYPE is NULL, determine symbol type from the die, otherwise | |
34eaf542 TT |
10450 | used the passed type. |
10451 | If SPACE is not NULL, use it to hold the new symbol. If it is | |
10452 | NULL, allocate a new symbol on the objfile's obstack. */ | |
c906108c SS |
10453 | |
10454 | static struct symbol * | |
34eaf542 TT |
10455 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
10456 | struct symbol *space) | |
c906108c | 10457 | { |
e7c27a73 | 10458 | struct objfile *objfile = cu->objfile; |
c906108c SS |
10459 | struct symbol *sym = NULL; |
10460 | char *name; | |
10461 | struct attribute *attr = NULL; | |
10462 | struct attribute *attr2 = NULL; | |
e142c38c | 10463 | CORE_ADDR baseaddr; |
e37fd15a SW |
10464 | struct pending **list_to_add = NULL; |
10465 | ||
edb3359d | 10466 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
e142c38c DJ |
10467 | |
10468 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 10469 | |
94af9270 | 10470 | name = dwarf2_name (die, cu); |
c906108c SS |
10471 | if (name) |
10472 | { | |
94af9270 | 10473 | const char *linkagename; |
34eaf542 | 10474 | int suppress_add = 0; |
94af9270 | 10475 | |
34eaf542 TT |
10476 | if (space) |
10477 | sym = space; | |
10478 | else | |
10479 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); | |
c906108c | 10480 | OBJSTAT (objfile, n_syms++); |
2de7ced7 DJ |
10481 | |
10482 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
33e5013e | 10483 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
94af9270 KS |
10484 | linkagename = dwarf2_physname (name, die, cu); |
10485 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); | |
c906108c | 10486 | |
f55ee35c JK |
10487 | /* Fortran does not have mangling standard and the mangling does differ |
10488 | between gfortran, iFort etc. */ | |
10489 | if (cu->language == language_fortran | |
b250c185 | 10490 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
29df156d SW |
10491 | symbol_set_demangled_name (&(sym->ginfo), |
10492 | (char *) dwarf2_full_name (name, die, cu), | |
10493 | NULL); | |
f55ee35c | 10494 | |
c906108c | 10495 | /* Default assumptions. |
c5aa993b | 10496 | Use the passed type or decode it from the die. */ |
176620f1 | 10497 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 10498 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
10499 | if (type != NULL) |
10500 | SYMBOL_TYPE (sym) = type; | |
10501 | else | |
e7c27a73 | 10502 | SYMBOL_TYPE (sym) = die_type (die, cu); |
edb3359d DJ |
10503 | attr = dwarf2_attr (die, |
10504 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, | |
10505 | cu); | |
c906108c SS |
10506 | if (attr) |
10507 | { | |
10508 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
10509 | } | |
cb1df416 | 10510 | |
edb3359d DJ |
10511 | attr = dwarf2_attr (die, |
10512 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, | |
10513 | cu); | |
cb1df416 DJ |
10514 | if (attr) |
10515 | { | |
10516 | int file_index = DW_UNSND (attr); | |
9a619af0 | 10517 | |
cb1df416 DJ |
10518 | if (cu->line_header == NULL |
10519 | || file_index > cu->line_header->num_file_names) | |
10520 | complaint (&symfile_complaints, | |
10521 | _("file index out of range")); | |
1c3d648d | 10522 | else if (file_index > 0) |
cb1df416 DJ |
10523 | { |
10524 | struct file_entry *fe; | |
9a619af0 | 10525 | |
cb1df416 DJ |
10526 | fe = &cu->line_header->file_names[file_index - 1]; |
10527 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
10528 | } | |
10529 | } | |
10530 | ||
c906108c SS |
10531 | switch (die->tag) |
10532 | { | |
10533 | case DW_TAG_label: | |
e142c38c | 10534 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
10535 | if (attr) |
10536 | { | |
10537 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
10538 | } | |
0f5238ed TT |
10539 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
10540 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; | |
c906108c | 10541 | SYMBOL_CLASS (sym) = LOC_LABEL; |
0f5238ed | 10542 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
10543 | break; |
10544 | case DW_TAG_subprogram: | |
10545 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
10546 | finish_block. */ | |
10547 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 10548 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
10549 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
10550 | || cu->language == language_ada) | |
c906108c | 10551 | { |
2cfa0c8d JB |
10552 | /* Subprograms marked external are stored as a global symbol. |
10553 | Ada subprograms, whether marked external or not, are always | |
10554 | stored as a global symbol, because we want to be able to | |
10555 | access them globally. For instance, we want to be able | |
10556 | to break on a nested subprogram without having to | |
10557 | specify the context. */ | |
e37fd15a | 10558 | list_to_add = &global_symbols; |
c906108c SS |
10559 | } |
10560 | else | |
10561 | { | |
e37fd15a | 10562 | list_to_add = cu->list_in_scope; |
c906108c SS |
10563 | } |
10564 | break; | |
edb3359d DJ |
10565 | case DW_TAG_inlined_subroutine: |
10566 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
10567 | finish_block. */ | |
10568 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
10569 | SYMBOL_INLINED (sym) = 1; | |
10570 | /* Do not add the symbol to any lists. It will be found via | |
10571 | BLOCK_FUNCTION from the blockvector. */ | |
10572 | break; | |
34eaf542 TT |
10573 | case DW_TAG_template_value_param: |
10574 | suppress_add = 1; | |
10575 | /* Fall through. */ | |
c906108c | 10576 | case DW_TAG_variable: |
254e6b9e | 10577 | case DW_TAG_member: |
c906108c SS |
10578 | /* Compilation with minimal debug info may result in variables |
10579 | with missing type entries. Change the misleading `void' type | |
10580 | to something sensible. */ | |
10581 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 10582 | SYMBOL_TYPE (sym) |
46bf5051 | 10583 | = objfile_type (objfile)->nodebug_data_symbol; |
64c50499 | 10584 | |
e142c38c | 10585 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
254e6b9e DE |
10586 | /* In the case of DW_TAG_member, we should only be called for |
10587 | static const members. */ | |
10588 | if (die->tag == DW_TAG_member) | |
10589 | { | |
3863f96c DE |
10590 | /* dwarf2_add_field uses die_is_declaration, |
10591 | so we do the same. */ | |
254e6b9e DE |
10592 | gdb_assert (die_is_declaration (die, cu)); |
10593 | gdb_assert (attr); | |
10594 | } | |
c906108c SS |
10595 | if (attr) |
10596 | { | |
e7c27a73 | 10597 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 10598 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
e37fd15a | 10599 | if (!suppress_add) |
34eaf542 TT |
10600 | { |
10601 | if (attr2 && (DW_UNSND (attr2) != 0)) | |
e37fd15a | 10602 | list_to_add = &global_symbols; |
34eaf542 | 10603 | else |
e37fd15a | 10604 | list_to_add = cu->list_in_scope; |
34eaf542 | 10605 | } |
c906108c SS |
10606 | break; |
10607 | } | |
e142c38c | 10608 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
10609 | if (attr) |
10610 | { | |
e7c27a73 | 10611 | var_decode_location (attr, sym, cu); |
e142c38c | 10612 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
caac4577 JG |
10613 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
10614 | && SYMBOL_VALUE_ADDRESS (sym) == 0 | |
10615 | && !dwarf2_per_objfile->has_section_at_zero) | |
10616 | { | |
10617 | /* When a static variable is eliminated by the linker, | |
10618 | the corresponding debug information is not stripped | |
10619 | out, but the variable address is set to null; | |
10620 | do not add such variables into symbol table. */ | |
10621 | } | |
10622 | else if (attr2 && (DW_UNSND (attr2) != 0)) | |
1c809c68 | 10623 | { |
f55ee35c JK |
10624 | /* Workaround gfortran PR debug/40040 - it uses |
10625 | DW_AT_location for variables in -fPIC libraries which may | |
10626 | get overriden by other libraries/executable and get | |
10627 | a different address. Resolve it by the minimal symbol | |
10628 | which may come from inferior's executable using copy | |
10629 | relocation. Make this workaround only for gfortran as for | |
10630 | other compilers GDB cannot guess the minimal symbol | |
10631 | Fortran mangling kind. */ | |
10632 | if (cu->language == language_fortran && die->parent | |
10633 | && die->parent->tag == DW_TAG_module | |
10634 | && cu->producer | |
10635 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) | |
10636 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
10637 | ||
1c809c68 TT |
10638 | /* A variable with DW_AT_external is never static, |
10639 | but it may be block-scoped. */ | |
10640 | list_to_add = (cu->list_in_scope == &file_symbols | |
10641 | ? &global_symbols : cu->list_in_scope); | |
1c809c68 | 10642 | } |
c906108c | 10643 | else |
e37fd15a | 10644 | list_to_add = cu->list_in_scope; |
c906108c SS |
10645 | } |
10646 | else | |
10647 | { | |
10648 | /* We do not know the address of this symbol. | |
c5aa993b JM |
10649 | If it is an external symbol and we have type information |
10650 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
10651 | The address of the variable will then be determined from | |
10652 | the minimal symbol table whenever the variable is | |
10653 | referenced. */ | |
e142c38c | 10654 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 10655 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 10656 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c | 10657 | { |
0fe7935b DJ |
10658 | /* A variable with DW_AT_external is never static, but it |
10659 | may be block-scoped. */ | |
10660 | list_to_add = (cu->list_in_scope == &file_symbols | |
10661 | ? &global_symbols : cu->list_in_scope); | |
10662 | ||
c906108c | 10663 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
c906108c | 10664 | } |
442ddf59 JK |
10665 | else if (!die_is_declaration (die, cu)) |
10666 | { | |
10667 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
10668 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
e37fd15a SW |
10669 | if (!suppress_add) |
10670 | list_to_add = cu->list_in_scope; | |
442ddf59 | 10671 | } |
c906108c SS |
10672 | } |
10673 | break; | |
10674 | case DW_TAG_formal_parameter: | |
edb3359d DJ |
10675 | /* If we are inside a function, mark this as an argument. If |
10676 | not, we might be looking at an argument to an inlined function | |
10677 | when we do not have enough information to show inlined frames; | |
10678 | pretend it's a local variable in that case so that the user can | |
10679 | still see it. */ | |
10680 | if (context_stack_depth > 0 | |
10681 | && context_stack[context_stack_depth - 1].name != NULL) | |
10682 | SYMBOL_IS_ARGUMENT (sym) = 1; | |
e142c38c | 10683 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
10684 | if (attr) |
10685 | { | |
e7c27a73 | 10686 | var_decode_location (attr, sym, cu); |
c906108c | 10687 | } |
e142c38c | 10688 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10689 | if (attr) |
10690 | { | |
e7c27a73 | 10691 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10692 | } |
f346a30d PM |
10693 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
10694 | if (attr && DW_UNSND (attr)) | |
10695 | { | |
10696 | struct type *ref_type; | |
10697 | ||
10698 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); | |
10699 | SYMBOL_TYPE (sym) = ref_type; | |
10700 | } | |
10701 | ||
e37fd15a | 10702 | list_to_add = cu->list_in_scope; |
c906108c SS |
10703 | break; |
10704 | case DW_TAG_unspecified_parameters: | |
10705 | /* From varargs functions; gdb doesn't seem to have any | |
10706 | interest in this information, so just ignore it for now. | |
10707 | (FIXME?) */ | |
10708 | break; | |
34eaf542 TT |
10709 | case DW_TAG_template_type_param: |
10710 | suppress_add = 1; | |
10711 | /* Fall through. */ | |
c906108c | 10712 | case DW_TAG_class_type: |
680b30c7 | 10713 | case DW_TAG_interface_type: |
c906108c SS |
10714 | case DW_TAG_structure_type: |
10715 | case DW_TAG_union_type: | |
72019c9c | 10716 | case DW_TAG_set_type: |
c906108c SS |
10717 | case DW_TAG_enumeration_type: |
10718 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 10719 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 10720 | |
63d06c5c | 10721 | { |
987504bb | 10722 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
10723 | really ever be static objects: otherwise, if you try |
10724 | to, say, break of a class's method and you're in a file | |
10725 | which doesn't mention that class, it won't work unless | |
10726 | the check for all static symbols in lookup_symbol_aux | |
10727 | saves you. See the OtherFileClass tests in | |
10728 | gdb.c++/namespace.exp. */ | |
10729 | ||
e37fd15a | 10730 | if (!suppress_add) |
34eaf542 | 10731 | { |
34eaf542 TT |
10732 | list_to_add = (cu->list_in_scope == &file_symbols |
10733 | && (cu->language == language_cplus | |
10734 | || cu->language == language_java) | |
10735 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c | 10736 | |
64382290 TT |
10737 | /* The semantics of C++ state that "struct foo { |
10738 | ... }" also defines a typedef for "foo". A Java | |
10739 | class declaration also defines a typedef for the | |
10740 | class. */ | |
10741 | if (cu->language == language_cplus | |
10742 | || cu->language == language_java | |
10743 | || cu->language == language_ada) | |
10744 | { | |
10745 | /* The symbol's name is already allocated along | |
10746 | with this objfile, so we don't need to | |
10747 | duplicate it for the type. */ | |
10748 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) | |
10749 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); | |
10750 | } | |
63d06c5c DC |
10751 | } |
10752 | } | |
c906108c SS |
10753 | break; |
10754 | case DW_TAG_typedef: | |
63d06c5c DC |
10755 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
10756 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e37fd15a | 10757 | list_to_add = cu->list_in_scope; |
63d06c5c | 10758 | break; |
c906108c | 10759 | case DW_TAG_base_type: |
a02abb62 | 10760 | case DW_TAG_subrange_type: |
c906108c | 10761 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 10762 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e37fd15a | 10763 | list_to_add = cu->list_in_scope; |
c906108c SS |
10764 | break; |
10765 | case DW_TAG_enumerator: | |
e142c38c | 10766 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
10767 | if (attr) |
10768 | { | |
e7c27a73 | 10769 | dwarf2_const_value (attr, sym, cu); |
c906108c | 10770 | } |
63d06c5c DC |
10771 | { |
10772 | /* NOTE: carlton/2003-11-10: See comment above in the | |
10773 | DW_TAG_class_type, etc. block. */ | |
10774 | ||
e142c38c | 10775 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
10776 | && (cu->language == language_cplus |
10777 | || cu->language == language_java) | |
e142c38c | 10778 | ? &global_symbols : cu->list_in_scope); |
63d06c5c | 10779 | } |
c906108c | 10780 | break; |
5c4e30ca DC |
10781 | case DW_TAG_namespace: |
10782 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
e37fd15a | 10783 | list_to_add = &global_symbols; |
5c4e30ca | 10784 | break; |
c906108c SS |
10785 | default: |
10786 | /* Not a tag we recognize. Hopefully we aren't processing | |
10787 | trash data, but since we must specifically ignore things | |
10788 | we don't recognize, there is nothing else we should do at | |
10789 | this point. */ | |
e2e0b3e5 | 10790 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 10791 | dwarf_tag_name (die->tag)); |
c906108c SS |
10792 | break; |
10793 | } | |
df8a16a1 | 10794 | |
e37fd15a SW |
10795 | if (suppress_add) |
10796 | { | |
10797 | sym->hash_next = objfile->template_symbols; | |
10798 | objfile->template_symbols = sym; | |
10799 | list_to_add = NULL; | |
10800 | } | |
10801 | ||
10802 | if (list_to_add != NULL) | |
10803 | add_symbol_to_list (sym, list_to_add); | |
10804 | ||
df8a16a1 DJ |
10805 | /* For the benefit of old versions of GCC, check for anonymous |
10806 | namespaces based on the demangled name. */ | |
10807 | if (!processing_has_namespace_info | |
94af9270 | 10808 | && cu->language == language_cplus) |
df8a16a1 | 10809 | cp_scan_for_anonymous_namespaces (sym); |
c906108c SS |
10810 | } |
10811 | return (sym); | |
10812 | } | |
10813 | ||
34eaf542 TT |
10814 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
10815 | ||
10816 | static struct symbol * | |
10817 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
10818 | { | |
10819 | return new_symbol_full (die, type, cu, NULL); | |
10820 | } | |
10821 | ||
98bfdba5 PA |
10822 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
10823 | zero-extend it as appropriate for the symbol's type. The DWARF | |
10824 | standard (v4) is not entirely clear about the meaning of using | |
10825 | DW_FORM_dataN for a constant with a signed type, where the type is | |
10826 | wider than the data. The conclusion of a discussion on the DWARF | |
10827 | list was that this is unspecified. We choose to always zero-extend | |
10828 | because that is the interpretation long in use by GCC. */ | |
c906108c | 10829 | |
98bfdba5 PA |
10830 | static gdb_byte * |
10831 | dwarf2_const_value_data (struct attribute *attr, struct type *type, | |
10832 | const char *name, struct obstack *obstack, | |
10833 | struct dwarf2_cu *cu, long *value, int bits) | |
c906108c | 10834 | { |
e7c27a73 | 10835 | struct objfile *objfile = cu->objfile; |
e17a4113 UW |
10836 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
10837 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; | |
98bfdba5 PA |
10838 | LONGEST l = DW_UNSND (attr); |
10839 | ||
10840 | if (bits < sizeof (*value) * 8) | |
10841 | { | |
10842 | l &= ((LONGEST) 1 << bits) - 1; | |
10843 | *value = l; | |
10844 | } | |
10845 | else if (bits == sizeof (*value) * 8) | |
10846 | *value = l; | |
10847 | else | |
10848 | { | |
10849 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); | |
10850 | store_unsigned_integer (bytes, bits / 8, byte_order, l); | |
10851 | return bytes; | |
10852 | } | |
10853 | ||
10854 | return NULL; | |
10855 | } | |
10856 | ||
10857 | /* Read a constant value from an attribute. Either set *VALUE, or if | |
10858 | the value does not fit in *VALUE, set *BYTES - either already | |
10859 | allocated on the objfile obstack, or newly allocated on OBSTACK, | |
10860 | or, set *BATON, if we translated the constant to a location | |
10861 | expression. */ | |
10862 | ||
10863 | static void | |
10864 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, | |
10865 | const char *name, struct obstack *obstack, | |
10866 | struct dwarf2_cu *cu, | |
10867 | long *value, gdb_byte **bytes, | |
10868 | struct dwarf2_locexpr_baton **baton) | |
10869 | { | |
10870 | struct objfile *objfile = cu->objfile; | |
10871 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 10872 | struct dwarf_block *blk; |
98bfdba5 PA |
10873 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
10874 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); | |
10875 | ||
10876 | *value = 0; | |
10877 | *bytes = NULL; | |
10878 | *baton = NULL; | |
c906108c SS |
10879 | |
10880 | switch (attr->form) | |
10881 | { | |
10882 | case DW_FORM_addr: | |
ac56253d | 10883 | { |
ac56253d TT |
10884 | gdb_byte *data; |
10885 | ||
98bfdba5 PA |
10886 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
10887 | dwarf2_const_value_length_mismatch_complaint (name, | |
ac56253d | 10888 | cu_header->addr_size, |
98bfdba5 | 10889 | TYPE_LENGTH (type)); |
ac56253d TT |
10890 | /* Symbols of this form are reasonably rare, so we just |
10891 | piggyback on the existing location code rather than writing | |
10892 | a new implementation of symbol_computed_ops. */ | |
98bfdba5 PA |
10893 | *baton = obstack_alloc (&objfile->objfile_obstack, |
10894 | sizeof (struct dwarf2_locexpr_baton)); | |
10895 | (*baton)->per_cu = cu->per_cu; | |
10896 | gdb_assert ((*baton)->per_cu); | |
ac56253d | 10897 | |
98bfdba5 PA |
10898 | (*baton)->size = 2 + cu_header->addr_size; |
10899 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); | |
10900 | (*baton)->data = data; | |
ac56253d TT |
10901 | |
10902 | data[0] = DW_OP_addr; | |
10903 | store_unsigned_integer (&data[1], cu_header->addr_size, | |
10904 | byte_order, DW_ADDR (attr)); | |
10905 | data[cu_header->addr_size + 1] = DW_OP_stack_value; | |
ac56253d | 10906 | } |
c906108c | 10907 | break; |
4ac36638 | 10908 | case DW_FORM_string: |
93b5768b | 10909 | case DW_FORM_strp: |
98bfdba5 PA |
10910 | /* DW_STRING is already allocated on the objfile obstack, point |
10911 | directly to it. */ | |
10912 | *bytes = (gdb_byte *) DW_STRING (attr); | |
93b5768b | 10913 | break; |
c906108c SS |
10914 | case DW_FORM_block1: |
10915 | case DW_FORM_block2: | |
10916 | case DW_FORM_block4: | |
10917 | case DW_FORM_block: | |
2dc7f7b3 | 10918 | case DW_FORM_exprloc: |
c906108c | 10919 | blk = DW_BLOCK (attr); |
98bfdba5 PA |
10920 | if (TYPE_LENGTH (type) != blk->size) |
10921 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, | |
10922 | TYPE_LENGTH (type)); | |
10923 | *bytes = blk->data; | |
c906108c | 10924 | break; |
2df3850c JM |
10925 | |
10926 | /* The DW_AT_const_value attributes are supposed to carry the | |
10927 | symbol's value "represented as it would be on the target | |
10928 | architecture." By the time we get here, it's already been | |
10929 | converted to host endianness, so we just need to sign- or | |
10930 | zero-extend it as appropriate. */ | |
10931 | case DW_FORM_data1: | |
98bfdba5 | 10932 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 8); |
2df3850c | 10933 | break; |
c906108c | 10934 | case DW_FORM_data2: |
98bfdba5 | 10935 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 16); |
2df3850c | 10936 | break; |
c906108c | 10937 | case DW_FORM_data4: |
98bfdba5 | 10938 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 32); |
2df3850c | 10939 | break; |
c906108c | 10940 | case DW_FORM_data8: |
98bfdba5 | 10941 | *bytes = dwarf2_const_value_data (attr, type, name, obstack, cu, value, 64); |
2df3850c JM |
10942 | break; |
10943 | ||
c906108c | 10944 | case DW_FORM_sdata: |
98bfdba5 | 10945 | *value = DW_SND (attr); |
2df3850c JM |
10946 | break; |
10947 | ||
c906108c | 10948 | case DW_FORM_udata: |
98bfdba5 | 10949 | *value = DW_UNSND (attr); |
c906108c | 10950 | break; |
2df3850c | 10951 | |
c906108c | 10952 | default: |
4d3c2250 | 10953 | complaint (&symfile_complaints, |
e2e0b3e5 | 10954 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 10955 | dwarf_form_name (attr->form)); |
98bfdba5 | 10956 | *value = 0; |
c906108c SS |
10957 | break; |
10958 | } | |
10959 | } | |
10960 | ||
2df3850c | 10961 | |
98bfdba5 PA |
10962 | /* Copy constant value from an attribute to a symbol. */ |
10963 | ||
2df3850c | 10964 | static void |
98bfdba5 PA |
10965 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
10966 | struct dwarf2_cu *cu) | |
2df3850c | 10967 | { |
98bfdba5 PA |
10968 | struct objfile *objfile = cu->objfile; |
10969 | struct comp_unit_head *cu_header = &cu->header; | |
10970 | long value; | |
10971 | gdb_byte *bytes; | |
10972 | struct dwarf2_locexpr_baton *baton; | |
2df3850c | 10973 | |
98bfdba5 PA |
10974 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
10975 | SYMBOL_PRINT_NAME (sym), | |
10976 | &objfile->objfile_obstack, cu, | |
10977 | &value, &bytes, &baton); | |
2df3850c | 10978 | |
98bfdba5 PA |
10979 | if (baton != NULL) |
10980 | { | |
10981 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; | |
10982 | SYMBOL_LOCATION_BATON (sym) = baton; | |
10983 | SYMBOL_CLASS (sym) = LOC_COMPUTED; | |
10984 | } | |
10985 | else if (bytes != NULL) | |
10986 | { | |
10987 | SYMBOL_VALUE_BYTES (sym) = bytes; | |
10988 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
10989 | } | |
10990 | else | |
10991 | { | |
10992 | SYMBOL_VALUE (sym) = value; | |
10993 | SYMBOL_CLASS (sym) = LOC_CONST; | |
10994 | } | |
2df3850c JM |
10995 | } |
10996 | ||
c906108c SS |
10997 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
10998 | ||
10999 | static struct type * | |
e7c27a73 | 11000 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11001 | { |
c906108c | 11002 | struct attribute *type_attr; |
c906108c | 11003 | |
e142c38c | 11004 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
11005 | if (!type_attr) |
11006 | { | |
11007 | /* A missing DW_AT_type represents a void type. */ | |
46bf5051 | 11008 | return objfile_type (cu->objfile)->builtin_void; |
c906108c | 11009 | } |
348e048f | 11010 | |
673bfd45 | 11011 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11012 | } |
11013 | ||
b4ba55a1 JB |
11014 | /* True iff CU's producer generates GNAT Ada auxiliary information |
11015 | that allows to find parallel types through that information instead | |
11016 | of having to do expensive parallel lookups by type name. */ | |
11017 | ||
11018 | static int | |
11019 | need_gnat_info (struct dwarf2_cu *cu) | |
11020 | { | |
11021 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version | |
11022 | of GNAT produces this auxiliary information, without any indication | |
11023 | that it is produced. Part of enhancing the FSF version of GNAT | |
11024 | to produce that information will be to put in place an indicator | |
11025 | that we can use in order to determine whether the descriptive type | |
11026 | info is available or not. One suggestion that has been made is | |
11027 | to use a new attribute, attached to the CU die. For now, assume | |
11028 | that the descriptive type info is not available. */ | |
11029 | return 0; | |
11030 | } | |
11031 | ||
b4ba55a1 JB |
11032 | /* Return the auxiliary type of the die in question using its |
11033 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the | |
11034 | attribute is not present. */ | |
11035 | ||
11036 | static struct type * | |
11037 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) | |
11038 | { | |
b4ba55a1 | 11039 | struct attribute *type_attr; |
b4ba55a1 JB |
11040 | |
11041 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); | |
11042 | if (!type_attr) | |
11043 | return NULL; | |
11044 | ||
673bfd45 | 11045 | return lookup_die_type (die, type_attr, cu); |
b4ba55a1 JB |
11046 | } |
11047 | ||
11048 | /* If DIE has a descriptive_type attribute, then set the TYPE's | |
11049 | descriptive type accordingly. */ | |
11050 | ||
11051 | static void | |
11052 | set_descriptive_type (struct type *type, struct die_info *die, | |
11053 | struct dwarf2_cu *cu) | |
11054 | { | |
11055 | struct type *descriptive_type = die_descriptive_type (die, cu); | |
11056 | ||
11057 | if (descriptive_type) | |
11058 | { | |
11059 | ALLOCATE_GNAT_AUX_TYPE (type); | |
11060 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; | |
11061 | } | |
11062 | } | |
11063 | ||
c906108c SS |
11064 | /* Return the containing type of the die in question using its |
11065 | DW_AT_containing_type attribute. */ | |
11066 | ||
11067 | static struct type * | |
e7c27a73 | 11068 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11069 | { |
c906108c | 11070 | struct attribute *type_attr; |
c906108c | 11071 | |
e142c38c | 11072 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
33ac96f0 JK |
11073 | if (!type_attr) |
11074 | error (_("Dwarf Error: Problem turning containing type into gdb type " | |
11075 | "[in module %s]"), cu->objfile->name); | |
11076 | ||
673bfd45 | 11077 | return lookup_die_type (die, type_attr, cu); |
c906108c SS |
11078 | } |
11079 | ||
673bfd45 DE |
11080 | /* Look up the type of DIE in CU using its type attribute ATTR. |
11081 | If there is no type substitute an error marker. */ | |
11082 | ||
c906108c | 11083 | static struct type * |
673bfd45 DE |
11084 | lookup_die_type (struct die_info *die, struct attribute *attr, |
11085 | struct dwarf2_cu *cu) | |
c906108c | 11086 | { |
f792889a DJ |
11087 | struct type *this_type; |
11088 | ||
673bfd45 DE |
11089 | /* First see if we have it cached. */ |
11090 | ||
11091 | if (is_ref_attr (attr)) | |
11092 | { | |
11093 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
11094 | ||
11095 | this_type = get_die_type_at_offset (offset, cu->per_cu); | |
11096 | } | |
11097 | else if (attr->form == DW_FORM_sig8) | |
11098 | { | |
11099 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
11100 | struct dwarf2_cu *sig_cu; | |
11101 | unsigned int offset; | |
11102 | ||
11103 | /* sig_type will be NULL if the signatured type is missing from | |
11104 | the debug info. */ | |
11105 | if (sig_type == NULL) | |
11106 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
11107 | "at 0x%x [in module %s]"), | |
11108 | die->offset, cu->objfile->name); | |
11109 | ||
11110 | gdb_assert (sig_type->per_cu.from_debug_types); | |
11111 | offset = sig_type->offset + sig_type->type_offset; | |
11112 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); | |
11113 | } | |
11114 | else | |
11115 | { | |
11116 | dump_die_for_error (die); | |
11117 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), | |
11118 | dwarf_attr_name (attr->name), cu->objfile->name); | |
11119 | } | |
11120 | ||
11121 | /* If not cached we need to read it in. */ | |
11122 | ||
11123 | if (this_type == NULL) | |
11124 | { | |
11125 | struct die_info *type_die; | |
11126 | struct dwarf2_cu *type_cu = cu; | |
11127 | ||
11128 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); | |
11129 | /* If the type is cached, we should have found it above. */ | |
11130 | gdb_assert (get_die_type (type_die, type_cu) == NULL); | |
11131 | this_type = read_type_die_1 (type_die, type_cu); | |
11132 | } | |
11133 | ||
11134 | /* If we still don't have a type use an error marker. */ | |
11135 | ||
11136 | if (this_type == NULL) | |
c906108c | 11137 | { |
b00fdb78 TT |
11138 | char *message, *saved; |
11139 | ||
11140 | /* read_type_die already issued a complaint. */ | |
11141 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), | |
11142 | cu->objfile->name, | |
11143 | cu->header.offset, | |
11144 | die->offset); | |
11145 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, | |
11146 | message, strlen (message)); | |
11147 | xfree (message); | |
11148 | ||
11149 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); | |
c906108c | 11150 | } |
673bfd45 | 11151 | |
f792889a | 11152 | return this_type; |
c906108c SS |
11153 | } |
11154 | ||
673bfd45 DE |
11155 | /* Return the type in DIE, CU. |
11156 | Returns NULL for invalid types. | |
11157 | ||
11158 | This first does a lookup in the appropriate type_hash table, | |
11159 | and only reads the die in if necessary. | |
11160 | ||
11161 | NOTE: This can be called when reading in partial or full symbols. */ | |
11162 | ||
f792889a | 11163 | static struct type * |
e7c27a73 | 11164 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 11165 | { |
f792889a DJ |
11166 | struct type *this_type; |
11167 | ||
11168 | this_type = get_die_type (die, cu); | |
11169 | if (this_type) | |
11170 | return this_type; | |
11171 | ||
673bfd45 DE |
11172 | return read_type_die_1 (die, cu); |
11173 | } | |
11174 | ||
11175 | /* Read the type in DIE, CU. | |
11176 | Returns NULL for invalid types. */ | |
11177 | ||
11178 | static struct type * | |
11179 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) | |
11180 | { | |
11181 | struct type *this_type = NULL; | |
11182 | ||
c906108c SS |
11183 | switch (die->tag) |
11184 | { | |
11185 | case DW_TAG_class_type: | |
680b30c7 | 11186 | case DW_TAG_interface_type: |
c906108c SS |
11187 | case DW_TAG_structure_type: |
11188 | case DW_TAG_union_type: | |
f792889a | 11189 | this_type = read_structure_type (die, cu); |
c906108c SS |
11190 | break; |
11191 | case DW_TAG_enumeration_type: | |
f792889a | 11192 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
11193 | break; |
11194 | case DW_TAG_subprogram: | |
11195 | case DW_TAG_subroutine_type: | |
edb3359d | 11196 | case DW_TAG_inlined_subroutine: |
f792889a | 11197 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
11198 | break; |
11199 | case DW_TAG_array_type: | |
f792889a | 11200 | this_type = read_array_type (die, cu); |
c906108c | 11201 | break; |
72019c9c | 11202 | case DW_TAG_set_type: |
f792889a | 11203 | this_type = read_set_type (die, cu); |
72019c9c | 11204 | break; |
c906108c | 11205 | case DW_TAG_pointer_type: |
f792889a | 11206 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
11207 | break; |
11208 | case DW_TAG_ptr_to_member_type: | |
f792889a | 11209 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
11210 | break; |
11211 | case DW_TAG_reference_type: | |
f792889a | 11212 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
11213 | break; |
11214 | case DW_TAG_const_type: | |
f792889a | 11215 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
11216 | break; |
11217 | case DW_TAG_volatile_type: | |
f792889a | 11218 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
11219 | break; |
11220 | case DW_TAG_string_type: | |
f792889a | 11221 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
11222 | break; |
11223 | case DW_TAG_typedef: | |
f792889a | 11224 | this_type = read_typedef (die, cu); |
c906108c | 11225 | break; |
a02abb62 | 11226 | case DW_TAG_subrange_type: |
f792889a | 11227 | this_type = read_subrange_type (die, cu); |
a02abb62 | 11228 | break; |
c906108c | 11229 | case DW_TAG_base_type: |
f792889a | 11230 | this_type = read_base_type (die, cu); |
c906108c | 11231 | break; |
81a17f79 | 11232 | case DW_TAG_unspecified_type: |
f792889a | 11233 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 11234 | break; |
0114d602 DJ |
11235 | case DW_TAG_namespace: |
11236 | this_type = read_namespace_type (die, cu); | |
11237 | break; | |
f55ee35c JK |
11238 | case DW_TAG_module: |
11239 | this_type = read_module_type (die, cu); | |
11240 | break; | |
c906108c | 11241 | default: |
a1f5b845 | 11242 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 11243 | dwarf_tag_name (die->tag)); |
c906108c SS |
11244 | break; |
11245 | } | |
63d06c5c | 11246 | |
f792889a | 11247 | return this_type; |
63d06c5c DC |
11248 | } |
11249 | ||
fdde2d81 | 11250 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 11251 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 11252 | |
0114d602 DJ |
11253 | For example, if we're within the method foo() in the following |
11254 | code: | |
11255 | ||
11256 | namespace N { | |
11257 | class C { | |
11258 | void foo () { | |
11259 | } | |
11260 | }; | |
11261 | } | |
11262 | ||
11263 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
11264 | |
11265 | static char * | |
e142c38c | 11266 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 11267 | { |
0114d602 DJ |
11268 | struct die_info *parent, *spec_die; |
11269 | struct dwarf2_cu *spec_cu; | |
11270 | struct type *parent_type; | |
63d06c5c | 11271 | |
f55ee35c JK |
11272 | if (cu->language != language_cplus && cu->language != language_java |
11273 | && cu->language != language_fortran) | |
0114d602 DJ |
11274 | return ""; |
11275 | ||
11276 | /* We have to be careful in the presence of DW_AT_specification. | |
11277 | For example, with GCC 3.4, given the code | |
11278 | ||
11279 | namespace N { | |
11280 | void foo() { | |
11281 | // Definition of N::foo. | |
11282 | } | |
11283 | } | |
11284 | ||
11285 | then we'll have a tree of DIEs like this: | |
11286 | ||
11287 | 1: DW_TAG_compile_unit | |
11288 | 2: DW_TAG_namespace // N | |
11289 | 3: DW_TAG_subprogram // declaration of N::foo | |
11290 | 4: DW_TAG_subprogram // definition of N::foo | |
11291 | DW_AT_specification // refers to die #3 | |
11292 | ||
11293 | Thus, when processing die #4, we have to pretend that we're in | |
11294 | the context of its DW_AT_specification, namely the contex of die | |
11295 | #3. */ | |
11296 | spec_cu = cu; | |
11297 | spec_die = die_specification (die, &spec_cu); | |
11298 | if (spec_die == NULL) | |
11299 | parent = die->parent; | |
11300 | else | |
63d06c5c | 11301 | { |
0114d602 DJ |
11302 | parent = spec_die->parent; |
11303 | cu = spec_cu; | |
63d06c5c | 11304 | } |
0114d602 DJ |
11305 | |
11306 | if (parent == NULL) | |
11307 | return ""; | |
98bfdba5 PA |
11308 | else if (parent->building_fullname) |
11309 | { | |
11310 | const char *name; | |
11311 | const char *parent_name; | |
11312 | ||
11313 | /* It has been seen on RealView 2.2 built binaries, | |
11314 | DW_TAG_template_type_param types actually _defined_ as | |
11315 | children of the parent class: | |
11316 | ||
11317 | enum E {}; | |
11318 | template class <class Enum> Class{}; | |
11319 | Class<enum E> class_e; | |
11320 | ||
11321 | 1: DW_TAG_class_type (Class) | |
11322 | 2: DW_TAG_enumeration_type (E) | |
11323 | 3: DW_TAG_enumerator (enum1:0) | |
11324 | 3: DW_TAG_enumerator (enum2:1) | |
11325 | ... | |
11326 | 2: DW_TAG_template_type_param | |
11327 | DW_AT_type DW_FORM_ref_udata (E) | |
11328 | ||
11329 | Besides being broken debug info, it can put GDB into an | |
11330 | infinite loop. Consider: | |
11331 | ||
11332 | When we're building the full name for Class<E>, we'll start | |
11333 | at Class, and go look over its template type parameters, | |
11334 | finding E. We'll then try to build the full name of E, and | |
11335 | reach here. We're now trying to build the full name of E, | |
11336 | and look over the parent DIE for containing scope. In the | |
11337 | broken case, if we followed the parent DIE of E, we'd again | |
11338 | find Class, and once again go look at its template type | |
11339 | arguments, etc., etc. Simply don't consider such parent die | |
11340 | as source-level parent of this die (it can't be, the language | |
11341 | doesn't allow it), and break the loop here. */ | |
11342 | name = dwarf2_name (die, cu); | |
11343 | parent_name = dwarf2_name (parent, cu); | |
11344 | complaint (&symfile_complaints, | |
11345 | _("template param type '%s' defined within parent '%s'"), | |
11346 | name ? name : "<unknown>", | |
11347 | parent_name ? parent_name : "<unknown>"); | |
11348 | return ""; | |
11349 | } | |
63d06c5c | 11350 | else |
0114d602 DJ |
11351 | switch (parent->tag) |
11352 | { | |
63d06c5c | 11353 | case DW_TAG_namespace: |
0114d602 | 11354 | parent_type = read_type_die (parent, cu); |
acebe513 UW |
11355 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
11356 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. | |
11357 | Work around this problem here. */ | |
11358 | if (cu->language == language_cplus | |
11359 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) | |
11360 | return ""; | |
0114d602 DJ |
11361 | /* We give a name to even anonymous namespaces. */ |
11362 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 11363 | case DW_TAG_class_type: |
680b30c7 | 11364 | case DW_TAG_interface_type: |
63d06c5c | 11365 | case DW_TAG_structure_type: |
0114d602 | 11366 | case DW_TAG_union_type: |
f55ee35c | 11367 | case DW_TAG_module: |
0114d602 DJ |
11368 | parent_type = read_type_die (parent, cu); |
11369 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
11370 | return TYPE_TAG_NAME (parent_type); | |
11371 | else | |
11372 | /* An anonymous structure is only allowed non-static data | |
11373 | members; no typedefs, no member functions, et cetera. | |
11374 | So it does not need a prefix. */ | |
11375 | return ""; | |
63d06c5c | 11376 | default: |
8176b9b8 | 11377 | return determine_prefix (parent, cu); |
63d06c5c | 11378 | } |
63d06c5c DC |
11379 | } |
11380 | ||
987504bb JJ |
11381 | /* Return a newly-allocated string formed by concatenating PREFIX and |
11382 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
11383 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
11384 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
11385 | is used to determine the language and hence, the appropriate separator. */ | |
11386 | ||
f55ee35c | 11387 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
63d06c5c DC |
11388 | |
11389 | static char * | |
f55ee35c JK |
11390 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
11391 | int physname, struct dwarf2_cu *cu) | |
63d06c5c | 11392 | { |
f55ee35c | 11393 | const char *lead = ""; |
5c315b68 | 11394 | const char *sep; |
63d06c5c | 11395 | |
987504bb JJ |
11396 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
11397 | sep = ""; | |
11398 | else if (cu->language == language_java) | |
11399 | sep = "."; | |
f55ee35c JK |
11400 | else if (cu->language == language_fortran && physname) |
11401 | { | |
11402 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or | |
11403 | DW_AT_MIPS_linkage_name is preferred and used instead. */ | |
11404 | ||
11405 | lead = "__"; | |
11406 | sep = "_MOD_"; | |
11407 | } | |
987504bb JJ |
11408 | else |
11409 | sep = "::"; | |
63d06c5c | 11410 | |
6dd47d34 DE |
11411 | if (prefix == NULL) |
11412 | prefix = ""; | |
11413 | if (suffix == NULL) | |
11414 | suffix = ""; | |
11415 | ||
987504bb JJ |
11416 | if (obs == NULL) |
11417 | { | |
11418 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
9a619af0 | 11419 | |
f55ee35c JK |
11420 | strcpy (retval, lead); |
11421 | strcat (retval, prefix); | |
6dd47d34 DE |
11422 | strcat (retval, sep); |
11423 | strcat (retval, suffix); | |
63d06c5c DC |
11424 | return retval; |
11425 | } | |
987504bb JJ |
11426 | else |
11427 | { | |
11428 | /* We have an obstack. */ | |
f55ee35c | 11429 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
987504bb | 11430 | } |
63d06c5c DC |
11431 | } |
11432 | ||
c906108c SS |
11433 | /* Return sibling of die, NULL if no sibling. */ |
11434 | ||
f9aca02d | 11435 | static struct die_info * |
fba45db2 | 11436 | sibling_die (struct die_info *die) |
c906108c | 11437 | { |
639d11d3 | 11438 | return die->sibling; |
c906108c SS |
11439 | } |
11440 | ||
71c25dea TT |
11441 | /* Get name of a die, return NULL if not found. */ |
11442 | ||
11443 | static char * | |
11444 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
11445 | struct obstack *obstack) | |
11446 | { | |
11447 | if (name && cu->language == language_cplus) | |
11448 | { | |
11449 | char *canon_name = cp_canonicalize_string (name); | |
11450 | ||
11451 | if (canon_name != NULL) | |
11452 | { | |
11453 | if (strcmp (canon_name, name) != 0) | |
11454 | name = obsavestring (canon_name, strlen (canon_name), | |
11455 | obstack); | |
11456 | xfree (canon_name); | |
11457 | } | |
11458 | } | |
11459 | ||
11460 | return name; | |
c906108c SS |
11461 | } |
11462 | ||
9219021c DC |
11463 | /* Get name of a die, return NULL if not found. */ |
11464 | ||
11465 | static char * | |
e142c38c | 11466 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
11467 | { |
11468 | struct attribute *attr; | |
11469 | ||
e142c38c | 11470 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
11471 | if (!attr || !DW_STRING (attr)) |
11472 | return NULL; | |
11473 | ||
11474 | switch (die->tag) | |
11475 | { | |
11476 | case DW_TAG_compile_unit: | |
11477 | /* Compilation units have a DW_AT_name that is a filename, not | |
11478 | a source language identifier. */ | |
11479 | case DW_TAG_enumeration_type: | |
11480 | case DW_TAG_enumerator: | |
11481 | /* These tags always have simple identifiers already; no need | |
11482 | to canonicalize them. */ | |
11483 | return DW_STRING (attr); | |
907af001 | 11484 | |
418835cc KS |
11485 | case DW_TAG_subprogram: |
11486 | /* Java constructors will all be named "<init>", so return | |
11487 | the class name when we see this special case. */ | |
11488 | if (cu->language == language_java | |
11489 | && DW_STRING (attr) != NULL | |
11490 | && strcmp (DW_STRING (attr), "<init>") == 0) | |
11491 | { | |
11492 | struct dwarf2_cu *spec_cu = cu; | |
11493 | struct die_info *spec_die; | |
11494 | ||
11495 | /* GCJ will output '<init>' for Java constructor names. | |
11496 | For this special case, return the name of the parent class. */ | |
11497 | ||
11498 | /* GCJ may output suprogram DIEs with AT_specification set. | |
11499 | If so, use the name of the specified DIE. */ | |
11500 | spec_die = die_specification (die, &spec_cu); | |
11501 | if (spec_die != NULL) | |
11502 | return dwarf2_name (spec_die, spec_cu); | |
11503 | ||
11504 | do | |
11505 | { | |
11506 | die = die->parent; | |
11507 | if (die->tag == DW_TAG_class_type) | |
11508 | return dwarf2_name (die, cu); | |
11509 | } | |
11510 | while (die->tag != DW_TAG_compile_unit); | |
11511 | } | |
907af001 UW |
11512 | break; |
11513 | ||
11514 | case DW_TAG_class_type: | |
11515 | case DW_TAG_interface_type: | |
11516 | case DW_TAG_structure_type: | |
11517 | case DW_TAG_union_type: | |
11518 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed | |
11519 | structures or unions. These were of the form "._%d" in GCC 4.1, | |
11520 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 | |
11521 | and GCC 4.4. We work around this problem by ignoring these. */ | |
11522 | if (strncmp (DW_STRING (attr), "._", 2) == 0 | |
11523 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) | |
11524 | return NULL; | |
11525 | break; | |
11526 | ||
71c25dea | 11527 | default: |
907af001 UW |
11528 | break; |
11529 | } | |
11530 | ||
11531 | if (!DW_STRING_IS_CANONICAL (attr)) | |
11532 | { | |
11533 | DW_STRING (attr) | |
11534 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
11535 | &cu->objfile->objfile_obstack); | |
11536 | DW_STRING_IS_CANONICAL (attr) = 1; | |
71c25dea | 11537 | } |
907af001 | 11538 | return DW_STRING (attr); |
9219021c DC |
11539 | } |
11540 | ||
11541 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
11542 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
11543 | containing the return value on output. */ | |
9219021c DC |
11544 | |
11545 | static struct die_info * | |
f2f0e013 | 11546 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
11547 | { |
11548 | struct attribute *attr; | |
9219021c | 11549 | |
f2f0e013 | 11550 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
11551 | if (attr == NULL) |
11552 | return NULL; | |
11553 | ||
f2f0e013 | 11554 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
11555 | } |
11556 | ||
c906108c SS |
11557 | /* Convert a DIE tag into its string name. */ |
11558 | ||
11559 | static char * | |
aa1ee363 | 11560 | dwarf_tag_name (unsigned tag) |
c906108c SS |
11561 | { |
11562 | switch (tag) | |
11563 | { | |
11564 | case DW_TAG_padding: | |
11565 | return "DW_TAG_padding"; | |
11566 | case DW_TAG_array_type: | |
11567 | return "DW_TAG_array_type"; | |
11568 | case DW_TAG_class_type: | |
11569 | return "DW_TAG_class_type"; | |
11570 | case DW_TAG_entry_point: | |
11571 | return "DW_TAG_entry_point"; | |
11572 | case DW_TAG_enumeration_type: | |
11573 | return "DW_TAG_enumeration_type"; | |
11574 | case DW_TAG_formal_parameter: | |
11575 | return "DW_TAG_formal_parameter"; | |
11576 | case DW_TAG_imported_declaration: | |
11577 | return "DW_TAG_imported_declaration"; | |
11578 | case DW_TAG_label: | |
11579 | return "DW_TAG_label"; | |
11580 | case DW_TAG_lexical_block: | |
11581 | return "DW_TAG_lexical_block"; | |
11582 | case DW_TAG_member: | |
11583 | return "DW_TAG_member"; | |
11584 | case DW_TAG_pointer_type: | |
11585 | return "DW_TAG_pointer_type"; | |
11586 | case DW_TAG_reference_type: | |
11587 | return "DW_TAG_reference_type"; | |
11588 | case DW_TAG_compile_unit: | |
11589 | return "DW_TAG_compile_unit"; | |
11590 | case DW_TAG_string_type: | |
11591 | return "DW_TAG_string_type"; | |
11592 | case DW_TAG_structure_type: | |
11593 | return "DW_TAG_structure_type"; | |
11594 | case DW_TAG_subroutine_type: | |
11595 | return "DW_TAG_subroutine_type"; | |
11596 | case DW_TAG_typedef: | |
11597 | return "DW_TAG_typedef"; | |
11598 | case DW_TAG_union_type: | |
11599 | return "DW_TAG_union_type"; | |
11600 | case DW_TAG_unspecified_parameters: | |
11601 | return "DW_TAG_unspecified_parameters"; | |
11602 | case DW_TAG_variant: | |
11603 | return "DW_TAG_variant"; | |
11604 | case DW_TAG_common_block: | |
11605 | return "DW_TAG_common_block"; | |
11606 | case DW_TAG_common_inclusion: | |
11607 | return "DW_TAG_common_inclusion"; | |
11608 | case DW_TAG_inheritance: | |
11609 | return "DW_TAG_inheritance"; | |
11610 | case DW_TAG_inlined_subroutine: | |
11611 | return "DW_TAG_inlined_subroutine"; | |
11612 | case DW_TAG_module: | |
11613 | return "DW_TAG_module"; | |
11614 | case DW_TAG_ptr_to_member_type: | |
11615 | return "DW_TAG_ptr_to_member_type"; | |
11616 | case DW_TAG_set_type: | |
11617 | return "DW_TAG_set_type"; | |
11618 | case DW_TAG_subrange_type: | |
11619 | return "DW_TAG_subrange_type"; | |
11620 | case DW_TAG_with_stmt: | |
11621 | return "DW_TAG_with_stmt"; | |
11622 | case DW_TAG_access_declaration: | |
11623 | return "DW_TAG_access_declaration"; | |
11624 | case DW_TAG_base_type: | |
11625 | return "DW_TAG_base_type"; | |
11626 | case DW_TAG_catch_block: | |
11627 | return "DW_TAG_catch_block"; | |
11628 | case DW_TAG_const_type: | |
11629 | return "DW_TAG_const_type"; | |
11630 | case DW_TAG_constant: | |
11631 | return "DW_TAG_constant"; | |
11632 | case DW_TAG_enumerator: | |
11633 | return "DW_TAG_enumerator"; | |
11634 | case DW_TAG_file_type: | |
11635 | return "DW_TAG_file_type"; | |
11636 | case DW_TAG_friend: | |
11637 | return "DW_TAG_friend"; | |
11638 | case DW_TAG_namelist: | |
11639 | return "DW_TAG_namelist"; | |
11640 | case DW_TAG_namelist_item: | |
11641 | return "DW_TAG_namelist_item"; | |
11642 | case DW_TAG_packed_type: | |
11643 | return "DW_TAG_packed_type"; | |
11644 | case DW_TAG_subprogram: | |
11645 | return "DW_TAG_subprogram"; | |
11646 | case DW_TAG_template_type_param: | |
11647 | return "DW_TAG_template_type_param"; | |
11648 | case DW_TAG_template_value_param: | |
11649 | return "DW_TAG_template_value_param"; | |
11650 | case DW_TAG_thrown_type: | |
11651 | return "DW_TAG_thrown_type"; | |
11652 | case DW_TAG_try_block: | |
11653 | return "DW_TAG_try_block"; | |
11654 | case DW_TAG_variant_part: | |
11655 | return "DW_TAG_variant_part"; | |
11656 | case DW_TAG_variable: | |
11657 | return "DW_TAG_variable"; | |
11658 | case DW_TAG_volatile_type: | |
11659 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
11660 | case DW_TAG_dwarf_procedure: |
11661 | return "DW_TAG_dwarf_procedure"; | |
11662 | case DW_TAG_restrict_type: | |
11663 | return "DW_TAG_restrict_type"; | |
11664 | case DW_TAG_interface_type: | |
11665 | return "DW_TAG_interface_type"; | |
11666 | case DW_TAG_namespace: | |
11667 | return "DW_TAG_namespace"; | |
11668 | case DW_TAG_imported_module: | |
11669 | return "DW_TAG_imported_module"; | |
11670 | case DW_TAG_unspecified_type: | |
11671 | return "DW_TAG_unspecified_type"; | |
11672 | case DW_TAG_partial_unit: | |
11673 | return "DW_TAG_partial_unit"; | |
11674 | case DW_TAG_imported_unit: | |
11675 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
11676 | case DW_TAG_condition: |
11677 | return "DW_TAG_condition"; | |
11678 | case DW_TAG_shared_type: | |
11679 | return "DW_TAG_shared_type"; | |
348e048f DE |
11680 | case DW_TAG_type_unit: |
11681 | return "DW_TAG_type_unit"; | |
c906108c SS |
11682 | case DW_TAG_MIPS_loop: |
11683 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
11684 | case DW_TAG_HP_array_descriptor: |
11685 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
11686 | case DW_TAG_format_label: |
11687 | return "DW_TAG_format_label"; | |
11688 | case DW_TAG_function_template: | |
11689 | return "DW_TAG_function_template"; | |
11690 | case DW_TAG_class_template: | |
11691 | return "DW_TAG_class_template"; | |
b7619582 GF |
11692 | case DW_TAG_GNU_BINCL: |
11693 | return "DW_TAG_GNU_BINCL"; | |
11694 | case DW_TAG_GNU_EINCL: | |
11695 | return "DW_TAG_GNU_EINCL"; | |
11696 | case DW_TAG_upc_shared_type: | |
11697 | return "DW_TAG_upc_shared_type"; | |
11698 | case DW_TAG_upc_strict_type: | |
11699 | return "DW_TAG_upc_strict_type"; | |
11700 | case DW_TAG_upc_relaxed_type: | |
11701 | return "DW_TAG_upc_relaxed_type"; | |
11702 | case DW_TAG_PGI_kanji_type: | |
11703 | return "DW_TAG_PGI_kanji_type"; | |
11704 | case DW_TAG_PGI_interface_block: | |
11705 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
11706 | default: |
11707 | return "DW_TAG_<unknown>"; | |
11708 | } | |
11709 | } | |
11710 | ||
11711 | /* Convert a DWARF attribute code into its string name. */ | |
11712 | ||
11713 | static char * | |
aa1ee363 | 11714 | dwarf_attr_name (unsigned attr) |
c906108c SS |
11715 | { |
11716 | switch (attr) | |
11717 | { | |
11718 | case DW_AT_sibling: | |
11719 | return "DW_AT_sibling"; | |
11720 | case DW_AT_location: | |
11721 | return "DW_AT_location"; | |
11722 | case DW_AT_name: | |
11723 | return "DW_AT_name"; | |
11724 | case DW_AT_ordering: | |
11725 | return "DW_AT_ordering"; | |
11726 | case DW_AT_subscr_data: | |
11727 | return "DW_AT_subscr_data"; | |
11728 | case DW_AT_byte_size: | |
11729 | return "DW_AT_byte_size"; | |
11730 | case DW_AT_bit_offset: | |
11731 | return "DW_AT_bit_offset"; | |
11732 | case DW_AT_bit_size: | |
11733 | return "DW_AT_bit_size"; | |
11734 | case DW_AT_element_list: | |
11735 | return "DW_AT_element_list"; | |
11736 | case DW_AT_stmt_list: | |
11737 | return "DW_AT_stmt_list"; | |
11738 | case DW_AT_low_pc: | |
11739 | return "DW_AT_low_pc"; | |
11740 | case DW_AT_high_pc: | |
11741 | return "DW_AT_high_pc"; | |
11742 | case DW_AT_language: | |
11743 | return "DW_AT_language"; | |
11744 | case DW_AT_member: | |
11745 | return "DW_AT_member"; | |
11746 | case DW_AT_discr: | |
11747 | return "DW_AT_discr"; | |
11748 | case DW_AT_discr_value: | |
11749 | return "DW_AT_discr_value"; | |
11750 | case DW_AT_visibility: | |
11751 | return "DW_AT_visibility"; | |
11752 | case DW_AT_import: | |
11753 | return "DW_AT_import"; | |
11754 | case DW_AT_string_length: | |
11755 | return "DW_AT_string_length"; | |
11756 | case DW_AT_common_reference: | |
11757 | return "DW_AT_common_reference"; | |
11758 | case DW_AT_comp_dir: | |
11759 | return "DW_AT_comp_dir"; | |
11760 | case DW_AT_const_value: | |
11761 | return "DW_AT_const_value"; | |
11762 | case DW_AT_containing_type: | |
11763 | return "DW_AT_containing_type"; | |
11764 | case DW_AT_default_value: | |
11765 | return "DW_AT_default_value"; | |
11766 | case DW_AT_inline: | |
11767 | return "DW_AT_inline"; | |
11768 | case DW_AT_is_optional: | |
11769 | return "DW_AT_is_optional"; | |
11770 | case DW_AT_lower_bound: | |
11771 | return "DW_AT_lower_bound"; | |
11772 | case DW_AT_producer: | |
11773 | return "DW_AT_producer"; | |
11774 | case DW_AT_prototyped: | |
11775 | return "DW_AT_prototyped"; | |
11776 | case DW_AT_return_addr: | |
11777 | return "DW_AT_return_addr"; | |
11778 | case DW_AT_start_scope: | |
11779 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
11780 | case DW_AT_bit_stride: |
11781 | return "DW_AT_bit_stride"; | |
c906108c SS |
11782 | case DW_AT_upper_bound: |
11783 | return "DW_AT_upper_bound"; | |
11784 | case DW_AT_abstract_origin: | |
11785 | return "DW_AT_abstract_origin"; | |
11786 | case DW_AT_accessibility: | |
11787 | return "DW_AT_accessibility"; | |
11788 | case DW_AT_address_class: | |
11789 | return "DW_AT_address_class"; | |
11790 | case DW_AT_artificial: | |
11791 | return "DW_AT_artificial"; | |
11792 | case DW_AT_base_types: | |
11793 | return "DW_AT_base_types"; | |
11794 | case DW_AT_calling_convention: | |
11795 | return "DW_AT_calling_convention"; | |
11796 | case DW_AT_count: | |
11797 | return "DW_AT_count"; | |
11798 | case DW_AT_data_member_location: | |
11799 | return "DW_AT_data_member_location"; | |
11800 | case DW_AT_decl_column: | |
11801 | return "DW_AT_decl_column"; | |
11802 | case DW_AT_decl_file: | |
11803 | return "DW_AT_decl_file"; | |
11804 | case DW_AT_decl_line: | |
11805 | return "DW_AT_decl_line"; | |
11806 | case DW_AT_declaration: | |
11807 | return "DW_AT_declaration"; | |
11808 | case DW_AT_discr_list: | |
11809 | return "DW_AT_discr_list"; | |
11810 | case DW_AT_encoding: | |
11811 | return "DW_AT_encoding"; | |
11812 | case DW_AT_external: | |
11813 | return "DW_AT_external"; | |
11814 | case DW_AT_frame_base: | |
11815 | return "DW_AT_frame_base"; | |
11816 | case DW_AT_friend: | |
11817 | return "DW_AT_friend"; | |
11818 | case DW_AT_identifier_case: | |
11819 | return "DW_AT_identifier_case"; | |
11820 | case DW_AT_macro_info: | |
11821 | return "DW_AT_macro_info"; | |
11822 | case DW_AT_namelist_items: | |
11823 | return "DW_AT_namelist_items"; | |
11824 | case DW_AT_priority: | |
11825 | return "DW_AT_priority"; | |
11826 | case DW_AT_segment: | |
11827 | return "DW_AT_segment"; | |
11828 | case DW_AT_specification: | |
11829 | return "DW_AT_specification"; | |
11830 | case DW_AT_static_link: | |
11831 | return "DW_AT_static_link"; | |
11832 | case DW_AT_type: | |
11833 | return "DW_AT_type"; | |
11834 | case DW_AT_use_location: | |
11835 | return "DW_AT_use_location"; | |
11836 | case DW_AT_variable_parameter: | |
11837 | return "DW_AT_variable_parameter"; | |
11838 | case DW_AT_virtuality: | |
11839 | return "DW_AT_virtuality"; | |
11840 | case DW_AT_vtable_elem_location: | |
11841 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 11842 | /* DWARF 3 values. */ |
d9fa45fe DC |
11843 | case DW_AT_allocated: |
11844 | return "DW_AT_allocated"; | |
11845 | case DW_AT_associated: | |
11846 | return "DW_AT_associated"; | |
11847 | case DW_AT_data_location: | |
11848 | return "DW_AT_data_location"; | |
09fa0d7c JK |
11849 | case DW_AT_byte_stride: |
11850 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
11851 | case DW_AT_entry_pc: |
11852 | return "DW_AT_entry_pc"; | |
11853 | case DW_AT_use_UTF8: | |
11854 | return "DW_AT_use_UTF8"; | |
11855 | case DW_AT_extension: | |
11856 | return "DW_AT_extension"; | |
11857 | case DW_AT_ranges: | |
11858 | return "DW_AT_ranges"; | |
11859 | case DW_AT_trampoline: | |
11860 | return "DW_AT_trampoline"; | |
11861 | case DW_AT_call_column: | |
11862 | return "DW_AT_call_column"; | |
11863 | case DW_AT_call_file: | |
11864 | return "DW_AT_call_file"; | |
11865 | case DW_AT_call_line: | |
11866 | return "DW_AT_call_line"; | |
b7619582 GF |
11867 | case DW_AT_description: |
11868 | return "DW_AT_description"; | |
11869 | case DW_AT_binary_scale: | |
11870 | return "DW_AT_binary_scale"; | |
11871 | case DW_AT_decimal_scale: | |
11872 | return "DW_AT_decimal_scale"; | |
11873 | case DW_AT_small: | |
11874 | return "DW_AT_small"; | |
11875 | case DW_AT_decimal_sign: | |
11876 | return "DW_AT_decimal_sign"; | |
11877 | case DW_AT_digit_count: | |
11878 | return "DW_AT_digit_count"; | |
11879 | case DW_AT_picture_string: | |
11880 | return "DW_AT_picture_string"; | |
11881 | case DW_AT_mutable: | |
11882 | return "DW_AT_mutable"; | |
11883 | case DW_AT_threads_scaled: | |
11884 | return "DW_AT_threads_scaled"; | |
11885 | case DW_AT_explicit: | |
11886 | return "DW_AT_explicit"; | |
11887 | case DW_AT_object_pointer: | |
11888 | return "DW_AT_object_pointer"; | |
11889 | case DW_AT_endianity: | |
11890 | return "DW_AT_endianity"; | |
11891 | case DW_AT_elemental: | |
11892 | return "DW_AT_elemental"; | |
11893 | case DW_AT_pure: | |
11894 | return "DW_AT_pure"; | |
11895 | case DW_AT_recursive: | |
11896 | return "DW_AT_recursive"; | |
348e048f DE |
11897 | /* DWARF 4 values. */ |
11898 | case DW_AT_signature: | |
11899 | return "DW_AT_signature"; | |
31ef98ae TT |
11900 | case DW_AT_linkage_name: |
11901 | return "DW_AT_linkage_name"; | |
b7619582 | 11902 | /* SGI/MIPS extensions. */ |
c764a876 | 11903 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
11904 | case DW_AT_MIPS_fde: |
11905 | return "DW_AT_MIPS_fde"; | |
c764a876 | 11906 | #endif |
c906108c SS |
11907 | case DW_AT_MIPS_loop_begin: |
11908 | return "DW_AT_MIPS_loop_begin"; | |
11909 | case DW_AT_MIPS_tail_loop_begin: | |
11910 | return "DW_AT_MIPS_tail_loop_begin"; | |
11911 | case DW_AT_MIPS_epilog_begin: | |
11912 | return "DW_AT_MIPS_epilog_begin"; | |
11913 | case DW_AT_MIPS_loop_unroll_factor: | |
11914 | return "DW_AT_MIPS_loop_unroll_factor"; | |
11915 | case DW_AT_MIPS_software_pipeline_depth: | |
11916 | return "DW_AT_MIPS_software_pipeline_depth"; | |
11917 | case DW_AT_MIPS_linkage_name: | |
11918 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
11919 | case DW_AT_MIPS_stride: |
11920 | return "DW_AT_MIPS_stride"; | |
11921 | case DW_AT_MIPS_abstract_name: | |
11922 | return "DW_AT_MIPS_abstract_name"; | |
11923 | case DW_AT_MIPS_clone_origin: | |
11924 | return "DW_AT_MIPS_clone_origin"; | |
11925 | case DW_AT_MIPS_has_inlines: | |
11926 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 11927 | /* HP extensions. */ |
c764a876 | 11928 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
11929 | case DW_AT_HP_block_index: |
11930 | return "DW_AT_HP_block_index"; | |
c764a876 | 11931 | #endif |
b7619582 GF |
11932 | case DW_AT_HP_unmodifiable: |
11933 | return "DW_AT_HP_unmodifiable"; | |
11934 | case DW_AT_HP_actuals_stmt_list: | |
11935 | return "DW_AT_HP_actuals_stmt_list"; | |
11936 | case DW_AT_HP_proc_per_section: | |
11937 | return "DW_AT_HP_proc_per_section"; | |
11938 | case DW_AT_HP_raw_data_ptr: | |
11939 | return "DW_AT_HP_raw_data_ptr"; | |
11940 | case DW_AT_HP_pass_by_reference: | |
11941 | return "DW_AT_HP_pass_by_reference"; | |
11942 | case DW_AT_HP_opt_level: | |
11943 | return "DW_AT_HP_opt_level"; | |
11944 | case DW_AT_HP_prof_version_id: | |
11945 | return "DW_AT_HP_prof_version_id"; | |
11946 | case DW_AT_HP_opt_flags: | |
11947 | return "DW_AT_HP_opt_flags"; | |
11948 | case DW_AT_HP_cold_region_low_pc: | |
11949 | return "DW_AT_HP_cold_region_low_pc"; | |
11950 | case DW_AT_HP_cold_region_high_pc: | |
11951 | return "DW_AT_HP_cold_region_high_pc"; | |
11952 | case DW_AT_HP_all_variables_modifiable: | |
11953 | return "DW_AT_HP_all_variables_modifiable"; | |
11954 | case DW_AT_HP_linkage_name: | |
11955 | return "DW_AT_HP_linkage_name"; | |
11956 | case DW_AT_HP_prof_flags: | |
11957 | return "DW_AT_HP_prof_flags"; | |
11958 | /* GNU extensions. */ | |
c906108c SS |
11959 | case DW_AT_sf_names: |
11960 | return "DW_AT_sf_names"; | |
11961 | case DW_AT_src_info: | |
11962 | return "DW_AT_src_info"; | |
11963 | case DW_AT_mac_info: | |
11964 | return "DW_AT_mac_info"; | |
11965 | case DW_AT_src_coords: | |
11966 | return "DW_AT_src_coords"; | |
11967 | case DW_AT_body_begin: | |
11968 | return "DW_AT_body_begin"; | |
11969 | case DW_AT_body_end: | |
11970 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
11971 | case DW_AT_GNU_vector: |
11972 | return "DW_AT_GNU_vector"; | |
2de00c64 DE |
11973 | case DW_AT_GNU_odr_signature: |
11974 | return "DW_AT_GNU_odr_signature"; | |
b7619582 GF |
11975 | /* VMS extensions. */ |
11976 | case DW_AT_VMS_rtnbeg_pd_address: | |
11977 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
11978 | /* UPC extension. */ | |
11979 | case DW_AT_upc_threads_scaled: | |
11980 | return "DW_AT_upc_threads_scaled"; | |
11981 | /* PGI (STMicroelectronics) extensions. */ | |
11982 | case DW_AT_PGI_lbase: | |
11983 | return "DW_AT_PGI_lbase"; | |
11984 | case DW_AT_PGI_soffset: | |
11985 | return "DW_AT_PGI_soffset"; | |
11986 | case DW_AT_PGI_lstride: | |
11987 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
11988 | default: |
11989 | return "DW_AT_<unknown>"; | |
11990 | } | |
11991 | } | |
11992 | ||
11993 | /* Convert a DWARF value form code into its string name. */ | |
11994 | ||
11995 | static char * | |
aa1ee363 | 11996 | dwarf_form_name (unsigned form) |
c906108c SS |
11997 | { |
11998 | switch (form) | |
11999 | { | |
12000 | case DW_FORM_addr: | |
12001 | return "DW_FORM_addr"; | |
12002 | case DW_FORM_block2: | |
12003 | return "DW_FORM_block2"; | |
12004 | case DW_FORM_block4: | |
12005 | return "DW_FORM_block4"; | |
12006 | case DW_FORM_data2: | |
12007 | return "DW_FORM_data2"; | |
12008 | case DW_FORM_data4: | |
12009 | return "DW_FORM_data4"; | |
12010 | case DW_FORM_data8: | |
12011 | return "DW_FORM_data8"; | |
12012 | case DW_FORM_string: | |
12013 | return "DW_FORM_string"; | |
12014 | case DW_FORM_block: | |
12015 | return "DW_FORM_block"; | |
12016 | case DW_FORM_block1: | |
12017 | return "DW_FORM_block1"; | |
12018 | case DW_FORM_data1: | |
12019 | return "DW_FORM_data1"; | |
12020 | case DW_FORM_flag: | |
12021 | return "DW_FORM_flag"; | |
12022 | case DW_FORM_sdata: | |
12023 | return "DW_FORM_sdata"; | |
12024 | case DW_FORM_strp: | |
12025 | return "DW_FORM_strp"; | |
12026 | case DW_FORM_udata: | |
12027 | return "DW_FORM_udata"; | |
12028 | case DW_FORM_ref_addr: | |
12029 | return "DW_FORM_ref_addr"; | |
12030 | case DW_FORM_ref1: | |
12031 | return "DW_FORM_ref1"; | |
12032 | case DW_FORM_ref2: | |
12033 | return "DW_FORM_ref2"; | |
12034 | case DW_FORM_ref4: | |
12035 | return "DW_FORM_ref4"; | |
12036 | case DW_FORM_ref8: | |
12037 | return "DW_FORM_ref8"; | |
12038 | case DW_FORM_ref_udata: | |
12039 | return "DW_FORM_ref_udata"; | |
12040 | case DW_FORM_indirect: | |
12041 | return "DW_FORM_indirect"; | |
348e048f DE |
12042 | case DW_FORM_sec_offset: |
12043 | return "DW_FORM_sec_offset"; | |
12044 | case DW_FORM_exprloc: | |
12045 | return "DW_FORM_exprloc"; | |
12046 | case DW_FORM_flag_present: | |
12047 | return "DW_FORM_flag_present"; | |
12048 | case DW_FORM_sig8: | |
12049 | return "DW_FORM_sig8"; | |
c906108c SS |
12050 | default: |
12051 | return "DW_FORM_<unknown>"; | |
12052 | } | |
12053 | } | |
12054 | ||
12055 | /* Convert a DWARF stack opcode into its string name. */ | |
12056 | ||
9eae7c52 TT |
12057 | const char * |
12058 | dwarf_stack_op_name (unsigned op, int def) | |
c906108c SS |
12059 | { |
12060 | switch (op) | |
12061 | { | |
12062 | case DW_OP_addr: | |
12063 | return "DW_OP_addr"; | |
12064 | case DW_OP_deref: | |
12065 | return "DW_OP_deref"; | |
12066 | case DW_OP_const1u: | |
12067 | return "DW_OP_const1u"; | |
12068 | case DW_OP_const1s: | |
12069 | return "DW_OP_const1s"; | |
12070 | case DW_OP_const2u: | |
12071 | return "DW_OP_const2u"; | |
12072 | case DW_OP_const2s: | |
12073 | return "DW_OP_const2s"; | |
12074 | case DW_OP_const4u: | |
12075 | return "DW_OP_const4u"; | |
12076 | case DW_OP_const4s: | |
12077 | return "DW_OP_const4s"; | |
12078 | case DW_OP_const8u: | |
12079 | return "DW_OP_const8u"; | |
12080 | case DW_OP_const8s: | |
12081 | return "DW_OP_const8s"; | |
12082 | case DW_OP_constu: | |
12083 | return "DW_OP_constu"; | |
12084 | case DW_OP_consts: | |
12085 | return "DW_OP_consts"; | |
12086 | case DW_OP_dup: | |
12087 | return "DW_OP_dup"; | |
12088 | case DW_OP_drop: | |
12089 | return "DW_OP_drop"; | |
12090 | case DW_OP_over: | |
12091 | return "DW_OP_over"; | |
12092 | case DW_OP_pick: | |
12093 | return "DW_OP_pick"; | |
12094 | case DW_OP_swap: | |
12095 | return "DW_OP_swap"; | |
12096 | case DW_OP_rot: | |
12097 | return "DW_OP_rot"; | |
12098 | case DW_OP_xderef: | |
12099 | return "DW_OP_xderef"; | |
12100 | case DW_OP_abs: | |
12101 | return "DW_OP_abs"; | |
12102 | case DW_OP_and: | |
12103 | return "DW_OP_and"; | |
12104 | case DW_OP_div: | |
12105 | return "DW_OP_div"; | |
12106 | case DW_OP_minus: | |
12107 | return "DW_OP_minus"; | |
12108 | case DW_OP_mod: | |
12109 | return "DW_OP_mod"; | |
12110 | case DW_OP_mul: | |
12111 | return "DW_OP_mul"; | |
12112 | case DW_OP_neg: | |
12113 | return "DW_OP_neg"; | |
12114 | case DW_OP_not: | |
12115 | return "DW_OP_not"; | |
12116 | case DW_OP_or: | |
12117 | return "DW_OP_or"; | |
12118 | case DW_OP_plus: | |
12119 | return "DW_OP_plus"; | |
12120 | case DW_OP_plus_uconst: | |
12121 | return "DW_OP_plus_uconst"; | |
12122 | case DW_OP_shl: | |
12123 | return "DW_OP_shl"; | |
12124 | case DW_OP_shr: | |
12125 | return "DW_OP_shr"; | |
12126 | case DW_OP_shra: | |
12127 | return "DW_OP_shra"; | |
12128 | case DW_OP_xor: | |
12129 | return "DW_OP_xor"; | |
12130 | case DW_OP_bra: | |
12131 | return "DW_OP_bra"; | |
12132 | case DW_OP_eq: | |
12133 | return "DW_OP_eq"; | |
12134 | case DW_OP_ge: | |
12135 | return "DW_OP_ge"; | |
12136 | case DW_OP_gt: | |
12137 | return "DW_OP_gt"; | |
12138 | case DW_OP_le: | |
12139 | return "DW_OP_le"; | |
12140 | case DW_OP_lt: | |
12141 | return "DW_OP_lt"; | |
12142 | case DW_OP_ne: | |
12143 | return "DW_OP_ne"; | |
12144 | case DW_OP_skip: | |
12145 | return "DW_OP_skip"; | |
12146 | case DW_OP_lit0: | |
12147 | return "DW_OP_lit0"; | |
12148 | case DW_OP_lit1: | |
12149 | return "DW_OP_lit1"; | |
12150 | case DW_OP_lit2: | |
12151 | return "DW_OP_lit2"; | |
12152 | case DW_OP_lit3: | |
12153 | return "DW_OP_lit3"; | |
12154 | case DW_OP_lit4: | |
12155 | return "DW_OP_lit4"; | |
12156 | case DW_OP_lit5: | |
12157 | return "DW_OP_lit5"; | |
12158 | case DW_OP_lit6: | |
12159 | return "DW_OP_lit6"; | |
12160 | case DW_OP_lit7: | |
12161 | return "DW_OP_lit7"; | |
12162 | case DW_OP_lit8: | |
12163 | return "DW_OP_lit8"; | |
12164 | case DW_OP_lit9: | |
12165 | return "DW_OP_lit9"; | |
12166 | case DW_OP_lit10: | |
12167 | return "DW_OP_lit10"; | |
12168 | case DW_OP_lit11: | |
12169 | return "DW_OP_lit11"; | |
12170 | case DW_OP_lit12: | |
12171 | return "DW_OP_lit12"; | |
12172 | case DW_OP_lit13: | |
12173 | return "DW_OP_lit13"; | |
12174 | case DW_OP_lit14: | |
12175 | return "DW_OP_lit14"; | |
12176 | case DW_OP_lit15: | |
12177 | return "DW_OP_lit15"; | |
12178 | case DW_OP_lit16: | |
12179 | return "DW_OP_lit16"; | |
12180 | case DW_OP_lit17: | |
12181 | return "DW_OP_lit17"; | |
12182 | case DW_OP_lit18: | |
12183 | return "DW_OP_lit18"; | |
12184 | case DW_OP_lit19: | |
12185 | return "DW_OP_lit19"; | |
12186 | case DW_OP_lit20: | |
12187 | return "DW_OP_lit20"; | |
12188 | case DW_OP_lit21: | |
12189 | return "DW_OP_lit21"; | |
12190 | case DW_OP_lit22: | |
12191 | return "DW_OP_lit22"; | |
12192 | case DW_OP_lit23: | |
12193 | return "DW_OP_lit23"; | |
12194 | case DW_OP_lit24: | |
12195 | return "DW_OP_lit24"; | |
12196 | case DW_OP_lit25: | |
12197 | return "DW_OP_lit25"; | |
12198 | case DW_OP_lit26: | |
12199 | return "DW_OP_lit26"; | |
12200 | case DW_OP_lit27: | |
12201 | return "DW_OP_lit27"; | |
12202 | case DW_OP_lit28: | |
12203 | return "DW_OP_lit28"; | |
12204 | case DW_OP_lit29: | |
12205 | return "DW_OP_lit29"; | |
12206 | case DW_OP_lit30: | |
12207 | return "DW_OP_lit30"; | |
12208 | case DW_OP_lit31: | |
12209 | return "DW_OP_lit31"; | |
12210 | case DW_OP_reg0: | |
12211 | return "DW_OP_reg0"; | |
12212 | case DW_OP_reg1: | |
12213 | return "DW_OP_reg1"; | |
12214 | case DW_OP_reg2: | |
12215 | return "DW_OP_reg2"; | |
12216 | case DW_OP_reg3: | |
12217 | return "DW_OP_reg3"; | |
12218 | case DW_OP_reg4: | |
12219 | return "DW_OP_reg4"; | |
12220 | case DW_OP_reg5: | |
12221 | return "DW_OP_reg5"; | |
12222 | case DW_OP_reg6: | |
12223 | return "DW_OP_reg6"; | |
12224 | case DW_OP_reg7: | |
12225 | return "DW_OP_reg7"; | |
12226 | case DW_OP_reg8: | |
12227 | return "DW_OP_reg8"; | |
12228 | case DW_OP_reg9: | |
12229 | return "DW_OP_reg9"; | |
12230 | case DW_OP_reg10: | |
12231 | return "DW_OP_reg10"; | |
12232 | case DW_OP_reg11: | |
12233 | return "DW_OP_reg11"; | |
12234 | case DW_OP_reg12: | |
12235 | return "DW_OP_reg12"; | |
12236 | case DW_OP_reg13: | |
12237 | return "DW_OP_reg13"; | |
12238 | case DW_OP_reg14: | |
12239 | return "DW_OP_reg14"; | |
12240 | case DW_OP_reg15: | |
12241 | return "DW_OP_reg15"; | |
12242 | case DW_OP_reg16: | |
12243 | return "DW_OP_reg16"; | |
12244 | case DW_OP_reg17: | |
12245 | return "DW_OP_reg17"; | |
12246 | case DW_OP_reg18: | |
12247 | return "DW_OP_reg18"; | |
12248 | case DW_OP_reg19: | |
12249 | return "DW_OP_reg19"; | |
12250 | case DW_OP_reg20: | |
12251 | return "DW_OP_reg20"; | |
12252 | case DW_OP_reg21: | |
12253 | return "DW_OP_reg21"; | |
12254 | case DW_OP_reg22: | |
12255 | return "DW_OP_reg22"; | |
12256 | case DW_OP_reg23: | |
12257 | return "DW_OP_reg23"; | |
12258 | case DW_OP_reg24: | |
12259 | return "DW_OP_reg24"; | |
12260 | case DW_OP_reg25: | |
12261 | return "DW_OP_reg25"; | |
12262 | case DW_OP_reg26: | |
12263 | return "DW_OP_reg26"; | |
12264 | case DW_OP_reg27: | |
12265 | return "DW_OP_reg27"; | |
12266 | case DW_OP_reg28: | |
12267 | return "DW_OP_reg28"; | |
12268 | case DW_OP_reg29: | |
12269 | return "DW_OP_reg29"; | |
12270 | case DW_OP_reg30: | |
12271 | return "DW_OP_reg30"; | |
12272 | case DW_OP_reg31: | |
12273 | return "DW_OP_reg31"; | |
12274 | case DW_OP_breg0: | |
12275 | return "DW_OP_breg0"; | |
12276 | case DW_OP_breg1: | |
12277 | return "DW_OP_breg1"; | |
12278 | case DW_OP_breg2: | |
12279 | return "DW_OP_breg2"; | |
12280 | case DW_OP_breg3: | |
12281 | return "DW_OP_breg3"; | |
12282 | case DW_OP_breg4: | |
12283 | return "DW_OP_breg4"; | |
12284 | case DW_OP_breg5: | |
12285 | return "DW_OP_breg5"; | |
12286 | case DW_OP_breg6: | |
12287 | return "DW_OP_breg6"; | |
12288 | case DW_OP_breg7: | |
12289 | return "DW_OP_breg7"; | |
12290 | case DW_OP_breg8: | |
12291 | return "DW_OP_breg8"; | |
12292 | case DW_OP_breg9: | |
12293 | return "DW_OP_breg9"; | |
12294 | case DW_OP_breg10: | |
12295 | return "DW_OP_breg10"; | |
12296 | case DW_OP_breg11: | |
12297 | return "DW_OP_breg11"; | |
12298 | case DW_OP_breg12: | |
12299 | return "DW_OP_breg12"; | |
12300 | case DW_OP_breg13: | |
12301 | return "DW_OP_breg13"; | |
12302 | case DW_OP_breg14: | |
12303 | return "DW_OP_breg14"; | |
12304 | case DW_OP_breg15: | |
12305 | return "DW_OP_breg15"; | |
12306 | case DW_OP_breg16: | |
12307 | return "DW_OP_breg16"; | |
12308 | case DW_OP_breg17: | |
12309 | return "DW_OP_breg17"; | |
12310 | case DW_OP_breg18: | |
12311 | return "DW_OP_breg18"; | |
12312 | case DW_OP_breg19: | |
12313 | return "DW_OP_breg19"; | |
12314 | case DW_OP_breg20: | |
12315 | return "DW_OP_breg20"; | |
12316 | case DW_OP_breg21: | |
12317 | return "DW_OP_breg21"; | |
12318 | case DW_OP_breg22: | |
12319 | return "DW_OP_breg22"; | |
12320 | case DW_OP_breg23: | |
12321 | return "DW_OP_breg23"; | |
12322 | case DW_OP_breg24: | |
12323 | return "DW_OP_breg24"; | |
12324 | case DW_OP_breg25: | |
12325 | return "DW_OP_breg25"; | |
12326 | case DW_OP_breg26: | |
12327 | return "DW_OP_breg26"; | |
12328 | case DW_OP_breg27: | |
12329 | return "DW_OP_breg27"; | |
12330 | case DW_OP_breg28: | |
12331 | return "DW_OP_breg28"; | |
12332 | case DW_OP_breg29: | |
12333 | return "DW_OP_breg29"; | |
12334 | case DW_OP_breg30: | |
12335 | return "DW_OP_breg30"; | |
12336 | case DW_OP_breg31: | |
12337 | return "DW_OP_breg31"; | |
12338 | case DW_OP_regx: | |
12339 | return "DW_OP_regx"; | |
12340 | case DW_OP_fbreg: | |
12341 | return "DW_OP_fbreg"; | |
12342 | case DW_OP_bregx: | |
12343 | return "DW_OP_bregx"; | |
12344 | case DW_OP_piece: | |
12345 | return "DW_OP_piece"; | |
12346 | case DW_OP_deref_size: | |
12347 | return "DW_OP_deref_size"; | |
12348 | case DW_OP_xderef_size: | |
12349 | return "DW_OP_xderef_size"; | |
12350 | case DW_OP_nop: | |
12351 | return "DW_OP_nop"; | |
b7619582 | 12352 | /* DWARF 3 extensions. */ |
ed348acc EZ |
12353 | case DW_OP_push_object_address: |
12354 | return "DW_OP_push_object_address"; | |
12355 | case DW_OP_call2: | |
12356 | return "DW_OP_call2"; | |
12357 | case DW_OP_call4: | |
12358 | return "DW_OP_call4"; | |
12359 | case DW_OP_call_ref: | |
12360 | return "DW_OP_call_ref"; | |
b7619582 GF |
12361 | case DW_OP_form_tls_address: |
12362 | return "DW_OP_form_tls_address"; | |
12363 | case DW_OP_call_frame_cfa: | |
12364 | return "DW_OP_call_frame_cfa"; | |
12365 | case DW_OP_bit_piece: | |
12366 | return "DW_OP_bit_piece"; | |
9eae7c52 TT |
12367 | /* DWARF 4 extensions. */ |
12368 | case DW_OP_implicit_value: | |
12369 | return "DW_OP_implicit_value"; | |
12370 | case DW_OP_stack_value: | |
12371 | return "DW_OP_stack_value"; | |
12372 | /* GNU extensions. */ | |
ed348acc EZ |
12373 | case DW_OP_GNU_push_tls_address: |
12374 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
12375 | case DW_OP_GNU_uninit: |
12376 | return "DW_OP_GNU_uninit"; | |
c906108c | 12377 | default: |
9eae7c52 | 12378 | return def ? "OP_<unknown>" : NULL; |
c906108c SS |
12379 | } |
12380 | } | |
12381 | ||
12382 | static char * | |
fba45db2 | 12383 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
12384 | { |
12385 | if (mybool) | |
12386 | return "TRUE"; | |
12387 | else | |
12388 | return "FALSE"; | |
12389 | } | |
12390 | ||
12391 | /* Convert a DWARF type code into its string name. */ | |
12392 | ||
12393 | static char * | |
aa1ee363 | 12394 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
12395 | { |
12396 | switch (enc) | |
12397 | { | |
b7619582 GF |
12398 | case DW_ATE_void: |
12399 | return "DW_ATE_void"; | |
c906108c SS |
12400 | case DW_ATE_address: |
12401 | return "DW_ATE_address"; | |
12402 | case DW_ATE_boolean: | |
12403 | return "DW_ATE_boolean"; | |
12404 | case DW_ATE_complex_float: | |
12405 | return "DW_ATE_complex_float"; | |
12406 | case DW_ATE_float: | |
12407 | return "DW_ATE_float"; | |
12408 | case DW_ATE_signed: | |
12409 | return "DW_ATE_signed"; | |
12410 | case DW_ATE_signed_char: | |
12411 | return "DW_ATE_signed_char"; | |
12412 | case DW_ATE_unsigned: | |
12413 | return "DW_ATE_unsigned"; | |
12414 | case DW_ATE_unsigned_char: | |
12415 | return "DW_ATE_unsigned_char"; | |
b7619582 | 12416 | /* DWARF 3. */ |
d9fa45fe DC |
12417 | case DW_ATE_imaginary_float: |
12418 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
12419 | case DW_ATE_packed_decimal: |
12420 | return "DW_ATE_packed_decimal"; | |
12421 | case DW_ATE_numeric_string: | |
12422 | return "DW_ATE_numeric_string"; | |
12423 | case DW_ATE_edited: | |
12424 | return "DW_ATE_edited"; | |
12425 | case DW_ATE_signed_fixed: | |
12426 | return "DW_ATE_signed_fixed"; | |
12427 | case DW_ATE_unsigned_fixed: | |
12428 | return "DW_ATE_unsigned_fixed"; | |
12429 | case DW_ATE_decimal_float: | |
12430 | return "DW_ATE_decimal_float"; | |
75079b2b TT |
12431 | /* DWARF 4. */ |
12432 | case DW_ATE_UTF: | |
12433 | return "DW_ATE_UTF"; | |
b7619582 GF |
12434 | /* HP extensions. */ |
12435 | case DW_ATE_HP_float80: | |
12436 | return "DW_ATE_HP_float80"; | |
12437 | case DW_ATE_HP_complex_float80: | |
12438 | return "DW_ATE_HP_complex_float80"; | |
12439 | case DW_ATE_HP_float128: | |
12440 | return "DW_ATE_HP_float128"; | |
12441 | case DW_ATE_HP_complex_float128: | |
12442 | return "DW_ATE_HP_complex_float128"; | |
12443 | case DW_ATE_HP_floathpintel: | |
12444 | return "DW_ATE_HP_floathpintel"; | |
12445 | case DW_ATE_HP_imaginary_float80: | |
12446 | return "DW_ATE_HP_imaginary_float80"; | |
12447 | case DW_ATE_HP_imaginary_float128: | |
12448 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
12449 | default: |
12450 | return "DW_ATE_<unknown>"; | |
12451 | } | |
12452 | } | |
12453 | ||
12454 | /* Convert a DWARF call frame info operation to its string name. */ | |
12455 | ||
12456 | #if 0 | |
12457 | static char * | |
aa1ee363 | 12458 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
12459 | { |
12460 | switch (cfi_opc) | |
12461 | { | |
12462 | case DW_CFA_advance_loc: | |
12463 | return "DW_CFA_advance_loc"; | |
12464 | case DW_CFA_offset: | |
12465 | return "DW_CFA_offset"; | |
12466 | case DW_CFA_restore: | |
12467 | return "DW_CFA_restore"; | |
12468 | case DW_CFA_nop: | |
12469 | return "DW_CFA_nop"; | |
12470 | case DW_CFA_set_loc: | |
12471 | return "DW_CFA_set_loc"; | |
12472 | case DW_CFA_advance_loc1: | |
12473 | return "DW_CFA_advance_loc1"; | |
12474 | case DW_CFA_advance_loc2: | |
12475 | return "DW_CFA_advance_loc2"; | |
12476 | case DW_CFA_advance_loc4: | |
12477 | return "DW_CFA_advance_loc4"; | |
12478 | case DW_CFA_offset_extended: | |
12479 | return "DW_CFA_offset_extended"; | |
12480 | case DW_CFA_restore_extended: | |
12481 | return "DW_CFA_restore_extended"; | |
12482 | case DW_CFA_undefined: | |
12483 | return "DW_CFA_undefined"; | |
12484 | case DW_CFA_same_value: | |
12485 | return "DW_CFA_same_value"; | |
12486 | case DW_CFA_register: | |
12487 | return "DW_CFA_register"; | |
12488 | case DW_CFA_remember_state: | |
12489 | return "DW_CFA_remember_state"; | |
12490 | case DW_CFA_restore_state: | |
12491 | return "DW_CFA_restore_state"; | |
12492 | case DW_CFA_def_cfa: | |
12493 | return "DW_CFA_def_cfa"; | |
12494 | case DW_CFA_def_cfa_register: | |
12495 | return "DW_CFA_def_cfa_register"; | |
12496 | case DW_CFA_def_cfa_offset: | |
12497 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 12498 | /* DWARF 3. */ |
985cb1a3 JM |
12499 | case DW_CFA_def_cfa_expression: |
12500 | return "DW_CFA_def_cfa_expression"; | |
12501 | case DW_CFA_expression: | |
12502 | return "DW_CFA_expression"; | |
12503 | case DW_CFA_offset_extended_sf: | |
12504 | return "DW_CFA_offset_extended_sf"; | |
12505 | case DW_CFA_def_cfa_sf: | |
12506 | return "DW_CFA_def_cfa_sf"; | |
12507 | case DW_CFA_def_cfa_offset_sf: | |
12508 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
12509 | case DW_CFA_val_offset: |
12510 | return "DW_CFA_val_offset"; | |
12511 | case DW_CFA_val_offset_sf: | |
12512 | return "DW_CFA_val_offset_sf"; | |
12513 | case DW_CFA_val_expression: | |
12514 | return "DW_CFA_val_expression"; | |
12515 | /* SGI/MIPS specific. */ | |
c906108c SS |
12516 | case DW_CFA_MIPS_advance_loc8: |
12517 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 12518 | /* GNU extensions. */ |
985cb1a3 JM |
12519 | case DW_CFA_GNU_window_save: |
12520 | return "DW_CFA_GNU_window_save"; | |
12521 | case DW_CFA_GNU_args_size: | |
12522 | return "DW_CFA_GNU_args_size"; | |
12523 | case DW_CFA_GNU_negative_offset_extended: | |
12524 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
12525 | default: |
12526 | return "DW_CFA_<unknown>"; | |
12527 | } | |
12528 | } | |
12529 | #endif | |
12530 | ||
f9aca02d | 12531 | static void |
d97bc12b | 12532 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
12533 | { |
12534 | unsigned int i; | |
12535 | ||
d97bc12b DE |
12536 | print_spaces (indent, f); |
12537 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 12538 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
12539 | |
12540 | if (die->parent != NULL) | |
12541 | { | |
12542 | print_spaces (indent, f); | |
12543 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
12544 | die->parent->offset); | |
12545 | } | |
12546 | ||
12547 | print_spaces (indent, f); | |
12548 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 12549 | dwarf_bool_name (die->child != NULL)); |
c906108c | 12550 | |
d97bc12b DE |
12551 | print_spaces (indent, f); |
12552 | fprintf_unfiltered (f, " attributes:\n"); | |
12553 | ||
c906108c SS |
12554 | for (i = 0; i < die->num_attrs; ++i) |
12555 | { | |
d97bc12b DE |
12556 | print_spaces (indent, f); |
12557 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
12558 | dwarf_attr_name (die->attrs[i].name), |
12559 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 12560 | |
c906108c SS |
12561 | switch (die->attrs[i].form) |
12562 | { | |
12563 | case DW_FORM_ref_addr: | |
12564 | case DW_FORM_addr: | |
d97bc12b | 12565 | fprintf_unfiltered (f, "address: "); |
5af949e3 | 12566 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
c906108c SS |
12567 | break; |
12568 | case DW_FORM_block2: | |
12569 | case DW_FORM_block4: | |
12570 | case DW_FORM_block: | |
12571 | case DW_FORM_block1: | |
d97bc12b | 12572 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 12573 | break; |
2dc7f7b3 TT |
12574 | case DW_FORM_exprloc: |
12575 | fprintf_unfiltered (f, "expression: size %u", | |
12576 | DW_BLOCK (&die->attrs[i])->size); | |
12577 | break; | |
10b3939b DJ |
12578 | case DW_FORM_ref1: |
12579 | case DW_FORM_ref2: | |
12580 | case DW_FORM_ref4: | |
d97bc12b | 12581 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
12582 | (long) (DW_ADDR (&die->attrs[i]))); |
12583 | break; | |
c906108c SS |
12584 | case DW_FORM_data1: |
12585 | case DW_FORM_data2: | |
12586 | case DW_FORM_data4: | |
ce5d95e1 | 12587 | case DW_FORM_data8: |
c906108c SS |
12588 | case DW_FORM_udata: |
12589 | case DW_FORM_sdata: | |
43bbcdc2 PH |
12590 | fprintf_unfiltered (f, "constant: %s", |
12591 | pulongest (DW_UNSND (&die->attrs[i]))); | |
c906108c | 12592 | break; |
2dc7f7b3 TT |
12593 | case DW_FORM_sec_offset: |
12594 | fprintf_unfiltered (f, "section offset: %s", | |
12595 | pulongest (DW_UNSND (&die->attrs[i]))); | |
12596 | break; | |
348e048f DE |
12597 | case DW_FORM_sig8: |
12598 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) | |
12599 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", | |
12600 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); | |
12601 | else | |
12602 | fprintf_unfiltered (f, "signatured type, offset: unknown"); | |
12603 | break; | |
c906108c | 12604 | case DW_FORM_string: |
4bdf3d34 | 12605 | case DW_FORM_strp: |
8285870a | 12606 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
c906108c | 12607 | DW_STRING (&die->attrs[i]) |
8285870a JK |
12608 | ? DW_STRING (&die->attrs[i]) : "", |
12609 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); | |
c906108c SS |
12610 | break; |
12611 | case DW_FORM_flag: | |
12612 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 12613 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 12614 | else |
d97bc12b | 12615 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 12616 | break; |
2dc7f7b3 TT |
12617 | case DW_FORM_flag_present: |
12618 | fprintf_unfiltered (f, "flag: TRUE"); | |
12619 | break; | |
a8329558 KW |
12620 | case DW_FORM_indirect: |
12621 | /* the reader will have reduced the indirect form to | |
12622 | the "base form" so this form should not occur */ | |
d97bc12b | 12623 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 12624 | break; |
c906108c | 12625 | default: |
d97bc12b | 12626 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 12627 | die->attrs[i].form); |
d97bc12b | 12628 | break; |
c906108c | 12629 | } |
d97bc12b | 12630 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
12631 | } |
12632 | } | |
12633 | ||
f9aca02d | 12634 | static void |
d97bc12b | 12635 | dump_die_for_error (struct die_info *die) |
c906108c | 12636 | { |
d97bc12b DE |
12637 | dump_die_shallow (gdb_stderr, 0, die); |
12638 | } | |
12639 | ||
12640 | static void | |
12641 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
12642 | { | |
12643 | int indent = level * 4; | |
12644 | ||
12645 | gdb_assert (die != NULL); | |
12646 | ||
12647 | if (level >= max_level) | |
12648 | return; | |
12649 | ||
12650 | dump_die_shallow (f, indent, die); | |
12651 | ||
12652 | if (die->child != NULL) | |
c906108c | 12653 | { |
d97bc12b DE |
12654 | print_spaces (indent, f); |
12655 | fprintf_unfiltered (f, " Children:"); | |
12656 | if (level + 1 < max_level) | |
12657 | { | |
12658 | fprintf_unfiltered (f, "\n"); | |
12659 | dump_die_1 (f, level + 1, max_level, die->child); | |
12660 | } | |
12661 | else | |
12662 | { | |
12663 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
12664 | } | |
12665 | } | |
12666 | ||
12667 | if (die->sibling != NULL && level > 0) | |
12668 | { | |
12669 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
12670 | } |
12671 | } | |
12672 | ||
d97bc12b DE |
12673 | /* This is called from the pdie macro in gdbinit.in. |
12674 | It's not static so gcc will keep a copy callable from gdb. */ | |
12675 | ||
12676 | void | |
12677 | dump_die (struct die_info *die, int max_level) | |
12678 | { | |
12679 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
12680 | } | |
12681 | ||
f9aca02d | 12682 | static void |
51545339 | 12683 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 12684 | { |
51545339 | 12685 | void **slot; |
c906108c | 12686 | |
51545339 DJ |
12687 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
12688 | ||
12689 | *slot = die; | |
c906108c SS |
12690 | } |
12691 | ||
93311388 DE |
12692 | static int |
12693 | is_ref_attr (struct attribute *attr) | |
c906108c | 12694 | { |
c906108c SS |
12695 | switch (attr->form) |
12696 | { | |
12697 | case DW_FORM_ref_addr: | |
c906108c SS |
12698 | case DW_FORM_ref1: |
12699 | case DW_FORM_ref2: | |
12700 | case DW_FORM_ref4: | |
613e1657 | 12701 | case DW_FORM_ref8: |
c906108c | 12702 | case DW_FORM_ref_udata: |
93311388 | 12703 | return 1; |
c906108c | 12704 | default: |
93311388 | 12705 | return 0; |
c906108c | 12706 | } |
93311388 DE |
12707 | } |
12708 | ||
12709 | static unsigned int | |
12710 | dwarf2_get_ref_die_offset (struct attribute *attr) | |
12711 | { | |
12712 | if (is_ref_attr (attr)) | |
12713 | return DW_ADDR (attr); | |
12714 | ||
12715 | complaint (&symfile_complaints, | |
12716 | _("unsupported die ref attribute form: '%s'"), | |
12717 | dwarf_form_name (attr->form)); | |
12718 | return 0; | |
c906108c SS |
12719 | } |
12720 | ||
43bbcdc2 PH |
12721 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
12722 | * the value held by the attribute is not constant. */ | |
a02abb62 | 12723 | |
43bbcdc2 | 12724 | static LONGEST |
a02abb62 JB |
12725 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
12726 | { | |
12727 | if (attr->form == DW_FORM_sdata) | |
12728 | return DW_SND (attr); | |
12729 | else if (attr->form == DW_FORM_udata | |
12730 | || attr->form == DW_FORM_data1 | |
12731 | || attr->form == DW_FORM_data2 | |
12732 | || attr->form == DW_FORM_data4 | |
12733 | || attr->form == DW_FORM_data8) | |
12734 | return DW_UNSND (attr); | |
12735 | else | |
12736 | { | |
e2e0b3e5 | 12737 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
12738 | dwarf_form_name (attr->form)); |
12739 | return default_value; | |
12740 | } | |
12741 | } | |
12742 | ||
03dd20cc | 12743 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
348e048f DE |
12744 | unit and add it to our queue. |
12745 | The result is non-zero if PER_CU was queued, otherwise the result is zero | |
12746 | meaning either PER_CU is already queued or it is already loaded. */ | |
03dd20cc | 12747 | |
348e048f | 12748 | static int |
03dd20cc DJ |
12749 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
12750 | struct dwarf2_per_cu_data *per_cu) | |
12751 | { | |
98bfdba5 PA |
12752 | /* We may arrive here during partial symbol reading, if we need full |
12753 | DIEs to process an unusual case (e.g. template arguments). Do | |
12754 | not queue PER_CU, just tell our caller to load its DIEs. */ | |
12755 | if (dwarf2_per_objfile->reading_partial_symbols) | |
12756 | { | |
12757 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) | |
12758 | return 1; | |
12759 | return 0; | |
12760 | } | |
12761 | ||
03dd20cc DJ |
12762 | /* Mark the dependence relation so that we don't flush PER_CU |
12763 | too early. */ | |
12764 | dwarf2_add_dependence (this_cu, per_cu); | |
12765 | ||
12766 | /* If it's already on the queue, we have nothing to do. */ | |
12767 | if (per_cu->queued) | |
348e048f | 12768 | return 0; |
03dd20cc DJ |
12769 | |
12770 | /* If the compilation unit is already loaded, just mark it as | |
12771 | used. */ | |
12772 | if (per_cu->cu != NULL) | |
12773 | { | |
12774 | per_cu->cu->last_used = 0; | |
348e048f | 12775 | return 0; |
03dd20cc DJ |
12776 | } |
12777 | ||
12778 | /* Add it to the queue. */ | |
12779 | queue_comp_unit (per_cu, this_cu->objfile); | |
348e048f DE |
12780 | |
12781 | return 1; | |
12782 | } | |
12783 | ||
12784 | /* Follow reference or signature attribute ATTR of SRC_DIE. | |
12785 | On entry *REF_CU is the CU of SRC_DIE. | |
12786 | On exit *REF_CU is the CU of the result. */ | |
12787 | ||
12788 | static struct die_info * | |
12789 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, | |
12790 | struct dwarf2_cu **ref_cu) | |
12791 | { | |
12792 | struct die_info *die; | |
12793 | ||
12794 | if (is_ref_attr (attr)) | |
12795 | die = follow_die_ref (src_die, attr, ref_cu); | |
12796 | else if (attr->form == DW_FORM_sig8) | |
12797 | die = follow_die_sig (src_die, attr, ref_cu); | |
12798 | else | |
12799 | { | |
12800 | dump_die_for_error (src_die); | |
12801 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), | |
12802 | (*ref_cu)->objfile->name); | |
12803 | } | |
12804 | ||
12805 | return die; | |
03dd20cc DJ |
12806 | } |
12807 | ||
5c631832 | 12808 | /* Follow reference OFFSET. |
673bfd45 DE |
12809 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
12810 | On exit *REF_CU is the CU of the result. | |
12811 | Returns NULL if OFFSET is invalid. */ | |
f504f079 | 12812 | |
f9aca02d | 12813 | static struct die_info * |
5c631832 | 12814 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
c906108c | 12815 | { |
10b3939b | 12816 | struct die_info temp_die; |
f2f0e013 | 12817 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 12818 | |
348e048f DE |
12819 | gdb_assert (cu->per_cu != NULL); |
12820 | ||
98bfdba5 PA |
12821 | target_cu = cu; |
12822 | ||
348e048f DE |
12823 | if (cu->per_cu->from_debug_types) |
12824 | { | |
12825 | /* .debug_types CUs cannot reference anything outside their CU. | |
12826 | If they need to, they have to reference a signatured type via | |
12827 | DW_FORM_sig8. */ | |
12828 | if (! offset_in_cu_p (&cu->header, offset)) | |
5c631832 | 12829 | return NULL; |
348e048f DE |
12830 | } |
12831 | else if (! offset_in_cu_p (&cu->header, offset)) | |
10b3939b DJ |
12832 | { |
12833 | struct dwarf2_per_cu_data *per_cu; | |
9a619af0 | 12834 | |
45452591 | 12835 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
12836 | |
12837 | /* If necessary, add it to the queue and load its DIEs. */ | |
348e048f DE |
12838 | if (maybe_queue_comp_unit (cu, per_cu)) |
12839 | load_full_comp_unit (per_cu, cu->objfile); | |
03dd20cc | 12840 | |
10b3939b DJ |
12841 | target_cu = per_cu->cu; |
12842 | } | |
98bfdba5 PA |
12843 | else if (cu->dies == NULL) |
12844 | { | |
12845 | /* We're loading full DIEs during partial symbol reading. */ | |
12846 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); | |
12847 | load_full_comp_unit (cu->per_cu, cu->objfile); | |
12848 | } | |
c906108c | 12849 | |
f2f0e013 | 12850 | *ref_cu = target_cu; |
51545339 | 12851 | temp_die.offset = offset; |
5c631832 JK |
12852 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
12853 | } | |
10b3939b | 12854 | |
5c631832 JK |
12855 | /* Follow reference attribute ATTR of SRC_DIE. |
12856 | On entry *REF_CU is the CU of SRC_DIE. | |
12857 | On exit *REF_CU is the CU of the result. */ | |
12858 | ||
12859 | static struct die_info * | |
12860 | follow_die_ref (struct die_info *src_die, struct attribute *attr, | |
12861 | struct dwarf2_cu **ref_cu) | |
12862 | { | |
12863 | unsigned int offset = dwarf2_get_ref_die_offset (attr); | |
12864 | struct dwarf2_cu *cu = *ref_cu; | |
12865 | struct die_info *die; | |
12866 | ||
12867 | die = follow_die_offset (offset, ref_cu); | |
12868 | if (!die) | |
12869 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " | |
12870 | "at 0x%x [in module %s]"), | |
12871 | offset, src_die->offset, cu->objfile->name); | |
348e048f | 12872 | |
5c631832 JK |
12873 | return die; |
12874 | } | |
12875 | ||
12876 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned | |
12877 | value is intended for DW_OP_call*. */ | |
12878 | ||
12879 | struct dwarf2_locexpr_baton | |
12880 | dwarf2_fetch_die_location_block (unsigned int offset, | |
12881 | struct dwarf2_per_cu_data *per_cu) | |
12882 | { | |
12883 | struct dwarf2_cu *cu = per_cu->cu; | |
12884 | struct die_info *die; | |
12885 | struct attribute *attr; | |
12886 | struct dwarf2_locexpr_baton retval; | |
12887 | ||
12888 | die = follow_die_offset (offset, &cu); | |
12889 | if (!die) | |
12890 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), | |
12891 | offset, per_cu->cu->objfile->name); | |
12892 | ||
12893 | attr = dwarf2_attr (die, DW_AT_location, cu); | |
12894 | if (!attr) | |
12895 | { | |
12896 | /* DWARF: "If there is no such attribute, then there is no effect.". */ | |
12897 | ||
12898 | retval.data = NULL; | |
12899 | retval.size = 0; | |
12900 | } | |
12901 | else | |
12902 | { | |
12903 | if (!attr_form_is_block (attr)) | |
12904 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " | |
12905 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), | |
12906 | offset, per_cu->cu->objfile->name); | |
12907 | ||
12908 | retval.data = DW_BLOCK (attr)->data; | |
12909 | retval.size = DW_BLOCK (attr)->size; | |
12910 | } | |
12911 | retval.per_cu = cu->per_cu; | |
12912 | return retval; | |
348e048f DE |
12913 | } |
12914 | ||
12915 | /* Follow the signature attribute ATTR in SRC_DIE. | |
12916 | On entry *REF_CU is the CU of SRC_DIE. | |
12917 | On exit *REF_CU is the CU of the result. */ | |
12918 | ||
12919 | static struct die_info * | |
12920 | follow_die_sig (struct die_info *src_die, struct attribute *attr, | |
12921 | struct dwarf2_cu **ref_cu) | |
12922 | { | |
12923 | struct objfile *objfile = (*ref_cu)->objfile; | |
12924 | struct die_info temp_die; | |
12925 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); | |
12926 | struct dwarf2_cu *sig_cu; | |
12927 | struct die_info *die; | |
12928 | ||
12929 | /* sig_type will be NULL if the signatured type is missing from | |
12930 | the debug info. */ | |
12931 | if (sig_type == NULL) | |
12932 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " | |
12933 | "at 0x%x [in module %s]"), | |
12934 | src_die->offset, objfile->name); | |
12935 | ||
12936 | /* If necessary, add it to the queue and load its DIEs. */ | |
12937 | ||
12938 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) | |
12939 | read_signatured_type (objfile, sig_type); | |
12940 | ||
12941 | gdb_assert (sig_type->per_cu.cu != NULL); | |
12942 | ||
12943 | sig_cu = sig_type->per_cu.cu; | |
12944 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; | |
12945 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); | |
12946 | if (die) | |
12947 | { | |
12948 | *ref_cu = sig_cu; | |
12949 | return die; | |
12950 | } | |
12951 | ||
12952 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced from DIE " | |
12953 | "at 0x%x [in module %s]"), | |
12954 | sig_type->type_offset, src_die->offset, objfile->name); | |
12955 | } | |
12956 | ||
12957 | /* Given an offset of a signatured type, return its signatured_type. */ | |
12958 | ||
12959 | static struct signatured_type * | |
12960 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) | |
12961 | { | |
12962 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; | |
12963 | unsigned int length, initial_length_size; | |
12964 | unsigned int sig_offset; | |
12965 | struct signatured_type find_entry, *type_sig; | |
12966 | ||
12967 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); | |
12968 | sig_offset = (initial_length_size | |
12969 | + 2 /*version*/ | |
12970 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ | |
12971 | + 1 /*address_size*/); | |
12972 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); | |
12973 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); | |
12974 | ||
12975 | /* This is only used to lookup previously recorded types. | |
12976 | If we didn't find it, it's our bug. */ | |
12977 | gdb_assert (type_sig != NULL); | |
12978 | gdb_assert (offset == type_sig->offset); | |
12979 | ||
12980 | return type_sig; | |
12981 | } | |
12982 | ||
12983 | /* Read in signatured type at OFFSET and build its CU and die(s). */ | |
12984 | ||
12985 | static void | |
12986 | read_signatured_type_at_offset (struct objfile *objfile, | |
12987 | unsigned int offset) | |
12988 | { | |
12989 | struct signatured_type *type_sig; | |
12990 | ||
be391dca TT |
12991 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
12992 | ||
348e048f DE |
12993 | /* We have the section offset, but we need the signature to do the |
12994 | hash table lookup. */ | |
12995 | type_sig = lookup_signatured_type_at_offset (objfile, offset); | |
12996 | ||
12997 | gdb_assert (type_sig->per_cu.cu == NULL); | |
12998 | ||
12999 | read_signatured_type (objfile, type_sig); | |
13000 | ||
13001 | gdb_assert (type_sig->per_cu.cu != NULL); | |
13002 | } | |
13003 | ||
13004 | /* Read in a signatured type and build its CU and DIEs. */ | |
13005 | ||
13006 | static void | |
13007 | read_signatured_type (struct objfile *objfile, | |
13008 | struct signatured_type *type_sig) | |
13009 | { | |
1fd400ff | 13010 | gdb_byte *types_ptr; |
348e048f DE |
13011 | struct die_reader_specs reader_specs; |
13012 | struct dwarf2_cu *cu; | |
13013 | ULONGEST signature; | |
13014 | struct cleanup *back_to, *free_cu_cleanup; | |
13015 | struct attribute *attr; | |
13016 | ||
1fd400ff TT |
13017 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
13018 | types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; | |
13019 | ||
348e048f DE |
13020 | gdb_assert (type_sig->per_cu.cu == NULL); |
13021 | ||
13022 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
13023 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
13024 | obstack_init (&cu->comp_unit_obstack); | |
13025 | cu->objfile = objfile; | |
13026 | type_sig->per_cu.cu = cu; | |
13027 | cu->per_cu = &type_sig->per_cu; | |
13028 | ||
13029 | /* If an error occurs while loading, release our storage. */ | |
13030 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
13031 | ||
13032 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, | |
13033 | types_ptr, objfile->obfd); | |
13034 | gdb_assert (signature == type_sig->signature); | |
13035 | ||
13036 | cu->die_hash | |
13037 | = htab_create_alloc_ex (cu->header.length / 12, | |
13038 | die_hash, | |
13039 | die_eq, | |
13040 | NULL, | |
13041 | &cu->comp_unit_obstack, | |
13042 | hashtab_obstack_allocate, | |
13043 | dummy_obstack_deallocate); | |
13044 | ||
13045 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); | |
13046 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
13047 | ||
13048 | init_cu_die_reader (&reader_specs, cu); | |
13049 | ||
13050 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, | |
13051 | NULL /*parent*/); | |
13052 | ||
13053 | /* We try not to read any attributes in this function, because not | |
13054 | all objfiles needed for references have been loaded yet, and symbol | |
13055 | table processing isn't initialized. But we have to set the CU language, | |
13056 | or we won't be able to build types correctly. */ | |
13057 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
13058 | if (attr) | |
13059 | set_cu_language (DW_UNSND (attr), cu); | |
13060 | else | |
13061 | set_cu_language (language_minimal, cu); | |
13062 | ||
13063 | do_cleanups (back_to); | |
13064 | ||
13065 | /* We've successfully allocated this compilation unit. Let our caller | |
13066 | clean it up when finished with it. */ | |
13067 | discard_cleanups (free_cu_cleanup); | |
13068 | ||
13069 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
13070 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; | |
c906108c SS |
13071 | } |
13072 | ||
c906108c SS |
13073 | /* Decode simple location descriptions. |
13074 | Given a pointer to a dwarf block that defines a location, compute | |
13075 | the location and return the value. | |
13076 | ||
4cecd739 DJ |
13077 | NOTE drow/2003-11-18: This function is called in two situations |
13078 | now: for the address of static or global variables (partial symbols | |
13079 | only) and for offsets into structures which are expected to be | |
13080 | (more or less) constant. The partial symbol case should go away, | |
13081 | and only the constant case should remain. That will let this | |
13082 | function complain more accurately. A few special modes are allowed | |
13083 | without complaint for global variables (for instance, global | |
13084 | register values and thread-local values). | |
c906108c SS |
13085 | |
13086 | A location description containing no operations indicates that the | |
4cecd739 | 13087 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
13088 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
13089 | callers will only want a very basic result and this can become a | |
13090 | complaint. | |
c906108c | 13091 | |
c906108c SS |
13092 | Note that stack[0] is unused except as a default error return. |
13093 | Note that stack overflow is not yet handled. */ | |
13094 | ||
13095 | static CORE_ADDR | |
e7c27a73 | 13096 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 13097 | { |
e7c27a73 | 13098 | struct objfile *objfile = cu->objfile; |
c906108c SS |
13099 | int i; |
13100 | int size = blk->size; | |
fe1b8b76 | 13101 | gdb_byte *data = blk->data; |
c906108c SS |
13102 | CORE_ADDR stack[64]; |
13103 | int stacki; | |
13104 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 13105 | gdb_byte op; |
c906108c SS |
13106 | |
13107 | i = 0; | |
13108 | stacki = 0; | |
13109 | stack[stacki] = 0; | |
c906108c SS |
13110 | |
13111 | while (i < size) | |
13112 | { | |
c906108c SS |
13113 | op = data[i++]; |
13114 | switch (op) | |
13115 | { | |
f1bea926 JM |
13116 | case DW_OP_lit0: |
13117 | case DW_OP_lit1: | |
13118 | case DW_OP_lit2: | |
13119 | case DW_OP_lit3: | |
13120 | case DW_OP_lit4: | |
13121 | case DW_OP_lit5: | |
13122 | case DW_OP_lit6: | |
13123 | case DW_OP_lit7: | |
13124 | case DW_OP_lit8: | |
13125 | case DW_OP_lit9: | |
13126 | case DW_OP_lit10: | |
13127 | case DW_OP_lit11: | |
13128 | case DW_OP_lit12: | |
13129 | case DW_OP_lit13: | |
13130 | case DW_OP_lit14: | |
13131 | case DW_OP_lit15: | |
13132 | case DW_OP_lit16: | |
13133 | case DW_OP_lit17: | |
13134 | case DW_OP_lit18: | |
13135 | case DW_OP_lit19: | |
13136 | case DW_OP_lit20: | |
13137 | case DW_OP_lit21: | |
13138 | case DW_OP_lit22: | |
13139 | case DW_OP_lit23: | |
13140 | case DW_OP_lit24: | |
13141 | case DW_OP_lit25: | |
13142 | case DW_OP_lit26: | |
13143 | case DW_OP_lit27: | |
13144 | case DW_OP_lit28: | |
13145 | case DW_OP_lit29: | |
13146 | case DW_OP_lit30: | |
13147 | case DW_OP_lit31: | |
13148 | stack[++stacki] = op - DW_OP_lit0; | |
13149 | break; | |
13150 | ||
c906108c SS |
13151 | case DW_OP_reg0: |
13152 | case DW_OP_reg1: | |
13153 | case DW_OP_reg2: | |
13154 | case DW_OP_reg3: | |
13155 | case DW_OP_reg4: | |
13156 | case DW_OP_reg5: | |
13157 | case DW_OP_reg6: | |
13158 | case DW_OP_reg7: | |
13159 | case DW_OP_reg8: | |
13160 | case DW_OP_reg9: | |
13161 | case DW_OP_reg10: | |
13162 | case DW_OP_reg11: | |
13163 | case DW_OP_reg12: | |
13164 | case DW_OP_reg13: | |
13165 | case DW_OP_reg14: | |
13166 | case DW_OP_reg15: | |
13167 | case DW_OP_reg16: | |
13168 | case DW_OP_reg17: | |
13169 | case DW_OP_reg18: | |
13170 | case DW_OP_reg19: | |
13171 | case DW_OP_reg20: | |
13172 | case DW_OP_reg21: | |
13173 | case DW_OP_reg22: | |
13174 | case DW_OP_reg23: | |
13175 | case DW_OP_reg24: | |
13176 | case DW_OP_reg25: | |
13177 | case DW_OP_reg26: | |
13178 | case DW_OP_reg27: | |
13179 | case DW_OP_reg28: | |
13180 | case DW_OP_reg29: | |
13181 | case DW_OP_reg30: | |
13182 | case DW_OP_reg31: | |
c906108c | 13183 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
13184 | if (i < size) |
13185 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13186 | break; |
13187 | ||
13188 | case DW_OP_regx: | |
c906108c SS |
13189 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
13190 | i += bytes_read; | |
c906108c | 13191 | stack[++stacki] = unsnd; |
4cecd739 DJ |
13192 | if (i < size) |
13193 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
13194 | break; |
13195 | ||
13196 | case DW_OP_addr: | |
107d2387 | 13197 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 13198 | cu, &bytes_read); |
107d2387 | 13199 | i += bytes_read; |
c906108c SS |
13200 | break; |
13201 | ||
13202 | case DW_OP_const1u: | |
13203 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
13204 | i += 1; | |
13205 | break; | |
13206 | ||
13207 | case DW_OP_const1s: | |
13208 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
13209 | i += 1; | |
13210 | break; | |
13211 | ||
13212 | case DW_OP_const2u: | |
13213 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
13214 | i += 2; | |
13215 | break; | |
13216 | ||
13217 | case DW_OP_const2s: | |
13218 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
13219 | i += 2; | |
13220 | break; | |
13221 | ||
13222 | case DW_OP_const4u: | |
13223 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
13224 | i += 4; | |
13225 | break; | |
13226 | ||
13227 | case DW_OP_const4s: | |
13228 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
13229 | i += 4; | |
13230 | break; | |
13231 | ||
13232 | case DW_OP_constu: | |
13233 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 13234 | &bytes_read); |
c906108c SS |
13235 | i += bytes_read; |
13236 | break; | |
13237 | ||
13238 | case DW_OP_consts: | |
13239 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
13240 | i += bytes_read; | |
13241 | break; | |
13242 | ||
f1bea926 JM |
13243 | case DW_OP_dup: |
13244 | stack[stacki + 1] = stack[stacki]; | |
13245 | stacki++; | |
13246 | break; | |
13247 | ||
c906108c SS |
13248 | case DW_OP_plus: |
13249 | stack[stacki - 1] += stack[stacki]; | |
13250 | stacki--; | |
13251 | break; | |
13252 | ||
13253 | case DW_OP_plus_uconst: | |
13254 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
13255 | i += bytes_read; | |
13256 | break; | |
13257 | ||
13258 | case DW_OP_minus: | |
f1bea926 | 13259 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
13260 | stacki--; |
13261 | break; | |
13262 | ||
7a292a7a | 13263 | case DW_OP_deref: |
7a292a7a | 13264 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
13265 | this using GDB's address_class enum. This is valid for partial |
13266 | global symbols, although the variable's address will be bogus | |
13267 | in the psymtab. */ | |
7a292a7a | 13268 | if (i < size) |
4d3c2250 | 13269 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
13270 | break; |
13271 | ||
9d774e44 | 13272 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
13273 | /* The top of the stack has the offset from the beginning |
13274 | of the thread control block at which the variable is located. */ | |
13275 | /* Nothing should follow this operator, so the top of stack would | |
13276 | be returned. */ | |
4cecd739 DJ |
13277 | /* This is valid for partial global symbols, but the variable's |
13278 | address will be bogus in the psymtab. */ | |
9d774e44 | 13279 | if (i < size) |
4d3c2250 | 13280 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
13281 | break; |
13282 | ||
42be36b3 CT |
13283 | case DW_OP_GNU_uninit: |
13284 | break; | |
13285 | ||
c906108c | 13286 | default: |
e2e0b3e5 | 13287 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
9eae7c52 | 13288 | dwarf_stack_op_name (op, 1)); |
c906108c SS |
13289 | return (stack[stacki]); |
13290 | } | |
13291 | } | |
13292 | return (stack[stacki]); | |
13293 | } | |
13294 | ||
13295 | /* memory allocation interface */ | |
13296 | ||
c906108c | 13297 | static struct dwarf_block * |
7b5a2f43 | 13298 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
13299 | { |
13300 | struct dwarf_block *blk; | |
13301 | ||
13302 | blk = (struct dwarf_block *) | |
7b5a2f43 | 13303 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
13304 | return (blk); |
13305 | } | |
13306 | ||
13307 | static struct abbrev_info * | |
f3dd6933 | 13308 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
13309 | { |
13310 | struct abbrev_info *abbrev; | |
13311 | ||
f3dd6933 DJ |
13312 | abbrev = (struct abbrev_info *) |
13313 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
13314 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
13315 | return (abbrev); | |
13316 | } | |
13317 | ||
13318 | static struct die_info * | |
b60c80d6 | 13319 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
13320 | { |
13321 | struct die_info *die; | |
b60c80d6 DJ |
13322 | size_t size = sizeof (struct die_info); |
13323 | ||
13324 | if (num_attrs > 1) | |
13325 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 13326 | |
b60c80d6 | 13327 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
13328 | memset (die, 0, sizeof (struct die_info)); |
13329 | return (die); | |
13330 | } | |
2e276125 JB |
13331 | |
13332 | \f | |
13333 | /* Macro support. */ | |
13334 | ||
13335 | ||
13336 | /* Return the full name of file number I in *LH's file name table. | |
13337 | Use COMP_DIR as the name of the current directory of the | |
13338 | compilation. The result is allocated using xmalloc; the caller is | |
13339 | responsible for freeing it. */ | |
13340 | static char * | |
13341 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
13342 | { | |
6a83a1e6 EZ |
13343 | /* Is the file number a valid index into the line header's file name |
13344 | table? Remember that file numbers start with one, not zero. */ | |
13345 | if (1 <= file && file <= lh->num_file_names) | |
13346 | { | |
13347 | struct file_entry *fe = &lh->file_names[file - 1]; | |
6e70227d | 13348 | |
6a83a1e6 EZ |
13349 | if (IS_ABSOLUTE_PATH (fe->name)) |
13350 | return xstrdup (fe->name); | |
13351 | else | |
13352 | { | |
13353 | const char *dir; | |
13354 | int dir_len; | |
13355 | char *full_name; | |
13356 | ||
13357 | if (fe->dir_index) | |
13358 | dir = lh->include_dirs[fe->dir_index - 1]; | |
13359 | else | |
13360 | dir = comp_dir; | |
13361 | ||
13362 | if (dir) | |
13363 | { | |
13364 | dir_len = strlen (dir); | |
13365 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
13366 | strcpy (full_name, dir); | |
13367 | full_name[dir_len] = '/'; | |
13368 | strcpy (full_name + dir_len + 1, fe->name); | |
13369 | return full_name; | |
13370 | } | |
13371 | else | |
13372 | return xstrdup (fe->name); | |
13373 | } | |
13374 | } | |
2e276125 JB |
13375 | else |
13376 | { | |
6a83a1e6 EZ |
13377 | /* The compiler produced a bogus file number. We can at least |
13378 | record the macro definitions made in the file, even if we | |
13379 | won't be able to find the file by name. */ | |
13380 | char fake_name[80]; | |
9a619af0 | 13381 | |
6a83a1e6 | 13382 | sprintf (fake_name, "<bad macro file number %d>", file); |
2e276125 | 13383 | |
6e70227d | 13384 | complaint (&symfile_complaints, |
6a83a1e6 EZ |
13385 | _("bad file number in macro information (%d)"), |
13386 | file); | |
2e276125 | 13387 | |
6a83a1e6 | 13388 | return xstrdup (fake_name); |
2e276125 JB |
13389 | } |
13390 | } | |
13391 | ||
13392 | ||
13393 | static struct macro_source_file * | |
13394 | macro_start_file (int file, int line, | |
13395 | struct macro_source_file *current_file, | |
13396 | const char *comp_dir, | |
13397 | struct line_header *lh, struct objfile *objfile) | |
13398 | { | |
13399 | /* The full name of this source file. */ | |
13400 | char *full_name = file_full_name (file, lh, comp_dir); | |
13401 | ||
13402 | /* We don't create a macro table for this compilation unit | |
13403 | at all until we actually get a filename. */ | |
13404 | if (! pending_macros) | |
4a146b47 | 13405 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 13406 | objfile->macro_cache); |
2e276125 JB |
13407 | |
13408 | if (! current_file) | |
13409 | /* If we have no current file, then this must be the start_file | |
13410 | directive for the compilation unit's main source file. */ | |
13411 | current_file = macro_set_main (pending_macros, full_name); | |
13412 | else | |
13413 | current_file = macro_include (current_file, line, full_name); | |
13414 | ||
13415 | xfree (full_name); | |
6e70227d | 13416 | |
2e276125 JB |
13417 | return current_file; |
13418 | } | |
13419 | ||
13420 | ||
13421 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
13422 | followed by a null byte. */ | |
13423 | static char * | |
13424 | copy_string (const char *buf, int len) | |
13425 | { | |
13426 | char *s = xmalloc (len + 1); | |
9a619af0 | 13427 | |
2e276125 JB |
13428 | memcpy (s, buf, len); |
13429 | s[len] = '\0'; | |
2e276125 JB |
13430 | return s; |
13431 | } | |
13432 | ||
13433 | ||
13434 | static const char * | |
13435 | consume_improper_spaces (const char *p, const char *body) | |
13436 | { | |
13437 | if (*p == ' ') | |
13438 | { | |
4d3c2250 | 13439 | complaint (&symfile_complaints, |
e2e0b3e5 | 13440 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 13441 | body); |
2e276125 JB |
13442 | |
13443 | while (*p == ' ') | |
13444 | p++; | |
13445 | } | |
13446 | ||
13447 | return p; | |
13448 | } | |
13449 | ||
13450 | ||
13451 | static void | |
13452 | parse_macro_definition (struct macro_source_file *file, int line, | |
13453 | const char *body) | |
13454 | { | |
13455 | const char *p; | |
13456 | ||
13457 | /* The body string takes one of two forms. For object-like macro | |
13458 | definitions, it should be: | |
13459 | ||
13460 | <macro name> " " <definition> | |
13461 | ||
13462 | For function-like macro definitions, it should be: | |
13463 | ||
13464 | <macro name> "() " <definition> | |
13465 | or | |
13466 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
13467 | ||
13468 | Spaces may appear only where explicitly indicated, and in the | |
13469 | <definition>. | |
13470 | ||
13471 | The Dwarf 2 spec says that an object-like macro's name is always | |
13472 | followed by a space, but versions of GCC around March 2002 omit | |
6e70227d | 13473 | the space when the macro's definition is the empty string. |
2e276125 JB |
13474 | |
13475 | The Dwarf 2 spec says that there should be no spaces between the | |
13476 | formal arguments in a function-like macro's formal argument list, | |
13477 | but versions of GCC around March 2002 include spaces after the | |
13478 | commas. */ | |
13479 | ||
13480 | ||
13481 | /* Find the extent of the macro name. The macro name is terminated | |
13482 | by either a space or null character (for an object-like macro) or | |
13483 | an opening paren (for a function-like macro). */ | |
13484 | for (p = body; *p; p++) | |
13485 | if (*p == ' ' || *p == '(') | |
13486 | break; | |
13487 | ||
13488 | if (*p == ' ' || *p == '\0') | |
13489 | { | |
13490 | /* It's an object-like macro. */ | |
13491 | int name_len = p - body; | |
13492 | char *name = copy_string (body, name_len); | |
13493 | const char *replacement; | |
13494 | ||
13495 | if (*p == ' ') | |
13496 | replacement = body + name_len + 1; | |
13497 | else | |
13498 | { | |
4d3c2250 | 13499 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13500 | replacement = body + name_len; |
13501 | } | |
6e70227d | 13502 | |
2e276125 JB |
13503 | macro_define_object (file, line, name, replacement); |
13504 | ||
13505 | xfree (name); | |
13506 | } | |
13507 | else if (*p == '(') | |
13508 | { | |
13509 | /* It's a function-like macro. */ | |
13510 | char *name = copy_string (body, p - body); | |
13511 | int argc = 0; | |
13512 | int argv_size = 1; | |
13513 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
13514 | ||
13515 | p++; | |
13516 | ||
13517 | p = consume_improper_spaces (p, body); | |
13518 | ||
13519 | /* Parse the formal argument list. */ | |
13520 | while (*p && *p != ')') | |
13521 | { | |
13522 | /* Find the extent of the current argument name. */ | |
13523 | const char *arg_start = p; | |
13524 | ||
13525 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
13526 | p++; | |
13527 | ||
13528 | if (! *p || p == arg_start) | |
4d3c2250 | 13529 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13530 | else |
13531 | { | |
13532 | /* Make sure argv has room for the new argument. */ | |
13533 | if (argc >= argv_size) | |
13534 | { | |
13535 | argv_size *= 2; | |
13536 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
13537 | } | |
13538 | ||
13539 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
13540 | } | |
13541 | ||
13542 | p = consume_improper_spaces (p, body); | |
13543 | ||
13544 | /* Consume the comma, if present. */ | |
13545 | if (*p == ',') | |
13546 | { | |
13547 | p++; | |
13548 | ||
13549 | p = consume_improper_spaces (p, body); | |
13550 | } | |
13551 | } | |
13552 | ||
13553 | if (*p == ')') | |
13554 | { | |
13555 | p++; | |
13556 | ||
13557 | if (*p == ' ') | |
13558 | /* Perfectly formed definition, no complaints. */ | |
13559 | macro_define_function (file, line, name, | |
6e70227d | 13560 | argc, (const char **) argv, |
2e276125 JB |
13561 | p + 1); |
13562 | else if (*p == '\0') | |
13563 | { | |
13564 | /* Complain, but do define it. */ | |
4d3c2250 | 13565 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 | 13566 | macro_define_function (file, line, name, |
6e70227d | 13567 | argc, (const char **) argv, |
2e276125 JB |
13568 | p); |
13569 | } | |
13570 | else | |
13571 | /* Just complain. */ | |
4d3c2250 | 13572 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13573 | } |
13574 | else | |
13575 | /* Just complain. */ | |
4d3c2250 | 13576 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13577 | |
13578 | xfree (name); | |
13579 | { | |
13580 | int i; | |
13581 | ||
13582 | for (i = 0; i < argc; i++) | |
13583 | xfree (argv[i]); | |
13584 | } | |
13585 | xfree (argv); | |
13586 | } | |
13587 | else | |
4d3c2250 | 13588 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
13589 | } |
13590 | ||
13591 | ||
13592 | static void | |
13593 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
13594 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 13595 | struct dwarf2_cu *cu) |
2e276125 | 13596 | { |
fe1b8b76 | 13597 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 13598 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
13599 | enum dwarf_macinfo_record_type macinfo_type; |
13600 | int at_commandline; | |
2e276125 | 13601 | |
be391dca TT |
13602 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
13603 | &dwarf2_per_objfile->macinfo); | |
dce234bc | 13604 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 13605 | { |
e2e0b3e5 | 13606 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
13607 | return; |
13608 | } | |
13609 | ||
757a13d0 JK |
13610 | /* First pass: Find the name of the base filename. |
13611 | This filename is needed in order to process all macros whose definition | |
13612 | (or undefinition) comes from the command line. These macros are defined | |
13613 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
13614 | associated to the base file. | |
13615 | ||
13616 | To determine the base file name, we scan the macro definitions until we | |
13617 | reach the first DW_MACINFO_start_file entry. We then initialize | |
13618 | CURRENT_FILE accordingly so that any macro definition found before the | |
13619 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
13620 | ||
dce234bc PP |
13621 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
13622 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
13623 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 13624 | |
757a13d0 | 13625 | do |
2e276125 | 13626 | { |
2e276125 JB |
13627 | /* Do we at least have room for a macinfo type byte? */ |
13628 | if (mac_ptr >= mac_end) | |
13629 | { | |
757a13d0 JK |
13630 | /* Complaint is printed during the second pass as GDB will probably |
13631 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
13632 | break; | |
2e276125 JB |
13633 | } |
13634 | ||
13635 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
13636 | mac_ptr++; | |
13637 | ||
13638 | switch (macinfo_type) | |
13639 | { | |
13640 | /* A zero macinfo type indicates the end of the macro | |
13641 | information. */ | |
13642 | case 0: | |
757a13d0 JK |
13643 | break; |
13644 | ||
13645 | case DW_MACINFO_define: | |
13646 | case DW_MACINFO_undef: | |
13647 | /* Only skip the data by MAC_PTR. */ | |
13648 | { | |
13649 | unsigned int bytes_read; | |
13650 | ||
13651 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13652 | mac_ptr += bytes_read; | |
9b1c24c8 | 13653 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
13654 | mac_ptr += bytes_read; |
13655 | } | |
13656 | break; | |
13657 | ||
13658 | case DW_MACINFO_start_file: | |
13659 | { | |
13660 | unsigned int bytes_read; | |
13661 | int line, file; | |
13662 | ||
13663 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13664 | mac_ptr += bytes_read; | |
13665 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13666 | mac_ptr += bytes_read; | |
13667 | ||
13668 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
13669 | lh, cu->objfile); | |
13670 | } | |
13671 | break; | |
13672 | ||
13673 | case DW_MACINFO_end_file: | |
13674 | /* No data to skip by MAC_PTR. */ | |
13675 | break; | |
13676 | ||
13677 | case DW_MACINFO_vendor_ext: | |
13678 | /* Only skip the data by MAC_PTR. */ | |
13679 | { | |
13680 | unsigned int bytes_read; | |
13681 | ||
13682 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13683 | mac_ptr += bytes_read; | |
9b1c24c8 | 13684 | read_direct_string (abfd, mac_ptr, &bytes_read); |
757a13d0 JK |
13685 | mac_ptr += bytes_read; |
13686 | } | |
13687 | break; | |
13688 | ||
13689 | default: | |
13690 | break; | |
13691 | } | |
13692 | } while (macinfo_type != 0 && current_file == NULL); | |
13693 | ||
13694 | /* Second pass: Process all entries. | |
13695 | ||
13696 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
13697 | command-line macro definitions/undefinitions. This flag is unset when we | |
13698 | reach the first DW_MACINFO_start_file entry. */ | |
13699 | ||
dce234bc | 13700 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
13701 | |
13702 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
13703 | GDB is still reading the definitions from command line. First | |
13704 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
13705 | to create CURRENT_FILE for the main source holding also the command line | |
13706 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
13707 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
13708 | ||
13709 | at_commandline = 1; | |
13710 | ||
13711 | do | |
13712 | { | |
13713 | /* Do we at least have room for a macinfo type byte? */ | |
13714 | if (mac_ptr >= mac_end) | |
13715 | { | |
13716 | dwarf2_macros_too_long_complaint (); | |
13717 | break; | |
13718 | } | |
13719 | ||
13720 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
13721 | mac_ptr++; | |
13722 | ||
13723 | switch (macinfo_type) | |
13724 | { | |
13725 | /* A zero macinfo type indicates the end of the macro | |
13726 | information. */ | |
13727 | case 0: | |
13728 | break; | |
2e276125 JB |
13729 | |
13730 | case DW_MACINFO_define: | |
13731 | case DW_MACINFO_undef: | |
13732 | { | |
891d2f0b | 13733 | unsigned int bytes_read; |
2e276125 JB |
13734 | int line; |
13735 | char *body; | |
13736 | ||
13737 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13738 | mac_ptr += bytes_read; | |
9b1c24c8 | 13739 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
13740 | mac_ptr += bytes_read; |
13741 | ||
13742 | if (! current_file) | |
757a13d0 JK |
13743 | { |
13744 | /* DWARF violation as no main source is present. */ | |
13745 | complaint (&symfile_complaints, | |
13746 | _("debug info with no main source gives macro %s " | |
13747 | "on line %d: %s"), | |
6e70227d DE |
13748 | macinfo_type == DW_MACINFO_define ? |
13749 | _("definition") : | |
905e0470 PM |
13750 | macinfo_type == DW_MACINFO_undef ? |
13751 | _("undefinition") : | |
13752 | _("something-or-other"), line, body); | |
757a13d0 JK |
13753 | break; |
13754 | } | |
13755 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 13756 | complaint (&symfile_complaints, |
757a13d0 JK |
13757 | _("debug info gives %s macro %s with %s line %d: %s"), |
13758 | at_commandline ? _("command-line") : _("in-file"), | |
905e0470 | 13759 | macinfo_type == DW_MACINFO_define ? |
6e70227d | 13760 | _("definition") : |
905e0470 PM |
13761 | macinfo_type == DW_MACINFO_undef ? |
13762 | _("undefinition") : | |
13763 | _("something-or-other"), | |
757a13d0 JK |
13764 | line == 0 ? _("zero") : _("non-zero"), line, body); |
13765 | ||
13766 | if (macinfo_type == DW_MACINFO_define) | |
13767 | parse_macro_definition (current_file, line, body); | |
13768 | else if (macinfo_type == DW_MACINFO_undef) | |
13769 | macro_undef (current_file, line, body); | |
2e276125 JB |
13770 | } |
13771 | break; | |
13772 | ||
13773 | case DW_MACINFO_start_file: | |
13774 | { | |
891d2f0b | 13775 | unsigned int bytes_read; |
2e276125 JB |
13776 | int line, file; |
13777 | ||
13778 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13779 | mac_ptr += bytes_read; | |
13780 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13781 | mac_ptr += bytes_read; | |
13782 | ||
757a13d0 JK |
13783 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
13784 | complaint (&symfile_complaints, | |
13785 | _("debug info gives source %d included " | |
13786 | "from %s at %s line %d"), | |
13787 | file, at_commandline ? _("command-line") : _("file"), | |
13788 | line == 0 ? _("zero") : _("non-zero"), line); | |
13789 | ||
13790 | if (at_commandline) | |
13791 | { | |
13792 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
13793 | at_commandline = 0; | |
13794 | } | |
13795 | else | |
13796 | current_file = macro_start_file (file, line, | |
13797 | current_file, comp_dir, | |
13798 | lh, cu->objfile); | |
2e276125 JB |
13799 | } |
13800 | break; | |
13801 | ||
13802 | case DW_MACINFO_end_file: | |
13803 | if (! current_file) | |
4d3c2250 | 13804 | complaint (&symfile_complaints, |
e2e0b3e5 | 13805 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
13806 | else |
13807 | { | |
13808 | current_file = current_file->included_by; | |
13809 | if (! current_file) | |
13810 | { | |
13811 | enum dwarf_macinfo_record_type next_type; | |
13812 | ||
13813 | /* GCC circa March 2002 doesn't produce the zero | |
13814 | type byte marking the end of the compilation | |
13815 | unit. Complain if it's not there, but exit no | |
13816 | matter what. */ | |
13817 | ||
13818 | /* Do we at least have room for a macinfo type byte? */ | |
13819 | if (mac_ptr >= mac_end) | |
13820 | { | |
4d3c2250 | 13821 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
13822 | return; |
13823 | } | |
13824 | ||
13825 | /* We don't increment mac_ptr here, so this is just | |
13826 | a look-ahead. */ | |
13827 | next_type = read_1_byte (abfd, mac_ptr); | |
13828 | if (next_type != 0) | |
4d3c2250 | 13829 | complaint (&symfile_complaints, |
e2e0b3e5 | 13830 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
13831 | |
13832 | return; | |
13833 | } | |
13834 | } | |
13835 | break; | |
13836 | ||
13837 | case DW_MACINFO_vendor_ext: | |
13838 | { | |
891d2f0b | 13839 | unsigned int bytes_read; |
2e276125 JB |
13840 | int constant; |
13841 | char *string; | |
13842 | ||
13843 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
13844 | mac_ptr += bytes_read; | |
9b1c24c8 | 13845 | string = read_direct_string (abfd, mac_ptr, &bytes_read); |
2e276125 JB |
13846 | mac_ptr += bytes_read; |
13847 | ||
13848 | /* We don't recognize any vendor extensions. */ | |
13849 | } | |
13850 | break; | |
13851 | } | |
757a13d0 | 13852 | } while (macinfo_type != 0); |
2e276125 | 13853 | } |
8e19ed76 PS |
13854 | |
13855 | /* Check if the attribute's form is a DW_FORM_block* | |
13856 | if so return true else false. */ | |
13857 | static int | |
13858 | attr_form_is_block (struct attribute *attr) | |
13859 | { | |
13860 | return (attr == NULL ? 0 : | |
13861 | attr->form == DW_FORM_block1 | |
13862 | || attr->form == DW_FORM_block2 | |
13863 | || attr->form == DW_FORM_block4 | |
2dc7f7b3 TT |
13864 | || attr->form == DW_FORM_block |
13865 | || attr->form == DW_FORM_exprloc); | |
8e19ed76 | 13866 | } |
4c2df51b | 13867 | |
c6a0999f JB |
13868 | /* Return non-zero if ATTR's value is a section offset --- classes |
13869 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
13870 | You may use DW_UNSND (attr) to retrieve such offsets. | |
13871 | ||
13872 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
13873 | may have a value that belongs to more than one of these classes; it | |
13874 | would be ambiguous if we did, because we use the same forms for all | |
13875 | of them. */ | |
3690dd37 JB |
13876 | static int |
13877 | attr_form_is_section_offset (struct attribute *attr) | |
13878 | { | |
13879 | return (attr->form == DW_FORM_data4 | |
2dc7f7b3 TT |
13880 | || attr->form == DW_FORM_data8 |
13881 | || attr->form == DW_FORM_sec_offset); | |
3690dd37 JB |
13882 | } |
13883 | ||
13884 | ||
13885 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
13886 | zero otherwise. When this function returns true, you can apply | |
13887 | dwarf2_get_attr_constant_value to it. | |
13888 | ||
13889 | However, note that for some attributes you must check | |
13890 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
13891 | and DW_FORM_data8 are members of both the constant class, and of | |
13892 | the classes that contain offsets into other debug sections | |
13893 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
13894 | that, if an attribute's can be either a constant or one of the | |
13895 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
13896 | taken as section offsets, not constants. */ | |
13897 | static int | |
13898 | attr_form_is_constant (struct attribute *attr) | |
13899 | { | |
13900 | switch (attr->form) | |
13901 | { | |
13902 | case DW_FORM_sdata: | |
13903 | case DW_FORM_udata: | |
13904 | case DW_FORM_data1: | |
13905 | case DW_FORM_data2: | |
13906 | case DW_FORM_data4: | |
13907 | case DW_FORM_data8: | |
13908 | return 1; | |
13909 | default: | |
13910 | return 0; | |
13911 | } | |
13912 | } | |
13913 | ||
4c2df51b DJ |
13914 | static void |
13915 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 13916 | struct dwarf2_cu *cu) |
4c2df51b | 13917 | { |
3690dd37 | 13918 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
13919 | /* ".debug_loc" may not exist at all, or the offset may be outside |
13920 | the section. If so, fall through to the complaint in the | |
13921 | other branch. */ | |
dce234bc | 13922 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 13923 | { |
0d53c4c4 | 13924 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 13925 | |
4a146b47 | 13926 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13927 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
13928 | baton->per_cu = cu->per_cu; |
13929 | gdb_assert (baton->per_cu); | |
4c2df51b | 13930 | |
be391dca TT |
13931 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
13932 | &dwarf2_per_objfile->loc); | |
13933 | ||
0d53c4c4 DJ |
13934 | /* We don't know how long the location list is, but make sure we |
13935 | don't run off the edge of the section. */ | |
dce234bc PP |
13936 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
13937 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
13938 | baton->base_address = cu->base_address; |
13939 | if (cu->base_known == 0) | |
0d53c4c4 | 13940 | complaint (&symfile_complaints, |
e2e0b3e5 | 13941 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 13942 | |
768a979c | 13943 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
13944 | SYMBOL_LOCATION_BATON (sym) = baton; |
13945 | } | |
13946 | else | |
13947 | { | |
13948 | struct dwarf2_locexpr_baton *baton; | |
13949 | ||
4a146b47 | 13950 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 13951 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
13952 | baton->per_cu = cu->per_cu; |
13953 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
13954 | |
13955 | if (attr_form_is_block (attr)) | |
13956 | { | |
13957 | /* Note that we're just copying the block's data pointer | |
13958 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
13959 | info_buffer for SYM's objfile; right now we never release |
13960 | that buffer, but when we do clean up properly this may | |
13961 | need to change. */ | |
0d53c4c4 DJ |
13962 | baton->size = DW_BLOCK (attr)->size; |
13963 | baton->data = DW_BLOCK (attr)->data; | |
13964 | } | |
13965 | else | |
13966 | { | |
13967 | dwarf2_invalid_attrib_class_complaint ("location description", | |
13968 | SYMBOL_NATURAL_NAME (sym)); | |
13969 | baton->size = 0; | |
13970 | baton->data = NULL; | |
13971 | } | |
6e70227d | 13972 | |
768a979c | 13973 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
13974 | SYMBOL_LOCATION_BATON (sym) = baton; |
13975 | } | |
4c2df51b | 13976 | } |
6502dd73 | 13977 | |
9aa1f1e3 TT |
13978 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
13979 | came from a separate debuginfo file, then the master objfile is | |
13980 | returned. */ | |
ae0d2f24 UW |
13981 | |
13982 | struct objfile * | |
13983 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
13984 | { | |
9291a0cd | 13985 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
13986 | |
13987 | /* Return the master objfile, so that we can report and look up the | |
13988 | correct file containing this variable. */ | |
13989 | if (objfile->separate_debug_objfile_backlink) | |
13990 | objfile = objfile->separate_debug_objfile_backlink; | |
13991 | ||
13992 | return objfile; | |
13993 | } | |
13994 | ||
13995 | /* Return the address size given in the compilation unit header for CU. */ | |
13996 | ||
13997 | CORE_ADDR | |
13998 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
13999 | { | |
14000 | if (per_cu->cu) | |
14001 | return per_cu->cu->header.addr_size; | |
14002 | else | |
14003 | { | |
14004 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14005 | struct objfile *objfile = per_cu->objfile; |
ae0d2f24 UW |
14006 | struct dwarf2_per_objfile *per_objfile |
14007 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 14008 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 | 14009 | struct comp_unit_head cu_header; |
9a619af0 | 14010 | |
ae0d2f24 UW |
14011 | memset (&cu_header, 0, sizeof cu_header); |
14012 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14013 | return cu_header.addr_size; | |
14014 | } | |
14015 | } | |
14016 | ||
9eae7c52 TT |
14017 | /* Return the offset size given in the compilation unit header for CU. */ |
14018 | ||
14019 | int | |
14020 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) | |
14021 | { | |
14022 | if (per_cu->cu) | |
14023 | return per_cu->cu->header.offset_size; | |
14024 | else | |
14025 | { | |
14026 | /* If the CU is not currently read in, we re-read its header. */ | |
9291a0cd | 14027 | struct objfile *objfile = per_cu->objfile; |
9eae7c52 TT |
14028 | struct dwarf2_per_objfile *per_objfile |
14029 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
14030 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; | |
14031 | struct comp_unit_head cu_header; | |
14032 | ||
14033 | memset (&cu_header, 0, sizeof cu_header); | |
14034 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
14035 | return cu_header.offset_size; | |
14036 | } | |
14037 | } | |
14038 | ||
9aa1f1e3 TT |
14039 | /* Return the text offset of the CU. The returned offset comes from |
14040 | this CU's objfile. If this objfile came from a separate debuginfo | |
14041 | file, then the offset may be different from the corresponding | |
14042 | offset in the parent objfile. */ | |
14043 | ||
14044 | CORE_ADDR | |
14045 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) | |
14046 | { | |
bb3fa9d0 | 14047 | struct objfile *objfile = per_cu->objfile; |
9aa1f1e3 TT |
14048 | |
14049 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
14050 | } | |
14051 | ||
348e048f DE |
14052 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
14053 | the DIE at OFFSET. Raises an error on failure. */ | |
ae038cb0 DJ |
14054 | |
14055 | static struct dwarf2_per_cu_data * | |
c764a876 | 14056 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
14057 | struct objfile *objfile) |
14058 | { | |
14059 | struct dwarf2_per_cu_data *this_cu; | |
14060 | int low, high; | |
14061 | ||
ae038cb0 DJ |
14062 | low = 0; |
14063 | high = dwarf2_per_objfile->n_comp_units - 1; | |
14064 | while (high > low) | |
14065 | { | |
14066 | int mid = low + (high - low) / 2; | |
9a619af0 | 14067 | |
ae038cb0 DJ |
14068 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
14069 | high = mid; | |
14070 | else | |
14071 | low = mid + 1; | |
14072 | } | |
14073 | gdb_assert (low == high); | |
14074 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
14075 | { | |
10b3939b | 14076 | if (low == 0) |
8a3fe4f8 AC |
14077 | error (_("Dwarf Error: could not find partial DIE containing " |
14078 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
14079 | (long) offset, bfd_get_filename (objfile->obfd)); |
14080 | ||
ae038cb0 DJ |
14081 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
14082 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
14083 | } | |
14084 | else | |
14085 | { | |
14086 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
14087 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
14088 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 14089 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
14090 | gdb_assert (offset < this_cu->offset + this_cu->length); |
14091 | return this_cu; | |
14092 | } | |
14093 | } | |
14094 | ||
10b3939b DJ |
14095 | /* Locate the compilation unit from OBJFILE which is located at exactly |
14096 | OFFSET. Raises an error on failure. */ | |
14097 | ||
ae038cb0 | 14098 | static struct dwarf2_per_cu_data * |
c764a876 | 14099 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
14100 | { |
14101 | struct dwarf2_per_cu_data *this_cu; | |
9a619af0 | 14102 | |
ae038cb0 DJ |
14103 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
14104 | if (this_cu->offset != offset) | |
c764a876 | 14105 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
14106 | return this_cu; |
14107 | } | |
14108 | ||
93311388 DE |
14109 | /* Malloc space for a dwarf2_cu for OBJFILE and initialize it. */ |
14110 | ||
14111 | static struct dwarf2_cu * | |
14112 | alloc_one_comp_unit (struct objfile *objfile) | |
14113 | { | |
14114 | struct dwarf2_cu *cu = xcalloc (1, sizeof (struct dwarf2_cu)); | |
14115 | cu->objfile = objfile; | |
14116 | obstack_init (&cu->comp_unit_obstack); | |
14117 | return cu; | |
14118 | } | |
14119 | ||
ae038cb0 DJ |
14120 | /* Release one cached compilation unit, CU. We unlink it from the tree |
14121 | of compilation units, but we don't remove it from the read_in_chain; | |
93311388 DE |
14122 | the caller is responsible for that. |
14123 | NOTE: DATA is a void * because this function is also used as a | |
14124 | cleanup routine. */ | |
ae038cb0 DJ |
14125 | |
14126 | static void | |
14127 | free_one_comp_unit (void *data) | |
14128 | { | |
14129 | struct dwarf2_cu *cu = data; | |
14130 | ||
14131 | if (cu->per_cu != NULL) | |
14132 | cu->per_cu->cu = NULL; | |
14133 | cu->per_cu = NULL; | |
14134 | ||
14135 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14136 | ||
14137 | xfree (cu); | |
14138 | } | |
14139 | ||
72bf9492 | 14140 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
14141 | when we're finished with it. We can't free the pointer itself, but be |
14142 | sure to unlink it from the cache. Also release any associated storage | |
14143 | and perform cache maintenance. | |
72bf9492 DJ |
14144 | |
14145 | Only used during partial symbol parsing. */ | |
14146 | ||
14147 | static void | |
14148 | free_stack_comp_unit (void *data) | |
14149 | { | |
14150 | struct dwarf2_cu *cu = data; | |
14151 | ||
14152 | obstack_free (&cu->comp_unit_obstack, NULL); | |
14153 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
14154 | |
14155 | if (cu->per_cu != NULL) | |
14156 | { | |
14157 | /* This compilation unit is on the stack in our caller, so we | |
14158 | should not xfree it. Just unlink it. */ | |
14159 | cu->per_cu->cu = NULL; | |
14160 | cu->per_cu = NULL; | |
14161 | ||
14162 | /* If we had a per-cu pointer, then we may have other compilation | |
14163 | units loaded, so age them now. */ | |
14164 | age_cached_comp_units (); | |
14165 | } | |
14166 | } | |
14167 | ||
14168 | /* Free all cached compilation units. */ | |
14169 | ||
14170 | static void | |
14171 | free_cached_comp_units (void *data) | |
14172 | { | |
14173 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14174 | ||
14175 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14176 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14177 | while (per_cu != NULL) | |
14178 | { | |
14179 | struct dwarf2_per_cu_data *next_cu; | |
14180 | ||
14181 | next_cu = per_cu->cu->read_in_chain; | |
14182 | ||
14183 | free_one_comp_unit (per_cu->cu); | |
14184 | *last_chain = next_cu; | |
14185 | ||
14186 | per_cu = next_cu; | |
14187 | } | |
14188 | } | |
14189 | ||
14190 | /* Increase the age counter on each cached compilation unit, and free | |
14191 | any that are too old. */ | |
14192 | ||
14193 | static void | |
14194 | age_cached_comp_units (void) | |
14195 | { | |
14196 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14197 | ||
14198 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
14199 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14200 | while (per_cu != NULL) | |
14201 | { | |
14202 | per_cu->cu->last_used ++; | |
14203 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
14204 | dwarf2_mark (per_cu->cu); | |
14205 | per_cu = per_cu->cu->read_in_chain; | |
14206 | } | |
14207 | ||
14208 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14209 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14210 | while (per_cu != NULL) | |
14211 | { | |
14212 | struct dwarf2_per_cu_data *next_cu; | |
14213 | ||
14214 | next_cu = per_cu->cu->read_in_chain; | |
14215 | ||
14216 | if (!per_cu->cu->mark) | |
14217 | { | |
14218 | free_one_comp_unit (per_cu->cu); | |
14219 | *last_chain = next_cu; | |
14220 | } | |
14221 | else | |
14222 | last_chain = &per_cu->cu->read_in_chain; | |
14223 | ||
14224 | per_cu = next_cu; | |
14225 | } | |
14226 | } | |
14227 | ||
14228 | /* Remove a single compilation unit from the cache. */ | |
14229 | ||
14230 | static void | |
14231 | free_one_cached_comp_unit (void *target_cu) | |
14232 | { | |
14233 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
14234 | ||
14235 | per_cu = dwarf2_per_objfile->read_in_chain; | |
14236 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
14237 | while (per_cu != NULL) | |
14238 | { | |
14239 | struct dwarf2_per_cu_data *next_cu; | |
14240 | ||
14241 | next_cu = per_cu->cu->read_in_chain; | |
14242 | ||
14243 | if (per_cu->cu == target_cu) | |
14244 | { | |
14245 | free_one_comp_unit (per_cu->cu); | |
14246 | *last_chain = next_cu; | |
14247 | break; | |
14248 | } | |
14249 | else | |
14250 | last_chain = &per_cu->cu->read_in_chain; | |
14251 | ||
14252 | per_cu = next_cu; | |
14253 | } | |
14254 | } | |
14255 | ||
fe3e1990 DJ |
14256 | /* Release all extra memory associated with OBJFILE. */ |
14257 | ||
14258 | void | |
14259 | dwarf2_free_objfile (struct objfile *objfile) | |
14260 | { | |
14261 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
14262 | ||
14263 | if (dwarf2_per_objfile == NULL) | |
14264 | return; | |
14265 | ||
14266 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
14267 | free_cached_comp_units (NULL); | |
14268 | ||
9291a0cd TT |
14269 | if (dwarf2_per_objfile->using_index) |
14270 | { | |
14271 | int i; | |
14272 | ||
14273 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) | |
14274 | { | |
14275 | int j; | |
e254ef6a DE |
14276 | struct dwarf2_per_cu_data *per_cu = |
14277 | dwarf2_per_objfile->all_comp_units[i]; | |
9291a0cd | 14278 | |
e254ef6a | 14279 | if (!per_cu->v.quick->lines) |
9291a0cd TT |
14280 | continue; |
14281 | ||
e254ef6a | 14282 | for (j = 0; j < per_cu->v.quick->lines->num_file_names; ++j) |
9291a0cd | 14283 | { |
e254ef6a DE |
14284 | if (per_cu->v.quick->file_names) |
14285 | xfree ((void *) per_cu->v.quick->file_names[j]); | |
14286 | if (per_cu->v.quick->full_names) | |
14287 | xfree ((void *) per_cu->v.quick->full_names[j]); | |
9291a0cd TT |
14288 | } |
14289 | ||
e254ef6a | 14290 | free_line_header (per_cu->v.quick->lines); |
9291a0cd TT |
14291 | } |
14292 | } | |
14293 | ||
fe3e1990 DJ |
14294 | /* Everything else should be on the objfile obstack. */ |
14295 | } | |
14296 | ||
1c379e20 DJ |
14297 | /* A pair of DIE offset and GDB type pointer. We store these |
14298 | in a hash table separate from the DIEs, and preserve them | |
14299 | when the DIEs are flushed out of cache. */ | |
14300 | ||
14301 | struct dwarf2_offset_and_type | |
14302 | { | |
14303 | unsigned int offset; | |
14304 | struct type *type; | |
14305 | }; | |
14306 | ||
14307 | /* Hash function for a dwarf2_offset_and_type. */ | |
14308 | ||
14309 | static hashval_t | |
14310 | offset_and_type_hash (const void *item) | |
14311 | { | |
14312 | const struct dwarf2_offset_and_type *ofs = item; | |
9a619af0 | 14313 | |
1c379e20 DJ |
14314 | return ofs->offset; |
14315 | } | |
14316 | ||
14317 | /* Equality function for a dwarf2_offset_and_type. */ | |
14318 | ||
14319 | static int | |
14320 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
14321 | { | |
14322 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
14323 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9a619af0 | 14324 | |
1c379e20 DJ |
14325 | return ofs_lhs->offset == ofs_rhs->offset; |
14326 | } | |
14327 | ||
14328 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
7e314c57 JK |
14329 | table if necessary. For convenience, return TYPE. |
14330 | ||
14331 | The DIEs reading must have careful ordering to: | |
14332 | * Not cause infite loops trying to read in DIEs as a prerequisite for | |
14333 | reading current DIE. | |
14334 | * Not trying to dereference contents of still incompletely read in types | |
14335 | while reading in other DIEs. | |
14336 | * Enable referencing still incompletely read in types just by a pointer to | |
14337 | the type without accessing its fields. | |
14338 | ||
14339 | Therefore caller should follow these rules: | |
14340 | * Try to fetch any prerequisite types we may need to build this DIE type | |
14341 | before building the type and calling set_die_type. | |
e71ec853 | 14342 | * After building type call set_die_type for current DIE as soon as |
7e314c57 JK |
14343 | possible before fetching more types to complete the current type. |
14344 | * Make the type as complete as possible before fetching more types. */ | |
1c379e20 | 14345 | |
f792889a | 14346 | static struct type * |
1c379e20 DJ |
14347 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
14348 | { | |
14349 | struct dwarf2_offset_and_type **slot, ofs; | |
673bfd45 DE |
14350 | struct objfile *objfile = cu->objfile; |
14351 | htab_t *type_hash_ptr; | |
1c379e20 | 14352 | |
b4ba55a1 JB |
14353 | /* For Ada types, make sure that the gnat-specific data is always |
14354 | initialized (if not already set). There are a few types where | |
14355 | we should not be doing so, because the type-specific area is | |
14356 | already used to hold some other piece of info (eg: TYPE_CODE_FLT | |
14357 | where the type-specific area is used to store the floatformat). | |
14358 | But this is not a problem, because the gnat-specific information | |
14359 | is actually not needed for these types. */ | |
14360 | if (need_gnat_info (cu) | |
14361 | && TYPE_CODE (type) != TYPE_CODE_FUNC | |
14362 | && TYPE_CODE (type) != TYPE_CODE_FLT | |
14363 | && !HAVE_GNAT_AUX_INFO (type)) | |
14364 | INIT_GNAT_SPECIFIC (type); | |
14365 | ||
673bfd45 DE |
14366 | if (cu->per_cu->from_debug_types) |
14367 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; | |
14368 | else | |
14369 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; | |
14370 | ||
14371 | if (*type_hash_ptr == NULL) | |
f792889a | 14372 | { |
673bfd45 DE |
14373 | *type_hash_ptr |
14374 | = htab_create_alloc_ex (127, | |
f792889a DJ |
14375 | offset_and_type_hash, |
14376 | offset_and_type_eq, | |
14377 | NULL, | |
673bfd45 | 14378 | &objfile->objfile_obstack, |
f792889a DJ |
14379 | hashtab_obstack_allocate, |
14380 | dummy_obstack_deallocate); | |
f792889a | 14381 | } |
1c379e20 DJ |
14382 | |
14383 | ofs.offset = die->offset; | |
14384 | ofs.type = type; | |
14385 | slot = (struct dwarf2_offset_and_type **) | |
673bfd45 | 14386 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
7e314c57 JK |
14387 | if (*slot) |
14388 | complaint (&symfile_complaints, | |
14389 | _("A problem internal to GDB: DIE 0x%x has type already set"), | |
14390 | die->offset); | |
673bfd45 | 14391 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
1c379e20 | 14392 | **slot = ofs; |
f792889a | 14393 | return type; |
1c379e20 DJ |
14394 | } |
14395 | ||
673bfd45 DE |
14396 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
14397 | table, or return NULL if the die does not have a saved type. */ | |
1c379e20 DJ |
14398 | |
14399 | static struct type * | |
673bfd45 DE |
14400 | get_die_type_at_offset (unsigned int offset, |
14401 | struct dwarf2_per_cu_data *per_cu) | |
1c379e20 DJ |
14402 | { |
14403 | struct dwarf2_offset_and_type *slot, ofs; | |
673bfd45 | 14404 | htab_t type_hash; |
f792889a | 14405 | |
673bfd45 DE |
14406 | if (per_cu->from_debug_types) |
14407 | type_hash = dwarf2_per_objfile->debug_types_type_hash; | |
14408 | else | |
14409 | type_hash = dwarf2_per_objfile->debug_info_type_hash; | |
f792889a DJ |
14410 | if (type_hash == NULL) |
14411 | return NULL; | |
1c379e20 | 14412 | |
673bfd45 | 14413 | ofs.offset = offset; |
1c379e20 DJ |
14414 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
14415 | if (slot) | |
14416 | return slot->type; | |
14417 | else | |
14418 | return NULL; | |
14419 | } | |
14420 | ||
673bfd45 DE |
14421 | /* Look up the type for DIE in the appropriate type_hash table, |
14422 | or return NULL if DIE does not have a saved type. */ | |
14423 | ||
14424 | static struct type * | |
14425 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) | |
14426 | { | |
14427 | return get_die_type_at_offset (die->offset, cu->per_cu); | |
14428 | } | |
14429 | ||
10b3939b DJ |
14430 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
14431 | ||
14432 | static void | |
14433 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
14434 | struct dwarf2_per_cu_data *ref_per_cu) | |
14435 | { | |
14436 | void **slot; | |
14437 | ||
14438 | if (cu->dependencies == NULL) | |
14439 | cu->dependencies | |
14440 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
14441 | NULL, &cu->comp_unit_obstack, | |
14442 | hashtab_obstack_allocate, | |
14443 | dummy_obstack_deallocate); | |
14444 | ||
14445 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
14446 | if (*slot == NULL) | |
14447 | *slot = ref_per_cu; | |
14448 | } | |
1c379e20 | 14449 | |
f504f079 DE |
14450 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
14451 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
14452 | cache that we must keep because we are keeping CU. */ |
14453 | ||
10b3939b DJ |
14454 | static int |
14455 | dwarf2_mark_helper (void **slot, void *data) | |
14456 | { | |
14457 | struct dwarf2_per_cu_data *per_cu; | |
14458 | ||
14459 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
14460 | if (per_cu->cu->mark) | |
14461 | return 1; | |
14462 | per_cu->cu->mark = 1; | |
14463 | ||
14464 | if (per_cu->cu->dependencies != NULL) | |
14465 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
14466 | ||
14467 | return 1; | |
14468 | } | |
14469 | ||
f504f079 DE |
14470 | /* Set the mark field in CU and in every other compilation unit in the |
14471 | cache that we must keep because we are keeping CU. */ | |
14472 | ||
ae038cb0 DJ |
14473 | static void |
14474 | dwarf2_mark (struct dwarf2_cu *cu) | |
14475 | { | |
14476 | if (cu->mark) | |
14477 | return; | |
14478 | cu->mark = 1; | |
10b3939b DJ |
14479 | if (cu->dependencies != NULL) |
14480 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
14481 | } |
14482 | ||
14483 | static void | |
14484 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
14485 | { | |
14486 | while (per_cu) | |
14487 | { | |
14488 | per_cu->cu->mark = 0; | |
14489 | per_cu = per_cu->cu->read_in_chain; | |
14490 | } | |
72bf9492 DJ |
14491 | } |
14492 | ||
72bf9492 DJ |
14493 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
14494 | is its offset in .debug_info for this objfile. */ | |
14495 | ||
14496 | static hashval_t | |
14497 | partial_die_hash (const void *item) | |
14498 | { | |
14499 | const struct partial_die_info *part_die = item; | |
9a619af0 | 14500 | |
72bf9492 DJ |
14501 | return part_die->offset; |
14502 | } | |
14503 | ||
14504 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
14505 | are equal if they have the same offset. */ | |
14506 | ||
14507 | static int | |
14508 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
14509 | { | |
14510 | const struct partial_die_info *part_die_lhs = item_lhs; | |
14511 | const struct partial_die_info *part_die_rhs = item_rhs; | |
9a619af0 | 14512 | |
72bf9492 DJ |
14513 | return part_die_lhs->offset == part_die_rhs->offset; |
14514 | } | |
14515 | ||
ae038cb0 DJ |
14516 | static struct cmd_list_element *set_dwarf2_cmdlist; |
14517 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
14518 | ||
14519 | static void | |
14520 | set_dwarf2_cmd (char *args, int from_tty) | |
14521 | { | |
14522 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
14523 | } | |
14524 | ||
14525 | static void | |
14526 | show_dwarf2_cmd (char *args, int from_tty) | |
6e70227d | 14527 | { |
ae038cb0 DJ |
14528 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
14529 | } | |
14530 | ||
dce234bc PP |
14531 | /* If section described by INFO was mmapped, munmap it now. */ |
14532 | ||
14533 | static void | |
14534 | munmap_section_buffer (struct dwarf2_section_info *info) | |
14535 | { | |
14536 | if (info->was_mmapped) | |
14537 | { | |
14538 | #ifdef HAVE_MMAP | |
14539 | intptr_t begin = (intptr_t) info->buffer; | |
14540 | intptr_t map_begin = begin & ~(pagesize - 1); | |
14541 | size_t map_length = info->size + begin - map_begin; | |
9a619af0 | 14542 | |
dce234bc PP |
14543 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
14544 | #else | |
14545 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
f3574227 | 14546 | gdb_assert_not_reached ("no mmap support"); |
dce234bc PP |
14547 | #endif |
14548 | } | |
14549 | } | |
14550 | ||
14551 | /* munmap debug sections for OBJFILE, if necessary. */ | |
14552 | ||
14553 | static void | |
c1bd65d0 | 14554 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
dce234bc PP |
14555 | { |
14556 | struct dwarf2_per_objfile *data = d; | |
9a619af0 | 14557 | |
16be1145 DE |
14558 | /* This is sorted according to the order they're defined in to make it easier |
14559 | to keep in sync. */ | |
dce234bc PP |
14560 | munmap_section_buffer (&data->info); |
14561 | munmap_section_buffer (&data->abbrev); | |
14562 | munmap_section_buffer (&data->line); | |
16be1145 | 14563 | munmap_section_buffer (&data->loc); |
dce234bc | 14564 | munmap_section_buffer (&data->macinfo); |
16be1145 | 14565 | munmap_section_buffer (&data->str); |
dce234bc | 14566 | munmap_section_buffer (&data->ranges); |
16be1145 | 14567 | munmap_section_buffer (&data->types); |
dce234bc PP |
14568 | munmap_section_buffer (&data->frame); |
14569 | munmap_section_buffer (&data->eh_frame); | |
9291a0cd TT |
14570 | munmap_section_buffer (&data->gdb_index); |
14571 | } | |
14572 | ||
14573 | \f | |
14574 | ||
14575 | /* The contents of the hash table we create when building the string | |
14576 | table. */ | |
14577 | struct strtab_entry | |
14578 | { | |
14579 | offset_type offset; | |
14580 | const char *str; | |
14581 | }; | |
14582 | ||
14583 | /* Hash function for a strtab_entry. */ | |
14584 | static hashval_t | |
14585 | hash_strtab_entry (const void *e) | |
14586 | { | |
14587 | const struct strtab_entry *entry = e; | |
14588 | return mapped_index_string_hash (entry->str); | |
14589 | } | |
14590 | ||
14591 | /* Equality function for a strtab_entry. */ | |
14592 | static int | |
14593 | eq_strtab_entry (const void *a, const void *b) | |
14594 | { | |
14595 | const struct strtab_entry *ea = a; | |
14596 | const struct strtab_entry *eb = b; | |
14597 | return !strcmp (ea->str, eb->str); | |
14598 | } | |
14599 | ||
14600 | /* Create a strtab_entry hash table. */ | |
14601 | static htab_t | |
14602 | create_strtab (void) | |
14603 | { | |
14604 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, | |
14605 | xfree, xcalloc, xfree); | |
14606 | } | |
14607 | ||
14608 | /* Add a string to the constant pool. Return the string's offset in | |
14609 | host order. */ | |
14610 | static offset_type | |
14611 | add_string (htab_t table, struct obstack *cpool, const char *str) | |
14612 | { | |
14613 | void **slot; | |
14614 | struct strtab_entry entry; | |
14615 | struct strtab_entry *result; | |
14616 | ||
14617 | entry.str = str; | |
14618 | slot = htab_find_slot (table, &entry, INSERT); | |
14619 | if (*slot) | |
14620 | result = *slot; | |
14621 | else | |
14622 | { | |
14623 | result = XNEW (struct strtab_entry); | |
14624 | result->offset = obstack_object_size (cpool); | |
14625 | result->str = str; | |
14626 | obstack_grow_str0 (cpool, str); | |
14627 | *slot = result; | |
14628 | } | |
14629 | return result->offset; | |
14630 | } | |
14631 | ||
14632 | /* An entry in the symbol table. */ | |
14633 | struct symtab_index_entry | |
14634 | { | |
14635 | /* The name of the symbol. */ | |
14636 | const char *name; | |
14637 | /* The offset of the name in the constant pool. */ | |
14638 | offset_type index_offset; | |
14639 | /* A sorted vector of the indices of all the CUs that hold an object | |
14640 | of this name. */ | |
14641 | VEC (offset_type) *cu_indices; | |
14642 | }; | |
14643 | ||
14644 | /* The symbol table. This is a power-of-2-sized hash table. */ | |
14645 | struct mapped_symtab | |
14646 | { | |
14647 | offset_type n_elements; | |
14648 | offset_type size; | |
14649 | struct symtab_index_entry **data; | |
14650 | }; | |
14651 | ||
14652 | /* Hash function for a symtab_index_entry. */ | |
14653 | static hashval_t | |
14654 | hash_symtab_entry (const void *e) | |
14655 | { | |
14656 | const struct symtab_index_entry *entry = e; | |
14657 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), | |
14658 | sizeof (offset_type) * VEC_length (offset_type, | |
14659 | entry->cu_indices), | |
14660 | 0); | |
14661 | } | |
14662 | ||
14663 | /* Equality function for a symtab_index_entry. */ | |
14664 | static int | |
14665 | eq_symtab_entry (const void *a, const void *b) | |
14666 | { | |
14667 | const struct symtab_index_entry *ea = a; | |
14668 | const struct symtab_index_entry *eb = b; | |
14669 | int len = VEC_length (offset_type, ea->cu_indices); | |
14670 | if (len != VEC_length (offset_type, eb->cu_indices)) | |
14671 | return 0; | |
14672 | return !memcmp (VEC_address (offset_type, ea->cu_indices), | |
14673 | VEC_address (offset_type, eb->cu_indices), | |
14674 | sizeof (offset_type) * len); | |
14675 | } | |
14676 | ||
14677 | /* Destroy a symtab_index_entry. */ | |
14678 | static void | |
14679 | delete_symtab_entry (void *p) | |
14680 | { | |
14681 | struct symtab_index_entry *entry = p; | |
14682 | VEC_free (offset_type, entry->cu_indices); | |
14683 | xfree (entry); | |
14684 | } | |
14685 | ||
14686 | /* Create a hash table holding symtab_index_entry objects. */ | |
14687 | static htab_t | |
14688 | create_index_table (void) | |
14689 | { | |
14690 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, | |
14691 | delete_symtab_entry, xcalloc, xfree); | |
14692 | } | |
14693 | ||
14694 | /* Create a new mapped symtab object. */ | |
14695 | static struct mapped_symtab * | |
14696 | create_mapped_symtab (void) | |
14697 | { | |
14698 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); | |
14699 | symtab->n_elements = 0; | |
14700 | symtab->size = 1024; | |
14701 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
14702 | return symtab; | |
14703 | } | |
14704 | ||
14705 | /* Destroy a mapped_symtab. */ | |
14706 | static void | |
14707 | cleanup_mapped_symtab (void *p) | |
14708 | { | |
14709 | struct mapped_symtab *symtab = p; | |
14710 | /* The contents of the array are freed when the other hash table is | |
14711 | destroyed. */ | |
14712 | xfree (symtab->data); | |
14713 | xfree (symtab); | |
14714 | } | |
14715 | ||
14716 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to | |
14717 | the slot. */ | |
14718 | static struct symtab_index_entry ** | |
14719 | find_slot (struct mapped_symtab *symtab, const char *name) | |
14720 | { | |
14721 | offset_type index, step, hash = mapped_index_string_hash (name); | |
14722 | ||
14723 | index = hash & (symtab->size - 1); | |
14724 | step = ((hash * 17) & (symtab->size - 1)) | 1; | |
14725 | ||
14726 | for (;;) | |
14727 | { | |
14728 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) | |
14729 | return &symtab->data[index]; | |
14730 | index = (index + step) & (symtab->size - 1); | |
14731 | } | |
14732 | } | |
14733 | ||
14734 | /* Expand SYMTAB's hash table. */ | |
14735 | static void | |
14736 | hash_expand (struct mapped_symtab *symtab) | |
14737 | { | |
14738 | offset_type old_size = symtab->size; | |
14739 | offset_type i; | |
14740 | struct symtab_index_entry **old_entries = symtab->data; | |
14741 | ||
14742 | symtab->size *= 2; | |
14743 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); | |
14744 | ||
14745 | for (i = 0; i < old_size; ++i) | |
14746 | { | |
14747 | if (old_entries[i]) | |
14748 | { | |
14749 | struct symtab_index_entry **slot = find_slot (symtab, | |
14750 | old_entries[i]->name); | |
14751 | *slot = old_entries[i]; | |
14752 | } | |
14753 | } | |
14754 | ||
14755 | xfree (old_entries); | |
14756 | } | |
14757 | ||
14758 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX | |
14759 | is the index of the CU in which the symbol appears. */ | |
14760 | static void | |
14761 | add_index_entry (struct mapped_symtab *symtab, const char *name, | |
14762 | offset_type cu_index) | |
14763 | { | |
14764 | struct symtab_index_entry **slot; | |
14765 | ||
14766 | ++symtab->n_elements; | |
14767 | if (4 * symtab->n_elements / 3 >= symtab->size) | |
14768 | hash_expand (symtab); | |
14769 | ||
14770 | slot = find_slot (symtab, name); | |
14771 | if (!*slot) | |
14772 | { | |
14773 | *slot = XNEW (struct symtab_index_entry); | |
14774 | (*slot)->name = name; | |
14775 | (*slot)->cu_indices = NULL; | |
14776 | } | |
14777 | /* Don't push an index twice. Due to how we add entries we only | |
14778 | have to check the last one. */ | |
14779 | if (VEC_empty (offset_type, (*slot)->cu_indices) | |
14780 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) | |
14781 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); | |
14782 | } | |
14783 | ||
14784 | /* Add a vector of indices to the constant pool. */ | |
14785 | static offset_type | |
14786 | add_indices_to_cpool (htab_t index_table, struct obstack *cpool, | |
14787 | struct symtab_index_entry *entry) | |
14788 | { | |
14789 | void **slot; | |
14790 | ||
14791 | slot = htab_find_slot (index_table, entry, INSERT); | |
14792 | if (!*slot) | |
14793 | { | |
14794 | offset_type len = VEC_length (offset_type, entry->cu_indices); | |
14795 | offset_type val = MAYBE_SWAP (len); | |
14796 | offset_type iter; | |
14797 | int i; | |
14798 | ||
14799 | *slot = entry; | |
14800 | entry->index_offset = obstack_object_size (cpool); | |
14801 | ||
14802 | obstack_grow (cpool, &val, sizeof (val)); | |
14803 | for (i = 0; | |
14804 | VEC_iterate (offset_type, entry->cu_indices, i, iter); | |
14805 | ++i) | |
14806 | { | |
14807 | val = MAYBE_SWAP (iter); | |
14808 | obstack_grow (cpool, &val, sizeof (val)); | |
14809 | } | |
14810 | } | |
14811 | else | |
14812 | { | |
14813 | struct symtab_index_entry *old_entry = *slot; | |
14814 | entry->index_offset = old_entry->index_offset; | |
14815 | entry = old_entry; | |
14816 | } | |
14817 | return entry->index_offset; | |
14818 | } | |
14819 | ||
14820 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with | |
14821 | constant pool entries going into the obstack CPOOL. */ | |
14822 | static void | |
14823 | write_hash_table (struct mapped_symtab *symtab, | |
14824 | struct obstack *output, struct obstack *cpool) | |
14825 | { | |
14826 | offset_type i; | |
14827 | htab_t index_table; | |
14828 | htab_t str_table; | |
14829 | ||
14830 | index_table = create_index_table (); | |
14831 | str_table = create_strtab (); | |
14832 | /* We add all the index vectors to the constant pool first, to | |
14833 | ensure alignment is ok. */ | |
14834 | for (i = 0; i < symtab->size; ++i) | |
14835 | { | |
14836 | if (symtab->data[i]) | |
14837 | add_indices_to_cpool (index_table, cpool, symtab->data[i]); | |
14838 | } | |
14839 | ||
14840 | /* Now write out the hash table. */ | |
14841 | for (i = 0; i < symtab->size; ++i) | |
14842 | { | |
14843 | offset_type str_off, vec_off; | |
14844 | ||
14845 | if (symtab->data[i]) | |
14846 | { | |
14847 | str_off = add_string (str_table, cpool, symtab->data[i]->name); | |
14848 | vec_off = symtab->data[i]->index_offset; | |
14849 | } | |
14850 | else | |
14851 | { | |
14852 | /* While 0 is a valid constant pool index, it is not valid | |
14853 | to have 0 for both offsets. */ | |
14854 | str_off = 0; | |
14855 | vec_off = 0; | |
14856 | } | |
14857 | ||
14858 | str_off = MAYBE_SWAP (str_off); | |
14859 | vec_off = MAYBE_SWAP (vec_off); | |
14860 | ||
14861 | obstack_grow (output, &str_off, sizeof (str_off)); | |
14862 | obstack_grow (output, &vec_off, sizeof (vec_off)); | |
14863 | } | |
14864 | ||
14865 | htab_delete (str_table); | |
14866 | htab_delete (index_table); | |
14867 | } | |
14868 | ||
14869 | /* Write an address entry to ADDR_OBSTACK. The addresses are taken | |
14870 | from PST; CU_INDEX is the index of the CU in the vector of all | |
14871 | CUs. */ | |
14872 | static void | |
14873 | add_address_entry (struct objfile *objfile, | |
14874 | struct obstack *addr_obstack, struct partial_symtab *pst, | |
14875 | unsigned int cu_index) | |
14876 | { | |
14877 | offset_type offset; | |
14878 | char addr[8]; | |
14879 | CORE_ADDR baseaddr; | |
14880 | ||
1fd400ff TT |
14881 | /* Don't bother recording empty ranges. */ |
14882 | if (pst->textlow == pst->texthigh) | |
14883 | return; | |
14884 | ||
9291a0cd TT |
14885 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
14886 | ||
14887 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->textlow - baseaddr); | |
14888 | obstack_grow (addr_obstack, addr, 8); | |
14889 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, pst->texthigh - baseaddr); | |
14890 | obstack_grow (addr_obstack, addr, 8); | |
14891 | offset = MAYBE_SWAP (cu_index); | |
14892 | obstack_grow (addr_obstack, &offset, sizeof (offset_type)); | |
14893 | } | |
14894 | ||
14895 | /* Add a list of partial symbols to SYMTAB. */ | |
14896 | static void | |
14897 | write_psymbols (struct mapped_symtab *symtab, | |
14898 | struct partial_symbol **psymp, | |
14899 | int count, | |
14900 | offset_type cu_index) | |
14901 | { | |
14902 | for (; count-- > 0; ++psymp) | |
14903 | { | |
14904 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) | |
14905 | error (_("Ada is not currently supported by the index")); | |
14906 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); | |
14907 | } | |
14908 | } | |
14909 | ||
14910 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an | |
14911 | exception if there is an error. */ | |
14912 | static void | |
14913 | write_obstack (FILE *file, struct obstack *obstack) | |
14914 | { | |
14915 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), | |
14916 | file) | |
14917 | != obstack_object_size (obstack)) | |
14918 | error (_("couldn't data write to file")); | |
14919 | } | |
14920 | ||
14921 | /* Unlink a file if the argument is not NULL. */ | |
14922 | static void | |
14923 | unlink_if_set (void *p) | |
14924 | { | |
14925 | char **filename = p; | |
14926 | if (*filename) | |
14927 | unlink (*filename); | |
14928 | } | |
14929 | ||
1fd400ff TT |
14930 | /* A helper struct used when iterating over debug_types. */ |
14931 | struct signatured_type_index_data | |
14932 | { | |
14933 | struct objfile *objfile; | |
14934 | struct mapped_symtab *symtab; | |
14935 | struct obstack *types_list; | |
14936 | int cu_index; | |
14937 | }; | |
14938 | ||
14939 | /* A helper function that writes a single signatured_type to an | |
14940 | obstack. */ | |
14941 | static int | |
14942 | write_one_signatured_type (void **slot, void *d) | |
14943 | { | |
14944 | struct signatured_type_index_data *info = d; | |
14945 | struct signatured_type *entry = (struct signatured_type *) *slot; | |
e254ef6a DE |
14946 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
14947 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
1fd400ff TT |
14948 | gdb_byte val[8]; |
14949 | ||
14950 | write_psymbols (info->symtab, | |
14951 | info->objfile->global_psymbols.list + psymtab->globals_offset, | |
14952 | psymtab->n_global_syms, info->cu_index); | |
14953 | write_psymbols (info->symtab, | |
14954 | info->objfile->static_psymbols.list + psymtab->statics_offset, | |
14955 | psymtab->n_static_syms, info->cu_index); | |
14956 | ||
14957 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset); | |
14958 | obstack_grow (info->types_list, val, 8); | |
14959 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); | |
14960 | obstack_grow (info->types_list, val, 8); | |
14961 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); | |
14962 | obstack_grow (info->types_list, val, 8); | |
14963 | ||
14964 | ++info->cu_index; | |
14965 | ||
14966 | return 1; | |
14967 | } | |
14968 | ||
9291a0cd TT |
14969 | /* Create an index file for OBJFILE in the directory DIR. */ |
14970 | static void | |
14971 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) | |
14972 | { | |
14973 | struct cleanup *cleanup; | |
14974 | char *filename, *cleanup_filename; | |
1fd400ff TT |
14975 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
14976 | struct obstack cu_list, types_cu_list; | |
9291a0cd TT |
14977 | int i; |
14978 | FILE *out_file; | |
14979 | struct mapped_symtab *symtab; | |
14980 | offset_type val, size_of_contents, total_len; | |
14981 | struct stat st; | |
14982 | char buf[8]; | |
14983 | ||
14984 | if (!objfile->psymtabs) | |
14985 | return; | |
14986 | if (dwarf2_per_objfile->using_index) | |
14987 | error (_("Cannot use an index to create the index")); | |
14988 | ||
14989 | if (stat (objfile->name, &st) < 0) | |
14990 | perror_with_name (_("Could not stat")); | |
14991 | ||
14992 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), | |
14993 | INDEX_SUFFIX, (char *) NULL); | |
14994 | cleanup = make_cleanup (xfree, filename); | |
14995 | ||
14996 | out_file = fopen (filename, "wb"); | |
14997 | if (!out_file) | |
14998 | error (_("Can't open `%s' for writing"), filename); | |
14999 | ||
15000 | cleanup_filename = filename; | |
15001 | make_cleanup (unlink_if_set, &cleanup_filename); | |
15002 | ||
15003 | symtab = create_mapped_symtab (); | |
15004 | make_cleanup (cleanup_mapped_symtab, symtab); | |
15005 | ||
15006 | obstack_init (&addr_obstack); | |
15007 | make_cleanup_obstack_free (&addr_obstack); | |
15008 | ||
15009 | obstack_init (&cu_list); | |
15010 | make_cleanup_obstack_free (&cu_list); | |
15011 | ||
1fd400ff TT |
15012 | obstack_init (&types_cu_list); |
15013 | make_cleanup_obstack_free (&types_cu_list); | |
15014 | ||
15015 | /* The list is already sorted, so we don't need to do additional | |
15016 | work here. Also, the debug_types entries do not appear in | |
15017 | all_comp_units, but only in their own hash table. */ | |
9291a0cd TT |
15018 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
15019 | { | |
e254ef6a DE |
15020 | struct dwarf2_per_cu_data *per_cu = dwarf2_per_objfile->all_comp_units[i]; |
15021 | struct partial_symtab *psymtab = per_cu->v.psymtab; | |
9291a0cd TT |
15022 | gdb_byte val[8]; |
15023 | ||
15024 | write_psymbols (symtab, | |
15025 | objfile->global_psymbols.list + psymtab->globals_offset, | |
15026 | psymtab->n_global_syms, i); | |
15027 | write_psymbols (symtab, | |
15028 | objfile->static_psymbols.list + psymtab->statics_offset, | |
15029 | psymtab->n_static_syms, i); | |
15030 | ||
15031 | add_address_entry (objfile, &addr_obstack, psymtab, i); | |
15032 | ||
e254ef6a | 15033 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
9291a0cd | 15034 | obstack_grow (&cu_list, val, 8); |
e254ef6a | 15035 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
9291a0cd TT |
15036 | obstack_grow (&cu_list, val, 8); |
15037 | } | |
15038 | ||
1fd400ff TT |
15039 | /* Write out the .debug_type entries, if any. */ |
15040 | if (dwarf2_per_objfile->signatured_types) | |
15041 | { | |
15042 | struct signatured_type_index_data sig_data; | |
15043 | ||
15044 | sig_data.objfile = objfile; | |
15045 | sig_data.symtab = symtab; | |
15046 | sig_data.types_list = &types_cu_list; | |
15047 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; | |
15048 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, | |
15049 | write_one_signatured_type, &sig_data); | |
15050 | } | |
15051 | ||
9291a0cd TT |
15052 | obstack_init (&constant_pool); |
15053 | make_cleanup_obstack_free (&constant_pool); | |
15054 | obstack_init (&symtab_obstack); | |
15055 | make_cleanup_obstack_free (&symtab_obstack); | |
15056 | write_hash_table (symtab, &symtab_obstack, &constant_pool); | |
15057 | ||
15058 | obstack_init (&contents); | |
15059 | make_cleanup_obstack_free (&contents); | |
1fd400ff | 15060 | size_of_contents = 6 * sizeof (offset_type); |
9291a0cd TT |
15061 | total_len = size_of_contents; |
15062 | ||
15063 | /* The version number. */ | |
1fd400ff | 15064 | val = MAYBE_SWAP (2); |
9291a0cd TT |
15065 | obstack_grow (&contents, &val, sizeof (val)); |
15066 | ||
15067 | /* The offset of the CU list from the start of the file. */ | |
15068 | val = MAYBE_SWAP (total_len); | |
15069 | obstack_grow (&contents, &val, sizeof (val)); | |
15070 | total_len += obstack_object_size (&cu_list); | |
15071 | ||
1fd400ff TT |
15072 | /* The offset of the types CU list from the start of the file. */ |
15073 | val = MAYBE_SWAP (total_len); | |
15074 | obstack_grow (&contents, &val, sizeof (val)); | |
15075 | total_len += obstack_object_size (&types_cu_list); | |
15076 | ||
9291a0cd TT |
15077 | /* The offset of the address table from the start of the file. */ |
15078 | val = MAYBE_SWAP (total_len); | |
15079 | obstack_grow (&contents, &val, sizeof (val)); | |
15080 | total_len += obstack_object_size (&addr_obstack); | |
15081 | ||
15082 | /* The offset of the symbol table from the start of the file. */ | |
15083 | val = MAYBE_SWAP (total_len); | |
15084 | obstack_grow (&contents, &val, sizeof (val)); | |
15085 | total_len += obstack_object_size (&symtab_obstack); | |
15086 | ||
15087 | /* The offset of the constant pool from the start of the file. */ | |
15088 | val = MAYBE_SWAP (total_len); | |
15089 | obstack_grow (&contents, &val, sizeof (val)); | |
15090 | total_len += obstack_object_size (&constant_pool); | |
15091 | ||
15092 | gdb_assert (obstack_object_size (&contents) == size_of_contents); | |
15093 | ||
15094 | write_obstack (out_file, &contents); | |
15095 | write_obstack (out_file, &cu_list); | |
1fd400ff | 15096 | write_obstack (out_file, &types_cu_list); |
9291a0cd TT |
15097 | write_obstack (out_file, &addr_obstack); |
15098 | write_obstack (out_file, &symtab_obstack); | |
15099 | write_obstack (out_file, &constant_pool); | |
15100 | ||
15101 | fclose (out_file); | |
15102 | ||
15103 | /* We want to keep the file, so we set cleanup_filename to NULL | |
15104 | here. See unlink_if_set. */ | |
15105 | cleanup_filename = NULL; | |
15106 | ||
15107 | do_cleanups (cleanup); | |
15108 | } | |
15109 | ||
15110 | /* The mapped index file format is designed to be directly mmap()able | |
15111 | on any architecture. In most cases, a datum is represented using a | |
15112 | little-endian 32-bit integer value, called an offset_type. Big | |
15113 | endian machines must byte-swap the values before using them. | |
15114 | Exceptions to this rule are noted. The data is laid out such that | |
15115 | alignment is always respected. | |
15116 | ||
15117 | A mapped index consists of several sections. | |
15118 | ||
15119 | 1. The file header. This is a sequence of values, of offset_type | |
15120 | unless otherwise noted: | |
1fd400ff TT |
15121 | [0] The version number. Currently 1 or 2. The differences are |
15122 | noted below. Version 1 did not account for .debug_types sections; | |
15123 | the presence of a .debug_types section invalidates any version 1 | |
15124 | index that may exist. | |
9291a0cd | 15125 | [1] The offset, from the start of the file, of the CU list. |
1fd400ff TT |
15126 | [1.5] In version 2, the offset, from the start of the file, of the |
15127 | types CU list. This offset does not appear in version 1. Note | |
15128 | that this can be empty, in which case this offset will be equal to | |
15129 | the next offset. | |
9291a0cd TT |
15130 | [2] The offset, from the start of the file, of the address section. |
15131 | [3] The offset, from the start of the file, of the symbol table. | |
15132 | [4] The offset, from the start of the file, of the constant pool. | |
15133 | ||
15134 | 2. The CU list. This is a sequence of pairs of 64-bit | |
1fd400ff TT |
15135 | little-endian values, sorted by the CU offset. The first element |
15136 | in each pair is the offset of a CU in the .debug_info section. The | |
15137 | second element in each pair is the length of that CU. References | |
15138 | to a CU elsewhere in the map are done using a CU index, which is | |
15139 | just the 0-based index into this table. Note that if there are | |
15140 | type CUs, then conceptually CUs and type CUs form a single list for | |
15141 | the purposes of CU indices. | |
15142 | ||
15143 | 2.5 The types CU list. This does not appear in a version 1 index. | |
15144 | This is a sequence of triplets of 64-bit little-endian values. In | |
15145 | a triplet, the first value is the CU offset, the second value is | |
15146 | the type offset in the CU, and the third value is the type | |
15147 | signature. The types CU list is not sorted. | |
9291a0cd TT |
15148 | |
15149 | 3. The address section. The address section consists of a sequence | |
15150 | of address entries. Each address entry has three elements. | |
15151 | [0] The low address. This is a 64-bit little-endian value. | |
15152 | [1] The high address. This is a 64-bit little-endian value. | |
15153 | [2] The CU index. This is an offset_type value. | |
15154 | ||
15155 | 4. The symbol table. This is a hash table. The size of the hash | |
15156 | table is always a power of 2. The initial hash and the step are | |
15157 | currently defined by the `find_slot' function. | |
15158 | ||
15159 | Each slot in the hash table consists of a pair of offset_type | |
15160 | values. The first value is the offset of the symbol's name in the | |
15161 | constant pool. The second value is the offset of the CU vector in | |
15162 | the constant pool. | |
15163 | ||
15164 | If both values are 0, then this slot in the hash table is empty. | |
15165 | This is ok because while 0 is a valid constant pool index, it | |
15166 | cannot be a valid index for both a string and a CU vector. | |
15167 | ||
15168 | A string in the constant pool is stored as a \0-terminated string, | |
15169 | as you'd expect. | |
15170 | ||
15171 | A CU vector in the constant pool is a sequence of offset_type | |
15172 | values. The first value is the number of CU indices in the vector. | |
15173 | Each subsequent value is the index of a CU in the CU list. This | |
15174 | element in the hash table is used to indicate which CUs define the | |
15175 | symbol. | |
15176 | ||
15177 | 5. The constant pool. This is simply a bunch of bytes. It is | |
15178 | organized so that alignment is correct: CU vectors are stored | |
15179 | first, followed by strings. */ | |
15180 | static void | |
15181 | save_gdb_index_command (char *arg, int from_tty) | |
15182 | { | |
15183 | struct objfile *objfile; | |
15184 | ||
15185 | if (!arg || !*arg) | |
96d19272 | 15186 | error (_("usage: save gdb-index DIRECTORY")); |
9291a0cd TT |
15187 | |
15188 | ALL_OBJFILES (objfile) | |
15189 | { | |
15190 | struct stat st; | |
15191 | ||
15192 | /* If the objfile does not correspond to an actual file, skip it. */ | |
15193 | if (stat (objfile->name, &st) < 0) | |
15194 | continue; | |
15195 | ||
15196 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
15197 | if (dwarf2_per_objfile) | |
15198 | { | |
15199 | volatile struct gdb_exception except; | |
15200 | ||
15201 | TRY_CATCH (except, RETURN_MASK_ERROR) | |
15202 | { | |
15203 | write_psymtabs_to_index (objfile, arg); | |
15204 | } | |
15205 | if (except.reason < 0) | |
15206 | exception_fprintf (gdb_stderr, except, | |
15207 | _("Error while writing index for `%s': "), | |
15208 | objfile->name); | |
15209 | } | |
15210 | } | |
dce234bc PP |
15211 | } |
15212 | ||
9291a0cd TT |
15213 | \f |
15214 | ||
9eae7c52 TT |
15215 | int dwarf2_always_disassemble; |
15216 | ||
15217 | static void | |
15218 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, | |
15219 | struct cmd_list_element *c, const char *value) | |
15220 | { | |
15221 | fprintf_filtered (file, _("\ | |
15222 | Whether to always disassemble DWARF expressions is %s.\n"), | |
15223 | value); | |
15224 | } | |
15225 | ||
6502dd73 DJ |
15226 | void _initialize_dwarf2_read (void); |
15227 | ||
15228 | void | |
15229 | _initialize_dwarf2_read (void) | |
15230 | { | |
96d19272 JK |
15231 | struct cmd_list_element *c; |
15232 | ||
dce234bc | 15233 | dwarf2_objfile_data_key |
c1bd65d0 | 15234 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
ae038cb0 | 15235 | |
1bedd215 AC |
15236 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
15237 | Set DWARF 2 specific variables.\n\ | |
15238 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
15239 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
15240 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
15241 | ||
1bedd215 AC |
15242 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
15243 | Show DWARF 2 specific variables\n\ | |
15244 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
15245 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
15246 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
15247 | ||
15248 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
15249 | &dwarf2_max_cache_age, _("\ |
15250 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
15251 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
15252 | A higher limit means that cached compilation units will be stored\n\ | |
15253 | in memory longer, and more total memory will be used. Zero disables\n\ | |
15254 | caching, which can slow down startup."), | |
2c5b56ce | 15255 | NULL, |
920d2a44 | 15256 | show_dwarf2_max_cache_age, |
2c5b56ce | 15257 | &set_dwarf2_cmdlist, |
ae038cb0 | 15258 | &show_dwarf2_cmdlist); |
d97bc12b | 15259 | |
9eae7c52 TT |
15260 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
15261 | &dwarf2_always_disassemble, _("\ | |
15262 | Set whether `info address' always disassembles DWARF expressions."), _("\ | |
15263 | Show whether `info address' always disassembles DWARF expressions."), _("\ | |
15264 | When enabled, DWARF expressions are always printed in an assembly-like\n\ | |
15265 | syntax. When disabled, expressions will be printed in a more\n\ | |
15266 | conversational style, when possible."), | |
15267 | NULL, | |
15268 | show_dwarf2_always_disassemble, | |
15269 | &set_dwarf2_cmdlist, | |
15270 | &show_dwarf2_cmdlist); | |
15271 | ||
d97bc12b DE |
15272 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
15273 | Set debugging of the dwarf2 DIE reader."), _("\ | |
15274 | Show debugging of the dwarf2 DIE reader."), _("\ | |
15275 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
15276 | The value is the maximum depth to print."), | |
15277 | NULL, | |
15278 | NULL, | |
15279 | &setdebuglist, &showdebuglist); | |
9291a0cd | 15280 | |
96d19272 JK |
15281 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
15282 | _("Save a .gdb-index file"), | |
15283 | &save_cmdlist); | |
15284 | set_cmd_completer (c, filename_completer); | |
6502dd73 | 15285 | } |