Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
6aba47ca | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
9b254dd1 | 4 | 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
7 | Inc. with support from Florida State University (under contract | |
8 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
9 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
10 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 11 | support. |
c906108c | 12 | |
c5aa993b | 13 | This file is part of GDB. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is free software; you can redistribute it and/or modify |
16 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
17 | the Free Software Foundation; either version 3 of the License, or |
18 | (at your option) any later version. | |
c906108c | 19 | |
a9762ec7 JB |
20 | This program is distributed in the hope that it will be useful, |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | GNU General Public License for more details. | |
c906108c | 24 | |
c5aa993b | 25 | You should have received a copy of the GNU General Public License |
a9762ec7 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
27 | |
28 | #include "defs.h" | |
29 | #include "bfd.h" | |
c906108c SS |
30 | #include "symtab.h" |
31 | #include "gdbtypes.h" | |
c906108c SS |
32 | #include "objfiles.h" |
33 | #include "elf/dwarf2.h" | |
34 | #include "buildsym.h" | |
35 | #include "demangle.h" | |
36 | #include "expression.h" | |
d5166ae1 | 37 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 38 | #include "macrotab.h" |
c906108c SS |
39 | #include "language.h" |
40 | #include "complaints.h" | |
357e46e7 | 41 | #include "bcache.h" |
4c2df51b DJ |
42 | #include "dwarf2expr.h" |
43 | #include "dwarf2loc.h" | |
9219021c | 44 | #include "cp-support.h" |
72bf9492 | 45 | #include "hashtab.h" |
ae038cb0 DJ |
46 | #include "command.h" |
47 | #include "gdbcmd.h" | |
ff013f42 | 48 | #include "addrmap.h" |
4c2df51b | 49 | |
c906108c SS |
50 | #include <fcntl.h> |
51 | #include "gdb_string.h" | |
4bdf3d34 | 52 | #include "gdb_assert.h" |
c906108c | 53 | #include <sys/types.h> |
233a11ab CS |
54 | #ifdef HAVE_ZLIB_H |
55 | #include <zlib.h> | |
56 | #endif | |
c906108c | 57 | |
d8151005 DJ |
58 | /* A note on memory usage for this file. |
59 | ||
60 | At the present time, this code reads the debug info sections into | |
61 | the objfile's objfile_obstack. A definite improvement for startup | |
62 | time, on platforms which do not emit relocations for debug | |
63 | sections, would be to use mmap instead. The object's complete | |
64 | debug information is loaded into memory, partly to simplify | |
65 | absolute DIE references. | |
66 | ||
67 | Whether using obstacks or mmap, the sections should remain loaded | |
68 | until the objfile is released, and pointers into the section data | |
69 | can be used for any other data associated to the objfile (symbol | |
70 | names, type names, location expressions to name a few). */ | |
71 | ||
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c SS |
88 | |
89 | /* .debug_pubnames header | |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct pubnames_header | |
93 | { | |
94 | unsigned int length; /* length of the .debug_pubnames | |
95 | contribution */ | |
96 | unsigned char version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int info_offset; /* offset into .debug_info section */ | |
99 | unsigned int info_size; /* byte size of .debug_info section | |
100 | portion */ | |
101 | } | |
102 | _PUBNAMES_HEADER; | |
103 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
104 | ||
105 | /* .debug_pubnames header | |
106 | Because of alignment constraints, this structure has padding and cannot | |
107 | be mapped directly onto the beginning of the .debug_info section. */ | |
108 | typedef struct aranges_header | |
109 | { | |
110 | unsigned int length; /* byte len of the .debug_aranges | |
111 | contribution */ | |
112 | unsigned short version; /* version number -- 2 for DWARF | |
113 | version 2 */ | |
114 | unsigned int info_offset; /* offset into .debug_info section */ | |
115 | unsigned char addr_size; /* byte size of an address */ | |
116 | unsigned char seg_size; /* byte size of segment descriptor */ | |
117 | } | |
118 | _ARANGES_HEADER; | |
119 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
120 | ||
121 | /* .debug_line statement program prologue | |
122 | Because of alignment constraints, this structure has padding and cannot | |
123 | be mapped directly onto the beginning of the .debug_info section. */ | |
124 | typedef struct statement_prologue | |
125 | { | |
126 | unsigned int total_length; /* byte length of the statement | |
127 | information */ | |
128 | unsigned short version; /* version number -- 2 for DWARF | |
129 | version 2 */ | |
130 | unsigned int prologue_length; /* # bytes between prologue & | |
131 | stmt program */ | |
132 | unsigned char minimum_instruction_length; /* byte size of | |
133 | smallest instr */ | |
134 | unsigned char default_is_stmt; /* initial value of is_stmt | |
135 | register */ | |
136 | char line_base; | |
137 | unsigned char line_range; | |
138 | unsigned char opcode_base; /* number assigned to first special | |
139 | opcode */ | |
140 | unsigned char *standard_opcode_lengths; | |
141 | } | |
142 | _STATEMENT_PROLOGUE; | |
143 | ||
6502dd73 DJ |
144 | static const struct objfile_data *dwarf2_objfile_data_key; |
145 | ||
146 | struct dwarf2_per_objfile | |
147 | { | |
148 | /* Sizes of debugging sections. */ | |
149 | unsigned int info_size; | |
150 | unsigned int abbrev_size; | |
151 | unsigned int line_size; | |
152 | unsigned int pubnames_size; | |
153 | unsigned int aranges_size; | |
154 | unsigned int loc_size; | |
155 | unsigned int macinfo_size; | |
156 | unsigned int str_size; | |
157 | unsigned int ranges_size; | |
158 | unsigned int frame_size; | |
159 | unsigned int eh_frame_size; | |
160 | ||
161 | /* Loaded data from the sections. */ | |
fe1b8b76 JB |
162 | gdb_byte *info_buffer; |
163 | gdb_byte *abbrev_buffer; | |
164 | gdb_byte *line_buffer; | |
165 | gdb_byte *str_buffer; | |
166 | gdb_byte *macinfo_buffer; | |
167 | gdb_byte *ranges_buffer; | |
168 | gdb_byte *loc_buffer; | |
ae038cb0 | 169 | |
10b3939b DJ |
170 | /* A list of all the compilation units. This is used to locate |
171 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
172 | struct dwarf2_per_cu_data **all_comp_units; |
173 | ||
174 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
175 | int n_comp_units; | |
176 | ||
177 | /* A chain of compilation units that are currently read in, so that | |
178 | they can be freed later. */ | |
179 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 FR |
180 | |
181 | /* A flag indicating wether this objfile has a section loaded at a | |
182 | VMA of 0. */ | |
183 | int has_section_at_zero; | |
6502dd73 DJ |
184 | }; |
185 | ||
186 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 187 | |
086df311 DJ |
188 | static asection *dwarf_info_section; |
189 | static asection *dwarf_abbrev_section; | |
190 | static asection *dwarf_line_section; | |
191 | static asection *dwarf_pubnames_section; | |
192 | static asection *dwarf_aranges_section; | |
193 | static asection *dwarf_loc_section; | |
194 | static asection *dwarf_macinfo_section; | |
195 | static asection *dwarf_str_section; | |
196 | static asection *dwarf_ranges_section; | |
197 | asection *dwarf_frame_section; | |
198 | asection *dwarf_eh_frame_section; | |
199 | ||
c906108c SS |
200 | /* names of the debugging sections */ |
201 | ||
233a11ab CS |
202 | /* Note that if the debugging section has been compressed, it might |
203 | have a name like .zdebug_info. */ | |
204 | ||
205 | #define INFO_SECTION "debug_info" | |
206 | #define ABBREV_SECTION "debug_abbrev" | |
207 | #define LINE_SECTION "debug_line" | |
208 | #define PUBNAMES_SECTION "debug_pubnames" | |
209 | #define ARANGES_SECTION "debug_aranges" | |
210 | #define LOC_SECTION "debug_loc" | |
211 | #define MACINFO_SECTION "debug_macinfo" | |
212 | #define STR_SECTION "debug_str" | |
213 | #define RANGES_SECTION "debug_ranges" | |
214 | #define FRAME_SECTION "debug_frame" | |
215 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
216 | |
217 | /* local data types */ | |
218 | ||
57349743 JB |
219 | /* We hold several abbreviation tables in memory at the same time. */ |
220 | #ifndef ABBREV_HASH_SIZE | |
221 | #define ABBREV_HASH_SIZE 121 | |
222 | #endif | |
223 | ||
107d2387 AC |
224 | /* The data in a compilation unit header, after target2host |
225 | translation, looks like this. */ | |
c906108c | 226 | struct comp_unit_head |
a738430d MK |
227 | { |
228 | unsigned long length; | |
229 | short version; | |
230 | unsigned int abbrev_offset; | |
231 | unsigned char addr_size; | |
232 | unsigned char signed_addr_p; | |
57349743 | 233 | |
a738430d MK |
234 | /* Size of file offsets; either 4 or 8. */ |
235 | unsigned int offset_size; | |
57349743 | 236 | |
a738430d MK |
237 | /* Size of the length field; either 4 or 12. */ |
238 | unsigned int initial_length_size; | |
57349743 | 239 | |
a738430d MK |
240 | /* Offset to the first byte of this compilation unit header in the |
241 | .debug_info section, for resolving relative reference dies. */ | |
242 | unsigned int offset; | |
57349743 | 243 | |
a738430d MK |
244 | /* Pointer to this compilation unit header in the .debug_info |
245 | section. */ | |
fe1b8b76 | 246 | gdb_byte *cu_head_ptr; |
57349743 | 247 | |
a738430d MK |
248 | /* Pointer to the first die of this compilation unit. This will be |
249 | the first byte following the compilation unit header. */ | |
fe1b8b76 | 250 | gdb_byte *first_die_ptr; |
af34e669 | 251 | |
a738430d MK |
252 | /* Pointer to the next compilation unit header in the program. */ |
253 | struct comp_unit_head *next; | |
0d53c4c4 | 254 | |
a738430d MK |
255 | /* Base address of this compilation unit. */ |
256 | CORE_ADDR base_address; | |
0d53c4c4 | 257 | |
a738430d MK |
258 | /* Non-zero if base_address has been set. */ |
259 | int base_known; | |
260 | }; | |
c906108c | 261 | |
e7c27a73 DJ |
262 | /* Internal state when decoding a particular compilation unit. */ |
263 | struct dwarf2_cu | |
264 | { | |
265 | /* The objfile containing this compilation unit. */ | |
266 | struct objfile *objfile; | |
267 | ||
268 | /* The header of the compilation unit. | |
269 | ||
270 | FIXME drow/2003-11-10: Some of the things from the comp_unit_head | |
f3dd6933 | 271 | should logically be moved to the dwarf2_cu structure. */ |
e7c27a73 | 272 | struct comp_unit_head header; |
e142c38c DJ |
273 | |
274 | struct function_range *first_fn, *last_fn, *cached_fn; | |
275 | ||
276 | /* The language we are debugging. */ | |
277 | enum language language; | |
278 | const struct language_defn *language_defn; | |
279 | ||
b0f35d58 DL |
280 | const char *producer; |
281 | ||
e142c38c DJ |
282 | /* The generic symbol table building routines have separate lists for |
283 | file scope symbols and all all other scopes (local scopes). So | |
284 | we need to select the right one to pass to add_symbol_to_list(). | |
285 | We do it by keeping a pointer to the correct list in list_in_scope. | |
286 | ||
287 | FIXME: The original dwarf code just treated the file scope as the | |
288 | first local scope, and all other local scopes as nested local | |
289 | scopes, and worked fine. Check to see if we really need to | |
290 | distinguish these in buildsym.c. */ | |
291 | struct pending **list_in_scope; | |
292 | ||
f3dd6933 DJ |
293 | /* DWARF abbreviation table associated with this compilation unit. */ |
294 | struct abbrev_info **dwarf2_abbrevs; | |
295 | ||
296 | /* Storage for the abbrev table. */ | |
297 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
298 | |
299 | /* Hash table holding all the loaded partial DIEs. */ | |
300 | htab_t partial_dies; | |
301 | ||
ff013f42 JK |
302 | /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */ |
303 | unsigned long ranges_offset; | |
304 | ||
72bf9492 DJ |
305 | /* Storage for things with the same lifetime as this read-in compilation |
306 | unit, including partial DIEs. */ | |
307 | struct obstack comp_unit_obstack; | |
308 | ||
ae038cb0 DJ |
309 | /* When multiple dwarf2_cu structures are living in memory, this field |
310 | chains them all together, so that they can be released efficiently. | |
311 | We will probably also want a generation counter so that most-recently-used | |
312 | compilation units are cached... */ | |
313 | struct dwarf2_per_cu_data *read_in_chain; | |
314 | ||
315 | /* Backchain to our per_cu entry if the tree has been built. */ | |
316 | struct dwarf2_per_cu_data *per_cu; | |
317 | ||
f792889a DJ |
318 | /* Pointer to the die -> type map. Although it is stored |
319 | permanently in per_cu, we copy it here to avoid double | |
320 | indirection. */ | |
321 | htab_t type_hash; | |
322 | ||
ae038cb0 DJ |
323 | /* How many compilation units ago was this CU last referenced? */ |
324 | int last_used; | |
325 | ||
10b3939b | 326 | /* A hash table of die offsets for following references. */ |
51545339 | 327 | htab_t die_hash; |
10b3939b DJ |
328 | |
329 | /* Full DIEs if read in. */ | |
330 | struct die_info *dies; | |
331 | ||
332 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
333 | units referenced by this one. Only set during full symbol processing; | |
334 | partial symbol tables do not have dependencies. */ | |
335 | htab_t dependencies; | |
336 | ||
cb1df416 DJ |
337 | /* Header data from the line table, during full symbol processing. */ |
338 | struct line_header *line_header; | |
339 | ||
ae038cb0 DJ |
340 | /* Mark used when releasing cached dies. */ |
341 | unsigned int mark : 1; | |
342 | ||
343 | /* This flag will be set if this compilation unit might include | |
344 | inter-compilation-unit references. */ | |
345 | unsigned int has_form_ref_addr : 1; | |
346 | ||
72bf9492 DJ |
347 | /* This flag will be set if this compilation unit includes any |
348 | DW_TAG_namespace DIEs. If we know that there are explicit | |
349 | DIEs for namespaces, we don't need to try to infer them | |
350 | from mangled names. */ | |
351 | unsigned int has_namespace_info : 1; | |
ff013f42 JK |
352 | |
353 | /* Field `ranges_offset' is filled in; flag as the value may be zero. */ | |
354 | unsigned int has_ranges_offset : 1; | |
e7c27a73 DJ |
355 | }; |
356 | ||
10b3939b DJ |
357 | /* Persistent data held for a compilation unit, even when not |
358 | processing it. We put a pointer to this structure in the | |
359 | read_symtab_private field of the psymtab. If we encounter | |
360 | inter-compilation-unit references, we also maintain a sorted | |
361 | list of all compilation units. */ | |
362 | ||
ae038cb0 DJ |
363 | struct dwarf2_per_cu_data |
364 | { | |
5afb4e99 | 365 | /* The start offset and length of this compilation unit. 2**30-1 |
ae038cb0 DJ |
366 | bytes should suffice to store the length of any compilation unit |
367 | - if it doesn't, GDB will fall over anyway. */ | |
368 | unsigned long offset; | |
5afb4e99 | 369 | unsigned long length : 30; |
ae038cb0 DJ |
370 | |
371 | /* Flag indicating this compilation unit will be read in before | |
372 | any of the current compilation units are processed. */ | |
373 | unsigned long queued : 1; | |
374 | ||
5afb4e99 DJ |
375 | /* This flag will be set if we need to load absolutely all DIEs |
376 | for this compilation unit, instead of just the ones we think | |
377 | are interesting. It gets set if we look for a DIE in the | |
378 | hash table and don't find it. */ | |
379 | unsigned int load_all_dies : 1; | |
380 | ||
ae038cb0 DJ |
381 | /* Set iff currently read in. */ |
382 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
383 | |
384 | /* If full symbols for this CU have been read in, then this field | |
385 | holds a map of DIE offsets to types. It isn't always possible | |
386 | to reconstruct this information later, so we have to preserve | |
387 | it. */ | |
1c379e20 | 388 | htab_t type_hash; |
10b3939b | 389 | |
31ffec48 DJ |
390 | /* The partial symbol table associated with this compilation unit, |
391 | or NULL for partial units (which do not have an associated | |
392 | symtab). */ | |
10b3939b | 393 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
394 | }; |
395 | ||
debd256d JB |
396 | /* The line number information for a compilation unit (found in the |
397 | .debug_line section) begins with a "statement program header", | |
398 | which contains the following information. */ | |
399 | struct line_header | |
400 | { | |
401 | unsigned int total_length; | |
402 | unsigned short version; | |
403 | unsigned int header_length; | |
404 | unsigned char minimum_instruction_length; | |
405 | unsigned char default_is_stmt; | |
406 | int line_base; | |
407 | unsigned char line_range; | |
408 | unsigned char opcode_base; | |
409 | ||
410 | /* standard_opcode_lengths[i] is the number of operands for the | |
411 | standard opcode whose value is i. This means that | |
412 | standard_opcode_lengths[0] is unused, and the last meaningful | |
413 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
414 | unsigned char *standard_opcode_lengths; | |
415 | ||
416 | /* The include_directories table. NOTE! These strings are not | |
417 | allocated with xmalloc; instead, they are pointers into | |
418 | debug_line_buffer. If you try to free them, `free' will get | |
419 | indigestion. */ | |
420 | unsigned int num_include_dirs, include_dirs_size; | |
421 | char **include_dirs; | |
422 | ||
423 | /* The file_names table. NOTE! These strings are not allocated | |
424 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
425 | Don't try to free them directly. */ | |
426 | unsigned int num_file_names, file_names_size; | |
427 | struct file_entry | |
c906108c | 428 | { |
debd256d JB |
429 | char *name; |
430 | unsigned int dir_index; | |
431 | unsigned int mod_time; | |
432 | unsigned int length; | |
aaa75496 | 433 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 434 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
435 | } *file_names; |
436 | ||
437 | /* The start and end of the statement program following this | |
6502dd73 | 438 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 439 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 440 | }; |
c906108c SS |
441 | |
442 | /* When we construct a partial symbol table entry we only | |
443 | need this much information. */ | |
444 | struct partial_die_info | |
445 | { | |
72bf9492 | 446 | /* Offset of this DIE. */ |
c906108c | 447 | unsigned int offset; |
72bf9492 DJ |
448 | |
449 | /* DWARF-2 tag for this DIE. */ | |
450 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
451 | ||
452 | /* Language code associated with this DIE. This is only used | |
453 | for the compilation unit DIE. */ | |
454 | unsigned int language : 8; | |
455 | ||
456 | /* Assorted flags describing the data found in this DIE. */ | |
457 | unsigned int has_children : 1; | |
458 | unsigned int is_external : 1; | |
459 | unsigned int is_declaration : 1; | |
460 | unsigned int has_type : 1; | |
461 | unsigned int has_specification : 1; | |
aaa75496 | 462 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
463 | unsigned int has_pc_info : 1; |
464 | ||
465 | /* Flag set if the SCOPE field of this structure has been | |
466 | computed. */ | |
467 | unsigned int scope_set : 1; | |
468 | ||
fa4028e9 JB |
469 | /* Flag set if the DIE has a byte_size attribute. */ |
470 | unsigned int has_byte_size : 1; | |
471 | ||
72bf9492 DJ |
472 | /* The name of this DIE. Normally the value of DW_AT_name, but |
473 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
474 | other fashion. */ | |
c906108c | 475 | char *name; |
57c22c6c | 476 | char *dirname; |
72bf9492 DJ |
477 | |
478 | /* The scope to prepend to our children. This is generally | |
479 | allocated on the comp_unit_obstack, so will disappear | |
480 | when this compilation unit leaves the cache. */ | |
481 | char *scope; | |
482 | ||
483 | /* The location description associated with this DIE, if any. */ | |
484 | struct dwarf_block *locdesc; | |
485 | ||
486 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
487 | CORE_ADDR lowpc; |
488 | CORE_ADDR highpc; | |
72bf9492 DJ |
489 | |
490 | /* Pointer into the info_buffer pointing at the target of | |
491 | DW_AT_sibling, if any. */ | |
fe1b8b76 | 492 | gdb_byte *sibling; |
72bf9492 DJ |
493 | |
494 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
495 | DW_AT_specification (or DW_AT_abstract_origin or | |
496 | DW_AT_extension). */ | |
497 | unsigned int spec_offset; | |
498 | ||
aaa75496 JB |
499 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
500 | unsigned int line_offset; | |
501 | ||
72bf9492 DJ |
502 | /* Pointers to this DIE's parent, first child, and next sibling, |
503 | if any. */ | |
504 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
505 | }; |
506 | ||
507 | /* This data structure holds the information of an abbrev. */ | |
508 | struct abbrev_info | |
509 | { | |
510 | unsigned int number; /* number identifying abbrev */ | |
511 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
512 | unsigned short has_children; /* boolean */ |
513 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
514 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
515 | struct abbrev_info *next; /* next in chain */ | |
516 | }; | |
517 | ||
518 | struct attr_abbrev | |
519 | { | |
520 | enum dwarf_attribute name; | |
521 | enum dwarf_form form; | |
522 | }; | |
523 | ||
b60c80d6 DJ |
524 | /* Attributes have a name and a value */ |
525 | struct attribute | |
526 | { | |
527 | enum dwarf_attribute name; | |
528 | enum dwarf_form form; | |
529 | union | |
530 | { | |
531 | char *str; | |
532 | struct dwarf_block *blk; | |
533 | unsigned long unsnd; | |
534 | long int snd; | |
535 | CORE_ADDR addr; | |
536 | } | |
537 | u; | |
538 | }; | |
539 | ||
c906108c SS |
540 | /* This data structure holds a complete die structure. */ |
541 | struct die_info | |
542 | { | |
c5aa993b | 543 | enum dwarf_tag tag; /* Tag indicating type of die */ |
c5aa993b JM |
544 | unsigned int abbrev; /* Abbrev number */ |
545 | unsigned int offset; /* Offset in .debug_info section */ | |
546 | unsigned int num_attrs; /* Number of attributes */ | |
78ba4af6 JB |
547 | |
548 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
549 | points to this die's parent; CHILD points to the first child of | |
550 | this node; and all the children of a given node are chained | |
551 | together via their SIBLING fields, terminated by a die whose | |
552 | tag is zero. */ | |
639d11d3 DC |
553 | struct die_info *child; /* Its first child, if any. */ |
554 | struct die_info *sibling; /* Its next sibling, if any. */ | |
555 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c | 556 | |
b60c80d6 DJ |
557 | /* An array of attributes, with NUM_ATTRS elements. There may be |
558 | zero, but it's not common and zero-sized arrays are not | |
559 | sufficiently portable C. */ | |
560 | struct attribute attrs[1]; | |
c906108c SS |
561 | }; |
562 | ||
5fb290d7 DJ |
563 | struct function_range |
564 | { | |
565 | const char *name; | |
566 | CORE_ADDR lowpc, highpc; | |
567 | int seen_line; | |
568 | struct function_range *next; | |
569 | }; | |
570 | ||
c906108c SS |
571 | /* Get at parts of an attribute structure */ |
572 | ||
573 | #define DW_STRING(attr) ((attr)->u.str) | |
574 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
575 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
576 | #define DW_SND(attr) ((attr)->u.snd) | |
577 | #define DW_ADDR(attr) ((attr)->u.addr) | |
578 | ||
579 | /* Blocks are a bunch of untyped bytes. */ | |
580 | struct dwarf_block | |
581 | { | |
582 | unsigned int size; | |
fe1b8b76 | 583 | gdb_byte *data; |
c906108c SS |
584 | }; |
585 | ||
c906108c SS |
586 | #ifndef ATTR_ALLOC_CHUNK |
587 | #define ATTR_ALLOC_CHUNK 4 | |
588 | #endif | |
589 | ||
c906108c SS |
590 | /* Allocate fields for structs, unions and enums in this size. */ |
591 | #ifndef DW_FIELD_ALLOC_CHUNK | |
592 | #define DW_FIELD_ALLOC_CHUNK 4 | |
593 | #endif | |
594 | ||
c906108c SS |
595 | /* A zeroed version of a partial die for initialization purposes. */ |
596 | static struct partial_die_info zeroed_partial_die; | |
597 | ||
c906108c SS |
598 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
599 | but this would require a corresponding change in unpack_field_as_long | |
600 | and friends. */ | |
601 | static int bits_per_byte = 8; | |
602 | ||
603 | /* The routines that read and process dies for a C struct or C++ class | |
604 | pass lists of data member fields and lists of member function fields | |
605 | in an instance of a field_info structure, as defined below. */ | |
606 | struct field_info | |
c5aa993b JM |
607 | { |
608 | /* List of data member and baseclasses fields. */ | |
609 | struct nextfield | |
610 | { | |
611 | struct nextfield *next; | |
612 | int accessibility; | |
613 | int virtuality; | |
614 | struct field field; | |
615 | } | |
616 | *fields; | |
c906108c | 617 | |
c5aa993b JM |
618 | /* Number of fields. */ |
619 | int nfields; | |
c906108c | 620 | |
c5aa993b JM |
621 | /* Number of baseclasses. */ |
622 | int nbaseclasses; | |
c906108c | 623 | |
c5aa993b JM |
624 | /* Set if the accesibility of one of the fields is not public. */ |
625 | int non_public_fields; | |
c906108c | 626 | |
c5aa993b JM |
627 | /* Member function fields array, entries are allocated in the order they |
628 | are encountered in the object file. */ | |
629 | struct nextfnfield | |
630 | { | |
631 | struct nextfnfield *next; | |
632 | struct fn_field fnfield; | |
633 | } | |
634 | *fnfields; | |
c906108c | 635 | |
c5aa993b JM |
636 | /* Member function fieldlist array, contains name of possibly overloaded |
637 | member function, number of overloaded member functions and a pointer | |
638 | to the head of the member function field chain. */ | |
639 | struct fnfieldlist | |
640 | { | |
641 | char *name; | |
642 | int length; | |
643 | struct nextfnfield *head; | |
644 | } | |
645 | *fnfieldlists; | |
c906108c | 646 | |
c5aa993b JM |
647 | /* Number of entries in the fnfieldlists array. */ |
648 | int nfnfields; | |
649 | }; | |
c906108c | 650 | |
10b3939b DJ |
651 | /* One item on the queue of compilation units to read in full symbols |
652 | for. */ | |
653 | struct dwarf2_queue_item | |
654 | { | |
655 | struct dwarf2_per_cu_data *per_cu; | |
656 | struct dwarf2_queue_item *next; | |
657 | }; | |
658 | ||
659 | /* The current queue. */ | |
660 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
661 | ||
ae038cb0 DJ |
662 | /* Loaded secondary compilation units are kept in memory until they |
663 | have not been referenced for the processing of this many | |
664 | compilation units. Set this to zero to disable caching. Cache | |
665 | sizes of up to at least twenty will improve startup time for | |
666 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
667 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
668 | static void |
669 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
670 | struct cmd_list_element *c, const char *value) | |
671 | { | |
672 | fprintf_filtered (file, _("\ | |
673 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
674 | value); | |
675 | } | |
676 | ||
ae038cb0 | 677 | |
c906108c SS |
678 | /* Various complaints about symbol reading that don't abort the process */ |
679 | ||
4d3c2250 KB |
680 | static void |
681 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 682 | { |
4d3c2250 | 683 | complaint (&symfile_complaints, |
e2e0b3e5 | 684 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
685 | } |
686 | ||
25e43795 DJ |
687 | static void |
688 | dwarf2_debug_line_missing_file_complaint (void) | |
689 | { | |
690 | complaint (&symfile_complaints, | |
691 | _(".debug_line section has line data without a file")); | |
692 | } | |
693 | ||
4d3c2250 KB |
694 | static void |
695 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 696 | { |
e2e0b3e5 | 697 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
698 | } |
699 | ||
4d3c2250 KB |
700 | static void |
701 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
702 | int arg3) | |
2e276125 | 703 | { |
4d3c2250 | 704 | complaint (&symfile_complaints, |
e2e0b3e5 | 705 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
706 | arg2, arg3); |
707 | } | |
708 | ||
709 | static void | |
710 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 711 | { |
4d3c2250 | 712 | complaint (&symfile_complaints, |
e2e0b3e5 | 713 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
714 | } |
715 | ||
716 | static void | |
717 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 718 | { |
4d3c2250 | 719 | complaint (&symfile_complaints, |
e2e0b3e5 | 720 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
721 | arg1); |
722 | } | |
723 | ||
724 | static void | |
725 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 726 | { |
4d3c2250 | 727 | complaint (&symfile_complaints, |
e2e0b3e5 | 728 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 729 | } |
c906108c | 730 | |
c906108c SS |
731 | /* local function prototypes */ |
732 | ||
4efb68b1 | 733 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
734 | |
735 | #if 0 | |
a14ed312 | 736 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
737 | #endif |
738 | ||
aaa75496 JB |
739 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
740 | struct objfile *); | |
741 | ||
742 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
743 | struct partial_die_info *, | |
744 | struct partial_symtab *); | |
745 | ||
a14ed312 | 746 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 747 | |
72bf9492 DJ |
748 | static void scan_partial_symbols (struct partial_die_info *, |
749 | CORE_ADDR *, CORE_ADDR *, | |
750 | struct dwarf2_cu *); | |
c906108c | 751 | |
72bf9492 DJ |
752 | static void add_partial_symbol (struct partial_die_info *, |
753 | struct dwarf2_cu *); | |
63d06c5c | 754 | |
72bf9492 | 755 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 756 | |
72bf9492 DJ |
757 | static void add_partial_namespace (struct partial_die_info *pdi, |
758 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
759 | struct dwarf2_cu *cu); | |
63d06c5c | 760 | |
72bf9492 DJ |
761 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
762 | struct dwarf2_cu *cu); | |
91c24f0a | 763 | |
fe1b8b76 JB |
764 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
765 | gdb_byte *info_ptr, | |
766 | bfd *abfd, | |
767 | struct dwarf2_cu *cu); | |
91c24f0a | 768 | |
a14ed312 | 769 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 770 | |
a14ed312 | 771 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 772 | |
fe1b8b76 | 773 | gdb_byte *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 774 | |
e7c27a73 | 775 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 776 | |
f3dd6933 | 777 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 778 | |
fe1b8b76 | 779 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 780 | struct dwarf2_cu *); |
72bf9492 | 781 | |
57349743 | 782 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 783 | struct dwarf2_cu *); |
c906108c | 784 | |
fe1b8b76 | 785 | static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int, |
72bf9492 DJ |
786 | struct dwarf2_cu *); |
787 | ||
fe1b8b76 JB |
788 | static gdb_byte *read_partial_die (struct partial_die_info *, |
789 | struct abbrev_info *abbrev, unsigned int, | |
790 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 791 | |
72bf9492 | 792 | static struct partial_die_info *find_partial_die (unsigned long, |
10b3939b | 793 | struct dwarf2_cu *); |
72bf9492 DJ |
794 | |
795 | static void fixup_partial_die (struct partial_die_info *, | |
796 | struct dwarf2_cu *); | |
797 | ||
fe1b8b76 JB |
798 | static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *, |
799 | struct dwarf2_cu *, int *); | |
c906108c | 800 | |
fe1b8b76 JB |
801 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
802 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 803 | |
fe1b8b76 JB |
804 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
805 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 806 | |
fe1b8b76 | 807 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 808 | |
fe1b8b76 | 809 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 810 | |
fe1b8b76 | 811 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 812 | |
fe1b8b76 | 813 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 814 | |
fe1b8b76 | 815 | static unsigned long read_8_bytes (bfd *, gdb_byte *); |
c906108c | 816 | |
fe1b8b76 | 817 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 818 | unsigned int *); |
c906108c | 819 | |
fe1b8b76 | 820 | static LONGEST read_initial_length (bfd *, gdb_byte *, |
891d2f0b | 821 | struct comp_unit_head *, unsigned int *); |
613e1657 | 822 | |
fe1b8b76 | 823 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
891d2f0b | 824 | unsigned int *); |
613e1657 | 825 | |
fe1b8b76 | 826 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 827 | |
fe1b8b76 | 828 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 829 | |
fe1b8b76 JB |
830 | static char *read_indirect_string (bfd *, gdb_byte *, |
831 | const struct comp_unit_head *, | |
832 | unsigned int *); | |
4bdf3d34 | 833 | |
fe1b8b76 | 834 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 835 | |
fe1b8b76 | 836 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 837 | |
fe1b8b76 | 838 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 839 | |
e142c38c | 840 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 841 | |
e142c38c DJ |
842 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
843 | struct dwarf2_cu *); | |
c906108c | 844 | |
05cf31d1 JB |
845 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
846 | struct dwarf2_cu *cu); | |
847 | ||
e142c38c | 848 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 849 | |
e142c38c | 850 | static struct die_info *die_specification (struct die_info *die, |
f2f0e013 | 851 | struct dwarf2_cu **); |
63d06c5c | 852 | |
debd256d JB |
853 | static void free_line_header (struct line_header *lh); |
854 | ||
aaa75496 JB |
855 | static void add_file_name (struct line_header *, char *, unsigned int, |
856 | unsigned int, unsigned int); | |
857 | ||
debd256d JB |
858 | static struct line_header *(dwarf_decode_line_header |
859 | (unsigned int offset, | |
e7c27a73 | 860 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
861 | |
862 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 863 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 864 | |
4f1520fb | 865 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 866 | |
a14ed312 | 867 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 868 | struct dwarf2_cu *); |
c906108c | 869 | |
a14ed312 | 870 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 871 | struct dwarf2_cu *); |
c906108c | 872 | |
2df3850c JM |
873 | static void dwarf2_const_value_data (struct attribute *attr, |
874 | struct symbol *sym, | |
875 | int bits); | |
876 | ||
e7c27a73 | 877 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 878 | |
e7c27a73 DJ |
879 | static struct type *die_containing_type (struct die_info *, |
880 | struct dwarf2_cu *); | |
c906108c | 881 | |
e7c27a73 | 882 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 883 | |
f792889a | 884 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 885 | |
086ed43d | 886 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 887 | |
fe1b8b76 JB |
888 | static char *typename_concat (struct obstack *, |
889 | const char *prefix, | |
890 | const char *suffix, | |
987504bb | 891 | struct dwarf2_cu *); |
63d06c5c | 892 | |
e7c27a73 | 893 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 894 | |
e7c27a73 | 895 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 896 | |
e7c27a73 | 897 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 898 | |
ff013f42 JK |
899 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
900 | struct dwarf2_cu *, struct partial_symtab *); | |
901 | ||
a14ed312 | 902 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 903 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 904 | |
fae299cd DC |
905 | static void get_scope_pc_bounds (struct die_info *, |
906 | CORE_ADDR *, CORE_ADDR *, | |
907 | struct dwarf2_cu *); | |
908 | ||
801e3a5b JB |
909 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
910 | CORE_ADDR, struct dwarf2_cu *); | |
911 | ||
a14ed312 | 912 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 913 | struct dwarf2_cu *); |
c906108c | 914 | |
a14ed312 | 915 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 916 | struct type *, struct dwarf2_cu *); |
c906108c | 917 | |
a14ed312 | 918 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 919 | struct die_info *, struct type *, |
e7c27a73 | 920 | struct dwarf2_cu *); |
c906108c | 921 | |
a14ed312 | 922 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 923 | struct type *, struct dwarf2_cu *); |
c906108c | 924 | |
134d01f1 | 925 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 926 | |
8176b9b8 DC |
927 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); |
928 | ||
e7c27a73 | 929 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 930 | |
e7c27a73 | 931 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 932 | |
38d518c9 | 933 | static const char *namespace_name (struct die_info *die, |
e142c38c | 934 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 935 | |
134d01f1 | 936 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 937 | |
e7c27a73 | 938 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 939 | |
7ca2d3a3 DL |
940 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
941 | struct dwarf2_cu *); | |
942 | ||
fe1b8b76 | 943 | static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *); |
c906108c | 944 | |
fe1b8b76 | 945 | static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 946 | struct dwarf2_cu *, |
fe1b8b76 | 947 | gdb_byte **new_info_ptr, |
639d11d3 DC |
948 | struct die_info *parent); |
949 | ||
fe1b8b76 | 950 | static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 951 | struct dwarf2_cu *, |
fe1b8b76 | 952 | gdb_byte **new_info_ptr, |
639d11d3 DC |
953 | struct die_info *parent); |
954 | ||
e7c27a73 | 955 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 956 | |
e142c38c | 957 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 958 | |
e142c38c | 959 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 960 | |
e142c38c | 961 | static struct die_info *dwarf2_extension (struct die_info *die, |
f2f0e013 | 962 | struct dwarf2_cu **); |
9219021c | 963 | |
a14ed312 | 964 | static char *dwarf_tag_name (unsigned int); |
c906108c | 965 | |
a14ed312 | 966 | static char *dwarf_attr_name (unsigned int); |
c906108c | 967 | |
a14ed312 | 968 | static char *dwarf_form_name (unsigned int); |
c906108c | 969 | |
a14ed312 | 970 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 971 | |
a14ed312 | 972 | static char *dwarf_bool_name (unsigned int); |
c906108c | 973 | |
a14ed312 | 974 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
975 | |
976 | #if 0 | |
a14ed312 | 977 | static char *dwarf_cfi_name (unsigned int); |
c906108c SS |
978 | #endif |
979 | ||
f9aca02d | 980 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 981 | |
f9aca02d | 982 | static void dump_die (struct die_info *); |
c906108c | 983 | |
f9aca02d | 984 | static void dump_die_list (struct die_info *); |
c906108c | 985 | |
51545339 | 986 | static void store_in_ref_table (struct die_info *, |
10b3939b | 987 | struct dwarf2_cu *); |
c906108c | 988 | |
e142c38c DJ |
989 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, |
990 | struct dwarf2_cu *); | |
c906108c | 991 | |
a02abb62 JB |
992 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
993 | ||
10b3939b DJ |
994 | static struct die_info *follow_die_ref (struct die_info *, |
995 | struct attribute *, | |
f2f0e013 | 996 | struct dwarf2_cu **); |
c906108c | 997 | |
c906108c SS |
998 | /* memory allocation interface */ |
999 | ||
7b5a2f43 | 1000 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1001 | |
f3dd6933 | 1002 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1003 | |
b60c80d6 | 1004 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
c906108c | 1005 | |
e142c38c | 1006 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1007 | |
e142c38c DJ |
1008 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1009 | struct dwarf2_cu *); | |
5fb290d7 | 1010 | |
2e276125 | 1011 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1012 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1013 | |
8e19ed76 PS |
1014 | static int attr_form_is_block (struct attribute *); |
1015 | ||
3690dd37 JB |
1016 | static int attr_form_is_section_offset (struct attribute *); |
1017 | ||
1018 | static int attr_form_is_constant (struct attribute *); | |
1019 | ||
93e7bd98 DJ |
1020 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1021 | struct symbol *sym, | |
1022 | struct dwarf2_cu *cu); | |
4c2df51b | 1023 | |
fe1b8b76 JB |
1024 | static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, |
1025 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1026 | |
72bf9492 DJ |
1027 | static void free_stack_comp_unit (void *); |
1028 | ||
72bf9492 DJ |
1029 | static hashval_t partial_die_hash (const void *item); |
1030 | ||
1031 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1032 | ||
ae038cb0 DJ |
1033 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
1034 | (unsigned long offset, struct objfile *objfile); | |
1035 | ||
1036 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
1037 | (unsigned long offset, struct objfile *objfile); | |
1038 | ||
1039 | static void free_one_comp_unit (void *); | |
1040 | ||
1041 | static void free_cached_comp_units (void *); | |
1042 | ||
1043 | static void age_cached_comp_units (void); | |
1044 | ||
1045 | static void free_one_cached_comp_unit (void *); | |
1046 | ||
f792889a DJ |
1047 | static struct type *set_die_type (struct die_info *, struct type *, |
1048 | struct dwarf2_cu *); | |
1c379e20 | 1049 | |
ae038cb0 DJ |
1050 | static void create_all_comp_units (struct objfile *); |
1051 | ||
31ffec48 DJ |
1052 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *, |
1053 | struct objfile *); | |
10b3939b DJ |
1054 | |
1055 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1056 | ||
1057 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1058 | struct dwarf2_per_cu_data *); | |
1059 | ||
ae038cb0 DJ |
1060 | static void dwarf2_mark (struct dwarf2_cu *); |
1061 | ||
1062 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1063 | ||
f792889a | 1064 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1065 | |
c906108c SS |
1066 | /* Try to locate the sections we need for DWARF 2 debugging |
1067 | information and return true if we have enough to do something. */ | |
1068 | ||
1069 | int | |
6502dd73 | 1070 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1071 | { |
6502dd73 DJ |
1072 | struct dwarf2_per_objfile *data; |
1073 | ||
1074 | /* Initialize per-objfile state. */ | |
1075 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1076 | memset (data, 0, sizeof (*data)); | |
1077 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1078 | dwarf2_per_objfile = data; | |
1079 | ||
188dd5d6 DJ |
1080 | dwarf_info_section = 0; |
1081 | dwarf_abbrev_section = 0; | |
1082 | dwarf_line_section = 0; | |
1083 | dwarf_str_section = 0; | |
1084 | dwarf_macinfo_section = 0; | |
1085 | dwarf_frame_section = 0; | |
1086 | dwarf_eh_frame_section = 0; | |
1087 | dwarf_ranges_section = 0; | |
1088 | dwarf_loc_section = 0; | |
af34e669 | 1089 | |
6502dd73 | 1090 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 1091 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
1092 | } |
1093 | ||
233a11ab CS |
1094 | /* When loading sections, we can either look for ".<name>", or for |
1095 | * ".z<name>", which indicates a compressed section. */ | |
1096 | ||
1097 | static int | |
1098 | section_is_p (asection *sectp, const char *name) | |
1099 | { | |
1100 | return ((sectp->name[0] == '.' | |
1101 | && strcmp (sectp->name + 1, name) == 0) | |
1102 | || (sectp->name[0] == '.' && sectp->name[1] == 'z' | |
1103 | && strcmp (sectp->name + 2, name) == 0)); | |
1104 | } | |
1105 | ||
c906108c SS |
1106 | /* This function is mapped across the sections and remembers the |
1107 | offset and size of each of the debugging sections we are interested | |
1108 | in. */ | |
1109 | ||
1110 | static void | |
72dca2f5 | 1111 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1112 | { |
233a11ab | 1113 | if (section_is_p (sectp, INFO_SECTION)) |
c906108c | 1114 | { |
2c500098 | 1115 | dwarf2_per_objfile->info_size = bfd_get_section_size (sectp); |
086df311 | 1116 | dwarf_info_section = sectp; |
c906108c | 1117 | } |
233a11ab | 1118 | else if (section_is_p (sectp, ABBREV_SECTION)) |
c906108c | 1119 | { |
2c500098 | 1120 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp); |
086df311 | 1121 | dwarf_abbrev_section = sectp; |
c906108c | 1122 | } |
233a11ab | 1123 | else if (section_is_p (sectp, LINE_SECTION)) |
c906108c | 1124 | { |
2c500098 | 1125 | dwarf2_per_objfile->line_size = bfd_get_section_size (sectp); |
086df311 | 1126 | dwarf_line_section = sectp; |
c906108c | 1127 | } |
233a11ab | 1128 | else if (section_is_p (sectp, PUBNAMES_SECTION)) |
c906108c | 1129 | { |
2c500098 | 1130 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp); |
086df311 | 1131 | dwarf_pubnames_section = sectp; |
c906108c | 1132 | } |
233a11ab | 1133 | else if (section_is_p (sectp, ARANGES_SECTION)) |
c906108c | 1134 | { |
2c500098 | 1135 | dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp); |
086df311 | 1136 | dwarf_aranges_section = sectp; |
c906108c | 1137 | } |
233a11ab | 1138 | else if (section_is_p (sectp, LOC_SECTION)) |
c906108c | 1139 | { |
2c500098 | 1140 | dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp); |
086df311 | 1141 | dwarf_loc_section = sectp; |
c906108c | 1142 | } |
233a11ab | 1143 | else if (section_is_p (sectp, MACINFO_SECTION)) |
c906108c | 1144 | { |
2c500098 | 1145 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp); |
0cf824c9 | 1146 | dwarf_macinfo_section = sectp; |
c906108c | 1147 | } |
233a11ab | 1148 | else if (section_is_p (sectp, STR_SECTION)) |
c906108c | 1149 | { |
2c500098 | 1150 | dwarf2_per_objfile->str_size = bfd_get_section_size (sectp); |
086df311 | 1151 | dwarf_str_section = sectp; |
c906108c | 1152 | } |
233a11ab | 1153 | else if (section_is_p (sectp, FRAME_SECTION)) |
b6af0555 | 1154 | { |
2c500098 | 1155 | dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp); |
086df311 | 1156 | dwarf_frame_section = sectp; |
b6af0555 | 1157 | } |
233a11ab | 1158 | else if (section_is_p (sectp, EH_FRAME_SECTION)) |
b6af0555 | 1159 | { |
3799ccc6 EZ |
1160 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1161 | if (aflag & SEC_HAS_CONTENTS) | |
1162 | { | |
2c500098 | 1163 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp); |
3799ccc6 EZ |
1164 | dwarf_eh_frame_section = sectp; |
1165 | } | |
b6af0555 | 1166 | } |
233a11ab | 1167 | else if (section_is_p (sectp, RANGES_SECTION)) |
af34e669 | 1168 | { |
2c500098 | 1169 | dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp); |
6f10aeb1 | 1170 | dwarf_ranges_section = sectp; |
af34e669 | 1171 | } |
72dca2f5 FR |
1172 | |
1173 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) | |
1174 | && bfd_section_vma (abfd, sectp) == 0) | |
1175 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1176 | } |
1177 | ||
233a11ab CS |
1178 | /* This function is called after decompressing a section, so |
1179 | dwarf2_per_objfile can record its new, uncompressed size. */ | |
1180 | ||
1181 | static void | |
1182 | dwarf2_resize_section (asection *sectp, bfd_size_type new_size) | |
1183 | { | |
1184 | if (section_is_p (sectp, INFO_SECTION)) | |
1185 | dwarf2_per_objfile->info_size = new_size; | |
1186 | else if (section_is_p (sectp, ABBREV_SECTION)) | |
1187 | dwarf2_per_objfile->abbrev_size = new_size; | |
1188 | else if (section_is_p (sectp, LINE_SECTION)) | |
1189 | dwarf2_per_objfile->line_size = new_size; | |
1190 | else if (section_is_p (sectp, PUBNAMES_SECTION)) | |
1191 | dwarf2_per_objfile->pubnames_size = new_size; | |
1192 | else if (section_is_p (sectp, ARANGES_SECTION)) | |
1193 | dwarf2_per_objfile->aranges_size = new_size; | |
1194 | else if (section_is_p (sectp, LOC_SECTION)) | |
1195 | dwarf2_per_objfile->loc_size = new_size; | |
1196 | else if (section_is_p (sectp, MACINFO_SECTION)) | |
1197 | dwarf2_per_objfile->macinfo_size = new_size; | |
1198 | else if (section_is_p (sectp, STR_SECTION)) | |
1199 | dwarf2_per_objfile->str_size = new_size; | |
1200 | else if (section_is_p (sectp, FRAME_SECTION)) | |
1201 | dwarf2_per_objfile->frame_size = new_size; | |
1202 | else if (section_is_p (sectp, EH_FRAME_SECTION)) | |
1203 | dwarf2_per_objfile->eh_frame_size = new_size; | |
1204 | else if (section_is_p (sectp, RANGES_SECTION)) | |
1205 | dwarf2_per_objfile->ranges_size = new_size; | |
1206 | else | |
1207 | internal_error (__FILE__, __LINE__, | |
1208 | _("dwarf2_resize_section: missing section_is_p check: %s"), | |
1209 | sectp->name); | |
1210 | } | |
1211 | ||
c906108c SS |
1212 | /* Build a partial symbol table. */ |
1213 | ||
1214 | void | |
fba45db2 | 1215 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1216 | { |
c906108c SS |
1217 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1218 | ||
6502dd73 DJ |
1219 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1220 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1221 | |
1222 | if (dwarf_line_section) | |
6502dd73 | 1223 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1224 | else |
6502dd73 | 1225 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1226 | |
188dd5d6 | 1227 | if (dwarf_str_section) |
6502dd73 | 1228 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1229 | else |
6502dd73 | 1230 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1231 | |
188dd5d6 | 1232 | if (dwarf_macinfo_section) |
6502dd73 | 1233 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1234 | dwarf_macinfo_section); |
2e276125 | 1235 | else |
6502dd73 | 1236 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1237 | |
188dd5d6 | 1238 | if (dwarf_ranges_section) |
6502dd73 | 1239 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1240 | else |
6502dd73 | 1241 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1242 | |
188dd5d6 | 1243 | if (dwarf_loc_section) |
6502dd73 | 1244 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1245 | else |
6502dd73 | 1246 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1247 | |
ef96bde8 EZ |
1248 | if (mainline |
1249 | || (objfile->global_psymbols.size == 0 | |
1250 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1251 | { |
1252 | init_psymbol_list (objfile, 1024); | |
1253 | } | |
1254 | ||
1255 | #if 0 | |
1256 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1257 | { | |
d4f3574e | 1258 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1259 | .debug_pubnames sections */ |
1260 | ||
d4f3574e | 1261 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1262 | } |
1263 | else | |
1264 | #endif | |
1265 | /* only test this case for now */ | |
c5aa993b | 1266 | { |
c906108c | 1267 | /* In this case we have to work a bit harder */ |
d4f3574e | 1268 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1269 | } |
1270 | } | |
1271 | ||
1272 | #if 0 | |
1273 | /* Build the partial symbol table from the information in the | |
1274 | .debug_pubnames and .debug_aranges sections. */ | |
1275 | ||
1276 | static void | |
fba45db2 | 1277 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1278 | { |
1279 | bfd *abfd = objfile->obfd; | |
1280 | char *aranges_buffer, *pubnames_buffer; | |
1281 | char *aranges_ptr, *pubnames_ptr; | |
1282 | unsigned int entry_length, version, info_offset, info_size; | |
1283 | ||
1284 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1285 | dwarf_pubnames_section); |
c906108c | 1286 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1287 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1288 | { |
613e1657 | 1289 | struct comp_unit_head cu_header; |
891d2f0b | 1290 | unsigned int bytes_read; |
613e1657 KB |
1291 | |
1292 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |
891d2f0b | 1293 | &bytes_read); |
613e1657 | 1294 | pubnames_ptr += bytes_read; |
c906108c SS |
1295 | version = read_1_byte (abfd, pubnames_ptr); |
1296 | pubnames_ptr += 1; | |
1297 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1298 | pubnames_ptr += 4; | |
1299 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1300 | pubnames_ptr += 4; | |
1301 | } | |
1302 | ||
1303 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1304 | dwarf_aranges_section); |
c906108c SS |
1305 | |
1306 | } | |
1307 | #endif | |
1308 | ||
107d2387 | 1309 | /* Read in the comp unit header information from the debug_info at |
917c78fc | 1310 | info_ptr. */ |
107d2387 | 1311 | |
fe1b8b76 | 1312 | static gdb_byte * |
107d2387 | 1313 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1314 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1315 | { |
1316 | int signed_addr; | |
891d2f0b | 1317 | unsigned int bytes_read; |
613e1657 KB |
1318 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, |
1319 | &bytes_read); | |
1320 | info_ptr += bytes_read; | |
107d2387 AC |
1321 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1322 | info_ptr += 2; | |
613e1657 KB |
1323 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
1324 | &bytes_read); | |
1325 | info_ptr += bytes_read; | |
107d2387 AC |
1326 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1327 | info_ptr += 1; | |
1328 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1329 | if (signed_addr < 0) | |
8e65ff28 | 1330 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1331 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 AC |
1332 | cu_header->signed_addr_p = signed_addr; |
1333 | return info_ptr; | |
1334 | } | |
1335 | ||
fe1b8b76 JB |
1336 | static gdb_byte * |
1337 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
72bf9492 DJ |
1338 | bfd *abfd) |
1339 | { | |
fe1b8b76 | 1340 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1341 | |
1342 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1343 | ||
2b949cb6 | 1344 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1345 | error (_("Dwarf Error: wrong version in compilation unit header " |
1346 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1347 | 2, bfd_get_filename (abfd)); |
1348 | ||
1349 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
8a3fe4f8 AC |
1350 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1351 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 DJ |
1352 | (long) header->abbrev_offset, |
1353 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1354 | bfd_get_filename (abfd)); | |
1355 | ||
1356 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1357 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
8a3fe4f8 AC |
1358 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1359 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 DJ |
1360 | (long) header->length, |
1361 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1362 | bfd_get_filename (abfd)); | |
1363 | ||
1364 | return info_ptr; | |
1365 | } | |
1366 | ||
aaa75496 JB |
1367 | /* Allocate a new partial symtab for file named NAME and mark this new |
1368 | partial symtab as being an include of PST. */ | |
1369 | ||
1370 | static void | |
1371 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1372 | struct objfile *objfile) | |
1373 | { | |
1374 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1375 | ||
1376 | subpst->section_offsets = pst->section_offsets; | |
1377 | subpst->textlow = 0; | |
1378 | subpst->texthigh = 0; | |
1379 | ||
1380 | subpst->dependencies = (struct partial_symtab **) | |
1381 | obstack_alloc (&objfile->objfile_obstack, | |
1382 | sizeof (struct partial_symtab *)); | |
1383 | subpst->dependencies[0] = pst; | |
1384 | subpst->number_of_dependencies = 1; | |
1385 | ||
1386 | subpst->globals_offset = 0; | |
1387 | subpst->n_global_syms = 0; | |
1388 | subpst->statics_offset = 0; | |
1389 | subpst->n_static_syms = 0; | |
1390 | subpst->symtab = NULL; | |
1391 | subpst->read_symtab = pst->read_symtab; | |
1392 | subpst->readin = 0; | |
1393 | ||
1394 | /* No private part is necessary for include psymtabs. This property | |
1395 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1396 | the regular ones. */ |
58a9656e | 1397 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1398 | } |
1399 | ||
1400 | /* Read the Line Number Program data and extract the list of files | |
1401 | included by the source file represented by PST. Build an include | |
1402 | partial symtab for each of these included files. | |
1403 | ||
1404 | This procedure assumes that there *is* a Line Number Program in | |
1405 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1406 | before calling this procedure. */ | |
1407 | ||
1408 | static void | |
1409 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1410 | struct partial_die_info *pdi, | |
1411 | struct partial_symtab *pst) | |
1412 | { | |
1413 | struct objfile *objfile = cu->objfile; | |
1414 | bfd *abfd = objfile->obfd; | |
1415 | struct line_header *lh; | |
1416 | ||
1417 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1418 | if (lh == NULL) | |
1419 | return; /* No linetable, so no includes. */ | |
1420 | ||
1421 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1422 | ||
1423 | free_line_header (lh); | |
1424 | } | |
1425 | ||
1426 | ||
c906108c SS |
1427 | /* Build the partial symbol table by doing a quick pass through the |
1428 | .debug_info and .debug_abbrev sections. */ | |
1429 | ||
1430 | static void | |
fba45db2 | 1431 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1432 | { |
1433 | /* Instead of reading this into a big buffer, we should probably use | |
1434 | mmap() on architectures that support it. (FIXME) */ | |
1435 | bfd *abfd = objfile->obfd; | |
fe1b8b76 JB |
1436 | gdb_byte *info_ptr; |
1437 | gdb_byte *beg_of_comp_unit; | |
c906108c SS |
1438 | struct partial_die_info comp_unit_die; |
1439 | struct partial_symtab *pst; | |
ae038cb0 | 1440 | struct cleanup *back_to; |
e142c38c | 1441 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1442 | |
6502dd73 | 1443 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1444 | |
ae038cb0 DJ |
1445 | /* Any cached compilation units will be linked by the per-objfile |
1446 | read_in_chain. Make sure to free them when we're done. */ | |
1447 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
1448 | ||
10b3939b DJ |
1449 | create_all_comp_units (objfile); |
1450 | ||
ff013f42 JK |
1451 | objfile->psymtabs_addrmap = addrmap_create_mutable |
1452 | (&objfile->objfile_obstack); | |
1453 | ||
6502dd73 | 1454 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1455 | length, only the individual functions to extract them (like |
72bf9492 | 1456 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1457 | the buffer is large enough to hold another complete object. |
1458 | ||
6502dd73 DJ |
1459 | At the moment, they don't actually check that. If .debug_info |
1460 | holds just one extra byte after the last compilation unit's dies, | |
1461 | then read_comp_unit_head will happily read off the end of the | |
1462 | buffer. read_partial_die is similarly casual. Those functions | |
1463 | should be fixed. | |
af703f96 JB |
1464 | |
1465 | For this loop condition, simply checking whether there's any data | |
1466 | left at all should be sufficient. */ | |
6502dd73 DJ |
1467 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1468 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1469 | { |
f3dd6933 | 1470 | struct cleanup *back_to_inner; |
e7c27a73 | 1471 | struct dwarf2_cu cu; |
72bf9492 DJ |
1472 | struct abbrev_info *abbrev; |
1473 | unsigned int bytes_read; | |
1474 | struct dwarf2_per_cu_data *this_cu; | |
1475 | ||
c906108c | 1476 | beg_of_comp_unit = info_ptr; |
c906108c | 1477 | |
72bf9492 DJ |
1478 | memset (&cu, 0, sizeof (cu)); |
1479 | ||
1480 | obstack_init (&cu.comp_unit_obstack); | |
1481 | ||
1482 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1483 | ||
e7c27a73 | 1484 | cu.objfile = objfile; |
72bf9492 | 1485 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1486 | |
57349743 | 1487 | /* Complete the cu_header */ |
6502dd73 | 1488 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
e7c27a73 DJ |
1489 | cu.header.first_die_ptr = info_ptr; |
1490 | cu.header.cu_head_ptr = beg_of_comp_unit; | |
57349743 | 1491 | |
e142c38c DJ |
1492 | cu.list_in_scope = &file_symbols; |
1493 | ||
c906108c | 1494 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1495 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1496 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 1497 | |
10b3939b | 1498 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); |
ae038cb0 | 1499 | |
c906108c | 1500 | /* Read the compilation unit die */ |
72bf9492 DJ |
1501 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1502 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1503 | abfd, info_ptr, &cu); | |
c906108c | 1504 | |
31ffec48 DJ |
1505 | if (comp_unit_die.tag == DW_TAG_partial_unit) |
1506 | { | |
1507 | info_ptr = (beg_of_comp_unit + cu.header.length | |
1508 | + cu.header.initial_length_size); | |
1509 | do_cleanups (back_to_inner); | |
1510 | continue; | |
1511 | } | |
1512 | ||
c906108c | 1513 | /* Set the language we're debugging */ |
e142c38c | 1514 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1515 | |
1516 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1517 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1518 | comp_unit_die.name ? comp_unit_die.name : "", |
ff013f42 JK |
1519 | /* TEXTLOW and TEXTHIGH are set below. */ |
1520 | 0, | |
c906108c SS |
1521 | objfile->global_psymbols.next, |
1522 | objfile->static_psymbols.next); | |
1523 | ||
ae038cb0 DJ |
1524 | if (comp_unit_die.dirname) |
1525 | pst->dirname = xstrdup (comp_unit_die.dirname); | |
57c22c6c | 1526 | |
10b3939b DJ |
1527 | pst->read_symtab_private = (char *) this_cu; |
1528 | ||
613e1657 | 1529 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1530 | |
1531 | /* Store the function that reads in the rest of the symbol table */ | |
1532 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1533 | ||
10b3939b DJ |
1534 | /* If this compilation unit was already read in, free the |
1535 | cached copy in order to read it in again. This is | |
1536 | necessary because we skipped some symbols when we first | |
1537 | read in the compilation unit (see load_partial_dies). | |
1538 | This problem could be avoided, but the benefit is | |
1539 | unclear. */ | |
1540 | if (this_cu->cu != NULL) | |
1541 | free_one_cached_comp_unit (this_cu->cu); | |
ae038cb0 | 1542 | |
10b3939b | 1543 | cu.per_cu = this_cu; |
ae038cb0 | 1544 | |
10b3939b DJ |
1545 | /* Note that this is a pointer to our stack frame, being |
1546 | added to a global data structure. It will be cleaned up | |
1547 | in free_stack_comp_unit when we finish with this | |
1548 | compilation unit. */ | |
1549 | this_cu->cu = &cu; | |
ae038cb0 | 1550 | |
10b3939b | 1551 | this_cu->psymtab = pst; |
ae038cb0 | 1552 | |
ff013f42 JK |
1553 | /* Possibly set the default values of LOWPC and HIGHPC from |
1554 | `DW_AT_ranges'. */ | |
1555 | if (cu.has_ranges_offset) | |
1556 | { | |
1557 | if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc, | |
1558 | &comp_unit_die.highpc, &cu, pst)) | |
1559 | comp_unit_die.has_pc_info = 1; | |
1560 | } | |
1561 | ||
c906108c SS |
1562 | /* Check if comp unit has_children. |
1563 | If so, read the rest of the partial symbols from this comp unit. | |
1564 | If not, there's no more debug_info for this comp unit. */ | |
1565 | if (comp_unit_die.has_children) | |
1566 | { | |
72bf9492 DJ |
1567 | struct partial_die_info *first_die; |
1568 | ||
91c24f0a DC |
1569 | lowpc = ((CORE_ADDR) -1); |
1570 | highpc = ((CORE_ADDR) 0); | |
1571 | ||
72bf9492 DJ |
1572 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1573 | ||
1574 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1575 | |
91c24f0a DC |
1576 | /* If we didn't find a lowpc, set it to highpc to avoid |
1577 | complaints from `maint check'. */ | |
1578 | if (lowpc == ((CORE_ADDR) -1)) | |
1579 | lowpc = highpc; | |
72bf9492 | 1580 | |
c906108c SS |
1581 | /* If the compilation unit didn't have an explicit address range, |
1582 | then use the information extracted from its child dies. */ | |
0b010bcc | 1583 | if (! comp_unit_die.has_pc_info) |
c906108c | 1584 | { |
c5aa993b | 1585 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1586 | comp_unit_die.highpc = highpc; |
1587 | } | |
1588 | } | |
c5aa993b | 1589 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1590 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1591 | ||
ff013f42 JK |
1592 | /* Store the contiguous range; `DW_AT_ranges' range is stored above. The |
1593 | range can be also empty for CUs with no code. */ | |
1594 | if (!cu.has_ranges_offset && pst->textlow < pst->texthigh) | |
1595 | addrmap_set_empty (objfile->psymtabs_addrmap, pst->textlow, | |
1596 | pst->texthigh - 1, pst); | |
1597 | ||
c906108c SS |
1598 | pst->n_global_syms = objfile->global_psymbols.next - |
1599 | (objfile->global_psymbols.list + pst->globals_offset); | |
1600 | pst->n_static_syms = objfile->static_psymbols.next - | |
1601 | (objfile->static_psymbols.list + pst->statics_offset); | |
1602 | sort_pst_symbols (pst); | |
1603 | ||
1604 | /* If there is already a psymtab or symtab for a file of this | |
1605 | name, remove it. (If there is a symtab, more drastic things | |
1606 | also happen.) This happens in VxWorks. */ | |
1607 | free_named_symtabs (pst->filename); | |
1608 | ||
dd373385 EZ |
1609 | info_ptr = beg_of_comp_unit + cu.header.length |
1610 | + cu.header.initial_length_size; | |
1611 | ||
aaa75496 JB |
1612 | if (comp_unit_die.has_stmt_list) |
1613 | { | |
1614 | /* Get the list of files included in the current compilation unit, | |
1615 | and build a psymtab for each of them. */ | |
1616 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1617 | } | |
1618 | ||
f3dd6933 | 1619 | do_cleanups (back_to_inner); |
c906108c | 1620 | } |
ff013f42 JK |
1621 | |
1622 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
1623 | &objfile->objfile_obstack); | |
1624 | ||
ae038cb0 DJ |
1625 | do_cleanups (back_to); |
1626 | } | |
1627 | ||
1628 | /* Load the DIEs for a secondary CU into memory. */ | |
1629 | ||
1630 | static void | |
1631 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |
1632 | { | |
1633 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 1634 | gdb_byte *info_ptr, *beg_of_comp_unit; |
ae038cb0 DJ |
1635 | struct partial_die_info comp_unit_die; |
1636 | struct dwarf2_cu *cu; | |
1637 | struct abbrev_info *abbrev; | |
1638 | unsigned int bytes_read; | |
1639 | struct cleanup *back_to; | |
1640 | ||
1641 | info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset; | |
1642 | beg_of_comp_unit = info_ptr; | |
1643 | ||
1644 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
1645 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
1646 | ||
1647 | obstack_init (&cu->comp_unit_obstack); | |
1648 | ||
1649 | cu->objfile = objfile; | |
1650 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |
1651 | ||
1652 | /* Complete the cu_header. */ | |
1653 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |
1654 | cu->header.first_die_ptr = info_ptr; | |
1655 | cu->header.cu_head_ptr = beg_of_comp_unit; | |
1656 | ||
1657 | /* Read the abbrevs for this compilation unit into a table. */ | |
1658 | dwarf2_read_abbrevs (abfd, cu); | |
1659 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
1660 | ||
1661 | /* Read the compilation unit die. */ | |
1662 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1663 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1664 | abfd, info_ptr, cu); | |
1665 | ||
1666 | /* Set the language we're debugging. */ | |
1667 | set_cu_language (comp_unit_die.language, cu); | |
1668 | ||
1669 | /* Link this compilation unit into the compilation unit tree. */ | |
1670 | this_cu->cu = cu; | |
1671 | cu->per_cu = this_cu; | |
f792889a | 1672 | cu->type_hash = cu->per_cu->type_hash; |
ae038cb0 DJ |
1673 | |
1674 | /* Check if comp unit has_children. | |
1675 | If so, read the rest of the partial symbols from this comp unit. | |
1676 | If not, there's no more debug_info for this comp unit. */ | |
1677 | if (comp_unit_die.has_children) | |
1678 | load_partial_dies (abfd, info_ptr, 0, cu); | |
1679 | ||
1680 | do_cleanups (back_to); | |
1681 | } | |
1682 | ||
1683 | /* Create a list of all compilation units in OBJFILE. We do this only | |
1684 | if an inter-comp-unit reference is found; presumably if there is one, | |
1685 | there will be many, and one will occur early in the .debug_info section. | |
1686 | So there's no point in building this list incrementally. */ | |
1687 | ||
1688 | static void | |
1689 | create_all_comp_units (struct objfile *objfile) | |
1690 | { | |
1691 | int n_allocated; | |
1692 | int n_comp_units; | |
1693 | struct dwarf2_per_cu_data **all_comp_units; | |
fe1b8b76 | 1694 | gdb_byte *info_ptr = dwarf2_per_objfile->info_buffer; |
ae038cb0 DJ |
1695 | |
1696 | n_comp_units = 0; | |
1697 | n_allocated = 10; | |
1698 | all_comp_units = xmalloc (n_allocated | |
1699 | * sizeof (struct dwarf2_per_cu_data *)); | |
1700 | ||
1701 | while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1702 | { | |
1703 | struct comp_unit_head cu_header; | |
fe1b8b76 | 1704 | gdb_byte *beg_of_comp_unit; |
ae038cb0 DJ |
1705 | struct dwarf2_per_cu_data *this_cu; |
1706 | unsigned long offset; | |
891d2f0b | 1707 | unsigned int bytes_read; |
ae038cb0 DJ |
1708 | |
1709 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |
1710 | ||
1711 | /* Read just enough information to find out where the next | |
1712 | compilation unit is. */ | |
dd373385 | 1713 | cu_header.initial_length_size = 0; |
ae038cb0 DJ |
1714 | cu_header.length = read_initial_length (objfile->obfd, info_ptr, |
1715 | &cu_header, &bytes_read); | |
1716 | ||
1717 | /* Save the compilation unit for later lookup. */ | |
1718 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
1719 | sizeof (struct dwarf2_per_cu_data)); | |
1720 | memset (this_cu, 0, sizeof (*this_cu)); | |
1721 | this_cu->offset = offset; | |
1722 | this_cu->length = cu_header.length + cu_header.initial_length_size; | |
1723 | ||
1724 | if (n_comp_units == n_allocated) | |
1725 | { | |
1726 | n_allocated *= 2; | |
1727 | all_comp_units = xrealloc (all_comp_units, | |
1728 | n_allocated | |
1729 | * sizeof (struct dwarf2_per_cu_data *)); | |
1730 | } | |
1731 | all_comp_units[n_comp_units++] = this_cu; | |
1732 | ||
1733 | info_ptr = info_ptr + this_cu->length; | |
1734 | } | |
1735 | ||
1736 | dwarf2_per_objfile->all_comp_units | |
1737 | = obstack_alloc (&objfile->objfile_obstack, | |
1738 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1739 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
1740 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1741 | xfree (all_comp_units); | |
1742 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
1743 | } |
1744 | ||
72bf9492 DJ |
1745 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1746 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1747 | in CU. */ | |
c906108c | 1748 | |
72bf9492 DJ |
1749 | static void |
1750 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1751 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1752 | { |
e7c27a73 | 1753 | struct objfile *objfile = cu->objfile; |
c906108c | 1754 | bfd *abfd = objfile->obfd; |
72bf9492 | 1755 | struct partial_die_info *pdi; |
c906108c | 1756 | |
91c24f0a DC |
1757 | /* Now, march along the PDI's, descending into ones which have |
1758 | interesting children but skipping the children of the other ones, | |
1759 | until we reach the end of the compilation unit. */ | |
c906108c | 1760 | |
72bf9492 | 1761 | pdi = first_die; |
91c24f0a | 1762 | |
72bf9492 DJ |
1763 | while (pdi != NULL) |
1764 | { | |
1765 | fixup_partial_die (pdi, cu); | |
c906108c | 1766 | |
91c24f0a DC |
1767 | /* Anonymous namespaces have no name but have interesting |
1768 | children, so we need to look at them. Ditto for anonymous | |
1769 | enums. */ | |
933c6fe4 | 1770 | |
72bf9492 DJ |
1771 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1772 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1773 | { |
72bf9492 | 1774 | switch (pdi->tag) |
c906108c SS |
1775 | { |
1776 | case DW_TAG_subprogram: | |
72bf9492 | 1777 | if (pdi->has_pc_info) |
c906108c | 1778 | { |
72bf9492 | 1779 | if (pdi->lowpc < *lowpc) |
c906108c | 1780 | { |
72bf9492 | 1781 | *lowpc = pdi->lowpc; |
c906108c | 1782 | } |
72bf9492 | 1783 | if (pdi->highpc > *highpc) |
c906108c | 1784 | { |
72bf9492 | 1785 | *highpc = pdi->highpc; |
c906108c | 1786 | } |
72bf9492 | 1787 | if (!pdi->is_declaration) |
c906108c | 1788 | { |
72bf9492 | 1789 | add_partial_symbol (pdi, cu); |
c906108c SS |
1790 | } |
1791 | } | |
1792 | break; | |
1793 | case DW_TAG_variable: | |
1794 | case DW_TAG_typedef: | |
91c24f0a | 1795 | case DW_TAG_union_type: |
72bf9492 | 1796 | if (!pdi->is_declaration) |
63d06c5c | 1797 | { |
72bf9492 | 1798 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1799 | } |
1800 | break; | |
c906108c | 1801 | case DW_TAG_class_type: |
680b30c7 | 1802 | case DW_TAG_interface_type: |
c906108c | 1803 | case DW_TAG_structure_type: |
72bf9492 | 1804 | if (!pdi->is_declaration) |
c906108c | 1805 | { |
72bf9492 | 1806 | add_partial_symbol (pdi, cu); |
c906108c SS |
1807 | } |
1808 | break; | |
91c24f0a | 1809 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1810 | if (!pdi->is_declaration) |
1811 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1812 | break; |
1813 | case DW_TAG_base_type: | |
a02abb62 | 1814 | case DW_TAG_subrange_type: |
c906108c | 1815 | /* File scope base type definitions are added to the partial |
c5aa993b | 1816 | symbol table. */ |
72bf9492 | 1817 | add_partial_symbol (pdi, cu); |
c906108c | 1818 | break; |
d9fa45fe | 1819 | case DW_TAG_namespace: |
72bf9492 | 1820 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1821 | break; |
c906108c SS |
1822 | default: |
1823 | break; | |
1824 | } | |
1825 | } | |
1826 | ||
72bf9492 DJ |
1827 | /* If the die has a sibling, skip to the sibling. */ |
1828 | ||
1829 | pdi = pdi->die_sibling; | |
1830 | } | |
1831 | } | |
1832 | ||
1833 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1834 | |
72bf9492 | 1835 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
1836 | name is concatenated with "::" and the partial DIE's name. For |
1837 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
1838 | Enumerators are an exception; they use the scope of their parent |
1839 | enumeration type, i.e. the name of the enumeration type is not | |
1840 | prepended to the enumerator. | |
91c24f0a | 1841 | |
72bf9492 DJ |
1842 | There are two complexities. One is DW_AT_specification; in this |
1843 | case "parent" means the parent of the target of the specification, | |
1844 | instead of the direct parent of the DIE. The other is compilers | |
1845 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1846 | the fully qualified name of structure types from their members' | |
1847 | linkage names. This must be done using the DIE's children rather | |
1848 | than the children of any DW_AT_specification target. We only need | |
1849 | to do this for structures at the top level, i.e. if the target of | |
1850 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1851 | have a parent. */ | |
1852 | ||
1853 | /* Compute the scope prefix associated with PDI's parent, in | |
1854 | compilation unit CU. The result will be allocated on CU's | |
1855 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1856 | field. NULL is returned if no prefix is necessary. */ | |
1857 | static char * | |
1858 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1859 | struct dwarf2_cu *cu) | |
1860 | { | |
1861 | char *grandparent_scope; | |
1862 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 1863 | |
72bf9492 DJ |
1864 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1865 | then this means the parent of the specification DIE. */ | |
1866 | ||
1867 | real_pdi = pdi; | |
72bf9492 | 1868 | while (real_pdi->has_specification) |
10b3939b | 1869 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
1870 | |
1871 | parent = real_pdi->die_parent; | |
1872 | if (parent == NULL) | |
1873 | return NULL; | |
1874 | ||
1875 | if (parent->scope_set) | |
1876 | return parent->scope; | |
1877 | ||
1878 | fixup_partial_die (parent, cu); | |
1879 | ||
10b3939b | 1880 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
1881 | |
1882 | if (parent->tag == DW_TAG_namespace | |
1883 | || parent->tag == DW_TAG_structure_type | |
1884 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 1885 | || parent->tag == DW_TAG_interface_type |
72bf9492 DJ |
1886 | || parent->tag == DW_TAG_union_type) |
1887 | { | |
1888 | if (grandparent_scope == NULL) | |
1889 | parent->scope = parent->name; | |
1890 | else | |
987504bb JJ |
1891 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
1892 | parent->name, cu); | |
72bf9492 DJ |
1893 | } |
1894 | else if (parent->tag == DW_TAG_enumeration_type) | |
1895 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1896 | parent->scope = grandparent_scope; | |
1897 | else | |
1898 | { | |
1899 | /* FIXME drow/2004-04-01: What should we be doing with | |
1900 | function-local names? For partial symbols, we should probably be | |
1901 | ignoring them. */ | |
1902 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1903 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
1904 | parent->tag, pdi->offset); |
1905 | parent->scope = grandparent_scope; | |
c906108c SS |
1906 | } |
1907 | ||
72bf9492 DJ |
1908 | parent->scope_set = 1; |
1909 | return parent->scope; | |
1910 | } | |
1911 | ||
1912 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1913 | CU. The result will be allocated with malloc. */ | |
1914 | static char * | |
1915 | partial_die_full_name (struct partial_die_info *pdi, | |
1916 | struct dwarf2_cu *cu) | |
1917 | { | |
1918 | char *parent_scope; | |
1919 | ||
1920 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1921 | if (parent_scope == NULL) | |
1922 | return NULL; | |
1923 | else | |
987504bb | 1924 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
1925 | } |
1926 | ||
1927 | static void | |
72bf9492 | 1928 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1929 | { |
e7c27a73 | 1930 | struct objfile *objfile = cu->objfile; |
c906108c | 1931 | CORE_ADDR addr = 0; |
decbce07 | 1932 | char *actual_name = NULL; |
72bf9492 | 1933 | const char *my_prefix; |
5c4e30ca | 1934 | const struct partial_symbol *psym = NULL; |
e142c38c | 1935 | CORE_ADDR baseaddr; |
72bf9492 | 1936 | int built_actual_name = 0; |
e142c38c DJ |
1937 | |
1938 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1939 | |
72bf9492 | 1940 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 1941 | { |
72bf9492 DJ |
1942 | actual_name = partial_die_full_name (pdi, cu); |
1943 | if (actual_name) | |
1944 | built_actual_name = 1; | |
63d06c5c DC |
1945 | } |
1946 | ||
72bf9492 DJ |
1947 | if (actual_name == NULL) |
1948 | actual_name = pdi->name; | |
1949 | ||
c906108c SS |
1950 | switch (pdi->tag) |
1951 | { | |
1952 | case DW_TAG_subprogram: | |
2cfa0c8d | 1953 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 1954 | { |
2cfa0c8d JB |
1955 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
1956 | of the global scope. But in Ada, we want to be able to access | |
1957 | nested procedures globally. So all Ada subprograms are stored | |
1958 | in the global scope. */ | |
38d518c9 | 1959 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1960 | mst_text, objfile); */ |
38d518c9 | 1961 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1962 | VAR_DOMAIN, LOC_BLOCK, |
1963 | &objfile->global_psymbols, | |
1964 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1965 | cu->language, objfile); |
c906108c SS |
1966 | } |
1967 | else | |
1968 | { | |
38d518c9 | 1969 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1970 | mst_file_text, objfile); */ |
38d518c9 | 1971 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1972 | VAR_DOMAIN, LOC_BLOCK, |
1973 | &objfile->static_psymbols, | |
1974 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1975 | cu->language, objfile); |
c906108c SS |
1976 | } |
1977 | break; | |
1978 | case DW_TAG_variable: | |
1979 | if (pdi->is_external) | |
1980 | { | |
1981 | /* Global Variable. | |
1982 | Don't enter into the minimal symbol tables as there is | |
1983 | a minimal symbol table entry from the ELF symbols already. | |
1984 | Enter into partial symbol table if it has a location | |
1985 | descriptor or a type. | |
1986 | If the location descriptor is missing, new_symbol will create | |
1987 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1988 | be determined from the minimal symbol table whenever the variable | |
1989 | is referenced. | |
1990 | The address for the partial symbol table entry is not | |
1991 | used by GDB, but it comes in handy for debugging partial symbol | |
1992 | table building. */ | |
1993 | ||
1994 | if (pdi->locdesc) | |
e7c27a73 | 1995 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 1996 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 1997 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1998 | VAR_DOMAIN, LOC_STATIC, |
1999 | &objfile->global_psymbols, | |
2000 | 0, addr + baseaddr, | |
e142c38c | 2001 | cu->language, objfile); |
c906108c SS |
2002 | } |
2003 | else | |
2004 | { | |
2005 | /* Static Variable. Skip symbols without location descriptors. */ | |
2006 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2007 | { |
2008 | if (built_actual_name) | |
2009 | xfree (actual_name); | |
2010 | return; | |
2011 | } | |
e7c27a73 | 2012 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2013 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2014 | mst_file_data, objfile); */ |
38d518c9 | 2015 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2016 | VAR_DOMAIN, LOC_STATIC, |
2017 | &objfile->static_psymbols, | |
2018 | 0, addr + baseaddr, | |
e142c38c | 2019 | cu->language, objfile); |
c906108c SS |
2020 | } |
2021 | break; | |
2022 | case DW_TAG_typedef: | |
2023 | case DW_TAG_base_type: | |
a02abb62 | 2024 | case DW_TAG_subrange_type: |
38d518c9 | 2025 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2026 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2027 | &objfile->static_psymbols, |
e142c38c | 2028 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2029 | break; |
72bf9492 DJ |
2030 | case DW_TAG_namespace: |
2031 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
2032 | VAR_DOMAIN, LOC_TYPEDEF, | |
2033 | &objfile->global_psymbols, | |
2034 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2035 | break; | |
c906108c | 2036 | case DW_TAG_class_type: |
680b30c7 | 2037 | case DW_TAG_interface_type: |
c906108c SS |
2038 | case DW_TAG_structure_type: |
2039 | case DW_TAG_union_type: | |
2040 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2041 | /* Skip external references. The DWARF standard says in the section |
2042 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2043 | structure, union or class type is represented by a structure, | |
2044 | union or class entry that does not have a byte size attribute | |
2045 | and that has a DW_AT_declaration attribute." */ | |
2046 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2047 | { |
2048 | if (built_actual_name) | |
2049 | xfree (actual_name); | |
2050 | return; | |
2051 | } | |
fa4028e9 | 2052 | |
63d06c5c DC |
2053 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2054 | static vs. global. */ | |
38d518c9 | 2055 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2056 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2057 | (cu->language == language_cplus |
2058 | || cu->language == language_java) | |
63d06c5c DC |
2059 | ? &objfile->global_psymbols |
2060 | : &objfile->static_psymbols, | |
e142c38c | 2061 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2062 | |
c906108c SS |
2063 | break; |
2064 | case DW_TAG_enumerator: | |
38d518c9 | 2065 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2066 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2067 | (cu->language == language_cplus |
2068 | || cu->language == language_java) | |
f6fe98ef DJ |
2069 | ? &objfile->global_psymbols |
2070 | : &objfile->static_psymbols, | |
e142c38c | 2071 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2072 | break; |
2073 | default: | |
2074 | break; | |
2075 | } | |
5c4e30ca DC |
2076 | |
2077 | /* Check to see if we should scan the name for possible namespace | |
2078 | info. Only do this if this is C++, if we don't have namespace | |
2079 | debugging info in the file, if the psym is of an appropriate type | |
2080 | (otherwise we'll have psym == NULL), and if we actually had a | |
2081 | mangled name to begin with. */ | |
2082 | ||
72bf9492 DJ |
2083 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2084 | cases which do not set PSYM above? */ | |
2085 | ||
e142c38c | 2086 | if (cu->language == language_cplus |
72bf9492 | 2087 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2088 | && psym != NULL |
2089 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2090 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2091 | objfile); | |
72bf9492 DJ |
2092 | |
2093 | if (built_actual_name) | |
2094 | xfree (actual_name); | |
c906108c SS |
2095 | } |
2096 | ||
72bf9492 DJ |
2097 | /* Determine whether a die of type TAG living in a C++ class or |
2098 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2099 | name listed in the die. */ |
2100 | ||
2101 | static int | |
72bf9492 | 2102 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2103 | { |
63d06c5c DC |
2104 | switch (tag) |
2105 | { | |
72bf9492 | 2106 | case DW_TAG_namespace: |
63d06c5c DC |
2107 | case DW_TAG_typedef: |
2108 | case DW_TAG_class_type: | |
680b30c7 | 2109 | case DW_TAG_interface_type: |
63d06c5c DC |
2110 | case DW_TAG_structure_type: |
2111 | case DW_TAG_union_type: | |
2112 | case DW_TAG_enumeration_type: | |
2113 | case DW_TAG_enumerator: | |
2114 | return 1; | |
2115 | default: | |
2116 | return 0; | |
2117 | } | |
2118 | } | |
2119 | ||
5c4e30ca DC |
2120 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2121 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2122 | the name of the enclosing namespace. */ | |
91c24f0a | 2123 | |
72bf9492 DJ |
2124 | static void |
2125 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2126 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 2127 | struct dwarf2_cu *cu) |
91c24f0a | 2128 | { |
e7c27a73 | 2129 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2130 | |
72bf9492 | 2131 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2132 | |
72bf9492 | 2133 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2134 | |
2135 | /* Now scan partial symbols in that namespace. */ | |
2136 | ||
91c24f0a | 2137 | if (pdi->has_children) |
72bf9492 | 2138 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
2139 | } |
2140 | ||
72bf9492 DJ |
2141 | /* See if we can figure out if the class lives in a namespace. We do |
2142 | this by looking for a member function; its demangled name will | |
2143 | contain namespace info, if there is any. */ | |
63d06c5c | 2144 | |
72bf9492 DJ |
2145 | static void |
2146 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2147 | struct dwarf2_cu *cu) | |
63d06c5c | 2148 | { |
987504bb JJ |
2149 | if ((cu->language == language_cplus |
2150 | || cu->language == language_java) | |
72bf9492 | 2151 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2152 | && struct_pdi->has_children) |
2153 | { | |
63d06c5c DC |
2154 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2155 | what template types look like, because the demangler | |
2156 | frequently doesn't give the same name as the debug info. We | |
2157 | could fix this by only using the demangled name to get the | |
134d01f1 | 2158 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2159 | |
72bf9492 DJ |
2160 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2161 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2162 | |
72bf9492 DJ |
2163 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2164 | we should not do this. We'll prepend the parent's fully qualified | |
2165 | name when we create the partial symbol. */ | |
5d51ca54 | 2166 | |
72bf9492 | 2167 | real_pdi = struct_pdi; |
72bf9492 | 2168 | while (real_pdi->has_specification) |
10b3939b | 2169 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2170 | |
72bf9492 DJ |
2171 | if (real_pdi->die_parent != NULL) |
2172 | return; | |
63d06c5c | 2173 | |
72bf9492 DJ |
2174 | while (child_pdi != NULL) |
2175 | { | |
2176 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2177 | { |
72bf9492 | 2178 | char *actual_class_name |
31c27f77 JJ |
2179 | = language_class_name_from_physname (cu->language_defn, |
2180 | child_pdi->name); | |
63d06c5c | 2181 | if (actual_class_name != NULL) |
72bf9492 DJ |
2182 | { |
2183 | struct_pdi->name | |
2184 | = obsavestring (actual_class_name, | |
2185 | strlen (actual_class_name), | |
2186 | &cu->comp_unit_obstack); | |
2187 | xfree (actual_class_name); | |
2188 | } | |
63d06c5c DC |
2189 | break; |
2190 | } | |
72bf9492 DJ |
2191 | |
2192 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2193 | } |
2194 | } | |
63d06c5c DC |
2195 | } |
2196 | ||
91c24f0a DC |
2197 | /* Read a partial die corresponding to an enumeration type. */ |
2198 | ||
72bf9492 DJ |
2199 | static void |
2200 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2201 | struct dwarf2_cu *cu) | |
91c24f0a | 2202 | { |
e7c27a73 | 2203 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2204 | bfd *abfd = objfile->obfd; |
72bf9492 | 2205 | struct partial_die_info *pdi; |
91c24f0a DC |
2206 | |
2207 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2208 | add_partial_symbol (enum_pdi, cu); |
2209 | ||
2210 | pdi = enum_pdi->die_child; | |
2211 | while (pdi) | |
91c24f0a | 2212 | { |
72bf9492 | 2213 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2214 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2215 | else |
72bf9492 DJ |
2216 | add_partial_symbol (pdi, cu); |
2217 | pdi = pdi->die_sibling; | |
91c24f0a | 2218 | } |
91c24f0a DC |
2219 | } |
2220 | ||
4bb7a0a7 DJ |
2221 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2222 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2223 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2224 | the initial number. */ | |
2225 | ||
2226 | static struct abbrev_info * | |
fe1b8b76 | 2227 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2228 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2229 | { |
2230 | bfd *abfd = cu->objfile->obfd; | |
2231 | unsigned int abbrev_number; | |
2232 | struct abbrev_info *abbrev; | |
2233 | ||
2234 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2235 | ||
2236 | if (abbrev_number == 0) | |
2237 | return NULL; | |
2238 | ||
2239 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2240 | if (!abbrev) | |
2241 | { | |
8a3fe4f8 | 2242 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2243 | bfd_get_filename (abfd)); |
2244 | } | |
2245 | ||
2246 | return abbrev; | |
2247 | } | |
2248 | ||
2249 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2250 | pointer to the end of a series of DIEs, terminated by an empty | |
2251 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2252 | ||
fe1b8b76 JB |
2253 | static gdb_byte * |
2254 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2255 | { |
2256 | struct abbrev_info *abbrev; | |
2257 | unsigned int bytes_read; | |
2258 | ||
2259 | while (1) | |
2260 | { | |
2261 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2262 | if (abbrev == NULL) | |
2263 | return info_ptr + bytes_read; | |
2264 | else | |
2265 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2266 | } | |
2267 | } | |
2268 | ||
2269 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2270 | should point just after the initial uleb128 of a DIE, and the | |
2271 | abbrev corresponding to that skipped uleb128 should be passed in | |
2272 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2273 | children. */ | |
2274 | ||
fe1b8b76 JB |
2275 | static gdb_byte * |
2276 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2277 | struct dwarf2_cu *cu) |
2278 | { | |
2279 | unsigned int bytes_read; | |
2280 | struct attribute attr; | |
2281 | bfd *abfd = cu->objfile->obfd; | |
2282 | unsigned int form, i; | |
2283 | ||
2284 | for (i = 0; i < abbrev->num_attrs; i++) | |
2285 | { | |
2286 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2287 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2288 | { | |
2289 | read_attribute (&attr, &abbrev->attrs[i], | |
2290 | abfd, info_ptr, cu); | |
2291 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2292 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2293 | else |
6502dd73 DJ |
2294 | return dwarf2_per_objfile->info_buffer |
2295 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
2296 | } |
2297 | ||
2298 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2299 | form = abbrev->attrs[i].form; | |
2300 | skip_attribute: | |
2301 | switch (form) | |
2302 | { | |
2303 | case DW_FORM_addr: | |
2304 | case DW_FORM_ref_addr: | |
2305 | info_ptr += cu->header.addr_size; | |
2306 | break; | |
2307 | case DW_FORM_data1: | |
2308 | case DW_FORM_ref1: | |
2309 | case DW_FORM_flag: | |
2310 | info_ptr += 1; | |
2311 | break; | |
2312 | case DW_FORM_data2: | |
2313 | case DW_FORM_ref2: | |
2314 | info_ptr += 2; | |
2315 | break; | |
2316 | case DW_FORM_data4: | |
2317 | case DW_FORM_ref4: | |
2318 | info_ptr += 4; | |
2319 | break; | |
2320 | case DW_FORM_data8: | |
2321 | case DW_FORM_ref8: | |
2322 | info_ptr += 8; | |
2323 | break; | |
2324 | case DW_FORM_string: | |
2325 | read_string (abfd, info_ptr, &bytes_read); | |
2326 | info_ptr += bytes_read; | |
2327 | break; | |
2328 | case DW_FORM_strp: | |
2329 | info_ptr += cu->header.offset_size; | |
2330 | break; | |
2331 | case DW_FORM_block: | |
2332 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2333 | info_ptr += bytes_read; | |
2334 | break; | |
2335 | case DW_FORM_block1: | |
2336 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2337 | break; | |
2338 | case DW_FORM_block2: | |
2339 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2340 | break; | |
2341 | case DW_FORM_block4: | |
2342 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2343 | break; | |
2344 | case DW_FORM_sdata: | |
2345 | case DW_FORM_udata: | |
2346 | case DW_FORM_ref_udata: | |
2347 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2348 | break; | |
2349 | case DW_FORM_indirect: | |
2350 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2351 | info_ptr += bytes_read; | |
2352 | /* We need to continue parsing from here, so just go back to | |
2353 | the top. */ | |
2354 | goto skip_attribute; | |
2355 | ||
2356 | default: | |
8a3fe4f8 | 2357 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2358 | dwarf_form_name (form), |
2359 | bfd_get_filename (abfd)); | |
2360 | } | |
2361 | } | |
2362 | ||
2363 | if (abbrev->has_children) | |
2364 | return skip_children (info_ptr, cu); | |
2365 | else | |
2366 | return info_ptr; | |
2367 | } | |
2368 | ||
2369 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2370 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2371 | |
fe1b8b76 JB |
2372 | static gdb_byte * |
2373 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2374 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2375 | { |
2376 | /* Do we know the sibling already? */ | |
72bf9492 | 2377 | |
91c24f0a DC |
2378 | if (orig_pdi->sibling) |
2379 | return orig_pdi->sibling; | |
2380 | ||
2381 | /* Are there any children to deal with? */ | |
2382 | ||
2383 | if (!orig_pdi->has_children) | |
2384 | return info_ptr; | |
2385 | ||
4bb7a0a7 | 2386 | /* Skip the children the long way. */ |
91c24f0a | 2387 | |
4bb7a0a7 | 2388 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2389 | } |
2390 | ||
c906108c SS |
2391 | /* Expand this partial symbol table into a full symbol table. */ |
2392 | ||
2393 | static void | |
fba45db2 | 2394 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2395 | { |
2396 | /* FIXME: This is barely more than a stub. */ | |
2397 | if (pst != NULL) | |
2398 | { | |
2399 | if (pst->readin) | |
2400 | { | |
8a3fe4f8 | 2401 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2402 | } |
2403 | else | |
2404 | { | |
2405 | if (info_verbose) | |
2406 | { | |
a3f17187 | 2407 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2408 | gdb_flush (gdb_stdout); |
2409 | } | |
2410 | ||
10b3939b DJ |
2411 | /* Restore our global data. */ |
2412 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2413 | dwarf2_objfile_data_key); | |
2414 | ||
c906108c SS |
2415 | psymtab_to_symtab_1 (pst); |
2416 | ||
2417 | /* Finish up the debug error message. */ | |
2418 | if (info_verbose) | |
a3f17187 | 2419 | printf_filtered (_("done.\n")); |
c906108c SS |
2420 | } |
2421 | } | |
2422 | } | |
2423 | ||
10b3939b DJ |
2424 | /* Add PER_CU to the queue. */ |
2425 | ||
2426 | static void | |
03dd20cc | 2427 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b DJ |
2428 | { |
2429 | struct dwarf2_queue_item *item; | |
2430 | ||
2431 | per_cu->queued = 1; | |
2432 | item = xmalloc (sizeof (*item)); | |
2433 | item->per_cu = per_cu; | |
2434 | item->next = NULL; | |
2435 | ||
2436 | if (dwarf2_queue == NULL) | |
2437 | dwarf2_queue = item; | |
2438 | else | |
2439 | dwarf2_queue_tail->next = item; | |
2440 | ||
2441 | dwarf2_queue_tail = item; | |
03dd20cc DJ |
2442 | |
2443 | /* Either PER_CU is the CU we want to process, or we're following a reference | |
2444 | pointing into PER_CU. Either way, we need its DIEs now. */ | |
2445 | load_full_comp_unit (item->per_cu, objfile); | |
2446 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2447 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
10b3939b DJ |
2448 | } |
2449 | ||
2450 | /* Process the queue. */ | |
2451 | ||
2452 | static void | |
2453 | process_queue (struct objfile *objfile) | |
2454 | { | |
2455 | struct dwarf2_queue_item *item, *next_item; | |
2456 | ||
03dd20cc DJ |
2457 | /* The queue starts out with one item, but following a DIE reference |
2458 | may load a new CU, adding it to the end of the queue. */ | |
10b3939b DJ |
2459 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
2460 | { | |
31ffec48 | 2461 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2462 | process_full_comp_unit (item->per_cu); |
2463 | ||
2464 | item->per_cu->queued = 0; | |
2465 | next_item = item->next; | |
2466 | xfree (item); | |
2467 | } | |
2468 | ||
2469 | dwarf2_queue_tail = NULL; | |
2470 | } | |
2471 | ||
2472 | /* Free all allocated queue entries. This function only releases anything if | |
2473 | an error was thrown; if the queue was processed then it would have been | |
2474 | freed as we went along. */ | |
2475 | ||
2476 | static void | |
2477 | dwarf2_release_queue (void *dummy) | |
2478 | { | |
2479 | struct dwarf2_queue_item *item, *last; | |
2480 | ||
2481 | item = dwarf2_queue; | |
2482 | while (item) | |
2483 | { | |
2484 | /* Anything still marked queued is likely to be in an | |
2485 | inconsistent state, so discard it. */ | |
2486 | if (item->per_cu->queued) | |
2487 | { | |
2488 | if (item->per_cu->cu != NULL) | |
2489 | free_one_cached_comp_unit (item->per_cu->cu); | |
2490 | item->per_cu->queued = 0; | |
2491 | } | |
2492 | ||
2493 | last = item; | |
2494 | item = item->next; | |
2495 | xfree (last); | |
2496 | } | |
2497 | ||
2498 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2499 | } | |
2500 | ||
2501 | /* Read in full symbols for PST, and anything it depends on. */ | |
2502 | ||
c906108c | 2503 | static void |
fba45db2 | 2504 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2505 | { |
10b3939b | 2506 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2507 | struct cleanup *back_to; |
aaa75496 JB |
2508 | int i; |
2509 | ||
2510 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2511 | if (!pst->dependencies[i]->readin) | |
2512 | { | |
2513 | /* Inform about additional files that need to be read in. */ | |
2514 | if (info_verbose) | |
2515 | { | |
a3f17187 | 2516 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2517 | fputs_filtered (" ", gdb_stdout); |
2518 | wrap_here (""); | |
2519 | fputs_filtered ("and ", gdb_stdout); | |
2520 | wrap_here (""); | |
2521 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2522 | wrap_here (""); /* Flush output */ | |
2523 | gdb_flush (gdb_stdout); | |
2524 | } | |
2525 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2526 | } | |
2527 | ||
10b3939b DJ |
2528 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2529 | ||
2530 | if (per_cu == NULL) | |
aaa75496 JB |
2531 | { |
2532 | /* It's an include file, no symbols to read for it. | |
2533 | Everything is in the parent symtab. */ | |
2534 | pst->readin = 1; | |
2535 | return; | |
2536 | } | |
c906108c | 2537 | |
10b3939b DJ |
2538 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2539 | ||
03dd20cc | 2540 | queue_comp_unit (per_cu, pst->objfile); |
10b3939b DJ |
2541 | |
2542 | process_queue (pst->objfile); | |
2543 | ||
2544 | /* Age the cache, releasing compilation units that have not | |
2545 | been used recently. */ | |
2546 | age_cached_comp_units (); | |
2547 | ||
2548 | do_cleanups (back_to); | |
2549 | } | |
2550 | ||
2551 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2552 | ||
2553 | static struct dwarf2_cu * | |
31ffec48 | 2554 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2555 | { |
31ffec48 | 2556 | bfd *abfd = objfile->obfd; |
10b3939b DJ |
2557 | struct dwarf2_cu *cu; |
2558 | unsigned long offset; | |
fe1b8b76 | 2559 | gdb_byte *info_ptr; |
10b3939b DJ |
2560 | struct cleanup *back_to, *free_cu_cleanup; |
2561 | struct attribute *attr; | |
2562 | CORE_ADDR baseaddr; | |
6502dd73 | 2563 | |
c906108c | 2564 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2565 | offset = per_cu->offset; |
6502dd73 DJ |
2566 | |
2567 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
63d06c5c | 2568 | |
10b3939b DJ |
2569 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2570 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2571 | |
10b3939b DJ |
2572 | /* If an error occurs while loading, release our storage. */ |
2573 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2574 | |
31ffec48 | 2575 | cu->objfile = objfile; |
e7c27a73 | 2576 | |
c906108c | 2577 | /* read in the comp_unit header */ |
10b3939b | 2578 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2579 | |
2580 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2581 | dwarf2_read_abbrevs (abfd, cu); |
2582 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2583 | ||
2584 | cu->header.offset = offset; | |
c906108c | 2585 | |
10b3939b DJ |
2586 | cu->per_cu = per_cu; |
2587 | per_cu->cu = cu; | |
f792889a | 2588 | cu->type_hash = per_cu->type_hash; |
e142c38c | 2589 | |
10b3939b DJ |
2590 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2591 | obstack_init (&cu->comp_unit_obstack); | |
2592 | ||
2593 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2594 | ||
2595 | /* We try not to read any attributes in this function, because not | |
2596 | all objfiles needed for references have been loaded yet, and symbol | |
2597 | table processing isn't initialized. But we have to set the CU language, | |
2598 | or we won't be able to build types correctly. */ | |
2599 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2600 | if (attr) | |
2601 | set_cu_language (DW_UNSND (attr), cu); | |
2602 | else | |
2603 | set_cu_language (language_minimal, cu); | |
2604 | ||
2605 | do_cleanups (back_to); | |
e142c38c | 2606 | |
10b3939b DJ |
2607 | /* We've successfully allocated this compilation unit. Let our caller |
2608 | clean it up when finished with it. */ | |
2609 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2610 | |
10b3939b DJ |
2611 | return cu; |
2612 | } | |
2613 | ||
2614 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2615 | already been loaded into memory. */ | |
2616 | ||
2617 | static void | |
2618 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2619 | { | |
2620 | struct partial_symtab *pst = per_cu->psymtab; | |
2621 | struct dwarf2_cu *cu = per_cu->cu; | |
2622 | struct objfile *objfile = pst->objfile; | |
2623 | bfd *abfd = objfile->obfd; | |
2624 | CORE_ADDR lowpc, highpc; | |
2625 | struct symtab *symtab; | |
2626 | struct cleanup *back_to; | |
2627 | struct attribute *attr; | |
2628 | CORE_ADDR baseaddr; | |
2629 | ||
2630 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2631 | ||
2632 | /* We're in the global namespace. */ | |
2633 | processing_current_prefix = ""; | |
2634 | ||
2635 | buildsym_init (); | |
2636 | back_to = make_cleanup (really_free_pendings, NULL); | |
2637 | ||
2638 | cu->list_in_scope = &file_symbols; | |
c906108c | 2639 | |
0d53c4c4 DJ |
2640 | /* Find the base address of the compilation unit for range lists and |
2641 | location lists. It will normally be specified by DW_AT_low_pc. | |
2642 | In DWARF-3 draft 4, the base address could be overridden by | |
2643 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2644 | compilation units with discontinuous ranges. */ | |
2645 | ||
10b3939b DJ |
2646 | cu->header.base_known = 0; |
2647 | cu->header.base_address = 0; | |
0d53c4c4 | 2648 | |
10b3939b | 2649 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2650 | if (attr) |
2651 | { | |
10b3939b DJ |
2652 | cu->header.base_address = DW_ADDR (attr); |
2653 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2654 | } |
2655 | else | |
2656 | { | |
10b3939b | 2657 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2658 | if (attr) |
2659 | { | |
10b3939b DJ |
2660 | cu->header.base_address = DW_ADDR (attr); |
2661 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2662 | } |
2663 | } | |
2664 | ||
c906108c | 2665 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2666 | process_die (cu->dies, cu); |
c906108c | 2667 | |
fae299cd DC |
2668 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2669 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2670 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2671 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2672 | |
613e1657 | 2673 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2674 | |
2675 | /* Set symtab language to language from DW_AT_language. | |
2676 | If the compilation is from a C file generated by language preprocessors, | |
2677 | do not set the language if it was already deduced by start_subfile. */ | |
2678 | if (symtab != NULL | |
10b3939b | 2679 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2680 | { |
10b3939b | 2681 | symtab->language = cu->language; |
c906108c SS |
2682 | } |
2683 | pst->symtab = symtab; | |
2684 | pst->readin = 1; | |
c906108c SS |
2685 | |
2686 | do_cleanups (back_to); | |
2687 | } | |
2688 | ||
2689 | /* Process a die and its children. */ | |
2690 | ||
2691 | static void | |
e7c27a73 | 2692 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2693 | { |
2694 | switch (die->tag) | |
2695 | { | |
2696 | case DW_TAG_padding: | |
2697 | break; | |
2698 | case DW_TAG_compile_unit: | |
e7c27a73 | 2699 | read_file_scope (die, cu); |
c906108c SS |
2700 | break; |
2701 | case DW_TAG_subprogram: | |
e7c27a73 | 2702 | read_func_scope (die, cu); |
c906108c SS |
2703 | break; |
2704 | case DW_TAG_inlined_subroutine: | |
2705 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2706 | They could be used to set breakpoints on all inlined instances |
2707 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2708 | break; |
2709 | case DW_TAG_lexical_block: | |
14898363 L |
2710 | case DW_TAG_try_block: |
2711 | case DW_TAG_catch_block: | |
e7c27a73 | 2712 | read_lexical_block_scope (die, cu); |
c906108c SS |
2713 | break; |
2714 | case DW_TAG_class_type: | |
680b30c7 | 2715 | case DW_TAG_interface_type: |
c906108c SS |
2716 | case DW_TAG_structure_type: |
2717 | case DW_TAG_union_type: | |
134d01f1 | 2718 | process_structure_scope (die, cu); |
c906108c SS |
2719 | break; |
2720 | case DW_TAG_enumeration_type: | |
134d01f1 | 2721 | process_enumeration_scope (die, cu); |
c906108c | 2722 | break; |
134d01f1 | 2723 | |
f792889a DJ |
2724 | /* These dies have a type, but processing them does not create |
2725 | a symbol or recurse to process the children. Therefore we can | |
2726 | read them on-demand through read_type_die. */ | |
c906108c | 2727 | case DW_TAG_subroutine_type: |
72019c9c | 2728 | case DW_TAG_set_type: |
c906108c | 2729 | case DW_TAG_array_type: |
c906108c | 2730 | case DW_TAG_pointer_type: |
c906108c | 2731 | case DW_TAG_ptr_to_member_type: |
c906108c | 2732 | case DW_TAG_reference_type: |
c906108c | 2733 | case DW_TAG_string_type: |
c906108c | 2734 | break; |
134d01f1 | 2735 | |
c906108c | 2736 | case DW_TAG_base_type: |
a02abb62 | 2737 | case DW_TAG_subrange_type: |
134d01f1 DJ |
2738 | /* Add a typedef symbol for the type definition, if it has a |
2739 | DW_AT_name. */ | |
f792889a | 2740 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 2741 | break; |
c906108c | 2742 | case DW_TAG_common_block: |
e7c27a73 | 2743 | read_common_block (die, cu); |
c906108c SS |
2744 | break; |
2745 | case DW_TAG_common_inclusion: | |
2746 | break; | |
d9fa45fe | 2747 | case DW_TAG_namespace: |
63d06c5c | 2748 | processing_has_namespace_info = 1; |
e7c27a73 | 2749 | read_namespace (die, cu); |
d9fa45fe DC |
2750 | break; |
2751 | case DW_TAG_imported_declaration: | |
2752 | case DW_TAG_imported_module: | |
2753 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2754 | information contained in these. DW_TAG_imported_declaration | |
2755 | dies shouldn't have children; DW_TAG_imported_module dies | |
2756 | shouldn't in the C++ case, but conceivably could in the | |
2757 | Fortran case, so we'll have to replace this gdb_assert if | |
2758 | Fortran compilers start generating that info. */ | |
63d06c5c | 2759 | processing_has_namespace_info = 1; |
639d11d3 | 2760 | gdb_assert (die->child == NULL); |
d9fa45fe | 2761 | break; |
c906108c | 2762 | default: |
e7c27a73 | 2763 | new_symbol (die, NULL, cu); |
c906108c SS |
2764 | break; |
2765 | } | |
2766 | } | |
2767 | ||
5fb290d7 | 2768 | static void |
e142c38c | 2769 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2770 | { |
e142c38c | 2771 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2772 | } |
2773 | ||
cb1df416 DJ |
2774 | static void |
2775 | free_cu_line_header (void *arg) | |
2776 | { | |
2777 | struct dwarf2_cu *cu = arg; | |
2778 | ||
2779 | free_line_header (cu->line_header); | |
2780 | cu->line_header = NULL; | |
2781 | } | |
2782 | ||
c906108c | 2783 | static void |
e7c27a73 | 2784 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2785 | { |
e7c27a73 DJ |
2786 | struct objfile *objfile = cu->objfile; |
2787 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2788 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2789 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2790 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2791 | struct attribute *attr; | |
e1024ff1 | 2792 | char *name = NULL; |
c906108c SS |
2793 | char *comp_dir = NULL; |
2794 | struct die_info *child_die; | |
2795 | bfd *abfd = objfile->obfd; | |
debd256d | 2796 | struct line_header *line_header = 0; |
e142c38c DJ |
2797 | CORE_ADDR baseaddr; |
2798 | ||
2799 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2800 | |
fae299cd | 2801 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2802 | |
2803 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2804 | from finish_block. */ | |
2acceee2 | 2805 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2806 | lowpc = highpc; |
2807 | lowpc += baseaddr; | |
2808 | highpc += baseaddr; | |
2809 | ||
39cbfefa DJ |
2810 | /* Find the filename. Do not use dwarf2_name here, since the filename |
2811 | is not a source language identifier. */ | |
e142c38c | 2812 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2813 | if (attr) |
2814 | { | |
2815 | name = DW_STRING (attr); | |
2816 | } | |
e1024ff1 | 2817 | |
e142c38c | 2818 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 2819 | if (attr) |
e1024ff1 DJ |
2820 | comp_dir = DW_STRING (attr); |
2821 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 2822 | { |
e1024ff1 DJ |
2823 | comp_dir = ldirname (name); |
2824 | if (comp_dir != NULL) | |
2825 | make_cleanup (xfree, comp_dir); | |
2826 | } | |
2827 | if (comp_dir != NULL) | |
2828 | { | |
2829 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2830 | directory, get rid of it. */ | |
2831 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 2832 | |
e1024ff1 DJ |
2833 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
2834 | comp_dir = cp + 1; | |
c906108c SS |
2835 | } |
2836 | ||
e1024ff1 DJ |
2837 | if (name == NULL) |
2838 | name = "<unknown>"; | |
2839 | ||
e142c38c | 2840 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2841 | if (attr) |
2842 | { | |
e142c38c | 2843 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2844 | } |
2845 | ||
b0f35d58 DL |
2846 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
2847 | if (attr) | |
2848 | cu->producer = DW_STRING (attr); | |
303b6f5d | 2849 | |
c906108c SS |
2850 | /* We assume that we're processing GCC output. */ |
2851 | processing_gcc_compilation = 2; | |
c906108c | 2852 | |
c906108c SS |
2853 | start_symtab (name, comp_dir, lowpc); |
2854 | record_debugformat ("DWARF 2"); | |
303b6f5d | 2855 | record_producer (cu->producer); |
c906108c | 2856 | |
e142c38c | 2857 | initialize_cu_func_list (cu); |
c906108c | 2858 | |
cb1df416 DJ |
2859 | /* Decode line number information if present. We do this before |
2860 | processing child DIEs, so that the line header table is available | |
2861 | for DW_AT_decl_file. */ | |
e142c38c | 2862 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2863 | if (attr) |
2864 | { | |
debd256d | 2865 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2866 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2867 | if (line_header) |
2868 | { | |
cb1df416 DJ |
2869 | cu->line_header = line_header; |
2870 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 2871 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2872 | } |
5fb290d7 | 2873 | } |
debd256d | 2874 | |
cb1df416 DJ |
2875 | /* Process all dies in compilation unit. */ |
2876 | if (die->child != NULL) | |
2877 | { | |
2878 | child_die = die->child; | |
2879 | while (child_die && child_die->tag) | |
2880 | { | |
2881 | process_die (child_die, cu); | |
2882 | child_die = sibling_die (child_die); | |
2883 | } | |
2884 | } | |
2885 | ||
2e276125 JB |
2886 | /* Decode macro information, if present. Dwarf 2 macro information |
2887 | refers to information in the line number info statement program | |
2888 | header, so we can only read it if we've read the header | |
2889 | successfully. */ | |
e142c38c | 2890 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2891 | if (attr && line_header) |
2e276125 JB |
2892 | { |
2893 | unsigned int macro_offset = DW_UNSND (attr); | |
2894 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2895 | comp_dir, abfd, cu); |
2e276125 | 2896 | } |
debd256d | 2897 | do_cleanups (back_to); |
5fb290d7 DJ |
2898 | } |
2899 | ||
2900 | static void | |
e142c38c DJ |
2901 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2902 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2903 | { |
2904 | struct function_range *thisfn; | |
2905 | ||
2906 | thisfn = (struct function_range *) | |
7b5a2f43 | 2907 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2908 | thisfn->name = name; |
2909 | thisfn->lowpc = lowpc; | |
2910 | thisfn->highpc = highpc; | |
2911 | thisfn->seen_line = 0; | |
2912 | thisfn->next = NULL; | |
2913 | ||
e142c38c DJ |
2914 | if (cu->last_fn == NULL) |
2915 | cu->first_fn = thisfn; | |
5fb290d7 | 2916 | else |
e142c38c | 2917 | cu->last_fn->next = thisfn; |
5fb290d7 | 2918 | |
e142c38c | 2919 | cu->last_fn = thisfn; |
c906108c SS |
2920 | } |
2921 | ||
2922 | static void | |
e7c27a73 | 2923 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2924 | { |
e7c27a73 | 2925 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2926 | struct context_stack *new; |
c906108c SS |
2927 | CORE_ADDR lowpc; |
2928 | CORE_ADDR highpc; | |
2929 | struct die_info *child_die; | |
2930 | struct attribute *attr; | |
2931 | char *name; | |
fdde2d81 DC |
2932 | const char *previous_prefix = processing_current_prefix; |
2933 | struct cleanup *back_to = NULL; | |
e142c38c | 2934 | CORE_ADDR baseaddr; |
801e3a5b | 2935 | struct block *block; |
c906108c | 2936 | |
e142c38c DJ |
2937 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2938 | ||
2939 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2940 | |
2941 | /* Ignore functions with missing or empty names and functions with | |
2942 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2943 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2944 | return; |
2945 | ||
987504bb JJ |
2946 | if (cu->language == language_cplus |
2947 | || cu->language == language_java) | |
fdde2d81 | 2948 | { |
f2f0e013 DJ |
2949 | struct dwarf2_cu *spec_cu = cu; |
2950 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
fdde2d81 | 2951 | |
2a35147e JB |
2952 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2953 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2954 | given the code | |
2955 | ||
2956 | namespace N { | |
2957 | void foo() { | |
2958 | // Definition of N::foo. | |
2959 | } | |
2960 | } | |
2961 | ||
2962 | then we'll have a tree of DIEs like this: | |
2963 | ||
2964 | 1: DW_TAG_compile_unit | |
2965 | 2: DW_TAG_namespace // N | |
2966 | 3: DW_TAG_subprogram // declaration of N::foo | |
2967 | 4: DW_TAG_subprogram // definition of N::foo | |
2968 | DW_AT_specification // refers to die #3 | |
2969 | ||
2970 | Thus, when processing die #4, we have to pretend that we're | |
2971 | in the context of its DW_AT_specification, namely the contex | |
2972 | of die #3. */ | |
fdde2d81 DC |
2973 | |
2974 | if (spec_die != NULL) | |
2975 | { | |
f2f0e013 | 2976 | char *specification_prefix = determine_prefix (spec_die, spec_cu); |
fdde2d81 DC |
2977 | processing_current_prefix = specification_prefix; |
2978 | back_to = make_cleanup (xfree, specification_prefix); | |
2979 | } | |
2980 | } | |
2981 | ||
c906108c SS |
2982 | lowpc += baseaddr; |
2983 | highpc += baseaddr; | |
2984 | ||
5fb290d7 | 2985 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2986 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 2987 | |
c906108c | 2988 | new = push_context (0, lowpc); |
f792889a | 2989 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 2990 | |
4cecd739 DJ |
2991 | /* If there is a location expression for DW_AT_frame_base, record |
2992 | it. */ | |
e142c38c | 2993 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 2994 | if (attr) |
c034e007 AC |
2995 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
2996 | expression is being recorded directly in the function's symbol | |
2997 | and not in a separate frame-base object. I guess this hack is | |
2998 | to avoid adding some sort of frame-base adjunct/annex to the | |
2999 | function's symbol :-(. The problem with doing this is that it | |
3000 | results in a function symbol with a location expression that | |
3001 | has nothing to do with the location of the function, ouch! The | |
3002 | relationship should be: a function's symbol has-a frame base; a | |
3003 | frame-base has-a location expression. */ | |
e7c27a73 | 3004 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3005 | |
e142c38c | 3006 | cu->list_in_scope = &local_symbols; |
c906108c | 3007 | |
639d11d3 | 3008 | if (die->child != NULL) |
c906108c | 3009 | { |
639d11d3 | 3010 | child_die = die->child; |
c906108c SS |
3011 | while (child_die && child_die->tag) |
3012 | { | |
e7c27a73 | 3013 | process_die (child_die, cu); |
c906108c SS |
3014 | child_die = sibling_die (child_die); |
3015 | } | |
3016 | } | |
3017 | ||
3018 | new = pop_context (); | |
3019 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3020 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3021 | lowpc, highpc, objfile); | |
3022 | ||
3023 | /* If we have address ranges, record them. */ | |
3024 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3025 | |
3026 | /* In C++, we can have functions nested inside functions (e.g., when | |
3027 | a function declares a class that has methods). This means that | |
3028 | when we finish processing a function scope, we may need to go | |
3029 | back to building a containing block's symbol lists. */ | |
3030 | local_symbols = new->locals; | |
3031 | param_symbols = new->params; | |
3032 | ||
921e78cf JB |
3033 | /* If we've finished processing a top-level function, subsequent |
3034 | symbols go in the file symbol list. */ | |
3035 | if (outermost_context_p ()) | |
e142c38c | 3036 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
3037 | |
3038 | processing_current_prefix = previous_prefix; | |
3039 | if (back_to != NULL) | |
3040 | do_cleanups (back_to); | |
c906108c SS |
3041 | } |
3042 | ||
3043 | /* Process all the DIES contained within a lexical block scope. Start | |
3044 | a new scope, process the dies, and then close the scope. */ | |
3045 | ||
3046 | static void | |
e7c27a73 | 3047 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3048 | { |
e7c27a73 | 3049 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3050 | struct context_stack *new; |
c906108c SS |
3051 | CORE_ADDR lowpc, highpc; |
3052 | struct die_info *child_die; | |
e142c38c DJ |
3053 | CORE_ADDR baseaddr; |
3054 | ||
3055 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3056 | |
3057 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3058 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3059 | as multiple lexical blocks? Handling children in a sane way would | |
3060 | be nasty. Might be easier to properly extend generic blocks to | |
3061 | describe ranges. */ | |
e7c27a73 | 3062 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3063 | return; |
3064 | lowpc += baseaddr; | |
3065 | highpc += baseaddr; | |
3066 | ||
3067 | push_context (0, lowpc); | |
639d11d3 | 3068 | if (die->child != NULL) |
c906108c | 3069 | { |
639d11d3 | 3070 | child_die = die->child; |
c906108c SS |
3071 | while (child_die && child_die->tag) |
3072 | { | |
e7c27a73 | 3073 | process_die (child_die, cu); |
c906108c SS |
3074 | child_die = sibling_die (child_die); |
3075 | } | |
3076 | } | |
3077 | new = pop_context (); | |
3078 | ||
3079 | if (local_symbols != NULL) | |
3080 | { | |
801e3a5b JB |
3081 | struct block *block |
3082 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3083 | highpc, objfile); | |
3084 | ||
3085 | /* Note that recording ranges after traversing children, as we | |
3086 | do here, means that recording a parent's ranges entails | |
3087 | walking across all its children's ranges as they appear in | |
3088 | the address map, which is quadratic behavior. | |
3089 | ||
3090 | It would be nicer to record the parent's ranges before | |
3091 | traversing its children, simply overriding whatever you find | |
3092 | there. But since we don't even decide whether to create a | |
3093 | block until after we've traversed its children, that's hard | |
3094 | to do. */ | |
3095 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3096 | } |
3097 | local_symbols = new->locals; | |
3098 | } | |
3099 | ||
43039443 | 3100 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3101 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3102 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3103 | |
3104 | static int | |
3105 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3106 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3107 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3108 | { |
3109 | struct objfile *objfile = cu->objfile; | |
3110 | struct comp_unit_head *cu_header = &cu->header; | |
3111 | bfd *obfd = objfile->obfd; | |
3112 | unsigned int addr_size = cu_header->addr_size; | |
3113 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3114 | /* Base address selection entry. */ | |
3115 | CORE_ADDR base; | |
3116 | int found_base; | |
3117 | unsigned int dummy; | |
3118 | gdb_byte *buffer; | |
3119 | CORE_ADDR marker; | |
3120 | int low_set; | |
3121 | CORE_ADDR low = 0; | |
3122 | CORE_ADDR high = 0; | |
ff013f42 | 3123 | CORE_ADDR baseaddr; |
43039443 JK |
3124 | |
3125 | found_base = cu_header->base_known; | |
3126 | base = cu_header->base_address; | |
3127 | ||
3128 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3129 | { | |
3130 | complaint (&symfile_complaints, | |
3131 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
3132 | offset); | |
3133 | return 0; | |
3134 | } | |
3135 | buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3136 | ||
3137 | /* Read in the largest possible address. */ | |
3138 | marker = read_address (obfd, buffer, cu, &dummy); | |
3139 | if ((marker & mask) == mask) | |
3140 | { | |
3141 | /* If we found the largest possible address, then | |
3142 | read the base address. */ | |
3143 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3144 | buffer += 2 * addr_size; | |
3145 | offset += 2 * addr_size; | |
3146 | found_base = 1; | |
3147 | } | |
3148 | ||
3149 | low_set = 0; | |
3150 | ||
e7030f15 | 3151 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 3152 | |
43039443 JK |
3153 | while (1) |
3154 | { | |
3155 | CORE_ADDR range_beginning, range_end; | |
3156 | ||
3157 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
3158 | buffer += addr_size; | |
3159 | range_end = read_address (obfd, buffer, cu, &dummy); | |
3160 | buffer += addr_size; | |
3161 | offset += 2 * addr_size; | |
3162 | ||
3163 | /* An end of list marker is a pair of zero addresses. */ | |
3164 | if (range_beginning == 0 && range_end == 0) | |
3165 | /* Found the end of list entry. */ | |
3166 | break; | |
3167 | ||
3168 | /* Each base address selection entry is a pair of 2 values. | |
3169 | The first is the largest possible address, the second is | |
3170 | the base address. Check for a base address here. */ | |
3171 | if ((range_beginning & mask) == mask) | |
3172 | { | |
3173 | /* If we found the largest possible address, then | |
3174 | read the base address. */ | |
3175 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3176 | found_base = 1; | |
3177 | continue; | |
3178 | } | |
3179 | ||
3180 | if (!found_base) | |
3181 | { | |
3182 | /* We have no valid base address for the ranges | |
3183 | data. */ | |
3184 | complaint (&symfile_complaints, | |
3185 | _("Invalid .debug_ranges data (no base address)")); | |
3186 | return 0; | |
3187 | } | |
3188 | ||
3189 | range_beginning += base; | |
3190 | range_end += base; | |
3191 | ||
ff013f42 JK |
3192 | if (ranges_pst != NULL && range_beginning < range_end) |
3193 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3194 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
3195 | ranges_pst); | |
3196 | ||
43039443 JK |
3197 | /* FIXME: This is recording everything as a low-high |
3198 | segment of consecutive addresses. We should have a | |
3199 | data structure for discontiguous block ranges | |
3200 | instead. */ | |
3201 | if (! low_set) | |
3202 | { | |
3203 | low = range_beginning; | |
3204 | high = range_end; | |
3205 | low_set = 1; | |
3206 | } | |
3207 | else | |
3208 | { | |
3209 | if (range_beginning < low) | |
3210 | low = range_beginning; | |
3211 | if (range_end > high) | |
3212 | high = range_end; | |
3213 | } | |
3214 | } | |
3215 | ||
3216 | if (! low_set) | |
3217 | /* If the first entry is an end-of-list marker, the range | |
3218 | describes an empty scope, i.e. no instructions. */ | |
3219 | return 0; | |
3220 | ||
3221 | if (low_return) | |
3222 | *low_return = low; | |
3223 | if (high_return) | |
3224 | *high_return = high; | |
3225 | return 1; | |
3226 | } | |
3227 | ||
af34e669 DJ |
3228 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3229 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3230 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3231 | static int |
af34e669 | 3232 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3233 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c SS |
3234 | { |
3235 | struct attribute *attr; | |
af34e669 DJ |
3236 | CORE_ADDR low = 0; |
3237 | CORE_ADDR high = 0; | |
3238 | int ret = 0; | |
c906108c | 3239 | |
e142c38c | 3240 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3241 | if (attr) |
af34e669 DJ |
3242 | { |
3243 | high = DW_ADDR (attr); | |
e142c38c | 3244 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3245 | if (attr) |
3246 | low = DW_ADDR (attr); | |
3247 | else | |
3248 | /* Found high w/o low attribute. */ | |
3249 | return 0; | |
3250 | ||
3251 | /* Found consecutive range of addresses. */ | |
3252 | ret = 1; | |
3253 | } | |
c906108c | 3254 | else |
af34e669 | 3255 | { |
e142c38c | 3256 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3257 | if (attr != NULL) |
3258 | { | |
af34e669 | 3259 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 3260 | .debug_ranges section. */ |
ff013f42 | 3261 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL)) |
af34e669 | 3262 | return 0; |
43039443 | 3263 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
3264 | ret = -1; |
3265 | } | |
3266 | } | |
c906108c SS |
3267 | |
3268 | if (high < low) | |
3269 | return 0; | |
3270 | ||
3271 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3272 | eliminate duplicate copies of functions and vtables and such. | |
3273 | The linker will arbitrarily choose one and discard the others. | |
3274 | The AT_*_pc values for such functions refer to local labels in | |
3275 | these sections. If the section from that file was discarded, the | |
3276 | labels are not in the output, so the relocs get a value of 0. | |
3277 | If this is a discarded function, mark the pc bounds as invalid, | |
3278 | so that GDB will ignore it. */ | |
72dca2f5 | 3279 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3280 | return 0; |
3281 | ||
3282 | *lowpc = low; | |
3283 | *highpc = high; | |
af34e669 | 3284 | return ret; |
c906108c SS |
3285 | } |
3286 | ||
fae299cd DC |
3287 | /* Get the low and high pc's represented by the scope DIE, and store |
3288 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3289 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3290 | ||
3291 | static void | |
3292 | get_scope_pc_bounds (struct die_info *die, | |
3293 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3294 | struct dwarf2_cu *cu) | |
3295 | { | |
3296 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3297 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3298 | CORE_ADDR current_low, current_high; | |
3299 | ||
3300 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3301 | { | |
3302 | best_low = current_low; | |
3303 | best_high = current_high; | |
3304 | } | |
3305 | else | |
3306 | { | |
3307 | struct die_info *child = die->child; | |
3308 | ||
3309 | while (child && child->tag) | |
3310 | { | |
3311 | switch (child->tag) { | |
3312 | case DW_TAG_subprogram: | |
3313 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
3314 | { | |
3315 | best_low = min (best_low, current_low); | |
3316 | best_high = max (best_high, current_high); | |
3317 | } | |
3318 | break; | |
3319 | case DW_TAG_namespace: | |
3320 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3321 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3322 | that current GCC's always emit the DIEs corresponding | |
3323 | to definitions of methods of classes as children of a | |
3324 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3325 | the DIEs giving the declarations, which could be | |
3326 | anywhere). But I don't see any reason why the | |
3327 | standards says that they have to be there. */ | |
3328 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3329 | ||
3330 | if (current_low != ((CORE_ADDR) -1)) | |
3331 | { | |
3332 | best_low = min (best_low, current_low); | |
3333 | best_high = max (best_high, current_high); | |
3334 | } | |
3335 | break; | |
3336 | default: | |
3337 | /* Ignore. */ | |
3338 | break; | |
3339 | } | |
3340 | ||
3341 | child = sibling_die (child); | |
3342 | } | |
3343 | } | |
3344 | ||
3345 | *lowpc = best_low; | |
3346 | *highpc = best_high; | |
3347 | } | |
3348 | ||
801e3a5b JB |
3349 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
3350 | in DIE. */ | |
3351 | static void | |
3352 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
3353 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
3354 | { | |
3355 | struct attribute *attr; | |
3356 | ||
3357 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
3358 | if (attr) | |
3359 | { | |
3360 | CORE_ADDR high = DW_ADDR (attr); | |
3361 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3362 | if (attr) | |
3363 | { | |
3364 | CORE_ADDR low = DW_ADDR (attr); | |
3365 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
3366 | } | |
3367 | } | |
3368 | ||
3369 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
3370 | if (attr) | |
3371 | { | |
3372 | bfd *obfd = cu->objfile->obfd; | |
3373 | ||
3374 | /* The value of the DW_AT_ranges attribute is the offset of the | |
3375 | address range list in the .debug_ranges section. */ | |
3376 | unsigned long offset = DW_UNSND (attr); | |
3377 | gdb_byte *buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3378 | ||
3379 | /* For some target architectures, but not others, the | |
3380 | read_address function sign-extends the addresses it returns. | |
3381 | To recognize base address selection entries, we need a | |
3382 | mask. */ | |
3383 | unsigned int addr_size = cu->header.addr_size; | |
3384 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3385 | ||
3386 | /* The base address, to which the next pair is relative. Note | |
3387 | that this 'base' is a DWARF concept: most entries in a range | |
3388 | list are relative, to reduce the number of relocs against the | |
3389 | debugging information. This is separate from this function's | |
3390 | 'baseaddr' argument, which GDB uses to relocate debugging | |
3391 | information from a shared library based on the address at | |
3392 | which the library was loaded. */ | |
3393 | CORE_ADDR base = cu->header.base_address; | |
3394 | int base_known = cu->header.base_known; | |
3395 | ||
3396 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3397 | { | |
3398 | complaint (&symfile_complaints, | |
3399 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
3400 | offset); | |
3401 | return; | |
3402 | } | |
3403 | ||
3404 | for (;;) | |
3405 | { | |
3406 | unsigned int bytes_read; | |
3407 | CORE_ADDR start, end; | |
3408 | ||
3409 | start = read_address (obfd, buffer, cu, &bytes_read); | |
3410 | buffer += bytes_read; | |
3411 | end = read_address (obfd, buffer, cu, &bytes_read); | |
3412 | buffer += bytes_read; | |
3413 | ||
3414 | /* Did we find the end of the range list? */ | |
3415 | if (start == 0 && end == 0) | |
3416 | break; | |
3417 | ||
3418 | /* Did we find a base address selection entry? */ | |
3419 | else if ((start & base_select_mask) == base_select_mask) | |
3420 | { | |
3421 | base = end; | |
3422 | base_known = 1; | |
3423 | } | |
3424 | ||
3425 | /* We found an ordinary address range. */ | |
3426 | else | |
3427 | { | |
3428 | if (!base_known) | |
3429 | { | |
3430 | complaint (&symfile_complaints, | |
3431 | _("Invalid .debug_ranges data (no base address)")); | |
3432 | return; | |
3433 | } | |
3434 | ||
3435 | record_block_range (block, | |
3436 | baseaddr + base + start, | |
3437 | baseaddr + base + end - 1); | |
3438 | } | |
3439 | } | |
3440 | } | |
3441 | } | |
3442 | ||
c906108c SS |
3443 | /* Add an aggregate field to the field list. */ |
3444 | ||
3445 | static void | |
107d2387 | 3446 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3447 | struct dwarf2_cu *cu) |
3448 | { | |
3449 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 3450 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
3451 | struct nextfield *new_field; |
3452 | struct attribute *attr; | |
3453 | struct field *fp; | |
3454 | char *fieldname = ""; | |
3455 | ||
3456 | /* Allocate a new field list entry and link it in. */ | |
3457 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3458 | make_cleanup (xfree, new_field); |
c906108c SS |
3459 | memset (new_field, 0, sizeof (struct nextfield)); |
3460 | new_field->next = fip->fields; | |
3461 | fip->fields = new_field; | |
3462 | fip->nfields++; | |
3463 | ||
3464 | /* Handle accessibility and virtuality of field. | |
3465 | The default accessibility for members is public, the default | |
3466 | accessibility for inheritance is private. */ | |
3467 | if (die->tag != DW_TAG_inheritance) | |
3468 | new_field->accessibility = DW_ACCESS_public; | |
3469 | else | |
3470 | new_field->accessibility = DW_ACCESS_private; | |
3471 | new_field->virtuality = DW_VIRTUALITY_none; | |
3472 | ||
e142c38c | 3473 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3474 | if (attr) |
3475 | new_field->accessibility = DW_UNSND (attr); | |
3476 | if (new_field->accessibility != DW_ACCESS_public) | |
3477 | fip->non_public_fields = 1; | |
e142c38c | 3478 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3479 | if (attr) |
3480 | new_field->virtuality = DW_UNSND (attr); | |
3481 | ||
3482 | fp = &new_field->field; | |
a9a9bd0f | 3483 | |
e142c38c | 3484 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3485 | { |
a9a9bd0f DC |
3486 | /* Data member other than a C++ static data member. */ |
3487 | ||
c906108c | 3488 | /* Get type of field. */ |
e7c27a73 | 3489 | fp->type = die_type (die, cu); |
c906108c | 3490 | |
01ad7f36 DJ |
3491 | FIELD_STATIC_KIND (*fp) = 0; |
3492 | ||
c906108c | 3493 | /* Get bit size of field (zero if none). */ |
e142c38c | 3494 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3495 | if (attr) |
3496 | { | |
3497 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3498 | } | |
3499 | else | |
3500 | { | |
3501 | FIELD_BITSIZE (*fp) = 0; | |
3502 | } | |
3503 | ||
3504 | /* Get bit offset of field. */ | |
e142c38c | 3505 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3506 | if (attr) |
3507 | { | |
c6a0999f JB |
3508 | int byte_offset; |
3509 | ||
3690dd37 JB |
3510 | if (attr_form_is_section_offset (attr)) |
3511 | { | |
3512 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 3513 | byte_offset = 0; |
3690dd37 JB |
3514 | } |
3515 | else if (attr_form_is_constant (attr)) | |
c6a0999f | 3516 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
3690dd37 | 3517 | else |
c6a0999f JB |
3518 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
3519 | ||
3520 | FIELD_BITPOS (*fp) = byte_offset * bits_per_byte; | |
c906108c SS |
3521 | } |
3522 | else | |
3523 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 3524 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3525 | if (attr) |
3526 | { | |
5e2b427d | 3527 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
3528 | { |
3529 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3530 | additional bit offset from the MSB of the containing |
3531 | anonymous object to the MSB of the field. We don't | |
3532 | have to do anything special since we don't need to | |
3533 | know the size of the anonymous object. */ | |
c906108c SS |
3534 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3535 | } | |
3536 | else | |
3537 | { | |
3538 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3539 | MSB of the anonymous object, subtract off the number of |
3540 | bits from the MSB of the field to the MSB of the | |
3541 | object, and then subtract off the number of bits of | |
3542 | the field itself. The result is the bit offset of | |
3543 | the LSB of the field. */ | |
c906108c SS |
3544 | int anonymous_size; |
3545 | int bit_offset = DW_UNSND (attr); | |
3546 | ||
e142c38c | 3547 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3548 | if (attr) |
3549 | { | |
3550 | /* The size of the anonymous object containing | |
3551 | the bit field is explicit, so use the | |
3552 | indicated size (in bytes). */ | |
3553 | anonymous_size = DW_UNSND (attr); | |
3554 | } | |
3555 | else | |
3556 | { | |
3557 | /* The size of the anonymous object containing | |
3558 | the bit field must be inferred from the type | |
3559 | attribute of the data member containing the | |
3560 | bit field. */ | |
3561 | anonymous_size = TYPE_LENGTH (fp->type); | |
3562 | } | |
3563 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3564 | - bit_offset - FIELD_BITSIZE (*fp); | |
3565 | } | |
3566 | } | |
3567 | ||
3568 | /* Get name of field. */ | |
39cbfefa DJ |
3569 | fieldname = dwarf2_name (die, cu); |
3570 | if (fieldname == NULL) | |
3571 | fieldname = ""; | |
d8151005 DJ |
3572 | |
3573 | /* The name is already allocated along with this objfile, so we don't | |
3574 | need to duplicate it for the type. */ | |
3575 | fp->name = fieldname; | |
c906108c SS |
3576 | |
3577 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3578 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3579 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3580 | { |
3581 | new_field->accessibility = DW_ACCESS_private; | |
3582 | fip->non_public_fields = 1; | |
3583 | } | |
3584 | } | |
a9a9bd0f | 3585 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3586 | { |
a9a9bd0f DC |
3587 | /* C++ static member. */ |
3588 | ||
3589 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3590 | is a declaration, but all versions of G++ as of this writing | |
3591 | (so through at least 3.2.1) incorrectly generate | |
3592 | DW_TAG_variable tags. */ | |
3593 | ||
c906108c | 3594 | char *physname; |
c906108c | 3595 | |
a9a9bd0f | 3596 | /* Get name of field. */ |
39cbfefa DJ |
3597 | fieldname = dwarf2_name (die, cu); |
3598 | if (fieldname == NULL) | |
c906108c SS |
3599 | return; |
3600 | ||
2df3850c | 3601 | /* Get physical name. */ |
e142c38c | 3602 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3603 | |
d8151005 DJ |
3604 | /* The name is already allocated along with this objfile, so we don't |
3605 | need to duplicate it for the type. */ | |
3606 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3607 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3608 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3609 | } |
3610 | else if (die->tag == DW_TAG_inheritance) | |
3611 | { | |
3612 | /* C++ base class field. */ | |
e142c38c | 3613 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3614 | if (attr) |
e7c27a73 | 3615 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 3616 | * bits_per_byte); |
c906108c | 3617 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 3618 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 3619 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3620 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3621 | fip->nbaseclasses++; | |
3622 | } | |
3623 | } | |
3624 | ||
3625 | /* Create the vector of fields, and attach it to the type. */ | |
3626 | ||
3627 | static void | |
fba45db2 | 3628 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3629 | struct dwarf2_cu *cu) |
c906108c SS |
3630 | { |
3631 | int nfields = fip->nfields; | |
3632 | ||
3633 | /* Record the field count, allocate space for the array of fields, | |
3634 | and create blank accessibility bitfields if necessary. */ | |
3635 | TYPE_NFIELDS (type) = nfields; | |
3636 | TYPE_FIELDS (type) = (struct field *) | |
3637 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3638 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3639 | ||
3640 | if (fip->non_public_fields) | |
3641 | { | |
3642 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3643 | ||
3644 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3645 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3646 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3647 | ||
3648 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3649 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3650 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3651 | ||
3652 | TYPE_FIELD_IGNORE_BITS (type) = | |
3653 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3654 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3655 | } | |
3656 | ||
3657 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3658 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3659 | if (fip->nbaseclasses) | |
3660 | { | |
3661 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 3662 | unsigned char *pointer; |
c906108c SS |
3663 | |
3664 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
3665 | pointer = TYPE_ALLOC (type, num_bytes); |
3666 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
3667 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
3668 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3669 | } | |
3670 | ||
3671 | /* Copy the saved-up fields into the field vector. Start from the head | |
3672 | of the list, adding to the tail of the field array, so that they end | |
3673 | up in the same order in the array in which they were added to the list. */ | |
3674 | while (nfields-- > 0) | |
3675 | { | |
3676 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3677 | switch (fip->fields->accessibility) | |
3678 | { | |
c5aa993b JM |
3679 | case DW_ACCESS_private: |
3680 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3681 | break; | |
c906108c | 3682 | |
c5aa993b JM |
3683 | case DW_ACCESS_protected: |
3684 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3685 | break; | |
c906108c | 3686 | |
c5aa993b JM |
3687 | case DW_ACCESS_public: |
3688 | break; | |
c906108c | 3689 | |
c5aa993b JM |
3690 | default: |
3691 | /* Unknown accessibility. Complain and treat it as public. */ | |
3692 | { | |
e2e0b3e5 | 3693 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 3694 | fip->fields->accessibility); |
c5aa993b JM |
3695 | } |
3696 | break; | |
c906108c SS |
3697 | } |
3698 | if (nfields < fip->nbaseclasses) | |
3699 | { | |
3700 | switch (fip->fields->virtuality) | |
3701 | { | |
c5aa993b JM |
3702 | case DW_VIRTUALITY_virtual: |
3703 | case DW_VIRTUALITY_pure_virtual: | |
3704 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3705 | break; | |
c906108c SS |
3706 | } |
3707 | } | |
3708 | fip->fields = fip->fields->next; | |
3709 | } | |
3710 | } | |
3711 | ||
c906108c SS |
3712 | /* Add a member function to the proper fieldlist. */ |
3713 | ||
3714 | static void | |
107d2387 | 3715 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3716 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3717 | { |
e7c27a73 | 3718 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3719 | struct attribute *attr; |
3720 | struct fnfieldlist *flp; | |
3721 | int i; | |
3722 | struct fn_field *fnp; | |
3723 | char *fieldname; | |
3724 | char *physname; | |
3725 | struct nextfnfield *new_fnfield; | |
f792889a | 3726 | struct type *this_type; |
c906108c | 3727 | |
2df3850c | 3728 | /* Get name of member function. */ |
39cbfefa DJ |
3729 | fieldname = dwarf2_name (die, cu); |
3730 | if (fieldname == NULL) | |
2df3850c | 3731 | return; |
c906108c | 3732 | |
2df3850c | 3733 | /* Get the mangled name. */ |
e142c38c | 3734 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3735 | |
3736 | /* Look up member function name in fieldlist. */ | |
3737 | for (i = 0; i < fip->nfnfields; i++) | |
3738 | { | |
27bfe10e | 3739 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3740 | break; |
3741 | } | |
3742 | ||
3743 | /* Create new list element if necessary. */ | |
3744 | if (i < fip->nfnfields) | |
3745 | flp = &fip->fnfieldlists[i]; | |
3746 | else | |
3747 | { | |
3748 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3749 | { | |
3750 | fip->fnfieldlists = (struct fnfieldlist *) | |
3751 | xrealloc (fip->fnfieldlists, | |
3752 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3753 | * sizeof (struct fnfieldlist)); |
c906108c | 3754 | if (fip->nfnfields == 0) |
c13c43fd | 3755 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3756 | } |
3757 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3758 | flp->name = fieldname; | |
3759 | flp->length = 0; | |
3760 | flp->head = NULL; | |
3761 | fip->nfnfields++; | |
3762 | } | |
3763 | ||
3764 | /* Create a new member function field and chain it to the field list | |
3765 | entry. */ | |
3766 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3767 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3768 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3769 | new_fnfield->next = flp->head; | |
3770 | flp->head = new_fnfield; | |
3771 | flp->length++; | |
3772 | ||
3773 | /* Fill in the member function field info. */ | |
3774 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3775 | /* The name is already allocated along with this objfile, so we don't |
3776 | need to duplicate it for the type. */ | |
3777 | fnp->physname = physname ? physname : ""; | |
c906108c | 3778 | fnp->type = alloc_type (objfile); |
f792889a DJ |
3779 | this_type = read_type_die (die, cu); |
3780 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 3781 | { |
f792889a | 3782 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 3783 | |
f792889a | 3784 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
3785 | of the method itself (TYPE_CODE_METHOD). */ |
3786 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
3787 | TYPE_TARGET_TYPE (this_type), |
3788 | TYPE_FIELDS (this_type), | |
3789 | TYPE_NFIELDS (this_type), | |
3790 | TYPE_VARARGS (this_type)); | |
c906108c SS |
3791 | |
3792 | /* Handle static member functions. | |
c5aa993b JM |
3793 | Dwarf2 has no clean way to discern C++ static and non-static |
3794 | member functions. G++ helps GDB by marking the first | |
3795 | parameter for non-static member functions (which is the | |
3796 | this pointer) as artificial. We obtain this information | |
3797 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 3798 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
3799 | fnp->voffset = VOFFSET_STATIC; |
3800 | } | |
3801 | else | |
e2e0b3e5 | 3802 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 3803 | physname); |
c906108c SS |
3804 | |
3805 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3806 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3807 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3808 | |
3809 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3810 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3811 | ||
3812 | /* Get accessibility. */ | |
e142c38c | 3813 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3814 | if (attr) |
3815 | { | |
3816 | switch (DW_UNSND (attr)) | |
3817 | { | |
c5aa993b JM |
3818 | case DW_ACCESS_private: |
3819 | fnp->is_private = 1; | |
3820 | break; | |
3821 | case DW_ACCESS_protected: | |
3822 | fnp->is_protected = 1; | |
3823 | break; | |
c906108c SS |
3824 | } |
3825 | } | |
3826 | ||
b02dede2 | 3827 | /* Check for artificial methods. */ |
e142c38c | 3828 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3829 | if (attr && DW_UNSND (attr) != 0) |
3830 | fnp->is_artificial = 1; | |
3831 | ||
c906108c | 3832 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3833 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3834 | if (attr) |
8e19ed76 PS |
3835 | { |
3836 | /* Support the .debug_loc offsets */ | |
3837 | if (attr_form_is_block (attr)) | |
3838 | { | |
e7c27a73 | 3839 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 3840 | } |
3690dd37 | 3841 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 3842 | { |
4d3c2250 | 3843 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3844 | } |
3845 | else | |
3846 | { | |
4d3c2250 KB |
3847 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3848 | fieldname); | |
8e19ed76 PS |
3849 | } |
3850 | } | |
c906108c SS |
3851 | } |
3852 | ||
3853 | /* Create the vector of member function fields, and attach it to the type. */ | |
3854 | ||
3855 | static void | |
fba45db2 | 3856 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3857 | struct dwarf2_cu *cu) |
c906108c SS |
3858 | { |
3859 | struct fnfieldlist *flp; | |
3860 | int total_length = 0; | |
3861 | int i; | |
3862 | ||
3863 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3864 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3865 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3866 | ||
3867 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3868 | { | |
3869 | struct nextfnfield *nfp = flp->head; | |
3870 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3871 | int k; | |
3872 | ||
3873 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3874 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3875 | fn_flp->fn_fields = (struct fn_field *) | |
3876 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3877 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3878 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3879 | |
3880 | total_length += flp->length; | |
3881 | } | |
3882 | ||
3883 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3884 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3885 | } | |
3886 | ||
1168df01 JB |
3887 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
3888 | language, zero otherwise. */ | |
3889 | static int | |
3890 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
3891 | { | |
3892 | static const char vptr[] = "_vptr"; | |
987504bb | 3893 | static const char vtable[] = "vtable"; |
1168df01 | 3894 | |
987504bb JJ |
3895 | /* Look for the C++ and Java forms of the vtable. */ |
3896 | if ((cu->language == language_java | |
3897 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
3898 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
3899 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
3900 | return 1; |
3901 | ||
3902 | return 0; | |
3903 | } | |
3904 | ||
c0dd20ea DJ |
3905 | /* GCC outputs unnamed structures that are really pointers to member |
3906 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
3907 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
3908 | zero. |
3909 | ||
3910 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
3911 | This is GCC PR debug/28767. */ | |
c0dd20ea | 3912 | |
f792889a | 3913 | static struct type * |
c0dd20ea DJ |
3914 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
3915 | { | |
3916 | struct objfile *objfile = cu->objfile; | |
3917 | struct type *type; | |
3918 | struct die_info *pfn_die, *delta_die; | |
3919 | struct attribute *pfn_name, *delta_name; | |
3920 | struct type *pfn_type, *domain_type; | |
3921 | ||
3922 | /* Check for a structure with no name and two children. */ | |
3923 | if (die->tag != DW_TAG_structure_type | |
3924 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
3925 | || die->child == NULL | |
3926 | || die->child->sibling == NULL | |
3927 | || (die->child->sibling->sibling != NULL | |
3928 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 3929 | return NULL; |
c0dd20ea DJ |
3930 | |
3931 | /* Check for __pfn and __delta members. */ | |
3932 | pfn_die = die->child; | |
3933 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
3934 | if (pfn_die->tag != DW_TAG_member | |
3935 | || pfn_name == NULL | |
3936 | || DW_STRING (pfn_name) == NULL | |
3937 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 3938 | return NULL; |
c0dd20ea DJ |
3939 | |
3940 | delta_die = pfn_die->sibling; | |
3941 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
3942 | if (delta_die->tag != DW_TAG_member | |
3943 | || delta_name == NULL | |
3944 | || DW_STRING (delta_name) == NULL | |
3945 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 3946 | return NULL; |
c0dd20ea DJ |
3947 | |
3948 | /* Find the type of the method. */ | |
3949 | pfn_type = die_type (pfn_die, cu); | |
3950 | if (pfn_type == NULL | |
3951 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
3952 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 3953 | return NULL; |
c0dd20ea DJ |
3954 | |
3955 | /* Look for the "this" argument. */ | |
3956 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
3957 | if (TYPE_NFIELDS (pfn_type) == 0 | |
3958 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 3959 | return NULL; |
c0dd20ea DJ |
3960 | |
3961 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
3962 | type = alloc_type (objfile); | |
3963 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
3964 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
3965 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 3966 | type = lookup_methodptr_type (type); |
f792889a | 3967 | return set_die_type (die, type, cu); |
c0dd20ea | 3968 | } |
1168df01 | 3969 | |
c906108c SS |
3970 | /* Called when we find the DIE that starts a structure or union scope |
3971 | (definition) to process all dies that define the members of the | |
3972 | structure or union. | |
3973 | ||
3974 | NOTE: we need to call struct_type regardless of whether or not the | |
3975 | DIE has an at_name attribute, since it might be an anonymous | |
3976 | structure or union. This gets the type entered into our set of | |
3977 | user defined types. | |
3978 | ||
3979 | However, if the structure is incomplete (an opaque struct/union) | |
3980 | then suppress creating a symbol table entry for it since gdb only | |
3981 | wants to find the one with the complete definition. Note that if | |
3982 | it is complete, we just call new_symbol, which does it's own | |
3983 | checking about whether the struct/union is anonymous or not (and | |
3984 | suppresses creating a symbol table entry itself). */ | |
3985 | ||
f792889a | 3986 | static struct type * |
134d01f1 | 3987 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3988 | { |
e7c27a73 | 3989 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3990 | struct type *type; |
3991 | struct attribute *attr; | |
63d06c5c DC |
3992 | const char *previous_prefix = processing_current_prefix; |
3993 | struct cleanup *back_to = NULL; | |
39cbfefa | 3994 | char *name; |
c906108c | 3995 | |
f792889a DJ |
3996 | type = quirk_gcc_member_function_pointer (die, cu); |
3997 | if (type) | |
3998 | return type; | |
c906108c | 3999 | |
c0dd20ea | 4000 | type = alloc_type (objfile); |
c906108c | 4001 | INIT_CPLUS_SPECIFIC (type); |
39cbfefa DJ |
4002 | name = dwarf2_name (die, cu); |
4003 | if (name != NULL) | |
c906108c | 4004 | { |
987504bb JJ |
4005 | if (cu->language == language_cplus |
4006 | || cu->language == language_java) | |
63d06c5c | 4007 | { |
8176b9b8 DC |
4008 | char *new_prefix = determine_class_name (die, cu); |
4009 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
4010 | strlen (new_prefix), | |
4011 | &objfile->objfile_obstack); | |
4012 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
4013 | processing_current_prefix = new_prefix; |
4014 | } | |
4015 | else | |
4016 | { | |
d8151005 DJ |
4017 | /* The name is already allocated along with this objfile, so |
4018 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4019 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4020 | } |
c906108c SS |
4021 | } |
4022 | ||
4023 | if (die->tag == DW_TAG_structure_type) | |
4024 | { | |
4025 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4026 | } | |
4027 | else if (die->tag == DW_TAG_union_type) | |
4028 | { | |
4029 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4030 | } | |
4031 | else | |
4032 | { | |
4033 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 4034 | in gdbtypes.h. */ |
c906108c SS |
4035 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
4036 | } | |
4037 | ||
e142c38c | 4038 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4039 | if (attr) |
4040 | { | |
4041 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4042 | } | |
4043 | else | |
4044 | { | |
4045 | TYPE_LENGTH (type) = 0; | |
4046 | } | |
4047 | ||
d77b6808 | 4048 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB_SUPPORTED; |
dc718098 JB |
4049 | if (die_is_declaration (die, cu)) |
4050 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4051 | ||
c906108c SS |
4052 | /* We need to add the type field to the die immediately so we don't |
4053 | infinitely recurse when dealing with pointers to the structure | |
4054 | type within the structure itself. */ | |
1c379e20 | 4055 | set_die_type (die, type, cu); |
c906108c | 4056 | |
e142c38c | 4057 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
4058 | { |
4059 | struct field_info fi; | |
4060 | struct die_info *child_die; | |
4061 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
4062 | ||
4063 | memset (&fi, 0, sizeof (struct field_info)); | |
4064 | ||
639d11d3 | 4065 | child_die = die->child; |
c906108c SS |
4066 | |
4067 | while (child_die && child_die->tag) | |
4068 | { | |
a9a9bd0f DC |
4069 | if (child_die->tag == DW_TAG_member |
4070 | || child_die->tag == DW_TAG_variable) | |
c906108c | 4071 | { |
a9a9bd0f DC |
4072 | /* NOTE: carlton/2002-11-05: A C++ static data member |
4073 | should be a DW_TAG_member that is a declaration, but | |
4074 | all versions of G++ as of this writing (so through at | |
4075 | least 3.2.1) incorrectly generate DW_TAG_variable | |
4076 | tags for them instead. */ | |
e7c27a73 | 4077 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4078 | } |
8713b1b1 | 4079 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
4080 | { |
4081 | /* C++ member function. */ | |
e7c27a73 | 4082 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
4083 | } |
4084 | else if (child_die->tag == DW_TAG_inheritance) | |
4085 | { | |
4086 | /* C++ base class field. */ | |
e7c27a73 | 4087 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4088 | } |
c906108c SS |
4089 | child_die = sibling_die (child_die); |
4090 | } | |
4091 | ||
4092 | /* Attach fields and member functions to the type. */ | |
4093 | if (fi.nfields) | |
e7c27a73 | 4094 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
4095 | if (fi.nfnfields) |
4096 | { | |
e7c27a73 | 4097 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 4098 | |
c5aa993b | 4099 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
4100 | class itself) which contains the vtable pointer for the current |
4101 | class from the DW_AT_containing_type attribute. */ | |
4102 | ||
e142c38c | 4103 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 4104 | { |
e7c27a73 | 4105 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
4106 | |
4107 | TYPE_VPTR_BASETYPE (type) = t; | |
4108 | if (type == t) | |
4109 | { | |
c906108c SS |
4110 | int i; |
4111 | ||
4112 | /* Our own class provides vtbl ptr. */ | |
4113 | for (i = TYPE_NFIELDS (t) - 1; | |
4114 | i >= TYPE_N_BASECLASSES (t); | |
4115 | --i) | |
4116 | { | |
4117 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
4118 | ||
1168df01 | 4119 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
4120 | { |
4121 | TYPE_VPTR_FIELDNO (type) = i; | |
4122 | break; | |
4123 | } | |
4124 | } | |
4125 | ||
4126 | /* Complain if virtual function table field not found. */ | |
4127 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 4128 | complaint (&symfile_complaints, |
e2e0b3e5 | 4129 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
4130 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
4131 | ""); | |
c906108c SS |
4132 | } |
4133 | else | |
4134 | { | |
4135 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4136 | } | |
4137 | } | |
f6235d4c EZ |
4138 | else if (cu->producer |
4139 | && strncmp (cu->producer, | |
4140 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
4141 | { | |
4142 | /* The IBM XLC compiler does not provide direct indication | |
4143 | of the containing type, but the vtable pointer is | |
4144 | always named __vfp. */ | |
4145 | ||
4146 | int i; | |
4147 | ||
4148 | for (i = TYPE_NFIELDS (type) - 1; | |
4149 | i >= TYPE_N_BASECLASSES (type); | |
4150 | --i) | |
4151 | { | |
4152 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
4153 | { | |
4154 | TYPE_VPTR_FIELDNO (type) = i; | |
4155 | TYPE_VPTR_BASETYPE (type) = type; | |
4156 | break; | |
4157 | } | |
4158 | } | |
4159 | } | |
c906108c SS |
4160 | } |
4161 | ||
c906108c SS |
4162 | do_cleanups (back_to); |
4163 | } | |
63d06c5c DC |
4164 | |
4165 | processing_current_prefix = previous_prefix; | |
4166 | if (back_to != NULL) | |
4167 | do_cleanups (back_to); | |
f792889a DJ |
4168 | |
4169 | return type; | |
c906108c SS |
4170 | } |
4171 | ||
134d01f1 DJ |
4172 | static void |
4173 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4174 | { | |
4175 | struct objfile *objfile = cu->objfile; | |
4176 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 4177 | struct die_info *child_die = die->child; |
f792889a | 4178 | struct type *this_type; |
c906108c | 4179 | |
f792889a DJ |
4180 | this_type = get_die_type (die, cu); |
4181 | if (this_type == NULL) | |
4182 | this_type = read_structure_type (die, cu); | |
4183 | if (TYPE_TAG_NAME (this_type) != NULL) | |
4184 | processing_current_prefix = TYPE_TAG_NAME (this_type); | |
c906108c | 4185 | |
90aeadfc DC |
4186 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4187 | snapshots) has been known to create a die giving a declaration | |
4188 | for a class that has, as a child, a die giving a definition for a | |
4189 | nested class. So we have to process our children even if the | |
4190 | current die is a declaration. Normally, of course, a declaration | |
4191 | won't have any children at all. */ | |
134d01f1 | 4192 | |
90aeadfc DC |
4193 | while (child_die != NULL && child_die->tag) |
4194 | { | |
4195 | if (child_die->tag == DW_TAG_member | |
4196 | || child_die->tag == DW_TAG_variable | |
4197 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4198 | { |
90aeadfc | 4199 | /* Do nothing. */ |
134d01f1 | 4200 | } |
90aeadfc DC |
4201 | else |
4202 | process_die (child_die, cu); | |
134d01f1 | 4203 | |
90aeadfc | 4204 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4205 | } |
4206 | ||
fa4028e9 JB |
4207 | /* Do not consider external references. According to the DWARF standard, |
4208 | these DIEs are identified by the fact that they have no byte_size | |
4209 | attribute, and a declaration attribute. */ | |
4210 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4211 | || !die_is_declaration (die, cu)) | |
f792889a | 4212 | new_symbol (die, this_type, cu); |
90aeadfc | 4213 | |
134d01f1 DJ |
4214 | processing_current_prefix = previous_prefix; |
4215 | } | |
4216 | ||
4217 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4218 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 4219 | |
f792889a | 4220 | static struct type * |
134d01f1 | 4221 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4222 | { |
e7c27a73 | 4223 | struct objfile *objfile = cu->objfile; |
c906108c | 4224 | struct type *type; |
c906108c | 4225 | struct attribute *attr; |
39cbfefa | 4226 | char *name; |
134d01f1 | 4227 | |
c906108c SS |
4228 | type = alloc_type (objfile); |
4229 | ||
4230 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
39cbfefa DJ |
4231 | name = dwarf2_name (die, cu); |
4232 | if (name != NULL) | |
c906108c | 4233 | { |
63d06c5c DC |
4234 | if (processing_has_namespace_info) |
4235 | { | |
987504bb JJ |
4236 | TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack, |
4237 | processing_current_prefix, | |
4238 | name, cu); | |
63d06c5c DC |
4239 | } |
4240 | else | |
4241 | { | |
d8151005 DJ |
4242 | /* The name is already allocated along with this objfile, so |
4243 | we don't need to duplicate it for the type. */ | |
4244 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 4245 | } |
c906108c SS |
4246 | } |
4247 | ||
e142c38c | 4248 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4249 | if (attr) |
4250 | { | |
4251 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4252 | } | |
4253 | else | |
4254 | { | |
4255 | TYPE_LENGTH (type) = 0; | |
4256 | } | |
4257 | ||
137033e9 JB |
4258 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
4259 | declared as private in the package spec, and then defined only | |
4260 | inside the package body. Such types are known as Taft Amendment | |
4261 | Types. When another package uses such a type, an incomplete DIE | |
4262 | may be generated by the compiler. */ | |
02eb380e JB |
4263 | if (die_is_declaration (die, cu)) |
4264 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4265 | ||
f792889a | 4266 | return set_die_type (die, type, cu); |
134d01f1 DJ |
4267 | } |
4268 | ||
8176b9b8 | 4269 | /* Determine the name of the type represented by DIE, which should be |
987504bb | 4270 | a named C++ or Java compound type. Return the name in question; the caller |
8176b9b8 DC |
4271 | is responsible for xfree()'ing it. */ |
4272 | ||
4273 | static char * | |
4274 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
4275 | { | |
4276 | struct cleanup *back_to = NULL; | |
f2f0e013 DJ |
4277 | struct dwarf2_cu *spec_cu = cu; |
4278 | struct die_info *spec_die = die_specification (die, &spec_cu); | |
8176b9b8 DC |
4279 | char *new_prefix = NULL; |
4280 | ||
4281 | /* If this is the definition of a class that is declared by another | |
4282 | die, then processing_current_prefix may not be accurate; see | |
4283 | read_func_scope for a similar example. */ | |
4284 | if (spec_die != NULL) | |
4285 | { | |
f2f0e013 | 4286 | char *specification_prefix = determine_prefix (spec_die, spec_cu); |
8176b9b8 DC |
4287 | processing_current_prefix = specification_prefix; |
4288 | back_to = make_cleanup (xfree, specification_prefix); | |
4289 | } | |
4290 | ||
4291 | /* If we don't have namespace debug info, guess the name by trying | |
4292 | to demangle the names of members, just like we did in | |
72bf9492 | 4293 | guess_structure_name. */ |
8176b9b8 DC |
4294 | if (!processing_has_namespace_info) |
4295 | { | |
4296 | struct die_info *child; | |
4297 | ||
4298 | for (child = die->child; | |
4299 | child != NULL && child->tag != 0; | |
4300 | child = sibling_die (child)) | |
4301 | { | |
4302 | if (child->tag == DW_TAG_subprogram) | |
4303 | { | |
31c27f77 JJ |
4304 | new_prefix |
4305 | = language_class_name_from_physname (cu->language_defn, | |
4306 | dwarf2_linkage_name | |
8176b9b8 DC |
4307 | (child, cu)); |
4308 | ||
4309 | if (new_prefix != NULL) | |
4310 | break; | |
4311 | } | |
4312 | } | |
4313 | } | |
4314 | ||
4315 | if (new_prefix == NULL) | |
4316 | { | |
4317 | const char *name = dwarf2_name (die, cu); | |
987504bb JJ |
4318 | new_prefix = typename_concat (NULL, processing_current_prefix, |
4319 | name ? name : "<<anonymous>>", | |
4320 | cu); | |
8176b9b8 DC |
4321 | } |
4322 | ||
4323 | if (back_to != NULL) | |
4324 | do_cleanups (back_to); | |
4325 | ||
4326 | return new_prefix; | |
4327 | } | |
4328 | ||
134d01f1 DJ |
4329 | /* Given a pointer to a die which begins an enumeration, process all |
4330 | the dies that define the members of the enumeration, and create the | |
4331 | symbol for the enumeration type. | |
4332 | ||
4333 | NOTE: We reverse the order of the element list. */ | |
4334 | ||
4335 | static void | |
4336 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4337 | { | |
4338 | struct objfile *objfile = cu->objfile; | |
4339 | struct die_info *child_die; | |
4340 | struct field *fields; | |
134d01f1 DJ |
4341 | struct symbol *sym; |
4342 | int num_fields; | |
4343 | int unsigned_enum = 1; | |
39cbfefa | 4344 | char *name; |
f792889a | 4345 | struct type *this_type; |
134d01f1 | 4346 | |
c906108c SS |
4347 | num_fields = 0; |
4348 | fields = NULL; | |
f792889a DJ |
4349 | this_type = get_die_type (die, cu); |
4350 | if (this_type == NULL) | |
4351 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 4352 | if (die->child != NULL) |
c906108c | 4353 | { |
639d11d3 | 4354 | child_die = die->child; |
c906108c SS |
4355 | while (child_die && child_die->tag) |
4356 | { | |
4357 | if (child_die->tag != DW_TAG_enumerator) | |
4358 | { | |
e7c27a73 | 4359 | process_die (child_die, cu); |
c906108c SS |
4360 | } |
4361 | else | |
4362 | { | |
39cbfefa DJ |
4363 | name = dwarf2_name (child_die, cu); |
4364 | if (name) | |
c906108c | 4365 | { |
f792889a | 4366 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
4367 | if (SYMBOL_VALUE (sym) < 0) |
4368 | unsigned_enum = 0; | |
4369 | ||
4370 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4371 | { | |
4372 | fields = (struct field *) | |
4373 | xrealloc (fields, | |
4374 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4375 | * sizeof (struct field)); |
c906108c SS |
4376 | } |
4377 | ||
22abf04a | 4378 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
4379 | FIELD_TYPE (fields[num_fields]) = NULL; |
4380 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
4381 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 4382 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
4383 | |
4384 | num_fields++; | |
4385 | } | |
4386 | } | |
4387 | ||
4388 | child_die = sibling_die (child_die); | |
4389 | } | |
4390 | ||
4391 | if (num_fields) | |
4392 | { | |
f792889a DJ |
4393 | TYPE_NFIELDS (this_type) = num_fields; |
4394 | TYPE_FIELDS (this_type) = (struct field *) | |
4395 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
4396 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 4397 | sizeof (struct field) * num_fields); |
b8c9b27d | 4398 | xfree (fields); |
c906108c SS |
4399 | } |
4400 | if (unsigned_enum) | |
f792889a | 4401 | TYPE_FLAGS (this_type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 4402 | } |
134d01f1 | 4403 | |
f792889a | 4404 | new_symbol (die, this_type, cu); |
c906108c SS |
4405 | } |
4406 | ||
4407 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4408 | the DIE's type field. For now, this only handles one dimensional | |
4409 | arrays. */ | |
4410 | ||
f792889a | 4411 | static struct type * |
e7c27a73 | 4412 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4413 | { |
e7c27a73 | 4414 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4415 | struct die_info *child_die; |
4416 | struct type *type = NULL; | |
4417 | struct type *element_type, *range_type, *index_type; | |
4418 | struct type **range_types = NULL; | |
4419 | struct attribute *attr; | |
4420 | int ndim = 0; | |
4421 | struct cleanup *back_to; | |
39cbfefa | 4422 | char *name; |
c906108c | 4423 | |
e7c27a73 | 4424 | element_type = die_type (die, cu); |
c906108c SS |
4425 | |
4426 | /* Irix 6.2 native cc creates array types without children for | |
4427 | arrays with unspecified length. */ | |
639d11d3 | 4428 | if (die->child == NULL) |
c906108c | 4429 | { |
6ccb9162 | 4430 | index_type = builtin_type_int32; |
c906108c | 4431 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
4432 | type = create_array_type (NULL, element_type, range_type); |
4433 | return set_die_type (die, type, cu); | |
c906108c SS |
4434 | } |
4435 | ||
4436 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4437 | child_die = die->child; |
c906108c SS |
4438 | while (child_die && child_die->tag) |
4439 | { | |
4440 | if (child_die->tag == DW_TAG_subrange_type) | |
4441 | { | |
f792889a DJ |
4442 | struct type *child_type = read_type_die (child_die, cu); |
4443 | if (child_type != NULL) | |
a02abb62 JB |
4444 | { |
4445 | /* The range type was succesfully read. Save it for | |
4446 | the array type creation. */ | |
4447 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4448 | { | |
4449 | range_types = (struct type **) | |
4450 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4451 | * sizeof (struct type *)); | |
4452 | if (ndim == 0) | |
4453 | make_cleanup (free_current_contents, &range_types); | |
4454 | } | |
f792889a | 4455 | range_types[ndim++] = child_type; |
a02abb62 | 4456 | } |
c906108c SS |
4457 | } |
4458 | child_die = sibling_die (child_die); | |
4459 | } | |
4460 | ||
4461 | /* Dwarf2 dimensions are output from left to right, create the | |
4462 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4463 | |
c906108c | 4464 | type = element_type; |
7ca2d3a3 DL |
4465 | |
4466 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4467 | { | |
4468 | int i = 0; | |
4469 | while (i < ndim) | |
4470 | type = create_array_type (NULL, type, range_types[i++]); | |
4471 | } | |
4472 | else | |
4473 | { | |
4474 | while (ndim-- > 0) | |
4475 | type = create_array_type (NULL, type, range_types[ndim]); | |
4476 | } | |
c906108c | 4477 | |
f5f8a009 EZ |
4478 | /* Understand Dwarf2 support for vector types (like they occur on |
4479 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4480 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4481 | custom vendor extension. The main difference between a regular | |
4482 | array and the vector variant is that vectors are passed by value | |
4483 | to functions. */ | |
e142c38c | 4484 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 4485 | if (attr) |
ea37ba09 | 4486 | make_vector_type (type); |
f5f8a009 | 4487 | |
39cbfefa DJ |
4488 | name = dwarf2_name (die, cu); |
4489 | if (name) | |
4490 | TYPE_NAME (type) = name; | |
714e295e | 4491 | |
c906108c SS |
4492 | do_cleanups (back_to); |
4493 | ||
4494 | /* Install the type in the die. */ | |
f792889a | 4495 | return set_die_type (die, type, cu); |
c906108c SS |
4496 | } |
4497 | ||
7ca2d3a3 DL |
4498 | static enum dwarf_array_dim_ordering |
4499 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4500 | { | |
4501 | struct attribute *attr; | |
4502 | ||
4503 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4504 | ||
4505 | if (attr) return DW_SND (attr); | |
4506 | ||
4507 | /* | |
4508 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4509 | opposite order to the dwarf2 specification, but data is still | |
4510 | laid out as per normal fortran. | |
4511 | ||
4512 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4513 | version checking. | |
4514 | */ | |
4515 | ||
4516 | if (cu->language == language_fortran && | |
4517 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4518 | { | |
4519 | return DW_ORD_row_major; | |
4520 | } | |
4521 | ||
4522 | switch (cu->language_defn->la_array_ordering) | |
4523 | { | |
4524 | case array_column_major: | |
4525 | return DW_ORD_col_major; | |
4526 | case array_row_major: | |
4527 | default: | |
4528 | return DW_ORD_row_major; | |
4529 | }; | |
4530 | } | |
4531 | ||
72019c9c GM |
4532 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4533 | the DIE's type field. */ | |
4534 | ||
f792889a | 4535 | static struct type * |
72019c9c GM |
4536 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
4537 | { | |
f792889a DJ |
4538 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
4539 | ||
4540 | return set_die_type (die, set_type, cu); | |
72019c9c | 4541 | } |
7ca2d3a3 | 4542 | |
c906108c SS |
4543 | /* First cut: install each common block member as a global variable. */ |
4544 | ||
4545 | static void | |
e7c27a73 | 4546 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4547 | { |
4548 | struct die_info *child_die; | |
4549 | struct attribute *attr; | |
4550 | struct symbol *sym; | |
4551 | CORE_ADDR base = (CORE_ADDR) 0; | |
4552 | ||
e142c38c | 4553 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4554 | if (attr) |
4555 | { | |
8e19ed76 PS |
4556 | /* Support the .debug_loc offsets */ |
4557 | if (attr_form_is_block (attr)) | |
4558 | { | |
e7c27a73 | 4559 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 4560 | } |
3690dd37 | 4561 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4562 | { |
4d3c2250 | 4563 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4564 | } |
4565 | else | |
4566 | { | |
4d3c2250 KB |
4567 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4568 | "common block member"); | |
8e19ed76 | 4569 | } |
c906108c | 4570 | } |
639d11d3 | 4571 | if (die->child != NULL) |
c906108c | 4572 | { |
639d11d3 | 4573 | child_die = die->child; |
c906108c SS |
4574 | while (child_die && child_die->tag) |
4575 | { | |
e7c27a73 | 4576 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4577 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4578 | if (attr) |
4579 | { | |
4580 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4581 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4582 | add_symbol_to_list (sym, &global_symbols); |
4583 | } | |
4584 | child_die = sibling_die (child_die); | |
4585 | } | |
4586 | } | |
4587 | } | |
4588 | ||
d9fa45fe DC |
4589 | /* Read a C++ namespace. */ |
4590 | ||
d9fa45fe | 4591 | static void |
e7c27a73 | 4592 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 4593 | { |
e7c27a73 | 4594 | struct objfile *objfile = cu->objfile; |
38d518c9 | 4595 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 4596 | const char *name; |
9219021c DC |
4597 | int is_anonymous; |
4598 | struct die_info *current_die; | |
987504bb | 4599 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
9219021c | 4600 | |
e142c38c | 4601 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4602 | |
4603 | /* Now build the name of the current namespace. */ | |
4604 | ||
38d518c9 | 4605 | if (previous_prefix[0] == '\0') |
9219021c | 4606 | { |
38d518c9 | 4607 | processing_current_prefix = name; |
9219021c DC |
4608 | } |
4609 | else | |
4610 | { | |
987504bb JJ |
4611 | char *temp_name = typename_concat (NULL, previous_prefix, name, cu); |
4612 | make_cleanup (xfree, temp_name); | |
38d518c9 | 4613 | processing_current_prefix = temp_name; |
9219021c DC |
4614 | } |
4615 | ||
5c4e30ca DC |
4616 | /* Add a symbol associated to this if we haven't seen the namespace |
4617 | before. Also, add a using directive if it's an anonymous | |
4618 | namespace. */ | |
9219021c | 4619 | |
f2f0e013 | 4620 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
5c4e30ca DC |
4621 | { |
4622 | struct type *type; | |
4623 | ||
4624 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
4625 | this cast will hopefully become unnecessary. */ | |
4626 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 4627 | (char *) processing_current_prefix, |
5c4e30ca DC |
4628 | objfile); |
4629 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4630 | ||
e7c27a73 | 4631 | new_symbol (die, type, cu); |
1c379e20 | 4632 | set_die_type (die, type, cu); |
5c4e30ca DC |
4633 | |
4634 | if (is_anonymous) | |
38d518c9 EZ |
4635 | cp_add_using_directive (processing_current_prefix, |
4636 | strlen (previous_prefix), | |
4637 | strlen (processing_current_prefix)); | |
5c4e30ca | 4638 | } |
9219021c | 4639 | |
639d11d3 | 4640 | if (die->child != NULL) |
d9fa45fe | 4641 | { |
639d11d3 | 4642 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4643 | |
4644 | while (child_die && child_die->tag) | |
4645 | { | |
e7c27a73 | 4646 | process_die (child_die, cu); |
d9fa45fe DC |
4647 | child_die = sibling_die (child_die); |
4648 | } | |
4649 | } | |
9219021c | 4650 | |
38d518c9 | 4651 | processing_current_prefix = previous_prefix; |
987504bb | 4652 | do_cleanups (back_to); |
38d518c9 EZ |
4653 | } |
4654 | ||
4655 | /* Return the name of the namespace represented by DIE. Set | |
4656 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
4657 | namespace. */ | |
4658 | ||
4659 | static const char * | |
e142c38c | 4660 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
4661 | { |
4662 | struct die_info *current_die; | |
4663 | const char *name = NULL; | |
4664 | ||
4665 | /* Loop through the extensions until we find a name. */ | |
4666 | ||
4667 | for (current_die = die; | |
4668 | current_die != NULL; | |
f2f0e013 | 4669 | current_die = dwarf2_extension (die, &cu)) |
38d518c9 | 4670 | { |
e142c38c | 4671 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
4672 | if (name != NULL) |
4673 | break; | |
4674 | } | |
4675 | ||
4676 | /* Is it an anonymous namespace? */ | |
4677 | ||
4678 | *is_anonymous = (name == NULL); | |
4679 | if (*is_anonymous) | |
4680 | name = "(anonymous namespace)"; | |
4681 | ||
4682 | return name; | |
d9fa45fe DC |
4683 | } |
4684 | ||
c906108c SS |
4685 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
4686 | the user defined type vector. */ | |
4687 | ||
f792889a | 4688 | static struct type * |
e7c27a73 | 4689 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4690 | { |
5e2b427d | 4691 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 4692 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 4693 | struct type *type; |
8b2dbe47 KB |
4694 | struct attribute *attr_byte_size; |
4695 | struct attribute *attr_address_class; | |
4696 | int byte_size, addr_class; | |
c906108c | 4697 | |
e7c27a73 | 4698 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 4699 | |
e142c38c | 4700 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
4701 | if (attr_byte_size) |
4702 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 4703 | else |
8b2dbe47 KB |
4704 | byte_size = cu_header->addr_size; |
4705 | ||
e142c38c | 4706 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
4707 | if (attr_address_class) |
4708 | addr_class = DW_UNSND (attr_address_class); | |
4709 | else | |
4710 | addr_class = DW_ADDR_none; | |
4711 | ||
4712 | /* If the pointer size or address class is different than the | |
4713 | default, create a type variant marked as such and set the | |
4714 | length accordingly. */ | |
4715 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 4716 | { |
5e2b427d | 4717 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
4718 | { |
4719 | int type_flags; | |
4720 | ||
849957d9 | 4721 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 4722 | (gdbarch, byte_size, addr_class); |
8b2dbe47 KB |
4723 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); |
4724 | type = make_type_with_address_space (type, type_flags); | |
4725 | } | |
4726 | else if (TYPE_LENGTH (type) != byte_size) | |
4727 | { | |
e2e0b3e5 | 4728 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
4729 | } |
4730 | else { | |
4731 | /* Should we also complain about unhandled address classes? */ | |
4732 | } | |
c906108c | 4733 | } |
8b2dbe47 KB |
4734 | |
4735 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 4736 | return set_die_type (die, type, cu); |
c906108c SS |
4737 | } |
4738 | ||
4739 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
4740 | the user defined type vector. */ | |
4741 | ||
f792889a | 4742 | static struct type * |
e7c27a73 | 4743 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4744 | { |
e7c27a73 | 4745 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4746 | struct type *type; |
4747 | struct type *to_type; | |
4748 | struct type *domain; | |
4749 | ||
e7c27a73 DJ |
4750 | to_type = die_type (die, cu); |
4751 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
4752 | |
4753 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
4754 | type = lookup_methodptr_type (to_type); | |
4755 | else | |
4756 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 4757 | |
f792889a | 4758 | return set_die_type (die, type, cu); |
c906108c SS |
4759 | } |
4760 | ||
4761 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
4762 | the user defined type vector. */ | |
4763 | ||
f792889a | 4764 | static struct type * |
e7c27a73 | 4765 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4766 | { |
e7c27a73 | 4767 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4768 | struct type *type; |
4769 | struct attribute *attr; | |
4770 | ||
e7c27a73 | 4771 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 4772 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4773 | if (attr) |
4774 | { | |
4775 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4776 | } | |
4777 | else | |
4778 | { | |
107d2387 | 4779 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 4780 | } |
f792889a | 4781 | return set_die_type (die, type, cu); |
c906108c SS |
4782 | } |
4783 | ||
f792889a | 4784 | static struct type * |
e7c27a73 | 4785 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4786 | { |
f792889a | 4787 | struct type *base_type, *cv_type; |
c906108c | 4788 | |
e7c27a73 | 4789 | base_type = die_type (die, cu); |
f792889a DJ |
4790 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
4791 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4792 | } |
4793 | ||
f792889a | 4794 | static struct type * |
e7c27a73 | 4795 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4796 | { |
f792889a | 4797 | struct type *base_type, *cv_type; |
c906108c | 4798 | |
e7c27a73 | 4799 | base_type = die_type (die, cu); |
f792889a DJ |
4800 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
4801 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4802 | } |
4803 | ||
4804 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4805 | the user defined type vector. It isn't really a user defined type, | |
4806 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4807 | attribute to reference it. */ | |
4808 | ||
f792889a | 4809 | static struct type * |
e7c27a73 | 4810 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4811 | { |
e7c27a73 | 4812 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4813 | struct type *type, *range_type, *index_type, *char_type; |
4814 | struct attribute *attr; | |
4815 | unsigned int length; | |
4816 | ||
e142c38c | 4817 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4818 | if (attr) |
4819 | { | |
4820 | length = DW_UNSND (attr); | |
4821 | } | |
4822 | else | |
4823 | { | |
b21b22e0 | 4824 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4825 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4826 | if (attr) |
4827 | { | |
4828 | length = DW_UNSND (attr); | |
4829 | } | |
4830 | else | |
4831 | { | |
4832 | length = 1; | |
4833 | } | |
c906108c | 4834 | } |
6ccb9162 UW |
4835 | |
4836 | index_type = builtin_type_int32; | |
c906108c | 4837 | range_type = create_range_type (NULL, index_type, 1, length); |
6ccb9162 UW |
4838 | type = create_string_type (NULL, range_type); |
4839 | ||
f792889a | 4840 | return set_die_type (die, type, cu); |
c906108c SS |
4841 | } |
4842 | ||
4843 | /* Handle DIES due to C code like: | |
4844 | ||
4845 | struct foo | |
c5aa993b JM |
4846 | { |
4847 | int (*funcp)(int a, long l); | |
4848 | int b; | |
4849 | }; | |
c906108c SS |
4850 | |
4851 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4852 | */ |
c906108c | 4853 | |
f792889a | 4854 | static struct type * |
e7c27a73 | 4855 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4856 | { |
4857 | struct type *type; /* Type that this function returns */ | |
4858 | struct type *ftype; /* Function that returns above type */ | |
4859 | struct attribute *attr; | |
4860 | ||
e7c27a73 | 4861 | type = die_type (die, cu); |
1326e61b | 4862 | ftype = make_function_type (type, (struct type **) 0); |
c906108c | 4863 | |
5b8101ae | 4864 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 4865 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4866 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 4867 | || cu->language == language_cplus |
5b8101ae PM |
4868 | || cu->language == language_java |
4869 | || cu->language == language_pascal) | |
c906108c SS |
4870 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4871 | ||
c055b101 CV |
4872 | /* Store the calling convention in the type if it's available in |
4873 | the subroutine die. Otherwise set the calling convention to | |
4874 | the default value DW_CC_normal. */ | |
4875 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
4876 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
4877 | ||
639d11d3 | 4878 | if (die->child != NULL) |
c906108c SS |
4879 | { |
4880 | struct die_info *child_die; | |
4881 | int nparams = 0; | |
4882 | int iparams = 0; | |
4883 | ||
4884 | /* Count the number of parameters. | |
4885 | FIXME: GDB currently ignores vararg functions, but knows about | |
4886 | vararg member functions. */ | |
639d11d3 | 4887 | child_die = die->child; |
c906108c SS |
4888 | while (child_die && child_die->tag) |
4889 | { | |
4890 | if (child_die->tag == DW_TAG_formal_parameter) | |
4891 | nparams++; | |
4892 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4893 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4894 | child_die = sibling_die (child_die); | |
4895 | } | |
4896 | ||
4897 | /* Allocate storage for parameters and fill them in. */ | |
4898 | TYPE_NFIELDS (ftype) = nparams; | |
4899 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 4900 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 4901 | |
639d11d3 | 4902 | child_die = die->child; |
c906108c SS |
4903 | while (child_die && child_die->tag) |
4904 | { | |
4905 | if (child_die->tag == DW_TAG_formal_parameter) | |
4906 | { | |
4907 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4908 | member functions. G++ helps GDB by marking the first |
4909 | parameter for non-static member functions (which is the | |
4910 | this pointer) as artificial. We pass this information | |
4911 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4912 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4913 | if (attr) |
4914 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4915 | else | |
4916 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4917 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4918 | iparams++; |
4919 | } | |
4920 | child_die = sibling_die (child_die); | |
4921 | } | |
4922 | } | |
4923 | ||
f792889a | 4924 | return set_die_type (die, ftype, cu); |
c906108c SS |
4925 | } |
4926 | ||
f792889a | 4927 | static struct type * |
e7c27a73 | 4928 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4929 | { |
e7c27a73 | 4930 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4931 | struct attribute *attr; |
4932 | char *name = NULL; | |
f792889a | 4933 | struct type *this_type; |
c906108c | 4934 | |
f792889a DJ |
4935 | name = dwarf2_name (die, cu); |
4936 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, | |
4937 | TYPE_FLAG_TARGET_STUB, name, objfile); | |
4938 | set_die_type (die, this_type, cu); | |
4939 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
4940 | return this_type; | |
c906108c SS |
4941 | } |
4942 | ||
4943 | /* Find a representation of a given base type and install | |
4944 | it in the TYPE field of the die. */ | |
4945 | ||
f792889a | 4946 | static struct type * |
e7c27a73 | 4947 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4948 | { |
e7c27a73 | 4949 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4950 | struct type *type; |
4951 | struct attribute *attr; | |
4952 | int encoding = 0, size = 0; | |
39cbfefa | 4953 | char *name; |
6ccb9162 UW |
4954 | enum type_code code = TYPE_CODE_INT; |
4955 | int type_flags = 0; | |
4956 | struct type *target_type = NULL; | |
c906108c | 4957 | |
e142c38c | 4958 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4959 | if (attr) |
4960 | { | |
4961 | encoding = DW_UNSND (attr); | |
4962 | } | |
e142c38c | 4963 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4964 | if (attr) |
4965 | { | |
4966 | size = DW_UNSND (attr); | |
4967 | } | |
39cbfefa | 4968 | name = dwarf2_name (die, cu); |
6ccb9162 | 4969 | if (!name) |
c906108c | 4970 | { |
6ccb9162 UW |
4971 | complaint (&symfile_complaints, |
4972 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 4973 | } |
6ccb9162 UW |
4974 | |
4975 | switch (encoding) | |
c906108c | 4976 | { |
6ccb9162 UW |
4977 | case DW_ATE_address: |
4978 | /* Turn DW_ATE_address into a void * pointer. */ | |
4979 | code = TYPE_CODE_PTR; | |
4980 | type_flags |= TYPE_FLAG_UNSIGNED; | |
4981 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
4982 | break; | |
4983 | case DW_ATE_boolean: | |
4984 | code = TYPE_CODE_BOOL; | |
4985 | type_flags |= TYPE_FLAG_UNSIGNED; | |
4986 | break; | |
4987 | case DW_ATE_complex_float: | |
4988 | code = TYPE_CODE_COMPLEX; | |
4989 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
4990 | break; | |
4991 | case DW_ATE_decimal_float: | |
4992 | code = TYPE_CODE_DECFLOAT; | |
4993 | break; | |
4994 | case DW_ATE_float: | |
4995 | code = TYPE_CODE_FLT; | |
4996 | break; | |
4997 | case DW_ATE_signed: | |
4998 | break; | |
4999 | case DW_ATE_unsigned: | |
5000 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5001 | break; | |
5002 | case DW_ATE_signed_char: | |
1760d9d5 | 5003 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5004 | code = TYPE_CODE_CHAR; |
5005 | break; | |
5006 | case DW_ATE_unsigned_char: | |
1760d9d5 | 5007 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5008 | code = TYPE_CODE_CHAR; |
5009 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5010 | break; | |
5011 | default: | |
5012 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
5013 | dwarf_type_encoding_name (encoding)); | |
5014 | break; | |
c906108c | 5015 | } |
6ccb9162 UW |
5016 | |
5017 | type = init_type (code, size, type_flags, name, objfile); | |
5018 | TYPE_TARGET_TYPE (type) = target_type; | |
5019 | ||
f792889a | 5020 | return set_die_type (die, type, cu); |
c906108c SS |
5021 | } |
5022 | ||
a02abb62 JB |
5023 | /* Read the given DW_AT_subrange DIE. */ |
5024 | ||
f792889a | 5025 | static struct type * |
a02abb62 JB |
5026 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
5027 | { | |
5e2b427d | 5028 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
5029 | struct type *base_type; |
5030 | struct type *range_type; | |
5031 | struct attribute *attr; | |
5032 | int low = 0; | |
5033 | int high = -1; | |
39cbfefa | 5034 | char *name; |
a02abb62 | 5035 | |
a02abb62 | 5036 | base_type = die_type (die, cu); |
3d1f72c2 | 5037 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
5038 | { |
5039 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5040 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 5041 | base_type |
5e2b427d | 5042 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 5043 | 0, NULL, cu->objfile); |
a02abb62 JB |
5044 | } |
5045 | ||
e142c38c | 5046 | if (cu->language == language_fortran) |
a02abb62 JB |
5047 | { |
5048 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
5049 | low = 1; | |
5050 | } | |
5051 | ||
dd5e6932 DJ |
5052 | /* FIXME: For variable sized arrays either of these could be |
5053 | a variable rather than a constant value. We'll allow it, | |
5054 | but we don't know how to handle it. */ | |
e142c38c | 5055 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
5056 | if (attr) |
5057 | low = dwarf2_get_attr_constant_value (attr, 0); | |
5058 | ||
e142c38c | 5059 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
5060 | if (attr) |
5061 | { | |
5062 | if (attr->form == DW_FORM_block1) | |
5063 | { | |
5064 | /* GCC encodes arrays with unspecified or dynamic length | |
5065 | with a DW_FORM_block1 attribute. | |
5066 | FIXME: GDB does not yet know how to handle dynamic | |
5067 | arrays properly, treat them as arrays with unspecified | |
5068 | length for now. | |
5069 | ||
5070 | FIXME: jimb/2003-09-22: GDB does not really know | |
5071 | how to handle arrays of unspecified length | |
5072 | either; we just represent them as zero-length | |
5073 | arrays. Choose an appropriate upper bound given | |
5074 | the lower bound we've computed above. */ | |
5075 | high = low - 1; | |
5076 | } | |
5077 | else | |
5078 | high = dwarf2_get_attr_constant_value (attr, 1); | |
5079 | } | |
5080 | ||
5081 | range_type = create_range_type (NULL, base_type, low, high); | |
5082 | ||
39cbfefa DJ |
5083 | name = dwarf2_name (die, cu); |
5084 | if (name) | |
5085 | TYPE_NAME (range_type) = name; | |
a02abb62 | 5086 | |
e142c38c | 5087 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
5088 | if (attr) |
5089 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
5090 | ||
f792889a | 5091 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
5092 | } |
5093 | ||
f792889a | 5094 | static struct type * |
81a17f79 JB |
5095 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
5096 | { | |
5097 | struct type *type; | |
81a17f79 | 5098 | |
81a17f79 JB |
5099 | /* For now, we only support the C meaning of an unspecified type: void. */ |
5100 | ||
39cbfefa | 5101 | type = init_type (TYPE_CODE_VOID, 0, 0, dwarf2_name (die, cu), |
81a17f79 JB |
5102 | cu->objfile); |
5103 | ||
f792889a | 5104 | return set_die_type (die, type, cu); |
81a17f79 | 5105 | } |
a02abb62 | 5106 | |
51545339 DJ |
5107 | /* Trivial hash function for die_info: the hash value of a DIE |
5108 | is its offset in .debug_info for this objfile. */ | |
5109 | ||
5110 | static hashval_t | |
5111 | die_hash (const void *item) | |
5112 | { | |
5113 | const struct die_info *die = item; | |
5114 | return die->offset; | |
5115 | } | |
5116 | ||
5117 | /* Trivial comparison function for die_info structures: two DIEs | |
5118 | are equal if they have the same offset. */ | |
5119 | ||
5120 | static int | |
5121 | die_eq (const void *item_lhs, const void *item_rhs) | |
5122 | { | |
5123 | const struct die_info *die_lhs = item_lhs; | |
5124 | const struct die_info *die_rhs = item_rhs; | |
5125 | return die_lhs->offset == die_rhs->offset; | |
5126 | } | |
5127 | ||
c906108c SS |
5128 | /* Read a whole compilation unit into a linked list of dies. */ |
5129 | ||
f9aca02d | 5130 | static struct die_info * |
fe1b8b76 | 5131 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5132 | { |
51545339 DJ |
5133 | cu->die_hash |
5134 | = htab_create_alloc_ex (cu->header.length / 12, | |
5135 | die_hash, | |
5136 | die_eq, | |
5137 | NULL, | |
5138 | &cu->comp_unit_obstack, | |
5139 | hashtab_obstack_allocate, | |
5140 | dummy_obstack_deallocate); | |
5141 | ||
e7c27a73 | 5142 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
5143 | } |
5144 | ||
5145 | /* Read a single die and all its descendents. Set the die's sibling | |
5146 | field to NULL; set other fields in the die correctly, and set all | |
5147 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
5148 | location of the info_ptr after reading all of those dies. PARENT | |
5149 | is the parent of the die in question. */ | |
5150 | ||
5151 | static struct die_info * | |
fe1b8b76 | 5152 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5153 | struct dwarf2_cu *cu, |
fe1b8b76 | 5154 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5155 | struct die_info *parent) |
5156 | { | |
5157 | struct die_info *die; | |
fe1b8b76 | 5158 | gdb_byte *cur_ptr; |
639d11d3 DC |
5159 | int has_children; |
5160 | ||
e7c27a73 | 5161 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
1d325ec1 DJ |
5162 | if (die == NULL) |
5163 | { | |
5164 | *new_info_ptr = cur_ptr; | |
5165 | return NULL; | |
5166 | } | |
51545339 | 5167 | store_in_ref_table (die, cu); |
639d11d3 DC |
5168 | |
5169 | if (has_children) | |
5170 | { | |
e7c27a73 | 5171 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5172 | new_info_ptr, die); |
5173 | } | |
5174 | else | |
5175 | { | |
5176 | die->child = NULL; | |
5177 | *new_info_ptr = cur_ptr; | |
5178 | } | |
5179 | ||
5180 | die->sibling = NULL; | |
5181 | die->parent = parent; | |
5182 | return die; | |
5183 | } | |
5184 | ||
5185 | /* Read a die, all of its descendents, and all of its siblings; set | |
5186 | all of the fields of all of the dies correctly. Arguments are as | |
5187 | in read_die_and_children. */ | |
5188 | ||
5189 | static struct die_info * | |
fe1b8b76 | 5190 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5191 | struct dwarf2_cu *cu, |
fe1b8b76 | 5192 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5193 | struct die_info *parent) |
5194 | { | |
5195 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5196 | gdb_byte *cur_ptr; |
639d11d3 | 5197 | |
c906108c | 5198 | cur_ptr = info_ptr; |
639d11d3 DC |
5199 | first_die = last_sibling = NULL; |
5200 | ||
5201 | while (1) | |
c906108c | 5202 | { |
639d11d3 | 5203 | struct die_info *die |
e7c27a73 | 5204 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 | 5205 | |
1d325ec1 | 5206 | if (die == NULL) |
c906108c | 5207 | { |
639d11d3 DC |
5208 | *new_info_ptr = cur_ptr; |
5209 | return first_die; | |
c906108c | 5210 | } |
1d325ec1 DJ |
5211 | |
5212 | if (!first_die) | |
5213 | first_die = die; | |
c906108c | 5214 | else |
1d325ec1 DJ |
5215 | last_sibling->sibling = die; |
5216 | ||
5217 | last_sibling = die; | |
c906108c | 5218 | } |
c906108c SS |
5219 | } |
5220 | ||
233a11ab CS |
5221 | /* Decompress a section that was compressed using zlib. Store the |
5222 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
5223 | ||
5224 | static void | |
5225 | zlib_decompress_section (struct objfile *objfile, asection *sectp, | |
5226 | gdb_byte **outbuf, bfd_size_type *outsize) | |
5227 | { | |
ef72380d | 5228 | bfd *abfd = objfile->obfd; |
233a11ab CS |
5229 | #ifndef HAVE_ZLIB_H |
5230 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
5231 | "is disabled in this copy of GDB"), | |
5232 | bfd_get_filename (abfd)); | |
5233 | #else | |
233a11ab CS |
5234 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
5235 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
5236 | bfd_size_type uncompressed_size; | |
5237 | gdb_byte *uncompressed_buffer; | |
5238 | z_stream strm; | |
5239 | int rc; | |
5240 | int header_size = 12; | |
5241 | ||
5242 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
5243 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
5244 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
5245 | bfd_get_filename (abfd)); | |
5246 | ||
5247 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
5248 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
5249 | if (compressed_size < header_size | |
5250 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
5251 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
5252 | bfd_get_filename (abfd)); | |
5253 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
5254 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
5255 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
5256 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
5257 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
5258 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
5259 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
5260 | uncompressed_size += compressed_buffer[11]; | |
5261 | ||
5262 | /* It is possible the section consists of several compressed | |
5263 | buffers concatenated together, so we uncompress in a loop. */ | |
5264 | strm.zalloc = NULL; | |
5265 | strm.zfree = NULL; | |
5266 | strm.opaque = NULL; | |
5267 | strm.avail_in = compressed_size - header_size; | |
5268 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
5269 | strm.avail_out = uncompressed_size; | |
5270 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
5271 | uncompressed_size); | |
5272 | rc = inflateInit (&strm); | |
5273 | while (strm.avail_in > 0) | |
5274 | { | |
5275 | if (rc != Z_OK) | |
5276 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
5277 | bfd_get_filename (abfd), rc); | |
5278 | strm.next_out = ((Bytef*) uncompressed_buffer | |
5279 | + (uncompressed_size - strm.avail_out)); | |
5280 | rc = inflate (&strm, Z_FINISH); | |
5281 | if (rc != Z_STREAM_END) | |
5282 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
5283 | bfd_get_filename (abfd), rc); | |
5284 | rc = inflateReset (&strm); | |
5285 | } | |
5286 | rc = inflateEnd (&strm); | |
5287 | if (rc != Z_OK | |
5288 | || strm.avail_out != 0) | |
5289 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
5290 | bfd_get_filename (abfd), rc); | |
5291 | ||
5292 | xfree (compressed_buffer); | |
5293 | *outbuf = uncompressed_buffer; | |
5294 | *outsize = uncompressed_size; | |
5295 | #endif | |
5296 | } | |
5297 | ||
5298 | ||
c906108c | 5299 | /* Read the contents of the section at OFFSET and of size SIZE from the |
233a11ab CS |
5300 | object file specified by OBJFILE into the objfile_obstack and return it. |
5301 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 5302 | |
fe1b8b76 | 5303 | gdb_byte * |
188dd5d6 | 5304 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
5305 | { |
5306 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 5307 | gdb_byte *buf, *retbuf; |
2c500098 | 5308 | bfd_size_type size = bfd_get_section_size (sectp); |
233a11ab | 5309 | unsigned char header[4]; |
c906108c SS |
5310 | |
5311 | if (size == 0) | |
5312 | return NULL; | |
5313 | ||
233a11ab CS |
5314 | /* Check if the file has a 4-byte header indicating compression. */ |
5315 | if (size > sizeof (header) | |
5316 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
5317 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
5318 | { | |
5319 | /* Upon decompression, update the buffer and its size. */ | |
5320 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
5321 | { | |
5322 | zlib_decompress_section (objfile, sectp, &buf, &size); | |
5323 | dwarf2_resize_section (sectp, size); | |
5324 | return buf; | |
5325 | } | |
5326 | } | |
5327 | ||
5328 | /* If we get here, we are a normal, not-compressed section. */ | |
fe1b8b76 | 5329 | buf = obstack_alloc (&objfile->objfile_obstack, size); |
233a11ab CS |
5330 | /* When debugging .o files, we may need to apply relocations; see |
5331 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
5332 | We never compress sections in .o files, so we only need to | |
5333 | try this when the section is not compressed. */ | |
fe1b8b76 | 5334 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); |
086df311 DJ |
5335 | if (retbuf != NULL) |
5336 | return retbuf; | |
5337 | ||
188dd5d6 DJ |
5338 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
5339 | || bfd_bread (buf, size, abfd) != size) | |
8a3fe4f8 | 5340 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
188dd5d6 DJ |
5341 | bfd_get_filename (abfd)); |
5342 | ||
c906108c SS |
5343 | return buf; |
5344 | } | |
5345 | ||
5346 | /* In DWARF version 2, the description of the debugging information is | |
5347 | stored in a separate .debug_abbrev section. Before we read any | |
5348 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5349 | in a hash table. This function also sets flags in CU describing |
5350 | the data found in the abbrev table. */ | |
c906108c SS |
5351 | |
5352 | static void | |
e7c27a73 | 5353 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5354 | { |
e7c27a73 | 5355 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5356 | gdb_byte *abbrev_ptr; |
c906108c SS |
5357 | struct abbrev_info *cur_abbrev; |
5358 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5359 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5360 | struct attr_abbrev *cur_attrs; |
5361 | unsigned int allocated_attrs; | |
c906108c | 5362 | |
57349743 | 5363 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5364 | obstack_init (&cu->abbrev_obstack); |
5365 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5366 | (ABBREV_HASH_SIZE | |
5367 | * sizeof (struct abbrev_info *))); | |
5368 | memset (cu->dwarf2_abbrevs, 0, | |
5369 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5370 | |
6502dd73 | 5371 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
5372 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5373 | abbrev_ptr += bytes_read; | |
5374 | ||
f3dd6933 DJ |
5375 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5376 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5377 | ||
c906108c SS |
5378 | /* loop until we reach an abbrev number of 0 */ |
5379 | while (abbrev_number) | |
5380 | { | |
f3dd6933 | 5381 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5382 | |
5383 | /* read in abbrev header */ | |
5384 | cur_abbrev->number = abbrev_number; | |
5385 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5386 | abbrev_ptr += bytes_read; | |
5387 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5388 | abbrev_ptr += 1; | |
5389 | ||
72bf9492 DJ |
5390 | if (cur_abbrev->tag == DW_TAG_namespace) |
5391 | cu->has_namespace_info = 1; | |
5392 | ||
c906108c SS |
5393 | /* now read in declarations */ |
5394 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5395 | abbrev_ptr += bytes_read; | |
5396 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5397 | abbrev_ptr += bytes_read; | |
5398 | while (abbrev_name) | |
5399 | { | |
f3dd6933 | 5400 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5401 | { |
f3dd6933 DJ |
5402 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5403 | cur_attrs | |
5404 | = xrealloc (cur_attrs, (allocated_attrs | |
5405 | * sizeof (struct attr_abbrev))); | |
c906108c | 5406 | } |
ae038cb0 DJ |
5407 | |
5408 | /* Record whether this compilation unit might have | |
5409 | inter-compilation-unit references. If we don't know what form | |
5410 | this attribute will have, then it might potentially be a | |
5411 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5412 | references. */ | |
5413 | ||
5414 | if (abbrev_form == DW_FORM_ref_addr | |
5415 | || abbrev_form == DW_FORM_indirect) | |
5416 | cu->has_form_ref_addr = 1; | |
5417 | ||
f3dd6933 DJ |
5418 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5419 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5420 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5421 | abbrev_ptr += bytes_read; | |
5422 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5423 | abbrev_ptr += bytes_read; | |
5424 | } | |
5425 | ||
f3dd6933 DJ |
5426 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5427 | (cur_abbrev->num_attrs | |
5428 | * sizeof (struct attr_abbrev))); | |
5429 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5430 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5431 | ||
c906108c | 5432 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5433 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5434 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5435 | |
5436 | /* Get next abbreviation. | |
5437 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5438 | always properly terminated with an abbrev number of 0. |
5439 | Exit loop if we encounter an abbreviation which we have | |
5440 | already read (which means we are about to read the abbreviations | |
5441 | for the next compile unit) or if the end of the abbreviation | |
5442 | table is reached. */ | |
6502dd73 DJ |
5443 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
5444 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
5445 | break; |
5446 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5447 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5448 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5449 | break; |
5450 | } | |
f3dd6933 DJ |
5451 | |
5452 | xfree (cur_attrs); | |
c906108c SS |
5453 | } |
5454 | ||
f3dd6933 | 5455 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5456 | |
c906108c | 5457 | static void |
f3dd6933 | 5458 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5459 | { |
f3dd6933 | 5460 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5461 | |
f3dd6933 DJ |
5462 | obstack_free (&cu->abbrev_obstack, NULL); |
5463 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5464 | } |
5465 | ||
5466 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5467 | ||
5468 | static struct abbrev_info * | |
e7c27a73 | 5469 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5470 | { |
5471 | unsigned int hash_number; | |
5472 | struct abbrev_info *abbrev; | |
5473 | ||
5474 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5475 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5476 | |
5477 | while (abbrev) | |
5478 | { | |
5479 | if (abbrev->number == number) | |
5480 | return abbrev; | |
5481 | else | |
5482 | abbrev = abbrev->next; | |
5483 | } | |
5484 | return NULL; | |
5485 | } | |
5486 | ||
72bf9492 DJ |
5487 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5488 | symbol for. */ | |
5489 | ||
5490 | static int | |
5491 | is_type_tag_for_partial (int tag) | |
5492 | { | |
5493 | switch (tag) | |
5494 | { | |
5495 | #if 0 | |
5496 | /* Some types that would be reasonable to generate partial symbols for, | |
5497 | that we don't at present. */ | |
5498 | case DW_TAG_array_type: | |
5499 | case DW_TAG_file_type: | |
5500 | case DW_TAG_ptr_to_member_type: | |
5501 | case DW_TAG_set_type: | |
5502 | case DW_TAG_string_type: | |
5503 | case DW_TAG_subroutine_type: | |
5504 | #endif | |
5505 | case DW_TAG_base_type: | |
5506 | case DW_TAG_class_type: | |
680b30c7 | 5507 | case DW_TAG_interface_type: |
72bf9492 DJ |
5508 | case DW_TAG_enumeration_type: |
5509 | case DW_TAG_structure_type: | |
5510 | case DW_TAG_subrange_type: | |
5511 | case DW_TAG_typedef: | |
5512 | case DW_TAG_union_type: | |
5513 | return 1; | |
5514 | default: | |
5515 | return 0; | |
5516 | } | |
5517 | } | |
5518 | ||
5519 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5520 | ||
5521 | static struct partial_die_info * | |
fe1b8b76 | 5522 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5523 | struct dwarf2_cu *cu) |
5524 | { | |
5525 | struct partial_die_info *part_die; | |
5526 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5527 | struct abbrev_info *abbrev; | |
5528 | unsigned int bytes_read; | |
5afb4e99 | 5529 | unsigned int load_all = 0; |
72bf9492 DJ |
5530 | |
5531 | int nesting_level = 1; | |
5532 | ||
5533 | parent_die = NULL; | |
5534 | last_die = NULL; | |
5535 | ||
5afb4e99 DJ |
5536 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5537 | load_all = 1; | |
5538 | ||
72bf9492 DJ |
5539 | cu->partial_dies |
5540 | = htab_create_alloc_ex (cu->header.length / 12, | |
5541 | partial_die_hash, | |
5542 | partial_die_eq, | |
5543 | NULL, | |
5544 | &cu->comp_unit_obstack, | |
5545 | hashtab_obstack_allocate, | |
5546 | dummy_obstack_deallocate); | |
5547 | ||
5548 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5549 | sizeof (struct partial_die_info)); | |
5550 | ||
5551 | while (1) | |
5552 | { | |
5553 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5554 | ||
5555 | /* A NULL abbrev means the end of a series of children. */ | |
5556 | if (abbrev == NULL) | |
5557 | { | |
5558 | if (--nesting_level == 0) | |
5559 | { | |
5560 | /* PART_DIE was probably the last thing allocated on the | |
5561 | comp_unit_obstack, so we could call obstack_free | |
5562 | here. We don't do that because the waste is small, | |
5563 | and will be cleaned up when we're done with this | |
5564 | compilation unit. This way, we're also more robust | |
5565 | against other users of the comp_unit_obstack. */ | |
5566 | return first_die; | |
5567 | } | |
5568 | info_ptr += bytes_read; | |
5569 | last_die = parent_die; | |
5570 | parent_die = parent_die->die_parent; | |
5571 | continue; | |
5572 | } | |
5573 | ||
5afb4e99 DJ |
5574 | /* Check whether this DIE is interesting enough to save. Normally |
5575 | we would not be interested in members here, but there may be | |
5576 | later variables referencing them via DW_AT_specification (for | |
5577 | static members). */ | |
5578 | if (!load_all | |
5579 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5580 | && abbrev->tag != DW_TAG_enumerator |
5581 | && abbrev->tag != DW_TAG_subprogram | |
5582 | && abbrev->tag != DW_TAG_variable | |
5afb4e99 DJ |
5583 | && abbrev->tag != DW_TAG_namespace |
5584 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5585 | { |
5586 | /* Otherwise we skip to the next sibling, if any. */ | |
5587 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5588 | continue; | |
5589 | } | |
5590 | ||
5591 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5592 | abfd, info_ptr, cu); | |
5593 | ||
5594 | /* This two-pass algorithm for processing partial symbols has a | |
5595 | high cost in cache pressure. Thus, handle some simple cases | |
5596 | here which cover the majority of C partial symbols. DIEs | |
5597 | which neither have specification tags in them, nor could have | |
5598 | specification tags elsewhere pointing at them, can simply be | |
5599 | processed and discarded. | |
5600 | ||
5601 | This segment is also optional; scan_partial_symbols and | |
5602 | add_partial_symbol will handle these DIEs if we chain | |
5603 | them in normally. When compilers which do not emit large | |
5604 | quantities of duplicate debug information are more common, | |
5605 | this code can probably be removed. */ | |
5606 | ||
5607 | /* Any complete simple types at the top level (pretty much all | |
5608 | of them, for a language without namespaces), can be processed | |
5609 | directly. */ | |
5610 | if (parent_die == NULL | |
5611 | && part_die->has_specification == 0 | |
5612 | && part_die->is_declaration == 0 | |
5613 | && (part_die->tag == DW_TAG_typedef | |
5614 | || part_die->tag == DW_TAG_base_type | |
5615 | || part_die->tag == DW_TAG_subrange_type)) | |
5616 | { | |
5617 | if (building_psymtab && part_die->name != NULL) | |
5618 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5619 | VAR_DOMAIN, LOC_TYPEDEF, | |
5620 | &cu->objfile->static_psymbols, | |
5621 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5622 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5623 | continue; | |
5624 | } | |
5625 | ||
5626 | /* If we're at the second level, and we're an enumerator, and | |
5627 | our parent has no specification (meaning possibly lives in a | |
5628 | namespace elsewhere), then we can add the partial symbol now | |
5629 | instead of queueing it. */ | |
5630 | if (part_die->tag == DW_TAG_enumerator | |
5631 | && parent_die != NULL | |
5632 | && parent_die->die_parent == NULL | |
5633 | && parent_die->tag == DW_TAG_enumeration_type | |
5634 | && parent_die->has_specification == 0) | |
5635 | { | |
5636 | if (part_die->name == NULL) | |
e2e0b3e5 | 5637 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5638 | else if (building_psymtab) |
5639 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5640 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5641 | (cu->language == language_cplus |
5642 | || cu->language == language_java) | |
72bf9492 DJ |
5643 | ? &cu->objfile->global_psymbols |
5644 | : &cu->objfile->static_psymbols, | |
5645 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5646 | ||
5647 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5648 | continue; | |
5649 | } | |
5650 | ||
5651 | /* We'll save this DIE so link it in. */ | |
5652 | part_die->die_parent = parent_die; | |
5653 | part_die->die_sibling = NULL; | |
5654 | part_die->die_child = NULL; | |
5655 | ||
5656 | if (last_die && last_die == parent_die) | |
5657 | last_die->die_child = part_die; | |
5658 | else if (last_die) | |
5659 | last_die->die_sibling = part_die; | |
5660 | ||
5661 | last_die = part_die; | |
5662 | ||
5663 | if (first_die == NULL) | |
5664 | first_die = part_die; | |
5665 | ||
5666 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5667 | find interesting need to be in the hash table, because we | |
5668 | also have the parent/sibling/child chains; only those that we | |
5669 | might refer to by offset later during partial symbol reading. | |
5670 | ||
5671 | For now this means things that might have be the target of a | |
5672 | DW_AT_specification, DW_AT_abstract_origin, or | |
5673 | DW_AT_extension. DW_AT_extension will refer only to | |
5674 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5675 | many things under the function DIE, but we do not recurse | |
5676 | into function DIEs during partial symbol reading) and | |
5677 | possibly variables as well; DW_AT_specification refers to | |
5678 | declarations. Declarations ought to have the DW_AT_declaration | |
5679 | flag. It happens that GCC forgets to put it in sometimes, but | |
5680 | only for functions, not for types. | |
5681 | ||
5682 | Adding more things than necessary to the hash table is harmless | |
5683 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5684 | wasted time in find_partial_die, when we reread the compilation |
5685 | unit with load_all_dies set. */ | |
72bf9492 | 5686 | |
5afb4e99 DJ |
5687 | if (load_all |
5688 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5689 | || abbrev->tag == DW_TAG_variable |
5690 | || abbrev->tag == DW_TAG_namespace | |
5691 | || part_die->is_declaration) | |
5692 | { | |
5693 | void **slot; | |
5694 | ||
5695 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5696 | part_die->offset, INSERT); | |
5697 | *slot = part_die; | |
5698 | } | |
5699 | ||
5700 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5701 | sizeof (struct partial_die_info)); | |
5702 | ||
5703 | /* For some DIEs we want to follow their children (if any). For C | |
5704 | we have no reason to follow the children of structures; for other | |
5705 | languages we have to, both so that we can get at method physnames | |
5706 | to infer fully qualified class names, and for DW_AT_specification. */ | |
5707 | if (last_die->has_children | |
5afb4e99 DJ |
5708 | && (load_all |
5709 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5710 | || last_die->tag == DW_TAG_enumeration_type |
5711 | || (cu->language != language_c | |
5712 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 5713 | || last_die->tag == DW_TAG_interface_type |
72bf9492 DJ |
5714 | || last_die->tag == DW_TAG_structure_type |
5715 | || last_die->tag == DW_TAG_union_type)))) | |
5716 | { | |
5717 | nesting_level++; | |
5718 | parent_die = last_die; | |
5719 | continue; | |
5720 | } | |
5721 | ||
5722 | /* Otherwise we skip to the next sibling, if any. */ | |
5723 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5724 | ||
5725 | /* Back to the top, do it again. */ | |
5726 | } | |
5727 | } | |
5728 | ||
c906108c SS |
5729 | /* Read a minimal amount of information into the minimal die structure. */ |
5730 | ||
fe1b8b76 | 5731 | static gdb_byte * |
72bf9492 DJ |
5732 | read_partial_die (struct partial_die_info *part_die, |
5733 | struct abbrev_info *abbrev, | |
5734 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 5735 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 5736 | { |
72bf9492 | 5737 | unsigned int bytes_read, i; |
c906108c | 5738 | struct attribute attr; |
c5aa993b | 5739 | int has_low_pc_attr = 0; |
c906108c | 5740 | int has_high_pc_attr = 0; |
e7030f15 | 5741 | CORE_ADDR base_address = 0; |
85cbf3d3 JK |
5742 | enum |
5743 | { | |
5744 | base_address_none, | |
5745 | base_address_low_pc, | |
5746 | /* Overrides BASE_ADDRESS_LOW_PC. */ | |
5747 | base_address_entry_pc | |
5748 | } | |
5749 | base_address_type = base_address_none; | |
c906108c | 5750 | |
72bf9492 | 5751 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 5752 | |
6502dd73 | 5753 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
5754 | |
5755 | info_ptr += abbrev_len; | |
5756 | ||
5757 | if (abbrev == NULL) | |
5758 | return info_ptr; | |
5759 | ||
c906108c SS |
5760 | part_die->tag = abbrev->tag; |
5761 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
5762 | |
5763 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5764 | { | |
e7c27a73 | 5765 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
5766 | |
5767 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 5768 | partial symbol table. */ |
c906108c SS |
5769 | switch (attr.name) |
5770 | { | |
5771 | case DW_AT_name: | |
5772 | ||
5773 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
5774 | if (part_die->name == NULL) | |
5775 | part_die->name = DW_STRING (&attr); | |
5776 | break; | |
57c22c6c BR |
5777 | case DW_AT_comp_dir: |
5778 | if (part_die->dirname == NULL) | |
5779 | part_die->dirname = DW_STRING (&attr); | |
5780 | break; | |
c906108c SS |
5781 | case DW_AT_MIPS_linkage_name: |
5782 | part_die->name = DW_STRING (&attr); | |
5783 | break; | |
5784 | case DW_AT_low_pc: | |
5785 | has_low_pc_attr = 1; | |
5786 | part_die->lowpc = DW_ADDR (&attr); | |
85cbf3d3 JK |
5787 | if (part_die->tag == DW_TAG_compile_unit |
5788 | && base_address_type < base_address_low_pc) | |
5789 | { | |
5790 | base_address = DW_ADDR (&attr); | |
5791 | base_address_type = base_address_low_pc; | |
5792 | } | |
c906108c SS |
5793 | break; |
5794 | case DW_AT_high_pc: | |
5795 | has_high_pc_attr = 1; | |
5796 | part_die->highpc = DW_ADDR (&attr); | |
5797 | break; | |
85cbf3d3 JK |
5798 | case DW_AT_entry_pc: |
5799 | if (part_die->tag == DW_TAG_compile_unit | |
5800 | && base_address_type < base_address_entry_pc) | |
5801 | { | |
5802 | base_address = DW_ADDR (&attr); | |
5803 | base_address_type = base_address_entry_pc; | |
5804 | } | |
5805 | break; | |
43039443 | 5806 | case DW_AT_ranges: |
ff013f42 JK |
5807 | if (part_die->tag == DW_TAG_compile_unit) |
5808 | { | |
5809 | cu->ranges_offset = DW_UNSND (&attr); | |
5810 | cu->has_ranges_offset = 1; | |
5811 | } | |
43039443 | 5812 | break; |
c906108c | 5813 | case DW_AT_location: |
8e19ed76 PS |
5814 | /* Support the .debug_loc offsets */ |
5815 | if (attr_form_is_block (&attr)) | |
5816 | { | |
5817 | part_die->locdesc = DW_BLOCK (&attr); | |
5818 | } | |
3690dd37 | 5819 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 5820 | { |
4d3c2250 | 5821 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5822 | } |
5823 | else | |
5824 | { | |
4d3c2250 KB |
5825 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5826 | "partial symbol information"); | |
8e19ed76 | 5827 | } |
c906108c SS |
5828 | break; |
5829 | case DW_AT_language: | |
5830 | part_die->language = DW_UNSND (&attr); | |
5831 | break; | |
5832 | case DW_AT_external: | |
5833 | part_die->is_external = DW_UNSND (&attr); | |
5834 | break; | |
5835 | case DW_AT_declaration: | |
5836 | part_die->is_declaration = DW_UNSND (&attr); | |
5837 | break; | |
5838 | case DW_AT_type: | |
5839 | part_die->has_type = 1; | |
5840 | break; | |
5841 | case DW_AT_abstract_origin: | |
5842 | case DW_AT_specification: | |
72bf9492 DJ |
5843 | case DW_AT_extension: |
5844 | part_die->has_specification = 1; | |
5845 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
5846 | break; |
5847 | case DW_AT_sibling: | |
5848 | /* Ignore absolute siblings, they might point outside of | |
5849 | the current compile unit. */ | |
5850 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 5851 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 5852 | else |
6502dd73 DJ |
5853 | part_die->sibling = dwarf2_per_objfile->info_buffer |
5854 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 5855 | break; |
aaa75496 JB |
5856 | case DW_AT_stmt_list: |
5857 | part_die->has_stmt_list = 1; | |
5858 | part_die->line_offset = DW_UNSND (&attr); | |
5859 | break; | |
fa4028e9 JB |
5860 | case DW_AT_byte_size: |
5861 | part_die->has_byte_size = 1; | |
5862 | break; | |
68511cec CES |
5863 | case DW_AT_calling_convention: |
5864 | /* DWARF doesn't provide a way to identify a program's source-level | |
5865 | entry point. DW_AT_calling_convention attributes are only meant | |
5866 | to describe functions' calling conventions. | |
5867 | ||
5868 | However, because it's a necessary piece of information in | |
5869 | Fortran, and because DW_CC_program is the only piece of debugging | |
5870 | information whose definition refers to a 'main program' at all, | |
5871 | several compilers have begun marking Fortran main programs with | |
5872 | DW_CC_program --- even when those functions use the standard | |
5873 | calling conventions. | |
5874 | ||
5875 | So until DWARF specifies a way to provide this information and | |
5876 | compilers pick up the new representation, we'll support this | |
5877 | practice. */ | |
5878 | if (DW_UNSND (&attr) == DW_CC_program | |
5879 | && cu->language == language_fortran) | |
5880 | set_main_name (part_die->name); | |
5881 | break; | |
c906108c SS |
5882 | default: |
5883 | break; | |
5884 | } | |
5885 | } | |
5886 | ||
c906108c SS |
5887 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
5888 | eliminate duplicate copies of functions and vtables and such. | |
5889 | The linker will arbitrarily choose one and discard the others. | |
5890 | The AT_*_pc values for such functions refer to local labels in | |
5891 | these sections. If the section from that file was discarded, the | |
5892 | labels are not in the output, so the relocs get a value of 0. | |
5893 | If this is a discarded function, mark the pc bounds as invalid, | |
5894 | so that GDB will ignore it. */ | |
5895 | if (has_low_pc_attr && has_high_pc_attr | |
5896 | && part_die->lowpc < part_die->highpc | |
5897 | && (part_die->lowpc != 0 | |
72dca2f5 | 5898 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 5899 | part_die->has_pc_info = 1; |
85cbf3d3 JK |
5900 | |
5901 | if (base_address_type != base_address_none && !cu->header.base_known) | |
5902 | { | |
5903 | gdb_assert (part_die->tag == DW_TAG_compile_unit); | |
5904 | cu->header.base_known = 1; | |
5905 | cu->header.base_address = base_address; | |
5906 | } | |
5907 | ||
c906108c SS |
5908 | return info_ptr; |
5909 | } | |
5910 | ||
72bf9492 DJ |
5911 | /* Find a cached partial DIE at OFFSET in CU. */ |
5912 | ||
5913 | static struct partial_die_info * | |
5914 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
5915 | { | |
5916 | struct partial_die_info *lookup_die = NULL; | |
5917 | struct partial_die_info part_die; | |
5918 | ||
5919 | part_die.offset = offset; | |
5920 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
5921 | ||
72bf9492 DJ |
5922 | return lookup_die; |
5923 | } | |
5924 | ||
5925 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
5926 | ||
5927 | static struct partial_die_info * | |
10b3939b | 5928 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu) |
72bf9492 | 5929 | { |
5afb4e99 DJ |
5930 | struct dwarf2_per_cu_data *per_cu = NULL; |
5931 | struct partial_die_info *pd = NULL; | |
72bf9492 DJ |
5932 | |
5933 | if (offset >= cu->header.offset | |
5934 | && offset < cu->header.offset + cu->header.length) | |
5afb4e99 DJ |
5935 | { |
5936 | pd = find_partial_die_in_comp_unit (offset, cu); | |
5937 | if (pd != NULL) | |
5938 | return pd; | |
5939 | } | |
72bf9492 | 5940 | |
ae038cb0 DJ |
5941 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
5942 | ||
ae038cb0 DJ |
5943 | if (per_cu->cu == NULL) |
5944 | { | |
5945 | load_comp_unit (per_cu, cu->objfile); | |
5946 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5947 | dwarf2_per_objfile->read_in_chain = per_cu; | |
5948 | } | |
5949 | ||
5950 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
5951 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
5952 | ||
5953 | if (pd == NULL && per_cu->load_all_dies == 0) | |
5954 | { | |
5955 | struct cleanup *back_to; | |
5956 | struct partial_die_info comp_unit_die; | |
5957 | struct abbrev_info *abbrev; | |
5958 | unsigned int bytes_read; | |
5959 | char *info_ptr; | |
5960 | ||
5961 | per_cu->load_all_dies = 1; | |
5962 | ||
5963 | /* Re-read the DIEs. */ | |
5964 | back_to = make_cleanup (null_cleanup, 0); | |
5965 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
5966 | { | |
5967 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
5968 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
5969 | } | |
5970 | info_ptr = per_cu->cu->header.first_die_ptr; | |
5971 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); | |
5972 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
5973 | per_cu->cu->objfile->obfd, info_ptr, | |
5974 | per_cu->cu); | |
5975 | if (comp_unit_die.has_children) | |
5976 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
5977 | do_cleanups (back_to); | |
5978 | ||
5979 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
5980 | } | |
5981 | ||
5982 | if (pd == NULL) | |
5983 | internal_error (__FILE__, __LINE__, | |
5984 | _("could not find partial DIE 0x%lx in cache [from module %s]\n"), | |
5985 | offset, bfd_get_filename (cu->objfile->obfd)); | |
5986 | return pd; | |
72bf9492 DJ |
5987 | } |
5988 | ||
5989 | /* Adjust PART_DIE before generating a symbol for it. This function | |
5990 | may set the is_external flag or change the DIE's name. */ | |
5991 | ||
5992 | static void | |
5993 | fixup_partial_die (struct partial_die_info *part_die, | |
5994 | struct dwarf2_cu *cu) | |
5995 | { | |
5996 | /* If we found a reference attribute and the DIE has no name, try | |
5997 | to find a name in the referred to DIE. */ | |
5998 | ||
5999 | if (part_die->name == NULL && part_die->has_specification) | |
6000 | { | |
6001 | struct partial_die_info *spec_die; | |
72bf9492 | 6002 | |
10b3939b | 6003 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6004 | |
10b3939b | 6005 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6006 | |
6007 | if (spec_die->name) | |
6008 | { | |
6009 | part_die->name = spec_die->name; | |
6010 | ||
6011 | /* Copy DW_AT_external attribute if it is set. */ | |
6012 | if (spec_die->is_external) | |
6013 | part_die->is_external = spec_die->is_external; | |
6014 | } | |
6015 | } | |
6016 | ||
6017 | /* Set default names for some unnamed DIEs. */ | |
6018 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6019 | || part_die->tag == DW_TAG_class_type)) | |
6020 | part_die->name = "(anonymous class)"; | |
6021 | ||
6022 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6023 | part_die->name = "(anonymous namespace)"; | |
6024 | ||
6025 | if (part_die->tag == DW_TAG_structure_type | |
6026 | || part_die->tag == DW_TAG_class_type | |
6027 | || part_die->tag == DW_TAG_union_type) | |
6028 | guess_structure_name (part_die, cu); | |
6029 | } | |
6030 | ||
639d11d3 DC |
6031 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6032 | point to a newly allocated die with its information, except for its | |
6033 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6034 | whether the die has children or not. */ | |
c906108c | 6035 | |
fe1b8b76 JB |
6036 | static gdb_byte * |
6037 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 6038 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
6039 | { |
6040 | unsigned int abbrev_number, bytes_read, i, offset; | |
6041 | struct abbrev_info *abbrev; | |
6042 | struct die_info *die; | |
6043 | ||
6502dd73 | 6044 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
6045 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6046 | info_ptr += bytes_read; | |
6047 | if (!abbrev_number) | |
6048 | { | |
1d325ec1 | 6049 | *diep = NULL; |
639d11d3 | 6050 | *has_children = 0; |
c906108c SS |
6051 | return info_ptr; |
6052 | } | |
6053 | ||
e7c27a73 | 6054 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
6055 | if (!abbrev) |
6056 | { | |
8a3fe4f8 | 6057 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 6058 | abbrev_number, |
639d11d3 | 6059 | bfd_get_filename (abfd)); |
c906108c | 6060 | } |
b60c80d6 | 6061 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
c906108c SS |
6062 | die->offset = offset; |
6063 | die->tag = abbrev->tag; | |
c906108c | 6064 | die->abbrev = abbrev_number; |
c906108c SS |
6065 | |
6066 | die->num_attrs = abbrev->num_attrs; | |
c906108c SS |
6067 | |
6068 | for (i = 0; i < abbrev->num_attrs; ++i) | |
03dd20cc DJ |
6069 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
6070 | abfd, info_ptr, cu); | |
c906108c SS |
6071 | |
6072 | *diep = die; | |
639d11d3 | 6073 | *has_children = abbrev->has_children; |
c906108c SS |
6074 | return info_ptr; |
6075 | } | |
6076 | ||
a8329558 | 6077 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6078 | |
fe1b8b76 | 6079 | static gdb_byte * |
a8329558 | 6080 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 6081 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 6082 | struct dwarf2_cu *cu) |
c906108c | 6083 | { |
e7c27a73 | 6084 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6085 | unsigned int bytes_read; |
6086 | struct dwarf_block *blk; | |
6087 | ||
a8329558 KW |
6088 | attr->form = form; |
6089 | switch (form) | |
c906108c SS |
6090 | { |
6091 | case DW_FORM_addr: | |
6092 | case DW_FORM_ref_addr: | |
e7c27a73 | 6093 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 6094 | info_ptr += bytes_read; |
c906108c SS |
6095 | break; |
6096 | case DW_FORM_block2: | |
7b5a2f43 | 6097 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6098 | blk->size = read_2_bytes (abfd, info_ptr); |
6099 | info_ptr += 2; | |
6100 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6101 | info_ptr += blk->size; | |
6102 | DW_BLOCK (attr) = blk; | |
6103 | break; | |
6104 | case DW_FORM_block4: | |
7b5a2f43 | 6105 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6106 | blk->size = read_4_bytes (abfd, info_ptr); |
6107 | info_ptr += 4; | |
6108 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6109 | info_ptr += blk->size; | |
6110 | DW_BLOCK (attr) = blk; | |
6111 | break; | |
6112 | case DW_FORM_data2: | |
6113 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
6114 | info_ptr += 2; | |
6115 | break; | |
6116 | case DW_FORM_data4: | |
6117 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
6118 | info_ptr += 4; | |
6119 | break; | |
6120 | case DW_FORM_data8: | |
6121 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
6122 | info_ptr += 8; | |
6123 | break; | |
6124 | case DW_FORM_string: | |
6125 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
6126 | info_ptr += bytes_read; | |
6127 | break; | |
4bdf3d34 JJ |
6128 | case DW_FORM_strp: |
6129 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
6130 | &bytes_read); | |
6131 | info_ptr += bytes_read; | |
6132 | break; | |
c906108c | 6133 | case DW_FORM_block: |
7b5a2f43 | 6134 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6135 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6136 | info_ptr += bytes_read; | |
6137 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6138 | info_ptr += blk->size; | |
6139 | DW_BLOCK (attr) = blk; | |
6140 | break; | |
6141 | case DW_FORM_block1: | |
7b5a2f43 | 6142 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6143 | blk->size = read_1_byte (abfd, info_ptr); |
6144 | info_ptr += 1; | |
6145 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6146 | info_ptr += blk->size; | |
6147 | DW_BLOCK (attr) = blk; | |
6148 | break; | |
6149 | case DW_FORM_data1: | |
6150 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6151 | info_ptr += 1; | |
6152 | break; | |
6153 | case DW_FORM_flag: | |
6154 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6155 | info_ptr += 1; | |
6156 | break; | |
6157 | case DW_FORM_sdata: | |
6158 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
6159 | info_ptr += bytes_read; | |
6160 | break; | |
6161 | case DW_FORM_udata: | |
6162 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6163 | info_ptr += bytes_read; | |
6164 | break; | |
6165 | case DW_FORM_ref1: | |
10b3939b | 6166 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
6167 | info_ptr += 1; |
6168 | break; | |
6169 | case DW_FORM_ref2: | |
10b3939b | 6170 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
6171 | info_ptr += 2; |
6172 | break; | |
6173 | case DW_FORM_ref4: | |
10b3939b | 6174 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
6175 | info_ptr += 4; |
6176 | break; | |
613e1657 | 6177 | case DW_FORM_ref8: |
10b3939b | 6178 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
6179 | info_ptr += 8; |
6180 | break; | |
c906108c | 6181 | case DW_FORM_ref_udata: |
10b3939b DJ |
6182 | DW_ADDR (attr) = (cu->header.offset |
6183 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
6184 | info_ptr += bytes_read; |
6185 | break; | |
c906108c | 6186 | case DW_FORM_indirect: |
a8329558 KW |
6187 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6188 | info_ptr += bytes_read; | |
e7c27a73 | 6189 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 6190 | break; |
c906108c | 6191 | default: |
8a3fe4f8 | 6192 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
6193 | dwarf_form_name (form), |
6194 | bfd_get_filename (abfd)); | |
c906108c | 6195 | } |
28e94949 JB |
6196 | |
6197 | /* We have seen instances where the compiler tried to emit a byte | |
6198 | size attribute of -1 which ended up being encoded as an unsigned | |
6199 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
6200 | an object of this size seems pretty unlikely so we can relatively | |
6201 | safely treat these cases as if the size attribute was invalid and | |
6202 | treat them as zero by default. */ | |
6203 | if (attr->name == DW_AT_byte_size | |
6204 | && form == DW_FORM_data4 | |
6205 | && DW_UNSND (attr) >= 0xffffffff) | |
01c66ae6 JB |
6206 | { |
6207 | complaint | |
6208 | (&symfile_complaints, | |
6209 | _("Suspicious DW_AT_byte_size value treated as zero instead of 0x%lx"), | |
6210 | DW_UNSND (attr)); | |
6211 | DW_UNSND (attr) = 0; | |
6212 | } | |
28e94949 | 6213 | |
c906108c SS |
6214 | return info_ptr; |
6215 | } | |
6216 | ||
a8329558 KW |
6217 | /* Read an attribute described by an abbreviated attribute. */ |
6218 | ||
fe1b8b76 | 6219 | static gdb_byte * |
a8329558 | 6220 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 6221 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
6222 | { |
6223 | attr->name = abbrev->name; | |
e7c27a73 | 6224 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
6225 | } |
6226 | ||
c906108c SS |
6227 | /* read dwarf information from a buffer */ |
6228 | ||
6229 | static unsigned int | |
fe1b8b76 | 6230 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6231 | { |
fe1b8b76 | 6232 | return bfd_get_8 (abfd, buf); |
c906108c SS |
6233 | } |
6234 | ||
6235 | static int | |
fe1b8b76 | 6236 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6237 | { |
fe1b8b76 | 6238 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
6239 | } |
6240 | ||
6241 | static unsigned int | |
fe1b8b76 | 6242 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6243 | { |
fe1b8b76 | 6244 | return bfd_get_16 (abfd, buf); |
c906108c SS |
6245 | } |
6246 | ||
6247 | static int | |
fe1b8b76 | 6248 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6249 | { |
fe1b8b76 | 6250 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
6251 | } |
6252 | ||
6253 | static unsigned int | |
fe1b8b76 | 6254 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6255 | { |
fe1b8b76 | 6256 | return bfd_get_32 (abfd, buf); |
c906108c SS |
6257 | } |
6258 | ||
6259 | static int | |
fe1b8b76 | 6260 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6261 | { |
fe1b8b76 | 6262 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
6263 | } |
6264 | ||
ce5d95e1 | 6265 | static unsigned long |
fe1b8b76 | 6266 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6267 | { |
fe1b8b76 | 6268 | return bfd_get_64 (abfd, buf); |
c906108c SS |
6269 | } |
6270 | ||
6271 | static CORE_ADDR | |
fe1b8b76 | 6272 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 6273 | unsigned int *bytes_read) |
c906108c | 6274 | { |
e7c27a73 | 6275 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6276 | CORE_ADDR retval = 0; |
6277 | ||
107d2387 | 6278 | if (cu_header->signed_addr_p) |
c906108c | 6279 | { |
107d2387 AC |
6280 | switch (cu_header->addr_size) |
6281 | { | |
6282 | case 2: | |
fe1b8b76 | 6283 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6284 | break; |
6285 | case 4: | |
fe1b8b76 | 6286 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6287 | break; |
6288 | case 8: | |
fe1b8b76 | 6289 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6290 | break; |
6291 | default: | |
8e65ff28 | 6292 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6293 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6294 | bfd_get_filename (abfd)); |
107d2387 AC |
6295 | } |
6296 | } | |
6297 | else | |
6298 | { | |
6299 | switch (cu_header->addr_size) | |
6300 | { | |
6301 | case 2: | |
fe1b8b76 | 6302 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6303 | break; |
6304 | case 4: | |
fe1b8b76 | 6305 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6306 | break; |
6307 | case 8: | |
fe1b8b76 | 6308 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6309 | break; |
6310 | default: | |
8e65ff28 | 6311 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6312 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6313 | bfd_get_filename (abfd)); |
107d2387 | 6314 | } |
c906108c | 6315 | } |
64367e0a | 6316 | |
107d2387 AC |
6317 | *bytes_read = cu_header->addr_size; |
6318 | return retval; | |
c906108c SS |
6319 | } |
6320 | ||
f7ef9339 | 6321 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6322 | specification allows the initial length to take up either 4 bytes |
6323 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6324 | bytes describe the length and all offsets will be 8 bytes in length | |
6325 | instead of 4. | |
6326 | ||
f7ef9339 KB |
6327 | An older, non-standard 64-bit format is also handled by this |
6328 | function. The older format in question stores the initial length | |
6329 | as an 8-byte quantity without an escape value. Lengths greater | |
6330 | than 2^32 aren't very common which means that the initial 4 bytes | |
6331 | is almost always zero. Since a length value of zero doesn't make | |
6332 | sense for the 32-bit format, this initial zero can be considered to | |
6333 | be an escape value which indicates the presence of the older 64-bit | |
6334 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6335 | greater than 4GB. If it becomes necessary to handle lengths |
6336 | somewhat larger than 4GB, we could allow other small values (such | |
6337 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6338 | escape values indicating the presence of the old format. | |
f7ef9339 | 6339 | |
917c78fc MK |
6340 | The value returned via bytes_read should be used to increment the |
6341 | relevant pointer after calling read_initial_length(). | |
613e1657 KB |
6342 | |
6343 | As a side effect, this function sets the fields initial_length_size | |
6344 | and offset_size in cu_header to the values appropriate for the | |
6345 | length field. (The format of the initial length field determines | |
dd373385 | 6346 | the width of file offsets to be fetched later with read_offset().) |
613e1657 KB |
6347 | |
6348 | [ Note: read_initial_length() and read_offset() are based on the | |
6349 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6350 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6351 | from: |
6352 | ||
f7ef9339 | 6353 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6354 | |
6355 | This document is only a draft and is subject to change. (So beware.) | |
6356 | ||
f7ef9339 | 6357 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6358 | determined empirically by examining 64-bit ELF files produced by |
6359 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6360 | |
6361 | - Kevin, July 16, 2002 | |
613e1657 KB |
6362 | ] */ |
6363 | ||
6364 | static LONGEST | |
fe1b8b76 | 6365 | read_initial_length (bfd *abfd, gdb_byte *buf, struct comp_unit_head *cu_header, |
891d2f0b | 6366 | unsigned int *bytes_read) |
613e1657 | 6367 | { |
fe1b8b76 | 6368 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6369 | |
dd373385 | 6370 | if (length == 0xffffffff) |
613e1657 | 6371 | { |
fe1b8b76 | 6372 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6373 | *bytes_read = 12; |
613e1657 | 6374 | } |
dd373385 | 6375 | else if (length == 0) |
f7ef9339 | 6376 | { |
dd373385 | 6377 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6378 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6379 | *bytes_read = 8; |
f7ef9339 | 6380 | } |
613e1657 KB |
6381 | else |
6382 | { | |
6383 | *bytes_read = 4; | |
613e1657 KB |
6384 | } |
6385 | ||
dd373385 EZ |
6386 | if (cu_header) |
6387 | { | |
6388 | gdb_assert (cu_header->initial_length_size == 0 | |
6389 | || cu_header->initial_length_size == 4 | |
6390 | || cu_header->initial_length_size == 8 | |
6391 | || cu_header->initial_length_size == 12); | |
6392 | ||
6393 | if (cu_header->initial_length_size != 0 | |
6394 | && cu_header->initial_length_size != *bytes_read) | |
6395 | complaint (&symfile_complaints, | |
6396 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
6397 | ||
6398 | cu_header->initial_length_size = *bytes_read; | |
6399 | cu_header->offset_size = (*bytes_read == 4) ? 4 : 8; | |
6400 | } | |
6401 | ||
6402 | return length; | |
613e1657 KB |
6403 | } |
6404 | ||
6405 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6406 | given by cu_header->offset_size. */ |
613e1657 KB |
6407 | |
6408 | static LONGEST | |
fe1b8b76 | 6409 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6410 | unsigned int *bytes_read) |
613e1657 KB |
6411 | { |
6412 | LONGEST retval = 0; | |
6413 | ||
6414 | switch (cu_header->offset_size) | |
6415 | { | |
6416 | case 4: | |
fe1b8b76 | 6417 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6418 | *bytes_read = 4; |
6419 | break; | |
6420 | case 8: | |
fe1b8b76 | 6421 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6422 | *bytes_read = 8; |
6423 | break; | |
6424 | default: | |
8e65ff28 | 6425 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6426 | _("read_offset: bad switch [in module %s]"), |
659b0389 | 6427 | bfd_get_filename (abfd)); |
613e1657 KB |
6428 | } |
6429 | ||
917c78fc | 6430 | return retval; |
613e1657 KB |
6431 | } |
6432 | ||
fe1b8b76 JB |
6433 | static gdb_byte * |
6434 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6435 | { |
6436 | /* If the size of a host char is 8 bits, we can return a pointer | |
6437 | to the buffer, otherwise we have to copy the data to a buffer | |
6438 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6439 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6440 | return buf; |
c906108c SS |
6441 | } |
6442 | ||
6443 | static char * | |
fe1b8b76 | 6444 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6445 | { |
6446 | /* If the size of a host char is 8 bits, we can return a pointer | |
6447 | to the string, otherwise we have to copy the string to a buffer | |
6448 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6449 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6450 | if (*buf == '\0') |
6451 | { | |
6452 | *bytes_read_ptr = 1; | |
6453 | return NULL; | |
6454 | } | |
fe1b8b76 JB |
6455 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6456 | return (char *) buf; | |
4bdf3d34 JJ |
6457 | } |
6458 | ||
6459 | static char * | |
fe1b8b76 | 6460 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6461 | const struct comp_unit_head *cu_header, |
6462 | unsigned int *bytes_read_ptr) | |
6463 | { | |
6464 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
891d2f0b | 6465 | bytes_read_ptr); |
c906108c | 6466 | |
6502dd73 | 6467 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 6468 | { |
8a3fe4f8 | 6469 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6470 | bfd_get_filename (abfd)); |
4bdf3d34 | 6471 | return NULL; |
c906108c | 6472 | } |
6502dd73 | 6473 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 6474 | { |
8a3fe4f8 | 6475 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6476 | bfd_get_filename (abfd)); |
c906108c SS |
6477 | return NULL; |
6478 | } | |
4bdf3d34 | 6479 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 6480 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 6481 | return NULL; |
fe1b8b76 | 6482 | return (char *) (dwarf2_per_objfile->str_buffer + str_offset); |
c906108c SS |
6483 | } |
6484 | ||
ce5d95e1 | 6485 | static unsigned long |
fe1b8b76 | 6486 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6487 | { |
ce5d95e1 JB |
6488 | unsigned long result; |
6489 | unsigned int num_read; | |
c906108c SS |
6490 | int i, shift; |
6491 | unsigned char byte; | |
6492 | ||
6493 | result = 0; | |
6494 | shift = 0; | |
6495 | num_read = 0; | |
6496 | i = 0; | |
6497 | while (1) | |
6498 | { | |
fe1b8b76 | 6499 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6500 | buf++; |
6501 | num_read++; | |
ce5d95e1 | 6502 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6503 | if ((byte & 128) == 0) |
6504 | { | |
6505 | break; | |
6506 | } | |
6507 | shift += 7; | |
6508 | } | |
6509 | *bytes_read_ptr = num_read; | |
6510 | return result; | |
6511 | } | |
6512 | ||
ce5d95e1 | 6513 | static long |
fe1b8b76 | 6514 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6515 | { |
ce5d95e1 | 6516 | long result; |
77e0b926 | 6517 | int i, shift, num_read; |
c906108c SS |
6518 | unsigned char byte; |
6519 | ||
6520 | result = 0; | |
6521 | shift = 0; | |
c906108c SS |
6522 | num_read = 0; |
6523 | i = 0; | |
6524 | while (1) | |
6525 | { | |
fe1b8b76 | 6526 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6527 | buf++; |
6528 | num_read++; | |
ce5d95e1 | 6529 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6530 | shift += 7; |
6531 | if ((byte & 128) == 0) | |
6532 | { | |
6533 | break; | |
6534 | } | |
6535 | } | |
77e0b926 DJ |
6536 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6537 | result |= -(((long)1) << shift); | |
c906108c SS |
6538 | *bytes_read_ptr = num_read; |
6539 | return result; | |
6540 | } | |
6541 | ||
4bb7a0a7 DJ |
6542 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6543 | ||
fe1b8b76 JB |
6544 | static gdb_byte * |
6545 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6546 | { |
6547 | int byte; | |
6548 | ||
6549 | while (1) | |
6550 | { | |
fe1b8b76 | 6551 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6552 | buf++; |
6553 | if ((byte & 128) == 0) | |
6554 | return buf; | |
6555 | } | |
6556 | } | |
6557 | ||
c906108c | 6558 | static void |
e142c38c | 6559 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6560 | { |
6561 | switch (lang) | |
6562 | { | |
6563 | case DW_LANG_C89: | |
6564 | case DW_LANG_C: | |
e142c38c | 6565 | cu->language = language_c; |
c906108c SS |
6566 | break; |
6567 | case DW_LANG_C_plus_plus: | |
e142c38c | 6568 | cu->language = language_cplus; |
c906108c SS |
6569 | break; |
6570 | case DW_LANG_Fortran77: | |
6571 | case DW_LANG_Fortran90: | |
b21b22e0 | 6572 | case DW_LANG_Fortran95: |
e142c38c | 6573 | cu->language = language_fortran; |
c906108c SS |
6574 | break; |
6575 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6576 | cu->language = language_asm; |
c906108c | 6577 | break; |
bebd888e | 6578 | case DW_LANG_Java: |
e142c38c | 6579 | cu->language = language_java; |
bebd888e | 6580 | break; |
c906108c | 6581 | case DW_LANG_Ada83: |
8aaf0b47 | 6582 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6583 | cu->language = language_ada; |
6584 | break; | |
72019c9c GM |
6585 | case DW_LANG_Modula2: |
6586 | cu->language = language_m2; | |
6587 | break; | |
fe8e67fd PM |
6588 | case DW_LANG_Pascal83: |
6589 | cu->language = language_pascal; | |
6590 | break; | |
22566fbd DJ |
6591 | case DW_LANG_ObjC: |
6592 | cu->language = language_objc; | |
6593 | break; | |
c906108c SS |
6594 | case DW_LANG_Cobol74: |
6595 | case DW_LANG_Cobol85: | |
c906108c | 6596 | default: |
e142c38c | 6597 | cu->language = language_minimal; |
c906108c SS |
6598 | break; |
6599 | } | |
e142c38c | 6600 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6601 | } |
6602 | ||
6603 | /* Return the named attribute or NULL if not there. */ | |
6604 | ||
6605 | static struct attribute * | |
e142c38c | 6606 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6607 | { |
6608 | unsigned int i; | |
6609 | struct attribute *spec = NULL; | |
6610 | ||
6611 | for (i = 0; i < die->num_attrs; ++i) | |
6612 | { | |
6613 | if (die->attrs[i].name == name) | |
10b3939b | 6614 | return &die->attrs[i]; |
c906108c SS |
6615 | if (die->attrs[i].name == DW_AT_specification |
6616 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6617 | spec = &die->attrs[i]; | |
6618 | } | |
c906108c | 6619 | |
10b3939b | 6620 | if (spec) |
f2f0e013 DJ |
6621 | { |
6622 | die = follow_die_ref (die, spec, &cu); | |
6623 | return dwarf2_attr (die, name, cu); | |
6624 | } | |
c5aa993b | 6625 | |
c906108c SS |
6626 | return NULL; |
6627 | } | |
6628 | ||
05cf31d1 JB |
6629 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6630 | and holds a non-zero value. This function should only be used for | |
6631 | DW_FORM_flag attributes. */ | |
6632 | ||
6633 | static int | |
6634 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6635 | { | |
6636 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6637 | ||
6638 | return (attr && DW_UNSND (attr)); | |
6639 | } | |
6640 | ||
3ca72b44 | 6641 | static int |
e142c38c | 6642 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6643 | { |
05cf31d1 JB |
6644 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6645 | which value is non-zero. However, we have to be careful with | |
6646 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6647 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6648 | end up accidently finding a declaration attribute that belongs | |
6649 | to a different DIE referenced by the specification attribute, | |
6650 | even though the given DIE does not have a declaration attribute. */ | |
6651 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6652 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6653 | } |
6654 | ||
63d06c5c | 6655 | /* Return the die giving the specification for DIE, if there is |
f2f0e013 DJ |
6656 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
6657 | containing the return value on output. */ | |
63d06c5c DC |
6658 | |
6659 | static struct die_info * | |
f2f0e013 | 6660 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
63d06c5c | 6661 | { |
f2f0e013 DJ |
6662 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
6663 | *spec_cu); | |
63d06c5c DC |
6664 | |
6665 | if (spec_attr == NULL) | |
6666 | return NULL; | |
6667 | else | |
f2f0e013 | 6668 | return follow_die_ref (die, spec_attr, spec_cu); |
63d06c5c | 6669 | } |
c906108c | 6670 | |
debd256d JB |
6671 | /* Free the line_header structure *LH, and any arrays and strings it |
6672 | refers to. */ | |
6673 | static void | |
6674 | free_line_header (struct line_header *lh) | |
6675 | { | |
6676 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6677 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6678 | |
6679 | /* Remember that all the lh->file_names[i].name pointers are | |
6680 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6681 | if (lh->file_names) | |
a8bc7b56 | 6682 | xfree (lh->file_names); |
debd256d JB |
6683 | |
6684 | /* Similarly for the include directory names. */ | |
6685 | if (lh->include_dirs) | |
a8bc7b56 | 6686 | xfree (lh->include_dirs); |
debd256d | 6687 | |
a8bc7b56 | 6688 | xfree (lh); |
debd256d JB |
6689 | } |
6690 | ||
6691 | ||
6692 | /* Add an entry to LH's include directory table. */ | |
6693 | static void | |
6694 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6695 | { |
debd256d JB |
6696 | /* Grow the array if necessary. */ |
6697 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6698 | { |
debd256d JB |
6699 | lh->include_dirs_size = 1; /* for testing */ |
6700 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6701 | * sizeof (*lh->include_dirs)); | |
6702 | } | |
6703 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
6704 | { | |
6705 | lh->include_dirs_size *= 2; | |
6706 | lh->include_dirs = xrealloc (lh->include_dirs, | |
6707 | (lh->include_dirs_size | |
6708 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 6709 | } |
c906108c | 6710 | |
debd256d JB |
6711 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
6712 | } | |
6713 | ||
6714 | ||
6715 | /* Add an entry to LH's file name table. */ | |
6716 | static void | |
6717 | add_file_name (struct line_header *lh, | |
6718 | char *name, | |
6719 | unsigned int dir_index, | |
6720 | unsigned int mod_time, | |
6721 | unsigned int length) | |
6722 | { | |
6723 | struct file_entry *fe; | |
6724 | ||
6725 | /* Grow the array if necessary. */ | |
6726 | if (lh->file_names_size == 0) | |
6727 | { | |
6728 | lh->file_names_size = 1; /* for testing */ | |
6729 | lh->file_names = xmalloc (lh->file_names_size | |
6730 | * sizeof (*lh->file_names)); | |
6731 | } | |
6732 | else if (lh->num_file_names >= lh->file_names_size) | |
6733 | { | |
6734 | lh->file_names_size *= 2; | |
6735 | lh->file_names = xrealloc (lh->file_names, | |
6736 | (lh->file_names_size | |
6737 | * sizeof (*lh->file_names))); | |
6738 | } | |
6739 | ||
6740 | fe = &lh->file_names[lh->num_file_names++]; | |
6741 | fe->name = name; | |
6742 | fe->dir_index = dir_index; | |
6743 | fe->mod_time = mod_time; | |
6744 | fe->length = length; | |
aaa75496 | 6745 | fe->included_p = 0; |
cb1df416 | 6746 | fe->symtab = NULL; |
debd256d JB |
6747 | } |
6748 | ||
6749 | ||
6750 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
6751 | .debug_line, according to the endianness of ABFD. Return a pointer |
6752 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
6753 | |
6754 | NOTE: the strings in the include directory and file name tables of | |
6755 | the returned object point into debug_line_buffer, and must not be | |
6756 | freed. */ | |
6757 | static struct line_header * | |
6758 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 6759 | struct dwarf2_cu *cu) |
debd256d JB |
6760 | { |
6761 | struct cleanup *back_to; | |
6762 | struct line_header *lh; | |
fe1b8b76 | 6763 | gdb_byte *line_ptr; |
891d2f0b | 6764 | unsigned int bytes_read; |
debd256d JB |
6765 | int i; |
6766 | char *cur_dir, *cur_file; | |
6767 | ||
6502dd73 | 6768 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 6769 | { |
e2e0b3e5 | 6770 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
6771 | return 0; |
6772 | } | |
6773 | ||
a738430d MK |
6774 | /* Make sure that at least there's room for the total_length field. |
6775 | That could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 6776 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 6777 | { |
4d3c2250 | 6778 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6779 | return 0; |
6780 | } | |
6781 | ||
6782 | lh = xmalloc (sizeof (*lh)); | |
6783 | memset (lh, 0, sizeof (*lh)); | |
6784 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
6785 | (void *) lh); | |
6786 | ||
6502dd73 | 6787 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d | 6788 | |
a738430d | 6789 | /* Read in the header. */ |
dd373385 EZ |
6790 | lh->total_length = |
6791 | read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); | |
debd256d | 6792 | line_ptr += bytes_read; |
6502dd73 DJ |
6793 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
6794 | + dwarf2_per_objfile->line_size)) | |
debd256d | 6795 | { |
4d3c2250 | 6796 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6797 | return 0; |
6798 | } | |
6799 | lh->statement_program_end = line_ptr + lh->total_length; | |
6800 | lh->version = read_2_bytes (abfd, line_ptr); | |
6801 | line_ptr += 2; | |
e7c27a73 | 6802 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
6803 | line_ptr += bytes_read; |
6804 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
6805 | line_ptr += 1; | |
6806 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
6807 | line_ptr += 1; | |
6808 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
6809 | line_ptr += 1; | |
6810 | lh->line_range = read_1_byte (abfd, line_ptr); | |
6811 | line_ptr += 1; | |
6812 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
6813 | line_ptr += 1; | |
6814 | lh->standard_opcode_lengths | |
fe1b8b76 | 6815 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
6816 | |
6817 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
6818 | for (i = 1; i < lh->opcode_base; ++i) | |
6819 | { | |
6820 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
6821 | line_ptr += 1; | |
6822 | } | |
6823 | ||
a738430d | 6824 | /* Read directory table. */ |
debd256d JB |
6825 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6826 | { | |
6827 | line_ptr += bytes_read; | |
6828 | add_include_dir (lh, cur_dir); | |
6829 | } | |
6830 | line_ptr += bytes_read; | |
6831 | ||
a738430d | 6832 | /* Read file name table. */ |
debd256d JB |
6833 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6834 | { | |
6835 | unsigned int dir_index, mod_time, length; | |
6836 | ||
6837 | line_ptr += bytes_read; | |
6838 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6839 | line_ptr += bytes_read; | |
6840 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6841 | line_ptr += bytes_read; | |
6842 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6843 | line_ptr += bytes_read; | |
6844 | ||
6845 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6846 | } | |
6847 | line_ptr += bytes_read; | |
6848 | lh->statement_program_start = line_ptr; | |
6849 | ||
6502dd73 DJ |
6850 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
6851 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 | 6852 | complaint (&symfile_complaints, |
e2e0b3e5 | 6853 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
6854 | |
6855 | discard_cleanups (back_to); | |
6856 | return lh; | |
6857 | } | |
c906108c | 6858 | |
5fb290d7 DJ |
6859 | /* This function exists to work around a bug in certain compilers |
6860 | (particularly GCC 2.95), in which the first line number marker of a | |
6861 | function does not show up until after the prologue, right before | |
6862 | the second line number marker. This function shifts ADDRESS down | |
6863 | to the beginning of the function if necessary, and is called on | |
6864 | addresses passed to record_line. */ | |
6865 | ||
6866 | static CORE_ADDR | |
e142c38c | 6867 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
6868 | { |
6869 | struct function_range *fn; | |
6870 | ||
6871 | /* Find the function_range containing address. */ | |
e142c38c | 6872 | if (!cu->first_fn) |
5fb290d7 DJ |
6873 | return address; |
6874 | ||
e142c38c DJ |
6875 | if (!cu->cached_fn) |
6876 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 6877 | |
e142c38c | 6878 | fn = cu->cached_fn; |
5fb290d7 DJ |
6879 | while (fn) |
6880 | if (fn->lowpc <= address && fn->highpc > address) | |
6881 | goto found; | |
6882 | else | |
6883 | fn = fn->next; | |
6884 | ||
e142c38c DJ |
6885 | fn = cu->first_fn; |
6886 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
6887 | if (fn->lowpc <= address && fn->highpc > address) |
6888 | goto found; | |
6889 | else | |
6890 | fn = fn->next; | |
6891 | ||
6892 | return address; | |
6893 | ||
6894 | found: | |
6895 | if (fn->seen_line) | |
6896 | return address; | |
6897 | if (address != fn->lowpc) | |
4d3c2250 | 6898 | complaint (&symfile_complaints, |
e2e0b3e5 | 6899 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 6900 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
6901 | fn->seen_line = 1; |
6902 | return fn->lowpc; | |
6903 | } | |
6904 | ||
aaa75496 JB |
6905 | /* Decode the Line Number Program (LNP) for the given line_header |
6906 | structure and CU. The actual information extracted and the type | |
6907 | of structures created from the LNP depends on the value of PST. | |
6908 | ||
6909 | 1. If PST is NULL, then this procedure uses the data from the program | |
6910 | to create all necessary symbol tables, and their linetables. | |
6911 | The compilation directory of the file is passed in COMP_DIR, | |
6912 | and must not be NULL. | |
6913 | ||
6914 | 2. If PST is not NULL, this procedure reads the program to determine | |
6915 | the list of files included by the unit represented by PST, and | |
6916 | builds all the associated partial symbol tables. In this case, | |
6917 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
6918 | is not used to compute the full name of the symtab, and therefore | |
6919 | omitting it when building the partial symtab does not introduce | |
6920 | the potential for inconsistency - a partial symtab and its associated | |
6921 | symbtab having a different fullname -). */ | |
debd256d | 6922 | |
c906108c | 6923 | static void |
debd256d | 6924 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 6925 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 6926 | { |
a8c50c1f | 6927 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 6928 | gdb_byte *line_end; |
a8c50c1f | 6929 | unsigned int bytes_read, extended_len; |
c906108c | 6930 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
6931 | CORE_ADDR baseaddr; |
6932 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 6933 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 6934 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
6935 | |
6936 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6937 | |
debd256d JB |
6938 | line_ptr = lh->statement_program_start; |
6939 | line_end = lh->statement_program_end; | |
c906108c SS |
6940 | |
6941 | /* Read the statement sequences until there's nothing left. */ | |
6942 | while (line_ptr < line_end) | |
6943 | { | |
6944 | /* state machine registers */ | |
6945 | CORE_ADDR address = 0; | |
6946 | unsigned int file = 1; | |
6947 | unsigned int line = 1; | |
6948 | unsigned int column = 0; | |
debd256d | 6949 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
6950 | int basic_block = 0; |
6951 | int end_sequence = 0; | |
6952 | ||
aaa75496 | 6953 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 6954 | { |
aaa75496 | 6955 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
6956 | /* lh->include_dirs and lh->file_names are 0-based, but the |
6957 | directory and file name numbers in the statement program | |
6958 | are 1-based. */ | |
6959 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 6960 | char *dir = NULL; |
a738430d | 6961 | |
debd256d JB |
6962 | if (fe->dir_index) |
6963 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
6964 | |
6965 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
6966 | } |
6967 | ||
a738430d | 6968 | /* Decode the table. */ |
c5aa993b | 6969 | while (!end_sequence) |
c906108c SS |
6970 | { |
6971 | op_code = read_1_byte (abfd, line_ptr); | |
6972 | line_ptr += 1; | |
9aa1fe7e | 6973 | |
debd256d | 6974 | if (op_code >= lh->opcode_base) |
a738430d MK |
6975 | { |
6976 | /* Special operand. */ | |
debd256d JB |
6977 | adj_opcode = op_code - lh->opcode_base; |
6978 | address += (adj_opcode / lh->line_range) | |
6979 | * lh->minimum_instruction_length; | |
6980 | line += lh->line_base + (adj_opcode % lh->line_range); | |
25e43795 DJ |
6981 | if (lh->num_file_names < file) |
6982 | dwarf2_debug_line_missing_file_complaint (); | |
6983 | else | |
6984 | { | |
6985 | lh->file_names[file - 1].included_p = 1; | |
6986 | if (!decode_for_pst_p) | |
6987 | { | |
6988 | if (last_subfile != current_subfile) | |
6989 | { | |
6990 | if (last_subfile) | |
6991 | record_line (last_subfile, 0, address); | |
6992 | last_subfile = current_subfile; | |
6993 | } | |
6994 | /* Append row to matrix using current values. */ | |
6995 | record_line (current_subfile, line, | |
6996 | check_cu_functions (address, cu)); | |
366da635 | 6997 | } |
25e43795 | 6998 | } |
9aa1fe7e GK |
6999 | basic_block = 1; |
7000 | } | |
7001 | else switch (op_code) | |
c906108c SS |
7002 | { |
7003 | case DW_LNS_extended_op: | |
a8c50c1f | 7004 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7005 | line_ptr += bytes_read; |
a8c50c1f | 7006 | extended_end = line_ptr + extended_len; |
c906108c SS |
7007 | extended_op = read_1_byte (abfd, line_ptr); |
7008 | line_ptr += 1; | |
7009 | switch (extended_op) | |
7010 | { | |
7011 | case DW_LNE_end_sequence: | |
7012 | end_sequence = 1; | |
25e43795 DJ |
7013 | |
7014 | if (lh->num_file_names < file) | |
7015 | dwarf2_debug_line_missing_file_complaint (); | |
7016 | else | |
7017 | { | |
7018 | lh->file_names[file - 1].included_p = 1; | |
7019 | if (!decode_for_pst_p) | |
7020 | record_line (current_subfile, 0, address); | |
7021 | } | |
c906108c SS |
7022 | break; |
7023 | case DW_LNE_set_address: | |
e7c27a73 | 7024 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7025 | line_ptr += bytes_read; |
7026 | address += baseaddr; | |
c906108c SS |
7027 | break; |
7028 | case DW_LNE_define_file: | |
debd256d JB |
7029 | { |
7030 | char *cur_file; | |
7031 | unsigned int dir_index, mod_time, length; | |
7032 | ||
7033 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
7034 | line_ptr += bytes_read; | |
7035 | dir_index = | |
7036 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7037 | line_ptr += bytes_read; | |
7038 | mod_time = | |
7039 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7040 | line_ptr += bytes_read; | |
7041 | length = | |
7042 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7043 | line_ptr += bytes_read; | |
7044 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7045 | } | |
c906108c SS |
7046 | break; |
7047 | default: | |
4d3c2250 | 7048 | complaint (&symfile_complaints, |
e2e0b3e5 | 7049 | _("mangled .debug_line section")); |
debd256d | 7050 | return; |
c906108c | 7051 | } |
a8c50c1f DJ |
7052 | /* Make sure that we parsed the extended op correctly. If e.g. |
7053 | we expected a different address size than the producer used, | |
7054 | we may have read the wrong number of bytes. */ | |
7055 | if (line_ptr != extended_end) | |
7056 | { | |
7057 | complaint (&symfile_complaints, | |
7058 | _("mangled .debug_line section")); | |
7059 | return; | |
7060 | } | |
c906108c SS |
7061 | break; |
7062 | case DW_LNS_copy: | |
25e43795 DJ |
7063 | if (lh->num_file_names < file) |
7064 | dwarf2_debug_line_missing_file_complaint (); | |
7065 | else | |
366da635 | 7066 | { |
25e43795 DJ |
7067 | lh->file_names[file - 1].included_p = 1; |
7068 | if (!decode_for_pst_p) | |
7069 | { | |
7070 | if (last_subfile != current_subfile) | |
7071 | { | |
7072 | if (last_subfile) | |
7073 | record_line (last_subfile, 0, address); | |
7074 | last_subfile = current_subfile; | |
7075 | } | |
7076 | record_line (current_subfile, line, | |
7077 | check_cu_functions (address, cu)); | |
7078 | } | |
366da635 | 7079 | } |
c906108c SS |
7080 | basic_block = 0; |
7081 | break; | |
7082 | case DW_LNS_advance_pc: | |
debd256d | 7083 | address += lh->minimum_instruction_length |
c906108c SS |
7084 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7085 | line_ptr += bytes_read; | |
7086 | break; | |
7087 | case DW_LNS_advance_line: | |
7088 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
7089 | line_ptr += bytes_read; | |
7090 | break; | |
7091 | case DW_LNS_set_file: | |
debd256d | 7092 | { |
a738430d MK |
7093 | /* The arrays lh->include_dirs and lh->file_names are |
7094 | 0-based, but the directory and file name numbers in | |
7095 | the statement program are 1-based. */ | |
debd256d | 7096 | struct file_entry *fe; |
4f1520fb | 7097 | char *dir = NULL; |
a738430d | 7098 | |
debd256d JB |
7099 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7100 | line_ptr += bytes_read; | |
25e43795 DJ |
7101 | if (lh->num_file_names < file) |
7102 | dwarf2_debug_line_missing_file_complaint (); | |
7103 | else | |
7104 | { | |
7105 | fe = &lh->file_names[file - 1]; | |
7106 | if (fe->dir_index) | |
7107 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7108 | if (!decode_for_pst_p) | |
7109 | { | |
7110 | last_subfile = current_subfile; | |
7111 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7112 | } | |
7113 | } | |
debd256d | 7114 | } |
c906108c SS |
7115 | break; |
7116 | case DW_LNS_set_column: | |
7117 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7118 | line_ptr += bytes_read; | |
7119 | break; | |
7120 | case DW_LNS_negate_stmt: | |
7121 | is_stmt = (!is_stmt); | |
7122 | break; | |
7123 | case DW_LNS_set_basic_block: | |
7124 | basic_block = 1; | |
7125 | break; | |
c2c6d25f JM |
7126 | /* Add to the address register of the state machine the |
7127 | address increment value corresponding to special opcode | |
a738430d MK |
7128 | 255. I.e., this value is scaled by the minimum |
7129 | instruction length since special opcode 255 would have | |
7130 | scaled the the increment. */ | |
c906108c | 7131 | case DW_LNS_const_add_pc: |
debd256d JB |
7132 | address += (lh->minimum_instruction_length |
7133 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
7134 | break; |
7135 | case DW_LNS_fixed_advance_pc: | |
7136 | address += read_2_bytes (abfd, line_ptr); | |
7137 | line_ptr += 2; | |
7138 | break; | |
9aa1fe7e | 7139 | default: |
a738430d MK |
7140 | { |
7141 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 7142 | int i; |
a738430d | 7143 | |
debd256d | 7144 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
7145 | { |
7146 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7147 | line_ptr += bytes_read; | |
7148 | } | |
7149 | } | |
c906108c SS |
7150 | } |
7151 | } | |
7152 | } | |
aaa75496 JB |
7153 | |
7154 | if (decode_for_pst_p) | |
7155 | { | |
7156 | int file_index; | |
7157 | ||
7158 | /* Now that we're done scanning the Line Header Program, we can | |
7159 | create the psymtab of each included file. */ | |
7160 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
7161 | if (lh->file_names[file_index].included_p == 1) | |
7162 | { | |
5b5464ad JB |
7163 | const struct file_entry fe = lh->file_names [file_index]; |
7164 | char *include_name = fe.name; | |
7165 | char *dir_name = NULL; | |
7166 | char *pst_filename = pst->filename; | |
7167 | ||
7168 | if (fe.dir_index) | |
7169 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
7170 | ||
7171 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
7172 | { | |
1754f103 MK |
7173 | include_name = concat (dir_name, SLASH_STRING, |
7174 | include_name, (char *)NULL); | |
5b5464ad JB |
7175 | make_cleanup (xfree, include_name); |
7176 | } | |
7177 | ||
7178 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
7179 | { | |
1754f103 MK |
7180 | pst_filename = concat (pst->dirname, SLASH_STRING, |
7181 | pst_filename, (char *)NULL); | |
5b5464ad JB |
7182 | make_cleanup (xfree, pst_filename); |
7183 | } | |
7184 | ||
7185 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
7186 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
7187 | } | |
7188 | } | |
cb1df416 DJ |
7189 | else |
7190 | { | |
7191 | /* Make sure a symtab is created for every file, even files | |
7192 | which contain only variables (i.e. no code with associated | |
7193 | line numbers). */ | |
7194 | ||
7195 | int i; | |
7196 | struct file_entry *fe; | |
7197 | ||
7198 | for (i = 0; i < lh->num_file_names; i++) | |
7199 | { | |
7200 | char *dir = NULL; | |
7201 | fe = &lh->file_names[i]; | |
7202 | if (fe->dir_index) | |
7203 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7204 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7205 | ||
7206 | /* Skip the main file; we don't need it, and it must be | |
7207 | allocated last, so that it will show up before the | |
7208 | non-primary symtabs in the objfile's symtab list. */ | |
7209 | if (current_subfile == first_subfile) | |
7210 | continue; | |
7211 | ||
7212 | if (current_subfile->symtab == NULL) | |
7213 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
7214 | cu->objfile); | |
7215 | fe->symtab = current_subfile->symtab; | |
7216 | } | |
7217 | } | |
c906108c SS |
7218 | } |
7219 | ||
7220 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
7221 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
7222 | or NULL if not known. COMP_DIR is the compilation directory for the |
7223 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
7224 | This routine tries to keep line numbers from identical absolute and |
7225 | relative file names in a common subfile. | |
7226 | ||
7227 | Using the `list' example from the GDB testsuite, which resides in | |
7228 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
7229 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
7230 | ||
c5aa993b JM |
7231 | DW_AT_name: /srcdir/list0.c |
7232 | DW_AT_comp_dir: /compdir | |
357e46e7 | 7233 | files.files[0].name: list0.h |
c5aa993b | 7234 | files.files[0].dir: /srcdir |
357e46e7 | 7235 | files.files[1].name: list0.c |
c5aa993b | 7236 | files.files[1].dir: /srcdir |
c906108c SS |
7237 | |
7238 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
7239 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
7240 | start_subfile will ensure that this happens provided that we pass the | |
7241 | concatenation of files.files[1].dir and files.files[1].name as the | |
7242 | subfile's name. */ | |
c906108c SS |
7243 | |
7244 | static void | |
4f1520fb | 7245 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 7246 | { |
4f1520fb FR |
7247 | char *fullname; |
7248 | ||
7249 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
7250 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
7251 | second argument to start_subfile. To be consistent, we do the | |
7252 | same here. In order not to lose the line information directory, | |
7253 | we concatenate it to the filename when it makes sense. | |
7254 | Note that the Dwarf3 standard says (speaking of filenames in line | |
7255 | information): ``The directory index is ignored for file names | |
7256 | that represent full path names''. Thus ignoring dirname in the | |
7257 | `else' branch below isn't an issue. */ | |
c906108c | 7258 | |
d5166ae1 | 7259 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
7260 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
7261 | else | |
7262 | fullname = filename; | |
c906108c | 7263 | |
4f1520fb FR |
7264 | start_subfile (fullname, comp_dir); |
7265 | ||
7266 | if (fullname != filename) | |
7267 | xfree (fullname); | |
c906108c SS |
7268 | } |
7269 | ||
4c2df51b DJ |
7270 | static void |
7271 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 7272 | struct dwarf2_cu *cu) |
4c2df51b | 7273 | { |
e7c27a73 DJ |
7274 | struct objfile *objfile = cu->objfile; |
7275 | struct comp_unit_head *cu_header = &cu->header; | |
7276 | ||
4c2df51b DJ |
7277 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
7278 | code here to turn a symbol with DW_AT_external and a | |
7279 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
7280 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
7281 | with some versions of binutils) where shared libraries could have | |
7282 | relocations against symbols in their debug information - the | |
7283 | minimal symbol would have the right address, but the debug info | |
7284 | would not. It's no longer necessary, because we will explicitly | |
7285 | apply relocations when we read in the debug information now. */ | |
7286 | ||
7287 | /* A DW_AT_location attribute with no contents indicates that a | |
7288 | variable has been optimized away. */ | |
7289 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
7290 | { | |
7291 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
7292 | return; | |
7293 | } | |
7294 | ||
7295 | /* Handle one degenerate form of location expression specially, to | |
7296 | preserve GDB's previous behavior when section offsets are | |
7297 | specified. If this is just a DW_OP_addr then mark this symbol | |
7298 | as LOC_STATIC. */ | |
7299 | ||
7300 | if (attr_form_is_block (attr) | |
7301 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
7302 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
7303 | { | |
891d2f0b | 7304 | unsigned int dummy; |
4c2df51b DJ |
7305 | |
7306 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 7307 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 7308 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
7309 | fixup_symbol_section (sym, objfile); |
7310 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
7311 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
7312 | return; |
7313 | } | |
7314 | ||
7315 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
7316 | expression evaluator, and use LOC_COMPUTED only when necessary | |
7317 | (i.e. when the value of a register or memory location is | |
7318 | referenced, or a thread-local block, etc.). Then again, it might | |
7319 | not be worthwhile. I'm assuming that it isn't unless performance | |
7320 | or memory numbers show me otherwise. */ | |
7321 | ||
e7c27a73 | 7322 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
7323 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
7324 | } | |
7325 | ||
c906108c SS |
7326 | /* Given a pointer to a DWARF information entry, figure out if we need |
7327 | to make a symbol table entry for it, and if so, create a new entry | |
7328 | and return a pointer to it. | |
7329 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 7330 | used the passed type. */ |
c906108c SS |
7331 | |
7332 | static struct symbol * | |
e7c27a73 | 7333 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 7334 | { |
e7c27a73 | 7335 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7336 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7337 | struct symbol *sym = NULL; |
7338 | char *name; | |
7339 | struct attribute *attr = NULL; | |
7340 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
7341 | CORE_ADDR baseaddr; |
7342 | ||
7343 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7344 | |
5c4e30ca | 7345 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7346 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7347 | else |
7348 | name = TYPE_NAME (type); | |
7349 | ||
c906108c SS |
7350 | if (name) |
7351 | { | |
4a146b47 | 7352 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7353 | sizeof (struct symbol)); |
7354 | OBJSTAT (objfile, n_syms++); | |
7355 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7356 | |
7357 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7358 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7359 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7360 | |
7361 | /* Default assumptions. | |
c5aa993b | 7362 | Use the passed type or decode it from the die. */ |
176620f1 | 7363 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7364 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7365 | if (type != NULL) |
7366 | SYMBOL_TYPE (sym) = type; | |
7367 | else | |
e7c27a73 | 7368 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7369 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7370 | if (attr) |
7371 | { | |
7372 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7373 | } | |
cb1df416 DJ |
7374 | |
7375 | attr = dwarf2_attr (die, DW_AT_decl_file, cu); | |
7376 | if (attr) | |
7377 | { | |
7378 | int file_index = DW_UNSND (attr); | |
7379 | if (cu->line_header == NULL | |
7380 | || file_index > cu->line_header->num_file_names) | |
7381 | complaint (&symfile_complaints, | |
7382 | _("file index out of range")); | |
1c3d648d | 7383 | else if (file_index > 0) |
cb1df416 DJ |
7384 | { |
7385 | struct file_entry *fe; | |
7386 | fe = &cu->line_header->file_names[file_index - 1]; | |
7387 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
7388 | } | |
7389 | } | |
7390 | ||
c906108c SS |
7391 | switch (die->tag) |
7392 | { | |
7393 | case DW_TAG_label: | |
e142c38c | 7394 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7395 | if (attr) |
7396 | { | |
7397 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7398 | } | |
7399 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7400 | break; | |
7401 | case DW_TAG_subprogram: | |
7402 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7403 | finish_block. */ | |
7404 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7405 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
7406 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
7407 | || cu->language == language_ada) | |
c906108c | 7408 | { |
2cfa0c8d JB |
7409 | /* Subprograms marked external are stored as a global symbol. |
7410 | Ada subprograms, whether marked external or not, are always | |
7411 | stored as a global symbol, because we want to be able to | |
7412 | access them globally. For instance, we want to be able | |
7413 | to break on a nested subprogram without having to | |
7414 | specify the context. */ | |
c906108c SS |
7415 | add_symbol_to_list (sym, &global_symbols); |
7416 | } | |
7417 | else | |
7418 | { | |
e142c38c | 7419 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7420 | } |
7421 | break; | |
7422 | case DW_TAG_variable: | |
7423 | /* Compilation with minimal debug info may result in variables | |
7424 | with missing type entries. Change the misleading `void' type | |
7425 | to something sensible. */ | |
7426 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 7427 | SYMBOL_TYPE (sym) |
5e2b427d | 7428 | = builtin_type (gdbarch)->nodebug_data_symbol; |
64c50499 | 7429 | |
e142c38c | 7430 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7431 | if (attr) |
7432 | { | |
e7c27a73 | 7433 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7434 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7435 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7436 | add_symbol_to_list (sym, &global_symbols); | |
7437 | else | |
e142c38c | 7438 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7439 | break; |
7440 | } | |
e142c38c | 7441 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7442 | if (attr) |
7443 | { | |
e7c27a73 | 7444 | var_decode_location (attr, sym, cu); |
e142c38c | 7445 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7446 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7447 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7448 | else |
e142c38c | 7449 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7450 | } |
7451 | else | |
7452 | { | |
7453 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7454 | If it is an external symbol and we have type information |
7455 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7456 | The address of the variable will then be determined from | |
7457 | the minimal symbol table whenever the variable is | |
7458 | referenced. */ | |
e142c38c | 7459 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7460 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7461 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7462 | { |
7463 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
7464 | add_symbol_to_list (sym, &global_symbols); | |
7465 | } | |
7466 | } | |
7467 | break; | |
7468 | case DW_TAG_formal_parameter: | |
2a2d4dc3 | 7469 | SYMBOL_IS_ARGUMENT (sym) = 1; |
e142c38c | 7470 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7471 | if (attr) |
7472 | { | |
e7c27a73 | 7473 | var_decode_location (attr, sym, cu); |
c906108c | 7474 | } |
e142c38c | 7475 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7476 | if (attr) |
7477 | { | |
e7c27a73 | 7478 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7479 | } |
e142c38c | 7480 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7481 | break; |
7482 | case DW_TAG_unspecified_parameters: | |
7483 | /* From varargs functions; gdb doesn't seem to have any | |
7484 | interest in this information, so just ignore it for now. | |
7485 | (FIXME?) */ | |
7486 | break; | |
7487 | case DW_TAG_class_type: | |
680b30c7 | 7488 | case DW_TAG_interface_type: |
c906108c SS |
7489 | case DW_TAG_structure_type: |
7490 | case DW_TAG_union_type: | |
72019c9c | 7491 | case DW_TAG_set_type: |
c906108c SS |
7492 | case DW_TAG_enumeration_type: |
7493 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 7494 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 7495 | |
63d06c5c DC |
7496 | /* Make sure that the symbol includes appropriate enclosing |
7497 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 7498 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
7499 | the type. */ |
7500 | ||
987504bb JJ |
7501 | if (cu->language == language_cplus |
7502 | || cu->language == language_java) | |
c906108c | 7503 | { |
63d06c5c DC |
7504 | struct type *type = SYMBOL_TYPE (sym); |
7505 | ||
7506 | if (TYPE_TAG_NAME (type) != NULL) | |
7507 | { | |
7508 | /* FIXME: carlton/2003-11-10: Should this use | |
7509 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
7510 | arises further down in this function.) */ |
7511 | /* The type's name is already allocated along with | |
7512 | this objfile, so we don't need to duplicate it | |
7513 | for the symbol. */ | |
7514 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 7515 | } |
c906108c | 7516 | } |
63d06c5c DC |
7517 | |
7518 | { | |
987504bb | 7519 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
7520 | really ever be static objects: otherwise, if you try |
7521 | to, say, break of a class's method and you're in a file | |
7522 | which doesn't mention that class, it won't work unless | |
7523 | the check for all static symbols in lookup_symbol_aux | |
7524 | saves you. See the OtherFileClass tests in | |
7525 | gdb.c++/namespace.exp. */ | |
7526 | ||
7527 | struct pending **list_to_add; | |
7528 | ||
e142c38c | 7529 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7530 | && (cu->language == language_cplus |
7531 | || cu->language == language_java) | |
e142c38c | 7532 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7533 | |
7534 | add_symbol_to_list (sym, list_to_add); | |
7535 | ||
7536 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb | 7537 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 7538 | defines a typedef for the class. */ |
987504bb | 7539 | if (cu->language == language_cplus |
8c6860bb JB |
7540 | || cu->language == language_java |
7541 | || cu->language == language_ada) | |
63d06c5c | 7542 | { |
d8151005 DJ |
7543 | /* The symbol's name is already allocated along with |
7544 | this objfile, so we don't need to duplicate it for | |
7545 | the type. */ | |
63d06c5c | 7546 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7547 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7548 | } |
7549 | } | |
c906108c SS |
7550 | break; |
7551 | case DW_TAG_typedef: | |
63d06c5c DC |
7552 | if (processing_has_namespace_info |
7553 | && processing_current_prefix[0] != '\0') | |
7554 | { | |
987504bb JJ |
7555 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7556 | processing_current_prefix, | |
7557 | name, cu); | |
63d06c5c DC |
7558 | } |
7559 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7560 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7561 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7562 | break; |
c906108c | 7563 | case DW_TAG_base_type: |
a02abb62 | 7564 | case DW_TAG_subrange_type: |
c906108c | 7565 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7566 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7567 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7568 | break; |
7569 | case DW_TAG_enumerator: | |
63d06c5c DC |
7570 | if (processing_has_namespace_info |
7571 | && processing_current_prefix[0] != '\0') | |
7572 | { | |
987504bb JJ |
7573 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7574 | processing_current_prefix, | |
7575 | name, cu); | |
63d06c5c | 7576 | } |
e142c38c | 7577 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7578 | if (attr) |
7579 | { | |
e7c27a73 | 7580 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7581 | } |
63d06c5c DC |
7582 | { |
7583 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7584 | DW_TAG_class_type, etc. block. */ | |
7585 | ||
7586 | struct pending **list_to_add; | |
7587 | ||
e142c38c | 7588 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7589 | && (cu->language == language_cplus |
7590 | || cu->language == language_java) | |
e142c38c | 7591 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7592 | |
7593 | add_symbol_to_list (sym, list_to_add); | |
7594 | } | |
c906108c | 7595 | break; |
5c4e30ca DC |
7596 | case DW_TAG_namespace: |
7597 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7598 | add_symbol_to_list (sym, &global_symbols); | |
7599 | break; | |
c906108c SS |
7600 | default: |
7601 | /* Not a tag we recognize. Hopefully we aren't processing | |
7602 | trash data, but since we must specifically ignore things | |
7603 | we don't recognize, there is nothing else we should do at | |
7604 | this point. */ | |
e2e0b3e5 | 7605 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7606 | dwarf_tag_name (die->tag)); |
c906108c SS |
7607 | break; |
7608 | } | |
7609 | } | |
7610 | return (sym); | |
7611 | } | |
7612 | ||
7613 | /* Copy constant value from an attribute to a symbol. */ | |
7614 | ||
7615 | static void | |
107d2387 | 7616 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7617 | struct dwarf2_cu *cu) |
c906108c | 7618 | { |
e7c27a73 DJ |
7619 | struct objfile *objfile = cu->objfile; |
7620 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7621 | struct dwarf_block *blk; |
7622 | ||
7623 | switch (attr->form) | |
7624 | { | |
7625 | case DW_FORM_addr: | |
107d2387 | 7626 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 7627 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7628 | cu_header->addr_size, |
7629 | TYPE_LENGTH (SYMBOL_TYPE | |
7630 | (sym))); | |
4e38b386 | 7631 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7632 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7633 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7634 | it's body - store_unsigned_integer. */ | |
7635 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7636 | DW_ADDR (attr)); | |
c906108c SS |
7637 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7638 | break; | |
93b5768b PA |
7639 | case DW_FORM_strp: |
7640 | /* DW_STRING is already allocated on the obstack, point directly | |
7641 | to it. */ | |
7642 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
7643 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7644 | break; | |
c906108c SS |
7645 | case DW_FORM_block1: |
7646 | case DW_FORM_block2: | |
7647 | case DW_FORM_block4: | |
7648 | case DW_FORM_block: | |
7649 | blk = DW_BLOCK (attr); | |
7650 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 7651 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7652 | blk->size, |
7653 | TYPE_LENGTH (SYMBOL_TYPE | |
7654 | (sym))); | |
4e38b386 | 7655 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7656 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7657 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7658 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7659 | break; | |
2df3850c JM |
7660 | |
7661 | /* The DW_AT_const_value attributes are supposed to carry the | |
7662 | symbol's value "represented as it would be on the target | |
7663 | architecture." By the time we get here, it's already been | |
7664 | converted to host endianness, so we just need to sign- or | |
7665 | zero-extend it as appropriate. */ | |
7666 | case DW_FORM_data1: | |
7667 | dwarf2_const_value_data (attr, sym, 8); | |
7668 | break; | |
c906108c | 7669 | case DW_FORM_data2: |
2df3850c JM |
7670 | dwarf2_const_value_data (attr, sym, 16); |
7671 | break; | |
c906108c | 7672 | case DW_FORM_data4: |
2df3850c JM |
7673 | dwarf2_const_value_data (attr, sym, 32); |
7674 | break; | |
c906108c | 7675 | case DW_FORM_data8: |
2df3850c JM |
7676 | dwarf2_const_value_data (attr, sym, 64); |
7677 | break; | |
7678 | ||
c906108c | 7679 | case DW_FORM_sdata: |
2df3850c JM |
7680 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7681 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7682 | break; | |
7683 | ||
c906108c SS |
7684 | case DW_FORM_udata: |
7685 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
7686 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7687 | break; | |
2df3850c | 7688 | |
c906108c | 7689 | default: |
4d3c2250 | 7690 | complaint (&symfile_complaints, |
e2e0b3e5 | 7691 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 7692 | dwarf_form_name (attr->form)); |
c906108c SS |
7693 | SYMBOL_VALUE (sym) = 0; |
7694 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7695 | break; | |
7696 | } | |
7697 | } | |
7698 | ||
2df3850c JM |
7699 | |
7700 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
7701 | or zero-extend it as appropriate for the symbol's type. */ | |
7702 | static void | |
7703 | dwarf2_const_value_data (struct attribute *attr, | |
7704 | struct symbol *sym, | |
7705 | int bits) | |
7706 | { | |
7707 | LONGEST l = DW_UNSND (attr); | |
7708 | ||
7709 | if (bits < sizeof (l) * 8) | |
7710 | { | |
7711 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
7712 | l &= ((LONGEST) 1 << bits) - 1; | |
7713 | else | |
bf9198f1 | 7714 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
7715 | } |
7716 | ||
7717 | SYMBOL_VALUE (sym) = l; | |
7718 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7719 | } | |
7720 | ||
7721 | ||
c906108c SS |
7722 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
7723 | ||
7724 | static struct type * | |
e7c27a73 | 7725 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7726 | { |
5e2b427d | 7727 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
c906108c SS |
7728 | struct type *type; |
7729 | struct attribute *type_attr; | |
7730 | struct die_info *type_die; | |
c906108c | 7731 | |
e142c38c | 7732 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
7733 | if (!type_attr) |
7734 | { | |
7735 | /* A missing DW_AT_type represents a void type. */ | |
5e2b427d | 7736 | return builtin_type (gdbarch)->builtin_void; |
c906108c SS |
7737 | } |
7738 | else | |
f2f0e013 | 7739 | type_die = follow_die_ref (die, type_attr, &cu); |
10b3939b | 7740 | |
e7c27a73 | 7741 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7742 | if (!type) |
7743 | { | |
7744 | dump_die (type_die); | |
8a3fe4f8 | 7745 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 7746 | cu->objfile->name); |
c906108c SS |
7747 | } |
7748 | return type; | |
7749 | } | |
7750 | ||
7751 | /* Return the containing type of the die in question using its | |
7752 | DW_AT_containing_type attribute. */ | |
7753 | ||
7754 | static struct type * | |
e7c27a73 | 7755 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7756 | { |
7757 | struct type *type = NULL; | |
7758 | struct attribute *type_attr; | |
7759 | struct die_info *type_die = NULL; | |
c906108c | 7760 | |
e142c38c | 7761 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
7762 | if (type_attr) |
7763 | { | |
f2f0e013 | 7764 | type_die = follow_die_ref (die, type_attr, &cu); |
e7c27a73 | 7765 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7766 | } |
7767 | if (!type) | |
7768 | { | |
7769 | if (type_die) | |
7770 | dump_die (type_die); | |
8a3fe4f8 | 7771 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 7772 | cu->objfile->name); |
c906108c SS |
7773 | } |
7774 | return type; | |
7775 | } | |
7776 | ||
c906108c | 7777 | static struct type * |
e7c27a73 | 7778 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7779 | { |
f792889a DJ |
7780 | struct type *this_type; |
7781 | ||
7782 | this_type = read_type_die (die, cu); | |
7783 | if (!this_type) | |
c906108c | 7784 | { |
f792889a DJ |
7785 | dump_die (die); |
7786 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), | |
7787 | cu->objfile->name); | |
c906108c | 7788 | } |
f792889a | 7789 | return this_type; |
c906108c SS |
7790 | } |
7791 | ||
f792889a | 7792 | static struct type * |
e7c27a73 | 7793 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7794 | { |
f792889a DJ |
7795 | char *prefix; |
7796 | const char *old_prefix; | |
7797 | struct cleanup *back_to; | |
7798 | struct type *this_type; | |
7799 | ||
7800 | this_type = get_die_type (die, cu); | |
7801 | if (this_type) | |
7802 | return this_type; | |
7803 | ||
7804 | prefix = determine_prefix (die, cu); | |
7805 | old_prefix = processing_current_prefix; | |
7806 | back_to = make_cleanup (xfree, prefix); | |
63d06c5c | 7807 | processing_current_prefix = prefix; |
f792889a | 7808 | |
c906108c SS |
7809 | switch (die->tag) |
7810 | { | |
7811 | case DW_TAG_class_type: | |
680b30c7 | 7812 | case DW_TAG_interface_type: |
c906108c SS |
7813 | case DW_TAG_structure_type: |
7814 | case DW_TAG_union_type: | |
f792889a | 7815 | this_type = read_structure_type (die, cu); |
c906108c SS |
7816 | break; |
7817 | case DW_TAG_enumeration_type: | |
f792889a | 7818 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
7819 | break; |
7820 | case DW_TAG_subprogram: | |
7821 | case DW_TAG_subroutine_type: | |
f792889a | 7822 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
7823 | break; |
7824 | case DW_TAG_array_type: | |
f792889a | 7825 | this_type = read_array_type (die, cu); |
c906108c | 7826 | break; |
72019c9c | 7827 | case DW_TAG_set_type: |
f792889a | 7828 | this_type = read_set_type (die, cu); |
72019c9c | 7829 | break; |
c906108c | 7830 | case DW_TAG_pointer_type: |
f792889a | 7831 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
7832 | break; |
7833 | case DW_TAG_ptr_to_member_type: | |
f792889a | 7834 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
7835 | break; |
7836 | case DW_TAG_reference_type: | |
f792889a | 7837 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
7838 | break; |
7839 | case DW_TAG_const_type: | |
f792889a | 7840 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
7841 | break; |
7842 | case DW_TAG_volatile_type: | |
f792889a | 7843 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
7844 | break; |
7845 | case DW_TAG_string_type: | |
f792889a | 7846 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
7847 | break; |
7848 | case DW_TAG_typedef: | |
f792889a | 7849 | this_type = read_typedef (die, cu); |
c906108c | 7850 | break; |
a02abb62 | 7851 | case DW_TAG_subrange_type: |
f792889a | 7852 | this_type = read_subrange_type (die, cu); |
a02abb62 | 7853 | break; |
c906108c | 7854 | case DW_TAG_base_type: |
f792889a | 7855 | this_type = read_base_type (die, cu); |
c906108c | 7856 | break; |
81a17f79 | 7857 | case DW_TAG_unspecified_type: |
f792889a | 7858 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 7859 | break; |
c906108c | 7860 | default: |
a1f5b845 | 7861 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 7862 | dwarf_tag_name (die->tag)); |
c906108c SS |
7863 | break; |
7864 | } | |
63d06c5c DC |
7865 | |
7866 | processing_current_prefix = old_prefix; | |
7867 | do_cleanups (back_to); | |
f792889a | 7868 | return this_type; |
63d06c5c DC |
7869 | } |
7870 | ||
fdde2d81 DC |
7871 | /* Return the name of the namespace/class that DIE is defined within, |
7872 | or "" if we can't tell. The caller should xfree the result. */ | |
7873 | ||
7874 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
7875 | therein) for an example of how to use this function to deal with | |
7876 | DW_AT_specification. */ | |
7877 | ||
7878 | static char * | |
e142c38c | 7879 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
7880 | { |
7881 | struct die_info *parent; | |
7882 | ||
987504bb JJ |
7883 | if (cu->language != language_cplus |
7884 | && cu->language != language_java) | |
63d06c5c DC |
7885 | return NULL; |
7886 | ||
7887 | parent = die->parent; | |
7888 | ||
7889 | if (parent == NULL) | |
7890 | { | |
8176b9b8 | 7891 | return xstrdup (""); |
63d06c5c DC |
7892 | } |
7893 | else | |
7894 | { | |
63d06c5c DC |
7895 | switch (parent->tag) { |
7896 | case DW_TAG_namespace: | |
7897 | { | |
8176b9b8 DC |
7898 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
7899 | before doing this check? */ | |
f792889a DJ |
7900 | struct type *parent_type = get_die_type (parent, cu); |
7901 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
8176b9b8 | 7902 | { |
f792889a | 7903 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
8176b9b8 DC |
7904 | } |
7905 | else | |
7906 | { | |
7907 | int dummy; | |
7908 | char *parent_prefix = determine_prefix (parent, cu); | |
987504bb | 7909 | char *retval = typename_concat (NULL, parent_prefix, |
8176b9b8 | 7910 | namespace_name (parent, &dummy, |
987504bb JJ |
7911 | cu), |
7912 | cu); | |
8176b9b8 DC |
7913 | xfree (parent_prefix); |
7914 | return retval; | |
7915 | } | |
63d06c5c DC |
7916 | } |
7917 | break; | |
7918 | case DW_TAG_class_type: | |
680b30c7 | 7919 | case DW_TAG_interface_type: |
63d06c5c DC |
7920 | case DW_TAG_structure_type: |
7921 | { | |
f792889a DJ |
7922 | struct type *parent_type = get_die_type (parent, cu); |
7923 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
63d06c5c | 7924 | { |
f792889a | 7925 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
63d06c5c DC |
7926 | } |
7927 | else | |
8176b9b8 DC |
7928 | { |
7929 | const char *old_prefix = processing_current_prefix; | |
7930 | char *new_prefix = determine_prefix (parent, cu); | |
7931 | char *retval; | |
7932 | ||
7933 | processing_current_prefix = new_prefix; | |
7934 | retval = determine_class_name (parent, cu); | |
7935 | processing_current_prefix = old_prefix; | |
7936 | ||
7937 | xfree (new_prefix); | |
7938 | return retval; | |
7939 | } | |
63d06c5c | 7940 | } |
63d06c5c | 7941 | default: |
8176b9b8 | 7942 | return determine_prefix (parent, cu); |
63d06c5c | 7943 | } |
63d06c5c DC |
7944 | } |
7945 | } | |
7946 | ||
987504bb JJ |
7947 | /* Return a newly-allocated string formed by concatenating PREFIX and |
7948 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
7949 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
7950 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
7951 | is used to determine the language and hence, the appropriate separator. */ | |
7952 | ||
7953 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
7954 | |
7955 | static char * | |
987504bb JJ |
7956 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
7957 | struct dwarf2_cu *cu) | |
63d06c5c | 7958 | { |
987504bb | 7959 | char *sep; |
63d06c5c | 7960 | |
987504bb JJ |
7961 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
7962 | sep = ""; | |
7963 | else if (cu->language == language_java) | |
7964 | sep = "."; | |
7965 | else | |
7966 | sep = "::"; | |
63d06c5c | 7967 | |
987504bb JJ |
7968 | if (obs == NULL) |
7969 | { | |
7970 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
7971 | retval[0] = '\0'; | |
7972 | ||
7973 | if (prefix) | |
7974 | { | |
7975 | strcpy (retval, prefix); | |
7976 | strcat (retval, sep); | |
7977 | } | |
7978 | if (suffix) | |
7979 | strcat (retval, suffix); | |
7980 | ||
63d06c5c DC |
7981 | return retval; |
7982 | } | |
987504bb JJ |
7983 | else |
7984 | { | |
7985 | /* We have an obstack. */ | |
7986 | return obconcat (obs, prefix, sep, suffix); | |
7987 | } | |
63d06c5c DC |
7988 | } |
7989 | ||
c906108c SS |
7990 | /* Return sibling of die, NULL if no sibling. */ |
7991 | ||
f9aca02d | 7992 | static struct die_info * |
fba45db2 | 7993 | sibling_die (struct die_info *die) |
c906108c | 7994 | { |
639d11d3 | 7995 | return die->sibling; |
c906108c SS |
7996 | } |
7997 | ||
7998 | /* Get linkage name of a die, return NULL if not found. */ | |
7999 | ||
8000 | static char * | |
e142c38c | 8001 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8002 | { |
8003 | struct attribute *attr; | |
8004 | ||
e142c38c | 8005 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
8006 | if (attr && DW_STRING (attr)) |
8007 | return DW_STRING (attr); | |
e142c38c | 8008 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
8009 | if (attr && DW_STRING (attr)) |
8010 | return DW_STRING (attr); | |
8011 | return NULL; | |
8012 | } | |
8013 | ||
9219021c DC |
8014 | /* Get name of a die, return NULL if not found. */ |
8015 | ||
8016 | static char * | |
e142c38c | 8017 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8018 | { |
8019 | struct attribute *attr; | |
8020 | ||
e142c38c | 8021 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
8022 | if (attr && DW_STRING (attr)) |
8023 | return DW_STRING (attr); | |
8024 | return NULL; | |
8025 | } | |
8026 | ||
8027 | /* Return the die that this die in an extension of, or NULL if there | |
f2f0e013 DJ |
8028 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
8029 | containing the return value on output. */ | |
9219021c DC |
8030 | |
8031 | static struct die_info * | |
f2f0e013 | 8032 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
9219021c DC |
8033 | { |
8034 | struct attribute *attr; | |
9219021c | 8035 | |
f2f0e013 | 8036 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
9219021c DC |
8037 | if (attr == NULL) |
8038 | return NULL; | |
8039 | ||
f2f0e013 | 8040 | return follow_die_ref (die, attr, ext_cu); |
9219021c DC |
8041 | } |
8042 | ||
c906108c SS |
8043 | /* Convert a DIE tag into its string name. */ |
8044 | ||
8045 | static char * | |
aa1ee363 | 8046 | dwarf_tag_name (unsigned tag) |
c906108c SS |
8047 | { |
8048 | switch (tag) | |
8049 | { | |
8050 | case DW_TAG_padding: | |
8051 | return "DW_TAG_padding"; | |
8052 | case DW_TAG_array_type: | |
8053 | return "DW_TAG_array_type"; | |
8054 | case DW_TAG_class_type: | |
8055 | return "DW_TAG_class_type"; | |
8056 | case DW_TAG_entry_point: | |
8057 | return "DW_TAG_entry_point"; | |
8058 | case DW_TAG_enumeration_type: | |
8059 | return "DW_TAG_enumeration_type"; | |
8060 | case DW_TAG_formal_parameter: | |
8061 | return "DW_TAG_formal_parameter"; | |
8062 | case DW_TAG_imported_declaration: | |
8063 | return "DW_TAG_imported_declaration"; | |
8064 | case DW_TAG_label: | |
8065 | return "DW_TAG_label"; | |
8066 | case DW_TAG_lexical_block: | |
8067 | return "DW_TAG_lexical_block"; | |
8068 | case DW_TAG_member: | |
8069 | return "DW_TAG_member"; | |
8070 | case DW_TAG_pointer_type: | |
8071 | return "DW_TAG_pointer_type"; | |
8072 | case DW_TAG_reference_type: | |
8073 | return "DW_TAG_reference_type"; | |
8074 | case DW_TAG_compile_unit: | |
8075 | return "DW_TAG_compile_unit"; | |
8076 | case DW_TAG_string_type: | |
8077 | return "DW_TAG_string_type"; | |
8078 | case DW_TAG_structure_type: | |
8079 | return "DW_TAG_structure_type"; | |
8080 | case DW_TAG_subroutine_type: | |
8081 | return "DW_TAG_subroutine_type"; | |
8082 | case DW_TAG_typedef: | |
8083 | return "DW_TAG_typedef"; | |
8084 | case DW_TAG_union_type: | |
8085 | return "DW_TAG_union_type"; | |
8086 | case DW_TAG_unspecified_parameters: | |
8087 | return "DW_TAG_unspecified_parameters"; | |
8088 | case DW_TAG_variant: | |
8089 | return "DW_TAG_variant"; | |
8090 | case DW_TAG_common_block: | |
8091 | return "DW_TAG_common_block"; | |
8092 | case DW_TAG_common_inclusion: | |
8093 | return "DW_TAG_common_inclusion"; | |
8094 | case DW_TAG_inheritance: | |
8095 | return "DW_TAG_inheritance"; | |
8096 | case DW_TAG_inlined_subroutine: | |
8097 | return "DW_TAG_inlined_subroutine"; | |
8098 | case DW_TAG_module: | |
8099 | return "DW_TAG_module"; | |
8100 | case DW_TAG_ptr_to_member_type: | |
8101 | return "DW_TAG_ptr_to_member_type"; | |
8102 | case DW_TAG_set_type: | |
8103 | return "DW_TAG_set_type"; | |
8104 | case DW_TAG_subrange_type: | |
8105 | return "DW_TAG_subrange_type"; | |
8106 | case DW_TAG_with_stmt: | |
8107 | return "DW_TAG_with_stmt"; | |
8108 | case DW_TAG_access_declaration: | |
8109 | return "DW_TAG_access_declaration"; | |
8110 | case DW_TAG_base_type: | |
8111 | return "DW_TAG_base_type"; | |
8112 | case DW_TAG_catch_block: | |
8113 | return "DW_TAG_catch_block"; | |
8114 | case DW_TAG_const_type: | |
8115 | return "DW_TAG_const_type"; | |
8116 | case DW_TAG_constant: | |
8117 | return "DW_TAG_constant"; | |
8118 | case DW_TAG_enumerator: | |
8119 | return "DW_TAG_enumerator"; | |
8120 | case DW_TAG_file_type: | |
8121 | return "DW_TAG_file_type"; | |
8122 | case DW_TAG_friend: | |
8123 | return "DW_TAG_friend"; | |
8124 | case DW_TAG_namelist: | |
8125 | return "DW_TAG_namelist"; | |
8126 | case DW_TAG_namelist_item: | |
8127 | return "DW_TAG_namelist_item"; | |
8128 | case DW_TAG_packed_type: | |
8129 | return "DW_TAG_packed_type"; | |
8130 | case DW_TAG_subprogram: | |
8131 | return "DW_TAG_subprogram"; | |
8132 | case DW_TAG_template_type_param: | |
8133 | return "DW_TAG_template_type_param"; | |
8134 | case DW_TAG_template_value_param: | |
8135 | return "DW_TAG_template_value_param"; | |
8136 | case DW_TAG_thrown_type: | |
8137 | return "DW_TAG_thrown_type"; | |
8138 | case DW_TAG_try_block: | |
8139 | return "DW_TAG_try_block"; | |
8140 | case DW_TAG_variant_part: | |
8141 | return "DW_TAG_variant_part"; | |
8142 | case DW_TAG_variable: | |
8143 | return "DW_TAG_variable"; | |
8144 | case DW_TAG_volatile_type: | |
8145 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
8146 | case DW_TAG_dwarf_procedure: |
8147 | return "DW_TAG_dwarf_procedure"; | |
8148 | case DW_TAG_restrict_type: | |
8149 | return "DW_TAG_restrict_type"; | |
8150 | case DW_TAG_interface_type: | |
8151 | return "DW_TAG_interface_type"; | |
8152 | case DW_TAG_namespace: | |
8153 | return "DW_TAG_namespace"; | |
8154 | case DW_TAG_imported_module: | |
8155 | return "DW_TAG_imported_module"; | |
8156 | case DW_TAG_unspecified_type: | |
8157 | return "DW_TAG_unspecified_type"; | |
8158 | case DW_TAG_partial_unit: | |
8159 | return "DW_TAG_partial_unit"; | |
8160 | case DW_TAG_imported_unit: | |
8161 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
8162 | case DW_TAG_condition: |
8163 | return "DW_TAG_condition"; | |
8164 | case DW_TAG_shared_type: | |
8165 | return "DW_TAG_shared_type"; | |
c906108c SS |
8166 | case DW_TAG_MIPS_loop: |
8167 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
8168 | case DW_TAG_HP_array_descriptor: |
8169 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
8170 | case DW_TAG_format_label: |
8171 | return "DW_TAG_format_label"; | |
8172 | case DW_TAG_function_template: | |
8173 | return "DW_TAG_function_template"; | |
8174 | case DW_TAG_class_template: | |
8175 | return "DW_TAG_class_template"; | |
b7619582 GF |
8176 | case DW_TAG_GNU_BINCL: |
8177 | return "DW_TAG_GNU_BINCL"; | |
8178 | case DW_TAG_GNU_EINCL: | |
8179 | return "DW_TAG_GNU_EINCL"; | |
8180 | case DW_TAG_upc_shared_type: | |
8181 | return "DW_TAG_upc_shared_type"; | |
8182 | case DW_TAG_upc_strict_type: | |
8183 | return "DW_TAG_upc_strict_type"; | |
8184 | case DW_TAG_upc_relaxed_type: | |
8185 | return "DW_TAG_upc_relaxed_type"; | |
8186 | case DW_TAG_PGI_kanji_type: | |
8187 | return "DW_TAG_PGI_kanji_type"; | |
8188 | case DW_TAG_PGI_interface_block: | |
8189 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
8190 | default: |
8191 | return "DW_TAG_<unknown>"; | |
8192 | } | |
8193 | } | |
8194 | ||
8195 | /* Convert a DWARF attribute code into its string name. */ | |
8196 | ||
8197 | static char * | |
aa1ee363 | 8198 | dwarf_attr_name (unsigned attr) |
c906108c SS |
8199 | { |
8200 | switch (attr) | |
8201 | { | |
8202 | case DW_AT_sibling: | |
8203 | return "DW_AT_sibling"; | |
8204 | case DW_AT_location: | |
8205 | return "DW_AT_location"; | |
8206 | case DW_AT_name: | |
8207 | return "DW_AT_name"; | |
8208 | case DW_AT_ordering: | |
8209 | return "DW_AT_ordering"; | |
8210 | case DW_AT_subscr_data: | |
8211 | return "DW_AT_subscr_data"; | |
8212 | case DW_AT_byte_size: | |
8213 | return "DW_AT_byte_size"; | |
8214 | case DW_AT_bit_offset: | |
8215 | return "DW_AT_bit_offset"; | |
8216 | case DW_AT_bit_size: | |
8217 | return "DW_AT_bit_size"; | |
8218 | case DW_AT_element_list: | |
8219 | return "DW_AT_element_list"; | |
8220 | case DW_AT_stmt_list: | |
8221 | return "DW_AT_stmt_list"; | |
8222 | case DW_AT_low_pc: | |
8223 | return "DW_AT_low_pc"; | |
8224 | case DW_AT_high_pc: | |
8225 | return "DW_AT_high_pc"; | |
8226 | case DW_AT_language: | |
8227 | return "DW_AT_language"; | |
8228 | case DW_AT_member: | |
8229 | return "DW_AT_member"; | |
8230 | case DW_AT_discr: | |
8231 | return "DW_AT_discr"; | |
8232 | case DW_AT_discr_value: | |
8233 | return "DW_AT_discr_value"; | |
8234 | case DW_AT_visibility: | |
8235 | return "DW_AT_visibility"; | |
8236 | case DW_AT_import: | |
8237 | return "DW_AT_import"; | |
8238 | case DW_AT_string_length: | |
8239 | return "DW_AT_string_length"; | |
8240 | case DW_AT_common_reference: | |
8241 | return "DW_AT_common_reference"; | |
8242 | case DW_AT_comp_dir: | |
8243 | return "DW_AT_comp_dir"; | |
8244 | case DW_AT_const_value: | |
8245 | return "DW_AT_const_value"; | |
8246 | case DW_AT_containing_type: | |
8247 | return "DW_AT_containing_type"; | |
8248 | case DW_AT_default_value: | |
8249 | return "DW_AT_default_value"; | |
8250 | case DW_AT_inline: | |
8251 | return "DW_AT_inline"; | |
8252 | case DW_AT_is_optional: | |
8253 | return "DW_AT_is_optional"; | |
8254 | case DW_AT_lower_bound: | |
8255 | return "DW_AT_lower_bound"; | |
8256 | case DW_AT_producer: | |
8257 | return "DW_AT_producer"; | |
8258 | case DW_AT_prototyped: | |
8259 | return "DW_AT_prototyped"; | |
8260 | case DW_AT_return_addr: | |
8261 | return "DW_AT_return_addr"; | |
8262 | case DW_AT_start_scope: | |
8263 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
8264 | case DW_AT_bit_stride: |
8265 | return "DW_AT_bit_stride"; | |
c906108c SS |
8266 | case DW_AT_upper_bound: |
8267 | return "DW_AT_upper_bound"; | |
8268 | case DW_AT_abstract_origin: | |
8269 | return "DW_AT_abstract_origin"; | |
8270 | case DW_AT_accessibility: | |
8271 | return "DW_AT_accessibility"; | |
8272 | case DW_AT_address_class: | |
8273 | return "DW_AT_address_class"; | |
8274 | case DW_AT_artificial: | |
8275 | return "DW_AT_artificial"; | |
8276 | case DW_AT_base_types: | |
8277 | return "DW_AT_base_types"; | |
8278 | case DW_AT_calling_convention: | |
8279 | return "DW_AT_calling_convention"; | |
8280 | case DW_AT_count: | |
8281 | return "DW_AT_count"; | |
8282 | case DW_AT_data_member_location: | |
8283 | return "DW_AT_data_member_location"; | |
8284 | case DW_AT_decl_column: | |
8285 | return "DW_AT_decl_column"; | |
8286 | case DW_AT_decl_file: | |
8287 | return "DW_AT_decl_file"; | |
8288 | case DW_AT_decl_line: | |
8289 | return "DW_AT_decl_line"; | |
8290 | case DW_AT_declaration: | |
8291 | return "DW_AT_declaration"; | |
8292 | case DW_AT_discr_list: | |
8293 | return "DW_AT_discr_list"; | |
8294 | case DW_AT_encoding: | |
8295 | return "DW_AT_encoding"; | |
8296 | case DW_AT_external: | |
8297 | return "DW_AT_external"; | |
8298 | case DW_AT_frame_base: | |
8299 | return "DW_AT_frame_base"; | |
8300 | case DW_AT_friend: | |
8301 | return "DW_AT_friend"; | |
8302 | case DW_AT_identifier_case: | |
8303 | return "DW_AT_identifier_case"; | |
8304 | case DW_AT_macro_info: | |
8305 | return "DW_AT_macro_info"; | |
8306 | case DW_AT_namelist_items: | |
8307 | return "DW_AT_namelist_items"; | |
8308 | case DW_AT_priority: | |
8309 | return "DW_AT_priority"; | |
8310 | case DW_AT_segment: | |
8311 | return "DW_AT_segment"; | |
8312 | case DW_AT_specification: | |
8313 | return "DW_AT_specification"; | |
8314 | case DW_AT_static_link: | |
8315 | return "DW_AT_static_link"; | |
8316 | case DW_AT_type: | |
8317 | return "DW_AT_type"; | |
8318 | case DW_AT_use_location: | |
8319 | return "DW_AT_use_location"; | |
8320 | case DW_AT_variable_parameter: | |
8321 | return "DW_AT_variable_parameter"; | |
8322 | case DW_AT_virtuality: | |
8323 | return "DW_AT_virtuality"; | |
8324 | case DW_AT_vtable_elem_location: | |
8325 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8326 | /* DWARF 3 values. */ |
d9fa45fe DC |
8327 | case DW_AT_allocated: |
8328 | return "DW_AT_allocated"; | |
8329 | case DW_AT_associated: | |
8330 | return "DW_AT_associated"; | |
8331 | case DW_AT_data_location: | |
8332 | return "DW_AT_data_location"; | |
09fa0d7c JK |
8333 | case DW_AT_byte_stride: |
8334 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
8335 | case DW_AT_entry_pc: |
8336 | return "DW_AT_entry_pc"; | |
8337 | case DW_AT_use_UTF8: | |
8338 | return "DW_AT_use_UTF8"; | |
8339 | case DW_AT_extension: | |
8340 | return "DW_AT_extension"; | |
8341 | case DW_AT_ranges: | |
8342 | return "DW_AT_ranges"; | |
8343 | case DW_AT_trampoline: | |
8344 | return "DW_AT_trampoline"; | |
8345 | case DW_AT_call_column: | |
8346 | return "DW_AT_call_column"; | |
8347 | case DW_AT_call_file: | |
8348 | return "DW_AT_call_file"; | |
8349 | case DW_AT_call_line: | |
8350 | return "DW_AT_call_line"; | |
b7619582 GF |
8351 | case DW_AT_description: |
8352 | return "DW_AT_description"; | |
8353 | case DW_AT_binary_scale: | |
8354 | return "DW_AT_binary_scale"; | |
8355 | case DW_AT_decimal_scale: | |
8356 | return "DW_AT_decimal_scale"; | |
8357 | case DW_AT_small: | |
8358 | return "DW_AT_small"; | |
8359 | case DW_AT_decimal_sign: | |
8360 | return "DW_AT_decimal_sign"; | |
8361 | case DW_AT_digit_count: | |
8362 | return "DW_AT_digit_count"; | |
8363 | case DW_AT_picture_string: | |
8364 | return "DW_AT_picture_string"; | |
8365 | case DW_AT_mutable: | |
8366 | return "DW_AT_mutable"; | |
8367 | case DW_AT_threads_scaled: | |
8368 | return "DW_AT_threads_scaled"; | |
8369 | case DW_AT_explicit: | |
8370 | return "DW_AT_explicit"; | |
8371 | case DW_AT_object_pointer: | |
8372 | return "DW_AT_object_pointer"; | |
8373 | case DW_AT_endianity: | |
8374 | return "DW_AT_endianity"; | |
8375 | case DW_AT_elemental: | |
8376 | return "DW_AT_elemental"; | |
8377 | case DW_AT_pure: | |
8378 | return "DW_AT_pure"; | |
8379 | case DW_AT_recursive: | |
8380 | return "DW_AT_recursive"; | |
c906108c | 8381 | #ifdef MIPS |
b7619582 | 8382 | /* SGI/MIPS extensions. */ |
c906108c SS |
8383 | case DW_AT_MIPS_fde: |
8384 | return "DW_AT_MIPS_fde"; | |
8385 | case DW_AT_MIPS_loop_begin: | |
8386 | return "DW_AT_MIPS_loop_begin"; | |
8387 | case DW_AT_MIPS_tail_loop_begin: | |
8388 | return "DW_AT_MIPS_tail_loop_begin"; | |
8389 | case DW_AT_MIPS_epilog_begin: | |
8390 | return "DW_AT_MIPS_epilog_begin"; | |
8391 | case DW_AT_MIPS_loop_unroll_factor: | |
8392 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8393 | case DW_AT_MIPS_software_pipeline_depth: | |
8394 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8395 | case DW_AT_MIPS_linkage_name: | |
8396 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8397 | case DW_AT_MIPS_stride: |
8398 | return "DW_AT_MIPS_stride"; | |
8399 | case DW_AT_MIPS_abstract_name: | |
8400 | return "DW_AT_MIPS_abstract_name"; | |
8401 | case DW_AT_MIPS_clone_origin: | |
8402 | return "DW_AT_MIPS_clone_origin"; | |
8403 | case DW_AT_MIPS_has_inlines: | |
8404 | return "DW_AT_MIPS_has_inlines"; | |
8405 | #endif | |
8406 | /* HP extensions. */ | |
8407 | case DW_AT_HP_block_index: | |
8408 | return "DW_AT_HP_block_index"; | |
8409 | case DW_AT_HP_unmodifiable: | |
8410 | return "DW_AT_HP_unmodifiable"; | |
8411 | case DW_AT_HP_actuals_stmt_list: | |
8412 | return "DW_AT_HP_actuals_stmt_list"; | |
8413 | case DW_AT_HP_proc_per_section: | |
8414 | return "DW_AT_HP_proc_per_section"; | |
8415 | case DW_AT_HP_raw_data_ptr: | |
8416 | return "DW_AT_HP_raw_data_ptr"; | |
8417 | case DW_AT_HP_pass_by_reference: | |
8418 | return "DW_AT_HP_pass_by_reference"; | |
8419 | case DW_AT_HP_opt_level: | |
8420 | return "DW_AT_HP_opt_level"; | |
8421 | case DW_AT_HP_prof_version_id: | |
8422 | return "DW_AT_HP_prof_version_id"; | |
8423 | case DW_AT_HP_opt_flags: | |
8424 | return "DW_AT_HP_opt_flags"; | |
8425 | case DW_AT_HP_cold_region_low_pc: | |
8426 | return "DW_AT_HP_cold_region_low_pc"; | |
8427 | case DW_AT_HP_cold_region_high_pc: | |
8428 | return "DW_AT_HP_cold_region_high_pc"; | |
8429 | case DW_AT_HP_all_variables_modifiable: | |
8430 | return "DW_AT_HP_all_variables_modifiable"; | |
8431 | case DW_AT_HP_linkage_name: | |
8432 | return "DW_AT_HP_linkage_name"; | |
8433 | case DW_AT_HP_prof_flags: | |
8434 | return "DW_AT_HP_prof_flags"; | |
8435 | /* GNU extensions. */ | |
c906108c SS |
8436 | case DW_AT_sf_names: |
8437 | return "DW_AT_sf_names"; | |
8438 | case DW_AT_src_info: | |
8439 | return "DW_AT_src_info"; | |
8440 | case DW_AT_mac_info: | |
8441 | return "DW_AT_mac_info"; | |
8442 | case DW_AT_src_coords: | |
8443 | return "DW_AT_src_coords"; | |
8444 | case DW_AT_body_begin: | |
8445 | return "DW_AT_body_begin"; | |
8446 | case DW_AT_body_end: | |
8447 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8448 | case DW_AT_GNU_vector: |
8449 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8450 | /* VMS extensions. */ |
8451 | case DW_AT_VMS_rtnbeg_pd_address: | |
8452 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8453 | /* UPC extension. */ | |
8454 | case DW_AT_upc_threads_scaled: | |
8455 | return "DW_AT_upc_threads_scaled"; | |
8456 | /* PGI (STMicroelectronics) extensions. */ | |
8457 | case DW_AT_PGI_lbase: | |
8458 | return "DW_AT_PGI_lbase"; | |
8459 | case DW_AT_PGI_soffset: | |
8460 | return "DW_AT_PGI_soffset"; | |
8461 | case DW_AT_PGI_lstride: | |
8462 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8463 | default: |
8464 | return "DW_AT_<unknown>"; | |
8465 | } | |
8466 | } | |
8467 | ||
8468 | /* Convert a DWARF value form code into its string name. */ | |
8469 | ||
8470 | static char * | |
aa1ee363 | 8471 | dwarf_form_name (unsigned form) |
c906108c SS |
8472 | { |
8473 | switch (form) | |
8474 | { | |
8475 | case DW_FORM_addr: | |
8476 | return "DW_FORM_addr"; | |
8477 | case DW_FORM_block2: | |
8478 | return "DW_FORM_block2"; | |
8479 | case DW_FORM_block4: | |
8480 | return "DW_FORM_block4"; | |
8481 | case DW_FORM_data2: | |
8482 | return "DW_FORM_data2"; | |
8483 | case DW_FORM_data4: | |
8484 | return "DW_FORM_data4"; | |
8485 | case DW_FORM_data8: | |
8486 | return "DW_FORM_data8"; | |
8487 | case DW_FORM_string: | |
8488 | return "DW_FORM_string"; | |
8489 | case DW_FORM_block: | |
8490 | return "DW_FORM_block"; | |
8491 | case DW_FORM_block1: | |
8492 | return "DW_FORM_block1"; | |
8493 | case DW_FORM_data1: | |
8494 | return "DW_FORM_data1"; | |
8495 | case DW_FORM_flag: | |
8496 | return "DW_FORM_flag"; | |
8497 | case DW_FORM_sdata: | |
8498 | return "DW_FORM_sdata"; | |
8499 | case DW_FORM_strp: | |
8500 | return "DW_FORM_strp"; | |
8501 | case DW_FORM_udata: | |
8502 | return "DW_FORM_udata"; | |
8503 | case DW_FORM_ref_addr: | |
8504 | return "DW_FORM_ref_addr"; | |
8505 | case DW_FORM_ref1: | |
8506 | return "DW_FORM_ref1"; | |
8507 | case DW_FORM_ref2: | |
8508 | return "DW_FORM_ref2"; | |
8509 | case DW_FORM_ref4: | |
8510 | return "DW_FORM_ref4"; | |
8511 | case DW_FORM_ref8: | |
8512 | return "DW_FORM_ref8"; | |
8513 | case DW_FORM_ref_udata: | |
8514 | return "DW_FORM_ref_udata"; | |
8515 | case DW_FORM_indirect: | |
8516 | return "DW_FORM_indirect"; | |
8517 | default: | |
8518 | return "DW_FORM_<unknown>"; | |
8519 | } | |
8520 | } | |
8521 | ||
8522 | /* Convert a DWARF stack opcode into its string name. */ | |
8523 | ||
8524 | static char * | |
aa1ee363 | 8525 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8526 | { |
8527 | switch (op) | |
8528 | { | |
8529 | case DW_OP_addr: | |
8530 | return "DW_OP_addr"; | |
8531 | case DW_OP_deref: | |
8532 | return "DW_OP_deref"; | |
8533 | case DW_OP_const1u: | |
8534 | return "DW_OP_const1u"; | |
8535 | case DW_OP_const1s: | |
8536 | return "DW_OP_const1s"; | |
8537 | case DW_OP_const2u: | |
8538 | return "DW_OP_const2u"; | |
8539 | case DW_OP_const2s: | |
8540 | return "DW_OP_const2s"; | |
8541 | case DW_OP_const4u: | |
8542 | return "DW_OP_const4u"; | |
8543 | case DW_OP_const4s: | |
8544 | return "DW_OP_const4s"; | |
8545 | case DW_OP_const8u: | |
8546 | return "DW_OP_const8u"; | |
8547 | case DW_OP_const8s: | |
8548 | return "DW_OP_const8s"; | |
8549 | case DW_OP_constu: | |
8550 | return "DW_OP_constu"; | |
8551 | case DW_OP_consts: | |
8552 | return "DW_OP_consts"; | |
8553 | case DW_OP_dup: | |
8554 | return "DW_OP_dup"; | |
8555 | case DW_OP_drop: | |
8556 | return "DW_OP_drop"; | |
8557 | case DW_OP_over: | |
8558 | return "DW_OP_over"; | |
8559 | case DW_OP_pick: | |
8560 | return "DW_OP_pick"; | |
8561 | case DW_OP_swap: | |
8562 | return "DW_OP_swap"; | |
8563 | case DW_OP_rot: | |
8564 | return "DW_OP_rot"; | |
8565 | case DW_OP_xderef: | |
8566 | return "DW_OP_xderef"; | |
8567 | case DW_OP_abs: | |
8568 | return "DW_OP_abs"; | |
8569 | case DW_OP_and: | |
8570 | return "DW_OP_and"; | |
8571 | case DW_OP_div: | |
8572 | return "DW_OP_div"; | |
8573 | case DW_OP_minus: | |
8574 | return "DW_OP_minus"; | |
8575 | case DW_OP_mod: | |
8576 | return "DW_OP_mod"; | |
8577 | case DW_OP_mul: | |
8578 | return "DW_OP_mul"; | |
8579 | case DW_OP_neg: | |
8580 | return "DW_OP_neg"; | |
8581 | case DW_OP_not: | |
8582 | return "DW_OP_not"; | |
8583 | case DW_OP_or: | |
8584 | return "DW_OP_or"; | |
8585 | case DW_OP_plus: | |
8586 | return "DW_OP_plus"; | |
8587 | case DW_OP_plus_uconst: | |
8588 | return "DW_OP_plus_uconst"; | |
8589 | case DW_OP_shl: | |
8590 | return "DW_OP_shl"; | |
8591 | case DW_OP_shr: | |
8592 | return "DW_OP_shr"; | |
8593 | case DW_OP_shra: | |
8594 | return "DW_OP_shra"; | |
8595 | case DW_OP_xor: | |
8596 | return "DW_OP_xor"; | |
8597 | case DW_OP_bra: | |
8598 | return "DW_OP_bra"; | |
8599 | case DW_OP_eq: | |
8600 | return "DW_OP_eq"; | |
8601 | case DW_OP_ge: | |
8602 | return "DW_OP_ge"; | |
8603 | case DW_OP_gt: | |
8604 | return "DW_OP_gt"; | |
8605 | case DW_OP_le: | |
8606 | return "DW_OP_le"; | |
8607 | case DW_OP_lt: | |
8608 | return "DW_OP_lt"; | |
8609 | case DW_OP_ne: | |
8610 | return "DW_OP_ne"; | |
8611 | case DW_OP_skip: | |
8612 | return "DW_OP_skip"; | |
8613 | case DW_OP_lit0: | |
8614 | return "DW_OP_lit0"; | |
8615 | case DW_OP_lit1: | |
8616 | return "DW_OP_lit1"; | |
8617 | case DW_OP_lit2: | |
8618 | return "DW_OP_lit2"; | |
8619 | case DW_OP_lit3: | |
8620 | return "DW_OP_lit3"; | |
8621 | case DW_OP_lit4: | |
8622 | return "DW_OP_lit4"; | |
8623 | case DW_OP_lit5: | |
8624 | return "DW_OP_lit5"; | |
8625 | case DW_OP_lit6: | |
8626 | return "DW_OP_lit6"; | |
8627 | case DW_OP_lit7: | |
8628 | return "DW_OP_lit7"; | |
8629 | case DW_OP_lit8: | |
8630 | return "DW_OP_lit8"; | |
8631 | case DW_OP_lit9: | |
8632 | return "DW_OP_lit9"; | |
8633 | case DW_OP_lit10: | |
8634 | return "DW_OP_lit10"; | |
8635 | case DW_OP_lit11: | |
8636 | return "DW_OP_lit11"; | |
8637 | case DW_OP_lit12: | |
8638 | return "DW_OP_lit12"; | |
8639 | case DW_OP_lit13: | |
8640 | return "DW_OP_lit13"; | |
8641 | case DW_OP_lit14: | |
8642 | return "DW_OP_lit14"; | |
8643 | case DW_OP_lit15: | |
8644 | return "DW_OP_lit15"; | |
8645 | case DW_OP_lit16: | |
8646 | return "DW_OP_lit16"; | |
8647 | case DW_OP_lit17: | |
8648 | return "DW_OP_lit17"; | |
8649 | case DW_OP_lit18: | |
8650 | return "DW_OP_lit18"; | |
8651 | case DW_OP_lit19: | |
8652 | return "DW_OP_lit19"; | |
8653 | case DW_OP_lit20: | |
8654 | return "DW_OP_lit20"; | |
8655 | case DW_OP_lit21: | |
8656 | return "DW_OP_lit21"; | |
8657 | case DW_OP_lit22: | |
8658 | return "DW_OP_lit22"; | |
8659 | case DW_OP_lit23: | |
8660 | return "DW_OP_lit23"; | |
8661 | case DW_OP_lit24: | |
8662 | return "DW_OP_lit24"; | |
8663 | case DW_OP_lit25: | |
8664 | return "DW_OP_lit25"; | |
8665 | case DW_OP_lit26: | |
8666 | return "DW_OP_lit26"; | |
8667 | case DW_OP_lit27: | |
8668 | return "DW_OP_lit27"; | |
8669 | case DW_OP_lit28: | |
8670 | return "DW_OP_lit28"; | |
8671 | case DW_OP_lit29: | |
8672 | return "DW_OP_lit29"; | |
8673 | case DW_OP_lit30: | |
8674 | return "DW_OP_lit30"; | |
8675 | case DW_OP_lit31: | |
8676 | return "DW_OP_lit31"; | |
8677 | case DW_OP_reg0: | |
8678 | return "DW_OP_reg0"; | |
8679 | case DW_OP_reg1: | |
8680 | return "DW_OP_reg1"; | |
8681 | case DW_OP_reg2: | |
8682 | return "DW_OP_reg2"; | |
8683 | case DW_OP_reg3: | |
8684 | return "DW_OP_reg3"; | |
8685 | case DW_OP_reg4: | |
8686 | return "DW_OP_reg4"; | |
8687 | case DW_OP_reg5: | |
8688 | return "DW_OP_reg5"; | |
8689 | case DW_OP_reg6: | |
8690 | return "DW_OP_reg6"; | |
8691 | case DW_OP_reg7: | |
8692 | return "DW_OP_reg7"; | |
8693 | case DW_OP_reg8: | |
8694 | return "DW_OP_reg8"; | |
8695 | case DW_OP_reg9: | |
8696 | return "DW_OP_reg9"; | |
8697 | case DW_OP_reg10: | |
8698 | return "DW_OP_reg10"; | |
8699 | case DW_OP_reg11: | |
8700 | return "DW_OP_reg11"; | |
8701 | case DW_OP_reg12: | |
8702 | return "DW_OP_reg12"; | |
8703 | case DW_OP_reg13: | |
8704 | return "DW_OP_reg13"; | |
8705 | case DW_OP_reg14: | |
8706 | return "DW_OP_reg14"; | |
8707 | case DW_OP_reg15: | |
8708 | return "DW_OP_reg15"; | |
8709 | case DW_OP_reg16: | |
8710 | return "DW_OP_reg16"; | |
8711 | case DW_OP_reg17: | |
8712 | return "DW_OP_reg17"; | |
8713 | case DW_OP_reg18: | |
8714 | return "DW_OP_reg18"; | |
8715 | case DW_OP_reg19: | |
8716 | return "DW_OP_reg19"; | |
8717 | case DW_OP_reg20: | |
8718 | return "DW_OP_reg20"; | |
8719 | case DW_OP_reg21: | |
8720 | return "DW_OP_reg21"; | |
8721 | case DW_OP_reg22: | |
8722 | return "DW_OP_reg22"; | |
8723 | case DW_OP_reg23: | |
8724 | return "DW_OP_reg23"; | |
8725 | case DW_OP_reg24: | |
8726 | return "DW_OP_reg24"; | |
8727 | case DW_OP_reg25: | |
8728 | return "DW_OP_reg25"; | |
8729 | case DW_OP_reg26: | |
8730 | return "DW_OP_reg26"; | |
8731 | case DW_OP_reg27: | |
8732 | return "DW_OP_reg27"; | |
8733 | case DW_OP_reg28: | |
8734 | return "DW_OP_reg28"; | |
8735 | case DW_OP_reg29: | |
8736 | return "DW_OP_reg29"; | |
8737 | case DW_OP_reg30: | |
8738 | return "DW_OP_reg30"; | |
8739 | case DW_OP_reg31: | |
8740 | return "DW_OP_reg31"; | |
8741 | case DW_OP_breg0: | |
8742 | return "DW_OP_breg0"; | |
8743 | case DW_OP_breg1: | |
8744 | return "DW_OP_breg1"; | |
8745 | case DW_OP_breg2: | |
8746 | return "DW_OP_breg2"; | |
8747 | case DW_OP_breg3: | |
8748 | return "DW_OP_breg3"; | |
8749 | case DW_OP_breg4: | |
8750 | return "DW_OP_breg4"; | |
8751 | case DW_OP_breg5: | |
8752 | return "DW_OP_breg5"; | |
8753 | case DW_OP_breg6: | |
8754 | return "DW_OP_breg6"; | |
8755 | case DW_OP_breg7: | |
8756 | return "DW_OP_breg7"; | |
8757 | case DW_OP_breg8: | |
8758 | return "DW_OP_breg8"; | |
8759 | case DW_OP_breg9: | |
8760 | return "DW_OP_breg9"; | |
8761 | case DW_OP_breg10: | |
8762 | return "DW_OP_breg10"; | |
8763 | case DW_OP_breg11: | |
8764 | return "DW_OP_breg11"; | |
8765 | case DW_OP_breg12: | |
8766 | return "DW_OP_breg12"; | |
8767 | case DW_OP_breg13: | |
8768 | return "DW_OP_breg13"; | |
8769 | case DW_OP_breg14: | |
8770 | return "DW_OP_breg14"; | |
8771 | case DW_OP_breg15: | |
8772 | return "DW_OP_breg15"; | |
8773 | case DW_OP_breg16: | |
8774 | return "DW_OP_breg16"; | |
8775 | case DW_OP_breg17: | |
8776 | return "DW_OP_breg17"; | |
8777 | case DW_OP_breg18: | |
8778 | return "DW_OP_breg18"; | |
8779 | case DW_OP_breg19: | |
8780 | return "DW_OP_breg19"; | |
8781 | case DW_OP_breg20: | |
8782 | return "DW_OP_breg20"; | |
8783 | case DW_OP_breg21: | |
8784 | return "DW_OP_breg21"; | |
8785 | case DW_OP_breg22: | |
8786 | return "DW_OP_breg22"; | |
8787 | case DW_OP_breg23: | |
8788 | return "DW_OP_breg23"; | |
8789 | case DW_OP_breg24: | |
8790 | return "DW_OP_breg24"; | |
8791 | case DW_OP_breg25: | |
8792 | return "DW_OP_breg25"; | |
8793 | case DW_OP_breg26: | |
8794 | return "DW_OP_breg26"; | |
8795 | case DW_OP_breg27: | |
8796 | return "DW_OP_breg27"; | |
8797 | case DW_OP_breg28: | |
8798 | return "DW_OP_breg28"; | |
8799 | case DW_OP_breg29: | |
8800 | return "DW_OP_breg29"; | |
8801 | case DW_OP_breg30: | |
8802 | return "DW_OP_breg30"; | |
8803 | case DW_OP_breg31: | |
8804 | return "DW_OP_breg31"; | |
8805 | case DW_OP_regx: | |
8806 | return "DW_OP_regx"; | |
8807 | case DW_OP_fbreg: | |
8808 | return "DW_OP_fbreg"; | |
8809 | case DW_OP_bregx: | |
8810 | return "DW_OP_bregx"; | |
8811 | case DW_OP_piece: | |
8812 | return "DW_OP_piece"; | |
8813 | case DW_OP_deref_size: | |
8814 | return "DW_OP_deref_size"; | |
8815 | case DW_OP_xderef_size: | |
8816 | return "DW_OP_xderef_size"; | |
8817 | case DW_OP_nop: | |
8818 | return "DW_OP_nop"; | |
b7619582 | 8819 | /* DWARF 3 extensions. */ |
ed348acc EZ |
8820 | case DW_OP_push_object_address: |
8821 | return "DW_OP_push_object_address"; | |
8822 | case DW_OP_call2: | |
8823 | return "DW_OP_call2"; | |
8824 | case DW_OP_call4: | |
8825 | return "DW_OP_call4"; | |
8826 | case DW_OP_call_ref: | |
8827 | return "DW_OP_call_ref"; | |
b7619582 GF |
8828 | /* GNU extensions. */ |
8829 | case DW_OP_form_tls_address: | |
8830 | return "DW_OP_form_tls_address"; | |
8831 | case DW_OP_call_frame_cfa: | |
8832 | return "DW_OP_call_frame_cfa"; | |
8833 | case DW_OP_bit_piece: | |
8834 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
8835 | case DW_OP_GNU_push_tls_address: |
8836 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
8837 | case DW_OP_GNU_uninit: |
8838 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
8839 | /* HP extensions. */ |
8840 | case DW_OP_HP_is_value: | |
8841 | return "DW_OP_HP_is_value"; | |
8842 | case DW_OP_HP_fltconst4: | |
8843 | return "DW_OP_HP_fltconst4"; | |
8844 | case DW_OP_HP_fltconst8: | |
8845 | return "DW_OP_HP_fltconst8"; | |
8846 | case DW_OP_HP_mod_range: | |
8847 | return "DW_OP_HP_mod_range"; | |
8848 | case DW_OP_HP_unmod_range: | |
8849 | return "DW_OP_HP_unmod_range"; | |
8850 | case DW_OP_HP_tls: | |
8851 | return "DW_OP_HP_tls"; | |
c906108c SS |
8852 | default: |
8853 | return "OP_<unknown>"; | |
8854 | } | |
8855 | } | |
8856 | ||
8857 | static char * | |
fba45db2 | 8858 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
8859 | { |
8860 | if (mybool) | |
8861 | return "TRUE"; | |
8862 | else | |
8863 | return "FALSE"; | |
8864 | } | |
8865 | ||
8866 | /* Convert a DWARF type code into its string name. */ | |
8867 | ||
8868 | static char * | |
aa1ee363 | 8869 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
8870 | { |
8871 | switch (enc) | |
8872 | { | |
b7619582 GF |
8873 | case DW_ATE_void: |
8874 | return "DW_ATE_void"; | |
c906108c SS |
8875 | case DW_ATE_address: |
8876 | return "DW_ATE_address"; | |
8877 | case DW_ATE_boolean: | |
8878 | return "DW_ATE_boolean"; | |
8879 | case DW_ATE_complex_float: | |
8880 | return "DW_ATE_complex_float"; | |
8881 | case DW_ATE_float: | |
8882 | return "DW_ATE_float"; | |
8883 | case DW_ATE_signed: | |
8884 | return "DW_ATE_signed"; | |
8885 | case DW_ATE_signed_char: | |
8886 | return "DW_ATE_signed_char"; | |
8887 | case DW_ATE_unsigned: | |
8888 | return "DW_ATE_unsigned"; | |
8889 | case DW_ATE_unsigned_char: | |
8890 | return "DW_ATE_unsigned_char"; | |
b7619582 | 8891 | /* DWARF 3. */ |
d9fa45fe DC |
8892 | case DW_ATE_imaginary_float: |
8893 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
8894 | case DW_ATE_packed_decimal: |
8895 | return "DW_ATE_packed_decimal"; | |
8896 | case DW_ATE_numeric_string: | |
8897 | return "DW_ATE_numeric_string"; | |
8898 | case DW_ATE_edited: | |
8899 | return "DW_ATE_edited"; | |
8900 | case DW_ATE_signed_fixed: | |
8901 | return "DW_ATE_signed_fixed"; | |
8902 | case DW_ATE_unsigned_fixed: | |
8903 | return "DW_ATE_unsigned_fixed"; | |
8904 | case DW_ATE_decimal_float: | |
8905 | return "DW_ATE_decimal_float"; | |
8906 | /* HP extensions. */ | |
8907 | case DW_ATE_HP_float80: | |
8908 | return "DW_ATE_HP_float80"; | |
8909 | case DW_ATE_HP_complex_float80: | |
8910 | return "DW_ATE_HP_complex_float80"; | |
8911 | case DW_ATE_HP_float128: | |
8912 | return "DW_ATE_HP_float128"; | |
8913 | case DW_ATE_HP_complex_float128: | |
8914 | return "DW_ATE_HP_complex_float128"; | |
8915 | case DW_ATE_HP_floathpintel: | |
8916 | return "DW_ATE_HP_floathpintel"; | |
8917 | case DW_ATE_HP_imaginary_float80: | |
8918 | return "DW_ATE_HP_imaginary_float80"; | |
8919 | case DW_ATE_HP_imaginary_float128: | |
8920 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
8921 | default: |
8922 | return "DW_ATE_<unknown>"; | |
8923 | } | |
8924 | } | |
8925 | ||
8926 | /* Convert a DWARF call frame info operation to its string name. */ | |
8927 | ||
8928 | #if 0 | |
8929 | static char * | |
aa1ee363 | 8930 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
8931 | { |
8932 | switch (cfi_opc) | |
8933 | { | |
8934 | case DW_CFA_advance_loc: | |
8935 | return "DW_CFA_advance_loc"; | |
8936 | case DW_CFA_offset: | |
8937 | return "DW_CFA_offset"; | |
8938 | case DW_CFA_restore: | |
8939 | return "DW_CFA_restore"; | |
8940 | case DW_CFA_nop: | |
8941 | return "DW_CFA_nop"; | |
8942 | case DW_CFA_set_loc: | |
8943 | return "DW_CFA_set_loc"; | |
8944 | case DW_CFA_advance_loc1: | |
8945 | return "DW_CFA_advance_loc1"; | |
8946 | case DW_CFA_advance_loc2: | |
8947 | return "DW_CFA_advance_loc2"; | |
8948 | case DW_CFA_advance_loc4: | |
8949 | return "DW_CFA_advance_loc4"; | |
8950 | case DW_CFA_offset_extended: | |
8951 | return "DW_CFA_offset_extended"; | |
8952 | case DW_CFA_restore_extended: | |
8953 | return "DW_CFA_restore_extended"; | |
8954 | case DW_CFA_undefined: | |
8955 | return "DW_CFA_undefined"; | |
8956 | case DW_CFA_same_value: | |
8957 | return "DW_CFA_same_value"; | |
8958 | case DW_CFA_register: | |
8959 | return "DW_CFA_register"; | |
8960 | case DW_CFA_remember_state: | |
8961 | return "DW_CFA_remember_state"; | |
8962 | case DW_CFA_restore_state: | |
8963 | return "DW_CFA_restore_state"; | |
8964 | case DW_CFA_def_cfa: | |
8965 | return "DW_CFA_def_cfa"; | |
8966 | case DW_CFA_def_cfa_register: | |
8967 | return "DW_CFA_def_cfa_register"; | |
8968 | case DW_CFA_def_cfa_offset: | |
8969 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 8970 | /* DWARF 3. */ |
985cb1a3 JM |
8971 | case DW_CFA_def_cfa_expression: |
8972 | return "DW_CFA_def_cfa_expression"; | |
8973 | case DW_CFA_expression: | |
8974 | return "DW_CFA_expression"; | |
8975 | case DW_CFA_offset_extended_sf: | |
8976 | return "DW_CFA_offset_extended_sf"; | |
8977 | case DW_CFA_def_cfa_sf: | |
8978 | return "DW_CFA_def_cfa_sf"; | |
8979 | case DW_CFA_def_cfa_offset_sf: | |
8980 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
8981 | case DW_CFA_val_offset: |
8982 | return "DW_CFA_val_offset"; | |
8983 | case DW_CFA_val_offset_sf: | |
8984 | return "DW_CFA_val_offset_sf"; | |
8985 | case DW_CFA_val_expression: | |
8986 | return "DW_CFA_val_expression"; | |
8987 | /* SGI/MIPS specific. */ | |
c906108c SS |
8988 | case DW_CFA_MIPS_advance_loc8: |
8989 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 8990 | /* GNU extensions. */ |
985cb1a3 JM |
8991 | case DW_CFA_GNU_window_save: |
8992 | return "DW_CFA_GNU_window_save"; | |
8993 | case DW_CFA_GNU_args_size: | |
8994 | return "DW_CFA_GNU_args_size"; | |
8995 | case DW_CFA_GNU_negative_offset_extended: | |
8996 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
8997 | default: |
8998 | return "DW_CFA_<unknown>"; | |
8999 | } | |
9000 | } | |
9001 | #endif | |
9002 | ||
f9aca02d | 9003 | static void |
fba45db2 | 9004 | dump_die (struct die_info *die) |
c906108c SS |
9005 | { |
9006 | unsigned int i; | |
9007 | ||
48cd0caa | 9008 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 9009 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 9010 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 9011 | dwarf_bool_name (die->child != NULL)); |
c906108c | 9012 | |
48cd0caa | 9013 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
9014 | for (i = 0; i < die->num_attrs; ++i) |
9015 | { | |
48cd0caa | 9016 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
9017 | dwarf_attr_name (die->attrs[i].name), |
9018 | dwarf_form_name (die->attrs[i].form)); | |
9019 | switch (die->attrs[i].form) | |
9020 | { | |
9021 | case DW_FORM_ref_addr: | |
9022 | case DW_FORM_addr: | |
48cd0caa | 9023 | fprintf_unfiltered (gdb_stderr, "address: "); |
ed49a04f | 9024 | fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), gdb_stderr); |
c906108c SS |
9025 | break; |
9026 | case DW_FORM_block2: | |
9027 | case DW_FORM_block4: | |
9028 | case DW_FORM_block: | |
9029 | case DW_FORM_block1: | |
48cd0caa | 9030 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 9031 | break; |
10b3939b DJ |
9032 | case DW_FORM_ref1: |
9033 | case DW_FORM_ref2: | |
9034 | case DW_FORM_ref4: | |
9035 | fprintf_unfiltered (gdb_stderr, "constant ref: %ld (adjusted)", | |
9036 | (long) (DW_ADDR (&die->attrs[i]))); | |
9037 | break; | |
c906108c SS |
9038 | case DW_FORM_data1: |
9039 | case DW_FORM_data2: | |
9040 | case DW_FORM_data4: | |
ce5d95e1 | 9041 | case DW_FORM_data8: |
c906108c SS |
9042 | case DW_FORM_udata: |
9043 | case DW_FORM_sdata: | |
48cd0caa | 9044 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
9045 | break; |
9046 | case DW_FORM_string: | |
4bdf3d34 | 9047 | case DW_FORM_strp: |
48cd0caa | 9048 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 9049 | DW_STRING (&die->attrs[i]) |
c5aa993b | 9050 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
9051 | break; |
9052 | case DW_FORM_flag: | |
9053 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 9054 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 9055 | else |
48cd0caa | 9056 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 9057 | break; |
a8329558 KW |
9058 | case DW_FORM_indirect: |
9059 | /* the reader will have reduced the indirect form to | |
9060 | the "base form" so this form should not occur */ | |
48cd0caa | 9061 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 9062 | break; |
c906108c | 9063 | default: |
48cd0caa | 9064 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 9065 | die->attrs[i].form); |
c906108c | 9066 | } |
48cd0caa | 9067 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
9068 | } |
9069 | } | |
9070 | ||
f9aca02d | 9071 | static void |
fba45db2 | 9072 | dump_die_list (struct die_info *die) |
c906108c SS |
9073 | { |
9074 | while (die) | |
9075 | { | |
9076 | dump_die (die); | |
639d11d3 DC |
9077 | if (die->child != NULL) |
9078 | dump_die_list (die->child); | |
9079 | if (die->sibling != NULL) | |
9080 | dump_die_list (die->sibling); | |
c906108c SS |
9081 | } |
9082 | } | |
9083 | ||
f9aca02d | 9084 | static void |
51545339 | 9085 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 9086 | { |
51545339 | 9087 | void **slot; |
c906108c | 9088 | |
51545339 DJ |
9089 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
9090 | ||
9091 | *slot = die; | |
c906108c SS |
9092 | } |
9093 | ||
9094 | static unsigned int | |
e142c38c | 9095 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
9096 | { |
9097 | unsigned int result = 0; | |
9098 | ||
9099 | switch (attr->form) | |
9100 | { | |
9101 | case DW_FORM_ref_addr: | |
c906108c SS |
9102 | case DW_FORM_ref1: |
9103 | case DW_FORM_ref2: | |
9104 | case DW_FORM_ref4: | |
613e1657 | 9105 | case DW_FORM_ref8: |
c906108c | 9106 | case DW_FORM_ref_udata: |
10b3939b | 9107 | result = DW_ADDR (attr); |
c906108c SS |
9108 | break; |
9109 | default: | |
4d3c2250 | 9110 | complaint (&symfile_complaints, |
e2e0b3e5 | 9111 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 9112 | dwarf_form_name (attr->form)); |
c906108c SS |
9113 | } |
9114 | return result; | |
9115 | } | |
9116 | ||
a02abb62 JB |
9117 | /* Return the constant value held by the given attribute. Return -1 |
9118 | if the value held by the attribute is not constant. */ | |
9119 | ||
9120 | static int | |
9121 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
9122 | { | |
9123 | if (attr->form == DW_FORM_sdata) | |
9124 | return DW_SND (attr); | |
9125 | else if (attr->form == DW_FORM_udata | |
9126 | || attr->form == DW_FORM_data1 | |
9127 | || attr->form == DW_FORM_data2 | |
9128 | || attr->form == DW_FORM_data4 | |
9129 | || attr->form == DW_FORM_data8) | |
9130 | return DW_UNSND (attr); | |
9131 | else | |
9132 | { | |
e2e0b3e5 | 9133 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
9134 | dwarf_form_name (attr->form)); |
9135 | return default_value; | |
9136 | } | |
9137 | } | |
9138 | ||
03dd20cc DJ |
9139 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
9140 | unit and add it to our queue. */ | |
9141 | ||
9142 | static void | |
9143 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, | |
9144 | struct dwarf2_per_cu_data *per_cu) | |
9145 | { | |
9146 | /* Mark the dependence relation so that we don't flush PER_CU | |
9147 | too early. */ | |
9148 | dwarf2_add_dependence (this_cu, per_cu); | |
9149 | ||
9150 | /* If it's already on the queue, we have nothing to do. */ | |
9151 | if (per_cu->queued) | |
9152 | return; | |
9153 | ||
9154 | /* If the compilation unit is already loaded, just mark it as | |
9155 | used. */ | |
9156 | if (per_cu->cu != NULL) | |
9157 | { | |
9158 | per_cu->cu->last_used = 0; | |
9159 | return; | |
9160 | } | |
9161 | ||
9162 | /* Add it to the queue. */ | |
9163 | queue_comp_unit (per_cu, this_cu->objfile); | |
9164 | } | |
9165 | ||
f9aca02d | 9166 | static struct die_info * |
10b3939b | 9167 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
f2f0e013 | 9168 | struct dwarf2_cu **ref_cu) |
c906108c SS |
9169 | { |
9170 | struct die_info *die; | |
10b3939b | 9171 | unsigned int offset; |
10b3939b | 9172 | struct die_info temp_die; |
f2f0e013 | 9173 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
10b3939b DJ |
9174 | |
9175 | offset = dwarf2_get_ref_die_offset (attr, cu); | |
9176 | ||
9177 | if (DW_ADDR (attr) < cu->header.offset | |
9178 | || DW_ADDR (attr) >= cu->header.offset + cu->header.length) | |
9179 | { | |
9180 | struct dwarf2_per_cu_data *per_cu; | |
9181 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (attr), | |
9182 | cu->objfile); | |
03dd20cc DJ |
9183 | |
9184 | /* If necessary, add it to the queue and load its DIEs. */ | |
9185 | maybe_queue_comp_unit (cu, per_cu); | |
9186 | ||
10b3939b DJ |
9187 | target_cu = per_cu->cu; |
9188 | } | |
9189 | else | |
9190 | target_cu = cu; | |
c906108c | 9191 | |
f2f0e013 | 9192 | *ref_cu = target_cu; |
51545339 DJ |
9193 | temp_die.offset = offset; |
9194 | die = htab_find_with_hash (target_cu->die_hash, &temp_die, offset); | |
9195 | if (die) | |
9196 | return die; | |
10b3939b | 9197 | |
8a3fe4f8 AC |
9198 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
9199 | "at 0x%lx [in module %s]"), | |
1d325ec1 | 9200 | (long) offset, (long) src_die->offset, cu->objfile->name); |
c906108c SS |
9201 | } |
9202 | ||
c906108c SS |
9203 | /* Decode simple location descriptions. |
9204 | Given a pointer to a dwarf block that defines a location, compute | |
9205 | the location and return the value. | |
9206 | ||
4cecd739 DJ |
9207 | NOTE drow/2003-11-18: This function is called in two situations |
9208 | now: for the address of static or global variables (partial symbols | |
9209 | only) and for offsets into structures which are expected to be | |
9210 | (more or less) constant. The partial symbol case should go away, | |
9211 | and only the constant case should remain. That will let this | |
9212 | function complain more accurately. A few special modes are allowed | |
9213 | without complaint for global variables (for instance, global | |
9214 | register values and thread-local values). | |
c906108c SS |
9215 | |
9216 | A location description containing no operations indicates that the | |
4cecd739 | 9217 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
9218 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
9219 | callers will only want a very basic result and this can become a | |
9220 | complaint. | |
c906108c | 9221 | |
c906108c SS |
9222 | Note that stack[0] is unused except as a default error return. |
9223 | Note that stack overflow is not yet handled. */ | |
9224 | ||
9225 | static CORE_ADDR | |
e7c27a73 | 9226 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 9227 | { |
e7c27a73 DJ |
9228 | struct objfile *objfile = cu->objfile; |
9229 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
9230 | int i; |
9231 | int size = blk->size; | |
fe1b8b76 | 9232 | gdb_byte *data = blk->data; |
c906108c SS |
9233 | CORE_ADDR stack[64]; |
9234 | int stacki; | |
9235 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 9236 | gdb_byte op; |
c906108c SS |
9237 | |
9238 | i = 0; | |
9239 | stacki = 0; | |
9240 | stack[stacki] = 0; | |
c906108c SS |
9241 | |
9242 | while (i < size) | |
9243 | { | |
c906108c SS |
9244 | op = data[i++]; |
9245 | switch (op) | |
9246 | { | |
f1bea926 JM |
9247 | case DW_OP_lit0: |
9248 | case DW_OP_lit1: | |
9249 | case DW_OP_lit2: | |
9250 | case DW_OP_lit3: | |
9251 | case DW_OP_lit4: | |
9252 | case DW_OP_lit5: | |
9253 | case DW_OP_lit6: | |
9254 | case DW_OP_lit7: | |
9255 | case DW_OP_lit8: | |
9256 | case DW_OP_lit9: | |
9257 | case DW_OP_lit10: | |
9258 | case DW_OP_lit11: | |
9259 | case DW_OP_lit12: | |
9260 | case DW_OP_lit13: | |
9261 | case DW_OP_lit14: | |
9262 | case DW_OP_lit15: | |
9263 | case DW_OP_lit16: | |
9264 | case DW_OP_lit17: | |
9265 | case DW_OP_lit18: | |
9266 | case DW_OP_lit19: | |
9267 | case DW_OP_lit20: | |
9268 | case DW_OP_lit21: | |
9269 | case DW_OP_lit22: | |
9270 | case DW_OP_lit23: | |
9271 | case DW_OP_lit24: | |
9272 | case DW_OP_lit25: | |
9273 | case DW_OP_lit26: | |
9274 | case DW_OP_lit27: | |
9275 | case DW_OP_lit28: | |
9276 | case DW_OP_lit29: | |
9277 | case DW_OP_lit30: | |
9278 | case DW_OP_lit31: | |
9279 | stack[++stacki] = op - DW_OP_lit0; | |
9280 | break; | |
9281 | ||
c906108c SS |
9282 | case DW_OP_reg0: |
9283 | case DW_OP_reg1: | |
9284 | case DW_OP_reg2: | |
9285 | case DW_OP_reg3: | |
9286 | case DW_OP_reg4: | |
9287 | case DW_OP_reg5: | |
9288 | case DW_OP_reg6: | |
9289 | case DW_OP_reg7: | |
9290 | case DW_OP_reg8: | |
9291 | case DW_OP_reg9: | |
9292 | case DW_OP_reg10: | |
9293 | case DW_OP_reg11: | |
9294 | case DW_OP_reg12: | |
9295 | case DW_OP_reg13: | |
9296 | case DW_OP_reg14: | |
9297 | case DW_OP_reg15: | |
9298 | case DW_OP_reg16: | |
9299 | case DW_OP_reg17: | |
9300 | case DW_OP_reg18: | |
9301 | case DW_OP_reg19: | |
9302 | case DW_OP_reg20: | |
9303 | case DW_OP_reg21: | |
9304 | case DW_OP_reg22: | |
9305 | case DW_OP_reg23: | |
9306 | case DW_OP_reg24: | |
9307 | case DW_OP_reg25: | |
9308 | case DW_OP_reg26: | |
9309 | case DW_OP_reg27: | |
9310 | case DW_OP_reg28: | |
9311 | case DW_OP_reg29: | |
9312 | case DW_OP_reg30: | |
9313 | case DW_OP_reg31: | |
c906108c | 9314 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9315 | if (i < size) |
9316 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9317 | break; |
9318 | ||
9319 | case DW_OP_regx: | |
c906108c SS |
9320 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9321 | i += bytes_read; | |
c906108c | 9322 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9323 | if (i < size) |
9324 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9325 | break; |
9326 | ||
9327 | case DW_OP_addr: | |
107d2387 | 9328 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9329 | cu, &bytes_read); |
107d2387 | 9330 | i += bytes_read; |
c906108c SS |
9331 | break; |
9332 | ||
9333 | case DW_OP_const1u: | |
9334 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9335 | i += 1; | |
9336 | break; | |
9337 | ||
9338 | case DW_OP_const1s: | |
9339 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9340 | i += 1; | |
9341 | break; | |
9342 | ||
9343 | case DW_OP_const2u: | |
9344 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9345 | i += 2; | |
9346 | break; | |
9347 | ||
9348 | case DW_OP_const2s: | |
9349 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9350 | i += 2; | |
9351 | break; | |
9352 | ||
9353 | case DW_OP_const4u: | |
9354 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9355 | i += 4; | |
9356 | break; | |
9357 | ||
9358 | case DW_OP_const4s: | |
9359 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9360 | i += 4; | |
9361 | break; | |
9362 | ||
9363 | case DW_OP_constu: | |
9364 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9365 | &bytes_read); |
c906108c SS |
9366 | i += bytes_read; |
9367 | break; | |
9368 | ||
9369 | case DW_OP_consts: | |
9370 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9371 | i += bytes_read; | |
9372 | break; | |
9373 | ||
f1bea926 JM |
9374 | case DW_OP_dup: |
9375 | stack[stacki + 1] = stack[stacki]; | |
9376 | stacki++; | |
9377 | break; | |
9378 | ||
c906108c SS |
9379 | case DW_OP_plus: |
9380 | stack[stacki - 1] += stack[stacki]; | |
9381 | stacki--; | |
9382 | break; | |
9383 | ||
9384 | case DW_OP_plus_uconst: | |
9385 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9386 | i += bytes_read; | |
9387 | break; | |
9388 | ||
9389 | case DW_OP_minus: | |
f1bea926 | 9390 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9391 | stacki--; |
9392 | break; | |
9393 | ||
7a292a7a | 9394 | case DW_OP_deref: |
7a292a7a | 9395 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9396 | this using GDB's address_class enum. This is valid for partial |
9397 | global symbols, although the variable's address will be bogus | |
9398 | in the psymtab. */ | |
7a292a7a | 9399 | if (i < size) |
4d3c2250 | 9400 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9401 | break; |
9402 | ||
9d774e44 | 9403 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9404 | /* The top of the stack has the offset from the beginning |
9405 | of the thread control block at which the variable is located. */ | |
9406 | /* Nothing should follow this operator, so the top of stack would | |
9407 | be returned. */ | |
4cecd739 DJ |
9408 | /* This is valid for partial global symbols, but the variable's |
9409 | address will be bogus in the psymtab. */ | |
9d774e44 | 9410 | if (i < size) |
4d3c2250 | 9411 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9412 | break; |
9413 | ||
42be36b3 CT |
9414 | case DW_OP_GNU_uninit: |
9415 | break; | |
9416 | ||
c906108c | 9417 | default: |
e2e0b3e5 | 9418 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9419 | dwarf_stack_op_name (op)); |
c906108c SS |
9420 | return (stack[stacki]); |
9421 | } | |
9422 | } | |
9423 | return (stack[stacki]); | |
9424 | } | |
9425 | ||
9426 | /* memory allocation interface */ | |
9427 | ||
c906108c | 9428 | static struct dwarf_block * |
7b5a2f43 | 9429 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9430 | { |
9431 | struct dwarf_block *blk; | |
9432 | ||
9433 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9434 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9435 | return (blk); |
9436 | } | |
9437 | ||
9438 | static struct abbrev_info * | |
f3dd6933 | 9439 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9440 | { |
9441 | struct abbrev_info *abbrev; | |
9442 | ||
f3dd6933 DJ |
9443 | abbrev = (struct abbrev_info *) |
9444 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9445 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9446 | return (abbrev); | |
9447 | } | |
9448 | ||
9449 | static struct die_info * | |
b60c80d6 | 9450 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
c906108c SS |
9451 | { |
9452 | struct die_info *die; | |
b60c80d6 DJ |
9453 | size_t size = sizeof (struct die_info); |
9454 | ||
9455 | if (num_attrs > 1) | |
9456 | size += (num_attrs - 1) * sizeof (struct attribute); | |
c906108c | 9457 | |
b60c80d6 | 9458 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
c906108c SS |
9459 | memset (die, 0, sizeof (struct die_info)); |
9460 | return (die); | |
9461 | } | |
2e276125 JB |
9462 | |
9463 | \f | |
9464 | /* Macro support. */ | |
9465 | ||
9466 | ||
9467 | /* Return the full name of file number I in *LH's file name table. | |
9468 | Use COMP_DIR as the name of the current directory of the | |
9469 | compilation. The result is allocated using xmalloc; the caller is | |
9470 | responsible for freeing it. */ | |
9471 | static char * | |
9472 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9473 | { | |
6a83a1e6 EZ |
9474 | /* Is the file number a valid index into the line header's file name |
9475 | table? Remember that file numbers start with one, not zero. */ | |
9476 | if (1 <= file && file <= lh->num_file_names) | |
9477 | { | |
9478 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9479 | |
6a83a1e6 EZ |
9480 | if (IS_ABSOLUTE_PATH (fe->name)) |
9481 | return xstrdup (fe->name); | |
9482 | else | |
9483 | { | |
9484 | const char *dir; | |
9485 | int dir_len; | |
9486 | char *full_name; | |
9487 | ||
9488 | if (fe->dir_index) | |
9489 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9490 | else | |
9491 | dir = comp_dir; | |
9492 | ||
9493 | if (dir) | |
9494 | { | |
9495 | dir_len = strlen (dir); | |
9496 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9497 | strcpy (full_name, dir); | |
9498 | full_name[dir_len] = '/'; | |
9499 | strcpy (full_name + dir_len + 1, fe->name); | |
9500 | return full_name; | |
9501 | } | |
9502 | else | |
9503 | return xstrdup (fe->name); | |
9504 | } | |
9505 | } | |
2e276125 JB |
9506 | else |
9507 | { | |
6a83a1e6 EZ |
9508 | /* The compiler produced a bogus file number. We can at least |
9509 | record the macro definitions made in the file, even if we | |
9510 | won't be able to find the file by name. */ | |
9511 | char fake_name[80]; | |
9512 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9513 | |
6a83a1e6 EZ |
9514 | complaint (&symfile_complaints, |
9515 | _("bad file number in macro information (%d)"), | |
9516 | file); | |
2e276125 | 9517 | |
6a83a1e6 | 9518 | return xstrdup (fake_name); |
2e276125 JB |
9519 | } |
9520 | } | |
9521 | ||
9522 | ||
9523 | static struct macro_source_file * | |
9524 | macro_start_file (int file, int line, | |
9525 | struct macro_source_file *current_file, | |
9526 | const char *comp_dir, | |
9527 | struct line_header *lh, struct objfile *objfile) | |
9528 | { | |
9529 | /* The full name of this source file. */ | |
9530 | char *full_name = file_full_name (file, lh, comp_dir); | |
9531 | ||
9532 | /* We don't create a macro table for this compilation unit | |
9533 | at all until we actually get a filename. */ | |
9534 | if (! pending_macros) | |
4a146b47 | 9535 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9536 | objfile->macro_cache); |
2e276125 JB |
9537 | |
9538 | if (! current_file) | |
9539 | /* If we have no current file, then this must be the start_file | |
9540 | directive for the compilation unit's main source file. */ | |
9541 | current_file = macro_set_main (pending_macros, full_name); | |
9542 | else | |
9543 | current_file = macro_include (current_file, line, full_name); | |
9544 | ||
9545 | xfree (full_name); | |
9546 | ||
9547 | return current_file; | |
9548 | } | |
9549 | ||
9550 | ||
9551 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9552 | followed by a null byte. */ | |
9553 | static char * | |
9554 | copy_string (const char *buf, int len) | |
9555 | { | |
9556 | char *s = xmalloc (len + 1); | |
9557 | memcpy (s, buf, len); | |
9558 | s[len] = '\0'; | |
9559 | ||
9560 | return s; | |
9561 | } | |
9562 | ||
9563 | ||
9564 | static const char * | |
9565 | consume_improper_spaces (const char *p, const char *body) | |
9566 | { | |
9567 | if (*p == ' ') | |
9568 | { | |
4d3c2250 | 9569 | complaint (&symfile_complaints, |
e2e0b3e5 | 9570 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9571 | body); |
2e276125 JB |
9572 | |
9573 | while (*p == ' ') | |
9574 | p++; | |
9575 | } | |
9576 | ||
9577 | return p; | |
9578 | } | |
9579 | ||
9580 | ||
9581 | static void | |
9582 | parse_macro_definition (struct macro_source_file *file, int line, | |
9583 | const char *body) | |
9584 | { | |
9585 | const char *p; | |
9586 | ||
9587 | /* The body string takes one of two forms. For object-like macro | |
9588 | definitions, it should be: | |
9589 | ||
9590 | <macro name> " " <definition> | |
9591 | ||
9592 | For function-like macro definitions, it should be: | |
9593 | ||
9594 | <macro name> "() " <definition> | |
9595 | or | |
9596 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
9597 | ||
9598 | Spaces may appear only where explicitly indicated, and in the | |
9599 | <definition>. | |
9600 | ||
9601 | The Dwarf 2 spec says that an object-like macro's name is always | |
9602 | followed by a space, but versions of GCC around March 2002 omit | |
9603 | the space when the macro's definition is the empty string. | |
9604 | ||
9605 | The Dwarf 2 spec says that there should be no spaces between the | |
9606 | formal arguments in a function-like macro's formal argument list, | |
9607 | but versions of GCC around March 2002 include spaces after the | |
9608 | commas. */ | |
9609 | ||
9610 | ||
9611 | /* Find the extent of the macro name. The macro name is terminated | |
9612 | by either a space or null character (for an object-like macro) or | |
9613 | an opening paren (for a function-like macro). */ | |
9614 | for (p = body; *p; p++) | |
9615 | if (*p == ' ' || *p == '(') | |
9616 | break; | |
9617 | ||
9618 | if (*p == ' ' || *p == '\0') | |
9619 | { | |
9620 | /* It's an object-like macro. */ | |
9621 | int name_len = p - body; | |
9622 | char *name = copy_string (body, name_len); | |
9623 | const char *replacement; | |
9624 | ||
9625 | if (*p == ' ') | |
9626 | replacement = body + name_len + 1; | |
9627 | else | |
9628 | { | |
4d3c2250 | 9629 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9630 | replacement = body + name_len; |
9631 | } | |
9632 | ||
9633 | macro_define_object (file, line, name, replacement); | |
9634 | ||
9635 | xfree (name); | |
9636 | } | |
9637 | else if (*p == '(') | |
9638 | { | |
9639 | /* It's a function-like macro. */ | |
9640 | char *name = copy_string (body, p - body); | |
9641 | int argc = 0; | |
9642 | int argv_size = 1; | |
9643 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
9644 | ||
9645 | p++; | |
9646 | ||
9647 | p = consume_improper_spaces (p, body); | |
9648 | ||
9649 | /* Parse the formal argument list. */ | |
9650 | while (*p && *p != ')') | |
9651 | { | |
9652 | /* Find the extent of the current argument name. */ | |
9653 | const char *arg_start = p; | |
9654 | ||
9655 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
9656 | p++; | |
9657 | ||
9658 | if (! *p || p == arg_start) | |
4d3c2250 | 9659 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9660 | else |
9661 | { | |
9662 | /* Make sure argv has room for the new argument. */ | |
9663 | if (argc >= argv_size) | |
9664 | { | |
9665 | argv_size *= 2; | |
9666 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
9667 | } | |
9668 | ||
9669 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
9670 | } | |
9671 | ||
9672 | p = consume_improper_spaces (p, body); | |
9673 | ||
9674 | /* Consume the comma, if present. */ | |
9675 | if (*p == ',') | |
9676 | { | |
9677 | p++; | |
9678 | ||
9679 | p = consume_improper_spaces (p, body); | |
9680 | } | |
9681 | } | |
9682 | ||
9683 | if (*p == ')') | |
9684 | { | |
9685 | p++; | |
9686 | ||
9687 | if (*p == ' ') | |
9688 | /* Perfectly formed definition, no complaints. */ | |
9689 | macro_define_function (file, line, name, | |
9690 | argc, (const char **) argv, | |
9691 | p + 1); | |
9692 | else if (*p == '\0') | |
9693 | { | |
9694 | /* Complain, but do define it. */ | |
4d3c2250 | 9695 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9696 | macro_define_function (file, line, name, |
9697 | argc, (const char **) argv, | |
9698 | p); | |
9699 | } | |
9700 | else | |
9701 | /* Just complain. */ | |
4d3c2250 | 9702 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9703 | } |
9704 | else | |
9705 | /* Just complain. */ | |
4d3c2250 | 9706 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9707 | |
9708 | xfree (name); | |
9709 | { | |
9710 | int i; | |
9711 | ||
9712 | for (i = 0; i < argc; i++) | |
9713 | xfree (argv[i]); | |
9714 | } | |
9715 | xfree (argv); | |
9716 | } | |
9717 | else | |
4d3c2250 | 9718 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9719 | } |
9720 | ||
9721 | ||
9722 | static void | |
9723 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
9724 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 9725 | struct dwarf2_cu *cu) |
2e276125 | 9726 | { |
fe1b8b76 | 9727 | gdb_byte *mac_ptr, *mac_end; |
2e276125 JB |
9728 | struct macro_source_file *current_file = 0; |
9729 | ||
6502dd73 | 9730 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 9731 | { |
e2e0b3e5 | 9732 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
9733 | return; |
9734 | } | |
9735 | ||
6502dd73 DJ |
9736 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
9737 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
9738 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
9739 | |
9740 | for (;;) | |
9741 | { | |
9742 | enum dwarf_macinfo_record_type macinfo_type; | |
9743 | ||
9744 | /* Do we at least have room for a macinfo type byte? */ | |
9745 | if (mac_ptr >= mac_end) | |
9746 | { | |
4d3c2250 | 9747 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9748 | return; |
9749 | } | |
9750 | ||
9751 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
9752 | mac_ptr++; | |
9753 | ||
9754 | switch (macinfo_type) | |
9755 | { | |
9756 | /* A zero macinfo type indicates the end of the macro | |
9757 | information. */ | |
9758 | case 0: | |
9759 | return; | |
9760 | ||
9761 | case DW_MACINFO_define: | |
9762 | case DW_MACINFO_undef: | |
9763 | { | |
891d2f0b | 9764 | unsigned int bytes_read; |
2e276125 JB |
9765 | int line; |
9766 | char *body; | |
9767 | ||
9768 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9769 | mac_ptr += bytes_read; | |
9770 | body = read_string (abfd, mac_ptr, &bytes_read); | |
9771 | mac_ptr += bytes_read; | |
9772 | ||
9773 | if (! current_file) | |
4d3c2250 | 9774 | complaint (&symfile_complaints, |
e2e0b3e5 | 9775 | _("debug info gives macro %s outside of any file: %s"), |
4d3c2250 KB |
9776 | macinfo_type == |
9777 | DW_MACINFO_define ? "definition" : macinfo_type == | |
9778 | DW_MACINFO_undef ? "undefinition" : | |
9779 | "something-or-other", body); | |
2e276125 JB |
9780 | else |
9781 | { | |
9782 | if (macinfo_type == DW_MACINFO_define) | |
9783 | parse_macro_definition (current_file, line, body); | |
9784 | else if (macinfo_type == DW_MACINFO_undef) | |
9785 | macro_undef (current_file, line, body); | |
9786 | } | |
9787 | } | |
9788 | break; | |
9789 | ||
9790 | case DW_MACINFO_start_file: | |
9791 | { | |
891d2f0b | 9792 | unsigned int bytes_read; |
2e276125 JB |
9793 | int line, file; |
9794 | ||
9795 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9796 | mac_ptr += bytes_read; | |
9797 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9798 | mac_ptr += bytes_read; | |
9799 | ||
9800 | current_file = macro_start_file (file, line, | |
9801 | current_file, comp_dir, | |
e7c27a73 | 9802 | lh, cu->objfile); |
2e276125 JB |
9803 | } |
9804 | break; | |
9805 | ||
9806 | case DW_MACINFO_end_file: | |
9807 | if (! current_file) | |
4d3c2250 | 9808 | complaint (&symfile_complaints, |
e2e0b3e5 | 9809 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
9810 | else |
9811 | { | |
9812 | current_file = current_file->included_by; | |
9813 | if (! current_file) | |
9814 | { | |
9815 | enum dwarf_macinfo_record_type next_type; | |
9816 | ||
9817 | /* GCC circa March 2002 doesn't produce the zero | |
9818 | type byte marking the end of the compilation | |
9819 | unit. Complain if it's not there, but exit no | |
9820 | matter what. */ | |
9821 | ||
9822 | /* Do we at least have room for a macinfo type byte? */ | |
9823 | if (mac_ptr >= mac_end) | |
9824 | { | |
4d3c2250 | 9825 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9826 | return; |
9827 | } | |
9828 | ||
9829 | /* We don't increment mac_ptr here, so this is just | |
9830 | a look-ahead. */ | |
9831 | next_type = read_1_byte (abfd, mac_ptr); | |
9832 | if (next_type != 0) | |
4d3c2250 | 9833 | complaint (&symfile_complaints, |
e2e0b3e5 | 9834 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
9835 | |
9836 | return; | |
9837 | } | |
9838 | } | |
9839 | break; | |
9840 | ||
9841 | case DW_MACINFO_vendor_ext: | |
9842 | { | |
891d2f0b | 9843 | unsigned int bytes_read; |
2e276125 JB |
9844 | int constant; |
9845 | char *string; | |
9846 | ||
9847 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9848 | mac_ptr += bytes_read; | |
9849 | string = read_string (abfd, mac_ptr, &bytes_read); | |
9850 | mac_ptr += bytes_read; | |
9851 | ||
9852 | /* We don't recognize any vendor extensions. */ | |
9853 | } | |
9854 | break; | |
9855 | } | |
9856 | } | |
9857 | } | |
8e19ed76 PS |
9858 | |
9859 | /* Check if the attribute's form is a DW_FORM_block* | |
9860 | if so return true else false. */ | |
9861 | static int | |
9862 | attr_form_is_block (struct attribute *attr) | |
9863 | { | |
9864 | return (attr == NULL ? 0 : | |
9865 | attr->form == DW_FORM_block1 | |
9866 | || attr->form == DW_FORM_block2 | |
9867 | || attr->form == DW_FORM_block4 | |
9868 | || attr->form == DW_FORM_block); | |
9869 | } | |
4c2df51b | 9870 | |
c6a0999f JB |
9871 | /* Return non-zero if ATTR's value is a section offset --- classes |
9872 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
9873 | You may use DW_UNSND (attr) to retrieve such offsets. | |
9874 | ||
9875 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
9876 | may have a value that belongs to more than one of these classes; it | |
9877 | would be ambiguous if we did, because we use the same forms for all | |
9878 | of them. */ | |
3690dd37 JB |
9879 | static int |
9880 | attr_form_is_section_offset (struct attribute *attr) | |
9881 | { | |
9882 | return (attr->form == DW_FORM_data4 | |
9883 | || attr->form == DW_FORM_data8); | |
9884 | } | |
9885 | ||
9886 | ||
9887 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
9888 | zero otherwise. When this function returns true, you can apply | |
9889 | dwarf2_get_attr_constant_value to it. | |
9890 | ||
9891 | However, note that for some attributes you must check | |
9892 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
9893 | and DW_FORM_data8 are members of both the constant class, and of | |
9894 | the classes that contain offsets into other debug sections | |
9895 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
9896 | that, if an attribute's can be either a constant or one of the | |
9897 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
9898 | taken as section offsets, not constants. */ | |
9899 | static int | |
9900 | attr_form_is_constant (struct attribute *attr) | |
9901 | { | |
9902 | switch (attr->form) | |
9903 | { | |
9904 | case DW_FORM_sdata: | |
9905 | case DW_FORM_udata: | |
9906 | case DW_FORM_data1: | |
9907 | case DW_FORM_data2: | |
9908 | case DW_FORM_data4: | |
9909 | case DW_FORM_data8: | |
9910 | return 1; | |
9911 | default: | |
9912 | return 0; | |
9913 | } | |
9914 | } | |
9915 | ||
4c2df51b DJ |
9916 | static void |
9917 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9918 | struct dwarf2_cu *cu) |
4c2df51b | 9919 | { |
3690dd37 | 9920 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
9921 | /* ".debug_loc" may not exist at all, or the offset may be outside |
9922 | the section. If so, fall through to the complaint in the | |
9923 | other branch. */ | |
9924 | && DW_UNSND (attr) < dwarf2_per_objfile->loc_size) | |
4c2df51b | 9925 | { |
0d53c4c4 | 9926 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 9927 | |
4a146b47 | 9928 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9929 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
9930 | baton->per_cu = cu->per_cu; |
9931 | gdb_assert (baton->per_cu); | |
4c2df51b | 9932 | |
0d53c4c4 DJ |
9933 | /* We don't know how long the location list is, but make sure we |
9934 | don't run off the edge of the section. */ | |
6502dd73 DJ |
9935 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
9936 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
9937 | baton->base_address = cu->header.base_address; |
9938 | if (cu->header.base_known == 0) | |
0d53c4c4 | 9939 | complaint (&symfile_complaints, |
e2e0b3e5 | 9940 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 9941 | |
a67af2b9 | 9942 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
9943 | SYMBOL_LOCATION_BATON (sym) = baton; |
9944 | } | |
9945 | else | |
9946 | { | |
9947 | struct dwarf2_locexpr_baton *baton; | |
9948 | ||
4a146b47 | 9949 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9950 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
9951 | baton->per_cu = cu->per_cu; |
9952 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
9953 | |
9954 | if (attr_form_is_block (attr)) | |
9955 | { | |
9956 | /* Note that we're just copying the block's data pointer | |
9957 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
9958 | info_buffer for SYM's objfile; right now we never release |
9959 | that buffer, but when we do clean up properly this may | |
9960 | need to change. */ | |
0d53c4c4 DJ |
9961 | baton->size = DW_BLOCK (attr)->size; |
9962 | baton->data = DW_BLOCK (attr)->data; | |
9963 | } | |
9964 | else | |
9965 | { | |
9966 | dwarf2_invalid_attrib_class_complaint ("location description", | |
9967 | SYMBOL_NATURAL_NAME (sym)); | |
9968 | baton->size = 0; | |
9969 | baton->data = NULL; | |
9970 | } | |
9971 | ||
a67af2b9 | 9972 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
9973 | SYMBOL_LOCATION_BATON (sym) = baton; |
9974 | } | |
4c2df51b | 9975 | } |
6502dd73 | 9976 | |
ae0d2f24 UW |
9977 | /* Return the OBJFILE associated with the compilation unit CU. */ |
9978 | ||
9979 | struct objfile * | |
9980 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
9981 | { | |
9982 | struct objfile *objfile = per_cu->psymtab->objfile; | |
9983 | ||
9984 | /* Return the master objfile, so that we can report and look up the | |
9985 | correct file containing this variable. */ | |
9986 | if (objfile->separate_debug_objfile_backlink) | |
9987 | objfile = objfile->separate_debug_objfile_backlink; | |
9988 | ||
9989 | return objfile; | |
9990 | } | |
9991 | ||
9992 | /* Return the address size given in the compilation unit header for CU. */ | |
9993 | ||
9994 | CORE_ADDR | |
9995 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
9996 | { | |
9997 | if (per_cu->cu) | |
9998 | return per_cu->cu->header.addr_size; | |
9999 | else | |
10000 | { | |
10001 | /* If the CU is not currently read in, we re-read its header. */ | |
10002 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10003 | struct dwarf2_per_objfile *per_objfile | |
10004 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
10005 | gdb_byte *info_ptr = per_objfile->info_buffer + per_cu->offset; | |
10006 | ||
10007 | struct comp_unit_head cu_header; | |
10008 | memset (&cu_header, 0, sizeof cu_header); | |
10009 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
10010 | return cu_header.addr_size; | |
10011 | } | |
10012 | } | |
10013 | ||
ae038cb0 | 10014 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 10015 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
10016 | |
10017 | static struct dwarf2_per_cu_data * | |
10018 | dwarf2_find_containing_comp_unit (unsigned long offset, | |
10019 | struct objfile *objfile) | |
10020 | { | |
10021 | struct dwarf2_per_cu_data *this_cu; | |
10022 | int low, high; | |
10023 | ||
ae038cb0 DJ |
10024 | low = 0; |
10025 | high = dwarf2_per_objfile->n_comp_units - 1; | |
10026 | while (high > low) | |
10027 | { | |
10028 | int mid = low + (high - low) / 2; | |
10029 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
10030 | high = mid; | |
10031 | else | |
10032 | low = mid + 1; | |
10033 | } | |
10034 | gdb_assert (low == high); | |
10035 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
10036 | { | |
10b3939b | 10037 | if (low == 0) |
8a3fe4f8 AC |
10038 | error (_("Dwarf Error: could not find partial DIE containing " |
10039 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
10040 | (long) offset, bfd_get_filename (objfile->obfd)); |
10041 | ||
ae038cb0 DJ |
10042 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
10043 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
10044 | } | |
10045 | else | |
10046 | { | |
10047 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
10048 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
10049 | && offset >= this_cu->offset + this_cu->length) | |
8a3fe4f8 | 10050 | error (_("invalid dwarf2 offset %ld"), offset); |
ae038cb0 DJ |
10051 | gdb_assert (offset < this_cu->offset + this_cu->length); |
10052 | return this_cu; | |
10053 | } | |
10054 | } | |
10055 | ||
10b3939b DJ |
10056 | /* Locate the compilation unit from OBJFILE which is located at exactly |
10057 | OFFSET. Raises an error on failure. */ | |
10058 | ||
ae038cb0 DJ |
10059 | static struct dwarf2_per_cu_data * |
10060 | dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile) | |
10061 | { | |
10062 | struct dwarf2_per_cu_data *this_cu; | |
10063 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
10064 | if (this_cu->offset != offset) | |
8a3fe4f8 | 10065 | error (_("no compilation unit with offset %ld."), offset); |
ae038cb0 DJ |
10066 | return this_cu; |
10067 | } | |
10068 | ||
10069 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
10070 | of compilation units, but we don't remove it from the read_in_chain; | |
10071 | the caller is responsible for that. */ | |
10072 | ||
10073 | static void | |
10074 | free_one_comp_unit (void *data) | |
10075 | { | |
10076 | struct dwarf2_cu *cu = data; | |
10077 | ||
10078 | if (cu->per_cu != NULL) | |
10079 | cu->per_cu->cu = NULL; | |
10080 | cu->per_cu = NULL; | |
10081 | ||
10082 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10083 | ||
10084 | xfree (cu); | |
10085 | } | |
10086 | ||
72bf9492 | 10087 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
10088 | when we're finished with it. We can't free the pointer itself, but be |
10089 | sure to unlink it from the cache. Also release any associated storage | |
10090 | and perform cache maintenance. | |
72bf9492 DJ |
10091 | |
10092 | Only used during partial symbol parsing. */ | |
10093 | ||
10094 | static void | |
10095 | free_stack_comp_unit (void *data) | |
10096 | { | |
10097 | struct dwarf2_cu *cu = data; | |
10098 | ||
10099 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10100 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
10101 | |
10102 | if (cu->per_cu != NULL) | |
10103 | { | |
10104 | /* This compilation unit is on the stack in our caller, so we | |
10105 | should not xfree it. Just unlink it. */ | |
10106 | cu->per_cu->cu = NULL; | |
10107 | cu->per_cu = NULL; | |
10108 | ||
10109 | /* If we had a per-cu pointer, then we may have other compilation | |
10110 | units loaded, so age them now. */ | |
10111 | age_cached_comp_units (); | |
10112 | } | |
10113 | } | |
10114 | ||
10115 | /* Free all cached compilation units. */ | |
10116 | ||
10117 | static void | |
10118 | free_cached_comp_units (void *data) | |
10119 | { | |
10120 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10121 | ||
10122 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10123 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10124 | while (per_cu != NULL) | |
10125 | { | |
10126 | struct dwarf2_per_cu_data *next_cu; | |
10127 | ||
10128 | next_cu = per_cu->cu->read_in_chain; | |
10129 | ||
10130 | free_one_comp_unit (per_cu->cu); | |
10131 | *last_chain = next_cu; | |
10132 | ||
10133 | per_cu = next_cu; | |
10134 | } | |
10135 | } | |
10136 | ||
10137 | /* Increase the age counter on each cached compilation unit, and free | |
10138 | any that are too old. */ | |
10139 | ||
10140 | static void | |
10141 | age_cached_comp_units (void) | |
10142 | { | |
10143 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10144 | ||
10145 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
10146 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10147 | while (per_cu != NULL) | |
10148 | { | |
10149 | per_cu->cu->last_used ++; | |
10150 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
10151 | dwarf2_mark (per_cu->cu); | |
10152 | per_cu = per_cu->cu->read_in_chain; | |
10153 | } | |
10154 | ||
10155 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10156 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10157 | while (per_cu != NULL) | |
10158 | { | |
10159 | struct dwarf2_per_cu_data *next_cu; | |
10160 | ||
10161 | next_cu = per_cu->cu->read_in_chain; | |
10162 | ||
10163 | if (!per_cu->cu->mark) | |
10164 | { | |
10165 | free_one_comp_unit (per_cu->cu); | |
10166 | *last_chain = next_cu; | |
10167 | } | |
10168 | else | |
10169 | last_chain = &per_cu->cu->read_in_chain; | |
10170 | ||
10171 | per_cu = next_cu; | |
10172 | } | |
10173 | } | |
10174 | ||
10175 | /* Remove a single compilation unit from the cache. */ | |
10176 | ||
10177 | static void | |
10178 | free_one_cached_comp_unit (void *target_cu) | |
10179 | { | |
10180 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10181 | ||
10182 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10183 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10184 | while (per_cu != NULL) | |
10185 | { | |
10186 | struct dwarf2_per_cu_data *next_cu; | |
10187 | ||
10188 | next_cu = per_cu->cu->read_in_chain; | |
10189 | ||
10190 | if (per_cu->cu == target_cu) | |
10191 | { | |
10192 | free_one_comp_unit (per_cu->cu); | |
10193 | *last_chain = next_cu; | |
10194 | break; | |
10195 | } | |
10196 | else | |
10197 | last_chain = &per_cu->cu->read_in_chain; | |
10198 | ||
10199 | per_cu = next_cu; | |
10200 | } | |
10201 | } | |
10202 | ||
fe3e1990 DJ |
10203 | /* Release all extra memory associated with OBJFILE. */ |
10204 | ||
10205 | void | |
10206 | dwarf2_free_objfile (struct objfile *objfile) | |
10207 | { | |
10208 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10209 | ||
10210 | if (dwarf2_per_objfile == NULL) | |
10211 | return; | |
10212 | ||
10213 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
10214 | free_cached_comp_units (NULL); | |
10215 | ||
10216 | /* Everything else should be on the objfile obstack. */ | |
10217 | } | |
10218 | ||
1c379e20 DJ |
10219 | /* A pair of DIE offset and GDB type pointer. We store these |
10220 | in a hash table separate from the DIEs, and preserve them | |
10221 | when the DIEs are flushed out of cache. */ | |
10222 | ||
10223 | struct dwarf2_offset_and_type | |
10224 | { | |
10225 | unsigned int offset; | |
10226 | struct type *type; | |
10227 | }; | |
10228 | ||
10229 | /* Hash function for a dwarf2_offset_and_type. */ | |
10230 | ||
10231 | static hashval_t | |
10232 | offset_and_type_hash (const void *item) | |
10233 | { | |
10234 | const struct dwarf2_offset_and_type *ofs = item; | |
10235 | return ofs->offset; | |
10236 | } | |
10237 | ||
10238 | /* Equality function for a dwarf2_offset_and_type. */ | |
10239 | ||
10240 | static int | |
10241 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
10242 | { | |
10243 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
10244 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
10245 | return ofs_lhs->offset == ofs_rhs->offset; | |
10246 | } | |
10247 | ||
10248 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 10249 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 10250 | |
f792889a | 10251 | static struct type * |
1c379e20 DJ |
10252 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
10253 | { | |
10254 | struct dwarf2_offset_and_type **slot, ofs; | |
10255 | ||
f792889a DJ |
10256 | if (cu->type_hash == NULL) |
10257 | { | |
10258 | gdb_assert (cu->per_cu != NULL); | |
10259 | cu->per_cu->type_hash | |
10260 | = htab_create_alloc_ex (cu->header.length / 24, | |
10261 | offset_and_type_hash, | |
10262 | offset_and_type_eq, | |
10263 | NULL, | |
10264 | &cu->objfile->objfile_obstack, | |
10265 | hashtab_obstack_allocate, | |
10266 | dummy_obstack_deallocate); | |
10267 | cu->type_hash = cu->per_cu->type_hash; | |
10268 | } | |
1c379e20 DJ |
10269 | |
10270 | ofs.offset = die->offset; | |
10271 | ofs.type = type; | |
10272 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 10273 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
10274 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
10275 | **slot = ofs; | |
f792889a | 10276 | return type; |
1c379e20 DJ |
10277 | } |
10278 | ||
f792889a DJ |
10279 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
10280 | not have a saved type. */ | |
1c379e20 DJ |
10281 | |
10282 | static struct type * | |
f792889a | 10283 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
10284 | { |
10285 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
10286 | htab_t type_hash = cu->type_hash; |
10287 | ||
10288 | if (type_hash == NULL) | |
10289 | return NULL; | |
1c379e20 DJ |
10290 | |
10291 | ofs.offset = die->offset; | |
10292 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
10293 | if (slot) | |
10294 | return slot->type; | |
10295 | else | |
10296 | return NULL; | |
10297 | } | |
10298 | ||
10b3939b DJ |
10299 | /* Set the mark field in CU and in every other compilation unit in the |
10300 | cache that we must keep because we are keeping CU. */ | |
10301 | ||
10302 | /* Add a dependence relationship from CU to REF_PER_CU. */ | |
10303 | ||
10304 | static void | |
10305 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
10306 | struct dwarf2_per_cu_data *ref_per_cu) | |
10307 | { | |
10308 | void **slot; | |
10309 | ||
10310 | if (cu->dependencies == NULL) | |
10311 | cu->dependencies | |
10312 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
10313 | NULL, &cu->comp_unit_obstack, | |
10314 | hashtab_obstack_allocate, | |
10315 | dummy_obstack_deallocate); | |
10316 | ||
10317 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
10318 | if (*slot == NULL) | |
10319 | *slot = ref_per_cu; | |
10320 | } | |
1c379e20 | 10321 | |
ae038cb0 DJ |
10322 | /* Set the mark field in CU and in every other compilation unit in the |
10323 | cache that we must keep because we are keeping CU. */ | |
10324 | ||
10b3939b DJ |
10325 | static int |
10326 | dwarf2_mark_helper (void **slot, void *data) | |
10327 | { | |
10328 | struct dwarf2_per_cu_data *per_cu; | |
10329 | ||
10330 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
10331 | if (per_cu->cu->mark) | |
10332 | return 1; | |
10333 | per_cu->cu->mark = 1; | |
10334 | ||
10335 | if (per_cu->cu->dependencies != NULL) | |
10336 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
10337 | ||
10338 | return 1; | |
10339 | } | |
10340 | ||
ae038cb0 DJ |
10341 | static void |
10342 | dwarf2_mark (struct dwarf2_cu *cu) | |
10343 | { | |
10344 | if (cu->mark) | |
10345 | return; | |
10346 | cu->mark = 1; | |
10b3939b DJ |
10347 | if (cu->dependencies != NULL) |
10348 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
10349 | } |
10350 | ||
10351 | static void | |
10352 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
10353 | { | |
10354 | while (per_cu) | |
10355 | { | |
10356 | per_cu->cu->mark = 0; | |
10357 | per_cu = per_cu->cu->read_in_chain; | |
10358 | } | |
72bf9492 DJ |
10359 | } |
10360 | ||
72bf9492 DJ |
10361 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10362 | is its offset in .debug_info for this objfile. */ | |
10363 | ||
10364 | static hashval_t | |
10365 | partial_die_hash (const void *item) | |
10366 | { | |
10367 | const struct partial_die_info *part_die = item; | |
10368 | return part_die->offset; | |
10369 | } | |
10370 | ||
10371 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10372 | are equal if they have the same offset. */ | |
10373 | ||
10374 | static int | |
10375 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10376 | { | |
10377 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10378 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10379 | return part_die_lhs->offset == part_die_rhs->offset; | |
10380 | } | |
10381 | ||
ae038cb0 DJ |
10382 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10383 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10384 | ||
10385 | static void | |
10386 | set_dwarf2_cmd (char *args, int from_tty) | |
10387 | { | |
10388 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10389 | } | |
10390 | ||
10391 | static void | |
10392 | show_dwarf2_cmd (char *args, int from_tty) | |
10393 | { | |
10394 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10395 | } | |
10396 | ||
6502dd73 DJ |
10397 | void _initialize_dwarf2_read (void); |
10398 | ||
10399 | void | |
10400 | _initialize_dwarf2_read (void) | |
10401 | { | |
10402 | dwarf2_objfile_data_key = register_objfile_data (); | |
ae038cb0 | 10403 | |
1bedd215 AC |
10404 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10405 | Set DWARF 2 specific variables.\n\ | |
10406 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10407 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10408 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10409 | ||
1bedd215 AC |
10410 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10411 | Show DWARF 2 specific variables\n\ | |
10412 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10413 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10414 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10415 | ||
10416 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10417 | &dwarf2_max_cache_age, _("\ |
10418 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10419 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10420 | A higher limit means that cached compilation units will be stored\n\ | |
10421 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10422 | caching, which can slow down startup."), | |
2c5b56ce | 10423 | NULL, |
920d2a44 | 10424 | show_dwarf2_max_cache_age, |
2c5b56ce | 10425 | &set_dwarf2_cmdlist, |
ae038cb0 | 10426 | &show_dwarf2_cmdlist); |
6502dd73 | 10427 | } |