Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
6aba47ca | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
9b254dd1 | 4 | 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
7 | Inc. with support from Florida State University (under contract | |
8 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
9 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
10 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
7ce59000 | 11 | support. |
c906108c | 12 | |
c5aa993b | 13 | This file is part of GDB. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is free software; you can redistribute it and/or modify |
16 | it under the terms of the GNU General Public License as published by | |
a9762ec7 JB |
17 | the Free Software Foundation; either version 3 of the License, or |
18 | (at your option) any later version. | |
c906108c | 19 | |
a9762ec7 JB |
20 | This program is distributed in the hope that it will be useful, |
21 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
23 | GNU General Public License for more details. | |
c906108c | 24 | |
c5aa993b | 25 | You should have received a copy of the GNU General Public License |
a9762ec7 | 26 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
27 | |
28 | #include "defs.h" | |
29 | #include "bfd.h" | |
c906108c SS |
30 | #include "symtab.h" |
31 | #include "gdbtypes.h" | |
c906108c SS |
32 | #include "objfiles.h" |
33 | #include "elf/dwarf2.h" | |
34 | #include "buildsym.h" | |
35 | #include "demangle.h" | |
36 | #include "expression.h" | |
d5166ae1 | 37 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 38 | #include "macrotab.h" |
c906108c SS |
39 | #include "language.h" |
40 | #include "complaints.h" | |
357e46e7 | 41 | #include "bcache.h" |
4c2df51b DJ |
42 | #include "dwarf2expr.h" |
43 | #include "dwarf2loc.h" | |
9219021c | 44 | #include "cp-support.h" |
72bf9492 | 45 | #include "hashtab.h" |
ae038cb0 DJ |
46 | #include "command.h" |
47 | #include "gdbcmd.h" | |
ff013f42 | 48 | #include "addrmap.h" |
4c2df51b | 49 | |
c906108c SS |
50 | #include <fcntl.h> |
51 | #include "gdb_string.h" | |
4bdf3d34 | 52 | #include "gdb_assert.h" |
c906108c | 53 | #include <sys/types.h> |
233a11ab CS |
54 | #ifdef HAVE_ZLIB_H |
55 | #include <zlib.h> | |
56 | #endif | |
c906108c | 57 | |
d8151005 DJ |
58 | /* A note on memory usage for this file. |
59 | ||
60 | At the present time, this code reads the debug info sections into | |
61 | the objfile's objfile_obstack. A definite improvement for startup | |
62 | time, on platforms which do not emit relocations for debug | |
63 | sections, would be to use mmap instead. The object's complete | |
64 | debug information is loaded into memory, partly to simplify | |
65 | absolute DIE references. | |
66 | ||
67 | Whether using obstacks or mmap, the sections should remain loaded | |
68 | until the objfile is released, and pointers into the section data | |
69 | can be used for any other data associated to the objfile (symbol | |
70 | names, type names, location expressions to name a few). */ | |
71 | ||
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c SS |
88 | |
89 | /* .debug_pubnames header | |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct pubnames_header | |
93 | { | |
94 | unsigned int length; /* length of the .debug_pubnames | |
95 | contribution */ | |
96 | unsigned char version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int info_offset; /* offset into .debug_info section */ | |
99 | unsigned int info_size; /* byte size of .debug_info section | |
100 | portion */ | |
101 | } | |
102 | _PUBNAMES_HEADER; | |
103 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
104 | ||
105 | /* .debug_pubnames header | |
106 | Because of alignment constraints, this structure has padding and cannot | |
107 | be mapped directly onto the beginning of the .debug_info section. */ | |
108 | typedef struct aranges_header | |
109 | { | |
110 | unsigned int length; /* byte len of the .debug_aranges | |
111 | contribution */ | |
112 | unsigned short version; /* version number -- 2 for DWARF | |
113 | version 2 */ | |
114 | unsigned int info_offset; /* offset into .debug_info section */ | |
115 | unsigned char addr_size; /* byte size of an address */ | |
116 | unsigned char seg_size; /* byte size of segment descriptor */ | |
117 | } | |
118 | _ARANGES_HEADER; | |
119 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
120 | ||
121 | /* .debug_line statement program prologue | |
122 | Because of alignment constraints, this structure has padding and cannot | |
123 | be mapped directly onto the beginning of the .debug_info section. */ | |
124 | typedef struct statement_prologue | |
125 | { | |
126 | unsigned int total_length; /* byte length of the statement | |
127 | information */ | |
128 | unsigned short version; /* version number -- 2 for DWARF | |
129 | version 2 */ | |
130 | unsigned int prologue_length; /* # bytes between prologue & | |
131 | stmt program */ | |
132 | unsigned char minimum_instruction_length; /* byte size of | |
133 | smallest instr */ | |
134 | unsigned char default_is_stmt; /* initial value of is_stmt | |
135 | register */ | |
136 | char line_base; | |
137 | unsigned char line_range; | |
138 | unsigned char opcode_base; /* number assigned to first special | |
139 | opcode */ | |
140 | unsigned char *standard_opcode_lengths; | |
141 | } | |
142 | _STATEMENT_PROLOGUE; | |
143 | ||
6502dd73 DJ |
144 | static const struct objfile_data *dwarf2_objfile_data_key; |
145 | ||
146 | struct dwarf2_per_objfile | |
147 | { | |
148 | /* Sizes of debugging sections. */ | |
149 | unsigned int info_size; | |
150 | unsigned int abbrev_size; | |
151 | unsigned int line_size; | |
152 | unsigned int pubnames_size; | |
153 | unsigned int aranges_size; | |
154 | unsigned int loc_size; | |
155 | unsigned int macinfo_size; | |
156 | unsigned int str_size; | |
157 | unsigned int ranges_size; | |
158 | unsigned int frame_size; | |
159 | unsigned int eh_frame_size; | |
160 | ||
161 | /* Loaded data from the sections. */ | |
fe1b8b76 JB |
162 | gdb_byte *info_buffer; |
163 | gdb_byte *abbrev_buffer; | |
164 | gdb_byte *line_buffer; | |
165 | gdb_byte *str_buffer; | |
166 | gdb_byte *macinfo_buffer; | |
167 | gdb_byte *ranges_buffer; | |
168 | gdb_byte *loc_buffer; | |
ae038cb0 | 169 | |
10b3939b DJ |
170 | /* A list of all the compilation units. This is used to locate |
171 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
172 | struct dwarf2_per_cu_data **all_comp_units; |
173 | ||
174 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
175 | int n_comp_units; | |
176 | ||
177 | /* A chain of compilation units that are currently read in, so that | |
178 | they can be freed later. */ | |
179 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 FR |
180 | |
181 | /* A flag indicating wether this objfile has a section loaded at a | |
182 | VMA of 0. */ | |
183 | int has_section_at_zero; | |
6502dd73 DJ |
184 | }; |
185 | ||
186 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 187 | |
086df311 DJ |
188 | static asection *dwarf_info_section; |
189 | static asection *dwarf_abbrev_section; | |
190 | static asection *dwarf_line_section; | |
191 | static asection *dwarf_pubnames_section; | |
192 | static asection *dwarf_aranges_section; | |
193 | static asection *dwarf_loc_section; | |
194 | static asection *dwarf_macinfo_section; | |
195 | static asection *dwarf_str_section; | |
196 | static asection *dwarf_ranges_section; | |
197 | asection *dwarf_frame_section; | |
198 | asection *dwarf_eh_frame_section; | |
199 | ||
c906108c SS |
200 | /* names of the debugging sections */ |
201 | ||
233a11ab CS |
202 | /* Note that if the debugging section has been compressed, it might |
203 | have a name like .zdebug_info. */ | |
204 | ||
205 | #define INFO_SECTION "debug_info" | |
206 | #define ABBREV_SECTION "debug_abbrev" | |
207 | #define LINE_SECTION "debug_line" | |
208 | #define PUBNAMES_SECTION "debug_pubnames" | |
209 | #define ARANGES_SECTION "debug_aranges" | |
210 | #define LOC_SECTION "debug_loc" | |
211 | #define MACINFO_SECTION "debug_macinfo" | |
212 | #define STR_SECTION "debug_str" | |
213 | #define RANGES_SECTION "debug_ranges" | |
214 | #define FRAME_SECTION "debug_frame" | |
215 | #define EH_FRAME_SECTION "eh_frame" | |
c906108c SS |
216 | |
217 | /* local data types */ | |
218 | ||
57349743 JB |
219 | /* We hold several abbreviation tables in memory at the same time. */ |
220 | #ifndef ABBREV_HASH_SIZE | |
221 | #define ABBREV_HASH_SIZE 121 | |
222 | #endif | |
223 | ||
107d2387 AC |
224 | /* The data in a compilation unit header, after target2host |
225 | translation, looks like this. */ | |
c906108c | 226 | struct comp_unit_head |
a738430d MK |
227 | { |
228 | unsigned long length; | |
229 | short version; | |
230 | unsigned int abbrev_offset; | |
231 | unsigned char addr_size; | |
232 | unsigned char signed_addr_p; | |
57349743 | 233 | |
a738430d MK |
234 | /* Size of file offsets; either 4 or 8. */ |
235 | unsigned int offset_size; | |
57349743 | 236 | |
a738430d MK |
237 | /* Size of the length field; either 4 or 12. */ |
238 | unsigned int initial_length_size; | |
57349743 | 239 | |
a738430d MK |
240 | /* Offset to the first byte of this compilation unit header in the |
241 | .debug_info section, for resolving relative reference dies. */ | |
242 | unsigned int offset; | |
57349743 | 243 | |
a738430d MK |
244 | /* Pointer to this compilation unit header in the .debug_info |
245 | section. */ | |
fe1b8b76 | 246 | gdb_byte *cu_head_ptr; |
57349743 | 247 | |
a738430d MK |
248 | /* Pointer to the first die of this compilation unit. This will be |
249 | the first byte following the compilation unit header. */ | |
fe1b8b76 | 250 | gdb_byte *first_die_ptr; |
af34e669 | 251 | |
a738430d MK |
252 | /* Pointer to the next compilation unit header in the program. */ |
253 | struct comp_unit_head *next; | |
0d53c4c4 | 254 | |
a738430d MK |
255 | /* Base address of this compilation unit. */ |
256 | CORE_ADDR base_address; | |
0d53c4c4 | 257 | |
a738430d MK |
258 | /* Non-zero if base_address has been set. */ |
259 | int base_known; | |
260 | }; | |
c906108c | 261 | |
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 | |
c906108c SS |
2069 | break; |
2070 | case DW_TAG_enumerator: | |
38d518c9 | 2071 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2072 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2073 | (cu->language == language_cplus |
2074 | || cu->language == language_java) | |
f6fe98ef DJ |
2075 | ? &objfile->global_psymbols |
2076 | : &objfile->static_psymbols, | |
e142c38c | 2077 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2078 | break; |
2079 | default: | |
2080 | break; | |
2081 | } | |
5c4e30ca DC |
2082 | |
2083 | /* Check to see if we should scan the name for possible namespace | |
2084 | info. Only do this if this is C++, if we don't have namespace | |
2085 | debugging info in the file, if the psym is of an appropriate type | |
2086 | (otherwise we'll have psym == NULL), and if we actually had a | |
2087 | mangled name to begin with. */ | |
2088 | ||
72bf9492 DJ |
2089 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2090 | cases which do not set PSYM above? */ | |
2091 | ||
e142c38c | 2092 | if (cu->language == language_cplus |
72bf9492 | 2093 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2094 | && psym != NULL |
2095 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2096 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2097 | objfile); | |
72bf9492 DJ |
2098 | |
2099 | if (built_actual_name) | |
2100 | xfree (actual_name); | |
c906108c SS |
2101 | } |
2102 | ||
72bf9492 DJ |
2103 | /* Determine whether a die of type TAG living in a C++ class or |
2104 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2105 | name listed in the die. */ |
2106 | ||
2107 | static int | |
72bf9492 | 2108 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2109 | { |
63d06c5c DC |
2110 | switch (tag) |
2111 | { | |
72bf9492 | 2112 | case DW_TAG_namespace: |
63d06c5c DC |
2113 | case DW_TAG_typedef: |
2114 | case DW_TAG_class_type: | |
680b30c7 | 2115 | case DW_TAG_interface_type: |
63d06c5c DC |
2116 | case DW_TAG_structure_type: |
2117 | case DW_TAG_union_type: | |
2118 | case DW_TAG_enumeration_type: | |
2119 | case DW_TAG_enumerator: | |
2120 | return 1; | |
2121 | default: | |
2122 | return 0; | |
2123 | } | |
2124 | } | |
2125 | ||
5c4e30ca DC |
2126 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2127 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2128 | the name of the enclosing namespace. */ | |
91c24f0a | 2129 | |
72bf9492 DJ |
2130 | static void |
2131 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2132 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 2133 | struct dwarf2_cu *cu) |
91c24f0a | 2134 | { |
e7c27a73 | 2135 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2136 | |
72bf9492 | 2137 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2138 | |
72bf9492 | 2139 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2140 | |
2141 | /* Now scan partial symbols in that namespace. */ | |
2142 | ||
91c24f0a | 2143 | if (pdi->has_children) |
72bf9492 | 2144 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
2145 | } |
2146 | ||
72bf9492 DJ |
2147 | /* See if we can figure out if the class lives in a namespace. We do |
2148 | this by looking for a member function; its demangled name will | |
2149 | contain namespace info, if there is any. */ | |
63d06c5c | 2150 | |
72bf9492 DJ |
2151 | static void |
2152 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2153 | struct dwarf2_cu *cu) | |
63d06c5c | 2154 | { |
987504bb JJ |
2155 | if ((cu->language == language_cplus |
2156 | || cu->language == language_java) | |
72bf9492 | 2157 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2158 | && struct_pdi->has_children) |
2159 | { | |
63d06c5c DC |
2160 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2161 | what template types look like, because the demangler | |
2162 | frequently doesn't give the same name as the debug info. We | |
2163 | could fix this by only using the demangled name to get the | |
134d01f1 | 2164 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2165 | |
72bf9492 DJ |
2166 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2167 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2168 | |
72bf9492 DJ |
2169 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2170 | we should not do this. We'll prepend the parent's fully qualified | |
2171 | name when we create the partial symbol. */ | |
5d51ca54 | 2172 | |
72bf9492 | 2173 | real_pdi = struct_pdi; |
72bf9492 | 2174 | while (real_pdi->has_specification) |
10b3939b | 2175 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2176 | |
72bf9492 DJ |
2177 | if (real_pdi->die_parent != NULL) |
2178 | return; | |
63d06c5c | 2179 | |
72bf9492 DJ |
2180 | while (child_pdi != NULL) |
2181 | { | |
2182 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2183 | { |
72bf9492 | 2184 | char *actual_class_name |
31c27f77 JJ |
2185 | = language_class_name_from_physname (cu->language_defn, |
2186 | child_pdi->name); | |
63d06c5c | 2187 | if (actual_class_name != NULL) |
72bf9492 DJ |
2188 | { |
2189 | struct_pdi->name | |
2190 | = obsavestring (actual_class_name, | |
2191 | strlen (actual_class_name), | |
2192 | &cu->comp_unit_obstack); | |
2193 | xfree (actual_class_name); | |
2194 | } | |
63d06c5c DC |
2195 | break; |
2196 | } | |
72bf9492 DJ |
2197 | |
2198 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2199 | } |
2200 | } | |
63d06c5c DC |
2201 | } |
2202 | ||
91c24f0a DC |
2203 | /* Read a partial die corresponding to an enumeration type. */ |
2204 | ||
72bf9492 DJ |
2205 | static void |
2206 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2207 | struct dwarf2_cu *cu) | |
91c24f0a | 2208 | { |
e7c27a73 | 2209 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2210 | bfd *abfd = objfile->obfd; |
72bf9492 | 2211 | struct partial_die_info *pdi; |
91c24f0a DC |
2212 | |
2213 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2214 | add_partial_symbol (enum_pdi, cu); |
2215 | ||
2216 | pdi = enum_pdi->die_child; | |
2217 | while (pdi) | |
91c24f0a | 2218 | { |
72bf9492 | 2219 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2220 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2221 | else |
72bf9492 DJ |
2222 | add_partial_symbol (pdi, cu); |
2223 | pdi = pdi->die_sibling; | |
91c24f0a | 2224 | } |
91c24f0a DC |
2225 | } |
2226 | ||
4bb7a0a7 DJ |
2227 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2228 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2229 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2230 | the initial number. */ | |
2231 | ||
2232 | static struct abbrev_info * | |
fe1b8b76 | 2233 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2234 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2235 | { |
2236 | bfd *abfd = cu->objfile->obfd; | |
2237 | unsigned int abbrev_number; | |
2238 | struct abbrev_info *abbrev; | |
2239 | ||
2240 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2241 | ||
2242 | if (abbrev_number == 0) | |
2243 | return NULL; | |
2244 | ||
2245 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2246 | if (!abbrev) | |
2247 | { | |
8a3fe4f8 | 2248 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2249 | bfd_get_filename (abfd)); |
2250 | } | |
2251 | ||
2252 | return abbrev; | |
2253 | } | |
2254 | ||
2255 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2256 | pointer to the end of a series of DIEs, terminated by an empty | |
2257 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2258 | ||
fe1b8b76 JB |
2259 | static gdb_byte * |
2260 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2261 | { |
2262 | struct abbrev_info *abbrev; | |
2263 | unsigned int bytes_read; | |
2264 | ||
2265 | while (1) | |
2266 | { | |
2267 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2268 | if (abbrev == NULL) | |
2269 | return info_ptr + bytes_read; | |
2270 | else | |
2271 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2272 | } | |
2273 | } | |
2274 | ||
2275 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2276 | should point just after the initial uleb128 of a DIE, and the | |
2277 | abbrev corresponding to that skipped uleb128 should be passed in | |
2278 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2279 | children. */ | |
2280 | ||
fe1b8b76 JB |
2281 | static gdb_byte * |
2282 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2283 | struct dwarf2_cu *cu) |
2284 | { | |
2285 | unsigned int bytes_read; | |
2286 | struct attribute attr; | |
2287 | bfd *abfd = cu->objfile->obfd; | |
2288 | unsigned int form, i; | |
2289 | ||
2290 | for (i = 0; i < abbrev->num_attrs; i++) | |
2291 | { | |
2292 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2293 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2294 | { | |
2295 | read_attribute (&attr, &abbrev->attrs[i], | |
2296 | abfd, info_ptr, cu); | |
2297 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2298 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2299 | else |
6502dd73 DJ |
2300 | return dwarf2_per_objfile->info_buffer |
2301 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
2302 | } |
2303 | ||
2304 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2305 | form = abbrev->attrs[i].form; | |
2306 | skip_attribute: | |
2307 | switch (form) | |
2308 | { | |
2309 | case DW_FORM_addr: | |
2310 | case DW_FORM_ref_addr: | |
2311 | info_ptr += cu->header.addr_size; | |
2312 | break; | |
2313 | case DW_FORM_data1: | |
2314 | case DW_FORM_ref1: | |
2315 | case DW_FORM_flag: | |
2316 | info_ptr += 1; | |
2317 | break; | |
2318 | case DW_FORM_data2: | |
2319 | case DW_FORM_ref2: | |
2320 | info_ptr += 2; | |
2321 | break; | |
2322 | case DW_FORM_data4: | |
2323 | case DW_FORM_ref4: | |
2324 | info_ptr += 4; | |
2325 | break; | |
2326 | case DW_FORM_data8: | |
2327 | case DW_FORM_ref8: | |
2328 | info_ptr += 8; | |
2329 | break; | |
2330 | case DW_FORM_string: | |
2331 | read_string (abfd, info_ptr, &bytes_read); | |
2332 | info_ptr += bytes_read; | |
2333 | break; | |
2334 | case DW_FORM_strp: | |
2335 | info_ptr += cu->header.offset_size; | |
2336 | break; | |
2337 | case DW_FORM_block: | |
2338 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2339 | info_ptr += bytes_read; | |
2340 | break; | |
2341 | case DW_FORM_block1: | |
2342 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2343 | break; | |
2344 | case DW_FORM_block2: | |
2345 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2346 | break; | |
2347 | case DW_FORM_block4: | |
2348 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2349 | break; | |
2350 | case DW_FORM_sdata: | |
2351 | case DW_FORM_udata: | |
2352 | case DW_FORM_ref_udata: | |
2353 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2354 | break; | |
2355 | case DW_FORM_indirect: | |
2356 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2357 | info_ptr += bytes_read; | |
2358 | /* We need to continue parsing from here, so just go back to | |
2359 | the top. */ | |
2360 | goto skip_attribute; | |
2361 | ||
2362 | default: | |
8a3fe4f8 | 2363 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2364 | dwarf_form_name (form), |
2365 | bfd_get_filename (abfd)); | |
2366 | } | |
2367 | } | |
2368 | ||
2369 | if (abbrev->has_children) | |
2370 | return skip_children (info_ptr, cu); | |
2371 | else | |
2372 | return info_ptr; | |
2373 | } | |
2374 | ||
2375 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2376 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2377 | |
fe1b8b76 JB |
2378 | static gdb_byte * |
2379 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2380 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2381 | { |
2382 | /* Do we know the sibling already? */ | |
72bf9492 | 2383 | |
91c24f0a DC |
2384 | if (orig_pdi->sibling) |
2385 | return orig_pdi->sibling; | |
2386 | ||
2387 | /* Are there any children to deal with? */ | |
2388 | ||
2389 | if (!orig_pdi->has_children) | |
2390 | return info_ptr; | |
2391 | ||
4bb7a0a7 | 2392 | /* Skip the children the long way. */ |
91c24f0a | 2393 | |
4bb7a0a7 | 2394 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2395 | } |
2396 | ||
c906108c SS |
2397 | /* Expand this partial symbol table into a full symbol table. */ |
2398 | ||
2399 | static void | |
fba45db2 | 2400 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2401 | { |
2402 | /* FIXME: This is barely more than a stub. */ | |
2403 | if (pst != NULL) | |
2404 | { | |
2405 | if (pst->readin) | |
2406 | { | |
8a3fe4f8 | 2407 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2408 | } |
2409 | else | |
2410 | { | |
2411 | if (info_verbose) | |
2412 | { | |
a3f17187 | 2413 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2414 | gdb_flush (gdb_stdout); |
2415 | } | |
2416 | ||
10b3939b DJ |
2417 | /* Restore our global data. */ |
2418 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2419 | dwarf2_objfile_data_key); | |
2420 | ||
c906108c SS |
2421 | psymtab_to_symtab_1 (pst); |
2422 | ||
2423 | /* Finish up the debug error message. */ | |
2424 | if (info_verbose) | |
a3f17187 | 2425 | printf_filtered (_("done.\n")); |
c906108c SS |
2426 | } |
2427 | } | |
2428 | } | |
2429 | ||
10b3939b DJ |
2430 | /* Add PER_CU to the queue. */ |
2431 | ||
2432 | static void | |
2433 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2434 | { | |
2435 | struct dwarf2_queue_item *item; | |
2436 | ||
2437 | per_cu->queued = 1; | |
2438 | item = xmalloc (sizeof (*item)); | |
2439 | item->per_cu = per_cu; | |
2440 | item->next = NULL; | |
2441 | ||
2442 | if (dwarf2_queue == NULL) | |
2443 | dwarf2_queue = item; | |
2444 | else | |
2445 | dwarf2_queue_tail->next = item; | |
2446 | ||
2447 | dwarf2_queue_tail = item; | |
2448 | } | |
2449 | ||
2450 | /* Process the queue. */ | |
2451 | ||
2452 | static void | |
2453 | process_queue (struct objfile *objfile) | |
2454 | { | |
2455 | struct dwarf2_queue_item *item, *next_item; | |
2456 | ||
2457 | /* Initially, there is just one item on the queue. Load its DIEs, | |
2458 | and the DIEs of any other compilation units it requires, | |
2459 | transitively. */ | |
2460 | ||
2461 | for (item = dwarf2_queue; item != NULL; item = item->next) | |
2462 | { | |
2463 | /* Read in this compilation unit. This may add new items to | |
2464 | the end of the queue. */ | |
31ffec48 | 2465 | load_full_comp_unit (item->per_cu, objfile); |
10b3939b DJ |
2466 | |
2467 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2468 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
10b3939b DJ |
2469 | } |
2470 | ||
2471 | /* Now everything left on the queue needs to be read in. Process | |
2472 | them, one at a time, removing from the queue as we finish. */ | |
2473 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) | |
2474 | { | |
31ffec48 | 2475 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2476 | process_full_comp_unit (item->per_cu); |
2477 | ||
2478 | item->per_cu->queued = 0; | |
2479 | next_item = item->next; | |
2480 | xfree (item); | |
2481 | } | |
2482 | ||
2483 | dwarf2_queue_tail = NULL; | |
2484 | } | |
2485 | ||
2486 | /* Free all allocated queue entries. This function only releases anything if | |
2487 | an error was thrown; if the queue was processed then it would have been | |
2488 | freed as we went along. */ | |
2489 | ||
2490 | static void | |
2491 | dwarf2_release_queue (void *dummy) | |
2492 | { | |
2493 | struct dwarf2_queue_item *item, *last; | |
2494 | ||
2495 | item = dwarf2_queue; | |
2496 | while (item) | |
2497 | { | |
2498 | /* Anything still marked queued is likely to be in an | |
2499 | inconsistent state, so discard it. */ | |
2500 | if (item->per_cu->queued) | |
2501 | { | |
2502 | if (item->per_cu->cu != NULL) | |
2503 | free_one_cached_comp_unit (item->per_cu->cu); | |
2504 | item->per_cu->queued = 0; | |
2505 | } | |
2506 | ||
2507 | last = item; | |
2508 | item = item->next; | |
2509 | xfree (last); | |
2510 | } | |
2511 | ||
2512 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2513 | } | |
2514 | ||
2515 | /* Read in full symbols for PST, and anything it depends on. */ | |
2516 | ||
c906108c | 2517 | static void |
fba45db2 | 2518 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2519 | { |
10b3939b | 2520 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2521 | struct cleanup *back_to; |
aaa75496 JB |
2522 | int i; |
2523 | ||
2524 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2525 | if (!pst->dependencies[i]->readin) | |
2526 | { | |
2527 | /* Inform about additional files that need to be read in. */ | |
2528 | if (info_verbose) | |
2529 | { | |
a3f17187 | 2530 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2531 | fputs_filtered (" ", gdb_stdout); |
2532 | wrap_here (""); | |
2533 | fputs_filtered ("and ", gdb_stdout); | |
2534 | wrap_here (""); | |
2535 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2536 | wrap_here (""); /* Flush output */ | |
2537 | gdb_flush (gdb_stdout); | |
2538 | } | |
2539 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2540 | } | |
2541 | ||
10b3939b DJ |
2542 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2543 | ||
2544 | if (per_cu == NULL) | |
aaa75496 JB |
2545 | { |
2546 | /* It's an include file, no symbols to read for it. | |
2547 | Everything is in the parent symtab. */ | |
2548 | pst->readin = 1; | |
2549 | return; | |
2550 | } | |
c906108c | 2551 | |
10b3939b DJ |
2552 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2553 | ||
2554 | queue_comp_unit (per_cu); | |
2555 | ||
2556 | process_queue (pst->objfile); | |
2557 | ||
2558 | /* Age the cache, releasing compilation units that have not | |
2559 | been used recently. */ | |
2560 | age_cached_comp_units (); | |
2561 | ||
2562 | do_cleanups (back_to); | |
2563 | } | |
2564 | ||
2565 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2566 | ||
2567 | static struct dwarf2_cu * | |
31ffec48 | 2568 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2569 | { |
31ffec48 | 2570 | bfd *abfd = objfile->obfd; |
10b3939b DJ |
2571 | struct dwarf2_cu *cu; |
2572 | unsigned long offset; | |
fe1b8b76 | 2573 | gdb_byte *info_ptr; |
10b3939b DJ |
2574 | struct cleanup *back_to, *free_cu_cleanup; |
2575 | struct attribute *attr; | |
2576 | CORE_ADDR baseaddr; | |
6502dd73 | 2577 | |
c906108c | 2578 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2579 | offset = per_cu->offset; |
6502dd73 DJ |
2580 | |
2581 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
63d06c5c | 2582 | |
10b3939b DJ |
2583 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2584 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2585 | |
10b3939b DJ |
2586 | /* If an error occurs while loading, release our storage. */ |
2587 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2588 | |
31ffec48 | 2589 | cu->objfile = objfile; |
e7c27a73 | 2590 | |
c906108c | 2591 | /* read in the comp_unit header */ |
10b3939b | 2592 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2593 | |
2594 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2595 | dwarf2_read_abbrevs (abfd, cu); |
2596 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2597 | ||
2598 | cu->header.offset = offset; | |
c906108c | 2599 | |
10b3939b DJ |
2600 | cu->per_cu = per_cu; |
2601 | per_cu->cu = cu; | |
f792889a | 2602 | cu->type_hash = per_cu->type_hash; |
e142c38c | 2603 | |
10b3939b DJ |
2604 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2605 | obstack_init (&cu->comp_unit_obstack); | |
2606 | ||
2607 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2608 | ||
2609 | /* We try not to read any attributes in this function, because not | |
2610 | all objfiles needed for references have been loaded yet, and symbol | |
2611 | table processing isn't initialized. But we have to set the CU language, | |
2612 | or we won't be able to build types correctly. */ | |
2613 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2614 | if (attr) | |
2615 | set_cu_language (DW_UNSND (attr), cu); | |
2616 | else | |
2617 | set_cu_language (language_minimal, cu); | |
2618 | ||
2619 | do_cleanups (back_to); | |
e142c38c | 2620 | |
10b3939b DJ |
2621 | /* We've successfully allocated this compilation unit. Let our caller |
2622 | clean it up when finished with it. */ | |
2623 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2624 | |
10b3939b DJ |
2625 | return cu; |
2626 | } | |
2627 | ||
2628 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2629 | already been loaded into memory. */ | |
2630 | ||
2631 | static void | |
2632 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2633 | { | |
2634 | struct partial_symtab *pst = per_cu->psymtab; | |
2635 | struct dwarf2_cu *cu = per_cu->cu; | |
2636 | struct objfile *objfile = pst->objfile; | |
2637 | bfd *abfd = objfile->obfd; | |
2638 | CORE_ADDR lowpc, highpc; | |
2639 | struct symtab *symtab; | |
2640 | struct cleanup *back_to; | |
2641 | struct attribute *attr; | |
2642 | CORE_ADDR baseaddr; | |
2643 | ||
2644 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2645 | ||
2646 | /* We're in the global namespace. */ | |
2647 | processing_current_prefix = ""; | |
2648 | ||
2649 | buildsym_init (); | |
2650 | back_to = make_cleanup (really_free_pendings, NULL); | |
2651 | ||
2652 | cu->list_in_scope = &file_symbols; | |
c906108c | 2653 | |
0d53c4c4 DJ |
2654 | /* Find the base address of the compilation unit for range lists and |
2655 | location lists. It will normally be specified by DW_AT_low_pc. | |
2656 | In DWARF-3 draft 4, the base address could be overridden by | |
2657 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2658 | compilation units with discontinuous ranges. */ | |
2659 | ||
10b3939b DJ |
2660 | cu->header.base_known = 0; |
2661 | cu->header.base_address = 0; | |
0d53c4c4 | 2662 | |
10b3939b | 2663 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2664 | if (attr) |
2665 | { | |
10b3939b DJ |
2666 | cu->header.base_address = DW_ADDR (attr); |
2667 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2668 | } |
2669 | else | |
2670 | { | |
10b3939b | 2671 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2672 | if (attr) |
2673 | { | |
10b3939b DJ |
2674 | cu->header.base_address = DW_ADDR (attr); |
2675 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2676 | } |
2677 | } | |
2678 | ||
c906108c | 2679 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2680 | process_die (cu->dies, cu); |
c906108c | 2681 | |
fae299cd DC |
2682 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2683 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2684 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2685 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2686 | |
613e1657 | 2687 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2688 | |
2689 | /* Set symtab language to language from DW_AT_language. | |
2690 | If the compilation is from a C file generated by language preprocessors, | |
2691 | do not set the language if it was already deduced by start_subfile. */ | |
2692 | if (symtab != NULL | |
10b3939b | 2693 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2694 | { |
10b3939b | 2695 | symtab->language = cu->language; |
c906108c SS |
2696 | } |
2697 | pst->symtab = symtab; | |
2698 | pst->readin = 1; | |
c906108c SS |
2699 | |
2700 | do_cleanups (back_to); | |
2701 | } | |
2702 | ||
2703 | /* Process a die and its children. */ | |
2704 | ||
2705 | static void | |
e7c27a73 | 2706 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2707 | { |
2708 | switch (die->tag) | |
2709 | { | |
2710 | case DW_TAG_padding: | |
2711 | break; | |
2712 | case DW_TAG_compile_unit: | |
e7c27a73 | 2713 | read_file_scope (die, cu); |
c906108c SS |
2714 | break; |
2715 | case DW_TAG_subprogram: | |
e7c27a73 | 2716 | read_func_scope (die, cu); |
c906108c SS |
2717 | break; |
2718 | case DW_TAG_inlined_subroutine: | |
2719 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2720 | They could be used to set breakpoints on all inlined instances |
2721 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2722 | break; |
2723 | case DW_TAG_lexical_block: | |
14898363 L |
2724 | case DW_TAG_try_block: |
2725 | case DW_TAG_catch_block: | |
e7c27a73 | 2726 | read_lexical_block_scope (die, cu); |
c906108c SS |
2727 | break; |
2728 | case DW_TAG_class_type: | |
680b30c7 | 2729 | case DW_TAG_interface_type: |
c906108c SS |
2730 | case DW_TAG_structure_type: |
2731 | case DW_TAG_union_type: | |
134d01f1 | 2732 | process_structure_scope (die, cu); |
c906108c SS |
2733 | break; |
2734 | case DW_TAG_enumeration_type: | |
134d01f1 | 2735 | process_enumeration_scope (die, cu); |
c906108c | 2736 | break; |
134d01f1 | 2737 | |
f792889a DJ |
2738 | /* These dies have a type, but processing them does not create |
2739 | a symbol or recurse to process the children. Therefore we can | |
2740 | read them on-demand through read_type_die. */ | |
c906108c | 2741 | case DW_TAG_subroutine_type: |
72019c9c | 2742 | case DW_TAG_set_type: |
c906108c | 2743 | case DW_TAG_array_type: |
c906108c | 2744 | case DW_TAG_pointer_type: |
c906108c | 2745 | case DW_TAG_ptr_to_member_type: |
c906108c | 2746 | case DW_TAG_reference_type: |
c906108c | 2747 | case DW_TAG_string_type: |
c906108c | 2748 | break; |
134d01f1 | 2749 | |
c906108c | 2750 | case DW_TAG_base_type: |
a02abb62 | 2751 | case DW_TAG_subrange_type: |
134d01f1 DJ |
2752 | /* Add a typedef symbol for the type definition, if it has a |
2753 | DW_AT_name. */ | |
f792889a | 2754 | new_symbol (die, read_type_die (die, cu), cu); |
a02abb62 | 2755 | break; |
c906108c | 2756 | case DW_TAG_common_block: |
e7c27a73 | 2757 | read_common_block (die, cu); |
c906108c SS |
2758 | break; |
2759 | case DW_TAG_common_inclusion: | |
2760 | break; | |
d9fa45fe | 2761 | case DW_TAG_namespace: |
63d06c5c | 2762 | processing_has_namespace_info = 1; |
e7c27a73 | 2763 | read_namespace (die, cu); |
d9fa45fe DC |
2764 | break; |
2765 | case DW_TAG_imported_declaration: | |
2766 | case DW_TAG_imported_module: | |
2767 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2768 | information contained in these. DW_TAG_imported_declaration | |
2769 | dies shouldn't have children; DW_TAG_imported_module dies | |
2770 | shouldn't in the C++ case, but conceivably could in the | |
2771 | Fortran case, so we'll have to replace this gdb_assert if | |
2772 | Fortran compilers start generating that info. */ | |
63d06c5c | 2773 | processing_has_namespace_info = 1; |
639d11d3 | 2774 | gdb_assert (die->child == NULL); |
d9fa45fe | 2775 | break; |
c906108c | 2776 | default: |
e7c27a73 | 2777 | new_symbol (die, NULL, cu); |
c906108c SS |
2778 | break; |
2779 | } | |
2780 | } | |
2781 | ||
5fb290d7 | 2782 | static void |
e142c38c | 2783 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2784 | { |
e142c38c | 2785 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2786 | } |
2787 | ||
cb1df416 DJ |
2788 | static void |
2789 | free_cu_line_header (void *arg) | |
2790 | { | |
2791 | struct dwarf2_cu *cu = arg; | |
2792 | ||
2793 | free_line_header (cu->line_header); | |
2794 | cu->line_header = NULL; | |
2795 | } | |
2796 | ||
c906108c | 2797 | static void |
e7c27a73 | 2798 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2799 | { |
e7c27a73 DJ |
2800 | struct objfile *objfile = cu->objfile; |
2801 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2802 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2803 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2804 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2805 | struct attribute *attr; | |
e1024ff1 | 2806 | char *name = NULL; |
c906108c SS |
2807 | char *comp_dir = NULL; |
2808 | struct die_info *child_die; | |
2809 | bfd *abfd = objfile->obfd; | |
debd256d | 2810 | struct line_header *line_header = 0; |
e142c38c DJ |
2811 | CORE_ADDR baseaddr; |
2812 | ||
2813 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2814 | |
fae299cd | 2815 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2816 | |
2817 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2818 | from finish_block. */ | |
2acceee2 | 2819 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2820 | lowpc = highpc; |
2821 | lowpc += baseaddr; | |
2822 | highpc += baseaddr; | |
2823 | ||
39cbfefa DJ |
2824 | /* Find the filename. Do not use dwarf2_name here, since the filename |
2825 | is not a source language identifier. */ | |
e142c38c | 2826 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2827 | if (attr) |
2828 | { | |
2829 | name = DW_STRING (attr); | |
2830 | } | |
e1024ff1 | 2831 | |
e142c38c | 2832 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c | 2833 | if (attr) |
e1024ff1 DJ |
2834 | comp_dir = DW_STRING (attr); |
2835 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) | |
c906108c | 2836 | { |
e1024ff1 DJ |
2837 | comp_dir = ldirname (name); |
2838 | if (comp_dir != NULL) | |
2839 | make_cleanup (xfree, comp_dir); | |
2840 | } | |
2841 | if (comp_dir != NULL) | |
2842 | { | |
2843 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2844 | directory, get rid of it. */ | |
2845 | char *cp = strchr (comp_dir, ':'); | |
c906108c | 2846 | |
e1024ff1 DJ |
2847 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
2848 | comp_dir = cp + 1; | |
c906108c SS |
2849 | } |
2850 | ||
e1024ff1 DJ |
2851 | if (name == NULL) |
2852 | name = "<unknown>"; | |
2853 | ||
e142c38c | 2854 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2855 | if (attr) |
2856 | { | |
e142c38c | 2857 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2858 | } |
2859 | ||
b0f35d58 DL |
2860 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
2861 | if (attr) | |
2862 | cu->producer = DW_STRING (attr); | |
303b6f5d | 2863 | |
c906108c SS |
2864 | /* We assume that we're processing GCC output. */ |
2865 | processing_gcc_compilation = 2; | |
c906108c | 2866 | |
c906108c SS |
2867 | start_symtab (name, comp_dir, lowpc); |
2868 | record_debugformat ("DWARF 2"); | |
303b6f5d | 2869 | record_producer (cu->producer); |
c906108c | 2870 | |
e142c38c | 2871 | initialize_cu_func_list (cu); |
c906108c | 2872 | |
cb1df416 DJ |
2873 | /* Decode line number information if present. We do this before |
2874 | processing child DIEs, so that the line header table is available | |
2875 | for DW_AT_decl_file. */ | |
e142c38c | 2876 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2877 | if (attr) |
2878 | { | |
debd256d | 2879 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2880 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2881 | if (line_header) |
2882 | { | |
cb1df416 DJ |
2883 | cu->line_header = line_header; |
2884 | make_cleanup (free_cu_line_header, cu); | |
aaa75496 | 2885 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2886 | } |
5fb290d7 | 2887 | } |
debd256d | 2888 | |
cb1df416 DJ |
2889 | /* Process all dies in compilation unit. */ |
2890 | if (die->child != NULL) | |
2891 | { | |
2892 | child_die = die->child; | |
2893 | while (child_die && child_die->tag) | |
2894 | { | |
2895 | process_die (child_die, cu); | |
2896 | child_die = sibling_die (child_die); | |
2897 | } | |
2898 | } | |
2899 | ||
2e276125 JB |
2900 | /* Decode macro information, if present. Dwarf 2 macro information |
2901 | refers to information in the line number info statement program | |
2902 | header, so we can only read it if we've read the header | |
2903 | successfully. */ | |
e142c38c | 2904 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2905 | if (attr && line_header) |
2e276125 JB |
2906 | { |
2907 | unsigned int macro_offset = DW_UNSND (attr); | |
2908 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2909 | comp_dir, abfd, cu); |
2e276125 | 2910 | } |
debd256d | 2911 | do_cleanups (back_to); |
5fb290d7 DJ |
2912 | } |
2913 | ||
2914 | static void | |
e142c38c DJ |
2915 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2916 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2917 | { |
2918 | struct function_range *thisfn; | |
2919 | ||
2920 | thisfn = (struct function_range *) | |
7b5a2f43 | 2921 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2922 | thisfn->name = name; |
2923 | thisfn->lowpc = lowpc; | |
2924 | thisfn->highpc = highpc; | |
2925 | thisfn->seen_line = 0; | |
2926 | thisfn->next = NULL; | |
2927 | ||
e142c38c DJ |
2928 | if (cu->last_fn == NULL) |
2929 | cu->first_fn = thisfn; | |
5fb290d7 | 2930 | else |
e142c38c | 2931 | cu->last_fn->next = thisfn; |
5fb290d7 | 2932 | |
e142c38c | 2933 | cu->last_fn = thisfn; |
c906108c SS |
2934 | } |
2935 | ||
2936 | static void | |
e7c27a73 | 2937 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2938 | { |
e7c27a73 | 2939 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2940 | struct context_stack *new; |
c906108c SS |
2941 | CORE_ADDR lowpc; |
2942 | CORE_ADDR highpc; | |
2943 | struct die_info *child_die; | |
2944 | struct attribute *attr; | |
2945 | char *name; | |
fdde2d81 DC |
2946 | const char *previous_prefix = processing_current_prefix; |
2947 | struct cleanup *back_to = NULL; | |
e142c38c | 2948 | CORE_ADDR baseaddr; |
801e3a5b | 2949 | struct block *block; |
c906108c | 2950 | |
e142c38c DJ |
2951 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2952 | ||
2953 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2954 | |
2955 | /* Ignore functions with missing or empty names and functions with | |
2956 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2957 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2958 | return; |
2959 | ||
987504bb JJ |
2960 | if (cu->language == language_cplus |
2961 | || cu->language == language_java) | |
fdde2d81 | 2962 | { |
086ed43d | 2963 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2964 | |
2a35147e JB |
2965 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2966 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2967 | given the code | |
2968 | ||
2969 | namespace N { | |
2970 | void foo() { | |
2971 | // Definition of N::foo. | |
2972 | } | |
2973 | } | |
2974 | ||
2975 | then we'll have a tree of DIEs like this: | |
2976 | ||
2977 | 1: DW_TAG_compile_unit | |
2978 | 2: DW_TAG_namespace // N | |
2979 | 3: DW_TAG_subprogram // declaration of N::foo | |
2980 | 4: DW_TAG_subprogram // definition of N::foo | |
2981 | DW_AT_specification // refers to die #3 | |
2982 | ||
2983 | Thus, when processing die #4, we have to pretend that we're | |
2984 | in the context of its DW_AT_specification, namely the contex | |
2985 | of die #3. */ | |
fdde2d81 DC |
2986 | |
2987 | if (spec_die != NULL) | |
2988 | { | |
e142c38c | 2989 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
2990 | processing_current_prefix = specification_prefix; |
2991 | back_to = make_cleanup (xfree, specification_prefix); | |
2992 | } | |
2993 | } | |
2994 | ||
c906108c SS |
2995 | lowpc += baseaddr; |
2996 | highpc += baseaddr; | |
2997 | ||
5fb290d7 | 2998 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2999 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 3000 | |
c906108c | 3001 | new = push_context (0, lowpc); |
f792889a | 3002 | new->name = new_symbol (die, read_type_die (die, cu), cu); |
4c2df51b | 3003 | |
4cecd739 DJ |
3004 | /* If there is a location expression for DW_AT_frame_base, record |
3005 | it. */ | |
e142c38c | 3006 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 3007 | if (attr) |
c034e007 AC |
3008 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
3009 | expression is being recorded directly in the function's symbol | |
3010 | and not in a separate frame-base object. I guess this hack is | |
3011 | to avoid adding some sort of frame-base adjunct/annex to the | |
3012 | function's symbol :-(. The problem with doing this is that it | |
3013 | results in a function symbol with a location expression that | |
3014 | has nothing to do with the location of the function, ouch! The | |
3015 | relationship should be: a function's symbol has-a frame base; a | |
3016 | frame-base has-a location expression. */ | |
e7c27a73 | 3017 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 3018 | |
e142c38c | 3019 | cu->list_in_scope = &local_symbols; |
c906108c | 3020 | |
639d11d3 | 3021 | if (die->child != NULL) |
c906108c | 3022 | { |
639d11d3 | 3023 | child_die = die->child; |
c906108c SS |
3024 | while (child_die && child_die->tag) |
3025 | { | |
e7c27a73 | 3026 | process_die (child_die, cu); |
c906108c SS |
3027 | child_die = sibling_die (child_die); |
3028 | } | |
3029 | } | |
3030 | ||
3031 | new = pop_context (); | |
3032 | /* Make a block for the local symbols within. */ | |
801e3a5b JB |
3033 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
3034 | lowpc, highpc, objfile); | |
3035 | ||
3036 | /* If we have address ranges, record them. */ | |
3037 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
208d8187 JB |
3038 | |
3039 | /* In C++, we can have functions nested inside functions (e.g., when | |
3040 | a function declares a class that has methods). This means that | |
3041 | when we finish processing a function scope, we may need to go | |
3042 | back to building a containing block's symbol lists. */ | |
3043 | local_symbols = new->locals; | |
3044 | param_symbols = new->params; | |
3045 | ||
921e78cf JB |
3046 | /* If we've finished processing a top-level function, subsequent |
3047 | symbols go in the file symbol list. */ | |
3048 | if (outermost_context_p ()) | |
e142c38c | 3049 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
3050 | |
3051 | processing_current_prefix = previous_prefix; | |
3052 | if (back_to != NULL) | |
3053 | do_cleanups (back_to); | |
c906108c SS |
3054 | } |
3055 | ||
3056 | /* Process all the DIES contained within a lexical block scope. Start | |
3057 | a new scope, process the dies, and then close the scope. */ | |
3058 | ||
3059 | static void | |
e7c27a73 | 3060 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3061 | { |
e7c27a73 | 3062 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3063 | struct context_stack *new; |
c906108c SS |
3064 | CORE_ADDR lowpc, highpc; |
3065 | struct die_info *child_die; | |
e142c38c DJ |
3066 | CORE_ADDR baseaddr; |
3067 | ||
3068 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3069 | |
3070 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3071 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3072 | as multiple lexical blocks? Handling children in a sane way would | |
3073 | be nasty. Might be easier to properly extend generic blocks to | |
3074 | describe ranges. */ | |
e7c27a73 | 3075 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3076 | return; |
3077 | lowpc += baseaddr; | |
3078 | highpc += baseaddr; | |
3079 | ||
3080 | push_context (0, lowpc); | |
639d11d3 | 3081 | if (die->child != NULL) |
c906108c | 3082 | { |
639d11d3 | 3083 | child_die = die->child; |
c906108c SS |
3084 | while (child_die && child_die->tag) |
3085 | { | |
e7c27a73 | 3086 | process_die (child_die, cu); |
c906108c SS |
3087 | child_die = sibling_die (child_die); |
3088 | } | |
3089 | } | |
3090 | new = pop_context (); | |
3091 | ||
3092 | if (local_symbols != NULL) | |
3093 | { | |
801e3a5b JB |
3094 | struct block *block |
3095 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3096 | highpc, objfile); | |
3097 | ||
3098 | /* Note that recording ranges after traversing children, as we | |
3099 | do here, means that recording a parent's ranges entails | |
3100 | walking across all its children's ranges as they appear in | |
3101 | the address map, which is quadratic behavior. | |
3102 | ||
3103 | It would be nicer to record the parent's ranges before | |
3104 | traversing its children, simply overriding whatever you find | |
3105 | there. But since we don't even decide whether to create a | |
3106 | block until after we've traversed its children, that's hard | |
3107 | to do. */ | |
3108 | dwarf2_record_block_ranges (die, block, baseaddr, cu); | |
c906108c SS |
3109 | } |
3110 | local_symbols = new->locals; | |
3111 | } | |
3112 | ||
43039443 | 3113 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
ff013f42 JK |
3114 | Return 1 if the attributes are present and valid, otherwise, return 0. |
3115 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ | |
43039443 JK |
3116 | |
3117 | static int | |
3118 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, | |
ff013f42 JK |
3119 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
3120 | struct partial_symtab *ranges_pst) | |
43039443 JK |
3121 | { |
3122 | struct objfile *objfile = cu->objfile; | |
3123 | struct comp_unit_head *cu_header = &cu->header; | |
3124 | bfd *obfd = objfile->obfd; | |
3125 | unsigned int addr_size = cu_header->addr_size; | |
3126 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3127 | /* Base address selection entry. */ | |
3128 | CORE_ADDR base; | |
3129 | int found_base; | |
3130 | unsigned int dummy; | |
3131 | gdb_byte *buffer; | |
3132 | CORE_ADDR marker; | |
3133 | int low_set; | |
3134 | CORE_ADDR low = 0; | |
3135 | CORE_ADDR high = 0; | |
ff013f42 | 3136 | CORE_ADDR baseaddr; |
43039443 JK |
3137 | |
3138 | found_base = cu_header->base_known; | |
3139 | base = cu_header->base_address; | |
3140 | ||
3141 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3142 | { | |
3143 | complaint (&symfile_complaints, | |
3144 | _("Offset %d out of bounds for DW_AT_ranges attribute"), | |
3145 | offset); | |
3146 | return 0; | |
3147 | } | |
3148 | buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3149 | ||
3150 | /* Read in the largest possible address. */ | |
3151 | marker = read_address (obfd, buffer, cu, &dummy); | |
3152 | if ((marker & mask) == mask) | |
3153 | { | |
3154 | /* If we found the largest possible address, then | |
3155 | read the base address. */ | |
3156 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3157 | buffer += 2 * addr_size; | |
3158 | offset += 2 * addr_size; | |
3159 | found_base = 1; | |
3160 | } | |
3161 | ||
3162 | low_set = 0; | |
3163 | ||
e7030f15 | 3164 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
ff013f42 | 3165 | |
43039443 JK |
3166 | while (1) |
3167 | { | |
3168 | CORE_ADDR range_beginning, range_end; | |
3169 | ||
3170 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |
3171 | buffer += addr_size; | |
3172 | range_end = read_address (obfd, buffer, cu, &dummy); | |
3173 | buffer += addr_size; | |
3174 | offset += 2 * addr_size; | |
3175 | ||
3176 | /* An end of list marker is a pair of zero addresses. */ | |
3177 | if (range_beginning == 0 && range_end == 0) | |
3178 | /* Found the end of list entry. */ | |
3179 | break; | |
3180 | ||
3181 | /* Each base address selection entry is a pair of 2 values. | |
3182 | The first is the largest possible address, the second is | |
3183 | the base address. Check for a base address here. */ | |
3184 | if ((range_beginning & mask) == mask) | |
3185 | { | |
3186 | /* If we found the largest possible address, then | |
3187 | read the base address. */ | |
3188 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |
3189 | found_base = 1; | |
3190 | continue; | |
3191 | } | |
3192 | ||
3193 | if (!found_base) | |
3194 | { | |
3195 | /* We have no valid base address for the ranges | |
3196 | data. */ | |
3197 | complaint (&symfile_complaints, | |
3198 | _("Invalid .debug_ranges data (no base address)")); | |
3199 | return 0; | |
3200 | } | |
3201 | ||
3202 | range_beginning += base; | |
3203 | range_end += base; | |
3204 | ||
ff013f42 JK |
3205 | if (ranges_pst != NULL && range_beginning < range_end) |
3206 | addrmap_set_empty (objfile->psymtabs_addrmap, | |
3207 | range_beginning + baseaddr, range_end - 1 + baseaddr, | |
3208 | ranges_pst); | |
3209 | ||
43039443 JK |
3210 | /* FIXME: This is recording everything as a low-high |
3211 | segment of consecutive addresses. We should have a | |
3212 | data structure for discontiguous block ranges | |
3213 | instead. */ | |
3214 | if (! low_set) | |
3215 | { | |
3216 | low = range_beginning; | |
3217 | high = range_end; | |
3218 | low_set = 1; | |
3219 | } | |
3220 | else | |
3221 | { | |
3222 | if (range_beginning < low) | |
3223 | low = range_beginning; | |
3224 | if (range_end > high) | |
3225 | high = range_end; | |
3226 | } | |
3227 | } | |
3228 | ||
3229 | if (! low_set) | |
3230 | /* If the first entry is an end-of-list marker, the range | |
3231 | describes an empty scope, i.e. no instructions. */ | |
3232 | return 0; | |
3233 | ||
3234 | if (low_return) | |
3235 | *low_return = low; | |
3236 | if (high_return) | |
3237 | *high_return = high; | |
3238 | return 1; | |
3239 | } | |
3240 | ||
af34e669 DJ |
3241 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3242 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3243 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3244 | static int |
af34e669 | 3245 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3246 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c SS |
3247 | { |
3248 | struct attribute *attr; | |
af34e669 DJ |
3249 | CORE_ADDR low = 0; |
3250 | CORE_ADDR high = 0; | |
3251 | int ret = 0; | |
c906108c | 3252 | |
e142c38c | 3253 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3254 | if (attr) |
af34e669 DJ |
3255 | { |
3256 | high = DW_ADDR (attr); | |
e142c38c | 3257 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3258 | if (attr) |
3259 | low = DW_ADDR (attr); | |
3260 | else | |
3261 | /* Found high w/o low attribute. */ | |
3262 | return 0; | |
3263 | ||
3264 | /* Found consecutive range of addresses. */ | |
3265 | ret = 1; | |
3266 | } | |
c906108c | 3267 | else |
af34e669 | 3268 | { |
e142c38c | 3269 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3270 | if (attr != NULL) |
3271 | { | |
af34e669 | 3272 | /* Value of the DW_AT_ranges attribute is the offset in the |
a604369a | 3273 | .debug_ranges section. */ |
ff013f42 | 3274 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, NULL)) |
af34e669 | 3275 | return 0; |
43039443 | 3276 | /* Found discontinuous range of addresses. */ |
af34e669 DJ |
3277 | ret = -1; |
3278 | } | |
3279 | } | |
c906108c SS |
3280 | |
3281 | if (high < low) | |
3282 | return 0; | |
3283 | ||
3284 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3285 | eliminate duplicate copies of functions and vtables and such. | |
3286 | The linker will arbitrarily choose one and discard the others. | |
3287 | The AT_*_pc values for such functions refer to local labels in | |
3288 | these sections. If the section from that file was discarded, the | |
3289 | labels are not in the output, so the relocs get a value of 0. | |
3290 | If this is a discarded function, mark the pc bounds as invalid, | |
3291 | so that GDB will ignore it. */ | |
72dca2f5 | 3292 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3293 | return 0; |
3294 | ||
3295 | *lowpc = low; | |
3296 | *highpc = high; | |
af34e669 | 3297 | return ret; |
c906108c SS |
3298 | } |
3299 | ||
fae299cd DC |
3300 | /* Get the low and high pc's represented by the scope DIE, and store |
3301 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3302 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3303 | ||
3304 | static void | |
3305 | get_scope_pc_bounds (struct die_info *die, | |
3306 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3307 | struct dwarf2_cu *cu) | |
3308 | { | |
3309 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3310 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3311 | CORE_ADDR current_low, current_high; | |
3312 | ||
3313 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3314 | { | |
3315 | best_low = current_low; | |
3316 | best_high = current_high; | |
3317 | } | |
3318 | else | |
3319 | { | |
3320 | struct die_info *child = die->child; | |
3321 | ||
3322 | while (child && child->tag) | |
3323 | { | |
3324 | switch (child->tag) { | |
3325 | case DW_TAG_subprogram: | |
3326 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
3327 | { | |
3328 | best_low = min (best_low, current_low); | |
3329 | best_high = max (best_high, current_high); | |
3330 | } | |
3331 | break; | |
3332 | case DW_TAG_namespace: | |
3333 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3334 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3335 | that current GCC's always emit the DIEs corresponding | |
3336 | to definitions of methods of classes as children of a | |
3337 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3338 | the DIEs giving the declarations, which could be | |
3339 | anywhere). But I don't see any reason why the | |
3340 | standards says that they have to be there. */ | |
3341 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3342 | ||
3343 | if (current_low != ((CORE_ADDR) -1)) | |
3344 | { | |
3345 | best_low = min (best_low, current_low); | |
3346 | best_high = max (best_high, current_high); | |
3347 | } | |
3348 | break; | |
3349 | default: | |
3350 | /* Ignore. */ | |
3351 | break; | |
3352 | } | |
3353 | ||
3354 | child = sibling_die (child); | |
3355 | } | |
3356 | } | |
3357 | ||
3358 | *lowpc = best_low; | |
3359 | *highpc = best_high; | |
3360 | } | |
3361 | ||
801e3a5b JB |
3362 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
3363 | in DIE. */ | |
3364 | static void | |
3365 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, | |
3366 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) | |
3367 | { | |
3368 | struct attribute *attr; | |
3369 | ||
3370 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |
3371 | if (attr) | |
3372 | { | |
3373 | CORE_ADDR high = DW_ADDR (attr); | |
3374 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |
3375 | if (attr) | |
3376 | { | |
3377 | CORE_ADDR low = DW_ADDR (attr); | |
3378 | record_block_range (block, baseaddr + low, baseaddr + high - 1); | |
3379 | } | |
3380 | } | |
3381 | ||
3382 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |
3383 | if (attr) | |
3384 | { | |
3385 | bfd *obfd = cu->objfile->obfd; | |
3386 | ||
3387 | /* The value of the DW_AT_ranges attribute is the offset of the | |
3388 | address range list in the .debug_ranges section. */ | |
3389 | unsigned long offset = DW_UNSND (attr); | |
3390 | gdb_byte *buffer = dwarf2_per_objfile->ranges_buffer + offset; | |
3391 | ||
3392 | /* For some target architectures, but not others, the | |
3393 | read_address function sign-extends the addresses it returns. | |
3394 | To recognize base address selection entries, we need a | |
3395 | mask. */ | |
3396 | unsigned int addr_size = cu->header.addr_size; | |
3397 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3398 | ||
3399 | /* The base address, to which the next pair is relative. Note | |
3400 | that this 'base' is a DWARF concept: most entries in a range | |
3401 | list are relative, to reduce the number of relocs against the | |
3402 | debugging information. This is separate from this function's | |
3403 | 'baseaddr' argument, which GDB uses to relocate debugging | |
3404 | information from a shared library based on the address at | |
3405 | which the library was loaded. */ | |
3406 | CORE_ADDR base = cu->header.base_address; | |
3407 | int base_known = cu->header.base_known; | |
3408 | ||
3409 | if (offset >= dwarf2_per_objfile->ranges_size) | |
3410 | { | |
3411 | complaint (&symfile_complaints, | |
3412 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), | |
3413 | offset); | |
3414 | return; | |
3415 | } | |
3416 | ||
3417 | for (;;) | |
3418 | { | |
3419 | unsigned int bytes_read; | |
3420 | CORE_ADDR start, end; | |
3421 | ||
3422 | start = read_address (obfd, buffer, cu, &bytes_read); | |
3423 | buffer += bytes_read; | |
3424 | end = read_address (obfd, buffer, cu, &bytes_read); | |
3425 | buffer += bytes_read; | |
3426 | ||
3427 | /* Did we find the end of the range list? */ | |
3428 | if (start == 0 && end == 0) | |
3429 | break; | |
3430 | ||
3431 | /* Did we find a base address selection entry? */ | |
3432 | else if ((start & base_select_mask) == base_select_mask) | |
3433 | { | |
3434 | base = end; | |
3435 | base_known = 1; | |
3436 | } | |
3437 | ||
3438 | /* We found an ordinary address range. */ | |
3439 | else | |
3440 | { | |
3441 | if (!base_known) | |
3442 | { | |
3443 | complaint (&symfile_complaints, | |
3444 | _("Invalid .debug_ranges data (no base address)")); | |
3445 | return; | |
3446 | } | |
3447 | ||
3448 | record_block_range (block, | |
3449 | baseaddr + base + start, | |
3450 | baseaddr + base + end - 1); | |
3451 | } | |
3452 | } | |
3453 | } | |
3454 | } | |
3455 | ||
c906108c SS |
3456 | /* Add an aggregate field to the field list. */ |
3457 | ||
3458 | static void | |
107d2387 | 3459 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3460 | struct dwarf2_cu *cu) |
3461 | { | |
3462 | struct objfile *objfile = cu->objfile; | |
5e2b427d | 3463 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
3464 | struct nextfield *new_field; |
3465 | struct attribute *attr; | |
3466 | struct field *fp; | |
3467 | char *fieldname = ""; | |
3468 | ||
3469 | /* Allocate a new field list entry and link it in. */ | |
3470 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3471 | make_cleanup (xfree, new_field); |
c906108c SS |
3472 | memset (new_field, 0, sizeof (struct nextfield)); |
3473 | new_field->next = fip->fields; | |
3474 | fip->fields = new_field; | |
3475 | fip->nfields++; | |
3476 | ||
3477 | /* Handle accessibility and virtuality of field. | |
3478 | The default accessibility for members is public, the default | |
3479 | accessibility for inheritance is private. */ | |
3480 | if (die->tag != DW_TAG_inheritance) | |
3481 | new_field->accessibility = DW_ACCESS_public; | |
3482 | else | |
3483 | new_field->accessibility = DW_ACCESS_private; | |
3484 | new_field->virtuality = DW_VIRTUALITY_none; | |
3485 | ||
e142c38c | 3486 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3487 | if (attr) |
3488 | new_field->accessibility = DW_UNSND (attr); | |
3489 | if (new_field->accessibility != DW_ACCESS_public) | |
3490 | fip->non_public_fields = 1; | |
e142c38c | 3491 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3492 | if (attr) |
3493 | new_field->virtuality = DW_UNSND (attr); | |
3494 | ||
3495 | fp = &new_field->field; | |
a9a9bd0f | 3496 | |
e142c38c | 3497 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3498 | { |
a9a9bd0f DC |
3499 | /* Data member other than a C++ static data member. */ |
3500 | ||
c906108c | 3501 | /* Get type of field. */ |
e7c27a73 | 3502 | fp->type = die_type (die, cu); |
c906108c | 3503 | |
01ad7f36 DJ |
3504 | FIELD_STATIC_KIND (*fp) = 0; |
3505 | ||
c906108c | 3506 | /* Get bit size of field (zero if none). */ |
e142c38c | 3507 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3508 | if (attr) |
3509 | { | |
3510 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3511 | } | |
3512 | else | |
3513 | { | |
3514 | FIELD_BITSIZE (*fp) = 0; | |
3515 | } | |
3516 | ||
3517 | /* Get bit offset of field. */ | |
e142c38c | 3518 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3519 | if (attr) |
3520 | { | |
c6a0999f JB |
3521 | int byte_offset; |
3522 | ||
3690dd37 JB |
3523 | if (attr_form_is_section_offset (attr)) |
3524 | { | |
3525 | dwarf2_complex_location_expr_complaint (); | |
c6a0999f | 3526 | byte_offset = 0; |
3690dd37 JB |
3527 | } |
3528 | else if (attr_form_is_constant (attr)) | |
c6a0999f | 3529 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
3690dd37 | 3530 | else |
c6a0999f JB |
3531 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
3532 | ||
3533 | FIELD_BITPOS (*fp) = byte_offset * bits_per_byte; | |
c906108c SS |
3534 | } |
3535 | else | |
3536 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 3537 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3538 | if (attr) |
3539 | { | |
5e2b427d | 3540 | if (gdbarch_bits_big_endian (gdbarch)) |
c906108c SS |
3541 | { |
3542 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3543 | additional bit offset from the MSB of the containing |
3544 | anonymous object to the MSB of the field. We don't | |
3545 | have to do anything special since we don't need to | |
3546 | know the size of the anonymous object. */ | |
c906108c SS |
3547 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3548 | } | |
3549 | else | |
3550 | { | |
3551 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3552 | MSB of the anonymous object, subtract off the number of |
3553 | bits from the MSB of the field to the MSB of the | |
3554 | object, and then subtract off the number of bits of | |
3555 | the field itself. The result is the bit offset of | |
3556 | the LSB of the field. */ | |
c906108c SS |
3557 | int anonymous_size; |
3558 | int bit_offset = DW_UNSND (attr); | |
3559 | ||
e142c38c | 3560 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3561 | if (attr) |
3562 | { | |
3563 | /* The size of the anonymous object containing | |
3564 | the bit field is explicit, so use the | |
3565 | indicated size (in bytes). */ | |
3566 | anonymous_size = DW_UNSND (attr); | |
3567 | } | |
3568 | else | |
3569 | { | |
3570 | /* The size of the anonymous object containing | |
3571 | the bit field must be inferred from the type | |
3572 | attribute of the data member containing the | |
3573 | bit field. */ | |
3574 | anonymous_size = TYPE_LENGTH (fp->type); | |
3575 | } | |
3576 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3577 | - bit_offset - FIELD_BITSIZE (*fp); | |
3578 | } | |
3579 | } | |
3580 | ||
3581 | /* Get name of field. */ | |
39cbfefa DJ |
3582 | fieldname = dwarf2_name (die, cu); |
3583 | if (fieldname == NULL) | |
3584 | fieldname = ""; | |
d8151005 DJ |
3585 | |
3586 | /* The name is already allocated along with this objfile, so we don't | |
3587 | need to duplicate it for the type. */ | |
3588 | fp->name = fieldname; | |
c906108c SS |
3589 | |
3590 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3591 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3592 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3593 | { |
3594 | new_field->accessibility = DW_ACCESS_private; | |
3595 | fip->non_public_fields = 1; | |
3596 | } | |
3597 | } | |
a9a9bd0f | 3598 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3599 | { |
a9a9bd0f DC |
3600 | /* C++ static member. */ |
3601 | ||
3602 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3603 | is a declaration, but all versions of G++ as of this writing | |
3604 | (so through at least 3.2.1) incorrectly generate | |
3605 | DW_TAG_variable tags. */ | |
3606 | ||
c906108c | 3607 | char *physname; |
c906108c | 3608 | |
a9a9bd0f | 3609 | /* Get name of field. */ |
39cbfefa DJ |
3610 | fieldname = dwarf2_name (die, cu); |
3611 | if (fieldname == NULL) | |
c906108c SS |
3612 | return; |
3613 | ||
2df3850c | 3614 | /* Get physical name. */ |
e142c38c | 3615 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3616 | |
d8151005 DJ |
3617 | /* The name is already allocated along with this objfile, so we don't |
3618 | need to duplicate it for the type. */ | |
3619 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3620 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3621 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3622 | } |
3623 | else if (die->tag == DW_TAG_inheritance) | |
3624 | { | |
3625 | /* C++ base class field. */ | |
e142c38c | 3626 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3627 | if (attr) |
e7c27a73 | 3628 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 3629 | * bits_per_byte); |
c906108c | 3630 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 3631 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 3632 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3633 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3634 | fip->nbaseclasses++; | |
3635 | } | |
3636 | } | |
3637 | ||
3638 | /* Create the vector of fields, and attach it to the type. */ | |
3639 | ||
3640 | static void | |
fba45db2 | 3641 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3642 | struct dwarf2_cu *cu) |
c906108c SS |
3643 | { |
3644 | int nfields = fip->nfields; | |
3645 | ||
3646 | /* Record the field count, allocate space for the array of fields, | |
3647 | and create blank accessibility bitfields if necessary. */ | |
3648 | TYPE_NFIELDS (type) = nfields; | |
3649 | TYPE_FIELDS (type) = (struct field *) | |
3650 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3651 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3652 | ||
3653 | if (fip->non_public_fields) | |
3654 | { | |
3655 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3656 | ||
3657 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3658 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3659 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3660 | ||
3661 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3662 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3663 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3664 | ||
3665 | TYPE_FIELD_IGNORE_BITS (type) = | |
3666 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3667 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3668 | } | |
3669 | ||
3670 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3671 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3672 | if (fip->nbaseclasses) | |
3673 | { | |
3674 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 3675 | unsigned char *pointer; |
c906108c SS |
3676 | |
3677 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
3678 | pointer = TYPE_ALLOC (type, num_bytes); |
3679 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
3680 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
3681 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3682 | } | |
3683 | ||
3684 | /* Copy the saved-up fields into the field vector. Start from the head | |
3685 | of the list, adding to the tail of the field array, so that they end | |
3686 | up in the same order in the array in which they were added to the list. */ | |
3687 | while (nfields-- > 0) | |
3688 | { | |
3689 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3690 | switch (fip->fields->accessibility) | |
3691 | { | |
c5aa993b JM |
3692 | case DW_ACCESS_private: |
3693 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3694 | break; | |
c906108c | 3695 | |
c5aa993b JM |
3696 | case DW_ACCESS_protected: |
3697 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3698 | break; | |
c906108c | 3699 | |
c5aa993b JM |
3700 | case DW_ACCESS_public: |
3701 | break; | |
c906108c | 3702 | |
c5aa993b JM |
3703 | default: |
3704 | /* Unknown accessibility. Complain and treat it as public. */ | |
3705 | { | |
e2e0b3e5 | 3706 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 3707 | fip->fields->accessibility); |
c5aa993b JM |
3708 | } |
3709 | break; | |
c906108c SS |
3710 | } |
3711 | if (nfields < fip->nbaseclasses) | |
3712 | { | |
3713 | switch (fip->fields->virtuality) | |
3714 | { | |
c5aa993b JM |
3715 | case DW_VIRTUALITY_virtual: |
3716 | case DW_VIRTUALITY_pure_virtual: | |
3717 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3718 | break; | |
c906108c SS |
3719 | } |
3720 | } | |
3721 | fip->fields = fip->fields->next; | |
3722 | } | |
3723 | } | |
3724 | ||
c906108c SS |
3725 | /* Add a member function to the proper fieldlist. */ |
3726 | ||
3727 | static void | |
107d2387 | 3728 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3729 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3730 | { |
e7c27a73 | 3731 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3732 | struct attribute *attr; |
3733 | struct fnfieldlist *flp; | |
3734 | int i; | |
3735 | struct fn_field *fnp; | |
3736 | char *fieldname; | |
3737 | char *physname; | |
3738 | struct nextfnfield *new_fnfield; | |
f792889a | 3739 | struct type *this_type; |
c906108c | 3740 | |
2df3850c | 3741 | /* Get name of member function. */ |
39cbfefa DJ |
3742 | fieldname = dwarf2_name (die, cu); |
3743 | if (fieldname == NULL) | |
2df3850c | 3744 | return; |
c906108c | 3745 | |
2df3850c | 3746 | /* Get the mangled name. */ |
e142c38c | 3747 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3748 | |
3749 | /* Look up member function name in fieldlist. */ | |
3750 | for (i = 0; i < fip->nfnfields; i++) | |
3751 | { | |
27bfe10e | 3752 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3753 | break; |
3754 | } | |
3755 | ||
3756 | /* Create new list element if necessary. */ | |
3757 | if (i < fip->nfnfields) | |
3758 | flp = &fip->fnfieldlists[i]; | |
3759 | else | |
3760 | { | |
3761 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3762 | { | |
3763 | fip->fnfieldlists = (struct fnfieldlist *) | |
3764 | xrealloc (fip->fnfieldlists, | |
3765 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3766 | * sizeof (struct fnfieldlist)); |
c906108c | 3767 | if (fip->nfnfields == 0) |
c13c43fd | 3768 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3769 | } |
3770 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3771 | flp->name = fieldname; | |
3772 | flp->length = 0; | |
3773 | flp->head = NULL; | |
3774 | fip->nfnfields++; | |
3775 | } | |
3776 | ||
3777 | /* Create a new member function field and chain it to the field list | |
3778 | entry. */ | |
3779 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3780 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3781 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3782 | new_fnfield->next = flp->head; | |
3783 | flp->head = new_fnfield; | |
3784 | flp->length++; | |
3785 | ||
3786 | /* Fill in the member function field info. */ | |
3787 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3788 | /* The name is already allocated along with this objfile, so we don't |
3789 | need to duplicate it for the type. */ | |
3790 | fnp->physname = physname ? physname : ""; | |
c906108c | 3791 | fnp->type = alloc_type (objfile); |
f792889a DJ |
3792 | this_type = read_type_die (die, cu); |
3793 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) | |
c906108c | 3794 | { |
f792889a | 3795 | int nparams = TYPE_NFIELDS (this_type); |
c906108c | 3796 | |
f792889a | 3797 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
e26fb1d7 DC |
3798 | of the method itself (TYPE_CODE_METHOD). */ |
3799 | smash_to_method_type (fnp->type, type, | |
f792889a DJ |
3800 | TYPE_TARGET_TYPE (this_type), |
3801 | TYPE_FIELDS (this_type), | |
3802 | TYPE_NFIELDS (this_type), | |
3803 | TYPE_VARARGS (this_type)); | |
c906108c SS |
3804 | |
3805 | /* Handle static member functions. | |
c5aa993b JM |
3806 | Dwarf2 has no clean way to discern C++ static and non-static |
3807 | member functions. G++ helps GDB by marking the first | |
3808 | parameter for non-static member functions (which is the | |
3809 | this pointer) as artificial. We obtain this information | |
3810 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
f792889a | 3811 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
c906108c SS |
3812 | fnp->voffset = VOFFSET_STATIC; |
3813 | } | |
3814 | else | |
e2e0b3e5 | 3815 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 3816 | physname); |
c906108c SS |
3817 | |
3818 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3819 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3820 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3821 | |
3822 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3823 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3824 | ||
3825 | /* Get accessibility. */ | |
e142c38c | 3826 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3827 | if (attr) |
3828 | { | |
3829 | switch (DW_UNSND (attr)) | |
3830 | { | |
c5aa993b JM |
3831 | case DW_ACCESS_private: |
3832 | fnp->is_private = 1; | |
3833 | break; | |
3834 | case DW_ACCESS_protected: | |
3835 | fnp->is_protected = 1; | |
3836 | break; | |
c906108c SS |
3837 | } |
3838 | } | |
3839 | ||
b02dede2 | 3840 | /* Check for artificial methods. */ |
e142c38c | 3841 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3842 | if (attr && DW_UNSND (attr) != 0) |
3843 | fnp->is_artificial = 1; | |
3844 | ||
c906108c | 3845 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3846 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3847 | if (attr) |
8e19ed76 PS |
3848 | { |
3849 | /* Support the .debug_loc offsets */ | |
3850 | if (attr_form_is_block (attr)) | |
3851 | { | |
e7c27a73 | 3852 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 | 3853 | } |
3690dd37 | 3854 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 3855 | { |
4d3c2250 | 3856 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3857 | } |
3858 | else | |
3859 | { | |
4d3c2250 KB |
3860 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3861 | fieldname); | |
8e19ed76 PS |
3862 | } |
3863 | } | |
c906108c SS |
3864 | } |
3865 | ||
3866 | /* Create the vector of member function fields, and attach it to the type. */ | |
3867 | ||
3868 | static void | |
fba45db2 | 3869 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3870 | struct dwarf2_cu *cu) |
c906108c SS |
3871 | { |
3872 | struct fnfieldlist *flp; | |
3873 | int total_length = 0; | |
3874 | int i; | |
3875 | ||
3876 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3877 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3878 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3879 | ||
3880 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3881 | { | |
3882 | struct nextfnfield *nfp = flp->head; | |
3883 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3884 | int k; | |
3885 | ||
3886 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3887 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3888 | fn_flp->fn_fields = (struct fn_field *) | |
3889 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3890 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3891 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3892 | |
3893 | total_length += flp->length; | |
3894 | } | |
3895 | ||
3896 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3897 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3898 | } | |
3899 | ||
1168df01 JB |
3900 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
3901 | language, zero otherwise. */ | |
3902 | static int | |
3903 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
3904 | { | |
3905 | static const char vptr[] = "_vptr"; | |
987504bb | 3906 | static const char vtable[] = "vtable"; |
1168df01 | 3907 | |
987504bb JJ |
3908 | /* Look for the C++ and Java forms of the vtable. */ |
3909 | if ((cu->language == language_java | |
3910 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
3911 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
3912 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
3913 | return 1; |
3914 | ||
3915 | return 0; | |
3916 | } | |
3917 | ||
c0dd20ea DJ |
3918 | /* GCC outputs unnamed structures that are really pointers to member |
3919 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
3920 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
3921 | zero. |
3922 | ||
3923 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
3924 | This is GCC PR debug/28767. */ | |
c0dd20ea | 3925 | |
f792889a | 3926 | static struct type * |
c0dd20ea DJ |
3927 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) |
3928 | { | |
3929 | struct objfile *objfile = cu->objfile; | |
3930 | struct type *type; | |
3931 | struct die_info *pfn_die, *delta_die; | |
3932 | struct attribute *pfn_name, *delta_name; | |
3933 | struct type *pfn_type, *domain_type; | |
3934 | ||
3935 | /* Check for a structure with no name and two children. */ | |
3936 | if (die->tag != DW_TAG_structure_type | |
3937 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
3938 | || die->child == NULL | |
3939 | || die->child->sibling == NULL | |
3940 | || (die->child->sibling->sibling != NULL | |
3941 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
f792889a | 3942 | return NULL; |
c0dd20ea DJ |
3943 | |
3944 | /* Check for __pfn and __delta members. */ | |
3945 | pfn_die = die->child; | |
3946 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
3947 | if (pfn_die->tag != DW_TAG_member | |
3948 | || pfn_name == NULL | |
3949 | || DW_STRING (pfn_name) == NULL | |
3950 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
f792889a | 3951 | return NULL; |
c0dd20ea DJ |
3952 | |
3953 | delta_die = pfn_die->sibling; | |
3954 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
3955 | if (delta_die->tag != DW_TAG_member | |
3956 | || delta_name == NULL | |
3957 | || DW_STRING (delta_name) == NULL | |
3958 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
f792889a | 3959 | return NULL; |
c0dd20ea DJ |
3960 | |
3961 | /* Find the type of the method. */ | |
3962 | pfn_type = die_type (pfn_die, cu); | |
3963 | if (pfn_type == NULL | |
3964 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
3965 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
f792889a | 3966 | return NULL; |
c0dd20ea DJ |
3967 | |
3968 | /* Look for the "this" argument. */ | |
3969 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
3970 | if (TYPE_NFIELDS (pfn_type) == 0 | |
3971 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
f792889a | 3972 | return NULL; |
c0dd20ea DJ |
3973 | |
3974 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
3975 | type = alloc_type (objfile); | |
3976 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
3977 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
3978 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 3979 | type = lookup_methodptr_type (type); |
f792889a | 3980 | return set_die_type (die, type, cu); |
c0dd20ea | 3981 | } |
1168df01 | 3982 | |
c906108c SS |
3983 | /* Called when we find the DIE that starts a structure or union scope |
3984 | (definition) to process all dies that define the members of the | |
3985 | structure or union. | |
3986 | ||
3987 | NOTE: we need to call struct_type regardless of whether or not the | |
3988 | DIE has an at_name attribute, since it might be an anonymous | |
3989 | structure or union. This gets the type entered into our set of | |
3990 | user defined types. | |
3991 | ||
3992 | However, if the structure is incomplete (an opaque struct/union) | |
3993 | then suppress creating a symbol table entry for it since gdb only | |
3994 | wants to find the one with the complete definition. Note that if | |
3995 | it is complete, we just call new_symbol, which does it's own | |
3996 | checking about whether the struct/union is anonymous or not (and | |
3997 | suppresses creating a symbol table entry itself). */ | |
3998 | ||
f792889a | 3999 | static struct type * |
134d01f1 | 4000 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4001 | { |
e7c27a73 | 4002 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4003 | struct type *type; |
4004 | struct attribute *attr; | |
63d06c5c DC |
4005 | const char *previous_prefix = processing_current_prefix; |
4006 | struct cleanup *back_to = NULL; | |
39cbfefa | 4007 | char *name; |
c906108c | 4008 | |
f792889a DJ |
4009 | type = quirk_gcc_member_function_pointer (die, cu); |
4010 | if (type) | |
4011 | return type; | |
c906108c | 4012 | |
c0dd20ea | 4013 | type = alloc_type (objfile); |
c906108c | 4014 | INIT_CPLUS_SPECIFIC (type); |
39cbfefa DJ |
4015 | name = dwarf2_name (die, cu); |
4016 | if (name != NULL) | |
c906108c | 4017 | { |
987504bb JJ |
4018 | if (cu->language == language_cplus |
4019 | || cu->language == language_java) | |
63d06c5c | 4020 | { |
8176b9b8 DC |
4021 | char *new_prefix = determine_class_name (die, cu); |
4022 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
4023 | strlen (new_prefix), | |
4024 | &objfile->objfile_obstack); | |
4025 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
4026 | processing_current_prefix = new_prefix; |
4027 | } | |
4028 | else | |
4029 | { | |
d8151005 DJ |
4030 | /* The name is already allocated along with this objfile, so |
4031 | we don't need to duplicate it for the type. */ | |
39cbfefa | 4032 | TYPE_TAG_NAME (type) = name; |
63d06c5c | 4033 | } |
c906108c SS |
4034 | } |
4035 | ||
4036 | if (die->tag == DW_TAG_structure_type) | |
4037 | { | |
4038 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
4039 | } | |
4040 | else if (die->tag == DW_TAG_union_type) | |
4041 | { | |
4042 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
4043 | } | |
4044 | else | |
4045 | { | |
4046 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 4047 | in gdbtypes.h. */ |
c906108c SS |
4048 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
4049 | } | |
4050 | ||
e142c38c | 4051 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4052 | if (attr) |
4053 | { | |
4054 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4055 | } | |
4056 | else | |
4057 | { | |
4058 | TYPE_LENGTH (type) = 0; | |
4059 | } | |
4060 | ||
d77b6808 | 4061 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB_SUPPORTED; |
dc718098 JB |
4062 | if (die_is_declaration (die, cu)) |
4063 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4064 | ||
c906108c SS |
4065 | /* We need to add the type field to the die immediately so we don't |
4066 | infinitely recurse when dealing with pointers to the structure | |
4067 | type within the structure itself. */ | |
1c379e20 | 4068 | set_die_type (die, type, cu); |
c906108c | 4069 | |
e142c38c | 4070 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
4071 | { |
4072 | struct field_info fi; | |
4073 | struct die_info *child_die; | |
4074 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
4075 | ||
4076 | memset (&fi, 0, sizeof (struct field_info)); | |
4077 | ||
639d11d3 | 4078 | child_die = die->child; |
c906108c SS |
4079 | |
4080 | while (child_die && child_die->tag) | |
4081 | { | |
a9a9bd0f DC |
4082 | if (child_die->tag == DW_TAG_member |
4083 | || child_die->tag == DW_TAG_variable) | |
c906108c | 4084 | { |
a9a9bd0f DC |
4085 | /* NOTE: carlton/2002-11-05: A C++ static data member |
4086 | should be a DW_TAG_member that is a declaration, but | |
4087 | all versions of G++ as of this writing (so through at | |
4088 | least 3.2.1) incorrectly generate DW_TAG_variable | |
4089 | tags for them instead. */ | |
e7c27a73 | 4090 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4091 | } |
8713b1b1 | 4092 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
4093 | { |
4094 | /* C++ member function. */ | |
e7c27a73 | 4095 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
4096 | } |
4097 | else if (child_die->tag == DW_TAG_inheritance) | |
4098 | { | |
4099 | /* C++ base class field. */ | |
e7c27a73 | 4100 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 4101 | } |
c906108c SS |
4102 | child_die = sibling_die (child_die); |
4103 | } | |
4104 | ||
4105 | /* Attach fields and member functions to the type. */ | |
4106 | if (fi.nfields) | |
e7c27a73 | 4107 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
4108 | if (fi.nfnfields) |
4109 | { | |
e7c27a73 | 4110 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 4111 | |
c5aa993b | 4112 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
4113 | class itself) which contains the vtable pointer for the current |
4114 | class from the DW_AT_containing_type attribute. */ | |
4115 | ||
e142c38c | 4116 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 4117 | { |
e7c27a73 | 4118 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
4119 | |
4120 | TYPE_VPTR_BASETYPE (type) = t; | |
4121 | if (type == t) | |
4122 | { | |
c906108c SS |
4123 | int i; |
4124 | ||
4125 | /* Our own class provides vtbl ptr. */ | |
4126 | for (i = TYPE_NFIELDS (t) - 1; | |
4127 | i >= TYPE_N_BASECLASSES (t); | |
4128 | --i) | |
4129 | { | |
4130 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
4131 | ||
1168df01 | 4132 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
4133 | { |
4134 | TYPE_VPTR_FIELDNO (type) = i; | |
4135 | break; | |
4136 | } | |
4137 | } | |
4138 | ||
4139 | /* Complain if virtual function table field not found. */ | |
4140 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 4141 | complaint (&symfile_complaints, |
e2e0b3e5 | 4142 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
4143 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
4144 | ""); | |
c906108c SS |
4145 | } |
4146 | else | |
4147 | { | |
4148 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
4149 | } | |
4150 | } | |
f6235d4c EZ |
4151 | else if (cu->producer |
4152 | && strncmp (cu->producer, | |
4153 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
4154 | { | |
4155 | /* The IBM XLC compiler does not provide direct indication | |
4156 | of the containing type, but the vtable pointer is | |
4157 | always named __vfp. */ | |
4158 | ||
4159 | int i; | |
4160 | ||
4161 | for (i = TYPE_NFIELDS (type) - 1; | |
4162 | i >= TYPE_N_BASECLASSES (type); | |
4163 | --i) | |
4164 | { | |
4165 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
4166 | { | |
4167 | TYPE_VPTR_FIELDNO (type) = i; | |
4168 | TYPE_VPTR_BASETYPE (type) = type; | |
4169 | break; | |
4170 | } | |
4171 | } | |
4172 | } | |
c906108c SS |
4173 | } |
4174 | ||
c906108c SS |
4175 | do_cleanups (back_to); |
4176 | } | |
63d06c5c DC |
4177 | |
4178 | processing_current_prefix = previous_prefix; | |
4179 | if (back_to != NULL) | |
4180 | do_cleanups (back_to); | |
f792889a DJ |
4181 | |
4182 | return type; | |
c906108c SS |
4183 | } |
4184 | ||
134d01f1 DJ |
4185 | static void |
4186 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4187 | { | |
4188 | struct objfile *objfile = cu->objfile; | |
4189 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 4190 | struct die_info *child_die = die->child; |
f792889a | 4191 | struct type *this_type; |
c906108c | 4192 | |
f792889a DJ |
4193 | this_type = get_die_type (die, cu); |
4194 | if (this_type == NULL) | |
4195 | this_type = read_structure_type (die, cu); | |
4196 | if (TYPE_TAG_NAME (this_type) != NULL) | |
4197 | processing_current_prefix = TYPE_TAG_NAME (this_type); | |
c906108c | 4198 | |
90aeadfc DC |
4199 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4200 | snapshots) has been known to create a die giving a declaration | |
4201 | for a class that has, as a child, a die giving a definition for a | |
4202 | nested class. So we have to process our children even if the | |
4203 | current die is a declaration. Normally, of course, a declaration | |
4204 | won't have any children at all. */ | |
134d01f1 | 4205 | |
90aeadfc DC |
4206 | while (child_die != NULL && child_die->tag) |
4207 | { | |
4208 | if (child_die->tag == DW_TAG_member | |
4209 | || child_die->tag == DW_TAG_variable | |
4210 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4211 | { |
90aeadfc | 4212 | /* Do nothing. */ |
134d01f1 | 4213 | } |
90aeadfc DC |
4214 | else |
4215 | process_die (child_die, cu); | |
134d01f1 | 4216 | |
90aeadfc | 4217 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4218 | } |
4219 | ||
fa4028e9 JB |
4220 | /* Do not consider external references. According to the DWARF standard, |
4221 | these DIEs are identified by the fact that they have no byte_size | |
4222 | attribute, and a declaration attribute. */ | |
4223 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4224 | || !die_is_declaration (die, cu)) | |
f792889a | 4225 | new_symbol (die, this_type, cu); |
90aeadfc | 4226 | |
134d01f1 DJ |
4227 | processing_current_prefix = previous_prefix; |
4228 | } | |
4229 | ||
4230 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4231 | complete the type's fields yet, or create any symbols. */ | |
c906108c | 4232 | |
f792889a | 4233 | static struct type * |
134d01f1 | 4234 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4235 | { |
e7c27a73 | 4236 | struct objfile *objfile = cu->objfile; |
c906108c | 4237 | struct type *type; |
c906108c | 4238 | struct attribute *attr; |
39cbfefa | 4239 | char *name; |
134d01f1 | 4240 | |
c906108c SS |
4241 | type = alloc_type (objfile); |
4242 | ||
4243 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
39cbfefa DJ |
4244 | name = dwarf2_name (die, cu); |
4245 | if (name != NULL) | |
c906108c | 4246 | { |
63d06c5c DC |
4247 | if (processing_has_namespace_info) |
4248 | { | |
987504bb JJ |
4249 | TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack, |
4250 | processing_current_prefix, | |
4251 | name, cu); | |
63d06c5c DC |
4252 | } |
4253 | else | |
4254 | { | |
d8151005 DJ |
4255 | /* The name is already allocated along with this objfile, so |
4256 | we don't need to duplicate it for the type. */ | |
4257 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 4258 | } |
c906108c SS |
4259 | } |
4260 | ||
e142c38c | 4261 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4262 | if (attr) |
4263 | { | |
4264 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4265 | } | |
4266 | else | |
4267 | { | |
4268 | TYPE_LENGTH (type) = 0; | |
4269 | } | |
4270 | ||
137033e9 JB |
4271 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
4272 | declared as private in the package spec, and then defined only | |
4273 | inside the package body. Such types are known as Taft Amendment | |
4274 | Types. When another package uses such a type, an incomplete DIE | |
4275 | may be generated by the compiler. */ | |
02eb380e JB |
4276 | if (die_is_declaration (die, cu)) |
4277 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
4278 | ||
f792889a | 4279 | return set_die_type (die, type, cu); |
134d01f1 DJ |
4280 | } |
4281 | ||
8176b9b8 | 4282 | /* Determine the name of the type represented by DIE, which should be |
987504bb | 4283 | a named C++ or Java compound type. Return the name in question; the caller |
8176b9b8 DC |
4284 | is responsible for xfree()'ing it. */ |
4285 | ||
4286 | static char * | |
4287 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
4288 | { | |
4289 | struct cleanup *back_to = NULL; | |
4290 | struct die_info *spec_die = die_specification (die, cu); | |
4291 | char *new_prefix = NULL; | |
4292 | ||
4293 | /* If this is the definition of a class that is declared by another | |
4294 | die, then processing_current_prefix may not be accurate; see | |
4295 | read_func_scope for a similar example. */ | |
4296 | if (spec_die != NULL) | |
4297 | { | |
4298 | char *specification_prefix = determine_prefix (spec_die, cu); | |
4299 | processing_current_prefix = specification_prefix; | |
4300 | back_to = make_cleanup (xfree, specification_prefix); | |
4301 | } | |
4302 | ||
4303 | /* If we don't have namespace debug info, guess the name by trying | |
4304 | to demangle the names of members, just like we did in | |
72bf9492 | 4305 | guess_structure_name. */ |
8176b9b8 DC |
4306 | if (!processing_has_namespace_info) |
4307 | { | |
4308 | struct die_info *child; | |
4309 | ||
4310 | for (child = die->child; | |
4311 | child != NULL && child->tag != 0; | |
4312 | child = sibling_die (child)) | |
4313 | { | |
4314 | if (child->tag == DW_TAG_subprogram) | |
4315 | { | |
31c27f77 JJ |
4316 | new_prefix |
4317 | = language_class_name_from_physname (cu->language_defn, | |
4318 | dwarf2_linkage_name | |
8176b9b8 DC |
4319 | (child, cu)); |
4320 | ||
4321 | if (new_prefix != NULL) | |
4322 | break; | |
4323 | } | |
4324 | } | |
4325 | } | |
4326 | ||
4327 | if (new_prefix == NULL) | |
4328 | { | |
4329 | const char *name = dwarf2_name (die, cu); | |
987504bb JJ |
4330 | new_prefix = typename_concat (NULL, processing_current_prefix, |
4331 | name ? name : "<<anonymous>>", | |
4332 | cu); | |
8176b9b8 DC |
4333 | } |
4334 | ||
4335 | if (back_to != NULL) | |
4336 | do_cleanups (back_to); | |
4337 | ||
4338 | return new_prefix; | |
4339 | } | |
4340 | ||
134d01f1 DJ |
4341 | /* Given a pointer to a die which begins an enumeration, process all |
4342 | the dies that define the members of the enumeration, and create the | |
4343 | symbol for the enumeration type. | |
4344 | ||
4345 | NOTE: We reverse the order of the element list. */ | |
4346 | ||
4347 | static void | |
4348 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4349 | { | |
4350 | struct objfile *objfile = cu->objfile; | |
4351 | struct die_info *child_die; | |
4352 | struct field *fields; | |
134d01f1 DJ |
4353 | struct symbol *sym; |
4354 | int num_fields; | |
4355 | int unsigned_enum = 1; | |
39cbfefa | 4356 | char *name; |
f792889a | 4357 | struct type *this_type; |
134d01f1 | 4358 | |
c906108c SS |
4359 | num_fields = 0; |
4360 | fields = NULL; | |
f792889a DJ |
4361 | this_type = get_die_type (die, cu); |
4362 | if (this_type == NULL) | |
4363 | this_type = read_enumeration_type (die, cu); | |
639d11d3 | 4364 | if (die->child != NULL) |
c906108c | 4365 | { |
639d11d3 | 4366 | child_die = die->child; |
c906108c SS |
4367 | while (child_die && child_die->tag) |
4368 | { | |
4369 | if (child_die->tag != DW_TAG_enumerator) | |
4370 | { | |
e7c27a73 | 4371 | process_die (child_die, cu); |
c906108c SS |
4372 | } |
4373 | else | |
4374 | { | |
39cbfefa DJ |
4375 | name = dwarf2_name (child_die, cu); |
4376 | if (name) | |
c906108c | 4377 | { |
f792889a | 4378 | sym = new_symbol (child_die, this_type, cu); |
c906108c SS |
4379 | if (SYMBOL_VALUE (sym) < 0) |
4380 | unsigned_enum = 0; | |
4381 | ||
4382 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4383 | { | |
4384 | fields = (struct field *) | |
4385 | xrealloc (fields, | |
4386 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4387 | * sizeof (struct field)); |
c906108c SS |
4388 | } |
4389 | ||
22abf04a | 4390 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
4391 | FIELD_TYPE (fields[num_fields]) = NULL; |
4392 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
4393 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 4394 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
4395 | |
4396 | num_fields++; | |
4397 | } | |
4398 | } | |
4399 | ||
4400 | child_die = sibling_die (child_die); | |
4401 | } | |
4402 | ||
4403 | if (num_fields) | |
4404 | { | |
f792889a DJ |
4405 | TYPE_NFIELDS (this_type) = num_fields; |
4406 | TYPE_FIELDS (this_type) = (struct field *) | |
4407 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); | |
4408 | memcpy (TYPE_FIELDS (this_type), fields, | |
c906108c | 4409 | sizeof (struct field) * num_fields); |
b8c9b27d | 4410 | xfree (fields); |
c906108c SS |
4411 | } |
4412 | if (unsigned_enum) | |
f792889a | 4413 | TYPE_FLAGS (this_type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 4414 | } |
134d01f1 | 4415 | |
f792889a | 4416 | new_symbol (die, this_type, cu); |
c906108c SS |
4417 | } |
4418 | ||
4419 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4420 | the DIE's type field. For now, this only handles one dimensional | |
4421 | arrays. */ | |
4422 | ||
f792889a | 4423 | static struct type * |
e7c27a73 | 4424 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4425 | { |
e7c27a73 | 4426 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4427 | struct die_info *child_die; |
4428 | struct type *type = NULL; | |
4429 | struct type *element_type, *range_type, *index_type; | |
4430 | struct type **range_types = NULL; | |
4431 | struct attribute *attr; | |
4432 | int ndim = 0; | |
4433 | struct cleanup *back_to; | |
39cbfefa | 4434 | char *name; |
c906108c | 4435 | |
e7c27a73 | 4436 | element_type = die_type (die, cu); |
c906108c SS |
4437 | |
4438 | /* Irix 6.2 native cc creates array types without children for | |
4439 | arrays with unspecified length. */ | |
639d11d3 | 4440 | if (die->child == NULL) |
c906108c | 4441 | { |
6ccb9162 | 4442 | index_type = builtin_type_int32; |
c906108c | 4443 | range_type = create_range_type (NULL, index_type, 0, -1); |
f792889a DJ |
4444 | type = create_array_type (NULL, element_type, range_type); |
4445 | return set_die_type (die, type, cu); | |
c906108c SS |
4446 | } |
4447 | ||
4448 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4449 | child_die = die->child; |
c906108c SS |
4450 | while (child_die && child_die->tag) |
4451 | { | |
4452 | if (child_die->tag == DW_TAG_subrange_type) | |
4453 | { | |
f792889a DJ |
4454 | struct type *child_type = read_type_die (child_die, cu); |
4455 | if (child_type != NULL) | |
a02abb62 JB |
4456 | { |
4457 | /* The range type was succesfully read. Save it for | |
4458 | the array type creation. */ | |
4459 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4460 | { | |
4461 | range_types = (struct type **) | |
4462 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4463 | * sizeof (struct type *)); | |
4464 | if (ndim == 0) | |
4465 | make_cleanup (free_current_contents, &range_types); | |
4466 | } | |
f792889a | 4467 | range_types[ndim++] = child_type; |
a02abb62 | 4468 | } |
c906108c SS |
4469 | } |
4470 | child_die = sibling_die (child_die); | |
4471 | } | |
4472 | ||
4473 | /* Dwarf2 dimensions are output from left to right, create the | |
4474 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4475 | |
c906108c | 4476 | type = element_type; |
7ca2d3a3 DL |
4477 | |
4478 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4479 | { | |
4480 | int i = 0; | |
4481 | while (i < ndim) | |
4482 | type = create_array_type (NULL, type, range_types[i++]); | |
4483 | } | |
4484 | else | |
4485 | { | |
4486 | while (ndim-- > 0) | |
4487 | type = create_array_type (NULL, type, range_types[ndim]); | |
4488 | } | |
c906108c | 4489 | |
f5f8a009 EZ |
4490 | /* Understand Dwarf2 support for vector types (like they occur on |
4491 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4492 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4493 | custom vendor extension. The main difference between a regular | |
4494 | array and the vector variant is that vectors are passed by value | |
4495 | to functions. */ | |
e142c38c | 4496 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 | 4497 | if (attr) |
ea37ba09 | 4498 | make_vector_type (type); |
f5f8a009 | 4499 | |
39cbfefa DJ |
4500 | name = dwarf2_name (die, cu); |
4501 | if (name) | |
4502 | TYPE_NAME (type) = name; | |
714e295e | 4503 | |
c906108c SS |
4504 | do_cleanups (back_to); |
4505 | ||
4506 | /* Install the type in the die. */ | |
f792889a | 4507 | return set_die_type (die, type, cu); |
c906108c SS |
4508 | } |
4509 | ||
7ca2d3a3 DL |
4510 | static enum dwarf_array_dim_ordering |
4511 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4512 | { | |
4513 | struct attribute *attr; | |
4514 | ||
4515 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4516 | ||
4517 | if (attr) return DW_SND (attr); | |
4518 | ||
4519 | /* | |
4520 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4521 | opposite order to the dwarf2 specification, but data is still | |
4522 | laid out as per normal fortran. | |
4523 | ||
4524 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4525 | version checking. | |
4526 | */ | |
4527 | ||
4528 | if (cu->language == language_fortran && | |
4529 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4530 | { | |
4531 | return DW_ORD_row_major; | |
4532 | } | |
4533 | ||
4534 | switch (cu->language_defn->la_array_ordering) | |
4535 | { | |
4536 | case array_column_major: | |
4537 | return DW_ORD_col_major; | |
4538 | case array_row_major: | |
4539 | default: | |
4540 | return DW_ORD_row_major; | |
4541 | }; | |
4542 | } | |
4543 | ||
72019c9c GM |
4544 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4545 | the DIE's type field. */ | |
4546 | ||
f792889a | 4547 | static struct type * |
72019c9c GM |
4548 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
4549 | { | |
f792889a DJ |
4550 | struct type *set_type = create_set_type (NULL, die_type (die, cu)); |
4551 | ||
4552 | return set_die_type (die, set_type, cu); | |
72019c9c | 4553 | } |
7ca2d3a3 | 4554 | |
c906108c SS |
4555 | /* First cut: install each common block member as a global variable. */ |
4556 | ||
4557 | static void | |
e7c27a73 | 4558 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4559 | { |
4560 | struct die_info *child_die; | |
4561 | struct attribute *attr; | |
4562 | struct symbol *sym; | |
4563 | CORE_ADDR base = (CORE_ADDR) 0; | |
4564 | ||
e142c38c | 4565 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4566 | if (attr) |
4567 | { | |
8e19ed76 PS |
4568 | /* Support the .debug_loc offsets */ |
4569 | if (attr_form_is_block (attr)) | |
4570 | { | |
e7c27a73 | 4571 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 | 4572 | } |
3690dd37 | 4573 | else if (attr_form_is_section_offset (attr)) |
8e19ed76 | 4574 | { |
4d3c2250 | 4575 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4576 | } |
4577 | else | |
4578 | { | |
4d3c2250 KB |
4579 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4580 | "common block member"); | |
8e19ed76 | 4581 | } |
c906108c | 4582 | } |
639d11d3 | 4583 | if (die->child != NULL) |
c906108c | 4584 | { |
639d11d3 | 4585 | child_die = die->child; |
c906108c SS |
4586 | while (child_die && child_die->tag) |
4587 | { | |
e7c27a73 | 4588 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4589 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4590 | if (attr) |
4591 | { | |
4592 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4593 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4594 | add_symbol_to_list (sym, &global_symbols); |
4595 | } | |
4596 | child_die = sibling_die (child_die); | |
4597 | } | |
4598 | } | |
4599 | } | |
4600 | ||
d9fa45fe DC |
4601 | /* Read a C++ namespace. */ |
4602 | ||
d9fa45fe | 4603 | static void |
e7c27a73 | 4604 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 4605 | { |
e7c27a73 | 4606 | struct objfile *objfile = cu->objfile; |
38d518c9 | 4607 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 4608 | const char *name; |
9219021c DC |
4609 | int is_anonymous; |
4610 | struct die_info *current_die; | |
987504bb | 4611 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
9219021c | 4612 | |
e142c38c | 4613 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4614 | |
4615 | /* Now build the name of the current namespace. */ | |
4616 | ||
38d518c9 | 4617 | if (previous_prefix[0] == '\0') |
9219021c | 4618 | { |
38d518c9 | 4619 | processing_current_prefix = name; |
9219021c DC |
4620 | } |
4621 | else | |
4622 | { | |
987504bb JJ |
4623 | char *temp_name = typename_concat (NULL, previous_prefix, name, cu); |
4624 | make_cleanup (xfree, temp_name); | |
38d518c9 | 4625 | processing_current_prefix = temp_name; |
9219021c DC |
4626 | } |
4627 | ||
5c4e30ca DC |
4628 | /* Add a symbol associated to this if we haven't seen the namespace |
4629 | before. Also, add a using directive if it's an anonymous | |
4630 | namespace. */ | |
9219021c | 4631 | |
e142c38c | 4632 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
4633 | { |
4634 | struct type *type; | |
4635 | ||
4636 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
4637 | this cast will hopefully become unnecessary. */ | |
4638 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 4639 | (char *) processing_current_prefix, |
5c4e30ca DC |
4640 | objfile); |
4641 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4642 | ||
e7c27a73 | 4643 | new_symbol (die, type, cu); |
1c379e20 | 4644 | set_die_type (die, type, cu); |
5c4e30ca DC |
4645 | |
4646 | if (is_anonymous) | |
38d518c9 EZ |
4647 | cp_add_using_directive (processing_current_prefix, |
4648 | strlen (previous_prefix), | |
4649 | strlen (processing_current_prefix)); | |
5c4e30ca | 4650 | } |
9219021c | 4651 | |
639d11d3 | 4652 | if (die->child != NULL) |
d9fa45fe | 4653 | { |
639d11d3 | 4654 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4655 | |
4656 | while (child_die && child_die->tag) | |
4657 | { | |
e7c27a73 | 4658 | process_die (child_die, cu); |
d9fa45fe DC |
4659 | child_die = sibling_die (child_die); |
4660 | } | |
4661 | } | |
9219021c | 4662 | |
38d518c9 | 4663 | processing_current_prefix = previous_prefix; |
987504bb | 4664 | do_cleanups (back_to); |
38d518c9 EZ |
4665 | } |
4666 | ||
4667 | /* Return the name of the namespace represented by DIE. Set | |
4668 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
4669 | namespace. */ | |
4670 | ||
4671 | static const char * | |
e142c38c | 4672 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
4673 | { |
4674 | struct die_info *current_die; | |
4675 | const char *name = NULL; | |
4676 | ||
4677 | /* Loop through the extensions until we find a name. */ | |
4678 | ||
4679 | for (current_die = die; | |
4680 | current_die != NULL; | |
e142c38c | 4681 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 4682 | { |
e142c38c | 4683 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
4684 | if (name != NULL) |
4685 | break; | |
4686 | } | |
4687 | ||
4688 | /* Is it an anonymous namespace? */ | |
4689 | ||
4690 | *is_anonymous = (name == NULL); | |
4691 | if (*is_anonymous) | |
4692 | name = "(anonymous namespace)"; | |
4693 | ||
4694 | return name; | |
d9fa45fe DC |
4695 | } |
4696 | ||
c906108c SS |
4697 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
4698 | the user defined type vector. */ | |
4699 | ||
f792889a | 4700 | static struct type * |
e7c27a73 | 4701 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4702 | { |
5e2b427d | 4703 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
e7c27a73 | 4704 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 4705 | struct type *type; |
8b2dbe47 KB |
4706 | struct attribute *attr_byte_size; |
4707 | struct attribute *attr_address_class; | |
4708 | int byte_size, addr_class; | |
c906108c | 4709 | |
e7c27a73 | 4710 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 4711 | |
e142c38c | 4712 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
4713 | if (attr_byte_size) |
4714 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 4715 | else |
8b2dbe47 KB |
4716 | byte_size = cu_header->addr_size; |
4717 | ||
e142c38c | 4718 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
4719 | if (attr_address_class) |
4720 | addr_class = DW_UNSND (attr_address_class); | |
4721 | else | |
4722 | addr_class = DW_ADDR_none; | |
4723 | ||
4724 | /* If the pointer size or address class is different than the | |
4725 | default, create a type variant marked as such and set the | |
4726 | length accordingly. */ | |
4727 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 4728 | { |
5e2b427d | 4729 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
8b2dbe47 KB |
4730 | { |
4731 | int type_flags; | |
4732 | ||
849957d9 | 4733 | type_flags = gdbarch_address_class_type_flags |
5e2b427d | 4734 | (gdbarch, byte_size, addr_class); |
8b2dbe47 KB |
4735 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); |
4736 | type = make_type_with_address_space (type, type_flags); | |
4737 | } | |
4738 | else if (TYPE_LENGTH (type) != byte_size) | |
4739 | { | |
e2e0b3e5 | 4740 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
4741 | } |
4742 | else { | |
4743 | /* Should we also complain about unhandled address classes? */ | |
4744 | } | |
c906108c | 4745 | } |
8b2dbe47 KB |
4746 | |
4747 | TYPE_LENGTH (type) = byte_size; | |
f792889a | 4748 | return set_die_type (die, type, cu); |
c906108c SS |
4749 | } |
4750 | ||
4751 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
4752 | the user defined type vector. */ | |
4753 | ||
f792889a | 4754 | static struct type * |
e7c27a73 | 4755 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4756 | { |
e7c27a73 | 4757 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4758 | struct type *type; |
4759 | struct type *to_type; | |
4760 | struct type *domain; | |
4761 | ||
e7c27a73 DJ |
4762 | to_type = die_type (die, cu); |
4763 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
4764 | |
4765 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
4766 | type = lookup_methodptr_type (to_type); | |
4767 | else | |
4768 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 4769 | |
f792889a | 4770 | return set_die_type (die, type, cu); |
c906108c SS |
4771 | } |
4772 | ||
4773 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
4774 | the user defined type vector. */ | |
4775 | ||
f792889a | 4776 | static struct type * |
e7c27a73 | 4777 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4778 | { |
e7c27a73 | 4779 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4780 | struct type *type; |
4781 | struct attribute *attr; | |
4782 | ||
e7c27a73 | 4783 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 4784 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4785 | if (attr) |
4786 | { | |
4787 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4788 | } | |
4789 | else | |
4790 | { | |
107d2387 | 4791 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 4792 | } |
f792889a | 4793 | return set_die_type (die, type, cu); |
c906108c SS |
4794 | } |
4795 | ||
f792889a | 4796 | static struct type * |
e7c27a73 | 4797 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4798 | { |
f792889a | 4799 | struct type *base_type, *cv_type; |
c906108c | 4800 | |
e7c27a73 | 4801 | base_type = die_type (die, cu); |
f792889a DJ |
4802 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
4803 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4804 | } |
4805 | ||
f792889a | 4806 | static struct type * |
e7c27a73 | 4807 | read_tag_volatile_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 (TYPE_CONST (base_type), 1, base_type, 0); |
4813 | return set_die_type (die, cv_type, cu); | |
c906108c SS |
4814 | } |
4815 | ||
4816 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4817 | the user defined type vector. It isn't really a user defined type, | |
4818 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4819 | attribute to reference it. */ | |
4820 | ||
f792889a | 4821 | static struct type * |
e7c27a73 | 4822 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4823 | { |
e7c27a73 | 4824 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4825 | struct type *type, *range_type, *index_type, *char_type; |
4826 | struct attribute *attr; | |
4827 | unsigned int length; | |
4828 | ||
e142c38c | 4829 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4830 | if (attr) |
4831 | { | |
4832 | length = DW_UNSND (attr); | |
4833 | } | |
4834 | else | |
4835 | { | |
b21b22e0 | 4836 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4837 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4838 | if (attr) |
4839 | { | |
4840 | length = DW_UNSND (attr); | |
4841 | } | |
4842 | else | |
4843 | { | |
4844 | length = 1; | |
4845 | } | |
c906108c | 4846 | } |
6ccb9162 UW |
4847 | |
4848 | index_type = builtin_type_int32; | |
c906108c | 4849 | range_type = create_range_type (NULL, index_type, 1, length); |
6ccb9162 UW |
4850 | type = create_string_type (NULL, range_type); |
4851 | ||
f792889a | 4852 | return set_die_type (die, type, cu); |
c906108c SS |
4853 | } |
4854 | ||
4855 | /* Handle DIES due to C code like: | |
4856 | ||
4857 | struct foo | |
c5aa993b JM |
4858 | { |
4859 | int (*funcp)(int a, long l); | |
4860 | int b; | |
4861 | }; | |
c906108c SS |
4862 | |
4863 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4864 | */ |
c906108c | 4865 | |
f792889a | 4866 | static struct type * |
e7c27a73 | 4867 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4868 | { |
4869 | struct type *type; /* Type that this function returns */ | |
4870 | struct type *ftype; /* Function that returns above type */ | |
4871 | struct attribute *attr; | |
4872 | ||
e7c27a73 | 4873 | type = die_type (die, cu); |
1326e61b | 4874 | ftype = make_function_type (type, (struct type **) 0); |
c906108c | 4875 | |
5b8101ae | 4876 | /* All functions in C++, Pascal and Java have prototypes. */ |
e142c38c | 4877 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4878 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb | 4879 | || cu->language == language_cplus |
5b8101ae PM |
4880 | || cu->language == language_java |
4881 | || cu->language == language_pascal) | |
c906108c SS |
4882 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4883 | ||
c055b101 CV |
4884 | /* Store the calling convention in the type if it's available in |
4885 | the subroutine die. Otherwise set the calling convention to | |
4886 | the default value DW_CC_normal. */ | |
4887 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); | |
4888 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; | |
4889 | ||
639d11d3 | 4890 | if (die->child != NULL) |
c906108c SS |
4891 | { |
4892 | struct die_info *child_die; | |
4893 | int nparams = 0; | |
4894 | int iparams = 0; | |
4895 | ||
4896 | /* Count the number of parameters. | |
4897 | FIXME: GDB currently ignores vararg functions, but knows about | |
4898 | vararg member functions. */ | |
639d11d3 | 4899 | child_die = die->child; |
c906108c SS |
4900 | while (child_die && child_die->tag) |
4901 | { | |
4902 | if (child_die->tag == DW_TAG_formal_parameter) | |
4903 | nparams++; | |
4904 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4905 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4906 | child_die = sibling_die (child_die); | |
4907 | } | |
4908 | ||
4909 | /* Allocate storage for parameters and fill them in. */ | |
4910 | TYPE_NFIELDS (ftype) = nparams; | |
4911 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 4912 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 4913 | |
639d11d3 | 4914 | child_die = die->child; |
c906108c SS |
4915 | while (child_die && child_die->tag) |
4916 | { | |
4917 | if (child_die->tag == DW_TAG_formal_parameter) | |
4918 | { | |
4919 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4920 | member functions. G++ helps GDB by marking the first |
4921 | parameter for non-static member functions (which is the | |
4922 | this pointer) as artificial. We pass this information | |
4923 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4924 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4925 | if (attr) |
4926 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4927 | else | |
4928 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4929 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4930 | iparams++; |
4931 | } | |
4932 | child_die = sibling_die (child_die); | |
4933 | } | |
4934 | } | |
4935 | ||
f792889a | 4936 | return set_die_type (die, ftype, cu); |
c906108c SS |
4937 | } |
4938 | ||
f792889a | 4939 | static struct type * |
e7c27a73 | 4940 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4941 | { |
e7c27a73 | 4942 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4943 | struct attribute *attr; |
4944 | char *name = NULL; | |
f792889a | 4945 | struct type *this_type; |
c906108c | 4946 | |
f792889a DJ |
4947 | name = dwarf2_name (die, cu); |
4948 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, | |
4949 | TYPE_FLAG_TARGET_STUB, name, objfile); | |
4950 | set_die_type (die, this_type, cu); | |
4951 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); | |
4952 | return this_type; | |
c906108c SS |
4953 | } |
4954 | ||
4955 | /* Find a representation of a given base type and install | |
4956 | it in the TYPE field of the die. */ | |
4957 | ||
f792889a | 4958 | static struct type * |
e7c27a73 | 4959 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4960 | { |
e7c27a73 | 4961 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4962 | struct type *type; |
4963 | struct attribute *attr; | |
4964 | int encoding = 0, size = 0; | |
39cbfefa | 4965 | char *name; |
6ccb9162 UW |
4966 | enum type_code code = TYPE_CODE_INT; |
4967 | int type_flags = 0; | |
4968 | struct type *target_type = NULL; | |
c906108c | 4969 | |
e142c38c | 4970 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4971 | if (attr) |
4972 | { | |
4973 | encoding = DW_UNSND (attr); | |
4974 | } | |
e142c38c | 4975 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4976 | if (attr) |
4977 | { | |
4978 | size = DW_UNSND (attr); | |
4979 | } | |
39cbfefa | 4980 | name = dwarf2_name (die, cu); |
6ccb9162 | 4981 | if (!name) |
c906108c | 4982 | { |
6ccb9162 UW |
4983 | complaint (&symfile_complaints, |
4984 | _("DW_AT_name missing from DW_TAG_base_type")); | |
c906108c | 4985 | } |
6ccb9162 UW |
4986 | |
4987 | switch (encoding) | |
c906108c | 4988 | { |
6ccb9162 UW |
4989 | case DW_ATE_address: |
4990 | /* Turn DW_ATE_address into a void * pointer. */ | |
4991 | code = TYPE_CODE_PTR; | |
4992 | type_flags |= TYPE_FLAG_UNSIGNED; | |
4993 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); | |
4994 | break; | |
4995 | case DW_ATE_boolean: | |
4996 | code = TYPE_CODE_BOOL; | |
4997 | type_flags |= TYPE_FLAG_UNSIGNED; | |
4998 | break; | |
4999 | case DW_ATE_complex_float: | |
5000 | code = TYPE_CODE_COMPLEX; | |
5001 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); | |
5002 | break; | |
5003 | case DW_ATE_decimal_float: | |
5004 | code = TYPE_CODE_DECFLOAT; | |
5005 | break; | |
5006 | case DW_ATE_float: | |
5007 | code = TYPE_CODE_FLT; | |
5008 | break; | |
5009 | case DW_ATE_signed: | |
5010 | break; | |
5011 | case DW_ATE_unsigned: | |
5012 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5013 | break; | |
5014 | case DW_ATE_signed_char: | |
1760d9d5 | 5015 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5016 | code = TYPE_CODE_CHAR; |
5017 | break; | |
5018 | case DW_ATE_unsigned_char: | |
1760d9d5 | 5019 | if (cu->language == language_ada || cu->language == language_m2) |
6ccb9162 UW |
5020 | code = TYPE_CODE_CHAR; |
5021 | type_flags |= TYPE_FLAG_UNSIGNED; | |
5022 | break; | |
5023 | default: | |
5024 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), | |
5025 | dwarf_type_encoding_name (encoding)); | |
5026 | break; | |
c906108c | 5027 | } |
6ccb9162 UW |
5028 | |
5029 | type = init_type (code, size, type_flags, name, objfile); | |
5030 | TYPE_TARGET_TYPE (type) = target_type; | |
5031 | ||
f792889a | 5032 | return set_die_type (die, type, cu); |
c906108c SS |
5033 | } |
5034 | ||
a02abb62 JB |
5035 | /* Read the given DW_AT_subrange DIE. */ |
5036 | ||
f792889a | 5037 | static struct type * |
a02abb62 JB |
5038 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
5039 | { | |
5e2b427d | 5040 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
a02abb62 JB |
5041 | struct type *base_type; |
5042 | struct type *range_type; | |
5043 | struct attribute *attr; | |
5044 | int low = 0; | |
5045 | int high = -1; | |
39cbfefa | 5046 | char *name; |
a02abb62 | 5047 | |
a02abb62 | 5048 | base_type = die_type (die, cu); |
3d1f72c2 | 5049 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
a02abb62 JB |
5050 | { |
5051 | complaint (&symfile_complaints, | |
e2e0b3e5 | 5052 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
17a912b6 | 5053 | base_type |
5e2b427d | 5054 | = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, |
6ccb9162 | 5055 | 0, NULL, cu->objfile); |
a02abb62 JB |
5056 | } |
5057 | ||
e142c38c | 5058 | if (cu->language == language_fortran) |
a02abb62 JB |
5059 | { |
5060 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
5061 | low = 1; | |
5062 | } | |
5063 | ||
dd5e6932 DJ |
5064 | /* FIXME: For variable sized arrays either of these could be |
5065 | a variable rather than a constant value. We'll allow it, | |
5066 | but we don't know how to handle it. */ | |
e142c38c | 5067 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
5068 | if (attr) |
5069 | low = dwarf2_get_attr_constant_value (attr, 0); | |
5070 | ||
e142c38c | 5071 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
5072 | if (attr) |
5073 | { | |
5074 | if (attr->form == DW_FORM_block1) | |
5075 | { | |
5076 | /* GCC encodes arrays with unspecified or dynamic length | |
5077 | with a DW_FORM_block1 attribute. | |
5078 | FIXME: GDB does not yet know how to handle dynamic | |
5079 | arrays properly, treat them as arrays with unspecified | |
5080 | length for now. | |
5081 | ||
5082 | FIXME: jimb/2003-09-22: GDB does not really know | |
5083 | how to handle arrays of unspecified length | |
5084 | either; we just represent them as zero-length | |
5085 | arrays. Choose an appropriate upper bound given | |
5086 | the lower bound we've computed above. */ | |
5087 | high = low - 1; | |
5088 | } | |
5089 | else | |
5090 | high = dwarf2_get_attr_constant_value (attr, 1); | |
5091 | } | |
5092 | ||
5093 | range_type = create_range_type (NULL, base_type, low, high); | |
5094 | ||
39cbfefa DJ |
5095 | name = dwarf2_name (die, cu); |
5096 | if (name) | |
5097 | TYPE_NAME (range_type) = name; | |
a02abb62 | 5098 | |
e142c38c | 5099 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
5100 | if (attr) |
5101 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
5102 | ||
f792889a | 5103 | return set_die_type (die, range_type, cu); |
a02abb62 JB |
5104 | } |
5105 | ||
f792889a | 5106 | static struct type * |
81a17f79 JB |
5107 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
5108 | { | |
5109 | struct type *type; | |
81a17f79 | 5110 | |
81a17f79 JB |
5111 | /* For now, we only support the C meaning of an unspecified type: void. */ |
5112 | ||
39cbfefa | 5113 | type = init_type (TYPE_CODE_VOID, 0, 0, dwarf2_name (die, cu), |
81a17f79 JB |
5114 | cu->objfile); |
5115 | ||
f792889a | 5116 | return set_die_type (die, type, cu); |
81a17f79 | 5117 | } |
a02abb62 | 5118 | |
c906108c SS |
5119 | /* Read a whole compilation unit into a linked list of dies. */ |
5120 | ||
f9aca02d | 5121 | static struct die_info * |
fe1b8b76 | 5122 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5123 | { |
e7c27a73 | 5124 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
5125 | } |
5126 | ||
5127 | /* Read a single die and all its descendents. Set the die's sibling | |
5128 | field to NULL; set other fields in the die correctly, and set all | |
5129 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
5130 | location of the info_ptr after reading all of those dies. PARENT | |
5131 | is the parent of the die in question. */ | |
5132 | ||
5133 | static struct die_info * | |
fe1b8b76 | 5134 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5135 | struct dwarf2_cu *cu, |
fe1b8b76 | 5136 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5137 | struct die_info *parent) |
5138 | { | |
5139 | struct die_info *die; | |
fe1b8b76 | 5140 | gdb_byte *cur_ptr; |
639d11d3 DC |
5141 | int has_children; |
5142 | ||
e7c27a73 | 5143 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
10b3939b | 5144 | store_in_ref_table (die->offset, die, cu); |
639d11d3 DC |
5145 | |
5146 | if (has_children) | |
5147 | { | |
e7c27a73 | 5148 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5149 | new_info_ptr, die); |
5150 | } | |
5151 | else | |
5152 | { | |
5153 | die->child = NULL; | |
5154 | *new_info_ptr = cur_ptr; | |
5155 | } | |
5156 | ||
5157 | die->sibling = NULL; | |
5158 | die->parent = parent; | |
5159 | return die; | |
5160 | } | |
5161 | ||
5162 | /* Read a die, all of its descendents, and all of its siblings; set | |
5163 | all of the fields of all of the dies correctly. Arguments are as | |
5164 | in read_die_and_children. */ | |
5165 | ||
5166 | static struct die_info * | |
fe1b8b76 | 5167 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5168 | struct dwarf2_cu *cu, |
fe1b8b76 | 5169 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5170 | struct die_info *parent) |
5171 | { | |
5172 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5173 | gdb_byte *cur_ptr; |
639d11d3 | 5174 | |
c906108c | 5175 | cur_ptr = info_ptr; |
639d11d3 DC |
5176 | first_die = last_sibling = NULL; |
5177 | ||
5178 | while (1) | |
c906108c | 5179 | { |
639d11d3 | 5180 | struct die_info *die |
e7c27a73 | 5181 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
5182 | |
5183 | if (!first_die) | |
c906108c | 5184 | { |
639d11d3 | 5185 | first_die = die; |
c906108c | 5186 | } |
639d11d3 | 5187 | else |
c906108c | 5188 | { |
639d11d3 | 5189 | last_sibling->sibling = die; |
c906108c SS |
5190 | } |
5191 | ||
639d11d3 | 5192 | if (die->tag == 0) |
c906108c | 5193 | { |
639d11d3 DC |
5194 | *new_info_ptr = cur_ptr; |
5195 | return first_die; | |
c906108c SS |
5196 | } |
5197 | else | |
5198 | { | |
639d11d3 | 5199 | last_sibling = die; |
c906108c SS |
5200 | } |
5201 | } | |
c906108c SS |
5202 | } |
5203 | ||
5204 | /* Free a linked list of dies. */ | |
5205 | ||
5206 | static void | |
fba45db2 | 5207 | free_die_list (struct die_info *dies) |
c906108c SS |
5208 | { |
5209 | struct die_info *die, *next; | |
5210 | ||
5211 | die = dies; | |
5212 | while (die) | |
5213 | { | |
639d11d3 DC |
5214 | if (die->child != NULL) |
5215 | free_die_list (die->child); | |
5216 | next = die->sibling; | |
b8c9b27d KB |
5217 | xfree (die->attrs); |
5218 | xfree (die); | |
c906108c SS |
5219 | die = next; |
5220 | } | |
5221 | } | |
5222 | ||
233a11ab CS |
5223 | /* Decompress a section that was compressed using zlib. Store the |
5224 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ | |
5225 | ||
5226 | static void | |
5227 | zlib_decompress_section (struct objfile *objfile, asection *sectp, | |
5228 | gdb_byte **outbuf, bfd_size_type *outsize) | |
5229 | { | |
ef72380d | 5230 | bfd *abfd = objfile->obfd; |
233a11ab CS |
5231 | #ifndef HAVE_ZLIB_H |
5232 | error (_("Support for zlib-compressed DWARF data (from '%s') " | |
5233 | "is disabled in this copy of GDB"), | |
5234 | bfd_get_filename (abfd)); | |
5235 | #else | |
233a11ab CS |
5236 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
5237 | gdb_byte *compressed_buffer = xmalloc (compressed_size); | |
5238 | bfd_size_type uncompressed_size; | |
5239 | gdb_byte *uncompressed_buffer; | |
5240 | z_stream strm; | |
5241 | int rc; | |
5242 | int header_size = 12; | |
5243 | ||
5244 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 | |
5245 | || bfd_bread (compressed_buffer, compressed_size, abfd) != compressed_size) | |
5246 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), | |
5247 | bfd_get_filename (abfd)); | |
5248 | ||
5249 | /* Read the zlib header. In this case, it should be "ZLIB" followed | |
5250 | by the uncompressed section size, 8 bytes in big-endian order. */ | |
5251 | if (compressed_size < header_size | |
5252 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) | |
5253 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), | |
5254 | bfd_get_filename (abfd)); | |
5255 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; | |
5256 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; | |
5257 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; | |
5258 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; | |
5259 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; | |
5260 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; | |
5261 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; | |
5262 | uncompressed_size += compressed_buffer[11]; | |
5263 | ||
5264 | /* It is possible the section consists of several compressed | |
5265 | buffers concatenated together, so we uncompress in a loop. */ | |
5266 | strm.zalloc = NULL; | |
5267 | strm.zfree = NULL; | |
5268 | strm.opaque = NULL; | |
5269 | strm.avail_in = compressed_size - header_size; | |
5270 | strm.next_in = (Bytef*) compressed_buffer + header_size; | |
5271 | strm.avail_out = uncompressed_size; | |
5272 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, | |
5273 | uncompressed_size); | |
5274 | rc = inflateInit (&strm); | |
5275 | while (strm.avail_in > 0) | |
5276 | { | |
5277 | if (rc != Z_OK) | |
5278 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), | |
5279 | bfd_get_filename (abfd), rc); | |
5280 | strm.next_out = ((Bytef*) uncompressed_buffer | |
5281 | + (uncompressed_size - strm.avail_out)); | |
5282 | rc = inflate (&strm, Z_FINISH); | |
5283 | if (rc != Z_STREAM_END) | |
5284 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), | |
5285 | bfd_get_filename (abfd), rc); | |
5286 | rc = inflateReset (&strm); | |
5287 | } | |
5288 | rc = inflateEnd (&strm); | |
5289 | if (rc != Z_OK | |
5290 | || strm.avail_out != 0) | |
5291 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), | |
5292 | bfd_get_filename (abfd), rc); | |
5293 | ||
5294 | xfree (compressed_buffer); | |
5295 | *outbuf = uncompressed_buffer; | |
5296 | *outsize = uncompressed_size; | |
5297 | #endif | |
5298 | } | |
5299 | ||
5300 | ||
c906108c | 5301 | /* Read the contents of the section at OFFSET and of size SIZE from the |
233a11ab CS |
5302 | object file specified by OBJFILE into the objfile_obstack and return it. |
5303 | If the section is compressed, uncompress it before returning. */ | |
c906108c | 5304 | |
fe1b8b76 | 5305 | gdb_byte * |
188dd5d6 | 5306 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
5307 | { |
5308 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 5309 | gdb_byte *buf, *retbuf; |
2c500098 | 5310 | bfd_size_type size = bfd_get_section_size (sectp); |
233a11ab | 5311 | unsigned char header[4]; |
c906108c SS |
5312 | |
5313 | if (size == 0) | |
5314 | return NULL; | |
5315 | ||
233a11ab CS |
5316 | /* Check if the file has a 4-byte header indicating compression. */ |
5317 | if (size > sizeof (header) | |
5318 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 | |
5319 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) | |
5320 | { | |
5321 | /* Upon decompression, update the buffer and its size. */ | |
5322 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) | |
5323 | { | |
5324 | zlib_decompress_section (objfile, sectp, &buf, &size); | |
5325 | dwarf2_resize_section (sectp, size); | |
5326 | return buf; | |
5327 | } | |
5328 | } | |
5329 | ||
5330 | /* If we get here, we are a normal, not-compressed section. */ | |
fe1b8b76 | 5331 | buf = obstack_alloc (&objfile->objfile_obstack, size); |
233a11ab CS |
5332 | /* When debugging .o files, we may need to apply relocations; see |
5333 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . | |
5334 | We never compress sections in .o files, so we only need to | |
5335 | try this when the section is not compressed. */ | |
fe1b8b76 | 5336 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); |
086df311 DJ |
5337 | if (retbuf != NULL) |
5338 | return retbuf; | |
5339 | ||
188dd5d6 DJ |
5340 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
5341 | || bfd_bread (buf, size, abfd) != size) | |
8a3fe4f8 | 5342 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
188dd5d6 DJ |
5343 | bfd_get_filename (abfd)); |
5344 | ||
c906108c SS |
5345 | return buf; |
5346 | } | |
5347 | ||
5348 | /* In DWARF version 2, the description of the debugging information is | |
5349 | stored in a separate .debug_abbrev section. Before we read any | |
5350 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5351 | in a hash table. This function also sets flags in CU describing |
5352 | the data found in the abbrev table. */ | |
c906108c SS |
5353 | |
5354 | static void | |
e7c27a73 | 5355 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5356 | { |
e7c27a73 | 5357 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5358 | gdb_byte *abbrev_ptr; |
c906108c SS |
5359 | struct abbrev_info *cur_abbrev; |
5360 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5361 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5362 | struct attr_abbrev *cur_attrs; |
5363 | unsigned int allocated_attrs; | |
c906108c | 5364 | |
57349743 | 5365 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5366 | obstack_init (&cu->abbrev_obstack); |
5367 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5368 | (ABBREV_HASH_SIZE | |
5369 | * sizeof (struct abbrev_info *))); | |
5370 | memset (cu->dwarf2_abbrevs, 0, | |
5371 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5372 | |
6502dd73 | 5373 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
5374 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5375 | abbrev_ptr += bytes_read; | |
5376 | ||
f3dd6933 DJ |
5377 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5378 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5379 | ||
c906108c SS |
5380 | /* loop until we reach an abbrev number of 0 */ |
5381 | while (abbrev_number) | |
5382 | { | |
f3dd6933 | 5383 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5384 | |
5385 | /* read in abbrev header */ | |
5386 | cur_abbrev->number = abbrev_number; | |
5387 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5388 | abbrev_ptr += bytes_read; | |
5389 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5390 | abbrev_ptr += 1; | |
5391 | ||
72bf9492 DJ |
5392 | if (cur_abbrev->tag == DW_TAG_namespace) |
5393 | cu->has_namespace_info = 1; | |
5394 | ||
c906108c SS |
5395 | /* now read in declarations */ |
5396 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5397 | abbrev_ptr += bytes_read; | |
5398 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5399 | abbrev_ptr += bytes_read; | |
5400 | while (abbrev_name) | |
5401 | { | |
f3dd6933 | 5402 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5403 | { |
f3dd6933 DJ |
5404 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5405 | cur_attrs | |
5406 | = xrealloc (cur_attrs, (allocated_attrs | |
5407 | * sizeof (struct attr_abbrev))); | |
c906108c | 5408 | } |
ae038cb0 DJ |
5409 | |
5410 | /* Record whether this compilation unit might have | |
5411 | inter-compilation-unit references. If we don't know what form | |
5412 | this attribute will have, then it might potentially be a | |
5413 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5414 | references. */ | |
5415 | ||
5416 | if (abbrev_form == DW_FORM_ref_addr | |
5417 | || abbrev_form == DW_FORM_indirect) | |
5418 | cu->has_form_ref_addr = 1; | |
5419 | ||
f3dd6933 DJ |
5420 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5421 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5422 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5423 | abbrev_ptr += bytes_read; | |
5424 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5425 | abbrev_ptr += bytes_read; | |
5426 | } | |
5427 | ||
f3dd6933 DJ |
5428 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5429 | (cur_abbrev->num_attrs | |
5430 | * sizeof (struct attr_abbrev))); | |
5431 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5432 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5433 | ||
c906108c | 5434 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5435 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5436 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5437 | |
5438 | /* Get next abbreviation. | |
5439 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5440 | always properly terminated with an abbrev number of 0. |
5441 | Exit loop if we encounter an abbreviation which we have | |
5442 | already read (which means we are about to read the abbreviations | |
5443 | for the next compile unit) or if the end of the abbreviation | |
5444 | table is reached. */ | |
6502dd73 DJ |
5445 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
5446 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
5447 | break; |
5448 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5449 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5450 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5451 | break; |
5452 | } | |
f3dd6933 DJ |
5453 | |
5454 | xfree (cur_attrs); | |
c906108c SS |
5455 | } |
5456 | ||
f3dd6933 | 5457 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5458 | |
c906108c | 5459 | static void |
f3dd6933 | 5460 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5461 | { |
f3dd6933 | 5462 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5463 | |
f3dd6933 DJ |
5464 | obstack_free (&cu->abbrev_obstack, NULL); |
5465 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5466 | } |
5467 | ||
5468 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5469 | ||
5470 | static struct abbrev_info * | |
e7c27a73 | 5471 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5472 | { |
5473 | unsigned int hash_number; | |
5474 | struct abbrev_info *abbrev; | |
5475 | ||
5476 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5477 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5478 | |
5479 | while (abbrev) | |
5480 | { | |
5481 | if (abbrev->number == number) | |
5482 | return abbrev; | |
5483 | else | |
5484 | abbrev = abbrev->next; | |
5485 | } | |
5486 | return NULL; | |
5487 | } | |
5488 | ||
72bf9492 DJ |
5489 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5490 | symbol for. */ | |
5491 | ||
5492 | static int | |
5493 | is_type_tag_for_partial (int tag) | |
5494 | { | |
5495 | switch (tag) | |
5496 | { | |
5497 | #if 0 | |
5498 | /* Some types that would be reasonable to generate partial symbols for, | |
5499 | that we don't at present. */ | |
5500 | case DW_TAG_array_type: | |
5501 | case DW_TAG_file_type: | |
5502 | case DW_TAG_ptr_to_member_type: | |
5503 | case DW_TAG_set_type: | |
5504 | case DW_TAG_string_type: | |
5505 | case DW_TAG_subroutine_type: | |
5506 | #endif | |
5507 | case DW_TAG_base_type: | |
5508 | case DW_TAG_class_type: | |
680b30c7 | 5509 | case DW_TAG_interface_type: |
72bf9492 DJ |
5510 | case DW_TAG_enumeration_type: |
5511 | case DW_TAG_structure_type: | |
5512 | case DW_TAG_subrange_type: | |
5513 | case DW_TAG_typedef: | |
5514 | case DW_TAG_union_type: | |
5515 | return 1; | |
5516 | default: | |
5517 | return 0; | |
5518 | } | |
5519 | } | |
5520 | ||
5521 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5522 | ||
5523 | static struct partial_die_info * | |
fe1b8b76 | 5524 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5525 | struct dwarf2_cu *cu) |
5526 | { | |
5527 | struct partial_die_info *part_die; | |
5528 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5529 | struct abbrev_info *abbrev; | |
5530 | unsigned int bytes_read; | |
5afb4e99 | 5531 | unsigned int load_all = 0; |
72bf9492 DJ |
5532 | |
5533 | int nesting_level = 1; | |
5534 | ||
5535 | parent_die = NULL; | |
5536 | last_die = NULL; | |
5537 | ||
5afb4e99 DJ |
5538 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5539 | load_all = 1; | |
5540 | ||
72bf9492 DJ |
5541 | cu->partial_dies |
5542 | = htab_create_alloc_ex (cu->header.length / 12, | |
5543 | partial_die_hash, | |
5544 | partial_die_eq, | |
5545 | NULL, | |
5546 | &cu->comp_unit_obstack, | |
5547 | hashtab_obstack_allocate, | |
5548 | dummy_obstack_deallocate); | |
5549 | ||
5550 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5551 | sizeof (struct partial_die_info)); | |
5552 | ||
5553 | while (1) | |
5554 | { | |
5555 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5556 | ||
5557 | /* A NULL abbrev means the end of a series of children. */ | |
5558 | if (abbrev == NULL) | |
5559 | { | |
5560 | if (--nesting_level == 0) | |
5561 | { | |
5562 | /* PART_DIE was probably the last thing allocated on the | |
5563 | comp_unit_obstack, so we could call obstack_free | |
5564 | here. We don't do that because the waste is small, | |
5565 | and will be cleaned up when we're done with this | |
5566 | compilation unit. This way, we're also more robust | |
5567 | against other users of the comp_unit_obstack. */ | |
5568 | return first_die; | |
5569 | } | |
5570 | info_ptr += bytes_read; | |
5571 | last_die = parent_die; | |
5572 | parent_die = parent_die->die_parent; | |
5573 | continue; | |
5574 | } | |
5575 | ||
5afb4e99 DJ |
5576 | /* Check whether this DIE is interesting enough to save. Normally |
5577 | we would not be interested in members here, but there may be | |
5578 | later variables referencing them via DW_AT_specification (for | |
5579 | static members). */ | |
5580 | if (!load_all | |
5581 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5582 | && abbrev->tag != DW_TAG_enumerator |
5583 | && abbrev->tag != DW_TAG_subprogram | |
5584 | && abbrev->tag != DW_TAG_variable | |
5afb4e99 DJ |
5585 | && abbrev->tag != DW_TAG_namespace |
5586 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5587 | { |
5588 | /* Otherwise we skip to the next sibling, if any. */ | |
5589 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5590 | continue; | |
5591 | } | |
5592 | ||
5593 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5594 | abfd, info_ptr, cu); | |
5595 | ||
5596 | /* This two-pass algorithm for processing partial symbols has a | |
5597 | high cost in cache pressure. Thus, handle some simple cases | |
5598 | here which cover the majority of C partial symbols. DIEs | |
5599 | which neither have specification tags in them, nor could have | |
5600 | specification tags elsewhere pointing at them, can simply be | |
5601 | processed and discarded. | |
5602 | ||
5603 | This segment is also optional; scan_partial_symbols and | |
5604 | add_partial_symbol will handle these DIEs if we chain | |
5605 | them in normally. When compilers which do not emit large | |
5606 | quantities of duplicate debug information are more common, | |
5607 | this code can probably be removed. */ | |
5608 | ||
5609 | /* Any complete simple types at the top level (pretty much all | |
5610 | of them, for a language without namespaces), can be processed | |
5611 | directly. */ | |
5612 | if (parent_die == NULL | |
5613 | && part_die->has_specification == 0 | |
5614 | && part_die->is_declaration == 0 | |
5615 | && (part_die->tag == DW_TAG_typedef | |
5616 | || part_die->tag == DW_TAG_base_type | |
5617 | || part_die->tag == DW_TAG_subrange_type)) | |
5618 | { | |
5619 | if (building_psymtab && part_die->name != NULL) | |
5620 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5621 | VAR_DOMAIN, LOC_TYPEDEF, | |
5622 | &cu->objfile->static_psymbols, | |
5623 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5624 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5625 | continue; | |
5626 | } | |
5627 | ||
5628 | /* If we're at the second level, and we're an enumerator, and | |
5629 | our parent has no specification (meaning possibly lives in a | |
5630 | namespace elsewhere), then we can add the partial symbol now | |
5631 | instead of queueing it. */ | |
5632 | if (part_die->tag == DW_TAG_enumerator | |
5633 | && parent_die != NULL | |
5634 | && parent_die->die_parent == NULL | |
5635 | && parent_die->tag == DW_TAG_enumeration_type | |
5636 | && parent_die->has_specification == 0) | |
5637 | { | |
5638 | if (part_die->name == NULL) | |
e2e0b3e5 | 5639 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5640 | else if (building_psymtab) |
5641 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5642 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5643 | (cu->language == language_cplus |
5644 | || cu->language == language_java) | |
72bf9492 DJ |
5645 | ? &cu->objfile->global_psymbols |
5646 | : &cu->objfile->static_psymbols, | |
5647 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5648 | ||
5649 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5650 | continue; | |
5651 | } | |
5652 | ||
5653 | /* We'll save this DIE so link it in. */ | |
5654 | part_die->die_parent = parent_die; | |
5655 | part_die->die_sibling = NULL; | |
5656 | part_die->die_child = NULL; | |
5657 | ||
5658 | if (last_die && last_die == parent_die) | |
5659 | last_die->die_child = part_die; | |
5660 | else if (last_die) | |
5661 | last_die->die_sibling = part_die; | |
5662 | ||
5663 | last_die = part_die; | |
5664 | ||
5665 | if (first_die == NULL) | |
5666 | first_die = part_die; | |
5667 | ||
5668 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5669 | find interesting need to be in the hash table, because we | |
5670 | also have the parent/sibling/child chains; only those that we | |
5671 | might refer to by offset later during partial symbol reading. | |
5672 | ||
5673 | For now this means things that might have be the target of a | |
5674 | DW_AT_specification, DW_AT_abstract_origin, or | |
5675 | DW_AT_extension. DW_AT_extension will refer only to | |
5676 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5677 | many things under the function DIE, but we do not recurse | |
5678 | into function DIEs during partial symbol reading) and | |
5679 | possibly variables as well; DW_AT_specification refers to | |
5680 | declarations. Declarations ought to have the DW_AT_declaration | |
5681 | flag. It happens that GCC forgets to put it in sometimes, but | |
5682 | only for functions, not for types. | |
5683 | ||
5684 | Adding more things than necessary to the hash table is harmless | |
5685 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5686 | wasted time in find_partial_die, when we reread the compilation |
5687 | unit with load_all_dies set. */ | |
72bf9492 | 5688 | |
5afb4e99 DJ |
5689 | if (load_all |
5690 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5691 | || abbrev->tag == DW_TAG_variable |
5692 | || abbrev->tag == DW_TAG_namespace | |
5693 | || part_die->is_declaration) | |
5694 | { | |
5695 | void **slot; | |
5696 | ||
5697 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5698 | part_die->offset, INSERT); | |
5699 | *slot = part_die; | |
5700 | } | |
5701 | ||
5702 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5703 | sizeof (struct partial_die_info)); | |
5704 | ||
5705 | /* For some DIEs we want to follow their children (if any). For C | |
5706 | we have no reason to follow the children of structures; for other | |
5707 | languages we have to, both so that we can get at method physnames | |
5708 | to infer fully qualified class names, and for DW_AT_specification. */ | |
5709 | if (last_die->has_children | |
5afb4e99 DJ |
5710 | && (load_all |
5711 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5712 | || last_die->tag == DW_TAG_enumeration_type |
5713 | || (cu->language != language_c | |
5714 | && (last_die->tag == DW_TAG_class_type | |
680b30c7 | 5715 | || last_die->tag == DW_TAG_interface_type |
72bf9492 DJ |
5716 | || last_die->tag == DW_TAG_structure_type |
5717 | || last_die->tag == DW_TAG_union_type)))) | |
5718 | { | |
5719 | nesting_level++; | |
5720 | parent_die = last_die; | |
5721 | continue; | |
5722 | } | |
5723 | ||
5724 | /* Otherwise we skip to the next sibling, if any. */ | |
5725 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5726 | ||
5727 | /* Back to the top, do it again. */ | |
5728 | } | |
5729 | } | |
5730 | ||
c906108c SS |
5731 | /* Read a minimal amount of information into the minimal die structure. */ |
5732 | ||
fe1b8b76 | 5733 | static gdb_byte * |
72bf9492 DJ |
5734 | read_partial_die (struct partial_die_info *part_die, |
5735 | struct abbrev_info *abbrev, | |
5736 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 5737 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 5738 | { |
72bf9492 | 5739 | unsigned int bytes_read, i; |
c906108c | 5740 | struct attribute attr; |
c5aa993b | 5741 | int has_low_pc_attr = 0; |
c906108c | 5742 | int has_high_pc_attr = 0; |
e7030f15 | 5743 | CORE_ADDR base_address = 0; |
85cbf3d3 JK |
5744 | enum |
5745 | { | |
5746 | base_address_none, | |
5747 | base_address_low_pc, | |
5748 | /* Overrides BASE_ADDRESS_LOW_PC. */ | |
5749 | base_address_entry_pc | |
5750 | } | |
5751 | base_address_type = base_address_none; | |
c906108c | 5752 | |
72bf9492 | 5753 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 5754 | |
6502dd73 | 5755 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
5756 | |
5757 | info_ptr += abbrev_len; | |
5758 | ||
5759 | if (abbrev == NULL) | |
5760 | return info_ptr; | |
5761 | ||
c906108c SS |
5762 | part_die->tag = abbrev->tag; |
5763 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
5764 | |
5765 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5766 | { | |
e7c27a73 | 5767 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
5768 | |
5769 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 5770 | partial symbol table. */ |
c906108c SS |
5771 | switch (attr.name) |
5772 | { | |
5773 | case DW_AT_name: | |
5774 | ||
5775 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
5776 | if (part_die->name == NULL) | |
5777 | part_die->name = DW_STRING (&attr); | |
5778 | break; | |
57c22c6c BR |
5779 | case DW_AT_comp_dir: |
5780 | if (part_die->dirname == NULL) | |
5781 | part_die->dirname = DW_STRING (&attr); | |
5782 | break; | |
c906108c SS |
5783 | case DW_AT_MIPS_linkage_name: |
5784 | part_die->name = DW_STRING (&attr); | |
5785 | break; | |
5786 | case DW_AT_low_pc: | |
5787 | has_low_pc_attr = 1; | |
5788 | part_die->lowpc = DW_ADDR (&attr); | |
85cbf3d3 JK |
5789 | if (part_die->tag == DW_TAG_compile_unit |
5790 | && base_address_type < base_address_low_pc) | |
5791 | { | |
5792 | base_address = DW_ADDR (&attr); | |
5793 | base_address_type = base_address_low_pc; | |
5794 | } | |
c906108c SS |
5795 | break; |
5796 | case DW_AT_high_pc: | |
5797 | has_high_pc_attr = 1; | |
5798 | part_die->highpc = DW_ADDR (&attr); | |
5799 | break; | |
85cbf3d3 JK |
5800 | case DW_AT_entry_pc: |
5801 | if (part_die->tag == DW_TAG_compile_unit | |
5802 | && base_address_type < base_address_entry_pc) | |
5803 | { | |
5804 | base_address = DW_ADDR (&attr); | |
5805 | base_address_type = base_address_entry_pc; | |
5806 | } | |
5807 | break; | |
43039443 | 5808 | case DW_AT_ranges: |
ff013f42 JK |
5809 | if (part_die->tag == DW_TAG_compile_unit) |
5810 | { | |
5811 | cu->ranges_offset = DW_UNSND (&attr); | |
5812 | cu->has_ranges_offset = 1; | |
5813 | } | |
43039443 | 5814 | break; |
c906108c | 5815 | case DW_AT_location: |
8e19ed76 PS |
5816 | /* Support the .debug_loc offsets */ |
5817 | if (attr_form_is_block (&attr)) | |
5818 | { | |
5819 | part_die->locdesc = DW_BLOCK (&attr); | |
5820 | } | |
3690dd37 | 5821 | else if (attr_form_is_section_offset (&attr)) |
8e19ed76 | 5822 | { |
4d3c2250 | 5823 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5824 | } |
5825 | else | |
5826 | { | |
4d3c2250 KB |
5827 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5828 | "partial symbol information"); | |
8e19ed76 | 5829 | } |
c906108c SS |
5830 | break; |
5831 | case DW_AT_language: | |
5832 | part_die->language = DW_UNSND (&attr); | |
5833 | break; | |
5834 | case DW_AT_external: | |
5835 | part_die->is_external = DW_UNSND (&attr); | |
5836 | break; | |
5837 | case DW_AT_declaration: | |
5838 | part_die->is_declaration = DW_UNSND (&attr); | |
5839 | break; | |
5840 | case DW_AT_type: | |
5841 | part_die->has_type = 1; | |
5842 | break; | |
5843 | case DW_AT_abstract_origin: | |
5844 | case DW_AT_specification: | |
72bf9492 DJ |
5845 | case DW_AT_extension: |
5846 | part_die->has_specification = 1; | |
5847 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
5848 | break; |
5849 | case DW_AT_sibling: | |
5850 | /* Ignore absolute siblings, they might point outside of | |
5851 | the current compile unit. */ | |
5852 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 5853 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 5854 | else |
6502dd73 DJ |
5855 | part_die->sibling = dwarf2_per_objfile->info_buffer |
5856 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 5857 | break; |
aaa75496 JB |
5858 | case DW_AT_stmt_list: |
5859 | part_die->has_stmt_list = 1; | |
5860 | part_die->line_offset = DW_UNSND (&attr); | |
5861 | break; | |
fa4028e9 JB |
5862 | case DW_AT_byte_size: |
5863 | part_die->has_byte_size = 1; | |
5864 | break; | |
68511cec CES |
5865 | case DW_AT_calling_convention: |
5866 | /* DWARF doesn't provide a way to identify a program's source-level | |
5867 | entry point. DW_AT_calling_convention attributes are only meant | |
5868 | to describe functions' calling conventions. | |
5869 | ||
5870 | However, because it's a necessary piece of information in | |
5871 | Fortran, and because DW_CC_program is the only piece of debugging | |
5872 | information whose definition refers to a 'main program' at all, | |
5873 | several compilers have begun marking Fortran main programs with | |
5874 | DW_CC_program --- even when those functions use the standard | |
5875 | calling conventions. | |
5876 | ||
5877 | So until DWARF specifies a way to provide this information and | |
5878 | compilers pick up the new representation, we'll support this | |
5879 | practice. */ | |
5880 | if (DW_UNSND (&attr) == DW_CC_program | |
5881 | && cu->language == language_fortran) | |
5882 | set_main_name (part_die->name); | |
5883 | break; | |
c906108c SS |
5884 | default: |
5885 | break; | |
5886 | } | |
5887 | } | |
5888 | ||
c906108c SS |
5889 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
5890 | eliminate duplicate copies of functions and vtables and such. | |
5891 | The linker will arbitrarily choose one and discard the others. | |
5892 | The AT_*_pc values for such functions refer to local labels in | |
5893 | these sections. If the section from that file was discarded, the | |
5894 | labels are not in the output, so the relocs get a value of 0. | |
5895 | If this is a discarded function, mark the pc bounds as invalid, | |
5896 | so that GDB will ignore it. */ | |
5897 | if (has_low_pc_attr && has_high_pc_attr | |
5898 | && part_die->lowpc < part_die->highpc | |
5899 | && (part_die->lowpc != 0 | |
72dca2f5 | 5900 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 5901 | part_die->has_pc_info = 1; |
85cbf3d3 JK |
5902 | |
5903 | if (base_address_type != base_address_none && !cu->header.base_known) | |
5904 | { | |
5905 | gdb_assert (part_die->tag == DW_TAG_compile_unit); | |
5906 | cu->header.base_known = 1; | |
5907 | cu->header.base_address = base_address; | |
5908 | } | |
5909 | ||
c906108c SS |
5910 | return info_ptr; |
5911 | } | |
5912 | ||
72bf9492 DJ |
5913 | /* Find a cached partial DIE at OFFSET in CU. */ |
5914 | ||
5915 | static struct partial_die_info * | |
5916 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
5917 | { | |
5918 | struct partial_die_info *lookup_die = NULL; | |
5919 | struct partial_die_info part_die; | |
5920 | ||
5921 | part_die.offset = offset; | |
5922 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
5923 | ||
72bf9492 DJ |
5924 | return lookup_die; |
5925 | } | |
5926 | ||
5927 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
5928 | ||
5929 | static struct partial_die_info * | |
10b3939b | 5930 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu) |
72bf9492 | 5931 | { |
5afb4e99 DJ |
5932 | struct dwarf2_per_cu_data *per_cu = NULL; |
5933 | struct partial_die_info *pd = NULL; | |
72bf9492 DJ |
5934 | |
5935 | if (offset >= cu->header.offset | |
5936 | && offset < cu->header.offset + cu->header.length) | |
5afb4e99 DJ |
5937 | { |
5938 | pd = find_partial_die_in_comp_unit (offset, cu); | |
5939 | if (pd != NULL) | |
5940 | return pd; | |
5941 | } | |
72bf9492 | 5942 | |
ae038cb0 DJ |
5943 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
5944 | ||
ae038cb0 DJ |
5945 | if (per_cu->cu == NULL) |
5946 | { | |
5947 | load_comp_unit (per_cu, cu->objfile); | |
5948 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5949 | dwarf2_per_objfile->read_in_chain = per_cu; | |
5950 | } | |
5951 | ||
5952 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
5953 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
5954 | ||
5955 | if (pd == NULL && per_cu->load_all_dies == 0) | |
5956 | { | |
5957 | struct cleanup *back_to; | |
5958 | struct partial_die_info comp_unit_die; | |
5959 | struct abbrev_info *abbrev; | |
5960 | unsigned int bytes_read; | |
5961 | char *info_ptr; | |
5962 | ||
5963 | per_cu->load_all_dies = 1; | |
5964 | ||
5965 | /* Re-read the DIEs. */ | |
5966 | back_to = make_cleanup (null_cleanup, 0); | |
5967 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
5968 | { | |
5969 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
5970 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
5971 | } | |
5972 | info_ptr = per_cu->cu->header.first_die_ptr; | |
5973 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); | |
5974 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
5975 | per_cu->cu->objfile->obfd, info_ptr, | |
5976 | per_cu->cu); | |
5977 | if (comp_unit_die.has_children) | |
5978 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
5979 | do_cleanups (back_to); | |
5980 | ||
5981 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
5982 | } | |
5983 | ||
5984 | if (pd == NULL) | |
5985 | internal_error (__FILE__, __LINE__, | |
5986 | _("could not find partial DIE 0x%lx in cache [from module %s]\n"), | |
5987 | offset, bfd_get_filename (cu->objfile->obfd)); | |
5988 | return pd; | |
72bf9492 DJ |
5989 | } |
5990 | ||
5991 | /* Adjust PART_DIE before generating a symbol for it. This function | |
5992 | may set the is_external flag or change the DIE's name. */ | |
5993 | ||
5994 | static void | |
5995 | fixup_partial_die (struct partial_die_info *part_die, | |
5996 | struct dwarf2_cu *cu) | |
5997 | { | |
5998 | /* If we found a reference attribute and the DIE has no name, try | |
5999 | to find a name in the referred to DIE. */ | |
6000 | ||
6001 | if (part_die->name == NULL && part_die->has_specification) | |
6002 | { | |
6003 | struct partial_die_info *spec_die; | |
72bf9492 | 6004 | |
10b3939b | 6005 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 6006 | |
10b3939b | 6007 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
6008 | |
6009 | if (spec_die->name) | |
6010 | { | |
6011 | part_die->name = spec_die->name; | |
6012 | ||
6013 | /* Copy DW_AT_external attribute if it is set. */ | |
6014 | if (spec_die->is_external) | |
6015 | part_die->is_external = spec_die->is_external; | |
6016 | } | |
6017 | } | |
6018 | ||
6019 | /* Set default names for some unnamed DIEs. */ | |
6020 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
6021 | || part_die->tag == DW_TAG_class_type)) | |
6022 | part_die->name = "(anonymous class)"; | |
6023 | ||
6024 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
6025 | part_die->name = "(anonymous namespace)"; | |
6026 | ||
6027 | if (part_die->tag == DW_TAG_structure_type | |
6028 | || part_die->tag == DW_TAG_class_type | |
6029 | || part_die->tag == DW_TAG_union_type) | |
6030 | guess_structure_name (part_die, cu); | |
6031 | } | |
6032 | ||
639d11d3 DC |
6033 | /* Read the die from the .debug_info section buffer. Set DIEP to |
6034 | point to a newly allocated die with its information, except for its | |
6035 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
6036 | whether the die has children or not. */ | |
c906108c | 6037 | |
fe1b8b76 JB |
6038 | static gdb_byte * |
6039 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 6040 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
6041 | { |
6042 | unsigned int abbrev_number, bytes_read, i, offset; | |
6043 | struct abbrev_info *abbrev; | |
6044 | struct die_info *die; | |
6045 | ||
6502dd73 | 6046 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
6047 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6048 | info_ptr += bytes_read; | |
6049 | if (!abbrev_number) | |
6050 | { | |
6051 | die = dwarf_alloc_die (); | |
6052 | die->tag = 0; | |
6053 | die->abbrev = abbrev_number; | |
c906108c | 6054 | *diep = die; |
639d11d3 | 6055 | *has_children = 0; |
c906108c SS |
6056 | return info_ptr; |
6057 | } | |
6058 | ||
e7c27a73 | 6059 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
6060 | if (!abbrev) |
6061 | { | |
8a3fe4f8 | 6062 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 6063 | abbrev_number, |
639d11d3 | 6064 | bfd_get_filename (abfd)); |
c906108c SS |
6065 | } |
6066 | die = dwarf_alloc_die (); | |
6067 | die->offset = offset; | |
6068 | die->tag = abbrev->tag; | |
c906108c | 6069 | die->abbrev = abbrev_number; |
c906108c SS |
6070 | |
6071 | die->num_attrs = abbrev->num_attrs; | |
6072 | die->attrs = (struct attribute *) | |
6073 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
6074 | ||
6075 | for (i = 0; i < abbrev->num_attrs; ++i) | |
6076 | { | |
6077 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 6078 | abfd, info_ptr, cu); |
10b3939b DJ |
6079 | |
6080 | /* If this attribute is an absolute reference to a different | |
6081 | compilation unit, make sure that compilation unit is loaded | |
6082 | also. */ | |
6083 | if (die->attrs[i].form == DW_FORM_ref_addr | |
6084 | && (DW_ADDR (&die->attrs[i]) < cu->header.offset | |
6085 | || (DW_ADDR (&die->attrs[i]) | |
6086 | >= cu->header.offset + cu->header.length))) | |
6087 | { | |
6088 | struct dwarf2_per_cu_data *per_cu; | |
6089 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (&die->attrs[i]), | |
6090 | cu->objfile); | |
6091 | ||
6092 | /* Mark the dependence relation so that we don't flush PER_CU | |
6093 | too early. */ | |
6094 | dwarf2_add_dependence (cu, per_cu); | |
6095 | ||
6096 | /* If it's already on the queue, we have nothing to do. */ | |
6097 | if (per_cu->queued) | |
6098 | continue; | |
6099 | ||
6100 | /* If the compilation unit is already loaded, just mark it as | |
6101 | used. */ | |
6102 | if (per_cu->cu != NULL) | |
6103 | { | |
6104 | per_cu->cu->last_used = 0; | |
6105 | continue; | |
6106 | } | |
6107 | ||
6108 | /* Add it to the queue. */ | |
6109 | queue_comp_unit (per_cu); | |
6110 | } | |
c906108c SS |
6111 | } |
6112 | ||
6113 | *diep = die; | |
639d11d3 | 6114 | *has_children = abbrev->has_children; |
c906108c SS |
6115 | return info_ptr; |
6116 | } | |
6117 | ||
a8329558 | 6118 | /* Read an attribute value described by an attribute form. */ |
c906108c | 6119 | |
fe1b8b76 | 6120 | static gdb_byte * |
a8329558 | 6121 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 6122 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 6123 | struct dwarf2_cu *cu) |
c906108c | 6124 | { |
e7c27a73 | 6125 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6126 | unsigned int bytes_read; |
6127 | struct dwarf_block *blk; | |
6128 | ||
a8329558 KW |
6129 | attr->form = form; |
6130 | switch (form) | |
c906108c SS |
6131 | { |
6132 | case DW_FORM_addr: | |
6133 | case DW_FORM_ref_addr: | |
e7c27a73 | 6134 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 6135 | info_ptr += bytes_read; |
c906108c SS |
6136 | break; |
6137 | case DW_FORM_block2: | |
7b5a2f43 | 6138 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6139 | blk->size = read_2_bytes (abfd, info_ptr); |
6140 | info_ptr += 2; | |
6141 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6142 | info_ptr += blk->size; | |
6143 | DW_BLOCK (attr) = blk; | |
6144 | break; | |
6145 | case DW_FORM_block4: | |
7b5a2f43 | 6146 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6147 | blk->size = read_4_bytes (abfd, info_ptr); |
6148 | info_ptr += 4; | |
6149 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6150 | info_ptr += blk->size; | |
6151 | DW_BLOCK (attr) = blk; | |
6152 | break; | |
6153 | case DW_FORM_data2: | |
6154 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
6155 | info_ptr += 2; | |
6156 | break; | |
6157 | case DW_FORM_data4: | |
6158 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
6159 | info_ptr += 4; | |
6160 | break; | |
6161 | case DW_FORM_data8: | |
6162 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
6163 | info_ptr += 8; | |
6164 | break; | |
6165 | case DW_FORM_string: | |
6166 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
6167 | info_ptr += bytes_read; | |
6168 | break; | |
4bdf3d34 JJ |
6169 | case DW_FORM_strp: |
6170 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
6171 | &bytes_read); | |
6172 | info_ptr += bytes_read; | |
6173 | break; | |
c906108c | 6174 | case DW_FORM_block: |
7b5a2f43 | 6175 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6176 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6177 | info_ptr += bytes_read; | |
6178 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6179 | info_ptr += blk->size; | |
6180 | DW_BLOCK (attr) = blk; | |
6181 | break; | |
6182 | case DW_FORM_block1: | |
7b5a2f43 | 6183 | blk = dwarf_alloc_block (cu); |
c906108c SS |
6184 | blk->size = read_1_byte (abfd, info_ptr); |
6185 | info_ptr += 1; | |
6186 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
6187 | info_ptr += blk->size; | |
6188 | DW_BLOCK (attr) = blk; | |
6189 | break; | |
6190 | case DW_FORM_data1: | |
6191 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6192 | info_ptr += 1; | |
6193 | break; | |
6194 | case DW_FORM_flag: | |
6195 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
6196 | info_ptr += 1; | |
6197 | break; | |
6198 | case DW_FORM_sdata: | |
6199 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
6200 | info_ptr += bytes_read; | |
6201 | break; | |
6202 | case DW_FORM_udata: | |
6203 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
6204 | info_ptr += bytes_read; | |
6205 | break; | |
6206 | case DW_FORM_ref1: | |
10b3939b | 6207 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
6208 | info_ptr += 1; |
6209 | break; | |
6210 | case DW_FORM_ref2: | |
10b3939b | 6211 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
6212 | info_ptr += 2; |
6213 | break; | |
6214 | case DW_FORM_ref4: | |
10b3939b | 6215 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
6216 | info_ptr += 4; |
6217 | break; | |
613e1657 | 6218 | case DW_FORM_ref8: |
10b3939b | 6219 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
6220 | info_ptr += 8; |
6221 | break; | |
c906108c | 6222 | case DW_FORM_ref_udata: |
10b3939b DJ |
6223 | DW_ADDR (attr) = (cu->header.offset |
6224 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
6225 | info_ptr += bytes_read; |
6226 | break; | |
c906108c | 6227 | case DW_FORM_indirect: |
a8329558 KW |
6228 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
6229 | info_ptr += bytes_read; | |
e7c27a73 | 6230 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 6231 | break; |
c906108c | 6232 | default: |
8a3fe4f8 | 6233 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
6234 | dwarf_form_name (form), |
6235 | bfd_get_filename (abfd)); | |
c906108c | 6236 | } |
28e94949 JB |
6237 | |
6238 | /* We have seen instances where the compiler tried to emit a byte | |
6239 | size attribute of -1 which ended up being encoded as an unsigned | |
6240 | 0xffffffff. Although 0xffffffff is technically a valid size value, | |
6241 | an object of this size seems pretty unlikely so we can relatively | |
6242 | safely treat these cases as if the size attribute was invalid and | |
6243 | treat them as zero by default. */ | |
6244 | if (attr->name == DW_AT_byte_size | |
6245 | && form == DW_FORM_data4 | |
6246 | && DW_UNSND (attr) >= 0xffffffff) | |
6247 | DW_UNSND (attr) = 0; | |
6248 | ||
c906108c SS |
6249 | return info_ptr; |
6250 | } | |
6251 | ||
a8329558 KW |
6252 | /* Read an attribute described by an abbreviated attribute. */ |
6253 | ||
fe1b8b76 | 6254 | static gdb_byte * |
a8329558 | 6255 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 6256 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
6257 | { |
6258 | attr->name = abbrev->name; | |
e7c27a73 | 6259 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
6260 | } |
6261 | ||
c906108c SS |
6262 | /* read dwarf information from a buffer */ |
6263 | ||
6264 | static unsigned int | |
fe1b8b76 | 6265 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6266 | { |
fe1b8b76 | 6267 | return bfd_get_8 (abfd, buf); |
c906108c SS |
6268 | } |
6269 | ||
6270 | static int | |
fe1b8b76 | 6271 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 6272 | { |
fe1b8b76 | 6273 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
6274 | } |
6275 | ||
6276 | static unsigned int | |
fe1b8b76 | 6277 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6278 | { |
fe1b8b76 | 6279 | return bfd_get_16 (abfd, buf); |
c906108c SS |
6280 | } |
6281 | ||
6282 | static int | |
fe1b8b76 | 6283 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6284 | { |
fe1b8b76 | 6285 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
6286 | } |
6287 | ||
6288 | static unsigned int | |
fe1b8b76 | 6289 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6290 | { |
fe1b8b76 | 6291 | return bfd_get_32 (abfd, buf); |
c906108c SS |
6292 | } |
6293 | ||
6294 | static int | |
fe1b8b76 | 6295 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6296 | { |
fe1b8b76 | 6297 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
6298 | } |
6299 | ||
ce5d95e1 | 6300 | static unsigned long |
fe1b8b76 | 6301 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 6302 | { |
fe1b8b76 | 6303 | return bfd_get_64 (abfd, buf); |
c906108c SS |
6304 | } |
6305 | ||
6306 | static CORE_ADDR | |
fe1b8b76 | 6307 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 6308 | unsigned int *bytes_read) |
c906108c | 6309 | { |
e7c27a73 | 6310 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6311 | CORE_ADDR retval = 0; |
6312 | ||
107d2387 | 6313 | if (cu_header->signed_addr_p) |
c906108c | 6314 | { |
107d2387 AC |
6315 | switch (cu_header->addr_size) |
6316 | { | |
6317 | case 2: | |
fe1b8b76 | 6318 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6319 | break; |
6320 | case 4: | |
fe1b8b76 | 6321 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6322 | break; |
6323 | case 8: | |
fe1b8b76 | 6324 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6325 | break; |
6326 | default: | |
8e65ff28 | 6327 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6328 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6329 | bfd_get_filename (abfd)); |
107d2387 AC |
6330 | } |
6331 | } | |
6332 | else | |
6333 | { | |
6334 | switch (cu_header->addr_size) | |
6335 | { | |
6336 | case 2: | |
fe1b8b76 | 6337 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6338 | break; |
6339 | case 4: | |
fe1b8b76 | 6340 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6341 | break; |
6342 | case 8: | |
fe1b8b76 | 6343 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6344 | break; |
6345 | default: | |
8e65ff28 | 6346 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6347 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6348 | bfd_get_filename (abfd)); |
107d2387 | 6349 | } |
c906108c | 6350 | } |
64367e0a | 6351 | |
107d2387 AC |
6352 | *bytes_read = cu_header->addr_size; |
6353 | return retval; | |
c906108c SS |
6354 | } |
6355 | ||
f7ef9339 | 6356 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6357 | specification allows the initial length to take up either 4 bytes |
6358 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6359 | bytes describe the length and all offsets will be 8 bytes in length | |
6360 | instead of 4. | |
6361 | ||
f7ef9339 KB |
6362 | An older, non-standard 64-bit format is also handled by this |
6363 | function. The older format in question stores the initial length | |
6364 | as an 8-byte quantity without an escape value. Lengths greater | |
6365 | than 2^32 aren't very common which means that the initial 4 bytes | |
6366 | is almost always zero. Since a length value of zero doesn't make | |
6367 | sense for the 32-bit format, this initial zero can be considered to | |
6368 | be an escape value which indicates the presence of the older 64-bit | |
6369 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6370 | greater than 4GB. If it becomes necessary to handle lengths |
6371 | somewhat larger than 4GB, we could allow other small values (such | |
6372 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6373 | escape values indicating the presence of the old format. | |
f7ef9339 | 6374 | |
917c78fc MK |
6375 | The value returned via bytes_read should be used to increment the |
6376 | relevant pointer after calling read_initial_length(). | |
613e1657 KB |
6377 | |
6378 | As a side effect, this function sets the fields initial_length_size | |
6379 | and offset_size in cu_header to the values appropriate for the | |
6380 | length field. (The format of the initial length field determines | |
dd373385 | 6381 | the width of file offsets to be fetched later with read_offset().) |
613e1657 KB |
6382 | |
6383 | [ Note: read_initial_length() and read_offset() are based on the | |
6384 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6385 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6386 | from: |
6387 | ||
f7ef9339 | 6388 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6389 | |
6390 | This document is only a draft and is subject to change. (So beware.) | |
6391 | ||
f7ef9339 | 6392 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6393 | determined empirically by examining 64-bit ELF files produced by |
6394 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6395 | |
6396 | - Kevin, July 16, 2002 | |
613e1657 KB |
6397 | ] */ |
6398 | ||
6399 | static LONGEST | |
fe1b8b76 | 6400 | read_initial_length (bfd *abfd, gdb_byte *buf, struct comp_unit_head *cu_header, |
891d2f0b | 6401 | unsigned int *bytes_read) |
613e1657 | 6402 | { |
fe1b8b76 | 6403 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6404 | |
dd373385 | 6405 | if (length == 0xffffffff) |
613e1657 | 6406 | { |
fe1b8b76 | 6407 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6408 | *bytes_read = 12; |
613e1657 | 6409 | } |
dd373385 | 6410 | else if (length == 0) |
f7ef9339 | 6411 | { |
dd373385 | 6412 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6413 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6414 | *bytes_read = 8; |
f7ef9339 | 6415 | } |
613e1657 KB |
6416 | else |
6417 | { | |
6418 | *bytes_read = 4; | |
613e1657 KB |
6419 | } |
6420 | ||
dd373385 EZ |
6421 | if (cu_header) |
6422 | { | |
6423 | gdb_assert (cu_header->initial_length_size == 0 | |
6424 | || cu_header->initial_length_size == 4 | |
6425 | || cu_header->initial_length_size == 8 | |
6426 | || cu_header->initial_length_size == 12); | |
6427 | ||
6428 | if (cu_header->initial_length_size != 0 | |
6429 | && cu_header->initial_length_size != *bytes_read) | |
6430 | complaint (&symfile_complaints, | |
6431 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
6432 | ||
6433 | cu_header->initial_length_size = *bytes_read; | |
6434 | cu_header->offset_size = (*bytes_read == 4) ? 4 : 8; | |
6435 | } | |
6436 | ||
6437 | return length; | |
613e1657 KB |
6438 | } |
6439 | ||
6440 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6441 | given by cu_header->offset_size. */ |
613e1657 KB |
6442 | |
6443 | static LONGEST | |
fe1b8b76 | 6444 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6445 | unsigned int *bytes_read) |
613e1657 KB |
6446 | { |
6447 | LONGEST retval = 0; | |
6448 | ||
6449 | switch (cu_header->offset_size) | |
6450 | { | |
6451 | case 4: | |
fe1b8b76 | 6452 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6453 | *bytes_read = 4; |
6454 | break; | |
6455 | case 8: | |
fe1b8b76 | 6456 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6457 | *bytes_read = 8; |
6458 | break; | |
6459 | default: | |
8e65ff28 | 6460 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6461 | _("read_offset: bad switch [in module %s]"), |
659b0389 | 6462 | bfd_get_filename (abfd)); |
613e1657 KB |
6463 | } |
6464 | ||
917c78fc | 6465 | return retval; |
613e1657 KB |
6466 | } |
6467 | ||
fe1b8b76 JB |
6468 | static gdb_byte * |
6469 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6470 | { |
6471 | /* If the size of a host char is 8 bits, we can return a pointer | |
6472 | to the buffer, otherwise we have to copy the data to a buffer | |
6473 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6474 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6475 | return buf; |
c906108c SS |
6476 | } |
6477 | ||
6478 | static char * | |
fe1b8b76 | 6479 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6480 | { |
6481 | /* If the size of a host char is 8 bits, we can return a pointer | |
6482 | to the string, otherwise we have to copy the string to a buffer | |
6483 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6484 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6485 | if (*buf == '\0') |
6486 | { | |
6487 | *bytes_read_ptr = 1; | |
6488 | return NULL; | |
6489 | } | |
fe1b8b76 JB |
6490 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6491 | return (char *) buf; | |
4bdf3d34 JJ |
6492 | } |
6493 | ||
6494 | static char * | |
fe1b8b76 | 6495 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6496 | const struct comp_unit_head *cu_header, |
6497 | unsigned int *bytes_read_ptr) | |
6498 | { | |
6499 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
891d2f0b | 6500 | bytes_read_ptr); |
c906108c | 6501 | |
6502dd73 | 6502 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 6503 | { |
8a3fe4f8 | 6504 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6505 | bfd_get_filename (abfd)); |
4bdf3d34 | 6506 | return NULL; |
c906108c | 6507 | } |
6502dd73 | 6508 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 6509 | { |
8a3fe4f8 | 6510 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6511 | bfd_get_filename (abfd)); |
c906108c SS |
6512 | return NULL; |
6513 | } | |
4bdf3d34 | 6514 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 6515 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 6516 | return NULL; |
fe1b8b76 | 6517 | return (char *) (dwarf2_per_objfile->str_buffer + str_offset); |
c906108c SS |
6518 | } |
6519 | ||
ce5d95e1 | 6520 | static unsigned long |
fe1b8b76 | 6521 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6522 | { |
ce5d95e1 JB |
6523 | unsigned long result; |
6524 | unsigned int num_read; | |
c906108c SS |
6525 | int i, shift; |
6526 | unsigned char byte; | |
6527 | ||
6528 | result = 0; | |
6529 | shift = 0; | |
6530 | num_read = 0; | |
6531 | i = 0; | |
6532 | while (1) | |
6533 | { | |
fe1b8b76 | 6534 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6535 | buf++; |
6536 | num_read++; | |
ce5d95e1 | 6537 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6538 | if ((byte & 128) == 0) |
6539 | { | |
6540 | break; | |
6541 | } | |
6542 | shift += 7; | |
6543 | } | |
6544 | *bytes_read_ptr = num_read; | |
6545 | return result; | |
6546 | } | |
6547 | ||
ce5d95e1 | 6548 | static long |
fe1b8b76 | 6549 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6550 | { |
ce5d95e1 | 6551 | long result; |
77e0b926 | 6552 | int i, shift, num_read; |
c906108c SS |
6553 | unsigned char byte; |
6554 | ||
6555 | result = 0; | |
6556 | shift = 0; | |
c906108c SS |
6557 | num_read = 0; |
6558 | i = 0; | |
6559 | while (1) | |
6560 | { | |
fe1b8b76 | 6561 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6562 | buf++; |
6563 | num_read++; | |
ce5d95e1 | 6564 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6565 | shift += 7; |
6566 | if ((byte & 128) == 0) | |
6567 | { | |
6568 | break; | |
6569 | } | |
6570 | } | |
77e0b926 DJ |
6571 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6572 | result |= -(((long)1) << shift); | |
c906108c SS |
6573 | *bytes_read_ptr = num_read; |
6574 | return result; | |
6575 | } | |
6576 | ||
4bb7a0a7 DJ |
6577 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6578 | ||
fe1b8b76 JB |
6579 | static gdb_byte * |
6580 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6581 | { |
6582 | int byte; | |
6583 | ||
6584 | while (1) | |
6585 | { | |
fe1b8b76 | 6586 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6587 | buf++; |
6588 | if ((byte & 128) == 0) | |
6589 | return buf; | |
6590 | } | |
6591 | } | |
6592 | ||
c906108c | 6593 | static void |
e142c38c | 6594 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6595 | { |
6596 | switch (lang) | |
6597 | { | |
6598 | case DW_LANG_C89: | |
6599 | case DW_LANG_C: | |
e142c38c | 6600 | cu->language = language_c; |
c906108c SS |
6601 | break; |
6602 | case DW_LANG_C_plus_plus: | |
e142c38c | 6603 | cu->language = language_cplus; |
c906108c SS |
6604 | break; |
6605 | case DW_LANG_Fortran77: | |
6606 | case DW_LANG_Fortran90: | |
b21b22e0 | 6607 | case DW_LANG_Fortran95: |
e142c38c | 6608 | cu->language = language_fortran; |
c906108c SS |
6609 | break; |
6610 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6611 | cu->language = language_asm; |
c906108c | 6612 | break; |
bebd888e | 6613 | case DW_LANG_Java: |
e142c38c | 6614 | cu->language = language_java; |
bebd888e | 6615 | break; |
c906108c | 6616 | case DW_LANG_Ada83: |
8aaf0b47 | 6617 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6618 | cu->language = language_ada; |
6619 | break; | |
72019c9c GM |
6620 | case DW_LANG_Modula2: |
6621 | cu->language = language_m2; | |
6622 | break; | |
fe8e67fd PM |
6623 | case DW_LANG_Pascal83: |
6624 | cu->language = language_pascal; | |
6625 | break; | |
22566fbd DJ |
6626 | case DW_LANG_ObjC: |
6627 | cu->language = language_objc; | |
6628 | break; | |
c906108c SS |
6629 | case DW_LANG_Cobol74: |
6630 | case DW_LANG_Cobol85: | |
c906108c | 6631 | default: |
e142c38c | 6632 | cu->language = language_minimal; |
c906108c SS |
6633 | break; |
6634 | } | |
e142c38c | 6635 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6636 | } |
6637 | ||
6638 | /* Return the named attribute or NULL if not there. */ | |
6639 | ||
6640 | static struct attribute * | |
e142c38c | 6641 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6642 | { |
6643 | unsigned int i; | |
6644 | struct attribute *spec = NULL; | |
6645 | ||
6646 | for (i = 0; i < die->num_attrs; ++i) | |
6647 | { | |
6648 | if (die->attrs[i].name == name) | |
10b3939b | 6649 | return &die->attrs[i]; |
c906108c SS |
6650 | if (die->attrs[i].name == DW_AT_specification |
6651 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6652 | spec = &die->attrs[i]; | |
6653 | } | |
c906108c | 6654 | |
10b3939b DJ |
6655 | if (spec) |
6656 | return dwarf2_attr (follow_die_ref (die, spec, cu), name, cu); | |
c5aa993b | 6657 | |
c906108c SS |
6658 | return NULL; |
6659 | } | |
6660 | ||
05cf31d1 JB |
6661 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6662 | and holds a non-zero value. This function should only be used for | |
6663 | DW_FORM_flag attributes. */ | |
6664 | ||
6665 | static int | |
6666 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6667 | { | |
6668 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6669 | ||
6670 | return (attr && DW_UNSND (attr)); | |
6671 | } | |
6672 | ||
3ca72b44 | 6673 | static int |
e142c38c | 6674 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6675 | { |
05cf31d1 JB |
6676 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6677 | which value is non-zero. However, we have to be careful with | |
6678 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6679 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6680 | end up accidently finding a declaration attribute that belongs | |
6681 | to a different DIE referenced by the specification attribute, | |
6682 | even though the given DIE does not have a declaration attribute. */ | |
6683 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6684 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6685 | } |
6686 | ||
63d06c5c DC |
6687 | /* Return the die giving the specification for DIE, if there is |
6688 | one. */ | |
6689 | ||
6690 | static struct die_info * | |
e142c38c | 6691 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 6692 | { |
e142c38c | 6693 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
6694 | |
6695 | if (spec_attr == NULL) | |
6696 | return NULL; | |
6697 | else | |
10b3939b | 6698 | return follow_die_ref (die, spec_attr, cu); |
63d06c5c | 6699 | } |
c906108c | 6700 | |
debd256d JB |
6701 | /* Free the line_header structure *LH, and any arrays and strings it |
6702 | refers to. */ | |
6703 | static void | |
6704 | free_line_header (struct line_header *lh) | |
6705 | { | |
6706 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6707 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6708 | |
6709 | /* Remember that all the lh->file_names[i].name pointers are | |
6710 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6711 | if (lh->file_names) | |
a8bc7b56 | 6712 | xfree (lh->file_names); |
debd256d JB |
6713 | |
6714 | /* Similarly for the include directory names. */ | |
6715 | if (lh->include_dirs) | |
a8bc7b56 | 6716 | xfree (lh->include_dirs); |
debd256d | 6717 | |
a8bc7b56 | 6718 | xfree (lh); |
debd256d JB |
6719 | } |
6720 | ||
6721 | ||
6722 | /* Add an entry to LH's include directory table. */ | |
6723 | static void | |
6724 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6725 | { |
debd256d JB |
6726 | /* Grow the array if necessary. */ |
6727 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6728 | { |
debd256d JB |
6729 | lh->include_dirs_size = 1; /* for testing */ |
6730 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6731 | * sizeof (*lh->include_dirs)); | |
6732 | } | |
6733 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
6734 | { | |
6735 | lh->include_dirs_size *= 2; | |
6736 | lh->include_dirs = xrealloc (lh->include_dirs, | |
6737 | (lh->include_dirs_size | |
6738 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 6739 | } |
c906108c | 6740 | |
debd256d JB |
6741 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
6742 | } | |
6743 | ||
6744 | ||
6745 | /* Add an entry to LH's file name table. */ | |
6746 | static void | |
6747 | add_file_name (struct line_header *lh, | |
6748 | char *name, | |
6749 | unsigned int dir_index, | |
6750 | unsigned int mod_time, | |
6751 | unsigned int length) | |
6752 | { | |
6753 | struct file_entry *fe; | |
6754 | ||
6755 | /* Grow the array if necessary. */ | |
6756 | if (lh->file_names_size == 0) | |
6757 | { | |
6758 | lh->file_names_size = 1; /* for testing */ | |
6759 | lh->file_names = xmalloc (lh->file_names_size | |
6760 | * sizeof (*lh->file_names)); | |
6761 | } | |
6762 | else if (lh->num_file_names >= lh->file_names_size) | |
6763 | { | |
6764 | lh->file_names_size *= 2; | |
6765 | lh->file_names = xrealloc (lh->file_names, | |
6766 | (lh->file_names_size | |
6767 | * sizeof (*lh->file_names))); | |
6768 | } | |
6769 | ||
6770 | fe = &lh->file_names[lh->num_file_names++]; | |
6771 | fe->name = name; | |
6772 | fe->dir_index = dir_index; | |
6773 | fe->mod_time = mod_time; | |
6774 | fe->length = length; | |
aaa75496 | 6775 | fe->included_p = 0; |
cb1df416 | 6776 | fe->symtab = NULL; |
debd256d JB |
6777 | } |
6778 | ||
6779 | ||
6780 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
6781 | .debug_line, according to the endianness of ABFD. Return a pointer |
6782 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
6783 | |
6784 | NOTE: the strings in the include directory and file name tables of | |
6785 | the returned object point into debug_line_buffer, and must not be | |
6786 | freed. */ | |
6787 | static struct line_header * | |
6788 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 6789 | struct dwarf2_cu *cu) |
debd256d JB |
6790 | { |
6791 | struct cleanup *back_to; | |
6792 | struct line_header *lh; | |
fe1b8b76 | 6793 | gdb_byte *line_ptr; |
891d2f0b | 6794 | unsigned int bytes_read; |
debd256d JB |
6795 | int i; |
6796 | char *cur_dir, *cur_file; | |
6797 | ||
6502dd73 | 6798 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 6799 | { |
e2e0b3e5 | 6800 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
6801 | return 0; |
6802 | } | |
6803 | ||
a738430d MK |
6804 | /* Make sure that at least there's room for the total_length field. |
6805 | That could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 6806 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 6807 | { |
4d3c2250 | 6808 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6809 | return 0; |
6810 | } | |
6811 | ||
6812 | lh = xmalloc (sizeof (*lh)); | |
6813 | memset (lh, 0, sizeof (*lh)); | |
6814 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
6815 | (void *) lh); | |
6816 | ||
6502dd73 | 6817 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d | 6818 | |
a738430d | 6819 | /* Read in the header. */ |
dd373385 EZ |
6820 | lh->total_length = |
6821 | read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); | |
debd256d | 6822 | line_ptr += bytes_read; |
6502dd73 DJ |
6823 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
6824 | + dwarf2_per_objfile->line_size)) | |
debd256d | 6825 | { |
4d3c2250 | 6826 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6827 | return 0; |
6828 | } | |
6829 | lh->statement_program_end = line_ptr + lh->total_length; | |
6830 | lh->version = read_2_bytes (abfd, line_ptr); | |
6831 | line_ptr += 2; | |
e7c27a73 | 6832 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
6833 | line_ptr += bytes_read; |
6834 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
6835 | line_ptr += 1; | |
6836 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
6837 | line_ptr += 1; | |
6838 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
6839 | line_ptr += 1; | |
6840 | lh->line_range = read_1_byte (abfd, line_ptr); | |
6841 | line_ptr += 1; | |
6842 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
6843 | line_ptr += 1; | |
6844 | lh->standard_opcode_lengths | |
fe1b8b76 | 6845 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
6846 | |
6847 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
6848 | for (i = 1; i < lh->opcode_base; ++i) | |
6849 | { | |
6850 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
6851 | line_ptr += 1; | |
6852 | } | |
6853 | ||
a738430d | 6854 | /* Read directory table. */ |
debd256d JB |
6855 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6856 | { | |
6857 | line_ptr += bytes_read; | |
6858 | add_include_dir (lh, cur_dir); | |
6859 | } | |
6860 | line_ptr += bytes_read; | |
6861 | ||
a738430d | 6862 | /* Read file name table. */ |
debd256d JB |
6863 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6864 | { | |
6865 | unsigned int dir_index, mod_time, length; | |
6866 | ||
6867 | line_ptr += bytes_read; | |
6868 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6869 | line_ptr += bytes_read; | |
6870 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6871 | line_ptr += bytes_read; | |
6872 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6873 | line_ptr += bytes_read; | |
6874 | ||
6875 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6876 | } | |
6877 | line_ptr += bytes_read; | |
6878 | lh->statement_program_start = line_ptr; | |
6879 | ||
6502dd73 DJ |
6880 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
6881 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 | 6882 | complaint (&symfile_complaints, |
e2e0b3e5 | 6883 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
6884 | |
6885 | discard_cleanups (back_to); | |
6886 | return lh; | |
6887 | } | |
c906108c | 6888 | |
5fb290d7 DJ |
6889 | /* This function exists to work around a bug in certain compilers |
6890 | (particularly GCC 2.95), in which the first line number marker of a | |
6891 | function does not show up until after the prologue, right before | |
6892 | the second line number marker. This function shifts ADDRESS down | |
6893 | to the beginning of the function if necessary, and is called on | |
6894 | addresses passed to record_line. */ | |
6895 | ||
6896 | static CORE_ADDR | |
e142c38c | 6897 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
6898 | { |
6899 | struct function_range *fn; | |
6900 | ||
6901 | /* Find the function_range containing address. */ | |
e142c38c | 6902 | if (!cu->first_fn) |
5fb290d7 DJ |
6903 | return address; |
6904 | ||
e142c38c DJ |
6905 | if (!cu->cached_fn) |
6906 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 6907 | |
e142c38c | 6908 | fn = cu->cached_fn; |
5fb290d7 DJ |
6909 | while (fn) |
6910 | if (fn->lowpc <= address && fn->highpc > address) | |
6911 | goto found; | |
6912 | else | |
6913 | fn = fn->next; | |
6914 | ||
e142c38c DJ |
6915 | fn = cu->first_fn; |
6916 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
6917 | if (fn->lowpc <= address && fn->highpc > address) |
6918 | goto found; | |
6919 | else | |
6920 | fn = fn->next; | |
6921 | ||
6922 | return address; | |
6923 | ||
6924 | found: | |
6925 | if (fn->seen_line) | |
6926 | return address; | |
6927 | if (address != fn->lowpc) | |
4d3c2250 | 6928 | complaint (&symfile_complaints, |
e2e0b3e5 | 6929 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 6930 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
6931 | fn->seen_line = 1; |
6932 | return fn->lowpc; | |
6933 | } | |
6934 | ||
aaa75496 JB |
6935 | /* Decode the Line Number Program (LNP) for the given line_header |
6936 | structure and CU. The actual information extracted and the type | |
6937 | of structures created from the LNP depends on the value of PST. | |
6938 | ||
6939 | 1. If PST is NULL, then this procedure uses the data from the program | |
6940 | to create all necessary symbol tables, and their linetables. | |
6941 | The compilation directory of the file is passed in COMP_DIR, | |
6942 | and must not be NULL. | |
6943 | ||
6944 | 2. If PST is not NULL, this procedure reads the program to determine | |
6945 | the list of files included by the unit represented by PST, and | |
6946 | builds all the associated partial symbol tables. In this case, | |
6947 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
6948 | is not used to compute the full name of the symtab, and therefore | |
6949 | omitting it when building the partial symtab does not introduce | |
6950 | the potential for inconsistency - a partial symtab and its associated | |
6951 | symbtab having a different fullname -). */ | |
debd256d | 6952 | |
c906108c | 6953 | static void |
debd256d | 6954 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 6955 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 6956 | { |
a8c50c1f | 6957 | gdb_byte *line_ptr, *extended_end; |
fe1b8b76 | 6958 | gdb_byte *line_end; |
a8c50c1f | 6959 | unsigned int bytes_read, extended_len; |
c906108c | 6960 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
6961 | CORE_ADDR baseaddr; |
6962 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 6963 | const int decode_for_pst_p = (pst != NULL); |
cb1df416 | 6964 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
e142c38c DJ |
6965 | |
6966 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6967 | |
debd256d JB |
6968 | line_ptr = lh->statement_program_start; |
6969 | line_end = lh->statement_program_end; | |
c906108c SS |
6970 | |
6971 | /* Read the statement sequences until there's nothing left. */ | |
6972 | while (line_ptr < line_end) | |
6973 | { | |
6974 | /* state machine registers */ | |
6975 | CORE_ADDR address = 0; | |
6976 | unsigned int file = 1; | |
6977 | unsigned int line = 1; | |
6978 | unsigned int column = 0; | |
debd256d | 6979 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
6980 | int basic_block = 0; |
6981 | int end_sequence = 0; | |
6982 | ||
aaa75496 | 6983 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 6984 | { |
aaa75496 | 6985 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
6986 | /* lh->include_dirs and lh->file_names are 0-based, but the |
6987 | directory and file name numbers in the statement program | |
6988 | are 1-based. */ | |
6989 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 6990 | char *dir = NULL; |
a738430d | 6991 | |
debd256d JB |
6992 | if (fe->dir_index) |
6993 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
6994 | |
6995 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
6996 | } |
6997 | ||
a738430d | 6998 | /* Decode the table. */ |
c5aa993b | 6999 | while (!end_sequence) |
c906108c SS |
7000 | { |
7001 | op_code = read_1_byte (abfd, line_ptr); | |
7002 | line_ptr += 1; | |
9aa1fe7e | 7003 | |
debd256d | 7004 | if (op_code >= lh->opcode_base) |
a738430d MK |
7005 | { |
7006 | /* Special operand. */ | |
debd256d JB |
7007 | adj_opcode = op_code - lh->opcode_base; |
7008 | address += (adj_opcode / lh->line_range) | |
7009 | * lh->minimum_instruction_length; | |
7010 | line += lh->line_base + (adj_opcode % lh->line_range); | |
25e43795 DJ |
7011 | if (lh->num_file_names < file) |
7012 | dwarf2_debug_line_missing_file_complaint (); | |
7013 | else | |
7014 | { | |
7015 | lh->file_names[file - 1].included_p = 1; | |
7016 | if (!decode_for_pst_p) | |
7017 | { | |
7018 | if (last_subfile != current_subfile) | |
7019 | { | |
7020 | if (last_subfile) | |
7021 | record_line (last_subfile, 0, address); | |
7022 | last_subfile = current_subfile; | |
7023 | } | |
7024 | /* Append row to matrix using current values. */ | |
7025 | record_line (current_subfile, line, | |
7026 | check_cu_functions (address, cu)); | |
366da635 | 7027 | } |
25e43795 | 7028 | } |
9aa1fe7e GK |
7029 | basic_block = 1; |
7030 | } | |
7031 | else switch (op_code) | |
c906108c SS |
7032 | { |
7033 | case DW_LNS_extended_op: | |
a8c50c1f | 7034 | extended_len = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
473b7be6 | 7035 | line_ptr += bytes_read; |
a8c50c1f | 7036 | extended_end = line_ptr + extended_len; |
c906108c SS |
7037 | extended_op = read_1_byte (abfd, line_ptr); |
7038 | line_ptr += 1; | |
7039 | switch (extended_op) | |
7040 | { | |
7041 | case DW_LNE_end_sequence: | |
7042 | end_sequence = 1; | |
25e43795 DJ |
7043 | |
7044 | if (lh->num_file_names < file) | |
7045 | dwarf2_debug_line_missing_file_complaint (); | |
7046 | else | |
7047 | { | |
7048 | lh->file_names[file - 1].included_p = 1; | |
7049 | if (!decode_for_pst_p) | |
7050 | record_line (current_subfile, 0, address); | |
7051 | } | |
c906108c SS |
7052 | break; |
7053 | case DW_LNE_set_address: | |
e7c27a73 | 7054 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
7055 | line_ptr += bytes_read; |
7056 | address += baseaddr; | |
c906108c SS |
7057 | break; |
7058 | case DW_LNE_define_file: | |
debd256d JB |
7059 | { |
7060 | char *cur_file; | |
7061 | unsigned int dir_index, mod_time, length; | |
7062 | ||
7063 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
7064 | line_ptr += bytes_read; | |
7065 | dir_index = | |
7066 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7067 | line_ptr += bytes_read; | |
7068 | mod_time = | |
7069 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7070 | line_ptr += bytes_read; | |
7071 | length = | |
7072 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7073 | line_ptr += bytes_read; | |
7074 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
7075 | } | |
c906108c SS |
7076 | break; |
7077 | default: | |
4d3c2250 | 7078 | complaint (&symfile_complaints, |
e2e0b3e5 | 7079 | _("mangled .debug_line section")); |
debd256d | 7080 | return; |
c906108c | 7081 | } |
a8c50c1f DJ |
7082 | /* Make sure that we parsed the extended op correctly. If e.g. |
7083 | we expected a different address size than the producer used, | |
7084 | we may have read the wrong number of bytes. */ | |
7085 | if (line_ptr != extended_end) | |
7086 | { | |
7087 | complaint (&symfile_complaints, | |
7088 | _("mangled .debug_line section")); | |
7089 | return; | |
7090 | } | |
c906108c SS |
7091 | break; |
7092 | case DW_LNS_copy: | |
25e43795 DJ |
7093 | if (lh->num_file_names < file) |
7094 | dwarf2_debug_line_missing_file_complaint (); | |
7095 | else | |
366da635 | 7096 | { |
25e43795 DJ |
7097 | lh->file_names[file - 1].included_p = 1; |
7098 | if (!decode_for_pst_p) | |
7099 | { | |
7100 | if (last_subfile != current_subfile) | |
7101 | { | |
7102 | if (last_subfile) | |
7103 | record_line (last_subfile, 0, address); | |
7104 | last_subfile = current_subfile; | |
7105 | } | |
7106 | record_line (current_subfile, line, | |
7107 | check_cu_functions (address, cu)); | |
7108 | } | |
366da635 | 7109 | } |
c906108c SS |
7110 | basic_block = 0; |
7111 | break; | |
7112 | case DW_LNS_advance_pc: | |
debd256d | 7113 | address += lh->minimum_instruction_length |
c906108c SS |
7114 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7115 | line_ptr += bytes_read; | |
7116 | break; | |
7117 | case DW_LNS_advance_line: | |
7118 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
7119 | line_ptr += bytes_read; | |
7120 | break; | |
7121 | case DW_LNS_set_file: | |
debd256d | 7122 | { |
a738430d MK |
7123 | /* The arrays lh->include_dirs and lh->file_names are |
7124 | 0-based, but the directory and file name numbers in | |
7125 | the statement program are 1-based. */ | |
debd256d | 7126 | struct file_entry *fe; |
4f1520fb | 7127 | char *dir = NULL; |
a738430d | 7128 | |
debd256d JB |
7129 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
7130 | line_ptr += bytes_read; | |
25e43795 DJ |
7131 | if (lh->num_file_names < file) |
7132 | dwarf2_debug_line_missing_file_complaint (); | |
7133 | else | |
7134 | { | |
7135 | fe = &lh->file_names[file - 1]; | |
7136 | if (fe->dir_index) | |
7137 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7138 | if (!decode_for_pst_p) | |
7139 | { | |
7140 | last_subfile = current_subfile; | |
7141 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7142 | } | |
7143 | } | |
debd256d | 7144 | } |
c906108c SS |
7145 | break; |
7146 | case DW_LNS_set_column: | |
7147 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7148 | line_ptr += bytes_read; | |
7149 | break; | |
7150 | case DW_LNS_negate_stmt: | |
7151 | is_stmt = (!is_stmt); | |
7152 | break; | |
7153 | case DW_LNS_set_basic_block: | |
7154 | basic_block = 1; | |
7155 | break; | |
c2c6d25f JM |
7156 | /* Add to the address register of the state machine the |
7157 | address increment value corresponding to special opcode | |
a738430d MK |
7158 | 255. I.e., this value is scaled by the minimum |
7159 | instruction length since special opcode 255 would have | |
7160 | scaled the the increment. */ | |
c906108c | 7161 | case DW_LNS_const_add_pc: |
debd256d JB |
7162 | address += (lh->minimum_instruction_length |
7163 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
7164 | break; |
7165 | case DW_LNS_fixed_advance_pc: | |
7166 | address += read_2_bytes (abfd, line_ptr); | |
7167 | line_ptr += 2; | |
7168 | break; | |
9aa1fe7e | 7169 | default: |
a738430d MK |
7170 | { |
7171 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 7172 | int i; |
a738430d | 7173 | |
debd256d | 7174 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
7175 | { |
7176 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
7177 | line_ptr += bytes_read; | |
7178 | } | |
7179 | } | |
c906108c SS |
7180 | } |
7181 | } | |
7182 | } | |
aaa75496 JB |
7183 | |
7184 | if (decode_for_pst_p) | |
7185 | { | |
7186 | int file_index; | |
7187 | ||
7188 | /* Now that we're done scanning the Line Header Program, we can | |
7189 | create the psymtab of each included file. */ | |
7190 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
7191 | if (lh->file_names[file_index].included_p == 1) | |
7192 | { | |
5b5464ad JB |
7193 | const struct file_entry fe = lh->file_names [file_index]; |
7194 | char *include_name = fe.name; | |
7195 | char *dir_name = NULL; | |
7196 | char *pst_filename = pst->filename; | |
7197 | ||
7198 | if (fe.dir_index) | |
7199 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
7200 | ||
7201 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
7202 | { | |
1754f103 MK |
7203 | include_name = concat (dir_name, SLASH_STRING, |
7204 | include_name, (char *)NULL); | |
5b5464ad JB |
7205 | make_cleanup (xfree, include_name); |
7206 | } | |
7207 | ||
7208 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
7209 | { | |
1754f103 MK |
7210 | pst_filename = concat (pst->dirname, SLASH_STRING, |
7211 | pst_filename, (char *)NULL); | |
5b5464ad JB |
7212 | make_cleanup (xfree, pst_filename); |
7213 | } | |
7214 | ||
7215 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
7216 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
7217 | } | |
7218 | } | |
cb1df416 DJ |
7219 | else |
7220 | { | |
7221 | /* Make sure a symtab is created for every file, even files | |
7222 | which contain only variables (i.e. no code with associated | |
7223 | line numbers). */ | |
7224 | ||
7225 | int i; | |
7226 | struct file_entry *fe; | |
7227 | ||
7228 | for (i = 0; i < lh->num_file_names; i++) | |
7229 | { | |
7230 | char *dir = NULL; | |
7231 | fe = &lh->file_names[i]; | |
7232 | if (fe->dir_index) | |
7233 | dir = lh->include_dirs[fe->dir_index - 1]; | |
7234 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
7235 | ||
7236 | /* Skip the main file; we don't need it, and it must be | |
7237 | allocated last, so that it will show up before the | |
7238 | non-primary symtabs in the objfile's symtab list. */ | |
7239 | if (current_subfile == first_subfile) | |
7240 | continue; | |
7241 | ||
7242 | if (current_subfile->symtab == NULL) | |
7243 | current_subfile->symtab = allocate_symtab (current_subfile->name, | |
7244 | cu->objfile); | |
7245 | fe->symtab = current_subfile->symtab; | |
7246 | } | |
7247 | } | |
c906108c SS |
7248 | } |
7249 | ||
7250 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
7251 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
7252 | or NULL if not known. COMP_DIR is the compilation directory for the |
7253 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
7254 | This routine tries to keep line numbers from identical absolute and |
7255 | relative file names in a common subfile. | |
7256 | ||
7257 | Using the `list' example from the GDB testsuite, which resides in | |
7258 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
7259 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
7260 | ||
c5aa993b JM |
7261 | DW_AT_name: /srcdir/list0.c |
7262 | DW_AT_comp_dir: /compdir | |
357e46e7 | 7263 | files.files[0].name: list0.h |
c5aa993b | 7264 | files.files[0].dir: /srcdir |
357e46e7 | 7265 | files.files[1].name: list0.c |
c5aa993b | 7266 | files.files[1].dir: /srcdir |
c906108c SS |
7267 | |
7268 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
7269 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
7270 | start_subfile will ensure that this happens provided that we pass the | |
7271 | concatenation of files.files[1].dir and files.files[1].name as the | |
7272 | subfile's name. */ | |
c906108c SS |
7273 | |
7274 | static void | |
4f1520fb | 7275 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 7276 | { |
4f1520fb FR |
7277 | char *fullname; |
7278 | ||
7279 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
7280 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
7281 | second argument to start_subfile. To be consistent, we do the | |
7282 | same here. In order not to lose the line information directory, | |
7283 | we concatenate it to the filename when it makes sense. | |
7284 | Note that the Dwarf3 standard says (speaking of filenames in line | |
7285 | information): ``The directory index is ignored for file names | |
7286 | that represent full path names''. Thus ignoring dirname in the | |
7287 | `else' branch below isn't an issue. */ | |
c906108c | 7288 | |
d5166ae1 | 7289 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
7290 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
7291 | else | |
7292 | fullname = filename; | |
c906108c | 7293 | |
4f1520fb FR |
7294 | start_subfile (fullname, comp_dir); |
7295 | ||
7296 | if (fullname != filename) | |
7297 | xfree (fullname); | |
c906108c SS |
7298 | } |
7299 | ||
4c2df51b DJ |
7300 | static void |
7301 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 7302 | struct dwarf2_cu *cu) |
4c2df51b | 7303 | { |
e7c27a73 DJ |
7304 | struct objfile *objfile = cu->objfile; |
7305 | struct comp_unit_head *cu_header = &cu->header; | |
7306 | ||
4c2df51b DJ |
7307 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
7308 | code here to turn a symbol with DW_AT_external and a | |
7309 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
7310 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
7311 | with some versions of binutils) where shared libraries could have | |
7312 | relocations against symbols in their debug information - the | |
7313 | minimal symbol would have the right address, but the debug info | |
7314 | would not. It's no longer necessary, because we will explicitly | |
7315 | apply relocations when we read in the debug information now. */ | |
7316 | ||
7317 | /* A DW_AT_location attribute with no contents indicates that a | |
7318 | variable has been optimized away. */ | |
7319 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
7320 | { | |
7321 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
7322 | return; | |
7323 | } | |
7324 | ||
7325 | /* Handle one degenerate form of location expression specially, to | |
7326 | preserve GDB's previous behavior when section offsets are | |
7327 | specified. If this is just a DW_OP_addr then mark this symbol | |
7328 | as LOC_STATIC. */ | |
7329 | ||
7330 | if (attr_form_is_block (attr) | |
7331 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
7332 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
7333 | { | |
891d2f0b | 7334 | unsigned int dummy; |
4c2df51b DJ |
7335 | |
7336 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 7337 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
907fc202 | 7338 | SYMBOL_CLASS (sym) = LOC_STATIC; |
4c2df51b DJ |
7339 | fixup_symbol_section (sym, objfile); |
7340 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
7341 | SYMBOL_SECTION (sym)); | |
4c2df51b DJ |
7342 | return; |
7343 | } | |
7344 | ||
7345 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
7346 | expression evaluator, and use LOC_COMPUTED only when necessary | |
7347 | (i.e. when the value of a register or memory location is | |
7348 | referenced, or a thread-local block, etc.). Then again, it might | |
7349 | not be worthwhile. I'm assuming that it isn't unless performance | |
7350 | or memory numbers show me otherwise. */ | |
7351 | ||
e7c27a73 | 7352 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
7353 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
7354 | } | |
7355 | ||
c906108c SS |
7356 | /* Given a pointer to a DWARF information entry, figure out if we need |
7357 | to make a symbol table entry for it, and if so, create a new entry | |
7358 | and return a pointer to it. | |
7359 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 7360 | used the passed type. */ |
c906108c SS |
7361 | |
7362 | static struct symbol * | |
e7c27a73 | 7363 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 7364 | { |
e7c27a73 | 7365 | struct objfile *objfile = cu->objfile; |
5e2b427d | 7366 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
c906108c SS |
7367 | struct symbol *sym = NULL; |
7368 | char *name; | |
7369 | struct attribute *attr = NULL; | |
7370 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
7371 | CORE_ADDR baseaddr; |
7372 | ||
7373 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 7374 | |
5c4e30ca | 7375 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7376 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7377 | else |
7378 | name = TYPE_NAME (type); | |
7379 | ||
c906108c SS |
7380 | if (name) |
7381 | { | |
4a146b47 | 7382 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7383 | sizeof (struct symbol)); |
7384 | OBJSTAT (objfile, n_syms++); | |
7385 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7386 | |
7387 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7388 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7389 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7390 | |
7391 | /* Default assumptions. | |
c5aa993b | 7392 | Use the passed type or decode it from the die. */ |
176620f1 | 7393 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7394 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7395 | if (type != NULL) |
7396 | SYMBOL_TYPE (sym) = type; | |
7397 | else | |
e7c27a73 | 7398 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7399 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7400 | if (attr) |
7401 | { | |
7402 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7403 | } | |
cb1df416 DJ |
7404 | |
7405 | attr = dwarf2_attr (die, DW_AT_decl_file, cu); | |
7406 | if (attr) | |
7407 | { | |
7408 | int file_index = DW_UNSND (attr); | |
7409 | if (cu->line_header == NULL | |
7410 | || file_index > cu->line_header->num_file_names) | |
7411 | complaint (&symfile_complaints, | |
7412 | _("file index out of range")); | |
1c3d648d | 7413 | else if (file_index > 0) |
cb1df416 DJ |
7414 | { |
7415 | struct file_entry *fe; | |
7416 | fe = &cu->line_header->file_names[file_index - 1]; | |
7417 | SYMBOL_SYMTAB (sym) = fe->symtab; | |
7418 | } | |
7419 | } | |
7420 | ||
c906108c SS |
7421 | switch (die->tag) |
7422 | { | |
7423 | case DW_TAG_label: | |
e142c38c | 7424 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7425 | if (attr) |
7426 | { | |
7427 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7428 | } | |
7429 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7430 | break; | |
7431 | case DW_TAG_subprogram: | |
7432 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7433 | finish_block. */ | |
7434 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7435 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
2cfa0c8d JB |
7436 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
7437 | || cu->language == language_ada) | |
c906108c | 7438 | { |
2cfa0c8d JB |
7439 | /* Subprograms marked external are stored as a global symbol. |
7440 | Ada subprograms, whether marked external or not, are always | |
7441 | stored as a global symbol, because we want to be able to | |
7442 | access them globally. For instance, we want to be able | |
7443 | to break on a nested subprogram without having to | |
7444 | specify the context. */ | |
c906108c SS |
7445 | add_symbol_to_list (sym, &global_symbols); |
7446 | } | |
7447 | else | |
7448 | { | |
e142c38c | 7449 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7450 | } |
7451 | break; | |
7452 | case DW_TAG_variable: | |
7453 | /* Compilation with minimal debug info may result in variables | |
7454 | with missing type entries. Change the misleading `void' type | |
7455 | to something sensible. */ | |
7456 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
64c50499 | 7457 | SYMBOL_TYPE (sym) |
5e2b427d | 7458 | = builtin_type (gdbarch)->nodebug_data_symbol; |
64c50499 | 7459 | |
e142c38c | 7460 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7461 | if (attr) |
7462 | { | |
e7c27a73 | 7463 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7464 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7465 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7466 | add_symbol_to_list (sym, &global_symbols); | |
7467 | else | |
e142c38c | 7468 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7469 | break; |
7470 | } | |
e142c38c | 7471 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7472 | if (attr) |
7473 | { | |
e7c27a73 | 7474 | var_decode_location (attr, sym, cu); |
e142c38c | 7475 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7476 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7477 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7478 | else |
e142c38c | 7479 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7480 | } |
7481 | else | |
7482 | { | |
7483 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7484 | If it is an external symbol and we have type information |
7485 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7486 | The address of the variable will then be determined from | |
7487 | the minimal symbol table whenever the variable is | |
7488 | referenced. */ | |
e142c38c | 7489 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7490 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7491 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7492 | { |
7493 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
7494 | add_symbol_to_list (sym, &global_symbols); | |
7495 | } | |
7496 | } | |
7497 | break; | |
7498 | case DW_TAG_formal_parameter: | |
2a2d4dc3 | 7499 | SYMBOL_IS_ARGUMENT (sym) = 1; |
e142c38c | 7500 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7501 | if (attr) |
7502 | { | |
e7c27a73 | 7503 | var_decode_location (attr, sym, cu); |
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 | 7567 | defines a typedef for "foo". A Java class declaration also |
5eeb2539 | 7568 | defines a typedef for the class. */ |
987504bb | 7569 | if (cu->language == language_cplus |
8c6860bb JB |
7570 | || cu->language == language_java |
7571 | || cu->language == language_ada) | |
63d06c5c | 7572 | { |
d8151005 DJ |
7573 | /* The symbol's name is already allocated along with |
7574 | this objfile, so we don't need to duplicate it for | |
7575 | the type. */ | |
63d06c5c | 7576 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7577 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7578 | } |
7579 | } | |
c906108c SS |
7580 | break; |
7581 | case DW_TAG_typedef: | |
63d06c5c DC |
7582 | if (processing_has_namespace_info |
7583 | && processing_current_prefix[0] != '\0') | |
7584 | { | |
987504bb JJ |
7585 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7586 | processing_current_prefix, | |
7587 | name, cu); | |
63d06c5c DC |
7588 | } |
7589 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7590 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7591 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7592 | break; |
c906108c | 7593 | case DW_TAG_base_type: |
a02abb62 | 7594 | case DW_TAG_subrange_type: |
c906108c | 7595 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7596 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7597 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7598 | break; |
7599 | case DW_TAG_enumerator: | |
63d06c5c DC |
7600 | if (processing_has_namespace_info |
7601 | && processing_current_prefix[0] != '\0') | |
7602 | { | |
987504bb JJ |
7603 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7604 | processing_current_prefix, | |
7605 | name, cu); | |
63d06c5c | 7606 | } |
e142c38c | 7607 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7608 | if (attr) |
7609 | { | |
e7c27a73 | 7610 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7611 | } |
63d06c5c DC |
7612 | { |
7613 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7614 | DW_TAG_class_type, etc. block. */ | |
7615 | ||
7616 | struct pending **list_to_add; | |
7617 | ||
e142c38c | 7618 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7619 | && (cu->language == language_cplus |
7620 | || cu->language == language_java) | |
e142c38c | 7621 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7622 | |
7623 | add_symbol_to_list (sym, list_to_add); | |
7624 | } | |
c906108c | 7625 | break; |
5c4e30ca DC |
7626 | case DW_TAG_namespace: |
7627 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7628 | add_symbol_to_list (sym, &global_symbols); | |
7629 | break; | |
c906108c SS |
7630 | default: |
7631 | /* Not a tag we recognize. Hopefully we aren't processing | |
7632 | trash data, but since we must specifically ignore things | |
7633 | we don't recognize, there is nothing else we should do at | |
7634 | this point. */ | |
e2e0b3e5 | 7635 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7636 | dwarf_tag_name (die->tag)); |
c906108c SS |
7637 | break; |
7638 | } | |
7639 | } | |
7640 | return (sym); | |
7641 | } | |
7642 | ||
7643 | /* Copy constant value from an attribute to a symbol. */ | |
7644 | ||
7645 | static void | |
107d2387 | 7646 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7647 | struct dwarf2_cu *cu) |
c906108c | 7648 | { |
e7c27a73 DJ |
7649 | struct objfile *objfile = cu->objfile; |
7650 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7651 | struct dwarf_block *blk; |
7652 | ||
7653 | switch (attr->form) | |
7654 | { | |
7655 | case DW_FORM_addr: | |
107d2387 | 7656 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 7657 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7658 | cu_header->addr_size, |
7659 | TYPE_LENGTH (SYMBOL_TYPE | |
7660 | (sym))); | |
4e38b386 | 7661 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7662 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7663 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7664 | it's body - store_unsigned_integer. */ | |
7665 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7666 | DW_ADDR (attr)); | |
c906108c SS |
7667 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7668 | break; | |
93b5768b PA |
7669 | case DW_FORM_strp: |
7670 | /* DW_STRING is already allocated on the obstack, point directly | |
7671 | to it. */ | |
7672 | SYMBOL_VALUE_BYTES (sym) = (gdb_byte *) DW_STRING (attr); | |
7673 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7674 | break; | |
c906108c SS |
7675 | case DW_FORM_block1: |
7676 | case DW_FORM_block2: | |
7677 | case DW_FORM_block4: | |
7678 | case DW_FORM_block: | |
7679 | blk = DW_BLOCK (attr); | |
7680 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 7681 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7682 | blk->size, |
7683 | TYPE_LENGTH (SYMBOL_TYPE | |
7684 | (sym))); | |
4e38b386 | 7685 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7686 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7687 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7688 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7689 | break; | |
2df3850c JM |
7690 | |
7691 | /* The DW_AT_const_value attributes are supposed to carry the | |
7692 | symbol's value "represented as it would be on the target | |
7693 | architecture." By the time we get here, it's already been | |
7694 | converted to host endianness, so we just need to sign- or | |
7695 | zero-extend it as appropriate. */ | |
7696 | case DW_FORM_data1: | |
7697 | dwarf2_const_value_data (attr, sym, 8); | |
7698 | break; | |
c906108c | 7699 | case DW_FORM_data2: |
2df3850c JM |
7700 | dwarf2_const_value_data (attr, sym, 16); |
7701 | break; | |
c906108c | 7702 | case DW_FORM_data4: |
2df3850c JM |
7703 | dwarf2_const_value_data (attr, sym, 32); |
7704 | break; | |
c906108c | 7705 | case DW_FORM_data8: |
2df3850c JM |
7706 | dwarf2_const_value_data (attr, sym, 64); |
7707 | break; | |
7708 | ||
c906108c | 7709 | case DW_FORM_sdata: |
2df3850c JM |
7710 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7711 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7712 | break; | |
7713 | ||
c906108c SS |
7714 | case DW_FORM_udata: |
7715 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
7716 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7717 | break; | |
2df3850c | 7718 | |
c906108c | 7719 | default: |
4d3c2250 | 7720 | complaint (&symfile_complaints, |
e2e0b3e5 | 7721 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 7722 | dwarf_form_name (attr->form)); |
c906108c SS |
7723 | SYMBOL_VALUE (sym) = 0; |
7724 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7725 | break; | |
7726 | } | |
7727 | } | |
7728 | ||
2df3850c JM |
7729 | |
7730 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
7731 | or zero-extend it as appropriate for the symbol's type. */ | |
7732 | static void | |
7733 | dwarf2_const_value_data (struct attribute *attr, | |
7734 | struct symbol *sym, | |
7735 | int bits) | |
7736 | { | |
7737 | LONGEST l = DW_UNSND (attr); | |
7738 | ||
7739 | if (bits < sizeof (l) * 8) | |
7740 | { | |
7741 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
7742 | l &= ((LONGEST) 1 << bits) - 1; | |
7743 | else | |
bf9198f1 | 7744 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
7745 | } |
7746 | ||
7747 | SYMBOL_VALUE (sym) = l; | |
7748 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7749 | } | |
7750 | ||
7751 | ||
c906108c SS |
7752 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
7753 | ||
7754 | static struct type * | |
e7c27a73 | 7755 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7756 | { |
5e2b427d | 7757 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
c906108c SS |
7758 | struct type *type; |
7759 | struct attribute *type_attr; | |
7760 | struct die_info *type_die; | |
c906108c | 7761 | |
e142c38c | 7762 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
7763 | if (!type_attr) |
7764 | { | |
7765 | /* A missing DW_AT_type represents a void type. */ | |
5e2b427d | 7766 | return builtin_type (gdbarch)->builtin_void; |
c906108c SS |
7767 | } |
7768 | else | |
10b3939b DJ |
7769 | type_die = follow_die_ref (die, type_attr, cu); |
7770 | ||
e7c27a73 | 7771 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7772 | if (!type) |
7773 | { | |
7774 | dump_die (type_die); | |
8a3fe4f8 | 7775 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 7776 | cu->objfile->name); |
c906108c SS |
7777 | } |
7778 | return type; | |
7779 | } | |
7780 | ||
7781 | /* Return the containing type of the die in question using its | |
7782 | DW_AT_containing_type attribute. */ | |
7783 | ||
7784 | static struct type * | |
e7c27a73 | 7785 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7786 | { |
7787 | struct type *type = NULL; | |
7788 | struct attribute *type_attr; | |
7789 | struct die_info *type_die = NULL; | |
c906108c | 7790 | |
e142c38c | 7791 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
7792 | if (type_attr) |
7793 | { | |
10b3939b | 7794 | type_die = follow_die_ref (die, type_attr, cu); |
e7c27a73 | 7795 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7796 | } |
7797 | if (!type) | |
7798 | { | |
7799 | if (type_die) | |
7800 | dump_die (type_die); | |
8a3fe4f8 | 7801 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 7802 | cu->objfile->name); |
c906108c SS |
7803 | } |
7804 | return type; | |
7805 | } | |
7806 | ||
c906108c | 7807 | static struct type * |
e7c27a73 | 7808 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7809 | { |
f792889a DJ |
7810 | struct type *this_type; |
7811 | ||
7812 | this_type = read_type_die (die, cu); | |
7813 | if (!this_type) | |
c906108c | 7814 | { |
f792889a DJ |
7815 | dump_die (die); |
7816 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), | |
7817 | cu->objfile->name); | |
c906108c | 7818 | } |
f792889a | 7819 | return this_type; |
c906108c SS |
7820 | } |
7821 | ||
f792889a | 7822 | static struct type * |
e7c27a73 | 7823 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7824 | { |
f792889a DJ |
7825 | char *prefix; |
7826 | const char *old_prefix; | |
7827 | struct cleanup *back_to; | |
7828 | struct type *this_type; | |
7829 | ||
7830 | this_type = get_die_type (die, cu); | |
7831 | if (this_type) | |
7832 | return this_type; | |
7833 | ||
7834 | prefix = determine_prefix (die, cu); | |
7835 | old_prefix = processing_current_prefix; | |
7836 | back_to = make_cleanup (xfree, prefix); | |
63d06c5c | 7837 | processing_current_prefix = prefix; |
f792889a | 7838 | |
c906108c SS |
7839 | switch (die->tag) |
7840 | { | |
7841 | case DW_TAG_class_type: | |
680b30c7 | 7842 | case DW_TAG_interface_type: |
c906108c SS |
7843 | case DW_TAG_structure_type: |
7844 | case DW_TAG_union_type: | |
f792889a | 7845 | this_type = read_structure_type (die, cu); |
c906108c SS |
7846 | break; |
7847 | case DW_TAG_enumeration_type: | |
f792889a | 7848 | this_type = read_enumeration_type (die, cu); |
c906108c SS |
7849 | break; |
7850 | case DW_TAG_subprogram: | |
7851 | case DW_TAG_subroutine_type: | |
f792889a | 7852 | this_type = read_subroutine_type (die, cu); |
c906108c SS |
7853 | break; |
7854 | case DW_TAG_array_type: | |
f792889a | 7855 | this_type = read_array_type (die, cu); |
c906108c | 7856 | break; |
72019c9c | 7857 | case DW_TAG_set_type: |
f792889a | 7858 | this_type = read_set_type (die, cu); |
72019c9c | 7859 | break; |
c906108c | 7860 | case DW_TAG_pointer_type: |
f792889a | 7861 | this_type = read_tag_pointer_type (die, cu); |
c906108c SS |
7862 | break; |
7863 | case DW_TAG_ptr_to_member_type: | |
f792889a | 7864 | this_type = read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
7865 | break; |
7866 | case DW_TAG_reference_type: | |
f792889a | 7867 | this_type = read_tag_reference_type (die, cu); |
c906108c SS |
7868 | break; |
7869 | case DW_TAG_const_type: | |
f792889a | 7870 | this_type = read_tag_const_type (die, cu); |
c906108c SS |
7871 | break; |
7872 | case DW_TAG_volatile_type: | |
f792889a | 7873 | this_type = read_tag_volatile_type (die, cu); |
c906108c SS |
7874 | break; |
7875 | case DW_TAG_string_type: | |
f792889a | 7876 | this_type = read_tag_string_type (die, cu); |
c906108c SS |
7877 | break; |
7878 | case DW_TAG_typedef: | |
f792889a | 7879 | this_type = read_typedef (die, cu); |
c906108c | 7880 | break; |
a02abb62 | 7881 | case DW_TAG_subrange_type: |
f792889a | 7882 | this_type = read_subrange_type (die, cu); |
a02abb62 | 7883 | break; |
c906108c | 7884 | case DW_TAG_base_type: |
f792889a | 7885 | this_type = read_base_type (die, cu); |
c906108c | 7886 | break; |
81a17f79 | 7887 | case DW_TAG_unspecified_type: |
f792889a | 7888 | this_type = read_unspecified_type (die, cu); |
81a17f79 | 7889 | break; |
c906108c | 7890 | default: |
a1f5b845 | 7891 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 7892 | dwarf_tag_name (die->tag)); |
c906108c SS |
7893 | break; |
7894 | } | |
63d06c5c DC |
7895 | |
7896 | processing_current_prefix = old_prefix; | |
7897 | do_cleanups (back_to); | |
f792889a | 7898 | return this_type; |
63d06c5c DC |
7899 | } |
7900 | ||
fdde2d81 DC |
7901 | /* Return the name of the namespace/class that DIE is defined within, |
7902 | or "" if we can't tell. The caller should xfree the result. */ | |
7903 | ||
7904 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
7905 | therein) for an example of how to use this function to deal with | |
7906 | DW_AT_specification. */ | |
7907 | ||
7908 | static char * | |
e142c38c | 7909 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
7910 | { |
7911 | struct die_info *parent; | |
7912 | ||
987504bb JJ |
7913 | if (cu->language != language_cplus |
7914 | && cu->language != language_java) | |
63d06c5c DC |
7915 | return NULL; |
7916 | ||
7917 | parent = die->parent; | |
7918 | ||
7919 | if (parent == NULL) | |
7920 | { | |
8176b9b8 | 7921 | return xstrdup (""); |
63d06c5c DC |
7922 | } |
7923 | else | |
7924 | { | |
63d06c5c DC |
7925 | switch (parent->tag) { |
7926 | case DW_TAG_namespace: | |
7927 | { | |
8176b9b8 DC |
7928 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
7929 | before doing this check? */ | |
f792889a DJ |
7930 | struct type *parent_type = get_die_type (parent, cu); |
7931 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
8176b9b8 | 7932 | { |
f792889a | 7933 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
8176b9b8 DC |
7934 | } |
7935 | else | |
7936 | { | |
7937 | int dummy; | |
7938 | char *parent_prefix = determine_prefix (parent, cu); | |
987504bb | 7939 | char *retval = typename_concat (NULL, parent_prefix, |
8176b9b8 | 7940 | namespace_name (parent, &dummy, |
987504bb JJ |
7941 | cu), |
7942 | cu); | |
8176b9b8 DC |
7943 | xfree (parent_prefix); |
7944 | return retval; | |
7945 | } | |
63d06c5c DC |
7946 | } |
7947 | break; | |
7948 | case DW_TAG_class_type: | |
680b30c7 | 7949 | case DW_TAG_interface_type: |
63d06c5c DC |
7950 | case DW_TAG_structure_type: |
7951 | { | |
f792889a DJ |
7952 | struct type *parent_type = get_die_type (parent, cu); |
7953 | if (parent_type != NULL && TYPE_TAG_NAME (parent_type) != NULL) | |
63d06c5c | 7954 | { |
f792889a | 7955 | return xstrdup (TYPE_TAG_NAME (parent_type)); |
63d06c5c DC |
7956 | } |
7957 | else | |
8176b9b8 DC |
7958 | { |
7959 | const char *old_prefix = processing_current_prefix; | |
7960 | char *new_prefix = determine_prefix (parent, cu); | |
7961 | char *retval; | |
7962 | ||
7963 | processing_current_prefix = new_prefix; | |
7964 | retval = determine_class_name (parent, cu); | |
7965 | processing_current_prefix = old_prefix; | |
7966 | ||
7967 | xfree (new_prefix); | |
7968 | return retval; | |
7969 | } | |
63d06c5c | 7970 | } |
63d06c5c | 7971 | default: |
8176b9b8 | 7972 | return determine_prefix (parent, cu); |
63d06c5c | 7973 | } |
63d06c5c DC |
7974 | } |
7975 | } | |
7976 | ||
987504bb JJ |
7977 | /* Return a newly-allocated string formed by concatenating PREFIX and |
7978 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
7979 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
7980 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
7981 | is used to determine the language and hence, the appropriate separator. */ | |
7982 | ||
7983 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
7984 | |
7985 | static char * | |
987504bb JJ |
7986 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
7987 | struct dwarf2_cu *cu) | |
63d06c5c | 7988 | { |
987504bb | 7989 | char *sep; |
63d06c5c | 7990 | |
987504bb JJ |
7991 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
7992 | sep = ""; | |
7993 | else if (cu->language == language_java) | |
7994 | sep = "."; | |
7995 | else | |
7996 | sep = "::"; | |
63d06c5c | 7997 | |
987504bb JJ |
7998 | if (obs == NULL) |
7999 | { | |
8000 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
8001 | retval[0] = '\0'; | |
8002 | ||
8003 | if (prefix) | |
8004 | { | |
8005 | strcpy (retval, prefix); | |
8006 | strcat (retval, sep); | |
8007 | } | |
8008 | if (suffix) | |
8009 | strcat (retval, suffix); | |
8010 | ||
63d06c5c DC |
8011 | return retval; |
8012 | } | |
987504bb JJ |
8013 | else |
8014 | { | |
8015 | /* We have an obstack. */ | |
8016 | return obconcat (obs, prefix, sep, suffix); | |
8017 | } | |
63d06c5c DC |
8018 | } |
8019 | ||
c906108c SS |
8020 | #if 0 |
8021 | struct die_info * | |
fba45db2 | 8022 | copy_die (struct die_info *old_die) |
c906108c SS |
8023 | { |
8024 | struct die_info *new_die; | |
8025 | int i, num_attrs; | |
8026 | ||
8027 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
8028 | memset (new_die, 0, sizeof (struct die_info)); | |
8029 | ||
8030 | new_die->tag = old_die->tag; | |
8031 | new_die->has_children = old_die->has_children; | |
8032 | new_die->abbrev = old_die->abbrev; | |
8033 | new_die->offset = old_die->offset; | |
c906108c SS |
8034 | |
8035 | num_attrs = old_die->num_attrs; | |
8036 | new_die->num_attrs = num_attrs; | |
8037 | new_die->attrs = (struct attribute *) | |
8038 | xmalloc (num_attrs * sizeof (struct attribute)); | |
8039 | ||
8040 | for (i = 0; i < old_die->num_attrs; ++i) | |
8041 | { | |
8042 | new_die->attrs[i].name = old_die->attrs[i].name; | |
8043 | new_die->attrs[i].form = old_die->attrs[i].form; | |
8044 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
8045 | } | |
8046 | ||
8047 | new_die->next = NULL; | |
8048 | return new_die; | |
8049 | } | |
8050 | #endif | |
8051 | ||
8052 | /* Return sibling of die, NULL if no sibling. */ | |
8053 | ||
f9aca02d | 8054 | static struct die_info * |
fba45db2 | 8055 | sibling_die (struct die_info *die) |
c906108c | 8056 | { |
639d11d3 | 8057 | return die->sibling; |
c906108c SS |
8058 | } |
8059 | ||
8060 | /* Get linkage name of a die, return NULL if not found. */ | |
8061 | ||
8062 | static char * | |
e142c38c | 8063 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
8064 | { |
8065 | struct attribute *attr; | |
8066 | ||
e142c38c | 8067 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
8068 | if (attr && DW_STRING (attr)) |
8069 | return DW_STRING (attr); | |
e142c38c | 8070 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
8071 | if (attr && DW_STRING (attr)) |
8072 | return DW_STRING (attr); | |
8073 | return NULL; | |
8074 | } | |
8075 | ||
9219021c DC |
8076 | /* Get name of a die, return NULL if not found. */ |
8077 | ||
8078 | static char * | |
e142c38c | 8079 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8080 | { |
8081 | struct attribute *attr; | |
8082 | ||
e142c38c | 8083 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
8084 | if (attr && DW_STRING (attr)) |
8085 | return DW_STRING (attr); | |
8086 | return NULL; | |
8087 | } | |
8088 | ||
8089 | /* Return the die that this die in an extension of, or NULL if there | |
8090 | is none. */ | |
8091 | ||
8092 | static struct die_info * | |
e142c38c | 8093 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
8094 | { |
8095 | struct attribute *attr; | |
9219021c | 8096 | |
e142c38c | 8097 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
8098 | if (attr == NULL) |
8099 | return NULL; | |
8100 | ||
10b3939b | 8101 | return follow_die_ref (die, attr, cu); |
9219021c DC |
8102 | } |
8103 | ||
c906108c SS |
8104 | /* Convert a DIE tag into its string name. */ |
8105 | ||
8106 | static char * | |
aa1ee363 | 8107 | dwarf_tag_name (unsigned tag) |
c906108c SS |
8108 | { |
8109 | switch (tag) | |
8110 | { | |
8111 | case DW_TAG_padding: | |
8112 | return "DW_TAG_padding"; | |
8113 | case DW_TAG_array_type: | |
8114 | return "DW_TAG_array_type"; | |
8115 | case DW_TAG_class_type: | |
8116 | return "DW_TAG_class_type"; | |
8117 | case DW_TAG_entry_point: | |
8118 | return "DW_TAG_entry_point"; | |
8119 | case DW_TAG_enumeration_type: | |
8120 | return "DW_TAG_enumeration_type"; | |
8121 | case DW_TAG_formal_parameter: | |
8122 | return "DW_TAG_formal_parameter"; | |
8123 | case DW_TAG_imported_declaration: | |
8124 | return "DW_TAG_imported_declaration"; | |
8125 | case DW_TAG_label: | |
8126 | return "DW_TAG_label"; | |
8127 | case DW_TAG_lexical_block: | |
8128 | return "DW_TAG_lexical_block"; | |
8129 | case DW_TAG_member: | |
8130 | return "DW_TAG_member"; | |
8131 | case DW_TAG_pointer_type: | |
8132 | return "DW_TAG_pointer_type"; | |
8133 | case DW_TAG_reference_type: | |
8134 | return "DW_TAG_reference_type"; | |
8135 | case DW_TAG_compile_unit: | |
8136 | return "DW_TAG_compile_unit"; | |
8137 | case DW_TAG_string_type: | |
8138 | return "DW_TAG_string_type"; | |
8139 | case DW_TAG_structure_type: | |
8140 | return "DW_TAG_structure_type"; | |
8141 | case DW_TAG_subroutine_type: | |
8142 | return "DW_TAG_subroutine_type"; | |
8143 | case DW_TAG_typedef: | |
8144 | return "DW_TAG_typedef"; | |
8145 | case DW_TAG_union_type: | |
8146 | return "DW_TAG_union_type"; | |
8147 | case DW_TAG_unspecified_parameters: | |
8148 | return "DW_TAG_unspecified_parameters"; | |
8149 | case DW_TAG_variant: | |
8150 | return "DW_TAG_variant"; | |
8151 | case DW_TAG_common_block: | |
8152 | return "DW_TAG_common_block"; | |
8153 | case DW_TAG_common_inclusion: | |
8154 | return "DW_TAG_common_inclusion"; | |
8155 | case DW_TAG_inheritance: | |
8156 | return "DW_TAG_inheritance"; | |
8157 | case DW_TAG_inlined_subroutine: | |
8158 | return "DW_TAG_inlined_subroutine"; | |
8159 | case DW_TAG_module: | |
8160 | return "DW_TAG_module"; | |
8161 | case DW_TAG_ptr_to_member_type: | |
8162 | return "DW_TAG_ptr_to_member_type"; | |
8163 | case DW_TAG_set_type: | |
8164 | return "DW_TAG_set_type"; | |
8165 | case DW_TAG_subrange_type: | |
8166 | return "DW_TAG_subrange_type"; | |
8167 | case DW_TAG_with_stmt: | |
8168 | return "DW_TAG_with_stmt"; | |
8169 | case DW_TAG_access_declaration: | |
8170 | return "DW_TAG_access_declaration"; | |
8171 | case DW_TAG_base_type: | |
8172 | return "DW_TAG_base_type"; | |
8173 | case DW_TAG_catch_block: | |
8174 | return "DW_TAG_catch_block"; | |
8175 | case DW_TAG_const_type: | |
8176 | return "DW_TAG_const_type"; | |
8177 | case DW_TAG_constant: | |
8178 | return "DW_TAG_constant"; | |
8179 | case DW_TAG_enumerator: | |
8180 | return "DW_TAG_enumerator"; | |
8181 | case DW_TAG_file_type: | |
8182 | return "DW_TAG_file_type"; | |
8183 | case DW_TAG_friend: | |
8184 | return "DW_TAG_friend"; | |
8185 | case DW_TAG_namelist: | |
8186 | return "DW_TAG_namelist"; | |
8187 | case DW_TAG_namelist_item: | |
8188 | return "DW_TAG_namelist_item"; | |
8189 | case DW_TAG_packed_type: | |
8190 | return "DW_TAG_packed_type"; | |
8191 | case DW_TAG_subprogram: | |
8192 | return "DW_TAG_subprogram"; | |
8193 | case DW_TAG_template_type_param: | |
8194 | return "DW_TAG_template_type_param"; | |
8195 | case DW_TAG_template_value_param: | |
8196 | return "DW_TAG_template_value_param"; | |
8197 | case DW_TAG_thrown_type: | |
8198 | return "DW_TAG_thrown_type"; | |
8199 | case DW_TAG_try_block: | |
8200 | return "DW_TAG_try_block"; | |
8201 | case DW_TAG_variant_part: | |
8202 | return "DW_TAG_variant_part"; | |
8203 | case DW_TAG_variable: | |
8204 | return "DW_TAG_variable"; | |
8205 | case DW_TAG_volatile_type: | |
8206 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
8207 | case DW_TAG_dwarf_procedure: |
8208 | return "DW_TAG_dwarf_procedure"; | |
8209 | case DW_TAG_restrict_type: | |
8210 | return "DW_TAG_restrict_type"; | |
8211 | case DW_TAG_interface_type: | |
8212 | return "DW_TAG_interface_type"; | |
8213 | case DW_TAG_namespace: | |
8214 | return "DW_TAG_namespace"; | |
8215 | case DW_TAG_imported_module: | |
8216 | return "DW_TAG_imported_module"; | |
8217 | case DW_TAG_unspecified_type: | |
8218 | return "DW_TAG_unspecified_type"; | |
8219 | case DW_TAG_partial_unit: | |
8220 | return "DW_TAG_partial_unit"; | |
8221 | case DW_TAG_imported_unit: | |
8222 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
8223 | case DW_TAG_condition: |
8224 | return "DW_TAG_condition"; | |
8225 | case DW_TAG_shared_type: | |
8226 | return "DW_TAG_shared_type"; | |
c906108c SS |
8227 | case DW_TAG_MIPS_loop: |
8228 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
8229 | case DW_TAG_HP_array_descriptor: |
8230 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
8231 | case DW_TAG_format_label: |
8232 | return "DW_TAG_format_label"; | |
8233 | case DW_TAG_function_template: | |
8234 | return "DW_TAG_function_template"; | |
8235 | case DW_TAG_class_template: | |
8236 | return "DW_TAG_class_template"; | |
b7619582 GF |
8237 | case DW_TAG_GNU_BINCL: |
8238 | return "DW_TAG_GNU_BINCL"; | |
8239 | case DW_TAG_GNU_EINCL: | |
8240 | return "DW_TAG_GNU_EINCL"; | |
8241 | case DW_TAG_upc_shared_type: | |
8242 | return "DW_TAG_upc_shared_type"; | |
8243 | case DW_TAG_upc_strict_type: | |
8244 | return "DW_TAG_upc_strict_type"; | |
8245 | case DW_TAG_upc_relaxed_type: | |
8246 | return "DW_TAG_upc_relaxed_type"; | |
8247 | case DW_TAG_PGI_kanji_type: | |
8248 | return "DW_TAG_PGI_kanji_type"; | |
8249 | case DW_TAG_PGI_interface_block: | |
8250 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
8251 | default: |
8252 | return "DW_TAG_<unknown>"; | |
8253 | } | |
8254 | } | |
8255 | ||
8256 | /* Convert a DWARF attribute code into its string name. */ | |
8257 | ||
8258 | static char * | |
aa1ee363 | 8259 | dwarf_attr_name (unsigned attr) |
c906108c SS |
8260 | { |
8261 | switch (attr) | |
8262 | { | |
8263 | case DW_AT_sibling: | |
8264 | return "DW_AT_sibling"; | |
8265 | case DW_AT_location: | |
8266 | return "DW_AT_location"; | |
8267 | case DW_AT_name: | |
8268 | return "DW_AT_name"; | |
8269 | case DW_AT_ordering: | |
8270 | return "DW_AT_ordering"; | |
8271 | case DW_AT_subscr_data: | |
8272 | return "DW_AT_subscr_data"; | |
8273 | case DW_AT_byte_size: | |
8274 | return "DW_AT_byte_size"; | |
8275 | case DW_AT_bit_offset: | |
8276 | return "DW_AT_bit_offset"; | |
8277 | case DW_AT_bit_size: | |
8278 | return "DW_AT_bit_size"; | |
8279 | case DW_AT_element_list: | |
8280 | return "DW_AT_element_list"; | |
8281 | case DW_AT_stmt_list: | |
8282 | return "DW_AT_stmt_list"; | |
8283 | case DW_AT_low_pc: | |
8284 | return "DW_AT_low_pc"; | |
8285 | case DW_AT_high_pc: | |
8286 | return "DW_AT_high_pc"; | |
8287 | case DW_AT_language: | |
8288 | return "DW_AT_language"; | |
8289 | case DW_AT_member: | |
8290 | return "DW_AT_member"; | |
8291 | case DW_AT_discr: | |
8292 | return "DW_AT_discr"; | |
8293 | case DW_AT_discr_value: | |
8294 | return "DW_AT_discr_value"; | |
8295 | case DW_AT_visibility: | |
8296 | return "DW_AT_visibility"; | |
8297 | case DW_AT_import: | |
8298 | return "DW_AT_import"; | |
8299 | case DW_AT_string_length: | |
8300 | return "DW_AT_string_length"; | |
8301 | case DW_AT_common_reference: | |
8302 | return "DW_AT_common_reference"; | |
8303 | case DW_AT_comp_dir: | |
8304 | return "DW_AT_comp_dir"; | |
8305 | case DW_AT_const_value: | |
8306 | return "DW_AT_const_value"; | |
8307 | case DW_AT_containing_type: | |
8308 | return "DW_AT_containing_type"; | |
8309 | case DW_AT_default_value: | |
8310 | return "DW_AT_default_value"; | |
8311 | case DW_AT_inline: | |
8312 | return "DW_AT_inline"; | |
8313 | case DW_AT_is_optional: | |
8314 | return "DW_AT_is_optional"; | |
8315 | case DW_AT_lower_bound: | |
8316 | return "DW_AT_lower_bound"; | |
8317 | case DW_AT_producer: | |
8318 | return "DW_AT_producer"; | |
8319 | case DW_AT_prototyped: | |
8320 | return "DW_AT_prototyped"; | |
8321 | case DW_AT_return_addr: | |
8322 | return "DW_AT_return_addr"; | |
8323 | case DW_AT_start_scope: | |
8324 | return "DW_AT_start_scope"; | |
09fa0d7c JK |
8325 | case DW_AT_bit_stride: |
8326 | return "DW_AT_bit_stride"; | |
c906108c SS |
8327 | case DW_AT_upper_bound: |
8328 | return "DW_AT_upper_bound"; | |
8329 | case DW_AT_abstract_origin: | |
8330 | return "DW_AT_abstract_origin"; | |
8331 | case DW_AT_accessibility: | |
8332 | return "DW_AT_accessibility"; | |
8333 | case DW_AT_address_class: | |
8334 | return "DW_AT_address_class"; | |
8335 | case DW_AT_artificial: | |
8336 | return "DW_AT_artificial"; | |
8337 | case DW_AT_base_types: | |
8338 | return "DW_AT_base_types"; | |
8339 | case DW_AT_calling_convention: | |
8340 | return "DW_AT_calling_convention"; | |
8341 | case DW_AT_count: | |
8342 | return "DW_AT_count"; | |
8343 | case DW_AT_data_member_location: | |
8344 | return "DW_AT_data_member_location"; | |
8345 | case DW_AT_decl_column: | |
8346 | return "DW_AT_decl_column"; | |
8347 | case DW_AT_decl_file: | |
8348 | return "DW_AT_decl_file"; | |
8349 | case DW_AT_decl_line: | |
8350 | return "DW_AT_decl_line"; | |
8351 | case DW_AT_declaration: | |
8352 | return "DW_AT_declaration"; | |
8353 | case DW_AT_discr_list: | |
8354 | return "DW_AT_discr_list"; | |
8355 | case DW_AT_encoding: | |
8356 | return "DW_AT_encoding"; | |
8357 | case DW_AT_external: | |
8358 | return "DW_AT_external"; | |
8359 | case DW_AT_frame_base: | |
8360 | return "DW_AT_frame_base"; | |
8361 | case DW_AT_friend: | |
8362 | return "DW_AT_friend"; | |
8363 | case DW_AT_identifier_case: | |
8364 | return "DW_AT_identifier_case"; | |
8365 | case DW_AT_macro_info: | |
8366 | return "DW_AT_macro_info"; | |
8367 | case DW_AT_namelist_items: | |
8368 | return "DW_AT_namelist_items"; | |
8369 | case DW_AT_priority: | |
8370 | return "DW_AT_priority"; | |
8371 | case DW_AT_segment: | |
8372 | return "DW_AT_segment"; | |
8373 | case DW_AT_specification: | |
8374 | return "DW_AT_specification"; | |
8375 | case DW_AT_static_link: | |
8376 | return "DW_AT_static_link"; | |
8377 | case DW_AT_type: | |
8378 | return "DW_AT_type"; | |
8379 | case DW_AT_use_location: | |
8380 | return "DW_AT_use_location"; | |
8381 | case DW_AT_variable_parameter: | |
8382 | return "DW_AT_variable_parameter"; | |
8383 | case DW_AT_virtuality: | |
8384 | return "DW_AT_virtuality"; | |
8385 | case DW_AT_vtable_elem_location: | |
8386 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8387 | /* DWARF 3 values. */ |
d9fa45fe DC |
8388 | case DW_AT_allocated: |
8389 | return "DW_AT_allocated"; | |
8390 | case DW_AT_associated: | |
8391 | return "DW_AT_associated"; | |
8392 | case DW_AT_data_location: | |
8393 | return "DW_AT_data_location"; | |
09fa0d7c JK |
8394 | case DW_AT_byte_stride: |
8395 | return "DW_AT_byte_stride"; | |
d9fa45fe DC |
8396 | case DW_AT_entry_pc: |
8397 | return "DW_AT_entry_pc"; | |
8398 | case DW_AT_use_UTF8: | |
8399 | return "DW_AT_use_UTF8"; | |
8400 | case DW_AT_extension: | |
8401 | return "DW_AT_extension"; | |
8402 | case DW_AT_ranges: | |
8403 | return "DW_AT_ranges"; | |
8404 | case DW_AT_trampoline: | |
8405 | return "DW_AT_trampoline"; | |
8406 | case DW_AT_call_column: | |
8407 | return "DW_AT_call_column"; | |
8408 | case DW_AT_call_file: | |
8409 | return "DW_AT_call_file"; | |
8410 | case DW_AT_call_line: | |
8411 | return "DW_AT_call_line"; | |
b7619582 GF |
8412 | case DW_AT_description: |
8413 | return "DW_AT_description"; | |
8414 | case DW_AT_binary_scale: | |
8415 | return "DW_AT_binary_scale"; | |
8416 | case DW_AT_decimal_scale: | |
8417 | return "DW_AT_decimal_scale"; | |
8418 | case DW_AT_small: | |
8419 | return "DW_AT_small"; | |
8420 | case DW_AT_decimal_sign: | |
8421 | return "DW_AT_decimal_sign"; | |
8422 | case DW_AT_digit_count: | |
8423 | return "DW_AT_digit_count"; | |
8424 | case DW_AT_picture_string: | |
8425 | return "DW_AT_picture_string"; | |
8426 | case DW_AT_mutable: | |
8427 | return "DW_AT_mutable"; | |
8428 | case DW_AT_threads_scaled: | |
8429 | return "DW_AT_threads_scaled"; | |
8430 | case DW_AT_explicit: | |
8431 | return "DW_AT_explicit"; | |
8432 | case DW_AT_object_pointer: | |
8433 | return "DW_AT_object_pointer"; | |
8434 | case DW_AT_endianity: | |
8435 | return "DW_AT_endianity"; | |
8436 | case DW_AT_elemental: | |
8437 | return "DW_AT_elemental"; | |
8438 | case DW_AT_pure: | |
8439 | return "DW_AT_pure"; | |
8440 | case DW_AT_recursive: | |
8441 | return "DW_AT_recursive"; | |
c906108c | 8442 | #ifdef MIPS |
b7619582 | 8443 | /* SGI/MIPS extensions. */ |
c906108c SS |
8444 | case DW_AT_MIPS_fde: |
8445 | return "DW_AT_MIPS_fde"; | |
8446 | case DW_AT_MIPS_loop_begin: | |
8447 | return "DW_AT_MIPS_loop_begin"; | |
8448 | case DW_AT_MIPS_tail_loop_begin: | |
8449 | return "DW_AT_MIPS_tail_loop_begin"; | |
8450 | case DW_AT_MIPS_epilog_begin: | |
8451 | return "DW_AT_MIPS_epilog_begin"; | |
8452 | case DW_AT_MIPS_loop_unroll_factor: | |
8453 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8454 | case DW_AT_MIPS_software_pipeline_depth: | |
8455 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8456 | case DW_AT_MIPS_linkage_name: | |
8457 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8458 | case DW_AT_MIPS_stride: |
8459 | return "DW_AT_MIPS_stride"; | |
8460 | case DW_AT_MIPS_abstract_name: | |
8461 | return "DW_AT_MIPS_abstract_name"; | |
8462 | case DW_AT_MIPS_clone_origin: | |
8463 | return "DW_AT_MIPS_clone_origin"; | |
8464 | case DW_AT_MIPS_has_inlines: | |
8465 | return "DW_AT_MIPS_has_inlines"; | |
8466 | #endif | |
8467 | /* HP extensions. */ | |
8468 | case DW_AT_HP_block_index: | |
8469 | return "DW_AT_HP_block_index"; | |
8470 | case DW_AT_HP_unmodifiable: | |
8471 | return "DW_AT_HP_unmodifiable"; | |
8472 | case DW_AT_HP_actuals_stmt_list: | |
8473 | return "DW_AT_HP_actuals_stmt_list"; | |
8474 | case DW_AT_HP_proc_per_section: | |
8475 | return "DW_AT_HP_proc_per_section"; | |
8476 | case DW_AT_HP_raw_data_ptr: | |
8477 | return "DW_AT_HP_raw_data_ptr"; | |
8478 | case DW_AT_HP_pass_by_reference: | |
8479 | return "DW_AT_HP_pass_by_reference"; | |
8480 | case DW_AT_HP_opt_level: | |
8481 | return "DW_AT_HP_opt_level"; | |
8482 | case DW_AT_HP_prof_version_id: | |
8483 | return "DW_AT_HP_prof_version_id"; | |
8484 | case DW_AT_HP_opt_flags: | |
8485 | return "DW_AT_HP_opt_flags"; | |
8486 | case DW_AT_HP_cold_region_low_pc: | |
8487 | return "DW_AT_HP_cold_region_low_pc"; | |
8488 | case DW_AT_HP_cold_region_high_pc: | |
8489 | return "DW_AT_HP_cold_region_high_pc"; | |
8490 | case DW_AT_HP_all_variables_modifiable: | |
8491 | return "DW_AT_HP_all_variables_modifiable"; | |
8492 | case DW_AT_HP_linkage_name: | |
8493 | return "DW_AT_HP_linkage_name"; | |
8494 | case DW_AT_HP_prof_flags: | |
8495 | return "DW_AT_HP_prof_flags"; | |
8496 | /* GNU extensions. */ | |
c906108c SS |
8497 | case DW_AT_sf_names: |
8498 | return "DW_AT_sf_names"; | |
8499 | case DW_AT_src_info: | |
8500 | return "DW_AT_src_info"; | |
8501 | case DW_AT_mac_info: | |
8502 | return "DW_AT_mac_info"; | |
8503 | case DW_AT_src_coords: | |
8504 | return "DW_AT_src_coords"; | |
8505 | case DW_AT_body_begin: | |
8506 | return "DW_AT_body_begin"; | |
8507 | case DW_AT_body_end: | |
8508 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8509 | case DW_AT_GNU_vector: |
8510 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8511 | /* VMS extensions. */ |
8512 | case DW_AT_VMS_rtnbeg_pd_address: | |
8513 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8514 | /* UPC extension. */ | |
8515 | case DW_AT_upc_threads_scaled: | |
8516 | return "DW_AT_upc_threads_scaled"; | |
8517 | /* PGI (STMicroelectronics) extensions. */ | |
8518 | case DW_AT_PGI_lbase: | |
8519 | return "DW_AT_PGI_lbase"; | |
8520 | case DW_AT_PGI_soffset: | |
8521 | return "DW_AT_PGI_soffset"; | |
8522 | case DW_AT_PGI_lstride: | |
8523 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8524 | default: |
8525 | return "DW_AT_<unknown>"; | |
8526 | } | |
8527 | } | |
8528 | ||
8529 | /* Convert a DWARF value form code into its string name. */ | |
8530 | ||
8531 | static char * | |
aa1ee363 | 8532 | dwarf_form_name (unsigned form) |
c906108c SS |
8533 | { |
8534 | switch (form) | |
8535 | { | |
8536 | case DW_FORM_addr: | |
8537 | return "DW_FORM_addr"; | |
8538 | case DW_FORM_block2: | |
8539 | return "DW_FORM_block2"; | |
8540 | case DW_FORM_block4: | |
8541 | return "DW_FORM_block4"; | |
8542 | case DW_FORM_data2: | |
8543 | return "DW_FORM_data2"; | |
8544 | case DW_FORM_data4: | |
8545 | return "DW_FORM_data4"; | |
8546 | case DW_FORM_data8: | |
8547 | return "DW_FORM_data8"; | |
8548 | case DW_FORM_string: | |
8549 | return "DW_FORM_string"; | |
8550 | case DW_FORM_block: | |
8551 | return "DW_FORM_block"; | |
8552 | case DW_FORM_block1: | |
8553 | return "DW_FORM_block1"; | |
8554 | case DW_FORM_data1: | |
8555 | return "DW_FORM_data1"; | |
8556 | case DW_FORM_flag: | |
8557 | return "DW_FORM_flag"; | |
8558 | case DW_FORM_sdata: | |
8559 | return "DW_FORM_sdata"; | |
8560 | case DW_FORM_strp: | |
8561 | return "DW_FORM_strp"; | |
8562 | case DW_FORM_udata: | |
8563 | return "DW_FORM_udata"; | |
8564 | case DW_FORM_ref_addr: | |
8565 | return "DW_FORM_ref_addr"; | |
8566 | case DW_FORM_ref1: | |
8567 | return "DW_FORM_ref1"; | |
8568 | case DW_FORM_ref2: | |
8569 | return "DW_FORM_ref2"; | |
8570 | case DW_FORM_ref4: | |
8571 | return "DW_FORM_ref4"; | |
8572 | case DW_FORM_ref8: | |
8573 | return "DW_FORM_ref8"; | |
8574 | case DW_FORM_ref_udata: | |
8575 | return "DW_FORM_ref_udata"; | |
8576 | case DW_FORM_indirect: | |
8577 | return "DW_FORM_indirect"; | |
8578 | default: | |
8579 | return "DW_FORM_<unknown>"; | |
8580 | } | |
8581 | } | |
8582 | ||
8583 | /* Convert a DWARF stack opcode into its string name. */ | |
8584 | ||
8585 | static char * | |
aa1ee363 | 8586 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8587 | { |
8588 | switch (op) | |
8589 | { | |
8590 | case DW_OP_addr: | |
8591 | return "DW_OP_addr"; | |
8592 | case DW_OP_deref: | |
8593 | return "DW_OP_deref"; | |
8594 | case DW_OP_const1u: | |
8595 | return "DW_OP_const1u"; | |
8596 | case DW_OP_const1s: | |
8597 | return "DW_OP_const1s"; | |
8598 | case DW_OP_const2u: | |
8599 | return "DW_OP_const2u"; | |
8600 | case DW_OP_const2s: | |
8601 | return "DW_OP_const2s"; | |
8602 | case DW_OP_const4u: | |
8603 | return "DW_OP_const4u"; | |
8604 | case DW_OP_const4s: | |
8605 | return "DW_OP_const4s"; | |
8606 | case DW_OP_const8u: | |
8607 | return "DW_OP_const8u"; | |
8608 | case DW_OP_const8s: | |
8609 | return "DW_OP_const8s"; | |
8610 | case DW_OP_constu: | |
8611 | return "DW_OP_constu"; | |
8612 | case DW_OP_consts: | |
8613 | return "DW_OP_consts"; | |
8614 | case DW_OP_dup: | |
8615 | return "DW_OP_dup"; | |
8616 | case DW_OP_drop: | |
8617 | return "DW_OP_drop"; | |
8618 | case DW_OP_over: | |
8619 | return "DW_OP_over"; | |
8620 | case DW_OP_pick: | |
8621 | return "DW_OP_pick"; | |
8622 | case DW_OP_swap: | |
8623 | return "DW_OP_swap"; | |
8624 | case DW_OP_rot: | |
8625 | return "DW_OP_rot"; | |
8626 | case DW_OP_xderef: | |
8627 | return "DW_OP_xderef"; | |
8628 | case DW_OP_abs: | |
8629 | return "DW_OP_abs"; | |
8630 | case DW_OP_and: | |
8631 | return "DW_OP_and"; | |
8632 | case DW_OP_div: | |
8633 | return "DW_OP_div"; | |
8634 | case DW_OP_minus: | |
8635 | return "DW_OP_minus"; | |
8636 | case DW_OP_mod: | |
8637 | return "DW_OP_mod"; | |
8638 | case DW_OP_mul: | |
8639 | return "DW_OP_mul"; | |
8640 | case DW_OP_neg: | |
8641 | return "DW_OP_neg"; | |
8642 | case DW_OP_not: | |
8643 | return "DW_OP_not"; | |
8644 | case DW_OP_or: | |
8645 | return "DW_OP_or"; | |
8646 | case DW_OP_plus: | |
8647 | return "DW_OP_plus"; | |
8648 | case DW_OP_plus_uconst: | |
8649 | return "DW_OP_plus_uconst"; | |
8650 | case DW_OP_shl: | |
8651 | return "DW_OP_shl"; | |
8652 | case DW_OP_shr: | |
8653 | return "DW_OP_shr"; | |
8654 | case DW_OP_shra: | |
8655 | return "DW_OP_shra"; | |
8656 | case DW_OP_xor: | |
8657 | return "DW_OP_xor"; | |
8658 | case DW_OP_bra: | |
8659 | return "DW_OP_bra"; | |
8660 | case DW_OP_eq: | |
8661 | return "DW_OP_eq"; | |
8662 | case DW_OP_ge: | |
8663 | return "DW_OP_ge"; | |
8664 | case DW_OP_gt: | |
8665 | return "DW_OP_gt"; | |
8666 | case DW_OP_le: | |
8667 | return "DW_OP_le"; | |
8668 | case DW_OP_lt: | |
8669 | return "DW_OP_lt"; | |
8670 | case DW_OP_ne: | |
8671 | return "DW_OP_ne"; | |
8672 | case DW_OP_skip: | |
8673 | return "DW_OP_skip"; | |
8674 | case DW_OP_lit0: | |
8675 | return "DW_OP_lit0"; | |
8676 | case DW_OP_lit1: | |
8677 | return "DW_OP_lit1"; | |
8678 | case DW_OP_lit2: | |
8679 | return "DW_OP_lit2"; | |
8680 | case DW_OP_lit3: | |
8681 | return "DW_OP_lit3"; | |
8682 | case DW_OP_lit4: | |
8683 | return "DW_OP_lit4"; | |
8684 | case DW_OP_lit5: | |
8685 | return "DW_OP_lit5"; | |
8686 | case DW_OP_lit6: | |
8687 | return "DW_OP_lit6"; | |
8688 | case DW_OP_lit7: | |
8689 | return "DW_OP_lit7"; | |
8690 | case DW_OP_lit8: | |
8691 | return "DW_OP_lit8"; | |
8692 | case DW_OP_lit9: | |
8693 | return "DW_OP_lit9"; | |
8694 | case DW_OP_lit10: | |
8695 | return "DW_OP_lit10"; | |
8696 | case DW_OP_lit11: | |
8697 | return "DW_OP_lit11"; | |
8698 | case DW_OP_lit12: | |
8699 | return "DW_OP_lit12"; | |
8700 | case DW_OP_lit13: | |
8701 | return "DW_OP_lit13"; | |
8702 | case DW_OP_lit14: | |
8703 | return "DW_OP_lit14"; | |
8704 | case DW_OP_lit15: | |
8705 | return "DW_OP_lit15"; | |
8706 | case DW_OP_lit16: | |
8707 | return "DW_OP_lit16"; | |
8708 | case DW_OP_lit17: | |
8709 | return "DW_OP_lit17"; | |
8710 | case DW_OP_lit18: | |
8711 | return "DW_OP_lit18"; | |
8712 | case DW_OP_lit19: | |
8713 | return "DW_OP_lit19"; | |
8714 | case DW_OP_lit20: | |
8715 | return "DW_OP_lit20"; | |
8716 | case DW_OP_lit21: | |
8717 | return "DW_OP_lit21"; | |
8718 | case DW_OP_lit22: | |
8719 | return "DW_OP_lit22"; | |
8720 | case DW_OP_lit23: | |
8721 | return "DW_OP_lit23"; | |
8722 | case DW_OP_lit24: | |
8723 | return "DW_OP_lit24"; | |
8724 | case DW_OP_lit25: | |
8725 | return "DW_OP_lit25"; | |
8726 | case DW_OP_lit26: | |
8727 | return "DW_OP_lit26"; | |
8728 | case DW_OP_lit27: | |
8729 | return "DW_OP_lit27"; | |
8730 | case DW_OP_lit28: | |
8731 | return "DW_OP_lit28"; | |
8732 | case DW_OP_lit29: | |
8733 | return "DW_OP_lit29"; | |
8734 | case DW_OP_lit30: | |
8735 | return "DW_OP_lit30"; | |
8736 | case DW_OP_lit31: | |
8737 | return "DW_OP_lit31"; | |
8738 | case DW_OP_reg0: | |
8739 | return "DW_OP_reg0"; | |
8740 | case DW_OP_reg1: | |
8741 | return "DW_OP_reg1"; | |
8742 | case DW_OP_reg2: | |
8743 | return "DW_OP_reg2"; | |
8744 | case DW_OP_reg3: | |
8745 | return "DW_OP_reg3"; | |
8746 | case DW_OP_reg4: | |
8747 | return "DW_OP_reg4"; | |
8748 | case DW_OP_reg5: | |
8749 | return "DW_OP_reg5"; | |
8750 | case DW_OP_reg6: | |
8751 | return "DW_OP_reg6"; | |
8752 | case DW_OP_reg7: | |
8753 | return "DW_OP_reg7"; | |
8754 | case DW_OP_reg8: | |
8755 | return "DW_OP_reg8"; | |
8756 | case DW_OP_reg9: | |
8757 | return "DW_OP_reg9"; | |
8758 | case DW_OP_reg10: | |
8759 | return "DW_OP_reg10"; | |
8760 | case DW_OP_reg11: | |
8761 | return "DW_OP_reg11"; | |
8762 | case DW_OP_reg12: | |
8763 | return "DW_OP_reg12"; | |
8764 | case DW_OP_reg13: | |
8765 | return "DW_OP_reg13"; | |
8766 | case DW_OP_reg14: | |
8767 | return "DW_OP_reg14"; | |
8768 | case DW_OP_reg15: | |
8769 | return "DW_OP_reg15"; | |
8770 | case DW_OP_reg16: | |
8771 | return "DW_OP_reg16"; | |
8772 | case DW_OP_reg17: | |
8773 | return "DW_OP_reg17"; | |
8774 | case DW_OP_reg18: | |
8775 | return "DW_OP_reg18"; | |
8776 | case DW_OP_reg19: | |
8777 | return "DW_OP_reg19"; | |
8778 | case DW_OP_reg20: | |
8779 | return "DW_OP_reg20"; | |
8780 | case DW_OP_reg21: | |
8781 | return "DW_OP_reg21"; | |
8782 | case DW_OP_reg22: | |
8783 | return "DW_OP_reg22"; | |
8784 | case DW_OP_reg23: | |
8785 | return "DW_OP_reg23"; | |
8786 | case DW_OP_reg24: | |
8787 | return "DW_OP_reg24"; | |
8788 | case DW_OP_reg25: | |
8789 | return "DW_OP_reg25"; | |
8790 | case DW_OP_reg26: | |
8791 | return "DW_OP_reg26"; | |
8792 | case DW_OP_reg27: | |
8793 | return "DW_OP_reg27"; | |
8794 | case DW_OP_reg28: | |
8795 | return "DW_OP_reg28"; | |
8796 | case DW_OP_reg29: | |
8797 | return "DW_OP_reg29"; | |
8798 | case DW_OP_reg30: | |
8799 | return "DW_OP_reg30"; | |
8800 | case DW_OP_reg31: | |
8801 | return "DW_OP_reg31"; | |
8802 | case DW_OP_breg0: | |
8803 | return "DW_OP_breg0"; | |
8804 | case DW_OP_breg1: | |
8805 | return "DW_OP_breg1"; | |
8806 | case DW_OP_breg2: | |
8807 | return "DW_OP_breg2"; | |
8808 | case DW_OP_breg3: | |
8809 | return "DW_OP_breg3"; | |
8810 | case DW_OP_breg4: | |
8811 | return "DW_OP_breg4"; | |
8812 | case DW_OP_breg5: | |
8813 | return "DW_OP_breg5"; | |
8814 | case DW_OP_breg6: | |
8815 | return "DW_OP_breg6"; | |
8816 | case DW_OP_breg7: | |
8817 | return "DW_OP_breg7"; | |
8818 | case DW_OP_breg8: | |
8819 | return "DW_OP_breg8"; | |
8820 | case DW_OP_breg9: | |
8821 | return "DW_OP_breg9"; | |
8822 | case DW_OP_breg10: | |
8823 | return "DW_OP_breg10"; | |
8824 | case DW_OP_breg11: | |
8825 | return "DW_OP_breg11"; | |
8826 | case DW_OP_breg12: | |
8827 | return "DW_OP_breg12"; | |
8828 | case DW_OP_breg13: | |
8829 | return "DW_OP_breg13"; | |
8830 | case DW_OP_breg14: | |
8831 | return "DW_OP_breg14"; | |
8832 | case DW_OP_breg15: | |
8833 | return "DW_OP_breg15"; | |
8834 | case DW_OP_breg16: | |
8835 | return "DW_OP_breg16"; | |
8836 | case DW_OP_breg17: | |
8837 | return "DW_OP_breg17"; | |
8838 | case DW_OP_breg18: | |
8839 | return "DW_OP_breg18"; | |
8840 | case DW_OP_breg19: | |
8841 | return "DW_OP_breg19"; | |
8842 | case DW_OP_breg20: | |
8843 | return "DW_OP_breg20"; | |
8844 | case DW_OP_breg21: | |
8845 | return "DW_OP_breg21"; | |
8846 | case DW_OP_breg22: | |
8847 | return "DW_OP_breg22"; | |
8848 | case DW_OP_breg23: | |
8849 | return "DW_OP_breg23"; | |
8850 | case DW_OP_breg24: | |
8851 | return "DW_OP_breg24"; | |
8852 | case DW_OP_breg25: | |
8853 | return "DW_OP_breg25"; | |
8854 | case DW_OP_breg26: | |
8855 | return "DW_OP_breg26"; | |
8856 | case DW_OP_breg27: | |
8857 | return "DW_OP_breg27"; | |
8858 | case DW_OP_breg28: | |
8859 | return "DW_OP_breg28"; | |
8860 | case DW_OP_breg29: | |
8861 | return "DW_OP_breg29"; | |
8862 | case DW_OP_breg30: | |
8863 | return "DW_OP_breg30"; | |
8864 | case DW_OP_breg31: | |
8865 | return "DW_OP_breg31"; | |
8866 | case DW_OP_regx: | |
8867 | return "DW_OP_regx"; | |
8868 | case DW_OP_fbreg: | |
8869 | return "DW_OP_fbreg"; | |
8870 | case DW_OP_bregx: | |
8871 | return "DW_OP_bregx"; | |
8872 | case DW_OP_piece: | |
8873 | return "DW_OP_piece"; | |
8874 | case DW_OP_deref_size: | |
8875 | return "DW_OP_deref_size"; | |
8876 | case DW_OP_xderef_size: | |
8877 | return "DW_OP_xderef_size"; | |
8878 | case DW_OP_nop: | |
8879 | return "DW_OP_nop"; | |
b7619582 | 8880 | /* DWARF 3 extensions. */ |
ed348acc EZ |
8881 | case DW_OP_push_object_address: |
8882 | return "DW_OP_push_object_address"; | |
8883 | case DW_OP_call2: | |
8884 | return "DW_OP_call2"; | |
8885 | case DW_OP_call4: | |
8886 | return "DW_OP_call4"; | |
8887 | case DW_OP_call_ref: | |
8888 | return "DW_OP_call_ref"; | |
b7619582 GF |
8889 | /* GNU extensions. */ |
8890 | case DW_OP_form_tls_address: | |
8891 | return "DW_OP_form_tls_address"; | |
8892 | case DW_OP_call_frame_cfa: | |
8893 | return "DW_OP_call_frame_cfa"; | |
8894 | case DW_OP_bit_piece: | |
8895 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
8896 | case DW_OP_GNU_push_tls_address: |
8897 | return "DW_OP_GNU_push_tls_address"; | |
42be36b3 CT |
8898 | case DW_OP_GNU_uninit: |
8899 | return "DW_OP_GNU_uninit"; | |
b7619582 GF |
8900 | /* HP extensions. */ |
8901 | case DW_OP_HP_is_value: | |
8902 | return "DW_OP_HP_is_value"; | |
8903 | case DW_OP_HP_fltconst4: | |
8904 | return "DW_OP_HP_fltconst4"; | |
8905 | case DW_OP_HP_fltconst8: | |
8906 | return "DW_OP_HP_fltconst8"; | |
8907 | case DW_OP_HP_mod_range: | |
8908 | return "DW_OP_HP_mod_range"; | |
8909 | case DW_OP_HP_unmod_range: | |
8910 | return "DW_OP_HP_unmod_range"; | |
8911 | case DW_OP_HP_tls: | |
8912 | return "DW_OP_HP_tls"; | |
c906108c SS |
8913 | default: |
8914 | return "OP_<unknown>"; | |
8915 | } | |
8916 | } | |
8917 | ||
8918 | static char * | |
fba45db2 | 8919 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
8920 | { |
8921 | if (mybool) | |
8922 | return "TRUE"; | |
8923 | else | |
8924 | return "FALSE"; | |
8925 | } | |
8926 | ||
8927 | /* Convert a DWARF type code into its string name. */ | |
8928 | ||
8929 | static char * | |
aa1ee363 | 8930 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
8931 | { |
8932 | switch (enc) | |
8933 | { | |
b7619582 GF |
8934 | case DW_ATE_void: |
8935 | return "DW_ATE_void"; | |
c906108c SS |
8936 | case DW_ATE_address: |
8937 | return "DW_ATE_address"; | |
8938 | case DW_ATE_boolean: | |
8939 | return "DW_ATE_boolean"; | |
8940 | case DW_ATE_complex_float: | |
8941 | return "DW_ATE_complex_float"; | |
8942 | case DW_ATE_float: | |
8943 | return "DW_ATE_float"; | |
8944 | case DW_ATE_signed: | |
8945 | return "DW_ATE_signed"; | |
8946 | case DW_ATE_signed_char: | |
8947 | return "DW_ATE_signed_char"; | |
8948 | case DW_ATE_unsigned: | |
8949 | return "DW_ATE_unsigned"; | |
8950 | case DW_ATE_unsigned_char: | |
8951 | return "DW_ATE_unsigned_char"; | |
b7619582 | 8952 | /* DWARF 3. */ |
d9fa45fe DC |
8953 | case DW_ATE_imaginary_float: |
8954 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
8955 | case DW_ATE_packed_decimal: |
8956 | return "DW_ATE_packed_decimal"; | |
8957 | case DW_ATE_numeric_string: | |
8958 | return "DW_ATE_numeric_string"; | |
8959 | case DW_ATE_edited: | |
8960 | return "DW_ATE_edited"; | |
8961 | case DW_ATE_signed_fixed: | |
8962 | return "DW_ATE_signed_fixed"; | |
8963 | case DW_ATE_unsigned_fixed: | |
8964 | return "DW_ATE_unsigned_fixed"; | |
8965 | case DW_ATE_decimal_float: | |
8966 | return "DW_ATE_decimal_float"; | |
8967 | /* HP extensions. */ | |
8968 | case DW_ATE_HP_float80: | |
8969 | return "DW_ATE_HP_float80"; | |
8970 | case DW_ATE_HP_complex_float80: | |
8971 | return "DW_ATE_HP_complex_float80"; | |
8972 | case DW_ATE_HP_float128: | |
8973 | return "DW_ATE_HP_float128"; | |
8974 | case DW_ATE_HP_complex_float128: | |
8975 | return "DW_ATE_HP_complex_float128"; | |
8976 | case DW_ATE_HP_floathpintel: | |
8977 | return "DW_ATE_HP_floathpintel"; | |
8978 | case DW_ATE_HP_imaginary_float80: | |
8979 | return "DW_ATE_HP_imaginary_float80"; | |
8980 | case DW_ATE_HP_imaginary_float128: | |
8981 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
8982 | default: |
8983 | return "DW_ATE_<unknown>"; | |
8984 | } | |
8985 | } | |
8986 | ||
8987 | /* Convert a DWARF call frame info operation to its string name. */ | |
8988 | ||
8989 | #if 0 | |
8990 | static char * | |
aa1ee363 | 8991 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
8992 | { |
8993 | switch (cfi_opc) | |
8994 | { | |
8995 | case DW_CFA_advance_loc: | |
8996 | return "DW_CFA_advance_loc"; | |
8997 | case DW_CFA_offset: | |
8998 | return "DW_CFA_offset"; | |
8999 | case DW_CFA_restore: | |
9000 | return "DW_CFA_restore"; | |
9001 | case DW_CFA_nop: | |
9002 | return "DW_CFA_nop"; | |
9003 | case DW_CFA_set_loc: | |
9004 | return "DW_CFA_set_loc"; | |
9005 | case DW_CFA_advance_loc1: | |
9006 | return "DW_CFA_advance_loc1"; | |
9007 | case DW_CFA_advance_loc2: | |
9008 | return "DW_CFA_advance_loc2"; | |
9009 | case DW_CFA_advance_loc4: | |
9010 | return "DW_CFA_advance_loc4"; | |
9011 | case DW_CFA_offset_extended: | |
9012 | return "DW_CFA_offset_extended"; | |
9013 | case DW_CFA_restore_extended: | |
9014 | return "DW_CFA_restore_extended"; | |
9015 | case DW_CFA_undefined: | |
9016 | return "DW_CFA_undefined"; | |
9017 | case DW_CFA_same_value: | |
9018 | return "DW_CFA_same_value"; | |
9019 | case DW_CFA_register: | |
9020 | return "DW_CFA_register"; | |
9021 | case DW_CFA_remember_state: | |
9022 | return "DW_CFA_remember_state"; | |
9023 | case DW_CFA_restore_state: | |
9024 | return "DW_CFA_restore_state"; | |
9025 | case DW_CFA_def_cfa: | |
9026 | return "DW_CFA_def_cfa"; | |
9027 | case DW_CFA_def_cfa_register: | |
9028 | return "DW_CFA_def_cfa_register"; | |
9029 | case DW_CFA_def_cfa_offset: | |
9030 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 9031 | /* DWARF 3. */ |
985cb1a3 JM |
9032 | case DW_CFA_def_cfa_expression: |
9033 | return "DW_CFA_def_cfa_expression"; | |
9034 | case DW_CFA_expression: | |
9035 | return "DW_CFA_expression"; | |
9036 | case DW_CFA_offset_extended_sf: | |
9037 | return "DW_CFA_offset_extended_sf"; | |
9038 | case DW_CFA_def_cfa_sf: | |
9039 | return "DW_CFA_def_cfa_sf"; | |
9040 | case DW_CFA_def_cfa_offset_sf: | |
9041 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
9042 | case DW_CFA_val_offset: |
9043 | return "DW_CFA_val_offset"; | |
9044 | case DW_CFA_val_offset_sf: | |
9045 | return "DW_CFA_val_offset_sf"; | |
9046 | case DW_CFA_val_expression: | |
9047 | return "DW_CFA_val_expression"; | |
9048 | /* SGI/MIPS specific. */ | |
c906108c SS |
9049 | case DW_CFA_MIPS_advance_loc8: |
9050 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 9051 | /* GNU extensions. */ |
985cb1a3 JM |
9052 | case DW_CFA_GNU_window_save: |
9053 | return "DW_CFA_GNU_window_save"; | |
9054 | case DW_CFA_GNU_args_size: | |
9055 | return "DW_CFA_GNU_args_size"; | |
9056 | case DW_CFA_GNU_negative_offset_extended: | |
9057 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
9058 | default: |
9059 | return "DW_CFA_<unknown>"; | |
9060 | } | |
9061 | } | |
9062 | #endif | |
9063 | ||
f9aca02d | 9064 | static void |
fba45db2 | 9065 | dump_die (struct die_info *die) |
c906108c SS |
9066 | { |
9067 | unsigned int i; | |
9068 | ||
48cd0caa | 9069 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 9070 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 9071 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 9072 | dwarf_bool_name (die->child != NULL)); |
c906108c | 9073 | |
48cd0caa | 9074 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
9075 | for (i = 0; i < die->num_attrs; ++i) |
9076 | { | |
48cd0caa | 9077 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
9078 | dwarf_attr_name (die->attrs[i].name), |
9079 | dwarf_form_name (die->attrs[i].form)); | |
9080 | switch (die->attrs[i].form) | |
9081 | { | |
9082 | case DW_FORM_ref_addr: | |
9083 | case DW_FORM_addr: | |
48cd0caa | 9084 | fprintf_unfiltered (gdb_stderr, "address: "); |
ed49a04f | 9085 | fputs_filtered (paddress (DW_ADDR (&die->attrs[i])), gdb_stderr); |
c906108c SS |
9086 | break; |
9087 | case DW_FORM_block2: | |
9088 | case DW_FORM_block4: | |
9089 | case DW_FORM_block: | |
9090 | case DW_FORM_block1: | |
48cd0caa | 9091 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 9092 | break; |
10b3939b DJ |
9093 | case DW_FORM_ref1: |
9094 | case DW_FORM_ref2: | |
9095 | case DW_FORM_ref4: | |
9096 | fprintf_unfiltered (gdb_stderr, "constant ref: %ld (adjusted)", | |
9097 | (long) (DW_ADDR (&die->attrs[i]))); | |
9098 | break; | |
c906108c SS |
9099 | case DW_FORM_data1: |
9100 | case DW_FORM_data2: | |
9101 | case DW_FORM_data4: | |
ce5d95e1 | 9102 | case DW_FORM_data8: |
c906108c SS |
9103 | case DW_FORM_udata: |
9104 | case DW_FORM_sdata: | |
48cd0caa | 9105 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
9106 | break; |
9107 | case DW_FORM_string: | |
4bdf3d34 | 9108 | case DW_FORM_strp: |
48cd0caa | 9109 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 9110 | DW_STRING (&die->attrs[i]) |
c5aa993b | 9111 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
9112 | break; |
9113 | case DW_FORM_flag: | |
9114 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 9115 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 9116 | else |
48cd0caa | 9117 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 9118 | break; |
a8329558 KW |
9119 | case DW_FORM_indirect: |
9120 | /* the reader will have reduced the indirect form to | |
9121 | the "base form" so this form should not occur */ | |
48cd0caa | 9122 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 9123 | break; |
c906108c | 9124 | default: |
48cd0caa | 9125 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 9126 | die->attrs[i].form); |
c906108c | 9127 | } |
48cd0caa | 9128 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
9129 | } |
9130 | } | |
9131 | ||
f9aca02d | 9132 | static void |
fba45db2 | 9133 | dump_die_list (struct die_info *die) |
c906108c SS |
9134 | { |
9135 | while (die) | |
9136 | { | |
9137 | dump_die (die); | |
639d11d3 DC |
9138 | if (die->child != NULL) |
9139 | dump_die_list (die->child); | |
9140 | if (die->sibling != NULL) | |
9141 | dump_die_list (die->sibling); | |
c906108c SS |
9142 | } |
9143 | } | |
9144 | ||
f9aca02d | 9145 | static void |
10b3939b DJ |
9146 | store_in_ref_table (unsigned int offset, struct die_info *die, |
9147 | struct dwarf2_cu *cu) | |
c906108c SS |
9148 | { |
9149 | int h; | |
9150 | struct die_info *old; | |
9151 | ||
9152 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 9153 | old = cu->die_ref_table[h]; |
c906108c | 9154 | die->next_ref = old; |
10b3939b | 9155 | cu->die_ref_table[h] = die; |
c906108c SS |
9156 | } |
9157 | ||
9158 | static unsigned int | |
e142c38c | 9159 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
9160 | { |
9161 | unsigned int result = 0; | |
9162 | ||
9163 | switch (attr->form) | |
9164 | { | |
9165 | case DW_FORM_ref_addr: | |
c906108c SS |
9166 | case DW_FORM_ref1: |
9167 | case DW_FORM_ref2: | |
9168 | case DW_FORM_ref4: | |
613e1657 | 9169 | case DW_FORM_ref8: |
c906108c | 9170 | case DW_FORM_ref_udata: |
10b3939b | 9171 | result = DW_ADDR (attr); |
c906108c SS |
9172 | break; |
9173 | default: | |
4d3c2250 | 9174 | complaint (&symfile_complaints, |
e2e0b3e5 | 9175 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 9176 | dwarf_form_name (attr->form)); |
c906108c SS |
9177 | } |
9178 | return result; | |
9179 | } | |
9180 | ||
a02abb62 JB |
9181 | /* Return the constant value held by the given attribute. Return -1 |
9182 | if the value held by the attribute is not constant. */ | |
9183 | ||
9184 | static int | |
9185 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
9186 | { | |
9187 | if (attr->form == DW_FORM_sdata) | |
9188 | return DW_SND (attr); | |
9189 | else if (attr->form == DW_FORM_udata | |
9190 | || attr->form == DW_FORM_data1 | |
9191 | || attr->form == DW_FORM_data2 | |
9192 | || attr->form == DW_FORM_data4 | |
9193 | || attr->form == DW_FORM_data8) | |
9194 | return DW_UNSND (attr); | |
9195 | else | |
9196 | { | |
e2e0b3e5 | 9197 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
9198 | dwarf_form_name (attr->form)); |
9199 | return default_value; | |
9200 | } | |
9201 | } | |
9202 | ||
f9aca02d | 9203 | static struct die_info * |
10b3939b DJ |
9204 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
9205 | struct dwarf2_cu *cu) | |
c906108c SS |
9206 | { |
9207 | struct die_info *die; | |
10b3939b | 9208 | unsigned int offset; |
c906108c | 9209 | int h; |
10b3939b DJ |
9210 | struct die_info temp_die; |
9211 | struct dwarf2_cu *target_cu; | |
9212 | ||
9213 | offset = dwarf2_get_ref_die_offset (attr, cu); | |
9214 | ||
9215 | if (DW_ADDR (attr) < cu->header.offset | |
9216 | || DW_ADDR (attr) >= cu->header.offset + cu->header.length) | |
9217 | { | |
9218 | struct dwarf2_per_cu_data *per_cu; | |
9219 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (attr), | |
9220 | cu->objfile); | |
9221 | target_cu = per_cu->cu; | |
9222 | } | |
9223 | else | |
9224 | target_cu = cu; | |
c906108c SS |
9225 | |
9226 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 9227 | die = target_cu->die_ref_table[h]; |
c906108c SS |
9228 | while (die) |
9229 | { | |
9230 | if (die->offset == offset) | |
10b3939b | 9231 | return die; |
c906108c SS |
9232 | die = die->next_ref; |
9233 | } | |
10b3939b | 9234 | |
8a3fe4f8 AC |
9235 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
9236 | "at 0x%lx [in module %s]"), | |
10b3939b DJ |
9237 | (long) src_die->offset, (long) offset, cu->objfile->name); |
9238 | ||
c906108c SS |
9239 | return NULL; |
9240 | } | |
9241 | ||
c906108c SS |
9242 | /* Decode simple location descriptions. |
9243 | Given a pointer to a dwarf block that defines a location, compute | |
9244 | the location and return the value. | |
9245 | ||
4cecd739 DJ |
9246 | NOTE drow/2003-11-18: This function is called in two situations |
9247 | now: for the address of static or global variables (partial symbols | |
9248 | only) and for offsets into structures which are expected to be | |
9249 | (more or less) constant. The partial symbol case should go away, | |
9250 | and only the constant case should remain. That will let this | |
9251 | function complain more accurately. A few special modes are allowed | |
9252 | without complaint for global variables (for instance, global | |
9253 | register values and thread-local values). | |
c906108c SS |
9254 | |
9255 | A location description containing no operations indicates that the | |
4cecd739 | 9256 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
9257 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
9258 | callers will only want a very basic result and this can become a | |
9259 | complaint. | |
c906108c | 9260 | |
c906108c SS |
9261 | Note that stack[0] is unused except as a default error return. |
9262 | Note that stack overflow is not yet handled. */ | |
9263 | ||
9264 | static CORE_ADDR | |
e7c27a73 | 9265 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 9266 | { |
e7c27a73 DJ |
9267 | struct objfile *objfile = cu->objfile; |
9268 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
9269 | int i; |
9270 | int size = blk->size; | |
fe1b8b76 | 9271 | gdb_byte *data = blk->data; |
c906108c SS |
9272 | CORE_ADDR stack[64]; |
9273 | int stacki; | |
9274 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 9275 | gdb_byte op; |
c906108c SS |
9276 | |
9277 | i = 0; | |
9278 | stacki = 0; | |
9279 | stack[stacki] = 0; | |
c906108c SS |
9280 | |
9281 | while (i < size) | |
9282 | { | |
c906108c SS |
9283 | op = data[i++]; |
9284 | switch (op) | |
9285 | { | |
f1bea926 JM |
9286 | case DW_OP_lit0: |
9287 | case DW_OP_lit1: | |
9288 | case DW_OP_lit2: | |
9289 | case DW_OP_lit3: | |
9290 | case DW_OP_lit4: | |
9291 | case DW_OP_lit5: | |
9292 | case DW_OP_lit6: | |
9293 | case DW_OP_lit7: | |
9294 | case DW_OP_lit8: | |
9295 | case DW_OP_lit9: | |
9296 | case DW_OP_lit10: | |
9297 | case DW_OP_lit11: | |
9298 | case DW_OP_lit12: | |
9299 | case DW_OP_lit13: | |
9300 | case DW_OP_lit14: | |
9301 | case DW_OP_lit15: | |
9302 | case DW_OP_lit16: | |
9303 | case DW_OP_lit17: | |
9304 | case DW_OP_lit18: | |
9305 | case DW_OP_lit19: | |
9306 | case DW_OP_lit20: | |
9307 | case DW_OP_lit21: | |
9308 | case DW_OP_lit22: | |
9309 | case DW_OP_lit23: | |
9310 | case DW_OP_lit24: | |
9311 | case DW_OP_lit25: | |
9312 | case DW_OP_lit26: | |
9313 | case DW_OP_lit27: | |
9314 | case DW_OP_lit28: | |
9315 | case DW_OP_lit29: | |
9316 | case DW_OP_lit30: | |
9317 | case DW_OP_lit31: | |
9318 | stack[++stacki] = op - DW_OP_lit0; | |
9319 | break; | |
9320 | ||
c906108c SS |
9321 | case DW_OP_reg0: |
9322 | case DW_OP_reg1: | |
9323 | case DW_OP_reg2: | |
9324 | case DW_OP_reg3: | |
9325 | case DW_OP_reg4: | |
9326 | case DW_OP_reg5: | |
9327 | case DW_OP_reg6: | |
9328 | case DW_OP_reg7: | |
9329 | case DW_OP_reg8: | |
9330 | case DW_OP_reg9: | |
9331 | case DW_OP_reg10: | |
9332 | case DW_OP_reg11: | |
9333 | case DW_OP_reg12: | |
9334 | case DW_OP_reg13: | |
9335 | case DW_OP_reg14: | |
9336 | case DW_OP_reg15: | |
9337 | case DW_OP_reg16: | |
9338 | case DW_OP_reg17: | |
9339 | case DW_OP_reg18: | |
9340 | case DW_OP_reg19: | |
9341 | case DW_OP_reg20: | |
9342 | case DW_OP_reg21: | |
9343 | case DW_OP_reg22: | |
9344 | case DW_OP_reg23: | |
9345 | case DW_OP_reg24: | |
9346 | case DW_OP_reg25: | |
9347 | case DW_OP_reg26: | |
9348 | case DW_OP_reg27: | |
9349 | case DW_OP_reg28: | |
9350 | case DW_OP_reg29: | |
9351 | case DW_OP_reg30: | |
9352 | case DW_OP_reg31: | |
c906108c | 9353 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9354 | if (i < size) |
9355 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9356 | break; |
9357 | ||
9358 | case DW_OP_regx: | |
c906108c SS |
9359 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9360 | i += bytes_read; | |
c906108c | 9361 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9362 | if (i < size) |
9363 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9364 | break; |
9365 | ||
9366 | case DW_OP_addr: | |
107d2387 | 9367 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9368 | cu, &bytes_read); |
107d2387 | 9369 | i += bytes_read; |
c906108c SS |
9370 | break; |
9371 | ||
9372 | case DW_OP_const1u: | |
9373 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9374 | i += 1; | |
9375 | break; | |
9376 | ||
9377 | case DW_OP_const1s: | |
9378 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9379 | i += 1; | |
9380 | break; | |
9381 | ||
9382 | case DW_OP_const2u: | |
9383 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9384 | i += 2; | |
9385 | break; | |
9386 | ||
9387 | case DW_OP_const2s: | |
9388 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9389 | i += 2; | |
9390 | break; | |
9391 | ||
9392 | case DW_OP_const4u: | |
9393 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9394 | i += 4; | |
9395 | break; | |
9396 | ||
9397 | case DW_OP_const4s: | |
9398 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9399 | i += 4; | |
9400 | break; | |
9401 | ||
9402 | case DW_OP_constu: | |
9403 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9404 | &bytes_read); |
c906108c SS |
9405 | i += bytes_read; |
9406 | break; | |
9407 | ||
9408 | case DW_OP_consts: | |
9409 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9410 | i += bytes_read; | |
9411 | break; | |
9412 | ||
f1bea926 JM |
9413 | case DW_OP_dup: |
9414 | stack[stacki + 1] = stack[stacki]; | |
9415 | stacki++; | |
9416 | break; | |
9417 | ||
c906108c SS |
9418 | case DW_OP_plus: |
9419 | stack[stacki - 1] += stack[stacki]; | |
9420 | stacki--; | |
9421 | break; | |
9422 | ||
9423 | case DW_OP_plus_uconst: | |
9424 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9425 | i += bytes_read; | |
9426 | break; | |
9427 | ||
9428 | case DW_OP_minus: | |
f1bea926 | 9429 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9430 | stacki--; |
9431 | break; | |
9432 | ||
7a292a7a | 9433 | case DW_OP_deref: |
7a292a7a | 9434 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9435 | this using GDB's address_class enum. This is valid for partial |
9436 | global symbols, although the variable's address will be bogus | |
9437 | in the psymtab. */ | |
7a292a7a | 9438 | if (i < size) |
4d3c2250 | 9439 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9440 | break; |
9441 | ||
9d774e44 | 9442 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9443 | /* The top of the stack has the offset from the beginning |
9444 | of the thread control block at which the variable is located. */ | |
9445 | /* Nothing should follow this operator, so the top of stack would | |
9446 | be returned. */ | |
4cecd739 DJ |
9447 | /* This is valid for partial global symbols, but the variable's |
9448 | address will be bogus in the psymtab. */ | |
9d774e44 | 9449 | if (i < size) |
4d3c2250 | 9450 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9451 | break; |
9452 | ||
42be36b3 CT |
9453 | case DW_OP_GNU_uninit: |
9454 | break; | |
9455 | ||
c906108c | 9456 | default: |
e2e0b3e5 | 9457 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9458 | dwarf_stack_op_name (op)); |
c906108c SS |
9459 | return (stack[stacki]); |
9460 | } | |
9461 | } | |
9462 | return (stack[stacki]); | |
9463 | } | |
9464 | ||
9465 | /* memory allocation interface */ | |
9466 | ||
c906108c | 9467 | static struct dwarf_block * |
7b5a2f43 | 9468 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9469 | { |
9470 | struct dwarf_block *blk; | |
9471 | ||
9472 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9473 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9474 | return (blk); |
9475 | } | |
9476 | ||
9477 | static struct abbrev_info * | |
f3dd6933 | 9478 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9479 | { |
9480 | struct abbrev_info *abbrev; | |
9481 | ||
f3dd6933 DJ |
9482 | abbrev = (struct abbrev_info *) |
9483 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9484 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9485 | return (abbrev); | |
9486 | } | |
9487 | ||
9488 | static struct die_info * | |
fba45db2 | 9489 | dwarf_alloc_die (void) |
c906108c SS |
9490 | { |
9491 | struct die_info *die; | |
9492 | ||
9493 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
9494 | memset (die, 0, sizeof (struct die_info)); | |
9495 | return (die); | |
9496 | } | |
2e276125 JB |
9497 | |
9498 | \f | |
9499 | /* Macro support. */ | |
9500 | ||
9501 | ||
9502 | /* Return the full name of file number I in *LH's file name table. | |
9503 | Use COMP_DIR as the name of the current directory of the | |
9504 | compilation. The result is allocated using xmalloc; the caller is | |
9505 | responsible for freeing it. */ | |
9506 | static char * | |
9507 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9508 | { | |
6a83a1e6 EZ |
9509 | /* Is the file number a valid index into the line header's file name |
9510 | table? Remember that file numbers start with one, not zero. */ | |
9511 | if (1 <= file && file <= lh->num_file_names) | |
9512 | { | |
9513 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9514 | |
6a83a1e6 EZ |
9515 | if (IS_ABSOLUTE_PATH (fe->name)) |
9516 | return xstrdup (fe->name); | |
9517 | else | |
9518 | { | |
9519 | const char *dir; | |
9520 | int dir_len; | |
9521 | char *full_name; | |
9522 | ||
9523 | if (fe->dir_index) | |
9524 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9525 | else | |
9526 | dir = comp_dir; | |
9527 | ||
9528 | if (dir) | |
9529 | { | |
9530 | dir_len = strlen (dir); | |
9531 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9532 | strcpy (full_name, dir); | |
9533 | full_name[dir_len] = '/'; | |
9534 | strcpy (full_name + dir_len + 1, fe->name); | |
9535 | return full_name; | |
9536 | } | |
9537 | else | |
9538 | return xstrdup (fe->name); | |
9539 | } | |
9540 | } | |
2e276125 JB |
9541 | else |
9542 | { | |
6a83a1e6 EZ |
9543 | /* The compiler produced a bogus file number. We can at least |
9544 | record the macro definitions made in the file, even if we | |
9545 | won't be able to find the file by name. */ | |
9546 | char fake_name[80]; | |
9547 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9548 | |
6a83a1e6 EZ |
9549 | complaint (&symfile_complaints, |
9550 | _("bad file number in macro information (%d)"), | |
9551 | file); | |
2e276125 | 9552 | |
6a83a1e6 | 9553 | return xstrdup (fake_name); |
2e276125 JB |
9554 | } |
9555 | } | |
9556 | ||
9557 | ||
9558 | static struct macro_source_file * | |
9559 | macro_start_file (int file, int line, | |
9560 | struct macro_source_file *current_file, | |
9561 | const char *comp_dir, | |
9562 | struct line_header *lh, struct objfile *objfile) | |
9563 | { | |
9564 | /* The full name of this source file. */ | |
9565 | char *full_name = file_full_name (file, lh, comp_dir); | |
9566 | ||
9567 | /* We don't create a macro table for this compilation unit | |
9568 | at all until we actually get a filename. */ | |
9569 | if (! pending_macros) | |
4a146b47 | 9570 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9571 | objfile->macro_cache); |
2e276125 JB |
9572 | |
9573 | if (! current_file) | |
9574 | /* If we have no current file, then this must be the start_file | |
9575 | directive for the compilation unit's main source file. */ | |
9576 | current_file = macro_set_main (pending_macros, full_name); | |
9577 | else | |
9578 | current_file = macro_include (current_file, line, full_name); | |
9579 | ||
9580 | xfree (full_name); | |
9581 | ||
9582 | return current_file; | |
9583 | } | |
9584 | ||
9585 | ||
9586 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9587 | followed by a null byte. */ | |
9588 | static char * | |
9589 | copy_string (const char *buf, int len) | |
9590 | { | |
9591 | char *s = xmalloc (len + 1); | |
9592 | memcpy (s, buf, len); | |
9593 | s[len] = '\0'; | |
9594 | ||
9595 | return s; | |
9596 | } | |
9597 | ||
9598 | ||
9599 | static const char * | |
9600 | consume_improper_spaces (const char *p, const char *body) | |
9601 | { | |
9602 | if (*p == ' ') | |
9603 | { | |
4d3c2250 | 9604 | complaint (&symfile_complaints, |
e2e0b3e5 | 9605 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9606 | body); |
2e276125 JB |
9607 | |
9608 | while (*p == ' ') | |
9609 | p++; | |
9610 | } | |
9611 | ||
9612 | return p; | |
9613 | } | |
9614 | ||
9615 | ||
9616 | static void | |
9617 | parse_macro_definition (struct macro_source_file *file, int line, | |
9618 | const char *body) | |
9619 | { | |
9620 | const char *p; | |
9621 | ||
9622 | /* The body string takes one of two forms. For object-like macro | |
9623 | definitions, it should be: | |
9624 | ||
9625 | <macro name> " " <definition> | |
9626 | ||
9627 | For function-like macro definitions, it should be: | |
9628 | ||
9629 | <macro name> "() " <definition> | |
9630 | or | |
9631 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
9632 | ||
9633 | Spaces may appear only where explicitly indicated, and in the | |
9634 | <definition>. | |
9635 | ||
9636 | The Dwarf 2 spec says that an object-like macro's name is always | |
9637 | followed by a space, but versions of GCC around March 2002 omit | |
9638 | the space when the macro's definition is the empty string. | |
9639 | ||
9640 | The Dwarf 2 spec says that there should be no spaces between the | |
9641 | formal arguments in a function-like macro's formal argument list, | |
9642 | but versions of GCC around March 2002 include spaces after the | |
9643 | commas. */ | |
9644 | ||
9645 | ||
9646 | /* Find the extent of the macro name. The macro name is terminated | |
9647 | by either a space or null character (for an object-like macro) or | |
9648 | an opening paren (for a function-like macro). */ | |
9649 | for (p = body; *p; p++) | |
9650 | if (*p == ' ' || *p == '(') | |
9651 | break; | |
9652 | ||
9653 | if (*p == ' ' || *p == '\0') | |
9654 | { | |
9655 | /* It's an object-like macro. */ | |
9656 | int name_len = p - body; | |
9657 | char *name = copy_string (body, name_len); | |
9658 | const char *replacement; | |
9659 | ||
9660 | if (*p == ' ') | |
9661 | replacement = body + name_len + 1; | |
9662 | else | |
9663 | { | |
4d3c2250 | 9664 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9665 | replacement = body + name_len; |
9666 | } | |
9667 | ||
9668 | macro_define_object (file, line, name, replacement); | |
9669 | ||
9670 | xfree (name); | |
9671 | } | |
9672 | else if (*p == '(') | |
9673 | { | |
9674 | /* It's a function-like macro. */ | |
9675 | char *name = copy_string (body, p - body); | |
9676 | int argc = 0; | |
9677 | int argv_size = 1; | |
9678 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
9679 | ||
9680 | p++; | |
9681 | ||
9682 | p = consume_improper_spaces (p, body); | |
9683 | ||
9684 | /* Parse the formal argument list. */ | |
9685 | while (*p && *p != ')') | |
9686 | { | |
9687 | /* Find the extent of the current argument name. */ | |
9688 | const char *arg_start = p; | |
9689 | ||
9690 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
9691 | p++; | |
9692 | ||
9693 | if (! *p || p == arg_start) | |
4d3c2250 | 9694 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9695 | else |
9696 | { | |
9697 | /* Make sure argv has room for the new argument. */ | |
9698 | if (argc >= argv_size) | |
9699 | { | |
9700 | argv_size *= 2; | |
9701 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
9702 | } | |
9703 | ||
9704 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
9705 | } | |
9706 | ||
9707 | p = consume_improper_spaces (p, body); | |
9708 | ||
9709 | /* Consume the comma, if present. */ | |
9710 | if (*p == ',') | |
9711 | { | |
9712 | p++; | |
9713 | ||
9714 | p = consume_improper_spaces (p, body); | |
9715 | } | |
9716 | } | |
9717 | ||
9718 | if (*p == ')') | |
9719 | { | |
9720 | p++; | |
9721 | ||
9722 | if (*p == ' ') | |
9723 | /* Perfectly formed definition, no complaints. */ | |
9724 | macro_define_function (file, line, name, | |
9725 | argc, (const char **) argv, | |
9726 | p + 1); | |
9727 | else if (*p == '\0') | |
9728 | { | |
9729 | /* Complain, but do define it. */ | |
4d3c2250 | 9730 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9731 | macro_define_function (file, line, name, |
9732 | argc, (const char **) argv, | |
9733 | p); | |
9734 | } | |
9735 | else | |
9736 | /* Just complain. */ | |
4d3c2250 | 9737 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9738 | } |
9739 | else | |
9740 | /* Just complain. */ | |
4d3c2250 | 9741 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9742 | |
9743 | xfree (name); | |
9744 | { | |
9745 | int i; | |
9746 | ||
9747 | for (i = 0; i < argc; i++) | |
9748 | xfree (argv[i]); | |
9749 | } | |
9750 | xfree (argv); | |
9751 | } | |
9752 | else | |
4d3c2250 | 9753 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9754 | } |
9755 | ||
9756 | ||
9757 | static void | |
9758 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
9759 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 9760 | struct dwarf2_cu *cu) |
2e276125 | 9761 | { |
fe1b8b76 | 9762 | gdb_byte *mac_ptr, *mac_end; |
2e276125 JB |
9763 | struct macro_source_file *current_file = 0; |
9764 | ||
6502dd73 | 9765 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 9766 | { |
e2e0b3e5 | 9767 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
9768 | return; |
9769 | } | |
9770 | ||
6502dd73 DJ |
9771 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
9772 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
9773 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
9774 | |
9775 | for (;;) | |
9776 | { | |
9777 | enum dwarf_macinfo_record_type macinfo_type; | |
9778 | ||
9779 | /* Do we at least have room for a macinfo type byte? */ | |
9780 | if (mac_ptr >= mac_end) | |
9781 | { | |
4d3c2250 | 9782 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9783 | return; |
9784 | } | |
9785 | ||
9786 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
9787 | mac_ptr++; | |
9788 | ||
9789 | switch (macinfo_type) | |
9790 | { | |
9791 | /* A zero macinfo type indicates the end of the macro | |
9792 | information. */ | |
9793 | case 0: | |
9794 | return; | |
9795 | ||
9796 | case DW_MACINFO_define: | |
9797 | case DW_MACINFO_undef: | |
9798 | { | |
891d2f0b | 9799 | unsigned int bytes_read; |
2e276125 JB |
9800 | int line; |
9801 | char *body; | |
9802 | ||
9803 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9804 | mac_ptr += bytes_read; | |
9805 | body = read_string (abfd, mac_ptr, &bytes_read); | |
9806 | mac_ptr += bytes_read; | |
9807 | ||
9808 | if (! current_file) | |
4d3c2250 | 9809 | complaint (&symfile_complaints, |
e2e0b3e5 | 9810 | _("debug info gives macro %s outside of any file: %s"), |
4d3c2250 KB |
9811 | macinfo_type == |
9812 | DW_MACINFO_define ? "definition" : macinfo_type == | |
9813 | DW_MACINFO_undef ? "undefinition" : | |
9814 | "something-or-other", body); | |
2e276125 JB |
9815 | else |
9816 | { | |
9817 | if (macinfo_type == DW_MACINFO_define) | |
9818 | parse_macro_definition (current_file, line, body); | |
9819 | else if (macinfo_type == DW_MACINFO_undef) | |
9820 | macro_undef (current_file, line, body); | |
9821 | } | |
9822 | } | |
9823 | break; | |
9824 | ||
9825 | case DW_MACINFO_start_file: | |
9826 | { | |
891d2f0b | 9827 | unsigned int bytes_read; |
2e276125 JB |
9828 | int line, file; |
9829 | ||
9830 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9831 | mac_ptr += bytes_read; | |
9832 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9833 | mac_ptr += bytes_read; | |
9834 | ||
9835 | current_file = macro_start_file (file, line, | |
9836 | current_file, comp_dir, | |
e7c27a73 | 9837 | lh, cu->objfile); |
2e276125 JB |
9838 | } |
9839 | break; | |
9840 | ||
9841 | case DW_MACINFO_end_file: | |
9842 | if (! current_file) | |
4d3c2250 | 9843 | complaint (&symfile_complaints, |
e2e0b3e5 | 9844 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
9845 | else |
9846 | { | |
9847 | current_file = current_file->included_by; | |
9848 | if (! current_file) | |
9849 | { | |
9850 | enum dwarf_macinfo_record_type next_type; | |
9851 | ||
9852 | /* GCC circa March 2002 doesn't produce the zero | |
9853 | type byte marking the end of the compilation | |
9854 | unit. Complain if it's not there, but exit no | |
9855 | matter what. */ | |
9856 | ||
9857 | /* Do we at least have room for a macinfo type byte? */ | |
9858 | if (mac_ptr >= mac_end) | |
9859 | { | |
4d3c2250 | 9860 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9861 | return; |
9862 | } | |
9863 | ||
9864 | /* We don't increment mac_ptr here, so this is just | |
9865 | a look-ahead. */ | |
9866 | next_type = read_1_byte (abfd, mac_ptr); | |
9867 | if (next_type != 0) | |
4d3c2250 | 9868 | complaint (&symfile_complaints, |
e2e0b3e5 | 9869 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
9870 | |
9871 | return; | |
9872 | } | |
9873 | } | |
9874 | break; | |
9875 | ||
9876 | case DW_MACINFO_vendor_ext: | |
9877 | { | |
891d2f0b | 9878 | unsigned int bytes_read; |
2e276125 JB |
9879 | int constant; |
9880 | char *string; | |
9881 | ||
9882 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9883 | mac_ptr += bytes_read; | |
9884 | string = read_string (abfd, mac_ptr, &bytes_read); | |
9885 | mac_ptr += bytes_read; | |
9886 | ||
9887 | /* We don't recognize any vendor extensions. */ | |
9888 | } | |
9889 | break; | |
9890 | } | |
9891 | } | |
9892 | } | |
8e19ed76 PS |
9893 | |
9894 | /* Check if the attribute's form is a DW_FORM_block* | |
9895 | if so return true else false. */ | |
9896 | static int | |
9897 | attr_form_is_block (struct attribute *attr) | |
9898 | { | |
9899 | return (attr == NULL ? 0 : | |
9900 | attr->form == DW_FORM_block1 | |
9901 | || attr->form == DW_FORM_block2 | |
9902 | || attr->form == DW_FORM_block4 | |
9903 | || attr->form == DW_FORM_block); | |
9904 | } | |
4c2df51b | 9905 | |
c6a0999f JB |
9906 | /* Return non-zero if ATTR's value is a section offset --- classes |
9907 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. | |
9908 | You may use DW_UNSND (attr) to retrieve such offsets. | |
9909 | ||
9910 | Section 7.5.4, "Attribute Encodings", explains that no attribute | |
9911 | may have a value that belongs to more than one of these classes; it | |
9912 | would be ambiguous if we did, because we use the same forms for all | |
9913 | of them. */ | |
3690dd37 JB |
9914 | static int |
9915 | attr_form_is_section_offset (struct attribute *attr) | |
9916 | { | |
9917 | return (attr->form == DW_FORM_data4 | |
9918 | || attr->form == DW_FORM_data8); | |
9919 | } | |
9920 | ||
9921 | ||
9922 | /* Return non-zero if ATTR's value falls in the 'constant' class, or | |
9923 | zero otherwise. When this function returns true, you can apply | |
9924 | dwarf2_get_attr_constant_value to it. | |
9925 | ||
9926 | However, note that for some attributes you must check | |
9927 | attr_form_is_section_offset before using this test. DW_FORM_data4 | |
9928 | and DW_FORM_data8 are members of both the constant class, and of | |
9929 | the classes that contain offsets into other debug sections | |
9930 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says | |
9931 | that, if an attribute's can be either a constant or one of the | |
9932 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be | |
9933 | taken as section offsets, not constants. */ | |
9934 | static int | |
9935 | attr_form_is_constant (struct attribute *attr) | |
9936 | { | |
9937 | switch (attr->form) | |
9938 | { | |
9939 | case DW_FORM_sdata: | |
9940 | case DW_FORM_udata: | |
9941 | case DW_FORM_data1: | |
9942 | case DW_FORM_data2: | |
9943 | case DW_FORM_data4: | |
9944 | case DW_FORM_data8: | |
9945 | return 1; | |
9946 | default: | |
9947 | return 0; | |
9948 | } | |
9949 | } | |
9950 | ||
4c2df51b DJ |
9951 | static void |
9952 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9953 | struct dwarf2_cu *cu) |
4c2df51b | 9954 | { |
3690dd37 | 9955 | if (attr_form_is_section_offset (attr) |
99bcc461 DJ |
9956 | /* ".debug_loc" may not exist at all, or the offset may be outside |
9957 | the section. If so, fall through to the complaint in the | |
9958 | other branch. */ | |
9959 | && DW_UNSND (attr) < dwarf2_per_objfile->loc_size) | |
4c2df51b | 9960 | { |
0d53c4c4 | 9961 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 9962 | |
4a146b47 | 9963 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9964 | sizeof (struct dwarf2_loclist_baton)); |
ae0d2f24 UW |
9965 | baton->per_cu = cu->per_cu; |
9966 | gdb_assert (baton->per_cu); | |
4c2df51b | 9967 | |
0d53c4c4 DJ |
9968 | /* We don't know how long the location list is, but make sure we |
9969 | don't run off the edge of the section. */ | |
6502dd73 DJ |
9970 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
9971 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
9972 | baton->base_address = cu->header.base_address; |
9973 | if (cu->header.base_known == 0) | |
0d53c4c4 | 9974 | complaint (&symfile_complaints, |
e2e0b3e5 | 9975 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 9976 | |
a67af2b9 | 9977 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
9978 | SYMBOL_LOCATION_BATON (sym) = baton; |
9979 | } | |
9980 | else | |
9981 | { | |
9982 | struct dwarf2_locexpr_baton *baton; | |
9983 | ||
4a146b47 | 9984 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9985 | sizeof (struct dwarf2_locexpr_baton)); |
ae0d2f24 UW |
9986 | baton->per_cu = cu->per_cu; |
9987 | gdb_assert (baton->per_cu); | |
0d53c4c4 DJ |
9988 | |
9989 | if (attr_form_is_block (attr)) | |
9990 | { | |
9991 | /* Note that we're just copying the block's data pointer | |
9992 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
9993 | info_buffer for SYM's objfile; right now we never release |
9994 | that buffer, but when we do clean up properly this may | |
9995 | need to change. */ | |
0d53c4c4 DJ |
9996 | baton->size = DW_BLOCK (attr)->size; |
9997 | baton->data = DW_BLOCK (attr)->data; | |
9998 | } | |
9999 | else | |
10000 | { | |
10001 | dwarf2_invalid_attrib_class_complaint ("location description", | |
10002 | SYMBOL_NATURAL_NAME (sym)); | |
10003 | baton->size = 0; | |
10004 | baton->data = NULL; | |
10005 | } | |
10006 | ||
a67af2b9 | 10007 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
10008 | SYMBOL_LOCATION_BATON (sym) = baton; |
10009 | } | |
4c2df51b | 10010 | } |
6502dd73 | 10011 | |
ae0d2f24 UW |
10012 | /* Return the OBJFILE associated with the compilation unit CU. */ |
10013 | ||
10014 | struct objfile * | |
10015 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) | |
10016 | { | |
10017 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10018 | ||
10019 | /* Return the master objfile, so that we can report and look up the | |
10020 | correct file containing this variable. */ | |
10021 | if (objfile->separate_debug_objfile_backlink) | |
10022 | objfile = objfile->separate_debug_objfile_backlink; | |
10023 | ||
10024 | return objfile; | |
10025 | } | |
10026 | ||
10027 | /* Return the address size given in the compilation unit header for CU. */ | |
10028 | ||
10029 | CORE_ADDR | |
10030 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) | |
10031 | { | |
10032 | if (per_cu->cu) | |
10033 | return per_cu->cu->header.addr_size; | |
10034 | else | |
10035 | { | |
10036 | /* If the CU is not currently read in, we re-read its header. */ | |
10037 | struct objfile *objfile = per_cu->psymtab->objfile; | |
10038 | struct dwarf2_per_objfile *per_objfile | |
10039 | = objfile_data (objfile, dwarf2_objfile_data_key); | |
10040 | gdb_byte *info_ptr = per_objfile->info_buffer + per_cu->offset; | |
10041 | ||
10042 | struct comp_unit_head cu_header; | |
10043 | memset (&cu_header, 0, sizeof cu_header); | |
10044 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); | |
10045 | return cu_header.addr_size; | |
10046 | } | |
10047 | } | |
10048 | ||
ae038cb0 | 10049 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 10050 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
10051 | |
10052 | static struct dwarf2_per_cu_data * | |
10053 | dwarf2_find_containing_comp_unit (unsigned long offset, | |
10054 | struct objfile *objfile) | |
10055 | { | |
10056 | struct dwarf2_per_cu_data *this_cu; | |
10057 | int low, high; | |
10058 | ||
ae038cb0 DJ |
10059 | low = 0; |
10060 | high = dwarf2_per_objfile->n_comp_units - 1; | |
10061 | while (high > low) | |
10062 | { | |
10063 | int mid = low + (high - low) / 2; | |
10064 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
10065 | high = mid; | |
10066 | else | |
10067 | low = mid + 1; | |
10068 | } | |
10069 | gdb_assert (low == high); | |
10070 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
10071 | { | |
10b3939b | 10072 | if (low == 0) |
8a3fe4f8 AC |
10073 | error (_("Dwarf Error: could not find partial DIE containing " |
10074 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
10075 | (long) offset, bfd_get_filename (objfile->obfd)); |
10076 | ||
ae038cb0 DJ |
10077 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
10078 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
10079 | } | |
10080 | else | |
10081 | { | |
10082 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
10083 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
10084 | && offset >= this_cu->offset + this_cu->length) | |
8a3fe4f8 | 10085 | error (_("invalid dwarf2 offset %ld"), offset); |
ae038cb0 DJ |
10086 | gdb_assert (offset < this_cu->offset + this_cu->length); |
10087 | return this_cu; | |
10088 | } | |
10089 | } | |
10090 | ||
10b3939b DJ |
10091 | /* Locate the compilation unit from OBJFILE which is located at exactly |
10092 | OFFSET. Raises an error on failure. */ | |
10093 | ||
ae038cb0 DJ |
10094 | static struct dwarf2_per_cu_data * |
10095 | dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile) | |
10096 | { | |
10097 | struct dwarf2_per_cu_data *this_cu; | |
10098 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
10099 | if (this_cu->offset != offset) | |
8a3fe4f8 | 10100 | error (_("no compilation unit with offset %ld."), offset); |
ae038cb0 DJ |
10101 | return this_cu; |
10102 | } | |
10103 | ||
10104 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
10105 | of compilation units, but we don't remove it from the read_in_chain; | |
10106 | the caller is responsible for that. */ | |
10107 | ||
10108 | static void | |
10109 | free_one_comp_unit (void *data) | |
10110 | { | |
10111 | struct dwarf2_cu *cu = data; | |
10112 | ||
10113 | if (cu->per_cu != NULL) | |
10114 | cu->per_cu->cu = NULL; | |
10115 | cu->per_cu = NULL; | |
10116 | ||
10117 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10b3939b DJ |
10118 | if (cu->dies) |
10119 | free_die_list (cu->dies); | |
ae038cb0 DJ |
10120 | |
10121 | xfree (cu); | |
10122 | } | |
10123 | ||
72bf9492 | 10124 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
10125 | when we're finished with it. We can't free the pointer itself, but be |
10126 | sure to unlink it from the cache. Also release any associated storage | |
10127 | and perform cache maintenance. | |
72bf9492 DJ |
10128 | |
10129 | Only used during partial symbol parsing. */ | |
10130 | ||
10131 | static void | |
10132 | free_stack_comp_unit (void *data) | |
10133 | { | |
10134 | struct dwarf2_cu *cu = data; | |
10135 | ||
10136 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10137 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
10138 | |
10139 | if (cu->per_cu != NULL) | |
10140 | { | |
10141 | /* This compilation unit is on the stack in our caller, so we | |
10142 | should not xfree it. Just unlink it. */ | |
10143 | cu->per_cu->cu = NULL; | |
10144 | cu->per_cu = NULL; | |
10145 | ||
10146 | /* If we had a per-cu pointer, then we may have other compilation | |
10147 | units loaded, so age them now. */ | |
10148 | age_cached_comp_units (); | |
10149 | } | |
10150 | } | |
10151 | ||
10152 | /* Free all cached compilation units. */ | |
10153 | ||
10154 | static void | |
10155 | free_cached_comp_units (void *data) | |
10156 | { | |
10157 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10158 | ||
10159 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10160 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10161 | while (per_cu != NULL) | |
10162 | { | |
10163 | struct dwarf2_per_cu_data *next_cu; | |
10164 | ||
10165 | next_cu = per_cu->cu->read_in_chain; | |
10166 | ||
10167 | free_one_comp_unit (per_cu->cu); | |
10168 | *last_chain = next_cu; | |
10169 | ||
10170 | per_cu = next_cu; | |
10171 | } | |
10172 | } | |
10173 | ||
10174 | /* Increase the age counter on each cached compilation unit, and free | |
10175 | any that are too old. */ | |
10176 | ||
10177 | static void | |
10178 | age_cached_comp_units (void) | |
10179 | { | |
10180 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10181 | ||
10182 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
10183 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10184 | while (per_cu != NULL) | |
10185 | { | |
10186 | per_cu->cu->last_used ++; | |
10187 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
10188 | dwarf2_mark (per_cu->cu); | |
10189 | per_cu = per_cu->cu->read_in_chain; | |
10190 | } | |
10191 | ||
10192 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10193 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10194 | while (per_cu != NULL) | |
10195 | { | |
10196 | struct dwarf2_per_cu_data *next_cu; | |
10197 | ||
10198 | next_cu = per_cu->cu->read_in_chain; | |
10199 | ||
10200 | if (!per_cu->cu->mark) | |
10201 | { | |
10202 | free_one_comp_unit (per_cu->cu); | |
10203 | *last_chain = next_cu; | |
10204 | } | |
10205 | else | |
10206 | last_chain = &per_cu->cu->read_in_chain; | |
10207 | ||
10208 | per_cu = next_cu; | |
10209 | } | |
10210 | } | |
10211 | ||
10212 | /* Remove a single compilation unit from the cache. */ | |
10213 | ||
10214 | static void | |
10215 | free_one_cached_comp_unit (void *target_cu) | |
10216 | { | |
10217 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
10218 | ||
10219 | per_cu = dwarf2_per_objfile->read_in_chain; | |
10220 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
10221 | while (per_cu != NULL) | |
10222 | { | |
10223 | struct dwarf2_per_cu_data *next_cu; | |
10224 | ||
10225 | next_cu = per_cu->cu->read_in_chain; | |
10226 | ||
10227 | if (per_cu->cu == target_cu) | |
10228 | { | |
10229 | free_one_comp_unit (per_cu->cu); | |
10230 | *last_chain = next_cu; | |
10231 | break; | |
10232 | } | |
10233 | else | |
10234 | last_chain = &per_cu->cu->read_in_chain; | |
10235 | ||
10236 | per_cu = next_cu; | |
10237 | } | |
10238 | } | |
10239 | ||
fe3e1990 DJ |
10240 | /* Release all extra memory associated with OBJFILE. */ |
10241 | ||
10242 | void | |
10243 | dwarf2_free_objfile (struct objfile *objfile) | |
10244 | { | |
10245 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); | |
10246 | ||
10247 | if (dwarf2_per_objfile == NULL) | |
10248 | return; | |
10249 | ||
10250 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ | |
10251 | free_cached_comp_units (NULL); | |
10252 | ||
10253 | /* Everything else should be on the objfile obstack. */ | |
10254 | } | |
10255 | ||
1c379e20 DJ |
10256 | /* A pair of DIE offset and GDB type pointer. We store these |
10257 | in a hash table separate from the DIEs, and preserve them | |
10258 | when the DIEs are flushed out of cache. */ | |
10259 | ||
10260 | struct dwarf2_offset_and_type | |
10261 | { | |
10262 | unsigned int offset; | |
10263 | struct type *type; | |
10264 | }; | |
10265 | ||
10266 | /* Hash function for a dwarf2_offset_and_type. */ | |
10267 | ||
10268 | static hashval_t | |
10269 | offset_and_type_hash (const void *item) | |
10270 | { | |
10271 | const struct dwarf2_offset_and_type *ofs = item; | |
10272 | return ofs->offset; | |
10273 | } | |
10274 | ||
10275 | /* Equality function for a dwarf2_offset_and_type. */ | |
10276 | ||
10277 | static int | |
10278 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
10279 | { | |
10280 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
10281 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
10282 | return ofs_lhs->offset == ofs_rhs->offset; | |
10283 | } | |
10284 | ||
10285 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
f792889a | 10286 | table if necessary. For convenience, return TYPE. */ |
1c379e20 | 10287 | |
f792889a | 10288 | static struct type * |
1c379e20 DJ |
10289 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
10290 | { | |
10291 | struct dwarf2_offset_and_type **slot, ofs; | |
10292 | ||
f792889a DJ |
10293 | if (cu->type_hash == NULL) |
10294 | { | |
10295 | gdb_assert (cu->per_cu != NULL); | |
10296 | cu->per_cu->type_hash | |
10297 | = htab_create_alloc_ex (cu->header.length / 24, | |
10298 | offset_and_type_hash, | |
10299 | offset_and_type_eq, | |
10300 | NULL, | |
10301 | &cu->objfile->objfile_obstack, | |
10302 | hashtab_obstack_allocate, | |
10303 | dummy_obstack_deallocate); | |
10304 | cu->type_hash = cu->per_cu->type_hash; | |
10305 | } | |
1c379e20 DJ |
10306 | |
10307 | ofs.offset = die->offset; | |
10308 | ofs.type = type; | |
10309 | slot = (struct dwarf2_offset_and_type **) | |
f792889a | 10310 | htab_find_slot_with_hash (cu->type_hash, &ofs, ofs.offset, INSERT); |
1c379e20 DJ |
10311 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); |
10312 | **slot = ofs; | |
f792889a | 10313 | return type; |
1c379e20 DJ |
10314 | } |
10315 | ||
f792889a DJ |
10316 | /* Find the type for DIE in CU's type_hash, or return NULL if DIE does |
10317 | not have a saved type. */ | |
1c379e20 DJ |
10318 | |
10319 | static struct type * | |
f792889a | 10320 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
1c379e20 DJ |
10321 | { |
10322 | struct dwarf2_offset_and_type *slot, ofs; | |
f792889a DJ |
10323 | htab_t type_hash = cu->type_hash; |
10324 | ||
10325 | if (type_hash == NULL) | |
10326 | return NULL; | |
1c379e20 DJ |
10327 | |
10328 | ofs.offset = die->offset; | |
10329 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
10330 | if (slot) | |
10331 | return slot->type; | |
10332 | else | |
10333 | return NULL; | |
10334 | } | |
10335 | ||
10b3939b DJ |
10336 | /* Set the mark field in CU and in every other compilation unit in the |
10337 | cache that we must keep because we are keeping CU. */ | |
10338 | ||
10339 | /* Add a dependence relationship from CU to REF_PER_CU. */ | |
10340 | ||
10341 | static void | |
10342 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
10343 | struct dwarf2_per_cu_data *ref_per_cu) | |
10344 | { | |
10345 | void **slot; | |
10346 | ||
10347 | if (cu->dependencies == NULL) | |
10348 | cu->dependencies | |
10349 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
10350 | NULL, &cu->comp_unit_obstack, | |
10351 | hashtab_obstack_allocate, | |
10352 | dummy_obstack_deallocate); | |
10353 | ||
10354 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
10355 | if (*slot == NULL) | |
10356 | *slot = ref_per_cu; | |
10357 | } | |
1c379e20 | 10358 | |
ae038cb0 DJ |
10359 | /* Set the mark field in CU and in every other compilation unit in the |
10360 | cache that we must keep because we are keeping CU. */ | |
10361 | ||
10b3939b DJ |
10362 | static int |
10363 | dwarf2_mark_helper (void **slot, void *data) | |
10364 | { | |
10365 | struct dwarf2_per_cu_data *per_cu; | |
10366 | ||
10367 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
10368 | if (per_cu->cu->mark) | |
10369 | return 1; | |
10370 | per_cu->cu->mark = 1; | |
10371 | ||
10372 | if (per_cu->cu->dependencies != NULL) | |
10373 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
10374 | ||
10375 | return 1; | |
10376 | } | |
10377 | ||
ae038cb0 DJ |
10378 | static void |
10379 | dwarf2_mark (struct dwarf2_cu *cu) | |
10380 | { | |
10381 | if (cu->mark) | |
10382 | return; | |
10383 | cu->mark = 1; | |
10b3939b DJ |
10384 | if (cu->dependencies != NULL) |
10385 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
10386 | } |
10387 | ||
10388 | static void | |
10389 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
10390 | { | |
10391 | while (per_cu) | |
10392 | { | |
10393 | per_cu->cu->mark = 0; | |
10394 | per_cu = per_cu->cu->read_in_chain; | |
10395 | } | |
72bf9492 DJ |
10396 | } |
10397 | ||
72bf9492 DJ |
10398 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10399 | is its offset in .debug_info for this objfile. */ | |
10400 | ||
10401 | static hashval_t | |
10402 | partial_die_hash (const void *item) | |
10403 | { | |
10404 | const struct partial_die_info *part_die = item; | |
10405 | return part_die->offset; | |
10406 | } | |
10407 | ||
10408 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10409 | are equal if they have the same offset. */ | |
10410 | ||
10411 | static int | |
10412 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10413 | { | |
10414 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10415 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10416 | return part_die_lhs->offset == part_die_rhs->offset; | |
10417 | } | |
10418 | ||
ae038cb0 DJ |
10419 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10420 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10421 | ||
10422 | static void | |
10423 | set_dwarf2_cmd (char *args, int from_tty) | |
10424 | { | |
10425 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10426 | } | |
10427 | ||
10428 | static void | |
10429 | show_dwarf2_cmd (char *args, int from_tty) | |
10430 | { | |
10431 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10432 | } | |
10433 | ||
6502dd73 DJ |
10434 | void _initialize_dwarf2_read (void); |
10435 | ||
10436 | void | |
10437 | _initialize_dwarf2_read (void) | |
10438 | { | |
10439 | dwarf2_objfile_data_key = register_objfile_data (); | |
ae038cb0 | 10440 | |
1bedd215 AC |
10441 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10442 | Set DWARF 2 specific variables.\n\ | |
10443 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10444 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10445 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10446 | ||
1bedd215 AC |
10447 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10448 | Show DWARF 2 specific variables\n\ | |
10449 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10450 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10451 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10452 | ||
10453 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10454 | &dwarf2_max_cache_age, _("\ |
10455 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10456 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10457 | A higher limit means that cached compilation units will be stored\n\ | |
10458 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10459 | caching, which can slow down startup."), | |
2c5b56ce | 10460 | NULL, |
920d2a44 | 10461 | show_dwarf2_max_cache_age, |
2c5b56ce | 10462 | &set_dwarf2_cmdlist, |
ae038cb0 | 10463 | &show_dwarf2_cmdlist); |
6502dd73 | 10464 | } |