]>
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 ([email protected]), 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 | |
10b3939b DJ |
262 | /* Fixed size for the DIE hash table. */ |
263 | #ifndef REF_HASH_SIZE | |
264 | #define REF_HASH_SIZE 1021 | |
265 | #endif | |
266 | ||
e7c27a73 DJ |
267 | /* Internal state when decoding a particular compilation unit. */ |
268 | struct dwarf2_cu | |
269 | { | |
270 | /* The objfile containing this compilation unit. */ | |
271 | struct objfile *objfile; | |
272 | ||
273 | /* The header of the compilation unit. | |
274 | ||
275 | FIXME drow/2003-11-10: Some of the things from the comp_unit_head | |
f3dd6933 | 276 | should logically be moved to the dwarf2_cu structure. */ |
e7c27a73 | 277 | struct comp_unit_head header; |
e142c38c DJ |
278 | |
279 | struct function_range *first_fn, *last_fn, *cached_fn; | |
280 | ||
281 | /* The language we are debugging. */ | |
282 | enum language language; | |
283 | const struct language_defn *language_defn; | |
284 | ||
b0f35d58 DL |
285 | const char *producer; |
286 | ||
e142c38c DJ |
287 | /* The generic symbol table building routines have separate lists for |
288 | file scope symbols and all all other scopes (local scopes). So | |
289 | we need to select the right one to pass to add_symbol_to_list(). | |
290 | We do it by keeping a pointer to the correct list in list_in_scope. | |
291 | ||
292 | FIXME: The original dwarf code just treated the file scope as the | |
293 | first local scope, and all other local scopes as nested local | |
294 | scopes, and worked fine. Check to see if we really need to | |
295 | distinguish these in buildsym.c. */ | |
296 | struct pending **list_in_scope; | |
297 | ||
f3dd6933 DJ |
298 | /* DWARF abbreviation table associated with this compilation unit. */ |
299 | struct abbrev_info **dwarf2_abbrevs; | |
300 | ||
301 | /* Storage for the abbrev table. */ | |
302 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
303 | |
304 | /* Hash table holding all the loaded partial DIEs. */ | |
305 | htab_t partial_dies; | |
306 | ||
ff013f42 JK |
307 | /* `.debug_ranges' offset for this `DW_TAG_compile_unit' DIE. */ |
308 | unsigned long ranges_offset; | |
309 | ||
72bf9492 DJ |
310 | /* Storage for things with the same lifetime as this read-in compilation |
311 | unit, including partial DIEs. */ | |
312 | struct obstack comp_unit_obstack; | |
313 | ||
ae038cb0 DJ |
314 | /* When multiple dwarf2_cu structures are living in memory, this field |
315 | chains them all together, so that they can be released efficiently. | |
316 | We will probably also want a generation counter so that most-recently-used | |
317 | compilation units are cached... */ | |
318 | struct dwarf2_per_cu_data *read_in_chain; | |
319 | ||
320 | /* Backchain to our per_cu entry if the tree has been built. */ | |
321 | struct dwarf2_per_cu_data *per_cu; | |
322 | ||
f792889a DJ |
323 | /* Pointer to the die -> type map. Although it is stored |
324 | permanently in per_cu, we copy it here to avoid double | |
325 | indirection. */ | |
326 | htab_t type_hash; | |
327 | ||
ae038cb0 DJ |
328 | /* How many compilation units ago was this CU last referenced? */ |
329 | int last_used; | |
330 | ||
10b3939b DJ |
331 | /* A hash table of die offsets for following references. */ |
332 | struct die_info *die_ref_table[REF_HASH_SIZE]; | |
333 | ||
334 | /* Full DIEs if read in. */ | |
335 | struct die_info *dies; | |
336 | ||
337 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
338 | units referenced by this one. Only set during full symbol processing; | |
339 | partial symbol tables do not have dependencies. */ | |
340 | htab_t dependencies; | |
341 | ||
cb1df416 DJ |
342 | /* Header data from the line table, during full symbol processing. */ |
343 | struct line_header *line_header; | |
344 | ||
ae038cb0 DJ |
345 | /* Mark used when releasing cached dies. */ |
346 | unsigned int mark : 1; | |
347 | ||
348 | /* This flag will be set if this compilation unit might include | |
349 | inter-compilation-unit references. */ | |
350 | unsigned int has_form_ref_addr : 1; | |
351 | ||
72bf9492 DJ |
352 | /* This flag will be set if this compilation unit includes any |
353 | DW_TAG_namespace DIEs. If we know that there are explicit | |
354 | DIEs for namespaces, we don't need to try to infer them | |
355 | from mangled names. */ | |
356 | unsigned int has_namespace_info : 1; | |
ff013f42 JK |
357 | |
358 | /* Field `ranges_offset' is filled in; flag as the value may be zero. */ | |
359 | unsigned int has_ranges_offset : 1; | |
e7c27a73 DJ |
360 | }; |
361 | ||
10b3939b DJ |
362 | /* Persistent data held for a compilation unit, even when not |
363 | processing it. We put a pointer to this structure in the | |
364 | read_symtab_private field of the psymtab. If we encounter | |
365 | inter-compilation-unit references, we also maintain a sorted | |
366 | list of all compilation units. */ | |
367 | ||
ae038cb0 DJ |
368 | struct dwarf2_per_cu_data |
369 | { | |
5afb4e99 | 370 | /* The start offset and length of this compilation unit. 2**30-1 |
ae038cb0 DJ |
371 | bytes should suffice to store the length of any compilation unit |
372 | - if it doesn't, GDB will fall over anyway. */ | |
373 | unsigned long offset; | |
5afb4e99 | 374 | unsigned long length : 30; |
ae038cb0 DJ |
375 | |
376 | /* Flag indicating this compilation unit will be read in before | |
377 | any of the current compilation units are processed. */ | |
378 | unsigned long queued : 1; | |
379 | ||
5afb4e99 DJ |
380 | /* This flag will be set if we need to load absolutely all DIEs |
381 | for this compilation unit, instead of just the ones we think | |
382 | are interesting. It gets set if we look for a DIE in the | |
383 | hash table and don't find it. */ | |
384 | unsigned int load_all_dies : 1; | |
385 | ||
ae038cb0 DJ |
386 | /* Set iff currently read in. */ |
387 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
388 | |
389 | /* If full symbols for this CU have been read in, then this field | |
390 | holds a map of DIE offsets to types. It isn't always possible | |
391 | to reconstruct this information later, so we have to preserve | |
392 | it. */ | |
1c379e20 | 393 | htab_t type_hash; |
10b3939b | 394 | |
31ffec48 DJ |
395 | /* The partial symbol table associated with this compilation unit, |
396 | or NULL for partial units (which do not have an associated | |
397 | symtab). */ | |
10b3939b | 398 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
399 | }; |
400 | ||
debd256d JB |
401 | /* The line number information for a compilation unit (found in the |
402 | .debug_line section) begins with a "statement program header", | |
403 | which contains the following information. */ | |
404 | struct line_header | |
405 | { | |
406 | unsigned int total_length; | |
407 | unsigned short version; | |
408 | unsigned int header_length; | |
409 | unsigned char minimum_instruction_length; | |
410 | unsigned char default_is_stmt; | |
411 | int line_base; | |
412 | unsigned char line_range; | |
413 | unsigned char opcode_base; | |
414 | ||
415 | /* standard_opcode_lengths[i] is the number of operands for the | |
416 | standard opcode whose value is i. This means that | |
417 | standard_opcode_lengths[0] is unused, and the last meaningful | |
418 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
419 | unsigned char *standard_opcode_lengths; | |
420 | ||
421 | /* The include_directories table. NOTE! These strings are not | |
422 | allocated with xmalloc; instead, they are pointers into | |
423 | debug_line_buffer. If you try to free them, `free' will get | |
424 | indigestion. */ | |
425 | unsigned int num_include_dirs, include_dirs_size; | |
426 | char **include_dirs; | |
427 | ||
428 | /* The file_names table. NOTE! These strings are not allocated | |
429 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
430 | Don't try to free them directly. */ | |
431 | unsigned int num_file_names, file_names_size; | |
432 | struct file_entry | |
c906108c | 433 | { |
debd256d JB |
434 | char *name; |
435 | unsigned int dir_index; | |
436 | unsigned int mod_time; | |
437 | unsigned int length; | |
aaa75496 | 438 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
cb1df416 | 439 | struct symtab *symtab; /* The associated symbol table, if any. */ |
debd256d JB |
440 | } *file_names; |
441 | ||
442 | /* The start and end of the statement program following this | |
6502dd73 | 443 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 444 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 445 | }; |
c906108c SS |
446 | |
447 | /* When we construct a partial symbol table entry we only | |
448 | need this much information. */ | |
449 | struct partial_die_info | |
450 | { | |
72bf9492 | 451 | /* Offset of this DIE. */ |
c906108c | 452 | unsigned int offset; |
72bf9492 DJ |
453 | |
454 | /* DWARF-2 tag for this DIE. */ | |
455 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
456 | ||
457 | /* Language code associated with this DIE. This is only used | |
458 | for the compilation unit DIE. */ | |
459 | unsigned int language : 8; | |
460 | ||
461 | /* Assorted flags describing the data found in this DIE. */ | |
462 | unsigned int has_children : 1; | |
463 | unsigned int is_external : 1; | |
464 | unsigned int is_declaration : 1; | |
465 | unsigned int has_type : 1; | |
466 | unsigned int has_specification : 1; | |
aaa75496 | 467 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
468 | unsigned int has_pc_info : 1; |
469 | ||
470 | /* Flag set if the SCOPE field of this structure has been | |
471 | computed. */ | |
472 | unsigned int scope_set : 1; | |
473 | ||
fa4028e9 JB |
474 | /* Flag set if the DIE has a byte_size attribute. */ |
475 | unsigned int has_byte_size : 1; | |
476 | ||
72bf9492 DJ |
477 | /* The name of this DIE. Normally the value of DW_AT_name, but |
478 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
479 | other fashion. */ | |
c906108c | 480 | char *name; |
57c22c6c | 481 | char *dirname; |
72bf9492 DJ |
482 | |
483 | /* The scope to prepend to our children. This is generally | |
484 | allocated on the comp_unit_obstack, so will disappear | |
485 | when this compilation unit leaves the cache. */ | |
486 | char *scope; | |
487 | ||
488 | /* The location description associated with this DIE, if any. */ | |
489 | struct dwarf_block *locdesc; | |
490 | ||
491 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
492 | CORE_ADDR lowpc; |
493 | CORE_ADDR highpc; | |
72bf9492 DJ |
494 | |
495 | /* Pointer into the info_buffer pointing at the target of | |
496 | DW_AT_sibling, if any. */ | |
fe1b8b76 | 497 | gdb_byte *sibling; |
72bf9492 DJ |
498 | |
499 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
500 | DW_AT_specification (or DW_AT_abstract_origin or | |
501 | DW_AT_extension). */ | |
502 | unsigned int spec_offset; | |
503 | ||
aaa75496 JB |
504 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
505 | unsigned int line_offset; | |
506 | ||
72bf9492 DJ |
507 | /* Pointers to this DIE's parent, first child, and next sibling, |
508 | if any. */ | |
509 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
510 | }; |
511 | ||
512 | /* This data structure holds the information of an abbrev. */ | |
513 | struct abbrev_info | |
514 | { | |
515 | unsigned int number; /* number identifying abbrev */ | |
516 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
517 | unsigned short has_children; /* boolean */ |
518 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
519 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
520 | struct abbrev_info *next; /* next in chain */ | |
521 | }; | |
522 | ||
523 | struct attr_abbrev | |
524 | { | |
525 | enum dwarf_attribute name; | |
526 | enum dwarf_form form; | |
527 | }; | |
528 | ||
529 | /* This data structure holds a complete die structure. */ | |
530 | struct die_info | |
531 | { | |
c5aa993b | 532 | enum dwarf_tag tag; /* Tag indicating type of die */ |
c5aa993b JM |
533 | unsigned int abbrev; /* Abbrev number */ |
534 | unsigned int offset; /* Offset in .debug_info section */ | |
535 | unsigned int num_attrs; /* Number of attributes */ | |
536 | struct attribute *attrs; /* An array of attributes */ | |
537 | struct die_info *next_ref; /* Next die in ref hash table */ | |
78ba4af6 JB |
538 | |
539 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
540 | points to this die's parent; CHILD points to the first child of | |
541 | this node; and all the children of a given node are chained | |
542 | together via their SIBLING fields, terminated by a die whose | |
543 | tag is zero. */ | |
639d11d3 DC |
544 | struct die_info *child; /* Its first child, if any. */ |
545 | struct die_info *sibling; /* Its next sibling, if any. */ | |
546 | struct die_info *parent; /* Its parent, if any. */ | |
c906108c SS |
547 | }; |
548 | ||
549 | /* Attributes have a name and a value */ | |
550 | struct attribute | |
551 | { | |
552 | enum dwarf_attribute name; | |
553 | enum dwarf_form form; | |
554 | union | |
555 | { | |
556 | char *str; | |
557 | struct dwarf_block *blk; | |
ce5d95e1 JB |
558 | unsigned long unsnd; |
559 | long int snd; | |
c906108c SS |
560 | CORE_ADDR addr; |
561 | } | |
562 | u; | |
563 | }; | |
564 | ||
5fb290d7 DJ |
565 | struct function_range |
566 | { | |
567 | const char *name; | |
568 | CORE_ADDR lowpc, highpc; | |
569 | int seen_line; | |
570 | struct function_range *next; | |
571 | }; | |
572 | ||
c906108c SS |
573 | /* Get at parts of an attribute structure */ |
574 | ||
575 | #define DW_STRING(attr) ((attr)->u.str) | |
576 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
577 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
578 | #define DW_SND(attr) ((attr)->u.snd) | |
579 | #define DW_ADDR(attr) ((attr)->u.addr) | |
580 | ||
581 | /* Blocks are a bunch of untyped bytes. */ | |
582 | struct dwarf_block | |
583 | { | |
584 | unsigned int size; | |
fe1b8b76 | 585 | gdb_byte *data; |
c906108c SS |
586 | }; |
587 | ||
c906108c SS |
588 | #ifndef ATTR_ALLOC_CHUNK |
589 | #define ATTR_ALLOC_CHUNK 4 | |
590 | #endif | |
591 | ||
c906108c SS |
592 | /* Allocate fields for structs, unions and enums in this size. */ |
593 | #ifndef DW_FIELD_ALLOC_CHUNK | |
594 | #define DW_FIELD_ALLOC_CHUNK 4 | |
595 | #endif | |
596 | ||
c906108c SS |
597 | /* A zeroed version of a partial die for initialization purposes. */ |
598 | static struct partial_die_info zeroed_partial_die; | |
599 | ||
c906108c SS |
600 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
601 | but this would require a corresponding change in unpack_field_as_long | |
602 | and friends. */ | |
603 | static int bits_per_byte = 8; | |
604 | ||
605 | /* The routines that read and process dies for a C struct or C++ class | |
606 | pass lists of data member fields and lists of member function fields | |
607 | in an instance of a field_info structure, as defined below. */ | |
608 | struct field_info | |
c5aa993b JM |
609 | { |
610 | /* List of data member and baseclasses fields. */ | |
611 | struct nextfield | |
612 | { | |
613 | struct nextfield *next; | |
614 | int accessibility; | |
615 | int virtuality; | |
616 | struct field field; | |
617 | } | |
618 | *fields; | |
c906108c | 619 | |
c5aa993b JM |
620 | /* Number of fields. */ |
621 | int nfields; | |
c906108c | 622 | |
c5aa993b JM |
623 | /* Number of baseclasses. */ |
624 | int nbaseclasses; | |
c906108c | 625 | |
c5aa993b JM |
626 | /* Set if the accesibility of one of the fields is not public. */ |
627 | int non_public_fields; | |
c906108c | 628 | |
c5aa993b JM |
629 | /* Member function fields array, entries are allocated in the order they |
630 | are encountered in the object file. */ | |
631 | struct nextfnfield | |
632 | { | |
633 | struct nextfnfield *next; | |
634 | struct fn_field fnfield; | |
635 | } | |
636 | *fnfields; | |
c906108c | 637 | |
c5aa993b JM |
638 | /* Member function fieldlist array, contains name of possibly overloaded |
639 | member function, number of overloaded member functions and a pointer | |
640 | to the head of the member function field chain. */ | |
641 | struct fnfieldlist | |
642 | { | |
643 | char *name; | |
644 | int length; | |
645 | struct nextfnfield *head; | |
646 | } | |
647 | *fnfieldlists; | |
c906108c | 648 | |
c5aa993b JM |
649 | /* Number of entries in the fnfieldlists array. */ |
650 | int nfnfields; | |
651 | }; | |
c906108c | 652 | |
10b3939b DJ |
653 | /* One item on the queue of compilation units to read in full symbols |
654 | for. */ | |
655 | struct dwarf2_queue_item | |
656 | { | |
657 | struct dwarf2_per_cu_data *per_cu; | |
658 | struct dwarf2_queue_item *next; | |
659 | }; | |
660 | ||
661 | /* The current queue. */ | |
662 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
663 | ||
ae038cb0 DJ |
664 | /* Loaded secondary compilation units are kept in memory until they |
665 | have not been referenced for the processing of this many | |
666 | compilation units. Set this to zero to disable caching. Cache | |
667 | sizes of up to at least twenty will improve startup time for | |
668 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
669 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
670 | static void |
671 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
672 | struct cmd_list_element *c, const char *value) | |
673 | { | |
674 | fprintf_filtered (file, _("\ | |
675 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
676 | value); | |
677 | } | |
678 | ||
ae038cb0 | 679 | |
c906108c SS |
680 | /* Various complaints about symbol reading that don't abort the process */ |
681 | ||
4d3c2250 KB |
682 | static void |
683 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 684 | { |
4d3c2250 | 685 | complaint (&symfile_complaints, |
e2e0b3e5 | 686 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
687 | } |
688 | ||
25e43795 DJ |
689 | static void |
690 | dwarf2_debug_line_missing_file_complaint (void) | |
691 | { | |
692 | complaint (&symfile_complaints, | |
693 | _(".debug_line section has line data without a file")); | |
694 | } | |
695 | ||
4d3c2250 KB |
696 | static void |
697 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 698 | { |
e2e0b3e5 | 699 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
700 | } |
701 | ||
4d3c2250 KB |
702 | static void |
703 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
704 | int arg3) | |
2e276125 | 705 | { |
4d3c2250 | 706 | complaint (&symfile_complaints, |
e2e0b3e5 | 707 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
708 | arg2, arg3); |
709 | } | |
710 | ||
711 | static void | |
712 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 713 | { |
4d3c2250 | 714 | complaint (&symfile_complaints, |
e2e0b3e5 | 715 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
716 | } |
717 | ||
718 | static void | |
719 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 720 | { |
4d3c2250 | 721 | complaint (&symfile_complaints, |
e2e0b3e5 | 722 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
723 | arg1); |
724 | } | |
725 | ||
726 | static void | |
727 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 728 | { |
4d3c2250 | 729 | complaint (&symfile_complaints, |
e2e0b3e5 | 730 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 731 | } |
c906108c | 732 | |
c906108c SS |
733 | /* local function prototypes */ |
734 | ||
4efb68b1 | 735 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
736 | |
737 | #if 0 | |
a14ed312 | 738 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
739 | #endif |
740 | ||
aaa75496 JB |
741 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
742 | struct objfile *); | |
743 | ||
744 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
745 | struct partial_die_info *, | |
746 | struct partial_symtab *); | |
747 | ||
a14ed312 | 748 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 749 | |
72bf9492 DJ |
750 | static void scan_partial_symbols (struct partial_die_info *, |
751 | CORE_ADDR *, CORE_ADDR *, | |
752 | struct dwarf2_cu *); | |
c906108c | 753 | |
72bf9492 DJ |
754 | static void add_partial_symbol (struct partial_die_info *, |
755 | struct dwarf2_cu *); | |
63d06c5c | 756 | |
72bf9492 | 757 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 758 | |
72bf9492 DJ |
759 | static void add_partial_namespace (struct partial_die_info *pdi, |
760 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
761 | struct dwarf2_cu *cu); | |
63d06c5c | 762 | |
72bf9492 DJ |
763 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
764 | struct dwarf2_cu *cu); | |
91c24f0a | 765 | |
fe1b8b76 JB |
766 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
767 | gdb_byte *info_ptr, | |
768 | bfd *abfd, | |
769 | struct dwarf2_cu *cu); | |
91c24f0a | 770 | |
a14ed312 | 771 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 772 | |
a14ed312 | 773 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 774 | |
fe1b8b76 | 775 | gdb_byte *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 776 | |
e7c27a73 | 777 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 778 | |
f3dd6933 | 779 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 780 | |
fe1b8b76 | 781 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 782 | struct dwarf2_cu *); |
72bf9492 | 783 | |
57349743 | 784 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 785 | struct dwarf2_cu *); |
c906108c | 786 | |
fe1b8b76 | 787 | static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int, |
72bf9492 DJ |
788 | struct dwarf2_cu *); |
789 | ||
fe1b8b76 JB |
790 | static gdb_byte *read_partial_die (struct partial_die_info *, |
791 | struct abbrev_info *abbrev, unsigned int, | |
792 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 793 | |
72bf9492 | 794 | static struct partial_die_info *find_partial_die (unsigned long, |
10b3939b | 795 | struct dwarf2_cu *); |
72bf9492 DJ |
796 | |
797 | static void fixup_partial_die (struct partial_die_info *, | |
798 | struct dwarf2_cu *); | |
799 | ||
fe1b8b76 JB |
800 | static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *, |
801 | struct dwarf2_cu *, int *); | |
c906108c | 802 | |
fe1b8b76 JB |
803 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
804 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 805 | |
fe1b8b76 JB |
806 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
807 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 808 | |
fe1b8b76 | 809 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 810 | |
fe1b8b76 | 811 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 812 | |
fe1b8b76 | 813 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 814 | |
fe1b8b76 | 815 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 816 | |
fe1b8b76 | 817 | static unsigned long read_8_bytes (bfd *, gdb_byte *); |
c906108c | 818 | |
fe1b8b76 | 819 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 820 | unsigned int *); |
c906108c | 821 | |
fe1b8b76 | 822 | static LONGEST read_initial_length (bfd *, gdb_byte *, |
891d2f0b | 823 | struct comp_unit_head *, unsigned int *); |
613e1657 | 824 | |
fe1b8b76 | 825 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
891d2f0b | 826 | unsigned int *); |
613e1657 | 827 | |
fe1b8b76 | 828 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 829 | |
fe1b8b76 | 830 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 831 | |
fe1b8b76 JB |
832 | static char *read_indirect_string (bfd *, gdb_byte *, |
833 | const struct comp_unit_head *, | |
834 | unsigned int *); | |
4bdf3d34 | 835 | |
fe1b8b76 | 836 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 837 | |
fe1b8b76 | 838 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 839 | |
fe1b8b76 | 840 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 841 | |
e142c38c | 842 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 843 | |
e142c38c DJ |
844 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
845 | struct dwarf2_cu *); | |
c906108c | 846 | |
05cf31d1 JB |
847 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
848 | struct dwarf2_cu *cu); | |
849 | ||
e142c38c | 850 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 851 | |
e142c38c DJ |
852 | static struct die_info *die_specification (struct die_info *die, |
853 | struct dwarf2_cu *); | |
63d06c5c | 854 | |
debd256d JB |
855 | static void free_line_header (struct line_header *lh); |
856 | ||
aaa75496 JB |
857 | static void add_file_name (struct line_header *, char *, unsigned int, |
858 | unsigned int, unsigned int); | |
859 | ||
debd256d JB |
860 | static struct line_header *(dwarf_decode_line_header |
861 | (unsigned int offset, | |
e7c27a73 | 862 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
863 | |
864 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 865 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 866 | |
4f1520fb | 867 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 868 | |
a14ed312 | 869 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 870 | struct dwarf2_cu *); |
c906108c | 871 | |
a14ed312 | 872 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 873 | struct dwarf2_cu *); |
c906108c | 874 | |
2df3850c JM |
875 | static void dwarf2_const_value_data (struct attribute *attr, |
876 | struct symbol *sym, | |
877 | int bits); | |
878 | ||
e7c27a73 | 879 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 880 | |
e7c27a73 DJ |
881 | static struct type *die_containing_type (struct die_info *, |
882 | struct dwarf2_cu *); | |
c906108c | 883 | |
e7c27a73 | 884 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 885 | |
f792889a | 886 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 887 | |
086ed43d | 888 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 889 | |
fe1b8b76 JB |
890 | static char *typename_concat (struct obstack *, |
891 | const char *prefix, | |
892 | const char *suffix, | |
987504bb | 893 | struct dwarf2_cu *); |
63d06c5c | 894 | |
e7c27a73 | 895 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 896 | |
e7c27a73 | 897 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 898 | |
e7c27a73 | 899 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 900 | |
ff013f42 JK |
901 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
902 | struct dwarf2_cu *, struct partial_symtab *); | |
903 | ||
a14ed312 | 904 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 905 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 906 | |
fae299cd DC |
907 | static void get_scope_pc_bounds (struct die_info *, |
908 | CORE_ADDR *, CORE_ADDR *, | |
909 | struct dwarf2_cu *); | |
910 | ||
801e3a5b JB |
911 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
912 | CORE_ADDR, struct dwarf2_cu *); | |
913 | ||
a14ed312 | 914 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 915 | struct dwarf2_cu *); |
c906108c | 916 | |
a14ed312 | 917 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 918 | struct type *, struct dwarf2_cu *); |
c906108c | 919 | |
a14ed312 | 920 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 921 | struct die_info *, struct type *, |
e7c27a73 | 922 | struct dwarf2_cu *); |
c906108c | 923 | |
a14ed312 | 924 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 925 | struct type *, struct dwarf2_cu *); |
c906108c | 926 | |
134d01f1 | 927 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 928 | |
8176b9b8 DC |
929 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); |
930 | ||
e7c27a73 | 931 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 932 | |
e7c27a73 | 933 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 934 | |
38d518c9 | 935 | static const char *namespace_name (struct die_info *die, |
e142c38c | 936 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 937 | |
134d01f1 | 938 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 939 | |
e7c27a73 | 940 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 941 | |
7ca2d3a3 DL |
942 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
943 | struct dwarf2_cu *); | |
944 | ||
fe1b8b76 | 945 | static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *); |
c906108c | 946 | |
fe1b8b76 | 947 | static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 948 | struct dwarf2_cu *, |
fe1b8b76 | 949 | gdb_byte **new_info_ptr, |
639d11d3 DC |
950 | struct die_info *parent); |
951 | ||
fe1b8b76 | 952 | static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 953 | struct dwarf2_cu *, |
fe1b8b76 | 954 | gdb_byte **new_info_ptr, |
639d11d3 DC |
955 | struct die_info *parent); |
956 | ||
a14ed312 | 957 | static void free_die_list (struct die_info *); |
c906108c | 958 | |
e7c27a73 | 959 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 960 | |
e142c38c | 961 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 962 | |
e142c38c | 963 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 964 | |
e142c38c DJ |
965 | static struct die_info *dwarf2_extension (struct die_info *die, |
966 | struct dwarf2_cu *); | |
9219021c | 967 | |
a14ed312 | 968 | static char *dwarf_tag_name (unsigned int); |
c906108c | 969 | |
a14ed312 | 970 | static char *dwarf_attr_name (unsigned int); |
c906108c | 971 | |
a14ed312 | 972 | static char *dwarf_form_name (unsigned int); |
c906108c | 973 | |
a14ed312 | 974 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 975 | |
a14ed312 | 976 | static char *dwarf_bool_name (unsigned int); |
c906108c | 977 | |
a14ed312 | 978 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
979 | |
980 | #if 0 | |
a14ed312 | 981 | static char *dwarf_cfi_name (unsigned int); |
c906108c | 982 | |
a14ed312 | 983 | struct die_info *copy_die (struct die_info *); |
c906108c SS |
984 | #endif |
985 | ||
f9aca02d | 986 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 987 | |
f9aca02d | 988 | static void dump_die (struct die_info *); |
c906108c | 989 | |
f9aca02d | 990 | static void dump_die_list (struct die_info *); |
c906108c | 991 | |
10b3939b DJ |
992 | static void store_in_ref_table (unsigned int, struct die_info *, |
993 | struct dwarf2_cu *); | |
c906108c | 994 | |
e142c38c DJ |
995 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, |
996 | struct dwarf2_cu *); | |
c906108c | 997 | |
a02abb62 JB |
998 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
999 | ||
10b3939b DJ |
1000 | static struct die_info *follow_die_ref (struct die_info *, |
1001 | struct attribute *, | |
1002 | struct dwarf2_cu *); | |
c906108c | 1003 | |
c906108c SS |
1004 | /* memory allocation interface */ |
1005 | ||
7b5a2f43 | 1006 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1007 | |
f3dd6933 | 1008 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1009 | |
a14ed312 | 1010 | static struct die_info *dwarf_alloc_die (void); |
c906108c | 1011 | |
e142c38c | 1012 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1013 | |
e142c38c DJ |
1014 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1015 | struct dwarf2_cu *); | |
5fb290d7 | 1016 | |
2e276125 | 1017 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1018 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1019 | |
8e19ed76 PS |
1020 | static int attr_form_is_block (struct attribute *); |
1021 | ||
3690dd37 JB |
1022 | static int attr_form_is_section_offset (struct attribute *); |
1023 | ||
1024 | static int attr_form_is_constant (struct attribute *); | |
1025 | ||
93e7bd98 DJ |
1026 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
1027 | struct symbol *sym, | |
1028 | struct dwarf2_cu *cu); | |
4c2df51b | 1029 | |
fe1b8b76 JB |
1030 | static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, |
1031 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1032 | |
72bf9492 DJ |
1033 | static void free_stack_comp_unit (void *); |
1034 | ||
72bf9492 DJ |
1035 | static hashval_t partial_die_hash (const void *item); |
1036 | ||
1037 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1038 | ||
ae038cb0 DJ |
1039 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
1040 | (unsigned long offset, struct objfile *objfile); | |
1041 | ||
1042 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
1043 | (unsigned long offset, struct objfile *objfile); | |
1044 | ||
1045 | static void free_one_comp_unit (void *); | |
1046 | ||
1047 | static void free_cached_comp_units (void *); | |
1048 | ||
1049 | static void age_cached_comp_units (void); | |
1050 | ||
1051 | static void free_one_cached_comp_unit (void *); | |
1052 | ||
f792889a DJ |
1053 | static struct type *set_die_type (struct die_info *, struct type *, |
1054 | struct dwarf2_cu *); | |
1c379e20 | 1055 | |
ae038cb0 DJ |
1056 | static void create_all_comp_units (struct objfile *); |
1057 | ||
31ffec48 DJ |
1058 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *, |
1059 | struct objfile *); | |
10b3939b DJ |
1060 | |
1061 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1062 | ||
1063 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1064 | struct dwarf2_per_cu_data *); | |
1065 | ||
ae038cb0 DJ |
1066 | static void dwarf2_mark (struct dwarf2_cu *); |
1067 | ||
1068 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1069 | ||
f792889a | 1070 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
72019c9c | 1071 | |
c906108c SS |
1072 | /* Try to locate the sections we need for DWARF 2 debugging |
1073 | information and return true if we have enough to do something. */ | |
1074 | ||
1075 | int | |
6502dd73 | 1076 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1077 | { |
6502dd73 DJ |
1078 | struct dwarf2_per_objfile *data; |
1079 | ||
1080 | /* Initialize per-objfile state. */ | |
1081 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1082 | memset (data, 0, sizeof (*data)); | |
1083 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1084 | dwarf2_per_objfile = data; | |
1085 | ||
188dd5d6 DJ |
1086 | dwarf_info_section = 0; |
1087 | dwarf_abbrev_section = 0; | |
1088 | dwarf_line_section = 0; | |
1089 | dwarf_str_section = 0; | |
1090 | dwarf_macinfo_section = 0; | |
1091 | dwarf_frame_section = 0; | |
1092 | dwarf_eh_frame_section = 0; | |
1093 | dwarf_ranges_section = 0; | |
1094 | dwarf_loc_section = 0; | |
af34e669 | 1095 | |
6502dd73 | 1096 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 1097 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
1098 | } |
1099 | ||
233a11ab CS |
1100 | /* When loading sections, we can either look for ".<name>", or for |
1101 | * ".z<name>", which indicates a compressed section. */ | |
1102 | ||
1103 | static int | |
1104 | section_is_p (asection *sectp, const char *name) | |
1105 | { | |
1106 | return ((sectp->name[0] == '.' | |
1107 | && strcmp (sectp->name + 1, name) == 0) | |
1108 | || (sectp->name[0] == '.' && sectp->name[1] == 'z' | |
1109 | && strcmp (sectp->name + 2, name) == 0)); | |
1110 | } | |
1111 | ||
c906108c SS |
1112 | /* This function is mapped across the sections and remembers the |
1113 | offset and size of each of the debugging sections we are interested | |
1114 | in. */ | |
1115 | ||
1116 | static void | |
72dca2f5 | 1117 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1118 | { |
233a11ab | 1119 | if (section_is_p (sectp, INFO_SECTION)) |
c906108c | 1120 | { |
2c500098 | 1121 | dwarf2_per_objfile->info_size = bfd_get_section_size (sectp); |
086df311 | 1122 | dwarf_info_section = sectp; |
c906108c | 1123 | } |
233a11ab | 1124 | else if (section_is_p (sectp, ABBREV_SECTION)) |
c906108c | 1125 | { |
2c500098 | 1126 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp); |
086df311 | 1127 | dwarf_abbrev_section = sectp; |
c906108c | 1128 | } |
233a11ab | 1129 | else if (section_is_p (sectp, LINE_SECTION)) |
c906108c | 1130 | { |
2c500098 | 1131 | dwarf2_per_objfile->line_size = bfd_get_section_size (sectp); |
086df311 | 1132 | dwarf_line_section = sectp; |
c906108c | 1133 | } |
233a11ab | 1134 | else if (section_is_p (sectp, PUBNAMES_SECTION)) |
c906108c | 1135 | { |
2c500098 | 1136 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp); |
086df311 | 1137 | dwarf_pubnames_section = sectp; |
c906108c | 1138 | } |
233a11ab | 1139 | else if (section_is_p (sectp, ARANGES_SECTION)) |
c906108c | 1140 | { |
2c500098 | 1141 | dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp); |
086df311 | 1142 | dwarf_aranges_section = sectp; |
c906108c | 1143 | } |
233a11ab | 1144 | else if (section_is_p (sectp, LOC_SECTION)) |
c906108c | 1145 | { |
2c500098 | 1146 | dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp); |
086df311 | 1147 | dwarf_loc_section = sectp; |
c906108c | 1148 | } |
233a11ab | 1149 | else if (section_is_p (sectp, MACINFO_SECTION)) |
c906108c | 1150 | { |
2c500098 | 1151 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp); |
0cf824c9 | 1152 | dwarf_macinfo_section = sectp; |
c906108c | 1153 | } |
233a11ab | 1154 | else if (section_is_p (sectp, STR_SECTION)) |
c906108c | 1155 | { |
2c500098 | 1156 | dwarf2_per_objfile->str_size = bfd_get_section_size (sectp); |
086df311 | 1157 | dwarf_str_section = sectp; |
c906108c | 1158 | } |
233a11ab | 1159 | else if (section_is_p (sectp, FRAME_SECTION)) |
b6af0555 | 1160 | { |
2c500098 | 1161 | dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp); |
086df311 | 1162 | dwarf_frame_section = sectp; |
b6af0555 | 1163 | } |
233a11ab | 1164 | else if (section_is_p (sectp, EH_FRAME_SECTION)) |
b6af0555 | 1165 | { |
3799ccc6 EZ |
1166 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1167 | if (aflag & SEC_HAS_CONTENTS) | |
1168 | { | |
2c500098 | 1169 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp); |
3799ccc6 EZ |
1170 | dwarf_eh_frame_section = sectp; |
1171 | } | |
b6af0555 | 1172 | } |
233a11ab | 1173 | else if (section_is_p (sectp, RANGES_SECTION)) |
af34e669 | 1174 | { |
2c500098 | 1175 | dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp); |
6f10aeb1 | 1176 | dwarf_ranges_section = sectp; |
af34e669 | 1177 | } |
72dca2f5 FR |
1178 | |
1179 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) | |
1180 | && bfd_section_vma (abfd, sectp) == 0) | |
1181 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1182 | } |
1183 | ||
233a11ab CS |
1184 | /* This function is called after decompressing a section, so |
1185 | dwarf2_per_objfile can record its new, uncompressed size. */ | |
1186 | ||
1187 | static void | |
1188 | dwarf2_resize_section (asection *sectp, bfd_size_type new_size) | |
1189 | { | |
1190 | if (section_is_p (sectp, INFO_SECTION)) | |
1191 | dwarf2_per_objfile->info_size = new_size; | |
1192 | else if (section_is_p (sectp, ABBREV_SECTION)) | |
1193 | dwarf2_per_objfile->abbrev_size = new_size; | |
1194 | else if (section_is_p (sectp, LINE_SECTION)) | |
1195 | dwarf2_per_objfile->line_size = new_size; | |
1196 | else if (section_is_p (sectp, PUBNAMES_SECTION)) | |
1197 | dwarf2_per_objfile->pubnames_size = new_size; | |
1198 | else if (section_is_p (sectp, ARANGES_SECTION)) | |
1199 | dwarf2_per_objfile->aranges_size = new_size; | |
1200 | else if (section_is_p (sectp, LOC_SECTION)) | |
1201 | dwarf2_per_objfile->loc_size = new_size; | |
1202 | else if (section_is_p (sectp, MACINFO_SECTION)) | |
1203 | dwarf2_per_objfile->macinfo_size = new_size; | |
1204 | else if (section_is_p (sectp, STR_SECTION)) | |
1205 | dwarf2_per_objfile->str_size = new_size; | |
1206 | else if (section_is_p (sectp, FRAME_SECTION)) | |
1207 | dwarf2_per_objfile->frame_size = new_size; | |
1208 | else if (section_is_p (sectp, EH_FRAME_SECTION)) | |
1209 | dwarf2_per_objfile->eh_frame_size = new_size; | |
1210 | else if (section_is_p (sectp, RANGES_SECTION)) | |
1211 | dwarf2_per_objfile->ranges_size = new_size; | |
1212 | else | |
1213 | internal_error (__FILE__, __LINE__, | |
1214 | _("dwarf2_resize_section: missing section_is_p check: %s"), | |
1215 | sectp->name); | |
1216 | } | |
1217 | ||
c906108c SS |
1218 | /* Build a partial symbol table. */ |
1219 | ||
1220 | void | |
fba45db2 | 1221 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1222 | { |
c906108c SS |
1223 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1224 | ||
6502dd73 DJ |
1225 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1226 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1227 | |
1228 | if (dwarf_line_section) | |
6502dd73 | 1229 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1230 | else |
6502dd73 | 1231 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1232 | |
188dd5d6 | 1233 | if (dwarf_str_section) |
6502dd73 | 1234 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1235 | else |
6502dd73 | 1236 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1237 | |
188dd5d6 | 1238 | if (dwarf_macinfo_section) |
6502dd73 | 1239 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1240 | dwarf_macinfo_section); |
2e276125 | 1241 | else |
6502dd73 | 1242 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1243 | |
188dd5d6 | 1244 | if (dwarf_ranges_section) |
6502dd73 | 1245 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1246 | else |
6502dd73 | 1247 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1248 | |
188dd5d6 | 1249 | if (dwarf_loc_section) |
6502dd73 | 1250 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1251 | else |
6502dd73 | 1252 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1253 | |
ef96bde8 EZ |
1254 | if (mainline |
1255 | || (objfile->global_psymbols.size == 0 | |
1256 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1257 | { |
1258 | init_psymbol_list (objfile, 1024); | |
1259 | } | |
1260 | ||
1261 | #if 0 | |
1262 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1263 | { | |
d4f3574e | 1264 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1265 | .debug_pubnames sections */ |
1266 | ||
d4f3574e | 1267 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1268 | } |
1269 | else | |
1270 | #endif | |
1271 | /* only test this case for now */ | |
c5aa993b | 1272 | { |
c906108c | 1273 | /* In this case we have to work a bit harder */ |
d4f3574e | 1274 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1275 | } |
1276 | } | |
1277 | ||
1278 | #if 0 | |
1279 | /* Build the partial symbol table from the information in the | |
1280 | .debug_pubnames and .debug_aranges sections. */ | |
1281 | ||
1282 | static void | |
fba45db2 | 1283 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1284 | { |
1285 | bfd *abfd = objfile->obfd; | |
1286 | char *aranges_buffer, *pubnames_buffer; | |
1287 | char *aranges_ptr, *pubnames_ptr; | |
1288 | unsigned int entry_length, version, info_offset, info_size; | |
1289 | ||
1290 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1291 | dwarf_pubnames_section); |
c906108c | 1292 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1293 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1294 | { |
613e1657 | 1295 | struct comp_unit_head cu_header; |
891d2f0b | 1296 | unsigned int bytes_read; |
613e1657 KB |
1297 | |
1298 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |
891d2f0b | 1299 | &bytes_read); |
613e1657 | 1300 | pubnames_ptr += bytes_read; |
c906108c SS |
1301 | version = read_1_byte (abfd, pubnames_ptr); |
1302 | pubnames_ptr += 1; | |
1303 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1304 | pubnames_ptr += 4; | |
1305 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1306 | pubnames_ptr += 4; | |
1307 | } | |
1308 | ||
1309 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1310 | dwarf_aranges_section); |
c906108c SS |
1311 | |
1312 | } | |
1313 | #endif | |
1314 | ||
107d2387 | 1315 | /* Read in the comp unit header information from the debug_info at |
917c78fc | 1316 | info_ptr. */ |
107d2387 | 1317 | |
fe1b8b76 | 1318 | static gdb_byte * |
107d2387 | 1319 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1320 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1321 | { |
1322 | int signed_addr; | |
891d2f0b | 1323 | unsigned int bytes_read; |
613e1657 KB |
1324 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, |
1325 | &bytes_read); | |
1326 | info_ptr += bytes_read; | |
107d2387 AC |
1327 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1328 | info_ptr += 2; | |
613e1657 KB |
1329 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
1330 | &bytes_read); | |
1331 | info_ptr += bytes_read; | |
107d2387 AC |
1332 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1333 | info_ptr += 1; | |
1334 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1335 | if (signed_addr < 0) | |
8e65ff28 | 1336 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1337 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 AC |
1338 | cu_header->signed_addr_p = signed_addr; |
1339 | return info_ptr; | |
1340 | } | |
1341 | ||
fe1b8b76 JB |
1342 | static gdb_byte * |
1343 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
72bf9492 DJ |
1344 | bfd *abfd) |
1345 | { | |
fe1b8b76 | 1346 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1347 | |
1348 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1349 | ||
2b949cb6 | 1350 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1351 | error (_("Dwarf Error: wrong version in compilation unit header " |
1352 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1353 | 2, bfd_get_filename (abfd)); |
1354 | ||
1355 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
8a3fe4f8 AC |
1356 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1357 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 DJ |
1358 | (long) header->abbrev_offset, |
1359 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1360 | bfd_get_filename (abfd)); | |
1361 | ||
1362 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1363 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
8a3fe4f8 AC |
1364 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1365 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 DJ |
1366 | (long) header->length, |
1367 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1368 | bfd_get_filename (abfd)); | |
1369 | ||
1370 | return info_ptr; | |
1371 | } | |
1372 | ||
aaa75496 JB |
1373 | /* Allocate a new partial symtab for file named NAME and mark this new |
1374 | partial symtab as being an include of PST. */ | |
1375 | ||
1376 | static void | |
1377 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1378 | struct objfile *objfile) | |
1379 | { | |
1380 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1381 | ||
1382 | subpst->section_offsets = pst->section_offsets; | |
1383 | subpst->textlow = 0; | |
1384 | subpst->texthigh = 0; | |
1385 | ||
1386 | subpst->dependencies = (struct partial_symtab **) | |
1387 | obstack_alloc (&objfile->objfile_obstack, | |
1388 | sizeof (struct partial_symtab *)); | |
1389 | subpst->dependencies[0] = pst; | |
1390 | subpst->number_of_dependencies = 1; | |
1391 | ||
1392 | subpst->globals_offset = 0; | |
1393 | subpst->n_global_syms = 0; | |
1394 | subpst->statics_offset = 0; | |
1395 | subpst->n_static_syms = 0; | |
1396 | subpst->symtab = NULL; | |
1397 | subpst->read_symtab = pst->read_symtab; | |
1398 | subpst->readin = 0; | |
1399 | ||
1400 | /* No private part is necessary for include psymtabs. This property | |
1401 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1402 | the regular ones. */ |
58a9656e | 1403 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1404 | } |
1405 | ||
1406 | /* Read the Line Number Program data and extract the list of files | |
1407 | included by the source file represented by PST. Build an include | |
1408 | partial symtab for each of these included files. | |
1409 | ||
1410 | This procedure assumes that there *is* a Line Number Program in | |
1411 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1412 | before calling this procedure. */ | |
1413 | ||
1414 | static void | |
1415 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1416 | struct partial_die_info *pdi, | |
1417 | struct partial_symtab *pst) | |
1418 | { | |
1419 | struct objfile *objfile = cu->objfile; | |
1420 | bfd *abfd = objfile->obfd; | |
1421 | struct line_header *lh; | |
1422 | ||
1423 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1424 | if (lh == NULL) | |
1425 | return; /* No linetable, so no includes. */ | |
1426 | ||
1427 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1428 | ||
1429 | free_line_header (lh); | |
1430 | } | |
1431 | ||
1432 | ||
c906108c SS |
1433 | /* Build the partial symbol table by doing a quick pass through the |
1434 | .debug_info and .debug_abbrev sections. */ | |
1435 | ||
1436 | static void | |
fba45db2 | 1437 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1438 | { |
1439 | /* Instead of reading this into a big buffer, we should probably use | |
1440 | mmap() on architectures that support it. (FIXME) */ | |
1441 | bfd *abfd = objfile->obfd; | |
fe1b8b76 JB |
1442 | gdb_byte *info_ptr; |
1443 | gdb_byte *beg_of_comp_unit; | |
c906108c SS |
1444 | struct partial_die_info comp_unit_die; |
1445 | struct partial_symtab *pst; | |
ae038cb0 | 1446 | struct cleanup *back_to; |
e142c38c | 1447 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1448 | |
6502dd73 | 1449 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1450 | |
ae038cb0 DJ |
1451 | /* Any cached compilation units will be linked by the per-objfile |
1452 | read_in_chain. Make sure to free them when we're done. */ | |
1453 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
1454 | ||
10b3939b DJ |
1455 | create_all_comp_units (objfile); |
1456 | ||
ff013f42 JK |
1457 | objfile->psymtabs_addrmap = addrmap_create_mutable |
1458 | (&objfile->objfile_obstack); | |
1459 | ||
6502dd73 | 1460 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1461 | length, only the individual functions to extract them (like |
72bf9492 | 1462 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1463 | the buffer is large enough to hold another complete object. |
1464 | ||
6502dd73 DJ |
1465 | At the moment, they don't actually check that. If .debug_info |
1466 | holds just one extra byte after the last compilation unit's dies, | |
1467 | then read_comp_unit_head will happily read off the end of the | |
1468 | buffer. read_partial_die is similarly casual. Those functions | |
1469 | should be fixed. | |
af703f96 JB |
1470 | |
1471 | For this loop condition, simply checking whether there's any data | |
1472 | left at all should be sufficient. */ | |
6502dd73 DJ |
1473 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1474 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1475 | { |
f3dd6933 | 1476 | struct cleanup *back_to_inner; |
e7c27a73 | 1477 | struct dwarf2_cu cu; |
72bf9492 DJ |
1478 | struct abbrev_info *abbrev; |
1479 | unsigned int bytes_read; | |
1480 | struct dwarf2_per_cu_data *this_cu; | |
1481 | ||
c906108c | 1482 | beg_of_comp_unit = info_ptr; |
c906108c | 1483 | |
72bf9492 DJ |
1484 | memset (&cu, 0, sizeof (cu)); |
1485 | ||
1486 | obstack_init (&cu.comp_unit_obstack); | |
1487 | ||
1488 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1489 | ||
e7c27a73 | 1490 | cu.objfile = objfile; |
72bf9492 | 1491 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1492 | |
57349743 | 1493 | /* Complete the cu_header */ |
6502dd73 | 1494 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
e7c27a73 DJ |
1495 | cu.header.first_die_ptr = info_ptr; |
1496 | cu.header.cu_head_ptr = beg_of_comp_unit; | |
57349743 | 1497 | |
e142c38c DJ |
1498 | cu.list_in_scope = &file_symbols; |
1499 | ||
c906108c | 1500 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1501 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1502 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 1503 | |
10b3939b | 1504 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); |
ae038cb0 | 1505 | |
c906108c | 1506 | /* Read the compilation unit die */ |
72bf9492 DJ |
1507 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1508 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1509 | abfd, info_ptr, &cu); | |
c906108c | 1510 | |
31ffec48 DJ |
1511 | if (comp_unit_die.tag == DW_TAG_partial_unit) |
1512 | { | |
1513 | info_ptr = (beg_of_comp_unit + cu.header.length | |
1514 | + cu.header.initial_length_size); | |
1515 | do_cleanups (back_to_inner); | |
1516 | continue; | |
1517 | } | |
1518 | ||
c906108c | 1519 | /* Set the language we're debugging */ |
e142c38c | 1520 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1521 | |
1522 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1523 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1524 | comp_unit_die.name ? comp_unit_die.name : "", |
ff013f42 JK |
1525 | /* TEXTLOW and TEXTHIGH are set below. */ |
1526 | 0, | |
c906108c SS |
1527 | objfile->global_psymbols.next, |
1528 | objfile->static_psymbols.next); | |
1529 | ||
ae038cb0 DJ |
1530 | if (comp_unit_die.dirname) |
1531 | pst->dirname = xstrdup (comp_unit_die.dirname); | |
57c22c6c | 1532 | |
10b3939b DJ |
1533 | pst->read_symtab_private = (char *) this_cu; |
1534 | ||
613e1657 | 1535 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1536 | |
1537 | /* Store the function that reads in the rest of the symbol table */ | |
1538 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1539 | ||
10b3939b DJ |
1540 | /* If this compilation unit was already read in, free the |
1541 | cached copy in order to read it in again. This is | |
1542 | necessary because we skipped some symbols when we first | |
1543 | read in the compilation unit (see load_partial_dies). | |
1544 | This problem could be avoided, but the benefit is | |
1545 | unclear. */ | |
1546 | if (this_cu->cu != NULL) | |
1547 | free_one_cached_comp_unit (this_cu->cu); | |
ae038cb0 | 1548 | |
10b3939b | 1549 | cu.per_cu = this_cu; |
ae038cb0 | 1550 | |
10b3939b DJ |
1551 | /* Note that this is a pointer to our stack frame, being |
1552 | added to a global data structure. It will be cleaned up | |
1553 | in free_stack_comp_unit when we finish with this | |
1554 | compilation unit. */ | |
1555 | this_cu->cu = &cu; | |
ae038cb0 | 1556 | |
10b3939b | 1557 | this_cu->psymtab = pst; |
ae038cb0 | 1558 | |
ff013f42 JK |
1559 | /* Possibly set the default values of LOWPC and HIGHPC from |
1560 | `DW_AT_ranges'. */ | |
1561 | if (cu.has_ranges_offset) | |
1562 | { | |
1563 | if (dwarf2_ranges_read (cu.ranges_offset, &comp_unit_die.lowpc, | |
1564 | &comp_unit_die.highpc, &cu, pst)) | |
1565 | comp_unit_die.has_pc_info = 1; | |
1566 | } | |
1567 | ||
c906108c SS |
1568 | /* Check if comp unit has_children. |
1569 | If so, read the rest of the partial symbols from this comp unit. | |
1570 | If not, there's no more debug_info for this comp unit. */ | |
1571 | if (comp_unit_die.has_children) | |
1572 | { | |
72bf9492 DJ |
1573 | struct partial_die_info *first_die; |
1574 | ||
91c24f0a DC |
1575 | lowpc = ((CORE_ADDR) -1); |
1576 | highpc = ((CORE_ADDR) 0); | |
1577 | ||
72bf9492 DJ |
1578 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1579 | ||
1580 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1581 | |
91c24f0a DC |
1582 | /* If we didn't find a lowpc, set it to highpc to avoid |
1583 | complaints from `maint check'. */ | |
1584 | if (lowpc == ((CORE_ADDR) -1)) | |
1585 | lowpc = highpc; | |
72bf9492 | 1586 | |
c906108c SS |
1587 | /* If the compilation unit didn't have an explicit address range, |
1588 | then use the information extracted from its child dies. */ | |
0b010bcc | 1589 | if (! comp_unit_die.has_pc_info) |
c906108c | 1590 | { |
c5aa993b | 1591 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1592 | comp_unit_die.highpc = highpc; |
1593 | } | |
1594 | } | |
c5aa993b | 1595 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1596 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1597 | ||
ff013f42 JK |
1598 | /* Store the contiguous range; `DW_AT_ranges' range is stored above. The |
1599 | range can be also empty for CUs with no code. */ | |
1600 | if (!cu.has_ranges_offset && pst->textlow < pst->texthigh) | |
1601 | addrmap_set_empty (objfile->psymtabs_addrmap, pst->textlow, | |
1602 | pst->texthigh - 1, pst); | |
1603 | ||
c906108c SS |
1604 | pst->n_global_syms = objfile->global_psymbols.next - |
1605 | (objfile->global_psymbols.list + pst->globals_offset); | |
1606 | pst->n_static_syms = objfile->static_psymbols.next - | |
1607 | (objfile->static_psymbols.list + pst->statics_offset); | |
1608 | sort_pst_symbols (pst); | |
1609 | ||
1610 | /* If there is already a psymtab or symtab for a file of this | |
1611 | name, remove it. (If there is a symtab, more drastic things | |
1612 | also happen.) This happens in VxWorks. */ | |
1613 | free_named_symtabs (pst->filename); | |
1614 | ||
dd373385 EZ |
1615 | info_ptr = beg_of_comp_unit + cu.header.length |
1616 | + cu.header.initial_length_size; | |
1617 | ||
aaa75496 JB |
1618 | if (comp_unit_die.has_stmt_list) |
1619 | { | |
1620 | /* Get the list of files included in the current compilation unit, | |
1621 | and build a psymtab for each of them. */ | |
1622 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1623 | } | |
1624 | ||
f3dd6933 | 1625 | do_cleanups (back_to_inner); |
c906108c | 1626 | } |
ff013f42 JK |
1627 | |
1628 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, | |
1629 | &objfile->objfile_obstack); | |
1630 | ||
ae038cb0 DJ |
1631 | do_cleanups (back_to); |
1632 | } | |
1633 | ||
1634 | /* Load the DIEs for a secondary CU into memory. */ | |
1635 | ||
1636 | static void | |
1637 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |
1638 | { | |
1639 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 1640 | gdb_byte *info_ptr, *beg_of_comp_unit; |
ae038cb0 DJ |
1641 | struct partial_die_info comp_unit_die; |
1642 | struct dwarf2_cu *cu; | |
1643 | struct abbrev_info *abbrev; | |
1644 | unsigned int bytes_read; | |
1645 | struct cleanup *back_to; | |
1646 | ||
1647 | info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset; | |
1648 | beg_of_comp_unit = info_ptr; | |
1649 | ||
1650 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
1651 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
1652 | ||
1653 | obstack_init (&cu->comp_unit_obstack); | |
1654 | ||
1655 | cu->objfile = objfile; | |
1656 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |
1657 | ||
1658 | /* Complete the cu_header. */ | |
1659 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |
1660 | cu->header.first_die_ptr = info_ptr; | |
1661 | cu->header.cu_head_ptr = beg_of_comp_unit; | |
1662 | ||
1663 | /* Read the abbrevs for this compilation unit into a table. */ | |
1664 | dwarf2_read_abbrevs (abfd, cu); | |
1665 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
1666 | ||
1667 | /* Read the compilation unit die. */ | |
1668 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1669 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1670 | abfd, info_ptr, cu); | |
1671 | ||
1672 | /* Set the language we're debugging. */ | |
1673 | set_cu_language (comp_unit_die.language, cu); | |
1674 | ||
1675 | /* Link this compilation unit into the compilation unit tree. */ | |
1676 | this_cu->cu = cu; | |
1677 | cu->per_cu = this_cu; | |
f792889a | 1678 | cu->type_hash = cu->per_cu->type_hash; |
ae038cb0 DJ |
1679 | |
1680 | /* Check if comp unit has_children. | |
1681 | If so, read the rest of the partial symbols from this comp unit. | |
1682 | If not, there's no more debug_info for this comp unit. */ | |
1683 | if (comp_unit_die.has_children) | |
1684 | load_partial_dies (abfd, info_ptr, 0, cu); | |
1685 | ||
1686 | do_cleanups (back_to); | |
1687 | } | |
1688 | ||
1689 | /* Create a list of all compilation units in OBJFILE. We do this only | |
1690 | if an inter-comp-unit reference is found; presumably if there is one, | |
1691 | there will be many, and one will occur early in the .debug_info section. | |
1692 | So there's no point in building this list incrementally. */ | |
1693 | ||
1694 | static void | |
1695 | create_all_comp_units (struct objfile *objfile) | |
1696 | { | |
1697 | int n_allocated; | |
1698 | int n_comp_units; | |
1699 | struct dwarf2_per_cu_data **all_comp_units; | |
fe1b8b76 | 1700 | gdb_byte *info_ptr = dwarf2_per_objfile->info_buffer; |
ae038cb0 DJ |
1701 | |
1702 | n_comp_units = 0; | |
1703 | n_allocated = 10; | |
1704 | all_comp_units = xmalloc (n_allocated | |
1705 | * sizeof (struct dwarf2_per_cu_data *)); | |
1706 | ||
1707 | while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1708 | { | |
1709 | struct comp_unit_head cu_header; | |
fe1b8b76 | 1710 | gdb_byte *beg_of_comp_unit; |
ae038cb0 DJ |
1711 | struct dwarf2_per_cu_data *this_cu; |
1712 | unsigned long offset; | |
891d2f0b | 1713 | unsigned int bytes_read; |
ae038cb0 DJ |
1714 | |
1715 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |
1716 | ||
1717 | /* Read just enough information to find out where the next | |
1718 | compilation unit is. */ | |
dd373385 | 1719 | cu_header.initial_length_size = 0; |
ae038cb0 DJ |
1720 | cu_header.length = read_initial_length (objfile->obfd, info_ptr, |
1721 | &cu_header, &bytes_read); | |
1722 | ||
1723 | /* Save the compilation unit for later lookup. */ | |
1724 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
1725 | sizeof (struct dwarf2_per_cu_data)); | |
1726 | memset (this_cu, 0, sizeof (*this_cu)); | |
1727 | this_cu->offset = offset; | |
1728 | this_cu->length = cu_header.length + cu_header.initial_length_size; | |
1729 | ||
1730 | if (n_comp_units == n_allocated) | |
1731 | { | |
1732 | n_allocated *= 2; | |
1733 | all_comp_units = xrealloc (all_comp_units, | |
1734 | n_allocated | |
1735 | * sizeof (struct dwarf2_per_cu_data *)); | |
1736 | } | |
1737 | all_comp_units[n_comp_units++] = this_cu; | |
1738 | ||
1739 | info_ptr = info_ptr + this_cu->length; | |
1740 | } | |
1741 | ||
1742 | dwarf2_per_objfile->all_comp_units | |
1743 | = obstack_alloc (&objfile->objfile_obstack, | |
1744 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1745 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
1746 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1747 | xfree (all_comp_units); | |
1748 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
1749 | } |
1750 | ||
72bf9492 DJ |
1751 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1752 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1753 | in CU. */ | |
c906108c | 1754 | |
72bf9492 DJ |
1755 | static void |
1756 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1757 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1758 | { |
e7c27a73 | 1759 | struct objfile *objfile = cu->objfile; |
c906108c | 1760 | bfd *abfd = objfile->obfd; |
72bf9492 | 1761 | struct partial_die_info *pdi; |
c906108c | 1762 | |
91c24f0a DC |
1763 | /* Now, march along the PDI's, descending into ones which have |
1764 | interesting children but skipping the children of the other ones, | |
1765 | until we reach the end of the compilation unit. */ | |
c906108c | 1766 | |
72bf9492 | 1767 | pdi = first_die; |
91c24f0a | 1768 | |
72bf9492 DJ |
1769 | while (pdi != NULL) |
1770 | { | |
1771 | fixup_partial_die (pdi, cu); | |
c906108c | 1772 | |
91c24f0a DC |
1773 | /* Anonymous namespaces have no name but have interesting |
1774 | children, so we need to look at them. Ditto for anonymous | |
1775 | enums. */ | |
933c6fe4 | 1776 | |
72bf9492 DJ |
1777 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1778 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1779 | { |
72bf9492 | 1780 | switch (pdi->tag) |
c906108c SS |
1781 | { |
1782 | case DW_TAG_subprogram: | |
72bf9492 | 1783 | if (pdi->has_pc_info) |
c906108c | 1784 | { |
72bf9492 | 1785 | if (pdi->lowpc < *lowpc) |
c906108c | 1786 | { |
72bf9492 | 1787 | *lowpc = pdi->lowpc; |
c906108c | 1788 | } |
72bf9492 | 1789 | if (pdi->highpc > *highpc) |
c906108c | 1790 | { |
72bf9492 | 1791 | *highpc = pdi->highpc; |
c906108c | 1792 | } |
72bf9492 | 1793 | if (!pdi->is_declaration) |
c906108c | 1794 | { |
72bf9492 | 1795 | add_partial_symbol (pdi, cu); |
c906108c SS |
1796 | } |
1797 | } | |
1798 | break; | |
1799 | case DW_TAG_variable: | |
1800 | case DW_TAG_typedef: | |
91c24f0a | 1801 | case DW_TAG_union_type: |
72bf9492 | 1802 | if (!pdi->is_declaration) |
63d06c5c | 1803 | { |
72bf9492 | 1804 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1805 | } |
1806 | break; | |
c906108c | 1807 | case DW_TAG_class_type: |
680b30c7 | 1808 | case DW_TAG_interface_type: |
c906108c | 1809 | case DW_TAG_structure_type: |
72bf9492 | 1810 | if (!pdi->is_declaration) |
c906108c | 1811 | { |
72bf9492 | 1812 | add_partial_symbol (pdi, cu); |
c906108c SS |
1813 | } |
1814 | break; | |
91c24f0a | 1815 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1816 | if (!pdi->is_declaration) |
1817 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1818 | break; |
1819 | case DW_TAG_base_type: | |
a02abb62 | 1820 | case DW_TAG_subrange_type: |
c906108c | 1821 | /* File scope base type definitions are added to the partial |
c5aa993b | 1822 | symbol table. */ |
72bf9492 | 1823 | add_partial_symbol (pdi, cu); |
c906108c | 1824 | break; |
d9fa45fe | 1825 | case DW_TAG_namespace: |
72bf9492 | 1826 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1827 | break; |
c906108c SS |
1828 | default: |
1829 | break; | |
1830 | } | |
1831 | } | |
1832 | ||
72bf9492 DJ |
1833 | /* If the die has a sibling, skip to the sibling. */ |
1834 | ||
1835 | pdi = pdi->die_sibling; | |
1836 | } | |
1837 | } | |
1838 | ||
1839 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1840 | |
72bf9492 | 1841 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
1842 | name is concatenated with "::" and the partial DIE's name. For |
1843 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
1844 | Enumerators are an exception; they use the scope of their parent |
1845 | enumeration type, i.e. the name of the enumeration type is not | |
1846 | prepended to the enumerator. | |
91c24f0a | 1847 | |
72bf9492 DJ |
1848 | There are two complexities. One is DW_AT_specification; in this |
1849 | case "parent" means the parent of the target of the specification, | |
1850 | instead of the direct parent of the DIE. The other is compilers | |
1851 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1852 | the fully qualified name of structure types from their members' | |
1853 | linkage names. This must be done using the DIE's children rather | |
1854 | than the children of any DW_AT_specification target. We only need | |
1855 | to do this for structures at the top level, i.e. if the target of | |
1856 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1857 | have a parent. */ | |
1858 | ||
1859 | /* Compute the scope prefix associated with PDI's parent, in | |
1860 | compilation unit CU. The result will be allocated on CU's | |
1861 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1862 | field. NULL is returned if no prefix is necessary. */ | |
1863 | static char * | |
1864 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1865 | struct dwarf2_cu *cu) | |
1866 | { | |
1867 | char *grandparent_scope; | |
1868 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 1869 | |
72bf9492 DJ |
1870 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1871 | then this means the parent of the specification DIE. */ | |
1872 | ||
1873 | real_pdi = pdi; | |
72bf9492 | 1874 | while (real_pdi->has_specification) |
10b3939b | 1875 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
1876 | |
1877 | parent = real_pdi->die_parent; | |
1878 | if (parent == NULL) | |
1879 | return NULL; | |
1880 | ||
1881 | if (parent->scope_set) | |
1882 | return parent->scope; | |
1883 | ||
1884 | fixup_partial_die (parent, cu); | |
1885 | ||
10b3939b | 1886 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
1887 | |
1888 | if (parent->tag == DW_TAG_namespace | |
1889 | || parent->tag == DW_TAG_structure_type | |
1890 | || parent->tag == DW_TAG_class_type | |
680b30c7 | 1891 | || parent->tag == DW_TAG_interface_type |
72bf9492 DJ |
1892 | || parent->tag == DW_TAG_union_type) |
1893 | { | |
1894 | if (grandparent_scope == NULL) | |
1895 | parent->scope = parent->name; | |
1896 | else | |
987504bb JJ |
1897 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
1898 | parent->name, cu); | |
72bf9492 DJ |
1899 | } |
1900 | else if (parent->tag == DW_TAG_enumeration_type) | |
1901 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1902 | parent->scope = grandparent_scope; | |
1903 | else | |
1904 | { | |
1905 | /* FIXME drow/2004-04-01: What should we be doing with | |
1906 | function-local names? For partial symbols, we should probably be | |
1907 | ignoring them. */ | |
1908 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1909 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
1910 | parent->tag, pdi->offset); |
1911 | parent->scope = grandparent_scope; | |
c906108c SS |
1912 | } |
1913 | ||
72bf9492 DJ |
1914 | parent->scope_set = 1; |
1915 | return parent->scope; | |
1916 | } | |
1917 | ||
1918 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1919 | CU. The result will be allocated with malloc. */ | |
1920 | static char * | |
1921 | partial_die_full_name (struct partial_die_info *pdi, | |
1922 | struct dwarf2_cu *cu) | |
1923 | { | |
1924 | char *parent_scope; | |
1925 | ||
1926 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1927 | if (parent_scope == NULL) | |
1928 | return NULL; | |
1929 | else | |
987504bb | 1930 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
1931 | } |
1932 | ||
1933 | static void | |
72bf9492 | 1934 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1935 | { |
e7c27a73 | 1936 | struct objfile *objfile = cu->objfile; |
c906108c | 1937 | CORE_ADDR addr = 0; |
decbce07 | 1938 | char *actual_name = NULL; |
72bf9492 | 1939 | const char *my_prefix; |
5c4e30ca | 1940 | const struct partial_symbol *psym = NULL; |
e142c38c | 1941 | CORE_ADDR baseaddr; |
72bf9492 | 1942 | int built_actual_name = 0; |
e142c38c DJ |
1943 | |
1944 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1945 | |
72bf9492 | 1946 | if (pdi_needs_namespace (pdi->tag)) |
63d06c5c | 1947 | { |
72bf9492 DJ |
1948 | actual_name = partial_die_full_name (pdi, cu); |
1949 | if (actual_name) | |
1950 | built_actual_name = 1; | |
63d06c5c DC |
1951 | } |
1952 | ||
72bf9492 DJ |
1953 | if (actual_name == NULL) |
1954 | actual_name = pdi->name; | |
1955 | ||
c906108c SS |
1956 | switch (pdi->tag) |
1957 | { | |
1958 | case DW_TAG_subprogram: | |
2cfa0c8d | 1959 | if (pdi->is_external || cu->language == language_ada) |
c906108c | 1960 | { |
2cfa0c8d JB |
1961 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
1962 | of the global scope. But in Ada, we want to be able to access | |
1963 | nested procedures globally. So all Ada subprograms are stored | |
1964 | in the global scope. */ | |
38d518c9 | 1965 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1966 | mst_text, objfile); */ |
38d518c9 | 1967 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1968 | VAR_DOMAIN, LOC_BLOCK, |
1969 | &objfile->global_psymbols, | |
1970 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1971 | cu->language, objfile); |
c906108c SS |
1972 | } |
1973 | else | |
1974 | { | |
38d518c9 | 1975 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1976 | mst_file_text, objfile); */ |
38d518c9 | 1977 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1978 | VAR_DOMAIN, LOC_BLOCK, |
1979 | &objfile->static_psymbols, | |
1980 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1981 | cu->language, objfile); |
c906108c SS |
1982 | } |
1983 | break; | |
1984 | case DW_TAG_variable: | |
1985 | if (pdi->is_external) | |
1986 | { | |
1987 | /* Global Variable. | |
1988 | Don't enter into the minimal symbol tables as there is | |
1989 | a minimal symbol table entry from the ELF symbols already. | |
1990 | Enter into partial symbol table if it has a location | |
1991 | descriptor or a type. | |
1992 | If the location descriptor is missing, new_symbol will create | |
1993 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1994 | be determined from the minimal symbol table whenever the variable | |
1995 | is referenced. | |
1996 | The address for the partial symbol table entry is not | |
1997 | used by GDB, but it comes in handy for debugging partial symbol | |
1998 | table building. */ | |
1999 | ||
2000 | if (pdi->locdesc) | |
e7c27a73 | 2001 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 2002 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 2003 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2004 | VAR_DOMAIN, LOC_STATIC, |
2005 | &objfile->global_psymbols, | |
2006 | 0, addr + baseaddr, | |
e142c38c | 2007 | cu->language, objfile); |
c906108c SS |
2008 | } |
2009 | else | |
2010 | { | |
2011 | /* Static Variable. Skip symbols without location descriptors. */ | |
2012 | if (pdi->locdesc == NULL) | |
decbce07 MS |
2013 | { |
2014 | if (built_actual_name) | |
2015 | xfree (actual_name); | |
2016 | return; | |
2017 | } | |
e7c27a73 | 2018 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 2019 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 2020 | mst_file_data, objfile); */ |
38d518c9 | 2021 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
2022 | VAR_DOMAIN, LOC_STATIC, |
2023 | &objfile->static_psymbols, | |
2024 | 0, addr + baseaddr, | |
e142c38c | 2025 | cu->language, objfile); |
c906108c SS |
2026 | } |
2027 | break; | |
2028 | case DW_TAG_typedef: | |
2029 | case DW_TAG_base_type: | |
a02abb62 | 2030 | case DW_TAG_subrange_type: |
38d518c9 | 2031 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2032 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 2033 | &objfile->static_psymbols, |
e142c38c | 2034 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2035 | break; |
72bf9492 DJ |
2036 | case DW_TAG_namespace: |
2037 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
2038 | VAR_DOMAIN, LOC_TYPEDEF, | |
2039 | &objfile->global_psymbols, | |
2040 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
2041 | break; | |
c906108c | 2042 | case DW_TAG_class_type: |
680b30c7 | 2043 | case DW_TAG_interface_type: |
c906108c SS |
2044 | case DW_TAG_structure_type: |
2045 | case DW_TAG_union_type: | |
2046 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
2047 | /* Skip external references. The DWARF standard says in the section |
2048 | about "Structure, Union, and Class Type Entries": "An incomplete | |
2049 | structure, union or class type is represented by a structure, | |
2050 | union or class entry that does not have a byte size attribute | |
2051 | and that has a DW_AT_declaration attribute." */ | |
2052 | if (!pdi->has_byte_size && pdi->is_declaration) | |
decbce07 MS |
2053 | { |
2054 | if (built_actual_name) | |
2055 | xfree (actual_name); | |
2056 | return; | |
2057 | } | |
fa4028e9 | 2058 | |
63d06c5c DC |
2059 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
2060 | static vs. global. */ | |
38d518c9 | 2061 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2062 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
2063 | (cu->language == language_cplus |
2064 | || cu->language == language_java) | |
63d06c5c DC |
2065 | ? &objfile->global_psymbols |
2066 | : &objfile->static_psymbols, | |
e142c38c | 2067 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2068 | |
987504bb | 2069 | if (cu->language == language_cplus |
8c6860bb JB |
2070 | || cu->language == language_java |
2071 | || cu->language == language_ada) | |
c906108c | 2072 | { |
987504bb | 2073 | /* For C++ and Java, these implicitly act as typedefs as well. */ |
38d518c9 | 2074 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2075 | VAR_DOMAIN, LOC_TYPEDEF, |
63d06c5c | 2076 | &objfile->global_psymbols, |
e142c38c | 2077 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2078 | } |
2079 | break; | |
2080 | case DW_TAG_enumerator: | |
38d518c9 | 2081 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2082 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2083 | (cu->language == language_cplus |
2084 | || cu->language == language_java) | |
f6fe98ef DJ |
2085 | ? &objfile->global_psymbols |
2086 | : &objfile->static_psymbols, | |
e142c38c | 2087 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2088 | break; |
2089 | default: | |
2090 | break; | |
2091 | } | |
5c4e30ca DC |
2092 | |
2093 | /* Check to see if we should scan the name for possible namespace | |
2094 | info. Only do this if this is C++, if we don't have namespace | |
2095 | debugging info in the file, if the psym is of an appropriate type | |
2096 | (otherwise we'll have psym == NULL), and if we actually had a | |
2097 | mangled name to begin with. */ | |
2098 | ||
72bf9492 DJ |
2099 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2100 | cases which do not set PSYM above? */ | |
2101 | ||
e142c38c | 2102 | if (cu->language == language_cplus |
72bf9492 | 2103 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2104 | && psym != NULL |
2105 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2106 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2107 | objfile); | |
72bf9492 DJ |
2108 | |
2109 | if (built_actual_name) | |
2110 | xfree (actual_name); | |
c906108c SS |
2111 | } |
2112 | ||
72bf9492 DJ |
2113 | /* Determine whether a die of type TAG living in a C++ class or |
2114 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2115 | name listed in the die. */ |
2116 | ||
2117 | static int | |
72bf9492 | 2118 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2119 | { |
63d06c5c DC |
2120 | switch (tag) |
2121 | { | |
72bf9492 | 2122 | case DW_TAG_namespace: |
63d06c5c DC |
2123 | case DW_TAG_typedef: |
2124 | case DW_TAG_class_type: | |
680b30c7 | 2125 | case DW_TAG_interface_type: |
63d06c5c DC |
2126 | case DW_TAG_structure_type: |
2127 | case DW_TAG_union_type: | |
2128 | case DW_TAG_enumeration_type: | |
2129 | case DW_TAG_enumerator: | |
2130 | return 1; | |
2131 | default: | |
2132 | return 0; | |
2133 | } | |
2134 | } | |
2135 | ||
5c4e30ca DC |
2136 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2137 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2138 | the name of the enclosing namespace. */ | |
91c24f0a | 2139 | |
72bf9492 DJ |
2140 | static void |
2141 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2142 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 2143 | struct dwarf2_cu *cu) |
91c24f0a | 2144 | { |
e7c27a73 | 2145 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2146 | |
72bf9492 | 2147 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2148 | |
72bf9492 | 2149 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2150 | |
2151 | /* Now scan partial symbols in that namespace. */ | |
2152 | ||
91c24f0a | 2153 | if (pdi->has_children) |
72bf9492 | 2154 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
2155 | } |
2156 | ||
72bf9492 DJ |
2157 | /* See if we can figure out if the class lives in a namespace. We do |
2158 | this by looking for a member function; its demangled name will | |
2159 | contain namespace info, if there is any. */ | |
63d06c5c | 2160 | |
72bf9492 DJ |
2161 | static void |
2162 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2163 | struct dwarf2_cu *cu) | |
63d06c5c | 2164 | { |
987504bb JJ |
2165 | if ((cu->language == language_cplus |
2166 | || cu->language == language_java) | |
72bf9492 | 2167 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2168 | && struct_pdi->has_children) |
2169 | { | |
63d06c5c DC |
2170 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2171 | what template types look like, because the demangler | |
2172 | frequently doesn't give the same name as the debug info. We | |
2173 | could fix this by only using the demangled name to get the | |
134d01f1 | 2174 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2175 | |
72bf9492 DJ |
2176 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2177 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2178 | |
72bf9492 DJ |
2179 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2180 | we should not do this. We'll prepend the parent's fully qualified | |
2181 | name when we create the partial symbol. */ | |
5d51ca54 | 2182 | |
72bf9492 | 2183 | real_pdi = struct_pdi; |
72bf9492 | 2184 | while (real_pdi->has_specification) |
10b3939b | 2185 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2186 | |
72bf9492 DJ |
2187 | if (real_pdi->die_parent != NULL) |
2188 | return; | |
63d06c5c | 2189 | |
72bf9492 DJ |
2190 | while (child_pdi != NULL) |
2191 | { | |
2192 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2193 | { |
72bf9492 | 2194 | char *actual_class_name |
31c27f77 JJ |
2195 | = language_class_name_from_physname (cu->language_defn, |
2196 | child_pdi->name); | |
63d06c5c | 2197 | if (actual_class_name != NULL) |
72bf9492 DJ |
2198 | { |
2199 | struct_pdi->name | |
2200 | = obsavestring (actual_class_name, | |
2201 | strlen (actual_class_name), | |
2202 | &cu->comp_unit_obstack); | |
2203 | xfree (actual_class_name); | |
2204 | } | |
63d06c5c DC |
2205 | break; |
2206 | } | |
72bf9492 DJ |
2207 | |
2208 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2209 | } |
2210 | } | |
63d06c5c DC |
2211 | } |
2212 | ||
91c24f0a DC |
2213 | /* Read a partial die corresponding to an enumeration type. */ |
2214 | ||
72bf9492 DJ |
2215 | static void |
2216 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2217 | struct dwarf2_cu *cu) | |
91c24f0a | 2218 | { |
e7c27a73 | 2219 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2220 | bfd *abfd = objfile->obfd; |
72bf9492 | 2221 | struct partial_die_info *pdi; |
91c24f0a DC |
2222 | |
2223 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2224 | add_partial_symbol (enum_pdi, cu); |
2225 | ||
2226 | pdi = enum_pdi->die_child; | |
2227 | while (pdi) | |
91c24f0a | 2228 | { |
72bf9492 | 2229 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2230 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2231 | else |
72bf9492 DJ |
2232 | add_partial_symbol (pdi, cu); |
2233 | pdi = pdi->die_sibling; | |
91c24f0a | 2234 | } |
91c24f0a DC |
2235 | } |
2236 | ||
4bb7a0a7 DJ |
2237 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2238 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2239 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2240 | the initial number. */ | |
2241 | ||
2242 | static struct abbrev_info * | |
fe1b8b76 | 2243 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2244 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2245 | { |
2246 | bfd *abfd = cu->objfile->obfd; | |
2247 | unsigned int abbrev_number; | |
2248 | struct abbrev_info *abbrev; | |
2249 | ||
2250 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2251 | ||
2252 | if (abbrev_number == 0) | |
2253 | return NULL; | |
2254 | ||
2255 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2256 | if (!abbrev) | |
2257 | { | |
8a3fe4f8 | 2258 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2259 | bfd_get_filename (abfd)); |
2260 | } | |
2261 | ||
2262 | return abbrev; | |
2263 | } | |
2264 | ||
2265 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2266 | pointer to the end of a series of DIEs, terminated by an empty | |
2267 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2268 | ||
fe1b8b76 JB |
2269 | static gdb_byte * |
2270 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2271 | { |
2272 | struct abbrev_info *abbrev; | |
2273 | unsigned int bytes_read; | |
2274 | ||
2275 | while (1) | |
2276 | { | |
2277 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2278 | if (abbrev == NULL) | |
2279 | return info_ptr + bytes_read; | |
2280 | else | |
2281 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2286 | should point just after the initial uleb128 of a DIE, and the | |
2287 | abbrev corresponding to that skipped uleb128 should be passed in | |
2288 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2289 | children. */ | |
2290 | ||
fe1b8b76 JB |
2291 | static gdb_byte * |
2292 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2293 | struct dwarf2_cu *cu) |
2294 | { | |
2295 | unsigned int bytes_read; | |
2296 | struct attribute attr; | |
2297 | bfd *abfd = cu->objfile->obfd; | |
2298 | unsigned int form, i; | |
2299 | ||
2300 | for (i = 0; i < abbrev->num_attrs; i++) | |
2301 | { | |
2302 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2303 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2304 | { | |
2305 | read_attribute (&attr, &abbrev->attrs[i], | |
2306 | abfd, info_ptr, cu); | |
2307 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2308 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2309 | else |
6502dd73 DJ |
2310 | return dwarf2_per_objfile->info_buffer |
2311 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
2312 | } |
2313 | ||
2314 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2315 | form = abbrev->attrs[i].form; | |
2316 | skip_attribute: | |
2317 | switch (form) | |
2318 | { | |
2319 | case DW_FORM_addr: | |
2320 | case DW_FORM_ref_addr: | |
2321 | info_ptr += cu->header.addr_size; | |
2322 | break; | |
2323 | case DW_FORM_data1: | |
2324 | case DW_FORM_ref1: | |
2325 | case DW_FORM_flag: | |
2326 | info_ptr += 1; | |
2327 | break; | |
2328 | case DW_FORM_data2: | |
2329 | case DW_FORM_ref2: | |
2330 | info_ptr += 2; | |
2331 | break; | |
2332 | case DW_FORM_data4: | |
2333 | case DW_FORM_ref4: | |
2334 | info_ptr += 4; | |
2335 | break; | |
2336 | case DW_FORM_data8: | |
2337 | case DW_FORM_ref8: | |
2338 | info_ptr += 8; | |
2339 | break; | |
2340 | case DW_FORM_string: | |
2341 | read_string (abfd, info_ptr, &bytes_read); | |
2342 | info_ptr += bytes_read; | |
2343 | break; | |
2344 | case DW_FORM_strp: | |
2345 | info_ptr += cu->header.offset_size; | |
2346 | break; | |
2347 | case DW_FORM_block: | |
2348 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2349 | info_ptr += bytes_read; | |
2350 | break; | |
2351 | case DW_FORM_block1: | |
2352 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2353 | break; | |
2354 | case DW_FORM_block2: | |
2355 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2356 | break; | |
2357 | case DW_FORM_block4: | |
2358 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2359 | break; | |
2360 | case DW_FORM_sdata: | |
2361 | case DW_FORM_udata: | |
2362 | case DW_FORM_ref_udata: | |
2363 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2364 | break; | |
2365 | case DW_FORM_indirect: | |
2366 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2367 | info_ptr += bytes_read; | |
2368 | /* We need to continue parsing from here, so just go back to | |
2369 | the top. */ | |
2370 | goto skip_attribute; | |
2371 | ||
2372 | default: | |
8a3fe4f8 | 2373 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2374 | dwarf_form_name (form), |
2375 | bfd_get_filename (abfd)); | |
2376 | } | |
2377 | } | |
2378 | ||
2379 | if (abbrev->has_children) | |
2380 | return skip_children (info_ptr, cu); | |
2381 | else | |
2382 | return info_ptr; | |
2383 | } | |
2384 | ||
2385 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2386 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2387 | |
fe1b8b76 JB |
2388 | static gdb_byte * |
2389 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2390 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2391 | { |
2392 | /* Do we know the sibling already? */ | |
72bf9492 | 2393 | |
91c24f0a DC |
2394 | if (orig_pdi->sibling) |
2395 | return orig_pdi->sibling; | |
2396 | ||
2397 | /* Are there any children to deal with? */ | |
2398 | ||
2399 | if (!orig_pdi->has_children) | |
2400 | return info_ptr; | |
2401 | ||
4bb7a0a7 | 2402 | /* Skip the children the long way. */ |
91c24f0a | 2403 | |
4bb7a0a7 | 2404 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2405 | } |
2406 | ||
c906108c SS |
2407 | /* Expand this partial symbol table into a full symbol table. */ |
2408 | ||
2409 | static void | |
fba45db2 | 2410 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2411 | { |
2412 | /* FIXME: This is barely more than a stub. */ | |
2413 | if (pst != NULL) | |
2414 | { | |
2415 | if (pst->readin) | |
2416 | { | |
8a3fe4f8 | 2417 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2418 | } |
2419 | else | |
2420 | { | |
2421 | if (info_verbose) | |
2422 | { | |
a3f17187 | 2423 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2424 | gdb_flush (gdb_stdout); |
2425 | } | |
2426 | ||
10b3939b DJ |
2427 | /* Restore our global data. */ |
2428 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2429 | dwarf2_objfile_data_key); | |
2430 | ||
c906108c SS |
2431 | psymtab_to_symtab_1 (pst); |
2432 | ||
2433 | /* Finish up the debug error message. */ | |
2434 | if (info_verbose) | |
a3f17187 | 2435 | printf_filtered (_("done.\n")); |
c906108c SS |
2436 | } |
2437 | } | |
2438 | } | |
2439 | ||
10b3939b DJ |
2440 | /* Add PER_CU to the queue. */ |
2441 | ||
2442 | static void | |
2443 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2444 | { | |
2445 | struct dwarf2_queue_item *item; | |
2446 | ||
2447 | per_cu->queued = 1; | |
2448 | item = xmalloc (sizeof (*item)); | |
2449 | item->per_cu = per_cu; | |
2450 | item->next = NULL; | |
2451 | ||
2452 | if (dwarf2_queue == NULL) | |
2453 | dwarf2_queue = item; | |
2454 | else | |
2455 | dwarf2_queue_tail->next = item; | |
2456 | ||
2457 | dwarf2_queue_tail = item; | |
2458 | } | |
2459 | ||
2460 | /* Process the queue. */ | |
2461 | ||
2462 | static void | |
2463 | process_queue (struct objfile *objfile) | |
2464 | { | |
2465 | struct dwarf2_queue_item *item, *next_item; | |
2466 | ||
2467 | /* Initially, there is just one item on the queue. Load its DIEs, | |
2468 | and the DIEs of any other compilation units it requires, | |
2469 | transitively. */ | |
2470 | ||
2471 | for (item = dwarf2_queue; item != NULL; item = item->next) | |
2472 | { | |
2473 | /* Read in this compilation unit. This may add new items to | |
2474 | the end of the queue. */ | |
31ffec48 | 2475 | load_full_comp_unit (item->per_cu, objfile); |
10b3939b DJ |
2476 | |
2477 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2478 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
10b3939b DJ |
2479 | } |
2480 | ||
2481 | /* Now everything left on the queue needs to be read in. Process | |
2482 | them, one at a time, removing from the queue as we finish. */ | |
2483 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) | |
2484 | { | |
31ffec48 | 2485 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2486 | process_full_comp_unit (item->per_cu); |
2487 | ||
2488 | item->per_cu->queued = 0; | |
2489 | next_item = item->next; | |
2490 | xfree (item); | |
2491 | } | |
2492 | ||
2493 | dwarf2_queue_tail = NULL; | |
2494 | } | |
2495 | ||
2496 | /* Free all allocated queue entries. This function only releases anything if | |
2497 | an error was thrown; if the queue was processed then it would have been | |
2498 | freed as we went along. */ | |
2499 | ||
2500 | static void | |
2501 | dwarf2_release_queue (void *dummy) | |
2502 | { | |
2503 | struct dwarf2_queue_item *item, *last; | |
2504 | ||
2505 | item = dwarf2_queue; | |
2506 | while (item) | |
2507 | { | |
2508 | /* Anything still marked queued is likely to be in an | |
2509 | inconsistent state, so discard it. */ | |
2510 | if (item->per_cu->queued) | |
2511 | { | |
2512 | if (item->per_cu->cu != NULL) | |
2513 | free_one_cached_comp_unit (item->per_cu->cu); | |
2514 | item->per_cu->queued = 0; | |
2515 | } | |
2516 | ||
2517 | last = item; | |
2518 | item = item->next; | |
2519 | xfree (last); | |
2520 | } | |
2521 | ||
2522 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2523 | } | |
2524 | ||
2525 | /* Read in full symbols for PST, and anything it depends on. */ | |
2526 | ||
c906108c | 2527 | static void |
fba45db2 | 2528 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2529 | { |
10b3939b | 2530 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2531 | struct cleanup *back_to; |
aaa75496 JB |
2532 | int i; |
2533 | ||
2534 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2535 | if (!pst->dependencies[i]->readin) | |
2536 | { | |
2537 | /* Inform about additional files that need to be read in. */ | |
2538 | if (info_verbose) | |
2539 | { | |
a3f17187 | 2540 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2541 | fputs_filtered (" ", gdb_stdout); |
2542 | wrap_here (""); | |
2543 | fputs_filtered ("and ", gdb_stdout); | |
2544 | wrap_here (""); | |
2545 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2546 | wrap_here (""); /* Flush output */ | |
2547 | gdb_flush (gdb_stdout); | |
2548 | } | |
2549 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2550 | } | |
2551 | ||
10b3939b DJ |
2552 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2553 | ||
2554 | if (per_cu == NULL) | |
aaa75496 JB |
2555 | { |
2556 | /* It's an include file, no symbols to read for it. | |
2557 | Everything is in the parent symtab. */ | |
2558 | pst->readin = 1; | |
2559 | return; | |
2560 | } | |
c906108c | 2561 | |
10b3939b DJ |
2562 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2563 | ||
2564 | queue_comp_unit (per_cu); | |
2565 | ||
2566 | process_queue (pst->objfile); | |
2567 | ||
2568 | /* Age the cache, releasing compilation units that have not | |
2569 | been used recently. */ | |
2570 | age_cached_comp_units (); | |
2571 | ||
2572 | do_cleanups (back_to); | |
2573 | } | |
2574 | ||
2575 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2576 | ||
2577 | static struct dwarf2_cu * | |
31ffec48 | 2578 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2579 | { |
31ffec48 | 2580 | bfd *abfd = objfile->obfd; |
10b3939b DJ |
2581 | struct dwarf2_cu *cu; |
2582 | unsigned long offset; | |
fe1b8b76 | 2583 | gdb_byte *info_ptr; |
10b3939b DJ |
2584 | struct cleanup *back_to, *free_cu_cleanup; |
2585 | struct attribute *attr; | |
2586 | CORE_ADDR baseaddr; | |
6502dd73 | 2587 | |
c906108c | 2588 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2589 | offset = per_cu->offset; |
6502dd73 DJ |
2590 | |
2591 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
63d06c5c | 2592 | |
10b3939b DJ |
2593 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2594 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2595 | |
10b3939b DJ |
2596 | /* If an error occurs while loading, release our storage. */ |
2597 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2598 | |
31ffec48 | 2599 | cu->objfile = objfile; |
e7c27a73 | 2600 | |
c906108c | 2601 | /* read in the comp_unit header */ |
10b3939b | 2602 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2603 | |
2604 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2605 | dwarf2_read_abbrevs (abfd, cu); |
2606 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2607 | ||
2608 | cu->header.offset = offset; | |
c906108c | 2609 | |
10b3939b DJ |
2610 | cu->per_cu = per_cu; |
2611 | per_cu->cu = cu; | |
f792889a | 2612 | cu->type_hash = per_cu->type_hash; |
e142c38c | 2613 | |
10b3939b DJ |
2614 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2615 | obstack_init (&cu->comp_unit_obstack); | |
2616 | ||
2617 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2618 | ||
2619 | /* We try not to read any attributes in this function, because not | |
2620 | all objfiles needed for references have been loaded yet, and symbol | |
2621 | table processing isn't initialized. But we have to set the CU language, | |
2622 | or we won't be able to build types correctly. */ | |
2623 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2624 | if (attr) | |
2625 | set_cu_language (DW_UNSND (attr), cu); | |
2626 | else | |
2627 | set_cu_language (language_minimal, cu); | |
2628 | ||
2629 | do_cleanups (back_to); | |
e142c38c | 2630 | |
10b3939b DJ |
2631 | /* We've successfully allocated this compilation unit. Let our caller |
2632 | clean it up when finished with it. */ | |
2633 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2634 | |
10b3939b DJ |
2635 | return cu; |
2636 | } | |
2637 | ||
2638 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2639 | already been loaded into memory. */ | |
2640 | ||
2641 | static void | |
2642 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2643 | { | |
2644 | struct partial_symtab *pst = per_cu->psymtab; | |
2645 | struct dwarf2_cu *cu = per_cu->cu; | |
2646 | struct objfile *objfile = pst->objfile; | |
2647 | bfd *abfd = objfile->obfd; | |
2648 | CORE_ADDR lowpc, highpc; | |
2649 | struct symtab *symtab; | |
2650 | struct cleanup *back_to; | |
2651 | struct attribute *attr; | |
2652 | CORE_ADDR baseaddr; | |
2653 | ||
2654 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2655 | ||
2656 | /* We're in the global namespace. */ | |
2657 | processing_current_prefix = ""; | |
2658 | ||
2659 | buildsym_init (); | |
2660 | back_to = make_cleanup (really_free_pendings, NULL); | |
2661 | ||
2662 | cu->list_in_scope = &file_symbols; | |
c906108c | 2663 | |
0d53c4c4 DJ |
2664 | /* Find the base address of the compilation unit for range lists and |
2665 | location lists. It will normally be specified by DW_AT_low_pc. | |
2666 | In DWARF-3 draft 4, the base address could be overridden by | |
2667 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2668 | compilation units with discontinuous ranges. */ | |
2669 | ||
10b3939b DJ |
2670 | cu->header.base_known = 0; |
2671 | cu->header.base_address = 0; | |
0d53c4c4 | 2672 | |
10b3939b | 2673 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2674 | if (attr) |
2675 | { | |
10b3939b DJ |
2676 | cu->header.base_address = DW_ADDR (attr); |
2677 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2678 | } |
2679 | else | |
2680 | { | |
10b3939b | 2681 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2682 | if (attr) |
2683 | { | |
10b3939b DJ |
2684 | cu->header.base_address = DW_ADDR (attr); |
2685 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2686 | } |
2687 | } | |
2688 | ||
c906108c | 2689 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2690 | process_die (cu->dies, cu); |
c906108c | 2691 | |
fae299cd DC |
2692 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2693 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2694 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2695 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2696 | |
613e1657 | 2697 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2698 | |
2699 | /* Set symtab language to language from DW_AT_language. | |
2700 | If the compilation is from a C file generated by language preprocessors, | |
2701 | do not set the language if it was already deduced by start_subfile. */ | |
2702 | if (symtab != NULL | |
10b3939b | 2703 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2704 | { |
10b3939b | 2705 | symtab->language = cu->language; |
c906108c SS |
2706 | } |
2707 | pst->symtab = symtab; | |
2708 | pst->readin = 1; | |
c906108c SS |
2709 | |
2710 | do_cleanups (back_to); | |
2711 | } | |
2712 | ||
2713 | /* Process a die and its children. */ | |
2714 | ||
2715 | static void | |
e7c27a73 | 2716 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2717 | { |
2718 | switch (die->tag) | |
2719 | { | |
2720 | case DW_TAG_padding: | |
2721 | break; | |
2722 | case DW_TAG_compile_unit: | |
e7c27a73 | 2723 | read_file_scope (die, cu); |
c906108c SS |
2724 | break; |
2725 | case DW_TAG_subprogram: | |
e7c27a73 | 2726 | read_func_scope (die, cu); |
c906108c SS |
2727 | break; |
2728 | case DW_TAG_inlined_subroutine: | |
2729 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2730 | They could be used to set breakpoints on all inlined instances |
2731 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2732 | break; |
2733 | case DW_TAG_lexical_block: | |
14898363 L |
2734 | case DW_TAG_try_block: |
2735 | case DW_TAG_catch_block: | |
e7c27a73 | 2736 | read_lexical_block_scope (die, cu); |
c906108c SS |
2737 | break; |
2738 | case DW_TAG_class_type: | |
680b30c7 | 2739 | case DW_TAG_interface_type: |
c906108c SS |
2740 | case DW_TAG_structure_type: |
2741 | case DW_TAG_union_type: | |
134d01f1 | 2742 | process_structure_scope (die, cu); |
c906108c SS |
2743 | break; |
2744 | case DW_TAG_enumeration_type: | |
134d01f1 | 2745 | process_enumeration_scope (die, cu); |
c906108c | 2746 | break; |
134d01f1 | 2747 | |
f792889a DJ |
2748 | /* These dies have a type, but processing them does not create |
2749 | a symbol or recurse to process the children. Therefore we can | |
2750 | read them on-demand through read_type_die. */ | |
c906108c | 2751 | case DW_TAG_subroutine_type: |
72019c9c | 2752 | case DW_TAG_set_type: |
c906108c | 2753 | case DW_TAG_array_type: |
c906108c | 2754 | case DW_TAG_pointer_type: |
c906108c | 2755 | case DW_TAG_ptr_to_member_type: |
c906108c | 2756 | case DW_TAG_reference_type: |
c906108c | 2757 | case DW_TAG_string_type: |
c906108c | 2758 | break; |
134d01f1 | 2759 | |
c906108c | 2760 | case DW_TAG_base_type: |
a02abb62 | 2761 | case DW_TAG_subrange_type: |
134d01f1 DJ |
2762 | /* Add a typedef symbol for the type definition, if it has a |
2763 | DW_AT_name. */ | |
f792889a | 2764 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 2765 | break; |
c906108c | 2766 | case DW_TAG_common_block: |
e7c27a73 | 2767 | read_common_block (die, cu); |
c906108c SS |
2768 | break; |
2769 | case DW_TAG_common_inclusion: | |
2770 | break; | |
d9fa45fe | 2771 | case DW_TAG_namespace: |
63d06c5c | 2772 | processing_has_namespace_info = 1; |
e7c27a73 | 2773 | read_namespace (die, cu); |
d9fa45fe DC |
2774 | break; |
2775 | case DW_TAG_imported_declaration: | |
2776 | case DW_TAG_imported_module: | |
2777 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2778 | information contained in these. DW_TAG_imported_declaration | |
2779 | dies shouldn't have children; DW_TAG_imported_module dies | |
2780 | shouldn't in the C++ case, but conceivably could in the | |
2781 | Fortran case, so we'll have to replace this gdb_assert if | |
2782 | Fortran compilers start generating that info. */ | |
63d06c5c | 2783 | processing_has_namespace_info = 1; |
639d11d3 | 2784 | gdb_assert (die->child == NULL); |
d9fa45fe | 2785 | break; |
c906108c | 2786 | default: |
e7c27a73 | 2787 | new_symbol (die, NULL, cu); |
c906108c SS |
2788 | break; |
2789 | } | |
2790 | } | |
2791 | ||
5fb290d7 | 2792 | static void |
e142c38c | 2793 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2794 | { |
e142c38c | 2795 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2796 | } |
2797 | ||
cb1df416 DJ |
2798 | static void |
2799 | free_cu_line_header (void *arg) | |
2800 | { | |
2801 | struct dwarf2_cu *cu = arg; | |
2802 | ||
2803 | free_line_header (cu->line_header); | |
2804 | cu->line_header = NULL; | |
2805 | } | |
2806 | ||
c906108c | 2807 | static void |
e7c27a73 | 2808 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2809 | { |
e7c27a73 DJ |
2810 | struct objfile *objfile = cu->objfile; |
2811 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2812 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2813 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2814 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2815 | struct attribute *attr; | |
e1024ff1 | 2816 | char *name = NULL; |
c906108c SS |
2817 | char *comp_dir = NULL; |
2818 | struct die_info *child_die; | |
2819 | bfd *abfd = objfile->obfd; | |
debd256d | 2820 | struct line_header *line_header = 0; |
e142c38c DJ |
2821 | CORE_ADDR baseaddr; |
2822 | ||
2823 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2824 | |
fae299cd | 2825 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2826 | |
2827 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2828 | from finish_block. */ | |
2acceee2 | 2829 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2830 | lowpc = highpc; |
2831 | lowpc += baseaddr; | |
2832 | highpc += baseaddr; | |
2833 | ||
39cbfefa DJ |
2834 | /* Find the filename. Do not use dwarf2_name here, since the filename |
2835 | is not a source language identifier. */ | |
e142c38c | 2836 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2837 | if (attr) |
2838 | { | |
2839 | name = DW_STRING (attr); | |
2840 | } | |
e1024ff1 | 2841 | |
e142c38c | 2842 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 2843 | if (attr) |
e1024ff1 DJ |
2844 | comp_dir = DW_STRING (attr); |
2845 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 2846 | { |
e1024ff1 DJ |
2847 | comp_dir = ldirname (name); |
2848 | if (comp_dir != NULL) | |
2849 | make_cleanup (xfree, comp_dir); | |
2850 | } | |
2851 | if (comp_dir != NULL) | |
2852 | { | |
2853 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2854 | directory, get rid of it. */ | |
2855 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 2856 | |
e1024ff1 DJ |
2857 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
2858 | comp_dir = cp + 1; | |
c906108c SS |
2859 | } |
2860 | ||
e1024ff1 DJ |
2861 | if (name == NULL) |
2862 | name = "<unknown>"; | |
2863 | ||
e142c38c | 2864 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2865 | if (attr) |
2866 | { | |
e142c38c | 2867 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2868 | } |
2869 | ||
b0f35d58 DL |
2870 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
2871 | if (attr) | |
2872 | cu->producer = DW_STRING (attr); | |
303b6f5d | 2873 | |
c906108c SS |
2874 | /* We assume that we're processing GCC output. */ |
2875 | processing_gcc_compilation = 2; | |
c906108c | 2876 | |
c906108c SS |
2877 | start_symtab (name, comp_dir, lowpc); |
2878 | record_debugformat ("DWARF 2"); | |
303b6f5d | 2879 | record_producer (cu->producer); |
c906108c | 2880 | |
e142c38c | 2881 | initialize_cu_func_list (cu); |
c906108c | 2882 | |
cb1df416 DJ |
2883 | /* Decode line number information if present. We do this before |
2884 | processing child DIEs, so that the line header table is available | |
2885 | for DW_AT_decl_file. */ | |
e142c38c | 2886 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2887 | if (attr) |
2888 | { | |
debd256d | 2889 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2890 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2891 | if (line_header) |
2892 | { | |
cb1df416 DJ |
2893 | cu->line_header = line_header; |
2894 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 2895 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2896 | } |
5fb290d7 | 2897 | } |
debd256d | 2898 | |
cb1df416 DJ |
2899 | /* Process all dies in compilation unit. */ |
2900 | if (die->child != NULL) | |
2901 | { | |
2902 | child_die = die->child; | |
2903 | while (child_die && child_die->tag) | |
2904 | { | |
2905 | process_die (child_die, cu); | |
2906 | child_die = sibling_die (child_die); | |
2907 | } | |
2908 | } | |
2909 | ||
2e276125 JB |
2910 | /* Decode macro information, if present. Dwarf 2 macro information |
2911 | refers to information in the line number info statement program | |
2912 | header, so we can only read it if we've read the header | |
2913 | successfully. */ | |
e142c38c | 2914 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2915 | if (attr && line_header) |
2e276125 JB |
2916 | { |
2917 | unsigned int macro_offset = DW_UNSND (attr); | |
2918 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2919 | comp_dir, abfd, cu); |
2e276125 | 2920 | } |
debd256d | 2921 | do_cleanups (back_to); |
5fb290d7 DJ |
2922 | } |
2923 | ||
2924 | static void | |
e142c38c DJ |
2925 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2926 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2927 | { |
2928 | struct function_range *thisfn; | |
2929 | ||
2930 | thisfn = (struct function_range *) | |
7b5a2f43 | 2931 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2932 | thisfn->name = name; |
2933 | thisfn->lowpc = lowpc; | |
2934 | thisfn->highpc = highpc; | |
2935 | thisfn->seen_line = 0; | |
2936 | thisfn->next = NULL; | |
2937 | ||
e142c38c DJ |
2938 | if (cu->last_fn == NULL) |
2939 | cu->first_fn = thisfn; | |
5fb290d7 | 2940 | else |
e142c38c | 2941 | cu->last_fn->next = thisfn; |
5fb290d7 | 2942 | |
e142c38c | 2943 | cu->last_fn = thisfn; |
c906108c SS |
2944 | } |
2945 | ||
2946 | static void | |
e7c27a73 | 2947 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2948 | { |
e7c27a73 | 2949 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2950 | struct context_stack *new; |
c906108c SS |
2951 | CORE_ADDR lowpc; |
2952 | CORE_ADDR highpc; | |
2953 | struct die_info *child_die; | |
2954 | struct attribute *attr; | |
2955 | char *name; | |
fdde2d81 DC |
2956 | const char *previous_prefix = processing_current_prefix; |
2957 | struct cleanup *back_to = NULL; | |
e142c38c | 2958 | CORE_ADDR baseaddr; |
801e3a5b | 2959 | struct block *block; |
c906108c | 2960 | |
e142c38c DJ |
2961 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2962 | ||
2963 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2964 | |
2965 | /* Ignore functions with missing or empty names and functions with | |
2966 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2967 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2968 | return; |
2969 | ||
987504bb JJ |
2970 | if (cu->language == language_cplus |
2971 | || cu->language == language_java) | |
fdde2d81 | 2972 | { |
086ed43d | 2973 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2974 | |
2a35147e JB |
2975 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2976 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2977 | given the code | |
2978 | ||
2979 | namespace N { | |
2980 | void foo() { | |
2981 | // Definition of N::foo. | |
2982 | } | |
2983 | } | |
2984 | ||
2985 | then we'll have a tree of DIEs like this: | |
2986 | ||
2987 | 1: DW_TAG_compile_unit | |
2988 | 2: DW_TAG_namespace // N | |
2989 | 3: DW_TAG_subprogram // declaration of N::foo | |
2990 | 4: DW_TAG_subprogram // definition of N::foo | |
2991 | DW_AT_specification // refers to die #3 | |
2992 | ||
2993 | Thus, when processing die #4, we have to pretend that we're | |
2994 | in the context of its DW_AT_specification, namely the contex | |
2995 | of die #3. */ | |
fdde2d81 DC |
2996 | |
2997 | if (spec_die != NULL) | |
2998 | { | |
e142c38c | 2999 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
3000 | processing_current_prefix = specification_prefix; |
3001 | back_to = make_cleanup (xfree, specification_prefix); | |
3002 | } | |
3003 | } | |
3004 | ||
c906108c SS |
3005 | lowpc += baseaddr; |
3006 | highpc += baseaddr; | |
3007 | ||
5fb290d7 | 3008 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 3009 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3010 | |
c906108c | 3011 | new = push_context (0, lowpc); |
f792889a | 3012 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3013 | |
4cecd739 DJ |
3014 | /* If there is a location expression for DW_AT_frame_base, record |
3015 | it. */ | |
e142c38c | 3016 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3017 | if (attr) |
c034e007 AC |
3018 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3019 | expression is being recorded directly in the function's symbol | |
3020 | and not in a separate frame-base object. I guess this hack is | |
3021 | to avoid adding some sort of frame-base adjunct/annex to the | |
3022 | function's symbol :-(. The problem with doing this is that it | |
3023 | results in a function symbol with a location expression that | |
3024 | has nothing to do with the location of the function, ouch! The | |
3025 | relationship should be: a function's symbol has-a frame base; a | |
3026 | frame-base has-a location expression. */ | |
e7c27a73 | 3027 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3028 | |
e142c38c | 3029 | cu->list_in_scope = &local_symbols; |
c906108c | 3030 | |
639d11d3 | 3031 | if (die->child != NULL) |
c906108c | 3032 | { |
639d11d3 | 3033 | child_die = die->child; |
c906108c SS |
3034 | while (child_die && child_die->tag) |
3035 | { | |
e7c27a73 | 3036 | process_die (child_die, cu); |
c906108c SS |
3037 | child_die = sibling_die (child_die); |
3038 | } | |
3039 | } | |
3040 | ||
3041 | new = pop_context (); | |
3042 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3043 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3044 | lowpc, highpc, objfile); | |
3045 | ||
3046 | /* If we have address ranges, record them. */ | |
3047 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3048 | |
3049 | /* In C++, we can have functions nested inside functions (e.g., when | |
3050 | a function declares a class that has methods). This means that | |
3051 | when we finish processing a function scope, we may need to go | |
3052 | back to building a containing block's symbol lists. */ | |
3053 | local_symbols = new->locals; | |
3054 | param_symbols = new->params; | |
3055 | ||
921e78cf JB |
3056 | /* If we've finished processing a top-level function, subsequent |
3057 | symbols go in the file symbol list. */ | |
3058 | if (outermost_context_p ()) | |
e142c38c | 3059 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
3060 | |
3061 | processing_current_prefix = previous_prefix; | |
3062 | if (back_to != NULL) | |
3063 | do_cleanups (back_to); | |
c906108c SS |
3064 | } |
3065 | ||
3066 | /* Process all the DIES contained within a lexical block scope. Start | |
3067 | a new scope, process the dies, and then close the scope. */ | |
3068 | ||
3069 | static void | |
e7c27a73 | 3070 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3071 | { |
e7c27a73 | 3072 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3073 | struct context_stack *new; |
c906108c SS |
3074 | CORE_ADDR lowpc, highpc; |
3075 | struct die_info *child_die; | |
e142c38c DJ |
3076 | CORE_ADDR baseaddr; |
3077 | ||
3078 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3079 | |
3080 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3081 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3082 | as multiple lexical blocks? Handling children in a sane way would | |
3083 | be nasty. Might be easier to properly extend generic blocks to | |
3084 | describe ranges. */ | |
e7c27a73 | 3085 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3086 | return; |
3087 | lowpc += baseaddr; | |
3088 | highpc += baseaddr; | |
3089 | ||
3090 | push_context (0, lowpc); | |
639d11d3 | 3091 | if (die->child != NULL) |
c906108c | 3092 | { |
639d11d3 | 3093 | child_die = die->child; |
c906108c SS |
3094 | while (child_die && child_die->tag) |
3095 | { | |
e7c27a73 | 3096 | process_die (child_die, cu); |
c906108c SS |
3097 | child_die = sibling_die (child_die); |
3098 | } | |
3099 | } | |
3100 | new = pop_context (); | |
3101 | ||
3102 | if (local_symbols != NULL) | |
3103 | { | |
801e3a5b JB |
3104 | struct block *block |
3105 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3106 | highpc, objfile); | |
3107 | ||
3108 | /* Note that recording ranges after traversing children, as we | |
3109 | do here, means that recording a parent's ranges entails | |
3110 | walking across all its children's ranges as they appear in | |
3111 | the address map, which is quadratic behavior. | |
3112 | ||
3113 | It would be nicer to record the parent's ranges before | |
3114 | traversing its children, simply overriding whatever you find | |
3115 | there. But since we don't even decide whether to create a | |
3116 | block until after we've traversed its children, that's hard | |
3117 | to do. */ | |
3118 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3119 | } |
3120 | local_symbols = new->locals; | |
3121 | } | |
3122 | ||
43039443 | 3123 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3124 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3125 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3126 | |
3127 | static int | |
3128 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3129 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3130 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3131 | { |
3132 | struct objfile *objfile = cu->objfile; | |
3133 | struct comp_unit_head *cu_header = &cu->header; | |
3134 | bfd *obfd = objfile->obfd; | |
3135 | unsigned int addr_size = cu_header->addr_size; | |
3136 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3137 | /* Base address selection entry. */ | |
3138 | CORE_ADDR base; | |
3139 | int found_base; | |
3140 | unsigned int dummy; | |
3141 | gdb_byte *buffer; | |
3142 | CORE_ADDR marker; | |
3143 | int low_set; | |
3144 | CORE_ADDR low = 0; | |
3145 | CORE_ADDR high = 0; | |
ff013f42 | 3146 | CORE_ADDR baseaddr; |
43039443 JK |
3147 | |
3148 | found_base = cu_header->base_known; | |
3149 | base = cu_header->base_address; | |
3150 | ||
3151 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3152 | { | |
3153 | complaint (&symfile_complaints, | |
3154 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
3155 | offset); | |
3156 | return 0; | |
3157 | } | |
3158 | buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3159 | ||
3160 | /* Read in the largest possible address. */ | |
3161 | marker = read_address (obfd, buffer, cu, &dummy); | |
3162 | if ((marker & mask) == mask) | |
3163 | { | |
3164 | /* If we found the largest possible address, then | |
3165 | read the base address. */ | |
3166 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3167 | buffer += 2 * addr_size; | |
3168 | offset += 2 * addr_size; | |
3169 | found_base = 1; | |
3170 | } | |
3171 | ||
3172 | low_set = 0; | |
3173 | ||
e7030f15 | 3174 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 3175 | |
43039443 JK |
3176 | while (1) |
3177 | { | |
3178 | CORE_ADDR range_beginning, range_end; | |
3179 | ||
3180 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
3181 | buffer += addr_size; | |
3182 | range_end = read_address (obfd, buffer, cu, &dummy); | |
3183 | buffer += addr_size; | |
3184 | offset += 2 * addr_size; | |
3185 | ||
3186 | /* An end of list marker is a pair of zero addresses. */ | |
3187 | if (range_beginning == 0 && range_end == 0) | |
3188 | /* Found the end of list entry. */ | |
3189 | break; | |
3190 | ||
3191 | /* Each base address selection entry is a pair of 2 values. | |
3192 | The first is the largest possible address, the second is | |
3193 | the base address. Check for a base address here. */ | |
3194 | if ((range_beginning & mask) == mask) | |
3195 | { | |
3196 | /* If we found the largest possible address, then | |
3197 | read the base address. */ | |
3198 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3199 | found_base = 1; | |
3200 | continue; | |
3201 | } | |
3202 | ||
3203 | if (!found_base) | |
3204 | { | |
3205 | /* We have no valid base address for the ranges | |
3206 | data. */ | |
3207 | complaint (&symfile_complaints, | |
3208 | _("Invalid .debug_ranges data (no base address)")); | |
3209 | return 0; | |
3210 | } | |
3211 | ||
3212 | range_beginning += base; | |
3213 | range_end += base; | |
3214 | ||
ff013f42 JK |
3215 | if (ranges_pst != NULL && range_beginning < range_end) |
3216 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3217 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
3218 | ranges_pst); | |
3219 | ||
43039443 JK |
3220 | /* FIXME: This is recording everything as a low-high |
3221 | segment of consecutive addresses. We should have a | |
3222 | data structure for discontiguous block ranges | |
3223 | instead. */ | |
3224 | if (! low_set) | |
3225 | { | |
3226 | low = range_beginning; | |
3227 | high = range_end; | |
3228 | low_set = 1; | |
3229 | } | |
3230 | else | |
3231 | { | |
3232 | if (range_beginning < low) | |
3233 | low = range_beginning; | |
3234 | if (range_end > high) | |
3235 | high = range_end; | |
3236 | } | |
3237 | } | |
3238 | ||
3239 | if (! low_set) | |
3240 | /* If the first entry is an end-of-list marker, the range | |
3241 | describes an empty scope, i.e. no instructions. */ | |
3242 | return 0; | |
3243 | ||
3244 | if (low_return) | |
3245 | *low_return = low; | |
3246 | if (high_return) | |
3247 | *high_return = high; | |
3248 | return 1; | |
3249 | } | |
3250 | ||
af34e669 DJ |
3251 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3252 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3253 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3254 | static int |
af34e669 | 3255 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3256 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c SS |
3257 | { |
3258 | struct attribute *attr; | |
af34e669 DJ |
3259 | CORE_ADDR low = 0; |
3260 | CORE_ADDR high = 0; | |
3261 | int ret = 0; | |
c906108c | 3262 | |
e142c38c | 3263 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3264 | if (attr) |
af34e669 DJ |
3265 | { |
3266 | high = DW_ADDR (attr); | |
e142c38c | 3267 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3268 | if (attr) |
3269 | low = DW_ADDR (attr); | |
3270 | else | |
3271 | /* Found high w/o low attribute. */ | |
3272 | return 0; | |
3273 | ||
3274 | /* Found consecutive range of addresses. */ | |
3275 | ret = 1; | |
3276 | } | |
c906108c | 3277 | else |
af34e669 | 3278 | { |
e142c38c | 3279 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3280 | if (attr != NULL) |
3281 | { | |
af34e669 | 3282 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 3283 | .debug_ranges section. */ |
ff013f42 | 3284 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL)) |
af34e669 | 3285 | return 0; |
43039443 | 3286 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
3287 | ret = -1; |
3288 | } | |
3289 | } | |
c906108c SS |
3290 | |
3291 | if (high < low) | |
3292 | return 0; | |
3293 | ||
3294 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3295 | eliminate duplicate copies of functions and vtables and such. | |
3296 | The linker will arbitrarily choose one and discard the others. | |
3297 | The AT_*_pc values for such functions refer to local labels in | |
3298 | these sections. If the section from that file was discarded, the | |
3299 | labels are not in the output, so the relocs get a value of 0. | |
3300 | If this is a discarded function, mark the pc bounds as invalid, | |
3301 | so that GDB will ignore it. */ | |
72dca2f5 | 3302 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3303 | return 0; |
3304 | ||
3305 | *lowpc = low; | |
3306 | *highpc = high; | |
af34e669 | 3307 | return ret; |
c906108c SS |
3308 | } |
3309 | ||
fae299cd DC |
3310 | /* Get the low and high pc's represented by the scope DIE, and store |
3311 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3312 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3313 | ||
3314 | static void | |
3315 | get_scope_pc_bounds (struct die_info *die, | |
3316 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3317 | struct dwarf2_cu *cu) | |
3318 | { | |
3319 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3320 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3321 | CORE_ADDR current_low, current_high; | |
3322 | ||
3323 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3324 | { | |
3325 | best_low = current_low; | |
3326 | best_high = current_high; | |
3327 | } | |
3328 | else | |
3329 | { | |
3330 | struct die_info *child = die->child; | |
3331 | ||
3332 | while (child && child->tag) | |
3333 | { | |
3334 | switch (child->tag) { | |
3335 | case DW_TAG_subprogram: | |
3336 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
3337 | { | |
3338 | best_low = min (best_low, current_low); | |
3339 | best_high = max (best_high, current_high); | |
3340 | } | |
3341 | break; | |
3342 | case DW_TAG_namespace: | |
3343 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3344 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3345 | that current GCC's always emit the DIEs corresponding | |
3346 | to definitions of methods of classes as children of a | |
3347 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3348 | the DIEs giving the declarations, which could be | |
3349 | anywhere). But I don't see any reason why the | |
3350 | standards says that they have to be there. */ | |
3351 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3352 | ||
3353 | if (current_low != ((CORE_ADDR) -1)) | |
3354 | { | |
3355 | best_low = min (best_low, current_low); | |
3356 | best_high = max (best_high, current_high); | |
3357 | } | |
3358 | break; | |
3359 | default: | |
3360 | /* Ignore. */ | |
3361 | break; | |
3362 | } | |
3363 | ||
3364 | child = sibling_die (child); | |
3365 | } | |
3366 | } | |
3367 | ||
3368 | *lowpc = best_low; | |
3369 | *highpc = best_high; | |
3370 | } | |
3371 | ||
801e3a5b JB |
3372 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
3373 | in DIE. */ | |
3374 | static void | |
3375 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
3376 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
3377 | { | |
3378 | struct attribute *attr; | |
3379 | ||
3380 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
3381 | if (attr) | |
3382 | { | |
3383 | CORE_ADDR high = DW_ADDR (attr); | |
3384 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3385 | if (attr) | |
3386 | { | |
3387 | CORE_ADDR low = DW_ADDR (attr); | |
3388 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
3389 | } | |
3390 | } | |
3391 | ||
3392 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
3393 | if (attr) | |
3394 | { | |
3395 | bfd *obfd = cu->objfile->obfd; | |
3396 | ||
3397 | /* The value of the DW_AT_ranges attribute is the offset of the | |
3398 | address range list in the .debug_ranges section. */ | |
3399 | unsigned long offset = DW_UNSND (attr); | |
3400 | gdb_byte *buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3401 | ||
3402 | /* For some target architectures, but not others, the | |
3403 | read_address function sign-extends the addresses it returns. | |
3404 | To recognize base address selection entries, we need a | |
3405 | mask. */ | |
3406 | unsigned int addr_size = cu->header.addr_size; | |
3407 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3408 | ||
3409 | /* The base address, to which the next pair is relative. Note | |
3410 | that this 'base' is a DWARF concept: most entries in a range | |
3411 | list are relative, to reduce the number of relocs against the | |
3412 | debugging information. This is separate from this function's | |
3413 | 'baseaddr' argument, which GDB uses to relocate debugging | |
3414 | information from a shared library based on the address at | |
3415 | which the library was loaded. */ | |
3416 | CORE_ADDR base = cu->header.base_address; | |
3417 | int base_known = cu->header.base_known; | |
3418 | ||
3419 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3420 | { | |
3421 | complaint (&symfile_complaints, | |
3422 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
3423 | offset); | |
3424 | return; | |
3425 | } | |
3426 | ||
3427 | for (;;) | |
3428 | { | |
3429 | unsigned int bytes_read; | |
3430 | CORE_ADDR start, end; | |
3431 | ||
3432 | start = read_address (obfd, buffer, cu, &bytes_read); | |
3433 | buffer += bytes_read; | |
3434 | end = read_address (obfd, buffer, cu, &bytes_read); | |
3435 | buffer += bytes_read; | |
3436 | ||
3437 | /* Did we find the end of the range list? */ | |
3438 | if (start == 0 && end == 0) | |
3439 | break; | |
3440 | ||
3441 | /* Did we find a base address selection entry? */ | |
3442 | else if ((start & base_select_mask) == base_select_mask) | |
3443 | { | |
3444 | base = end; | |
3445 | base_known = 1; | |
3446 | } | |
3447 | ||
3448 | /* We found an ordinary address range. */ | |
3449 | else | |
3450 | { | |
3451 | if (!base_known) | |
3452 | { | |
3453 | complaint (&symfile_complaints, | |
3454 | _("Invalid .debug_ranges data (no base address)")); | |
3455 | return; | |
3456 | } | |
3457 | ||
3458 | record_block_range (block, | |
3459 | baseaddr + base + start, | |
3460 | baseaddr + base + end - 1); | |
3461 | } | |
3462 | } | |
3463 | } | |
3464 | } | |
3465 | ||
c906108c SS |
3466 | /* Add an aggregate field to the field list. */ |
3467 | ||
3468 | static void | |
107d2387 | 3469 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3470 | struct dwarf2_cu *cu) |
3471 | { | |
3472 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 3473 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
3474 | struct nextfield *new_field; |
3475 | struct attribute *attr; | |
3476 | struct field *fp; | |
3477 | char *fieldname = ""; | |
3478 | ||
3479 | /* Allocate a new field list entry and link it in. */ | |
3480 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3481 | make_cleanup (xfree, new_field); |
c906108c SS |
3482 | memset (new_field, 0, sizeof (struct nextfield)); |
3483 | new_field->next = fip->fields; | |
3484 | fip->fields = new_field; | |
3485 | fip->nfields++; | |
3486 | ||
3487 | /* Handle accessibility and virtuality of field. | |
3488 | The default accessibility for members is public, the default | |
3489 | accessibility for inheritance is private. */ | |
3490 | if (die->tag != DW_TAG_inheritance) | |
3491 | new_field->accessibility = DW_ACCESS_public; | |
3492 | else | |
3493 | new_field->accessibility = DW_ACCESS_private; | |
3494 | new_field->virtuality = DW_VIRTUALITY_none; | |
3495 | ||
e142c38c | 3496 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3497 | if (attr) |
3498 | new_field->accessibility = DW_UNSND (attr); | |
3499 | if (new_field->accessibility != DW_ACCESS_public) | |
3500 | fip->non_public_fields = 1; | |
e142c38c | 3501 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3502 | if (attr) |
3503 | new_field->virtuality = DW_UNSND (attr); | |
3504 | ||
3505 | fp = &new_field->field; | |
a9a9bd0f | 3506 | |
e142c38c | 3507 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3508 | { |
a9a9bd0f DC |
3509 | /* Data member other than a C++ static data member. */ |
3510 | ||
c906108c | 3511 | /* Get type of field. */ |
e7c27a73 | 3512 | fp->type = die_type (die, cu); |
c906108c | 3513 | |
01ad7f36 DJ |
3514 | FIELD_STATIC_KIND (*fp) = 0; |
3515 | ||
c906108c | 3516 | /* Get bit size of field (zero if none). */ |
e142c38c | 3517 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3518 | if (attr) |
3519 | { | |
3520 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3521 | } | |
3522 | else | |
3523 | { | |
3524 | FIELD_BITSIZE (*fp) = 0; | |
3525 | } | |
3526 | ||
3527 | /* Get bit offset of field. */ | |
e142c38c | 3528 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3529 | if (attr) |
3530 | { | |
c6a0999f JB |
3531 | int byte_offset; |
3532 | ||
3690dd37 JB |
3533 | if (attr_form_is_section_offset (attr)) |
3534 | { | |
3535 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 3536 | byte_offset = 0; |
3690dd37 JB |
3537 | } |
3538 | else if (attr_form_is_constant (attr)) | |
c6a0999f | 3539 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
3690dd37 | 3540 | else |
c6a0999f JB |
3541 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
3542 | ||
3543 | FIELD_BITPOS (*fp) = byte_offset * bits_per_byte; | |
c906108c SS |
3544 | } |
3545 | else | |
3546 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 3547 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3548 | if (attr) |
3549 | { | |
5e2b427d | 3550 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
3551 | { |
3552 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3553 | additional bit offset from the MSB of the containing |
3554 | anonymous object to the MSB of the field. We don't | |
3555 | have to do anything special since we don't need to | |
3556 | know the size of the anonymous object. */ | |
c906108c SS |
3557 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3558 | } | |
3559 | else | |
3560 | { | |
3561 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3562 | MSB of the anonymous object, subtract off the number of |
3563 | bits from the MSB of the field to the MSB of the | |
3564 | object, and then subtract off the number of bits of | |
3565 | the field itself. The result is the bit offset of | |
3566 | the LSB of the field. */ | |
c906108c SS |
3567 | int anonymous_size; |
3568 | int bit_offset = DW_UNSND (attr); | |
3569 | ||
e142c38c | 3570 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3571 | if (attr) |
3572 | { | |
3573 | /* The size of the anonymous object containing | |
3574 | the bit field is explicit, so use the | |
3575 | indicated size (in bytes). */ | |
3576 | anonymous_size = DW_UNSND (attr); | |
3577 | } | |
3578 | else | |
3579 | { | |
3580 | /* The size of the anonymous object containing | |
3581 | the bit field must be inferred from the type | |
3582 | attribute of the data member containing the | |
3583 | bit field. */ | |
3584 | anonymous_size = TYPE_LENGTH (fp->type); | |
3585 | } | |
3586 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3587 | - bit_offset - FIELD_BITSIZE (*fp); | |
3588 | } | |
3589 | } | |
3590 | ||
3591 | /* Get name of field. */ | |
39cbfefa DJ |
3592 | fieldname = dwarf2_name (die, cu); |
3593 | if (fieldname == NULL) | |
3594 | fieldname = ""; | |
d8151005 DJ |
3595 | |
3596 | /* The name is already allocated along with this objfile, so we don't | |
3597 | need to duplicate it for the type. */ | |
3598 | fp->name = fieldname; | |
c906108c SS |
3599 | |
3600 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3601 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3602 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3603 | { |
3604 | new_field->accessibility = DW_ACCESS_private; | |
3605 | fip->non_public_fields = 1; | |
3606 | } | |
3607 | } | |
a9a9bd0f | 3608 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3609 | { |
a9a9bd0f DC |
3610 | /* C++ static member. */ |
3611 | ||
3612 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3613 | is a declaration, but all versions of G++ as of this writing | |
3614 | (so through at least 3.2.1) incorrectly generate | |
3615 | DW_TAG_variable tags. */ | |
3616 | ||
c906108c | 3617 | char *physname; |
c906108c | 3618 | |
a9a9bd0f | 3619 | /* Get name of field. */ |
39cbfefa DJ |
3620 | fieldname = dwarf2_name (die, cu); |
3621 | if (fieldname == NULL) | |
c906108c SS |
3622 | return; |
3623 | ||
2df3850c | 3624 | /* Get physical name. */ |
e142c38c | 3625 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3626 | |
d8151005 DJ |
3627 | /* The name is already allocated along with this objfile, so we don't |
3628 | need to duplicate it for the type. */ | |
3629 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3630 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3631 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3632 | } |
3633 | else if (die->tag == DW_TAG_inheritance) | |
3634 | { | |
3635 | /* C++ base class field. */ | |
e142c38c | 3636 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3637 | if (attr) |
e7c27a73 | 3638 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 3639 | * bits_per_byte); |
c906108c | 3640 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 3641 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 3642 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3643 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3644 | fip->nbaseclasses++; | |
3645 | } | |
3646 | } | |
3647 | ||
3648 | /* Create the vector of fields, and attach it to the type. */ | |
3649 | ||
3650 | static void | |
fba45db2 | 3651 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3652 | struct dwarf2_cu *cu) |
c906108c SS |
3653 | { |
3654 | int nfields = fip->nfields; | |
3655 | ||
3656 | /* Record the field count, allocate space for the array of fields, | |
3657 | and create blank accessibility bitfields if necessary. */ | |
3658 | TYPE_NFIELDS (type) = nfields; | |
3659 | TYPE_FIELDS (type) = (struct field *) | |
3660 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3661 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3662 | ||
3663 | if (fip->non_public_fields) | |
3664 | { | |
3665 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3666 | ||
3667 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3668 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3669 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3670 | ||
3671 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3672 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3673 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3674 | ||
3675 | TYPE_FIELD_IGNORE_BITS (type) = | |
3676 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3677 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3678 | } | |
3679 | ||
3680 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3681 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3682 | if (fip->nbaseclasses) | |
3683 | { | |
3684 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 3685 | unsigned char *pointer; |
c906108c SS |
3686 | |
3687 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
3688 | pointer = TYPE_ALLOC (type, num_bytes); |
3689 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
3690 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
3691 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3692 | } | |
3693 | ||
3694 | /* Copy the saved-up fields into the field vector. Start from the head | |
3695 | of the list, adding to the tail of the field array, so that they end | |
3696 | up in the same order in the array in which they were added to the list. */ | |
3697 | while (nfields-- > 0) | |
3698 | { | |
3699 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3700 | switch (fip->fields->accessibility) | |
3701 | { | |
c5aa993b JM |
3702 | case DW_ACCESS_private: |
3703 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3704 | break; | |
c906108c | 3705 | |
c5aa993b JM |
3706 | case DW_ACCESS_protected: |
3707 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3708 | break; | |
c906108c | 3709 | |
c5aa993b JM |
3710 | case DW_ACCESS_public: |
3711 | break; | |
c906108c | 3712 | |
c5aa993b JM |
3713 | default: |
3714 | /* Unknown accessibility. Complain and treat it as public. */ | |
3715 | { | |
e2e0b3e5 | 3716 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 3717 | fip->fields->accessibility); |
c5aa993b JM |
3718 | } |
3719 | break; | |
c906108c SS |
3720 | } |
3721 | if (nfields < fip->nbaseclasses) | |
3722 | { | |
3723 | switch (fip->fields->virtuality) | |
3724 | { | |
c5aa993b JM |
3725 | case DW_VIRTUALITY_virtual: |
3726 | case DW_VIRTUALITY_pure_virtual: | |
3727 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3728 | break; | |
c906108c SS |
3729 | } |
3730 | } | |
3731 | fip->fields = fip->fields->next; | |
3732 | } | |
3733 | } | |
3734 | ||
c906108c SS |
3735 | /* Add a member function to the proper fieldlist. */ |
3736 | ||
3737 | static void | |
107d2387 | 3738 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3739 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3740 | { |
e7c27a73 | 3741 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3742 | struct attribute *attr; |
3743 | struct fnfieldlist *flp; | |
3744 | int i; | |
3745 | struct fn_field *fnp; | |
3746 | char *fieldname; | |
3747 | char *physname; | |
3748 | struct nextfnfield *new_fnfield; | |
f792889a | 3749 | struct type *this_type; |
c906108c | 3750 | |
2df3850c | 3751 | /* Get name of member function. */ |
39cbfefa DJ |
3752 | fieldname = dwarf2_name (die, cu); |
3753 | if (fieldname == NULL) | |
2df3850c | 3754 | return; |
c906108c | 3755 | |
2df3850c | 3756 | /* Get the mangled name. */ |
e142c38c | 3757 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3758 | |
3759 | /* Look up member function name in fieldlist. */ | |
3760 | for (i = 0; i < fip->nfnfields; i++) | |
3761 | { | |
27bfe10e | 3762 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3763 | break; |
3764 | } | |
3765 | ||
3766 | /* Create new list element if necessary. */ | |
3767 | if (i < fip->nfnfields) | |
3768 | flp = &fip->fnfieldlists[i]; | |
3769 | else | |
3770 | { | |
3771 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3772 | { | |
3773 | fip->fnfieldlists = (struct fnfieldlist *) | |
3774 | xrealloc (fip->fnfieldlists, | |
3775 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3776 | * sizeof (struct fnfieldlist)); |
c906108c | 3777 | if (fip->nfnfields == 0) |
c13c43fd | 3778 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3779 | } |
3780 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3781 | flp->name = fieldname; | |
3782 | flp->length = 0; | |
3783 | flp->head = NULL; | |
3784 | fip->nfnfields++; | |
3785 | } | |
3786 | ||
3787 | /* Create a new member function field and chain it to the field list | |
3788 | entry. */ | |
3789 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3790 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3791 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3792 | new_fnfield->next = flp->head; | |
3793 | flp->head = new_fnfield; | |
3794 | flp->length++; | |
3795 | ||
3796 | /* Fill in the member function field info. */ | |
3797 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3798 | /* The name is already allocated along with this objfile, so we don't |
3799 | need to duplicate it for the type. */ | |
3800 | fnp->physname = physname ? physname : ""; | |
c906108c | 3801 | fnp->type = alloc_type (objfile); |
f792889a DJ |
3802 | this_type = read_type_die (die, cu); |
3803 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 3804 | { |
f792889a | 3805 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 3806 | |
f792889a | 3807 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
3808 | of the method itself (TYPE_CODE_METHOD). */ |
3809 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
3810 | TYPE_TARGET_TYPE (this_type), |
3811 | TYPE_FIELDS (this_type), | |
3812 | TYPE_NFIELDS (this_type), | |
3813 | TYPE_VARARGS (this_type)); | |
c906108c SS |
3814 | |
3815 | /* Handle static member functions. | |
c5aa993b JM |
3816 | Dwarf2 has no clean way to discern C++ static and non-static |
3817 | member functions. G++ helps GDB by marking the first | |
3818 | parameter for non-static member functions (which is the | |
3819 | this pointer) as artificial. We obtain this information | |
3820 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 3821 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
3822 | fnp->voffset = VOFFSET_STATIC; |
3823 | } | |
3824 | else | |
e2e0b3e5 | 3825 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 3826 | physname); |
c906108c SS |
3827 | |
3828 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3829 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3830 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3831 | |
3832 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3833 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3834 | ||
3835 | /* Get accessibility. */ | |
e142c38c | 3836 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3837 | if (attr) |
3838 | { | |
3839 | switch (DW_UNSND (attr)) | |
3840 | { | |
c5aa993b JM |
3841 | case DW_ACCESS_private: |
3842 | fnp->is_private = 1; | |
3843 | break; | |
3844 | case DW_ACCESS_protected: | |
3845 | fnp->is_protected = 1; | |
3846 | break; | |
c906108c SS |
3847 | } |
3848 | } | |
3849 | ||
b02dede2 | 3850 | /* Check for artificial methods. */ |
e142c38c | 3851 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3852 | if (attr && DW_UNSND (attr) != 0) |
3853 | fnp->is_artificial = 1; | |
3854 | ||
c906108c | 3855 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3856 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3857 | if (attr) |
8e19ed76 PS |
3858 | { |
3859 | /* Support the .debug_loc offsets */ | |
3860 | if (attr_form_is_block (attr)) | |
3861 | { | |
e7c27a73 | 3862 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 3863 | } |
3690dd37 | 3864 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 3865 | { |
4d3c2250 | 3866 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3867 | } |
3868 | else | |
3869 | { | |
4d3c2250 KB |
3870 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3871 | fieldname); | |
8e19ed76 PS |
3872 | } |
3873 | } | |
c906108c SS |
3874 | } |
3875 | ||
3876 | /* Create the vector of member function fields, and attach it to the type. */ | |
3877 | ||
3878 | static void | |
fba45db2 | 3879 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3880 | struct dwarf2_cu *cu) |
c906108c SS |
3881 | { |
3882 | struct fnfieldlist *flp; | |
3883 | int total_length = 0; | |
3884 | int i; | |
3885 | ||
3886 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3887 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3888 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3889 | ||
3890 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3891 | { | |
3892 | struct nextfnfield *nfp = flp->head; | |
3893 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3894 | int k; | |
3895 | ||
3896 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3897 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3898 | fn_flp->fn_fields = (struct fn_field *) | |
3899 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3900 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3901 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3902 | |
3903 | total_length += flp->length; | |
3904 | } | |
3905 | ||
3906 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3907 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3908 | } | |
3909 | ||
1168df01 JB |
3910 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
3911 | language, zero otherwise. */ | |
3912 | static int | |
3913 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
3914 | { | |
3915 | static const char vptr[] = "_vptr"; | |
987504bb | 3916 | static const char vtable[] = "vtable"; |
1168df01 | 3917 | |
987504bb JJ |
3918 | /* Look for the C++ and Java forms of the vtable. */ |
3919 | if ((cu->language == language_java | |
3920 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
3921 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
3922 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
3923 | return 1; |
3924 | ||
3925 | return 0; | |
3926 | } | |
3927 | ||
c0dd20ea DJ |
3928 | /* GCC outputs unnamed structures that are really pointers to member |
3929 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
3930 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
3931 | zero. |
3932 | ||
3933 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
3934 | This is GCC PR debug/28767. */ | |
c0dd20ea | 3935 | |
f792889a | 3936 | static struct type * |
c0dd20ea DJ |
3937 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
3938 | { | |
3939 | struct objfile *objfile = cu->objfile; | |
3940 | struct type *type; | |
3941 | struct die_info *pfn_die, *delta_die; | |
3942 | struct attribute *pfn_name, *delta_name; | |
3943 | struct type *pfn_type, *domain_type; | |
3944 | ||
3945 | /* Check for a structure with no name and two children. */ | |
3946 | if (die->tag != DW_TAG_structure_type | |
3947 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
3948 | || die->child == NULL | |
3949 | || die->child->sibling == NULL | |
3950 | || (die->child->sibling->sibling != NULL | |
3951 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 3952 | return NULL; |
c0dd20ea DJ |
3953 | |
3954 | /* Check for __pfn and __delta members. */ | |
3955 | pfn_die = die->child; | |
3956 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
3957 | if (pfn_die->tag != DW_TAG_member | |
3958 | || pfn_name == NULL | |
3959 | || DW_STRING (pfn_name) == NULL | |
3960 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 3961 | return NULL; |
c0dd20ea DJ |
3962 | |
3963 | delta_die = pfn_die->sibling; | |
3964 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
3965 | if (delta_die->tag != DW_TAG_member | |
3966 | || delta_name == NULL | |
3967 | || DW_STRING (delta_name) == NULL | |
3968 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 3969 | return NULL; |
c0dd20ea DJ |
3970 | |
3971 | /* Find the type of the method. */ | |
3972 | pfn_type = die_type (pfn_die, cu); | |
3973 | if (pfn_type == NULL | |
3974 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
3975 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 3976 | return NULL; |
c0dd20ea DJ |
3977 | |
3978 | /* Look for the "this" argument. */ | |
3979 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
3980 | if (TYPE_NFIELDS (pfn_type) == 0 | |
3981 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 3982 | return NULL; |
c0dd20ea DJ |
3983 | |
3984 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
3985 | type = alloc_type (objfile); | |
3986 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
3987 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
3988 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 3989 | type = lookup_methodptr_type (type); |
f792889a | 3990 | return set_die_type (die, type, cu); |
c0dd20ea | 3991 | } |
1168df01 | 3992 | |
c906108c SS |
3993 | /* Called when we find the DIE that starts a structure or union scope |
3994 | (definition) to process all dies that define the members of the | |
3995 | structure or union. | |
3996 | ||
3997 | NOTE: we need to call struct_type regardless of whether or not the | |
3998 | DIE has an at_name attribute, since it might be an anonymous | |
3999 | structure or union. This gets the type entered into our set of | |
4000 | user defined types. | |
4001 | ||
4002 | However, if the structure is incomplete (an opaque struct/union) | |
4003 | then suppress creating a symbol table entry for it since gdb only | |
4004 | wants to find the one with the complete definition. Note that if | |
4005 | it is complete, we just call new_symbol, which does it's own | |
4006 | checking about whether the struct/union is anonymous or not (and | |
4007 | suppresses creating a symbol table entry itself). */ | |
4008 | ||
f792889a | 4009 | static struct type * |
134d01f1 | 4010 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4011 | { |
e7c27a73 | 4012 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4013 | struct type *type; |
4014 | struct attribute *attr; | |
63d06c5c DC |
4015 | const char *previous_prefix = processing_current_prefix; |
4016 | struct cleanup *back_to = NULL; | |
39cbfefa | 4017 | char *name; |
c906108c | 4018 | |
f792889a DJ |
4019 | type = quirk_gcc_member_function_pointer (die, cu); |
4020 | if (type) | |
4021 | return type; | |
c906108c | 4022 | |
c0dd20ea | 4023 | type = alloc_type (objfile); |
c906108c | 4024 | INIT_CPLUS_SPECIFIC (type); |
39cbfefa DJ |
4025 | name = dwarf2_name (die, cu); |
4026 | if (name != NULL) | |
c906108c | 4027 | { |
987504bb JJ |
4028 | if (cu->language == language_cplus |
4029 | || cu->language == language_java) | |
63d06c5c | 4030 | { |
8176b9b8 DC |
4031 | char *new_prefix = determine_class_name (die, cu); |
4032 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
4033 | strlen (new_prefix), | |
4034 | &objfile->objfile_obstack); | |
4035 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
4036 | processing_current_prefix = new_prefix; |
4037 | } | |
4038 | else | |
4039 | { | |
d8151005 DJ |
4040 | /* The name is already allocated along with this objfile, so |
4041 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4042 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4043 | } |
c906108c SS |
4044 | } |
4045 | ||
4046 | if (die->tag == DW_TAG_structure_type) | |
4047 | { | |
4048 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4049 | } | |
4050 | else if (die->tag == DW_TAG_union_type) | |
4051 | { | |
4052 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4053 | } | |
4054 | else | |
4055 | { | |
4056 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 4057 | in gdbtypes.h. */ |
c906108c SS |
4058 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
4059 | } | |
4060 | ||
e142c38c | 4061 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4062 | if (attr) |
4063 | { | |
4064 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4065 | } | |
4066 | else | |
4067 | { | |
4068 | TYPE_LENGTH (type) = 0; | |
4069 | } | |
4070 | ||
d77b6808 | 4071 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB_SUPPORTED; |
dc718098 JB |
4072 | if (die_is_declaration (die, cu)) |
4073 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4074 | ||
c906108c SS |
4075 | /* We need to add the type field to the die immediately so we don't |
4076 | infinitely recurse when dealing with pointers to the structure | |
4077 | type within the structure itself. */ | |
1c379e20 | 4078 | set_die_type (die, type, cu); |
c906108c | 4079 | |
e142c38c | 4080 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
4081 | { |
4082 | struct field_info fi; | |
4083 | struct die_info *child_die; | |
4084 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
4085 | ||
4086 | memset (&fi, 0, sizeof (struct field_info)); | |
4087 | ||
639d11d3 | 4088 | child_die = die->child; |
c906108c SS |
4089 | |
4090 | while (child_die && child_die->tag) | |
4091 | { | |
a9a9bd0f DC |
4092 | if (child_die->tag == DW_TAG_member |
4093 | || child_die->tag == DW_TAG_variable) | |
c906108c | 4094 | { |
a9a9bd0f DC |
4095 | /* NOTE: carlton/2002-11-05: A C++ static data member |
4096 | should be a DW_TAG_member that is a declaration, but | |
4097 | all versions of G++ as of this writing (so through at | |
4098 | least 3.2.1) incorrectly generate DW_TAG_variable | |
4099 | tags for them instead. */ | |
e7c27a73 | 4100 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4101 | } |
8713b1b1 | 4102 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
4103 | { |
4104 | /* C++ member function. */ | |
e7c27a73 | 4105 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
4106 | } |
4107 | else if (child_die->tag == DW_TAG_inheritance) | |
4108 | { | |
4109 | /* C++ base class field. */ | |
e7c27a73 | 4110 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4111 | } |
c906108c SS |
4112 | child_die = sibling_die (child_die); |
4113 | } | |
4114 | ||
4115 | /* Attach fields and member functions to the type. */ | |
4116 | if (fi.nfields) | |
e7c27a73 | 4117 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
4118 | if (fi.nfnfields) |
4119 | { | |
e7c27a73 | 4120 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 4121 | |
c5aa993b | 4122 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
4123 | class itself) which contains the vtable pointer for the current |
4124 | class from the DW_AT_containing_type attribute. */ | |
4125 | ||
e142c38c | 4126 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 4127 | { |
e7c27a73 | 4128 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
4129 | |
4130 | TYPE_VPTR_BASETYPE (type) = t; | |
4131 | if (type == t) | |
4132 | { | |
c906108c SS |
4133 | int i; |
4134 | ||
4135 | /* Our own class provides vtbl ptr. */ | |
4136 | for (i = TYPE_NFIELDS (t) - 1; | |
4137 | i >= TYPE_N_BASECLASSES (t); | |
4138 | --i) | |
4139 | { | |
4140 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
4141 | ||
1168df01 | 4142 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
4143 | { |
4144 | TYPE_VPTR_FIELDNO (type) = i; | |
4145 | break; | |
4146 | } | |
4147 | } | |
4148 | ||
4149 | /* Complain if virtual function table field not found. */ | |
4150 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 4151 | complaint (&symfile_complaints, |
e2e0b3e5 | 4152 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
4153 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
4154 | ""); | |
c906108c SS |
4155 | } |
4156 | else | |
4157 | { | |
4158 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4159 | } | |
4160 | } | |
f6235d4c EZ |
4161 | else if (cu->producer |
4162 | && strncmp (cu->producer, | |
4163 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
4164 | { | |
4165 | /* The IBM XLC compiler does not provide direct indication | |
4166 | of the containing type, but the vtable pointer is | |
4167 | always named __vfp. */ | |
4168 | ||
4169 | int i; | |
4170 | ||
4171 | for (i = TYPE_NFIELDS (type) - 1; | |
4172 | i >= TYPE_N_BASECLASSES (type); | |
4173 | --i) | |
4174 | { | |
4175 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
4176 | { | |
4177 | TYPE_VPTR_FIELDNO (type) = i; | |
4178 | TYPE_VPTR_BASETYPE (type) = type; | |
4179 | break; | |
4180 | } | |
4181 | } | |
4182 | } | |
c906108c SS |
4183 | } |
4184 | ||
c906108c SS |
4185 | do_cleanups (back_to); |
4186 | } | |
63d06c5c DC |
4187 | |
4188 | processing_current_prefix = previous_prefix; | |
4189 | if (back_to != NULL) | |
4190 | do_cleanups (back_to); | |
f792889a DJ |
4191 | |
4192 | return type; | |
c906108c SS |
4193 | } |
4194 | ||
134d01f1 DJ |
4195 | static void |
4196 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4197 | { | |
4198 | struct objfile *objfile = cu->objfile; | |
4199 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 4200 | struct die_info *child_die = die->child; |
f792889a | 4201 | struct type *this_type; |
c906108c | 4202 | |
f792889a DJ |
4203 | this_type = get_die_type (die, cu); |
4204 | if (this_type == NULL) | |
4205 | this_type = read_structure_type (die, cu); | |
4206 | if (TYPE_TAG_NAME (this_type) != NULL) | |
4207 | processing_current_prefix = TYPE_TAG_NAME (this_type); | |
c906108c | 4208 | |
90aeadfc DC |
4209 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4210 | snapshots) has been known to create a die giving a declaration | |
4211 | for a class that has, as a child, a die giving a definition for a | |
4212 | nested class. So we have to process our children even if the | |
4213 | current die is a declaration. Normally, of course, a declaration | |
4214 | won't have any children at all. */ | |
134d01f1 | 4215 | |
90aeadfc DC |
4216 | while (child_die != NULL && child_die->tag) |
4217 | { | |
4218 | if (child_die->tag == DW_TAG_member | |
4219 | || child_die->tag == DW_TAG_variable | |
4220 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4221 | { |
90aeadfc | 4222 | /* Do nothing. */ |
134d01f1 | 4223 | } |
90aeadfc DC |
4224 | else |
4225 | process_die (child_die, cu); | |
134d01f1 | 4226 | |
90aeadfc | 4227 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4228 | } |
4229 | ||
fa4028e9 JB |
4230 | /* Do not consider external references. According to the DWARF standard, |
4231 | these DIEs are identified by the fact that they have no byte_size | |
4232 | attribute, and a declaration attribute. */ | |
4233 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4234 | || !die_is_declaration (die, cu)) | |
f792889a | 4235 | new_symbol (die, this_type, cu); |
90aeadfc | 4236 | |
134d01f1 DJ |
4237 | processing_current_prefix = previous_prefix; |
4238 | } | |
4239 | ||
4240 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4241 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 4242 | |
f792889a | 4243 | static struct type * |
134d01f1 | 4244 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4245 | { |
e7c27a73 | 4246 | struct objfile *objfile = cu->objfile; |
c906108c | 4247 | struct type *type; |
c906108c | 4248 | struct attribute *attr; |
39cbfefa | 4249 | char *name; |
134d01f1 | 4250 | |
c906108c SS |
4251 | type = alloc_type (objfile); |
4252 | ||
4253 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
39cbfefa DJ |
4254 | name = dwarf2_name (die, cu); |
4255 | if (name != NULL) | |
c906108c | 4256 | { |
63d06c5c DC |
4257 | if (processing_has_namespace_info) |
4258 | { | |
987504bb JJ |
4259 | TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack, |
4260 | processing_current_prefix, | |
4261 | name, cu); | |
63d06c5c DC |
4262 | } |
4263 | else | |
4264 | { | |
d8151005 DJ |
4265 | /* The name is already allocated along with this objfile, so |
4266 | we don't need to duplicate it for the type. */ | |
4267 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 4268 | } |
c906108c SS |
4269 | } |
4270 | ||
e142c38c | 4271 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4272 | if (attr) |
4273 | { | |
4274 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4275 | } | |
4276 | else | |
4277 | { | |
4278 | TYPE_LENGTH (type) = 0; | |
4279 | } | |
4280 | ||
137033e9 JB |
4281 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
4282 | declared as private in the package spec, and then defined only | |
4283 | inside the package body. Such types are known as Taft Amendment | |
4284 | Types. When another package uses such a type, an incomplete DIE | |
4285 | may be generated by the compiler. */ | |
02eb380e JB |
4286 | if (die_is_declaration (die, cu)) |
4287 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4288 | ||
f792889a | 4289 | return set_die_type (die, type, cu); |
134d01f1 DJ |
4290 | } |
4291 | ||
8176b9b8 | 4292 | /* Determine the name of the type represented by DIE, which should be |
987504bb | 4293 | a named C++ or Java compound type. Return the name in question; the caller |
8176b9b8 DC |
4294 | is responsible for xfree()'ing it. */ |
4295 | ||
4296 | static char * | |
4297 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
4298 | { | |
4299 | struct cleanup *back_to = NULL; | |
4300 | struct die_info *spec_die = die_specification (die, cu); | |
4301 | char *new_prefix = NULL; | |
4302 | ||
4303 | /* If this is the definition of a class that is declared by another | |
4304 | die, then processing_current_prefix may not be accurate; see | |
4305 | read_func_scope for a similar example. */ | |
4306 | if (spec_die != NULL) | |
4307 | { | |
4308 | char *specification_prefix = determine_prefix (spec_die, cu); | |
4309 | processing_current_prefix = specification_prefix; | |
4310 | back_to = make_cleanup (xfree, specification_prefix); | |
4311 | } | |
4312 | ||
4313 | /* If we don't have namespace debug info, guess the name by trying | |
4314 | to demangle the names of members, just like we did in | |
72bf9492 | 4315 | guess_structure_name. */ |
8176b9b8 DC |
4316 | if (!processing_has_namespace_info) |
4317 | { | |
4318 | struct die_info *child; | |
4319 | ||
4320 | for (child = die->child; | |
4321 | child != NULL && child->tag != 0; | |
4322 | child = sibling_die (child)) | |
4323 | { | |
4324 | if (child->tag == DW_TAG_subprogram) | |
4325 | { | |
31c27f77 JJ |
4326 | new_prefix |
4327 | = language_class_name_from_physname (cu->language_defn, | |
4328 | dwarf2_linkage_name | |
8176b9b8 DC |
4329 | (child, cu)); |
4330 | ||
4331 | if (new_prefix != NULL) | |
4332 | break; | |
4333 | } | |
4334 | } | |
4335 | } | |
4336 | ||
4337 | if (new_prefix == NULL) | |
4338 | { | |
4339 | const char *name = dwarf2_name (die, cu); | |
987504bb JJ |
4340 | new_prefix = typename_concat (NULL, processing_current_prefix, |
4341 | name ? name : "<<anonymous>>", | |
4342 | cu); | |
8176b9b8 DC |
4343 | } |
4344 | ||
4345 | if (back_to != NULL) | |
4346 | do_cleanups (back_to); | |
4347 | ||
4348 | return new_prefix; | |
4349 | } | |
4350 | ||
134d01f1 DJ |
4351 | /* Given a pointer to a die which begins an enumeration, process all |
4352 | the dies that define the members of the enumeration, and create the | |
4353 | symbol for the enumeration type. | |
4354 | ||
4355 | NOTE: We reverse the order of the element list. */ | |
4356 | ||
4357 | static void | |
4358 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4359 | { | |
4360 | struct objfile *objfile = cu->objfile; | |
4361 | struct die_info *child_die; | |
4362 | struct field *fields; | |
134d01f1 DJ |
4363 | struct symbol *sym; |
4364 | int num_fields; | |
4365 | int unsigned_enum = 1; | |
39cbfefa | 4366 | char *name; |
f792889a | 4367 | struct type *this_type; |
134d01f1 | 4368 | |
c906108c SS |
4369 | num_fields = 0; |
4370 | fields = NULL; | |
f792889a DJ |
4371 | this_type = get_die_type (die, cu); |
4372 | if (this_type == NULL) | |
4373 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 4374 | if (die->child != NULL) |
c906108c | 4375 | { |
639d11d3 | 4376 | child_die = die->child; |
c906108c SS |
4377 | while (child_die && child_die->tag) |
4378 | { | |
4379 | if (child_die->tag != DW_TAG_enumerator) | |
4380 | { | |
e7c27a73 | 4381 | process_die (child_die, cu); |
c906108c SS |
4382 | } |
4383 | else | |
4384 | { | |
39cbfefa DJ |
4385 | name = dwarf2_name (child_die, cu); |
4386 | if (name) | |
c906108c | 4387 | { |
f792889a | 4388 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
4389 | if (SYMBOL_VALUE (sym) < 0) |
4390 | unsigned_enum = 0; | |
4391 | ||
4392 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4393 | { | |
4394 | fields = (struct field *) | |
4395 | xrealloc (fields, | |
4396 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4397 | * sizeof (struct field)); |
c906108c SS |
4398 | } |
4399 | ||
22abf04a | 4400 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
4401 | FIELD_TYPE (fields[num_fields]) = NULL; |
4402 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
4403 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 4404 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
4405 | |
4406 | num_fields++; | |
4407 | } | |
4408 | } | |
4409 | ||
4410 | child_die = sibling_die (child_die); | |
4411 | } | |
4412 | ||
4413 | if (num_fields) | |
4414 | { | |
f792889a DJ |
4415 | TYPE_NFIELDS (this_type) = num_fields; |
4416 | TYPE_FIELDS (this_type) = (struct field *) | |
4417 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
4418 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 4419 | sizeof (struct field) * num_fields); |
b8c9b27d | 4420 | xfree (fields); |
c906108c SS |
4421 | } |
4422 | if (unsigned_enum) | |
f792889a | 4423 | TYPE_FLAGS (this_type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 4424 | } |
134d01f1 | 4425 | |
f792889a | 4426 | new_symbol (die, this_type, cu); |
c906108c SS |
4427 | } |
4428 | ||
4429 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4430 | the DIE's type field. For now, this only handles one dimensional | |
4431 | arrays. */ | |
4432 | ||
f792889a | 4433 | static struct type * |
e7c27a73 | 4434 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4435 | { |
e7c27a73 | 4436 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4437 | struct die_info *child_die; |
4438 | struct type *type = NULL; | |
4439 | struct type *element_type, *range_type, *index_type; | |
4440 | struct type **range_types = NULL; | |
4441 | struct attribute *attr; | |
4442 | int ndim = 0; | |
4443 | struct cleanup *back_to; | |
39cbfefa | 4444 | char *name; |
c906108c | 4445 | |
e7c27a73 | 4446 | element_type = die_type (die, cu); |
c906108c SS |
4447 | |
4448 | /* Irix 6.2 native cc creates array types without children for | |
4449 | arrays with unspecified length. */ | |
639d11d3 | 4450 | if (die->child == NULL) |
c906108c | 4451 | { |
6ccb9162 | 4452 | index_type = builtin_type_int32; |
c906108c | 4453 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
4454 | type = create_array_type (NULL, element_type, range_type); |
4455 | return set_die_type (die, type, cu); | |
c906108c SS |
4456 | } |
4457 | ||
4458 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4459 | child_die = die->child; |
c906108c SS |
4460 | while (child_die && child_die->tag) |
4461 | { | |
4462 | if (child_die->tag == DW_TAG_subrange_type) | |
4463 | { | |
f792889a DJ |
4464 | struct type *child_type = read_type_die (child_die, cu); |
4465 | if (child_type != NULL) | |
a02abb62 JB |
4466 | { |
4467 | /* The range type was succesfully read. Save it for | |
4468 | the array type creation. */ | |
4469 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4470 | { | |
4471 | range_types = (struct type **) | |
4472 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4473 | * sizeof (struct type *)); | |
4474 | if (ndim == 0) | |
4475 | make_cleanup (free_current_contents, &range_types); | |
4476 | } | |
f792889a | 4477 | range_types[ndim++] = child_type; |
a02abb62 | 4478 | } |
c906108c SS |
4479 | } |
4480 | child_die = sibling_die (child_die); | |
4481 | } | |
4482 | ||
4483 | /* Dwarf2 dimensions are output from left to right, create the | |
4484 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4485 | |
c906108c | 4486 | type = element_type; |
7ca2d3a3 DL |
4487 | |
4488 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4489 | { | |
4490 | int i = 0; | |
4491 | while (i < ndim) | |
4492 | type = create_array_type (NULL, type, range_types[i++]); | |
4493 | } | |
4494 | else | |
4495 | { | |
4496 | while (ndim-- > 0) | |
4497 | type = create_array_type (NULL, type, range_types[ndim]); | |
4498 | } | |
c906108c | 4499 | |
f5f8a009 EZ |
4500 | /* Understand Dwarf2 support for vector types (like they occur on |
4501 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4502 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4503 | custom vendor extension. The main difference between a regular | |
4504 | array and the vector variant is that vectors are passed by value | |
4505 | to functions. */ | |
e142c38c | 4506 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 4507 | if (attr) |
ea37ba09 | 4508 | make_vector_type (type); |
f5f8a009 | 4509 | |
39cbfefa DJ |
4510 | name = dwarf2_name (die, cu); |
4511 | if (name) | |
4512 | TYPE_NAME (type) = name; | |
714e295e | 4513 | |
c906108c SS |
4514 | do_cleanups (back_to); |
4515 | ||
4516 | /* Install the type in the die. */ | |
f792889a | 4517 | return set_die_type (die, type, cu); |
c906108c SS |
4518 | } |
4519 | ||
7ca2d3a3 DL |
4520 | static enum dwarf_array_dim_ordering |
4521 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4522 | { | |
4523 | struct attribute *attr; | |
4524 | ||
4525 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4526 | ||
4527 | if (attr) return DW_SND (attr); | |
4528 | ||
4529 | /* | |
4530 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4531 | opposite order to the dwarf2 specification, but data is still | |
4532 | laid out as per normal fortran. | |
4533 | ||
4534 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4535 | version checking. | |
4536 | */ | |
4537 | ||
4538 | if (cu->language == language_fortran && | |
4539 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4540 | { | |
4541 | return DW_ORD_row_major; | |
4542 | } | |
4543 | ||
4544 | switch (cu->language_defn->la_array_ordering) | |
4545 | { | |
4546 | case array_column_major: | |
4547 | return DW_ORD_col_major; | |
4548 | case array_row_major: | |
4549 | default: | |
4550 | return DW_ORD_row_major; | |
4551 | }; | |
4552 | } | |
4553 | ||
72019c9c GM |
4554 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4555 | the DIE's type field. */ | |
4556 | ||
f792889a | 4557 | static struct type * |
72019c9c GM |
4558 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
4559 | { | |
f792889a DJ |
4560 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
4561 | ||
4562 | return set_die_type (die, set_type, cu); | |
72019c9c | 4563 | } |
7ca2d3a3 | 4564 | |
c906108c SS |
4565 | /* First cut: install each common block member as a global variable. */ |
4566 | ||
4567 | static void | |
e7c27a73 | 4568 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4569 | { |
4570 | struct die_info *child_die; | |
4571 | struct attribute *attr; | |
4572 | struct symbol *sym; | |
4573 | CORE_ADDR base = (CORE_ADDR) 0; | |
4574 | ||
e142c38c | 4575 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4576 | if (attr) |
4577 | { | |
8e19ed76 PS |
4578 | /* Support the .debug_loc offsets */ |
4579 | if (attr_form_is_block (attr)) | |
4580 | { | |
e7c27a73 | 4581 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 4582 | } |
3690dd37 | 4583 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4584 | { |
4d3c2250 | 4585 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4586 | } |
4587 | else | |
4588 | { | |
4d3c2250 KB |
4589 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4590 | "common block member"); | |
8e19ed76 | 4591 | } |
c906108c | 4592 | } |
639d11d3 | 4593 | if (die->child != NULL) |
c906108c | 4594 | { |
639d11d3 | 4595 | child_die = die->child; |
c906108c SS |
4596 | while (child_die && child_die->tag) |
4597 | { | |
e7c27a73 | 4598 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4599 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4600 | if (attr) |
4601 | { | |
4602 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4603 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4604 | add_symbol_to_list (sym, &global_symbols); |
4605 | } | |
4606 | child_die = sibling_die (child_die); | |
4607 | } | |
4608 | } | |
4609 | } | |
4610 | ||
d9fa45fe DC |
4611 | /* Read a C++ namespace. */ |
4612 | ||
d9fa45fe | 4613 | static void |
e7c27a73 | 4614 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 4615 | { |
e7c27a73 | 4616 | struct objfile *objfile = cu->objfile; |
38d518c9 | 4617 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 4618 | const char *name; |
9219021c DC |
4619 | int is_anonymous; |
4620 | struct die_info *current_die; | |
987504bb | 4621 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
9219021c | 4622 | |
e142c38c | 4623 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4624 | |
4625 | /* Now build the name of the current namespace. */ | |
4626 | ||
38d518c9 | 4627 | if (previous_prefix[0] == '\0') |
9219021c | 4628 | { |
38d518c9 | 4629 | processing_current_prefix = name; |
9219021c DC |
4630 | } |
4631 | else | |
4632 | { | |
987504bb JJ |
4633 | char *temp_name = typename_concat (NULL, previous_prefix, name, cu); |
4634 | make_cleanup (xfree, temp_name); | |
38d518c9 | 4635 | processing_current_prefix = temp_name; |
9219021c DC |
4636 | } |
4637 | ||
5c4e30ca DC |
4638 | /* Add a symbol associated to this if we haven't seen the namespace |
4639 | before. Also, add a using directive if it's an anonymous | |
4640 | namespace. */ | |
9219021c | 4641 | |
e142c38c | 4642 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
4643 | { |
4644 | struct type *type; | |
4645 | ||
4646 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
4647 | this cast will hopefully become unnecessary. */ | |
4648 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 4649 | (char *) processing_current_prefix, |
5c4e30ca DC |
4650 | objfile); |
4651 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4652 | ||
e7c27a73 | 4653 | new_symbol (die, type, cu); |
1c379e20 | 4654 | set_die_type (die, type, cu); |
5c4e30ca DC |
4655 | |
4656 | if (is_anonymous) | |
38d518c9 EZ |
4657 | cp_add_using_directive (processing_current_prefix, |
4658 | strlen (previous_prefix), | |
4659 | strlen (processing_current_prefix)); | |
5c4e30ca | 4660 | } |
9219021c | 4661 | |
639d11d3 | 4662 | if (die->child != NULL) |
d9fa45fe | 4663 | { |
639d11d3 | 4664 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4665 | |
4666 | while (child_die && child_die->tag) | |
4667 | { | |
e7c27a73 | 4668 | process_die (child_die, cu); |
d9fa45fe DC |
4669 | child_die = sibling_die (child_die); |
4670 | } | |
4671 | } | |
9219021c | 4672 | |
38d518c9 | 4673 | processing_current_prefix = previous_prefix; |
987504bb | 4674 | do_cleanups (back_to); |
38d518c9 EZ |
4675 | } |
4676 | ||
4677 | /* Return the name of the namespace represented by DIE. Set | |
4678 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
4679 | namespace. */ | |
4680 | ||
4681 | static const char * | |
e142c38c | 4682 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
4683 | { |
4684 | struct die_info *current_die; | |
4685 | const char *name = NULL; | |
4686 | ||
4687 | /* Loop through the extensions until we find a name. */ | |
4688 | ||
4689 | for (current_die = die; | |
4690 | current_die != NULL; | |
e142c38c | 4691 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 4692 | { |
e142c38c | 4693 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
4694 | if (name != NULL) |
4695 | break; | |
4696 | } | |
4697 | ||
4698 | /* Is it an anonymous namespace? */ | |
4699 | ||
4700 | *is_anonymous = (name == NULL); | |
4701 | if (*is_anonymous) | |
4702 | name = "(anonymous namespace)"; | |
4703 | ||
4704 | return name; | |
d9fa45fe DC |
4705 | } |
4706 | ||
c906108c SS |
4707 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
4708 | the user defined type vector. */ | |
4709 | ||
f792889a | 4710 | static struct type * |
e7c27a73 | 4711 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4712 | { |
5e2b427d | 4713 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 4714 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 4715 | struct type *type; |
8b2dbe47 KB |
4716 | struct attribute *attr_byte_size; |
4717 | struct attribute *attr_address_class; | |
4718 | int byte_size, addr_class; | |
c906108c | 4719 | |
e7c27a73 | 4720 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 4721 | |
e142c38c | 4722 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
4723 | if (attr_byte_size) |
4724 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 4725 | else |
8b2dbe47 KB |
4726 | byte_size = cu_header->addr_size; |
4727 | ||
e142c38c | 4728 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
4729 | if (attr_address_class) |
4730 | addr_class = DW_UNSND (attr_address_class); | |
4731 | else | |
4732 | addr_class = DW_ADDR_none; | |
4733 | ||
4734 | /* If the pointer size or address class is different than the | |
4735 | default, create a type variant marked as such and set the | |
4736 | length accordingly. */ | |
4737 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 4738 | { |
5e2b427d | 4739 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
4740 | { |
4741 | int type_flags; | |
4742 | ||
849957d9 | 4743 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 4744 | (gdbarch, byte_size, addr_class); |
8b2dbe47 KB |
4745 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); |
4746 | type = make_type_with_address_space (type, type_flags); | |
4747 | } | |
4748 | else if (TYPE_LENGTH (type) != byte_size) | |
4749 | { | |
e2e0b3e5 | 4750 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
4751 | } |
4752 | else { | |
4753 | /* Should we also complain about unhandled address classes? */ | |
4754 | } | |
c906108c | 4755 | } |
8b2dbe47 KB |
4756 | |
4757 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 4758 | return set_die_type (die, type, cu); |
c906108c SS |
4759 | } |
4760 | ||
4761 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
4762 | the user defined type vector. */ | |
4763 | ||
f792889a | 4764 | static struct type * |
e7c27a73 | 4765 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4766 | { |
e7c27a73 | 4767 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4768 | struct type *type; |
4769 | struct type *to_type; | |
4770 | struct type *domain; | |
4771 | ||
e7c27a73 DJ |
4772 | to_type = die_type (die, cu); |
4773 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
4774 | |
4775 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
4776 | type = lookup_methodptr_type (to_type); | |
4777 | else | |
4778 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 4779 | |
f792889a | 4780 | return set_die_type (die, type, cu); |
c906108c SS |
4781 | } |
4782 | ||
4783 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
4784 | the user defined type vector. */ | |
4785 | ||
f792889a | 4786 | static struct type * |
e7c27a73 | 4787 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4788 | { |
e7c27a73 | 4789 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4790 | struct type *type; |
4791 | struct attribute *attr; | |
4792 | ||
e7c27a73 | 4793 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 4794 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4795 | if (attr) |
4796 | { | |
4797 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4798 | } | |
4799 | else | |
4800 | { | |
107d2387 | 4801 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 4802 | } |
f792889a | 4803 | return set_die_type (die, type, cu); |
c906108c SS |
4804 | } |
4805 | ||
f792889a | 4806 | static struct type * |
e7c27a73 | 4807 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4808 | { |
f792889a | 4809 | struct type *base_type, *cv_type; |
c906108c | 4810 | |
e7c27a73 | 4811 | base_type = die_type (die, cu); |
f792889a DJ |
4812 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
4813 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4814 | } |
4815 | ||
f792889a | 4816 | static struct type * |
e7c27a73 | 4817 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4818 | { |
f792889a | 4819 | struct type *base_type, *cv_type; |
c906108c | 4820 | |
e7c27a73 | 4821 | base_type = die_type (die, cu); |
f792889a DJ |
4822 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
4823 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4824 | } |
4825 | ||
4826 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4827 | the user defined type vector. It isn't really a user defined type, | |
4828 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4829 | attribute to reference it. */ | |
4830 | ||
f792889a | 4831 | static struct type * |
e7c27a73 | 4832 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4833 | { |
e7c27a73 | 4834 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4835 | struct type *type, *range_type, *index_type, *char_type; |
4836 | struct attribute *attr; | |
4837 | unsigned int length; | |
4838 | ||
e142c38c | 4839 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4840 | if (attr) |
4841 | { | |
4842 | length = DW_UNSND (attr); | |
4843 | } | |
4844 | else | |
4845 | { | |
b21b22e0 | 4846 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4847 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4848 | if (attr) |
4849 | { | |
4850 | length = DW_UNSND (attr); | |
4851 | } | |
4852 | else | |
4853 | { | |
4854 | length = 1; | |
4855 | } | |
c906108c | 4856 | } |
6ccb9162 UW |
4857 | |
4858 | index_type = builtin_type_int32; | |
c906108c | 4859 | range_type = create_range_type (NULL, index_type, 1, length); |
6ccb9162 UW |
4860 | type = create_string_type (NULL, range_type); |
4861 | ||
f792889a | 4862 | return set_die_type (die, type, cu); |
c906108c SS |
4863 | } |
4864 | ||
4865 | /* Handle DIES due to C code like: | |
4866 | ||
4867 | struct foo | |
c5aa993b JM |
4868 | { |
4869 | int (*funcp)(int a, long l); | |
4870 | int b; | |
4871 | }; | |
c906108c SS |
4872 | |
4873 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4874 | */ |
c906108c | 4875 | |
f792889a | 4876 | static struct type * |
e7c27a73 | 4877 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4878 | { |
4879 | struct type *type; /* Type that this function returns */ | |
4880 | struct type *ftype; /* Function that returns above type */ | |
4881 | struct attribute *attr; | |
4882 | ||
e7c27a73 | 4883 | type = die_type (die, cu); |
1326e61b | 4884 | ftype = make_function_type (type, (struct type **) 0); |
c906108c | 4885 | |
5b8101ae | 4886 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 4887 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4888 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 4889 | || cu->language == language_cplus |
5b8101ae PM |
4890 | || cu->language == language_java |
4891 | || cu->language == language_pascal) | |
c906108c SS |
4892 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4893 | ||
c055b101 CV |
4894 | /* Store the calling convention in the type if it's available in |
4895 | the subroutine die. Otherwise set the calling convention to | |
4896 | the default value DW_CC_normal. */ | |
4897 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
4898 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
4899 | ||
639d11d3 | 4900 | if (die->child != NULL) |
c906108c SS |
4901 | { |
4902 | struct die_info *child_die; | |
4903 | int nparams = 0; | |
4904 | int iparams = 0; | |
4905 | ||
4906 | /* Count the number of parameters. | |
4907 | FIXME: GDB currently ignores vararg functions, but knows about | |
4908 | vararg member functions. */ | |
639d11d3 | 4909 | child_die = die->child; |
c906108c SS |
4910 | while (child_die && child_die->tag) |
4911 | { | |
4912 | if (child_die->tag == DW_TAG_formal_parameter) | |
4913 | nparams++; | |
4914 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4915 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4916 | child_die = sibling_die (child_die); | |
4917 | } | |
4918 | ||
4919 | /* Allocate storage for parameters and fill them in. */ | |
4920 | TYPE_NFIELDS (ftype) = nparams; | |
4921 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 4922 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 4923 | |
639d11d3 | 4924 | child_die = die->child; |
c906108c SS |
4925 | while (child_die && child_die->tag) |
4926 | { | |
4927 | if (child_die->tag == DW_TAG_formal_parameter) | |
4928 | { | |
4929 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4930 | member functions. G++ helps GDB by marking the first |
4931 | parameter for non-static member functions (which is the | |
4932 | this pointer) as artificial. We pass this information | |
4933 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4934 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4935 | if (attr) |
4936 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4937 | else | |
4938 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4939 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4940 | iparams++; |
4941 | } | |
4942 | child_die = sibling_die (child_die); | |
4943 | } | |
4944 | } | |
4945 | ||
f792889a | 4946 | return set_die_type (die, ftype, cu); |
c906108c SS |
4947 | } |
4948 | ||
f792889a | 4949 | static struct type * |
e7c27a73 | 4950 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4951 | { |
e7c27a73 | 4952 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4953 | struct attribute *attr; |
4954 | char *name = NULL; | |
f792889a | 4955 | struct type *this_type; |
c906108c | 4956 | |
f792889a DJ |
4957 | name = dwarf2_name (die, cu); |
4958 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, | |
4959 | TYPE_FLAG_TARGET_STUB, name, objfile); | |
4960 | set_die_type (die, this_type, cu); | |
4961 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
4962 | return this_type; | |
c906108c SS |
4963 | } |
4964 | ||
4965 | /* Find a representation of a given base type and install | |
4966 | it in the TYPE field of the die. */ | |
4967 | ||
f792889a | 4968 | static struct type * |
e7c27a73 | 4969 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4970 | { |
e7c27a73 | 4971 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4972 | struct type *type; |
4973 | struct attribute *attr; | |
4974 | int encoding = 0, size = 0; | |
39cbfefa | 4975 | char *name; |
6ccb9162 UW |
4976 | enum type_code code = TYPE_CODE_INT; |
4977 | int type_flags = 0; | |
4978 | struct type *target_type = NULL; | |
c906108c | 4979 | |
e142c38c | 4980 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4981 | if (attr) |
4982 | { | |
4983 | encoding = DW_UNSND (attr); | |
4984 | } | |
e142c38c | 4985 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4986 | if (attr) |
4987 | { | |
4988 | size = DW_UNSND (attr); | |
4989 | } | |
39cbfefa | 4990 | name = dwarf2_name (die, cu); |
6ccb9162 | 4991 | if (!name) |
c906108c | 4992 | { |
6ccb9162 UW |
4993 | complaint (&symfile_complaints, |
4994 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 4995 | } |
6ccb9162 UW |
4996 | |
4997 | switch (encoding) | |
c906108c | 4998 | { |
6ccb9162 UW |
4999 | case DW_ATE_address: |
5000 | /* Turn DW_ATE_address into a void * pointer. */ | |
5001 | code = TYPE_CODE_PTR; | |
5002 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5003 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
5004 | break; | |
5005 | case DW_ATE_boolean: | |
5006 | code = TYPE_CODE_BOOL; | |
5007 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5008 | break; | |
5009 | case DW_ATE_complex_float: | |
5010 | code = TYPE_CODE_COMPLEX; | |
5011 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
5012 | break; | |
5013 | case DW_ATE_decimal_float: | |
5014 | code = TYPE_CODE_DECFLOAT; | |
5015 | break; | |
5016 | case DW_ATE_float: | |
5017 | code = TYPE_CODE_FLT; | |
5018 | break; | |
5019 | case DW_ATE_signed: | |
5020 | break; | |
5021 | case DW_ATE_unsigned: | |
5022 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5023 | break; | |
5024 | case DW_ATE_signed_char: | |
1760d9d5 | 5025 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5026 | code = TYPE_CODE_CHAR; |
5027 | break; | |
5028 | case DW_ATE_unsigned_char: | |
1760d9d5 | 5029 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5030 | code = TYPE_CODE_CHAR; |
5031 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5032 | break; | |
5033 | default: | |
5034 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
5035 | dwarf_type_encoding_name (encoding)); | |
5036 | break; | |
c906108c | 5037 | } |
6ccb9162 UW |
5038 | |
5039 | type = init_type (code, size, type_flags, name, objfile); | |
5040 | TYPE_TARGET_TYPE (type) = target_type; | |
5041 | ||
f792889a | 5042 | return set_die_type (die, type, cu); |
c906108c SS |
5043 | } |
5044 | ||
a02abb62 JB |
5045 | /* Read the given DW_AT_subrange DIE. */ |
5046 | ||
f792889a | 5047 | static struct type * |
a02abb62 JB |
5048 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
5049 | { | |
5e2b427d | 5050 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
5051 | struct type *base_type; |
5052 | struct type *range_type; | |
5053 | struct attribute *attr; | |
5054 | int low = 0; | |
5055 | int high = -1; | |
39cbfefa | 5056 | char *name; |
a02abb62 | 5057 | |
a02abb62 | 5058 | base_type = die_type (die, cu); |
3d1f72c2 | 5059 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
5060 | { |
5061 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5062 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 5063 | base_type |
5e2b427d | 5064 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 5065 | 0, NULL, cu->objfile); |
a02abb62 JB |
5066 | } |
5067 | ||
e142c38c | 5068 | if (cu->language == language_fortran) |
a02abb62 JB |
5069 | { |
5070 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
5071 | low = 1; | |
5072 | } | |
5073 | ||
dd5e6932 DJ |
5074 | /* FIXME: For variable sized arrays either of these could be |
5075 | a variable rather than a constant value. We'll allow it, | |
5076 | but we don't know how to handle it. */ | |
e142c38c | 5077 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
5078 | if (attr) |
5079 | low = dwarf2_get_attr_constant_value (attr, 0); | |
5080 | ||
e142c38c | 5081 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
5082 | if (attr) |
5083 | { | |
5084 | if (attr->form == DW_FORM_block1) | |
5085 | { | |
5086 | /* GCC encodes arrays with unspecified or dynamic length | |
5087 | with a DW_FORM_block1 attribute. | |
5088 | FIXME: GDB does not yet know how to handle dynamic | |
5089 | arrays properly, treat them as arrays with unspecified | |
5090 | length for now. | |
5091 | ||
5092 | FIXME: jimb/2003-09-22: GDB does not really know | |
5093 | how to handle arrays of unspecified length | |
5094 | either; we just represent them as zero-length | |
5095 | arrays. Choose an appropriate upper bound given | |
5096 | the lower bound we've computed above. */ | |
5097 | high = low - 1; | |
5098 | } | |
5099 | else | |
5100 | high = dwarf2_get_attr_constant_value (attr, 1); | |
5101 | } | |
5102 | ||
5103 | range_type = create_range_type (NULL, base_type, low, high); | |
5104 | ||
39cbfefa DJ |
5105 | name = dwarf2_name (die, cu); |
5106 | if (name) | |
5107 | TYPE_NAME (range_type) = name; | |
a02abb62 | 5108 | |
e142c38c | 5109 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
5110 | if (attr) |
5111 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
5112 | ||
f792889a | 5113 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
5114 | } |
5115 | ||
f792889a | 5116 | static struct type * |
81a17f79 JB |
5117 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
5118 | { | |
5119 | struct type *type; | |
81a17f79 | 5120 | |
81a17f79 JB |
5121 | /* For now, we only support the C meaning of an unspecified type: void. */ |
5122 | ||
39cbfefa | 5123 | type = init_type (TYPE_CODE_VOID, 0, 0, dwarf2_name (die, cu), |
81a17f79 JB |
5124 | cu->objfile); |
5125 | ||
f792889a | 5126 | return set_die_type (die, type, cu); |
81a17f79 | 5127 | } |
a02abb62 | 5128 | |
c906108c SS |
5129 | /* Read a whole compilation unit into a linked list of dies. */ |
5130 | ||
f9aca02d | 5131 | static struct die_info * |
fe1b8b76 | 5132 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5133 | { |
e7c27a73 | 5134 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
5135 | } |
5136 | ||
5137 | /* Read a single die and all its descendents. Set the die's sibling | |
5138 | field to NULL; set other fields in the die correctly, and set all | |
5139 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
5140 | location of the info_ptr after reading all of those dies. PARENT | |
5141 | is the parent of the die in question. */ | |
5142 | ||
5143 | static struct die_info * | |
fe1b8b76 | 5144 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5145 | struct dwarf2_cu *cu, |
fe1b8b76 | 5146 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5147 | struct die_info *parent) |
5148 | { | |
5149 | struct die_info *die; | |
fe1b8b76 | 5150 | gdb_byte *cur_ptr; |
639d11d3 DC |
5151 | int has_children; |
5152 | ||
e7c27a73 | 5153 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
10b3939b | 5154 | store_in_ref_table (die->offset, die, cu); |
639d11d3 DC |
5155 | |
5156 | if (has_children) | |
5157 | { | |
e7c27a73 | 5158 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5159 | new_info_ptr, die); |
5160 | } | |
5161 | else | |
5162 | { | |
5163 | die->child = NULL; | |
5164 | *new_info_ptr = cur_ptr; | |
5165 | } | |
5166 | ||
5167 | die->sibling = NULL; | |
5168 | die->parent = parent; | |
5169 | return die; | |
5170 | } | |
5171 | ||
5172 | /* Read a die, all of its descendents, and all of its siblings; set | |
5173 | all of the fields of all of the dies correctly. Arguments are as | |
5174 | in read_die_and_children. */ | |
5175 | ||
5176 | static struct die_info * | |
fe1b8b76 | 5177 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5178 | struct dwarf2_cu *cu, |
fe1b8b76 | 5179 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5180 | struct die_info *parent) |
5181 | { | |
5182 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5183 | gdb_byte *cur_ptr; |
639d11d3 | 5184 | |
c906108c | 5185 | cur_ptr = info_ptr; |
639d11d3 DC |
5186 | first_die = last_sibling = NULL; |
5187 | ||
5188 | while (1) | |
c906108c | 5189 | { |
639d11d3 | 5190 | struct die_info *die |
e7c27a73 | 5191 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
5192 | |
5193 | if (!first_die) | |
c906108c | 5194 | { |
639d11d3 | 5195 | first_die = die; |
c906108c | 5196 | } |
639d11d3 | 5197 | else |
c906108c | 5198 | { |
639d11d3 | 5199 | last_sibling->sibling = die; |
c906108c SS |
5200 | } |
5201 | ||
639d11d3 | 5202 | if (die->tag == 0) |
c906108c | 5203 | { |
639d11d3 DC |
5204 | *new_info_ptr = cur_ptr; |
5205 | return first_die; | |
c906108c SS |
5206 | } |
5207 | else | |
5208 | { | |
639d11d3 | 5209 | last_sibling = die; |
c906108c SS |
5210 | } |
5211 | } | |
c906108c SS |
5212 | } |
5213 | ||
5214 | /* Free a linked list of dies. */ | |
5215 | ||
5216 | static void | |
fba45db2 | 5217 | free_die_list (struct die_info *dies) |
c906108c SS |
5218 | { |
5219 | struct die_info *die, *next; | |
5220 | ||
5221 | die = dies; | |
5222 | while (die) | |
5223 | { | |
639d11d3 DC |
5224 | if (die->child != NULL) |
5225 | free_die_list (die->child); | |
5226 | next = die->sibling; | |
b8c9b27d KB |
5227 | xfree (die->attrs); |
5228 | xfree (die); | |
c906108c SS |
5229 | die = next; |
5230 | } | |
5231 | } | |
5232 | ||
233a11ab CS |
5233 | /* Decompress a section that was compressed using zlib. Store the |
5234 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
5235 | ||
5236 | static void | |
5237 | zlib_decompress_section (struct objfile *objfile, asection *sectp, | |
5238 | gdb_byte **outbuf, bfd_size_type *outsize) | |
5239 | { | |
ef72380d | 5240 | bfd *abfd = objfile->obfd; |
233a11ab CS |
5241 | #ifndef HAVE_ZLIB_H |
5242 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
5243 | "is disabled in this copy of GDB"), | |
5244 | bfd_get_filename (abfd)); | |
5245 | #else | |
233a11ab CS |
5246 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
5247 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
5248 | bfd_size_type uncompressed_size; | |
5249 | gdb_byte *uncompressed_buffer; | |
5250 | z_stream strm; | |
5251 | int rc; | |
5252 | int header_size = 12; | |
5253 | ||
5254 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
5255 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
5256 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
5257 | bfd_get_filename (abfd)); | |
5258 | ||
5259 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
5260 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
5261 | if (compressed_size < header_size | |
5262 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
5263 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
5264 | bfd_get_filename (abfd)); | |
5265 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
5266 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
5267 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
5268 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
5269 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
5270 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
5271 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
5272 | uncompressed_size += compressed_buffer[11]; | |
5273 | ||
5274 | /* It is possible the section consists of several compressed | |
5275 | buffers concatenated together, so we uncompress in a loop. */ | |
5276 | strm.zalloc = NULL; | |
5277 | strm.zfree = NULL; | |
5278 | strm.opaque = NULL; | |
5279 | strm.avail_in = compressed_size - header_size; | |
5280 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
5281 | strm.avail_out = uncompressed_size; | |
5282 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
5283 | uncompressed_size); | |
5284 | rc = inflateInit (&strm); | |
5285 | while (strm.avail_in > 0) | |
5286 | { | |
5287 | if (rc != Z_OK) | |
5288 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
5289 | bfd_get_filename (abfd), rc); | |
5290 | strm.next_out = ((Bytef*) uncompressed_buffer | |
5291 | + (uncompressed_size - strm.avail_out)); | |
5292 | rc = inflate (&strm, Z_FINISH); | |
5293 | if (rc != Z_STREAM_END) | |
5294 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
5295 | bfd_get_filename (abfd), rc); | |
5296 | rc = inflateReset (&strm); | |
5297 | } | |
5298 | rc = inflateEnd (&strm); | |
5299 | if (rc != Z_OK | |
5300 | || strm.avail_out != 0) | |
5301 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
5302 | bfd_get_filename (abfd), rc); | |
5303 | ||
5304 | xfree (compressed_buffer); | |
5305 | *outbuf = uncompressed_buffer; | |
5306 | *outsize = uncompressed_size; | |
5307 | #endif | |
5308 | } | |
5309 | ||
5310 | ||
c906108c | 5311 | /* Read the contents of the section at OFFSET and of size SIZE from the |
233a11ab CS |
5312 | object file specified by OBJFILE into the objfile_obstack and return it. |
5313 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 5314 | |
fe1b8b76 | 5315 | gdb_byte * |
188dd5d6 | 5316 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
5317 | { |
5318 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 5319 | gdb_byte *buf, *retbuf; |
2c500098 | 5320 | bfd_size_type size = bfd_get_section_size (sectp); |
233a11ab | 5321 | unsigned char header[4]; |
c906108c SS |
5322 | |
5323 | if (size == 0) | |
5324 | return NULL; | |
5325 | ||
233a11ab CS |
5326 | /* Check if the file has a 4-byte header indicating compression. */ |
5327 | if (size > sizeof (header) | |
5328 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
5329 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
5330 | { | |
5331 | /* Upon decompression, update the buffer and its size. */ | |
5332 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
5333 | { | |
5334 | zlib_decompress_section (objfile, sectp, &buf, &size); | |
5335 | dwarf2_resize_section (sectp, size); | |
5336 | return buf; | |
5337 | } | |
5338 | } | |
5339 | ||
5340 | /* If we get here, we are a normal, not-compressed section. */ | |
fe1b8b76 | 5341 | buf = obstack_alloc (&objfile->objfile_obstack, size); |
233a11ab CS |
5342 | /* When debugging .o files, we may need to apply relocations; see |
5343 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
5344 | We never compress sections in .o files, so we only need to | |
5345 | try this when the section is not compressed. */ | |
fe1b8b76 | 5346 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); |
086df311 DJ |
5347 | if (retbuf != NULL) |
5348 | return retbuf; | |
5349 | ||
188dd5d6 DJ |
5350 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
5351 | || bfd_bread (buf, size, abfd) != size) | |
8a3fe4f8 | 5352 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
188dd5d6 DJ |
5353 | bfd_get_filename (abfd)); |
5354 | ||
c906108c SS |
5355 | return buf; |
5356 | } | |
5357 | ||
5358 | /* In DWARF version 2, the description of the debugging information is | |
5359 | stored in a separate .debug_abbrev section. Before we read any | |
5360 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5361 | in a hash table. This function also sets flags in CU describing |
5362 | the data found in the abbrev table. */ | |
c906108c SS |
5363 | |
5364 | static void | |
e7c27a73 | 5365 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5366 | { |
e7c27a73 | 5367 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5368 | gdb_byte *abbrev_ptr; |
c906108c SS |
5369 | struct abbrev_info *cur_abbrev; |
5370 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5371 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5372 | struct attr_abbrev *cur_attrs; |
5373 | unsigned int allocated_attrs; | |
c906108c | 5374 | |
57349743 | 5375 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5376 | obstack_init (&cu->abbrev_obstack); |
5377 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5378 | (ABBREV_HASH_SIZE | |
5379 | * sizeof (struct abbrev_info *))); | |
5380 | memset (cu->dwarf2_abbrevs, 0, | |
5381 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5382 | |
6502dd73 | 5383 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
5384 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5385 | abbrev_ptr += bytes_read; | |
5386 | ||
f3dd6933 DJ |
5387 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5388 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5389 | ||
c906108c SS |
5390 | /* loop until we reach an abbrev number of 0 */ |
5391 | while (abbrev_number) | |
5392 | { | |
f3dd6933 | 5393 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5394 | |
5395 | /* read in abbrev header */ | |
5396 | cur_abbrev->number = abbrev_number; | |
5397 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5398 | abbrev_ptr += bytes_read; | |
5399 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5400 | abbrev_ptr += 1; | |
5401 | ||
72bf9492 DJ |
5402 | if (cur_abbrev->tag == DW_TAG_namespace) |
5403 | cu->has_namespace_info = 1; | |
5404 | ||
c906108c SS |
5405 | /* now read in declarations */ |
5406 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5407 | abbrev_ptr += bytes_read; | |
5408 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5409 | abbrev_ptr += bytes_read; | |
5410 | while (abbrev_name) | |
5411 | { | |
f3dd6933 | 5412 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5413 | { |
f3dd6933 DJ |
5414 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5415 | cur_attrs | |
5416 | = xrealloc (cur_attrs, (allocated_attrs | |
5417 | * sizeof (struct attr_abbrev))); | |
c906108c | 5418 | } |
ae038cb0 DJ |
5419 | |
5420 | /* Record whether this compilation unit might have | |
5421 | inter-compilation-unit references. If we don't know what form | |
5422 | this attribute will have, then it might potentially be a | |
5423 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5424 | references. */ | |
5425 | ||
5426 | if (abbrev_form == DW_FORM_ref_addr | |
5427 | || abbrev_form == DW_FORM_indirect) | |
5428 | cu->has_form_ref_addr = 1; | |
5429 | ||
f3dd6933 DJ |
5430 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5431 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5432 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5433 | abbrev_ptr += bytes_read; | |
5434 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5435 | abbrev_ptr += bytes_read; | |
5436 | } | |
5437 | ||
f3dd6933 DJ |
5438 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5439 | (cur_abbrev->num_attrs | |
5440 | * sizeof (struct attr_abbrev))); | |
5441 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5442 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5443 | ||
c906108c | 5444 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5445 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5446 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5447 | |
5448 | /* Get next abbreviation. | |
5449 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5450 | always properly terminated with an abbrev number of 0. |
5451 | Exit loop if we encounter an abbreviation which we have | |
5452 | already read (which means we are about to read the abbreviations | |
5453 | for the next compile unit) or if the end of the abbreviation | |
5454 | table is reached. */ | |
6502dd73 DJ |
5455 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
5456 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
5457 | break; |
5458 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5459 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5460 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5461 | break; |
5462 | } | |
f3dd6933 DJ |
5463 | |
5464 | xfree (cur_attrs); | |
c906108c SS |
5465 | } |
5466 | ||
f3dd6933 | 5467 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5468 | |
c906108c | 5469 | static void |
f3dd6933 | 5470 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5471 | { |
f3dd6933 | 5472 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5473 | |
f3dd6933 DJ |
5474 | obstack_free (&cu->abbrev_obstack, NULL); |
5475 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5476 | } |
5477 | ||
5478 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5479 | ||
5480 | static struct abbrev_info * | |
e7c27a73 | 5481 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5482 | { |
5483 | unsigned int hash_number; | |
5484 | struct abbrev_info *abbrev; | |
5485 | ||
5486 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5487 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5488 | |
5489 | while (abbrev) | |
5490 | { | |
5491 | if (abbrev->number == number) | |
5492 | return abbrev; | |
5493 | else | |
5494 | abbrev = abbrev->next; | |
5495 | } | |
5496 | return NULL; | |
5497 | } | |
5498 | ||
72bf9492 DJ |
5499 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5500 | symbol for. */ | |
5501 | ||
5502 | static int | |
5503 | is_type_tag_for_partial (int tag) | |
5504 | { | |
5505 | switch (tag) | |
5506 | { | |
5507 | #if 0 | |
5508 | /* Some types that would be reasonable to generate partial symbols for, | |
5509 | that we don't at present. */ | |
5510 | case DW_TAG_array_type: | |
5511 | case DW_TAG_file_type: | |
5512 | case DW_TAG_ptr_to_member_type: | |
5513 | case DW_TAG_set_type: | |
5514 | case DW_TAG_string_type: | |
5515 | case DW_TAG_subroutine_type: | |
5516 | #endif | |
5517 | case DW_TAG_base_type: | |
5518 | case DW_TAG_class_type: | |
680b30c7 | 5519 | case DW_TAG_interface_type: |
72bf9492 DJ |
5520 | case DW_TAG_enumeration_type: |
5521 | case DW_TAG_structure_type: | |
5522 | case DW_TAG_subrange_type: | |
5523 | case DW_TAG_typedef: | |
5524 | case DW_TAG_union_type: | |
5525 | return 1; | |
5526 | default: | |
5527 | return 0; | |
5528 | } | |
5529 | } | |
5530 | ||
5531 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5532 | ||
5533 | static struct partial_die_info * | |
fe1b8b76 | 5534 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5535 | struct dwarf2_cu *cu) |
5536 | { | |
5537 | struct partial_die_info *part_die; | |
5538 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5539 | struct abbrev_info *abbrev; | |
5540 | unsigned int bytes_read; | |
5afb4e99 | 5541 | unsigned int load_all = 0; |
72bf9492 DJ |
5542 | |
5543 | int nesting_level = 1; | |
5544 | ||
5545 | parent_die = NULL; | |
5546 | last_die = NULL; | |
5547 | ||
5afb4e99 DJ |
5548 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5549 | load_all = 1; | |
5550 | ||
72bf9492 DJ |
5551 | cu->partial_dies |
5552 | = htab_create_alloc_ex (cu->header.length / 12, | |
5553 | partial_die_hash, | |
5554 | partial_die_eq, | |
5555 | NULL, | |
5556 | &cu->comp_unit_obstack, | |
5557 | hashtab_obstack_allocate, | |
5558 | dummy_obstack_deallocate); | |
5559 | ||
5560 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5561 | sizeof (struct partial_die_info)); | |
5562 | ||
5563 | while (1) | |
5564 | { | |
5565 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5566 | ||
5567 | /* A NULL abbrev means the end of a series of children. */ | |
5568 | if (abbrev == NULL) | |
5569 | { | |
5570 | if (--nesting_level == 0) | |
5571 | { | |
5572 | /* PART_DIE was probably the last thing allocated on the | |
5573 | comp_unit_obstack, so we could call obstack_free | |
5574 | here. We don't do that because the waste is small, | |
5575 | and will be cleaned up when we're done with this | |
5576 | compilation unit. This way, we're also more robust | |
5577 | against other users of the comp_unit_obstack. */ | |
5578 | return first_die; | |
5579 | } | |
5580 | info_ptr += bytes_read; | |
5581 | last_die = parent_die; | |
5582 | parent_die = parent_die->die_parent; | |
5583 | continue; | |
5584 | } | |
5585 | ||
5afb4e99 DJ |
5586 | /* Check whether this DIE is interesting enough to save. Normally |
5587 | we would not be interested in members here, but there may be | |
5588 | later variables referencing them via DW_AT_specification (for | |
5589 | static members). */ | |
5590 | if (!load_all | |
5591 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5592 | && abbrev->tag != DW_TAG_enumerator |
5593 | && abbrev->tag != DW_TAG_subprogram | |
5594 | && abbrev->tag != DW_TAG_variable | |
5afb4e99 DJ |
5595 | && abbrev->tag != DW_TAG_namespace |
5596 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5597 | { |
5598 | /* Otherwise we skip to the next sibling, if any. */ | |
5599 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5600 | continue; | |
5601 | } | |
5602 | ||
5603 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5604 | abfd, info_ptr, cu); | |
5605 | ||
5606 | /* This two-pass algorithm for processing partial symbols has a | |
5607 | high cost in cache pressure. Thus, handle some simple cases | |
5608 | here which cover the majority of C partial symbols. DIEs | |
5609 | which neither have specification tags in them, nor could have | |
5610 | specification tags elsewhere pointing at them, can simply be | |
5611 | processed and discarded. | |
5612 | ||
5613 | This segment is also optional; scan_partial_symbols and | |
5614 | add_partial_symbol will handle these DIEs if we chain | |
5615 | them in normally. When compilers which do not emit large | |
5616 | quantities of duplicate debug information are more common, | |
5617 | this code can probably be removed. */ | |
5618 | ||
5619 | /* Any complete simple types at the top level (pretty much all | |
5620 | of them, for a language without namespaces), can be processed | |
5621 | directly. */ | |
5622 | if (parent_die == NULL | |
5623 | && part_die->has_specification == 0 | |
5624 | && part_die->is_declaration == 0 | |
5625 | && (part_die->tag == DW_TAG_typedef | |
5626 | || part_die->tag == DW_TAG_base_type | |
5627 | || part_die->tag == DW_TAG_subrange_type)) | |
5628 | { | |
5629 | if (building_psymtab && part_die->name != NULL) | |
5630 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5631 | VAR_DOMAIN, LOC_TYPEDEF, | |
5632 | &cu->objfile->static_psymbols, | |
5633 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5634 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5635 | continue; | |
5636 | } | |
5637 | ||
5638 | /* If we're at the second level, and we're an enumerator, and | |
5639 | our parent has no specification (meaning possibly lives in a | |
5640 | namespace elsewhere), then we can add the partial symbol now | |
5641 | instead of queueing it. */ | |
5642 | if (part_die->tag == DW_TAG_enumerator | |
5643 | && parent_die != NULL | |
5644 | && parent_die->die_parent == NULL | |
5645 | && parent_die->tag == DW_TAG_enumeration_type | |
5646 | && parent_die->has_specification == 0) | |
5647 | { | |
5648 | if (part_die->name == NULL) | |
e2e0b3e5 | 5649 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5650 | else if (building_psymtab) |
5651 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5652 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5653 | (cu->language == language_cplus |
5654 | || cu->language == language_java) | |
72bf9492 DJ |
5655 | ? &cu->objfile->global_psymbols |
5656 | : &cu->objfile->static_psymbols, | |
5657 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5658 | ||
5659 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5660 | continue; | |
5661 | } | |
5662 | ||
5663 | /* We'll save this DIE so link it in. */ | |
5664 | part_die->die_parent = parent_die; | |
5665 | part_die->die_sibling = NULL; | |
5666 | part_die->die_child = NULL; | |
5667 | ||
5668 | if (last_die && last_die == parent_die) | |
5669 | last_die->die_child = part_die; | |
5670 | else if (last_die) | |
5671 | last_die->die_sibling = part_die; | |
5672 | ||
5673 | last_die = part_die; | |
5674 | ||
5675 | if (first_die == NULL) | |
5676 | first_die = part_die; | |
5677 | ||
5678 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5679 | find interesting need to be in the hash table, because we | |
5680 | also have the parent/sibling/child chains; only those that we | |
5681 | might refer to by offset later during partial symbol reading. | |
5682 | ||
5683 | For now this means things that might have be the target of a | |
5684 | DW_AT_specification, DW_AT_abstract_origin, or | |
5685 | DW_AT_extension. DW_AT_extension will refer only to | |
5686 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5687 | many things under the function DIE, but we do not recurse | |
5688 | into function DIEs during partial symbol reading) and | |
5689 | possibly variables as well; DW_AT_specification refers to | |
5690 | declarations. Declarations ought to have the DW_AT_declaration | |
5691 | flag. It happens that GCC forgets to put it in sometimes, but | |
5692 | only for functions, not for types. | |
5693 | ||
5694 | Adding more things than necessary to the hash table is harmless | |
5695 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5696 | wasted time in find_partial_die, when we reread the compilation |
5697 | unit with load_all_dies set. */ | |
72bf9492 | 5698 | |
5afb4e99 DJ |
5699 | if (load_all |
5700 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5701 | || abbrev->tag == DW_TAG_variable |
5702 | || abbrev->tag == DW_TAG_namespace | |
5703 | || part_die->is_declaration) | |
5704 | { | |
5705 | void **slot; | |
5706 | ||
5707 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5708 | part_die->offset, INSERT); | |
5709 | *slot = part_die; | |
5710 | } | |
5711 | ||
5712 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5713 | sizeof (struct partial_die_info)); | |
5714 | ||
5715 | /* For some DIEs we want to follow their children (if any). For C | |
5716 | we have no reason to follow the children of structures; for other | |
5717 | languages we have to, both so that we can get at method physnames | |
5718 | to infer fully qualified class names, and for DW_AT_specification. */ | |
5719 | if (last_die->has_children | |
5afb4e99 DJ |
5720 | && (load_all |
5721 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5722 | || last_die->tag == DW_TAG_enumeration_type |
5723 | || (cu->language != language_c | |
5724 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 5725 | || last_die->tag == DW_TAG_interface_type |
72bf9492 DJ |
5726 | || last_die->tag == DW_TAG_structure_type |
5727 | || last_die->tag == DW_TAG_union_type)))) | |
5728 | { | |
5729 | nesting_level++; | |
5730 | parent_die = last_die; | |
5731 | continue; | |
5732 | } | |
5733 | ||
5734 | /* Otherwise we skip to the next sibling, if any. */ | |
5735 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5736 | ||
5737 | /* Back to the top, do it again. */ | |
5738 | } | |
5739 | } | |
5740 | ||
c906108c SS |
5741 | /* Read a minimal amount of information into the minimal die structure. */ |
5742 | ||
fe1b8b76 | 5743 | static gdb_byte * |
72bf9492 DJ |
5744 | read_partial_die (struct partial_die_info *part_die, |
5745 | struct abbrev_info *abbrev, | |
5746 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 5747 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 5748 | { |
72bf9492 | 5749 | unsigned int bytes_read, i; |
c906108c | 5750 | struct attribute attr; |
c5aa993b | 5751 | int has_low_pc_attr = 0; |
c906108c | 5752 | int has_high_pc_attr = 0; |
e7030f15 | 5753 | CORE_ADDR base_address = 0; |
85cbf3d3 JK |
5754 | enum |
5755 | { | |
5756 | base_address_none, | |
5757 | base_address_low_pc, | |
5758 | /* Overrides BASE_ADDRESS_LOW_PC. */ | |
5759 | base_address_entry_pc | |
5760 | } | |
5761 | base_address_type = base_address_none; | |
c906108c | 5762 | |
72bf9492 | 5763 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 5764 | |
6502dd73 | 5765 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
5766 | |
5767 | info_ptr += abbrev_len; | |
5768 | ||
5769 | if (abbrev == NULL) | |
5770 | return info_ptr; | |
5771 | ||
c906108c SS |
5772 | part_die->tag = abbrev->tag; |
5773 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
5774 | |
5775 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5776 | { | |
e7c27a73 | 5777 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
5778 | |
5779 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 5780 | partial symbol table. */ |
c906108c SS |
5781 | switch (attr.name) |
5782 | { | |
5783 | case DW_AT_name: | |
5784 | ||
5785 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
5786 | if (part_die->name == NULL) | |
5787 | part_die->name = DW_STRING (&attr); | |
5788 | break; | |
57c22c6c BR |
5789 | case DW_AT_comp_dir: |
5790 | if (part_die->dirname == NULL) | |
5791 | part_die->dirname = DW_STRING (&attr); | |
5792 | break; | |
c906108c SS |
5793 | case DW_AT_MIPS_linkage_name: |
5794 | part_die->name = DW_STRING (&attr); | |
5795 | break; | |
5796 | case DW_AT_low_pc: | |
5797 | has_low_pc_attr = 1; | |
5798 | part_die->lowpc = DW_ADDR (&attr); | |
85cbf3d3 JK |
5799 | if (part_die->tag == DW_TAG_compile_unit |
5800 | && base_address_type < base_address_low_pc) | |
5801 | { | |
5802 | base_address = DW_ADDR (&attr); | |
5803 | base_address_type = base_address_low_pc; | |
5804 | } | |
c906108c SS |
5805 | break; |
5806 | case DW_AT_high_pc: | |
5807 | has_high_pc_attr = 1; | |
5808 | part_die->highpc = DW_ADDR (&attr); | |
5809 | break; | |
85cbf3d3 JK |
5810 | case DW_AT_entry_pc: |
5811 | if (part_die->tag == DW_TAG_compile_unit | |
5812 | && base_address_type < base_address_entry_pc) | |
5813 | { | |
5814 | base_address = DW_ADDR (&attr); | |
5815 | base_address_type = base_address_entry_pc; | |
5816 | } | |
5817 | break; | |
43039443 | 5818 | case DW_AT_ranges: |
ff013f42 JK |
5819 | if (part_die->tag == DW_TAG_compile_unit) |
5820 | { | |
5821 | cu->ranges_offset = DW_UNSND (&attr); | |
5822 | cu->has_ranges_offset = 1; | |
5823 | } | |
43039443 | 5824 | break; |
c906108c | 5825 | case DW_AT_location: |
8e19ed76 PS |
5826 | /* Support the .debug_loc offsets */ |
5827 | if (attr_form_is_block (&attr)) | |
5828 | { | |
5829 | part_die->locdesc = DW_BLOCK (&attr); | |
5830 | } | |
3690dd37 | 5831 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 5832 | { |
4d3c2250 | 5833 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5834 | } |
5835 | else | |
5836 | { | |
4d3c2250 KB |
5837 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5838 | "partial symbol information"); | |
8e19ed76 | 5839 | } |
c906108c SS |
5840 | break; |
5841 | case DW_AT_language: | |
5842 | part_die->language = DW_UNSND (&attr); | |
5843 | break; | |
5844 | case DW_AT_external: | |
5845 | part_die->is_external = DW_UNSND (&attr); | |
5846 | break; | |
5847 | case DW_AT_declaration: | |
5848 | part_die->is_declaration = DW_UNSND (&attr); | |
5849 | break; | |
5850 | case DW_AT_type: | |
5851 | part_die->has_type = 1; | |
5852 | break; | |
5853 | case DW_AT_abstract_origin: | |
5854 | case DW_AT_specification: | |
72bf9492 DJ |
5855 | case DW_AT_extension: |
5856 | part_die->has_specification = 1; | |
5857 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
5858 | break; |
5859 | case DW_AT_sibling: | |
5860 | /* Ignore absolute siblings, they might point outside of | |
5861 | the current compile unit. */ | |
5862 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 5863 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 5864 | else |
6502dd73 DJ |
5865 | part_die->sibling = dwarf2_per_objfile->info_buffer |
5866 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 5867 | break; |
aaa75496 JB |
5868 | case DW_AT_stmt_list: |
5869 | part_die->has_stmt_list = 1; | |
5870 | part_die->line_offset = DW_UNSND (&attr); | |
5871 | break; | |
fa4028e9 JB |
5872 | case DW_AT_byte_size: |
5873 | part_die->has_byte_size = 1; | |
5874 | break; | |
68511cec CES |
5875 | case DW_AT_calling_convention: |
5876 | /* DWARF doesn't provide a way to identify a program's source-level | |
5877 | entry point. DW_AT_calling_convention attributes are only meant | |
5878 | to describe functions' calling conventions. | |
5879 | ||
5880 | However, because it's a necessary piece of information in | |
5881 | Fortran, and because DW_CC_program is the only piece of debugging | |
5882 | information whose definition refers to a 'main program' at all, | |
5883 | several compilers have begun marking Fortran main programs with | |
5884 | DW_CC_program --- even when those functions use the standard | |
5885 | calling conventions. | |
5886 | ||
5887 | So until DWARF specifies a way to provide this information and | |
5888 | compilers pick up the new representation, we'll support this | |
5889 | practice. */ | |
5890 | if (DW_UNSND (&attr) == DW_CC_program | |
5891 | && cu->language == language_fortran) | |
5892 | set_main_name (part_die->name); | |
5893 | break; | |
c906108c SS |
5894 | default: |
5895 | break; | |
5896 | } | |
5897 | } | |
5898 | ||
c906108c SS |
5899 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
5900 | eliminate duplicate copies of functions and vtables and such. | |
5901 | The linker will arbitrarily choose one and discard the others. | |
5902 | The AT_*_pc values for such functions refer to local labels in | |
5903 | these sections. If the section from that file was discarded, the | |
5904 | labels are not in the output, so the relocs get a value of 0. | |
5905 | If this is a discarded function, mark the pc bounds as invalid, | |
5906 | so that GDB will ignore it. */ | |
5907 | if (has_low_pc_attr && has_high_pc_attr | |
5908 | && part_die->lowpc < part_die->highpc | |
5909 | && (part_die->lowpc != 0 | |
72dca2f5 | 5910 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 5911 | part_die->has_pc_info = 1; |
85cbf3d3 JK |
5912 | |
5913 | if (base_address_type != base_address_none && !cu->header.base_known) | |
5914 | { | |
5915 | gdb_assert (part_die->tag == DW_TAG_compile_unit); | |
5916 | cu->header.base_known = 1; | |
5917 | cu->header.base_address = base_address; | |
5918 | } | |
5919 | ||
c906108c SS |
5920 | return info_ptr; |
5921 | } | |
5922 | ||
72bf9492 DJ |
5923 | /* Find a cached partial DIE at OFFSET in CU. */ |
5924 | ||
5925 | static struct partial_die_info * | |
5926 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
5927 | { | |
5928 | struct partial_die_info *lookup_die = NULL; | |
5929 | struct partial_die_info part_die; | |
5930 | ||
5931 | part_die.offset = offset; | |
5932 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
5933 | ||
72bf9492 DJ |
5934 | return lookup_die; |
5935 | } | |
5936 | ||
5937 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
5938 | ||
5939 | static struct partial_die_info * | |
10b3939b | 5940 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu) |
72bf9492 | 5941 | { |
5afb4e99 DJ |
5942 | struct dwarf2_per_cu_data *per_cu = NULL; |
5943 | struct partial_die_info *pd = NULL; | |
72bf9492 DJ |
5944 | |
5945 | if (offset >= cu->header.offset | |
5946 | && offset < cu->header.offset + cu->header.length) | |
5afb4e99 DJ |
5947 | { |
5948 | pd = find_partial_die_in_comp_unit (offset, cu); | |
5949 | if (pd != NULL) | |
5950 | return pd; | |
5951 | } | |
72bf9492 | 5952 | |
ae038cb0 DJ |
5953 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
5954 | ||
ae038cb0 DJ |
5955 | if (per_cu->cu == NULL) |
5956 | { | |
5957 | load_comp_unit (per_cu, cu->objfile); | |
5958 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5959 | dwarf2_per_objfile->read_in_chain = per_cu; | |
5960 | } | |
5961 | ||
5962 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
5963 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
5964 | ||
5965 | if (pd == NULL && per_cu->load_all_dies == 0) | |
5966 | { | |
5967 | struct cleanup *back_to; | |
5968 | struct partial_die_info comp_unit_die; | |
5969 | struct abbrev_info *abbrev; | |
5970 | unsigned int bytes_read; | |
5971 | char *info_ptr; | |
5972 | ||
5973 | per_cu->load_all_dies = 1; | |
5974 | ||
5975 | /* Re-read the DIEs. */ | |
5976 | back_to = make_cleanup (null_cleanup, 0); | |
5977 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
5978 | { | |
5979 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
5980 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
5981 | } | |
5982 | info_ptr = per_cu->cu->header.first_die_ptr; | |
5983 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); | |
5984 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
5985 | per_cu->cu->objfile->obfd, info_ptr, | |
5986 | per_cu->cu); | |
5987 | if (comp_unit_die.has_children) | |
5988 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
5989 | do_cleanups (back_to); | |
5990 | ||
5991 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
5992 | } | |
5993 | ||
5994 | if (pd == NULL) | |
5995 | internal_error (__FILE__, __LINE__, | |
5996 | _("could not find partial DIE 0x%lx in cache [from module %s]\n"), | |
5997 | offset, bfd_get_filename (cu->objfile->obfd)); | |
5998 | return pd; | |
72bf9492 DJ |
5999 | } |
6000 | ||
6001 | /* Adjust PART_DIE before generating a symbol for it. This function | |
6002 | may set the is_external flag or change the DIE's name. */ | |
6003 | ||
6004 | static void | |
6005 | fixup_partial_die (struct partial_die_info *part_die, | |
6006 | struct dwarf2_cu *cu) | |
6007 | { | |
6008 | /* If we found a reference attribute and the DIE has no name, try | |
6009 | to find a name in the referred to DIE. */ | |
6010 | ||
6011 | if (part_die->name == NULL && part_die->has_specification) | |
6012 | { | |
6013 | struct partial_die_info *spec_die; | |
72bf9492 | 6014 | |
10b3939b | 6015 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6016 | |
10b3939b | 6017 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6018 | |
6019 | if (spec_die->name) | |
6020 | { | |
6021 | part_die->name = spec_die->name; | |
6022 | ||
6023 | /* Copy DW_AT_external attribute if it is set. */ | |
6024 | if (spec_die->is_external) | |
6025 | part_die->is_external = spec_die->is_external; | |
6026 | } | |
6027 | } | |
6028 | ||
6029 | /* Set default names for some unnamed DIEs. */ | |
6030 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6031 | || part_die->tag == DW_TAG_class_type)) | |
6032 | part_die->name = "(anonymous class)"; | |
6033 | ||
6034 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6035 | part_die->name = "(anonymous namespace)"; | |
6036 | ||
6037 | if (part_die->tag == DW_TAG_structure_type | |
6038 | || part_die->tag == DW_TAG_class_type | |
6039 | || part_die->tag == DW_TAG_union_type) | |
6040 | guess_structure_name (part_die, cu); | |
6041 | } | |
6042 | ||
639d11d3 DC |
6043 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6044 | point to a newly allocated die with its information, except for its | |
6045 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6046 | whether the die has children or not. */ | |
c906108c | 6047 | |
fe1b8b76 JB |
6048 | static gdb_byte * |
6049 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 6050 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
6051 | { |
6052 | unsigned int abbrev_number, bytes_read, i, offset; | |
6053 | struct abbrev_info *abbrev; | |
6054 | struct die_info *die; | |
6055 | ||
6502dd73 | 6056 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
6057 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6058 | info_ptr += bytes_read; | |
6059 | if (!abbrev_number) | |
6060 | { | |
6061 | die = dwarf_alloc_die (); | |
6062 | die->tag = 0; | |
6063 | die->abbrev = abbrev_number; | |
c906108c | 6064 | *diep = die; |
639d11d3 | 6065 | *has_children = 0; |
c906108c SS |
6066 | return info_ptr; |
6067 | } | |
6068 | ||
e7c27a73 | 6069 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
6070 | if (!abbrev) |
6071 | { | |
8a3fe4f8 | 6072 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 6073 | abbrev_number, |
639d11d3 | 6074 | bfd_get_filename (abfd)); |
c906108c SS |
6075 | } |
6076 | die = dwarf_alloc_die (); | |
6077 | die->offset = offset; | |
6078 | die->tag = abbrev->tag; | |
c906108c | 6079 | die->abbrev = abbrev_number; |
c906108c SS |
6080 | |
6081 | die->num_attrs = abbrev->num_attrs; | |
6082 | die->attrs = (struct attribute *) | |
6083 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
6084 | ||
6085 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6086 | { | |
6087 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 6088 | abfd, info_ptr, cu); |
10b3939b DJ |
6089 | |
6090 | /* If this attribute is an absolute reference to a different | |
6091 | compilation unit, make sure that compilation unit is loaded | |
6092 | also. */ | |
6093 | if (die->attrs[i].form == DW_FORM_ref_addr | |
6094 | && (DW_ADDR (&die->attrs[i]) < cu->header.offset | |
6095 | || (DW_ADDR (&die->attrs[i]) | |
6096 | >= cu->header.offset + cu->header.length))) | |
6097 | { | |
6098 | struct dwarf2_per_cu_data *per_cu; | |
6099 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (&die->attrs[i]), | |
6100 | cu->objfile); | |
6101 | ||
6102 | /* Mark the dependence relation so that we don't flush PER_CU | |
6103 | too early. */ | |
6104 | dwarf2_add_dependence (cu, per_cu); | |
6105 | ||
6106 | /* If it's already on the queue, we have nothing to do. */ | |
6107 | if (per_cu->queued) | |
6108 | continue; | |
6109 | ||
6110 | /* If the compilation unit is already loaded, just mark it as | |
6111 | used. */ | |
6112 | if (per_cu->cu != NULL) | |
6113 | { | |
6114 | per_cu->cu->last_used = 0; | |
6115 | continue; | |
6116 | } | |
6117 | ||
6118 | /* Add it to the queue. */ | |
6119 | queue_comp_unit (per_cu); | |
6120 | } | |
c906108c SS |
6121 | } |
6122 | ||
6123 | *diep = die; | |
639d11d3 | 6124 | *has_children = abbrev->has_children; |
c906108c SS |
6125 | return info_ptr; |
6126 | } | |
6127 | ||
a8329558 | 6128 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6129 | |
fe1b8b76 | 6130 | static gdb_byte * |
a8329558 | 6131 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 6132 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 6133 | struct dwarf2_cu *cu) |
c906108c | 6134 | { |
e7c27a73 | 6135 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6136 | unsigned int bytes_read; |
6137 | struct dwarf_block *blk; | |
6138 | ||
a8329558 KW |
6139 | attr->form = form; |
6140 | switch (form) | |
c906108c SS |
6141 | { |
6142 | case DW_FORM_addr: | |
6143 | case DW_FORM_ref_addr: | |
e7c27a73 | 6144 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 6145 | info_ptr += bytes_read; |
c906108c SS |
6146 | break; |
6147 | case DW_FORM_block2: | |
7b5a2f43 | 6148 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6149 | blk->size = read_2_bytes (abfd, info_ptr); |
6150 | info_ptr += 2; | |
6151 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6152 | info_ptr += blk->size; | |
6153 | DW_BLOCK (attr) = blk; | |
6154 | break; | |
6155 | case DW_FORM_block4: | |
7b5a2f43 | 6156 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6157 | blk->size = read_4_bytes (abfd, info_ptr); |
6158 | info_ptr += 4; | |
6159 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6160 | info_ptr += blk->size; | |
6161 | DW_BLOCK (attr) = blk; | |
6162 | break; | |
6163 | case DW_FORM_data2: | |
6164 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
6165 | info_ptr += 2; | |
6166 | break; | |
6167 | case DW_FORM_data4: | |
6168 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
6169 | info_ptr += 4; | |
6170 | break; | |
6171 | case DW_FORM_data8: | |
6172 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
6173 | info_ptr += 8; | |
6174 | break; | |
6175 | case DW_FORM_string: | |
6176 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
6177 | info_ptr += bytes_read; | |
6178 | break; | |
4bdf3d34 JJ |
6179 | case DW_FORM_strp: |
6180 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
6181 | &bytes_read); | |
6182 | info_ptr += bytes_read; | |
6183 | break; | |
c906108c | 6184 | case DW_FORM_block: |
7b5a2f43 | 6185 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6186 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6187 | info_ptr += bytes_read; | |
6188 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6189 | info_ptr += blk->size; | |
6190 | DW_BLOCK (attr) = blk; | |
6191 | break; | |
6192 | case DW_FORM_block1: | |
7b5a2f43 | 6193 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6194 | blk->size = read_1_byte (abfd, info_ptr); |
6195 | info_ptr += 1; | |
6196 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6197 | info_ptr += blk->size; | |
6198 | DW_BLOCK (attr) = blk; | |
6199 | break; | |
6200 | case DW_FORM_data1: | |
6201 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6202 | info_ptr += 1; | |
6203 | break; | |
6204 | case DW_FORM_flag: | |
6205 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6206 | info_ptr += 1; | |
6207 | break; | |
6208 | case DW_FORM_sdata: | |
6209 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
6210 | info_ptr += bytes_read; | |
6211 | break; | |
6212 | case DW_FORM_udata: | |
6213 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6214 | info_ptr += bytes_read; | |
6215 | break; | |
6216 | case DW_FORM_ref1: | |
10b3939b | 6217 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
6218 | info_ptr += 1; |
6219 | break; | |
6220 | case DW_FORM_ref2: | |
10b3939b | 6221 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
6222 | info_ptr += 2; |
6223 | break; | |
6224 | case DW_FORM_ref4: | |
10b3939b | 6225 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
6226 | info_ptr += 4; |
6227 | break; | |
613e1657 | 6228 | case DW_FORM_ref8: |
10b3939b | 6229 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
6230 | info_ptr += 8; |
6231 | break; | |
c906108c | 6232 | case DW_FORM_ref_udata: |
10b3939b DJ |
6233 | DW_ADDR (attr) = (cu->header.offset |
6234 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
6235 | info_ptr += bytes_read; |
6236 | break; | |
c906108c | 6237 | case DW_FORM_indirect: |
a8329558 KW |
6238 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6239 | info_ptr += bytes_read; | |
e7c27a73 | 6240 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 6241 | break; |
c906108c | 6242 | default: |
8a3fe4f8 | 6243 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
6244 | dwarf_form_name (form), |
6245 | bfd_get_filename (abfd)); | |
c906108c SS |
6246 | } |
6247 | return info_ptr; | |
6248 | } | |
6249 | ||
a8329558 KW |
6250 | /* Read an attribute described by an abbreviated attribute. */ |
6251 | ||
fe1b8b76 | 6252 | static gdb_byte * |
a8329558 | 6253 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 6254 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
6255 | { |
6256 | attr->name = abbrev->name; | |
e7c27a73 | 6257 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
6258 | } |
6259 | ||
c906108c SS |
6260 | /* read dwarf information from a buffer */ |
6261 | ||
6262 | static unsigned int | |
fe1b8b76 | 6263 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6264 | { |
fe1b8b76 | 6265 | return bfd_get_8 (abfd, buf); |
c906108c SS |
6266 | } |
6267 | ||
6268 | static int | |
fe1b8b76 | 6269 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6270 | { |
fe1b8b76 | 6271 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
6272 | } |
6273 | ||
6274 | static unsigned int | |
fe1b8b76 | 6275 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6276 | { |
fe1b8b76 | 6277 | return bfd_get_16 (abfd, buf); |
c906108c SS |
6278 | } |
6279 | ||
6280 | static int | |
fe1b8b76 | 6281 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6282 | { |
fe1b8b76 | 6283 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
6284 | } |
6285 | ||
6286 | static unsigned int | |
fe1b8b76 | 6287 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6288 | { |
fe1b8b76 | 6289 | return bfd_get_32 (abfd, buf); |
c906108c SS |
6290 | } |
6291 | ||
6292 | static int | |
fe1b8b76 | 6293 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6294 | { |
fe1b8b76 | 6295 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
6296 | } |
6297 | ||
ce5d95e1 | 6298 | static unsigned long |
fe1b8b76 | 6299 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6300 | { |
fe1b8b76 | 6301 | return bfd_get_64 (abfd, buf); |
c906108c SS |
6302 | } |
6303 | ||
6304 | static CORE_ADDR | |
fe1b8b76 | 6305 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 6306 | unsigned int *bytes_read) |
c906108c | 6307 | { |
e7c27a73 | 6308 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6309 | CORE_ADDR retval = 0; |
6310 | ||
107d2387 | 6311 | if (cu_header->signed_addr_p) |
c906108c | 6312 | { |
107d2387 AC |
6313 | switch (cu_header->addr_size) |
6314 | { | |
6315 | case 2: | |
fe1b8b76 | 6316 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6317 | break; |
6318 | case 4: | |
fe1b8b76 | 6319 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6320 | break; |
6321 | case 8: | |
fe1b8b76 | 6322 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6323 | break; |
6324 | default: | |
8e65ff28 | 6325 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6326 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6327 | bfd_get_filename (abfd)); |
107d2387 AC |
6328 | } |
6329 | } | |
6330 | else | |
6331 | { | |
6332 | switch (cu_header->addr_size) | |
6333 | { | |
6334 | case 2: | |
fe1b8b76 | 6335 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6336 | break; |
6337 | case 4: | |
fe1b8b76 | 6338 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6339 | break; |
6340 | case 8: | |
fe1b8b76 | 6341 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6342 | break; |
6343 | default: | |
8e65ff28 | 6344 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6345 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6346 | bfd_get_filename (abfd)); |
107d2387 | 6347 | } |
c906108c | 6348 | } |
64367e0a | 6349 | |
107d2387 AC |
6350 | *bytes_read = cu_header->addr_size; |
6351 | return retval; | |
c906108c SS |
6352 | } |
6353 | ||
f7ef9339 | 6354 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6355 | specification allows the initial length to take up either 4 bytes |
6356 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6357 | bytes describe the length and all offsets will be 8 bytes in length | |
6358 | instead of 4. | |
6359 | ||
f7ef9339 KB |
6360 | An older, non-standard 64-bit format is also handled by this |
6361 | function. The older format in question stores the initial length | |
6362 | as an 8-byte quantity without an escape value. Lengths greater | |
6363 | than 2^32 aren't very common which means that the initial 4 bytes | |
6364 | is almost always zero. Since a length value of zero doesn't make | |
6365 | sense for the 32-bit format, this initial zero can be considered to | |
6366 | be an escape value which indicates the presence of the older 64-bit | |
6367 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6368 | greater than 4GB. If it becomes necessary to handle lengths |
6369 | somewhat larger than 4GB, we could allow other small values (such | |
6370 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6371 | escape values indicating the presence of the old format. | |
f7ef9339 | 6372 | |
917c78fc MK |
6373 | The value returned via bytes_read should be used to increment the |
6374 | relevant pointer after calling read_initial_length(). | |
613e1657 KB |
6375 | |
6376 | As a side effect, this function sets the fields initial_length_size | |
6377 | and offset_size in cu_header to the values appropriate for the | |
6378 | length field. (The format of the initial length field determines | |
dd373385 | 6379 | the width of file offsets to be fetched later with read_offset().) |
613e1657 KB |
6380 | |
6381 | [ Note: read_initial_length() and read_offset() are based on the | |
6382 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6383 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6384 | from: |
6385 | ||
f7ef9339 | 6386 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6387 | |
6388 | This document is only a draft and is subject to change. (So beware.) | |
6389 | ||
f7ef9339 | 6390 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6391 | determined empirically by examining 64-bit ELF files produced by |
6392 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6393 | |
6394 | - Kevin, July 16, 2002 | |
613e1657 KB |
6395 | ] */ |
6396 | ||
6397 | static LONGEST | |
fe1b8b76 | 6398 | read_initial_length (bfd *abfd, gdb_byte *buf, struct comp_unit_head *cu_header, |
891d2f0b | 6399 | unsigned int *bytes_read) |
613e1657 | 6400 | { |
fe1b8b76 | 6401 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6402 | |
dd373385 | 6403 | if (length == 0xffffffff) |
613e1657 | 6404 | { |
fe1b8b76 | 6405 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6406 | *bytes_read = 12; |
613e1657 | 6407 | } |
dd373385 | 6408 | else if (length == 0) |
f7ef9339 | 6409 | { |
dd373385 | 6410 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6411 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6412 | *bytes_read = 8; |
f7ef9339 | 6413 | } |
613e1657 KB |
6414 | else |
6415 | { | |
6416 | *bytes_read = 4; | |
613e1657 KB |
6417 | } |
6418 | ||
dd373385 EZ |
6419 | if (cu_header) |
6420 | { | |
6421 | gdb_assert (cu_header->initial_length_size == 0 | |
6422 | || cu_header->initial_length_size == 4 | |
6423 | || cu_header->initial_length_size == 8 | |
6424 | || cu_header->initial_length_size == 12); | |
6425 | ||
6426 | if (cu_header->initial_length_size != 0 | |
6427 | && cu_header->initial_length_size != *bytes_read) | |
6428 | complaint (&symfile_complaints, | |
6429 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
6430 | ||
6431 | cu_header->initial_length_size = *bytes_read; | |
6432 | cu_header->offset_size = (*bytes_read == 4) ? 4 : 8; | |
6433 | } | |
6434 | ||
6435 | return length; | |
613e1657 KB |
6436 | } |
6437 | ||
6438 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6439 | given by cu_header->offset_size. */ |
613e1657 KB |
6440 | |
6441 | static LONGEST | |
fe1b8b76 | 6442 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6443 | unsigned int *bytes_read) |
613e1657 KB |
6444 | { |
6445 | LONGEST retval = 0; | |
6446 | ||
6447 | switch (cu_header->offset_size) | |
6448 | { | |
6449 | case 4: | |
fe1b8b76 | 6450 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6451 | *bytes_read = 4; |
6452 | break; | |
6453 | case 8: | |
fe1b8b76 | 6454 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6455 | *bytes_read = 8; |
6456 | break; | |
6457 | default: | |
8e65ff28 | 6458 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6459 | _("read_offset: bad switch [in module %s]"), |
659b0389 | 6460 | bfd_get_filename (abfd)); |
613e1657 KB |
6461 | } |
6462 | ||
917c78fc | 6463 | return retval; |
613e1657 KB |
6464 | } |
6465 | ||
fe1b8b76 JB |
6466 | static gdb_byte * |
6467 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6468 | { |
6469 | /* If the size of a host char is 8 bits, we can return a pointer | |
6470 | to the buffer, otherwise we have to copy the data to a buffer | |
6471 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6472 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6473 | return buf; |
c906108c SS |
6474 | } |
6475 | ||
6476 | static char * | |
fe1b8b76 | 6477 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6478 | { |
6479 | /* If the size of a host char is 8 bits, we can return a pointer | |
6480 | to the string, otherwise we have to copy the string to a buffer | |
6481 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6482 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6483 | if (*buf == '\0') |
6484 | { | |
6485 | *bytes_read_ptr = 1; | |
6486 | return NULL; | |
6487 | } | |
fe1b8b76 JB |
6488 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6489 | return (char *) buf; | |
4bdf3d34 JJ |
6490 | } |
6491 | ||
6492 | static char * | |
fe1b8b76 | 6493 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6494 | const struct comp_unit_head *cu_header, |
6495 | unsigned int *bytes_read_ptr) | |
6496 | { | |
6497 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
891d2f0b | 6498 | bytes_read_ptr); |
c906108c | 6499 | |
6502dd73 | 6500 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 6501 | { |
8a3fe4f8 | 6502 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6503 | bfd_get_filename (abfd)); |
4bdf3d34 | 6504 | return NULL; |
c906108c | 6505 | } |
6502dd73 | 6506 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 6507 | { |
8a3fe4f8 | 6508 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6509 | bfd_get_filename (abfd)); |
c906108c SS |
6510 | return NULL; |
6511 | } | |
4bdf3d34 | 6512 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 6513 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 6514 | return NULL; |
fe1b8b76 | 6515 | return (char *) (dwarf2_per_objfile->str_buffer + str_offset); |
c906108c SS |
6516 | } |
6517 | ||
ce5d95e1 | 6518 | static unsigned long |
fe1b8b76 | 6519 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6520 | { |
ce5d95e1 JB |
6521 | unsigned long result; |
6522 | unsigned int num_read; | |
c906108c SS |
6523 | int i, shift; |
6524 | unsigned char byte; | |
6525 | ||
6526 | result = 0; | |
6527 | shift = 0; | |
6528 | num_read = 0; | |
6529 | i = 0; | |
6530 | while (1) | |
6531 | { | |
fe1b8b76 | 6532 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6533 | buf++; |
6534 | num_read++; | |
ce5d95e1 | 6535 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6536 | if ((byte & 128) == 0) |
6537 | { | |
6538 | break; | |
6539 | } | |
6540 | shift += 7; | |
6541 | } | |
6542 | *bytes_read_ptr = num_read; | |
6543 | return result; | |
6544 | } | |
6545 | ||
ce5d95e1 | 6546 | static long |
fe1b8b76 | 6547 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6548 | { |
ce5d95e1 | 6549 | long result; |
77e0b926 | 6550 | int i, shift, num_read; |
c906108c SS |
6551 | unsigned char byte; |
6552 | ||
6553 | result = 0; | |
6554 | shift = 0; | |
c906108c SS |
6555 | num_read = 0; |
6556 | i = 0; | |
6557 | while (1) | |
6558 | { | |
fe1b8b76 | 6559 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6560 | buf++; |
6561 | num_read++; | |
ce5d95e1 | 6562 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6563 | shift += 7; |
6564 | if ((byte & 128) == 0) | |
6565 | { | |
6566 | break; | |
6567 | } | |
6568 | } | |
77e0b926 DJ |
6569 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6570 | result |= -(((long)1) << shift); | |
c906108c SS |
6571 | *bytes_read_ptr = num_read; |
6572 | return result; | |
6573 | } | |
6574 | ||
4bb7a0a7 DJ |
6575 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6576 | ||
fe1b8b76 JB |
6577 | static gdb_byte * |
6578 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6579 | { |
6580 | int byte; | |
6581 | ||
6582 | while (1) | |
6583 | { | |
fe1b8b76 | 6584 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6585 | buf++; |
6586 | if ((byte & 128) == 0) | |
6587 | return buf; | |
6588 | } | |
6589 | } | |
6590 | ||
c906108c | 6591 | static void |
e142c38c | 6592 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6593 | { |
6594 | switch (lang) | |
6595 | { | |
6596 | case DW_LANG_C89: | |
6597 | case DW_LANG_C: | |
e142c38c | 6598 | cu->language = language_c; |
c906108c SS |
6599 | break; |
6600 | case DW_LANG_C_plus_plus: | |
e142c38c | 6601 | cu->language = language_cplus; |
c906108c SS |
6602 | break; |
6603 | case DW_LANG_Fortran77: | |
6604 | case DW_LANG_Fortran90: | |
b21b22e0 | 6605 | case DW_LANG_Fortran95: |
e142c38c | 6606 | cu->language = language_fortran; |
c906108c SS |
6607 | break; |
6608 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6609 | cu->language = language_asm; |
c906108c | 6610 | break; |
bebd888e | 6611 | case DW_LANG_Java: |
e142c38c | 6612 | cu->language = language_java; |
bebd888e | 6613 | break; |
c906108c | 6614 | case DW_LANG_Ada83: |
8aaf0b47 | 6615 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6616 | cu->language = language_ada; |
6617 | break; | |
72019c9c GM |
6618 | case DW_LANG_Modula2: |
6619 | cu->language = language_m2; | |
6620 | break; | |
fe8e67fd PM |
6621 | case DW_LANG_Pascal83: |
6622 | cu->language = language_pascal; | |
6623 | break; | |
22566fbd DJ |
6624 | case DW_LANG_ObjC: |
6625 | cu->language = language_objc; | |
6626 | break; | |
c906108c SS |
6627 | case DW_LANG_Cobol74: |
6628 | case DW_LANG_Cobol85: | |
c906108c | 6629 | default: |
e142c38c | 6630 | cu->language = language_minimal; |
c906108c SS |
6631 | break; |
6632 | } | |
e142c38c | 6633 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6634 | } |
6635 | ||
6636 | /* Return the named attribute or NULL if not there. */ | |
6637 | ||
6638 | static struct attribute * | |
e142c38c | 6639 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6640 | { |
6641 | unsigned int i; | |
6642 | struct attribute *spec = NULL; | |
6643 | ||
6644 | for (i = 0; i < die->num_attrs; ++i) | |
6645 | { | |
6646 | if (die->attrs[i].name == name) | |
10b3939b | 6647 | return &die->attrs[i]; |
c906108c SS |
6648 | if (die->attrs[i].name == DW_AT_specification |
6649 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6650 | spec = &die->attrs[i]; | |
6651 | } | |
c906108c | 6652 | |
10b3939b DJ |
6653 | if (spec) |
6654 | return dwarf2_attr (follow_die_ref (die, spec, cu), name, cu); | |
c5aa993b | 6655 | |
c906108c SS |
6656 | return NULL; |
6657 | } | |
6658 | ||
05cf31d1 JB |
6659 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6660 | and holds a non-zero value. This function should only be used for | |
6661 | DW_FORM_flag attributes. */ | |
6662 | ||
6663 | static int | |
6664 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6665 | { | |
6666 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6667 | ||
6668 | return (attr && DW_UNSND (attr)); | |
6669 | } | |
6670 | ||
3ca72b44 | 6671 | static int |
e142c38c | 6672 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6673 | { |
05cf31d1 JB |
6674 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6675 | which value is non-zero. However, we have to be careful with | |
6676 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6677 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6678 | end up accidently finding a declaration attribute that belongs | |
6679 | to a different DIE referenced by the specification attribute, | |
6680 | even though the given DIE does not have a declaration attribute. */ | |
6681 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6682 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6683 | } |
6684 | ||
63d06c5c DC |
6685 | /* Return the die giving the specification for DIE, if there is |
6686 | one. */ | |
6687 | ||
6688 | static struct die_info * | |
e142c38c | 6689 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 6690 | { |
e142c38c | 6691 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
6692 | |
6693 | if (spec_attr == NULL) | |
6694 | return NULL; | |
6695 | else | |
10b3939b | 6696 | return follow_die_ref (die, spec_attr, cu); |
63d06c5c | 6697 | } |
c906108c | 6698 | |
debd256d JB |
6699 | /* Free the line_header structure *LH, and any arrays and strings it |
6700 | refers to. */ | |
6701 | static void | |
6702 | free_line_header (struct line_header *lh) | |
6703 | { | |
6704 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6705 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6706 | |
6707 | /* Remember that all the lh->file_names[i].name pointers are | |
6708 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6709 | if (lh->file_names) | |
a8bc7b56 | 6710 | xfree (lh->file_names); |
debd256d JB |
6711 | |
6712 | /* Similarly for the include directory names. */ | |
6713 | if (lh->include_dirs) | |
a8bc7b56 | 6714 | xfree (lh->include_dirs); |
debd256d | 6715 | |
a8bc7b56 | 6716 | xfree (lh); |
debd256d JB |
6717 | } |
6718 | ||
6719 | ||
6720 | /* Add an entry to LH's include directory table. */ | |
6721 | static void | |
6722 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6723 | { |
debd256d JB |
6724 | /* Grow the array if necessary. */ |
6725 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6726 | { |
debd256d JB |
6727 | lh->include_dirs_size = 1; /* for testing */ |
6728 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6729 | * sizeof (*lh->include_dirs)); | |
6730 | } | |
6731 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
6732 | { | |
6733 | lh->include_dirs_size *= 2; | |
6734 | lh->include_dirs = xrealloc (lh->include_dirs, | |
6735 | (lh->include_dirs_size | |
6736 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 6737 | } |
c906108c | 6738 | |
debd256d JB |
6739 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
6740 | } | |
6741 | ||
6742 | ||
6743 | /* Add an entry to LH's file name table. */ | |
6744 | static void | |
6745 | add_file_name (struct line_header *lh, | |
6746 | char *name, | |
6747 | unsigned int dir_index, | |
6748 | unsigned int mod_time, | |
6749 | unsigned int length) | |
6750 | { | |
6751 | struct file_entry *fe; | |
6752 | ||
6753 | /* Grow the array if necessary. */ | |
6754 | if (lh->file_names_size == 0) | |
6755 | { | |
6756 | lh->file_names_size = 1; /* for testing */ | |
6757 | lh->file_names = xmalloc (lh->file_names_size | |
6758 | * sizeof (*lh->file_names)); | |
6759 | } | |
6760 | else if (lh->num_file_names >= lh->file_names_size) | |
6761 | { | |
6762 | lh->file_names_size *= 2; | |
6763 | lh->file_names = xrealloc (lh->file_names, | |
6764 | (lh->file_names_size | |
6765 | * sizeof (*lh->file_names))); | |
6766 | } | |
6767 | ||
6768 | fe = &lh->file_names[lh->num_file_names++]; | |
6769 | fe->name = name; | |
6770 | fe->dir_index = dir_index; | |
6771 | fe->mod_time = mod_time; | |
6772 | fe->length = length; | |
aaa75496 | 6773 | fe->included_p = 0; |
cb1df416 | 6774 | fe->symtab = NULL; |
debd256d JB |
6775 | } |
6776 | ||
6777 | ||
6778 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
6779 | .debug_line, according to the endianness of ABFD. Return a pointer |
6780 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
6781 | |
6782 | NOTE: the strings in the include directory and file name tables of | |
6783 | the returned object point into debug_line_buffer, and must not be | |
6784 | freed. */ | |
6785 | static struct line_header * | |
6786 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 6787 | struct dwarf2_cu *cu) |
debd256d JB |
6788 | { |
6789 | struct cleanup *back_to; | |
6790 | struct line_header *lh; | |
fe1b8b76 | 6791 | gdb_byte *line_ptr; |
891d2f0b | 6792 | unsigned int bytes_read; |
debd256d JB |
6793 | int i; |
6794 | char *cur_dir, *cur_file; | |
6795 | ||
6502dd73 | 6796 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 6797 | { |
e2e0b3e5 | 6798 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
6799 | return 0; |
6800 | } | |
6801 | ||
a738430d MK |
6802 | /* Make sure that at least there's room for the total_length field. |
6803 | That could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 6804 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 6805 | { |
4d3c2250 | 6806 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6807 | return 0; |
6808 | } | |
6809 | ||
6810 | lh = xmalloc (sizeof (*lh)); | |
6811 | memset (lh, 0, sizeof (*lh)); | |
6812 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
6813 | (void *) lh); | |
6814 | ||
6502dd73 | 6815 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d | 6816 | |
a738430d | 6817 | /* Read in the header. */ |
dd373385 EZ |
6818 | lh->total_length = |
6819 | read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); | |
debd256d | 6820 | line_ptr += bytes_read; |
6502dd73 DJ |
6821 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
6822 | + dwarf2_per_objfile->line_size)) | |
debd256d | 6823 | { |
4d3c2250 | 6824 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6825 | return 0; |
6826 | } | |
6827 | lh->statement_program_end = line_ptr + lh->total_length; | |
6828 | lh->version = read_2_bytes (abfd, line_ptr); | |
6829 | line_ptr += 2; | |
e7c27a73 | 6830 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
6831 | line_ptr += bytes_read; |
6832 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
6833 | line_ptr += 1; | |
6834 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
6835 | line_ptr += 1; | |
6836 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
6837 | line_ptr += 1; | |
6838 | lh->line_range = read_1_byte (abfd, line_ptr); | |
6839 | line_ptr += 1; | |
6840 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
6841 | line_ptr += 1; | |
6842 | lh->standard_opcode_lengths | |
fe1b8b76 | 6843 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
6844 | |
6845 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
6846 | for (i = 1; i < lh->opcode_base; ++i) | |
6847 | { | |
6848 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
6849 | line_ptr += 1; | |
6850 | } | |
6851 | ||
a738430d | 6852 | /* Read directory table. */ |
debd256d JB |
6853 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6854 | { | |
6855 | line_ptr += bytes_read; | |
6856 | add_include_dir (lh, cur_dir); | |
6857 | } | |
6858 | line_ptr += bytes_read; | |
6859 | ||
a738430d | 6860 | /* Read file name table. */ |
debd256d JB |
6861 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6862 | { | |
6863 | unsigned int dir_index, mod_time, length; | |
6864 | ||
6865 | line_ptr += bytes_read; | |
6866 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6867 | line_ptr += bytes_read; | |
6868 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6869 | line_ptr += bytes_read; | |
6870 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6871 | line_ptr += bytes_read; | |
6872 | ||
6873 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6874 | } | |
6875 | line_ptr += bytes_read; | |
6876 | lh->statement_program_start = line_ptr; | |
6877 | ||
6502dd73 DJ |
6878 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
6879 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 | 6880 | complaint (&symfile_complaints, |
e2e0b3e5 | 6881 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
6882 | |
6883 | discard_cleanups (back_to); | |
6884 | return lh; | |
6885 | } | |
c906108c | 6886 | |
5fb290d7 DJ |
6887 | /* This function exists to work around a bug in certain compilers |
6888 | (particularly GCC 2.95), in which the first line number marker of a | |
6889 | function does not show up until after the prologue, right before | |
6890 | the second line number marker. This function shifts ADDRESS down | |
6891 | to the beginning of the function if necessary, and is called on | |
6892 | addresses passed to record_line. */ | |
6893 | ||
6894 | static CORE_ADDR | |
e142c38c | 6895 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
6896 | { |
6897 | struct function_range *fn; | |
6898 | ||
6899 | /* Find the function_range containing address. */ | |
e142c38c | 6900 | if (!cu->first_fn) |
5fb290d7 DJ |
6901 | return address; |
6902 | ||
e142c38c DJ |
6903 | if (!cu->cached_fn) |
6904 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 6905 | |
e142c38c | 6906 | fn = cu->cached_fn; |
5fb290d7 DJ |
6907 | while (fn) |
6908 | if (fn->lowpc <= address && fn->highpc > address) | |
6909 | goto found; | |
6910 | else | |
6911 | fn = fn->next; | |
6912 | ||
e142c38c DJ |
6913 | fn = cu->first_fn; |
6914 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
6915 | if (fn->lowpc <= address && fn->highpc > address) |
6916 | goto found; | |
6917 | else | |
6918 | fn = fn->next; | |
6919 | ||
6920 | return address; | |
6921 | ||
6922 | found: | |
6923 | if (fn->seen_line) | |
6924 | return address; | |
6925 | if (address != fn->lowpc) | |
4d3c2250 | 6926 | complaint (&symfile_complaints, |
e2e0b3e5 | 6927 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 6928 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
6929 | fn->seen_line = 1; |
6930 | return fn->lowpc; | |
6931 | } | |
6932 | ||
aaa75496 JB |
6933 | /* Decode the Line Number Program (LNP) for the given line_header |
6934 | structure and CU. The actual information extracted and the type | |
6935 | of structures created from the LNP depends on the value of PST. | |
6936 | ||
6937 | 1. If PST is NULL, then this procedure uses the data from the program | |
6938 | to create all necessary symbol tables, and their linetables. | |
6939 | The compilation directory of the file is passed in COMP_DIR, | |
6940 | and must not be NULL. | |
6941 | ||
6942 | 2. If PST is not NULL, this procedure reads the program to determine | |
6943 | the list of files included by the unit represented by PST, and | |
6944 | builds all the associated partial symbol tables. In this case, | |
6945 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
6946 | is not used to compute the full name of the symtab, and therefore | |
6947 | omitting it when building the partial symtab does not introduce | |
6948 | the potential for inconsistency - a partial symtab and its associated | |
6949 | symbtab having a different fullname -). */ | |
debd256d | 6950 | |
c906108c | 6951 | static void |
debd256d | 6952 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 6953 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 6954 | { |
a8c50c1f | 6955 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 6956 | gdb_byte *line_end; |
a8c50c1f | 6957 | unsigned int bytes_read, extended_len; |
c906108c | 6958 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
6959 | CORE_ADDR baseaddr; |
6960 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 6961 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 6962 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
6963 | |
6964 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6965 | |
debd256d JB |
6966 | line_ptr = lh->statement_program_start; |
6967 | line_end = lh->statement_program_end; | |
c906108c SS |
6968 | |
6969 | /* Read the statement sequences until there's nothing left. */ | |
6970 | while (line_ptr < line_end) | |
6971 | { | |
6972 | /* state machine registers */ | |
6973 | CORE_ADDR address = 0; | |
6974 | unsigned int file = 1; | |
6975 | unsigned int line = 1; | |
6976 | unsigned int column = 0; | |
debd256d | 6977 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
6978 | int basic_block = 0; |
6979 | int end_sequence = 0; | |
6980 | ||
aaa75496 | 6981 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 6982 | { |
aaa75496 | 6983 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
6984 | /* lh->include_dirs and lh->file_names are 0-based, but the |
6985 | directory and file name numbers in the statement program | |
6986 | are 1-based. */ | |
6987 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 6988 | char *dir = NULL; |
a738430d | 6989 | |
debd256d JB |
6990 | if (fe->dir_index) |
6991 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
6992 | |
6993 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
6994 | } |
6995 | ||
a738430d | 6996 | /* Decode the table. */ |
c5aa993b | 6997 | while (!end_sequence) |
c906108c SS |
6998 | { |
6999 | op_code = read_1_byte (abfd, line_ptr); | |
7000 | line_ptr += 1; | |
9aa1fe7e | 7001 | |
debd256d | 7002 | if (op_code >= lh->opcode_base) |
a738430d MK |
7003 | { |
7004 | /* Special operand. */ | |
debd256d JB |
7005 | adj_opcode = op_code - lh->opcode_base; |
7006 | address += (adj_opcode / lh->line_range) | |
7007 | * lh->minimum_instruction_length; | |
7008 | line += lh->line_base + (adj_opcode % lh->line_range); | |
25e43795 DJ |
7009 | if (lh->num_file_names < file) |
7010 | dwarf2_debug_line_missing_file_complaint (); | |
7011 | else | |
7012 | { | |
7013 | lh->file_names[file - 1].included_p = 1; | |
7014 | if (!decode_for_pst_p) | |
7015 | { | |
7016 | if (last_subfile != current_subfile) | |
7017 | { | |
7018 | if (last_subfile) | |
7019 | record_line (last_subfile, 0, address); | |
7020 | last_subfile = current_subfile; | |
7021 | } | |
7022 | /* Append row to matrix using current values. */ | |
7023 | record_line (current_subfile, line, | |
7024 | check_cu_functions (address, cu)); | |
366da635 | 7025 | } |
25e43795 | 7026 | } |
9aa1fe7e GK |
7027 | basic_block = 1; |
7028 | } | |
7029 | else switch (op_code) | |
c906108c SS |
7030 | { |
7031 | case DW_LNS_extended_op: | |
a8c50c1f | 7032 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7033 | line_ptr += bytes_read; |
a8c50c1f | 7034 | extended_end = line_ptr + extended_len; |
c906108c SS |
7035 | extended_op = read_1_byte (abfd, line_ptr); |
7036 | line_ptr += 1; | |
7037 | switch (extended_op) | |
7038 | { | |
7039 | case DW_LNE_end_sequence: | |
7040 | end_sequence = 1; | |
25e43795 DJ |
7041 | |
7042 | if (lh->num_file_names < file) | |
7043 | dwarf2_debug_line_missing_file_complaint (); | |
7044 | else | |
7045 | { | |
7046 | lh->file_names[file - 1].included_p = 1; | |
7047 | if (!decode_for_pst_p) | |
7048 | record_line (current_subfile, 0, address); | |
7049 | } | |
c906108c SS |
7050 | break; |
7051 | case DW_LNE_set_address: | |
e7c27a73 | 7052 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7053 | line_ptr += bytes_read; |
7054 | address += baseaddr; | |
c906108c SS |
7055 | break; |
7056 | case DW_LNE_define_file: | |
debd256d JB |
7057 | { |
7058 | char *cur_file; | |
7059 | unsigned int dir_index, mod_time, length; | |
7060 | ||
7061 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
7062 | line_ptr += bytes_read; | |
7063 | dir_index = | |
7064 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7065 | line_ptr += bytes_read; | |
7066 | mod_time = | |
7067 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7068 | line_ptr += bytes_read; | |
7069 | length = | |
7070 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7071 | line_ptr += bytes_read; | |
7072 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7073 | } | |
c906108c SS |
7074 | break; |
7075 | default: | |
4d3c2250 | 7076 | complaint (&symfile_complaints, |
e2e0b3e5 | 7077 | _("mangled .debug_line section")); |
debd256d | 7078 | return; |
c906108c | 7079 | } |
a8c50c1f DJ |
7080 | /* Make sure that we parsed the extended op correctly. If e.g. |
7081 | we expected a different address size than the producer used, | |
7082 | we may have read the wrong number of bytes. */ | |
7083 | if (line_ptr != extended_end) | |
7084 | { | |
7085 | complaint (&symfile_complaints, | |
7086 | _("mangled .debug_line section")); | |
7087 | return; | |
7088 | } | |
c906108c SS |
7089 | break; |
7090 | case DW_LNS_copy: | |
25e43795 DJ |
7091 | if (lh->num_file_names < file) |
7092 | dwarf2_debug_line_missing_file_complaint (); | |
7093 | else | |
366da635 | 7094 | { |
25e43795 DJ |
7095 | lh->file_names[file - 1].included_p = 1; |
7096 | if (!decode_for_pst_p) | |
7097 | { | |
7098 | if (last_subfile != current_subfile) | |
7099 | { | |
7100 | if (last_subfile) | |
7101 | record_line (last_subfile, 0, address); | |
7102 | last_subfile = current_subfile; | |
7103 | } | |
7104 | record_line (current_subfile, line, | |
7105 | check_cu_functions (address, cu)); | |
7106 | } | |
366da635 | 7107 | } |
c906108c SS |
7108 | basic_block = 0; |
7109 | break; | |
7110 | case DW_LNS_advance_pc: | |
debd256d | 7111 | address += lh->minimum_instruction_length |
c906108c SS |
7112 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7113 | line_ptr += bytes_read; | |
7114 | break; | |
7115 | case DW_LNS_advance_line: | |
7116 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
7117 | line_ptr += bytes_read; | |
7118 | break; | |
7119 | case DW_LNS_set_file: | |
debd256d | 7120 | { |
a738430d MK |
7121 | /* The arrays lh->include_dirs and lh->file_names are |
7122 | 0-based, but the directory and file name numbers in | |
7123 | the statement program are 1-based. */ | |
debd256d | 7124 | struct file_entry *fe; |
4f1520fb | 7125 | char *dir = NULL; |
a738430d | 7126 | |
debd256d JB |
7127 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7128 | line_ptr += bytes_read; | |
25e43795 DJ |
7129 | if (lh->num_file_names < file) |
7130 | dwarf2_debug_line_missing_file_complaint (); | |
7131 | else | |
7132 | { | |
7133 | fe = &lh->file_names[file - 1]; | |
7134 | if (fe->dir_index) | |
7135 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7136 | if (!decode_for_pst_p) | |
7137 | { | |
7138 | last_subfile = current_subfile; | |
7139 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7140 | } | |
7141 | } | |
debd256d | 7142 | } |
c906108c SS |
7143 | break; |
7144 | case DW_LNS_set_column: | |
7145 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7146 | line_ptr += bytes_read; | |
7147 | break; | |
7148 | case DW_LNS_negate_stmt: | |
7149 | is_stmt = (!is_stmt); | |
7150 | break; | |
7151 | case DW_LNS_set_basic_block: | |
7152 | basic_block = 1; | |
7153 | break; | |
c2c6d25f JM |
7154 | /* Add to the address register of the state machine the |
7155 | address increment value corresponding to special opcode | |
a738430d MK |
7156 | 255. I.e., this value is scaled by the minimum |
7157 | instruction length since special opcode 255 would have | |
7158 | scaled the the increment. */ | |
c906108c | 7159 | case DW_LNS_const_add_pc: |
debd256d JB |
7160 | address += (lh->minimum_instruction_length |
7161 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
7162 | break; |
7163 | case DW_LNS_fixed_advance_pc: | |
7164 | address += read_2_bytes (abfd, line_ptr); | |
7165 | line_ptr += 2; | |
7166 | break; | |
9aa1fe7e | 7167 | default: |
a738430d MK |
7168 | { |
7169 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 7170 | int i; |
a738430d | 7171 | |
debd256d | 7172 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
7173 | { |
7174 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7175 | line_ptr += bytes_read; | |
7176 | } | |
7177 | } | |
c906108c SS |
7178 | } |
7179 | } | |
7180 | } | |
aaa75496 JB |
7181 | |
7182 | if (decode_for_pst_p) | |
7183 | { | |
7184 | int file_index; | |
7185 | ||
7186 | /* Now that we're done scanning the Line Header Program, we can | |
7187 | create the psymtab of each included file. */ | |
7188 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
7189 | if (lh->file_names[file_index].included_p == 1) | |
7190 | { | |
5b5464ad JB |
7191 | const struct file_entry fe = lh->file_names [file_index]; |
7192 | char *include_name = fe.name; | |
7193 | char *dir_name = NULL; | |
7194 | char *pst_filename = pst->filename; | |
7195 | ||
7196 | if (fe.dir_index) | |
7197 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
7198 | ||
7199 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
7200 | { | |
1754f103 MK |
7201 | include_name = concat (dir_name, SLASH_STRING, |
7202 | include_name, (char *)NULL); | |
5b5464ad JB |
7203 | make_cleanup (xfree, include_name); |
7204 | } | |
7205 | ||
7206 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
7207 | { | |
1754f103 MK |
7208 | pst_filename = concat (pst->dirname, SLASH_STRING, |
7209 | pst_filename, (char *)NULL); | |
5b5464ad JB |
7210 | make_cleanup (xfree, pst_filename); |
7211 | } | |
7212 | ||
7213 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
7214 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
7215 | } | |
7216 | } | |
cb1df416 DJ |
7217 | else |
7218 | { | |
7219 | /* Make sure a symtab is created for every file, even files | |
7220 | which contain only variables (i.e. no code with associated | |
7221 | line numbers). */ | |
7222 | ||
7223 | int i; | |
7224 | struct file_entry *fe; | |
7225 | ||
7226 | for (i = 0; i < lh->num_file_names; i++) | |
7227 | { | |
7228 | char *dir = NULL; | |
7229 | fe = &lh->file_names[i]; | |
7230 | if (fe->dir_index) | |
7231 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7232 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7233 | ||
7234 | /* Skip the main file; we don't need it, and it must be | |
7235 | allocated last, so that it will show up before the | |
7236 | non-primary symtabs in the objfile's symtab list. */ | |
7237 | if (current_subfile == first_subfile) | |
7238 | continue; | |
7239 | ||
7240 | if (current_subfile->symtab == NULL) | |
7241 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
7242 | cu->objfile); | |
7243 | fe->symtab = current_subfile->symtab; | |
7244 | } | |
7245 | } | |
c906108c SS |
7246 | } |
7247 | ||
7248 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
7249 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
7250 | or NULL if not known. COMP_DIR is the compilation directory for the |
7251 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
7252 | This routine tries to keep line numbers from identical absolute and |
7253 | relative file names in a common subfile. | |
7254 | ||
7255 | Using the `list' example from the GDB testsuite, which resides in | |
7256 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
7257 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
7258 | ||
c5aa993b JM |
7259 | DW_AT_name: /srcdir/list0.c |
7260 | DW_AT_comp_dir: /compdir | |
357e46e7 | 7261 | files.files[0].name: list0.h |
c5aa993b | 7262 | files.files[0].dir: /srcdir |
357e46e7 | 7263 | files.files[1].name: list0.c |
c5aa993b | 7264 | files.files[1].dir: /srcdir |
c906108c SS |
7265 | |
7266 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
7267 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
7268 | start_subfile will ensure that this happens provided that we pass the | |
7269 | concatenation of files.files[1].dir and files.files[1].name as the | |
7270 | subfile's name. */ | |
c906108c SS |
7271 | |
7272 | static void | |
4f1520fb | 7273 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 7274 | { |
4f1520fb FR |
7275 | char *fullname; |
7276 | ||
7277 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
7278 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
7279 | second argument to start_subfile. To be consistent, we do the | |
7280 | same here. In order not to lose the line information directory, | |
7281 | we concatenate it to the filename when it makes sense. | |
7282 | Note that the Dwarf3 standard says (speaking of filenames in line | |
7283 | information): ``The directory index is ignored for file names | |
7284 | that represent full path names''. Thus ignoring dirname in the | |
7285 | `else' branch below isn't an issue. */ | |
c906108c | 7286 | |
d5166ae1 | 7287 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
7288 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
7289 | else | |
7290 | fullname = filename; | |
c906108c | 7291 | |
4f1520fb FR |
7292 | start_subfile (fullname, comp_dir); |
7293 | ||
7294 | if (fullname != filename) | |
7295 | xfree (fullname); | |
c906108c SS |
7296 | } |
7297 | ||
4c2df51b DJ |
7298 | static void |
7299 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 7300 | struct dwarf2_cu *cu) |
4c2df51b | 7301 | { |
e7c27a73 DJ |
7302 | struct objfile *objfile = cu->objfile; |
7303 | struct comp_unit_head *cu_header = &cu->header; | |
7304 | ||
4c2df51b DJ |
7305 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
7306 | code here to turn a symbol with DW_AT_external and a | |
7307 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
7308 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
7309 | with some versions of binutils) where shared libraries could have | |
7310 | relocations against symbols in their debug information - the | |
7311 | minimal symbol would have the right address, but the debug info | |
7312 | would not. It's no longer necessary, because we will explicitly | |
7313 | apply relocations when we read in the debug information now. */ | |
7314 | ||
7315 | /* A DW_AT_location attribute with no contents indicates that a | |
7316 | variable has been optimized away. */ | |
7317 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
7318 | { | |
7319 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
7320 | return; | |
7321 | } | |
7322 | ||
7323 | /* Handle one degenerate form of location expression specially, to | |
7324 | preserve GDB's previous behavior when section offsets are | |
7325 | specified. If this is just a DW_OP_addr then mark this symbol | |
7326 | as LOC_STATIC. */ | |
7327 | ||
7328 | if (attr_form_is_block (attr) | |
7329 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
7330 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
7331 | { | |
891d2f0b | 7332 | unsigned int dummy; |
4c2df51b DJ |
7333 | |
7334 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 7335 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
4c2df51b DJ |
7336 | fixup_symbol_section (sym, objfile); |
7337 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
7338 | SYMBOL_SECTION (sym)); | |
7339 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
7340 | return; | |
7341 | } | |
7342 | ||
7343 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
7344 | expression evaluator, and use LOC_COMPUTED only when necessary | |
7345 | (i.e. when the value of a register or memory location is | |
7346 | referenced, or a thread-local block, etc.). Then again, it might | |
7347 | not be worthwhile. I'm assuming that it isn't unless performance | |
7348 | or memory numbers show me otherwise. */ | |
7349 | ||
e7c27a73 | 7350 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
7351 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
7352 | } | |
7353 | ||
c906108c SS |
7354 | /* Given a pointer to a DWARF information entry, figure out if we need |
7355 | to make a symbol table entry for it, and if so, create a new entry | |
7356 | and return a pointer to it. | |
7357 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 7358 | used the passed type. */ |
c906108c SS |
7359 | |
7360 | static struct symbol * | |
e7c27a73 | 7361 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 7362 | { |
e7c27a73 | 7363 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7364 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7365 | struct symbol *sym = NULL; |
7366 | char *name; | |
7367 | struct attribute *attr = NULL; | |
7368 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
7369 | CORE_ADDR baseaddr; |
7370 | ||
7371 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7372 | |
5c4e30ca | 7373 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7374 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7375 | else |
7376 | name = TYPE_NAME (type); | |
7377 | ||
c906108c SS |
7378 | if (name) |
7379 | { | |
4a146b47 | 7380 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7381 | sizeof (struct symbol)); |
7382 | OBJSTAT (objfile, n_syms++); | |
7383 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7384 | |
7385 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7386 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7387 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7388 | |
7389 | /* Default assumptions. | |
c5aa993b | 7390 | Use the passed type or decode it from the die. */ |
176620f1 | 7391 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7392 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7393 | if (type != NULL) |
7394 | SYMBOL_TYPE (sym) = type; | |
7395 | else | |
e7c27a73 | 7396 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7397 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7398 | if (attr) |
7399 | { | |
7400 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7401 | } | |
cb1df416 DJ |
7402 | |
7403 | attr = dwarf2_attr (die, DW_AT_decl_file, cu); | |
7404 | if (attr) | |
7405 | { | |
7406 | int file_index = DW_UNSND (attr); | |
7407 | if (cu->line_header == NULL | |
7408 | || file_index > cu->line_header->num_file_names) | |
7409 | complaint (&symfile_complaints, | |
7410 | _("file index out of range")); | |
1c3d648d | 7411 | else if (file_index > 0) |
cb1df416 DJ |
7412 | { |
7413 | struct file_entry *fe; | |
7414 | fe = &cu->line_header->file_names[file_index - 1]; | |
7415 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
7416 | } | |
7417 | } | |
7418 | ||
c906108c SS |
7419 | switch (die->tag) |
7420 | { | |
7421 | case DW_TAG_label: | |
e142c38c | 7422 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7423 | if (attr) |
7424 | { | |
7425 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7426 | } | |
7427 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7428 | break; | |
7429 | case DW_TAG_subprogram: | |
7430 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7431 | finish_block. */ | |
7432 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7433 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
7434 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
7435 | || cu->language == language_ada) | |
c906108c | 7436 | { |
2cfa0c8d JB |
7437 | /* Subprograms marked external are stored as a global symbol. |
7438 | Ada subprograms, whether marked external or not, are always | |
7439 | stored as a global symbol, because we want to be able to | |
7440 | access them globally. For instance, we want to be able | |
7441 | to break on a nested subprogram without having to | |
7442 | specify the context. */ | |
c906108c SS |
7443 | add_symbol_to_list (sym, &global_symbols); |
7444 | } | |
7445 | else | |
7446 | { | |
e142c38c | 7447 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7448 | } |
7449 | break; | |
7450 | case DW_TAG_variable: | |
7451 | /* Compilation with minimal debug info may result in variables | |
7452 | with missing type entries. Change the misleading `void' type | |
7453 | to something sensible. */ | |
7454 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 7455 | SYMBOL_TYPE (sym) |
5e2b427d | 7456 | = builtin_type (gdbarch)->nodebug_data_symbol; |
64c50499 | 7457 | |
e142c38c | 7458 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7459 | if (attr) |
7460 | { | |
e7c27a73 | 7461 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7462 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7463 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7464 | add_symbol_to_list (sym, &global_symbols); | |
7465 | else | |
e142c38c | 7466 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7467 | break; |
7468 | } | |
e142c38c | 7469 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7470 | if (attr) |
7471 | { | |
e7c27a73 | 7472 | var_decode_location (attr, sym, cu); |
e142c38c | 7473 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7474 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7475 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7476 | else |
e142c38c | 7477 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7478 | } |
7479 | else | |
7480 | { | |
7481 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7482 | If it is an external symbol and we have type information |
7483 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7484 | The address of the variable will then be determined from | |
7485 | the minimal symbol table whenever the variable is | |
7486 | referenced. */ | |
e142c38c | 7487 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7488 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7489 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7490 | { |
7491 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
7492 | add_symbol_to_list (sym, &global_symbols); | |
7493 | } | |
7494 | } | |
7495 | break; | |
7496 | case DW_TAG_formal_parameter: | |
e142c38c | 7497 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7498 | if (attr) |
7499 | { | |
e7c27a73 | 7500 | var_decode_location (attr, sym, cu); |
7cf6e574 DJ |
7501 | /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ |
7502 | if (SYMBOL_CLASS (sym) == LOC_COMPUTED) | |
7503 | SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; | |
c906108c | 7504 | } |
e142c38c | 7505 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7506 | if (attr) |
7507 | { | |
e7c27a73 | 7508 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7509 | } |
e142c38c | 7510 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7511 | break; |
7512 | case DW_TAG_unspecified_parameters: | |
7513 | /* From varargs functions; gdb doesn't seem to have any | |
7514 | interest in this information, so just ignore it for now. | |
7515 | (FIXME?) */ | |
7516 | break; | |
7517 | case DW_TAG_class_type: | |
680b30c7 | 7518 | case DW_TAG_interface_type: |
c906108c SS |
7519 | case DW_TAG_structure_type: |
7520 | case DW_TAG_union_type: | |
72019c9c | 7521 | case DW_TAG_set_type: |
c906108c SS |
7522 | case DW_TAG_enumeration_type: |
7523 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 7524 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 7525 | |
63d06c5c DC |
7526 | /* Make sure that the symbol includes appropriate enclosing |
7527 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 7528 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
7529 | the type. */ |
7530 | ||
987504bb JJ |
7531 | if (cu->language == language_cplus |
7532 | || cu->language == language_java) | |
c906108c | 7533 | { |
63d06c5c DC |
7534 | struct type *type = SYMBOL_TYPE (sym); |
7535 | ||
7536 | if (TYPE_TAG_NAME (type) != NULL) | |
7537 | { | |
7538 | /* FIXME: carlton/2003-11-10: Should this use | |
7539 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
7540 | arises further down in this function.) */ |
7541 | /* The type's name is already allocated along with | |
7542 | this objfile, so we don't need to duplicate it | |
7543 | for the symbol. */ | |
7544 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 7545 | } |
c906108c | 7546 | } |
63d06c5c DC |
7547 | |
7548 | { | |
987504bb | 7549 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
7550 | really ever be static objects: otherwise, if you try |
7551 | to, say, break of a class's method and you're in a file | |
7552 | which doesn't mention that class, it won't work unless | |
7553 | the check for all static symbols in lookup_symbol_aux | |
7554 | saves you. See the OtherFileClass tests in | |
7555 | gdb.c++/namespace.exp. */ | |
7556 | ||
7557 | struct pending **list_to_add; | |
7558 | ||
e142c38c | 7559 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7560 | && (cu->language == language_cplus |
7561 | || cu->language == language_java) | |
e142c38c | 7562 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7563 | |
7564 | add_symbol_to_list (sym, list_to_add); | |
7565 | ||
7566 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb JJ |
7567 | defines a typedef for "foo". A Java class declaration also |
7568 | defines a typedef for the class. Synthesize a typedef symbol | |
7569 | so that "ptype foo" works as expected. */ | |
7570 | if (cu->language == language_cplus | |
8c6860bb JB |
7571 | || cu->language == language_java |
7572 | || cu->language == language_ada) | |
63d06c5c DC |
7573 | { |
7574 | struct symbol *typedef_sym = (struct symbol *) | |
4a146b47 | 7575 | obstack_alloc (&objfile->objfile_obstack, |
63d06c5c DC |
7576 | sizeof (struct symbol)); |
7577 | *typedef_sym = *sym; | |
7578 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; | |
d8151005 DJ |
7579 | /* The symbol's name is already allocated along with |
7580 | this objfile, so we don't need to duplicate it for | |
7581 | the type. */ | |
63d06c5c | 7582 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7583 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7584 | add_symbol_to_list (typedef_sym, list_to_add); |
7585 | } | |
7586 | } | |
c906108c SS |
7587 | break; |
7588 | case DW_TAG_typedef: | |
63d06c5c DC |
7589 | if (processing_has_namespace_info |
7590 | && processing_current_prefix[0] != '\0') | |
7591 | { | |
987504bb JJ |
7592 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7593 | processing_current_prefix, | |
7594 | name, cu); | |
63d06c5c DC |
7595 | } |
7596 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7597 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7598 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7599 | break; |
c906108c | 7600 | case DW_TAG_base_type: |
a02abb62 | 7601 | case DW_TAG_subrange_type: |
c906108c | 7602 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7603 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7604 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7605 | break; |
7606 | case DW_TAG_enumerator: | |
63d06c5c DC |
7607 | if (processing_has_namespace_info |
7608 | && processing_current_prefix[0] != '\0') | |
7609 | { | |
987504bb JJ |
7610 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7611 | processing_current_prefix, | |
7612 | name, cu); | |
63d06c5c | 7613 | } |
e142c38c | 7614 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7615 | if (attr) |
7616 | { | |
e7c27a73 | 7617 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7618 | } |
63d06c5c DC |
7619 | { |
7620 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7621 | DW_TAG_class_type, etc. block. */ | |
7622 | ||
7623 | struct pending **list_to_add; | |
7624 | ||
e142c38c | 7625 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7626 | && (cu->language == language_cplus |
7627 | || cu->language == language_java) | |
e142c38c | 7628 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7629 | |
7630 | add_symbol_to_list (sym, list_to_add); | |
7631 | } | |
c906108c | 7632 | break; |
5c4e30ca DC |
7633 | case DW_TAG_namespace: |
7634 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7635 | add_symbol_to_list (sym, &global_symbols); | |
7636 | break; | |
c906108c SS |
7637 | default: |
7638 | /* Not a tag we recognize. Hopefully we aren't processing | |
7639 | trash data, but since we must specifically ignore things | |
7640 | we don't recognize, there is nothing else we should do at | |
7641 | this point. */ | |
e2e0b3e5 | 7642 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7643 | dwarf_tag_name (die->tag)); |
c906108c SS |
7644 | break; |
7645 | } | |
7646 | } | |
7647 | return (sym); | |
7648 | } | |
7649 | ||
7650 | /* Copy constant value from an attribute to a symbol. */ | |
7651 | ||
7652 | static void | |
107d2387 | 7653 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7654 | struct dwarf2_cu *cu) |
c906108c | 7655 | { |
e7c27a73 DJ |
7656 | struct objfile *objfile = cu->objfile; |
7657 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7658 | struct dwarf_block *blk; |
7659 | ||
7660 | switch (attr->form) | |
7661 | { | |
7662 | case DW_FORM_addr: | |
107d2387 | 7663 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 7664 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7665 | cu_header->addr_size, |
7666 | TYPE_LENGTH (SYMBOL_TYPE | |
7667 | (sym))); | |
4e38b386 | 7668 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7669 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7670 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7671 | it's body - store_unsigned_integer. */ | |
7672 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7673 | DW_ADDR (attr)); | |
c906108c SS |
7674 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7675 | break; | |
93b5768b PA |
7676 | case DW_FORM_strp: |
7677 | /* DW_STRING is already allocated on the obstack, point directly | |
7678 | to it. */ | |
7679 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
7680 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7681 | break; | |
c906108c SS |
7682 | case DW_FORM_block1: |
7683 | case DW_FORM_block2: | |
7684 | case DW_FORM_block4: | |
7685 | case DW_FORM_block: | |
7686 | blk = DW_BLOCK (attr); | |
7687 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 7688 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7689 | blk->size, |
7690 | TYPE_LENGTH (SYMBOL_TYPE | |
7691 | (sym))); | |
4e38b386 | 7692 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7693 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7694 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7695 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7696 | break; | |
2df3850c JM |
7697 | |
7698 | /* The DW_AT_const_value attributes are supposed to carry the | |
7699 | symbol's value "represented as it would be on the target | |
7700 | architecture." By the time we get here, it's already been | |
7701 | converted to host endianness, so we just need to sign- or | |
7702 | zero-extend it as appropriate. */ | |
7703 | case DW_FORM_data1: | |
7704 | dwarf2_const_value_data (attr, sym, 8); | |
7705 | break; | |
c906108c | 7706 | case DW_FORM_data2: |
2df3850c JM |
7707 | dwarf2_const_value_data (attr, sym, 16); |
7708 | break; | |
c906108c | 7709 | case DW_FORM_data4: |
2df3850c JM |
7710 | dwarf2_const_value_data (attr, sym, 32); |
7711 | break; | |
c906108c | 7712 | case DW_FORM_data8: |
2df3850c JM |
7713 | dwarf2_const_value_data (attr, sym, 64); |
7714 | break; | |
7715 | ||
c906108c | 7716 | case DW_FORM_sdata: |
2df3850c JM |
7717 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7718 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7719 | break; | |
7720 | ||
c906108c SS |
7721 | case DW_FORM_udata: |
7722 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
7723 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7724 | break; | |
2df3850c | 7725 | |
c906108c | 7726 | default: |
4d3c2250 | 7727 | complaint (&symfile_complaints, |
e2e0b3e5 | 7728 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 7729 | dwarf_form_name (attr->form)); |
c906108c SS |
7730 | SYMBOL_VALUE (sym) = 0; |
7731 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7732 | break; | |
7733 | } | |
7734 | } | |
7735 | ||
2df3850c JM |
7736 | |
7737 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
7738 | or zero-extend it as appropriate for the symbol's type. */ | |
7739 | static void | |
7740 | dwarf2_const_value_data (struct attribute *attr, | |
7741 | struct symbol *sym, | |
7742 | int bits) | |
7743 | { | |
7744 | LONGEST l = DW_UNSND (attr); | |
7745 | ||
7746 | if (bits < sizeof (l) * 8) | |
7747 | { | |
7748 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
7749 | l &= ((LONGEST) 1 << bits) - 1; | |
7750 | else | |
bf9198f1 | 7751 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
7752 | } |
7753 | ||
7754 | SYMBOL_VALUE (sym) = l; | |
7755 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7756 | } | |
7757 | ||
7758 | ||
c906108c SS |
7759 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
7760 | ||
7761 | static struct type * | |
e7c27a73 | 7762 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7763 | { |
5e2b427d | 7764 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
c906108c SS |
7765 | struct type *type; |
7766 | struct attribute *type_attr; | |
7767 | struct die_info *type_die; | |
c906108c | 7768 | |
e142c38c | 7769 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
7770 | if (!type_attr) |
7771 | { | |
7772 | /* A missing DW_AT_type represents a void type. */ | |
5e2b427d | 7773 | return builtin_type (gdbarch)->builtin_void; |
c906108c SS |
7774 | } |
7775 | else | |
10b3939b DJ |
7776 | type_die = follow_die_ref (die, type_attr, cu); |
7777 | ||
e7c27a73 | 7778 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7779 | if (!type) |
7780 | { | |
7781 | dump_die (type_die); | |
8a3fe4f8 | 7782 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 7783 | cu->objfile->name); |
c906108c SS |
7784 | } |
7785 | return type; | |
7786 | } | |
7787 | ||
7788 | /* Return the containing type of the die in question using its | |
7789 | DW_AT_containing_type attribute. */ | |
7790 | ||
7791 | static struct type * | |
e7c27a73 | 7792 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7793 | { |
7794 | struct type *type = NULL; | |
7795 | struct attribute *type_attr; | |
7796 | struct die_info *type_die = NULL; | |
c906108c | 7797 | |
e142c38c | 7798 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
7799 | if (type_attr) |
7800 | { | |
10b3939b | 7801 | type_die = follow_die_ref (die, type_attr, cu); |
e7c27a73 | 7802 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7803 | } |
7804 | if (!type) | |
7805 | { | |
7806 | if (type_die) | |
7807 | dump_die (type_die); | |
8a3fe4f8 | 7808 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 7809 | cu->objfile->name); |
c906108c SS |
7810 | } |
7811 | return type; | |
7812 | } | |
7813 | ||
c906108c | 7814 | static struct type * |
e7c27a73 | 7815 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7816 | { |
f792889a DJ |
7817 | struct type *this_type; |
7818 | ||
7819 | this_type = read_type_die (die, cu); | |
7820 | if (!this_type) | |
c906108c | 7821 | { |
f792889a DJ |
7822 | dump_die (die); |
7823 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), | |
7824 | cu->objfile->name); | |
c906108c | 7825 | } |
f792889a | 7826 | return this_type; |
c906108c SS |
7827 | } |
7828 | ||
f792889a | 7829 | static struct type * |
e7c27a73 | 7830 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7831 | { |
f792889a DJ |
7832 | char *prefix; |
7833 | const char *old_prefix; | |
7834 | struct cleanup *back_to; | |
7835 | struct type *this_type; | |
7836 | ||
7837 | this_type = get_die_type (die, cu); | |
7838 | if (this_type) | |
7839 | return this_type; | |
7840 | ||
7841 | prefix = determine_prefix (die, cu); | |
7842 | old_prefix = processing_current_prefix; | |
7843 | back_to = make_cleanup (xfree, prefix); | |
63d06c5c | 7844 | processing_current_prefix = prefix; |
f792889a | 7845 | |
c906108c SS |
7846 | switch (die->tag) |
7847 | { | |
7848 | case DW_TAG_class_type: | |
680b30c7 | 7849 | case DW_TAG_interface_type: |
c906108c SS |
7850 | case DW_TAG_structure_type: |
7851 | case DW_TAG_union_type: | |
f792889a | 7852 | this_type = read_structure_type (die, cu); |
c906108c SS |
7853 | break; |
7854 | case DW_TAG_enumeration_type: | |
f792889a | 7855 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
7856 | break; |
7857 | case DW_TAG_subprogram: | |
7858 | case DW_TAG_subroutine_type: | |
f792889a | 7859 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
7860 | break; |
7861 | case DW_TAG_array_type: | |
f792889a | 7862 | this_type = read_array_type (die, cu); |
c906108c | 7863 | break; |
72019c9c | 7864 | case DW_TAG_set_type: |
f792889a | 7865 | this_type = read_set_type (die, cu); |
72019c9c | 7866 | break; |
c906108c | 7867 | case DW_TAG_pointer_type: |
f792889a | 7868 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
7869 | break; |
7870 | case DW_TAG_ptr_to_member_type: | |
f792889a | 7871 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
7872 | break; |
7873 | case DW_TAG_reference_type: | |
f792889a | 7874 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
7875 | break; |
7876 | case DW_TAG_const_type: | |
f792889a | 7877 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
7878 | break; |
7879 | case DW_TAG_volatile_type: | |
f792889a | 7880 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
7881 | break; |
7882 | case DW_TAG_string_type: | |
f792889a | 7883 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
7884 | break; |
7885 | case DW_TAG_typedef: | |
f792889a | 7886 | this_type = read_typedef (die, cu); |
c906108c | 7887 | break; |
a02abb62 | 7888 | case DW_TAG_subrange_type: |
f792889a | 7889 | this_type = read_subrange_type (die, cu); |
a02abb62 | 7890 | break; |
c906108c | 7891 | case DW_TAG_base_type: |
f792889a | 7892 | this_type = read_base_type (die, cu); |
c906108c | 7893 | break; |
81a17f79 | 7894 | case DW_TAG_unspecified_type: |
f792889a | 7895 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 7896 | break; |
c906108c | 7897 | default: |
a1f5b845 | 7898 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 7899 | dwarf_tag_name (die->tag)); |
c906108c SS |
7900 | break; |
7901 | } | |
63d06c5c DC |
7902 | |
7903 | processing_current_prefix = old_prefix; | |
7904 | do_cleanups (back_to); | |
f792889a | 7905 | return this_type; |
63d06c5c DC |
7906 | } |
7907 | ||
fdde2d81 DC |
7908 | /* Return the name of the namespace/class that DIE is defined within, |
7909 | or "" if we can't tell. The caller should xfree the result. */ | |
7910 | ||
7911 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
7912 | therein) for an example of how to use this function to deal with | |
7913 | DW_AT_specification. */ | |
7914 | ||
7915 | static char * | |
e142c38c | 7916 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
7917 | { |
7918 | struct die_info *parent; | |
7919 | ||
987504bb JJ |
7920 | if (cu->language != language_cplus |
7921 | && cu->language != language_java) | |
63d06c5c DC |
7922 | return NULL; |
7923 | ||
7924 | parent = die->parent; | |
7925 | ||
7926 | if (parent == NULL) | |
7927 | { | |
8176b9b8 | 7928 | return xstrdup (""); |
63d06c5c DC |
7929 | } |
7930 | else | |
7931 | { | |
63d06c5c DC |
7932 | switch (parent->tag) { |
7933 | case DW_TAG_namespace: | |
7934 | { | |
8176b9b8 DC |
7935 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
7936 | before doing this check? */ | |
f792889a DJ |
7937 | struct type *parent_type = get_die_type (parent, cu); |
7938 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
8176b9b8 | 7939 | { |
f792889a | 7940 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
8176b9b8 DC |
7941 | } |
7942 | else | |
7943 | { | |
7944 | int dummy; | |
7945 | char *parent_prefix = determine_prefix (parent, cu); | |
987504bb | 7946 | char *retval = typename_concat (NULL, parent_prefix, |
8176b9b8 | 7947 | namespace_name (parent, &dummy, |
987504bb JJ |
7948 | cu), |
7949 | cu); | |
8176b9b8 DC |
7950 | xfree (parent_prefix); |
7951 | return retval; | |
7952 | } | |
63d06c5c DC |
7953 | } |
7954 | break; | |
7955 | case DW_TAG_class_type: | |
680b30c7 | 7956 | case DW_TAG_interface_type: |
63d06c5c DC |
7957 | case DW_TAG_structure_type: |
7958 | { | |
f792889a DJ |
7959 | struct type *parent_type = get_die_type (parent, cu); |
7960 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
63d06c5c | 7961 | { |
f792889a | 7962 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
63d06c5c DC |
7963 | } |
7964 | else | |
8176b9b8 DC |
7965 | { |
7966 | const char *old_prefix = processing_current_prefix; | |
7967 | char *new_prefix = determine_prefix (parent, cu); | |
7968 | char *retval; | |
7969 | ||
7970 | processing_current_prefix = new_prefix; | |
7971 | retval = determine_class_name (parent, cu); | |
7972 | processing_current_prefix = old_prefix; | |
7973 | ||
7974 | xfree (new_prefix); | |
7975 | return retval; | |
7976 | } | |
63d06c5c | 7977 | } |
63d06c5c | 7978 | default: |
8176b9b8 | 7979 | return determine_prefix (parent, cu); |
63d06c5c | 7980 | } |
63d06c5c DC |
7981 | } |
7982 | } | |
7983 | ||
987504bb JJ |
7984 | /* Return a newly-allocated string formed by concatenating PREFIX and |
7985 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
7986 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
7987 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
7988 | is used to determine the language and hence, the appropriate separator. */ | |
7989 | ||
7990 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
7991 | |
7992 | static char * | |
987504bb JJ |
7993 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
7994 | struct dwarf2_cu *cu) | |
63d06c5c | 7995 | { |
987504bb | 7996 | char *sep; |
63d06c5c | 7997 | |
987504bb JJ |
7998 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
7999 | sep = ""; | |
8000 | else if (cu->language == language_java) | |
8001 | sep = "."; | |
8002 | else | |
8003 | sep = "::"; | |
63d06c5c | 8004 | |
987504bb JJ |
8005 | if (obs == NULL) |
8006 | { | |
8007 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
8008 | retval[0] = '\0'; | |
8009 | ||
8010 | if (prefix) | |
8011 | { | |
8012 | strcpy (retval, prefix); | |
8013 | strcat (retval, sep); | |
8014 | } | |
8015 | if (suffix) | |
8016 | strcat (retval, suffix); | |
8017 | ||
63d06c5c DC |
8018 | return retval; |
8019 | } | |
987504bb JJ |
8020 | else |
8021 | { | |
8022 | /* We have an obstack. */ | |
8023 | return obconcat (obs, prefix, sep, suffix); | |
8024 | } | |
63d06c5c DC |
8025 | } |
8026 | ||
c906108c SS |
8027 | #if 0 |
8028 | struct die_info * | |
fba45db2 | 8029 | copy_die (struct die_info *old_die) |
c906108c SS |
8030 | { |
8031 | struct die_info *new_die; | |
8032 | int i, num_attrs; | |
8033 | ||
8034 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
8035 | memset (new_die, 0, sizeof (struct die_info)); | |
8036 | ||
8037 | new_die->tag = old_die->tag; | |
8038 | new_die->has_children = old_die->has_children; | |
8039 | new_die->abbrev = old_die->abbrev; | |
8040 | new_die->offset = old_die->offset; | |
c906108c SS |
8041 | |
8042 | num_attrs = old_die->num_attrs; | |
8043 | new_die->num_attrs = num_attrs; | |
8044 | new_die->attrs = (struct attribute *) | |
8045 | xmalloc (num_attrs * sizeof (struct attribute)); | |
8046 | ||
8047 | for (i = 0; i < old_die->num_attrs; ++i) | |
8048 | { | |
8049 | new_die->attrs[i].name = old_die->attrs[i].name; | |
8050 | new_die->attrs[i].form = old_die->attrs[i].form; | |
8051 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
8052 | } | |
8053 | ||
8054 | new_die->next = NULL; | |
8055 | return new_die; | |
8056 | } | |
8057 | #endif | |
8058 | ||
8059 | /* Return sibling of die, NULL if no sibling. */ | |
8060 | ||
f9aca02d | 8061 | static struct die_info * |
fba45db2 | 8062 | sibling_die (struct die_info *die) |
c906108c | 8063 | { |
639d11d3 | 8064 | return die->sibling; |
c906108c SS |
8065 | } |
8066 | ||
8067 | /* Get linkage name of a die, return NULL if not found. */ | |
8068 | ||
8069 | static char * | |
e142c38c | 8070 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8071 | { |
8072 | struct attribute *attr; | |
8073 | ||
e142c38c | 8074 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
8075 | if (attr && DW_STRING (attr)) |
8076 | return DW_STRING (attr); | |
e142c38c | 8077 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
8078 | if (attr && DW_STRING (attr)) |
8079 | return DW_STRING (attr); | |
8080 | return NULL; | |
8081 | } | |
8082 | ||
9219021c DC |
8083 | /* Get name of a die, return NULL if not found. */ |
8084 | ||
8085 | static char * | |
e142c38c | 8086 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8087 | { |
8088 | struct attribute *attr; | |
8089 | ||
e142c38c | 8090 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
8091 | if (attr && DW_STRING (attr)) |
8092 | return DW_STRING (attr); | |
8093 | return NULL; | |
8094 | } | |
8095 | ||
8096 | /* Return the die that this die in an extension of, or NULL if there | |
8097 | is none. */ | |
8098 | ||
8099 | static struct die_info * | |
e142c38c | 8100 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8101 | { |
8102 | struct attribute *attr; | |
9219021c | 8103 | |
e142c38c | 8104 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
8105 | if (attr == NULL) |
8106 | return NULL; | |
8107 | ||
10b3939b | 8108 | return follow_die_ref (die, attr, cu); |
9219021c DC |
8109 | } |
8110 | ||
c906108c SS |
8111 | /* Convert a DIE tag into its string name. */ |
8112 | ||
8113 | static char * | |
aa1ee363 | 8114 | dwarf_tag_name (unsigned tag) |
c906108c SS |
8115 | { |
8116 | switch (tag) | |
8117 | { | |
8118 | case DW_TAG_padding: | |
8119 | return "DW_TAG_padding"; | |
8120 | case DW_TAG_array_type: | |
8121 | return "DW_TAG_array_type"; | |
8122 | case DW_TAG_class_type: | |
8123 | return "DW_TAG_class_type"; | |
8124 | case DW_TAG_entry_point: | |
8125 | return "DW_TAG_entry_point"; | |
8126 | case DW_TAG_enumeration_type: | |
8127 | return "DW_TAG_enumeration_type"; | |
8128 | case DW_TAG_formal_parameter: | |
8129 | return "DW_TAG_formal_parameter"; | |
8130 | case DW_TAG_imported_declaration: | |
8131 | return "DW_TAG_imported_declaration"; | |
8132 | case DW_TAG_label: | |
8133 | return "DW_TAG_label"; | |
8134 | case DW_TAG_lexical_block: | |
8135 | return "DW_TAG_lexical_block"; | |
8136 | case DW_TAG_member: | |
8137 | return "DW_TAG_member"; | |
8138 | case DW_TAG_pointer_type: | |
8139 | return "DW_TAG_pointer_type"; | |
8140 | case DW_TAG_reference_type: | |
8141 | return "DW_TAG_reference_type"; | |
8142 | case DW_TAG_compile_unit: | |
8143 | return "DW_TAG_compile_unit"; | |
8144 | case DW_TAG_string_type: | |
8145 | return "DW_TAG_string_type"; | |
8146 | case DW_TAG_structure_type: | |
8147 | return "DW_TAG_structure_type"; | |
8148 | case DW_TAG_subroutine_type: | |
8149 | return "DW_TAG_subroutine_type"; | |
8150 | case DW_TAG_typedef: | |
8151 | return "DW_TAG_typedef"; | |
8152 | case DW_TAG_union_type: | |
8153 | return "DW_TAG_union_type"; | |
8154 | case DW_TAG_unspecified_parameters: | |
8155 | return "DW_TAG_unspecified_parameters"; | |
8156 | case DW_TAG_variant: | |
8157 | return "DW_TAG_variant"; | |
8158 | case DW_TAG_common_block: | |
8159 | return "DW_TAG_common_block"; | |
8160 | case DW_TAG_common_inclusion: | |
8161 | return "DW_TAG_common_inclusion"; | |
8162 | case DW_TAG_inheritance: | |
8163 | return "DW_TAG_inheritance"; | |
8164 | case DW_TAG_inlined_subroutine: | |
8165 | return "DW_TAG_inlined_subroutine"; | |
8166 | case DW_TAG_module: | |
8167 | return "DW_TAG_module"; | |
8168 | case DW_TAG_ptr_to_member_type: | |
8169 | return "DW_TAG_ptr_to_member_type"; | |
8170 | case DW_TAG_set_type: | |
8171 | return "DW_TAG_set_type"; | |
8172 | case DW_TAG_subrange_type: | |
8173 | return "DW_TAG_subrange_type"; | |
8174 | case DW_TAG_with_stmt: | |
8175 | return "DW_TAG_with_stmt"; | |
8176 | case DW_TAG_access_declaration: | |
8177 | return "DW_TAG_access_declaration"; | |
8178 | case DW_TAG_base_type: | |
8179 | return "DW_TAG_base_type"; | |
8180 | case DW_TAG_catch_block: | |
8181 | return "DW_TAG_catch_block"; | |
8182 | case DW_TAG_const_type: | |
8183 | return "DW_TAG_const_type"; | |
8184 | case DW_TAG_constant: | |
8185 | return "DW_TAG_constant"; | |
8186 | case DW_TAG_enumerator: | |
8187 | return "DW_TAG_enumerator"; | |
8188 | case DW_TAG_file_type: | |
8189 | return "DW_TAG_file_type"; | |
8190 | case DW_TAG_friend: | |
8191 | return "DW_TAG_friend"; | |
8192 | case DW_TAG_namelist: | |
8193 | return "DW_TAG_namelist"; | |
8194 | case DW_TAG_namelist_item: | |
8195 | return "DW_TAG_namelist_item"; | |
8196 | case DW_TAG_packed_type: | |
8197 | return "DW_TAG_packed_type"; | |
8198 | case DW_TAG_subprogram: | |
8199 | return "DW_TAG_subprogram"; | |
8200 | case DW_TAG_template_type_param: | |
8201 | return "DW_TAG_template_type_param"; | |
8202 | case DW_TAG_template_value_param: | |
8203 | return "DW_TAG_template_value_param"; | |
8204 | case DW_TAG_thrown_type: | |
8205 | return "DW_TAG_thrown_type"; | |
8206 | case DW_TAG_try_block: | |
8207 | return "DW_TAG_try_block"; | |
8208 | case DW_TAG_variant_part: | |
8209 | return "DW_TAG_variant_part"; | |
8210 | case DW_TAG_variable: | |
8211 | return "DW_TAG_variable"; | |
8212 | case DW_TAG_volatile_type: | |
8213 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
8214 | case DW_TAG_dwarf_procedure: |
8215 | return "DW_TAG_dwarf_procedure"; | |
8216 | case DW_TAG_restrict_type: | |
8217 | return "DW_TAG_restrict_type"; | |
8218 | case DW_TAG_interface_type: | |
8219 | return "DW_TAG_interface_type"; | |
8220 | case DW_TAG_namespace: | |
8221 | return "DW_TAG_namespace"; | |
8222 | case DW_TAG_imported_module: | |
8223 | return "DW_TAG_imported_module"; | |
8224 | case DW_TAG_unspecified_type: | |
8225 | return "DW_TAG_unspecified_type"; | |
8226 | case DW_TAG_partial_unit: | |
8227 | return "DW_TAG_partial_unit"; | |
8228 | case DW_TAG_imported_unit: | |
8229 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
8230 | case DW_TAG_condition: |
8231 | return "DW_TAG_condition"; | |
8232 | case DW_TAG_shared_type: | |
8233 | return "DW_TAG_shared_type"; | |
c906108c SS |
8234 | case DW_TAG_MIPS_loop: |
8235 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
8236 | case DW_TAG_HP_array_descriptor: |
8237 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
8238 | case DW_TAG_format_label: |
8239 | return "DW_TAG_format_label"; | |
8240 | case DW_TAG_function_template: | |
8241 | return "DW_TAG_function_template"; | |
8242 | case DW_TAG_class_template: | |
8243 | return "DW_TAG_class_template"; | |
b7619582 GF |
8244 | case DW_TAG_GNU_BINCL: |
8245 | return "DW_TAG_GNU_BINCL"; | |
8246 | case DW_TAG_GNU_EINCL: | |
8247 | return "DW_TAG_GNU_EINCL"; | |
8248 | case DW_TAG_upc_shared_type: | |
8249 | return "DW_TAG_upc_shared_type"; | |
8250 | case DW_TAG_upc_strict_type: | |
8251 | return "DW_TAG_upc_strict_type"; | |
8252 | case DW_TAG_upc_relaxed_type: | |
8253 | return "DW_TAG_upc_relaxed_type"; | |
8254 | case DW_TAG_PGI_kanji_type: | |
8255 | return "DW_TAG_PGI_kanji_type"; | |
8256 | case DW_TAG_PGI_interface_block: | |
8257 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
8258 | default: |
8259 | return "DW_TAG_<unknown>"; | |
8260 | } | |
8261 | } | |
8262 | ||
8263 | /* Convert a DWARF attribute code into its string name. */ | |
8264 | ||
8265 | static char * | |
aa1ee363 | 8266 | dwarf_attr_name (unsigned attr) |
c906108c SS |
8267 | { |
8268 | switch (attr) | |
8269 | { | |
8270 | case DW_AT_sibling: | |
8271 | return "DW_AT_sibling"; | |
8272 | case DW_AT_location: | |
8273 | return "DW_AT_location"; | |
8274 | case DW_AT_name: | |
8275 | return "DW_AT_name"; | |
8276 | case DW_AT_ordering: | |
8277 | return "DW_AT_ordering"; | |
8278 | case DW_AT_subscr_data: | |
8279 | return "DW_AT_subscr_data"; | |
8280 | case DW_AT_byte_size: | |
8281 | return "DW_AT_byte_size"; | |
8282 | case DW_AT_bit_offset: | |
8283 | return "DW_AT_bit_offset"; | |
8284 | case DW_AT_bit_size: | |
8285 | return "DW_AT_bit_size"; | |
8286 | case DW_AT_element_list: | |
8287 | return "DW_AT_element_list"; | |
8288 | case DW_AT_stmt_list: | |
8289 | return "DW_AT_stmt_list"; | |
8290 | case DW_AT_low_pc: | |
8291 | return "DW_AT_low_pc"; | |
8292 | case DW_AT_high_pc: | |
8293 | return "DW_AT_high_pc"; | |
8294 | case DW_AT_language: | |
8295 | return "DW_AT_language"; | |
8296 | case DW_AT_member: | |
8297 | return "DW_AT_member"; | |
8298 | case DW_AT_discr: | |
8299 | return "DW_AT_discr"; | |
8300 | case DW_AT_discr_value: | |
8301 | return "DW_AT_discr_value"; | |
8302 | case DW_AT_visibility: | |
8303 | return "DW_AT_visibility"; | |
8304 | case DW_AT_import: | |
8305 | return "DW_AT_import"; | |
8306 | case DW_AT_string_length: | |
8307 | return "DW_AT_string_length"; | |
8308 | case DW_AT_common_reference: | |
8309 | return "DW_AT_common_reference"; | |
8310 | case DW_AT_comp_dir: | |
8311 | return "DW_AT_comp_dir"; | |
8312 | case DW_AT_const_value: | |
8313 | return "DW_AT_const_value"; | |
8314 | case DW_AT_containing_type: | |
8315 | return "DW_AT_containing_type"; | |
8316 | case DW_AT_default_value: | |
8317 | return "DW_AT_default_value"; | |
8318 | case DW_AT_inline: | |
8319 | return "DW_AT_inline"; | |
8320 | case DW_AT_is_optional: | |
8321 | return "DW_AT_is_optional"; | |
8322 | case DW_AT_lower_bound: | |
8323 | return "DW_AT_lower_bound"; | |
8324 | case DW_AT_producer: | |
8325 | return "DW_AT_producer"; | |
8326 | case DW_AT_prototyped: | |
8327 | return "DW_AT_prototyped"; | |
8328 | case DW_AT_return_addr: | |
8329 | return "DW_AT_return_addr"; | |
8330 | case DW_AT_start_scope: | |
8331 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
8332 | case DW_AT_bit_stride: |
8333 | return "DW_AT_bit_stride"; | |
c906108c SS |
8334 | case DW_AT_upper_bound: |
8335 | return "DW_AT_upper_bound"; | |
8336 | case DW_AT_abstract_origin: | |
8337 | return "DW_AT_abstract_origin"; | |
8338 | case DW_AT_accessibility: | |
8339 | return "DW_AT_accessibility"; | |
8340 | case DW_AT_address_class: | |
8341 | return "DW_AT_address_class"; | |
8342 | case DW_AT_artificial: | |
8343 | return "DW_AT_artificial"; | |
8344 | case DW_AT_base_types: | |
8345 | return "DW_AT_base_types"; | |
8346 | case DW_AT_calling_convention: | |
8347 | return "DW_AT_calling_convention"; | |
8348 | case DW_AT_count: | |
8349 | return "DW_AT_count"; | |
8350 | case DW_AT_data_member_location: | |
8351 | return "DW_AT_data_member_location"; | |
8352 | case DW_AT_decl_column: | |
8353 | return "DW_AT_decl_column"; | |
8354 | case DW_AT_decl_file: | |
8355 | return "DW_AT_decl_file"; | |
8356 | case DW_AT_decl_line: | |
8357 | return "DW_AT_decl_line"; | |
8358 | case DW_AT_declaration: | |
8359 | return "DW_AT_declaration"; | |
8360 | case DW_AT_discr_list: | |
8361 | return "DW_AT_discr_list"; | |
8362 | case DW_AT_encoding: | |
8363 | return "DW_AT_encoding"; | |
8364 | case DW_AT_external: | |
8365 | return "DW_AT_external"; | |
8366 | case DW_AT_frame_base: | |
8367 | return "DW_AT_frame_base"; | |
8368 | case DW_AT_friend: | |
8369 | return "DW_AT_friend"; | |
8370 | case DW_AT_identifier_case: | |
8371 | return "DW_AT_identifier_case"; | |
8372 | case DW_AT_macro_info: | |
8373 | return "DW_AT_macro_info"; | |
8374 | case DW_AT_namelist_items: | |
8375 | return "DW_AT_namelist_items"; | |
8376 | case DW_AT_priority: | |
8377 | return "DW_AT_priority"; | |
8378 | case DW_AT_segment: | |
8379 | return "DW_AT_segment"; | |
8380 | case DW_AT_specification: | |
8381 | return "DW_AT_specification"; | |
8382 | case DW_AT_static_link: | |
8383 | return "DW_AT_static_link"; | |
8384 | case DW_AT_type: | |
8385 | return "DW_AT_type"; | |
8386 | case DW_AT_use_location: | |
8387 | return "DW_AT_use_location"; | |
8388 | case DW_AT_variable_parameter: | |
8389 | return "DW_AT_variable_parameter"; | |
8390 | case DW_AT_virtuality: | |
8391 | return "DW_AT_virtuality"; | |
8392 | case DW_AT_vtable_elem_location: | |
8393 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8394 | /* DWARF 3 values. */ |
d9fa45fe DC |
8395 | case DW_AT_allocated: |
8396 | return "DW_AT_allocated"; | |
8397 | case DW_AT_associated: | |
8398 | return "DW_AT_associated"; | |
8399 | case DW_AT_data_location: | |
8400 | return "DW_AT_data_location"; | |
09fa0d7c JK |
8401 | case DW_AT_byte_stride: |
8402 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
8403 | case DW_AT_entry_pc: |
8404 | return "DW_AT_entry_pc"; | |
8405 | case DW_AT_use_UTF8: | |
8406 | return "DW_AT_use_UTF8"; | |
8407 | case DW_AT_extension: | |
8408 | return "DW_AT_extension"; | |
8409 | case DW_AT_ranges: | |
8410 | return "DW_AT_ranges"; | |
8411 | case DW_AT_trampoline: | |
8412 | return "DW_AT_trampoline"; | |
8413 | case DW_AT_call_column: | |
8414 | return "DW_AT_call_column"; | |
8415 | case DW_AT_call_file: | |
8416 | return "DW_AT_call_file"; | |
8417 | case DW_AT_call_line: | |
8418 | return "DW_AT_call_line"; | |
b7619582 GF |
8419 | case DW_AT_description: |
8420 | return "DW_AT_description"; | |
8421 | case DW_AT_binary_scale: | |
8422 | return "DW_AT_binary_scale"; | |
8423 | case DW_AT_decimal_scale: | |
8424 | return "DW_AT_decimal_scale"; | |
8425 | case DW_AT_small: | |
8426 | return "DW_AT_small"; | |
8427 | case DW_AT_decimal_sign: | |
8428 | return "DW_AT_decimal_sign"; | |
8429 | case DW_AT_digit_count: | |
8430 | return "DW_AT_digit_count"; | |
8431 | case DW_AT_picture_string: | |
8432 | return "DW_AT_picture_string"; | |
8433 | case DW_AT_mutable: | |
8434 | return "DW_AT_mutable"; | |
8435 | case DW_AT_threads_scaled: | |
8436 | return "DW_AT_threads_scaled"; | |
8437 | case DW_AT_explicit: | |
8438 | return "DW_AT_explicit"; | |
8439 | case DW_AT_object_pointer: | |
8440 | return "DW_AT_object_pointer"; | |
8441 | case DW_AT_endianity: | |
8442 | return "DW_AT_endianity"; | |
8443 | case DW_AT_elemental: | |
8444 | return "DW_AT_elemental"; | |
8445 | case DW_AT_pure: | |
8446 | return "DW_AT_pure"; | |
8447 | case DW_AT_recursive: | |
8448 | return "DW_AT_recursive"; | |
c906108c | 8449 | #ifdef MIPS |
b7619582 | 8450 | /* SGI/MIPS extensions. */ |
c906108c SS |
8451 | case DW_AT_MIPS_fde: |
8452 | return "DW_AT_MIPS_fde"; | |
8453 | case DW_AT_MIPS_loop_begin: | |
8454 | return "DW_AT_MIPS_loop_begin"; | |
8455 | case DW_AT_MIPS_tail_loop_begin: | |
8456 | return "DW_AT_MIPS_tail_loop_begin"; | |
8457 | case DW_AT_MIPS_epilog_begin: | |
8458 | return "DW_AT_MIPS_epilog_begin"; | |
8459 | case DW_AT_MIPS_loop_unroll_factor: | |
8460 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8461 | case DW_AT_MIPS_software_pipeline_depth: | |
8462 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8463 | case DW_AT_MIPS_linkage_name: | |
8464 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8465 | case DW_AT_MIPS_stride: |
8466 | return "DW_AT_MIPS_stride"; | |
8467 | case DW_AT_MIPS_abstract_name: | |
8468 | return "DW_AT_MIPS_abstract_name"; | |
8469 | case DW_AT_MIPS_clone_origin: | |
8470 | return "DW_AT_MIPS_clone_origin"; | |
8471 | case DW_AT_MIPS_has_inlines: | |
8472 | return "DW_AT_MIPS_has_inlines"; | |
8473 | #endif | |
8474 | /* HP extensions. */ | |
8475 | case DW_AT_HP_block_index: | |
8476 | return "DW_AT_HP_block_index"; | |
8477 | case DW_AT_HP_unmodifiable: | |
8478 | return "DW_AT_HP_unmodifiable"; | |
8479 | case DW_AT_HP_actuals_stmt_list: | |
8480 | return "DW_AT_HP_actuals_stmt_list"; | |
8481 | case DW_AT_HP_proc_per_section: | |
8482 | return "DW_AT_HP_proc_per_section"; | |
8483 | case DW_AT_HP_raw_data_ptr: | |
8484 | return "DW_AT_HP_raw_data_ptr"; | |
8485 | case DW_AT_HP_pass_by_reference: | |
8486 | return "DW_AT_HP_pass_by_reference"; | |
8487 | case DW_AT_HP_opt_level: | |
8488 | return "DW_AT_HP_opt_level"; | |
8489 | case DW_AT_HP_prof_version_id: | |
8490 | return "DW_AT_HP_prof_version_id"; | |
8491 | case DW_AT_HP_opt_flags: | |
8492 | return "DW_AT_HP_opt_flags"; | |
8493 | case DW_AT_HP_cold_region_low_pc: | |
8494 | return "DW_AT_HP_cold_region_low_pc"; | |
8495 | case DW_AT_HP_cold_region_high_pc: | |
8496 | return "DW_AT_HP_cold_region_high_pc"; | |
8497 | case DW_AT_HP_all_variables_modifiable: | |
8498 | return "DW_AT_HP_all_variables_modifiable"; | |
8499 | case DW_AT_HP_linkage_name: | |
8500 | return "DW_AT_HP_linkage_name"; | |
8501 | case DW_AT_HP_prof_flags: | |
8502 | return "DW_AT_HP_prof_flags"; | |
8503 | /* GNU extensions. */ | |
c906108c SS |
8504 | case DW_AT_sf_names: |
8505 | return "DW_AT_sf_names"; | |
8506 | case DW_AT_src_info: | |
8507 | return "DW_AT_src_info"; | |
8508 | case DW_AT_mac_info: | |
8509 | return "DW_AT_mac_info"; | |
8510 | case DW_AT_src_coords: | |
8511 | return "DW_AT_src_coords"; | |
8512 | case DW_AT_body_begin: | |
8513 | return "DW_AT_body_begin"; | |
8514 | case DW_AT_body_end: | |
8515 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8516 | case DW_AT_GNU_vector: |
8517 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8518 | /* VMS extensions. */ |
8519 | case DW_AT_VMS_rtnbeg_pd_address: | |
8520 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8521 | /* UPC extension. */ | |
8522 | case DW_AT_upc_threads_scaled: | |
8523 | return "DW_AT_upc_threads_scaled"; | |
8524 | /* PGI (STMicroelectronics) extensions. */ | |
8525 | case DW_AT_PGI_lbase: | |
8526 | return "DW_AT_PGI_lbase"; | |
8527 | case DW_AT_PGI_soffset: | |
8528 | return "DW_AT_PGI_soffset"; | |
8529 | case DW_AT_PGI_lstride: | |
8530 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8531 | default: |
8532 | return "DW_AT_<unknown>"; | |
8533 | } | |
8534 | } | |
8535 | ||
8536 | /* Convert a DWARF value form code into its string name. */ | |
8537 | ||
8538 | static char * | |
aa1ee363 | 8539 | dwarf_form_name (unsigned form) |
c906108c SS |
8540 | { |
8541 | switch (form) | |
8542 | { | |
8543 | case DW_FORM_addr: | |
8544 | return "DW_FORM_addr"; | |
8545 | case DW_FORM_block2: | |
8546 | return "DW_FORM_block2"; | |
8547 | case DW_FORM_block4: | |
8548 | return "DW_FORM_block4"; | |
8549 | case DW_FORM_data2: | |
8550 | return "DW_FORM_data2"; | |
8551 | case DW_FORM_data4: | |
8552 | return "DW_FORM_data4"; | |
8553 | case DW_FORM_data8: | |
8554 | return "DW_FORM_data8"; | |
8555 | case DW_FORM_string: | |
8556 | return "DW_FORM_string"; | |
8557 | case DW_FORM_block: | |
8558 | return "DW_FORM_block"; | |
8559 | case DW_FORM_block1: | |
8560 | return "DW_FORM_block1"; | |
8561 | case DW_FORM_data1: | |
8562 | return "DW_FORM_data1"; | |
8563 | case DW_FORM_flag: | |
8564 | return "DW_FORM_flag"; | |
8565 | case DW_FORM_sdata: | |
8566 | return "DW_FORM_sdata"; | |
8567 | case DW_FORM_strp: | |
8568 | return "DW_FORM_strp"; | |
8569 | case DW_FORM_udata: | |
8570 | return "DW_FORM_udata"; | |
8571 | case DW_FORM_ref_addr: | |
8572 | return "DW_FORM_ref_addr"; | |
8573 | case DW_FORM_ref1: | |
8574 | return "DW_FORM_ref1"; | |
8575 | case DW_FORM_ref2: | |
8576 | return "DW_FORM_ref2"; | |
8577 | case DW_FORM_ref4: | |
8578 | return "DW_FORM_ref4"; | |
8579 | case DW_FORM_ref8: | |
8580 | return "DW_FORM_ref8"; | |
8581 | case DW_FORM_ref_udata: | |
8582 | return "DW_FORM_ref_udata"; | |
8583 | case DW_FORM_indirect: | |
8584 | return "DW_FORM_indirect"; | |
8585 | default: | |
8586 | return "DW_FORM_<unknown>"; | |
8587 | } | |
8588 | } | |
8589 | ||
8590 | /* Convert a DWARF stack opcode into its string name. */ | |
8591 | ||
8592 | static char * | |
aa1ee363 | 8593 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8594 | { |
8595 | switch (op) | |
8596 | { | |
8597 | case DW_OP_addr: | |
8598 | return "DW_OP_addr"; | |
8599 | case DW_OP_deref: | |
8600 | return "DW_OP_deref"; | |
8601 | case DW_OP_const1u: | |
8602 | return "DW_OP_const1u"; | |
8603 | case DW_OP_const1s: | |
8604 | return "DW_OP_const1s"; | |
8605 | case DW_OP_const2u: | |
8606 | return "DW_OP_const2u"; | |
8607 | case DW_OP_const2s: | |
8608 | return "DW_OP_const2s"; | |
8609 | case DW_OP_const4u: | |
8610 | return "DW_OP_const4u"; | |
8611 | case DW_OP_const4s: | |
8612 | return "DW_OP_const4s"; | |
8613 | case DW_OP_const8u: | |
8614 | return "DW_OP_const8u"; | |
8615 | case DW_OP_const8s: | |
8616 | return "DW_OP_const8s"; | |
8617 | case DW_OP_constu: | |
8618 | return "DW_OP_constu"; | |
8619 | case DW_OP_consts: | |
8620 | return "DW_OP_consts"; | |
8621 | case DW_OP_dup: | |
8622 | return "DW_OP_dup"; | |
8623 | case DW_OP_drop: | |
8624 | return "DW_OP_drop"; | |
8625 | case DW_OP_over: | |
8626 | return "DW_OP_over"; | |
8627 | case DW_OP_pick: | |
8628 | return "DW_OP_pick"; | |
8629 | case DW_OP_swap: | |
8630 | return "DW_OP_swap"; | |
8631 | case DW_OP_rot: | |
8632 | return "DW_OP_rot"; | |
8633 | case DW_OP_xderef: | |
8634 | return "DW_OP_xderef"; | |
8635 | case DW_OP_abs: | |
8636 | return "DW_OP_abs"; | |
8637 | case DW_OP_and: | |
8638 | return "DW_OP_and"; | |
8639 | case DW_OP_div: | |
8640 | return "DW_OP_div"; | |
8641 | case DW_OP_minus: | |
8642 | return "DW_OP_minus"; | |
8643 | case DW_OP_mod: | |
8644 | return "DW_OP_mod"; | |
8645 | case DW_OP_mul: | |
8646 | return "DW_OP_mul"; | |
8647 | case DW_OP_neg: | |
8648 | return "DW_OP_neg"; | |
8649 | case DW_OP_not: | |
8650 | return "DW_OP_not"; | |
8651 | case DW_OP_or: | |
8652 | return "DW_OP_or"; | |
8653 | case DW_OP_plus: | |
8654 | return "DW_OP_plus"; | |
8655 | case DW_OP_plus_uconst: | |
8656 | return "DW_OP_plus_uconst"; | |
8657 | case DW_OP_shl: | |
8658 | return "DW_OP_shl"; | |
8659 | case DW_OP_shr: | |
8660 | return "DW_OP_shr"; | |
8661 | case DW_OP_shra: | |
8662 | return "DW_OP_shra"; | |
8663 | case DW_OP_xor: | |
8664 | return "DW_OP_xor"; | |
8665 | case DW_OP_bra: | |
8666 | return "DW_OP_bra"; | |
8667 | case DW_OP_eq: | |
8668 | return "DW_OP_eq"; | |
8669 | case DW_OP_ge: | |
8670 | return "DW_OP_ge"; | |
8671 | case DW_OP_gt: | |
8672 | return "DW_OP_gt"; | |
8673 | case DW_OP_le: | |
8674 | return "DW_OP_le"; | |
8675 | case DW_OP_lt: | |
8676 | return "DW_OP_lt"; | |
8677 | case DW_OP_ne: | |
8678 | return "DW_OP_ne"; | |
8679 | case DW_OP_skip: | |
8680 | return "DW_OP_skip"; | |
8681 | case DW_OP_lit0: | |
8682 | return "DW_OP_lit0"; | |
8683 | case DW_OP_lit1: | |
8684 | return "DW_OP_lit1"; | |
8685 | case DW_OP_lit2: | |
8686 | return "DW_OP_lit2"; | |
8687 | case DW_OP_lit3: | |
8688 | return "DW_OP_lit3"; | |
8689 | case DW_OP_lit4: | |
8690 | return "DW_OP_lit4"; | |
8691 | case DW_OP_lit5: | |
8692 | return "DW_OP_lit5"; | |
8693 | case DW_OP_lit6: | |
8694 | return "DW_OP_lit6"; | |
8695 | case DW_OP_lit7: | |
8696 | return "DW_OP_lit7"; | |
8697 | case DW_OP_lit8: | |
8698 | return "DW_OP_lit8"; | |
8699 | case DW_OP_lit9: | |
8700 | return "DW_OP_lit9"; | |
8701 | case DW_OP_lit10: | |
8702 | return "DW_OP_lit10"; | |
8703 | case DW_OP_lit11: | |
8704 | return "DW_OP_lit11"; | |
8705 | case DW_OP_lit12: | |
8706 | return "DW_OP_lit12"; | |
8707 | case DW_OP_lit13: | |
8708 | return "DW_OP_lit13"; | |
8709 | case DW_OP_lit14: | |
8710 | return "DW_OP_lit14"; | |
8711 | case DW_OP_lit15: | |
8712 | return "DW_OP_lit15"; | |
8713 | case DW_OP_lit16: | |
8714 | return "DW_OP_lit16"; | |
8715 | case DW_OP_lit17: | |
8716 | return "DW_OP_lit17"; | |
8717 | case DW_OP_lit18: | |
8718 | return "DW_OP_lit18"; | |
8719 | case DW_OP_lit19: | |
8720 | return "DW_OP_lit19"; | |
8721 | case DW_OP_lit20: | |
8722 | return "DW_OP_lit20"; | |
8723 | case DW_OP_lit21: | |
8724 | return "DW_OP_lit21"; | |
8725 | case DW_OP_lit22: | |
8726 | return "DW_OP_lit22"; | |
8727 | case DW_OP_lit23: | |
8728 | return "DW_OP_lit23"; | |
8729 | case DW_OP_lit24: | |
8730 | return "DW_OP_lit24"; | |
8731 | case DW_OP_lit25: | |
8732 | return "DW_OP_lit25"; | |
8733 | case DW_OP_lit26: | |
8734 | return "DW_OP_lit26"; | |
8735 | case DW_OP_lit27: | |
8736 | return "DW_OP_lit27"; | |
8737 | case DW_OP_lit28: | |
8738 | return "DW_OP_lit28"; | |
8739 | case DW_OP_lit29: | |
8740 | return "DW_OP_lit29"; | |
8741 | case DW_OP_lit30: | |
8742 | return "DW_OP_lit30"; | |
8743 | case DW_OP_lit31: | |
8744 | return "DW_OP_lit31"; | |
8745 | case DW_OP_reg0: | |
8746 | return "DW_OP_reg0"; | |
8747 | case DW_OP_reg1: | |
8748 | return "DW_OP_reg1"; | |
8749 | case DW_OP_reg2: | |
8750 | return "DW_OP_reg2"; | |
8751 | case DW_OP_reg3: | |
8752 | return "DW_OP_reg3"; | |
8753 | case DW_OP_reg4: | |
8754 | return "DW_OP_reg4"; | |
8755 | case DW_OP_reg5: | |
8756 | return "DW_OP_reg5"; | |
8757 | case DW_OP_reg6: | |
8758 | return "DW_OP_reg6"; | |
8759 | case DW_OP_reg7: | |
8760 | return "DW_OP_reg7"; | |
8761 | case DW_OP_reg8: | |
8762 | return "DW_OP_reg8"; | |
8763 | case DW_OP_reg9: | |
8764 | return "DW_OP_reg9"; | |
8765 | case DW_OP_reg10: | |
8766 | return "DW_OP_reg10"; | |
8767 | case DW_OP_reg11: | |
8768 | return "DW_OP_reg11"; | |
8769 | case DW_OP_reg12: | |
8770 | return "DW_OP_reg12"; | |
8771 | case DW_OP_reg13: | |
8772 | return "DW_OP_reg13"; | |
8773 | case DW_OP_reg14: | |
8774 | return "DW_OP_reg14"; | |
8775 | case DW_OP_reg15: | |
8776 | return "DW_OP_reg15"; | |
8777 | case DW_OP_reg16: | |
8778 | return "DW_OP_reg16"; | |
8779 | case DW_OP_reg17: | |
8780 | return "DW_OP_reg17"; | |
8781 | case DW_OP_reg18: | |
8782 | return "DW_OP_reg18"; | |
8783 | case DW_OP_reg19: | |
8784 | return "DW_OP_reg19"; | |
8785 | case DW_OP_reg20: | |
8786 | return "DW_OP_reg20"; | |
8787 | case DW_OP_reg21: | |
8788 | return "DW_OP_reg21"; | |
8789 | case DW_OP_reg22: | |
8790 | return "DW_OP_reg22"; | |
8791 | case DW_OP_reg23: | |
8792 | return "DW_OP_reg23"; | |
8793 | case DW_OP_reg24: | |
8794 | return "DW_OP_reg24"; | |
8795 | case DW_OP_reg25: | |
8796 | return "DW_OP_reg25"; | |
8797 | case DW_OP_reg26: | |
8798 | return "DW_OP_reg26"; | |
8799 | case DW_OP_reg27: | |
8800 | return "DW_OP_reg27"; | |
8801 | case DW_OP_reg28: | |
8802 | return "DW_OP_reg28"; | |
8803 | case DW_OP_reg29: | |
8804 | return "DW_OP_reg29"; | |
8805 | case DW_OP_reg30: | |
8806 | return "DW_OP_reg30"; | |
8807 | case DW_OP_reg31: | |
8808 | return "DW_OP_reg31"; | |
8809 | case DW_OP_breg0: | |
8810 | return "DW_OP_breg0"; | |
8811 | case DW_OP_breg1: | |
8812 | return "DW_OP_breg1"; | |
8813 | case DW_OP_breg2: | |
8814 | return "DW_OP_breg2"; | |
8815 | case DW_OP_breg3: | |
8816 | return "DW_OP_breg3"; | |
8817 | case DW_OP_breg4: | |
8818 | return "DW_OP_breg4"; | |
8819 | case DW_OP_breg5: | |
8820 | return "DW_OP_breg5"; | |
8821 | case DW_OP_breg6: | |
8822 | return "DW_OP_breg6"; | |
8823 | case DW_OP_breg7: | |
8824 | return "DW_OP_breg7"; | |
8825 | case DW_OP_breg8: | |
8826 | return "DW_OP_breg8"; | |
8827 | case DW_OP_breg9: | |
8828 | return "DW_OP_breg9"; | |
8829 | case DW_OP_breg10: | |
8830 | return "DW_OP_breg10"; | |
8831 | case DW_OP_breg11: | |
8832 | return "DW_OP_breg11"; | |
8833 | case DW_OP_breg12: | |
8834 | return "DW_OP_breg12"; | |
8835 | case DW_OP_breg13: | |
8836 | return "DW_OP_breg13"; | |
8837 | case DW_OP_breg14: | |
8838 | return "DW_OP_breg14"; | |
8839 | case DW_OP_breg15: | |
8840 | return "DW_OP_breg15"; | |
8841 | case DW_OP_breg16: | |
8842 | return "DW_OP_breg16"; | |
8843 | case DW_OP_breg17: | |
8844 | return "DW_OP_breg17"; | |
8845 | case DW_OP_breg18: | |
8846 | return "DW_OP_breg18"; | |
8847 | case DW_OP_breg19: | |
8848 | return "DW_OP_breg19"; | |
8849 | case DW_OP_breg20: | |
8850 | return "DW_OP_breg20"; | |
8851 | case DW_OP_breg21: | |
8852 | return "DW_OP_breg21"; | |
8853 | case DW_OP_breg22: | |
8854 | return "DW_OP_breg22"; | |
8855 | case DW_OP_breg23: | |
8856 | return "DW_OP_breg23"; | |
8857 | case DW_OP_breg24: | |
8858 | return "DW_OP_breg24"; | |
8859 | case DW_OP_breg25: | |
8860 | return "DW_OP_breg25"; | |
8861 | case DW_OP_breg26: | |
8862 | return "DW_OP_breg26"; | |
8863 | case DW_OP_breg27: | |
8864 | return "DW_OP_breg27"; | |
8865 | case DW_OP_breg28: | |
8866 | return "DW_OP_breg28"; | |
8867 | case DW_OP_breg29: | |
8868 | return "DW_OP_breg29"; | |
8869 | case DW_OP_breg30: | |
8870 | return "DW_OP_breg30"; | |
8871 | case DW_OP_breg31: | |
8872 | return "DW_OP_breg31"; | |
8873 | case DW_OP_regx: | |
8874 | return "DW_OP_regx"; | |
8875 | case DW_OP_fbreg: | |
8876 | return "DW_OP_fbreg"; | |
8877 | case DW_OP_bregx: | |
8878 | return "DW_OP_bregx"; | |
8879 | case DW_OP_piece: | |
8880 | return "DW_OP_piece"; | |
8881 | case DW_OP_deref_size: | |
8882 | return "DW_OP_deref_size"; | |
8883 | case DW_OP_xderef_size: | |
8884 | return "DW_OP_xderef_size"; | |
8885 | case DW_OP_nop: | |
8886 | return "DW_OP_nop"; | |
b7619582 | 8887 | /* DWARF 3 extensions. */ |
ed348acc EZ |
8888 | case DW_OP_push_object_address: |
8889 | return "DW_OP_push_object_address"; | |
8890 | case DW_OP_call2: | |
8891 | return "DW_OP_call2"; | |
8892 | case DW_OP_call4: | |
8893 | return "DW_OP_call4"; | |
8894 | case DW_OP_call_ref: | |
8895 | return "DW_OP_call_ref"; | |
b7619582 GF |
8896 | /* GNU extensions. */ |
8897 | case DW_OP_form_tls_address: | |
8898 | return "DW_OP_form_tls_address"; | |
8899 | case DW_OP_call_frame_cfa: | |
8900 | return "DW_OP_call_frame_cfa"; | |
8901 | case DW_OP_bit_piece: | |
8902 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
8903 | case DW_OP_GNU_push_tls_address: |
8904 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
8905 | case DW_OP_GNU_uninit: |
8906 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
8907 | /* HP extensions. */ |
8908 | case DW_OP_HP_is_value: | |
8909 | return "DW_OP_HP_is_value"; | |
8910 | case DW_OP_HP_fltconst4: | |
8911 | return "DW_OP_HP_fltconst4"; | |
8912 | case DW_OP_HP_fltconst8: | |
8913 | return "DW_OP_HP_fltconst8"; | |
8914 | case DW_OP_HP_mod_range: | |
8915 | return "DW_OP_HP_mod_range"; | |
8916 | case DW_OP_HP_unmod_range: | |
8917 | return "DW_OP_HP_unmod_range"; | |
8918 | case DW_OP_HP_tls: | |
8919 | return "DW_OP_HP_tls"; | |
c906108c SS |
8920 | default: |
8921 | return "OP_<unknown>"; | |
8922 | } | |
8923 | } | |
8924 | ||
8925 | static char * | |
fba45db2 | 8926 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
8927 | { |
8928 | if (mybool) | |
8929 | return "TRUE"; | |
8930 | else | |
8931 | return "FALSE"; | |
8932 | } | |
8933 | ||
8934 | /* Convert a DWARF type code into its string name. */ | |
8935 | ||
8936 | static char * | |
aa1ee363 | 8937 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
8938 | { |
8939 | switch (enc) | |
8940 | { | |
b7619582 GF |
8941 | case DW_ATE_void: |
8942 | return "DW_ATE_void"; | |
c906108c SS |
8943 | case DW_ATE_address: |
8944 | return "DW_ATE_address"; | |
8945 | case DW_ATE_boolean: | |
8946 | return "DW_ATE_boolean"; | |
8947 | case DW_ATE_complex_float: | |
8948 | return "DW_ATE_complex_float"; | |
8949 | case DW_ATE_float: | |
8950 | return "DW_ATE_float"; | |
8951 | case DW_ATE_signed: | |
8952 | return "DW_ATE_signed"; | |
8953 | case DW_ATE_signed_char: | |
8954 | return "DW_ATE_signed_char"; | |
8955 | case DW_ATE_unsigned: | |
8956 | return "DW_ATE_unsigned"; | |
8957 | case DW_ATE_unsigned_char: | |
8958 | return "DW_ATE_unsigned_char"; | |
b7619582 | 8959 | /* DWARF 3. */ |
d9fa45fe DC |
8960 | case DW_ATE_imaginary_float: |
8961 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
8962 | case DW_ATE_packed_decimal: |
8963 | return "DW_ATE_packed_decimal"; | |
8964 | case DW_ATE_numeric_string: | |
8965 | return "DW_ATE_numeric_string"; | |
8966 | case DW_ATE_edited: | |
8967 | return "DW_ATE_edited"; | |
8968 | case DW_ATE_signed_fixed: | |
8969 | return "DW_ATE_signed_fixed"; | |
8970 | case DW_ATE_unsigned_fixed: | |
8971 | return "DW_ATE_unsigned_fixed"; | |
8972 | case DW_ATE_decimal_float: | |
8973 | return "DW_ATE_decimal_float"; | |
8974 | /* HP extensions. */ | |
8975 | case DW_ATE_HP_float80: | |
8976 | return "DW_ATE_HP_float80"; | |
8977 | case DW_ATE_HP_complex_float80: | |
8978 | return "DW_ATE_HP_complex_float80"; | |
8979 | case DW_ATE_HP_float128: | |
8980 | return "DW_ATE_HP_float128"; | |
8981 | case DW_ATE_HP_complex_float128: | |
8982 | return "DW_ATE_HP_complex_float128"; | |
8983 | case DW_ATE_HP_floathpintel: | |
8984 | return "DW_ATE_HP_floathpintel"; | |
8985 | case DW_ATE_HP_imaginary_float80: | |
8986 | return "DW_ATE_HP_imaginary_float80"; | |
8987 | case DW_ATE_HP_imaginary_float128: | |
8988 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
8989 | default: |
8990 | return "DW_ATE_<unknown>"; | |
8991 | } | |
8992 | } | |
8993 | ||
8994 | /* Convert a DWARF call frame info operation to its string name. */ | |
8995 | ||
8996 | #if 0 | |
8997 | static char * | |
aa1ee363 | 8998 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
8999 | { |
9000 | switch (cfi_opc) | |
9001 | { | |
9002 | case DW_CFA_advance_loc: | |
9003 | return "DW_CFA_advance_loc"; | |
9004 | case DW_CFA_offset: | |
9005 | return "DW_CFA_offset"; | |
9006 | case DW_CFA_restore: | |
9007 | return "DW_CFA_restore"; | |
9008 | case DW_CFA_nop: | |
9009 | return "DW_CFA_nop"; | |
9010 | case DW_CFA_set_loc: | |
9011 | return "DW_CFA_set_loc"; | |
9012 | case DW_CFA_advance_loc1: | |
9013 | return "DW_CFA_advance_loc1"; | |
9014 | case DW_CFA_advance_loc2: | |
9015 | return "DW_CFA_advance_loc2"; | |
9016 | case DW_CFA_advance_loc4: | |
9017 | return "DW_CFA_advance_loc4"; | |
9018 | case DW_CFA_offset_extended: | |
9019 | return "DW_CFA_offset_extended"; | |
9020 | case DW_CFA_restore_extended: | |
9021 | return "DW_CFA_restore_extended"; | |
9022 | case DW_CFA_undefined: | |
9023 | return "DW_CFA_undefined"; | |
9024 | case DW_CFA_same_value: | |
9025 | return "DW_CFA_same_value"; | |
9026 | case DW_CFA_register: | |
9027 | return "DW_CFA_register"; | |
9028 | case DW_CFA_remember_state: | |
9029 | return "DW_CFA_remember_state"; | |
9030 | case DW_CFA_restore_state: | |
9031 | return "DW_CFA_restore_state"; | |
9032 | case DW_CFA_def_cfa: | |
9033 | return "DW_CFA_def_cfa"; | |
9034 | case DW_CFA_def_cfa_register: | |
9035 | return "DW_CFA_def_cfa_register"; | |
9036 | case DW_CFA_def_cfa_offset: | |
9037 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 9038 | /* DWARF 3. */ |
985cb1a3 JM |
9039 | case DW_CFA_def_cfa_expression: |
9040 | return "DW_CFA_def_cfa_expression"; | |
9041 | case DW_CFA_expression: | |
9042 | return "DW_CFA_expression"; | |
9043 | case DW_CFA_offset_extended_sf: | |
9044 | return "DW_CFA_offset_extended_sf"; | |
9045 | case DW_CFA_def_cfa_sf: | |
9046 | return "DW_CFA_def_cfa_sf"; | |
9047 | case DW_CFA_def_cfa_offset_sf: | |
9048 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
9049 | case DW_CFA_val_offset: |
9050 | return "DW_CFA_val_offset"; | |
9051 | case DW_CFA_val_offset_sf: | |
9052 | return "DW_CFA_val_offset_sf"; | |
9053 | case DW_CFA_val_expression: | |
9054 | return "DW_CFA_val_expression"; | |
9055 | /* SGI/MIPS specific. */ | |
c906108c SS |
9056 | case DW_CFA_MIPS_advance_loc8: |
9057 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 9058 | /* GNU extensions. */ |
985cb1a3 JM |
9059 | case DW_CFA_GNU_window_save: |
9060 | return "DW_CFA_GNU_window_save"; | |
9061 | case DW_CFA_GNU_args_size: | |
9062 | return "DW_CFA_GNU_args_size"; | |
9063 | case DW_CFA_GNU_negative_offset_extended: | |
9064 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
9065 | default: |
9066 | return "DW_CFA_<unknown>"; | |
9067 | } | |
9068 | } | |
9069 | #endif | |
9070 | ||
f9aca02d | 9071 | static void |
fba45db2 | 9072 | dump_die (struct die_info *die) |
c906108c SS |
9073 | { |
9074 | unsigned int i; | |
9075 | ||
48cd0caa | 9076 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 9077 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 9078 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 9079 | dwarf_bool_name (die->child != NULL)); |
c906108c | 9080 | |
48cd0caa | 9081 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
9082 | for (i = 0; i < die->num_attrs; ++i) |
9083 | { | |
48cd0caa | 9084 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
9085 | dwarf_attr_name (die->attrs[i].name), |
9086 | dwarf_form_name (die->attrs[i].form)); | |
9087 | switch (die->attrs[i].form) | |
9088 | { | |
9089 | case DW_FORM_ref_addr: | |
9090 | case DW_FORM_addr: | |
48cd0caa | 9091 | fprintf_unfiltered (gdb_stderr, "address: "); |
ed49a04f | 9092 | fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), gdb_stderr); |
c906108c SS |
9093 | break; |
9094 | case DW_FORM_block2: | |
9095 | case DW_FORM_block4: | |
9096 | case DW_FORM_block: | |
9097 | case DW_FORM_block1: | |
48cd0caa | 9098 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 9099 | break; |
10b3939b DJ |
9100 | case DW_FORM_ref1: |
9101 | case DW_FORM_ref2: | |
9102 | case DW_FORM_ref4: | |
9103 | fprintf_unfiltered (gdb_stderr, "constant ref: %ld (adjusted)", | |
9104 | (long) (DW_ADDR (&die->attrs[i]))); | |
9105 | break; | |
c906108c SS |
9106 | case DW_FORM_data1: |
9107 | case DW_FORM_data2: | |
9108 | case DW_FORM_data4: | |
ce5d95e1 | 9109 | case DW_FORM_data8: |
c906108c SS |
9110 | case DW_FORM_udata: |
9111 | case DW_FORM_sdata: | |
48cd0caa | 9112 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
9113 | break; |
9114 | case DW_FORM_string: | |
4bdf3d34 | 9115 | case DW_FORM_strp: |
48cd0caa | 9116 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 9117 | DW_STRING (&die->attrs[i]) |
c5aa993b | 9118 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
9119 | break; |
9120 | case DW_FORM_flag: | |
9121 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 9122 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 9123 | else |
48cd0caa | 9124 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 9125 | break; |
a8329558 KW |
9126 | case DW_FORM_indirect: |
9127 | /* the reader will have reduced the indirect form to | |
9128 | the "base form" so this form should not occur */ | |
48cd0caa | 9129 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 9130 | break; |
c906108c | 9131 | default: |
48cd0caa | 9132 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 9133 | die->attrs[i].form); |
c906108c | 9134 | } |
48cd0caa | 9135 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
9136 | } |
9137 | } | |
9138 | ||
f9aca02d | 9139 | static void |
fba45db2 | 9140 | dump_die_list (struct die_info *die) |
c906108c SS |
9141 | { |
9142 | while (die) | |
9143 | { | |
9144 | dump_die (die); | |
639d11d3 DC |
9145 | if (die->child != NULL) |
9146 | dump_die_list (die->child); | |
9147 | if (die->sibling != NULL) | |
9148 | dump_die_list (die->sibling); | |
c906108c SS |
9149 | } |
9150 | } | |
9151 | ||
f9aca02d | 9152 | static void |
10b3939b DJ |
9153 | store_in_ref_table (unsigned int offset, struct die_info *die, |
9154 | struct dwarf2_cu *cu) | |
c906108c SS |
9155 | { |
9156 | int h; | |
9157 | struct die_info *old; | |
9158 | ||
9159 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 9160 | old = cu->die_ref_table[h]; |
c906108c | 9161 | die->next_ref = old; |
10b3939b | 9162 | cu->die_ref_table[h] = die; |
c906108c SS |
9163 | } |
9164 | ||
9165 | static unsigned int | |
e142c38c | 9166 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
9167 | { |
9168 | unsigned int result = 0; | |
9169 | ||
9170 | switch (attr->form) | |
9171 | { | |
9172 | case DW_FORM_ref_addr: | |
c906108c SS |
9173 | case DW_FORM_ref1: |
9174 | case DW_FORM_ref2: | |
9175 | case DW_FORM_ref4: | |
613e1657 | 9176 | case DW_FORM_ref8: |
c906108c | 9177 | case DW_FORM_ref_udata: |
10b3939b | 9178 | result = DW_ADDR (attr); |
c906108c SS |
9179 | break; |
9180 | default: | |
4d3c2250 | 9181 | complaint (&symfile_complaints, |
e2e0b3e5 | 9182 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 9183 | dwarf_form_name (attr->form)); |
c906108c SS |
9184 | } |
9185 | return result; | |
9186 | } | |
9187 | ||
a02abb62 JB |
9188 | /* Return the constant value held by the given attribute. Return -1 |
9189 | if the value held by the attribute is not constant. */ | |
9190 | ||
9191 | static int | |
9192 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
9193 | { | |
9194 | if (attr->form == DW_FORM_sdata) | |
9195 | return DW_SND (attr); | |
9196 | else if (attr->form == DW_FORM_udata | |
9197 | || attr->form == DW_FORM_data1 | |
9198 | || attr->form == DW_FORM_data2 | |
9199 | || attr->form == DW_FORM_data4 | |
9200 | || attr->form == DW_FORM_data8) | |
9201 | return DW_UNSND (attr); | |
9202 | else | |
9203 | { | |
e2e0b3e5 | 9204 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
9205 | dwarf_form_name (attr->form)); |
9206 | return default_value; | |
9207 | } | |
9208 | } | |
9209 | ||
f9aca02d | 9210 | static struct die_info * |
10b3939b DJ |
9211 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
9212 | struct dwarf2_cu *cu) | |
c906108c SS |
9213 | { |
9214 | struct die_info *die; | |
10b3939b | 9215 | unsigned int offset; |
c906108c | 9216 | int h; |
10b3939b DJ |
9217 | struct die_info temp_die; |
9218 | struct dwarf2_cu *target_cu; | |
9219 | ||
9220 | offset = dwarf2_get_ref_die_offset (attr, cu); | |
9221 | ||
9222 | if (DW_ADDR (attr) < cu->header.offset | |
9223 | || DW_ADDR (attr) >= cu->header.offset + cu->header.length) | |
9224 | { | |
9225 | struct dwarf2_per_cu_data *per_cu; | |
9226 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (attr), | |
9227 | cu->objfile); | |
9228 | target_cu = per_cu->cu; | |
9229 | } | |
9230 | else | |
9231 | target_cu = cu; | |
c906108c SS |
9232 | |
9233 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 9234 | die = target_cu->die_ref_table[h]; |
c906108c SS |
9235 | while (die) |
9236 | { | |
9237 | if (die->offset == offset) | |
10b3939b | 9238 | return die; |
c906108c SS |
9239 | die = die->next_ref; |
9240 | } | |
10b3939b | 9241 | |
8a3fe4f8 AC |
9242 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
9243 | "at 0x%lx [in module %s]"), | |
10b3939b DJ |
9244 | (long) src_die->offset, (long) offset, cu->objfile->name); |
9245 | ||
c906108c SS |
9246 | return NULL; |
9247 | } | |
9248 | ||
c906108c SS |
9249 | /* Decode simple location descriptions. |
9250 | Given a pointer to a dwarf block that defines a location, compute | |
9251 | the location and return the value. | |
9252 | ||
4cecd739 DJ |
9253 | NOTE drow/2003-11-18: This function is called in two situations |
9254 | now: for the address of static or global variables (partial symbols | |
9255 | only) and for offsets into structures which are expected to be | |
9256 | (more or less) constant. The partial symbol case should go away, | |
9257 | and only the constant case should remain. That will let this | |
9258 | function complain more accurately. A few special modes are allowed | |
9259 | without complaint for global variables (for instance, global | |
9260 | register values and thread-local values). | |
c906108c SS |
9261 | |
9262 | A location description containing no operations indicates that the | |
4cecd739 | 9263 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
9264 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
9265 | callers will only want a very basic result and this can become a | |
9266 | complaint. | |
c906108c | 9267 | |
c906108c SS |
9268 | Note that stack[0] is unused except as a default error return. |
9269 | Note that stack overflow is not yet handled. */ | |
9270 | ||
9271 | static CORE_ADDR | |
e7c27a73 | 9272 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 9273 | { |
e7c27a73 DJ |
9274 | struct objfile *objfile = cu->objfile; |
9275 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
9276 | int i; |
9277 | int size = blk->size; | |
fe1b8b76 | 9278 | gdb_byte *data = blk->data; |
c906108c SS |
9279 | CORE_ADDR stack[64]; |
9280 | int stacki; | |
9281 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 9282 | gdb_byte op; |
c906108c SS |
9283 | |
9284 | i = 0; | |
9285 | stacki = 0; | |
9286 | stack[stacki] = 0; | |
c906108c SS |
9287 | |
9288 | while (i < size) | |
9289 | { | |
c906108c SS |
9290 | op = data[i++]; |
9291 | switch (op) | |
9292 | { | |
f1bea926 JM |
9293 | case DW_OP_lit0: |
9294 | case DW_OP_lit1: | |
9295 | case DW_OP_lit2: | |
9296 | case DW_OP_lit3: | |
9297 | case DW_OP_lit4: | |
9298 | case DW_OP_lit5: | |
9299 | case DW_OP_lit6: | |
9300 | case DW_OP_lit7: | |
9301 | case DW_OP_lit8: | |
9302 | case DW_OP_lit9: | |
9303 | case DW_OP_lit10: | |
9304 | case DW_OP_lit11: | |
9305 | case DW_OP_lit12: | |
9306 | case DW_OP_lit13: | |
9307 | case DW_OP_lit14: | |
9308 | case DW_OP_lit15: | |
9309 | case DW_OP_lit16: | |
9310 | case DW_OP_lit17: | |
9311 | case DW_OP_lit18: | |
9312 | case DW_OP_lit19: | |
9313 | case DW_OP_lit20: | |
9314 | case DW_OP_lit21: | |
9315 | case DW_OP_lit22: | |
9316 | case DW_OP_lit23: | |
9317 | case DW_OP_lit24: | |
9318 | case DW_OP_lit25: | |
9319 | case DW_OP_lit26: | |
9320 | case DW_OP_lit27: | |
9321 | case DW_OP_lit28: | |
9322 | case DW_OP_lit29: | |
9323 | case DW_OP_lit30: | |
9324 | case DW_OP_lit31: | |
9325 | stack[++stacki] = op - DW_OP_lit0; | |
9326 | break; | |
9327 | ||
c906108c SS |
9328 | case DW_OP_reg0: |
9329 | case DW_OP_reg1: | |
9330 | case DW_OP_reg2: | |
9331 | case DW_OP_reg3: | |
9332 | case DW_OP_reg4: | |
9333 | case DW_OP_reg5: | |
9334 | case DW_OP_reg6: | |
9335 | case DW_OP_reg7: | |
9336 | case DW_OP_reg8: | |
9337 | case DW_OP_reg9: | |
9338 | case DW_OP_reg10: | |
9339 | case DW_OP_reg11: | |
9340 | case DW_OP_reg12: | |
9341 | case DW_OP_reg13: | |
9342 | case DW_OP_reg14: | |
9343 | case DW_OP_reg15: | |
9344 | case DW_OP_reg16: | |
9345 | case DW_OP_reg17: | |
9346 | case DW_OP_reg18: | |
9347 | case DW_OP_reg19: | |
9348 | case DW_OP_reg20: | |
9349 | case DW_OP_reg21: | |
9350 | case DW_OP_reg22: | |
9351 | case DW_OP_reg23: | |
9352 | case DW_OP_reg24: | |
9353 | case DW_OP_reg25: | |
9354 | case DW_OP_reg26: | |
9355 | case DW_OP_reg27: | |
9356 | case DW_OP_reg28: | |
9357 | case DW_OP_reg29: | |
9358 | case DW_OP_reg30: | |
9359 | case DW_OP_reg31: | |
c906108c | 9360 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9361 | if (i < size) |
9362 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9363 | break; |
9364 | ||
9365 | case DW_OP_regx: | |
c906108c SS |
9366 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9367 | i += bytes_read; | |
c906108c | 9368 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9369 | if (i < size) |
9370 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9371 | break; |
9372 | ||
9373 | case DW_OP_addr: | |
107d2387 | 9374 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9375 | cu, &bytes_read); |
107d2387 | 9376 | i += bytes_read; |
c906108c SS |
9377 | break; |
9378 | ||
9379 | case DW_OP_const1u: | |
9380 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9381 | i += 1; | |
9382 | break; | |
9383 | ||
9384 | case DW_OP_const1s: | |
9385 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9386 | i += 1; | |
9387 | break; | |
9388 | ||
9389 | case DW_OP_const2u: | |
9390 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9391 | i += 2; | |
9392 | break; | |
9393 | ||
9394 | case DW_OP_const2s: | |
9395 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9396 | i += 2; | |
9397 | break; | |
9398 | ||
9399 | case DW_OP_const4u: | |
9400 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9401 | i += 4; | |
9402 | break; | |
9403 | ||
9404 | case DW_OP_const4s: | |
9405 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9406 | i += 4; | |
9407 | break; | |
9408 | ||
9409 | case DW_OP_constu: | |
9410 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9411 | &bytes_read); |
c906108c SS |
9412 | i += bytes_read; |
9413 | break; | |
9414 | ||
9415 | case DW_OP_consts: | |
9416 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9417 | i += bytes_read; | |
9418 | break; | |
9419 | ||
f1bea926 JM |
9420 | case DW_OP_dup: |
9421 | stack[stacki + 1] = stack[stacki]; | |
9422 | stacki++; | |
9423 | break; | |
9424 | ||
c906108c SS |
9425 | case DW_OP_plus: |
9426 | stack[stacki - 1] += stack[stacki]; | |
9427 | stacki--; | |
9428 | break; | |
9429 | ||
9430 | case DW_OP_plus_uconst: | |
9431 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9432 | i += bytes_read; | |
9433 | break; | |
9434 | ||
9435 | case DW_OP_minus: | |
f1bea926 | 9436 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9437 | stacki--; |
9438 | break; | |
9439 | ||
7a292a7a | 9440 | case DW_OP_deref: |
7a292a7a | 9441 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9442 | this using GDB's address_class enum. This is valid for partial |
9443 | global symbols, although the variable's address will be bogus | |
9444 | in the psymtab. */ | |
7a292a7a | 9445 | if (i < size) |
4d3c2250 | 9446 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9447 | break; |
9448 | ||
9d774e44 | 9449 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9450 | /* The top of the stack has the offset from the beginning |
9451 | of the thread control block at which the variable is located. */ | |
9452 | /* Nothing should follow this operator, so the top of stack would | |
9453 | be returned. */ | |
4cecd739 DJ |
9454 | /* This is valid for partial global symbols, but the variable's |
9455 | address will be bogus in the psymtab. */ | |
9d774e44 | 9456 | if (i < size) |
4d3c2250 | 9457 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9458 | break; |
9459 | ||
42be36b3 CT |
9460 | case DW_OP_GNU_uninit: |
9461 | break; | |
9462 | ||
c906108c | 9463 | default: |
e2e0b3e5 | 9464 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9465 | dwarf_stack_op_name (op)); |
c906108c SS |
9466 | return (stack[stacki]); |
9467 | } | |
9468 | } | |
9469 | return (stack[stacki]); | |
9470 | } | |
9471 | ||
9472 | /* memory allocation interface */ | |
9473 | ||
c906108c | 9474 | static struct dwarf_block * |
7b5a2f43 | 9475 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9476 | { |
9477 | struct dwarf_block *blk; | |
9478 | ||
9479 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9480 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9481 | return (blk); |
9482 | } | |
9483 | ||
9484 | static struct abbrev_info * | |
f3dd6933 | 9485 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9486 | { |
9487 | struct abbrev_info *abbrev; | |
9488 | ||
f3dd6933 DJ |
9489 | abbrev = (struct abbrev_info *) |
9490 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9491 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9492 | return (abbrev); | |
9493 | } | |
9494 | ||
9495 | static struct die_info * | |
fba45db2 | 9496 | dwarf_alloc_die (void) |
c906108c SS |
9497 | { |
9498 | struct die_info *die; | |
9499 | ||
9500 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
9501 | memset (die, 0, sizeof (struct die_info)); | |
9502 | return (die); | |
9503 | } | |
2e276125 JB |
9504 | |
9505 | \f | |
9506 | /* Macro support. */ | |
9507 | ||
9508 | ||
9509 | /* Return the full name of file number I in *LH's file name table. | |
9510 | Use COMP_DIR as the name of the current directory of the | |
9511 | compilation. The result is allocated using xmalloc; the caller is | |
9512 | responsible for freeing it. */ | |
9513 | static char * | |
9514 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9515 | { | |
6a83a1e6 EZ |
9516 | /* Is the file number a valid index into the line header's file name |
9517 | table? Remember that file numbers start with one, not zero. */ | |
9518 | if (1 <= file && file <= lh->num_file_names) | |
9519 | { | |
9520 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9521 | |
6a83a1e6 EZ |
9522 | if (IS_ABSOLUTE_PATH (fe->name)) |
9523 | return xstrdup (fe->name); | |
9524 | else | |
9525 | { | |
9526 | const char *dir; | |
9527 | int dir_len; | |
9528 | char *full_name; | |
9529 | ||
9530 | if (fe->dir_index) | |
9531 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9532 | else | |
9533 | dir = comp_dir; | |
9534 | ||
9535 | if (dir) | |
9536 | { | |
9537 | dir_len = strlen (dir); | |
9538 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9539 | strcpy (full_name, dir); | |
9540 | full_name[dir_len] = '/'; | |
9541 | strcpy (full_name + dir_len + 1, fe->name); | |
9542 | return full_name; | |
9543 | } | |
9544 | else | |
9545 | return xstrdup (fe->name); | |
9546 | } | |
9547 | } | |
2e276125 JB |
9548 | else |
9549 | { | |
6a83a1e6 EZ |
9550 | /* The compiler produced a bogus file number. We can at least |
9551 | record the macro definitions made in the file, even if we | |
9552 | won't be able to find the file by name. */ | |
9553 | char fake_name[80]; | |
9554 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9555 | |
6a83a1e6 EZ |
9556 | complaint (&symfile_complaints, |
9557 | _("bad file number in macro information (%d)"), | |
9558 | file); | |
2e276125 | 9559 | |
6a83a1e6 | 9560 | return xstrdup (fake_name); |
2e276125 JB |
9561 | } |
9562 | } | |
9563 | ||
9564 | ||
9565 | static struct macro_source_file * | |
9566 | macro_start_file (int file, int line, | |
9567 | struct macro_source_file *current_file, | |
9568 | const char *comp_dir, | |
9569 | struct line_header *lh, struct objfile *objfile) | |
9570 | { | |
9571 | /* The full name of this source file. */ | |
9572 | char *full_name = file_full_name (file, lh, comp_dir); | |
9573 | ||
9574 | /* We don't create a macro table for this compilation unit | |
9575 | at all until we actually get a filename. */ | |
9576 | if (! pending_macros) | |
4a146b47 | 9577 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9578 | objfile->macro_cache); |
2e276125 JB |
9579 | |
9580 | if (! current_file) | |
9581 | /* If we have no current file, then this must be the start_file | |
9582 | directive for the compilation unit's main source file. */ | |
9583 | current_file = macro_set_main (pending_macros, full_name); | |
9584 | else | |
9585 | current_file = macro_include (current_file, line, full_name); | |
9586 | ||
9587 | xfree (full_name); | |
9588 | ||
9589 | return current_file; | |
9590 | } | |
9591 | ||
9592 | ||
9593 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9594 | followed by a null byte. */ | |
9595 | static char * | |
9596 | copy_string (const char *buf, int len) | |
9597 | { | |
9598 | char *s = xmalloc (len + 1); | |
9599 | memcpy (s, buf, len); | |
9600 | s[len] = '\0'; | |
9601 | ||
9602 | return s; | |
9603 | } | |
9604 | ||
9605 | ||
9606 | static const char * | |
9607 | consume_improper_spaces (const char *p, const char *body) | |
9608 | { | |
9609 | if (*p == ' ') | |
9610 | { | |
4d3c2250 | 9611 | complaint (&symfile_complaints, |
e2e0b3e5 | 9612 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9613 | body); |
2e276125 JB |
9614 | |
9615 | while (*p == ' ') | |
9616 | p++; | |
9617 | } | |
9618 | ||
9619 | return p; | |
9620 | } | |
9621 | ||
9622 | ||
9623 | static void | |
9624 | parse_macro_definition (struct macro_source_file *file, int line, | |
9625 | const char *body) | |
9626 | { | |
9627 | const char *p; | |
9628 | ||
9629 | /* The body string takes one of two forms. For object-like macro | |
9630 | definitions, it should be: | |
9631 | ||
9632 | <macro name> " " <definition> | |
9633 | ||
9634 | For function-like macro definitions, it should be: | |
9635 | ||
9636 | <macro name> "() " <definition> | |
9637 | or | |
9638 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
9639 | ||
9640 | Spaces may appear only where explicitly indicated, and in the | |
9641 | <definition>. | |
9642 | ||
9643 | The Dwarf 2 spec says that an object-like macro's name is always | |
9644 | followed by a space, but versions of GCC around March 2002 omit | |
9645 | the space when the macro's definition is the empty string. | |
9646 | ||
9647 | The Dwarf 2 spec says that there should be no spaces between the | |
9648 | formal arguments in a function-like macro's formal argument list, | |
9649 | but versions of GCC around March 2002 include spaces after the | |
9650 | commas. */ | |
9651 | ||
9652 | ||
9653 | /* Find the extent of the macro name. The macro name is terminated | |
9654 | by either a space or null character (for an object-like macro) or | |
9655 | an opening paren (for a function-like macro). */ | |
9656 | for (p = body; *p; p++) | |
9657 | if (*p == ' ' || *p == '(') | |
9658 | break; | |
9659 | ||
9660 | if (*p == ' ' || *p == '\0') | |
9661 | { | |
9662 | /* It's an object-like macro. */ | |
9663 | int name_len = p - body; | |
9664 | char *name = copy_string (body, name_len); | |
9665 | const char *replacement; | |
9666 | ||
9667 | if (*p == ' ') | |
9668 | replacement = body + name_len + 1; | |
9669 | else | |
9670 | { | |
4d3c2250 | 9671 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9672 | replacement = body + name_len; |
9673 | } | |
9674 | ||
9675 | macro_define_object (file, line, name, replacement); | |
9676 | ||
9677 | xfree (name); | |
9678 | } | |
9679 | else if (*p == '(') | |
9680 | { | |
9681 | /* It's a function-like macro. */ | |
9682 | char *name = copy_string (body, p - body); | |
9683 | int argc = 0; | |
9684 | int argv_size = 1; | |
9685 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
9686 | ||
9687 | p++; | |
9688 | ||
9689 | p = consume_improper_spaces (p, body); | |
9690 | ||
9691 | /* Parse the formal argument list. */ | |
9692 | while (*p && *p != ')') | |
9693 | { | |
9694 | /* Find the extent of the current argument name. */ | |
9695 | const char *arg_start = p; | |
9696 | ||
9697 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
9698 | p++; | |
9699 | ||
9700 | if (! *p || p == arg_start) | |
4d3c2250 | 9701 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9702 | else |
9703 | { | |
9704 | /* Make sure argv has room for the new argument. */ | |
9705 | if (argc >= argv_size) | |
9706 | { | |
9707 | argv_size *= 2; | |
9708 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
9709 | } | |
9710 | ||
9711 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
9712 | } | |
9713 | ||
9714 | p = consume_improper_spaces (p, body); | |
9715 | ||
9716 | /* Consume the comma, if present. */ | |
9717 | if (*p == ',') | |
9718 | { | |
9719 | p++; | |
9720 | ||
9721 | p = consume_improper_spaces (p, body); | |
9722 | } | |
9723 | } | |
9724 | ||
9725 | if (*p == ')') | |
9726 | { | |
9727 | p++; | |
9728 | ||
9729 | if (*p == ' ') | |
9730 | /* Perfectly formed definition, no complaints. */ | |
9731 | macro_define_function (file, line, name, | |
9732 | argc, (const char **) argv, | |
9733 | p + 1); | |
9734 | else if (*p == '\0') | |
9735 | { | |
9736 | /* Complain, but do define it. */ | |
4d3c2250 | 9737 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9738 | macro_define_function (file, line, name, |
9739 | argc, (const char **) argv, | |
9740 | p); | |
9741 | } | |
9742 | else | |
9743 | /* Just complain. */ | |
4d3c2250 | 9744 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9745 | } |
9746 | else | |
9747 | /* Just complain. */ | |
4d3c2250 | 9748 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9749 | |
9750 | xfree (name); | |
9751 | { | |
9752 | int i; | |
9753 | ||
9754 | for (i = 0; i < argc; i++) | |
9755 | xfree (argv[i]); | |
9756 | } | |
9757 | xfree (argv); | |
9758 | } | |
9759 | else | |
4d3c2250 | 9760 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9761 | } |
9762 | ||
9763 | ||
9764 | static void | |
9765 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
9766 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 9767 | struct dwarf2_cu *cu) |
2e276125 | 9768 | { |
fe1b8b76 | 9769 | gdb_byte *mac_ptr, *mac_end; |
2e276125 JB |
9770 | struct macro_source_file *current_file = 0; |
9771 | ||
6502dd73 | 9772 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 9773 | { |
e2e0b3e5 | 9774 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
9775 | return; |
9776 | } | |
9777 | ||
6502dd73 DJ |
9778 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
9779 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
9780 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
9781 | |
9782 | for (;;) | |
9783 | { | |
9784 | enum dwarf_macinfo_record_type macinfo_type; | |
9785 | ||
9786 | /* Do we at least have room for a macinfo type byte? */ | |
9787 | if (mac_ptr >= mac_end) | |
9788 | { | |
4d3c2250 | 9789 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9790 | return; |
9791 | } | |
9792 | ||
9793 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
9794 | mac_ptr++; | |
9795 | ||
9796 | switch (macinfo_type) | |
9797 | { | |
9798 | /* A zero macinfo type indicates the end of the macro | |
9799 | information. */ | |
9800 | case 0: | |
9801 | return; | |
9802 | ||
9803 | case DW_MACINFO_define: | |
9804 | case DW_MACINFO_undef: | |
9805 | { | |
891d2f0b | 9806 | unsigned int bytes_read; |
2e276125 JB |
9807 | int line; |
9808 | char *body; | |
9809 | ||
9810 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9811 | mac_ptr += bytes_read; | |
9812 | body = read_string (abfd, mac_ptr, &bytes_read); | |
9813 | mac_ptr += bytes_read; | |
9814 | ||
9815 | if (! current_file) | |
4d3c2250 | 9816 | complaint (&symfile_complaints, |
e2e0b3e5 | 9817 | _("debug info gives macro %s outside of any file: %s"), |
4d3c2250 KB |
9818 | macinfo_type == |
9819 | DW_MACINFO_define ? "definition" : macinfo_type == | |
9820 | DW_MACINFO_undef ? "undefinition" : | |
9821 | "something-or-other", body); | |
2e276125 JB |
9822 | else |
9823 | { | |
9824 | if (macinfo_type == DW_MACINFO_define) | |
9825 | parse_macro_definition (current_file, line, body); | |
9826 | else if (macinfo_type == DW_MACINFO_undef) | |
9827 | macro_undef (current_file, line, body); | |
9828 | } | |
9829 | } | |
9830 | break; | |
9831 | ||
9832 | case DW_MACINFO_start_file: | |
9833 | { | |
891d2f0b | 9834 | unsigned int bytes_read; |
2e276125 JB |
9835 | int line, file; |
9836 | ||
9837 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9838 | mac_ptr += bytes_read; | |
9839 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9840 | mac_ptr += bytes_read; | |
9841 | ||
9842 | current_file = macro_start_file (file, line, | |
9843 | current_file, comp_dir, | |
e7c27a73 | 9844 | lh, cu->objfile); |
2e276125 JB |
9845 | } |
9846 | break; | |
9847 | ||
9848 | case DW_MACINFO_end_file: | |
9849 | if (! current_file) | |
4d3c2250 | 9850 | complaint (&symfile_complaints, |
e2e0b3e5 | 9851 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
9852 | else |
9853 | { | |
9854 | current_file = current_file->included_by; | |
9855 | if (! current_file) | |
9856 | { | |
9857 | enum dwarf_macinfo_record_type next_type; | |
9858 | ||
9859 | /* GCC circa March 2002 doesn't produce the zero | |
9860 | type byte marking the end of the compilation | |
9861 | unit. Complain if it's not there, but exit no | |
9862 | matter what. */ | |
9863 | ||
9864 | /* Do we at least have room for a macinfo type byte? */ | |
9865 | if (mac_ptr >= mac_end) | |
9866 | { | |
4d3c2250 | 9867 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9868 | return; |
9869 | } | |
9870 | ||
9871 | /* We don't increment mac_ptr here, so this is just | |
9872 | a look-ahead. */ | |
9873 | next_type = read_1_byte (abfd, mac_ptr); | |
9874 | if (next_type != 0) | |
4d3c2250 | 9875 | complaint (&symfile_complaints, |
e2e0b3e5 | 9876 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
9877 | |
9878 | return; | |
9879 | } | |
9880 | } | |
9881 | break; | |
9882 | ||
9883 | case DW_MACINFO_vendor_ext: | |
9884 | { | |
891d2f0b | 9885 | unsigned int bytes_read; |
2e276125 JB |
9886 | int constant; |
9887 | char *string; | |
9888 | ||
9889 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9890 | mac_ptr += bytes_read; | |
9891 | string = read_string (abfd, mac_ptr, &bytes_read); | |
9892 | mac_ptr += bytes_read; | |
9893 | ||
9894 | /* We don't recognize any vendor extensions. */ | |
9895 | } | |
9896 | break; | |
9897 | } | |
9898 | } | |
9899 | } | |
8e19ed76 PS |
9900 | |
9901 | /* Check if the attribute's form is a DW_FORM_block* | |
9902 | if so return true else false. */ | |
9903 | static int | |
9904 | attr_form_is_block (struct attribute *attr) | |
9905 | { | |
9906 | return (attr == NULL ? 0 : | |
9907 | attr->form == DW_FORM_block1 | |
9908 | || attr->form == DW_FORM_block2 | |
9909 | || attr->form == DW_FORM_block4 | |
9910 | || attr->form == DW_FORM_block); | |
9911 | } | |
4c2df51b | 9912 | |
c6a0999f JB |
9913 | /* Return non-zero if ATTR's value is a section offset --- classes |
9914 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
9915 | You may use DW_UNSND (attr) to retrieve such offsets. | |
9916 | ||
9917 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
9918 | may have a value that belongs to more than one of these classes; it | |
9919 | would be ambiguous if we did, because we use the same forms for all | |
9920 | of them. */ | |
3690dd37 JB |
9921 | static int |
9922 | attr_form_is_section_offset (struct attribute *attr) | |
9923 | { | |
9924 | return (attr->form == DW_FORM_data4 | |
9925 | || attr->form == DW_FORM_data8); | |
9926 | } | |
9927 | ||
9928 | ||
9929 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
9930 | zero otherwise. When this function returns true, you can apply | |
9931 | dwarf2_get_attr_constant_value to it. | |
9932 | ||
9933 | However, note that for some attributes you must check | |
9934 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
9935 | and DW_FORM_data8 are members of both the constant class, and of | |
9936 | the classes that contain offsets into other debug sections | |
9937 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
9938 | that, if an attribute's can be either a constant or one of the | |
9939 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
9940 | taken as section offsets, not constants. */ | |
9941 | static int | |
9942 | attr_form_is_constant (struct attribute *attr) | |
9943 | { | |
9944 | switch (attr->form) | |
9945 | { | |
9946 | case DW_FORM_sdata: | |
9947 | case DW_FORM_udata: | |
9948 | case DW_FORM_data1: | |
9949 | case DW_FORM_data2: | |
9950 | case DW_FORM_data4: | |
9951 | case DW_FORM_data8: | |
9952 | return 1; | |
9953 | default: | |
9954 | return 0; | |
9955 | } | |
9956 | } | |
9957 | ||
4c2df51b DJ |
9958 | static void |
9959 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9960 | struct dwarf2_cu *cu) |
4c2df51b | 9961 | { |
3690dd37 | 9962 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
9963 | /* ".debug_loc" may not exist at all, or the offset may be outside |
9964 | the section. If so, fall through to the complaint in the | |
9965 | other branch. */ | |
9966 | && DW_UNSND (attr) < dwarf2_per_objfile->loc_size) | |
4c2df51b | 9967 | { |
0d53c4c4 | 9968 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 9969 | |
4a146b47 | 9970 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9971 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
9972 | baton->per_cu = cu->per_cu; |
9973 | gdb_assert (baton->per_cu); | |
4c2df51b | 9974 | |
0d53c4c4 DJ |
9975 | /* We don't know how long the location list is, but make sure we |
9976 | don't run off the edge of the section. */ | |
6502dd73 DJ |
9977 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
9978 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
9979 | baton->base_address = cu->header.base_address; |
9980 | if (cu->header.base_known == 0) | |
0d53c4c4 | 9981 | complaint (&symfile_complaints, |
e2e0b3e5 | 9982 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 9983 | |
a67af2b9 | 9984 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
9985 | SYMBOL_LOCATION_BATON (sym) = baton; |
9986 | } | |
9987 | else | |
9988 | { | |
9989 | struct dwarf2_locexpr_baton *baton; | |
9990 | ||
4a146b47 | 9991 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9992 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
9993 | baton->per_cu = cu->per_cu; |
9994 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
9995 | |
9996 | if (attr_form_is_block (attr)) | |
9997 | { | |
9998 | /* Note that we're just copying the block's data pointer | |
9999 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
10000 | info_buffer for SYM's objfile; right now we never release |
10001 | that buffer, but when we do clean up properly this may | |
10002 | need to change. */ | |
0d53c4c4 DJ |
10003 | baton->size = DW_BLOCK (attr)->size; |
10004 | baton->data = DW_BLOCK (attr)->data; | |
10005 | } | |
10006 | else | |
10007 | { | |
10008 | dwarf2_invalid_attrib_class_complaint ("location description", | |
10009 | SYMBOL_NATURAL_NAME (sym)); | |
10010 | baton->size = 0; | |
10011 | baton->data = NULL; | |
10012 | } | |
10013 | ||
a67af2b9 | 10014 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
10015 | SYMBOL_LOCATION_BATON (sym) = baton; |
10016 | } | |
4c2df51b | 10017 | } |
6502dd73 | 10018 | |
ae0d2f24 UW |
10019 | /* Return the OBJFILE associated with the compilation unit CU. */ |
10020 | ||
10021 | struct objfile * | |
10022 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
10023 | { | |
10024 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10025 | ||
10026 | /* Return the master objfile, so that we can report and look up the | |
10027 | correct file containing this variable. */ | |
10028 | if (objfile->separate_debug_objfile_backlink) | |
10029 | objfile = objfile->separate_debug_objfile_backlink; | |
10030 | ||
10031 | return objfile; | |
10032 | } | |
10033 | ||
10034 | /* Return the address size given in the compilation unit header for CU. */ | |
10035 | ||
10036 | CORE_ADDR | |
10037 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
10038 | { | |
10039 | if (per_cu->cu) | |
10040 | return per_cu->cu->header.addr_size; | |
10041 | else | |
10042 | { | |
10043 | /* If the CU is not currently read in, we re-read its header. */ | |
10044 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10045 | struct dwarf2_per_objfile *per_objfile | |
10046 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
10047 | gdb_byte *info_ptr = per_objfile->info_buffer + per_cu->offset; | |
10048 | ||
10049 | struct comp_unit_head cu_header; | |
10050 | memset (&cu_header, 0, sizeof cu_header); | |
10051 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
10052 | return cu_header.addr_size; | |
10053 | } | |
10054 | } | |
10055 | ||
ae038cb0 | 10056 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 10057 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
10058 | |
10059 | static struct dwarf2_per_cu_data * | |
10060 | dwarf2_find_containing_comp_unit (unsigned long offset, | |
10061 | struct objfile *objfile) | |
10062 | { | |
10063 | struct dwarf2_per_cu_data *this_cu; | |
10064 | int low, high; | |
10065 | ||
ae038cb0 DJ |
10066 | low = 0; |
10067 | high = dwarf2_per_objfile->n_comp_units - 1; | |
10068 | while (high > low) | |
10069 | { | |
10070 | int mid = low + (high - low) / 2; | |
10071 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
10072 | high = mid; | |
10073 | else | |
10074 | low = mid + 1; | |
10075 | } | |
10076 | gdb_assert (low == high); | |
10077 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
10078 | { | |
10b3939b | 10079 | if (low == 0) |
8a3fe4f8 AC |
10080 | error (_("Dwarf Error: could not find partial DIE containing " |
10081 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
10082 | (long) offset, bfd_get_filename (objfile->obfd)); |
10083 | ||
ae038cb0 DJ |
10084 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
10085 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
10086 | } | |
10087 | else | |
10088 | { | |
10089 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
10090 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
10091 | && offset >= this_cu->offset + this_cu->length) | |
8a3fe4f8 | 10092 | error (_("invalid dwarf2 offset %ld"), offset); |
ae038cb0 DJ |
10093 | gdb_assert (offset < this_cu->offset + this_cu->length); |
10094 | return this_cu; | |
10095 | } | |
10096 | } | |
10097 | ||
10b3939b DJ |
10098 | /* Locate the compilation unit from OBJFILE which is located at exactly |
10099 | OFFSET. Raises an error on failure. */ | |
10100 | ||
ae038cb0 DJ |
10101 | static struct dwarf2_per_cu_data * |
10102 | dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile) | |
10103 | { | |
10104 | struct dwarf2_per_cu_data *this_cu; | |
10105 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
10106 | if (this_cu->offset != offset) | |
8a3fe4f8 | 10107 | error (_("no compilation unit with offset %ld."), offset); |
ae038cb0 DJ |
10108 | return this_cu; |
10109 | } | |
10110 | ||
10111 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
10112 | of compilation units, but we don't remove it from the read_in_chain; | |
10113 | the caller is responsible for that. */ | |
10114 | ||
10115 | static void | |
10116 | free_one_comp_unit (void *data) | |
10117 | { | |
10118 | struct dwarf2_cu *cu = data; | |
10119 | ||
10120 | if (cu->per_cu != NULL) | |
10121 | cu->per_cu->cu = NULL; | |
10122 | cu->per_cu = NULL; | |
10123 | ||
10124 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10b3939b DJ |
10125 | if (cu->dies) |
10126 | free_die_list (cu->dies); | |
ae038cb0 DJ |
10127 | |
10128 | xfree (cu); | |
10129 | } | |
10130 | ||
72bf9492 | 10131 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
10132 | when we're finished with it. We can't free the pointer itself, but be |
10133 | sure to unlink it from the cache. Also release any associated storage | |
10134 | and perform cache maintenance. | |
72bf9492 DJ |
10135 | |
10136 | Only used during partial symbol parsing. */ | |
10137 | ||
10138 | static void | |
10139 | free_stack_comp_unit (void *data) | |
10140 | { | |
10141 | struct dwarf2_cu *cu = data; | |
10142 | ||
10143 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10144 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
10145 | |
10146 | if (cu->per_cu != NULL) | |
10147 | { | |
10148 | /* This compilation unit is on the stack in our caller, so we | |
10149 | should not xfree it. Just unlink it. */ | |
10150 | cu->per_cu->cu = NULL; | |
10151 | cu->per_cu = NULL; | |
10152 | ||
10153 | /* If we had a per-cu pointer, then we may have other compilation | |
10154 | units loaded, so age them now. */ | |
10155 | age_cached_comp_units (); | |
10156 | } | |
10157 | } | |
10158 | ||
10159 | /* Free all cached compilation units. */ | |
10160 | ||
10161 | static void | |
10162 | free_cached_comp_units (void *data) | |
10163 | { | |
10164 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10165 | ||
10166 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10167 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10168 | while (per_cu != NULL) | |
10169 | { | |
10170 | struct dwarf2_per_cu_data *next_cu; | |
10171 | ||
10172 | next_cu = per_cu->cu->read_in_chain; | |
10173 | ||
10174 | free_one_comp_unit (per_cu->cu); | |
10175 | *last_chain = next_cu; | |
10176 | ||
10177 | per_cu = next_cu; | |
10178 | } | |
10179 | } | |
10180 | ||
10181 | /* Increase the age counter on each cached compilation unit, and free | |
10182 | any that are too old. */ | |
10183 | ||
10184 | static void | |
10185 | age_cached_comp_units (void) | |
10186 | { | |
10187 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10188 | ||
10189 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
10190 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10191 | while (per_cu != NULL) | |
10192 | { | |
10193 | per_cu->cu->last_used ++; | |
10194 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
10195 | dwarf2_mark (per_cu->cu); | |
10196 | per_cu = per_cu->cu->read_in_chain; | |
10197 | } | |
10198 | ||
10199 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10200 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10201 | while (per_cu != NULL) | |
10202 | { | |
10203 | struct dwarf2_per_cu_data *next_cu; | |
10204 | ||
10205 | next_cu = per_cu->cu->read_in_chain; | |
10206 | ||
10207 | if (!per_cu->cu->mark) | |
10208 | { | |
10209 | free_one_comp_unit (per_cu->cu); | |
10210 | *last_chain = next_cu; | |
10211 | } | |
10212 | else | |
10213 | last_chain = &per_cu->cu->read_in_chain; | |
10214 | ||
10215 | per_cu = next_cu; | |
10216 | } | |
10217 | } | |
10218 | ||
10219 | /* Remove a single compilation unit from the cache. */ | |
10220 | ||
10221 | static void | |
10222 | free_one_cached_comp_unit (void *target_cu) | |
10223 | { | |
10224 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10225 | ||
10226 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10227 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10228 | while (per_cu != NULL) | |
10229 | { | |
10230 | struct dwarf2_per_cu_data *next_cu; | |
10231 | ||
10232 | next_cu = per_cu->cu->read_in_chain; | |
10233 | ||
10234 | if (per_cu->cu == target_cu) | |
10235 | { | |
10236 | free_one_comp_unit (per_cu->cu); | |
10237 | *last_chain = next_cu; | |
10238 | break; | |
10239 | } | |
10240 | else | |
10241 | last_chain = &per_cu->cu->read_in_chain; | |
10242 | ||
10243 | per_cu = next_cu; | |
10244 | } | |
10245 | } | |
10246 | ||
fe3e1990 DJ |
10247 | /* Release all extra memory associated with OBJFILE. */ |
10248 | ||
10249 | void | |
10250 | dwarf2_free_objfile (struct objfile *objfile) | |
10251 | { | |
10252 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10253 | ||
10254 | if (dwarf2_per_objfile == NULL) | |
10255 | return; | |
10256 | ||
10257 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
10258 | free_cached_comp_units (NULL); | |
10259 | ||
10260 | /* Everything else should be on the objfile obstack. */ | |
10261 | } | |
10262 | ||
1c379e20 DJ |
10263 | /* A pair of DIE offset and GDB type pointer. We store these |
10264 | in a hash table separate from the DIEs, and preserve them | |
10265 | when the DIEs are flushed out of cache. */ | |
10266 | ||
10267 | struct dwarf2_offset_and_type | |
10268 | { | |
10269 | unsigned int offset; | |
10270 | struct type *type; | |
10271 | }; | |
10272 | ||
10273 | /* Hash function for a dwarf2_offset_and_type. */ | |
10274 | ||
10275 | static hashval_t | |
10276 | offset_and_type_hash (const void *item) | |
10277 | { | |
10278 | const struct dwarf2_offset_and_type *ofs = item; | |
10279 | return ofs->offset; | |
10280 | } | |
10281 | ||
10282 | /* Equality function for a dwarf2_offset_and_type. */ | |
10283 | ||
10284 | static int | |
10285 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
10286 | { | |
10287 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
10288 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
10289 | return ofs_lhs->offset == ofs_rhs->offset; | |
10290 | } | |
10291 | ||
10292 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 10293 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 10294 | |
f792889a | 10295 | static struct type * |
1c379e20 DJ |
10296 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
10297 | { | |
10298 | struct dwarf2_offset_and_type **slot, ofs; | |
10299 | ||
f792889a DJ |
10300 | if (cu->type_hash == NULL) |
10301 | { | |
10302 | gdb_assert (cu->per_cu != NULL); | |
10303 | cu->per_cu->type_hash | |
10304 | = htab_create_alloc_ex (cu->header.length / 24, | |
10305 | offset_and_type_hash, | |
10306 | offset_and_type_eq, | |
10307 | NULL, | |
10308 | &cu->objfile->objfile_obstack, | |
10309 | hashtab_obstack_allocate, | |
10310 | dummy_obstack_deallocate); | |
10311 | cu->type_hash = cu->per_cu->type_hash; | |
10312 | } | |
1c379e20 DJ |
10313 | |
10314 | ofs.offset = die->offset; | |
10315 | ofs.type = type; | |
10316 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 10317 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
10318 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
10319 | **slot = ofs; | |
f792889a | 10320 | return type; |
1c379e20 DJ |
10321 | } |
10322 | ||
f792889a DJ |
10323 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
10324 | not have a saved type. */ | |
1c379e20 DJ |
10325 | |
10326 | static struct type * | |
f792889a | 10327 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
10328 | { |
10329 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
10330 | htab_t type_hash = cu->type_hash; |
10331 | ||
10332 | if (type_hash == NULL) | |
10333 | return NULL; | |
1c379e20 DJ |
10334 | |
10335 | ofs.offset = die->offset; | |
10336 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
10337 | if (slot) | |
10338 | return slot->type; | |
10339 | else | |
10340 | return NULL; | |
10341 | } | |
10342 | ||
10b3939b DJ |
10343 | /* Set the mark field in CU and in every other compilation unit in the |
10344 | cache that we must keep because we are keeping CU. */ | |
10345 | ||
10346 | /* Add a dependence relationship from CU to REF_PER_CU. */ | |
10347 | ||
10348 | static void | |
10349 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
10350 | struct dwarf2_per_cu_data *ref_per_cu) | |
10351 | { | |
10352 | void **slot; | |
10353 | ||
10354 | if (cu->dependencies == NULL) | |
10355 | cu->dependencies | |
10356 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
10357 | NULL, &cu->comp_unit_obstack, | |
10358 | hashtab_obstack_allocate, | |
10359 | dummy_obstack_deallocate); | |
10360 | ||
10361 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
10362 | if (*slot == NULL) | |
10363 | *slot = ref_per_cu; | |
10364 | } | |
1c379e20 | 10365 | |
ae038cb0 DJ |
10366 | /* Set the mark field in CU and in every other compilation unit in the |
10367 | cache that we must keep because we are keeping CU. */ | |
10368 | ||
10b3939b DJ |
10369 | static int |
10370 | dwarf2_mark_helper (void **slot, void *data) | |
10371 | { | |
10372 | struct dwarf2_per_cu_data *per_cu; | |
10373 | ||
10374 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
10375 | if (per_cu->cu->mark) | |
10376 | return 1; | |
10377 | per_cu->cu->mark = 1; | |
10378 | ||
10379 | if (per_cu->cu->dependencies != NULL) | |
10380 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
10381 | ||
10382 | return 1; | |
10383 | } | |
10384 | ||
ae038cb0 DJ |
10385 | static void |
10386 | dwarf2_mark (struct dwarf2_cu *cu) | |
10387 | { | |
10388 | if (cu->mark) | |
10389 | return; | |
10390 | cu->mark = 1; | |
10b3939b DJ |
10391 | if (cu->dependencies != NULL) |
10392 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
10393 | } |
10394 | ||
10395 | static void | |
10396 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
10397 | { | |
10398 | while (per_cu) | |
10399 | { | |
10400 | per_cu->cu->mark = 0; | |
10401 | per_cu = per_cu->cu->read_in_chain; | |
10402 | } | |
72bf9492 DJ |
10403 | } |
10404 | ||
72bf9492 DJ |
10405 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10406 | is its offset in .debug_info for this objfile. */ | |
10407 | ||
10408 | static hashval_t | |
10409 | partial_die_hash (const void *item) | |
10410 | { | |
10411 | const struct partial_die_info *part_die = item; | |
10412 | return part_die->offset; | |
10413 | } | |
10414 | ||
10415 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10416 | are equal if they have the same offset. */ | |
10417 | ||
10418 | static int | |
10419 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10420 | { | |
10421 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10422 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10423 | return part_die_lhs->offset == part_die_rhs->offset; | |
10424 | } | |
10425 | ||
ae038cb0 DJ |
10426 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10427 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10428 | ||
10429 | static void | |
10430 | set_dwarf2_cmd (char *args, int from_tty) | |
10431 | { | |
10432 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10433 | } | |
10434 | ||
10435 | static void | |
10436 | show_dwarf2_cmd (char *args, int from_tty) | |
10437 | { | |
10438 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10439 | } | |
10440 | ||
6502dd73 DJ |
10441 | void _initialize_dwarf2_read (void); |
10442 | ||
10443 | void | |
10444 | _initialize_dwarf2_read (void) | |
10445 | { | |
10446 | dwarf2_objfile_data_key = register_objfile_data (); | |
ae038cb0 | 10447 | |
1bedd215 AC |
10448 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10449 | Set DWARF 2 specific variables.\n\ | |
10450 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10451 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10452 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10453 | ||
1bedd215 AC |
10454 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10455 | Show DWARF 2 specific variables\n\ | |
10456 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10457 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10458 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10459 | ||
10460 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10461 | &dwarf2_max_cache_age, _("\ |
10462 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10463 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10464 | A higher limit means that cached compilation units will be stored\n\ | |
10465 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10466 | caching, which can slow down startup."), | |
2c5b56ce | 10467 | NULL, |
920d2a44 | 10468 | show_dwarf2_max_cache_age, |
2c5b56ce | 10469 | &set_dwarf2_cmdlist, |
ae038cb0 | 10470 | &show_dwarf2_cmdlist); |
6502dd73 | 10471 | } |