]>
Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
917c78fc | 2 | |
72019c9c | 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, |
fa4028e9 | 4 | 2002, 2003, 2004, 2005, 2006, 2007 |
8e65ff28 | 5 | Free Software Foundation, Inc. |
c906108c SS |
6 | |
7 | Adapted by Gary Funck ([email protected]), Intrepid Technology, | |
8 | Inc. with support from Florida State University (under contract | |
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
12 | support in dwarfread.c | |
13 | ||
c5aa993b | 14 | This file is part of GDB. |
c906108c | 15 | |
c5aa993b JM |
16 | This program is free software; you can redistribute it and/or modify |
17 | it under the terms of the GNU General Public License as published by | |
18 | the Free Software Foundation; either version 2 of the License, or (at | |
19 | your option) any later version. | |
c906108c | 20 | |
c5aa993b JM |
21 | This program is distributed in the hope that it will be useful, but |
22 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
24 | General Public License for more details. | |
c906108c | 25 | |
c5aa993b JM |
26 | You should have received a copy of the GNU General Public License |
27 | along with this program; if not, write to the Free Software | |
197e01b6 EZ |
28 | Foundation, Inc., 51 Franklin Street, Fifth Floor, |
29 | Boston, MA 02110-1301, USA. */ | |
c906108c SS |
30 | |
31 | #include "defs.h" | |
32 | #include "bfd.h" | |
c906108c SS |
33 | #include "symtab.h" |
34 | #include "gdbtypes.h" | |
c906108c SS |
35 | #include "objfiles.h" |
36 | #include "elf/dwarf2.h" | |
37 | #include "buildsym.h" | |
38 | #include "demangle.h" | |
39 | #include "expression.h" | |
d5166ae1 | 40 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 41 | #include "macrotab.h" |
c906108c SS |
42 | #include "language.h" |
43 | #include "complaints.h" | |
357e46e7 | 44 | #include "bcache.h" |
4c2df51b DJ |
45 | #include "dwarf2expr.h" |
46 | #include "dwarf2loc.h" | |
9219021c | 47 | #include "cp-support.h" |
72bf9492 | 48 | #include "hashtab.h" |
ae038cb0 DJ |
49 | #include "command.h" |
50 | #include "gdbcmd.h" | |
4c2df51b | 51 | |
c906108c SS |
52 | #include <fcntl.h> |
53 | #include "gdb_string.h" | |
4bdf3d34 | 54 | #include "gdb_assert.h" |
c906108c SS |
55 | #include <sys/types.h> |
56 | ||
d8151005 DJ |
57 | /* A note on memory usage for this file. |
58 | ||
59 | At the present time, this code reads the debug info sections into | |
60 | the objfile's objfile_obstack. A definite improvement for startup | |
61 | time, on platforms which do not emit relocations for debug | |
62 | sections, would be to use mmap instead. The object's complete | |
63 | debug information is loaded into memory, partly to simplify | |
64 | absolute DIE references. | |
65 | ||
66 | Whether using obstacks or mmap, the sections should remain loaded | |
67 | until the objfile is released, and pointers into the section data | |
68 | can be used for any other data associated to the objfile (symbol | |
69 | names, type names, location expressions to name a few). */ | |
70 | ||
88496bb5 MS |
71 | #ifndef DWARF2_REG_TO_REGNUM |
72 | #define DWARF2_REG_TO_REGNUM(REG) (REG) | |
73 | #endif | |
74 | ||
107d2387 | 75 | #if 0 |
357e46e7 | 76 | /* .debug_info header for a compilation unit |
c906108c SS |
77 | Because of alignment constraints, this structure has padding and cannot |
78 | be mapped directly onto the beginning of the .debug_info section. */ | |
79 | typedef struct comp_unit_header | |
80 | { | |
81 | unsigned int length; /* length of the .debug_info | |
82 | contribution */ | |
83 | unsigned short version; /* version number -- 2 for DWARF | |
84 | version 2 */ | |
85 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
86 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
87 | } | |
88 | _COMP_UNIT_HEADER; | |
89 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 90 | #endif |
c906108c SS |
91 | |
92 | /* .debug_pubnames header | |
93 | Because of alignment constraints, this structure has padding and cannot | |
94 | be mapped directly onto the beginning of the .debug_info section. */ | |
95 | typedef struct pubnames_header | |
96 | { | |
97 | unsigned int length; /* length of the .debug_pubnames | |
98 | contribution */ | |
99 | unsigned char version; /* version number -- 2 for DWARF | |
100 | version 2 */ | |
101 | unsigned int info_offset; /* offset into .debug_info section */ | |
102 | unsigned int info_size; /* byte size of .debug_info section | |
103 | portion */ | |
104 | } | |
105 | _PUBNAMES_HEADER; | |
106 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
107 | ||
108 | /* .debug_pubnames header | |
109 | Because of alignment constraints, this structure has padding and cannot | |
110 | be mapped directly onto the beginning of the .debug_info section. */ | |
111 | typedef struct aranges_header | |
112 | { | |
113 | unsigned int length; /* byte len of the .debug_aranges | |
114 | contribution */ | |
115 | unsigned short version; /* version number -- 2 for DWARF | |
116 | version 2 */ | |
117 | unsigned int info_offset; /* offset into .debug_info section */ | |
118 | unsigned char addr_size; /* byte size of an address */ | |
119 | unsigned char seg_size; /* byte size of segment descriptor */ | |
120 | } | |
121 | _ARANGES_HEADER; | |
122 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
123 | ||
124 | /* .debug_line statement program prologue | |
125 | Because of alignment constraints, this structure has padding and cannot | |
126 | be mapped directly onto the beginning of the .debug_info section. */ | |
127 | typedef struct statement_prologue | |
128 | { | |
129 | unsigned int total_length; /* byte length of the statement | |
130 | information */ | |
131 | unsigned short version; /* version number -- 2 for DWARF | |
132 | version 2 */ | |
133 | unsigned int prologue_length; /* # bytes between prologue & | |
134 | stmt program */ | |
135 | unsigned char minimum_instruction_length; /* byte size of | |
136 | smallest instr */ | |
137 | unsigned char default_is_stmt; /* initial value of is_stmt | |
138 | register */ | |
139 | char line_base; | |
140 | unsigned char line_range; | |
141 | unsigned char opcode_base; /* number assigned to first special | |
142 | opcode */ | |
143 | unsigned char *standard_opcode_lengths; | |
144 | } | |
145 | _STATEMENT_PROLOGUE; | |
146 | ||
6502dd73 DJ |
147 | static const struct objfile_data *dwarf2_objfile_data_key; |
148 | ||
149 | struct dwarf2_per_objfile | |
150 | { | |
151 | /* Sizes of debugging sections. */ | |
152 | unsigned int info_size; | |
153 | unsigned int abbrev_size; | |
154 | unsigned int line_size; | |
155 | unsigned int pubnames_size; | |
156 | unsigned int aranges_size; | |
157 | unsigned int loc_size; | |
158 | unsigned int macinfo_size; | |
159 | unsigned int str_size; | |
160 | unsigned int ranges_size; | |
161 | unsigned int frame_size; | |
162 | unsigned int eh_frame_size; | |
163 | ||
164 | /* Loaded data from the sections. */ | |
fe1b8b76 JB |
165 | gdb_byte *info_buffer; |
166 | gdb_byte *abbrev_buffer; | |
167 | gdb_byte *line_buffer; | |
168 | gdb_byte *str_buffer; | |
169 | gdb_byte *macinfo_buffer; | |
170 | gdb_byte *ranges_buffer; | |
171 | gdb_byte *loc_buffer; | |
ae038cb0 | 172 | |
10b3939b DJ |
173 | /* A list of all the compilation units. This is used to locate |
174 | the target compilation unit of a particular reference. */ | |
ae038cb0 DJ |
175 | struct dwarf2_per_cu_data **all_comp_units; |
176 | ||
177 | /* The number of compilation units in ALL_COMP_UNITS. */ | |
178 | int n_comp_units; | |
179 | ||
180 | /* A chain of compilation units that are currently read in, so that | |
181 | they can be freed later. */ | |
182 | struct dwarf2_per_cu_data *read_in_chain; | |
72dca2f5 FR |
183 | |
184 | /* A flag indicating wether this objfile has a section loaded at a | |
185 | VMA of 0. */ | |
186 | int has_section_at_zero; | |
6502dd73 DJ |
187 | }; |
188 | ||
189 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 190 | |
086df311 DJ |
191 | static asection *dwarf_info_section; |
192 | static asection *dwarf_abbrev_section; | |
193 | static asection *dwarf_line_section; | |
194 | static asection *dwarf_pubnames_section; | |
195 | static asection *dwarf_aranges_section; | |
196 | static asection *dwarf_loc_section; | |
197 | static asection *dwarf_macinfo_section; | |
198 | static asection *dwarf_str_section; | |
199 | static asection *dwarf_ranges_section; | |
200 | asection *dwarf_frame_section; | |
201 | asection *dwarf_eh_frame_section; | |
202 | ||
c906108c SS |
203 | /* names of the debugging sections */ |
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" | |
af34e669 | 213 | #define RANGES_SECTION ".debug_ranges" |
b6af0555 JS |
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 | ||
298 | /* Maintain an array of referenced fundamental types for the current | |
299 | compilation unit being read. For DWARF version 1, we have to construct | |
300 | the fundamental types on the fly, since no information about the | |
301 | fundamental types is supplied. Each such fundamental type is created by | |
302 | calling a language dependent routine to create the type, and then a | |
303 | pointer to that type is then placed in the array at the index specified | |
304 | by it's FT_<TYPENAME> value. The array has a fixed size set by the | |
305 | FT_NUM_MEMBERS compile time constant, which is the number of predefined | |
306 | fundamental types gdb knows how to construct. */ | |
307 | struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ | |
f3dd6933 DJ |
308 | |
309 | /* DWARF abbreviation table associated with this compilation unit. */ | |
310 | struct abbrev_info **dwarf2_abbrevs; | |
311 | ||
312 | /* Storage for the abbrev table. */ | |
313 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
314 | |
315 | /* Hash table holding all the loaded partial DIEs. */ | |
316 | htab_t partial_dies; | |
317 | ||
318 | /* Storage for things with the same lifetime as this read-in compilation | |
319 | unit, including partial DIEs. */ | |
320 | struct obstack comp_unit_obstack; | |
321 | ||
ae038cb0 DJ |
322 | /* When multiple dwarf2_cu structures are living in memory, this field |
323 | chains them all together, so that they can be released efficiently. | |
324 | We will probably also want a generation counter so that most-recently-used | |
325 | compilation units are cached... */ | |
326 | struct dwarf2_per_cu_data *read_in_chain; | |
327 | ||
328 | /* Backchain to our per_cu entry if the tree has been built. */ | |
329 | struct dwarf2_per_cu_data *per_cu; | |
330 | ||
331 | /* How many compilation units ago was this CU last referenced? */ | |
332 | int last_used; | |
333 | ||
10b3939b DJ |
334 | /* A hash table of die offsets for following references. */ |
335 | struct die_info *die_ref_table[REF_HASH_SIZE]; | |
336 | ||
337 | /* Full DIEs if read in. */ | |
338 | struct die_info *dies; | |
339 | ||
340 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |
341 | units referenced by this one. Only set during full symbol processing; | |
342 | partial symbol tables do not have dependencies. */ | |
343 | htab_t dependencies; | |
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; | |
e7c27a73 DJ |
357 | }; |
358 | ||
10b3939b DJ |
359 | /* Persistent data held for a compilation unit, even when not |
360 | processing it. We put a pointer to this structure in the | |
361 | read_symtab_private field of the psymtab. If we encounter | |
362 | inter-compilation-unit references, we also maintain a sorted | |
363 | list of all compilation units. */ | |
364 | ||
ae038cb0 DJ |
365 | struct dwarf2_per_cu_data |
366 | { | |
5afb4e99 | 367 | /* The start offset and length of this compilation unit. 2**30-1 |
ae038cb0 DJ |
368 | bytes should suffice to store the length of any compilation unit |
369 | - if it doesn't, GDB will fall over anyway. */ | |
370 | unsigned long offset; | |
5afb4e99 | 371 | unsigned long length : 30; |
ae038cb0 DJ |
372 | |
373 | /* Flag indicating this compilation unit will be read in before | |
374 | any of the current compilation units are processed. */ | |
375 | unsigned long queued : 1; | |
376 | ||
5afb4e99 DJ |
377 | /* This flag will be set if we need to load absolutely all DIEs |
378 | for this compilation unit, instead of just the ones we think | |
379 | are interesting. It gets set if we look for a DIE in the | |
380 | hash table and don't find it. */ | |
381 | unsigned int load_all_dies : 1; | |
382 | ||
ae038cb0 DJ |
383 | /* Set iff currently read in. */ |
384 | struct dwarf2_cu *cu; | |
1c379e20 DJ |
385 | |
386 | /* If full symbols for this CU have been read in, then this field | |
387 | holds a map of DIE offsets to types. It isn't always possible | |
388 | to reconstruct this information later, so we have to preserve | |
389 | it. */ | |
1c379e20 | 390 | htab_t type_hash; |
10b3939b | 391 | |
31ffec48 DJ |
392 | /* The partial symbol table associated with this compilation unit, |
393 | or NULL for partial units (which do not have an associated | |
394 | symtab). */ | |
10b3939b | 395 | struct partial_symtab *psymtab; |
ae038cb0 DJ |
396 | }; |
397 | ||
debd256d JB |
398 | /* The line number information for a compilation unit (found in the |
399 | .debug_line section) begins with a "statement program header", | |
400 | which contains the following information. */ | |
401 | struct line_header | |
402 | { | |
403 | unsigned int total_length; | |
404 | unsigned short version; | |
405 | unsigned int header_length; | |
406 | unsigned char minimum_instruction_length; | |
407 | unsigned char default_is_stmt; | |
408 | int line_base; | |
409 | unsigned char line_range; | |
410 | unsigned char opcode_base; | |
411 | ||
412 | /* standard_opcode_lengths[i] is the number of operands for the | |
413 | standard opcode whose value is i. This means that | |
414 | standard_opcode_lengths[0] is unused, and the last meaningful | |
415 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
416 | unsigned char *standard_opcode_lengths; | |
417 | ||
418 | /* The include_directories table. NOTE! These strings are not | |
419 | allocated with xmalloc; instead, they are pointers into | |
420 | debug_line_buffer. If you try to free them, `free' will get | |
421 | indigestion. */ | |
422 | unsigned int num_include_dirs, include_dirs_size; | |
423 | char **include_dirs; | |
424 | ||
425 | /* The file_names table. NOTE! These strings are not allocated | |
426 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
427 | Don't try to free them directly. */ | |
428 | unsigned int num_file_names, file_names_size; | |
429 | struct file_entry | |
c906108c | 430 | { |
debd256d JB |
431 | char *name; |
432 | unsigned int dir_index; | |
433 | unsigned int mod_time; | |
434 | unsigned int length; | |
aaa75496 | 435 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
debd256d JB |
436 | } *file_names; |
437 | ||
438 | /* The start and end of the statement program following this | |
6502dd73 | 439 | header. These point into dwarf2_per_objfile->line_buffer. */ |
fe1b8b76 | 440 | gdb_byte *statement_program_start, *statement_program_end; |
debd256d | 441 | }; |
c906108c SS |
442 | |
443 | /* When we construct a partial symbol table entry we only | |
444 | need this much information. */ | |
445 | struct partial_die_info | |
446 | { | |
72bf9492 | 447 | /* Offset of this DIE. */ |
c906108c | 448 | unsigned int offset; |
72bf9492 DJ |
449 | |
450 | /* DWARF-2 tag for this DIE. */ | |
451 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
452 | ||
453 | /* Language code associated with this DIE. This is only used | |
454 | for the compilation unit DIE. */ | |
455 | unsigned int language : 8; | |
456 | ||
457 | /* Assorted flags describing the data found in this DIE. */ | |
458 | unsigned int has_children : 1; | |
459 | unsigned int is_external : 1; | |
460 | unsigned int is_declaration : 1; | |
461 | unsigned int has_type : 1; | |
462 | unsigned int has_specification : 1; | |
aaa75496 | 463 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
464 | unsigned int has_pc_info : 1; |
465 | ||
466 | /* Flag set if the SCOPE field of this structure has been | |
467 | computed. */ | |
468 | unsigned int scope_set : 1; | |
469 | ||
fa4028e9 JB |
470 | /* Flag set if the DIE has a byte_size attribute. */ |
471 | unsigned int has_byte_size : 1; | |
472 | ||
72bf9492 DJ |
473 | /* The name of this DIE. Normally the value of DW_AT_name, but |
474 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
475 | other fashion. */ | |
c906108c | 476 | char *name; |
57c22c6c | 477 | char *dirname; |
72bf9492 DJ |
478 | |
479 | /* The scope to prepend to our children. This is generally | |
480 | allocated on the comp_unit_obstack, so will disappear | |
481 | when this compilation unit leaves the cache. */ | |
482 | char *scope; | |
483 | ||
484 | /* The location description associated with this DIE, if any. */ | |
485 | struct dwarf_block *locdesc; | |
486 | ||
487 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
488 | CORE_ADDR lowpc; |
489 | CORE_ADDR highpc; | |
72bf9492 DJ |
490 | |
491 | /* Pointer into the info_buffer pointing at the target of | |
492 | DW_AT_sibling, if any. */ | |
fe1b8b76 | 493 | gdb_byte *sibling; |
72bf9492 DJ |
494 | |
495 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
496 | DW_AT_specification (or DW_AT_abstract_origin or | |
497 | DW_AT_extension). */ | |
498 | unsigned int spec_offset; | |
499 | ||
aaa75496 JB |
500 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
501 | unsigned int line_offset; | |
502 | ||
72bf9492 DJ |
503 | /* Pointers to this DIE's parent, first child, and next sibling, |
504 | if any. */ | |
505 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
506 | }; |
507 | ||
508 | /* This data structure holds the information of an abbrev. */ | |
509 | struct abbrev_info | |
510 | { | |
511 | unsigned int number; /* number identifying abbrev */ | |
512 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
513 | unsigned short has_children; /* boolean */ |
514 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
515 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
516 | struct abbrev_info *next; /* next in chain */ | |
517 | }; | |
518 | ||
519 | struct attr_abbrev | |
520 | { | |
521 | enum dwarf_attribute name; | |
522 | enum dwarf_form form; | |
523 | }; | |
524 | ||
525 | /* This data structure holds a complete die structure. */ | |
526 | struct die_info | |
527 | { | |
c5aa993b | 528 | enum dwarf_tag tag; /* Tag indicating type of die */ |
c5aa993b JM |
529 | unsigned int abbrev; /* Abbrev number */ |
530 | unsigned int offset; /* Offset in .debug_info section */ | |
531 | unsigned int num_attrs; /* Number of attributes */ | |
532 | struct attribute *attrs; /* An array of attributes */ | |
533 | struct die_info *next_ref; /* Next die in ref hash table */ | |
78ba4af6 JB |
534 | |
535 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
536 | points to this die's parent; CHILD points to the first child of | |
537 | this node; and all the children of a given node are chained | |
538 | together via their SIBLING fields, terminated by a die whose | |
539 | tag is zero. */ | |
639d11d3 DC |
540 | struct die_info *child; /* Its first child, if any. */ |
541 | struct die_info *sibling; /* Its next sibling, if any. */ | |
542 | struct die_info *parent; /* Its parent, if any. */ | |
78ba4af6 | 543 | |
c5aa993b | 544 | struct type *type; /* Cached type information */ |
c906108c SS |
545 | }; |
546 | ||
547 | /* Attributes have a name and a value */ | |
548 | struct attribute | |
549 | { | |
550 | enum dwarf_attribute name; | |
551 | enum dwarf_form form; | |
552 | union | |
553 | { | |
554 | char *str; | |
555 | struct dwarf_block *blk; | |
ce5d95e1 JB |
556 | unsigned long unsnd; |
557 | long int snd; | |
c906108c SS |
558 | CORE_ADDR addr; |
559 | } | |
560 | u; | |
561 | }; | |
562 | ||
5fb290d7 DJ |
563 | struct function_range |
564 | { | |
565 | const char *name; | |
566 | CORE_ADDR lowpc, highpc; | |
567 | int seen_line; | |
568 | struct function_range *next; | |
569 | }; | |
570 | ||
c906108c SS |
571 | /* Get at parts of an attribute structure */ |
572 | ||
573 | #define DW_STRING(attr) ((attr)->u.str) | |
574 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
575 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
576 | #define DW_SND(attr) ((attr)->u.snd) | |
577 | #define DW_ADDR(attr) ((attr)->u.addr) | |
578 | ||
579 | /* Blocks are a bunch of untyped bytes. */ | |
580 | struct dwarf_block | |
581 | { | |
582 | unsigned int size; | |
fe1b8b76 | 583 | gdb_byte *data; |
c906108c SS |
584 | }; |
585 | ||
c906108c SS |
586 | #ifndef ATTR_ALLOC_CHUNK |
587 | #define ATTR_ALLOC_CHUNK 4 | |
588 | #endif | |
589 | ||
c906108c SS |
590 | /* Allocate fields for structs, unions and enums in this size. */ |
591 | #ifndef DW_FIELD_ALLOC_CHUNK | |
592 | #define DW_FIELD_ALLOC_CHUNK 4 | |
593 | #endif | |
594 | ||
c906108c SS |
595 | /* A zeroed version of a partial die for initialization purposes. */ |
596 | static struct partial_die_info zeroed_partial_die; | |
597 | ||
c906108c SS |
598 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
599 | but this would require a corresponding change in unpack_field_as_long | |
600 | and friends. */ | |
601 | static int bits_per_byte = 8; | |
602 | ||
603 | /* The routines that read and process dies for a C struct or C++ class | |
604 | pass lists of data member fields and lists of member function fields | |
605 | in an instance of a field_info structure, as defined below. */ | |
606 | struct field_info | |
c5aa993b JM |
607 | { |
608 | /* List of data member and baseclasses fields. */ | |
609 | struct nextfield | |
610 | { | |
611 | struct nextfield *next; | |
612 | int accessibility; | |
613 | int virtuality; | |
614 | struct field field; | |
615 | } | |
616 | *fields; | |
c906108c | 617 | |
c5aa993b JM |
618 | /* Number of fields. */ |
619 | int nfields; | |
c906108c | 620 | |
c5aa993b JM |
621 | /* Number of baseclasses. */ |
622 | int nbaseclasses; | |
c906108c | 623 | |
c5aa993b JM |
624 | /* Set if the accesibility of one of the fields is not public. */ |
625 | int non_public_fields; | |
c906108c | 626 | |
c5aa993b JM |
627 | /* Member function fields array, entries are allocated in the order they |
628 | are encountered in the object file. */ | |
629 | struct nextfnfield | |
630 | { | |
631 | struct nextfnfield *next; | |
632 | struct fn_field fnfield; | |
633 | } | |
634 | *fnfields; | |
c906108c | 635 | |
c5aa993b JM |
636 | /* Member function fieldlist array, contains name of possibly overloaded |
637 | member function, number of overloaded member functions and a pointer | |
638 | to the head of the member function field chain. */ | |
639 | struct fnfieldlist | |
640 | { | |
641 | char *name; | |
642 | int length; | |
643 | struct nextfnfield *head; | |
644 | } | |
645 | *fnfieldlists; | |
c906108c | 646 | |
c5aa993b JM |
647 | /* Number of entries in the fnfieldlists array. */ |
648 | int nfnfields; | |
649 | }; | |
c906108c | 650 | |
10b3939b DJ |
651 | /* One item on the queue of compilation units to read in full symbols |
652 | for. */ | |
653 | struct dwarf2_queue_item | |
654 | { | |
655 | struct dwarf2_per_cu_data *per_cu; | |
656 | struct dwarf2_queue_item *next; | |
657 | }; | |
658 | ||
659 | /* The current queue. */ | |
660 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |
661 | ||
ae038cb0 DJ |
662 | /* Loaded secondary compilation units are kept in memory until they |
663 | have not been referenced for the processing of this many | |
664 | compilation units. Set this to zero to disable caching. Cache | |
665 | sizes of up to at least twenty will improve startup time for | |
666 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |
667 | static int dwarf2_max_cache_age = 5; | |
920d2a44 AC |
668 | static void |
669 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, | |
670 | struct cmd_list_element *c, const char *value) | |
671 | { | |
672 | fprintf_filtered (file, _("\ | |
673 | The upper bound on the age of cached dwarf2 compilation units is %s.\n"), | |
674 | value); | |
675 | } | |
676 | ||
ae038cb0 | 677 | |
c906108c SS |
678 | /* Various complaints about symbol reading that don't abort the process */ |
679 | ||
4d3c2250 KB |
680 | static void |
681 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 682 | { |
4d3c2250 | 683 | complaint (&symfile_complaints, |
e2e0b3e5 | 684 | _("statement list doesn't fit in .debug_line section")); |
4d3c2250 KB |
685 | } |
686 | ||
687 | static void | |
688 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 689 | { |
e2e0b3e5 | 690 | complaint (&symfile_complaints, _("location expression too complex")); |
4d3c2250 KB |
691 | } |
692 | ||
4d3c2250 KB |
693 | static void |
694 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
695 | int arg3) | |
2e276125 | 696 | { |
4d3c2250 | 697 | complaint (&symfile_complaints, |
e2e0b3e5 | 698 | _("const value length mismatch for '%s', got %d, expected %d"), arg1, |
4d3c2250 KB |
699 | arg2, arg3); |
700 | } | |
701 | ||
702 | static void | |
703 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 704 | { |
4d3c2250 | 705 | complaint (&symfile_complaints, |
e2e0b3e5 | 706 | _("macro info runs off end of `.debug_macinfo' section")); |
4d3c2250 KB |
707 | } |
708 | ||
709 | static void | |
710 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 711 | { |
4d3c2250 | 712 | complaint (&symfile_complaints, |
e2e0b3e5 | 713 | _("macro debug info contains a malformed macro definition:\n`%s'"), |
4d3c2250 KB |
714 | arg1); |
715 | } | |
716 | ||
717 | static void | |
718 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 719 | { |
4d3c2250 | 720 | complaint (&symfile_complaints, |
e2e0b3e5 | 721 | _("invalid attribute class or form for '%s' in '%s'"), arg1, arg2); |
4d3c2250 | 722 | } |
c906108c | 723 | |
c906108c SS |
724 | /* local function prototypes */ |
725 | ||
4efb68b1 | 726 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
727 | |
728 | #if 0 | |
a14ed312 | 729 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
730 | #endif |
731 | ||
aaa75496 JB |
732 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
733 | struct objfile *); | |
734 | ||
735 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
736 | struct partial_die_info *, | |
737 | struct partial_symtab *); | |
738 | ||
a14ed312 | 739 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 740 | |
72bf9492 DJ |
741 | static void scan_partial_symbols (struct partial_die_info *, |
742 | CORE_ADDR *, CORE_ADDR *, | |
743 | struct dwarf2_cu *); | |
c906108c | 744 | |
72bf9492 DJ |
745 | static void add_partial_symbol (struct partial_die_info *, |
746 | struct dwarf2_cu *); | |
63d06c5c | 747 | |
72bf9492 | 748 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 749 | |
72bf9492 DJ |
750 | static void add_partial_namespace (struct partial_die_info *pdi, |
751 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
752 | struct dwarf2_cu *cu); | |
63d06c5c | 753 | |
72bf9492 DJ |
754 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
755 | struct dwarf2_cu *cu); | |
91c24f0a | 756 | |
fe1b8b76 JB |
757 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
758 | gdb_byte *info_ptr, | |
759 | bfd *abfd, | |
760 | struct dwarf2_cu *cu); | |
91c24f0a | 761 | |
a14ed312 | 762 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 763 | |
a14ed312 | 764 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 765 | |
fe1b8b76 | 766 | gdb_byte *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 767 | |
e7c27a73 | 768 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 769 | |
f3dd6933 | 770 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 771 | |
fe1b8b76 | 772 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
891d2f0b | 773 | struct dwarf2_cu *); |
72bf9492 | 774 | |
57349743 | 775 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 776 | struct dwarf2_cu *); |
c906108c | 777 | |
fe1b8b76 | 778 | static struct partial_die_info *load_partial_dies (bfd *, gdb_byte *, int, |
72bf9492 DJ |
779 | struct dwarf2_cu *); |
780 | ||
fe1b8b76 JB |
781 | static gdb_byte *read_partial_die (struct partial_die_info *, |
782 | struct abbrev_info *abbrev, unsigned int, | |
783 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 784 | |
72bf9492 | 785 | static struct partial_die_info *find_partial_die (unsigned long, |
10b3939b | 786 | struct dwarf2_cu *); |
72bf9492 DJ |
787 | |
788 | static void fixup_partial_die (struct partial_die_info *, | |
789 | struct dwarf2_cu *); | |
790 | ||
fe1b8b76 JB |
791 | static gdb_byte *read_full_die (struct die_info **, bfd *, gdb_byte *, |
792 | struct dwarf2_cu *, int *); | |
c906108c | 793 | |
fe1b8b76 JB |
794 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
795 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
c906108c | 796 | |
fe1b8b76 JB |
797 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
798 | bfd *, gdb_byte *, struct dwarf2_cu *); | |
a8329558 | 799 | |
fe1b8b76 | 800 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
c906108c | 801 | |
fe1b8b76 | 802 | static int read_1_signed_byte (bfd *, gdb_byte *); |
c906108c | 803 | |
fe1b8b76 | 804 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
c906108c | 805 | |
fe1b8b76 | 806 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
c906108c | 807 | |
fe1b8b76 | 808 | static unsigned long read_8_bytes (bfd *, gdb_byte *); |
c906108c | 809 | |
fe1b8b76 | 810 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
891d2f0b | 811 | unsigned int *); |
c906108c | 812 | |
fe1b8b76 | 813 | static LONGEST read_initial_length (bfd *, gdb_byte *, |
891d2f0b | 814 | struct comp_unit_head *, unsigned int *); |
613e1657 | 815 | |
fe1b8b76 | 816 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
891d2f0b | 817 | unsigned int *); |
613e1657 | 818 | |
fe1b8b76 | 819 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
c906108c | 820 | |
fe1b8b76 | 821 | static char *read_string (bfd *, gdb_byte *, unsigned int *); |
c906108c | 822 | |
fe1b8b76 JB |
823 | static char *read_indirect_string (bfd *, gdb_byte *, |
824 | const struct comp_unit_head *, | |
825 | unsigned int *); | |
4bdf3d34 | 826 | |
fe1b8b76 | 827 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 828 | |
fe1b8b76 | 829 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
c906108c | 830 | |
fe1b8b76 | 831 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
4bb7a0a7 | 832 | |
e142c38c | 833 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 834 | |
e142c38c DJ |
835 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
836 | struct dwarf2_cu *); | |
c906108c | 837 | |
05cf31d1 JB |
838 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
839 | struct dwarf2_cu *cu); | |
840 | ||
e142c38c | 841 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 842 | |
e142c38c DJ |
843 | static struct die_info *die_specification (struct die_info *die, |
844 | struct dwarf2_cu *); | |
63d06c5c | 845 | |
debd256d JB |
846 | static void free_line_header (struct line_header *lh); |
847 | ||
aaa75496 JB |
848 | static void add_file_name (struct line_header *, char *, unsigned int, |
849 | unsigned int, unsigned int); | |
850 | ||
debd256d JB |
851 | static struct line_header *(dwarf_decode_line_header |
852 | (unsigned int offset, | |
e7c27a73 | 853 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
854 | |
855 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 856 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 857 | |
4f1520fb | 858 | static void dwarf2_start_subfile (char *, char *, char *); |
c906108c | 859 | |
a14ed312 | 860 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 861 | struct dwarf2_cu *); |
c906108c | 862 | |
a14ed312 | 863 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 864 | struct dwarf2_cu *); |
c906108c | 865 | |
2df3850c JM |
866 | static void dwarf2_const_value_data (struct attribute *attr, |
867 | struct symbol *sym, | |
868 | int bits); | |
869 | ||
e7c27a73 | 870 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 871 | |
e7c27a73 DJ |
872 | static struct type *die_containing_type (struct die_info *, |
873 | struct dwarf2_cu *); | |
c906108c | 874 | |
e7c27a73 | 875 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 876 | |
e7c27a73 | 877 | static void read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 878 | |
086ed43d | 879 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c | 880 | |
fe1b8b76 JB |
881 | static char *typename_concat (struct obstack *, |
882 | const char *prefix, | |
883 | const char *suffix, | |
987504bb | 884 | struct dwarf2_cu *); |
63d06c5c | 885 | |
e7c27a73 | 886 | static void read_typedef (struct die_info *, struct dwarf2_cu *); |
c906108c | 887 | |
e7c27a73 | 888 | static void read_base_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 889 | |
a02abb62 JB |
890 | static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); |
891 | ||
e7c27a73 | 892 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 893 | |
e7c27a73 | 894 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 895 | |
e7c27a73 | 896 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 897 | |
a14ed312 | 898 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 899 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 900 | |
fae299cd DC |
901 | static void get_scope_pc_bounds (struct die_info *, |
902 | CORE_ADDR *, CORE_ADDR *, | |
903 | struct dwarf2_cu *); | |
904 | ||
a14ed312 | 905 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 906 | struct dwarf2_cu *); |
c906108c | 907 | |
a14ed312 | 908 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 909 | struct type *, struct dwarf2_cu *); |
c906108c | 910 | |
a14ed312 | 911 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 912 | struct die_info *, struct type *, |
e7c27a73 | 913 | struct dwarf2_cu *); |
c906108c | 914 | |
a14ed312 | 915 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 916 | struct type *, struct dwarf2_cu *); |
c906108c | 917 | |
134d01f1 DJ |
918 | static void read_structure_type (struct die_info *, struct dwarf2_cu *); |
919 | ||
920 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 921 | |
8176b9b8 DC |
922 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); |
923 | ||
e7c27a73 | 924 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 925 | |
e7c27a73 | 926 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 927 | |
38d518c9 | 928 | static const char *namespace_name (struct die_info *die, |
e142c38c | 929 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 930 | |
134d01f1 DJ |
931 | static void read_enumeration_type (struct die_info *, struct dwarf2_cu *); |
932 | ||
933 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 934 | |
e7c27a73 | 935 | static struct type *dwarf_base_type (int, int, struct dwarf2_cu *); |
c906108c | 936 | |
e7c27a73 | 937 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 938 | |
e7c27a73 | 939 | static void read_array_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 940 | |
7ca2d3a3 DL |
941 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
942 | struct dwarf2_cu *); | |
943 | ||
e7c27a73 | 944 | static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 945 | |
e7c27a73 DJ |
946 | static void read_tag_ptr_to_member_type (struct die_info *, |
947 | struct dwarf2_cu *); | |
c906108c | 948 | |
e7c27a73 | 949 | static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 950 | |
e7c27a73 | 951 | static void read_tag_const_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 952 | |
e7c27a73 | 953 | static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 954 | |
e7c27a73 | 955 | static void read_tag_string_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 956 | |
e7c27a73 | 957 | static void read_subroutine_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 958 | |
fe1b8b76 | 959 | static struct die_info *read_comp_unit (gdb_byte *, bfd *, struct dwarf2_cu *); |
c906108c | 960 | |
fe1b8b76 | 961 | static struct die_info *read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 962 | struct dwarf2_cu *, |
fe1b8b76 | 963 | gdb_byte **new_info_ptr, |
639d11d3 DC |
964 | struct die_info *parent); |
965 | ||
fe1b8b76 | 966 | static struct die_info *read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 967 | struct dwarf2_cu *, |
fe1b8b76 | 968 | gdb_byte **new_info_ptr, |
639d11d3 DC |
969 | struct die_info *parent); |
970 | ||
a14ed312 | 971 | static void free_die_list (struct die_info *); |
c906108c | 972 | |
e7c27a73 | 973 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 974 | |
e142c38c | 975 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 976 | |
e142c38c | 977 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 978 | |
e142c38c DJ |
979 | static struct die_info *dwarf2_extension (struct die_info *die, |
980 | struct dwarf2_cu *); | |
9219021c | 981 | |
a14ed312 | 982 | static char *dwarf_tag_name (unsigned int); |
c906108c | 983 | |
a14ed312 | 984 | static char *dwarf_attr_name (unsigned int); |
c906108c | 985 | |
a14ed312 | 986 | static char *dwarf_form_name (unsigned int); |
c906108c | 987 | |
a14ed312 | 988 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 989 | |
a14ed312 | 990 | static char *dwarf_bool_name (unsigned int); |
c906108c | 991 | |
a14ed312 | 992 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
993 | |
994 | #if 0 | |
a14ed312 | 995 | static char *dwarf_cfi_name (unsigned int); |
c906108c | 996 | |
a14ed312 | 997 | struct die_info *copy_die (struct die_info *); |
c906108c SS |
998 | #endif |
999 | ||
f9aca02d | 1000 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 1001 | |
f9aca02d | 1002 | static void dump_die (struct die_info *); |
c906108c | 1003 | |
f9aca02d | 1004 | static void dump_die_list (struct die_info *); |
c906108c | 1005 | |
10b3939b DJ |
1006 | static void store_in_ref_table (unsigned int, struct die_info *, |
1007 | struct dwarf2_cu *); | |
c906108c | 1008 | |
e142c38c DJ |
1009 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, |
1010 | struct dwarf2_cu *); | |
c906108c | 1011 | |
a02abb62 JB |
1012 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
1013 | ||
10b3939b DJ |
1014 | static struct die_info *follow_die_ref (struct die_info *, |
1015 | struct attribute *, | |
1016 | struct dwarf2_cu *); | |
c906108c | 1017 | |
e142c38c DJ |
1018 | static struct type *dwarf2_fundamental_type (struct objfile *, int, |
1019 | struct dwarf2_cu *); | |
c906108c SS |
1020 | |
1021 | /* memory allocation interface */ | |
1022 | ||
7b5a2f43 | 1023 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 1024 | |
f3dd6933 | 1025 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 1026 | |
a14ed312 | 1027 | static struct die_info *dwarf_alloc_die (void); |
c906108c | 1028 | |
e142c38c | 1029 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 1030 | |
e142c38c DJ |
1031 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
1032 | struct dwarf2_cu *); | |
5fb290d7 | 1033 | |
2e276125 | 1034 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 1035 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 1036 | |
8e19ed76 PS |
1037 | static int attr_form_is_block (struct attribute *); |
1038 | ||
4c2df51b DJ |
1039 | static void |
1040 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 1041 | struct dwarf2_cu *cu); |
4c2df51b | 1042 | |
fe1b8b76 JB |
1043 | static gdb_byte *skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, |
1044 | struct dwarf2_cu *cu); | |
4bb7a0a7 | 1045 | |
72bf9492 DJ |
1046 | static void free_stack_comp_unit (void *); |
1047 | ||
72bf9492 DJ |
1048 | static hashval_t partial_die_hash (const void *item); |
1049 | ||
1050 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
1051 | ||
ae038cb0 DJ |
1052 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
1053 | (unsigned long offset, struct objfile *objfile); | |
1054 | ||
1055 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |
1056 | (unsigned long offset, struct objfile *objfile); | |
1057 | ||
1058 | static void free_one_comp_unit (void *); | |
1059 | ||
1060 | static void free_cached_comp_units (void *); | |
1061 | ||
1062 | static void age_cached_comp_units (void); | |
1063 | ||
1064 | static void free_one_cached_comp_unit (void *); | |
1065 | ||
1c379e20 DJ |
1066 | static void set_die_type (struct die_info *, struct type *, |
1067 | struct dwarf2_cu *); | |
1068 | ||
1c379e20 DJ |
1069 | static void reset_die_and_siblings_types (struct die_info *, |
1070 | struct dwarf2_cu *); | |
1c379e20 | 1071 | |
ae038cb0 DJ |
1072 | static void create_all_comp_units (struct objfile *); |
1073 | ||
31ffec48 DJ |
1074 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *, |
1075 | struct objfile *); | |
10b3939b DJ |
1076 | |
1077 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |
1078 | ||
1079 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |
1080 | struct dwarf2_per_cu_data *); | |
1081 | ||
ae038cb0 DJ |
1082 | static void dwarf2_mark (struct dwarf2_cu *); |
1083 | ||
1084 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |
1085 | ||
72019c9c GM |
1086 | static void read_set_type (struct die_info *, struct dwarf2_cu *); |
1087 | ||
1088 | ||
c906108c SS |
1089 | /* Try to locate the sections we need for DWARF 2 debugging |
1090 | information and return true if we have enough to do something. */ | |
1091 | ||
1092 | int | |
6502dd73 | 1093 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 1094 | { |
6502dd73 DJ |
1095 | struct dwarf2_per_objfile *data; |
1096 | ||
1097 | /* Initialize per-objfile state. */ | |
1098 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
1099 | memset (data, 0, sizeof (*data)); | |
1100 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
1101 | dwarf2_per_objfile = data; | |
1102 | ||
188dd5d6 DJ |
1103 | dwarf_info_section = 0; |
1104 | dwarf_abbrev_section = 0; | |
1105 | dwarf_line_section = 0; | |
1106 | dwarf_str_section = 0; | |
1107 | dwarf_macinfo_section = 0; | |
1108 | dwarf_frame_section = 0; | |
1109 | dwarf_eh_frame_section = 0; | |
1110 | dwarf_ranges_section = 0; | |
1111 | dwarf_loc_section = 0; | |
af34e669 | 1112 | |
6502dd73 | 1113 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 1114 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
1115 | } |
1116 | ||
1117 | /* This function is mapped across the sections and remembers the | |
1118 | offset and size of each of the debugging sections we are interested | |
1119 | in. */ | |
1120 | ||
1121 | static void | |
72dca2f5 | 1122 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
c906108c | 1123 | { |
6314a349 | 1124 | if (strcmp (sectp->name, INFO_SECTION) == 0) |
c906108c | 1125 | { |
2c500098 | 1126 | dwarf2_per_objfile->info_size = bfd_get_section_size (sectp); |
086df311 | 1127 | dwarf_info_section = sectp; |
c906108c | 1128 | } |
6314a349 | 1129 | else if (strcmp (sectp->name, ABBREV_SECTION) == 0) |
c906108c | 1130 | { |
2c500098 | 1131 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp); |
086df311 | 1132 | dwarf_abbrev_section = sectp; |
c906108c | 1133 | } |
6314a349 | 1134 | else if (strcmp (sectp->name, LINE_SECTION) == 0) |
c906108c | 1135 | { |
2c500098 | 1136 | dwarf2_per_objfile->line_size = bfd_get_section_size (sectp); |
086df311 | 1137 | dwarf_line_section = sectp; |
c906108c | 1138 | } |
6314a349 | 1139 | else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0) |
c906108c | 1140 | { |
2c500098 | 1141 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp); |
086df311 | 1142 | dwarf_pubnames_section = sectp; |
c906108c | 1143 | } |
6314a349 | 1144 | else if (strcmp (sectp->name, ARANGES_SECTION) == 0) |
c906108c | 1145 | { |
2c500098 | 1146 | dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp); |
086df311 | 1147 | dwarf_aranges_section = sectp; |
c906108c | 1148 | } |
6314a349 | 1149 | else if (strcmp (sectp->name, LOC_SECTION) == 0) |
c906108c | 1150 | { |
2c500098 | 1151 | dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp); |
086df311 | 1152 | dwarf_loc_section = sectp; |
c906108c | 1153 | } |
6314a349 | 1154 | else if (strcmp (sectp->name, MACINFO_SECTION) == 0) |
c906108c | 1155 | { |
2c500098 | 1156 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp); |
0cf824c9 | 1157 | dwarf_macinfo_section = sectp; |
c906108c | 1158 | } |
6314a349 | 1159 | else if (strcmp (sectp->name, STR_SECTION) == 0) |
c906108c | 1160 | { |
2c500098 | 1161 | dwarf2_per_objfile->str_size = bfd_get_section_size (sectp); |
086df311 | 1162 | dwarf_str_section = sectp; |
c906108c | 1163 | } |
6314a349 | 1164 | else if (strcmp (sectp->name, FRAME_SECTION) == 0) |
b6af0555 | 1165 | { |
2c500098 | 1166 | dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp); |
086df311 | 1167 | dwarf_frame_section = sectp; |
b6af0555 | 1168 | } |
6314a349 | 1169 | else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0) |
b6af0555 | 1170 | { |
3799ccc6 EZ |
1171 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1172 | if (aflag & SEC_HAS_CONTENTS) | |
1173 | { | |
2c500098 | 1174 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp); |
3799ccc6 EZ |
1175 | dwarf_eh_frame_section = sectp; |
1176 | } | |
b6af0555 | 1177 | } |
6314a349 | 1178 | else if (strcmp (sectp->name, RANGES_SECTION) == 0) |
af34e669 | 1179 | { |
2c500098 | 1180 | dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp); |
6f10aeb1 | 1181 | dwarf_ranges_section = sectp; |
af34e669 | 1182 | } |
72dca2f5 FR |
1183 | |
1184 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) | |
1185 | && bfd_section_vma (abfd, sectp) == 0) | |
1186 | dwarf2_per_objfile->has_section_at_zero = 1; | |
c906108c SS |
1187 | } |
1188 | ||
1189 | /* Build a partial symbol table. */ | |
1190 | ||
1191 | void | |
fba45db2 | 1192 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1193 | { |
c906108c SS |
1194 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1195 | ||
6502dd73 DJ |
1196 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1197 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1198 | |
1199 | if (dwarf_line_section) | |
6502dd73 | 1200 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1201 | else |
6502dd73 | 1202 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1203 | |
188dd5d6 | 1204 | if (dwarf_str_section) |
6502dd73 | 1205 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1206 | else |
6502dd73 | 1207 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1208 | |
188dd5d6 | 1209 | if (dwarf_macinfo_section) |
6502dd73 | 1210 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1211 | dwarf_macinfo_section); |
2e276125 | 1212 | else |
6502dd73 | 1213 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1214 | |
188dd5d6 | 1215 | if (dwarf_ranges_section) |
6502dd73 | 1216 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1217 | else |
6502dd73 | 1218 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1219 | |
188dd5d6 | 1220 | if (dwarf_loc_section) |
6502dd73 | 1221 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1222 | else |
6502dd73 | 1223 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1224 | |
ef96bde8 EZ |
1225 | if (mainline |
1226 | || (objfile->global_psymbols.size == 0 | |
1227 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1228 | { |
1229 | init_psymbol_list (objfile, 1024); | |
1230 | } | |
1231 | ||
1232 | #if 0 | |
1233 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1234 | { | |
d4f3574e | 1235 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1236 | .debug_pubnames sections */ |
1237 | ||
d4f3574e | 1238 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1239 | } |
1240 | else | |
1241 | #endif | |
1242 | /* only test this case for now */ | |
c5aa993b | 1243 | { |
c906108c | 1244 | /* In this case we have to work a bit harder */ |
d4f3574e | 1245 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1246 | } |
1247 | } | |
1248 | ||
1249 | #if 0 | |
1250 | /* Build the partial symbol table from the information in the | |
1251 | .debug_pubnames and .debug_aranges sections. */ | |
1252 | ||
1253 | static void | |
fba45db2 | 1254 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1255 | { |
1256 | bfd *abfd = objfile->obfd; | |
1257 | char *aranges_buffer, *pubnames_buffer; | |
1258 | char *aranges_ptr, *pubnames_ptr; | |
1259 | unsigned int entry_length, version, info_offset, info_size; | |
1260 | ||
1261 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1262 | dwarf_pubnames_section); |
c906108c | 1263 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1264 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1265 | { |
613e1657 | 1266 | struct comp_unit_head cu_header; |
891d2f0b | 1267 | unsigned int bytes_read; |
613e1657 KB |
1268 | |
1269 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |
891d2f0b | 1270 | &bytes_read); |
613e1657 | 1271 | pubnames_ptr += bytes_read; |
c906108c SS |
1272 | version = read_1_byte (abfd, pubnames_ptr); |
1273 | pubnames_ptr += 1; | |
1274 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1275 | pubnames_ptr += 4; | |
1276 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1277 | pubnames_ptr += 4; | |
1278 | } | |
1279 | ||
1280 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1281 | dwarf_aranges_section); |
c906108c SS |
1282 | |
1283 | } | |
1284 | #endif | |
1285 | ||
107d2387 | 1286 | /* Read in the comp unit header information from the debug_info at |
917c78fc | 1287 | info_ptr. */ |
107d2387 | 1288 | |
fe1b8b76 | 1289 | static gdb_byte * |
107d2387 | 1290 | read_comp_unit_head (struct comp_unit_head *cu_header, |
fe1b8b76 | 1291 | gdb_byte *info_ptr, bfd *abfd) |
107d2387 AC |
1292 | { |
1293 | int signed_addr; | |
891d2f0b | 1294 | unsigned int bytes_read; |
613e1657 KB |
1295 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, |
1296 | &bytes_read); | |
1297 | info_ptr += bytes_read; | |
107d2387 AC |
1298 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1299 | info_ptr += 2; | |
613e1657 KB |
1300 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
1301 | &bytes_read); | |
1302 | info_ptr += bytes_read; | |
107d2387 AC |
1303 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1304 | info_ptr += 1; | |
1305 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1306 | if (signed_addr < 0) | |
8e65ff28 | 1307 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 1308 | _("read_comp_unit_head: dwarf from non elf file")); |
107d2387 AC |
1309 | cu_header->signed_addr_p = signed_addr; |
1310 | return info_ptr; | |
1311 | } | |
1312 | ||
fe1b8b76 JB |
1313 | static gdb_byte * |
1314 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, | |
72bf9492 DJ |
1315 | bfd *abfd) |
1316 | { | |
fe1b8b76 | 1317 | gdb_byte *beg_of_comp_unit = info_ptr; |
72bf9492 DJ |
1318 | |
1319 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1320 | ||
2b949cb6 | 1321 | if (header->version != 2 && header->version != 3) |
8a3fe4f8 AC |
1322 | error (_("Dwarf Error: wrong version in compilation unit header " |
1323 | "(is %d, should be %d) [in module %s]"), header->version, | |
72bf9492 DJ |
1324 | 2, bfd_get_filename (abfd)); |
1325 | ||
1326 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
8a3fe4f8 AC |
1327 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
1328 | "(offset 0x%lx + 6) [in module %s]"), | |
72bf9492 DJ |
1329 | (long) header->abbrev_offset, |
1330 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1331 | bfd_get_filename (abfd)); | |
1332 | ||
1333 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1334 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
8a3fe4f8 AC |
1335 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
1336 | "(offset 0x%lx + 0) [in module %s]"), | |
72bf9492 DJ |
1337 | (long) header->length, |
1338 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1339 | bfd_get_filename (abfd)); | |
1340 | ||
1341 | return info_ptr; | |
1342 | } | |
1343 | ||
aaa75496 JB |
1344 | /* Allocate a new partial symtab for file named NAME and mark this new |
1345 | partial symtab as being an include of PST. */ | |
1346 | ||
1347 | static void | |
1348 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1349 | struct objfile *objfile) | |
1350 | { | |
1351 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1352 | ||
1353 | subpst->section_offsets = pst->section_offsets; | |
1354 | subpst->textlow = 0; | |
1355 | subpst->texthigh = 0; | |
1356 | ||
1357 | subpst->dependencies = (struct partial_symtab **) | |
1358 | obstack_alloc (&objfile->objfile_obstack, | |
1359 | sizeof (struct partial_symtab *)); | |
1360 | subpst->dependencies[0] = pst; | |
1361 | subpst->number_of_dependencies = 1; | |
1362 | ||
1363 | subpst->globals_offset = 0; | |
1364 | subpst->n_global_syms = 0; | |
1365 | subpst->statics_offset = 0; | |
1366 | subpst->n_static_syms = 0; | |
1367 | subpst->symtab = NULL; | |
1368 | subpst->read_symtab = pst->read_symtab; | |
1369 | subpst->readin = 0; | |
1370 | ||
1371 | /* No private part is necessary for include psymtabs. This property | |
1372 | can be used to differentiate between such include psymtabs and | |
10b3939b | 1373 | the regular ones. */ |
58a9656e | 1374 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1375 | } |
1376 | ||
1377 | /* Read the Line Number Program data and extract the list of files | |
1378 | included by the source file represented by PST. Build an include | |
1379 | partial symtab for each of these included files. | |
1380 | ||
1381 | This procedure assumes that there *is* a Line Number Program in | |
1382 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1383 | before calling this procedure. */ | |
1384 | ||
1385 | static void | |
1386 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1387 | struct partial_die_info *pdi, | |
1388 | struct partial_symtab *pst) | |
1389 | { | |
1390 | struct objfile *objfile = cu->objfile; | |
1391 | bfd *abfd = objfile->obfd; | |
1392 | struct line_header *lh; | |
1393 | ||
1394 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1395 | if (lh == NULL) | |
1396 | return; /* No linetable, so no includes. */ | |
1397 | ||
1398 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1399 | ||
1400 | free_line_header (lh); | |
1401 | } | |
1402 | ||
1403 | ||
c906108c SS |
1404 | /* Build the partial symbol table by doing a quick pass through the |
1405 | .debug_info and .debug_abbrev sections. */ | |
1406 | ||
1407 | static void | |
fba45db2 | 1408 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1409 | { |
1410 | /* Instead of reading this into a big buffer, we should probably use | |
1411 | mmap() on architectures that support it. (FIXME) */ | |
1412 | bfd *abfd = objfile->obfd; | |
fe1b8b76 JB |
1413 | gdb_byte *info_ptr; |
1414 | gdb_byte *beg_of_comp_unit; | |
c906108c SS |
1415 | struct partial_die_info comp_unit_die; |
1416 | struct partial_symtab *pst; | |
ae038cb0 | 1417 | struct cleanup *back_to; |
e142c38c | 1418 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1419 | |
6502dd73 | 1420 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1421 | |
ae038cb0 DJ |
1422 | /* Any cached compilation units will be linked by the per-objfile |
1423 | read_in_chain. Make sure to free them when we're done. */ | |
1424 | back_to = make_cleanup (free_cached_comp_units, NULL); | |
1425 | ||
10b3939b DJ |
1426 | create_all_comp_units (objfile); |
1427 | ||
6502dd73 | 1428 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1429 | length, only the individual functions to extract them (like |
72bf9492 | 1430 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1431 | the buffer is large enough to hold another complete object. |
1432 | ||
6502dd73 DJ |
1433 | At the moment, they don't actually check that. If .debug_info |
1434 | holds just one extra byte after the last compilation unit's dies, | |
1435 | then read_comp_unit_head will happily read off the end of the | |
1436 | buffer. read_partial_die is similarly casual. Those functions | |
1437 | should be fixed. | |
af703f96 JB |
1438 | |
1439 | For this loop condition, simply checking whether there's any data | |
1440 | left at all should be sufficient. */ | |
6502dd73 DJ |
1441 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1442 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1443 | { |
f3dd6933 | 1444 | struct cleanup *back_to_inner; |
e7c27a73 | 1445 | struct dwarf2_cu cu; |
72bf9492 DJ |
1446 | struct abbrev_info *abbrev; |
1447 | unsigned int bytes_read; | |
1448 | struct dwarf2_per_cu_data *this_cu; | |
1449 | ||
c906108c | 1450 | beg_of_comp_unit = info_ptr; |
c906108c | 1451 | |
72bf9492 DJ |
1452 | memset (&cu, 0, sizeof (cu)); |
1453 | ||
1454 | obstack_init (&cu.comp_unit_obstack); | |
1455 | ||
1456 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1457 | ||
e7c27a73 | 1458 | cu.objfile = objfile; |
72bf9492 | 1459 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1460 | |
57349743 | 1461 | /* Complete the cu_header */ |
6502dd73 | 1462 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
e7c27a73 DJ |
1463 | cu.header.first_die_ptr = info_ptr; |
1464 | cu.header.cu_head_ptr = beg_of_comp_unit; | |
57349743 | 1465 | |
e142c38c DJ |
1466 | cu.list_in_scope = &file_symbols; |
1467 | ||
c906108c | 1468 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1469 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1470 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 1471 | |
10b3939b | 1472 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); |
ae038cb0 | 1473 | |
c906108c | 1474 | /* Read the compilation unit die */ |
72bf9492 DJ |
1475 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1476 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1477 | abfd, info_ptr, &cu); | |
c906108c | 1478 | |
31ffec48 DJ |
1479 | if (comp_unit_die.tag == DW_TAG_partial_unit) |
1480 | { | |
1481 | info_ptr = (beg_of_comp_unit + cu.header.length | |
1482 | + cu.header.initial_length_size); | |
1483 | do_cleanups (back_to_inner); | |
1484 | continue; | |
1485 | } | |
1486 | ||
c906108c | 1487 | /* Set the language we're debugging */ |
e142c38c | 1488 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1489 | |
1490 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1491 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1492 | comp_unit_die.name ? comp_unit_die.name : "", |
c906108c SS |
1493 | comp_unit_die.lowpc, |
1494 | objfile->global_psymbols.next, | |
1495 | objfile->static_psymbols.next); | |
1496 | ||
ae038cb0 DJ |
1497 | if (comp_unit_die.dirname) |
1498 | pst->dirname = xstrdup (comp_unit_die.dirname); | |
57c22c6c | 1499 | |
10b3939b DJ |
1500 | pst->read_symtab_private = (char *) this_cu; |
1501 | ||
613e1657 | 1502 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1503 | |
1504 | /* Store the function that reads in the rest of the symbol table */ | |
1505 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1506 | ||
10b3939b DJ |
1507 | /* If this compilation unit was already read in, free the |
1508 | cached copy in order to read it in again. This is | |
1509 | necessary because we skipped some symbols when we first | |
1510 | read in the compilation unit (see load_partial_dies). | |
1511 | This problem could be avoided, but the benefit is | |
1512 | unclear. */ | |
1513 | if (this_cu->cu != NULL) | |
1514 | free_one_cached_comp_unit (this_cu->cu); | |
ae038cb0 | 1515 | |
10b3939b | 1516 | cu.per_cu = this_cu; |
ae038cb0 | 1517 | |
10b3939b DJ |
1518 | /* Note that this is a pointer to our stack frame, being |
1519 | added to a global data structure. It will be cleaned up | |
1520 | in free_stack_comp_unit when we finish with this | |
1521 | compilation unit. */ | |
1522 | this_cu->cu = &cu; | |
ae038cb0 | 1523 | |
10b3939b | 1524 | this_cu->psymtab = pst; |
ae038cb0 | 1525 | |
c906108c SS |
1526 | /* Check if comp unit has_children. |
1527 | If so, read the rest of the partial symbols from this comp unit. | |
1528 | If not, there's no more debug_info for this comp unit. */ | |
1529 | if (comp_unit_die.has_children) | |
1530 | { | |
72bf9492 DJ |
1531 | struct partial_die_info *first_die; |
1532 | ||
91c24f0a DC |
1533 | lowpc = ((CORE_ADDR) -1); |
1534 | highpc = ((CORE_ADDR) 0); | |
1535 | ||
72bf9492 DJ |
1536 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1537 | ||
1538 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1539 | |
91c24f0a DC |
1540 | /* If we didn't find a lowpc, set it to highpc to avoid |
1541 | complaints from `maint check'. */ | |
1542 | if (lowpc == ((CORE_ADDR) -1)) | |
1543 | lowpc = highpc; | |
72bf9492 | 1544 | |
c906108c SS |
1545 | /* If the compilation unit didn't have an explicit address range, |
1546 | then use the information extracted from its child dies. */ | |
0b010bcc | 1547 | if (! comp_unit_die.has_pc_info) |
c906108c | 1548 | { |
c5aa993b | 1549 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1550 | comp_unit_die.highpc = highpc; |
1551 | } | |
1552 | } | |
c5aa993b | 1553 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1554 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1555 | ||
1556 | pst->n_global_syms = objfile->global_psymbols.next - | |
1557 | (objfile->global_psymbols.list + pst->globals_offset); | |
1558 | pst->n_static_syms = objfile->static_psymbols.next - | |
1559 | (objfile->static_psymbols.list + pst->statics_offset); | |
1560 | sort_pst_symbols (pst); | |
1561 | ||
1562 | /* If there is already a psymtab or symtab for a file of this | |
1563 | name, remove it. (If there is a symtab, more drastic things | |
1564 | also happen.) This happens in VxWorks. */ | |
1565 | free_named_symtabs (pst->filename); | |
1566 | ||
dd373385 EZ |
1567 | info_ptr = beg_of_comp_unit + cu.header.length |
1568 | + cu.header.initial_length_size; | |
1569 | ||
aaa75496 JB |
1570 | if (comp_unit_die.has_stmt_list) |
1571 | { | |
1572 | /* Get the list of files included in the current compilation unit, | |
1573 | and build a psymtab for each of them. */ | |
1574 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1575 | } | |
1576 | ||
f3dd6933 | 1577 | do_cleanups (back_to_inner); |
c906108c | 1578 | } |
ae038cb0 DJ |
1579 | do_cleanups (back_to); |
1580 | } | |
1581 | ||
1582 | /* Load the DIEs for a secondary CU into memory. */ | |
1583 | ||
1584 | static void | |
1585 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |
1586 | { | |
1587 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 1588 | gdb_byte *info_ptr, *beg_of_comp_unit; |
ae038cb0 DJ |
1589 | struct partial_die_info comp_unit_die; |
1590 | struct dwarf2_cu *cu; | |
1591 | struct abbrev_info *abbrev; | |
1592 | unsigned int bytes_read; | |
1593 | struct cleanup *back_to; | |
1594 | ||
1595 | info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset; | |
1596 | beg_of_comp_unit = info_ptr; | |
1597 | ||
1598 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |
1599 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
1600 | ||
1601 | obstack_init (&cu->comp_unit_obstack); | |
1602 | ||
1603 | cu->objfile = objfile; | |
1604 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |
1605 | ||
1606 | /* Complete the cu_header. */ | |
1607 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |
1608 | cu->header.first_die_ptr = info_ptr; | |
1609 | cu->header.cu_head_ptr = beg_of_comp_unit; | |
1610 | ||
1611 | /* Read the abbrevs for this compilation unit into a table. */ | |
1612 | dwarf2_read_abbrevs (abfd, cu); | |
1613 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
1614 | ||
1615 | /* Read the compilation unit die. */ | |
1616 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1617 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1618 | abfd, info_ptr, cu); | |
1619 | ||
1620 | /* Set the language we're debugging. */ | |
1621 | set_cu_language (comp_unit_die.language, cu); | |
1622 | ||
1623 | /* Link this compilation unit into the compilation unit tree. */ | |
1624 | this_cu->cu = cu; | |
1625 | cu->per_cu = this_cu; | |
1626 | ||
1627 | /* Check if comp unit has_children. | |
1628 | If so, read the rest of the partial symbols from this comp unit. | |
1629 | If not, there's no more debug_info for this comp unit. */ | |
1630 | if (comp_unit_die.has_children) | |
1631 | load_partial_dies (abfd, info_ptr, 0, cu); | |
1632 | ||
1633 | do_cleanups (back_to); | |
1634 | } | |
1635 | ||
1636 | /* Create a list of all compilation units in OBJFILE. We do this only | |
1637 | if an inter-comp-unit reference is found; presumably if there is one, | |
1638 | there will be many, and one will occur early in the .debug_info section. | |
1639 | So there's no point in building this list incrementally. */ | |
1640 | ||
1641 | static void | |
1642 | create_all_comp_units (struct objfile *objfile) | |
1643 | { | |
1644 | int n_allocated; | |
1645 | int n_comp_units; | |
1646 | struct dwarf2_per_cu_data **all_comp_units; | |
fe1b8b76 | 1647 | gdb_byte *info_ptr = dwarf2_per_objfile->info_buffer; |
ae038cb0 DJ |
1648 | |
1649 | n_comp_units = 0; | |
1650 | n_allocated = 10; | |
1651 | all_comp_units = xmalloc (n_allocated | |
1652 | * sizeof (struct dwarf2_per_cu_data *)); | |
1653 | ||
1654 | while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1655 | { | |
1656 | struct comp_unit_head cu_header; | |
fe1b8b76 | 1657 | gdb_byte *beg_of_comp_unit; |
ae038cb0 DJ |
1658 | struct dwarf2_per_cu_data *this_cu; |
1659 | unsigned long offset; | |
891d2f0b | 1660 | unsigned int bytes_read; |
ae038cb0 DJ |
1661 | |
1662 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |
1663 | ||
1664 | /* Read just enough information to find out where the next | |
1665 | compilation unit is. */ | |
dd373385 | 1666 | cu_header.initial_length_size = 0; |
ae038cb0 DJ |
1667 | cu_header.length = read_initial_length (objfile->obfd, info_ptr, |
1668 | &cu_header, &bytes_read); | |
1669 | ||
1670 | /* Save the compilation unit for later lookup. */ | |
1671 | this_cu = obstack_alloc (&objfile->objfile_obstack, | |
1672 | sizeof (struct dwarf2_per_cu_data)); | |
1673 | memset (this_cu, 0, sizeof (*this_cu)); | |
1674 | this_cu->offset = offset; | |
1675 | this_cu->length = cu_header.length + cu_header.initial_length_size; | |
1676 | ||
1677 | if (n_comp_units == n_allocated) | |
1678 | { | |
1679 | n_allocated *= 2; | |
1680 | all_comp_units = xrealloc (all_comp_units, | |
1681 | n_allocated | |
1682 | * sizeof (struct dwarf2_per_cu_data *)); | |
1683 | } | |
1684 | all_comp_units[n_comp_units++] = this_cu; | |
1685 | ||
1686 | info_ptr = info_ptr + this_cu->length; | |
1687 | } | |
1688 | ||
1689 | dwarf2_per_objfile->all_comp_units | |
1690 | = obstack_alloc (&objfile->objfile_obstack, | |
1691 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1692 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |
1693 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |
1694 | xfree (all_comp_units); | |
1695 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |
c906108c SS |
1696 | } |
1697 | ||
72bf9492 DJ |
1698 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1699 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1700 | in CU. */ | |
c906108c | 1701 | |
72bf9492 DJ |
1702 | static void |
1703 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1704 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1705 | { |
e7c27a73 | 1706 | struct objfile *objfile = cu->objfile; |
c906108c | 1707 | bfd *abfd = objfile->obfd; |
72bf9492 | 1708 | struct partial_die_info *pdi; |
c906108c | 1709 | |
91c24f0a DC |
1710 | /* Now, march along the PDI's, descending into ones which have |
1711 | interesting children but skipping the children of the other ones, | |
1712 | until we reach the end of the compilation unit. */ | |
c906108c | 1713 | |
72bf9492 | 1714 | pdi = first_die; |
91c24f0a | 1715 | |
72bf9492 DJ |
1716 | while (pdi != NULL) |
1717 | { | |
1718 | fixup_partial_die (pdi, cu); | |
c906108c | 1719 | |
91c24f0a DC |
1720 | /* Anonymous namespaces have no name but have interesting |
1721 | children, so we need to look at them. Ditto for anonymous | |
1722 | enums. */ | |
933c6fe4 | 1723 | |
72bf9492 DJ |
1724 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1725 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1726 | { |
72bf9492 | 1727 | switch (pdi->tag) |
c906108c SS |
1728 | { |
1729 | case DW_TAG_subprogram: | |
72bf9492 | 1730 | if (pdi->has_pc_info) |
c906108c | 1731 | { |
72bf9492 | 1732 | if (pdi->lowpc < *lowpc) |
c906108c | 1733 | { |
72bf9492 | 1734 | *lowpc = pdi->lowpc; |
c906108c | 1735 | } |
72bf9492 | 1736 | if (pdi->highpc > *highpc) |
c906108c | 1737 | { |
72bf9492 | 1738 | *highpc = pdi->highpc; |
c906108c | 1739 | } |
72bf9492 | 1740 | if (!pdi->is_declaration) |
c906108c | 1741 | { |
72bf9492 | 1742 | add_partial_symbol (pdi, cu); |
c906108c SS |
1743 | } |
1744 | } | |
1745 | break; | |
1746 | case DW_TAG_variable: | |
1747 | case DW_TAG_typedef: | |
91c24f0a | 1748 | case DW_TAG_union_type: |
72bf9492 | 1749 | if (!pdi->is_declaration) |
63d06c5c | 1750 | { |
72bf9492 | 1751 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1752 | } |
1753 | break; | |
c906108c SS |
1754 | case DW_TAG_class_type: |
1755 | case DW_TAG_structure_type: | |
72bf9492 | 1756 | if (!pdi->is_declaration) |
c906108c | 1757 | { |
72bf9492 | 1758 | add_partial_symbol (pdi, cu); |
c906108c SS |
1759 | } |
1760 | break; | |
91c24f0a | 1761 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1762 | if (!pdi->is_declaration) |
1763 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1764 | break; |
1765 | case DW_TAG_base_type: | |
a02abb62 | 1766 | case DW_TAG_subrange_type: |
c906108c | 1767 | /* File scope base type definitions are added to the partial |
c5aa993b | 1768 | symbol table. */ |
72bf9492 | 1769 | add_partial_symbol (pdi, cu); |
c906108c | 1770 | break; |
d9fa45fe | 1771 | case DW_TAG_namespace: |
72bf9492 | 1772 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1773 | break; |
c906108c SS |
1774 | default: |
1775 | break; | |
1776 | } | |
1777 | } | |
1778 | ||
72bf9492 DJ |
1779 | /* If the die has a sibling, skip to the sibling. */ |
1780 | ||
1781 | pdi = pdi->die_sibling; | |
1782 | } | |
1783 | } | |
1784 | ||
1785 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1786 | |
72bf9492 | 1787 | Normally, this is simple. For C++, the parent DIE's fully scoped |
987504bb JJ |
1788 | name is concatenated with "::" and the partial DIE's name. For |
1789 | Java, the same thing occurs except that "." is used instead of "::". | |
72bf9492 DJ |
1790 | Enumerators are an exception; they use the scope of their parent |
1791 | enumeration type, i.e. the name of the enumeration type is not | |
1792 | prepended to the enumerator. | |
91c24f0a | 1793 | |
72bf9492 DJ |
1794 | There are two complexities. One is DW_AT_specification; in this |
1795 | case "parent" means the parent of the target of the specification, | |
1796 | instead of the direct parent of the DIE. The other is compilers | |
1797 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1798 | the fully qualified name of structure types from their members' | |
1799 | linkage names. This must be done using the DIE's children rather | |
1800 | than the children of any DW_AT_specification target. We only need | |
1801 | to do this for structures at the top level, i.e. if the target of | |
1802 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1803 | have a parent. */ | |
1804 | ||
1805 | /* Compute the scope prefix associated with PDI's parent, in | |
1806 | compilation unit CU. The result will be allocated on CU's | |
1807 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1808 | field. NULL is returned if no prefix is necessary. */ | |
1809 | static char * | |
1810 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1811 | struct dwarf2_cu *cu) | |
1812 | { | |
1813 | char *grandparent_scope; | |
1814 | struct partial_die_info *parent, *real_pdi; | |
91c24f0a | 1815 | |
72bf9492 DJ |
1816 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1817 | then this means the parent of the specification DIE. */ | |
1818 | ||
1819 | real_pdi = pdi; | |
72bf9492 | 1820 | while (real_pdi->has_specification) |
10b3939b | 1821 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
72bf9492 DJ |
1822 | |
1823 | parent = real_pdi->die_parent; | |
1824 | if (parent == NULL) | |
1825 | return NULL; | |
1826 | ||
1827 | if (parent->scope_set) | |
1828 | return parent->scope; | |
1829 | ||
1830 | fixup_partial_die (parent, cu); | |
1831 | ||
10b3939b | 1832 | grandparent_scope = partial_die_parent_scope (parent, cu); |
72bf9492 DJ |
1833 | |
1834 | if (parent->tag == DW_TAG_namespace | |
1835 | || parent->tag == DW_TAG_structure_type | |
1836 | || parent->tag == DW_TAG_class_type | |
1837 | || parent->tag == DW_TAG_union_type) | |
1838 | { | |
1839 | if (grandparent_scope == NULL) | |
1840 | parent->scope = parent->name; | |
1841 | else | |
987504bb JJ |
1842 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, |
1843 | parent->name, cu); | |
72bf9492 DJ |
1844 | } |
1845 | else if (parent->tag == DW_TAG_enumeration_type) | |
1846 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1847 | parent->scope = grandparent_scope; | |
1848 | else | |
1849 | { | |
1850 | /* FIXME drow/2004-04-01: What should we be doing with | |
1851 | function-local names? For partial symbols, we should probably be | |
1852 | ignoring them. */ | |
1853 | complaint (&symfile_complaints, | |
e2e0b3e5 | 1854 | _("unhandled containing DIE tag %d for DIE at %d"), |
72bf9492 DJ |
1855 | parent->tag, pdi->offset); |
1856 | parent->scope = grandparent_scope; | |
c906108c SS |
1857 | } |
1858 | ||
72bf9492 DJ |
1859 | parent->scope_set = 1; |
1860 | return parent->scope; | |
1861 | } | |
1862 | ||
1863 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1864 | CU. The result will be allocated with malloc. */ | |
1865 | static char * | |
1866 | partial_die_full_name (struct partial_die_info *pdi, | |
1867 | struct dwarf2_cu *cu) | |
1868 | { | |
1869 | char *parent_scope; | |
1870 | ||
1871 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1872 | if (parent_scope == NULL) | |
1873 | return NULL; | |
1874 | else | |
987504bb | 1875 | return typename_concat (NULL, parent_scope, pdi->name, cu); |
c906108c SS |
1876 | } |
1877 | ||
1878 | static void | |
72bf9492 | 1879 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1880 | { |
e7c27a73 | 1881 | struct objfile *objfile = cu->objfile; |
c906108c | 1882 | CORE_ADDR addr = 0; |
72bf9492 DJ |
1883 | char *actual_name; |
1884 | const char *my_prefix; | |
5c4e30ca | 1885 | const struct partial_symbol *psym = NULL; |
e142c38c | 1886 | CORE_ADDR baseaddr; |
72bf9492 | 1887 | int built_actual_name = 0; |
e142c38c DJ |
1888 | |
1889 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1890 | |
72bf9492 DJ |
1891 | actual_name = NULL; |
1892 | ||
1893 | if (pdi_needs_namespace (pdi->tag)) | |
63d06c5c | 1894 | { |
72bf9492 DJ |
1895 | actual_name = partial_die_full_name (pdi, cu); |
1896 | if (actual_name) | |
1897 | built_actual_name = 1; | |
63d06c5c DC |
1898 | } |
1899 | ||
72bf9492 DJ |
1900 | if (actual_name == NULL) |
1901 | actual_name = pdi->name; | |
1902 | ||
c906108c SS |
1903 | switch (pdi->tag) |
1904 | { | |
1905 | case DW_TAG_subprogram: | |
1906 | if (pdi->is_external) | |
1907 | { | |
38d518c9 | 1908 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1909 | mst_text, objfile); */ |
38d518c9 | 1910 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1911 | VAR_DOMAIN, LOC_BLOCK, |
1912 | &objfile->global_psymbols, | |
1913 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1914 | cu->language, objfile); |
c906108c SS |
1915 | } |
1916 | else | |
1917 | { | |
38d518c9 | 1918 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1919 | mst_file_text, objfile); */ |
38d518c9 | 1920 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1921 | VAR_DOMAIN, LOC_BLOCK, |
1922 | &objfile->static_psymbols, | |
1923 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1924 | cu->language, objfile); |
c906108c SS |
1925 | } |
1926 | break; | |
1927 | case DW_TAG_variable: | |
1928 | if (pdi->is_external) | |
1929 | { | |
1930 | /* Global Variable. | |
1931 | Don't enter into the minimal symbol tables as there is | |
1932 | a minimal symbol table entry from the ELF symbols already. | |
1933 | Enter into partial symbol table if it has a location | |
1934 | descriptor or a type. | |
1935 | If the location descriptor is missing, new_symbol will create | |
1936 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1937 | be determined from the minimal symbol table whenever the variable | |
1938 | is referenced. | |
1939 | The address for the partial symbol table entry is not | |
1940 | used by GDB, but it comes in handy for debugging partial symbol | |
1941 | table building. */ | |
1942 | ||
1943 | if (pdi->locdesc) | |
e7c27a73 | 1944 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 1945 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 1946 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1947 | VAR_DOMAIN, LOC_STATIC, |
1948 | &objfile->global_psymbols, | |
1949 | 0, addr + baseaddr, | |
e142c38c | 1950 | cu->language, objfile); |
c906108c SS |
1951 | } |
1952 | else | |
1953 | { | |
1954 | /* Static Variable. Skip symbols without location descriptors. */ | |
1955 | if (pdi->locdesc == NULL) | |
1956 | return; | |
e7c27a73 | 1957 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 1958 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 1959 | mst_file_data, objfile); */ |
38d518c9 | 1960 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1961 | VAR_DOMAIN, LOC_STATIC, |
1962 | &objfile->static_psymbols, | |
1963 | 0, addr + baseaddr, | |
e142c38c | 1964 | cu->language, objfile); |
c906108c SS |
1965 | } |
1966 | break; | |
1967 | case DW_TAG_typedef: | |
1968 | case DW_TAG_base_type: | |
a02abb62 | 1969 | case DW_TAG_subrange_type: |
38d518c9 | 1970 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1971 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 1972 | &objfile->static_psymbols, |
e142c38c | 1973 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 1974 | break; |
72bf9492 DJ |
1975 | case DW_TAG_namespace: |
1976 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
1977 | VAR_DOMAIN, LOC_TYPEDEF, | |
1978 | &objfile->global_psymbols, | |
1979 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
1980 | break; | |
c906108c SS |
1981 | case DW_TAG_class_type: |
1982 | case DW_TAG_structure_type: | |
1983 | case DW_TAG_union_type: | |
1984 | case DW_TAG_enumeration_type: | |
fa4028e9 JB |
1985 | /* Skip external references. The DWARF standard says in the section |
1986 | about "Structure, Union, and Class Type Entries": "An incomplete | |
1987 | structure, union or class type is represented by a structure, | |
1988 | union or class entry that does not have a byte size attribute | |
1989 | and that has a DW_AT_declaration attribute." */ | |
1990 | if (!pdi->has_byte_size && pdi->is_declaration) | |
1991 | return; | |
1992 | ||
63d06c5c DC |
1993 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
1994 | static vs. global. */ | |
38d518c9 | 1995 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1996 | STRUCT_DOMAIN, LOC_TYPEDEF, |
987504bb JJ |
1997 | (cu->language == language_cplus |
1998 | || cu->language == language_java) | |
63d06c5c DC |
1999 | ? &objfile->global_psymbols |
2000 | : &objfile->static_psymbols, | |
e142c38c | 2001 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 2002 | |
987504bb JJ |
2003 | if (cu->language == language_cplus |
2004 | || cu->language == language_java) | |
c906108c | 2005 | { |
987504bb | 2006 | /* For C++ and Java, these implicitly act as typedefs as well. */ |
38d518c9 | 2007 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2008 | VAR_DOMAIN, LOC_TYPEDEF, |
63d06c5c | 2009 | &objfile->global_psymbols, |
e142c38c | 2010 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2011 | } |
2012 | break; | |
2013 | case DW_TAG_enumerator: | |
38d518c9 | 2014 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 2015 | VAR_DOMAIN, LOC_CONST, |
987504bb JJ |
2016 | (cu->language == language_cplus |
2017 | || cu->language == language_java) | |
f6fe98ef DJ |
2018 | ? &objfile->global_psymbols |
2019 | : &objfile->static_psymbols, | |
e142c38c | 2020 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
2021 | break; |
2022 | default: | |
2023 | break; | |
2024 | } | |
5c4e30ca DC |
2025 | |
2026 | /* Check to see if we should scan the name for possible namespace | |
2027 | info. Only do this if this is C++, if we don't have namespace | |
2028 | debugging info in the file, if the psym is of an appropriate type | |
2029 | (otherwise we'll have psym == NULL), and if we actually had a | |
2030 | mangled name to begin with. */ | |
2031 | ||
72bf9492 DJ |
2032 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
2033 | cases which do not set PSYM above? */ | |
2034 | ||
e142c38c | 2035 | if (cu->language == language_cplus |
72bf9492 | 2036 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
2037 | && psym != NULL |
2038 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
2039 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
2040 | objfile); | |
72bf9492 DJ |
2041 | |
2042 | if (built_actual_name) | |
2043 | xfree (actual_name); | |
c906108c SS |
2044 | } |
2045 | ||
72bf9492 DJ |
2046 | /* Determine whether a die of type TAG living in a C++ class or |
2047 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
2048 | name listed in the die. */ |
2049 | ||
2050 | static int | |
72bf9492 | 2051 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 2052 | { |
63d06c5c DC |
2053 | switch (tag) |
2054 | { | |
72bf9492 | 2055 | case DW_TAG_namespace: |
63d06c5c DC |
2056 | case DW_TAG_typedef: |
2057 | case DW_TAG_class_type: | |
2058 | case DW_TAG_structure_type: | |
2059 | case DW_TAG_union_type: | |
2060 | case DW_TAG_enumeration_type: | |
2061 | case DW_TAG_enumerator: | |
2062 | return 1; | |
2063 | default: | |
2064 | return 0; | |
2065 | } | |
2066 | } | |
2067 | ||
5c4e30ca DC |
2068 | /* Read a partial die corresponding to a namespace; also, add a symbol |
2069 | corresponding to that namespace to the symbol table. NAMESPACE is | |
2070 | the name of the enclosing namespace. */ | |
91c24f0a | 2071 | |
72bf9492 DJ |
2072 | static void |
2073 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 2074 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 2075 | struct dwarf2_cu *cu) |
91c24f0a | 2076 | { |
e7c27a73 | 2077 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 2078 | |
72bf9492 | 2079 | /* Add a symbol for the namespace. */ |
e7c27a73 | 2080 | |
72bf9492 | 2081 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
2082 | |
2083 | /* Now scan partial symbols in that namespace. */ | |
2084 | ||
91c24f0a | 2085 | if (pdi->has_children) |
72bf9492 | 2086 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
2087 | } |
2088 | ||
72bf9492 DJ |
2089 | /* See if we can figure out if the class lives in a namespace. We do |
2090 | this by looking for a member function; its demangled name will | |
2091 | contain namespace info, if there is any. */ | |
63d06c5c | 2092 | |
72bf9492 DJ |
2093 | static void |
2094 | guess_structure_name (struct partial_die_info *struct_pdi, | |
2095 | struct dwarf2_cu *cu) | |
63d06c5c | 2096 | { |
987504bb JJ |
2097 | if ((cu->language == language_cplus |
2098 | || cu->language == language_java) | |
72bf9492 | 2099 | && cu->has_namespace_info == 0 |
63d06c5c DC |
2100 | && struct_pdi->has_children) |
2101 | { | |
63d06c5c DC |
2102 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
2103 | what template types look like, because the demangler | |
2104 | frequently doesn't give the same name as the debug info. We | |
2105 | could fix this by only using the demangled name to get the | |
134d01f1 | 2106 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 2107 | |
72bf9492 DJ |
2108 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
2109 | struct partial_die_info *real_pdi; | |
5d51ca54 | 2110 | |
72bf9492 DJ |
2111 | /* If this DIE (this DIE's specification, if any) has a parent, then |
2112 | we should not do this. We'll prepend the parent's fully qualified | |
2113 | name when we create the partial symbol. */ | |
5d51ca54 | 2114 | |
72bf9492 | 2115 | real_pdi = struct_pdi; |
72bf9492 | 2116 | while (real_pdi->has_specification) |
10b3939b | 2117 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
63d06c5c | 2118 | |
72bf9492 DJ |
2119 | if (real_pdi->die_parent != NULL) |
2120 | return; | |
63d06c5c | 2121 | |
72bf9492 DJ |
2122 | while (child_pdi != NULL) |
2123 | { | |
2124 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 2125 | { |
72bf9492 | 2126 | char *actual_class_name |
31c27f77 JJ |
2127 | = language_class_name_from_physname (cu->language_defn, |
2128 | child_pdi->name); | |
63d06c5c | 2129 | if (actual_class_name != NULL) |
72bf9492 DJ |
2130 | { |
2131 | struct_pdi->name | |
2132 | = obsavestring (actual_class_name, | |
2133 | strlen (actual_class_name), | |
2134 | &cu->comp_unit_obstack); | |
2135 | xfree (actual_class_name); | |
2136 | } | |
63d06c5c DC |
2137 | break; |
2138 | } | |
72bf9492 DJ |
2139 | |
2140 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
2141 | } |
2142 | } | |
63d06c5c DC |
2143 | } |
2144 | ||
91c24f0a DC |
2145 | /* Read a partial die corresponding to an enumeration type. */ |
2146 | ||
72bf9492 DJ |
2147 | static void |
2148 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
2149 | struct dwarf2_cu *cu) | |
91c24f0a | 2150 | { |
e7c27a73 | 2151 | struct objfile *objfile = cu->objfile; |
91c24f0a | 2152 | bfd *abfd = objfile->obfd; |
72bf9492 | 2153 | struct partial_die_info *pdi; |
91c24f0a DC |
2154 | |
2155 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
2156 | add_partial_symbol (enum_pdi, cu); |
2157 | ||
2158 | pdi = enum_pdi->die_child; | |
2159 | while (pdi) | |
91c24f0a | 2160 | { |
72bf9492 | 2161 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
e2e0b3e5 | 2162 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
91c24f0a | 2163 | else |
72bf9492 DJ |
2164 | add_partial_symbol (pdi, cu); |
2165 | pdi = pdi->die_sibling; | |
91c24f0a | 2166 | } |
91c24f0a DC |
2167 | } |
2168 | ||
4bb7a0a7 DJ |
2169 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
2170 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
2171 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
2172 | the initial number. */ | |
2173 | ||
2174 | static struct abbrev_info * | |
fe1b8b76 | 2175 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
891d2f0b | 2176 | struct dwarf2_cu *cu) |
4bb7a0a7 DJ |
2177 | { |
2178 | bfd *abfd = cu->objfile->obfd; | |
2179 | unsigned int abbrev_number; | |
2180 | struct abbrev_info *abbrev; | |
2181 | ||
2182 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
2183 | ||
2184 | if (abbrev_number == 0) | |
2185 | return NULL; | |
2186 | ||
2187 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
2188 | if (!abbrev) | |
2189 | { | |
8a3fe4f8 | 2190 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), abbrev_number, |
4bb7a0a7 DJ |
2191 | bfd_get_filename (abfd)); |
2192 | } | |
2193 | ||
2194 | return abbrev; | |
2195 | } | |
2196 | ||
2197 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
2198 | pointer to the end of a series of DIEs, terminated by an empty | |
2199 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
2200 | ||
fe1b8b76 JB |
2201 | static gdb_byte * |
2202 | skip_children (gdb_byte *info_ptr, struct dwarf2_cu *cu) | |
4bb7a0a7 DJ |
2203 | { |
2204 | struct abbrev_info *abbrev; | |
2205 | unsigned int bytes_read; | |
2206 | ||
2207 | while (1) | |
2208 | { | |
2209 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
2210 | if (abbrev == NULL) | |
2211 | return info_ptr + bytes_read; | |
2212 | else | |
2213 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
2214 | } | |
2215 | } | |
2216 | ||
2217 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
2218 | should point just after the initial uleb128 of a DIE, and the | |
2219 | abbrev corresponding to that skipped uleb128 should be passed in | |
2220 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
2221 | children. */ | |
2222 | ||
fe1b8b76 JB |
2223 | static gdb_byte * |
2224 | skip_one_die (gdb_byte *info_ptr, struct abbrev_info *abbrev, | |
4bb7a0a7 DJ |
2225 | struct dwarf2_cu *cu) |
2226 | { | |
2227 | unsigned int bytes_read; | |
2228 | struct attribute attr; | |
2229 | bfd *abfd = cu->objfile->obfd; | |
2230 | unsigned int form, i; | |
2231 | ||
2232 | for (i = 0; i < abbrev->num_attrs; i++) | |
2233 | { | |
2234 | /* The only abbrev we care about is DW_AT_sibling. */ | |
2235 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
2236 | { | |
2237 | read_attribute (&attr, &abbrev->attrs[i], | |
2238 | abfd, info_ptr, cu); | |
2239 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 2240 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
4bb7a0a7 | 2241 | else |
6502dd73 DJ |
2242 | return dwarf2_per_objfile->info_buffer |
2243 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
2244 | } |
2245 | ||
2246 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
2247 | form = abbrev->attrs[i].form; | |
2248 | skip_attribute: | |
2249 | switch (form) | |
2250 | { | |
2251 | case DW_FORM_addr: | |
2252 | case DW_FORM_ref_addr: | |
2253 | info_ptr += cu->header.addr_size; | |
2254 | break; | |
2255 | case DW_FORM_data1: | |
2256 | case DW_FORM_ref1: | |
2257 | case DW_FORM_flag: | |
2258 | info_ptr += 1; | |
2259 | break; | |
2260 | case DW_FORM_data2: | |
2261 | case DW_FORM_ref2: | |
2262 | info_ptr += 2; | |
2263 | break; | |
2264 | case DW_FORM_data4: | |
2265 | case DW_FORM_ref4: | |
2266 | info_ptr += 4; | |
2267 | break; | |
2268 | case DW_FORM_data8: | |
2269 | case DW_FORM_ref8: | |
2270 | info_ptr += 8; | |
2271 | break; | |
2272 | case DW_FORM_string: | |
2273 | read_string (abfd, info_ptr, &bytes_read); | |
2274 | info_ptr += bytes_read; | |
2275 | break; | |
2276 | case DW_FORM_strp: | |
2277 | info_ptr += cu->header.offset_size; | |
2278 | break; | |
2279 | case DW_FORM_block: | |
2280 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2281 | info_ptr += bytes_read; | |
2282 | break; | |
2283 | case DW_FORM_block1: | |
2284 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
2285 | break; | |
2286 | case DW_FORM_block2: | |
2287 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
2288 | break; | |
2289 | case DW_FORM_block4: | |
2290 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2291 | break; | |
2292 | case DW_FORM_sdata: | |
2293 | case DW_FORM_udata: | |
2294 | case DW_FORM_ref_udata: | |
2295 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2296 | break; | |
2297 | case DW_FORM_indirect: | |
2298 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2299 | info_ptr += bytes_read; | |
2300 | /* We need to continue parsing from here, so just go back to | |
2301 | the top. */ | |
2302 | goto skip_attribute; | |
2303 | ||
2304 | default: | |
8a3fe4f8 | 2305 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
4bb7a0a7 DJ |
2306 | dwarf_form_name (form), |
2307 | bfd_get_filename (abfd)); | |
2308 | } | |
2309 | } | |
2310 | ||
2311 | if (abbrev->has_children) | |
2312 | return skip_children (info_ptr, cu); | |
2313 | else | |
2314 | return info_ptr; | |
2315 | } | |
2316 | ||
2317 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2318 | the next DIE after ORIG_PDI. */ | |
91c24f0a | 2319 | |
fe1b8b76 JB |
2320 | static gdb_byte * |
2321 | locate_pdi_sibling (struct partial_die_info *orig_pdi, gdb_byte *info_ptr, | |
e7c27a73 | 2322 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2323 | { |
2324 | /* Do we know the sibling already? */ | |
72bf9492 | 2325 | |
91c24f0a DC |
2326 | if (orig_pdi->sibling) |
2327 | return orig_pdi->sibling; | |
2328 | ||
2329 | /* Are there any children to deal with? */ | |
2330 | ||
2331 | if (!orig_pdi->has_children) | |
2332 | return info_ptr; | |
2333 | ||
4bb7a0a7 | 2334 | /* Skip the children the long way. */ |
91c24f0a | 2335 | |
4bb7a0a7 | 2336 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2337 | } |
2338 | ||
c906108c SS |
2339 | /* Expand this partial symbol table into a full symbol table. */ |
2340 | ||
2341 | static void | |
fba45db2 | 2342 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2343 | { |
2344 | /* FIXME: This is barely more than a stub. */ | |
2345 | if (pst != NULL) | |
2346 | { | |
2347 | if (pst->readin) | |
2348 | { | |
8a3fe4f8 | 2349 | warning (_("bug: psymtab for %s is already read in."), pst->filename); |
c906108c SS |
2350 | } |
2351 | else | |
2352 | { | |
2353 | if (info_verbose) | |
2354 | { | |
a3f17187 | 2355 | printf_filtered (_("Reading in symbols for %s..."), pst->filename); |
c906108c SS |
2356 | gdb_flush (gdb_stdout); |
2357 | } | |
2358 | ||
10b3939b DJ |
2359 | /* Restore our global data. */ |
2360 | dwarf2_per_objfile = objfile_data (pst->objfile, | |
2361 | dwarf2_objfile_data_key); | |
2362 | ||
c906108c SS |
2363 | psymtab_to_symtab_1 (pst); |
2364 | ||
2365 | /* Finish up the debug error message. */ | |
2366 | if (info_verbose) | |
a3f17187 | 2367 | printf_filtered (_("done.\n")); |
c906108c SS |
2368 | } |
2369 | } | |
2370 | } | |
2371 | ||
10b3939b DJ |
2372 | /* Add PER_CU to the queue. */ |
2373 | ||
2374 | static void | |
2375 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2376 | { | |
2377 | struct dwarf2_queue_item *item; | |
2378 | ||
2379 | per_cu->queued = 1; | |
2380 | item = xmalloc (sizeof (*item)); | |
2381 | item->per_cu = per_cu; | |
2382 | item->next = NULL; | |
2383 | ||
2384 | if (dwarf2_queue == NULL) | |
2385 | dwarf2_queue = item; | |
2386 | else | |
2387 | dwarf2_queue_tail->next = item; | |
2388 | ||
2389 | dwarf2_queue_tail = item; | |
2390 | } | |
2391 | ||
2392 | /* Process the queue. */ | |
2393 | ||
2394 | static void | |
2395 | process_queue (struct objfile *objfile) | |
2396 | { | |
2397 | struct dwarf2_queue_item *item, *next_item; | |
2398 | ||
2399 | /* Initially, there is just one item on the queue. Load its DIEs, | |
2400 | and the DIEs of any other compilation units it requires, | |
2401 | transitively. */ | |
2402 | ||
2403 | for (item = dwarf2_queue; item != NULL; item = item->next) | |
2404 | { | |
2405 | /* Read in this compilation unit. This may add new items to | |
2406 | the end of the queue. */ | |
31ffec48 | 2407 | load_full_comp_unit (item->per_cu, objfile); |
10b3939b DJ |
2408 | |
2409 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
2410 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |
2411 | ||
2412 | /* If this compilation unit has already had full symbols created, | |
2413 | reset the TYPE fields in each DIE. */ | |
31ffec48 | 2414 | if (item->per_cu->type_hash) |
10b3939b DJ |
2415 | reset_die_and_siblings_types (item->per_cu->cu->dies, |
2416 | item->per_cu->cu); | |
2417 | } | |
2418 | ||
2419 | /* Now everything left on the queue needs to be read in. Process | |
2420 | them, one at a time, removing from the queue as we finish. */ | |
2421 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) | |
2422 | { | |
31ffec48 | 2423 | if (item->per_cu->psymtab && !item->per_cu->psymtab->readin) |
10b3939b DJ |
2424 | process_full_comp_unit (item->per_cu); |
2425 | ||
2426 | item->per_cu->queued = 0; | |
2427 | next_item = item->next; | |
2428 | xfree (item); | |
2429 | } | |
2430 | ||
2431 | dwarf2_queue_tail = NULL; | |
2432 | } | |
2433 | ||
2434 | /* Free all allocated queue entries. This function only releases anything if | |
2435 | an error was thrown; if the queue was processed then it would have been | |
2436 | freed as we went along. */ | |
2437 | ||
2438 | static void | |
2439 | dwarf2_release_queue (void *dummy) | |
2440 | { | |
2441 | struct dwarf2_queue_item *item, *last; | |
2442 | ||
2443 | item = dwarf2_queue; | |
2444 | while (item) | |
2445 | { | |
2446 | /* Anything still marked queued is likely to be in an | |
2447 | inconsistent state, so discard it. */ | |
2448 | if (item->per_cu->queued) | |
2449 | { | |
2450 | if (item->per_cu->cu != NULL) | |
2451 | free_one_cached_comp_unit (item->per_cu->cu); | |
2452 | item->per_cu->queued = 0; | |
2453 | } | |
2454 | ||
2455 | last = item; | |
2456 | item = item->next; | |
2457 | xfree (last); | |
2458 | } | |
2459 | ||
2460 | dwarf2_queue = dwarf2_queue_tail = NULL; | |
2461 | } | |
2462 | ||
2463 | /* Read in full symbols for PST, and anything it depends on. */ | |
2464 | ||
c906108c | 2465 | static void |
fba45db2 | 2466 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c | 2467 | { |
10b3939b | 2468 | struct dwarf2_per_cu_data *per_cu; |
c906108c | 2469 | struct cleanup *back_to; |
aaa75496 JB |
2470 | int i; |
2471 | ||
2472 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2473 | if (!pst->dependencies[i]->readin) | |
2474 | { | |
2475 | /* Inform about additional files that need to be read in. */ | |
2476 | if (info_verbose) | |
2477 | { | |
a3f17187 | 2478 | /* FIXME: i18n: Need to make this a single string. */ |
aaa75496 JB |
2479 | fputs_filtered (" ", gdb_stdout); |
2480 | wrap_here (""); | |
2481 | fputs_filtered ("and ", gdb_stdout); | |
2482 | wrap_here (""); | |
2483 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2484 | wrap_here (""); /* Flush output */ | |
2485 | gdb_flush (gdb_stdout); | |
2486 | } | |
2487 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2488 | } | |
2489 | ||
10b3939b DJ |
2490 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; |
2491 | ||
2492 | if (per_cu == NULL) | |
aaa75496 JB |
2493 | { |
2494 | /* It's an include file, no symbols to read for it. | |
2495 | Everything is in the parent symtab. */ | |
2496 | pst->readin = 1; | |
2497 | return; | |
2498 | } | |
c906108c | 2499 | |
10b3939b DJ |
2500 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
2501 | ||
2502 | queue_comp_unit (per_cu); | |
2503 | ||
2504 | process_queue (pst->objfile); | |
2505 | ||
2506 | /* Age the cache, releasing compilation units that have not | |
2507 | been used recently. */ | |
2508 | age_cached_comp_units (); | |
2509 | ||
2510 | do_cleanups (back_to); | |
2511 | } | |
2512 | ||
2513 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |
2514 | ||
2515 | static struct dwarf2_cu * | |
31ffec48 | 2516 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
10b3939b | 2517 | { |
31ffec48 | 2518 | bfd *abfd = objfile->obfd; |
10b3939b DJ |
2519 | struct dwarf2_cu *cu; |
2520 | unsigned long offset; | |
fe1b8b76 | 2521 | gdb_byte *info_ptr; |
10b3939b DJ |
2522 | struct cleanup *back_to, *free_cu_cleanup; |
2523 | struct attribute *attr; | |
2524 | CORE_ADDR baseaddr; | |
6502dd73 | 2525 | |
c906108c | 2526 | /* Set local variables from the partial symbol table info. */ |
10b3939b | 2527 | offset = per_cu->offset; |
6502dd73 DJ |
2528 | |
2529 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
63d06c5c | 2530 | |
10b3939b DJ |
2531 | cu = xmalloc (sizeof (struct dwarf2_cu)); |
2532 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |
c906108c | 2533 | |
10b3939b DJ |
2534 | /* If an error occurs while loading, release our storage. */ |
2535 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |
c906108c | 2536 | |
31ffec48 | 2537 | cu->objfile = objfile; |
e7c27a73 | 2538 | |
c906108c | 2539 | /* read in the comp_unit header */ |
10b3939b | 2540 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
c906108c SS |
2541 | |
2542 | /* Read the abbrevs for this compilation unit */ | |
10b3939b DJ |
2543 | dwarf2_read_abbrevs (abfd, cu); |
2544 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |
2545 | ||
2546 | cu->header.offset = offset; | |
c906108c | 2547 | |
10b3939b DJ |
2548 | cu->per_cu = per_cu; |
2549 | per_cu->cu = cu; | |
e142c38c | 2550 | |
10b3939b DJ |
2551 | /* We use this obstack for block values in dwarf_alloc_block. */ |
2552 | obstack_init (&cu->comp_unit_obstack); | |
2553 | ||
2554 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |
2555 | ||
2556 | /* We try not to read any attributes in this function, because not | |
2557 | all objfiles needed for references have been loaded yet, and symbol | |
2558 | table processing isn't initialized. But we have to set the CU language, | |
2559 | or we won't be able to build types correctly. */ | |
2560 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |
2561 | if (attr) | |
2562 | set_cu_language (DW_UNSND (attr), cu); | |
2563 | else | |
2564 | set_cu_language (language_minimal, cu); | |
2565 | ||
2566 | do_cleanups (back_to); | |
e142c38c | 2567 | |
10b3939b DJ |
2568 | /* We've successfully allocated this compilation unit. Let our caller |
2569 | clean it up when finished with it. */ | |
2570 | discard_cleanups (free_cu_cleanup); | |
c906108c | 2571 | |
10b3939b DJ |
2572 | return cu; |
2573 | } | |
2574 | ||
2575 | /* Generate full symbol information for PST and CU, whose DIEs have | |
2576 | already been loaded into memory. */ | |
2577 | ||
2578 | static void | |
2579 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |
2580 | { | |
2581 | struct partial_symtab *pst = per_cu->psymtab; | |
2582 | struct dwarf2_cu *cu = per_cu->cu; | |
2583 | struct objfile *objfile = pst->objfile; | |
2584 | bfd *abfd = objfile->obfd; | |
2585 | CORE_ADDR lowpc, highpc; | |
2586 | struct symtab *symtab; | |
2587 | struct cleanup *back_to; | |
2588 | struct attribute *attr; | |
2589 | CORE_ADDR baseaddr; | |
2590 | ||
2591 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
2592 | ||
2593 | /* We're in the global namespace. */ | |
2594 | processing_current_prefix = ""; | |
2595 | ||
2596 | buildsym_init (); | |
2597 | back_to = make_cleanup (really_free_pendings, NULL); | |
2598 | ||
2599 | cu->list_in_scope = &file_symbols; | |
c906108c | 2600 | |
0d53c4c4 DJ |
2601 | /* Find the base address of the compilation unit for range lists and |
2602 | location lists. It will normally be specified by DW_AT_low_pc. | |
2603 | In DWARF-3 draft 4, the base address could be overridden by | |
2604 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2605 | compilation units with discontinuous ranges. */ | |
2606 | ||
10b3939b DJ |
2607 | cu->header.base_known = 0; |
2608 | cu->header.base_address = 0; | |
0d53c4c4 | 2609 | |
10b3939b | 2610 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); |
0d53c4c4 DJ |
2611 | if (attr) |
2612 | { | |
10b3939b DJ |
2613 | cu->header.base_address = DW_ADDR (attr); |
2614 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2615 | } |
2616 | else | |
2617 | { | |
10b3939b | 2618 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); |
0d53c4c4 DJ |
2619 | if (attr) |
2620 | { | |
10b3939b DJ |
2621 | cu->header.base_address = DW_ADDR (attr); |
2622 | cu->header.base_known = 1; | |
0d53c4c4 DJ |
2623 | } |
2624 | } | |
2625 | ||
c906108c | 2626 | /* Do line number decoding in read_file_scope () */ |
10b3939b | 2627 | process_die (cu->dies, cu); |
c906108c | 2628 | |
fae299cd DC |
2629 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2630 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2631 | it, by scanning the DIE's below the compilation unit. */ | |
10b3939b | 2632 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
c906108c | 2633 | |
613e1657 | 2634 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2635 | |
2636 | /* Set symtab language to language from DW_AT_language. | |
2637 | If the compilation is from a C file generated by language preprocessors, | |
2638 | do not set the language if it was already deduced by start_subfile. */ | |
2639 | if (symtab != NULL | |
10b3939b | 2640 | && !(cu->language == language_c && symtab->language != language_c)) |
c906108c | 2641 | { |
10b3939b | 2642 | symtab->language = cu->language; |
c906108c SS |
2643 | } |
2644 | pst->symtab = symtab; | |
2645 | pst->readin = 1; | |
c906108c SS |
2646 | |
2647 | do_cleanups (back_to); | |
2648 | } | |
2649 | ||
2650 | /* Process a die and its children. */ | |
2651 | ||
2652 | static void | |
e7c27a73 | 2653 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2654 | { |
2655 | switch (die->tag) | |
2656 | { | |
2657 | case DW_TAG_padding: | |
2658 | break; | |
2659 | case DW_TAG_compile_unit: | |
e7c27a73 | 2660 | read_file_scope (die, cu); |
c906108c SS |
2661 | break; |
2662 | case DW_TAG_subprogram: | |
e7c27a73 DJ |
2663 | read_subroutine_type (die, cu); |
2664 | read_func_scope (die, cu); | |
c906108c SS |
2665 | break; |
2666 | case DW_TAG_inlined_subroutine: | |
2667 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2668 | They could be used to set breakpoints on all inlined instances |
2669 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2670 | break; |
2671 | case DW_TAG_lexical_block: | |
14898363 L |
2672 | case DW_TAG_try_block: |
2673 | case DW_TAG_catch_block: | |
e7c27a73 | 2674 | read_lexical_block_scope (die, cu); |
c906108c SS |
2675 | break; |
2676 | case DW_TAG_class_type: | |
2677 | case DW_TAG_structure_type: | |
2678 | case DW_TAG_union_type: | |
134d01f1 DJ |
2679 | read_structure_type (die, cu); |
2680 | process_structure_scope (die, cu); | |
c906108c SS |
2681 | break; |
2682 | case DW_TAG_enumeration_type: | |
134d01f1 DJ |
2683 | read_enumeration_type (die, cu); |
2684 | process_enumeration_scope (die, cu); | |
c906108c | 2685 | break; |
134d01f1 DJ |
2686 | |
2687 | /* FIXME drow/2004-03-14: These initialize die->type, but do not create | |
2688 | a symbol or process any children. Therefore it doesn't do anything | |
2689 | that won't be done on-demand by read_type_die. */ | |
c906108c | 2690 | case DW_TAG_subroutine_type: |
e7c27a73 | 2691 | read_subroutine_type (die, cu); |
c906108c | 2692 | break; |
72019c9c GM |
2693 | case DW_TAG_set_type: |
2694 | read_set_type (die, cu); | |
2695 | break; | |
c906108c | 2696 | case DW_TAG_array_type: |
e7c27a73 | 2697 | read_array_type (die, cu); |
c906108c SS |
2698 | break; |
2699 | case DW_TAG_pointer_type: | |
e7c27a73 | 2700 | read_tag_pointer_type (die, cu); |
c906108c SS |
2701 | break; |
2702 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 2703 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
2704 | break; |
2705 | case DW_TAG_reference_type: | |
e7c27a73 | 2706 | read_tag_reference_type (die, cu); |
c906108c SS |
2707 | break; |
2708 | case DW_TAG_string_type: | |
e7c27a73 | 2709 | read_tag_string_type (die, cu); |
c906108c | 2710 | break; |
134d01f1 DJ |
2711 | /* END FIXME */ |
2712 | ||
c906108c | 2713 | case DW_TAG_base_type: |
e7c27a73 | 2714 | read_base_type (die, cu); |
134d01f1 DJ |
2715 | /* Add a typedef symbol for the type definition, if it has a |
2716 | DW_AT_name. */ | |
2717 | new_symbol (die, die->type, cu); | |
c906108c | 2718 | break; |
a02abb62 JB |
2719 | case DW_TAG_subrange_type: |
2720 | read_subrange_type (die, cu); | |
134d01f1 DJ |
2721 | /* Add a typedef symbol for the type definition, if it has a |
2722 | DW_AT_name. */ | |
2723 | new_symbol (die, die->type, cu); | |
a02abb62 | 2724 | break; |
c906108c | 2725 | case DW_TAG_common_block: |
e7c27a73 | 2726 | read_common_block (die, cu); |
c906108c SS |
2727 | break; |
2728 | case DW_TAG_common_inclusion: | |
2729 | break; | |
d9fa45fe | 2730 | case DW_TAG_namespace: |
63d06c5c | 2731 | processing_has_namespace_info = 1; |
e7c27a73 | 2732 | read_namespace (die, cu); |
d9fa45fe DC |
2733 | break; |
2734 | case DW_TAG_imported_declaration: | |
2735 | case DW_TAG_imported_module: | |
2736 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2737 | information contained in these. DW_TAG_imported_declaration | |
2738 | dies shouldn't have children; DW_TAG_imported_module dies | |
2739 | shouldn't in the C++ case, but conceivably could in the | |
2740 | Fortran case, so we'll have to replace this gdb_assert if | |
2741 | Fortran compilers start generating that info. */ | |
63d06c5c | 2742 | processing_has_namespace_info = 1; |
639d11d3 | 2743 | gdb_assert (die->child == NULL); |
d9fa45fe | 2744 | break; |
c906108c | 2745 | default: |
e7c27a73 | 2746 | new_symbol (die, NULL, cu); |
c906108c SS |
2747 | break; |
2748 | } | |
2749 | } | |
2750 | ||
5fb290d7 | 2751 | static void |
e142c38c | 2752 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2753 | { |
e142c38c | 2754 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2755 | } |
2756 | ||
c906108c | 2757 | static void |
e7c27a73 | 2758 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2759 | { |
e7c27a73 DJ |
2760 | struct objfile *objfile = cu->objfile; |
2761 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2762 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2763 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2764 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2765 | struct attribute *attr; | |
2766 | char *name = "<unknown>"; | |
2767 | char *comp_dir = NULL; | |
2768 | struct die_info *child_die; | |
2769 | bfd *abfd = objfile->obfd; | |
debd256d | 2770 | struct line_header *line_header = 0; |
e142c38c DJ |
2771 | CORE_ADDR baseaddr; |
2772 | ||
2773 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2774 | |
fae299cd | 2775 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2776 | |
2777 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2778 | from finish_block. */ | |
2acceee2 | 2779 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2780 | lowpc = highpc; |
2781 | lowpc += baseaddr; | |
2782 | highpc += baseaddr; | |
2783 | ||
e142c38c | 2784 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2785 | if (attr) |
2786 | { | |
2787 | name = DW_STRING (attr); | |
2788 | } | |
e142c38c | 2789 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c SS |
2790 | if (attr) |
2791 | { | |
2792 | comp_dir = DW_STRING (attr); | |
2793 | if (comp_dir) | |
2794 | { | |
2795 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2796 | directory, get rid of it. */ | |
2797 | char *cp = strchr (comp_dir, ':'); | |
2798 | ||
2799 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') | |
2800 | comp_dir = cp + 1; | |
2801 | } | |
2802 | } | |
2803 | ||
e142c38c | 2804 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2805 | if (attr) |
2806 | { | |
e142c38c | 2807 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2808 | } |
2809 | ||
b0f35d58 DL |
2810 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
2811 | if (attr) | |
2812 | cu->producer = DW_STRING (attr); | |
303b6f5d | 2813 | |
c906108c SS |
2814 | /* We assume that we're processing GCC output. */ |
2815 | processing_gcc_compilation = 2; | |
c906108c SS |
2816 | |
2817 | /* The compilation unit may be in a different language or objfile, | |
2818 | zero out all remembered fundamental types. */ | |
e142c38c | 2819 | memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); |
c906108c SS |
2820 | |
2821 | start_symtab (name, comp_dir, lowpc); | |
2822 | record_debugformat ("DWARF 2"); | |
303b6f5d | 2823 | record_producer (cu->producer); |
c906108c | 2824 | |
e142c38c | 2825 | initialize_cu_func_list (cu); |
c906108c SS |
2826 | |
2827 | /* Process all dies in compilation unit. */ | |
639d11d3 | 2828 | if (die->child != NULL) |
c906108c | 2829 | { |
639d11d3 | 2830 | child_die = die->child; |
c906108c SS |
2831 | while (child_die && child_die->tag) |
2832 | { | |
e7c27a73 | 2833 | process_die (child_die, cu); |
c906108c SS |
2834 | child_die = sibling_die (child_die); |
2835 | } | |
2836 | } | |
5fb290d7 DJ |
2837 | |
2838 | /* Decode line number information if present. */ | |
e142c38c | 2839 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2840 | if (attr) |
2841 | { | |
debd256d | 2842 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2843 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2844 | if (line_header) |
2845 | { | |
2846 | make_cleanup ((make_cleanup_ftype *) free_line_header, | |
2847 | (void *) line_header); | |
aaa75496 | 2848 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2849 | } |
5fb290d7 | 2850 | } |
debd256d | 2851 | |
2e276125 JB |
2852 | /* Decode macro information, if present. Dwarf 2 macro information |
2853 | refers to information in the line number info statement program | |
2854 | header, so we can only read it if we've read the header | |
2855 | successfully. */ | |
e142c38c | 2856 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2857 | if (attr && line_header) |
2e276125 JB |
2858 | { |
2859 | unsigned int macro_offset = DW_UNSND (attr); | |
2860 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2861 | comp_dir, abfd, cu); |
2e276125 | 2862 | } |
debd256d | 2863 | do_cleanups (back_to); |
5fb290d7 DJ |
2864 | } |
2865 | ||
2866 | static void | |
e142c38c DJ |
2867 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2868 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2869 | { |
2870 | struct function_range *thisfn; | |
2871 | ||
2872 | thisfn = (struct function_range *) | |
7b5a2f43 | 2873 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2874 | thisfn->name = name; |
2875 | thisfn->lowpc = lowpc; | |
2876 | thisfn->highpc = highpc; | |
2877 | thisfn->seen_line = 0; | |
2878 | thisfn->next = NULL; | |
2879 | ||
e142c38c DJ |
2880 | if (cu->last_fn == NULL) |
2881 | cu->first_fn = thisfn; | |
5fb290d7 | 2882 | else |
e142c38c | 2883 | cu->last_fn->next = thisfn; |
5fb290d7 | 2884 | |
e142c38c | 2885 | cu->last_fn = thisfn; |
c906108c SS |
2886 | } |
2887 | ||
2888 | static void | |
e7c27a73 | 2889 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2890 | { |
e7c27a73 | 2891 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2892 | struct context_stack *new; |
c906108c SS |
2893 | CORE_ADDR lowpc; |
2894 | CORE_ADDR highpc; | |
2895 | struct die_info *child_die; | |
2896 | struct attribute *attr; | |
2897 | char *name; | |
fdde2d81 DC |
2898 | const char *previous_prefix = processing_current_prefix; |
2899 | struct cleanup *back_to = NULL; | |
e142c38c | 2900 | CORE_ADDR baseaddr; |
c906108c | 2901 | |
e142c38c DJ |
2902 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2903 | ||
2904 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2905 | |
2906 | /* Ignore functions with missing or empty names and functions with | |
2907 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2908 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2909 | return; |
2910 | ||
987504bb JJ |
2911 | if (cu->language == language_cplus |
2912 | || cu->language == language_java) | |
fdde2d81 | 2913 | { |
086ed43d | 2914 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2915 | |
2a35147e JB |
2916 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2917 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2918 | given the code | |
2919 | ||
2920 | namespace N { | |
2921 | void foo() { | |
2922 | // Definition of N::foo. | |
2923 | } | |
2924 | } | |
2925 | ||
2926 | then we'll have a tree of DIEs like this: | |
2927 | ||
2928 | 1: DW_TAG_compile_unit | |
2929 | 2: DW_TAG_namespace // N | |
2930 | 3: DW_TAG_subprogram // declaration of N::foo | |
2931 | 4: DW_TAG_subprogram // definition of N::foo | |
2932 | DW_AT_specification // refers to die #3 | |
2933 | ||
2934 | Thus, when processing die #4, we have to pretend that we're | |
2935 | in the context of its DW_AT_specification, namely the contex | |
2936 | of die #3. */ | |
fdde2d81 DC |
2937 | |
2938 | if (spec_die != NULL) | |
2939 | { | |
e142c38c | 2940 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
2941 | processing_current_prefix = specification_prefix; |
2942 | back_to = make_cleanup (xfree, specification_prefix); | |
2943 | } | |
2944 | } | |
2945 | ||
c906108c SS |
2946 | lowpc += baseaddr; |
2947 | highpc += baseaddr; | |
2948 | ||
5fb290d7 | 2949 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2950 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 2951 | |
c906108c | 2952 | new = push_context (0, lowpc); |
e7c27a73 | 2953 | new->name = new_symbol (die, die->type, cu); |
4c2df51b | 2954 | |
4cecd739 DJ |
2955 | /* If there is a location expression for DW_AT_frame_base, record |
2956 | it. */ | |
e142c38c | 2957 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 2958 | if (attr) |
c034e007 AC |
2959 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
2960 | expression is being recorded directly in the function's symbol | |
2961 | and not in a separate frame-base object. I guess this hack is | |
2962 | to avoid adding some sort of frame-base adjunct/annex to the | |
2963 | function's symbol :-(. The problem with doing this is that it | |
2964 | results in a function symbol with a location expression that | |
2965 | has nothing to do with the location of the function, ouch! The | |
2966 | relationship should be: a function's symbol has-a frame base; a | |
2967 | frame-base has-a location expression. */ | |
e7c27a73 | 2968 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 2969 | |
e142c38c | 2970 | cu->list_in_scope = &local_symbols; |
c906108c | 2971 | |
639d11d3 | 2972 | if (die->child != NULL) |
c906108c | 2973 | { |
639d11d3 | 2974 | child_die = die->child; |
c906108c SS |
2975 | while (child_die && child_die->tag) |
2976 | { | |
e7c27a73 | 2977 | process_die (child_die, cu); |
c906108c SS |
2978 | child_die = sibling_die (child_die); |
2979 | } | |
2980 | } | |
2981 | ||
2982 | new = pop_context (); | |
2983 | /* Make a block for the local symbols within. */ | |
2984 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2985 | lowpc, highpc, objfile); | |
208d8187 JB |
2986 | |
2987 | /* In C++, we can have functions nested inside functions (e.g., when | |
2988 | a function declares a class that has methods). This means that | |
2989 | when we finish processing a function scope, we may need to go | |
2990 | back to building a containing block's symbol lists. */ | |
2991 | local_symbols = new->locals; | |
2992 | param_symbols = new->params; | |
2993 | ||
921e78cf JB |
2994 | /* If we've finished processing a top-level function, subsequent |
2995 | symbols go in the file symbol list. */ | |
2996 | if (outermost_context_p ()) | |
e142c38c | 2997 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
2998 | |
2999 | processing_current_prefix = previous_prefix; | |
3000 | if (back_to != NULL) | |
3001 | do_cleanups (back_to); | |
c906108c SS |
3002 | } |
3003 | ||
3004 | /* Process all the DIES contained within a lexical block scope. Start | |
3005 | a new scope, process the dies, and then close the scope. */ | |
3006 | ||
3007 | static void | |
e7c27a73 | 3008 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3009 | { |
e7c27a73 | 3010 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 3011 | struct context_stack *new; |
c906108c SS |
3012 | CORE_ADDR lowpc, highpc; |
3013 | struct die_info *child_die; | |
e142c38c DJ |
3014 | CORE_ADDR baseaddr; |
3015 | ||
3016 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
3017 | |
3018 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
3019 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
3020 | as multiple lexical blocks? Handling children in a sane way would | |
3021 | be nasty. Might be easier to properly extend generic blocks to | |
3022 | describe ranges. */ | |
e7c27a73 | 3023 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
3024 | return; |
3025 | lowpc += baseaddr; | |
3026 | highpc += baseaddr; | |
3027 | ||
3028 | push_context (0, lowpc); | |
639d11d3 | 3029 | if (die->child != NULL) |
c906108c | 3030 | { |
639d11d3 | 3031 | child_die = die->child; |
c906108c SS |
3032 | while (child_die && child_die->tag) |
3033 | { | |
e7c27a73 | 3034 | process_die (child_die, cu); |
c906108c SS |
3035 | child_die = sibling_die (child_die); |
3036 | } | |
3037 | } | |
3038 | new = pop_context (); | |
3039 | ||
3040 | if (local_symbols != NULL) | |
3041 | { | |
3042 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
3043 | highpc, objfile); | |
3044 | } | |
3045 | local_symbols = new->locals; | |
3046 | } | |
3047 | ||
af34e669 DJ |
3048 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
3049 | are present and valid, otherwise, return 0. Return -1 if the range is | |
3050 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 3051 | static int |
af34e669 | 3052 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 3053 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c | 3054 | { |
e7c27a73 DJ |
3055 | struct objfile *objfile = cu->objfile; |
3056 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 3057 | struct attribute *attr; |
af34e669 DJ |
3058 | bfd *obfd = objfile->obfd; |
3059 | CORE_ADDR low = 0; | |
3060 | CORE_ADDR high = 0; | |
3061 | int ret = 0; | |
c906108c | 3062 | |
e142c38c | 3063 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 3064 | if (attr) |
af34e669 DJ |
3065 | { |
3066 | high = DW_ADDR (attr); | |
e142c38c | 3067 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
3068 | if (attr) |
3069 | low = DW_ADDR (attr); | |
3070 | else | |
3071 | /* Found high w/o low attribute. */ | |
3072 | return 0; | |
3073 | ||
3074 | /* Found consecutive range of addresses. */ | |
3075 | ret = 1; | |
3076 | } | |
c906108c | 3077 | else |
af34e669 | 3078 | { |
e142c38c | 3079 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
3080 | if (attr != NULL) |
3081 | { | |
3082 | unsigned int addr_size = cu_header->addr_size; | |
3083 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
3084 | /* Value of the DW_AT_ranges attribute is the offset in the | |
a604369a | 3085 | .debug_ranges section. */ |
af34e669 DJ |
3086 | unsigned int offset = DW_UNSND (attr); |
3087 | /* Base address selection entry. */ | |
0d53c4c4 DJ |
3088 | CORE_ADDR base; |
3089 | int found_base; | |
891d2f0b | 3090 | unsigned int dummy; |
fe1b8b76 | 3091 | gdb_byte *buffer; |
af34e669 DJ |
3092 | CORE_ADDR marker; |
3093 | int low_set; | |
3094 | ||
0d53c4c4 DJ |
3095 | found_base = cu_header->base_known; |
3096 | base = cu_header->base_address; | |
a604369a | 3097 | |
6502dd73 | 3098 | if (offset >= dwarf2_per_objfile->ranges_size) |
a604369a KB |
3099 | { |
3100 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3101 | _("Offset %d out of bounds for DW_AT_ranges attribute"), |
a604369a KB |
3102 | offset); |
3103 | return 0; | |
3104 | } | |
6502dd73 | 3105 | buffer = dwarf2_per_objfile->ranges_buffer + offset; |
af34e669 | 3106 | |
af34e669 | 3107 | /* Read in the largest possible address. */ |
e7c27a73 | 3108 | marker = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
3109 | if ((marker & mask) == mask) |
3110 | { | |
3111 | /* If we found the largest possible address, then | |
3112 | read the base address. */ | |
e7c27a73 | 3113 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
3114 | buffer += 2 * addr_size; |
3115 | offset += 2 * addr_size; | |
3116 | found_base = 1; | |
3117 | } | |
3118 | ||
3119 | low_set = 0; | |
3120 | ||
3121 | while (1) | |
3122 | { | |
3123 | CORE_ADDR range_beginning, range_end; | |
3124 | ||
e7c27a73 | 3125 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
af34e669 | 3126 | buffer += addr_size; |
e7c27a73 | 3127 | range_end = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
3128 | buffer += addr_size; |
3129 | offset += 2 * addr_size; | |
3130 | ||
3131 | /* An end of list marker is a pair of zero addresses. */ | |
3132 | if (range_beginning == 0 && range_end == 0) | |
3133 | /* Found the end of list entry. */ | |
3134 | break; | |
3135 | ||
3136 | /* Each base address selection entry is a pair of 2 values. | |
3137 | The first is the largest possible address, the second is | |
3138 | the base address. Check for a base address here. */ | |
3139 | if ((range_beginning & mask) == mask) | |
3140 | { | |
3141 | /* If we found the largest possible address, then | |
3142 | read the base address. */ | |
e7c27a73 | 3143 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
3144 | found_base = 1; |
3145 | continue; | |
3146 | } | |
3147 | ||
3148 | if (!found_base) | |
3149 | { | |
3150 | /* We have no valid base address for the ranges | |
3151 | data. */ | |
3152 | complaint (&symfile_complaints, | |
e2e0b3e5 | 3153 | _("Invalid .debug_ranges data (no base address)")); |
af34e669 DJ |
3154 | return 0; |
3155 | } | |
3156 | ||
8f05cde5 DJ |
3157 | range_beginning += base; |
3158 | range_end += base; | |
3159 | ||
af34e669 DJ |
3160 | /* FIXME: This is recording everything as a low-high |
3161 | segment of consecutive addresses. We should have a | |
3162 | data structure for discontiguous block ranges | |
3163 | instead. */ | |
3164 | if (! low_set) | |
3165 | { | |
3166 | low = range_beginning; | |
3167 | high = range_end; | |
3168 | low_set = 1; | |
3169 | } | |
3170 | else | |
3171 | { | |
3172 | if (range_beginning < low) | |
3173 | low = range_beginning; | |
3174 | if (range_end > high) | |
3175 | high = range_end; | |
3176 | } | |
3177 | } | |
3178 | ||
3179 | if (! low_set) | |
3180 | /* If the first entry is an end-of-list marker, the range | |
3181 | describes an empty scope, i.e. no instructions. */ | |
3182 | return 0; | |
3183 | ||
3184 | ret = -1; | |
3185 | } | |
3186 | } | |
c906108c SS |
3187 | |
3188 | if (high < low) | |
3189 | return 0; | |
3190 | ||
3191 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
3192 | eliminate duplicate copies of functions and vtables and such. | |
3193 | The linker will arbitrarily choose one and discard the others. | |
3194 | The AT_*_pc values for such functions refer to local labels in | |
3195 | these sections. If the section from that file was discarded, the | |
3196 | labels are not in the output, so the relocs get a value of 0. | |
3197 | If this is a discarded function, mark the pc bounds as invalid, | |
3198 | so that GDB will ignore it. */ | |
72dca2f5 | 3199 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
c906108c SS |
3200 | return 0; |
3201 | ||
3202 | *lowpc = low; | |
3203 | *highpc = high; | |
af34e669 | 3204 | return ret; |
c906108c SS |
3205 | } |
3206 | ||
fae299cd DC |
3207 | /* Get the low and high pc's represented by the scope DIE, and store |
3208 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
3209 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
3210 | ||
3211 | static void | |
3212 | get_scope_pc_bounds (struct die_info *die, | |
3213 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
3214 | struct dwarf2_cu *cu) | |
3215 | { | |
3216 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
3217 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
3218 | CORE_ADDR current_low, current_high; | |
3219 | ||
3220 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
3221 | { | |
3222 | best_low = current_low; | |
3223 | best_high = current_high; | |
3224 | } | |
3225 | else | |
3226 | { | |
3227 | struct die_info *child = die->child; | |
3228 | ||
3229 | while (child && child->tag) | |
3230 | { | |
3231 | switch (child->tag) { | |
3232 | case DW_TAG_subprogram: | |
3233 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
3234 | { | |
3235 | best_low = min (best_low, current_low); | |
3236 | best_high = max (best_high, current_high); | |
3237 | } | |
3238 | break; | |
3239 | case DW_TAG_namespace: | |
3240 | /* FIXME: carlton/2004-01-16: Should we do this for | |
3241 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
3242 | that current GCC's always emit the DIEs corresponding | |
3243 | to definitions of methods of classes as children of a | |
3244 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
3245 | the DIEs giving the declarations, which could be | |
3246 | anywhere). But I don't see any reason why the | |
3247 | standards says that they have to be there. */ | |
3248 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
3249 | ||
3250 | if (current_low != ((CORE_ADDR) -1)) | |
3251 | { | |
3252 | best_low = min (best_low, current_low); | |
3253 | best_high = max (best_high, current_high); | |
3254 | } | |
3255 | break; | |
3256 | default: | |
3257 | /* Ignore. */ | |
3258 | break; | |
3259 | } | |
3260 | ||
3261 | child = sibling_die (child); | |
3262 | } | |
3263 | } | |
3264 | ||
3265 | *lowpc = best_low; | |
3266 | *highpc = best_high; | |
3267 | } | |
3268 | ||
c906108c SS |
3269 | /* Add an aggregate field to the field list. */ |
3270 | ||
3271 | static void | |
107d2387 | 3272 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
3273 | struct dwarf2_cu *cu) |
3274 | { | |
3275 | struct objfile *objfile = cu->objfile; | |
c906108c SS |
3276 | struct nextfield *new_field; |
3277 | struct attribute *attr; | |
3278 | struct field *fp; | |
3279 | char *fieldname = ""; | |
3280 | ||
3281 | /* Allocate a new field list entry and link it in. */ | |
3282 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 3283 | make_cleanup (xfree, new_field); |
c906108c SS |
3284 | memset (new_field, 0, sizeof (struct nextfield)); |
3285 | new_field->next = fip->fields; | |
3286 | fip->fields = new_field; | |
3287 | fip->nfields++; | |
3288 | ||
3289 | /* Handle accessibility and virtuality of field. | |
3290 | The default accessibility for members is public, the default | |
3291 | accessibility for inheritance is private. */ | |
3292 | if (die->tag != DW_TAG_inheritance) | |
3293 | new_field->accessibility = DW_ACCESS_public; | |
3294 | else | |
3295 | new_field->accessibility = DW_ACCESS_private; | |
3296 | new_field->virtuality = DW_VIRTUALITY_none; | |
3297 | ||
e142c38c | 3298 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3299 | if (attr) |
3300 | new_field->accessibility = DW_UNSND (attr); | |
3301 | if (new_field->accessibility != DW_ACCESS_public) | |
3302 | fip->non_public_fields = 1; | |
e142c38c | 3303 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
3304 | if (attr) |
3305 | new_field->virtuality = DW_UNSND (attr); | |
3306 | ||
3307 | fp = &new_field->field; | |
a9a9bd0f | 3308 | |
e142c38c | 3309 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 3310 | { |
a9a9bd0f DC |
3311 | /* Data member other than a C++ static data member. */ |
3312 | ||
c906108c | 3313 | /* Get type of field. */ |
e7c27a73 | 3314 | fp->type = die_type (die, cu); |
c906108c | 3315 | |
01ad7f36 DJ |
3316 | FIELD_STATIC_KIND (*fp) = 0; |
3317 | ||
c906108c | 3318 | /* Get bit size of field (zero if none). */ |
e142c38c | 3319 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
3320 | if (attr) |
3321 | { | |
3322 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
3323 | } | |
3324 | else | |
3325 | { | |
3326 | FIELD_BITSIZE (*fp) = 0; | |
3327 | } | |
3328 | ||
3329 | /* Get bit offset of field. */ | |
e142c38c | 3330 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
3331 | if (attr) |
3332 | { | |
3333 | FIELD_BITPOS (*fp) = | |
e7c27a73 | 3334 | decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; |
c906108c SS |
3335 | } |
3336 | else | |
3337 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 3338 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
3339 | if (attr) |
3340 | { | |
3341 | if (BITS_BIG_ENDIAN) | |
3342 | { | |
3343 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
3344 | additional bit offset from the MSB of the containing |
3345 | anonymous object to the MSB of the field. We don't | |
3346 | have to do anything special since we don't need to | |
3347 | know the size of the anonymous object. */ | |
c906108c SS |
3348 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
3349 | } | |
3350 | else | |
3351 | { | |
3352 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
3353 | MSB of the anonymous object, subtract off the number of |
3354 | bits from the MSB of the field to the MSB of the | |
3355 | object, and then subtract off the number of bits of | |
3356 | the field itself. The result is the bit offset of | |
3357 | the LSB of the field. */ | |
c906108c SS |
3358 | int anonymous_size; |
3359 | int bit_offset = DW_UNSND (attr); | |
3360 | ||
e142c38c | 3361 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3362 | if (attr) |
3363 | { | |
3364 | /* The size of the anonymous object containing | |
3365 | the bit field is explicit, so use the | |
3366 | indicated size (in bytes). */ | |
3367 | anonymous_size = DW_UNSND (attr); | |
3368 | } | |
3369 | else | |
3370 | { | |
3371 | /* The size of the anonymous object containing | |
3372 | the bit field must be inferred from the type | |
3373 | attribute of the data member containing the | |
3374 | bit field. */ | |
3375 | anonymous_size = TYPE_LENGTH (fp->type); | |
3376 | } | |
3377 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
3378 | - bit_offset - FIELD_BITSIZE (*fp); | |
3379 | } | |
3380 | } | |
3381 | ||
3382 | /* Get name of field. */ | |
e142c38c | 3383 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3384 | if (attr && DW_STRING (attr)) |
3385 | fieldname = DW_STRING (attr); | |
d8151005 DJ |
3386 | |
3387 | /* The name is already allocated along with this objfile, so we don't | |
3388 | need to duplicate it for the type. */ | |
3389 | fp->name = fieldname; | |
c906108c SS |
3390 | |
3391 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 3392 | pointer or virtual base class pointer) to private. */ |
e142c38c | 3393 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
3394 | { |
3395 | new_field->accessibility = DW_ACCESS_private; | |
3396 | fip->non_public_fields = 1; | |
3397 | } | |
3398 | } | |
a9a9bd0f | 3399 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 3400 | { |
a9a9bd0f DC |
3401 | /* C++ static member. */ |
3402 | ||
3403 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
3404 | is a declaration, but all versions of G++ as of this writing | |
3405 | (so through at least 3.2.1) incorrectly generate | |
3406 | DW_TAG_variable tags. */ | |
3407 | ||
c906108c | 3408 | char *physname; |
c906108c | 3409 | |
a9a9bd0f | 3410 | /* Get name of field. */ |
e142c38c | 3411 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
3412 | if (attr && DW_STRING (attr)) |
3413 | fieldname = DW_STRING (attr); | |
3414 | else | |
c906108c SS |
3415 | return; |
3416 | ||
2df3850c | 3417 | /* Get physical name. */ |
e142c38c | 3418 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 3419 | |
d8151005 DJ |
3420 | /* The name is already allocated along with this objfile, so we don't |
3421 | need to duplicate it for the type. */ | |
3422 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 3423 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 3424 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
3425 | } |
3426 | else if (die->tag == DW_TAG_inheritance) | |
3427 | { | |
3428 | /* C++ base class field. */ | |
e142c38c | 3429 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 3430 | if (attr) |
e7c27a73 | 3431 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 3432 | * bits_per_byte); |
c906108c | 3433 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 3434 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 3435 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3436 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3437 | fip->nbaseclasses++; | |
3438 | } | |
3439 | } | |
3440 | ||
3441 | /* Create the vector of fields, and attach it to the type. */ | |
3442 | ||
3443 | static void | |
fba45db2 | 3444 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3445 | struct dwarf2_cu *cu) |
c906108c SS |
3446 | { |
3447 | int nfields = fip->nfields; | |
3448 | ||
3449 | /* Record the field count, allocate space for the array of fields, | |
3450 | and create blank accessibility bitfields if necessary. */ | |
3451 | TYPE_NFIELDS (type) = nfields; | |
3452 | TYPE_FIELDS (type) = (struct field *) | |
3453 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3454 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3455 | ||
3456 | if (fip->non_public_fields) | |
3457 | { | |
3458 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3459 | ||
3460 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3461 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3462 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3463 | ||
3464 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3465 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3466 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3467 | ||
3468 | TYPE_FIELD_IGNORE_BITS (type) = | |
3469 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3470 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3471 | } | |
3472 | ||
3473 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3474 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3475 | if (fip->nbaseclasses) | |
3476 | { | |
3477 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
fe1b8b76 | 3478 | unsigned char *pointer; |
c906108c SS |
3479 | |
3480 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
fe1b8b76 JB |
3481 | pointer = TYPE_ALLOC (type, num_bytes); |
3482 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; | |
c906108c SS |
3483 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
3484 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3485 | } | |
3486 | ||
3487 | /* Copy the saved-up fields into the field vector. Start from the head | |
3488 | of the list, adding to the tail of the field array, so that they end | |
3489 | up in the same order in the array in which they were added to the list. */ | |
3490 | while (nfields-- > 0) | |
3491 | { | |
3492 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3493 | switch (fip->fields->accessibility) | |
3494 | { | |
c5aa993b JM |
3495 | case DW_ACCESS_private: |
3496 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3497 | break; | |
c906108c | 3498 | |
c5aa993b JM |
3499 | case DW_ACCESS_protected: |
3500 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3501 | break; | |
c906108c | 3502 | |
c5aa993b JM |
3503 | case DW_ACCESS_public: |
3504 | break; | |
c906108c | 3505 | |
c5aa993b JM |
3506 | default: |
3507 | /* Unknown accessibility. Complain and treat it as public. */ | |
3508 | { | |
e2e0b3e5 | 3509 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
4d3c2250 | 3510 | fip->fields->accessibility); |
c5aa993b JM |
3511 | } |
3512 | break; | |
c906108c SS |
3513 | } |
3514 | if (nfields < fip->nbaseclasses) | |
3515 | { | |
3516 | switch (fip->fields->virtuality) | |
3517 | { | |
c5aa993b JM |
3518 | case DW_VIRTUALITY_virtual: |
3519 | case DW_VIRTUALITY_pure_virtual: | |
3520 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3521 | break; | |
c906108c SS |
3522 | } |
3523 | } | |
3524 | fip->fields = fip->fields->next; | |
3525 | } | |
3526 | } | |
3527 | ||
c906108c SS |
3528 | /* Add a member function to the proper fieldlist. */ |
3529 | ||
3530 | static void | |
107d2387 | 3531 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3532 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3533 | { |
e7c27a73 | 3534 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3535 | struct attribute *attr; |
3536 | struct fnfieldlist *flp; | |
3537 | int i; | |
3538 | struct fn_field *fnp; | |
3539 | char *fieldname; | |
3540 | char *physname; | |
3541 | struct nextfnfield *new_fnfield; | |
3542 | ||
2df3850c | 3543 | /* Get name of member function. */ |
e142c38c | 3544 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
3545 | if (attr && DW_STRING (attr)) |
3546 | fieldname = DW_STRING (attr); | |
c906108c | 3547 | else |
2df3850c | 3548 | return; |
c906108c | 3549 | |
2df3850c | 3550 | /* Get the mangled name. */ |
e142c38c | 3551 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3552 | |
3553 | /* Look up member function name in fieldlist. */ | |
3554 | for (i = 0; i < fip->nfnfields; i++) | |
3555 | { | |
27bfe10e | 3556 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3557 | break; |
3558 | } | |
3559 | ||
3560 | /* Create new list element if necessary. */ | |
3561 | if (i < fip->nfnfields) | |
3562 | flp = &fip->fnfieldlists[i]; | |
3563 | else | |
3564 | { | |
3565 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3566 | { | |
3567 | fip->fnfieldlists = (struct fnfieldlist *) | |
3568 | xrealloc (fip->fnfieldlists, | |
3569 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3570 | * sizeof (struct fnfieldlist)); |
c906108c | 3571 | if (fip->nfnfields == 0) |
c13c43fd | 3572 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3573 | } |
3574 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3575 | flp->name = fieldname; | |
3576 | flp->length = 0; | |
3577 | flp->head = NULL; | |
3578 | fip->nfnfields++; | |
3579 | } | |
3580 | ||
3581 | /* Create a new member function field and chain it to the field list | |
3582 | entry. */ | |
3583 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3584 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3585 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3586 | new_fnfield->next = flp->head; | |
3587 | flp->head = new_fnfield; | |
3588 | flp->length++; | |
3589 | ||
3590 | /* Fill in the member function field info. */ | |
3591 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3592 | /* The name is already allocated along with this objfile, so we don't |
3593 | need to duplicate it for the type. */ | |
3594 | fnp->physname = physname ? physname : ""; | |
c906108c SS |
3595 | fnp->type = alloc_type (objfile); |
3596 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) | |
3597 | { | |
c906108c | 3598 | int nparams = TYPE_NFIELDS (die->type); |
c906108c | 3599 | |
e26fb1d7 DC |
3600 | /* TYPE is the domain of this method, and DIE->TYPE is the type |
3601 | of the method itself (TYPE_CODE_METHOD). */ | |
3602 | smash_to_method_type (fnp->type, type, | |
ad2f7632 DJ |
3603 | TYPE_TARGET_TYPE (die->type), |
3604 | TYPE_FIELDS (die->type), | |
3605 | TYPE_NFIELDS (die->type), | |
3606 | TYPE_VARARGS (die->type)); | |
c906108c SS |
3607 | |
3608 | /* Handle static member functions. | |
c5aa993b JM |
3609 | Dwarf2 has no clean way to discern C++ static and non-static |
3610 | member functions. G++ helps GDB by marking the first | |
3611 | parameter for non-static member functions (which is the | |
3612 | this pointer) as artificial. We obtain this information | |
3613 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
3614 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
3615 | fnp->voffset = VOFFSET_STATIC; | |
3616 | } | |
3617 | else | |
e2e0b3e5 | 3618 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
4d3c2250 | 3619 | physname); |
c906108c SS |
3620 | |
3621 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3622 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3623 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3624 | |
3625 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3626 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3627 | ||
3628 | /* Get accessibility. */ | |
e142c38c | 3629 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3630 | if (attr) |
3631 | { | |
3632 | switch (DW_UNSND (attr)) | |
3633 | { | |
c5aa993b JM |
3634 | case DW_ACCESS_private: |
3635 | fnp->is_private = 1; | |
3636 | break; | |
3637 | case DW_ACCESS_protected: | |
3638 | fnp->is_protected = 1; | |
3639 | break; | |
c906108c SS |
3640 | } |
3641 | } | |
3642 | ||
b02dede2 | 3643 | /* Check for artificial methods. */ |
e142c38c | 3644 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3645 | if (attr && DW_UNSND (attr) != 0) |
3646 | fnp->is_artificial = 1; | |
3647 | ||
c906108c | 3648 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3649 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3650 | if (attr) |
8e19ed76 PS |
3651 | { |
3652 | /* Support the .debug_loc offsets */ | |
3653 | if (attr_form_is_block (attr)) | |
3654 | { | |
e7c27a73 | 3655 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 PS |
3656 | } |
3657 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3658 | { | |
4d3c2250 | 3659 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3660 | } |
3661 | else | |
3662 | { | |
4d3c2250 KB |
3663 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3664 | fieldname); | |
8e19ed76 PS |
3665 | } |
3666 | } | |
c906108c SS |
3667 | } |
3668 | ||
3669 | /* Create the vector of member function fields, and attach it to the type. */ | |
3670 | ||
3671 | static void | |
fba45db2 | 3672 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3673 | struct dwarf2_cu *cu) |
c906108c SS |
3674 | { |
3675 | struct fnfieldlist *flp; | |
3676 | int total_length = 0; | |
3677 | int i; | |
3678 | ||
3679 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3680 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3681 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3682 | ||
3683 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3684 | { | |
3685 | struct nextfnfield *nfp = flp->head; | |
3686 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3687 | int k; | |
3688 | ||
3689 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3690 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3691 | fn_flp->fn_fields = (struct fn_field *) | |
3692 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3693 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3694 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3695 | |
3696 | total_length += flp->length; | |
3697 | } | |
3698 | ||
3699 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3700 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3701 | } | |
3702 | ||
1168df01 JB |
3703 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
3704 | language, zero otherwise. */ | |
3705 | static int | |
3706 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |
3707 | { | |
3708 | static const char vptr[] = "_vptr"; | |
987504bb | 3709 | static const char vtable[] = "vtable"; |
1168df01 | 3710 | |
987504bb JJ |
3711 | /* Look for the C++ and Java forms of the vtable. */ |
3712 | if ((cu->language == language_java | |
3713 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |
3714 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |
3715 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |
1168df01 JB |
3716 | return 1; |
3717 | ||
3718 | return 0; | |
3719 | } | |
3720 | ||
c0dd20ea DJ |
3721 | /* GCC outputs unnamed structures that are really pointers to member |
3722 | functions, with the ABI-specified layout. If DIE (from CU) describes | |
3723 | such a structure, set its type, and return nonzero. Otherwise return | |
61049d3b DJ |
3724 | zero. |
3725 | ||
3726 | GCC shouldn't do this; it should just output pointer to member DIEs. | |
3727 | This is GCC PR debug/28767. */ | |
c0dd20ea DJ |
3728 | |
3729 | static int | |
3730 | quirk_gcc_member_function_pointer (struct die_info *die, struct dwarf2_cu *cu) | |
3731 | { | |
3732 | struct objfile *objfile = cu->objfile; | |
3733 | struct type *type; | |
3734 | struct die_info *pfn_die, *delta_die; | |
3735 | struct attribute *pfn_name, *delta_name; | |
3736 | struct type *pfn_type, *domain_type; | |
3737 | ||
3738 | /* Check for a structure with no name and two children. */ | |
3739 | if (die->tag != DW_TAG_structure_type | |
3740 | || dwarf2_attr (die, DW_AT_name, cu) != NULL | |
3741 | || die->child == NULL | |
3742 | || die->child->sibling == NULL | |
3743 | || (die->child->sibling->sibling != NULL | |
3744 | && die->child->sibling->sibling->tag != DW_TAG_padding)) | |
3745 | return 0; | |
3746 | ||
3747 | /* Check for __pfn and __delta members. */ | |
3748 | pfn_die = die->child; | |
3749 | pfn_name = dwarf2_attr (pfn_die, DW_AT_name, cu); | |
3750 | if (pfn_die->tag != DW_TAG_member | |
3751 | || pfn_name == NULL | |
3752 | || DW_STRING (pfn_name) == NULL | |
3753 | || strcmp ("__pfn", DW_STRING (pfn_name)) != 0) | |
3754 | return 0; | |
3755 | ||
3756 | delta_die = pfn_die->sibling; | |
3757 | delta_name = dwarf2_attr (delta_die, DW_AT_name, cu); | |
3758 | if (delta_die->tag != DW_TAG_member | |
3759 | || delta_name == NULL | |
3760 | || DW_STRING (delta_name) == NULL | |
3761 | || strcmp ("__delta", DW_STRING (delta_name)) != 0) | |
3762 | return 0; | |
3763 | ||
3764 | /* Find the type of the method. */ | |
3765 | pfn_type = die_type (pfn_die, cu); | |
3766 | if (pfn_type == NULL | |
3767 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR | |
3768 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) | |
3769 | return 0; | |
3770 | ||
3771 | /* Look for the "this" argument. */ | |
3772 | pfn_type = TYPE_TARGET_TYPE (pfn_type); | |
3773 | if (TYPE_NFIELDS (pfn_type) == 0 | |
3774 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) | |
3775 | return 0; | |
3776 | ||
3777 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); | |
3778 | type = alloc_type (objfile); | |
3779 | smash_to_method_type (type, domain_type, TYPE_TARGET_TYPE (pfn_type), | |
3780 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), | |
3781 | TYPE_VARARGS (pfn_type)); | |
0d5de010 | 3782 | type = lookup_methodptr_type (type); |
c0dd20ea DJ |
3783 | set_die_type (die, type, cu); |
3784 | ||
3785 | return 1; | |
3786 | } | |
1168df01 | 3787 | |
c906108c SS |
3788 | /* Called when we find the DIE that starts a structure or union scope |
3789 | (definition) to process all dies that define the members of the | |
3790 | structure or union. | |
3791 | ||
3792 | NOTE: we need to call struct_type regardless of whether or not the | |
3793 | DIE has an at_name attribute, since it might be an anonymous | |
3794 | structure or union. This gets the type entered into our set of | |
3795 | user defined types. | |
3796 | ||
3797 | However, if the structure is incomplete (an opaque struct/union) | |
3798 | then suppress creating a symbol table entry for it since gdb only | |
3799 | wants to find the one with the complete definition. Note that if | |
3800 | it is complete, we just call new_symbol, which does it's own | |
3801 | checking about whether the struct/union is anonymous or not (and | |
3802 | suppresses creating a symbol table entry itself). */ | |
3803 | ||
3804 | static void | |
134d01f1 | 3805 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3806 | { |
e7c27a73 | 3807 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3808 | struct type *type; |
3809 | struct attribute *attr; | |
63d06c5c DC |
3810 | const char *previous_prefix = processing_current_prefix; |
3811 | struct cleanup *back_to = NULL; | |
c906108c | 3812 | |
134d01f1 DJ |
3813 | if (die->type) |
3814 | return; | |
3815 | ||
c0dd20ea DJ |
3816 | if (quirk_gcc_member_function_pointer (die, cu)) |
3817 | return; | |
c906108c | 3818 | |
c0dd20ea | 3819 | type = alloc_type (objfile); |
c906108c | 3820 | INIT_CPLUS_SPECIFIC (type); |
e142c38c | 3821 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3822 | if (attr && DW_STRING (attr)) |
3823 | { | |
987504bb JJ |
3824 | if (cu->language == language_cplus |
3825 | || cu->language == language_java) | |
63d06c5c | 3826 | { |
8176b9b8 DC |
3827 | char *new_prefix = determine_class_name (die, cu); |
3828 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
3829 | strlen (new_prefix), | |
3830 | &objfile->objfile_obstack); | |
3831 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
3832 | processing_current_prefix = new_prefix; |
3833 | } | |
3834 | else | |
3835 | { | |
d8151005 DJ |
3836 | /* The name is already allocated along with this objfile, so |
3837 | we don't need to duplicate it for the type. */ | |
8176b9b8 | 3838 | TYPE_TAG_NAME (type) = DW_STRING (attr); |
63d06c5c | 3839 | } |
c906108c SS |
3840 | } |
3841 | ||
3842 | if (die->tag == DW_TAG_structure_type) | |
3843 | { | |
3844 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
3845 | } | |
3846 | else if (die->tag == DW_TAG_union_type) | |
3847 | { | |
3848 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
3849 | } | |
3850 | else | |
3851 | { | |
3852 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 3853 | in gdbtypes.h. */ |
c906108c SS |
3854 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
3855 | } | |
3856 | ||
e142c38c | 3857 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3858 | if (attr) |
3859 | { | |
3860 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3861 | } | |
3862 | else | |
3863 | { | |
3864 | TYPE_LENGTH (type) = 0; | |
3865 | } | |
3866 | ||
dc718098 JB |
3867 | if (die_is_declaration (die, cu)) |
3868 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
3869 | ||
c906108c SS |
3870 | /* We need to add the type field to the die immediately so we don't |
3871 | infinitely recurse when dealing with pointers to the structure | |
3872 | type within the structure itself. */ | |
1c379e20 | 3873 | set_die_type (die, type, cu); |
c906108c | 3874 | |
e142c38c | 3875 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
3876 | { |
3877 | struct field_info fi; | |
3878 | struct die_info *child_die; | |
3879 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
3880 | ||
3881 | memset (&fi, 0, sizeof (struct field_info)); | |
3882 | ||
639d11d3 | 3883 | child_die = die->child; |
c906108c SS |
3884 | |
3885 | while (child_die && child_die->tag) | |
3886 | { | |
a9a9bd0f DC |
3887 | if (child_die->tag == DW_TAG_member |
3888 | || child_die->tag == DW_TAG_variable) | |
c906108c | 3889 | { |
a9a9bd0f DC |
3890 | /* NOTE: carlton/2002-11-05: A C++ static data member |
3891 | should be a DW_TAG_member that is a declaration, but | |
3892 | all versions of G++ as of this writing (so through at | |
3893 | least 3.2.1) incorrectly generate DW_TAG_variable | |
3894 | tags for them instead. */ | |
e7c27a73 | 3895 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3896 | } |
8713b1b1 | 3897 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
3898 | { |
3899 | /* C++ member function. */ | |
134d01f1 | 3900 | read_type_die (child_die, cu); |
e7c27a73 | 3901 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
3902 | } |
3903 | else if (child_die->tag == DW_TAG_inheritance) | |
3904 | { | |
3905 | /* C++ base class field. */ | |
e7c27a73 | 3906 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3907 | } |
c906108c SS |
3908 | child_die = sibling_die (child_die); |
3909 | } | |
3910 | ||
3911 | /* Attach fields and member functions to the type. */ | |
3912 | if (fi.nfields) | |
e7c27a73 | 3913 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
3914 | if (fi.nfnfields) |
3915 | { | |
e7c27a73 | 3916 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 3917 | |
c5aa993b | 3918 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
3919 | class itself) which contains the vtable pointer for the current |
3920 | class from the DW_AT_containing_type attribute. */ | |
3921 | ||
e142c38c | 3922 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 3923 | { |
e7c27a73 | 3924 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
3925 | |
3926 | TYPE_VPTR_BASETYPE (type) = t; | |
3927 | if (type == t) | |
3928 | { | |
c906108c SS |
3929 | int i; |
3930 | ||
3931 | /* Our own class provides vtbl ptr. */ | |
3932 | for (i = TYPE_NFIELDS (t) - 1; | |
3933 | i >= TYPE_N_BASECLASSES (t); | |
3934 | --i) | |
3935 | { | |
3936 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
3937 | ||
1168df01 | 3938 | if (is_vtable_name (fieldname, cu)) |
c906108c SS |
3939 | { |
3940 | TYPE_VPTR_FIELDNO (type) = i; | |
3941 | break; | |
3942 | } | |
3943 | } | |
3944 | ||
3945 | /* Complain if virtual function table field not found. */ | |
3946 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 | 3947 | complaint (&symfile_complaints, |
e2e0b3e5 | 3948 | _("virtual function table pointer not found when defining class '%s'"), |
4d3c2250 KB |
3949 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
3950 | ""); | |
c906108c SS |
3951 | } |
3952 | else | |
3953 | { | |
3954 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
3955 | } | |
3956 | } | |
f6235d4c EZ |
3957 | else if (cu->producer |
3958 | && strncmp (cu->producer, | |
3959 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) | |
3960 | { | |
3961 | /* The IBM XLC compiler does not provide direct indication | |
3962 | of the containing type, but the vtable pointer is | |
3963 | always named __vfp. */ | |
3964 | ||
3965 | int i; | |
3966 | ||
3967 | for (i = TYPE_NFIELDS (type) - 1; | |
3968 | i >= TYPE_N_BASECLASSES (type); | |
3969 | --i) | |
3970 | { | |
3971 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) | |
3972 | { | |
3973 | TYPE_VPTR_FIELDNO (type) = i; | |
3974 | TYPE_VPTR_BASETYPE (type) = type; | |
3975 | break; | |
3976 | } | |
3977 | } | |
3978 | } | |
c906108c SS |
3979 | } |
3980 | ||
c906108c SS |
3981 | do_cleanups (back_to); |
3982 | } | |
63d06c5c DC |
3983 | |
3984 | processing_current_prefix = previous_prefix; | |
3985 | if (back_to != NULL) | |
3986 | do_cleanups (back_to); | |
c906108c SS |
3987 | } |
3988 | ||
134d01f1 DJ |
3989 | static void |
3990 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3991 | { | |
3992 | struct objfile *objfile = cu->objfile; | |
3993 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 3994 | struct die_info *child_die = die->child; |
c906108c | 3995 | |
134d01f1 DJ |
3996 | if (TYPE_TAG_NAME (die->type) != NULL) |
3997 | processing_current_prefix = TYPE_TAG_NAME (die->type); | |
c906108c | 3998 | |
90aeadfc DC |
3999 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
4000 | snapshots) has been known to create a die giving a declaration | |
4001 | for a class that has, as a child, a die giving a definition for a | |
4002 | nested class. So we have to process our children even if the | |
4003 | current die is a declaration. Normally, of course, a declaration | |
4004 | won't have any children at all. */ | |
134d01f1 | 4005 | |
90aeadfc DC |
4006 | while (child_die != NULL && child_die->tag) |
4007 | { | |
4008 | if (child_die->tag == DW_TAG_member | |
4009 | || child_die->tag == DW_TAG_variable | |
4010 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 4011 | { |
90aeadfc | 4012 | /* Do nothing. */ |
134d01f1 | 4013 | } |
90aeadfc DC |
4014 | else |
4015 | process_die (child_die, cu); | |
134d01f1 | 4016 | |
90aeadfc | 4017 | child_die = sibling_die (child_die); |
134d01f1 DJ |
4018 | } |
4019 | ||
fa4028e9 JB |
4020 | /* Do not consider external references. According to the DWARF standard, |
4021 | these DIEs are identified by the fact that they have no byte_size | |
4022 | attribute, and a declaration attribute. */ | |
4023 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL | |
4024 | || !die_is_declaration (die, cu)) | |
90aeadfc DC |
4025 | new_symbol (die, die->type, cu); |
4026 | ||
134d01f1 DJ |
4027 | processing_current_prefix = previous_prefix; |
4028 | } | |
4029 | ||
4030 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
4031 | complete the type's fields yet, or create any symbols. */ | |
c906108c SS |
4032 | |
4033 | static void | |
134d01f1 | 4034 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4035 | { |
e7c27a73 | 4036 | struct objfile *objfile = cu->objfile; |
c906108c | 4037 | struct type *type; |
c906108c | 4038 | struct attribute *attr; |
134d01f1 DJ |
4039 | |
4040 | if (die->type) | |
4041 | return; | |
c906108c SS |
4042 | |
4043 | type = alloc_type (objfile); | |
4044 | ||
4045 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
e142c38c | 4046 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
4047 | if (attr && DW_STRING (attr)) |
4048 | { | |
d8151005 | 4049 | char *name = DW_STRING (attr); |
63d06c5c DC |
4050 | |
4051 | if (processing_has_namespace_info) | |
4052 | { | |
987504bb JJ |
4053 | TYPE_TAG_NAME (type) = typename_concat (&objfile->objfile_obstack, |
4054 | processing_current_prefix, | |
4055 | name, cu); | |
63d06c5c DC |
4056 | } |
4057 | else | |
4058 | { | |
d8151005 DJ |
4059 | /* The name is already allocated along with this objfile, so |
4060 | we don't need to duplicate it for the type. */ | |
4061 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 4062 | } |
c906108c SS |
4063 | } |
4064 | ||
e142c38c | 4065 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4066 | if (attr) |
4067 | { | |
4068 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4069 | } | |
4070 | else | |
4071 | { | |
4072 | TYPE_LENGTH (type) = 0; | |
4073 | } | |
4074 | ||
1c379e20 | 4075 | set_die_type (die, type, cu); |
134d01f1 DJ |
4076 | } |
4077 | ||
8176b9b8 | 4078 | /* Determine the name of the type represented by DIE, which should be |
987504bb | 4079 | a named C++ or Java compound type. Return the name in question; the caller |
8176b9b8 DC |
4080 | is responsible for xfree()'ing it. */ |
4081 | ||
4082 | static char * | |
4083 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
4084 | { | |
4085 | struct cleanup *back_to = NULL; | |
4086 | struct die_info *spec_die = die_specification (die, cu); | |
4087 | char *new_prefix = NULL; | |
4088 | ||
4089 | /* If this is the definition of a class that is declared by another | |
4090 | die, then processing_current_prefix may not be accurate; see | |
4091 | read_func_scope for a similar example. */ | |
4092 | if (spec_die != NULL) | |
4093 | { | |
4094 | char *specification_prefix = determine_prefix (spec_die, cu); | |
4095 | processing_current_prefix = specification_prefix; | |
4096 | back_to = make_cleanup (xfree, specification_prefix); | |
4097 | } | |
4098 | ||
4099 | /* If we don't have namespace debug info, guess the name by trying | |
4100 | to demangle the names of members, just like we did in | |
72bf9492 | 4101 | guess_structure_name. */ |
8176b9b8 DC |
4102 | if (!processing_has_namespace_info) |
4103 | { | |
4104 | struct die_info *child; | |
4105 | ||
4106 | for (child = die->child; | |
4107 | child != NULL && child->tag != 0; | |
4108 | child = sibling_die (child)) | |
4109 | { | |
4110 | if (child->tag == DW_TAG_subprogram) | |
4111 | { | |
31c27f77 JJ |
4112 | new_prefix |
4113 | = language_class_name_from_physname (cu->language_defn, | |
4114 | dwarf2_linkage_name | |
8176b9b8 DC |
4115 | (child, cu)); |
4116 | ||
4117 | if (new_prefix != NULL) | |
4118 | break; | |
4119 | } | |
4120 | } | |
4121 | } | |
4122 | ||
4123 | if (new_prefix == NULL) | |
4124 | { | |
4125 | const char *name = dwarf2_name (die, cu); | |
987504bb JJ |
4126 | new_prefix = typename_concat (NULL, processing_current_prefix, |
4127 | name ? name : "<<anonymous>>", | |
4128 | cu); | |
8176b9b8 DC |
4129 | } |
4130 | ||
4131 | if (back_to != NULL) | |
4132 | do_cleanups (back_to); | |
4133 | ||
4134 | return new_prefix; | |
4135 | } | |
4136 | ||
134d01f1 DJ |
4137 | /* Given a pointer to a die which begins an enumeration, process all |
4138 | the dies that define the members of the enumeration, and create the | |
4139 | symbol for the enumeration type. | |
4140 | ||
4141 | NOTE: We reverse the order of the element list. */ | |
4142 | ||
4143 | static void | |
4144 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
4145 | { | |
4146 | struct objfile *objfile = cu->objfile; | |
4147 | struct die_info *child_die; | |
4148 | struct field *fields; | |
4149 | struct attribute *attr; | |
4150 | struct symbol *sym; | |
4151 | int num_fields; | |
4152 | int unsigned_enum = 1; | |
4153 | ||
c906108c SS |
4154 | num_fields = 0; |
4155 | fields = NULL; | |
639d11d3 | 4156 | if (die->child != NULL) |
c906108c | 4157 | { |
639d11d3 | 4158 | child_die = die->child; |
c906108c SS |
4159 | while (child_die && child_die->tag) |
4160 | { | |
4161 | if (child_die->tag != DW_TAG_enumerator) | |
4162 | { | |
e7c27a73 | 4163 | process_die (child_die, cu); |
c906108c SS |
4164 | } |
4165 | else | |
4166 | { | |
e142c38c | 4167 | attr = dwarf2_attr (child_die, DW_AT_name, cu); |
c906108c SS |
4168 | if (attr) |
4169 | { | |
134d01f1 | 4170 | sym = new_symbol (child_die, die->type, cu); |
c906108c SS |
4171 | if (SYMBOL_VALUE (sym) < 0) |
4172 | unsigned_enum = 0; | |
4173 | ||
4174 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
4175 | { | |
4176 | fields = (struct field *) | |
4177 | xrealloc (fields, | |
4178 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 4179 | * sizeof (struct field)); |
c906108c SS |
4180 | } |
4181 | ||
22abf04a | 4182 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
4183 | FIELD_TYPE (fields[num_fields]) = NULL; |
4184 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
4185 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 4186 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
4187 | |
4188 | num_fields++; | |
4189 | } | |
4190 | } | |
4191 | ||
4192 | child_die = sibling_die (child_die); | |
4193 | } | |
4194 | ||
4195 | if (num_fields) | |
4196 | { | |
134d01f1 DJ |
4197 | TYPE_NFIELDS (die->type) = num_fields; |
4198 | TYPE_FIELDS (die->type) = (struct field *) | |
4199 | TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); | |
4200 | memcpy (TYPE_FIELDS (die->type), fields, | |
c906108c | 4201 | sizeof (struct field) * num_fields); |
b8c9b27d | 4202 | xfree (fields); |
c906108c SS |
4203 | } |
4204 | if (unsigned_enum) | |
134d01f1 | 4205 | TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 4206 | } |
134d01f1 DJ |
4207 | |
4208 | new_symbol (die, die->type, cu); | |
c906108c SS |
4209 | } |
4210 | ||
4211 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
4212 | the DIE's type field. For now, this only handles one dimensional | |
4213 | arrays. */ | |
4214 | ||
4215 | static void | |
e7c27a73 | 4216 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4217 | { |
e7c27a73 | 4218 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4219 | struct die_info *child_die; |
4220 | struct type *type = NULL; | |
4221 | struct type *element_type, *range_type, *index_type; | |
4222 | struct type **range_types = NULL; | |
4223 | struct attribute *attr; | |
4224 | int ndim = 0; | |
4225 | struct cleanup *back_to; | |
4226 | ||
4227 | /* Return if we've already decoded this type. */ | |
4228 | if (die->type) | |
4229 | { | |
4230 | return; | |
4231 | } | |
4232 | ||
e7c27a73 | 4233 | element_type = die_type (die, cu); |
c906108c SS |
4234 | |
4235 | /* Irix 6.2 native cc creates array types without children for | |
4236 | arrays with unspecified length. */ | |
639d11d3 | 4237 | if (die->child == NULL) |
c906108c | 4238 | { |
e142c38c | 4239 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c | 4240 | range_type = create_range_type (NULL, index_type, 0, -1); |
1c379e20 DJ |
4241 | set_die_type (die, create_array_type (NULL, element_type, range_type), |
4242 | cu); | |
c906108c SS |
4243 | return; |
4244 | } | |
4245 | ||
4246 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 4247 | child_die = die->child; |
c906108c SS |
4248 | while (child_die && child_die->tag) |
4249 | { | |
4250 | if (child_die->tag == DW_TAG_subrange_type) | |
4251 | { | |
a02abb62 | 4252 | read_subrange_type (child_die, cu); |
c906108c | 4253 | |
a02abb62 JB |
4254 | if (child_die->type != NULL) |
4255 | { | |
4256 | /* The range type was succesfully read. Save it for | |
4257 | the array type creation. */ | |
4258 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
4259 | { | |
4260 | range_types = (struct type **) | |
4261 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
4262 | * sizeof (struct type *)); | |
4263 | if (ndim == 0) | |
4264 | make_cleanup (free_current_contents, &range_types); | |
4265 | } | |
4266 | range_types[ndim++] = child_die->type; | |
4267 | } | |
c906108c SS |
4268 | } |
4269 | child_die = sibling_die (child_die); | |
4270 | } | |
4271 | ||
4272 | /* Dwarf2 dimensions are output from left to right, create the | |
4273 | necessary array types in backwards order. */ | |
7ca2d3a3 | 4274 | |
c906108c | 4275 | type = element_type; |
7ca2d3a3 DL |
4276 | |
4277 | if (read_array_order (die, cu) == DW_ORD_col_major) | |
4278 | { | |
4279 | int i = 0; | |
4280 | while (i < ndim) | |
4281 | type = create_array_type (NULL, type, range_types[i++]); | |
4282 | } | |
4283 | else | |
4284 | { | |
4285 | while (ndim-- > 0) | |
4286 | type = create_array_type (NULL, type, range_types[ndim]); | |
4287 | } | |
c906108c | 4288 | |
f5f8a009 EZ |
4289 | /* Understand Dwarf2 support for vector types (like they occur on |
4290 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
4291 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
4292 | custom vendor extension. The main difference between a regular | |
4293 | array and the vector variant is that vectors are passed by value | |
4294 | to functions. */ | |
e142c38c | 4295 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 EZ |
4296 | if (attr) |
4297 | TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; | |
4298 | ||
714e295e JB |
4299 | attr = dwarf2_attr (die, DW_AT_name, cu); |
4300 | if (attr && DW_STRING (attr)) | |
4301 | TYPE_NAME (type) = DW_STRING (attr); | |
4302 | ||
c906108c SS |
4303 | do_cleanups (back_to); |
4304 | ||
4305 | /* Install the type in the die. */ | |
1c379e20 | 4306 | set_die_type (die, type, cu); |
c906108c SS |
4307 | } |
4308 | ||
7ca2d3a3 DL |
4309 | static enum dwarf_array_dim_ordering |
4310 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |
4311 | { | |
4312 | struct attribute *attr; | |
4313 | ||
4314 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |
4315 | ||
4316 | if (attr) return DW_SND (attr); | |
4317 | ||
4318 | /* | |
4319 | GNU F77 is a special case, as at 08/2004 array type info is the | |
4320 | opposite order to the dwarf2 specification, but data is still | |
4321 | laid out as per normal fortran. | |
4322 | ||
4323 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |
4324 | version checking. | |
4325 | */ | |
4326 | ||
4327 | if (cu->language == language_fortran && | |
4328 | cu->producer && strstr (cu->producer, "GNU F77")) | |
4329 | { | |
4330 | return DW_ORD_row_major; | |
4331 | } | |
4332 | ||
4333 | switch (cu->language_defn->la_array_ordering) | |
4334 | { | |
4335 | case array_column_major: | |
4336 | return DW_ORD_col_major; | |
4337 | case array_row_major: | |
4338 | default: | |
4339 | return DW_ORD_row_major; | |
4340 | }; | |
4341 | } | |
4342 | ||
72019c9c GM |
4343 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
4344 | the DIE's type field. */ | |
4345 | ||
4346 | static void | |
4347 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) | |
4348 | { | |
4349 | if (die->type == NULL) | |
4350 | die->type = create_set_type ((struct type *) NULL, die_type (die, cu)); | |
4351 | } | |
7ca2d3a3 | 4352 | |
c906108c SS |
4353 | /* First cut: install each common block member as a global variable. */ |
4354 | ||
4355 | static void | |
e7c27a73 | 4356 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4357 | { |
4358 | struct die_info *child_die; | |
4359 | struct attribute *attr; | |
4360 | struct symbol *sym; | |
4361 | CORE_ADDR base = (CORE_ADDR) 0; | |
4362 | ||
e142c38c | 4363 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
4364 | if (attr) |
4365 | { | |
8e19ed76 PS |
4366 | /* Support the .debug_loc offsets */ |
4367 | if (attr_form_is_block (attr)) | |
4368 | { | |
e7c27a73 | 4369 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 PS |
4370 | } |
4371 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
4372 | { | |
4d3c2250 | 4373 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4374 | } |
4375 | else | |
4376 | { | |
4d3c2250 KB |
4377 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4378 | "common block member"); | |
8e19ed76 | 4379 | } |
c906108c | 4380 | } |
639d11d3 | 4381 | if (die->child != NULL) |
c906108c | 4382 | { |
639d11d3 | 4383 | child_die = die->child; |
c906108c SS |
4384 | while (child_die && child_die->tag) |
4385 | { | |
e7c27a73 | 4386 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 4387 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
4388 | if (attr) |
4389 | { | |
4390 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 4391 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
4392 | add_symbol_to_list (sym, &global_symbols); |
4393 | } | |
4394 | child_die = sibling_die (child_die); | |
4395 | } | |
4396 | } | |
4397 | } | |
4398 | ||
d9fa45fe DC |
4399 | /* Read a C++ namespace. */ |
4400 | ||
d9fa45fe | 4401 | static void |
e7c27a73 | 4402 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 4403 | { |
e7c27a73 | 4404 | struct objfile *objfile = cu->objfile; |
38d518c9 | 4405 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 4406 | const char *name; |
9219021c DC |
4407 | int is_anonymous; |
4408 | struct die_info *current_die; | |
987504bb | 4409 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
9219021c | 4410 | |
e142c38c | 4411 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
4412 | |
4413 | /* Now build the name of the current namespace. */ | |
4414 | ||
38d518c9 | 4415 | if (previous_prefix[0] == '\0') |
9219021c | 4416 | { |
38d518c9 | 4417 | processing_current_prefix = name; |
9219021c DC |
4418 | } |
4419 | else | |
4420 | { | |
987504bb JJ |
4421 | char *temp_name = typename_concat (NULL, previous_prefix, name, cu); |
4422 | make_cleanup (xfree, temp_name); | |
38d518c9 | 4423 | processing_current_prefix = temp_name; |
9219021c DC |
4424 | } |
4425 | ||
5c4e30ca DC |
4426 | /* Add a symbol associated to this if we haven't seen the namespace |
4427 | before. Also, add a using directive if it's an anonymous | |
4428 | namespace. */ | |
9219021c | 4429 | |
e142c38c | 4430 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
4431 | { |
4432 | struct type *type; | |
4433 | ||
4434 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
4435 | this cast will hopefully become unnecessary. */ | |
4436 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 4437 | (char *) processing_current_prefix, |
5c4e30ca DC |
4438 | objfile); |
4439 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
4440 | ||
e7c27a73 | 4441 | new_symbol (die, type, cu); |
1c379e20 | 4442 | set_die_type (die, type, cu); |
5c4e30ca DC |
4443 | |
4444 | if (is_anonymous) | |
38d518c9 EZ |
4445 | cp_add_using_directive (processing_current_prefix, |
4446 | strlen (previous_prefix), | |
4447 | strlen (processing_current_prefix)); | |
5c4e30ca | 4448 | } |
9219021c | 4449 | |
639d11d3 | 4450 | if (die->child != NULL) |
d9fa45fe | 4451 | { |
639d11d3 | 4452 | struct die_info *child_die = die->child; |
d9fa45fe DC |
4453 | |
4454 | while (child_die && child_die->tag) | |
4455 | { | |
e7c27a73 | 4456 | process_die (child_die, cu); |
d9fa45fe DC |
4457 | child_die = sibling_die (child_die); |
4458 | } | |
4459 | } | |
9219021c | 4460 | |
38d518c9 | 4461 | processing_current_prefix = previous_prefix; |
987504bb | 4462 | do_cleanups (back_to); |
38d518c9 EZ |
4463 | } |
4464 | ||
4465 | /* Return the name of the namespace represented by DIE. Set | |
4466 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
4467 | namespace. */ | |
4468 | ||
4469 | static const char * | |
e142c38c | 4470 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
4471 | { |
4472 | struct die_info *current_die; | |
4473 | const char *name = NULL; | |
4474 | ||
4475 | /* Loop through the extensions until we find a name. */ | |
4476 | ||
4477 | for (current_die = die; | |
4478 | current_die != NULL; | |
e142c38c | 4479 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 4480 | { |
e142c38c | 4481 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
4482 | if (name != NULL) |
4483 | break; | |
4484 | } | |
4485 | ||
4486 | /* Is it an anonymous namespace? */ | |
4487 | ||
4488 | *is_anonymous = (name == NULL); | |
4489 | if (*is_anonymous) | |
4490 | name = "(anonymous namespace)"; | |
4491 | ||
4492 | return name; | |
d9fa45fe DC |
4493 | } |
4494 | ||
c906108c SS |
4495 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
4496 | the user defined type vector. */ | |
4497 | ||
4498 | static void | |
e7c27a73 | 4499 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4500 | { |
e7c27a73 | 4501 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 4502 | struct type *type; |
8b2dbe47 KB |
4503 | struct attribute *attr_byte_size; |
4504 | struct attribute *attr_address_class; | |
4505 | int byte_size, addr_class; | |
c906108c SS |
4506 | |
4507 | if (die->type) | |
4508 | { | |
4509 | return; | |
4510 | } | |
4511 | ||
e7c27a73 | 4512 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 4513 | |
e142c38c | 4514 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
4515 | if (attr_byte_size) |
4516 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 4517 | else |
8b2dbe47 KB |
4518 | byte_size = cu_header->addr_size; |
4519 | ||
e142c38c | 4520 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
4521 | if (attr_address_class) |
4522 | addr_class = DW_UNSND (attr_address_class); | |
4523 | else | |
4524 | addr_class = DW_ADDR_none; | |
4525 | ||
4526 | /* If the pointer size or address class is different than the | |
4527 | default, create a type variant marked as such and set the | |
4528 | length accordingly. */ | |
4529 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 4530 | { |
8b2dbe47 KB |
4531 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()) |
4532 | { | |
4533 | int type_flags; | |
4534 | ||
4535 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); | |
4536 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); | |
4537 | type = make_type_with_address_space (type, type_flags); | |
4538 | } | |
4539 | else if (TYPE_LENGTH (type) != byte_size) | |
4540 | { | |
e2e0b3e5 | 4541 | complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); |
8b2dbe47 KB |
4542 | } |
4543 | else { | |
4544 | /* Should we also complain about unhandled address classes? */ | |
4545 | } | |
c906108c | 4546 | } |
8b2dbe47 KB |
4547 | |
4548 | TYPE_LENGTH (type) = byte_size; | |
1c379e20 | 4549 | set_die_type (die, type, cu); |
c906108c SS |
4550 | } |
4551 | ||
4552 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
4553 | the user defined type vector. */ | |
4554 | ||
4555 | static void | |
e7c27a73 | 4556 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4557 | { |
e7c27a73 | 4558 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4559 | struct type *type; |
4560 | struct type *to_type; | |
4561 | struct type *domain; | |
4562 | ||
4563 | if (die->type) | |
4564 | { | |
4565 | return; | |
4566 | } | |
4567 | ||
e7c27a73 DJ |
4568 | to_type = die_type (die, cu); |
4569 | domain = die_containing_type (die, cu); | |
0d5de010 DJ |
4570 | |
4571 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) | |
4572 | type = lookup_methodptr_type (to_type); | |
4573 | else | |
4574 | type = lookup_memberptr_type (to_type, domain); | |
c906108c | 4575 | |
1c379e20 | 4576 | set_die_type (die, type, cu); |
c906108c SS |
4577 | } |
4578 | ||
4579 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
4580 | the user defined type vector. */ | |
4581 | ||
4582 | static void | |
e7c27a73 | 4583 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4584 | { |
e7c27a73 | 4585 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4586 | struct type *type; |
4587 | struct attribute *attr; | |
4588 | ||
4589 | if (die->type) | |
4590 | { | |
4591 | return; | |
4592 | } | |
4593 | ||
e7c27a73 | 4594 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 4595 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4596 | if (attr) |
4597 | { | |
4598 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
4599 | } | |
4600 | else | |
4601 | { | |
107d2387 | 4602 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c | 4603 | } |
1c379e20 | 4604 | set_die_type (die, type, cu); |
c906108c SS |
4605 | } |
4606 | ||
4607 | static void | |
e7c27a73 | 4608 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4609 | { |
090c42a4 JB |
4610 | struct type *base_type; |
4611 | ||
c906108c SS |
4612 | if (die->type) |
4613 | { | |
4614 | return; | |
4615 | } | |
4616 | ||
e7c27a73 | 4617 | base_type = die_type (die, cu); |
1c379e20 DJ |
4618 | set_die_type (die, make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0), |
4619 | cu); | |
c906108c SS |
4620 | } |
4621 | ||
4622 | static void | |
e7c27a73 | 4623 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4624 | { |
090c42a4 JB |
4625 | struct type *base_type; |
4626 | ||
c906108c SS |
4627 | if (die->type) |
4628 | { | |
4629 | return; | |
4630 | } | |
4631 | ||
e7c27a73 | 4632 | base_type = die_type (die, cu); |
1c379e20 DJ |
4633 | set_die_type (die, make_cv_type (TYPE_CONST (base_type), 1, base_type, 0), |
4634 | cu); | |
c906108c SS |
4635 | } |
4636 | ||
4637 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4638 | the user defined type vector. It isn't really a user defined type, | |
4639 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4640 | attribute to reference it. */ | |
4641 | ||
4642 | static void | |
e7c27a73 | 4643 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4644 | { |
e7c27a73 | 4645 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4646 | struct type *type, *range_type, *index_type, *char_type; |
4647 | struct attribute *attr; | |
4648 | unsigned int length; | |
4649 | ||
4650 | if (die->type) | |
4651 | { | |
4652 | return; | |
4653 | } | |
4654 | ||
e142c38c | 4655 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4656 | if (attr) |
4657 | { | |
4658 | length = DW_UNSND (attr); | |
4659 | } | |
4660 | else | |
4661 | { | |
b21b22e0 | 4662 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4663 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4664 | if (attr) |
4665 | { | |
4666 | length = DW_UNSND (attr); | |
4667 | } | |
4668 | else | |
4669 | { | |
4670 | length = 1; | |
4671 | } | |
c906108c | 4672 | } |
e142c38c | 4673 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c | 4674 | range_type = create_range_type (NULL, index_type, 1, length); |
e142c38c | 4675 | if (cu->language == language_fortran) |
b21b22e0 PS |
4676 | { |
4677 | /* Need to create a unique string type for bounds | |
4678 | information */ | |
4679 | type = create_string_type (0, range_type); | |
4680 | } | |
4681 | else | |
4682 | { | |
e142c38c | 4683 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); |
b21b22e0 PS |
4684 | type = create_string_type (char_type, range_type); |
4685 | } | |
1c379e20 | 4686 | set_die_type (die, type, cu); |
c906108c SS |
4687 | } |
4688 | ||
4689 | /* Handle DIES due to C code like: | |
4690 | ||
4691 | struct foo | |
c5aa993b JM |
4692 | { |
4693 | int (*funcp)(int a, long l); | |
4694 | int b; | |
4695 | }; | |
c906108c SS |
4696 | |
4697 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4698 | */ |
c906108c SS |
4699 | |
4700 | static void | |
e7c27a73 | 4701 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4702 | { |
4703 | struct type *type; /* Type that this function returns */ | |
4704 | struct type *ftype; /* Function that returns above type */ | |
4705 | struct attribute *attr; | |
4706 | ||
4707 | /* Decode the type that this subroutine returns */ | |
4708 | if (die->type) | |
4709 | { | |
4710 | return; | |
4711 | } | |
e7c27a73 | 4712 | type = die_type (die, cu); |
1326e61b | 4713 | ftype = make_function_type (type, (struct type **) 0); |
c906108c | 4714 | |
987504bb | 4715 | /* All functions in C++ and Java have prototypes. */ |
e142c38c | 4716 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4717 | if ((attr && (DW_UNSND (attr) != 0)) |
987504bb JJ |
4718 | || cu->language == language_cplus |
4719 | || cu->language == language_java) | |
c906108c SS |
4720 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4721 | ||
639d11d3 | 4722 | if (die->child != NULL) |
c906108c SS |
4723 | { |
4724 | struct die_info *child_die; | |
4725 | int nparams = 0; | |
4726 | int iparams = 0; | |
4727 | ||
4728 | /* Count the number of parameters. | |
4729 | FIXME: GDB currently ignores vararg functions, but knows about | |
4730 | vararg member functions. */ | |
639d11d3 | 4731 | child_die = die->child; |
c906108c SS |
4732 | while (child_die && child_die->tag) |
4733 | { | |
4734 | if (child_die->tag == DW_TAG_formal_parameter) | |
4735 | nparams++; | |
4736 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4737 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4738 | child_die = sibling_die (child_die); | |
4739 | } | |
4740 | ||
4741 | /* Allocate storage for parameters and fill them in. */ | |
4742 | TYPE_NFIELDS (ftype) = nparams; | |
4743 | TYPE_FIELDS (ftype) = (struct field *) | |
ae5a43e0 | 4744 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
c906108c | 4745 | |
639d11d3 | 4746 | child_die = die->child; |
c906108c SS |
4747 | while (child_die && child_die->tag) |
4748 | { | |
4749 | if (child_die->tag == DW_TAG_formal_parameter) | |
4750 | { | |
4751 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4752 | member functions. G++ helps GDB by marking the first |
4753 | parameter for non-static member functions (which is the | |
4754 | this pointer) as artificial. We pass this information | |
4755 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4756 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4757 | if (attr) |
4758 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4759 | else | |
4760 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4761 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4762 | iparams++; |
4763 | } | |
4764 | child_die = sibling_die (child_die); | |
4765 | } | |
4766 | } | |
4767 | ||
1c379e20 | 4768 | set_die_type (die, ftype, cu); |
c906108c SS |
4769 | } |
4770 | ||
4771 | static void | |
e7c27a73 | 4772 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4773 | { |
e7c27a73 | 4774 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4775 | struct attribute *attr; |
4776 | char *name = NULL; | |
c906108c SS |
4777 | |
4778 | if (!die->type) | |
4779 | { | |
e142c38c | 4780 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c | 4781 | if (attr && DW_STRING (attr)) |
2f038fcb FF |
4782 | { |
4783 | name = DW_STRING (attr); | |
4784 | } | |
1c379e20 DJ |
4785 | set_die_type (die, init_type (TYPE_CODE_TYPEDEF, 0, |
4786 | TYPE_FLAG_TARGET_STUB, name, objfile), | |
4787 | cu); | |
e7c27a73 | 4788 | TYPE_TARGET_TYPE (die->type) = die_type (die, cu); |
c906108c SS |
4789 | } |
4790 | } | |
4791 | ||
4792 | /* Find a representation of a given base type and install | |
4793 | it in the TYPE field of the die. */ | |
4794 | ||
4795 | static void | |
e7c27a73 | 4796 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4797 | { |
e7c27a73 | 4798 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4799 | struct type *type; |
4800 | struct attribute *attr; | |
4801 | int encoding = 0, size = 0; | |
4802 | ||
4803 | /* If we've already decoded this die, this is a no-op. */ | |
4804 | if (die->type) | |
4805 | { | |
4806 | return; | |
4807 | } | |
4808 | ||
e142c38c | 4809 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4810 | if (attr) |
4811 | { | |
4812 | encoding = DW_UNSND (attr); | |
4813 | } | |
e142c38c | 4814 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4815 | if (attr) |
4816 | { | |
4817 | size = DW_UNSND (attr); | |
4818 | } | |
e142c38c | 4819 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
4820 | if (attr && DW_STRING (attr)) |
4821 | { | |
4822 | enum type_code code = TYPE_CODE_INT; | |
f5ef7c67 | 4823 | int type_flags = 0; |
c906108c SS |
4824 | |
4825 | switch (encoding) | |
4826 | { | |
4827 | case DW_ATE_address: | |
4828 | /* Turn DW_ATE_address into a void * pointer. */ | |
4829 | code = TYPE_CODE_PTR; | |
f5ef7c67 | 4830 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4831 | break; |
4832 | case DW_ATE_boolean: | |
4833 | code = TYPE_CODE_BOOL; | |
f5ef7c67 | 4834 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4835 | break; |
4836 | case DW_ATE_complex_float: | |
4837 | code = TYPE_CODE_COMPLEX; | |
4838 | break; | |
4839 | case DW_ATE_float: | |
4840 | code = TYPE_CODE_FLT; | |
4841 | break; | |
4842 | case DW_ATE_signed: | |
c906108c SS |
4843 | break; |
4844 | case DW_ATE_unsigned: | |
72019c9c GM |
4845 | type_flags |= TYPE_FLAG_UNSIGNED; |
4846 | break; | |
4847 | case DW_ATE_signed_char: | |
4848 | if (cu->language == language_m2) | |
4849 | code = TYPE_CODE_CHAR; | |
4850 | break; | |
4851 | case DW_ATE_unsigned_char: | |
4852 | if (cu->language == language_m2) | |
4853 | code = TYPE_CODE_CHAR; | |
f5ef7c67 | 4854 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4855 | break; |
4856 | default: | |
e2e0b3e5 | 4857 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), |
4d3c2250 | 4858 | dwarf_type_encoding_name (encoding)); |
c906108c SS |
4859 | break; |
4860 | } | |
f5ef7c67 | 4861 | type = init_type (code, size, type_flags, DW_STRING (attr), objfile); |
c906108c | 4862 | if (encoding == DW_ATE_address) |
e142c38c DJ |
4863 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, |
4864 | cu); | |
f65ca430 DJ |
4865 | else if (encoding == DW_ATE_complex_float) |
4866 | { | |
4867 | if (size == 32) | |
4868 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4869 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); |
f65ca430 DJ |
4870 | else if (size == 16) |
4871 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4872 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
f65ca430 DJ |
4873 | else if (size == 8) |
4874 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4875 | = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
f65ca430 | 4876 | } |
c906108c SS |
4877 | } |
4878 | else | |
4879 | { | |
e7c27a73 | 4880 | type = dwarf_base_type (encoding, size, cu); |
c906108c | 4881 | } |
1c379e20 | 4882 | set_die_type (die, type, cu); |
c906108c SS |
4883 | } |
4884 | ||
a02abb62 JB |
4885 | /* Read the given DW_AT_subrange DIE. */ |
4886 | ||
4887 | static void | |
4888 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) | |
4889 | { | |
4890 | struct type *base_type; | |
4891 | struct type *range_type; | |
4892 | struct attribute *attr; | |
4893 | int low = 0; | |
4894 | int high = -1; | |
4895 | ||
4896 | /* If we have already decoded this die, then nothing more to do. */ | |
4897 | if (die->type) | |
4898 | return; | |
4899 | ||
4900 | base_type = die_type (die, cu); | |
4901 | if (base_type == NULL) | |
4902 | { | |
4903 | complaint (&symfile_complaints, | |
e2e0b3e5 | 4904 | _("DW_AT_type missing from DW_TAG_subrange_type")); |
a02abb62 JB |
4905 | return; |
4906 | } | |
4907 | ||
4908 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
4909 | base_type = alloc_type (NULL); | |
4910 | ||
e142c38c | 4911 | if (cu->language == language_fortran) |
a02abb62 JB |
4912 | { |
4913 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
4914 | low = 1; | |
4915 | } | |
4916 | ||
dd5e6932 DJ |
4917 | /* FIXME: For variable sized arrays either of these could be |
4918 | a variable rather than a constant value. We'll allow it, | |
4919 | but we don't know how to handle it. */ | |
e142c38c | 4920 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
4921 | if (attr) |
4922 | low = dwarf2_get_attr_constant_value (attr, 0); | |
4923 | ||
e142c38c | 4924 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
4925 | if (attr) |
4926 | { | |
4927 | if (attr->form == DW_FORM_block1) | |
4928 | { | |
4929 | /* GCC encodes arrays with unspecified or dynamic length | |
4930 | with a DW_FORM_block1 attribute. | |
4931 | FIXME: GDB does not yet know how to handle dynamic | |
4932 | arrays properly, treat them as arrays with unspecified | |
4933 | length for now. | |
4934 | ||
4935 | FIXME: jimb/2003-09-22: GDB does not really know | |
4936 | how to handle arrays of unspecified length | |
4937 | either; we just represent them as zero-length | |
4938 | arrays. Choose an appropriate upper bound given | |
4939 | the lower bound we've computed above. */ | |
4940 | high = low - 1; | |
4941 | } | |
4942 | else | |
4943 | high = dwarf2_get_attr_constant_value (attr, 1); | |
4944 | } | |
4945 | ||
4946 | range_type = create_range_type (NULL, base_type, low, high); | |
4947 | ||
e142c38c | 4948 | attr = dwarf2_attr (die, DW_AT_name, cu); |
a02abb62 JB |
4949 | if (attr && DW_STRING (attr)) |
4950 | TYPE_NAME (range_type) = DW_STRING (attr); | |
4951 | ||
e142c38c | 4952 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
4953 | if (attr) |
4954 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
4955 | ||
1c379e20 | 4956 | set_die_type (die, range_type, cu); |
a02abb62 JB |
4957 | } |
4958 | ||
81a17f79 JB |
4959 | static void |
4960 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) | |
4961 | { | |
4962 | struct type *type; | |
4963 | struct attribute *attr; | |
4964 | ||
4965 | if (die->type) | |
4966 | return; | |
4967 | ||
4968 | /* For now, we only support the C meaning of an unspecified type: void. */ | |
4969 | ||
4970 | attr = dwarf2_attr (die, DW_AT_name, cu); | |
4971 | type = init_type (TYPE_CODE_VOID, 0, 0, attr ? DW_STRING (attr) : "", | |
4972 | cu->objfile); | |
4973 | ||
4974 | set_die_type (die, type, cu); | |
4975 | } | |
a02abb62 | 4976 | |
c906108c SS |
4977 | /* Read a whole compilation unit into a linked list of dies. */ |
4978 | ||
f9aca02d | 4979 | static struct die_info * |
fe1b8b76 | 4980 | read_comp_unit (gdb_byte *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4981 | { |
e7c27a73 | 4982 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
4983 | } |
4984 | ||
4985 | /* Read a single die and all its descendents. Set the die's sibling | |
4986 | field to NULL; set other fields in the die correctly, and set all | |
4987 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
4988 | location of the info_ptr after reading all of those dies. PARENT | |
4989 | is the parent of the die in question. */ | |
4990 | ||
4991 | static struct die_info * | |
fe1b8b76 | 4992 | read_die_and_children (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 4993 | struct dwarf2_cu *cu, |
fe1b8b76 | 4994 | gdb_byte **new_info_ptr, |
639d11d3 DC |
4995 | struct die_info *parent) |
4996 | { | |
4997 | struct die_info *die; | |
fe1b8b76 | 4998 | gdb_byte *cur_ptr; |
639d11d3 DC |
4999 | int has_children; |
5000 | ||
e7c27a73 | 5001 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
10b3939b | 5002 | store_in_ref_table (die->offset, die, cu); |
639d11d3 DC |
5003 | |
5004 | if (has_children) | |
5005 | { | |
e7c27a73 | 5006 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
5007 | new_info_ptr, die); |
5008 | } | |
5009 | else | |
5010 | { | |
5011 | die->child = NULL; | |
5012 | *new_info_ptr = cur_ptr; | |
5013 | } | |
5014 | ||
5015 | die->sibling = NULL; | |
5016 | die->parent = parent; | |
5017 | return die; | |
5018 | } | |
5019 | ||
5020 | /* Read a die, all of its descendents, and all of its siblings; set | |
5021 | all of the fields of all of the dies correctly. Arguments are as | |
5022 | in read_die_and_children. */ | |
5023 | ||
5024 | static struct die_info * | |
fe1b8b76 | 5025 | read_die_and_siblings (gdb_byte *info_ptr, bfd *abfd, |
e7c27a73 | 5026 | struct dwarf2_cu *cu, |
fe1b8b76 | 5027 | gdb_byte **new_info_ptr, |
639d11d3 DC |
5028 | struct die_info *parent) |
5029 | { | |
5030 | struct die_info *first_die, *last_sibling; | |
fe1b8b76 | 5031 | gdb_byte *cur_ptr; |
639d11d3 | 5032 | |
c906108c | 5033 | cur_ptr = info_ptr; |
639d11d3 DC |
5034 | first_die = last_sibling = NULL; |
5035 | ||
5036 | while (1) | |
c906108c | 5037 | { |
639d11d3 | 5038 | struct die_info *die |
e7c27a73 | 5039 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
5040 | |
5041 | if (!first_die) | |
c906108c | 5042 | { |
639d11d3 | 5043 | first_die = die; |
c906108c | 5044 | } |
639d11d3 | 5045 | else |
c906108c | 5046 | { |
639d11d3 | 5047 | last_sibling->sibling = die; |
c906108c SS |
5048 | } |
5049 | ||
639d11d3 | 5050 | if (die->tag == 0) |
c906108c | 5051 | { |
639d11d3 DC |
5052 | *new_info_ptr = cur_ptr; |
5053 | return first_die; | |
c906108c SS |
5054 | } |
5055 | else | |
5056 | { | |
639d11d3 | 5057 | last_sibling = die; |
c906108c SS |
5058 | } |
5059 | } | |
c906108c SS |
5060 | } |
5061 | ||
5062 | /* Free a linked list of dies. */ | |
5063 | ||
5064 | static void | |
fba45db2 | 5065 | free_die_list (struct die_info *dies) |
c906108c SS |
5066 | { |
5067 | struct die_info *die, *next; | |
5068 | ||
5069 | die = dies; | |
5070 | while (die) | |
5071 | { | |
639d11d3 DC |
5072 | if (die->child != NULL) |
5073 | free_die_list (die->child); | |
5074 | next = die->sibling; | |
b8c9b27d KB |
5075 | xfree (die->attrs); |
5076 | xfree (die); | |
c906108c SS |
5077 | die = next; |
5078 | } | |
5079 | } | |
5080 | ||
5081 | /* Read the contents of the section at OFFSET and of size SIZE from the | |
8b92e4d5 | 5082 | object file specified by OBJFILE into the objfile_obstack and return it. */ |
c906108c | 5083 | |
fe1b8b76 | 5084 | gdb_byte * |
188dd5d6 | 5085 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
5086 | { |
5087 | bfd *abfd = objfile->obfd; | |
fe1b8b76 | 5088 | gdb_byte *buf, *retbuf; |
2c500098 | 5089 | bfd_size_type size = bfd_get_section_size (sectp); |
c906108c SS |
5090 | |
5091 | if (size == 0) | |
5092 | return NULL; | |
5093 | ||
fe1b8b76 JB |
5094 | buf = obstack_alloc (&objfile->objfile_obstack, size); |
5095 | retbuf = symfile_relocate_debug_section (abfd, sectp, buf); | |
086df311 DJ |
5096 | if (retbuf != NULL) |
5097 | return retbuf; | |
5098 | ||
188dd5d6 DJ |
5099 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
5100 | || bfd_bread (buf, size, abfd) != size) | |
8a3fe4f8 | 5101 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
188dd5d6 DJ |
5102 | bfd_get_filename (abfd)); |
5103 | ||
c906108c SS |
5104 | return buf; |
5105 | } | |
5106 | ||
5107 | /* In DWARF version 2, the description of the debugging information is | |
5108 | stored in a separate .debug_abbrev section. Before we read any | |
5109 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
5110 | in a hash table. This function also sets flags in CU describing |
5111 | the data found in the abbrev table. */ | |
c906108c SS |
5112 | |
5113 | static void | |
e7c27a73 | 5114 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 5115 | { |
e7c27a73 | 5116 | struct comp_unit_head *cu_header = &cu->header; |
fe1b8b76 | 5117 | gdb_byte *abbrev_ptr; |
c906108c SS |
5118 | struct abbrev_info *cur_abbrev; |
5119 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
5120 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
5121 | struct attr_abbrev *cur_attrs; |
5122 | unsigned int allocated_attrs; | |
c906108c | 5123 | |
57349743 | 5124 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
5125 | obstack_init (&cu->abbrev_obstack); |
5126 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
5127 | (ABBREV_HASH_SIZE | |
5128 | * sizeof (struct abbrev_info *))); | |
5129 | memset (cu->dwarf2_abbrevs, 0, | |
5130 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 5131 | |
6502dd73 | 5132 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
5133 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5134 | abbrev_ptr += bytes_read; | |
5135 | ||
f3dd6933 DJ |
5136 | allocated_attrs = ATTR_ALLOC_CHUNK; |
5137 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
5138 | ||
c906108c SS |
5139 | /* loop until we reach an abbrev number of 0 */ |
5140 | while (abbrev_number) | |
5141 | { | |
f3dd6933 | 5142 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
5143 | |
5144 | /* read in abbrev header */ | |
5145 | cur_abbrev->number = abbrev_number; | |
5146 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5147 | abbrev_ptr += bytes_read; | |
5148 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
5149 | abbrev_ptr += 1; | |
5150 | ||
72bf9492 DJ |
5151 | if (cur_abbrev->tag == DW_TAG_namespace) |
5152 | cu->has_namespace_info = 1; | |
5153 | ||
c906108c SS |
5154 | /* now read in declarations */ |
5155 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5156 | abbrev_ptr += bytes_read; | |
5157 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5158 | abbrev_ptr += bytes_read; | |
5159 | while (abbrev_name) | |
5160 | { | |
f3dd6933 | 5161 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 5162 | { |
f3dd6933 DJ |
5163 | allocated_attrs += ATTR_ALLOC_CHUNK; |
5164 | cur_attrs | |
5165 | = xrealloc (cur_attrs, (allocated_attrs | |
5166 | * sizeof (struct attr_abbrev))); | |
c906108c | 5167 | } |
ae038cb0 DJ |
5168 | |
5169 | /* Record whether this compilation unit might have | |
5170 | inter-compilation-unit references. If we don't know what form | |
5171 | this attribute will have, then it might potentially be a | |
5172 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |
5173 | references. */ | |
5174 | ||
5175 | if (abbrev_form == DW_FORM_ref_addr | |
5176 | || abbrev_form == DW_FORM_indirect) | |
5177 | cu->has_form_ref_addr = 1; | |
5178 | ||
f3dd6933 DJ |
5179 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
5180 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
5181 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
5182 | abbrev_ptr += bytes_read; | |
5183 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5184 | abbrev_ptr += bytes_read; | |
5185 | } | |
5186 | ||
f3dd6933 DJ |
5187 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
5188 | (cur_abbrev->num_attrs | |
5189 | * sizeof (struct attr_abbrev))); | |
5190 | memcpy (cur_abbrev->attrs, cur_attrs, | |
5191 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
5192 | ||
c906108c | 5193 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
5194 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
5195 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
5196 | |
5197 | /* Get next abbreviation. | |
5198 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
5199 | always properly terminated with an abbrev number of 0. |
5200 | Exit loop if we encounter an abbreviation which we have | |
5201 | already read (which means we are about to read the abbreviations | |
5202 | for the next compile unit) or if the end of the abbreviation | |
5203 | table is reached. */ | |
6502dd73 DJ |
5204 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
5205 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
5206 | break; |
5207 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
5208 | abbrev_ptr += bytes_read; | |
e7c27a73 | 5209 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
5210 | break; |
5211 | } | |
f3dd6933 DJ |
5212 | |
5213 | xfree (cur_attrs); | |
c906108c SS |
5214 | } |
5215 | ||
f3dd6933 | 5216 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 5217 | |
c906108c | 5218 | static void |
f3dd6933 | 5219 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 5220 | { |
f3dd6933 | 5221 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 5222 | |
f3dd6933 DJ |
5223 | obstack_free (&cu->abbrev_obstack, NULL); |
5224 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
5225 | } |
5226 | ||
5227 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
5228 | ||
5229 | static struct abbrev_info * | |
e7c27a73 | 5230 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
5231 | { |
5232 | unsigned int hash_number; | |
5233 | struct abbrev_info *abbrev; | |
5234 | ||
5235 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 5236 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
5237 | |
5238 | while (abbrev) | |
5239 | { | |
5240 | if (abbrev->number == number) | |
5241 | return abbrev; | |
5242 | else | |
5243 | abbrev = abbrev->next; | |
5244 | } | |
5245 | return NULL; | |
5246 | } | |
5247 | ||
72bf9492 DJ |
5248 | /* Returns nonzero if TAG represents a type that we might generate a partial |
5249 | symbol for. */ | |
5250 | ||
5251 | static int | |
5252 | is_type_tag_for_partial (int tag) | |
5253 | { | |
5254 | switch (tag) | |
5255 | { | |
5256 | #if 0 | |
5257 | /* Some types that would be reasonable to generate partial symbols for, | |
5258 | that we don't at present. */ | |
5259 | case DW_TAG_array_type: | |
5260 | case DW_TAG_file_type: | |
5261 | case DW_TAG_ptr_to_member_type: | |
5262 | case DW_TAG_set_type: | |
5263 | case DW_TAG_string_type: | |
5264 | case DW_TAG_subroutine_type: | |
5265 | #endif | |
5266 | case DW_TAG_base_type: | |
5267 | case DW_TAG_class_type: | |
5268 | case DW_TAG_enumeration_type: | |
5269 | case DW_TAG_structure_type: | |
5270 | case DW_TAG_subrange_type: | |
5271 | case DW_TAG_typedef: | |
5272 | case DW_TAG_union_type: | |
5273 | return 1; | |
5274 | default: | |
5275 | return 0; | |
5276 | } | |
5277 | } | |
5278 | ||
5279 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
5280 | ||
5281 | static struct partial_die_info * | |
fe1b8b76 | 5282 | load_partial_dies (bfd *abfd, gdb_byte *info_ptr, int building_psymtab, |
72bf9492 DJ |
5283 | struct dwarf2_cu *cu) |
5284 | { | |
5285 | struct partial_die_info *part_die; | |
5286 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
5287 | struct abbrev_info *abbrev; | |
5288 | unsigned int bytes_read; | |
5afb4e99 | 5289 | unsigned int load_all = 0; |
72bf9492 DJ |
5290 | |
5291 | int nesting_level = 1; | |
5292 | ||
5293 | parent_die = NULL; | |
5294 | last_die = NULL; | |
5295 | ||
5afb4e99 DJ |
5296 | if (cu->per_cu && cu->per_cu->load_all_dies) |
5297 | load_all = 1; | |
5298 | ||
72bf9492 DJ |
5299 | cu->partial_dies |
5300 | = htab_create_alloc_ex (cu->header.length / 12, | |
5301 | partial_die_hash, | |
5302 | partial_die_eq, | |
5303 | NULL, | |
5304 | &cu->comp_unit_obstack, | |
5305 | hashtab_obstack_allocate, | |
5306 | dummy_obstack_deallocate); | |
5307 | ||
5308 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5309 | sizeof (struct partial_die_info)); | |
5310 | ||
5311 | while (1) | |
5312 | { | |
5313 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
5314 | ||
5315 | /* A NULL abbrev means the end of a series of children. */ | |
5316 | if (abbrev == NULL) | |
5317 | { | |
5318 | if (--nesting_level == 0) | |
5319 | { | |
5320 | /* PART_DIE was probably the last thing allocated on the | |
5321 | comp_unit_obstack, so we could call obstack_free | |
5322 | here. We don't do that because the waste is small, | |
5323 | and will be cleaned up when we're done with this | |
5324 | compilation unit. This way, we're also more robust | |
5325 | against other users of the comp_unit_obstack. */ | |
5326 | return first_die; | |
5327 | } | |
5328 | info_ptr += bytes_read; | |
5329 | last_die = parent_die; | |
5330 | parent_die = parent_die->die_parent; | |
5331 | continue; | |
5332 | } | |
5333 | ||
5afb4e99 DJ |
5334 | /* Check whether this DIE is interesting enough to save. Normally |
5335 | we would not be interested in members here, but there may be | |
5336 | later variables referencing them via DW_AT_specification (for | |
5337 | static members). */ | |
5338 | if (!load_all | |
5339 | && !is_type_tag_for_partial (abbrev->tag) | |
72bf9492 DJ |
5340 | && abbrev->tag != DW_TAG_enumerator |
5341 | && abbrev->tag != DW_TAG_subprogram | |
5342 | && abbrev->tag != DW_TAG_variable | |
5afb4e99 DJ |
5343 | && abbrev->tag != DW_TAG_namespace |
5344 | && abbrev->tag != DW_TAG_member) | |
72bf9492 DJ |
5345 | { |
5346 | /* Otherwise we skip to the next sibling, if any. */ | |
5347 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
5348 | continue; | |
5349 | } | |
5350 | ||
5351 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
5352 | abfd, info_ptr, cu); | |
5353 | ||
5354 | /* This two-pass algorithm for processing partial symbols has a | |
5355 | high cost in cache pressure. Thus, handle some simple cases | |
5356 | here which cover the majority of C partial symbols. DIEs | |
5357 | which neither have specification tags in them, nor could have | |
5358 | specification tags elsewhere pointing at them, can simply be | |
5359 | processed and discarded. | |
5360 | ||
5361 | This segment is also optional; scan_partial_symbols and | |
5362 | add_partial_symbol will handle these DIEs if we chain | |
5363 | them in normally. When compilers which do not emit large | |
5364 | quantities of duplicate debug information are more common, | |
5365 | this code can probably be removed. */ | |
5366 | ||
5367 | /* Any complete simple types at the top level (pretty much all | |
5368 | of them, for a language without namespaces), can be processed | |
5369 | directly. */ | |
5370 | if (parent_die == NULL | |
5371 | && part_die->has_specification == 0 | |
5372 | && part_die->is_declaration == 0 | |
5373 | && (part_die->tag == DW_TAG_typedef | |
5374 | || part_die->tag == DW_TAG_base_type | |
5375 | || part_die->tag == DW_TAG_subrange_type)) | |
5376 | { | |
5377 | if (building_psymtab && part_die->name != NULL) | |
5378 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5379 | VAR_DOMAIN, LOC_TYPEDEF, | |
5380 | &cu->objfile->static_psymbols, | |
5381 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5382 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5383 | continue; | |
5384 | } | |
5385 | ||
5386 | /* If we're at the second level, and we're an enumerator, and | |
5387 | our parent has no specification (meaning possibly lives in a | |
5388 | namespace elsewhere), then we can add the partial symbol now | |
5389 | instead of queueing it. */ | |
5390 | if (part_die->tag == DW_TAG_enumerator | |
5391 | && parent_die != NULL | |
5392 | && parent_die->die_parent == NULL | |
5393 | && parent_die->tag == DW_TAG_enumeration_type | |
5394 | && parent_die->has_specification == 0) | |
5395 | { | |
5396 | if (part_die->name == NULL) | |
e2e0b3e5 | 5397 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
72bf9492 DJ |
5398 | else if (building_psymtab) |
5399 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
5400 | VAR_DOMAIN, LOC_CONST, | |
987504bb JJ |
5401 | (cu->language == language_cplus |
5402 | || cu->language == language_java) | |
72bf9492 DJ |
5403 | ? &cu->objfile->global_psymbols |
5404 | : &cu->objfile->static_psymbols, | |
5405 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
5406 | ||
5407 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
5408 | continue; | |
5409 | } | |
5410 | ||
5411 | /* We'll save this DIE so link it in. */ | |
5412 | part_die->die_parent = parent_die; | |
5413 | part_die->die_sibling = NULL; | |
5414 | part_die->die_child = NULL; | |
5415 | ||
5416 | if (last_die && last_die == parent_die) | |
5417 | last_die->die_child = part_die; | |
5418 | else if (last_die) | |
5419 | last_die->die_sibling = part_die; | |
5420 | ||
5421 | last_die = part_die; | |
5422 | ||
5423 | if (first_die == NULL) | |
5424 | first_die = part_die; | |
5425 | ||
5426 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
5427 | find interesting need to be in the hash table, because we | |
5428 | also have the parent/sibling/child chains; only those that we | |
5429 | might refer to by offset later during partial symbol reading. | |
5430 | ||
5431 | For now this means things that might have be the target of a | |
5432 | DW_AT_specification, DW_AT_abstract_origin, or | |
5433 | DW_AT_extension. DW_AT_extension will refer only to | |
5434 | namespaces; DW_AT_abstract_origin refers to functions (and | |
5435 | many things under the function DIE, but we do not recurse | |
5436 | into function DIEs during partial symbol reading) and | |
5437 | possibly variables as well; DW_AT_specification refers to | |
5438 | declarations. Declarations ought to have the DW_AT_declaration | |
5439 | flag. It happens that GCC forgets to put it in sometimes, but | |
5440 | only for functions, not for types. | |
5441 | ||
5442 | Adding more things than necessary to the hash table is harmless | |
5443 | except for the performance cost. Adding too few will result in | |
5afb4e99 DJ |
5444 | wasted time in find_partial_die, when we reread the compilation |
5445 | unit with load_all_dies set. */ | |
72bf9492 | 5446 | |
5afb4e99 DJ |
5447 | if (load_all |
5448 | || abbrev->tag == DW_TAG_subprogram | |
72bf9492 DJ |
5449 | || abbrev->tag == DW_TAG_variable |
5450 | || abbrev->tag == DW_TAG_namespace | |
5451 | || part_die->is_declaration) | |
5452 | { | |
5453 | void **slot; | |
5454 | ||
5455 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
5456 | part_die->offset, INSERT); | |
5457 | *slot = part_die; | |
5458 | } | |
5459 | ||
5460 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
5461 | sizeof (struct partial_die_info)); | |
5462 | ||
5463 | /* For some DIEs we want to follow their children (if any). For C | |
5464 | we have no reason to follow the children of structures; for other | |
5465 | languages we have to, both so that we can get at method physnames | |
5466 | to infer fully qualified class names, and for DW_AT_specification. */ | |
5467 | if (last_die->has_children | |
5afb4e99 DJ |
5468 | && (load_all |
5469 | || last_die->tag == DW_TAG_namespace | |
72bf9492 DJ |
5470 | || last_die->tag == DW_TAG_enumeration_type |
5471 | || (cu->language != language_c | |
5472 | && (last_die->tag == DW_TAG_class_type | |
5473 | || last_die->tag == DW_TAG_structure_type | |
5474 | || last_die->tag == DW_TAG_union_type)))) | |
5475 | { | |
5476 | nesting_level++; | |
5477 | parent_die = last_die; | |
5478 | continue; | |
5479 | } | |
5480 | ||
5481 | /* Otherwise we skip to the next sibling, if any. */ | |
5482 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
5483 | ||
5484 | /* Back to the top, do it again. */ | |
5485 | } | |
5486 | } | |
5487 | ||
c906108c SS |
5488 | /* Read a minimal amount of information into the minimal die structure. */ |
5489 | ||
fe1b8b76 | 5490 | static gdb_byte * |
72bf9492 DJ |
5491 | read_partial_die (struct partial_die_info *part_die, |
5492 | struct abbrev_info *abbrev, | |
5493 | unsigned int abbrev_len, bfd *abfd, | |
fe1b8b76 | 5494 | gdb_byte *info_ptr, struct dwarf2_cu *cu) |
c906108c | 5495 | { |
72bf9492 | 5496 | unsigned int bytes_read, i; |
c906108c | 5497 | struct attribute attr; |
c5aa993b | 5498 | int has_low_pc_attr = 0; |
c906108c SS |
5499 | int has_high_pc_attr = 0; |
5500 | ||
72bf9492 | 5501 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 5502 | |
6502dd73 | 5503 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
5504 | |
5505 | info_ptr += abbrev_len; | |
5506 | ||
5507 | if (abbrev == NULL) | |
5508 | return info_ptr; | |
5509 | ||
c906108c SS |
5510 | part_die->tag = abbrev->tag; |
5511 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
5512 | |
5513 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5514 | { | |
e7c27a73 | 5515 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
5516 | |
5517 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 5518 | partial symbol table. */ |
c906108c SS |
5519 | switch (attr.name) |
5520 | { | |
5521 | case DW_AT_name: | |
5522 | ||
5523 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
5524 | if (part_die->name == NULL) | |
5525 | part_die->name = DW_STRING (&attr); | |
5526 | break; | |
57c22c6c BR |
5527 | case DW_AT_comp_dir: |
5528 | if (part_die->dirname == NULL) | |
5529 | part_die->dirname = DW_STRING (&attr); | |
5530 | break; | |
c906108c SS |
5531 | case DW_AT_MIPS_linkage_name: |
5532 | part_die->name = DW_STRING (&attr); | |
5533 | break; | |
5534 | case DW_AT_low_pc: | |
5535 | has_low_pc_attr = 1; | |
5536 | part_die->lowpc = DW_ADDR (&attr); | |
5537 | break; | |
5538 | case DW_AT_high_pc: | |
5539 | has_high_pc_attr = 1; | |
5540 | part_die->highpc = DW_ADDR (&attr); | |
5541 | break; | |
5542 | case DW_AT_location: | |
8e19ed76 PS |
5543 | /* Support the .debug_loc offsets */ |
5544 | if (attr_form_is_block (&attr)) | |
5545 | { | |
5546 | part_die->locdesc = DW_BLOCK (&attr); | |
5547 | } | |
5548 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) | |
5549 | { | |
4d3c2250 | 5550 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
5551 | } |
5552 | else | |
5553 | { | |
4d3c2250 KB |
5554 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
5555 | "partial symbol information"); | |
8e19ed76 | 5556 | } |
c906108c SS |
5557 | break; |
5558 | case DW_AT_language: | |
5559 | part_die->language = DW_UNSND (&attr); | |
5560 | break; | |
5561 | case DW_AT_external: | |
5562 | part_die->is_external = DW_UNSND (&attr); | |
5563 | break; | |
5564 | case DW_AT_declaration: | |
5565 | part_die->is_declaration = DW_UNSND (&attr); | |
5566 | break; | |
5567 | case DW_AT_type: | |
5568 | part_die->has_type = 1; | |
5569 | break; | |
5570 | case DW_AT_abstract_origin: | |
5571 | case DW_AT_specification: | |
72bf9492 DJ |
5572 | case DW_AT_extension: |
5573 | part_die->has_specification = 1; | |
5574 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
5575 | break; |
5576 | case DW_AT_sibling: | |
5577 | /* Ignore absolute siblings, they might point outside of | |
5578 | the current compile unit. */ | |
5579 | if (attr.form == DW_FORM_ref_addr) | |
e2e0b3e5 | 5580 | complaint (&symfile_complaints, _("ignoring absolute DW_AT_sibling")); |
c906108c | 5581 | else |
6502dd73 DJ |
5582 | part_die->sibling = dwarf2_per_objfile->info_buffer |
5583 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 5584 | break; |
aaa75496 JB |
5585 | case DW_AT_stmt_list: |
5586 | part_die->has_stmt_list = 1; | |
5587 | part_die->line_offset = DW_UNSND (&attr); | |
5588 | break; | |
fa4028e9 JB |
5589 | case DW_AT_byte_size: |
5590 | part_die->has_byte_size = 1; | |
5591 | break; | |
c906108c SS |
5592 | default: |
5593 | break; | |
5594 | } | |
5595 | } | |
5596 | ||
c906108c SS |
5597 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
5598 | eliminate duplicate copies of functions and vtables and such. | |
5599 | The linker will arbitrarily choose one and discard the others. | |
5600 | The AT_*_pc values for such functions refer to local labels in | |
5601 | these sections. If the section from that file was discarded, the | |
5602 | labels are not in the output, so the relocs get a value of 0. | |
5603 | If this is a discarded function, mark the pc bounds as invalid, | |
5604 | so that GDB will ignore it. */ | |
5605 | if (has_low_pc_attr && has_high_pc_attr | |
5606 | && part_die->lowpc < part_die->highpc | |
5607 | && (part_die->lowpc != 0 | |
72dca2f5 | 5608 | || dwarf2_per_objfile->has_section_at_zero)) |
0b010bcc | 5609 | part_die->has_pc_info = 1; |
c906108c SS |
5610 | return info_ptr; |
5611 | } | |
5612 | ||
72bf9492 DJ |
5613 | /* Find a cached partial DIE at OFFSET in CU. */ |
5614 | ||
5615 | static struct partial_die_info * | |
5616 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
5617 | { | |
5618 | struct partial_die_info *lookup_die = NULL; | |
5619 | struct partial_die_info part_die; | |
5620 | ||
5621 | part_die.offset = offset; | |
5622 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
5623 | ||
72bf9492 DJ |
5624 | return lookup_die; |
5625 | } | |
5626 | ||
5627 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
5628 | ||
5629 | static struct partial_die_info * | |
10b3939b | 5630 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu) |
72bf9492 | 5631 | { |
5afb4e99 DJ |
5632 | struct dwarf2_per_cu_data *per_cu = NULL; |
5633 | struct partial_die_info *pd = NULL; | |
72bf9492 DJ |
5634 | |
5635 | if (offset >= cu->header.offset | |
5636 | && offset < cu->header.offset + cu->header.length) | |
5afb4e99 DJ |
5637 | { |
5638 | pd = find_partial_die_in_comp_unit (offset, cu); | |
5639 | if (pd != NULL) | |
5640 | return pd; | |
5641 | } | |
72bf9492 | 5642 | |
ae038cb0 DJ |
5643 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
5644 | ||
ae038cb0 DJ |
5645 | if (per_cu->cu == NULL) |
5646 | { | |
5647 | load_comp_unit (per_cu, cu->objfile); | |
5648 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |
5649 | dwarf2_per_objfile->read_in_chain = per_cu; | |
5650 | } | |
5651 | ||
5652 | per_cu->cu->last_used = 0; | |
5afb4e99 DJ |
5653 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
5654 | ||
5655 | if (pd == NULL && per_cu->load_all_dies == 0) | |
5656 | { | |
5657 | struct cleanup *back_to; | |
5658 | struct partial_die_info comp_unit_die; | |
5659 | struct abbrev_info *abbrev; | |
5660 | unsigned int bytes_read; | |
5661 | char *info_ptr; | |
5662 | ||
5663 | per_cu->load_all_dies = 1; | |
5664 | ||
5665 | /* Re-read the DIEs. */ | |
5666 | back_to = make_cleanup (null_cleanup, 0); | |
5667 | if (per_cu->cu->dwarf2_abbrevs == NULL) | |
5668 | { | |
5669 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); | |
5670 | back_to = make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); | |
5671 | } | |
5672 | info_ptr = per_cu->cu->header.first_die_ptr; | |
5673 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); | |
5674 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
5675 | per_cu->cu->objfile->obfd, info_ptr, | |
5676 | per_cu->cu); | |
5677 | if (comp_unit_die.has_children) | |
5678 | load_partial_dies (per_cu->cu->objfile->obfd, info_ptr, 0, per_cu->cu); | |
5679 | do_cleanups (back_to); | |
5680 | ||
5681 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); | |
5682 | } | |
5683 | ||
5684 | if (pd == NULL) | |
5685 | internal_error (__FILE__, __LINE__, | |
5686 | _("could not find partial DIE 0x%lx in cache [from module %s]\n"), | |
5687 | offset, bfd_get_filename (cu->objfile->obfd)); | |
5688 | return pd; | |
72bf9492 DJ |
5689 | } |
5690 | ||
5691 | /* Adjust PART_DIE before generating a symbol for it. This function | |
5692 | may set the is_external flag or change the DIE's name. */ | |
5693 | ||
5694 | static void | |
5695 | fixup_partial_die (struct partial_die_info *part_die, | |
5696 | struct dwarf2_cu *cu) | |
5697 | { | |
5698 | /* If we found a reference attribute and the DIE has no name, try | |
5699 | to find a name in the referred to DIE. */ | |
5700 | ||
5701 | if (part_die->name == NULL && part_die->has_specification) | |
5702 | { | |
5703 | struct partial_die_info *spec_die; | |
72bf9492 | 5704 | |
10b3939b | 5705 | spec_die = find_partial_die (part_die->spec_offset, cu); |
72bf9492 | 5706 | |
10b3939b | 5707 | fixup_partial_die (spec_die, cu); |
72bf9492 DJ |
5708 | |
5709 | if (spec_die->name) | |
5710 | { | |
5711 | part_die->name = spec_die->name; | |
5712 | ||
5713 | /* Copy DW_AT_external attribute if it is set. */ | |
5714 | if (spec_die->is_external) | |
5715 | part_die->is_external = spec_die->is_external; | |
5716 | } | |
5717 | } | |
5718 | ||
5719 | /* Set default names for some unnamed DIEs. */ | |
5720 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
5721 | || part_die->tag == DW_TAG_class_type)) | |
5722 | part_die->name = "(anonymous class)"; | |
5723 | ||
5724 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
5725 | part_die->name = "(anonymous namespace)"; | |
5726 | ||
5727 | if (part_die->tag == DW_TAG_structure_type | |
5728 | || part_die->tag == DW_TAG_class_type | |
5729 | || part_die->tag == DW_TAG_union_type) | |
5730 | guess_structure_name (part_die, cu); | |
5731 | } | |
5732 | ||
639d11d3 DC |
5733 | /* Read the die from the .debug_info section buffer. Set DIEP to |
5734 | point to a newly allocated die with its information, except for its | |
5735 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
5736 | whether the die has children or not. */ | |
c906108c | 5737 | |
fe1b8b76 JB |
5738 | static gdb_byte * |
5739 | read_full_die (struct die_info **diep, bfd *abfd, gdb_byte *info_ptr, | |
e7c27a73 | 5740 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
5741 | { |
5742 | unsigned int abbrev_number, bytes_read, i, offset; | |
5743 | struct abbrev_info *abbrev; | |
5744 | struct die_info *die; | |
5745 | ||
6502dd73 | 5746 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
5747 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5748 | info_ptr += bytes_read; | |
5749 | if (!abbrev_number) | |
5750 | { | |
5751 | die = dwarf_alloc_die (); | |
5752 | die->tag = 0; | |
5753 | die->abbrev = abbrev_number; | |
5754 | die->type = NULL; | |
5755 | *diep = die; | |
639d11d3 | 5756 | *has_children = 0; |
c906108c SS |
5757 | return info_ptr; |
5758 | } | |
5759 | ||
e7c27a73 | 5760 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
5761 | if (!abbrev) |
5762 | { | |
8a3fe4f8 | 5763 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
72bf9492 | 5764 | abbrev_number, |
639d11d3 | 5765 | bfd_get_filename (abfd)); |
c906108c SS |
5766 | } |
5767 | die = dwarf_alloc_die (); | |
5768 | die->offset = offset; | |
5769 | die->tag = abbrev->tag; | |
c906108c SS |
5770 | die->abbrev = abbrev_number; |
5771 | die->type = NULL; | |
5772 | ||
5773 | die->num_attrs = abbrev->num_attrs; | |
5774 | die->attrs = (struct attribute *) | |
5775 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
5776 | ||
5777 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5778 | { | |
5779 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 5780 | abfd, info_ptr, cu); |
10b3939b DJ |
5781 | |
5782 | /* If this attribute is an absolute reference to a different | |
5783 | compilation unit, make sure that compilation unit is loaded | |
5784 | also. */ | |
5785 | if (die->attrs[i].form == DW_FORM_ref_addr | |
5786 | && (DW_ADDR (&die->attrs[i]) < cu->header.offset | |
5787 | || (DW_ADDR (&die->attrs[i]) | |
5788 | >= cu->header.offset + cu->header.length))) | |
5789 | { | |
5790 | struct dwarf2_per_cu_data *per_cu; | |
5791 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (&die->attrs[i]), | |
5792 | cu->objfile); | |
5793 | ||
5794 | /* Mark the dependence relation so that we don't flush PER_CU | |
5795 | too early. */ | |
5796 | dwarf2_add_dependence (cu, per_cu); | |
5797 | ||
5798 | /* If it's already on the queue, we have nothing to do. */ | |
5799 | if (per_cu->queued) | |
5800 | continue; | |
5801 | ||
5802 | /* If the compilation unit is already loaded, just mark it as | |
5803 | used. */ | |
5804 | if (per_cu->cu != NULL) | |
5805 | { | |
5806 | per_cu->cu->last_used = 0; | |
5807 | continue; | |
5808 | } | |
5809 | ||
5810 | /* Add it to the queue. */ | |
5811 | queue_comp_unit (per_cu); | |
5812 | } | |
c906108c SS |
5813 | } |
5814 | ||
5815 | *diep = die; | |
639d11d3 | 5816 | *has_children = abbrev->has_children; |
c906108c SS |
5817 | return info_ptr; |
5818 | } | |
5819 | ||
a8329558 | 5820 | /* Read an attribute value described by an attribute form. */ |
c906108c | 5821 | |
fe1b8b76 | 5822 | static gdb_byte * |
a8329558 | 5823 | read_attribute_value (struct attribute *attr, unsigned form, |
fe1b8b76 | 5824 | bfd *abfd, gdb_byte *info_ptr, |
e7c27a73 | 5825 | struct dwarf2_cu *cu) |
c906108c | 5826 | { |
e7c27a73 | 5827 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5828 | unsigned int bytes_read; |
5829 | struct dwarf_block *blk; | |
5830 | ||
a8329558 KW |
5831 | attr->form = form; |
5832 | switch (form) | |
c906108c SS |
5833 | { |
5834 | case DW_FORM_addr: | |
5835 | case DW_FORM_ref_addr: | |
e7c27a73 | 5836 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 5837 | info_ptr += bytes_read; |
c906108c SS |
5838 | break; |
5839 | case DW_FORM_block2: | |
7b5a2f43 | 5840 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5841 | blk->size = read_2_bytes (abfd, info_ptr); |
5842 | info_ptr += 2; | |
5843 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5844 | info_ptr += blk->size; | |
5845 | DW_BLOCK (attr) = blk; | |
5846 | break; | |
5847 | case DW_FORM_block4: | |
7b5a2f43 | 5848 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5849 | blk->size = read_4_bytes (abfd, info_ptr); |
5850 | info_ptr += 4; | |
5851 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5852 | info_ptr += blk->size; | |
5853 | DW_BLOCK (attr) = blk; | |
5854 | break; | |
5855 | case DW_FORM_data2: | |
5856 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5857 | info_ptr += 2; | |
5858 | break; | |
5859 | case DW_FORM_data4: | |
5860 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5861 | info_ptr += 4; | |
5862 | break; | |
5863 | case DW_FORM_data8: | |
5864 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5865 | info_ptr += 8; | |
5866 | break; | |
5867 | case DW_FORM_string: | |
5868 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
5869 | info_ptr += bytes_read; | |
5870 | break; | |
4bdf3d34 JJ |
5871 | case DW_FORM_strp: |
5872 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
5873 | &bytes_read); | |
5874 | info_ptr += bytes_read; | |
5875 | break; | |
c906108c | 5876 | case DW_FORM_block: |
7b5a2f43 | 5877 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5878 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5879 | info_ptr += bytes_read; | |
5880 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5881 | info_ptr += blk->size; | |
5882 | DW_BLOCK (attr) = blk; | |
5883 | break; | |
5884 | case DW_FORM_block1: | |
7b5a2f43 | 5885 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5886 | blk->size = read_1_byte (abfd, info_ptr); |
5887 | info_ptr += 1; | |
5888 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5889 | info_ptr += blk->size; | |
5890 | DW_BLOCK (attr) = blk; | |
5891 | break; | |
5892 | case DW_FORM_data1: | |
5893 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5894 | info_ptr += 1; | |
5895 | break; | |
5896 | case DW_FORM_flag: | |
5897 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5898 | info_ptr += 1; | |
5899 | break; | |
5900 | case DW_FORM_sdata: | |
5901 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
5902 | info_ptr += bytes_read; | |
5903 | break; | |
5904 | case DW_FORM_udata: | |
5905 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5906 | info_ptr += bytes_read; | |
5907 | break; | |
5908 | case DW_FORM_ref1: | |
10b3939b | 5909 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
c906108c SS |
5910 | info_ptr += 1; |
5911 | break; | |
5912 | case DW_FORM_ref2: | |
10b3939b | 5913 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
c906108c SS |
5914 | info_ptr += 2; |
5915 | break; | |
5916 | case DW_FORM_ref4: | |
10b3939b | 5917 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
c906108c SS |
5918 | info_ptr += 4; |
5919 | break; | |
613e1657 | 5920 | case DW_FORM_ref8: |
10b3939b | 5921 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
613e1657 KB |
5922 | info_ptr += 8; |
5923 | break; | |
c906108c | 5924 | case DW_FORM_ref_udata: |
10b3939b DJ |
5925 | DW_ADDR (attr) = (cu->header.offset |
5926 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |
c906108c SS |
5927 | info_ptr += bytes_read; |
5928 | break; | |
c906108c | 5929 | case DW_FORM_indirect: |
a8329558 KW |
5930 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5931 | info_ptr += bytes_read; | |
e7c27a73 | 5932 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 5933 | break; |
c906108c | 5934 | default: |
8a3fe4f8 | 5935 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
659b0389 ML |
5936 | dwarf_form_name (form), |
5937 | bfd_get_filename (abfd)); | |
c906108c SS |
5938 | } |
5939 | return info_ptr; | |
5940 | } | |
5941 | ||
a8329558 KW |
5942 | /* Read an attribute described by an abbreviated attribute. */ |
5943 | ||
fe1b8b76 | 5944 | static gdb_byte * |
a8329558 | 5945 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
fe1b8b76 | 5946 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
5947 | { |
5948 | attr->name = abbrev->name; | |
e7c27a73 | 5949 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
5950 | } |
5951 | ||
c906108c SS |
5952 | /* read dwarf information from a buffer */ |
5953 | ||
5954 | static unsigned int | |
fe1b8b76 | 5955 | read_1_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 5956 | { |
fe1b8b76 | 5957 | return bfd_get_8 (abfd, buf); |
c906108c SS |
5958 | } |
5959 | ||
5960 | static int | |
fe1b8b76 | 5961 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
c906108c | 5962 | { |
fe1b8b76 | 5963 | return bfd_get_signed_8 (abfd, buf); |
c906108c SS |
5964 | } |
5965 | ||
5966 | static unsigned int | |
fe1b8b76 | 5967 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 5968 | { |
fe1b8b76 | 5969 | return bfd_get_16 (abfd, buf); |
c906108c SS |
5970 | } |
5971 | ||
5972 | static int | |
fe1b8b76 | 5973 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 5974 | { |
fe1b8b76 | 5975 | return bfd_get_signed_16 (abfd, buf); |
c906108c SS |
5976 | } |
5977 | ||
5978 | static unsigned int | |
fe1b8b76 | 5979 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 5980 | { |
fe1b8b76 | 5981 | return bfd_get_32 (abfd, buf); |
c906108c SS |
5982 | } |
5983 | ||
5984 | static int | |
fe1b8b76 | 5985 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 5986 | { |
fe1b8b76 | 5987 | return bfd_get_signed_32 (abfd, buf); |
c906108c SS |
5988 | } |
5989 | ||
ce5d95e1 | 5990 | static unsigned long |
fe1b8b76 | 5991 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
c906108c | 5992 | { |
fe1b8b76 | 5993 | return bfd_get_64 (abfd, buf); |
c906108c SS |
5994 | } |
5995 | ||
5996 | static CORE_ADDR | |
fe1b8b76 | 5997 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
891d2f0b | 5998 | unsigned int *bytes_read) |
c906108c | 5999 | { |
e7c27a73 | 6000 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
6001 | CORE_ADDR retval = 0; |
6002 | ||
107d2387 | 6003 | if (cu_header->signed_addr_p) |
c906108c | 6004 | { |
107d2387 AC |
6005 | switch (cu_header->addr_size) |
6006 | { | |
6007 | case 2: | |
fe1b8b76 | 6008 | retval = bfd_get_signed_16 (abfd, buf); |
107d2387 AC |
6009 | break; |
6010 | case 4: | |
fe1b8b76 | 6011 | retval = bfd_get_signed_32 (abfd, buf); |
107d2387 AC |
6012 | break; |
6013 | case 8: | |
fe1b8b76 | 6014 | retval = bfd_get_signed_64 (abfd, buf); |
107d2387 AC |
6015 | break; |
6016 | default: | |
8e65ff28 | 6017 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6018 | _("read_address: bad switch, signed [in module %s]"), |
659b0389 | 6019 | bfd_get_filename (abfd)); |
107d2387 AC |
6020 | } |
6021 | } | |
6022 | else | |
6023 | { | |
6024 | switch (cu_header->addr_size) | |
6025 | { | |
6026 | case 2: | |
fe1b8b76 | 6027 | retval = bfd_get_16 (abfd, buf); |
107d2387 AC |
6028 | break; |
6029 | case 4: | |
fe1b8b76 | 6030 | retval = bfd_get_32 (abfd, buf); |
107d2387 AC |
6031 | break; |
6032 | case 8: | |
fe1b8b76 | 6033 | retval = bfd_get_64 (abfd, buf); |
107d2387 AC |
6034 | break; |
6035 | default: | |
8e65ff28 | 6036 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6037 | _("read_address: bad switch, unsigned [in module %s]"), |
659b0389 | 6038 | bfd_get_filename (abfd)); |
107d2387 | 6039 | } |
c906108c | 6040 | } |
64367e0a | 6041 | |
107d2387 AC |
6042 | *bytes_read = cu_header->addr_size; |
6043 | return retval; | |
c906108c SS |
6044 | } |
6045 | ||
f7ef9339 | 6046 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
6047 | specification allows the initial length to take up either 4 bytes |
6048 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
6049 | bytes describe the length and all offsets will be 8 bytes in length | |
6050 | instead of 4. | |
6051 | ||
f7ef9339 KB |
6052 | An older, non-standard 64-bit format is also handled by this |
6053 | function. The older format in question stores the initial length | |
6054 | as an 8-byte quantity without an escape value. Lengths greater | |
6055 | than 2^32 aren't very common which means that the initial 4 bytes | |
6056 | is almost always zero. Since a length value of zero doesn't make | |
6057 | sense for the 32-bit format, this initial zero can be considered to | |
6058 | be an escape value which indicates the presence of the older 64-bit | |
6059 | format. As written, the code can't detect (old format) lengths | |
917c78fc MK |
6060 | greater than 4GB. If it becomes necessary to handle lengths |
6061 | somewhat larger than 4GB, we could allow other small values (such | |
6062 | as the non-sensical values of 1, 2, and 3) to also be used as | |
6063 | escape values indicating the presence of the old format. | |
f7ef9339 | 6064 | |
917c78fc MK |
6065 | The value returned via bytes_read should be used to increment the |
6066 | relevant pointer after calling read_initial_length(). | |
613e1657 KB |
6067 | |
6068 | As a side effect, this function sets the fields initial_length_size | |
6069 | and offset_size in cu_header to the values appropriate for the | |
6070 | length field. (The format of the initial length field determines | |
dd373385 | 6071 | the width of file offsets to be fetched later with read_offset().) |
613e1657 KB |
6072 | |
6073 | [ Note: read_initial_length() and read_offset() are based on the | |
6074 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 6075 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
6076 | from: |
6077 | ||
f7ef9339 | 6078 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
6079 | |
6080 | This document is only a draft and is subject to change. (So beware.) | |
6081 | ||
f7ef9339 | 6082 | Details regarding the older, non-standard 64-bit format were |
917c78fc MK |
6083 | determined empirically by examining 64-bit ELF files produced by |
6084 | the SGI toolchain on an IRIX 6.5 machine. | |
f7ef9339 KB |
6085 | |
6086 | - Kevin, July 16, 2002 | |
613e1657 KB |
6087 | ] */ |
6088 | ||
6089 | static LONGEST | |
fe1b8b76 | 6090 | read_initial_length (bfd *abfd, gdb_byte *buf, struct comp_unit_head *cu_header, |
891d2f0b | 6091 | unsigned int *bytes_read) |
613e1657 | 6092 | { |
fe1b8b76 | 6093 | LONGEST length = bfd_get_32 (abfd, buf); |
613e1657 | 6094 | |
dd373385 | 6095 | if (length == 0xffffffff) |
613e1657 | 6096 | { |
fe1b8b76 | 6097 | length = bfd_get_64 (abfd, buf + 4); |
613e1657 | 6098 | *bytes_read = 12; |
613e1657 | 6099 | } |
dd373385 | 6100 | else if (length == 0) |
f7ef9339 | 6101 | { |
dd373385 | 6102 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
fe1b8b76 | 6103 | length = bfd_get_64 (abfd, buf); |
f7ef9339 | 6104 | *bytes_read = 8; |
f7ef9339 | 6105 | } |
613e1657 KB |
6106 | else |
6107 | { | |
6108 | *bytes_read = 4; | |
613e1657 KB |
6109 | } |
6110 | ||
dd373385 EZ |
6111 | if (cu_header) |
6112 | { | |
6113 | gdb_assert (cu_header->initial_length_size == 0 | |
6114 | || cu_header->initial_length_size == 4 | |
6115 | || cu_header->initial_length_size == 8 | |
6116 | || cu_header->initial_length_size == 12); | |
6117 | ||
6118 | if (cu_header->initial_length_size != 0 | |
6119 | && cu_header->initial_length_size != *bytes_read) | |
6120 | complaint (&symfile_complaints, | |
6121 | _("intermixed 32-bit and 64-bit DWARF sections")); | |
6122 | ||
6123 | cu_header->initial_length_size = *bytes_read; | |
6124 | cu_header->offset_size = (*bytes_read == 4) ? 4 : 8; | |
6125 | } | |
6126 | ||
6127 | return length; | |
613e1657 KB |
6128 | } |
6129 | ||
6130 | /* Read an offset from the data stream. The size of the offset is | |
917c78fc | 6131 | given by cu_header->offset_size. */ |
613e1657 KB |
6132 | |
6133 | static LONGEST | |
fe1b8b76 | 6134 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
891d2f0b | 6135 | unsigned int *bytes_read) |
613e1657 KB |
6136 | { |
6137 | LONGEST retval = 0; | |
6138 | ||
6139 | switch (cu_header->offset_size) | |
6140 | { | |
6141 | case 4: | |
fe1b8b76 | 6142 | retval = bfd_get_32 (abfd, buf); |
613e1657 KB |
6143 | *bytes_read = 4; |
6144 | break; | |
6145 | case 8: | |
fe1b8b76 | 6146 | retval = bfd_get_64 (abfd, buf); |
613e1657 KB |
6147 | *bytes_read = 8; |
6148 | break; | |
6149 | default: | |
8e65ff28 | 6150 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 6151 | _("read_offset: bad switch [in module %s]"), |
659b0389 | 6152 | bfd_get_filename (abfd)); |
613e1657 KB |
6153 | } |
6154 | ||
917c78fc | 6155 | return retval; |
613e1657 KB |
6156 | } |
6157 | ||
fe1b8b76 JB |
6158 | static gdb_byte * |
6159 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) | |
c906108c SS |
6160 | { |
6161 | /* If the size of a host char is 8 bits, we can return a pointer | |
6162 | to the buffer, otherwise we have to copy the data to a buffer | |
6163 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6164 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 6165 | return buf; |
c906108c SS |
6166 | } |
6167 | ||
6168 | static char * | |
fe1b8b76 | 6169 | read_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
6170 | { |
6171 | /* If the size of a host char is 8 bits, we can return a pointer | |
6172 | to the string, otherwise we have to copy the string to a buffer | |
6173 | allocated on the temporary obstack. */ | |
4bdf3d34 | 6174 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
6175 | if (*buf == '\0') |
6176 | { | |
6177 | *bytes_read_ptr = 1; | |
6178 | return NULL; | |
6179 | } | |
fe1b8b76 JB |
6180 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
6181 | return (char *) buf; | |
4bdf3d34 JJ |
6182 | } |
6183 | ||
6184 | static char * | |
fe1b8b76 | 6185 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
4bdf3d34 JJ |
6186 | const struct comp_unit_head *cu_header, |
6187 | unsigned int *bytes_read_ptr) | |
6188 | { | |
6189 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
891d2f0b | 6190 | bytes_read_ptr); |
c906108c | 6191 | |
6502dd73 | 6192 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 6193 | { |
8a3fe4f8 | 6194 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
659b0389 | 6195 | bfd_get_filename (abfd)); |
4bdf3d34 | 6196 | return NULL; |
c906108c | 6197 | } |
6502dd73 | 6198 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 6199 | { |
8a3fe4f8 | 6200 | error (_("DW_FORM_strp pointing outside of .debug_str section [in module %s]"), |
659b0389 | 6201 | bfd_get_filename (abfd)); |
c906108c SS |
6202 | return NULL; |
6203 | } | |
4bdf3d34 | 6204 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 6205 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 6206 | return NULL; |
fe1b8b76 | 6207 | return (char *) (dwarf2_per_objfile->str_buffer + str_offset); |
c906108c SS |
6208 | } |
6209 | ||
ce5d95e1 | 6210 | static unsigned long |
fe1b8b76 | 6211 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6212 | { |
ce5d95e1 JB |
6213 | unsigned long result; |
6214 | unsigned int num_read; | |
c906108c SS |
6215 | int i, shift; |
6216 | unsigned char byte; | |
6217 | ||
6218 | result = 0; | |
6219 | shift = 0; | |
6220 | num_read = 0; | |
6221 | i = 0; | |
6222 | while (1) | |
6223 | { | |
fe1b8b76 | 6224 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6225 | buf++; |
6226 | num_read++; | |
ce5d95e1 | 6227 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
6228 | if ((byte & 128) == 0) |
6229 | { | |
6230 | break; | |
6231 | } | |
6232 | shift += 7; | |
6233 | } | |
6234 | *bytes_read_ptr = num_read; | |
6235 | return result; | |
6236 | } | |
6237 | ||
ce5d95e1 | 6238 | static long |
fe1b8b76 | 6239 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
c906108c | 6240 | { |
ce5d95e1 | 6241 | long result; |
77e0b926 | 6242 | int i, shift, num_read; |
c906108c SS |
6243 | unsigned char byte; |
6244 | ||
6245 | result = 0; | |
6246 | shift = 0; | |
c906108c SS |
6247 | num_read = 0; |
6248 | i = 0; | |
6249 | while (1) | |
6250 | { | |
fe1b8b76 | 6251 | byte = bfd_get_8 (abfd, buf); |
c906108c SS |
6252 | buf++; |
6253 | num_read++; | |
ce5d95e1 | 6254 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
6255 | shift += 7; |
6256 | if ((byte & 128) == 0) | |
6257 | { | |
6258 | break; | |
6259 | } | |
6260 | } | |
77e0b926 DJ |
6261 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
6262 | result |= -(((long)1) << shift); | |
c906108c SS |
6263 | *bytes_read_ptr = num_read; |
6264 | return result; | |
6265 | } | |
6266 | ||
4bb7a0a7 DJ |
6267 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
6268 | ||
fe1b8b76 JB |
6269 | static gdb_byte * |
6270 | skip_leb128 (bfd *abfd, gdb_byte *buf) | |
4bb7a0a7 DJ |
6271 | { |
6272 | int byte; | |
6273 | ||
6274 | while (1) | |
6275 | { | |
fe1b8b76 | 6276 | byte = bfd_get_8 (abfd, buf); |
4bb7a0a7 DJ |
6277 | buf++; |
6278 | if ((byte & 128) == 0) | |
6279 | return buf; | |
6280 | } | |
6281 | } | |
6282 | ||
c906108c | 6283 | static void |
e142c38c | 6284 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
6285 | { |
6286 | switch (lang) | |
6287 | { | |
6288 | case DW_LANG_C89: | |
6289 | case DW_LANG_C: | |
e142c38c | 6290 | cu->language = language_c; |
c906108c SS |
6291 | break; |
6292 | case DW_LANG_C_plus_plus: | |
e142c38c | 6293 | cu->language = language_cplus; |
c906108c SS |
6294 | break; |
6295 | case DW_LANG_Fortran77: | |
6296 | case DW_LANG_Fortran90: | |
b21b22e0 | 6297 | case DW_LANG_Fortran95: |
e142c38c | 6298 | cu->language = language_fortran; |
c906108c SS |
6299 | break; |
6300 | case DW_LANG_Mips_Assembler: | |
e142c38c | 6301 | cu->language = language_asm; |
c906108c | 6302 | break; |
bebd888e | 6303 | case DW_LANG_Java: |
e142c38c | 6304 | cu->language = language_java; |
bebd888e | 6305 | break; |
c906108c | 6306 | case DW_LANG_Ada83: |
8aaf0b47 | 6307 | case DW_LANG_Ada95: |
bc5f45f8 JB |
6308 | cu->language = language_ada; |
6309 | break; | |
72019c9c GM |
6310 | case DW_LANG_Modula2: |
6311 | cu->language = language_m2; | |
6312 | break; | |
c906108c SS |
6313 | case DW_LANG_Cobol74: |
6314 | case DW_LANG_Cobol85: | |
6315 | case DW_LANG_Pascal83: | |
c906108c | 6316 | default: |
e142c38c | 6317 | cu->language = language_minimal; |
c906108c SS |
6318 | break; |
6319 | } | |
e142c38c | 6320 | cu->language_defn = language_def (cu->language); |
c906108c SS |
6321 | } |
6322 | ||
6323 | /* Return the named attribute or NULL if not there. */ | |
6324 | ||
6325 | static struct attribute * | |
e142c38c | 6326 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
6327 | { |
6328 | unsigned int i; | |
6329 | struct attribute *spec = NULL; | |
6330 | ||
6331 | for (i = 0; i < die->num_attrs; ++i) | |
6332 | { | |
6333 | if (die->attrs[i].name == name) | |
10b3939b | 6334 | return &die->attrs[i]; |
c906108c SS |
6335 | if (die->attrs[i].name == DW_AT_specification |
6336 | || die->attrs[i].name == DW_AT_abstract_origin) | |
6337 | spec = &die->attrs[i]; | |
6338 | } | |
c906108c | 6339 | |
10b3939b DJ |
6340 | if (spec) |
6341 | return dwarf2_attr (follow_die_ref (die, spec, cu), name, cu); | |
c5aa993b | 6342 | |
c906108c SS |
6343 | return NULL; |
6344 | } | |
6345 | ||
05cf31d1 JB |
6346 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
6347 | and holds a non-zero value. This function should only be used for | |
6348 | DW_FORM_flag attributes. */ | |
6349 | ||
6350 | static int | |
6351 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
6352 | { | |
6353 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
6354 | ||
6355 | return (attr && DW_UNSND (attr)); | |
6356 | } | |
6357 | ||
3ca72b44 | 6358 | static int |
e142c38c | 6359 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 6360 | { |
05cf31d1 JB |
6361 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
6362 | which value is non-zero. However, we have to be careful with | |
6363 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
6364 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
6365 | end up accidently finding a declaration attribute that belongs | |
6366 | to a different DIE referenced by the specification attribute, | |
6367 | even though the given DIE does not have a declaration attribute. */ | |
6368 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
6369 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
6370 | } |
6371 | ||
63d06c5c DC |
6372 | /* Return the die giving the specification for DIE, if there is |
6373 | one. */ | |
6374 | ||
6375 | static struct die_info * | |
e142c38c | 6376 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 6377 | { |
e142c38c | 6378 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
6379 | |
6380 | if (spec_attr == NULL) | |
6381 | return NULL; | |
6382 | else | |
10b3939b | 6383 | return follow_die_ref (die, spec_attr, cu); |
63d06c5c | 6384 | } |
c906108c | 6385 | |
debd256d JB |
6386 | /* Free the line_header structure *LH, and any arrays and strings it |
6387 | refers to. */ | |
6388 | static void | |
6389 | free_line_header (struct line_header *lh) | |
6390 | { | |
6391 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 6392 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
6393 | |
6394 | /* Remember that all the lh->file_names[i].name pointers are | |
6395 | pointers into debug_line_buffer, and don't need to be freed. */ | |
6396 | if (lh->file_names) | |
a8bc7b56 | 6397 | xfree (lh->file_names); |
debd256d JB |
6398 | |
6399 | /* Similarly for the include directory names. */ | |
6400 | if (lh->include_dirs) | |
a8bc7b56 | 6401 | xfree (lh->include_dirs); |
debd256d | 6402 | |
a8bc7b56 | 6403 | xfree (lh); |
debd256d JB |
6404 | } |
6405 | ||
6406 | ||
6407 | /* Add an entry to LH's include directory table. */ | |
6408 | static void | |
6409 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 6410 | { |
debd256d JB |
6411 | /* Grow the array if necessary. */ |
6412 | if (lh->include_dirs_size == 0) | |
c5aa993b | 6413 | { |
debd256d JB |
6414 | lh->include_dirs_size = 1; /* for testing */ |
6415 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
6416 | * sizeof (*lh->include_dirs)); | |
6417 | } | |
6418 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
6419 | { | |
6420 | lh->include_dirs_size *= 2; | |
6421 | lh->include_dirs = xrealloc (lh->include_dirs, | |
6422 | (lh->include_dirs_size | |
6423 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 6424 | } |
c906108c | 6425 | |
debd256d JB |
6426 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
6427 | } | |
6428 | ||
6429 | ||
6430 | /* Add an entry to LH's file name table. */ | |
6431 | static void | |
6432 | add_file_name (struct line_header *lh, | |
6433 | char *name, | |
6434 | unsigned int dir_index, | |
6435 | unsigned int mod_time, | |
6436 | unsigned int length) | |
6437 | { | |
6438 | struct file_entry *fe; | |
6439 | ||
6440 | /* Grow the array if necessary. */ | |
6441 | if (lh->file_names_size == 0) | |
6442 | { | |
6443 | lh->file_names_size = 1; /* for testing */ | |
6444 | lh->file_names = xmalloc (lh->file_names_size | |
6445 | * sizeof (*lh->file_names)); | |
6446 | } | |
6447 | else if (lh->num_file_names >= lh->file_names_size) | |
6448 | { | |
6449 | lh->file_names_size *= 2; | |
6450 | lh->file_names = xrealloc (lh->file_names, | |
6451 | (lh->file_names_size | |
6452 | * sizeof (*lh->file_names))); | |
6453 | } | |
6454 | ||
6455 | fe = &lh->file_names[lh->num_file_names++]; | |
6456 | fe->name = name; | |
6457 | fe->dir_index = dir_index; | |
6458 | fe->mod_time = mod_time; | |
6459 | fe->length = length; | |
aaa75496 | 6460 | fe->included_p = 0; |
debd256d JB |
6461 | } |
6462 | ||
6463 | ||
6464 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
6465 | .debug_line, according to the endianness of ABFD. Return a pointer |
6466 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
6467 | |
6468 | NOTE: the strings in the include directory and file name tables of | |
6469 | the returned object point into debug_line_buffer, and must not be | |
6470 | freed. */ | |
6471 | static struct line_header * | |
6472 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 6473 | struct dwarf2_cu *cu) |
debd256d JB |
6474 | { |
6475 | struct cleanup *back_to; | |
6476 | struct line_header *lh; | |
fe1b8b76 | 6477 | gdb_byte *line_ptr; |
891d2f0b | 6478 | unsigned int bytes_read; |
debd256d JB |
6479 | int i; |
6480 | char *cur_dir, *cur_file; | |
6481 | ||
6502dd73 | 6482 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 6483 | { |
e2e0b3e5 | 6484 | complaint (&symfile_complaints, _("missing .debug_line section")); |
debd256d JB |
6485 | return 0; |
6486 | } | |
6487 | ||
a738430d MK |
6488 | /* Make sure that at least there's room for the total_length field. |
6489 | That could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 6490 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 6491 | { |
4d3c2250 | 6492 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6493 | return 0; |
6494 | } | |
6495 | ||
6496 | lh = xmalloc (sizeof (*lh)); | |
6497 | memset (lh, 0, sizeof (*lh)); | |
6498 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
6499 | (void *) lh); | |
6500 | ||
6502dd73 | 6501 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d | 6502 | |
a738430d | 6503 | /* Read in the header. */ |
dd373385 EZ |
6504 | lh->total_length = |
6505 | read_initial_length (abfd, line_ptr, &cu->header, &bytes_read); | |
debd256d | 6506 | line_ptr += bytes_read; |
6502dd73 DJ |
6507 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
6508 | + dwarf2_per_objfile->line_size)) | |
debd256d | 6509 | { |
4d3c2250 | 6510 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
6511 | return 0; |
6512 | } | |
6513 | lh->statement_program_end = line_ptr + lh->total_length; | |
6514 | lh->version = read_2_bytes (abfd, line_ptr); | |
6515 | line_ptr += 2; | |
e7c27a73 | 6516 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
6517 | line_ptr += bytes_read; |
6518 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
6519 | line_ptr += 1; | |
6520 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
6521 | line_ptr += 1; | |
6522 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
6523 | line_ptr += 1; | |
6524 | lh->line_range = read_1_byte (abfd, line_ptr); | |
6525 | line_ptr += 1; | |
6526 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
6527 | line_ptr += 1; | |
6528 | lh->standard_opcode_lengths | |
fe1b8b76 | 6529 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
debd256d JB |
6530 | |
6531 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
6532 | for (i = 1; i < lh->opcode_base; ++i) | |
6533 | { | |
6534 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
6535 | line_ptr += 1; | |
6536 | } | |
6537 | ||
a738430d | 6538 | /* Read directory table. */ |
debd256d JB |
6539 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6540 | { | |
6541 | line_ptr += bytes_read; | |
6542 | add_include_dir (lh, cur_dir); | |
6543 | } | |
6544 | line_ptr += bytes_read; | |
6545 | ||
a738430d | 6546 | /* Read file name table. */ |
debd256d JB |
6547 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
6548 | { | |
6549 | unsigned int dir_index, mod_time, length; | |
6550 | ||
6551 | line_ptr += bytes_read; | |
6552 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6553 | line_ptr += bytes_read; | |
6554 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6555 | line_ptr += bytes_read; | |
6556 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6557 | line_ptr += bytes_read; | |
6558 | ||
6559 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6560 | } | |
6561 | line_ptr += bytes_read; | |
6562 | lh->statement_program_start = line_ptr; | |
6563 | ||
6502dd73 DJ |
6564 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
6565 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 | 6566 | complaint (&symfile_complaints, |
e2e0b3e5 | 6567 | _("line number info header doesn't fit in `.debug_line' section")); |
debd256d JB |
6568 | |
6569 | discard_cleanups (back_to); | |
6570 | return lh; | |
6571 | } | |
c906108c | 6572 | |
5fb290d7 DJ |
6573 | /* This function exists to work around a bug in certain compilers |
6574 | (particularly GCC 2.95), in which the first line number marker of a | |
6575 | function does not show up until after the prologue, right before | |
6576 | the second line number marker. This function shifts ADDRESS down | |
6577 | to the beginning of the function if necessary, and is called on | |
6578 | addresses passed to record_line. */ | |
6579 | ||
6580 | static CORE_ADDR | |
e142c38c | 6581 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
6582 | { |
6583 | struct function_range *fn; | |
6584 | ||
6585 | /* Find the function_range containing address. */ | |
e142c38c | 6586 | if (!cu->first_fn) |
5fb290d7 DJ |
6587 | return address; |
6588 | ||
e142c38c DJ |
6589 | if (!cu->cached_fn) |
6590 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 6591 | |
e142c38c | 6592 | fn = cu->cached_fn; |
5fb290d7 DJ |
6593 | while (fn) |
6594 | if (fn->lowpc <= address && fn->highpc > address) | |
6595 | goto found; | |
6596 | else | |
6597 | fn = fn->next; | |
6598 | ||
e142c38c DJ |
6599 | fn = cu->first_fn; |
6600 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
6601 | if (fn->lowpc <= address && fn->highpc > address) |
6602 | goto found; | |
6603 | else | |
6604 | fn = fn->next; | |
6605 | ||
6606 | return address; | |
6607 | ||
6608 | found: | |
6609 | if (fn->seen_line) | |
6610 | return address; | |
6611 | if (address != fn->lowpc) | |
4d3c2250 | 6612 | complaint (&symfile_complaints, |
e2e0b3e5 | 6613 | _("misplaced first line number at 0x%lx for '%s'"), |
4d3c2250 | 6614 | (unsigned long) address, fn->name); |
5fb290d7 DJ |
6615 | fn->seen_line = 1; |
6616 | return fn->lowpc; | |
6617 | } | |
6618 | ||
aaa75496 JB |
6619 | /* Decode the Line Number Program (LNP) for the given line_header |
6620 | structure and CU. The actual information extracted and the type | |
6621 | of structures created from the LNP depends on the value of PST. | |
6622 | ||
6623 | 1. If PST is NULL, then this procedure uses the data from the program | |
6624 | to create all necessary symbol tables, and their linetables. | |
6625 | The compilation directory of the file is passed in COMP_DIR, | |
6626 | and must not be NULL. | |
6627 | ||
6628 | 2. If PST is not NULL, this procedure reads the program to determine | |
6629 | the list of files included by the unit represented by PST, and | |
6630 | builds all the associated partial symbol tables. In this case, | |
6631 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
6632 | is not used to compute the full name of the symtab, and therefore | |
6633 | omitting it when building the partial symtab does not introduce | |
6634 | the potential for inconsistency - a partial symtab and its associated | |
6635 | symbtab having a different fullname -). */ | |
debd256d | 6636 | |
c906108c | 6637 | static void |
debd256d | 6638 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 6639 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c | 6640 | { |
fe1b8b76 JB |
6641 | gdb_byte *line_ptr; |
6642 | gdb_byte *line_end; | |
e7c27a73 | 6643 | unsigned int bytes_read; |
c906108c | 6644 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
6645 | CORE_ADDR baseaddr; |
6646 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 6647 | const int decode_for_pst_p = (pst != NULL); |
366da635 | 6648 | struct subfile *last_subfile = NULL; |
e142c38c DJ |
6649 | |
6650 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6651 | |
debd256d JB |
6652 | line_ptr = lh->statement_program_start; |
6653 | line_end = lh->statement_program_end; | |
c906108c SS |
6654 | |
6655 | /* Read the statement sequences until there's nothing left. */ | |
6656 | while (line_ptr < line_end) | |
6657 | { | |
6658 | /* state machine registers */ | |
6659 | CORE_ADDR address = 0; | |
6660 | unsigned int file = 1; | |
6661 | unsigned int line = 1; | |
6662 | unsigned int column = 0; | |
debd256d | 6663 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
6664 | int basic_block = 0; |
6665 | int end_sequence = 0; | |
6666 | ||
aaa75496 | 6667 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 6668 | { |
aaa75496 | 6669 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
6670 | /* lh->include_dirs and lh->file_names are 0-based, but the |
6671 | directory and file name numbers in the statement program | |
6672 | are 1-based. */ | |
6673 | struct file_entry *fe = &lh->file_names[file - 1]; | |
4f1520fb | 6674 | char *dir = NULL; |
a738430d | 6675 | |
debd256d JB |
6676 | if (fe->dir_index) |
6677 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb FR |
6678 | |
6679 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
c906108c SS |
6680 | } |
6681 | ||
a738430d | 6682 | /* Decode the table. */ |
c5aa993b | 6683 | while (!end_sequence) |
c906108c SS |
6684 | { |
6685 | op_code = read_1_byte (abfd, line_ptr); | |
6686 | line_ptr += 1; | |
9aa1fe7e | 6687 | |
debd256d | 6688 | if (op_code >= lh->opcode_base) |
a738430d MK |
6689 | { |
6690 | /* Special operand. */ | |
debd256d JB |
6691 | adj_opcode = op_code - lh->opcode_base; |
6692 | address += (adj_opcode / lh->line_range) | |
6693 | * lh->minimum_instruction_length; | |
6694 | line += lh->line_base + (adj_opcode % lh->line_range); | |
aa495d11 | 6695 | lh->file_names[file - 1].included_p = 1; |
aaa75496 JB |
6696 | if (!decode_for_pst_p) |
6697 | { | |
366da635 DJ |
6698 | if (last_subfile != current_subfile) |
6699 | { | |
6700 | if (last_subfile) | |
6701 | record_line (last_subfile, 0, address); | |
6702 | last_subfile = current_subfile; | |
6703 | } | |
a738430d | 6704 | /* Append row to matrix using current values. */ |
aaa75496 JB |
6705 | record_line (current_subfile, line, |
6706 | check_cu_functions (address, cu)); | |
6707 | } | |
9aa1fe7e GK |
6708 | basic_block = 1; |
6709 | } | |
6710 | else switch (op_code) | |
c906108c SS |
6711 | { |
6712 | case DW_LNS_extended_op: | |
473b7be6 DJ |
6713 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
6714 | line_ptr += bytes_read; | |
c906108c SS |
6715 | extended_op = read_1_byte (abfd, line_ptr); |
6716 | line_ptr += 1; | |
6717 | switch (extended_op) | |
6718 | { | |
6719 | case DW_LNE_end_sequence: | |
6720 | end_sequence = 1; | |
aa495d11 | 6721 | lh->file_names[file - 1].included_p = 1; |
aaa75496 JB |
6722 | if (!decode_for_pst_p) |
6723 | record_line (current_subfile, 0, address); | |
c906108c SS |
6724 | break; |
6725 | case DW_LNE_set_address: | |
e7c27a73 | 6726 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
6727 | line_ptr += bytes_read; |
6728 | address += baseaddr; | |
c906108c SS |
6729 | break; |
6730 | case DW_LNE_define_file: | |
debd256d JB |
6731 | { |
6732 | char *cur_file; | |
6733 | unsigned int dir_index, mod_time, length; | |
6734 | ||
6735 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
6736 | line_ptr += bytes_read; | |
6737 | dir_index = | |
6738 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6739 | line_ptr += bytes_read; | |
6740 | mod_time = | |
6741 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6742 | line_ptr += bytes_read; | |
6743 | length = | |
6744 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6745 | line_ptr += bytes_read; | |
6746 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6747 | } | |
c906108c SS |
6748 | break; |
6749 | default: | |
4d3c2250 | 6750 | complaint (&symfile_complaints, |
e2e0b3e5 | 6751 | _("mangled .debug_line section")); |
debd256d | 6752 | return; |
c906108c SS |
6753 | } |
6754 | break; | |
6755 | case DW_LNS_copy: | |
aa495d11 | 6756 | lh->file_names[file - 1].included_p = 1; |
aaa75496 | 6757 | if (!decode_for_pst_p) |
366da635 DJ |
6758 | { |
6759 | if (last_subfile != current_subfile) | |
6760 | { | |
6761 | if (last_subfile) | |
6762 | record_line (last_subfile, 0, address); | |
6763 | last_subfile = current_subfile; | |
6764 | } | |
6765 | record_line (current_subfile, line, | |
6766 | check_cu_functions (address, cu)); | |
6767 | } | |
c906108c SS |
6768 | basic_block = 0; |
6769 | break; | |
6770 | case DW_LNS_advance_pc: | |
debd256d | 6771 | address += lh->minimum_instruction_length |
c906108c SS |
6772 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
6773 | line_ptr += bytes_read; | |
6774 | break; | |
6775 | case DW_LNS_advance_line: | |
6776 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
6777 | line_ptr += bytes_read; | |
6778 | break; | |
6779 | case DW_LNS_set_file: | |
debd256d | 6780 | { |
a738430d MK |
6781 | /* The arrays lh->include_dirs and lh->file_names are |
6782 | 0-based, but the directory and file name numbers in | |
6783 | the statement program are 1-based. */ | |
debd256d | 6784 | struct file_entry *fe; |
4f1520fb | 6785 | char *dir = NULL; |
a738430d | 6786 | |
debd256d JB |
6787 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
6788 | line_ptr += bytes_read; | |
6789 | fe = &lh->file_names[file - 1]; | |
6790 | if (fe->dir_index) | |
6791 | dir = lh->include_dirs[fe->dir_index - 1]; | |
4f1520fb | 6792 | |
aaa75496 | 6793 | if (!decode_for_pst_p) |
366da635 DJ |
6794 | { |
6795 | last_subfile = current_subfile; | |
6796 | dwarf2_start_subfile (fe->name, dir, comp_dir); | |
6797 | } | |
debd256d | 6798 | } |
c906108c SS |
6799 | break; |
6800 | case DW_LNS_set_column: | |
6801 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6802 | line_ptr += bytes_read; | |
6803 | break; | |
6804 | case DW_LNS_negate_stmt: | |
6805 | is_stmt = (!is_stmt); | |
6806 | break; | |
6807 | case DW_LNS_set_basic_block: | |
6808 | basic_block = 1; | |
6809 | break; | |
c2c6d25f JM |
6810 | /* Add to the address register of the state machine the |
6811 | address increment value corresponding to special opcode | |
a738430d MK |
6812 | 255. I.e., this value is scaled by the minimum |
6813 | instruction length since special opcode 255 would have | |
6814 | scaled the the increment. */ | |
c906108c | 6815 | case DW_LNS_const_add_pc: |
debd256d JB |
6816 | address += (lh->minimum_instruction_length |
6817 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
6818 | break; |
6819 | case DW_LNS_fixed_advance_pc: | |
6820 | address += read_2_bytes (abfd, line_ptr); | |
6821 | line_ptr += 2; | |
6822 | break; | |
9aa1fe7e | 6823 | default: |
a738430d MK |
6824 | { |
6825 | /* Unknown standard opcode, ignore it. */ | |
9aa1fe7e | 6826 | int i; |
a738430d | 6827 | |
debd256d | 6828 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
6829 | { |
6830 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6831 | line_ptr += bytes_read; | |
6832 | } | |
6833 | } | |
c906108c SS |
6834 | } |
6835 | } | |
6836 | } | |
aaa75496 JB |
6837 | |
6838 | if (decode_for_pst_p) | |
6839 | { | |
6840 | int file_index; | |
6841 | ||
6842 | /* Now that we're done scanning the Line Header Program, we can | |
6843 | create the psymtab of each included file. */ | |
6844 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
6845 | if (lh->file_names[file_index].included_p == 1) | |
6846 | { | |
5b5464ad JB |
6847 | const struct file_entry fe = lh->file_names [file_index]; |
6848 | char *include_name = fe.name; | |
6849 | char *dir_name = NULL; | |
6850 | char *pst_filename = pst->filename; | |
6851 | ||
6852 | if (fe.dir_index) | |
6853 | dir_name = lh->include_dirs[fe.dir_index - 1]; | |
6854 | ||
6855 | if (!IS_ABSOLUTE_PATH (include_name) && dir_name != NULL) | |
6856 | { | |
1754f103 MK |
6857 | include_name = concat (dir_name, SLASH_STRING, |
6858 | include_name, (char *)NULL); | |
5b5464ad JB |
6859 | make_cleanup (xfree, include_name); |
6860 | } | |
6861 | ||
6862 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) | |
6863 | { | |
1754f103 MK |
6864 | pst_filename = concat (pst->dirname, SLASH_STRING, |
6865 | pst_filename, (char *)NULL); | |
5b5464ad JB |
6866 | make_cleanup (xfree, pst_filename); |
6867 | } | |
6868 | ||
6869 | if (strcmp (include_name, pst_filename) != 0) | |
aaa75496 JB |
6870 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
6871 | } | |
6872 | } | |
c906108c SS |
6873 | } |
6874 | ||
6875 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
6876 | DIRNAME the name of the source directory which contains FILENAME | |
4f1520fb FR |
6877 | or NULL if not known. COMP_DIR is the compilation directory for the |
6878 | linetable's compilation unit or NULL if not known. | |
c906108c SS |
6879 | This routine tries to keep line numbers from identical absolute and |
6880 | relative file names in a common subfile. | |
6881 | ||
6882 | Using the `list' example from the GDB testsuite, which resides in | |
6883 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
6884 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
6885 | ||
c5aa993b JM |
6886 | DW_AT_name: /srcdir/list0.c |
6887 | DW_AT_comp_dir: /compdir | |
357e46e7 | 6888 | files.files[0].name: list0.h |
c5aa993b | 6889 | files.files[0].dir: /srcdir |
357e46e7 | 6890 | files.files[1].name: list0.c |
c5aa993b | 6891 | files.files[1].dir: /srcdir |
c906108c SS |
6892 | |
6893 | The line number information for list0.c has to end up in a single | |
4f1520fb FR |
6894 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
6895 | start_subfile will ensure that this happens provided that we pass the | |
6896 | concatenation of files.files[1].dir and files.files[1].name as the | |
6897 | subfile's name. */ | |
c906108c SS |
6898 | |
6899 | static void | |
4f1520fb | 6900 | dwarf2_start_subfile (char *filename, char *dirname, char *comp_dir) |
c906108c | 6901 | { |
4f1520fb FR |
6902 | char *fullname; |
6903 | ||
6904 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). | |
6905 | `start_symtab' will always pass the contents of DW_AT_comp_dir as | |
6906 | second argument to start_subfile. To be consistent, we do the | |
6907 | same here. In order not to lose the line information directory, | |
6908 | we concatenate it to the filename when it makes sense. | |
6909 | Note that the Dwarf3 standard says (speaking of filenames in line | |
6910 | information): ``The directory index is ignored for file names | |
6911 | that represent full path names''. Thus ignoring dirname in the | |
6912 | `else' branch below isn't an issue. */ | |
c906108c | 6913 | |
d5166ae1 | 6914 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
4f1520fb FR |
6915 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
6916 | else | |
6917 | fullname = filename; | |
c906108c | 6918 | |
4f1520fb FR |
6919 | start_subfile (fullname, comp_dir); |
6920 | ||
6921 | if (fullname != filename) | |
6922 | xfree (fullname); | |
c906108c SS |
6923 | } |
6924 | ||
4c2df51b DJ |
6925 | static void |
6926 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 6927 | struct dwarf2_cu *cu) |
4c2df51b | 6928 | { |
e7c27a73 DJ |
6929 | struct objfile *objfile = cu->objfile; |
6930 | struct comp_unit_head *cu_header = &cu->header; | |
6931 | ||
4c2df51b DJ |
6932 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
6933 | code here to turn a symbol with DW_AT_external and a | |
6934 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
6935 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
6936 | with some versions of binutils) where shared libraries could have | |
6937 | relocations against symbols in their debug information - the | |
6938 | minimal symbol would have the right address, but the debug info | |
6939 | would not. It's no longer necessary, because we will explicitly | |
6940 | apply relocations when we read in the debug information now. */ | |
6941 | ||
6942 | /* A DW_AT_location attribute with no contents indicates that a | |
6943 | variable has been optimized away. */ | |
6944 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
6945 | { | |
6946 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
6947 | return; | |
6948 | } | |
6949 | ||
6950 | /* Handle one degenerate form of location expression specially, to | |
6951 | preserve GDB's previous behavior when section offsets are | |
6952 | specified. If this is just a DW_OP_addr then mark this symbol | |
6953 | as LOC_STATIC. */ | |
6954 | ||
6955 | if (attr_form_is_block (attr) | |
6956 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
6957 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
6958 | { | |
891d2f0b | 6959 | unsigned int dummy; |
4c2df51b DJ |
6960 | |
6961 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 6962 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
4c2df51b DJ |
6963 | fixup_symbol_section (sym, objfile); |
6964 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
6965 | SYMBOL_SECTION (sym)); | |
6966 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
6967 | return; | |
6968 | } | |
6969 | ||
6970 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
6971 | expression evaluator, and use LOC_COMPUTED only when necessary | |
6972 | (i.e. when the value of a register or memory location is | |
6973 | referenced, or a thread-local block, etc.). Then again, it might | |
6974 | not be worthwhile. I'm assuming that it isn't unless performance | |
6975 | or memory numbers show me otherwise. */ | |
6976 | ||
e7c27a73 | 6977 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
6978 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
6979 | } | |
6980 | ||
c906108c SS |
6981 | /* Given a pointer to a DWARF information entry, figure out if we need |
6982 | to make a symbol table entry for it, and if so, create a new entry | |
6983 | and return a pointer to it. | |
6984 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 6985 | used the passed type. */ |
c906108c SS |
6986 | |
6987 | static struct symbol * | |
e7c27a73 | 6988 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 6989 | { |
e7c27a73 | 6990 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6991 | struct symbol *sym = NULL; |
6992 | char *name; | |
6993 | struct attribute *attr = NULL; | |
6994 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
6995 | CORE_ADDR baseaddr; |
6996 | ||
6997 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6998 | |
5c4e30ca | 6999 | if (die->tag != DW_TAG_namespace) |
e142c38c | 7000 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
7001 | else |
7002 | name = TYPE_NAME (type); | |
7003 | ||
c906108c SS |
7004 | if (name) |
7005 | { | |
4a146b47 | 7006 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
7007 | sizeof (struct symbol)); |
7008 | OBJSTAT (objfile, n_syms++); | |
7009 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
7010 | |
7011 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 7012 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 7013 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
7014 | |
7015 | /* Default assumptions. | |
c5aa993b | 7016 | Use the passed type or decode it from the die. */ |
176620f1 | 7017 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
875dc2fc | 7018 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
c906108c SS |
7019 | if (type != NULL) |
7020 | SYMBOL_TYPE (sym) = type; | |
7021 | else | |
e7c27a73 | 7022 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 7023 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
7024 | if (attr) |
7025 | { | |
7026 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
7027 | } | |
c906108c SS |
7028 | switch (die->tag) |
7029 | { | |
7030 | case DW_TAG_label: | |
e142c38c | 7031 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
7032 | if (attr) |
7033 | { | |
7034 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
7035 | } | |
7036 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
7037 | break; | |
7038 | case DW_TAG_subprogram: | |
7039 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
7040 | finish_block. */ | |
7041 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 7042 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7043 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7044 | { | |
7045 | add_symbol_to_list (sym, &global_symbols); | |
7046 | } | |
7047 | else | |
7048 | { | |
e142c38c | 7049 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7050 | } |
7051 | break; | |
7052 | case DW_TAG_variable: | |
7053 | /* Compilation with minimal debug info may result in variables | |
7054 | with missing type entries. Change the misleading `void' type | |
7055 | to something sensible. */ | |
7056 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
7057 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, | |
7058 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
7059 | "<variable, no debug info>", | |
7060 | objfile); | |
e142c38c | 7061 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7062 | if (attr) |
7063 | { | |
e7c27a73 | 7064 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 7065 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
7066 | if (attr2 && (DW_UNSND (attr2) != 0)) |
7067 | add_symbol_to_list (sym, &global_symbols); | |
7068 | else | |
e142c38c | 7069 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7070 | break; |
7071 | } | |
e142c38c | 7072 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7073 | if (attr) |
7074 | { | |
e7c27a73 | 7075 | var_decode_location (attr, sym, cu); |
e142c38c | 7076 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7077 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 7078 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 7079 | else |
e142c38c | 7080 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7081 | } |
7082 | else | |
7083 | { | |
7084 | /* We do not know the address of this symbol. | |
c5aa993b JM |
7085 | If it is an external symbol and we have type information |
7086 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
7087 | The address of the variable will then be determined from | |
7088 | the minimal symbol table whenever the variable is | |
7089 | referenced. */ | |
e142c38c | 7090 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 7091 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 7092 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
7093 | { |
7094 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
7095 | add_symbol_to_list (sym, &global_symbols); | |
7096 | } | |
7097 | } | |
7098 | break; | |
7099 | case DW_TAG_formal_parameter: | |
e142c38c | 7100 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
7101 | if (attr) |
7102 | { | |
e7c27a73 | 7103 | var_decode_location (attr, sym, cu); |
7cf6e574 DJ |
7104 | /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ |
7105 | if (SYMBOL_CLASS (sym) == LOC_COMPUTED) | |
7106 | SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; | |
c906108c | 7107 | } |
e142c38c | 7108 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7109 | if (attr) |
7110 | { | |
e7c27a73 | 7111 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7112 | } |
e142c38c | 7113 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7114 | break; |
7115 | case DW_TAG_unspecified_parameters: | |
7116 | /* From varargs functions; gdb doesn't seem to have any | |
7117 | interest in this information, so just ignore it for now. | |
7118 | (FIXME?) */ | |
7119 | break; | |
7120 | case DW_TAG_class_type: | |
7121 | case DW_TAG_structure_type: | |
7122 | case DW_TAG_union_type: | |
72019c9c | 7123 | case DW_TAG_set_type: |
c906108c SS |
7124 | case DW_TAG_enumeration_type: |
7125 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 7126 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 7127 | |
63d06c5c DC |
7128 | /* Make sure that the symbol includes appropriate enclosing |
7129 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 7130 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
7131 | the type. */ |
7132 | ||
987504bb JJ |
7133 | if (cu->language == language_cplus |
7134 | || cu->language == language_java) | |
c906108c | 7135 | { |
63d06c5c DC |
7136 | struct type *type = SYMBOL_TYPE (sym); |
7137 | ||
7138 | if (TYPE_TAG_NAME (type) != NULL) | |
7139 | { | |
7140 | /* FIXME: carlton/2003-11-10: Should this use | |
7141 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
7142 | arises further down in this function.) */ |
7143 | /* The type's name is already allocated along with | |
7144 | this objfile, so we don't need to duplicate it | |
7145 | for the symbol. */ | |
7146 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 7147 | } |
c906108c | 7148 | } |
63d06c5c DC |
7149 | |
7150 | { | |
987504bb | 7151 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
63d06c5c DC |
7152 | really ever be static objects: otherwise, if you try |
7153 | to, say, break of a class's method and you're in a file | |
7154 | which doesn't mention that class, it won't work unless | |
7155 | the check for all static symbols in lookup_symbol_aux | |
7156 | saves you. See the OtherFileClass tests in | |
7157 | gdb.c++/namespace.exp. */ | |
7158 | ||
7159 | struct pending **list_to_add; | |
7160 | ||
e142c38c | 7161 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7162 | && (cu->language == language_cplus |
7163 | || cu->language == language_java) | |
e142c38c | 7164 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7165 | |
7166 | add_symbol_to_list (sym, list_to_add); | |
7167 | ||
7168 | /* The semantics of C++ state that "struct foo { ... }" also | |
987504bb JJ |
7169 | defines a typedef for "foo". A Java class declaration also |
7170 | defines a typedef for the class. Synthesize a typedef symbol | |
7171 | so that "ptype foo" works as expected. */ | |
7172 | if (cu->language == language_cplus | |
7173 | || cu->language == language_java) | |
63d06c5c DC |
7174 | { |
7175 | struct symbol *typedef_sym = (struct symbol *) | |
4a146b47 | 7176 | obstack_alloc (&objfile->objfile_obstack, |
63d06c5c DC |
7177 | sizeof (struct symbol)); |
7178 | *typedef_sym = *sym; | |
7179 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; | |
d8151005 DJ |
7180 | /* The symbol's name is already allocated along with |
7181 | this objfile, so we don't need to duplicate it for | |
7182 | the type. */ | |
63d06c5c | 7183 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
77ef991d | 7184 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
63d06c5c DC |
7185 | add_symbol_to_list (typedef_sym, list_to_add); |
7186 | } | |
7187 | } | |
c906108c SS |
7188 | break; |
7189 | case DW_TAG_typedef: | |
63d06c5c DC |
7190 | if (processing_has_namespace_info |
7191 | && processing_current_prefix[0] != '\0') | |
7192 | { | |
987504bb JJ |
7193 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7194 | processing_current_prefix, | |
7195 | name, cu); | |
63d06c5c DC |
7196 | } |
7197 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7198 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 7199 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 7200 | break; |
c906108c | 7201 | case DW_TAG_base_type: |
a02abb62 | 7202 | case DW_TAG_subrange_type: |
c906108c | 7203 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 7204 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 7205 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
7206 | break; |
7207 | case DW_TAG_enumerator: | |
63d06c5c DC |
7208 | if (processing_has_namespace_info |
7209 | && processing_current_prefix[0] != '\0') | |
7210 | { | |
987504bb JJ |
7211 | SYMBOL_LINKAGE_NAME (sym) = typename_concat (&objfile->objfile_obstack, |
7212 | processing_current_prefix, | |
7213 | name, cu); | |
63d06c5c | 7214 | } |
e142c38c | 7215 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
7216 | if (attr) |
7217 | { | |
e7c27a73 | 7218 | dwarf2_const_value (attr, sym, cu); |
c906108c | 7219 | } |
63d06c5c DC |
7220 | { |
7221 | /* NOTE: carlton/2003-11-10: See comment above in the | |
7222 | DW_TAG_class_type, etc. block. */ | |
7223 | ||
7224 | struct pending **list_to_add; | |
7225 | ||
e142c38c | 7226 | list_to_add = (cu->list_in_scope == &file_symbols |
987504bb JJ |
7227 | && (cu->language == language_cplus |
7228 | || cu->language == language_java) | |
e142c38c | 7229 | ? &global_symbols : cu->list_in_scope); |
63d06c5c DC |
7230 | |
7231 | add_symbol_to_list (sym, list_to_add); | |
7232 | } | |
c906108c | 7233 | break; |
5c4e30ca DC |
7234 | case DW_TAG_namespace: |
7235 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
7236 | add_symbol_to_list (sym, &global_symbols); | |
7237 | break; | |
c906108c SS |
7238 | default: |
7239 | /* Not a tag we recognize. Hopefully we aren't processing | |
7240 | trash data, but since we must specifically ignore things | |
7241 | we don't recognize, there is nothing else we should do at | |
7242 | this point. */ | |
e2e0b3e5 | 7243 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
4d3c2250 | 7244 | dwarf_tag_name (die->tag)); |
c906108c SS |
7245 | break; |
7246 | } | |
7247 | } | |
7248 | return (sym); | |
7249 | } | |
7250 | ||
7251 | /* Copy constant value from an attribute to a symbol. */ | |
7252 | ||
7253 | static void | |
107d2387 | 7254 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 7255 | struct dwarf2_cu *cu) |
c906108c | 7256 | { |
e7c27a73 DJ |
7257 | struct objfile *objfile = cu->objfile; |
7258 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
7259 | struct dwarf_block *blk; |
7260 | ||
7261 | switch (attr->form) | |
7262 | { | |
7263 | case DW_FORM_addr: | |
107d2387 | 7264 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 7265 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7266 | cu_header->addr_size, |
7267 | TYPE_LENGTH (SYMBOL_TYPE | |
7268 | (sym))); | |
4e38b386 | 7269 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7270 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
7271 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
7272 | it's body - store_unsigned_integer. */ | |
7273 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
7274 | DW_ADDR (attr)); | |
c906108c SS |
7275 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
7276 | break; | |
7277 | case DW_FORM_block1: | |
7278 | case DW_FORM_block2: | |
7279 | case DW_FORM_block4: | |
7280 | case DW_FORM_block: | |
7281 | blk = DW_BLOCK (attr); | |
7282 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 7283 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
7284 | blk->size, |
7285 | TYPE_LENGTH (SYMBOL_TYPE | |
7286 | (sym))); | |
4e38b386 | 7287 | SYMBOL_VALUE_BYTES (sym) = |
4a146b47 | 7288 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
7289 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
7290 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
7291 | break; | |
2df3850c JM |
7292 | |
7293 | /* The DW_AT_const_value attributes are supposed to carry the | |
7294 | symbol's value "represented as it would be on the target | |
7295 | architecture." By the time we get here, it's already been | |
7296 | converted to host endianness, so we just need to sign- or | |
7297 | zero-extend it as appropriate. */ | |
7298 | case DW_FORM_data1: | |
7299 | dwarf2_const_value_data (attr, sym, 8); | |
7300 | break; | |
c906108c | 7301 | case DW_FORM_data2: |
2df3850c JM |
7302 | dwarf2_const_value_data (attr, sym, 16); |
7303 | break; | |
c906108c | 7304 | case DW_FORM_data4: |
2df3850c JM |
7305 | dwarf2_const_value_data (attr, sym, 32); |
7306 | break; | |
c906108c | 7307 | case DW_FORM_data8: |
2df3850c JM |
7308 | dwarf2_const_value_data (attr, sym, 64); |
7309 | break; | |
7310 | ||
c906108c | 7311 | case DW_FORM_sdata: |
2df3850c JM |
7312 | SYMBOL_VALUE (sym) = DW_SND (attr); |
7313 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7314 | break; | |
7315 | ||
c906108c SS |
7316 | case DW_FORM_udata: |
7317 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
7318 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7319 | break; | |
2df3850c | 7320 | |
c906108c | 7321 | default: |
4d3c2250 | 7322 | complaint (&symfile_complaints, |
e2e0b3e5 | 7323 | _("unsupported const value attribute form: '%s'"), |
4d3c2250 | 7324 | dwarf_form_name (attr->form)); |
c906108c SS |
7325 | SYMBOL_VALUE (sym) = 0; |
7326 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7327 | break; | |
7328 | } | |
7329 | } | |
7330 | ||
2df3850c JM |
7331 | |
7332 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
7333 | or zero-extend it as appropriate for the symbol's type. */ | |
7334 | static void | |
7335 | dwarf2_const_value_data (struct attribute *attr, | |
7336 | struct symbol *sym, | |
7337 | int bits) | |
7338 | { | |
7339 | LONGEST l = DW_UNSND (attr); | |
7340 | ||
7341 | if (bits < sizeof (l) * 8) | |
7342 | { | |
7343 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
7344 | l &= ((LONGEST) 1 << bits) - 1; | |
7345 | else | |
bf9198f1 | 7346 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
7347 | } |
7348 | ||
7349 | SYMBOL_VALUE (sym) = l; | |
7350 | SYMBOL_CLASS (sym) = LOC_CONST; | |
7351 | } | |
7352 | ||
7353 | ||
c906108c SS |
7354 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
7355 | ||
7356 | static struct type * | |
e7c27a73 | 7357 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7358 | { |
7359 | struct type *type; | |
7360 | struct attribute *type_attr; | |
7361 | struct die_info *type_die; | |
c906108c | 7362 | |
e142c38c | 7363 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
7364 | if (!type_attr) |
7365 | { | |
7366 | /* A missing DW_AT_type represents a void type. */ | |
e142c38c | 7367 | return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); |
c906108c SS |
7368 | } |
7369 | else | |
10b3939b DJ |
7370 | type_die = follow_die_ref (die, type_attr, cu); |
7371 | ||
e7c27a73 | 7372 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7373 | if (!type) |
7374 | { | |
7375 | dump_die (type_die); | |
8a3fe4f8 | 7376 | error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), |
e7c27a73 | 7377 | cu->objfile->name); |
c906108c SS |
7378 | } |
7379 | return type; | |
7380 | } | |
7381 | ||
7382 | /* Return the containing type of the die in question using its | |
7383 | DW_AT_containing_type attribute. */ | |
7384 | ||
7385 | static struct type * | |
e7c27a73 | 7386 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7387 | { |
7388 | struct type *type = NULL; | |
7389 | struct attribute *type_attr; | |
7390 | struct die_info *type_die = NULL; | |
c906108c | 7391 | |
e142c38c | 7392 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
7393 | if (type_attr) |
7394 | { | |
10b3939b | 7395 | type_die = follow_die_ref (die, type_attr, cu); |
e7c27a73 | 7396 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
7397 | } |
7398 | if (!type) | |
7399 | { | |
7400 | if (type_die) | |
7401 | dump_die (type_die); | |
8a3fe4f8 | 7402 | error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), |
e7c27a73 | 7403 | cu->objfile->name); |
c906108c SS |
7404 | } |
7405 | return type; | |
7406 | } | |
7407 | ||
c906108c | 7408 | static struct type * |
e7c27a73 | 7409 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7410 | { |
7411 | if (die->type) | |
7412 | { | |
7413 | return die->type; | |
7414 | } | |
7415 | else | |
7416 | { | |
e7c27a73 | 7417 | read_type_die (die, cu); |
c906108c SS |
7418 | if (!die->type) |
7419 | { | |
7420 | dump_die (die); | |
8a3fe4f8 | 7421 | error (_("Dwarf Error: Cannot find type of die [in module %s]"), |
e7c27a73 | 7422 | cu->objfile->name); |
c906108c SS |
7423 | } |
7424 | return die->type; | |
7425 | } | |
7426 | } | |
7427 | ||
7428 | static void | |
e7c27a73 | 7429 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 7430 | { |
e142c38c | 7431 | char *prefix = determine_prefix (die, cu); |
63d06c5c DC |
7432 | const char *old_prefix = processing_current_prefix; |
7433 | struct cleanup *back_to = make_cleanup (xfree, prefix); | |
7434 | processing_current_prefix = prefix; | |
7435 | ||
c906108c SS |
7436 | switch (die->tag) |
7437 | { | |
7438 | case DW_TAG_class_type: | |
7439 | case DW_TAG_structure_type: | |
7440 | case DW_TAG_union_type: | |
134d01f1 | 7441 | read_structure_type (die, cu); |
c906108c SS |
7442 | break; |
7443 | case DW_TAG_enumeration_type: | |
134d01f1 | 7444 | read_enumeration_type (die, cu); |
c906108c SS |
7445 | break; |
7446 | case DW_TAG_subprogram: | |
7447 | case DW_TAG_subroutine_type: | |
e7c27a73 | 7448 | read_subroutine_type (die, cu); |
c906108c SS |
7449 | break; |
7450 | case DW_TAG_array_type: | |
e7c27a73 | 7451 | read_array_type (die, cu); |
c906108c | 7452 | break; |
72019c9c GM |
7453 | case DW_TAG_set_type: |
7454 | read_set_type (die, cu); | |
7455 | break; | |
c906108c | 7456 | case DW_TAG_pointer_type: |
e7c27a73 | 7457 | read_tag_pointer_type (die, cu); |
c906108c SS |
7458 | break; |
7459 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 7460 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
7461 | break; |
7462 | case DW_TAG_reference_type: | |
e7c27a73 | 7463 | read_tag_reference_type (die, cu); |
c906108c SS |
7464 | break; |
7465 | case DW_TAG_const_type: | |
e7c27a73 | 7466 | read_tag_const_type (die, cu); |
c906108c SS |
7467 | break; |
7468 | case DW_TAG_volatile_type: | |
e7c27a73 | 7469 | read_tag_volatile_type (die, cu); |
c906108c SS |
7470 | break; |
7471 | case DW_TAG_string_type: | |
e7c27a73 | 7472 | read_tag_string_type (die, cu); |
c906108c SS |
7473 | break; |
7474 | case DW_TAG_typedef: | |
e7c27a73 | 7475 | read_typedef (die, cu); |
c906108c | 7476 | break; |
a02abb62 JB |
7477 | case DW_TAG_subrange_type: |
7478 | read_subrange_type (die, cu); | |
7479 | break; | |
c906108c | 7480 | case DW_TAG_base_type: |
e7c27a73 | 7481 | read_base_type (die, cu); |
c906108c | 7482 | break; |
81a17f79 JB |
7483 | case DW_TAG_unspecified_type: |
7484 | read_unspecified_type (die, cu); | |
7485 | break; | |
c906108c | 7486 | default: |
a1f5b845 | 7487 | complaint (&symfile_complaints, _("unexpected tag in read_type_die: '%s'"), |
4d3c2250 | 7488 | dwarf_tag_name (die->tag)); |
c906108c SS |
7489 | break; |
7490 | } | |
63d06c5c DC |
7491 | |
7492 | processing_current_prefix = old_prefix; | |
7493 | do_cleanups (back_to); | |
7494 | } | |
7495 | ||
fdde2d81 DC |
7496 | /* Return the name of the namespace/class that DIE is defined within, |
7497 | or "" if we can't tell. The caller should xfree the result. */ | |
7498 | ||
7499 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
7500 | therein) for an example of how to use this function to deal with | |
7501 | DW_AT_specification. */ | |
7502 | ||
7503 | static char * | |
e142c38c | 7504 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
7505 | { |
7506 | struct die_info *parent; | |
7507 | ||
987504bb JJ |
7508 | if (cu->language != language_cplus |
7509 | && cu->language != language_java) | |
63d06c5c DC |
7510 | return NULL; |
7511 | ||
7512 | parent = die->parent; | |
7513 | ||
7514 | if (parent == NULL) | |
7515 | { | |
8176b9b8 | 7516 | return xstrdup (""); |
63d06c5c DC |
7517 | } |
7518 | else | |
7519 | { | |
63d06c5c DC |
7520 | switch (parent->tag) { |
7521 | case DW_TAG_namespace: | |
7522 | { | |
8176b9b8 DC |
7523 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
7524 | before doing this check? */ | |
7525 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) | |
7526 | { | |
7527 | return xstrdup (TYPE_TAG_NAME (parent->type)); | |
7528 | } | |
7529 | else | |
7530 | { | |
7531 | int dummy; | |
7532 | char *parent_prefix = determine_prefix (parent, cu); | |
987504bb | 7533 | char *retval = typename_concat (NULL, parent_prefix, |
8176b9b8 | 7534 | namespace_name (parent, &dummy, |
987504bb JJ |
7535 | cu), |
7536 | cu); | |
8176b9b8 DC |
7537 | xfree (parent_prefix); |
7538 | return retval; | |
7539 | } | |
63d06c5c DC |
7540 | } |
7541 | break; | |
7542 | case DW_TAG_class_type: | |
7543 | case DW_TAG_structure_type: | |
7544 | { | |
8176b9b8 | 7545 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) |
63d06c5c | 7546 | { |
8176b9b8 | 7547 | return xstrdup (TYPE_TAG_NAME (parent->type)); |
63d06c5c DC |
7548 | } |
7549 | else | |
8176b9b8 DC |
7550 | { |
7551 | const char *old_prefix = processing_current_prefix; | |
7552 | char *new_prefix = determine_prefix (parent, cu); | |
7553 | char *retval; | |
7554 | ||
7555 | processing_current_prefix = new_prefix; | |
7556 | retval = determine_class_name (parent, cu); | |
7557 | processing_current_prefix = old_prefix; | |
7558 | ||
7559 | xfree (new_prefix); | |
7560 | return retval; | |
7561 | } | |
63d06c5c | 7562 | } |
63d06c5c | 7563 | default: |
8176b9b8 | 7564 | return determine_prefix (parent, cu); |
63d06c5c | 7565 | } |
63d06c5c DC |
7566 | } |
7567 | } | |
7568 | ||
987504bb JJ |
7569 | /* Return a newly-allocated string formed by concatenating PREFIX and |
7570 | SUFFIX with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then | |
7571 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, | |
7572 | perform an obconcat, otherwise allocate storage for the result. The CU argument | |
7573 | is used to determine the language and hence, the appropriate separator. */ | |
7574 | ||
7575 | #define MAX_SEP_LEN 2 /* sizeof ("::") */ | |
63d06c5c DC |
7576 | |
7577 | static char * | |
987504bb JJ |
7578 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
7579 | struct dwarf2_cu *cu) | |
63d06c5c | 7580 | { |
987504bb | 7581 | char *sep; |
63d06c5c | 7582 | |
987504bb JJ |
7583 | if (suffix == NULL || suffix[0] == '\0' || prefix == NULL || prefix[0] == '\0') |
7584 | sep = ""; | |
7585 | else if (cu->language == language_java) | |
7586 | sep = "."; | |
7587 | else | |
7588 | sep = "::"; | |
63d06c5c | 7589 | |
987504bb JJ |
7590 | if (obs == NULL) |
7591 | { | |
7592 | char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); | |
7593 | retval[0] = '\0'; | |
7594 | ||
7595 | if (prefix) | |
7596 | { | |
7597 | strcpy (retval, prefix); | |
7598 | strcat (retval, sep); | |
7599 | } | |
7600 | if (suffix) | |
7601 | strcat (retval, suffix); | |
7602 | ||
63d06c5c DC |
7603 | return retval; |
7604 | } | |
987504bb JJ |
7605 | else |
7606 | { | |
7607 | /* We have an obstack. */ | |
7608 | return obconcat (obs, prefix, sep, suffix); | |
7609 | } | |
63d06c5c DC |
7610 | } |
7611 | ||
c906108c | 7612 | static struct type * |
e7c27a73 | 7613 | dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) |
c906108c | 7614 | { |
e7c27a73 DJ |
7615 | struct objfile *objfile = cu->objfile; |
7616 | ||
c906108c SS |
7617 | /* FIXME - this should not produce a new (struct type *) |
7618 | every time. It should cache base types. */ | |
7619 | struct type *type; | |
7620 | switch (encoding) | |
7621 | { | |
7622 | case DW_ATE_address: | |
e142c38c | 7623 | type = dwarf2_fundamental_type (objfile, FT_VOID, cu); |
c906108c SS |
7624 | return type; |
7625 | case DW_ATE_boolean: | |
e142c38c | 7626 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); |
c906108c SS |
7627 | return type; |
7628 | case DW_ATE_complex_float: | |
7629 | if (size == 16) | |
7630 | { | |
e142c38c | 7631 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); |
c906108c SS |
7632 | } |
7633 | else | |
7634 | { | |
e142c38c | 7635 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); |
c906108c SS |
7636 | } |
7637 | return type; | |
7638 | case DW_ATE_float: | |
7639 | if (size == 8) | |
7640 | { | |
e142c38c | 7641 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
c906108c SS |
7642 | } |
7643 | else | |
7644 | { | |
e142c38c | 7645 | type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
c906108c SS |
7646 | } |
7647 | return type; | |
7648 | case DW_ATE_signed: | |
7649 | switch (size) | |
7650 | { | |
7651 | case 1: | |
e142c38c | 7652 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
7653 | break; |
7654 | case 2: | |
e142c38c | 7655 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); |
c906108c SS |
7656 | break; |
7657 | default: | |
7658 | case 4: | |
e142c38c | 7659 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
7660 | break; |
7661 | } | |
7662 | return type; | |
7663 | case DW_ATE_signed_char: | |
e142c38c | 7664 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
7665 | return type; |
7666 | case DW_ATE_unsigned: | |
7667 | switch (size) | |
7668 | { | |
7669 | case 1: | |
e142c38c | 7670 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
7671 | break; |
7672 | case 2: | |
e142c38c | 7673 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); |
c906108c SS |
7674 | break; |
7675 | default: | |
7676 | case 4: | |
e142c38c | 7677 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); |
c906108c SS |
7678 | break; |
7679 | } | |
7680 | return type; | |
7681 | case DW_ATE_unsigned_char: | |
e142c38c | 7682 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
7683 | return type; |
7684 | default: | |
e142c38c | 7685 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
7686 | return type; |
7687 | } | |
7688 | } | |
7689 | ||
7690 | #if 0 | |
7691 | struct die_info * | |
fba45db2 | 7692 | copy_die (struct die_info *old_die) |
c906108c SS |
7693 | { |
7694 | struct die_info *new_die; | |
7695 | int i, num_attrs; | |
7696 | ||
7697 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
7698 | memset (new_die, 0, sizeof (struct die_info)); | |
7699 | ||
7700 | new_die->tag = old_die->tag; | |
7701 | new_die->has_children = old_die->has_children; | |
7702 | new_die->abbrev = old_die->abbrev; | |
7703 | new_die->offset = old_die->offset; | |
7704 | new_die->type = NULL; | |
7705 | ||
7706 | num_attrs = old_die->num_attrs; | |
7707 | new_die->num_attrs = num_attrs; | |
7708 | new_die->attrs = (struct attribute *) | |
7709 | xmalloc (num_attrs * sizeof (struct attribute)); | |
7710 | ||
7711 | for (i = 0; i < old_die->num_attrs; ++i) | |
7712 | { | |
7713 | new_die->attrs[i].name = old_die->attrs[i].name; | |
7714 | new_die->attrs[i].form = old_die->attrs[i].form; | |
7715 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
7716 | } | |
7717 | ||
7718 | new_die->next = NULL; | |
7719 | return new_die; | |
7720 | } | |
7721 | #endif | |
7722 | ||
7723 | /* Return sibling of die, NULL if no sibling. */ | |
7724 | ||
f9aca02d | 7725 | static struct die_info * |
fba45db2 | 7726 | sibling_die (struct die_info *die) |
c906108c | 7727 | { |
639d11d3 | 7728 | return die->sibling; |
c906108c SS |
7729 | } |
7730 | ||
7731 | /* Get linkage name of a die, return NULL if not found. */ | |
7732 | ||
7733 | static char * | |
e142c38c | 7734 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
7735 | { |
7736 | struct attribute *attr; | |
7737 | ||
e142c38c | 7738 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
7739 | if (attr && DW_STRING (attr)) |
7740 | return DW_STRING (attr); | |
e142c38c | 7741 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
7742 | if (attr && DW_STRING (attr)) |
7743 | return DW_STRING (attr); | |
7744 | return NULL; | |
7745 | } | |
7746 | ||
9219021c DC |
7747 | /* Get name of a die, return NULL if not found. */ |
7748 | ||
7749 | static char * | |
e142c38c | 7750 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
7751 | { |
7752 | struct attribute *attr; | |
7753 | ||
e142c38c | 7754 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
7755 | if (attr && DW_STRING (attr)) |
7756 | return DW_STRING (attr); | |
7757 | return NULL; | |
7758 | } | |
7759 | ||
7760 | /* Return the die that this die in an extension of, or NULL if there | |
7761 | is none. */ | |
7762 | ||
7763 | static struct die_info * | |
e142c38c | 7764 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
7765 | { |
7766 | struct attribute *attr; | |
9219021c | 7767 | |
e142c38c | 7768 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
7769 | if (attr == NULL) |
7770 | return NULL; | |
7771 | ||
10b3939b | 7772 | return follow_die_ref (die, attr, cu); |
9219021c DC |
7773 | } |
7774 | ||
c906108c SS |
7775 | /* Convert a DIE tag into its string name. */ |
7776 | ||
7777 | static char * | |
aa1ee363 | 7778 | dwarf_tag_name (unsigned tag) |
c906108c SS |
7779 | { |
7780 | switch (tag) | |
7781 | { | |
7782 | case DW_TAG_padding: | |
7783 | return "DW_TAG_padding"; | |
7784 | case DW_TAG_array_type: | |
7785 | return "DW_TAG_array_type"; | |
7786 | case DW_TAG_class_type: | |
7787 | return "DW_TAG_class_type"; | |
7788 | case DW_TAG_entry_point: | |
7789 | return "DW_TAG_entry_point"; | |
7790 | case DW_TAG_enumeration_type: | |
7791 | return "DW_TAG_enumeration_type"; | |
7792 | case DW_TAG_formal_parameter: | |
7793 | return "DW_TAG_formal_parameter"; | |
7794 | case DW_TAG_imported_declaration: | |
7795 | return "DW_TAG_imported_declaration"; | |
7796 | case DW_TAG_label: | |
7797 | return "DW_TAG_label"; | |
7798 | case DW_TAG_lexical_block: | |
7799 | return "DW_TAG_lexical_block"; | |
7800 | case DW_TAG_member: | |
7801 | return "DW_TAG_member"; | |
7802 | case DW_TAG_pointer_type: | |
7803 | return "DW_TAG_pointer_type"; | |
7804 | case DW_TAG_reference_type: | |
7805 | return "DW_TAG_reference_type"; | |
7806 | case DW_TAG_compile_unit: | |
7807 | return "DW_TAG_compile_unit"; | |
7808 | case DW_TAG_string_type: | |
7809 | return "DW_TAG_string_type"; | |
7810 | case DW_TAG_structure_type: | |
7811 | return "DW_TAG_structure_type"; | |
7812 | case DW_TAG_subroutine_type: | |
7813 | return "DW_TAG_subroutine_type"; | |
7814 | case DW_TAG_typedef: | |
7815 | return "DW_TAG_typedef"; | |
7816 | case DW_TAG_union_type: | |
7817 | return "DW_TAG_union_type"; | |
7818 | case DW_TAG_unspecified_parameters: | |
7819 | return "DW_TAG_unspecified_parameters"; | |
7820 | case DW_TAG_variant: | |
7821 | return "DW_TAG_variant"; | |
7822 | case DW_TAG_common_block: | |
7823 | return "DW_TAG_common_block"; | |
7824 | case DW_TAG_common_inclusion: | |
7825 | return "DW_TAG_common_inclusion"; | |
7826 | case DW_TAG_inheritance: | |
7827 | return "DW_TAG_inheritance"; | |
7828 | case DW_TAG_inlined_subroutine: | |
7829 | return "DW_TAG_inlined_subroutine"; | |
7830 | case DW_TAG_module: | |
7831 | return "DW_TAG_module"; | |
7832 | case DW_TAG_ptr_to_member_type: | |
7833 | return "DW_TAG_ptr_to_member_type"; | |
7834 | case DW_TAG_set_type: | |
7835 | return "DW_TAG_set_type"; | |
7836 | case DW_TAG_subrange_type: | |
7837 | return "DW_TAG_subrange_type"; | |
7838 | case DW_TAG_with_stmt: | |
7839 | return "DW_TAG_with_stmt"; | |
7840 | case DW_TAG_access_declaration: | |
7841 | return "DW_TAG_access_declaration"; | |
7842 | case DW_TAG_base_type: | |
7843 | return "DW_TAG_base_type"; | |
7844 | case DW_TAG_catch_block: | |
7845 | return "DW_TAG_catch_block"; | |
7846 | case DW_TAG_const_type: | |
7847 | return "DW_TAG_const_type"; | |
7848 | case DW_TAG_constant: | |
7849 | return "DW_TAG_constant"; | |
7850 | case DW_TAG_enumerator: | |
7851 | return "DW_TAG_enumerator"; | |
7852 | case DW_TAG_file_type: | |
7853 | return "DW_TAG_file_type"; | |
7854 | case DW_TAG_friend: | |
7855 | return "DW_TAG_friend"; | |
7856 | case DW_TAG_namelist: | |
7857 | return "DW_TAG_namelist"; | |
7858 | case DW_TAG_namelist_item: | |
7859 | return "DW_TAG_namelist_item"; | |
7860 | case DW_TAG_packed_type: | |
7861 | return "DW_TAG_packed_type"; | |
7862 | case DW_TAG_subprogram: | |
7863 | return "DW_TAG_subprogram"; | |
7864 | case DW_TAG_template_type_param: | |
7865 | return "DW_TAG_template_type_param"; | |
7866 | case DW_TAG_template_value_param: | |
7867 | return "DW_TAG_template_value_param"; | |
7868 | case DW_TAG_thrown_type: | |
7869 | return "DW_TAG_thrown_type"; | |
7870 | case DW_TAG_try_block: | |
7871 | return "DW_TAG_try_block"; | |
7872 | case DW_TAG_variant_part: | |
7873 | return "DW_TAG_variant_part"; | |
7874 | case DW_TAG_variable: | |
7875 | return "DW_TAG_variable"; | |
7876 | case DW_TAG_volatile_type: | |
7877 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
7878 | case DW_TAG_dwarf_procedure: |
7879 | return "DW_TAG_dwarf_procedure"; | |
7880 | case DW_TAG_restrict_type: | |
7881 | return "DW_TAG_restrict_type"; | |
7882 | case DW_TAG_interface_type: | |
7883 | return "DW_TAG_interface_type"; | |
7884 | case DW_TAG_namespace: | |
7885 | return "DW_TAG_namespace"; | |
7886 | case DW_TAG_imported_module: | |
7887 | return "DW_TAG_imported_module"; | |
7888 | case DW_TAG_unspecified_type: | |
7889 | return "DW_TAG_unspecified_type"; | |
7890 | case DW_TAG_partial_unit: | |
7891 | return "DW_TAG_partial_unit"; | |
7892 | case DW_TAG_imported_unit: | |
7893 | return "DW_TAG_imported_unit"; | |
b7619582 GF |
7894 | case DW_TAG_condition: |
7895 | return "DW_TAG_condition"; | |
7896 | case DW_TAG_shared_type: | |
7897 | return "DW_TAG_shared_type"; | |
c906108c SS |
7898 | case DW_TAG_MIPS_loop: |
7899 | return "DW_TAG_MIPS_loop"; | |
b7619582 GF |
7900 | case DW_TAG_HP_array_descriptor: |
7901 | return "DW_TAG_HP_array_descriptor"; | |
c906108c SS |
7902 | case DW_TAG_format_label: |
7903 | return "DW_TAG_format_label"; | |
7904 | case DW_TAG_function_template: | |
7905 | return "DW_TAG_function_template"; | |
7906 | case DW_TAG_class_template: | |
7907 | return "DW_TAG_class_template"; | |
b7619582 GF |
7908 | case DW_TAG_GNU_BINCL: |
7909 | return "DW_TAG_GNU_BINCL"; | |
7910 | case DW_TAG_GNU_EINCL: | |
7911 | return "DW_TAG_GNU_EINCL"; | |
7912 | case DW_TAG_upc_shared_type: | |
7913 | return "DW_TAG_upc_shared_type"; | |
7914 | case DW_TAG_upc_strict_type: | |
7915 | return "DW_TAG_upc_strict_type"; | |
7916 | case DW_TAG_upc_relaxed_type: | |
7917 | return "DW_TAG_upc_relaxed_type"; | |
7918 | case DW_TAG_PGI_kanji_type: | |
7919 | return "DW_TAG_PGI_kanji_type"; | |
7920 | case DW_TAG_PGI_interface_block: | |
7921 | return "DW_TAG_PGI_interface_block"; | |
c906108c SS |
7922 | default: |
7923 | return "DW_TAG_<unknown>"; | |
7924 | } | |
7925 | } | |
7926 | ||
7927 | /* Convert a DWARF attribute code into its string name. */ | |
7928 | ||
7929 | static char * | |
aa1ee363 | 7930 | dwarf_attr_name (unsigned attr) |
c906108c SS |
7931 | { |
7932 | switch (attr) | |
7933 | { | |
7934 | case DW_AT_sibling: | |
7935 | return "DW_AT_sibling"; | |
7936 | case DW_AT_location: | |
7937 | return "DW_AT_location"; | |
7938 | case DW_AT_name: | |
7939 | return "DW_AT_name"; | |
7940 | case DW_AT_ordering: | |
7941 | return "DW_AT_ordering"; | |
7942 | case DW_AT_subscr_data: | |
7943 | return "DW_AT_subscr_data"; | |
7944 | case DW_AT_byte_size: | |
7945 | return "DW_AT_byte_size"; | |
7946 | case DW_AT_bit_offset: | |
7947 | return "DW_AT_bit_offset"; | |
7948 | case DW_AT_bit_size: | |
7949 | return "DW_AT_bit_size"; | |
7950 | case DW_AT_element_list: | |
7951 | return "DW_AT_element_list"; | |
7952 | case DW_AT_stmt_list: | |
7953 | return "DW_AT_stmt_list"; | |
7954 | case DW_AT_low_pc: | |
7955 | return "DW_AT_low_pc"; | |
7956 | case DW_AT_high_pc: | |
7957 | return "DW_AT_high_pc"; | |
7958 | case DW_AT_language: | |
7959 | return "DW_AT_language"; | |
7960 | case DW_AT_member: | |
7961 | return "DW_AT_member"; | |
7962 | case DW_AT_discr: | |
7963 | return "DW_AT_discr"; | |
7964 | case DW_AT_discr_value: | |
7965 | return "DW_AT_discr_value"; | |
7966 | case DW_AT_visibility: | |
7967 | return "DW_AT_visibility"; | |
7968 | case DW_AT_import: | |
7969 | return "DW_AT_import"; | |
7970 | case DW_AT_string_length: | |
7971 | return "DW_AT_string_length"; | |
7972 | case DW_AT_common_reference: | |
7973 | return "DW_AT_common_reference"; | |
7974 | case DW_AT_comp_dir: | |
7975 | return "DW_AT_comp_dir"; | |
7976 | case DW_AT_const_value: | |
7977 | return "DW_AT_const_value"; | |
7978 | case DW_AT_containing_type: | |
7979 | return "DW_AT_containing_type"; | |
7980 | case DW_AT_default_value: | |
7981 | return "DW_AT_default_value"; | |
7982 | case DW_AT_inline: | |
7983 | return "DW_AT_inline"; | |
7984 | case DW_AT_is_optional: | |
7985 | return "DW_AT_is_optional"; | |
7986 | case DW_AT_lower_bound: | |
7987 | return "DW_AT_lower_bound"; | |
7988 | case DW_AT_producer: | |
7989 | return "DW_AT_producer"; | |
7990 | case DW_AT_prototyped: | |
7991 | return "DW_AT_prototyped"; | |
7992 | case DW_AT_return_addr: | |
7993 | return "DW_AT_return_addr"; | |
7994 | case DW_AT_start_scope: | |
7995 | return "DW_AT_start_scope"; | |
7996 | case DW_AT_stride_size: | |
7997 | return "DW_AT_stride_size"; | |
7998 | case DW_AT_upper_bound: | |
7999 | return "DW_AT_upper_bound"; | |
8000 | case DW_AT_abstract_origin: | |
8001 | return "DW_AT_abstract_origin"; | |
8002 | case DW_AT_accessibility: | |
8003 | return "DW_AT_accessibility"; | |
8004 | case DW_AT_address_class: | |
8005 | return "DW_AT_address_class"; | |
8006 | case DW_AT_artificial: | |
8007 | return "DW_AT_artificial"; | |
8008 | case DW_AT_base_types: | |
8009 | return "DW_AT_base_types"; | |
8010 | case DW_AT_calling_convention: | |
8011 | return "DW_AT_calling_convention"; | |
8012 | case DW_AT_count: | |
8013 | return "DW_AT_count"; | |
8014 | case DW_AT_data_member_location: | |
8015 | return "DW_AT_data_member_location"; | |
8016 | case DW_AT_decl_column: | |
8017 | return "DW_AT_decl_column"; | |
8018 | case DW_AT_decl_file: | |
8019 | return "DW_AT_decl_file"; | |
8020 | case DW_AT_decl_line: | |
8021 | return "DW_AT_decl_line"; | |
8022 | case DW_AT_declaration: | |
8023 | return "DW_AT_declaration"; | |
8024 | case DW_AT_discr_list: | |
8025 | return "DW_AT_discr_list"; | |
8026 | case DW_AT_encoding: | |
8027 | return "DW_AT_encoding"; | |
8028 | case DW_AT_external: | |
8029 | return "DW_AT_external"; | |
8030 | case DW_AT_frame_base: | |
8031 | return "DW_AT_frame_base"; | |
8032 | case DW_AT_friend: | |
8033 | return "DW_AT_friend"; | |
8034 | case DW_AT_identifier_case: | |
8035 | return "DW_AT_identifier_case"; | |
8036 | case DW_AT_macro_info: | |
8037 | return "DW_AT_macro_info"; | |
8038 | case DW_AT_namelist_items: | |
8039 | return "DW_AT_namelist_items"; | |
8040 | case DW_AT_priority: | |
8041 | return "DW_AT_priority"; | |
8042 | case DW_AT_segment: | |
8043 | return "DW_AT_segment"; | |
8044 | case DW_AT_specification: | |
8045 | return "DW_AT_specification"; | |
8046 | case DW_AT_static_link: | |
8047 | return "DW_AT_static_link"; | |
8048 | case DW_AT_type: | |
8049 | return "DW_AT_type"; | |
8050 | case DW_AT_use_location: | |
8051 | return "DW_AT_use_location"; | |
8052 | case DW_AT_variable_parameter: | |
8053 | return "DW_AT_variable_parameter"; | |
8054 | case DW_AT_virtuality: | |
8055 | return "DW_AT_virtuality"; | |
8056 | case DW_AT_vtable_elem_location: | |
8057 | return "DW_AT_vtable_elem_location"; | |
b7619582 | 8058 | /* DWARF 3 values. */ |
d9fa45fe DC |
8059 | case DW_AT_allocated: |
8060 | return "DW_AT_allocated"; | |
8061 | case DW_AT_associated: | |
8062 | return "DW_AT_associated"; | |
8063 | case DW_AT_data_location: | |
8064 | return "DW_AT_data_location"; | |
8065 | case DW_AT_stride: | |
8066 | return "DW_AT_stride"; | |
8067 | case DW_AT_entry_pc: | |
8068 | return "DW_AT_entry_pc"; | |
8069 | case DW_AT_use_UTF8: | |
8070 | return "DW_AT_use_UTF8"; | |
8071 | case DW_AT_extension: | |
8072 | return "DW_AT_extension"; | |
8073 | case DW_AT_ranges: | |
8074 | return "DW_AT_ranges"; | |
8075 | case DW_AT_trampoline: | |
8076 | return "DW_AT_trampoline"; | |
8077 | case DW_AT_call_column: | |
8078 | return "DW_AT_call_column"; | |
8079 | case DW_AT_call_file: | |
8080 | return "DW_AT_call_file"; | |
8081 | case DW_AT_call_line: | |
8082 | return "DW_AT_call_line"; | |
b7619582 GF |
8083 | case DW_AT_description: |
8084 | return "DW_AT_description"; | |
8085 | case DW_AT_binary_scale: | |
8086 | return "DW_AT_binary_scale"; | |
8087 | case DW_AT_decimal_scale: | |
8088 | return "DW_AT_decimal_scale"; | |
8089 | case DW_AT_small: | |
8090 | return "DW_AT_small"; | |
8091 | case DW_AT_decimal_sign: | |
8092 | return "DW_AT_decimal_sign"; | |
8093 | case DW_AT_digit_count: | |
8094 | return "DW_AT_digit_count"; | |
8095 | case DW_AT_picture_string: | |
8096 | return "DW_AT_picture_string"; | |
8097 | case DW_AT_mutable: | |
8098 | return "DW_AT_mutable"; | |
8099 | case DW_AT_threads_scaled: | |
8100 | return "DW_AT_threads_scaled"; | |
8101 | case DW_AT_explicit: | |
8102 | return "DW_AT_explicit"; | |
8103 | case DW_AT_object_pointer: | |
8104 | return "DW_AT_object_pointer"; | |
8105 | case DW_AT_endianity: | |
8106 | return "DW_AT_endianity"; | |
8107 | case DW_AT_elemental: | |
8108 | return "DW_AT_elemental"; | |
8109 | case DW_AT_pure: | |
8110 | return "DW_AT_pure"; | |
8111 | case DW_AT_recursive: | |
8112 | return "DW_AT_recursive"; | |
c906108c | 8113 | #ifdef MIPS |
b7619582 | 8114 | /* SGI/MIPS extensions. */ |
c906108c SS |
8115 | case DW_AT_MIPS_fde: |
8116 | return "DW_AT_MIPS_fde"; | |
8117 | case DW_AT_MIPS_loop_begin: | |
8118 | return "DW_AT_MIPS_loop_begin"; | |
8119 | case DW_AT_MIPS_tail_loop_begin: | |
8120 | return "DW_AT_MIPS_tail_loop_begin"; | |
8121 | case DW_AT_MIPS_epilog_begin: | |
8122 | return "DW_AT_MIPS_epilog_begin"; | |
8123 | case DW_AT_MIPS_loop_unroll_factor: | |
8124 | return "DW_AT_MIPS_loop_unroll_factor"; | |
8125 | case DW_AT_MIPS_software_pipeline_depth: | |
8126 | return "DW_AT_MIPS_software_pipeline_depth"; | |
8127 | case DW_AT_MIPS_linkage_name: | |
8128 | return "DW_AT_MIPS_linkage_name"; | |
b7619582 GF |
8129 | case DW_AT_MIPS_stride: |
8130 | return "DW_AT_MIPS_stride"; | |
8131 | case DW_AT_MIPS_abstract_name: | |
8132 | return "DW_AT_MIPS_abstract_name"; | |
8133 | case DW_AT_MIPS_clone_origin: | |
8134 | return "DW_AT_MIPS_clone_origin"; | |
8135 | case DW_AT_MIPS_has_inlines: | |
8136 | return "DW_AT_MIPS_has_inlines"; | |
8137 | #endif | |
8138 | /* HP extensions. */ | |
8139 | case DW_AT_HP_block_index: | |
8140 | return "DW_AT_HP_block_index"; | |
8141 | case DW_AT_HP_unmodifiable: | |
8142 | return "DW_AT_HP_unmodifiable"; | |
8143 | case DW_AT_HP_actuals_stmt_list: | |
8144 | return "DW_AT_HP_actuals_stmt_list"; | |
8145 | case DW_AT_HP_proc_per_section: | |
8146 | return "DW_AT_HP_proc_per_section"; | |
8147 | case DW_AT_HP_raw_data_ptr: | |
8148 | return "DW_AT_HP_raw_data_ptr"; | |
8149 | case DW_AT_HP_pass_by_reference: | |
8150 | return "DW_AT_HP_pass_by_reference"; | |
8151 | case DW_AT_HP_opt_level: | |
8152 | return "DW_AT_HP_opt_level"; | |
8153 | case DW_AT_HP_prof_version_id: | |
8154 | return "DW_AT_HP_prof_version_id"; | |
8155 | case DW_AT_HP_opt_flags: | |
8156 | return "DW_AT_HP_opt_flags"; | |
8157 | case DW_AT_HP_cold_region_low_pc: | |
8158 | return "DW_AT_HP_cold_region_low_pc"; | |
8159 | case DW_AT_HP_cold_region_high_pc: | |
8160 | return "DW_AT_HP_cold_region_high_pc"; | |
8161 | case DW_AT_HP_all_variables_modifiable: | |
8162 | return "DW_AT_HP_all_variables_modifiable"; | |
8163 | case DW_AT_HP_linkage_name: | |
8164 | return "DW_AT_HP_linkage_name"; | |
8165 | case DW_AT_HP_prof_flags: | |
8166 | return "DW_AT_HP_prof_flags"; | |
8167 | /* GNU extensions. */ | |
c906108c SS |
8168 | case DW_AT_sf_names: |
8169 | return "DW_AT_sf_names"; | |
8170 | case DW_AT_src_info: | |
8171 | return "DW_AT_src_info"; | |
8172 | case DW_AT_mac_info: | |
8173 | return "DW_AT_mac_info"; | |
8174 | case DW_AT_src_coords: | |
8175 | return "DW_AT_src_coords"; | |
8176 | case DW_AT_body_begin: | |
8177 | return "DW_AT_body_begin"; | |
8178 | case DW_AT_body_end: | |
8179 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
8180 | case DW_AT_GNU_vector: |
8181 | return "DW_AT_GNU_vector"; | |
b7619582 GF |
8182 | /* VMS extensions. */ |
8183 | case DW_AT_VMS_rtnbeg_pd_address: | |
8184 | return "DW_AT_VMS_rtnbeg_pd_address"; | |
8185 | /* UPC extension. */ | |
8186 | case DW_AT_upc_threads_scaled: | |
8187 | return "DW_AT_upc_threads_scaled"; | |
8188 | /* PGI (STMicroelectronics) extensions. */ | |
8189 | case DW_AT_PGI_lbase: | |
8190 | return "DW_AT_PGI_lbase"; | |
8191 | case DW_AT_PGI_soffset: | |
8192 | return "DW_AT_PGI_soffset"; | |
8193 | case DW_AT_PGI_lstride: | |
8194 | return "DW_AT_PGI_lstride"; | |
c906108c SS |
8195 | default: |
8196 | return "DW_AT_<unknown>"; | |
8197 | } | |
8198 | } | |
8199 | ||
8200 | /* Convert a DWARF value form code into its string name. */ | |
8201 | ||
8202 | static char * | |
aa1ee363 | 8203 | dwarf_form_name (unsigned form) |
c906108c SS |
8204 | { |
8205 | switch (form) | |
8206 | { | |
8207 | case DW_FORM_addr: | |
8208 | return "DW_FORM_addr"; | |
8209 | case DW_FORM_block2: | |
8210 | return "DW_FORM_block2"; | |
8211 | case DW_FORM_block4: | |
8212 | return "DW_FORM_block4"; | |
8213 | case DW_FORM_data2: | |
8214 | return "DW_FORM_data2"; | |
8215 | case DW_FORM_data4: | |
8216 | return "DW_FORM_data4"; | |
8217 | case DW_FORM_data8: | |
8218 | return "DW_FORM_data8"; | |
8219 | case DW_FORM_string: | |
8220 | return "DW_FORM_string"; | |
8221 | case DW_FORM_block: | |
8222 | return "DW_FORM_block"; | |
8223 | case DW_FORM_block1: | |
8224 | return "DW_FORM_block1"; | |
8225 | case DW_FORM_data1: | |
8226 | return "DW_FORM_data1"; | |
8227 | case DW_FORM_flag: | |
8228 | return "DW_FORM_flag"; | |
8229 | case DW_FORM_sdata: | |
8230 | return "DW_FORM_sdata"; | |
8231 | case DW_FORM_strp: | |
8232 | return "DW_FORM_strp"; | |
8233 | case DW_FORM_udata: | |
8234 | return "DW_FORM_udata"; | |
8235 | case DW_FORM_ref_addr: | |
8236 | return "DW_FORM_ref_addr"; | |
8237 | case DW_FORM_ref1: | |
8238 | return "DW_FORM_ref1"; | |
8239 | case DW_FORM_ref2: | |
8240 | return "DW_FORM_ref2"; | |
8241 | case DW_FORM_ref4: | |
8242 | return "DW_FORM_ref4"; | |
8243 | case DW_FORM_ref8: | |
8244 | return "DW_FORM_ref8"; | |
8245 | case DW_FORM_ref_udata: | |
8246 | return "DW_FORM_ref_udata"; | |
8247 | case DW_FORM_indirect: | |
8248 | return "DW_FORM_indirect"; | |
8249 | default: | |
8250 | return "DW_FORM_<unknown>"; | |
8251 | } | |
8252 | } | |
8253 | ||
8254 | /* Convert a DWARF stack opcode into its string name. */ | |
8255 | ||
8256 | static char * | |
aa1ee363 | 8257 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
8258 | { |
8259 | switch (op) | |
8260 | { | |
8261 | case DW_OP_addr: | |
8262 | return "DW_OP_addr"; | |
8263 | case DW_OP_deref: | |
8264 | return "DW_OP_deref"; | |
8265 | case DW_OP_const1u: | |
8266 | return "DW_OP_const1u"; | |
8267 | case DW_OP_const1s: | |
8268 | return "DW_OP_const1s"; | |
8269 | case DW_OP_const2u: | |
8270 | return "DW_OP_const2u"; | |
8271 | case DW_OP_const2s: | |
8272 | return "DW_OP_const2s"; | |
8273 | case DW_OP_const4u: | |
8274 | return "DW_OP_const4u"; | |
8275 | case DW_OP_const4s: | |
8276 | return "DW_OP_const4s"; | |
8277 | case DW_OP_const8u: | |
8278 | return "DW_OP_const8u"; | |
8279 | case DW_OP_const8s: | |
8280 | return "DW_OP_const8s"; | |
8281 | case DW_OP_constu: | |
8282 | return "DW_OP_constu"; | |
8283 | case DW_OP_consts: | |
8284 | return "DW_OP_consts"; | |
8285 | case DW_OP_dup: | |
8286 | return "DW_OP_dup"; | |
8287 | case DW_OP_drop: | |
8288 | return "DW_OP_drop"; | |
8289 | case DW_OP_over: | |
8290 | return "DW_OP_over"; | |
8291 | case DW_OP_pick: | |
8292 | return "DW_OP_pick"; | |
8293 | case DW_OP_swap: | |
8294 | return "DW_OP_swap"; | |
8295 | case DW_OP_rot: | |
8296 | return "DW_OP_rot"; | |
8297 | case DW_OP_xderef: | |
8298 | return "DW_OP_xderef"; | |
8299 | case DW_OP_abs: | |
8300 | return "DW_OP_abs"; | |
8301 | case DW_OP_and: | |
8302 | return "DW_OP_and"; | |
8303 | case DW_OP_div: | |
8304 | return "DW_OP_div"; | |
8305 | case DW_OP_minus: | |
8306 | return "DW_OP_minus"; | |
8307 | case DW_OP_mod: | |
8308 | return "DW_OP_mod"; | |
8309 | case DW_OP_mul: | |
8310 | return "DW_OP_mul"; | |
8311 | case DW_OP_neg: | |
8312 | return "DW_OP_neg"; | |
8313 | case DW_OP_not: | |
8314 | return "DW_OP_not"; | |
8315 | case DW_OP_or: | |
8316 | return "DW_OP_or"; | |
8317 | case DW_OP_plus: | |
8318 | return "DW_OP_plus"; | |
8319 | case DW_OP_plus_uconst: | |
8320 | return "DW_OP_plus_uconst"; | |
8321 | case DW_OP_shl: | |
8322 | return "DW_OP_shl"; | |
8323 | case DW_OP_shr: | |
8324 | return "DW_OP_shr"; | |
8325 | case DW_OP_shra: | |
8326 | return "DW_OP_shra"; | |
8327 | case DW_OP_xor: | |
8328 | return "DW_OP_xor"; | |
8329 | case DW_OP_bra: | |
8330 | return "DW_OP_bra"; | |
8331 | case DW_OP_eq: | |
8332 | return "DW_OP_eq"; | |
8333 | case DW_OP_ge: | |
8334 | return "DW_OP_ge"; | |
8335 | case DW_OP_gt: | |
8336 | return "DW_OP_gt"; | |
8337 | case DW_OP_le: | |
8338 | return "DW_OP_le"; | |
8339 | case DW_OP_lt: | |
8340 | return "DW_OP_lt"; | |
8341 | case DW_OP_ne: | |
8342 | return "DW_OP_ne"; | |
8343 | case DW_OP_skip: | |
8344 | return "DW_OP_skip"; | |
8345 | case DW_OP_lit0: | |
8346 | return "DW_OP_lit0"; | |
8347 | case DW_OP_lit1: | |
8348 | return "DW_OP_lit1"; | |
8349 | case DW_OP_lit2: | |
8350 | return "DW_OP_lit2"; | |
8351 | case DW_OP_lit3: | |
8352 | return "DW_OP_lit3"; | |
8353 | case DW_OP_lit4: | |
8354 | return "DW_OP_lit4"; | |
8355 | case DW_OP_lit5: | |
8356 | return "DW_OP_lit5"; | |
8357 | case DW_OP_lit6: | |
8358 | return "DW_OP_lit6"; | |
8359 | case DW_OP_lit7: | |
8360 | return "DW_OP_lit7"; | |
8361 | case DW_OP_lit8: | |
8362 | return "DW_OP_lit8"; | |
8363 | case DW_OP_lit9: | |
8364 | return "DW_OP_lit9"; | |
8365 | case DW_OP_lit10: | |
8366 | return "DW_OP_lit10"; | |
8367 | case DW_OP_lit11: | |
8368 | return "DW_OP_lit11"; | |
8369 | case DW_OP_lit12: | |
8370 | return "DW_OP_lit12"; | |
8371 | case DW_OP_lit13: | |
8372 | return "DW_OP_lit13"; | |
8373 | case DW_OP_lit14: | |
8374 | return "DW_OP_lit14"; | |
8375 | case DW_OP_lit15: | |
8376 | return "DW_OP_lit15"; | |
8377 | case DW_OP_lit16: | |
8378 | return "DW_OP_lit16"; | |
8379 | case DW_OP_lit17: | |
8380 | return "DW_OP_lit17"; | |
8381 | case DW_OP_lit18: | |
8382 | return "DW_OP_lit18"; | |
8383 | case DW_OP_lit19: | |
8384 | return "DW_OP_lit19"; | |
8385 | case DW_OP_lit20: | |
8386 | return "DW_OP_lit20"; | |
8387 | case DW_OP_lit21: | |
8388 | return "DW_OP_lit21"; | |
8389 | case DW_OP_lit22: | |
8390 | return "DW_OP_lit22"; | |
8391 | case DW_OP_lit23: | |
8392 | return "DW_OP_lit23"; | |
8393 | case DW_OP_lit24: | |
8394 | return "DW_OP_lit24"; | |
8395 | case DW_OP_lit25: | |
8396 | return "DW_OP_lit25"; | |
8397 | case DW_OP_lit26: | |
8398 | return "DW_OP_lit26"; | |
8399 | case DW_OP_lit27: | |
8400 | return "DW_OP_lit27"; | |
8401 | case DW_OP_lit28: | |
8402 | return "DW_OP_lit28"; | |
8403 | case DW_OP_lit29: | |
8404 | return "DW_OP_lit29"; | |
8405 | case DW_OP_lit30: | |
8406 | return "DW_OP_lit30"; | |
8407 | case DW_OP_lit31: | |
8408 | return "DW_OP_lit31"; | |
8409 | case DW_OP_reg0: | |
8410 | return "DW_OP_reg0"; | |
8411 | case DW_OP_reg1: | |
8412 | return "DW_OP_reg1"; | |
8413 | case DW_OP_reg2: | |
8414 | return "DW_OP_reg2"; | |
8415 | case DW_OP_reg3: | |
8416 | return "DW_OP_reg3"; | |
8417 | case DW_OP_reg4: | |
8418 | return "DW_OP_reg4"; | |
8419 | case DW_OP_reg5: | |
8420 | return "DW_OP_reg5"; | |
8421 | case DW_OP_reg6: | |
8422 | return "DW_OP_reg6"; | |
8423 | case DW_OP_reg7: | |
8424 | return "DW_OP_reg7"; | |
8425 | case DW_OP_reg8: | |
8426 | return "DW_OP_reg8"; | |
8427 | case DW_OP_reg9: | |
8428 | return "DW_OP_reg9"; | |
8429 | case DW_OP_reg10: | |
8430 | return "DW_OP_reg10"; | |
8431 | case DW_OP_reg11: | |
8432 | return "DW_OP_reg11"; | |
8433 | case DW_OP_reg12: | |
8434 | return "DW_OP_reg12"; | |
8435 | case DW_OP_reg13: | |
8436 | return "DW_OP_reg13"; | |
8437 | case DW_OP_reg14: | |
8438 | return "DW_OP_reg14"; | |
8439 | case DW_OP_reg15: | |
8440 | return "DW_OP_reg15"; | |
8441 | case DW_OP_reg16: | |
8442 | return "DW_OP_reg16"; | |
8443 | case DW_OP_reg17: | |
8444 | return "DW_OP_reg17"; | |
8445 | case DW_OP_reg18: | |
8446 | return "DW_OP_reg18"; | |
8447 | case DW_OP_reg19: | |
8448 | return "DW_OP_reg19"; | |
8449 | case DW_OP_reg20: | |
8450 | return "DW_OP_reg20"; | |
8451 | case DW_OP_reg21: | |
8452 | return "DW_OP_reg21"; | |
8453 | case DW_OP_reg22: | |
8454 | return "DW_OP_reg22"; | |
8455 | case DW_OP_reg23: | |
8456 | return "DW_OP_reg23"; | |
8457 | case DW_OP_reg24: | |
8458 | return "DW_OP_reg24"; | |
8459 | case DW_OP_reg25: | |
8460 | return "DW_OP_reg25"; | |
8461 | case DW_OP_reg26: | |
8462 | return "DW_OP_reg26"; | |
8463 | case DW_OP_reg27: | |
8464 | return "DW_OP_reg27"; | |
8465 | case DW_OP_reg28: | |
8466 | return "DW_OP_reg28"; | |
8467 | case DW_OP_reg29: | |
8468 | return "DW_OP_reg29"; | |
8469 | case DW_OP_reg30: | |
8470 | return "DW_OP_reg30"; | |
8471 | case DW_OP_reg31: | |
8472 | return "DW_OP_reg31"; | |
8473 | case DW_OP_breg0: | |
8474 | return "DW_OP_breg0"; | |
8475 | case DW_OP_breg1: | |
8476 | return "DW_OP_breg1"; | |
8477 | case DW_OP_breg2: | |
8478 | return "DW_OP_breg2"; | |
8479 | case DW_OP_breg3: | |
8480 | return "DW_OP_breg3"; | |
8481 | case DW_OP_breg4: | |
8482 | return "DW_OP_breg4"; | |
8483 | case DW_OP_breg5: | |
8484 | return "DW_OP_breg5"; | |
8485 | case DW_OP_breg6: | |
8486 | return "DW_OP_breg6"; | |
8487 | case DW_OP_breg7: | |
8488 | return "DW_OP_breg7"; | |
8489 | case DW_OP_breg8: | |
8490 | return "DW_OP_breg8"; | |
8491 | case DW_OP_breg9: | |
8492 | return "DW_OP_breg9"; | |
8493 | case DW_OP_breg10: | |
8494 | return "DW_OP_breg10"; | |
8495 | case DW_OP_breg11: | |
8496 | return "DW_OP_breg11"; | |
8497 | case DW_OP_breg12: | |
8498 | return "DW_OP_breg12"; | |
8499 | case DW_OP_breg13: | |
8500 | return "DW_OP_breg13"; | |
8501 | case DW_OP_breg14: | |
8502 | return "DW_OP_breg14"; | |
8503 | case DW_OP_breg15: | |
8504 | return "DW_OP_breg15"; | |
8505 | case DW_OP_breg16: | |
8506 | return "DW_OP_breg16"; | |
8507 | case DW_OP_breg17: | |
8508 | return "DW_OP_breg17"; | |
8509 | case DW_OP_breg18: | |
8510 | return "DW_OP_breg18"; | |
8511 | case DW_OP_breg19: | |
8512 | return "DW_OP_breg19"; | |
8513 | case DW_OP_breg20: | |
8514 | return "DW_OP_breg20"; | |
8515 | case DW_OP_breg21: | |
8516 | return "DW_OP_breg21"; | |
8517 | case DW_OP_breg22: | |
8518 | return "DW_OP_breg22"; | |
8519 | case DW_OP_breg23: | |
8520 | return "DW_OP_breg23"; | |
8521 | case DW_OP_breg24: | |
8522 | return "DW_OP_breg24"; | |
8523 | case DW_OP_breg25: | |
8524 | return "DW_OP_breg25"; | |
8525 | case DW_OP_breg26: | |
8526 | return "DW_OP_breg26"; | |
8527 | case DW_OP_breg27: | |
8528 | return "DW_OP_breg27"; | |
8529 | case DW_OP_breg28: | |
8530 | return "DW_OP_breg28"; | |
8531 | case DW_OP_breg29: | |
8532 | return "DW_OP_breg29"; | |
8533 | case DW_OP_breg30: | |
8534 | return "DW_OP_breg30"; | |
8535 | case DW_OP_breg31: | |
8536 | return "DW_OP_breg31"; | |
8537 | case DW_OP_regx: | |
8538 | return "DW_OP_regx"; | |
8539 | case DW_OP_fbreg: | |
8540 | return "DW_OP_fbreg"; | |
8541 | case DW_OP_bregx: | |
8542 | return "DW_OP_bregx"; | |
8543 | case DW_OP_piece: | |
8544 | return "DW_OP_piece"; | |
8545 | case DW_OP_deref_size: | |
8546 | return "DW_OP_deref_size"; | |
8547 | case DW_OP_xderef_size: | |
8548 | return "DW_OP_xderef_size"; | |
8549 | case DW_OP_nop: | |
8550 | return "DW_OP_nop"; | |
b7619582 | 8551 | /* DWARF 3 extensions. */ |
ed348acc EZ |
8552 | case DW_OP_push_object_address: |
8553 | return "DW_OP_push_object_address"; | |
8554 | case DW_OP_call2: | |
8555 | return "DW_OP_call2"; | |
8556 | case DW_OP_call4: | |
8557 | return "DW_OP_call4"; | |
8558 | case DW_OP_call_ref: | |
8559 | return "DW_OP_call_ref"; | |
b7619582 GF |
8560 | /* GNU extensions. */ |
8561 | case DW_OP_form_tls_address: | |
8562 | return "DW_OP_form_tls_address"; | |
8563 | case DW_OP_call_frame_cfa: | |
8564 | return "DW_OP_call_frame_cfa"; | |
8565 | case DW_OP_bit_piece: | |
8566 | return "DW_OP_bit_piece"; | |
ed348acc EZ |
8567 | case DW_OP_GNU_push_tls_address: |
8568 | return "DW_OP_GNU_push_tls_address"; | |
b7619582 GF |
8569 | /* HP extensions. */ |
8570 | case DW_OP_HP_is_value: | |
8571 | return "DW_OP_HP_is_value"; | |
8572 | case DW_OP_HP_fltconst4: | |
8573 | return "DW_OP_HP_fltconst4"; | |
8574 | case DW_OP_HP_fltconst8: | |
8575 | return "DW_OP_HP_fltconst8"; | |
8576 | case DW_OP_HP_mod_range: | |
8577 | return "DW_OP_HP_mod_range"; | |
8578 | case DW_OP_HP_unmod_range: | |
8579 | return "DW_OP_HP_unmod_range"; | |
8580 | case DW_OP_HP_tls: | |
8581 | return "DW_OP_HP_tls"; | |
c906108c SS |
8582 | default: |
8583 | return "OP_<unknown>"; | |
8584 | } | |
8585 | } | |
8586 | ||
8587 | static char * | |
fba45db2 | 8588 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
8589 | { |
8590 | if (mybool) | |
8591 | return "TRUE"; | |
8592 | else | |
8593 | return "FALSE"; | |
8594 | } | |
8595 | ||
8596 | /* Convert a DWARF type code into its string name. */ | |
8597 | ||
8598 | static char * | |
aa1ee363 | 8599 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
8600 | { |
8601 | switch (enc) | |
8602 | { | |
b7619582 GF |
8603 | case DW_ATE_void: |
8604 | return "DW_ATE_void"; | |
c906108c SS |
8605 | case DW_ATE_address: |
8606 | return "DW_ATE_address"; | |
8607 | case DW_ATE_boolean: | |
8608 | return "DW_ATE_boolean"; | |
8609 | case DW_ATE_complex_float: | |
8610 | return "DW_ATE_complex_float"; | |
8611 | case DW_ATE_float: | |
8612 | return "DW_ATE_float"; | |
8613 | case DW_ATE_signed: | |
8614 | return "DW_ATE_signed"; | |
8615 | case DW_ATE_signed_char: | |
8616 | return "DW_ATE_signed_char"; | |
8617 | case DW_ATE_unsigned: | |
8618 | return "DW_ATE_unsigned"; | |
8619 | case DW_ATE_unsigned_char: | |
8620 | return "DW_ATE_unsigned_char"; | |
b7619582 | 8621 | /* DWARF 3. */ |
d9fa45fe DC |
8622 | case DW_ATE_imaginary_float: |
8623 | return "DW_ATE_imaginary_float"; | |
b7619582 GF |
8624 | case DW_ATE_packed_decimal: |
8625 | return "DW_ATE_packed_decimal"; | |
8626 | case DW_ATE_numeric_string: | |
8627 | return "DW_ATE_numeric_string"; | |
8628 | case DW_ATE_edited: | |
8629 | return "DW_ATE_edited"; | |
8630 | case DW_ATE_signed_fixed: | |
8631 | return "DW_ATE_signed_fixed"; | |
8632 | case DW_ATE_unsigned_fixed: | |
8633 | return "DW_ATE_unsigned_fixed"; | |
8634 | case DW_ATE_decimal_float: | |
8635 | return "DW_ATE_decimal_float"; | |
8636 | /* HP extensions. */ | |
8637 | case DW_ATE_HP_float80: | |
8638 | return "DW_ATE_HP_float80"; | |
8639 | case DW_ATE_HP_complex_float80: | |
8640 | return "DW_ATE_HP_complex_float80"; | |
8641 | case DW_ATE_HP_float128: | |
8642 | return "DW_ATE_HP_float128"; | |
8643 | case DW_ATE_HP_complex_float128: | |
8644 | return "DW_ATE_HP_complex_float128"; | |
8645 | case DW_ATE_HP_floathpintel: | |
8646 | return "DW_ATE_HP_floathpintel"; | |
8647 | case DW_ATE_HP_imaginary_float80: | |
8648 | return "DW_ATE_HP_imaginary_float80"; | |
8649 | case DW_ATE_HP_imaginary_float128: | |
8650 | return "DW_ATE_HP_imaginary_float128"; | |
c906108c SS |
8651 | default: |
8652 | return "DW_ATE_<unknown>"; | |
8653 | } | |
8654 | } | |
8655 | ||
8656 | /* Convert a DWARF call frame info operation to its string name. */ | |
8657 | ||
8658 | #if 0 | |
8659 | static char * | |
aa1ee363 | 8660 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
8661 | { |
8662 | switch (cfi_opc) | |
8663 | { | |
8664 | case DW_CFA_advance_loc: | |
8665 | return "DW_CFA_advance_loc"; | |
8666 | case DW_CFA_offset: | |
8667 | return "DW_CFA_offset"; | |
8668 | case DW_CFA_restore: | |
8669 | return "DW_CFA_restore"; | |
8670 | case DW_CFA_nop: | |
8671 | return "DW_CFA_nop"; | |
8672 | case DW_CFA_set_loc: | |
8673 | return "DW_CFA_set_loc"; | |
8674 | case DW_CFA_advance_loc1: | |
8675 | return "DW_CFA_advance_loc1"; | |
8676 | case DW_CFA_advance_loc2: | |
8677 | return "DW_CFA_advance_loc2"; | |
8678 | case DW_CFA_advance_loc4: | |
8679 | return "DW_CFA_advance_loc4"; | |
8680 | case DW_CFA_offset_extended: | |
8681 | return "DW_CFA_offset_extended"; | |
8682 | case DW_CFA_restore_extended: | |
8683 | return "DW_CFA_restore_extended"; | |
8684 | case DW_CFA_undefined: | |
8685 | return "DW_CFA_undefined"; | |
8686 | case DW_CFA_same_value: | |
8687 | return "DW_CFA_same_value"; | |
8688 | case DW_CFA_register: | |
8689 | return "DW_CFA_register"; | |
8690 | case DW_CFA_remember_state: | |
8691 | return "DW_CFA_remember_state"; | |
8692 | case DW_CFA_restore_state: | |
8693 | return "DW_CFA_restore_state"; | |
8694 | case DW_CFA_def_cfa: | |
8695 | return "DW_CFA_def_cfa"; | |
8696 | case DW_CFA_def_cfa_register: | |
8697 | return "DW_CFA_def_cfa_register"; | |
8698 | case DW_CFA_def_cfa_offset: | |
8699 | return "DW_CFA_def_cfa_offset"; | |
b7619582 | 8700 | /* DWARF 3. */ |
985cb1a3 JM |
8701 | case DW_CFA_def_cfa_expression: |
8702 | return "DW_CFA_def_cfa_expression"; | |
8703 | case DW_CFA_expression: | |
8704 | return "DW_CFA_expression"; | |
8705 | case DW_CFA_offset_extended_sf: | |
8706 | return "DW_CFA_offset_extended_sf"; | |
8707 | case DW_CFA_def_cfa_sf: | |
8708 | return "DW_CFA_def_cfa_sf"; | |
8709 | case DW_CFA_def_cfa_offset_sf: | |
8710 | return "DW_CFA_def_cfa_offset_sf"; | |
b7619582 GF |
8711 | case DW_CFA_val_offset: |
8712 | return "DW_CFA_val_offset"; | |
8713 | case DW_CFA_val_offset_sf: | |
8714 | return "DW_CFA_val_offset_sf"; | |
8715 | case DW_CFA_val_expression: | |
8716 | return "DW_CFA_val_expression"; | |
8717 | /* SGI/MIPS specific. */ | |
c906108c SS |
8718 | case DW_CFA_MIPS_advance_loc8: |
8719 | return "DW_CFA_MIPS_advance_loc8"; | |
b7619582 | 8720 | /* GNU extensions. */ |
985cb1a3 JM |
8721 | case DW_CFA_GNU_window_save: |
8722 | return "DW_CFA_GNU_window_save"; | |
8723 | case DW_CFA_GNU_args_size: | |
8724 | return "DW_CFA_GNU_args_size"; | |
8725 | case DW_CFA_GNU_negative_offset_extended: | |
8726 | return "DW_CFA_GNU_negative_offset_extended"; | |
c906108c SS |
8727 | default: |
8728 | return "DW_CFA_<unknown>"; | |
8729 | } | |
8730 | } | |
8731 | #endif | |
8732 | ||
f9aca02d | 8733 | static void |
fba45db2 | 8734 | dump_die (struct die_info *die) |
c906108c SS |
8735 | { |
8736 | unsigned int i; | |
8737 | ||
48cd0caa | 8738 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 8739 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 8740 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 8741 | dwarf_bool_name (die->child != NULL)); |
c906108c | 8742 | |
48cd0caa | 8743 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
8744 | for (i = 0; i < die->num_attrs; ++i) |
8745 | { | |
48cd0caa | 8746 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
8747 | dwarf_attr_name (die->attrs[i].name), |
8748 | dwarf_form_name (die->attrs[i].form)); | |
8749 | switch (die->attrs[i].form) | |
8750 | { | |
8751 | case DW_FORM_ref_addr: | |
8752 | case DW_FORM_addr: | |
48cd0caa | 8753 | fprintf_unfiltered (gdb_stderr, "address: "); |
66bf4b3a | 8754 | deprecated_print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); |
c906108c SS |
8755 | break; |
8756 | case DW_FORM_block2: | |
8757 | case DW_FORM_block4: | |
8758 | case DW_FORM_block: | |
8759 | case DW_FORM_block1: | |
48cd0caa | 8760 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c | 8761 | break; |
10b3939b DJ |
8762 | case DW_FORM_ref1: |
8763 | case DW_FORM_ref2: | |
8764 | case DW_FORM_ref4: | |
8765 | fprintf_unfiltered (gdb_stderr, "constant ref: %ld (adjusted)", | |
8766 | (long) (DW_ADDR (&die->attrs[i]))); | |
8767 | break; | |
c906108c SS |
8768 | case DW_FORM_data1: |
8769 | case DW_FORM_data2: | |
8770 | case DW_FORM_data4: | |
ce5d95e1 | 8771 | case DW_FORM_data8: |
c906108c SS |
8772 | case DW_FORM_udata: |
8773 | case DW_FORM_sdata: | |
48cd0caa | 8774 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
8775 | break; |
8776 | case DW_FORM_string: | |
4bdf3d34 | 8777 | case DW_FORM_strp: |
48cd0caa | 8778 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 8779 | DW_STRING (&die->attrs[i]) |
c5aa993b | 8780 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
8781 | break; |
8782 | case DW_FORM_flag: | |
8783 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 8784 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 8785 | else |
48cd0caa | 8786 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 8787 | break; |
a8329558 KW |
8788 | case DW_FORM_indirect: |
8789 | /* the reader will have reduced the indirect form to | |
8790 | the "base form" so this form should not occur */ | |
48cd0caa | 8791 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 8792 | break; |
c906108c | 8793 | default: |
48cd0caa | 8794 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 8795 | die->attrs[i].form); |
c906108c | 8796 | } |
48cd0caa | 8797 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
8798 | } |
8799 | } | |
8800 | ||
f9aca02d | 8801 | static void |
fba45db2 | 8802 | dump_die_list (struct die_info *die) |
c906108c SS |
8803 | { |
8804 | while (die) | |
8805 | { | |
8806 | dump_die (die); | |
639d11d3 DC |
8807 | if (die->child != NULL) |
8808 | dump_die_list (die->child); | |
8809 | if (die->sibling != NULL) | |
8810 | dump_die_list (die->sibling); | |
c906108c SS |
8811 | } |
8812 | } | |
8813 | ||
f9aca02d | 8814 | static void |
10b3939b DJ |
8815 | store_in_ref_table (unsigned int offset, struct die_info *die, |
8816 | struct dwarf2_cu *cu) | |
c906108c SS |
8817 | { |
8818 | int h; | |
8819 | struct die_info *old; | |
8820 | ||
8821 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 8822 | old = cu->die_ref_table[h]; |
c906108c | 8823 | die->next_ref = old; |
10b3939b | 8824 | cu->die_ref_table[h] = die; |
c906108c SS |
8825 | } |
8826 | ||
8827 | static unsigned int | |
e142c38c | 8828 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
8829 | { |
8830 | unsigned int result = 0; | |
8831 | ||
8832 | switch (attr->form) | |
8833 | { | |
8834 | case DW_FORM_ref_addr: | |
c906108c SS |
8835 | case DW_FORM_ref1: |
8836 | case DW_FORM_ref2: | |
8837 | case DW_FORM_ref4: | |
613e1657 | 8838 | case DW_FORM_ref8: |
c906108c | 8839 | case DW_FORM_ref_udata: |
10b3939b | 8840 | result = DW_ADDR (attr); |
c906108c SS |
8841 | break; |
8842 | default: | |
4d3c2250 | 8843 | complaint (&symfile_complaints, |
e2e0b3e5 | 8844 | _("unsupported die ref attribute form: '%s'"), |
4d3c2250 | 8845 | dwarf_form_name (attr->form)); |
c906108c SS |
8846 | } |
8847 | return result; | |
8848 | } | |
8849 | ||
a02abb62 JB |
8850 | /* Return the constant value held by the given attribute. Return -1 |
8851 | if the value held by the attribute is not constant. */ | |
8852 | ||
8853 | static int | |
8854 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
8855 | { | |
8856 | if (attr->form == DW_FORM_sdata) | |
8857 | return DW_SND (attr); | |
8858 | else if (attr->form == DW_FORM_udata | |
8859 | || attr->form == DW_FORM_data1 | |
8860 | || attr->form == DW_FORM_data2 | |
8861 | || attr->form == DW_FORM_data4 | |
8862 | || attr->form == DW_FORM_data8) | |
8863 | return DW_UNSND (attr); | |
8864 | else | |
8865 | { | |
e2e0b3e5 | 8866 | complaint (&symfile_complaints, _("Attribute value is not a constant (%s)"), |
a02abb62 JB |
8867 | dwarf_form_name (attr->form)); |
8868 | return default_value; | |
8869 | } | |
8870 | } | |
8871 | ||
f9aca02d | 8872 | static struct die_info * |
10b3939b DJ |
8873 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
8874 | struct dwarf2_cu *cu) | |
c906108c SS |
8875 | { |
8876 | struct die_info *die; | |
10b3939b | 8877 | unsigned int offset; |
c906108c | 8878 | int h; |
10b3939b DJ |
8879 | struct die_info temp_die; |
8880 | struct dwarf2_cu *target_cu; | |
8881 | ||
8882 | offset = dwarf2_get_ref_die_offset (attr, cu); | |
8883 | ||
8884 | if (DW_ADDR (attr) < cu->header.offset | |
8885 | || DW_ADDR (attr) >= cu->header.offset + cu->header.length) | |
8886 | { | |
8887 | struct dwarf2_per_cu_data *per_cu; | |
8888 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (attr), | |
8889 | cu->objfile); | |
8890 | target_cu = per_cu->cu; | |
8891 | } | |
8892 | else | |
8893 | target_cu = cu; | |
c906108c SS |
8894 | |
8895 | h = (offset % REF_HASH_SIZE); | |
10b3939b | 8896 | die = target_cu->die_ref_table[h]; |
c906108c SS |
8897 | while (die) |
8898 | { | |
8899 | if (die->offset == offset) | |
10b3939b | 8900 | return die; |
c906108c SS |
8901 | die = die->next_ref; |
8902 | } | |
10b3939b | 8903 | |
8a3fe4f8 AC |
8904 | error (_("Dwarf Error: Cannot find DIE at 0x%lx referenced from DIE " |
8905 | "at 0x%lx [in module %s]"), | |
10b3939b DJ |
8906 | (long) src_die->offset, (long) offset, cu->objfile->name); |
8907 | ||
c906108c SS |
8908 | return NULL; |
8909 | } | |
8910 | ||
8911 | static struct type * | |
e142c38c DJ |
8912 | dwarf2_fundamental_type (struct objfile *objfile, int typeid, |
8913 | struct dwarf2_cu *cu) | |
c906108c SS |
8914 | { |
8915 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
8916 | { | |
8a3fe4f8 | 8917 | error (_("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]"), |
659b0389 | 8918 | typeid, objfile->name); |
c906108c SS |
8919 | } |
8920 | ||
8921 | /* Look for this particular type in the fundamental type vector. If | |
8922 | one is not found, create and install one appropriate for the | |
8923 | current language and the current target machine. */ | |
8924 | ||
e142c38c | 8925 | if (cu->ftypes[typeid] == NULL) |
c906108c | 8926 | { |
e142c38c | 8927 | cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); |
c906108c SS |
8928 | } |
8929 | ||
e142c38c | 8930 | return (cu->ftypes[typeid]); |
c906108c SS |
8931 | } |
8932 | ||
8933 | /* Decode simple location descriptions. | |
8934 | Given a pointer to a dwarf block that defines a location, compute | |
8935 | the location and return the value. | |
8936 | ||
4cecd739 DJ |
8937 | NOTE drow/2003-11-18: This function is called in two situations |
8938 | now: for the address of static or global variables (partial symbols | |
8939 | only) and for offsets into structures which are expected to be | |
8940 | (more or less) constant. The partial symbol case should go away, | |
8941 | and only the constant case should remain. That will let this | |
8942 | function complain more accurately. A few special modes are allowed | |
8943 | without complaint for global variables (for instance, global | |
8944 | register values and thread-local values). | |
c906108c SS |
8945 | |
8946 | A location description containing no operations indicates that the | |
4cecd739 | 8947 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
8948 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
8949 | callers will only want a very basic result and this can become a | |
8950 | complaint. | |
c906108c | 8951 | |
c906108c SS |
8952 | Note that stack[0] is unused except as a default error return. |
8953 | Note that stack overflow is not yet handled. */ | |
8954 | ||
8955 | static CORE_ADDR | |
e7c27a73 | 8956 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 8957 | { |
e7c27a73 DJ |
8958 | struct objfile *objfile = cu->objfile; |
8959 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
8960 | int i; |
8961 | int size = blk->size; | |
fe1b8b76 | 8962 | gdb_byte *data = blk->data; |
c906108c SS |
8963 | CORE_ADDR stack[64]; |
8964 | int stacki; | |
8965 | unsigned int bytes_read, unsnd; | |
fe1b8b76 | 8966 | gdb_byte op; |
c906108c SS |
8967 | |
8968 | i = 0; | |
8969 | stacki = 0; | |
8970 | stack[stacki] = 0; | |
c906108c SS |
8971 | |
8972 | while (i < size) | |
8973 | { | |
c906108c SS |
8974 | op = data[i++]; |
8975 | switch (op) | |
8976 | { | |
f1bea926 JM |
8977 | case DW_OP_lit0: |
8978 | case DW_OP_lit1: | |
8979 | case DW_OP_lit2: | |
8980 | case DW_OP_lit3: | |
8981 | case DW_OP_lit4: | |
8982 | case DW_OP_lit5: | |
8983 | case DW_OP_lit6: | |
8984 | case DW_OP_lit7: | |
8985 | case DW_OP_lit8: | |
8986 | case DW_OP_lit9: | |
8987 | case DW_OP_lit10: | |
8988 | case DW_OP_lit11: | |
8989 | case DW_OP_lit12: | |
8990 | case DW_OP_lit13: | |
8991 | case DW_OP_lit14: | |
8992 | case DW_OP_lit15: | |
8993 | case DW_OP_lit16: | |
8994 | case DW_OP_lit17: | |
8995 | case DW_OP_lit18: | |
8996 | case DW_OP_lit19: | |
8997 | case DW_OP_lit20: | |
8998 | case DW_OP_lit21: | |
8999 | case DW_OP_lit22: | |
9000 | case DW_OP_lit23: | |
9001 | case DW_OP_lit24: | |
9002 | case DW_OP_lit25: | |
9003 | case DW_OP_lit26: | |
9004 | case DW_OP_lit27: | |
9005 | case DW_OP_lit28: | |
9006 | case DW_OP_lit29: | |
9007 | case DW_OP_lit30: | |
9008 | case DW_OP_lit31: | |
9009 | stack[++stacki] = op - DW_OP_lit0; | |
9010 | break; | |
9011 | ||
c906108c SS |
9012 | case DW_OP_reg0: |
9013 | case DW_OP_reg1: | |
9014 | case DW_OP_reg2: | |
9015 | case DW_OP_reg3: | |
9016 | case DW_OP_reg4: | |
9017 | case DW_OP_reg5: | |
9018 | case DW_OP_reg6: | |
9019 | case DW_OP_reg7: | |
9020 | case DW_OP_reg8: | |
9021 | case DW_OP_reg9: | |
9022 | case DW_OP_reg10: | |
9023 | case DW_OP_reg11: | |
9024 | case DW_OP_reg12: | |
9025 | case DW_OP_reg13: | |
9026 | case DW_OP_reg14: | |
9027 | case DW_OP_reg15: | |
9028 | case DW_OP_reg16: | |
9029 | case DW_OP_reg17: | |
9030 | case DW_OP_reg18: | |
9031 | case DW_OP_reg19: | |
9032 | case DW_OP_reg20: | |
9033 | case DW_OP_reg21: | |
9034 | case DW_OP_reg22: | |
9035 | case DW_OP_reg23: | |
9036 | case DW_OP_reg24: | |
9037 | case DW_OP_reg25: | |
9038 | case DW_OP_reg26: | |
9039 | case DW_OP_reg27: | |
9040 | case DW_OP_reg28: | |
9041 | case DW_OP_reg29: | |
9042 | case DW_OP_reg30: | |
9043 | case DW_OP_reg31: | |
c906108c | 9044 | stack[++stacki] = op - DW_OP_reg0; |
4cecd739 DJ |
9045 | if (i < size) |
9046 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9047 | break; |
9048 | ||
9049 | case DW_OP_regx: | |
c906108c SS |
9050 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
9051 | i += bytes_read; | |
c906108c | 9052 | stack[++stacki] = unsnd; |
4cecd739 DJ |
9053 | if (i < size) |
9054 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
9055 | break; |
9056 | ||
9057 | case DW_OP_addr: | |
107d2387 | 9058 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 9059 | cu, &bytes_read); |
107d2387 | 9060 | i += bytes_read; |
c906108c SS |
9061 | break; |
9062 | ||
9063 | case DW_OP_const1u: | |
9064 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
9065 | i += 1; | |
9066 | break; | |
9067 | ||
9068 | case DW_OP_const1s: | |
9069 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
9070 | i += 1; | |
9071 | break; | |
9072 | ||
9073 | case DW_OP_const2u: | |
9074 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
9075 | i += 2; | |
9076 | break; | |
9077 | ||
9078 | case DW_OP_const2s: | |
9079 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
9080 | i += 2; | |
9081 | break; | |
9082 | ||
9083 | case DW_OP_const4u: | |
9084 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
9085 | i += 4; | |
9086 | break; | |
9087 | ||
9088 | case DW_OP_const4s: | |
9089 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
9090 | i += 4; | |
9091 | break; | |
9092 | ||
9093 | case DW_OP_constu: | |
9094 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 9095 | &bytes_read); |
c906108c SS |
9096 | i += bytes_read; |
9097 | break; | |
9098 | ||
9099 | case DW_OP_consts: | |
9100 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
9101 | i += bytes_read; | |
9102 | break; | |
9103 | ||
f1bea926 JM |
9104 | case DW_OP_dup: |
9105 | stack[stacki + 1] = stack[stacki]; | |
9106 | stacki++; | |
9107 | break; | |
9108 | ||
c906108c SS |
9109 | case DW_OP_plus: |
9110 | stack[stacki - 1] += stack[stacki]; | |
9111 | stacki--; | |
9112 | break; | |
9113 | ||
9114 | case DW_OP_plus_uconst: | |
9115 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
9116 | i += bytes_read; | |
9117 | break; | |
9118 | ||
9119 | case DW_OP_minus: | |
f1bea926 | 9120 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
9121 | stacki--; |
9122 | break; | |
9123 | ||
7a292a7a | 9124 | case DW_OP_deref: |
7a292a7a | 9125 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
9126 | this using GDB's address_class enum. This is valid for partial |
9127 | global symbols, although the variable's address will be bogus | |
9128 | in the psymtab. */ | |
7a292a7a | 9129 | if (i < size) |
4d3c2250 | 9130 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
9131 | break; |
9132 | ||
9d774e44 | 9133 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
9134 | /* The top of the stack has the offset from the beginning |
9135 | of the thread control block at which the variable is located. */ | |
9136 | /* Nothing should follow this operator, so the top of stack would | |
9137 | be returned. */ | |
4cecd739 DJ |
9138 | /* This is valid for partial global symbols, but the variable's |
9139 | address will be bogus in the psymtab. */ | |
9d774e44 | 9140 | if (i < size) |
4d3c2250 | 9141 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
9142 | break; |
9143 | ||
c906108c | 9144 | default: |
e2e0b3e5 | 9145 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
4d3c2250 | 9146 | dwarf_stack_op_name (op)); |
c906108c SS |
9147 | return (stack[stacki]); |
9148 | } | |
9149 | } | |
9150 | return (stack[stacki]); | |
9151 | } | |
9152 | ||
9153 | /* memory allocation interface */ | |
9154 | ||
c906108c | 9155 | static struct dwarf_block * |
7b5a2f43 | 9156 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
9157 | { |
9158 | struct dwarf_block *blk; | |
9159 | ||
9160 | blk = (struct dwarf_block *) | |
7b5a2f43 | 9161 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
9162 | return (blk); |
9163 | } | |
9164 | ||
9165 | static struct abbrev_info * | |
f3dd6933 | 9166 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
9167 | { |
9168 | struct abbrev_info *abbrev; | |
9169 | ||
f3dd6933 DJ |
9170 | abbrev = (struct abbrev_info *) |
9171 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
9172 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
9173 | return (abbrev); | |
9174 | } | |
9175 | ||
9176 | static struct die_info * | |
fba45db2 | 9177 | dwarf_alloc_die (void) |
c906108c SS |
9178 | { |
9179 | struct die_info *die; | |
9180 | ||
9181 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
9182 | memset (die, 0, sizeof (struct die_info)); | |
9183 | return (die); | |
9184 | } | |
2e276125 JB |
9185 | |
9186 | \f | |
9187 | /* Macro support. */ | |
9188 | ||
9189 | ||
9190 | /* Return the full name of file number I in *LH's file name table. | |
9191 | Use COMP_DIR as the name of the current directory of the | |
9192 | compilation. The result is allocated using xmalloc; the caller is | |
9193 | responsible for freeing it. */ | |
9194 | static char * | |
9195 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
9196 | { | |
6a83a1e6 EZ |
9197 | /* Is the file number a valid index into the line header's file name |
9198 | table? Remember that file numbers start with one, not zero. */ | |
9199 | if (1 <= file && file <= lh->num_file_names) | |
9200 | { | |
9201 | struct file_entry *fe = &lh->file_names[file - 1]; | |
2e276125 | 9202 | |
6a83a1e6 EZ |
9203 | if (IS_ABSOLUTE_PATH (fe->name)) |
9204 | return xstrdup (fe->name); | |
9205 | else | |
9206 | { | |
9207 | const char *dir; | |
9208 | int dir_len; | |
9209 | char *full_name; | |
9210 | ||
9211 | if (fe->dir_index) | |
9212 | dir = lh->include_dirs[fe->dir_index - 1]; | |
9213 | else | |
9214 | dir = comp_dir; | |
9215 | ||
9216 | if (dir) | |
9217 | { | |
9218 | dir_len = strlen (dir); | |
9219 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
9220 | strcpy (full_name, dir); | |
9221 | full_name[dir_len] = '/'; | |
9222 | strcpy (full_name + dir_len + 1, fe->name); | |
9223 | return full_name; | |
9224 | } | |
9225 | else | |
9226 | return xstrdup (fe->name); | |
9227 | } | |
9228 | } | |
2e276125 JB |
9229 | else |
9230 | { | |
6a83a1e6 EZ |
9231 | /* The compiler produced a bogus file number. We can at least |
9232 | record the macro definitions made in the file, even if we | |
9233 | won't be able to find the file by name. */ | |
9234 | char fake_name[80]; | |
9235 | sprintf (fake_name, "<bad macro file number %d>", file); | |
2e276125 | 9236 | |
6a83a1e6 EZ |
9237 | complaint (&symfile_complaints, |
9238 | _("bad file number in macro information (%d)"), | |
9239 | file); | |
2e276125 | 9240 | |
6a83a1e6 | 9241 | return xstrdup (fake_name); |
2e276125 JB |
9242 | } |
9243 | } | |
9244 | ||
9245 | ||
9246 | static struct macro_source_file * | |
9247 | macro_start_file (int file, int line, | |
9248 | struct macro_source_file *current_file, | |
9249 | const char *comp_dir, | |
9250 | struct line_header *lh, struct objfile *objfile) | |
9251 | { | |
9252 | /* The full name of this source file. */ | |
9253 | char *full_name = file_full_name (file, lh, comp_dir); | |
9254 | ||
9255 | /* We don't create a macro table for this compilation unit | |
9256 | at all until we actually get a filename. */ | |
9257 | if (! pending_macros) | |
4a146b47 | 9258 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 9259 | objfile->macro_cache); |
2e276125 JB |
9260 | |
9261 | if (! current_file) | |
9262 | /* If we have no current file, then this must be the start_file | |
9263 | directive for the compilation unit's main source file. */ | |
9264 | current_file = macro_set_main (pending_macros, full_name); | |
9265 | else | |
9266 | current_file = macro_include (current_file, line, full_name); | |
9267 | ||
9268 | xfree (full_name); | |
9269 | ||
9270 | return current_file; | |
9271 | } | |
9272 | ||
9273 | ||
9274 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
9275 | followed by a null byte. */ | |
9276 | static char * | |
9277 | copy_string (const char *buf, int len) | |
9278 | { | |
9279 | char *s = xmalloc (len + 1); | |
9280 | memcpy (s, buf, len); | |
9281 | s[len] = '\0'; | |
9282 | ||
9283 | return s; | |
9284 | } | |
9285 | ||
9286 | ||
9287 | static const char * | |
9288 | consume_improper_spaces (const char *p, const char *body) | |
9289 | { | |
9290 | if (*p == ' ') | |
9291 | { | |
4d3c2250 | 9292 | complaint (&symfile_complaints, |
e2e0b3e5 | 9293 | _("macro definition contains spaces in formal argument list:\n`%s'"), |
4d3c2250 | 9294 | body); |
2e276125 JB |
9295 | |
9296 | while (*p == ' ') | |
9297 | p++; | |
9298 | } | |
9299 | ||
9300 | return p; | |
9301 | } | |
9302 | ||
9303 | ||
9304 | static void | |
9305 | parse_macro_definition (struct macro_source_file *file, int line, | |
9306 | const char *body) | |
9307 | { | |
9308 | const char *p; | |
9309 | ||
9310 | /* The body string takes one of two forms. For object-like macro | |
9311 | definitions, it should be: | |
9312 | ||
9313 | <macro name> " " <definition> | |
9314 | ||
9315 | For function-like macro definitions, it should be: | |
9316 | ||
9317 | <macro name> "() " <definition> | |
9318 | or | |
9319 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
9320 | ||
9321 | Spaces may appear only where explicitly indicated, and in the | |
9322 | <definition>. | |
9323 | ||
9324 | The Dwarf 2 spec says that an object-like macro's name is always | |
9325 | followed by a space, but versions of GCC around March 2002 omit | |
9326 | the space when the macro's definition is the empty string. | |
9327 | ||
9328 | The Dwarf 2 spec says that there should be no spaces between the | |
9329 | formal arguments in a function-like macro's formal argument list, | |
9330 | but versions of GCC around March 2002 include spaces after the | |
9331 | commas. */ | |
9332 | ||
9333 | ||
9334 | /* Find the extent of the macro name. The macro name is terminated | |
9335 | by either a space or null character (for an object-like macro) or | |
9336 | an opening paren (for a function-like macro). */ | |
9337 | for (p = body; *p; p++) | |
9338 | if (*p == ' ' || *p == '(') | |
9339 | break; | |
9340 | ||
9341 | if (*p == ' ' || *p == '\0') | |
9342 | { | |
9343 | /* It's an object-like macro. */ | |
9344 | int name_len = p - body; | |
9345 | char *name = copy_string (body, name_len); | |
9346 | const char *replacement; | |
9347 | ||
9348 | if (*p == ' ') | |
9349 | replacement = body + name_len + 1; | |
9350 | else | |
9351 | { | |
4d3c2250 | 9352 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9353 | replacement = body + name_len; |
9354 | } | |
9355 | ||
9356 | macro_define_object (file, line, name, replacement); | |
9357 | ||
9358 | xfree (name); | |
9359 | } | |
9360 | else if (*p == '(') | |
9361 | { | |
9362 | /* It's a function-like macro. */ | |
9363 | char *name = copy_string (body, p - body); | |
9364 | int argc = 0; | |
9365 | int argv_size = 1; | |
9366 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
9367 | ||
9368 | p++; | |
9369 | ||
9370 | p = consume_improper_spaces (p, body); | |
9371 | ||
9372 | /* Parse the formal argument list. */ | |
9373 | while (*p && *p != ')') | |
9374 | { | |
9375 | /* Find the extent of the current argument name. */ | |
9376 | const char *arg_start = p; | |
9377 | ||
9378 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
9379 | p++; | |
9380 | ||
9381 | if (! *p || p == arg_start) | |
4d3c2250 | 9382 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9383 | else |
9384 | { | |
9385 | /* Make sure argv has room for the new argument. */ | |
9386 | if (argc >= argv_size) | |
9387 | { | |
9388 | argv_size *= 2; | |
9389 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
9390 | } | |
9391 | ||
9392 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
9393 | } | |
9394 | ||
9395 | p = consume_improper_spaces (p, body); | |
9396 | ||
9397 | /* Consume the comma, if present. */ | |
9398 | if (*p == ',') | |
9399 | { | |
9400 | p++; | |
9401 | ||
9402 | p = consume_improper_spaces (p, body); | |
9403 | } | |
9404 | } | |
9405 | ||
9406 | if (*p == ')') | |
9407 | { | |
9408 | p++; | |
9409 | ||
9410 | if (*p == ' ') | |
9411 | /* Perfectly formed definition, no complaints. */ | |
9412 | macro_define_function (file, line, name, | |
9413 | argc, (const char **) argv, | |
9414 | p + 1); | |
9415 | else if (*p == '\0') | |
9416 | { | |
9417 | /* Complain, but do define it. */ | |
4d3c2250 | 9418 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9419 | macro_define_function (file, line, name, |
9420 | argc, (const char **) argv, | |
9421 | p); | |
9422 | } | |
9423 | else | |
9424 | /* Just complain. */ | |
4d3c2250 | 9425 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9426 | } |
9427 | else | |
9428 | /* Just complain. */ | |
4d3c2250 | 9429 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9430 | |
9431 | xfree (name); | |
9432 | { | |
9433 | int i; | |
9434 | ||
9435 | for (i = 0; i < argc; i++) | |
9436 | xfree (argv[i]); | |
9437 | } | |
9438 | xfree (argv); | |
9439 | } | |
9440 | else | |
4d3c2250 | 9441 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
9442 | } |
9443 | ||
9444 | ||
9445 | static void | |
9446 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
9447 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 9448 | struct dwarf2_cu *cu) |
2e276125 | 9449 | { |
fe1b8b76 | 9450 | gdb_byte *mac_ptr, *mac_end; |
2e276125 JB |
9451 | struct macro_source_file *current_file = 0; |
9452 | ||
6502dd73 | 9453 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 9454 | { |
e2e0b3e5 | 9455 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
2e276125 JB |
9456 | return; |
9457 | } | |
9458 | ||
6502dd73 DJ |
9459 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
9460 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
9461 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
9462 | |
9463 | for (;;) | |
9464 | { | |
9465 | enum dwarf_macinfo_record_type macinfo_type; | |
9466 | ||
9467 | /* Do we at least have room for a macinfo type byte? */ | |
9468 | if (mac_ptr >= mac_end) | |
9469 | { | |
4d3c2250 | 9470 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9471 | return; |
9472 | } | |
9473 | ||
9474 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
9475 | mac_ptr++; | |
9476 | ||
9477 | switch (macinfo_type) | |
9478 | { | |
9479 | /* A zero macinfo type indicates the end of the macro | |
9480 | information. */ | |
9481 | case 0: | |
9482 | return; | |
9483 | ||
9484 | case DW_MACINFO_define: | |
9485 | case DW_MACINFO_undef: | |
9486 | { | |
891d2f0b | 9487 | unsigned int bytes_read; |
2e276125 JB |
9488 | int line; |
9489 | char *body; | |
9490 | ||
9491 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9492 | mac_ptr += bytes_read; | |
9493 | body = read_string (abfd, mac_ptr, &bytes_read); | |
9494 | mac_ptr += bytes_read; | |
9495 | ||
9496 | if (! current_file) | |
4d3c2250 | 9497 | complaint (&symfile_complaints, |
e2e0b3e5 | 9498 | _("debug info gives macro %s outside of any file: %s"), |
4d3c2250 KB |
9499 | macinfo_type == |
9500 | DW_MACINFO_define ? "definition" : macinfo_type == | |
9501 | DW_MACINFO_undef ? "undefinition" : | |
9502 | "something-or-other", body); | |
2e276125 JB |
9503 | else |
9504 | { | |
9505 | if (macinfo_type == DW_MACINFO_define) | |
9506 | parse_macro_definition (current_file, line, body); | |
9507 | else if (macinfo_type == DW_MACINFO_undef) | |
9508 | macro_undef (current_file, line, body); | |
9509 | } | |
9510 | } | |
9511 | break; | |
9512 | ||
9513 | case DW_MACINFO_start_file: | |
9514 | { | |
891d2f0b | 9515 | unsigned int bytes_read; |
2e276125 JB |
9516 | int line, file; |
9517 | ||
9518 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9519 | mac_ptr += bytes_read; | |
9520 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9521 | mac_ptr += bytes_read; | |
9522 | ||
9523 | current_file = macro_start_file (file, line, | |
9524 | current_file, comp_dir, | |
e7c27a73 | 9525 | lh, cu->objfile); |
2e276125 JB |
9526 | } |
9527 | break; | |
9528 | ||
9529 | case DW_MACINFO_end_file: | |
9530 | if (! current_file) | |
4d3c2250 | 9531 | complaint (&symfile_complaints, |
e2e0b3e5 | 9532 | _("macro debug info has an unmatched `close_file' directive")); |
2e276125 JB |
9533 | else |
9534 | { | |
9535 | current_file = current_file->included_by; | |
9536 | if (! current_file) | |
9537 | { | |
9538 | enum dwarf_macinfo_record_type next_type; | |
9539 | ||
9540 | /* GCC circa March 2002 doesn't produce the zero | |
9541 | type byte marking the end of the compilation | |
9542 | unit. Complain if it's not there, but exit no | |
9543 | matter what. */ | |
9544 | ||
9545 | /* Do we at least have room for a macinfo type byte? */ | |
9546 | if (mac_ptr >= mac_end) | |
9547 | { | |
4d3c2250 | 9548 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
9549 | return; |
9550 | } | |
9551 | ||
9552 | /* We don't increment mac_ptr here, so this is just | |
9553 | a look-ahead. */ | |
9554 | next_type = read_1_byte (abfd, mac_ptr); | |
9555 | if (next_type != 0) | |
4d3c2250 | 9556 | complaint (&symfile_complaints, |
e2e0b3e5 | 9557 | _("no terminating 0-type entry for macros in `.debug_macinfo' section")); |
2e276125 JB |
9558 | |
9559 | return; | |
9560 | } | |
9561 | } | |
9562 | break; | |
9563 | ||
9564 | case DW_MACINFO_vendor_ext: | |
9565 | { | |
891d2f0b | 9566 | unsigned int bytes_read; |
2e276125 JB |
9567 | int constant; |
9568 | char *string; | |
9569 | ||
9570 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
9571 | mac_ptr += bytes_read; | |
9572 | string = read_string (abfd, mac_ptr, &bytes_read); | |
9573 | mac_ptr += bytes_read; | |
9574 | ||
9575 | /* We don't recognize any vendor extensions. */ | |
9576 | } | |
9577 | break; | |
9578 | } | |
9579 | } | |
9580 | } | |
8e19ed76 PS |
9581 | |
9582 | /* Check if the attribute's form is a DW_FORM_block* | |
9583 | if so return true else false. */ | |
9584 | static int | |
9585 | attr_form_is_block (struct attribute *attr) | |
9586 | { | |
9587 | return (attr == NULL ? 0 : | |
9588 | attr->form == DW_FORM_block1 | |
9589 | || attr->form == DW_FORM_block2 | |
9590 | || attr->form == DW_FORM_block4 | |
9591 | || attr->form == DW_FORM_block); | |
9592 | } | |
4c2df51b DJ |
9593 | |
9594 | static void | |
9595 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 9596 | struct dwarf2_cu *cu) |
4c2df51b | 9597 | { |
99bcc461 DJ |
9598 | if ((attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
9599 | /* ".debug_loc" may not exist at all, or the offset may be outside | |
9600 | the section. If so, fall through to the complaint in the | |
9601 | other branch. */ | |
9602 | && DW_UNSND (attr) < dwarf2_per_objfile->loc_size) | |
4c2df51b | 9603 | { |
0d53c4c4 | 9604 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 9605 | |
4a146b47 | 9606 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9607 | sizeof (struct dwarf2_loclist_baton)); |
e7c27a73 | 9608 | baton->objfile = cu->objfile; |
4c2df51b | 9609 | |
0d53c4c4 DJ |
9610 | /* We don't know how long the location list is, but make sure we |
9611 | don't run off the edge of the section. */ | |
6502dd73 DJ |
9612 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
9613 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
9614 | baton->base_address = cu->header.base_address; |
9615 | if (cu->header.base_known == 0) | |
0d53c4c4 | 9616 | complaint (&symfile_complaints, |
e2e0b3e5 | 9617 | _("Location list used without specifying the CU base address.")); |
4c2df51b | 9618 | |
a67af2b9 | 9619 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
9620 | SYMBOL_LOCATION_BATON (sym) = baton; |
9621 | } | |
9622 | else | |
9623 | { | |
9624 | struct dwarf2_locexpr_baton *baton; | |
9625 | ||
4a146b47 | 9626 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 9627 | sizeof (struct dwarf2_locexpr_baton)); |
e7c27a73 | 9628 | baton->objfile = cu->objfile; |
0d53c4c4 DJ |
9629 | |
9630 | if (attr_form_is_block (attr)) | |
9631 | { | |
9632 | /* Note that we're just copying the block's data pointer | |
9633 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
9634 | info_buffer for SYM's objfile; right now we never release |
9635 | that buffer, but when we do clean up properly this may | |
9636 | need to change. */ | |
0d53c4c4 DJ |
9637 | baton->size = DW_BLOCK (attr)->size; |
9638 | baton->data = DW_BLOCK (attr)->data; | |
9639 | } | |
9640 | else | |
9641 | { | |
9642 | dwarf2_invalid_attrib_class_complaint ("location description", | |
9643 | SYMBOL_NATURAL_NAME (sym)); | |
9644 | baton->size = 0; | |
9645 | baton->data = NULL; | |
9646 | } | |
9647 | ||
a67af2b9 | 9648 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
9649 | SYMBOL_LOCATION_BATON (sym) = baton; |
9650 | } | |
4c2df51b | 9651 | } |
6502dd73 | 9652 | |
ae038cb0 | 9653 | /* Locate the compilation unit from CU's objfile which contains the |
10b3939b | 9654 | DIE at OFFSET. Raises an error on failure. */ |
ae038cb0 DJ |
9655 | |
9656 | static struct dwarf2_per_cu_data * | |
9657 | dwarf2_find_containing_comp_unit (unsigned long offset, | |
9658 | struct objfile *objfile) | |
9659 | { | |
9660 | struct dwarf2_per_cu_data *this_cu; | |
9661 | int low, high; | |
9662 | ||
ae038cb0 DJ |
9663 | low = 0; |
9664 | high = dwarf2_per_objfile->n_comp_units - 1; | |
9665 | while (high > low) | |
9666 | { | |
9667 | int mid = low + (high - low) / 2; | |
9668 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) | |
9669 | high = mid; | |
9670 | else | |
9671 | low = mid + 1; | |
9672 | } | |
9673 | gdb_assert (low == high); | |
9674 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) | |
9675 | { | |
10b3939b | 9676 | if (low == 0) |
8a3fe4f8 AC |
9677 | error (_("Dwarf Error: could not find partial DIE containing " |
9678 | "offset 0x%lx [in module %s]"), | |
10b3939b DJ |
9679 | (long) offset, bfd_get_filename (objfile->obfd)); |
9680 | ||
ae038cb0 DJ |
9681 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
9682 | return dwarf2_per_objfile->all_comp_units[low-1]; | |
9683 | } | |
9684 | else | |
9685 | { | |
9686 | this_cu = dwarf2_per_objfile->all_comp_units[low]; | |
9687 | if (low == dwarf2_per_objfile->n_comp_units - 1 | |
9688 | && offset >= this_cu->offset + this_cu->length) | |
8a3fe4f8 | 9689 | error (_("invalid dwarf2 offset %ld"), offset); |
ae038cb0 DJ |
9690 | gdb_assert (offset < this_cu->offset + this_cu->length); |
9691 | return this_cu; | |
9692 | } | |
9693 | } | |
9694 | ||
10b3939b DJ |
9695 | /* Locate the compilation unit from OBJFILE which is located at exactly |
9696 | OFFSET. Raises an error on failure. */ | |
9697 | ||
ae038cb0 DJ |
9698 | static struct dwarf2_per_cu_data * |
9699 | dwarf2_find_comp_unit (unsigned long offset, struct objfile *objfile) | |
9700 | { | |
9701 | struct dwarf2_per_cu_data *this_cu; | |
9702 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); | |
9703 | if (this_cu->offset != offset) | |
8a3fe4f8 | 9704 | error (_("no compilation unit with offset %ld."), offset); |
ae038cb0 DJ |
9705 | return this_cu; |
9706 | } | |
9707 | ||
9708 | /* Release one cached compilation unit, CU. We unlink it from the tree | |
9709 | of compilation units, but we don't remove it from the read_in_chain; | |
9710 | the caller is responsible for that. */ | |
9711 | ||
9712 | static void | |
9713 | free_one_comp_unit (void *data) | |
9714 | { | |
9715 | struct dwarf2_cu *cu = data; | |
9716 | ||
9717 | if (cu->per_cu != NULL) | |
9718 | cu->per_cu->cu = NULL; | |
9719 | cu->per_cu = NULL; | |
9720 | ||
9721 | obstack_free (&cu->comp_unit_obstack, NULL); | |
10b3939b DJ |
9722 | if (cu->dies) |
9723 | free_die_list (cu->dies); | |
ae038cb0 DJ |
9724 | |
9725 | xfree (cu); | |
9726 | } | |
9727 | ||
72bf9492 | 9728 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
ae038cb0 DJ |
9729 | when we're finished with it. We can't free the pointer itself, but be |
9730 | sure to unlink it from the cache. Also release any associated storage | |
9731 | and perform cache maintenance. | |
72bf9492 DJ |
9732 | |
9733 | Only used during partial symbol parsing. */ | |
9734 | ||
9735 | static void | |
9736 | free_stack_comp_unit (void *data) | |
9737 | { | |
9738 | struct dwarf2_cu *cu = data; | |
9739 | ||
9740 | obstack_free (&cu->comp_unit_obstack, NULL); | |
9741 | cu->partial_dies = NULL; | |
ae038cb0 DJ |
9742 | |
9743 | if (cu->per_cu != NULL) | |
9744 | { | |
9745 | /* This compilation unit is on the stack in our caller, so we | |
9746 | should not xfree it. Just unlink it. */ | |
9747 | cu->per_cu->cu = NULL; | |
9748 | cu->per_cu = NULL; | |
9749 | ||
9750 | /* If we had a per-cu pointer, then we may have other compilation | |
9751 | units loaded, so age them now. */ | |
9752 | age_cached_comp_units (); | |
9753 | } | |
9754 | } | |
9755 | ||
9756 | /* Free all cached compilation units. */ | |
9757 | ||
9758 | static void | |
9759 | free_cached_comp_units (void *data) | |
9760 | { | |
9761 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
9762 | ||
9763 | per_cu = dwarf2_per_objfile->read_in_chain; | |
9764 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
9765 | while (per_cu != NULL) | |
9766 | { | |
9767 | struct dwarf2_per_cu_data *next_cu; | |
9768 | ||
9769 | next_cu = per_cu->cu->read_in_chain; | |
9770 | ||
9771 | free_one_comp_unit (per_cu->cu); | |
9772 | *last_chain = next_cu; | |
9773 | ||
9774 | per_cu = next_cu; | |
9775 | } | |
9776 | } | |
9777 | ||
9778 | /* Increase the age counter on each cached compilation unit, and free | |
9779 | any that are too old. */ | |
9780 | ||
9781 | static void | |
9782 | age_cached_comp_units (void) | |
9783 | { | |
9784 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
9785 | ||
9786 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); | |
9787 | per_cu = dwarf2_per_objfile->read_in_chain; | |
9788 | while (per_cu != NULL) | |
9789 | { | |
9790 | per_cu->cu->last_used ++; | |
9791 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) | |
9792 | dwarf2_mark (per_cu->cu); | |
9793 | per_cu = per_cu->cu->read_in_chain; | |
9794 | } | |
9795 | ||
9796 | per_cu = dwarf2_per_objfile->read_in_chain; | |
9797 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
9798 | while (per_cu != NULL) | |
9799 | { | |
9800 | struct dwarf2_per_cu_data *next_cu; | |
9801 | ||
9802 | next_cu = per_cu->cu->read_in_chain; | |
9803 | ||
9804 | if (!per_cu->cu->mark) | |
9805 | { | |
9806 | free_one_comp_unit (per_cu->cu); | |
9807 | *last_chain = next_cu; | |
9808 | } | |
9809 | else | |
9810 | last_chain = &per_cu->cu->read_in_chain; | |
9811 | ||
9812 | per_cu = next_cu; | |
9813 | } | |
9814 | } | |
9815 | ||
9816 | /* Remove a single compilation unit from the cache. */ | |
9817 | ||
9818 | static void | |
9819 | free_one_cached_comp_unit (void *target_cu) | |
9820 | { | |
9821 | struct dwarf2_per_cu_data *per_cu, **last_chain; | |
9822 | ||
9823 | per_cu = dwarf2_per_objfile->read_in_chain; | |
9824 | last_chain = &dwarf2_per_objfile->read_in_chain; | |
9825 | while (per_cu != NULL) | |
9826 | { | |
9827 | struct dwarf2_per_cu_data *next_cu; | |
9828 | ||
9829 | next_cu = per_cu->cu->read_in_chain; | |
9830 | ||
9831 | if (per_cu->cu == target_cu) | |
9832 | { | |
9833 | free_one_comp_unit (per_cu->cu); | |
9834 | *last_chain = next_cu; | |
9835 | break; | |
9836 | } | |
9837 | else | |
9838 | last_chain = &per_cu->cu->read_in_chain; | |
9839 | ||
9840 | per_cu = next_cu; | |
9841 | } | |
9842 | } | |
9843 | ||
1c379e20 DJ |
9844 | /* A pair of DIE offset and GDB type pointer. We store these |
9845 | in a hash table separate from the DIEs, and preserve them | |
9846 | when the DIEs are flushed out of cache. */ | |
9847 | ||
9848 | struct dwarf2_offset_and_type | |
9849 | { | |
9850 | unsigned int offset; | |
9851 | struct type *type; | |
9852 | }; | |
9853 | ||
9854 | /* Hash function for a dwarf2_offset_and_type. */ | |
9855 | ||
9856 | static hashval_t | |
9857 | offset_and_type_hash (const void *item) | |
9858 | { | |
9859 | const struct dwarf2_offset_and_type *ofs = item; | |
9860 | return ofs->offset; | |
9861 | } | |
9862 | ||
9863 | /* Equality function for a dwarf2_offset_and_type. */ | |
9864 | ||
9865 | static int | |
9866 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) | |
9867 | { | |
9868 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; | |
9869 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; | |
9870 | return ofs_lhs->offset == ofs_rhs->offset; | |
9871 | } | |
9872 | ||
9873 | /* Set the type associated with DIE to TYPE. Save it in CU's hash | |
9874 | table if necessary. */ | |
9875 | ||
9876 | static void | |
9877 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) | |
9878 | { | |
9879 | struct dwarf2_offset_and_type **slot, ofs; | |
9880 | ||
9881 | die->type = type; | |
9882 | ||
9883 | if (cu->per_cu == NULL) | |
9884 | return; | |
9885 | ||
9886 | if (cu->per_cu->type_hash == NULL) | |
9887 | cu->per_cu->type_hash | |
9888 | = htab_create_alloc_ex (cu->header.length / 24, | |
9889 | offset_and_type_hash, | |
9890 | offset_and_type_eq, | |
9891 | NULL, | |
9892 | &cu->objfile->objfile_obstack, | |
9893 | hashtab_obstack_allocate, | |
9894 | dummy_obstack_deallocate); | |
9895 | ||
9896 | ofs.offset = die->offset; | |
9897 | ofs.type = type; | |
9898 | slot = (struct dwarf2_offset_and_type **) | |
9899 | htab_find_slot_with_hash (cu->per_cu->type_hash, &ofs, ofs.offset, INSERT); | |
9900 | *slot = obstack_alloc (&cu->objfile->objfile_obstack, sizeof (**slot)); | |
9901 | **slot = ofs; | |
9902 | } | |
9903 | ||
1c379e20 DJ |
9904 | /* Find the type for DIE in TYPE_HASH, or return NULL if DIE does not |
9905 | have a saved type. */ | |
9906 | ||
9907 | static struct type * | |
9908 | get_die_type (struct die_info *die, htab_t type_hash) | |
9909 | { | |
9910 | struct dwarf2_offset_and_type *slot, ofs; | |
9911 | ||
9912 | ofs.offset = die->offset; | |
9913 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); | |
9914 | if (slot) | |
9915 | return slot->type; | |
9916 | else | |
9917 | return NULL; | |
9918 | } | |
9919 | ||
9920 | /* Restore the types of the DIE tree starting at START_DIE from the hash | |
9921 | table saved in CU. */ | |
9922 | ||
9923 | static void | |
9924 | reset_die_and_siblings_types (struct die_info *start_die, struct dwarf2_cu *cu) | |
9925 | { | |
9926 | struct die_info *die; | |
9927 | ||
9928 | if (cu->per_cu->type_hash == NULL) | |
9929 | return; | |
9930 | ||
9931 | for (die = start_die; die != NULL; die = die->sibling) | |
9932 | { | |
9933 | die->type = get_die_type (die, cu->per_cu->type_hash); | |
9934 | if (die->child != NULL) | |
9935 | reset_die_and_siblings_types (die->child, cu); | |
9936 | } | |
9937 | } | |
9938 | ||
10b3939b DJ |
9939 | /* Set the mark field in CU and in every other compilation unit in the |
9940 | cache that we must keep because we are keeping CU. */ | |
9941 | ||
9942 | /* Add a dependence relationship from CU to REF_PER_CU. */ | |
9943 | ||
9944 | static void | |
9945 | dwarf2_add_dependence (struct dwarf2_cu *cu, | |
9946 | struct dwarf2_per_cu_data *ref_per_cu) | |
9947 | { | |
9948 | void **slot; | |
9949 | ||
9950 | if (cu->dependencies == NULL) | |
9951 | cu->dependencies | |
9952 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, | |
9953 | NULL, &cu->comp_unit_obstack, | |
9954 | hashtab_obstack_allocate, | |
9955 | dummy_obstack_deallocate); | |
9956 | ||
9957 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); | |
9958 | if (*slot == NULL) | |
9959 | *slot = ref_per_cu; | |
9960 | } | |
1c379e20 | 9961 | |
ae038cb0 DJ |
9962 | /* Set the mark field in CU and in every other compilation unit in the |
9963 | cache that we must keep because we are keeping CU. */ | |
9964 | ||
10b3939b DJ |
9965 | static int |
9966 | dwarf2_mark_helper (void **slot, void *data) | |
9967 | { | |
9968 | struct dwarf2_per_cu_data *per_cu; | |
9969 | ||
9970 | per_cu = (struct dwarf2_per_cu_data *) *slot; | |
9971 | if (per_cu->cu->mark) | |
9972 | return 1; | |
9973 | per_cu->cu->mark = 1; | |
9974 | ||
9975 | if (per_cu->cu->dependencies != NULL) | |
9976 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); | |
9977 | ||
9978 | return 1; | |
9979 | } | |
9980 | ||
ae038cb0 DJ |
9981 | static void |
9982 | dwarf2_mark (struct dwarf2_cu *cu) | |
9983 | { | |
9984 | if (cu->mark) | |
9985 | return; | |
9986 | cu->mark = 1; | |
10b3939b DJ |
9987 | if (cu->dependencies != NULL) |
9988 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); | |
ae038cb0 DJ |
9989 | } |
9990 | ||
9991 | static void | |
9992 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) | |
9993 | { | |
9994 | while (per_cu) | |
9995 | { | |
9996 | per_cu->cu->mark = 0; | |
9997 | per_cu = per_cu->cu->read_in_chain; | |
9998 | } | |
72bf9492 DJ |
9999 | } |
10000 | ||
72bf9492 DJ |
10001 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
10002 | is its offset in .debug_info for this objfile. */ | |
10003 | ||
10004 | static hashval_t | |
10005 | partial_die_hash (const void *item) | |
10006 | { | |
10007 | const struct partial_die_info *part_die = item; | |
10008 | return part_die->offset; | |
10009 | } | |
10010 | ||
10011 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
10012 | are equal if they have the same offset. */ | |
10013 | ||
10014 | static int | |
10015 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
10016 | { | |
10017 | const struct partial_die_info *part_die_lhs = item_lhs; | |
10018 | const struct partial_die_info *part_die_rhs = item_rhs; | |
10019 | return part_die_lhs->offset == part_die_rhs->offset; | |
10020 | } | |
10021 | ||
ae038cb0 DJ |
10022 | static struct cmd_list_element *set_dwarf2_cmdlist; |
10023 | static struct cmd_list_element *show_dwarf2_cmdlist; | |
10024 | ||
10025 | static void | |
10026 | set_dwarf2_cmd (char *args, int from_tty) | |
10027 | { | |
10028 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); | |
10029 | } | |
10030 | ||
10031 | static void | |
10032 | show_dwarf2_cmd (char *args, int from_tty) | |
10033 | { | |
10034 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); | |
10035 | } | |
10036 | ||
6502dd73 DJ |
10037 | void _initialize_dwarf2_read (void); |
10038 | ||
10039 | void | |
10040 | _initialize_dwarf2_read (void) | |
10041 | { | |
10042 | dwarf2_objfile_data_key = register_objfile_data (); | |
ae038cb0 | 10043 | |
1bedd215 AC |
10044 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
10045 | Set DWARF 2 specific variables.\n\ | |
10046 | Configure DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10047 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
10048 | 0/*allow-unknown*/, &maintenance_set_cmdlist); | |
10049 | ||
1bedd215 AC |
10050 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
10051 | Show DWARF 2 specific variables\n\ | |
10052 | Show DWARF 2 variables such as the cache size"), | |
ae038cb0 DJ |
10053 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
10054 | 0/*allow-unknown*/, &maintenance_show_cmdlist); | |
10055 | ||
10056 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, | |
7915a72c AC |
10057 | &dwarf2_max_cache_age, _("\ |
10058 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10059 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ | |
10060 | A higher limit means that cached compilation units will be stored\n\ | |
10061 | in memory longer, and more total memory will be used. Zero disables\n\ | |
10062 | caching, which can slow down startup."), | |
2c5b56ce | 10063 | NULL, |
920d2a44 | 10064 | show_dwarf2_max_cache_age, |
2c5b56ce | 10065 | &set_dwarf2_cmdlist, |
ae038cb0 | 10066 | &show_dwarf2_cmdlist); |
6502dd73 | 10067 | } |