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, |
0fb0cc75 JB |
4 | 2004, 2005, 2006, 2007, 2008, 2009 |
5 | Free Software Foundation, Inc. | |
c906108c SS |
6 | |
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 12 | support. |
c906108c | 13 | |
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
18 | the Free Software Foundation; either version 3 of the License, or |
19 | (at your option) any later version. | |
c906108c | 20 | |
a9762ec7 JB |
21 | This program is distributed in the hope that it will be useful, |
22 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | GNU General Public License for more details. | |
c906108c | 25 | |
c5aa993b | 26 | You should have received a copy of the GNU General Public License |
a9762ec7 | 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
28 | |
29 | #include "defs.h" | |
30 | #include "bfd.h" | |
c906108c SS |
31 | #include "symtab.h" |
32 | #include "gdbtypes.h" | |
c906108c SS |
33 | #include "objfiles.h" |
34 | #include "elf/dwarf2.h" | |
35 | #include "buildsym.h" | |
36 | #include "demangle.h" | |
37 | #include "expression.h" | |
d5166ae1 | 38 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 39 | #include "macrotab.h" |
c906108c SS |
40 | #include "language.h" |
41 | #include "complaints.h" | |
357e46e7 | 42 | #include "bcache.h" |
4c2df51b DJ |
43 | #include "dwarf2expr.h" |
44 | #include "dwarf2loc.h" | |
9219021c | 45 | #include "cp-support.h" |
72bf9492 | 46 | #include "hashtab.h" |
ae038cb0 DJ |
47 | #include "command.h" |
48 | #include "gdbcmd.h" | |
ff013f42 | 49 | #include "addrmap.h" |
4c2df51b | 50 | |
c906108c SS |
51 | #include <fcntl.h> |
52 | #include "gdb_string.h" | |
4bdf3d34 | 53 | #include "gdb_assert.h" |
c906108c | 54 | #include <sys/types.h> |
233a11ab CS |
55 | #ifdef HAVE_ZLIB_H |
56 | #include <zlib.h> | |
57 | #endif | |
dce234bc PP |
58 | #ifdef HAVE_MMAP |
59 | #include <sys/mman.h> | |
60 | #endif | |
d8151005 | 61 | |
107d2387 | 62 | #if 0 |
357e46e7 | 63 | /* .debug_info header for a compilation unit |
c906108c SS |
64 | Because of alignment constraints, this structure has padding and cannot |
65 | be mapped directly onto the beginning of the .debug_info section. */ | |
66 | typedef struct comp_unit_header | |
67 | { | |
68 | unsigned int length; /* length of the .debug_info | |
69 | contribution */ | |
70 | unsigned short version; /* version number -- 2 for DWARF | |
71 | version 2 */ | |
72 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
73 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
74 | } | |
75 | _COMP_UNIT_HEADER; | |
76 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 77 | #endif |
c906108c SS |
78 | |
79 | /* .debug_pubnames header | |
80 | Because of alignment constraints, this structure has padding and cannot | |
81 | be mapped directly onto the beginning of the .debug_info section. */ | |
82 | typedef struct pubnames_header | |
83 | { | |
84 | unsigned int length; /* length of the .debug_pubnames | |
85 | contribution */ | |
86 | unsigned char version; /* version number -- 2 for DWARF | |
87 | version 2 */ | |
88 | unsigned int info_offset; /* offset into .debug_info section */ | |
89 | unsigned int info_size; /* byte size of .debug_info section | |
90 | portion */ | |
91 | } | |
92 | _PUBNAMES_HEADER; | |
93 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
94 | ||
95 | /* .debug_pubnames header | |
96 | Because of alignment constraints, this structure has padding and cannot | |
97 | be mapped directly onto the beginning of the .debug_info section. */ | |
98 | typedef struct aranges_header | |
99 | { | |
100 | unsigned int length; /* byte len of the .debug_aranges | |
101 | contribution */ | |
102 | unsigned short version; /* version number -- 2 for DWARF | |
103 | version 2 */ | |
104 | unsigned int info_offset; /* offset into .debug_info section */ | |
105 | unsigned char addr_size; /* byte size of an address */ | |
106 | unsigned char seg_size; /* byte size of segment descriptor */ | |
107 | } | |
108 | _ARANGES_HEADER; | |
109 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
110 | ||
111 | /* .debug_line statement program prologue | |
112 | Because of alignment constraints, this structure has padding and cannot | |
113 | be mapped directly onto the beginning of the .debug_info section. */ | |
114 | typedef struct statement_prologue | |
115 | { | |
116 | unsigned int total_length; /* byte length of the statement | |
117 | information */ | |
118 | unsigned short version; /* version number -- 2 for DWARF | |
119 | version 2 */ | |
120 | unsigned int prologue_length; /* # bytes between prologue & | |
121 | stmt program */ | |
122 | unsigned char minimum_instruction_length; /* byte size of | |
123 | smallest instr */ | |
124 | unsigned char default_is_stmt; /* initial value of is_stmt | |
125 | register */ | |
126 | char line_base; | |
127 | unsigned char line_range; | |
128 | unsigned char opcode_base; /* number assigned to first special | |
129 | opcode */ | |
130 | unsigned char *standard_opcode_lengths; | |
131 | } | |
132 | _STATEMENT_PROLOGUE; | |
133 | ||
d97bc12b DE |
134 | /* When non-zero, dump DIEs after they are read in. */ |
135 | static int dwarf2_die_debug = 0; | |
136 | ||
dce234bc PP |
137 | static int pagesize; |
138 | ||
df8a16a1 DJ |
139 | /* When set, the file that we're processing is known to have debugging |
140 | info for C++ namespaces. GCC 3.3.x did not produce this information, | |
141 | but later versions do. */ | |
142 | ||
143 | static int processing_has_namespace_info; | |
144 | ||
6502dd73 DJ |
145 | static const struct objfile_data *dwarf2_objfile_data_key; |
146 | ||
dce234bc PP |
147 | struct dwarf2_section_info |
148 | { | |
149 | asection *asection; | |
150 | gdb_byte *buffer; | |
151 | bfd_size_type size; | |
152 | int was_mmapped; | |
153 | }; | |
154 | ||
6502dd73 DJ |
155 | struct dwarf2_per_objfile |
156 | { | |
dce234bc PP |
157 | struct dwarf2_section_info info; |
158 | struct dwarf2_section_info abbrev; | |
159 | struct dwarf2_section_info line; | |
160 | struct dwarf2_section_info pubnames; | |
161 | struct dwarf2_section_info aranges; | |
162 | struct dwarf2_section_info loc; | |
163 | struct dwarf2_section_info macinfo; | |
164 | struct dwarf2_section_info str; | |
165 | struct dwarf2_section_info ranges; | |
166 | struct dwarf2_section_info frame; | |
167 | struct dwarf2_section_info eh_frame; | |
ae038cb0 | 168 | |
10b3939b DJ |
169 | /* A list of all the compilation units. This is used to locate |
170 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
171 | struct dwarf2_per_cu_data **all_comp_units; |
172 | ||
173 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
174 | int n_comp_units; | |
175 | ||
176 | /* A chain of compilation units that are currently read in, so that | |
177 | they can be freed later. */ | |
178 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 FR |
179 | |
180 | /* A flag indicating wether this objfile has a section loaded at a | |
181 | VMA of 0. */ | |
182 | int has_section_at_zero; | |
6502dd73 DJ |
183 | }; |
184 | ||
185 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c SS |
186 | |
187 | /* names of the debugging sections */ | |
188 | ||
233a11ab CS |
189 | /* Note that if the debugging section has been compressed, it might |
190 | have a name like .zdebug_info. */ | |
191 | ||
192 | #define INFO_SECTION "debug_info" | |
193 | #define ABBREV_SECTION "debug_abbrev" | |
194 | #define LINE_SECTION "debug_line" | |
195 | #define PUBNAMES_SECTION "debug_pubnames" | |
196 | #define ARANGES_SECTION "debug_aranges" | |
197 | #define LOC_SECTION "debug_loc" | |
198 | #define MACINFO_SECTION "debug_macinfo" | |
199 | #define STR_SECTION "debug_str" | |
200 | #define RANGES_SECTION "debug_ranges" | |
201 | #define FRAME_SECTION "debug_frame" | |
202 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
203 | |
204 | /* local data types */ | |
205 | ||
57349743 JB |
206 | /* We hold several abbreviation tables in memory at the same time. */ |
207 | #ifndef ABBREV_HASH_SIZE | |
208 | #define ABBREV_HASH_SIZE 121 | |
209 | #endif | |
210 | ||
107d2387 AC |
211 | /* The data in a compilation unit header, after target2host |
212 | translation, looks like this. */ | |
c906108c | 213 | struct comp_unit_head |
a738430d | 214 | { |
c764a876 | 215 | unsigned int length; |
a738430d | 216 | short version; |
a738430d MK |
217 | unsigned char addr_size; |
218 | unsigned char signed_addr_p; | |
9cbfa09e | 219 | unsigned int abbrev_offset; |
57349743 | 220 | |
a738430d MK |
221 | /* Size of file offsets; either 4 or 8. */ |
222 | unsigned int offset_size; | |
57349743 | 223 | |
a738430d MK |
224 | /* Size of the length field; either 4 or 12. */ |
225 | unsigned int initial_length_size; | |
57349743 | 226 | |
a738430d MK |
227 | /* Offset to the first byte of this compilation unit header in the |
228 | .debug_info section, for resolving relative reference dies. */ | |
229 | unsigned int offset; | |
57349743 | 230 | |
d00adf39 DE |
231 | /* Offset to first die in this cu from the start of the cu. |
232 | This will be the first byte following the compilation unit header. */ | |
233 | unsigned int first_die_offset; | |
a738430d | 234 | }; |
c906108c | 235 | |
e7c27a73 DJ |
236 | /* Internal state when decoding a particular compilation unit. */ |
237 | struct dwarf2_cu | |
238 | { | |
239 | /* The objfile containing this compilation unit. */ | |
240 | struct objfile *objfile; | |
241 | ||
d00adf39 | 242 | /* The header of the compilation unit. */ |
e7c27a73 | 243 | struct comp_unit_head header; |
e142c38c | 244 | |
d00adf39 DE |
245 | /* Base address of this compilation unit. */ |
246 | CORE_ADDR base_address; | |
247 | ||
248 | /* Non-zero if base_address has been set. */ | |
249 | int base_known; | |
250 | ||
e142c38c DJ |
251 | struct function_range *first_fn, *last_fn, *cached_fn; |
252 | ||
253 | /* The language we are debugging. */ | |
254 | enum language language; | |
255 | const struct language_defn *language_defn; | |
256 | ||
b0f35d58 DL |
257 | const char *producer; |
258 | ||
e142c38c DJ |
259 | /* The generic symbol table building routines have separate lists for |
260 | file scope symbols and all all other scopes (local scopes). So | |
261 | we need to select the right one to pass to add_symbol_to_list(). | |
262 | We do it by keeping a pointer to the correct list in list_in_scope. | |
263 | ||
264 | FIXME: The original dwarf code just treated the file scope as the | |
265 | first local scope, and all other local scopes as nested local | |
266 | scopes, and worked fine. Check to see if we really need to | |
267 | distinguish these in buildsym.c. */ | |
268 | struct pending **list_in_scope; | |
269 | ||
f3dd6933 DJ |
270 | /* DWARF abbreviation table associated with this compilation unit. */ |
271 | struct abbrev_info **dwarf2_abbrevs; | |
272 | ||
273 | /* Storage for the abbrev table. */ | |
274 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
275 | |
276 | /* Hash table holding all the loaded partial DIEs. */ | |
277 | htab_t partial_dies; | |
278 | ||
ff013f42 | 279 | /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */ |
c764a876 | 280 | unsigned int ranges_offset; |
ff013f42 | 281 | |
72bf9492 DJ |
282 | /* Storage for things with the same lifetime as this read-in compilation |
283 | unit, including partial DIEs. */ | |
284 | struct obstack comp_unit_obstack; | |
285 | ||
ae038cb0 DJ |
286 | /* When multiple dwarf2_cu structures are living in memory, this field |
287 | chains them all together, so that they can be released efficiently. | |
288 | We will probably also want a generation counter so that most-recently-used | |
289 | compilation units are cached... */ | |
290 | struct dwarf2_per_cu_data *read_in_chain; | |
291 | ||
292 | /* Backchain to our per_cu entry if the tree has been built. */ | |
293 | struct dwarf2_per_cu_data *per_cu; | |
294 | ||
f792889a DJ |
295 | /* Pointer to the die -> type map. Although it is stored |
296 | permanently in per_cu, we copy it here to avoid double | |
297 | indirection. */ | |
298 | htab_t type_hash; | |
299 | ||
ae038cb0 DJ |
300 | /* How many compilation units ago was this CU last referenced? */ |
301 | int last_used; | |
302 | ||
10b3939b | 303 | /* A hash table of die offsets for following references. */ |
51545339 | 304 | htab_t die_hash; |
10b3939b DJ |
305 | |
306 | /* Full DIEs if read in. */ | |
307 | struct die_info *dies; | |
308 | ||
309 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
310 | units referenced by this one. Only set during full symbol processing; | |
311 | partial symbol tables do not have dependencies. */ | |
312 | htab_t dependencies; | |
313 | ||
cb1df416 DJ |
314 | /* Header data from the line table, during full symbol processing. */ |
315 | struct line_header *line_header; | |
316 | ||
ae038cb0 DJ |
317 | /* Mark used when releasing cached dies. */ |
318 | unsigned int mark : 1; | |
319 | ||
320 | /* This flag will be set if this compilation unit might include | |
321 | inter-compilation-unit references. */ | |
322 | unsigned int has_form_ref_addr : 1; | |
323 | ||
72bf9492 DJ |
324 | /* This flag will be set if this compilation unit includes any |
325 | DW_TAG_namespace DIEs. If we know that there are explicit | |
326 | DIEs for namespaces, we don't need to try to infer them | |
327 | from mangled names. */ | |
328 | unsigned int has_namespace_info : 1; | |
ff013f42 JK |
329 | |
330 | /* Field `ranges_offset' is filled in; flag as the value may be zero. */ | |
331 | unsigned int has_ranges_offset : 1; | |
e7c27a73 DJ |
332 | }; |
333 | ||
10b3939b DJ |
334 | /* Persistent data held for a compilation unit, even when not |
335 | processing it. We put a pointer to this structure in the | |
336 | read_symtab_private field of the psymtab. If we encounter | |
337 | inter-compilation-unit references, we also maintain a sorted | |
338 | list of all compilation units. */ | |
339 | ||
ae038cb0 DJ |
340 | struct dwarf2_per_cu_data |
341 | { | |
5afb4e99 | 342 | /* The start offset and length of this compilation unit. 2**30-1 |
ae038cb0 | 343 | bytes should suffice to store the length of any compilation unit |
45452591 DE |
344 | - if it doesn't, GDB will fall over anyway. |
345 | NOTE: Unlike comp_unit_head.length, this length includes | |
346 | initial_length_size. */ | |
c764a876 DE |
347 | unsigned int offset; |
348 | unsigned int length : 30; | |
ae038cb0 DJ |
349 | |
350 | /* Flag indicating this compilation unit will be read in before | |
351 | any of the current compilation units are processed. */ | |
c764a876 | 352 | unsigned int queued : 1; |
ae038cb0 | 353 | |
5afb4e99 DJ |
354 | /* This flag will be set if we need to load absolutely all DIEs |
355 | for this compilation unit, instead of just the ones we think | |
356 | are interesting. It gets set if we look for a DIE in the | |
357 | hash table and don't find it. */ | |
358 | unsigned int load_all_dies : 1; | |
359 | ||
ae038cb0 DJ |
360 | /* Set iff currently read in. */ |
361 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
362 | |
363 | /* If full symbols for this CU have been read in, then this field | |
364 | holds a map of DIE offsets to types. It isn't always possible | |
365 | to reconstruct this information later, so we have to preserve | |
366 | it. */ | |
1c379e20 | 367 | htab_t type_hash; |
10b3939b | 368 | |
31ffec48 DJ |
369 | /* The partial symbol table associated with this compilation unit, |
370 | or NULL for partial units (which do not have an associated | |
371 | symtab). */ | |
10b3939b | 372 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
373 | }; |
374 | ||
debd256d JB |
375 | /* The line number information for a compilation unit (found in the |
376 | .debug_line section) begins with a "statement program header", | |
377 | which contains the following information. */ | |
378 | struct line_header | |
379 | { | |
380 | unsigned int total_length; | |
381 | unsigned short version; | |
382 | unsigned int header_length; | |
383 | unsigned char minimum_instruction_length; | |
384 | unsigned char default_is_stmt; | |
385 | int line_base; | |
386 | unsigned char line_range; | |
387 | unsigned char opcode_base; | |
388 | ||
389 | /* standard_opcode_lengths[i] is the number of operands for the | |
390 | standard opcode whose value is i. This means that | |
391 | standard_opcode_lengths[0] is unused, and the last meaningful | |
392 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
393 | unsigned char *standard_opcode_lengths; | |
394 | ||
395 | /* The include_directories table. NOTE! These strings are not | |
396 | allocated with xmalloc; instead, they are pointers into | |
397 | debug_line_buffer. If you try to free them, `free' will get | |
398 | indigestion. */ | |
399 | unsigned int num_include_dirs, include_dirs_size; | |
400 | char **include_dirs; | |
401 | ||
402 | /* The file_names table. NOTE! These strings are not allocated | |
403 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
404 | Don't try to free them directly. */ | |
405 | unsigned int num_file_names, file_names_size; | |
406 | struct file_entry | |
c906108c | 407 | { |
debd256d JB |
408 | char *name; |
409 | unsigned int dir_index; | |
410 | unsigned int mod_time; | |
411 | unsigned int length; | |
aaa75496 | 412 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 413 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
414 | } *file_names; |
415 | ||
416 | /* The start and end of the statement program following this | |
6502dd73 | 417 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 418 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 419 | }; |
c906108c SS |
420 | |
421 | /* When we construct a partial symbol table entry we only | |
422 | need this much information. */ | |
423 | struct partial_die_info | |
424 | { | |
72bf9492 | 425 | /* Offset of this DIE. */ |
c906108c | 426 | unsigned int offset; |
72bf9492 DJ |
427 | |
428 | /* DWARF-2 tag for this DIE. */ | |
429 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
430 | ||
431 | /* Language code associated with this DIE. This is only used | |
432 | for the compilation unit DIE. */ | |
433 | unsigned int language : 8; | |
434 | ||
435 | /* Assorted flags describing the data found in this DIE. */ | |
436 | unsigned int has_children : 1; | |
437 | unsigned int is_external : 1; | |
438 | unsigned int is_declaration : 1; | |
439 | unsigned int has_type : 1; | |
440 | unsigned int has_specification : 1; | |
aaa75496 | 441 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
442 | unsigned int has_pc_info : 1; |
443 | ||
444 | /* Flag set if the SCOPE field of this structure has been | |
445 | computed. */ | |
446 | unsigned int scope_set : 1; | |
447 | ||
fa4028e9 JB |
448 | /* Flag set if the DIE has a byte_size attribute. */ |
449 | unsigned int has_byte_size : 1; | |
450 | ||
72bf9492 DJ |
451 | /* The name of this DIE. Normally the value of DW_AT_name, but |
452 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
453 | other fashion. */ | |
c906108c | 454 | char *name; |
57c22c6c | 455 | char *dirname; |
72bf9492 DJ |
456 | |
457 | /* The scope to prepend to our children. This is generally | |
458 | allocated on the comp_unit_obstack, so will disappear | |
459 | when this compilation unit leaves the cache. */ | |
460 | char *scope; | |
461 | ||
462 | /* The location description associated with this DIE, if any. */ | |
463 | struct dwarf_block *locdesc; | |
464 | ||
465 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
466 | CORE_ADDR lowpc; |
467 | CORE_ADDR highpc; | |
72bf9492 DJ |
468 | |
469 | /* Pointer into the info_buffer pointing at the target of | |
470 | DW_AT_sibling, if any. */ | |
fe1b8b76 | 471 | gdb_byte *sibling; |
72bf9492 DJ |
472 | |
473 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
474 | DW_AT_specification (or DW_AT_abstract_origin or | |
475 | DW_AT_extension). */ | |
476 | unsigned int spec_offset; | |
477 | ||
aaa75496 JB |
478 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
479 | unsigned int line_offset; | |
480 | ||
72bf9492 DJ |
481 | /* Pointers to this DIE's parent, first child, and next sibling, |
482 | if any. */ | |
483 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
484 | }; |
485 | ||
486 | /* This data structure holds the information of an abbrev. */ | |
487 | struct abbrev_info | |
488 | { | |
489 | unsigned int number; /* number identifying abbrev */ | |
490 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
491 | unsigned short has_children; /* boolean */ |
492 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
493 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
494 | struct abbrev_info *next; /* next in chain */ | |
495 | }; | |
496 | ||
497 | struct attr_abbrev | |
498 | { | |
9d25dd43 DE |
499 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
500 | ENUM_BITFIELD(dwarf_form) form : 16; | |
c906108c SS |
501 | }; |
502 | ||
71c25dea TT |
503 | /* Additional GDB-specific attribute forms. */ |
504 | enum | |
505 | { | |
506 | /* A string which has been updated to GDB's internal | |
507 | representation (e.g. converted to canonical form) and does not | |
508 | need to be updated again. */ | |
509 | GDB_FORM_cached_string = 0xff | |
510 | }; | |
511 | ||
b60c80d6 DJ |
512 | /* Attributes have a name and a value */ |
513 | struct attribute | |
514 | { | |
9d25dd43 DE |
515 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
516 | ENUM_BITFIELD(dwarf_form) form : 16; | |
b60c80d6 DJ |
517 | union |
518 | { | |
519 | char *str; | |
520 | struct dwarf_block *blk; | |
521 | unsigned long unsnd; | |
522 | long int snd; | |
523 | CORE_ADDR addr; | |
524 | } | |
525 | u; | |
526 | }; | |
527 | ||
c906108c SS |
528 | /* This data structure holds a complete die structure. */ |
529 | struct die_info | |
530 | { | |
76815b17 DE |
531 | /* DWARF-2 tag for this DIE. */ |
532 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
533 | ||
534 | /* Number of attributes */ | |
535 | unsigned short num_attrs; | |
536 | ||
537 | /* Abbrev number */ | |
538 | unsigned int abbrev; | |
539 | ||
540 | /* Offset in .debug_info section */ | |
541 | unsigned int offset; | |
78ba4af6 JB |
542 | |
543 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
544 | points to this die's parent; CHILD points to the first child of | |
545 | this node; and all the children of a given node are chained | |
546 | together via their SIBLING fields, terminated by a die whose | |
547 | tag is zero. */ | |
639d11d3 DC |
548 | struct die_info *child; /* Its first child, if any. */ |
549 | struct die_info *sibling; /* Its next sibling, if any. */ | |
550 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 551 | |
b60c80d6 DJ |
552 | /* An array of attributes, with NUM_ATTRS elements. There may be |
553 | zero, but it's not common and zero-sized arrays are not | |
554 | sufficiently portable C. */ | |
555 | struct attribute attrs[1]; | |
c906108c SS |
556 | }; |
557 | ||
5fb290d7 DJ |
558 | struct function_range |
559 | { | |
560 | const char *name; | |
561 | CORE_ADDR lowpc, highpc; | |
562 | int seen_line; | |
563 | struct function_range *next; | |
564 | }; | |
565 | ||
c906108c SS |
566 | /* Get at parts of an attribute structure */ |
567 | ||
568 | #define DW_STRING(attr) ((attr)->u.str) | |
569 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
570 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
571 | #define DW_SND(attr) ((attr)->u.snd) | |
572 | #define DW_ADDR(attr) ((attr)->u.addr) | |
573 | ||
574 | /* Blocks are a bunch of untyped bytes. */ | |
575 | struct dwarf_block | |
576 | { | |
577 | unsigned int size; | |
fe1b8b76 | 578 | gdb_byte *data; |
c906108c SS |
579 | }; |
580 | ||
c906108c SS |
581 | #ifndef ATTR_ALLOC_CHUNK |
582 | #define ATTR_ALLOC_CHUNK 4 | |
583 | #endif | |
584 | ||
c906108c SS |
585 | /* Allocate fields for structs, unions and enums in this size. */ |
586 | #ifndef DW_FIELD_ALLOC_CHUNK | |
587 | #define DW_FIELD_ALLOC_CHUNK 4 | |
588 | #endif | |
589 | ||
c906108c SS |
590 | /* A zeroed version of a partial die for initialization purposes. */ |
591 | static struct partial_die_info zeroed_partial_die; | |
592 | ||
c906108c SS |
593 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
594 | but this would require a corresponding change in unpack_field_as_long | |
595 | and friends. */ | |
596 | static int bits_per_byte = 8; | |
597 | ||
598 | /* The routines that read and process dies for a C struct or C++ class | |
599 | pass lists of data member fields and lists of member function fields | |
600 | in an instance of a field_info structure, as defined below. */ | |
601 | struct field_info | |
c5aa993b JM |
602 | { |
603 | /* List of data member and baseclasses fields. */ | |
604 | struct nextfield | |
605 | { | |
606 | struct nextfield *next; | |
607 | int accessibility; | |
608 | int virtuality; | |
609 | struct field field; | |
610 | } | |
611 | *fields; | |
c906108c | 612 | |
c5aa993b JM |
613 | /* Number of fields. */ |
614 | int nfields; | |
c906108c | 615 | |
c5aa993b JM |
616 | /* Number of baseclasses. */ |
617 | int nbaseclasses; | |
c906108c | 618 | |
c5aa993b JM |
619 | /* Set if the accesibility of one of the fields is not public. */ |
620 | int non_public_fields; | |
c906108c | 621 | |
c5aa993b JM |
622 | /* Member function fields array, entries are allocated in the order they |
623 | are encountered in the object file. */ | |
624 | struct nextfnfield | |
625 | { | |
626 | struct nextfnfield *next; | |
627 | struct fn_field fnfield; | |
628 | } | |
629 | *fnfields; | |
c906108c | 630 | |
c5aa993b JM |
631 | /* Member function fieldlist array, contains name of possibly overloaded |
632 | member function, number of overloaded member functions and a pointer | |
633 | to the head of the member function field chain. */ | |
634 | struct fnfieldlist | |
635 | { | |
636 | char *name; | |
637 | int length; | |
638 | struct nextfnfield *head; | |
639 | } | |
640 | *fnfieldlists; | |
c906108c | 641 | |
c5aa993b JM |
642 | /* Number of entries in the fnfieldlists array. */ |
643 | int nfnfields; | |
644 | }; | |
c906108c | 645 | |
10b3939b DJ |
646 | /* One item on the queue of compilation units to read in full symbols |
647 | for. */ | |
648 | struct dwarf2_queue_item | |
649 | { | |
650 | struct dwarf2_per_cu_data *per_cu; | |
651 | struct dwarf2_queue_item *next; | |
652 | }; | |
653 | ||
654 | /* The current queue. */ | |
655 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
656 | ||
ae038cb0 DJ |
657 | /* Loaded secondary compilation units are kept in memory until they |
658 | have not been referenced for the processing of this many | |
659 | compilation units. Set this to zero to disable caching. Cache | |
660 | sizes of up to at least twenty will improve startup time for | |
661 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
662 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
663 | static void |
664 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
665 | struct cmd_list_element *c, const char *value) | |
666 | { | |
667 | fprintf_filtered (file, _("\ | |
668 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
669 | value); | |
670 | } | |
671 | ||
ae038cb0 | 672 | |
c906108c SS |
673 | /* Various complaints about symbol reading that don't abort the process */ |
674 | ||
4d3c2250 KB |
675 | static void |
676 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 677 | { |
4d3c2250 | 678 | complaint (&symfile_complaints, |
e2e0b3e5 | 679 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
680 | } |
681 | ||
25e43795 DJ |
682 | static void |
683 | dwarf2_debug_line_missing_file_complaint (void) | |
684 | { | |
685 | complaint (&symfile_complaints, | |
686 | _(".debug_line section has line data without a file")); | |
687 | } | |
688 | ||
59205f5a JB |
689 | static void |
690 | dwarf2_debug_line_missing_end_sequence_complaint (void) | |
691 | { | |
692 | complaint (&symfile_complaints, | |
693 | _(".debug_line section has line program sequence without an end")); | |
694 | } | |
695 | ||
4d3c2250 KB |
696 | static void |
697 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 698 | { |
e2e0b3e5 | 699 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
700 | } |
701 | ||
4d3c2250 KB |
702 | static void |
703 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
704 | int arg3) | |
2e276125 | 705 | { |
4d3c2250 | 706 | complaint (&symfile_complaints, |
e2e0b3e5 | 707 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
708 | arg2, arg3); |
709 | } | |
710 | ||
711 | static void | |
712 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 713 | { |
4d3c2250 | 714 | complaint (&symfile_complaints, |
e2e0b3e5 | 715 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
716 | } |
717 | ||
718 | static void | |
719 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 720 | { |
4d3c2250 | 721 | complaint (&symfile_complaints, |
e2e0b3e5 | 722 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
723 | arg1); |
724 | } | |
725 | ||
726 | static void | |
727 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 728 | { |
4d3c2250 | 729 | complaint (&symfile_complaints, |
e2e0b3e5 | 730 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 731 | } |
c906108c | 732 | |
c906108c SS |
733 | /* local function prototypes */ |
734 | ||
4efb68b1 | 735 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
736 | |
737 | #if 0 | |
a14ed312 | 738 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
739 | #endif |
740 | ||
aaa75496 JB |
741 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
742 | struct objfile *); | |
743 | ||
744 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
745 | struct partial_die_info *, | |
746 | struct partial_symtab *); | |
747 | ||
a14ed312 | 748 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 749 | |
72bf9492 DJ |
750 | static void scan_partial_symbols (struct partial_die_info *, |
751 | CORE_ADDR *, CORE_ADDR *, | |
5734ee8b | 752 | int, struct dwarf2_cu *); |
c906108c | 753 | |
72bf9492 DJ |
754 | static void add_partial_symbol (struct partial_die_info *, |
755 | struct dwarf2_cu *); | |
63d06c5c | 756 | |
72bf9492 | 757 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 758 | |
72bf9492 DJ |
759 | static void add_partial_namespace (struct partial_die_info *pdi, |
760 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 761 | int need_pc, struct dwarf2_cu *cu); |
63d06c5c | 762 | |
5d7cb8df JK |
763 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
764 | CORE_ADDR *highpc, int need_pc, | |
765 | struct dwarf2_cu *cu); | |
766 | ||
72bf9492 DJ |
767 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
768 | struct dwarf2_cu *cu); | |
91c24f0a | 769 | |
bc30ff58 JB |
770 | static void add_partial_subprogram (struct partial_die_info *pdi, |
771 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 772 | int need_pc, struct dwarf2_cu *cu); |
bc30ff58 | 773 | |
fe1b8b76 JB |
774 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
775 | gdb_byte *info_ptr, | |
776 | bfd *abfd, | |
777 | struct dwarf2_cu *cu); | |
91c24f0a | 778 | |
a14ed312 | 779 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 780 | |
a14ed312 | 781 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 782 | |
e7c27a73 | 783 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 784 | |
f3dd6933 | 785 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 786 | |
fe1b8b76 | 787 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 788 | struct dwarf2_cu *); |
72bf9492 | 789 | |
57349743 | 790 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 791 | struct dwarf2_cu *); |
c906108c | 792 | |
fe1b8b76 | 793 | static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int, |
72bf9492 DJ |
794 | struct dwarf2_cu *); |
795 | ||
fe1b8b76 JB |
796 | static gdb_byte *read_partial_die (struct partial_die_info *, |
797 | struct abbrev_info *abbrev, unsigned int, | |
798 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 799 | |
c764a876 | 800 | static struct partial_die_info *find_partial_die (unsigned int, |
10b3939b | 801 | struct dwarf2_cu *); |
72bf9492 DJ |
802 | |
803 | static void fixup_partial_die (struct partial_die_info *, | |
804 | struct dwarf2_cu *); | |
805 | ||
fe1b8b76 JB |
806 | static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *, |
807 | struct dwarf2_cu *, int *); | |
c906108c | 808 | |
fe1b8b76 JB |
809 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
810 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 811 | |
fe1b8b76 JB |
812 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
813 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 814 | |
fe1b8b76 | 815 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 816 | |
fe1b8b76 | 817 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 818 | |
fe1b8b76 | 819 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 820 | |
fe1b8b76 | 821 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 822 | |
fe1b8b76 | 823 | static unsigned long read_8_bytes (bfd *, gdb_byte *); |
c906108c | 824 | |
fe1b8b76 | 825 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 826 | unsigned int *); |
c906108c | 827 | |
c764a876 DE |
828 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
829 | ||
830 | static LONGEST read_checked_initial_length_and_offset | |
831 | (bfd *, gdb_byte *, const struct comp_unit_head *, | |
832 | unsigned int *, unsigned int *); | |
613e1657 | 833 | |
fe1b8b76 | 834 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
c764a876 DE |
835 | unsigned int *); |
836 | ||
837 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); | |
613e1657 | 838 | |
fe1b8b76 | 839 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 840 | |
fe1b8b76 | 841 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 842 | |
fe1b8b76 JB |
843 | static char *read_indirect_string (bfd *, gdb_byte *, |
844 | const struct comp_unit_head *, | |
845 | unsigned int *); | |
4bdf3d34 | 846 | |
fe1b8b76 | 847 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 848 | |
fe1b8b76 | 849 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 850 | |
fe1b8b76 | 851 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 852 | |
e142c38c | 853 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 854 | |
e142c38c DJ |
855 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
856 | struct dwarf2_cu *); | |
c906108c | 857 | |
05cf31d1 JB |
858 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
859 | struct dwarf2_cu *cu); | |
860 | ||
e142c38c | 861 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 862 | |
e142c38c | 863 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 864 | struct dwarf2_cu **); |
63d06c5c | 865 | |
debd256d JB |
866 | static void free_line_header (struct line_header *lh); |
867 | ||
aaa75496 JB |
868 | static void add_file_name (struct line_header *, char *, unsigned int, |
869 | unsigned int, unsigned int); | |
870 | ||
debd256d JB |
871 | static struct line_header *(dwarf_decode_line_header |
872 | (unsigned int offset, | |
e7c27a73 | 873 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
874 | |
875 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 876 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 877 | |
4f1520fb | 878 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 879 | |
a14ed312 | 880 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 881 | struct dwarf2_cu *); |
c906108c | 882 | |
a14ed312 | 883 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 884 | struct dwarf2_cu *); |
c906108c | 885 | |
2df3850c JM |
886 | static void dwarf2_const_value_data (struct attribute *attr, |
887 | struct symbol *sym, | |
888 | int bits); | |
889 | ||
e7c27a73 | 890 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 891 | |
e7c27a73 DJ |
892 | static struct type *die_containing_type (struct die_info *, |
893 | struct dwarf2_cu *); | |
c906108c | 894 | |
e7c27a73 | 895 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 896 | |
f792889a | 897 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 898 | |
086ed43d | 899 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 900 | |
fe1b8b76 JB |
901 | static char *typename_concat (struct obstack *, |
902 | const char *prefix, | |
903 | const char *suffix, | |
987504bb | 904 | struct dwarf2_cu *); |
63d06c5c | 905 | |
e7c27a73 | 906 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 907 | |
e7c27a73 | 908 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 909 | |
e7c27a73 | 910 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 911 | |
ff013f42 JK |
912 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
913 | struct dwarf2_cu *, struct partial_symtab *); | |
914 | ||
a14ed312 | 915 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 916 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 917 | |
fae299cd DC |
918 | static void get_scope_pc_bounds (struct die_info *, |
919 | CORE_ADDR *, CORE_ADDR *, | |
920 | struct dwarf2_cu *); | |
921 | ||
801e3a5b JB |
922 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
923 | CORE_ADDR, struct dwarf2_cu *); | |
924 | ||
a14ed312 | 925 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 926 | struct dwarf2_cu *); |
c906108c | 927 | |
a14ed312 | 928 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 929 | struct type *, struct dwarf2_cu *); |
c906108c | 930 | |
a14ed312 | 931 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 932 | struct die_info *, struct type *, |
e7c27a73 | 933 | struct dwarf2_cu *); |
c906108c | 934 | |
a14ed312 | 935 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 936 | struct type *, struct dwarf2_cu *); |
c906108c | 937 | |
134d01f1 | 938 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 939 | |
0114d602 DJ |
940 | static const char *determine_class_name (struct die_info *die, |
941 | struct dwarf2_cu *cu); | |
8176b9b8 | 942 | |
e7c27a73 | 943 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 944 | |
e7c27a73 | 945 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 946 | |
5d7cb8df JK |
947 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
948 | ||
38d518c9 | 949 | static const char *namespace_name (struct die_info *die, |
e142c38c | 950 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 951 | |
134d01f1 | 952 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 953 | |
e7c27a73 | 954 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 955 | |
7ca2d3a3 DL |
956 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
957 | struct dwarf2_cu *); | |
958 | ||
fe1b8b76 | 959 | static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *); |
c906108c | 960 | |
d97bc12b DE |
961 | static struct die_info *read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd, |
962 | struct dwarf2_cu *, | |
963 | gdb_byte **new_info_ptr, | |
964 | struct die_info *parent); | |
965 | ||
fe1b8b76 | 966 | static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 967 | struct dwarf2_cu *, |
fe1b8b76 | 968 | gdb_byte **new_info_ptr, |
639d11d3 DC |
969 | struct die_info *parent); |
970 | ||
fe1b8b76 | 971 | static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 972 | struct dwarf2_cu *, |
fe1b8b76 | 973 | gdb_byte **new_info_ptr, |
639d11d3 DC |
974 | struct die_info *parent); |
975 | ||
e7c27a73 | 976 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 977 | |
e142c38c | 978 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 979 | |
71c25dea TT |
980 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
981 | struct obstack *); | |
982 | ||
e142c38c | 983 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 984 | |
e142c38c | 985 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 986 | struct dwarf2_cu **); |
9219021c | 987 | |
a14ed312 | 988 | static char *dwarf_tag_name (unsigned int); |
c906108c | 989 | |
a14ed312 | 990 | static char *dwarf_attr_name (unsigned int); |
c906108c | 991 | |
a14ed312 | 992 | static char *dwarf_form_name (unsigned int); |
c906108c | 993 | |
a14ed312 | 994 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 995 | |
a14ed312 | 996 | static char *dwarf_bool_name (unsigned int); |
c906108c | 997 | |
a14ed312 | 998 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
999 | |
1000 | #if 0 | |
a14ed312 | 1001 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
1002 | #endif |
1003 | ||
f9aca02d | 1004 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1005 | |
d97bc12b DE |
1006 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
1007 | ||
1008 | static void dump_die_for_error (struct die_info *); | |
1009 | ||
1010 | static void dump_die_1 (struct ui_file *, int level, int max_level, | |
1011 | struct die_info *); | |
c906108c | 1012 | |
d97bc12b | 1013 | /*static*/ void dump_die (struct die_info *, int max_level); |
c906108c | 1014 | |
51545339 | 1015 | static void store_in_ref_table (struct die_info *, |
10b3939b | 1016 | struct dwarf2_cu *); |
c906108c | 1017 | |
c764a876 | 1018 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
c906108c | 1019 | |
a02abb62 JB |
1020 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
1021 | ||
10b3939b DJ |
1022 | static struct die_info *follow_die_ref (struct die_info *, |
1023 | struct attribute *, | |
f2f0e013 | 1024 | struct dwarf2_cu **); |
c906108c | 1025 | |
c906108c SS |
1026 | /* memory allocation interface */ |
1027 | ||
7b5a2f43 | 1028 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1029 | |
f3dd6933 | 1030 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1031 | |
b60c80d6 | 1032 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1033 | |
e142c38c | 1034 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1035 | |
e142c38c DJ |
1036 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1037 | struct dwarf2_cu *); | |
5fb290d7 | 1038 | |
2e276125 | 1039 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1040 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1041 | |
8e19ed76 PS |
1042 | static int attr_form_is_block (struct attribute *); |
1043 | ||
3690dd37 JB |
1044 | static int attr_form_is_section_offset (struct attribute *); |
1045 | ||
1046 | static int attr_form_is_constant (struct attribute *); | |
1047 | ||
93e7bd98 DJ |
1048 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1049 | struct symbol *sym, | |
1050 | struct dwarf2_cu *cu); | |
4c2df51b | 1051 | |
fe1b8b76 JB |
1052 | static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, |
1053 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1054 | |
72bf9492 DJ |
1055 | static void free_stack_comp_unit (void *); |
1056 | ||
72bf9492 DJ |
1057 | static hashval_t partial_die_hash (const void *item); |
1058 | ||
1059 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1060 | ||
ae038cb0 | 1061 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
c764a876 | 1062 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1063 | |
1064 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
c764a876 | 1065 | (unsigned int offset, struct objfile *objfile); |
ae038cb0 DJ |
1066 | |
1067 | static void free_one_comp_unit (void *); | |
1068 | ||
1069 | static void free_cached_comp_units (void *); | |
1070 | ||
1071 | static void age_cached_comp_units (void); | |
1072 | ||
1073 | static void free_one_cached_comp_unit (void *); | |
1074 | ||
f792889a DJ |
1075 | static struct type *set_die_type (struct die_info *, struct type *, |
1076 | struct dwarf2_cu *); | |
1c379e20 | 1077 | |
ae038cb0 DJ |
1078 | static void create_all_comp_units (struct objfile *); |
1079 | ||
31ffec48 DJ |
1080 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *, |
1081 | struct objfile *); | |
10b3939b DJ |
1082 | |
1083 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1084 | ||
1085 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1086 | struct dwarf2_per_cu_data *); | |
1087 | ||
ae038cb0 DJ |
1088 | static void dwarf2_mark (struct dwarf2_cu *); |
1089 | ||
1090 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1091 | ||
f792889a | 1092 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1093 | |
c906108c SS |
1094 | /* Try to locate the sections we need for DWARF 2 debugging |
1095 | information and return true if we have enough to do something. */ | |
1096 | ||
1097 | int | |
6502dd73 | 1098 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1099 | { |
6502dd73 DJ |
1100 | struct dwarf2_per_objfile *data; |
1101 | ||
1102 | /* Initialize per-objfile state. */ | |
1103 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1104 | memset (data, 0, sizeof (*data)); | |
1105 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1106 | dwarf2_per_objfile = data; | |
1107 | ||
6502dd73 | 1108 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
dce234bc | 1109 | return (data->info.asection != NULL && data->abbrev.asection != NULL); |
c906108c SS |
1110 | } |
1111 | ||
233a11ab CS |
1112 | /* When loading sections, we can either look for ".<name>", or for |
1113 | * ".z<name>", which indicates a compressed section. */ | |
1114 | ||
1115 | static int | |
dce234bc | 1116 | section_is_p (const char *section_name, const char *name) |
233a11ab | 1117 | { |
dce234bc PP |
1118 | return (section_name[0] == '.' |
1119 | && (strcmp (section_name + 1, name) == 0 | |
1120 | || (section_name[1] == 'z' | |
1121 | && strcmp (section_name + 2, name) == 0))); | |
233a11ab CS |
1122 | } |
1123 | ||
c906108c SS |
1124 | /* This function is mapped across the sections and remembers the |
1125 | offset and size of each of the debugging sections we are interested | |
1126 | in. */ | |
1127 | ||
1128 | static void | |
72dca2f5 | 1129 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1130 | { |
dce234bc | 1131 | if (section_is_p (sectp->name, INFO_SECTION)) |
c906108c | 1132 | { |
dce234bc PP |
1133 | dwarf2_per_objfile->info.asection = sectp; |
1134 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); | |
c906108c | 1135 | } |
dce234bc | 1136 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
c906108c | 1137 | { |
dce234bc PP |
1138 | dwarf2_per_objfile->abbrev.asection = sectp; |
1139 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); | |
c906108c | 1140 | } |
dce234bc | 1141 | else if (section_is_p (sectp->name, LINE_SECTION)) |
c906108c | 1142 | { |
dce234bc PP |
1143 | dwarf2_per_objfile->line.asection = sectp; |
1144 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); | |
c906108c | 1145 | } |
dce234bc | 1146 | else if (section_is_p (sectp->name, PUBNAMES_SECTION)) |
c906108c | 1147 | { |
dce234bc PP |
1148 | dwarf2_per_objfile->pubnames.asection = sectp; |
1149 | dwarf2_per_objfile->pubnames.size = bfd_get_section_size (sectp); | |
c906108c | 1150 | } |
dce234bc | 1151 | else if (section_is_p (sectp->name, ARANGES_SECTION)) |
c906108c | 1152 | { |
dce234bc PP |
1153 | dwarf2_per_objfile->aranges.asection = sectp; |
1154 | dwarf2_per_objfile->aranges.size = bfd_get_section_size (sectp); | |
c906108c | 1155 | } |
dce234bc | 1156 | else if (section_is_p (sectp->name, LOC_SECTION)) |
c906108c | 1157 | { |
dce234bc PP |
1158 | dwarf2_per_objfile->loc.asection = sectp; |
1159 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); | |
c906108c | 1160 | } |
dce234bc | 1161 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
c906108c | 1162 | { |
dce234bc PP |
1163 | dwarf2_per_objfile->macinfo.asection = sectp; |
1164 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); | |
c906108c | 1165 | } |
dce234bc | 1166 | else if (section_is_p (sectp->name, STR_SECTION)) |
c906108c | 1167 | { |
dce234bc PP |
1168 | dwarf2_per_objfile->str.asection = sectp; |
1169 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); | |
c906108c | 1170 | } |
dce234bc | 1171 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
b6af0555 | 1172 | { |
dce234bc PP |
1173 | dwarf2_per_objfile->frame.asection = sectp; |
1174 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); | |
b6af0555 | 1175 | } |
dce234bc | 1176 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
b6af0555 | 1177 | { |
3799ccc6 EZ |
1178 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1179 | if (aflag & SEC_HAS_CONTENTS) | |
1180 | { | |
dce234bc PP |
1181 | dwarf2_per_objfile->eh_frame.asection = sectp; |
1182 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); | |
3799ccc6 | 1183 | } |
b6af0555 | 1184 | } |
dce234bc | 1185 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
af34e669 | 1186 | { |
dce234bc PP |
1187 | dwarf2_per_objfile->ranges.asection = sectp; |
1188 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); | |
af34e669 | 1189 | } |
dce234bc | 1190 | |
72dca2f5 FR |
1191 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
1192 | && bfd_section_vma (abfd, sectp) == 0) | |
1193 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1194 | } |
1195 | ||
dce234bc PP |
1196 | /* Decompress a section that was compressed using zlib. Store the |
1197 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
233a11ab CS |
1198 | |
1199 | static void | |
dce234bc PP |
1200 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
1201 | gdb_byte **outbuf, bfd_size_type *outsize) | |
1202 | { | |
1203 | bfd *abfd = objfile->obfd; | |
1204 | #ifndef HAVE_ZLIB_H | |
1205 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
1206 | "is disabled in this copy of GDB"), | |
1207 | bfd_get_filename (abfd)); | |
1208 | #else | |
1209 | bfd_size_type compressed_size = bfd_get_section_size (sectp); | |
1210 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
1211 | bfd_size_type uncompressed_size; | |
1212 | gdb_byte *uncompressed_buffer; | |
1213 | z_stream strm; | |
1214 | int rc; | |
1215 | int header_size = 12; | |
1216 | ||
1217 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1218 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
1219 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1220 | bfd_get_filename (abfd)); | |
1221 | ||
1222 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
1223 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
1224 | if (compressed_size < header_size | |
1225 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
1226 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
1227 | bfd_get_filename (abfd)); | |
1228 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
1229 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
1230 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
1231 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
1232 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
1233 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
1234 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
1235 | uncompressed_size += compressed_buffer[11]; | |
1236 | ||
1237 | /* It is possible the section consists of several compressed | |
1238 | buffers concatenated together, so we uncompress in a loop. */ | |
1239 | strm.zalloc = NULL; | |
1240 | strm.zfree = NULL; | |
1241 | strm.opaque = NULL; | |
1242 | strm.avail_in = compressed_size - header_size; | |
1243 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
1244 | strm.avail_out = uncompressed_size; | |
1245 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
1246 | uncompressed_size); | |
1247 | rc = inflateInit (&strm); | |
1248 | while (strm.avail_in > 0) | |
1249 | { | |
1250 | if (rc != Z_OK) | |
1251 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
1252 | bfd_get_filename (abfd), rc); | |
1253 | strm.next_out = ((Bytef*) uncompressed_buffer | |
1254 | + (uncompressed_size - strm.avail_out)); | |
1255 | rc = inflate (&strm, Z_FINISH); | |
1256 | if (rc != Z_STREAM_END) | |
1257 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
1258 | bfd_get_filename (abfd), rc); | |
1259 | rc = inflateReset (&strm); | |
1260 | } | |
1261 | rc = inflateEnd (&strm); | |
1262 | if (rc != Z_OK | |
1263 | || strm.avail_out != 0) | |
1264 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
1265 | bfd_get_filename (abfd), rc); | |
1266 | ||
1267 | xfree (compressed_buffer); | |
1268 | *outbuf = uncompressed_buffer; | |
1269 | *outsize = uncompressed_size; | |
1270 | #endif | |
233a11ab CS |
1271 | } |
1272 | ||
dce234bc PP |
1273 | /* Read the contents of the section SECTP from object file specified by |
1274 | OBJFILE, store info about the section into INFO. | |
1275 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 1276 | |
dce234bc PP |
1277 | static void |
1278 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) | |
c906108c | 1279 | { |
dce234bc PP |
1280 | bfd *abfd = objfile->obfd; |
1281 | asection *sectp = info->asection; | |
1282 | gdb_byte *buf, *retbuf; | |
1283 | unsigned char header[4]; | |
c906108c | 1284 | |
dce234bc PP |
1285 | info->buffer = NULL; |
1286 | info->was_mmapped = 0; | |
188dd5d6 | 1287 | |
dce234bc PP |
1288 | if (info->asection == NULL || info->size == 0) |
1289 | return; | |
c906108c | 1290 | |
dce234bc PP |
1291 | /* Check if the file has a 4-byte header indicating compression. */ |
1292 | if (info->size > sizeof (header) | |
1293 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
1294 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
1295 | { | |
1296 | /* Upon decompression, update the buffer and its size. */ | |
1297 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
1298 | { | |
1299 | zlib_decompress_section (objfile, sectp, &info->buffer, | |
1300 | &info->size); | |
1301 | return; | |
1302 | } | |
1303 | } | |
4bdf3d34 | 1304 | |
dce234bc PP |
1305 | #ifdef HAVE_MMAP |
1306 | if (pagesize == 0) | |
1307 | pagesize = getpagesize (); | |
2e276125 | 1308 | |
dce234bc PP |
1309 | /* Only try to mmap sections which are large enough: we don't want to |
1310 | waste space due to fragmentation. Also, only try mmap for sections | |
1311 | without relocations. */ | |
1312 | ||
1313 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) | |
1314 | { | |
1315 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); | |
1316 | size_t map_length = info->size + sectp->filepos - pg_offset; | |
1317 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, | |
1318 | MAP_PRIVATE, pg_offset); | |
1319 | ||
1320 | if (retbuf != MAP_FAILED) | |
1321 | { | |
1322 | info->was_mmapped = 1; | |
1323 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; | |
1324 | return; | |
1325 | } | |
1326 | } | |
1327 | #endif | |
1328 | ||
1329 | /* If we get here, we are a normal, not-compressed section. */ | |
1330 | info->buffer = buf | |
1331 | = obstack_alloc (&objfile->objfile_obstack, info->size); | |
1332 | ||
1333 | /* When debugging .o files, we may need to apply relocations; see | |
1334 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
1335 | We never compress sections in .o files, so we only need to | |
1336 | try this when the section is not compressed. */ | |
1337 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); | |
1338 | if (retbuf != NULL) | |
1339 | { | |
1340 | info->buffer = retbuf; | |
1341 | return; | |
1342 | } | |
1343 | ||
1344 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
1345 | || bfd_bread (buf, info->size, abfd) != info->size) | |
1346 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
1347 | bfd_get_filename (abfd)); | |
1348 | } | |
1349 | ||
1350 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and | |
1351 | SECTION_NAME. */ | |
af34e669 | 1352 | |
dce234bc PP |
1353 | void |
1354 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, | |
1355 | asection **sectp, gdb_byte **bufp, | |
1356 | bfd_size_type *sizep) | |
1357 | { | |
1358 | struct dwarf2_per_objfile *data | |
1359 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
1360 | struct dwarf2_section_info *info; | |
1361 | if (section_is_p (section_name, EH_FRAME_SECTION)) | |
1362 | info = &data->eh_frame; | |
1363 | else if (section_is_p (section_name, FRAME_SECTION)) | |
1364 | info = &data->frame; | |
0d53c4c4 | 1365 | else |
dce234bc PP |
1366 | gdb_assert (0); |
1367 | ||
1368 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) | |
1369 | /* We haven't read this section in yet. Do it now. */ | |
1370 | dwarf2_read_section (objfile, info); | |
1371 | ||
1372 | *sectp = info->asection; | |
1373 | *bufp = info->buffer; | |
1374 | *sizep = info->size; | |
1375 | } | |
1376 | ||
1377 | /* Build a partial symbol table. */ | |
1378 | ||
1379 | void | |
1380 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) | |
1381 | { | |
1382 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); | |
1383 | dwarf2_read_section (objfile, &dwarf2_per_objfile->abbrev); | |
1384 | dwarf2_read_section (objfile, &dwarf2_per_objfile->line); | |
1385 | dwarf2_read_section (objfile, &dwarf2_per_objfile->str); | |
1386 | dwarf2_read_section (objfile, &dwarf2_per_objfile->macinfo); | |
1387 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); | |
1388 | dwarf2_read_section (objfile, &dwarf2_per_objfile->loc); | |
1389 | dwarf2_read_section (objfile, &dwarf2_per_objfile->eh_frame); | |
1390 | dwarf2_read_section (objfile, &dwarf2_per_objfile->frame); | |
0d53c4c4 | 1391 | |
ef96bde8 EZ |
1392 | if (mainline |
1393 | || (objfile->global_psymbols.size == 0 | |
1394 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1395 | { |
1396 | init_psymbol_list (objfile, 1024); | |
1397 | } | |
1398 | ||
1399 | #if 0 | |
1400 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1401 | { | |
d4f3574e | 1402 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1403 | .debug_pubnames sections */ |
1404 | ||
d4f3574e | 1405 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1406 | } |
1407 | else | |
1408 | #endif | |
1409 | /* only test this case for now */ | |
c5aa993b | 1410 | { |
c906108c | 1411 | /* In this case we have to work a bit harder */ |
d4f3574e | 1412 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1413 | } |
1414 | } | |
1415 | ||
1416 | #if 0 | |
1417 | /* Build the partial symbol table from the information in the | |
1418 | .debug_pubnames and .debug_aranges sections. */ | |
1419 | ||
1420 | static void | |
fba45db2 | 1421 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1422 | { |
1423 | bfd *abfd = objfile->obfd; | |
1424 | char *aranges_buffer, *pubnames_buffer; | |
1425 | char *aranges_ptr, *pubnames_ptr; | |
1426 | unsigned int entry_length, version, info_offset, info_size; | |
1427 | ||
1428 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1429 | dwarf_pubnames_section); |
c906108c | 1430 | pubnames_ptr = pubnames_buffer; |
dce234bc | 1431 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames.size) |
c906108c | 1432 | { |
891d2f0b | 1433 | unsigned int bytes_read; |
613e1657 | 1434 | |
c764a876 | 1435 | entry_length = read_initial_length (abfd, pubnames_ptr, &bytes_read); |
613e1657 | 1436 | pubnames_ptr += bytes_read; |
c906108c SS |
1437 | version = read_1_byte (abfd, pubnames_ptr); |
1438 | pubnames_ptr += 1; | |
1439 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1440 | pubnames_ptr += 4; | |
1441 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1442 | pubnames_ptr += 4; | |
1443 | } | |
1444 | ||
1445 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1446 | dwarf_aranges_section); |
c906108c SS |
1447 | |
1448 | } | |
1449 | #endif | |
1450 | ||
45452591 DE |
1451 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
1452 | ||
1453 | static inline int | |
1454 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) | |
1455 | { | |
1456 | unsigned int bottom = cu_header->offset; | |
1457 | unsigned int top = (cu_header->offset | |
1458 | + cu_header->length | |
1459 | + cu_header->initial_length_size); | |
1460 | return (offset >= bottom && offset < top); | |
1461 | } | |
1462 | ||
107d2387 | 1463 | /* Read in the comp unit header information from the debug_info at |
917c78fc | 1464 | info_ptr. */ |
107d2387 | 1465 | |
fe1b8b76 | 1466 | static gdb_byte * |
107d2387 | 1467 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1468 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1469 | { |
1470 | int signed_addr; | |
891d2f0b | 1471 | unsigned int bytes_read; |
c764a876 DE |
1472 | |
1473 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); | |
1474 | cu_header->initial_length_size = bytes_read; | |
1475 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; | |
613e1657 | 1476 | info_ptr += bytes_read; |
107d2387 AC |
1477 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1478 | info_ptr += 2; | |
613e1657 | 1479 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
c764a876 | 1480 | &bytes_read); |
613e1657 | 1481 | info_ptr += bytes_read; |
107d2387 AC |
1482 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1483 | info_ptr += 1; | |
1484 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1485 | if (signed_addr < 0) | |
8e65ff28 | 1486 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1487 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 | 1488 | cu_header->signed_addr_p = signed_addr; |
c764a876 | 1489 | |
107d2387 AC |
1490 | return info_ptr; |
1491 | } | |
1492 | ||
fe1b8b76 JB |
1493 | static gdb_byte * |
1494 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
72bf9492 DJ |
1495 | bfd *abfd) |
1496 | { | |
fe1b8b76 | 1497 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1498 | |
1499 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1500 | ||
2b949cb6 | 1501 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1502 | error (_("Dwarf Error: wrong version in compilation unit header " |
1503 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1504 | 2, bfd_get_filename (abfd)); |
1505 | ||
dce234bc | 1506 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
8a3fe4f8 AC |
1507 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1508 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 | 1509 | (long) header->abbrev_offset, |
dce234bc | 1510 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info.buffer), |
72bf9492 DJ |
1511 | bfd_get_filename (abfd)); |
1512 | ||
1513 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
dce234bc | 1514 | > dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
8a3fe4f8 AC |
1515 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1516 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 | 1517 | (long) header->length, |
dce234bc | 1518 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info.buffer), |
72bf9492 DJ |
1519 | bfd_get_filename (abfd)); |
1520 | ||
1521 | return info_ptr; | |
1522 | } | |
1523 | ||
aaa75496 JB |
1524 | /* Allocate a new partial symtab for file named NAME and mark this new |
1525 | partial symtab as being an include of PST. */ | |
1526 | ||
1527 | static void | |
1528 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1529 | struct objfile *objfile) | |
1530 | { | |
1531 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1532 | ||
1533 | subpst->section_offsets = pst->section_offsets; | |
1534 | subpst->textlow = 0; | |
1535 | subpst->texthigh = 0; | |
1536 | ||
1537 | subpst->dependencies = (struct partial_symtab **) | |
1538 | obstack_alloc (&objfile->objfile_obstack, | |
1539 | sizeof (struct partial_symtab *)); | |
1540 | subpst->dependencies[0] = pst; | |
1541 | subpst->number_of_dependencies = 1; | |
1542 | ||
1543 | subpst->globals_offset = 0; | |
1544 | subpst->n_global_syms = 0; | |
1545 | subpst->statics_offset = 0; | |
1546 | subpst->n_static_syms = 0; | |
1547 | subpst->symtab = NULL; | |
1548 | subpst->read_symtab = pst->read_symtab; | |
1549 | subpst->readin = 0; | |
1550 | ||
1551 | /* No private part is necessary for include psymtabs. This property | |
1552 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1553 | the regular ones. */ |
58a9656e | 1554 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1555 | } |
1556 | ||
1557 | /* Read the Line Number Program data and extract the list of files | |
1558 | included by the source file represented by PST. Build an include | |
1559 | partial symtab for each of these included files. | |
1560 | ||
1561 | This procedure assumes that there *is* a Line Number Program in | |
1562 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1563 | before calling this procedure. */ | |
1564 | ||
1565 | static void | |
1566 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1567 | struct partial_die_info *pdi, | |
1568 | struct partial_symtab *pst) | |
1569 | { | |
1570 | struct objfile *objfile = cu->objfile; | |
1571 | bfd *abfd = objfile->obfd; | |
1572 | struct line_header *lh; | |
1573 | ||
1574 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1575 | if (lh == NULL) | |
1576 | return; /* No linetable, so no includes. */ | |
1577 | ||
1578 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1579 | ||
1580 | free_line_header (lh); | |
1581 | } | |
1582 | ||
1583 | ||
c906108c SS |
1584 | /* Build the partial symbol table by doing a quick pass through the |
1585 | .debug_info and .debug_abbrev sections. */ | |
1586 | ||
1587 | static void | |
fba45db2 | 1588 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1589 | { |
1590 | /* Instead of reading this into a big buffer, we should probably use | |
1591 | mmap() on architectures that support it. (FIXME) */ | |
1592 | bfd *abfd = objfile->obfd; | |
fe1b8b76 JB |
1593 | gdb_byte *info_ptr; |
1594 | gdb_byte *beg_of_comp_unit; | |
c906108c SS |
1595 | struct partial_die_info comp_unit_die; |
1596 | struct partial_symtab *pst; | |
ae038cb0 | 1597 | struct cleanup *back_to; |
5734ee8b | 1598 | CORE_ADDR baseaddr; |
c906108c | 1599 | |
dce234bc | 1600 | info_ptr = dwarf2_per_objfile->info.buffer; |
c906108c | 1601 | |
ae038cb0 DJ |
1602 | /* Any cached compilation units will be linked by the per-objfile |
1603 | read_in_chain. Make sure to free them when we're done. */ | |
1604 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
1605 | ||
10b3939b DJ |
1606 | create_all_comp_units (objfile); |
1607 | ||
ff013f42 JK |
1608 | objfile->psymtabs_addrmap = addrmap_create_mutable |
1609 | (&objfile->objfile_obstack); | |
1610 | ||
6502dd73 | 1611 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1612 | length, only the individual functions to extract them (like |
72bf9492 | 1613 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1614 | the buffer is large enough to hold another complete object. |
1615 | ||
6502dd73 DJ |
1616 | At the moment, they don't actually check that. If .debug_info |
1617 | holds just one extra byte after the last compilation unit's dies, | |
1618 | then read_comp_unit_head will happily read off the end of the | |
1619 | buffer. read_partial_die is similarly casual. Those functions | |
1620 | should be fixed. | |
af703f96 JB |
1621 | |
1622 | For this loop condition, simply checking whether there's any data | |
1623 | left at all should be sufficient. */ | |
dce234bc PP |
1624 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
1625 | + dwarf2_per_objfile->info.size)) | |
c906108c | 1626 | { |
f3dd6933 | 1627 | struct cleanup *back_to_inner; |
e7c27a73 | 1628 | struct dwarf2_cu cu; |
72bf9492 DJ |
1629 | struct abbrev_info *abbrev; |
1630 | unsigned int bytes_read; | |
1631 | struct dwarf2_per_cu_data *this_cu; | |
1632 | ||
c906108c | 1633 | beg_of_comp_unit = info_ptr; |
c906108c | 1634 | |
72bf9492 DJ |
1635 | memset (&cu, 0, sizeof (cu)); |
1636 | ||
1637 | obstack_init (&cu.comp_unit_obstack); | |
1638 | ||
1639 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1640 | ||
e7c27a73 | 1641 | cu.objfile = objfile; |
72bf9492 | 1642 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1643 | |
57349743 | 1644 | /* Complete the cu_header */ |
dce234bc | 1645 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info.buffer; |
d00adf39 | 1646 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; |
57349743 | 1647 | |
e142c38c DJ |
1648 | cu.list_in_scope = &file_symbols; |
1649 | ||
c906108c | 1650 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1651 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1652 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 1653 | |
10b3939b | 1654 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); |
ae038cb0 | 1655 | |
c906108c | 1656 | /* Read the compilation unit die */ |
72bf9492 DJ |
1657 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1658 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1659 | abfd, info_ptr, &cu); | |
c906108c | 1660 | |
31ffec48 DJ |
1661 | if (comp_unit_die.tag == DW_TAG_partial_unit) |
1662 | { | |
1663 | info_ptr = (beg_of_comp_unit + cu.header.length | |
1664 | + cu.header.initial_length_size); | |
1665 | do_cleanups (back_to_inner); | |
1666 | continue; | |
1667 | } | |
1668 | ||
c906108c | 1669 | /* Set the language we're debugging */ |
e142c38c | 1670 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1671 | |
1672 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1673 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1674 | comp_unit_die.name ? comp_unit_die.name : "", |
ff013f42 JK |
1675 | /* TEXTLOW and TEXTHIGH are set below. */ |
1676 | 0, | |
c906108c SS |
1677 | objfile->global_psymbols.next, |
1678 | objfile->static_psymbols.next); | |
1679 | ||
ae038cb0 | 1680 | if (comp_unit_die.dirname) |
a683b3c0 TT |
1681 | pst->dirname = obsavestring (comp_unit_die.dirname, |
1682 | strlen (comp_unit_die.dirname), | |
1683 | &objfile->objfile_obstack); | |
57c22c6c | 1684 | |
10b3939b DJ |
1685 | pst->read_symtab_private = (char *) this_cu; |
1686 | ||
613e1657 | 1687 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1688 | |
1689 | /* Store the function that reads in the rest of the symbol table */ | |
1690 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1691 | ||
10b3939b DJ |
1692 | /* If this compilation unit was already read in, free the |
1693 | cached copy in order to read it in again. This is | |
1694 | necessary because we skipped some symbols when we first | |
1695 | read in the compilation unit (see load_partial_dies). | |
1696 | This problem could be avoided, but the benefit is | |
1697 | unclear. */ | |
1698 | if (this_cu->cu != NULL) | |
1699 | free_one_cached_comp_unit (this_cu->cu); | |
ae038cb0 | 1700 | |
10b3939b | 1701 | cu.per_cu = this_cu; |
ae038cb0 | 1702 | |
10b3939b DJ |
1703 | /* Note that this is a pointer to our stack frame, being |
1704 | added to a global data structure. It will be cleaned up | |
1705 | in free_stack_comp_unit when we finish with this | |
1706 | compilation unit. */ | |
1707 | this_cu->cu = &cu; | |
ae038cb0 | 1708 | |
10b3939b | 1709 | this_cu->psymtab = pst; |
ae038cb0 | 1710 | |
ff013f42 JK |
1711 | /* Possibly set the default values of LOWPC and HIGHPC from |
1712 | `DW_AT_ranges'. */ | |
1713 | if (cu.has_ranges_offset) | |
1714 | { | |
1715 | if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc, | |
1716 | &comp_unit_die.highpc, &cu, pst)) | |
1717 | comp_unit_die.has_pc_info = 1; | |
1718 | } | |
5734ee8b DJ |
1719 | else if (comp_unit_die.has_pc_info |
1720 | && comp_unit_die.lowpc < comp_unit_die.highpc) | |
1721 | /* Store the contiguous range if it is not empty; it can be empty for | |
1722 | CUs with no code. */ | |
1723 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
1724 | comp_unit_die.lowpc + baseaddr, | |
1725 | comp_unit_die.highpc + baseaddr - 1, pst); | |
ff013f42 | 1726 | |
c906108c SS |
1727 | /* Check if comp unit has_children. |
1728 | If so, read the rest of the partial symbols from this comp unit. | |
1729 | If not, there's no more debug_info for this comp unit. */ | |
1730 | if (comp_unit_die.has_children) | |
1731 | { | |
72bf9492 | 1732 | struct partial_die_info *first_die; |
5734ee8b | 1733 | CORE_ADDR lowpc, highpc; |
72bf9492 | 1734 | |
91c24f0a DC |
1735 | lowpc = ((CORE_ADDR) -1); |
1736 | highpc = ((CORE_ADDR) 0); | |
1737 | ||
72bf9492 DJ |
1738 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1739 | ||
5734ee8b DJ |
1740 | scan_partial_symbols (first_die, &lowpc, &highpc, |
1741 | ! comp_unit_die.has_pc_info, &cu); | |
c906108c | 1742 | |
91c24f0a DC |
1743 | /* If we didn't find a lowpc, set it to highpc to avoid |
1744 | complaints from `maint check'. */ | |
1745 | if (lowpc == ((CORE_ADDR) -1)) | |
1746 | lowpc = highpc; | |
72bf9492 | 1747 | |
c906108c SS |
1748 | /* If the compilation unit didn't have an explicit address range, |
1749 | then use the information extracted from its child dies. */ | |
0b010bcc | 1750 | if (! comp_unit_die.has_pc_info) |
c906108c | 1751 | { |
c5aa993b | 1752 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1753 | comp_unit_die.highpc = highpc; |
1754 | } | |
1755 | } | |
c5aa993b | 1756 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1757 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1758 | ||
1759 | pst->n_global_syms = objfile->global_psymbols.next - | |
1760 | (objfile->global_psymbols.list + pst->globals_offset); | |
1761 | pst->n_static_syms = objfile->static_psymbols.next - | |
1762 | (objfile->static_psymbols.list + pst->statics_offset); | |
1763 | sort_pst_symbols (pst); | |
1764 | ||
1765 | /* If there is already a psymtab or symtab for a file of this | |
1766 | name, remove it. (If there is a symtab, more drastic things | |
1767 | also happen.) This happens in VxWorks. */ | |
1768 | free_named_symtabs (pst->filename); | |
1769 | ||
dd373385 EZ |
1770 | info_ptr = beg_of_comp_unit + cu.header.length |
1771 | + cu.header.initial_length_size; | |
1772 | ||
aaa75496 JB |
1773 | if (comp_unit_die.has_stmt_list) |
1774 | { | |
1775 | /* Get the list of files included in the current compilation unit, | |
1776 | and build a psymtab for each of them. */ | |
1777 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1778 | } | |
1779 | ||
f3dd6933 | 1780 | do_cleanups (back_to_inner); |
c906108c | 1781 | } |
ff013f42 JK |
1782 | |
1783 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
1784 | &objfile->objfile_obstack); | |
1785 | ||
ae038cb0 DJ |
1786 | do_cleanups (back_to); |
1787 | } | |
1788 | ||
1789 | /* Load the DIEs for a secondary CU into memory. */ | |
1790 | ||
1791 | static void | |
1792 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |
1793 | { | |
1794 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 1795 | gdb_byte *info_ptr, *beg_of_comp_unit; |
ae038cb0 DJ |
1796 | struct partial_die_info comp_unit_die; |
1797 | struct dwarf2_cu *cu; | |
1798 | struct abbrev_info *abbrev; | |
1799 | unsigned int bytes_read; | |
1800 | struct cleanup *back_to; | |
1801 | ||
dce234bc | 1802 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
ae038cb0 DJ |
1803 | beg_of_comp_unit = info_ptr; |
1804 | ||
1805 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
1806 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
1807 | ||
1808 | obstack_init (&cu->comp_unit_obstack); | |
1809 | ||
1810 | cu->objfile = objfile; | |
1811 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |
1812 | ||
1813 | /* Complete the cu_header. */ | |
dce234bc | 1814 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info.buffer; |
d00adf39 | 1815 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
ae038cb0 DJ |
1816 | |
1817 | /* Read the abbrevs for this compilation unit into a table. */ | |
1818 | dwarf2_read_abbrevs (abfd, cu); | |
1819 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
1820 | ||
1821 | /* Read the compilation unit die. */ | |
1822 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1823 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1824 | abfd, info_ptr, cu); | |
1825 | ||
1826 | /* Set the language we're debugging. */ | |
1827 | set_cu_language (comp_unit_die.language, cu); | |
1828 | ||
1829 | /* Link this compilation unit into the compilation unit tree. */ | |
1830 | this_cu->cu = cu; | |
1831 | cu->per_cu = this_cu; | |
f792889a | 1832 | cu->type_hash = cu->per_cu->type_hash; |
ae038cb0 DJ |
1833 | |
1834 | /* Check if comp unit has_children. | |
1835 | If so, read the rest of the partial symbols from this comp unit. | |
1836 | If not, there's no more debug_info for this comp unit. */ | |
1837 | if (comp_unit_die.has_children) | |
1838 | load_partial_dies (abfd, info_ptr, 0, cu); | |
1839 | ||
1840 | do_cleanups (back_to); | |
1841 | } | |
1842 | ||
1843 | /* Create a list of all compilation units in OBJFILE. We do this only | |
1844 | if an inter-comp-unit reference is found; presumably if there is one, | |
1845 | there will be many, and one will occur early in the .debug_info section. | |
1846 | So there's no point in building this list incrementally. */ | |
1847 | ||
1848 | static void | |
1849 | create_all_comp_units (struct objfile *objfile) | |
1850 | { | |
1851 | int n_allocated; | |
1852 | int n_comp_units; | |
1853 | struct dwarf2_per_cu_data **all_comp_units; | |
dce234bc | 1854 | gdb_byte *info_ptr = dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
1855 | |
1856 | n_comp_units = 0; | |
1857 | n_allocated = 10; | |
1858 | all_comp_units = xmalloc (n_allocated | |
1859 | * sizeof (struct dwarf2_per_cu_data *)); | |
1860 | ||
dce234bc | 1861 | while (info_ptr < dwarf2_per_objfile->info.buffer + dwarf2_per_objfile->info.size) |
ae038cb0 | 1862 | { |
c764a876 | 1863 | unsigned int length, initial_length_size; |
fe1b8b76 | 1864 | gdb_byte *beg_of_comp_unit; |
ae038cb0 | 1865 | struct dwarf2_per_cu_data *this_cu; |
c764a876 | 1866 | unsigned int offset; |
ae038cb0 | 1867 | |
dce234bc | 1868 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
ae038cb0 DJ |
1869 | |
1870 | /* Read just enough information to find out where the next | |
1871 | compilation unit is. */ | |
c764a876 DE |
1872 | length = read_initial_length (objfile->obfd, info_ptr, |
1873 | &initial_length_size); | |
ae038cb0 DJ |
1874 | |
1875 | /* Save the compilation unit for later lookup. */ | |
1876 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
1877 | sizeof (struct dwarf2_per_cu_data)); | |
1878 | memset (this_cu, 0, sizeof (*this_cu)); | |
1879 | this_cu->offset = offset; | |
c764a876 | 1880 | this_cu->length = length + initial_length_size; |
ae038cb0 DJ |
1881 | |
1882 | if (n_comp_units == n_allocated) | |
1883 | { | |
1884 | n_allocated *= 2; | |
1885 | all_comp_units = xrealloc (all_comp_units, | |
1886 | n_allocated | |
1887 | * sizeof (struct dwarf2_per_cu_data *)); | |
1888 | } | |
1889 | all_comp_units[n_comp_units++] = this_cu; | |
1890 | ||
1891 | info_ptr = info_ptr + this_cu->length; | |
1892 | } | |
1893 | ||
1894 | dwarf2_per_objfile->all_comp_units | |
1895 | = obstack_alloc (&objfile->objfile_obstack, | |
1896 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1897 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
1898 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1899 | xfree (all_comp_units); | |
1900 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
1901 | } |
1902 | ||
5734ee8b DJ |
1903 | /* Process all loaded DIEs for compilation unit CU, starting at |
1904 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation | |
1905 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or | |
1906 | DW_AT_ranges). If NEED_PC is set, then this function will set | |
1907 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU | |
1908 | and record the covered ranges in the addrmap. */ | |
c906108c | 1909 | |
72bf9492 DJ |
1910 | static void |
1911 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
5734ee8b | 1912 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
c906108c | 1913 | { |
e7c27a73 | 1914 | struct objfile *objfile = cu->objfile; |
c906108c | 1915 | bfd *abfd = objfile->obfd; |
72bf9492 | 1916 | struct partial_die_info *pdi; |
c906108c | 1917 | |
91c24f0a DC |
1918 | /* Now, march along the PDI's, descending into ones which have |
1919 | interesting children but skipping the children of the other ones, | |
1920 | until we reach the end of the compilation unit. */ | |
c906108c | 1921 | |
72bf9492 | 1922 | pdi = first_die; |
91c24f0a | 1923 | |
72bf9492 DJ |
1924 | while (pdi != NULL) |
1925 | { | |
1926 | fixup_partial_die (pdi, cu); | |
c906108c | 1927 | |
91c24f0a DC |
1928 | /* Anonymous namespaces have no name but have interesting |
1929 | children, so we need to look at them. Ditto for anonymous | |
1930 | enums. */ | |
933c6fe4 | 1931 | |
72bf9492 DJ |
1932 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1933 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1934 | { |
72bf9492 | 1935 | switch (pdi->tag) |
c906108c SS |
1936 | { |
1937 | case DW_TAG_subprogram: | |
5734ee8b | 1938 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
c906108c SS |
1939 | break; |
1940 | case DW_TAG_variable: | |
1941 | case DW_TAG_typedef: | |
91c24f0a | 1942 | case DW_TAG_union_type: |
72bf9492 | 1943 | if (!pdi->is_declaration) |
63d06c5c | 1944 | { |
72bf9492 | 1945 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1946 | } |
1947 | break; | |
c906108c | 1948 | case DW_TAG_class_type: |
680b30c7 | 1949 | case DW_TAG_interface_type: |
c906108c | 1950 | case DW_TAG_structure_type: |
72bf9492 | 1951 | if (!pdi->is_declaration) |
c906108c | 1952 | { |
72bf9492 | 1953 | add_partial_symbol (pdi, cu); |
c906108c SS |
1954 | } |
1955 | break; | |
91c24f0a | 1956 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1957 | if (!pdi->is_declaration) |
1958 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1959 | break; |
1960 | case DW_TAG_base_type: | |
a02abb62 | 1961 | case DW_TAG_subrange_type: |
c906108c | 1962 | /* File scope base type definitions are added to the partial |
c5aa993b | 1963 | symbol table. */ |
72bf9492 | 1964 | add_partial_symbol (pdi, cu); |
c906108c | 1965 | break; |
d9fa45fe | 1966 | case DW_TAG_namespace: |
5734ee8b | 1967 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
91c24f0a | 1968 | break; |
5d7cb8df JK |
1969 | case DW_TAG_module: |
1970 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); | |
1971 | break; | |
c906108c SS |
1972 | default: |
1973 | break; | |
1974 | } | |
1975 | } | |
1976 | ||
72bf9492 DJ |
1977 | /* If the die has a sibling, skip to the sibling. */ |
1978 | ||
1979 | pdi = pdi->die_sibling; | |
1980 | } | |
1981 | } | |
1982 | ||
1983 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1984 | |
72bf9492 | 1985 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
1986 | name is concatenated with "::" and the partial DIE's name. For |
1987 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
1988 | Enumerators are an exception; they use the scope of their parent |
1989 | enumeration type, i.e. the name of the enumeration type is not | |
1990 | prepended to the enumerator. | |
91c24f0a | 1991 | |
72bf9492 DJ |
1992 | There are two complexities. One is DW_AT_specification; in this |
1993 | case "parent" means the parent of the target of the specification, | |
1994 | instead of the direct parent of the DIE. The other is compilers | |
1995 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1996 | the fully qualified name of structure types from their members' | |
1997 | linkage names. This must be done using the DIE's children rather | |
1998 | than the children of any DW_AT_specification target. We only need | |
1999 | to do this for structures at the top level, i.e. if the target of | |
2000 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
2001 | have a parent. */ | |
2002 | ||
2003 | /* Compute the scope prefix associated with PDI's parent, in | |
2004 | compilation unit CU. The result will be allocated on CU's | |
2005 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
2006 | field. NULL is returned if no prefix is necessary. */ | |
2007 | static char * | |
2008 | partial_die_parent_scope (struct partial_die_info *pdi, | |
2009 | struct dwarf2_cu *cu) | |
2010 | { | |
2011 | char *grandparent_scope; | |
2012 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 2013 | |
72bf9492 DJ |
2014 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
2015 | then this means the parent of the specification DIE. */ | |
2016 | ||
2017 | real_pdi = pdi; | |
72bf9492 | 2018 | while (real_pdi->has_specification) |
10b3939b | 2019 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
2020 | |
2021 | parent = real_pdi->die_parent; | |
2022 | if (parent == NULL) | |
2023 | return NULL; | |
2024 | ||
2025 | if (parent->scope_set) | |
2026 | return parent->scope; | |
2027 | ||
2028 | fixup_partial_die (parent, cu); | |
2029 | ||
10b3939b | 2030 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
2031 | |
2032 | if (parent->tag == DW_TAG_namespace | |
2033 | || parent->tag == DW_TAG_structure_type | |
2034 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 2035 | || parent->tag == DW_TAG_interface_type |
72bf9492 DJ |
2036 | || parent->tag == DW_TAG_union_type) |
2037 | { | |
2038 | if (grandparent_scope == NULL) | |
2039 | parent->scope = parent->name; | |
2040 | else | |
987504bb JJ |
2041 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
2042 | parent->name, cu); | |
72bf9492 DJ |
2043 | } |
2044 | else if (parent->tag == DW_TAG_enumeration_type) | |
2045 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
2046 | parent->scope = grandparent_scope; | |
2047 | else | |
2048 | { | |
2049 | /* FIXME drow/2004-04-01: What should we be doing with | |
2050 | function-local names? For partial symbols, we should probably be | |
2051 | ignoring them. */ | |
2052 | complaint (&symfile_complaints, | |
e2e0b3e5 | 2053 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
2054 | parent->tag, pdi->offset); |
2055 | parent->scope = grandparent_scope; | |
c906108c SS |
2056 | } |
2057 | ||
72bf9492 DJ |
2058 | parent->scope_set = 1; |
2059 | return parent->scope; | |
2060 | } | |
2061 | ||
2062 | /* Return the fully scoped name associated with PDI, from compilation unit | |
2063 | CU. The result will be allocated with malloc. */ | |
2064 | static char * | |
2065 | partial_die_full_name (struct partial_die_info *pdi, | |
2066 | struct dwarf2_cu *cu) | |
2067 | { | |
2068 | char *parent_scope; | |
2069 | ||
2070 | parent_scope = partial_die_parent_scope (pdi, cu); | |
2071 | if (parent_scope == NULL) | |
2072 | return NULL; | |
2073 | else | |
987504bb | 2074 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
2075 | } |
2076 | ||
2077 | static void | |
72bf9492 | 2078 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 2079 | { |
e7c27a73 | 2080 | struct objfile *objfile = cu->objfile; |
c906108c | 2081 | CORE_ADDR addr = 0; |
decbce07 | 2082 | char *actual_name = NULL; |
72bf9492 | 2083 | const char *my_prefix; |
5c4e30ca | 2084 | const struct partial_symbol *psym = NULL; |
e142c38c | 2085 | CORE_ADDR baseaddr; |
72bf9492 | 2086 | int built_actual_name = 0; |
e142c38c DJ |
2087 | |
2088 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2089 | |
72bf9492 | 2090 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 2091 | { |
72bf9492 DJ |
2092 | actual_name = partial_die_full_name (pdi, cu); |
2093 | if (actual_name) | |
2094 | built_actual_name = 1; | |
63d06c5c DC |
2095 | } |
2096 | ||
72bf9492 DJ |
2097 | if (actual_name == NULL) |
2098 | actual_name = pdi->name; | |
2099 | ||
c906108c SS |
2100 | switch (pdi->tag) |
2101 | { | |
2102 | case DW_TAG_subprogram: | |
2cfa0c8d | 2103 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 2104 | { |
2cfa0c8d JB |
2105 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
2106 | of the global scope. But in Ada, we want to be able to access | |
2107 | nested procedures globally. So all Ada subprograms are stored | |
2108 | in the global scope. */ | |
38d518c9 | 2109 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2110 | mst_text, objfile); */ |
38d518c9 | 2111 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2112 | VAR_DOMAIN, LOC_BLOCK, |
2113 | &objfile->global_psymbols, | |
2114 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2115 | cu->language, objfile); |
c906108c SS |
2116 | } |
2117 | else | |
2118 | { | |
38d518c9 | 2119 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 2120 | mst_file_text, objfile); */ |
38d518c9 | 2121 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2122 | VAR_DOMAIN, LOC_BLOCK, |
2123 | &objfile->static_psymbols, | |
2124 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 2125 | cu->language, objfile); |
c906108c SS |
2126 | } |
2127 | break; | |
2128 | case DW_TAG_variable: | |
2129 | if (pdi->is_external) | |
2130 | { | |
2131 | /* Global Variable. | |
2132 | Don't enter into the minimal symbol tables as there is | |
2133 | a minimal symbol table entry from the ELF symbols already. | |
2134 | Enter into partial symbol table if it has a location | |
2135 | descriptor or a type. | |
2136 | If the location descriptor is missing, new_symbol will create | |
2137 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
2138 | be determined from the minimal symbol table whenever the variable | |
2139 | is referenced. | |
2140 | The address for the partial symbol table entry is not | |
2141 | used by GDB, but it comes in handy for debugging partial symbol | |
2142 | table building. */ | |
2143 | ||
2144 | if (pdi->locdesc) | |
e7c27a73 | 2145 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2146 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2147 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2148 | VAR_DOMAIN, LOC_STATIC, |
2149 | &objfile->global_psymbols, | |
2150 | 0, addr + baseaddr, | |
e142c38c | 2151 | cu->language, objfile); |
c906108c SS |
2152 | } |
2153 | else | |
2154 | { | |
2155 | /* Static Variable. Skip symbols without location descriptors. */ | |
2156 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2157 | { |
2158 | if (built_actual_name) | |
2159 | xfree (actual_name); | |
2160 | return; | |
2161 | } | |
e7c27a73 | 2162 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2163 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2164 | mst_file_data, objfile); */ |
38d518c9 | 2165 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2166 | VAR_DOMAIN, LOC_STATIC, |
2167 | &objfile->static_psymbols, | |
2168 | 0, addr + baseaddr, | |
e142c38c | 2169 | cu->language, objfile); |
c906108c SS |
2170 | } |
2171 | break; | |
2172 | case DW_TAG_typedef: | |
2173 | case DW_TAG_base_type: | |
a02abb62 | 2174 | case DW_TAG_subrange_type: |
38d518c9 | 2175 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2176 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2177 | &objfile->static_psymbols, |
e142c38c | 2178 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2179 | break; |
72bf9492 DJ |
2180 | case DW_TAG_namespace: |
2181 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
2182 | VAR_DOMAIN, LOC_TYPEDEF, | |
2183 | &objfile->global_psymbols, | |
2184 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2185 | break; | |
c906108c | 2186 | case DW_TAG_class_type: |
680b30c7 | 2187 | case DW_TAG_interface_type: |
c906108c SS |
2188 | case DW_TAG_structure_type: |
2189 | case DW_TAG_union_type: | |
2190 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2191 | /* Skip external references. The DWARF standard says in the section |
2192 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2193 | structure, union or class type is represented by a structure, | |
2194 | union or class entry that does not have a byte size attribute | |
2195 | and that has a DW_AT_declaration attribute." */ | |
2196 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2197 | { |
2198 | if (built_actual_name) | |
2199 | xfree (actual_name); | |
2200 | return; | |
2201 | } | |
fa4028e9 | 2202 | |
63d06c5c DC |
2203 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2204 | static vs. global. */ | |
38d518c9 | 2205 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2206 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2207 | (cu->language == language_cplus |
2208 | || cu->language == language_java) | |
63d06c5c DC |
2209 | ? &objfile->global_psymbols |
2210 | : &objfile->static_psymbols, | |
e142c38c | 2211 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2212 | |
c906108c SS |
2213 | break; |
2214 | case DW_TAG_enumerator: | |
38d518c9 | 2215 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2216 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2217 | (cu->language == language_cplus |
2218 | || cu->language == language_java) | |
f6fe98ef DJ |
2219 | ? &objfile->global_psymbols |
2220 | : &objfile->static_psymbols, | |
e142c38c | 2221 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2222 | break; |
2223 | default: | |
2224 | break; | |
2225 | } | |
5c4e30ca DC |
2226 | |
2227 | /* Check to see if we should scan the name for possible namespace | |
2228 | info. Only do this if this is C++, if we don't have namespace | |
2229 | debugging info in the file, if the psym is of an appropriate type | |
2230 | (otherwise we'll have psym == NULL), and if we actually had a | |
2231 | mangled name to begin with. */ | |
2232 | ||
72bf9492 DJ |
2233 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2234 | cases which do not set PSYM above? */ | |
2235 | ||
e142c38c | 2236 | if (cu->language == language_cplus |
72bf9492 | 2237 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2238 | && psym != NULL |
2239 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2240 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2241 | objfile); | |
72bf9492 DJ |
2242 | |
2243 | if (built_actual_name) | |
2244 | xfree (actual_name); | |
c906108c SS |
2245 | } |
2246 | ||
72bf9492 DJ |
2247 | /* Determine whether a die of type TAG living in a C++ class or |
2248 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2249 | name listed in the die. */ |
2250 | ||
2251 | static int | |
72bf9492 | 2252 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2253 | { |
63d06c5c DC |
2254 | switch (tag) |
2255 | { | |
72bf9492 | 2256 | case DW_TAG_namespace: |
63d06c5c DC |
2257 | case DW_TAG_typedef: |
2258 | case DW_TAG_class_type: | |
680b30c7 | 2259 | case DW_TAG_interface_type: |
63d06c5c DC |
2260 | case DW_TAG_structure_type: |
2261 | case DW_TAG_union_type: | |
2262 | case DW_TAG_enumeration_type: | |
2263 | case DW_TAG_enumerator: | |
2264 | return 1; | |
2265 | default: | |
2266 | return 0; | |
2267 | } | |
2268 | } | |
2269 | ||
5c4e30ca DC |
2270 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2271 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2272 | the name of the enclosing namespace. */ | |
91c24f0a | 2273 | |
72bf9492 DJ |
2274 | static void |
2275 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2276 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
5734ee8b | 2277 | int need_pc, struct dwarf2_cu *cu) |
91c24f0a | 2278 | { |
e7c27a73 | 2279 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2280 | |
72bf9492 | 2281 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2282 | |
72bf9492 | 2283 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2284 | |
2285 | /* Now scan partial symbols in that namespace. */ | |
2286 | ||
91c24f0a | 2287 | if (pdi->has_children) |
5734ee8b | 2288 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
91c24f0a DC |
2289 | } |
2290 | ||
5d7cb8df JK |
2291 | /* Read a partial die corresponding to a Fortran module. */ |
2292 | ||
2293 | static void | |
2294 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, | |
2295 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) | |
2296 | { | |
2297 | /* Now scan partial symbols in that module. | |
2298 | ||
2299 | FIXME: Support the separate Fortran module namespaces. */ | |
2300 | ||
2301 | if (pdi->has_children) | |
2302 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); | |
2303 | } | |
2304 | ||
bc30ff58 JB |
2305 | /* Read a partial die corresponding to a subprogram and create a partial |
2306 | symbol for that subprogram. When the CU language allows it, this | |
2307 | routine also defines a partial symbol for each nested subprogram | |
2308 | that this subprogram contains. | |
2309 | ||
2310 | DIE my also be a lexical block, in which case we simply search | |
2311 | recursively for suprograms defined inside that lexical block. | |
2312 | Again, this is only performed when the CU language allows this | |
2313 | type of definitions. */ | |
2314 | ||
2315 | static void | |
2316 | add_partial_subprogram (struct partial_die_info *pdi, | |
2317 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
5734ee8b | 2318 | int need_pc, struct dwarf2_cu *cu) |
bc30ff58 JB |
2319 | { |
2320 | if (pdi->tag == DW_TAG_subprogram) | |
2321 | { | |
2322 | if (pdi->has_pc_info) | |
2323 | { | |
2324 | if (pdi->lowpc < *lowpc) | |
2325 | *lowpc = pdi->lowpc; | |
2326 | if (pdi->highpc > *highpc) | |
2327 | *highpc = pdi->highpc; | |
5734ee8b DJ |
2328 | if (need_pc) |
2329 | { | |
2330 | CORE_ADDR baseaddr; | |
2331 | struct objfile *objfile = cu->objfile; | |
2332 | ||
2333 | baseaddr = ANOFFSET (objfile->section_offsets, | |
2334 | SECT_OFF_TEXT (objfile)); | |
2335 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
2336 | pdi->lowpc, pdi->highpc - 1, | |
2337 | cu->per_cu->psymtab); | |
2338 | } | |
bc30ff58 JB |
2339 | if (!pdi->is_declaration) |
2340 | add_partial_symbol (pdi, cu); | |
2341 | } | |
2342 | } | |
2343 | ||
2344 | if (! pdi->has_children) | |
2345 | return; | |
2346 | ||
2347 | if (cu->language == language_ada) | |
2348 | { | |
2349 | pdi = pdi->die_child; | |
2350 | while (pdi != NULL) | |
2351 | { | |
2352 | fixup_partial_die (pdi, cu); | |
2353 | if (pdi->tag == DW_TAG_subprogram | |
2354 | || pdi->tag == DW_TAG_lexical_block) | |
5734ee8b | 2355 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
bc30ff58 JB |
2356 | pdi = pdi->die_sibling; |
2357 | } | |
2358 | } | |
2359 | } | |
2360 | ||
72bf9492 DJ |
2361 | /* See if we can figure out if the class lives in a namespace. We do |
2362 | this by looking for a member function; its demangled name will | |
2363 | contain namespace info, if there is any. */ | |
63d06c5c | 2364 | |
72bf9492 DJ |
2365 | static void |
2366 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2367 | struct dwarf2_cu *cu) | |
63d06c5c | 2368 | { |
987504bb JJ |
2369 | if ((cu->language == language_cplus |
2370 | || cu->language == language_java) | |
72bf9492 | 2371 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2372 | && struct_pdi->has_children) |
2373 | { | |
63d06c5c DC |
2374 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2375 | what template types look like, because the demangler | |
2376 | frequently doesn't give the same name as the debug info. We | |
2377 | could fix this by only using the demangled name to get the | |
134d01f1 | 2378 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2379 | |
72bf9492 DJ |
2380 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2381 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2382 | |
72bf9492 DJ |
2383 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2384 | we should not do this. We'll prepend the parent's fully qualified | |
2385 | name when we create the partial symbol. */ | |
5d51ca54 | 2386 | |
72bf9492 | 2387 | real_pdi = struct_pdi; |
72bf9492 | 2388 | while (real_pdi->has_specification) |
10b3939b | 2389 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2390 | |
72bf9492 DJ |
2391 | if (real_pdi->die_parent != NULL) |
2392 | return; | |
63d06c5c | 2393 | |
72bf9492 DJ |
2394 | while (child_pdi != NULL) |
2395 | { | |
2396 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2397 | { |
72bf9492 | 2398 | char *actual_class_name |
31c27f77 JJ |
2399 | = language_class_name_from_physname (cu->language_defn, |
2400 | child_pdi->name); | |
63d06c5c | 2401 | if (actual_class_name != NULL) |
72bf9492 DJ |
2402 | { |
2403 | struct_pdi->name | |
2404 | = obsavestring (actual_class_name, | |
2405 | strlen (actual_class_name), | |
2406 | &cu->comp_unit_obstack); | |
2407 | xfree (actual_class_name); | |
2408 | } | |
63d06c5c DC |
2409 | break; |
2410 | } | |
72bf9492 DJ |
2411 | |
2412 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2413 | } |
2414 | } | |
63d06c5c DC |
2415 | } |
2416 | ||
91c24f0a DC |
2417 | /* Read a partial die corresponding to an enumeration type. */ |
2418 | ||
72bf9492 DJ |
2419 | static void |
2420 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2421 | struct dwarf2_cu *cu) | |
91c24f0a | 2422 | { |
e7c27a73 | 2423 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2424 | bfd *abfd = objfile->obfd; |
72bf9492 | 2425 | struct partial_die_info *pdi; |
91c24f0a DC |
2426 | |
2427 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2428 | add_partial_symbol (enum_pdi, cu); |
2429 | ||
2430 | pdi = enum_pdi->die_child; | |
2431 | while (pdi) | |
91c24f0a | 2432 | { |
72bf9492 | 2433 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2434 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2435 | else |
72bf9492 DJ |
2436 | add_partial_symbol (pdi, cu); |
2437 | pdi = pdi->die_sibling; | |
91c24f0a | 2438 | } |
91c24f0a DC |
2439 | } |
2440 | ||
4bb7a0a7 DJ |
2441 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2442 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2443 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2444 | the initial number. */ | |
2445 | ||
2446 | static struct abbrev_info * | |
fe1b8b76 | 2447 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2448 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2449 | { |
2450 | bfd *abfd = cu->objfile->obfd; | |
2451 | unsigned int abbrev_number; | |
2452 | struct abbrev_info *abbrev; | |
2453 | ||
2454 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2455 | ||
2456 | if (abbrev_number == 0) | |
2457 | return NULL; | |
2458 | ||
2459 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2460 | if (!abbrev) | |
2461 | { | |
8a3fe4f8 | 2462 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2463 | bfd_get_filename (abfd)); |
2464 | } | |
2465 | ||
2466 | return abbrev; | |
2467 | } | |
2468 | ||
2469 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2470 | pointer to the end of a series of DIEs, terminated by an empty | |
2471 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2472 | ||
fe1b8b76 JB |
2473 | static gdb_byte * |
2474 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2475 | { |
2476 | struct abbrev_info *abbrev; | |
2477 | unsigned int bytes_read; | |
2478 | ||
2479 | while (1) | |
2480 | { | |
2481 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2482 | if (abbrev == NULL) | |
2483 | return info_ptr + bytes_read; | |
2484 | else | |
2485 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2486 | } | |
2487 | } | |
2488 | ||
2489 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2490 | should point just after the initial uleb128 of a DIE, and the | |
2491 | abbrev corresponding to that skipped uleb128 should be passed in | |
2492 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2493 | children. */ | |
2494 | ||
fe1b8b76 JB |
2495 | static gdb_byte * |
2496 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2497 | struct dwarf2_cu *cu) |
2498 | { | |
2499 | unsigned int bytes_read; | |
2500 | struct attribute attr; | |
2501 | bfd *abfd = cu->objfile->obfd; | |
2502 | unsigned int form, i; | |
2503 | ||
2504 | for (i = 0; i < abbrev->num_attrs; i++) | |
2505 | { | |
2506 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2507 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2508 | { | |
2509 | read_attribute (&attr, &abbrev->attrs[i], | |
2510 | abfd, info_ptr, cu); | |
2511 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2512 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2513 | else |
dce234bc | 2514 | return dwarf2_per_objfile->info.buffer |
c764a876 | 2515 | + dwarf2_get_ref_die_offset (&attr); |
4bb7a0a7 DJ |
2516 | } |
2517 | ||
2518 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2519 | form = abbrev->attrs[i].form; | |
2520 | skip_attribute: | |
2521 | switch (form) | |
2522 | { | |
2523 | case DW_FORM_addr: | |
2524 | case DW_FORM_ref_addr: | |
2525 | info_ptr += cu->header.addr_size; | |
2526 | break; | |
2527 | case DW_FORM_data1: | |
2528 | case DW_FORM_ref1: | |
2529 | case DW_FORM_flag: | |
2530 | info_ptr += 1; | |
2531 | break; | |
2532 | case DW_FORM_data2: | |
2533 | case DW_FORM_ref2: | |
2534 | info_ptr += 2; | |
2535 | break; | |
2536 | case DW_FORM_data4: | |
2537 | case DW_FORM_ref4: | |
2538 | info_ptr += 4; | |
2539 | break; | |
2540 | case DW_FORM_data8: | |
2541 | case DW_FORM_ref8: | |
2542 | info_ptr += 8; | |
2543 | break; | |
2544 | case DW_FORM_string: | |
2545 | read_string (abfd, info_ptr, &bytes_read); | |
2546 | info_ptr += bytes_read; | |
2547 | break; | |
2548 | case DW_FORM_strp: | |
2549 | info_ptr += cu->header.offset_size; | |
2550 | break; | |
2551 | case DW_FORM_block: | |
2552 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2553 | info_ptr += bytes_read; | |
2554 | break; | |
2555 | case DW_FORM_block1: | |
2556 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2557 | break; | |
2558 | case DW_FORM_block2: | |
2559 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2560 | break; | |
2561 | case DW_FORM_block4: | |
2562 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2563 | break; | |
2564 | case DW_FORM_sdata: | |
2565 | case DW_FORM_udata: | |
2566 | case DW_FORM_ref_udata: | |
2567 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2568 | break; | |
2569 | case DW_FORM_indirect: | |
2570 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2571 | info_ptr += bytes_read; | |
2572 | /* We need to continue parsing from here, so just go back to | |
2573 | the top. */ | |
2574 | goto skip_attribute; | |
2575 | ||
2576 | default: | |
8a3fe4f8 | 2577 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2578 | dwarf_form_name (form), |
2579 | bfd_get_filename (abfd)); | |
2580 | } | |
2581 | } | |
2582 | ||
2583 | if (abbrev->has_children) | |
2584 | return skip_children (info_ptr, cu); | |
2585 | else | |
2586 | return info_ptr; | |
2587 | } | |
2588 | ||
2589 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2590 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2591 | |
fe1b8b76 JB |
2592 | static gdb_byte * |
2593 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2594 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2595 | { |
2596 | /* Do we know the sibling already? */ | |
72bf9492 | 2597 | |
91c24f0a DC |
2598 | if (orig_pdi->sibling) |
2599 | return orig_pdi->sibling; | |
2600 | ||
2601 | /* Are there any children to deal with? */ | |
2602 | ||
2603 | if (!orig_pdi->has_children) | |
2604 | return info_ptr; | |
2605 | ||
4bb7a0a7 | 2606 | /* Skip the children the long way. */ |
91c24f0a | 2607 | |
4bb7a0a7 | 2608 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2609 | } |
2610 | ||
c906108c SS |
2611 | /* Expand this partial symbol table into a full symbol table. */ |
2612 | ||
2613 | static void | |
fba45db2 | 2614 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2615 | { |
2616 | /* FIXME: This is barely more than a stub. */ | |
2617 | if (pst != NULL) | |
2618 | { | |
2619 | if (pst->readin) | |
2620 | { | |
8a3fe4f8 | 2621 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2622 | } |
2623 | else | |
2624 | { | |
2625 | if (info_verbose) | |
2626 | { | |
a3f17187 | 2627 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2628 | gdb_flush (gdb_stdout); |
2629 | } | |
2630 | ||
10b3939b DJ |
2631 | /* Restore our global data. */ |
2632 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2633 | dwarf2_objfile_data_key); | |
2634 | ||
b2ab525c KB |
2635 | /* If this psymtab is constructed from a debug-only objfile, the |
2636 | has_section_at_zero flag will not necessarily be correct. We | |
2637 | can get the correct value for this flag by looking at the data | |
2638 | associated with the (presumably stripped) associated objfile. */ | |
2639 | if (pst->objfile->separate_debug_objfile_backlink) | |
2640 | { | |
2641 | struct dwarf2_per_objfile *dpo_backlink | |
2642 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, | |
2643 | dwarf2_objfile_data_key); | |
2644 | dwarf2_per_objfile->has_section_at_zero | |
2645 | = dpo_backlink->has_section_at_zero; | |
2646 | } | |
2647 | ||
c906108c SS |
2648 | psymtab_to_symtab_1 (pst); |
2649 | ||
2650 | /* Finish up the debug error message. */ | |
2651 | if (info_verbose) | |
a3f17187 | 2652 | printf_filtered (_("done.\n")); |
c906108c SS |
2653 | } |
2654 | } | |
2655 | } | |
2656 | ||
10b3939b DJ |
2657 | /* Add PER_CU to the queue. */ |
2658 | ||
2659 | static void | |
03dd20cc | 2660 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
2661 | { |
2662 | struct dwarf2_queue_item *item; | |
2663 | ||
2664 | per_cu->queued = 1; | |
2665 | item = xmalloc (sizeof (*item)); | |
2666 | item->per_cu = per_cu; | |
2667 | item->next = NULL; | |
2668 | ||
2669 | if (dwarf2_queue == NULL) | |
2670 | dwarf2_queue = item; | |
2671 | else | |
2672 | dwarf2_queue_tail->next = item; | |
2673 | ||
2674 | dwarf2_queue_tail = item; | |
03dd20cc DJ |
2675 | |
2676 | /* Either PER_CU is the CU we want to process, or we're following a reference | |
2677 | pointing into PER_CU. Either way, we need its DIEs now. */ | |
2678 | load_full_comp_unit (item->per_cu, objfile); | |
2679 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2680 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
10b3939b DJ |
2681 | } |
2682 | ||
2683 | /* Process the queue. */ | |
2684 | ||
2685 | static void | |
2686 | process_queue (struct objfile *objfile) | |
2687 | { | |
2688 | struct dwarf2_queue_item *item, *next_item; | |
2689 | ||
03dd20cc DJ |
2690 | /* The queue starts out with one item, but following a DIE reference |
2691 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
2692 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
2693 | { | |
31ffec48 | 2694 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2695 | process_full_comp_unit (item->per_cu); |
2696 | ||
2697 | item->per_cu->queued = 0; | |
2698 | next_item = item->next; | |
2699 | xfree (item); | |
2700 | } | |
2701 | ||
2702 | dwarf2_queue_tail = NULL; | |
2703 | } | |
2704 | ||
2705 | /* Free all allocated queue entries. This function only releases anything if | |
2706 | an error was thrown; if the queue was processed then it would have been | |
2707 | freed as we went along. */ | |
2708 | ||
2709 | static void | |
2710 | dwarf2_release_queue (void *dummy) | |
2711 | { | |
2712 | struct dwarf2_queue_item *item, *last; | |
2713 | ||
2714 | item = dwarf2_queue; | |
2715 | while (item) | |
2716 | { | |
2717 | /* Anything still marked queued is likely to be in an | |
2718 | inconsistent state, so discard it. */ | |
2719 | if (item->per_cu->queued) | |
2720 | { | |
2721 | if (item->per_cu->cu != NULL) | |
2722 | free_one_cached_comp_unit (item->per_cu->cu); | |
2723 | item->per_cu->queued = 0; | |
2724 | } | |
2725 | ||
2726 | last = item; | |
2727 | item = item->next; | |
2728 | xfree (last); | |
2729 | } | |
2730 | ||
2731 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2732 | } | |
2733 | ||
2734 | /* Read in full symbols for PST, and anything it depends on. */ | |
2735 | ||
c906108c | 2736 | static void |
fba45db2 | 2737 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2738 | { |
10b3939b | 2739 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2740 | struct cleanup *back_to; |
aaa75496 JB |
2741 | int i; |
2742 | ||
2743 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2744 | if (!pst->dependencies[i]->readin) | |
2745 | { | |
2746 | /* Inform about additional files that need to be read in. */ | |
2747 | if (info_verbose) | |
2748 | { | |
a3f17187 | 2749 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2750 | fputs_filtered (" ", gdb_stdout); |
2751 | wrap_here (""); | |
2752 | fputs_filtered ("and ", gdb_stdout); | |
2753 | wrap_here (""); | |
2754 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2755 | wrap_here (""); /* Flush output */ | |
2756 | gdb_flush (gdb_stdout); | |
2757 | } | |
2758 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2759 | } | |
2760 | ||
10b3939b DJ |
2761 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2762 | ||
2763 | if (per_cu == NULL) | |
aaa75496 JB |
2764 | { |
2765 | /* It's an include file, no symbols to read for it. | |
2766 | Everything is in the parent symtab. */ | |
2767 | pst->readin = 1; | |
2768 | return; | |
2769 | } | |
c906108c | 2770 | |
10b3939b DJ |
2771 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2772 | ||
03dd20cc | 2773 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b DJ |
2774 | |
2775 | process_queue (pst->objfile); | |
2776 | ||
2777 | /* Age the cache, releasing compilation units that have not | |
2778 | been used recently. */ | |
2779 | age_cached_comp_units (); | |
2780 | ||
2781 | do_cleanups (back_to); | |
2782 | } | |
2783 | ||
2784 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2785 | ||
2786 | static struct dwarf2_cu * | |
31ffec48 | 2787 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2788 | { |
31ffec48 | 2789 | bfd *abfd = objfile->obfd; |
10b3939b | 2790 | struct dwarf2_cu *cu; |
c764a876 | 2791 | unsigned int offset; |
fe1b8b76 | 2792 | gdb_byte *info_ptr; |
10b3939b DJ |
2793 | struct cleanup *back_to, *free_cu_cleanup; |
2794 | struct attribute *attr; | |
2795 | CORE_ADDR baseaddr; | |
6502dd73 | 2796 | |
c906108c | 2797 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2798 | offset = per_cu->offset; |
6502dd73 | 2799 | |
dce234bc | 2800 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
63d06c5c | 2801 | |
10b3939b DJ |
2802 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2803 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2804 | |
10b3939b DJ |
2805 | /* If an error occurs while loading, release our storage. */ |
2806 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2807 | |
31ffec48 | 2808 | cu->objfile = objfile; |
e7c27a73 | 2809 | |
c906108c | 2810 | /* read in the comp_unit header */ |
10b3939b | 2811 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2812 | |
2813 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2814 | dwarf2_read_abbrevs (abfd, cu); |
2815 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2816 | ||
2817 | cu->header.offset = offset; | |
c906108c | 2818 | |
10b3939b DJ |
2819 | cu->per_cu = per_cu; |
2820 | per_cu->cu = cu; | |
f792889a | 2821 | cu->type_hash = per_cu->type_hash; |
e142c38c | 2822 | |
10b3939b DJ |
2823 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2824 | obstack_init (&cu->comp_unit_obstack); | |
2825 | ||
2826 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2827 | ||
2828 | /* We try not to read any attributes in this function, because not | |
2829 | all objfiles needed for references have been loaded yet, and symbol | |
2830 | table processing isn't initialized. But we have to set the CU language, | |
2831 | or we won't be able to build types correctly. */ | |
2832 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2833 | if (attr) | |
2834 | set_cu_language (DW_UNSND (attr), cu); | |
2835 | else | |
2836 | set_cu_language (language_minimal, cu); | |
2837 | ||
2838 | do_cleanups (back_to); | |
e142c38c | 2839 | |
10b3939b DJ |
2840 | /* We've successfully allocated this compilation unit. Let our caller |
2841 | clean it up when finished with it. */ | |
2842 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2843 | |
10b3939b DJ |
2844 | return cu; |
2845 | } | |
2846 | ||
2847 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2848 | already been loaded into memory. */ | |
2849 | ||
2850 | static void | |
2851 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2852 | { | |
2853 | struct partial_symtab *pst = per_cu->psymtab; | |
2854 | struct dwarf2_cu *cu = per_cu->cu; | |
2855 | struct objfile *objfile = pst->objfile; | |
2856 | bfd *abfd = objfile->obfd; | |
2857 | CORE_ADDR lowpc, highpc; | |
2858 | struct symtab *symtab; | |
2859 | struct cleanup *back_to; | |
2860 | struct attribute *attr; | |
2861 | CORE_ADDR baseaddr; | |
2862 | ||
2863 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2864 | ||
10b3939b DJ |
2865 | buildsym_init (); |
2866 | back_to = make_cleanup (really_free_pendings, NULL); | |
2867 | ||
2868 | cu->list_in_scope = &file_symbols; | |
c906108c | 2869 | |
0d53c4c4 DJ |
2870 | /* Find the base address of the compilation unit for range lists and |
2871 | location lists. It will normally be specified by DW_AT_low_pc. | |
2872 | In DWARF-3 draft 4, the base address could be overridden by | |
2873 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2874 | compilation units with discontinuous ranges. */ | |
2875 | ||
d00adf39 DE |
2876 | cu->base_known = 0; |
2877 | cu->base_address = 0; | |
0d53c4c4 | 2878 | |
10b3939b | 2879 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2880 | if (attr) |
2881 | { | |
d00adf39 DE |
2882 | cu->base_address = DW_ADDR (attr); |
2883 | cu->base_known = 1; | |
0d53c4c4 DJ |
2884 | } |
2885 | else | |
2886 | { | |
10b3939b | 2887 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2888 | if (attr) |
2889 | { | |
d00adf39 DE |
2890 | cu->base_address = DW_ADDR (attr); |
2891 | cu->base_known = 1; | |
0d53c4c4 DJ |
2892 | } |
2893 | } | |
2894 | ||
c906108c | 2895 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2896 | process_die (cu->dies, cu); |
c906108c | 2897 | |
fae299cd DC |
2898 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2899 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2900 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2901 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2902 | |
613e1657 | 2903 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2904 | |
2905 | /* Set symtab language to language from DW_AT_language. | |
2906 | If the compilation is from a C file generated by language preprocessors, | |
2907 | do not set the language if it was already deduced by start_subfile. */ | |
2908 | if (symtab != NULL | |
10b3939b | 2909 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2910 | { |
10b3939b | 2911 | symtab->language = cu->language; |
c906108c SS |
2912 | } |
2913 | pst->symtab = symtab; | |
2914 | pst->readin = 1; | |
c906108c SS |
2915 | |
2916 | do_cleanups (back_to); | |
2917 | } | |
2918 | ||
2919 | /* Process a die and its children. */ | |
2920 | ||
2921 | static void | |
e7c27a73 | 2922 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2923 | { |
2924 | switch (die->tag) | |
2925 | { | |
2926 | case DW_TAG_padding: | |
2927 | break; | |
2928 | case DW_TAG_compile_unit: | |
e7c27a73 | 2929 | read_file_scope (die, cu); |
c906108c SS |
2930 | break; |
2931 | case DW_TAG_subprogram: | |
e7c27a73 | 2932 | read_func_scope (die, cu); |
c906108c SS |
2933 | break; |
2934 | case DW_TAG_inlined_subroutine: | |
2935 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2936 | They could be used to set breakpoints on all inlined instances |
2937 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2938 | break; |
2939 | case DW_TAG_lexical_block: | |
14898363 L |
2940 | case DW_TAG_try_block: |
2941 | case DW_TAG_catch_block: | |
e7c27a73 | 2942 | read_lexical_block_scope (die, cu); |
c906108c SS |
2943 | break; |
2944 | case DW_TAG_class_type: | |
680b30c7 | 2945 | case DW_TAG_interface_type: |
c906108c SS |
2946 | case DW_TAG_structure_type: |
2947 | case DW_TAG_union_type: | |
134d01f1 | 2948 | process_structure_scope (die, cu); |
c906108c SS |
2949 | break; |
2950 | case DW_TAG_enumeration_type: | |
134d01f1 | 2951 | process_enumeration_scope (die, cu); |
c906108c | 2952 | break; |
134d01f1 | 2953 | |
f792889a DJ |
2954 | /* These dies have a type, but processing them does not create |
2955 | a symbol or recurse to process the children. Therefore we can | |
2956 | read them on-demand through read_type_die. */ | |
c906108c | 2957 | case DW_TAG_subroutine_type: |
72019c9c | 2958 | case DW_TAG_set_type: |
c906108c | 2959 | case DW_TAG_array_type: |
c906108c | 2960 | case DW_TAG_pointer_type: |
c906108c | 2961 | case DW_TAG_ptr_to_member_type: |
c906108c | 2962 | case DW_TAG_reference_type: |
c906108c | 2963 | case DW_TAG_string_type: |
c906108c | 2964 | break; |
134d01f1 | 2965 | |
c906108c | 2966 | case DW_TAG_base_type: |
a02abb62 | 2967 | case DW_TAG_subrange_type: |
cb249c71 | 2968 | case DW_TAG_typedef: |
134d01f1 DJ |
2969 | /* Add a typedef symbol for the type definition, if it has a |
2970 | DW_AT_name. */ | |
f792889a | 2971 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 2972 | break; |
c906108c | 2973 | case DW_TAG_common_block: |
e7c27a73 | 2974 | read_common_block (die, cu); |
c906108c SS |
2975 | break; |
2976 | case DW_TAG_common_inclusion: | |
2977 | break; | |
d9fa45fe | 2978 | case DW_TAG_namespace: |
63d06c5c | 2979 | processing_has_namespace_info = 1; |
e7c27a73 | 2980 | read_namespace (die, cu); |
d9fa45fe | 2981 | break; |
5d7cb8df JK |
2982 | case DW_TAG_module: |
2983 | read_module (die, cu); | |
2984 | break; | |
d9fa45fe DC |
2985 | case DW_TAG_imported_declaration: |
2986 | case DW_TAG_imported_module: | |
2987 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2988 | information contained in these. DW_TAG_imported_declaration | |
2989 | dies shouldn't have children; DW_TAG_imported_module dies | |
2990 | shouldn't in the C++ case, but conceivably could in the | |
d68209e4 | 2991 | Fortran case. */ |
63d06c5c | 2992 | processing_has_namespace_info = 1; |
d68209e4 JK |
2993 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
2994 | dwarf_tag_name (die->tag)); | |
d9fa45fe | 2995 | break; |
c906108c | 2996 | default: |
e7c27a73 | 2997 | new_symbol (die, NULL, cu); |
c906108c SS |
2998 | break; |
2999 | } | |
3000 | } | |
3001 | ||
0114d602 DJ |
3002 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
3003 | If scope qualifiers are appropriate they will be added. The result | |
3004 | will be allocated on the objfile_obstack, or NULL if the DIE does | |
3005 | not have a name. */ | |
3006 | ||
3007 | static const char * | |
3008 | dwarf2_full_name (struct die_info *die, struct dwarf2_cu *cu) | |
3009 | { | |
3010 | struct attribute *attr; | |
3011 | char *prefix, *name; | |
3012 | struct ui_file *buf = NULL; | |
3013 | ||
3014 | name = dwarf2_name (die, cu); | |
3015 | if (!name) | |
3016 | return NULL; | |
3017 | ||
3018 | /* These are the only languages we know how to qualify names in. */ | |
3019 | if (cu->language != language_cplus | |
3020 | && cu->language != language_java) | |
3021 | return name; | |
3022 | ||
3023 | /* If no prefix is necessary for this type of DIE, return the | |
3024 | unqualified name. The other three tags listed could be handled | |
3025 | in pdi_needs_namespace, but that requires broader changes. */ | |
3026 | if (!pdi_needs_namespace (die->tag) | |
3027 | && die->tag != DW_TAG_subprogram | |
3028 | && die->tag != DW_TAG_variable | |
3029 | && die->tag != DW_TAG_member) | |
3030 | return name; | |
3031 | ||
3032 | prefix = determine_prefix (die, cu); | |
3033 | if (*prefix != '\0') | |
3034 | name = typename_concat (&cu->objfile->objfile_obstack, prefix, | |
3035 | name, cu); | |
3036 | ||
3037 | return name; | |
3038 | } | |
3039 | ||
5fb290d7 | 3040 | static void |
e142c38c | 3041 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 3042 | { |
e142c38c | 3043 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
3044 | } |
3045 | ||
cb1df416 DJ |
3046 | static void |
3047 | free_cu_line_header (void *arg) | |
3048 | { | |
3049 | struct dwarf2_cu *cu = arg; | |
3050 | ||
3051 | free_line_header (cu->line_header); | |
3052 | cu->line_header = NULL; | |
3053 | } | |
3054 | ||
c906108c | 3055 | static void |
e7c27a73 | 3056 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3057 | { |
e7c27a73 DJ |
3058 | struct objfile *objfile = cu->objfile; |
3059 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 3060 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 3061 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
3062 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
3063 | struct attribute *attr; | |
e1024ff1 | 3064 | char *name = NULL; |
c906108c SS |
3065 | char *comp_dir = NULL; |
3066 | struct die_info *child_die; | |
3067 | bfd *abfd = objfile->obfd; | |
debd256d | 3068 | struct line_header *line_header = 0; |
e142c38c DJ |
3069 | CORE_ADDR baseaddr; |
3070 | ||
3071 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 3072 | |
fae299cd | 3073 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
3074 | |
3075 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
3076 | from finish_block. */ | |
2acceee2 | 3077 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
3078 | lowpc = highpc; |
3079 | lowpc += baseaddr; | |
3080 | highpc += baseaddr; | |
3081 | ||
39cbfefa DJ |
3082 | /* Find the filename. Do not use dwarf2_name here, since the filename |
3083 | is not a source language identifier. */ | |
e142c38c | 3084 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3085 | if (attr) |
3086 | { | |
3087 | name = DW_STRING (attr); | |
3088 | } | |
e1024ff1 | 3089 | |
e142c38c | 3090 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 3091 | if (attr) |
e1024ff1 DJ |
3092 | comp_dir = DW_STRING (attr); |
3093 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 3094 | { |
e1024ff1 DJ |
3095 | comp_dir = ldirname (name); |
3096 | if (comp_dir != NULL) | |
3097 | make_cleanup (xfree, comp_dir); | |
3098 | } | |
3099 | if (comp_dir != NULL) | |
3100 | { | |
3101 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
3102 | directory, get rid of it. */ | |
3103 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 3104 | |
e1024ff1 DJ |
3105 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
3106 | comp_dir = cp + 1; | |
c906108c SS |
3107 | } |
3108 | ||
e1024ff1 DJ |
3109 | if (name == NULL) |
3110 | name = "<unknown>"; | |
3111 | ||
e142c38c | 3112 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
3113 | if (attr) |
3114 | { | |
e142c38c | 3115 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
3116 | } |
3117 | ||
b0f35d58 DL |
3118 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
3119 | if (attr) | |
3120 | cu->producer = DW_STRING (attr); | |
303b6f5d | 3121 | |
c906108c SS |
3122 | /* We assume that we're processing GCC output. */ |
3123 | processing_gcc_compilation = 2; | |
c906108c | 3124 | |
df8a16a1 DJ |
3125 | processing_has_namespace_info = 0; |
3126 | ||
c906108c SS |
3127 | start_symtab (name, comp_dir, lowpc); |
3128 | record_debugformat ("DWARF 2"); | |
303b6f5d | 3129 | record_producer (cu->producer); |
c906108c | 3130 | |
e142c38c | 3131 | initialize_cu_func_list (cu); |
c906108c | 3132 | |
cb1df416 DJ |
3133 | /* Decode line number information if present. We do this before |
3134 | processing child DIEs, so that the line header table is available | |
3135 | for DW_AT_decl_file. */ | |
e142c38c | 3136 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
3137 | if (attr) |
3138 | { | |
debd256d | 3139 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 3140 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
3141 | if (line_header) |
3142 | { | |
cb1df416 DJ |
3143 | cu->line_header = line_header; |
3144 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 3145 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 3146 | } |
5fb290d7 | 3147 | } |
debd256d | 3148 | |
cb1df416 DJ |
3149 | /* Process all dies in compilation unit. */ |
3150 | if (die->child != NULL) | |
3151 | { | |
3152 | child_die = die->child; | |
3153 | while (child_die && child_die->tag) | |
3154 | { | |
3155 | process_die (child_die, cu); | |
3156 | child_die = sibling_die (child_die); | |
3157 | } | |
3158 | } | |
3159 | ||
2e276125 JB |
3160 | /* Decode macro information, if present. Dwarf 2 macro information |
3161 | refers to information in the line number info statement program | |
3162 | header, so we can only read it if we've read the header | |
3163 | successfully. */ | |
e142c38c | 3164 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 3165 | if (attr && line_header) |
2e276125 JB |
3166 | { |
3167 | unsigned int macro_offset = DW_UNSND (attr); | |
3168 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 3169 | comp_dir, abfd, cu); |
2e276125 | 3170 | } |
debd256d | 3171 | do_cleanups (back_to); |
5fb290d7 DJ |
3172 | } |
3173 | ||
3174 | static void | |
e142c38c DJ |
3175 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
3176 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
3177 | { |
3178 | struct function_range *thisfn; | |
3179 | ||
3180 | thisfn = (struct function_range *) | |
7b5a2f43 | 3181 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
3182 | thisfn->name = name; |
3183 | thisfn->lowpc = lowpc; | |
3184 | thisfn->highpc = highpc; | |
3185 | thisfn->seen_line = 0; | |
3186 | thisfn->next = NULL; | |
3187 | ||
e142c38c DJ |
3188 | if (cu->last_fn == NULL) |
3189 | cu->first_fn = thisfn; | |
5fb290d7 | 3190 | else |
e142c38c | 3191 | cu->last_fn->next = thisfn; |
5fb290d7 | 3192 | |
e142c38c | 3193 | cu->last_fn = thisfn; |
c906108c SS |
3194 | } |
3195 | ||
d389af10 JK |
3196 | /* qsort helper for inherit_abstract_dies. */ |
3197 | ||
3198 | static int | |
3199 | unsigned_int_compar (const void *ap, const void *bp) | |
3200 | { | |
3201 | unsigned int a = *(unsigned int *) ap; | |
3202 | unsigned int b = *(unsigned int *) bp; | |
3203 | ||
3204 | return (a > b) - (b > a); | |
3205 | } | |
3206 | ||
3207 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). | |
3208 | Inherit only the children of the DW_AT_abstract_origin DIE not being already | |
3209 | referenced by DW_AT_abstract_origin from the children of the current DIE. */ | |
3210 | ||
3211 | static void | |
3212 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) | |
3213 | { | |
3214 | struct die_info *child_die; | |
3215 | unsigned die_children_count; | |
3216 | /* CU offsets which were referenced by children of the current DIE. */ | |
3217 | unsigned *offsets; | |
3218 | unsigned *offsets_end, *offsetp; | |
3219 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ | |
3220 | struct die_info *origin_die; | |
3221 | /* Iterator of the ORIGIN_DIE children. */ | |
3222 | struct die_info *origin_child_die; | |
3223 | struct cleanup *cleanups; | |
3224 | struct attribute *attr; | |
3225 | ||
3226 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); | |
3227 | if (!attr) | |
3228 | return; | |
3229 | ||
3230 | origin_die = follow_die_ref (die, attr, &cu); | |
3231 | if (die->tag != origin_die->tag) | |
3232 | complaint (&symfile_complaints, | |
3233 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), | |
3234 | die->offset, origin_die->offset); | |
3235 | ||
3236 | child_die = die->child; | |
3237 | die_children_count = 0; | |
3238 | while (child_die && child_die->tag) | |
3239 | { | |
3240 | child_die = sibling_die (child_die); | |
3241 | die_children_count++; | |
3242 | } | |
3243 | offsets = xmalloc (sizeof (*offsets) * die_children_count); | |
3244 | cleanups = make_cleanup (xfree, offsets); | |
3245 | ||
3246 | offsets_end = offsets; | |
3247 | child_die = die->child; | |
3248 | while (child_die && child_die->tag) | |
3249 | { | |
3250 | attr = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); | |
3251 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract | |
3252 | counterpart may exist. */ | |
3253 | if (attr) | |
3254 | { | |
3255 | struct die_info *child_origin_die; | |
3256 | ||
3257 | child_origin_die = follow_die_ref (child_die, attr, &cu); | |
3258 | if (child_die->tag != child_origin_die->tag) | |
3259 | complaint (&symfile_complaints, | |
3260 | _("Child DIE 0x%x and its abstract origin 0x%x have " | |
3261 | "different tags"), child_die->offset, | |
3262 | child_origin_die->offset); | |
3263 | *offsets_end++ = child_origin_die->offset; | |
3264 | } | |
3265 | child_die = sibling_die (child_die); | |
3266 | } | |
3267 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), | |
3268 | unsigned_int_compar); | |
3269 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) | |
3270 | if (offsetp[-1] == *offsetp) | |
3271 | complaint (&symfile_complaints, _("Multiple children of DIE 0x%x refer " | |
3272 | "to DIE 0x%x as their abstract origin"), | |
3273 | die->offset, *offsetp); | |
3274 | ||
3275 | offsetp = offsets; | |
3276 | origin_child_die = origin_die->child; | |
3277 | while (origin_child_die && origin_child_die->tag) | |
3278 | { | |
3279 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ | |
3280 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) | |
3281 | offsetp++; | |
3282 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) | |
3283 | { | |
3284 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ | |
3285 | process_die (origin_child_die, cu); | |
3286 | } | |
3287 | origin_child_die = sibling_die (origin_child_die); | |
3288 | } | |
3289 | ||
3290 | do_cleanups (cleanups); | |
3291 | } | |
3292 | ||
c906108c | 3293 | static void |
e7c27a73 | 3294 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3295 | { |
e7c27a73 | 3296 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3297 | struct context_stack *new; |
c906108c SS |
3298 | CORE_ADDR lowpc; |
3299 | CORE_ADDR highpc; | |
3300 | struct die_info *child_die; | |
3301 | struct attribute *attr; | |
3302 | char *name; | |
e142c38c | 3303 | CORE_ADDR baseaddr; |
801e3a5b | 3304 | struct block *block; |
c906108c | 3305 | |
e142c38c DJ |
3306 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
3307 | ||
3308 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
3309 | |
3310 | /* Ignore functions with missing or empty names and functions with | |
3311 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 3312 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3313 | return; |
3314 | ||
3315 | lowpc += baseaddr; | |
3316 | highpc += baseaddr; | |
3317 | ||
5fb290d7 | 3318 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3319 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3320 | |
c906108c | 3321 | new = push_context (0, lowpc); |
f792889a | 3322 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3323 | |
4cecd739 DJ |
3324 | /* If there is a location expression for DW_AT_frame_base, record |
3325 | it. */ | |
e142c38c | 3326 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3327 | if (attr) |
c034e007 AC |
3328 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3329 | expression is being recorded directly in the function's symbol | |
3330 | and not in a separate frame-base object. I guess this hack is | |
3331 | to avoid adding some sort of frame-base adjunct/annex to the | |
3332 | function's symbol :-(. The problem with doing this is that it | |
3333 | results in a function symbol with a location expression that | |
3334 | has nothing to do with the location of the function, ouch! The | |
3335 | relationship should be: a function's symbol has-a frame base; a | |
3336 | frame-base has-a location expression. */ | |
e7c27a73 | 3337 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3338 | |
e142c38c | 3339 | cu->list_in_scope = &local_symbols; |
c906108c | 3340 | |
639d11d3 | 3341 | if (die->child != NULL) |
c906108c | 3342 | { |
639d11d3 | 3343 | child_die = die->child; |
c906108c SS |
3344 | while (child_die && child_die->tag) |
3345 | { | |
e7c27a73 | 3346 | process_die (child_die, cu); |
c906108c SS |
3347 | child_die = sibling_die (child_die); |
3348 | } | |
3349 | } | |
3350 | ||
d389af10 JK |
3351 | inherit_abstract_dies (die, cu); |
3352 | ||
c906108c SS |
3353 | new = pop_context (); |
3354 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3355 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3356 | lowpc, highpc, objfile); | |
3357 | ||
df8a16a1 DJ |
3358 | /* For C++, set the block's scope. */ |
3359 | if (cu->language == language_cplus) | |
3360 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, | |
0114d602 | 3361 | determine_prefix (die, cu), |
df8a16a1 DJ |
3362 | processing_has_namespace_info); |
3363 | ||
801e3a5b JB |
3364 | /* If we have address ranges, record them. */ |
3365 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3366 | |
3367 | /* In C++, we can have functions nested inside functions (e.g., when | |
3368 | a function declares a class that has methods). This means that | |
3369 | when we finish processing a function scope, we may need to go | |
3370 | back to building a containing block's symbol lists. */ | |
3371 | local_symbols = new->locals; | |
3372 | param_symbols = new->params; | |
3373 | ||
921e78cf JB |
3374 | /* If we've finished processing a top-level function, subsequent |
3375 | symbols go in the file symbol list. */ | |
3376 | if (outermost_context_p ()) | |
e142c38c | 3377 | cu->list_in_scope = &file_symbols; |
c906108c SS |
3378 | } |
3379 | ||
3380 | /* Process all the DIES contained within a lexical block scope. Start | |
3381 | a new scope, process the dies, and then close the scope. */ | |
3382 | ||
3383 | static void | |
e7c27a73 | 3384 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3385 | { |
e7c27a73 | 3386 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3387 | struct context_stack *new; |
c906108c SS |
3388 | CORE_ADDR lowpc, highpc; |
3389 | struct die_info *child_die; | |
e142c38c DJ |
3390 | CORE_ADDR baseaddr; |
3391 | ||
3392 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3393 | |
3394 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3395 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3396 | as multiple lexical blocks? Handling children in a sane way would | |
3397 | be nasty. Might be easier to properly extend generic blocks to | |
3398 | describe ranges. */ | |
e7c27a73 | 3399 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3400 | return; |
3401 | lowpc += baseaddr; | |
3402 | highpc += baseaddr; | |
3403 | ||
3404 | push_context (0, lowpc); | |
639d11d3 | 3405 | if (die->child != NULL) |
c906108c | 3406 | { |
639d11d3 | 3407 | child_die = die->child; |
c906108c SS |
3408 | while (child_die && child_die->tag) |
3409 | { | |
e7c27a73 | 3410 | process_die (child_die, cu); |
c906108c SS |
3411 | child_die = sibling_die (child_die); |
3412 | } | |
3413 | } | |
3414 | new = pop_context (); | |
3415 | ||
3416 | if (local_symbols != NULL) | |
3417 | { | |
801e3a5b JB |
3418 | struct block *block |
3419 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3420 | highpc, objfile); | |
3421 | ||
3422 | /* Note that recording ranges after traversing children, as we | |
3423 | do here, means that recording a parent's ranges entails | |
3424 | walking across all its children's ranges as they appear in | |
3425 | the address map, which is quadratic behavior. | |
3426 | ||
3427 | It would be nicer to record the parent's ranges before | |
3428 | traversing its children, simply overriding whatever you find | |
3429 | there. But since we don't even decide whether to create a | |
3430 | block until after we've traversed its children, that's hard | |
3431 | to do. */ | |
3432 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3433 | } |
3434 | local_symbols = new->locals; | |
3435 | } | |
3436 | ||
43039443 | 3437 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3438 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3439 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3440 | |
3441 | static int | |
3442 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3443 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3444 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3445 | { |
3446 | struct objfile *objfile = cu->objfile; | |
3447 | struct comp_unit_head *cu_header = &cu->header; | |
3448 | bfd *obfd = objfile->obfd; | |
3449 | unsigned int addr_size = cu_header->addr_size; | |
3450 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3451 | /* Base address selection entry. */ | |
3452 | CORE_ADDR base; | |
3453 | int found_base; | |
3454 | unsigned int dummy; | |
3455 | gdb_byte *buffer; | |
3456 | CORE_ADDR marker; | |
3457 | int low_set; | |
3458 | CORE_ADDR low = 0; | |
3459 | CORE_ADDR high = 0; | |
ff013f42 | 3460 | CORE_ADDR baseaddr; |
43039443 | 3461 | |
d00adf39 DE |
3462 | found_base = cu->base_known; |
3463 | base = cu->base_address; | |
43039443 | 3464 | |
dce234bc | 3465 | if (offset >= dwarf2_per_objfile->ranges.size) |
43039443 JK |
3466 | { |
3467 | complaint (&symfile_complaints, | |
3468 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
3469 | offset); | |
3470 | return 0; | |
3471 | } | |
dce234bc | 3472 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
43039443 JK |
3473 | |
3474 | /* Read in the largest possible address. */ | |
3475 | marker = read_address (obfd, buffer, cu, &dummy); | |
3476 | if ((marker & mask) == mask) | |
3477 | { | |
3478 | /* If we found the largest possible address, then | |
3479 | read the base address. */ | |
3480 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3481 | buffer += 2 * addr_size; | |
3482 | offset += 2 * addr_size; | |
3483 | found_base = 1; | |
3484 | } | |
3485 | ||
3486 | low_set = 0; | |
3487 | ||
e7030f15 | 3488 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 3489 | |
43039443 JK |
3490 | while (1) |
3491 | { | |
3492 | CORE_ADDR range_beginning, range_end; | |
3493 | ||
3494 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
3495 | buffer += addr_size; | |
3496 | range_end = read_address (obfd, buffer, cu, &dummy); | |
3497 | buffer += addr_size; | |
3498 | offset += 2 * addr_size; | |
3499 | ||
3500 | /* An end of list marker is a pair of zero addresses. */ | |
3501 | if (range_beginning == 0 && range_end == 0) | |
3502 | /* Found the end of list entry. */ | |
3503 | break; | |
3504 | ||
3505 | /* Each base address selection entry is a pair of 2 values. | |
3506 | The first is the largest possible address, the second is | |
3507 | the base address. Check for a base address here. */ | |
3508 | if ((range_beginning & mask) == mask) | |
3509 | { | |
3510 | /* If we found the largest possible address, then | |
3511 | read the base address. */ | |
3512 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3513 | found_base = 1; | |
3514 | continue; | |
3515 | } | |
3516 | ||
3517 | if (!found_base) | |
3518 | { | |
3519 | /* We have no valid base address for the ranges | |
3520 | data. */ | |
3521 | complaint (&symfile_complaints, | |
3522 | _("Invalid .debug_ranges data (no base address)")); | |
3523 | return 0; | |
3524 | } | |
3525 | ||
3526 | range_beginning += base; | |
3527 | range_end += base; | |
3528 | ||
ff013f42 JK |
3529 | if (ranges_pst != NULL && range_beginning < range_end) |
3530 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3531 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
3532 | ranges_pst); | |
3533 | ||
43039443 JK |
3534 | /* FIXME: This is recording everything as a low-high |
3535 | segment of consecutive addresses. We should have a | |
3536 | data structure for discontiguous block ranges | |
3537 | instead. */ | |
3538 | if (! low_set) | |
3539 | { | |
3540 | low = range_beginning; | |
3541 | high = range_end; | |
3542 | low_set = 1; | |
3543 | } | |
3544 | else | |
3545 | { | |
3546 | if (range_beginning < low) | |
3547 | low = range_beginning; | |
3548 | if (range_end > high) | |
3549 | high = range_end; | |
3550 | } | |
3551 | } | |
3552 | ||
3553 | if (! low_set) | |
3554 | /* If the first entry is an end-of-list marker, the range | |
3555 | describes an empty scope, i.e. no instructions. */ | |
3556 | return 0; | |
3557 | ||
3558 | if (low_return) | |
3559 | *low_return = low; | |
3560 | if (high_return) | |
3561 | *high_return = high; | |
3562 | return 1; | |
3563 | } | |
3564 | ||
af34e669 DJ |
3565 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3566 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3567 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3568 | static int |
af34e669 | 3569 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3570 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c SS |
3571 | { |
3572 | struct attribute *attr; | |
af34e669 DJ |
3573 | CORE_ADDR low = 0; |
3574 | CORE_ADDR high = 0; | |
3575 | int ret = 0; | |
c906108c | 3576 | |
e142c38c | 3577 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3578 | if (attr) |
af34e669 DJ |
3579 | { |
3580 | high = DW_ADDR (attr); | |
e142c38c | 3581 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3582 | if (attr) |
3583 | low = DW_ADDR (attr); | |
3584 | else | |
3585 | /* Found high w/o low attribute. */ | |
3586 | return 0; | |
3587 | ||
3588 | /* Found consecutive range of addresses. */ | |
3589 | ret = 1; | |
3590 | } | |
c906108c | 3591 | else |
af34e669 | 3592 | { |
e142c38c | 3593 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3594 | if (attr != NULL) |
3595 | { | |
af34e669 | 3596 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 3597 | .debug_ranges section. */ |
ff013f42 | 3598 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL)) |
af34e669 | 3599 | return 0; |
43039443 | 3600 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
3601 | ret = -1; |
3602 | } | |
3603 | } | |
c906108c SS |
3604 | |
3605 | if (high < low) | |
3606 | return 0; | |
3607 | ||
3608 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3609 | eliminate duplicate copies of functions and vtables and such. | |
3610 | The linker will arbitrarily choose one and discard the others. | |
3611 | The AT_*_pc values for such functions refer to local labels in | |
3612 | these sections. If the section from that file was discarded, the | |
3613 | labels are not in the output, so the relocs get a value of 0. | |
3614 | If this is a discarded function, mark the pc bounds as invalid, | |
3615 | so that GDB will ignore it. */ | |
72dca2f5 | 3616 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3617 | return 0; |
3618 | ||
3619 | *lowpc = low; | |
3620 | *highpc = high; | |
af34e669 | 3621 | return ret; |
c906108c SS |
3622 | } |
3623 | ||
b084d499 JB |
3624 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
3625 | its low and high PC addresses. Do nothing if these addresses could not | |
3626 | be determined. Otherwise, set LOWPC to the low address if it is smaller, | |
3627 | and HIGHPC to the high address if greater than HIGHPC. */ | |
3628 | ||
3629 | static void | |
3630 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, | |
3631 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3632 | struct dwarf2_cu *cu) | |
3633 | { | |
3634 | CORE_ADDR low, high; | |
3635 | struct die_info *child = die->child; | |
3636 | ||
3637 | if (dwarf2_get_pc_bounds (die, &low, &high, cu)) | |
3638 | { | |
3639 | *lowpc = min (*lowpc, low); | |
3640 | *highpc = max (*highpc, high); | |
3641 | } | |
3642 | ||
3643 | /* If the language does not allow nested subprograms (either inside | |
3644 | subprograms or lexical blocks), we're done. */ | |
3645 | if (cu->language != language_ada) | |
3646 | return; | |
3647 | ||
3648 | /* Check all the children of the given DIE. If it contains nested | |
3649 | subprograms, then check their pc bounds. Likewise, we need to | |
3650 | check lexical blocks as well, as they may also contain subprogram | |
3651 | definitions. */ | |
3652 | while (child && child->tag) | |
3653 | { | |
3654 | if (child->tag == DW_TAG_subprogram | |
3655 | || child->tag == DW_TAG_lexical_block) | |
3656 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); | |
3657 | child = sibling_die (child); | |
3658 | } | |
3659 | } | |
3660 | ||
fae299cd DC |
3661 | /* Get the low and high pc's represented by the scope DIE, and store |
3662 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3663 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3664 | ||
3665 | static void | |
3666 | get_scope_pc_bounds (struct die_info *die, | |
3667 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3668 | struct dwarf2_cu *cu) | |
3669 | { | |
3670 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3671 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3672 | CORE_ADDR current_low, current_high; | |
3673 | ||
3674 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3675 | { | |
3676 | best_low = current_low; | |
3677 | best_high = current_high; | |
3678 | } | |
3679 | else | |
3680 | { | |
3681 | struct die_info *child = die->child; | |
3682 | ||
3683 | while (child && child->tag) | |
3684 | { | |
3685 | switch (child->tag) { | |
3686 | case DW_TAG_subprogram: | |
b084d499 | 3687 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
fae299cd DC |
3688 | break; |
3689 | case DW_TAG_namespace: | |
3690 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3691 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3692 | that current GCC's always emit the DIEs corresponding | |
3693 | to definitions of methods of classes as children of a | |
3694 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3695 | the DIEs giving the declarations, which could be | |
3696 | anywhere). But I don't see any reason why the | |
3697 | standards says that they have to be there. */ | |
3698 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3699 | ||
3700 | if (current_low != ((CORE_ADDR) -1)) | |
3701 | { | |
3702 | best_low = min (best_low, current_low); | |
3703 | best_high = max (best_high, current_high); | |
3704 | } | |
3705 | break; | |
3706 | default: | |
3707 | /* Ignore. */ | |
3708 | break; | |
3709 | } | |
3710 | ||
3711 | child = sibling_die (child); | |
3712 | } | |
3713 | } | |
3714 | ||
3715 | *lowpc = best_low; | |
3716 | *highpc = best_high; | |
3717 | } | |
3718 | ||
801e3a5b JB |
3719 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
3720 | in DIE. */ | |
3721 | static void | |
3722 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
3723 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
3724 | { | |
3725 | struct attribute *attr; | |
3726 | ||
3727 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
3728 | if (attr) | |
3729 | { | |
3730 | CORE_ADDR high = DW_ADDR (attr); | |
3731 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3732 | if (attr) | |
3733 | { | |
3734 | CORE_ADDR low = DW_ADDR (attr); | |
3735 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
3736 | } | |
3737 | } | |
3738 | ||
3739 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
3740 | if (attr) | |
3741 | { | |
3742 | bfd *obfd = cu->objfile->obfd; | |
3743 | ||
3744 | /* The value of the DW_AT_ranges attribute is the offset of the | |
3745 | address range list in the .debug_ranges section. */ | |
3746 | unsigned long offset = DW_UNSND (attr); | |
dce234bc | 3747 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
801e3a5b JB |
3748 | |
3749 | /* For some target architectures, but not others, the | |
3750 | read_address function sign-extends the addresses it returns. | |
3751 | To recognize base address selection entries, we need a | |
3752 | mask. */ | |
3753 | unsigned int addr_size = cu->header.addr_size; | |
3754 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3755 | ||
3756 | /* The base address, to which the next pair is relative. Note | |
3757 | that this 'base' is a DWARF concept: most entries in a range | |
3758 | list are relative, to reduce the number of relocs against the | |
3759 | debugging information. This is separate from this function's | |
3760 | 'baseaddr' argument, which GDB uses to relocate debugging | |
3761 | information from a shared library based on the address at | |
3762 | which the library was loaded. */ | |
d00adf39 DE |
3763 | CORE_ADDR base = cu->base_address; |
3764 | int base_known = cu->base_known; | |
801e3a5b | 3765 | |
dce234bc | 3766 | if (offset >= dwarf2_per_objfile->ranges.size) |
801e3a5b JB |
3767 | { |
3768 | complaint (&symfile_complaints, | |
3769 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
3770 | offset); | |
3771 | return; | |
3772 | } | |
3773 | ||
3774 | for (;;) | |
3775 | { | |
3776 | unsigned int bytes_read; | |
3777 | CORE_ADDR start, end; | |
3778 | ||
3779 | start = read_address (obfd, buffer, cu, &bytes_read); | |
3780 | buffer += bytes_read; | |
3781 | end = read_address (obfd, buffer, cu, &bytes_read); | |
3782 | buffer += bytes_read; | |
3783 | ||
3784 | /* Did we find the end of the range list? */ | |
3785 | if (start == 0 && end == 0) | |
3786 | break; | |
3787 | ||
3788 | /* Did we find a base address selection entry? */ | |
3789 | else if ((start & base_select_mask) == base_select_mask) | |
3790 | { | |
3791 | base = end; | |
3792 | base_known = 1; | |
3793 | } | |
3794 | ||
3795 | /* We found an ordinary address range. */ | |
3796 | else | |
3797 | { | |
3798 | if (!base_known) | |
3799 | { | |
3800 | complaint (&symfile_complaints, | |
3801 | _("Invalid .debug_ranges data (no base address)")); | |
3802 | return; | |
3803 | } | |
3804 | ||
3805 | record_block_range (block, | |
3806 | baseaddr + base + start, | |
3807 | baseaddr + base + end - 1); | |
3808 | } | |
3809 | } | |
3810 | } | |
3811 | } | |
3812 | ||
c906108c SS |
3813 | /* Add an aggregate field to the field list. */ |
3814 | ||
3815 | static void | |
107d2387 | 3816 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3817 | struct dwarf2_cu *cu) |
3818 | { | |
3819 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 3820 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
3821 | struct nextfield *new_field; |
3822 | struct attribute *attr; | |
3823 | struct field *fp; | |
3824 | char *fieldname = ""; | |
3825 | ||
3826 | /* Allocate a new field list entry and link it in. */ | |
3827 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3828 | make_cleanup (xfree, new_field); |
c906108c SS |
3829 | memset (new_field, 0, sizeof (struct nextfield)); |
3830 | new_field->next = fip->fields; | |
3831 | fip->fields = new_field; | |
3832 | fip->nfields++; | |
3833 | ||
3834 | /* Handle accessibility and virtuality of field. | |
3835 | The default accessibility for members is public, the default | |
3836 | accessibility for inheritance is private. */ | |
3837 | if (die->tag != DW_TAG_inheritance) | |
3838 | new_field->accessibility = DW_ACCESS_public; | |
3839 | else | |
3840 | new_field->accessibility = DW_ACCESS_private; | |
3841 | new_field->virtuality = DW_VIRTUALITY_none; | |
3842 | ||
e142c38c | 3843 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3844 | if (attr) |
3845 | new_field->accessibility = DW_UNSND (attr); | |
3846 | if (new_field->accessibility != DW_ACCESS_public) | |
3847 | fip->non_public_fields = 1; | |
e142c38c | 3848 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3849 | if (attr) |
3850 | new_field->virtuality = DW_UNSND (attr); | |
3851 | ||
3852 | fp = &new_field->field; | |
a9a9bd0f | 3853 | |
e142c38c | 3854 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3855 | { |
a9a9bd0f DC |
3856 | /* Data member other than a C++ static data member. */ |
3857 | ||
c906108c | 3858 | /* Get type of field. */ |
e7c27a73 | 3859 | fp->type = die_type (die, cu); |
c906108c | 3860 | |
d6a843b5 | 3861 | SET_FIELD_BITPOS (*fp, 0); |
01ad7f36 | 3862 | |
c906108c | 3863 | /* Get bit size of field (zero if none). */ |
e142c38c | 3864 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3865 | if (attr) |
3866 | { | |
3867 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3868 | } | |
3869 | else | |
3870 | { | |
3871 | FIELD_BITSIZE (*fp) = 0; | |
3872 | } | |
3873 | ||
3874 | /* Get bit offset of field. */ | |
e142c38c | 3875 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3876 | if (attr) |
3877 | { | |
c6a0999f JB |
3878 | int byte_offset; |
3879 | ||
3690dd37 JB |
3880 | if (attr_form_is_section_offset (attr)) |
3881 | { | |
3882 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 3883 | byte_offset = 0; |
3690dd37 JB |
3884 | } |
3885 | else if (attr_form_is_constant (attr)) | |
c6a0999f | 3886 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
3690dd37 | 3887 | else |
c6a0999f JB |
3888 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
3889 | ||
d6a843b5 | 3890 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
c906108c | 3891 | } |
e142c38c | 3892 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3893 | if (attr) |
3894 | { | |
5e2b427d | 3895 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
3896 | { |
3897 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3898 | additional bit offset from the MSB of the containing |
3899 | anonymous object to the MSB of the field. We don't | |
3900 | have to do anything special since we don't need to | |
3901 | know the size of the anonymous object. */ | |
c906108c SS |
3902 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3903 | } | |
3904 | else | |
3905 | { | |
3906 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3907 | MSB of the anonymous object, subtract off the number of |
3908 | bits from the MSB of the field to the MSB of the | |
3909 | object, and then subtract off the number of bits of | |
3910 | the field itself. The result is the bit offset of | |
3911 | the LSB of the field. */ | |
c906108c SS |
3912 | int anonymous_size; |
3913 | int bit_offset = DW_UNSND (attr); | |
3914 | ||
e142c38c | 3915 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3916 | if (attr) |
3917 | { | |
3918 | /* The size of the anonymous object containing | |
3919 | the bit field is explicit, so use the | |
3920 | indicated size (in bytes). */ | |
3921 | anonymous_size = DW_UNSND (attr); | |
3922 | } | |
3923 | else | |
3924 | { | |
3925 | /* The size of the anonymous object containing | |
3926 | the bit field must be inferred from the type | |
3927 | attribute of the data member containing the | |
3928 | bit field. */ | |
3929 | anonymous_size = TYPE_LENGTH (fp->type); | |
3930 | } | |
3931 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3932 | - bit_offset - FIELD_BITSIZE (*fp); | |
3933 | } | |
3934 | } | |
3935 | ||
3936 | /* Get name of field. */ | |
39cbfefa DJ |
3937 | fieldname = dwarf2_name (die, cu); |
3938 | if (fieldname == NULL) | |
3939 | fieldname = ""; | |
d8151005 DJ |
3940 | |
3941 | /* The name is already allocated along with this objfile, so we don't | |
3942 | need to duplicate it for the type. */ | |
3943 | fp->name = fieldname; | |
c906108c SS |
3944 | |
3945 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3946 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3947 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3948 | { |
3949 | new_field->accessibility = DW_ACCESS_private; | |
3950 | fip->non_public_fields = 1; | |
3951 | } | |
3952 | } | |
a9a9bd0f | 3953 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3954 | { |
a9a9bd0f DC |
3955 | /* C++ static member. */ |
3956 | ||
3957 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3958 | is a declaration, but all versions of G++ as of this writing | |
3959 | (so through at least 3.2.1) incorrectly generate | |
3960 | DW_TAG_variable tags. */ | |
3961 | ||
c906108c | 3962 | char *physname; |
c906108c | 3963 | |
a9a9bd0f | 3964 | /* Get name of field. */ |
39cbfefa DJ |
3965 | fieldname = dwarf2_name (die, cu); |
3966 | if (fieldname == NULL) | |
c906108c SS |
3967 | return; |
3968 | ||
2df3850c | 3969 | /* Get physical name. */ |
e142c38c | 3970 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3971 | |
d8151005 DJ |
3972 | /* The name is already allocated along with this objfile, so we don't |
3973 | need to duplicate it for the type. */ | |
3974 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3975 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3976 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3977 | } |
3978 | else if (die->tag == DW_TAG_inheritance) | |
3979 | { | |
3980 | /* C++ base class field. */ | |
e142c38c | 3981 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3982 | if (attr) |
d6a843b5 JK |
3983 | SET_FIELD_BITPOS (*fp, decode_locdesc (DW_BLOCK (attr), cu) |
3984 | * bits_per_byte); | |
c906108c | 3985 | FIELD_BITSIZE (*fp) = 0; |
e7c27a73 | 3986 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3987 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3988 | fip->nbaseclasses++; | |
3989 | } | |
3990 | } | |
3991 | ||
3992 | /* Create the vector of fields, and attach it to the type. */ | |
3993 | ||
3994 | static void | |
fba45db2 | 3995 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3996 | struct dwarf2_cu *cu) |
c906108c SS |
3997 | { |
3998 | int nfields = fip->nfields; | |
3999 | ||
4000 | /* Record the field count, allocate space for the array of fields, | |
4001 | and create blank accessibility bitfields if necessary. */ | |
4002 | TYPE_NFIELDS (type) = nfields; | |
4003 | TYPE_FIELDS (type) = (struct field *) | |
4004 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
4005 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
4006 | ||
4007 | if (fip->non_public_fields) | |
4008 | { | |
4009 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4010 | ||
4011 | TYPE_FIELD_PRIVATE_BITS (type) = | |
4012 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4013 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
4014 | ||
4015 | TYPE_FIELD_PROTECTED_BITS (type) = | |
4016 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4017 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
4018 | ||
4019 | TYPE_FIELD_IGNORE_BITS (type) = | |
4020 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
4021 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
4022 | } | |
4023 | ||
4024 | /* If the type has baseclasses, allocate and clear a bit vector for | |
4025 | TYPE_FIELD_VIRTUAL_BITS. */ | |
4026 | if (fip->nbaseclasses) | |
4027 | { | |
4028 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 4029 | unsigned char *pointer; |
c906108c SS |
4030 | |
4031 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
4032 | pointer = TYPE_ALLOC (type, num_bytes); |
4033 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
4034 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
4035 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
4036 | } | |
4037 | ||
4038 | /* Copy the saved-up fields into the field vector. Start from the head | |
4039 | of the list, adding to the tail of the field array, so that they end | |
4040 | up in the same order in the array in which they were added to the list. */ | |
4041 | while (nfields-- > 0) | |
4042 | { | |
4043 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
4044 | switch (fip->fields->accessibility) | |
4045 | { | |
c5aa993b JM |
4046 | case DW_ACCESS_private: |
4047 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
4048 | break; | |
c906108c | 4049 | |
c5aa993b JM |
4050 | case DW_ACCESS_protected: |
4051 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
4052 | break; | |
c906108c | 4053 | |
c5aa993b JM |
4054 | case DW_ACCESS_public: |
4055 | break; | |
c906108c | 4056 | |
c5aa993b JM |
4057 | default: |
4058 | /* Unknown accessibility. Complain and treat it as public. */ | |
4059 | { | |
e2e0b3e5 | 4060 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 4061 | fip->fields->accessibility); |
c5aa993b JM |
4062 | } |
4063 | break; | |
c906108c SS |
4064 | } |
4065 | if (nfields < fip->nbaseclasses) | |
4066 | { | |
4067 | switch (fip->fields->virtuality) | |
4068 | { | |
c5aa993b JM |
4069 | case DW_VIRTUALITY_virtual: |
4070 | case DW_VIRTUALITY_pure_virtual: | |
4071 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
4072 | break; | |
c906108c SS |
4073 | } |
4074 | } | |
4075 | fip->fields = fip->fields->next; | |
4076 | } | |
4077 | } | |
4078 | ||
c906108c SS |
4079 | /* Add a member function to the proper fieldlist. */ |
4080 | ||
4081 | static void | |
107d2387 | 4082 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 4083 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 4084 | { |
e7c27a73 | 4085 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4086 | struct attribute *attr; |
4087 | struct fnfieldlist *flp; | |
4088 | int i; | |
4089 | struct fn_field *fnp; | |
4090 | char *fieldname; | |
4091 | char *physname; | |
4092 | struct nextfnfield *new_fnfield; | |
f792889a | 4093 | struct type *this_type; |
c906108c | 4094 | |
2df3850c | 4095 | /* Get name of member function. */ |
39cbfefa DJ |
4096 | fieldname = dwarf2_name (die, cu); |
4097 | if (fieldname == NULL) | |
2df3850c | 4098 | return; |
c906108c | 4099 | |
2df3850c | 4100 | /* Get the mangled name. */ |
e142c38c | 4101 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
4102 | |
4103 | /* Look up member function name in fieldlist. */ | |
4104 | for (i = 0; i < fip->nfnfields; i++) | |
4105 | { | |
27bfe10e | 4106 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
4107 | break; |
4108 | } | |
4109 | ||
4110 | /* Create new list element if necessary. */ | |
4111 | if (i < fip->nfnfields) | |
4112 | flp = &fip->fnfieldlists[i]; | |
4113 | else | |
4114 | { | |
4115 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4116 | { | |
4117 | fip->fnfieldlists = (struct fnfieldlist *) | |
4118 | xrealloc (fip->fnfieldlists, | |
4119 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4120 | * sizeof (struct fnfieldlist)); |
c906108c | 4121 | if (fip->nfnfields == 0) |
c13c43fd | 4122 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
4123 | } |
4124 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
4125 | flp->name = fieldname; | |
4126 | flp->length = 0; | |
4127 | flp->head = NULL; | |
4128 | fip->nfnfields++; | |
4129 | } | |
4130 | ||
4131 | /* Create a new member function field and chain it to the field list | |
4132 | entry. */ | |
4133 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 4134 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
4135 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
4136 | new_fnfield->next = flp->head; | |
4137 | flp->head = new_fnfield; | |
4138 | flp->length++; | |
4139 | ||
4140 | /* Fill in the member function field info. */ | |
4141 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
4142 | /* The name is already allocated along with this objfile, so we don't |
4143 | need to duplicate it for the type. */ | |
4144 | fnp->physname = physname ? physname : ""; | |
c906108c | 4145 | fnp->type = alloc_type (objfile); |
f792889a DJ |
4146 | this_type = read_type_die (die, cu); |
4147 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 4148 | { |
f792889a | 4149 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 4150 | |
f792889a | 4151 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
4152 | of the method itself (TYPE_CODE_METHOD). */ |
4153 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
4154 | TYPE_TARGET_TYPE (this_type), |
4155 | TYPE_FIELDS (this_type), | |
4156 | TYPE_NFIELDS (this_type), | |
4157 | TYPE_VARARGS (this_type)); | |
c906108c SS |
4158 | |
4159 | /* Handle static member functions. | |
c5aa993b JM |
4160 | Dwarf2 has no clean way to discern C++ static and non-static |
4161 | member functions. G++ helps GDB by marking the first | |
4162 | parameter for non-static member functions (which is the | |
4163 | this pointer) as artificial. We obtain this information | |
4164 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 4165 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
4166 | fnp->voffset = VOFFSET_STATIC; |
4167 | } | |
4168 | else | |
e2e0b3e5 | 4169 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 4170 | physname); |
c906108c SS |
4171 | |
4172 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 4173 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 4174 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
4175 | |
4176 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
4177 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
4178 | ||
4179 | /* Get accessibility. */ | |
e142c38c | 4180 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
4181 | if (attr) |
4182 | { | |
4183 | switch (DW_UNSND (attr)) | |
4184 | { | |
c5aa993b JM |
4185 | case DW_ACCESS_private: |
4186 | fnp->is_private = 1; | |
4187 | break; | |
4188 | case DW_ACCESS_protected: | |
4189 | fnp->is_protected = 1; | |
4190 | break; | |
c906108c SS |
4191 | } |
4192 | } | |
4193 | ||
b02dede2 | 4194 | /* Check for artificial methods. */ |
e142c38c | 4195 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
4196 | if (attr && DW_UNSND (attr) != 0) |
4197 | fnp->is_artificial = 1; | |
4198 | ||
c906108c | 4199 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 4200 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 4201 | if (attr) |
8e19ed76 PS |
4202 | { |
4203 | /* Support the .debug_loc offsets */ | |
4204 | if (attr_form_is_block (attr)) | |
4205 | { | |
e7c27a73 | 4206 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 4207 | } |
3690dd37 | 4208 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4209 | { |
4d3c2250 | 4210 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4211 | } |
4212 | else | |
4213 | { | |
4d3c2250 KB |
4214 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
4215 | fieldname); | |
8e19ed76 PS |
4216 | } |
4217 | } | |
c906108c SS |
4218 | } |
4219 | ||
4220 | /* Create the vector of member function fields, and attach it to the type. */ | |
4221 | ||
4222 | static void | |
fba45db2 | 4223 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 4224 | struct dwarf2_cu *cu) |
c906108c SS |
4225 | { |
4226 | struct fnfieldlist *flp; | |
4227 | int total_length = 0; | |
4228 | int i; | |
4229 | ||
4230 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
4231 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
4232 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
4233 | ||
4234 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
4235 | { | |
4236 | struct nextfnfield *nfp = flp->head; | |
4237 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
4238 | int k; | |
4239 | ||
4240 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
4241 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
4242 | fn_flp->fn_fields = (struct fn_field *) | |
4243 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
4244 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 4245 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
4246 | |
4247 | total_length += flp->length; | |
4248 | } | |
4249 | ||
4250 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
4251 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
4252 | } | |
4253 | ||
1168df01 JB |
4254 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
4255 | language, zero otherwise. */ | |
4256 | static int | |
4257 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
4258 | { | |
4259 | static const char vptr[] = "_vptr"; | |
987504bb | 4260 | static const char vtable[] = "vtable"; |
1168df01 | 4261 | |
987504bb JJ |
4262 | /* Look for the C++ and Java forms of the vtable. */ |
4263 | if ((cu->language == language_java | |
4264 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
4265 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
4266 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
4267 | return 1; |
4268 | ||
4269 | return 0; | |
4270 | } | |
4271 | ||
c0dd20ea DJ |
4272 | /* GCC outputs unnamed structures that are really pointers to member |
4273 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
4274 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
4275 | zero. |
4276 | ||
4277 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
4278 | This is GCC PR debug/28767. */ | |
c0dd20ea | 4279 | |
f792889a | 4280 | static struct type * |
c0dd20ea DJ |
4281 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
4282 | { | |
4283 | struct objfile *objfile = cu->objfile; | |
4284 | struct type *type; | |
4285 | struct die_info *pfn_die, *delta_die; | |
4286 | struct attribute *pfn_name, *delta_name; | |
4287 | struct type *pfn_type, *domain_type; | |
4288 | ||
4289 | /* Check for a structure with no name and two children. */ | |
4290 | if (die->tag != DW_TAG_structure_type | |
4291 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
4292 | || die->child == NULL | |
4293 | || die->child->sibling == NULL | |
4294 | || (die->child->sibling->sibling != NULL | |
4295 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 4296 | return NULL; |
c0dd20ea DJ |
4297 | |
4298 | /* Check for __pfn and __delta members. */ | |
4299 | pfn_die = die->child; | |
4300 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
4301 | if (pfn_die->tag != DW_TAG_member | |
4302 | || pfn_name == NULL | |
4303 | || DW_STRING (pfn_name) == NULL | |
4304 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 4305 | return NULL; |
c0dd20ea DJ |
4306 | |
4307 | delta_die = pfn_die->sibling; | |
4308 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
4309 | if (delta_die->tag != DW_TAG_member | |
4310 | || delta_name == NULL | |
4311 | || DW_STRING (delta_name) == NULL | |
4312 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 4313 | return NULL; |
c0dd20ea DJ |
4314 | |
4315 | /* Find the type of the method. */ | |
4316 | pfn_type = die_type (pfn_die, cu); | |
4317 | if (pfn_type == NULL | |
4318 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
4319 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 4320 | return NULL; |
c0dd20ea DJ |
4321 | |
4322 | /* Look for the "this" argument. */ | |
4323 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
4324 | if (TYPE_NFIELDS (pfn_type) == 0 | |
4325 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 4326 | return NULL; |
c0dd20ea DJ |
4327 | |
4328 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
4329 | type = alloc_type (objfile); | |
4330 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
4331 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
4332 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 4333 | type = lookup_methodptr_type (type); |
f792889a | 4334 | return set_die_type (die, type, cu); |
c0dd20ea | 4335 | } |
1168df01 | 4336 | |
c906108c SS |
4337 | /* Called when we find the DIE that starts a structure or union scope |
4338 | (definition) to process all dies that define the members of the | |
4339 | structure or union. | |
4340 | ||
4341 | NOTE: we need to call struct_type regardless of whether or not the | |
4342 | DIE has an at_name attribute, since it might be an anonymous | |
4343 | structure or union. This gets the type entered into our set of | |
4344 | user defined types. | |
4345 | ||
4346 | However, if the structure is incomplete (an opaque struct/union) | |
4347 | then suppress creating a symbol table entry for it since gdb only | |
4348 | wants to find the one with the complete definition. Note that if | |
4349 | it is complete, we just call new_symbol, which does it's own | |
4350 | checking about whether the struct/union is anonymous or not (and | |
4351 | suppresses creating a symbol table entry itself). */ | |
4352 | ||
f792889a | 4353 | static struct type * |
134d01f1 | 4354 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4355 | { |
e7c27a73 | 4356 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4357 | struct type *type; |
4358 | struct attribute *attr; | |
39cbfefa | 4359 | char *name; |
0114d602 | 4360 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
c906108c | 4361 | |
f792889a DJ |
4362 | type = quirk_gcc_member_function_pointer (die, cu); |
4363 | if (type) | |
4364 | return type; | |
c906108c | 4365 | |
c0dd20ea | 4366 | type = alloc_type (objfile); |
c906108c | 4367 | INIT_CPLUS_SPECIFIC (type); |
39cbfefa DJ |
4368 | name = dwarf2_name (die, cu); |
4369 | if (name != NULL) | |
c906108c | 4370 | { |
987504bb JJ |
4371 | if (cu->language == language_cplus |
4372 | || cu->language == language_java) | |
63d06c5c | 4373 | { |
0114d602 DJ |
4374 | const char *new_prefix = determine_class_name (die, cu); |
4375 | TYPE_TAG_NAME (type) = (char *) new_prefix; | |
63d06c5c DC |
4376 | } |
4377 | else | |
4378 | { | |
d8151005 DJ |
4379 | /* The name is already allocated along with this objfile, so |
4380 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4381 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4382 | } |
c906108c SS |
4383 | } |
4384 | ||
4385 | if (die->tag == DW_TAG_structure_type) | |
4386 | { | |
4387 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4388 | } | |
4389 | else if (die->tag == DW_TAG_union_type) | |
4390 | { | |
4391 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4392 | } | |
4393 | else | |
4394 | { | |
4395 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 4396 | in gdbtypes.h. */ |
c906108c SS |
4397 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
4398 | } | |
4399 | ||
e142c38c | 4400 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4401 | if (attr) |
4402 | { | |
4403 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4404 | } | |
4405 | else | |
4406 | { | |
4407 | TYPE_LENGTH (type) = 0; | |
4408 | } | |
4409 | ||
876cecd0 | 4410 | TYPE_STUB_SUPPORTED (type) = 1; |
dc718098 | 4411 | if (die_is_declaration (die, cu)) |
876cecd0 | 4412 | TYPE_STUB (type) = 1; |
dc718098 | 4413 | |
c906108c SS |
4414 | /* We need to add the type field to the die immediately so we don't |
4415 | infinitely recurse when dealing with pointers to the structure | |
4416 | type within the structure itself. */ | |
1c379e20 | 4417 | set_die_type (die, type, cu); |
c906108c | 4418 | |
e142c38c | 4419 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
4420 | { |
4421 | struct field_info fi; | |
4422 | struct die_info *child_die; | |
c906108c SS |
4423 | |
4424 | memset (&fi, 0, sizeof (struct field_info)); | |
4425 | ||
639d11d3 | 4426 | child_die = die->child; |
c906108c SS |
4427 | |
4428 | while (child_die && child_die->tag) | |
4429 | { | |
a9a9bd0f DC |
4430 | if (child_die->tag == DW_TAG_member |
4431 | || child_die->tag == DW_TAG_variable) | |
c906108c | 4432 | { |
a9a9bd0f DC |
4433 | /* NOTE: carlton/2002-11-05: A C++ static data member |
4434 | should be a DW_TAG_member that is a declaration, but | |
4435 | all versions of G++ as of this writing (so through at | |
4436 | least 3.2.1) incorrectly generate DW_TAG_variable | |
4437 | tags for them instead. */ | |
e7c27a73 | 4438 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4439 | } |
8713b1b1 | 4440 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
4441 | { |
4442 | /* C++ member function. */ | |
e7c27a73 | 4443 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
4444 | } |
4445 | else if (child_die->tag == DW_TAG_inheritance) | |
4446 | { | |
4447 | /* C++ base class field. */ | |
e7c27a73 | 4448 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4449 | } |
c906108c SS |
4450 | child_die = sibling_die (child_die); |
4451 | } | |
4452 | ||
4453 | /* Attach fields and member functions to the type. */ | |
4454 | if (fi.nfields) | |
e7c27a73 | 4455 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
4456 | if (fi.nfnfields) |
4457 | { | |
e7c27a73 | 4458 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 4459 | |
c5aa993b | 4460 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
4461 | class itself) which contains the vtable pointer for the current |
4462 | class from the DW_AT_containing_type attribute. */ | |
4463 | ||
e142c38c | 4464 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 4465 | { |
e7c27a73 | 4466 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
4467 | |
4468 | TYPE_VPTR_BASETYPE (type) = t; | |
4469 | if (type == t) | |
4470 | { | |
c906108c SS |
4471 | int i; |
4472 | ||
4473 | /* Our own class provides vtbl ptr. */ | |
4474 | for (i = TYPE_NFIELDS (t) - 1; | |
4475 | i >= TYPE_N_BASECLASSES (t); | |
4476 | --i) | |
4477 | { | |
4478 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
4479 | ||
1168df01 | 4480 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
4481 | { |
4482 | TYPE_VPTR_FIELDNO (type) = i; | |
4483 | break; | |
4484 | } | |
4485 | } | |
4486 | ||
4487 | /* Complain if virtual function table field not found. */ | |
4488 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 4489 | complaint (&symfile_complaints, |
e2e0b3e5 | 4490 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
4491 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
4492 | ""); | |
c906108c SS |
4493 | } |
4494 | else | |
4495 | { | |
4496 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4497 | } | |
4498 | } | |
f6235d4c EZ |
4499 | else if (cu->producer |
4500 | && strncmp (cu->producer, | |
4501 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
4502 | { | |
4503 | /* The IBM XLC compiler does not provide direct indication | |
4504 | of the containing type, but the vtable pointer is | |
4505 | always named __vfp. */ | |
4506 | ||
4507 | int i; | |
4508 | ||
4509 | for (i = TYPE_NFIELDS (type) - 1; | |
4510 | i >= TYPE_N_BASECLASSES (type); | |
4511 | --i) | |
4512 | { | |
4513 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
4514 | { | |
4515 | TYPE_VPTR_FIELDNO (type) = i; | |
4516 | TYPE_VPTR_BASETYPE (type) = type; | |
4517 | break; | |
4518 | } | |
4519 | } | |
4520 | } | |
c906108c | 4521 | } |
c906108c | 4522 | } |
63d06c5c | 4523 | |
0114d602 | 4524 | do_cleanups (back_to); |
f792889a | 4525 | return type; |
c906108c SS |
4526 | } |
4527 | ||
134d01f1 DJ |
4528 | static void |
4529 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4530 | { | |
4531 | struct objfile *objfile = cu->objfile; | |
90aeadfc | 4532 | struct die_info *child_die = die->child; |
f792889a | 4533 | struct type *this_type; |
c906108c | 4534 | |
f792889a DJ |
4535 | this_type = get_die_type (die, cu); |
4536 | if (this_type == NULL) | |
4537 | this_type = read_structure_type (die, cu); | |
c906108c | 4538 | |
90aeadfc DC |
4539 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4540 | snapshots) has been known to create a die giving a declaration | |
4541 | for a class that has, as a child, a die giving a definition for a | |
4542 | nested class. So we have to process our children even if the | |
4543 | current die is a declaration. Normally, of course, a declaration | |
4544 | won't have any children at all. */ | |
134d01f1 | 4545 | |
90aeadfc DC |
4546 | while (child_die != NULL && child_die->tag) |
4547 | { | |
4548 | if (child_die->tag == DW_TAG_member | |
4549 | || child_die->tag == DW_TAG_variable | |
4550 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4551 | { |
90aeadfc | 4552 | /* Do nothing. */ |
134d01f1 | 4553 | } |
90aeadfc DC |
4554 | else |
4555 | process_die (child_die, cu); | |
134d01f1 | 4556 | |
90aeadfc | 4557 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4558 | } |
4559 | ||
fa4028e9 JB |
4560 | /* Do not consider external references. According to the DWARF standard, |
4561 | these DIEs are identified by the fact that they have no byte_size | |
4562 | attribute, and a declaration attribute. */ | |
4563 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4564 | || !die_is_declaration (die, cu)) | |
f792889a | 4565 | new_symbol (die, this_type, cu); |
134d01f1 DJ |
4566 | } |
4567 | ||
4568 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4569 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 4570 | |
f792889a | 4571 | static struct type * |
134d01f1 | 4572 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4573 | { |
e7c27a73 | 4574 | struct objfile *objfile = cu->objfile; |
c906108c | 4575 | struct type *type; |
c906108c | 4576 | struct attribute *attr; |
0114d602 | 4577 | const char *name; |
134d01f1 | 4578 | |
c906108c SS |
4579 | type = alloc_type (objfile); |
4580 | ||
4581 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
0114d602 | 4582 | name = dwarf2_full_name (die, cu); |
39cbfefa | 4583 | if (name != NULL) |
0114d602 | 4584 | TYPE_TAG_NAME (type) = (char *) name; |
c906108c | 4585 | |
e142c38c | 4586 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4587 | if (attr) |
4588 | { | |
4589 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4590 | } | |
4591 | else | |
4592 | { | |
4593 | TYPE_LENGTH (type) = 0; | |
4594 | } | |
4595 | ||
137033e9 JB |
4596 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
4597 | declared as private in the package spec, and then defined only | |
4598 | inside the package body. Such types are known as Taft Amendment | |
4599 | Types. When another package uses such a type, an incomplete DIE | |
4600 | may be generated by the compiler. */ | |
02eb380e | 4601 | if (die_is_declaration (die, cu)) |
876cecd0 | 4602 | TYPE_STUB (type) = 1; |
02eb380e | 4603 | |
f792889a | 4604 | return set_die_type (die, type, cu); |
134d01f1 DJ |
4605 | } |
4606 | ||
8176b9b8 | 4607 | /* Determine the name of the type represented by DIE, which should be |
0114d602 DJ |
4608 | a named C++ or Java compound type. Return the name in question, |
4609 | allocated on the objfile obstack. */ | |
8176b9b8 | 4610 | |
0114d602 | 4611 | static const char * |
8176b9b8 DC |
4612 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) |
4613 | { | |
0114d602 | 4614 | const char *new_prefix = NULL; |
8176b9b8 DC |
4615 | |
4616 | /* If we don't have namespace debug info, guess the name by trying | |
4617 | to demangle the names of members, just like we did in | |
72bf9492 | 4618 | guess_structure_name. */ |
8176b9b8 DC |
4619 | if (!processing_has_namespace_info) |
4620 | { | |
4621 | struct die_info *child; | |
4622 | ||
4623 | for (child = die->child; | |
4624 | child != NULL && child->tag != 0; | |
4625 | child = sibling_die (child)) | |
4626 | { | |
4627 | if (child->tag == DW_TAG_subprogram) | |
4628 | { | |
0114d602 | 4629 | char *phys_prefix |
31c27f77 JJ |
4630 | = language_class_name_from_physname (cu->language_defn, |
4631 | dwarf2_linkage_name | |
8176b9b8 DC |
4632 | (child, cu)); |
4633 | ||
0114d602 DJ |
4634 | if (phys_prefix != NULL) |
4635 | { | |
4636 | new_prefix | |
4637 | = obsavestring (phys_prefix, strlen (phys_prefix), | |
4638 | &cu->objfile->objfile_obstack); | |
4639 | xfree (phys_prefix); | |
4640 | break; | |
4641 | } | |
8176b9b8 DC |
4642 | } |
4643 | } | |
4644 | } | |
4645 | ||
4646 | if (new_prefix == NULL) | |
0114d602 | 4647 | new_prefix = dwarf2_full_name (die, cu); |
8176b9b8 DC |
4648 | |
4649 | return new_prefix; | |
4650 | } | |
4651 | ||
134d01f1 DJ |
4652 | /* Given a pointer to a die which begins an enumeration, process all |
4653 | the dies that define the members of the enumeration, and create the | |
4654 | symbol for the enumeration type. | |
4655 | ||
4656 | NOTE: We reverse the order of the element list. */ | |
4657 | ||
4658 | static void | |
4659 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4660 | { | |
4661 | struct objfile *objfile = cu->objfile; | |
4662 | struct die_info *child_die; | |
4663 | struct field *fields; | |
134d01f1 DJ |
4664 | struct symbol *sym; |
4665 | int num_fields; | |
4666 | int unsigned_enum = 1; | |
39cbfefa | 4667 | char *name; |
f792889a | 4668 | struct type *this_type; |
134d01f1 | 4669 | |
c906108c SS |
4670 | num_fields = 0; |
4671 | fields = NULL; | |
f792889a DJ |
4672 | this_type = get_die_type (die, cu); |
4673 | if (this_type == NULL) | |
4674 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 4675 | if (die->child != NULL) |
c906108c | 4676 | { |
639d11d3 | 4677 | child_die = die->child; |
c906108c SS |
4678 | while (child_die && child_die->tag) |
4679 | { | |
4680 | if (child_die->tag != DW_TAG_enumerator) | |
4681 | { | |
e7c27a73 | 4682 | process_die (child_die, cu); |
c906108c SS |
4683 | } |
4684 | else | |
4685 | { | |
39cbfefa DJ |
4686 | name = dwarf2_name (child_die, cu); |
4687 | if (name) | |
c906108c | 4688 | { |
f792889a | 4689 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
4690 | if (SYMBOL_VALUE (sym) < 0) |
4691 | unsigned_enum = 0; | |
4692 | ||
4693 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4694 | { | |
4695 | fields = (struct field *) | |
4696 | xrealloc (fields, | |
4697 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4698 | * sizeof (struct field)); |
c906108c SS |
4699 | } |
4700 | ||
3567439c | 4701 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
c906108c | 4702 | FIELD_TYPE (fields[num_fields]) = NULL; |
d6a843b5 | 4703 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
c906108c SS |
4704 | FIELD_BITSIZE (fields[num_fields]) = 0; |
4705 | ||
4706 | num_fields++; | |
4707 | } | |
4708 | } | |
4709 | ||
4710 | child_die = sibling_die (child_die); | |
4711 | } | |
4712 | ||
4713 | if (num_fields) | |
4714 | { | |
f792889a DJ |
4715 | TYPE_NFIELDS (this_type) = num_fields; |
4716 | TYPE_FIELDS (this_type) = (struct field *) | |
4717 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
4718 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 4719 | sizeof (struct field) * num_fields); |
b8c9b27d | 4720 | xfree (fields); |
c906108c SS |
4721 | } |
4722 | if (unsigned_enum) | |
876cecd0 | 4723 | TYPE_UNSIGNED (this_type) = 1; |
c906108c | 4724 | } |
134d01f1 | 4725 | |
f792889a | 4726 | new_symbol (die, this_type, cu); |
c906108c SS |
4727 | } |
4728 | ||
4729 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4730 | the DIE's type field. For now, this only handles one dimensional | |
4731 | arrays. */ | |
4732 | ||
f792889a | 4733 | static struct type * |
e7c27a73 | 4734 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4735 | { |
e7c27a73 | 4736 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4737 | struct die_info *child_die; |
4738 | struct type *type = NULL; | |
4739 | struct type *element_type, *range_type, *index_type; | |
4740 | struct type **range_types = NULL; | |
4741 | struct attribute *attr; | |
4742 | int ndim = 0; | |
4743 | struct cleanup *back_to; | |
39cbfefa | 4744 | char *name; |
c906108c | 4745 | |
e7c27a73 | 4746 | element_type = die_type (die, cu); |
c906108c SS |
4747 | |
4748 | /* Irix 6.2 native cc creates array types without children for | |
4749 | arrays with unspecified length. */ | |
639d11d3 | 4750 | if (die->child == NULL) |
c906108c | 4751 | { |
6ccb9162 | 4752 | index_type = builtin_type_int32; |
c906108c | 4753 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
4754 | type = create_array_type (NULL, element_type, range_type); |
4755 | return set_die_type (die, type, cu); | |
c906108c SS |
4756 | } |
4757 | ||
4758 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4759 | child_die = die->child; |
c906108c SS |
4760 | while (child_die && child_die->tag) |
4761 | { | |
4762 | if (child_die->tag == DW_TAG_subrange_type) | |
4763 | { | |
f792889a DJ |
4764 | struct type *child_type = read_type_die (child_die, cu); |
4765 | if (child_type != NULL) | |
a02abb62 JB |
4766 | { |
4767 | /* The range type was succesfully read. Save it for | |
4768 | the array type creation. */ | |
4769 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4770 | { | |
4771 | range_types = (struct type **) | |
4772 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4773 | * sizeof (struct type *)); | |
4774 | if (ndim == 0) | |
4775 | make_cleanup (free_current_contents, &range_types); | |
4776 | } | |
f792889a | 4777 | range_types[ndim++] = child_type; |
a02abb62 | 4778 | } |
c906108c SS |
4779 | } |
4780 | child_die = sibling_die (child_die); | |
4781 | } | |
4782 | ||
4783 | /* Dwarf2 dimensions are output from left to right, create the | |
4784 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4785 | |
c906108c | 4786 | type = element_type; |
7ca2d3a3 DL |
4787 | |
4788 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4789 | { | |
4790 | int i = 0; | |
4791 | while (i < ndim) | |
4792 | type = create_array_type (NULL, type, range_types[i++]); | |
4793 | } | |
4794 | else | |
4795 | { | |
4796 | while (ndim-- > 0) | |
4797 | type = create_array_type (NULL, type, range_types[ndim]); | |
4798 | } | |
c906108c | 4799 | |
f5f8a009 EZ |
4800 | /* Understand Dwarf2 support for vector types (like they occur on |
4801 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4802 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4803 | custom vendor extension. The main difference between a regular | |
4804 | array and the vector variant is that vectors are passed by value | |
4805 | to functions. */ | |
e142c38c | 4806 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 4807 | if (attr) |
ea37ba09 | 4808 | make_vector_type (type); |
f5f8a009 | 4809 | |
39cbfefa DJ |
4810 | name = dwarf2_name (die, cu); |
4811 | if (name) | |
4812 | TYPE_NAME (type) = name; | |
714e295e | 4813 | |
c906108c SS |
4814 | do_cleanups (back_to); |
4815 | ||
4816 | /* Install the type in the die. */ | |
f792889a | 4817 | return set_die_type (die, type, cu); |
c906108c SS |
4818 | } |
4819 | ||
7ca2d3a3 DL |
4820 | static enum dwarf_array_dim_ordering |
4821 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4822 | { | |
4823 | struct attribute *attr; | |
4824 | ||
4825 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4826 | ||
4827 | if (attr) return DW_SND (attr); | |
4828 | ||
4829 | /* | |
4830 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4831 | opposite order to the dwarf2 specification, but data is still | |
4832 | laid out as per normal fortran. | |
4833 | ||
4834 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4835 | version checking. | |
4836 | */ | |
4837 | ||
4838 | if (cu->language == language_fortran && | |
4839 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4840 | { | |
4841 | return DW_ORD_row_major; | |
4842 | } | |
4843 | ||
4844 | switch (cu->language_defn->la_array_ordering) | |
4845 | { | |
4846 | case array_column_major: | |
4847 | return DW_ORD_col_major; | |
4848 | case array_row_major: | |
4849 | default: | |
4850 | return DW_ORD_row_major; | |
4851 | }; | |
4852 | } | |
4853 | ||
72019c9c GM |
4854 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4855 | the DIE's type field. */ | |
4856 | ||
f792889a | 4857 | static struct type * |
72019c9c GM |
4858 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
4859 | { | |
f792889a DJ |
4860 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
4861 | ||
4862 | return set_die_type (die, set_type, cu); | |
72019c9c | 4863 | } |
7ca2d3a3 | 4864 | |
c906108c SS |
4865 | /* First cut: install each common block member as a global variable. */ |
4866 | ||
4867 | static void | |
e7c27a73 | 4868 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4869 | { |
4870 | struct die_info *child_die; | |
4871 | struct attribute *attr; | |
4872 | struct symbol *sym; | |
4873 | CORE_ADDR base = (CORE_ADDR) 0; | |
4874 | ||
e142c38c | 4875 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4876 | if (attr) |
4877 | { | |
8e19ed76 PS |
4878 | /* Support the .debug_loc offsets */ |
4879 | if (attr_form_is_block (attr)) | |
4880 | { | |
e7c27a73 | 4881 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 4882 | } |
3690dd37 | 4883 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4884 | { |
4d3c2250 | 4885 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4886 | } |
4887 | else | |
4888 | { | |
4d3c2250 KB |
4889 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4890 | "common block member"); | |
8e19ed76 | 4891 | } |
c906108c | 4892 | } |
639d11d3 | 4893 | if (die->child != NULL) |
c906108c | 4894 | { |
639d11d3 | 4895 | child_die = die->child; |
c906108c SS |
4896 | while (child_die && child_die->tag) |
4897 | { | |
e7c27a73 | 4898 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4899 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4900 | if (attr) |
4901 | { | |
4902 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4903 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4904 | add_symbol_to_list (sym, &global_symbols); |
4905 | } | |
4906 | child_die = sibling_die (child_die); | |
4907 | } | |
4908 | } | |
4909 | } | |
4910 | ||
0114d602 | 4911 | /* Create a type for a C++ namespace. */ |
d9fa45fe | 4912 | |
0114d602 DJ |
4913 | static struct type * |
4914 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) | |
d9fa45fe | 4915 | { |
e7c27a73 | 4916 | struct objfile *objfile = cu->objfile; |
0114d602 | 4917 | const char *previous_prefix, *name; |
9219021c | 4918 | int is_anonymous; |
0114d602 DJ |
4919 | struct type *type; |
4920 | ||
4921 | /* For extensions, reuse the type of the original namespace. */ | |
4922 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) | |
4923 | { | |
4924 | struct die_info *ext_die; | |
4925 | struct dwarf2_cu *ext_cu = cu; | |
4926 | ext_die = dwarf2_extension (die, &ext_cu); | |
4927 | type = read_type_die (ext_die, ext_cu); | |
4928 | return set_die_type (die, type, cu); | |
4929 | } | |
9219021c | 4930 | |
e142c38c | 4931 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4932 | |
4933 | /* Now build the name of the current namespace. */ | |
4934 | ||
0114d602 DJ |
4935 | previous_prefix = determine_prefix (die, cu); |
4936 | if (previous_prefix[0] != '\0') | |
4937 | name = typename_concat (&objfile->objfile_obstack, | |
4938 | previous_prefix, name, cu); | |
4939 | ||
4940 | /* Create the type. */ | |
4941 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, | |
4942 | objfile); | |
4943 | TYPE_NAME (type) = (char *) name; | |
4944 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4945 | ||
4946 | set_die_type (die, type, cu); | |
4947 | ||
4948 | return type; | |
4949 | } | |
4950 | ||
4951 | /* Read a C++ namespace. */ | |
4952 | ||
4953 | static void | |
4954 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |
4955 | { | |
4956 | struct objfile *objfile = cu->objfile; | |
4957 | const char *name; | |
4958 | int is_anonymous; | |
9219021c | 4959 | |
5c4e30ca DC |
4960 | /* Add a symbol associated to this if we haven't seen the namespace |
4961 | before. Also, add a using directive if it's an anonymous | |
4962 | namespace. */ | |
9219021c | 4963 | |
f2f0e013 | 4964 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
4965 | { |
4966 | struct type *type; | |
4967 | ||
0114d602 | 4968 | type = read_type_die (die, cu); |
e7c27a73 | 4969 | new_symbol (die, type, cu); |
5c4e30ca | 4970 | |
0114d602 | 4971 | name = namespace_name (die, &is_anonymous, cu); |
5c4e30ca | 4972 | if (is_anonymous) |
0114d602 DJ |
4973 | { |
4974 | const char *previous_prefix = determine_prefix (die, cu); | |
4975 | cp_add_using_directive (TYPE_NAME (type), | |
4976 | strlen (previous_prefix), | |
4977 | strlen (TYPE_NAME (type))); | |
4978 | } | |
5c4e30ca | 4979 | } |
9219021c | 4980 | |
639d11d3 | 4981 | if (die->child != NULL) |
d9fa45fe | 4982 | { |
639d11d3 | 4983 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4984 | |
4985 | while (child_die && child_die->tag) | |
4986 | { | |
e7c27a73 | 4987 | process_die (child_die, cu); |
d9fa45fe DC |
4988 | child_die = sibling_die (child_die); |
4989 | } | |
4990 | } | |
38d518c9 EZ |
4991 | } |
4992 | ||
5d7cb8df JK |
4993 | /* Read a Fortran module. */ |
4994 | ||
4995 | static void | |
4996 | read_module (struct die_info *die, struct dwarf2_cu *cu) | |
4997 | { | |
4998 | struct die_info *child_die = die->child; | |
4999 | ||
5000 | /* FIXME: Support the separate Fortran module namespaces. */ | |
5001 | ||
5002 | while (child_die && child_die->tag) | |
5003 | { | |
5004 | process_die (child_die, cu); | |
5005 | child_die = sibling_die (child_die); | |
5006 | } | |
5007 | } | |
5008 | ||
38d518c9 EZ |
5009 | /* Return the name of the namespace represented by DIE. Set |
5010 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
5011 | namespace. */ | |
5012 | ||
5013 | static const char * | |
e142c38c | 5014 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
5015 | { |
5016 | struct die_info *current_die; | |
5017 | const char *name = NULL; | |
5018 | ||
5019 | /* Loop through the extensions until we find a name. */ | |
5020 | ||
5021 | for (current_die = die; | |
5022 | current_die != NULL; | |
f2f0e013 | 5023 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 5024 | { |
e142c38c | 5025 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
5026 | if (name != NULL) |
5027 | break; | |
5028 | } | |
5029 | ||
5030 | /* Is it an anonymous namespace? */ | |
5031 | ||
5032 | *is_anonymous = (name == NULL); | |
5033 | if (*is_anonymous) | |
5034 | name = "(anonymous namespace)"; | |
5035 | ||
5036 | return name; | |
d9fa45fe DC |
5037 | } |
5038 | ||
c906108c SS |
5039 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
5040 | the user defined type vector. */ | |
5041 | ||
f792889a | 5042 | static struct type * |
e7c27a73 | 5043 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5044 | { |
5e2b427d | 5045 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 5046 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 5047 | struct type *type; |
8b2dbe47 KB |
5048 | struct attribute *attr_byte_size; |
5049 | struct attribute *attr_address_class; | |
5050 | int byte_size, addr_class; | |
c906108c | 5051 | |
e7c27a73 | 5052 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 5053 | |
e142c38c | 5054 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
5055 | if (attr_byte_size) |
5056 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 5057 | else |
8b2dbe47 KB |
5058 | byte_size = cu_header->addr_size; |
5059 | ||
e142c38c | 5060 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
5061 | if (attr_address_class) |
5062 | addr_class = DW_UNSND (attr_address_class); | |
5063 | else | |
5064 | addr_class = DW_ADDR_none; | |
5065 | ||
5066 | /* If the pointer size or address class is different than the | |
5067 | default, create a type variant marked as such and set the | |
5068 | length accordingly. */ | |
5069 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 5070 | { |
5e2b427d | 5071 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
5072 | { |
5073 | int type_flags; | |
5074 | ||
849957d9 | 5075 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 5076 | (gdbarch, byte_size, addr_class); |
876cecd0 TT |
5077 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
5078 | == 0); | |
8b2dbe47 KB |
5079 | type = make_type_with_address_space (type, type_flags); |
5080 | } | |
5081 | else if (TYPE_LENGTH (type) != byte_size) | |
5082 | { | |
e2e0b3e5 | 5083 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
5084 | } |
5085 | else { | |
5086 | /* Should we also complain about unhandled address classes? */ | |
5087 | } | |
c906108c | 5088 | } |
8b2dbe47 KB |
5089 | |
5090 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 5091 | return set_die_type (die, type, cu); |
c906108c SS |
5092 | } |
5093 | ||
5094 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
5095 | the user defined type vector. */ | |
5096 | ||
f792889a | 5097 | static struct type * |
e7c27a73 | 5098 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5099 | { |
e7c27a73 | 5100 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5101 | struct type *type; |
5102 | struct type *to_type; | |
5103 | struct type *domain; | |
5104 | ||
e7c27a73 DJ |
5105 | to_type = die_type (die, cu); |
5106 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
5107 | |
5108 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
5109 | type = lookup_methodptr_type (to_type); | |
5110 | else | |
5111 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 5112 | |
f792889a | 5113 | return set_die_type (die, type, cu); |
c906108c SS |
5114 | } |
5115 | ||
5116 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
5117 | the user defined type vector. */ | |
5118 | ||
f792889a | 5119 | static struct type * |
e7c27a73 | 5120 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5121 | { |
e7c27a73 | 5122 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5123 | struct type *type; |
5124 | struct attribute *attr; | |
5125 | ||
e7c27a73 | 5126 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 5127 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5128 | if (attr) |
5129 | { | |
5130 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
5131 | } | |
5132 | else | |
5133 | { | |
107d2387 | 5134 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 5135 | } |
f792889a | 5136 | return set_die_type (die, type, cu); |
c906108c SS |
5137 | } |
5138 | ||
f792889a | 5139 | static struct type * |
e7c27a73 | 5140 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5141 | { |
f792889a | 5142 | struct type *base_type, *cv_type; |
c906108c | 5143 | |
e7c27a73 | 5144 | base_type = die_type (die, cu); |
f792889a DJ |
5145 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
5146 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5147 | } |
5148 | ||
f792889a | 5149 | static struct type * |
e7c27a73 | 5150 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5151 | { |
f792889a | 5152 | struct type *base_type, *cv_type; |
c906108c | 5153 | |
e7c27a73 | 5154 | base_type = die_type (die, cu); |
f792889a DJ |
5155 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
5156 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
5157 | } |
5158 | ||
5159 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
5160 | the user defined type vector. It isn't really a user defined type, | |
5161 | but it behaves like one, with other DIE's using an AT_user_def_type | |
5162 | attribute to reference it. */ | |
5163 | ||
f792889a | 5164 | static struct type * |
e7c27a73 | 5165 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5166 | { |
e7c27a73 | 5167 | struct objfile *objfile = cu->objfile; |
3b7538c0 | 5168 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
5169 | struct type *type, *range_type, *index_type, *char_type; |
5170 | struct attribute *attr; | |
5171 | unsigned int length; | |
5172 | ||
e142c38c | 5173 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
5174 | if (attr) |
5175 | { | |
5176 | length = DW_UNSND (attr); | |
5177 | } | |
5178 | else | |
5179 | { | |
b21b22e0 | 5180 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 5181 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
5182 | if (attr) |
5183 | { | |
5184 | length = DW_UNSND (attr); | |
5185 | } | |
5186 | else | |
5187 | { | |
5188 | length = 1; | |
5189 | } | |
c906108c | 5190 | } |
6ccb9162 UW |
5191 | |
5192 | index_type = builtin_type_int32; | |
c906108c | 5193 | range_type = create_range_type (NULL, index_type, 1, length); |
3b7538c0 UW |
5194 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
5195 | type = create_string_type (NULL, char_type, range_type); | |
6ccb9162 | 5196 | |
f792889a | 5197 | return set_die_type (die, type, cu); |
c906108c SS |
5198 | } |
5199 | ||
5200 | /* Handle DIES due to C code like: | |
5201 | ||
5202 | struct foo | |
c5aa993b JM |
5203 | { |
5204 | int (*funcp)(int a, long l); | |
5205 | int b; | |
5206 | }; | |
c906108c SS |
5207 | |
5208 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 5209 | */ |
c906108c | 5210 | |
f792889a | 5211 | static struct type * |
e7c27a73 | 5212 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
5213 | { |
5214 | struct type *type; /* Type that this function returns */ | |
5215 | struct type *ftype; /* Function that returns above type */ | |
5216 | struct attribute *attr; | |
5217 | ||
e7c27a73 | 5218 | type = die_type (die, cu); |
323427d1 | 5219 | ftype = make_function_type (type, (struct type **) 0, cu->objfile); |
c906108c | 5220 | |
5b8101ae | 5221 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 5222 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 5223 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 5224 | || cu->language == language_cplus |
5b8101ae PM |
5225 | || cu->language == language_java |
5226 | || cu->language == language_pascal) | |
876cecd0 | 5227 | TYPE_PROTOTYPED (ftype) = 1; |
c906108c | 5228 | |
c055b101 CV |
5229 | /* Store the calling convention in the type if it's available in |
5230 | the subroutine die. Otherwise set the calling convention to | |
5231 | the default value DW_CC_normal. */ | |
5232 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
5233 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
5234 | ||
639d11d3 | 5235 | if (die->child != NULL) |
c906108c SS |
5236 | { |
5237 | struct die_info *child_die; | |
5238 | int nparams = 0; | |
5239 | int iparams = 0; | |
5240 | ||
5241 | /* Count the number of parameters. | |
5242 | FIXME: GDB currently ignores vararg functions, but knows about | |
5243 | vararg member functions. */ | |
639d11d3 | 5244 | child_die = die->child; |
c906108c SS |
5245 | while (child_die && child_die->tag) |
5246 | { | |
5247 | if (child_die->tag == DW_TAG_formal_parameter) | |
5248 | nparams++; | |
5249 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
876cecd0 | 5250 | TYPE_VARARGS (ftype) = 1; |
c906108c SS |
5251 | child_die = sibling_die (child_die); |
5252 | } | |
5253 | ||
5254 | /* Allocate storage for parameters and fill them in. */ | |
5255 | TYPE_NFIELDS (ftype) = nparams; | |
5256 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 5257 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 5258 | |
639d11d3 | 5259 | child_die = die->child; |
c906108c SS |
5260 | while (child_die && child_die->tag) |
5261 | { | |
5262 | if (child_die->tag == DW_TAG_formal_parameter) | |
5263 | { | |
5264 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
5265 | member functions. G++ helps GDB by marking the first |
5266 | parameter for non-static member functions (which is the | |
5267 | this pointer) as artificial. We pass this information | |
5268 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 5269 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
5270 | if (attr) |
5271 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
5272 | else | |
5273 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 5274 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
5275 | iparams++; |
5276 | } | |
5277 | child_die = sibling_die (child_die); | |
5278 | } | |
5279 | } | |
5280 | ||
f792889a | 5281 | return set_die_type (die, ftype, cu); |
c906108c SS |
5282 | } |
5283 | ||
f792889a | 5284 | static struct type * |
e7c27a73 | 5285 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5286 | { |
e7c27a73 | 5287 | struct objfile *objfile = cu->objfile; |
2f038fcb | 5288 | struct attribute *attr; |
0114d602 | 5289 | const char *name = NULL; |
f792889a | 5290 | struct type *this_type; |
c906108c | 5291 | |
0114d602 | 5292 | name = dwarf2_full_name (die, cu); |
f792889a | 5293 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
0114d602 DJ |
5294 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
5295 | TYPE_NAME (this_type) = (char *) name; | |
f792889a DJ |
5296 | set_die_type (die, this_type, cu); |
5297 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
5298 | return this_type; | |
c906108c SS |
5299 | } |
5300 | ||
5301 | /* Find a representation of a given base type and install | |
5302 | it in the TYPE field of the die. */ | |
5303 | ||
f792889a | 5304 | static struct type * |
e7c27a73 | 5305 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 5306 | { |
e7c27a73 | 5307 | struct objfile *objfile = cu->objfile; |
c906108c SS |
5308 | struct type *type; |
5309 | struct attribute *attr; | |
5310 | int encoding = 0, size = 0; | |
39cbfefa | 5311 | char *name; |
6ccb9162 UW |
5312 | enum type_code code = TYPE_CODE_INT; |
5313 | int type_flags = 0; | |
5314 | struct type *target_type = NULL; | |
c906108c | 5315 | |
e142c38c | 5316 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
5317 | if (attr) |
5318 | { | |
5319 | encoding = DW_UNSND (attr); | |
5320 | } | |
e142c38c | 5321 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
5322 | if (attr) |
5323 | { | |
5324 | size = DW_UNSND (attr); | |
5325 | } | |
39cbfefa | 5326 | name = dwarf2_name (die, cu); |
6ccb9162 | 5327 | if (!name) |
c906108c | 5328 | { |
6ccb9162 UW |
5329 | complaint (&symfile_complaints, |
5330 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 5331 | } |
6ccb9162 UW |
5332 | |
5333 | switch (encoding) | |
c906108c | 5334 | { |
6ccb9162 UW |
5335 | case DW_ATE_address: |
5336 | /* Turn DW_ATE_address into a void * pointer. */ | |
5337 | code = TYPE_CODE_PTR; | |
5338 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5339 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
5340 | break; | |
5341 | case DW_ATE_boolean: | |
5342 | code = TYPE_CODE_BOOL; | |
5343 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5344 | break; | |
5345 | case DW_ATE_complex_float: | |
5346 | code = TYPE_CODE_COMPLEX; | |
5347 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
5348 | break; | |
5349 | case DW_ATE_decimal_float: | |
5350 | code = TYPE_CODE_DECFLOAT; | |
5351 | break; | |
5352 | case DW_ATE_float: | |
5353 | code = TYPE_CODE_FLT; | |
5354 | break; | |
5355 | case DW_ATE_signed: | |
5356 | break; | |
5357 | case DW_ATE_unsigned: | |
5358 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5359 | break; | |
5360 | case DW_ATE_signed_char: | |
868a0084 PM |
5361 | if (cu->language == language_ada || cu->language == language_m2 |
5362 | || cu->language == language_pascal) | |
6ccb9162 UW |
5363 | code = TYPE_CODE_CHAR; |
5364 | break; | |
5365 | case DW_ATE_unsigned_char: | |
868a0084 PM |
5366 | if (cu->language == language_ada || cu->language == language_m2 |
5367 | || cu->language == language_pascal) | |
6ccb9162 UW |
5368 | code = TYPE_CODE_CHAR; |
5369 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5370 | break; | |
5371 | default: | |
5372 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
5373 | dwarf_type_encoding_name (encoding)); | |
5374 | break; | |
c906108c | 5375 | } |
6ccb9162 | 5376 | |
0114d602 DJ |
5377 | type = init_type (code, size, type_flags, NULL, objfile); |
5378 | TYPE_NAME (type) = name; | |
6ccb9162 UW |
5379 | TYPE_TARGET_TYPE (type) = target_type; |
5380 | ||
0114d602 | 5381 | if (name && strcmp (name, "char") == 0) |
876cecd0 | 5382 | TYPE_NOSIGN (type) = 1; |
0114d602 | 5383 | |
f792889a | 5384 | return set_die_type (die, type, cu); |
c906108c SS |
5385 | } |
5386 | ||
a02abb62 JB |
5387 | /* Read the given DW_AT_subrange DIE. */ |
5388 | ||
f792889a | 5389 | static struct type * |
a02abb62 JB |
5390 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
5391 | { | |
5e2b427d | 5392 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
5393 | struct type *base_type; |
5394 | struct type *range_type; | |
5395 | struct attribute *attr; | |
5396 | int low = 0; | |
5397 | int high = -1; | |
39cbfefa | 5398 | char *name; |
a02abb62 | 5399 | |
a02abb62 | 5400 | base_type = die_type (die, cu); |
3d1f72c2 | 5401 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
5402 | { |
5403 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5404 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 5405 | base_type |
5e2b427d | 5406 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 5407 | 0, NULL, cu->objfile); |
a02abb62 JB |
5408 | } |
5409 | ||
e142c38c | 5410 | if (cu->language == language_fortran) |
a02abb62 JB |
5411 | { |
5412 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
5413 | low = 1; | |
5414 | } | |
5415 | ||
dd5e6932 DJ |
5416 | /* FIXME: For variable sized arrays either of these could be |
5417 | a variable rather than a constant value. We'll allow it, | |
5418 | but we don't know how to handle it. */ | |
e142c38c | 5419 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
5420 | if (attr) |
5421 | low = dwarf2_get_attr_constant_value (attr, 0); | |
5422 | ||
e142c38c | 5423 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
5424 | if (attr) |
5425 | { | |
5426 | if (attr->form == DW_FORM_block1) | |
5427 | { | |
5428 | /* GCC encodes arrays with unspecified or dynamic length | |
5429 | with a DW_FORM_block1 attribute. | |
5430 | FIXME: GDB does not yet know how to handle dynamic | |
5431 | arrays properly, treat them as arrays with unspecified | |
5432 | length for now. | |
5433 | ||
5434 | FIXME: jimb/2003-09-22: GDB does not really know | |
5435 | how to handle arrays of unspecified length | |
5436 | either; we just represent them as zero-length | |
5437 | arrays. Choose an appropriate upper bound given | |
5438 | the lower bound we've computed above. */ | |
5439 | high = low - 1; | |
5440 | } | |
5441 | else | |
5442 | high = dwarf2_get_attr_constant_value (attr, 1); | |
5443 | } | |
5444 | ||
5445 | range_type = create_range_type (NULL, base_type, low, high); | |
5446 | ||
39cbfefa DJ |
5447 | name = dwarf2_name (die, cu); |
5448 | if (name) | |
5449 | TYPE_NAME (range_type) = name; | |
a02abb62 | 5450 | |
e142c38c | 5451 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
5452 | if (attr) |
5453 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
5454 | ||
f792889a | 5455 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
5456 | } |
5457 | ||
f792889a | 5458 | static struct type * |
81a17f79 JB |
5459 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
5460 | { | |
5461 | struct type *type; | |
81a17f79 | 5462 | |
81a17f79 JB |
5463 | /* For now, we only support the C meaning of an unspecified type: void. */ |
5464 | ||
0114d602 DJ |
5465 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
5466 | TYPE_NAME (type) = dwarf2_name (die, cu); | |
81a17f79 | 5467 | |
f792889a | 5468 | return set_die_type (die, type, cu); |
81a17f79 | 5469 | } |
a02abb62 | 5470 | |
51545339 DJ |
5471 | /* Trivial hash function for die_info: the hash value of a DIE |
5472 | is its offset in .debug_info for this objfile. */ | |
5473 | ||
5474 | static hashval_t | |
5475 | die_hash (const void *item) | |
5476 | { | |
5477 | const struct die_info *die = item; | |
5478 | return die->offset; | |
5479 | } | |
5480 | ||
5481 | /* Trivial comparison function for die_info structures: two DIEs | |
5482 | are equal if they have the same offset. */ | |
5483 | ||
5484 | static int | |
5485 | die_eq (const void *item_lhs, const void *item_rhs) | |
5486 | { | |
5487 | const struct die_info *die_lhs = item_lhs; | |
5488 | const struct die_info *die_rhs = item_rhs; | |
5489 | return die_lhs->offset == die_rhs->offset; | |
5490 | } | |
5491 | ||
c906108c SS |
5492 | /* Read a whole compilation unit into a linked list of dies. */ |
5493 | ||
f9aca02d | 5494 | static struct die_info * |
fe1b8b76 | 5495 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5496 | { |
51545339 DJ |
5497 | cu->die_hash |
5498 | = htab_create_alloc_ex (cu->header.length / 12, | |
5499 | die_hash, | |
5500 | die_eq, | |
5501 | NULL, | |
5502 | &cu->comp_unit_obstack, | |
5503 | hashtab_obstack_allocate, | |
5504 | dummy_obstack_deallocate); | |
5505 | ||
e7c27a73 | 5506 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
5507 | } |
5508 | ||
d97bc12b DE |
5509 | /* Main entry point for reading a DIE and all children. |
5510 | Read the DIE and dump it if requested. */ | |
5511 | ||
5512 | static struct die_info * | |
5513 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, | |
5514 | struct dwarf2_cu *cu, | |
5515 | gdb_byte **new_info_ptr, | |
5516 | struct die_info *parent) | |
5517 | { | |
5518 | struct die_info *result = read_die_and_children_1 (info_ptr, abfd, cu, | |
5519 | new_info_ptr, parent); | |
5520 | ||
5521 | if (dwarf2_die_debug) | |
5522 | { | |
5523 | fprintf_unfiltered (gdb_stdlog, "Read die from .debug_info:\n"); | |
5524 | dump_die (result, dwarf2_die_debug); | |
5525 | } | |
5526 | ||
5527 | return result; | |
5528 | } | |
5529 | ||
639d11d3 DC |
5530 | /* Read a single die and all its descendents. Set the die's sibling |
5531 | field to NULL; set other fields in the die correctly, and set all | |
5532 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
5533 | location of the info_ptr after reading all of those dies. PARENT | |
5534 | is the parent of the die in question. */ | |
5535 | ||
5536 | static struct die_info * | |
d97bc12b DE |
5537 | read_die_and_children_1 (gdb_byte *info_ptr, bfd *abfd, |
5538 | struct dwarf2_cu *cu, | |
5539 | gdb_byte **new_info_ptr, | |
5540 | struct die_info *parent) | |
639d11d3 DC |
5541 | { |
5542 | struct die_info *die; | |
fe1b8b76 | 5543 | gdb_byte *cur_ptr; |
639d11d3 DC |
5544 | int has_children; |
5545 | ||
e7c27a73 | 5546 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
1d325ec1 DJ |
5547 | if (die == NULL) |
5548 | { | |
5549 | *new_info_ptr = cur_ptr; | |
5550 | return NULL; | |
5551 | } | |
51545339 | 5552 | store_in_ref_table (die, cu); |
639d11d3 DC |
5553 | |
5554 | if (has_children) | |
5555 | { | |
e7c27a73 | 5556 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5557 | new_info_ptr, die); |
5558 | } | |
5559 | else | |
5560 | { | |
5561 | die->child = NULL; | |
5562 | *new_info_ptr = cur_ptr; | |
5563 | } | |
5564 | ||
5565 | die->sibling = NULL; | |
5566 | die->parent = parent; | |
5567 | return die; | |
5568 | } | |
5569 | ||
5570 | /* Read a die, all of its descendents, and all of its siblings; set | |
5571 | all of the fields of all of the dies correctly. Arguments are as | |
5572 | in read_die_and_children. */ | |
5573 | ||
5574 | static struct die_info * | |
fe1b8b76 | 5575 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5576 | struct dwarf2_cu *cu, |
fe1b8b76 | 5577 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5578 | struct die_info *parent) |
5579 | { | |
5580 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5581 | gdb_byte *cur_ptr; |
639d11d3 | 5582 | |
c906108c | 5583 | cur_ptr = info_ptr; |
639d11d3 DC |
5584 | first_die = last_sibling = NULL; |
5585 | ||
5586 | while (1) | |
c906108c | 5587 | { |
639d11d3 | 5588 | struct die_info *die |
d97bc12b | 5589 | = read_die_and_children_1 (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 | 5590 | |
1d325ec1 | 5591 | if (die == NULL) |
c906108c | 5592 | { |
639d11d3 DC |
5593 | *new_info_ptr = cur_ptr; |
5594 | return first_die; | |
c906108c | 5595 | } |
1d325ec1 DJ |
5596 | |
5597 | if (!first_die) | |
5598 | first_die = die; | |
c906108c | 5599 | else |
1d325ec1 DJ |
5600 | last_sibling->sibling = die; |
5601 | ||
5602 | last_sibling = die; | |
c906108c | 5603 | } |
c906108c SS |
5604 | } |
5605 | ||
c906108c SS |
5606 | /* In DWARF version 2, the description of the debugging information is |
5607 | stored in a separate .debug_abbrev section. Before we read any | |
5608 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5609 | in a hash table. This function also sets flags in CU describing |
5610 | the data found in the abbrev table. */ | |
c906108c SS |
5611 | |
5612 | static void | |
e7c27a73 | 5613 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5614 | { |
e7c27a73 | 5615 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5616 | gdb_byte *abbrev_ptr; |
c906108c SS |
5617 | struct abbrev_info *cur_abbrev; |
5618 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5619 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5620 | struct attr_abbrev *cur_attrs; |
5621 | unsigned int allocated_attrs; | |
c906108c | 5622 | |
57349743 | 5623 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5624 | obstack_init (&cu->abbrev_obstack); |
5625 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5626 | (ABBREV_HASH_SIZE | |
5627 | * sizeof (struct abbrev_info *))); | |
5628 | memset (cu->dwarf2_abbrevs, 0, | |
5629 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5630 | |
dce234bc | 5631 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
c906108c SS |
5632 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5633 | abbrev_ptr += bytes_read; | |
5634 | ||
f3dd6933 DJ |
5635 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5636 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5637 | ||
c906108c SS |
5638 | /* loop until we reach an abbrev number of 0 */ |
5639 | while (abbrev_number) | |
5640 | { | |
f3dd6933 | 5641 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5642 | |
5643 | /* read in abbrev header */ | |
5644 | cur_abbrev->number = abbrev_number; | |
5645 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5646 | abbrev_ptr += bytes_read; | |
5647 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5648 | abbrev_ptr += 1; | |
5649 | ||
72bf9492 DJ |
5650 | if (cur_abbrev->tag == DW_TAG_namespace) |
5651 | cu->has_namespace_info = 1; | |
5652 | ||
c906108c SS |
5653 | /* now read in declarations */ |
5654 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5655 | abbrev_ptr += bytes_read; | |
5656 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5657 | abbrev_ptr += bytes_read; | |
5658 | while (abbrev_name) | |
5659 | { | |
f3dd6933 | 5660 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5661 | { |
f3dd6933 DJ |
5662 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5663 | cur_attrs | |
5664 | = xrealloc (cur_attrs, (allocated_attrs | |
5665 | * sizeof (struct attr_abbrev))); | |
c906108c | 5666 | } |
ae038cb0 DJ |
5667 | |
5668 | /* Record whether this compilation unit might have | |
5669 | inter-compilation-unit references. If we don't know what form | |
5670 | this attribute will have, then it might potentially be a | |
5671 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5672 | references. */ | |
5673 | ||
5674 | if (abbrev_form == DW_FORM_ref_addr | |
5675 | || abbrev_form == DW_FORM_indirect) | |
5676 | cu->has_form_ref_addr = 1; | |
5677 | ||
f3dd6933 DJ |
5678 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5679 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5680 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5681 | abbrev_ptr += bytes_read; | |
5682 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5683 | abbrev_ptr += bytes_read; | |
5684 | } | |
5685 | ||
f3dd6933 DJ |
5686 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5687 | (cur_abbrev->num_attrs | |
5688 | * sizeof (struct attr_abbrev))); | |
5689 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5690 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5691 | ||
c906108c | 5692 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5693 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5694 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5695 | |
5696 | /* Get next abbreviation. | |
5697 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5698 | always properly terminated with an abbrev number of 0. |
5699 | Exit loop if we encounter an abbreviation which we have | |
5700 | already read (which means we are about to read the abbreviations | |
5701 | for the next compile unit) or if the end of the abbreviation | |
5702 | table is reached. */ | |
dce234bc PP |
5703 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
5704 | >= dwarf2_per_objfile->abbrev.size) | |
c906108c SS |
5705 | break; |
5706 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5707 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5708 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5709 | break; |
5710 | } | |
f3dd6933 DJ |
5711 | |
5712 | xfree (cur_attrs); | |
c906108c SS |
5713 | } |
5714 | ||
f3dd6933 | 5715 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5716 | |
c906108c | 5717 | static void |
f3dd6933 | 5718 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5719 | { |
f3dd6933 | 5720 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5721 | |
f3dd6933 DJ |
5722 | obstack_free (&cu->abbrev_obstack, NULL); |
5723 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5724 | } |
5725 | ||
5726 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5727 | ||
5728 | static struct abbrev_info * | |
e7c27a73 | 5729 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5730 | { |
5731 | unsigned int hash_number; | |
5732 | struct abbrev_info *abbrev; | |
5733 | ||
5734 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5735 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5736 | |
5737 | while (abbrev) | |
5738 | { | |
5739 | if (abbrev->number == number) | |
5740 | return abbrev; | |
5741 | else | |
5742 | abbrev = abbrev->next; | |
5743 | } | |
5744 | return NULL; | |
5745 | } | |
5746 | ||
72bf9492 DJ |
5747 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5748 | symbol for. */ | |
5749 | ||
5750 | static int | |
5751 | is_type_tag_for_partial (int tag) | |
5752 | { | |
5753 | switch (tag) | |
5754 | { | |
5755 | #if 0 | |
5756 | /* Some types that would be reasonable to generate partial symbols for, | |
5757 | that we don't at present. */ | |
5758 | case DW_TAG_array_type: | |
5759 | case DW_TAG_file_type: | |
5760 | case DW_TAG_ptr_to_member_type: | |
5761 | case DW_TAG_set_type: | |
5762 | case DW_TAG_string_type: | |
5763 | case DW_TAG_subroutine_type: | |
5764 | #endif | |
5765 | case DW_TAG_base_type: | |
5766 | case DW_TAG_class_type: | |
680b30c7 | 5767 | case DW_TAG_interface_type: |
72bf9492 DJ |
5768 | case DW_TAG_enumeration_type: |
5769 | case DW_TAG_structure_type: | |
5770 | case DW_TAG_subrange_type: | |
5771 | case DW_TAG_typedef: | |
5772 | case DW_TAG_union_type: | |
5773 | return 1; | |
5774 | default: | |
5775 | return 0; | |
5776 | } | |
5777 | } | |
5778 | ||
5779 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5780 | ||
5781 | static struct partial_die_info * | |
fe1b8b76 | 5782 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5783 | struct dwarf2_cu *cu) |
5784 | { | |
5785 | struct partial_die_info *part_die; | |
5786 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5787 | struct abbrev_info *abbrev; | |
5788 | unsigned int bytes_read; | |
5afb4e99 | 5789 | unsigned int load_all = 0; |
72bf9492 DJ |
5790 | |
5791 | int nesting_level = 1; | |
5792 | ||
5793 | parent_die = NULL; | |
5794 | last_die = NULL; | |
5795 | ||
5afb4e99 DJ |
5796 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5797 | load_all = 1; | |
5798 | ||
72bf9492 DJ |
5799 | cu->partial_dies |
5800 | = htab_create_alloc_ex (cu->header.length / 12, | |
5801 | partial_die_hash, | |
5802 | partial_die_eq, | |
5803 | NULL, | |
5804 | &cu->comp_unit_obstack, | |
5805 | hashtab_obstack_allocate, | |
5806 | dummy_obstack_deallocate); | |
5807 | ||
5808 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5809 | sizeof (struct partial_die_info)); | |
5810 | ||
5811 | while (1) | |
5812 | { | |
5813 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5814 | ||
5815 | /* A NULL abbrev means the end of a series of children. */ | |
5816 | if (abbrev == NULL) | |
5817 | { | |
5818 | if (--nesting_level == 0) | |
5819 | { | |
5820 | /* PART_DIE was probably the last thing allocated on the | |
5821 | comp_unit_obstack, so we could call obstack_free | |
5822 | here. We don't do that because the waste is small, | |
5823 | and will be cleaned up when we're done with this | |
5824 | compilation unit. This way, we're also more robust | |
5825 | against other users of the comp_unit_obstack. */ | |
5826 | return first_die; | |
5827 | } | |
5828 | info_ptr += bytes_read; | |
5829 | last_die = parent_die; | |
5830 | parent_die = parent_die->die_parent; | |
5831 | continue; | |
5832 | } | |
5833 | ||
5afb4e99 DJ |
5834 | /* Check whether this DIE is interesting enough to save. Normally |
5835 | we would not be interested in members here, but there may be | |
5836 | later variables referencing them via DW_AT_specification (for | |
5837 | static members). */ | |
5838 | if (!load_all | |
5839 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5840 | && abbrev->tag != DW_TAG_enumerator |
5841 | && abbrev->tag != DW_TAG_subprogram | |
bc30ff58 | 5842 | && abbrev->tag != DW_TAG_lexical_block |
72bf9492 | 5843 | && abbrev->tag != DW_TAG_variable |
5afb4e99 DJ |
5844 | && abbrev->tag != DW_TAG_namespace |
5845 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5846 | { |
5847 | /* Otherwise we skip to the next sibling, if any. */ | |
5848 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5849 | continue; | |
5850 | } | |
5851 | ||
5852 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5853 | abfd, info_ptr, cu); | |
5854 | ||
5855 | /* This two-pass algorithm for processing partial symbols has a | |
5856 | high cost in cache pressure. Thus, handle some simple cases | |
5857 | here which cover the majority of C partial symbols. DIEs | |
5858 | which neither have specification tags in them, nor could have | |
5859 | specification tags elsewhere pointing at them, can simply be | |
5860 | processed and discarded. | |
5861 | ||
5862 | This segment is also optional; scan_partial_symbols and | |
5863 | add_partial_symbol will handle these DIEs if we chain | |
5864 | them in normally. When compilers which do not emit large | |
5865 | quantities of duplicate debug information are more common, | |
5866 | this code can probably be removed. */ | |
5867 | ||
5868 | /* Any complete simple types at the top level (pretty much all | |
5869 | of them, for a language without namespaces), can be processed | |
5870 | directly. */ | |
5871 | if (parent_die == NULL | |
5872 | && part_die->has_specification == 0 | |
5873 | && part_die->is_declaration == 0 | |
5874 | && (part_die->tag == DW_TAG_typedef | |
5875 | || part_die->tag == DW_TAG_base_type | |
5876 | || part_die->tag == DW_TAG_subrange_type)) | |
5877 | { | |
5878 | if (building_psymtab && part_die->name != NULL) | |
5879 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5880 | VAR_DOMAIN, LOC_TYPEDEF, | |
5881 | &cu->objfile->static_psymbols, | |
5882 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5883 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5884 | continue; | |
5885 | } | |
5886 | ||
5887 | /* If we're at the second level, and we're an enumerator, and | |
5888 | our parent has no specification (meaning possibly lives in a | |
5889 | namespace elsewhere), then we can add the partial symbol now | |
5890 | instead of queueing it. */ | |
5891 | if (part_die->tag == DW_TAG_enumerator | |
5892 | && parent_die != NULL | |
5893 | && parent_die->die_parent == NULL | |
5894 | && parent_die->tag == DW_TAG_enumeration_type | |
5895 | && parent_die->has_specification == 0) | |
5896 | { | |
5897 | if (part_die->name == NULL) | |
e2e0b3e5 | 5898 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5899 | else if (building_psymtab) |
5900 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5901 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5902 | (cu->language == language_cplus |
5903 | || cu->language == language_java) | |
72bf9492 DJ |
5904 | ? &cu->objfile->global_psymbols |
5905 | : &cu->objfile->static_psymbols, | |
5906 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5907 | ||
5908 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5909 | continue; | |
5910 | } | |
5911 | ||
5912 | /* We'll save this DIE so link it in. */ | |
5913 | part_die->die_parent = parent_die; | |
5914 | part_die->die_sibling = NULL; | |
5915 | part_die->die_child = NULL; | |
5916 | ||
5917 | if (last_die && last_die == parent_die) | |
5918 | last_die->die_child = part_die; | |
5919 | else if (last_die) | |
5920 | last_die->die_sibling = part_die; | |
5921 | ||
5922 | last_die = part_die; | |
5923 | ||
5924 | if (first_die == NULL) | |
5925 | first_die = part_die; | |
5926 | ||
5927 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5928 | find interesting need to be in the hash table, because we | |
5929 | also have the parent/sibling/child chains; only those that we | |
5930 | might refer to by offset later during partial symbol reading. | |
5931 | ||
5932 | For now this means things that might have be the target of a | |
5933 | DW_AT_specification, DW_AT_abstract_origin, or | |
5934 | DW_AT_extension. DW_AT_extension will refer only to | |
5935 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5936 | many things under the function DIE, but we do not recurse | |
5937 | into function DIEs during partial symbol reading) and | |
5938 | possibly variables as well; DW_AT_specification refers to | |
5939 | declarations. Declarations ought to have the DW_AT_declaration | |
5940 | flag. It happens that GCC forgets to put it in sometimes, but | |
5941 | only for functions, not for types. | |
5942 | ||
5943 | Adding more things than necessary to the hash table is harmless | |
5944 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5945 | wasted time in find_partial_die, when we reread the compilation |
5946 | unit with load_all_dies set. */ | |
72bf9492 | 5947 | |
5afb4e99 DJ |
5948 | if (load_all |
5949 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5950 | || abbrev->tag == DW_TAG_variable |
5951 | || abbrev->tag == DW_TAG_namespace | |
5952 | || part_die->is_declaration) | |
5953 | { | |
5954 | void **slot; | |
5955 | ||
5956 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5957 | part_die->offset, INSERT); | |
5958 | *slot = part_die; | |
5959 | } | |
5960 | ||
5961 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5962 | sizeof (struct partial_die_info)); | |
5963 | ||
5964 | /* For some DIEs we want to follow their children (if any). For C | |
bc30ff58 | 5965 | we have no reason to follow the children of structures; for other |
72bf9492 | 5966 | languages we have to, both so that we can get at method physnames |
bc30ff58 JB |
5967 | to infer fully qualified class names, and for DW_AT_specification. |
5968 | ||
5969 | For Ada, we need to scan the children of subprograms and lexical | |
5970 | blocks as well because Ada allows the definition of nested | |
5971 | entities that could be interesting for the debugger, such as | |
5972 | nested subprograms for instance. */ | |
72bf9492 | 5973 | if (last_die->has_children |
5afb4e99 DJ |
5974 | && (load_all |
5975 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5976 | || last_die->tag == DW_TAG_enumeration_type |
5977 | || (cu->language != language_c | |
5978 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 5979 | || last_die->tag == DW_TAG_interface_type |
72bf9492 | 5980 | || last_die->tag == DW_TAG_structure_type |
bc30ff58 JB |
5981 | || last_die->tag == DW_TAG_union_type)) |
5982 | || (cu->language == language_ada | |
5983 | && (last_die->tag == DW_TAG_subprogram | |
5984 | || last_die->tag == DW_TAG_lexical_block)))) | |
72bf9492 DJ |
5985 | { |
5986 | nesting_level++; | |
5987 | parent_die = last_die; | |
5988 | continue; | |
5989 | } | |
5990 | ||
5991 | /* Otherwise we skip to the next sibling, if any. */ | |
5992 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5993 | ||
5994 | /* Back to the top, do it again. */ | |
5995 | } | |
5996 | } | |
5997 | ||
c906108c SS |
5998 | /* Read a minimal amount of information into the minimal die structure. */ |
5999 | ||
fe1b8b76 | 6000 | static gdb_byte * |
72bf9492 DJ |
6001 | read_partial_die (struct partial_die_info *part_die, |
6002 | struct abbrev_info *abbrev, | |
6003 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 6004 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 6005 | { |
72bf9492 | 6006 | unsigned int bytes_read, i; |
c906108c | 6007 | struct attribute attr; |
c5aa993b | 6008 | int has_low_pc_attr = 0; |
c906108c | 6009 | int has_high_pc_attr = 0; |
e7030f15 | 6010 | CORE_ADDR base_address = 0; |
85cbf3d3 JK |
6011 | enum |
6012 | { | |
6013 | base_address_none, | |
6014 | base_address_low_pc, | |
6015 | /* Overrides BASE_ADDRESS_LOW_PC. */ | |
6016 | base_address_entry_pc | |
6017 | } | |
6018 | base_address_type = base_address_none; | |
c906108c | 6019 | |
72bf9492 | 6020 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 6021 | |
dce234bc | 6022 | part_die->offset = info_ptr - dwarf2_per_objfile->info.buffer; |
72bf9492 DJ |
6023 | |
6024 | info_ptr += abbrev_len; | |
6025 | ||
6026 | if (abbrev == NULL) | |
6027 | return info_ptr; | |
6028 | ||
c906108c SS |
6029 | part_die->tag = abbrev->tag; |
6030 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
6031 | |
6032 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6033 | { | |
e7c27a73 | 6034 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
6035 | |
6036 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 6037 | partial symbol table. */ |
c906108c SS |
6038 | switch (attr.name) |
6039 | { | |
6040 | case DW_AT_name: | |
71c25dea TT |
6041 | switch (part_die->tag) |
6042 | { | |
6043 | case DW_TAG_compile_unit: | |
6044 | /* Compilation units have a DW_AT_name that is a filename, not | |
6045 | a source language identifier. */ | |
6046 | case DW_TAG_enumeration_type: | |
6047 | case DW_TAG_enumerator: | |
6048 | /* These tags always have simple identifiers already; no need | |
6049 | to canonicalize them. */ | |
6050 | part_die->name = DW_STRING (&attr); | |
6051 | break; | |
6052 | default: | |
6053 | part_die->name | |
6054 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, | |
6055 | &cu->comp_unit_obstack); | |
6056 | break; | |
6057 | } | |
c906108c | 6058 | break; |
57c22c6c BR |
6059 | case DW_AT_comp_dir: |
6060 | if (part_die->dirname == NULL) | |
6061 | part_die->dirname = DW_STRING (&attr); | |
6062 | break; | |
c906108c SS |
6063 | case DW_AT_MIPS_linkage_name: |
6064 | part_die->name = DW_STRING (&attr); | |
6065 | break; | |
6066 | case DW_AT_low_pc: | |
6067 | has_low_pc_attr = 1; | |
6068 | part_die->lowpc = DW_ADDR (&attr); | |
85cbf3d3 JK |
6069 | if (part_die->tag == DW_TAG_compile_unit |
6070 | && base_address_type < base_address_low_pc) | |
6071 | { | |
6072 | base_address = DW_ADDR (&attr); | |
6073 | base_address_type = base_address_low_pc; | |
6074 | } | |
c906108c SS |
6075 | break; |
6076 | case DW_AT_high_pc: | |
6077 | has_high_pc_attr = 1; | |
6078 | part_die->highpc = DW_ADDR (&attr); | |
6079 | break; | |
85cbf3d3 JK |
6080 | case DW_AT_entry_pc: |
6081 | if (part_die->tag == DW_TAG_compile_unit | |
6082 | && base_address_type < base_address_entry_pc) | |
6083 | { | |
6084 | base_address = DW_ADDR (&attr); | |
6085 | base_address_type = base_address_entry_pc; | |
6086 | } | |
6087 | break; | |
43039443 | 6088 | case DW_AT_ranges: |
ff013f42 JK |
6089 | if (part_die->tag == DW_TAG_compile_unit) |
6090 | { | |
6091 | cu->ranges_offset = DW_UNSND (&attr); | |
6092 | cu->has_ranges_offset = 1; | |
6093 | } | |
43039443 | 6094 | break; |
c906108c | 6095 | case DW_AT_location: |
8e19ed76 PS |
6096 | /* Support the .debug_loc offsets */ |
6097 | if (attr_form_is_block (&attr)) | |
6098 | { | |
6099 | part_die->locdesc = DW_BLOCK (&attr); | |
6100 | } | |
3690dd37 | 6101 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 6102 | { |
4d3c2250 | 6103 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
6104 | } |
6105 | else | |
6106 | { | |
4d3c2250 KB |
6107 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
6108 | "partial symbol information"); | |
8e19ed76 | 6109 | } |
c906108c SS |
6110 | break; |
6111 | case DW_AT_language: | |
6112 | part_die->language = DW_UNSND (&attr); | |
6113 | break; | |
6114 | case DW_AT_external: | |
6115 | part_die->is_external = DW_UNSND (&attr); | |
6116 | break; | |
6117 | case DW_AT_declaration: | |
6118 | part_die->is_declaration = DW_UNSND (&attr); | |
6119 | break; | |
6120 | case DW_AT_type: | |
6121 | part_die->has_type = 1; | |
6122 | break; | |
6123 | case DW_AT_abstract_origin: | |
6124 | case DW_AT_specification: | |
72bf9492 DJ |
6125 | case DW_AT_extension: |
6126 | part_die->has_specification = 1; | |
c764a876 | 6127 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
c906108c SS |
6128 | break; |
6129 | case DW_AT_sibling: | |
6130 | /* Ignore absolute siblings, they might point outside of | |
6131 | the current compile unit. */ | |
6132 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 6133 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 6134 | else |
dce234bc | 6135 | part_die->sibling = dwarf2_per_objfile->info.buffer |
c764a876 | 6136 | + dwarf2_get_ref_die_offset (&attr); |
c906108c | 6137 | break; |
aaa75496 JB |
6138 | case DW_AT_stmt_list: |
6139 | part_die->has_stmt_list = 1; | |
6140 | part_die->line_offset = DW_UNSND (&attr); | |
6141 | break; | |
fa4028e9 JB |
6142 | case DW_AT_byte_size: |
6143 | part_die->has_byte_size = 1; | |
6144 | break; | |
68511cec CES |
6145 | case DW_AT_calling_convention: |
6146 | /* DWARF doesn't provide a way to identify a program's source-level | |
6147 | entry point. DW_AT_calling_convention attributes are only meant | |
6148 | to describe functions' calling conventions. | |
6149 | ||
6150 | However, because it's a necessary piece of information in | |
6151 | Fortran, and because DW_CC_program is the only piece of debugging | |
6152 | information whose definition refers to a 'main program' at all, | |
6153 | several compilers have begun marking Fortran main programs with | |
6154 | DW_CC_program --- even when those functions use the standard | |
6155 | calling conventions. | |
6156 | ||
6157 | So until DWARF specifies a way to provide this information and | |
6158 | compilers pick up the new representation, we'll support this | |
6159 | practice. */ | |
6160 | if (DW_UNSND (&attr) == DW_CC_program | |
6161 | && cu->language == language_fortran) | |
6162 | set_main_name (part_die->name); | |
6163 | break; | |
c906108c SS |
6164 | default: |
6165 | break; | |
6166 | } | |
6167 | } | |
6168 | ||
c906108c SS |
6169 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
6170 | eliminate duplicate copies of functions and vtables and such. | |
6171 | The linker will arbitrarily choose one and discard the others. | |
6172 | The AT_*_pc values for such functions refer to local labels in | |
6173 | these sections. If the section from that file was discarded, the | |
6174 | labels are not in the output, so the relocs get a value of 0. | |
6175 | If this is a discarded function, mark the pc bounds as invalid, | |
6176 | so that GDB will ignore it. */ | |
6177 | if (has_low_pc_attr && has_high_pc_attr | |
6178 | && part_die->lowpc < part_die->highpc | |
6179 | && (part_die->lowpc != 0 | |
72dca2f5 | 6180 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 6181 | part_die->has_pc_info = 1; |
85cbf3d3 | 6182 | |
d00adf39 | 6183 | if (base_address_type != base_address_none && !cu->base_known) |
85cbf3d3 JK |
6184 | { |
6185 | gdb_assert (part_die->tag == DW_TAG_compile_unit); | |
d00adf39 DE |
6186 | cu->base_known = 1; |
6187 | cu->base_address = base_address; | |
85cbf3d3 JK |
6188 | } |
6189 | ||
c906108c SS |
6190 | return info_ptr; |
6191 | } | |
6192 | ||
72bf9492 DJ |
6193 | /* Find a cached partial DIE at OFFSET in CU. */ |
6194 | ||
6195 | static struct partial_die_info * | |
c764a876 | 6196 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 DJ |
6197 | { |
6198 | struct partial_die_info *lookup_die = NULL; | |
6199 | struct partial_die_info part_die; | |
6200 | ||
6201 | part_die.offset = offset; | |
6202 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
6203 | ||
72bf9492 DJ |
6204 | return lookup_die; |
6205 | } | |
6206 | ||
6207 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
6208 | ||
6209 | static struct partial_die_info * | |
c764a876 | 6210 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
72bf9492 | 6211 | { |
5afb4e99 DJ |
6212 | struct dwarf2_per_cu_data *per_cu = NULL; |
6213 | struct partial_die_info *pd = NULL; | |
72bf9492 | 6214 | |
45452591 | 6215 | if (offset_in_cu_p (&cu->header, offset)) |
5afb4e99 DJ |
6216 | { |
6217 | pd = find_partial_die_in_comp_unit (offset, cu); | |
6218 | if (pd != NULL) | |
6219 | return pd; | |
6220 | } | |
72bf9492 | 6221 | |
ae038cb0 DJ |
6222 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
6223 | ||
ae038cb0 DJ |
6224 | if (per_cu->cu == NULL) |
6225 | { | |
6226 | load_comp_unit (per_cu, cu->objfile); | |
6227 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
6228 | dwarf2_per_objfile->read_in_chain = per_cu; | |
6229 | } | |
6230 | ||
6231 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
6232 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
6233 | ||
6234 | if (pd == NULL && per_cu->load_all_dies == 0) | |
6235 | { | |
6236 | struct cleanup *back_to; | |
6237 | struct partial_die_info comp_unit_die; | |
6238 | struct abbrev_info *abbrev; | |
6239 | unsigned int bytes_read; | |
6240 | char *info_ptr; | |
6241 | ||
6242 | per_cu->load_all_dies = 1; | |
6243 | ||
6244 | /* Re-read the DIEs. */ | |
6245 | back_to = make_cleanup (null_cleanup, 0); | |
6246 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
6247 | { | |
6248 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
6249 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
6250 | } | |
dce234bc | 6251 | info_ptr = (dwarf2_per_objfile->info.buffer |
d00adf39 DE |
6252 | + per_cu->cu->header.offset |
6253 | + per_cu->cu->header.first_die_offset); | |
5afb4e99 DJ |
6254 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
6255 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
6256 | per_cu->cu->objfile->obfd, info_ptr, | |
6257 | per_cu->cu); | |
6258 | if (comp_unit_die.has_children) | |
6259 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
6260 | do_cleanups (back_to); | |
6261 | ||
6262 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
6263 | } | |
6264 | ||
6265 | if (pd == NULL) | |
6266 | internal_error (__FILE__, __LINE__, | |
c764a876 | 6267 | _("could not find partial DIE 0x%x in cache [from module %s]\n"), |
5afb4e99 DJ |
6268 | offset, bfd_get_filename (cu->objfile->obfd)); |
6269 | return pd; | |
72bf9492 DJ |
6270 | } |
6271 | ||
6272 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6273 | may set the is_external flag or change the DIE's name. */ | |
6274 | ||
6275 | static void | |
6276 | fixup_partial_die (struct partial_die_info *part_die, | |
6277 | struct dwarf2_cu *cu) | |
6278 | { | |
6279 | /* If we found a reference attribute and the DIE has no name, try | |
6280 | to find a name in the referred to DIE. */ | |
6281 | ||
6282 | if (part_die->name == NULL && part_die->has_specification) | |
6283 | { | |
6284 | struct partial_die_info *spec_die; | |
72bf9492 | 6285 | |
10b3939b | 6286 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6287 | |
10b3939b | 6288 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6289 | |
6290 | if (spec_die->name) | |
6291 | { | |
6292 | part_die->name = spec_die->name; | |
6293 | ||
6294 | /* Copy DW_AT_external attribute if it is set. */ | |
6295 | if (spec_die->is_external) | |
6296 | part_die->is_external = spec_die->is_external; | |
6297 | } | |
6298 | } | |
6299 | ||
6300 | /* Set default names for some unnamed DIEs. */ | |
6301 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6302 | || part_die->tag == DW_TAG_class_type)) | |
6303 | part_die->name = "(anonymous class)"; | |
6304 | ||
6305 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6306 | part_die->name = "(anonymous namespace)"; | |
6307 | ||
6308 | if (part_die->tag == DW_TAG_structure_type | |
6309 | || part_die->tag == DW_TAG_class_type | |
6310 | || part_die->tag == DW_TAG_union_type) | |
6311 | guess_structure_name (part_die, cu); | |
6312 | } | |
6313 | ||
639d11d3 DC |
6314 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6315 | point to a newly allocated die with its information, except for its | |
6316 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6317 | whether the die has children or not. */ | |
c906108c | 6318 | |
fe1b8b76 JB |
6319 | static gdb_byte * |
6320 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 6321 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
6322 | { |
6323 | unsigned int abbrev_number, bytes_read, i, offset; | |
6324 | struct abbrev_info *abbrev; | |
6325 | struct die_info *die; | |
6326 | ||
dce234bc | 6327 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
c906108c SS |
6328 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6329 | info_ptr += bytes_read; | |
6330 | if (!abbrev_number) | |
6331 | { | |
1d325ec1 | 6332 | *diep = NULL; |
639d11d3 | 6333 | *has_children = 0; |
c906108c SS |
6334 | return info_ptr; |
6335 | } | |
6336 | ||
e7c27a73 | 6337 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
6338 | if (!abbrev) |
6339 | { | |
8a3fe4f8 | 6340 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 6341 | abbrev_number, |
639d11d3 | 6342 | bfd_get_filename (abfd)); |
c906108c | 6343 | } |
b60c80d6 | 6344 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
c906108c SS |
6345 | die->offset = offset; |
6346 | die->tag = abbrev->tag; | |
c906108c | 6347 | die->abbrev = abbrev_number; |
c906108c SS |
6348 | |
6349 | die->num_attrs = abbrev->num_attrs; | |
c906108c SS |
6350 | |
6351 | for (i = 0; i < abbrev->num_attrs; ++i) | |
03dd20cc DJ |
6352 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
6353 | abfd, info_ptr, cu); | |
c906108c SS |
6354 | |
6355 | *diep = die; | |
639d11d3 | 6356 | *has_children = abbrev->has_children; |
c906108c SS |
6357 | return info_ptr; |
6358 | } | |
6359 | ||
a8329558 | 6360 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6361 | |
fe1b8b76 | 6362 | static gdb_byte * |
a8329558 | 6363 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 6364 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 6365 | struct dwarf2_cu *cu) |
c906108c | 6366 | { |
e7c27a73 | 6367 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6368 | unsigned int bytes_read; |
6369 | struct dwarf_block *blk; | |
6370 | ||
a8329558 KW |
6371 | attr->form = form; |
6372 | switch (form) | |
c906108c SS |
6373 | { |
6374 | case DW_FORM_addr: | |
6375 | case DW_FORM_ref_addr: | |
e7c27a73 | 6376 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 6377 | info_ptr += bytes_read; |
c906108c SS |
6378 | break; |
6379 | case DW_FORM_block2: | |
7b5a2f43 | 6380 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6381 | blk->size = read_2_bytes (abfd, info_ptr); |
6382 | info_ptr += 2; | |
6383 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6384 | info_ptr += blk->size; | |
6385 | DW_BLOCK (attr) = blk; | |
6386 | break; | |
6387 | case DW_FORM_block4: | |
7b5a2f43 | 6388 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6389 | blk->size = read_4_bytes (abfd, info_ptr); |
6390 | info_ptr += 4; | |
6391 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6392 | info_ptr += blk->size; | |
6393 | DW_BLOCK (attr) = blk; | |
6394 | break; | |
6395 | case DW_FORM_data2: | |
6396 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
6397 | info_ptr += 2; | |
6398 | break; | |
6399 | case DW_FORM_data4: | |
6400 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
6401 | info_ptr += 4; | |
6402 | break; | |
6403 | case DW_FORM_data8: | |
6404 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
6405 | info_ptr += 8; | |
6406 | break; | |
6407 | case DW_FORM_string: | |
6408 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
6409 | info_ptr += bytes_read; | |
6410 | break; | |
4bdf3d34 JJ |
6411 | case DW_FORM_strp: |
6412 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
6413 | &bytes_read); | |
6414 | info_ptr += bytes_read; | |
6415 | break; | |
c906108c | 6416 | case DW_FORM_block: |
7b5a2f43 | 6417 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6418 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6419 | info_ptr += bytes_read; | |
6420 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6421 | info_ptr += blk->size; | |
6422 | DW_BLOCK (attr) = blk; | |
6423 | break; | |
6424 | case DW_FORM_block1: | |
7b5a2f43 | 6425 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6426 | blk->size = read_1_byte (abfd, info_ptr); |
6427 | info_ptr += 1; | |
6428 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6429 | info_ptr += blk->size; | |
6430 | DW_BLOCK (attr) = blk; | |
6431 | break; | |
6432 | case DW_FORM_data1: | |
6433 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6434 | info_ptr += 1; | |
6435 | break; | |
6436 | case DW_FORM_flag: | |
6437 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6438 | info_ptr += 1; | |
6439 | break; | |
6440 | case DW_FORM_sdata: | |
6441 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
6442 | info_ptr += bytes_read; | |
6443 | break; | |
6444 | case DW_FORM_udata: | |
6445 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6446 | info_ptr += bytes_read; | |
6447 | break; | |
6448 | case DW_FORM_ref1: | |
10b3939b | 6449 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
6450 | info_ptr += 1; |
6451 | break; | |
6452 | case DW_FORM_ref2: | |
10b3939b | 6453 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
6454 | info_ptr += 2; |
6455 | break; | |
6456 | case DW_FORM_ref4: | |
10b3939b | 6457 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
6458 | info_ptr += 4; |
6459 | break; | |
613e1657 | 6460 | case DW_FORM_ref8: |
10b3939b | 6461 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
6462 | info_ptr += 8; |
6463 | break; | |
c906108c | 6464 | case DW_FORM_ref_udata: |
10b3939b DJ |
6465 | DW_ADDR (attr) = (cu->header.offset |
6466 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
6467 | info_ptr += bytes_read; |
6468 | break; | |
c906108c | 6469 | case DW_FORM_indirect: |
a8329558 KW |
6470 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6471 | info_ptr += bytes_read; | |
e7c27a73 | 6472 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 6473 | break; |
c906108c | 6474 | default: |
8a3fe4f8 | 6475 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
6476 | dwarf_form_name (form), |
6477 | bfd_get_filename (abfd)); | |
c906108c | 6478 | } |
28e94949 JB |
6479 | |
6480 | /* We have seen instances where the compiler tried to emit a byte | |
6481 | size attribute of -1 which ended up being encoded as an unsigned | |
6482 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
6483 | an object of this size seems pretty unlikely so we can relatively | |
6484 | safely treat these cases as if the size attribute was invalid and | |
6485 | treat them as zero by default. */ | |
6486 | if (attr->name == DW_AT_byte_size | |
6487 | && form == DW_FORM_data4 | |
6488 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
6489 | { |
6490 | complaint | |
6491 | (&symfile_complaints, | |
6492 | _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"), | |
6493 | DW_UNSND (attr)); | |
6494 | DW_UNSND (attr) = 0; | |
6495 | } | |
28e94949 | 6496 | |
c906108c SS |
6497 | return info_ptr; |
6498 | } | |
6499 | ||
a8329558 KW |
6500 | /* Read an attribute described by an abbreviated attribute. */ |
6501 | ||
fe1b8b76 | 6502 | static gdb_byte * |
a8329558 | 6503 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 6504 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
6505 | { |
6506 | attr->name = abbrev->name; | |
e7c27a73 | 6507 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
6508 | } |
6509 | ||
c906108c SS |
6510 | /* read dwarf information from a buffer */ |
6511 | ||
6512 | static unsigned int | |
fe1b8b76 | 6513 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6514 | { |
fe1b8b76 | 6515 | return bfd_get_8 (abfd, buf); |
c906108c SS |
6516 | } |
6517 | ||
6518 | static int | |
fe1b8b76 | 6519 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6520 | { |
fe1b8b76 | 6521 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
6522 | } |
6523 | ||
6524 | static unsigned int | |
fe1b8b76 | 6525 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6526 | { |
fe1b8b76 | 6527 | return bfd_get_16 (abfd, buf); |
c906108c SS |
6528 | } |
6529 | ||
6530 | static int | |
fe1b8b76 | 6531 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6532 | { |
fe1b8b76 | 6533 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
6534 | } |
6535 | ||
6536 | static unsigned int | |
fe1b8b76 | 6537 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6538 | { |
fe1b8b76 | 6539 | return bfd_get_32 (abfd, buf); |
c906108c SS |
6540 | } |
6541 | ||
6542 | static int | |
fe1b8b76 | 6543 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6544 | { |
fe1b8b76 | 6545 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
6546 | } |
6547 | ||
ce5d95e1 | 6548 | static unsigned long |
fe1b8b76 | 6549 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6550 | { |
fe1b8b76 | 6551 | return bfd_get_64 (abfd, buf); |
c906108c SS |
6552 | } |
6553 | ||
6554 | static CORE_ADDR | |
fe1b8b76 | 6555 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 6556 | unsigned int *bytes_read) |
c906108c | 6557 | { |
e7c27a73 | 6558 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6559 | CORE_ADDR retval = 0; |
6560 | ||
107d2387 | 6561 | if (cu_header->signed_addr_p) |
c906108c | 6562 | { |
107d2387 AC |
6563 | switch (cu_header->addr_size) |
6564 | { | |
6565 | case 2: | |
fe1b8b76 | 6566 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6567 | break; |
6568 | case 4: | |
fe1b8b76 | 6569 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6570 | break; |
6571 | case 8: | |
fe1b8b76 | 6572 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6573 | break; |
6574 | default: | |
8e65ff28 | 6575 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6576 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6577 | bfd_get_filename (abfd)); |
107d2387 AC |
6578 | } |
6579 | } | |
6580 | else | |
6581 | { | |
6582 | switch (cu_header->addr_size) | |
6583 | { | |
6584 | case 2: | |
fe1b8b76 | 6585 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6586 | break; |
6587 | case 4: | |
fe1b8b76 | 6588 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6589 | break; |
6590 | case 8: | |
fe1b8b76 | 6591 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6592 | break; |
6593 | default: | |
8e65ff28 | 6594 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6595 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6596 | bfd_get_filename (abfd)); |
107d2387 | 6597 | } |
c906108c | 6598 | } |
64367e0a | 6599 | |
107d2387 AC |
6600 | *bytes_read = cu_header->addr_size; |
6601 | return retval; | |
c906108c SS |
6602 | } |
6603 | ||
f7ef9339 | 6604 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6605 | specification allows the initial length to take up either 4 bytes |
6606 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6607 | bytes describe the length and all offsets will be 8 bytes in length | |
6608 | instead of 4. | |
6609 | ||
f7ef9339 KB |
6610 | An older, non-standard 64-bit format is also handled by this |
6611 | function. The older format in question stores the initial length | |
6612 | as an 8-byte quantity without an escape value. Lengths greater | |
6613 | than 2^32 aren't very common which means that the initial 4 bytes | |
6614 | is almost always zero. Since a length value of zero doesn't make | |
6615 | sense for the 32-bit format, this initial zero can be considered to | |
6616 | be an escape value which indicates the presence of the older 64-bit | |
6617 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6618 | greater than 4GB. If it becomes necessary to handle lengths |
6619 | somewhat larger than 4GB, we could allow other small values (such | |
6620 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6621 | escape values indicating the presence of the old format. | |
f7ef9339 | 6622 | |
917c78fc MK |
6623 | The value returned via bytes_read should be used to increment the |
6624 | relevant pointer after calling read_initial_length(). | |
c764a876 | 6625 | |
613e1657 KB |
6626 | [ Note: read_initial_length() and read_offset() are based on the |
6627 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6628 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6629 | from: |
6630 | ||
f7ef9339 | 6631 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6632 | |
6633 | This document is only a draft and is subject to change. (So beware.) | |
6634 | ||
f7ef9339 | 6635 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6636 | determined empirically by examining 64-bit ELF files produced by |
6637 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6638 | |
6639 | - Kevin, July 16, 2002 | |
613e1657 KB |
6640 | ] */ |
6641 | ||
6642 | static LONGEST | |
c764a876 | 6643 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
613e1657 | 6644 | { |
fe1b8b76 | 6645 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6646 | |
dd373385 | 6647 | if (length == 0xffffffff) |
613e1657 | 6648 | { |
fe1b8b76 | 6649 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6650 | *bytes_read = 12; |
613e1657 | 6651 | } |
dd373385 | 6652 | else if (length == 0) |
f7ef9339 | 6653 | { |
dd373385 | 6654 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6655 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6656 | *bytes_read = 8; |
f7ef9339 | 6657 | } |
613e1657 KB |
6658 | else |
6659 | { | |
6660 | *bytes_read = 4; | |
613e1657 KB |
6661 | } |
6662 | ||
c764a876 DE |
6663 | return length; |
6664 | } | |
dd373385 | 6665 | |
c764a876 DE |
6666 | /* Cover function for read_initial_length. |
6667 | Returns the length of the object at BUF, and stores the size of the | |
6668 | initial length in *BYTES_READ and stores the size that offsets will be in | |
6669 | *OFFSET_SIZE. | |
6670 | If the initial length size is not equivalent to that specified in | |
6671 | CU_HEADER then issue a complaint. | |
6672 | This is useful when reading non-comp-unit headers. */ | |
dd373385 | 6673 | |
c764a876 DE |
6674 | static LONGEST |
6675 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, | |
6676 | const struct comp_unit_head *cu_header, | |
6677 | unsigned int *bytes_read, | |
6678 | unsigned int *offset_size) | |
6679 | { | |
6680 | LONGEST length = read_initial_length (abfd, buf, bytes_read); | |
6681 | ||
6682 | gdb_assert (cu_header->initial_length_size == 4 | |
6683 | || cu_header->initial_length_size == 8 | |
6684 | || cu_header->initial_length_size == 12); | |
6685 | ||
6686 | if (cu_header->initial_length_size != *bytes_read) | |
6687 | complaint (&symfile_complaints, | |
6688 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
dd373385 | 6689 | |
c764a876 | 6690 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
dd373385 | 6691 | return length; |
613e1657 KB |
6692 | } |
6693 | ||
6694 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6695 | given by cu_header->offset_size. */ |
613e1657 KB |
6696 | |
6697 | static LONGEST | |
fe1b8b76 | 6698 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6699 | unsigned int *bytes_read) |
c764a876 DE |
6700 | { |
6701 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); | |
6702 | *bytes_read = cu_header->offset_size; | |
6703 | return offset; | |
6704 | } | |
6705 | ||
6706 | /* Read an offset from the data stream. */ | |
6707 | ||
6708 | static LONGEST | |
6709 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) | |
613e1657 KB |
6710 | { |
6711 | LONGEST retval = 0; | |
6712 | ||
c764a876 | 6713 | switch (offset_size) |
613e1657 KB |
6714 | { |
6715 | case 4: | |
fe1b8b76 | 6716 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6717 | break; |
6718 | case 8: | |
fe1b8b76 | 6719 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6720 | break; |
6721 | default: | |
8e65ff28 | 6722 | internal_error (__FILE__, __LINE__, |
c764a876 | 6723 | _("read_offset_1: bad switch [in module %s]"), |
659b0389 | 6724 | bfd_get_filename (abfd)); |
613e1657 KB |
6725 | } |
6726 | ||
917c78fc | 6727 | return retval; |
613e1657 KB |
6728 | } |
6729 | ||
fe1b8b76 JB |
6730 | static gdb_byte * |
6731 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6732 | { |
6733 | /* If the size of a host char is 8 bits, we can return a pointer | |
6734 | to the buffer, otherwise we have to copy the data to a buffer | |
6735 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6736 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6737 | return buf; |
c906108c SS |
6738 | } |
6739 | ||
6740 | static char * | |
fe1b8b76 | 6741 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6742 | { |
6743 | /* If the size of a host char is 8 bits, we can return a pointer | |
6744 | to the string, otherwise we have to copy the string to a buffer | |
6745 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6746 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6747 | if (*buf == '\0') |
6748 | { | |
6749 | *bytes_read_ptr = 1; | |
6750 | return NULL; | |
6751 | } | |
fe1b8b76 JB |
6752 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6753 | return (char *) buf; | |
4bdf3d34 JJ |
6754 | } |
6755 | ||
6756 | static char * | |
fe1b8b76 | 6757 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6758 | const struct comp_unit_head *cu_header, |
6759 | unsigned int *bytes_read_ptr) | |
6760 | { | |
c764a876 | 6761 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
c906108c | 6762 | |
dce234bc | 6763 | if (dwarf2_per_objfile->str.buffer == NULL) |
c906108c | 6764 | { |
8a3fe4f8 | 6765 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6766 | bfd_get_filename (abfd)); |
4bdf3d34 | 6767 | return NULL; |
c906108c | 6768 | } |
dce234bc | 6769 | if (str_offset >= dwarf2_per_objfile->str.size) |
c906108c | 6770 | { |
8a3fe4f8 | 6771 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6772 | bfd_get_filename (abfd)); |
c906108c SS |
6773 | return NULL; |
6774 | } | |
4bdf3d34 | 6775 | gdb_assert (HOST_CHAR_BIT == 8); |
dce234bc | 6776 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
4bdf3d34 | 6777 | return NULL; |
dce234bc | 6778 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
c906108c SS |
6779 | } |
6780 | ||
ce5d95e1 | 6781 | static unsigned long |
fe1b8b76 | 6782 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6783 | { |
ce5d95e1 JB |
6784 | unsigned long result; |
6785 | unsigned int num_read; | |
c906108c SS |
6786 | int i, shift; |
6787 | unsigned char byte; | |
6788 | ||
6789 | result = 0; | |
6790 | shift = 0; | |
6791 | num_read = 0; | |
6792 | i = 0; | |
6793 | while (1) | |
6794 | { | |
fe1b8b76 | 6795 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6796 | buf++; |
6797 | num_read++; | |
ce5d95e1 | 6798 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6799 | if ((byte & 128) == 0) |
6800 | { | |
6801 | break; | |
6802 | } | |
6803 | shift += 7; | |
6804 | } | |
6805 | *bytes_read_ptr = num_read; | |
6806 | return result; | |
6807 | } | |
6808 | ||
ce5d95e1 | 6809 | static long |
fe1b8b76 | 6810 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6811 | { |
ce5d95e1 | 6812 | long result; |
77e0b926 | 6813 | int i, shift, num_read; |
c906108c SS |
6814 | unsigned char byte; |
6815 | ||
6816 | result = 0; | |
6817 | shift = 0; | |
c906108c SS |
6818 | num_read = 0; |
6819 | i = 0; | |
6820 | while (1) | |
6821 | { | |
fe1b8b76 | 6822 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6823 | buf++; |
6824 | num_read++; | |
ce5d95e1 | 6825 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6826 | shift += 7; |
6827 | if ((byte & 128) == 0) | |
6828 | { | |
6829 | break; | |
6830 | } | |
6831 | } | |
77e0b926 DJ |
6832 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6833 | result |= -(((long)1) << shift); | |
c906108c SS |
6834 | *bytes_read_ptr = num_read; |
6835 | return result; | |
6836 | } | |
6837 | ||
4bb7a0a7 DJ |
6838 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6839 | ||
fe1b8b76 JB |
6840 | static gdb_byte * |
6841 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6842 | { |
6843 | int byte; | |
6844 | ||
6845 | while (1) | |
6846 | { | |
fe1b8b76 | 6847 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6848 | buf++; |
6849 | if ((byte & 128) == 0) | |
6850 | return buf; | |
6851 | } | |
6852 | } | |
6853 | ||
c906108c | 6854 | static void |
e142c38c | 6855 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6856 | { |
6857 | switch (lang) | |
6858 | { | |
6859 | case DW_LANG_C89: | |
76bee0cc | 6860 | case DW_LANG_C99: |
c906108c | 6861 | case DW_LANG_C: |
e142c38c | 6862 | cu->language = language_c; |
c906108c SS |
6863 | break; |
6864 | case DW_LANG_C_plus_plus: | |
e142c38c | 6865 | cu->language = language_cplus; |
c906108c SS |
6866 | break; |
6867 | case DW_LANG_Fortran77: | |
6868 | case DW_LANG_Fortran90: | |
b21b22e0 | 6869 | case DW_LANG_Fortran95: |
e142c38c | 6870 | cu->language = language_fortran; |
c906108c SS |
6871 | break; |
6872 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6873 | cu->language = language_asm; |
c906108c | 6874 | break; |
bebd888e | 6875 | case DW_LANG_Java: |
e142c38c | 6876 | cu->language = language_java; |
bebd888e | 6877 | break; |
c906108c | 6878 | case DW_LANG_Ada83: |
8aaf0b47 | 6879 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6880 | cu->language = language_ada; |
6881 | break; | |
72019c9c GM |
6882 | case DW_LANG_Modula2: |
6883 | cu->language = language_m2; | |
6884 | break; | |
fe8e67fd PM |
6885 | case DW_LANG_Pascal83: |
6886 | cu->language = language_pascal; | |
6887 | break; | |
22566fbd DJ |
6888 | case DW_LANG_ObjC: |
6889 | cu->language = language_objc; | |
6890 | break; | |
c906108c SS |
6891 | case DW_LANG_Cobol74: |
6892 | case DW_LANG_Cobol85: | |
c906108c | 6893 | default: |
e142c38c | 6894 | cu->language = language_minimal; |
c906108c SS |
6895 | break; |
6896 | } | |
e142c38c | 6897 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6898 | } |
6899 | ||
6900 | /* Return the named attribute or NULL if not there. */ | |
6901 | ||
6902 | static struct attribute * | |
e142c38c | 6903 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6904 | { |
6905 | unsigned int i; | |
6906 | struct attribute *spec = NULL; | |
6907 | ||
6908 | for (i = 0; i < die->num_attrs; ++i) | |
6909 | { | |
6910 | if (die->attrs[i].name == name) | |
10b3939b | 6911 | return &die->attrs[i]; |
c906108c SS |
6912 | if (die->attrs[i].name == DW_AT_specification |
6913 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6914 | spec = &die->attrs[i]; | |
6915 | } | |
c906108c | 6916 | |
10b3939b | 6917 | if (spec) |
f2f0e013 DJ |
6918 | { |
6919 | die = follow_die_ref (die, spec, &cu); | |
6920 | return dwarf2_attr (die, name, cu); | |
6921 | } | |
c5aa993b | 6922 | |
c906108c SS |
6923 | return NULL; |
6924 | } | |
6925 | ||
05cf31d1 JB |
6926 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6927 | and holds a non-zero value. This function should only be used for | |
6928 | DW_FORM_flag attributes. */ | |
6929 | ||
6930 | static int | |
6931 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6932 | { | |
6933 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6934 | ||
6935 | return (attr && DW_UNSND (attr)); | |
6936 | } | |
6937 | ||
3ca72b44 | 6938 | static int |
e142c38c | 6939 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6940 | { |
05cf31d1 JB |
6941 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6942 | which value is non-zero. However, we have to be careful with | |
6943 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6944 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6945 | end up accidently finding a declaration attribute that belongs | |
6946 | to a different DIE referenced by the specification attribute, | |
6947 | even though the given DIE does not have a declaration attribute. */ | |
6948 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6949 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6950 | } |
6951 | ||
63d06c5c | 6952 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 DJ |
6953 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
6954 | containing the return value on output. */ | |
63d06c5c DC |
6955 | |
6956 | static struct die_info * | |
f2f0e013 | 6957 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 6958 | { |
f2f0e013 DJ |
6959 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
6960 | *spec_cu); | |
63d06c5c DC |
6961 | |
6962 | if (spec_attr == NULL) | |
6963 | return NULL; | |
6964 | else | |
f2f0e013 | 6965 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 6966 | } |
c906108c | 6967 | |
debd256d JB |
6968 | /* Free the line_header structure *LH, and any arrays and strings it |
6969 | refers to. */ | |
6970 | static void | |
6971 | free_line_header (struct line_header *lh) | |
6972 | { | |
6973 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6974 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6975 | |
6976 | /* Remember that all the lh->file_names[i].name pointers are | |
6977 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6978 | if (lh->file_names) | |
a8bc7b56 | 6979 | xfree (lh->file_names); |
debd256d JB |
6980 | |
6981 | /* Similarly for the include directory names. */ | |
6982 | if (lh->include_dirs) | |
a8bc7b56 | 6983 | xfree (lh->include_dirs); |
debd256d | 6984 | |
a8bc7b56 | 6985 | xfree (lh); |
debd256d JB |
6986 | } |
6987 | ||
6988 | ||
6989 | /* Add an entry to LH's include directory table. */ | |
6990 | static void | |
6991 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6992 | { |
debd256d JB |
6993 | /* Grow the array if necessary. */ |
6994 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6995 | { |
debd256d JB |
6996 | lh->include_dirs_size = 1; /* for testing */ |
6997 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6998 | * sizeof (*lh->include_dirs)); | |
6999 | } | |
7000 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
7001 | { | |
7002 | lh->include_dirs_size *= 2; | |
7003 | lh->include_dirs = xrealloc (lh->include_dirs, | |
7004 | (lh->include_dirs_size | |
7005 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 7006 | } |
c906108c | 7007 | |
debd256d JB |
7008 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
7009 | } | |
7010 | ||
7011 | ||
7012 | /* Add an entry to LH's file name table. */ | |
7013 | static void | |
7014 | add_file_name (struct line_header *lh, | |
7015 | char *name, | |
7016 | unsigned int dir_index, | |
7017 | unsigned int mod_time, | |
7018 | unsigned int length) | |
7019 | { | |
7020 | struct file_entry *fe; | |
7021 | ||
7022 | /* Grow the array if necessary. */ | |
7023 | if (lh->file_names_size == 0) | |
7024 | { | |
7025 | lh->file_names_size = 1; /* for testing */ | |
7026 | lh->file_names = xmalloc (lh->file_names_size | |
7027 | * sizeof (*lh->file_names)); | |
7028 | } | |
7029 | else if (lh->num_file_names >= lh->file_names_size) | |
7030 | { | |
7031 | lh->file_names_size *= 2; | |
7032 | lh->file_names = xrealloc (lh->file_names, | |
7033 | (lh->file_names_size | |
7034 | * sizeof (*lh->file_names))); | |
7035 | } | |
7036 | ||
7037 | fe = &lh->file_names[lh->num_file_names++]; | |
7038 | fe->name = name; | |
7039 | fe->dir_index = dir_index; | |
7040 | fe->mod_time = mod_time; | |
7041 | fe->length = length; | |
aaa75496 | 7042 | fe->included_p = 0; |
cb1df416 | 7043 | fe->symtab = NULL; |
debd256d JB |
7044 | } |
7045 | ||
7046 | ||
7047 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
7048 | .debug_line, according to the endianness of ABFD. Return a pointer |
7049 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
7050 | |
7051 | NOTE: the strings in the include directory and file name tables of | |
7052 | the returned object point into debug_line_buffer, and must not be | |
7053 | freed. */ | |
7054 | static struct line_header * | |
7055 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 7056 | struct dwarf2_cu *cu) |
debd256d JB |
7057 | { |
7058 | struct cleanup *back_to; | |
7059 | struct line_header *lh; | |
fe1b8b76 | 7060 | gdb_byte *line_ptr; |
c764a876 | 7061 | unsigned int bytes_read, offset_size; |
debd256d JB |
7062 | int i; |
7063 | char *cur_dir, *cur_file; | |
7064 | ||
dce234bc | 7065 | if (dwarf2_per_objfile->line.buffer == NULL) |
debd256d | 7066 | { |
e2e0b3e5 | 7067 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
7068 | return 0; |
7069 | } | |
7070 | ||
a738430d MK |
7071 | /* Make sure that at least there's room for the total_length field. |
7072 | That could be 12 bytes long, but we're just going to fudge that. */ | |
dce234bc | 7073 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
debd256d | 7074 | { |
4d3c2250 | 7075 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7076 | return 0; |
7077 | } | |
7078 | ||
7079 | lh = xmalloc (sizeof (*lh)); | |
7080 | memset (lh, 0, sizeof (*lh)); | |
7081 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
7082 | (void *) lh); | |
7083 | ||
dce234bc | 7084 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
debd256d | 7085 | |
a738430d | 7086 | /* Read in the header. */ |
dd373385 | 7087 | lh->total_length = |
c764a876 DE |
7088 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
7089 | &bytes_read, &offset_size); | |
debd256d | 7090 | line_ptr += bytes_read; |
dce234bc PP |
7091 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
7092 | + dwarf2_per_objfile->line.size)) | |
debd256d | 7093 | { |
4d3c2250 | 7094 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
7095 | return 0; |
7096 | } | |
7097 | lh->statement_program_end = line_ptr + lh->total_length; | |
7098 | lh->version = read_2_bytes (abfd, line_ptr); | |
7099 | line_ptr += 2; | |
c764a876 DE |
7100 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
7101 | line_ptr += offset_size; | |
debd256d JB |
7102 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
7103 | line_ptr += 1; | |
7104 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
7105 | line_ptr += 1; | |
7106 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
7107 | line_ptr += 1; | |
7108 | lh->line_range = read_1_byte (abfd, line_ptr); | |
7109 | line_ptr += 1; | |
7110 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
7111 | line_ptr += 1; | |
7112 | lh->standard_opcode_lengths | |
fe1b8b76 | 7113 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
7114 | |
7115 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
7116 | for (i = 1; i < lh->opcode_base; ++i) | |
7117 | { | |
7118 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
7119 | line_ptr += 1; | |
7120 | } | |
7121 | ||
a738430d | 7122 | /* Read directory table. */ |
debd256d JB |
7123 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7124 | { | |
7125 | line_ptr += bytes_read; | |
7126 | add_include_dir (lh, cur_dir); | |
7127 | } | |
7128 | line_ptr += bytes_read; | |
7129 | ||
a738430d | 7130 | /* Read file name table. */ |
debd256d JB |
7131 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
7132 | { | |
7133 | unsigned int dir_index, mod_time, length; | |
7134 | ||
7135 | line_ptr += bytes_read; | |
7136 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7137 | line_ptr += bytes_read; | |
7138 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7139 | line_ptr += bytes_read; | |
7140 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7141 | line_ptr += bytes_read; | |
7142 | ||
7143 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7144 | } | |
7145 | line_ptr += bytes_read; | |
7146 | lh->statement_program_start = line_ptr; | |
7147 | ||
dce234bc PP |
7148 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
7149 | + dwarf2_per_objfile->line.size)) | |
4d3c2250 | 7150 | complaint (&symfile_complaints, |
e2e0b3e5 | 7151 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
7152 | |
7153 | discard_cleanups (back_to); | |
7154 | return lh; | |
7155 | } | |
c906108c | 7156 | |
5fb290d7 DJ |
7157 | /* This function exists to work around a bug in certain compilers |
7158 | (particularly GCC 2.95), in which the first line number marker of a | |
7159 | function does not show up until after the prologue, right before | |
7160 | the second line number marker. This function shifts ADDRESS down | |
7161 | to the beginning of the function if necessary, and is called on | |
7162 | addresses passed to record_line. */ | |
7163 | ||
7164 | static CORE_ADDR | |
e142c38c | 7165 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
7166 | { |
7167 | struct function_range *fn; | |
7168 | ||
7169 | /* Find the function_range containing address. */ | |
e142c38c | 7170 | if (!cu->first_fn) |
5fb290d7 DJ |
7171 | return address; |
7172 | ||
e142c38c DJ |
7173 | if (!cu->cached_fn) |
7174 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 7175 | |
e142c38c | 7176 | fn = cu->cached_fn; |
5fb290d7 DJ |
7177 | while (fn) |
7178 | if (fn->lowpc <= address && fn->highpc > address) | |
7179 | goto found; | |
7180 | else | |
7181 | fn = fn->next; | |
7182 | ||
e142c38c DJ |
7183 | fn = cu->first_fn; |
7184 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
7185 | if (fn->lowpc <= address && fn->highpc > address) |
7186 | goto found; | |
7187 | else | |
7188 | fn = fn->next; | |
7189 | ||
7190 | return address; | |
7191 | ||
7192 | found: | |
7193 | if (fn->seen_line) | |
7194 | return address; | |
7195 | if (address != fn->lowpc) | |
4d3c2250 | 7196 | complaint (&symfile_complaints, |
e2e0b3e5 | 7197 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 7198 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
7199 | fn->seen_line = 1; |
7200 | return fn->lowpc; | |
7201 | } | |
7202 | ||
aaa75496 JB |
7203 | /* Decode the Line Number Program (LNP) for the given line_header |
7204 | structure and CU. The actual information extracted and the type | |
7205 | of structures created from the LNP depends on the value of PST. | |
7206 | ||
7207 | 1. If PST is NULL, then this procedure uses the data from the program | |
7208 | to create all necessary symbol tables, and their linetables. | |
7209 | The compilation directory of the file is passed in COMP_DIR, | |
7210 | and must not be NULL. | |
7211 | ||
7212 | 2. If PST is not NULL, this procedure reads the program to determine | |
7213 | the list of files included by the unit represented by PST, and | |
7214 | builds all the associated partial symbol tables. In this case, | |
7215 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
7216 | is not used to compute the full name of the symtab, and therefore | |
7217 | omitting it when building the partial symtab does not introduce | |
7218 | the potential for inconsistency - a partial symtab and its associated | |
7219 | symbtab having a different fullname -). */ | |
debd256d | 7220 | |
c906108c | 7221 | static void |
debd256d | 7222 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 7223 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 7224 | { |
a8c50c1f | 7225 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 7226 | gdb_byte *line_end; |
a8c50c1f | 7227 | unsigned int bytes_read, extended_len; |
c906108c | 7228 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
7229 | CORE_ADDR baseaddr; |
7230 | struct objfile *objfile = cu->objfile; | |
fbf65064 | 7231 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
aaa75496 | 7232 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 7233 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
7234 | |
7235 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7236 | |
debd256d JB |
7237 | line_ptr = lh->statement_program_start; |
7238 | line_end = lh->statement_program_end; | |
c906108c SS |
7239 | |
7240 | /* Read the statement sequences until there's nothing left. */ | |
7241 | while (line_ptr < line_end) | |
7242 | { | |
7243 | /* state machine registers */ | |
7244 | CORE_ADDR address = 0; | |
7245 | unsigned int file = 1; | |
7246 | unsigned int line = 1; | |
7247 | unsigned int column = 0; | |
debd256d | 7248 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
7249 | int basic_block = 0; |
7250 | int end_sequence = 0; | |
fbf65064 | 7251 | CORE_ADDR addr; |
c906108c | 7252 | |
aaa75496 | 7253 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 7254 | { |
aaa75496 | 7255 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
7256 | /* lh->include_dirs and lh->file_names are 0-based, but the |
7257 | directory and file name numbers in the statement program | |
7258 | are 1-based. */ | |
7259 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 7260 | char *dir = NULL; |
a738430d | 7261 | |
debd256d JB |
7262 | if (fe->dir_index) |
7263 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
7264 | |
7265 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
7266 | } |
7267 | ||
a738430d | 7268 | /* Decode the table. */ |
c5aa993b | 7269 | while (!end_sequence) |
c906108c SS |
7270 | { |
7271 | op_code = read_1_byte (abfd, line_ptr); | |
7272 | line_ptr += 1; | |
59205f5a JB |
7273 | if (line_ptr > line_end) |
7274 | { | |
7275 | dwarf2_debug_line_missing_end_sequence_complaint (); | |
7276 | break; | |
7277 | } | |
9aa1fe7e | 7278 | |
debd256d | 7279 | if (op_code >= lh->opcode_base) |
a738430d MK |
7280 | { |
7281 | /* Special operand. */ | |
debd256d JB |
7282 | adj_opcode = op_code - lh->opcode_base; |
7283 | address += (adj_opcode / lh->line_range) | |
7284 | * lh->minimum_instruction_length; | |
7285 | line += lh->line_base + (adj_opcode % lh->line_range); | |
59205f5a | 7286 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
7287 | dwarf2_debug_line_missing_file_complaint (); |
7288 | else | |
7289 | { | |
7290 | lh->file_names[file - 1].included_p = 1; | |
7291 | if (!decode_for_pst_p) | |
fbf65064 UW |
7292 | { |
7293 | if (last_subfile != current_subfile) | |
7294 | { | |
7295 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
7296 | if (last_subfile) | |
7297 | record_line (last_subfile, 0, addr); | |
7298 | last_subfile = current_subfile; | |
7299 | } | |
25e43795 | 7300 | /* Append row to matrix using current values. */ |
fbf65064 UW |
7301 | addr = check_cu_functions (address, cu); |
7302 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
7303 | record_line (current_subfile, line, addr); | |
366da635 | 7304 | } |
25e43795 | 7305 | } |
9aa1fe7e GK |
7306 | basic_block = 1; |
7307 | } | |
7308 | else switch (op_code) | |
c906108c SS |
7309 | { |
7310 | case DW_LNS_extended_op: | |
a8c50c1f | 7311 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7312 | line_ptr += bytes_read; |
a8c50c1f | 7313 | extended_end = line_ptr + extended_len; |
c906108c SS |
7314 | extended_op = read_1_byte (abfd, line_ptr); |
7315 | line_ptr += 1; | |
7316 | switch (extended_op) | |
7317 | { | |
7318 | case DW_LNE_end_sequence: | |
7319 | end_sequence = 1; | |
c906108c SS |
7320 | break; |
7321 | case DW_LNE_set_address: | |
e7c27a73 | 7322 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7323 | line_ptr += bytes_read; |
7324 | address += baseaddr; | |
c906108c SS |
7325 | break; |
7326 | case DW_LNE_define_file: | |
debd256d JB |
7327 | { |
7328 | char *cur_file; | |
7329 | unsigned int dir_index, mod_time, length; | |
7330 | ||
7331 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
7332 | line_ptr += bytes_read; | |
7333 | dir_index = | |
7334 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7335 | line_ptr += bytes_read; | |
7336 | mod_time = | |
7337 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7338 | line_ptr += bytes_read; | |
7339 | length = | |
7340 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7341 | line_ptr += bytes_read; | |
7342 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7343 | } | |
c906108c | 7344 | break; |
d0c6ba3d CC |
7345 | case DW_LNE_set_discriminator: |
7346 | /* The discriminator is not interesting to the debugger; | |
7347 | just ignore it. */ | |
7348 | line_ptr = extended_end; | |
7349 | break; | |
c906108c | 7350 | default: |
4d3c2250 | 7351 | complaint (&symfile_complaints, |
e2e0b3e5 | 7352 | _("mangled .debug_line section")); |
debd256d | 7353 | return; |
c906108c | 7354 | } |
a8c50c1f DJ |
7355 | /* Make sure that we parsed the extended op correctly. If e.g. |
7356 | we expected a different address size than the producer used, | |
7357 | we may have read the wrong number of bytes. */ | |
7358 | if (line_ptr != extended_end) | |
7359 | { | |
7360 | complaint (&symfile_complaints, | |
7361 | _("mangled .debug_line section")); | |
7362 | return; | |
7363 | } | |
c906108c SS |
7364 | break; |
7365 | case DW_LNS_copy: | |
59205f5a | 7366 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
7367 | dwarf2_debug_line_missing_file_complaint (); |
7368 | else | |
366da635 | 7369 | { |
25e43795 DJ |
7370 | lh->file_names[file - 1].included_p = 1; |
7371 | if (!decode_for_pst_p) | |
fbf65064 UW |
7372 | { |
7373 | if (last_subfile != current_subfile) | |
7374 | { | |
7375 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
7376 | if (last_subfile) | |
7377 | record_line (last_subfile, 0, addr); | |
7378 | last_subfile = current_subfile; | |
7379 | } | |
7380 | addr = check_cu_functions (address, cu); | |
7381 | addr = gdbarch_addr_bits_remove (gdbarch, addr); | |
7382 | record_line (current_subfile, line, addr); | |
7383 | } | |
366da635 | 7384 | } |
c906108c SS |
7385 | basic_block = 0; |
7386 | break; | |
7387 | case DW_LNS_advance_pc: | |
debd256d | 7388 | address += lh->minimum_instruction_length |
c906108c SS |
7389 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7390 | line_ptr += bytes_read; | |
7391 | break; | |
7392 | case DW_LNS_advance_line: | |
7393 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
7394 | line_ptr += bytes_read; | |
7395 | break; | |
7396 | case DW_LNS_set_file: | |
debd256d | 7397 | { |
a738430d MK |
7398 | /* The arrays lh->include_dirs and lh->file_names are |
7399 | 0-based, but the directory and file name numbers in | |
7400 | the statement program are 1-based. */ | |
debd256d | 7401 | struct file_entry *fe; |
4f1520fb | 7402 | char *dir = NULL; |
a738430d | 7403 | |
debd256d JB |
7404 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7405 | line_ptr += bytes_read; | |
59205f5a | 7406 | if (lh->num_file_names < file || file == 0) |
25e43795 DJ |
7407 | dwarf2_debug_line_missing_file_complaint (); |
7408 | else | |
7409 | { | |
7410 | fe = &lh->file_names[file - 1]; | |
7411 | if (fe->dir_index) | |
7412 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7413 | if (!decode_for_pst_p) | |
7414 | { | |
7415 | last_subfile = current_subfile; | |
7416 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7417 | } | |
7418 | } | |
debd256d | 7419 | } |
c906108c SS |
7420 | break; |
7421 | case DW_LNS_set_column: | |
7422 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7423 | line_ptr += bytes_read; | |
7424 | break; | |
7425 | case DW_LNS_negate_stmt: | |
7426 | is_stmt = (!is_stmt); | |
7427 | break; | |
7428 | case DW_LNS_set_basic_block: | |
7429 | basic_block = 1; | |
7430 | break; | |
c2c6d25f JM |
7431 | /* Add to the address register of the state machine the |
7432 | address increment value corresponding to special opcode | |
a738430d MK |
7433 | 255. I.e., this value is scaled by the minimum |
7434 | instruction length since special opcode 255 would have | |
7435 | scaled the the increment. */ | |
c906108c | 7436 | case DW_LNS_const_add_pc: |
debd256d JB |
7437 | address += (lh->minimum_instruction_length |
7438 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
7439 | break; |
7440 | case DW_LNS_fixed_advance_pc: | |
7441 | address += read_2_bytes (abfd, line_ptr); | |
7442 | line_ptr += 2; | |
7443 | break; | |
9aa1fe7e | 7444 | default: |
a738430d MK |
7445 | { |
7446 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 7447 | int i; |
a738430d | 7448 | |
debd256d | 7449 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
7450 | { |
7451 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7452 | line_ptr += bytes_read; | |
7453 | } | |
7454 | } | |
c906108c SS |
7455 | } |
7456 | } | |
59205f5a JB |
7457 | if (lh->num_file_names < file || file == 0) |
7458 | dwarf2_debug_line_missing_file_complaint (); | |
7459 | else | |
7460 | { | |
7461 | lh->file_names[file - 1].included_p = 1; | |
7462 | if (!decode_for_pst_p) | |
fbf65064 UW |
7463 | { |
7464 | addr = gdbarch_addr_bits_remove (gdbarch, address); | |
7465 | record_line (current_subfile, 0, addr); | |
7466 | } | |
59205f5a | 7467 | } |
c906108c | 7468 | } |
aaa75496 JB |
7469 | |
7470 | if (decode_for_pst_p) | |
7471 | { | |
7472 | int file_index; | |
7473 | ||
7474 | /* Now that we're done scanning the Line Header Program, we can | |
7475 | create the psymtab of each included file. */ | |
7476 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
7477 | if (lh->file_names[file_index].included_p == 1) | |
7478 | { | |
5b5464ad JB |
7479 | const struct file_entry fe = lh->file_names [file_index]; |
7480 | char *include_name = fe.name; | |
7481 | char *dir_name = NULL; | |
7482 | char *pst_filename = pst->filename; | |
7483 | ||
7484 | if (fe.dir_index) | |
7485 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
7486 | ||
7487 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
7488 | { | |
1754f103 MK |
7489 | include_name = concat (dir_name, SLASH_STRING, |
7490 | include_name, (char *)NULL); | |
5b5464ad JB |
7491 | make_cleanup (xfree, include_name); |
7492 | } | |
7493 | ||
7494 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
7495 | { | |
1754f103 MK |
7496 | pst_filename = concat (pst->dirname, SLASH_STRING, |
7497 | pst_filename, (char *)NULL); | |
5b5464ad JB |
7498 | make_cleanup (xfree, pst_filename); |
7499 | } | |
7500 | ||
7501 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
7502 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
7503 | } | |
7504 | } | |
cb1df416 DJ |
7505 | else |
7506 | { | |
7507 | /* Make sure a symtab is created for every file, even files | |
7508 | which contain only variables (i.e. no code with associated | |
7509 | line numbers). */ | |
7510 | ||
7511 | int i; | |
7512 | struct file_entry *fe; | |
7513 | ||
7514 | for (i = 0; i < lh->num_file_names; i++) | |
7515 | { | |
7516 | char *dir = NULL; | |
7517 | fe = &lh->file_names[i]; | |
7518 | if (fe->dir_index) | |
7519 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7520 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7521 | ||
7522 | /* Skip the main file; we don't need it, and it must be | |
7523 | allocated last, so that it will show up before the | |
7524 | non-primary symtabs in the objfile's symtab list. */ | |
7525 | if (current_subfile == first_subfile) | |
7526 | continue; | |
7527 | ||
7528 | if (current_subfile->symtab == NULL) | |
7529 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
7530 | cu->objfile); | |
7531 | fe->symtab = current_subfile->symtab; | |
7532 | } | |
7533 | } | |
c906108c SS |
7534 | } |
7535 | ||
7536 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
7537 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
7538 | or NULL if not known. COMP_DIR is the compilation directory for the |
7539 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
7540 | This routine tries to keep line numbers from identical absolute and |
7541 | relative file names in a common subfile. | |
7542 | ||
7543 | Using the `list' example from the GDB testsuite, which resides in | |
7544 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
7545 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
7546 | ||
c5aa993b JM |
7547 | DW_AT_name: /srcdir/list0.c |
7548 | DW_AT_comp_dir: /compdir | |
357e46e7 | 7549 | files.files[0].name: list0.h |
c5aa993b | 7550 | files.files[0].dir: /srcdir |
357e46e7 | 7551 | files.files[1].name: list0.c |
c5aa993b | 7552 | files.files[1].dir: /srcdir |
c906108c SS |
7553 | |
7554 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
7555 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
7556 | start_subfile will ensure that this happens provided that we pass the | |
7557 | concatenation of files.files[1].dir and files.files[1].name as the | |
7558 | subfile's name. */ | |
c906108c SS |
7559 | |
7560 | static void | |
4f1520fb | 7561 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 7562 | { |
4f1520fb FR |
7563 | char *fullname; |
7564 | ||
7565 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
7566 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
7567 | second argument to start_subfile. To be consistent, we do the | |
7568 | same here. In order not to lose the line information directory, | |
7569 | we concatenate it to the filename when it makes sense. | |
7570 | Note that the Dwarf3 standard says (speaking of filenames in line | |
7571 | information): ``The directory index is ignored for file names | |
7572 | that represent full path names''. Thus ignoring dirname in the | |
7573 | `else' branch below isn't an issue. */ | |
c906108c | 7574 | |
d5166ae1 | 7575 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
7576 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
7577 | else | |
7578 | fullname = filename; | |
c906108c | 7579 | |
4f1520fb FR |
7580 | start_subfile (fullname, comp_dir); |
7581 | ||
7582 | if (fullname != filename) | |
7583 | xfree (fullname); | |
c906108c SS |
7584 | } |
7585 | ||
4c2df51b DJ |
7586 | static void |
7587 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 7588 | struct dwarf2_cu *cu) |
4c2df51b | 7589 | { |
e7c27a73 DJ |
7590 | struct objfile *objfile = cu->objfile; |
7591 | struct comp_unit_head *cu_header = &cu->header; | |
7592 | ||
4c2df51b DJ |
7593 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
7594 | code here to turn a symbol with DW_AT_external and a | |
7595 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
7596 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
7597 | with some versions of binutils) where shared libraries could have | |
7598 | relocations against symbols in their debug information - the | |
7599 | minimal symbol would have the right address, but the debug info | |
7600 | would not. It's no longer necessary, because we will explicitly | |
7601 | apply relocations when we read in the debug information now. */ | |
7602 | ||
7603 | /* A DW_AT_location attribute with no contents indicates that a | |
7604 | variable has been optimized away. */ | |
7605 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
7606 | { | |
7607 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
7608 | return; | |
7609 | } | |
7610 | ||
7611 | /* Handle one degenerate form of location expression specially, to | |
7612 | preserve GDB's previous behavior when section offsets are | |
7613 | specified. If this is just a DW_OP_addr then mark this symbol | |
7614 | as LOC_STATIC. */ | |
7615 | ||
7616 | if (attr_form_is_block (attr) | |
7617 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
7618 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
7619 | { | |
891d2f0b | 7620 | unsigned int dummy; |
4c2df51b DJ |
7621 | |
7622 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 7623 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 7624 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
7625 | fixup_symbol_section (sym, objfile); |
7626 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
7627 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
7628 | return; |
7629 | } | |
7630 | ||
7631 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
7632 | expression evaluator, and use LOC_COMPUTED only when necessary | |
7633 | (i.e. when the value of a register or memory location is | |
7634 | referenced, or a thread-local block, etc.). Then again, it might | |
7635 | not be worthwhile. I'm assuming that it isn't unless performance | |
7636 | or memory numbers show me otherwise. */ | |
7637 | ||
e7c27a73 | 7638 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
7639 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
7640 | } | |
7641 | ||
c906108c SS |
7642 | /* Given a pointer to a DWARF information entry, figure out if we need |
7643 | to make a symbol table entry for it, and if so, create a new entry | |
7644 | and return a pointer to it. | |
7645 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 7646 | used the passed type. */ |
c906108c SS |
7647 | |
7648 | static struct symbol * | |
e7c27a73 | 7649 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 7650 | { |
e7c27a73 | 7651 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7652 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7653 | struct symbol *sym = NULL; |
7654 | char *name; | |
7655 | struct attribute *attr = NULL; | |
7656 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
7657 | CORE_ADDR baseaddr; |
7658 | ||
7659 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7660 | |
5c4e30ca | 7661 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7662 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7663 | else |
7664 | name = TYPE_NAME (type); | |
7665 | ||
c906108c SS |
7666 | if (name) |
7667 | { | |
4a146b47 | 7668 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7669 | sizeof (struct symbol)); |
7670 | OBJSTAT (objfile, n_syms++); | |
7671 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7672 | |
7673 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7674 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7675 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7676 | |
7677 | /* Default assumptions. | |
c5aa993b | 7678 | Use the passed type or decode it from the die. */ |
176620f1 | 7679 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7680 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7681 | if (type != NULL) |
7682 | SYMBOL_TYPE (sym) = type; | |
7683 | else | |
e7c27a73 | 7684 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7685 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7686 | if (attr) |
7687 | { | |
7688 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7689 | } | |
cb1df416 DJ |
7690 | |
7691 | attr = dwarf2_attr (die, DW_AT_decl_file, cu); | |
7692 | if (attr) | |
7693 | { | |
7694 | int file_index = DW_UNSND (attr); | |
7695 | if (cu->line_header == NULL | |
7696 | || file_index > cu->line_header->num_file_names) | |
7697 | complaint (&symfile_complaints, | |
7698 | _("file index out of range")); | |
1c3d648d | 7699 | else if (file_index > 0) |
cb1df416 DJ |
7700 | { |
7701 | struct file_entry *fe; | |
7702 | fe = &cu->line_header->file_names[file_index - 1]; | |
7703 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
7704 | } | |
7705 | } | |
7706 | ||
c906108c SS |
7707 | switch (die->tag) |
7708 | { | |
7709 | case DW_TAG_label: | |
e142c38c | 7710 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7711 | if (attr) |
7712 | { | |
7713 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7714 | } | |
7715 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7716 | break; | |
7717 | case DW_TAG_subprogram: | |
7718 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7719 | finish_block. */ | |
7720 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7721 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
7722 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
7723 | || cu->language == language_ada) | |
c906108c | 7724 | { |
2cfa0c8d JB |
7725 | /* Subprograms marked external are stored as a global symbol. |
7726 | Ada subprograms, whether marked external or not, are always | |
7727 | stored as a global symbol, because we want to be able to | |
7728 | access them globally. For instance, we want to be able | |
7729 | to break on a nested subprogram without having to | |
7730 | specify the context. */ | |
c906108c SS |
7731 | add_symbol_to_list (sym, &global_symbols); |
7732 | } | |
7733 | else | |
7734 | { | |
e142c38c | 7735 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7736 | } |
7737 | break; | |
7738 | case DW_TAG_variable: | |
7739 | /* Compilation with minimal debug info may result in variables | |
7740 | with missing type entries. Change the misleading `void' type | |
7741 | to something sensible. */ | |
7742 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 7743 | SYMBOL_TYPE (sym) |
5e2b427d | 7744 | = builtin_type (gdbarch)->nodebug_data_symbol; |
64c50499 | 7745 | |
e142c38c | 7746 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7747 | if (attr) |
7748 | { | |
e7c27a73 | 7749 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7750 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7751 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7752 | add_symbol_to_list (sym, &global_symbols); | |
7753 | else | |
e142c38c | 7754 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7755 | break; |
7756 | } | |
e142c38c | 7757 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7758 | if (attr) |
7759 | { | |
e7c27a73 | 7760 | var_decode_location (attr, sym, cu); |
e142c38c | 7761 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7762 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7763 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7764 | else |
e142c38c | 7765 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7766 | } |
7767 | else | |
7768 | { | |
7769 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7770 | If it is an external symbol and we have type information |
7771 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7772 | The address of the variable will then be determined from | |
7773 | the minimal symbol table whenever the variable is | |
7774 | referenced. */ | |
e142c38c | 7775 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7776 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7777 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7778 | { |
7779 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
de40b933 | 7780 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c | 7781 | } |
442ddf59 JK |
7782 | else if (!die_is_declaration (die, cu)) |
7783 | { | |
7784 | /* Use the default LOC_OPTIMIZED_OUT class. */ | |
7785 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); | |
7786 | add_symbol_to_list (sym, cu->list_in_scope); | |
7787 | } | |
c906108c SS |
7788 | } |
7789 | break; | |
7790 | case DW_TAG_formal_parameter: | |
2a2d4dc3 | 7791 | SYMBOL_IS_ARGUMENT (sym) = 1; |
e142c38c | 7792 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7793 | if (attr) |
7794 | { | |
e7c27a73 | 7795 | var_decode_location (attr, sym, cu); |
c906108c | 7796 | } |
e142c38c | 7797 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7798 | if (attr) |
7799 | { | |
e7c27a73 | 7800 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7801 | } |
e142c38c | 7802 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7803 | break; |
7804 | case DW_TAG_unspecified_parameters: | |
7805 | /* From varargs functions; gdb doesn't seem to have any | |
7806 | interest in this information, so just ignore it for now. | |
7807 | (FIXME?) */ | |
7808 | break; | |
7809 | case DW_TAG_class_type: | |
680b30c7 | 7810 | case DW_TAG_interface_type: |
c906108c SS |
7811 | case DW_TAG_structure_type: |
7812 | case DW_TAG_union_type: | |
72019c9c | 7813 | case DW_TAG_set_type: |
c906108c SS |
7814 | case DW_TAG_enumeration_type: |
7815 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 7816 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 7817 | |
63d06c5c DC |
7818 | /* Make sure that the symbol includes appropriate enclosing |
7819 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 7820 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
7821 | the type. */ |
7822 | ||
987504bb JJ |
7823 | if (cu->language == language_cplus |
7824 | || cu->language == language_java) | |
c906108c | 7825 | { |
63d06c5c DC |
7826 | struct type *type = SYMBOL_TYPE (sym); |
7827 | ||
7828 | if (TYPE_TAG_NAME (type) != NULL) | |
7829 | { | |
7830 | /* FIXME: carlton/2003-11-10: Should this use | |
7831 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
7832 | arises further down in this function.) */ |
7833 | /* The type's name is already allocated along with | |
7834 | this objfile, so we don't need to duplicate it | |
7835 | for the symbol. */ | |
7836 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 7837 | } |
c906108c | 7838 | } |
63d06c5c DC |
7839 | |
7840 | { | |
987504bb | 7841 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
7842 | really ever be static objects: otherwise, if you try |
7843 | to, say, break of a class's method and you're in a file | |
7844 | which doesn't mention that class, it won't work unless | |
7845 | the check for all static symbols in lookup_symbol_aux | |
7846 | saves you. See the OtherFileClass tests in | |
7847 | gdb.c++/namespace.exp. */ | |
7848 | ||
7849 | struct pending **list_to_add; | |
7850 | ||
e142c38c | 7851 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7852 | && (cu->language == language_cplus |
7853 | || cu->language == language_java) | |
e142c38c | 7854 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7855 | |
7856 | add_symbol_to_list (sym, list_to_add); | |
7857 | ||
7858 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 7859 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 7860 | defines a typedef for the class. */ |
987504bb | 7861 | if (cu->language == language_cplus |
8c6860bb JB |
7862 | || cu->language == language_java |
7863 | || cu->language == language_ada) | |
63d06c5c | 7864 | { |
d8151005 DJ |
7865 | /* The symbol's name is already allocated along with |
7866 | this objfile, so we don't need to duplicate it for | |
7867 | the type. */ | |
63d06c5c | 7868 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7869 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7870 | } |
7871 | } | |
c906108c SS |
7872 | break; |
7873 | case DW_TAG_typedef: | |
0114d602 | 7874 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
63d06c5c DC |
7875 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
7876 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7877 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7878 | break; |
c906108c | 7879 | case DW_TAG_base_type: |
a02abb62 | 7880 | case DW_TAG_subrange_type: |
c906108c | 7881 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7882 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7883 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7884 | break; |
7885 | case DW_TAG_enumerator: | |
0114d602 | 7886 | SYMBOL_LINKAGE_NAME (sym) = (char *) dwarf2_full_name (die, cu); |
e142c38c | 7887 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7888 | if (attr) |
7889 | { | |
e7c27a73 | 7890 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7891 | } |
63d06c5c DC |
7892 | { |
7893 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7894 | DW_TAG_class_type, etc. block. */ | |
7895 | ||
7896 | struct pending **list_to_add; | |
7897 | ||
e142c38c | 7898 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7899 | && (cu->language == language_cplus |
7900 | || cu->language == language_java) | |
e142c38c | 7901 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7902 | |
7903 | add_symbol_to_list (sym, list_to_add); | |
7904 | } | |
c906108c | 7905 | break; |
5c4e30ca DC |
7906 | case DW_TAG_namespace: |
7907 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7908 | add_symbol_to_list (sym, &global_symbols); | |
7909 | break; | |
c906108c SS |
7910 | default: |
7911 | /* Not a tag we recognize. Hopefully we aren't processing | |
7912 | trash data, but since we must specifically ignore things | |
7913 | we don't recognize, there is nothing else we should do at | |
7914 | this point. */ | |
e2e0b3e5 | 7915 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7916 | dwarf_tag_name (die->tag)); |
c906108c SS |
7917 | break; |
7918 | } | |
df8a16a1 DJ |
7919 | |
7920 | /* For the benefit of old versions of GCC, check for anonymous | |
7921 | namespaces based on the demangled name. */ | |
7922 | if (!processing_has_namespace_info | |
7923 | && cu->language == language_cplus | |
7924 | && dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu) != NULL) | |
7925 | cp_scan_for_anonymous_namespaces (sym); | |
c906108c SS |
7926 | } |
7927 | return (sym); | |
7928 | } | |
7929 | ||
7930 | /* Copy constant value from an attribute to a symbol. */ | |
7931 | ||
7932 | static void | |
107d2387 | 7933 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7934 | struct dwarf2_cu *cu) |
c906108c | 7935 | { |
e7c27a73 DJ |
7936 | struct objfile *objfile = cu->objfile; |
7937 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7938 | struct dwarf_block *blk; |
7939 | ||
7940 | switch (attr->form) | |
7941 | { | |
7942 | case DW_FORM_addr: | |
107d2387 | 7943 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
3567439c | 7944 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
7945 | cu_header->addr_size, |
7946 | TYPE_LENGTH (SYMBOL_TYPE | |
7947 | (sym))); | |
4e38b386 | 7948 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7949 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7950 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7951 | it's body - store_unsigned_integer. */ | |
7952 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7953 | DW_ADDR (attr)); | |
c906108c SS |
7954 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7955 | break; | |
4ac36638 | 7956 | case DW_FORM_string: |
93b5768b PA |
7957 | case DW_FORM_strp: |
7958 | /* DW_STRING is already allocated on the obstack, point directly | |
7959 | to it. */ | |
7960 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
7961 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7962 | break; | |
c906108c SS |
7963 | case DW_FORM_block1: |
7964 | case DW_FORM_block2: | |
7965 | case DW_FORM_block4: | |
7966 | case DW_FORM_block: | |
7967 | blk = DW_BLOCK (attr); | |
7968 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
3567439c | 7969 | dwarf2_const_value_length_mismatch_complaint (SYMBOL_PRINT_NAME (sym), |
4d3c2250 KB |
7970 | blk->size, |
7971 | TYPE_LENGTH (SYMBOL_TYPE | |
7972 | (sym))); | |
4e38b386 | 7973 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7974 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7975 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7976 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7977 | break; | |
2df3850c JM |
7978 | |
7979 | /* The DW_AT_const_value attributes are supposed to carry the | |
7980 | symbol's value "represented as it would be on the target | |
7981 | architecture." By the time we get here, it's already been | |
7982 | converted to host endianness, so we just need to sign- or | |
7983 | zero-extend it as appropriate. */ | |
7984 | case DW_FORM_data1: | |
7985 | dwarf2_const_value_data (attr, sym, 8); | |
7986 | break; | |
c906108c | 7987 | case DW_FORM_data2: |
2df3850c JM |
7988 | dwarf2_const_value_data (attr, sym, 16); |
7989 | break; | |
c906108c | 7990 | case DW_FORM_data4: |
2df3850c JM |
7991 | dwarf2_const_value_data (attr, sym, 32); |
7992 | break; | |
c906108c | 7993 | case DW_FORM_data8: |
2df3850c JM |
7994 | dwarf2_const_value_data (attr, sym, 64); |
7995 | break; | |
7996 | ||
c906108c | 7997 | case DW_FORM_sdata: |
2df3850c JM |
7998 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7999 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8000 | break; | |
8001 | ||
c906108c SS |
8002 | case DW_FORM_udata: |
8003 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
8004 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8005 | break; | |
2df3850c | 8006 | |
c906108c | 8007 | default: |
4d3c2250 | 8008 | complaint (&symfile_complaints, |
e2e0b3e5 | 8009 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 8010 | dwarf_form_name (attr->form)); |
c906108c SS |
8011 | SYMBOL_VALUE (sym) = 0; |
8012 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8013 | break; | |
8014 | } | |
8015 | } | |
8016 | ||
2df3850c JM |
8017 | |
8018 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
8019 | or zero-extend it as appropriate for the symbol's type. */ | |
8020 | static void | |
8021 | dwarf2_const_value_data (struct attribute *attr, | |
8022 | struct symbol *sym, | |
8023 | int bits) | |
8024 | { | |
8025 | LONGEST l = DW_UNSND (attr); | |
8026 | ||
8027 | if (bits < sizeof (l) * 8) | |
8028 | { | |
8029 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
8030 | l &= ((LONGEST) 1 << bits) - 1; | |
8031 | else | |
bf9198f1 | 8032 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
8033 | } |
8034 | ||
8035 | SYMBOL_VALUE (sym) = l; | |
8036 | SYMBOL_CLASS (sym) = LOC_CONST; | |
8037 | } | |
8038 | ||
8039 | ||
c906108c SS |
8040 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
8041 | ||
8042 | static struct type * | |
e7c27a73 | 8043 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8044 | { |
5e2b427d | 8045 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
c906108c SS |
8046 | struct type *type; |
8047 | struct attribute *type_attr; | |
8048 | struct die_info *type_die; | |
c906108c | 8049 | |
e142c38c | 8050 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
8051 | if (!type_attr) |
8052 | { | |
8053 | /* A missing DW_AT_type represents a void type. */ | |
5e2b427d | 8054 | return builtin_type (gdbarch)->builtin_void; |
c906108c SS |
8055 | } |
8056 | else | |
f2f0e013 | 8057 | type_die = follow_die_ref (die, type_attr, &cu); |
10b3939b | 8058 | |
e7c27a73 | 8059 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8060 | if (!type) |
8061 | { | |
d97bc12b | 8062 | dump_die_for_error (type_die); |
8a3fe4f8 | 8063 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 8064 | cu->objfile->name); |
c906108c SS |
8065 | } |
8066 | return type; | |
8067 | } | |
8068 | ||
8069 | /* Return the containing type of the die in question using its | |
8070 | DW_AT_containing_type attribute. */ | |
8071 | ||
8072 | static struct type * | |
e7c27a73 | 8073 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8074 | { |
8075 | struct type *type = NULL; | |
8076 | struct attribute *type_attr; | |
8077 | struct die_info *type_die = NULL; | |
c906108c | 8078 | |
e142c38c | 8079 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
8080 | if (type_attr) |
8081 | { | |
f2f0e013 | 8082 | type_die = follow_die_ref (die, type_attr, &cu); |
e7c27a73 | 8083 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
8084 | } |
8085 | if (!type) | |
8086 | { | |
8087 | if (type_die) | |
d97bc12b | 8088 | dump_die_for_error (type_die); |
8a3fe4f8 | 8089 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 8090 | cu->objfile->name); |
c906108c SS |
8091 | } |
8092 | return type; | |
8093 | } | |
8094 | ||
c906108c | 8095 | static struct type * |
e7c27a73 | 8096 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8097 | { |
f792889a DJ |
8098 | struct type *this_type; |
8099 | ||
8100 | this_type = read_type_die (die, cu); | |
8101 | if (!this_type) | |
c906108c | 8102 | { |
d97bc12b | 8103 | dump_die_for_error (die); |
f792889a DJ |
8104 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
8105 | cu->objfile->name); | |
c906108c | 8106 | } |
f792889a | 8107 | return this_type; |
c906108c SS |
8108 | } |
8109 | ||
f792889a | 8110 | static struct type * |
e7c27a73 | 8111 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 8112 | { |
f792889a DJ |
8113 | struct type *this_type; |
8114 | ||
8115 | this_type = get_die_type (die, cu); | |
8116 | if (this_type) | |
8117 | return this_type; | |
8118 | ||
c906108c SS |
8119 | switch (die->tag) |
8120 | { | |
8121 | case DW_TAG_class_type: | |
680b30c7 | 8122 | case DW_TAG_interface_type: |
c906108c SS |
8123 | case DW_TAG_structure_type: |
8124 | case DW_TAG_union_type: | |
f792889a | 8125 | this_type = read_structure_type (die, cu); |
c906108c SS |
8126 | break; |
8127 | case DW_TAG_enumeration_type: | |
f792889a | 8128 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
8129 | break; |
8130 | case DW_TAG_subprogram: | |
8131 | case DW_TAG_subroutine_type: | |
f792889a | 8132 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
8133 | break; |
8134 | case DW_TAG_array_type: | |
f792889a | 8135 | this_type = read_array_type (die, cu); |
c906108c | 8136 | break; |
72019c9c | 8137 | case DW_TAG_set_type: |
f792889a | 8138 | this_type = read_set_type (die, cu); |
72019c9c | 8139 | break; |
c906108c | 8140 | case DW_TAG_pointer_type: |
f792889a | 8141 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
8142 | break; |
8143 | case DW_TAG_ptr_to_member_type: | |
f792889a | 8144 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
8145 | break; |
8146 | case DW_TAG_reference_type: | |
f792889a | 8147 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
8148 | break; |
8149 | case DW_TAG_const_type: | |
f792889a | 8150 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
8151 | break; |
8152 | case DW_TAG_volatile_type: | |
f792889a | 8153 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
8154 | break; |
8155 | case DW_TAG_string_type: | |
f792889a | 8156 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
8157 | break; |
8158 | case DW_TAG_typedef: | |
f792889a | 8159 | this_type = read_typedef (die, cu); |
c906108c | 8160 | break; |
a02abb62 | 8161 | case DW_TAG_subrange_type: |
f792889a | 8162 | this_type = read_subrange_type (die, cu); |
a02abb62 | 8163 | break; |
c906108c | 8164 | case DW_TAG_base_type: |
f792889a | 8165 | this_type = read_base_type (die, cu); |
c906108c | 8166 | break; |
81a17f79 | 8167 | case DW_TAG_unspecified_type: |
f792889a | 8168 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 8169 | break; |
0114d602 DJ |
8170 | case DW_TAG_namespace: |
8171 | this_type = read_namespace_type (die, cu); | |
8172 | break; | |
c906108c | 8173 | default: |
a1f5b845 | 8174 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 8175 | dwarf_tag_name (die->tag)); |
c906108c SS |
8176 | break; |
8177 | } | |
63d06c5c | 8178 | |
f792889a | 8179 | return this_type; |
63d06c5c DC |
8180 | } |
8181 | ||
fdde2d81 | 8182 | /* Return the name of the namespace/class that DIE is defined within, |
0114d602 | 8183 | or "" if we can't tell. The caller should not xfree the result. |
fdde2d81 | 8184 | |
0114d602 DJ |
8185 | For example, if we're within the method foo() in the following |
8186 | code: | |
8187 | ||
8188 | namespace N { | |
8189 | class C { | |
8190 | void foo () { | |
8191 | } | |
8192 | }; | |
8193 | } | |
8194 | ||
8195 | then determine_prefix on foo's die will return "N::C". */ | |
fdde2d81 DC |
8196 | |
8197 | static char * | |
e142c38c | 8198 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 8199 | { |
0114d602 DJ |
8200 | struct die_info *parent, *spec_die; |
8201 | struct dwarf2_cu *spec_cu; | |
8202 | struct type *parent_type; | |
63d06c5c | 8203 | |
987504bb JJ |
8204 | if (cu->language != language_cplus |
8205 | && cu->language != language_java) | |
0114d602 DJ |
8206 | return ""; |
8207 | ||
8208 | /* We have to be careful in the presence of DW_AT_specification. | |
8209 | For example, with GCC 3.4, given the code | |
8210 | ||
8211 | namespace N { | |
8212 | void foo() { | |
8213 | // Definition of N::foo. | |
8214 | } | |
8215 | } | |
8216 | ||
8217 | then we'll have a tree of DIEs like this: | |
8218 | ||
8219 | 1: DW_TAG_compile_unit | |
8220 | 2: DW_TAG_namespace // N | |
8221 | 3: DW_TAG_subprogram // declaration of N::foo | |
8222 | 4: DW_TAG_subprogram // definition of N::foo | |
8223 | DW_AT_specification // refers to die #3 | |
8224 | ||
8225 | Thus, when processing die #4, we have to pretend that we're in | |
8226 | the context of its DW_AT_specification, namely the contex of die | |
8227 | #3. */ | |
8228 | spec_cu = cu; | |
8229 | spec_die = die_specification (die, &spec_cu); | |
8230 | if (spec_die == NULL) | |
8231 | parent = die->parent; | |
8232 | else | |
63d06c5c | 8233 | { |
0114d602 DJ |
8234 | parent = spec_die->parent; |
8235 | cu = spec_cu; | |
63d06c5c | 8236 | } |
0114d602 DJ |
8237 | |
8238 | if (parent == NULL) | |
8239 | return ""; | |
63d06c5c | 8240 | else |
0114d602 DJ |
8241 | switch (parent->tag) |
8242 | { | |
63d06c5c | 8243 | case DW_TAG_namespace: |
0114d602 DJ |
8244 | parent_type = read_type_die (parent, cu); |
8245 | /* We give a name to even anonymous namespaces. */ | |
8246 | return TYPE_TAG_NAME (parent_type); | |
63d06c5c | 8247 | case DW_TAG_class_type: |
680b30c7 | 8248 | case DW_TAG_interface_type: |
63d06c5c | 8249 | case DW_TAG_structure_type: |
0114d602 DJ |
8250 | case DW_TAG_union_type: |
8251 | parent_type = read_type_die (parent, cu); | |
8252 | if (TYPE_TAG_NAME (parent_type) != NULL) | |
8253 | return TYPE_TAG_NAME (parent_type); | |
8254 | else | |
8255 | /* An anonymous structure is only allowed non-static data | |
8256 | members; no typedefs, no member functions, et cetera. | |
8257 | So it does not need a prefix. */ | |
8258 | return ""; | |
63d06c5c | 8259 | default: |
8176b9b8 | 8260 | return determine_prefix (parent, cu); |
63d06c5c | 8261 | } |
63d06c5c DC |
8262 | } |
8263 | ||
987504bb JJ |
8264 | /* Return a newly-allocated string formed by concatenating PREFIX and |
8265 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
8266 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
8267 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
8268 | is used to determine the language and hence, the appropriate separator. */ | |
8269 | ||
8270 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
8271 | |
8272 | static char * | |
987504bb JJ |
8273 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
8274 | struct dwarf2_cu *cu) | |
63d06c5c | 8275 | { |
987504bb | 8276 | char *sep; |
63d06c5c | 8277 | |
987504bb JJ |
8278 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
8279 | sep = ""; | |
8280 | else if (cu->language == language_java) | |
8281 | sep = "."; | |
8282 | else | |
8283 | sep = "::"; | |
63d06c5c | 8284 | |
6dd47d34 DE |
8285 | if (prefix == NULL) |
8286 | prefix = ""; | |
8287 | if (suffix == NULL) | |
8288 | suffix = ""; | |
8289 | ||
987504bb JJ |
8290 | if (obs == NULL) |
8291 | { | |
8292 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
6dd47d34 DE |
8293 | strcpy (retval, prefix); |
8294 | strcat (retval, sep); | |
8295 | strcat (retval, suffix); | |
63d06c5c DC |
8296 | return retval; |
8297 | } | |
987504bb JJ |
8298 | else |
8299 | { | |
8300 | /* We have an obstack. */ | |
8301 | return obconcat (obs, prefix, sep, suffix); | |
8302 | } | |
63d06c5c DC |
8303 | } |
8304 | ||
c906108c SS |
8305 | /* Return sibling of die, NULL if no sibling. */ |
8306 | ||
f9aca02d | 8307 | static struct die_info * |
fba45db2 | 8308 | sibling_die (struct die_info *die) |
c906108c | 8309 | { |
639d11d3 | 8310 | return die->sibling; |
c906108c SS |
8311 | } |
8312 | ||
8313 | /* Get linkage name of a die, return NULL if not found. */ | |
8314 | ||
8315 | static char * | |
e142c38c | 8316 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8317 | { |
8318 | struct attribute *attr; | |
8319 | ||
e142c38c | 8320 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
8321 | if (attr && DW_STRING (attr)) |
8322 | return DW_STRING (attr); | |
71c25dea TT |
8323 | return dwarf2_name (die, cu); |
8324 | } | |
8325 | ||
8326 | /* Get name of a die, return NULL if not found. */ | |
8327 | ||
8328 | static char * | |
8329 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, | |
8330 | struct obstack *obstack) | |
8331 | { | |
8332 | if (name && cu->language == language_cplus) | |
8333 | { | |
8334 | char *canon_name = cp_canonicalize_string (name); | |
8335 | ||
8336 | if (canon_name != NULL) | |
8337 | { | |
8338 | if (strcmp (canon_name, name) != 0) | |
8339 | name = obsavestring (canon_name, strlen (canon_name), | |
8340 | obstack); | |
8341 | xfree (canon_name); | |
8342 | } | |
8343 | } | |
8344 | ||
8345 | return name; | |
c906108c SS |
8346 | } |
8347 | ||
9219021c DC |
8348 | /* Get name of a die, return NULL if not found. */ |
8349 | ||
8350 | static char * | |
e142c38c | 8351 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8352 | { |
8353 | struct attribute *attr; | |
8354 | ||
e142c38c | 8355 | attr = dwarf2_attr (die, DW_AT_name, cu); |
71c25dea TT |
8356 | if (!attr || !DW_STRING (attr)) |
8357 | return NULL; | |
8358 | ||
8359 | switch (die->tag) | |
8360 | { | |
8361 | case DW_TAG_compile_unit: | |
8362 | /* Compilation units have a DW_AT_name that is a filename, not | |
8363 | a source language identifier. */ | |
8364 | case DW_TAG_enumeration_type: | |
8365 | case DW_TAG_enumerator: | |
8366 | /* These tags always have simple identifiers already; no need | |
8367 | to canonicalize them. */ | |
8368 | return DW_STRING (attr); | |
8369 | default: | |
8370 | if (attr->form != GDB_FORM_cached_string) | |
8371 | { | |
8372 | DW_STRING (attr) | |
8373 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, | |
8374 | &cu->objfile->objfile_obstack); | |
8375 | attr->form = GDB_FORM_cached_string; | |
8376 | } | |
8377 | return DW_STRING (attr); | |
8378 | } | |
9219021c DC |
8379 | } |
8380 | ||
8381 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
8382 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
8383 | containing the return value on output. */ | |
9219021c DC |
8384 | |
8385 | static struct die_info * | |
f2f0e013 | 8386 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
8387 | { |
8388 | struct attribute *attr; | |
9219021c | 8389 | |
f2f0e013 | 8390 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
8391 | if (attr == NULL) |
8392 | return NULL; | |
8393 | ||
f2f0e013 | 8394 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
8395 | } |
8396 | ||
c906108c SS |
8397 | /* Convert a DIE tag into its string name. */ |
8398 | ||
8399 | static char * | |
aa1ee363 | 8400 | dwarf_tag_name (unsigned tag) |
c906108c SS |
8401 | { |
8402 | switch (tag) | |
8403 | { | |
8404 | case DW_TAG_padding: | |
8405 | return "DW_TAG_padding"; | |
8406 | case DW_TAG_array_type: | |
8407 | return "DW_TAG_array_type"; | |
8408 | case DW_TAG_class_type: | |
8409 | return "DW_TAG_class_type"; | |
8410 | case DW_TAG_entry_point: | |
8411 | return "DW_TAG_entry_point"; | |
8412 | case DW_TAG_enumeration_type: | |
8413 | return "DW_TAG_enumeration_type"; | |
8414 | case DW_TAG_formal_parameter: | |
8415 | return "DW_TAG_formal_parameter"; | |
8416 | case DW_TAG_imported_declaration: | |
8417 | return "DW_TAG_imported_declaration"; | |
8418 | case DW_TAG_label: | |
8419 | return "DW_TAG_label"; | |
8420 | case DW_TAG_lexical_block: | |
8421 | return "DW_TAG_lexical_block"; | |
8422 | case DW_TAG_member: | |
8423 | return "DW_TAG_member"; | |
8424 | case DW_TAG_pointer_type: | |
8425 | return "DW_TAG_pointer_type"; | |
8426 | case DW_TAG_reference_type: | |
8427 | return "DW_TAG_reference_type"; | |
8428 | case DW_TAG_compile_unit: | |
8429 | return "DW_TAG_compile_unit"; | |
8430 | case DW_TAG_string_type: | |
8431 | return "DW_TAG_string_type"; | |
8432 | case DW_TAG_structure_type: | |
8433 | return "DW_TAG_structure_type"; | |
8434 | case DW_TAG_subroutine_type: | |
8435 | return "DW_TAG_subroutine_type"; | |
8436 | case DW_TAG_typedef: | |
8437 | return "DW_TAG_typedef"; | |
8438 | case DW_TAG_union_type: | |
8439 | return "DW_TAG_union_type"; | |
8440 | case DW_TAG_unspecified_parameters: | |
8441 | return "DW_TAG_unspecified_parameters"; | |
8442 | case DW_TAG_variant: | |
8443 | return "DW_TAG_variant"; | |
8444 | case DW_TAG_common_block: | |
8445 | return "DW_TAG_common_block"; | |
8446 | case DW_TAG_common_inclusion: | |
8447 | return "DW_TAG_common_inclusion"; | |
8448 | case DW_TAG_inheritance: | |
8449 | return "DW_TAG_inheritance"; | |
8450 | case DW_TAG_inlined_subroutine: | |
8451 | return "DW_TAG_inlined_subroutine"; | |
8452 | case DW_TAG_module: | |
8453 | return "DW_TAG_module"; | |
8454 | case DW_TAG_ptr_to_member_type: | |
8455 | return "DW_TAG_ptr_to_member_type"; | |
8456 | case DW_TAG_set_type: | |
8457 | return "DW_TAG_set_type"; | |
8458 | case DW_TAG_subrange_type: | |
8459 | return "DW_TAG_subrange_type"; | |
8460 | case DW_TAG_with_stmt: | |
8461 | return "DW_TAG_with_stmt"; | |
8462 | case DW_TAG_access_declaration: | |
8463 | return "DW_TAG_access_declaration"; | |
8464 | case DW_TAG_base_type: | |
8465 | return "DW_TAG_base_type"; | |
8466 | case DW_TAG_catch_block: | |
8467 | return "DW_TAG_catch_block"; | |
8468 | case DW_TAG_const_type: | |
8469 | return "DW_TAG_const_type"; | |
8470 | case DW_TAG_constant: | |
8471 | return "DW_TAG_constant"; | |
8472 | case DW_TAG_enumerator: | |
8473 | return "DW_TAG_enumerator"; | |
8474 | case DW_TAG_file_type: | |
8475 | return "DW_TAG_file_type"; | |
8476 | case DW_TAG_friend: | |
8477 | return "DW_TAG_friend"; | |
8478 | case DW_TAG_namelist: | |
8479 | return "DW_TAG_namelist"; | |
8480 | case DW_TAG_namelist_item: | |
8481 | return "DW_TAG_namelist_item"; | |
8482 | case DW_TAG_packed_type: | |
8483 | return "DW_TAG_packed_type"; | |
8484 | case DW_TAG_subprogram: | |
8485 | return "DW_TAG_subprogram"; | |
8486 | case DW_TAG_template_type_param: | |
8487 | return "DW_TAG_template_type_param"; | |
8488 | case DW_TAG_template_value_param: | |
8489 | return "DW_TAG_template_value_param"; | |
8490 | case DW_TAG_thrown_type: | |
8491 | return "DW_TAG_thrown_type"; | |
8492 | case DW_TAG_try_block: | |
8493 | return "DW_TAG_try_block"; | |
8494 | case DW_TAG_variant_part: | |
8495 | return "DW_TAG_variant_part"; | |
8496 | case DW_TAG_variable: | |
8497 | return "DW_TAG_variable"; | |
8498 | case DW_TAG_volatile_type: | |
8499 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
8500 | case DW_TAG_dwarf_procedure: |
8501 | return "DW_TAG_dwarf_procedure"; | |
8502 | case DW_TAG_restrict_type: | |
8503 | return "DW_TAG_restrict_type"; | |
8504 | case DW_TAG_interface_type: | |
8505 | return "DW_TAG_interface_type"; | |
8506 | case DW_TAG_namespace: | |
8507 | return "DW_TAG_namespace"; | |
8508 | case DW_TAG_imported_module: | |
8509 | return "DW_TAG_imported_module"; | |
8510 | case DW_TAG_unspecified_type: | |
8511 | return "DW_TAG_unspecified_type"; | |
8512 | case DW_TAG_partial_unit: | |
8513 | return "DW_TAG_partial_unit"; | |
8514 | case DW_TAG_imported_unit: | |
8515 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
8516 | case DW_TAG_condition: |
8517 | return "DW_TAG_condition"; | |
8518 | case DW_TAG_shared_type: | |
8519 | return "DW_TAG_shared_type"; | |
c906108c SS |
8520 | case DW_TAG_MIPS_loop: |
8521 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
8522 | case DW_TAG_HP_array_descriptor: |
8523 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
8524 | case DW_TAG_format_label: |
8525 | return "DW_TAG_format_label"; | |
8526 | case DW_TAG_function_template: | |
8527 | return "DW_TAG_function_template"; | |
8528 | case DW_TAG_class_template: | |
8529 | return "DW_TAG_class_template"; | |
b7619582 GF |
8530 | case DW_TAG_GNU_BINCL: |
8531 | return "DW_TAG_GNU_BINCL"; | |
8532 | case DW_TAG_GNU_EINCL: | |
8533 | return "DW_TAG_GNU_EINCL"; | |
8534 | case DW_TAG_upc_shared_type: | |
8535 | return "DW_TAG_upc_shared_type"; | |
8536 | case DW_TAG_upc_strict_type: | |
8537 | return "DW_TAG_upc_strict_type"; | |
8538 | case DW_TAG_upc_relaxed_type: | |
8539 | return "DW_TAG_upc_relaxed_type"; | |
8540 | case DW_TAG_PGI_kanji_type: | |
8541 | return "DW_TAG_PGI_kanji_type"; | |
8542 | case DW_TAG_PGI_interface_block: | |
8543 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
8544 | default: |
8545 | return "DW_TAG_<unknown>"; | |
8546 | } | |
8547 | } | |
8548 | ||
8549 | /* Convert a DWARF attribute code into its string name. */ | |
8550 | ||
8551 | static char * | |
aa1ee363 | 8552 | dwarf_attr_name (unsigned attr) |
c906108c SS |
8553 | { |
8554 | switch (attr) | |
8555 | { | |
8556 | case DW_AT_sibling: | |
8557 | return "DW_AT_sibling"; | |
8558 | case DW_AT_location: | |
8559 | return "DW_AT_location"; | |
8560 | case DW_AT_name: | |
8561 | return "DW_AT_name"; | |
8562 | case DW_AT_ordering: | |
8563 | return "DW_AT_ordering"; | |
8564 | case DW_AT_subscr_data: | |
8565 | return "DW_AT_subscr_data"; | |
8566 | case DW_AT_byte_size: | |
8567 | return "DW_AT_byte_size"; | |
8568 | case DW_AT_bit_offset: | |
8569 | return "DW_AT_bit_offset"; | |
8570 | case DW_AT_bit_size: | |
8571 | return "DW_AT_bit_size"; | |
8572 | case DW_AT_element_list: | |
8573 | return "DW_AT_element_list"; | |
8574 | case DW_AT_stmt_list: | |
8575 | return "DW_AT_stmt_list"; | |
8576 | case DW_AT_low_pc: | |
8577 | return "DW_AT_low_pc"; | |
8578 | case DW_AT_high_pc: | |
8579 | return "DW_AT_high_pc"; | |
8580 | case DW_AT_language: | |
8581 | return "DW_AT_language"; | |
8582 | case DW_AT_member: | |
8583 | return "DW_AT_member"; | |
8584 | case DW_AT_discr: | |
8585 | return "DW_AT_discr"; | |
8586 | case DW_AT_discr_value: | |
8587 | return "DW_AT_discr_value"; | |
8588 | case DW_AT_visibility: | |
8589 | return "DW_AT_visibility"; | |
8590 | case DW_AT_import: | |
8591 | return "DW_AT_import"; | |
8592 | case DW_AT_string_length: | |
8593 | return "DW_AT_string_length"; | |
8594 | case DW_AT_common_reference: | |
8595 | return "DW_AT_common_reference"; | |
8596 | case DW_AT_comp_dir: | |
8597 | return "DW_AT_comp_dir"; | |
8598 | case DW_AT_const_value: | |
8599 | return "DW_AT_const_value"; | |
8600 | case DW_AT_containing_type: | |
8601 | return "DW_AT_containing_type"; | |
8602 | case DW_AT_default_value: | |
8603 | return "DW_AT_default_value"; | |
8604 | case DW_AT_inline: | |
8605 | return "DW_AT_inline"; | |
8606 | case DW_AT_is_optional: | |
8607 | return "DW_AT_is_optional"; | |
8608 | case DW_AT_lower_bound: | |
8609 | return "DW_AT_lower_bound"; | |
8610 | case DW_AT_producer: | |
8611 | return "DW_AT_producer"; | |
8612 | case DW_AT_prototyped: | |
8613 | return "DW_AT_prototyped"; | |
8614 | case DW_AT_return_addr: | |
8615 | return "DW_AT_return_addr"; | |
8616 | case DW_AT_start_scope: | |
8617 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
8618 | case DW_AT_bit_stride: |
8619 | return "DW_AT_bit_stride"; | |
c906108c SS |
8620 | case DW_AT_upper_bound: |
8621 | return "DW_AT_upper_bound"; | |
8622 | case DW_AT_abstract_origin: | |
8623 | return "DW_AT_abstract_origin"; | |
8624 | case DW_AT_accessibility: | |
8625 | return "DW_AT_accessibility"; | |
8626 | case DW_AT_address_class: | |
8627 | return "DW_AT_address_class"; | |
8628 | case DW_AT_artificial: | |
8629 | return "DW_AT_artificial"; | |
8630 | case DW_AT_base_types: | |
8631 | return "DW_AT_base_types"; | |
8632 | case DW_AT_calling_convention: | |
8633 | return "DW_AT_calling_convention"; | |
8634 | case DW_AT_count: | |
8635 | return "DW_AT_count"; | |
8636 | case DW_AT_data_member_location: | |
8637 | return "DW_AT_data_member_location"; | |
8638 | case DW_AT_decl_column: | |
8639 | return "DW_AT_decl_column"; | |
8640 | case DW_AT_decl_file: | |
8641 | return "DW_AT_decl_file"; | |
8642 | case DW_AT_decl_line: | |
8643 | return "DW_AT_decl_line"; | |
8644 | case DW_AT_declaration: | |
8645 | return "DW_AT_declaration"; | |
8646 | case DW_AT_discr_list: | |
8647 | return "DW_AT_discr_list"; | |
8648 | case DW_AT_encoding: | |
8649 | return "DW_AT_encoding"; | |
8650 | case DW_AT_external: | |
8651 | return "DW_AT_external"; | |
8652 | case DW_AT_frame_base: | |
8653 | return "DW_AT_frame_base"; | |
8654 | case DW_AT_friend: | |
8655 | return "DW_AT_friend"; | |
8656 | case DW_AT_identifier_case: | |
8657 | return "DW_AT_identifier_case"; | |
8658 | case DW_AT_macro_info: | |
8659 | return "DW_AT_macro_info"; | |
8660 | case DW_AT_namelist_items: | |
8661 | return "DW_AT_namelist_items"; | |
8662 | case DW_AT_priority: | |
8663 | return "DW_AT_priority"; | |
8664 | case DW_AT_segment: | |
8665 | return "DW_AT_segment"; | |
8666 | case DW_AT_specification: | |
8667 | return "DW_AT_specification"; | |
8668 | case DW_AT_static_link: | |
8669 | return "DW_AT_static_link"; | |
8670 | case DW_AT_type: | |
8671 | return "DW_AT_type"; | |
8672 | case DW_AT_use_location: | |
8673 | return "DW_AT_use_location"; | |
8674 | case DW_AT_variable_parameter: | |
8675 | return "DW_AT_variable_parameter"; | |
8676 | case DW_AT_virtuality: | |
8677 | return "DW_AT_virtuality"; | |
8678 | case DW_AT_vtable_elem_location: | |
8679 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8680 | /* DWARF 3 values. */ |
d9fa45fe DC |
8681 | case DW_AT_allocated: |
8682 | return "DW_AT_allocated"; | |
8683 | case DW_AT_associated: | |
8684 | return "DW_AT_associated"; | |
8685 | case DW_AT_data_location: | |
8686 | return "DW_AT_data_location"; | |
09fa0d7c JK |
8687 | case DW_AT_byte_stride: |
8688 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
8689 | case DW_AT_entry_pc: |
8690 | return "DW_AT_entry_pc"; | |
8691 | case DW_AT_use_UTF8: | |
8692 | return "DW_AT_use_UTF8"; | |
8693 | case DW_AT_extension: | |
8694 | return "DW_AT_extension"; | |
8695 | case DW_AT_ranges: | |
8696 | return "DW_AT_ranges"; | |
8697 | case DW_AT_trampoline: | |
8698 | return "DW_AT_trampoline"; | |
8699 | case DW_AT_call_column: | |
8700 | return "DW_AT_call_column"; | |
8701 | case DW_AT_call_file: | |
8702 | return "DW_AT_call_file"; | |
8703 | case DW_AT_call_line: | |
8704 | return "DW_AT_call_line"; | |
b7619582 GF |
8705 | case DW_AT_description: |
8706 | return "DW_AT_description"; | |
8707 | case DW_AT_binary_scale: | |
8708 | return "DW_AT_binary_scale"; | |
8709 | case DW_AT_decimal_scale: | |
8710 | return "DW_AT_decimal_scale"; | |
8711 | case DW_AT_small: | |
8712 | return "DW_AT_small"; | |
8713 | case DW_AT_decimal_sign: | |
8714 | return "DW_AT_decimal_sign"; | |
8715 | case DW_AT_digit_count: | |
8716 | return "DW_AT_digit_count"; | |
8717 | case DW_AT_picture_string: | |
8718 | return "DW_AT_picture_string"; | |
8719 | case DW_AT_mutable: | |
8720 | return "DW_AT_mutable"; | |
8721 | case DW_AT_threads_scaled: | |
8722 | return "DW_AT_threads_scaled"; | |
8723 | case DW_AT_explicit: | |
8724 | return "DW_AT_explicit"; | |
8725 | case DW_AT_object_pointer: | |
8726 | return "DW_AT_object_pointer"; | |
8727 | case DW_AT_endianity: | |
8728 | return "DW_AT_endianity"; | |
8729 | case DW_AT_elemental: | |
8730 | return "DW_AT_elemental"; | |
8731 | case DW_AT_pure: | |
8732 | return "DW_AT_pure"; | |
8733 | case DW_AT_recursive: | |
8734 | return "DW_AT_recursive"; | |
b7619582 | 8735 | /* SGI/MIPS extensions. */ |
c764a876 | 8736 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
c906108c SS |
8737 | case DW_AT_MIPS_fde: |
8738 | return "DW_AT_MIPS_fde"; | |
c764a876 | 8739 | #endif |
c906108c SS |
8740 | case DW_AT_MIPS_loop_begin: |
8741 | return "DW_AT_MIPS_loop_begin"; | |
8742 | case DW_AT_MIPS_tail_loop_begin: | |
8743 | return "DW_AT_MIPS_tail_loop_begin"; | |
8744 | case DW_AT_MIPS_epilog_begin: | |
8745 | return "DW_AT_MIPS_epilog_begin"; | |
8746 | case DW_AT_MIPS_loop_unroll_factor: | |
8747 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8748 | case DW_AT_MIPS_software_pipeline_depth: | |
8749 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8750 | case DW_AT_MIPS_linkage_name: | |
8751 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8752 | case DW_AT_MIPS_stride: |
8753 | return "DW_AT_MIPS_stride"; | |
8754 | case DW_AT_MIPS_abstract_name: | |
8755 | return "DW_AT_MIPS_abstract_name"; | |
8756 | case DW_AT_MIPS_clone_origin: | |
8757 | return "DW_AT_MIPS_clone_origin"; | |
8758 | case DW_AT_MIPS_has_inlines: | |
8759 | return "DW_AT_MIPS_has_inlines"; | |
b7619582 | 8760 | /* HP extensions. */ |
c764a876 | 8761 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
b7619582 GF |
8762 | case DW_AT_HP_block_index: |
8763 | return "DW_AT_HP_block_index"; | |
c764a876 | 8764 | #endif |
b7619582 GF |
8765 | case DW_AT_HP_unmodifiable: |
8766 | return "DW_AT_HP_unmodifiable"; | |
8767 | case DW_AT_HP_actuals_stmt_list: | |
8768 | return "DW_AT_HP_actuals_stmt_list"; | |
8769 | case DW_AT_HP_proc_per_section: | |
8770 | return "DW_AT_HP_proc_per_section"; | |
8771 | case DW_AT_HP_raw_data_ptr: | |
8772 | return "DW_AT_HP_raw_data_ptr"; | |
8773 | case DW_AT_HP_pass_by_reference: | |
8774 | return "DW_AT_HP_pass_by_reference"; | |
8775 | case DW_AT_HP_opt_level: | |
8776 | return "DW_AT_HP_opt_level"; | |
8777 | case DW_AT_HP_prof_version_id: | |
8778 | return "DW_AT_HP_prof_version_id"; | |
8779 | case DW_AT_HP_opt_flags: | |
8780 | return "DW_AT_HP_opt_flags"; | |
8781 | case DW_AT_HP_cold_region_low_pc: | |
8782 | return "DW_AT_HP_cold_region_low_pc"; | |
8783 | case DW_AT_HP_cold_region_high_pc: | |
8784 | return "DW_AT_HP_cold_region_high_pc"; | |
8785 | case DW_AT_HP_all_variables_modifiable: | |
8786 | return "DW_AT_HP_all_variables_modifiable"; | |
8787 | case DW_AT_HP_linkage_name: | |
8788 | return "DW_AT_HP_linkage_name"; | |
8789 | case DW_AT_HP_prof_flags: | |
8790 | return "DW_AT_HP_prof_flags"; | |
8791 | /* GNU extensions. */ | |
c906108c SS |
8792 | case DW_AT_sf_names: |
8793 | return "DW_AT_sf_names"; | |
8794 | case DW_AT_src_info: | |
8795 | return "DW_AT_src_info"; | |
8796 | case DW_AT_mac_info: | |
8797 | return "DW_AT_mac_info"; | |
8798 | case DW_AT_src_coords: | |
8799 | return "DW_AT_src_coords"; | |
8800 | case DW_AT_body_begin: | |
8801 | return "DW_AT_body_begin"; | |
8802 | case DW_AT_body_end: | |
8803 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8804 | case DW_AT_GNU_vector: |
8805 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8806 | /* VMS extensions. */ |
8807 | case DW_AT_VMS_rtnbeg_pd_address: | |
8808 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8809 | /* UPC extension. */ | |
8810 | case DW_AT_upc_threads_scaled: | |
8811 | return "DW_AT_upc_threads_scaled"; | |
8812 | /* PGI (STMicroelectronics) extensions. */ | |
8813 | case DW_AT_PGI_lbase: | |
8814 | return "DW_AT_PGI_lbase"; | |
8815 | case DW_AT_PGI_soffset: | |
8816 | return "DW_AT_PGI_soffset"; | |
8817 | case DW_AT_PGI_lstride: | |
8818 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8819 | default: |
8820 | return "DW_AT_<unknown>"; | |
8821 | } | |
8822 | } | |
8823 | ||
8824 | /* Convert a DWARF value form code into its string name. */ | |
8825 | ||
8826 | static char * | |
aa1ee363 | 8827 | dwarf_form_name (unsigned form) |
c906108c SS |
8828 | { |
8829 | switch (form) | |
8830 | { | |
8831 | case DW_FORM_addr: | |
8832 | return "DW_FORM_addr"; | |
8833 | case DW_FORM_block2: | |
8834 | return "DW_FORM_block2"; | |
8835 | case DW_FORM_block4: | |
8836 | return "DW_FORM_block4"; | |
8837 | case DW_FORM_data2: | |
8838 | return "DW_FORM_data2"; | |
8839 | case DW_FORM_data4: | |
8840 | return "DW_FORM_data4"; | |
8841 | case DW_FORM_data8: | |
8842 | return "DW_FORM_data8"; | |
8843 | case DW_FORM_string: | |
8844 | return "DW_FORM_string"; | |
8845 | case DW_FORM_block: | |
8846 | return "DW_FORM_block"; | |
8847 | case DW_FORM_block1: | |
8848 | return "DW_FORM_block1"; | |
8849 | case DW_FORM_data1: | |
8850 | return "DW_FORM_data1"; | |
8851 | case DW_FORM_flag: | |
8852 | return "DW_FORM_flag"; | |
8853 | case DW_FORM_sdata: | |
8854 | return "DW_FORM_sdata"; | |
8855 | case DW_FORM_strp: | |
8856 | return "DW_FORM_strp"; | |
8857 | case DW_FORM_udata: | |
8858 | return "DW_FORM_udata"; | |
8859 | case DW_FORM_ref_addr: | |
8860 | return "DW_FORM_ref_addr"; | |
8861 | case DW_FORM_ref1: | |
8862 | return "DW_FORM_ref1"; | |
8863 | case DW_FORM_ref2: | |
8864 | return "DW_FORM_ref2"; | |
8865 | case DW_FORM_ref4: | |
8866 | return "DW_FORM_ref4"; | |
8867 | case DW_FORM_ref8: | |
8868 | return "DW_FORM_ref8"; | |
8869 | case DW_FORM_ref_udata: | |
8870 | return "DW_FORM_ref_udata"; | |
8871 | case DW_FORM_indirect: | |
8872 | return "DW_FORM_indirect"; | |
71c25dea TT |
8873 | case GDB_FORM_cached_string: |
8874 | return "GDB_FORM_cached_string"; | |
c906108c SS |
8875 | default: |
8876 | return "DW_FORM_<unknown>"; | |
8877 | } | |
8878 | } | |
8879 | ||
8880 | /* Convert a DWARF stack opcode into its string name. */ | |
8881 | ||
8882 | static char * | |
aa1ee363 | 8883 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8884 | { |
8885 | switch (op) | |
8886 | { | |
8887 | case DW_OP_addr: | |
8888 | return "DW_OP_addr"; | |
8889 | case DW_OP_deref: | |
8890 | return "DW_OP_deref"; | |
8891 | case DW_OP_const1u: | |
8892 | return "DW_OP_const1u"; | |
8893 | case DW_OP_const1s: | |
8894 | return "DW_OP_const1s"; | |
8895 | case DW_OP_const2u: | |
8896 | return "DW_OP_const2u"; | |
8897 | case DW_OP_const2s: | |
8898 | return "DW_OP_const2s"; | |
8899 | case DW_OP_const4u: | |
8900 | return "DW_OP_const4u"; | |
8901 | case DW_OP_const4s: | |
8902 | return "DW_OP_const4s"; | |
8903 | case DW_OP_const8u: | |
8904 | return "DW_OP_const8u"; | |
8905 | case DW_OP_const8s: | |
8906 | return "DW_OP_const8s"; | |
8907 | case DW_OP_constu: | |
8908 | return "DW_OP_constu"; | |
8909 | case DW_OP_consts: | |
8910 | return "DW_OP_consts"; | |
8911 | case DW_OP_dup: | |
8912 | return "DW_OP_dup"; | |
8913 | case DW_OP_drop: | |
8914 | return "DW_OP_drop"; | |
8915 | case DW_OP_over: | |
8916 | return "DW_OP_over"; | |
8917 | case DW_OP_pick: | |
8918 | return "DW_OP_pick"; | |
8919 | case DW_OP_swap: | |
8920 | return "DW_OP_swap"; | |
8921 | case DW_OP_rot: | |
8922 | return "DW_OP_rot"; | |
8923 | case DW_OP_xderef: | |
8924 | return "DW_OP_xderef"; | |
8925 | case DW_OP_abs: | |
8926 | return "DW_OP_abs"; | |
8927 | case DW_OP_and: | |
8928 | return "DW_OP_and"; | |
8929 | case DW_OP_div: | |
8930 | return "DW_OP_div"; | |
8931 | case DW_OP_minus: | |
8932 | return "DW_OP_minus"; | |
8933 | case DW_OP_mod: | |
8934 | return "DW_OP_mod"; | |
8935 | case DW_OP_mul: | |
8936 | return "DW_OP_mul"; | |
8937 | case DW_OP_neg: | |
8938 | return "DW_OP_neg"; | |
8939 | case DW_OP_not: | |
8940 | return "DW_OP_not"; | |
8941 | case DW_OP_or: | |
8942 | return "DW_OP_or"; | |
8943 | case DW_OP_plus: | |
8944 | return "DW_OP_plus"; | |
8945 | case DW_OP_plus_uconst: | |
8946 | return "DW_OP_plus_uconst"; | |
8947 | case DW_OP_shl: | |
8948 | return "DW_OP_shl"; | |
8949 | case DW_OP_shr: | |
8950 | return "DW_OP_shr"; | |
8951 | case DW_OP_shra: | |
8952 | return "DW_OP_shra"; | |
8953 | case DW_OP_xor: | |
8954 | return "DW_OP_xor"; | |
8955 | case DW_OP_bra: | |
8956 | return "DW_OP_bra"; | |
8957 | case DW_OP_eq: | |
8958 | return "DW_OP_eq"; | |
8959 | case DW_OP_ge: | |
8960 | return "DW_OP_ge"; | |
8961 | case DW_OP_gt: | |
8962 | return "DW_OP_gt"; | |
8963 | case DW_OP_le: | |
8964 | return "DW_OP_le"; | |
8965 | case DW_OP_lt: | |
8966 | return "DW_OP_lt"; | |
8967 | case DW_OP_ne: | |
8968 | return "DW_OP_ne"; | |
8969 | case DW_OP_skip: | |
8970 | return "DW_OP_skip"; | |
8971 | case DW_OP_lit0: | |
8972 | return "DW_OP_lit0"; | |
8973 | case DW_OP_lit1: | |
8974 | return "DW_OP_lit1"; | |
8975 | case DW_OP_lit2: | |
8976 | return "DW_OP_lit2"; | |
8977 | case DW_OP_lit3: | |
8978 | return "DW_OP_lit3"; | |
8979 | case DW_OP_lit4: | |
8980 | return "DW_OP_lit4"; | |
8981 | case DW_OP_lit5: | |
8982 | return "DW_OP_lit5"; | |
8983 | case DW_OP_lit6: | |
8984 | return "DW_OP_lit6"; | |
8985 | case DW_OP_lit7: | |
8986 | return "DW_OP_lit7"; | |
8987 | case DW_OP_lit8: | |
8988 | return "DW_OP_lit8"; | |
8989 | case DW_OP_lit9: | |
8990 | return "DW_OP_lit9"; | |
8991 | case DW_OP_lit10: | |
8992 | return "DW_OP_lit10"; | |
8993 | case DW_OP_lit11: | |
8994 | return "DW_OP_lit11"; | |
8995 | case DW_OP_lit12: | |
8996 | return "DW_OP_lit12"; | |
8997 | case DW_OP_lit13: | |
8998 | return "DW_OP_lit13"; | |
8999 | case DW_OP_lit14: | |
9000 | return "DW_OP_lit14"; | |
9001 | case DW_OP_lit15: | |
9002 | return "DW_OP_lit15"; | |
9003 | case DW_OP_lit16: | |
9004 | return "DW_OP_lit16"; | |
9005 | case DW_OP_lit17: | |
9006 | return "DW_OP_lit17"; | |
9007 | case DW_OP_lit18: | |
9008 | return "DW_OP_lit18"; | |
9009 | case DW_OP_lit19: | |
9010 | return "DW_OP_lit19"; | |
9011 | case DW_OP_lit20: | |
9012 | return "DW_OP_lit20"; | |
9013 | case DW_OP_lit21: | |
9014 | return "DW_OP_lit21"; | |
9015 | case DW_OP_lit22: | |
9016 | return "DW_OP_lit22"; | |
9017 | case DW_OP_lit23: | |
9018 | return "DW_OP_lit23"; | |
9019 | case DW_OP_lit24: | |
9020 | return "DW_OP_lit24"; | |
9021 | case DW_OP_lit25: | |
9022 | return "DW_OP_lit25"; | |
9023 | case DW_OP_lit26: | |
9024 | return "DW_OP_lit26"; | |
9025 | case DW_OP_lit27: | |
9026 | return "DW_OP_lit27"; | |
9027 | case DW_OP_lit28: | |
9028 | return "DW_OP_lit28"; | |
9029 | case DW_OP_lit29: | |
9030 | return "DW_OP_lit29"; | |
9031 | case DW_OP_lit30: | |
9032 | return "DW_OP_lit30"; | |
9033 | case DW_OP_lit31: | |
9034 | return "DW_OP_lit31"; | |
9035 | case DW_OP_reg0: | |
9036 | return "DW_OP_reg0"; | |
9037 | case DW_OP_reg1: | |
9038 | return "DW_OP_reg1"; | |
9039 | case DW_OP_reg2: | |
9040 | return "DW_OP_reg2"; | |
9041 | case DW_OP_reg3: | |
9042 | return "DW_OP_reg3"; | |
9043 | case DW_OP_reg4: | |
9044 | return "DW_OP_reg4"; | |
9045 | case DW_OP_reg5: | |
9046 | return "DW_OP_reg5"; | |
9047 | case DW_OP_reg6: | |
9048 | return "DW_OP_reg6"; | |
9049 | case DW_OP_reg7: | |
9050 | return "DW_OP_reg7"; | |
9051 | case DW_OP_reg8: | |
9052 | return "DW_OP_reg8"; | |
9053 | case DW_OP_reg9: | |
9054 | return "DW_OP_reg9"; | |
9055 | case DW_OP_reg10: | |
9056 | return "DW_OP_reg10"; | |
9057 | case DW_OP_reg11: | |
9058 | return "DW_OP_reg11"; | |
9059 | case DW_OP_reg12: | |
9060 | return "DW_OP_reg12"; | |
9061 | case DW_OP_reg13: | |
9062 | return "DW_OP_reg13"; | |
9063 | case DW_OP_reg14: | |
9064 | return "DW_OP_reg14"; | |
9065 | case DW_OP_reg15: | |
9066 | return "DW_OP_reg15"; | |
9067 | case DW_OP_reg16: | |
9068 | return "DW_OP_reg16"; | |
9069 | case DW_OP_reg17: | |
9070 | return "DW_OP_reg17"; | |
9071 | case DW_OP_reg18: | |
9072 | return "DW_OP_reg18"; | |
9073 | case DW_OP_reg19: | |
9074 | return "DW_OP_reg19"; | |
9075 | case DW_OP_reg20: | |
9076 | return "DW_OP_reg20"; | |
9077 | case DW_OP_reg21: | |
9078 | return "DW_OP_reg21"; | |
9079 | case DW_OP_reg22: | |
9080 | return "DW_OP_reg22"; | |
9081 | case DW_OP_reg23: | |
9082 | return "DW_OP_reg23"; | |
9083 | case DW_OP_reg24: | |
9084 | return "DW_OP_reg24"; | |
9085 | case DW_OP_reg25: | |
9086 | return "DW_OP_reg25"; | |
9087 | case DW_OP_reg26: | |
9088 | return "DW_OP_reg26"; | |
9089 | case DW_OP_reg27: | |
9090 | return "DW_OP_reg27"; | |
9091 | case DW_OP_reg28: | |
9092 | return "DW_OP_reg28"; | |
9093 | case DW_OP_reg29: | |
9094 | return "DW_OP_reg29"; | |
9095 | case DW_OP_reg30: | |
9096 | return "DW_OP_reg30"; | |
9097 | case DW_OP_reg31: | |
9098 | return "DW_OP_reg31"; | |
9099 | case DW_OP_breg0: | |
9100 | return "DW_OP_breg0"; | |
9101 | case DW_OP_breg1: | |
9102 | return "DW_OP_breg1"; | |
9103 | case DW_OP_breg2: | |
9104 | return "DW_OP_breg2"; | |
9105 | case DW_OP_breg3: | |
9106 | return "DW_OP_breg3"; | |
9107 | case DW_OP_breg4: | |
9108 | return "DW_OP_breg4"; | |
9109 | case DW_OP_breg5: | |
9110 | return "DW_OP_breg5"; | |
9111 | case DW_OP_breg6: | |
9112 | return "DW_OP_breg6"; | |
9113 | case DW_OP_breg7: | |
9114 | return "DW_OP_breg7"; | |
9115 | case DW_OP_breg8: | |
9116 | return "DW_OP_breg8"; | |
9117 | case DW_OP_breg9: | |
9118 | return "DW_OP_breg9"; | |
9119 | case DW_OP_breg10: | |
9120 | return "DW_OP_breg10"; | |
9121 | case DW_OP_breg11: | |
9122 | return "DW_OP_breg11"; | |
9123 | case DW_OP_breg12: | |
9124 | return "DW_OP_breg12"; | |
9125 | case DW_OP_breg13: | |
9126 | return "DW_OP_breg13"; | |
9127 | case DW_OP_breg14: | |
9128 | return "DW_OP_breg14"; | |
9129 | case DW_OP_breg15: | |
9130 | return "DW_OP_breg15"; | |
9131 | case DW_OP_breg16: | |
9132 | return "DW_OP_breg16"; | |
9133 | case DW_OP_breg17: | |
9134 | return "DW_OP_breg17"; | |
9135 | case DW_OP_breg18: | |
9136 | return "DW_OP_breg18"; | |
9137 | case DW_OP_breg19: | |
9138 | return "DW_OP_breg19"; | |
9139 | case DW_OP_breg20: | |
9140 | return "DW_OP_breg20"; | |
9141 | case DW_OP_breg21: | |
9142 | return "DW_OP_breg21"; | |
9143 | case DW_OP_breg22: | |
9144 | return "DW_OP_breg22"; | |
9145 | case DW_OP_breg23: | |
9146 | return "DW_OP_breg23"; | |
9147 | case DW_OP_breg24: | |
9148 | return "DW_OP_breg24"; | |
9149 | case DW_OP_breg25: | |
9150 | return "DW_OP_breg25"; | |
9151 | case DW_OP_breg26: | |
9152 | return "DW_OP_breg26"; | |
9153 | case DW_OP_breg27: | |
9154 | return "DW_OP_breg27"; | |
9155 | case DW_OP_breg28: | |
9156 | return "DW_OP_breg28"; | |
9157 | case DW_OP_breg29: | |
9158 | return "DW_OP_breg29"; | |
9159 | case DW_OP_breg30: | |
9160 | return "DW_OP_breg30"; | |
9161 | case DW_OP_breg31: | |
9162 | return "DW_OP_breg31"; | |
9163 | case DW_OP_regx: | |
9164 | return "DW_OP_regx"; | |
9165 | case DW_OP_fbreg: | |
9166 | return "DW_OP_fbreg"; | |
9167 | case DW_OP_bregx: | |
9168 | return "DW_OP_bregx"; | |
9169 | case DW_OP_piece: | |
9170 | return "DW_OP_piece"; | |
9171 | case DW_OP_deref_size: | |
9172 | return "DW_OP_deref_size"; | |
9173 | case DW_OP_xderef_size: | |
9174 | return "DW_OP_xderef_size"; | |
9175 | case DW_OP_nop: | |
9176 | return "DW_OP_nop"; | |
b7619582 | 9177 | /* DWARF 3 extensions. */ |
ed348acc EZ |
9178 | case DW_OP_push_object_address: |
9179 | return "DW_OP_push_object_address"; | |
9180 | case DW_OP_call2: | |
9181 | return "DW_OP_call2"; | |
9182 | case DW_OP_call4: | |
9183 | return "DW_OP_call4"; | |
9184 | case DW_OP_call_ref: | |
9185 | return "DW_OP_call_ref"; | |
b7619582 GF |
9186 | /* GNU extensions. */ |
9187 | case DW_OP_form_tls_address: | |
9188 | return "DW_OP_form_tls_address"; | |
9189 | case DW_OP_call_frame_cfa: | |
9190 | return "DW_OP_call_frame_cfa"; | |
9191 | case DW_OP_bit_piece: | |
9192 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
9193 | case DW_OP_GNU_push_tls_address: |
9194 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
9195 | case DW_OP_GNU_uninit: |
9196 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
9197 | /* HP extensions. */ |
9198 | case DW_OP_HP_is_value: | |
9199 | return "DW_OP_HP_is_value"; | |
9200 | case DW_OP_HP_fltconst4: | |
9201 | return "DW_OP_HP_fltconst4"; | |
9202 | case DW_OP_HP_fltconst8: | |
9203 | return "DW_OP_HP_fltconst8"; | |
9204 | case DW_OP_HP_mod_range: | |
9205 | return "DW_OP_HP_mod_range"; | |
9206 | case DW_OP_HP_unmod_range: | |
9207 | return "DW_OP_HP_unmod_range"; | |
9208 | case DW_OP_HP_tls: | |
9209 | return "DW_OP_HP_tls"; | |
c906108c SS |
9210 | default: |
9211 | return "OP_<unknown>"; | |
9212 | } | |
9213 | } | |
9214 | ||
9215 | static char * | |
fba45db2 | 9216 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
9217 | { |
9218 | if (mybool) | |
9219 | return "TRUE"; | |
9220 | else | |
9221 | return "FALSE"; | |
9222 | } | |
9223 | ||
9224 | /* Convert a DWARF type code into its string name. */ | |
9225 | ||
9226 | static char * | |
aa1ee363 | 9227 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
9228 | { |
9229 | switch (enc) | |
9230 | { | |
b7619582 GF |
9231 | case DW_ATE_void: |
9232 | return "DW_ATE_void"; | |
c906108c SS |
9233 | case DW_ATE_address: |
9234 | return "DW_ATE_address"; | |
9235 | case DW_ATE_boolean: | |
9236 | return "DW_ATE_boolean"; | |
9237 | case DW_ATE_complex_float: | |
9238 | return "DW_ATE_complex_float"; | |
9239 | case DW_ATE_float: | |
9240 | return "DW_ATE_float"; | |
9241 | case DW_ATE_signed: | |
9242 | return "DW_ATE_signed"; | |
9243 | case DW_ATE_signed_char: | |
9244 | return "DW_ATE_signed_char"; | |
9245 | case DW_ATE_unsigned: | |
9246 | return "DW_ATE_unsigned"; | |
9247 | case DW_ATE_unsigned_char: | |
9248 | return "DW_ATE_unsigned_char"; | |
b7619582 | 9249 | /* DWARF 3. */ |
d9fa45fe DC |
9250 | case DW_ATE_imaginary_float: |
9251 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
9252 | case DW_ATE_packed_decimal: |
9253 | return "DW_ATE_packed_decimal"; | |
9254 | case DW_ATE_numeric_string: | |
9255 | return "DW_ATE_numeric_string"; | |
9256 | case DW_ATE_edited: | |
9257 | return "DW_ATE_edited"; | |
9258 | case DW_ATE_signed_fixed: | |
9259 | return "DW_ATE_signed_fixed"; | |
9260 | case DW_ATE_unsigned_fixed: | |
9261 | return "DW_ATE_unsigned_fixed"; | |
9262 | case DW_ATE_decimal_float: | |
9263 | return "DW_ATE_decimal_float"; | |
9264 | /* HP extensions. */ | |
9265 | case DW_ATE_HP_float80: | |
9266 | return "DW_ATE_HP_float80"; | |
9267 | case DW_ATE_HP_complex_float80: | |
9268 | return "DW_ATE_HP_complex_float80"; | |
9269 | case DW_ATE_HP_float128: | |
9270 | return "DW_ATE_HP_float128"; | |
9271 | case DW_ATE_HP_complex_float128: | |
9272 | return "DW_ATE_HP_complex_float128"; | |
9273 | case DW_ATE_HP_floathpintel: | |
9274 | return "DW_ATE_HP_floathpintel"; | |
9275 | case DW_ATE_HP_imaginary_float80: | |
9276 | return "DW_ATE_HP_imaginary_float80"; | |
9277 | case DW_ATE_HP_imaginary_float128: | |
9278 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
9279 | default: |
9280 | return "DW_ATE_<unknown>"; | |
9281 | } | |
9282 | } | |
9283 | ||
9284 | /* Convert a DWARF call frame info operation to its string name. */ | |
9285 | ||
9286 | #if 0 | |
9287 | static char * | |
aa1ee363 | 9288 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
9289 | { |
9290 | switch (cfi_opc) | |
9291 | { | |
9292 | case DW_CFA_advance_loc: | |
9293 | return "DW_CFA_advance_loc"; | |
9294 | case DW_CFA_offset: | |
9295 | return "DW_CFA_offset"; | |
9296 | case DW_CFA_restore: | |
9297 | return "DW_CFA_restore"; | |
9298 | case DW_CFA_nop: | |
9299 | return "DW_CFA_nop"; | |
9300 | case DW_CFA_set_loc: | |
9301 | return "DW_CFA_set_loc"; | |
9302 | case DW_CFA_advance_loc1: | |
9303 | return "DW_CFA_advance_loc1"; | |
9304 | case DW_CFA_advance_loc2: | |
9305 | return "DW_CFA_advance_loc2"; | |
9306 | case DW_CFA_advance_loc4: | |
9307 | return "DW_CFA_advance_loc4"; | |
9308 | case DW_CFA_offset_extended: | |
9309 | return "DW_CFA_offset_extended"; | |
9310 | case DW_CFA_restore_extended: | |
9311 | return "DW_CFA_restore_extended"; | |
9312 | case DW_CFA_undefined: | |
9313 | return "DW_CFA_undefined"; | |
9314 | case DW_CFA_same_value: | |
9315 | return "DW_CFA_same_value"; | |
9316 | case DW_CFA_register: | |
9317 | return "DW_CFA_register"; | |
9318 | case DW_CFA_remember_state: | |
9319 | return "DW_CFA_remember_state"; | |
9320 | case DW_CFA_restore_state: | |
9321 | return "DW_CFA_restore_state"; | |
9322 | case DW_CFA_def_cfa: | |
9323 | return "DW_CFA_def_cfa"; | |
9324 | case DW_CFA_def_cfa_register: | |
9325 | return "DW_CFA_def_cfa_register"; | |
9326 | case DW_CFA_def_cfa_offset: | |
9327 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 9328 | /* DWARF 3. */ |
985cb1a3 JM |
9329 | case DW_CFA_def_cfa_expression: |
9330 | return "DW_CFA_def_cfa_expression"; | |
9331 | case DW_CFA_expression: | |
9332 | return "DW_CFA_expression"; | |
9333 | case DW_CFA_offset_extended_sf: | |
9334 | return "DW_CFA_offset_extended_sf"; | |
9335 | case DW_CFA_def_cfa_sf: | |
9336 | return "DW_CFA_def_cfa_sf"; | |
9337 | case DW_CFA_def_cfa_offset_sf: | |
9338 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
9339 | case DW_CFA_val_offset: |
9340 | return "DW_CFA_val_offset"; | |
9341 | case DW_CFA_val_offset_sf: | |
9342 | return "DW_CFA_val_offset_sf"; | |
9343 | case DW_CFA_val_expression: | |
9344 | return "DW_CFA_val_expression"; | |
9345 | /* SGI/MIPS specific. */ | |
c906108c SS |
9346 | case DW_CFA_MIPS_advance_loc8: |
9347 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 9348 | /* GNU extensions. */ |
985cb1a3 JM |
9349 | case DW_CFA_GNU_window_save: |
9350 | return "DW_CFA_GNU_window_save"; | |
9351 | case DW_CFA_GNU_args_size: | |
9352 | return "DW_CFA_GNU_args_size"; | |
9353 | case DW_CFA_GNU_negative_offset_extended: | |
9354 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
9355 | default: |
9356 | return "DW_CFA_<unknown>"; | |
9357 | } | |
9358 | } | |
9359 | #endif | |
9360 | ||
f9aca02d | 9361 | static void |
d97bc12b | 9362 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
c906108c SS |
9363 | { |
9364 | unsigned int i; | |
9365 | ||
d97bc12b DE |
9366 | print_spaces (indent, f); |
9367 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", | |
c906108c | 9368 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
d97bc12b DE |
9369 | |
9370 | if (die->parent != NULL) | |
9371 | { | |
9372 | print_spaces (indent, f); | |
9373 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", | |
9374 | die->parent->offset); | |
9375 | } | |
9376 | ||
9377 | print_spaces (indent, f); | |
9378 | fprintf_unfiltered (f, " has children: %s\n", | |
639d11d3 | 9379 | dwarf_bool_name (die->child != NULL)); |
c906108c | 9380 | |
d97bc12b DE |
9381 | print_spaces (indent, f); |
9382 | fprintf_unfiltered (f, " attributes:\n"); | |
9383 | ||
c906108c SS |
9384 | for (i = 0; i < die->num_attrs; ++i) |
9385 | { | |
d97bc12b DE |
9386 | print_spaces (indent, f); |
9387 | fprintf_unfiltered (f, " %s (%s) ", | |
c906108c SS |
9388 | dwarf_attr_name (die->attrs[i].name), |
9389 | dwarf_form_name (die->attrs[i].form)); | |
d97bc12b | 9390 | |
c906108c SS |
9391 | switch (die->attrs[i].form) |
9392 | { | |
9393 | case DW_FORM_ref_addr: | |
9394 | case DW_FORM_addr: | |
d97bc12b DE |
9395 | fprintf_unfiltered (f, "address: "); |
9396 | fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), f); | |
c906108c SS |
9397 | break; |
9398 | case DW_FORM_block2: | |
9399 | case DW_FORM_block4: | |
9400 | case DW_FORM_block: | |
9401 | case DW_FORM_block1: | |
d97bc12b | 9402 | fprintf_unfiltered (f, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 9403 | break; |
10b3939b DJ |
9404 | case DW_FORM_ref1: |
9405 | case DW_FORM_ref2: | |
9406 | case DW_FORM_ref4: | |
d97bc12b | 9407 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
10b3939b DJ |
9408 | (long) (DW_ADDR (&die->attrs[i]))); |
9409 | break; | |
c906108c SS |
9410 | case DW_FORM_data1: |
9411 | case DW_FORM_data2: | |
9412 | case DW_FORM_data4: | |
ce5d95e1 | 9413 | case DW_FORM_data8: |
c906108c SS |
9414 | case DW_FORM_udata: |
9415 | case DW_FORM_sdata: | |
d97bc12b | 9416 | fprintf_unfiltered (f, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
9417 | break; |
9418 | case DW_FORM_string: | |
4bdf3d34 | 9419 | case DW_FORM_strp: |
71c25dea | 9420 | case GDB_FORM_cached_string: |
d97bc12b | 9421 | fprintf_unfiltered (f, "string: \"%s\"", |
c906108c | 9422 | DW_STRING (&die->attrs[i]) |
c5aa993b | 9423 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
9424 | break; |
9425 | case DW_FORM_flag: | |
9426 | if (DW_UNSND (&die->attrs[i])) | |
d97bc12b | 9427 | fprintf_unfiltered (f, "flag: TRUE"); |
c906108c | 9428 | else |
d97bc12b | 9429 | fprintf_unfiltered (f, "flag: FALSE"); |
c906108c | 9430 | break; |
a8329558 KW |
9431 | case DW_FORM_indirect: |
9432 | /* the reader will have reduced the indirect form to | |
9433 | the "base form" so this form should not occur */ | |
d97bc12b | 9434 | fprintf_unfiltered (f, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 9435 | break; |
c906108c | 9436 | default: |
d97bc12b | 9437 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
c5aa993b | 9438 | die->attrs[i].form); |
d97bc12b | 9439 | break; |
c906108c | 9440 | } |
d97bc12b | 9441 | fprintf_unfiltered (f, "\n"); |
c906108c SS |
9442 | } |
9443 | } | |
9444 | ||
f9aca02d | 9445 | static void |
d97bc12b | 9446 | dump_die_for_error (struct die_info *die) |
c906108c | 9447 | { |
d97bc12b DE |
9448 | dump_die_shallow (gdb_stderr, 0, die); |
9449 | } | |
9450 | ||
9451 | static void | |
9452 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) | |
9453 | { | |
9454 | int indent = level * 4; | |
9455 | ||
9456 | gdb_assert (die != NULL); | |
9457 | ||
9458 | if (level >= max_level) | |
9459 | return; | |
9460 | ||
9461 | dump_die_shallow (f, indent, die); | |
9462 | ||
9463 | if (die->child != NULL) | |
c906108c | 9464 | { |
d97bc12b DE |
9465 | print_spaces (indent, f); |
9466 | fprintf_unfiltered (f, " Children:"); | |
9467 | if (level + 1 < max_level) | |
9468 | { | |
9469 | fprintf_unfiltered (f, "\n"); | |
9470 | dump_die_1 (f, level + 1, max_level, die->child); | |
9471 | } | |
9472 | else | |
9473 | { | |
9474 | fprintf_unfiltered (f, " [not printed, max nesting level reached]\n"); | |
9475 | } | |
9476 | } | |
9477 | ||
9478 | if (die->sibling != NULL && level > 0) | |
9479 | { | |
9480 | dump_die_1 (f, level, max_level, die->sibling); | |
c906108c SS |
9481 | } |
9482 | } | |
9483 | ||
d97bc12b DE |
9484 | /* This is called from the pdie macro in gdbinit.in. |
9485 | It's not static so gcc will keep a copy callable from gdb. */ | |
9486 | ||
9487 | void | |
9488 | dump_die (struct die_info *die, int max_level) | |
9489 | { | |
9490 | dump_die_1 (gdb_stdlog, 0, max_level, die); | |
9491 | } | |
9492 | ||
f9aca02d | 9493 | static void |
51545339 | 9494 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9495 | { |
51545339 | 9496 | void **slot; |
c906108c | 9497 | |
51545339 DJ |
9498 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
9499 | ||
9500 | *slot = die; | |
c906108c SS |
9501 | } |
9502 | ||
9503 | static unsigned int | |
c764a876 | 9504 | dwarf2_get_ref_die_offset (struct attribute *attr) |
c906108c SS |
9505 | { |
9506 | unsigned int result = 0; | |
9507 | ||
9508 | switch (attr->form) | |
9509 | { | |
9510 | case DW_FORM_ref_addr: | |
c906108c SS |
9511 | case DW_FORM_ref1: |
9512 | case DW_FORM_ref2: | |
9513 | case DW_FORM_ref4: | |
613e1657 | 9514 | case DW_FORM_ref8: |
c906108c | 9515 | case DW_FORM_ref_udata: |
10b3939b | 9516 | result = DW_ADDR (attr); |
c906108c SS |
9517 | break; |
9518 | default: | |
4d3c2250 | 9519 | complaint (&symfile_complaints, |
e2e0b3e5 | 9520 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 9521 | dwarf_form_name (attr->form)); |
c906108c SS |
9522 | } |
9523 | return result; | |
9524 | } | |
9525 | ||
a02abb62 JB |
9526 | /* Return the constant value held by the given attribute. Return -1 |
9527 | if the value held by the attribute is not constant. */ | |
9528 | ||
9529 | static int | |
9530 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
9531 | { | |
9532 | if (attr->form == DW_FORM_sdata) | |
9533 | return DW_SND (attr); | |
9534 | else if (attr->form == DW_FORM_udata | |
9535 | || attr->form == DW_FORM_data1 | |
9536 | || attr->form == DW_FORM_data2 | |
9537 | || attr->form == DW_FORM_data4 | |
9538 | || attr->form == DW_FORM_data8) | |
9539 | return DW_UNSND (attr); | |
9540 | else | |
9541 | { | |
e2e0b3e5 | 9542 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
9543 | dwarf_form_name (attr->form)); |
9544 | return default_value; | |
9545 | } | |
9546 | } | |
9547 | ||
03dd20cc DJ |
9548 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
9549 | unit and add it to our queue. */ | |
9550 | ||
9551 | static void | |
9552 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
9553 | struct dwarf2_per_cu_data *per_cu) | |
9554 | { | |
9555 | /* Mark the dependence relation so that we don't flush PER_CU | |
9556 | too early. */ | |
9557 | dwarf2_add_dependence (this_cu, per_cu); | |
9558 | ||
9559 | /* If it's already on the queue, we have nothing to do. */ | |
9560 | if (per_cu->queued) | |
9561 | return; | |
9562 | ||
9563 | /* If the compilation unit is already loaded, just mark it as | |
9564 | used. */ | |
9565 | if (per_cu->cu != NULL) | |
9566 | { | |
9567 | per_cu->cu->last_used = 0; | |
9568 | return; | |
9569 | } | |
9570 | ||
9571 | /* Add it to the queue. */ | |
9572 | queue_comp_unit (per_cu, this_cu->objfile); | |
9573 | } | |
9574 | ||
f504f079 DE |
9575 | /* Follow reference attribute ATTR of SRC_DIE. |
9576 | On entry *REF_CU is the CU of SRC_DIE. | |
9577 | On exit *REF_CU is the CU of the result. */ | |
9578 | ||
f9aca02d | 9579 | static struct die_info * |
10b3939b | 9580 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 9581 | struct dwarf2_cu **ref_cu) |
c906108c SS |
9582 | { |
9583 | struct die_info *die; | |
10b3939b | 9584 | unsigned int offset; |
10b3939b | 9585 | struct die_info temp_die; |
f2f0e013 | 9586 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b | 9587 | |
c764a876 | 9588 | offset = dwarf2_get_ref_die_offset (attr); |
10b3939b | 9589 | |
45452591 | 9590 | if (! offset_in_cu_p (&cu->header, offset)) |
10b3939b DJ |
9591 | { |
9592 | struct dwarf2_per_cu_data *per_cu; | |
45452591 | 9593 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
03dd20cc DJ |
9594 | |
9595 | /* If necessary, add it to the queue and load its DIEs. */ | |
9596 | maybe_queue_comp_unit (cu, per_cu); | |
9597 | ||
10b3939b DJ |
9598 | target_cu = per_cu->cu; |
9599 | } | |
9600 | else | |
9601 | target_cu = cu; | |
c906108c | 9602 | |
f2f0e013 | 9603 | *ref_cu = target_cu; |
51545339 DJ |
9604 | temp_die.offset = offset; |
9605 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
9606 | if (die) | |
9607 | return die; | |
10b3939b | 9608 | |
8a3fe4f8 AC |
9609 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
9610 | "at 0x%lx [in module %s]"), | |
1d325ec1 | 9611 | (long) offset, (long) src_die->offset, cu->objfile->name); |
c906108c SS |
9612 | } |
9613 | ||
c906108c SS |
9614 | /* Decode simple location descriptions. |
9615 | Given a pointer to a dwarf block that defines a location, compute | |
9616 | the location and return the value. | |
9617 | ||
4cecd739 DJ |
9618 | NOTE drow/2003-11-18: This function is called in two situations |
9619 | now: for the address of static or global variables (partial symbols | |
9620 | only) and for offsets into structures which are expected to be | |
9621 | (more or less) constant. The partial symbol case should go away, | |
9622 | and only the constant case should remain. That will let this | |
9623 | function complain more accurately. A few special modes are allowed | |
9624 | without complaint for global variables (for instance, global | |
9625 | register values and thread-local values). | |
c906108c SS |
9626 | |
9627 | A location description containing no operations indicates that the | |
4cecd739 | 9628 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
9629 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
9630 | callers will only want a very basic result and this can become a | |
9631 | complaint. | |
c906108c | 9632 | |
c906108c SS |
9633 | Note that stack[0] is unused except as a default error return. |
9634 | Note that stack overflow is not yet handled. */ | |
9635 | ||
9636 | static CORE_ADDR | |
e7c27a73 | 9637 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 9638 | { |
e7c27a73 DJ |
9639 | struct objfile *objfile = cu->objfile; |
9640 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
9641 | int i; |
9642 | int size = blk->size; | |
fe1b8b76 | 9643 | gdb_byte *data = blk->data; |
c906108c SS |
9644 | CORE_ADDR stack[64]; |
9645 | int stacki; | |
9646 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 9647 | gdb_byte op; |
c906108c SS |
9648 | |
9649 | i = 0; | |
9650 | stacki = 0; | |
9651 | stack[stacki] = 0; | |
c906108c SS |
9652 | |
9653 | while (i < size) | |
9654 | { | |
c906108c SS |
9655 | op = data[i++]; |
9656 | switch (op) | |
9657 | { | |
f1bea926 JM |
9658 | case DW_OP_lit0: |
9659 | case DW_OP_lit1: | |
9660 | case DW_OP_lit2: | |
9661 | case DW_OP_lit3: | |
9662 | case DW_OP_lit4: | |
9663 | case DW_OP_lit5: | |
9664 | case DW_OP_lit6: | |
9665 | case DW_OP_lit7: | |
9666 | case DW_OP_lit8: | |
9667 | case DW_OP_lit9: | |
9668 | case DW_OP_lit10: | |
9669 | case DW_OP_lit11: | |
9670 | case DW_OP_lit12: | |
9671 | case DW_OP_lit13: | |
9672 | case DW_OP_lit14: | |
9673 | case DW_OP_lit15: | |
9674 | case DW_OP_lit16: | |
9675 | case DW_OP_lit17: | |
9676 | case DW_OP_lit18: | |
9677 | case DW_OP_lit19: | |
9678 | case DW_OP_lit20: | |
9679 | case DW_OP_lit21: | |
9680 | case DW_OP_lit22: | |
9681 | case DW_OP_lit23: | |
9682 | case DW_OP_lit24: | |
9683 | case DW_OP_lit25: | |
9684 | case DW_OP_lit26: | |
9685 | case DW_OP_lit27: | |
9686 | case DW_OP_lit28: | |
9687 | case DW_OP_lit29: | |
9688 | case DW_OP_lit30: | |
9689 | case DW_OP_lit31: | |
9690 | stack[++stacki] = op - DW_OP_lit0; | |
9691 | break; | |
9692 | ||
c906108c SS |
9693 | case DW_OP_reg0: |
9694 | case DW_OP_reg1: | |
9695 | case DW_OP_reg2: | |
9696 | case DW_OP_reg3: | |
9697 | case DW_OP_reg4: | |
9698 | case DW_OP_reg5: | |
9699 | case DW_OP_reg6: | |
9700 | case DW_OP_reg7: | |
9701 | case DW_OP_reg8: | |
9702 | case DW_OP_reg9: | |
9703 | case DW_OP_reg10: | |
9704 | case DW_OP_reg11: | |
9705 | case DW_OP_reg12: | |
9706 | case DW_OP_reg13: | |
9707 | case DW_OP_reg14: | |
9708 | case DW_OP_reg15: | |
9709 | case DW_OP_reg16: | |
9710 | case DW_OP_reg17: | |
9711 | case DW_OP_reg18: | |
9712 | case DW_OP_reg19: | |
9713 | case DW_OP_reg20: | |
9714 | case DW_OP_reg21: | |
9715 | case DW_OP_reg22: | |
9716 | case DW_OP_reg23: | |
9717 | case DW_OP_reg24: | |
9718 | case DW_OP_reg25: | |
9719 | case DW_OP_reg26: | |
9720 | case DW_OP_reg27: | |
9721 | case DW_OP_reg28: | |
9722 | case DW_OP_reg29: | |
9723 | case DW_OP_reg30: | |
9724 | case DW_OP_reg31: | |
c906108c | 9725 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9726 | if (i < size) |
9727 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9728 | break; |
9729 | ||
9730 | case DW_OP_regx: | |
c906108c SS |
9731 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9732 | i += bytes_read; | |
c906108c | 9733 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9734 | if (i < size) |
9735 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9736 | break; |
9737 | ||
9738 | case DW_OP_addr: | |
107d2387 | 9739 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9740 | cu, &bytes_read); |
107d2387 | 9741 | i += bytes_read; |
c906108c SS |
9742 | break; |
9743 | ||
9744 | case DW_OP_const1u: | |
9745 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9746 | i += 1; | |
9747 | break; | |
9748 | ||
9749 | case DW_OP_const1s: | |
9750 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9751 | i += 1; | |
9752 | break; | |
9753 | ||
9754 | case DW_OP_const2u: | |
9755 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9756 | i += 2; | |
9757 | break; | |
9758 | ||
9759 | case DW_OP_const2s: | |
9760 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9761 | i += 2; | |
9762 | break; | |
9763 | ||
9764 | case DW_OP_const4u: | |
9765 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9766 | i += 4; | |
9767 | break; | |
9768 | ||
9769 | case DW_OP_const4s: | |
9770 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9771 | i += 4; | |
9772 | break; | |
9773 | ||
9774 | case DW_OP_constu: | |
9775 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9776 | &bytes_read); |
c906108c SS |
9777 | i += bytes_read; |
9778 | break; | |
9779 | ||
9780 | case DW_OP_consts: | |
9781 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9782 | i += bytes_read; | |
9783 | break; | |
9784 | ||
f1bea926 JM |
9785 | case DW_OP_dup: |
9786 | stack[stacki + 1] = stack[stacki]; | |
9787 | stacki++; | |
9788 | break; | |
9789 | ||
c906108c SS |
9790 | case DW_OP_plus: |
9791 | stack[stacki - 1] += stack[stacki]; | |
9792 | stacki--; | |
9793 | break; | |
9794 | ||
9795 | case DW_OP_plus_uconst: | |
9796 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9797 | i += bytes_read; | |
9798 | break; | |
9799 | ||
9800 | case DW_OP_minus: | |
f1bea926 | 9801 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9802 | stacki--; |
9803 | break; | |
9804 | ||
7a292a7a | 9805 | case DW_OP_deref: |
7a292a7a | 9806 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9807 | this using GDB's address_class enum. This is valid for partial |
9808 | global symbols, although the variable's address will be bogus | |
9809 | in the psymtab. */ | |
7a292a7a | 9810 | if (i < size) |
4d3c2250 | 9811 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9812 | break; |
9813 | ||
9d774e44 | 9814 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9815 | /* The top of the stack has the offset from the beginning |
9816 | of the thread control block at which the variable is located. */ | |
9817 | /* Nothing should follow this operator, so the top of stack would | |
9818 | be returned. */ | |
4cecd739 DJ |
9819 | /* This is valid for partial global symbols, but the variable's |
9820 | address will be bogus in the psymtab. */ | |
9d774e44 | 9821 | if (i < size) |
4d3c2250 | 9822 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9823 | break; |
9824 | ||
42be36b3 CT |
9825 | case DW_OP_GNU_uninit: |
9826 | break; | |
9827 | ||
c906108c | 9828 | default: |
e2e0b3e5 | 9829 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9830 | dwarf_stack_op_name (op)); |
c906108c SS |
9831 | return (stack[stacki]); |
9832 | } | |
9833 | } | |
9834 | return (stack[stacki]); | |
9835 | } | |
9836 | ||
9837 | /* memory allocation interface */ | |
9838 | ||
c906108c | 9839 | static struct dwarf_block * |
7b5a2f43 | 9840 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9841 | { |
9842 | struct dwarf_block *blk; | |
9843 | ||
9844 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9845 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9846 | return (blk); |
9847 | } | |
9848 | ||
9849 | static struct abbrev_info * | |
f3dd6933 | 9850 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9851 | { |
9852 | struct abbrev_info *abbrev; | |
9853 | ||
f3dd6933 DJ |
9854 | abbrev = (struct abbrev_info *) |
9855 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9856 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9857 | return (abbrev); | |
9858 | } | |
9859 | ||
9860 | static struct die_info * | |
b60c80d6 | 9861 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
9862 | { |
9863 | struct die_info *die; | |
b60c80d6 DJ |
9864 | size_t size = sizeof (struct die_info); |
9865 | ||
9866 | if (num_attrs > 1) | |
9867 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 9868 | |
b60c80d6 | 9869 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
9870 | memset (die, 0, sizeof (struct die_info)); |
9871 | return (die); | |
9872 | } | |
2e276125 JB |
9873 | |
9874 | \f | |
9875 | /* Macro support. */ | |
9876 | ||
9877 | ||
9878 | /* Return the full name of file number I in *LH's file name table. | |
9879 | Use COMP_DIR as the name of the current directory of the | |
9880 | compilation. The result is allocated using xmalloc; the caller is | |
9881 | responsible for freeing it. */ | |
9882 | static char * | |
9883 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9884 | { | |
6a83a1e6 EZ |
9885 | /* Is the file number a valid index into the line header's file name |
9886 | table? Remember that file numbers start with one, not zero. */ | |
9887 | if (1 <= file && file <= lh->num_file_names) | |
9888 | { | |
9889 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9890 | |
6a83a1e6 EZ |
9891 | if (IS_ABSOLUTE_PATH (fe->name)) |
9892 | return xstrdup (fe->name); | |
9893 | else | |
9894 | { | |
9895 | const char *dir; | |
9896 | int dir_len; | |
9897 | char *full_name; | |
9898 | ||
9899 | if (fe->dir_index) | |
9900 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9901 | else | |
9902 | dir = comp_dir; | |
9903 | ||
9904 | if (dir) | |
9905 | { | |
9906 | dir_len = strlen (dir); | |
9907 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9908 | strcpy (full_name, dir); | |
9909 | full_name[dir_len] = '/'; | |
9910 | strcpy (full_name + dir_len + 1, fe->name); | |
9911 | return full_name; | |
9912 | } | |
9913 | else | |
9914 | return xstrdup (fe->name); | |
9915 | } | |
9916 | } | |
2e276125 JB |
9917 | else |
9918 | { | |
6a83a1e6 EZ |
9919 | /* The compiler produced a bogus file number. We can at least |
9920 | record the macro definitions made in the file, even if we | |
9921 | won't be able to find the file by name. */ | |
9922 | char fake_name[80]; | |
9923 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9924 | |
6a83a1e6 EZ |
9925 | complaint (&symfile_complaints, |
9926 | _("bad file number in macro information (%d)"), | |
9927 | file); | |
2e276125 | 9928 | |
6a83a1e6 | 9929 | return xstrdup (fake_name); |
2e276125 JB |
9930 | } |
9931 | } | |
9932 | ||
9933 | ||
9934 | static struct macro_source_file * | |
9935 | macro_start_file (int file, int line, | |
9936 | struct macro_source_file *current_file, | |
9937 | const char *comp_dir, | |
9938 | struct line_header *lh, struct objfile *objfile) | |
9939 | { | |
9940 | /* The full name of this source file. */ | |
9941 | char *full_name = file_full_name (file, lh, comp_dir); | |
9942 | ||
9943 | /* We don't create a macro table for this compilation unit | |
9944 | at all until we actually get a filename. */ | |
9945 | if (! pending_macros) | |
4a146b47 | 9946 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9947 | objfile->macro_cache); |
2e276125 JB |
9948 | |
9949 | if (! current_file) | |
9950 | /* If we have no current file, then this must be the start_file | |
9951 | directive for the compilation unit's main source file. */ | |
9952 | current_file = macro_set_main (pending_macros, full_name); | |
9953 | else | |
9954 | current_file = macro_include (current_file, line, full_name); | |
9955 | ||
9956 | xfree (full_name); | |
9957 | ||
9958 | return current_file; | |
9959 | } | |
9960 | ||
9961 | ||
9962 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9963 | followed by a null byte. */ | |
9964 | static char * | |
9965 | copy_string (const char *buf, int len) | |
9966 | { | |
9967 | char *s = xmalloc (len + 1); | |
9968 | memcpy (s, buf, len); | |
9969 | s[len] = '\0'; | |
9970 | ||
9971 | return s; | |
9972 | } | |
9973 | ||
9974 | ||
9975 | static const char * | |
9976 | consume_improper_spaces (const char *p, const char *body) | |
9977 | { | |
9978 | if (*p == ' ') | |
9979 | { | |
4d3c2250 | 9980 | complaint (&symfile_complaints, |
e2e0b3e5 | 9981 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9982 | body); |
2e276125 JB |
9983 | |
9984 | while (*p == ' ') | |
9985 | p++; | |
9986 | } | |
9987 | ||
9988 | return p; | |
9989 | } | |
9990 | ||
9991 | ||
9992 | static void | |
9993 | parse_macro_definition (struct macro_source_file *file, int line, | |
9994 | const char *body) | |
9995 | { | |
9996 | const char *p; | |
9997 | ||
9998 | /* The body string takes one of two forms. For object-like macro | |
9999 | definitions, it should be: | |
10000 | ||
10001 | <macro name> " " <definition> | |
10002 | ||
10003 | For function-like macro definitions, it should be: | |
10004 | ||
10005 | <macro name> "() " <definition> | |
10006 | or | |
10007 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
10008 | ||
10009 | Spaces may appear only where explicitly indicated, and in the | |
10010 | <definition>. | |
10011 | ||
10012 | The Dwarf 2 spec says that an object-like macro's name is always | |
10013 | followed by a space, but versions of GCC around March 2002 omit | |
10014 | the space when the macro's definition is the empty string. | |
10015 | ||
10016 | The Dwarf 2 spec says that there should be no spaces between the | |
10017 | formal arguments in a function-like macro's formal argument list, | |
10018 | but versions of GCC around March 2002 include spaces after the | |
10019 | commas. */ | |
10020 | ||
10021 | ||
10022 | /* Find the extent of the macro name. The macro name is terminated | |
10023 | by either a space or null character (for an object-like macro) or | |
10024 | an opening paren (for a function-like macro). */ | |
10025 | for (p = body; *p; p++) | |
10026 | if (*p == ' ' || *p == '(') | |
10027 | break; | |
10028 | ||
10029 | if (*p == ' ' || *p == '\0') | |
10030 | { | |
10031 | /* It's an object-like macro. */ | |
10032 | int name_len = p - body; | |
10033 | char *name = copy_string (body, name_len); | |
10034 | const char *replacement; | |
10035 | ||
10036 | if (*p == ' ') | |
10037 | replacement = body + name_len + 1; | |
10038 | else | |
10039 | { | |
4d3c2250 | 10040 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10041 | replacement = body + name_len; |
10042 | } | |
10043 | ||
10044 | macro_define_object (file, line, name, replacement); | |
10045 | ||
10046 | xfree (name); | |
10047 | } | |
10048 | else if (*p == '(') | |
10049 | { | |
10050 | /* It's a function-like macro. */ | |
10051 | char *name = copy_string (body, p - body); | |
10052 | int argc = 0; | |
10053 | int argv_size = 1; | |
10054 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
10055 | ||
10056 | p++; | |
10057 | ||
10058 | p = consume_improper_spaces (p, body); | |
10059 | ||
10060 | /* Parse the formal argument list. */ | |
10061 | while (*p && *p != ')') | |
10062 | { | |
10063 | /* Find the extent of the current argument name. */ | |
10064 | const char *arg_start = p; | |
10065 | ||
10066 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
10067 | p++; | |
10068 | ||
10069 | if (! *p || p == arg_start) | |
4d3c2250 | 10070 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10071 | else |
10072 | { | |
10073 | /* Make sure argv has room for the new argument. */ | |
10074 | if (argc >= argv_size) | |
10075 | { | |
10076 | argv_size *= 2; | |
10077 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
10078 | } | |
10079 | ||
10080 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
10081 | } | |
10082 | ||
10083 | p = consume_improper_spaces (p, body); | |
10084 | ||
10085 | /* Consume the comma, if present. */ | |
10086 | if (*p == ',') | |
10087 | { | |
10088 | p++; | |
10089 | ||
10090 | p = consume_improper_spaces (p, body); | |
10091 | } | |
10092 | } | |
10093 | ||
10094 | if (*p == ')') | |
10095 | { | |
10096 | p++; | |
10097 | ||
10098 | if (*p == ' ') | |
10099 | /* Perfectly formed definition, no complaints. */ | |
10100 | macro_define_function (file, line, name, | |
10101 | argc, (const char **) argv, | |
10102 | p + 1); | |
10103 | else if (*p == '\0') | |
10104 | { | |
10105 | /* Complain, but do define it. */ | |
4d3c2250 | 10106 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10107 | macro_define_function (file, line, name, |
10108 | argc, (const char **) argv, | |
10109 | p); | |
10110 | } | |
10111 | else | |
10112 | /* Just complain. */ | |
4d3c2250 | 10113 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10114 | } |
10115 | else | |
10116 | /* Just complain. */ | |
4d3c2250 | 10117 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10118 | |
10119 | xfree (name); | |
10120 | { | |
10121 | int i; | |
10122 | ||
10123 | for (i = 0; i < argc; i++) | |
10124 | xfree (argv[i]); | |
10125 | } | |
10126 | xfree (argv); | |
10127 | } | |
10128 | else | |
4d3c2250 | 10129 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
10130 | } |
10131 | ||
10132 | ||
10133 | static void | |
10134 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
10135 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 10136 | struct dwarf2_cu *cu) |
2e276125 | 10137 | { |
fe1b8b76 | 10138 | gdb_byte *mac_ptr, *mac_end; |
2e276125 | 10139 | struct macro_source_file *current_file = 0; |
757a13d0 JK |
10140 | enum dwarf_macinfo_record_type macinfo_type; |
10141 | int at_commandline; | |
2e276125 | 10142 | |
dce234bc | 10143 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
2e276125 | 10144 | { |
e2e0b3e5 | 10145 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
10146 | return; |
10147 | } | |
10148 | ||
757a13d0 JK |
10149 | /* First pass: Find the name of the base filename. |
10150 | This filename is needed in order to process all macros whose definition | |
10151 | (or undefinition) comes from the command line. These macros are defined | |
10152 | before the first DW_MACINFO_start_file entry, and yet still need to be | |
10153 | associated to the base file. | |
10154 | ||
10155 | To determine the base file name, we scan the macro definitions until we | |
10156 | reach the first DW_MACINFO_start_file entry. We then initialize | |
10157 | CURRENT_FILE accordingly so that any macro definition found before the | |
10158 | first DW_MACINFO_start_file can still be associated to the base file. */ | |
10159 | ||
dce234bc PP |
10160 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
10161 | mac_end = dwarf2_per_objfile->macinfo.buffer | |
10162 | + dwarf2_per_objfile->macinfo.size; | |
2e276125 | 10163 | |
757a13d0 | 10164 | do |
2e276125 | 10165 | { |
2e276125 JB |
10166 | /* Do we at least have room for a macinfo type byte? */ |
10167 | if (mac_ptr >= mac_end) | |
10168 | { | |
757a13d0 JK |
10169 | /* Complaint is printed during the second pass as GDB will probably |
10170 | stop the first pass earlier upon finding DW_MACINFO_start_file. */ | |
10171 | break; | |
2e276125 JB |
10172 | } |
10173 | ||
10174 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
10175 | mac_ptr++; | |
10176 | ||
10177 | switch (macinfo_type) | |
10178 | { | |
10179 | /* A zero macinfo type indicates the end of the macro | |
10180 | information. */ | |
10181 | case 0: | |
757a13d0 JK |
10182 | break; |
10183 | ||
10184 | case DW_MACINFO_define: | |
10185 | case DW_MACINFO_undef: | |
10186 | /* Only skip the data by MAC_PTR. */ | |
10187 | { | |
10188 | unsigned int bytes_read; | |
10189 | ||
10190 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10191 | mac_ptr += bytes_read; | |
10192 | read_string (abfd, mac_ptr, &bytes_read); | |
10193 | mac_ptr += bytes_read; | |
10194 | } | |
10195 | break; | |
10196 | ||
10197 | case DW_MACINFO_start_file: | |
10198 | { | |
10199 | unsigned int bytes_read; | |
10200 | int line, file; | |
10201 | ||
10202 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10203 | mac_ptr += bytes_read; | |
10204 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10205 | mac_ptr += bytes_read; | |
10206 | ||
10207 | current_file = macro_start_file (file, line, current_file, comp_dir, | |
10208 | lh, cu->objfile); | |
10209 | } | |
10210 | break; | |
10211 | ||
10212 | case DW_MACINFO_end_file: | |
10213 | /* No data to skip by MAC_PTR. */ | |
10214 | break; | |
10215 | ||
10216 | case DW_MACINFO_vendor_ext: | |
10217 | /* Only skip the data by MAC_PTR. */ | |
10218 | { | |
10219 | unsigned int bytes_read; | |
10220 | ||
10221 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10222 | mac_ptr += bytes_read; | |
10223 | read_string (abfd, mac_ptr, &bytes_read); | |
10224 | mac_ptr += bytes_read; | |
10225 | } | |
10226 | break; | |
10227 | ||
10228 | default: | |
10229 | break; | |
10230 | } | |
10231 | } while (macinfo_type != 0 && current_file == NULL); | |
10232 | ||
10233 | /* Second pass: Process all entries. | |
10234 | ||
10235 | Use the AT_COMMAND_LINE flag to determine whether we are still processing | |
10236 | command-line macro definitions/undefinitions. This flag is unset when we | |
10237 | reach the first DW_MACINFO_start_file entry. */ | |
10238 | ||
dce234bc | 10239 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
757a13d0 JK |
10240 | |
10241 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true | |
10242 | GDB is still reading the definitions from command line. First | |
10243 | DW_MACINFO_start_file will need to be ignored as it was already executed | |
10244 | to create CURRENT_FILE for the main source holding also the command line | |
10245 | definitions. On first met DW_MACINFO_start_file this flag is reset to | |
10246 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ | |
10247 | ||
10248 | at_commandline = 1; | |
10249 | ||
10250 | do | |
10251 | { | |
10252 | /* Do we at least have room for a macinfo type byte? */ | |
10253 | if (mac_ptr >= mac_end) | |
10254 | { | |
10255 | dwarf2_macros_too_long_complaint (); | |
10256 | break; | |
10257 | } | |
10258 | ||
10259 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
10260 | mac_ptr++; | |
10261 | ||
10262 | switch (macinfo_type) | |
10263 | { | |
10264 | /* A zero macinfo type indicates the end of the macro | |
10265 | information. */ | |
10266 | case 0: | |
10267 | break; | |
2e276125 JB |
10268 | |
10269 | case DW_MACINFO_define: | |
10270 | case DW_MACINFO_undef: | |
10271 | { | |
891d2f0b | 10272 | unsigned int bytes_read; |
2e276125 JB |
10273 | int line; |
10274 | char *body; | |
10275 | ||
10276 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10277 | mac_ptr += bytes_read; | |
10278 | body = read_string (abfd, mac_ptr, &bytes_read); | |
10279 | mac_ptr += bytes_read; | |
10280 | ||
10281 | if (! current_file) | |
757a13d0 JK |
10282 | { |
10283 | /* DWARF violation as no main source is present. */ | |
10284 | complaint (&symfile_complaints, | |
10285 | _("debug info with no main source gives macro %s " | |
10286 | "on line %d: %s"), | |
10287 | macinfo_type == | |
10288 | DW_MACINFO_define ? _("definition") : macinfo_type == | |
10289 | DW_MACINFO_undef ? _("undefinition") : | |
10290 | "something-or-other", line, body); | |
10291 | break; | |
10292 | } | |
10293 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) | |
4d3c2250 | 10294 | complaint (&symfile_complaints, |
757a13d0 JK |
10295 | _("debug info gives %s macro %s with %s line %d: %s"), |
10296 | at_commandline ? _("command-line") : _("in-file"), | |
4d3c2250 | 10297 | macinfo_type == |
757a13d0 JK |
10298 | DW_MACINFO_define ? _("definition") : macinfo_type == |
10299 | DW_MACINFO_undef ? _("undefinition") : | |
10300 | "something-or-other", | |
10301 | line == 0 ? _("zero") : _("non-zero"), line, body); | |
10302 | ||
10303 | if (macinfo_type == DW_MACINFO_define) | |
10304 | parse_macro_definition (current_file, line, body); | |
10305 | else if (macinfo_type == DW_MACINFO_undef) | |
10306 | macro_undef (current_file, line, body); | |
2e276125 JB |
10307 | } |
10308 | break; | |
10309 | ||
10310 | case DW_MACINFO_start_file: | |
10311 | { | |
891d2f0b | 10312 | unsigned int bytes_read; |
2e276125 JB |
10313 | int line, file; |
10314 | ||
10315 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10316 | mac_ptr += bytes_read; | |
10317 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10318 | mac_ptr += bytes_read; | |
10319 | ||
757a13d0 JK |
10320 | if ((line == 0 && !at_commandline) || (line != 0 && at_commandline)) |
10321 | complaint (&symfile_complaints, | |
10322 | _("debug info gives source %d included " | |
10323 | "from %s at %s line %d"), | |
10324 | file, at_commandline ? _("command-line") : _("file"), | |
10325 | line == 0 ? _("zero") : _("non-zero"), line); | |
10326 | ||
10327 | if (at_commandline) | |
10328 | { | |
10329 | /* This DW_MACINFO_start_file was executed in the pass one. */ | |
10330 | at_commandline = 0; | |
10331 | } | |
10332 | else | |
10333 | current_file = macro_start_file (file, line, | |
10334 | current_file, comp_dir, | |
10335 | lh, cu->objfile); | |
2e276125 JB |
10336 | } |
10337 | break; | |
10338 | ||
10339 | case DW_MACINFO_end_file: | |
10340 | if (! current_file) | |
4d3c2250 | 10341 | complaint (&symfile_complaints, |
e2e0b3e5 | 10342 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
10343 | else |
10344 | { | |
10345 | current_file = current_file->included_by; | |
10346 | if (! current_file) | |
10347 | { | |
10348 | enum dwarf_macinfo_record_type next_type; | |
10349 | ||
10350 | /* GCC circa March 2002 doesn't produce the zero | |
10351 | type byte marking the end of the compilation | |
10352 | unit. Complain if it's not there, but exit no | |
10353 | matter what. */ | |
10354 | ||
10355 | /* Do we at least have room for a macinfo type byte? */ | |
10356 | if (mac_ptr >= mac_end) | |
10357 | { | |
4d3c2250 | 10358 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
10359 | return; |
10360 | } | |
10361 | ||
10362 | /* We don't increment mac_ptr here, so this is just | |
10363 | a look-ahead. */ | |
10364 | next_type = read_1_byte (abfd, mac_ptr); | |
10365 | if (next_type != 0) | |
4d3c2250 | 10366 | complaint (&symfile_complaints, |
e2e0b3e5 | 10367 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
10368 | |
10369 | return; | |
10370 | } | |
10371 | } | |
10372 | break; | |
10373 | ||
10374 | case DW_MACINFO_vendor_ext: | |
10375 | { | |
891d2f0b | 10376 | unsigned int bytes_read; |
2e276125 JB |
10377 | int constant; |
10378 | char *string; | |
10379 | ||
10380 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
10381 | mac_ptr += bytes_read; | |
10382 | string = read_string (abfd, mac_ptr, &bytes_read); | |
10383 | mac_ptr += bytes_read; | |
10384 | ||
10385 | /* We don't recognize any vendor extensions. */ | |
10386 | } | |
10387 | break; | |
10388 | } | |
757a13d0 | 10389 | } while (macinfo_type != 0); |
2e276125 | 10390 | } |
8e19ed76 PS |
10391 | |
10392 | /* Check if the attribute's form is a DW_FORM_block* | |
10393 | if so return true else false. */ | |
10394 | static int | |
10395 | attr_form_is_block (struct attribute *attr) | |
10396 | { | |
10397 | return (attr == NULL ? 0 : | |
10398 | attr->form == DW_FORM_block1 | |
10399 | || attr->form == DW_FORM_block2 | |
10400 | || attr->form == DW_FORM_block4 | |
10401 | || attr->form == DW_FORM_block); | |
10402 | } | |
4c2df51b | 10403 | |
c6a0999f JB |
10404 | /* Return non-zero if ATTR's value is a section offset --- classes |
10405 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
10406 | You may use DW_UNSND (attr) to retrieve such offsets. | |
10407 | ||
10408 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
10409 | may have a value that belongs to more than one of these classes; it | |
10410 | would be ambiguous if we did, because we use the same forms for all | |
10411 | of them. */ | |
3690dd37 JB |
10412 | static int |
10413 | attr_form_is_section_offset (struct attribute *attr) | |
10414 | { | |
10415 | return (attr->form == DW_FORM_data4 | |
10416 | || attr->form == DW_FORM_data8); | |
10417 | } | |
10418 | ||
10419 | ||
10420 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
10421 | zero otherwise. When this function returns true, you can apply | |
10422 | dwarf2_get_attr_constant_value to it. | |
10423 | ||
10424 | However, note that for some attributes you must check | |
10425 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
10426 | and DW_FORM_data8 are members of both the constant class, and of | |
10427 | the classes that contain offsets into other debug sections | |
10428 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
10429 | that, if an attribute's can be either a constant or one of the | |
10430 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
10431 | taken as section offsets, not constants. */ | |
10432 | static int | |
10433 | attr_form_is_constant (struct attribute *attr) | |
10434 | { | |
10435 | switch (attr->form) | |
10436 | { | |
10437 | case DW_FORM_sdata: | |
10438 | case DW_FORM_udata: | |
10439 | case DW_FORM_data1: | |
10440 | case DW_FORM_data2: | |
10441 | case DW_FORM_data4: | |
10442 | case DW_FORM_data8: | |
10443 | return 1; | |
10444 | default: | |
10445 | return 0; | |
10446 | } | |
10447 | } | |
10448 | ||
4c2df51b DJ |
10449 | static void |
10450 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 10451 | struct dwarf2_cu *cu) |
4c2df51b | 10452 | { |
3690dd37 | 10453 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
10454 | /* ".debug_loc" may not exist at all, or the offset may be outside |
10455 | the section. If so, fall through to the complaint in the | |
10456 | other branch. */ | |
dce234bc | 10457 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
4c2df51b | 10458 | { |
0d53c4c4 | 10459 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 10460 | |
4a146b47 | 10461 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 10462 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
10463 | baton->per_cu = cu->per_cu; |
10464 | gdb_assert (baton->per_cu); | |
4c2df51b | 10465 | |
0d53c4c4 DJ |
10466 | /* We don't know how long the location list is, but make sure we |
10467 | don't run off the edge of the section. */ | |
dce234bc PP |
10468 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
10469 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); | |
d00adf39 DE |
10470 | baton->base_address = cu->base_address; |
10471 | if (cu->base_known == 0) | |
0d53c4c4 | 10472 | complaint (&symfile_complaints, |
e2e0b3e5 | 10473 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 10474 | |
768a979c | 10475 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
10476 | SYMBOL_LOCATION_BATON (sym) = baton; |
10477 | } | |
10478 | else | |
10479 | { | |
10480 | struct dwarf2_locexpr_baton *baton; | |
10481 | ||
4a146b47 | 10482 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 10483 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
10484 | baton->per_cu = cu->per_cu; |
10485 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
10486 | |
10487 | if (attr_form_is_block (attr)) | |
10488 | { | |
10489 | /* Note that we're just copying the block's data pointer | |
10490 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
10491 | info_buffer for SYM's objfile; right now we never release |
10492 | that buffer, but when we do clean up properly this may | |
10493 | need to change. */ | |
0d53c4c4 DJ |
10494 | baton->size = DW_BLOCK (attr)->size; |
10495 | baton->data = DW_BLOCK (attr)->data; | |
10496 | } | |
10497 | else | |
10498 | { | |
10499 | dwarf2_invalid_attrib_class_complaint ("location description", | |
10500 | SYMBOL_NATURAL_NAME (sym)); | |
10501 | baton->size = 0; | |
10502 | baton->data = NULL; | |
10503 | } | |
10504 | ||
768a979c | 10505 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
10506 | SYMBOL_LOCATION_BATON (sym) = baton; |
10507 | } | |
4c2df51b | 10508 | } |
6502dd73 | 10509 | |
ae0d2f24 UW |
10510 | /* Return the OBJFILE associated with the compilation unit CU. */ |
10511 | ||
10512 | struct objfile * | |
10513 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
10514 | { | |
10515 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10516 | ||
10517 | /* Return the master objfile, so that we can report and look up the | |
10518 | correct file containing this variable. */ | |
10519 | if (objfile->separate_debug_objfile_backlink) | |
10520 | objfile = objfile->separate_debug_objfile_backlink; | |
10521 | ||
10522 | return objfile; | |
10523 | } | |
10524 | ||
10525 | /* Return the address size given in the compilation unit header for CU. */ | |
10526 | ||
10527 | CORE_ADDR | |
10528 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
10529 | { | |
10530 | if (per_cu->cu) | |
10531 | return per_cu->cu->header.addr_size; | |
10532 | else | |
10533 | { | |
10534 | /* If the CU is not currently read in, we re-read its header. */ | |
10535 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10536 | struct dwarf2_per_objfile *per_objfile | |
10537 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
dce234bc | 10538 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
ae0d2f24 UW |
10539 | |
10540 | struct comp_unit_head cu_header; | |
10541 | memset (&cu_header, 0, sizeof cu_header); | |
10542 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
10543 | return cu_header.addr_size; | |
10544 | } | |
10545 | } | |
10546 | ||
ae038cb0 | 10547 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 10548 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
10549 | |
10550 | static struct dwarf2_per_cu_data * | |
c764a876 | 10551 | dwarf2_find_containing_comp_unit (unsigned int offset, |
ae038cb0 DJ |
10552 | struct objfile *objfile) |
10553 | { | |
10554 | struct dwarf2_per_cu_data *this_cu; | |
10555 | int low, high; | |
10556 | ||
ae038cb0 DJ |
10557 | low = 0; |
10558 | high = dwarf2_per_objfile->n_comp_units - 1; | |
10559 | while (high > low) | |
10560 | { | |
10561 | int mid = low + (high - low) / 2; | |
10562 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
10563 | high = mid; | |
10564 | else | |
10565 | low = mid + 1; | |
10566 | } | |
10567 | gdb_assert (low == high); | |
10568 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
10569 | { | |
10b3939b | 10570 | if (low == 0) |
8a3fe4f8 AC |
10571 | error (_("Dwarf Error: could not find partial DIE containing " |
10572 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
10573 | (long) offset, bfd_get_filename (objfile->obfd)); |
10574 | ||
ae038cb0 DJ |
10575 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
10576 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
10577 | } | |
10578 | else | |
10579 | { | |
10580 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
10581 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
10582 | && offset >= this_cu->offset + this_cu->length) | |
c764a876 | 10583 | error (_("invalid dwarf2 offset %u"), offset); |
ae038cb0 DJ |
10584 | gdb_assert (offset < this_cu->offset + this_cu->length); |
10585 | return this_cu; | |
10586 | } | |
10587 | } | |
10588 | ||
10b3939b DJ |
10589 | /* Locate the compilation unit from OBJFILE which is located at exactly |
10590 | OFFSET. Raises an error on failure. */ | |
10591 | ||
ae038cb0 | 10592 | static struct dwarf2_per_cu_data * |
c764a876 | 10593 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
ae038cb0 DJ |
10594 | { |
10595 | struct dwarf2_per_cu_data *this_cu; | |
10596 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
10597 | if (this_cu->offset != offset) | |
c764a876 | 10598 | error (_("no compilation unit with offset %u."), offset); |
ae038cb0 DJ |
10599 | return this_cu; |
10600 | } | |
10601 | ||
10602 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
10603 | of compilation units, but we don't remove it from the read_in_chain; | |
10604 | the caller is responsible for that. */ | |
10605 | ||
10606 | static void | |
10607 | free_one_comp_unit (void *data) | |
10608 | { | |
10609 | struct dwarf2_cu *cu = data; | |
10610 | ||
10611 | if (cu->per_cu != NULL) | |
10612 | cu->per_cu->cu = NULL; | |
10613 | cu->per_cu = NULL; | |
10614 | ||
10615 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10616 | ||
10617 | xfree (cu); | |
10618 | } | |
10619 | ||
72bf9492 | 10620 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
10621 | when we're finished with it. We can't free the pointer itself, but be |
10622 | sure to unlink it from the cache. Also release any associated storage | |
10623 | and perform cache maintenance. | |
72bf9492 DJ |
10624 | |
10625 | Only used during partial symbol parsing. */ | |
10626 | ||
10627 | static void | |
10628 | free_stack_comp_unit (void *data) | |
10629 | { | |
10630 | struct dwarf2_cu *cu = data; | |
10631 | ||
10632 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10633 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
10634 | |
10635 | if (cu->per_cu != NULL) | |
10636 | { | |
10637 | /* This compilation unit is on the stack in our caller, so we | |
10638 | should not xfree it. Just unlink it. */ | |
10639 | cu->per_cu->cu = NULL; | |
10640 | cu->per_cu = NULL; | |
10641 | ||
10642 | /* If we had a per-cu pointer, then we may have other compilation | |
10643 | units loaded, so age them now. */ | |
10644 | age_cached_comp_units (); | |
10645 | } | |
10646 | } | |
10647 | ||
10648 | /* Free all cached compilation units. */ | |
10649 | ||
10650 | static void | |
10651 | free_cached_comp_units (void *data) | |
10652 | { | |
10653 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10654 | ||
10655 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10656 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10657 | while (per_cu != NULL) | |
10658 | { | |
10659 | struct dwarf2_per_cu_data *next_cu; | |
10660 | ||
10661 | next_cu = per_cu->cu->read_in_chain; | |
10662 | ||
10663 | free_one_comp_unit (per_cu->cu); | |
10664 | *last_chain = next_cu; | |
10665 | ||
10666 | per_cu = next_cu; | |
10667 | } | |
10668 | } | |
10669 | ||
10670 | /* Increase the age counter on each cached compilation unit, and free | |
10671 | any that are too old. */ | |
10672 | ||
10673 | static void | |
10674 | age_cached_comp_units (void) | |
10675 | { | |
10676 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10677 | ||
10678 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
10679 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10680 | while (per_cu != NULL) | |
10681 | { | |
10682 | per_cu->cu->last_used ++; | |
10683 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
10684 | dwarf2_mark (per_cu->cu); | |
10685 | per_cu = per_cu->cu->read_in_chain; | |
10686 | } | |
10687 | ||
10688 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10689 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10690 | while (per_cu != NULL) | |
10691 | { | |
10692 | struct dwarf2_per_cu_data *next_cu; | |
10693 | ||
10694 | next_cu = per_cu->cu->read_in_chain; | |
10695 | ||
10696 | if (!per_cu->cu->mark) | |
10697 | { | |
10698 | free_one_comp_unit (per_cu->cu); | |
10699 | *last_chain = next_cu; | |
10700 | } | |
10701 | else | |
10702 | last_chain = &per_cu->cu->read_in_chain; | |
10703 | ||
10704 | per_cu = next_cu; | |
10705 | } | |
10706 | } | |
10707 | ||
10708 | /* Remove a single compilation unit from the cache. */ | |
10709 | ||
10710 | static void | |
10711 | free_one_cached_comp_unit (void *target_cu) | |
10712 | { | |
10713 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10714 | ||
10715 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10716 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10717 | while (per_cu != NULL) | |
10718 | { | |
10719 | struct dwarf2_per_cu_data *next_cu; | |
10720 | ||
10721 | next_cu = per_cu->cu->read_in_chain; | |
10722 | ||
10723 | if (per_cu->cu == target_cu) | |
10724 | { | |
10725 | free_one_comp_unit (per_cu->cu); | |
10726 | *last_chain = next_cu; | |
10727 | break; | |
10728 | } | |
10729 | else | |
10730 | last_chain = &per_cu->cu->read_in_chain; | |
10731 | ||
10732 | per_cu = next_cu; | |
10733 | } | |
10734 | } | |
10735 | ||
fe3e1990 DJ |
10736 | /* Release all extra memory associated with OBJFILE. */ |
10737 | ||
10738 | void | |
10739 | dwarf2_free_objfile (struct objfile *objfile) | |
10740 | { | |
10741 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10742 | ||
10743 | if (dwarf2_per_objfile == NULL) | |
10744 | return; | |
10745 | ||
10746 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
10747 | free_cached_comp_units (NULL); | |
10748 | ||
10749 | /* Everything else should be on the objfile obstack. */ | |
10750 | } | |
10751 | ||
1c379e20 DJ |
10752 | /* A pair of DIE offset and GDB type pointer. We store these |
10753 | in a hash table separate from the DIEs, and preserve them | |
10754 | when the DIEs are flushed out of cache. */ | |
10755 | ||
10756 | struct dwarf2_offset_and_type | |
10757 | { | |
10758 | unsigned int offset; | |
10759 | struct type *type; | |
10760 | }; | |
10761 | ||
10762 | /* Hash function for a dwarf2_offset_and_type. */ | |
10763 | ||
10764 | static hashval_t | |
10765 | offset_and_type_hash (const void *item) | |
10766 | { | |
10767 | const struct dwarf2_offset_and_type *ofs = item; | |
10768 | return ofs->offset; | |
10769 | } | |
10770 | ||
10771 | /* Equality function for a dwarf2_offset_and_type. */ | |
10772 | ||
10773 | static int | |
10774 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
10775 | { | |
10776 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
10777 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
10778 | return ofs_lhs->offset == ofs_rhs->offset; | |
10779 | } | |
10780 | ||
10781 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 10782 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 10783 | |
f792889a | 10784 | static struct type * |
1c379e20 DJ |
10785 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
10786 | { | |
10787 | struct dwarf2_offset_and_type **slot, ofs; | |
10788 | ||
f792889a DJ |
10789 | if (cu->type_hash == NULL) |
10790 | { | |
10791 | gdb_assert (cu->per_cu != NULL); | |
10792 | cu->per_cu->type_hash | |
10793 | = htab_create_alloc_ex (cu->header.length / 24, | |
10794 | offset_and_type_hash, | |
10795 | offset_and_type_eq, | |
10796 | NULL, | |
10797 | &cu->objfile->objfile_obstack, | |
10798 | hashtab_obstack_allocate, | |
10799 | dummy_obstack_deallocate); | |
10800 | cu->type_hash = cu->per_cu->type_hash; | |
10801 | } | |
1c379e20 DJ |
10802 | |
10803 | ofs.offset = die->offset; | |
10804 | ofs.type = type; | |
10805 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 10806 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
10807 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
10808 | **slot = ofs; | |
f792889a | 10809 | return type; |
1c379e20 DJ |
10810 | } |
10811 | ||
f792889a DJ |
10812 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
10813 | not have a saved type. */ | |
1c379e20 DJ |
10814 | |
10815 | static struct type * | |
f792889a | 10816 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
10817 | { |
10818 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
10819 | htab_t type_hash = cu->type_hash; |
10820 | ||
10821 | if (type_hash == NULL) | |
10822 | return NULL; | |
1c379e20 DJ |
10823 | |
10824 | ofs.offset = die->offset; | |
10825 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
10826 | if (slot) | |
10827 | return slot->type; | |
10828 | else | |
10829 | return NULL; | |
10830 | } | |
10831 | ||
10b3939b DJ |
10832 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
10833 | ||
10834 | static void | |
10835 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
10836 | struct dwarf2_per_cu_data *ref_per_cu) | |
10837 | { | |
10838 | void **slot; | |
10839 | ||
10840 | if (cu->dependencies == NULL) | |
10841 | cu->dependencies | |
10842 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
10843 | NULL, &cu->comp_unit_obstack, | |
10844 | hashtab_obstack_allocate, | |
10845 | dummy_obstack_deallocate); | |
10846 | ||
10847 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
10848 | if (*slot == NULL) | |
10849 | *slot = ref_per_cu; | |
10850 | } | |
1c379e20 | 10851 | |
f504f079 DE |
10852 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
10853 | Set the mark field in every compilation unit in the | |
ae038cb0 DJ |
10854 | cache that we must keep because we are keeping CU. */ |
10855 | ||
10b3939b DJ |
10856 | static int |
10857 | dwarf2_mark_helper (void **slot, void *data) | |
10858 | { | |
10859 | struct dwarf2_per_cu_data *per_cu; | |
10860 | ||
10861 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
10862 | if (per_cu->cu->mark) | |
10863 | return 1; | |
10864 | per_cu->cu->mark = 1; | |
10865 | ||
10866 | if (per_cu->cu->dependencies != NULL) | |
10867 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
10868 | ||
10869 | return 1; | |
10870 | } | |
10871 | ||
f504f079 DE |
10872 | /* Set the mark field in CU and in every other compilation unit in the |
10873 | cache that we must keep because we are keeping CU. */ | |
10874 | ||
ae038cb0 DJ |
10875 | static void |
10876 | dwarf2_mark (struct dwarf2_cu *cu) | |
10877 | { | |
10878 | if (cu->mark) | |
10879 | return; | |
10880 | cu->mark = 1; | |
10b3939b DJ |
10881 | if (cu->dependencies != NULL) |
10882 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
10883 | } |
10884 | ||
10885 | static void | |
10886 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
10887 | { | |
10888 | while (per_cu) | |
10889 | { | |
10890 | per_cu->cu->mark = 0; | |
10891 | per_cu = per_cu->cu->read_in_chain; | |
10892 | } | |
72bf9492 DJ |
10893 | } |
10894 | ||
72bf9492 DJ |
10895 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10896 | is its offset in .debug_info for this objfile. */ | |
10897 | ||
10898 | static hashval_t | |
10899 | partial_die_hash (const void *item) | |
10900 | { | |
10901 | const struct partial_die_info *part_die = item; | |
10902 | return part_die->offset; | |
10903 | } | |
10904 | ||
10905 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10906 | are equal if they have the same offset. */ | |
10907 | ||
10908 | static int | |
10909 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10910 | { | |
10911 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10912 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10913 | return part_die_lhs->offset == part_die_rhs->offset; | |
10914 | } | |
10915 | ||
ae038cb0 DJ |
10916 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10917 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10918 | ||
10919 | static void | |
10920 | set_dwarf2_cmd (char *args, int from_tty) | |
10921 | { | |
10922 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10923 | } | |
10924 | ||
10925 | static void | |
10926 | show_dwarf2_cmd (char *args, int from_tty) | |
10927 | { | |
10928 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10929 | } | |
10930 | ||
dce234bc PP |
10931 | /* If section described by INFO was mmapped, munmap it now. */ |
10932 | ||
10933 | static void | |
10934 | munmap_section_buffer (struct dwarf2_section_info *info) | |
10935 | { | |
10936 | if (info->was_mmapped) | |
10937 | { | |
10938 | #ifdef HAVE_MMAP | |
10939 | intptr_t begin = (intptr_t) info->buffer; | |
10940 | intptr_t map_begin = begin & ~(pagesize - 1); | |
10941 | size_t map_length = info->size + begin - map_begin; | |
10942 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); | |
10943 | #else | |
10944 | /* Without HAVE_MMAP, we should never be here to begin with. */ | |
10945 | gdb_assert (0); | |
10946 | #endif | |
10947 | } | |
10948 | } | |
10949 | ||
10950 | /* munmap debug sections for OBJFILE, if necessary. */ | |
10951 | ||
10952 | static void | |
10953 | dwarf2_per_objfile_cleanup (struct objfile *objfile, void *d) | |
10954 | { | |
10955 | struct dwarf2_per_objfile *data = d; | |
10956 | munmap_section_buffer (&data->info); | |
10957 | munmap_section_buffer (&data->abbrev); | |
10958 | munmap_section_buffer (&data->line); | |
10959 | munmap_section_buffer (&data->str); | |
10960 | munmap_section_buffer (&data->macinfo); | |
10961 | munmap_section_buffer (&data->ranges); | |
10962 | munmap_section_buffer (&data->loc); | |
10963 | munmap_section_buffer (&data->frame); | |
10964 | munmap_section_buffer (&data->eh_frame); | |
10965 | } | |
10966 | ||
6502dd73 DJ |
10967 | void _initialize_dwarf2_read (void); |
10968 | ||
10969 | void | |
10970 | _initialize_dwarf2_read (void) | |
10971 | { | |
dce234bc PP |
10972 | dwarf2_objfile_data_key |
10973 | = register_objfile_data_with_cleanup (dwarf2_per_objfile_cleanup); | |
ae038cb0 | 10974 | |
1bedd215 AC |
10975 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10976 | Set DWARF 2 specific variables.\n\ | |
10977 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10978 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10979 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10980 | ||
1bedd215 AC |
10981 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10982 | Show DWARF 2 specific variables\n\ | |
10983 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10984 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10985 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10986 | ||
10987 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10988 | &dwarf2_max_cache_age, _("\ |
10989 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10990 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10991 | A higher limit means that cached compilation units will be stored\n\ | |
10992 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10993 | caching, which can slow down startup."), | |
2c5b56ce | 10994 | NULL, |
920d2a44 | 10995 | show_dwarf2_max_cache_age, |
2c5b56ce | 10996 | &set_dwarf2_cmdlist, |
ae038cb0 | 10997 | &show_dwarf2_cmdlist); |
d97bc12b DE |
10998 | |
10999 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ | |
11000 | Set debugging of the dwarf2 DIE reader."), _("\ | |
11001 | Show debugging of the dwarf2 DIE reader."), _("\ | |
11002 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ | |
11003 | The value is the maximum depth to print."), | |
11004 | NULL, | |
11005 | NULL, | |
11006 | &setdebuglist, &showdebuglist); | |
6502dd73 | 11007 | } |