Commit | Line | Data |
---|---|---|
c906108c | 1 | /* DWARF 2 debugging format support for GDB. |
b44e9041 EZ |
2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
3 | 2004 | |
8e65ff28 | 4 | Free Software Foundation, Inc. |
c906108c SS |
5 | |
6 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |
7 | Inc. with support from Florida State University (under contract | |
8 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |
9 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |
10 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |
11 | support in dwarfread.c | |
12 | ||
c5aa993b | 13 | This file is part of GDB. |
c906108c | 14 | |
c5aa993b JM |
15 | This program is free software; you can redistribute it and/or modify |
16 | it under the terms of the GNU General Public License as published by | |
17 | the Free Software Foundation; either version 2 of the License, or (at | |
18 | your option) any later version. | |
c906108c | 19 | |
c5aa993b JM |
20 | This program is distributed in the hope that it will be useful, but |
21 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
23 | General Public License for more details. | |
c906108c | 24 | |
c5aa993b JM |
25 | You should have received a copy of the GNU General Public License |
26 | along with this program; if not, write to the Free Software | |
27 | Foundation, Inc., 59 Temple Place - Suite 330, | |
28 | Boston, MA 02111-1307, USA. */ | |
c906108c SS |
29 | |
30 | #include "defs.h" | |
31 | #include "bfd.h" | |
c906108c SS |
32 | #include "symtab.h" |
33 | #include "gdbtypes.h" | |
c906108c SS |
34 | #include "objfiles.h" |
35 | #include "elf/dwarf2.h" | |
36 | #include "buildsym.h" | |
37 | #include "demangle.h" | |
38 | #include "expression.h" | |
d5166ae1 | 39 | #include "filenames.h" /* for DOSish file names */ |
2e276125 | 40 | #include "macrotab.h" |
c906108c SS |
41 | #include "language.h" |
42 | #include "complaints.h" | |
357e46e7 | 43 | #include "bcache.h" |
4c2df51b DJ |
44 | #include "dwarf2expr.h" |
45 | #include "dwarf2loc.h" | |
9219021c | 46 | #include "cp-support.h" |
72bf9492 | 47 | #include "hashtab.h" |
4c2df51b | 48 | |
c906108c SS |
49 | #include <fcntl.h> |
50 | #include "gdb_string.h" | |
4bdf3d34 | 51 | #include "gdb_assert.h" |
c906108c SS |
52 | #include <sys/types.h> |
53 | ||
d8151005 DJ |
54 | /* A note on memory usage for this file. |
55 | ||
56 | At the present time, this code reads the debug info sections into | |
57 | the objfile's objfile_obstack. A definite improvement for startup | |
58 | time, on platforms which do not emit relocations for debug | |
59 | sections, would be to use mmap instead. The object's complete | |
60 | debug information is loaded into memory, partly to simplify | |
61 | absolute DIE references. | |
62 | ||
63 | Whether using obstacks or mmap, the sections should remain loaded | |
64 | until the objfile is released, and pointers into the section data | |
65 | can be used for any other data associated to the objfile (symbol | |
66 | names, type names, location expressions to name a few). */ | |
67 | ||
88496bb5 MS |
68 | #ifndef DWARF2_REG_TO_REGNUM |
69 | #define DWARF2_REG_TO_REGNUM(REG) (REG) | |
70 | #endif | |
71 | ||
107d2387 | 72 | #if 0 |
357e46e7 | 73 | /* .debug_info header for a compilation unit |
c906108c SS |
74 | Because of alignment constraints, this structure has padding and cannot |
75 | be mapped directly onto the beginning of the .debug_info section. */ | |
76 | typedef struct comp_unit_header | |
77 | { | |
78 | unsigned int length; /* length of the .debug_info | |
79 | contribution */ | |
80 | unsigned short version; /* version number -- 2 for DWARF | |
81 | version 2 */ | |
82 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |
83 | unsigned char addr_size; /* byte size of an address -- 4 */ | |
84 | } | |
85 | _COMP_UNIT_HEADER; | |
86 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |
107d2387 | 87 | #endif |
c906108c SS |
88 | |
89 | /* .debug_pubnames header | |
90 | Because of alignment constraints, this structure has padding and cannot | |
91 | be mapped directly onto the beginning of the .debug_info section. */ | |
92 | typedef struct pubnames_header | |
93 | { | |
94 | unsigned int length; /* length of the .debug_pubnames | |
95 | contribution */ | |
96 | unsigned char version; /* version number -- 2 for DWARF | |
97 | version 2 */ | |
98 | unsigned int info_offset; /* offset into .debug_info section */ | |
99 | unsigned int info_size; /* byte size of .debug_info section | |
100 | portion */ | |
101 | } | |
102 | _PUBNAMES_HEADER; | |
103 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 | |
104 | ||
105 | /* .debug_pubnames header | |
106 | Because of alignment constraints, this structure has padding and cannot | |
107 | be mapped directly onto the beginning of the .debug_info section. */ | |
108 | typedef struct aranges_header | |
109 | { | |
110 | unsigned int length; /* byte len of the .debug_aranges | |
111 | contribution */ | |
112 | unsigned short version; /* version number -- 2 for DWARF | |
113 | version 2 */ | |
114 | unsigned int info_offset; /* offset into .debug_info section */ | |
115 | unsigned char addr_size; /* byte size of an address */ | |
116 | unsigned char seg_size; /* byte size of segment descriptor */ | |
117 | } | |
118 | _ARANGES_HEADER; | |
119 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 | |
120 | ||
121 | /* .debug_line statement program prologue | |
122 | Because of alignment constraints, this structure has padding and cannot | |
123 | be mapped directly onto the beginning of the .debug_info section. */ | |
124 | typedef struct statement_prologue | |
125 | { | |
126 | unsigned int total_length; /* byte length of the statement | |
127 | information */ | |
128 | unsigned short version; /* version number -- 2 for DWARF | |
129 | version 2 */ | |
130 | unsigned int prologue_length; /* # bytes between prologue & | |
131 | stmt program */ | |
132 | unsigned char minimum_instruction_length; /* byte size of | |
133 | smallest instr */ | |
134 | unsigned char default_is_stmt; /* initial value of is_stmt | |
135 | register */ | |
136 | char line_base; | |
137 | unsigned char line_range; | |
138 | unsigned char opcode_base; /* number assigned to first special | |
139 | opcode */ | |
140 | unsigned char *standard_opcode_lengths; | |
141 | } | |
142 | _STATEMENT_PROLOGUE; | |
143 | ||
6502dd73 DJ |
144 | static const struct objfile_data *dwarf2_objfile_data_key; |
145 | ||
146 | struct dwarf2_per_objfile | |
147 | { | |
148 | /* Sizes of debugging sections. */ | |
149 | unsigned int info_size; | |
150 | unsigned int abbrev_size; | |
151 | unsigned int line_size; | |
152 | unsigned int pubnames_size; | |
153 | unsigned int aranges_size; | |
154 | unsigned int loc_size; | |
155 | unsigned int macinfo_size; | |
156 | unsigned int str_size; | |
157 | unsigned int ranges_size; | |
158 | unsigned int frame_size; | |
159 | unsigned int eh_frame_size; | |
160 | ||
161 | /* Loaded data from the sections. */ | |
162 | char *info_buffer; | |
163 | char *abbrev_buffer; | |
164 | char *line_buffer; | |
165 | char *str_buffer; | |
166 | char *macinfo_buffer; | |
167 | char *ranges_buffer; | |
168 | char *loc_buffer; | |
169 | }; | |
170 | ||
171 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |
c906108c | 172 | |
086df311 DJ |
173 | static asection *dwarf_info_section; |
174 | static asection *dwarf_abbrev_section; | |
175 | static asection *dwarf_line_section; | |
176 | static asection *dwarf_pubnames_section; | |
177 | static asection *dwarf_aranges_section; | |
178 | static asection *dwarf_loc_section; | |
179 | static asection *dwarf_macinfo_section; | |
180 | static asection *dwarf_str_section; | |
181 | static asection *dwarf_ranges_section; | |
182 | asection *dwarf_frame_section; | |
183 | asection *dwarf_eh_frame_section; | |
184 | ||
c906108c SS |
185 | /* names of the debugging sections */ |
186 | ||
187 | #define INFO_SECTION ".debug_info" | |
188 | #define ABBREV_SECTION ".debug_abbrev" | |
189 | #define LINE_SECTION ".debug_line" | |
190 | #define PUBNAMES_SECTION ".debug_pubnames" | |
191 | #define ARANGES_SECTION ".debug_aranges" | |
192 | #define LOC_SECTION ".debug_loc" | |
193 | #define MACINFO_SECTION ".debug_macinfo" | |
194 | #define STR_SECTION ".debug_str" | |
af34e669 | 195 | #define RANGES_SECTION ".debug_ranges" |
b6af0555 JS |
196 | #define FRAME_SECTION ".debug_frame" |
197 | #define EH_FRAME_SECTION ".eh_frame" | |
c906108c SS |
198 | |
199 | /* local data types */ | |
200 | ||
57349743 JB |
201 | /* We hold several abbreviation tables in memory at the same time. */ |
202 | #ifndef ABBREV_HASH_SIZE | |
203 | #define ABBREV_HASH_SIZE 121 | |
204 | #endif | |
205 | ||
107d2387 AC |
206 | /* The data in a compilation unit header, after target2host |
207 | translation, looks like this. */ | |
c906108c SS |
208 | struct comp_unit_head |
209 | { | |
613e1657 | 210 | unsigned long length; |
c906108c SS |
211 | short version; |
212 | unsigned int abbrev_offset; | |
213 | unsigned char addr_size; | |
107d2387 | 214 | unsigned char signed_addr_p; |
613e1657 KB |
215 | unsigned int offset_size; /* size of file offsets; either 4 or 8 */ |
216 | unsigned int initial_length_size; /* size of the length field; either | |
217 | 4 or 12 */ | |
57349743 JB |
218 | |
219 | /* Offset to the first byte of this compilation unit header in the | |
220 | * .debug_info section, for resolving relative reference dies. */ | |
221 | ||
222 | unsigned int offset; | |
223 | ||
224 | /* Pointer to this compilation unit header in the .debug_info | |
225 | * section */ | |
226 | ||
227 | char *cu_head_ptr; | |
228 | ||
229 | /* Pointer to the first die of this compilatio unit. This will | |
230 | * be the first byte following the compilation unit header. */ | |
231 | ||
232 | char *first_die_ptr; | |
233 | ||
234 | /* Pointer to the next compilation unit header in the program. */ | |
235 | ||
236 | struct comp_unit_head *next; | |
237 | ||
0d53c4c4 | 238 | /* Base address of this compilation unit. */ |
af34e669 | 239 | |
0d53c4c4 DJ |
240 | CORE_ADDR base_address; |
241 | ||
242 | /* Non-zero if base_address has been set. */ | |
243 | ||
244 | int base_known; | |
c906108c SS |
245 | }; |
246 | ||
e7c27a73 DJ |
247 | /* Internal state when decoding a particular compilation unit. */ |
248 | struct dwarf2_cu | |
249 | { | |
250 | /* The objfile containing this compilation unit. */ | |
251 | struct objfile *objfile; | |
252 | ||
253 | /* The header of the compilation unit. | |
254 | ||
255 | FIXME drow/2003-11-10: Some of the things from the comp_unit_head | |
f3dd6933 | 256 | should logically be moved to the dwarf2_cu structure. */ |
e7c27a73 | 257 | struct comp_unit_head header; |
e142c38c DJ |
258 | |
259 | struct function_range *first_fn, *last_fn, *cached_fn; | |
260 | ||
261 | /* The language we are debugging. */ | |
262 | enum language language; | |
263 | const struct language_defn *language_defn; | |
264 | ||
265 | /* The generic symbol table building routines have separate lists for | |
266 | file scope symbols and all all other scopes (local scopes). So | |
267 | we need to select the right one to pass to add_symbol_to_list(). | |
268 | We do it by keeping a pointer to the correct list in list_in_scope. | |
269 | ||
270 | FIXME: The original dwarf code just treated the file scope as the | |
271 | first local scope, and all other local scopes as nested local | |
272 | scopes, and worked fine. Check to see if we really need to | |
273 | distinguish these in buildsym.c. */ | |
274 | struct pending **list_in_scope; | |
275 | ||
276 | /* Maintain an array of referenced fundamental types for the current | |
277 | compilation unit being read. For DWARF version 1, we have to construct | |
278 | the fundamental types on the fly, since no information about the | |
279 | fundamental types is supplied. Each such fundamental type is created by | |
280 | calling a language dependent routine to create the type, and then a | |
281 | pointer to that type is then placed in the array at the index specified | |
282 | by it's FT_<TYPENAME> value. The array has a fixed size set by the | |
283 | FT_NUM_MEMBERS compile time constant, which is the number of predefined | |
284 | fundamental types gdb knows how to construct. */ | |
285 | struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ | |
f3dd6933 DJ |
286 | |
287 | /* DWARF abbreviation table associated with this compilation unit. */ | |
288 | struct abbrev_info **dwarf2_abbrevs; | |
289 | ||
290 | /* Storage for the abbrev table. */ | |
291 | struct obstack abbrev_obstack; | |
72bf9492 DJ |
292 | |
293 | /* Hash table holding all the loaded partial DIEs. */ | |
294 | htab_t partial_dies; | |
295 | ||
296 | /* Storage for things with the same lifetime as this read-in compilation | |
297 | unit, including partial DIEs. */ | |
298 | struct obstack comp_unit_obstack; | |
299 | ||
300 | /* This flag will be set if this compilation unit includes any | |
301 | DW_TAG_namespace DIEs. If we know that there are explicit | |
302 | DIEs for namespaces, we don't need to try to infer them | |
303 | from mangled names. */ | |
304 | unsigned int has_namespace_info : 1; | |
e7c27a73 DJ |
305 | }; |
306 | ||
debd256d JB |
307 | /* The line number information for a compilation unit (found in the |
308 | .debug_line section) begins with a "statement program header", | |
309 | which contains the following information. */ | |
310 | struct line_header | |
311 | { | |
312 | unsigned int total_length; | |
313 | unsigned short version; | |
314 | unsigned int header_length; | |
315 | unsigned char minimum_instruction_length; | |
316 | unsigned char default_is_stmt; | |
317 | int line_base; | |
318 | unsigned char line_range; | |
319 | unsigned char opcode_base; | |
320 | ||
321 | /* standard_opcode_lengths[i] is the number of operands for the | |
322 | standard opcode whose value is i. This means that | |
323 | standard_opcode_lengths[0] is unused, and the last meaningful | |
324 | element is standard_opcode_lengths[opcode_base - 1]. */ | |
325 | unsigned char *standard_opcode_lengths; | |
326 | ||
327 | /* The include_directories table. NOTE! These strings are not | |
328 | allocated with xmalloc; instead, they are pointers into | |
329 | debug_line_buffer. If you try to free them, `free' will get | |
330 | indigestion. */ | |
331 | unsigned int num_include_dirs, include_dirs_size; | |
332 | char **include_dirs; | |
333 | ||
334 | /* The file_names table. NOTE! These strings are not allocated | |
335 | with xmalloc; instead, they are pointers into debug_line_buffer. | |
336 | Don't try to free them directly. */ | |
337 | unsigned int num_file_names, file_names_size; | |
338 | struct file_entry | |
c906108c | 339 | { |
debd256d JB |
340 | char *name; |
341 | unsigned int dir_index; | |
342 | unsigned int mod_time; | |
343 | unsigned int length; | |
aaa75496 | 344 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
debd256d JB |
345 | } *file_names; |
346 | ||
347 | /* The start and end of the statement program following this | |
6502dd73 | 348 | header. These point into dwarf2_per_objfile->line_buffer. */ |
debd256d JB |
349 | char *statement_program_start, *statement_program_end; |
350 | }; | |
c906108c SS |
351 | |
352 | /* When we construct a partial symbol table entry we only | |
353 | need this much information. */ | |
354 | struct partial_die_info | |
355 | { | |
72bf9492 | 356 | /* Offset of this DIE. */ |
c906108c | 357 | unsigned int offset; |
72bf9492 DJ |
358 | |
359 | /* DWARF-2 tag for this DIE. */ | |
360 | ENUM_BITFIELD(dwarf_tag) tag : 16; | |
361 | ||
362 | /* Language code associated with this DIE. This is only used | |
363 | for the compilation unit DIE. */ | |
364 | unsigned int language : 8; | |
365 | ||
366 | /* Assorted flags describing the data found in this DIE. */ | |
367 | unsigned int has_children : 1; | |
368 | unsigned int is_external : 1; | |
369 | unsigned int is_declaration : 1; | |
370 | unsigned int has_type : 1; | |
371 | unsigned int has_specification : 1; | |
aaa75496 | 372 | unsigned int has_stmt_list : 1; |
72bf9492 DJ |
373 | unsigned int has_pc_info : 1; |
374 | ||
375 | /* Flag set if the SCOPE field of this structure has been | |
376 | computed. */ | |
377 | unsigned int scope_set : 1; | |
378 | ||
379 | /* The name of this DIE. Normally the value of DW_AT_name, but | |
380 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |
381 | other fashion. */ | |
c906108c | 382 | char *name; |
72bf9492 DJ |
383 | |
384 | /* The scope to prepend to our children. This is generally | |
385 | allocated on the comp_unit_obstack, so will disappear | |
386 | when this compilation unit leaves the cache. */ | |
387 | char *scope; | |
388 | ||
389 | /* The location description associated with this DIE, if any. */ | |
390 | struct dwarf_block *locdesc; | |
391 | ||
392 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |
c906108c SS |
393 | CORE_ADDR lowpc; |
394 | CORE_ADDR highpc; | |
72bf9492 DJ |
395 | |
396 | /* Pointer into the info_buffer pointing at the target of | |
397 | DW_AT_sibling, if any. */ | |
c906108c | 398 | char *sibling; |
72bf9492 DJ |
399 | |
400 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |
401 | DW_AT_specification (or DW_AT_abstract_origin or | |
402 | DW_AT_extension). */ | |
403 | unsigned int spec_offset; | |
404 | ||
aaa75496 JB |
405 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ |
406 | unsigned int line_offset; | |
407 | ||
72bf9492 DJ |
408 | /* Pointers to this DIE's parent, first child, and next sibling, |
409 | if any. */ | |
410 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |
c906108c SS |
411 | }; |
412 | ||
413 | /* This data structure holds the information of an abbrev. */ | |
414 | struct abbrev_info | |
415 | { | |
416 | unsigned int number; /* number identifying abbrev */ | |
417 | enum dwarf_tag tag; /* dwarf tag */ | |
f3dd6933 DJ |
418 | unsigned short has_children; /* boolean */ |
419 | unsigned short num_attrs; /* number of attributes */ | |
c906108c SS |
420 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
421 | struct abbrev_info *next; /* next in chain */ | |
422 | }; | |
423 | ||
424 | struct attr_abbrev | |
425 | { | |
426 | enum dwarf_attribute name; | |
427 | enum dwarf_form form; | |
428 | }; | |
429 | ||
430 | /* This data structure holds a complete die structure. */ | |
431 | struct die_info | |
432 | { | |
c5aa993b | 433 | enum dwarf_tag tag; /* Tag indicating type of die */ |
c5aa993b JM |
434 | unsigned int abbrev; /* Abbrev number */ |
435 | unsigned int offset; /* Offset in .debug_info section */ | |
436 | unsigned int num_attrs; /* Number of attributes */ | |
437 | struct attribute *attrs; /* An array of attributes */ | |
438 | struct die_info *next_ref; /* Next die in ref hash table */ | |
78ba4af6 JB |
439 | |
440 | /* The dies in a compilation unit form an n-ary tree. PARENT | |
441 | points to this die's parent; CHILD points to the first child of | |
442 | this node; and all the children of a given node are chained | |
443 | together via their SIBLING fields, terminated by a die whose | |
444 | tag is zero. */ | |
639d11d3 DC |
445 | struct die_info *child; /* Its first child, if any. */ |
446 | struct die_info *sibling; /* Its next sibling, if any. */ | |
447 | struct die_info *parent; /* Its parent, if any. */ | |
78ba4af6 | 448 | |
c5aa993b | 449 | struct type *type; /* Cached type information */ |
c906108c SS |
450 | }; |
451 | ||
452 | /* Attributes have a name and a value */ | |
453 | struct attribute | |
454 | { | |
455 | enum dwarf_attribute name; | |
456 | enum dwarf_form form; | |
457 | union | |
458 | { | |
459 | char *str; | |
460 | struct dwarf_block *blk; | |
ce5d95e1 JB |
461 | unsigned long unsnd; |
462 | long int snd; | |
c906108c SS |
463 | CORE_ADDR addr; |
464 | } | |
465 | u; | |
466 | }; | |
467 | ||
5fb290d7 DJ |
468 | struct function_range |
469 | { | |
470 | const char *name; | |
471 | CORE_ADDR lowpc, highpc; | |
472 | int seen_line; | |
473 | struct function_range *next; | |
474 | }; | |
475 | ||
c906108c SS |
476 | /* Get at parts of an attribute structure */ |
477 | ||
478 | #define DW_STRING(attr) ((attr)->u.str) | |
479 | #define DW_UNSND(attr) ((attr)->u.unsnd) | |
480 | #define DW_BLOCK(attr) ((attr)->u.blk) | |
481 | #define DW_SND(attr) ((attr)->u.snd) | |
482 | #define DW_ADDR(attr) ((attr)->u.addr) | |
483 | ||
484 | /* Blocks are a bunch of untyped bytes. */ | |
485 | struct dwarf_block | |
486 | { | |
487 | unsigned int size; | |
488 | char *data; | |
489 | }; | |
490 | ||
c906108c SS |
491 | #ifndef ATTR_ALLOC_CHUNK |
492 | #define ATTR_ALLOC_CHUNK 4 | |
493 | #endif | |
494 | ||
c906108c SS |
495 | /* A hash table of die offsets for following references. */ |
496 | #ifndef REF_HASH_SIZE | |
497 | #define REF_HASH_SIZE 1021 | |
498 | #endif | |
499 | ||
500 | static struct die_info *die_ref_table[REF_HASH_SIZE]; | |
501 | ||
c906108c SS |
502 | /* Allocate fields for structs, unions and enums in this size. */ |
503 | #ifndef DW_FIELD_ALLOC_CHUNK | |
504 | #define DW_FIELD_ALLOC_CHUNK 4 | |
505 | #endif | |
506 | ||
c906108c SS |
507 | /* A zeroed version of a partial die for initialization purposes. */ |
508 | static struct partial_die_info zeroed_partial_die; | |
509 | ||
7a292a7a SS |
510 | /* FIXME: decode_locdesc sets these variables to describe the location |
511 | to the caller. These ought to be a structure or something. If | |
512 | none of the flags are set, the object lives at the address returned | |
513 | by decode_locdesc. */ | |
514 | ||
7a292a7a SS |
515 | static int isreg; /* Object lives in register. |
516 | decode_locdesc's return value is | |
517 | the register number. */ | |
c906108c | 518 | |
c906108c | 519 | /* We put a pointer to this structure in the read_symtab_private field |
6502dd73 | 520 | of the psymtab. */ |
c906108c SS |
521 | |
522 | struct dwarf2_pinfo | |
c5aa993b | 523 | { |
6502dd73 | 524 | /* Offset in .debug_info for this compilation unit. */ |
c906108c | 525 | |
c5aa993b | 526 | unsigned long dwarf_info_offset; |
c5aa993b | 527 | }; |
c906108c SS |
528 | |
529 | #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) | |
c906108c | 530 | #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) |
c906108c | 531 | |
c906108c SS |
532 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
533 | but this would require a corresponding change in unpack_field_as_long | |
534 | and friends. */ | |
535 | static int bits_per_byte = 8; | |
536 | ||
537 | /* The routines that read and process dies for a C struct or C++ class | |
538 | pass lists of data member fields and lists of member function fields | |
539 | in an instance of a field_info structure, as defined below. */ | |
540 | struct field_info | |
c5aa993b JM |
541 | { |
542 | /* List of data member and baseclasses fields. */ | |
543 | struct nextfield | |
544 | { | |
545 | struct nextfield *next; | |
546 | int accessibility; | |
547 | int virtuality; | |
548 | struct field field; | |
549 | } | |
550 | *fields; | |
c906108c | 551 | |
c5aa993b JM |
552 | /* Number of fields. */ |
553 | int nfields; | |
c906108c | 554 | |
c5aa993b JM |
555 | /* Number of baseclasses. */ |
556 | int nbaseclasses; | |
c906108c | 557 | |
c5aa993b JM |
558 | /* Set if the accesibility of one of the fields is not public. */ |
559 | int non_public_fields; | |
c906108c | 560 | |
c5aa993b JM |
561 | /* Member function fields array, entries are allocated in the order they |
562 | are encountered in the object file. */ | |
563 | struct nextfnfield | |
564 | { | |
565 | struct nextfnfield *next; | |
566 | struct fn_field fnfield; | |
567 | } | |
568 | *fnfields; | |
c906108c | 569 | |
c5aa993b JM |
570 | /* Member function fieldlist array, contains name of possibly overloaded |
571 | member function, number of overloaded member functions and a pointer | |
572 | to the head of the member function field chain. */ | |
573 | struct fnfieldlist | |
574 | { | |
575 | char *name; | |
576 | int length; | |
577 | struct nextfnfield *head; | |
578 | } | |
579 | *fnfieldlists; | |
c906108c | 580 | |
c5aa993b JM |
581 | /* Number of entries in the fnfieldlists array. */ |
582 | int nfnfields; | |
583 | }; | |
c906108c | 584 | |
c906108c SS |
585 | /* Various complaints about symbol reading that don't abort the process */ |
586 | ||
4d3c2250 KB |
587 | static void |
588 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |
2e276125 | 589 | { |
4d3c2250 KB |
590 | complaint (&symfile_complaints, |
591 | "statement list doesn't fit in .debug_line section"); | |
592 | } | |
593 | ||
594 | static void | |
595 | dwarf2_complex_location_expr_complaint (void) | |
2e276125 | 596 | { |
4d3c2250 KB |
597 | complaint (&symfile_complaints, "location expression too complex"); |
598 | } | |
599 | ||
4d3c2250 KB |
600 | static void |
601 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |
602 | int arg3) | |
2e276125 | 603 | { |
4d3c2250 KB |
604 | complaint (&symfile_complaints, |
605 | "const value length mismatch for '%s', got %d, expected %d", arg1, | |
606 | arg2, arg3); | |
607 | } | |
608 | ||
609 | static void | |
610 | dwarf2_macros_too_long_complaint (void) | |
2e276125 | 611 | { |
4d3c2250 KB |
612 | complaint (&symfile_complaints, |
613 | "macro info runs off end of `.debug_macinfo' section"); | |
614 | } | |
615 | ||
616 | static void | |
617 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |
8e19ed76 | 618 | { |
4d3c2250 KB |
619 | complaint (&symfile_complaints, |
620 | "macro debug info contains a malformed macro definition:\n`%s'", | |
621 | arg1); | |
622 | } | |
623 | ||
624 | static void | |
625 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |
8b2dbe47 | 626 | { |
4d3c2250 KB |
627 | complaint (&symfile_complaints, |
628 | "invalid attribute class or form for '%s' in '%s'", arg1, arg2); | |
629 | } | |
c906108c | 630 | |
c906108c SS |
631 | /* local function prototypes */ |
632 | ||
4efb68b1 | 633 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
c906108c SS |
634 | |
635 | #if 0 | |
a14ed312 | 636 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
c906108c SS |
637 | #endif |
638 | ||
aaa75496 JB |
639 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
640 | struct objfile *); | |
641 | ||
642 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |
643 | struct partial_die_info *, | |
644 | struct partial_symtab *); | |
645 | ||
a14ed312 | 646 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
c906108c | 647 | |
72bf9492 DJ |
648 | static void scan_partial_symbols (struct partial_die_info *, |
649 | CORE_ADDR *, CORE_ADDR *, | |
650 | struct dwarf2_cu *); | |
c906108c | 651 | |
72bf9492 DJ |
652 | static void add_partial_symbol (struct partial_die_info *, |
653 | struct dwarf2_cu *); | |
63d06c5c | 654 | |
72bf9492 | 655 | static int pdi_needs_namespace (enum dwarf_tag tag); |
91c24f0a | 656 | |
72bf9492 DJ |
657 | static void add_partial_namespace (struct partial_die_info *pdi, |
658 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
659 | struct dwarf2_cu *cu); | |
63d06c5c | 660 | |
72bf9492 DJ |
661 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
662 | struct dwarf2_cu *cu); | |
91c24f0a DC |
663 | |
664 | static char *locate_pdi_sibling (struct partial_die_info *orig_pdi, | |
665 | char *info_ptr, | |
666 | bfd *abfd, | |
e7c27a73 | 667 | struct dwarf2_cu *cu); |
91c24f0a | 668 | |
a14ed312 | 669 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
c906108c | 670 | |
a14ed312 | 671 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
c906108c | 672 | |
188dd5d6 | 673 | char *dwarf2_read_section (struct objfile *, asection *); |
c906108c | 674 | |
e7c27a73 | 675 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
c906108c | 676 | |
f3dd6933 | 677 | static void dwarf2_free_abbrev_table (void *); |
c906108c | 678 | |
72bf9492 DJ |
679 | static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *); |
680 | ||
57349743 | 681 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
e7c27a73 | 682 | struct dwarf2_cu *); |
c906108c | 683 | |
72bf9492 DJ |
684 | static struct partial_die_info *load_partial_dies (bfd *, char *, int, |
685 | struct dwarf2_cu *); | |
686 | ||
a14ed312 | 687 | static char *read_partial_die (struct partial_die_info *, |
72bf9492 | 688 | struct abbrev_info *abbrev, unsigned int, |
e7c27a73 | 689 | bfd *, char *, struct dwarf2_cu *); |
c906108c | 690 | |
72bf9492 DJ |
691 | static struct partial_die_info *find_partial_die (unsigned long, |
692 | struct dwarf2_cu *, | |
693 | struct dwarf2_cu **); | |
694 | ||
695 | static void fixup_partial_die (struct partial_die_info *, | |
696 | struct dwarf2_cu *); | |
697 | ||
107d2387 | 698 | static char *read_full_die (struct die_info **, bfd *, char *, |
e7c27a73 | 699 | struct dwarf2_cu *, int *); |
c906108c | 700 | |
a14ed312 | 701 | static char *read_attribute (struct attribute *, struct attr_abbrev *, |
e7c27a73 | 702 | bfd *, char *, struct dwarf2_cu *); |
c906108c | 703 | |
a8329558 | 704 | static char *read_attribute_value (struct attribute *, unsigned, |
e7c27a73 | 705 | bfd *, char *, struct dwarf2_cu *); |
a8329558 | 706 | |
a14ed312 | 707 | static unsigned int read_1_byte (bfd *, char *); |
c906108c | 708 | |
a14ed312 | 709 | static int read_1_signed_byte (bfd *, char *); |
c906108c | 710 | |
a14ed312 | 711 | static unsigned int read_2_bytes (bfd *, char *); |
c906108c | 712 | |
a14ed312 | 713 | static unsigned int read_4_bytes (bfd *, char *); |
c906108c | 714 | |
ce5d95e1 | 715 | static unsigned long read_8_bytes (bfd *, char *); |
c906108c | 716 | |
e7c27a73 | 717 | static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *, |
107d2387 | 718 | int *bytes_read); |
c906108c | 719 | |
613e1657 KB |
720 | static LONGEST read_initial_length (bfd *, char *, |
721 | struct comp_unit_head *, int *bytes_read); | |
722 | ||
723 | static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *, | |
724 | int *bytes_read); | |
725 | ||
a14ed312 | 726 | static char *read_n_bytes (bfd *, char *, unsigned int); |
c906108c | 727 | |
a14ed312 | 728 | static char *read_string (bfd *, char *, unsigned int *); |
c906108c | 729 | |
4bdf3d34 JJ |
730 | static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, |
731 | unsigned int *); | |
732 | ||
ce5d95e1 | 733 | static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); |
c906108c | 734 | |
ce5d95e1 | 735 | static long read_signed_leb128 (bfd *, char *, unsigned int *); |
c906108c | 736 | |
4bb7a0a7 DJ |
737 | static char *skip_leb128 (bfd *, char *); |
738 | ||
e142c38c | 739 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
c906108c | 740 | |
e142c38c DJ |
741 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
742 | struct dwarf2_cu *); | |
c906108c | 743 | |
05cf31d1 JB |
744 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
745 | struct dwarf2_cu *cu); | |
746 | ||
e142c38c | 747 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
3ca72b44 | 748 | |
e142c38c DJ |
749 | static struct die_info *die_specification (struct die_info *die, |
750 | struct dwarf2_cu *); | |
63d06c5c | 751 | |
debd256d JB |
752 | static void free_line_header (struct line_header *lh); |
753 | ||
aaa75496 JB |
754 | static void add_file_name (struct line_header *, char *, unsigned int, |
755 | unsigned int, unsigned int); | |
756 | ||
debd256d JB |
757 | static struct line_header *(dwarf_decode_line_header |
758 | (unsigned int offset, | |
e7c27a73 | 759 | bfd *abfd, struct dwarf2_cu *cu)); |
debd256d JB |
760 | |
761 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |
aaa75496 | 762 | struct dwarf2_cu *, struct partial_symtab *); |
c906108c | 763 | |
a14ed312 | 764 | static void dwarf2_start_subfile (char *, char *); |
c906108c | 765 | |
a14ed312 | 766 | static struct symbol *new_symbol (struct die_info *, struct type *, |
e7c27a73 | 767 | struct dwarf2_cu *); |
c906108c | 768 | |
a14ed312 | 769 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
e7c27a73 | 770 | struct dwarf2_cu *); |
c906108c | 771 | |
2df3850c JM |
772 | static void dwarf2_const_value_data (struct attribute *attr, |
773 | struct symbol *sym, | |
774 | int bits); | |
775 | ||
e7c27a73 | 776 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 777 | |
e7c27a73 DJ |
778 | static struct type *die_containing_type (struct die_info *, |
779 | struct dwarf2_cu *); | |
c906108c SS |
780 | |
781 | #if 0 | |
a14ed312 | 782 | static struct type *type_at_offset (unsigned int, struct objfile *); |
c906108c SS |
783 | #endif |
784 | ||
e7c27a73 | 785 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 786 | |
e7c27a73 | 787 | static void read_type_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 788 | |
086ed43d | 789 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
63d06c5c DC |
790 | |
791 | static char *typename_concat (const char *prefix, const char *suffix); | |
792 | ||
e7c27a73 | 793 | static void read_typedef (struct die_info *, struct dwarf2_cu *); |
c906108c | 794 | |
e7c27a73 | 795 | static void read_base_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 796 | |
a02abb62 JB |
797 | static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); |
798 | ||
e7c27a73 | 799 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 800 | |
e7c27a73 | 801 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 802 | |
e7c27a73 | 803 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
c906108c | 804 | |
a14ed312 | 805 | static int dwarf2_get_pc_bounds (struct die_info *, |
e7c27a73 | 806 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); |
c906108c | 807 | |
fae299cd DC |
808 | static void get_scope_pc_bounds (struct die_info *, |
809 | CORE_ADDR *, CORE_ADDR *, | |
810 | struct dwarf2_cu *); | |
811 | ||
a14ed312 | 812 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
e7c27a73 | 813 | struct dwarf2_cu *); |
c906108c | 814 | |
a14ed312 | 815 | static void dwarf2_attach_fields_to_type (struct field_info *, |
e7c27a73 | 816 | struct type *, struct dwarf2_cu *); |
c906108c | 817 | |
a14ed312 | 818 | static void dwarf2_add_member_fn (struct field_info *, |
e26fb1d7 | 819 | struct die_info *, struct type *, |
e7c27a73 | 820 | struct dwarf2_cu *); |
c906108c | 821 | |
a14ed312 | 822 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
e7c27a73 | 823 | struct type *, struct dwarf2_cu *); |
c906108c | 824 | |
134d01f1 DJ |
825 | static void read_structure_type (struct die_info *, struct dwarf2_cu *); |
826 | ||
827 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 828 | |
8176b9b8 DC |
829 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); |
830 | ||
e7c27a73 | 831 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
c906108c | 832 | |
e7c27a73 | 833 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
d9fa45fe | 834 | |
38d518c9 | 835 | static const char *namespace_name (struct die_info *die, |
e142c38c | 836 | int *is_anonymous, struct dwarf2_cu *); |
38d518c9 | 837 | |
134d01f1 DJ |
838 | static void read_enumeration_type (struct die_info *, struct dwarf2_cu *); |
839 | ||
840 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); | |
c906108c | 841 | |
e7c27a73 | 842 | static struct type *dwarf_base_type (int, int, struct dwarf2_cu *); |
c906108c | 843 | |
e7c27a73 | 844 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
c906108c | 845 | |
e7c27a73 | 846 | static void read_array_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 847 | |
e7c27a73 | 848 | static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 849 | |
e7c27a73 DJ |
850 | static void read_tag_ptr_to_member_type (struct die_info *, |
851 | struct dwarf2_cu *); | |
c906108c | 852 | |
e7c27a73 | 853 | static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 854 | |
e7c27a73 | 855 | static void read_tag_const_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 856 | |
e7c27a73 | 857 | static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 858 | |
e7c27a73 | 859 | static void read_tag_string_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 860 | |
e7c27a73 | 861 | static void read_subroutine_type (struct die_info *, struct dwarf2_cu *); |
c906108c | 862 | |
e7c27a73 | 863 | static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *); |
c906108c | 864 | |
639d11d3 | 865 | static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd, |
e7c27a73 | 866 | struct dwarf2_cu *, |
639d11d3 DC |
867 | char **new_info_ptr, |
868 | struct die_info *parent); | |
869 | ||
870 | static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd, | |
e7c27a73 | 871 | struct dwarf2_cu *, |
639d11d3 DC |
872 | char **new_info_ptr, |
873 | struct die_info *parent); | |
874 | ||
a14ed312 | 875 | static void free_die_list (struct die_info *); |
c906108c | 876 | |
74b7792f AC |
877 | static struct cleanup *make_cleanup_free_die_list (struct die_info *); |
878 | ||
e7c27a73 | 879 | static void process_die (struct die_info *, struct dwarf2_cu *); |
c906108c | 880 | |
e142c38c | 881 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); |
c906108c | 882 | |
e142c38c | 883 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
9219021c | 884 | |
e142c38c DJ |
885 | static struct die_info *dwarf2_extension (struct die_info *die, |
886 | struct dwarf2_cu *); | |
9219021c | 887 | |
a14ed312 | 888 | static char *dwarf_tag_name (unsigned int); |
c906108c | 889 | |
a14ed312 | 890 | static char *dwarf_attr_name (unsigned int); |
c906108c | 891 | |
a14ed312 | 892 | static char *dwarf_form_name (unsigned int); |
c906108c | 893 | |
a14ed312 | 894 | static char *dwarf_stack_op_name (unsigned int); |
c906108c | 895 | |
a14ed312 | 896 | static char *dwarf_bool_name (unsigned int); |
c906108c | 897 | |
a14ed312 | 898 | static char *dwarf_type_encoding_name (unsigned int); |
c906108c SS |
899 | |
900 | #if 0 | |
a14ed312 | 901 | static char *dwarf_cfi_name (unsigned int); |
c906108c | 902 | |
a14ed312 | 903 | struct die_info *copy_die (struct die_info *); |
c906108c SS |
904 | #endif |
905 | ||
f9aca02d | 906 | static struct die_info *sibling_die (struct die_info *); |
c906108c | 907 | |
f9aca02d | 908 | static void dump_die (struct die_info *); |
c906108c | 909 | |
f9aca02d | 910 | static void dump_die_list (struct die_info *); |
c906108c | 911 | |
f9aca02d | 912 | static void store_in_ref_table (unsigned int, struct die_info *); |
c906108c | 913 | |
7f0e3f52 | 914 | static void dwarf2_empty_hash_tables (void); |
c906108c | 915 | |
e142c38c DJ |
916 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, |
917 | struct dwarf2_cu *); | |
c906108c | 918 | |
a02abb62 JB |
919 | static int dwarf2_get_attr_constant_value (struct attribute *, int); |
920 | ||
f9aca02d | 921 | static struct die_info *follow_die_ref (unsigned int); |
c906108c | 922 | |
e142c38c DJ |
923 | static struct type *dwarf2_fundamental_type (struct objfile *, int, |
924 | struct dwarf2_cu *); | |
c906108c SS |
925 | |
926 | /* memory allocation interface */ | |
927 | ||
7b5a2f43 | 928 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
c906108c | 929 | |
f3dd6933 | 930 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
c906108c | 931 | |
a14ed312 | 932 | static struct die_info *dwarf_alloc_die (void); |
c906108c | 933 | |
e142c38c | 934 | static void initialize_cu_func_list (struct dwarf2_cu *); |
5fb290d7 | 935 | |
e142c38c DJ |
936 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
937 | struct dwarf2_cu *); | |
5fb290d7 | 938 | |
2e276125 | 939 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
e7c27a73 | 940 | char *, bfd *, struct dwarf2_cu *); |
2e276125 | 941 | |
8e19ed76 PS |
942 | static int attr_form_is_block (struct attribute *); |
943 | ||
4c2df51b DJ |
944 | static void |
945 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 946 | struct dwarf2_cu *cu); |
4c2df51b | 947 | |
4bb7a0a7 DJ |
948 | static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev, |
949 | struct dwarf2_cu *cu); | |
950 | ||
72bf9492 DJ |
951 | static void free_stack_comp_unit (void *); |
952 | ||
953 | static void *hashtab_obstack_allocate (void *data, size_t size, size_t count); | |
954 | ||
955 | static void dummy_obstack_deallocate (void *object, void *data); | |
956 | ||
957 | static hashval_t partial_die_hash (const void *item); | |
958 | ||
959 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |
960 | ||
c906108c SS |
961 | /* Try to locate the sections we need for DWARF 2 debugging |
962 | information and return true if we have enough to do something. */ | |
963 | ||
964 | int | |
6502dd73 | 965 | dwarf2_has_info (struct objfile *objfile) |
c906108c | 966 | { |
6502dd73 DJ |
967 | struct dwarf2_per_objfile *data; |
968 | ||
969 | /* Initialize per-objfile state. */ | |
970 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); | |
971 | memset (data, 0, sizeof (*data)); | |
972 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |
973 | dwarf2_per_objfile = data; | |
974 | ||
188dd5d6 DJ |
975 | dwarf_info_section = 0; |
976 | dwarf_abbrev_section = 0; | |
977 | dwarf_line_section = 0; | |
978 | dwarf_str_section = 0; | |
979 | dwarf_macinfo_section = 0; | |
980 | dwarf_frame_section = 0; | |
981 | dwarf_eh_frame_section = 0; | |
982 | dwarf_ranges_section = 0; | |
983 | dwarf_loc_section = 0; | |
af34e669 | 984 | |
6502dd73 | 985 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
188dd5d6 | 986 | return (dwarf_info_section != NULL && dwarf_abbrev_section != NULL); |
c906108c SS |
987 | } |
988 | ||
989 | /* This function is mapped across the sections and remembers the | |
990 | offset and size of each of the debugging sections we are interested | |
991 | in. */ | |
992 | ||
993 | static void | |
4efb68b1 | 994 | dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) |
c906108c | 995 | { |
6314a349 | 996 | if (strcmp (sectp->name, INFO_SECTION) == 0) |
c906108c | 997 | { |
6502dd73 | 998 | dwarf2_per_objfile->info_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 999 | dwarf_info_section = sectp; |
c906108c | 1000 | } |
6314a349 | 1001 | else if (strcmp (sectp->name, ABBREV_SECTION) == 0) |
c906108c | 1002 | { |
6502dd73 | 1003 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1004 | dwarf_abbrev_section = sectp; |
c906108c | 1005 | } |
6314a349 | 1006 | else if (strcmp (sectp->name, LINE_SECTION) == 0) |
c906108c | 1007 | { |
6502dd73 | 1008 | dwarf2_per_objfile->line_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1009 | dwarf_line_section = sectp; |
c906108c | 1010 | } |
6314a349 | 1011 | else if (strcmp (sectp->name, PUBNAMES_SECTION) == 0) |
c906108c | 1012 | { |
6502dd73 | 1013 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1014 | dwarf_pubnames_section = sectp; |
c906108c | 1015 | } |
6314a349 | 1016 | else if (strcmp (sectp->name, ARANGES_SECTION) == 0) |
c906108c | 1017 | { |
6502dd73 | 1018 | dwarf2_per_objfile->aranges_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1019 | dwarf_aranges_section = sectp; |
c906108c | 1020 | } |
6314a349 | 1021 | else if (strcmp (sectp->name, LOC_SECTION) == 0) |
c906108c | 1022 | { |
6502dd73 | 1023 | dwarf2_per_objfile->loc_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1024 | dwarf_loc_section = sectp; |
c906108c | 1025 | } |
6314a349 | 1026 | else if (strcmp (sectp->name, MACINFO_SECTION) == 0) |
c906108c | 1027 | { |
6502dd73 | 1028 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size_before_reloc (sectp); |
0cf824c9 | 1029 | dwarf_macinfo_section = sectp; |
c906108c | 1030 | } |
6314a349 | 1031 | else if (strcmp (sectp->name, STR_SECTION) == 0) |
c906108c | 1032 | { |
6502dd73 | 1033 | dwarf2_per_objfile->str_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1034 | dwarf_str_section = sectp; |
c906108c | 1035 | } |
6314a349 | 1036 | else if (strcmp (sectp->name, FRAME_SECTION) == 0) |
b6af0555 | 1037 | { |
6502dd73 | 1038 | dwarf2_per_objfile->frame_size = bfd_get_section_size_before_reloc (sectp); |
086df311 | 1039 | dwarf_frame_section = sectp; |
b6af0555 | 1040 | } |
6314a349 | 1041 | else if (strcmp (sectp->name, EH_FRAME_SECTION) == 0) |
b6af0555 | 1042 | { |
3799ccc6 EZ |
1043 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
1044 | if (aflag & SEC_HAS_CONTENTS) | |
1045 | { | |
6502dd73 | 1046 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size_before_reloc (sectp); |
3799ccc6 EZ |
1047 | dwarf_eh_frame_section = sectp; |
1048 | } | |
b6af0555 | 1049 | } |
6314a349 | 1050 | else if (strcmp (sectp->name, RANGES_SECTION) == 0) |
af34e669 | 1051 | { |
6502dd73 | 1052 | dwarf2_per_objfile->ranges_size = bfd_get_section_size_before_reloc (sectp); |
6f10aeb1 | 1053 | dwarf_ranges_section = sectp; |
af34e669 | 1054 | } |
c906108c SS |
1055 | } |
1056 | ||
1057 | /* Build a partial symbol table. */ | |
1058 | ||
1059 | void | |
fba45db2 | 1060 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
c906108c | 1061 | { |
c906108c SS |
1062 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
1063 | ||
6502dd73 DJ |
1064 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); |
1065 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |
188dd5d6 DJ |
1066 | |
1067 | if (dwarf_line_section) | |
6502dd73 | 1068 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); |
41ff2da1 | 1069 | else |
6502dd73 | 1070 | dwarf2_per_objfile->line_buffer = NULL; |
c906108c | 1071 | |
188dd5d6 | 1072 | if (dwarf_str_section) |
6502dd73 | 1073 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); |
4bdf3d34 | 1074 | else |
6502dd73 | 1075 | dwarf2_per_objfile->str_buffer = NULL; |
4bdf3d34 | 1076 | |
188dd5d6 | 1077 | if (dwarf_macinfo_section) |
6502dd73 | 1078 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, |
086df311 | 1079 | dwarf_macinfo_section); |
2e276125 | 1080 | else |
6502dd73 | 1081 | dwarf2_per_objfile->macinfo_buffer = NULL; |
2e276125 | 1082 | |
188dd5d6 | 1083 | if (dwarf_ranges_section) |
6502dd73 | 1084 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); |
af34e669 | 1085 | else |
6502dd73 | 1086 | dwarf2_per_objfile->ranges_buffer = NULL; |
af34e669 | 1087 | |
188dd5d6 | 1088 | if (dwarf_loc_section) |
6502dd73 | 1089 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); |
0d53c4c4 | 1090 | else |
6502dd73 | 1091 | dwarf2_per_objfile->loc_buffer = NULL; |
0d53c4c4 | 1092 | |
ef96bde8 EZ |
1093 | if (mainline |
1094 | || (objfile->global_psymbols.size == 0 | |
1095 | && objfile->static_psymbols.size == 0)) | |
c906108c SS |
1096 | { |
1097 | init_psymbol_list (objfile, 1024); | |
1098 | } | |
1099 | ||
1100 | #if 0 | |
1101 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |
1102 | { | |
d4f3574e | 1103 | /* Things are significantly easier if we have .debug_aranges and |
c906108c SS |
1104 | .debug_pubnames sections */ |
1105 | ||
d4f3574e | 1106 | dwarf2_build_psymtabs_easy (objfile, mainline); |
c906108c SS |
1107 | } |
1108 | else | |
1109 | #endif | |
1110 | /* only test this case for now */ | |
c5aa993b | 1111 | { |
c906108c | 1112 | /* In this case we have to work a bit harder */ |
d4f3574e | 1113 | dwarf2_build_psymtabs_hard (objfile, mainline); |
c906108c SS |
1114 | } |
1115 | } | |
1116 | ||
1117 | #if 0 | |
1118 | /* Build the partial symbol table from the information in the | |
1119 | .debug_pubnames and .debug_aranges sections. */ | |
1120 | ||
1121 | static void | |
fba45db2 | 1122 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
c906108c SS |
1123 | { |
1124 | bfd *abfd = objfile->obfd; | |
1125 | char *aranges_buffer, *pubnames_buffer; | |
1126 | char *aranges_ptr, *pubnames_ptr; | |
1127 | unsigned int entry_length, version, info_offset, info_size; | |
1128 | ||
1129 | pubnames_buffer = dwarf2_read_section (objfile, | |
086df311 | 1130 | dwarf_pubnames_section); |
c906108c | 1131 | pubnames_ptr = pubnames_buffer; |
6502dd73 | 1132 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) |
c906108c | 1133 | { |
613e1657 KB |
1134 | struct comp_unit_head cu_header; |
1135 | int bytes_read; | |
1136 | ||
1137 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |
1138 | &bytes_read); | |
1139 | pubnames_ptr += bytes_read; | |
c906108c SS |
1140 | version = read_1_byte (abfd, pubnames_ptr); |
1141 | pubnames_ptr += 1; | |
1142 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |
1143 | pubnames_ptr += 4; | |
1144 | info_size = read_4_bytes (abfd, pubnames_ptr); | |
1145 | pubnames_ptr += 4; | |
1146 | } | |
1147 | ||
1148 | aranges_buffer = dwarf2_read_section (objfile, | |
086df311 | 1149 | dwarf_aranges_section); |
c906108c SS |
1150 | |
1151 | } | |
1152 | #endif | |
1153 | ||
107d2387 AC |
1154 | /* Read in the comp unit header information from the debug_info at |
1155 | info_ptr. */ | |
1156 | ||
1157 | static char * | |
1158 | read_comp_unit_head (struct comp_unit_head *cu_header, | |
1159 | char *info_ptr, bfd *abfd) | |
1160 | { | |
1161 | int signed_addr; | |
613e1657 KB |
1162 | int bytes_read; |
1163 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, | |
1164 | &bytes_read); | |
1165 | info_ptr += bytes_read; | |
107d2387 AC |
1166 | cu_header->version = read_2_bytes (abfd, info_ptr); |
1167 | info_ptr += 2; | |
613e1657 KB |
1168 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
1169 | &bytes_read); | |
1170 | info_ptr += bytes_read; | |
107d2387 AC |
1171 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
1172 | info_ptr += 1; | |
1173 | signed_addr = bfd_get_sign_extend_vma (abfd); | |
1174 | if (signed_addr < 0) | |
8e65ff28 AC |
1175 | internal_error (__FILE__, __LINE__, |
1176 | "read_comp_unit_head: dwarf from non elf file"); | |
107d2387 AC |
1177 | cu_header->signed_addr_p = signed_addr; |
1178 | return info_ptr; | |
1179 | } | |
1180 | ||
72bf9492 DJ |
1181 | static char * |
1182 | partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr, | |
1183 | bfd *abfd) | |
1184 | { | |
1185 | char *beg_of_comp_unit = info_ptr; | |
1186 | ||
1187 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |
1188 | ||
1189 | if (header->version != 2) | |
1190 | error ("Dwarf Error: wrong version in compilation unit header " | |
1191 | "(is %d, should be %d) [in module %s]", header->version, | |
1192 | 2, bfd_get_filename (abfd)); | |
1193 | ||
1194 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |
1195 | error ("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |
1196 | "(offset 0x%lx + 6) [in module %s]", | |
1197 | (long) header->abbrev_offset, | |
1198 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1199 | bfd_get_filename (abfd)); | |
1200 | ||
1201 | if (beg_of_comp_unit + header->length + header->initial_length_size | |
1202 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |
1203 | error ("Dwarf Error: bad length (0x%lx) in compilation unit header " | |
1204 | "(offset 0x%lx + 0) [in module %s]", | |
1205 | (long) header->length, | |
1206 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |
1207 | bfd_get_filename (abfd)); | |
1208 | ||
1209 | return info_ptr; | |
1210 | } | |
1211 | ||
aaa75496 JB |
1212 | /* Allocate a new partial symtab for file named NAME and mark this new |
1213 | partial symtab as being an include of PST. */ | |
1214 | ||
1215 | static void | |
1216 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |
1217 | struct objfile *objfile) | |
1218 | { | |
1219 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |
1220 | ||
1221 | subpst->section_offsets = pst->section_offsets; | |
1222 | subpst->textlow = 0; | |
1223 | subpst->texthigh = 0; | |
1224 | ||
1225 | subpst->dependencies = (struct partial_symtab **) | |
1226 | obstack_alloc (&objfile->objfile_obstack, | |
1227 | sizeof (struct partial_symtab *)); | |
1228 | subpst->dependencies[0] = pst; | |
1229 | subpst->number_of_dependencies = 1; | |
1230 | ||
1231 | subpst->globals_offset = 0; | |
1232 | subpst->n_global_syms = 0; | |
1233 | subpst->statics_offset = 0; | |
1234 | subpst->n_static_syms = 0; | |
1235 | subpst->symtab = NULL; | |
1236 | subpst->read_symtab = pst->read_symtab; | |
1237 | subpst->readin = 0; | |
1238 | ||
1239 | /* No private part is necessary for include psymtabs. This property | |
1240 | can be used to differentiate between such include psymtabs and | |
1241 | the regular ones. If it ever happens that a regular psymtab can | |
58a9656e | 1242 | legitimally have a NULL private part, then we'll have to add a |
aaa75496 | 1243 | dedicated field for that in the dwarf2_pinfo structure. */ |
58a9656e | 1244 | subpst->read_symtab_private = NULL; |
aaa75496 JB |
1245 | } |
1246 | ||
1247 | /* Read the Line Number Program data and extract the list of files | |
1248 | included by the source file represented by PST. Build an include | |
1249 | partial symtab for each of these included files. | |
1250 | ||
1251 | This procedure assumes that there *is* a Line Number Program in | |
1252 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |
1253 | before calling this procedure. */ | |
1254 | ||
1255 | static void | |
1256 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |
1257 | struct partial_die_info *pdi, | |
1258 | struct partial_symtab *pst) | |
1259 | { | |
1260 | struct objfile *objfile = cu->objfile; | |
1261 | bfd *abfd = objfile->obfd; | |
1262 | struct line_header *lh; | |
1263 | ||
1264 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |
1265 | if (lh == NULL) | |
1266 | return; /* No linetable, so no includes. */ | |
1267 | ||
1268 | dwarf_decode_lines (lh, NULL, abfd, cu, pst); | |
1269 | ||
1270 | free_line_header (lh); | |
1271 | } | |
1272 | ||
1273 | ||
c906108c SS |
1274 | /* Build the partial symbol table by doing a quick pass through the |
1275 | .debug_info and .debug_abbrev sections. */ | |
1276 | ||
1277 | static void | |
fba45db2 | 1278 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
c906108c SS |
1279 | { |
1280 | /* Instead of reading this into a big buffer, we should probably use | |
1281 | mmap() on architectures that support it. (FIXME) */ | |
1282 | bfd *abfd = objfile->obfd; | |
72bf9492 | 1283 | char *info_ptr; |
c906108c | 1284 | char *beg_of_comp_unit; |
c906108c SS |
1285 | struct partial_die_info comp_unit_die; |
1286 | struct partial_symtab *pst; | |
e142c38c | 1287 | CORE_ADDR lowpc, highpc, baseaddr; |
c906108c | 1288 | |
6502dd73 | 1289 | info_ptr = dwarf2_per_objfile->info_buffer; |
c906108c | 1290 | |
6502dd73 | 1291 | /* Since the objects we're extracting from .debug_info vary in |
af703f96 | 1292 | length, only the individual functions to extract them (like |
72bf9492 | 1293 | read_comp_unit_head and load_partial_die) can really know whether |
af703f96 JB |
1294 | the buffer is large enough to hold another complete object. |
1295 | ||
6502dd73 DJ |
1296 | At the moment, they don't actually check that. If .debug_info |
1297 | holds just one extra byte after the last compilation unit's dies, | |
1298 | then read_comp_unit_head will happily read off the end of the | |
1299 | buffer. read_partial_die is similarly casual. Those functions | |
1300 | should be fixed. | |
af703f96 JB |
1301 | |
1302 | For this loop condition, simply checking whether there's any data | |
1303 | left at all should be sufficient. */ | |
6502dd73 DJ |
1304 | while (info_ptr < (dwarf2_per_objfile->info_buffer |
1305 | + dwarf2_per_objfile->info_size)) | |
c906108c | 1306 | { |
f3dd6933 | 1307 | struct cleanup *back_to_inner; |
e7c27a73 | 1308 | struct dwarf2_cu cu; |
72bf9492 DJ |
1309 | struct abbrev_info *abbrev; |
1310 | unsigned int bytes_read; | |
1311 | struct dwarf2_per_cu_data *this_cu; | |
1312 | ||
c906108c | 1313 | beg_of_comp_unit = info_ptr; |
c906108c | 1314 | |
72bf9492 DJ |
1315 | memset (&cu, 0, sizeof (cu)); |
1316 | ||
1317 | obstack_init (&cu.comp_unit_obstack); | |
1318 | ||
1319 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |
1320 | ||
e7c27a73 | 1321 | cu.objfile = objfile; |
72bf9492 | 1322 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); |
e7c27a73 | 1323 | |
57349743 | 1324 | /* Complete the cu_header */ |
6502dd73 | 1325 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
e7c27a73 DJ |
1326 | cu.header.first_die_ptr = info_ptr; |
1327 | cu.header.cu_head_ptr = beg_of_comp_unit; | |
57349743 | 1328 | |
e142c38c DJ |
1329 | cu.list_in_scope = &file_symbols; |
1330 | ||
72bf9492 DJ |
1331 | cu.partial_dies = NULL; |
1332 | ||
c906108c | 1333 | /* Read the abbrevs for this compilation unit into a table */ |
e7c27a73 | 1334 | dwarf2_read_abbrevs (abfd, &cu); |
72bf9492 | 1335 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c SS |
1336 | |
1337 | /* Read the compilation unit die */ | |
72bf9492 DJ |
1338 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); |
1339 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |
1340 | abfd, info_ptr, &cu); | |
c906108c SS |
1341 | |
1342 | /* Set the language we're debugging */ | |
e142c38c | 1343 | set_cu_language (comp_unit_die.language, &cu); |
c906108c SS |
1344 | |
1345 | /* Allocate a new partial symbol table structure */ | |
d4f3574e | 1346 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
96baa820 | 1347 | comp_unit_die.name ? comp_unit_die.name : "", |
c906108c SS |
1348 | comp_unit_die.lowpc, |
1349 | objfile->global_psymbols.next, | |
1350 | objfile->static_psymbols.next); | |
1351 | ||
1352 | pst->read_symtab_private = (char *) | |
8b92e4d5 | 1353 | obstack_alloc (&objfile->objfile_obstack, sizeof (struct dwarf2_pinfo)); |
6502dd73 | 1354 | DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; |
613e1657 | 1355 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c SS |
1356 | |
1357 | /* Store the function that reads in the rest of the symbol table */ | |
1358 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |
1359 | ||
1360 | /* Check if comp unit has_children. | |
1361 | If so, read the rest of the partial symbols from this comp unit. | |
1362 | If not, there's no more debug_info for this comp unit. */ | |
1363 | if (comp_unit_die.has_children) | |
1364 | { | |
72bf9492 DJ |
1365 | struct partial_die_info *first_die; |
1366 | ||
91c24f0a DC |
1367 | lowpc = ((CORE_ADDR) -1); |
1368 | highpc = ((CORE_ADDR) 0); | |
1369 | ||
72bf9492 DJ |
1370 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); |
1371 | ||
1372 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |
c906108c | 1373 | |
91c24f0a DC |
1374 | /* If we didn't find a lowpc, set it to highpc to avoid |
1375 | complaints from `maint check'. */ | |
1376 | if (lowpc == ((CORE_ADDR) -1)) | |
1377 | lowpc = highpc; | |
72bf9492 | 1378 | |
c906108c SS |
1379 | /* If the compilation unit didn't have an explicit address range, |
1380 | then use the information extracted from its child dies. */ | |
0b010bcc | 1381 | if (! comp_unit_die.has_pc_info) |
c906108c | 1382 | { |
c5aa993b | 1383 | comp_unit_die.lowpc = lowpc; |
c906108c SS |
1384 | comp_unit_die.highpc = highpc; |
1385 | } | |
1386 | } | |
c5aa993b | 1387 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
c906108c SS |
1388 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
1389 | ||
1390 | pst->n_global_syms = objfile->global_psymbols.next - | |
1391 | (objfile->global_psymbols.list + pst->globals_offset); | |
1392 | pst->n_static_syms = objfile->static_psymbols.next - | |
1393 | (objfile->static_psymbols.list + pst->statics_offset); | |
1394 | sort_pst_symbols (pst); | |
1395 | ||
1396 | /* If there is already a psymtab or symtab for a file of this | |
1397 | name, remove it. (If there is a symtab, more drastic things | |
1398 | also happen.) This happens in VxWorks. */ | |
1399 | free_named_symtabs (pst->filename); | |
1400 | ||
aaa75496 JB |
1401 | if (comp_unit_die.has_stmt_list) |
1402 | { | |
1403 | /* Get the list of files included in the current compilation unit, | |
1404 | and build a psymtab for each of them. */ | |
1405 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |
1406 | } | |
1407 | ||
72bf9492 | 1408 | info_ptr = beg_of_comp_unit + cu.header.length |
e7c27a73 | 1409 | + cu.header.initial_length_size; |
f3dd6933 DJ |
1410 | |
1411 | do_cleanups (back_to_inner); | |
c906108c | 1412 | } |
c906108c SS |
1413 | } |
1414 | ||
72bf9492 DJ |
1415 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. |
1416 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |
1417 | in CU. */ | |
c906108c | 1418 | |
72bf9492 DJ |
1419 | static void |
1420 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |
1421 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |
c906108c | 1422 | { |
e7c27a73 | 1423 | struct objfile *objfile = cu->objfile; |
c906108c | 1424 | bfd *abfd = objfile->obfd; |
72bf9492 | 1425 | struct partial_die_info *pdi; |
c906108c | 1426 | |
91c24f0a DC |
1427 | /* Now, march along the PDI's, descending into ones which have |
1428 | interesting children but skipping the children of the other ones, | |
1429 | until we reach the end of the compilation unit. */ | |
c906108c | 1430 | |
72bf9492 | 1431 | pdi = first_die; |
91c24f0a | 1432 | |
72bf9492 DJ |
1433 | while (pdi != NULL) |
1434 | { | |
1435 | fixup_partial_die (pdi, cu); | |
c906108c | 1436 | |
91c24f0a DC |
1437 | /* Anonymous namespaces have no name but have interesting |
1438 | children, so we need to look at them. Ditto for anonymous | |
1439 | enums. */ | |
933c6fe4 | 1440 | |
72bf9492 DJ |
1441 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
1442 | || pdi->tag == DW_TAG_enumeration_type) | |
c906108c | 1443 | { |
72bf9492 | 1444 | switch (pdi->tag) |
c906108c SS |
1445 | { |
1446 | case DW_TAG_subprogram: | |
72bf9492 | 1447 | if (pdi->has_pc_info) |
c906108c | 1448 | { |
72bf9492 | 1449 | if (pdi->lowpc < *lowpc) |
c906108c | 1450 | { |
72bf9492 | 1451 | *lowpc = pdi->lowpc; |
c906108c | 1452 | } |
72bf9492 | 1453 | if (pdi->highpc > *highpc) |
c906108c | 1454 | { |
72bf9492 | 1455 | *highpc = pdi->highpc; |
c906108c | 1456 | } |
72bf9492 | 1457 | if (!pdi->is_declaration) |
c906108c | 1458 | { |
72bf9492 | 1459 | add_partial_symbol (pdi, cu); |
c906108c SS |
1460 | } |
1461 | } | |
1462 | break; | |
1463 | case DW_TAG_variable: | |
1464 | case DW_TAG_typedef: | |
91c24f0a | 1465 | case DW_TAG_union_type: |
72bf9492 | 1466 | if (!pdi->is_declaration) |
63d06c5c | 1467 | { |
72bf9492 | 1468 | add_partial_symbol (pdi, cu); |
63d06c5c DC |
1469 | } |
1470 | break; | |
c906108c SS |
1471 | case DW_TAG_class_type: |
1472 | case DW_TAG_structure_type: | |
72bf9492 | 1473 | if (!pdi->is_declaration) |
c906108c | 1474 | { |
72bf9492 | 1475 | add_partial_symbol (pdi, cu); |
c906108c SS |
1476 | } |
1477 | break; | |
91c24f0a | 1478 | case DW_TAG_enumeration_type: |
72bf9492 DJ |
1479 | if (!pdi->is_declaration) |
1480 | add_partial_enumeration (pdi, cu); | |
c906108c SS |
1481 | break; |
1482 | case DW_TAG_base_type: | |
a02abb62 | 1483 | case DW_TAG_subrange_type: |
c906108c | 1484 | /* File scope base type definitions are added to the partial |
c5aa993b | 1485 | symbol table. */ |
72bf9492 | 1486 | add_partial_symbol (pdi, cu); |
c906108c | 1487 | break; |
d9fa45fe | 1488 | case DW_TAG_namespace: |
72bf9492 | 1489 | add_partial_namespace (pdi, lowpc, highpc, cu); |
91c24f0a | 1490 | break; |
c906108c SS |
1491 | default: |
1492 | break; | |
1493 | } | |
1494 | } | |
1495 | ||
72bf9492 DJ |
1496 | /* If the die has a sibling, skip to the sibling. */ |
1497 | ||
1498 | pdi = pdi->die_sibling; | |
1499 | } | |
1500 | } | |
1501 | ||
1502 | /* Functions used to compute the fully scoped name of a partial DIE. | |
91c24f0a | 1503 | |
72bf9492 DJ |
1504 | Normally, this is simple. For C++, the parent DIE's fully scoped |
1505 | name is concatenated with "::" and the partial DIE's name. | |
1506 | Enumerators are an exception; they use the scope of their parent | |
1507 | enumeration type, i.e. the name of the enumeration type is not | |
1508 | prepended to the enumerator. | |
91c24f0a | 1509 | |
72bf9492 DJ |
1510 | There are two complexities. One is DW_AT_specification; in this |
1511 | case "parent" means the parent of the target of the specification, | |
1512 | instead of the direct parent of the DIE. The other is compilers | |
1513 | which do not emit DW_TAG_namespace; in this case we try to guess | |
1514 | the fully qualified name of structure types from their members' | |
1515 | linkage names. This must be done using the DIE's children rather | |
1516 | than the children of any DW_AT_specification target. We only need | |
1517 | to do this for structures at the top level, i.e. if the target of | |
1518 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |
1519 | have a parent. */ | |
1520 | ||
1521 | /* Compute the scope prefix associated with PDI's parent, in | |
1522 | compilation unit CU. The result will be allocated on CU's | |
1523 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |
1524 | field. NULL is returned if no prefix is necessary. */ | |
1525 | static char * | |
1526 | partial_die_parent_scope (struct partial_die_info *pdi, | |
1527 | struct dwarf2_cu *cu) | |
1528 | { | |
1529 | char *grandparent_scope; | |
1530 | struct partial_die_info *parent, *real_pdi; | |
1531 | struct dwarf2_cu *spec_cu; | |
91c24f0a | 1532 | |
72bf9492 DJ |
1533 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
1534 | then this means the parent of the specification DIE. */ | |
1535 | ||
1536 | real_pdi = pdi; | |
1537 | spec_cu = cu; | |
1538 | while (real_pdi->has_specification) | |
1539 | real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu); | |
1540 | ||
1541 | parent = real_pdi->die_parent; | |
1542 | if (parent == NULL) | |
1543 | return NULL; | |
1544 | ||
1545 | if (parent->scope_set) | |
1546 | return parent->scope; | |
1547 | ||
1548 | fixup_partial_die (parent, cu); | |
1549 | ||
1550 | grandparent_scope = partial_die_parent_scope (parent, spec_cu); | |
1551 | ||
1552 | if (parent->tag == DW_TAG_namespace | |
1553 | || parent->tag == DW_TAG_structure_type | |
1554 | || parent->tag == DW_TAG_class_type | |
1555 | || parent->tag == DW_TAG_union_type) | |
1556 | { | |
1557 | if (grandparent_scope == NULL) | |
1558 | parent->scope = parent->name; | |
1559 | else | |
1560 | parent->scope = obconcat (&cu->comp_unit_obstack, grandparent_scope, | |
1561 | "::", parent->name); | |
1562 | } | |
1563 | else if (parent->tag == DW_TAG_enumeration_type) | |
1564 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |
1565 | parent->scope = grandparent_scope; | |
1566 | else | |
1567 | { | |
1568 | /* FIXME drow/2004-04-01: What should we be doing with | |
1569 | function-local names? For partial symbols, we should probably be | |
1570 | ignoring them. */ | |
1571 | complaint (&symfile_complaints, | |
1572 | "unhandled containing DIE tag %d for DIE at %d", | |
1573 | parent->tag, pdi->offset); | |
1574 | parent->scope = grandparent_scope; | |
c906108c SS |
1575 | } |
1576 | ||
72bf9492 DJ |
1577 | parent->scope_set = 1; |
1578 | return parent->scope; | |
1579 | } | |
1580 | ||
1581 | /* Return the fully scoped name associated with PDI, from compilation unit | |
1582 | CU. The result will be allocated with malloc. */ | |
1583 | static char * | |
1584 | partial_die_full_name (struct partial_die_info *pdi, | |
1585 | struct dwarf2_cu *cu) | |
1586 | { | |
1587 | char *parent_scope; | |
1588 | ||
1589 | parent_scope = partial_die_parent_scope (pdi, cu); | |
1590 | if (parent_scope == NULL) | |
1591 | return NULL; | |
1592 | else | |
1593 | return concat (parent_scope, "::", pdi->name, NULL); | |
c906108c SS |
1594 | } |
1595 | ||
1596 | static void | |
72bf9492 | 1597 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
c906108c | 1598 | { |
e7c27a73 | 1599 | struct objfile *objfile = cu->objfile; |
c906108c | 1600 | CORE_ADDR addr = 0; |
72bf9492 DJ |
1601 | char *actual_name; |
1602 | const char *my_prefix; | |
5c4e30ca | 1603 | const struct partial_symbol *psym = NULL; |
e142c38c | 1604 | CORE_ADDR baseaddr; |
72bf9492 | 1605 | int built_actual_name = 0; |
e142c38c DJ |
1606 | |
1607 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 1608 | |
72bf9492 DJ |
1609 | actual_name = NULL; |
1610 | ||
1611 | if (pdi_needs_namespace (pdi->tag)) | |
63d06c5c | 1612 | { |
72bf9492 DJ |
1613 | actual_name = partial_die_full_name (pdi, cu); |
1614 | if (actual_name) | |
1615 | built_actual_name = 1; | |
63d06c5c DC |
1616 | } |
1617 | ||
72bf9492 DJ |
1618 | if (actual_name == NULL) |
1619 | actual_name = pdi->name; | |
1620 | ||
c906108c SS |
1621 | switch (pdi->tag) |
1622 | { | |
1623 | case DW_TAG_subprogram: | |
1624 | if (pdi->is_external) | |
1625 | { | |
38d518c9 | 1626 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1627 | mst_text, objfile); */ |
38d518c9 | 1628 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1629 | VAR_DOMAIN, LOC_BLOCK, |
1630 | &objfile->global_psymbols, | |
1631 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1632 | cu->language, objfile); |
c906108c SS |
1633 | } |
1634 | else | |
1635 | { | |
38d518c9 | 1636 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
c5aa993b | 1637 | mst_file_text, objfile); */ |
38d518c9 | 1638 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1639 | VAR_DOMAIN, LOC_BLOCK, |
1640 | &objfile->static_psymbols, | |
1641 | 0, pdi->lowpc + baseaddr, | |
e142c38c | 1642 | cu->language, objfile); |
c906108c SS |
1643 | } |
1644 | break; | |
1645 | case DW_TAG_variable: | |
1646 | if (pdi->is_external) | |
1647 | { | |
1648 | /* Global Variable. | |
1649 | Don't enter into the minimal symbol tables as there is | |
1650 | a minimal symbol table entry from the ELF symbols already. | |
1651 | Enter into partial symbol table if it has a location | |
1652 | descriptor or a type. | |
1653 | If the location descriptor is missing, new_symbol will create | |
1654 | a LOC_UNRESOLVED symbol, the address of the variable will then | |
1655 | be determined from the minimal symbol table whenever the variable | |
1656 | is referenced. | |
1657 | The address for the partial symbol table entry is not | |
1658 | used by GDB, but it comes in handy for debugging partial symbol | |
1659 | table building. */ | |
1660 | ||
1661 | if (pdi->locdesc) | |
e7c27a73 | 1662 | addr = decode_locdesc (pdi->locdesc, cu); |
c906108c | 1663 | if (pdi->locdesc || pdi->has_type) |
38d518c9 | 1664 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1665 | VAR_DOMAIN, LOC_STATIC, |
1666 | &objfile->global_psymbols, | |
1667 | 0, addr + baseaddr, | |
e142c38c | 1668 | cu->language, objfile); |
c906108c SS |
1669 | } |
1670 | else | |
1671 | { | |
1672 | /* Static Variable. Skip symbols without location descriptors. */ | |
1673 | if (pdi->locdesc == NULL) | |
1674 | return; | |
e7c27a73 | 1675 | addr = decode_locdesc (pdi->locdesc, cu); |
38d518c9 | 1676 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
c5aa993b | 1677 | mst_file_data, objfile); */ |
38d518c9 | 1678 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
5c4e30ca DC |
1679 | VAR_DOMAIN, LOC_STATIC, |
1680 | &objfile->static_psymbols, | |
1681 | 0, addr + baseaddr, | |
e142c38c | 1682 | cu->language, objfile); |
c906108c SS |
1683 | } |
1684 | break; | |
1685 | case DW_TAG_typedef: | |
1686 | case DW_TAG_base_type: | |
a02abb62 | 1687 | case DW_TAG_subrange_type: |
38d518c9 | 1688 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1689 | VAR_DOMAIN, LOC_TYPEDEF, |
c906108c | 1690 | &objfile->static_psymbols, |
e142c38c | 1691 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 1692 | break; |
72bf9492 DJ |
1693 | case DW_TAG_namespace: |
1694 | add_psymbol_to_list (actual_name, strlen (actual_name), | |
1695 | VAR_DOMAIN, LOC_TYPEDEF, | |
1696 | &objfile->global_psymbols, | |
1697 | 0, (CORE_ADDR) 0, cu->language, objfile); | |
1698 | break; | |
c906108c SS |
1699 | case DW_TAG_class_type: |
1700 | case DW_TAG_structure_type: | |
1701 | case DW_TAG_union_type: | |
1702 | case DW_TAG_enumeration_type: | |
1703 | /* Skip aggregate types without children, these are external | |
c5aa993b | 1704 | references. */ |
63d06c5c DC |
1705 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
1706 | static vs. global. */ | |
c906108c SS |
1707 | if (pdi->has_children == 0) |
1708 | return; | |
38d518c9 | 1709 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1710 | STRUCT_DOMAIN, LOC_TYPEDEF, |
e142c38c | 1711 | cu->language == language_cplus |
63d06c5c DC |
1712 | ? &objfile->global_psymbols |
1713 | : &objfile->static_psymbols, | |
e142c38c | 1714 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c | 1715 | |
e142c38c | 1716 | if (cu->language == language_cplus) |
c906108c SS |
1717 | { |
1718 | /* For C++, these implicitly act as typedefs as well. */ | |
38d518c9 | 1719 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1720 | VAR_DOMAIN, LOC_TYPEDEF, |
63d06c5c | 1721 | &objfile->global_psymbols, |
e142c38c | 1722 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
1723 | } |
1724 | break; | |
1725 | case DW_TAG_enumerator: | |
38d518c9 | 1726 | add_psymbol_to_list (actual_name, strlen (actual_name), |
176620f1 | 1727 | VAR_DOMAIN, LOC_CONST, |
e142c38c | 1728 | cu->language == language_cplus |
f6fe98ef DJ |
1729 | ? &objfile->global_psymbols |
1730 | : &objfile->static_psymbols, | |
e142c38c | 1731 | 0, (CORE_ADDR) 0, cu->language, objfile); |
c906108c SS |
1732 | break; |
1733 | default: | |
1734 | break; | |
1735 | } | |
5c4e30ca DC |
1736 | |
1737 | /* Check to see if we should scan the name for possible namespace | |
1738 | info. Only do this if this is C++, if we don't have namespace | |
1739 | debugging info in the file, if the psym is of an appropriate type | |
1740 | (otherwise we'll have psym == NULL), and if we actually had a | |
1741 | mangled name to begin with. */ | |
1742 | ||
72bf9492 DJ |
1743 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the |
1744 | cases which do not set PSYM above? */ | |
1745 | ||
e142c38c | 1746 | if (cu->language == language_cplus |
72bf9492 | 1747 | && cu->has_namespace_info == 0 |
5c4e30ca DC |
1748 | && psym != NULL |
1749 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym) != NULL) | |
1750 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym), | |
1751 | objfile); | |
72bf9492 DJ |
1752 | |
1753 | if (built_actual_name) | |
1754 | xfree (actual_name); | |
c906108c SS |
1755 | } |
1756 | ||
72bf9492 DJ |
1757 | /* Determine whether a die of type TAG living in a C++ class or |
1758 | namespace needs to have the name of the scope prepended to the | |
63d06c5c DC |
1759 | name listed in the die. */ |
1760 | ||
1761 | static int | |
72bf9492 | 1762 | pdi_needs_namespace (enum dwarf_tag tag) |
63d06c5c | 1763 | { |
63d06c5c DC |
1764 | switch (tag) |
1765 | { | |
72bf9492 | 1766 | case DW_TAG_namespace: |
63d06c5c DC |
1767 | case DW_TAG_typedef: |
1768 | case DW_TAG_class_type: | |
1769 | case DW_TAG_structure_type: | |
1770 | case DW_TAG_union_type: | |
1771 | case DW_TAG_enumeration_type: | |
1772 | case DW_TAG_enumerator: | |
1773 | return 1; | |
1774 | default: | |
1775 | return 0; | |
1776 | } | |
1777 | } | |
1778 | ||
5c4e30ca DC |
1779 | /* Read a partial die corresponding to a namespace; also, add a symbol |
1780 | corresponding to that namespace to the symbol table. NAMESPACE is | |
1781 | the name of the enclosing namespace. */ | |
91c24f0a | 1782 | |
72bf9492 DJ |
1783 | static void |
1784 | add_partial_namespace (struct partial_die_info *pdi, | |
91c24f0a | 1785 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
72bf9492 | 1786 | struct dwarf2_cu *cu) |
91c24f0a | 1787 | { |
e7c27a73 | 1788 | struct objfile *objfile = cu->objfile; |
5c4e30ca | 1789 | |
72bf9492 | 1790 | /* Add a symbol for the namespace. */ |
e7c27a73 | 1791 | |
72bf9492 | 1792 | add_partial_symbol (pdi, cu); |
5c4e30ca DC |
1793 | |
1794 | /* Now scan partial symbols in that namespace. */ | |
1795 | ||
91c24f0a | 1796 | if (pdi->has_children) |
72bf9492 | 1797 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); |
91c24f0a DC |
1798 | } |
1799 | ||
72bf9492 DJ |
1800 | /* See if we can figure out if the class lives in a namespace. We do |
1801 | this by looking for a member function; its demangled name will | |
1802 | contain namespace info, if there is any. */ | |
63d06c5c | 1803 | |
72bf9492 DJ |
1804 | static void |
1805 | guess_structure_name (struct partial_die_info *struct_pdi, | |
1806 | struct dwarf2_cu *cu) | |
63d06c5c | 1807 | { |
e142c38c | 1808 | if (cu->language == language_cplus |
72bf9492 | 1809 | && cu->has_namespace_info == 0 |
63d06c5c DC |
1810 | && struct_pdi->has_children) |
1811 | { | |
63d06c5c DC |
1812 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
1813 | what template types look like, because the demangler | |
1814 | frequently doesn't give the same name as the debug info. We | |
1815 | could fix this by only using the demangled name to get the | |
134d01f1 | 1816 | prefix (but see comment in read_structure_type). */ |
63d06c5c | 1817 | |
72bf9492 DJ |
1818 | struct partial_die_info *child_pdi = struct_pdi->die_child; |
1819 | struct partial_die_info *real_pdi; | |
1820 | struct dwarf2_cu *spec_cu; | |
5d51ca54 | 1821 | |
72bf9492 DJ |
1822 | /* If this DIE (this DIE's specification, if any) has a parent, then |
1823 | we should not do this. We'll prepend the parent's fully qualified | |
1824 | name when we create the partial symbol. */ | |
5d51ca54 | 1825 | |
72bf9492 DJ |
1826 | real_pdi = struct_pdi; |
1827 | spec_cu = cu; | |
1828 | while (real_pdi->has_specification) | |
1829 | real_pdi = find_partial_die (real_pdi->spec_offset, spec_cu, &spec_cu); | |
63d06c5c | 1830 | |
72bf9492 DJ |
1831 | if (real_pdi->die_parent != NULL) |
1832 | return; | |
63d06c5c | 1833 | |
72bf9492 DJ |
1834 | while (child_pdi != NULL) |
1835 | { | |
1836 | if (child_pdi->tag == DW_TAG_subprogram) | |
63d06c5c | 1837 | { |
72bf9492 DJ |
1838 | char *actual_class_name |
1839 | = class_name_from_physname (child_pdi->name); | |
63d06c5c | 1840 | if (actual_class_name != NULL) |
72bf9492 DJ |
1841 | { |
1842 | struct_pdi->name | |
1843 | = obsavestring (actual_class_name, | |
1844 | strlen (actual_class_name), | |
1845 | &cu->comp_unit_obstack); | |
1846 | xfree (actual_class_name); | |
1847 | } | |
63d06c5c DC |
1848 | break; |
1849 | } | |
72bf9492 DJ |
1850 | |
1851 | child_pdi = child_pdi->die_sibling; | |
63d06c5c DC |
1852 | } |
1853 | } | |
63d06c5c DC |
1854 | } |
1855 | ||
91c24f0a DC |
1856 | /* Read a partial die corresponding to an enumeration type. */ |
1857 | ||
72bf9492 DJ |
1858 | static void |
1859 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |
1860 | struct dwarf2_cu *cu) | |
91c24f0a | 1861 | { |
e7c27a73 | 1862 | struct objfile *objfile = cu->objfile; |
91c24f0a | 1863 | bfd *abfd = objfile->obfd; |
72bf9492 | 1864 | struct partial_die_info *pdi; |
91c24f0a DC |
1865 | |
1866 | if (enum_pdi->name != NULL) | |
72bf9492 DJ |
1867 | add_partial_symbol (enum_pdi, cu); |
1868 | ||
1869 | pdi = enum_pdi->die_child; | |
1870 | while (pdi) | |
91c24f0a | 1871 | { |
72bf9492 | 1872 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
91c24f0a DC |
1873 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); |
1874 | else | |
72bf9492 DJ |
1875 | add_partial_symbol (pdi, cu); |
1876 | pdi = pdi->die_sibling; | |
91c24f0a | 1877 | } |
91c24f0a DC |
1878 | } |
1879 | ||
4bb7a0a7 DJ |
1880 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
1881 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |
1882 | an empty DIE). In either case *BYTES_READ will be set to the length of | |
1883 | the initial number. */ | |
1884 | ||
1885 | static struct abbrev_info * | |
1886 | peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu) | |
1887 | { | |
1888 | bfd *abfd = cu->objfile->obfd; | |
1889 | unsigned int abbrev_number; | |
1890 | struct abbrev_info *abbrev; | |
1891 | ||
1892 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |
1893 | ||
1894 | if (abbrev_number == 0) | |
1895 | return NULL; | |
1896 | ||
1897 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |
1898 | if (!abbrev) | |
1899 | { | |
1900 | error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, | |
1901 | bfd_get_filename (abfd)); | |
1902 | } | |
1903 | ||
1904 | return abbrev; | |
1905 | } | |
1906 | ||
1907 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |
1908 | pointer to the end of a series of DIEs, terminated by an empty | |
1909 | DIE. Any children of the skipped DIEs will also be skipped. */ | |
1910 | ||
1911 | static char * | |
1912 | skip_children (char *info_ptr, struct dwarf2_cu *cu) | |
1913 | { | |
1914 | struct abbrev_info *abbrev; | |
1915 | unsigned int bytes_read; | |
1916 | ||
1917 | while (1) | |
1918 | { | |
1919 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
1920 | if (abbrev == NULL) | |
1921 | return info_ptr + bytes_read; | |
1922 | else | |
1923 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
1924 | } | |
1925 | } | |
1926 | ||
1927 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |
1928 | should point just after the initial uleb128 of a DIE, and the | |
1929 | abbrev corresponding to that skipped uleb128 should be passed in | |
1930 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |
1931 | children. */ | |
1932 | ||
1933 | static char * | |
1934 | skip_one_die (char *info_ptr, struct abbrev_info *abbrev, | |
1935 | struct dwarf2_cu *cu) | |
1936 | { | |
1937 | unsigned int bytes_read; | |
1938 | struct attribute attr; | |
1939 | bfd *abfd = cu->objfile->obfd; | |
1940 | unsigned int form, i; | |
1941 | ||
1942 | for (i = 0; i < abbrev->num_attrs; i++) | |
1943 | { | |
1944 | /* The only abbrev we care about is DW_AT_sibling. */ | |
1945 | if (abbrev->attrs[i].name == DW_AT_sibling) | |
1946 | { | |
1947 | read_attribute (&attr, &abbrev->attrs[i], | |
1948 | abfd, info_ptr, cu); | |
1949 | if (attr.form == DW_FORM_ref_addr) | |
1950 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); | |
1951 | else | |
6502dd73 DJ |
1952 | return dwarf2_per_objfile->info_buffer |
1953 | + dwarf2_get_ref_die_offset (&attr, cu); | |
4bb7a0a7 DJ |
1954 | } |
1955 | ||
1956 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |
1957 | form = abbrev->attrs[i].form; | |
1958 | skip_attribute: | |
1959 | switch (form) | |
1960 | { | |
1961 | case DW_FORM_addr: | |
1962 | case DW_FORM_ref_addr: | |
1963 | info_ptr += cu->header.addr_size; | |
1964 | break; | |
1965 | case DW_FORM_data1: | |
1966 | case DW_FORM_ref1: | |
1967 | case DW_FORM_flag: | |
1968 | info_ptr += 1; | |
1969 | break; | |
1970 | case DW_FORM_data2: | |
1971 | case DW_FORM_ref2: | |
1972 | info_ptr += 2; | |
1973 | break; | |
1974 | case DW_FORM_data4: | |
1975 | case DW_FORM_ref4: | |
1976 | info_ptr += 4; | |
1977 | break; | |
1978 | case DW_FORM_data8: | |
1979 | case DW_FORM_ref8: | |
1980 | info_ptr += 8; | |
1981 | break; | |
1982 | case DW_FORM_string: | |
1983 | read_string (abfd, info_ptr, &bytes_read); | |
1984 | info_ptr += bytes_read; | |
1985 | break; | |
1986 | case DW_FORM_strp: | |
1987 | info_ptr += cu->header.offset_size; | |
1988 | break; | |
1989 | case DW_FORM_block: | |
1990 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
1991 | info_ptr += bytes_read; | |
1992 | break; | |
1993 | case DW_FORM_block1: | |
1994 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |
1995 | break; | |
1996 | case DW_FORM_block2: | |
1997 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |
1998 | break; | |
1999 | case DW_FORM_block4: | |
2000 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |
2001 | break; | |
2002 | case DW_FORM_sdata: | |
2003 | case DW_FORM_udata: | |
2004 | case DW_FORM_ref_udata: | |
2005 | info_ptr = skip_leb128 (abfd, info_ptr); | |
2006 | break; | |
2007 | case DW_FORM_indirect: | |
2008 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
2009 | info_ptr += bytes_read; | |
2010 | /* We need to continue parsing from here, so just go back to | |
2011 | the top. */ | |
2012 | goto skip_attribute; | |
2013 | ||
2014 | default: | |
2015 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", | |
2016 | dwarf_form_name (form), | |
2017 | bfd_get_filename (abfd)); | |
2018 | } | |
2019 | } | |
2020 | ||
2021 | if (abbrev->has_children) | |
2022 | return skip_children (info_ptr, cu); | |
2023 | else | |
2024 | return info_ptr; | |
2025 | } | |
2026 | ||
2027 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |
2028 | the next DIE after ORIG_PDI. */ | |
91c24f0a DC |
2029 | |
2030 | static char * | |
2031 | locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr, | |
e7c27a73 | 2032 | bfd *abfd, struct dwarf2_cu *cu) |
91c24f0a DC |
2033 | { |
2034 | /* Do we know the sibling already? */ | |
72bf9492 | 2035 | |
91c24f0a DC |
2036 | if (orig_pdi->sibling) |
2037 | return orig_pdi->sibling; | |
2038 | ||
2039 | /* Are there any children to deal with? */ | |
2040 | ||
2041 | if (!orig_pdi->has_children) | |
2042 | return info_ptr; | |
2043 | ||
4bb7a0a7 | 2044 | /* Skip the children the long way. */ |
91c24f0a | 2045 | |
4bb7a0a7 | 2046 | return skip_children (info_ptr, cu); |
91c24f0a DC |
2047 | } |
2048 | ||
c906108c SS |
2049 | /* Expand this partial symbol table into a full symbol table. */ |
2050 | ||
2051 | static void | |
fba45db2 | 2052 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
c906108c SS |
2053 | { |
2054 | /* FIXME: This is barely more than a stub. */ | |
2055 | if (pst != NULL) | |
2056 | { | |
2057 | if (pst->readin) | |
2058 | { | |
2059 | warning ("bug: psymtab for %s is already read in.", pst->filename); | |
2060 | } | |
2061 | else | |
2062 | { | |
2063 | if (info_verbose) | |
2064 | { | |
2065 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |
2066 | gdb_flush (gdb_stdout); | |
2067 | } | |
2068 | ||
2069 | psymtab_to_symtab_1 (pst); | |
2070 | ||
2071 | /* Finish up the debug error message. */ | |
2072 | if (info_verbose) | |
2073 | printf_filtered ("done.\n"); | |
2074 | } | |
2075 | } | |
2076 | } | |
2077 | ||
2078 | static void | |
fba45db2 | 2079 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
c906108c SS |
2080 | { |
2081 | struct objfile *objfile = pst->objfile; | |
2082 | bfd *abfd = objfile->obfd; | |
e7c27a73 | 2083 | struct dwarf2_cu cu; |
c906108c SS |
2084 | struct die_info *dies; |
2085 | unsigned long offset; | |
2086 | CORE_ADDR lowpc, highpc; | |
2087 | struct die_info *child_die; | |
2088 | char *info_ptr; | |
2089 | struct symtab *symtab; | |
2090 | struct cleanup *back_to; | |
0d53c4c4 | 2091 | struct attribute *attr; |
e142c38c | 2092 | CORE_ADDR baseaddr; |
aaa75496 JB |
2093 | int i; |
2094 | ||
2095 | for (i = 0; i < pst->number_of_dependencies; i++) | |
2096 | if (!pst->dependencies[i]->readin) | |
2097 | { | |
2098 | /* Inform about additional files that need to be read in. */ | |
2099 | if (info_verbose) | |
2100 | { | |
2101 | fputs_filtered (" ", gdb_stdout); | |
2102 | wrap_here (""); | |
2103 | fputs_filtered ("and ", gdb_stdout); | |
2104 | wrap_here (""); | |
2105 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |
2106 | wrap_here (""); /* Flush output */ | |
2107 | gdb_flush (gdb_stdout); | |
2108 | } | |
2109 | psymtab_to_symtab_1 (pst->dependencies[i]); | |
2110 | } | |
2111 | ||
58a9656e | 2112 | if (pst->read_symtab_private == NULL) |
aaa75496 JB |
2113 | { |
2114 | /* It's an include file, no symbols to read for it. | |
2115 | Everything is in the parent symtab. */ | |
2116 | pst->readin = 1; | |
2117 | return; | |
2118 | } | |
c906108c | 2119 | |
6502dd73 DJ |
2120 | dwarf2_per_objfile = objfile_data (pst->objfile, dwarf2_objfile_data_key); |
2121 | ||
c906108c | 2122 | /* Set local variables from the partial symbol table info. */ |
c5aa993b | 2123 | offset = DWARF_INFO_OFFSET (pst); |
6502dd73 DJ |
2124 | |
2125 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |
e142c38c | 2126 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
c906108c | 2127 | |
63d06c5c DC |
2128 | /* We're in the global namespace. */ |
2129 | processing_current_prefix = ""; | |
2130 | ||
7b5a2f43 DJ |
2131 | obstack_init (&cu.comp_unit_obstack); |
2132 | back_to = make_cleanup (free_stack_comp_unit, &cu); | |
c906108c SS |
2133 | |
2134 | buildsym_init (); | |
a0b3c4fd | 2135 | make_cleanup (really_free_pendings, NULL); |
c906108c | 2136 | |
e7c27a73 DJ |
2137 | cu.objfile = objfile; |
2138 | ||
c906108c | 2139 | /* read in the comp_unit header */ |
e7c27a73 | 2140 | info_ptr = read_comp_unit_head (&cu.header, info_ptr, abfd); |
c906108c SS |
2141 | |
2142 | /* Read the abbrevs for this compilation unit */ | |
e7c27a73 | 2143 | dwarf2_read_abbrevs (abfd, &cu); |
f3dd6933 | 2144 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
c906108c | 2145 | |
e142c38c DJ |
2146 | cu.header.offset = offset; |
2147 | ||
2148 | cu.list_in_scope = &file_symbols; | |
2149 | ||
e7c27a73 | 2150 | dies = read_comp_unit (info_ptr, abfd, &cu); |
c906108c | 2151 | |
74b7792f | 2152 | make_cleanup_free_die_list (dies); |
c906108c | 2153 | |
0d53c4c4 DJ |
2154 | /* Find the base address of the compilation unit for range lists and |
2155 | location lists. It will normally be specified by DW_AT_low_pc. | |
2156 | In DWARF-3 draft 4, the base address could be overridden by | |
2157 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |
2158 | compilation units with discontinuous ranges. */ | |
2159 | ||
e7c27a73 DJ |
2160 | cu.header.base_known = 0; |
2161 | cu.header.base_address = 0; | |
0d53c4c4 | 2162 | |
e142c38c | 2163 | attr = dwarf2_attr (dies, DW_AT_entry_pc, &cu); |
0d53c4c4 DJ |
2164 | if (attr) |
2165 | { | |
e7c27a73 DJ |
2166 | cu.header.base_address = DW_ADDR (attr); |
2167 | cu.header.base_known = 1; | |
0d53c4c4 DJ |
2168 | } |
2169 | else | |
2170 | { | |
e142c38c | 2171 | attr = dwarf2_attr (dies, DW_AT_low_pc, &cu); |
0d53c4c4 DJ |
2172 | if (attr) |
2173 | { | |
e7c27a73 DJ |
2174 | cu.header.base_address = DW_ADDR (attr); |
2175 | cu.header.base_known = 1; | |
0d53c4c4 DJ |
2176 | } |
2177 | } | |
2178 | ||
c906108c | 2179 | /* Do line number decoding in read_file_scope () */ |
e7c27a73 | 2180 | process_die (dies, &cu); |
c906108c | 2181 | |
fae299cd DC |
2182 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
2183 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |
2184 | it, by scanning the DIE's below the compilation unit. */ | |
2185 | get_scope_pc_bounds (dies, &lowpc, &highpc, &cu); | |
c906108c | 2186 | |
613e1657 | 2187 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
c906108c SS |
2188 | |
2189 | /* Set symtab language to language from DW_AT_language. | |
2190 | If the compilation is from a C file generated by language preprocessors, | |
2191 | do not set the language if it was already deduced by start_subfile. */ | |
2192 | if (symtab != NULL | |
e142c38c | 2193 | && !(cu.language == language_c && symtab->language != language_c)) |
c906108c | 2194 | { |
e142c38c | 2195 | symtab->language = cu.language; |
c906108c SS |
2196 | } |
2197 | pst->symtab = symtab; | |
2198 | pst->readin = 1; | |
c906108c SS |
2199 | |
2200 | do_cleanups (back_to); | |
2201 | } | |
2202 | ||
2203 | /* Process a die and its children. */ | |
2204 | ||
2205 | static void | |
e7c27a73 | 2206 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
2207 | { |
2208 | switch (die->tag) | |
2209 | { | |
2210 | case DW_TAG_padding: | |
2211 | break; | |
2212 | case DW_TAG_compile_unit: | |
e7c27a73 | 2213 | read_file_scope (die, cu); |
c906108c SS |
2214 | break; |
2215 | case DW_TAG_subprogram: | |
e7c27a73 DJ |
2216 | read_subroutine_type (die, cu); |
2217 | read_func_scope (die, cu); | |
c906108c SS |
2218 | break; |
2219 | case DW_TAG_inlined_subroutine: | |
2220 | /* FIXME: These are ignored for now. | |
c5aa993b JM |
2221 | They could be used to set breakpoints on all inlined instances |
2222 | of a function and make GDB `next' properly over inlined functions. */ | |
c906108c SS |
2223 | break; |
2224 | case DW_TAG_lexical_block: | |
14898363 L |
2225 | case DW_TAG_try_block: |
2226 | case DW_TAG_catch_block: | |
e7c27a73 | 2227 | read_lexical_block_scope (die, cu); |
c906108c SS |
2228 | break; |
2229 | case DW_TAG_class_type: | |
2230 | case DW_TAG_structure_type: | |
2231 | case DW_TAG_union_type: | |
134d01f1 DJ |
2232 | read_structure_type (die, cu); |
2233 | process_structure_scope (die, cu); | |
c906108c SS |
2234 | break; |
2235 | case DW_TAG_enumeration_type: | |
134d01f1 DJ |
2236 | read_enumeration_type (die, cu); |
2237 | process_enumeration_scope (die, cu); | |
c906108c | 2238 | break; |
134d01f1 DJ |
2239 | |
2240 | /* FIXME drow/2004-03-14: These initialize die->type, but do not create | |
2241 | a symbol or process any children. Therefore it doesn't do anything | |
2242 | that won't be done on-demand by read_type_die. */ | |
c906108c | 2243 | case DW_TAG_subroutine_type: |
e7c27a73 | 2244 | read_subroutine_type (die, cu); |
c906108c SS |
2245 | break; |
2246 | case DW_TAG_array_type: | |
e7c27a73 | 2247 | read_array_type (die, cu); |
c906108c SS |
2248 | break; |
2249 | case DW_TAG_pointer_type: | |
e7c27a73 | 2250 | read_tag_pointer_type (die, cu); |
c906108c SS |
2251 | break; |
2252 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 2253 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
2254 | break; |
2255 | case DW_TAG_reference_type: | |
e7c27a73 | 2256 | read_tag_reference_type (die, cu); |
c906108c SS |
2257 | break; |
2258 | case DW_TAG_string_type: | |
e7c27a73 | 2259 | read_tag_string_type (die, cu); |
c906108c | 2260 | break; |
134d01f1 DJ |
2261 | /* END FIXME */ |
2262 | ||
c906108c | 2263 | case DW_TAG_base_type: |
e7c27a73 | 2264 | read_base_type (die, cu); |
134d01f1 DJ |
2265 | /* Add a typedef symbol for the type definition, if it has a |
2266 | DW_AT_name. */ | |
2267 | new_symbol (die, die->type, cu); | |
c906108c | 2268 | break; |
a02abb62 JB |
2269 | case DW_TAG_subrange_type: |
2270 | read_subrange_type (die, cu); | |
134d01f1 DJ |
2271 | /* Add a typedef symbol for the type definition, if it has a |
2272 | DW_AT_name. */ | |
2273 | new_symbol (die, die->type, cu); | |
a02abb62 | 2274 | break; |
c906108c | 2275 | case DW_TAG_common_block: |
e7c27a73 | 2276 | read_common_block (die, cu); |
c906108c SS |
2277 | break; |
2278 | case DW_TAG_common_inclusion: | |
2279 | break; | |
d9fa45fe | 2280 | case DW_TAG_namespace: |
63d06c5c | 2281 | processing_has_namespace_info = 1; |
e7c27a73 | 2282 | read_namespace (die, cu); |
d9fa45fe DC |
2283 | break; |
2284 | case DW_TAG_imported_declaration: | |
2285 | case DW_TAG_imported_module: | |
2286 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |
2287 | information contained in these. DW_TAG_imported_declaration | |
2288 | dies shouldn't have children; DW_TAG_imported_module dies | |
2289 | shouldn't in the C++ case, but conceivably could in the | |
2290 | Fortran case, so we'll have to replace this gdb_assert if | |
2291 | Fortran compilers start generating that info. */ | |
63d06c5c | 2292 | processing_has_namespace_info = 1; |
639d11d3 | 2293 | gdb_assert (die->child == NULL); |
d9fa45fe | 2294 | break; |
c906108c | 2295 | default: |
e7c27a73 | 2296 | new_symbol (die, NULL, cu); |
c906108c SS |
2297 | break; |
2298 | } | |
2299 | } | |
2300 | ||
5fb290d7 | 2301 | static void |
e142c38c | 2302 | initialize_cu_func_list (struct dwarf2_cu *cu) |
5fb290d7 | 2303 | { |
e142c38c | 2304 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
5fb290d7 DJ |
2305 | } |
2306 | ||
c906108c | 2307 | static void |
e7c27a73 | 2308 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2309 | { |
e7c27a73 DJ |
2310 | struct objfile *objfile = cu->objfile; |
2311 | struct comp_unit_head *cu_header = &cu->header; | |
debd256d | 2312 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
2acceee2 | 2313 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
c906108c SS |
2314 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
2315 | struct attribute *attr; | |
2316 | char *name = "<unknown>"; | |
2317 | char *comp_dir = NULL; | |
2318 | struct die_info *child_die; | |
2319 | bfd *abfd = objfile->obfd; | |
debd256d | 2320 | struct line_header *line_header = 0; |
e142c38c DJ |
2321 | CORE_ADDR baseaddr; |
2322 | ||
2323 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 2324 | |
fae299cd | 2325 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
c906108c SS |
2326 | |
2327 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |
2328 | from finish_block. */ | |
2acceee2 | 2329 | if (lowpc == ((CORE_ADDR) -1)) |
c906108c SS |
2330 | lowpc = highpc; |
2331 | lowpc += baseaddr; | |
2332 | highpc += baseaddr; | |
2333 | ||
e142c38c | 2334 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2335 | if (attr) |
2336 | { | |
2337 | name = DW_STRING (attr); | |
2338 | } | |
e142c38c | 2339 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
c906108c SS |
2340 | if (attr) |
2341 | { | |
2342 | comp_dir = DW_STRING (attr); | |
2343 | if (comp_dir) | |
2344 | { | |
2345 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |
2346 | directory, get rid of it. */ | |
2347 | char *cp = strchr (comp_dir, ':'); | |
2348 | ||
2349 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') | |
2350 | comp_dir = cp + 1; | |
2351 | } | |
2352 | } | |
2353 | ||
e142c38c | 2354 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2355 | if (attr) |
2356 | { | |
e142c38c | 2357 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2358 | } |
2359 | ||
2360 | /* We assume that we're processing GCC output. */ | |
2361 | processing_gcc_compilation = 2; | |
2362 | #if 0 | |
c5aa993b JM |
2363 | /* FIXME:Do something here. */ |
2364 | if (dip->at_producer != NULL) | |
c906108c SS |
2365 | { |
2366 | handle_producer (dip->at_producer); | |
2367 | } | |
2368 | #endif | |
2369 | ||
2370 | /* The compilation unit may be in a different language or objfile, | |
2371 | zero out all remembered fundamental types. */ | |
e142c38c | 2372 | memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); |
c906108c SS |
2373 | |
2374 | start_symtab (name, comp_dir, lowpc); | |
2375 | record_debugformat ("DWARF 2"); | |
2376 | ||
e142c38c | 2377 | initialize_cu_func_list (cu); |
c906108c SS |
2378 | |
2379 | /* Process all dies in compilation unit. */ | |
639d11d3 | 2380 | if (die->child != NULL) |
c906108c | 2381 | { |
639d11d3 | 2382 | child_die = die->child; |
c906108c SS |
2383 | while (child_die && child_die->tag) |
2384 | { | |
e7c27a73 | 2385 | process_die (child_die, cu); |
c906108c SS |
2386 | child_die = sibling_die (child_die); |
2387 | } | |
2388 | } | |
5fb290d7 DJ |
2389 | |
2390 | /* Decode line number information if present. */ | |
e142c38c | 2391 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2392 | if (attr) |
2393 | { | |
debd256d | 2394 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2395 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2396 | if (line_header) |
2397 | { | |
2398 | make_cleanup ((make_cleanup_ftype *) free_line_header, | |
2399 | (void *) line_header); | |
aaa75496 | 2400 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2401 | } |
5fb290d7 | 2402 | } |
debd256d | 2403 | |
2e276125 JB |
2404 | /* Decode macro information, if present. Dwarf 2 macro information |
2405 | refers to information in the line number info statement program | |
2406 | header, so we can only read it if we've read the header | |
2407 | successfully. */ | |
e142c38c | 2408 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2409 | if (attr && line_header) |
2e276125 JB |
2410 | { |
2411 | unsigned int macro_offset = DW_UNSND (attr); | |
2412 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2413 | comp_dir, abfd, cu); |
2e276125 | 2414 | } |
debd256d | 2415 | do_cleanups (back_to); |
5fb290d7 DJ |
2416 | } |
2417 | ||
2418 | static void | |
e142c38c DJ |
2419 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2420 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2421 | { |
2422 | struct function_range *thisfn; | |
2423 | ||
2424 | thisfn = (struct function_range *) | |
7b5a2f43 | 2425 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2426 | thisfn->name = name; |
2427 | thisfn->lowpc = lowpc; | |
2428 | thisfn->highpc = highpc; | |
2429 | thisfn->seen_line = 0; | |
2430 | thisfn->next = NULL; | |
2431 | ||
e142c38c DJ |
2432 | if (cu->last_fn == NULL) |
2433 | cu->first_fn = thisfn; | |
5fb290d7 | 2434 | else |
e142c38c | 2435 | cu->last_fn->next = thisfn; |
5fb290d7 | 2436 | |
e142c38c | 2437 | cu->last_fn = thisfn; |
c906108c SS |
2438 | } |
2439 | ||
2440 | static void | |
e7c27a73 | 2441 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2442 | { |
e7c27a73 | 2443 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2444 | struct context_stack *new; |
c906108c SS |
2445 | CORE_ADDR lowpc; |
2446 | CORE_ADDR highpc; | |
2447 | struct die_info *child_die; | |
2448 | struct attribute *attr; | |
2449 | char *name; | |
fdde2d81 DC |
2450 | const char *previous_prefix = processing_current_prefix; |
2451 | struct cleanup *back_to = NULL; | |
e142c38c | 2452 | CORE_ADDR baseaddr; |
c906108c | 2453 | |
e142c38c DJ |
2454 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2455 | ||
2456 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2457 | |
2458 | /* Ignore functions with missing or empty names and functions with | |
2459 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2460 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2461 | return; |
2462 | ||
086ed43d | 2463 | if (cu->language == language_cplus) |
fdde2d81 | 2464 | { |
086ed43d | 2465 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2466 | |
2a35147e JB |
2467 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2468 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2469 | given the code | |
2470 | ||
2471 | namespace N { | |
2472 | void foo() { | |
2473 | // Definition of N::foo. | |
2474 | } | |
2475 | } | |
2476 | ||
2477 | then we'll have a tree of DIEs like this: | |
2478 | ||
2479 | 1: DW_TAG_compile_unit | |
2480 | 2: DW_TAG_namespace // N | |
2481 | 3: DW_TAG_subprogram // declaration of N::foo | |
2482 | 4: DW_TAG_subprogram // definition of N::foo | |
2483 | DW_AT_specification // refers to die #3 | |
2484 | ||
2485 | Thus, when processing die #4, we have to pretend that we're | |
2486 | in the context of its DW_AT_specification, namely the contex | |
2487 | of die #3. */ | |
fdde2d81 DC |
2488 | |
2489 | if (spec_die != NULL) | |
2490 | { | |
e142c38c | 2491 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
2492 | processing_current_prefix = specification_prefix; |
2493 | back_to = make_cleanup (xfree, specification_prefix); | |
2494 | } | |
2495 | } | |
2496 | ||
c906108c SS |
2497 | lowpc += baseaddr; |
2498 | highpc += baseaddr; | |
2499 | ||
5fb290d7 | 2500 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2501 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 2502 | |
c906108c SS |
2503 | if (objfile->ei.entry_point >= lowpc && |
2504 | objfile->ei.entry_point < highpc) | |
2505 | { | |
2506 | objfile->ei.entry_func_lowpc = lowpc; | |
2507 | objfile->ei.entry_func_highpc = highpc; | |
2508 | } | |
2509 | ||
c906108c | 2510 | new = push_context (0, lowpc); |
e7c27a73 | 2511 | new->name = new_symbol (die, die->type, cu); |
4c2df51b | 2512 | |
4cecd739 DJ |
2513 | /* If there is a location expression for DW_AT_frame_base, record |
2514 | it. */ | |
e142c38c | 2515 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 2516 | if (attr) |
c034e007 AC |
2517 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
2518 | expression is being recorded directly in the function's symbol | |
2519 | and not in a separate frame-base object. I guess this hack is | |
2520 | to avoid adding some sort of frame-base adjunct/annex to the | |
2521 | function's symbol :-(. The problem with doing this is that it | |
2522 | results in a function symbol with a location expression that | |
2523 | has nothing to do with the location of the function, ouch! The | |
2524 | relationship should be: a function's symbol has-a frame base; a | |
2525 | frame-base has-a location expression. */ | |
e7c27a73 | 2526 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 2527 | |
e142c38c | 2528 | cu->list_in_scope = &local_symbols; |
c906108c | 2529 | |
639d11d3 | 2530 | if (die->child != NULL) |
c906108c | 2531 | { |
639d11d3 | 2532 | child_die = die->child; |
c906108c SS |
2533 | while (child_die && child_die->tag) |
2534 | { | |
e7c27a73 | 2535 | process_die (child_die, cu); |
c906108c SS |
2536 | child_die = sibling_die (child_die); |
2537 | } | |
2538 | } | |
2539 | ||
2540 | new = pop_context (); | |
2541 | /* Make a block for the local symbols within. */ | |
2542 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2543 | lowpc, highpc, objfile); | |
208d8187 JB |
2544 | |
2545 | /* In C++, we can have functions nested inside functions (e.g., when | |
2546 | a function declares a class that has methods). This means that | |
2547 | when we finish processing a function scope, we may need to go | |
2548 | back to building a containing block's symbol lists. */ | |
2549 | local_symbols = new->locals; | |
2550 | param_symbols = new->params; | |
2551 | ||
921e78cf JB |
2552 | /* If we've finished processing a top-level function, subsequent |
2553 | symbols go in the file symbol list. */ | |
2554 | if (outermost_context_p ()) | |
e142c38c | 2555 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
2556 | |
2557 | processing_current_prefix = previous_prefix; | |
2558 | if (back_to != NULL) | |
2559 | do_cleanups (back_to); | |
c906108c SS |
2560 | } |
2561 | ||
2562 | /* Process all the DIES contained within a lexical block scope. Start | |
2563 | a new scope, process the dies, and then close the scope. */ | |
2564 | ||
2565 | static void | |
e7c27a73 | 2566 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2567 | { |
e7c27a73 | 2568 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2569 | struct context_stack *new; |
c906108c SS |
2570 | CORE_ADDR lowpc, highpc; |
2571 | struct die_info *child_die; | |
e142c38c DJ |
2572 | CORE_ADDR baseaddr; |
2573 | ||
2574 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
2575 | |
2576 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
2577 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
2578 | as multiple lexical blocks? Handling children in a sane way would | |
2579 | be nasty. Might be easier to properly extend generic blocks to | |
2580 | describe ranges. */ | |
e7c27a73 | 2581 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2582 | return; |
2583 | lowpc += baseaddr; | |
2584 | highpc += baseaddr; | |
2585 | ||
2586 | push_context (0, lowpc); | |
639d11d3 | 2587 | if (die->child != NULL) |
c906108c | 2588 | { |
639d11d3 | 2589 | child_die = die->child; |
c906108c SS |
2590 | while (child_die && child_die->tag) |
2591 | { | |
e7c27a73 | 2592 | process_die (child_die, cu); |
c906108c SS |
2593 | child_die = sibling_die (child_die); |
2594 | } | |
2595 | } | |
2596 | new = pop_context (); | |
2597 | ||
2598 | if (local_symbols != NULL) | |
2599 | { | |
2600 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
2601 | highpc, objfile); | |
2602 | } | |
2603 | local_symbols = new->locals; | |
2604 | } | |
2605 | ||
af34e669 DJ |
2606 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
2607 | are present and valid, otherwise, return 0. Return -1 if the range is | |
2608 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 2609 | static int |
af34e669 | 2610 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 2611 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c | 2612 | { |
e7c27a73 DJ |
2613 | struct objfile *objfile = cu->objfile; |
2614 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 2615 | struct attribute *attr; |
af34e669 DJ |
2616 | bfd *obfd = objfile->obfd; |
2617 | CORE_ADDR low = 0; | |
2618 | CORE_ADDR high = 0; | |
2619 | int ret = 0; | |
c906108c | 2620 | |
e142c38c | 2621 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 2622 | if (attr) |
af34e669 DJ |
2623 | { |
2624 | high = DW_ADDR (attr); | |
e142c38c | 2625 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
2626 | if (attr) |
2627 | low = DW_ADDR (attr); | |
2628 | else | |
2629 | /* Found high w/o low attribute. */ | |
2630 | return 0; | |
2631 | ||
2632 | /* Found consecutive range of addresses. */ | |
2633 | ret = 1; | |
2634 | } | |
c906108c | 2635 | else |
af34e669 | 2636 | { |
e142c38c | 2637 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
2638 | if (attr != NULL) |
2639 | { | |
2640 | unsigned int addr_size = cu_header->addr_size; | |
2641 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
2642 | /* Value of the DW_AT_ranges attribute is the offset in the | |
a604369a | 2643 | .debug_ranges section. */ |
af34e669 DJ |
2644 | unsigned int offset = DW_UNSND (attr); |
2645 | /* Base address selection entry. */ | |
0d53c4c4 DJ |
2646 | CORE_ADDR base; |
2647 | int found_base; | |
af34e669 | 2648 | int dummy; |
af34e669 DJ |
2649 | char *buffer; |
2650 | CORE_ADDR marker; | |
2651 | int low_set; | |
2652 | ||
0d53c4c4 DJ |
2653 | found_base = cu_header->base_known; |
2654 | base = cu_header->base_address; | |
a604369a | 2655 | |
6502dd73 | 2656 | if (offset >= dwarf2_per_objfile->ranges_size) |
a604369a KB |
2657 | { |
2658 | complaint (&symfile_complaints, | |
2659 | "Offset %d out of bounds for DW_AT_ranges attribute", | |
2660 | offset); | |
2661 | return 0; | |
2662 | } | |
6502dd73 | 2663 | buffer = dwarf2_per_objfile->ranges_buffer + offset; |
af34e669 | 2664 | |
af34e669 | 2665 | /* Read in the largest possible address. */ |
e7c27a73 | 2666 | marker = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2667 | if ((marker & mask) == mask) |
2668 | { | |
2669 | /* If we found the largest possible address, then | |
2670 | read the base address. */ | |
e7c27a73 | 2671 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2672 | buffer += 2 * addr_size; |
2673 | offset += 2 * addr_size; | |
2674 | found_base = 1; | |
2675 | } | |
2676 | ||
2677 | low_set = 0; | |
2678 | ||
2679 | while (1) | |
2680 | { | |
2681 | CORE_ADDR range_beginning, range_end; | |
2682 | ||
e7c27a73 | 2683 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
af34e669 | 2684 | buffer += addr_size; |
e7c27a73 | 2685 | range_end = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2686 | buffer += addr_size; |
2687 | offset += 2 * addr_size; | |
2688 | ||
2689 | /* An end of list marker is a pair of zero addresses. */ | |
2690 | if (range_beginning == 0 && range_end == 0) | |
2691 | /* Found the end of list entry. */ | |
2692 | break; | |
2693 | ||
2694 | /* Each base address selection entry is a pair of 2 values. | |
2695 | The first is the largest possible address, the second is | |
2696 | the base address. Check for a base address here. */ | |
2697 | if ((range_beginning & mask) == mask) | |
2698 | { | |
2699 | /* If we found the largest possible address, then | |
2700 | read the base address. */ | |
e7c27a73 | 2701 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2702 | found_base = 1; |
2703 | continue; | |
2704 | } | |
2705 | ||
2706 | if (!found_base) | |
2707 | { | |
2708 | /* We have no valid base address for the ranges | |
2709 | data. */ | |
2710 | complaint (&symfile_complaints, | |
2711 | "Invalid .debug_ranges data (no base address)"); | |
2712 | return 0; | |
2713 | } | |
2714 | ||
8f05cde5 DJ |
2715 | range_beginning += base; |
2716 | range_end += base; | |
2717 | ||
af34e669 DJ |
2718 | /* FIXME: This is recording everything as a low-high |
2719 | segment of consecutive addresses. We should have a | |
2720 | data structure for discontiguous block ranges | |
2721 | instead. */ | |
2722 | if (! low_set) | |
2723 | { | |
2724 | low = range_beginning; | |
2725 | high = range_end; | |
2726 | low_set = 1; | |
2727 | } | |
2728 | else | |
2729 | { | |
2730 | if (range_beginning < low) | |
2731 | low = range_beginning; | |
2732 | if (range_end > high) | |
2733 | high = range_end; | |
2734 | } | |
2735 | } | |
2736 | ||
2737 | if (! low_set) | |
2738 | /* If the first entry is an end-of-list marker, the range | |
2739 | describes an empty scope, i.e. no instructions. */ | |
2740 | return 0; | |
2741 | ||
2742 | ret = -1; | |
2743 | } | |
2744 | } | |
c906108c SS |
2745 | |
2746 | if (high < low) | |
2747 | return 0; | |
2748 | ||
2749 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
2750 | eliminate duplicate copies of functions and vtables and such. | |
2751 | The linker will arbitrarily choose one and discard the others. | |
2752 | The AT_*_pc values for such functions refer to local labels in | |
2753 | these sections. If the section from that file was discarded, the | |
2754 | labels are not in the output, so the relocs get a value of 0. | |
2755 | If this is a discarded function, mark the pc bounds as invalid, | |
2756 | so that GDB will ignore it. */ | |
af34e669 | 2757 | if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) |
c906108c SS |
2758 | return 0; |
2759 | ||
2760 | *lowpc = low; | |
2761 | *highpc = high; | |
af34e669 | 2762 | return ret; |
c906108c SS |
2763 | } |
2764 | ||
fae299cd DC |
2765 | /* Get the low and high pc's represented by the scope DIE, and store |
2766 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
2767 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
2768 | ||
2769 | static void | |
2770 | get_scope_pc_bounds (struct die_info *die, | |
2771 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
2772 | struct dwarf2_cu *cu) | |
2773 | { | |
2774 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
2775 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
2776 | CORE_ADDR current_low, current_high; | |
2777 | ||
2778 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
2779 | { | |
2780 | best_low = current_low; | |
2781 | best_high = current_high; | |
2782 | } | |
2783 | else | |
2784 | { | |
2785 | struct die_info *child = die->child; | |
2786 | ||
2787 | while (child && child->tag) | |
2788 | { | |
2789 | switch (child->tag) { | |
2790 | case DW_TAG_subprogram: | |
2791 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
2792 | { | |
2793 | best_low = min (best_low, current_low); | |
2794 | best_high = max (best_high, current_high); | |
2795 | } | |
2796 | break; | |
2797 | case DW_TAG_namespace: | |
2798 | /* FIXME: carlton/2004-01-16: Should we do this for | |
2799 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
2800 | that current GCC's always emit the DIEs corresponding | |
2801 | to definitions of methods of classes as children of a | |
2802 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
2803 | the DIEs giving the declarations, which could be | |
2804 | anywhere). But I don't see any reason why the | |
2805 | standards says that they have to be there. */ | |
2806 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
2807 | ||
2808 | if (current_low != ((CORE_ADDR) -1)) | |
2809 | { | |
2810 | best_low = min (best_low, current_low); | |
2811 | best_high = max (best_high, current_high); | |
2812 | } | |
2813 | break; | |
2814 | default: | |
2815 | /* Ignore. */ | |
2816 | break; | |
2817 | } | |
2818 | ||
2819 | child = sibling_die (child); | |
2820 | } | |
2821 | } | |
2822 | ||
2823 | *lowpc = best_low; | |
2824 | *highpc = best_high; | |
2825 | } | |
2826 | ||
c906108c SS |
2827 | /* Add an aggregate field to the field list. */ |
2828 | ||
2829 | static void | |
107d2387 | 2830 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
2831 | struct dwarf2_cu *cu) |
2832 | { | |
2833 | struct objfile *objfile = cu->objfile; | |
c906108c SS |
2834 | struct nextfield *new_field; |
2835 | struct attribute *attr; | |
2836 | struct field *fp; | |
2837 | char *fieldname = ""; | |
2838 | ||
2839 | /* Allocate a new field list entry and link it in. */ | |
2840 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 2841 | make_cleanup (xfree, new_field); |
c906108c SS |
2842 | memset (new_field, 0, sizeof (struct nextfield)); |
2843 | new_field->next = fip->fields; | |
2844 | fip->fields = new_field; | |
2845 | fip->nfields++; | |
2846 | ||
2847 | /* Handle accessibility and virtuality of field. | |
2848 | The default accessibility for members is public, the default | |
2849 | accessibility for inheritance is private. */ | |
2850 | if (die->tag != DW_TAG_inheritance) | |
2851 | new_field->accessibility = DW_ACCESS_public; | |
2852 | else | |
2853 | new_field->accessibility = DW_ACCESS_private; | |
2854 | new_field->virtuality = DW_VIRTUALITY_none; | |
2855 | ||
e142c38c | 2856 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
2857 | if (attr) |
2858 | new_field->accessibility = DW_UNSND (attr); | |
2859 | if (new_field->accessibility != DW_ACCESS_public) | |
2860 | fip->non_public_fields = 1; | |
e142c38c | 2861 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
2862 | if (attr) |
2863 | new_field->virtuality = DW_UNSND (attr); | |
2864 | ||
2865 | fp = &new_field->field; | |
a9a9bd0f | 2866 | |
e142c38c | 2867 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 2868 | { |
a9a9bd0f DC |
2869 | /* Data member other than a C++ static data member. */ |
2870 | ||
c906108c | 2871 | /* Get type of field. */ |
e7c27a73 | 2872 | fp->type = die_type (die, cu); |
c906108c | 2873 | |
01ad7f36 DJ |
2874 | FIELD_STATIC_KIND (*fp) = 0; |
2875 | ||
c906108c | 2876 | /* Get bit size of field (zero if none). */ |
e142c38c | 2877 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
2878 | if (attr) |
2879 | { | |
2880 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
2881 | } | |
2882 | else | |
2883 | { | |
2884 | FIELD_BITSIZE (*fp) = 0; | |
2885 | } | |
2886 | ||
2887 | /* Get bit offset of field. */ | |
e142c38c | 2888 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
2889 | if (attr) |
2890 | { | |
2891 | FIELD_BITPOS (*fp) = | |
e7c27a73 | 2892 | decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; |
c906108c SS |
2893 | } |
2894 | else | |
2895 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 2896 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
2897 | if (attr) |
2898 | { | |
2899 | if (BITS_BIG_ENDIAN) | |
2900 | { | |
2901 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
2902 | additional bit offset from the MSB of the containing |
2903 | anonymous object to the MSB of the field. We don't | |
2904 | have to do anything special since we don't need to | |
2905 | know the size of the anonymous object. */ | |
c906108c SS |
2906 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
2907 | } | |
2908 | else | |
2909 | { | |
2910 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
2911 | MSB of the anonymous object, subtract off the number of |
2912 | bits from the MSB of the field to the MSB of the | |
2913 | object, and then subtract off the number of bits of | |
2914 | the field itself. The result is the bit offset of | |
2915 | the LSB of the field. */ | |
c906108c SS |
2916 | int anonymous_size; |
2917 | int bit_offset = DW_UNSND (attr); | |
2918 | ||
e142c38c | 2919 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
2920 | if (attr) |
2921 | { | |
2922 | /* The size of the anonymous object containing | |
2923 | the bit field is explicit, so use the | |
2924 | indicated size (in bytes). */ | |
2925 | anonymous_size = DW_UNSND (attr); | |
2926 | } | |
2927 | else | |
2928 | { | |
2929 | /* The size of the anonymous object containing | |
2930 | the bit field must be inferred from the type | |
2931 | attribute of the data member containing the | |
2932 | bit field. */ | |
2933 | anonymous_size = TYPE_LENGTH (fp->type); | |
2934 | } | |
2935 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
2936 | - bit_offset - FIELD_BITSIZE (*fp); | |
2937 | } | |
2938 | } | |
2939 | ||
2940 | /* Get name of field. */ | |
e142c38c | 2941 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2942 | if (attr && DW_STRING (attr)) |
2943 | fieldname = DW_STRING (attr); | |
d8151005 DJ |
2944 | |
2945 | /* The name is already allocated along with this objfile, so we don't | |
2946 | need to duplicate it for the type. */ | |
2947 | fp->name = fieldname; | |
c906108c SS |
2948 | |
2949 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 2950 | pointer or virtual base class pointer) to private. */ |
e142c38c | 2951 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
2952 | { |
2953 | new_field->accessibility = DW_ACCESS_private; | |
2954 | fip->non_public_fields = 1; | |
2955 | } | |
2956 | } | |
a9a9bd0f | 2957 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 2958 | { |
a9a9bd0f DC |
2959 | /* C++ static member. */ |
2960 | ||
2961 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
2962 | is a declaration, but all versions of G++ as of this writing | |
2963 | (so through at least 3.2.1) incorrectly generate | |
2964 | DW_TAG_variable tags. */ | |
2965 | ||
c906108c | 2966 | char *physname; |
c906108c | 2967 | |
a9a9bd0f | 2968 | /* Get name of field. */ |
e142c38c | 2969 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
2970 | if (attr && DW_STRING (attr)) |
2971 | fieldname = DW_STRING (attr); | |
2972 | else | |
c906108c SS |
2973 | return; |
2974 | ||
2df3850c | 2975 | /* Get physical name. */ |
e142c38c | 2976 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 2977 | |
d8151005 DJ |
2978 | /* The name is already allocated along with this objfile, so we don't |
2979 | need to duplicate it for the type. */ | |
2980 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 2981 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 2982 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
2983 | } |
2984 | else if (die->tag == DW_TAG_inheritance) | |
2985 | { | |
2986 | /* C++ base class field. */ | |
e142c38c | 2987 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 2988 | if (attr) |
e7c27a73 | 2989 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 2990 | * bits_per_byte); |
c906108c | 2991 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 2992 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 2993 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
2994 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
2995 | fip->nbaseclasses++; | |
2996 | } | |
2997 | } | |
2998 | ||
2999 | /* Create the vector of fields, and attach it to the type. */ | |
3000 | ||
3001 | static void | |
fba45db2 | 3002 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3003 | struct dwarf2_cu *cu) |
c906108c SS |
3004 | { |
3005 | int nfields = fip->nfields; | |
3006 | ||
3007 | /* Record the field count, allocate space for the array of fields, | |
3008 | and create blank accessibility bitfields if necessary. */ | |
3009 | TYPE_NFIELDS (type) = nfields; | |
3010 | TYPE_FIELDS (type) = (struct field *) | |
3011 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3012 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3013 | ||
3014 | if (fip->non_public_fields) | |
3015 | { | |
3016 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3017 | ||
3018 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3019 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3020 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3021 | ||
3022 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3023 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3024 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3025 | ||
3026 | TYPE_FIELD_IGNORE_BITS (type) = | |
3027 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3028 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3029 | } | |
3030 | ||
3031 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3032 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3033 | if (fip->nbaseclasses) | |
3034 | { | |
3035 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
3036 | char *pointer; | |
3037 | ||
3038 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3039 | pointer = (char *) TYPE_ALLOC (type, num_bytes); | |
3040 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
3041 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); | |
3042 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3043 | } | |
3044 | ||
3045 | /* Copy the saved-up fields into the field vector. Start from the head | |
3046 | of the list, adding to the tail of the field array, so that they end | |
3047 | up in the same order in the array in which they were added to the list. */ | |
3048 | while (nfields-- > 0) | |
3049 | { | |
3050 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3051 | switch (fip->fields->accessibility) | |
3052 | { | |
c5aa993b JM |
3053 | case DW_ACCESS_private: |
3054 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3055 | break; | |
c906108c | 3056 | |
c5aa993b JM |
3057 | case DW_ACCESS_protected: |
3058 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3059 | break; | |
c906108c | 3060 | |
c5aa993b JM |
3061 | case DW_ACCESS_public: |
3062 | break; | |
c906108c | 3063 | |
c5aa993b JM |
3064 | default: |
3065 | /* Unknown accessibility. Complain and treat it as public. */ | |
3066 | { | |
4d3c2250 KB |
3067 | complaint (&symfile_complaints, "unsupported accessibility %d", |
3068 | fip->fields->accessibility); | |
c5aa993b JM |
3069 | } |
3070 | break; | |
c906108c SS |
3071 | } |
3072 | if (nfields < fip->nbaseclasses) | |
3073 | { | |
3074 | switch (fip->fields->virtuality) | |
3075 | { | |
c5aa993b JM |
3076 | case DW_VIRTUALITY_virtual: |
3077 | case DW_VIRTUALITY_pure_virtual: | |
3078 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3079 | break; | |
c906108c SS |
3080 | } |
3081 | } | |
3082 | fip->fields = fip->fields->next; | |
3083 | } | |
3084 | } | |
3085 | ||
c906108c SS |
3086 | /* Add a member function to the proper fieldlist. */ |
3087 | ||
3088 | static void | |
107d2387 | 3089 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3090 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3091 | { |
e7c27a73 | 3092 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3093 | struct attribute *attr; |
3094 | struct fnfieldlist *flp; | |
3095 | int i; | |
3096 | struct fn_field *fnp; | |
3097 | char *fieldname; | |
3098 | char *physname; | |
3099 | struct nextfnfield *new_fnfield; | |
3100 | ||
2df3850c | 3101 | /* Get name of member function. */ |
e142c38c | 3102 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
3103 | if (attr && DW_STRING (attr)) |
3104 | fieldname = DW_STRING (attr); | |
c906108c | 3105 | else |
2df3850c | 3106 | return; |
c906108c | 3107 | |
2df3850c | 3108 | /* Get the mangled name. */ |
e142c38c | 3109 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3110 | |
3111 | /* Look up member function name in fieldlist. */ | |
3112 | for (i = 0; i < fip->nfnfields; i++) | |
3113 | { | |
27bfe10e | 3114 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3115 | break; |
3116 | } | |
3117 | ||
3118 | /* Create new list element if necessary. */ | |
3119 | if (i < fip->nfnfields) | |
3120 | flp = &fip->fnfieldlists[i]; | |
3121 | else | |
3122 | { | |
3123 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3124 | { | |
3125 | fip->fnfieldlists = (struct fnfieldlist *) | |
3126 | xrealloc (fip->fnfieldlists, | |
3127 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3128 | * sizeof (struct fnfieldlist)); |
c906108c | 3129 | if (fip->nfnfields == 0) |
c13c43fd | 3130 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3131 | } |
3132 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3133 | flp->name = fieldname; | |
3134 | flp->length = 0; | |
3135 | flp->head = NULL; | |
3136 | fip->nfnfields++; | |
3137 | } | |
3138 | ||
3139 | /* Create a new member function field and chain it to the field list | |
3140 | entry. */ | |
3141 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3142 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3143 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3144 | new_fnfield->next = flp->head; | |
3145 | flp->head = new_fnfield; | |
3146 | flp->length++; | |
3147 | ||
3148 | /* Fill in the member function field info. */ | |
3149 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3150 | /* The name is already allocated along with this objfile, so we don't |
3151 | need to duplicate it for the type. */ | |
3152 | fnp->physname = physname ? physname : ""; | |
c906108c SS |
3153 | fnp->type = alloc_type (objfile); |
3154 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) | |
3155 | { | |
c906108c | 3156 | int nparams = TYPE_NFIELDS (die->type); |
c906108c | 3157 | |
e26fb1d7 DC |
3158 | /* TYPE is the domain of this method, and DIE->TYPE is the type |
3159 | of the method itself (TYPE_CODE_METHOD). */ | |
3160 | smash_to_method_type (fnp->type, type, | |
ad2f7632 DJ |
3161 | TYPE_TARGET_TYPE (die->type), |
3162 | TYPE_FIELDS (die->type), | |
3163 | TYPE_NFIELDS (die->type), | |
3164 | TYPE_VARARGS (die->type)); | |
c906108c SS |
3165 | |
3166 | /* Handle static member functions. | |
c5aa993b JM |
3167 | Dwarf2 has no clean way to discern C++ static and non-static |
3168 | member functions. G++ helps GDB by marking the first | |
3169 | parameter for non-static member functions (which is the | |
3170 | this pointer) as artificial. We obtain this information | |
3171 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
3172 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
3173 | fnp->voffset = VOFFSET_STATIC; | |
3174 | } | |
3175 | else | |
4d3c2250 KB |
3176 | complaint (&symfile_complaints, "member function type missing for '%s'", |
3177 | physname); | |
c906108c SS |
3178 | |
3179 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3180 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3181 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3182 | |
3183 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3184 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3185 | ||
3186 | /* Get accessibility. */ | |
e142c38c | 3187 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3188 | if (attr) |
3189 | { | |
3190 | switch (DW_UNSND (attr)) | |
3191 | { | |
c5aa993b JM |
3192 | case DW_ACCESS_private: |
3193 | fnp->is_private = 1; | |
3194 | break; | |
3195 | case DW_ACCESS_protected: | |
3196 | fnp->is_protected = 1; | |
3197 | break; | |
c906108c SS |
3198 | } |
3199 | } | |
3200 | ||
b02dede2 | 3201 | /* Check for artificial methods. */ |
e142c38c | 3202 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3203 | if (attr && DW_UNSND (attr) != 0) |
3204 | fnp->is_artificial = 1; | |
3205 | ||
c906108c | 3206 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3207 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3208 | if (attr) |
8e19ed76 PS |
3209 | { |
3210 | /* Support the .debug_loc offsets */ | |
3211 | if (attr_form_is_block (attr)) | |
3212 | { | |
e7c27a73 | 3213 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 PS |
3214 | } |
3215 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3216 | { | |
4d3c2250 | 3217 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3218 | } |
3219 | else | |
3220 | { | |
4d3c2250 KB |
3221 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3222 | fieldname); | |
8e19ed76 PS |
3223 | } |
3224 | } | |
c906108c SS |
3225 | } |
3226 | ||
3227 | /* Create the vector of member function fields, and attach it to the type. */ | |
3228 | ||
3229 | static void | |
fba45db2 | 3230 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3231 | struct dwarf2_cu *cu) |
c906108c SS |
3232 | { |
3233 | struct fnfieldlist *flp; | |
3234 | int total_length = 0; | |
3235 | int i; | |
3236 | ||
3237 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3238 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3239 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3240 | ||
3241 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3242 | { | |
3243 | struct nextfnfield *nfp = flp->head; | |
3244 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3245 | int k; | |
3246 | ||
3247 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3248 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3249 | fn_flp->fn_fields = (struct fn_field *) | |
3250 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3251 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3252 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3253 | |
3254 | total_length += flp->length; | |
3255 | } | |
3256 | ||
3257 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3258 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3259 | } | |
3260 | ||
3261 | /* Called when we find the DIE that starts a structure or union scope | |
3262 | (definition) to process all dies that define the members of the | |
3263 | structure or union. | |
3264 | ||
3265 | NOTE: we need to call struct_type regardless of whether or not the | |
3266 | DIE has an at_name attribute, since it might be an anonymous | |
3267 | structure or union. This gets the type entered into our set of | |
3268 | user defined types. | |
3269 | ||
3270 | However, if the structure is incomplete (an opaque struct/union) | |
3271 | then suppress creating a symbol table entry for it since gdb only | |
3272 | wants to find the one with the complete definition. Note that if | |
3273 | it is complete, we just call new_symbol, which does it's own | |
3274 | checking about whether the struct/union is anonymous or not (and | |
3275 | suppresses creating a symbol table entry itself). */ | |
3276 | ||
3277 | static void | |
134d01f1 | 3278 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3279 | { |
e7c27a73 | 3280 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3281 | struct type *type; |
3282 | struct attribute *attr; | |
63d06c5c DC |
3283 | const char *previous_prefix = processing_current_prefix; |
3284 | struct cleanup *back_to = NULL; | |
c906108c | 3285 | |
134d01f1 DJ |
3286 | if (die->type) |
3287 | return; | |
3288 | ||
c906108c SS |
3289 | type = alloc_type (objfile); |
3290 | ||
3291 | INIT_CPLUS_SPECIFIC (type); | |
e142c38c | 3292 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3293 | if (attr && DW_STRING (attr)) |
3294 | { | |
e142c38c | 3295 | if (cu->language == language_cplus) |
63d06c5c | 3296 | { |
8176b9b8 DC |
3297 | char *new_prefix = determine_class_name (die, cu); |
3298 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
3299 | strlen (new_prefix), | |
3300 | &objfile->objfile_obstack); | |
3301 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
3302 | processing_current_prefix = new_prefix; |
3303 | } | |
3304 | else | |
3305 | { | |
d8151005 DJ |
3306 | /* The name is already allocated along with this objfile, so |
3307 | we don't need to duplicate it for the type. */ | |
8176b9b8 | 3308 | TYPE_TAG_NAME (type) = DW_STRING (attr); |
63d06c5c | 3309 | } |
c906108c SS |
3310 | } |
3311 | ||
3312 | if (die->tag == DW_TAG_structure_type) | |
3313 | { | |
3314 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
3315 | } | |
3316 | else if (die->tag == DW_TAG_union_type) | |
3317 | { | |
3318 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
3319 | } | |
3320 | else | |
3321 | { | |
3322 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 3323 | in gdbtypes.h. */ |
c906108c SS |
3324 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
3325 | } | |
3326 | ||
e142c38c | 3327 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3328 | if (attr) |
3329 | { | |
3330 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3331 | } | |
3332 | else | |
3333 | { | |
3334 | TYPE_LENGTH (type) = 0; | |
3335 | } | |
3336 | ||
dc718098 JB |
3337 | if (die_is_declaration (die, cu)) |
3338 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
3339 | ||
c906108c SS |
3340 | /* We need to add the type field to the die immediately so we don't |
3341 | infinitely recurse when dealing with pointers to the structure | |
3342 | type within the structure itself. */ | |
3343 | die->type = type; | |
3344 | ||
e142c38c | 3345 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
3346 | { |
3347 | struct field_info fi; | |
3348 | struct die_info *child_die; | |
3349 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
3350 | ||
3351 | memset (&fi, 0, sizeof (struct field_info)); | |
3352 | ||
639d11d3 | 3353 | child_die = die->child; |
c906108c SS |
3354 | |
3355 | while (child_die && child_die->tag) | |
3356 | { | |
a9a9bd0f DC |
3357 | if (child_die->tag == DW_TAG_member |
3358 | || child_die->tag == DW_TAG_variable) | |
c906108c | 3359 | { |
a9a9bd0f DC |
3360 | /* NOTE: carlton/2002-11-05: A C++ static data member |
3361 | should be a DW_TAG_member that is a declaration, but | |
3362 | all versions of G++ as of this writing (so through at | |
3363 | least 3.2.1) incorrectly generate DW_TAG_variable | |
3364 | tags for them instead. */ | |
e7c27a73 | 3365 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3366 | } |
8713b1b1 | 3367 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
3368 | { |
3369 | /* C++ member function. */ | |
134d01f1 | 3370 | read_type_die (child_die, cu); |
e7c27a73 | 3371 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
3372 | } |
3373 | else if (child_die->tag == DW_TAG_inheritance) | |
3374 | { | |
3375 | /* C++ base class field. */ | |
e7c27a73 | 3376 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3377 | } |
c906108c SS |
3378 | child_die = sibling_die (child_die); |
3379 | } | |
3380 | ||
3381 | /* Attach fields and member functions to the type. */ | |
3382 | if (fi.nfields) | |
e7c27a73 | 3383 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
3384 | if (fi.nfnfields) |
3385 | { | |
e7c27a73 | 3386 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 3387 | |
c5aa993b | 3388 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
3389 | class itself) which contains the vtable pointer for the current |
3390 | class from the DW_AT_containing_type attribute. */ | |
3391 | ||
e142c38c | 3392 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 3393 | { |
e7c27a73 | 3394 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
3395 | |
3396 | TYPE_VPTR_BASETYPE (type) = t; | |
3397 | if (type == t) | |
3398 | { | |
c5aa993b JM |
3399 | static const char vptr_name[] = |
3400 | {'_', 'v', 'p', 't', 'r', '\0'}; | |
c906108c SS |
3401 | int i; |
3402 | ||
3403 | /* Our own class provides vtbl ptr. */ | |
3404 | for (i = TYPE_NFIELDS (t) - 1; | |
3405 | i >= TYPE_N_BASECLASSES (t); | |
3406 | --i) | |
3407 | { | |
3408 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
3409 | ||
27bfe10e JB |
3410 | if ((strncmp (fieldname, vptr_name, |
3411 | strlen (vptr_name) - 1) | |
3412 | == 0) | |
c906108c SS |
3413 | && is_cplus_marker (fieldname[strlen (vptr_name)])) |
3414 | { | |
3415 | TYPE_VPTR_FIELDNO (type) = i; | |
3416 | break; | |
3417 | } | |
3418 | } | |
3419 | ||
3420 | /* Complain if virtual function table field not found. */ | |
3421 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 KB |
3422 | complaint (&symfile_complaints, |
3423 | "virtual function table pointer not found when defining class '%s'", | |
3424 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : | |
3425 | ""); | |
c906108c SS |
3426 | } |
3427 | else | |
3428 | { | |
3429 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
3430 | } | |
3431 | } | |
3432 | } | |
3433 | ||
c906108c SS |
3434 | do_cleanups (back_to); |
3435 | } | |
63d06c5c DC |
3436 | |
3437 | processing_current_prefix = previous_prefix; | |
3438 | if (back_to != NULL) | |
3439 | do_cleanups (back_to); | |
c906108c SS |
3440 | } |
3441 | ||
134d01f1 DJ |
3442 | static void |
3443 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3444 | { | |
3445 | struct objfile *objfile = cu->objfile; | |
3446 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 3447 | struct die_info *child_die = die->child; |
c906108c | 3448 | |
134d01f1 DJ |
3449 | if (TYPE_TAG_NAME (die->type) != NULL) |
3450 | processing_current_prefix = TYPE_TAG_NAME (die->type); | |
c906108c | 3451 | |
90aeadfc DC |
3452 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
3453 | snapshots) has been known to create a die giving a declaration | |
3454 | for a class that has, as a child, a die giving a definition for a | |
3455 | nested class. So we have to process our children even if the | |
3456 | current die is a declaration. Normally, of course, a declaration | |
3457 | won't have any children at all. */ | |
134d01f1 | 3458 | |
90aeadfc DC |
3459 | while (child_die != NULL && child_die->tag) |
3460 | { | |
3461 | if (child_die->tag == DW_TAG_member | |
3462 | || child_die->tag == DW_TAG_variable | |
3463 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 3464 | { |
90aeadfc | 3465 | /* Do nothing. */ |
134d01f1 | 3466 | } |
90aeadfc DC |
3467 | else |
3468 | process_die (child_die, cu); | |
134d01f1 | 3469 | |
90aeadfc | 3470 | child_die = sibling_die (child_die); |
134d01f1 DJ |
3471 | } |
3472 | ||
90aeadfc DC |
3473 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
3474 | new_symbol (die, die->type, cu); | |
3475 | ||
134d01f1 DJ |
3476 | processing_current_prefix = previous_prefix; |
3477 | } | |
3478 | ||
3479 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
3480 | complete the type's fields yet, or create any symbols. */ | |
c906108c SS |
3481 | |
3482 | static void | |
134d01f1 | 3483 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3484 | { |
e7c27a73 | 3485 | struct objfile *objfile = cu->objfile; |
c906108c | 3486 | struct type *type; |
c906108c | 3487 | struct attribute *attr; |
134d01f1 DJ |
3488 | |
3489 | if (die->type) | |
3490 | return; | |
c906108c SS |
3491 | |
3492 | type = alloc_type (objfile); | |
3493 | ||
3494 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
e142c38c | 3495 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3496 | if (attr && DW_STRING (attr)) |
3497 | { | |
d8151005 | 3498 | char *name = DW_STRING (attr); |
63d06c5c DC |
3499 | |
3500 | if (processing_has_namespace_info) | |
3501 | { | |
b99607ea | 3502 | TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
3503 | processing_current_prefix, |
3504 | processing_current_prefix[0] == '\0' | |
3505 | ? "" : "::", | |
3506 | name); | |
3507 | } | |
3508 | else | |
3509 | { | |
d8151005 DJ |
3510 | /* The name is already allocated along with this objfile, so |
3511 | we don't need to duplicate it for the type. */ | |
3512 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 3513 | } |
c906108c SS |
3514 | } |
3515 | ||
e142c38c | 3516 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3517 | if (attr) |
3518 | { | |
3519 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3520 | } | |
3521 | else | |
3522 | { | |
3523 | TYPE_LENGTH (type) = 0; | |
3524 | } | |
3525 | ||
134d01f1 DJ |
3526 | die->type = type; |
3527 | } | |
3528 | ||
8176b9b8 DC |
3529 | /* Determine the name of the type represented by DIE, which should be |
3530 | a named C++ compound type. Return the name in question; the caller | |
3531 | is responsible for xfree()'ing it. */ | |
3532 | ||
3533 | static char * | |
3534 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
3535 | { | |
3536 | struct cleanup *back_to = NULL; | |
3537 | struct die_info *spec_die = die_specification (die, cu); | |
3538 | char *new_prefix = NULL; | |
3539 | ||
3540 | /* If this is the definition of a class that is declared by another | |
3541 | die, then processing_current_prefix may not be accurate; see | |
3542 | read_func_scope for a similar example. */ | |
3543 | if (spec_die != NULL) | |
3544 | { | |
3545 | char *specification_prefix = determine_prefix (spec_die, cu); | |
3546 | processing_current_prefix = specification_prefix; | |
3547 | back_to = make_cleanup (xfree, specification_prefix); | |
3548 | } | |
3549 | ||
3550 | /* If we don't have namespace debug info, guess the name by trying | |
3551 | to demangle the names of members, just like we did in | |
72bf9492 | 3552 | guess_structure_name. */ |
8176b9b8 DC |
3553 | if (!processing_has_namespace_info) |
3554 | { | |
3555 | struct die_info *child; | |
3556 | ||
3557 | for (child = die->child; | |
3558 | child != NULL && child->tag != 0; | |
3559 | child = sibling_die (child)) | |
3560 | { | |
3561 | if (child->tag == DW_TAG_subprogram) | |
3562 | { | |
3563 | new_prefix = class_name_from_physname (dwarf2_linkage_name | |
3564 | (child, cu)); | |
3565 | ||
3566 | if (new_prefix != NULL) | |
3567 | break; | |
3568 | } | |
3569 | } | |
3570 | } | |
3571 | ||
3572 | if (new_prefix == NULL) | |
3573 | { | |
3574 | const char *name = dwarf2_name (die, cu); | |
3575 | new_prefix = typename_concat (processing_current_prefix, | |
3576 | name ? name : "<<anonymous>>"); | |
3577 | } | |
3578 | ||
3579 | if (back_to != NULL) | |
3580 | do_cleanups (back_to); | |
3581 | ||
3582 | return new_prefix; | |
3583 | } | |
3584 | ||
134d01f1 DJ |
3585 | /* Given a pointer to a die which begins an enumeration, process all |
3586 | the dies that define the members of the enumeration, and create the | |
3587 | symbol for the enumeration type. | |
3588 | ||
3589 | NOTE: We reverse the order of the element list. */ | |
3590 | ||
3591 | static void | |
3592 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3593 | { | |
3594 | struct objfile *objfile = cu->objfile; | |
3595 | struct die_info *child_die; | |
3596 | struct field *fields; | |
3597 | struct attribute *attr; | |
3598 | struct symbol *sym; | |
3599 | int num_fields; | |
3600 | int unsigned_enum = 1; | |
3601 | ||
c906108c SS |
3602 | num_fields = 0; |
3603 | fields = NULL; | |
639d11d3 | 3604 | if (die->child != NULL) |
c906108c | 3605 | { |
639d11d3 | 3606 | child_die = die->child; |
c906108c SS |
3607 | while (child_die && child_die->tag) |
3608 | { | |
3609 | if (child_die->tag != DW_TAG_enumerator) | |
3610 | { | |
e7c27a73 | 3611 | process_die (child_die, cu); |
c906108c SS |
3612 | } |
3613 | else | |
3614 | { | |
e142c38c | 3615 | attr = dwarf2_attr (child_die, DW_AT_name, cu); |
c906108c SS |
3616 | if (attr) |
3617 | { | |
134d01f1 | 3618 | sym = new_symbol (child_die, die->type, cu); |
c906108c SS |
3619 | if (SYMBOL_VALUE (sym) < 0) |
3620 | unsigned_enum = 0; | |
3621 | ||
3622 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3623 | { | |
3624 | fields = (struct field *) | |
3625 | xrealloc (fields, | |
3626 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3627 | * sizeof (struct field)); |
c906108c SS |
3628 | } |
3629 | ||
22abf04a | 3630 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
3631 | FIELD_TYPE (fields[num_fields]) = NULL; |
3632 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
3633 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 3634 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
3635 | |
3636 | num_fields++; | |
3637 | } | |
3638 | } | |
3639 | ||
3640 | child_die = sibling_die (child_die); | |
3641 | } | |
3642 | ||
3643 | if (num_fields) | |
3644 | { | |
134d01f1 DJ |
3645 | TYPE_NFIELDS (die->type) = num_fields; |
3646 | TYPE_FIELDS (die->type) = (struct field *) | |
3647 | TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); | |
3648 | memcpy (TYPE_FIELDS (die->type), fields, | |
c906108c | 3649 | sizeof (struct field) * num_fields); |
b8c9b27d | 3650 | xfree (fields); |
c906108c SS |
3651 | } |
3652 | if (unsigned_enum) | |
134d01f1 | 3653 | TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 3654 | } |
134d01f1 DJ |
3655 | |
3656 | new_symbol (die, die->type, cu); | |
c906108c SS |
3657 | } |
3658 | ||
3659 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
3660 | the DIE's type field. For now, this only handles one dimensional | |
3661 | arrays. */ | |
3662 | ||
3663 | static void | |
e7c27a73 | 3664 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3665 | { |
e7c27a73 | 3666 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3667 | struct die_info *child_die; |
3668 | struct type *type = NULL; | |
3669 | struct type *element_type, *range_type, *index_type; | |
3670 | struct type **range_types = NULL; | |
3671 | struct attribute *attr; | |
3672 | int ndim = 0; | |
3673 | struct cleanup *back_to; | |
3674 | ||
3675 | /* Return if we've already decoded this type. */ | |
3676 | if (die->type) | |
3677 | { | |
3678 | return; | |
3679 | } | |
3680 | ||
e7c27a73 | 3681 | element_type = die_type (die, cu); |
c906108c SS |
3682 | |
3683 | /* Irix 6.2 native cc creates array types without children for | |
3684 | arrays with unspecified length. */ | |
639d11d3 | 3685 | if (die->child == NULL) |
c906108c | 3686 | { |
e142c38c | 3687 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c SS |
3688 | range_type = create_range_type (NULL, index_type, 0, -1); |
3689 | die->type = create_array_type (NULL, element_type, range_type); | |
3690 | return; | |
3691 | } | |
3692 | ||
3693 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 3694 | child_die = die->child; |
c906108c SS |
3695 | while (child_die && child_die->tag) |
3696 | { | |
3697 | if (child_die->tag == DW_TAG_subrange_type) | |
3698 | { | |
a02abb62 | 3699 | read_subrange_type (child_die, cu); |
c906108c | 3700 | |
a02abb62 JB |
3701 | if (child_die->type != NULL) |
3702 | { | |
3703 | /* The range type was succesfully read. Save it for | |
3704 | the array type creation. */ | |
3705 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
3706 | { | |
3707 | range_types = (struct type **) | |
3708 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
3709 | * sizeof (struct type *)); | |
3710 | if (ndim == 0) | |
3711 | make_cleanup (free_current_contents, &range_types); | |
3712 | } | |
3713 | range_types[ndim++] = child_die->type; | |
3714 | } | |
c906108c SS |
3715 | } |
3716 | child_die = sibling_die (child_die); | |
3717 | } | |
3718 | ||
3719 | /* Dwarf2 dimensions are output from left to right, create the | |
3720 | necessary array types in backwards order. */ | |
3721 | type = element_type; | |
3722 | while (ndim-- > 0) | |
3723 | type = create_array_type (NULL, type, range_types[ndim]); | |
3724 | ||
f5f8a009 EZ |
3725 | /* Understand Dwarf2 support for vector types (like they occur on |
3726 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
3727 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
3728 | custom vendor extension. The main difference between a regular | |
3729 | array and the vector variant is that vectors are passed by value | |
3730 | to functions. */ | |
e142c38c | 3731 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 EZ |
3732 | if (attr) |
3733 | TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; | |
3734 | ||
c906108c SS |
3735 | do_cleanups (back_to); |
3736 | ||
3737 | /* Install the type in the die. */ | |
3738 | die->type = type; | |
3739 | } | |
3740 | ||
3741 | /* First cut: install each common block member as a global variable. */ | |
3742 | ||
3743 | static void | |
e7c27a73 | 3744 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3745 | { |
3746 | struct die_info *child_die; | |
3747 | struct attribute *attr; | |
3748 | struct symbol *sym; | |
3749 | CORE_ADDR base = (CORE_ADDR) 0; | |
3750 | ||
e142c38c | 3751 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
3752 | if (attr) |
3753 | { | |
8e19ed76 PS |
3754 | /* Support the .debug_loc offsets */ |
3755 | if (attr_form_is_block (attr)) | |
3756 | { | |
e7c27a73 | 3757 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 PS |
3758 | } |
3759 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3760 | { | |
4d3c2250 | 3761 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3762 | } |
3763 | else | |
3764 | { | |
4d3c2250 KB |
3765 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
3766 | "common block member"); | |
8e19ed76 | 3767 | } |
c906108c | 3768 | } |
639d11d3 | 3769 | if (die->child != NULL) |
c906108c | 3770 | { |
639d11d3 | 3771 | child_die = die->child; |
c906108c SS |
3772 | while (child_die && child_die->tag) |
3773 | { | |
e7c27a73 | 3774 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 3775 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
3776 | if (attr) |
3777 | { | |
3778 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 3779 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
3780 | add_symbol_to_list (sym, &global_symbols); |
3781 | } | |
3782 | child_die = sibling_die (child_die); | |
3783 | } | |
3784 | } | |
3785 | } | |
3786 | ||
d9fa45fe DC |
3787 | /* Read a C++ namespace. */ |
3788 | ||
d9fa45fe | 3789 | static void |
e7c27a73 | 3790 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 3791 | { |
e7c27a73 | 3792 | struct objfile *objfile = cu->objfile; |
38d518c9 | 3793 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 3794 | const char *name; |
9219021c DC |
3795 | int is_anonymous; |
3796 | struct die_info *current_die; | |
3797 | ||
e142c38c | 3798 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
3799 | |
3800 | /* Now build the name of the current namespace. */ | |
3801 | ||
38d518c9 | 3802 | if (previous_prefix[0] == '\0') |
9219021c | 3803 | { |
38d518c9 | 3804 | processing_current_prefix = name; |
9219021c DC |
3805 | } |
3806 | else | |
3807 | { | |
38d518c9 | 3808 | /* We need temp_name around because processing_current_prefix |
9219021c | 3809 | is a const char *. */ |
38d518c9 | 3810 | char *temp_name = alloca (strlen (previous_prefix) |
9219021c | 3811 | + 2 + strlen(name) + 1); |
38d518c9 | 3812 | strcpy (temp_name, previous_prefix); |
9219021c DC |
3813 | strcat (temp_name, "::"); |
3814 | strcat (temp_name, name); | |
3815 | ||
38d518c9 | 3816 | processing_current_prefix = temp_name; |
9219021c DC |
3817 | } |
3818 | ||
5c4e30ca DC |
3819 | /* Add a symbol associated to this if we haven't seen the namespace |
3820 | before. Also, add a using directive if it's an anonymous | |
3821 | namespace. */ | |
9219021c | 3822 | |
e142c38c | 3823 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
3824 | { |
3825 | struct type *type; | |
3826 | ||
3827 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
3828 | this cast will hopefully become unnecessary. */ | |
3829 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 3830 | (char *) processing_current_prefix, |
5c4e30ca DC |
3831 | objfile); |
3832 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
3833 | ||
e7c27a73 | 3834 | new_symbol (die, type, cu); |
8176b9b8 | 3835 | die->type = type; |
5c4e30ca DC |
3836 | |
3837 | if (is_anonymous) | |
38d518c9 EZ |
3838 | cp_add_using_directive (processing_current_prefix, |
3839 | strlen (previous_prefix), | |
3840 | strlen (processing_current_prefix)); | |
5c4e30ca | 3841 | } |
9219021c | 3842 | |
639d11d3 | 3843 | if (die->child != NULL) |
d9fa45fe | 3844 | { |
639d11d3 | 3845 | struct die_info *child_die = die->child; |
d9fa45fe DC |
3846 | |
3847 | while (child_die && child_die->tag) | |
3848 | { | |
e7c27a73 | 3849 | process_die (child_die, cu); |
d9fa45fe DC |
3850 | child_die = sibling_die (child_die); |
3851 | } | |
3852 | } | |
9219021c | 3853 | |
38d518c9 EZ |
3854 | processing_current_prefix = previous_prefix; |
3855 | } | |
3856 | ||
3857 | /* Return the name of the namespace represented by DIE. Set | |
3858 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
3859 | namespace. */ | |
3860 | ||
3861 | static const char * | |
e142c38c | 3862 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
3863 | { |
3864 | struct die_info *current_die; | |
3865 | const char *name = NULL; | |
3866 | ||
3867 | /* Loop through the extensions until we find a name. */ | |
3868 | ||
3869 | for (current_die = die; | |
3870 | current_die != NULL; | |
e142c38c | 3871 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 3872 | { |
e142c38c | 3873 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
3874 | if (name != NULL) |
3875 | break; | |
3876 | } | |
3877 | ||
3878 | /* Is it an anonymous namespace? */ | |
3879 | ||
3880 | *is_anonymous = (name == NULL); | |
3881 | if (*is_anonymous) | |
3882 | name = "(anonymous namespace)"; | |
3883 | ||
3884 | return name; | |
d9fa45fe DC |
3885 | } |
3886 | ||
c906108c SS |
3887 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
3888 | the user defined type vector. */ | |
3889 | ||
3890 | static void | |
e7c27a73 | 3891 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3892 | { |
e7c27a73 | 3893 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 3894 | struct type *type; |
8b2dbe47 KB |
3895 | struct attribute *attr_byte_size; |
3896 | struct attribute *attr_address_class; | |
3897 | int byte_size, addr_class; | |
c906108c SS |
3898 | |
3899 | if (die->type) | |
3900 | { | |
3901 | return; | |
3902 | } | |
3903 | ||
e7c27a73 | 3904 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 3905 | |
e142c38c | 3906 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
3907 | if (attr_byte_size) |
3908 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 3909 | else |
8b2dbe47 KB |
3910 | byte_size = cu_header->addr_size; |
3911 | ||
e142c38c | 3912 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
3913 | if (attr_address_class) |
3914 | addr_class = DW_UNSND (attr_address_class); | |
3915 | else | |
3916 | addr_class = DW_ADDR_none; | |
3917 | ||
3918 | /* If the pointer size or address class is different than the | |
3919 | default, create a type variant marked as such and set the | |
3920 | length accordingly. */ | |
3921 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 3922 | { |
8b2dbe47 KB |
3923 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()) |
3924 | { | |
3925 | int type_flags; | |
3926 | ||
3927 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); | |
3928 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); | |
3929 | type = make_type_with_address_space (type, type_flags); | |
3930 | } | |
3931 | else if (TYPE_LENGTH (type) != byte_size) | |
3932 | { | |
4d3c2250 | 3933 | complaint (&symfile_complaints, "invalid pointer size %d", byte_size); |
8b2dbe47 KB |
3934 | } |
3935 | else { | |
3936 | /* Should we also complain about unhandled address classes? */ | |
3937 | } | |
c906108c | 3938 | } |
8b2dbe47 KB |
3939 | |
3940 | TYPE_LENGTH (type) = byte_size; | |
c906108c SS |
3941 | die->type = type; |
3942 | } | |
3943 | ||
3944 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
3945 | the user defined type vector. */ | |
3946 | ||
3947 | static void | |
e7c27a73 | 3948 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3949 | { |
e7c27a73 | 3950 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3951 | struct type *type; |
3952 | struct type *to_type; | |
3953 | struct type *domain; | |
3954 | ||
3955 | if (die->type) | |
3956 | { | |
3957 | return; | |
3958 | } | |
3959 | ||
3960 | type = alloc_type (objfile); | |
e7c27a73 DJ |
3961 | to_type = die_type (die, cu); |
3962 | domain = die_containing_type (die, cu); | |
c906108c SS |
3963 | smash_to_member_type (type, domain, to_type); |
3964 | ||
3965 | die->type = type; | |
3966 | } | |
3967 | ||
3968 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
3969 | the user defined type vector. */ | |
3970 | ||
3971 | static void | |
e7c27a73 | 3972 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3973 | { |
e7c27a73 | 3974 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
3975 | struct type *type; |
3976 | struct attribute *attr; | |
3977 | ||
3978 | if (die->type) | |
3979 | { | |
3980 | return; | |
3981 | } | |
3982 | ||
e7c27a73 | 3983 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 3984 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3985 | if (attr) |
3986 | { | |
3987 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3988 | } | |
3989 | else | |
3990 | { | |
107d2387 | 3991 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c SS |
3992 | } |
3993 | die->type = type; | |
3994 | } | |
3995 | ||
3996 | static void | |
e7c27a73 | 3997 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3998 | { |
090c42a4 JB |
3999 | struct type *base_type; |
4000 | ||
c906108c SS |
4001 | if (die->type) |
4002 | { | |
4003 | return; | |
4004 | } | |
4005 | ||
e7c27a73 | 4006 | base_type = die_type (die, cu); |
090c42a4 | 4007 | die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
c906108c SS |
4008 | } |
4009 | ||
4010 | static void | |
e7c27a73 | 4011 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4012 | { |
090c42a4 JB |
4013 | struct type *base_type; |
4014 | ||
c906108c SS |
4015 | if (die->type) |
4016 | { | |
4017 | return; | |
4018 | } | |
4019 | ||
e7c27a73 | 4020 | base_type = die_type (die, cu); |
090c42a4 | 4021 | die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
c906108c SS |
4022 | } |
4023 | ||
4024 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4025 | the user defined type vector. It isn't really a user defined type, | |
4026 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4027 | attribute to reference it. */ | |
4028 | ||
4029 | static void | |
e7c27a73 | 4030 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4031 | { |
e7c27a73 | 4032 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4033 | struct type *type, *range_type, *index_type, *char_type; |
4034 | struct attribute *attr; | |
4035 | unsigned int length; | |
4036 | ||
4037 | if (die->type) | |
4038 | { | |
4039 | return; | |
4040 | } | |
4041 | ||
e142c38c | 4042 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4043 | if (attr) |
4044 | { | |
4045 | length = DW_UNSND (attr); | |
4046 | } | |
4047 | else | |
4048 | { | |
b21b22e0 | 4049 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4050 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4051 | if (attr) |
4052 | { | |
4053 | length = DW_UNSND (attr); | |
4054 | } | |
4055 | else | |
4056 | { | |
4057 | length = 1; | |
4058 | } | |
c906108c | 4059 | } |
e142c38c | 4060 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c | 4061 | range_type = create_range_type (NULL, index_type, 1, length); |
e142c38c | 4062 | if (cu->language == language_fortran) |
b21b22e0 PS |
4063 | { |
4064 | /* Need to create a unique string type for bounds | |
4065 | information */ | |
4066 | type = create_string_type (0, range_type); | |
4067 | } | |
4068 | else | |
4069 | { | |
e142c38c | 4070 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); |
b21b22e0 PS |
4071 | type = create_string_type (char_type, range_type); |
4072 | } | |
c906108c SS |
4073 | die->type = type; |
4074 | } | |
4075 | ||
4076 | /* Handle DIES due to C code like: | |
4077 | ||
4078 | struct foo | |
c5aa993b JM |
4079 | { |
4080 | int (*funcp)(int a, long l); | |
4081 | int b; | |
4082 | }; | |
c906108c SS |
4083 | |
4084 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4085 | */ |
c906108c SS |
4086 | |
4087 | static void | |
e7c27a73 | 4088 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4089 | { |
4090 | struct type *type; /* Type that this function returns */ | |
4091 | struct type *ftype; /* Function that returns above type */ | |
4092 | struct attribute *attr; | |
4093 | ||
4094 | /* Decode the type that this subroutine returns */ | |
4095 | if (die->type) | |
4096 | { | |
4097 | return; | |
4098 | } | |
e7c27a73 | 4099 | type = die_type (die, cu); |
c906108c SS |
4100 | ftype = lookup_function_type (type); |
4101 | ||
4102 | /* All functions in C++ have prototypes. */ | |
e142c38c | 4103 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4104 | if ((attr && (DW_UNSND (attr) != 0)) |
e142c38c | 4105 | || cu->language == language_cplus) |
c906108c SS |
4106 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4107 | ||
639d11d3 | 4108 | if (die->child != NULL) |
c906108c SS |
4109 | { |
4110 | struct die_info *child_die; | |
4111 | int nparams = 0; | |
4112 | int iparams = 0; | |
4113 | ||
4114 | /* Count the number of parameters. | |
4115 | FIXME: GDB currently ignores vararg functions, but knows about | |
4116 | vararg member functions. */ | |
639d11d3 | 4117 | child_die = die->child; |
c906108c SS |
4118 | while (child_die && child_die->tag) |
4119 | { | |
4120 | if (child_die->tag == DW_TAG_formal_parameter) | |
4121 | nparams++; | |
4122 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4123 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4124 | child_die = sibling_die (child_die); | |
4125 | } | |
4126 | ||
4127 | /* Allocate storage for parameters and fill them in. */ | |
4128 | TYPE_NFIELDS (ftype) = nparams; | |
4129 | TYPE_FIELDS (ftype) = (struct field *) | |
4130 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
4131 | ||
639d11d3 | 4132 | child_die = die->child; |
c906108c SS |
4133 | while (child_die && child_die->tag) |
4134 | { | |
4135 | if (child_die->tag == DW_TAG_formal_parameter) | |
4136 | { | |
4137 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4138 | member functions. G++ helps GDB by marking the first |
4139 | parameter for non-static member functions (which is the | |
4140 | this pointer) as artificial. We pass this information | |
4141 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4142 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4143 | if (attr) |
4144 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4145 | else | |
4146 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4147 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4148 | iparams++; |
4149 | } | |
4150 | child_die = sibling_die (child_die); | |
4151 | } | |
4152 | } | |
4153 | ||
4154 | die->type = ftype; | |
4155 | } | |
4156 | ||
4157 | static void | |
e7c27a73 | 4158 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4159 | { |
e7c27a73 | 4160 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4161 | struct attribute *attr; |
4162 | char *name = NULL; | |
c906108c SS |
4163 | |
4164 | if (!die->type) | |
4165 | { | |
e142c38c | 4166 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c | 4167 | if (attr && DW_STRING (attr)) |
2f038fcb FF |
4168 | { |
4169 | name = DW_STRING (attr); | |
4170 | } | |
4171 | die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); | |
e7c27a73 | 4172 | TYPE_TARGET_TYPE (die->type) = die_type (die, cu); |
c906108c SS |
4173 | } |
4174 | } | |
4175 | ||
4176 | /* Find a representation of a given base type and install | |
4177 | it in the TYPE field of the die. */ | |
4178 | ||
4179 | static void | |
e7c27a73 | 4180 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4181 | { |
e7c27a73 | 4182 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4183 | struct type *type; |
4184 | struct attribute *attr; | |
4185 | int encoding = 0, size = 0; | |
4186 | ||
4187 | /* If we've already decoded this die, this is a no-op. */ | |
4188 | if (die->type) | |
4189 | { | |
4190 | return; | |
4191 | } | |
4192 | ||
e142c38c | 4193 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4194 | if (attr) |
4195 | { | |
4196 | encoding = DW_UNSND (attr); | |
4197 | } | |
e142c38c | 4198 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4199 | if (attr) |
4200 | { | |
4201 | size = DW_UNSND (attr); | |
4202 | } | |
e142c38c | 4203 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
4204 | if (attr && DW_STRING (attr)) |
4205 | { | |
4206 | enum type_code code = TYPE_CODE_INT; | |
f5ef7c67 | 4207 | int type_flags = 0; |
c906108c SS |
4208 | |
4209 | switch (encoding) | |
4210 | { | |
4211 | case DW_ATE_address: | |
4212 | /* Turn DW_ATE_address into a void * pointer. */ | |
4213 | code = TYPE_CODE_PTR; | |
f5ef7c67 | 4214 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4215 | break; |
4216 | case DW_ATE_boolean: | |
4217 | code = TYPE_CODE_BOOL; | |
f5ef7c67 | 4218 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4219 | break; |
4220 | case DW_ATE_complex_float: | |
4221 | code = TYPE_CODE_COMPLEX; | |
4222 | break; | |
4223 | case DW_ATE_float: | |
4224 | code = TYPE_CODE_FLT; | |
4225 | break; | |
4226 | case DW_ATE_signed: | |
4227 | case DW_ATE_signed_char: | |
4228 | break; | |
4229 | case DW_ATE_unsigned: | |
4230 | case DW_ATE_unsigned_char: | |
f5ef7c67 | 4231 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4232 | break; |
4233 | default: | |
4d3c2250 KB |
4234 | complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", |
4235 | dwarf_type_encoding_name (encoding)); | |
c906108c SS |
4236 | break; |
4237 | } | |
f5ef7c67 | 4238 | type = init_type (code, size, type_flags, DW_STRING (attr), objfile); |
c906108c | 4239 | if (encoding == DW_ATE_address) |
e142c38c DJ |
4240 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, |
4241 | cu); | |
f65ca430 DJ |
4242 | else if (encoding == DW_ATE_complex_float) |
4243 | { | |
4244 | if (size == 32) | |
4245 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4246 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); |
f65ca430 DJ |
4247 | else if (size == 16) |
4248 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4249 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
f65ca430 DJ |
4250 | else if (size == 8) |
4251 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4252 | = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
f65ca430 | 4253 | } |
c906108c SS |
4254 | } |
4255 | else | |
4256 | { | |
e7c27a73 | 4257 | type = dwarf_base_type (encoding, size, cu); |
c906108c SS |
4258 | } |
4259 | die->type = type; | |
4260 | } | |
4261 | ||
a02abb62 JB |
4262 | /* Read the given DW_AT_subrange DIE. */ |
4263 | ||
4264 | static void | |
4265 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) | |
4266 | { | |
4267 | struct type *base_type; | |
4268 | struct type *range_type; | |
4269 | struct attribute *attr; | |
4270 | int low = 0; | |
4271 | int high = -1; | |
4272 | ||
4273 | /* If we have already decoded this die, then nothing more to do. */ | |
4274 | if (die->type) | |
4275 | return; | |
4276 | ||
4277 | base_type = die_type (die, cu); | |
4278 | if (base_type == NULL) | |
4279 | { | |
4280 | complaint (&symfile_complaints, | |
4281 | "DW_AT_type missing from DW_TAG_subrange_type"); | |
4282 | return; | |
4283 | } | |
4284 | ||
4285 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
4286 | base_type = alloc_type (NULL); | |
4287 | ||
e142c38c | 4288 | if (cu->language == language_fortran) |
a02abb62 JB |
4289 | { |
4290 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
4291 | low = 1; | |
4292 | } | |
4293 | ||
e142c38c | 4294 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
4295 | if (attr) |
4296 | low = dwarf2_get_attr_constant_value (attr, 0); | |
4297 | ||
e142c38c | 4298 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
4299 | if (attr) |
4300 | { | |
4301 | if (attr->form == DW_FORM_block1) | |
4302 | { | |
4303 | /* GCC encodes arrays with unspecified or dynamic length | |
4304 | with a DW_FORM_block1 attribute. | |
4305 | FIXME: GDB does not yet know how to handle dynamic | |
4306 | arrays properly, treat them as arrays with unspecified | |
4307 | length for now. | |
4308 | ||
4309 | FIXME: jimb/2003-09-22: GDB does not really know | |
4310 | how to handle arrays of unspecified length | |
4311 | either; we just represent them as zero-length | |
4312 | arrays. Choose an appropriate upper bound given | |
4313 | the lower bound we've computed above. */ | |
4314 | high = low - 1; | |
4315 | } | |
4316 | else | |
4317 | high = dwarf2_get_attr_constant_value (attr, 1); | |
4318 | } | |
4319 | ||
4320 | range_type = create_range_type (NULL, base_type, low, high); | |
4321 | ||
e142c38c | 4322 | attr = dwarf2_attr (die, DW_AT_name, cu); |
a02abb62 JB |
4323 | if (attr && DW_STRING (attr)) |
4324 | TYPE_NAME (range_type) = DW_STRING (attr); | |
4325 | ||
e142c38c | 4326 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
4327 | if (attr) |
4328 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
4329 | ||
4330 | die->type = range_type; | |
4331 | } | |
4332 | ||
4333 | ||
c906108c SS |
4334 | /* Read a whole compilation unit into a linked list of dies. */ |
4335 | ||
f9aca02d | 4336 | static struct die_info * |
e7c27a73 | 4337 | read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4338 | { |
b3810801 | 4339 | /* Reset die reference table; we are |
7f0e3f52 AC |
4340 | building new ones now. */ |
4341 | dwarf2_empty_hash_tables (); | |
c906108c | 4342 | |
e7c27a73 | 4343 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
4344 | } |
4345 | ||
4346 | /* Read a single die and all its descendents. Set the die's sibling | |
4347 | field to NULL; set other fields in the die correctly, and set all | |
4348 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
4349 | location of the info_ptr after reading all of those dies. PARENT | |
4350 | is the parent of the die in question. */ | |
4351 | ||
4352 | static struct die_info * | |
4353 | read_die_and_children (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4354 | struct dwarf2_cu *cu, |
639d11d3 DC |
4355 | char **new_info_ptr, |
4356 | struct die_info *parent) | |
4357 | { | |
4358 | struct die_info *die; | |
4359 | char *cur_ptr; | |
4360 | int has_children; | |
4361 | ||
e7c27a73 | 4362 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
639d11d3 DC |
4363 | store_in_ref_table (die->offset, die); |
4364 | ||
4365 | if (has_children) | |
4366 | { | |
e7c27a73 | 4367 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
4368 | new_info_ptr, die); |
4369 | } | |
4370 | else | |
4371 | { | |
4372 | die->child = NULL; | |
4373 | *new_info_ptr = cur_ptr; | |
4374 | } | |
4375 | ||
4376 | die->sibling = NULL; | |
4377 | die->parent = parent; | |
4378 | return die; | |
4379 | } | |
4380 | ||
4381 | /* Read a die, all of its descendents, and all of its siblings; set | |
4382 | all of the fields of all of the dies correctly. Arguments are as | |
4383 | in read_die_and_children. */ | |
4384 | ||
4385 | static struct die_info * | |
4386 | read_die_and_siblings (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4387 | struct dwarf2_cu *cu, |
639d11d3 DC |
4388 | char **new_info_ptr, |
4389 | struct die_info *parent) | |
4390 | { | |
4391 | struct die_info *first_die, *last_sibling; | |
4392 | char *cur_ptr; | |
4393 | ||
c906108c | 4394 | cur_ptr = info_ptr; |
639d11d3 DC |
4395 | first_die = last_sibling = NULL; |
4396 | ||
4397 | while (1) | |
c906108c | 4398 | { |
639d11d3 | 4399 | struct die_info *die |
e7c27a73 | 4400 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
4401 | |
4402 | if (!first_die) | |
c906108c | 4403 | { |
639d11d3 | 4404 | first_die = die; |
c906108c | 4405 | } |
639d11d3 | 4406 | else |
c906108c | 4407 | { |
639d11d3 | 4408 | last_sibling->sibling = die; |
c906108c SS |
4409 | } |
4410 | ||
639d11d3 | 4411 | if (die->tag == 0) |
c906108c | 4412 | { |
639d11d3 DC |
4413 | *new_info_ptr = cur_ptr; |
4414 | return first_die; | |
c906108c SS |
4415 | } |
4416 | else | |
4417 | { | |
639d11d3 | 4418 | last_sibling = die; |
c906108c SS |
4419 | } |
4420 | } | |
c906108c SS |
4421 | } |
4422 | ||
4423 | /* Free a linked list of dies. */ | |
4424 | ||
4425 | static void | |
fba45db2 | 4426 | free_die_list (struct die_info *dies) |
c906108c SS |
4427 | { |
4428 | struct die_info *die, *next; | |
4429 | ||
4430 | die = dies; | |
4431 | while (die) | |
4432 | { | |
639d11d3 DC |
4433 | if (die->child != NULL) |
4434 | free_die_list (die->child); | |
4435 | next = die->sibling; | |
b8c9b27d KB |
4436 | xfree (die->attrs); |
4437 | xfree (die); | |
c906108c SS |
4438 | die = next; |
4439 | } | |
4440 | } | |
4441 | ||
74b7792f AC |
4442 | static void |
4443 | do_free_die_list_cleanup (void *dies) | |
4444 | { | |
4445 | free_die_list (dies); | |
4446 | } | |
4447 | ||
4448 | static struct cleanup * | |
4449 | make_cleanup_free_die_list (struct die_info *dies) | |
4450 | { | |
4451 | return make_cleanup (do_free_die_list_cleanup, dies); | |
4452 | } | |
4453 | ||
4454 | ||
c906108c | 4455 | /* Read the contents of the section at OFFSET and of size SIZE from the |
8b92e4d5 | 4456 | object file specified by OBJFILE into the objfile_obstack and return it. */ |
c906108c | 4457 | |
b6af0555 | 4458 | char * |
188dd5d6 | 4459 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
4460 | { |
4461 | bfd *abfd = objfile->obfd; | |
086df311 | 4462 | char *buf, *retbuf; |
188dd5d6 | 4463 | bfd_size_type size = bfd_get_section_size_before_reloc (sectp); |
c906108c SS |
4464 | |
4465 | if (size == 0) | |
4466 | return NULL; | |
4467 | ||
8b92e4d5 | 4468 | buf = (char *) obstack_alloc (&objfile->objfile_obstack, size); |
086df311 DJ |
4469 | retbuf |
4470 | = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); | |
4471 | if (retbuf != NULL) | |
4472 | return retbuf; | |
4473 | ||
188dd5d6 DJ |
4474 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
4475 | || bfd_bread (buf, size, abfd) != size) | |
4476 | error ("Dwarf Error: Can't read DWARF data from '%s'", | |
4477 | bfd_get_filename (abfd)); | |
4478 | ||
c906108c SS |
4479 | return buf; |
4480 | } | |
4481 | ||
4482 | /* In DWARF version 2, the description of the debugging information is | |
4483 | stored in a separate .debug_abbrev section. Before we read any | |
4484 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
4485 | in a hash table. This function also sets flags in CU describing |
4486 | the data found in the abbrev table. */ | |
c906108c SS |
4487 | |
4488 | static void | |
e7c27a73 | 4489 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4490 | { |
e7c27a73 | 4491 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4492 | char *abbrev_ptr; |
4493 | struct abbrev_info *cur_abbrev; | |
4494 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
4495 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
4496 | struct attr_abbrev *cur_attrs; |
4497 | unsigned int allocated_attrs; | |
c906108c | 4498 | |
57349743 | 4499 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
4500 | obstack_init (&cu->abbrev_obstack); |
4501 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
4502 | (ABBREV_HASH_SIZE | |
4503 | * sizeof (struct abbrev_info *))); | |
4504 | memset (cu->dwarf2_abbrevs, 0, | |
4505 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 4506 | |
6502dd73 | 4507 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
4508 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4509 | abbrev_ptr += bytes_read; | |
4510 | ||
f3dd6933 DJ |
4511 | allocated_attrs = ATTR_ALLOC_CHUNK; |
4512 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
4513 | ||
c906108c SS |
4514 | /* loop until we reach an abbrev number of 0 */ |
4515 | while (abbrev_number) | |
4516 | { | |
f3dd6933 | 4517 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
4518 | |
4519 | /* read in abbrev header */ | |
4520 | cur_abbrev->number = abbrev_number; | |
4521 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4522 | abbrev_ptr += bytes_read; | |
4523 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
4524 | abbrev_ptr += 1; | |
4525 | ||
72bf9492 DJ |
4526 | if (cur_abbrev->tag == DW_TAG_namespace) |
4527 | cu->has_namespace_info = 1; | |
4528 | ||
c906108c SS |
4529 | /* now read in declarations */ |
4530 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4531 | abbrev_ptr += bytes_read; | |
4532 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4533 | abbrev_ptr += bytes_read; | |
4534 | while (abbrev_name) | |
4535 | { | |
f3dd6933 | 4536 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 4537 | { |
f3dd6933 DJ |
4538 | allocated_attrs += ATTR_ALLOC_CHUNK; |
4539 | cur_attrs | |
4540 | = xrealloc (cur_attrs, (allocated_attrs | |
4541 | * sizeof (struct attr_abbrev))); | |
c906108c | 4542 | } |
f3dd6933 DJ |
4543 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
4544 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
4545 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4546 | abbrev_ptr += bytes_read; | |
4547 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4548 | abbrev_ptr += bytes_read; | |
4549 | } | |
4550 | ||
f3dd6933 DJ |
4551 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
4552 | (cur_abbrev->num_attrs | |
4553 | * sizeof (struct attr_abbrev))); | |
4554 | memcpy (cur_abbrev->attrs, cur_attrs, | |
4555 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
4556 | ||
c906108c | 4557 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
4558 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
4559 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
4560 | |
4561 | /* Get next abbreviation. | |
4562 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
4563 | always properly terminated with an abbrev number of 0. |
4564 | Exit loop if we encounter an abbreviation which we have | |
4565 | already read (which means we are about to read the abbreviations | |
4566 | for the next compile unit) or if the end of the abbreviation | |
4567 | table is reached. */ | |
6502dd73 DJ |
4568 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
4569 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
4570 | break; |
4571 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4572 | abbrev_ptr += bytes_read; | |
e7c27a73 | 4573 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
4574 | break; |
4575 | } | |
f3dd6933 DJ |
4576 | |
4577 | xfree (cur_attrs); | |
c906108c SS |
4578 | } |
4579 | ||
f3dd6933 | 4580 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 4581 | |
c906108c | 4582 | static void |
f3dd6933 | 4583 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 4584 | { |
f3dd6933 | 4585 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 4586 | |
f3dd6933 DJ |
4587 | obstack_free (&cu->abbrev_obstack, NULL); |
4588 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
4589 | } |
4590 | ||
4591 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
4592 | ||
4593 | static struct abbrev_info * | |
e7c27a73 | 4594 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
4595 | { |
4596 | unsigned int hash_number; | |
4597 | struct abbrev_info *abbrev; | |
4598 | ||
4599 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 4600 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
4601 | |
4602 | while (abbrev) | |
4603 | { | |
4604 | if (abbrev->number == number) | |
4605 | return abbrev; | |
4606 | else | |
4607 | abbrev = abbrev->next; | |
4608 | } | |
4609 | return NULL; | |
4610 | } | |
4611 | ||
72bf9492 DJ |
4612 | /* Returns nonzero if TAG represents a type that we might generate a partial |
4613 | symbol for. */ | |
4614 | ||
4615 | static int | |
4616 | is_type_tag_for_partial (int tag) | |
4617 | { | |
4618 | switch (tag) | |
4619 | { | |
4620 | #if 0 | |
4621 | /* Some types that would be reasonable to generate partial symbols for, | |
4622 | that we don't at present. */ | |
4623 | case DW_TAG_array_type: | |
4624 | case DW_TAG_file_type: | |
4625 | case DW_TAG_ptr_to_member_type: | |
4626 | case DW_TAG_set_type: | |
4627 | case DW_TAG_string_type: | |
4628 | case DW_TAG_subroutine_type: | |
4629 | #endif | |
4630 | case DW_TAG_base_type: | |
4631 | case DW_TAG_class_type: | |
4632 | case DW_TAG_enumeration_type: | |
4633 | case DW_TAG_structure_type: | |
4634 | case DW_TAG_subrange_type: | |
4635 | case DW_TAG_typedef: | |
4636 | case DW_TAG_union_type: | |
4637 | return 1; | |
4638 | default: | |
4639 | return 0; | |
4640 | } | |
4641 | } | |
4642 | ||
4643 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
4644 | ||
4645 | static struct partial_die_info * | |
4646 | load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab, | |
4647 | struct dwarf2_cu *cu) | |
4648 | { | |
4649 | struct partial_die_info *part_die; | |
4650 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
4651 | struct abbrev_info *abbrev; | |
4652 | unsigned int bytes_read; | |
4653 | ||
4654 | int nesting_level = 1; | |
4655 | ||
4656 | parent_die = NULL; | |
4657 | last_die = NULL; | |
4658 | ||
4659 | cu->partial_dies | |
4660 | = htab_create_alloc_ex (cu->header.length / 12, | |
4661 | partial_die_hash, | |
4662 | partial_die_eq, | |
4663 | NULL, | |
4664 | &cu->comp_unit_obstack, | |
4665 | hashtab_obstack_allocate, | |
4666 | dummy_obstack_deallocate); | |
4667 | ||
4668 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4669 | sizeof (struct partial_die_info)); | |
4670 | ||
4671 | while (1) | |
4672 | { | |
4673 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4674 | ||
4675 | /* A NULL abbrev means the end of a series of children. */ | |
4676 | if (abbrev == NULL) | |
4677 | { | |
4678 | if (--nesting_level == 0) | |
4679 | { | |
4680 | /* PART_DIE was probably the last thing allocated on the | |
4681 | comp_unit_obstack, so we could call obstack_free | |
4682 | here. We don't do that because the waste is small, | |
4683 | and will be cleaned up when we're done with this | |
4684 | compilation unit. This way, we're also more robust | |
4685 | against other users of the comp_unit_obstack. */ | |
4686 | return first_die; | |
4687 | } | |
4688 | info_ptr += bytes_read; | |
4689 | last_die = parent_die; | |
4690 | parent_die = parent_die->die_parent; | |
4691 | continue; | |
4692 | } | |
4693 | ||
4694 | /* Check whether this DIE is interesting enough to save. */ | |
4695 | if (!is_type_tag_for_partial (abbrev->tag) | |
4696 | && abbrev->tag != DW_TAG_enumerator | |
4697 | && abbrev->tag != DW_TAG_subprogram | |
4698 | && abbrev->tag != DW_TAG_variable | |
4699 | && abbrev->tag != DW_TAG_namespace) | |
4700 | { | |
4701 | /* Otherwise we skip to the next sibling, if any. */ | |
4702 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
4703 | continue; | |
4704 | } | |
4705 | ||
4706 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
4707 | abfd, info_ptr, cu); | |
4708 | ||
4709 | /* This two-pass algorithm for processing partial symbols has a | |
4710 | high cost in cache pressure. Thus, handle some simple cases | |
4711 | here which cover the majority of C partial symbols. DIEs | |
4712 | which neither have specification tags in them, nor could have | |
4713 | specification tags elsewhere pointing at them, can simply be | |
4714 | processed and discarded. | |
4715 | ||
4716 | This segment is also optional; scan_partial_symbols and | |
4717 | add_partial_symbol will handle these DIEs if we chain | |
4718 | them in normally. When compilers which do not emit large | |
4719 | quantities of duplicate debug information are more common, | |
4720 | this code can probably be removed. */ | |
4721 | ||
4722 | /* Any complete simple types at the top level (pretty much all | |
4723 | of them, for a language without namespaces), can be processed | |
4724 | directly. */ | |
4725 | if (parent_die == NULL | |
4726 | && part_die->has_specification == 0 | |
4727 | && part_die->is_declaration == 0 | |
4728 | && (part_die->tag == DW_TAG_typedef | |
4729 | || part_die->tag == DW_TAG_base_type | |
4730 | || part_die->tag == DW_TAG_subrange_type)) | |
4731 | { | |
4732 | if (building_psymtab && part_die->name != NULL) | |
4733 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4734 | VAR_DOMAIN, LOC_TYPEDEF, | |
4735 | &cu->objfile->static_psymbols, | |
4736 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4737 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4738 | continue; | |
4739 | } | |
4740 | ||
4741 | /* If we're at the second level, and we're an enumerator, and | |
4742 | our parent has no specification (meaning possibly lives in a | |
4743 | namespace elsewhere), then we can add the partial symbol now | |
4744 | instead of queueing it. */ | |
4745 | if (part_die->tag == DW_TAG_enumerator | |
4746 | && parent_die != NULL | |
4747 | && parent_die->die_parent == NULL | |
4748 | && parent_die->tag == DW_TAG_enumeration_type | |
4749 | && parent_die->has_specification == 0) | |
4750 | { | |
4751 | if (part_die->name == NULL) | |
4752 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); | |
4753 | else if (building_psymtab) | |
4754 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4755 | VAR_DOMAIN, LOC_CONST, | |
4756 | cu->language == language_cplus | |
4757 | ? &cu->objfile->global_psymbols | |
4758 | : &cu->objfile->static_psymbols, | |
4759 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4760 | ||
4761 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4762 | continue; | |
4763 | } | |
4764 | ||
4765 | /* We'll save this DIE so link it in. */ | |
4766 | part_die->die_parent = parent_die; | |
4767 | part_die->die_sibling = NULL; | |
4768 | part_die->die_child = NULL; | |
4769 | ||
4770 | if (last_die && last_die == parent_die) | |
4771 | last_die->die_child = part_die; | |
4772 | else if (last_die) | |
4773 | last_die->die_sibling = part_die; | |
4774 | ||
4775 | last_die = part_die; | |
4776 | ||
4777 | if (first_die == NULL) | |
4778 | first_die = part_die; | |
4779 | ||
4780 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
4781 | find interesting need to be in the hash table, because we | |
4782 | also have the parent/sibling/child chains; only those that we | |
4783 | might refer to by offset later during partial symbol reading. | |
4784 | ||
4785 | For now this means things that might have be the target of a | |
4786 | DW_AT_specification, DW_AT_abstract_origin, or | |
4787 | DW_AT_extension. DW_AT_extension will refer only to | |
4788 | namespaces; DW_AT_abstract_origin refers to functions (and | |
4789 | many things under the function DIE, but we do not recurse | |
4790 | into function DIEs during partial symbol reading) and | |
4791 | possibly variables as well; DW_AT_specification refers to | |
4792 | declarations. Declarations ought to have the DW_AT_declaration | |
4793 | flag. It happens that GCC forgets to put it in sometimes, but | |
4794 | only for functions, not for types. | |
4795 | ||
4796 | Adding more things than necessary to the hash table is harmless | |
4797 | except for the performance cost. Adding too few will result in | |
4798 | internal errors in find_partial_die. */ | |
4799 | ||
4800 | if (abbrev->tag == DW_TAG_subprogram | |
4801 | || abbrev->tag == DW_TAG_variable | |
4802 | || abbrev->tag == DW_TAG_namespace | |
4803 | || part_die->is_declaration) | |
4804 | { | |
4805 | void **slot; | |
4806 | ||
4807 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
4808 | part_die->offset, INSERT); | |
4809 | *slot = part_die; | |
4810 | } | |
4811 | ||
4812 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4813 | sizeof (struct partial_die_info)); | |
4814 | ||
4815 | /* For some DIEs we want to follow their children (if any). For C | |
4816 | we have no reason to follow the children of structures; for other | |
4817 | languages we have to, both so that we can get at method physnames | |
4818 | to infer fully qualified class names, and for DW_AT_specification. */ | |
4819 | if (last_die->has_children | |
4820 | && (last_die->tag == DW_TAG_namespace | |
4821 | || last_die->tag == DW_TAG_enumeration_type | |
4822 | || (cu->language != language_c | |
4823 | && (last_die->tag == DW_TAG_class_type | |
4824 | || last_die->tag == DW_TAG_structure_type | |
4825 | || last_die->tag == DW_TAG_union_type)))) | |
4826 | { | |
4827 | nesting_level++; | |
4828 | parent_die = last_die; | |
4829 | continue; | |
4830 | } | |
4831 | ||
4832 | /* Otherwise we skip to the next sibling, if any. */ | |
4833 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
4834 | ||
4835 | /* Back to the top, do it again. */ | |
4836 | } | |
4837 | } | |
4838 | ||
c906108c SS |
4839 | /* Read a minimal amount of information into the minimal die structure. */ |
4840 | ||
4841 | static char * | |
72bf9492 DJ |
4842 | read_partial_die (struct partial_die_info *part_die, |
4843 | struct abbrev_info *abbrev, | |
4844 | unsigned int abbrev_len, bfd *abfd, | |
e7c27a73 | 4845 | char *info_ptr, struct dwarf2_cu *cu) |
c906108c | 4846 | { |
72bf9492 | 4847 | unsigned int bytes_read, i; |
c906108c | 4848 | struct attribute attr; |
c5aa993b | 4849 | int has_low_pc_attr = 0; |
c906108c SS |
4850 | int has_high_pc_attr = 0; |
4851 | ||
72bf9492 | 4852 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 4853 | |
6502dd73 | 4854 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
4855 | |
4856 | info_ptr += abbrev_len; | |
4857 | ||
4858 | if (abbrev == NULL) | |
4859 | return info_ptr; | |
4860 | ||
c906108c SS |
4861 | part_die->tag = abbrev->tag; |
4862 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
4863 | |
4864 | for (i = 0; i < abbrev->num_attrs; ++i) | |
4865 | { | |
e7c27a73 | 4866 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
4867 | |
4868 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 4869 | partial symbol table. */ |
c906108c SS |
4870 | switch (attr.name) |
4871 | { | |
4872 | case DW_AT_name: | |
4873 | ||
4874 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
4875 | if (part_die->name == NULL) | |
4876 | part_die->name = DW_STRING (&attr); | |
4877 | break; | |
4878 | case DW_AT_MIPS_linkage_name: | |
4879 | part_die->name = DW_STRING (&attr); | |
4880 | break; | |
4881 | case DW_AT_low_pc: | |
4882 | has_low_pc_attr = 1; | |
4883 | part_die->lowpc = DW_ADDR (&attr); | |
4884 | break; | |
4885 | case DW_AT_high_pc: | |
4886 | has_high_pc_attr = 1; | |
4887 | part_die->highpc = DW_ADDR (&attr); | |
4888 | break; | |
4889 | case DW_AT_location: | |
8e19ed76 PS |
4890 | /* Support the .debug_loc offsets */ |
4891 | if (attr_form_is_block (&attr)) | |
4892 | { | |
4893 | part_die->locdesc = DW_BLOCK (&attr); | |
4894 | } | |
4895 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) | |
4896 | { | |
4d3c2250 | 4897 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4898 | } |
4899 | else | |
4900 | { | |
4d3c2250 KB |
4901 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4902 | "partial symbol information"); | |
8e19ed76 | 4903 | } |
c906108c SS |
4904 | break; |
4905 | case DW_AT_language: | |
4906 | part_die->language = DW_UNSND (&attr); | |
4907 | break; | |
4908 | case DW_AT_external: | |
4909 | part_die->is_external = DW_UNSND (&attr); | |
4910 | break; | |
4911 | case DW_AT_declaration: | |
4912 | part_die->is_declaration = DW_UNSND (&attr); | |
4913 | break; | |
4914 | case DW_AT_type: | |
4915 | part_die->has_type = 1; | |
4916 | break; | |
4917 | case DW_AT_abstract_origin: | |
4918 | case DW_AT_specification: | |
72bf9492 DJ |
4919 | case DW_AT_extension: |
4920 | part_die->has_specification = 1; | |
4921 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
4922 | break; |
4923 | case DW_AT_sibling: | |
4924 | /* Ignore absolute siblings, they might point outside of | |
4925 | the current compile unit. */ | |
4926 | if (attr.form == DW_FORM_ref_addr) | |
4d3c2250 | 4927 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); |
c906108c | 4928 | else |
6502dd73 DJ |
4929 | part_die->sibling = dwarf2_per_objfile->info_buffer |
4930 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 4931 | break; |
aaa75496 JB |
4932 | case DW_AT_stmt_list: |
4933 | part_die->has_stmt_list = 1; | |
4934 | part_die->line_offset = DW_UNSND (&attr); | |
4935 | break; | |
c906108c SS |
4936 | default: |
4937 | break; | |
4938 | } | |
4939 | } | |
4940 | ||
c906108c SS |
4941 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
4942 | eliminate duplicate copies of functions and vtables and such. | |
4943 | The linker will arbitrarily choose one and discard the others. | |
4944 | The AT_*_pc values for such functions refer to local labels in | |
4945 | these sections. If the section from that file was discarded, the | |
4946 | labels are not in the output, so the relocs get a value of 0. | |
4947 | If this is a discarded function, mark the pc bounds as invalid, | |
4948 | so that GDB will ignore it. */ | |
4949 | if (has_low_pc_attr && has_high_pc_attr | |
4950 | && part_die->lowpc < part_die->highpc | |
4951 | && (part_die->lowpc != 0 | |
4952 | || (bfd_get_file_flags (abfd) & HAS_RELOC))) | |
0b010bcc | 4953 | part_die->has_pc_info = 1; |
c906108c SS |
4954 | return info_ptr; |
4955 | } | |
4956 | ||
72bf9492 DJ |
4957 | /* Find a cached partial DIE at OFFSET in CU. */ |
4958 | ||
4959 | static struct partial_die_info * | |
4960 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
4961 | { | |
4962 | struct partial_die_info *lookup_die = NULL; | |
4963 | struct partial_die_info part_die; | |
4964 | ||
4965 | part_die.offset = offset; | |
4966 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
4967 | ||
4968 | if (lookup_die == NULL) | |
4969 | internal_error (__FILE__, __LINE__, | |
4970 | "could not find partial DIE in cache\n"); | |
4971 | ||
4972 | return lookup_die; | |
4973 | } | |
4974 | ||
4975 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
4976 | ||
4977 | static struct partial_die_info * | |
4978 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu, | |
4979 | struct dwarf2_cu **target_cu) | |
4980 | { | |
4981 | struct dwarf2_per_cu_data *per_cu; | |
4982 | ||
4983 | if (offset >= cu->header.offset | |
4984 | && offset < cu->header.offset + cu->header.length) | |
4985 | { | |
4986 | *target_cu = cu; | |
4987 | return find_partial_die_in_comp_unit (offset, cu); | |
4988 | } | |
4989 | ||
4990 | internal_error (__FILE__, __LINE__, | |
4991 | "unsupported inter-compilation-unit reference"); | |
4992 | } | |
4993 | ||
4994 | /* Adjust PART_DIE before generating a symbol for it. This function | |
4995 | may set the is_external flag or change the DIE's name. */ | |
4996 | ||
4997 | static void | |
4998 | fixup_partial_die (struct partial_die_info *part_die, | |
4999 | struct dwarf2_cu *cu) | |
5000 | { | |
5001 | /* If we found a reference attribute and the DIE has no name, try | |
5002 | to find a name in the referred to DIE. */ | |
5003 | ||
5004 | if (part_die->name == NULL && part_die->has_specification) | |
5005 | { | |
5006 | struct partial_die_info *spec_die; | |
5007 | struct dwarf2_cu *spec_cu; | |
5008 | ||
5009 | spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu); | |
5010 | ||
5011 | fixup_partial_die (spec_die, spec_cu); | |
5012 | ||
5013 | if (spec_die->name) | |
5014 | { | |
5015 | part_die->name = spec_die->name; | |
5016 | ||
5017 | /* Copy DW_AT_external attribute if it is set. */ | |
5018 | if (spec_die->is_external) | |
5019 | part_die->is_external = spec_die->is_external; | |
5020 | } | |
5021 | } | |
5022 | ||
5023 | /* Set default names for some unnamed DIEs. */ | |
5024 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
5025 | || part_die->tag == DW_TAG_class_type)) | |
5026 | part_die->name = "(anonymous class)"; | |
5027 | ||
5028 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
5029 | part_die->name = "(anonymous namespace)"; | |
5030 | ||
5031 | if (part_die->tag == DW_TAG_structure_type | |
5032 | || part_die->tag == DW_TAG_class_type | |
5033 | || part_die->tag == DW_TAG_union_type) | |
5034 | guess_structure_name (part_die, cu); | |
5035 | } | |
5036 | ||
639d11d3 DC |
5037 | /* Read the die from the .debug_info section buffer. Set DIEP to |
5038 | point to a newly allocated die with its information, except for its | |
5039 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
5040 | whether the die has children or not. */ | |
c906108c SS |
5041 | |
5042 | static char * | |
107d2387 | 5043 | read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, |
e7c27a73 | 5044 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
5045 | { |
5046 | unsigned int abbrev_number, bytes_read, i, offset; | |
5047 | struct abbrev_info *abbrev; | |
5048 | struct die_info *die; | |
5049 | ||
6502dd73 | 5050 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
5051 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5052 | info_ptr += bytes_read; | |
5053 | if (!abbrev_number) | |
5054 | { | |
5055 | die = dwarf_alloc_die (); | |
5056 | die->tag = 0; | |
5057 | die->abbrev = abbrev_number; | |
5058 | die->type = NULL; | |
5059 | *diep = die; | |
639d11d3 | 5060 | *has_children = 0; |
c906108c SS |
5061 | return info_ptr; |
5062 | } | |
5063 | ||
e7c27a73 | 5064 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
5065 | if (!abbrev) |
5066 | { | |
639d11d3 | 5067 | error ("Dwarf Error: could not find abbrev number %d [in module %s]", |
72bf9492 | 5068 | abbrev_number, |
639d11d3 | 5069 | bfd_get_filename (abfd)); |
c906108c SS |
5070 | } |
5071 | die = dwarf_alloc_die (); | |
5072 | die->offset = offset; | |
5073 | die->tag = abbrev->tag; | |
c906108c SS |
5074 | die->abbrev = abbrev_number; |
5075 | die->type = NULL; | |
5076 | ||
5077 | die->num_attrs = abbrev->num_attrs; | |
5078 | die->attrs = (struct attribute *) | |
5079 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
5080 | ||
5081 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5082 | { | |
5083 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 5084 | abfd, info_ptr, cu); |
c906108c SS |
5085 | } |
5086 | ||
5087 | *diep = die; | |
639d11d3 | 5088 | *has_children = abbrev->has_children; |
c906108c SS |
5089 | return info_ptr; |
5090 | } | |
5091 | ||
a8329558 | 5092 | /* Read an attribute value described by an attribute form. */ |
c906108c SS |
5093 | |
5094 | static char * | |
a8329558 | 5095 | read_attribute_value (struct attribute *attr, unsigned form, |
e7c27a73 DJ |
5096 | bfd *abfd, char *info_ptr, |
5097 | struct dwarf2_cu *cu) | |
c906108c | 5098 | { |
e7c27a73 | 5099 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5100 | unsigned int bytes_read; |
5101 | struct dwarf_block *blk; | |
5102 | ||
a8329558 KW |
5103 | attr->form = form; |
5104 | switch (form) | |
c906108c SS |
5105 | { |
5106 | case DW_FORM_addr: | |
5107 | case DW_FORM_ref_addr: | |
e7c27a73 | 5108 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 5109 | info_ptr += bytes_read; |
c906108c SS |
5110 | break; |
5111 | case DW_FORM_block2: | |
7b5a2f43 | 5112 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5113 | blk->size = read_2_bytes (abfd, info_ptr); |
5114 | info_ptr += 2; | |
5115 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5116 | info_ptr += blk->size; | |
5117 | DW_BLOCK (attr) = blk; | |
5118 | break; | |
5119 | case DW_FORM_block4: | |
7b5a2f43 | 5120 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5121 | blk->size = read_4_bytes (abfd, info_ptr); |
5122 | info_ptr += 4; | |
5123 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5124 | info_ptr += blk->size; | |
5125 | DW_BLOCK (attr) = blk; | |
5126 | break; | |
5127 | case DW_FORM_data2: | |
5128 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5129 | info_ptr += 2; | |
5130 | break; | |
5131 | case DW_FORM_data4: | |
5132 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5133 | info_ptr += 4; | |
5134 | break; | |
5135 | case DW_FORM_data8: | |
5136 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5137 | info_ptr += 8; | |
5138 | break; | |
5139 | case DW_FORM_string: | |
5140 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
5141 | info_ptr += bytes_read; | |
5142 | break; | |
4bdf3d34 JJ |
5143 | case DW_FORM_strp: |
5144 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
5145 | &bytes_read); | |
5146 | info_ptr += bytes_read; | |
5147 | break; | |
c906108c | 5148 | case DW_FORM_block: |
7b5a2f43 | 5149 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5150 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5151 | info_ptr += bytes_read; | |
5152 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5153 | info_ptr += blk->size; | |
5154 | DW_BLOCK (attr) = blk; | |
5155 | break; | |
5156 | case DW_FORM_block1: | |
7b5a2f43 | 5157 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5158 | blk->size = read_1_byte (abfd, info_ptr); |
5159 | info_ptr += 1; | |
5160 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5161 | info_ptr += blk->size; | |
5162 | DW_BLOCK (attr) = blk; | |
5163 | break; | |
5164 | case DW_FORM_data1: | |
5165 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5166 | info_ptr += 1; | |
5167 | break; | |
5168 | case DW_FORM_flag: | |
5169 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5170 | info_ptr += 1; | |
5171 | break; | |
5172 | case DW_FORM_sdata: | |
5173 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
5174 | info_ptr += bytes_read; | |
5175 | break; | |
5176 | case DW_FORM_udata: | |
5177 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5178 | info_ptr += bytes_read; | |
5179 | break; | |
5180 | case DW_FORM_ref1: | |
5181 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5182 | info_ptr += 1; | |
5183 | break; | |
5184 | case DW_FORM_ref2: | |
5185 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5186 | info_ptr += 2; | |
5187 | break; | |
5188 | case DW_FORM_ref4: | |
5189 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5190 | info_ptr += 4; | |
5191 | break; | |
613e1657 KB |
5192 | case DW_FORM_ref8: |
5193 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5194 | info_ptr += 8; | |
5195 | break; | |
c906108c SS |
5196 | case DW_FORM_ref_udata: |
5197 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5198 | info_ptr += bytes_read; | |
5199 | break; | |
c906108c | 5200 | case DW_FORM_indirect: |
a8329558 KW |
5201 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5202 | info_ptr += bytes_read; | |
e7c27a73 | 5203 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 5204 | break; |
c906108c | 5205 | default: |
659b0389 ML |
5206 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", |
5207 | dwarf_form_name (form), | |
5208 | bfd_get_filename (abfd)); | |
c906108c SS |
5209 | } |
5210 | return info_ptr; | |
5211 | } | |
5212 | ||
a8329558 KW |
5213 | /* Read an attribute described by an abbreviated attribute. */ |
5214 | ||
5215 | static char * | |
5216 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, | |
e7c27a73 | 5217 | bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
5218 | { |
5219 | attr->name = abbrev->name; | |
e7c27a73 | 5220 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
5221 | } |
5222 | ||
c906108c SS |
5223 | /* read dwarf information from a buffer */ |
5224 | ||
5225 | static unsigned int | |
fba45db2 | 5226 | read_1_byte (bfd *abfd, char *buf) |
c906108c SS |
5227 | { |
5228 | return bfd_get_8 (abfd, (bfd_byte *) buf); | |
5229 | } | |
5230 | ||
5231 | static int | |
fba45db2 | 5232 | read_1_signed_byte (bfd *abfd, char *buf) |
c906108c SS |
5233 | { |
5234 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf); | |
5235 | } | |
5236 | ||
5237 | static unsigned int | |
fba45db2 | 5238 | read_2_bytes (bfd *abfd, char *buf) |
c906108c SS |
5239 | { |
5240 | return bfd_get_16 (abfd, (bfd_byte *) buf); | |
5241 | } | |
5242 | ||
5243 | static int | |
fba45db2 | 5244 | read_2_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5245 | { |
5246 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5247 | } | |
5248 | ||
5249 | static unsigned int | |
fba45db2 | 5250 | read_4_bytes (bfd *abfd, char *buf) |
c906108c SS |
5251 | { |
5252 | return bfd_get_32 (abfd, (bfd_byte *) buf); | |
5253 | } | |
5254 | ||
5255 | static int | |
fba45db2 | 5256 | read_4_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5257 | { |
5258 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5259 | } | |
5260 | ||
ce5d95e1 | 5261 | static unsigned long |
fba45db2 | 5262 | read_8_bytes (bfd *abfd, char *buf) |
c906108c SS |
5263 | { |
5264 | return bfd_get_64 (abfd, (bfd_byte *) buf); | |
5265 | } | |
5266 | ||
5267 | static CORE_ADDR | |
e7c27a73 | 5268 | read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) |
c906108c | 5269 | { |
e7c27a73 | 5270 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5271 | CORE_ADDR retval = 0; |
5272 | ||
107d2387 | 5273 | if (cu_header->signed_addr_p) |
c906108c | 5274 | { |
107d2387 AC |
5275 | switch (cu_header->addr_size) |
5276 | { | |
5277 | case 2: | |
5278 | retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5279 | break; | |
5280 | case 4: | |
5281 | retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5282 | break; | |
5283 | case 8: | |
5284 | retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); | |
5285 | break; | |
5286 | default: | |
8e65ff28 | 5287 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5288 | "read_address: bad switch, signed [in module %s]", |
5289 | bfd_get_filename (abfd)); | |
107d2387 AC |
5290 | } |
5291 | } | |
5292 | else | |
5293 | { | |
5294 | switch (cu_header->addr_size) | |
5295 | { | |
5296 | case 2: | |
5297 | retval = bfd_get_16 (abfd, (bfd_byte *) buf); | |
5298 | break; | |
5299 | case 4: | |
5300 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5301 | break; | |
5302 | case 8: | |
5303 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5304 | break; | |
5305 | default: | |
8e65ff28 | 5306 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5307 | "read_address: bad switch, unsigned [in module %s]", |
5308 | bfd_get_filename (abfd)); | |
107d2387 | 5309 | } |
c906108c | 5310 | } |
64367e0a | 5311 | |
107d2387 AC |
5312 | *bytes_read = cu_header->addr_size; |
5313 | return retval; | |
c906108c SS |
5314 | } |
5315 | ||
f7ef9339 | 5316 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
5317 | specification allows the initial length to take up either 4 bytes |
5318 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
5319 | bytes describe the length and all offsets will be 8 bytes in length | |
5320 | instead of 4. | |
5321 | ||
f7ef9339 KB |
5322 | An older, non-standard 64-bit format is also handled by this |
5323 | function. The older format in question stores the initial length | |
5324 | as an 8-byte quantity without an escape value. Lengths greater | |
5325 | than 2^32 aren't very common which means that the initial 4 bytes | |
5326 | is almost always zero. Since a length value of zero doesn't make | |
5327 | sense for the 32-bit format, this initial zero can be considered to | |
5328 | be an escape value which indicates the presence of the older 64-bit | |
5329 | format. As written, the code can't detect (old format) lengths | |
5330 | greater than 4GB. If it becomes necessary to handle lengths somewhat | |
5331 | larger than 4GB, we could allow other small values (such as the | |
5332 | non-sensical values of 1, 2, and 3) to also be used as escape values | |
5333 | indicating the presence of the old format. | |
5334 | ||
613e1657 KB |
5335 | The value returned via bytes_read should be used to increment |
5336 | the relevant pointer after calling read_initial_length(). | |
5337 | ||
5338 | As a side effect, this function sets the fields initial_length_size | |
5339 | and offset_size in cu_header to the values appropriate for the | |
5340 | length field. (The format of the initial length field determines | |
5341 | the width of file offsets to be fetched later with fetch_offset().) | |
5342 | ||
5343 | [ Note: read_initial_length() and read_offset() are based on the | |
5344 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 5345 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
5346 | from: |
5347 | ||
f7ef9339 | 5348 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
5349 | |
5350 | This document is only a draft and is subject to change. (So beware.) | |
5351 | ||
f7ef9339 KB |
5352 | Details regarding the older, non-standard 64-bit format were |
5353 | determined empirically by examining 64-bit ELF files produced | |
5354 | by the SGI toolchain on an IRIX 6.5 machine. | |
5355 | ||
5356 | - Kevin, July 16, 2002 | |
613e1657 KB |
5357 | ] */ |
5358 | ||
5359 | static LONGEST | |
5360 | read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, | |
5361 | int *bytes_read) | |
5362 | { | |
5363 | LONGEST retval = 0; | |
5364 | ||
5365 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5366 | ||
5367 | if (retval == 0xffffffff) | |
5368 | { | |
5369 | retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); | |
5370 | *bytes_read = 12; | |
5371 | if (cu_header != NULL) | |
5372 | { | |
5373 | cu_header->initial_length_size = 12; | |
5374 | cu_header->offset_size = 8; | |
5375 | } | |
5376 | } | |
f7ef9339 KB |
5377 | else if (retval == 0) |
5378 | { | |
5379 | /* Handle (non-standard) 64-bit DWARF2 formats such as that used | |
5380 | by IRIX. */ | |
5381 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5382 | *bytes_read = 8; | |
5383 | if (cu_header != NULL) | |
5384 | { | |
5385 | cu_header->initial_length_size = 8; | |
5386 | cu_header->offset_size = 8; | |
5387 | } | |
5388 | } | |
613e1657 KB |
5389 | else |
5390 | { | |
5391 | *bytes_read = 4; | |
5392 | if (cu_header != NULL) | |
5393 | { | |
5394 | cu_header->initial_length_size = 4; | |
5395 | cu_header->offset_size = 4; | |
5396 | } | |
5397 | } | |
5398 | ||
5399 | return retval; | |
5400 | } | |
5401 | ||
5402 | /* Read an offset from the data stream. The size of the offset is | |
5403 | given by cu_header->offset_size. */ | |
5404 | ||
5405 | static LONGEST | |
5406 | read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, | |
5407 | int *bytes_read) | |
5408 | { | |
5409 | LONGEST retval = 0; | |
5410 | ||
5411 | switch (cu_header->offset_size) | |
5412 | { | |
5413 | case 4: | |
5414 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5415 | *bytes_read = 4; | |
5416 | break; | |
5417 | case 8: | |
5418 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5419 | *bytes_read = 8; | |
5420 | break; | |
5421 | default: | |
8e65ff28 | 5422 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5423 | "read_offset: bad switch [in module %s]", |
5424 | bfd_get_filename (abfd)); | |
613e1657 KB |
5425 | } |
5426 | ||
5427 | return retval; | |
5428 | } | |
5429 | ||
c906108c | 5430 | static char * |
fba45db2 | 5431 | read_n_bytes (bfd *abfd, char *buf, unsigned int size) |
c906108c SS |
5432 | { |
5433 | /* If the size of a host char is 8 bits, we can return a pointer | |
5434 | to the buffer, otherwise we have to copy the data to a buffer | |
5435 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5436 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 5437 | return buf; |
c906108c SS |
5438 | } |
5439 | ||
5440 | static char * | |
fba45db2 | 5441 | read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
5442 | { |
5443 | /* If the size of a host char is 8 bits, we can return a pointer | |
5444 | to the string, otherwise we have to copy the string to a buffer | |
5445 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5446 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
5447 | if (*buf == '\0') |
5448 | { | |
5449 | *bytes_read_ptr = 1; | |
5450 | return NULL; | |
5451 | } | |
5452 | *bytes_read_ptr = strlen (buf) + 1; | |
5453 | return buf; | |
4bdf3d34 JJ |
5454 | } |
5455 | ||
5456 | static char * | |
5457 | read_indirect_string (bfd *abfd, char *buf, | |
5458 | const struct comp_unit_head *cu_header, | |
5459 | unsigned int *bytes_read_ptr) | |
5460 | { | |
5461 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
5462 | (int *) bytes_read_ptr); | |
c906108c | 5463 | |
6502dd73 | 5464 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 5465 | { |
659b0389 ML |
5466 | error ("DW_FORM_strp used without .debug_str section [in module %s]", |
5467 | bfd_get_filename (abfd)); | |
4bdf3d34 | 5468 | return NULL; |
c906108c | 5469 | } |
6502dd73 | 5470 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 5471 | { |
659b0389 ML |
5472 | error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", |
5473 | bfd_get_filename (abfd)); | |
c906108c SS |
5474 | return NULL; |
5475 | } | |
4bdf3d34 | 5476 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 5477 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 5478 | return NULL; |
6502dd73 | 5479 | return dwarf2_per_objfile->str_buffer + str_offset; |
c906108c SS |
5480 | } |
5481 | ||
ce5d95e1 | 5482 | static unsigned long |
fba45db2 | 5483 | read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5484 | { |
ce5d95e1 JB |
5485 | unsigned long result; |
5486 | unsigned int num_read; | |
c906108c SS |
5487 | int i, shift; |
5488 | unsigned char byte; | |
5489 | ||
5490 | result = 0; | |
5491 | shift = 0; | |
5492 | num_read = 0; | |
5493 | i = 0; | |
5494 | while (1) | |
5495 | { | |
5496 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5497 | buf++; | |
5498 | num_read++; | |
ce5d95e1 | 5499 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
5500 | if ((byte & 128) == 0) |
5501 | { | |
5502 | break; | |
5503 | } | |
5504 | shift += 7; | |
5505 | } | |
5506 | *bytes_read_ptr = num_read; | |
5507 | return result; | |
5508 | } | |
5509 | ||
ce5d95e1 | 5510 | static long |
fba45db2 | 5511 | read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5512 | { |
ce5d95e1 | 5513 | long result; |
c906108c SS |
5514 | int i, shift, size, num_read; |
5515 | unsigned char byte; | |
5516 | ||
5517 | result = 0; | |
5518 | shift = 0; | |
5519 | size = 32; | |
5520 | num_read = 0; | |
5521 | i = 0; | |
5522 | while (1) | |
5523 | { | |
5524 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5525 | buf++; | |
5526 | num_read++; | |
ce5d95e1 | 5527 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
5528 | shift += 7; |
5529 | if ((byte & 128) == 0) | |
5530 | { | |
5531 | break; | |
5532 | } | |
5533 | } | |
5534 | if ((shift < size) && (byte & 0x40)) | |
5535 | { | |
5536 | result |= -(1 << shift); | |
5537 | } | |
5538 | *bytes_read_ptr = num_read; | |
5539 | return result; | |
5540 | } | |
5541 | ||
4bb7a0a7 DJ |
5542 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
5543 | ||
5544 | static char * | |
5545 | skip_leb128 (bfd *abfd, char *buf) | |
5546 | { | |
5547 | int byte; | |
5548 | ||
5549 | while (1) | |
5550 | { | |
5551 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5552 | buf++; | |
5553 | if ((byte & 128) == 0) | |
5554 | return buf; | |
5555 | } | |
5556 | } | |
5557 | ||
c906108c | 5558 | static void |
e142c38c | 5559 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
5560 | { |
5561 | switch (lang) | |
5562 | { | |
5563 | case DW_LANG_C89: | |
5564 | case DW_LANG_C: | |
e142c38c | 5565 | cu->language = language_c; |
c906108c SS |
5566 | break; |
5567 | case DW_LANG_C_plus_plus: | |
e142c38c | 5568 | cu->language = language_cplus; |
c906108c SS |
5569 | break; |
5570 | case DW_LANG_Fortran77: | |
5571 | case DW_LANG_Fortran90: | |
b21b22e0 | 5572 | case DW_LANG_Fortran95: |
e142c38c | 5573 | cu->language = language_fortran; |
c906108c SS |
5574 | break; |
5575 | case DW_LANG_Mips_Assembler: | |
e142c38c | 5576 | cu->language = language_asm; |
c906108c | 5577 | break; |
bebd888e | 5578 | case DW_LANG_Java: |
e142c38c | 5579 | cu->language = language_java; |
bebd888e | 5580 | break; |
c906108c | 5581 | case DW_LANG_Ada83: |
8aaf0b47 | 5582 | case DW_LANG_Ada95: |
c906108c SS |
5583 | case DW_LANG_Cobol74: |
5584 | case DW_LANG_Cobol85: | |
5585 | case DW_LANG_Pascal83: | |
5586 | case DW_LANG_Modula2: | |
5587 | default: | |
e142c38c | 5588 | cu->language = language_minimal; |
c906108c SS |
5589 | break; |
5590 | } | |
e142c38c | 5591 | cu->language_defn = language_def (cu->language); |
c906108c SS |
5592 | } |
5593 | ||
5594 | /* Return the named attribute or NULL if not there. */ | |
5595 | ||
5596 | static struct attribute * | |
e142c38c | 5597 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
5598 | { |
5599 | unsigned int i; | |
5600 | struct attribute *spec = NULL; | |
5601 | ||
5602 | for (i = 0; i < die->num_attrs; ++i) | |
5603 | { | |
5604 | if (die->attrs[i].name == name) | |
5605 | { | |
5606 | return &die->attrs[i]; | |
5607 | } | |
5608 | if (die->attrs[i].name == DW_AT_specification | |
5609 | || die->attrs[i].name == DW_AT_abstract_origin) | |
5610 | spec = &die->attrs[i]; | |
5611 | } | |
5612 | if (spec) | |
5613 | { | |
5614 | struct die_info *ref_die = | |
e142c38c | 5615 | follow_die_ref (dwarf2_get_ref_die_offset (spec, cu)); |
c906108c SS |
5616 | |
5617 | if (ref_die) | |
e142c38c | 5618 | return dwarf2_attr (ref_die, name, cu); |
c906108c | 5619 | } |
c5aa993b | 5620 | |
c906108c SS |
5621 | return NULL; |
5622 | } | |
5623 | ||
05cf31d1 JB |
5624 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
5625 | and holds a non-zero value. This function should only be used for | |
5626 | DW_FORM_flag attributes. */ | |
5627 | ||
5628 | static int | |
5629 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
5630 | { | |
5631 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
5632 | ||
5633 | return (attr && DW_UNSND (attr)); | |
5634 | } | |
5635 | ||
3ca72b44 | 5636 | static int |
e142c38c | 5637 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 5638 | { |
05cf31d1 JB |
5639 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
5640 | which value is non-zero. However, we have to be careful with | |
5641 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
5642 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
5643 | end up accidently finding a declaration attribute that belongs | |
5644 | to a different DIE referenced by the specification attribute, | |
5645 | even though the given DIE does not have a declaration attribute. */ | |
5646 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
5647 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
5648 | } |
5649 | ||
63d06c5c DC |
5650 | /* Return the die giving the specification for DIE, if there is |
5651 | one. */ | |
5652 | ||
5653 | static struct die_info * | |
e142c38c | 5654 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 5655 | { |
e142c38c | 5656 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
5657 | |
5658 | if (spec_attr == NULL) | |
5659 | return NULL; | |
5660 | else | |
e142c38c | 5661 | return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu)); |
63d06c5c | 5662 | } |
c906108c | 5663 | |
debd256d JB |
5664 | /* Free the line_header structure *LH, and any arrays and strings it |
5665 | refers to. */ | |
5666 | static void | |
5667 | free_line_header (struct line_header *lh) | |
5668 | { | |
5669 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 5670 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
5671 | |
5672 | /* Remember that all the lh->file_names[i].name pointers are | |
5673 | pointers into debug_line_buffer, and don't need to be freed. */ | |
5674 | if (lh->file_names) | |
a8bc7b56 | 5675 | xfree (lh->file_names); |
debd256d JB |
5676 | |
5677 | /* Similarly for the include directory names. */ | |
5678 | if (lh->include_dirs) | |
a8bc7b56 | 5679 | xfree (lh->include_dirs); |
debd256d | 5680 | |
a8bc7b56 | 5681 | xfree (lh); |
debd256d JB |
5682 | } |
5683 | ||
5684 | ||
5685 | /* Add an entry to LH's include directory table. */ | |
5686 | static void | |
5687 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 5688 | { |
debd256d JB |
5689 | /* Grow the array if necessary. */ |
5690 | if (lh->include_dirs_size == 0) | |
c5aa993b | 5691 | { |
debd256d JB |
5692 | lh->include_dirs_size = 1; /* for testing */ |
5693 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
5694 | * sizeof (*lh->include_dirs)); | |
5695 | } | |
5696 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
5697 | { | |
5698 | lh->include_dirs_size *= 2; | |
5699 | lh->include_dirs = xrealloc (lh->include_dirs, | |
5700 | (lh->include_dirs_size | |
5701 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 5702 | } |
c906108c | 5703 | |
debd256d JB |
5704 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
5705 | } | |
5706 | ||
5707 | ||
5708 | /* Add an entry to LH's file name table. */ | |
5709 | static void | |
5710 | add_file_name (struct line_header *lh, | |
5711 | char *name, | |
5712 | unsigned int dir_index, | |
5713 | unsigned int mod_time, | |
5714 | unsigned int length) | |
5715 | { | |
5716 | struct file_entry *fe; | |
5717 | ||
5718 | /* Grow the array if necessary. */ | |
5719 | if (lh->file_names_size == 0) | |
5720 | { | |
5721 | lh->file_names_size = 1; /* for testing */ | |
5722 | lh->file_names = xmalloc (lh->file_names_size | |
5723 | * sizeof (*lh->file_names)); | |
5724 | } | |
5725 | else if (lh->num_file_names >= lh->file_names_size) | |
5726 | { | |
5727 | lh->file_names_size *= 2; | |
5728 | lh->file_names = xrealloc (lh->file_names, | |
5729 | (lh->file_names_size | |
5730 | * sizeof (*lh->file_names))); | |
5731 | } | |
5732 | ||
5733 | fe = &lh->file_names[lh->num_file_names++]; | |
5734 | fe->name = name; | |
5735 | fe->dir_index = dir_index; | |
5736 | fe->mod_time = mod_time; | |
5737 | fe->length = length; | |
aaa75496 | 5738 | fe->included_p = 0; |
debd256d JB |
5739 | } |
5740 | ||
5741 | ||
5742 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
5743 | .debug_line, according to the endianness of ABFD. Return a pointer |
5744 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
5745 | |
5746 | NOTE: the strings in the include directory and file name tables of | |
5747 | the returned object point into debug_line_buffer, and must not be | |
5748 | freed. */ | |
5749 | static struct line_header * | |
5750 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 5751 | struct dwarf2_cu *cu) |
debd256d JB |
5752 | { |
5753 | struct cleanup *back_to; | |
5754 | struct line_header *lh; | |
5755 | char *line_ptr; | |
5756 | int bytes_read; | |
5757 | int i; | |
5758 | char *cur_dir, *cur_file; | |
5759 | ||
6502dd73 | 5760 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 5761 | { |
4d3c2250 | 5762 | complaint (&symfile_complaints, "missing .debug_line section"); |
debd256d JB |
5763 | return 0; |
5764 | } | |
5765 | ||
5766 | /* Make sure that at least there's room for the total_length field. That | |
5767 | could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 5768 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 5769 | { |
4d3c2250 | 5770 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5771 | return 0; |
5772 | } | |
5773 | ||
5774 | lh = xmalloc (sizeof (*lh)); | |
5775 | memset (lh, 0, sizeof (*lh)); | |
5776 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
5777 | (void *) lh); | |
5778 | ||
6502dd73 | 5779 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d JB |
5780 | |
5781 | /* read in the header */ | |
5782 | lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read); | |
5783 | line_ptr += bytes_read; | |
6502dd73 DJ |
5784 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
5785 | + dwarf2_per_objfile->line_size)) | |
debd256d | 5786 | { |
4d3c2250 | 5787 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5788 | return 0; |
5789 | } | |
5790 | lh->statement_program_end = line_ptr + lh->total_length; | |
5791 | lh->version = read_2_bytes (abfd, line_ptr); | |
5792 | line_ptr += 2; | |
e7c27a73 | 5793 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
5794 | line_ptr += bytes_read; |
5795 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
5796 | line_ptr += 1; | |
5797 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
5798 | line_ptr += 1; | |
5799 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
5800 | line_ptr += 1; | |
5801 | lh->line_range = read_1_byte (abfd, line_ptr); | |
5802 | line_ptr += 1; | |
5803 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
5804 | line_ptr += 1; | |
5805 | lh->standard_opcode_lengths | |
5806 | = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); | |
5807 | ||
5808 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
5809 | for (i = 1; i < lh->opcode_base; ++i) | |
5810 | { | |
5811 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
5812 | line_ptr += 1; | |
5813 | } | |
5814 | ||
5815 | /* Read directory table */ | |
5816 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5817 | { | |
5818 | line_ptr += bytes_read; | |
5819 | add_include_dir (lh, cur_dir); | |
5820 | } | |
5821 | line_ptr += bytes_read; | |
5822 | ||
5823 | /* Read file name table */ | |
5824 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5825 | { | |
5826 | unsigned int dir_index, mod_time, length; | |
5827 | ||
5828 | line_ptr += bytes_read; | |
5829 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5830 | line_ptr += bytes_read; | |
5831 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5832 | line_ptr += bytes_read; | |
5833 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5834 | line_ptr += bytes_read; | |
5835 | ||
5836 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
5837 | } | |
5838 | line_ptr += bytes_read; | |
5839 | lh->statement_program_start = line_ptr; | |
5840 | ||
6502dd73 DJ |
5841 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
5842 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 KB |
5843 | complaint (&symfile_complaints, |
5844 | "line number info header doesn't fit in `.debug_line' section"); | |
debd256d JB |
5845 | |
5846 | discard_cleanups (back_to); | |
5847 | return lh; | |
5848 | } | |
c906108c | 5849 | |
5fb290d7 DJ |
5850 | /* This function exists to work around a bug in certain compilers |
5851 | (particularly GCC 2.95), in which the first line number marker of a | |
5852 | function does not show up until after the prologue, right before | |
5853 | the second line number marker. This function shifts ADDRESS down | |
5854 | to the beginning of the function if necessary, and is called on | |
5855 | addresses passed to record_line. */ | |
5856 | ||
5857 | static CORE_ADDR | |
e142c38c | 5858 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
5859 | { |
5860 | struct function_range *fn; | |
5861 | ||
5862 | /* Find the function_range containing address. */ | |
e142c38c | 5863 | if (!cu->first_fn) |
5fb290d7 DJ |
5864 | return address; |
5865 | ||
e142c38c DJ |
5866 | if (!cu->cached_fn) |
5867 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 5868 | |
e142c38c | 5869 | fn = cu->cached_fn; |
5fb290d7 DJ |
5870 | while (fn) |
5871 | if (fn->lowpc <= address && fn->highpc > address) | |
5872 | goto found; | |
5873 | else | |
5874 | fn = fn->next; | |
5875 | ||
e142c38c DJ |
5876 | fn = cu->first_fn; |
5877 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
5878 | if (fn->lowpc <= address && fn->highpc > address) |
5879 | goto found; | |
5880 | else | |
5881 | fn = fn->next; | |
5882 | ||
5883 | return address; | |
5884 | ||
5885 | found: | |
5886 | if (fn->seen_line) | |
5887 | return address; | |
5888 | if (address != fn->lowpc) | |
4d3c2250 KB |
5889 | complaint (&symfile_complaints, |
5890 | "misplaced first line number at 0x%lx for '%s'", | |
5891 | (unsigned long) address, fn->name); | |
5fb290d7 DJ |
5892 | fn->seen_line = 1; |
5893 | return fn->lowpc; | |
5894 | } | |
5895 | ||
aaa75496 JB |
5896 | /* Decode the Line Number Program (LNP) for the given line_header |
5897 | structure and CU. The actual information extracted and the type | |
5898 | of structures created from the LNP depends on the value of PST. | |
5899 | ||
5900 | 1. If PST is NULL, then this procedure uses the data from the program | |
5901 | to create all necessary symbol tables, and their linetables. | |
5902 | The compilation directory of the file is passed in COMP_DIR, | |
5903 | and must not be NULL. | |
5904 | ||
5905 | 2. If PST is not NULL, this procedure reads the program to determine | |
5906 | the list of files included by the unit represented by PST, and | |
5907 | builds all the associated partial symbol tables. In this case, | |
5908 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
5909 | is not used to compute the full name of the symtab, and therefore | |
5910 | omitting it when building the partial symtab does not introduce | |
5911 | the potential for inconsistency - a partial symtab and its associated | |
5912 | symbtab having a different fullname -). */ | |
debd256d | 5913 | |
c906108c | 5914 | static void |
debd256d | 5915 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 5916 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c SS |
5917 | { |
5918 | char *line_ptr; | |
5919 | char *line_end; | |
e7c27a73 | 5920 | unsigned int bytes_read; |
c906108c | 5921 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
5922 | CORE_ADDR baseaddr; |
5923 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 5924 | const int decode_for_pst_p = (pst != NULL); |
e142c38c DJ |
5925 | |
5926 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 5927 | |
debd256d JB |
5928 | line_ptr = lh->statement_program_start; |
5929 | line_end = lh->statement_program_end; | |
c906108c SS |
5930 | |
5931 | /* Read the statement sequences until there's nothing left. */ | |
5932 | while (line_ptr < line_end) | |
5933 | { | |
5934 | /* state machine registers */ | |
5935 | CORE_ADDR address = 0; | |
5936 | unsigned int file = 1; | |
5937 | unsigned int line = 1; | |
5938 | unsigned int column = 0; | |
debd256d | 5939 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
5940 | int basic_block = 0; |
5941 | int end_sequence = 0; | |
5942 | ||
aaa75496 | 5943 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 5944 | { |
aaa75496 | 5945 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
5946 | /* lh->include_dirs and lh->file_names are 0-based, but the |
5947 | directory and file name numbers in the statement program | |
5948 | are 1-based. */ | |
5949 | struct file_entry *fe = &lh->file_names[file - 1]; | |
5950 | char *dir; | |
5951 | if (fe->dir_index) | |
5952 | dir = lh->include_dirs[fe->dir_index - 1]; | |
5953 | else | |
5954 | dir = comp_dir; | |
5955 | dwarf2_start_subfile (fe->name, dir); | |
c906108c SS |
5956 | } |
5957 | ||
5958 | /* Decode the table. */ | |
c5aa993b | 5959 | while (!end_sequence) |
c906108c SS |
5960 | { |
5961 | op_code = read_1_byte (abfd, line_ptr); | |
5962 | line_ptr += 1; | |
9aa1fe7e | 5963 | |
debd256d | 5964 | if (op_code >= lh->opcode_base) |
9aa1fe7e | 5965 | { /* Special operand. */ |
debd256d JB |
5966 | adj_opcode = op_code - lh->opcode_base; |
5967 | address += (adj_opcode / lh->line_range) | |
5968 | * lh->minimum_instruction_length; | |
5969 | line += lh->line_base + (adj_opcode % lh->line_range); | |
aaa75496 JB |
5970 | if (!decode_for_pst_p) |
5971 | { | |
5972 | /* append row to matrix using current values */ | |
5973 | record_line (current_subfile, line, | |
5974 | check_cu_functions (address, cu)); | |
5975 | } | |
9aa1fe7e GK |
5976 | basic_block = 1; |
5977 | } | |
5978 | else switch (op_code) | |
c906108c SS |
5979 | { |
5980 | case DW_LNS_extended_op: | |
5981 | line_ptr += 1; /* ignore length */ | |
5982 | extended_op = read_1_byte (abfd, line_ptr); | |
5983 | line_ptr += 1; | |
5984 | switch (extended_op) | |
5985 | { | |
5986 | case DW_LNE_end_sequence: | |
5987 | end_sequence = 1; | |
aaa75496 JB |
5988 | if (!decode_for_pst_p) |
5989 | record_line (current_subfile, 0, address); | |
c906108c SS |
5990 | break; |
5991 | case DW_LNE_set_address: | |
e7c27a73 | 5992 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
5993 | line_ptr += bytes_read; |
5994 | address += baseaddr; | |
c906108c SS |
5995 | break; |
5996 | case DW_LNE_define_file: | |
debd256d JB |
5997 | { |
5998 | char *cur_file; | |
5999 | unsigned int dir_index, mod_time, length; | |
6000 | ||
6001 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
6002 | line_ptr += bytes_read; | |
6003 | dir_index = | |
6004 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6005 | line_ptr += bytes_read; | |
6006 | mod_time = | |
6007 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6008 | line_ptr += bytes_read; | |
6009 | length = | |
6010 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6011 | line_ptr += bytes_read; | |
6012 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6013 | } | |
c906108c SS |
6014 | break; |
6015 | default: | |
4d3c2250 KB |
6016 | complaint (&symfile_complaints, |
6017 | "mangled .debug_line section"); | |
debd256d | 6018 | return; |
c906108c SS |
6019 | } |
6020 | break; | |
6021 | case DW_LNS_copy: | |
aaa75496 JB |
6022 | if (!decode_for_pst_p) |
6023 | record_line (current_subfile, line, | |
6024 | check_cu_functions (address, cu)); | |
c906108c SS |
6025 | basic_block = 0; |
6026 | break; | |
6027 | case DW_LNS_advance_pc: | |
debd256d | 6028 | address += lh->minimum_instruction_length |
c906108c SS |
6029 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
6030 | line_ptr += bytes_read; | |
6031 | break; | |
6032 | case DW_LNS_advance_line: | |
6033 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
6034 | line_ptr += bytes_read; | |
6035 | break; | |
6036 | case DW_LNS_set_file: | |
debd256d JB |
6037 | { |
6038 | /* lh->include_dirs and lh->file_names are 0-based, | |
6039 | but the directory and file name numbers in the | |
6040 | statement program are 1-based. */ | |
6041 | struct file_entry *fe; | |
6042 | char *dir; | |
6043 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6044 | line_ptr += bytes_read; | |
6045 | fe = &lh->file_names[file - 1]; | |
aaa75496 | 6046 | fe->included_p = 1; |
debd256d JB |
6047 | if (fe->dir_index) |
6048 | dir = lh->include_dirs[fe->dir_index - 1]; | |
6049 | else | |
6050 | dir = comp_dir; | |
aaa75496 JB |
6051 | if (!decode_for_pst_p) |
6052 | dwarf2_start_subfile (fe->name, dir); | |
debd256d | 6053 | } |
c906108c SS |
6054 | break; |
6055 | case DW_LNS_set_column: | |
6056 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6057 | line_ptr += bytes_read; | |
6058 | break; | |
6059 | case DW_LNS_negate_stmt: | |
6060 | is_stmt = (!is_stmt); | |
6061 | break; | |
6062 | case DW_LNS_set_basic_block: | |
6063 | basic_block = 1; | |
6064 | break; | |
c2c6d25f JM |
6065 | /* Add to the address register of the state machine the |
6066 | address increment value corresponding to special opcode | |
6067 | 255. Ie, this value is scaled by the minimum instruction | |
6068 | length since special opcode 255 would have scaled the | |
6069 | the increment. */ | |
c906108c | 6070 | case DW_LNS_const_add_pc: |
debd256d JB |
6071 | address += (lh->minimum_instruction_length |
6072 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
6073 | break; |
6074 | case DW_LNS_fixed_advance_pc: | |
6075 | address += read_2_bytes (abfd, line_ptr); | |
6076 | line_ptr += 2; | |
6077 | break; | |
9aa1fe7e GK |
6078 | default: |
6079 | { /* Unknown standard opcode, ignore it. */ | |
6080 | int i; | |
debd256d | 6081 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
6082 | { |
6083 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6084 | line_ptr += bytes_read; | |
6085 | } | |
6086 | } | |
c906108c SS |
6087 | } |
6088 | } | |
6089 | } | |
aaa75496 JB |
6090 | |
6091 | if (decode_for_pst_p) | |
6092 | { | |
6093 | int file_index; | |
6094 | ||
6095 | /* Now that we're done scanning the Line Header Program, we can | |
6096 | create the psymtab of each included file. */ | |
6097 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
6098 | if (lh->file_names[file_index].included_p == 1) | |
6099 | { | |
6100 | char *include_name = lh->file_names [file_index].name; | |
6101 | ||
6102 | if (strcmp (include_name, pst->filename) != 0) | |
6103 | dwarf2_create_include_psymtab (include_name, pst, objfile); | |
6104 | } | |
6105 | } | |
c906108c SS |
6106 | } |
6107 | ||
6108 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
6109 | DIRNAME the name of the source directory which contains FILENAME | |
6110 | or NULL if not known. | |
6111 | This routine tries to keep line numbers from identical absolute and | |
6112 | relative file names in a common subfile. | |
6113 | ||
6114 | Using the `list' example from the GDB testsuite, which resides in | |
6115 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
6116 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
6117 | ||
c5aa993b JM |
6118 | DW_AT_name: /srcdir/list0.c |
6119 | DW_AT_comp_dir: /compdir | |
357e46e7 | 6120 | files.files[0].name: list0.h |
c5aa993b | 6121 | files.files[0].dir: /srcdir |
357e46e7 | 6122 | files.files[1].name: list0.c |
c5aa993b | 6123 | files.files[1].dir: /srcdir |
c906108c SS |
6124 | |
6125 | The line number information for list0.c has to end up in a single | |
6126 | subfile, so that `break /srcdir/list0.c:1' works as expected. */ | |
6127 | ||
6128 | static void | |
fba45db2 | 6129 | dwarf2_start_subfile (char *filename, char *dirname) |
c906108c SS |
6130 | { |
6131 | /* If the filename isn't absolute, try to match an existing subfile | |
6132 | with the full pathname. */ | |
6133 | ||
d5166ae1 | 6134 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
c906108c SS |
6135 | { |
6136 | struct subfile *subfile; | |
6137 | char *fullname = concat (dirname, "/", filename, NULL); | |
6138 | ||
6139 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
6140 | { | |
d5166ae1 | 6141 | if (FILENAME_CMP (subfile->name, fullname) == 0) |
c906108c SS |
6142 | { |
6143 | current_subfile = subfile; | |
b8c9b27d | 6144 | xfree (fullname); |
c906108c SS |
6145 | return; |
6146 | } | |
6147 | } | |
b8c9b27d | 6148 | xfree (fullname); |
c906108c SS |
6149 | } |
6150 | start_subfile (filename, dirname); | |
6151 | } | |
6152 | ||
4c2df51b DJ |
6153 | static void |
6154 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 6155 | struct dwarf2_cu *cu) |
4c2df51b | 6156 | { |
e7c27a73 DJ |
6157 | struct objfile *objfile = cu->objfile; |
6158 | struct comp_unit_head *cu_header = &cu->header; | |
6159 | ||
4c2df51b DJ |
6160 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
6161 | code here to turn a symbol with DW_AT_external and a | |
6162 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
6163 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
6164 | with some versions of binutils) where shared libraries could have | |
6165 | relocations against symbols in their debug information - the | |
6166 | minimal symbol would have the right address, but the debug info | |
6167 | would not. It's no longer necessary, because we will explicitly | |
6168 | apply relocations when we read in the debug information now. */ | |
6169 | ||
6170 | /* A DW_AT_location attribute with no contents indicates that a | |
6171 | variable has been optimized away. */ | |
6172 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
6173 | { | |
6174 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
6175 | return; | |
6176 | } | |
6177 | ||
6178 | /* Handle one degenerate form of location expression specially, to | |
6179 | preserve GDB's previous behavior when section offsets are | |
6180 | specified. If this is just a DW_OP_addr then mark this symbol | |
6181 | as LOC_STATIC. */ | |
6182 | ||
6183 | if (attr_form_is_block (attr) | |
6184 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
6185 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
6186 | { | |
6187 | int dummy; | |
6188 | ||
6189 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 6190 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
4c2df51b DJ |
6191 | fixup_symbol_section (sym, objfile); |
6192 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
6193 | SYMBOL_SECTION (sym)); | |
6194 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
6195 | return; | |
6196 | } | |
6197 | ||
6198 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
6199 | expression evaluator, and use LOC_COMPUTED only when necessary | |
6200 | (i.e. when the value of a register or memory location is | |
6201 | referenced, or a thread-local block, etc.). Then again, it might | |
6202 | not be worthwhile. I'm assuming that it isn't unless performance | |
6203 | or memory numbers show me otherwise. */ | |
6204 | ||
e7c27a73 | 6205 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
6206 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
6207 | } | |
6208 | ||
c906108c SS |
6209 | /* Given a pointer to a DWARF information entry, figure out if we need |
6210 | to make a symbol table entry for it, and if so, create a new entry | |
6211 | and return a pointer to it. | |
6212 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 6213 | used the passed type. */ |
c906108c SS |
6214 | |
6215 | static struct symbol * | |
e7c27a73 | 6216 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 6217 | { |
e7c27a73 | 6218 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6219 | struct symbol *sym = NULL; |
6220 | char *name; | |
6221 | struct attribute *attr = NULL; | |
6222 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
6223 | CORE_ADDR baseaddr; |
6224 | ||
6225 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6226 | |
5c4e30ca | 6227 | if (die->tag != DW_TAG_namespace) |
e142c38c | 6228 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
6229 | else |
6230 | name = TYPE_NAME (type); | |
6231 | ||
c906108c SS |
6232 | if (name) |
6233 | { | |
4a146b47 | 6234 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
6235 | sizeof (struct symbol)); |
6236 | OBJSTAT (objfile, n_syms++); | |
6237 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
6238 | |
6239 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 6240 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 6241 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
6242 | |
6243 | /* Default assumptions. | |
c5aa993b | 6244 | Use the passed type or decode it from the die. */ |
176620f1 | 6245 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
c906108c SS |
6246 | SYMBOL_CLASS (sym) = LOC_STATIC; |
6247 | if (type != NULL) | |
6248 | SYMBOL_TYPE (sym) = type; | |
6249 | else | |
e7c27a73 | 6250 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 6251 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
6252 | if (attr) |
6253 | { | |
6254 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
6255 | } | |
c906108c SS |
6256 | switch (die->tag) |
6257 | { | |
6258 | case DW_TAG_label: | |
e142c38c | 6259 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
6260 | if (attr) |
6261 | { | |
6262 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
6263 | } | |
6264 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
6265 | break; | |
6266 | case DW_TAG_subprogram: | |
6267 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
6268 | finish_block. */ | |
6269 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 6270 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6271 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6272 | { | |
6273 | add_symbol_to_list (sym, &global_symbols); | |
6274 | } | |
6275 | else | |
6276 | { | |
e142c38c | 6277 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6278 | } |
6279 | break; | |
6280 | case DW_TAG_variable: | |
6281 | /* Compilation with minimal debug info may result in variables | |
6282 | with missing type entries. Change the misleading `void' type | |
6283 | to something sensible. */ | |
6284 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
6285 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, | |
6286 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
6287 | "<variable, no debug info>", | |
6288 | objfile); | |
e142c38c | 6289 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6290 | if (attr) |
6291 | { | |
e7c27a73 | 6292 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 6293 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6294 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6295 | add_symbol_to_list (sym, &global_symbols); | |
6296 | else | |
e142c38c | 6297 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6298 | break; |
6299 | } | |
e142c38c | 6300 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6301 | if (attr) |
6302 | { | |
e7c27a73 | 6303 | var_decode_location (attr, sym, cu); |
e142c38c | 6304 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6305 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 6306 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 6307 | else |
e142c38c | 6308 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6309 | } |
6310 | else | |
6311 | { | |
6312 | /* We do not know the address of this symbol. | |
c5aa993b JM |
6313 | If it is an external symbol and we have type information |
6314 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
6315 | The address of the variable will then be determined from | |
6316 | the minimal symbol table whenever the variable is | |
6317 | referenced. */ | |
e142c38c | 6318 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6319 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 6320 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
6321 | { |
6322 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
6323 | add_symbol_to_list (sym, &global_symbols); | |
6324 | } | |
6325 | } | |
6326 | break; | |
6327 | case DW_TAG_formal_parameter: | |
e142c38c | 6328 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6329 | if (attr) |
6330 | { | |
e7c27a73 | 6331 | var_decode_location (attr, sym, cu); |
7cf6e574 DJ |
6332 | /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ |
6333 | if (SYMBOL_CLASS (sym) == LOC_COMPUTED) | |
6334 | SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; | |
c906108c | 6335 | } |
e142c38c | 6336 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6337 | if (attr) |
6338 | { | |
e7c27a73 | 6339 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6340 | } |
e142c38c | 6341 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6342 | break; |
6343 | case DW_TAG_unspecified_parameters: | |
6344 | /* From varargs functions; gdb doesn't seem to have any | |
6345 | interest in this information, so just ignore it for now. | |
6346 | (FIXME?) */ | |
6347 | break; | |
6348 | case DW_TAG_class_type: | |
6349 | case DW_TAG_structure_type: | |
6350 | case DW_TAG_union_type: | |
6351 | case DW_TAG_enumeration_type: | |
6352 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 6353 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 6354 | |
63d06c5c DC |
6355 | /* Make sure that the symbol includes appropriate enclosing |
6356 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 6357 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
6358 | the type. */ |
6359 | ||
e142c38c | 6360 | if (cu->language == language_cplus) |
c906108c | 6361 | { |
63d06c5c DC |
6362 | struct type *type = SYMBOL_TYPE (sym); |
6363 | ||
6364 | if (TYPE_TAG_NAME (type) != NULL) | |
6365 | { | |
6366 | /* FIXME: carlton/2003-11-10: Should this use | |
6367 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
6368 | arises further down in this function.) */ |
6369 | /* The type's name is already allocated along with | |
6370 | this objfile, so we don't need to duplicate it | |
6371 | for the symbol. */ | |
6372 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 6373 | } |
c906108c | 6374 | } |
63d06c5c DC |
6375 | |
6376 | { | |
6377 | /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't | |
6378 | really ever be static objects: otherwise, if you try | |
6379 | to, say, break of a class's method and you're in a file | |
6380 | which doesn't mention that class, it won't work unless | |
6381 | the check for all static symbols in lookup_symbol_aux | |
6382 | saves you. See the OtherFileClass tests in | |
6383 | gdb.c++/namespace.exp. */ | |
6384 | ||
6385 | struct pending **list_to_add; | |
6386 | ||
e142c38c DJ |
6387 | list_to_add = (cu->list_in_scope == &file_symbols |
6388 | && cu->language == language_cplus | |
6389 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6390 | |
6391 | add_symbol_to_list (sym, list_to_add); | |
6392 | ||
6393 | /* The semantics of C++ state that "struct foo { ... }" also | |
6394 | defines a typedef for "foo". Synthesize a typedef symbol so | |
6395 | that "ptype foo" works as expected. */ | |
e142c38c | 6396 | if (cu->language == language_cplus) |
63d06c5c DC |
6397 | { |
6398 | struct symbol *typedef_sym = (struct symbol *) | |
4a146b47 | 6399 | obstack_alloc (&objfile->objfile_obstack, |
63d06c5c DC |
6400 | sizeof (struct symbol)); |
6401 | *typedef_sym = *sym; | |
6402 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; | |
d8151005 DJ |
6403 | /* The symbol's name is already allocated along with |
6404 | this objfile, so we don't need to duplicate it for | |
6405 | the type. */ | |
63d06c5c | 6406 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
d8151005 | 6407 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym); |
63d06c5c DC |
6408 | add_symbol_to_list (typedef_sym, list_to_add); |
6409 | } | |
6410 | } | |
c906108c SS |
6411 | break; |
6412 | case DW_TAG_typedef: | |
63d06c5c DC |
6413 | if (processing_has_namespace_info |
6414 | && processing_current_prefix[0] != '\0') | |
6415 | { | |
4a146b47 | 6416 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6417 | processing_current_prefix, |
6418 | "::", | |
6419 | name); | |
6420 | } | |
6421 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6422 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 6423 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 6424 | break; |
c906108c | 6425 | case DW_TAG_base_type: |
a02abb62 | 6426 | case DW_TAG_subrange_type: |
c906108c | 6427 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 6428 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 6429 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6430 | break; |
6431 | case DW_TAG_enumerator: | |
63d06c5c DC |
6432 | if (processing_has_namespace_info |
6433 | && processing_current_prefix[0] != '\0') | |
6434 | { | |
4a146b47 | 6435 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6436 | processing_current_prefix, |
6437 | "::", | |
6438 | name); | |
6439 | } | |
e142c38c | 6440 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6441 | if (attr) |
6442 | { | |
e7c27a73 | 6443 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6444 | } |
63d06c5c DC |
6445 | { |
6446 | /* NOTE: carlton/2003-11-10: See comment above in the | |
6447 | DW_TAG_class_type, etc. block. */ | |
6448 | ||
6449 | struct pending **list_to_add; | |
6450 | ||
e142c38c DJ |
6451 | list_to_add = (cu->list_in_scope == &file_symbols |
6452 | && cu->language == language_cplus | |
6453 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6454 | |
6455 | add_symbol_to_list (sym, list_to_add); | |
6456 | } | |
c906108c | 6457 | break; |
5c4e30ca DC |
6458 | case DW_TAG_namespace: |
6459 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6460 | add_symbol_to_list (sym, &global_symbols); | |
6461 | break; | |
c906108c SS |
6462 | default: |
6463 | /* Not a tag we recognize. Hopefully we aren't processing | |
6464 | trash data, but since we must specifically ignore things | |
6465 | we don't recognize, there is nothing else we should do at | |
6466 | this point. */ | |
4d3c2250 KB |
6467 | complaint (&symfile_complaints, "unsupported tag: '%s'", |
6468 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6469 | break; |
6470 | } | |
6471 | } | |
6472 | return (sym); | |
6473 | } | |
6474 | ||
6475 | /* Copy constant value from an attribute to a symbol. */ | |
6476 | ||
6477 | static void | |
107d2387 | 6478 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 6479 | struct dwarf2_cu *cu) |
c906108c | 6480 | { |
e7c27a73 DJ |
6481 | struct objfile *objfile = cu->objfile; |
6482 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
6483 | struct dwarf_block *blk; |
6484 | ||
6485 | switch (attr->form) | |
6486 | { | |
6487 | case DW_FORM_addr: | |
107d2387 | 6488 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 6489 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6490 | cu_header->addr_size, |
6491 | TYPE_LENGTH (SYMBOL_TYPE | |
6492 | (sym))); | |
c906108c | 6493 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6494 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
6495 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
6496 | it's body - store_unsigned_integer. */ | |
6497 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
6498 | DW_ADDR (attr)); | |
c906108c SS |
6499 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
6500 | break; | |
6501 | case DW_FORM_block1: | |
6502 | case DW_FORM_block2: | |
6503 | case DW_FORM_block4: | |
6504 | case DW_FORM_block: | |
6505 | blk = DW_BLOCK (attr); | |
6506 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 6507 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6508 | blk->size, |
6509 | TYPE_LENGTH (SYMBOL_TYPE | |
6510 | (sym))); | |
c906108c | 6511 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6512 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
6513 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
6514 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
6515 | break; | |
2df3850c JM |
6516 | |
6517 | /* The DW_AT_const_value attributes are supposed to carry the | |
6518 | symbol's value "represented as it would be on the target | |
6519 | architecture." By the time we get here, it's already been | |
6520 | converted to host endianness, so we just need to sign- or | |
6521 | zero-extend it as appropriate. */ | |
6522 | case DW_FORM_data1: | |
6523 | dwarf2_const_value_data (attr, sym, 8); | |
6524 | break; | |
c906108c | 6525 | case DW_FORM_data2: |
2df3850c JM |
6526 | dwarf2_const_value_data (attr, sym, 16); |
6527 | break; | |
c906108c | 6528 | case DW_FORM_data4: |
2df3850c JM |
6529 | dwarf2_const_value_data (attr, sym, 32); |
6530 | break; | |
c906108c | 6531 | case DW_FORM_data8: |
2df3850c JM |
6532 | dwarf2_const_value_data (attr, sym, 64); |
6533 | break; | |
6534 | ||
c906108c | 6535 | case DW_FORM_sdata: |
2df3850c JM |
6536 | SYMBOL_VALUE (sym) = DW_SND (attr); |
6537 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6538 | break; | |
6539 | ||
c906108c SS |
6540 | case DW_FORM_udata: |
6541 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
6542 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6543 | break; | |
2df3850c | 6544 | |
c906108c | 6545 | default: |
4d3c2250 KB |
6546 | complaint (&symfile_complaints, |
6547 | "unsupported const value attribute form: '%s'", | |
6548 | dwarf_form_name (attr->form)); | |
c906108c SS |
6549 | SYMBOL_VALUE (sym) = 0; |
6550 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6551 | break; | |
6552 | } | |
6553 | } | |
6554 | ||
2df3850c JM |
6555 | |
6556 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
6557 | or zero-extend it as appropriate for the symbol's type. */ | |
6558 | static void | |
6559 | dwarf2_const_value_data (struct attribute *attr, | |
6560 | struct symbol *sym, | |
6561 | int bits) | |
6562 | { | |
6563 | LONGEST l = DW_UNSND (attr); | |
6564 | ||
6565 | if (bits < sizeof (l) * 8) | |
6566 | { | |
6567 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
6568 | l &= ((LONGEST) 1 << bits) - 1; | |
6569 | else | |
bf9198f1 | 6570 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
6571 | } |
6572 | ||
6573 | SYMBOL_VALUE (sym) = l; | |
6574 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6575 | } | |
6576 | ||
6577 | ||
c906108c SS |
6578 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
6579 | ||
6580 | static struct type * | |
e7c27a73 | 6581 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6582 | { |
6583 | struct type *type; | |
6584 | struct attribute *type_attr; | |
6585 | struct die_info *type_die; | |
6586 | unsigned int ref; | |
6587 | ||
e142c38c | 6588 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
6589 | if (!type_attr) |
6590 | { | |
6591 | /* A missing DW_AT_type represents a void type. */ | |
e142c38c | 6592 | return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); |
c906108c SS |
6593 | } |
6594 | else | |
6595 | { | |
e142c38c | 6596 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6597 | type_die = follow_die_ref (ref); |
6598 | if (!type_die) | |
6599 | { | |
659b0389 | 6600 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", |
e7c27a73 | 6601 | ref, cu->objfile->name); |
c906108c SS |
6602 | return NULL; |
6603 | } | |
6604 | } | |
e7c27a73 | 6605 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6606 | if (!type) |
6607 | { | |
6608 | dump_die (type_die); | |
659b0389 | 6609 | error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", |
e7c27a73 | 6610 | cu->objfile->name); |
c906108c SS |
6611 | } |
6612 | return type; | |
6613 | } | |
6614 | ||
6615 | /* Return the containing type of the die in question using its | |
6616 | DW_AT_containing_type attribute. */ | |
6617 | ||
6618 | static struct type * | |
e7c27a73 | 6619 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6620 | { |
6621 | struct type *type = NULL; | |
6622 | struct attribute *type_attr; | |
6623 | struct die_info *type_die = NULL; | |
6624 | unsigned int ref; | |
6625 | ||
e142c38c | 6626 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
6627 | if (type_attr) |
6628 | { | |
e142c38c | 6629 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6630 | type_die = follow_die_ref (ref); |
6631 | if (!type_die) | |
6632 | { | |
659b0389 | 6633 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, |
e7c27a73 | 6634 | cu->objfile->name); |
c906108c SS |
6635 | return NULL; |
6636 | } | |
e7c27a73 | 6637 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6638 | } |
6639 | if (!type) | |
6640 | { | |
6641 | if (type_die) | |
6642 | dump_die (type_die); | |
659b0389 | 6643 | error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", |
e7c27a73 | 6644 | cu->objfile->name); |
c906108c SS |
6645 | } |
6646 | return type; | |
6647 | } | |
6648 | ||
6649 | #if 0 | |
6650 | static struct type * | |
e7c27a73 | 6651 | type_at_offset (unsigned int offset, struct dwarf2_cu *cu) |
c906108c SS |
6652 | { |
6653 | struct die_info *die; | |
6654 | struct type *type; | |
6655 | ||
6656 | die = follow_die_ref (offset); | |
6657 | if (!die) | |
6658 | { | |
6659 | error ("Dwarf Error: Cannot find type referent at offset %d.", offset); | |
6660 | return NULL; | |
6661 | } | |
e7c27a73 | 6662 | type = tag_type_to_type (die, cu); |
c906108c SS |
6663 | return type; |
6664 | } | |
6665 | #endif | |
6666 | ||
6667 | static struct type * | |
e7c27a73 | 6668 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6669 | { |
6670 | if (die->type) | |
6671 | { | |
6672 | return die->type; | |
6673 | } | |
6674 | else | |
6675 | { | |
e7c27a73 | 6676 | read_type_die (die, cu); |
c906108c SS |
6677 | if (!die->type) |
6678 | { | |
6679 | dump_die (die); | |
659b0389 | 6680 | error ("Dwarf Error: Cannot find type of die [in module %s]", |
e7c27a73 | 6681 | cu->objfile->name); |
c906108c SS |
6682 | } |
6683 | return die->type; | |
6684 | } | |
6685 | } | |
6686 | ||
6687 | static void | |
e7c27a73 | 6688 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6689 | { |
e142c38c | 6690 | char *prefix = determine_prefix (die, cu); |
63d06c5c DC |
6691 | const char *old_prefix = processing_current_prefix; |
6692 | struct cleanup *back_to = make_cleanup (xfree, prefix); | |
6693 | processing_current_prefix = prefix; | |
6694 | ||
c906108c SS |
6695 | switch (die->tag) |
6696 | { | |
6697 | case DW_TAG_class_type: | |
6698 | case DW_TAG_structure_type: | |
6699 | case DW_TAG_union_type: | |
134d01f1 | 6700 | read_structure_type (die, cu); |
c906108c SS |
6701 | break; |
6702 | case DW_TAG_enumeration_type: | |
134d01f1 | 6703 | read_enumeration_type (die, cu); |
c906108c SS |
6704 | break; |
6705 | case DW_TAG_subprogram: | |
6706 | case DW_TAG_subroutine_type: | |
e7c27a73 | 6707 | read_subroutine_type (die, cu); |
c906108c SS |
6708 | break; |
6709 | case DW_TAG_array_type: | |
e7c27a73 | 6710 | read_array_type (die, cu); |
c906108c SS |
6711 | break; |
6712 | case DW_TAG_pointer_type: | |
e7c27a73 | 6713 | read_tag_pointer_type (die, cu); |
c906108c SS |
6714 | break; |
6715 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 6716 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
6717 | break; |
6718 | case DW_TAG_reference_type: | |
e7c27a73 | 6719 | read_tag_reference_type (die, cu); |
c906108c SS |
6720 | break; |
6721 | case DW_TAG_const_type: | |
e7c27a73 | 6722 | read_tag_const_type (die, cu); |
c906108c SS |
6723 | break; |
6724 | case DW_TAG_volatile_type: | |
e7c27a73 | 6725 | read_tag_volatile_type (die, cu); |
c906108c SS |
6726 | break; |
6727 | case DW_TAG_string_type: | |
e7c27a73 | 6728 | read_tag_string_type (die, cu); |
c906108c SS |
6729 | break; |
6730 | case DW_TAG_typedef: | |
e7c27a73 | 6731 | read_typedef (die, cu); |
c906108c | 6732 | break; |
a02abb62 JB |
6733 | case DW_TAG_subrange_type: |
6734 | read_subrange_type (die, cu); | |
6735 | break; | |
c906108c | 6736 | case DW_TAG_base_type: |
e7c27a73 | 6737 | read_base_type (die, cu); |
c906108c SS |
6738 | break; |
6739 | default: | |
4d3c2250 KB |
6740 | complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", |
6741 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6742 | break; |
6743 | } | |
63d06c5c DC |
6744 | |
6745 | processing_current_prefix = old_prefix; | |
6746 | do_cleanups (back_to); | |
6747 | } | |
6748 | ||
fdde2d81 DC |
6749 | /* Return the name of the namespace/class that DIE is defined within, |
6750 | or "" if we can't tell. The caller should xfree the result. */ | |
6751 | ||
6752 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
6753 | therein) for an example of how to use this function to deal with | |
6754 | DW_AT_specification. */ | |
6755 | ||
6756 | static char * | |
e142c38c | 6757 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
6758 | { |
6759 | struct die_info *parent; | |
6760 | ||
e142c38c | 6761 | if (cu->language != language_cplus) |
63d06c5c DC |
6762 | return NULL; |
6763 | ||
6764 | parent = die->parent; | |
6765 | ||
6766 | if (parent == NULL) | |
6767 | { | |
8176b9b8 | 6768 | return xstrdup (""); |
63d06c5c DC |
6769 | } |
6770 | else | |
6771 | { | |
63d06c5c DC |
6772 | switch (parent->tag) { |
6773 | case DW_TAG_namespace: | |
6774 | { | |
8176b9b8 DC |
6775 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
6776 | before doing this check? */ | |
6777 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) | |
6778 | { | |
6779 | return xstrdup (TYPE_TAG_NAME (parent->type)); | |
6780 | } | |
6781 | else | |
6782 | { | |
6783 | int dummy; | |
6784 | char *parent_prefix = determine_prefix (parent, cu); | |
6785 | char *retval = typename_concat (parent_prefix, | |
6786 | namespace_name (parent, &dummy, | |
6787 | cu)); | |
6788 | xfree (parent_prefix); | |
6789 | return retval; | |
6790 | } | |
63d06c5c DC |
6791 | } |
6792 | break; | |
6793 | case DW_TAG_class_type: | |
6794 | case DW_TAG_structure_type: | |
6795 | { | |
8176b9b8 | 6796 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) |
63d06c5c | 6797 | { |
8176b9b8 | 6798 | return xstrdup (TYPE_TAG_NAME (parent->type)); |
63d06c5c DC |
6799 | } |
6800 | else | |
8176b9b8 DC |
6801 | { |
6802 | const char *old_prefix = processing_current_prefix; | |
6803 | char *new_prefix = determine_prefix (parent, cu); | |
6804 | char *retval; | |
6805 | ||
6806 | processing_current_prefix = new_prefix; | |
6807 | retval = determine_class_name (parent, cu); | |
6808 | processing_current_prefix = old_prefix; | |
6809 | ||
6810 | xfree (new_prefix); | |
6811 | return retval; | |
6812 | } | |
63d06c5c | 6813 | } |
63d06c5c | 6814 | default: |
8176b9b8 | 6815 | return determine_prefix (parent, cu); |
63d06c5c | 6816 | } |
63d06c5c DC |
6817 | } |
6818 | } | |
6819 | ||
6820 | /* Return a newly-allocated string formed by concatenating PREFIX, | |
6821 | "::", and SUFFIX, except that if PREFIX is NULL or the empty | |
6822 | string, just return a copy of SUFFIX. */ | |
6823 | ||
6824 | static char * | |
6825 | typename_concat (const char *prefix, const char *suffix) | |
6826 | { | |
6827 | if (prefix == NULL || prefix[0] == '\0') | |
6828 | return xstrdup (suffix); | |
6829 | else | |
6830 | { | |
6831 | char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1); | |
6832 | ||
6833 | strcpy (retval, prefix); | |
6834 | strcat (retval, "::"); | |
6835 | strcat (retval, suffix); | |
6836 | ||
6837 | return retval; | |
6838 | } | |
6839 | } | |
6840 | ||
c906108c | 6841 | static struct type * |
e7c27a73 | 6842 | dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) |
c906108c | 6843 | { |
e7c27a73 DJ |
6844 | struct objfile *objfile = cu->objfile; |
6845 | ||
c906108c SS |
6846 | /* FIXME - this should not produce a new (struct type *) |
6847 | every time. It should cache base types. */ | |
6848 | struct type *type; | |
6849 | switch (encoding) | |
6850 | { | |
6851 | case DW_ATE_address: | |
e142c38c | 6852 | type = dwarf2_fundamental_type (objfile, FT_VOID, cu); |
c906108c SS |
6853 | return type; |
6854 | case DW_ATE_boolean: | |
e142c38c | 6855 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); |
c906108c SS |
6856 | return type; |
6857 | case DW_ATE_complex_float: | |
6858 | if (size == 16) | |
6859 | { | |
e142c38c | 6860 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); |
c906108c SS |
6861 | } |
6862 | else | |
6863 | { | |
e142c38c | 6864 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); |
c906108c SS |
6865 | } |
6866 | return type; | |
6867 | case DW_ATE_float: | |
6868 | if (size == 8) | |
6869 | { | |
e142c38c | 6870 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
c906108c SS |
6871 | } |
6872 | else | |
6873 | { | |
e142c38c | 6874 | type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
c906108c SS |
6875 | } |
6876 | return type; | |
6877 | case DW_ATE_signed: | |
6878 | switch (size) | |
6879 | { | |
6880 | case 1: | |
e142c38c | 6881 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6882 | break; |
6883 | case 2: | |
e142c38c | 6884 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); |
c906108c SS |
6885 | break; |
6886 | default: | |
6887 | case 4: | |
e142c38c | 6888 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6889 | break; |
6890 | } | |
6891 | return type; | |
6892 | case DW_ATE_signed_char: | |
e142c38c | 6893 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6894 | return type; |
6895 | case DW_ATE_unsigned: | |
6896 | switch (size) | |
6897 | { | |
6898 | case 1: | |
e142c38c | 6899 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6900 | break; |
6901 | case 2: | |
e142c38c | 6902 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); |
c906108c SS |
6903 | break; |
6904 | default: | |
6905 | case 4: | |
e142c38c | 6906 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); |
c906108c SS |
6907 | break; |
6908 | } | |
6909 | return type; | |
6910 | case DW_ATE_unsigned_char: | |
e142c38c | 6911 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6912 | return type; |
6913 | default: | |
e142c38c | 6914 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6915 | return type; |
6916 | } | |
6917 | } | |
6918 | ||
6919 | #if 0 | |
6920 | struct die_info * | |
fba45db2 | 6921 | copy_die (struct die_info *old_die) |
c906108c SS |
6922 | { |
6923 | struct die_info *new_die; | |
6924 | int i, num_attrs; | |
6925 | ||
6926 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
6927 | memset (new_die, 0, sizeof (struct die_info)); | |
6928 | ||
6929 | new_die->tag = old_die->tag; | |
6930 | new_die->has_children = old_die->has_children; | |
6931 | new_die->abbrev = old_die->abbrev; | |
6932 | new_die->offset = old_die->offset; | |
6933 | new_die->type = NULL; | |
6934 | ||
6935 | num_attrs = old_die->num_attrs; | |
6936 | new_die->num_attrs = num_attrs; | |
6937 | new_die->attrs = (struct attribute *) | |
6938 | xmalloc (num_attrs * sizeof (struct attribute)); | |
6939 | ||
6940 | for (i = 0; i < old_die->num_attrs; ++i) | |
6941 | { | |
6942 | new_die->attrs[i].name = old_die->attrs[i].name; | |
6943 | new_die->attrs[i].form = old_die->attrs[i].form; | |
6944 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
6945 | } | |
6946 | ||
6947 | new_die->next = NULL; | |
6948 | return new_die; | |
6949 | } | |
6950 | #endif | |
6951 | ||
6952 | /* Return sibling of die, NULL if no sibling. */ | |
6953 | ||
f9aca02d | 6954 | static struct die_info * |
fba45db2 | 6955 | sibling_die (struct die_info *die) |
c906108c | 6956 | { |
639d11d3 | 6957 | return die->sibling; |
c906108c SS |
6958 | } |
6959 | ||
6960 | /* Get linkage name of a die, return NULL if not found. */ | |
6961 | ||
6962 | static char * | |
e142c38c | 6963 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6964 | { |
6965 | struct attribute *attr; | |
6966 | ||
e142c38c | 6967 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
6968 | if (attr && DW_STRING (attr)) |
6969 | return DW_STRING (attr); | |
e142c38c | 6970 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
6971 | if (attr && DW_STRING (attr)) |
6972 | return DW_STRING (attr); | |
6973 | return NULL; | |
6974 | } | |
6975 | ||
9219021c DC |
6976 | /* Get name of a die, return NULL if not found. */ |
6977 | ||
6978 | static char * | |
e142c38c | 6979 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
6980 | { |
6981 | struct attribute *attr; | |
6982 | ||
e142c38c | 6983 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
6984 | if (attr && DW_STRING (attr)) |
6985 | return DW_STRING (attr); | |
6986 | return NULL; | |
6987 | } | |
6988 | ||
6989 | /* Return the die that this die in an extension of, or NULL if there | |
6990 | is none. */ | |
6991 | ||
6992 | static struct die_info * | |
e142c38c | 6993 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
6994 | { |
6995 | struct attribute *attr; | |
6996 | struct die_info *extension_die; | |
6997 | unsigned int ref; | |
6998 | ||
e142c38c | 6999 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
7000 | if (attr == NULL) |
7001 | return NULL; | |
7002 | ||
e142c38c | 7003 | ref = dwarf2_get_ref_die_offset (attr, cu); |
9219021c DC |
7004 | extension_die = follow_die_ref (ref); |
7005 | if (!extension_die) | |
7006 | { | |
7007 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); | |
7008 | } | |
7009 | ||
7010 | return extension_die; | |
7011 | } | |
7012 | ||
c906108c SS |
7013 | /* Convert a DIE tag into its string name. */ |
7014 | ||
7015 | static char * | |
aa1ee363 | 7016 | dwarf_tag_name (unsigned tag) |
c906108c SS |
7017 | { |
7018 | switch (tag) | |
7019 | { | |
7020 | case DW_TAG_padding: | |
7021 | return "DW_TAG_padding"; | |
7022 | case DW_TAG_array_type: | |
7023 | return "DW_TAG_array_type"; | |
7024 | case DW_TAG_class_type: | |
7025 | return "DW_TAG_class_type"; | |
7026 | case DW_TAG_entry_point: | |
7027 | return "DW_TAG_entry_point"; | |
7028 | case DW_TAG_enumeration_type: | |
7029 | return "DW_TAG_enumeration_type"; | |
7030 | case DW_TAG_formal_parameter: | |
7031 | return "DW_TAG_formal_parameter"; | |
7032 | case DW_TAG_imported_declaration: | |
7033 | return "DW_TAG_imported_declaration"; | |
7034 | case DW_TAG_label: | |
7035 | return "DW_TAG_label"; | |
7036 | case DW_TAG_lexical_block: | |
7037 | return "DW_TAG_lexical_block"; | |
7038 | case DW_TAG_member: | |
7039 | return "DW_TAG_member"; | |
7040 | case DW_TAG_pointer_type: | |
7041 | return "DW_TAG_pointer_type"; | |
7042 | case DW_TAG_reference_type: | |
7043 | return "DW_TAG_reference_type"; | |
7044 | case DW_TAG_compile_unit: | |
7045 | return "DW_TAG_compile_unit"; | |
7046 | case DW_TAG_string_type: | |
7047 | return "DW_TAG_string_type"; | |
7048 | case DW_TAG_structure_type: | |
7049 | return "DW_TAG_structure_type"; | |
7050 | case DW_TAG_subroutine_type: | |
7051 | return "DW_TAG_subroutine_type"; | |
7052 | case DW_TAG_typedef: | |
7053 | return "DW_TAG_typedef"; | |
7054 | case DW_TAG_union_type: | |
7055 | return "DW_TAG_union_type"; | |
7056 | case DW_TAG_unspecified_parameters: | |
7057 | return "DW_TAG_unspecified_parameters"; | |
7058 | case DW_TAG_variant: | |
7059 | return "DW_TAG_variant"; | |
7060 | case DW_TAG_common_block: | |
7061 | return "DW_TAG_common_block"; | |
7062 | case DW_TAG_common_inclusion: | |
7063 | return "DW_TAG_common_inclusion"; | |
7064 | case DW_TAG_inheritance: | |
7065 | return "DW_TAG_inheritance"; | |
7066 | case DW_TAG_inlined_subroutine: | |
7067 | return "DW_TAG_inlined_subroutine"; | |
7068 | case DW_TAG_module: | |
7069 | return "DW_TAG_module"; | |
7070 | case DW_TAG_ptr_to_member_type: | |
7071 | return "DW_TAG_ptr_to_member_type"; | |
7072 | case DW_TAG_set_type: | |
7073 | return "DW_TAG_set_type"; | |
7074 | case DW_TAG_subrange_type: | |
7075 | return "DW_TAG_subrange_type"; | |
7076 | case DW_TAG_with_stmt: | |
7077 | return "DW_TAG_with_stmt"; | |
7078 | case DW_TAG_access_declaration: | |
7079 | return "DW_TAG_access_declaration"; | |
7080 | case DW_TAG_base_type: | |
7081 | return "DW_TAG_base_type"; | |
7082 | case DW_TAG_catch_block: | |
7083 | return "DW_TAG_catch_block"; | |
7084 | case DW_TAG_const_type: | |
7085 | return "DW_TAG_const_type"; | |
7086 | case DW_TAG_constant: | |
7087 | return "DW_TAG_constant"; | |
7088 | case DW_TAG_enumerator: | |
7089 | return "DW_TAG_enumerator"; | |
7090 | case DW_TAG_file_type: | |
7091 | return "DW_TAG_file_type"; | |
7092 | case DW_TAG_friend: | |
7093 | return "DW_TAG_friend"; | |
7094 | case DW_TAG_namelist: | |
7095 | return "DW_TAG_namelist"; | |
7096 | case DW_TAG_namelist_item: | |
7097 | return "DW_TAG_namelist_item"; | |
7098 | case DW_TAG_packed_type: | |
7099 | return "DW_TAG_packed_type"; | |
7100 | case DW_TAG_subprogram: | |
7101 | return "DW_TAG_subprogram"; | |
7102 | case DW_TAG_template_type_param: | |
7103 | return "DW_TAG_template_type_param"; | |
7104 | case DW_TAG_template_value_param: | |
7105 | return "DW_TAG_template_value_param"; | |
7106 | case DW_TAG_thrown_type: | |
7107 | return "DW_TAG_thrown_type"; | |
7108 | case DW_TAG_try_block: | |
7109 | return "DW_TAG_try_block"; | |
7110 | case DW_TAG_variant_part: | |
7111 | return "DW_TAG_variant_part"; | |
7112 | case DW_TAG_variable: | |
7113 | return "DW_TAG_variable"; | |
7114 | case DW_TAG_volatile_type: | |
7115 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
7116 | case DW_TAG_dwarf_procedure: |
7117 | return "DW_TAG_dwarf_procedure"; | |
7118 | case DW_TAG_restrict_type: | |
7119 | return "DW_TAG_restrict_type"; | |
7120 | case DW_TAG_interface_type: | |
7121 | return "DW_TAG_interface_type"; | |
7122 | case DW_TAG_namespace: | |
7123 | return "DW_TAG_namespace"; | |
7124 | case DW_TAG_imported_module: | |
7125 | return "DW_TAG_imported_module"; | |
7126 | case DW_TAG_unspecified_type: | |
7127 | return "DW_TAG_unspecified_type"; | |
7128 | case DW_TAG_partial_unit: | |
7129 | return "DW_TAG_partial_unit"; | |
7130 | case DW_TAG_imported_unit: | |
7131 | return "DW_TAG_imported_unit"; | |
c906108c SS |
7132 | case DW_TAG_MIPS_loop: |
7133 | return "DW_TAG_MIPS_loop"; | |
7134 | case DW_TAG_format_label: | |
7135 | return "DW_TAG_format_label"; | |
7136 | case DW_TAG_function_template: | |
7137 | return "DW_TAG_function_template"; | |
7138 | case DW_TAG_class_template: | |
7139 | return "DW_TAG_class_template"; | |
7140 | default: | |
7141 | return "DW_TAG_<unknown>"; | |
7142 | } | |
7143 | } | |
7144 | ||
7145 | /* Convert a DWARF attribute code into its string name. */ | |
7146 | ||
7147 | static char * | |
aa1ee363 | 7148 | dwarf_attr_name (unsigned attr) |
c906108c SS |
7149 | { |
7150 | switch (attr) | |
7151 | { | |
7152 | case DW_AT_sibling: | |
7153 | return "DW_AT_sibling"; | |
7154 | case DW_AT_location: | |
7155 | return "DW_AT_location"; | |
7156 | case DW_AT_name: | |
7157 | return "DW_AT_name"; | |
7158 | case DW_AT_ordering: | |
7159 | return "DW_AT_ordering"; | |
7160 | case DW_AT_subscr_data: | |
7161 | return "DW_AT_subscr_data"; | |
7162 | case DW_AT_byte_size: | |
7163 | return "DW_AT_byte_size"; | |
7164 | case DW_AT_bit_offset: | |
7165 | return "DW_AT_bit_offset"; | |
7166 | case DW_AT_bit_size: | |
7167 | return "DW_AT_bit_size"; | |
7168 | case DW_AT_element_list: | |
7169 | return "DW_AT_element_list"; | |
7170 | case DW_AT_stmt_list: | |
7171 | return "DW_AT_stmt_list"; | |
7172 | case DW_AT_low_pc: | |
7173 | return "DW_AT_low_pc"; | |
7174 | case DW_AT_high_pc: | |
7175 | return "DW_AT_high_pc"; | |
7176 | case DW_AT_language: | |
7177 | return "DW_AT_language"; | |
7178 | case DW_AT_member: | |
7179 | return "DW_AT_member"; | |
7180 | case DW_AT_discr: | |
7181 | return "DW_AT_discr"; | |
7182 | case DW_AT_discr_value: | |
7183 | return "DW_AT_discr_value"; | |
7184 | case DW_AT_visibility: | |
7185 | return "DW_AT_visibility"; | |
7186 | case DW_AT_import: | |
7187 | return "DW_AT_import"; | |
7188 | case DW_AT_string_length: | |
7189 | return "DW_AT_string_length"; | |
7190 | case DW_AT_common_reference: | |
7191 | return "DW_AT_common_reference"; | |
7192 | case DW_AT_comp_dir: | |
7193 | return "DW_AT_comp_dir"; | |
7194 | case DW_AT_const_value: | |
7195 | return "DW_AT_const_value"; | |
7196 | case DW_AT_containing_type: | |
7197 | return "DW_AT_containing_type"; | |
7198 | case DW_AT_default_value: | |
7199 | return "DW_AT_default_value"; | |
7200 | case DW_AT_inline: | |
7201 | return "DW_AT_inline"; | |
7202 | case DW_AT_is_optional: | |
7203 | return "DW_AT_is_optional"; | |
7204 | case DW_AT_lower_bound: | |
7205 | return "DW_AT_lower_bound"; | |
7206 | case DW_AT_producer: | |
7207 | return "DW_AT_producer"; | |
7208 | case DW_AT_prototyped: | |
7209 | return "DW_AT_prototyped"; | |
7210 | case DW_AT_return_addr: | |
7211 | return "DW_AT_return_addr"; | |
7212 | case DW_AT_start_scope: | |
7213 | return "DW_AT_start_scope"; | |
7214 | case DW_AT_stride_size: | |
7215 | return "DW_AT_stride_size"; | |
7216 | case DW_AT_upper_bound: | |
7217 | return "DW_AT_upper_bound"; | |
7218 | case DW_AT_abstract_origin: | |
7219 | return "DW_AT_abstract_origin"; | |
7220 | case DW_AT_accessibility: | |
7221 | return "DW_AT_accessibility"; | |
7222 | case DW_AT_address_class: | |
7223 | return "DW_AT_address_class"; | |
7224 | case DW_AT_artificial: | |
7225 | return "DW_AT_artificial"; | |
7226 | case DW_AT_base_types: | |
7227 | return "DW_AT_base_types"; | |
7228 | case DW_AT_calling_convention: | |
7229 | return "DW_AT_calling_convention"; | |
7230 | case DW_AT_count: | |
7231 | return "DW_AT_count"; | |
7232 | case DW_AT_data_member_location: | |
7233 | return "DW_AT_data_member_location"; | |
7234 | case DW_AT_decl_column: | |
7235 | return "DW_AT_decl_column"; | |
7236 | case DW_AT_decl_file: | |
7237 | return "DW_AT_decl_file"; | |
7238 | case DW_AT_decl_line: | |
7239 | return "DW_AT_decl_line"; | |
7240 | case DW_AT_declaration: | |
7241 | return "DW_AT_declaration"; | |
7242 | case DW_AT_discr_list: | |
7243 | return "DW_AT_discr_list"; | |
7244 | case DW_AT_encoding: | |
7245 | return "DW_AT_encoding"; | |
7246 | case DW_AT_external: | |
7247 | return "DW_AT_external"; | |
7248 | case DW_AT_frame_base: | |
7249 | return "DW_AT_frame_base"; | |
7250 | case DW_AT_friend: | |
7251 | return "DW_AT_friend"; | |
7252 | case DW_AT_identifier_case: | |
7253 | return "DW_AT_identifier_case"; | |
7254 | case DW_AT_macro_info: | |
7255 | return "DW_AT_macro_info"; | |
7256 | case DW_AT_namelist_items: | |
7257 | return "DW_AT_namelist_items"; | |
7258 | case DW_AT_priority: | |
7259 | return "DW_AT_priority"; | |
7260 | case DW_AT_segment: | |
7261 | return "DW_AT_segment"; | |
7262 | case DW_AT_specification: | |
7263 | return "DW_AT_specification"; | |
7264 | case DW_AT_static_link: | |
7265 | return "DW_AT_static_link"; | |
7266 | case DW_AT_type: | |
7267 | return "DW_AT_type"; | |
7268 | case DW_AT_use_location: | |
7269 | return "DW_AT_use_location"; | |
7270 | case DW_AT_variable_parameter: | |
7271 | return "DW_AT_variable_parameter"; | |
7272 | case DW_AT_virtuality: | |
7273 | return "DW_AT_virtuality"; | |
7274 | case DW_AT_vtable_elem_location: | |
7275 | return "DW_AT_vtable_elem_location"; | |
d9fa45fe DC |
7276 | case DW_AT_allocated: |
7277 | return "DW_AT_allocated"; | |
7278 | case DW_AT_associated: | |
7279 | return "DW_AT_associated"; | |
7280 | case DW_AT_data_location: | |
7281 | return "DW_AT_data_location"; | |
7282 | case DW_AT_stride: | |
7283 | return "DW_AT_stride"; | |
7284 | case DW_AT_entry_pc: | |
7285 | return "DW_AT_entry_pc"; | |
7286 | case DW_AT_use_UTF8: | |
7287 | return "DW_AT_use_UTF8"; | |
7288 | case DW_AT_extension: | |
7289 | return "DW_AT_extension"; | |
7290 | case DW_AT_ranges: | |
7291 | return "DW_AT_ranges"; | |
7292 | case DW_AT_trampoline: | |
7293 | return "DW_AT_trampoline"; | |
7294 | case DW_AT_call_column: | |
7295 | return "DW_AT_call_column"; | |
7296 | case DW_AT_call_file: | |
7297 | return "DW_AT_call_file"; | |
7298 | case DW_AT_call_line: | |
7299 | return "DW_AT_call_line"; | |
c906108c SS |
7300 | #ifdef MIPS |
7301 | case DW_AT_MIPS_fde: | |
7302 | return "DW_AT_MIPS_fde"; | |
7303 | case DW_AT_MIPS_loop_begin: | |
7304 | return "DW_AT_MIPS_loop_begin"; | |
7305 | case DW_AT_MIPS_tail_loop_begin: | |
7306 | return "DW_AT_MIPS_tail_loop_begin"; | |
7307 | case DW_AT_MIPS_epilog_begin: | |
7308 | return "DW_AT_MIPS_epilog_begin"; | |
7309 | case DW_AT_MIPS_loop_unroll_factor: | |
7310 | return "DW_AT_MIPS_loop_unroll_factor"; | |
7311 | case DW_AT_MIPS_software_pipeline_depth: | |
7312 | return "DW_AT_MIPS_software_pipeline_depth"; | |
e0a4f5a1 | 7313 | #endif |
c906108c SS |
7314 | case DW_AT_MIPS_linkage_name: |
7315 | return "DW_AT_MIPS_linkage_name"; | |
c906108c SS |
7316 | |
7317 | case DW_AT_sf_names: | |
7318 | return "DW_AT_sf_names"; | |
7319 | case DW_AT_src_info: | |
7320 | return "DW_AT_src_info"; | |
7321 | case DW_AT_mac_info: | |
7322 | return "DW_AT_mac_info"; | |
7323 | case DW_AT_src_coords: | |
7324 | return "DW_AT_src_coords"; | |
7325 | case DW_AT_body_begin: | |
7326 | return "DW_AT_body_begin"; | |
7327 | case DW_AT_body_end: | |
7328 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
7329 | case DW_AT_GNU_vector: |
7330 | return "DW_AT_GNU_vector"; | |
c906108c SS |
7331 | default: |
7332 | return "DW_AT_<unknown>"; | |
7333 | } | |
7334 | } | |
7335 | ||
7336 | /* Convert a DWARF value form code into its string name. */ | |
7337 | ||
7338 | static char * | |
aa1ee363 | 7339 | dwarf_form_name (unsigned form) |
c906108c SS |
7340 | { |
7341 | switch (form) | |
7342 | { | |
7343 | case DW_FORM_addr: | |
7344 | return "DW_FORM_addr"; | |
7345 | case DW_FORM_block2: | |
7346 | return "DW_FORM_block2"; | |
7347 | case DW_FORM_block4: | |
7348 | return "DW_FORM_block4"; | |
7349 | case DW_FORM_data2: | |
7350 | return "DW_FORM_data2"; | |
7351 | case DW_FORM_data4: | |
7352 | return "DW_FORM_data4"; | |
7353 | case DW_FORM_data8: | |
7354 | return "DW_FORM_data8"; | |
7355 | case DW_FORM_string: | |
7356 | return "DW_FORM_string"; | |
7357 | case DW_FORM_block: | |
7358 | return "DW_FORM_block"; | |
7359 | case DW_FORM_block1: | |
7360 | return "DW_FORM_block1"; | |
7361 | case DW_FORM_data1: | |
7362 | return "DW_FORM_data1"; | |
7363 | case DW_FORM_flag: | |
7364 | return "DW_FORM_flag"; | |
7365 | case DW_FORM_sdata: | |
7366 | return "DW_FORM_sdata"; | |
7367 | case DW_FORM_strp: | |
7368 | return "DW_FORM_strp"; | |
7369 | case DW_FORM_udata: | |
7370 | return "DW_FORM_udata"; | |
7371 | case DW_FORM_ref_addr: | |
7372 | return "DW_FORM_ref_addr"; | |
7373 | case DW_FORM_ref1: | |
7374 | return "DW_FORM_ref1"; | |
7375 | case DW_FORM_ref2: | |
7376 | return "DW_FORM_ref2"; | |
7377 | case DW_FORM_ref4: | |
7378 | return "DW_FORM_ref4"; | |
7379 | case DW_FORM_ref8: | |
7380 | return "DW_FORM_ref8"; | |
7381 | case DW_FORM_ref_udata: | |
7382 | return "DW_FORM_ref_udata"; | |
7383 | case DW_FORM_indirect: | |
7384 | return "DW_FORM_indirect"; | |
7385 | default: | |
7386 | return "DW_FORM_<unknown>"; | |
7387 | } | |
7388 | } | |
7389 | ||
7390 | /* Convert a DWARF stack opcode into its string name. */ | |
7391 | ||
7392 | static char * | |
aa1ee363 | 7393 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
7394 | { |
7395 | switch (op) | |
7396 | { | |
7397 | case DW_OP_addr: | |
7398 | return "DW_OP_addr"; | |
7399 | case DW_OP_deref: | |
7400 | return "DW_OP_deref"; | |
7401 | case DW_OP_const1u: | |
7402 | return "DW_OP_const1u"; | |
7403 | case DW_OP_const1s: | |
7404 | return "DW_OP_const1s"; | |
7405 | case DW_OP_const2u: | |
7406 | return "DW_OP_const2u"; | |
7407 | case DW_OP_const2s: | |
7408 | return "DW_OP_const2s"; | |
7409 | case DW_OP_const4u: | |
7410 | return "DW_OP_const4u"; | |
7411 | case DW_OP_const4s: | |
7412 | return "DW_OP_const4s"; | |
7413 | case DW_OP_const8u: | |
7414 | return "DW_OP_const8u"; | |
7415 | case DW_OP_const8s: | |
7416 | return "DW_OP_const8s"; | |
7417 | case DW_OP_constu: | |
7418 | return "DW_OP_constu"; | |
7419 | case DW_OP_consts: | |
7420 | return "DW_OP_consts"; | |
7421 | case DW_OP_dup: | |
7422 | return "DW_OP_dup"; | |
7423 | case DW_OP_drop: | |
7424 | return "DW_OP_drop"; | |
7425 | case DW_OP_over: | |
7426 | return "DW_OP_over"; | |
7427 | case DW_OP_pick: | |
7428 | return "DW_OP_pick"; | |
7429 | case DW_OP_swap: | |
7430 | return "DW_OP_swap"; | |
7431 | case DW_OP_rot: | |
7432 | return "DW_OP_rot"; | |
7433 | case DW_OP_xderef: | |
7434 | return "DW_OP_xderef"; | |
7435 | case DW_OP_abs: | |
7436 | return "DW_OP_abs"; | |
7437 | case DW_OP_and: | |
7438 | return "DW_OP_and"; | |
7439 | case DW_OP_div: | |
7440 | return "DW_OP_div"; | |
7441 | case DW_OP_minus: | |
7442 | return "DW_OP_minus"; | |
7443 | case DW_OP_mod: | |
7444 | return "DW_OP_mod"; | |
7445 | case DW_OP_mul: | |
7446 | return "DW_OP_mul"; | |
7447 | case DW_OP_neg: | |
7448 | return "DW_OP_neg"; | |
7449 | case DW_OP_not: | |
7450 | return "DW_OP_not"; | |
7451 | case DW_OP_or: | |
7452 | return "DW_OP_or"; | |
7453 | case DW_OP_plus: | |
7454 | return "DW_OP_plus"; | |
7455 | case DW_OP_plus_uconst: | |
7456 | return "DW_OP_plus_uconst"; | |
7457 | case DW_OP_shl: | |
7458 | return "DW_OP_shl"; | |
7459 | case DW_OP_shr: | |
7460 | return "DW_OP_shr"; | |
7461 | case DW_OP_shra: | |
7462 | return "DW_OP_shra"; | |
7463 | case DW_OP_xor: | |
7464 | return "DW_OP_xor"; | |
7465 | case DW_OP_bra: | |
7466 | return "DW_OP_bra"; | |
7467 | case DW_OP_eq: | |
7468 | return "DW_OP_eq"; | |
7469 | case DW_OP_ge: | |
7470 | return "DW_OP_ge"; | |
7471 | case DW_OP_gt: | |
7472 | return "DW_OP_gt"; | |
7473 | case DW_OP_le: | |
7474 | return "DW_OP_le"; | |
7475 | case DW_OP_lt: | |
7476 | return "DW_OP_lt"; | |
7477 | case DW_OP_ne: | |
7478 | return "DW_OP_ne"; | |
7479 | case DW_OP_skip: | |
7480 | return "DW_OP_skip"; | |
7481 | case DW_OP_lit0: | |
7482 | return "DW_OP_lit0"; | |
7483 | case DW_OP_lit1: | |
7484 | return "DW_OP_lit1"; | |
7485 | case DW_OP_lit2: | |
7486 | return "DW_OP_lit2"; | |
7487 | case DW_OP_lit3: | |
7488 | return "DW_OP_lit3"; | |
7489 | case DW_OP_lit4: | |
7490 | return "DW_OP_lit4"; | |
7491 | case DW_OP_lit5: | |
7492 | return "DW_OP_lit5"; | |
7493 | case DW_OP_lit6: | |
7494 | return "DW_OP_lit6"; | |
7495 | case DW_OP_lit7: | |
7496 | return "DW_OP_lit7"; | |
7497 | case DW_OP_lit8: | |
7498 | return "DW_OP_lit8"; | |
7499 | case DW_OP_lit9: | |
7500 | return "DW_OP_lit9"; | |
7501 | case DW_OP_lit10: | |
7502 | return "DW_OP_lit10"; | |
7503 | case DW_OP_lit11: | |
7504 | return "DW_OP_lit11"; | |
7505 | case DW_OP_lit12: | |
7506 | return "DW_OP_lit12"; | |
7507 | case DW_OP_lit13: | |
7508 | return "DW_OP_lit13"; | |
7509 | case DW_OP_lit14: | |
7510 | return "DW_OP_lit14"; | |
7511 | case DW_OP_lit15: | |
7512 | return "DW_OP_lit15"; | |
7513 | case DW_OP_lit16: | |
7514 | return "DW_OP_lit16"; | |
7515 | case DW_OP_lit17: | |
7516 | return "DW_OP_lit17"; | |
7517 | case DW_OP_lit18: | |
7518 | return "DW_OP_lit18"; | |
7519 | case DW_OP_lit19: | |
7520 | return "DW_OP_lit19"; | |
7521 | case DW_OP_lit20: | |
7522 | return "DW_OP_lit20"; | |
7523 | case DW_OP_lit21: | |
7524 | return "DW_OP_lit21"; | |
7525 | case DW_OP_lit22: | |
7526 | return "DW_OP_lit22"; | |
7527 | case DW_OP_lit23: | |
7528 | return "DW_OP_lit23"; | |
7529 | case DW_OP_lit24: | |
7530 | return "DW_OP_lit24"; | |
7531 | case DW_OP_lit25: | |
7532 | return "DW_OP_lit25"; | |
7533 | case DW_OP_lit26: | |
7534 | return "DW_OP_lit26"; | |
7535 | case DW_OP_lit27: | |
7536 | return "DW_OP_lit27"; | |
7537 | case DW_OP_lit28: | |
7538 | return "DW_OP_lit28"; | |
7539 | case DW_OP_lit29: | |
7540 | return "DW_OP_lit29"; | |
7541 | case DW_OP_lit30: | |
7542 | return "DW_OP_lit30"; | |
7543 | case DW_OP_lit31: | |
7544 | return "DW_OP_lit31"; | |
7545 | case DW_OP_reg0: | |
7546 | return "DW_OP_reg0"; | |
7547 | case DW_OP_reg1: | |
7548 | return "DW_OP_reg1"; | |
7549 | case DW_OP_reg2: | |
7550 | return "DW_OP_reg2"; | |
7551 | case DW_OP_reg3: | |
7552 | return "DW_OP_reg3"; | |
7553 | case DW_OP_reg4: | |
7554 | return "DW_OP_reg4"; | |
7555 | case DW_OP_reg5: | |
7556 | return "DW_OP_reg5"; | |
7557 | case DW_OP_reg6: | |
7558 | return "DW_OP_reg6"; | |
7559 | case DW_OP_reg7: | |
7560 | return "DW_OP_reg7"; | |
7561 | case DW_OP_reg8: | |
7562 | return "DW_OP_reg8"; | |
7563 | case DW_OP_reg9: | |
7564 | return "DW_OP_reg9"; | |
7565 | case DW_OP_reg10: | |
7566 | return "DW_OP_reg10"; | |
7567 | case DW_OP_reg11: | |
7568 | return "DW_OP_reg11"; | |
7569 | case DW_OP_reg12: | |
7570 | return "DW_OP_reg12"; | |
7571 | case DW_OP_reg13: | |
7572 | return "DW_OP_reg13"; | |
7573 | case DW_OP_reg14: | |
7574 | return "DW_OP_reg14"; | |
7575 | case DW_OP_reg15: | |
7576 | return "DW_OP_reg15"; | |
7577 | case DW_OP_reg16: | |
7578 | return "DW_OP_reg16"; | |
7579 | case DW_OP_reg17: | |
7580 | return "DW_OP_reg17"; | |
7581 | case DW_OP_reg18: | |
7582 | return "DW_OP_reg18"; | |
7583 | case DW_OP_reg19: | |
7584 | return "DW_OP_reg19"; | |
7585 | case DW_OP_reg20: | |
7586 | return "DW_OP_reg20"; | |
7587 | case DW_OP_reg21: | |
7588 | return "DW_OP_reg21"; | |
7589 | case DW_OP_reg22: | |
7590 | return "DW_OP_reg22"; | |
7591 | case DW_OP_reg23: | |
7592 | return "DW_OP_reg23"; | |
7593 | case DW_OP_reg24: | |
7594 | return "DW_OP_reg24"; | |
7595 | case DW_OP_reg25: | |
7596 | return "DW_OP_reg25"; | |
7597 | case DW_OP_reg26: | |
7598 | return "DW_OP_reg26"; | |
7599 | case DW_OP_reg27: | |
7600 | return "DW_OP_reg27"; | |
7601 | case DW_OP_reg28: | |
7602 | return "DW_OP_reg28"; | |
7603 | case DW_OP_reg29: | |
7604 | return "DW_OP_reg29"; | |
7605 | case DW_OP_reg30: | |
7606 | return "DW_OP_reg30"; | |
7607 | case DW_OP_reg31: | |
7608 | return "DW_OP_reg31"; | |
7609 | case DW_OP_breg0: | |
7610 | return "DW_OP_breg0"; | |
7611 | case DW_OP_breg1: | |
7612 | return "DW_OP_breg1"; | |
7613 | case DW_OP_breg2: | |
7614 | return "DW_OP_breg2"; | |
7615 | case DW_OP_breg3: | |
7616 | return "DW_OP_breg3"; | |
7617 | case DW_OP_breg4: | |
7618 | return "DW_OP_breg4"; | |
7619 | case DW_OP_breg5: | |
7620 | return "DW_OP_breg5"; | |
7621 | case DW_OP_breg6: | |
7622 | return "DW_OP_breg6"; | |
7623 | case DW_OP_breg7: | |
7624 | return "DW_OP_breg7"; | |
7625 | case DW_OP_breg8: | |
7626 | return "DW_OP_breg8"; | |
7627 | case DW_OP_breg9: | |
7628 | return "DW_OP_breg9"; | |
7629 | case DW_OP_breg10: | |
7630 | return "DW_OP_breg10"; | |
7631 | case DW_OP_breg11: | |
7632 | return "DW_OP_breg11"; | |
7633 | case DW_OP_breg12: | |
7634 | return "DW_OP_breg12"; | |
7635 | case DW_OP_breg13: | |
7636 | return "DW_OP_breg13"; | |
7637 | case DW_OP_breg14: | |
7638 | return "DW_OP_breg14"; | |
7639 | case DW_OP_breg15: | |
7640 | return "DW_OP_breg15"; | |
7641 | case DW_OP_breg16: | |
7642 | return "DW_OP_breg16"; | |
7643 | case DW_OP_breg17: | |
7644 | return "DW_OP_breg17"; | |
7645 | case DW_OP_breg18: | |
7646 | return "DW_OP_breg18"; | |
7647 | case DW_OP_breg19: | |
7648 | return "DW_OP_breg19"; | |
7649 | case DW_OP_breg20: | |
7650 | return "DW_OP_breg20"; | |
7651 | case DW_OP_breg21: | |
7652 | return "DW_OP_breg21"; | |
7653 | case DW_OP_breg22: | |
7654 | return "DW_OP_breg22"; | |
7655 | case DW_OP_breg23: | |
7656 | return "DW_OP_breg23"; | |
7657 | case DW_OP_breg24: | |
7658 | return "DW_OP_breg24"; | |
7659 | case DW_OP_breg25: | |
7660 | return "DW_OP_breg25"; | |
7661 | case DW_OP_breg26: | |
7662 | return "DW_OP_breg26"; | |
7663 | case DW_OP_breg27: | |
7664 | return "DW_OP_breg27"; | |
7665 | case DW_OP_breg28: | |
7666 | return "DW_OP_breg28"; | |
7667 | case DW_OP_breg29: | |
7668 | return "DW_OP_breg29"; | |
7669 | case DW_OP_breg30: | |
7670 | return "DW_OP_breg30"; | |
7671 | case DW_OP_breg31: | |
7672 | return "DW_OP_breg31"; | |
7673 | case DW_OP_regx: | |
7674 | return "DW_OP_regx"; | |
7675 | case DW_OP_fbreg: | |
7676 | return "DW_OP_fbreg"; | |
7677 | case DW_OP_bregx: | |
7678 | return "DW_OP_bregx"; | |
7679 | case DW_OP_piece: | |
7680 | return "DW_OP_piece"; | |
7681 | case DW_OP_deref_size: | |
7682 | return "DW_OP_deref_size"; | |
7683 | case DW_OP_xderef_size: | |
7684 | return "DW_OP_xderef_size"; | |
7685 | case DW_OP_nop: | |
7686 | return "DW_OP_nop"; | |
ed348acc EZ |
7687 | /* DWARF 3 extensions. */ |
7688 | case DW_OP_push_object_address: | |
7689 | return "DW_OP_push_object_address"; | |
7690 | case DW_OP_call2: | |
7691 | return "DW_OP_call2"; | |
7692 | case DW_OP_call4: | |
7693 | return "DW_OP_call4"; | |
7694 | case DW_OP_call_ref: | |
7695 | return "DW_OP_call_ref"; | |
7696 | /* GNU extensions. */ | |
7697 | case DW_OP_GNU_push_tls_address: | |
7698 | return "DW_OP_GNU_push_tls_address"; | |
c906108c SS |
7699 | default: |
7700 | return "OP_<unknown>"; | |
7701 | } | |
7702 | } | |
7703 | ||
7704 | static char * | |
fba45db2 | 7705 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
7706 | { |
7707 | if (mybool) | |
7708 | return "TRUE"; | |
7709 | else | |
7710 | return "FALSE"; | |
7711 | } | |
7712 | ||
7713 | /* Convert a DWARF type code into its string name. */ | |
7714 | ||
7715 | static char * | |
aa1ee363 | 7716 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
7717 | { |
7718 | switch (enc) | |
7719 | { | |
7720 | case DW_ATE_address: | |
7721 | return "DW_ATE_address"; | |
7722 | case DW_ATE_boolean: | |
7723 | return "DW_ATE_boolean"; | |
7724 | case DW_ATE_complex_float: | |
7725 | return "DW_ATE_complex_float"; | |
7726 | case DW_ATE_float: | |
7727 | return "DW_ATE_float"; | |
7728 | case DW_ATE_signed: | |
7729 | return "DW_ATE_signed"; | |
7730 | case DW_ATE_signed_char: | |
7731 | return "DW_ATE_signed_char"; | |
7732 | case DW_ATE_unsigned: | |
7733 | return "DW_ATE_unsigned"; | |
7734 | case DW_ATE_unsigned_char: | |
7735 | return "DW_ATE_unsigned_char"; | |
d9fa45fe DC |
7736 | case DW_ATE_imaginary_float: |
7737 | return "DW_ATE_imaginary_float"; | |
c906108c SS |
7738 | default: |
7739 | return "DW_ATE_<unknown>"; | |
7740 | } | |
7741 | } | |
7742 | ||
7743 | /* Convert a DWARF call frame info operation to its string name. */ | |
7744 | ||
7745 | #if 0 | |
7746 | static char * | |
aa1ee363 | 7747 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
7748 | { |
7749 | switch (cfi_opc) | |
7750 | { | |
7751 | case DW_CFA_advance_loc: | |
7752 | return "DW_CFA_advance_loc"; | |
7753 | case DW_CFA_offset: | |
7754 | return "DW_CFA_offset"; | |
7755 | case DW_CFA_restore: | |
7756 | return "DW_CFA_restore"; | |
7757 | case DW_CFA_nop: | |
7758 | return "DW_CFA_nop"; | |
7759 | case DW_CFA_set_loc: | |
7760 | return "DW_CFA_set_loc"; | |
7761 | case DW_CFA_advance_loc1: | |
7762 | return "DW_CFA_advance_loc1"; | |
7763 | case DW_CFA_advance_loc2: | |
7764 | return "DW_CFA_advance_loc2"; | |
7765 | case DW_CFA_advance_loc4: | |
7766 | return "DW_CFA_advance_loc4"; | |
7767 | case DW_CFA_offset_extended: | |
7768 | return "DW_CFA_offset_extended"; | |
7769 | case DW_CFA_restore_extended: | |
7770 | return "DW_CFA_restore_extended"; | |
7771 | case DW_CFA_undefined: | |
7772 | return "DW_CFA_undefined"; | |
7773 | case DW_CFA_same_value: | |
7774 | return "DW_CFA_same_value"; | |
7775 | case DW_CFA_register: | |
7776 | return "DW_CFA_register"; | |
7777 | case DW_CFA_remember_state: | |
7778 | return "DW_CFA_remember_state"; | |
7779 | case DW_CFA_restore_state: | |
7780 | return "DW_CFA_restore_state"; | |
7781 | case DW_CFA_def_cfa: | |
7782 | return "DW_CFA_def_cfa"; | |
7783 | case DW_CFA_def_cfa_register: | |
7784 | return "DW_CFA_def_cfa_register"; | |
7785 | case DW_CFA_def_cfa_offset: | |
7786 | return "DW_CFA_def_cfa_offset"; | |
985cb1a3 JM |
7787 | |
7788 | /* DWARF 3 */ | |
7789 | case DW_CFA_def_cfa_expression: | |
7790 | return "DW_CFA_def_cfa_expression"; | |
7791 | case DW_CFA_expression: | |
7792 | return "DW_CFA_expression"; | |
7793 | case DW_CFA_offset_extended_sf: | |
7794 | return "DW_CFA_offset_extended_sf"; | |
7795 | case DW_CFA_def_cfa_sf: | |
7796 | return "DW_CFA_def_cfa_sf"; | |
7797 | case DW_CFA_def_cfa_offset_sf: | |
7798 | return "DW_CFA_def_cfa_offset_sf"; | |
7799 | ||
c906108c SS |
7800 | /* SGI/MIPS specific */ |
7801 | case DW_CFA_MIPS_advance_loc8: | |
7802 | return "DW_CFA_MIPS_advance_loc8"; | |
985cb1a3 JM |
7803 | |
7804 | /* GNU extensions */ | |
7805 | case DW_CFA_GNU_window_save: | |
7806 | return "DW_CFA_GNU_window_save"; | |
7807 | case DW_CFA_GNU_args_size: | |
7808 | return "DW_CFA_GNU_args_size"; | |
7809 | case DW_CFA_GNU_negative_offset_extended: | |
7810 | return "DW_CFA_GNU_negative_offset_extended"; | |
7811 | ||
c906108c SS |
7812 | default: |
7813 | return "DW_CFA_<unknown>"; | |
7814 | } | |
7815 | } | |
7816 | #endif | |
7817 | ||
f9aca02d | 7818 | static void |
fba45db2 | 7819 | dump_die (struct die_info *die) |
c906108c SS |
7820 | { |
7821 | unsigned int i; | |
7822 | ||
48cd0caa | 7823 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 7824 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 7825 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 7826 | dwarf_bool_name (die->child != NULL)); |
c906108c | 7827 | |
48cd0caa | 7828 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
7829 | for (i = 0; i < die->num_attrs; ++i) |
7830 | { | |
48cd0caa | 7831 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
7832 | dwarf_attr_name (die->attrs[i].name), |
7833 | dwarf_form_name (die->attrs[i].form)); | |
7834 | switch (die->attrs[i].form) | |
7835 | { | |
7836 | case DW_FORM_ref_addr: | |
7837 | case DW_FORM_addr: | |
48cd0caa | 7838 | fprintf_unfiltered (gdb_stderr, "address: "); |
c906108c SS |
7839 | print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); |
7840 | break; | |
7841 | case DW_FORM_block2: | |
7842 | case DW_FORM_block4: | |
7843 | case DW_FORM_block: | |
7844 | case DW_FORM_block1: | |
48cd0caa | 7845 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c SS |
7846 | break; |
7847 | case DW_FORM_data1: | |
7848 | case DW_FORM_data2: | |
7849 | case DW_FORM_data4: | |
ce5d95e1 | 7850 | case DW_FORM_data8: |
c906108c SS |
7851 | case DW_FORM_ref1: |
7852 | case DW_FORM_ref2: | |
7853 | case DW_FORM_ref4: | |
7854 | case DW_FORM_udata: | |
7855 | case DW_FORM_sdata: | |
48cd0caa | 7856 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
7857 | break; |
7858 | case DW_FORM_string: | |
4bdf3d34 | 7859 | case DW_FORM_strp: |
48cd0caa | 7860 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 7861 | DW_STRING (&die->attrs[i]) |
c5aa993b | 7862 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
7863 | break; |
7864 | case DW_FORM_flag: | |
7865 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 7866 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 7867 | else |
48cd0caa | 7868 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 7869 | break; |
a8329558 KW |
7870 | case DW_FORM_indirect: |
7871 | /* the reader will have reduced the indirect form to | |
7872 | the "base form" so this form should not occur */ | |
48cd0caa | 7873 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 7874 | break; |
c906108c | 7875 | default: |
48cd0caa | 7876 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 7877 | die->attrs[i].form); |
c906108c | 7878 | } |
48cd0caa | 7879 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
7880 | } |
7881 | } | |
7882 | ||
f9aca02d | 7883 | static void |
fba45db2 | 7884 | dump_die_list (struct die_info *die) |
c906108c SS |
7885 | { |
7886 | while (die) | |
7887 | { | |
7888 | dump_die (die); | |
639d11d3 DC |
7889 | if (die->child != NULL) |
7890 | dump_die_list (die->child); | |
7891 | if (die->sibling != NULL) | |
7892 | dump_die_list (die->sibling); | |
c906108c SS |
7893 | } |
7894 | } | |
7895 | ||
f9aca02d | 7896 | static void |
fba45db2 | 7897 | store_in_ref_table (unsigned int offset, struct die_info *die) |
c906108c SS |
7898 | { |
7899 | int h; | |
7900 | struct die_info *old; | |
7901 | ||
7902 | h = (offset % REF_HASH_SIZE); | |
7903 | old = die_ref_table[h]; | |
7904 | die->next_ref = old; | |
7905 | die_ref_table[h] = die; | |
7906 | } | |
7907 | ||
7908 | ||
7909 | static void | |
fba45db2 | 7910 | dwarf2_empty_hash_tables (void) |
c906108c SS |
7911 | { |
7912 | memset (die_ref_table, 0, sizeof (die_ref_table)); | |
7913 | } | |
7914 | ||
7915 | static unsigned int | |
e142c38c | 7916 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
7917 | { |
7918 | unsigned int result = 0; | |
7919 | ||
7920 | switch (attr->form) | |
7921 | { | |
7922 | case DW_FORM_ref_addr: | |
7923 | result = DW_ADDR (attr); | |
7924 | break; | |
7925 | case DW_FORM_ref1: | |
7926 | case DW_FORM_ref2: | |
7927 | case DW_FORM_ref4: | |
613e1657 | 7928 | case DW_FORM_ref8: |
c906108c | 7929 | case DW_FORM_ref_udata: |
e142c38c | 7930 | result = cu->header.offset + DW_UNSND (attr); |
c906108c SS |
7931 | break; |
7932 | default: | |
4d3c2250 KB |
7933 | complaint (&symfile_complaints, |
7934 | "unsupported die ref attribute form: '%s'", | |
7935 | dwarf_form_name (attr->form)); | |
c906108c SS |
7936 | } |
7937 | return result; | |
7938 | } | |
7939 | ||
a02abb62 JB |
7940 | /* Return the constant value held by the given attribute. Return -1 |
7941 | if the value held by the attribute is not constant. */ | |
7942 | ||
7943 | static int | |
7944 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
7945 | { | |
7946 | if (attr->form == DW_FORM_sdata) | |
7947 | return DW_SND (attr); | |
7948 | else if (attr->form == DW_FORM_udata | |
7949 | || attr->form == DW_FORM_data1 | |
7950 | || attr->form == DW_FORM_data2 | |
7951 | || attr->form == DW_FORM_data4 | |
7952 | || attr->form == DW_FORM_data8) | |
7953 | return DW_UNSND (attr); | |
7954 | else | |
7955 | { | |
7956 | complaint (&symfile_complaints, "Attribute value is not a constant (%s)", | |
7957 | dwarf_form_name (attr->form)); | |
7958 | return default_value; | |
7959 | } | |
7960 | } | |
7961 | ||
f9aca02d | 7962 | static struct die_info * |
fba45db2 | 7963 | follow_die_ref (unsigned int offset) |
c906108c SS |
7964 | { |
7965 | struct die_info *die; | |
7966 | int h; | |
7967 | ||
7968 | h = (offset % REF_HASH_SIZE); | |
7969 | die = die_ref_table[h]; | |
7970 | while (die) | |
7971 | { | |
7972 | if (die->offset == offset) | |
7973 | { | |
7974 | return die; | |
7975 | } | |
7976 | die = die->next_ref; | |
7977 | } | |
7978 | return NULL; | |
7979 | } | |
7980 | ||
7981 | static struct type * | |
e142c38c DJ |
7982 | dwarf2_fundamental_type (struct objfile *objfile, int typeid, |
7983 | struct dwarf2_cu *cu) | |
c906108c SS |
7984 | { |
7985 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
7986 | { | |
659b0389 ML |
7987 | error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", |
7988 | typeid, objfile->name); | |
c906108c SS |
7989 | } |
7990 | ||
7991 | /* Look for this particular type in the fundamental type vector. If | |
7992 | one is not found, create and install one appropriate for the | |
7993 | current language and the current target machine. */ | |
7994 | ||
e142c38c | 7995 | if (cu->ftypes[typeid] == NULL) |
c906108c | 7996 | { |
e142c38c | 7997 | cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); |
c906108c SS |
7998 | } |
7999 | ||
e142c38c | 8000 | return (cu->ftypes[typeid]); |
c906108c SS |
8001 | } |
8002 | ||
8003 | /* Decode simple location descriptions. | |
8004 | Given a pointer to a dwarf block that defines a location, compute | |
8005 | the location and return the value. | |
8006 | ||
4cecd739 DJ |
8007 | NOTE drow/2003-11-18: This function is called in two situations |
8008 | now: for the address of static or global variables (partial symbols | |
8009 | only) and for offsets into structures which are expected to be | |
8010 | (more or less) constant. The partial symbol case should go away, | |
8011 | and only the constant case should remain. That will let this | |
8012 | function complain more accurately. A few special modes are allowed | |
8013 | without complaint for global variables (for instance, global | |
8014 | register values and thread-local values). | |
c906108c SS |
8015 | |
8016 | A location description containing no operations indicates that the | |
4cecd739 | 8017 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
8018 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
8019 | callers will only want a very basic result and this can become a | |
8020 | complaint. | |
c906108c SS |
8021 | |
8022 | When the result is a register number, the global isreg flag is set, | |
8023 | otherwise it is cleared. | |
8024 | ||
c906108c SS |
8025 | Note that stack[0] is unused except as a default error return. |
8026 | Note that stack overflow is not yet handled. */ | |
8027 | ||
8028 | static CORE_ADDR | |
e7c27a73 | 8029 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 8030 | { |
e7c27a73 DJ |
8031 | struct objfile *objfile = cu->objfile; |
8032 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
8033 | int i; |
8034 | int size = blk->size; | |
8035 | char *data = blk->data; | |
8036 | CORE_ADDR stack[64]; | |
8037 | int stacki; | |
8038 | unsigned int bytes_read, unsnd; | |
8039 | unsigned char op; | |
8040 | ||
8041 | i = 0; | |
8042 | stacki = 0; | |
8043 | stack[stacki] = 0; | |
8044 | isreg = 0; | |
c906108c SS |
8045 | |
8046 | while (i < size) | |
8047 | { | |
c906108c SS |
8048 | op = data[i++]; |
8049 | switch (op) | |
8050 | { | |
f1bea926 JM |
8051 | case DW_OP_lit0: |
8052 | case DW_OP_lit1: | |
8053 | case DW_OP_lit2: | |
8054 | case DW_OP_lit3: | |
8055 | case DW_OP_lit4: | |
8056 | case DW_OP_lit5: | |
8057 | case DW_OP_lit6: | |
8058 | case DW_OP_lit7: | |
8059 | case DW_OP_lit8: | |
8060 | case DW_OP_lit9: | |
8061 | case DW_OP_lit10: | |
8062 | case DW_OP_lit11: | |
8063 | case DW_OP_lit12: | |
8064 | case DW_OP_lit13: | |
8065 | case DW_OP_lit14: | |
8066 | case DW_OP_lit15: | |
8067 | case DW_OP_lit16: | |
8068 | case DW_OP_lit17: | |
8069 | case DW_OP_lit18: | |
8070 | case DW_OP_lit19: | |
8071 | case DW_OP_lit20: | |
8072 | case DW_OP_lit21: | |
8073 | case DW_OP_lit22: | |
8074 | case DW_OP_lit23: | |
8075 | case DW_OP_lit24: | |
8076 | case DW_OP_lit25: | |
8077 | case DW_OP_lit26: | |
8078 | case DW_OP_lit27: | |
8079 | case DW_OP_lit28: | |
8080 | case DW_OP_lit29: | |
8081 | case DW_OP_lit30: | |
8082 | case DW_OP_lit31: | |
8083 | stack[++stacki] = op - DW_OP_lit0; | |
8084 | break; | |
8085 | ||
c906108c SS |
8086 | case DW_OP_reg0: |
8087 | case DW_OP_reg1: | |
8088 | case DW_OP_reg2: | |
8089 | case DW_OP_reg3: | |
8090 | case DW_OP_reg4: | |
8091 | case DW_OP_reg5: | |
8092 | case DW_OP_reg6: | |
8093 | case DW_OP_reg7: | |
8094 | case DW_OP_reg8: | |
8095 | case DW_OP_reg9: | |
8096 | case DW_OP_reg10: | |
8097 | case DW_OP_reg11: | |
8098 | case DW_OP_reg12: | |
8099 | case DW_OP_reg13: | |
8100 | case DW_OP_reg14: | |
8101 | case DW_OP_reg15: | |
8102 | case DW_OP_reg16: | |
8103 | case DW_OP_reg17: | |
8104 | case DW_OP_reg18: | |
8105 | case DW_OP_reg19: | |
8106 | case DW_OP_reg20: | |
8107 | case DW_OP_reg21: | |
8108 | case DW_OP_reg22: | |
8109 | case DW_OP_reg23: | |
8110 | case DW_OP_reg24: | |
8111 | case DW_OP_reg25: | |
8112 | case DW_OP_reg26: | |
8113 | case DW_OP_reg27: | |
8114 | case DW_OP_reg28: | |
8115 | case DW_OP_reg29: | |
8116 | case DW_OP_reg30: | |
8117 | case DW_OP_reg31: | |
8118 | isreg = 1; | |
8119 | stack[++stacki] = op - DW_OP_reg0; | |
4cecd739 DJ |
8120 | if (i < size) |
8121 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8122 | break; |
8123 | ||
8124 | case DW_OP_regx: | |
8125 | isreg = 1; | |
8126 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8127 | i += bytes_read; | |
c906108c | 8128 | stack[++stacki] = unsnd; |
4cecd739 DJ |
8129 | if (i < size) |
8130 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8131 | break; |
8132 | ||
8133 | case DW_OP_addr: | |
107d2387 | 8134 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 8135 | cu, &bytes_read); |
107d2387 | 8136 | i += bytes_read; |
c906108c SS |
8137 | break; |
8138 | ||
8139 | case DW_OP_const1u: | |
8140 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
8141 | i += 1; | |
8142 | break; | |
8143 | ||
8144 | case DW_OP_const1s: | |
8145 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
8146 | i += 1; | |
8147 | break; | |
8148 | ||
8149 | case DW_OP_const2u: | |
8150 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
8151 | i += 2; | |
8152 | break; | |
8153 | ||
8154 | case DW_OP_const2s: | |
8155 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
8156 | i += 2; | |
8157 | break; | |
8158 | ||
8159 | case DW_OP_const4u: | |
8160 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
8161 | i += 4; | |
8162 | break; | |
8163 | ||
8164 | case DW_OP_const4s: | |
8165 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
8166 | i += 4; | |
8167 | break; | |
8168 | ||
8169 | case DW_OP_constu: | |
8170 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 8171 | &bytes_read); |
c906108c SS |
8172 | i += bytes_read; |
8173 | break; | |
8174 | ||
8175 | case DW_OP_consts: | |
8176 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
8177 | i += bytes_read; | |
8178 | break; | |
8179 | ||
f1bea926 JM |
8180 | case DW_OP_dup: |
8181 | stack[stacki + 1] = stack[stacki]; | |
8182 | stacki++; | |
8183 | break; | |
8184 | ||
c906108c SS |
8185 | case DW_OP_plus: |
8186 | stack[stacki - 1] += stack[stacki]; | |
8187 | stacki--; | |
8188 | break; | |
8189 | ||
8190 | case DW_OP_plus_uconst: | |
8191 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8192 | i += bytes_read; | |
8193 | break; | |
8194 | ||
8195 | case DW_OP_minus: | |
f1bea926 | 8196 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
8197 | stacki--; |
8198 | break; | |
8199 | ||
7a292a7a | 8200 | case DW_OP_deref: |
7a292a7a | 8201 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
8202 | this using GDB's address_class enum. This is valid for partial |
8203 | global symbols, although the variable's address will be bogus | |
8204 | in the psymtab. */ | |
7a292a7a | 8205 | if (i < size) |
4d3c2250 | 8206 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
8207 | break; |
8208 | ||
9d774e44 | 8209 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
8210 | /* The top of the stack has the offset from the beginning |
8211 | of the thread control block at which the variable is located. */ | |
8212 | /* Nothing should follow this operator, so the top of stack would | |
8213 | be returned. */ | |
4cecd739 DJ |
8214 | /* This is valid for partial global symbols, but the variable's |
8215 | address will be bogus in the psymtab. */ | |
9d774e44 | 8216 | if (i < size) |
4d3c2250 | 8217 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
8218 | break; |
8219 | ||
c906108c | 8220 | default: |
4d3c2250 KB |
8221 | complaint (&symfile_complaints, "unsupported stack op: '%s'", |
8222 | dwarf_stack_op_name (op)); | |
c906108c SS |
8223 | return (stack[stacki]); |
8224 | } | |
8225 | } | |
8226 | return (stack[stacki]); | |
8227 | } | |
8228 | ||
8229 | /* memory allocation interface */ | |
8230 | ||
c906108c | 8231 | static struct dwarf_block * |
7b5a2f43 | 8232 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
8233 | { |
8234 | struct dwarf_block *blk; | |
8235 | ||
8236 | blk = (struct dwarf_block *) | |
7b5a2f43 | 8237 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
8238 | return (blk); |
8239 | } | |
8240 | ||
8241 | static struct abbrev_info * | |
f3dd6933 | 8242 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
8243 | { |
8244 | struct abbrev_info *abbrev; | |
8245 | ||
f3dd6933 DJ |
8246 | abbrev = (struct abbrev_info *) |
8247 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
8248 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
8249 | return (abbrev); | |
8250 | } | |
8251 | ||
8252 | static struct die_info * | |
fba45db2 | 8253 | dwarf_alloc_die (void) |
c906108c SS |
8254 | { |
8255 | struct die_info *die; | |
8256 | ||
8257 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
8258 | memset (die, 0, sizeof (struct die_info)); | |
8259 | return (die); | |
8260 | } | |
2e276125 JB |
8261 | |
8262 | \f | |
8263 | /* Macro support. */ | |
8264 | ||
8265 | ||
8266 | /* Return the full name of file number I in *LH's file name table. | |
8267 | Use COMP_DIR as the name of the current directory of the | |
8268 | compilation. The result is allocated using xmalloc; the caller is | |
8269 | responsible for freeing it. */ | |
8270 | static char * | |
8271 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
8272 | { | |
8273 | struct file_entry *fe = &lh->file_names[file - 1]; | |
8274 | ||
8275 | if (IS_ABSOLUTE_PATH (fe->name)) | |
8276 | return xstrdup (fe->name); | |
8277 | else | |
8278 | { | |
8279 | const char *dir; | |
8280 | int dir_len; | |
8281 | char *full_name; | |
8282 | ||
8283 | if (fe->dir_index) | |
8284 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8285 | else | |
8286 | dir = comp_dir; | |
8287 | ||
8288 | if (dir) | |
8289 | { | |
8290 | dir_len = strlen (dir); | |
8291 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
8292 | strcpy (full_name, dir); | |
8293 | full_name[dir_len] = '/'; | |
8294 | strcpy (full_name + dir_len + 1, fe->name); | |
8295 | return full_name; | |
8296 | } | |
8297 | else | |
8298 | return xstrdup (fe->name); | |
8299 | } | |
8300 | } | |
8301 | ||
8302 | ||
8303 | static struct macro_source_file * | |
8304 | macro_start_file (int file, int line, | |
8305 | struct macro_source_file *current_file, | |
8306 | const char *comp_dir, | |
8307 | struct line_header *lh, struct objfile *objfile) | |
8308 | { | |
8309 | /* The full name of this source file. */ | |
8310 | char *full_name = file_full_name (file, lh, comp_dir); | |
8311 | ||
8312 | /* We don't create a macro table for this compilation unit | |
8313 | at all until we actually get a filename. */ | |
8314 | if (! pending_macros) | |
4a146b47 | 8315 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 8316 | objfile->macro_cache); |
2e276125 JB |
8317 | |
8318 | if (! current_file) | |
8319 | /* If we have no current file, then this must be the start_file | |
8320 | directive for the compilation unit's main source file. */ | |
8321 | current_file = macro_set_main (pending_macros, full_name); | |
8322 | else | |
8323 | current_file = macro_include (current_file, line, full_name); | |
8324 | ||
8325 | xfree (full_name); | |
8326 | ||
8327 | return current_file; | |
8328 | } | |
8329 | ||
8330 | ||
8331 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
8332 | followed by a null byte. */ | |
8333 | static char * | |
8334 | copy_string (const char *buf, int len) | |
8335 | { | |
8336 | char *s = xmalloc (len + 1); | |
8337 | memcpy (s, buf, len); | |
8338 | s[len] = '\0'; | |
8339 | ||
8340 | return s; | |
8341 | } | |
8342 | ||
8343 | ||
8344 | static const char * | |
8345 | consume_improper_spaces (const char *p, const char *body) | |
8346 | { | |
8347 | if (*p == ' ') | |
8348 | { | |
4d3c2250 KB |
8349 | complaint (&symfile_complaints, |
8350 | "macro definition contains spaces in formal argument list:\n`%s'", | |
8351 | body); | |
2e276125 JB |
8352 | |
8353 | while (*p == ' ') | |
8354 | p++; | |
8355 | } | |
8356 | ||
8357 | return p; | |
8358 | } | |
8359 | ||
8360 | ||
8361 | static void | |
8362 | parse_macro_definition (struct macro_source_file *file, int line, | |
8363 | const char *body) | |
8364 | { | |
8365 | const char *p; | |
8366 | ||
8367 | /* The body string takes one of two forms. For object-like macro | |
8368 | definitions, it should be: | |
8369 | ||
8370 | <macro name> " " <definition> | |
8371 | ||
8372 | For function-like macro definitions, it should be: | |
8373 | ||
8374 | <macro name> "() " <definition> | |
8375 | or | |
8376 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
8377 | ||
8378 | Spaces may appear only where explicitly indicated, and in the | |
8379 | <definition>. | |
8380 | ||
8381 | The Dwarf 2 spec says that an object-like macro's name is always | |
8382 | followed by a space, but versions of GCC around March 2002 omit | |
8383 | the space when the macro's definition is the empty string. | |
8384 | ||
8385 | The Dwarf 2 spec says that there should be no spaces between the | |
8386 | formal arguments in a function-like macro's formal argument list, | |
8387 | but versions of GCC around March 2002 include spaces after the | |
8388 | commas. */ | |
8389 | ||
8390 | ||
8391 | /* Find the extent of the macro name. The macro name is terminated | |
8392 | by either a space or null character (for an object-like macro) or | |
8393 | an opening paren (for a function-like macro). */ | |
8394 | for (p = body; *p; p++) | |
8395 | if (*p == ' ' || *p == '(') | |
8396 | break; | |
8397 | ||
8398 | if (*p == ' ' || *p == '\0') | |
8399 | { | |
8400 | /* It's an object-like macro. */ | |
8401 | int name_len = p - body; | |
8402 | char *name = copy_string (body, name_len); | |
8403 | const char *replacement; | |
8404 | ||
8405 | if (*p == ' ') | |
8406 | replacement = body + name_len + 1; | |
8407 | else | |
8408 | { | |
4d3c2250 | 8409 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8410 | replacement = body + name_len; |
8411 | } | |
8412 | ||
8413 | macro_define_object (file, line, name, replacement); | |
8414 | ||
8415 | xfree (name); | |
8416 | } | |
8417 | else if (*p == '(') | |
8418 | { | |
8419 | /* It's a function-like macro. */ | |
8420 | char *name = copy_string (body, p - body); | |
8421 | int argc = 0; | |
8422 | int argv_size = 1; | |
8423 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
8424 | ||
8425 | p++; | |
8426 | ||
8427 | p = consume_improper_spaces (p, body); | |
8428 | ||
8429 | /* Parse the formal argument list. */ | |
8430 | while (*p && *p != ')') | |
8431 | { | |
8432 | /* Find the extent of the current argument name. */ | |
8433 | const char *arg_start = p; | |
8434 | ||
8435 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
8436 | p++; | |
8437 | ||
8438 | if (! *p || p == arg_start) | |
4d3c2250 | 8439 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8440 | else |
8441 | { | |
8442 | /* Make sure argv has room for the new argument. */ | |
8443 | if (argc >= argv_size) | |
8444 | { | |
8445 | argv_size *= 2; | |
8446 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
8447 | } | |
8448 | ||
8449 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
8450 | } | |
8451 | ||
8452 | p = consume_improper_spaces (p, body); | |
8453 | ||
8454 | /* Consume the comma, if present. */ | |
8455 | if (*p == ',') | |
8456 | { | |
8457 | p++; | |
8458 | ||
8459 | p = consume_improper_spaces (p, body); | |
8460 | } | |
8461 | } | |
8462 | ||
8463 | if (*p == ')') | |
8464 | { | |
8465 | p++; | |
8466 | ||
8467 | if (*p == ' ') | |
8468 | /* Perfectly formed definition, no complaints. */ | |
8469 | macro_define_function (file, line, name, | |
8470 | argc, (const char **) argv, | |
8471 | p + 1); | |
8472 | else if (*p == '\0') | |
8473 | { | |
8474 | /* Complain, but do define it. */ | |
4d3c2250 | 8475 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8476 | macro_define_function (file, line, name, |
8477 | argc, (const char **) argv, | |
8478 | p); | |
8479 | } | |
8480 | else | |
8481 | /* Just complain. */ | |
4d3c2250 | 8482 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8483 | } |
8484 | else | |
8485 | /* Just complain. */ | |
4d3c2250 | 8486 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8487 | |
8488 | xfree (name); | |
8489 | { | |
8490 | int i; | |
8491 | ||
8492 | for (i = 0; i < argc; i++) | |
8493 | xfree (argv[i]); | |
8494 | } | |
8495 | xfree (argv); | |
8496 | } | |
8497 | else | |
4d3c2250 | 8498 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8499 | } |
8500 | ||
8501 | ||
8502 | static void | |
8503 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
8504 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 8505 | struct dwarf2_cu *cu) |
2e276125 JB |
8506 | { |
8507 | char *mac_ptr, *mac_end; | |
8508 | struct macro_source_file *current_file = 0; | |
8509 | ||
6502dd73 | 8510 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 8511 | { |
4d3c2250 | 8512 | complaint (&symfile_complaints, "missing .debug_macinfo section"); |
2e276125 JB |
8513 | return; |
8514 | } | |
8515 | ||
6502dd73 DJ |
8516 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
8517 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
8518 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
8519 | |
8520 | for (;;) | |
8521 | { | |
8522 | enum dwarf_macinfo_record_type macinfo_type; | |
8523 | ||
8524 | /* Do we at least have room for a macinfo type byte? */ | |
8525 | if (mac_ptr >= mac_end) | |
8526 | { | |
4d3c2250 | 8527 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8528 | return; |
8529 | } | |
8530 | ||
8531 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
8532 | mac_ptr++; | |
8533 | ||
8534 | switch (macinfo_type) | |
8535 | { | |
8536 | /* A zero macinfo type indicates the end of the macro | |
8537 | information. */ | |
8538 | case 0: | |
8539 | return; | |
8540 | ||
8541 | case DW_MACINFO_define: | |
8542 | case DW_MACINFO_undef: | |
8543 | { | |
8544 | int bytes_read; | |
8545 | int line; | |
8546 | char *body; | |
8547 | ||
8548 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8549 | mac_ptr += bytes_read; | |
8550 | body = read_string (abfd, mac_ptr, &bytes_read); | |
8551 | mac_ptr += bytes_read; | |
8552 | ||
8553 | if (! current_file) | |
4d3c2250 KB |
8554 | complaint (&symfile_complaints, |
8555 | "debug info gives macro %s outside of any file: %s", | |
8556 | macinfo_type == | |
8557 | DW_MACINFO_define ? "definition" : macinfo_type == | |
8558 | DW_MACINFO_undef ? "undefinition" : | |
8559 | "something-or-other", body); | |
2e276125 JB |
8560 | else |
8561 | { | |
8562 | if (macinfo_type == DW_MACINFO_define) | |
8563 | parse_macro_definition (current_file, line, body); | |
8564 | else if (macinfo_type == DW_MACINFO_undef) | |
8565 | macro_undef (current_file, line, body); | |
8566 | } | |
8567 | } | |
8568 | break; | |
8569 | ||
8570 | case DW_MACINFO_start_file: | |
8571 | { | |
8572 | int bytes_read; | |
8573 | int line, file; | |
8574 | ||
8575 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8576 | mac_ptr += bytes_read; | |
8577 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8578 | mac_ptr += bytes_read; | |
8579 | ||
8580 | current_file = macro_start_file (file, line, | |
8581 | current_file, comp_dir, | |
e7c27a73 | 8582 | lh, cu->objfile); |
2e276125 JB |
8583 | } |
8584 | break; | |
8585 | ||
8586 | case DW_MACINFO_end_file: | |
8587 | if (! current_file) | |
4d3c2250 KB |
8588 | complaint (&symfile_complaints, |
8589 | "macro debug info has an unmatched `close_file' directive"); | |
2e276125 JB |
8590 | else |
8591 | { | |
8592 | current_file = current_file->included_by; | |
8593 | if (! current_file) | |
8594 | { | |
8595 | enum dwarf_macinfo_record_type next_type; | |
8596 | ||
8597 | /* GCC circa March 2002 doesn't produce the zero | |
8598 | type byte marking the end of the compilation | |
8599 | unit. Complain if it's not there, but exit no | |
8600 | matter what. */ | |
8601 | ||
8602 | /* Do we at least have room for a macinfo type byte? */ | |
8603 | if (mac_ptr >= mac_end) | |
8604 | { | |
4d3c2250 | 8605 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8606 | return; |
8607 | } | |
8608 | ||
8609 | /* We don't increment mac_ptr here, so this is just | |
8610 | a look-ahead. */ | |
8611 | next_type = read_1_byte (abfd, mac_ptr); | |
8612 | if (next_type != 0) | |
4d3c2250 KB |
8613 | complaint (&symfile_complaints, |
8614 | "no terminating 0-type entry for macros in `.debug_macinfo' section"); | |
2e276125 JB |
8615 | |
8616 | return; | |
8617 | } | |
8618 | } | |
8619 | break; | |
8620 | ||
8621 | case DW_MACINFO_vendor_ext: | |
8622 | { | |
8623 | int bytes_read; | |
8624 | int constant; | |
8625 | char *string; | |
8626 | ||
8627 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8628 | mac_ptr += bytes_read; | |
8629 | string = read_string (abfd, mac_ptr, &bytes_read); | |
8630 | mac_ptr += bytes_read; | |
8631 | ||
8632 | /* We don't recognize any vendor extensions. */ | |
8633 | } | |
8634 | break; | |
8635 | } | |
8636 | } | |
8637 | } | |
8e19ed76 PS |
8638 | |
8639 | /* Check if the attribute's form is a DW_FORM_block* | |
8640 | if so return true else false. */ | |
8641 | static int | |
8642 | attr_form_is_block (struct attribute *attr) | |
8643 | { | |
8644 | return (attr == NULL ? 0 : | |
8645 | attr->form == DW_FORM_block1 | |
8646 | || attr->form == DW_FORM_block2 | |
8647 | || attr->form == DW_FORM_block4 | |
8648 | || attr->form == DW_FORM_block); | |
8649 | } | |
4c2df51b DJ |
8650 | |
8651 | static void | |
8652 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8653 | struct dwarf2_cu *cu) |
4c2df51b | 8654 | { |
0d53c4c4 | 8655 | if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
4c2df51b | 8656 | { |
0d53c4c4 | 8657 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 8658 | |
4a146b47 | 8659 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8660 | sizeof (struct dwarf2_loclist_baton)); |
e7c27a73 | 8661 | baton->objfile = cu->objfile; |
4c2df51b | 8662 | |
0d53c4c4 DJ |
8663 | /* We don't know how long the location list is, but make sure we |
8664 | don't run off the edge of the section. */ | |
6502dd73 DJ |
8665 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
8666 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
8667 | baton->base_address = cu->header.base_address; |
8668 | if (cu->header.base_known == 0) | |
0d53c4c4 DJ |
8669 | complaint (&symfile_complaints, |
8670 | "Location list used without specifying the CU base address."); | |
4c2df51b | 8671 | |
a67af2b9 | 8672 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
8673 | SYMBOL_LOCATION_BATON (sym) = baton; |
8674 | } | |
8675 | else | |
8676 | { | |
8677 | struct dwarf2_locexpr_baton *baton; | |
8678 | ||
4a146b47 | 8679 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8680 | sizeof (struct dwarf2_locexpr_baton)); |
e7c27a73 | 8681 | baton->objfile = cu->objfile; |
0d53c4c4 DJ |
8682 | |
8683 | if (attr_form_is_block (attr)) | |
8684 | { | |
8685 | /* Note that we're just copying the block's data pointer | |
8686 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
8687 | info_buffer for SYM's objfile; right now we never release |
8688 | that buffer, but when we do clean up properly this may | |
8689 | need to change. */ | |
0d53c4c4 DJ |
8690 | baton->size = DW_BLOCK (attr)->size; |
8691 | baton->data = DW_BLOCK (attr)->data; | |
8692 | } | |
8693 | else | |
8694 | { | |
8695 | dwarf2_invalid_attrib_class_complaint ("location description", | |
8696 | SYMBOL_NATURAL_NAME (sym)); | |
8697 | baton->size = 0; | |
8698 | baton->data = NULL; | |
8699 | } | |
8700 | ||
a67af2b9 | 8701 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
8702 | SYMBOL_LOCATION_BATON (sym) = baton; |
8703 | } | |
4c2df51b | 8704 | } |
6502dd73 | 8705 | |
72bf9492 DJ |
8706 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
8707 | when we're finished with it. We can't free the pointer itself, but | |
8708 | release any associated storage. | |
8709 | ||
8710 | Only used during partial symbol parsing. */ | |
8711 | ||
8712 | static void | |
8713 | free_stack_comp_unit (void *data) | |
8714 | { | |
8715 | struct dwarf2_cu *cu = data; | |
8716 | ||
8717 | obstack_free (&cu->comp_unit_obstack, NULL); | |
8718 | cu->partial_dies = NULL; | |
8719 | } | |
8720 | ||
8721 | /* Allocation function for the libiberty hash table which uses an | |
8722 | obstack. */ | |
8723 | ||
8724 | static void * | |
8725 | hashtab_obstack_allocate (void *data, size_t size, size_t count) | |
8726 | { | |
8727 | unsigned int total = size * count; | |
8728 | void *ptr = obstack_alloc ((struct obstack *) data, total); | |
8729 | memset (ptr, 0, total); | |
8730 | return ptr; | |
8731 | } | |
8732 | ||
8733 | /* Trivial deallocation function for the libiberty splay tree and hash | |
8734 | table - don't deallocate anything. Rely on later deletion of the | |
8735 | obstack. */ | |
8736 | ||
8737 | static void | |
8738 | dummy_obstack_deallocate (void *object, void *data) | |
8739 | { | |
8740 | return; | |
8741 | } | |
8742 | ||
8743 | /* Trivial hash function for partial_die_info: the hash value of a DIE | |
8744 | is its offset in .debug_info for this objfile. */ | |
8745 | ||
8746 | static hashval_t | |
8747 | partial_die_hash (const void *item) | |
8748 | { | |
8749 | const struct partial_die_info *part_die = item; | |
8750 | return part_die->offset; | |
8751 | } | |
8752 | ||
8753 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
8754 | are equal if they have the same offset. */ | |
8755 | ||
8756 | static int | |
8757 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
8758 | { | |
8759 | const struct partial_die_info *part_die_lhs = item_lhs; | |
8760 | const struct partial_die_info *part_die_rhs = item_rhs; | |
8761 | return part_die_lhs->offset == part_die_rhs->offset; | |
8762 | } | |
8763 | ||
6502dd73 DJ |
8764 | void _initialize_dwarf2_read (void); |
8765 | ||
8766 | void | |
8767 | _initialize_dwarf2_read (void) | |
8768 | { | |
8769 | dwarf2_objfile_data_key = register_objfile_data (); | |
8770 | } |