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, |
9b254dd1 | 4 | 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
7 | Inc. with support from Florida State University (under contract | |
8 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
9 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
10 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 11 | support. |
c906108c | 12 | |
c5aa993b | 13 | This file is part of GDB. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is free software; you can redistribute it and/or modify |
16 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
17 | the Free Software Foundation; either version 3 of the License, or |
18 | (at your option) any later version. | |
c906108c | 19 | |
a9762ec7 JB |
20 | This program is distributed in the hope that it will be useful, |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | GNU General Public License for more details. | |
c906108c | 24 | |
c5aa993b | 25 | You should have received a copy of the GNU General Public License |
a9762ec7 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
27 | |
28 | #include "defs.h" | |
29 | #include "bfd.h" | |
c906108c SS |
30 | #include "symtab.h" |
31 | #include "gdbtypes.h" | |
c906108c SS |
32 | #include "objfiles.h" |
33 | #include "elf/dwarf2.h" | |
34 | #include "buildsym.h" | |
35 | #include "demangle.h" | |
36 | #include "expression.h" | |
d5166ae1 | 37 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 38 | #include "macrotab.h" |
c906108c SS |
39 | #include "language.h" |
40 | #include "complaints.h" | |
357e46e7 | 41 | #include "bcache.h" |
4c2df51b DJ |
42 | #include "dwarf2expr.h" |
43 | #include "dwarf2loc.h" | |
9219021c | 44 | #include "cp-support.h" |
72bf9492 | 45 | #include "hashtab.h" |
ae038cb0 DJ |
46 | #include "command.h" |
47 | #include "gdbcmd.h" | |
ff013f42 | 48 | #include "addrmap.h" |
4c2df51b | 49 | |
c906108c SS |
50 | #include <fcntl.h> |
51 | #include "gdb_string.h" | |
4bdf3d34 | 52 | #include "gdb_assert.h" |
c906108c | 53 | #include <sys/types.h> |
233a11ab CS |
54 | #ifdef HAVE_ZLIB_H |
55 | #include <zlib.h> | |
56 | #endif | |
c906108c | 57 | |
d8151005 DJ |
58 | /* A note on memory usage for this file. |
59 | ||
60 | At the present time, this code reads the debug info sections into | |
61 | the objfile's objfile_obstack. A definite improvement for startup | |
62 | time, on platforms which do not emit relocations for debug | |
63 | sections, would be to use mmap instead. The object's complete | |
64 | debug information is loaded into memory, partly to simplify | |
65 | absolute DIE references. | |
66 | ||
67 | Whether using obstacks or mmap, the sections should remain loaded | |
68 | until the objfile is released, and pointers into the section data | |
69 | can be used for any other data associated to the objfile (symbol | |
70 | names, type names, location expressions to name a few). */ | |
71 | ||
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c SS |
88 | |
89 | /* .debug_pubnames header | |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct pubnames_header | |
93 | { | |
94 | unsigned int length; /* length of the .debug_pubnames | |
95 | contribution */ | |
96 | unsigned char version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int info_offset; /* offset into .debug_info section */ | |
99 | unsigned int info_size; /* byte size of .debug_info section | |
100 | portion */ | |
101 | } | |
102 | _PUBNAMES_HEADER; | |
103 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
104 | ||
105 | /* .debug_pubnames header | |
106 | Because of alignment constraints, this structure has padding and cannot | |
107 | be mapped directly onto the beginning of the .debug_info section. */ | |
108 | typedef struct aranges_header | |
109 | { | |
110 | unsigned int length; /* byte len of the .debug_aranges | |
111 | contribution */ | |
112 | unsigned short version; /* version number -- 2 for DWARF | |
113 | version 2 */ | |
114 | unsigned int info_offset; /* offset into .debug_info section */ | |
115 | unsigned char addr_size; /* byte size of an address */ | |
116 | unsigned char seg_size; /* byte size of segment descriptor */ | |
117 | } | |
118 | _ARANGES_HEADER; | |
119 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
120 | ||
121 | /* .debug_line statement program prologue | |
122 | Because of alignment constraints, this structure has padding and cannot | |
123 | be mapped directly onto the beginning of the .debug_info section. */ | |
124 | typedef struct statement_prologue | |
125 | { | |
126 | unsigned int total_length; /* byte length of the statement | |
127 | information */ | |
128 | unsigned short version; /* version number -- 2 for DWARF | |
129 | version 2 */ | |
130 | unsigned int prologue_length; /* # bytes between prologue & | |
131 | stmt program */ | |
132 | unsigned char minimum_instruction_length; /* byte size of | |
133 | smallest instr */ | |
134 | unsigned char default_is_stmt; /* initial value of is_stmt | |
135 | register */ | |
136 | char line_base; | |
137 | unsigned char line_range; | |
138 | unsigned char opcode_base; /* number assigned to first special | |
139 | opcode */ | |
140 | unsigned char *standard_opcode_lengths; | |
141 | } | |
142 | _STATEMENT_PROLOGUE; | |
143 | ||
d97bc12b DE |
144 | /* When non-zero, dump DIEs after they are read in. */ |
145 | static int dwarf2_die_debug = 0; | |
146 | ||
df8a16a1 DJ |
147 | /* When set, the file that we're processing is known to have debugging |
148 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
149 | but later versions do. */ | |
150 | ||
151 | static int processing_has_namespace_info; | |
152 | ||
6502dd73 DJ |
153 | static const struct objfile_data *dwarf2_objfile_data_key; |
154 | ||
155 | struct dwarf2_per_objfile | |
156 | { | |
157 | /* Sizes of debugging sections. */ | |
158 | unsigned int info_size; | |
159 | unsigned int abbrev_size; | |
160 | unsigned int line_size; | |
161 | unsigned int pubnames_size; | |
162 | unsigned int aranges_size; | |
163 | unsigned int loc_size; | |
164 | unsigned int macinfo_size; | |
165 | unsigned int str_size; | |
166 | unsigned int ranges_size; | |
167 | unsigned int frame_size; | |
168 | unsigned int eh_frame_size; | |
169 | ||
170 | /* Loaded data from the sections. */ | |
fe1b8b76 JB |
171 | gdb_byte *info_buffer; |
172 | gdb_byte *abbrev_buffer; | |
173 | gdb_byte *line_buffer; | |
174 | gdb_byte *str_buffer; | |
175 | gdb_byte *macinfo_buffer; | |
176 | gdb_byte *ranges_buffer; | |
177 | gdb_byte *loc_buffer; | |
ae038cb0 | 178 | |
10b3939b DJ |
179 | /* A list of all the compilation units. This is used to locate |
180 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
181 | struct dwarf2_per_cu_data **all_comp_units; |
182 | ||
183 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
184 | int n_comp_units; | |
185 | ||
186 | /* A chain of compilation units that are currently read in, so that | |
187 | they can be freed later. */ | |
188 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 FR |
189 | |
190 | /* A flag indicating wether this objfile has a section loaded at a | |
191 | VMA of 0. */ | |
192 | int has_section_at_zero; | |
6502dd73 DJ |
193 | }; |
194 | ||
195 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 196 | |
086df311 DJ |
197 | static asection *dwarf_info_section; |
198 | static asection *dwarf_abbrev_section; | |
199 | static asection *dwarf_line_section; | |
200 | static asection *dwarf_pubnames_section; | |
201 | static asection *dwarf_aranges_section; | |
202 | static asection *dwarf_loc_section; | |
203 | static asection *dwarf_macinfo_section; | |
204 | static asection *dwarf_str_section; | |
205 | static asection *dwarf_ranges_section; | |
206 | asection *dwarf_frame_section; | |
207 | asection *dwarf_eh_frame_section; | |
208 | ||
c906108c SS |
209 | /* names of the debugging sections */ |
210 | ||
233a11ab CS |
211 | /* Note that if the debugging section has been compressed, it might |
212 | have a name like .zdebug_info. */ | |
213 | ||
214 | #define INFO_SECTION "debug_info" | |
215 | #define ABBREV_SECTION "debug_abbrev" | |
216 | #define LINE_SECTION "debug_line" | |
217 | #define PUBNAMES_SECTION "debug_pubnames" | |
218 | #define ARANGES_SECTION "debug_aranges" | |
219 | #define LOC_SECTION "debug_loc" | |
220 | #define MACINFO_SECTION "debug_macinfo" | |
221 | #define STR_SECTION "debug_str" | |
222 | #define RANGES_SECTION "debug_ranges" | |
223 | #define FRAME_SECTION "debug_frame" | |
224 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
225 | |
226 | /* local data types */ | |
227 | ||
57349743 JB |
228 | /* We hold several abbreviation tables in memory at the same time. */ |
229 | #ifndef ABBREV_HASH_SIZE | |
230 | #define ABBREV_HASH_SIZE 121 | |
231 | #endif | |
232 | ||
107d2387 AC |
233 | /* The data in a compilation unit header, after target2host |
234 | translation, looks like this. */ | |
c906108c | 235 | struct comp_unit_head |
a738430d | 236 | { |
c764a876 | 237 | unsigned int length; |
a738430d | 238 | short version; |
a738430d MK |
239 | unsigned char addr_size; |
240 | unsigned char signed_addr_p; | |
9cbfa09e | 241 | unsigned int abbrev_offset; |
57349743 | 242 | |
a738430d MK |
243 | /* Size of file offsets; either 4 or 8. */ |
244 | unsigned int offset_size; | |
57349743 | 245 | |
a738430d MK |
246 | /* Size of the length field; either 4 or 12. */ |
247 | unsigned int initial_length_size; | |
57349743 | 248 | |
a738430d MK |
249 | /* Offset to the first byte of this compilation unit header in the |
250 | .debug_info section, for resolving relative reference dies. */ | |
251 | unsigned int offset; | |
57349743 | 252 | |
d00adf39 DE |
253 | /* Offset to first die in this cu from the start of the cu. |
254 | This will be the first byte following the compilation unit header. */ | |
255 | unsigned int first_die_offset; | |
a738430d | 256 | }; |
c906108c | 257 | |
e7c27a73 DJ |
258 | /* Internal state when decoding a particular compilation unit. */ |
259 | struct dwarf2_cu | |
260 | { | |
261 | /* The objfile containing this compilation unit. */ | |
262 | struct objfile *objfile; | |
263 | ||
d00adf39 | 264 | /* The header of the compilation unit. */ |
e7c27a73 | 265 | struct comp_unit_head header; |
e142c38c | 266 | |
d00adf39 DE |
267 | /* Base address of this compilation unit. */ |
268 | CORE_ADDR base_address; | |
269 | ||
270 | /* Non-zero if base_address has been set. */ | |
271 | int base_known; | |
272 | ||
e142c38c DJ |
273 | struct function_range *first_fn, *last_fn, *cached_fn; |
274 | ||
275 | /* The language we are debugging. */ | |
276 | enum language language; | |
277 | const struct language_defn *language_defn; | |
278 | ||
b0f35d58 DL |
279 | const char *producer; |
280 | ||
e142c38c DJ |
281 | /* The generic symbol table building routines have separate lists for |
282 | file scope symbols and all all other scopes (local scopes). So | |
283 | we need to select the right one to pass to add_symbol_to_list(). | |
284 | We do it by keeping a pointer to the correct list in list_in_scope. | |
285 | ||
286 | FIXME: The original dwarf code just treated the file scope as the | |
287 | first local scope, and all other local scopes as nested local | |
288 | scopes, and worked fine. Check to see if we really need to | |
289 | distinguish these in buildsym.c. */ | |
290 | struct pending **list_in_scope; | |
291 | ||
f3dd6933 DJ |
292 | /* DWARF abbreviation table associated with this compilation unit. */ |
293 | struct abbrev_info **dwarf2_abbrevs; | |
294 | ||
295 | /* Storage for the abbrev table. */ | |
296 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
297 | |
298 | /* Hash table holding all the loaded partial DIEs. */ | |
299 | htab_t partial_dies; | |
300 | ||
ff013f42 | 301 | /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */ |
c764a876 | 302 | unsigned int ranges_offset; |
ff013f42 | 303 | |
72bf9492 DJ |
304 | /* Storage for things with the same lifetime as this read-in compilation |
305 | unit, including partial DIEs. */ | |
306 | struct obstack comp_unit_obstack; | |
307 | ||
ae038cb0 DJ |
308 | /* When multiple dwarf2_cu structures are living in memory, this field |
309 | chains them all together, so that they can be released efficiently. | |
310 | We will probably also want a generation counter so that most-recently-used | |
311 | compilation units are cached... */ | |
312 | struct dwarf2_per_cu_data *read_in_chain; | |
313 | ||
314 | /* Backchain to our per_cu entry if the tree has been built. */ | |
315 | struct dwarf2_per_cu_data *per_cu; | |
316 | ||
f792889a DJ |
317 | /* Pointer to the die -> type map. Although it is stored |
318 | permanently in per_cu, we copy it here to avoid double | |
319 | indirection. */ | |
320 | htab_t type_hash; | |
321 | ||
ae038cb0 DJ |
322 | /* How many compilation units ago was this CU last referenced? */ |
323 | int last_used; | |
324 | ||
10b3939b | 325 | /* A hash table of die offsets for following references. */ |
51545339 | 326 | htab_t die_hash; |
10b3939b DJ |
327 | |
328 | /* Full DIEs if read in. */ | |
329 | struct die_info *dies; | |
330 | ||
331 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
332 | units referenced by this one. Only set during full symbol processing; | |
333 | partial symbol tables do not have dependencies. */ | |
334 | htab_t dependencies; | |
335 | ||
cb1df416 DJ |
336 | /* Header data from the line table, during full symbol processing. */ |
337 | struct line_header *line_header; | |
338 | ||
ae038cb0 DJ |
339 | /* Mark used when releasing cached dies. */ |
340 | unsigned int mark : 1; | |
341 | ||
342 | /* This flag will be set if this compilation unit might include | |
343 | inter-compilation-unit references. */ | |
344 | unsigned int has_form_ref_addr : 1; | |
345 | ||
72bf9492 DJ |
346 | /* This flag will be set if this compilation unit includes any |
347 | DW_TAG_namespace DIEs. If we know that there are explicit | |
348 | DIEs for namespaces, we don't need to try to infer them | |
349 | from mangled names. */ | |
350 | unsigned int has_namespace_info : 1; | |
ff013f42 JK |
351 | |
352 | /* Field `ranges_offset' is filled in; flag as the value may be zero. */ | |
353 | unsigned int has_ranges_offset : 1; | |
e7c27a73 DJ |
354 | }; |
355 | ||
10b3939b DJ |
356 | /* Persistent data held for a compilation unit, even when not |
357 | processing it. We put a pointer to this structure in the | |
358 | read_symtab_private field of the psymtab. If we encounter | |
359 | inter-compilation-unit references, we also maintain a sorted | |
360 | list of all compilation units. */ | |
361 | ||
ae038cb0 DJ |
362 | struct dwarf2_per_cu_data |
363 | { | |
5afb4e99 | 364 | /* The start offset and length of this compilation unit. 2**30-1 |
ae038cb0 | 365 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
366 | - if it doesn't, GDB will fall over anyway. |
367 | NOTE: Unlike comp_unit_head.length, this length includes | |
368 | initial_length_size. */ | |
c764a876 DE |
369 | unsigned int offset; |
370 | unsigned int length : 30; | |
ae038cb0 DJ |
371 | |
372 | /* Flag indicating this compilation unit will be read in before | |
373 | any of the current compilation units are processed. */ | |
c764a876 | 374 | unsigned int queued : 1; |
ae038cb0 | 375 | |
5afb4e99 DJ |
376 | /* This flag will be set if we need to load absolutely all DIEs |
377 | for this compilation unit, instead of just the ones we think | |
378 | are interesting. It gets set if we look for a DIE in the | |
379 | hash table and don't find it. */ | |
380 | unsigned int load_all_dies : 1; | |
381 | ||
ae038cb0 DJ |
382 | /* Set iff currently read in. */ |
383 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
384 | |
385 | /* If full symbols for this CU have been read in, then this field | |
386 | holds a map of DIE offsets to types. It isn't always possible | |
387 | to reconstruct this information later, so we have to preserve | |
388 | it. */ | |
1c379e20 | 389 | htab_t type_hash; |
10b3939b | 390 | |
31ffec48 DJ |
391 | /* The partial symbol table associated with this compilation unit, |
392 | or NULL for partial units (which do not have an associated | |
393 | symtab). */ | |
10b3939b | 394 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
395 | }; |
396 | ||
debd256d JB |
397 | /* The line number information for a compilation unit (found in the |
398 | .debug_line section) begins with a "statement program header", | |
399 | which contains the following information. */ | |
400 | struct line_header | |
401 | { | |
402 | unsigned int total_length; | |
403 | unsigned short version; | |
404 | unsigned int header_length; | |
405 | unsigned char minimum_instruction_length; | |
406 | unsigned char default_is_stmt; | |
407 | int line_base; | |
408 | unsigned char line_range; | |
409 | unsigned char opcode_base; | |
410 | ||
411 | /* standard_opcode_lengths[i] is the number of operands for the | |
412 | standard opcode whose value is i. This means that | |
413 | standard_opcode_lengths[0] is unused, and the last meaningful | |
414 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
415 | unsigned char *standard_opcode_lengths; | |
416 | ||
417 | /* The include_directories table. NOTE! These strings are not | |
418 | allocated with xmalloc; instead, they are pointers into | |
419 | debug_line_buffer. If you try to free them, `free' will get | |
420 | indigestion. */ | |
421 | unsigned int num_include_dirs, include_dirs_size; | |
422 | char **include_dirs; | |
423 | ||
424 | /* The file_names table. NOTE! These strings are not allocated | |
425 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
426 | Don't try to free them directly. */ | |
427 | unsigned int num_file_names, file_names_size; | |
428 | struct file_entry | |
c906108c | 429 | { |
debd256d JB |
430 | char *name; |
431 | unsigned int dir_index; | |
432 | unsigned int mod_time; | |
433 | unsigned int length; | |
aaa75496 | 434 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 435 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
436 | } *file_names; |
437 | ||
438 | /* The start and end of the statement program following this | |
6502dd73 | 439 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 440 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 441 | }; |
c906108c SS |
442 | |
443 | /* When we construct a partial symbol table entry we only | |
444 | need this much information. */ | |
445 | struct partial_die_info | |
446 | { | |
72bf9492 | 447 | /* Offset of this DIE. */ |
c906108c | 448 | unsigned int offset; |
72bf9492 DJ |
449 | |
450 | /* DWARF-2 tag for this DIE. */ | |
451 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
452 | ||
453 | /* Language code associated with this DIE. This is only used | |
454 | for the compilation unit DIE. */ | |
455 | unsigned int language : 8; | |
456 | ||
457 | /* Assorted flags describing the data found in this DIE. */ | |
458 | unsigned int has_children : 1; | |
459 | unsigned int is_external : 1; | |
460 | unsigned int is_declaration : 1; | |
461 | unsigned int has_type : 1; | |
462 | unsigned int has_specification : 1; | |
aaa75496 | 463 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
464 | unsigned int has_pc_info : 1; |
465 | ||
466 | /* Flag set if the SCOPE field of this structure has been | |
467 | computed. */ | |
468 | unsigned int scope_set : 1; | |
469 | ||
fa4028e9 JB |
470 | /* Flag set if the DIE has a byte_size attribute. */ |
471 | unsigned int has_byte_size : 1; | |
472 | ||
72bf9492 DJ |
473 | /* The name of this DIE. Normally the value of DW_AT_name, but |
474 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
475 | other fashion. */ | |
c906108c | 476 | char *name; |
57c22c6c | 477 | char *dirname; |
72bf9492 DJ |
478 | |
479 | /* The scope to prepend to our children. This is generally | |
480 | allocated on the comp_unit_obstack, so will disappear | |
481 | when this compilation unit leaves the cache. */ | |
482 | char *scope; | |
483 | ||
484 | /* The location description associated with this DIE, if any. */ | |
485 | struct dwarf_block *locdesc; | |
486 | ||
487 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
488 | CORE_ADDR lowpc; |
489 | CORE_ADDR highpc; | |
72bf9492 DJ |
490 | |
491 | /* Pointer into the info_buffer pointing at the target of | |
492 | DW_AT_sibling, if any. */ | |
fe1b8b76 | 493 | gdb_byte *sibling; |
72bf9492 DJ |
494 | |
495 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
496 | DW_AT_specification (or DW_AT_abstract_origin or | |
497 | DW_AT_extension). */ | |
498 | unsigned int spec_offset; | |
499 | ||
aaa75496 JB |
500 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
501 | unsigned int line_offset; | |
502 | ||
72bf9492 DJ |
503 | /* Pointers to this DIE's parent, first child, and next sibling, |
504 | if any. */ | |
505 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
506 | }; |
507 | ||
508 | /* This data structure holds the information of an abbrev. */ | |
509 | struct abbrev_info | |
510 | { | |
511 | unsigned int number; /* number identifying abbrev */ | |
512 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
513 | unsigned short has_children; /* boolean */ |
514 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
515 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
516 | struct abbrev_info *next; /* next in chain */ | |
517 | }; | |
518 | ||
519 | struct attr_abbrev | |
520 | { | |
9d25dd43 DE |
521 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
522 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
523 | }; |
524 | ||
b60c80d6 DJ |
525 | /* Attributes have a name and a value */ |
526 | struct attribute | |
527 | { | |
9d25dd43 DE |
528 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
529 | ENUM_BITFIELD(dwarf_form) form : 16; | |
b60c80d6 DJ |
530 | union |
531 | { | |
532 | char *str; | |
533 | struct dwarf_block *blk; | |
534 | unsigned long unsnd; | |
535 | long int snd; | |
536 | CORE_ADDR addr; | |
537 | } | |
538 | u; | |
539 | }; | |
540 | ||
c906108c SS |
541 | /* This data structure holds a complete die structure. */ |
542 | struct die_info | |
543 | { | |
76815b17 DE |
544 | /* DWARF-2 tag for this DIE. */ |
545 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
546 | ||
547 | /* Number of attributes */ | |
548 | unsigned short num_attrs; | |
549 | ||
550 | /* Abbrev number */ | |
551 | unsigned int abbrev; | |
552 | ||
553 | /* Offset in .debug_info section */ | |
554 | unsigned int offset; | |
78ba4af6 JB |
555 | |
556 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
557 | points to this die's parent; CHILD points to the first child of | |
558 | this node; and all the children of a given node are chained | |
559 | together via their SIBLING fields, terminated by a die whose | |
560 | tag is zero. */ | |
639d11d3 DC |
561 | struct die_info *child; /* Its first child, if any. */ |
562 | struct die_info *sibling; /* Its next sibling, if any. */ | |
563 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 564 | |
b60c80d6 DJ |
565 | /* An array of attributes, with NUM_ATTRS elements. There may be |
566 | zero, but it's not common and zero-sized arrays are not | |
567 | sufficiently portable C. */ | |
568 | struct attribute attrs[1]; | |
c906108c SS |
569 | }; |
570 | ||
5fb290d7 DJ |
571 | struct function_range |
572 | { | |
573 | const char *name; | |
574 | CORE_ADDR lowpc, highpc; | |
575 | int seen_line; | |
576 | struct function_range *next; | |
577 | }; | |
578 | ||
c906108c SS |
579 | /* Get at parts of an attribute structure */ |
580 | ||
581 | #define DW_STRING(attr) ((attr)->u.str) | |
582 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
583 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
584 | #define DW_SND(attr) ((attr)->u.snd) | |
585 | #define DW_ADDR(attr) ((attr)->u.addr) | |
586 | ||
587 | /* Blocks are a bunch of untyped bytes. */ | |
588 | struct dwarf_block | |
589 | { | |
590 | unsigned int size; | |
fe1b8b76 | 591 | gdb_byte *data; |
c906108c SS |
592 | }; |
593 | ||
c906108c SS |
594 | #ifndef ATTR_ALLOC_CHUNK |
595 | #define ATTR_ALLOC_CHUNK 4 | |
596 | #endif | |
597 | ||
c906108c SS |
598 | /* Allocate fields for structs, unions and enums in this size. */ |
599 | #ifndef DW_FIELD_ALLOC_CHUNK | |
600 | #define DW_FIELD_ALLOC_CHUNK 4 | |
601 | #endif | |
602 | ||
c906108c SS |
603 | /* A zeroed version of a partial die for initialization purposes. */ |
604 | static struct partial_die_info zeroed_partial_die; | |
605 | ||
c906108c SS |
606 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
607 | but this would require a corresponding change in unpack_field_as_long | |
608 | and friends. */ | |
609 | static int bits_per_byte = 8; | |
610 | ||
611 | /* The routines that read and process dies for a C struct or C++ class | |
612 | pass lists of data member fields and lists of member function fields | |
613 | in an instance of a field_info structure, as defined below. */ | |
614 | struct field_info | |
c5aa993b JM |
615 | { |
616 | /* List of data member and baseclasses fields. */ | |
617 | struct nextfield | |
618 | { | |
619 | struct nextfield *next; | |
620 | int accessibility; | |
621 | int virtuality; | |
622 | struct field field; | |
623 | } | |
624 | *fields; | |
c906108c | 625 | |
c5aa993b JM |
626 | /* Number of fields. */ |
627 | int nfields; | |
c906108c | 628 | |
c5aa993b JM |
629 | /* Number of baseclasses. */ |
630 | int nbaseclasses; | |
c906108c | 631 | |
c5aa993b JM |
632 | /* Set if the accesibility of one of the fields is not public. */ |
633 | int non_public_fields; | |
c906108c | 634 | |
c5aa993b JM |
635 | /* Member function fields array, entries are allocated in the order they |
636 | are encountered in the object file. */ | |
637 | struct nextfnfield | |
638 | { | |
639 | struct nextfnfield *next; | |
640 | struct fn_field fnfield; | |
641 | } | |
642 | *fnfields; | |
c906108c | 643 | |
c5aa993b JM |
644 | /* Member function fieldlist array, contains name of possibly overloaded |
645 | member function, number of overloaded member functions and a pointer | |
646 | to the head of the member function field chain. */ | |
647 | struct fnfieldlist | |
648 | { | |
649 | char *name; | |
650 | int length; | |
651 | struct nextfnfield *head; | |
652 | } | |
653 | *fnfieldlists; | |
c906108c | 654 | |
c5aa993b JM |
655 | /* Number of entries in the fnfieldlists array. */ |
656 | int nfnfields; | |
657 | }; | |
c906108c | 658 | |
10b3939b DJ |
659 | /* One item on the queue of compilation units to read in full symbols |
660 | for. */ | |
661 | struct dwarf2_queue_item | |
662 | { | |
663 | struct dwarf2_per_cu_data *per_cu; | |
664 | struct dwarf2_queue_item *next; | |
665 | }; | |
666 | ||
667 | /* The current queue. */ | |
668 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
669 | ||
ae038cb0 DJ |
670 | /* Loaded secondary compilation units are kept in memory until they |
671 | have not been referenced for the processing of this many | |
672 | compilation units. Set this to zero to disable caching. Cache | |
673 | sizes of up to at least twenty will improve startup time for | |
674 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
675 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
676 | static void |
677 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
678 | struct cmd_list_element *c, const char *value) | |
679 | { | |
680 | fprintf_filtered (file, _("\ | |
681 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
682 | value); | |
683 | } | |
684 | ||
ae038cb0 | 685 | |
c906108c SS |
686 | /* Various complaints about symbol reading that don't abort the process */ |
687 | ||
4d3c2250 KB |
688 | static void |
689 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 690 | { |
4d3c2250 | 691 | complaint (&symfile_complaints, |
e2e0b3e5 | 692 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
693 | } |
694 | ||
25e43795 DJ |
695 | static void |
696 | dwarf2_debug_line_missing_file_complaint (void) | |
697 | { | |
698 | complaint (&symfile_complaints, | |
699 | _(".debug_line section has line data without a file")); | |
700 | } | |
701 | ||
4d3c2250 KB |
702 | static void |
703 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 704 | { |
e2e0b3e5 | 705 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
706 | } |
707 | ||
4d3c2250 KB |
708 | static void |
709 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
710 | int arg3) | |
2e276125 | 711 | { |
4d3c2250 | 712 | complaint (&symfile_complaints, |
e2e0b3e5 | 713 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
714 | arg2, arg3); |
715 | } | |
716 | ||
717 | static void | |
718 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 719 | { |
4d3c2250 | 720 | complaint (&symfile_complaints, |
e2e0b3e5 | 721 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
722 | } |
723 | ||
724 | static void | |
725 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 726 | { |
4d3c2250 | 727 | complaint (&symfile_complaints, |
e2e0b3e5 | 728 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
729 | arg1); |
730 | } | |
731 | ||
732 | static void | |
733 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 734 | { |
4d3c2250 | 735 | complaint (&symfile_complaints, |
e2e0b3e5 | 736 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 737 | } |
c906108c | 738 | |
c906108c SS |
739 | /* local function prototypes */ |
740 | ||
4efb68b1 | 741 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
742 | |
743 | #if 0 | |
a14ed312 | 744 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
745 | #endif |
746 | ||
aaa75496 JB |
747 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
748 | struct objfile *); | |
749 | ||
750 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
751 | struct partial_die_info *, | |
752 | struct partial_symtab *); | |
753 | ||
a14ed312 | 754 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 755 | |
72bf9492 DJ |
756 | static void scan_partial_symbols (struct partial_die_info *, |
757 | CORE_ADDR *, CORE_ADDR *, | |
758 | struct dwarf2_cu *); | |
c906108c | 759 | |
72bf9492 DJ |
760 | static void add_partial_symbol (struct partial_die_info *, |
761 | struct dwarf2_cu *); | |
63d06c5c | 762 | |
72bf9492 | 763 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 764 | |
72bf9492 DJ |
765 | static void add_partial_namespace (struct partial_die_info *pdi, |
766 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
767 | struct dwarf2_cu *cu); | |
63d06c5c | 768 | |
72bf9492 DJ |
769 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
770 | struct dwarf2_cu *cu); | |
91c24f0a | 771 | |
bc30ff58 JB |
772 | static void add_partial_subprogram (struct partial_die_info *pdi, |
773 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
774 | struct dwarf2_cu *cu); | |
775 | ||
fe1b8b76 JB |
776 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
777 | gdb_byte *info_ptr, | |
778 | bfd *abfd, | |
779 | struct dwarf2_cu *cu); | |
91c24f0a | 780 | |
a14ed312 | 781 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 782 | |
a14ed312 | 783 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 784 | |
fe1b8b76 | 785 | gdb_byte *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 786 | |
e7c27a73 | 787 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 788 | |
f3dd6933 | 789 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 790 | |
fe1b8b76 | 791 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 792 | struct dwarf2_cu *); |
72bf9492 | 793 | |
57349743 | 794 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 795 | struct dwarf2_cu *); |
c906108c | 796 | |
fe1b8b76 | 797 | static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int, |
72bf9492 DJ |
798 | struct dwarf2_cu *); |
799 | ||
fe1b8b76 JB |
800 | static gdb_byte *read_partial_die (struct partial_die_info *, |
801 | struct abbrev_info *abbrev, unsigned int, | |
802 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 803 | |
c764a876 | 804 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 805 | struct dwarf2_cu *); |
72bf9492 DJ |
806 | |
807 | static void fixup_partial_die (struct partial_die_info *, | |
808 | struct dwarf2_cu *); | |
809 | ||
fe1b8b76 JB |
810 | static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *, |
811 | struct dwarf2_cu *, int *); | |
c906108c | 812 | |
fe1b8b76 JB |
813 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
814 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 815 | |
fe1b8b76 JB |
816 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
817 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 818 | |
fe1b8b76 | 819 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 820 | |
fe1b8b76 | 821 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 822 | |
fe1b8b76 | 823 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 824 | |
fe1b8b76 | 825 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 826 | |
fe1b8b76 | 827 | static unsigned long read_8_bytes (bfd *, gdb_byte *); |
c906108c | 828 | |
fe1b8b76 | 829 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 830 | unsigned int *); |
c906108c | 831 | |
c764a876 DE |
832 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
833 | ||
834 | static LONGEST read_checked_initial_length_and_offset | |
835 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
836 | unsigned int *, unsigned int *); | |
613e1657 | 837 | |
fe1b8b76 | 838 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
839 | unsigned int *); |
840 | ||
841 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 842 | |
fe1b8b76 | 843 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 844 | |
fe1b8b76 | 845 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 846 | |
fe1b8b76 JB |
847 | static char *read_indirect_string (bfd *, gdb_byte *, |
848 | const struct comp_unit_head *, | |
849 | unsigned int *); | |
4bdf3d34 | 850 | |
fe1b8b76 | 851 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 852 | |
fe1b8b76 | 853 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 854 | |
fe1b8b76 | 855 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 856 | |
e142c38c | 857 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 858 | |
e142c38c DJ |
859 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
860 | struct dwarf2_cu *); | |
c906108c | 861 | |
05cf31d1 JB |
862 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
863 | struct dwarf2_cu *cu); | |
864 | ||
e142c38c | 865 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 866 | |
e142c38c | 867 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 868 | struct dwarf2_cu **); |
63d06c5c | 869 | |
debd256d JB |
870 | static void free_line_header (struct line_header *lh); |
871 | ||
aaa75496 JB |
872 | static void add_file_name (struct line_header *, char *, unsigned int, |
873 | unsigned int, unsigned int); | |
874 | ||
debd256d JB |
875 | static struct line_header *(dwarf_decode_line_header |
876 | (unsigned int offset, | |
e7c27a73 | 877 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
878 | |
879 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 880 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 881 | |
4f1520fb | 882 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 883 | |
a14ed312 | 884 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 885 | struct dwarf2_cu *); |
c906108c | 886 | |
a14ed312 | 887 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 888 | struct dwarf2_cu *); |
c906108c | 889 | |
2df3850c JM |
890 | static void dwarf2_const_value_data (struct attribute *attr, |
891 | struct symbol *sym, | |
892 | int bits); | |
893 | ||
e7c27a73 | 894 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 895 | |
e7c27a73 DJ |
896 | static struct type *die_containing_type (struct die_info *, |
897 | struct dwarf2_cu *); | |
c906108c | 898 | |
e7c27a73 | 899 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 900 | |
f792889a | 901 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 902 | |
086ed43d | 903 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 904 | |
fe1b8b76 JB |
905 | static char *typename_concat (struct obstack *, |
906 | const char *prefix, | |
907 | const char *suffix, | |
987504bb | 908 | struct dwarf2_cu *); |
63d06c5c | 909 | |
e7c27a73 | 910 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 911 | |
e7c27a73 | 912 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 913 | |
e7c27a73 | 914 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 915 | |
ff013f42 JK |
916 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
917 | struct dwarf2_cu *, struct partial_symtab *); | |
918 | ||
a14ed312 | 919 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 920 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 921 | |
fae299cd DC |
922 | static void get_scope_pc_bounds (struct die_info *, |
923 | CORE_ADDR *, CORE_ADDR *, | |
924 | struct dwarf2_cu *); | |
925 | ||
801e3a5b JB |
926 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
927 | CORE_ADDR, struct dwarf2_cu *); | |
928 | ||
a14ed312 | 929 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 930 | struct dwarf2_cu *); |
c906108c | 931 | |
a14ed312 | 932 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 933 | struct type *, struct dwarf2_cu *); |
c906108c | 934 | |
a14ed312 | 935 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 936 | struct die_info *, struct type *, |
e7c27a73 | 937 | struct dwarf2_cu *); |
c906108c | 938 | |
a14ed312 | 939 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 940 | struct type *, struct dwarf2_cu *); |
c906108c | 941 | |
134d01f1 | 942 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 943 | |
0114d602 DJ |
944 | static const char *determine_class_name (struct die_info *die, |
945 | struct dwarf2_cu *cu); | |
8176b9b8 | 946 | |
e7c27a73 | 947 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 948 | |
e7c27a73 | 949 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 950 | |
38d518c9 | 951 | static const char *namespace_name (struct die_info *die, |
e142c38c | 952 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 953 | |
134d01f1 | 954 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 955 | |
e7c27a73 | 956 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 957 | |
7ca2d3a3 DL |
958 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
959 | struct dwarf2_cu *); | |
960 | ||
fe1b8b76 | 961 | static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *); |
c906108c | 962 | |
d97bc12b DE |
963 | static struct die_info *read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd, |
964 | struct dwarf2_cu *, | |
965 | gdb_byte **new_info_ptr, | |
966 | struct die_info *parent); | |
967 | ||
fe1b8b76 | 968 | static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 969 | struct dwarf2_cu *, |
fe1b8b76 | 970 | gdb_byte **new_info_ptr, |
639d11d3 DC |
971 | struct die_info *parent); |
972 | ||
fe1b8b76 | 973 | static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 974 | struct dwarf2_cu *, |
fe1b8b76 | 975 | gdb_byte **new_info_ptr, |
639d11d3 DC |
976 | struct die_info *parent); |
977 | ||
e7c27a73 | 978 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 979 | |
e142c38c | 980 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 981 | |
e142c38c | 982 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 983 | |
e142c38c | 984 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 985 | struct dwarf2_cu **); |
9219021c | 986 | |
a14ed312 | 987 | static char *dwarf_tag_name (unsigned int); |
c906108c | 988 | |
a14ed312 | 989 | static char *dwarf_attr_name (unsigned int); |
c906108c | 990 | |
a14ed312 | 991 | static char *dwarf_form_name (unsigned int); |
c906108c | 992 | |
a14ed312 | 993 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 994 | |
a14ed312 | 995 | static char *dwarf_bool_name (unsigned int); |
c906108c | 996 | |
a14ed312 | 997 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
998 | |
999 | #if 0 | |
a14ed312 | 1000 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1001 | #endif |
1002 | ||
f9aca02d | 1003 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1004 | |
d97bc12b DE |
1005 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1006 | ||
1007 | static void dump_die_for_error (struct die_info *); | |
1008 | ||
1009 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1010 | struct die_info *); | |
c906108c | 1011 | |
d97bc12b | 1012 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1013 | |
51545339 | 1014 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1015 | struct dwarf2_cu *); |
c906108c | 1016 | |
c764a876 | 1017 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1018 | |
a02abb62 JB |
1019 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
1020 | ||
10b3939b DJ |
1021 | static struct die_info *follow_die_ref (struct die_info *, |
1022 | struct attribute *, | |
f2f0e013 | 1023 | struct dwarf2_cu **); |
c906108c | 1024 | |
c906108c SS |
1025 | /* memory allocation interface */ |
1026 | ||
7b5a2f43 | 1027 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1028 | |
f3dd6933 | 1029 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1030 | |
b60c80d6 | 1031 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1032 | |
e142c38c | 1033 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1034 | |
e142c38c DJ |
1035 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1036 | struct dwarf2_cu *); | |
5fb290d7 | 1037 | |
2e276125 | 1038 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1039 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1040 | |
8e19ed76 PS |
1041 | static int attr_form_is_block (struct attribute *); |
1042 | ||
3690dd37 JB |
1043 | static int attr_form_is_section_offset (struct attribute *); |
1044 | ||
1045 | static int attr_form_is_constant (struct attribute *); | |
1046 | ||
93e7bd98 DJ |
1047 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1048 | struct symbol *sym, | |
1049 | struct dwarf2_cu *cu); | |
4c2df51b | 1050 | |
fe1b8b76 JB |
1051 | static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, |
1052 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1053 | |
72bf9492 DJ |
1054 | static void free_stack_comp_unit (void *); |
1055 | ||
72bf9492 DJ |
1056 | static hashval_t partial_die_hash (const void *item); |
1057 | ||
1058 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1059 | ||
ae038cb0 | 1060 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1061 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1062 | |
1063 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1064 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1065 | |
1066 | static void free_one_comp_unit (void *); | |
1067 | ||
1068 | static void free_cached_comp_units (void *); | |
1069 | ||
1070 | static void age_cached_comp_units (void); | |
1071 | ||
1072 | static void free_one_cached_comp_unit (void *); | |
1073 | ||
f792889a DJ |
1074 | static struct type *set_die_type (struct die_info *, struct type *, |
1075 | struct dwarf2_cu *); | |
1c379e20 | 1076 | |
ae038cb0 DJ |
1077 | static void create_all_comp_units (struct objfile *); |
1078 | ||
31ffec48 DJ |
1079 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *, |
1080 | struct objfile *); | |
10b3939b DJ |
1081 | |
1082 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1083 | ||
1084 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1085 | struct dwarf2_per_cu_data *); | |
1086 | ||
ae038cb0 DJ |
1087 | static void dwarf2_mark (struct dwarf2_cu *); |
1088 | ||
1089 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1090 | ||
f792889a | 1091 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1092 | |
c906108c SS |
1093 | /* Try to locate the sections we need for DWARF 2 debugging |
1094 | information and return true if we have enough to do something. */ | |
1095 | ||
1096 | int | |
6502dd73 | 1097 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1098 | { |
6502dd73 DJ |
1099 | struct dwarf2_per_objfile *data; |
1100 | ||
1101 | /* Initialize per-objfile state. */ | |
1102 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1103 | memset (data, 0, sizeof (*data)); | |
1104 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1105 | dwarf2_per_objfile = data; | |
1106 | ||
188dd5d6 DJ |
1107 | dwarf_info_section = 0; |
1108 | dwarf_abbrev_section = 0; | |
1109 | dwarf_line_section = 0; | |
1110 | dwarf_str_section = 0; | |
1111 | dwarf_macinfo_section = 0; | |
1112 | dwarf_frame_section = 0; | |
1113 | dwarf_eh_frame_section = 0; | |
1114 | dwarf_ranges_section = 0; | |
1115 | dwarf_loc_section = 0; | |
af34e669 | 1116 | |
6502dd73 | 1117 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 1118 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
1119 | } |
1120 | ||
233a11ab CS |
1121 | /* When loading sections, we can either look for ".<name>", or for |
1122 | * ".z<name>", which indicates a compressed section. */ | |
1123 | ||
1124 | static int | |
1125 | section_is_p (asection *sectp, const char *name) | |
1126 | { | |
1127 | return ((sectp->name[0] == '.' | |
1128 | && strcmp (sectp->name + 1, name) == 0) | |
1129 | || (sectp->name[0] == '.' && sectp->name[1] == 'z' | |
1130 | && strcmp (sectp->name + 2, name) == 0)); | |
1131 | } | |
1132 | ||
c906108c SS |
1133 | /* This function is mapped across the sections and remembers the |
1134 | offset and size of each of the debugging sections we are interested | |
1135 | in. */ | |
1136 | ||
1137 | static void | |
72dca2f5 | 1138 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1139 | { |
233a11ab | 1140 | if (section_is_p (sectp, INFO_SECTION)) |
c906108c | 1141 | { |
2c500098 | 1142 | dwarf2_per_objfile->info_size = bfd_get_section_size (sectp); |
086df311 | 1143 | dwarf_info_section = sectp; |
c906108c | 1144 | } |
233a11ab | 1145 | else if (section_is_p (sectp, ABBREV_SECTION)) |
c906108c | 1146 | { |
2c500098 | 1147 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp); |
086df311 | 1148 | dwarf_abbrev_section = sectp; |
c906108c | 1149 | } |
233a11ab | 1150 | else if (section_is_p (sectp, LINE_SECTION)) |
c906108c | 1151 | { |
2c500098 | 1152 | dwarf2_per_objfile->line_size = bfd_get_section_size (sectp); |
086df311 | 1153 | dwarf_line_section = sectp; |
c906108c | 1154 | } |
233a11ab | 1155 | else if (section_is_p (sectp, PUBNAMES_SECTION)) |
c906108c | 1156 | { |
2c500098 | 1157 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp); |
086df311 | 1158 | dwarf_pubnames_section = sectp; |
c906108c | 1159 | } |
233a11ab | 1160 | else if (section_is_p (sectp, ARANGES_SECTION)) |
c906108c | 1161 | { |
2c500098 | 1162 | dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp); |
086df311 | 1163 | dwarf_aranges_section = sectp; |
c906108c | 1164 | } |
233a11ab | 1165 | else if (section_is_p (sectp, LOC_SECTION)) |
c906108c | 1166 | { |
2c500098 | 1167 | dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp); |
086df311 | 1168 | dwarf_loc_section = sectp; |
c906108c | 1169 | } |
233a11ab | 1170 | else if (section_is_p (sectp, MACINFO_SECTION)) |
c906108c | 1171 | { |
2c500098 | 1172 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp); |
0cf824c9 | 1173 | dwarf_macinfo_section = sectp; |
c906108c | 1174 | } |
233a11ab | 1175 | else if (section_is_p (sectp, STR_SECTION)) |
c906108c | 1176 | { |
2c500098 | 1177 | dwarf2_per_objfile->str_size = bfd_get_section_size (sectp); |
086df311 | 1178 | dwarf_str_section = sectp; |
c906108c | 1179 | } |
233a11ab | 1180 | else if (section_is_p (sectp, FRAME_SECTION)) |
b6af0555 | 1181 | { |
2c500098 | 1182 | dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp); |
086df311 | 1183 | dwarf_frame_section = sectp; |
b6af0555 | 1184 | } |
233a11ab | 1185 | else if (section_is_p (sectp, EH_FRAME_SECTION)) |
b6af0555 | 1186 | { |
3799ccc6 EZ |
1187 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1188 | if (aflag & SEC_HAS_CONTENTS) | |
1189 | { | |
2c500098 | 1190 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp); |
3799ccc6 EZ |
1191 | dwarf_eh_frame_section = sectp; |
1192 | } | |
b6af0555 | 1193 | } |
233a11ab | 1194 | else if (section_is_p (sectp, RANGES_SECTION)) |
af34e669 | 1195 | { |
2c500098 | 1196 | dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp); |
6f10aeb1 | 1197 | dwarf_ranges_section = sectp; |
af34e669 | 1198 | } |
72dca2f5 FR |
1199 | |
1200 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) | |
1201 | && bfd_section_vma (abfd, sectp) == 0) | |
1202 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1203 | } |
1204 | ||
233a11ab CS |
1205 | /* This function is called after decompressing a section, so |
1206 | dwarf2_per_objfile can record its new, uncompressed size. */ | |
1207 | ||
1208 | static void | |
1209 | dwarf2_resize_section (asection *sectp, bfd_size_type new_size) | |
1210 | { | |
1211 | if (section_is_p (sectp, INFO_SECTION)) | |
1212 | dwarf2_per_objfile->info_size = new_size; | |
1213 | else if (section_is_p (sectp, ABBREV_SECTION)) | |
1214 | dwarf2_per_objfile->abbrev_size = new_size; | |
1215 | else if (section_is_p (sectp, LINE_SECTION)) | |
1216 | dwarf2_per_objfile->line_size = new_size; | |
1217 | else if (section_is_p (sectp, PUBNAMES_SECTION)) | |
1218 | dwarf2_per_objfile->pubnames_size = new_size; | |
1219 | else if (section_is_p (sectp, ARANGES_SECTION)) | |
1220 | dwarf2_per_objfile->aranges_size = new_size; | |
1221 | else if (section_is_p (sectp, LOC_SECTION)) | |
1222 | dwarf2_per_objfile->loc_size = new_size; | |
1223 | else if (section_is_p (sectp, MACINFO_SECTION)) | |
1224 | dwarf2_per_objfile->macinfo_size = new_size; | |
1225 | else if (section_is_p (sectp, STR_SECTION)) | |
1226 | dwarf2_per_objfile->str_size = new_size; | |
1227 | else if (section_is_p (sectp, FRAME_SECTION)) | |
1228 | dwarf2_per_objfile->frame_size = new_size; | |
1229 | else if (section_is_p (sectp, EH_FRAME_SECTION)) | |
1230 | dwarf2_per_objfile->eh_frame_size = new_size; | |
1231 | else if (section_is_p (sectp, RANGES_SECTION)) | |
1232 | dwarf2_per_objfile->ranges_size = new_size; | |
1233 | else | |
1234 | internal_error (__FILE__, __LINE__, | |
1235 | _("dwarf2_resize_section: missing section_is_p check: %s"), | |
1236 | sectp->name); | |
1237 | } | |
1238 | ||
c906108c SS |
1239 | /* Build a partial symbol table. */ |
1240 | ||
1241 | void | |
fba45db2 | 1242 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1243 | { |
c906108c SS |
1244 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1245 | ||
6502dd73 DJ |
1246 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1247 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1248 | |
1249 | if (dwarf_line_section) | |
6502dd73 | 1250 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1251 | else |
6502dd73 | 1252 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1253 | |
188dd5d6 | 1254 | if (dwarf_str_section) |
6502dd73 | 1255 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1256 | else |
6502dd73 | 1257 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1258 | |
188dd5d6 | 1259 | if (dwarf_macinfo_section) |
6502dd73 | 1260 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1261 | dwarf_macinfo_section); |
2e276125 | 1262 | else |
6502dd73 | 1263 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1264 | |
188dd5d6 | 1265 | if (dwarf_ranges_section) |
6502dd73 | 1266 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1267 | else |
6502dd73 | 1268 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1269 | |
188dd5d6 | 1270 | if (dwarf_loc_section) |
6502dd73 | 1271 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1272 | else |
6502dd73 | 1273 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1274 | |
ef96bde8 EZ |
1275 | if (mainline |
1276 | || (objfile->global_psymbols.size == 0 | |
1277 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1278 | { |
1279 | init_psymbol_list (objfile, 1024); | |
1280 | } | |
1281 | ||
1282 | #if 0 | |
1283 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1284 | { | |
d4f3574e | 1285 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1286 | .debug_pubnames sections */ |
1287 | ||
d4f3574e | 1288 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1289 | } |
1290 | else | |
1291 | #endif | |
1292 | /* only test this case for now */ | |
c5aa993b | 1293 | { |
c906108c | 1294 | /* In this case we have to work a bit harder */ |
d4f3574e | 1295 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1296 | } |
1297 | } | |
1298 | ||
1299 | #if 0 | |
1300 | /* Build the partial symbol table from the information in the | |
1301 | .debug_pubnames and .debug_aranges sections. */ | |
1302 | ||
1303 | static void | |
fba45db2 | 1304 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1305 | { |
1306 | bfd *abfd = objfile->obfd; | |
1307 | char *aranges_buffer, *pubnames_buffer; | |
1308 | char *aranges_ptr, *pubnames_ptr; | |
1309 | unsigned int entry_length, version, info_offset, info_size; | |
1310 | ||
1311 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1312 | dwarf_pubnames_section); |
c906108c | 1313 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1314 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1315 | { |
891d2f0b | 1316 | unsigned int bytes_read; |
613e1657 | 1317 | |
c764a876 | 1318 | entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read); |
613e1657 | 1319 | pubnames_ptr += bytes_read; |
c906108c SS |
1320 | version = read_1_byte (abfd, pubnames_ptr); |
1321 | pubnames_ptr += 1; | |
1322 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1323 | pubnames_ptr += 4; | |
1324 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1325 | pubnames_ptr += 4; | |
1326 | } | |
1327 | ||
1328 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1329 | dwarf_aranges_section); |
c906108c SS |
1330 | |
1331 | } | |
1332 | #endif | |
1333 | ||
45452591 DE |
1334 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
1335 | ||
1336 | static inline int | |
1337 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
1338 | { | |
1339 | unsigned int bottom = cu_header->offset; | |
1340 | unsigned int top = (cu_header->offset | |
1341 | + cu_header->length | |
1342 | + cu_header->initial_length_size); | |
1343 | return (offset >= bottom && offset < top); | |
1344 | } | |
1345 | ||
107d2387 | 1346 | /* Read in the comp unit header information from the debug_info at |
917c78fc | 1347 | info_ptr. */ |
107d2387 | 1348 | |
fe1b8b76 | 1349 | static gdb_byte * |
107d2387 | 1350 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1351 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1352 | { |
1353 | int signed_addr; | |
891d2f0b | 1354 | unsigned int bytes_read; |
c764a876 DE |
1355 | |
1356 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
1357 | cu_header->initial_length_size = bytes_read; | |
1358 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 1359 | info_ptr += bytes_read; |
107d2387 AC |
1360 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1361 | info_ptr += 2; | |
613e1657 | 1362 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 1363 | &bytes_read); |
613e1657 | 1364 | info_ptr += bytes_read; |
107d2387 AC |
1365 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1366 | info_ptr += 1; | |
1367 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1368 | if (signed_addr < 0) | |
8e65ff28 | 1369 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1370 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 1371 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 1372 | |
107d2387 AC |
1373 | return info_ptr; |
1374 | } | |
1375 | ||
fe1b8b76 JB |
1376 | static gdb_byte * |
1377 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
72bf9492 DJ |
1378 | bfd *abfd) |
1379 | { | |
fe1b8b76 | 1380 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1381 | |
1382 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1383 | ||
2b949cb6 | 1384 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1385 | error (_("Dwarf Error: wrong version in compilation unit header " |
1386 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1387 | 2, bfd_get_filename (abfd)); |
1388 | ||
1389 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
8a3fe4f8 AC |
1390 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1391 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 DJ |
1392 | (long) header->abbrev_offset, |
1393 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1394 | bfd_get_filename (abfd)); | |
1395 | ||
1396 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1397 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
8a3fe4f8 AC |
1398 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1399 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 DJ |
1400 | (long) header->length, |
1401 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1402 | bfd_get_filename (abfd)); | |
1403 | ||
1404 | return info_ptr; | |
1405 | } | |
1406 | ||
aaa75496 JB |
1407 | /* Allocate a new partial symtab for file named NAME and mark this new |
1408 | partial symtab as being an include of PST. */ | |
1409 | ||
1410 | static void | |
1411 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1412 | struct objfile *objfile) | |
1413 | { | |
1414 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1415 | ||
1416 | subpst->section_offsets = pst->section_offsets; | |
1417 | subpst->textlow = 0; | |
1418 | subpst->texthigh = 0; | |
1419 | ||
1420 | subpst->dependencies = (struct partial_symtab **) | |
1421 | obstack_alloc (&objfile->objfile_obstack, | |
1422 | sizeof (struct partial_symtab *)); | |
1423 | subpst->dependencies[0] = pst; | |
1424 | subpst->number_of_dependencies = 1; | |
1425 | ||
1426 | subpst->globals_offset = 0; | |
1427 | subpst->n_global_syms = 0; | |
1428 | subpst->statics_offset = 0; | |
1429 | subpst->n_static_syms = 0; | |
1430 | subpst->symtab = NULL; | |
1431 | subpst->read_symtab = pst->read_symtab; | |
1432 | subpst->readin = 0; | |
1433 | ||
1434 | /* No private part is necessary for include psymtabs. This property | |
1435 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1436 | the regular ones. */ |
58a9656e | 1437 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1438 | } |
1439 | ||
1440 | /* Read the Line Number Program data and extract the list of files | |
1441 | included by the source file represented by PST. Build an include | |
1442 | partial symtab for each of these included files. | |
1443 | ||
1444 | This procedure assumes that there *is* a Line Number Program in | |
1445 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1446 | before calling this procedure. */ | |
1447 | ||
1448 | static void | |
1449 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1450 | struct partial_die_info *pdi, | |
1451 | struct partial_symtab *pst) | |
1452 | { | |
1453 | struct objfile *objfile = cu->objfile; | |
1454 | bfd *abfd = objfile->obfd; | |
1455 | struct line_header *lh; | |
1456 | ||
1457 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1458 | if (lh == NULL) | |
1459 | return; /* No linetable, so no includes. */ | |
1460 | ||
1461 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1462 | ||
1463 | free_line_header (lh); | |
1464 | } | |
1465 | ||
1466 | ||
c906108c SS |
1467 | /* Build the partial symbol table by doing a quick pass through the |
1468 | .debug_info and .debug_abbrev sections. */ | |
1469 | ||
1470 | static void | |
fba45db2 | 1471 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1472 | { |
1473 | /* Instead of reading this into a big buffer, we should probably use | |
1474 | mmap() on architectures that support it. (FIXME) */ | |
1475 | bfd *abfd = objfile->obfd; | |
fe1b8b76 JB |
1476 | gdb_byte *info_ptr; |
1477 | gdb_byte *beg_of_comp_unit; | |
c906108c SS |
1478 | struct partial_die_info comp_unit_die; |
1479 | struct partial_symtab *pst; | |
ae038cb0 | 1480 | struct cleanup *back_to; |
e142c38c | 1481 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1482 | |
6502dd73 | 1483 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1484 | |
ae038cb0 DJ |
1485 | /* Any cached compilation units will be linked by the per-objfile |
1486 | read_in_chain. Make sure to free them when we're done. */ | |
1487 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
1488 | ||
10b3939b DJ |
1489 | create_all_comp_units (objfile); |
1490 | ||
ff013f42 JK |
1491 | objfile->psymtabs_addrmap = addrmap_create_mutable |
1492 | (&objfile->objfile_obstack); | |
1493 | ||
6502dd73 | 1494 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1495 | length, only the individual functions to extract them (like |
72bf9492 | 1496 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1497 | the buffer is large enough to hold another complete object. |
1498 | ||
6502dd73 DJ |
1499 | At the moment, they don't actually check that. If .debug_info |
1500 | holds just one extra byte after the last compilation unit's dies, | |
1501 | then read_comp_unit_head will happily read off the end of the | |
1502 | buffer. read_partial_die is similarly casual. Those functions | |
1503 | should be fixed. | |
af703f96 JB |
1504 | |
1505 | For this loop condition, simply checking whether there's any data | |
1506 | left at all should be sufficient. */ | |
6502dd73 DJ |
1507 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1508 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1509 | { |
f3dd6933 | 1510 | struct cleanup *back_to_inner; |
e7c27a73 | 1511 | struct dwarf2_cu cu; |
72bf9492 DJ |
1512 | struct abbrev_info *abbrev; |
1513 | unsigned int bytes_read; | |
1514 | struct dwarf2_per_cu_data *this_cu; | |
1515 | ||
c906108c | 1516 | beg_of_comp_unit = info_ptr; |
c906108c | 1517 | |
72bf9492 DJ |
1518 | memset (&cu, 0, sizeof (cu)); |
1519 | ||
1520 | obstack_init (&cu.comp_unit_obstack); | |
1521 | ||
1522 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1523 | ||
e7c27a73 | 1524 | cu.objfile = objfile; |
72bf9492 | 1525 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1526 | |
57349743 | 1527 | /* Complete the cu_header */ |
6502dd73 | 1528 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
d00adf39 | 1529 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; |
57349743 | 1530 | |
e142c38c DJ |
1531 | cu.list_in_scope = &file_symbols; |
1532 | ||
c906108c | 1533 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1534 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1535 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 1536 | |
10b3939b | 1537 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); |
ae038cb0 | 1538 | |
c906108c | 1539 | /* Read the compilation unit die */ |
72bf9492 DJ |
1540 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1541 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1542 | abfd, info_ptr, &cu); | |
c906108c | 1543 | |
31ffec48 DJ |
1544 | if (comp_unit_die.tag == DW_TAG_partial_unit) |
1545 | { | |
1546 | info_ptr = (beg_of_comp_unit + cu.header.length | |
1547 | + cu.header.initial_length_size); | |
1548 | do_cleanups (back_to_inner); | |
1549 | continue; | |
1550 | } | |
1551 | ||
c906108c | 1552 | /* Set the language we're debugging */ |
e142c38c | 1553 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1554 | |
1555 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1556 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1557 | comp_unit_die.name ? comp_unit_die.name : "", |
ff013f42 JK |
1558 | /* TEXTLOW and TEXTHIGH are set below. */ |
1559 | 0, | |
c906108c SS |
1560 | objfile->global_psymbols.next, |
1561 | objfile->static_psymbols.next); | |
1562 | ||
ae038cb0 | 1563 | if (comp_unit_die.dirname) |
a683b3c0 TT |
1564 | pst->dirname = obsavestring (comp_unit_die.dirname, |
1565 | strlen (comp_unit_die.dirname), | |
1566 | &objfile->objfile_obstack); | |
57c22c6c | 1567 | |
10b3939b DJ |
1568 | pst->read_symtab_private = (char *) this_cu; |
1569 | ||
613e1657 | 1570 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1571 | |
1572 | /* Store the function that reads in the rest of the symbol table */ | |
1573 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1574 | ||
10b3939b DJ |
1575 | /* If this compilation unit was already read in, free the |
1576 | cached copy in order to read it in again. This is | |
1577 | necessary because we skipped some symbols when we first | |
1578 | read in the compilation unit (see load_partial_dies). | |
1579 | This problem could be avoided, but the benefit is | |
1580 | unclear. */ | |
1581 | if (this_cu->cu != NULL) | |
1582 | free_one_cached_comp_unit (this_cu->cu); | |
ae038cb0 | 1583 | |
10b3939b | 1584 | cu.per_cu = this_cu; |
ae038cb0 | 1585 | |
10b3939b DJ |
1586 | /* Note that this is a pointer to our stack frame, being |
1587 | added to a global data structure. It will be cleaned up | |
1588 | in free_stack_comp_unit when we finish with this | |
1589 | compilation unit. */ | |
1590 | this_cu->cu = &cu; | |
ae038cb0 | 1591 | |
10b3939b | 1592 | this_cu->psymtab = pst; |
ae038cb0 | 1593 | |
ff013f42 JK |
1594 | /* Possibly set the default values of LOWPC and HIGHPC from |
1595 | `DW_AT_ranges'. */ | |
1596 | if (cu.has_ranges_offset) | |
1597 | { | |
1598 | if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc, | |
1599 | &comp_unit_die.highpc, &cu, pst)) | |
1600 | comp_unit_die.has_pc_info = 1; | |
1601 | } | |
1602 | ||
c906108c SS |
1603 | /* Check if comp unit has_children. |
1604 | If so, read the rest of the partial symbols from this comp unit. | |
1605 | If not, there's no more debug_info for this comp unit. */ | |
1606 | if (comp_unit_die.has_children) | |
1607 | { | |
72bf9492 DJ |
1608 | struct partial_die_info *first_die; |
1609 | ||
91c24f0a DC |
1610 | lowpc = ((CORE_ADDR) -1); |
1611 | highpc = ((CORE_ADDR) 0); | |
1612 | ||
72bf9492 DJ |
1613 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1614 | ||
1615 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1616 | |
91c24f0a DC |
1617 | /* If we didn't find a lowpc, set it to highpc to avoid |
1618 | complaints from `maint check'. */ | |
1619 | if (lowpc == ((CORE_ADDR) -1)) | |
1620 | lowpc = highpc; | |
72bf9492 | 1621 | |
c906108c SS |
1622 | /* If the compilation unit didn't have an explicit address range, |
1623 | then use the information extracted from its child dies. */ | |
0b010bcc | 1624 | if (! comp_unit_die.has_pc_info) |
c906108c | 1625 | { |
c5aa993b | 1626 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1627 | comp_unit_die.highpc = highpc; |
1628 | } | |
1629 | } | |
c5aa993b | 1630 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1631 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1632 | ||
ff013f42 JK |
1633 | /* Store the contiguous range; `DW_AT_ranges' range is stored above. The |
1634 | range can be also empty for CUs with no code. */ | |
1635 | if (!cu.has_ranges_offset && pst->textlow < pst->texthigh) | |
1636 | addrmap_set_empty (objfile->psymtabs_addrmap, pst->textlow, | |
1637 | pst->texthigh - 1, pst); | |
1638 | ||
c906108c SS |
1639 | pst->n_global_syms = objfile->global_psymbols.next - |
1640 | (objfile->global_psymbols.list + pst->globals_offset); | |
1641 | pst->n_static_syms = objfile->static_psymbols.next - | |
1642 | (objfile->static_psymbols.list + pst->statics_offset); | |
1643 | sort_pst_symbols (pst); | |
1644 | ||
1645 | /* If there is already a psymtab or symtab for a file of this | |
1646 | name, remove it. (If there is a symtab, more drastic things | |
1647 | also happen.) This happens in VxWorks. */ | |
1648 | free_named_symtabs (pst->filename); | |
1649 | ||
dd373385 EZ |
1650 | info_ptr = beg_of_comp_unit + cu.header.length |
1651 | + cu.header.initial_length_size; | |
1652 | ||
aaa75496 JB |
1653 | if (comp_unit_die.has_stmt_list) |
1654 | { | |
1655 | /* Get the list of files included in the current compilation unit, | |
1656 | and build a psymtab for each of them. */ | |
1657 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1658 | } | |
1659 | ||
f3dd6933 | 1660 | do_cleanups (back_to_inner); |
c906108c | 1661 | } |
ff013f42 JK |
1662 | |
1663 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
1664 | &objfile->objfile_obstack); | |
1665 | ||
ae038cb0 DJ |
1666 | do_cleanups (back_to); |
1667 | } | |
1668 | ||
1669 | /* Load the DIEs for a secondary CU into memory. */ | |
1670 | ||
1671 | static void | |
1672 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |
1673 | { | |
1674 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 1675 | gdb_byte *info_ptr, *beg_of_comp_unit; |
ae038cb0 DJ |
1676 | struct partial_die_info comp_unit_die; |
1677 | struct dwarf2_cu *cu; | |
1678 | struct abbrev_info *abbrev; | |
1679 | unsigned int bytes_read; | |
1680 | struct cleanup *back_to; | |
1681 | ||
1682 | info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset; | |
1683 | beg_of_comp_unit = info_ptr; | |
1684 | ||
1685 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
1686 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
1687 | ||
1688 | obstack_init (&cu->comp_unit_obstack); | |
1689 | ||
1690 | cu->objfile = objfile; | |
1691 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |
1692 | ||
1693 | /* Complete the cu_header. */ | |
1694 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |
d00adf39 | 1695 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
1696 | |
1697 | /* Read the abbrevs for this compilation unit into a table. */ | |
1698 | dwarf2_read_abbrevs (abfd, cu); | |
1699 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
1700 | ||
1701 | /* Read the compilation unit die. */ | |
1702 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1703 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1704 | abfd, info_ptr, cu); | |
1705 | ||
1706 | /* Set the language we're debugging. */ | |
1707 | set_cu_language (comp_unit_die.language, cu); | |
1708 | ||
1709 | /* Link this compilation unit into the compilation unit tree. */ | |
1710 | this_cu->cu = cu; | |
1711 | cu->per_cu = this_cu; | |
f792889a | 1712 | cu->type_hash = cu->per_cu->type_hash; |
ae038cb0 DJ |
1713 | |
1714 | /* Check if comp unit has_children. | |
1715 | If so, read the rest of the partial symbols from this comp unit. | |
1716 | If not, there's no more debug_info for this comp unit. */ | |
1717 | if (comp_unit_die.has_children) | |
1718 | load_partial_dies (abfd, info_ptr, 0, cu); | |
1719 | ||
1720 | do_cleanups (back_to); | |
1721 | } | |
1722 | ||
1723 | /* Create a list of all compilation units in OBJFILE. We do this only | |
1724 | if an inter-comp-unit reference is found; presumably if there is one, | |
1725 | there will be many, and one will occur early in the .debug_info section. | |
1726 | So there's no point in building this list incrementally. */ | |
1727 | ||
1728 | static void | |
1729 | create_all_comp_units (struct objfile *objfile) | |
1730 | { | |
1731 | int n_allocated; | |
1732 | int n_comp_units; | |
1733 | struct dwarf2_per_cu_data **all_comp_units; | |
fe1b8b76 | 1734 | gdb_byte *info_ptr = dwarf2_per_objfile->info_buffer; |
ae038cb0 DJ |
1735 | |
1736 | n_comp_units = 0; | |
1737 | n_allocated = 10; | |
1738 | all_comp_units = xmalloc (n_allocated | |
1739 | * sizeof (struct dwarf2_per_cu_data *)); | |
1740 | ||
1741 | while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1742 | { | |
c764a876 | 1743 | unsigned int length, initial_length_size; |
fe1b8b76 | 1744 | gdb_byte *beg_of_comp_unit; |
ae038cb0 | 1745 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 1746 | unsigned int offset; |
ae038cb0 DJ |
1747 | |
1748 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |
1749 | ||
1750 | /* Read just enough information to find out where the next | |
1751 | compilation unit is. */ | |
c764a876 DE |
1752 | length = read_initial_length (objfile->obfd, info_ptr, |
1753 | &initial_length_size); | |
ae038cb0 DJ |
1754 | |
1755 | /* Save the compilation unit for later lookup. */ | |
1756 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
1757 | sizeof (struct dwarf2_per_cu_data)); | |
1758 | memset (this_cu, 0, sizeof (*this_cu)); | |
1759 | this_cu->offset = offset; | |
c764a876 | 1760 | this_cu->length = length + initial_length_size; |
ae038cb0 DJ |
1761 | |
1762 | if (n_comp_units == n_allocated) | |
1763 | { | |
1764 | n_allocated *= 2; | |
1765 | all_comp_units = xrealloc (all_comp_units, | |
1766 | n_allocated | |
1767 | * sizeof (struct dwarf2_per_cu_data *)); | |
1768 | } | |
1769 | all_comp_units[n_comp_units++] = this_cu; | |
1770 | ||
1771 | info_ptr = info_ptr + this_cu->length; | |
1772 | } | |
1773 | ||
1774 | dwarf2_per_objfile->all_comp_units | |
1775 | = obstack_alloc (&objfile->objfile_obstack, | |
1776 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1777 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
1778 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1779 | xfree (all_comp_units); | |
1780 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
1781 | } |
1782 | ||
72bf9492 DJ |
1783 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1784 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1785 | in CU. */ | |
c906108c | 1786 | |
72bf9492 DJ |
1787 | static void |
1788 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1789 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1790 | { |
e7c27a73 | 1791 | struct objfile *objfile = cu->objfile; |
c906108c | 1792 | bfd *abfd = objfile->obfd; |
72bf9492 | 1793 | struct partial_die_info *pdi; |
c906108c | 1794 | |
91c24f0a DC |
1795 | /* Now, march along the PDI's, descending into ones which have |
1796 | interesting children but skipping the children of the other ones, | |
1797 | until we reach the end of the compilation unit. */ | |
c906108c | 1798 | |
72bf9492 | 1799 | pdi = first_die; |
91c24f0a | 1800 | |
72bf9492 DJ |
1801 | while (pdi != NULL) |
1802 | { | |
1803 | fixup_partial_die (pdi, cu); | |
c906108c | 1804 | |
91c24f0a DC |
1805 | /* Anonymous namespaces have no name but have interesting |
1806 | children, so we need to look at them. Ditto for anonymous | |
1807 | enums. */ | |
933c6fe4 | 1808 | |
72bf9492 DJ |
1809 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1810 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1811 | { |
72bf9492 | 1812 | switch (pdi->tag) |
c906108c SS |
1813 | { |
1814 | case DW_TAG_subprogram: | |
bc30ff58 | 1815 | add_partial_subprogram (pdi, lowpc, highpc, cu); |
c906108c SS |
1816 | break; |
1817 | case DW_TAG_variable: | |
1818 | case DW_TAG_typedef: | |
91c24f0a | 1819 | case DW_TAG_union_type: |
72bf9492 | 1820 | if (!pdi->is_declaration) |
63d06c5c | 1821 | { |
72bf9492 | 1822 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1823 | } |
1824 | break; | |
c906108c | 1825 | case DW_TAG_class_type: |
680b30c7 | 1826 | case DW_TAG_interface_type: |
c906108c | 1827 | case DW_TAG_structure_type: |
72bf9492 | 1828 | if (!pdi->is_declaration) |
c906108c | 1829 | { |
72bf9492 | 1830 | add_partial_symbol (pdi, cu); |
c906108c SS |
1831 | } |
1832 | break; | |
91c24f0a | 1833 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1834 | if (!pdi->is_declaration) |
1835 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1836 | break; |
1837 | case DW_TAG_base_type: | |
a02abb62 | 1838 | case DW_TAG_subrange_type: |
c906108c | 1839 | /* File scope base type definitions are added to the partial |
c5aa993b | 1840 | symbol table. */ |
72bf9492 | 1841 | add_partial_symbol (pdi, cu); |
c906108c | 1842 | break; |
d9fa45fe | 1843 | case DW_TAG_namespace: |
72bf9492 | 1844 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1845 | break; |
c906108c SS |
1846 | default: |
1847 | break; | |
1848 | } | |
1849 | } | |
1850 | ||
72bf9492 DJ |
1851 | /* If the die has a sibling, skip to the sibling. */ |
1852 | ||
1853 | pdi = pdi->die_sibling; | |
1854 | } | |
1855 | } | |
1856 | ||
1857 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1858 | |
72bf9492 | 1859 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
1860 | name is concatenated with "::" and the partial DIE's name. For |
1861 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
1862 | Enumerators are an exception; they use the scope of their parent |
1863 | enumeration type, i.e. the name of the enumeration type is not | |
1864 | prepended to the enumerator. | |
91c24f0a | 1865 | |
72bf9492 DJ |
1866 | There are two complexities. One is DW_AT_specification; in this |
1867 | case "parent" means the parent of the target of the specification, | |
1868 | instead of the direct parent of the DIE. The other is compilers | |
1869 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1870 | the fully qualified name of structure types from their members' | |
1871 | linkage names. This must be done using the DIE's children rather | |
1872 | than the children of any DW_AT_specification target. We only need | |
1873 | to do this for structures at the top level, i.e. if the target of | |
1874 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1875 | have a parent. */ | |
1876 | ||
1877 | /* Compute the scope prefix associated with PDI's parent, in | |
1878 | compilation unit CU. The result will be allocated on CU's | |
1879 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1880 | field. NULL is returned if no prefix is necessary. */ | |
1881 | static char * | |
1882 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1883 | struct dwarf2_cu *cu) | |
1884 | { | |
1885 | char *grandparent_scope; | |
1886 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 1887 | |
72bf9492 DJ |
1888 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1889 | then this means the parent of the specification DIE. */ | |
1890 | ||
1891 | real_pdi = pdi; | |
72bf9492 | 1892 | while (real_pdi->has_specification) |
10b3939b | 1893 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
1894 | |
1895 | parent = real_pdi->die_parent; | |
1896 | if (parent == NULL) | |
1897 | return NULL; | |
1898 | ||
1899 | if (parent->scope_set) | |
1900 | return parent->scope; | |
1901 | ||
1902 | fixup_partial_die (parent, cu); | |
1903 | ||
10b3939b | 1904 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
1905 | |
1906 | if (parent->tag == DW_TAG_namespace | |
1907 | || parent->tag == DW_TAG_structure_type | |
1908 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 1909 | || parent->tag == DW_TAG_interface_type |
72bf9492 DJ |
1910 | || parent->tag == DW_TAG_union_type) |
1911 | { | |
1912 | if (grandparent_scope == NULL) | |
1913 | parent->scope = parent->name; | |
1914 | else | |
987504bb JJ |
1915 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
1916 | parent->name, cu); | |
72bf9492 DJ |
1917 | } |
1918 | else if (parent->tag == DW_TAG_enumeration_type) | |
1919 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1920 | parent->scope = grandparent_scope; | |
1921 | else | |
1922 | { | |
1923 | /* FIXME drow/2004-04-01: What should we be doing with | |
1924 | function-local names? For partial symbols, we should probably be | |
1925 | ignoring them. */ | |
1926 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1927 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
1928 | parent->tag, pdi->offset); |
1929 | parent->scope = grandparent_scope; | |
c906108c SS |
1930 | } |
1931 | ||
72bf9492 DJ |
1932 | parent->scope_set = 1; |
1933 | return parent->scope; | |
1934 | } | |
1935 | ||
1936 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1937 | CU. The result will be allocated with malloc. */ | |
1938 | static char * | |
1939 | partial_die_full_name (struct partial_die_info *pdi, | |
1940 | struct dwarf2_cu *cu) | |
1941 | { | |
1942 | char *parent_scope; | |
1943 | ||
1944 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1945 | if (parent_scope == NULL) | |
1946 | return NULL; | |
1947 | else | |
987504bb | 1948 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
1949 | } |
1950 | ||
1951 | static void | |
72bf9492 | 1952 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1953 | { |
e7c27a73 | 1954 | struct objfile *objfile = cu->objfile; |
c906108c | 1955 | CORE_ADDR addr = 0; |
decbce07 | 1956 | char *actual_name = NULL; |
72bf9492 | 1957 | const char *my_prefix; |
5c4e30ca | 1958 | const struct partial_symbol *psym = NULL; |
e142c38c | 1959 | CORE_ADDR baseaddr; |
72bf9492 | 1960 | int built_actual_name = 0; |
e142c38c DJ |
1961 | |
1962 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1963 | |
72bf9492 | 1964 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 1965 | { |
72bf9492 DJ |
1966 | actual_name = partial_die_full_name (pdi, cu); |
1967 | if (actual_name) | |
1968 | built_actual_name = 1; | |
63d06c5c DC |
1969 | } |
1970 | ||
72bf9492 DJ |
1971 | if (actual_name == NULL) |
1972 | actual_name = pdi->name; | |
1973 | ||
c906108c SS |
1974 | switch (pdi->tag) |
1975 | { | |
1976 | case DW_TAG_subprogram: | |
2cfa0c8d | 1977 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 1978 | { |
2cfa0c8d JB |
1979 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
1980 | of the global scope. But in Ada, we want to be able to access | |
1981 | nested procedures globally. So all Ada subprograms are stored | |
1982 | in the global scope. */ | |
38d518c9 | 1983 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1984 | mst_text, objfile); */ |
38d518c9 | 1985 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1986 | VAR_DOMAIN, LOC_BLOCK, |
1987 | &objfile->global_psymbols, | |
1988 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1989 | cu->language, objfile); |
c906108c SS |
1990 | } |
1991 | else | |
1992 | { | |
38d518c9 | 1993 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1994 | mst_file_text, objfile); */ |
38d518c9 | 1995 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1996 | VAR_DOMAIN, LOC_BLOCK, |
1997 | &objfile->static_psymbols, | |
1998 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1999 | cu->language, objfile); |
c906108c SS |
2000 | } |
2001 | break; | |
2002 | case DW_TAG_variable: | |
2003 | if (pdi->is_external) | |
2004 | { | |
2005 | /* Global Variable. | |
2006 | Don't enter into the minimal symbol tables as there is | |
2007 | a minimal symbol table entry from the ELF symbols already. | |
2008 | Enter into partial symbol table if it has a location | |
2009 | descriptor or a type. | |
2010 | If the location descriptor is missing, new_symbol will create | |
2011 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2012 | be determined from the minimal symbol table whenever the variable | |
2013 | is referenced. | |
2014 | The address for the partial symbol table entry is not | |
2015 | used by GDB, but it comes in handy for debugging partial symbol | |
2016 | table building. */ | |
2017 | ||
2018 | if (pdi->locdesc) | |
e7c27a73 | 2019 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2020 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2021 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2022 | VAR_DOMAIN, LOC_STATIC, |
2023 | &objfile->global_psymbols, | |
2024 | 0, addr + baseaddr, | |
e142c38c | 2025 | cu->language, objfile); |
c906108c SS |
2026 | } |
2027 | else | |
2028 | { | |
2029 | /* Static Variable. Skip symbols without location descriptors. */ | |
2030 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2031 | { |
2032 | if (built_actual_name) | |
2033 | xfree (actual_name); | |
2034 | return; | |
2035 | } | |
e7c27a73 | 2036 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2037 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2038 | mst_file_data, objfile); */ |
38d518c9 | 2039 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2040 | VAR_DOMAIN, LOC_STATIC, |
2041 | &objfile->static_psymbols, | |
2042 | 0, addr + baseaddr, | |
e142c38c | 2043 | cu->language, objfile); |
c906108c SS |
2044 | } |
2045 | break; | |
2046 | case DW_TAG_typedef: | |
2047 | case DW_TAG_base_type: | |
a02abb62 | 2048 | case DW_TAG_subrange_type: |
38d518c9 | 2049 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2050 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2051 | &objfile->static_psymbols, |
e142c38c | 2052 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2053 | break; |
72bf9492 DJ |
2054 | case DW_TAG_namespace: |
2055 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
2056 | VAR_DOMAIN, LOC_TYPEDEF, | |
2057 | &objfile->global_psymbols, | |
2058 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2059 | break; | |
c906108c | 2060 | case DW_TAG_class_type: |
680b30c7 | 2061 | case DW_TAG_interface_type: |
c906108c SS |
2062 | case DW_TAG_structure_type: |
2063 | case DW_TAG_union_type: | |
2064 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2065 | /* Skip external references. The DWARF standard says in the section |
2066 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2067 | structure, union or class type is represented by a structure, | |
2068 | union or class entry that does not have a byte size attribute | |
2069 | and that has a DW_AT_declaration attribute." */ | |
2070 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2071 | { |
2072 | if (built_actual_name) | |
2073 | xfree (actual_name); | |
2074 | return; | |
2075 | } | |
fa4028e9 | 2076 | |
63d06c5c DC |
2077 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2078 | static vs. global. */ | |
38d518c9 | 2079 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2080 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2081 | (cu->language == language_cplus |
2082 | || cu->language == language_java) | |
63d06c5c DC |
2083 | ? &objfile->global_psymbols |
2084 | : &objfile->static_psymbols, | |
e142c38c | 2085 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2086 | |
c906108c SS |
2087 | break; |
2088 | case DW_TAG_enumerator: | |
38d518c9 | 2089 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2090 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2091 | (cu->language == language_cplus |
2092 | || cu->language == language_java) | |
f6fe98ef DJ |
2093 | ? &objfile->global_psymbols |
2094 | : &objfile->static_psymbols, | |
e142c38c | 2095 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2096 | break; |
2097 | default: | |
2098 | break; | |
2099 | } | |
5c4e30ca DC |
2100 | |
2101 | /* Check to see if we should scan the name for possible namespace | |
2102 | info. Only do this if this is C++, if we don't have namespace | |
2103 | debugging info in the file, if the psym is of an appropriate type | |
2104 | (otherwise we'll have psym == NULL), and if we actually had a | |
2105 | mangled name to begin with. */ | |
2106 | ||
72bf9492 DJ |
2107 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2108 | cases which do not set PSYM above? */ | |
2109 | ||
e142c38c | 2110 | if (cu->language == language_cplus |
72bf9492 | 2111 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2112 | && psym != NULL |
2113 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2114 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2115 | objfile); | |
72bf9492 DJ |
2116 | |
2117 | if (built_actual_name) | |
2118 | xfree (actual_name); | |
c906108c SS |
2119 | } |
2120 | ||
72bf9492 DJ |
2121 | /* Determine whether a die of type TAG living in a C++ class or |
2122 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2123 | name listed in the die. */ |
2124 | ||
2125 | static int | |
72bf9492 | 2126 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2127 | { |
63d06c5c DC |
2128 | switch (tag) |
2129 | { | |
72bf9492 | 2130 | case DW_TAG_namespace: |
63d06c5c DC |
2131 | case DW_TAG_typedef: |
2132 | case DW_TAG_class_type: | |
680b30c7 | 2133 | case DW_TAG_interface_type: |
63d06c5c DC |
2134 | case DW_TAG_structure_type: |
2135 | case DW_TAG_union_type: | |
2136 | case DW_TAG_enumeration_type: | |
2137 | case DW_TAG_enumerator: | |
2138 | return 1; | |
2139 | default: | |
2140 | return 0; | |
2141 | } | |
2142 | } | |
2143 | ||
5c4e30ca DC |
2144 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2145 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2146 | the name of the enclosing namespace. */ | |
91c24f0a | 2147 | |
72bf9492 DJ |
2148 | static void |
2149 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2150 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 2151 | struct dwarf2_cu *cu) |
91c24f0a | 2152 | { |
e7c27a73 | 2153 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2154 | |
72bf9492 | 2155 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2156 | |
72bf9492 | 2157 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2158 | |
2159 | /* Now scan partial symbols in that namespace. */ | |
2160 | ||
91c24f0a | 2161 | if (pdi->has_children) |
72bf9492 | 2162 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
2163 | } |
2164 | ||
bc30ff58 JB |
2165 | /* Read a partial die corresponding to a subprogram and create a partial |
2166 | symbol for that subprogram. When the CU language allows it, this | |
2167 | routine also defines a partial symbol for each nested subprogram | |
2168 | that this subprogram contains. | |
2169 | ||
2170 | DIE my also be a lexical block, in which case we simply search | |
2171 | recursively for suprograms defined inside that lexical block. | |
2172 | Again, this is only performed when the CU language allows this | |
2173 | type of definitions. */ | |
2174 | ||
2175 | static void | |
2176 | add_partial_subprogram (struct partial_die_info *pdi, | |
2177 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
2178 | struct dwarf2_cu *cu) | |
2179 | { | |
2180 | if (pdi->tag == DW_TAG_subprogram) | |
2181 | { | |
2182 | if (pdi->has_pc_info) | |
2183 | { | |
2184 | if (pdi->lowpc < *lowpc) | |
2185 | *lowpc = pdi->lowpc; | |
2186 | if (pdi->highpc > *highpc) | |
2187 | *highpc = pdi->highpc; | |
2188 | if (!pdi->is_declaration) | |
2189 | add_partial_symbol (pdi, cu); | |
2190 | } | |
2191 | } | |
2192 | ||
2193 | if (! pdi->has_children) | |
2194 | return; | |
2195 | ||
2196 | if (cu->language == language_ada) | |
2197 | { | |
2198 | pdi = pdi->die_child; | |
2199 | while (pdi != NULL) | |
2200 | { | |
2201 | fixup_partial_die (pdi, cu); | |
2202 | if (pdi->tag == DW_TAG_subprogram | |
2203 | || pdi->tag == DW_TAG_lexical_block) | |
2204 | add_partial_subprogram (pdi, lowpc, highpc, cu); | |
2205 | pdi = pdi->die_sibling; | |
2206 | } | |
2207 | } | |
2208 | } | |
2209 | ||
72bf9492 DJ |
2210 | /* See if we can figure out if the class lives in a namespace. We do |
2211 | this by looking for a member function; its demangled name will | |
2212 | contain namespace info, if there is any. */ | |
63d06c5c | 2213 | |
72bf9492 DJ |
2214 | static void |
2215 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2216 | struct dwarf2_cu *cu) | |
63d06c5c | 2217 | { |
987504bb JJ |
2218 | if ((cu->language == language_cplus |
2219 | || cu->language == language_java) | |
72bf9492 | 2220 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2221 | && struct_pdi->has_children) |
2222 | { | |
63d06c5c DC |
2223 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2224 | what template types look like, because the demangler | |
2225 | frequently doesn't give the same name as the debug info. We | |
2226 | could fix this by only using the demangled name to get the | |
134d01f1 | 2227 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2228 | |
72bf9492 DJ |
2229 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2230 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2231 | |
72bf9492 DJ |
2232 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2233 | we should not do this. We'll prepend the parent's fully qualified | |
2234 | name when we create the partial symbol. */ | |
5d51ca54 | 2235 | |
72bf9492 | 2236 | real_pdi = struct_pdi; |
72bf9492 | 2237 | while (real_pdi->has_specification) |
10b3939b | 2238 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2239 | |
72bf9492 DJ |
2240 | if (real_pdi->die_parent != NULL) |
2241 | return; | |
63d06c5c | 2242 | |
72bf9492 DJ |
2243 | while (child_pdi != NULL) |
2244 | { | |
2245 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2246 | { |
72bf9492 | 2247 | char *actual_class_name |
31c27f77 JJ |
2248 | = language_class_name_from_physname (cu->language_defn, |
2249 | child_pdi->name); | |
63d06c5c | 2250 | if (actual_class_name != NULL) |
72bf9492 DJ |
2251 | { |
2252 | struct_pdi->name | |
2253 | = obsavestring (actual_class_name, | |
2254 | strlen (actual_class_name), | |
2255 | &cu->comp_unit_obstack); | |
2256 | xfree (actual_class_name); | |
2257 | } | |
63d06c5c DC |
2258 | break; |
2259 | } | |
72bf9492 DJ |
2260 | |
2261 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2262 | } |
2263 | } | |
63d06c5c DC |
2264 | } |
2265 | ||
91c24f0a DC |
2266 | /* Read a partial die corresponding to an enumeration type. */ |
2267 | ||
72bf9492 DJ |
2268 | static void |
2269 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2270 | struct dwarf2_cu *cu) | |
91c24f0a | 2271 | { |
e7c27a73 | 2272 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2273 | bfd *abfd = objfile->obfd; |
72bf9492 | 2274 | struct partial_die_info *pdi; |
91c24f0a DC |
2275 | |
2276 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2277 | add_partial_symbol (enum_pdi, cu); |
2278 | ||
2279 | pdi = enum_pdi->die_child; | |
2280 | while (pdi) | |
91c24f0a | 2281 | { |
72bf9492 | 2282 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2283 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2284 | else |
72bf9492 DJ |
2285 | add_partial_symbol (pdi, cu); |
2286 | pdi = pdi->die_sibling; | |
91c24f0a | 2287 | } |
91c24f0a DC |
2288 | } |
2289 | ||
4bb7a0a7 DJ |
2290 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2291 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2292 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2293 | the initial number. */ | |
2294 | ||
2295 | static struct abbrev_info * | |
fe1b8b76 | 2296 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2297 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2298 | { |
2299 | bfd *abfd = cu->objfile->obfd; | |
2300 | unsigned int abbrev_number; | |
2301 | struct abbrev_info *abbrev; | |
2302 | ||
2303 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2304 | ||
2305 | if (abbrev_number == 0) | |
2306 | return NULL; | |
2307 | ||
2308 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2309 | if (!abbrev) | |
2310 | { | |
8a3fe4f8 | 2311 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2312 | bfd_get_filename (abfd)); |
2313 | } | |
2314 | ||
2315 | return abbrev; | |
2316 | } | |
2317 | ||
2318 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2319 | pointer to the end of a series of DIEs, terminated by an empty | |
2320 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2321 | ||
fe1b8b76 JB |
2322 | static gdb_byte * |
2323 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2324 | { |
2325 | struct abbrev_info *abbrev; | |
2326 | unsigned int bytes_read; | |
2327 | ||
2328 | while (1) | |
2329 | { | |
2330 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2331 | if (abbrev == NULL) | |
2332 | return info_ptr + bytes_read; | |
2333 | else | |
2334 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2335 | } | |
2336 | } | |
2337 | ||
2338 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2339 | should point just after the initial uleb128 of a DIE, and the | |
2340 | abbrev corresponding to that skipped uleb128 should be passed in | |
2341 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2342 | children. */ | |
2343 | ||
fe1b8b76 JB |
2344 | static gdb_byte * |
2345 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2346 | struct dwarf2_cu *cu) |
2347 | { | |
2348 | unsigned int bytes_read; | |
2349 | struct attribute attr; | |
2350 | bfd *abfd = cu->objfile->obfd; | |
2351 | unsigned int form, i; | |
2352 | ||
2353 | for (i = 0; i < abbrev->num_attrs; i++) | |
2354 | { | |
2355 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2356 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2357 | { | |
2358 | read_attribute (&attr, &abbrev->attrs[i], | |
2359 | abfd, info_ptr, cu); | |
2360 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2361 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2362 | else |
6502dd73 | 2363 | return dwarf2_per_objfile->info_buffer |
c764a876 | 2364 | + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2365 | } |
2366 | ||
2367 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2368 | form = abbrev->attrs[i].form; | |
2369 | skip_attribute: | |
2370 | switch (form) | |
2371 | { | |
2372 | case DW_FORM_addr: | |
2373 | case DW_FORM_ref_addr: | |
2374 | info_ptr += cu->header.addr_size; | |
2375 | break; | |
2376 | case DW_FORM_data1: | |
2377 | case DW_FORM_ref1: | |
2378 | case DW_FORM_flag: | |
2379 | info_ptr += 1; | |
2380 | break; | |
2381 | case DW_FORM_data2: | |
2382 | case DW_FORM_ref2: | |
2383 | info_ptr += 2; | |
2384 | break; | |
2385 | case DW_FORM_data4: | |
2386 | case DW_FORM_ref4: | |
2387 | info_ptr += 4; | |
2388 | break; | |
2389 | case DW_FORM_data8: | |
2390 | case DW_FORM_ref8: | |
2391 | info_ptr += 8; | |
2392 | break; | |
2393 | case DW_FORM_string: | |
2394 | read_string (abfd, info_ptr, &bytes_read); | |
2395 | info_ptr += bytes_read; | |
2396 | break; | |
2397 | case DW_FORM_strp: | |
2398 | info_ptr += cu->header.offset_size; | |
2399 | break; | |
2400 | case DW_FORM_block: | |
2401 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2402 | info_ptr += bytes_read; | |
2403 | break; | |
2404 | case DW_FORM_block1: | |
2405 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2406 | break; | |
2407 | case DW_FORM_block2: | |
2408 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2409 | break; | |
2410 | case DW_FORM_block4: | |
2411 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2412 | break; | |
2413 | case DW_FORM_sdata: | |
2414 | case DW_FORM_udata: | |
2415 | case DW_FORM_ref_udata: | |
2416 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2417 | break; | |
2418 | case DW_FORM_indirect: | |
2419 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2420 | info_ptr += bytes_read; | |
2421 | /* We need to continue parsing from here, so just go back to | |
2422 | the top. */ | |
2423 | goto skip_attribute; | |
2424 | ||
2425 | default: | |
8a3fe4f8 | 2426 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2427 | dwarf_form_name (form), |
2428 | bfd_get_filename (abfd)); | |
2429 | } | |
2430 | } | |
2431 | ||
2432 | if (abbrev->has_children) | |
2433 | return skip_children (info_ptr, cu); | |
2434 | else | |
2435 | return info_ptr; | |
2436 | } | |
2437 | ||
2438 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2439 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2440 | |
fe1b8b76 JB |
2441 | static gdb_byte * |
2442 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2443 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2444 | { |
2445 | /* Do we know the sibling already? */ | |
72bf9492 | 2446 | |
91c24f0a DC |
2447 | if (orig_pdi->sibling) |
2448 | return orig_pdi->sibling; | |
2449 | ||
2450 | /* Are there any children to deal with? */ | |
2451 | ||
2452 | if (!orig_pdi->has_children) | |
2453 | return info_ptr; | |
2454 | ||
4bb7a0a7 | 2455 | /* Skip the children the long way. */ |
91c24f0a | 2456 | |
4bb7a0a7 | 2457 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2458 | } |
2459 | ||
c906108c SS |
2460 | /* Expand this partial symbol table into a full symbol table. */ |
2461 | ||
2462 | static void | |
fba45db2 | 2463 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2464 | { |
2465 | /* FIXME: This is barely more than a stub. */ | |
2466 | if (pst != NULL) | |
2467 | { | |
2468 | if (pst->readin) | |
2469 | { | |
8a3fe4f8 | 2470 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2471 | } |
2472 | else | |
2473 | { | |
2474 | if (info_verbose) | |
2475 | { | |
a3f17187 | 2476 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2477 | gdb_flush (gdb_stdout); |
2478 | } | |
2479 | ||
10b3939b DJ |
2480 | /* Restore our global data. */ |
2481 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2482 | dwarf2_objfile_data_key); | |
2483 | ||
c906108c SS |
2484 | psymtab_to_symtab_1 (pst); |
2485 | ||
2486 | /* Finish up the debug error message. */ | |
2487 | if (info_verbose) | |
a3f17187 | 2488 | printf_filtered (_("done.\n")); |
c906108c SS |
2489 | } |
2490 | } | |
2491 | } | |
2492 | ||
10b3939b DJ |
2493 | /* Add PER_CU to the queue. */ |
2494 | ||
2495 | static void | |
03dd20cc | 2496 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
2497 | { |
2498 | struct dwarf2_queue_item *item; | |
2499 | ||
2500 | per_cu->queued = 1; | |
2501 | item = xmalloc (sizeof (*item)); | |
2502 | item->per_cu = per_cu; | |
2503 | item->next = NULL; | |
2504 | ||
2505 | if (dwarf2_queue == NULL) | |
2506 | dwarf2_queue = item; | |
2507 | else | |
2508 | dwarf2_queue_tail->next = item; | |
2509 | ||
2510 | dwarf2_queue_tail = item; | |
03dd20cc DJ |
2511 | |
2512 | /* Either PER_CU is the CU we want to process, or we're following a reference | |
2513 | pointing into PER_CU. Either way, we need its DIEs now. */ | |
2514 | load_full_comp_unit (item->per_cu, objfile); | |
2515 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2516 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
10b3939b DJ |
2517 | } |
2518 | ||
2519 | /* Process the queue. */ | |
2520 | ||
2521 | static void | |
2522 | process_queue (struct objfile *objfile) | |
2523 | { | |
2524 | struct dwarf2_queue_item *item, *next_item; | |
2525 | ||
03dd20cc DJ |
2526 | /* The queue starts out with one item, but following a DIE reference |
2527 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
2528 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
2529 | { | |
31ffec48 | 2530 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2531 | process_full_comp_unit (item->per_cu); |
2532 | ||
2533 | item->per_cu->queued = 0; | |
2534 | next_item = item->next; | |
2535 | xfree (item); | |
2536 | } | |
2537 | ||
2538 | dwarf2_queue_tail = NULL; | |
2539 | } | |
2540 | ||
2541 | /* Free all allocated queue entries. This function only releases anything if | |
2542 | an error was thrown; if the queue was processed then it would have been | |
2543 | freed as we went along. */ | |
2544 | ||
2545 | static void | |
2546 | dwarf2_release_queue (void *dummy) | |
2547 | { | |
2548 | struct dwarf2_queue_item *item, *last; | |
2549 | ||
2550 | item = dwarf2_queue; | |
2551 | while (item) | |
2552 | { | |
2553 | /* Anything still marked queued is likely to be in an | |
2554 | inconsistent state, so discard it. */ | |
2555 | if (item->per_cu->queued) | |
2556 | { | |
2557 | if (item->per_cu->cu != NULL) | |
2558 | free_one_cached_comp_unit (item->per_cu->cu); | |
2559 | item->per_cu->queued = 0; | |
2560 | } | |
2561 | ||
2562 | last = item; | |
2563 | item = item->next; | |
2564 | xfree (last); | |
2565 | } | |
2566 | ||
2567 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2568 | } | |
2569 | ||
2570 | /* Read in full symbols for PST, and anything it depends on. */ | |
2571 | ||
c906108c | 2572 | static void |
fba45db2 | 2573 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2574 | { |
10b3939b | 2575 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2576 | struct cleanup *back_to; |
aaa75496 JB |
2577 | int i; |
2578 | ||
2579 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2580 | if (!pst->dependencies[i]->readin) | |
2581 | { | |
2582 | /* Inform about additional files that need to be read in. */ | |
2583 | if (info_verbose) | |
2584 | { | |
a3f17187 | 2585 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2586 | fputs_filtered (" ", gdb_stdout); |
2587 | wrap_here (""); | |
2588 | fputs_filtered ("and ", gdb_stdout); | |
2589 | wrap_here (""); | |
2590 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2591 | wrap_here (""); /* Flush output */ | |
2592 | gdb_flush (gdb_stdout); | |
2593 | } | |
2594 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2595 | } | |
2596 | ||
10b3939b DJ |
2597 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2598 | ||
2599 | if (per_cu == NULL) | |
aaa75496 JB |
2600 | { |
2601 | /* It's an include file, no symbols to read for it. | |
2602 | Everything is in the parent symtab. */ | |
2603 | pst->readin = 1; | |
2604 | return; | |
2605 | } | |
c906108c | 2606 | |
10b3939b DJ |
2607 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2608 | ||
03dd20cc | 2609 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b DJ |
2610 | |
2611 | process_queue (pst->objfile); | |
2612 | ||
2613 | /* Age the cache, releasing compilation units that have not | |
2614 | been used recently. */ | |
2615 | age_cached_comp_units (); | |
2616 | ||
2617 | do_cleanups (back_to); | |
2618 | } | |
2619 | ||
2620 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2621 | ||
2622 | static struct dwarf2_cu * | |
31ffec48 | 2623 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2624 | { |
31ffec48 | 2625 | bfd *abfd = objfile->obfd; |
10b3939b | 2626 | struct dwarf2_cu *cu; |
c764a876 | 2627 | unsigned int offset; |
fe1b8b76 | 2628 | gdb_byte *info_ptr; |
10b3939b DJ |
2629 | struct cleanup *back_to, *free_cu_cleanup; |
2630 | struct attribute *attr; | |
2631 | CORE_ADDR baseaddr; | |
6502dd73 | 2632 | |
c906108c | 2633 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2634 | offset = per_cu->offset; |
6502dd73 DJ |
2635 | |
2636 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
63d06c5c | 2637 | |
10b3939b DJ |
2638 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2639 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2640 | |
10b3939b DJ |
2641 | /* If an error occurs while loading, release our storage. */ |
2642 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2643 | |
31ffec48 | 2644 | cu->objfile = objfile; |
e7c27a73 | 2645 | |
c906108c | 2646 | /* read in the comp_unit header */ |
10b3939b | 2647 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2648 | |
2649 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2650 | dwarf2_read_abbrevs (abfd, cu); |
2651 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2652 | ||
2653 | cu->header.offset = offset; | |
c906108c | 2654 | |
10b3939b DJ |
2655 | cu->per_cu = per_cu; |
2656 | per_cu->cu = cu; | |
f792889a | 2657 | cu->type_hash = per_cu->type_hash; |
e142c38c | 2658 | |
10b3939b DJ |
2659 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2660 | obstack_init (&cu->comp_unit_obstack); | |
2661 | ||
2662 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2663 | ||
2664 | /* We try not to read any attributes in this function, because not | |
2665 | all objfiles needed for references have been loaded yet, and symbol | |
2666 | table processing isn't initialized. But we have to set the CU language, | |
2667 | or we won't be able to build types correctly. */ | |
2668 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2669 | if (attr) | |
2670 | set_cu_language (DW_UNSND (attr), cu); | |
2671 | else | |
2672 | set_cu_language (language_minimal, cu); | |
2673 | ||
2674 | do_cleanups (back_to); | |
e142c38c | 2675 | |
10b3939b DJ |
2676 | /* We've successfully allocated this compilation unit. Let our caller |
2677 | clean it up when finished with it. */ | |
2678 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2679 | |
10b3939b DJ |
2680 | return cu; |
2681 | } | |
2682 | ||
2683 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2684 | already been loaded into memory. */ | |
2685 | ||
2686 | static void | |
2687 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2688 | { | |
2689 | struct partial_symtab *pst = per_cu->psymtab; | |
2690 | struct dwarf2_cu *cu = per_cu->cu; | |
2691 | struct objfile *objfile = pst->objfile; | |
2692 | bfd *abfd = objfile->obfd; | |
2693 | CORE_ADDR lowpc, highpc; | |
2694 | struct symtab *symtab; | |
2695 | struct cleanup *back_to; | |
2696 | struct attribute *attr; | |
2697 | CORE_ADDR baseaddr; | |
2698 | ||
2699 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2700 | ||
10b3939b DJ |
2701 | buildsym_init (); |
2702 | back_to = make_cleanup (really_free_pendings, NULL); | |
2703 | ||
2704 | cu->list_in_scope = &file_symbols; | |
c906108c | 2705 | |
0d53c4c4 DJ |
2706 | /* Find the base address of the compilation unit for range lists and |
2707 | location lists. It will normally be specified by DW_AT_low_pc. | |
2708 | In DWARF-3 draft 4, the base address could be overridden by | |
2709 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2710 | compilation units with discontinuous ranges. */ | |
2711 | ||
d00adf39 DE |
2712 | cu->base_known = 0; |
2713 | cu->base_address = 0; | |
0d53c4c4 | 2714 | |
10b3939b | 2715 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2716 | if (attr) |
2717 | { | |
d00adf39 DE |
2718 | cu->base_address = DW_ADDR (attr); |
2719 | cu->base_known = 1; | |
0d53c4c4 DJ |
2720 | } |
2721 | else | |
2722 | { | |
10b3939b | 2723 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2724 | if (attr) |
2725 | { | |
d00adf39 DE |
2726 | cu->base_address = DW_ADDR (attr); |
2727 | cu->base_known = 1; | |
0d53c4c4 DJ |
2728 | } |
2729 | } | |
2730 | ||
c906108c | 2731 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2732 | process_die (cu->dies, cu); |
c906108c | 2733 | |
fae299cd DC |
2734 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2735 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2736 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2737 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2738 | |
613e1657 | 2739 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2740 | |
2741 | /* Set symtab language to language from DW_AT_language. | |
2742 | If the compilation is from a C file generated by language preprocessors, | |
2743 | do not set the language if it was already deduced by start_subfile. */ | |
2744 | if (symtab != NULL | |
10b3939b | 2745 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2746 | { |
10b3939b | 2747 | symtab->language = cu->language; |
c906108c SS |
2748 | } |
2749 | pst->symtab = symtab; | |
2750 | pst->readin = 1; | |
c906108c SS |
2751 | |
2752 | do_cleanups (back_to); | |
2753 | } | |
2754 | ||
2755 | /* Process a die and its children. */ | |
2756 | ||
2757 | static void | |
e7c27a73 | 2758 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2759 | { |
2760 | switch (die->tag) | |
2761 | { | |
2762 | case DW_TAG_padding: | |
2763 | break; | |
2764 | case DW_TAG_compile_unit: | |
e7c27a73 | 2765 | read_file_scope (die, cu); |
c906108c SS |
2766 | break; |
2767 | case DW_TAG_subprogram: | |
e7c27a73 | 2768 | read_func_scope (die, cu); |
c906108c SS |
2769 | break; |
2770 | case DW_TAG_inlined_subroutine: | |
2771 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2772 | They could be used to set breakpoints on all inlined instances |
2773 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2774 | break; |
2775 | case DW_TAG_lexical_block: | |
14898363 L |
2776 | case DW_TAG_try_block: |
2777 | case DW_TAG_catch_block: | |
e7c27a73 | 2778 | read_lexical_block_scope (die, cu); |
c906108c SS |
2779 | break; |
2780 | case DW_TAG_class_type: | |
680b30c7 | 2781 | case DW_TAG_interface_type: |
c906108c SS |
2782 | case DW_TAG_structure_type: |
2783 | case DW_TAG_union_type: | |
134d01f1 | 2784 | process_structure_scope (die, cu); |
c906108c SS |
2785 | break; |
2786 | case DW_TAG_enumeration_type: | |
134d01f1 | 2787 | process_enumeration_scope (die, cu); |
c906108c | 2788 | break; |
134d01f1 | 2789 | |
f792889a DJ |
2790 | /* These dies have a type, but processing them does not create |
2791 | a symbol or recurse to process the children. Therefore we can | |
2792 | read them on-demand through read_type_die. */ | |
c906108c | 2793 | case DW_TAG_subroutine_type: |
72019c9c | 2794 | case DW_TAG_set_type: |
c906108c | 2795 | case DW_TAG_array_type: |
c906108c | 2796 | case DW_TAG_pointer_type: |
c906108c | 2797 | case DW_TAG_ptr_to_member_type: |
c906108c | 2798 | case DW_TAG_reference_type: |
c906108c | 2799 | case DW_TAG_string_type: |
c906108c | 2800 | break; |
134d01f1 | 2801 | |
c906108c | 2802 | case DW_TAG_base_type: |
a02abb62 | 2803 | case DW_TAG_subrange_type: |
134d01f1 DJ |
2804 | /* Add a typedef symbol for the type definition, if it has a |
2805 | DW_AT_name. */ | |
f792889a | 2806 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 2807 | break; |
c906108c | 2808 | case DW_TAG_common_block: |
e7c27a73 | 2809 | read_common_block (die, cu); |
c906108c SS |
2810 | break; |
2811 | case DW_TAG_common_inclusion: | |
2812 | break; | |
d9fa45fe | 2813 | case DW_TAG_namespace: |
63d06c5c | 2814 | processing_has_namespace_info = 1; |
e7c27a73 | 2815 | read_namespace (die, cu); |
d9fa45fe DC |
2816 | break; |
2817 | case DW_TAG_imported_declaration: | |
2818 | case DW_TAG_imported_module: | |
2819 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2820 | information contained in these. DW_TAG_imported_declaration | |
2821 | dies shouldn't have children; DW_TAG_imported_module dies | |
2822 | shouldn't in the C++ case, but conceivably could in the | |
d68209e4 | 2823 | Fortran case. */ |
63d06c5c | 2824 | processing_has_namespace_info = 1; |
d68209e4 JK |
2825 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
2826 | dwarf_tag_name (die->tag)); | |
d9fa45fe | 2827 | break; |
c906108c | 2828 | default: |
e7c27a73 | 2829 | new_symbol (die, NULL, cu); |
c906108c SS |
2830 | break; |
2831 | } | |
2832 | } | |
2833 | ||
0114d602 DJ |
2834 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
2835 | If scope qualifiers are appropriate they will be added. The result | |
2836 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
2837 | not have a name. */ | |
2838 | ||
2839 | static const char * | |
2840 | dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu) | |
2841 | { | |
2842 | struct attribute *attr; | |
2843 | char *prefix, *name; | |
2844 | struct ui_file *buf = NULL; | |
2845 | ||
2846 | name = dwarf2_name (die, cu); | |
2847 | if (!name) | |
2848 | return NULL; | |
2849 | ||
2850 | /* These are the only languages we know how to qualify names in. */ | |
2851 | if (cu->language != language_cplus | |
2852 | && cu->language != language_java) | |
2853 | return name; | |
2854 | ||
2855 | /* If no prefix is necessary for this type of DIE, return the | |
2856 | unqualified name. The other three tags listed could be handled | |
2857 | in pdi_needs_namespace, but that requires broader changes. */ | |
2858 | if (!pdi_needs_namespace (die->tag) | |
2859 | && die->tag != DW_TAG_subprogram | |
2860 | && die->tag != DW_TAG_variable | |
2861 | && die->tag != DW_TAG_member) | |
2862 | return name; | |
2863 | ||
2864 | prefix = determine_prefix (die, cu); | |
2865 | if (*prefix != '\0') | |
2866 | name = typename_concat (&cu->objfile->objfile_obstack, prefix, | |
2867 | name, cu); | |
2868 | ||
2869 | return name; | |
2870 | } | |
2871 | ||
5fb290d7 | 2872 | static void |
e142c38c | 2873 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2874 | { |
e142c38c | 2875 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2876 | } |
2877 | ||
cb1df416 DJ |
2878 | static void |
2879 | free_cu_line_header (void *arg) | |
2880 | { | |
2881 | struct dwarf2_cu *cu = arg; | |
2882 | ||
2883 | free_line_header (cu->line_header); | |
2884 | cu->line_header = NULL; | |
2885 | } | |
2886 | ||
c906108c | 2887 | static void |
e7c27a73 | 2888 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2889 | { |
e7c27a73 DJ |
2890 | struct objfile *objfile = cu->objfile; |
2891 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2892 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2893 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2894 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2895 | struct attribute *attr; | |
e1024ff1 | 2896 | char *name = NULL; |
c906108c SS |
2897 | char *comp_dir = NULL; |
2898 | struct die_info *child_die; | |
2899 | bfd *abfd = objfile->obfd; | |
debd256d | 2900 | struct line_header *line_header = 0; |
e142c38c DJ |
2901 | CORE_ADDR baseaddr; |
2902 | ||
2903 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2904 | |
fae299cd | 2905 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2906 | |
2907 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2908 | from finish_block. */ | |
2acceee2 | 2909 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2910 | lowpc = highpc; |
2911 | lowpc += baseaddr; | |
2912 | highpc += baseaddr; | |
2913 | ||
39cbfefa DJ |
2914 | /* Find the filename. Do not use dwarf2_name here, since the filename |
2915 | is not a source language identifier. */ | |
e142c38c | 2916 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2917 | if (attr) |
2918 | { | |
2919 | name = DW_STRING (attr); | |
2920 | } | |
e1024ff1 | 2921 | |
e142c38c | 2922 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 2923 | if (attr) |
e1024ff1 DJ |
2924 | comp_dir = DW_STRING (attr); |
2925 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 2926 | { |
e1024ff1 DJ |
2927 | comp_dir = ldirname (name); |
2928 | if (comp_dir != NULL) | |
2929 | make_cleanup (xfree, comp_dir); | |
2930 | } | |
2931 | if (comp_dir != NULL) | |
2932 | { | |
2933 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2934 | directory, get rid of it. */ | |
2935 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 2936 | |
e1024ff1 DJ |
2937 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
2938 | comp_dir = cp + 1; | |
c906108c SS |
2939 | } |
2940 | ||
e1024ff1 DJ |
2941 | if (name == NULL) |
2942 | name = "<unknown>"; | |
2943 | ||
e142c38c | 2944 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2945 | if (attr) |
2946 | { | |
e142c38c | 2947 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2948 | } |
2949 | ||
b0f35d58 DL |
2950 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
2951 | if (attr) | |
2952 | cu->producer = DW_STRING (attr); | |
303b6f5d | 2953 | |
c906108c SS |
2954 | /* We assume that we're processing GCC output. */ |
2955 | processing_gcc_compilation = 2; | |
c906108c | 2956 | |
df8a16a1 DJ |
2957 | processing_has_namespace_info = 0; |
2958 | ||
c906108c SS |
2959 | start_symtab (name, comp_dir, lowpc); |
2960 | record_debugformat ("DWARF 2"); | |
303b6f5d | 2961 | record_producer (cu->producer); |
c906108c | 2962 | |
e142c38c | 2963 | initialize_cu_func_list (cu); |
c906108c | 2964 | |
cb1df416 DJ |
2965 | /* Decode line number information if present. We do this before |
2966 | processing child DIEs, so that the line header table is available | |
2967 | for DW_AT_decl_file. */ | |
e142c38c | 2968 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2969 | if (attr) |
2970 | { | |
debd256d | 2971 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2972 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2973 | if (line_header) |
2974 | { | |
cb1df416 DJ |
2975 | cu->line_header = line_header; |
2976 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 2977 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2978 | } |
5fb290d7 | 2979 | } |
debd256d | 2980 | |
cb1df416 DJ |
2981 | /* Process all dies in compilation unit. */ |
2982 | if (die->child != NULL) | |
2983 | { | |
2984 | child_die = die->child; | |
2985 | while (child_die && child_die->tag) | |
2986 | { | |
2987 | process_die (child_die, cu); | |
2988 | child_die = sibling_die (child_die); | |
2989 | } | |
2990 | } | |
2991 | ||
2e276125 JB |
2992 | /* Decode macro information, if present. Dwarf 2 macro information |
2993 | refers to information in the line number info statement program | |
2994 | header, so we can only read it if we've read the header | |
2995 | successfully. */ | |
e142c38c | 2996 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2997 | if (attr && line_header) |
2e276125 JB |
2998 | { |
2999 | unsigned int macro_offset = DW_UNSND (attr); | |
3000 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3001 | comp_dir, abfd, cu); |
2e276125 | 3002 | } |
debd256d | 3003 | do_cleanups (back_to); |
5fb290d7 DJ |
3004 | } |
3005 | ||
3006 | static void | |
e142c38c DJ |
3007 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3008 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3009 | { |
3010 | struct function_range *thisfn; | |
3011 | ||
3012 | thisfn = (struct function_range *) | |
7b5a2f43 | 3013 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3014 | thisfn->name = name; |
3015 | thisfn->lowpc = lowpc; | |
3016 | thisfn->highpc = highpc; | |
3017 | thisfn->seen_line = 0; | |
3018 | thisfn->next = NULL; | |
3019 | ||
e142c38c DJ |
3020 | if (cu->last_fn == NULL) |
3021 | cu->first_fn = thisfn; | |
5fb290d7 | 3022 | else |
e142c38c | 3023 | cu->last_fn->next = thisfn; |
5fb290d7 | 3024 | |
e142c38c | 3025 | cu->last_fn = thisfn; |
c906108c SS |
3026 | } |
3027 | ||
3028 | static void | |
e7c27a73 | 3029 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3030 | { |
e7c27a73 | 3031 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3032 | struct context_stack *new; |
c906108c SS |
3033 | CORE_ADDR lowpc; |
3034 | CORE_ADDR highpc; | |
3035 | struct die_info *child_die; | |
3036 | struct attribute *attr; | |
3037 | char *name; | |
e142c38c | 3038 | CORE_ADDR baseaddr; |
801e3a5b | 3039 | struct block *block; |
c906108c | 3040 | |
e142c38c DJ |
3041 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3042 | ||
3043 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
3044 | |
3045 | /* Ignore functions with missing or empty names and functions with | |
3046 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 3047 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3048 | return; |
3049 | ||
3050 | lowpc += baseaddr; | |
3051 | highpc += baseaddr; | |
3052 | ||
5fb290d7 | 3053 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3054 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3055 | |
c906108c | 3056 | new = push_context (0, lowpc); |
f792889a | 3057 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3058 | |
4cecd739 DJ |
3059 | /* If there is a location expression for DW_AT_frame_base, record |
3060 | it. */ | |
e142c38c | 3061 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3062 | if (attr) |
c034e007 AC |
3063 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3064 | expression is being recorded directly in the function's symbol | |
3065 | and not in a separate frame-base object. I guess this hack is | |
3066 | to avoid adding some sort of frame-base adjunct/annex to the | |
3067 | function's symbol :-(. The problem with doing this is that it | |
3068 | results in a function symbol with a location expression that | |
3069 | has nothing to do with the location of the function, ouch! The | |
3070 | relationship should be: a function's symbol has-a frame base; a | |
3071 | frame-base has-a location expression. */ | |
e7c27a73 | 3072 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3073 | |
e142c38c | 3074 | cu->list_in_scope = &local_symbols; |
c906108c | 3075 | |
639d11d3 | 3076 | if (die->child != NULL) |
c906108c | 3077 | { |
639d11d3 | 3078 | child_die = die->child; |
c906108c SS |
3079 | while (child_die && child_die->tag) |
3080 | { | |
e7c27a73 | 3081 | process_die (child_die, cu); |
c906108c SS |
3082 | child_die = sibling_die (child_die); |
3083 | } | |
3084 | } | |
3085 | ||
3086 | new = pop_context (); | |
3087 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3088 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3089 | lowpc, highpc, objfile); | |
3090 | ||
df8a16a1 DJ |
3091 | /* For C++, set the block's scope. */ |
3092 | if (cu->language == language_cplus) | |
3093 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3094 | determine_prefix (die, cu), |
df8a16a1 DJ |
3095 | processing_has_namespace_info); |
3096 | ||
801e3a5b JB |
3097 | /* If we have address ranges, record them. */ |
3098 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3099 | |
3100 | /* In C++, we can have functions nested inside functions (e.g., when | |
3101 | a function declares a class that has methods). This means that | |
3102 | when we finish processing a function scope, we may need to go | |
3103 | back to building a containing block's symbol lists. */ | |
3104 | local_symbols = new->locals; | |
3105 | param_symbols = new->params; | |
3106 | ||
921e78cf JB |
3107 | /* If we've finished processing a top-level function, subsequent |
3108 | symbols go in the file symbol list. */ | |
3109 | if (outermost_context_p ()) | |
e142c38c | 3110 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3111 | } |
3112 | ||
3113 | /* Process all the DIES contained within a lexical block scope. Start | |
3114 | a new scope, process the dies, and then close the scope. */ | |
3115 | ||
3116 | static void | |
e7c27a73 | 3117 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3118 | { |
e7c27a73 | 3119 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3120 | struct context_stack *new; |
c906108c SS |
3121 | CORE_ADDR lowpc, highpc; |
3122 | struct die_info *child_die; | |
e142c38c DJ |
3123 | CORE_ADDR baseaddr; |
3124 | ||
3125 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3126 | |
3127 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3128 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3129 | as multiple lexical blocks? Handling children in a sane way would | |
3130 | be nasty. Might be easier to properly extend generic blocks to | |
3131 | describe ranges. */ | |
e7c27a73 | 3132 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3133 | return; |
3134 | lowpc += baseaddr; | |
3135 | highpc += baseaddr; | |
3136 | ||
3137 | push_context (0, lowpc); | |
639d11d3 | 3138 | if (die->child != NULL) |
c906108c | 3139 | { |
639d11d3 | 3140 | child_die = die->child; |
c906108c SS |
3141 | while (child_die && child_die->tag) |
3142 | { | |
e7c27a73 | 3143 | process_die (child_die, cu); |
c906108c SS |
3144 | child_die = sibling_die (child_die); |
3145 | } | |
3146 | } | |
3147 | new = pop_context (); | |
3148 | ||
3149 | if (local_symbols != NULL) | |
3150 | { | |
801e3a5b JB |
3151 | struct block *block |
3152 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3153 | highpc, objfile); | |
3154 | ||
3155 | /* Note that recording ranges after traversing children, as we | |
3156 | do here, means that recording a parent's ranges entails | |
3157 | walking across all its children's ranges as they appear in | |
3158 | the address map, which is quadratic behavior. | |
3159 | ||
3160 | It would be nicer to record the parent's ranges before | |
3161 | traversing its children, simply overriding whatever you find | |
3162 | there. But since we don't even decide whether to create a | |
3163 | block until after we've traversed its children, that's hard | |
3164 | to do. */ | |
3165 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3166 | } |
3167 | local_symbols = new->locals; | |
3168 | } | |
3169 | ||
43039443 | 3170 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3171 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3172 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3173 | |
3174 | static int | |
3175 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3176 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3177 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3178 | { |
3179 | struct objfile *objfile = cu->objfile; | |
3180 | struct comp_unit_head *cu_header = &cu->header; | |
3181 | bfd *obfd = objfile->obfd; | |
3182 | unsigned int addr_size = cu_header->addr_size; | |
3183 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3184 | /* Base address selection entry. */ | |
3185 | CORE_ADDR base; | |
3186 | int found_base; | |
3187 | unsigned int dummy; | |
3188 | gdb_byte *buffer; | |
3189 | CORE_ADDR marker; | |
3190 | int low_set; | |
3191 | CORE_ADDR low = 0; | |
3192 | CORE_ADDR high = 0; | |
ff013f42 | 3193 | CORE_ADDR baseaddr; |
43039443 | 3194 | |
d00adf39 DE |
3195 | found_base = cu->base_known; |
3196 | base = cu->base_address; | |
43039443 JK |
3197 | |
3198 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3199 | { | |
3200 | complaint (&symfile_complaints, | |
3201 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
3202 | offset); | |
3203 | return 0; | |
3204 | } | |
3205 | buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3206 | ||
3207 | /* Read in the largest possible address. */ | |
3208 | marker = read_address (obfd, buffer, cu, &dummy); | |
3209 | if ((marker & mask) == mask) | |
3210 | { | |
3211 | /* If we found the largest possible address, then | |
3212 | read the base address. */ | |
3213 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3214 | buffer += 2 * addr_size; | |
3215 | offset += 2 * addr_size; | |
3216 | found_base = 1; | |
3217 | } | |
3218 | ||
3219 | low_set = 0; | |
3220 | ||
e7030f15 | 3221 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 3222 | |
43039443 JK |
3223 | while (1) |
3224 | { | |
3225 | CORE_ADDR range_beginning, range_end; | |
3226 | ||
3227 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
3228 | buffer += addr_size; | |
3229 | range_end = read_address (obfd, buffer, cu, &dummy); | |
3230 | buffer += addr_size; | |
3231 | offset += 2 * addr_size; | |
3232 | ||
3233 | /* An end of list marker is a pair of zero addresses. */ | |
3234 | if (range_beginning == 0 && range_end == 0) | |
3235 | /* Found the end of list entry. */ | |
3236 | break; | |
3237 | ||
3238 | /* Each base address selection entry is a pair of 2 values. | |
3239 | The first is the largest possible address, the second is | |
3240 | the base address. Check for a base address here. */ | |
3241 | if ((range_beginning & mask) == mask) | |
3242 | { | |
3243 | /* If we found the largest possible address, then | |
3244 | read the base address. */ | |
3245 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3246 | found_base = 1; | |
3247 | continue; | |
3248 | } | |
3249 | ||
3250 | if (!found_base) | |
3251 | { | |
3252 | /* We have no valid base address for the ranges | |
3253 | data. */ | |
3254 | complaint (&symfile_complaints, | |
3255 | _("Invalid .debug_ranges data (no base address)")); | |
3256 | return 0; | |
3257 | } | |
3258 | ||
3259 | range_beginning += base; | |
3260 | range_end += base; | |
3261 | ||
ff013f42 JK |
3262 | if (ranges_pst != NULL && range_beginning < range_end) |
3263 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3264 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
3265 | ranges_pst); | |
3266 | ||
43039443 JK |
3267 | /* FIXME: This is recording everything as a low-high |
3268 | segment of consecutive addresses. We should have a | |
3269 | data structure for discontiguous block ranges | |
3270 | instead. */ | |
3271 | if (! low_set) | |
3272 | { | |
3273 | low = range_beginning; | |
3274 | high = range_end; | |
3275 | low_set = 1; | |
3276 | } | |
3277 | else | |
3278 | { | |
3279 | if (range_beginning < low) | |
3280 | low = range_beginning; | |
3281 | if (range_end > high) | |
3282 | high = range_end; | |
3283 | } | |
3284 | } | |
3285 | ||
3286 | if (! low_set) | |
3287 | /* If the first entry is an end-of-list marker, the range | |
3288 | describes an empty scope, i.e. no instructions. */ | |
3289 | return 0; | |
3290 | ||
3291 | if (low_return) | |
3292 | *low_return = low; | |
3293 | if (high_return) | |
3294 | *high_return = high; | |
3295 | return 1; | |
3296 | } | |
3297 | ||
af34e669 DJ |
3298 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3299 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3300 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3301 | static int |
af34e669 | 3302 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3303 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c SS |
3304 | { |
3305 | struct attribute *attr; | |
af34e669 DJ |
3306 | CORE_ADDR low = 0; |
3307 | CORE_ADDR high = 0; | |
3308 | int ret = 0; | |
c906108c | 3309 | |
e142c38c | 3310 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3311 | if (attr) |
af34e669 DJ |
3312 | { |
3313 | high = DW_ADDR (attr); | |
e142c38c | 3314 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3315 | if (attr) |
3316 | low = DW_ADDR (attr); | |
3317 | else | |
3318 | /* Found high w/o low attribute. */ | |
3319 | return 0; | |
3320 | ||
3321 | /* Found consecutive range of addresses. */ | |
3322 | ret = 1; | |
3323 | } | |
c906108c | 3324 | else |
af34e669 | 3325 | { |
e142c38c | 3326 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3327 | if (attr != NULL) |
3328 | { | |
af34e669 | 3329 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 3330 | .debug_ranges section. */ |
ff013f42 | 3331 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL)) |
af34e669 | 3332 | return 0; |
43039443 | 3333 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
3334 | ret = -1; |
3335 | } | |
3336 | } | |
c906108c SS |
3337 | |
3338 | if (high < low) | |
3339 | return 0; | |
3340 | ||
3341 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3342 | eliminate duplicate copies of functions and vtables and such. | |
3343 | The linker will arbitrarily choose one and discard the others. | |
3344 | The AT_*_pc values for such functions refer to local labels in | |
3345 | these sections. If the section from that file was discarded, the | |
3346 | labels are not in the output, so the relocs get a value of 0. | |
3347 | If this is a discarded function, mark the pc bounds as invalid, | |
3348 | so that GDB will ignore it. */ | |
72dca2f5 | 3349 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3350 | return 0; |
3351 | ||
3352 | *lowpc = low; | |
3353 | *highpc = high; | |
af34e669 | 3354 | return ret; |
c906108c SS |
3355 | } |
3356 | ||
b084d499 JB |
3357 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
3358 | its low and high PC addresses. Do nothing if these addresses could not | |
3359 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
3360 | and HIGHPC to the high address if greater than HIGHPC. */ | |
3361 | ||
3362 | static void | |
3363 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
3364 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3365 | struct dwarf2_cu *cu) | |
3366 | { | |
3367 | CORE_ADDR low, high; | |
3368 | struct die_info *child = die->child; | |
3369 | ||
3370 | if (dwarf2_get_pc_bounds (die, &low, &high, cu)) | |
3371 | { | |
3372 | *lowpc = min (*lowpc, low); | |
3373 | *highpc = max (*highpc, high); | |
3374 | } | |
3375 | ||
3376 | /* If the language does not allow nested subprograms (either inside | |
3377 | subprograms or lexical blocks), we're done. */ | |
3378 | if (cu->language != language_ada) | |
3379 | return; | |
3380 | ||
3381 | /* Check all the children of the given DIE. If it contains nested | |
3382 | subprograms, then check their pc bounds. Likewise, we need to | |
3383 | check lexical blocks as well, as they may also contain subprogram | |
3384 | definitions. */ | |
3385 | while (child && child->tag) | |
3386 | { | |
3387 | if (child->tag == DW_TAG_subprogram | |
3388 | || child->tag == DW_TAG_lexical_block) | |
3389 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
3390 | child = sibling_die (child); | |
3391 | } | |
3392 | } | |
3393 | ||
fae299cd DC |
3394 | /* Get the low and high pc's represented by the scope DIE, and store |
3395 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3396 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3397 | ||
3398 | static void | |
3399 | get_scope_pc_bounds (struct die_info *die, | |
3400 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3401 | struct dwarf2_cu *cu) | |
3402 | { | |
3403 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3404 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3405 | CORE_ADDR current_low, current_high; | |
3406 | ||
3407 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3408 | { | |
3409 | best_low = current_low; | |
3410 | best_high = current_high; | |
3411 | } | |
3412 | else | |
3413 | { | |
3414 | struct die_info *child = die->child; | |
3415 | ||
3416 | while (child && child->tag) | |
3417 | { | |
3418 | switch (child->tag) { | |
3419 | case DW_TAG_subprogram: | |
b084d499 | 3420 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
3421 | break; |
3422 | case DW_TAG_namespace: | |
3423 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3424 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3425 | that current GCC's always emit the DIEs corresponding | |
3426 | to definitions of methods of classes as children of a | |
3427 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3428 | the DIEs giving the declarations, which could be | |
3429 | anywhere). But I don't see any reason why the | |
3430 | standards says that they have to be there. */ | |
3431 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3432 | ||
3433 | if (current_low != ((CORE_ADDR) -1)) | |
3434 | { | |
3435 | best_low = min (best_low, current_low); | |
3436 | best_high = max (best_high, current_high); | |
3437 | } | |
3438 | break; | |
3439 | default: | |
3440 | /* Ignore. */ | |
3441 | break; | |
3442 | } | |
3443 | ||
3444 | child = sibling_die (child); | |
3445 | } | |
3446 | } | |
3447 | ||
3448 | *lowpc = best_low; | |
3449 | *highpc = best_high; | |
3450 | } | |
3451 | ||
801e3a5b JB |
3452 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
3453 | in DIE. */ | |
3454 | static void | |
3455 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
3456 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
3457 | { | |
3458 | struct attribute *attr; | |
3459 | ||
3460 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
3461 | if (attr) | |
3462 | { | |
3463 | CORE_ADDR high = DW_ADDR (attr); | |
3464 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3465 | if (attr) | |
3466 | { | |
3467 | CORE_ADDR low = DW_ADDR (attr); | |
3468 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
3469 | } | |
3470 | } | |
3471 | ||
3472 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
3473 | if (attr) | |
3474 | { | |
3475 | bfd *obfd = cu->objfile->obfd; | |
3476 | ||
3477 | /* The value of the DW_AT_ranges attribute is the offset of the | |
3478 | address range list in the .debug_ranges section. */ | |
3479 | unsigned long offset = DW_UNSND (attr); | |
3480 | gdb_byte *buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3481 | ||
3482 | /* For some target architectures, but not others, the | |
3483 | read_address function sign-extends the addresses it returns. | |
3484 | To recognize base address selection entries, we need a | |
3485 | mask. */ | |
3486 | unsigned int addr_size = cu->header.addr_size; | |
3487 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3488 | ||
3489 | /* The base address, to which the next pair is relative. Note | |
3490 | that this 'base' is a DWARF concept: most entries in a range | |
3491 | list are relative, to reduce the number of relocs against the | |
3492 | debugging information. This is separate from this function's | |
3493 | 'baseaddr' argument, which GDB uses to relocate debugging | |
3494 | information from a shared library based on the address at | |
3495 | which the library was loaded. */ | |
d00adf39 DE |
3496 | CORE_ADDR base = cu->base_address; |
3497 | int base_known = cu->base_known; | |
801e3a5b JB |
3498 | |
3499 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3500 | { | |
3501 | complaint (&symfile_complaints, | |
3502 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
3503 | offset); | |
3504 | return; | |
3505 | } | |
3506 | ||
3507 | for (;;) | |
3508 | { | |
3509 | unsigned int bytes_read; | |
3510 | CORE_ADDR start, end; | |
3511 | ||
3512 | start = read_address (obfd, buffer, cu, &bytes_read); | |
3513 | buffer += bytes_read; | |
3514 | end = read_address (obfd, buffer, cu, &bytes_read); | |
3515 | buffer += bytes_read; | |
3516 | ||
3517 | /* Did we find the end of the range list? */ | |
3518 | if (start == 0 && end == 0) | |
3519 | break; | |
3520 | ||
3521 | /* Did we find a base address selection entry? */ | |
3522 | else if ((start & base_select_mask) == base_select_mask) | |
3523 | { | |
3524 | base = end; | |
3525 | base_known = 1; | |
3526 | } | |
3527 | ||
3528 | /* We found an ordinary address range. */ | |
3529 | else | |
3530 | { | |
3531 | if (!base_known) | |
3532 | { | |
3533 | complaint (&symfile_complaints, | |
3534 | _("Invalid .debug_ranges data (no base address)")); | |
3535 | return; | |
3536 | } | |
3537 | ||
3538 | record_block_range (block, | |
3539 | baseaddr + base + start, | |
3540 | baseaddr + base + end - 1); | |
3541 | } | |
3542 | } | |
3543 | } | |
3544 | } | |
3545 | ||
c906108c SS |
3546 | /* Add an aggregate field to the field list. */ |
3547 | ||
3548 | static void | |
107d2387 | 3549 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3550 | struct dwarf2_cu *cu) |
3551 | { | |
3552 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 3553 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
3554 | struct nextfield *new_field; |
3555 | struct attribute *attr; | |
3556 | struct field *fp; | |
3557 | char *fieldname = ""; | |
3558 | ||
3559 | /* Allocate a new field list entry and link it in. */ | |
3560 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3561 | make_cleanup (xfree, new_field); |
c906108c SS |
3562 | memset (new_field, 0, sizeof (struct nextfield)); |
3563 | new_field->next = fip->fields; | |
3564 | fip->fields = new_field; | |
3565 | fip->nfields++; | |
3566 | ||
3567 | /* Handle accessibility and virtuality of field. | |
3568 | The default accessibility for members is public, the default | |
3569 | accessibility for inheritance is private. */ | |
3570 | if (die->tag != DW_TAG_inheritance) | |
3571 | new_field->accessibility = DW_ACCESS_public; | |
3572 | else | |
3573 | new_field->accessibility = DW_ACCESS_private; | |
3574 | new_field->virtuality = DW_VIRTUALITY_none; | |
3575 | ||
e142c38c | 3576 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3577 | if (attr) |
3578 | new_field->accessibility = DW_UNSND (attr); | |
3579 | if (new_field->accessibility != DW_ACCESS_public) | |
3580 | fip->non_public_fields = 1; | |
e142c38c | 3581 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3582 | if (attr) |
3583 | new_field->virtuality = DW_UNSND (attr); | |
3584 | ||
3585 | fp = &new_field->field; | |
a9a9bd0f | 3586 | |
e142c38c | 3587 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3588 | { |
a9a9bd0f DC |
3589 | /* Data member other than a C++ static data member. */ |
3590 | ||
c906108c | 3591 | /* Get type of field. */ |
e7c27a73 | 3592 | fp->type = die_type (die, cu); |
c906108c | 3593 | |
d6a843b5 | 3594 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 3595 | |
c906108c | 3596 | /* Get bit size of field (zero if none). */ |
e142c38c | 3597 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3598 | if (attr) |
3599 | { | |
3600 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3601 | } | |
3602 | else | |
3603 | { | |
3604 | FIELD_BITSIZE (*fp) = 0; | |
3605 | } | |
3606 | ||
3607 | /* Get bit offset of field. */ | |
e142c38c | 3608 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3609 | if (attr) |
3610 | { | |
c6a0999f JB |
3611 | int byte_offset; |
3612 | ||
3690dd37 JB |
3613 | if (attr_form_is_section_offset (attr)) |
3614 | { | |
3615 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 3616 | byte_offset = 0; |
3690dd37 JB |
3617 | } |
3618 | else if (attr_form_is_constant (attr)) | |
c6a0999f | 3619 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
3690dd37 | 3620 | else |
c6a0999f JB |
3621 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
3622 | ||
d6a843b5 | 3623 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 3624 | } |
e142c38c | 3625 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3626 | if (attr) |
3627 | { | |
5e2b427d | 3628 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
3629 | { |
3630 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3631 | additional bit offset from the MSB of the containing |
3632 | anonymous object to the MSB of the field. We don't | |
3633 | have to do anything special since we don't need to | |
3634 | know the size of the anonymous object. */ | |
c906108c SS |
3635 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3636 | } | |
3637 | else | |
3638 | { | |
3639 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3640 | MSB of the anonymous object, subtract off the number of |
3641 | bits from the MSB of the field to the MSB of the | |
3642 | object, and then subtract off the number of bits of | |
3643 | the field itself. The result is the bit offset of | |
3644 | the LSB of the field. */ | |
c906108c SS |
3645 | int anonymous_size; |
3646 | int bit_offset = DW_UNSND (attr); | |
3647 | ||
e142c38c | 3648 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3649 | if (attr) |
3650 | { | |
3651 | /* The size of the anonymous object containing | |
3652 | the bit field is explicit, so use the | |
3653 | indicated size (in bytes). */ | |
3654 | anonymous_size = DW_UNSND (attr); | |
3655 | } | |
3656 | else | |
3657 | { | |
3658 | /* The size of the anonymous object containing | |
3659 | the bit field must be inferred from the type | |
3660 | attribute of the data member containing the | |
3661 | bit field. */ | |
3662 | anonymous_size = TYPE_LENGTH (fp->type); | |
3663 | } | |
3664 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3665 | - bit_offset - FIELD_BITSIZE (*fp); | |
3666 | } | |
3667 | } | |
3668 | ||
3669 | /* Get name of field. */ | |
39cbfefa DJ |
3670 | fieldname = dwarf2_name (die, cu); |
3671 | if (fieldname == NULL) | |
3672 | fieldname = ""; | |
d8151005 DJ |
3673 | |
3674 | /* The name is already allocated along with this objfile, so we don't | |
3675 | need to duplicate it for the type. */ | |
3676 | fp->name = fieldname; | |
c906108c SS |
3677 | |
3678 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3679 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3680 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3681 | { |
3682 | new_field->accessibility = DW_ACCESS_private; | |
3683 | fip->non_public_fields = 1; | |
3684 | } | |
3685 | } | |
a9a9bd0f | 3686 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3687 | { |
a9a9bd0f DC |
3688 | /* C++ static member. */ |
3689 | ||
3690 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3691 | is a declaration, but all versions of G++ as of this writing | |
3692 | (so through at least 3.2.1) incorrectly generate | |
3693 | DW_TAG_variable tags. */ | |
3694 | ||
c906108c | 3695 | char *physname; |
c906108c | 3696 | |
a9a9bd0f | 3697 | /* Get name of field. */ |
39cbfefa DJ |
3698 | fieldname = dwarf2_name (die, cu); |
3699 | if (fieldname == NULL) | |
c906108c SS |
3700 | return; |
3701 | ||
2df3850c | 3702 | /* Get physical name. */ |
e142c38c | 3703 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3704 | |
d8151005 DJ |
3705 | /* The name is already allocated along with this objfile, so we don't |
3706 | need to duplicate it for the type. */ | |
3707 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3708 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3709 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3710 | } |
3711 | else if (die->tag == DW_TAG_inheritance) | |
3712 | { | |
3713 | /* C++ base class field. */ | |
e142c38c | 3714 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3715 | if (attr) |
d6a843b5 JK |
3716 | SET_FIELD_BITPOS (*fp, decode_locdesc (DW_BLOCK (attr), cu) |
3717 | * bits_per_byte); | |
c906108c | 3718 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 3719 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3720 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3721 | fip->nbaseclasses++; | |
3722 | } | |
3723 | } | |
3724 | ||
3725 | /* Create the vector of fields, and attach it to the type. */ | |
3726 | ||
3727 | static void | |
fba45db2 | 3728 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3729 | struct dwarf2_cu *cu) |
c906108c SS |
3730 | { |
3731 | int nfields = fip->nfields; | |
3732 | ||
3733 | /* Record the field count, allocate space for the array of fields, | |
3734 | and create blank accessibility bitfields if necessary. */ | |
3735 | TYPE_NFIELDS (type) = nfields; | |
3736 | TYPE_FIELDS (type) = (struct field *) | |
3737 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3738 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3739 | ||
3740 | if (fip->non_public_fields) | |
3741 | { | |
3742 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3743 | ||
3744 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3745 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3746 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3747 | ||
3748 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3749 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3750 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3751 | ||
3752 | TYPE_FIELD_IGNORE_BITS (type) = | |
3753 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3754 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3755 | } | |
3756 | ||
3757 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3758 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3759 | if (fip->nbaseclasses) | |
3760 | { | |
3761 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 3762 | unsigned char *pointer; |
c906108c SS |
3763 | |
3764 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
3765 | pointer = TYPE_ALLOC (type, num_bytes); |
3766 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
3767 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
3768 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3769 | } | |
3770 | ||
3771 | /* Copy the saved-up fields into the field vector. Start from the head | |
3772 | of the list, adding to the tail of the field array, so that they end | |
3773 | up in the same order in the array in which they were added to the list. */ | |
3774 | while (nfields-- > 0) | |
3775 | { | |
3776 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3777 | switch (fip->fields->accessibility) | |
3778 | { | |
c5aa993b JM |
3779 | case DW_ACCESS_private: |
3780 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3781 | break; | |
c906108c | 3782 | |
c5aa993b JM |
3783 | case DW_ACCESS_protected: |
3784 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3785 | break; | |
c906108c | 3786 | |
c5aa993b JM |
3787 | case DW_ACCESS_public: |
3788 | break; | |
c906108c | 3789 | |
c5aa993b JM |
3790 | default: |
3791 | /* Unknown accessibility. Complain and treat it as public. */ | |
3792 | { | |
e2e0b3e5 | 3793 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 3794 | fip->fields->accessibility); |
c5aa993b JM |
3795 | } |
3796 | break; | |
c906108c SS |
3797 | } |
3798 | if (nfields < fip->nbaseclasses) | |
3799 | { | |
3800 | switch (fip->fields->virtuality) | |
3801 | { | |
c5aa993b JM |
3802 | case DW_VIRTUALITY_virtual: |
3803 | case DW_VIRTUALITY_pure_virtual: | |
3804 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3805 | break; | |
c906108c SS |
3806 | } |
3807 | } | |
3808 | fip->fields = fip->fields->next; | |
3809 | } | |
3810 | } | |
3811 | ||
c906108c SS |
3812 | /* Add a member function to the proper fieldlist. */ |
3813 | ||
3814 | static void | |
107d2387 | 3815 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3816 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3817 | { |
e7c27a73 | 3818 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3819 | struct attribute *attr; |
3820 | struct fnfieldlist *flp; | |
3821 | int i; | |
3822 | struct fn_field *fnp; | |
3823 | char *fieldname; | |
3824 | char *physname; | |
3825 | struct nextfnfield *new_fnfield; | |
f792889a | 3826 | struct type *this_type; |
c906108c | 3827 | |
2df3850c | 3828 | /* Get name of member function. */ |
39cbfefa DJ |
3829 | fieldname = dwarf2_name (die, cu); |
3830 | if (fieldname == NULL) | |
2df3850c | 3831 | return; |
c906108c | 3832 | |
2df3850c | 3833 | /* Get the mangled name. */ |
e142c38c | 3834 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3835 | |
3836 | /* Look up member function name in fieldlist. */ | |
3837 | for (i = 0; i < fip->nfnfields; i++) | |
3838 | { | |
27bfe10e | 3839 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3840 | break; |
3841 | } | |
3842 | ||
3843 | /* Create new list element if necessary. */ | |
3844 | if (i < fip->nfnfields) | |
3845 | flp = &fip->fnfieldlists[i]; | |
3846 | else | |
3847 | { | |
3848 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3849 | { | |
3850 | fip->fnfieldlists = (struct fnfieldlist *) | |
3851 | xrealloc (fip->fnfieldlists, | |
3852 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3853 | * sizeof (struct fnfieldlist)); |
c906108c | 3854 | if (fip->nfnfields == 0) |
c13c43fd | 3855 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3856 | } |
3857 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3858 | flp->name = fieldname; | |
3859 | flp->length = 0; | |
3860 | flp->head = NULL; | |
3861 | fip->nfnfields++; | |
3862 | } | |
3863 | ||
3864 | /* Create a new member function field and chain it to the field list | |
3865 | entry. */ | |
3866 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3867 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3868 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3869 | new_fnfield->next = flp->head; | |
3870 | flp->head = new_fnfield; | |
3871 | flp->length++; | |
3872 | ||
3873 | /* Fill in the member function field info. */ | |
3874 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3875 | /* The name is already allocated along with this objfile, so we don't |
3876 | need to duplicate it for the type. */ | |
3877 | fnp->physname = physname ? physname : ""; | |
c906108c | 3878 | fnp->type = alloc_type (objfile); |
f792889a DJ |
3879 | this_type = read_type_die (die, cu); |
3880 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 3881 | { |
f792889a | 3882 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 3883 | |
f792889a | 3884 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
3885 | of the method itself (TYPE_CODE_METHOD). */ |
3886 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
3887 | TYPE_TARGET_TYPE (this_type), |
3888 | TYPE_FIELDS (this_type), | |
3889 | TYPE_NFIELDS (this_type), | |
3890 | TYPE_VARARGS (this_type)); | |
c906108c SS |
3891 | |
3892 | /* Handle static member functions. | |
c5aa993b JM |
3893 | Dwarf2 has no clean way to discern C++ static and non-static |
3894 | member functions. G++ helps GDB by marking the first | |
3895 | parameter for non-static member functions (which is the | |
3896 | this pointer) as artificial. We obtain this information | |
3897 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 3898 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
3899 | fnp->voffset = VOFFSET_STATIC; |
3900 | } | |
3901 | else | |
e2e0b3e5 | 3902 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 3903 | physname); |
c906108c SS |
3904 | |
3905 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3906 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3907 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3908 | |
3909 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3910 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3911 | ||
3912 | /* Get accessibility. */ | |
e142c38c | 3913 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3914 | if (attr) |
3915 | { | |
3916 | switch (DW_UNSND (attr)) | |
3917 | { | |
c5aa993b JM |
3918 | case DW_ACCESS_private: |
3919 | fnp->is_private = 1; | |
3920 | break; | |
3921 | case DW_ACCESS_protected: | |
3922 | fnp->is_protected = 1; | |
3923 | break; | |
c906108c SS |
3924 | } |
3925 | } | |
3926 | ||
b02dede2 | 3927 | /* Check for artificial methods. */ |
e142c38c | 3928 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3929 | if (attr && DW_UNSND (attr) != 0) |
3930 | fnp->is_artificial = 1; | |
3931 | ||
c906108c | 3932 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3933 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3934 | if (attr) |
8e19ed76 PS |
3935 | { |
3936 | /* Support the .debug_loc offsets */ | |
3937 | if (attr_form_is_block (attr)) | |
3938 | { | |
e7c27a73 | 3939 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 3940 | } |
3690dd37 | 3941 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 3942 | { |
4d3c2250 | 3943 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3944 | } |
3945 | else | |
3946 | { | |
4d3c2250 KB |
3947 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3948 | fieldname); | |
8e19ed76 PS |
3949 | } |
3950 | } | |
c906108c SS |
3951 | } |
3952 | ||
3953 | /* Create the vector of member function fields, and attach it to the type. */ | |
3954 | ||
3955 | static void | |
fba45db2 | 3956 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3957 | struct dwarf2_cu *cu) |
c906108c SS |
3958 | { |
3959 | struct fnfieldlist *flp; | |
3960 | int total_length = 0; | |
3961 | int i; | |
3962 | ||
3963 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3964 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3965 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3966 | ||
3967 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3968 | { | |
3969 | struct nextfnfield *nfp = flp->head; | |
3970 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3971 | int k; | |
3972 | ||
3973 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3974 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3975 | fn_flp->fn_fields = (struct fn_field *) | |
3976 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3977 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3978 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3979 | |
3980 | total_length += flp->length; | |
3981 | } | |
3982 | ||
3983 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3984 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3985 | } | |
3986 | ||
1168df01 JB |
3987 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
3988 | language, zero otherwise. */ | |
3989 | static int | |
3990 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
3991 | { | |
3992 | static const char vptr[] = "_vptr"; | |
987504bb | 3993 | static const char vtable[] = "vtable"; |
1168df01 | 3994 | |
987504bb JJ |
3995 | /* Look for the C++ and Java forms of the vtable. */ |
3996 | if ((cu->language == language_java | |
3997 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
3998 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
3999 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4000 | return 1; |
4001 | ||
4002 | return 0; | |
4003 | } | |
4004 | ||
c0dd20ea DJ |
4005 | /* GCC outputs unnamed structures that are really pointers to member |
4006 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
4007 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
4008 | zero. |
4009 | ||
4010 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4011 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4012 | |
f792889a | 4013 | static struct type * |
c0dd20ea DJ |
4014 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
4015 | { | |
4016 | struct objfile *objfile = cu->objfile; | |
4017 | struct type *type; | |
4018 | struct die_info *pfn_die, *delta_die; | |
4019 | struct attribute *pfn_name, *delta_name; | |
4020 | struct type *pfn_type, *domain_type; | |
4021 | ||
4022 | /* Check for a structure with no name and two children. */ | |
4023 | if (die->tag != DW_TAG_structure_type | |
4024 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
4025 | || die->child == NULL | |
4026 | || die->child->sibling == NULL | |
4027 | || (die->child->sibling->sibling != NULL | |
4028 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 4029 | return NULL; |
c0dd20ea DJ |
4030 | |
4031 | /* Check for __pfn and __delta members. */ | |
4032 | pfn_die = die->child; | |
4033 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
4034 | if (pfn_die->tag != DW_TAG_member | |
4035 | || pfn_name == NULL | |
4036 | || DW_STRING (pfn_name) == NULL | |
4037 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 4038 | return NULL; |
c0dd20ea DJ |
4039 | |
4040 | delta_die = pfn_die->sibling; | |
4041 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
4042 | if (delta_die->tag != DW_TAG_member | |
4043 | || delta_name == NULL | |
4044 | || DW_STRING (delta_name) == NULL | |
4045 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 4046 | return NULL; |
c0dd20ea DJ |
4047 | |
4048 | /* Find the type of the method. */ | |
4049 | pfn_type = die_type (pfn_die, cu); | |
4050 | if (pfn_type == NULL | |
4051 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4052 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 4053 | return NULL; |
c0dd20ea DJ |
4054 | |
4055 | /* Look for the "this" argument. */ | |
4056 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
4057 | if (TYPE_NFIELDS (pfn_type) == 0 | |
4058 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 4059 | return NULL; |
c0dd20ea DJ |
4060 | |
4061 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
4062 | type = alloc_type (objfile); | |
4063 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
4064 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
4065 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 4066 | type = lookup_methodptr_type (type); |
f792889a | 4067 | return set_die_type (die, type, cu); |
c0dd20ea | 4068 | } |
1168df01 | 4069 | |
c906108c SS |
4070 | /* Called when we find the DIE that starts a structure or union scope |
4071 | (definition) to process all dies that define the members of the | |
4072 | structure or union. | |
4073 | ||
4074 | NOTE: we need to call struct_type regardless of whether or not the | |
4075 | DIE has an at_name attribute, since it might be an anonymous | |
4076 | structure or union. This gets the type entered into our set of | |
4077 | user defined types. | |
4078 | ||
4079 | However, if the structure is incomplete (an opaque struct/union) | |
4080 | then suppress creating a symbol table entry for it since gdb only | |
4081 | wants to find the one with the complete definition. Note that if | |
4082 | it is complete, we just call new_symbol, which does it's own | |
4083 | checking about whether the struct/union is anonymous or not (and | |
4084 | suppresses creating a symbol table entry itself). */ | |
4085 | ||
f792889a | 4086 | static struct type * |
134d01f1 | 4087 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4088 | { |
e7c27a73 | 4089 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4090 | struct type *type; |
4091 | struct attribute *attr; | |
39cbfefa | 4092 | char *name; |
0114d602 | 4093 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 4094 | |
f792889a DJ |
4095 | type = quirk_gcc_member_function_pointer (die, cu); |
4096 | if (type) | |
4097 | return type; | |
c906108c | 4098 | |
c0dd20ea | 4099 | type = alloc_type (objfile); |
c906108c | 4100 | INIT_CPLUS_SPECIFIC (type); |
39cbfefa DJ |
4101 | name = dwarf2_name (die, cu); |
4102 | if (name != NULL) | |
c906108c | 4103 | { |
987504bb JJ |
4104 | if (cu->language == language_cplus |
4105 | || cu->language == language_java) | |
63d06c5c | 4106 | { |
0114d602 DJ |
4107 | const char *new_prefix = determine_class_name (die, cu); |
4108 | TYPE_TAG_NAME (type) = (char *) new_prefix; | |
63d06c5c DC |
4109 | } |
4110 | else | |
4111 | { | |
d8151005 DJ |
4112 | /* The name is already allocated along with this objfile, so |
4113 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4114 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4115 | } |
c906108c SS |
4116 | } |
4117 | ||
4118 | if (die->tag == DW_TAG_structure_type) | |
4119 | { | |
4120 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4121 | } | |
4122 | else if (die->tag == DW_TAG_union_type) | |
4123 | { | |
4124 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4125 | } | |
4126 | else | |
4127 | { | |
4128 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 4129 | in gdbtypes.h. */ |
c906108c SS |
4130 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
4131 | } | |
4132 | ||
e142c38c | 4133 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4134 | if (attr) |
4135 | { | |
4136 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4137 | } | |
4138 | else | |
4139 | { | |
4140 | TYPE_LENGTH (type) = 0; | |
4141 | } | |
4142 | ||
876cecd0 | 4143 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 4144 | if (die_is_declaration (die, cu)) |
876cecd0 | 4145 | TYPE_STUB (type) = 1; |
dc718098 | 4146 | |
c906108c SS |
4147 | /* We need to add the type field to the die immediately so we don't |
4148 | infinitely recurse when dealing with pointers to the structure | |
4149 | type within the structure itself. */ | |
1c379e20 | 4150 | set_die_type (die, type, cu); |
c906108c | 4151 | |
e142c38c | 4152 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
4153 | { |
4154 | struct field_info fi; | |
4155 | struct die_info *child_die; | |
c906108c SS |
4156 | |
4157 | memset (&fi, 0, sizeof (struct field_info)); | |
4158 | ||
639d11d3 | 4159 | child_die = die->child; |
c906108c SS |
4160 | |
4161 | while (child_die && child_die->tag) | |
4162 | { | |
a9a9bd0f DC |
4163 | if (child_die->tag == DW_TAG_member |
4164 | || child_die->tag == DW_TAG_variable) | |
c906108c | 4165 | { |
a9a9bd0f DC |
4166 | /* NOTE: carlton/2002-11-05: A C++ static data member |
4167 | should be a DW_TAG_member that is a declaration, but | |
4168 | all versions of G++ as of this writing (so through at | |
4169 | least 3.2.1) incorrectly generate DW_TAG_variable | |
4170 | tags for them instead. */ | |
e7c27a73 | 4171 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4172 | } |
8713b1b1 | 4173 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
4174 | { |
4175 | /* C++ member function. */ | |
e7c27a73 | 4176 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
4177 | } |
4178 | else if (child_die->tag == DW_TAG_inheritance) | |
4179 | { | |
4180 | /* C++ base class field. */ | |
e7c27a73 | 4181 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4182 | } |
c906108c SS |
4183 | child_die = sibling_die (child_die); |
4184 | } | |
4185 | ||
4186 | /* Attach fields and member functions to the type. */ | |
4187 | if (fi.nfields) | |
e7c27a73 | 4188 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
4189 | if (fi.nfnfields) |
4190 | { | |
e7c27a73 | 4191 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 4192 | |
c5aa993b | 4193 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
4194 | class itself) which contains the vtable pointer for the current |
4195 | class from the DW_AT_containing_type attribute. */ | |
4196 | ||
e142c38c | 4197 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 4198 | { |
e7c27a73 | 4199 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
4200 | |
4201 | TYPE_VPTR_BASETYPE (type) = t; | |
4202 | if (type == t) | |
4203 | { | |
c906108c SS |
4204 | int i; |
4205 | ||
4206 | /* Our own class provides vtbl ptr. */ | |
4207 | for (i = TYPE_NFIELDS (t) - 1; | |
4208 | i >= TYPE_N_BASECLASSES (t); | |
4209 | --i) | |
4210 | { | |
4211 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
4212 | ||
1168df01 | 4213 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
4214 | { |
4215 | TYPE_VPTR_FIELDNO (type) = i; | |
4216 | break; | |
4217 | } | |
4218 | } | |
4219 | ||
4220 | /* Complain if virtual function table field not found. */ | |
4221 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 4222 | complaint (&symfile_complaints, |
e2e0b3e5 | 4223 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
4224 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
4225 | ""); | |
c906108c SS |
4226 | } |
4227 | else | |
4228 | { | |
4229 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4230 | } | |
4231 | } | |
f6235d4c EZ |
4232 | else if (cu->producer |
4233 | && strncmp (cu->producer, | |
4234 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
4235 | { | |
4236 | /* The IBM XLC compiler does not provide direct indication | |
4237 | of the containing type, but the vtable pointer is | |
4238 | always named __vfp. */ | |
4239 | ||
4240 | int i; | |
4241 | ||
4242 | for (i = TYPE_NFIELDS (type) - 1; | |
4243 | i >= TYPE_N_BASECLASSES (type); | |
4244 | --i) | |
4245 | { | |
4246 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
4247 | { | |
4248 | TYPE_VPTR_FIELDNO (type) = i; | |
4249 | TYPE_VPTR_BASETYPE (type) = type; | |
4250 | break; | |
4251 | } | |
4252 | } | |
4253 | } | |
c906108c | 4254 | } |
c906108c | 4255 | } |
63d06c5c | 4256 | |
0114d602 | 4257 | do_cleanups (back_to); |
f792889a | 4258 | return type; |
c906108c SS |
4259 | } |
4260 | ||
134d01f1 DJ |
4261 | static void |
4262 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4263 | { | |
4264 | struct objfile *objfile = cu->objfile; | |
90aeadfc | 4265 | struct die_info *child_die = die->child; |
f792889a | 4266 | struct type *this_type; |
c906108c | 4267 | |
f792889a DJ |
4268 | this_type = get_die_type (die, cu); |
4269 | if (this_type == NULL) | |
4270 | this_type = read_structure_type (die, cu); | |
c906108c | 4271 | |
90aeadfc DC |
4272 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4273 | snapshots) has been known to create a die giving a declaration | |
4274 | for a class that has, as a child, a die giving a definition for a | |
4275 | nested class. So we have to process our children even if the | |
4276 | current die is a declaration. Normally, of course, a declaration | |
4277 | won't have any children at all. */ | |
134d01f1 | 4278 | |
90aeadfc DC |
4279 | while (child_die != NULL && child_die->tag) |
4280 | { | |
4281 | if (child_die->tag == DW_TAG_member | |
4282 | || child_die->tag == DW_TAG_variable | |
4283 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4284 | { |
90aeadfc | 4285 | /* Do nothing. */ |
134d01f1 | 4286 | } |
90aeadfc DC |
4287 | else |
4288 | process_die (child_die, cu); | |
134d01f1 | 4289 | |
90aeadfc | 4290 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4291 | } |
4292 | ||
fa4028e9 JB |
4293 | /* Do not consider external references. According to the DWARF standard, |
4294 | these DIEs are identified by the fact that they have no byte_size | |
4295 | attribute, and a declaration attribute. */ | |
4296 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4297 | || !die_is_declaration (die, cu)) | |
f792889a | 4298 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
4299 | } |
4300 | ||
4301 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4302 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 4303 | |
f792889a | 4304 | static struct type * |
134d01f1 | 4305 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4306 | { |
e7c27a73 | 4307 | struct objfile *objfile = cu->objfile; |
c906108c | 4308 | struct type *type; |
c906108c | 4309 | struct attribute *attr; |
0114d602 | 4310 | const char *name; |
134d01f1 | 4311 | |
c906108c SS |
4312 | type = alloc_type (objfile); |
4313 | ||
4314 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
0114d602 | 4315 | name = dwarf2_full_name (die, cu); |
39cbfefa | 4316 | if (name != NULL) |
0114d602 | 4317 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 4318 | |
e142c38c | 4319 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4320 | if (attr) |
4321 | { | |
4322 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4323 | } | |
4324 | else | |
4325 | { | |
4326 | TYPE_LENGTH (type) = 0; | |
4327 | } | |
4328 | ||
137033e9 JB |
4329 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
4330 | declared as private in the package spec, and then defined only | |
4331 | inside the package body. Such types are known as Taft Amendment | |
4332 | Types. When another package uses such a type, an incomplete DIE | |
4333 | may be generated by the compiler. */ | |
02eb380e | 4334 | if (die_is_declaration (die, cu)) |
876cecd0 | 4335 | TYPE_STUB (type) = 1; |
02eb380e | 4336 | |
f792889a | 4337 | return set_die_type (die, type, cu); |
134d01f1 DJ |
4338 | } |
4339 | ||
8176b9b8 | 4340 | /* Determine the name of the type represented by DIE, which should be |
0114d602 DJ |
4341 | a named C++ or Java compound type. Return the name in question, |
4342 | allocated on the objfile obstack. */ | |
8176b9b8 | 4343 | |
0114d602 | 4344 | static const char * |
8176b9b8 DC |
4345 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) |
4346 | { | |
0114d602 | 4347 | const char *new_prefix = NULL; |
8176b9b8 DC |
4348 | |
4349 | /* If we don't have namespace debug info, guess the name by trying | |
4350 | to demangle the names of members, just like we did in | |
72bf9492 | 4351 | guess_structure_name. */ |
8176b9b8 DC |
4352 | if (!processing_has_namespace_info) |
4353 | { | |
4354 | struct die_info *child; | |
4355 | ||
4356 | for (child = die->child; | |
4357 | child != NULL && child->tag != 0; | |
4358 | child = sibling_die (child)) | |
4359 | { | |
4360 | if (child->tag == DW_TAG_subprogram) | |
4361 | { | |
0114d602 | 4362 | char *phys_prefix |
31c27f77 JJ |
4363 | = language_class_name_from_physname (cu->language_defn, |
4364 | dwarf2_linkage_name | |
8176b9b8 DC |
4365 | (child, cu)); |
4366 | ||
0114d602 DJ |
4367 | if (phys_prefix != NULL) |
4368 | { | |
4369 | new_prefix | |
4370 | = obsavestring (phys_prefix, strlen (phys_prefix), | |
4371 | &cu->objfile->objfile_obstack); | |
4372 | xfree (phys_prefix); | |
4373 | break; | |
4374 | } | |
8176b9b8 DC |
4375 | } |
4376 | } | |
4377 | } | |
4378 | ||
4379 | if (new_prefix == NULL) | |
0114d602 | 4380 | new_prefix = dwarf2_full_name (die, cu); |
8176b9b8 DC |
4381 | |
4382 | return new_prefix; | |
4383 | } | |
4384 | ||
134d01f1 DJ |
4385 | /* Given a pointer to a die which begins an enumeration, process all |
4386 | the dies that define the members of the enumeration, and create the | |
4387 | symbol for the enumeration type. | |
4388 | ||
4389 | NOTE: We reverse the order of the element list. */ | |
4390 | ||
4391 | static void | |
4392 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4393 | { | |
4394 | struct objfile *objfile = cu->objfile; | |
4395 | struct die_info *child_die; | |
4396 | struct field *fields; | |
134d01f1 DJ |
4397 | struct symbol *sym; |
4398 | int num_fields; | |
4399 | int unsigned_enum = 1; | |
39cbfefa | 4400 | char *name; |
f792889a | 4401 | struct type *this_type; |
134d01f1 | 4402 | |
c906108c SS |
4403 | num_fields = 0; |
4404 | fields = NULL; | |
f792889a DJ |
4405 | this_type = get_die_type (die, cu); |
4406 | if (this_type == NULL) | |
4407 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 4408 | if (die->child != NULL) |
c906108c | 4409 | { |
639d11d3 | 4410 | child_die = die->child; |
c906108c SS |
4411 | while (child_die && child_die->tag) |
4412 | { | |
4413 | if (child_die->tag != DW_TAG_enumerator) | |
4414 | { | |
e7c27a73 | 4415 | process_die (child_die, cu); |
c906108c SS |
4416 | } |
4417 | else | |
4418 | { | |
39cbfefa DJ |
4419 | name = dwarf2_name (child_die, cu); |
4420 | if (name) | |
c906108c | 4421 | { |
f792889a | 4422 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
4423 | if (SYMBOL_VALUE (sym) < 0) |
4424 | unsigned_enum = 0; | |
4425 | ||
4426 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4427 | { | |
4428 | fields = (struct field *) | |
4429 | xrealloc (fields, | |
4430 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4431 | * sizeof (struct field)); |
c906108c SS |
4432 | } |
4433 | ||
3567439c | 4434 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 4435 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 4436 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
4437 | FIELD_BITSIZE (fields[num_fields]) = 0; |
4438 | ||
4439 | num_fields++; | |
4440 | } | |
4441 | } | |
4442 | ||
4443 | child_die = sibling_die (child_die); | |
4444 | } | |
4445 | ||
4446 | if (num_fields) | |
4447 | { | |
f792889a DJ |
4448 | TYPE_NFIELDS (this_type) = num_fields; |
4449 | TYPE_FIELDS (this_type) = (struct field *) | |
4450 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
4451 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 4452 | sizeof (struct field) * num_fields); |
b8c9b27d | 4453 | xfree (fields); |
c906108c SS |
4454 | } |
4455 | if (unsigned_enum) | |
876cecd0 | 4456 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 4457 | } |
134d01f1 | 4458 | |
f792889a | 4459 | new_symbol (die, this_type, cu); |
c906108c SS |
4460 | } |
4461 | ||
4462 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4463 | the DIE's type field. For now, this only handles one dimensional | |
4464 | arrays. */ | |
4465 | ||
f792889a | 4466 | static struct type * |
e7c27a73 | 4467 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4468 | { |
e7c27a73 | 4469 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4470 | struct die_info *child_die; |
4471 | struct type *type = NULL; | |
4472 | struct type *element_type, *range_type, *index_type; | |
4473 | struct type **range_types = NULL; | |
4474 | struct attribute *attr; | |
4475 | int ndim = 0; | |
4476 | struct cleanup *back_to; | |
39cbfefa | 4477 | char *name; |
c906108c | 4478 | |
e7c27a73 | 4479 | element_type = die_type (die, cu); |
c906108c SS |
4480 | |
4481 | /* Irix 6.2 native cc creates array types without children for | |
4482 | arrays with unspecified length. */ | |
639d11d3 | 4483 | if (die->child == NULL) |
c906108c | 4484 | { |
6ccb9162 | 4485 | index_type = builtin_type_int32; |
c906108c | 4486 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
4487 | type = create_array_type (NULL, element_type, range_type); |
4488 | return set_die_type (die, type, cu); | |
c906108c SS |
4489 | } |
4490 | ||
4491 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4492 | child_die = die->child; |
c906108c SS |
4493 | while (child_die && child_die->tag) |
4494 | { | |
4495 | if (child_die->tag == DW_TAG_subrange_type) | |
4496 | { | |
f792889a DJ |
4497 | struct type *child_type = read_type_die (child_die, cu); |
4498 | if (child_type != NULL) | |
a02abb62 JB |
4499 | { |
4500 | /* The range type was succesfully read. Save it for | |
4501 | the array type creation. */ | |
4502 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4503 | { | |
4504 | range_types = (struct type **) | |
4505 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4506 | * sizeof (struct type *)); | |
4507 | if (ndim == 0) | |
4508 | make_cleanup (free_current_contents, &range_types); | |
4509 | } | |
f792889a | 4510 | range_types[ndim++] = child_type; |
a02abb62 | 4511 | } |
c906108c SS |
4512 | } |
4513 | child_die = sibling_die (child_die); | |
4514 | } | |
4515 | ||
4516 | /* Dwarf2 dimensions are output from left to right, create the | |
4517 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4518 | |
c906108c | 4519 | type = element_type; |
7ca2d3a3 DL |
4520 | |
4521 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4522 | { | |
4523 | int i = 0; | |
4524 | while (i < ndim) | |
4525 | type = create_array_type (NULL, type, range_types[i++]); | |
4526 | } | |
4527 | else | |
4528 | { | |
4529 | while (ndim-- > 0) | |
4530 | type = create_array_type (NULL, type, range_types[ndim]); | |
4531 | } | |
c906108c | 4532 | |
f5f8a009 EZ |
4533 | /* Understand Dwarf2 support for vector types (like they occur on |
4534 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4535 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4536 | custom vendor extension. The main difference between a regular | |
4537 | array and the vector variant is that vectors are passed by value | |
4538 | to functions. */ | |
e142c38c | 4539 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 4540 | if (attr) |
ea37ba09 | 4541 | make_vector_type (type); |
f5f8a009 | 4542 | |
39cbfefa DJ |
4543 | name = dwarf2_name (die, cu); |
4544 | if (name) | |
4545 | TYPE_NAME (type) = name; | |
714e295e | 4546 | |
c906108c SS |
4547 | do_cleanups (back_to); |
4548 | ||
4549 | /* Install the type in the die. */ | |
f792889a | 4550 | return set_die_type (die, type, cu); |
c906108c SS |
4551 | } |
4552 | ||
7ca2d3a3 DL |
4553 | static enum dwarf_array_dim_ordering |
4554 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4555 | { | |
4556 | struct attribute *attr; | |
4557 | ||
4558 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4559 | ||
4560 | if (attr) return DW_SND (attr); | |
4561 | ||
4562 | /* | |
4563 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4564 | opposite order to the dwarf2 specification, but data is still | |
4565 | laid out as per normal fortran. | |
4566 | ||
4567 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4568 | version checking. | |
4569 | */ | |
4570 | ||
4571 | if (cu->language == language_fortran && | |
4572 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4573 | { | |
4574 | return DW_ORD_row_major; | |
4575 | } | |
4576 | ||
4577 | switch (cu->language_defn->la_array_ordering) | |
4578 | { | |
4579 | case array_column_major: | |
4580 | return DW_ORD_col_major; | |
4581 | case array_row_major: | |
4582 | default: | |
4583 | return DW_ORD_row_major; | |
4584 | }; | |
4585 | } | |
4586 | ||
72019c9c GM |
4587 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4588 | the DIE's type field. */ | |
4589 | ||
f792889a | 4590 | static struct type * |
72019c9c GM |
4591 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
4592 | { | |
f792889a DJ |
4593 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
4594 | ||
4595 | return set_die_type (die, set_type, cu); | |
72019c9c | 4596 | } |
7ca2d3a3 | 4597 | |
c906108c SS |
4598 | /* First cut: install each common block member as a global variable. */ |
4599 | ||
4600 | static void | |
e7c27a73 | 4601 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4602 | { |
4603 | struct die_info *child_die; | |
4604 | struct attribute *attr; | |
4605 | struct symbol *sym; | |
4606 | CORE_ADDR base = (CORE_ADDR) 0; | |
4607 | ||
e142c38c | 4608 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4609 | if (attr) |
4610 | { | |
8e19ed76 PS |
4611 | /* Support the .debug_loc offsets */ |
4612 | if (attr_form_is_block (attr)) | |
4613 | { | |
e7c27a73 | 4614 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 4615 | } |
3690dd37 | 4616 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4617 | { |
4d3c2250 | 4618 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4619 | } |
4620 | else | |
4621 | { | |
4d3c2250 KB |
4622 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4623 | "common block member"); | |
8e19ed76 | 4624 | } |
c906108c | 4625 | } |
639d11d3 | 4626 | if (die->child != NULL) |
c906108c | 4627 | { |
639d11d3 | 4628 | child_die = die->child; |
c906108c SS |
4629 | while (child_die && child_die->tag) |
4630 | { | |
e7c27a73 | 4631 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4632 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4633 | if (attr) |
4634 | { | |
4635 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4636 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4637 | add_symbol_to_list (sym, &global_symbols); |
4638 | } | |
4639 | child_die = sibling_die (child_die); | |
4640 | } | |
4641 | } | |
4642 | } | |
4643 | ||
0114d602 | 4644 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 4645 | |
0114d602 DJ |
4646 | static struct type * |
4647 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 4648 | { |
e7c27a73 | 4649 | struct objfile *objfile = cu->objfile; |
0114d602 | 4650 | const char *previous_prefix, *name; |
9219021c | 4651 | int is_anonymous; |
0114d602 DJ |
4652 | struct type *type; |
4653 | ||
4654 | /* For extensions, reuse the type of the original namespace. */ | |
4655 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
4656 | { | |
4657 | struct die_info *ext_die; | |
4658 | struct dwarf2_cu *ext_cu = cu; | |
4659 | ext_die = dwarf2_extension (die, &ext_cu); | |
4660 | type = read_type_die (ext_die, ext_cu); | |
4661 | return set_die_type (die, type, cu); | |
4662 | } | |
9219021c | 4663 | |
e142c38c | 4664 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4665 | |
4666 | /* Now build the name of the current namespace. */ | |
4667 | ||
0114d602 DJ |
4668 | previous_prefix = determine_prefix (die, cu); |
4669 | if (previous_prefix[0] != '\0') | |
4670 | name = typename_concat (&objfile->objfile_obstack, | |
4671 | previous_prefix, name, cu); | |
4672 | ||
4673 | /* Create the type. */ | |
4674 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
4675 | objfile); | |
4676 | TYPE_NAME (type) = (char *) name; | |
4677 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4678 | ||
4679 | set_die_type (die, type, cu); | |
4680 | ||
4681 | return type; | |
4682 | } | |
4683 | ||
4684 | /* Read a C++ namespace. */ | |
4685 | ||
4686 | static void | |
4687 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4688 | { | |
4689 | struct objfile *objfile = cu->objfile; | |
4690 | const char *name; | |
4691 | int is_anonymous; | |
9219021c | 4692 | |
5c4e30ca DC |
4693 | /* Add a symbol associated to this if we haven't seen the namespace |
4694 | before. Also, add a using directive if it's an anonymous | |
4695 | namespace. */ | |
9219021c | 4696 | |
f2f0e013 | 4697 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
4698 | { |
4699 | struct type *type; | |
4700 | ||
0114d602 | 4701 | type = read_type_die (die, cu); |
e7c27a73 | 4702 | new_symbol (die, type, cu); |
5c4e30ca | 4703 | |
0114d602 | 4704 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 4705 | if (is_anonymous) |
0114d602 DJ |
4706 | { |
4707 | const char *previous_prefix = determine_prefix (die, cu); | |
4708 | cp_add_using_directive (TYPE_NAME (type), | |
4709 | strlen (previous_prefix), | |
4710 | strlen (TYPE_NAME (type))); | |
4711 | } | |
5c4e30ca | 4712 | } |
9219021c | 4713 | |
639d11d3 | 4714 | if (die->child != NULL) |
d9fa45fe | 4715 | { |
639d11d3 | 4716 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4717 | |
4718 | while (child_die && child_die->tag) | |
4719 | { | |
e7c27a73 | 4720 | process_die (child_die, cu); |
d9fa45fe DC |
4721 | child_die = sibling_die (child_die); |
4722 | } | |
4723 | } | |
38d518c9 EZ |
4724 | } |
4725 | ||
4726 | /* Return the name of the namespace represented by DIE. Set | |
4727 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
4728 | namespace. */ | |
4729 | ||
4730 | static const char * | |
e142c38c | 4731 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
4732 | { |
4733 | struct die_info *current_die; | |
4734 | const char *name = NULL; | |
4735 | ||
4736 | /* Loop through the extensions until we find a name. */ | |
4737 | ||
4738 | for (current_die = die; | |
4739 | current_die != NULL; | |
f2f0e013 | 4740 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 4741 | { |
e142c38c | 4742 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
4743 | if (name != NULL) |
4744 | break; | |
4745 | } | |
4746 | ||
4747 | /* Is it an anonymous namespace? */ | |
4748 | ||
4749 | *is_anonymous = (name == NULL); | |
4750 | if (*is_anonymous) | |
4751 | name = "(anonymous namespace)"; | |
4752 | ||
4753 | return name; | |
d9fa45fe DC |
4754 | } |
4755 | ||
c906108c SS |
4756 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
4757 | the user defined type vector. */ | |
4758 | ||
f792889a | 4759 | static struct type * |
e7c27a73 | 4760 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4761 | { |
5e2b427d | 4762 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 4763 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 4764 | struct type *type; |
8b2dbe47 KB |
4765 | struct attribute *attr_byte_size; |
4766 | struct attribute *attr_address_class; | |
4767 | int byte_size, addr_class; | |
c906108c | 4768 | |
e7c27a73 | 4769 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 4770 | |
e142c38c | 4771 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
4772 | if (attr_byte_size) |
4773 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 4774 | else |
8b2dbe47 KB |
4775 | byte_size = cu_header->addr_size; |
4776 | ||
e142c38c | 4777 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
4778 | if (attr_address_class) |
4779 | addr_class = DW_UNSND (attr_address_class); | |
4780 | else | |
4781 | addr_class = DW_ADDR_none; | |
4782 | ||
4783 | /* If the pointer size or address class is different than the | |
4784 | default, create a type variant marked as such and set the | |
4785 | length accordingly. */ | |
4786 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 4787 | { |
5e2b427d | 4788 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
4789 | { |
4790 | int type_flags; | |
4791 | ||
849957d9 | 4792 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 4793 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
4794 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
4795 | == 0); | |
8b2dbe47 KB |
4796 | type = make_type_with_address_space (type, type_flags); |
4797 | } | |
4798 | else if (TYPE_LENGTH (type) != byte_size) | |
4799 | { | |
e2e0b3e5 | 4800 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
4801 | } |
4802 | else { | |
4803 | /* Should we also complain about unhandled address classes? */ | |
4804 | } | |
c906108c | 4805 | } |
8b2dbe47 KB |
4806 | |
4807 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 4808 | return set_die_type (die, type, cu); |
c906108c SS |
4809 | } |
4810 | ||
4811 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
4812 | the user defined type vector. */ | |
4813 | ||
f792889a | 4814 | static struct type * |
e7c27a73 | 4815 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4816 | { |
e7c27a73 | 4817 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4818 | struct type *type; |
4819 | struct type *to_type; | |
4820 | struct type *domain; | |
4821 | ||
e7c27a73 DJ |
4822 | to_type = die_type (die, cu); |
4823 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
4824 | |
4825 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
4826 | type = lookup_methodptr_type (to_type); | |
4827 | else | |
4828 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 4829 | |
f792889a | 4830 | return set_die_type (die, type, cu); |
c906108c SS |
4831 | } |
4832 | ||
4833 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
4834 | the user defined type vector. */ | |
4835 | ||
f792889a | 4836 | static struct type * |
e7c27a73 | 4837 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4838 | { |
e7c27a73 | 4839 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4840 | struct type *type; |
4841 | struct attribute *attr; | |
4842 | ||
e7c27a73 | 4843 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 4844 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4845 | if (attr) |
4846 | { | |
4847 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4848 | } | |
4849 | else | |
4850 | { | |
107d2387 | 4851 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 4852 | } |
f792889a | 4853 | return set_die_type (die, type, cu); |
c906108c SS |
4854 | } |
4855 | ||
f792889a | 4856 | static struct type * |
e7c27a73 | 4857 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4858 | { |
f792889a | 4859 | struct type *base_type, *cv_type; |
c906108c | 4860 | |
e7c27a73 | 4861 | base_type = die_type (die, cu); |
f792889a DJ |
4862 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
4863 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4864 | } |
4865 | ||
f792889a | 4866 | static struct type * |
e7c27a73 | 4867 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4868 | { |
f792889a | 4869 | struct type *base_type, *cv_type; |
c906108c | 4870 | |
e7c27a73 | 4871 | base_type = die_type (die, cu); |
f792889a DJ |
4872 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
4873 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4874 | } |
4875 | ||
4876 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4877 | the user defined type vector. It isn't really a user defined type, | |
4878 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4879 | attribute to reference it. */ | |
4880 | ||
f792889a | 4881 | static struct type * |
e7c27a73 | 4882 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4883 | { |
e7c27a73 | 4884 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4885 | struct type *type, *range_type, *index_type, *char_type; |
4886 | struct attribute *attr; | |
4887 | unsigned int length; | |
4888 | ||
e142c38c | 4889 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4890 | if (attr) |
4891 | { | |
4892 | length = DW_UNSND (attr); | |
4893 | } | |
4894 | else | |
4895 | { | |
b21b22e0 | 4896 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4897 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4898 | if (attr) |
4899 | { | |
4900 | length = DW_UNSND (attr); | |
4901 | } | |
4902 | else | |
4903 | { | |
4904 | length = 1; | |
4905 | } | |
c906108c | 4906 | } |
6ccb9162 UW |
4907 | |
4908 | index_type = builtin_type_int32; | |
c906108c | 4909 | range_type = create_range_type (NULL, index_type, 1, length); |
6ccb9162 UW |
4910 | type = create_string_type (NULL, range_type); |
4911 | ||
f792889a | 4912 | return set_die_type (die, type, cu); |
c906108c SS |
4913 | } |
4914 | ||
4915 | /* Handle DIES due to C code like: | |
4916 | ||
4917 | struct foo | |
c5aa993b JM |
4918 | { |
4919 | int (*funcp)(int a, long l); | |
4920 | int b; | |
4921 | }; | |
c906108c SS |
4922 | |
4923 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4924 | */ |
c906108c | 4925 | |
f792889a | 4926 | static struct type * |
e7c27a73 | 4927 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4928 | { |
4929 | struct type *type; /* Type that this function returns */ | |
4930 | struct type *ftype; /* Function that returns above type */ | |
4931 | struct attribute *attr; | |
4932 | ||
e7c27a73 | 4933 | type = die_type (die, cu); |
1326e61b | 4934 | ftype = make_function_type (type, (struct type **) 0); |
c906108c | 4935 | |
5b8101ae | 4936 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 4937 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4938 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 4939 | || cu->language == language_cplus |
5b8101ae PM |
4940 | || cu->language == language_java |
4941 | || cu->language == language_pascal) | |
876cecd0 | 4942 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 4943 | |
c055b101 CV |
4944 | /* Store the calling convention in the type if it's available in |
4945 | the subroutine die. Otherwise set the calling convention to | |
4946 | the default value DW_CC_normal. */ | |
4947 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
4948 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
4949 | ||
639d11d3 | 4950 | if (die->child != NULL) |
c906108c SS |
4951 | { |
4952 | struct die_info *child_die; | |
4953 | int nparams = 0; | |
4954 | int iparams = 0; | |
4955 | ||
4956 | /* Count the number of parameters. | |
4957 | FIXME: GDB currently ignores vararg functions, but knows about | |
4958 | vararg member functions. */ | |
639d11d3 | 4959 | child_die = die->child; |
c906108c SS |
4960 | while (child_die && child_die->tag) |
4961 | { | |
4962 | if (child_die->tag == DW_TAG_formal_parameter) | |
4963 | nparams++; | |
4964 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 4965 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
4966 | child_die = sibling_die (child_die); |
4967 | } | |
4968 | ||
4969 | /* Allocate storage for parameters and fill them in. */ | |
4970 | TYPE_NFIELDS (ftype) = nparams; | |
4971 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 4972 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 4973 | |
639d11d3 | 4974 | child_die = die->child; |
c906108c SS |
4975 | while (child_die && child_die->tag) |
4976 | { | |
4977 | if (child_die->tag == DW_TAG_formal_parameter) | |
4978 | { | |
4979 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4980 | member functions. G++ helps GDB by marking the first |
4981 | parameter for non-static member functions (which is the | |
4982 | this pointer) as artificial. We pass this information | |
4983 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4984 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4985 | if (attr) |
4986 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4987 | else | |
4988 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4989 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4990 | iparams++; |
4991 | } | |
4992 | child_die = sibling_die (child_die); | |
4993 | } | |
4994 | } | |
4995 | ||
f792889a | 4996 | return set_die_type (die, ftype, cu); |
c906108c SS |
4997 | } |
4998 | ||
f792889a | 4999 | static struct type * |
e7c27a73 | 5000 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5001 | { |
e7c27a73 | 5002 | struct objfile *objfile = cu->objfile; |
2f038fcb | 5003 | struct attribute *attr; |
0114d602 | 5004 | const char *name = NULL; |
f792889a | 5005 | struct type *this_type; |
c906108c | 5006 | |
0114d602 | 5007 | name = dwarf2_full_name (die, cu); |
f792889a | 5008 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5009 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5010 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
5011 | set_die_type (die, this_type, cu); |
5012 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
5013 | return this_type; | |
c906108c SS |
5014 | } |
5015 | ||
5016 | /* Find a representation of a given base type and install | |
5017 | it in the TYPE field of the die. */ | |
5018 | ||
f792889a | 5019 | static struct type * |
e7c27a73 | 5020 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5021 | { |
e7c27a73 | 5022 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5023 | struct type *type; |
5024 | struct attribute *attr; | |
5025 | int encoding = 0, size = 0; | |
39cbfefa | 5026 | char *name; |
6ccb9162 UW |
5027 | enum type_code code = TYPE_CODE_INT; |
5028 | int type_flags = 0; | |
5029 | struct type *target_type = NULL; | |
c906108c | 5030 | |
e142c38c | 5031 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
5032 | if (attr) |
5033 | { | |
5034 | encoding = DW_UNSND (attr); | |
5035 | } | |
e142c38c | 5036 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5037 | if (attr) |
5038 | { | |
5039 | size = DW_UNSND (attr); | |
5040 | } | |
39cbfefa | 5041 | name = dwarf2_name (die, cu); |
6ccb9162 | 5042 | if (!name) |
c906108c | 5043 | { |
6ccb9162 UW |
5044 | complaint (&symfile_complaints, |
5045 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 5046 | } |
6ccb9162 UW |
5047 | |
5048 | switch (encoding) | |
c906108c | 5049 | { |
6ccb9162 UW |
5050 | case DW_ATE_address: |
5051 | /* Turn DW_ATE_address into a void * pointer. */ | |
5052 | code = TYPE_CODE_PTR; | |
5053 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5054 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
5055 | break; | |
5056 | case DW_ATE_boolean: | |
5057 | code = TYPE_CODE_BOOL; | |
5058 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5059 | break; | |
5060 | case DW_ATE_complex_float: | |
5061 | code = TYPE_CODE_COMPLEX; | |
5062 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
5063 | break; | |
5064 | case DW_ATE_decimal_float: | |
5065 | code = TYPE_CODE_DECFLOAT; | |
5066 | break; | |
5067 | case DW_ATE_float: | |
5068 | code = TYPE_CODE_FLT; | |
5069 | break; | |
5070 | case DW_ATE_signed: | |
5071 | break; | |
5072 | case DW_ATE_unsigned: | |
5073 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5074 | break; | |
5075 | case DW_ATE_signed_char: | |
1760d9d5 | 5076 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5077 | code = TYPE_CODE_CHAR; |
5078 | break; | |
5079 | case DW_ATE_unsigned_char: | |
1760d9d5 | 5080 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5081 | code = TYPE_CODE_CHAR; |
5082 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5083 | break; | |
5084 | default: | |
5085 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
5086 | dwarf_type_encoding_name (encoding)); | |
5087 | break; | |
c906108c | 5088 | } |
6ccb9162 | 5089 | |
0114d602 DJ |
5090 | type = init_type (code, size, type_flags, NULL, objfile); |
5091 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
5092 | TYPE_TARGET_TYPE (type) = target_type; |
5093 | ||
0114d602 | 5094 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 5095 | TYPE_NOSIGN (type) = 1; |
0114d602 | 5096 | |
f792889a | 5097 | return set_die_type (die, type, cu); |
c906108c SS |
5098 | } |
5099 | ||
a02abb62 JB |
5100 | /* Read the given DW_AT_subrange DIE. */ |
5101 | ||
f792889a | 5102 | static struct type * |
a02abb62 JB |
5103 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
5104 | { | |
5e2b427d | 5105 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
5106 | struct type *base_type; |
5107 | struct type *range_type; | |
5108 | struct attribute *attr; | |
5109 | int low = 0; | |
5110 | int high = -1; | |
39cbfefa | 5111 | char *name; |
a02abb62 | 5112 | |
a02abb62 | 5113 | base_type = die_type (die, cu); |
3d1f72c2 | 5114 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
5115 | { |
5116 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5117 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 5118 | base_type |
5e2b427d | 5119 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 5120 | 0, NULL, cu->objfile); |
a02abb62 JB |
5121 | } |
5122 | ||
e142c38c | 5123 | if (cu->language == language_fortran) |
a02abb62 JB |
5124 | { |
5125 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
5126 | low = 1; | |
5127 | } | |
5128 | ||
dd5e6932 DJ |
5129 | /* FIXME: For variable sized arrays either of these could be |
5130 | a variable rather than a constant value. We'll allow it, | |
5131 | but we don't know how to handle it. */ | |
e142c38c | 5132 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
5133 | if (attr) |
5134 | low = dwarf2_get_attr_constant_value (attr, 0); | |
5135 | ||
e142c38c | 5136 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
5137 | if (attr) |
5138 | { | |
5139 | if (attr->form == DW_FORM_block1) | |
5140 | { | |
5141 | /* GCC encodes arrays with unspecified or dynamic length | |
5142 | with a DW_FORM_block1 attribute. | |
5143 | FIXME: GDB does not yet know how to handle dynamic | |
5144 | arrays properly, treat them as arrays with unspecified | |
5145 | length for now. | |
5146 | ||
5147 | FIXME: jimb/2003-09-22: GDB does not really know | |
5148 | how to handle arrays of unspecified length | |
5149 | either; we just represent them as zero-length | |
5150 | arrays. Choose an appropriate upper bound given | |
5151 | the lower bound we've computed above. */ | |
5152 | high = low - 1; | |
5153 | } | |
5154 | else | |
5155 | high = dwarf2_get_attr_constant_value (attr, 1); | |
5156 | } | |
5157 | ||
5158 | range_type = create_range_type (NULL, base_type, low, high); | |
5159 | ||
39cbfefa DJ |
5160 | name = dwarf2_name (die, cu); |
5161 | if (name) | |
5162 | TYPE_NAME (range_type) = name; | |
a02abb62 | 5163 | |
e142c38c | 5164 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
5165 | if (attr) |
5166 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
5167 | ||
f792889a | 5168 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
5169 | } |
5170 | ||
f792889a | 5171 | static struct type * |
81a17f79 JB |
5172 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
5173 | { | |
5174 | struct type *type; | |
81a17f79 | 5175 | |
81a17f79 JB |
5176 | /* For now, we only support the C meaning of an unspecified type: void. */ |
5177 | ||
0114d602 DJ |
5178 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
5179 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 5180 | |
f792889a | 5181 | return set_die_type (die, type, cu); |
81a17f79 | 5182 | } |
a02abb62 | 5183 | |
51545339 DJ |
5184 | /* Trivial hash function for die_info: the hash value of a DIE |
5185 | is its offset in .debug_info for this objfile. */ | |
5186 | ||
5187 | static hashval_t | |
5188 | die_hash (const void *item) | |
5189 | { | |
5190 | const struct die_info *die = item; | |
5191 | return die->offset; | |
5192 | } | |
5193 | ||
5194 | /* Trivial comparison function for die_info structures: two DIEs | |
5195 | are equal if they have the same offset. */ | |
5196 | ||
5197 | static int | |
5198 | die_eq (const void *item_lhs, const void *item_rhs) | |
5199 | { | |
5200 | const struct die_info *die_lhs = item_lhs; | |
5201 | const struct die_info *die_rhs = item_rhs; | |
5202 | return die_lhs->offset == die_rhs->offset; | |
5203 | } | |
5204 | ||
c906108c SS |
5205 | /* Read a whole compilation unit into a linked list of dies. */ |
5206 | ||
f9aca02d | 5207 | static struct die_info * |
fe1b8b76 | 5208 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5209 | { |
51545339 DJ |
5210 | cu->die_hash |
5211 | = htab_create_alloc_ex (cu->header.length / 12, | |
5212 | die_hash, | |
5213 | die_eq, | |
5214 | NULL, | |
5215 | &cu->comp_unit_obstack, | |
5216 | hashtab_obstack_allocate, | |
5217 | dummy_obstack_deallocate); | |
5218 | ||
e7c27a73 | 5219 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
5220 | } |
5221 | ||
d97bc12b DE |
5222 | /* Main entry point for reading a DIE and all children. |
5223 | Read the DIE and dump it if requested. */ | |
5224 | ||
5225 | static struct die_info * | |
5226 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, | |
5227 | struct dwarf2_cu *cu, | |
5228 | gdb_byte **new_info_ptr, | |
5229 | struct die_info *parent) | |
5230 | { | |
5231 | struct die_info *result = read_die_and_children_1 (info_ptr, abfd, cu, | |
5232 | new_info_ptr, parent); | |
5233 | ||
5234 | if (dwarf2_die_debug) | |
5235 | { | |
5236 | fprintf_unfiltered (gdb_stdlog, "Read die from .debug_info:\n"); | |
5237 | dump_die (result, dwarf2_die_debug); | |
5238 | } | |
5239 | ||
5240 | return result; | |
5241 | } | |
5242 | ||
639d11d3 DC |
5243 | /* Read a single die and all its descendents. Set the die's sibling |
5244 | field to NULL; set other fields in the die correctly, and set all | |
5245 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
5246 | location of the info_ptr after reading all of those dies. PARENT | |
5247 | is the parent of the die in question. */ | |
5248 | ||
5249 | static struct die_info * | |
d97bc12b DE |
5250 | read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd, |
5251 | struct dwarf2_cu *cu, | |
5252 | gdb_byte **new_info_ptr, | |
5253 | struct die_info *parent) | |
639d11d3 DC |
5254 | { |
5255 | struct die_info *die; | |
fe1b8b76 | 5256 | gdb_byte *cur_ptr; |
639d11d3 DC |
5257 | int has_children; |
5258 | ||
e7c27a73 | 5259 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
1d325ec1 DJ |
5260 | if (die == NULL) |
5261 | { | |
5262 | *new_info_ptr = cur_ptr; | |
5263 | return NULL; | |
5264 | } | |
51545339 | 5265 | store_in_ref_table (die, cu); |
639d11d3 DC |
5266 | |
5267 | if (has_children) | |
5268 | { | |
e7c27a73 | 5269 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5270 | new_info_ptr, die); |
5271 | } | |
5272 | else | |
5273 | { | |
5274 | die->child = NULL; | |
5275 | *new_info_ptr = cur_ptr; | |
5276 | } | |
5277 | ||
5278 | die->sibling = NULL; | |
5279 | die->parent = parent; | |
5280 | return die; | |
5281 | } | |
5282 | ||
5283 | /* Read a die, all of its descendents, and all of its siblings; set | |
5284 | all of the fields of all of the dies correctly. Arguments are as | |
5285 | in read_die_and_children. */ | |
5286 | ||
5287 | static struct die_info * | |
fe1b8b76 | 5288 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5289 | struct dwarf2_cu *cu, |
fe1b8b76 | 5290 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5291 | struct die_info *parent) |
5292 | { | |
5293 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5294 | gdb_byte *cur_ptr; |
639d11d3 | 5295 | |
c906108c | 5296 | cur_ptr = info_ptr; |
639d11d3 DC |
5297 | first_die = last_sibling = NULL; |
5298 | ||
5299 | while (1) | |
c906108c | 5300 | { |
639d11d3 | 5301 | struct die_info *die |
d97bc12b | 5302 | = read_die_and_children_1 (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 | 5303 | |
1d325ec1 | 5304 | if (die == NULL) |
c906108c | 5305 | { |
639d11d3 DC |
5306 | *new_info_ptr = cur_ptr; |
5307 | return first_die; | |
c906108c | 5308 | } |
1d325ec1 DJ |
5309 | |
5310 | if (!first_die) | |
5311 | first_die = die; | |
c906108c | 5312 | else |
1d325ec1 DJ |
5313 | last_sibling->sibling = die; |
5314 | ||
5315 | last_sibling = die; | |
c906108c | 5316 | } |
c906108c SS |
5317 | } |
5318 | ||
233a11ab CS |
5319 | /* Decompress a section that was compressed using zlib. Store the |
5320 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
5321 | ||
5322 | static void | |
5323 | zlib_decompress_section (struct objfile *objfile, asection *sectp, | |
5324 | gdb_byte **outbuf, bfd_size_type *outsize) | |
5325 | { | |
ef72380d | 5326 | bfd *abfd = objfile->obfd; |
233a11ab CS |
5327 | #ifndef HAVE_ZLIB_H |
5328 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
5329 | "is disabled in this copy of GDB"), | |
5330 | bfd_get_filename (abfd)); | |
5331 | #else | |
233a11ab CS |
5332 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
5333 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
5334 | bfd_size_type uncompressed_size; | |
5335 | gdb_byte *uncompressed_buffer; | |
5336 | z_stream strm; | |
5337 | int rc; | |
5338 | int header_size = 12; | |
5339 | ||
5340 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
5341 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
5342 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
5343 | bfd_get_filename (abfd)); | |
5344 | ||
5345 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
5346 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
5347 | if (compressed_size < header_size | |
5348 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
5349 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
5350 | bfd_get_filename (abfd)); | |
5351 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
5352 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
5353 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
5354 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
5355 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
5356 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
5357 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
5358 | uncompressed_size += compressed_buffer[11]; | |
5359 | ||
5360 | /* It is possible the section consists of several compressed | |
5361 | buffers concatenated together, so we uncompress in a loop. */ | |
5362 | strm.zalloc = NULL; | |
5363 | strm.zfree = NULL; | |
5364 | strm.opaque = NULL; | |
5365 | strm.avail_in = compressed_size - header_size; | |
5366 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
5367 | strm.avail_out = uncompressed_size; | |
5368 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
5369 | uncompressed_size); | |
5370 | rc = inflateInit (&strm); | |
5371 | while (strm.avail_in > 0) | |
5372 | { | |
5373 | if (rc != Z_OK) | |
5374 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
5375 | bfd_get_filename (abfd), rc); | |
5376 | strm.next_out = ((Bytef*) uncompressed_buffer | |
5377 | + (uncompressed_size - strm.avail_out)); | |
5378 | rc = inflate (&strm, Z_FINISH); | |
5379 | if (rc != Z_STREAM_END) | |
5380 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
5381 | bfd_get_filename (abfd), rc); | |
5382 | rc = inflateReset (&strm); | |
5383 | } | |
5384 | rc = inflateEnd (&strm); | |
5385 | if (rc != Z_OK | |
5386 | || strm.avail_out != 0) | |
5387 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
5388 | bfd_get_filename (abfd), rc); | |
5389 | ||
5390 | xfree (compressed_buffer); | |
5391 | *outbuf = uncompressed_buffer; | |
5392 | *outsize = uncompressed_size; | |
5393 | #endif | |
5394 | } | |
5395 | ||
5396 | ||
c906108c | 5397 | /* Read the contents of the section at OFFSET and of size SIZE from the |
233a11ab CS |
5398 | object file specified by OBJFILE into the objfile_obstack and return it. |
5399 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 5400 | |
fe1b8b76 | 5401 | gdb_byte * |
188dd5d6 | 5402 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
5403 | { |
5404 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 5405 | gdb_byte *buf, *retbuf; |
2c500098 | 5406 | bfd_size_type size = bfd_get_section_size (sectp); |
233a11ab | 5407 | unsigned char header[4]; |
c906108c SS |
5408 | |
5409 | if (size == 0) | |
5410 | return NULL; | |
5411 | ||
233a11ab CS |
5412 | /* Check if the file has a 4-byte header indicating compression. */ |
5413 | if (size > sizeof (header) | |
5414 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
5415 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
5416 | { | |
5417 | /* Upon decompression, update the buffer and its size. */ | |
5418 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
5419 | { | |
5420 | zlib_decompress_section (objfile, sectp, &buf, &size); | |
5421 | dwarf2_resize_section (sectp, size); | |
5422 | return buf; | |
5423 | } | |
5424 | } | |
5425 | ||
5426 | /* If we get here, we are a normal, not-compressed section. */ | |
fe1b8b76 | 5427 | buf = obstack_alloc (&objfile->objfile_obstack, size); |
233a11ab CS |
5428 | /* When debugging .o files, we may need to apply relocations; see |
5429 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
5430 | We never compress sections in .o files, so we only need to | |
5431 | try this when the section is not compressed. */ | |
fe1b8b76 | 5432 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); |
086df311 DJ |
5433 | if (retbuf != NULL) |
5434 | return retbuf; | |
5435 | ||
188dd5d6 DJ |
5436 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
5437 | || bfd_bread (buf, size, abfd) != size) | |
8a3fe4f8 | 5438 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
188dd5d6 DJ |
5439 | bfd_get_filename (abfd)); |
5440 | ||
c906108c SS |
5441 | return buf; |
5442 | } | |
5443 | ||
5444 | /* In DWARF version 2, the description of the debugging information is | |
5445 | stored in a separate .debug_abbrev section. Before we read any | |
5446 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5447 | in a hash table. This function also sets flags in CU describing |
5448 | the data found in the abbrev table. */ | |
c906108c SS |
5449 | |
5450 | static void | |
e7c27a73 | 5451 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5452 | { |
e7c27a73 | 5453 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5454 | gdb_byte *abbrev_ptr; |
c906108c SS |
5455 | struct abbrev_info *cur_abbrev; |
5456 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5457 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5458 | struct attr_abbrev *cur_attrs; |
5459 | unsigned int allocated_attrs; | |
c906108c | 5460 | |
57349743 | 5461 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5462 | obstack_init (&cu->abbrev_obstack); |
5463 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5464 | (ABBREV_HASH_SIZE | |
5465 | * sizeof (struct abbrev_info *))); | |
5466 | memset (cu->dwarf2_abbrevs, 0, | |
5467 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5468 | |
6502dd73 | 5469 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
5470 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5471 | abbrev_ptr += bytes_read; | |
5472 | ||
f3dd6933 DJ |
5473 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5474 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5475 | ||
c906108c SS |
5476 | /* loop until we reach an abbrev number of 0 */ |
5477 | while (abbrev_number) | |
5478 | { | |
f3dd6933 | 5479 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5480 | |
5481 | /* read in abbrev header */ | |
5482 | cur_abbrev->number = abbrev_number; | |
5483 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5484 | abbrev_ptr += bytes_read; | |
5485 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5486 | abbrev_ptr += 1; | |
5487 | ||
72bf9492 DJ |
5488 | if (cur_abbrev->tag == DW_TAG_namespace) |
5489 | cu->has_namespace_info = 1; | |
5490 | ||
c906108c SS |
5491 | /* now read in declarations */ |
5492 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5493 | abbrev_ptr += bytes_read; | |
5494 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5495 | abbrev_ptr += bytes_read; | |
5496 | while (abbrev_name) | |
5497 | { | |
f3dd6933 | 5498 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5499 | { |
f3dd6933 DJ |
5500 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5501 | cur_attrs | |
5502 | = xrealloc (cur_attrs, (allocated_attrs | |
5503 | * sizeof (struct attr_abbrev))); | |
c906108c | 5504 | } |
ae038cb0 DJ |
5505 | |
5506 | /* Record whether this compilation unit might have | |
5507 | inter-compilation-unit references. If we don't know what form | |
5508 | this attribute will have, then it might potentially be a | |
5509 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5510 | references. */ | |
5511 | ||
5512 | if (abbrev_form == DW_FORM_ref_addr | |
5513 | || abbrev_form == DW_FORM_indirect) | |
5514 | cu->has_form_ref_addr = 1; | |
5515 | ||
f3dd6933 DJ |
5516 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5517 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5518 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5519 | abbrev_ptr += bytes_read; | |
5520 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5521 | abbrev_ptr += bytes_read; | |
5522 | } | |
5523 | ||
f3dd6933 DJ |
5524 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5525 | (cur_abbrev->num_attrs | |
5526 | * sizeof (struct attr_abbrev))); | |
5527 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5528 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5529 | ||
c906108c | 5530 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5531 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5532 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5533 | |
5534 | /* Get next abbreviation. | |
5535 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5536 | always properly terminated with an abbrev number of 0. |
5537 | Exit loop if we encounter an abbreviation which we have | |
5538 | already read (which means we are about to read the abbreviations | |
5539 | for the next compile unit) or if the end of the abbreviation | |
5540 | table is reached. */ | |
6502dd73 DJ |
5541 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
5542 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
5543 | break; |
5544 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5545 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5546 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5547 | break; |
5548 | } | |
f3dd6933 DJ |
5549 | |
5550 | xfree (cur_attrs); | |
c906108c SS |
5551 | } |
5552 | ||
f3dd6933 | 5553 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5554 | |
c906108c | 5555 | static void |
f3dd6933 | 5556 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5557 | { |
f3dd6933 | 5558 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5559 | |
f3dd6933 DJ |
5560 | obstack_free (&cu->abbrev_obstack, NULL); |
5561 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5562 | } |
5563 | ||
5564 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5565 | ||
5566 | static struct abbrev_info * | |
e7c27a73 | 5567 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5568 | { |
5569 | unsigned int hash_number; | |
5570 | struct abbrev_info *abbrev; | |
5571 | ||
5572 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5573 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5574 | |
5575 | while (abbrev) | |
5576 | { | |
5577 | if (abbrev->number == number) | |
5578 | return abbrev; | |
5579 | else | |
5580 | abbrev = abbrev->next; | |
5581 | } | |
5582 | return NULL; | |
5583 | } | |
5584 | ||
72bf9492 DJ |
5585 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5586 | symbol for. */ | |
5587 | ||
5588 | static int | |
5589 | is_type_tag_for_partial (int tag) | |
5590 | { | |
5591 | switch (tag) | |
5592 | { | |
5593 | #if 0 | |
5594 | /* Some types that would be reasonable to generate partial symbols for, | |
5595 | that we don't at present. */ | |
5596 | case DW_TAG_array_type: | |
5597 | case DW_TAG_file_type: | |
5598 | case DW_TAG_ptr_to_member_type: | |
5599 | case DW_TAG_set_type: | |
5600 | case DW_TAG_string_type: | |
5601 | case DW_TAG_subroutine_type: | |
5602 | #endif | |
5603 | case DW_TAG_base_type: | |
5604 | case DW_TAG_class_type: | |
680b30c7 | 5605 | case DW_TAG_interface_type: |
72bf9492 DJ |
5606 | case DW_TAG_enumeration_type: |
5607 | case DW_TAG_structure_type: | |
5608 | case DW_TAG_subrange_type: | |
5609 | case DW_TAG_typedef: | |
5610 | case DW_TAG_union_type: | |
5611 | return 1; | |
5612 | default: | |
5613 | return 0; | |
5614 | } | |
5615 | } | |
5616 | ||
5617 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5618 | ||
5619 | static struct partial_die_info * | |
fe1b8b76 | 5620 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5621 | struct dwarf2_cu *cu) |
5622 | { | |
5623 | struct partial_die_info *part_die; | |
5624 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5625 | struct abbrev_info *abbrev; | |
5626 | unsigned int bytes_read; | |
5afb4e99 | 5627 | unsigned int load_all = 0; |
72bf9492 DJ |
5628 | |
5629 | int nesting_level = 1; | |
5630 | ||
5631 | parent_die = NULL; | |
5632 | last_die = NULL; | |
5633 | ||
5afb4e99 DJ |
5634 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5635 | load_all = 1; | |
5636 | ||
72bf9492 DJ |
5637 | cu->partial_dies |
5638 | = htab_create_alloc_ex (cu->header.length / 12, | |
5639 | partial_die_hash, | |
5640 | partial_die_eq, | |
5641 | NULL, | |
5642 | &cu->comp_unit_obstack, | |
5643 | hashtab_obstack_allocate, | |
5644 | dummy_obstack_deallocate); | |
5645 | ||
5646 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5647 | sizeof (struct partial_die_info)); | |
5648 | ||
5649 | while (1) | |
5650 | { | |
5651 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5652 | ||
5653 | /* A NULL abbrev means the end of a series of children. */ | |
5654 | if (abbrev == NULL) | |
5655 | { | |
5656 | if (--nesting_level == 0) | |
5657 | { | |
5658 | /* PART_DIE was probably the last thing allocated on the | |
5659 | comp_unit_obstack, so we could call obstack_free | |
5660 | here. We don't do that because the waste is small, | |
5661 | and will be cleaned up when we're done with this | |
5662 | compilation unit. This way, we're also more robust | |
5663 | against other users of the comp_unit_obstack. */ | |
5664 | return first_die; | |
5665 | } | |
5666 | info_ptr += bytes_read; | |
5667 | last_die = parent_die; | |
5668 | parent_die = parent_die->die_parent; | |
5669 | continue; | |
5670 | } | |
5671 | ||
5afb4e99 DJ |
5672 | /* Check whether this DIE is interesting enough to save. Normally |
5673 | we would not be interested in members here, but there may be | |
5674 | later variables referencing them via DW_AT_specification (for | |
5675 | static members). */ | |
5676 | if (!load_all | |
5677 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5678 | && abbrev->tag != DW_TAG_enumerator |
5679 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 5680 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 5681 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
5682 | && abbrev->tag != DW_TAG_namespace |
5683 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5684 | { |
5685 | /* Otherwise we skip to the next sibling, if any. */ | |
5686 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5687 | continue; | |
5688 | } | |
5689 | ||
5690 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5691 | abfd, info_ptr, cu); | |
5692 | ||
5693 | /* This two-pass algorithm for processing partial symbols has a | |
5694 | high cost in cache pressure. Thus, handle some simple cases | |
5695 | here which cover the majority of C partial symbols. DIEs | |
5696 | which neither have specification tags in them, nor could have | |
5697 | specification tags elsewhere pointing at them, can simply be | |
5698 | processed and discarded. | |
5699 | ||
5700 | This segment is also optional; scan_partial_symbols and | |
5701 | add_partial_symbol will handle these DIEs if we chain | |
5702 | them in normally. When compilers which do not emit large | |
5703 | quantities of duplicate debug information are more common, | |
5704 | this code can probably be removed. */ | |
5705 | ||
5706 | /* Any complete simple types at the top level (pretty much all | |
5707 | of them, for a language without namespaces), can be processed | |
5708 | directly. */ | |
5709 | if (parent_die == NULL | |
5710 | && part_die->has_specification == 0 | |
5711 | && part_die->is_declaration == 0 | |
5712 | && (part_die->tag == DW_TAG_typedef | |
5713 | || part_die->tag == DW_TAG_base_type | |
5714 | || part_die->tag == DW_TAG_subrange_type)) | |
5715 | { | |
5716 | if (building_psymtab && part_die->name != NULL) | |
5717 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5718 | VAR_DOMAIN, LOC_TYPEDEF, | |
5719 | &cu->objfile->static_psymbols, | |
5720 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5721 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5722 | continue; | |
5723 | } | |
5724 | ||
5725 | /* If we're at the second level, and we're an enumerator, and | |
5726 | our parent has no specification (meaning possibly lives in a | |
5727 | namespace elsewhere), then we can add the partial symbol now | |
5728 | instead of queueing it. */ | |
5729 | if (part_die->tag == DW_TAG_enumerator | |
5730 | && parent_die != NULL | |
5731 | && parent_die->die_parent == NULL | |
5732 | && parent_die->tag == DW_TAG_enumeration_type | |
5733 | && parent_die->has_specification == 0) | |
5734 | { | |
5735 | if (part_die->name == NULL) | |
e2e0b3e5 | 5736 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5737 | else if (building_psymtab) |
5738 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5739 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5740 | (cu->language == language_cplus |
5741 | || cu->language == language_java) | |
72bf9492 DJ |
5742 | ? &cu->objfile->global_psymbols |
5743 | : &cu->objfile->static_psymbols, | |
5744 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5745 | ||
5746 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5747 | continue; | |
5748 | } | |
5749 | ||
5750 | /* We'll save this DIE so link it in. */ | |
5751 | part_die->die_parent = parent_die; | |
5752 | part_die->die_sibling = NULL; | |
5753 | part_die->die_child = NULL; | |
5754 | ||
5755 | if (last_die && last_die == parent_die) | |
5756 | last_die->die_child = part_die; | |
5757 | else if (last_die) | |
5758 | last_die->die_sibling = part_die; | |
5759 | ||
5760 | last_die = part_die; | |
5761 | ||
5762 | if (first_die == NULL) | |
5763 | first_die = part_die; | |
5764 | ||
5765 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5766 | find interesting need to be in the hash table, because we | |
5767 | also have the parent/sibling/child chains; only those that we | |
5768 | might refer to by offset later during partial symbol reading. | |
5769 | ||
5770 | For now this means things that might have be the target of a | |
5771 | DW_AT_specification, DW_AT_abstract_origin, or | |
5772 | DW_AT_extension. DW_AT_extension will refer only to | |
5773 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5774 | many things under the function DIE, but we do not recurse | |
5775 | into function DIEs during partial symbol reading) and | |
5776 | possibly variables as well; DW_AT_specification refers to | |
5777 | declarations. Declarations ought to have the DW_AT_declaration | |
5778 | flag. It happens that GCC forgets to put it in sometimes, but | |
5779 | only for functions, not for types. | |
5780 | ||
5781 | Adding more things than necessary to the hash table is harmless | |
5782 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5783 | wasted time in find_partial_die, when we reread the compilation |
5784 | unit with load_all_dies set. */ | |
72bf9492 | 5785 | |
5afb4e99 DJ |
5786 | if (load_all |
5787 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5788 | || abbrev->tag == DW_TAG_variable |
5789 | || abbrev->tag == DW_TAG_namespace | |
5790 | || part_die->is_declaration) | |
5791 | { | |
5792 | void **slot; | |
5793 | ||
5794 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5795 | part_die->offset, INSERT); | |
5796 | *slot = part_die; | |
5797 | } | |
5798 | ||
5799 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5800 | sizeof (struct partial_die_info)); | |
5801 | ||
5802 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 5803 | we have no reason to follow the children of structures; for other |
72bf9492 | 5804 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
5805 | to infer fully qualified class names, and for DW_AT_specification. |
5806 | ||
5807 | For Ada, we need to scan the children of subprograms and lexical | |
5808 | blocks as well because Ada allows the definition of nested | |
5809 | entities that could be interesting for the debugger, such as | |
5810 | nested subprograms for instance. */ | |
72bf9492 | 5811 | if (last_die->has_children |
5afb4e99 DJ |
5812 | && (load_all |
5813 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5814 | || last_die->tag == DW_TAG_enumeration_type |
5815 | || (cu->language != language_c | |
5816 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 5817 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 5818 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
5819 | || last_die->tag == DW_TAG_union_type)) |
5820 | || (cu->language == language_ada | |
5821 | && (last_die->tag == DW_TAG_subprogram | |
5822 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
5823 | { |
5824 | nesting_level++; | |
5825 | parent_die = last_die; | |
5826 | continue; | |
5827 | } | |
5828 | ||
5829 | /* Otherwise we skip to the next sibling, if any. */ | |
5830 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5831 | ||
5832 | /* Back to the top, do it again. */ | |
5833 | } | |
5834 | } | |
5835 | ||
c906108c SS |
5836 | /* Read a minimal amount of information into the minimal die structure. */ |
5837 | ||
fe1b8b76 | 5838 | static gdb_byte * |
72bf9492 DJ |
5839 | read_partial_die (struct partial_die_info *part_die, |
5840 | struct abbrev_info *abbrev, | |
5841 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 5842 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 5843 | { |
72bf9492 | 5844 | unsigned int bytes_read, i; |
c906108c | 5845 | struct attribute attr; |
c5aa993b | 5846 | int has_low_pc_attr = 0; |
c906108c | 5847 | int has_high_pc_attr = 0; |
e7030f15 | 5848 | CORE_ADDR base_address = 0; |
85cbf3d3 JK |
5849 | enum |
5850 | { | |
5851 | base_address_none, | |
5852 | base_address_low_pc, | |
5853 | /* Overrides BASE_ADDRESS_LOW_PC. */ | |
5854 | base_address_entry_pc | |
5855 | } | |
5856 | base_address_type = base_address_none; | |
c906108c | 5857 | |
72bf9492 | 5858 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 5859 | |
6502dd73 | 5860 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
5861 | |
5862 | info_ptr += abbrev_len; | |
5863 | ||
5864 | if (abbrev == NULL) | |
5865 | return info_ptr; | |
5866 | ||
c906108c SS |
5867 | part_die->tag = abbrev->tag; |
5868 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
5869 | |
5870 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5871 | { | |
e7c27a73 | 5872 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
5873 | |
5874 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 5875 | partial symbol table. */ |
c906108c SS |
5876 | switch (attr.name) |
5877 | { | |
5878 | case DW_AT_name: | |
5879 | ||
5880 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
5881 | if (part_die->name == NULL) | |
5882 | part_die->name = DW_STRING (&attr); | |
5883 | break; | |
57c22c6c BR |
5884 | case DW_AT_comp_dir: |
5885 | if (part_die->dirname == NULL) | |
5886 | part_die->dirname = DW_STRING (&attr); | |
5887 | break; | |
c906108c SS |
5888 | case DW_AT_MIPS_linkage_name: |
5889 | part_die->name = DW_STRING (&attr); | |
5890 | break; | |
5891 | case DW_AT_low_pc: | |
5892 | has_low_pc_attr = 1; | |
5893 | part_die->lowpc = DW_ADDR (&attr); | |
85cbf3d3 JK |
5894 | if (part_die->tag == DW_TAG_compile_unit |
5895 | && base_address_type < base_address_low_pc) | |
5896 | { | |
5897 | base_address = DW_ADDR (&attr); | |
5898 | base_address_type = base_address_low_pc; | |
5899 | } | |
c906108c SS |
5900 | break; |
5901 | case DW_AT_high_pc: | |
5902 | has_high_pc_attr = 1; | |
5903 | part_die->highpc = DW_ADDR (&attr); | |
5904 | break; | |
85cbf3d3 JK |
5905 | case DW_AT_entry_pc: |
5906 | if (part_die->tag == DW_TAG_compile_unit | |
5907 | && base_address_type < base_address_entry_pc) | |
5908 | { | |
5909 | base_address = DW_ADDR (&attr); | |
5910 | base_address_type = base_address_entry_pc; | |
5911 | } | |
5912 | break; | |
43039443 | 5913 | case DW_AT_ranges: |
ff013f42 JK |
5914 | if (part_die->tag == DW_TAG_compile_unit) |
5915 | { | |
5916 | cu->ranges_offset = DW_UNSND (&attr); | |
5917 | cu->has_ranges_offset = 1; | |
5918 | } | |
43039443 | 5919 | break; |
c906108c | 5920 | case DW_AT_location: |
8e19ed76 PS |
5921 | /* Support the .debug_loc offsets */ |
5922 | if (attr_form_is_block (&attr)) | |
5923 | { | |
5924 | part_die->locdesc = DW_BLOCK (&attr); | |
5925 | } | |
3690dd37 | 5926 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 5927 | { |
4d3c2250 | 5928 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5929 | } |
5930 | else | |
5931 | { | |
4d3c2250 KB |
5932 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5933 | "partial symbol information"); | |
8e19ed76 | 5934 | } |
c906108c SS |
5935 | break; |
5936 | case DW_AT_language: | |
5937 | part_die->language = DW_UNSND (&attr); | |
5938 | break; | |
5939 | case DW_AT_external: | |
5940 | part_die->is_external = DW_UNSND (&attr); | |
5941 | break; | |
5942 | case DW_AT_declaration: | |
5943 | part_die->is_declaration = DW_UNSND (&attr); | |
5944 | break; | |
5945 | case DW_AT_type: | |
5946 | part_die->has_type = 1; | |
5947 | break; | |
5948 | case DW_AT_abstract_origin: | |
5949 | case DW_AT_specification: | |
72bf9492 DJ |
5950 | case DW_AT_extension: |
5951 | part_die->has_specification = 1; | |
c764a876 | 5952 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
5953 | break; |
5954 | case DW_AT_sibling: | |
5955 | /* Ignore absolute siblings, they might point outside of | |
5956 | the current compile unit. */ | |
5957 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 5958 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 5959 | else |
6502dd73 | 5960 | part_die->sibling = dwarf2_per_objfile->info_buffer |
c764a876 | 5961 | + dwarf2_get_ref_die_offset (&attr); |
c906108c | 5962 | break; |
aaa75496 JB |
5963 | case DW_AT_stmt_list: |
5964 | part_die->has_stmt_list = 1; | |
5965 | part_die->line_offset = DW_UNSND (&attr); | |
5966 | break; | |
fa4028e9 JB |
5967 | case DW_AT_byte_size: |
5968 | part_die->has_byte_size = 1; | |
5969 | break; | |
68511cec CES |
5970 | case DW_AT_calling_convention: |
5971 | /* DWARF doesn't provide a way to identify a program's source-level | |
5972 | entry point. DW_AT_calling_convention attributes are only meant | |
5973 | to describe functions' calling conventions. | |
5974 | ||
5975 | However, because it's a necessary piece of information in | |
5976 | Fortran, and because DW_CC_program is the only piece of debugging | |
5977 | information whose definition refers to a 'main program' at all, | |
5978 | several compilers have begun marking Fortran main programs with | |
5979 | DW_CC_program --- even when those functions use the standard | |
5980 | calling conventions. | |
5981 | ||
5982 | So until DWARF specifies a way to provide this information and | |
5983 | compilers pick up the new representation, we'll support this | |
5984 | practice. */ | |
5985 | if (DW_UNSND (&attr) == DW_CC_program | |
5986 | && cu->language == language_fortran) | |
5987 | set_main_name (part_die->name); | |
5988 | break; | |
c906108c SS |
5989 | default: |
5990 | break; | |
5991 | } | |
5992 | } | |
5993 | ||
c906108c SS |
5994 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
5995 | eliminate duplicate copies of functions and vtables and such. | |
5996 | The linker will arbitrarily choose one and discard the others. | |
5997 | The AT_*_pc values for such functions refer to local labels in | |
5998 | these sections. If the section from that file was discarded, the | |
5999 | labels are not in the output, so the relocs get a value of 0. | |
6000 | If this is a discarded function, mark the pc bounds as invalid, | |
6001 | so that GDB will ignore it. */ | |
6002 | if (has_low_pc_attr && has_high_pc_attr | |
6003 | && part_die->lowpc < part_die->highpc | |
6004 | && (part_die->lowpc != 0 | |
72dca2f5 | 6005 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6006 | part_die->has_pc_info = 1; |
85cbf3d3 | 6007 | |
d00adf39 | 6008 | if (base_address_type != base_address_none && !cu->base_known) |
85cbf3d3 JK |
6009 | { |
6010 | gdb_assert (part_die->tag == DW_TAG_compile_unit); | |
d00adf39 DE |
6011 | cu->base_known = 1; |
6012 | cu->base_address = base_address; | |
85cbf3d3 JK |
6013 | } |
6014 | ||
c906108c SS |
6015 | return info_ptr; |
6016 | } | |
6017 | ||
72bf9492 DJ |
6018 | /* Find a cached partial DIE at OFFSET in CU. */ |
6019 | ||
6020 | static struct partial_die_info * | |
c764a876 | 6021 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6022 | { |
6023 | struct partial_die_info *lookup_die = NULL; | |
6024 | struct partial_die_info part_die; | |
6025 | ||
6026 | part_die.offset = offset; | |
6027 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6028 | ||
72bf9492 DJ |
6029 | return lookup_die; |
6030 | } | |
6031 | ||
6032 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
6033 | ||
6034 | static struct partial_die_info * | |
c764a876 | 6035 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6036 | { |
5afb4e99 DJ |
6037 | struct dwarf2_per_cu_data *per_cu = NULL; |
6038 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6039 | |
45452591 | 6040 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6041 | { |
6042 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6043 | if (pd != NULL) | |
6044 | return pd; | |
6045 | } | |
72bf9492 | 6046 | |
ae038cb0 DJ |
6047 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6048 | ||
ae038cb0 DJ |
6049 | if (per_cu->cu == NULL) |
6050 | { | |
6051 | load_comp_unit (per_cu, cu->objfile); | |
6052 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
6053 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6054 | } | |
6055 | ||
6056 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6057 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6058 | ||
6059 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6060 | { | |
6061 | struct cleanup *back_to; | |
6062 | struct partial_die_info comp_unit_die; | |
6063 | struct abbrev_info *abbrev; | |
6064 | unsigned int bytes_read; | |
6065 | char *info_ptr; | |
6066 | ||
6067 | per_cu->load_all_dies = 1; | |
6068 | ||
6069 | /* Re-read the DIEs. */ | |
6070 | back_to = make_cleanup (null_cleanup, 0); | |
6071 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6072 | { | |
6073 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
6074 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
6075 | } | |
d00adf39 DE |
6076 | info_ptr = (dwarf2_per_objfile->info_buffer |
6077 | + per_cu->cu->header.offset | |
6078 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
6079 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
6080 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
6081 | per_cu->cu->objfile->obfd, info_ptr, | |
6082 | per_cu->cu); | |
6083 | if (comp_unit_die.has_children) | |
6084 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
6085 | do_cleanups (back_to); | |
6086 | ||
6087 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
6088 | } | |
6089 | ||
6090 | if (pd == NULL) | |
6091 | internal_error (__FILE__, __LINE__, | |
c764a876 | 6092 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
6093 | offset, bfd_get_filename (cu->objfile->obfd)); |
6094 | return pd; | |
72bf9492 DJ |
6095 | } |
6096 | ||
6097 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6098 | may set the is_external flag or change the DIE's name. */ | |
6099 | ||
6100 | static void | |
6101 | fixup_partial_die (struct partial_die_info *part_die, | |
6102 | struct dwarf2_cu *cu) | |
6103 | { | |
6104 | /* If we found a reference attribute and the DIE has no name, try | |
6105 | to find a name in the referred to DIE. */ | |
6106 | ||
6107 | if (part_die->name == NULL && part_die->has_specification) | |
6108 | { | |
6109 | struct partial_die_info *spec_die; | |
72bf9492 | 6110 | |
10b3939b | 6111 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6112 | |
10b3939b | 6113 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6114 | |
6115 | if (spec_die->name) | |
6116 | { | |
6117 | part_die->name = spec_die->name; | |
6118 | ||
6119 | /* Copy DW_AT_external attribute if it is set. */ | |
6120 | if (spec_die->is_external) | |
6121 | part_die->is_external = spec_die->is_external; | |
6122 | } | |
6123 | } | |
6124 | ||
6125 | /* Set default names for some unnamed DIEs. */ | |
6126 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6127 | || part_die->tag == DW_TAG_class_type)) | |
6128 | part_die->name = "(anonymous class)"; | |
6129 | ||
6130 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6131 | part_die->name = "(anonymous namespace)"; | |
6132 | ||
6133 | if (part_die->tag == DW_TAG_structure_type | |
6134 | || part_die->tag == DW_TAG_class_type | |
6135 | || part_die->tag == DW_TAG_union_type) | |
6136 | guess_structure_name (part_die, cu); | |
6137 | } | |
6138 | ||
639d11d3 DC |
6139 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6140 | point to a newly allocated die with its information, except for its | |
6141 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6142 | whether the die has children or not. */ | |
c906108c | 6143 | |
fe1b8b76 JB |
6144 | static gdb_byte * |
6145 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 6146 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
6147 | { |
6148 | unsigned int abbrev_number, bytes_read, i, offset; | |
6149 | struct abbrev_info *abbrev; | |
6150 | struct die_info *die; | |
6151 | ||
6502dd73 | 6152 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
6153 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6154 | info_ptr += bytes_read; | |
6155 | if (!abbrev_number) | |
6156 | { | |
1d325ec1 | 6157 | *diep = NULL; |
639d11d3 | 6158 | *has_children = 0; |
c906108c SS |
6159 | return info_ptr; |
6160 | } | |
6161 | ||
e7c27a73 | 6162 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
6163 | if (!abbrev) |
6164 | { | |
8a3fe4f8 | 6165 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 6166 | abbrev_number, |
639d11d3 | 6167 | bfd_get_filename (abfd)); |
c906108c | 6168 | } |
b60c80d6 | 6169 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
c906108c SS |
6170 | die->offset = offset; |
6171 | die->tag = abbrev->tag; | |
c906108c | 6172 | die->abbrev = abbrev_number; |
c906108c SS |
6173 | |
6174 | die->num_attrs = abbrev->num_attrs; | |
c906108c SS |
6175 | |
6176 | for (i = 0; i < abbrev->num_attrs; ++i) | |
03dd20cc DJ |
6177 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
6178 | abfd, info_ptr, cu); | |
c906108c SS |
6179 | |
6180 | *diep = die; | |
639d11d3 | 6181 | *has_children = abbrev->has_children; |
c906108c SS |
6182 | return info_ptr; |
6183 | } | |
6184 | ||
a8329558 | 6185 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6186 | |
fe1b8b76 | 6187 | static gdb_byte * |
a8329558 | 6188 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 6189 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 6190 | struct dwarf2_cu *cu) |
c906108c | 6191 | { |
e7c27a73 | 6192 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6193 | unsigned int bytes_read; |
6194 | struct dwarf_block *blk; | |
6195 | ||
a8329558 KW |
6196 | attr->form = form; |
6197 | switch (form) | |
c906108c SS |
6198 | { |
6199 | case DW_FORM_addr: | |
6200 | case DW_FORM_ref_addr: | |
e7c27a73 | 6201 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 6202 | info_ptr += bytes_read; |
c906108c SS |
6203 | break; |
6204 | case DW_FORM_block2: | |
7b5a2f43 | 6205 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6206 | blk->size = read_2_bytes (abfd, info_ptr); |
6207 | info_ptr += 2; | |
6208 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6209 | info_ptr += blk->size; | |
6210 | DW_BLOCK (attr) = blk; | |
6211 | break; | |
6212 | case DW_FORM_block4: | |
7b5a2f43 | 6213 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6214 | blk->size = read_4_bytes (abfd, info_ptr); |
6215 | info_ptr += 4; | |
6216 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6217 | info_ptr += blk->size; | |
6218 | DW_BLOCK (attr) = blk; | |
6219 | break; | |
6220 | case DW_FORM_data2: | |
6221 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
6222 | info_ptr += 2; | |
6223 | break; | |
6224 | case DW_FORM_data4: | |
6225 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
6226 | info_ptr += 4; | |
6227 | break; | |
6228 | case DW_FORM_data8: | |
6229 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
6230 | info_ptr += 8; | |
6231 | break; | |
6232 | case DW_FORM_string: | |
6233 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
6234 | info_ptr += bytes_read; | |
6235 | break; | |
4bdf3d34 JJ |
6236 | case DW_FORM_strp: |
6237 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
6238 | &bytes_read); | |
6239 | info_ptr += bytes_read; | |
6240 | break; | |
c906108c | 6241 | case DW_FORM_block: |
7b5a2f43 | 6242 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6243 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6244 | info_ptr += bytes_read; | |
6245 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6246 | info_ptr += blk->size; | |
6247 | DW_BLOCK (attr) = blk; | |
6248 | break; | |
6249 | case DW_FORM_block1: | |
7b5a2f43 | 6250 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6251 | blk->size = read_1_byte (abfd, info_ptr); |
6252 | info_ptr += 1; | |
6253 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6254 | info_ptr += blk->size; | |
6255 | DW_BLOCK (attr) = blk; | |
6256 | break; | |
6257 | case DW_FORM_data1: | |
6258 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6259 | info_ptr += 1; | |
6260 | break; | |
6261 | case DW_FORM_flag: | |
6262 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6263 | info_ptr += 1; | |
6264 | break; | |
6265 | case DW_FORM_sdata: | |
6266 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
6267 | info_ptr += bytes_read; | |
6268 | break; | |
6269 | case DW_FORM_udata: | |
6270 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6271 | info_ptr += bytes_read; | |
6272 | break; | |
6273 | case DW_FORM_ref1: | |
10b3939b | 6274 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
6275 | info_ptr += 1; |
6276 | break; | |
6277 | case DW_FORM_ref2: | |
10b3939b | 6278 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
6279 | info_ptr += 2; |
6280 | break; | |
6281 | case DW_FORM_ref4: | |
10b3939b | 6282 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
6283 | info_ptr += 4; |
6284 | break; | |
613e1657 | 6285 | case DW_FORM_ref8: |
10b3939b | 6286 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
6287 | info_ptr += 8; |
6288 | break; | |
c906108c | 6289 | case DW_FORM_ref_udata: |
10b3939b DJ |
6290 | DW_ADDR (attr) = (cu->header.offset |
6291 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
6292 | info_ptr += bytes_read; |
6293 | break; | |
c906108c | 6294 | case DW_FORM_indirect: |
a8329558 KW |
6295 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6296 | info_ptr += bytes_read; | |
e7c27a73 | 6297 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 6298 | break; |
c906108c | 6299 | default: |
8a3fe4f8 | 6300 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
6301 | dwarf_form_name (form), |
6302 | bfd_get_filename (abfd)); | |
c906108c | 6303 | } |
28e94949 JB |
6304 | |
6305 | /* We have seen instances where the compiler tried to emit a byte | |
6306 | size attribute of -1 which ended up being encoded as an unsigned | |
6307 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
6308 | an object of this size seems pretty unlikely so we can relatively | |
6309 | safely treat these cases as if the size attribute was invalid and | |
6310 | treat them as zero by default. */ | |
6311 | if (attr->name == DW_AT_byte_size | |
6312 | && form == DW_FORM_data4 | |
6313 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
6314 | { |
6315 | complaint | |
6316 | (&symfile_complaints, | |
6317 | _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"), | |
6318 | DW_UNSND (attr)); | |
6319 | DW_UNSND (attr) = 0; | |
6320 | } | |
28e94949 | 6321 | |
c906108c SS |
6322 | return info_ptr; |
6323 | } | |
6324 | ||
a8329558 KW |
6325 | /* Read an attribute described by an abbreviated attribute. */ |
6326 | ||
fe1b8b76 | 6327 | static gdb_byte * |
a8329558 | 6328 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 6329 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
6330 | { |
6331 | attr->name = abbrev->name; | |
e7c27a73 | 6332 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
6333 | } |
6334 | ||
c906108c SS |
6335 | /* read dwarf information from a buffer */ |
6336 | ||
6337 | static unsigned int | |
fe1b8b76 | 6338 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6339 | { |
fe1b8b76 | 6340 | return bfd_get_8 (abfd, buf); |
c906108c SS |
6341 | } |
6342 | ||
6343 | static int | |
fe1b8b76 | 6344 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6345 | { |
fe1b8b76 | 6346 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
6347 | } |
6348 | ||
6349 | static unsigned int | |
fe1b8b76 | 6350 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6351 | { |
fe1b8b76 | 6352 | return bfd_get_16 (abfd, buf); |
c906108c SS |
6353 | } |
6354 | ||
6355 | static int | |
fe1b8b76 | 6356 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6357 | { |
fe1b8b76 | 6358 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
6359 | } |
6360 | ||
6361 | static unsigned int | |
fe1b8b76 | 6362 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6363 | { |
fe1b8b76 | 6364 | return bfd_get_32 (abfd, buf); |
c906108c SS |
6365 | } |
6366 | ||
6367 | static int | |
fe1b8b76 | 6368 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6369 | { |
fe1b8b76 | 6370 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
6371 | } |
6372 | ||
ce5d95e1 | 6373 | static unsigned long |
fe1b8b76 | 6374 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6375 | { |
fe1b8b76 | 6376 | return bfd_get_64 (abfd, buf); |
c906108c SS |
6377 | } |
6378 | ||
6379 | static CORE_ADDR | |
fe1b8b76 | 6380 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 6381 | unsigned int *bytes_read) |
c906108c | 6382 | { |
e7c27a73 | 6383 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6384 | CORE_ADDR retval = 0; |
6385 | ||
107d2387 | 6386 | if (cu_header->signed_addr_p) |
c906108c | 6387 | { |
107d2387 AC |
6388 | switch (cu_header->addr_size) |
6389 | { | |
6390 | case 2: | |
fe1b8b76 | 6391 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6392 | break; |
6393 | case 4: | |
fe1b8b76 | 6394 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6395 | break; |
6396 | case 8: | |
fe1b8b76 | 6397 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6398 | break; |
6399 | default: | |
8e65ff28 | 6400 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6401 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6402 | bfd_get_filename (abfd)); |
107d2387 AC |
6403 | } |
6404 | } | |
6405 | else | |
6406 | { | |
6407 | switch (cu_header->addr_size) | |
6408 | { | |
6409 | case 2: | |
fe1b8b76 | 6410 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6411 | break; |
6412 | case 4: | |
fe1b8b76 | 6413 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6414 | break; |
6415 | case 8: | |
fe1b8b76 | 6416 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6417 | break; |
6418 | default: | |
8e65ff28 | 6419 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6420 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6421 | bfd_get_filename (abfd)); |
107d2387 | 6422 | } |
c906108c | 6423 | } |
64367e0a | 6424 | |
107d2387 AC |
6425 | *bytes_read = cu_header->addr_size; |
6426 | return retval; | |
c906108c SS |
6427 | } |
6428 | ||
f7ef9339 | 6429 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6430 | specification allows the initial length to take up either 4 bytes |
6431 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6432 | bytes describe the length and all offsets will be 8 bytes in length | |
6433 | instead of 4. | |
6434 | ||
f7ef9339 KB |
6435 | An older, non-standard 64-bit format is also handled by this |
6436 | function. The older format in question stores the initial length | |
6437 | as an 8-byte quantity without an escape value. Lengths greater | |
6438 | than 2^32 aren't very common which means that the initial 4 bytes | |
6439 | is almost always zero. Since a length value of zero doesn't make | |
6440 | sense for the 32-bit format, this initial zero can be considered to | |
6441 | be an escape value which indicates the presence of the older 64-bit | |
6442 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6443 | greater than 4GB. If it becomes necessary to handle lengths |
6444 | somewhat larger than 4GB, we could allow other small values (such | |
6445 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6446 | escape values indicating the presence of the old format. | |
f7ef9339 | 6447 | |
917c78fc MK |
6448 | The value returned via bytes_read should be used to increment the |
6449 | relevant pointer after calling read_initial_length(). | |
c764a876 | 6450 | |
613e1657 KB |
6451 | [ Note: read_initial_length() and read_offset() are based on the |
6452 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6453 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6454 | from: |
6455 | ||
f7ef9339 | 6456 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6457 | |
6458 | This document is only a draft and is subject to change. (So beware.) | |
6459 | ||
f7ef9339 | 6460 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6461 | determined empirically by examining 64-bit ELF files produced by |
6462 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6463 | |
6464 | - Kevin, July 16, 2002 | |
613e1657 KB |
6465 | ] */ |
6466 | ||
6467 | static LONGEST | |
c764a876 | 6468 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 6469 | { |
fe1b8b76 | 6470 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6471 | |
dd373385 | 6472 | if (length == 0xffffffff) |
613e1657 | 6473 | { |
fe1b8b76 | 6474 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6475 | *bytes_read = 12; |
613e1657 | 6476 | } |
dd373385 | 6477 | else if (length == 0) |
f7ef9339 | 6478 | { |
dd373385 | 6479 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6480 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6481 | *bytes_read = 8; |
f7ef9339 | 6482 | } |
613e1657 KB |
6483 | else |
6484 | { | |
6485 | *bytes_read = 4; | |
613e1657 KB |
6486 | } |
6487 | ||
c764a876 DE |
6488 | return length; |
6489 | } | |
dd373385 | 6490 | |
c764a876 DE |
6491 | /* Cover function for read_initial_length. |
6492 | Returns the length of the object at BUF, and stores the size of the | |
6493 | initial length in *BYTES_READ and stores the size that offsets will be in | |
6494 | *OFFSET_SIZE. | |
6495 | If the initial length size is not equivalent to that specified in | |
6496 | CU_HEADER then issue a complaint. | |
6497 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 6498 | |
c764a876 DE |
6499 | static LONGEST |
6500 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
6501 | const struct comp_unit_head *cu_header, | |
6502 | unsigned int *bytes_read, | |
6503 | unsigned int *offset_size) | |
6504 | { | |
6505 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
6506 | ||
6507 | gdb_assert (cu_header->initial_length_size == 4 | |
6508 | || cu_header->initial_length_size == 8 | |
6509 | || cu_header->initial_length_size == 12); | |
6510 | ||
6511 | if (cu_header->initial_length_size != *bytes_read) | |
6512 | complaint (&symfile_complaints, | |
6513 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 6514 | |
c764a876 | 6515 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 6516 | return length; |
613e1657 KB |
6517 | } |
6518 | ||
6519 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6520 | given by cu_header->offset_size. */ |
613e1657 KB |
6521 | |
6522 | static LONGEST | |
fe1b8b76 | 6523 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6524 | unsigned int *bytes_read) |
c764a876 DE |
6525 | { |
6526 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
6527 | *bytes_read = cu_header->offset_size; | |
6528 | return offset; | |
6529 | } | |
6530 | ||
6531 | /* Read an offset from the data stream. */ | |
6532 | ||
6533 | static LONGEST | |
6534 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
6535 | { |
6536 | LONGEST retval = 0; | |
6537 | ||
c764a876 | 6538 | switch (offset_size) |
613e1657 KB |
6539 | { |
6540 | case 4: | |
fe1b8b76 | 6541 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6542 | break; |
6543 | case 8: | |
fe1b8b76 | 6544 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6545 | break; |
6546 | default: | |
8e65ff28 | 6547 | internal_error (__FILE__, __LINE__, |
c764a876 | 6548 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 6549 | bfd_get_filename (abfd)); |
613e1657 KB |
6550 | } |
6551 | ||
917c78fc | 6552 | return retval; |
613e1657 KB |
6553 | } |
6554 | ||
fe1b8b76 JB |
6555 | static gdb_byte * |
6556 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6557 | { |
6558 | /* If the size of a host char is 8 bits, we can return a pointer | |
6559 | to the buffer, otherwise we have to copy the data to a buffer | |
6560 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6561 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6562 | return buf; |
c906108c SS |
6563 | } |
6564 | ||
6565 | static char * | |
fe1b8b76 | 6566 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6567 | { |
6568 | /* If the size of a host char is 8 bits, we can return a pointer | |
6569 | to the string, otherwise we have to copy the string to a buffer | |
6570 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6571 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6572 | if (*buf == '\0') |
6573 | { | |
6574 | *bytes_read_ptr = 1; | |
6575 | return NULL; | |
6576 | } | |
fe1b8b76 JB |
6577 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6578 | return (char *) buf; | |
4bdf3d34 JJ |
6579 | } |
6580 | ||
6581 | static char * | |
fe1b8b76 | 6582 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6583 | const struct comp_unit_head *cu_header, |
6584 | unsigned int *bytes_read_ptr) | |
6585 | { | |
c764a876 | 6586 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 6587 | |
6502dd73 | 6588 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 6589 | { |
8a3fe4f8 | 6590 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6591 | bfd_get_filename (abfd)); |
4bdf3d34 | 6592 | return NULL; |
c906108c | 6593 | } |
6502dd73 | 6594 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 6595 | { |
8a3fe4f8 | 6596 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6597 | bfd_get_filename (abfd)); |
c906108c SS |
6598 | return NULL; |
6599 | } | |
4bdf3d34 | 6600 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 6601 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 6602 | return NULL; |
fe1b8b76 | 6603 | return (char *) (dwarf2_per_objfile->str_buffer + str_offset); |
c906108c SS |
6604 | } |
6605 | ||
ce5d95e1 | 6606 | static unsigned long |
fe1b8b76 | 6607 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6608 | { |
ce5d95e1 JB |
6609 | unsigned long result; |
6610 | unsigned int num_read; | |
c906108c SS |
6611 | int i, shift; |
6612 | unsigned char byte; | |
6613 | ||
6614 | result = 0; | |
6615 | shift = 0; | |
6616 | num_read = 0; | |
6617 | i = 0; | |
6618 | while (1) | |
6619 | { | |
fe1b8b76 | 6620 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6621 | buf++; |
6622 | num_read++; | |
ce5d95e1 | 6623 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6624 | if ((byte & 128) == 0) |
6625 | { | |
6626 | break; | |
6627 | } | |
6628 | shift += 7; | |
6629 | } | |
6630 | *bytes_read_ptr = num_read; | |
6631 | return result; | |
6632 | } | |
6633 | ||
ce5d95e1 | 6634 | static long |
fe1b8b76 | 6635 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6636 | { |
ce5d95e1 | 6637 | long result; |
77e0b926 | 6638 | int i, shift, num_read; |
c906108c SS |
6639 | unsigned char byte; |
6640 | ||
6641 | result = 0; | |
6642 | shift = 0; | |
c906108c SS |
6643 | num_read = 0; |
6644 | i = 0; | |
6645 | while (1) | |
6646 | { | |
fe1b8b76 | 6647 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6648 | buf++; |
6649 | num_read++; | |
ce5d95e1 | 6650 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6651 | shift += 7; |
6652 | if ((byte & 128) == 0) | |
6653 | { | |
6654 | break; | |
6655 | } | |
6656 | } | |
77e0b926 DJ |
6657 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6658 | result |= -(((long)1) << shift); | |
c906108c SS |
6659 | *bytes_read_ptr = num_read; |
6660 | return result; | |
6661 | } | |
6662 | ||
4bb7a0a7 DJ |
6663 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6664 | ||
fe1b8b76 JB |
6665 | static gdb_byte * |
6666 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6667 | { |
6668 | int byte; | |
6669 | ||
6670 | while (1) | |
6671 | { | |
fe1b8b76 | 6672 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6673 | buf++; |
6674 | if ((byte & 128) == 0) | |
6675 | return buf; | |
6676 | } | |
6677 | } | |
6678 | ||
c906108c | 6679 | static void |
e142c38c | 6680 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6681 | { |
6682 | switch (lang) | |
6683 | { | |
6684 | case DW_LANG_C89: | |
6685 | case DW_LANG_C: | |
e142c38c | 6686 | cu->language = language_c; |
c906108c SS |
6687 | break; |
6688 | case DW_LANG_C_plus_plus: | |
e142c38c | 6689 | cu->language = language_cplus; |
c906108c SS |
6690 | break; |
6691 | case DW_LANG_Fortran77: | |
6692 | case DW_LANG_Fortran90: | |
b21b22e0 | 6693 | case DW_LANG_Fortran95: |
e142c38c | 6694 | cu->language = language_fortran; |
c906108c SS |
6695 | break; |
6696 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6697 | cu->language = language_asm; |
c906108c | 6698 | break; |
bebd888e | 6699 | case DW_LANG_Java: |
e142c38c | 6700 | cu->language = language_java; |
bebd888e | 6701 | break; |
c906108c | 6702 | case DW_LANG_Ada83: |
8aaf0b47 | 6703 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6704 | cu->language = language_ada; |
6705 | break; | |
72019c9c GM |
6706 | case DW_LANG_Modula2: |
6707 | cu->language = language_m2; | |
6708 | break; | |
fe8e67fd PM |
6709 | case DW_LANG_Pascal83: |
6710 | cu->language = language_pascal; | |
6711 | break; | |
22566fbd DJ |
6712 | case DW_LANG_ObjC: |
6713 | cu->language = language_objc; | |
6714 | break; | |
c906108c SS |
6715 | case DW_LANG_Cobol74: |
6716 | case DW_LANG_Cobol85: | |
c906108c | 6717 | default: |
e142c38c | 6718 | cu->language = language_minimal; |
c906108c SS |
6719 | break; |
6720 | } | |
e142c38c | 6721 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6722 | } |
6723 | ||
6724 | /* Return the named attribute or NULL if not there. */ | |
6725 | ||
6726 | static struct attribute * | |
e142c38c | 6727 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6728 | { |
6729 | unsigned int i; | |
6730 | struct attribute *spec = NULL; | |
6731 | ||
6732 | for (i = 0; i < die->num_attrs; ++i) | |
6733 | { | |
6734 | if (die->attrs[i].name == name) | |
10b3939b | 6735 | return &die->attrs[i]; |
c906108c SS |
6736 | if (die->attrs[i].name == DW_AT_specification |
6737 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6738 | spec = &die->attrs[i]; | |
6739 | } | |
c906108c | 6740 | |
10b3939b | 6741 | if (spec) |
f2f0e013 DJ |
6742 | { |
6743 | die = follow_die_ref (die, spec, &cu); | |
6744 | return dwarf2_attr (die, name, cu); | |
6745 | } | |
c5aa993b | 6746 | |
c906108c SS |
6747 | return NULL; |
6748 | } | |
6749 | ||
05cf31d1 JB |
6750 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6751 | and holds a non-zero value. This function should only be used for | |
6752 | DW_FORM_flag attributes. */ | |
6753 | ||
6754 | static int | |
6755 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6756 | { | |
6757 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6758 | ||
6759 | return (attr && DW_UNSND (attr)); | |
6760 | } | |
6761 | ||
3ca72b44 | 6762 | static int |
e142c38c | 6763 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6764 | { |
05cf31d1 JB |
6765 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6766 | which value is non-zero. However, we have to be careful with | |
6767 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6768 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6769 | end up accidently finding a declaration attribute that belongs | |
6770 | to a different DIE referenced by the specification attribute, | |
6771 | even though the given DIE does not have a declaration attribute. */ | |
6772 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6773 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6774 | } |
6775 | ||
63d06c5c | 6776 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 DJ |
6777 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
6778 | containing the return value on output. */ | |
63d06c5c DC |
6779 | |
6780 | static struct die_info * | |
f2f0e013 | 6781 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 6782 | { |
f2f0e013 DJ |
6783 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
6784 | *spec_cu); | |
63d06c5c DC |
6785 | |
6786 | if (spec_attr == NULL) | |
6787 | return NULL; | |
6788 | else | |
f2f0e013 | 6789 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 6790 | } |
c906108c | 6791 | |
debd256d JB |
6792 | /* Free the line_header structure *LH, and any arrays and strings it |
6793 | refers to. */ | |
6794 | static void | |
6795 | free_line_header (struct line_header *lh) | |
6796 | { | |
6797 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6798 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6799 | |
6800 | /* Remember that all the lh->file_names[i].name pointers are | |
6801 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6802 | if (lh->file_names) | |
a8bc7b56 | 6803 | xfree (lh->file_names); |
debd256d JB |
6804 | |
6805 | /* Similarly for the include directory names. */ | |
6806 | if (lh->include_dirs) | |
a8bc7b56 | 6807 | xfree (lh->include_dirs); |
debd256d | 6808 | |
a8bc7b56 | 6809 | xfree (lh); |
debd256d JB |
6810 | } |
6811 | ||
6812 | ||
6813 | /* Add an entry to LH's include directory table. */ | |
6814 | static void | |
6815 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6816 | { |
debd256d JB |
6817 | /* Grow the array if necessary. */ |
6818 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6819 | { |
debd256d JB |
6820 | lh->include_dirs_size = 1; /* for testing */ |
6821 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6822 | * sizeof (*lh->include_dirs)); | |
6823 | } | |
6824 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
6825 | { | |
6826 | lh->include_dirs_size *= 2; | |
6827 | lh->include_dirs = xrealloc (lh->include_dirs, | |
6828 | (lh->include_dirs_size | |
6829 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 6830 | } |
c906108c | 6831 | |
debd256d JB |
6832 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
6833 | } | |
6834 | ||
6835 | ||
6836 | /* Add an entry to LH's file name table. */ | |
6837 | static void | |
6838 | add_file_name (struct line_header *lh, | |
6839 | char *name, | |
6840 | unsigned int dir_index, | |
6841 | unsigned int mod_time, | |
6842 | unsigned int length) | |
6843 | { | |
6844 | struct file_entry *fe; | |
6845 | ||
6846 | /* Grow the array if necessary. */ | |
6847 | if (lh->file_names_size == 0) | |
6848 | { | |
6849 | lh->file_names_size = 1; /* for testing */ | |
6850 | lh->file_names = xmalloc (lh->file_names_size | |
6851 | * sizeof (*lh->file_names)); | |
6852 | } | |
6853 | else if (lh->num_file_names >= lh->file_names_size) | |
6854 | { | |
6855 | lh->file_names_size *= 2; | |
6856 | lh->file_names = xrealloc (lh->file_names, | |
6857 | (lh->file_names_size | |
6858 | * sizeof (*lh->file_names))); | |
6859 | } | |
6860 | ||
6861 | fe = &lh->file_names[lh->num_file_names++]; | |
6862 | fe->name = name; | |
6863 | fe->dir_index = dir_index; | |
6864 | fe->mod_time = mod_time; | |
6865 | fe->length = length; | |
aaa75496 | 6866 | fe->included_p = 0; |
cb1df416 | 6867 | fe->symtab = NULL; |
debd256d JB |
6868 | } |
6869 | ||
6870 | ||
6871 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
6872 | .debug_line, according to the endianness of ABFD. Return a pointer |
6873 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
6874 | |
6875 | NOTE: the strings in the include directory and file name tables of | |
6876 | the returned object point into debug_line_buffer, and must not be | |
6877 | freed. */ | |
6878 | static struct line_header * | |
6879 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 6880 | struct dwarf2_cu *cu) |
debd256d JB |
6881 | { |
6882 | struct cleanup *back_to; | |
6883 | struct line_header *lh; | |
fe1b8b76 | 6884 | gdb_byte *line_ptr; |
c764a876 | 6885 | unsigned int bytes_read, offset_size; |
debd256d JB |
6886 | int i; |
6887 | char *cur_dir, *cur_file; | |
6888 | ||
6502dd73 | 6889 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 6890 | { |
e2e0b3e5 | 6891 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
6892 | return 0; |
6893 | } | |
6894 | ||
a738430d MK |
6895 | /* Make sure that at least there's room for the total_length field. |
6896 | That could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 6897 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 6898 | { |
4d3c2250 | 6899 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6900 | return 0; |
6901 | } | |
6902 | ||
6903 | lh = xmalloc (sizeof (*lh)); | |
6904 | memset (lh, 0, sizeof (*lh)); | |
6905 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
6906 | (void *) lh); | |
6907 | ||
6502dd73 | 6908 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d | 6909 | |
a738430d | 6910 | /* Read in the header. */ |
dd373385 | 6911 | lh->total_length = |
c764a876 DE |
6912 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
6913 | &bytes_read, &offset_size); | |
debd256d | 6914 | line_ptr += bytes_read; |
6502dd73 DJ |
6915 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
6916 | + dwarf2_per_objfile->line_size)) | |
debd256d | 6917 | { |
4d3c2250 | 6918 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6919 | return 0; |
6920 | } | |
6921 | lh->statement_program_end = line_ptr + lh->total_length; | |
6922 | lh->version = read_2_bytes (abfd, line_ptr); | |
6923 | line_ptr += 2; | |
c764a876 DE |
6924 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
6925 | line_ptr += offset_size; | |
debd256d JB |
6926 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
6927 | line_ptr += 1; | |
6928 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
6929 | line_ptr += 1; | |
6930 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
6931 | line_ptr += 1; | |
6932 | lh->line_range = read_1_byte (abfd, line_ptr); | |
6933 | line_ptr += 1; | |
6934 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
6935 | line_ptr += 1; | |
6936 | lh->standard_opcode_lengths | |
fe1b8b76 | 6937 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
6938 | |
6939 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
6940 | for (i = 1; i < lh->opcode_base; ++i) | |
6941 | { | |
6942 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
6943 | line_ptr += 1; | |
6944 | } | |
6945 | ||
a738430d | 6946 | /* Read directory table. */ |
debd256d JB |
6947 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6948 | { | |
6949 | line_ptr += bytes_read; | |
6950 | add_include_dir (lh, cur_dir); | |
6951 | } | |
6952 | line_ptr += bytes_read; | |
6953 | ||
a738430d | 6954 | /* Read file name table. */ |
debd256d JB |
6955 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6956 | { | |
6957 | unsigned int dir_index, mod_time, length; | |
6958 | ||
6959 | line_ptr += bytes_read; | |
6960 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6961 | line_ptr += bytes_read; | |
6962 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6963 | line_ptr += bytes_read; | |
6964 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6965 | line_ptr += bytes_read; | |
6966 | ||
6967 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6968 | } | |
6969 | line_ptr += bytes_read; | |
6970 | lh->statement_program_start = line_ptr; | |
6971 | ||
6502dd73 DJ |
6972 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
6973 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 | 6974 | complaint (&symfile_complaints, |
e2e0b3e5 | 6975 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
6976 | |
6977 | discard_cleanups (back_to); | |
6978 | return lh; | |
6979 | } | |
c906108c | 6980 | |
5fb290d7 DJ |
6981 | /* This function exists to work around a bug in certain compilers |
6982 | (particularly GCC 2.95), in which the first line number marker of a | |
6983 | function does not show up until after the prologue, right before | |
6984 | the second line number marker. This function shifts ADDRESS down | |
6985 | to the beginning of the function if necessary, and is called on | |
6986 | addresses passed to record_line. */ | |
6987 | ||
6988 | static CORE_ADDR | |
e142c38c | 6989 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
6990 | { |
6991 | struct function_range *fn; | |
6992 | ||
6993 | /* Find the function_range containing address. */ | |
e142c38c | 6994 | if (!cu->first_fn) |
5fb290d7 DJ |
6995 | return address; |
6996 | ||
e142c38c DJ |
6997 | if (!cu->cached_fn) |
6998 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 6999 | |
e142c38c | 7000 | fn = cu->cached_fn; |
5fb290d7 DJ |
7001 | while (fn) |
7002 | if (fn->lowpc <= address && fn->highpc > address) | |
7003 | goto found; | |
7004 | else | |
7005 | fn = fn->next; | |
7006 | ||
e142c38c DJ |
7007 | fn = cu->first_fn; |
7008 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7009 | if (fn->lowpc <= address && fn->highpc > address) |
7010 | goto found; | |
7011 | else | |
7012 | fn = fn->next; | |
7013 | ||
7014 | return address; | |
7015 | ||
7016 | found: | |
7017 | if (fn->seen_line) | |
7018 | return address; | |
7019 | if (address != fn->lowpc) | |
4d3c2250 | 7020 | complaint (&symfile_complaints, |
e2e0b3e5 | 7021 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7022 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7023 | fn->seen_line = 1; |
7024 | return fn->lowpc; | |
7025 | } | |
7026 | ||
aaa75496 JB |
7027 | /* Decode the Line Number Program (LNP) for the given line_header |
7028 | structure and CU. The actual information extracted and the type | |
7029 | of structures created from the LNP depends on the value of PST. | |
7030 | ||
7031 | 1. If PST is NULL, then this procedure uses the data from the program | |
7032 | to create all necessary symbol tables, and their linetables. | |
7033 | The compilation directory of the file is passed in COMP_DIR, | |
7034 | and must not be NULL. | |
7035 | ||
7036 | 2. If PST is not NULL, this procedure reads the program to determine | |
7037 | the list of files included by the unit represented by PST, and | |
7038 | builds all the associated partial symbol tables. In this case, | |
7039 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7040 | is not used to compute the full name of the symtab, and therefore | |
7041 | omitting it when building the partial symtab does not introduce | |
7042 | the potential for inconsistency - a partial symtab and its associated | |
7043 | symbtab having a different fullname -). */ | |
debd256d | 7044 | |
c906108c | 7045 | static void |
debd256d | 7046 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7047 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7048 | { |
a8c50c1f | 7049 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 7050 | gdb_byte *line_end; |
a8c50c1f | 7051 | unsigned int bytes_read, extended_len; |
c906108c | 7052 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
7053 | CORE_ADDR baseaddr; |
7054 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 7055 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 7056 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
7057 | |
7058 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7059 | |
debd256d JB |
7060 | line_ptr = lh->statement_program_start; |
7061 | line_end = lh->statement_program_end; | |
c906108c SS |
7062 | |
7063 | /* Read the statement sequences until there's nothing left. */ | |
7064 | while (line_ptr < line_end) | |
7065 | { | |
7066 | /* state machine registers */ | |
7067 | CORE_ADDR address = 0; | |
7068 | unsigned int file = 1; | |
7069 | unsigned int line = 1; | |
7070 | unsigned int column = 0; | |
debd256d | 7071 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
7072 | int basic_block = 0; |
7073 | int end_sequence = 0; | |
7074 | ||
aaa75496 | 7075 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 7076 | { |
aaa75496 | 7077 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
7078 | /* lh->include_dirs and lh->file_names are 0-based, but the |
7079 | directory and file name numbers in the statement program | |
7080 | are 1-based. */ | |
7081 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 7082 | char *dir = NULL; |
a738430d | 7083 | |
debd256d JB |
7084 | if (fe->dir_index) |
7085 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
7086 | |
7087 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
7088 | } |
7089 | ||
a738430d | 7090 | /* Decode the table. */ |
c5aa993b | 7091 | while (!end_sequence) |
c906108c SS |
7092 | { |
7093 | op_code = read_1_byte (abfd, line_ptr); | |
7094 | line_ptr += 1; | |
9aa1fe7e | 7095 | |
debd256d | 7096 | if (op_code >= lh->opcode_base) |
a738430d MK |
7097 | { |
7098 | /* Special operand. */ | |
debd256d JB |
7099 | adj_opcode = op_code - lh->opcode_base; |
7100 | address += (adj_opcode / lh->line_range) | |
7101 | * lh->minimum_instruction_length; | |
7102 | line += lh->line_base + (adj_opcode % lh->line_range); | |
25e43795 DJ |
7103 | if (lh->num_file_names < file) |
7104 | dwarf2_debug_line_missing_file_complaint (); | |
7105 | else | |
7106 | { | |
7107 | lh->file_names[file - 1].included_p = 1; | |
7108 | if (!decode_for_pst_p) | |
7109 | { | |
7110 | if (last_subfile != current_subfile) | |
7111 | { | |
7112 | if (last_subfile) | |
7113 | record_line (last_subfile, 0, address); | |
7114 | last_subfile = current_subfile; | |
7115 | } | |
7116 | /* Append row to matrix using current values. */ | |
7117 | record_line (current_subfile, line, | |
7118 | check_cu_functions (address, cu)); | |
366da635 | 7119 | } |
25e43795 | 7120 | } |
9aa1fe7e GK |
7121 | basic_block = 1; |
7122 | } | |
7123 | else switch (op_code) | |
c906108c SS |
7124 | { |
7125 | case DW_LNS_extended_op: | |
a8c50c1f | 7126 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7127 | line_ptr += bytes_read; |
a8c50c1f | 7128 | extended_end = line_ptr + extended_len; |
c906108c SS |
7129 | extended_op = read_1_byte (abfd, line_ptr); |
7130 | line_ptr += 1; | |
7131 | switch (extended_op) | |
7132 | { | |
7133 | case DW_LNE_end_sequence: | |
7134 | end_sequence = 1; | |
25e43795 DJ |
7135 | |
7136 | if (lh->num_file_names < file) | |
7137 | dwarf2_debug_line_missing_file_complaint (); | |
7138 | else | |
7139 | { | |
7140 | lh->file_names[file - 1].included_p = 1; | |
7141 | if (!decode_for_pst_p) | |
7142 | record_line (current_subfile, 0, address); | |
7143 | } | |
c906108c SS |
7144 | break; |
7145 | case DW_LNE_set_address: | |
e7c27a73 | 7146 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7147 | line_ptr += bytes_read; |
7148 | address += baseaddr; | |
c906108c SS |
7149 | break; |
7150 | case DW_LNE_define_file: | |
debd256d JB |
7151 | { |
7152 | char *cur_file; | |
7153 | unsigned int dir_index, mod_time, length; | |
7154 | ||
7155 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
7156 | line_ptr += bytes_read; | |
7157 | dir_index = | |
7158 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7159 | line_ptr += bytes_read; | |
7160 | mod_time = | |
7161 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7162 | line_ptr += bytes_read; | |
7163 | length = | |
7164 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7165 | line_ptr += bytes_read; | |
7166 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7167 | } | |
c906108c SS |
7168 | break; |
7169 | default: | |
4d3c2250 | 7170 | complaint (&symfile_complaints, |
e2e0b3e5 | 7171 | _("mangled .debug_line section")); |
debd256d | 7172 | return; |
c906108c | 7173 | } |
a8c50c1f DJ |
7174 | /* Make sure that we parsed the extended op correctly. If e.g. |
7175 | we expected a different address size than the producer used, | |
7176 | we may have read the wrong number of bytes. */ | |
7177 | if (line_ptr != extended_end) | |
7178 | { | |
7179 | complaint (&symfile_complaints, | |
7180 | _("mangled .debug_line section")); | |
7181 | return; | |
7182 | } | |
c906108c SS |
7183 | break; |
7184 | case DW_LNS_copy: | |
25e43795 DJ |
7185 | if (lh->num_file_names < file) |
7186 | dwarf2_debug_line_missing_file_complaint (); | |
7187 | else | |
366da635 | 7188 | { |
25e43795 DJ |
7189 | lh->file_names[file - 1].included_p = 1; |
7190 | if (!decode_for_pst_p) | |
7191 | { | |
7192 | if (last_subfile != current_subfile) | |
7193 | { | |
7194 | if (last_subfile) | |
7195 | record_line (last_subfile, 0, address); | |
7196 | last_subfile = current_subfile; | |
7197 | } | |
7198 | record_line (current_subfile, line, | |
7199 | check_cu_functions (address, cu)); | |
7200 | } | |
366da635 | 7201 | } |
c906108c SS |
7202 | basic_block = 0; |
7203 | break; | |
7204 | case DW_LNS_advance_pc: | |
debd256d | 7205 | address += lh->minimum_instruction_length |
c906108c SS |
7206 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7207 | line_ptr += bytes_read; | |
7208 | break; | |
7209 | case DW_LNS_advance_line: | |
7210 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
7211 | line_ptr += bytes_read; | |
7212 | break; | |
7213 | case DW_LNS_set_file: | |
debd256d | 7214 | { |
a738430d MK |
7215 | /* The arrays lh->include_dirs and lh->file_names are |
7216 | 0-based, but the directory and file name numbers in | |
7217 | the statement program are 1-based. */ | |
debd256d | 7218 | struct file_entry *fe; |
4f1520fb | 7219 | char *dir = NULL; |
a738430d | 7220 | |
debd256d JB |
7221 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7222 | line_ptr += bytes_read; | |
25e43795 DJ |
7223 | if (lh->num_file_names < file) |
7224 | dwarf2_debug_line_missing_file_complaint (); | |
7225 | else | |
7226 | { | |
7227 | fe = &lh->file_names[file - 1]; | |
7228 | if (fe->dir_index) | |
7229 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7230 | if (!decode_for_pst_p) | |
7231 | { | |
7232 | last_subfile = current_subfile; | |
7233 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7234 | } | |
7235 | } | |
debd256d | 7236 | } |
c906108c SS |
7237 | break; |
7238 | case DW_LNS_set_column: | |
7239 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7240 | line_ptr += bytes_read; | |
7241 | break; | |
7242 | case DW_LNS_negate_stmt: | |
7243 | is_stmt = (!is_stmt); | |
7244 | break; | |
7245 | case DW_LNS_set_basic_block: | |
7246 | basic_block = 1; | |
7247 | break; | |
c2c6d25f JM |
7248 | /* Add to the address register of the state machine the |
7249 | address increment value corresponding to special opcode | |
a738430d MK |
7250 | 255. I.e., this value is scaled by the minimum |
7251 | instruction length since special opcode 255 would have | |
7252 | scaled the the increment. */ | |
c906108c | 7253 | case DW_LNS_const_add_pc: |
debd256d JB |
7254 | address += (lh->minimum_instruction_length |
7255 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
7256 | break; |
7257 | case DW_LNS_fixed_advance_pc: | |
7258 | address += read_2_bytes (abfd, line_ptr); | |
7259 | line_ptr += 2; | |
7260 | break; | |
9aa1fe7e | 7261 | default: |
a738430d MK |
7262 | { |
7263 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 7264 | int i; |
a738430d | 7265 | |
debd256d | 7266 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
7267 | { |
7268 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7269 | line_ptr += bytes_read; | |
7270 | } | |
7271 | } | |
c906108c SS |
7272 | } |
7273 | } | |
7274 | } | |
aaa75496 JB |
7275 | |
7276 | if (decode_for_pst_p) | |
7277 | { | |
7278 | int file_index; | |
7279 | ||
7280 | /* Now that we're done scanning the Line Header Program, we can | |
7281 | create the psymtab of each included file. */ | |
7282 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
7283 | if (lh->file_names[file_index].included_p == 1) | |
7284 | { | |
5b5464ad JB |
7285 | const struct file_entry fe = lh->file_names [file_index]; |
7286 | char *include_name = fe.name; | |
7287 | char *dir_name = NULL; | |
7288 | char *pst_filename = pst->filename; | |
7289 | ||
7290 | if (fe.dir_index) | |
7291 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
7292 | ||
7293 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
7294 | { | |
1754f103 MK |
7295 | include_name = concat (dir_name, SLASH_STRING, |
7296 | include_name, (char *)NULL); | |
5b5464ad JB |
7297 | make_cleanup (xfree, include_name); |
7298 | } | |
7299 | ||
7300 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
7301 | { | |
1754f103 MK |
7302 | pst_filename = concat (pst->dirname, SLASH_STRING, |
7303 | pst_filename, (char *)NULL); | |
5b5464ad JB |
7304 | make_cleanup (xfree, pst_filename); |
7305 | } | |
7306 | ||
7307 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
7308 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
7309 | } | |
7310 | } | |
cb1df416 DJ |
7311 | else |
7312 | { | |
7313 | /* Make sure a symtab is created for every file, even files | |
7314 | which contain only variables (i.e. no code with associated | |
7315 | line numbers). */ | |
7316 | ||
7317 | int i; | |
7318 | struct file_entry *fe; | |
7319 | ||
7320 | for (i = 0; i < lh->num_file_names; i++) | |
7321 | { | |
7322 | char *dir = NULL; | |
7323 | fe = &lh->file_names[i]; | |
7324 | if (fe->dir_index) | |
7325 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7326 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7327 | ||
7328 | /* Skip the main file; we don't need it, and it must be | |
7329 | allocated last, so that it will show up before the | |
7330 | non-primary symtabs in the objfile's symtab list. */ | |
7331 | if (current_subfile == first_subfile) | |
7332 | continue; | |
7333 | ||
7334 | if (current_subfile->symtab == NULL) | |
7335 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
7336 | cu->objfile); | |
7337 | fe->symtab = current_subfile->symtab; | |
7338 | } | |
7339 | } | |
c906108c SS |
7340 | } |
7341 | ||
7342 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
7343 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
7344 | or NULL if not known. COMP_DIR is the compilation directory for the |
7345 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
7346 | This routine tries to keep line numbers from identical absolute and |
7347 | relative file names in a common subfile. | |
7348 | ||
7349 | Using the `list' example from the GDB testsuite, which resides in | |
7350 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
7351 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
7352 | ||
c5aa993b JM |
7353 | DW_AT_name: /srcdir/list0.c |
7354 | DW_AT_comp_dir: /compdir | |
357e46e7 | 7355 | files.files[0].name: list0.h |
c5aa993b | 7356 | files.files[0].dir: /srcdir |
357e46e7 | 7357 | files.files[1].name: list0.c |
c5aa993b | 7358 | files.files[1].dir: /srcdir |
c906108c SS |
7359 | |
7360 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
7361 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
7362 | start_subfile will ensure that this happens provided that we pass the | |
7363 | concatenation of files.files[1].dir and files.files[1].name as the | |
7364 | subfile's name. */ | |
c906108c SS |
7365 | |
7366 | static void | |
4f1520fb | 7367 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 7368 | { |
4f1520fb FR |
7369 | char *fullname; |
7370 | ||
7371 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
7372 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
7373 | second argument to start_subfile. To be consistent, we do the | |
7374 | same here. In order not to lose the line information directory, | |
7375 | we concatenate it to the filename when it makes sense. | |
7376 | Note that the Dwarf3 standard says (speaking of filenames in line | |
7377 | information): ``The directory index is ignored for file names | |
7378 | that represent full path names''. Thus ignoring dirname in the | |
7379 | `else' branch below isn't an issue. */ | |
c906108c | 7380 | |
d5166ae1 | 7381 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
7382 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
7383 | else | |
7384 | fullname = filename; | |
c906108c | 7385 | |
4f1520fb FR |
7386 | start_subfile (fullname, comp_dir); |
7387 | ||
7388 | if (fullname != filename) | |
7389 | xfree (fullname); | |
c906108c SS |
7390 | } |
7391 | ||
4c2df51b DJ |
7392 | static void |
7393 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 7394 | struct dwarf2_cu *cu) |
4c2df51b | 7395 | { |
e7c27a73 DJ |
7396 | struct objfile *objfile = cu->objfile; |
7397 | struct comp_unit_head *cu_header = &cu->header; | |
7398 | ||
4c2df51b DJ |
7399 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
7400 | code here to turn a symbol with DW_AT_external and a | |
7401 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
7402 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
7403 | with some versions of binutils) where shared libraries could have | |
7404 | relocations against symbols in their debug information - the | |
7405 | minimal symbol would have the right address, but the debug info | |
7406 | would not. It's no longer necessary, because we will explicitly | |
7407 | apply relocations when we read in the debug information now. */ | |
7408 | ||
7409 | /* A DW_AT_location attribute with no contents indicates that a | |
7410 | variable has been optimized away. */ | |
7411 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
7412 | { | |
7413 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
7414 | return; | |
7415 | } | |
7416 | ||
7417 | /* Handle one degenerate form of location expression specially, to | |
7418 | preserve GDB's previous behavior when section offsets are | |
7419 | specified. If this is just a DW_OP_addr then mark this symbol | |
7420 | as LOC_STATIC. */ | |
7421 | ||
7422 | if (attr_form_is_block (attr) | |
7423 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
7424 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
7425 | { | |
891d2f0b | 7426 | unsigned int dummy; |
4c2df51b DJ |
7427 | |
7428 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 7429 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 7430 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
7431 | fixup_symbol_section (sym, objfile); |
7432 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
7433 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
7434 | return; |
7435 | } | |
7436 | ||
7437 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
7438 | expression evaluator, and use LOC_COMPUTED only when necessary | |
7439 | (i.e. when the value of a register or memory location is | |
7440 | referenced, or a thread-local block, etc.). Then again, it might | |
7441 | not be worthwhile. I'm assuming that it isn't unless performance | |
7442 | or memory numbers show me otherwise. */ | |
7443 | ||
e7c27a73 | 7444 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
7445 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
7446 | } | |
7447 | ||
c906108c SS |
7448 | /* Given a pointer to a DWARF information entry, figure out if we need |
7449 | to make a symbol table entry for it, and if so, create a new entry | |
7450 | and return a pointer to it. | |
7451 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 7452 | used the passed type. */ |
c906108c SS |
7453 | |
7454 | static struct symbol * | |
e7c27a73 | 7455 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 7456 | { |
e7c27a73 | 7457 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7458 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7459 | struct symbol *sym = NULL; |
7460 | char *name; | |
7461 | struct attribute *attr = NULL; | |
7462 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
7463 | CORE_ADDR baseaddr; |
7464 | ||
7465 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7466 | |
5c4e30ca | 7467 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7468 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7469 | else |
7470 | name = TYPE_NAME (type); | |
7471 | ||
c906108c SS |
7472 | if (name) |
7473 | { | |
4a146b47 | 7474 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7475 | sizeof (struct symbol)); |
7476 | OBJSTAT (objfile, n_syms++); | |
7477 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7478 | |
7479 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7480 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7481 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7482 | |
7483 | /* Default assumptions. | |
c5aa993b | 7484 | Use the passed type or decode it from the die. */ |
176620f1 | 7485 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7486 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7487 | if (type != NULL) |
7488 | SYMBOL_TYPE (sym) = type; | |
7489 | else | |
e7c27a73 | 7490 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7491 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7492 | if (attr) |
7493 | { | |
7494 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7495 | } | |
cb1df416 DJ |
7496 | |
7497 | attr = dwarf2_attr (die, DW_AT_decl_file, cu); | |
7498 | if (attr) | |
7499 | { | |
7500 | int file_index = DW_UNSND (attr); | |
7501 | if (cu->line_header == NULL | |
7502 | || file_index > cu->line_header->num_file_names) | |
7503 | complaint (&symfile_complaints, | |
7504 | _("file index out of range")); | |
1c3d648d | 7505 | else if (file_index > 0) |
cb1df416 DJ |
7506 | { |
7507 | struct file_entry *fe; | |
7508 | fe = &cu->line_header->file_names[file_index - 1]; | |
7509 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
7510 | } | |
7511 | } | |
7512 | ||
c906108c SS |
7513 | switch (die->tag) |
7514 | { | |
7515 | case DW_TAG_label: | |
e142c38c | 7516 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7517 | if (attr) |
7518 | { | |
7519 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7520 | } | |
7521 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7522 | break; | |
7523 | case DW_TAG_subprogram: | |
7524 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7525 | finish_block. */ | |
7526 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7527 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
7528 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
7529 | || cu->language == language_ada) | |
c906108c | 7530 | { |
2cfa0c8d JB |
7531 | /* Subprograms marked external are stored as a global symbol. |
7532 | Ada subprograms, whether marked external or not, are always | |
7533 | stored as a global symbol, because we want to be able to | |
7534 | access them globally. For instance, we want to be able | |
7535 | to break on a nested subprogram without having to | |
7536 | specify the context. */ | |
c906108c SS |
7537 | add_symbol_to_list (sym, &global_symbols); |
7538 | } | |
7539 | else | |
7540 | { | |
e142c38c | 7541 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7542 | } |
7543 | break; | |
7544 | case DW_TAG_variable: | |
7545 | /* Compilation with minimal debug info may result in variables | |
7546 | with missing type entries. Change the misleading `void' type | |
7547 | to something sensible. */ | |
7548 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 7549 | SYMBOL_TYPE (sym) |
5e2b427d | 7550 | = builtin_type (gdbarch)->nodebug_data_symbol; |
64c50499 | 7551 | |
e142c38c | 7552 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7553 | if (attr) |
7554 | { | |
e7c27a73 | 7555 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7556 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7557 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7558 | add_symbol_to_list (sym, &global_symbols); | |
7559 | else | |
e142c38c | 7560 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7561 | break; |
7562 | } | |
e142c38c | 7563 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7564 | if (attr) |
7565 | { | |
e7c27a73 | 7566 | var_decode_location (attr, sym, cu); |
e142c38c | 7567 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7568 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7569 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7570 | else |
e142c38c | 7571 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7572 | } |
7573 | else | |
7574 | { | |
7575 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7576 | If it is an external symbol and we have type information |
7577 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7578 | The address of the variable will then be determined from | |
7579 | the minimal symbol table whenever the variable is | |
7580 | referenced. */ | |
e142c38c | 7581 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7582 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7583 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7584 | { |
7585 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
7586 | add_symbol_to_list (sym, &global_symbols); | |
7587 | } | |
7588 | } | |
7589 | break; | |
7590 | case DW_TAG_formal_parameter: | |
2a2d4dc3 | 7591 | SYMBOL_IS_ARGUMENT (sym) = 1; |
e142c38c | 7592 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7593 | if (attr) |
7594 | { | |
e7c27a73 | 7595 | var_decode_location (attr, sym, cu); |
c906108c | 7596 | } |
e142c38c | 7597 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7598 | if (attr) |
7599 | { | |
e7c27a73 | 7600 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7601 | } |
e142c38c | 7602 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7603 | break; |
7604 | case DW_TAG_unspecified_parameters: | |
7605 | /* From varargs functions; gdb doesn't seem to have any | |
7606 | interest in this information, so just ignore it for now. | |
7607 | (FIXME?) */ | |
7608 | break; | |
7609 | case DW_TAG_class_type: | |
680b30c7 | 7610 | case DW_TAG_interface_type: |
c906108c SS |
7611 | case DW_TAG_structure_type: |
7612 | case DW_TAG_union_type: | |
72019c9c | 7613 | case DW_TAG_set_type: |
c906108c SS |
7614 | case DW_TAG_enumeration_type: |
7615 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 7616 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 7617 | |
63d06c5c DC |
7618 | /* Make sure that the symbol includes appropriate enclosing |
7619 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 7620 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
7621 | the type. */ |
7622 | ||
987504bb JJ |
7623 | if (cu->language == language_cplus |
7624 | || cu->language == language_java) | |
c906108c | 7625 | { |
63d06c5c DC |
7626 | struct type *type = SYMBOL_TYPE (sym); |
7627 | ||
7628 | if (TYPE_TAG_NAME (type) != NULL) | |
7629 | { | |
7630 | /* FIXME: carlton/2003-11-10: Should this use | |
7631 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
7632 | arises further down in this function.) */ |
7633 | /* The type's name is already allocated along with | |
7634 | this objfile, so we don't need to duplicate it | |
7635 | for the symbol. */ | |
7636 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 7637 | } |
c906108c | 7638 | } |
63d06c5c DC |
7639 | |
7640 | { | |
987504bb | 7641 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
7642 | really ever be static objects: otherwise, if you try |
7643 | to, say, break of a class's method and you're in a file | |
7644 | which doesn't mention that class, it won't work unless | |
7645 | the check for all static symbols in lookup_symbol_aux | |
7646 | saves you. See the OtherFileClass tests in | |
7647 | gdb.c++/namespace.exp. */ | |
7648 | ||
7649 | struct pending **list_to_add; | |
7650 | ||
e142c38c | 7651 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7652 | && (cu->language == language_cplus |
7653 | || cu->language == language_java) | |
e142c38c | 7654 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7655 | |
7656 | add_symbol_to_list (sym, list_to_add); | |
7657 | ||
7658 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 7659 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 7660 | defines a typedef for the class. */ |
987504bb | 7661 | if (cu->language == language_cplus |
8c6860bb JB |
7662 | || cu->language == language_java |
7663 | || cu->language == language_ada) | |
63d06c5c | 7664 | { |
d8151005 DJ |
7665 | /* The symbol's name is already allocated along with |
7666 | this objfile, so we don't need to duplicate it for | |
7667 | the type. */ | |
63d06c5c | 7668 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7669 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7670 | } |
7671 | } | |
c906108c SS |
7672 | break; |
7673 | case DW_TAG_typedef: | |
0114d602 | 7674 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
63d06c5c DC |
7675 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
7676 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7677 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7678 | break; |
c906108c | 7679 | case DW_TAG_base_type: |
a02abb62 | 7680 | case DW_TAG_subrange_type: |
c906108c | 7681 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7682 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7683 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7684 | break; |
7685 | case DW_TAG_enumerator: | |
0114d602 | 7686 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
e142c38c | 7687 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7688 | if (attr) |
7689 | { | |
e7c27a73 | 7690 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7691 | } |
63d06c5c DC |
7692 | { |
7693 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7694 | DW_TAG_class_type, etc. block. */ | |
7695 | ||
7696 | struct pending **list_to_add; | |
7697 | ||
e142c38c | 7698 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7699 | && (cu->language == language_cplus |
7700 | || cu->language == language_java) | |
e142c38c | 7701 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7702 | |
7703 | add_symbol_to_list (sym, list_to_add); | |
7704 | } | |
c906108c | 7705 | break; |
5c4e30ca DC |
7706 | case DW_TAG_namespace: |
7707 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7708 | add_symbol_to_list (sym, &global_symbols); | |
7709 | break; | |
c906108c SS |
7710 | default: |
7711 | /* Not a tag we recognize. Hopefully we aren't processing | |
7712 | trash data, but since we must specifically ignore things | |
7713 | we don't recognize, there is nothing else we should do at | |
7714 | this point. */ | |
e2e0b3e5 | 7715 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7716 | dwarf_tag_name (die->tag)); |
c906108c SS |
7717 | break; |
7718 | } | |
df8a16a1 DJ |
7719 | |
7720 | /* For the benefit of old versions of GCC, check for anonymous | |
7721 | namespaces based on the demangled name. */ | |
7722 | if (!processing_has_namespace_info | |
7723 | && cu->language == language_cplus | |
7724 | && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL) | |
7725 | cp_scan_for_anonymous_namespaces (sym); | |
c906108c SS |
7726 | } |
7727 | return (sym); | |
7728 | } | |
7729 | ||
7730 | /* Copy constant value from an attribute to a symbol. */ | |
7731 | ||
7732 | static void | |
107d2387 | 7733 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7734 | struct dwarf2_cu *cu) |
c906108c | 7735 | { |
e7c27a73 DJ |
7736 | struct objfile *objfile = cu->objfile; |
7737 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7738 | struct dwarf_block *blk; |
7739 | ||
7740 | switch (attr->form) | |
7741 | { | |
7742 | case DW_FORM_addr: | |
107d2387 | 7743 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 7744 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
7745 | cu_header->addr_size, |
7746 | TYPE_LENGTH (SYMBOL_TYPE | |
7747 | (sym))); | |
4e38b386 | 7748 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7749 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7750 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7751 | it's body - store_unsigned_integer. */ | |
7752 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7753 | DW_ADDR (attr)); | |
c906108c SS |
7754 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7755 | break; | |
93b5768b PA |
7756 | case DW_FORM_strp: |
7757 | /* DW_STRING is already allocated on the obstack, point directly | |
7758 | to it. */ | |
7759 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
7760 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7761 | break; | |
c906108c SS |
7762 | case DW_FORM_block1: |
7763 | case DW_FORM_block2: | |
7764 | case DW_FORM_block4: | |
7765 | case DW_FORM_block: | |
7766 | blk = DW_BLOCK (attr); | |
7767 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 7768 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
7769 | blk->size, |
7770 | TYPE_LENGTH (SYMBOL_TYPE | |
7771 | (sym))); | |
4e38b386 | 7772 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7773 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7774 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7775 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7776 | break; | |
2df3850c JM |
7777 | |
7778 | /* The DW_AT_const_value attributes are supposed to carry the | |
7779 | symbol's value "represented as it would be on the target | |
7780 | architecture." By the time we get here, it's already been | |
7781 | converted to host endianness, so we just need to sign- or | |
7782 | zero-extend it as appropriate. */ | |
7783 | case DW_FORM_data1: | |
7784 | dwarf2_const_value_data (attr, sym, 8); | |
7785 | break; | |
c906108c | 7786 | case DW_FORM_data2: |
2df3850c JM |
7787 | dwarf2_const_value_data (attr, sym, 16); |
7788 | break; | |
c906108c | 7789 | case DW_FORM_data4: |
2df3850c JM |
7790 | dwarf2_const_value_data (attr, sym, 32); |
7791 | break; | |
c906108c | 7792 | case DW_FORM_data8: |
2df3850c JM |
7793 | dwarf2_const_value_data (attr, sym, 64); |
7794 | break; | |
7795 | ||
c906108c | 7796 | case DW_FORM_sdata: |
2df3850c JM |
7797 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7798 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7799 | break; | |
7800 | ||
c906108c SS |
7801 | case DW_FORM_udata: |
7802 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
7803 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7804 | break; | |
2df3850c | 7805 | |
c906108c | 7806 | default: |
4d3c2250 | 7807 | complaint (&symfile_complaints, |
e2e0b3e5 | 7808 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 7809 | dwarf_form_name (attr->form)); |
c906108c SS |
7810 | SYMBOL_VALUE (sym) = 0; |
7811 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7812 | break; | |
7813 | } | |
7814 | } | |
7815 | ||
2df3850c JM |
7816 | |
7817 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
7818 | or zero-extend it as appropriate for the symbol's type. */ | |
7819 | static void | |
7820 | dwarf2_const_value_data (struct attribute *attr, | |
7821 | struct symbol *sym, | |
7822 | int bits) | |
7823 | { | |
7824 | LONGEST l = DW_UNSND (attr); | |
7825 | ||
7826 | if (bits < sizeof (l) * 8) | |
7827 | { | |
7828 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
7829 | l &= ((LONGEST) 1 << bits) - 1; | |
7830 | else | |
bf9198f1 | 7831 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
7832 | } |
7833 | ||
7834 | SYMBOL_VALUE (sym) = l; | |
7835 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7836 | } | |
7837 | ||
7838 | ||
c906108c SS |
7839 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
7840 | ||
7841 | static struct type * | |
e7c27a73 | 7842 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7843 | { |
5e2b427d | 7844 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
c906108c SS |
7845 | struct type *type; |
7846 | struct attribute *type_attr; | |
7847 | struct die_info *type_die; | |
c906108c | 7848 | |
e142c38c | 7849 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
7850 | if (!type_attr) |
7851 | { | |
7852 | /* A missing DW_AT_type represents a void type. */ | |
5e2b427d | 7853 | return builtin_type (gdbarch)->builtin_void; |
c906108c SS |
7854 | } |
7855 | else | |
f2f0e013 | 7856 | type_die = follow_die_ref (die, type_attr, &cu); |
10b3939b | 7857 | |
e7c27a73 | 7858 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7859 | if (!type) |
7860 | { | |
d97bc12b | 7861 | dump_die_for_error (type_die); |
8a3fe4f8 | 7862 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 7863 | cu->objfile->name); |
c906108c SS |
7864 | } |
7865 | return type; | |
7866 | } | |
7867 | ||
7868 | /* Return the containing type of the die in question using its | |
7869 | DW_AT_containing_type attribute. */ | |
7870 | ||
7871 | static struct type * | |
e7c27a73 | 7872 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7873 | { |
7874 | struct type *type = NULL; | |
7875 | struct attribute *type_attr; | |
7876 | struct die_info *type_die = NULL; | |
c906108c | 7877 | |
e142c38c | 7878 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
7879 | if (type_attr) |
7880 | { | |
f2f0e013 | 7881 | type_die = follow_die_ref (die, type_attr, &cu); |
e7c27a73 | 7882 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7883 | } |
7884 | if (!type) | |
7885 | { | |
7886 | if (type_die) | |
d97bc12b | 7887 | dump_die_for_error (type_die); |
8a3fe4f8 | 7888 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 7889 | cu->objfile->name); |
c906108c SS |
7890 | } |
7891 | return type; | |
7892 | } | |
7893 | ||
c906108c | 7894 | static struct type * |
e7c27a73 | 7895 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7896 | { |
f792889a DJ |
7897 | struct type *this_type; |
7898 | ||
7899 | this_type = read_type_die (die, cu); | |
7900 | if (!this_type) | |
c906108c | 7901 | { |
d97bc12b | 7902 | dump_die_for_error (die); |
f792889a DJ |
7903 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
7904 | cu->objfile->name); | |
c906108c | 7905 | } |
f792889a | 7906 | return this_type; |
c906108c SS |
7907 | } |
7908 | ||
f792889a | 7909 | static struct type * |
e7c27a73 | 7910 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7911 | { |
f792889a DJ |
7912 | struct type *this_type; |
7913 | ||
7914 | this_type = get_die_type (die, cu); | |
7915 | if (this_type) | |
7916 | return this_type; | |
7917 | ||
c906108c SS |
7918 | switch (die->tag) |
7919 | { | |
7920 | case DW_TAG_class_type: | |
680b30c7 | 7921 | case DW_TAG_interface_type: |
c906108c SS |
7922 | case DW_TAG_structure_type: |
7923 | case DW_TAG_union_type: | |
f792889a | 7924 | this_type = read_structure_type (die, cu); |
c906108c SS |
7925 | break; |
7926 | case DW_TAG_enumeration_type: | |
f792889a | 7927 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
7928 | break; |
7929 | case DW_TAG_subprogram: | |
7930 | case DW_TAG_subroutine_type: | |
f792889a | 7931 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
7932 | break; |
7933 | case DW_TAG_array_type: | |
f792889a | 7934 | this_type = read_array_type (die, cu); |
c906108c | 7935 | break; |
72019c9c | 7936 | case DW_TAG_set_type: |
f792889a | 7937 | this_type = read_set_type (die, cu); |
72019c9c | 7938 | break; |
c906108c | 7939 | case DW_TAG_pointer_type: |
f792889a | 7940 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
7941 | break; |
7942 | case DW_TAG_ptr_to_member_type: | |
f792889a | 7943 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
7944 | break; |
7945 | case DW_TAG_reference_type: | |
f792889a | 7946 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
7947 | break; |
7948 | case DW_TAG_const_type: | |
f792889a | 7949 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
7950 | break; |
7951 | case DW_TAG_volatile_type: | |
f792889a | 7952 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
7953 | break; |
7954 | case DW_TAG_string_type: | |
f792889a | 7955 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
7956 | break; |
7957 | case DW_TAG_typedef: | |
f792889a | 7958 | this_type = read_typedef (die, cu); |
c906108c | 7959 | break; |
a02abb62 | 7960 | case DW_TAG_subrange_type: |
f792889a | 7961 | this_type = read_subrange_type (die, cu); |
a02abb62 | 7962 | break; |
c906108c | 7963 | case DW_TAG_base_type: |
f792889a | 7964 | this_type = read_base_type (die, cu); |
c906108c | 7965 | break; |
81a17f79 | 7966 | case DW_TAG_unspecified_type: |
f792889a | 7967 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 7968 | break; |
0114d602 DJ |
7969 | case DW_TAG_namespace: |
7970 | this_type = read_namespace_type (die, cu); | |
7971 | break; | |
c906108c | 7972 | default: |
a1f5b845 | 7973 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 7974 | dwarf_tag_name (die->tag)); |
c906108c SS |
7975 | break; |
7976 | } | |
63d06c5c | 7977 | |
f792889a | 7978 | return this_type; |
63d06c5c DC |
7979 | } |
7980 | ||
fdde2d81 | 7981 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 7982 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 7983 | |
0114d602 DJ |
7984 | For example, if we're within the method foo() in the following |
7985 | code: | |
7986 | ||
7987 | namespace N { | |
7988 | class C { | |
7989 | void foo () { | |
7990 | } | |
7991 | }; | |
7992 | } | |
7993 | ||
7994 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
7995 | |
7996 | static char * | |
e142c38c | 7997 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 7998 | { |
0114d602 DJ |
7999 | struct die_info *parent, *spec_die; |
8000 | struct dwarf2_cu *spec_cu; | |
8001 | struct type *parent_type; | |
63d06c5c | 8002 | |
987504bb JJ |
8003 | if (cu->language != language_cplus |
8004 | && cu->language != language_java) | |
0114d602 DJ |
8005 | return ""; |
8006 | ||
8007 | /* We have to be careful in the presence of DW_AT_specification. | |
8008 | For example, with GCC 3.4, given the code | |
8009 | ||
8010 | namespace N { | |
8011 | void foo() { | |
8012 | // Definition of N::foo. | |
8013 | } | |
8014 | } | |
8015 | ||
8016 | then we'll have a tree of DIEs like this: | |
8017 | ||
8018 | 1: DW_TAG_compile_unit | |
8019 | 2: DW_TAG_namespace // N | |
8020 | 3: DW_TAG_subprogram // declaration of N::foo | |
8021 | 4: DW_TAG_subprogram // definition of N::foo | |
8022 | DW_AT_specification // refers to die #3 | |
8023 | ||
8024 | Thus, when processing die #4, we have to pretend that we're in | |
8025 | the context of its DW_AT_specification, namely the contex of die | |
8026 | #3. */ | |
8027 | spec_cu = cu; | |
8028 | spec_die = die_specification (die, &spec_cu); | |
8029 | if (spec_die == NULL) | |
8030 | parent = die->parent; | |
8031 | else | |
63d06c5c | 8032 | { |
0114d602 DJ |
8033 | parent = spec_die->parent; |
8034 | cu = spec_cu; | |
63d06c5c | 8035 | } |
0114d602 DJ |
8036 | |
8037 | if (parent == NULL) | |
8038 | return ""; | |
63d06c5c | 8039 | else |
0114d602 DJ |
8040 | switch (parent->tag) |
8041 | { | |
63d06c5c | 8042 | case DW_TAG_namespace: |
0114d602 DJ |
8043 | parent_type = read_type_die (parent, cu); |
8044 | /* We give a name to even anonymous namespaces. */ | |
8045 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 8046 | case DW_TAG_class_type: |
680b30c7 | 8047 | case DW_TAG_interface_type: |
63d06c5c | 8048 | case DW_TAG_structure_type: |
0114d602 DJ |
8049 | case DW_TAG_union_type: |
8050 | parent_type = read_type_die (parent, cu); | |
8051 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
8052 | return TYPE_TAG_NAME (parent_type); | |
8053 | else | |
8054 | /* An anonymous structure is only allowed non-static data | |
8055 | members; no typedefs, no member functions, et cetera. | |
8056 | So it does not need a prefix. */ | |
8057 | return ""; | |
63d06c5c | 8058 | default: |
8176b9b8 | 8059 | return determine_prefix (parent, cu); |
63d06c5c | 8060 | } |
63d06c5c DC |
8061 | } |
8062 | ||
987504bb JJ |
8063 | /* Return a newly-allocated string formed by concatenating PREFIX and |
8064 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
8065 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
8066 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
8067 | is used to determine the language and hence, the appropriate separator. */ | |
8068 | ||
8069 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
8070 | |
8071 | static char * | |
987504bb JJ |
8072 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
8073 | struct dwarf2_cu *cu) | |
63d06c5c | 8074 | { |
987504bb | 8075 | char *sep; |
63d06c5c | 8076 | |
987504bb JJ |
8077 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
8078 | sep = ""; | |
8079 | else if (cu->language == language_java) | |
8080 | sep = "."; | |
8081 | else | |
8082 | sep = "::"; | |
63d06c5c | 8083 | |
987504bb JJ |
8084 | if (obs == NULL) |
8085 | { | |
8086 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
8087 | retval[0] = '\0'; | |
8088 | ||
8089 | if (prefix) | |
8090 | { | |
8091 | strcpy (retval, prefix); | |
8092 | strcat (retval, sep); | |
8093 | } | |
8094 | if (suffix) | |
8095 | strcat (retval, suffix); | |
8096 | ||
63d06c5c DC |
8097 | return retval; |
8098 | } | |
987504bb JJ |
8099 | else |
8100 | { | |
8101 | /* We have an obstack. */ | |
8102 | return obconcat (obs, prefix, sep, suffix); | |
8103 | } | |
63d06c5c DC |
8104 | } |
8105 | ||
c906108c SS |
8106 | /* Return sibling of die, NULL if no sibling. */ |
8107 | ||
f9aca02d | 8108 | static struct die_info * |
fba45db2 | 8109 | sibling_die (struct die_info *die) |
c906108c | 8110 | { |
639d11d3 | 8111 | return die->sibling; |
c906108c SS |
8112 | } |
8113 | ||
8114 | /* Get linkage name of a die, return NULL if not found. */ | |
8115 | ||
8116 | static char * | |
e142c38c | 8117 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8118 | { |
8119 | struct attribute *attr; | |
8120 | ||
e142c38c | 8121 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
8122 | if (attr && DW_STRING (attr)) |
8123 | return DW_STRING (attr); | |
e142c38c | 8124 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
8125 | if (attr && DW_STRING (attr)) |
8126 | return DW_STRING (attr); | |
8127 | return NULL; | |
8128 | } | |
8129 | ||
9219021c DC |
8130 | /* Get name of a die, return NULL if not found. */ |
8131 | ||
8132 | static char * | |
e142c38c | 8133 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8134 | { |
8135 | struct attribute *attr; | |
8136 | ||
e142c38c | 8137 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
8138 | if (attr && DW_STRING (attr)) |
8139 | return DW_STRING (attr); | |
8140 | return NULL; | |
8141 | } | |
8142 | ||
8143 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
8144 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
8145 | containing the return value on output. */ | |
9219021c DC |
8146 | |
8147 | static struct die_info * | |
f2f0e013 | 8148 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
8149 | { |
8150 | struct attribute *attr; | |
9219021c | 8151 | |
f2f0e013 | 8152 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
8153 | if (attr == NULL) |
8154 | return NULL; | |
8155 | ||
f2f0e013 | 8156 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
8157 | } |
8158 | ||
c906108c SS |
8159 | /* Convert a DIE tag into its string name. */ |
8160 | ||
8161 | static char * | |
aa1ee363 | 8162 | dwarf_tag_name (unsigned tag) |
c906108c SS |
8163 | { |
8164 | switch (tag) | |
8165 | { | |
8166 | case DW_TAG_padding: | |
8167 | return "DW_TAG_padding"; | |
8168 | case DW_TAG_array_type: | |
8169 | return "DW_TAG_array_type"; | |
8170 | case DW_TAG_class_type: | |
8171 | return "DW_TAG_class_type"; | |
8172 | case DW_TAG_entry_point: | |
8173 | return "DW_TAG_entry_point"; | |
8174 | case DW_TAG_enumeration_type: | |
8175 | return "DW_TAG_enumeration_type"; | |
8176 | case DW_TAG_formal_parameter: | |
8177 | return "DW_TAG_formal_parameter"; | |
8178 | case DW_TAG_imported_declaration: | |
8179 | return "DW_TAG_imported_declaration"; | |
8180 | case DW_TAG_label: | |
8181 | return "DW_TAG_label"; | |
8182 | case DW_TAG_lexical_block: | |
8183 | return "DW_TAG_lexical_block"; | |
8184 | case DW_TAG_member: | |
8185 | return "DW_TAG_member"; | |
8186 | case DW_TAG_pointer_type: | |
8187 | return "DW_TAG_pointer_type"; | |
8188 | case DW_TAG_reference_type: | |
8189 | return "DW_TAG_reference_type"; | |
8190 | case DW_TAG_compile_unit: | |
8191 | return "DW_TAG_compile_unit"; | |
8192 | case DW_TAG_string_type: | |
8193 | return "DW_TAG_string_type"; | |
8194 | case DW_TAG_structure_type: | |
8195 | return "DW_TAG_structure_type"; | |
8196 | case DW_TAG_subroutine_type: | |
8197 | return "DW_TAG_subroutine_type"; | |
8198 | case DW_TAG_typedef: | |
8199 | return "DW_TAG_typedef"; | |
8200 | case DW_TAG_union_type: | |
8201 | return "DW_TAG_union_type"; | |
8202 | case DW_TAG_unspecified_parameters: | |
8203 | return "DW_TAG_unspecified_parameters"; | |
8204 | case DW_TAG_variant: | |
8205 | return "DW_TAG_variant"; | |
8206 | case DW_TAG_common_block: | |
8207 | return "DW_TAG_common_block"; | |
8208 | case DW_TAG_common_inclusion: | |
8209 | return "DW_TAG_common_inclusion"; | |
8210 | case DW_TAG_inheritance: | |
8211 | return "DW_TAG_inheritance"; | |
8212 | case DW_TAG_inlined_subroutine: | |
8213 | return "DW_TAG_inlined_subroutine"; | |
8214 | case DW_TAG_module: | |
8215 | return "DW_TAG_module"; | |
8216 | case DW_TAG_ptr_to_member_type: | |
8217 | return "DW_TAG_ptr_to_member_type"; | |
8218 | case DW_TAG_set_type: | |
8219 | return "DW_TAG_set_type"; | |
8220 | case DW_TAG_subrange_type: | |
8221 | return "DW_TAG_subrange_type"; | |
8222 | case DW_TAG_with_stmt: | |
8223 | return "DW_TAG_with_stmt"; | |
8224 | case DW_TAG_access_declaration: | |
8225 | return "DW_TAG_access_declaration"; | |
8226 | case DW_TAG_base_type: | |
8227 | return "DW_TAG_base_type"; | |
8228 | case DW_TAG_catch_block: | |
8229 | return "DW_TAG_catch_block"; | |
8230 | case DW_TAG_const_type: | |
8231 | return "DW_TAG_const_type"; | |
8232 | case DW_TAG_constant: | |
8233 | return "DW_TAG_constant"; | |
8234 | case DW_TAG_enumerator: | |
8235 | return "DW_TAG_enumerator"; | |
8236 | case DW_TAG_file_type: | |
8237 | return "DW_TAG_file_type"; | |
8238 | case DW_TAG_friend: | |
8239 | return "DW_TAG_friend"; | |
8240 | case DW_TAG_namelist: | |
8241 | return "DW_TAG_namelist"; | |
8242 | case DW_TAG_namelist_item: | |
8243 | return "DW_TAG_namelist_item"; | |
8244 | case DW_TAG_packed_type: | |
8245 | return "DW_TAG_packed_type"; | |
8246 | case DW_TAG_subprogram: | |
8247 | return "DW_TAG_subprogram"; | |
8248 | case DW_TAG_template_type_param: | |
8249 | return "DW_TAG_template_type_param"; | |
8250 | case DW_TAG_template_value_param: | |
8251 | return "DW_TAG_template_value_param"; | |
8252 | case DW_TAG_thrown_type: | |
8253 | return "DW_TAG_thrown_type"; | |
8254 | case DW_TAG_try_block: | |
8255 | return "DW_TAG_try_block"; | |
8256 | case DW_TAG_variant_part: | |
8257 | return "DW_TAG_variant_part"; | |
8258 | case DW_TAG_variable: | |
8259 | return "DW_TAG_variable"; | |
8260 | case DW_TAG_volatile_type: | |
8261 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
8262 | case DW_TAG_dwarf_procedure: |
8263 | return "DW_TAG_dwarf_procedure"; | |
8264 | case DW_TAG_restrict_type: | |
8265 | return "DW_TAG_restrict_type"; | |
8266 | case DW_TAG_interface_type: | |
8267 | return "DW_TAG_interface_type"; | |
8268 | case DW_TAG_namespace: | |
8269 | return "DW_TAG_namespace"; | |
8270 | case DW_TAG_imported_module: | |
8271 | return "DW_TAG_imported_module"; | |
8272 | case DW_TAG_unspecified_type: | |
8273 | return "DW_TAG_unspecified_type"; | |
8274 | case DW_TAG_partial_unit: | |
8275 | return "DW_TAG_partial_unit"; | |
8276 | case DW_TAG_imported_unit: | |
8277 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
8278 | case DW_TAG_condition: |
8279 | return "DW_TAG_condition"; | |
8280 | case DW_TAG_shared_type: | |
8281 | return "DW_TAG_shared_type"; | |
c906108c SS |
8282 | case DW_TAG_MIPS_loop: |
8283 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
8284 | case DW_TAG_HP_array_descriptor: |
8285 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
8286 | case DW_TAG_format_label: |
8287 | return "DW_TAG_format_label"; | |
8288 | case DW_TAG_function_template: | |
8289 | return "DW_TAG_function_template"; | |
8290 | case DW_TAG_class_template: | |
8291 | return "DW_TAG_class_template"; | |
b7619582 GF |
8292 | case DW_TAG_GNU_BINCL: |
8293 | return "DW_TAG_GNU_BINCL"; | |
8294 | case DW_TAG_GNU_EINCL: | |
8295 | return "DW_TAG_GNU_EINCL"; | |
8296 | case DW_TAG_upc_shared_type: | |
8297 | return "DW_TAG_upc_shared_type"; | |
8298 | case DW_TAG_upc_strict_type: | |
8299 | return "DW_TAG_upc_strict_type"; | |
8300 | case DW_TAG_upc_relaxed_type: | |
8301 | return "DW_TAG_upc_relaxed_type"; | |
8302 | case DW_TAG_PGI_kanji_type: | |
8303 | return "DW_TAG_PGI_kanji_type"; | |
8304 | case DW_TAG_PGI_interface_block: | |
8305 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
8306 | default: |
8307 | return "DW_TAG_<unknown>"; | |
8308 | } | |
8309 | } | |
8310 | ||
8311 | /* Convert a DWARF attribute code into its string name. */ | |
8312 | ||
8313 | static char * | |
aa1ee363 | 8314 | dwarf_attr_name (unsigned attr) |
c906108c SS |
8315 | { |
8316 | switch (attr) | |
8317 | { | |
8318 | case DW_AT_sibling: | |
8319 | return "DW_AT_sibling"; | |
8320 | case DW_AT_location: | |
8321 | return "DW_AT_location"; | |
8322 | case DW_AT_name: | |
8323 | return "DW_AT_name"; | |
8324 | case DW_AT_ordering: | |
8325 | return "DW_AT_ordering"; | |
8326 | case DW_AT_subscr_data: | |
8327 | return "DW_AT_subscr_data"; | |
8328 | case DW_AT_byte_size: | |
8329 | return "DW_AT_byte_size"; | |
8330 | case DW_AT_bit_offset: | |
8331 | return "DW_AT_bit_offset"; | |
8332 | case DW_AT_bit_size: | |
8333 | return "DW_AT_bit_size"; | |
8334 | case DW_AT_element_list: | |
8335 | return "DW_AT_element_list"; | |
8336 | case DW_AT_stmt_list: | |
8337 | return "DW_AT_stmt_list"; | |
8338 | case DW_AT_low_pc: | |
8339 | return "DW_AT_low_pc"; | |
8340 | case DW_AT_high_pc: | |
8341 | return "DW_AT_high_pc"; | |
8342 | case DW_AT_language: | |
8343 | return "DW_AT_language"; | |
8344 | case DW_AT_member: | |
8345 | return "DW_AT_member"; | |
8346 | case DW_AT_discr: | |
8347 | return "DW_AT_discr"; | |
8348 | case DW_AT_discr_value: | |
8349 | return "DW_AT_discr_value"; | |
8350 | case DW_AT_visibility: | |
8351 | return "DW_AT_visibility"; | |
8352 | case DW_AT_import: | |
8353 | return "DW_AT_import"; | |
8354 | case DW_AT_string_length: | |
8355 | return "DW_AT_string_length"; | |
8356 | case DW_AT_common_reference: | |
8357 | return "DW_AT_common_reference"; | |
8358 | case DW_AT_comp_dir: | |
8359 | return "DW_AT_comp_dir"; | |
8360 | case DW_AT_const_value: | |
8361 | return "DW_AT_const_value"; | |
8362 | case DW_AT_containing_type: | |
8363 | return "DW_AT_containing_type"; | |
8364 | case DW_AT_default_value: | |
8365 | return "DW_AT_default_value"; | |
8366 | case DW_AT_inline: | |
8367 | return "DW_AT_inline"; | |
8368 | case DW_AT_is_optional: | |
8369 | return "DW_AT_is_optional"; | |
8370 | case DW_AT_lower_bound: | |
8371 | return "DW_AT_lower_bound"; | |
8372 | case DW_AT_producer: | |
8373 | return "DW_AT_producer"; | |
8374 | case DW_AT_prototyped: | |
8375 | return "DW_AT_prototyped"; | |
8376 | case DW_AT_return_addr: | |
8377 | return "DW_AT_return_addr"; | |
8378 | case DW_AT_start_scope: | |
8379 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
8380 | case DW_AT_bit_stride: |
8381 | return "DW_AT_bit_stride"; | |
c906108c SS |
8382 | case DW_AT_upper_bound: |
8383 | return "DW_AT_upper_bound"; | |
8384 | case DW_AT_abstract_origin: | |
8385 | return "DW_AT_abstract_origin"; | |
8386 | case DW_AT_accessibility: | |
8387 | return "DW_AT_accessibility"; | |
8388 | case DW_AT_address_class: | |
8389 | return "DW_AT_address_class"; | |
8390 | case DW_AT_artificial: | |
8391 | return "DW_AT_artificial"; | |
8392 | case DW_AT_base_types: | |
8393 | return "DW_AT_base_types"; | |
8394 | case DW_AT_calling_convention: | |
8395 | return "DW_AT_calling_convention"; | |
8396 | case DW_AT_count: | |
8397 | return "DW_AT_count"; | |
8398 | case DW_AT_data_member_location: | |
8399 | return "DW_AT_data_member_location"; | |
8400 | case DW_AT_decl_column: | |
8401 | return "DW_AT_decl_column"; | |
8402 | case DW_AT_decl_file: | |
8403 | return "DW_AT_decl_file"; | |
8404 | case DW_AT_decl_line: | |
8405 | return "DW_AT_decl_line"; | |
8406 | case DW_AT_declaration: | |
8407 | return "DW_AT_declaration"; | |
8408 | case DW_AT_discr_list: | |
8409 | return "DW_AT_discr_list"; | |
8410 | case DW_AT_encoding: | |
8411 | return "DW_AT_encoding"; | |
8412 | case DW_AT_external: | |
8413 | return "DW_AT_external"; | |
8414 | case DW_AT_frame_base: | |
8415 | return "DW_AT_frame_base"; | |
8416 | case DW_AT_friend: | |
8417 | return "DW_AT_friend"; | |
8418 | case DW_AT_identifier_case: | |
8419 | return "DW_AT_identifier_case"; | |
8420 | case DW_AT_macro_info: | |
8421 | return "DW_AT_macro_info"; | |
8422 | case DW_AT_namelist_items: | |
8423 | return "DW_AT_namelist_items"; | |
8424 | case DW_AT_priority: | |
8425 | return "DW_AT_priority"; | |
8426 | case DW_AT_segment: | |
8427 | return "DW_AT_segment"; | |
8428 | case DW_AT_specification: | |
8429 | return "DW_AT_specification"; | |
8430 | case DW_AT_static_link: | |
8431 | return "DW_AT_static_link"; | |
8432 | case DW_AT_type: | |
8433 | return "DW_AT_type"; | |
8434 | case DW_AT_use_location: | |
8435 | return "DW_AT_use_location"; | |
8436 | case DW_AT_variable_parameter: | |
8437 | return "DW_AT_variable_parameter"; | |
8438 | case DW_AT_virtuality: | |
8439 | return "DW_AT_virtuality"; | |
8440 | case DW_AT_vtable_elem_location: | |
8441 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8442 | /* DWARF 3 values. */ |
d9fa45fe DC |
8443 | case DW_AT_allocated: |
8444 | return "DW_AT_allocated"; | |
8445 | case DW_AT_associated: | |
8446 | return "DW_AT_associated"; | |
8447 | case DW_AT_data_location: | |
8448 | return "DW_AT_data_location"; | |
09fa0d7c JK |
8449 | case DW_AT_byte_stride: |
8450 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
8451 | case DW_AT_entry_pc: |
8452 | return "DW_AT_entry_pc"; | |
8453 | case DW_AT_use_UTF8: | |
8454 | return "DW_AT_use_UTF8"; | |
8455 | case DW_AT_extension: | |
8456 | return "DW_AT_extension"; | |
8457 | case DW_AT_ranges: | |
8458 | return "DW_AT_ranges"; | |
8459 | case DW_AT_trampoline: | |
8460 | return "DW_AT_trampoline"; | |
8461 | case DW_AT_call_column: | |
8462 | return "DW_AT_call_column"; | |
8463 | case DW_AT_call_file: | |
8464 | return "DW_AT_call_file"; | |
8465 | case DW_AT_call_line: | |
8466 | return "DW_AT_call_line"; | |
b7619582 GF |
8467 | case DW_AT_description: |
8468 | return "DW_AT_description"; | |
8469 | case DW_AT_binary_scale: | |
8470 | return "DW_AT_binary_scale"; | |
8471 | case DW_AT_decimal_scale: | |
8472 | return "DW_AT_decimal_scale"; | |
8473 | case DW_AT_small: | |
8474 | return "DW_AT_small"; | |
8475 | case DW_AT_decimal_sign: | |
8476 | return "DW_AT_decimal_sign"; | |
8477 | case DW_AT_digit_count: | |
8478 | return "DW_AT_digit_count"; | |
8479 | case DW_AT_picture_string: | |
8480 | return "DW_AT_picture_string"; | |
8481 | case DW_AT_mutable: | |
8482 | return "DW_AT_mutable"; | |
8483 | case DW_AT_threads_scaled: | |
8484 | return "DW_AT_threads_scaled"; | |
8485 | case DW_AT_explicit: | |
8486 | return "DW_AT_explicit"; | |
8487 | case DW_AT_object_pointer: | |
8488 | return "DW_AT_object_pointer"; | |
8489 | case DW_AT_endianity: | |
8490 | return "DW_AT_endianity"; | |
8491 | case DW_AT_elemental: | |
8492 | return "DW_AT_elemental"; | |
8493 | case DW_AT_pure: | |
8494 | return "DW_AT_pure"; | |
8495 | case DW_AT_recursive: | |
8496 | return "DW_AT_recursive"; | |
b7619582 | 8497 | /* SGI/MIPS extensions. */ |
c764a876 | 8498 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
8499 | case DW_AT_MIPS_fde: |
8500 | return "DW_AT_MIPS_fde"; | |
c764a876 | 8501 | #endif |
c906108c SS |
8502 | case DW_AT_MIPS_loop_begin: |
8503 | return "DW_AT_MIPS_loop_begin"; | |
8504 | case DW_AT_MIPS_tail_loop_begin: | |
8505 | return "DW_AT_MIPS_tail_loop_begin"; | |
8506 | case DW_AT_MIPS_epilog_begin: | |
8507 | return "DW_AT_MIPS_epilog_begin"; | |
8508 | case DW_AT_MIPS_loop_unroll_factor: | |
8509 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8510 | case DW_AT_MIPS_software_pipeline_depth: | |
8511 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8512 | case DW_AT_MIPS_linkage_name: | |
8513 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8514 | case DW_AT_MIPS_stride: |
8515 | return "DW_AT_MIPS_stride"; | |
8516 | case DW_AT_MIPS_abstract_name: | |
8517 | return "DW_AT_MIPS_abstract_name"; | |
8518 | case DW_AT_MIPS_clone_origin: | |
8519 | return "DW_AT_MIPS_clone_origin"; | |
8520 | case DW_AT_MIPS_has_inlines: | |
8521 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 8522 | /* HP extensions. */ |
c764a876 | 8523 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
8524 | case DW_AT_HP_block_index: |
8525 | return "DW_AT_HP_block_index"; | |
c764a876 | 8526 | #endif |
b7619582 GF |
8527 | case DW_AT_HP_unmodifiable: |
8528 | return "DW_AT_HP_unmodifiable"; | |
8529 | case DW_AT_HP_actuals_stmt_list: | |
8530 | return "DW_AT_HP_actuals_stmt_list"; | |
8531 | case DW_AT_HP_proc_per_section: | |
8532 | return "DW_AT_HP_proc_per_section"; | |
8533 | case DW_AT_HP_raw_data_ptr: | |
8534 | return "DW_AT_HP_raw_data_ptr"; | |
8535 | case DW_AT_HP_pass_by_reference: | |
8536 | return "DW_AT_HP_pass_by_reference"; | |
8537 | case DW_AT_HP_opt_level: | |
8538 | return "DW_AT_HP_opt_level"; | |
8539 | case DW_AT_HP_prof_version_id: | |
8540 | return "DW_AT_HP_prof_version_id"; | |
8541 | case DW_AT_HP_opt_flags: | |
8542 | return "DW_AT_HP_opt_flags"; | |
8543 | case DW_AT_HP_cold_region_low_pc: | |
8544 | return "DW_AT_HP_cold_region_low_pc"; | |
8545 | case DW_AT_HP_cold_region_high_pc: | |
8546 | return "DW_AT_HP_cold_region_high_pc"; | |
8547 | case DW_AT_HP_all_variables_modifiable: | |
8548 | return "DW_AT_HP_all_variables_modifiable"; | |
8549 | case DW_AT_HP_linkage_name: | |
8550 | return "DW_AT_HP_linkage_name"; | |
8551 | case DW_AT_HP_prof_flags: | |
8552 | return "DW_AT_HP_prof_flags"; | |
8553 | /* GNU extensions. */ | |
c906108c SS |
8554 | case DW_AT_sf_names: |
8555 | return "DW_AT_sf_names"; | |
8556 | case DW_AT_src_info: | |
8557 | return "DW_AT_src_info"; | |
8558 | case DW_AT_mac_info: | |
8559 | return "DW_AT_mac_info"; | |
8560 | case DW_AT_src_coords: | |
8561 | return "DW_AT_src_coords"; | |
8562 | case DW_AT_body_begin: | |
8563 | return "DW_AT_body_begin"; | |
8564 | case DW_AT_body_end: | |
8565 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8566 | case DW_AT_GNU_vector: |
8567 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8568 | /* VMS extensions. */ |
8569 | case DW_AT_VMS_rtnbeg_pd_address: | |
8570 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8571 | /* UPC extension. */ | |
8572 | case DW_AT_upc_threads_scaled: | |
8573 | return "DW_AT_upc_threads_scaled"; | |
8574 | /* PGI (STMicroelectronics) extensions. */ | |
8575 | case DW_AT_PGI_lbase: | |
8576 | return "DW_AT_PGI_lbase"; | |
8577 | case DW_AT_PGI_soffset: | |
8578 | return "DW_AT_PGI_soffset"; | |
8579 | case DW_AT_PGI_lstride: | |
8580 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8581 | default: |
8582 | return "DW_AT_<unknown>"; | |
8583 | } | |
8584 | } | |
8585 | ||
8586 | /* Convert a DWARF value form code into its string name. */ | |
8587 | ||
8588 | static char * | |
aa1ee363 | 8589 | dwarf_form_name (unsigned form) |
c906108c SS |
8590 | { |
8591 | switch (form) | |
8592 | { | |
8593 | case DW_FORM_addr: | |
8594 | return "DW_FORM_addr"; | |
8595 | case DW_FORM_block2: | |
8596 | return "DW_FORM_block2"; | |
8597 | case DW_FORM_block4: | |
8598 | return "DW_FORM_block4"; | |
8599 | case DW_FORM_data2: | |
8600 | return "DW_FORM_data2"; | |
8601 | case DW_FORM_data4: | |
8602 | return "DW_FORM_data4"; | |
8603 | case DW_FORM_data8: | |
8604 | return "DW_FORM_data8"; | |
8605 | case DW_FORM_string: | |
8606 | return "DW_FORM_string"; | |
8607 | case DW_FORM_block: | |
8608 | return "DW_FORM_block"; | |
8609 | case DW_FORM_block1: | |
8610 | return "DW_FORM_block1"; | |
8611 | case DW_FORM_data1: | |
8612 | return "DW_FORM_data1"; | |
8613 | case DW_FORM_flag: | |
8614 | return "DW_FORM_flag"; | |
8615 | case DW_FORM_sdata: | |
8616 | return "DW_FORM_sdata"; | |
8617 | case DW_FORM_strp: | |
8618 | return "DW_FORM_strp"; | |
8619 | case DW_FORM_udata: | |
8620 | return "DW_FORM_udata"; | |
8621 | case DW_FORM_ref_addr: | |
8622 | return "DW_FORM_ref_addr"; | |
8623 | case DW_FORM_ref1: | |
8624 | return "DW_FORM_ref1"; | |
8625 | case DW_FORM_ref2: | |
8626 | return "DW_FORM_ref2"; | |
8627 | case DW_FORM_ref4: | |
8628 | return "DW_FORM_ref4"; | |
8629 | case DW_FORM_ref8: | |
8630 | return "DW_FORM_ref8"; | |
8631 | case DW_FORM_ref_udata: | |
8632 | return "DW_FORM_ref_udata"; | |
8633 | case DW_FORM_indirect: | |
8634 | return "DW_FORM_indirect"; | |
8635 | default: | |
8636 | return "DW_FORM_<unknown>"; | |
8637 | } | |
8638 | } | |
8639 | ||
8640 | /* Convert a DWARF stack opcode into its string name. */ | |
8641 | ||
8642 | static char * | |
aa1ee363 | 8643 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8644 | { |
8645 | switch (op) | |
8646 | { | |
8647 | case DW_OP_addr: | |
8648 | return "DW_OP_addr"; | |
8649 | case DW_OP_deref: | |
8650 | return "DW_OP_deref"; | |
8651 | case DW_OP_const1u: | |
8652 | return "DW_OP_const1u"; | |
8653 | case DW_OP_const1s: | |
8654 | return "DW_OP_const1s"; | |
8655 | case DW_OP_const2u: | |
8656 | return "DW_OP_const2u"; | |
8657 | case DW_OP_const2s: | |
8658 | return "DW_OP_const2s"; | |
8659 | case DW_OP_const4u: | |
8660 | return "DW_OP_const4u"; | |
8661 | case DW_OP_const4s: | |
8662 | return "DW_OP_const4s"; | |
8663 | case DW_OP_const8u: | |
8664 | return "DW_OP_const8u"; | |
8665 | case DW_OP_const8s: | |
8666 | return "DW_OP_const8s"; | |
8667 | case DW_OP_constu: | |
8668 | return "DW_OP_constu"; | |
8669 | case DW_OP_consts: | |
8670 | return "DW_OP_consts"; | |
8671 | case DW_OP_dup: | |
8672 | return "DW_OP_dup"; | |
8673 | case DW_OP_drop: | |
8674 | return "DW_OP_drop"; | |
8675 | case DW_OP_over: | |
8676 | return "DW_OP_over"; | |
8677 | case DW_OP_pick: | |
8678 | return "DW_OP_pick"; | |
8679 | case DW_OP_swap: | |
8680 | return "DW_OP_swap"; | |
8681 | case DW_OP_rot: | |
8682 | return "DW_OP_rot"; | |
8683 | case DW_OP_xderef: | |
8684 | return "DW_OP_xderef"; | |
8685 | case DW_OP_abs: | |
8686 | return "DW_OP_abs"; | |
8687 | case DW_OP_and: | |
8688 | return "DW_OP_and"; | |
8689 | case DW_OP_div: | |
8690 | return "DW_OP_div"; | |
8691 | case DW_OP_minus: | |
8692 | return "DW_OP_minus"; | |
8693 | case DW_OP_mod: | |
8694 | return "DW_OP_mod"; | |
8695 | case DW_OP_mul: | |
8696 | return "DW_OP_mul"; | |
8697 | case DW_OP_neg: | |
8698 | return "DW_OP_neg"; | |
8699 | case DW_OP_not: | |
8700 | return "DW_OP_not"; | |
8701 | case DW_OP_or: | |
8702 | return "DW_OP_or"; | |
8703 | case DW_OP_plus: | |
8704 | return "DW_OP_plus"; | |
8705 | case DW_OP_plus_uconst: | |
8706 | return "DW_OP_plus_uconst"; | |
8707 | case DW_OP_shl: | |
8708 | return "DW_OP_shl"; | |
8709 | case DW_OP_shr: | |
8710 | return "DW_OP_shr"; | |
8711 | case DW_OP_shra: | |
8712 | return "DW_OP_shra"; | |
8713 | case DW_OP_xor: | |
8714 | return "DW_OP_xor"; | |
8715 | case DW_OP_bra: | |
8716 | return "DW_OP_bra"; | |
8717 | case DW_OP_eq: | |
8718 | return "DW_OP_eq"; | |
8719 | case DW_OP_ge: | |
8720 | return "DW_OP_ge"; | |
8721 | case DW_OP_gt: | |
8722 | return "DW_OP_gt"; | |
8723 | case DW_OP_le: | |
8724 | return "DW_OP_le"; | |
8725 | case DW_OP_lt: | |
8726 | return "DW_OP_lt"; | |
8727 | case DW_OP_ne: | |
8728 | return "DW_OP_ne"; | |
8729 | case DW_OP_skip: | |
8730 | return "DW_OP_skip"; | |
8731 | case DW_OP_lit0: | |
8732 | return "DW_OP_lit0"; | |
8733 | case DW_OP_lit1: | |
8734 | return "DW_OP_lit1"; | |
8735 | case DW_OP_lit2: | |
8736 | return "DW_OP_lit2"; | |
8737 | case DW_OP_lit3: | |
8738 | return "DW_OP_lit3"; | |
8739 | case DW_OP_lit4: | |
8740 | return "DW_OP_lit4"; | |
8741 | case DW_OP_lit5: | |
8742 | return "DW_OP_lit5"; | |
8743 | case DW_OP_lit6: | |
8744 | return "DW_OP_lit6"; | |
8745 | case DW_OP_lit7: | |
8746 | return "DW_OP_lit7"; | |
8747 | case DW_OP_lit8: | |
8748 | return "DW_OP_lit8"; | |
8749 | case DW_OP_lit9: | |
8750 | return "DW_OP_lit9"; | |
8751 | case DW_OP_lit10: | |
8752 | return "DW_OP_lit10"; | |
8753 | case DW_OP_lit11: | |
8754 | return "DW_OP_lit11"; | |
8755 | case DW_OP_lit12: | |
8756 | return "DW_OP_lit12"; | |
8757 | case DW_OP_lit13: | |
8758 | return "DW_OP_lit13"; | |
8759 | case DW_OP_lit14: | |
8760 | return "DW_OP_lit14"; | |
8761 | case DW_OP_lit15: | |
8762 | return "DW_OP_lit15"; | |
8763 | case DW_OP_lit16: | |
8764 | return "DW_OP_lit16"; | |
8765 | case DW_OP_lit17: | |
8766 | return "DW_OP_lit17"; | |
8767 | case DW_OP_lit18: | |
8768 | return "DW_OP_lit18"; | |
8769 | case DW_OP_lit19: | |
8770 | return "DW_OP_lit19"; | |
8771 | case DW_OP_lit20: | |
8772 | return "DW_OP_lit20"; | |
8773 | case DW_OP_lit21: | |
8774 | return "DW_OP_lit21"; | |
8775 | case DW_OP_lit22: | |
8776 | return "DW_OP_lit22"; | |
8777 | case DW_OP_lit23: | |
8778 | return "DW_OP_lit23"; | |
8779 | case DW_OP_lit24: | |
8780 | return "DW_OP_lit24"; | |
8781 | case DW_OP_lit25: | |
8782 | return "DW_OP_lit25"; | |
8783 | case DW_OP_lit26: | |
8784 | return "DW_OP_lit26"; | |
8785 | case DW_OP_lit27: | |
8786 | return "DW_OP_lit27"; | |
8787 | case DW_OP_lit28: | |
8788 | return "DW_OP_lit28"; | |
8789 | case DW_OP_lit29: | |
8790 | return "DW_OP_lit29"; | |
8791 | case DW_OP_lit30: | |
8792 | return "DW_OP_lit30"; | |
8793 | case DW_OP_lit31: | |
8794 | return "DW_OP_lit31"; | |
8795 | case DW_OP_reg0: | |
8796 | return "DW_OP_reg0"; | |
8797 | case DW_OP_reg1: | |
8798 | return "DW_OP_reg1"; | |
8799 | case DW_OP_reg2: | |
8800 | return "DW_OP_reg2"; | |
8801 | case DW_OP_reg3: | |
8802 | return "DW_OP_reg3"; | |
8803 | case DW_OP_reg4: | |
8804 | return "DW_OP_reg4"; | |
8805 | case DW_OP_reg5: | |
8806 | return "DW_OP_reg5"; | |
8807 | case DW_OP_reg6: | |
8808 | return "DW_OP_reg6"; | |
8809 | case DW_OP_reg7: | |
8810 | return "DW_OP_reg7"; | |
8811 | case DW_OP_reg8: | |
8812 | return "DW_OP_reg8"; | |
8813 | case DW_OP_reg9: | |
8814 | return "DW_OP_reg9"; | |
8815 | case DW_OP_reg10: | |
8816 | return "DW_OP_reg10"; | |
8817 | case DW_OP_reg11: | |
8818 | return "DW_OP_reg11"; | |
8819 | case DW_OP_reg12: | |
8820 | return "DW_OP_reg12"; | |
8821 | case DW_OP_reg13: | |
8822 | return "DW_OP_reg13"; | |
8823 | case DW_OP_reg14: | |
8824 | return "DW_OP_reg14"; | |
8825 | case DW_OP_reg15: | |
8826 | return "DW_OP_reg15"; | |
8827 | case DW_OP_reg16: | |
8828 | return "DW_OP_reg16"; | |
8829 | case DW_OP_reg17: | |
8830 | return "DW_OP_reg17"; | |
8831 | case DW_OP_reg18: | |
8832 | return "DW_OP_reg18"; | |
8833 | case DW_OP_reg19: | |
8834 | return "DW_OP_reg19"; | |
8835 | case DW_OP_reg20: | |
8836 | return "DW_OP_reg20"; | |
8837 | case DW_OP_reg21: | |
8838 | return "DW_OP_reg21"; | |
8839 | case DW_OP_reg22: | |
8840 | return "DW_OP_reg22"; | |
8841 | case DW_OP_reg23: | |
8842 | return "DW_OP_reg23"; | |
8843 | case DW_OP_reg24: | |
8844 | return "DW_OP_reg24"; | |
8845 | case DW_OP_reg25: | |
8846 | return "DW_OP_reg25"; | |
8847 | case DW_OP_reg26: | |
8848 | return "DW_OP_reg26"; | |
8849 | case DW_OP_reg27: | |
8850 | return "DW_OP_reg27"; | |
8851 | case DW_OP_reg28: | |
8852 | return "DW_OP_reg28"; | |
8853 | case DW_OP_reg29: | |
8854 | return "DW_OP_reg29"; | |
8855 | case DW_OP_reg30: | |
8856 | return "DW_OP_reg30"; | |
8857 | case DW_OP_reg31: | |
8858 | return "DW_OP_reg31"; | |
8859 | case DW_OP_breg0: | |
8860 | return "DW_OP_breg0"; | |
8861 | case DW_OP_breg1: | |
8862 | return "DW_OP_breg1"; | |
8863 | case DW_OP_breg2: | |
8864 | return "DW_OP_breg2"; | |
8865 | case DW_OP_breg3: | |
8866 | return "DW_OP_breg3"; | |
8867 | case DW_OP_breg4: | |
8868 | return "DW_OP_breg4"; | |
8869 | case DW_OP_breg5: | |
8870 | return "DW_OP_breg5"; | |
8871 | case DW_OP_breg6: | |
8872 | return "DW_OP_breg6"; | |
8873 | case DW_OP_breg7: | |
8874 | return "DW_OP_breg7"; | |
8875 | case DW_OP_breg8: | |
8876 | return "DW_OP_breg8"; | |
8877 | case DW_OP_breg9: | |
8878 | return "DW_OP_breg9"; | |
8879 | case DW_OP_breg10: | |
8880 | return "DW_OP_breg10"; | |
8881 | case DW_OP_breg11: | |
8882 | return "DW_OP_breg11"; | |
8883 | case DW_OP_breg12: | |
8884 | return "DW_OP_breg12"; | |
8885 | case DW_OP_breg13: | |
8886 | return "DW_OP_breg13"; | |
8887 | case DW_OP_breg14: | |
8888 | return "DW_OP_breg14"; | |
8889 | case DW_OP_breg15: | |
8890 | return "DW_OP_breg15"; | |
8891 | case DW_OP_breg16: | |
8892 | return "DW_OP_breg16"; | |
8893 | case DW_OP_breg17: | |
8894 | return "DW_OP_breg17"; | |
8895 | case DW_OP_breg18: | |
8896 | return "DW_OP_breg18"; | |
8897 | case DW_OP_breg19: | |
8898 | return "DW_OP_breg19"; | |
8899 | case DW_OP_breg20: | |
8900 | return "DW_OP_breg20"; | |
8901 | case DW_OP_breg21: | |
8902 | return "DW_OP_breg21"; | |
8903 | case DW_OP_breg22: | |
8904 | return "DW_OP_breg22"; | |
8905 | case DW_OP_breg23: | |
8906 | return "DW_OP_breg23"; | |
8907 | case DW_OP_breg24: | |
8908 | return "DW_OP_breg24"; | |
8909 | case DW_OP_breg25: | |
8910 | return "DW_OP_breg25"; | |
8911 | case DW_OP_breg26: | |
8912 | return "DW_OP_breg26"; | |
8913 | case DW_OP_breg27: | |
8914 | return "DW_OP_breg27"; | |
8915 | case DW_OP_breg28: | |
8916 | return "DW_OP_breg28"; | |
8917 | case DW_OP_breg29: | |
8918 | return "DW_OP_breg29"; | |
8919 | case DW_OP_breg30: | |
8920 | return "DW_OP_breg30"; | |
8921 | case DW_OP_breg31: | |
8922 | return "DW_OP_breg31"; | |
8923 | case DW_OP_regx: | |
8924 | return "DW_OP_regx"; | |
8925 | case DW_OP_fbreg: | |
8926 | return "DW_OP_fbreg"; | |
8927 | case DW_OP_bregx: | |
8928 | return "DW_OP_bregx"; | |
8929 | case DW_OP_piece: | |
8930 | return "DW_OP_piece"; | |
8931 | case DW_OP_deref_size: | |
8932 | return "DW_OP_deref_size"; | |
8933 | case DW_OP_xderef_size: | |
8934 | return "DW_OP_xderef_size"; | |
8935 | case DW_OP_nop: | |
8936 | return "DW_OP_nop"; | |
b7619582 | 8937 | /* DWARF 3 extensions. */ |
ed348acc EZ |
8938 | case DW_OP_push_object_address: |
8939 | return "DW_OP_push_object_address"; | |
8940 | case DW_OP_call2: | |
8941 | return "DW_OP_call2"; | |
8942 | case DW_OP_call4: | |
8943 | return "DW_OP_call4"; | |
8944 | case DW_OP_call_ref: | |
8945 | return "DW_OP_call_ref"; | |
b7619582 GF |
8946 | /* GNU extensions. */ |
8947 | case DW_OP_form_tls_address: | |
8948 | return "DW_OP_form_tls_address"; | |
8949 | case DW_OP_call_frame_cfa: | |
8950 | return "DW_OP_call_frame_cfa"; | |
8951 | case DW_OP_bit_piece: | |
8952 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
8953 | case DW_OP_GNU_push_tls_address: |
8954 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
8955 | case DW_OP_GNU_uninit: |
8956 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
8957 | /* HP extensions. */ |
8958 | case DW_OP_HP_is_value: | |
8959 | return "DW_OP_HP_is_value"; | |
8960 | case DW_OP_HP_fltconst4: | |
8961 | return "DW_OP_HP_fltconst4"; | |
8962 | case DW_OP_HP_fltconst8: | |
8963 | return "DW_OP_HP_fltconst8"; | |
8964 | case DW_OP_HP_mod_range: | |
8965 | return "DW_OP_HP_mod_range"; | |
8966 | case DW_OP_HP_unmod_range: | |
8967 | return "DW_OP_HP_unmod_range"; | |
8968 | case DW_OP_HP_tls: | |
8969 | return "DW_OP_HP_tls"; | |
c906108c SS |
8970 | default: |
8971 | return "OP_<unknown>"; | |
8972 | } | |
8973 | } | |
8974 | ||
8975 | static char * | |
fba45db2 | 8976 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
8977 | { |
8978 | if (mybool) | |
8979 | return "TRUE"; | |
8980 | else | |
8981 | return "FALSE"; | |
8982 | } | |
8983 | ||
8984 | /* Convert a DWARF type code into its string name. */ | |
8985 | ||
8986 | static char * | |
aa1ee363 | 8987 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
8988 | { |
8989 | switch (enc) | |
8990 | { | |
b7619582 GF |
8991 | case DW_ATE_void: |
8992 | return "DW_ATE_void"; | |
c906108c SS |
8993 | case DW_ATE_address: |
8994 | return "DW_ATE_address"; | |
8995 | case DW_ATE_boolean: | |
8996 | return "DW_ATE_boolean"; | |
8997 | case DW_ATE_complex_float: | |
8998 | return "DW_ATE_complex_float"; | |
8999 | case DW_ATE_float: | |
9000 | return "DW_ATE_float"; | |
9001 | case DW_ATE_signed: | |
9002 | return "DW_ATE_signed"; | |
9003 | case DW_ATE_signed_char: | |
9004 | return "DW_ATE_signed_char"; | |
9005 | case DW_ATE_unsigned: | |
9006 | return "DW_ATE_unsigned"; | |
9007 | case DW_ATE_unsigned_char: | |
9008 | return "DW_ATE_unsigned_char"; | |
b7619582 | 9009 | /* DWARF 3. */ |
d9fa45fe DC |
9010 | case DW_ATE_imaginary_float: |
9011 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
9012 | case DW_ATE_packed_decimal: |
9013 | return "DW_ATE_packed_decimal"; | |
9014 | case DW_ATE_numeric_string: | |
9015 | return "DW_ATE_numeric_string"; | |
9016 | case DW_ATE_edited: | |
9017 | return "DW_ATE_edited"; | |
9018 | case DW_ATE_signed_fixed: | |
9019 | return "DW_ATE_signed_fixed"; | |
9020 | case DW_ATE_unsigned_fixed: | |
9021 | return "DW_ATE_unsigned_fixed"; | |
9022 | case DW_ATE_decimal_float: | |
9023 | return "DW_ATE_decimal_float"; | |
9024 | /* HP extensions. */ | |
9025 | case DW_ATE_HP_float80: | |
9026 | return "DW_ATE_HP_float80"; | |
9027 | case DW_ATE_HP_complex_float80: | |
9028 | return "DW_ATE_HP_complex_float80"; | |
9029 | case DW_ATE_HP_float128: | |
9030 | return "DW_ATE_HP_float128"; | |
9031 | case DW_ATE_HP_complex_float128: | |
9032 | return "DW_ATE_HP_complex_float128"; | |
9033 | case DW_ATE_HP_floathpintel: | |
9034 | return "DW_ATE_HP_floathpintel"; | |
9035 | case DW_ATE_HP_imaginary_float80: | |
9036 | return "DW_ATE_HP_imaginary_float80"; | |
9037 | case DW_ATE_HP_imaginary_float128: | |
9038 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
9039 | default: |
9040 | return "DW_ATE_<unknown>"; | |
9041 | } | |
9042 | } | |
9043 | ||
9044 | /* Convert a DWARF call frame info operation to its string name. */ | |
9045 | ||
9046 | #if 0 | |
9047 | static char * | |
aa1ee363 | 9048 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
9049 | { |
9050 | switch (cfi_opc) | |
9051 | { | |
9052 | case DW_CFA_advance_loc: | |
9053 | return "DW_CFA_advance_loc"; | |
9054 | case DW_CFA_offset: | |
9055 | return "DW_CFA_offset"; | |
9056 | case DW_CFA_restore: | |
9057 | return "DW_CFA_restore"; | |
9058 | case DW_CFA_nop: | |
9059 | return "DW_CFA_nop"; | |
9060 | case DW_CFA_set_loc: | |
9061 | return "DW_CFA_set_loc"; | |
9062 | case DW_CFA_advance_loc1: | |
9063 | return "DW_CFA_advance_loc1"; | |
9064 | case DW_CFA_advance_loc2: | |
9065 | return "DW_CFA_advance_loc2"; | |
9066 | case DW_CFA_advance_loc4: | |
9067 | return "DW_CFA_advance_loc4"; | |
9068 | case DW_CFA_offset_extended: | |
9069 | return "DW_CFA_offset_extended"; | |
9070 | case DW_CFA_restore_extended: | |
9071 | return "DW_CFA_restore_extended"; | |
9072 | case DW_CFA_undefined: | |
9073 | return "DW_CFA_undefined"; | |
9074 | case DW_CFA_same_value: | |
9075 | return "DW_CFA_same_value"; | |
9076 | case DW_CFA_register: | |
9077 | return "DW_CFA_register"; | |
9078 | case DW_CFA_remember_state: | |
9079 | return "DW_CFA_remember_state"; | |
9080 | case DW_CFA_restore_state: | |
9081 | return "DW_CFA_restore_state"; | |
9082 | case DW_CFA_def_cfa: | |
9083 | return "DW_CFA_def_cfa"; | |
9084 | case DW_CFA_def_cfa_register: | |
9085 | return "DW_CFA_def_cfa_register"; | |
9086 | case DW_CFA_def_cfa_offset: | |
9087 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 9088 | /* DWARF 3. */ |
985cb1a3 JM |
9089 | case DW_CFA_def_cfa_expression: |
9090 | return "DW_CFA_def_cfa_expression"; | |
9091 | case DW_CFA_expression: | |
9092 | return "DW_CFA_expression"; | |
9093 | case DW_CFA_offset_extended_sf: | |
9094 | return "DW_CFA_offset_extended_sf"; | |
9095 | case DW_CFA_def_cfa_sf: | |
9096 | return "DW_CFA_def_cfa_sf"; | |
9097 | case DW_CFA_def_cfa_offset_sf: | |
9098 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
9099 | case DW_CFA_val_offset: |
9100 | return "DW_CFA_val_offset"; | |
9101 | case DW_CFA_val_offset_sf: | |
9102 | return "DW_CFA_val_offset_sf"; | |
9103 | case DW_CFA_val_expression: | |
9104 | return "DW_CFA_val_expression"; | |
9105 | /* SGI/MIPS specific. */ | |
c906108c SS |
9106 | case DW_CFA_MIPS_advance_loc8: |
9107 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 9108 | /* GNU extensions. */ |
985cb1a3 JM |
9109 | case DW_CFA_GNU_window_save: |
9110 | return "DW_CFA_GNU_window_save"; | |
9111 | case DW_CFA_GNU_args_size: | |
9112 | return "DW_CFA_GNU_args_size"; | |
9113 | case DW_CFA_GNU_negative_offset_extended: | |
9114 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
9115 | default: |
9116 | return "DW_CFA_<unknown>"; | |
9117 | } | |
9118 | } | |
9119 | #endif | |
9120 | ||
f9aca02d | 9121 | static void |
d97bc12b | 9122 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
9123 | { |
9124 | unsigned int i; | |
9125 | ||
d97bc12b DE |
9126 | print_spaces (indent, f); |
9127 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 9128 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
9129 | |
9130 | if (die->parent != NULL) | |
9131 | { | |
9132 | print_spaces (indent, f); | |
9133 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
9134 | die->parent->offset); | |
9135 | } | |
9136 | ||
9137 | print_spaces (indent, f); | |
9138 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 9139 | dwarf_bool_name (die->child != NULL)); |
c906108c | 9140 | |
d97bc12b DE |
9141 | print_spaces (indent, f); |
9142 | fprintf_unfiltered (f, " attributes:\n"); | |
9143 | ||
c906108c SS |
9144 | for (i = 0; i < die->num_attrs; ++i) |
9145 | { | |
d97bc12b DE |
9146 | print_spaces (indent, f); |
9147 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
9148 | dwarf_attr_name (die->attrs[i].name), |
9149 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 9150 | |
c906108c SS |
9151 | switch (die->attrs[i].form) |
9152 | { | |
9153 | case DW_FORM_ref_addr: | |
9154 | case DW_FORM_addr: | |
d97bc12b DE |
9155 | fprintf_unfiltered (f, "address: "); |
9156 | fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), f); | |
c906108c SS |
9157 | break; |
9158 | case DW_FORM_block2: | |
9159 | case DW_FORM_block4: | |
9160 | case DW_FORM_block: | |
9161 | case DW_FORM_block1: | |
d97bc12b | 9162 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 9163 | break; |
10b3939b DJ |
9164 | case DW_FORM_ref1: |
9165 | case DW_FORM_ref2: | |
9166 | case DW_FORM_ref4: | |
d97bc12b | 9167 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
9168 | (long) (DW_ADDR (&die->attrs[i]))); |
9169 | break; | |
c906108c SS |
9170 | case DW_FORM_data1: |
9171 | case DW_FORM_data2: | |
9172 | case DW_FORM_data4: | |
ce5d95e1 | 9173 | case DW_FORM_data8: |
c906108c SS |
9174 | case DW_FORM_udata: |
9175 | case DW_FORM_sdata: | |
d97bc12b | 9176 | fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
9177 | break; |
9178 | case DW_FORM_string: | |
4bdf3d34 | 9179 | case DW_FORM_strp: |
d97bc12b | 9180 | fprintf_unfiltered (f, "string: \"%s\"", |
c906108c | 9181 | DW_STRING (&die->attrs[i]) |
c5aa993b | 9182 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
9183 | break; |
9184 | case DW_FORM_flag: | |
9185 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 9186 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 9187 | else |
d97bc12b | 9188 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 9189 | break; |
a8329558 KW |
9190 | case DW_FORM_indirect: |
9191 | /* the reader will have reduced the indirect form to | |
9192 | the "base form" so this form should not occur */ | |
d97bc12b | 9193 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 9194 | break; |
c906108c | 9195 | default: |
d97bc12b | 9196 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 9197 | die->attrs[i].form); |
d97bc12b | 9198 | break; |
c906108c | 9199 | } |
d97bc12b | 9200 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
9201 | } |
9202 | } | |
9203 | ||
f9aca02d | 9204 | static void |
d97bc12b | 9205 | dump_die_for_error (struct die_info *die) |
c906108c | 9206 | { |
d97bc12b DE |
9207 | dump_die_shallow (gdb_stderr, 0, die); |
9208 | } | |
9209 | ||
9210 | static void | |
9211 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
9212 | { | |
9213 | int indent = level * 4; | |
9214 | ||
9215 | gdb_assert (die != NULL); | |
9216 | ||
9217 | if (level >= max_level) | |
9218 | return; | |
9219 | ||
9220 | dump_die_shallow (f, indent, die); | |
9221 | ||
9222 | if (die->child != NULL) | |
c906108c | 9223 | { |
d97bc12b DE |
9224 | print_spaces (indent, f); |
9225 | fprintf_unfiltered (f, " Children:"); | |
9226 | if (level + 1 < max_level) | |
9227 | { | |
9228 | fprintf_unfiltered (f, "\n"); | |
9229 | dump_die_1 (f, level + 1, max_level, die->child); | |
9230 | } | |
9231 | else | |
9232 | { | |
9233 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
9234 | } | |
9235 | } | |
9236 | ||
9237 | if (die->sibling != NULL && level > 0) | |
9238 | { | |
9239 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
9240 | } |
9241 | } | |
9242 | ||
d97bc12b DE |
9243 | /* This is called from the pdie macro in gdbinit.in. |
9244 | It's not static so gcc will keep a copy callable from gdb. */ | |
9245 | ||
9246 | void | |
9247 | dump_die (struct die_info *die, int max_level) | |
9248 | { | |
9249 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
9250 | } | |
9251 | ||
f9aca02d | 9252 | static void |
51545339 | 9253 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9254 | { |
51545339 | 9255 | void **slot; |
c906108c | 9256 | |
51545339 DJ |
9257 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
9258 | ||
9259 | *slot = die; | |
c906108c SS |
9260 | } |
9261 | ||
9262 | static unsigned int | |
c764a876 | 9263 | dwarf2_get_ref_die_offset (struct attribute *attr) |
c906108c SS |
9264 | { |
9265 | unsigned int result = 0; | |
9266 | ||
9267 | switch (attr->form) | |
9268 | { | |
9269 | case DW_FORM_ref_addr: | |
c906108c SS |
9270 | case DW_FORM_ref1: |
9271 | case DW_FORM_ref2: | |
9272 | case DW_FORM_ref4: | |
613e1657 | 9273 | case DW_FORM_ref8: |
c906108c | 9274 | case DW_FORM_ref_udata: |
10b3939b | 9275 | result = DW_ADDR (attr); |
c906108c SS |
9276 | break; |
9277 | default: | |
4d3c2250 | 9278 | complaint (&symfile_complaints, |
e2e0b3e5 | 9279 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 9280 | dwarf_form_name (attr->form)); |
c906108c SS |
9281 | } |
9282 | return result; | |
9283 | } | |
9284 | ||
a02abb62 JB |
9285 | /* Return the constant value held by the given attribute. Return -1 |
9286 | if the value held by the attribute is not constant. */ | |
9287 | ||
9288 | static int | |
9289 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
9290 | { | |
9291 | if (attr->form == DW_FORM_sdata) | |
9292 | return DW_SND (attr); | |
9293 | else if (attr->form == DW_FORM_udata | |
9294 | || attr->form == DW_FORM_data1 | |
9295 | || attr->form == DW_FORM_data2 | |
9296 | || attr->form == DW_FORM_data4 | |
9297 | || attr->form == DW_FORM_data8) | |
9298 | return DW_UNSND (attr); | |
9299 | else | |
9300 | { | |
e2e0b3e5 | 9301 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
9302 | dwarf_form_name (attr->form)); |
9303 | return default_value; | |
9304 | } | |
9305 | } | |
9306 | ||
03dd20cc DJ |
9307 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
9308 | unit and add it to our queue. */ | |
9309 | ||
9310 | static void | |
9311 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
9312 | struct dwarf2_per_cu_data *per_cu) | |
9313 | { | |
9314 | /* Mark the dependence relation so that we don't flush PER_CU | |
9315 | too early. */ | |
9316 | dwarf2_add_dependence (this_cu, per_cu); | |
9317 | ||
9318 | /* If it's already on the queue, we have nothing to do. */ | |
9319 | if (per_cu->queued) | |
9320 | return; | |
9321 | ||
9322 | /* If the compilation unit is already loaded, just mark it as | |
9323 | used. */ | |
9324 | if (per_cu->cu != NULL) | |
9325 | { | |
9326 | per_cu->cu->last_used = 0; | |
9327 | return; | |
9328 | } | |
9329 | ||
9330 | /* Add it to the queue. */ | |
9331 | queue_comp_unit (per_cu, this_cu->objfile); | |
9332 | } | |
9333 | ||
f9aca02d | 9334 | static struct die_info * |
10b3939b | 9335 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 9336 | struct dwarf2_cu **ref_cu) |
c906108c SS |
9337 | { |
9338 | struct die_info *die; | |
10b3939b | 9339 | unsigned int offset; |
10b3939b | 9340 | struct die_info temp_die; |
f2f0e013 | 9341 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 9342 | |
c764a876 | 9343 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 9344 | |
45452591 | 9345 | if (! offset_in_cu_p (&cu->header, offset)) |
10b3939b DJ |
9346 | { |
9347 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 9348 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
9349 | |
9350 | /* If necessary, add it to the queue and load its DIEs. */ | |
9351 | maybe_queue_comp_unit (cu, per_cu); | |
9352 | ||
10b3939b DJ |
9353 | target_cu = per_cu->cu; |
9354 | } | |
9355 | else | |
9356 | target_cu = cu; | |
c906108c | 9357 | |
f2f0e013 | 9358 | *ref_cu = target_cu; |
51545339 DJ |
9359 | temp_die.offset = offset; |
9360 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
9361 | if (die) | |
9362 | return die; | |
10b3939b | 9363 | |
8a3fe4f8 AC |
9364 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
9365 | "at 0x%lx [in module %s]"), | |
1d325ec1 | 9366 | (long) offset, (long) src_die->offset, cu->objfile->name); |
c906108c SS |
9367 | } |
9368 | ||
c906108c SS |
9369 | /* Decode simple location descriptions. |
9370 | Given a pointer to a dwarf block that defines a location, compute | |
9371 | the location and return the value. | |
9372 | ||
4cecd739 DJ |
9373 | NOTE drow/2003-11-18: This function is called in two situations |
9374 | now: for the address of static or global variables (partial symbols | |
9375 | only) and for offsets into structures which are expected to be | |
9376 | (more or less) constant. The partial symbol case should go away, | |
9377 | and only the constant case should remain. That will let this | |
9378 | function complain more accurately. A few special modes are allowed | |
9379 | without complaint for global variables (for instance, global | |
9380 | register values and thread-local values). | |
c906108c SS |
9381 | |
9382 | A location description containing no operations indicates that the | |
4cecd739 | 9383 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
9384 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
9385 | callers will only want a very basic result and this can become a | |
9386 | complaint. | |
c906108c | 9387 | |
c906108c SS |
9388 | Note that stack[0] is unused except as a default error return. |
9389 | Note that stack overflow is not yet handled. */ | |
9390 | ||
9391 | static CORE_ADDR | |
e7c27a73 | 9392 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 9393 | { |
e7c27a73 DJ |
9394 | struct objfile *objfile = cu->objfile; |
9395 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
9396 | int i; |
9397 | int size = blk->size; | |
fe1b8b76 | 9398 | gdb_byte *data = blk->data; |
c906108c SS |
9399 | CORE_ADDR stack[64]; |
9400 | int stacki; | |
9401 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 9402 | gdb_byte op; |
c906108c SS |
9403 | |
9404 | i = 0; | |
9405 | stacki = 0; | |
9406 | stack[stacki] = 0; | |
c906108c SS |
9407 | |
9408 | while (i < size) | |
9409 | { | |
c906108c SS |
9410 | op = data[i++]; |
9411 | switch (op) | |
9412 | { | |
f1bea926 JM |
9413 | case DW_OP_lit0: |
9414 | case DW_OP_lit1: | |
9415 | case DW_OP_lit2: | |
9416 | case DW_OP_lit3: | |
9417 | case DW_OP_lit4: | |
9418 | case DW_OP_lit5: | |
9419 | case DW_OP_lit6: | |
9420 | case DW_OP_lit7: | |
9421 | case DW_OP_lit8: | |
9422 | case DW_OP_lit9: | |
9423 | case DW_OP_lit10: | |
9424 | case DW_OP_lit11: | |
9425 | case DW_OP_lit12: | |
9426 | case DW_OP_lit13: | |
9427 | case DW_OP_lit14: | |
9428 | case DW_OP_lit15: | |
9429 | case DW_OP_lit16: | |
9430 | case DW_OP_lit17: | |
9431 | case DW_OP_lit18: | |
9432 | case DW_OP_lit19: | |
9433 | case DW_OP_lit20: | |
9434 | case DW_OP_lit21: | |
9435 | case DW_OP_lit22: | |
9436 | case DW_OP_lit23: | |
9437 | case DW_OP_lit24: | |
9438 | case DW_OP_lit25: | |
9439 | case DW_OP_lit26: | |
9440 | case DW_OP_lit27: | |
9441 | case DW_OP_lit28: | |
9442 | case DW_OP_lit29: | |
9443 | case DW_OP_lit30: | |
9444 | case DW_OP_lit31: | |
9445 | stack[++stacki] = op - DW_OP_lit0; | |
9446 | break; | |
9447 | ||
c906108c SS |
9448 | case DW_OP_reg0: |
9449 | case DW_OP_reg1: | |
9450 | case DW_OP_reg2: | |
9451 | case DW_OP_reg3: | |
9452 | case DW_OP_reg4: | |
9453 | case DW_OP_reg5: | |
9454 | case DW_OP_reg6: | |
9455 | case DW_OP_reg7: | |
9456 | case DW_OP_reg8: | |
9457 | case DW_OP_reg9: | |
9458 | case DW_OP_reg10: | |
9459 | case DW_OP_reg11: | |
9460 | case DW_OP_reg12: | |
9461 | case DW_OP_reg13: | |
9462 | case DW_OP_reg14: | |
9463 | case DW_OP_reg15: | |
9464 | case DW_OP_reg16: | |
9465 | case DW_OP_reg17: | |
9466 | case DW_OP_reg18: | |
9467 | case DW_OP_reg19: | |
9468 | case DW_OP_reg20: | |
9469 | case DW_OP_reg21: | |
9470 | case DW_OP_reg22: | |
9471 | case DW_OP_reg23: | |
9472 | case DW_OP_reg24: | |
9473 | case DW_OP_reg25: | |
9474 | case DW_OP_reg26: | |
9475 | case DW_OP_reg27: | |
9476 | case DW_OP_reg28: | |
9477 | case DW_OP_reg29: | |
9478 | case DW_OP_reg30: | |
9479 | case DW_OP_reg31: | |
c906108c | 9480 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9481 | if (i < size) |
9482 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9483 | break; |
9484 | ||
9485 | case DW_OP_regx: | |
c906108c SS |
9486 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9487 | i += bytes_read; | |
c906108c | 9488 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9489 | if (i < size) |
9490 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9491 | break; |
9492 | ||
9493 | case DW_OP_addr: | |
107d2387 | 9494 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9495 | cu, &bytes_read); |
107d2387 | 9496 | i += bytes_read; |
c906108c SS |
9497 | break; |
9498 | ||
9499 | case DW_OP_const1u: | |
9500 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9501 | i += 1; | |
9502 | break; | |
9503 | ||
9504 | case DW_OP_const1s: | |
9505 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9506 | i += 1; | |
9507 | break; | |
9508 | ||
9509 | case DW_OP_const2u: | |
9510 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9511 | i += 2; | |
9512 | break; | |
9513 | ||
9514 | case DW_OP_const2s: | |
9515 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9516 | i += 2; | |
9517 | break; | |
9518 | ||
9519 | case DW_OP_const4u: | |
9520 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9521 | i += 4; | |
9522 | break; | |
9523 | ||
9524 | case DW_OP_const4s: | |
9525 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9526 | i += 4; | |
9527 | break; | |
9528 | ||
9529 | case DW_OP_constu: | |
9530 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9531 | &bytes_read); |
c906108c SS |
9532 | i += bytes_read; |
9533 | break; | |
9534 | ||
9535 | case DW_OP_consts: | |
9536 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9537 | i += bytes_read; | |
9538 | break; | |
9539 | ||
f1bea926 JM |
9540 | case DW_OP_dup: |
9541 | stack[stacki + 1] = stack[stacki]; | |
9542 | stacki++; | |
9543 | break; | |
9544 | ||
c906108c SS |
9545 | case DW_OP_plus: |
9546 | stack[stacki - 1] += stack[stacki]; | |
9547 | stacki--; | |
9548 | break; | |
9549 | ||
9550 | case DW_OP_plus_uconst: | |
9551 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9552 | i += bytes_read; | |
9553 | break; | |
9554 | ||
9555 | case DW_OP_minus: | |
f1bea926 | 9556 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9557 | stacki--; |
9558 | break; | |
9559 | ||
7a292a7a | 9560 | case DW_OP_deref: |
7a292a7a | 9561 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9562 | this using GDB's address_class enum. This is valid for partial |
9563 | global symbols, although the variable's address will be bogus | |
9564 | in the psymtab. */ | |
7a292a7a | 9565 | if (i < size) |
4d3c2250 | 9566 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9567 | break; |
9568 | ||
9d774e44 | 9569 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9570 | /* The top of the stack has the offset from the beginning |
9571 | of the thread control block at which the variable is located. */ | |
9572 | /* Nothing should follow this operator, so the top of stack would | |
9573 | be returned. */ | |
4cecd739 DJ |
9574 | /* This is valid for partial global symbols, but the variable's |
9575 | address will be bogus in the psymtab. */ | |
9d774e44 | 9576 | if (i < size) |
4d3c2250 | 9577 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9578 | break; |
9579 | ||
42be36b3 CT |
9580 | case DW_OP_GNU_uninit: |
9581 | break; | |
9582 | ||
c906108c | 9583 | default: |
e2e0b3e5 | 9584 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9585 | dwarf_stack_op_name (op)); |
c906108c SS |
9586 | return (stack[stacki]); |
9587 | } | |
9588 | } | |
9589 | return (stack[stacki]); | |
9590 | } | |
9591 | ||
9592 | /* memory allocation interface */ | |
9593 | ||
c906108c | 9594 | static struct dwarf_block * |
7b5a2f43 | 9595 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9596 | { |
9597 | struct dwarf_block *blk; | |
9598 | ||
9599 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9600 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9601 | return (blk); |
9602 | } | |
9603 | ||
9604 | static struct abbrev_info * | |
f3dd6933 | 9605 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9606 | { |
9607 | struct abbrev_info *abbrev; | |
9608 | ||
f3dd6933 DJ |
9609 | abbrev = (struct abbrev_info *) |
9610 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9611 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9612 | return (abbrev); | |
9613 | } | |
9614 | ||
9615 | static struct die_info * | |
b60c80d6 | 9616 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
9617 | { |
9618 | struct die_info *die; | |
b60c80d6 DJ |
9619 | size_t size = sizeof (struct die_info); |
9620 | ||
9621 | if (num_attrs > 1) | |
9622 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 9623 | |
b60c80d6 | 9624 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
9625 | memset (die, 0, sizeof (struct die_info)); |
9626 | return (die); | |
9627 | } | |
2e276125 JB |
9628 | |
9629 | \f | |
9630 | /* Macro support. */ | |
9631 | ||
9632 | ||
9633 | /* Return the full name of file number I in *LH's file name table. | |
9634 | Use COMP_DIR as the name of the current directory of the | |
9635 | compilation. The result is allocated using xmalloc; the caller is | |
9636 | responsible for freeing it. */ | |
9637 | static char * | |
9638 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9639 | { | |
6a83a1e6 EZ |
9640 | /* Is the file number a valid index into the line header's file name |
9641 | table? Remember that file numbers start with one, not zero. */ | |
9642 | if (1 <= file && file <= lh->num_file_names) | |
9643 | { | |
9644 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9645 | |
6a83a1e6 EZ |
9646 | if (IS_ABSOLUTE_PATH (fe->name)) |
9647 | return xstrdup (fe->name); | |
9648 | else | |
9649 | { | |
9650 | const char *dir; | |
9651 | int dir_len; | |
9652 | char *full_name; | |
9653 | ||
9654 | if (fe->dir_index) | |
9655 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9656 | else | |
9657 | dir = comp_dir; | |
9658 | ||
9659 | if (dir) | |
9660 | { | |
9661 | dir_len = strlen (dir); | |
9662 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9663 | strcpy (full_name, dir); | |
9664 | full_name[dir_len] = '/'; | |
9665 | strcpy (full_name + dir_len + 1, fe->name); | |
9666 | return full_name; | |
9667 | } | |
9668 | else | |
9669 | return xstrdup (fe->name); | |
9670 | } | |
9671 | } | |
2e276125 JB |
9672 | else |
9673 | { | |
6a83a1e6 EZ |
9674 | /* The compiler produced a bogus file number. We can at least |
9675 | record the macro definitions made in the file, even if we | |
9676 | won't be able to find the file by name. */ | |
9677 | char fake_name[80]; | |
9678 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9679 | |
6a83a1e6 EZ |
9680 | complaint (&symfile_complaints, |
9681 | _("bad file number in macro information (%d)"), | |
9682 | file); | |
2e276125 | 9683 | |
6a83a1e6 | 9684 | return xstrdup (fake_name); |
2e276125 JB |
9685 | } |
9686 | } | |
9687 | ||
9688 | ||
9689 | static struct macro_source_file * | |
9690 | macro_start_file (int file, int line, | |
9691 | struct macro_source_file *current_file, | |
9692 | const char *comp_dir, | |
9693 | struct line_header *lh, struct objfile *objfile) | |
9694 | { | |
9695 | /* The full name of this source file. */ | |
9696 | char *full_name = file_full_name (file, lh, comp_dir); | |
9697 | ||
9698 | /* We don't create a macro table for this compilation unit | |
9699 | at all until we actually get a filename. */ | |
9700 | if (! pending_macros) | |
4a146b47 | 9701 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9702 | objfile->macro_cache); |
2e276125 JB |
9703 | |
9704 | if (! current_file) | |
9705 | /* If we have no current file, then this must be the start_file | |
9706 | directive for the compilation unit's main source file. */ | |
9707 | current_file = macro_set_main (pending_macros, full_name); | |
9708 | else | |
9709 | current_file = macro_include (current_file, line, full_name); | |
9710 | ||
9711 | xfree (full_name); | |
9712 | ||
9713 | return current_file; | |
9714 | } | |
9715 | ||
9716 | ||
9717 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9718 | followed by a null byte. */ | |
9719 | static char * | |
9720 | copy_string (const char *buf, int len) | |
9721 | { | |
9722 | char *s = xmalloc (len + 1); | |
9723 | memcpy (s, buf, len); | |
9724 | s[len] = '\0'; | |
9725 | ||
9726 | return s; | |
9727 | } | |
9728 | ||
9729 | ||
9730 | static const char * | |
9731 | consume_improper_spaces (const char *p, const char *body) | |
9732 | { | |
9733 | if (*p == ' ') | |
9734 | { | |
4d3c2250 | 9735 | complaint (&symfile_complaints, |
e2e0b3e5 | 9736 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9737 | body); |
2e276125 JB |
9738 | |
9739 | while (*p == ' ') | |
9740 | p++; | |
9741 | } | |
9742 | ||
9743 | return p; | |
9744 | } | |
9745 | ||
9746 | ||
9747 | static void | |
9748 | parse_macro_definition (struct macro_source_file *file, int line, | |
9749 | const char *body) | |
9750 | { | |
9751 | const char *p; | |
9752 | ||
9753 | /* The body string takes one of two forms. For object-like macro | |
9754 | definitions, it should be: | |
9755 | ||
9756 | <macro name> " " <definition> | |
9757 | ||
9758 | For function-like macro definitions, it should be: | |
9759 | ||
9760 | <macro name> "() " <definition> | |
9761 | or | |
9762 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
9763 | ||
9764 | Spaces may appear only where explicitly indicated, and in the | |
9765 | <definition>. | |
9766 | ||
9767 | The Dwarf 2 spec says that an object-like macro's name is always | |
9768 | followed by a space, but versions of GCC around March 2002 omit | |
9769 | the space when the macro's definition is the empty string. | |
9770 | ||
9771 | The Dwarf 2 spec says that there should be no spaces between the | |
9772 | formal arguments in a function-like macro's formal argument list, | |
9773 | but versions of GCC around March 2002 include spaces after the | |
9774 | commas. */ | |
9775 | ||
9776 | ||
9777 | /* Find the extent of the macro name. The macro name is terminated | |
9778 | by either a space or null character (for an object-like macro) or | |
9779 | an opening paren (for a function-like macro). */ | |
9780 | for (p = body; *p; p++) | |
9781 | if (*p == ' ' || *p == '(') | |
9782 | break; | |
9783 | ||
9784 | if (*p == ' ' || *p == '\0') | |
9785 | { | |
9786 | /* It's an object-like macro. */ | |
9787 | int name_len = p - body; | |
9788 | char *name = copy_string (body, name_len); | |
9789 | const char *replacement; | |
9790 | ||
9791 | if (*p == ' ') | |
9792 | replacement = body + name_len + 1; | |
9793 | else | |
9794 | { | |
4d3c2250 | 9795 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9796 | replacement = body + name_len; |
9797 | } | |
9798 | ||
9799 | macro_define_object (file, line, name, replacement); | |
9800 | ||
9801 | xfree (name); | |
9802 | } | |
9803 | else if (*p == '(') | |
9804 | { | |
9805 | /* It's a function-like macro. */ | |
9806 | char *name = copy_string (body, p - body); | |
9807 | int argc = 0; | |
9808 | int argv_size = 1; | |
9809 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
9810 | ||
9811 | p++; | |
9812 | ||
9813 | p = consume_improper_spaces (p, body); | |
9814 | ||
9815 | /* Parse the formal argument list. */ | |
9816 | while (*p && *p != ')') | |
9817 | { | |
9818 | /* Find the extent of the current argument name. */ | |
9819 | const char *arg_start = p; | |
9820 | ||
9821 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
9822 | p++; | |
9823 | ||
9824 | if (! *p || p == arg_start) | |
4d3c2250 | 9825 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9826 | else |
9827 | { | |
9828 | /* Make sure argv has room for the new argument. */ | |
9829 | if (argc >= argv_size) | |
9830 | { | |
9831 | argv_size *= 2; | |
9832 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
9833 | } | |
9834 | ||
9835 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
9836 | } | |
9837 | ||
9838 | p = consume_improper_spaces (p, body); | |
9839 | ||
9840 | /* Consume the comma, if present. */ | |
9841 | if (*p == ',') | |
9842 | { | |
9843 | p++; | |
9844 | ||
9845 | p = consume_improper_spaces (p, body); | |
9846 | } | |
9847 | } | |
9848 | ||
9849 | if (*p == ')') | |
9850 | { | |
9851 | p++; | |
9852 | ||
9853 | if (*p == ' ') | |
9854 | /* Perfectly formed definition, no complaints. */ | |
9855 | macro_define_function (file, line, name, | |
9856 | argc, (const char **) argv, | |
9857 | p + 1); | |
9858 | else if (*p == '\0') | |
9859 | { | |
9860 | /* Complain, but do define it. */ | |
4d3c2250 | 9861 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9862 | macro_define_function (file, line, name, |
9863 | argc, (const char **) argv, | |
9864 | p); | |
9865 | } | |
9866 | else | |
9867 | /* Just complain. */ | |
4d3c2250 | 9868 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9869 | } |
9870 | else | |
9871 | /* Just complain. */ | |
4d3c2250 | 9872 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9873 | |
9874 | xfree (name); | |
9875 | { | |
9876 | int i; | |
9877 | ||
9878 | for (i = 0; i < argc; i++) | |
9879 | xfree (argv[i]); | |
9880 | } | |
9881 | xfree (argv); | |
9882 | } | |
9883 | else | |
4d3c2250 | 9884 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9885 | } |
9886 | ||
9887 | ||
9888 | static void | |
9889 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
9890 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 9891 | struct dwarf2_cu *cu) |
2e276125 | 9892 | { |
fe1b8b76 | 9893 | gdb_byte *mac_ptr, *mac_end; |
2e276125 JB |
9894 | struct macro_source_file *current_file = 0; |
9895 | ||
6502dd73 | 9896 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 9897 | { |
e2e0b3e5 | 9898 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
9899 | return; |
9900 | } | |
9901 | ||
6502dd73 DJ |
9902 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
9903 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
9904 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
9905 | |
9906 | for (;;) | |
9907 | { | |
9908 | enum dwarf_macinfo_record_type macinfo_type; | |
9909 | ||
9910 | /* Do we at least have room for a macinfo type byte? */ | |
9911 | if (mac_ptr >= mac_end) | |
9912 | { | |
4d3c2250 | 9913 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9914 | return; |
9915 | } | |
9916 | ||
9917 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
9918 | mac_ptr++; | |
9919 | ||
9920 | switch (macinfo_type) | |
9921 | { | |
9922 | /* A zero macinfo type indicates the end of the macro | |
9923 | information. */ | |
9924 | case 0: | |
9925 | return; | |
9926 | ||
9927 | case DW_MACINFO_define: | |
9928 | case DW_MACINFO_undef: | |
9929 | { | |
891d2f0b | 9930 | unsigned int bytes_read; |
2e276125 JB |
9931 | int line; |
9932 | char *body; | |
9933 | ||
9934 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9935 | mac_ptr += bytes_read; | |
9936 | body = read_string (abfd, mac_ptr, &bytes_read); | |
9937 | mac_ptr += bytes_read; | |
9938 | ||
9939 | if (! current_file) | |
4d3c2250 | 9940 | complaint (&symfile_complaints, |
e2e0b3e5 | 9941 | _("debug info gives macro %s outside of any file: %s"), |
4d3c2250 KB |
9942 | macinfo_type == |
9943 | DW_MACINFO_define ? "definition" : macinfo_type == | |
9944 | DW_MACINFO_undef ? "undefinition" : | |
9945 | "something-or-other", body); | |
2e276125 JB |
9946 | else |
9947 | { | |
9948 | if (macinfo_type == DW_MACINFO_define) | |
9949 | parse_macro_definition (current_file, line, body); | |
9950 | else if (macinfo_type == DW_MACINFO_undef) | |
9951 | macro_undef (current_file, line, body); | |
9952 | } | |
9953 | } | |
9954 | break; | |
9955 | ||
9956 | case DW_MACINFO_start_file: | |
9957 | { | |
891d2f0b | 9958 | unsigned int bytes_read; |
2e276125 JB |
9959 | int line, file; |
9960 | ||
9961 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9962 | mac_ptr += bytes_read; | |
9963 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9964 | mac_ptr += bytes_read; | |
9965 | ||
9966 | current_file = macro_start_file (file, line, | |
9967 | current_file, comp_dir, | |
e7c27a73 | 9968 | lh, cu->objfile); |
2e276125 JB |
9969 | } |
9970 | break; | |
9971 | ||
9972 | case DW_MACINFO_end_file: | |
9973 | if (! current_file) | |
4d3c2250 | 9974 | complaint (&symfile_complaints, |
e2e0b3e5 | 9975 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
9976 | else |
9977 | { | |
9978 | current_file = current_file->included_by; | |
9979 | if (! current_file) | |
9980 | { | |
9981 | enum dwarf_macinfo_record_type next_type; | |
9982 | ||
9983 | /* GCC circa March 2002 doesn't produce the zero | |
9984 | type byte marking the end of the compilation | |
9985 | unit. Complain if it's not there, but exit no | |
9986 | matter what. */ | |
9987 | ||
9988 | /* Do we at least have room for a macinfo type byte? */ | |
9989 | if (mac_ptr >= mac_end) | |
9990 | { | |
4d3c2250 | 9991 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9992 | return; |
9993 | } | |
9994 | ||
9995 | /* We don't increment mac_ptr here, so this is just | |
9996 | a look-ahead. */ | |
9997 | next_type = read_1_byte (abfd, mac_ptr); | |
9998 | if (next_type != 0) | |
4d3c2250 | 9999 | complaint (&symfile_complaints, |
e2e0b3e5 | 10000 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
10001 | |
10002 | return; | |
10003 | } | |
10004 | } | |
10005 | break; | |
10006 | ||
10007 | case DW_MACINFO_vendor_ext: | |
10008 | { | |
891d2f0b | 10009 | unsigned int bytes_read; |
2e276125 JB |
10010 | int constant; |
10011 | char *string; | |
10012 | ||
10013 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10014 | mac_ptr += bytes_read; | |
10015 | string = read_string (abfd, mac_ptr, &bytes_read); | |
10016 | mac_ptr += bytes_read; | |
10017 | ||
10018 | /* We don't recognize any vendor extensions. */ | |
10019 | } | |
10020 | break; | |
10021 | } | |
10022 | } | |
10023 | } | |
8e19ed76 PS |
10024 | |
10025 | /* Check if the attribute's form is a DW_FORM_block* | |
10026 | if so return true else false. */ | |
10027 | static int | |
10028 | attr_form_is_block (struct attribute *attr) | |
10029 | { | |
10030 | return (attr == NULL ? 0 : | |
10031 | attr->form == DW_FORM_block1 | |
10032 | || attr->form == DW_FORM_block2 | |
10033 | || attr->form == DW_FORM_block4 | |
10034 | || attr->form == DW_FORM_block); | |
10035 | } | |
4c2df51b | 10036 | |
c6a0999f JB |
10037 | /* Return non-zero if ATTR's value is a section offset --- classes |
10038 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
10039 | You may use DW_UNSND (attr) to retrieve such offsets. | |
10040 | ||
10041 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
10042 | may have a value that belongs to more than one of these classes; it | |
10043 | would be ambiguous if we did, because we use the same forms for all | |
10044 | of them. */ | |
3690dd37 JB |
10045 | static int |
10046 | attr_form_is_section_offset (struct attribute *attr) | |
10047 | { | |
10048 | return (attr->form == DW_FORM_data4 | |
10049 | || attr->form == DW_FORM_data8); | |
10050 | } | |
10051 | ||
10052 | ||
10053 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
10054 | zero otherwise. When this function returns true, you can apply | |
10055 | dwarf2_get_attr_constant_value to it. | |
10056 | ||
10057 | However, note that for some attributes you must check | |
10058 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
10059 | and DW_FORM_data8 are members of both the constant class, and of | |
10060 | the classes that contain offsets into other debug sections | |
10061 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
10062 | that, if an attribute's can be either a constant or one of the | |
10063 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
10064 | taken as section offsets, not constants. */ | |
10065 | static int | |
10066 | attr_form_is_constant (struct attribute *attr) | |
10067 | { | |
10068 | switch (attr->form) | |
10069 | { | |
10070 | case DW_FORM_sdata: | |
10071 | case DW_FORM_udata: | |
10072 | case DW_FORM_data1: | |
10073 | case DW_FORM_data2: | |
10074 | case DW_FORM_data4: | |
10075 | case DW_FORM_data8: | |
10076 | return 1; | |
10077 | default: | |
10078 | return 0; | |
10079 | } | |
10080 | } | |
10081 | ||
4c2df51b DJ |
10082 | static void |
10083 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 10084 | struct dwarf2_cu *cu) |
4c2df51b | 10085 | { |
3690dd37 | 10086 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
10087 | /* ".debug_loc" may not exist at all, or the offset may be outside |
10088 | the section. If so, fall through to the complaint in the | |
10089 | other branch. */ | |
10090 | && DW_UNSND (attr) < dwarf2_per_objfile->loc_size) | |
4c2df51b | 10091 | { |
0d53c4c4 | 10092 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 10093 | |
4a146b47 | 10094 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 10095 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
10096 | baton->per_cu = cu->per_cu; |
10097 | gdb_assert (baton->per_cu); | |
4c2df51b | 10098 | |
0d53c4c4 DJ |
10099 | /* We don't know how long the location list is, but make sure we |
10100 | don't run off the edge of the section. */ | |
6502dd73 DJ |
10101 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
10102 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
d00adf39 DE |
10103 | baton->base_address = cu->base_address; |
10104 | if (cu->base_known == 0) | |
0d53c4c4 | 10105 | complaint (&symfile_complaints, |
e2e0b3e5 | 10106 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 10107 | |
a67af2b9 | 10108 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
10109 | SYMBOL_LOCATION_BATON (sym) = baton; |
10110 | } | |
10111 | else | |
10112 | { | |
10113 | struct dwarf2_locexpr_baton *baton; | |
10114 | ||
4a146b47 | 10115 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 10116 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
10117 | baton->per_cu = cu->per_cu; |
10118 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
10119 | |
10120 | if (attr_form_is_block (attr)) | |
10121 | { | |
10122 | /* Note that we're just copying the block's data pointer | |
10123 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
10124 | info_buffer for SYM's objfile; right now we never release |
10125 | that buffer, but when we do clean up properly this may | |
10126 | need to change. */ | |
0d53c4c4 DJ |
10127 | baton->size = DW_BLOCK (attr)->size; |
10128 | baton->data = DW_BLOCK (attr)->data; | |
10129 | } | |
10130 | else | |
10131 | { | |
10132 | dwarf2_invalid_attrib_class_complaint ("location description", | |
10133 | SYMBOL_NATURAL_NAME (sym)); | |
10134 | baton->size = 0; | |
10135 | baton->data = NULL; | |
10136 | } | |
10137 | ||
a67af2b9 | 10138 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
10139 | SYMBOL_LOCATION_BATON (sym) = baton; |
10140 | } | |
4c2df51b | 10141 | } |
6502dd73 | 10142 | |
ae0d2f24 UW |
10143 | /* Return the OBJFILE associated with the compilation unit CU. */ |
10144 | ||
10145 | struct objfile * | |
10146 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
10147 | { | |
10148 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10149 | ||
10150 | /* Return the master objfile, so that we can report and look up the | |
10151 | correct file containing this variable. */ | |
10152 | if (objfile->separate_debug_objfile_backlink) | |
10153 | objfile = objfile->separate_debug_objfile_backlink; | |
10154 | ||
10155 | return objfile; | |
10156 | } | |
10157 | ||
10158 | /* Return the address size given in the compilation unit header for CU. */ | |
10159 | ||
10160 | CORE_ADDR | |
10161 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
10162 | { | |
10163 | if (per_cu->cu) | |
10164 | return per_cu->cu->header.addr_size; | |
10165 | else | |
10166 | { | |
10167 | /* If the CU is not currently read in, we re-read its header. */ | |
10168 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10169 | struct dwarf2_per_objfile *per_objfile | |
10170 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
10171 | gdb_byte *info_ptr = per_objfile->info_buffer + per_cu->offset; | |
10172 | ||
10173 | struct comp_unit_head cu_header; | |
10174 | memset (&cu_header, 0, sizeof cu_header); | |
10175 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
10176 | return cu_header.addr_size; | |
10177 | } | |
10178 | } | |
10179 | ||
ae038cb0 | 10180 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 10181 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
10182 | |
10183 | static struct dwarf2_per_cu_data * | |
c764a876 | 10184 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
10185 | struct objfile *objfile) |
10186 | { | |
10187 | struct dwarf2_per_cu_data *this_cu; | |
10188 | int low, high; | |
10189 | ||
ae038cb0 DJ |
10190 | low = 0; |
10191 | high = dwarf2_per_objfile->n_comp_units - 1; | |
10192 | while (high > low) | |
10193 | { | |
10194 | int mid = low + (high - low) / 2; | |
10195 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
10196 | high = mid; | |
10197 | else | |
10198 | low = mid + 1; | |
10199 | } | |
10200 | gdb_assert (low == high); | |
10201 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
10202 | { | |
10b3939b | 10203 | if (low == 0) |
8a3fe4f8 AC |
10204 | error (_("Dwarf Error: could not find partial DIE containing " |
10205 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
10206 | (long) offset, bfd_get_filename (objfile->obfd)); |
10207 | ||
ae038cb0 DJ |
10208 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
10209 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
10210 | } | |
10211 | else | |
10212 | { | |
10213 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
10214 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
10215 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 10216 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
10217 | gdb_assert (offset < this_cu->offset + this_cu->length); |
10218 | return this_cu; | |
10219 | } | |
10220 | } | |
10221 | ||
10b3939b DJ |
10222 | /* Locate the compilation unit from OBJFILE which is located at exactly |
10223 | OFFSET. Raises an error on failure. */ | |
10224 | ||
ae038cb0 | 10225 | static struct dwarf2_per_cu_data * |
c764a876 | 10226 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
10227 | { |
10228 | struct dwarf2_per_cu_data *this_cu; | |
10229 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
10230 | if (this_cu->offset != offset) | |
c764a876 | 10231 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
10232 | return this_cu; |
10233 | } | |
10234 | ||
10235 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
10236 | of compilation units, but we don't remove it from the read_in_chain; | |
10237 | the caller is responsible for that. */ | |
10238 | ||
10239 | static void | |
10240 | free_one_comp_unit (void *data) | |
10241 | { | |
10242 | struct dwarf2_cu *cu = data; | |
10243 | ||
10244 | if (cu->per_cu != NULL) | |
10245 | cu->per_cu->cu = NULL; | |
10246 | cu->per_cu = NULL; | |
10247 | ||
10248 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10249 | ||
10250 | xfree (cu); | |
10251 | } | |
10252 | ||
72bf9492 | 10253 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
10254 | when we're finished with it. We can't free the pointer itself, but be |
10255 | sure to unlink it from the cache. Also release any associated storage | |
10256 | and perform cache maintenance. | |
72bf9492 DJ |
10257 | |
10258 | Only used during partial symbol parsing. */ | |
10259 | ||
10260 | static void | |
10261 | free_stack_comp_unit (void *data) | |
10262 | { | |
10263 | struct dwarf2_cu *cu = data; | |
10264 | ||
10265 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10266 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
10267 | |
10268 | if (cu->per_cu != NULL) | |
10269 | { | |
10270 | /* This compilation unit is on the stack in our caller, so we | |
10271 | should not xfree it. Just unlink it. */ | |
10272 | cu->per_cu->cu = NULL; | |
10273 | cu->per_cu = NULL; | |
10274 | ||
10275 | /* If we had a per-cu pointer, then we may have other compilation | |
10276 | units loaded, so age them now. */ | |
10277 | age_cached_comp_units (); | |
10278 | } | |
10279 | } | |
10280 | ||
10281 | /* Free all cached compilation units. */ | |
10282 | ||
10283 | static void | |
10284 | free_cached_comp_units (void *data) | |
10285 | { | |
10286 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10287 | ||
10288 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10289 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10290 | while (per_cu != NULL) | |
10291 | { | |
10292 | struct dwarf2_per_cu_data *next_cu; | |
10293 | ||
10294 | next_cu = per_cu->cu->read_in_chain; | |
10295 | ||
10296 | free_one_comp_unit (per_cu->cu); | |
10297 | *last_chain = next_cu; | |
10298 | ||
10299 | per_cu = next_cu; | |
10300 | } | |
10301 | } | |
10302 | ||
10303 | /* Increase the age counter on each cached compilation unit, and free | |
10304 | any that are too old. */ | |
10305 | ||
10306 | static void | |
10307 | age_cached_comp_units (void) | |
10308 | { | |
10309 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10310 | ||
10311 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
10312 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10313 | while (per_cu != NULL) | |
10314 | { | |
10315 | per_cu->cu->last_used ++; | |
10316 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
10317 | dwarf2_mark (per_cu->cu); | |
10318 | per_cu = per_cu->cu->read_in_chain; | |
10319 | } | |
10320 | ||
10321 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10322 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10323 | while (per_cu != NULL) | |
10324 | { | |
10325 | struct dwarf2_per_cu_data *next_cu; | |
10326 | ||
10327 | next_cu = per_cu->cu->read_in_chain; | |
10328 | ||
10329 | if (!per_cu->cu->mark) | |
10330 | { | |
10331 | free_one_comp_unit (per_cu->cu); | |
10332 | *last_chain = next_cu; | |
10333 | } | |
10334 | else | |
10335 | last_chain = &per_cu->cu->read_in_chain; | |
10336 | ||
10337 | per_cu = next_cu; | |
10338 | } | |
10339 | } | |
10340 | ||
10341 | /* Remove a single compilation unit from the cache. */ | |
10342 | ||
10343 | static void | |
10344 | free_one_cached_comp_unit (void *target_cu) | |
10345 | { | |
10346 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10347 | ||
10348 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10349 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10350 | while (per_cu != NULL) | |
10351 | { | |
10352 | struct dwarf2_per_cu_data *next_cu; | |
10353 | ||
10354 | next_cu = per_cu->cu->read_in_chain; | |
10355 | ||
10356 | if (per_cu->cu == target_cu) | |
10357 | { | |
10358 | free_one_comp_unit (per_cu->cu); | |
10359 | *last_chain = next_cu; | |
10360 | break; | |
10361 | } | |
10362 | else | |
10363 | last_chain = &per_cu->cu->read_in_chain; | |
10364 | ||
10365 | per_cu = next_cu; | |
10366 | } | |
10367 | } | |
10368 | ||
fe3e1990 DJ |
10369 | /* Release all extra memory associated with OBJFILE. */ |
10370 | ||
10371 | void | |
10372 | dwarf2_free_objfile (struct objfile *objfile) | |
10373 | { | |
10374 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10375 | ||
10376 | if (dwarf2_per_objfile == NULL) | |
10377 | return; | |
10378 | ||
10379 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
10380 | free_cached_comp_units (NULL); | |
10381 | ||
10382 | /* Everything else should be on the objfile obstack. */ | |
10383 | } | |
10384 | ||
1c379e20 DJ |
10385 | /* A pair of DIE offset and GDB type pointer. We store these |
10386 | in a hash table separate from the DIEs, and preserve them | |
10387 | when the DIEs are flushed out of cache. */ | |
10388 | ||
10389 | struct dwarf2_offset_and_type | |
10390 | { | |
10391 | unsigned int offset; | |
10392 | struct type *type; | |
10393 | }; | |
10394 | ||
10395 | /* Hash function for a dwarf2_offset_and_type. */ | |
10396 | ||
10397 | static hashval_t | |
10398 | offset_and_type_hash (const void *item) | |
10399 | { | |
10400 | const struct dwarf2_offset_and_type *ofs = item; | |
10401 | return ofs->offset; | |
10402 | } | |
10403 | ||
10404 | /* Equality function for a dwarf2_offset_and_type. */ | |
10405 | ||
10406 | static int | |
10407 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
10408 | { | |
10409 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
10410 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
10411 | return ofs_lhs->offset == ofs_rhs->offset; | |
10412 | } | |
10413 | ||
10414 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 10415 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 10416 | |
f792889a | 10417 | static struct type * |
1c379e20 DJ |
10418 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
10419 | { | |
10420 | struct dwarf2_offset_and_type **slot, ofs; | |
10421 | ||
f792889a DJ |
10422 | if (cu->type_hash == NULL) |
10423 | { | |
10424 | gdb_assert (cu->per_cu != NULL); | |
10425 | cu->per_cu->type_hash | |
10426 | = htab_create_alloc_ex (cu->header.length / 24, | |
10427 | offset_and_type_hash, | |
10428 | offset_and_type_eq, | |
10429 | NULL, | |
10430 | &cu->objfile->objfile_obstack, | |
10431 | hashtab_obstack_allocate, | |
10432 | dummy_obstack_deallocate); | |
10433 | cu->type_hash = cu->per_cu->type_hash; | |
10434 | } | |
1c379e20 DJ |
10435 | |
10436 | ofs.offset = die->offset; | |
10437 | ofs.type = type; | |
10438 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 10439 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
10440 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
10441 | **slot = ofs; | |
f792889a | 10442 | return type; |
1c379e20 DJ |
10443 | } |
10444 | ||
f792889a DJ |
10445 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
10446 | not have a saved type. */ | |
1c379e20 DJ |
10447 | |
10448 | static struct type * | |
f792889a | 10449 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
10450 | { |
10451 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
10452 | htab_t type_hash = cu->type_hash; |
10453 | ||
10454 | if (type_hash == NULL) | |
10455 | return NULL; | |
1c379e20 DJ |
10456 | |
10457 | ofs.offset = die->offset; | |
10458 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
10459 | if (slot) | |
10460 | return slot->type; | |
10461 | else | |
10462 | return NULL; | |
10463 | } | |
10464 | ||
10b3939b DJ |
10465 | /* Set the mark field in CU and in every other compilation unit in the |
10466 | cache that we must keep because we are keeping CU. */ | |
10467 | ||
10468 | /* Add a dependence relationship from CU to REF_PER_CU. */ | |
10469 | ||
10470 | static void | |
10471 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
10472 | struct dwarf2_per_cu_data *ref_per_cu) | |
10473 | { | |
10474 | void **slot; | |
10475 | ||
10476 | if (cu->dependencies == NULL) | |
10477 | cu->dependencies | |
10478 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
10479 | NULL, &cu->comp_unit_obstack, | |
10480 | hashtab_obstack_allocate, | |
10481 | dummy_obstack_deallocate); | |
10482 | ||
10483 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
10484 | if (*slot == NULL) | |
10485 | *slot = ref_per_cu; | |
10486 | } | |
1c379e20 | 10487 | |
ae038cb0 DJ |
10488 | /* Set the mark field in CU and in every other compilation unit in the |
10489 | cache that we must keep because we are keeping CU. */ | |
10490 | ||
10b3939b DJ |
10491 | static int |
10492 | dwarf2_mark_helper (void **slot, void *data) | |
10493 | { | |
10494 | struct dwarf2_per_cu_data *per_cu; | |
10495 | ||
10496 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
10497 | if (per_cu->cu->mark) | |
10498 | return 1; | |
10499 | per_cu->cu->mark = 1; | |
10500 | ||
10501 | if (per_cu->cu->dependencies != NULL) | |
10502 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
10503 | ||
10504 | return 1; | |
10505 | } | |
10506 | ||
ae038cb0 DJ |
10507 | static void |
10508 | dwarf2_mark (struct dwarf2_cu *cu) | |
10509 | { | |
10510 | if (cu->mark) | |
10511 | return; | |
10512 | cu->mark = 1; | |
10b3939b DJ |
10513 | if (cu->dependencies != NULL) |
10514 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
10515 | } |
10516 | ||
10517 | static void | |
10518 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
10519 | { | |
10520 | while (per_cu) | |
10521 | { | |
10522 | per_cu->cu->mark = 0; | |
10523 | per_cu = per_cu->cu->read_in_chain; | |
10524 | } | |
72bf9492 DJ |
10525 | } |
10526 | ||
72bf9492 DJ |
10527 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10528 | is its offset in .debug_info for this objfile. */ | |
10529 | ||
10530 | static hashval_t | |
10531 | partial_die_hash (const void *item) | |
10532 | { | |
10533 | const struct partial_die_info *part_die = item; | |
10534 | return part_die->offset; | |
10535 | } | |
10536 | ||
10537 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10538 | are equal if they have the same offset. */ | |
10539 | ||
10540 | static int | |
10541 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10542 | { | |
10543 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10544 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10545 | return part_die_lhs->offset == part_die_rhs->offset; | |
10546 | } | |
10547 | ||
ae038cb0 DJ |
10548 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10549 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10550 | ||
10551 | static void | |
10552 | set_dwarf2_cmd (char *args, int from_tty) | |
10553 | { | |
10554 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10555 | } | |
10556 | ||
10557 | static void | |
10558 | show_dwarf2_cmd (char *args, int from_tty) | |
10559 | { | |
10560 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10561 | } | |
10562 | ||
6502dd73 DJ |
10563 | void _initialize_dwarf2_read (void); |
10564 | ||
10565 | void | |
10566 | _initialize_dwarf2_read (void) | |
10567 | { | |
10568 | dwarf2_objfile_data_key = register_objfile_data (); | |
ae038cb0 | 10569 | |
1bedd215 AC |
10570 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10571 | Set DWARF 2 specific variables.\n\ | |
10572 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10573 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10574 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10575 | ||
1bedd215 AC |
10576 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10577 | Show DWARF 2 specific variables\n\ | |
10578 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10579 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10580 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10581 | ||
10582 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10583 | &dwarf2_max_cache_age, _("\ |
10584 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10585 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10586 | A higher limit means that cached compilation units will be stored\n\ | |
10587 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10588 | caching, which can slow down startup."), | |
2c5b56ce | 10589 | NULL, |
920d2a44 | 10590 | show_dwarf2_max_cache_age, |
2c5b56ce | 10591 | &set_dwarf2_cmdlist, |
ae038cb0 | 10592 | &show_dwarf2_cmdlist); |
d97bc12b DE |
10593 | |
10594 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
10595 | Set debugging of the dwarf2 DIE reader."), _("\ | |
10596 | Show debugging of the dwarf2 DIE reader."), _("\ | |
10597 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
10598 | The value is the maximum depth to print."), | |
10599 | NULL, | |
10600 | NULL, | |
10601 | &setdebuglist, &showdebuglist); | |
6502dd73 | 10602 | } |