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 | |
1242 | legitimally have a NULL PST_PRIVATE part, then we'll have to add a | |
1243 | dedicated field for that in the dwarf2_pinfo structure. */ | |
1244 | PST_PRIVATE (subpst) = NULL; | |
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 | ||
2112 | if (PST_PRIVATE (pst) == NULL) | |
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 | ||
2354 | if (objfile->ei.entry_point >= lowpc && | |
2355 | objfile->ei.entry_point < highpc) | |
2356 | { | |
627b3ba2 AC |
2357 | objfile->ei.deprecated_entry_file_lowpc = lowpc; |
2358 | objfile->ei.deprecated_entry_file_highpc = highpc; | |
c906108c SS |
2359 | } |
2360 | ||
e142c38c | 2361 | attr = dwarf2_attr (die, DW_AT_language, cu); |
c906108c SS |
2362 | if (attr) |
2363 | { | |
e142c38c | 2364 | set_cu_language (DW_UNSND (attr), cu); |
c906108c SS |
2365 | } |
2366 | ||
2367 | /* We assume that we're processing GCC output. */ | |
2368 | processing_gcc_compilation = 2; | |
2369 | #if 0 | |
c5aa993b JM |
2370 | /* FIXME:Do something here. */ |
2371 | if (dip->at_producer != NULL) | |
c906108c SS |
2372 | { |
2373 | handle_producer (dip->at_producer); | |
2374 | } | |
2375 | #endif | |
2376 | ||
2377 | /* The compilation unit may be in a different language or objfile, | |
2378 | zero out all remembered fundamental types. */ | |
e142c38c | 2379 | memset (cu->ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); |
c906108c SS |
2380 | |
2381 | start_symtab (name, comp_dir, lowpc); | |
2382 | record_debugformat ("DWARF 2"); | |
2383 | ||
e142c38c | 2384 | initialize_cu_func_list (cu); |
c906108c SS |
2385 | |
2386 | /* Process all dies in compilation unit. */ | |
639d11d3 | 2387 | if (die->child != NULL) |
c906108c | 2388 | { |
639d11d3 | 2389 | child_die = die->child; |
c906108c SS |
2390 | while (child_die && child_die->tag) |
2391 | { | |
e7c27a73 | 2392 | process_die (child_die, cu); |
c906108c SS |
2393 | child_die = sibling_die (child_die); |
2394 | } | |
2395 | } | |
5fb290d7 DJ |
2396 | |
2397 | /* Decode line number information if present. */ | |
e142c38c | 2398 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
5fb290d7 DJ |
2399 | if (attr) |
2400 | { | |
debd256d | 2401 | unsigned int line_offset = DW_UNSND (attr); |
e7c27a73 | 2402 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
debd256d JB |
2403 | if (line_header) |
2404 | { | |
2405 | make_cleanup ((make_cleanup_ftype *) free_line_header, | |
2406 | (void *) line_header); | |
aaa75496 | 2407 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
debd256d | 2408 | } |
5fb290d7 | 2409 | } |
debd256d | 2410 | |
2e276125 JB |
2411 | /* Decode macro information, if present. Dwarf 2 macro information |
2412 | refers to information in the line number info statement program | |
2413 | header, so we can only read it if we've read the header | |
2414 | successfully. */ | |
e142c38c | 2415 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
41ff2da1 | 2416 | if (attr && line_header) |
2e276125 JB |
2417 | { |
2418 | unsigned int macro_offset = DW_UNSND (attr); | |
2419 | dwarf_decode_macros (line_header, macro_offset, | |
e7c27a73 | 2420 | comp_dir, abfd, cu); |
2e276125 | 2421 | } |
debd256d | 2422 | do_cleanups (back_to); |
5fb290d7 DJ |
2423 | } |
2424 | ||
2425 | static void | |
e142c38c DJ |
2426 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
2427 | struct dwarf2_cu *cu) | |
5fb290d7 DJ |
2428 | { |
2429 | struct function_range *thisfn; | |
2430 | ||
2431 | thisfn = (struct function_range *) | |
7b5a2f43 | 2432 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
5fb290d7 DJ |
2433 | thisfn->name = name; |
2434 | thisfn->lowpc = lowpc; | |
2435 | thisfn->highpc = highpc; | |
2436 | thisfn->seen_line = 0; | |
2437 | thisfn->next = NULL; | |
2438 | ||
e142c38c DJ |
2439 | if (cu->last_fn == NULL) |
2440 | cu->first_fn = thisfn; | |
5fb290d7 | 2441 | else |
e142c38c | 2442 | cu->last_fn->next = thisfn; |
5fb290d7 | 2443 | |
e142c38c | 2444 | cu->last_fn = thisfn; |
c906108c SS |
2445 | } |
2446 | ||
2447 | static void | |
e7c27a73 | 2448 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2449 | { |
e7c27a73 | 2450 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2451 | struct context_stack *new; |
c906108c SS |
2452 | CORE_ADDR lowpc; |
2453 | CORE_ADDR highpc; | |
2454 | struct die_info *child_die; | |
2455 | struct attribute *attr; | |
2456 | char *name; | |
fdde2d81 DC |
2457 | const char *previous_prefix = processing_current_prefix; |
2458 | struct cleanup *back_to = NULL; | |
e142c38c | 2459 | CORE_ADDR baseaddr; |
c906108c | 2460 | |
e142c38c DJ |
2461 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
2462 | ||
2463 | name = dwarf2_linkage_name (die, cu); | |
c906108c SS |
2464 | |
2465 | /* Ignore functions with missing or empty names and functions with | |
2466 | missing or invalid low and high pc attributes. */ | |
e7c27a73 | 2467 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2468 | return; |
2469 | ||
086ed43d | 2470 | if (cu->language == language_cplus) |
fdde2d81 | 2471 | { |
086ed43d | 2472 | struct die_info *spec_die = die_specification (die, cu); |
fdde2d81 | 2473 | |
2a35147e JB |
2474 | /* NOTE: carlton/2004-01-23: We have to be careful in the |
2475 | presence of DW_AT_specification. For example, with GCC 3.4, | |
2476 | given the code | |
2477 | ||
2478 | namespace N { | |
2479 | void foo() { | |
2480 | // Definition of N::foo. | |
2481 | } | |
2482 | } | |
2483 | ||
2484 | then we'll have a tree of DIEs like this: | |
2485 | ||
2486 | 1: DW_TAG_compile_unit | |
2487 | 2: DW_TAG_namespace // N | |
2488 | 3: DW_TAG_subprogram // declaration of N::foo | |
2489 | 4: DW_TAG_subprogram // definition of N::foo | |
2490 | DW_AT_specification // refers to die #3 | |
2491 | ||
2492 | Thus, when processing die #4, we have to pretend that we're | |
2493 | in the context of its DW_AT_specification, namely the contex | |
2494 | of die #3. */ | |
fdde2d81 DC |
2495 | |
2496 | if (spec_die != NULL) | |
2497 | { | |
e142c38c | 2498 | char *specification_prefix = determine_prefix (spec_die, cu); |
fdde2d81 DC |
2499 | processing_current_prefix = specification_prefix; |
2500 | back_to = make_cleanup (xfree, specification_prefix); | |
2501 | } | |
2502 | } | |
2503 | ||
c906108c SS |
2504 | lowpc += baseaddr; |
2505 | highpc += baseaddr; | |
2506 | ||
5fb290d7 | 2507 | /* Record the function range for dwarf_decode_lines. */ |
e142c38c | 2508 | add_to_cu_func_list (name, lowpc, highpc, cu); |
5fb290d7 | 2509 | |
c906108c SS |
2510 | if (objfile->ei.entry_point >= lowpc && |
2511 | objfile->ei.entry_point < highpc) | |
2512 | { | |
2513 | objfile->ei.entry_func_lowpc = lowpc; | |
2514 | objfile->ei.entry_func_highpc = highpc; | |
2515 | } | |
2516 | ||
c906108c | 2517 | new = push_context (0, lowpc); |
e7c27a73 | 2518 | new->name = new_symbol (die, die->type, cu); |
4c2df51b | 2519 | |
4cecd739 DJ |
2520 | /* If there is a location expression for DW_AT_frame_base, record |
2521 | it. */ | |
e142c38c | 2522 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
4c2df51b | 2523 | if (attr) |
c034e007 AC |
2524 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
2525 | expression is being recorded directly in the function's symbol | |
2526 | and not in a separate frame-base object. I guess this hack is | |
2527 | to avoid adding some sort of frame-base adjunct/annex to the | |
2528 | function's symbol :-(. The problem with doing this is that it | |
2529 | results in a function symbol with a location expression that | |
2530 | has nothing to do with the location of the function, ouch! The | |
2531 | relationship should be: a function's symbol has-a frame base; a | |
2532 | frame-base has-a location expression. */ | |
e7c27a73 | 2533 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
4c2df51b | 2534 | |
e142c38c | 2535 | cu->list_in_scope = &local_symbols; |
c906108c | 2536 | |
639d11d3 | 2537 | if (die->child != NULL) |
c906108c | 2538 | { |
639d11d3 | 2539 | child_die = die->child; |
c906108c SS |
2540 | while (child_die && child_die->tag) |
2541 | { | |
e7c27a73 | 2542 | process_die (child_die, cu); |
c906108c SS |
2543 | child_die = sibling_die (child_die); |
2544 | } | |
2545 | } | |
2546 | ||
2547 | new = pop_context (); | |
2548 | /* Make a block for the local symbols within. */ | |
2549 | finish_block (new->name, &local_symbols, new->old_blocks, | |
2550 | lowpc, highpc, objfile); | |
208d8187 JB |
2551 | |
2552 | /* In C++, we can have functions nested inside functions (e.g., when | |
2553 | a function declares a class that has methods). This means that | |
2554 | when we finish processing a function scope, we may need to go | |
2555 | back to building a containing block's symbol lists. */ | |
2556 | local_symbols = new->locals; | |
2557 | param_symbols = new->params; | |
2558 | ||
921e78cf JB |
2559 | /* If we've finished processing a top-level function, subsequent |
2560 | symbols go in the file symbol list. */ | |
2561 | if (outermost_context_p ()) | |
e142c38c | 2562 | cu->list_in_scope = &file_symbols; |
fdde2d81 DC |
2563 | |
2564 | processing_current_prefix = previous_prefix; | |
2565 | if (back_to != NULL) | |
2566 | do_cleanups (back_to); | |
c906108c SS |
2567 | } |
2568 | ||
2569 | /* Process all the DIES contained within a lexical block scope. Start | |
2570 | a new scope, process the dies, and then close the scope. */ | |
2571 | ||
2572 | static void | |
e7c27a73 | 2573 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 2574 | { |
e7c27a73 | 2575 | struct objfile *objfile = cu->objfile; |
52f0bd74 | 2576 | struct context_stack *new; |
c906108c SS |
2577 | CORE_ADDR lowpc, highpc; |
2578 | struct die_info *child_die; | |
e142c38c DJ |
2579 | CORE_ADDR baseaddr; |
2580 | ||
2581 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c SS |
2582 | |
2583 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |
af34e669 DJ |
2584 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
2585 | as multiple lexical blocks? Handling children in a sane way would | |
2586 | be nasty. Might be easier to properly extend generic blocks to | |
2587 | describe ranges. */ | |
e7c27a73 | 2588 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) |
c906108c SS |
2589 | return; |
2590 | lowpc += baseaddr; | |
2591 | highpc += baseaddr; | |
2592 | ||
2593 | push_context (0, lowpc); | |
639d11d3 | 2594 | if (die->child != NULL) |
c906108c | 2595 | { |
639d11d3 | 2596 | child_die = die->child; |
c906108c SS |
2597 | while (child_die && child_die->tag) |
2598 | { | |
e7c27a73 | 2599 | process_die (child_die, cu); |
c906108c SS |
2600 | child_die = sibling_die (child_die); |
2601 | } | |
2602 | } | |
2603 | new = pop_context (); | |
2604 | ||
2605 | if (local_symbols != NULL) | |
2606 | { | |
2607 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |
2608 | highpc, objfile); | |
2609 | } | |
2610 | local_symbols = new->locals; | |
2611 | } | |
2612 | ||
af34e669 DJ |
2613 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
2614 | are present and valid, otherwise, return 0. Return -1 if the range is | |
2615 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |
c906108c | 2616 | static int |
af34e669 | 2617 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
e7c27a73 | 2618 | CORE_ADDR *highpc, struct dwarf2_cu *cu) |
c906108c | 2619 | { |
e7c27a73 DJ |
2620 | struct objfile *objfile = cu->objfile; |
2621 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c | 2622 | struct attribute *attr; |
af34e669 DJ |
2623 | bfd *obfd = objfile->obfd; |
2624 | CORE_ADDR low = 0; | |
2625 | CORE_ADDR high = 0; | |
2626 | int ret = 0; | |
c906108c | 2627 | |
e142c38c | 2628 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
c906108c | 2629 | if (attr) |
af34e669 DJ |
2630 | { |
2631 | high = DW_ADDR (attr); | |
e142c38c | 2632 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
af34e669 DJ |
2633 | if (attr) |
2634 | low = DW_ADDR (attr); | |
2635 | else | |
2636 | /* Found high w/o low attribute. */ | |
2637 | return 0; | |
2638 | ||
2639 | /* Found consecutive range of addresses. */ | |
2640 | ret = 1; | |
2641 | } | |
c906108c | 2642 | else |
af34e669 | 2643 | { |
e142c38c | 2644 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
af34e669 DJ |
2645 | if (attr != NULL) |
2646 | { | |
2647 | unsigned int addr_size = cu_header->addr_size; | |
2648 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |
2649 | /* Value of the DW_AT_ranges attribute is the offset in the | |
a604369a | 2650 | .debug_ranges section. */ |
af34e669 DJ |
2651 | unsigned int offset = DW_UNSND (attr); |
2652 | /* Base address selection entry. */ | |
0d53c4c4 DJ |
2653 | CORE_ADDR base; |
2654 | int found_base; | |
af34e669 | 2655 | int dummy; |
af34e669 DJ |
2656 | char *buffer; |
2657 | CORE_ADDR marker; | |
2658 | int low_set; | |
2659 | ||
0d53c4c4 DJ |
2660 | found_base = cu_header->base_known; |
2661 | base = cu_header->base_address; | |
a604369a | 2662 | |
6502dd73 | 2663 | if (offset >= dwarf2_per_objfile->ranges_size) |
a604369a KB |
2664 | { |
2665 | complaint (&symfile_complaints, | |
2666 | "Offset %d out of bounds for DW_AT_ranges attribute", | |
2667 | offset); | |
2668 | return 0; | |
2669 | } | |
6502dd73 | 2670 | buffer = dwarf2_per_objfile->ranges_buffer + offset; |
af34e669 | 2671 | |
af34e669 | 2672 | /* Read in the largest possible address. */ |
e7c27a73 | 2673 | marker = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2674 | if ((marker & mask) == mask) |
2675 | { | |
2676 | /* If we found the largest possible address, then | |
2677 | read the base address. */ | |
e7c27a73 | 2678 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2679 | buffer += 2 * addr_size; |
2680 | offset += 2 * addr_size; | |
2681 | found_base = 1; | |
2682 | } | |
2683 | ||
2684 | low_set = 0; | |
2685 | ||
2686 | while (1) | |
2687 | { | |
2688 | CORE_ADDR range_beginning, range_end; | |
2689 | ||
e7c27a73 | 2690 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
af34e669 | 2691 | buffer += addr_size; |
e7c27a73 | 2692 | range_end = read_address (obfd, buffer, cu, &dummy); |
af34e669 DJ |
2693 | buffer += addr_size; |
2694 | offset += 2 * addr_size; | |
2695 | ||
2696 | /* An end of list marker is a pair of zero addresses. */ | |
2697 | if (range_beginning == 0 && range_end == 0) | |
2698 | /* Found the end of list entry. */ | |
2699 | break; | |
2700 | ||
2701 | /* Each base address selection entry is a pair of 2 values. | |
2702 | The first is the largest possible address, the second is | |
2703 | the base address. Check for a base address here. */ | |
2704 | if ((range_beginning & mask) == mask) | |
2705 | { | |
2706 | /* If we found the largest possible address, then | |
2707 | read the base address. */ | |
e7c27a73 | 2708 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
af34e669 DJ |
2709 | found_base = 1; |
2710 | continue; | |
2711 | } | |
2712 | ||
2713 | if (!found_base) | |
2714 | { | |
2715 | /* We have no valid base address for the ranges | |
2716 | data. */ | |
2717 | complaint (&symfile_complaints, | |
2718 | "Invalid .debug_ranges data (no base address)"); | |
2719 | return 0; | |
2720 | } | |
2721 | ||
8f05cde5 DJ |
2722 | range_beginning += base; |
2723 | range_end += base; | |
2724 | ||
af34e669 DJ |
2725 | /* FIXME: This is recording everything as a low-high |
2726 | segment of consecutive addresses. We should have a | |
2727 | data structure for discontiguous block ranges | |
2728 | instead. */ | |
2729 | if (! low_set) | |
2730 | { | |
2731 | low = range_beginning; | |
2732 | high = range_end; | |
2733 | low_set = 1; | |
2734 | } | |
2735 | else | |
2736 | { | |
2737 | if (range_beginning < low) | |
2738 | low = range_beginning; | |
2739 | if (range_end > high) | |
2740 | high = range_end; | |
2741 | } | |
2742 | } | |
2743 | ||
2744 | if (! low_set) | |
2745 | /* If the first entry is an end-of-list marker, the range | |
2746 | describes an empty scope, i.e. no instructions. */ | |
2747 | return 0; | |
2748 | ||
2749 | ret = -1; | |
2750 | } | |
2751 | } | |
c906108c SS |
2752 | |
2753 | if (high < low) | |
2754 | return 0; | |
2755 | ||
2756 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |
2757 | eliminate duplicate copies of functions and vtables and such. | |
2758 | The linker will arbitrarily choose one and discard the others. | |
2759 | The AT_*_pc values for such functions refer to local labels in | |
2760 | these sections. If the section from that file was discarded, the | |
2761 | labels are not in the output, so the relocs get a value of 0. | |
2762 | If this is a discarded function, mark the pc bounds as invalid, | |
2763 | so that GDB will ignore it. */ | |
af34e669 | 2764 | if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) |
c906108c SS |
2765 | return 0; |
2766 | ||
2767 | *lowpc = low; | |
2768 | *highpc = high; | |
af34e669 | 2769 | return ret; |
c906108c SS |
2770 | } |
2771 | ||
fae299cd DC |
2772 | /* Get the low and high pc's represented by the scope DIE, and store |
2773 | them in *LOWPC and *HIGHPC. If the correct values can't be | |
2774 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |
2775 | ||
2776 | static void | |
2777 | get_scope_pc_bounds (struct die_info *die, | |
2778 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |
2779 | struct dwarf2_cu *cu) | |
2780 | { | |
2781 | CORE_ADDR best_low = (CORE_ADDR) -1; | |
2782 | CORE_ADDR best_high = (CORE_ADDR) 0; | |
2783 | CORE_ADDR current_low, current_high; | |
2784 | ||
2785 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |
2786 | { | |
2787 | best_low = current_low; | |
2788 | best_high = current_high; | |
2789 | } | |
2790 | else | |
2791 | { | |
2792 | struct die_info *child = die->child; | |
2793 | ||
2794 | while (child && child->tag) | |
2795 | { | |
2796 | switch (child->tag) { | |
2797 | case DW_TAG_subprogram: | |
2798 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |
2799 | { | |
2800 | best_low = min (best_low, current_low); | |
2801 | best_high = max (best_high, current_high); | |
2802 | } | |
2803 | break; | |
2804 | case DW_TAG_namespace: | |
2805 | /* FIXME: carlton/2004-01-16: Should we do this for | |
2806 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |
2807 | that current GCC's always emit the DIEs corresponding | |
2808 | to definitions of methods of classes as children of a | |
2809 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |
2810 | the DIEs giving the declarations, which could be | |
2811 | anywhere). But I don't see any reason why the | |
2812 | standards says that they have to be there. */ | |
2813 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |
2814 | ||
2815 | if (current_low != ((CORE_ADDR) -1)) | |
2816 | { | |
2817 | best_low = min (best_low, current_low); | |
2818 | best_high = max (best_high, current_high); | |
2819 | } | |
2820 | break; | |
2821 | default: | |
2822 | /* Ignore. */ | |
2823 | break; | |
2824 | } | |
2825 | ||
2826 | child = sibling_die (child); | |
2827 | } | |
2828 | } | |
2829 | ||
2830 | *lowpc = best_low; | |
2831 | *highpc = best_high; | |
2832 | } | |
2833 | ||
c906108c SS |
2834 | /* Add an aggregate field to the field list. */ |
2835 | ||
2836 | static void | |
107d2387 | 2837 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
e7c27a73 DJ |
2838 | struct dwarf2_cu *cu) |
2839 | { | |
2840 | struct objfile *objfile = cu->objfile; | |
c906108c SS |
2841 | struct nextfield *new_field; |
2842 | struct attribute *attr; | |
2843 | struct field *fp; | |
2844 | char *fieldname = ""; | |
2845 | ||
2846 | /* Allocate a new field list entry and link it in. */ | |
2847 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |
b8c9b27d | 2848 | make_cleanup (xfree, new_field); |
c906108c SS |
2849 | memset (new_field, 0, sizeof (struct nextfield)); |
2850 | new_field->next = fip->fields; | |
2851 | fip->fields = new_field; | |
2852 | fip->nfields++; | |
2853 | ||
2854 | /* Handle accessibility and virtuality of field. | |
2855 | The default accessibility for members is public, the default | |
2856 | accessibility for inheritance is private. */ | |
2857 | if (die->tag != DW_TAG_inheritance) | |
2858 | new_field->accessibility = DW_ACCESS_public; | |
2859 | else | |
2860 | new_field->accessibility = DW_ACCESS_private; | |
2861 | new_field->virtuality = DW_VIRTUALITY_none; | |
2862 | ||
e142c38c | 2863 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
2864 | if (attr) |
2865 | new_field->accessibility = DW_UNSND (attr); | |
2866 | if (new_field->accessibility != DW_ACCESS_public) | |
2867 | fip->non_public_fields = 1; | |
e142c38c | 2868 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
c906108c SS |
2869 | if (attr) |
2870 | new_field->virtuality = DW_UNSND (attr); | |
2871 | ||
2872 | fp = &new_field->field; | |
a9a9bd0f | 2873 | |
e142c38c | 2874 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
c906108c | 2875 | { |
a9a9bd0f DC |
2876 | /* Data member other than a C++ static data member. */ |
2877 | ||
c906108c | 2878 | /* Get type of field. */ |
e7c27a73 | 2879 | fp->type = die_type (die, cu); |
c906108c | 2880 | |
01ad7f36 DJ |
2881 | FIELD_STATIC_KIND (*fp) = 0; |
2882 | ||
c906108c | 2883 | /* Get bit size of field (zero if none). */ |
e142c38c | 2884 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
c906108c SS |
2885 | if (attr) |
2886 | { | |
2887 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); | |
2888 | } | |
2889 | else | |
2890 | { | |
2891 | FIELD_BITSIZE (*fp) = 0; | |
2892 | } | |
2893 | ||
2894 | /* Get bit offset of field. */ | |
e142c38c | 2895 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c SS |
2896 | if (attr) |
2897 | { | |
2898 | FIELD_BITPOS (*fp) = | |
e7c27a73 | 2899 | decode_locdesc (DW_BLOCK (attr), cu) * bits_per_byte; |
c906108c SS |
2900 | } |
2901 | else | |
2902 | FIELD_BITPOS (*fp) = 0; | |
e142c38c | 2903 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
c906108c SS |
2904 | if (attr) |
2905 | { | |
2906 | if (BITS_BIG_ENDIAN) | |
2907 | { | |
2908 | /* For big endian bits, the DW_AT_bit_offset gives the | |
c5aa993b JM |
2909 | additional bit offset from the MSB of the containing |
2910 | anonymous object to the MSB of the field. We don't | |
2911 | have to do anything special since we don't need to | |
2912 | know the size of the anonymous object. */ | |
c906108c SS |
2913 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
2914 | } | |
2915 | else | |
2916 | { | |
2917 | /* For little endian bits, compute the bit offset to the | |
c5aa993b JM |
2918 | MSB of the anonymous object, subtract off the number of |
2919 | bits from the MSB of the field to the MSB of the | |
2920 | object, and then subtract off the number of bits of | |
2921 | the field itself. The result is the bit offset of | |
2922 | the LSB of the field. */ | |
c906108c SS |
2923 | int anonymous_size; |
2924 | int bit_offset = DW_UNSND (attr); | |
2925 | ||
e142c38c | 2926 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
2927 | if (attr) |
2928 | { | |
2929 | /* The size of the anonymous object containing | |
2930 | the bit field is explicit, so use the | |
2931 | indicated size (in bytes). */ | |
2932 | anonymous_size = DW_UNSND (attr); | |
2933 | } | |
2934 | else | |
2935 | { | |
2936 | /* The size of the anonymous object containing | |
2937 | the bit field must be inferred from the type | |
2938 | attribute of the data member containing the | |
2939 | bit field. */ | |
2940 | anonymous_size = TYPE_LENGTH (fp->type); | |
2941 | } | |
2942 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte | |
2943 | - bit_offset - FIELD_BITSIZE (*fp); | |
2944 | } | |
2945 | } | |
2946 | ||
2947 | /* Get name of field. */ | |
e142c38c | 2948 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
2949 | if (attr && DW_STRING (attr)) |
2950 | fieldname = DW_STRING (attr); | |
d8151005 DJ |
2951 | |
2952 | /* The name is already allocated along with this objfile, so we don't | |
2953 | need to duplicate it for the type. */ | |
2954 | fp->name = fieldname; | |
c906108c SS |
2955 | |
2956 | /* Change accessibility for artificial fields (e.g. virtual table | |
c5aa993b | 2957 | pointer or virtual base class pointer) to private. */ |
e142c38c | 2958 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
c906108c SS |
2959 | { |
2960 | new_field->accessibility = DW_ACCESS_private; | |
2961 | fip->non_public_fields = 1; | |
2962 | } | |
2963 | } | |
a9a9bd0f | 2964 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
c906108c | 2965 | { |
a9a9bd0f DC |
2966 | /* C++ static member. */ |
2967 | ||
2968 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |
2969 | is a declaration, but all versions of G++ as of this writing | |
2970 | (so through at least 3.2.1) incorrectly generate | |
2971 | DW_TAG_variable tags. */ | |
2972 | ||
c906108c | 2973 | char *physname; |
c906108c | 2974 | |
a9a9bd0f | 2975 | /* Get name of field. */ |
e142c38c | 2976 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
2977 | if (attr && DW_STRING (attr)) |
2978 | fieldname = DW_STRING (attr); | |
2979 | else | |
c906108c SS |
2980 | return; |
2981 | ||
2df3850c | 2982 | /* Get physical name. */ |
e142c38c | 2983 | physname = dwarf2_linkage_name (die, cu); |
c906108c | 2984 | |
d8151005 DJ |
2985 | /* The name is already allocated along with this objfile, so we don't |
2986 | need to duplicate it for the type. */ | |
2987 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); | |
e7c27a73 | 2988 | FIELD_TYPE (*fp) = die_type (die, cu); |
d8151005 | 2989 | FIELD_NAME (*fp) = fieldname; |
c906108c SS |
2990 | } |
2991 | else if (die->tag == DW_TAG_inheritance) | |
2992 | { | |
2993 | /* C++ base class field. */ | |
e142c38c | 2994 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
c906108c | 2995 | if (attr) |
e7c27a73 | 2996 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), cu) |
107d2387 | 2997 | * bits_per_byte); |
c906108c | 2998 | FIELD_BITSIZE (*fp) = 0; |
01ad7f36 | 2999 | FIELD_STATIC_KIND (*fp) = 0; |
e7c27a73 | 3000 | FIELD_TYPE (*fp) = die_type (die, cu); |
c906108c SS |
3001 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
3002 | fip->nbaseclasses++; | |
3003 | } | |
3004 | } | |
3005 | ||
3006 | /* Create the vector of fields, and attach it to the type. */ | |
3007 | ||
3008 | static void | |
fba45db2 | 3009 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3010 | struct dwarf2_cu *cu) |
c906108c SS |
3011 | { |
3012 | int nfields = fip->nfields; | |
3013 | ||
3014 | /* Record the field count, allocate space for the array of fields, | |
3015 | and create blank accessibility bitfields if necessary. */ | |
3016 | TYPE_NFIELDS (type) = nfields; | |
3017 | TYPE_FIELDS (type) = (struct field *) | |
3018 | TYPE_ALLOC (type, sizeof (struct field) * nfields); | |
3019 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); | |
3020 | ||
3021 | if (fip->non_public_fields) | |
3022 | { | |
3023 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3024 | ||
3025 | TYPE_FIELD_PRIVATE_BITS (type) = | |
3026 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3027 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); | |
3028 | ||
3029 | TYPE_FIELD_PROTECTED_BITS (type) = | |
3030 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3031 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); | |
3032 | ||
3033 | TYPE_FIELD_IGNORE_BITS (type) = | |
3034 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); | |
3035 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); | |
3036 | } | |
3037 | ||
3038 | /* If the type has baseclasses, allocate and clear a bit vector for | |
3039 | TYPE_FIELD_VIRTUAL_BITS. */ | |
3040 | if (fip->nbaseclasses) | |
3041 | { | |
3042 | int num_bytes = B_BYTES (fip->nbaseclasses); | |
3043 | char *pointer; | |
3044 | ||
3045 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3046 | pointer = (char *) TYPE_ALLOC (type, num_bytes); | |
3047 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; | |
3048 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); | |
3049 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; | |
3050 | } | |
3051 | ||
3052 | /* Copy the saved-up fields into the field vector. Start from the head | |
3053 | of the list, adding to the tail of the field array, so that they end | |
3054 | up in the same order in the array in which they were added to the list. */ | |
3055 | while (nfields-- > 0) | |
3056 | { | |
3057 | TYPE_FIELD (type, nfields) = fip->fields->field; | |
3058 | switch (fip->fields->accessibility) | |
3059 | { | |
c5aa993b JM |
3060 | case DW_ACCESS_private: |
3061 | SET_TYPE_FIELD_PRIVATE (type, nfields); | |
3062 | break; | |
c906108c | 3063 | |
c5aa993b JM |
3064 | case DW_ACCESS_protected: |
3065 | SET_TYPE_FIELD_PROTECTED (type, nfields); | |
3066 | break; | |
c906108c | 3067 | |
c5aa993b JM |
3068 | case DW_ACCESS_public: |
3069 | break; | |
c906108c | 3070 | |
c5aa993b JM |
3071 | default: |
3072 | /* Unknown accessibility. Complain and treat it as public. */ | |
3073 | { | |
4d3c2250 KB |
3074 | complaint (&symfile_complaints, "unsupported accessibility %d", |
3075 | fip->fields->accessibility); | |
c5aa993b JM |
3076 | } |
3077 | break; | |
c906108c SS |
3078 | } |
3079 | if (nfields < fip->nbaseclasses) | |
3080 | { | |
3081 | switch (fip->fields->virtuality) | |
3082 | { | |
c5aa993b JM |
3083 | case DW_VIRTUALITY_virtual: |
3084 | case DW_VIRTUALITY_pure_virtual: | |
3085 | SET_TYPE_FIELD_VIRTUAL (type, nfields); | |
3086 | break; | |
c906108c SS |
3087 | } |
3088 | } | |
3089 | fip->fields = fip->fields->next; | |
3090 | } | |
3091 | } | |
3092 | ||
c906108c SS |
3093 | /* Add a member function to the proper fieldlist. */ |
3094 | ||
3095 | static void | |
107d2387 | 3096 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
e7c27a73 | 3097 | struct type *type, struct dwarf2_cu *cu) |
c906108c | 3098 | { |
e7c27a73 | 3099 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3100 | struct attribute *attr; |
3101 | struct fnfieldlist *flp; | |
3102 | int i; | |
3103 | struct fn_field *fnp; | |
3104 | char *fieldname; | |
3105 | char *physname; | |
3106 | struct nextfnfield *new_fnfield; | |
3107 | ||
2df3850c | 3108 | /* Get name of member function. */ |
e142c38c | 3109 | attr = dwarf2_attr (die, DW_AT_name, cu); |
2df3850c JM |
3110 | if (attr && DW_STRING (attr)) |
3111 | fieldname = DW_STRING (attr); | |
c906108c | 3112 | else |
2df3850c | 3113 | return; |
c906108c | 3114 | |
2df3850c | 3115 | /* Get the mangled name. */ |
e142c38c | 3116 | physname = dwarf2_linkage_name (die, cu); |
c906108c SS |
3117 | |
3118 | /* Look up member function name in fieldlist. */ | |
3119 | for (i = 0; i < fip->nfnfields; i++) | |
3120 | { | |
27bfe10e | 3121 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
c906108c SS |
3122 | break; |
3123 | } | |
3124 | ||
3125 | /* Create new list element if necessary. */ | |
3126 | if (i < fip->nfnfields) | |
3127 | flp = &fip->fnfieldlists[i]; | |
3128 | else | |
3129 | { | |
3130 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3131 | { | |
3132 | fip->fnfieldlists = (struct fnfieldlist *) | |
3133 | xrealloc (fip->fnfieldlists, | |
3134 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3135 | * sizeof (struct fnfieldlist)); |
c906108c | 3136 | if (fip->nfnfields == 0) |
c13c43fd | 3137 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
c906108c SS |
3138 | } |
3139 | flp = &fip->fnfieldlists[fip->nfnfields]; | |
3140 | flp->name = fieldname; | |
3141 | flp->length = 0; | |
3142 | flp->head = NULL; | |
3143 | fip->nfnfields++; | |
3144 | } | |
3145 | ||
3146 | /* Create a new member function field and chain it to the field list | |
3147 | entry. */ | |
3148 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |
b8c9b27d | 3149 | make_cleanup (xfree, new_fnfield); |
c906108c SS |
3150 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
3151 | new_fnfield->next = flp->head; | |
3152 | flp->head = new_fnfield; | |
3153 | flp->length++; | |
3154 | ||
3155 | /* Fill in the member function field info. */ | |
3156 | fnp = &new_fnfield->fnfield; | |
d8151005 DJ |
3157 | /* The name is already allocated along with this objfile, so we don't |
3158 | need to duplicate it for the type. */ | |
3159 | fnp->physname = physname ? physname : ""; | |
c906108c SS |
3160 | fnp->type = alloc_type (objfile); |
3161 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) | |
3162 | { | |
c906108c | 3163 | int nparams = TYPE_NFIELDS (die->type); |
c906108c | 3164 | |
e26fb1d7 DC |
3165 | /* TYPE is the domain of this method, and DIE->TYPE is the type |
3166 | of the method itself (TYPE_CODE_METHOD). */ | |
3167 | smash_to_method_type (fnp->type, type, | |
ad2f7632 DJ |
3168 | TYPE_TARGET_TYPE (die->type), |
3169 | TYPE_FIELDS (die->type), | |
3170 | TYPE_NFIELDS (die->type), | |
3171 | TYPE_VARARGS (die->type)); | |
c906108c SS |
3172 | |
3173 | /* Handle static member functions. | |
c5aa993b JM |
3174 | Dwarf2 has no clean way to discern C++ static and non-static |
3175 | member functions. G++ helps GDB by marking the first | |
3176 | parameter for non-static member functions (which is the | |
3177 | this pointer) as artificial. We obtain this information | |
3178 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |
c906108c SS |
3179 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
3180 | fnp->voffset = VOFFSET_STATIC; | |
3181 | } | |
3182 | else | |
4d3c2250 KB |
3183 | complaint (&symfile_complaints, "member function type missing for '%s'", |
3184 | physname); | |
c906108c SS |
3185 | |
3186 | /* Get fcontext from DW_AT_containing_type if present. */ | |
e142c38c | 3187 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
e7c27a73 | 3188 | fnp->fcontext = die_containing_type (die, cu); |
c906108c SS |
3189 | |
3190 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |
3191 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |
3192 | ||
3193 | /* Get accessibility. */ | |
e142c38c | 3194 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
c906108c SS |
3195 | if (attr) |
3196 | { | |
3197 | switch (DW_UNSND (attr)) | |
3198 | { | |
c5aa993b JM |
3199 | case DW_ACCESS_private: |
3200 | fnp->is_private = 1; | |
3201 | break; | |
3202 | case DW_ACCESS_protected: | |
3203 | fnp->is_protected = 1; | |
3204 | break; | |
c906108c SS |
3205 | } |
3206 | } | |
3207 | ||
b02dede2 | 3208 | /* Check for artificial methods. */ |
e142c38c | 3209 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
b02dede2 DJ |
3210 | if (attr && DW_UNSND (attr) != 0) |
3211 | fnp->is_artificial = 1; | |
3212 | ||
c906108c | 3213 | /* Get index in virtual function table if it is a virtual member function. */ |
e142c38c | 3214 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
c906108c | 3215 | if (attr) |
8e19ed76 PS |
3216 | { |
3217 | /* Support the .debug_loc offsets */ | |
3218 | if (attr_form_is_block (attr)) | |
3219 | { | |
e7c27a73 | 3220 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
8e19ed76 PS |
3221 | } |
3222 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3223 | { | |
4d3c2250 | 3224 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3225 | } |
3226 | else | |
3227 | { | |
4d3c2250 KB |
3228 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
3229 | fieldname); | |
8e19ed76 PS |
3230 | } |
3231 | } | |
c906108c SS |
3232 | } |
3233 | ||
3234 | /* Create the vector of member function fields, and attach it to the type. */ | |
3235 | ||
3236 | static void | |
fba45db2 | 3237 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
e7c27a73 | 3238 | struct dwarf2_cu *cu) |
c906108c SS |
3239 | { |
3240 | struct fnfieldlist *flp; | |
3241 | int total_length = 0; | |
3242 | int i; | |
3243 | ||
3244 | ALLOCATE_CPLUS_STRUCT_TYPE (type); | |
3245 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) | |
3246 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); | |
3247 | ||
3248 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |
3249 | { | |
3250 | struct nextfnfield *nfp = flp->head; | |
3251 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); | |
3252 | int k; | |
3253 | ||
3254 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; | |
3255 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; | |
3256 | fn_flp->fn_fields = (struct fn_field *) | |
3257 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); | |
3258 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |
c5aa993b | 3259 | fn_flp->fn_fields[k] = nfp->fnfield; |
c906108c SS |
3260 | |
3261 | total_length += flp->length; | |
3262 | } | |
3263 | ||
3264 | TYPE_NFN_FIELDS (type) = fip->nfnfields; | |
3265 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; | |
3266 | } | |
3267 | ||
3268 | /* Called when we find the DIE that starts a structure or union scope | |
3269 | (definition) to process all dies that define the members of the | |
3270 | structure or union. | |
3271 | ||
3272 | NOTE: we need to call struct_type regardless of whether or not the | |
3273 | DIE has an at_name attribute, since it might be an anonymous | |
3274 | structure or union. This gets the type entered into our set of | |
3275 | user defined types. | |
3276 | ||
3277 | However, if the structure is incomplete (an opaque struct/union) | |
3278 | then suppress creating a symbol table entry for it since gdb only | |
3279 | wants to find the one with the complete definition. Note that if | |
3280 | it is complete, we just call new_symbol, which does it's own | |
3281 | checking about whether the struct/union is anonymous or not (and | |
3282 | suppresses creating a symbol table entry itself). */ | |
3283 | ||
3284 | static void | |
134d01f1 | 3285 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3286 | { |
e7c27a73 | 3287 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3288 | struct type *type; |
3289 | struct attribute *attr; | |
63d06c5c DC |
3290 | const char *previous_prefix = processing_current_prefix; |
3291 | struct cleanup *back_to = NULL; | |
c906108c | 3292 | |
134d01f1 DJ |
3293 | if (die->type) |
3294 | return; | |
3295 | ||
c906108c SS |
3296 | type = alloc_type (objfile); |
3297 | ||
3298 | INIT_CPLUS_SPECIFIC (type); | |
e142c38c | 3299 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3300 | if (attr && DW_STRING (attr)) |
3301 | { | |
e142c38c | 3302 | if (cu->language == language_cplus) |
63d06c5c | 3303 | { |
8176b9b8 DC |
3304 | char *new_prefix = determine_class_name (die, cu); |
3305 | TYPE_TAG_NAME (type) = obsavestring (new_prefix, | |
3306 | strlen (new_prefix), | |
3307 | &objfile->objfile_obstack); | |
3308 | back_to = make_cleanup (xfree, new_prefix); | |
63d06c5c DC |
3309 | processing_current_prefix = new_prefix; |
3310 | } | |
3311 | else | |
3312 | { | |
d8151005 DJ |
3313 | /* The name is already allocated along with this objfile, so |
3314 | we don't need to duplicate it for the type. */ | |
8176b9b8 | 3315 | TYPE_TAG_NAME (type) = DW_STRING (attr); |
63d06c5c | 3316 | } |
c906108c SS |
3317 | } |
3318 | ||
3319 | if (die->tag == DW_TAG_structure_type) | |
3320 | { | |
3321 | TYPE_CODE (type) = TYPE_CODE_STRUCT; | |
3322 | } | |
3323 | else if (die->tag == DW_TAG_union_type) | |
3324 | { | |
3325 | TYPE_CODE (type) = TYPE_CODE_UNION; | |
3326 | } | |
3327 | else | |
3328 | { | |
3329 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |
c5aa993b | 3330 | in gdbtypes.h. */ |
c906108c SS |
3331 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
3332 | } | |
3333 | ||
e142c38c | 3334 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3335 | if (attr) |
3336 | { | |
3337 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3338 | } | |
3339 | else | |
3340 | { | |
3341 | TYPE_LENGTH (type) = 0; | |
3342 | } | |
3343 | ||
dc718098 JB |
3344 | if (die_is_declaration (die, cu)) |
3345 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; | |
3346 | ||
c906108c SS |
3347 | /* We need to add the type field to the die immediately so we don't |
3348 | infinitely recurse when dealing with pointers to the structure | |
3349 | type within the structure itself. */ | |
3350 | die->type = type; | |
3351 | ||
e142c38c | 3352 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
c906108c SS |
3353 | { |
3354 | struct field_info fi; | |
3355 | struct die_info *child_die; | |
3356 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); | |
3357 | ||
3358 | memset (&fi, 0, sizeof (struct field_info)); | |
3359 | ||
639d11d3 | 3360 | child_die = die->child; |
c906108c SS |
3361 | |
3362 | while (child_die && child_die->tag) | |
3363 | { | |
a9a9bd0f DC |
3364 | if (child_die->tag == DW_TAG_member |
3365 | || child_die->tag == DW_TAG_variable) | |
c906108c | 3366 | { |
a9a9bd0f DC |
3367 | /* NOTE: carlton/2002-11-05: A C++ static data member |
3368 | should be a DW_TAG_member that is a declaration, but | |
3369 | all versions of G++ as of this writing (so through at | |
3370 | least 3.2.1) incorrectly generate DW_TAG_variable | |
3371 | tags for them instead. */ | |
e7c27a73 | 3372 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3373 | } |
8713b1b1 | 3374 | else if (child_die->tag == DW_TAG_subprogram) |
c906108c SS |
3375 | { |
3376 | /* C++ member function. */ | |
134d01f1 | 3377 | read_type_die (child_die, cu); |
e7c27a73 | 3378 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
c906108c SS |
3379 | } |
3380 | else if (child_die->tag == DW_TAG_inheritance) | |
3381 | { | |
3382 | /* C++ base class field. */ | |
e7c27a73 | 3383 | dwarf2_add_field (&fi, child_die, cu); |
c906108c | 3384 | } |
c906108c SS |
3385 | child_die = sibling_die (child_die); |
3386 | } | |
3387 | ||
3388 | /* Attach fields and member functions to the type. */ | |
3389 | if (fi.nfields) | |
e7c27a73 | 3390 | dwarf2_attach_fields_to_type (&fi, type, cu); |
c906108c SS |
3391 | if (fi.nfnfields) |
3392 | { | |
e7c27a73 | 3393 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
c906108c | 3394 | |
c5aa993b | 3395 | /* Get the type which refers to the base class (possibly this |
c906108c SS |
3396 | class itself) which contains the vtable pointer for the current |
3397 | class from the DW_AT_containing_type attribute. */ | |
3398 | ||
e142c38c | 3399 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
c906108c | 3400 | { |
e7c27a73 | 3401 | struct type *t = die_containing_type (die, cu); |
c906108c SS |
3402 | |
3403 | TYPE_VPTR_BASETYPE (type) = t; | |
3404 | if (type == t) | |
3405 | { | |
c5aa993b JM |
3406 | static const char vptr_name[] = |
3407 | {'_', 'v', 'p', 't', 'r', '\0'}; | |
c906108c SS |
3408 | int i; |
3409 | ||
3410 | /* Our own class provides vtbl ptr. */ | |
3411 | for (i = TYPE_NFIELDS (t) - 1; | |
3412 | i >= TYPE_N_BASECLASSES (t); | |
3413 | --i) | |
3414 | { | |
3415 | char *fieldname = TYPE_FIELD_NAME (t, i); | |
3416 | ||
27bfe10e JB |
3417 | if ((strncmp (fieldname, vptr_name, |
3418 | strlen (vptr_name) - 1) | |
3419 | == 0) | |
c906108c SS |
3420 | && is_cplus_marker (fieldname[strlen (vptr_name)])) |
3421 | { | |
3422 | TYPE_VPTR_FIELDNO (type) = i; | |
3423 | break; | |
3424 | } | |
3425 | } | |
3426 | ||
3427 | /* Complain if virtual function table field not found. */ | |
3428 | if (i < TYPE_N_BASECLASSES (t)) | |
4d3c2250 KB |
3429 | complaint (&symfile_complaints, |
3430 | "virtual function table pointer not found when defining class '%s'", | |
3431 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : | |
3432 | ""); | |
c906108c SS |
3433 | } |
3434 | else | |
3435 | { | |
3436 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); | |
3437 | } | |
3438 | } | |
3439 | } | |
3440 | ||
c906108c SS |
3441 | do_cleanups (back_to); |
3442 | } | |
63d06c5c DC |
3443 | |
3444 | processing_current_prefix = previous_prefix; | |
3445 | if (back_to != NULL) | |
3446 | do_cleanups (back_to); | |
c906108c SS |
3447 | } |
3448 | ||
134d01f1 DJ |
3449 | static void |
3450 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3451 | { | |
3452 | struct objfile *objfile = cu->objfile; | |
3453 | const char *previous_prefix = processing_current_prefix; | |
90aeadfc | 3454 | struct die_info *child_die = die->child; |
c906108c | 3455 | |
134d01f1 DJ |
3456 | if (TYPE_TAG_NAME (die->type) != NULL) |
3457 | processing_current_prefix = TYPE_TAG_NAME (die->type); | |
c906108c | 3458 | |
90aeadfc DC |
3459 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
3460 | snapshots) has been known to create a die giving a declaration | |
3461 | for a class that has, as a child, a die giving a definition for a | |
3462 | nested class. So we have to process our children even if the | |
3463 | current die is a declaration. Normally, of course, a declaration | |
3464 | won't have any children at all. */ | |
134d01f1 | 3465 | |
90aeadfc DC |
3466 | while (child_die != NULL && child_die->tag) |
3467 | { | |
3468 | if (child_die->tag == DW_TAG_member | |
3469 | || child_die->tag == DW_TAG_variable | |
3470 | || child_die->tag == DW_TAG_inheritance) | |
134d01f1 | 3471 | { |
90aeadfc | 3472 | /* Do nothing. */ |
134d01f1 | 3473 | } |
90aeadfc DC |
3474 | else |
3475 | process_die (child_die, cu); | |
134d01f1 | 3476 | |
90aeadfc | 3477 | child_die = sibling_die (child_die); |
134d01f1 DJ |
3478 | } |
3479 | ||
90aeadfc DC |
3480 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
3481 | new_symbol (die, die->type, cu); | |
3482 | ||
134d01f1 DJ |
3483 | processing_current_prefix = previous_prefix; |
3484 | } | |
3485 | ||
3486 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |
3487 | complete the type's fields yet, or create any symbols. */ | |
c906108c SS |
3488 | |
3489 | static void | |
134d01f1 | 3490 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3491 | { |
e7c27a73 | 3492 | struct objfile *objfile = cu->objfile; |
c906108c | 3493 | struct type *type; |
c906108c | 3494 | struct attribute *attr; |
134d01f1 DJ |
3495 | |
3496 | if (die->type) | |
3497 | return; | |
c906108c SS |
3498 | |
3499 | type = alloc_type (objfile); | |
3500 | ||
3501 | TYPE_CODE (type) = TYPE_CODE_ENUM; | |
e142c38c | 3502 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
3503 | if (attr && DW_STRING (attr)) |
3504 | { | |
d8151005 | 3505 | char *name = DW_STRING (attr); |
63d06c5c DC |
3506 | |
3507 | if (processing_has_namespace_info) | |
3508 | { | |
b99607ea | 3509 | TYPE_TAG_NAME (type) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
3510 | processing_current_prefix, |
3511 | processing_current_prefix[0] == '\0' | |
3512 | ? "" : "::", | |
3513 | name); | |
3514 | } | |
3515 | else | |
3516 | { | |
d8151005 DJ |
3517 | /* The name is already allocated along with this objfile, so |
3518 | we don't need to duplicate it for the type. */ | |
3519 | TYPE_TAG_NAME (type) = name; | |
63d06c5c | 3520 | } |
c906108c SS |
3521 | } |
3522 | ||
e142c38c | 3523 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3524 | if (attr) |
3525 | { | |
3526 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3527 | } | |
3528 | else | |
3529 | { | |
3530 | TYPE_LENGTH (type) = 0; | |
3531 | } | |
3532 | ||
134d01f1 DJ |
3533 | die->type = type; |
3534 | } | |
3535 | ||
8176b9b8 DC |
3536 | /* Determine the name of the type represented by DIE, which should be |
3537 | a named C++ compound type. Return the name in question; the caller | |
3538 | is responsible for xfree()'ing it. */ | |
3539 | ||
3540 | static char * | |
3541 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |
3542 | { | |
3543 | struct cleanup *back_to = NULL; | |
3544 | struct die_info *spec_die = die_specification (die, cu); | |
3545 | char *new_prefix = NULL; | |
3546 | ||
3547 | /* If this is the definition of a class that is declared by another | |
3548 | die, then processing_current_prefix may not be accurate; see | |
3549 | read_func_scope for a similar example. */ | |
3550 | if (spec_die != NULL) | |
3551 | { | |
3552 | char *specification_prefix = determine_prefix (spec_die, cu); | |
3553 | processing_current_prefix = specification_prefix; | |
3554 | back_to = make_cleanup (xfree, specification_prefix); | |
3555 | } | |
3556 | ||
3557 | /* If we don't have namespace debug info, guess the name by trying | |
3558 | to demangle the names of members, just like we did in | |
72bf9492 | 3559 | guess_structure_name. */ |
8176b9b8 DC |
3560 | if (!processing_has_namespace_info) |
3561 | { | |
3562 | struct die_info *child; | |
3563 | ||
3564 | for (child = die->child; | |
3565 | child != NULL && child->tag != 0; | |
3566 | child = sibling_die (child)) | |
3567 | { | |
3568 | if (child->tag == DW_TAG_subprogram) | |
3569 | { | |
3570 | new_prefix = class_name_from_physname (dwarf2_linkage_name | |
3571 | (child, cu)); | |
3572 | ||
3573 | if (new_prefix != NULL) | |
3574 | break; | |
3575 | } | |
3576 | } | |
3577 | } | |
3578 | ||
3579 | if (new_prefix == NULL) | |
3580 | { | |
3581 | const char *name = dwarf2_name (die, cu); | |
3582 | new_prefix = typename_concat (processing_current_prefix, | |
3583 | name ? name : "<<anonymous>>"); | |
3584 | } | |
3585 | ||
3586 | if (back_to != NULL) | |
3587 | do_cleanups (back_to); | |
3588 | ||
3589 | return new_prefix; | |
3590 | } | |
3591 | ||
134d01f1 DJ |
3592 | /* Given a pointer to a die which begins an enumeration, process all |
3593 | the dies that define the members of the enumeration, and create the | |
3594 | symbol for the enumeration type. | |
3595 | ||
3596 | NOTE: We reverse the order of the element list. */ | |
3597 | ||
3598 | static void | |
3599 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |
3600 | { | |
3601 | struct objfile *objfile = cu->objfile; | |
3602 | struct die_info *child_die; | |
3603 | struct field *fields; | |
3604 | struct attribute *attr; | |
3605 | struct symbol *sym; | |
3606 | int num_fields; | |
3607 | int unsigned_enum = 1; | |
3608 | ||
c906108c SS |
3609 | num_fields = 0; |
3610 | fields = NULL; | |
639d11d3 | 3611 | if (die->child != NULL) |
c906108c | 3612 | { |
639d11d3 | 3613 | child_die = die->child; |
c906108c SS |
3614 | while (child_die && child_die->tag) |
3615 | { | |
3616 | if (child_die->tag != DW_TAG_enumerator) | |
3617 | { | |
e7c27a73 | 3618 | process_die (child_die, cu); |
c906108c SS |
3619 | } |
3620 | else | |
3621 | { | |
e142c38c | 3622 | attr = dwarf2_attr (child_die, DW_AT_name, cu); |
c906108c SS |
3623 | if (attr) |
3624 | { | |
134d01f1 | 3625 | sym = new_symbol (child_die, die->type, cu); |
c906108c SS |
3626 | if (SYMBOL_VALUE (sym) < 0) |
3627 | unsigned_enum = 0; | |
3628 | ||
3629 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) | |
3630 | { | |
3631 | fields = (struct field *) | |
3632 | xrealloc (fields, | |
3633 | (num_fields + DW_FIELD_ALLOC_CHUNK) | |
c5aa993b | 3634 | * sizeof (struct field)); |
c906108c SS |
3635 | } |
3636 | ||
22abf04a | 3637 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
c906108c SS |
3638 | FIELD_TYPE (fields[num_fields]) = NULL; |
3639 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); | |
3640 | FIELD_BITSIZE (fields[num_fields]) = 0; | |
01ad7f36 | 3641 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
c906108c SS |
3642 | |
3643 | num_fields++; | |
3644 | } | |
3645 | } | |
3646 | ||
3647 | child_die = sibling_die (child_die); | |
3648 | } | |
3649 | ||
3650 | if (num_fields) | |
3651 | { | |
134d01f1 DJ |
3652 | TYPE_NFIELDS (die->type) = num_fields; |
3653 | TYPE_FIELDS (die->type) = (struct field *) | |
3654 | TYPE_ALLOC (die->type, sizeof (struct field) * num_fields); | |
3655 | memcpy (TYPE_FIELDS (die->type), fields, | |
c906108c | 3656 | sizeof (struct field) * num_fields); |
b8c9b27d | 3657 | xfree (fields); |
c906108c SS |
3658 | } |
3659 | if (unsigned_enum) | |
134d01f1 | 3660 | TYPE_FLAGS (die->type) |= TYPE_FLAG_UNSIGNED; |
c906108c | 3661 | } |
134d01f1 DJ |
3662 | |
3663 | new_symbol (die, die->type, cu); | |
c906108c SS |
3664 | } |
3665 | ||
3666 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |
3667 | the DIE's type field. For now, this only handles one dimensional | |
3668 | arrays. */ | |
3669 | ||
3670 | static void | |
e7c27a73 | 3671 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3672 | { |
e7c27a73 | 3673 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3674 | struct die_info *child_die; |
3675 | struct type *type = NULL; | |
3676 | struct type *element_type, *range_type, *index_type; | |
3677 | struct type **range_types = NULL; | |
3678 | struct attribute *attr; | |
3679 | int ndim = 0; | |
3680 | struct cleanup *back_to; | |
3681 | ||
3682 | /* Return if we've already decoded this type. */ | |
3683 | if (die->type) | |
3684 | { | |
3685 | return; | |
3686 | } | |
3687 | ||
e7c27a73 | 3688 | element_type = die_type (die, cu); |
c906108c SS |
3689 | |
3690 | /* Irix 6.2 native cc creates array types without children for | |
3691 | arrays with unspecified length. */ | |
639d11d3 | 3692 | if (die->child == NULL) |
c906108c | 3693 | { |
e142c38c | 3694 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c SS |
3695 | range_type = create_range_type (NULL, index_type, 0, -1); |
3696 | die->type = create_array_type (NULL, element_type, range_type); | |
3697 | return; | |
3698 | } | |
3699 | ||
3700 | back_to = make_cleanup (null_cleanup, NULL); | |
639d11d3 | 3701 | child_die = die->child; |
c906108c SS |
3702 | while (child_die && child_die->tag) |
3703 | { | |
3704 | if (child_die->tag == DW_TAG_subrange_type) | |
3705 | { | |
a02abb62 | 3706 | read_subrange_type (child_die, cu); |
c906108c | 3707 | |
a02abb62 JB |
3708 | if (child_die->type != NULL) |
3709 | { | |
3710 | /* The range type was succesfully read. Save it for | |
3711 | the array type creation. */ | |
3712 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) | |
3713 | { | |
3714 | range_types = (struct type **) | |
3715 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) | |
3716 | * sizeof (struct type *)); | |
3717 | if (ndim == 0) | |
3718 | make_cleanup (free_current_contents, &range_types); | |
3719 | } | |
3720 | range_types[ndim++] = child_die->type; | |
3721 | } | |
c906108c SS |
3722 | } |
3723 | child_die = sibling_die (child_die); | |
3724 | } | |
3725 | ||
3726 | /* Dwarf2 dimensions are output from left to right, create the | |
3727 | necessary array types in backwards order. */ | |
3728 | type = element_type; | |
3729 | while (ndim-- > 0) | |
3730 | type = create_array_type (NULL, type, range_types[ndim]); | |
3731 | ||
f5f8a009 EZ |
3732 | /* Understand Dwarf2 support for vector types (like they occur on |
3733 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |
3734 | array type. This is not part of the Dwarf2/3 standard yet, but a | |
3735 | custom vendor extension. The main difference between a regular | |
3736 | array and the vector variant is that vectors are passed by value | |
3737 | to functions. */ | |
e142c38c | 3738 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
f5f8a009 EZ |
3739 | if (attr) |
3740 | TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; | |
3741 | ||
c906108c SS |
3742 | do_cleanups (back_to); |
3743 | ||
3744 | /* Install the type in the die. */ | |
3745 | die->type = type; | |
3746 | } | |
3747 | ||
3748 | /* First cut: install each common block member as a global variable. */ | |
3749 | ||
3750 | static void | |
e7c27a73 | 3751 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
3752 | { |
3753 | struct die_info *child_die; | |
3754 | struct attribute *attr; | |
3755 | struct symbol *sym; | |
3756 | CORE_ADDR base = (CORE_ADDR) 0; | |
3757 | ||
e142c38c | 3758 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
3759 | if (attr) |
3760 | { | |
8e19ed76 PS |
3761 | /* Support the .debug_loc offsets */ |
3762 | if (attr_form_is_block (attr)) | |
3763 | { | |
e7c27a73 | 3764 | base = decode_locdesc (DW_BLOCK (attr), cu); |
8e19ed76 PS |
3765 | } |
3766 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |
3767 | { | |
4d3c2250 | 3768 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
3769 | } |
3770 | else | |
3771 | { | |
4d3c2250 KB |
3772 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
3773 | "common block member"); | |
8e19ed76 | 3774 | } |
c906108c | 3775 | } |
639d11d3 | 3776 | if (die->child != NULL) |
c906108c | 3777 | { |
639d11d3 | 3778 | child_die = die->child; |
c906108c SS |
3779 | while (child_die && child_die->tag) |
3780 | { | |
e7c27a73 | 3781 | sym = new_symbol (child_die, NULL, cu); |
e142c38c | 3782 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
c906108c SS |
3783 | if (attr) |
3784 | { | |
3785 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 3786 | base + decode_locdesc (DW_BLOCK (attr), cu); |
c906108c SS |
3787 | add_symbol_to_list (sym, &global_symbols); |
3788 | } | |
3789 | child_die = sibling_die (child_die); | |
3790 | } | |
3791 | } | |
3792 | } | |
3793 | ||
d9fa45fe DC |
3794 | /* Read a C++ namespace. */ |
3795 | ||
d9fa45fe | 3796 | static void |
e7c27a73 | 3797 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
d9fa45fe | 3798 | { |
e7c27a73 | 3799 | struct objfile *objfile = cu->objfile; |
38d518c9 | 3800 | const char *previous_prefix = processing_current_prefix; |
63d06c5c | 3801 | const char *name; |
9219021c DC |
3802 | int is_anonymous; |
3803 | struct die_info *current_die; | |
3804 | ||
e142c38c | 3805 | name = namespace_name (die, &is_anonymous, cu); |
9219021c DC |
3806 | |
3807 | /* Now build the name of the current namespace. */ | |
3808 | ||
38d518c9 | 3809 | if (previous_prefix[0] == '\0') |
9219021c | 3810 | { |
38d518c9 | 3811 | processing_current_prefix = name; |
9219021c DC |
3812 | } |
3813 | else | |
3814 | { | |
38d518c9 | 3815 | /* We need temp_name around because processing_current_prefix |
9219021c | 3816 | is a const char *. */ |
38d518c9 | 3817 | char *temp_name = alloca (strlen (previous_prefix) |
9219021c | 3818 | + 2 + strlen(name) + 1); |
38d518c9 | 3819 | strcpy (temp_name, previous_prefix); |
9219021c DC |
3820 | strcat (temp_name, "::"); |
3821 | strcat (temp_name, name); | |
3822 | ||
38d518c9 | 3823 | processing_current_prefix = temp_name; |
9219021c DC |
3824 | } |
3825 | ||
5c4e30ca DC |
3826 | /* Add a symbol associated to this if we haven't seen the namespace |
3827 | before. Also, add a using directive if it's an anonymous | |
3828 | namespace. */ | |
9219021c | 3829 | |
e142c38c | 3830 | if (dwarf2_extension (die, cu) == NULL) |
5c4e30ca DC |
3831 | { |
3832 | struct type *type; | |
3833 | ||
3834 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |
3835 | this cast will hopefully become unnecessary. */ | |
3836 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |
38d518c9 | 3837 | (char *) processing_current_prefix, |
5c4e30ca DC |
3838 | objfile); |
3839 | TYPE_TAG_NAME (type) = TYPE_NAME (type); | |
3840 | ||
e7c27a73 | 3841 | new_symbol (die, type, cu); |
8176b9b8 | 3842 | die->type = type; |
5c4e30ca DC |
3843 | |
3844 | if (is_anonymous) | |
38d518c9 EZ |
3845 | cp_add_using_directive (processing_current_prefix, |
3846 | strlen (previous_prefix), | |
3847 | strlen (processing_current_prefix)); | |
5c4e30ca | 3848 | } |
9219021c | 3849 | |
639d11d3 | 3850 | if (die->child != NULL) |
d9fa45fe | 3851 | { |
639d11d3 | 3852 | struct die_info *child_die = die->child; |
d9fa45fe DC |
3853 | |
3854 | while (child_die && child_die->tag) | |
3855 | { | |
e7c27a73 | 3856 | process_die (child_die, cu); |
d9fa45fe DC |
3857 | child_die = sibling_die (child_die); |
3858 | } | |
3859 | } | |
9219021c | 3860 | |
38d518c9 EZ |
3861 | processing_current_prefix = previous_prefix; |
3862 | } | |
3863 | ||
3864 | /* Return the name of the namespace represented by DIE. Set | |
3865 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |
3866 | namespace. */ | |
3867 | ||
3868 | static const char * | |
e142c38c | 3869 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
38d518c9 EZ |
3870 | { |
3871 | struct die_info *current_die; | |
3872 | const char *name = NULL; | |
3873 | ||
3874 | /* Loop through the extensions until we find a name. */ | |
3875 | ||
3876 | for (current_die = die; | |
3877 | current_die != NULL; | |
e142c38c | 3878 | current_die = dwarf2_extension (die, cu)) |
38d518c9 | 3879 | { |
e142c38c | 3880 | name = dwarf2_name (current_die, cu); |
38d518c9 EZ |
3881 | if (name != NULL) |
3882 | break; | |
3883 | } | |
3884 | ||
3885 | /* Is it an anonymous namespace? */ | |
3886 | ||
3887 | *is_anonymous = (name == NULL); | |
3888 | if (*is_anonymous) | |
3889 | name = "(anonymous namespace)"; | |
3890 | ||
3891 | return name; | |
d9fa45fe DC |
3892 | } |
3893 | ||
c906108c SS |
3894 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
3895 | the user defined type vector. */ | |
3896 | ||
3897 | static void | |
e7c27a73 | 3898 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3899 | { |
e7c27a73 | 3900 | struct comp_unit_head *cu_header = &cu->header; |
c906108c | 3901 | struct type *type; |
8b2dbe47 KB |
3902 | struct attribute *attr_byte_size; |
3903 | struct attribute *attr_address_class; | |
3904 | int byte_size, addr_class; | |
c906108c SS |
3905 | |
3906 | if (die->type) | |
3907 | { | |
3908 | return; | |
3909 | } | |
3910 | ||
e7c27a73 | 3911 | type = lookup_pointer_type (die_type (die, cu)); |
8b2dbe47 | 3912 | |
e142c38c | 3913 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
8b2dbe47 KB |
3914 | if (attr_byte_size) |
3915 | byte_size = DW_UNSND (attr_byte_size); | |
c906108c | 3916 | else |
8b2dbe47 KB |
3917 | byte_size = cu_header->addr_size; |
3918 | ||
e142c38c | 3919 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
8b2dbe47 KB |
3920 | if (attr_address_class) |
3921 | addr_class = DW_UNSND (attr_address_class); | |
3922 | else | |
3923 | addr_class = DW_ADDR_none; | |
3924 | ||
3925 | /* If the pointer size or address class is different than the | |
3926 | default, create a type variant marked as such and set the | |
3927 | length accordingly. */ | |
3928 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) | |
c906108c | 3929 | { |
8b2dbe47 KB |
3930 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()) |
3931 | { | |
3932 | int type_flags; | |
3933 | ||
3934 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); | |
3935 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); | |
3936 | type = make_type_with_address_space (type, type_flags); | |
3937 | } | |
3938 | else if (TYPE_LENGTH (type) != byte_size) | |
3939 | { | |
4d3c2250 | 3940 | complaint (&symfile_complaints, "invalid pointer size %d", byte_size); |
8b2dbe47 KB |
3941 | } |
3942 | else { | |
3943 | /* Should we also complain about unhandled address classes? */ | |
3944 | } | |
c906108c | 3945 | } |
8b2dbe47 KB |
3946 | |
3947 | TYPE_LENGTH (type) = byte_size; | |
c906108c SS |
3948 | die->type = type; |
3949 | } | |
3950 | ||
3951 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |
3952 | the user defined type vector. */ | |
3953 | ||
3954 | static void | |
e7c27a73 | 3955 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3956 | { |
e7c27a73 | 3957 | struct objfile *objfile = cu->objfile; |
c906108c SS |
3958 | struct type *type; |
3959 | struct type *to_type; | |
3960 | struct type *domain; | |
3961 | ||
3962 | if (die->type) | |
3963 | { | |
3964 | return; | |
3965 | } | |
3966 | ||
3967 | type = alloc_type (objfile); | |
e7c27a73 DJ |
3968 | to_type = die_type (die, cu); |
3969 | domain = die_containing_type (die, cu); | |
c906108c SS |
3970 | smash_to_member_type (type, domain, to_type); |
3971 | ||
3972 | die->type = type; | |
3973 | } | |
3974 | ||
3975 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |
3976 | the user defined type vector. */ | |
3977 | ||
3978 | static void | |
e7c27a73 | 3979 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 3980 | { |
e7c27a73 | 3981 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
3982 | struct type *type; |
3983 | struct attribute *attr; | |
3984 | ||
3985 | if (die->type) | |
3986 | { | |
3987 | return; | |
3988 | } | |
3989 | ||
e7c27a73 | 3990 | type = lookup_reference_type (die_type (die, cu)); |
e142c38c | 3991 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
3992 | if (attr) |
3993 | { | |
3994 | TYPE_LENGTH (type) = DW_UNSND (attr); | |
3995 | } | |
3996 | else | |
3997 | { | |
107d2387 | 3998 | TYPE_LENGTH (type) = cu_header->addr_size; |
c906108c SS |
3999 | } |
4000 | die->type = type; | |
4001 | } | |
4002 | ||
4003 | static void | |
e7c27a73 | 4004 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4005 | { |
090c42a4 JB |
4006 | struct type *base_type; |
4007 | ||
c906108c SS |
4008 | if (die->type) |
4009 | { | |
4010 | return; | |
4011 | } | |
4012 | ||
e7c27a73 | 4013 | base_type = die_type (die, cu); |
090c42a4 | 4014 | die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
c906108c SS |
4015 | } |
4016 | ||
4017 | static void | |
e7c27a73 | 4018 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4019 | { |
090c42a4 JB |
4020 | struct type *base_type; |
4021 | ||
c906108c SS |
4022 | if (die->type) |
4023 | { | |
4024 | return; | |
4025 | } | |
4026 | ||
e7c27a73 | 4027 | base_type = die_type (die, cu); |
090c42a4 | 4028 | die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
c906108c SS |
4029 | } |
4030 | ||
4031 | /* Extract all information from a DW_TAG_string_type DIE and add to | |
4032 | the user defined type vector. It isn't really a user defined type, | |
4033 | but it behaves like one, with other DIE's using an AT_user_def_type | |
4034 | attribute to reference it. */ | |
4035 | ||
4036 | static void | |
e7c27a73 | 4037 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4038 | { |
e7c27a73 | 4039 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4040 | struct type *type, *range_type, *index_type, *char_type; |
4041 | struct attribute *attr; | |
4042 | unsigned int length; | |
4043 | ||
4044 | if (die->type) | |
4045 | { | |
4046 | return; | |
4047 | } | |
4048 | ||
e142c38c | 4049 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
c906108c SS |
4050 | if (attr) |
4051 | { | |
4052 | length = DW_UNSND (attr); | |
4053 | } | |
4054 | else | |
4055 | { | |
b21b22e0 | 4056 | /* check for the DW_AT_byte_size attribute */ |
e142c38c | 4057 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
b21b22e0 PS |
4058 | if (attr) |
4059 | { | |
4060 | length = DW_UNSND (attr); | |
4061 | } | |
4062 | else | |
4063 | { | |
4064 | length = 1; | |
4065 | } | |
c906108c | 4066 | } |
e142c38c | 4067 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER, cu); |
c906108c | 4068 | range_type = create_range_type (NULL, index_type, 1, length); |
e142c38c | 4069 | if (cu->language == language_fortran) |
b21b22e0 PS |
4070 | { |
4071 | /* Need to create a unique string type for bounds | |
4072 | information */ | |
4073 | type = create_string_type (0, range_type); | |
4074 | } | |
4075 | else | |
4076 | { | |
e142c38c | 4077 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR, cu); |
b21b22e0 PS |
4078 | type = create_string_type (char_type, range_type); |
4079 | } | |
c906108c SS |
4080 | die->type = type; |
4081 | } | |
4082 | ||
4083 | /* Handle DIES due to C code like: | |
4084 | ||
4085 | struct foo | |
c5aa993b JM |
4086 | { |
4087 | int (*funcp)(int a, long l); | |
4088 | int b; | |
4089 | }; | |
c906108c SS |
4090 | |
4091 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |
c5aa993b | 4092 | */ |
c906108c SS |
4093 | |
4094 | static void | |
e7c27a73 | 4095 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
4096 | { |
4097 | struct type *type; /* Type that this function returns */ | |
4098 | struct type *ftype; /* Function that returns above type */ | |
4099 | struct attribute *attr; | |
4100 | ||
4101 | /* Decode the type that this subroutine returns */ | |
4102 | if (die->type) | |
4103 | { | |
4104 | return; | |
4105 | } | |
e7c27a73 | 4106 | type = die_type (die, cu); |
c906108c SS |
4107 | ftype = lookup_function_type (type); |
4108 | ||
4109 | /* All functions in C++ have prototypes. */ | |
e142c38c | 4110 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
c906108c | 4111 | if ((attr && (DW_UNSND (attr) != 0)) |
e142c38c | 4112 | || cu->language == language_cplus) |
c906108c SS |
4113 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
4114 | ||
639d11d3 | 4115 | if (die->child != NULL) |
c906108c SS |
4116 | { |
4117 | struct die_info *child_die; | |
4118 | int nparams = 0; | |
4119 | int iparams = 0; | |
4120 | ||
4121 | /* Count the number of parameters. | |
4122 | FIXME: GDB currently ignores vararg functions, but knows about | |
4123 | vararg member functions. */ | |
639d11d3 | 4124 | child_die = die->child; |
c906108c SS |
4125 | while (child_die && child_die->tag) |
4126 | { | |
4127 | if (child_die->tag == DW_TAG_formal_parameter) | |
4128 | nparams++; | |
4129 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |
4130 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; | |
4131 | child_die = sibling_die (child_die); | |
4132 | } | |
4133 | ||
4134 | /* Allocate storage for parameters and fill them in. */ | |
4135 | TYPE_NFIELDS (ftype) = nparams; | |
4136 | TYPE_FIELDS (ftype) = (struct field *) | |
4137 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); | |
4138 | ||
639d11d3 | 4139 | child_die = die->child; |
c906108c SS |
4140 | while (child_die && child_die->tag) |
4141 | { | |
4142 | if (child_die->tag == DW_TAG_formal_parameter) | |
4143 | { | |
4144 | /* Dwarf2 has no clean way to discern C++ static and non-static | |
c5aa993b JM |
4145 | member functions. G++ helps GDB by marking the first |
4146 | parameter for non-static member functions (which is the | |
4147 | this pointer) as artificial. We pass this information | |
4148 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |
e142c38c | 4149 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
c906108c SS |
4150 | if (attr) |
4151 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); | |
4152 | else | |
4153 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; | |
e7c27a73 | 4154 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, cu); |
c906108c SS |
4155 | iparams++; |
4156 | } | |
4157 | child_die = sibling_die (child_die); | |
4158 | } | |
4159 | } | |
4160 | ||
4161 | die->type = ftype; | |
4162 | } | |
4163 | ||
4164 | static void | |
e7c27a73 | 4165 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4166 | { |
e7c27a73 | 4167 | struct objfile *objfile = cu->objfile; |
2f038fcb FF |
4168 | struct attribute *attr; |
4169 | char *name = NULL; | |
c906108c SS |
4170 | |
4171 | if (!die->type) | |
4172 | { | |
e142c38c | 4173 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c | 4174 | if (attr && DW_STRING (attr)) |
2f038fcb FF |
4175 | { |
4176 | name = DW_STRING (attr); | |
4177 | } | |
4178 | die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); | |
e7c27a73 | 4179 | TYPE_TARGET_TYPE (die->type) = die_type (die, cu); |
c906108c SS |
4180 | } |
4181 | } | |
4182 | ||
4183 | /* Find a representation of a given base type and install | |
4184 | it in the TYPE field of the die. */ | |
4185 | ||
4186 | static void | |
e7c27a73 | 4187 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 4188 | { |
e7c27a73 | 4189 | struct objfile *objfile = cu->objfile; |
c906108c SS |
4190 | struct type *type; |
4191 | struct attribute *attr; | |
4192 | int encoding = 0, size = 0; | |
4193 | ||
4194 | /* If we've already decoded this die, this is a no-op. */ | |
4195 | if (die->type) | |
4196 | { | |
4197 | return; | |
4198 | } | |
4199 | ||
e142c38c | 4200 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
c906108c SS |
4201 | if (attr) |
4202 | { | |
4203 | encoding = DW_UNSND (attr); | |
4204 | } | |
e142c38c | 4205 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
c906108c SS |
4206 | if (attr) |
4207 | { | |
4208 | size = DW_UNSND (attr); | |
4209 | } | |
e142c38c | 4210 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
4211 | if (attr && DW_STRING (attr)) |
4212 | { | |
4213 | enum type_code code = TYPE_CODE_INT; | |
f5ef7c67 | 4214 | int type_flags = 0; |
c906108c SS |
4215 | |
4216 | switch (encoding) | |
4217 | { | |
4218 | case DW_ATE_address: | |
4219 | /* Turn DW_ATE_address into a void * pointer. */ | |
4220 | code = TYPE_CODE_PTR; | |
f5ef7c67 | 4221 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4222 | break; |
4223 | case DW_ATE_boolean: | |
4224 | code = TYPE_CODE_BOOL; | |
f5ef7c67 | 4225 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4226 | break; |
4227 | case DW_ATE_complex_float: | |
4228 | code = TYPE_CODE_COMPLEX; | |
4229 | break; | |
4230 | case DW_ATE_float: | |
4231 | code = TYPE_CODE_FLT; | |
4232 | break; | |
4233 | case DW_ATE_signed: | |
4234 | case DW_ATE_signed_char: | |
4235 | break; | |
4236 | case DW_ATE_unsigned: | |
4237 | case DW_ATE_unsigned_char: | |
f5ef7c67 | 4238 | type_flags |= TYPE_FLAG_UNSIGNED; |
c906108c SS |
4239 | break; |
4240 | default: | |
4d3c2250 KB |
4241 | complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", |
4242 | dwarf_type_encoding_name (encoding)); | |
c906108c SS |
4243 | break; |
4244 | } | |
f5ef7c67 | 4245 | type = init_type (code, size, type_flags, DW_STRING (attr), objfile); |
c906108c | 4246 | if (encoding == DW_ATE_address) |
e142c38c DJ |
4247 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID, |
4248 | cu); | |
f65ca430 DJ |
4249 | else if (encoding == DW_ATE_complex_float) |
4250 | { | |
4251 | if (size == 32) | |
4252 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4253 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT, cu); |
f65ca430 DJ |
4254 | else if (size == 16) |
4255 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4256 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
f65ca430 DJ |
4257 | else if (size == 8) |
4258 | TYPE_TARGET_TYPE (type) | |
e142c38c | 4259 | = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
f65ca430 | 4260 | } |
c906108c SS |
4261 | } |
4262 | else | |
4263 | { | |
e7c27a73 | 4264 | type = dwarf_base_type (encoding, size, cu); |
c906108c SS |
4265 | } |
4266 | die->type = type; | |
4267 | } | |
4268 | ||
a02abb62 JB |
4269 | /* Read the given DW_AT_subrange DIE. */ |
4270 | ||
4271 | static void | |
4272 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) | |
4273 | { | |
4274 | struct type *base_type; | |
4275 | struct type *range_type; | |
4276 | struct attribute *attr; | |
4277 | int low = 0; | |
4278 | int high = -1; | |
4279 | ||
4280 | /* If we have already decoded this die, then nothing more to do. */ | |
4281 | if (die->type) | |
4282 | return; | |
4283 | ||
4284 | base_type = die_type (die, cu); | |
4285 | if (base_type == NULL) | |
4286 | { | |
4287 | complaint (&symfile_complaints, | |
4288 | "DW_AT_type missing from DW_TAG_subrange_type"); | |
4289 | return; | |
4290 | } | |
4291 | ||
4292 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) | |
4293 | base_type = alloc_type (NULL); | |
4294 | ||
e142c38c | 4295 | if (cu->language == language_fortran) |
a02abb62 JB |
4296 | { |
4297 | /* FORTRAN implies a lower bound of 1, if not given. */ | |
4298 | low = 1; | |
4299 | } | |
4300 | ||
e142c38c | 4301 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
a02abb62 JB |
4302 | if (attr) |
4303 | low = dwarf2_get_attr_constant_value (attr, 0); | |
4304 | ||
e142c38c | 4305 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
a02abb62 JB |
4306 | if (attr) |
4307 | { | |
4308 | if (attr->form == DW_FORM_block1) | |
4309 | { | |
4310 | /* GCC encodes arrays with unspecified or dynamic length | |
4311 | with a DW_FORM_block1 attribute. | |
4312 | FIXME: GDB does not yet know how to handle dynamic | |
4313 | arrays properly, treat them as arrays with unspecified | |
4314 | length for now. | |
4315 | ||
4316 | FIXME: jimb/2003-09-22: GDB does not really know | |
4317 | how to handle arrays of unspecified length | |
4318 | either; we just represent them as zero-length | |
4319 | arrays. Choose an appropriate upper bound given | |
4320 | the lower bound we've computed above. */ | |
4321 | high = low - 1; | |
4322 | } | |
4323 | else | |
4324 | high = dwarf2_get_attr_constant_value (attr, 1); | |
4325 | } | |
4326 | ||
4327 | range_type = create_range_type (NULL, base_type, low, high); | |
4328 | ||
e142c38c | 4329 | attr = dwarf2_attr (die, DW_AT_name, cu); |
a02abb62 JB |
4330 | if (attr && DW_STRING (attr)) |
4331 | TYPE_NAME (range_type) = DW_STRING (attr); | |
4332 | ||
e142c38c | 4333 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
a02abb62 JB |
4334 | if (attr) |
4335 | TYPE_LENGTH (range_type) = DW_UNSND (attr); | |
4336 | ||
4337 | die->type = range_type; | |
4338 | } | |
4339 | ||
4340 | ||
c906108c SS |
4341 | /* Read a whole compilation unit into a linked list of dies. */ |
4342 | ||
f9aca02d | 4343 | static struct die_info * |
e7c27a73 | 4344 | read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4345 | { |
b3810801 | 4346 | /* Reset die reference table; we are |
7f0e3f52 AC |
4347 | building new ones now. */ |
4348 | dwarf2_empty_hash_tables (); | |
c906108c | 4349 | |
e7c27a73 | 4350 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL); |
639d11d3 DC |
4351 | } |
4352 | ||
4353 | /* Read a single die and all its descendents. Set the die's sibling | |
4354 | field to NULL; set other fields in the die correctly, and set all | |
4355 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |
4356 | location of the info_ptr after reading all of those dies. PARENT | |
4357 | is the parent of the die in question. */ | |
4358 | ||
4359 | static struct die_info * | |
4360 | read_die_and_children (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4361 | struct dwarf2_cu *cu, |
639d11d3 DC |
4362 | char **new_info_ptr, |
4363 | struct die_info *parent) | |
4364 | { | |
4365 | struct die_info *die; | |
4366 | char *cur_ptr; | |
4367 | int has_children; | |
4368 | ||
e7c27a73 | 4369 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); |
639d11d3 DC |
4370 | store_in_ref_table (die->offset, die); |
4371 | ||
4372 | if (has_children) | |
4373 | { | |
e7c27a73 | 4374 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, |
639d11d3 DC |
4375 | new_info_ptr, die); |
4376 | } | |
4377 | else | |
4378 | { | |
4379 | die->child = NULL; | |
4380 | *new_info_ptr = cur_ptr; | |
4381 | } | |
4382 | ||
4383 | die->sibling = NULL; | |
4384 | die->parent = parent; | |
4385 | return die; | |
4386 | } | |
4387 | ||
4388 | /* Read a die, all of its descendents, and all of its siblings; set | |
4389 | all of the fields of all of the dies correctly. Arguments are as | |
4390 | in read_die_and_children. */ | |
4391 | ||
4392 | static struct die_info * | |
4393 | read_die_and_siblings (char *info_ptr, bfd *abfd, | |
e7c27a73 | 4394 | struct dwarf2_cu *cu, |
639d11d3 DC |
4395 | char **new_info_ptr, |
4396 | struct die_info *parent) | |
4397 | { | |
4398 | struct die_info *first_die, *last_sibling; | |
4399 | char *cur_ptr; | |
4400 | ||
c906108c | 4401 | cur_ptr = info_ptr; |
639d11d3 DC |
4402 | first_die = last_sibling = NULL; |
4403 | ||
4404 | while (1) | |
c906108c | 4405 | { |
639d11d3 | 4406 | struct die_info *die |
e7c27a73 | 4407 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); |
639d11d3 DC |
4408 | |
4409 | if (!first_die) | |
c906108c | 4410 | { |
639d11d3 | 4411 | first_die = die; |
c906108c | 4412 | } |
639d11d3 | 4413 | else |
c906108c | 4414 | { |
639d11d3 | 4415 | last_sibling->sibling = die; |
c906108c SS |
4416 | } |
4417 | ||
639d11d3 | 4418 | if (die->tag == 0) |
c906108c | 4419 | { |
639d11d3 DC |
4420 | *new_info_ptr = cur_ptr; |
4421 | return first_die; | |
c906108c SS |
4422 | } |
4423 | else | |
4424 | { | |
639d11d3 | 4425 | last_sibling = die; |
c906108c SS |
4426 | } |
4427 | } | |
c906108c SS |
4428 | } |
4429 | ||
4430 | /* Free a linked list of dies. */ | |
4431 | ||
4432 | static void | |
fba45db2 | 4433 | free_die_list (struct die_info *dies) |
c906108c SS |
4434 | { |
4435 | struct die_info *die, *next; | |
4436 | ||
4437 | die = dies; | |
4438 | while (die) | |
4439 | { | |
639d11d3 DC |
4440 | if (die->child != NULL) |
4441 | free_die_list (die->child); | |
4442 | next = die->sibling; | |
b8c9b27d KB |
4443 | xfree (die->attrs); |
4444 | xfree (die); | |
c906108c SS |
4445 | die = next; |
4446 | } | |
4447 | } | |
4448 | ||
74b7792f AC |
4449 | static void |
4450 | do_free_die_list_cleanup (void *dies) | |
4451 | { | |
4452 | free_die_list (dies); | |
4453 | } | |
4454 | ||
4455 | static struct cleanup * | |
4456 | make_cleanup_free_die_list (struct die_info *dies) | |
4457 | { | |
4458 | return make_cleanup (do_free_die_list_cleanup, dies); | |
4459 | } | |
4460 | ||
4461 | ||
c906108c | 4462 | /* Read the contents of the section at OFFSET and of size SIZE from the |
8b92e4d5 | 4463 | object file specified by OBJFILE into the objfile_obstack and return it. */ |
c906108c | 4464 | |
b6af0555 | 4465 | char * |
188dd5d6 | 4466 | dwarf2_read_section (struct objfile *objfile, asection *sectp) |
c906108c SS |
4467 | { |
4468 | bfd *abfd = objfile->obfd; | |
086df311 | 4469 | char *buf, *retbuf; |
188dd5d6 | 4470 | bfd_size_type size = bfd_get_section_size_before_reloc (sectp); |
c906108c SS |
4471 | |
4472 | if (size == 0) | |
4473 | return NULL; | |
4474 | ||
8b92e4d5 | 4475 | buf = (char *) obstack_alloc (&objfile->objfile_obstack, size); |
086df311 DJ |
4476 | retbuf |
4477 | = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); | |
4478 | if (retbuf != NULL) | |
4479 | return retbuf; | |
4480 | ||
188dd5d6 DJ |
4481 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
4482 | || bfd_bread (buf, size, abfd) != size) | |
4483 | error ("Dwarf Error: Can't read DWARF data from '%s'", | |
4484 | bfd_get_filename (abfd)); | |
4485 | ||
c906108c SS |
4486 | return buf; |
4487 | } | |
4488 | ||
4489 | /* In DWARF version 2, the description of the debugging information is | |
4490 | stored in a separate .debug_abbrev section. Before we read any | |
4491 | dies from a section we read in all abbreviations and install them | |
72bf9492 DJ |
4492 | in a hash table. This function also sets flags in CU describing |
4493 | the data found in the abbrev table. */ | |
c906108c SS |
4494 | |
4495 | static void | |
e7c27a73 | 4496 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
c906108c | 4497 | { |
e7c27a73 | 4498 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
4499 | char *abbrev_ptr; |
4500 | struct abbrev_info *cur_abbrev; | |
4501 | unsigned int abbrev_number, bytes_read, abbrev_name; | |
4502 | unsigned int abbrev_form, hash_number; | |
f3dd6933 DJ |
4503 | struct attr_abbrev *cur_attrs; |
4504 | unsigned int allocated_attrs; | |
c906108c | 4505 | |
57349743 | 4506 | /* Initialize dwarf2 abbrevs */ |
f3dd6933 DJ |
4507 | obstack_init (&cu->abbrev_obstack); |
4508 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, | |
4509 | (ABBREV_HASH_SIZE | |
4510 | * sizeof (struct abbrev_info *))); | |
4511 | memset (cu->dwarf2_abbrevs, 0, | |
4512 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); | |
c906108c | 4513 | |
6502dd73 | 4514 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; |
c906108c SS |
4515 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4516 | abbrev_ptr += bytes_read; | |
4517 | ||
f3dd6933 DJ |
4518 | allocated_attrs = ATTR_ALLOC_CHUNK; |
4519 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |
4520 | ||
c906108c SS |
4521 | /* loop until we reach an abbrev number of 0 */ |
4522 | while (abbrev_number) | |
4523 | { | |
f3dd6933 | 4524 | cur_abbrev = dwarf_alloc_abbrev (cu); |
c906108c SS |
4525 | |
4526 | /* read in abbrev header */ | |
4527 | cur_abbrev->number = abbrev_number; | |
4528 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4529 | abbrev_ptr += bytes_read; | |
4530 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |
4531 | abbrev_ptr += 1; | |
4532 | ||
72bf9492 DJ |
4533 | if (cur_abbrev->tag == DW_TAG_namespace) |
4534 | cu->has_namespace_info = 1; | |
4535 | ||
c906108c SS |
4536 | /* now read in declarations */ |
4537 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4538 | abbrev_ptr += bytes_read; | |
4539 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4540 | abbrev_ptr += bytes_read; | |
4541 | while (abbrev_name) | |
4542 | { | |
f3dd6933 | 4543 | if (cur_abbrev->num_attrs == allocated_attrs) |
c906108c | 4544 | { |
f3dd6933 DJ |
4545 | allocated_attrs += ATTR_ALLOC_CHUNK; |
4546 | cur_attrs | |
4547 | = xrealloc (cur_attrs, (allocated_attrs | |
4548 | * sizeof (struct attr_abbrev))); | |
c906108c | 4549 | } |
f3dd6933 DJ |
4550 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
4551 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |
c906108c SS |
4552 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
4553 | abbrev_ptr += bytes_read; | |
4554 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4555 | abbrev_ptr += bytes_read; | |
4556 | } | |
4557 | ||
f3dd6933 DJ |
4558 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
4559 | (cur_abbrev->num_attrs | |
4560 | * sizeof (struct attr_abbrev))); | |
4561 | memcpy (cur_abbrev->attrs, cur_attrs, | |
4562 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |
4563 | ||
c906108c | 4564 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
f3dd6933 DJ |
4565 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
4566 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |
c906108c SS |
4567 | |
4568 | /* Get next abbreviation. | |
4569 | Under Irix6 the abbreviations for a compilation unit are not | |
c5aa993b JM |
4570 | always properly terminated with an abbrev number of 0. |
4571 | Exit loop if we encounter an abbreviation which we have | |
4572 | already read (which means we are about to read the abbreviations | |
4573 | for the next compile unit) or if the end of the abbreviation | |
4574 | table is reached. */ | |
6502dd73 DJ |
4575 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) |
4576 | >= dwarf2_per_objfile->abbrev_size) | |
c906108c SS |
4577 | break; |
4578 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |
4579 | abbrev_ptr += bytes_read; | |
e7c27a73 | 4580 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
c906108c SS |
4581 | break; |
4582 | } | |
f3dd6933 DJ |
4583 | |
4584 | xfree (cur_attrs); | |
c906108c SS |
4585 | } |
4586 | ||
f3dd6933 | 4587 | /* Release the memory used by the abbrev table for a compilation unit. */ |
c906108c | 4588 | |
c906108c | 4589 | static void |
f3dd6933 | 4590 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
c906108c | 4591 | { |
f3dd6933 | 4592 | struct dwarf2_cu *cu = ptr_to_cu; |
c906108c | 4593 | |
f3dd6933 DJ |
4594 | obstack_free (&cu->abbrev_obstack, NULL); |
4595 | cu->dwarf2_abbrevs = NULL; | |
c906108c SS |
4596 | } |
4597 | ||
4598 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |
4599 | ||
4600 | static struct abbrev_info * | |
e7c27a73 | 4601 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
c906108c SS |
4602 | { |
4603 | unsigned int hash_number; | |
4604 | struct abbrev_info *abbrev; | |
4605 | ||
4606 | hash_number = number % ABBREV_HASH_SIZE; | |
f3dd6933 | 4607 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
c906108c SS |
4608 | |
4609 | while (abbrev) | |
4610 | { | |
4611 | if (abbrev->number == number) | |
4612 | return abbrev; | |
4613 | else | |
4614 | abbrev = abbrev->next; | |
4615 | } | |
4616 | return NULL; | |
4617 | } | |
4618 | ||
72bf9492 DJ |
4619 | /* Returns nonzero if TAG represents a type that we might generate a partial |
4620 | symbol for. */ | |
4621 | ||
4622 | static int | |
4623 | is_type_tag_for_partial (int tag) | |
4624 | { | |
4625 | switch (tag) | |
4626 | { | |
4627 | #if 0 | |
4628 | /* Some types that would be reasonable to generate partial symbols for, | |
4629 | that we don't at present. */ | |
4630 | case DW_TAG_array_type: | |
4631 | case DW_TAG_file_type: | |
4632 | case DW_TAG_ptr_to_member_type: | |
4633 | case DW_TAG_set_type: | |
4634 | case DW_TAG_string_type: | |
4635 | case DW_TAG_subroutine_type: | |
4636 | #endif | |
4637 | case DW_TAG_base_type: | |
4638 | case DW_TAG_class_type: | |
4639 | case DW_TAG_enumeration_type: | |
4640 | case DW_TAG_structure_type: | |
4641 | case DW_TAG_subrange_type: | |
4642 | case DW_TAG_typedef: | |
4643 | case DW_TAG_union_type: | |
4644 | return 1; | |
4645 | default: | |
4646 | return 0; | |
4647 | } | |
4648 | } | |
4649 | ||
4650 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |
4651 | ||
4652 | static struct partial_die_info * | |
4653 | load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab, | |
4654 | struct dwarf2_cu *cu) | |
4655 | { | |
4656 | struct partial_die_info *part_die; | |
4657 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; | |
4658 | struct abbrev_info *abbrev; | |
4659 | unsigned int bytes_read; | |
4660 | ||
4661 | int nesting_level = 1; | |
4662 | ||
4663 | parent_die = NULL; | |
4664 | last_die = NULL; | |
4665 | ||
4666 | cu->partial_dies | |
4667 | = htab_create_alloc_ex (cu->header.length / 12, | |
4668 | partial_die_hash, | |
4669 | partial_die_eq, | |
4670 | NULL, | |
4671 | &cu->comp_unit_obstack, | |
4672 | hashtab_obstack_allocate, | |
4673 | dummy_obstack_deallocate); | |
4674 | ||
4675 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4676 | sizeof (struct partial_die_info)); | |
4677 | ||
4678 | while (1) | |
4679 | { | |
4680 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |
4681 | ||
4682 | /* A NULL abbrev means the end of a series of children. */ | |
4683 | if (abbrev == NULL) | |
4684 | { | |
4685 | if (--nesting_level == 0) | |
4686 | { | |
4687 | /* PART_DIE was probably the last thing allocated on the | |
4688 | comp_unit_obstack, so we could call obstack_free | |
4689 | here. We don't do that because the waste is small, | |
4690 | and will be cleaned up when we're done with this | |
4691 | compilation unit. This way, we're also more robust | |
4692 | against other users of the comp_unit_obstack. */ | |
4693 | return first_die; | |
4694 | } | |
4695 | info_ptr += bytes_read; | |
4696 | last_die = parent_die; | |
4697 | parent_die = parent_die->die_parent; | |
4698 | continue; | |
4699 | } | |
4700 | ||
4701 | /* Check whether this DIE is interesting enough to save. */ | |
4702 | if (!is_type_tag_for_partial (abbrev->tag) | |
4703 | && abbrev->tag != DW_TAG_enumerator | |
4704 | && abbrev->tag != DW_TAG_subprogram | |
4705 | && abbrev->tag != DW_TAG_variable | |
4706 | && abbrev->tag != DW_TAG_namespace) | |
4707 | { | |
4708 | /* Otherwise we skip to the next sibling, if any. */ | |
4709 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |
4710 | continue; | |
4711 | } | |
4712 | ||
4713 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |
4714 | abfd, info_ptr, cu); | |
4715 | ||
4716 | /* This two-pass algorithm for processing partial symbols has a | |
4717 | high cost in cache pressure. Thus, handle some simple cases | |
4718 | here which cover the majority of C partial symbols. DIEs | |
4719 | which neither have specification tags in them, nor could have | |
4720 | specification tags elsewhere pointing at them, can simply be | |
4721 | processed and discarded. | |
4722 | ||
4723 | This segment is also optional; scan_partial_symbols and | |
4724 | add_partial_symbol will handle these DIEs if we chain | |
4725 | them in normally. When compilers which do not emit large | |
4726 | quantities of duplicate debug information are more common, | |
4727 | this code can probably be removed. */ | |
4728 | ||
4729 | /* Any complete simple types at the top level (pretty much all | |
4730 | of them, for a language without namespaces), can be processed | |
4731 | directly. */ | |
4732 | if (parent_die == NULL | |
4733 | && part_die->has_specification == 0 | |
4734 | && part_die->is_declaration == 0 | |
4735 | && (part_die->tag == DW_TAG_typedef | |
4736 | || part_die->tag == DW_TAG_base_type | |
4737 | || part_die->tag == DW_TAG_subrange_type)) | |
4738 | { | |
4739 | if (building_psymtab && part_die->name != NULL) | |
4740 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4741 | VAR_DOMAIN, LOC_TYPEDEF, | |
4742 | &cu->objfile->static_psymbols, | |
4743 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4744 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4745 | continue; | |
4746 | } | |
4747 | ||
4748 | /* If we're at the second level, and we're an enumerator, and | |
4749 | our parent has no specification (meaning possibly lives in a | |
4750 | namespace elsewhere), then we can add the partial symbol now | |
4751 | instead of queueing it. */ | |
4752 | if (part_die->tag == DW_TAG_enumerator | |
4753 | && parent_die != NULL | |
4754 | && parent_die->die_parent == NULL | |
4755 | && parent_die->tag == DW_TAG_enumeration_type | |
4756 | && parent_die->has_specification == 0) | |
4757 | { | |
4758 | if (part_die->name == NULL) | |
4759 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); | |
4760 | else if (building_psymtab) | |
4761 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |
4762 | VAR_DOMAIN, LOC_CONST, | |
4763 | cu->language == language_cplus | |
4764 | ? &cu->objfile->global_psymbols | |
4765 | : &cu->objfile->static_psymbols, | |
4766 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |
4767 | ||
4768 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |
4769 | continue; | |
4770 | } | |
4771 | ||
4772 | /* We'll save this DIE so link it in. */ | |
4773 | part_die->die_parent = parent_die; | |
4774 | part_die->die_sibling = NULL; | |
4775 | part_die->die_child = NULL; | |
4776 | ||
4777 | if (last_die && last_die == parent_die) | |
4778 | last_die->die_child = part_die; | |
4779 | else if (last_die) | |
4780 | last_die->die_sibling = part_die; | |
4781 | ||
4782 | last_die = part_die; | |
4783 | ||
4784 | if (first_die == NULL) | |
4785 | first_die = part_die; | |
4786 | ||
4787 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |
4788 | find interesting need to be in the hash table, because we | |
4789 | also have the parent/sibling/child chains; only those that we | |
4790 | might refer to by offset later during partial symbol reading. | |
4791 | ||
4792 | For now this means things that might have be the target of a | |
4793 | DW_AT_specification, DW_AT_abstract_origin, or | |
4794 | DW_AT_extension. DW_AT_extension will refer only to | |
4795 | namespaces; DW_AT_abstract_origin refers to functions (and | |
4796 | many things under the function DIE, but we do not recurse | |
4797 | into function DIEs during partial symbol reading) and | |
4798 | possibly variables as well; DW_AT_specification refers to | |
4799 | declarations. Declarations ought to have the DW_AT_declaration | |
4800 | flag. It happens that GCC forgets to put it in sometimes, but | |
4801 | only for functions, not for types. | |
4802 | ||
4803 | Adding more things than necessary to the hash table is harmless | |
4804 | except for the performance cost. Adding too few will result in | |
4805 | internal errors in find_partial_die. */ | |
4806 | ||
4807 | if (abbrev->tag == DW_TAG_subprogram | |
4808 | || abbrev->tag == DW_TAG_variable | |
4809 | || abbrev->tag == DW_TAG_namespace | |
4810 | || part_die->is_declaration) | |
4811 | { | |
4812 | void **slot; | |
4813 | ||
4814 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |
4815 | part_die->offset, INSERT); | |
4816 | *slot = part_die; | |
4817 | } | |
4818 | ||
4819 | part_die = obstack_alloc (&cu->comp_unit_obstack, | |
4820 | sizeof (struct partial_die_info)); | |
4821 | ||
4822 | /* For some DIEs we want to follow their children (if any). For C | |
4823 | we have no reason to follow the children of structures; for other | |
4824 | languages we have to, both so that we can get at method physnames | |
4825 | to infer fully qualified class names, and for DW_AT_specification. */ | |
4826 | if (last_die->has_children | |
4827 | && (last_die->tag == DW_TAG_namespace | |
4828 | || last_die->tag == DW_TAG_enumeration_type | |
4829 | || (cu->language != language_c | |
4830 | && (last_die->tag == DW_TAG_class_type | |
4831 | || last_die->tag == DW_TAG_structure_type | |
4832 | || last_die->tag == DW_TAG_union_type)))) | |
4833 | { | |
4834 | nesting_level++; | |
4835 | parent_die = last_die; | |
4836 | continue; | |
4837 | } | |
4838 | ||
4839 | /* Otherwise we skip to the next sibling, if any. */ | |
4840 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |
4841 | ||
4842 | /* Back to the top, do it again. */ | |
4843 | } | |
4844 | } | |
4845 | ||
c906108c SS |
4846 | /* Read a minimal amount of information into the minimal die structure. */ |
4847 | ||
4848 | static char * | |
72bf9492 DJ |
4849 | read_partial_die (struct partial_die_info *part_die, |
4850 | struct abbrev_info *abbrev, | |
4851 | unsigned int abbrev_len, bfd *abfd, | |
e7c27a73 | 4852 | char *info_ptr, struct dwarf2_cu *cu) |
c906108c | 4853 | { |
72bf9492 | 4854 | unsigned int bytes_read, i; |
c906108c | 4855 | struct attribute attr; |
c5aa993b | 4856 | int has_low_pc_attr = 0; |
c906108c SS |
4857 | int has_high_pc_attr = 0; |
4858 | ||
72bf9492 | 4859 | memset (part_die, 0, sizeof (struct partial_die_info)); |
c906108c | 4860 | |
6502dd73 | 4861 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; |
72bf9492 DJ |
4862 | |
4863 | info_ptr += abbrev_len; | |
4864 | ||
4865 | if (abbrev == NULL) | |
4866 | return info_ptr; | |
4867 | ||
c906108c SS |
4868 | part_die->tag = abbrev->tag; |
4869 | part_die->has_children = abbrev->has_children; | |
c906108c SS |
4870 | |
4871 | for (i = 0; i < abbrev->num_attrs; ++i) | |
4872 | { | |
e7c27a73 | 4873 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
c906108c SS |
4874 | |
4875 | /* Store the data if it is of an attribute we want to keep in a | |
c5aa993b | 4876 | partial symbol table. */ |
c906108c SS |
4877 | switch (attr.name) |
4878 | { | |
4879 | case DW_AT_name: | |
4880 | ||
4881 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |
4882 | if (part_die->name == NULL) | |
4883 | part_die->name = DW_STRING (&attr); | |
4884 | break; | |
4885 | case DW_AT_MIPS_linkage_name: | |
4886 | part_die->name = DW_STRING (&attr); | |
4887 | break; | |
4888 | case DW_AT_low_pc: | |
4889 | has_low_pc_attr = 1; | |
4890 | part_die->lowpc = DW_ADDR (&attr); | |
4891 | break; | |
4892 | case DW_AT_high_pc: | |
4893 | has_high_pc_attr = 1; | |
4894 | part_die->highpc = DW_ADDR (&attr); | |
4895 | break; | |
4896 | case DW_AT_location: | |
8e19ed76 PS |
4897 | /* Support the .debug_loc offsets */ |
4898 | if (attr_form_is_block (&attr)) | |
4899 | { | |
4900 | part_die->locdesc = DW_BLOCK (&attr); | |
4901 | } | |
4902 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) | |
4903 | { | |
4d3c2250 | 4904 | dwarf2_complex_location_expr_complaint (); |
8e19ed76 PS |
4905 | } |
4906 | else | |
4907 | { | |
4d3c2250 KB |
4908 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
4909 | "partial symbol information"); | |
8e19ed76 | 4910 | } |
c906108c SS |
4911 | break; |
4912 | case DW_AT_language: | |
4913 | part_die->language = DW_UNSND (&attr); | |
4914 | break; | |
4915 | case DW_AT_external: | |
4916 | part_die->is_external = DW_UNSND (&attr); | |
4917 | break; | |
4918 | case DW_AT_declaration: | |
4919 | part_die->is_declaration = DW_UNSND (&attr); | |
4920 | break; | |
4921 | case DW_AT_type: | |
4922 | part_die->has_type = 1; | |
4923 | break; | |
4924 | case DW_AT_abstract_origin: | |
4925 | case DW_AT_specification: | |
72bf9492 DJ |
4926 | case DW_AT_extension: |
4927 | part_die->has_specification = 1; | |
4928 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c SS |
4929 | break; |
4930 | case DW_AT_sibling: | |
4931 | /* Ignore absolute siblings, they might point outside of | |
4932 | the current compile unit. */ | |
4933 | if (attr.form == DW_FORM_ref_addr) | |
4d3c2250 | 4934 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); |
c906108c | 4935 | else |
6502dd73 DJ |
4936 | part_die->sibling = dwarf2_per_objfile->info_buffer |
4937 | + dwarf2_get_ref_die_offset (&attr, cu); | |
c906108c | 4938 | break; |
aaa75496 JB |
4939 | case DW_AT_stmt_list: |
4940 | part_die->has_stmt_list = 1; | |
4941 | part_die->line_offset = DW_UNSND (&attr); | |
4942 | break; | |
c906108c SS |
4943 | default: |
4944 | break; | |
4945 | } | |
4946 | } | |
4947 | ||
c906108c SS |
4948 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
4949 | eliminate duplicate copies of functions and vtables and such. | |
4950 | The linker will arbitrarily choose one and discard the others. | |
4951 | The AT_*_pc values for such functions refer to local labels in | |
4952 | these sections. If the section from that file was discarded, the | |
4953 | labels are not in the output, so the relocs get a value of 0. | |
4954 | If this is a discarded function, mark the pc bounds as invalid, | |
4955 | so that GDB will ignore it. */ | |
4956 | if (has_low_pc_attr && has_high_pc_attr | |
4957 | && part_die->lowpc < part_die->highpc | |
4958 | && (part_die->lowpc != 0 | |
4959 | || (bfd_get_file_flags (abfd) & HAS_RELOC))) | |
0b010bcc | 4960 | part_die->has_pc_info = 1; |
c906108c SS |
4961 | return info_ptr; |
4962 | } | |
4963 | ||
72bf9492 DJ |
4964 | /* Find a cached partial DIE at OFFSET in CU. */ |
4965 | ||
4966 | static struct partial_die_info * | |
4967 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |
4968 | { | |
4969 | struct partial_die_info *lookup_die = NULL; | |
4970 | struct partial_die_info part_die; | |
4971 | ||
4972 | part_die.offset = offset; | |
4973 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |
4974 | ||
4975 | if (lookup_die == NULL) | |
4976 | internal_error (__FILE__, __LINE__, | |
4977 | "could not find partial DIE in cache\n"); | |
4978 | ||
4979 | return lookup_die; | |
4980 | } | |
4981 | ||
4982 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |
4983 | ||
4984 | static struct partial_die_info * | |
4985 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu, | |
4986 | struct dwarf2_cu **target_cu) | |
4987 | { | |
4988 | struct dwarf2_per_cu_data *per_cu; | |
4989 | ||
4990 | if (offset >= cu->header.offset | |
4991 | && offset < cu->header.offset + cu->header.length) | |
4992 | { | |
4993 | *target_cu = cu; | |
4994 | return find_partial_die_in_comp_unit (offset, cu); | |
4995 | } | |
4996 | ||
4997 | internal_error (__FILE__, __LINE__, | |
4998 | "unsupported inter-compilation-unit reference"); | |
4999 | } | |
5000 | ||
5001 | /* Adjust PART_DIE before generating a symbol for it. This function | |
5002 | may set the is_external flag or change the DIE's name. */ | |
5003 | ||
5004 | static void | |
5005 | fixup_partial_die (struct partial_die_info *part_die, | |
5006 | struct dwarf2_cu *cu) | |
5007 | { | |
5008 | /* If we found a reference attribute and the DIE has no name, try | |
5009 | to find a name in the referred to DIE. */ | |
5010 | ||
5011 | if (part_die->name == NULL && part_die->has_specification) | |
5012 | { | |
5013 | struct partial_die_info *spec_die; | |
5014 | struct dwarf2_cu *spec_cu; | |
5015 | ||
5016 | spec_die = find_partial_die (part_die->spec_offset, cu, &spec_cu); | |
5017 | ||
5018 | fixup_partial_die (spec_die, spec_cu); | |
5019 | ||
5020 | if (spec_die->name) | |
5021 | { | |
5022 | part_die->name = spec_die->name; | |
5023 | ||
5024 | /* Copy DW_AT_external attribute if it is set. */ | |
5025 | if (spec_die->is_external) | |
5026 | part_die->is_external = spec_die->is_external; | |
5027 | } | |
5028 | } | |
5029 | ||
5030 | /* Set default names for some unnamed DIEs. */ | |
5031 | if (part_die->name == NULL && (part_die->tag == DW_TAG_structure_type | |
5032 | || part_die->tag == DW_TAG_class_type)) | |
5033 | part_die->name = "(anonymous class)"; | |
5034 | ||
5035 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) | |
5036 | part_die->name = "(anonymous namespace)"; | |
5037 | ||
5038 | if (part_die->tag == DW_TAG_structure_type | |
5039 | || part_die->tag == DW_TAG_class_type | |
5040 | || part_die->tag == DW_TAG_union_type) | |
5041 | guess_structure_name (part_die, cu); | |
5042 | } | |
5043 | ||
639d11d3 DC |
5044 | /* Read the die from the .debug_info section buffer. Set DIEP to |
5045 | point to a newly allocated die with its information, except for its | |
5046 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |
5047 | whether the die has children or not. */ | |
c906108c SS |
5048 | |
5049 | static char * | |
107d2387 | 5050 | read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, |
e7c27a73 | 5051 | struct dwarf2_cu *cu, int *has_children) |
c906108c SS |
5052 | { |
5053 | unsigned int abbrev_number, bytes_read, i, offset; | |
5054 | struct abbrev_info *abbrev; | |
5055 | struct die_info *die; | |
5056 | ||
6502dd73 | 5057 | offset = info_ptr - dwarf2_per_objfile->info_buffer; |
c906108c SS |
5058 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5059 | info_ptr += bytes_read; | |
5060 | if (!abbrev_number) | |
5061 | { | |
5062 | die = dwarf_alloc_die (); | |
5063 | die->tag = 0; | |
5064 | die->abbrev = abbrev_number; | |
5065 | die->type = NULL; | |
5066 | *diep = die; | |
639d11d3 | 5067 | *has_children = 0; |
c906108c SS |
5068 | return info_ptr; |
5069 | } | |
5070 | ||
e7c27a73 | 5071 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
c906108c SS |
5072 | if (!abbrev) |
5073 | { | |
639d11d3 | 5074 | error ("Dwarf Error: could not find abbrev number %d [in module %s]", |
72bf9492 | 5075 | abbrev_number, |
639d11d3 | 5076 | bfd_get_filename (abfd)); |
c906108c SS |
5077 | } |
5078 | die = dwarf_alloc_die (); | |
5079 | die->offset = offset; | |
5080 | die->tag = abbrev->tag; | |
c906108c SS |
5081 | die->abbrev = abbrev_number; |
5082 | die->type = NULL; | |
5083 | ||
5084 | die->num_attrs = abbrev->num_attrs; | |
5085 | die->attrs = (struct attribute *) | |
5086 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |
5087 | ||
5088 | for (i = 0; i < abbrev->num_attrs; ++i) | |
5089 | { | |
5090 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |
e7c27a73 | 5091 | abfd, info_ptr, cu); |
c906108c SS |
5092 | } |
5093 | ||
5094 | *diep = die; | |
639d11d3 | 5095 | *has_children = abbrev->has_children; |
c906108c SS |
5096 | return info_ptr; |
5097 | } | |
5098 | ||
a8329558 | 5099 | /* Read an attribute value described by an attribute form. */ |
c906108c SS |
5100 | |
5101 | static char * | |
a8329558 | 5102 | read_attribute_value (struct attribute *attr, unsigned form, |
e7c27a73 DJ |
5103 | bfd *abfd, char *info_ptr, |
5104 | struct dwarf2_cu *cu) | |
c906108c | 5105 | { |
e7c27a73 | 5106 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5107 | unsigned int bytes_read; |
5108 | struct dwarf_block *blk; | |
5109 | ||
a8329558 KW |
5110 | attr->form = form; |
5111 | switch (form) | |
c906108c SS |
5112 | { |
5113 | case DW_FORM_addr: | |
5114 | case DW_FORM_ref_addr: | |
e7c27a73 | 5115 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
107d2387 | 5116 | info_ptr += bytes_read; |
c906108c SS |
5117 | break; |
5118 | case DW_FORM_block2: | |
7b5a2f43 | 5119 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5120 | blk->size = read_2_bytes (abfd, info_ptr); |
5121 | info_ptr += 2; | |
5122 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5123 | info_ptr += blk->size; | |
5124 | DW_BLOCK (attr) = blk; | |
5125 | break; | |
5126 | case DW_FORM_block4: | |
7b5a2f43 | 5127 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5128 | blk->size = read_4_bytes (abfd, info_ptr); |
5129 | info_ptr += 4; | |
5130 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5131 | info_ptr += blk->size; | |
5132 | DW_BLOCK (attr) = blk; | |
5133 | break; | |
5134 | case DW_FORM_data2: | |
5135 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5136 | info_ptr += 2; | |
5137 | break; | |
5138 | case DW_FORM_data4: | |
5139 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5140 | info_ptr += 4; | |
5141 | break; | |
5142 | case DW_FORM_data8: | |
5143 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5144 | info_ptr += 8; | |
5145 | break; | |
5146 | case DW_FORM_string: | |
5147 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); | |
5148 | info_ptr += bytes_read; | |
5149 | break; | |
4bdf3d34 JJ |
5150 | case DW_FORM_strp: |
5151 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, | |
5152 | &bytes_read); | |
5153 | info_ptr += bytes_read; | |
5154 | break; | |
c906108c | 5155 | case DW_FORM_block: |
7b5a2f43 | 5156 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5157 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5158 | info_ptr += bytes_read; | |
5159 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5160 | info_ptr += blk->size; | |
5161 | DW_BLOCK (attr) = blk; | |
5162 | break; | |
5163 | case DW_FORM_block1: | |
7b5a2f43 | 5164 | blk = dwarf_alloc_block (cu); |
c906108c SS |
5165 | blk->size = read_1_byte (abfd, info_ptr); |
5166 | info_ptr += 1; | |
5167 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |
5168 | info_ptr += blk->size; | |
5169 | DW_BLOCK (attr) = blk; | |
5170 | break; | |
5171 | case DW_FORM_data1: | |
5172 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5173 | info_ptr += 1; | |
5174 | break; | |
5175 | case DW_FORM_flag: | |
5176 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5177 | info_ptr += 1; | |
5178 | break; | |
5179 | case DW_FORM_sdata: | |
5180 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |
5181 | info_ptr += bytes_read; | |
5182 | break; | |
5183 | case DW_FORM_udata: | |
5184 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5185 | info_ptr += bytes_read; | |
5186 | break; | |
5187 | case DW_FORM_ref1: | |
5188 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); | |
5189 | info_ptr += 1; | |
5190 | break; | |
5191 | case DW_FORM_ref2: | |
5192 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); | |
5193 | info_ptr += 2; | |
5194 | break; | |
5195 | case DW_FORM_ref4: | |
5196 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); | |
5197 | info_ptr += 4; | |
5198 | break; | |
613e1657 KB |
5199 | case DW_FORM_ref8: |
5200 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); | |
5201 | info_ptr += 8; | |
5202 | break; | |
c906108c SS |
5203 | case DW_FORM_ref_udata: |
5204 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |
5205 | info_ptr += bytes_read; | |
5206 | break; | |
c906108c | 5207 | case DW_FORM_indirect: |
a8329558 KW |
5208 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
5209 | info_ptr += bytes_read; | |
e7c27a73 | 5210 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
a8329558 | 5211 | break; |
c906108c | 5212 | default: |
659b0389 ML |
5213 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", |
5214 | dwarf_form_name (form), | |
5215 | bfd_get_filename (abfd)); | |
c906108c SS |
5216 | } |
5217 | return info_ptr; | |
5218 | } | |
5219 | ||
a8329558 KW |
5220 | /* Read an attribute described by an abbreviated attribute. */ |
5221 | ||
5222 | static char * | |
5223 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, | |
e7c27a73 | 5224 | bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) |
a8329558 KW |
5225 | { |
5226 | attr->name = abbrev->name; | |
e7c27a73 | 5227 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
a8329558 KW |
5228 | } |
5229 | ||
c906108c SS |
5230 | /* read dwarf information from a buffer */ |
5231 | ||
5232 | static unsigned int | |
fba45db2 | 5233 | read_1_byte (bfd *abfd, char *buf) |
c906108c SS |
5234 | { |
5235 | return bfd_get_8 (abfd, (bfd_byte *) buf); | |
5236 | } | |
5237 | ||
5238 | static int | |
fba45db2 | 5239 | read_1_signed_byte (bfd *abfd, char *buf) |
c906108c SS |
5240 | { |
5241 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf); | |
5242 | } | |
5243 | ||
5244 | static unsigned int | |
fba45db2 | 5245 | read_2_bytes (bfd *abfd, char *buf) |
c906108c SS |
5246 | { |
5247 | return bfd_get_16 (abfd, (bfd_byte *) buf); | |
5248 | } | |
5249 | ||
5250 | static int | |
fba45db2 | 5251 | read_2_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5252 | { |
5253 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5254 | } | |
5255 | ||
5256 | static unsigned int | |
fba45db2 | 5257 | read_4_bytes (bfd *abfd, char *buf) |
c906108c SS |
5258 | { |
5259 | return bfd_get_32 (abfd, (bfd_byte *) buf); | |
5260 | } | |
5261 | ||
5262 | static int | |
fba45db2 | 5263 | read_4_signed_bytes (bfd *abfd, char *buf) |
c906108c SS |
5264 | { |
5265 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5266 | } | |
5267 | ||
ce5d95e1 | 5268 | static unsigned long |
fba45db2 | 5269 | read_8_bytes (bfd *abfd, char *buf) |
c906108c SS |
5270 | { |
5271 | return bfd_get_64 (abfd, (bfd_byte *) buf); | |
5272 | } | |
5273 | ||
5274 | static CORE_ADDR | |
e7c27a73 | 5275 | read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) |
c906108c | 5276 | { |
e7c27a73 | 5277 | struct comp_unit_head *cu_header = &cu->header; |
c906108c SS |
5278 | CORE_ADDR retval = 0; |
5279 | ||
107d2387 | 5280 | if (cu_header->signed_addr_p) |
c906108c | 5281 | { |
107d2387 AC |
5282 | switch (cu_header->addr_size) |
5283 | { | |
5284 | case 2: | |
5285 | retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); | |
5286 | break; | |
5287 | case 4: | |
5288 | retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); | |
5289 | break; | |
5290 | case 8: | |
5291 | retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); | |
5292 | break; | |
5293 | default: | |
8e65ff28 | 5294 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5295 | "read_address: bad switch, signed [in module %s]", |
5296 | bfd_get_filename (abfd)); | |
107d2387 AC |
5297 | } |
5298 | } | |
5299 | else | |
5300 | { | |
5301 | switch (cu_header->addr_size) | |
5302 | { | |
5303 | case 2: | |
5304 | retval = bfd_get_16 (abfd, (bfd_byte *) buf); | |
5305 | break; | |
5306 | case 4: | |
5307 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5308 | break; | |
5309 | case 8: | |
5310 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5311 | break; | |
5312 | default: | |
8e65ff28 | 5313 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5314 | "read_address: bad switch, unsigned [in module %s]", |
5315 | bfd_get_filename (abfd)); | |
107d2387 | 5316 | } |
c906108c | 5317 | } |
64367e0a | 5318 | |
107d2387 AC |
5319 | *bytes_read = cu_header->addr_size; |
5320 | return retval; | |
c906108c SS |
5321 | } |
5322 | ||
f7ef9339 | 5323 | /* Read the initial length from a section. The (draft) DWARF 3 |
613e1657 KB |
5324 | specification allows the initial length to take up either 4 bytes |
5325 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |
5326 | bytes describe the length and all offsets will be 8 bytes in length | |
5327 | instead of 4. | |
5328 | ||
f7ef9339 KB |
5329 | An older, non-standard 64-bit format is also handled by this |
5330 | function. The older format in question stores the initial length | |
5331 | as an 8-byte quantity without an escape value. Lengths greater | |
5332 | than 2^32 aren't very common which means that the initial 4 bytes | |
5333 | is almost always zero. Since a length value of zero doesn't make | |
5334 | sense for the 32-bit format, this initial zero can be considered to | |
5335 | be an escape value which indicates the presence of the older 64-bit | |
5336 | format. As written, the code can't detect (old format) lengths | |
5337 | greater than 4GB. If it becomes necessary to handle lengths somewhat | |
5338 | larger than 4GB, we could allow other small values (such as the | |
5339 | non-sensical values of 1, 2, and 3) to also be used as escape values | |
5340 | indicating the presence of the old format. | |
5341 | ||
613e1657 KB |
5342 | The value returned via bytes_read should be used to increment |
5343 | the relevant pointer after calling read_initial_length(). | |
5344 | ||
5345 | As a side effect, this function sets the fields initial_length_size | |
5346 | and offset_size in cu_header to the values appropriate for the | |
5347 | length field. (The format of the initial length field determines | |
5348 | the width of file offsets to be fetched later with fetch_offset().) | |
5349 | ||
5350 | [ Note: read_initial_length() and read_offset() are based on the | |
5351 | document entitled "DWARF Debugging Information Format", revision | |
f7ef9339 | 5352 | 3, draft 8, dated November 19, 2001. This document was obtained |
613e1657 KB |
5353 | from: |
5354 | ||
f7ef9339 | 5355 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
613e1657 KB |
5356 | |
5357 | This document is only a draft and is subject to change. (So beware.) | |
5358 | ||
f7ef9339 KB |
5359 | Details regarding the older, non-standard 64-bit format were |
5360 | determined empirically by examining 64-bit ELF files produced | |
5361 | by the SGI toolchain on an IRIX 6.5 machine. | |
5362 | ||
5363 | - Kevin, July 16, 2002 | |
613e1657 KB |
5364 | ] */ |
5365 | ||
5366 | static LONGEST | |
5367 | read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, | |
5368 | int *bytes_read) | |
5369 | { | |
5370 | LONGEST retval = 0; | |
5371 | ||
5372 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5373 | ||
5374 | if (retval == 0xffffffff) | |
5375 | { | |
5376 | retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); | |
5377 | *bytes_read = 12; | |
5378 | if (cu_header != NULL) | |
5379 | { | |
5380 | cu_header->initial_length_size = 12; | |
5381 | cu_header->offset_size = 8; | |
5382 | } | |
5383 | } | |
f7ef9339 KB |
5384 | else if (retval == 0) |
5385 | { | |
5386 | /* Handle (non-standard) 64-bit DWARF2 formats such as that used | |
5387 | by IRIX. */ | |
5388 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5389 | *bytes_read = 8; | |
5390 | if (cu_header != NULL) | |
5391 | { | |
5392 | cu_header->initial_length_size = 8; | |
5393 | cu_header->offset_size = 8; | |
5394 | } | |
5395 | } | |
613e1657 KB |
5396 | else |
5397 | { | |
5398 | *bytes_read = 4; | |
5399 | if (cu_header != NULL) | |
5400 | { | |
5401 | cu_header->initial_length_size = 4; | |
5402 | cu_header->offset_size = 4; | |
5403 | } | |
5404 | } | |
5405 | ||
5406 | return retval; | |
5407 | } | |
5408 | ||
5409 | /* Read an offset from the data stream. The size of the offset is | |
5410 | given by cu_header->offset_size. */ | |
5411 | ||
5412 | static LONGEST | |
5413 | read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, | |
5414 | int *bytes_read) | |
5415 | { | |
5416 | LONGEST retval = 0; | |
5417 | ||
5418 | switch (cu_header->offset_size) | |
5419 | { | |
5420 | case 4: | |
5421 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); | |
5422 | *bytes_read = 4; | |
5423 | break; | |
5424 | case 8: | |
5425 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); | |
5426 | *bytes_read = 8; | |
5427 | break; | |
5428 | default: | |
8e65ff28 | 5429 | internal_error (__FILE__, __LINE__, |
659b0389 ML |
5430 | "read_offset: bad switch [in module %s]", |
5431 | bfd_get_filename (abfd)); | |
613e1657 KB |
5432 | } |
5433 | ||
5434 | return retval; | |
5435 | } | |
5436 | ||
c906108c | 5437 | static char * |
fba45db2 | 5438 | read_n_bytes (bfd *abfd, char *buf, unsigned int size) |
c906108c SS |
5439 | { |
5440 | /* If the size of a host char is 8 bits, we can return a pointer | |
5441 | to the buffer, otherwise we have to copy the data to a buffer | |
5442 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5443 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c | 5444 | return buf; |
c906108c SS |
5445 | } |
5446 | ||
5447 | static char * | |
fba45db2 | 5448 | read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c SS |
5449 | { |
5450 | /* If the size of a host char is 8 bits, we can return a pointer | |
5451 | to the string, otherwise we have to copy the string to a buffer | |
5452 | allocated on the temporary obstack. */ | |
4bdf3d34 | 5453 | gdb_assert (HOST_CHAR_BIT == 8); |
c906108c SS |
5454 | if (*buf == '\0') |
5455 | { | |
5456 | *bytes_read_ptr = 1; | |
5457 | return NULL; | |
5458 | } | |
5459 | *bytes_read_ptr = strlen (buf) + 1; | |
5460 | return buf; | |
4bdf3d34 JJ |
5461 | } |
5462 | ||
5463 | static char * | |
5464 | read_indirect_string (bfd *abfd, char *buf, | |
5465 | const struct comp_unit_head *cu_header, | |
5466 | unsigned int *bytes_read_ptr) | |
5467 | { | |
5468 | LONGEST str_offset = read_offset (abfd, buf, cu_header, | |
5469 | (int *) bytes_read_ptr); | |
c906108c | 5470 | |
6502dd73 | 5471 | if (dwarf2_per_objfile->str_buffer == NULL) |
c906108c | 5472 | { |
659b0389 ML |
5473 | error ("DW_FORM_strp used without .debug_str section [in module %s]", |
5474 | bfd_get_filename (abfd)); | |
4bdf3d34 | 5475 | return NULL; |
c906108c | 5476 | } |
6502dd73 | 5477 | if (str_offset >= dwarf2_per_objfile->str_size) |
c906108c | 5478 | { |
659b0389 ML |
5479 | error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", |
5480 | bfd_get_filename (abfd)); | |
c906108c SS |
5481 | return NULL; |
5482 | } | |
4bdf3d34 | 5483 | gdb_assert (HOST_CHAR_BIT == 8); |
6502dd73 | 5484 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') |
4bdf3d34 | 5485 | return NULL; |
6502dd73 | 5486 | return dwarf2_per_objfile->str_buffer + str_offset; |
c906108c SS |
5487 | } |
5488 | ||
ce5d95e1 | 5489 | static unsigned long |
fba45db2 | 5490 | read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5491 | { |
ce5d95e1 JB |
5492 | unsigned long result; |
5493 | unsigned int num_read; | |
c906108c SS |
5494 | int i, shift; |
5495 | unsigned char byte; | |
5496 | ||
5497 | result = 0; | |
5498 | shift = 0; | |
5499 | num_read = 0; | |
5500 | i = 0; | |
5501 | while (1) | |
5502 | { | |
5503 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5504 | buf++; | |
5505 | num_read++; | |
ce5d95e1 | 5506 | result |= ((unsigned long)(byte & 127) << shift); |
c906108c SS |
5507 | if ((byte & 128) == 0) |
5508 | { | |
5509 | break; | |
5510 | } | |
5511 | shift += 7; | |
5512 | } | |
5513 | *bytes_read_ptr = num_read; | |
5514 | return result; | |
5515 | } | |
5516 | ||
ce5d95e1 | 5517 | static long |
fba45db2 | 5518 | read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
c906108c | 5519 | { |
ce5d95e1 | 5520 | long result; |
c906108c SS |
5521 | int i, shift, size, num_read; |
5522 | unsigned char byte; | |
5523 | ||
5524 | result = 0; | |
5525 | shift = 0; | |
5526 | size = 32; | |
5527 | num_read = 0; | |
5528 | i = 0; | |
5529 | while (1) | |
5530 | { | |
5531 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5532 | buf++; | |
5533 | num_read++; | |
ce5d95e1 | 5534 | result |= ((long)(byte & 127) << shift); |
c906108c SS |
5535 | shift += 7; |
5536 | if ((byte & 128) == 0) | |
5537 | { | |
5538 | break; | |
5539 | } | |
5540 | } | |
5541 | if ((shift < size) && (byte & 0x40)) | |
5542 | { | |
5543 | result |= -(1 << shift); | |
5544 | } | |
5545 | *bytes_read_ptr = num_read; | |
5546 | return result; | |
5547 | } | |
5548 | ||
4bb7a0a7 DJ |
5549 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
5550 | ||
5551 | static char * | |
5552 | skip_leb128 (bfd *abfd, char *buf) | |
5553 | { | |
5554 | int byte; | |
5555 | ||
5556 | while (1) | |
5557 | { | |
5558 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); | |
5559 | buf++; | |
5560 | if ((byte & 128) == 0) | |
5561 | return buf; | |
5562 | } | |
5563 | } | |
5564 | ||
c906108c | 5565 | static void |
e142c38c | 5566 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
c906108c SS |
5567 | { |
5568 | switch (lang) | |
5569 | { | |
5570 | case DW_LANG_C89: | |
5571 | case DW_LANG_C: | |
e142c38c | 5572 | cu->language = language_c; |
c906108c SS |
5573 | break; |
5574 | case DW_LANG_C_plus_plus: | |
e142c38c | 5575 | cu->language = language_cplus; |
c906108c SS |
5576 | break; |
5577 | case DW_LANG_Fortran77: | |
5578 | case DW_LANG_Fortran90: | |
b21b22e0 | 5579 | case DW_LANG_Fortran95: |
e142c38c | 5580 | cu->language = language_fortran; |
c906108c SS |
5581 | break; |
5582 | case DW_LANG_Mips_Assembler: | |
e142c38c | 5583 | cu->language = language_asm; |
c906108c | 5584 | break; |
bebd888e | 5585 | case DW_LANG_Java: |
e142c38c | 5586 | cu->language = language_java; |
bebd888e | 5587 | break; |
c906108c | 5588 | case DW_LANG_Ada83: |
8aaf0b47 | 5589 | case DW_LANG_Ada95: |
c906108c SS |
5590 | case DW_LANG_Cobol74: |
5591 | case DW_LANG_Cobol85: | |
5592 | case DW_LANG_Pascal83: | |
5593 | case DW_LANG_Modula2: | |
5594 | default: | |
e142c38c | 5595 | cu->language = language_minimal; |
c906108c SS |
5596 | break; |
5597 | } | |
e142c38c | 5598 | cu->language_defn = language_def (cu->language); |
c906108c SS |
5599 | } |
5600 | ||
5601 | /* Return the named attribute or NULL if not there. */ | |
5602 | ||
5603 | static struct attribute * | |
e142c38c | 5604 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
c906108c SS |
5605 | { |
5606 | unsigned int i; | |
5607 | struct attribute *spec = NULL; | |
5608 | ||
5609 | for (i = 0; i < die->num_attrs; ++i) | |
5610 | { | |
5611 | if (die->attrs[i].name == name) | |
5612 | { | |
5613 | return &die->attrs[i]; | |
5614 | } | |
5615 | if (die->attrs[i].name == DW_AT_specification | |
5616 | || die->attrs[i].name == DW_AT_abstract_origin) | |
5617 | spec = &die->attrs[i]; | |
5618 | } | |
5619 | if (spec) | |
5620 | { | |
5621 | struct die_info *ref_die = | |
e142c38c | 5622 | follow_die_ref (dwarf2_get_ref_die_offset (spec, cu)); |
c906108c SS |
5623 | |
5624 | if (ref_die) | |
e142c38c | 5625 | return dwarf2_attr (ref_die, name, cu); |
c906108c | 5626 | } |
c5aa993b | 5627 | |
c906108c SS |
5628 | return NULL; |
5629 | } | |
5630 | ||
05cf31d1 JB |
5631 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
5632 | and holds a non-zero value. This function should only be used for | |
5633 | DW_FORM_flag attributes. */ | |
5634 | ||
5635 | static int | |
5636 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) | |
5637 | { | |
5638 | struct attribute *attr = dwarf2_attr (die, name, cu); | |
5639 | ||
5640 | return (attr && DW_UNSND (attr)); | |
5641 | } | |
5642 | ||
3ca72b44 | 5643 | static int |
e142c38c | 5644 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
3ca72b44 | 5645 | { |
05cf31d1 JB |
5646 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
5647 | which value is non-zero. However, we have to be careful with | |
5648 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() | |
5649 | (via dwarf2_flag_true_p) follows this attribute. So we may | |
5650 | end up accidently finding a declaration attribute that belongs | |
5651 | to a different DIE referenced by the specification attribute, | |
5652 | even though the given DIE does not have a declaration attribute. */ | |
5653 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) | |
5654 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); | |
3ca72b44 AC |
5655 | } |
5656 | ||
63d06c5c DC |
5657 | /* Return the die giving the specification for DIE, if there is |
5658 | one. */ | |
5659 | ||
5660 | static struct die_info * | |
e142c38c | 5661 | die_specification (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c | 5662 | { |
e142c38c | 5663 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, cu); |
63d06c5c DC |
5664 | |
5665 | if (spec_attr == NULL) | |
5666 | return NULL; | |
5667 | else | |
e142c38c | 5668 | return follow_die_ref (dwarf2_get_ref_die_offset (spec_attr, cu)); |
63d06c5c | 5669 | } |
c906108c | 5670 | |
debd256d JB |
5671 | /* Free the line_header structure *LH, and any arrays and strings it |
5672 | refers to. */ | |
5673 | static void | |
5674 | free_line_header (struct line_header *lh) | |
5675 | { | |
5676 | if (lh->standard_opcode_lengths) | |
a8bc7b56 | 5677 | xfree (lh->standard_opcode_lengths); |
debd256d JB |
5678 | |
5679 | /* Remember that all the lh->file_names[i].name pointers are | |
5680 | pointers into debug_line_buffer, and don't need to be freed. */ | |
5681 | if (lh->file_names) | |
a8bc7b56 | 5682 | xfree (lh->file_names); |
debd256d JB |
5683 | |
5684 | /* Similarly for the include directory names. */ | |
5685 | if (lh->include_dirs) | |
a8bc7b56 | 5686 | xfree (lh->include_dirs); |
debd256d | 5687 | |
a8bc7b56 | 5688 | xfree (lh); |
debd256d JB |
5689 | } |
5690 | ||
5691 | ||
5692 | /* Add an entry to LH's include directory table. */ | |
5693 | static void | |
5694 | add_include_dir (struct line_header *lh, char *include_dir) | |
c906108c | 5695 | { |
debd256d JB |
5696 | /* Grow the array if necessary. */ |
5697 | if (lh->include_dirs_size == 0) | |
c5aa993b | 5698 | { |
debd256d JB |
5699 | lh->include_dirs_size = 1; /* for testing */ |
5700 | lh->include_dirs = xmalloc (lh->include_dirs_size | |
5701 | * sizeof (*lh->include_dirs)); | |
5702 | } | |
5703 | else if (lh->num_include_dirs >= lh->include_dirs_size) | |
5704 | { | |
5705 | lh->include_dirs_size *= 2; | |
5706 | lh->include_dirs = xrealloc (lh->include_dirs, | |
5707 | (lh->include_dirs_size | |
5708 | * sizeof (*lh->include_dirs))); | |
c5aa993b | 5709 | } |
c906108c | 5710 | |
debd256d JB |
5711 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
5712 | } | |
5713 | ||
5714 | ||
5715 | /* Add an entry to LH's file name table. */ | |
5716 | static void | |
5717 | add_file_name (struct line_header *lh, | |
5718 | char *name, | |
5719 | unsigned int dir_index, | |
5720 | unsigned int mod_time, | |
5721 | unsigned int length) | |
5722 | { | |
5723 | struct file_entry *fe; | |
5724 | ||
5725 | /* Grow the array if necessary. */ | |
5726 | if (lh->file_names_size == 0) | |
5727 | { | |
5728 | lh->file_names_size = 1; /* for testing */ | |
5729 | lh->file_names = xmalloc (lh->file_names_size | |
5730 | * sizeof (*lh->file_names)); | |
5731 | } | |
5732 | else if (lh->num_file_names >= lh->file_names_size) | |
5733 | { | |
5734 | lh->file_names_size *= 2; | |
5735 | lh->file_names = xrealloc (lh->file_names, | |
5736 | (lh->file_names_size | |
5737 | * sizeof (*lh->file_names))); | |
5738 | } | |
5739 | ||
5740 | fe = &lh->file_names[lh->num_file_names++]; | |
5741 | fe->name = name; | |
5742 | fe->dir_index = dir_index; | |
5743 | fe->mod_time = mod_time; | |
5744 | fe->length = length; | |
aaa75496 | 5745 | fe->included_p = 0; |
debd256d JB |
5746 | } |
5747 | ||
5748 | ||
5749 | /* Read the statement program header starting at OFFSET in | |
6502dd73 DJ |
5750 | .debug_line, according to the endianness of ABFD. Return a pointer |
5751 | to a struct line_header, allocated using xmalloc. | |
debd256d JB |
5752 | |
5753 | NOTE: the strings in the include directory and file name tables of | |
5754 | the returned object point into debug_line_buffer, and must not be | |
5755 | freed. */ | |
5756 | static struct line_header * | |
5757 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, | |
e7c27a73 | 5758 | struct dwarf2_cu *cu) |
debd256d JB |
5759 | { |
5760 | struct cleanup *back_to; | |
5761 | struct line_header *lh; | |
5762 | char *line_ptr; | |
5763 | int bytes_read; | |
5764 | int i; | |
5765 | char *cur_dir, *cur_file; | |
5766 | ||
6502dd73 | 5767 | if (dwarf2_per_objfile->line_buffer == NULL) |
debd256d | 5768 | { |
4d3c2250 | 5769 | complaint (&symfile_complaints, "missing .debug_line section"); |
debd256d JB |
5770 | return 0; |
5771 | } | |
5772 | ||
5773 | /* Make sure that at least there's room for the total_length field. That | |
5774 | could be 12 bytes long, but we're just going to fudge that. */ | |
6502dd73 | 5775 | if (offset + 4 >= dwarf2_per_objfile->line_size) |
debd256d | 5776 | { |
4d3c2250 | 5777 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5778 | return 0; |
5779 | } | |
5780 | ||
5781 | lh = xmalloc (sizeof (*lh)); | |
5782 | memset (lh, 0, sizeof (*lh)); | |
5783 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, | |
5784 | (void *) lh); | |
5785 | ||
6502dd73 | 5786 | line_ptr = dwarf2_per_objfile->line_buffer + offset; |
debd256d JB |
5787 | |
5788 | /* read in the header */ | |
5789 | lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read); | |
5790 | line_ptr += bytes_read; | |
6502dd73 DJ |
5791 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line_buffer |
5792 | + dwarf2_per_objfile->line_size)) | |
debd256d | 5793 | { |
4d3c2250 | 5794 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
debd256d JB |
5795 | return 0; |
5796 | } | |
5797 | lh->statement_program_end = line_ptr + lh->total_length; | |
5798 | lh->version = read_2_bytes (abfd, line_ptr); | |
5799 | line_ptr += 2; | |
e7c27a73 | 5800 | lh->header_length = read_offset (abfd, line_ptr, &cu->header, &bytes_read); |
debd256d JB |
5801 | line_ptr += bytes_read; |
5802 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); | |
5803 | line_ptr += 1; | |
5804 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); | |
5805 | line_ptr += 1; | |
5806 | lh->line_base = read_1_signed_byte (abfd, line_ptr); | |
5807 | line_ptr += 1; | |
5808 | lh->line_range = read_1_byte (abfd, line_ptr); | |
5809 | line_ptr += 1; | |
5810 | lh->opcode_base = read_1_byte (abfd, line_ptr); | |
5811 | line_ptr += 1; | |
5812 | lh->standard_opcode_lengths | |
5813 | = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); | |
5814 | ||
5815 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ | |
5816 | for (i = 1; i < lh->opcode_base; ++i) | |
5817 | { | |
5818 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); | |
5819 | line_ptr += 1; | |
5820 | } | |
5821 | ||
5822 | /* Read directory table */ | |
5823 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5824 | { | |
5825 | line_ptr += bytes_read; | |
5826 | add_include_dir (lh, cur_dir); | |
5827 | } | |
5828 | line_ptr += bytes_read; | |
5829 | ||
5830 | /* Read file name table */ | |
5831 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) | |
5832 | { | |
5833 | unsigned int dir_index, mod_time, length; | |
5834 | ||
5835 | line_ptr += bytes_read; | |
5836 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5837 | line_ptr += bytes_read; | |
5838 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5839 | line_ptr += bytes_read; | |
5840 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
5841 | line_ptr += bytes_read; | |
5842 | ||
5843 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
5844 | } | |
5845 | line_ptr += bytes_read; | |
5846 | lh->statement_program_start = line_ptr; | |
5847 | ||
6502dd73 DJ |
5848 | if (line_ptr > (dwarf2_per_objfile->line_buffer |
5849 | + dwarf2_per_objfile->line_size)) | |
4d3c2250 KB |
5850 | complaint (&symfile_complaints, |
5851 | "line number info header doesn't fit in `.debug_line' section"); | |
debd256d JB |
5852 | |
5853 | discard_cleanups (back_to); | |
5854 | return lh; | |
5855 | } | |
c906108c | 5856 | |
5fb290d7 DJ |
5857 | /* This function exists to work around a bug in certain compilers |
5858 | (particularly GCC 2.95), in which the first line number marker of a | |
5859 | function does not show up until after the prologue, right before | |
5860 | the second line number marker. This function shifts ADDRESS down | |
5861 | to the beginning of the function if necessary, and is called on | |
5862 | addresses passed to record_line. */ | |
5863 | ||
5864 | static CORE_ADDR | |
e142c38c | 5865 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
5fb290d7 DJ |
5866 | { |
5867 | struct function_range *fn; | |
5868 | ||
5869 | /* Find the function_range containing address. */ | |
e142c38c | 5870 | if (!cu->first_fn) |
5fb290d7 DJ |
5871 | return address; |
5872 | ||
e142c38c DJ |
5873 | if (!cu->cached_fn) |
5874 | cu->cached_fn = cu->first_fn; | |
5fb290d7 | 5875 | |
e142c38c | 5876 | fn = cu->cached_fn; |
5fb290d7 DJ |
5877 | while (fn) |
5878 | if (fn->lowpc <= address && fn->highpc > address) | |
5879 | goto found; | |
5880 | else | |
5881 | fn = fn->next; | |
5882 | ||
e142c38c DJ |
5883 | fn = cu->first_fn; |
5884 | while (fn && fn != cu->cached_fn) | |
5fb290d7 DJ |
5885 | if (fn->lowpc <= address && fn->highpc > address) |
5886 | goto found; | |
5887 | else | |
5888 | fn = fn->next; | |
5889 | ||
5890 | return address; | |
5891 | ||
5892 | found: | |
5893 | if (fn->seen_line) | |
5894 | return address; | |
5895 | if (address != fn->lowpc) | |
4d3c2250 KB |
5896 | complaint (&symfile_complaints, |
5897 | "misplaced first line number at 0x%lx for '%s'", | |
5898 | (unsigned long) address, fn->name); | |
5fb290d7 DJ |
5899 | fn->seen_line = 1; |
5900 | return fn->lowpc; | |
5901 | } | |
5902 | ||
aaa75496 JB |
5903 | /* Decode the Line Number Program (LNP) for the given line_header |
5904 | structure and CU. The actual information extracted and the type | |
5905 | of structures created from the LNP depends on the value of PST. | |
5906 | ||
5907 | 1. If PST is NULL, then this procedure uses the data from the program | |
5908 | to create all necessary symbol tables, and their linetables. | |
5909 | The compilation directory of the file is passed in COMP_DIR, | |
5910 | and must not be NULL. | |
5911 | ||
5912 | 2. If PST is not NULL, this procedure reads the program to determine | |
5913 | the list of files included by the unit represented by PST, and | |
5914 | builds all the associated partial symbol tables. In this case, | |
5915 | the value of COMP_DIR is ignored, and can thus be NULL (the COMP_DIR | |
5916 | is not used to compute the full name of the symtab, and therefore | |
5917 | omitting it when building the partial symtab does not introduce | |
5918 | the potential for inconsistency - a partial symtab and its associated | |
5919 | symbtab having a different fullname -). */ | |
debd256d | 5920 | |
c906108c | 5921 | static void |
debd256d | 5922 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
aaa75496 | 5923 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
c906108c SS |
5924 | { |
5925 | char *line_ptr; | |
5926 | char *line_end; | |
e7c27a73 | 5927 | unsigned int bytes_read; |
c906108c | 5928 | unsigned char op_code, extended_op, adj_opcode; |
e142c38c DJ |
5929 | CORE_ADDR baseaddr; |
5930 | struct objfile *objfile = cu->objfile; | |
aaa75496 | 5931 | const int decode_for_pst_p = (pst != NULL); |
e142c38c DJ |
5932 | |
5933 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 5934 | |
debd256d JB |
5935 | line_ptr = lh->statement_program_start; |
5936 | line_end = lh->statement_program_end; | |
c906108c SS |
5937 | |
5938 | /* Read the statement sequences until there's nothing left. */ | |
5939 | while (line_ptr < line_end) | |
5940 | { | |
5941 | /* state machine registers */ | |
5942 | CORE_ADDR address = 0; | |
5943 | unsigned int file = 1; | |
5944 | unsigned int line = 1; | |
5945 | unsigned int column = 0; | |
debd256d | 5946 | int is_stmt = lh->default_is_stmt; |
c906108c SS |
5947 | int basic_block = 0; |
5948 | int end_sequence = 0; | |
5949 | ||
aaa75496 | 5950 | if (!decode_for_pst_p && lh->num_file_names >= file) |
c906108c | 5951 | { |
aaa75496 | 5952 | /* Start a subfile for the current file of the state machine. */ |
debd256d JB |
5953 | /* lh->include_dirs and lh->file_names are 0-based, but the |
5954 | directory and file name numbers in the statement program | |
5955 | are 1-based. */ | |
5956 | struct file_entry *fe = &lh->file_names[file - 1]; | |
5957 | char *dir; | |
5958 | if (fe->dir_index) | |
5959 | dir = lh->include_dirs[fe->dir_index - 1]; | |
5960 | else | |
5961 | dir = comp_dir; | |
5962 | dwarf2_start_subfile (fe->name, dir); | |
c906108c SS |
5963 | } |
5964 | ||
5965 | /* Decode the table. */ | |
c5aa993b | 5966 | while (!end_sequence) |
c906108c SS |
5967 | { |
5968 | op_code = read_1_byte (abfd, line_ptr); | |
5969 | line_ptr += 1; | |
9aa1fe7e | 5970 | |
debd256d | 5971 | if (op_code >= lh->opcode_base) |
9aa1fe7e | 5972 | { /* Special operand. */ |
debd256d JB |
5973 | adj_opcode = op_code - lh->opcode_base; |
5974 | address += (adj_opcode / lh->line_range) | |
5975 | * lh->minimum_instruction_length; | |
5976 | line += lh->line_base + (adj_opcode % lh->line_range); | |
aaa75496 JB |
5977 | if (!decode_for_pst_p) |
5978 | { | |
5979 | /* append row to matrix using current values */ | |
5980 | record_line (current_subfile, line, | |
5981 | check_cu_functions (address, cu)); | |
5982 | } | |
9aa1fe7e GK |
5983 | basic_block = 1; |
5984 | } | |
5985 | else switch (op_code) | |
c906108c SS |
5986 | { |
5987 | case DW_LNS_extended_op: | |
5988 | line_ptr += 1; /* ignore length */ | |
5989 | extended_op = read_1_byte (abfd, line_ptr); | |
5990 | line_ptr += 1; | |
5991 | switch (extended_op) | |
5992 | { | |
5993 | case DW_LNE_end_sequence: | |
5994 | end_sequence = 1; | |
aaa75496 JB |
5995 | if (!decode_for_pst_p) |
5996 | record_line (current_subfile, 0, address); | |
c906108c SS |
5997 | break; |
5998 | case DW_LNE_set_address: | |
e7c27a73 | 5999 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
107d2387 AC |
6000 | line_ptr += bytes_read; |
6001 | address += baseaddr; | |
c906108c SS |
6002 | break; |
6003 | case DW_LNE_define_file: | |
debd256d JB |
6004 | { |
6005 | char *cur_file; | |
6006 | unsigned int dir_index, mod_time, length; | |
6007 | ||
6008 | cur_file = read_string (abfd, line_ptr, &bytes_read); | |
6009 | line_ptr += bytes_read; | |
6010 | dir_index = | |
6011 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6012 | line_ptr += bytes_read; | |
6013 | mod_time = | |
6014 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6015 | line_ptr += bytes_read; | |
6016 | length = | |
6017 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6018 | line_ptr += bytes_read; | |
6019 | add_file_name (lh, cur_file, dir_index, mod_time, length); | |
6020 | } | |
c906108c SS |
6021 | break; |
6022 | default: | |
4d3c2250 KB |
6023 | complaint (&symfile_complaints, |
6024 | "mangled .debug_line section"); | |
debd256d | 6025 | return; |
c906108c SS |
6026 | } |
6027 | break; | |
6028 | case DW_LNS_copy: | |
aaa75496 JB |
6029 | if (!decode_for_pst_p) |
6030 | record_line (current_subfile, line, | |
6031 | check_cu_functions (address, cu)); | |
c906108c SS |
6032 | basic_block = 0; |
6033 | break; | |
6034 | case DW_LNS_advance_pc: | |
debd256d | 6035 | address += lh->minimum_instruction_length |
c906108c SS |
6036 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
6037 | line_ptr += bytes_read; | |
6038 | break; | |
6039 | case DW_LNS_advance_line: | |
6040 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); | |
6041 | line_ptr += bytes_read; | |
6042 | break; | |
6043 | case DW_LNS_set_file: | |
debd256d JB |
6044 | { |
6045 | /* lh->include_dirs and lh->file_names are 0-based, | |
6046 | but the directory and file name numbers in the | |
6047 | statement program are 1-based. */ | |
6048 | struct file_entry *fe; | |
6049 | char *dir; | |
6050 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6051 | line_ptr += bytes_read; | |
6052 | fe = &lh->file_names[file - 1]; | |
aaa75496 | 6053 | fe->included_p = 1; |
debd256d JB |
6054 | if (fe->dir_index) |
6055 | dir = lh->include_dirs[fe->dir_index - 1]; | |
6056 | else | |
6057 | dir = comp_dir; | |
aaa75496 JB |
6058 | if (!decode_for_pst_p) |
6059 | dwarf2_start_subfile (fe->name, dir); | |
debd256d | 6060 | } |
c906108c SS |
6061 | break; |
6062 | case DW_LNS_set_column: | |
6063 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6064 | line_ptr += bytes_read; | |
6065 | break; | |
6066 | case DW_LNS_negate_stmt: | |
6067 | is_stmt = (!is_stmt); | |
6068 | break; | |
6069 | case DW_LNS_set_basic_block: | |
6070 | basic_block = 1; | |
6071 | break; | |
c2c6d25f JM |
6072 | /* Add to the address register of the state machine the |
6073 | address increment value corresponding to special opcode | |
6074 | 255. Ie, this value is scaled by the minimum instruction | |
6075 | length since special opcode 255 would have scaled the | |
6076 | the increment. */ | |
c906108c | 6077 | case DW_LNS_const_add_pc: |
debd256d JB |
6078 | address += (lh->minimum_instruction_length |
6079 | * ((255 - lh->opcode_base) / lh->line_range)); | |
c906108c SS |
6080 | break; |
6081 | case DW_LNS_fixed_advance_pc: | |
6082 | address += read_2_bytes (abfd, line_ptr); | |
6083 | line_ptr += 2; | |
6084 | break; | |
9aa1fe7e GK |
6085 | default: |
6086 | { /* Unknown standard opcode, ignore it. */ | |
6087 | int i; | |
debd256d | 6088 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
9aa1fe7e GK |
6089 | { |
6090 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); | |
6091 | line_ptr += bytes_read; | |
6092 | } | |
6093 | } | |
c906108c SS |
6094 | } |
6095 | } | |
6096 | } | |
aaa75496 JB |
6097 | |
6098 | if (decode_for_pst_p) | |
6099 | { | |
6100 | int file_index; | |
6101 | ||
6102 | /* Now that we're done scanning the Line Header Program, we can | |
6103 | create the psymtab of each included file. */ | |
6104 | for (file_index = 0; file_index < lh->num_file_names; file_index++) | |
6105 | if (lh->file_names[file_index].included_p == 1) | |
6106 | { | |
6107 | char *include_name = lh->file_names [file_index].name; | |
6108 | ||
6109 | if (strcmp (include_name, pst->filename) != 0) | |
6110 | dwarf2_create_include_psymtab (include_name, pst, objfile); | |
6111 | } | |
6112 | } | |
c906108c SS |
6113 | } |
6114 | ||
6115 | /* Start a subfile for DWARF. FILENAME is the name of the file and | |
6116 | DIRNAME the name of the source directory which contains FILENAME | |
6117 | or NULL if not known. | |
6118 | This routine tries to keep line numbers from identical absolute and | |
6119 | relative file names in a common subfile. | |
6120 | ||
6121 | Using the `list' example from the GDB testsuite, which resides in | |
6122 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename | |
6123 | of /srcdir/list0.c yields the following debugging information for list0.c: | |
6124 | ||
c5aa993b JM |
6125 | DW_AT_name: /srcdir/list0.c |
6126 | DW_AT_comp_dir: /compdir | |
357e46e7 | 6127 | files.files[0].name: list0.h |
c5aa993b | 6128 | files.files[0].dir: /srcdir |
357e46e7 | 6129 | files.files[1].name: list0.c |
c5aa993b | 6130 | files.files[1].dir: /srcdir |
c906108c SS |
6131 | |
6132 | The line number information for list0.c has to end up in a single | |
6133 | subfile, so that `break /srcdir/list0.c:1' works as expected. */ | |
6134 | ||
6135 | static void | |
fba45db2 | 6136 | dwarf2_start_subfile (char *filename, char *dirname) |
c906108c SS |
6137 | { |
6138 | /* If the filename isn't absolute, try to match an existing subfile | |
6139 | with the full pathname. */ | |
6140 | ||
d5166ae1 | 6141 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
c906108c SS |
6142 | { |
6143 | struct subfile *subfile; | |
6144 | char *fullname = concat (dirname, "/", filename, NULL); | |
6145 | ||
6146 | for (subfile = subfiles; subfile; subfile = subfile->next) | |
6147 | { | |
d5166ae1 | 6148 | if (FILENAME_CMP (subfile->name, fullname) == 0) |
c906108c SS |
6149 | { |
6150 | current_subfile = subfile; | |
b8c9b27d | 6151 | xfree (fullname); |
c906108c SS |
6152 | return; |
6153 | } | |
6154 | } | |
b8c9b27d | 6155 | xfree (fullname); |
c906108c SS |
6156 | } |
6157 | start_subfile (filename, dirname); | |
6158 | } | |
6159 | ||
4c2df51b DJ |
6160 | static void |
6161 | var_decode_location (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 6162 | struct dwarf2_cu *cu) |
4c2df51b | 6163 | { |
e7c27a73 DJ |
6164 | struct objfile *objfile = cu->objfile; |
6165 | struct comp_unit_head *cu_header = &cu->header; | |
6166 | ||
4c2df51b DJ |
6167 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
6168 | code here to turn a symbol with DW_AT_external and a | |
6169 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was | |
6170 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux | |
6171 | with some versions of binutils) where shared libraries could have | |
6172 | relocations against symbols in their debug information - the | |
6173 | minimal symbol would have the right address, but the debug info | |
6174 | would not. It's no longer necessary, because we will explicitly | |
6175 | apply relocations when we read in the debug information now. */ | |
6176 | ||
6177 | /* A DW_AT_location attribute with no contents indicates that a | |
6178 | variable has been optimized away. */ | |
6179 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) | |
6180 | { | |
6181 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; | |
6182 | return; | |
6183 | } | |
6184 | ||
6185 | /* Handle one degenerate form of location expression specially, to | |
6186 | preserve GDB's previous behavior when section offsets are | |
6187 | specified. If this is just a DW_OP_addr then mark this symbol | |
6188 | as LOC_STATIC. */ | |
6189 | ||
6190 | if (attr_form_is_block (attr) | |
6191 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size | |
6192 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) | |
6193 | { | |
6194 | int dummy; | |
6195 | ||
6196 | SYMBOL_VALUE_ADDRESS (sym) = | |
e7c27a73 | 6197 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
4c2df51b DJ |
6198 | fixup_symbol_section (sym, objfile); |
6199 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, | |
6200 | SYMBOL_SECTION (sym)); | |
6201 | SYMBOL_CLASS (sym) = LOC_STATIC; | |
6202 | return; | |
6203 | } | |
6204 | ||
6205 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static | |
6206 | expression evaluator, and use LOC_COMPUTED only when necessary | |
6207 | (i.e. when the value of a register or memory location is | |
6208 | referenced, or a thread-local block, etc.). Then again, it might | |
6209 | not be worthwhile. I'm assuming that it isn't unless performance | |
6210 | or memory numbers show me otherwise. */ | |
6211 | ||
e7c27a73 | 6212 | dwarf2_symbol_mark_computed (attr, sym, cu); |
4c2df51b DJ |
6213 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
6214 | } | |
6215 | ||
c906108c SS |
6216 | /* Given a pointer to a DWARF information entry, figure out if we need |
6217 | to make a symbol table entry for it, and if so, create a new entry | |
6218 | and return a pointer to it. | |
6219 | If TYPE is NULL, determine symbol type from the die, otherwise | |
2df3850c | 6220 | used the passed type. */ |
c906108c SS |
6221 | |
6222 | static struct symbol * | |
e7c27a73 | 6223 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
c906108c | 6224 | { |
e7c27a73 | 6225 | struct objfile *objfile = cu->objfile; |
c906108c SS |
6226 | struct symbol *sym = NULL; |
6227 | char *name; | |
6228 | struct attribute *attr = NULL; | |
6229 | struct attribute *attr2 = NULL; | |
e142c38c DJ |
6230 | CORE_ADDR baseaddr; |
6231 | ||
6232 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); | |
c906108c | 6233 | |
5c4e30ca | 6234 | if (die->tag != DW_TAG_namespace) |
e142c38c | 6235 | name = dwarf2_linkage_name (die, cu); |
5c4e30ca DC |
6236 | else |
6237 | name = TYPE_NAME (type); | |
6238 | ||
c906108c SS |
6239 | if (name) |
6240 | { | |
4a146b47 | 6241 | sym = (struct symbol *) obstack_alloc (&objfile->objfile_obstack, |
c906108c SS |
6242 | sizeof (struct symbol)); |
6243 | OBJSTAT (objfile, n_syms++); | |
6244 | memset (sym, 0, sizeof (struct symbol)); | |
2de7ced7 DJ |
6245 | |
6246 | /* Cache this symbol's name and the name's demangled form (if any). */ | |
e142c38c | 6247 | SYMBOL_LANGUAGE (sym) = cu->language; |
2de7ced7 | 6248 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
c906108c SS |
6249 | |
6250 | /* Default assumptions. | |
c5aa993b | 6251 | Use the passed type or decode it from the die. */ |
176620f1 | 6252 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
c906108c SS |
6253 | SYMBOL_CLASS (sym) = LOC_STATIC; |
6254 | if (type != NULL) | |
6255 | SYMBOL_TYPE (sym) = type; | |
6256 | else | |
e7c27a73 | 6257 | SYMBOL_TYPE (sym) = die_type (die, cu); |
e142c38c | 6258 | attr = dwarf2_attr (die, DW_AT_decl_line, cu); |
c906108c SS |
6259 | if (attr) |
6260 | { | |
6261 | SYMBOL_LINE (sym) = DW_UNSND (attr); | |
6262 | } | |
c906108c SS |
6263 | switch (die->tag) |
6264 | { | |
6265 | case DW_TAG_label: | |
e142c38c | 6266 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
c906108c SS |
6267 | if (attr) |
6268 | { | |
6269 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; | |
6270 | } | |
6271 | SYMBOL_CLASS (sym) = LOC_LABEL; | |
6272 | break; | |
6273 | case DW_TAG_subprogram: | |
6274 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by | |
6275 | finish_block. */ | |
6276 | SYMBOL_CLASS (sym) = LOC_BLOCK; | |
e142c38c | 6277 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6278 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6279 | { | |
6280 | add_symbol_to_list (sym, &global_symbols); | |
6281 | } | |
6282 | else | |
6283 | { | |
e142c38c | 6284 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6285 | } |
6286 | break; | |
6287 | case DW_TAG_variable: | |
6288 | /* Compilation with minimal debug info may result in variables | |
6289 | with missing type entries. Change the misleading `void' type | |
6290 | to something sensible. */ | |
6291 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) | |
6292 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, | |
6293 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, | |
6294 | "<variable, no debug info>", | |
6295 | objfile); | |
e142c38c | 6296 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6297 | if (attr) |
6298 | { | |
e7c27a73 | 6299 | dwarf2_const_value (attr, sym, cu); |
e142c38c | 6300 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c SS |
6301 | if (attr2 && (DW_UNSND (attr2) != 0)) |
6302 | add_symbol_to_list (sym, &global_symbols); | |
6303 | else | |
e142c38c | 6304 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6305 | break; |
6306 | } | |
e142c38c | 6307 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6308 | if (attr) |
6309 | { | |
e7c27a73 | 6310 | var_decode_location (attr, sym, cu); |
e142c38c | 6311 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6312 | if (attr2 && (DW_UNSND (attr2) != 0)) |
4c2df51b | 6313 | add_symbol_to_list (sym, &global_symbols); |
c906108c | 6314 | else |
e142c38c | 6315 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6316 | } |
6317 | else | |
6318 | { | |
6319 | /* We do not know the address of this symbol. | |
c5aa993b JM |
6320 | If it is an external symbol and we have type information |
6321 | for it, enter the symbol as a LOC_UNRESOLVED symbol. | |
6322 | The address of the variable will then be determined from | |
6323 | the minimal symbol table whenever the variable is | |
6324 | referenced. */ | |
e142c38c | 6325 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
c906108c | 6326 | if (attr2 && (DW_UNSND (attr2) != 0) |
e142c38c | 6327 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
c906108c SS |
6328 | { |
6329 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; | |
6330 | add_symbol_to_list (sym, &global_symbols); | |
6331 | } | |
6332 | } | |
6333 | break; | |
6334 | case DW_TAG_formal_parameter: | |
e142c38c | 6335 | attr = dwarf2_attr (die, DW_AT_location, cu); |
c906108c SS |
6336 | if (attr) |
6337 | { | |
e7c27a73 | 6338 | var_decode_location (attr, sym, cu); |
7cf6e574 DJ |
6339 | /* FIXME drow/2003-07-31: Is LOC_COMPUTED_ARG necessary? */ |
6340 | if (SYMBOL_CLASS (sym) == LOC_COMPUTED) | |
6341 | SYMBOL_CLASS (sym) = LOC_COMPUTED_ARG; | |
c906108c | 6342 | } |
e142c38c | 6343 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6344 | if (attr) |
6345 | { | |
e7c27a73 | 6346 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6347 | } |
e142c38c | 6348 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6349 | break; |
6350 | case DW_TAG_unspecified_parameters: | |
6351 | /* From varargs functions; gdb doesn't seem to have any | |
6352 | interest in this information, so just ignore it for now. | |
6353 | (FIXME?) */ | |
6354 | break; | |
6355 | case DW_TAG_class_type: | |
6356 | case DW_TAG_structure_type: | |
6357 | case DW_TAG_union_type: | |
6358 | case DW_TAG_enumeration_type: | |
6359 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
176620f1 | 6360 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
c906108c | 6361 | |
63d06c5c DC |
6362 | /* Make sure that the symbol includes appropriate enclosing |
6363 | classes/namespaces in its name. These are calculated in | |
134d01f1 | 6364 | read_structure_type, and the correct name is saved in |
63d06c5c DC |
6365 | the type. */ |
6366 | ||
e142c38c | 6367 | if (cu->language == language_cplus) |
c906108c | 6368 | { |
63d06c5c DC |
6369 | struct type *type = SYMBOL_TYPE (sym); |
6370 | ||
6371 | if (TYPE_TAG_NAME (type) != NULL) | |
6372 | { | |
6373 | /* FIXME: carlton/2003-11-10: Should this use | |
6374 | SYMBOL_SET_NAMES instead? (The same problem also | |
d8151005 DJ |
6375 | arises further down in this function.) */ |
6376 | /* The type's name is already allocated along with | |
6377 | this objfile, so we don't need to duplicate it | |
6378 | for the symbol. */ | |
6379 | SYMBOL_LINKAGE_NAME (sym) = TYPE_TAG_NAME (type); | |
63d06c5c | 6380 | } |
c906108c | 6381 | } |
63d06c5c DC |
6382 | |
6383 | { | |
6384 | /* NOTE: carlton/2003-11-10: C++ class symbols shouldn't | |
6385 | really ever be static objects: otherwise, if you try | |
6386 | to, say, break of a class's method and you're in a file | |
6387 | which doesn't mention that class, it won't work unless | |
6388 | the check for all static symbols in lookup_symbol_aux | |
6389 | saves you. See the OtherFileClass tests in | |
6390 | gdb.c++/namespace.exp. */ | |
6391 | ||
6392 | struct pending **list_to_add; | |
6393 | ||
e142c38c DJ |
6394 | list_to_add = (cu->list_in_scope == &file_symbols |
6395 | && cu->language == language_cplus | |
6396 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6397 | |
6398 | add_symbol_to_list (sym, list_to_add); | |
6399 | ||
6400 | /* The semantics of C++ state that "struct foo { ... }" also | |
6401 | defines a typedef for "foo". Synthesize a typedef symbol so | |
6402 | that "ptype foo" works as expected. */ | |
e142c38c | 6403 | if (cu->language == language_cplus) |
63d06c5c DC |
6404 | { |
6405 | struct symbol *typedef_sym = (struct symbol *) | |
4a146b47 | 6406 | obstack_alloc (&objfile->objfile_obstack, |
63d06c5c DC |
6407 | sizeof (struct symbol)); |
6408 | *typedef_sym = *sym; | |
6409 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; | |
d8151005 DJ |
6410 | /* The symbol's name is already allocated along with |
6411 | this objfile, so we don't need to duplicate it for | |
6412 | the type. */ | |
63d06c5c | 6413 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
d8151005 | 6414 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NATURAL_NAME (sym); |
63d06c5c DC |
6415 | add_symbol_to_list (typedef_sym, list_to_add); |
6416 | } | |
6417 | } | |
c906108c SS |
6418 | break; |
6419 | case DW_TAG_typedef: | |
63d06c5c DC |
6420 | if (processing_has_namespace_info |
6421 | && processing_current_prefix[0] != '\0') | |
6422 | { | |
4a146b47 | 6423 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6424 | processing_current_prefix, |
6425 | "::", | |
6426 | name); | |
6427 | } | |
6428 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6429 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; | |
e142c38c | 6430 | add_symbol_to_list (sym, cu->list_in_scope); |
63d06c5c | 6431 | break; |
c906108c | 6432 | case DW_TAG_base_type: |
a02abb62 | 6433 | case DW_TAG_subrange_type: |
c906108c | 6434 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
176620f1 | 6435 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
e142c38c | 6436 | add_symbol_to_list (sym, cu->list_in_scope); |
c906108c SS |
6437 | break; |
6438 | case DW_TAG_enumerator: | |
63d06c5c DC |
6439 | if (processing_has_namespace_info |
6440 | && processing_current_prefix[0] != '\0') | |
6441 | { | |
4a146b47 | 6442 | SYMBOL_LINKAGE_NAME (sym) = obconcat (&objfile->objfile_obstack, |
63d06c5c DC |
6443 | processing_current_prefix, |
6444 | "::", | |
6445 | name); | |
6446 | } | |
e142c38c | 6447 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
c906108c SS |
6448 | if (attr) |
6449 | { | |
e7c27a73 | 6450 | dwarf2_const_value (attr, sym, cu); |
c906108c | 6451 | } |
63d06c5c DC |
6452 | { |
6453 | /* NOTE: carlton/2003-11-10: See comment above in the | |
6454 | DW_TAG_class_type, etc. block. */ | |
6455 | ||
6456 | struct pending **list_to_add; | |
6457 | ||
e142c38c DJ |
6458 | list_to_add = (cu->list_in_scope == &file_symbols |
6459 | && cu->language == language_cplus | |
6460 | ? &global_symbols : cu->list_in_scope); | |
63d06c5c DC |
6461 | |
6462 | add_symbol_to_list (sym, list_to_add); | |
6463 | } | |
c906108c | 6464 | break; |
5c4e30ca DC |
6465 | case DW_TAG_namespace: |
6466 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; | |
6467 | add_symbol_to_list (sym, &global_symbols); | |
6468 | break; | |
c906108c SS |
6469 | default: |
6470 | /* Not a tag we recognize. Hopefully we aren't processing | |
6471 | trash data, but since we must specifically ignore things | |
6472 | we don't recognize, there is nothing else we should do at | |
6473 | this point. */ | |
4d3c2250 KB |
6474 | complaint (&symfile_complaints, "unsupported tag: '%s'", |
6475 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6476 | break; |
6477 | } | |
6478 | } | |
6479 | return (sym); | |
6480 | } | |
6481 | ||
6482 | /* Copy constant value from an attribute to a symbol. */ | |
6483 | ||
6484 | static void | |
107d2387 | 6485 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
e7c27a73 | 6486 | struct dwarf2_cu *cu) |
c906108c | 6487 | { |
e7c27a73 DJ |
6488 | struct objfile *objfile = cu->objfile; |
6489 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
6490 | struct dwarf_block *blk; |
6491 | ||
6492 | switch (attr->form) | |
6493 | { | |
6494 | case DW_FORM_addr: | |
107d2387 | 6495 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
22abf04a | 6496 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6497 | cu_header->addr_size, |
6498 | TYPE_LENGTH (SYMBOL_TYPE | |
6499 | (sym))); | |
c906108c | 6500 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6501 | obstack_alloc (&objfile->objfile_obstack, cu_header->addr_size); |
fbd9dcd3 AC |
6502 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
6503 | it's body - store_unsigned_integer. */ | |
6504 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, | |
6505 | DW_ADDR (attr)); | |
c906108c SS |
6506 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
6507 | break; | |
6508 | case DW_FORM_block1: | |
6509 | case DW_FORM_block2: | |
6510 | case DW_FORM_block4: | |
6511 | case DW_FORM_block: | |
6512 | blk = DW_BLOCK (attr); | |
6513 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) | |
22abf04a | 6514 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
4d3c2250 KB |
6515 | blk->size, |
6516 | TYPE_LENGTH (SYMBOL_TYPE | |
6517 | (sym))); | |
c906108c | 6518 | SYMBOL_VALUE_BYTES (sym) = (char *) |
4a146b47 | 6519 | obstack_alloc (&objfile->objfile_obstack, blk->size); |
c906108c SS |
6520 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
6521 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; | |
6522 | break; | |
2df3850c JM |
6523 | |
6524 | /* The DW_AT_const_value attributes are supposed to carry the | |
6525 | symbol's value "represented as it would be on the target | |
6526 | architecture." By the time we get here, it's already been | |
6527 | converted to host endianness, so we just need to sign- or | |
6528 | zero-extend it as appropriate. */ | |
6529 | case DW_FORM_data1: | |
6530 | dwarf2_const_value_data (attr, sym, 8); | |
6531 | break; | |
c906108c | 6532 | case DW_FORM_data2: |
2df3850c JM |
6533 | dwarf2_const_value_data (attr, sym, 16); |
6534 | break; | |
c906108c | 6535 | case DW_FORM_data4: |
2df3850c JM |
6536 | dwarf2_const_value_data (attr, sym, 32); |
6537 | break; | |
c906108c | 6538 | case DW_FORM_data8: |
2df3850c JM |
6539 | dwarf2_const_value_data (attr, sym, 64); |
6540 | break; | |
6541 | ||
c906108c | 6542 | case DW_FORM_sdata: |
2df3850c JM |
6543 | SYMBOL_VALUE (sym) = DW_SND (attr); |
6544 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6545 | break; | |
6546 | ||
c906108c SS |
6547 | case DW_FORM_udata: |
6548 | SYMBOL_VALUE (sym) = DW_UNSND (attr); | |
6549 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6550 | break; | |
2df3850c | 6551 | |
c906108c | 6552 | default: |
4d3c2250 KB |
6553 | complaint (&symfile_complaints, |
6554 | "unsupported const value attribute form: '%s'", | |
6555 | dwarf_form_name (attr->form)); | |
c906108c SS |
6556 | SYMBOL_VALUE (sym) = 0; |
6557 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6558 | break; | |
6559 | } | |
6560 | } | |
6561 | ||
2df3850c JM |
6562 | |
6563 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- | |
6564 | or zero-extend it as appropriate for the symbol's type. */ | |
6565 | static void | |
6566 | dwarf2_const_value_data (struct attribute *attr, | |
6567 | struct symbol *sym, | |
6568 | int bits) | |
6569 | { | |
6570 | LONGEST l = DW_UNSND (attr); | |
6571 | ||
6572 | if (bits < sizeof (l) * 8) | |
6573 | { | |
6574 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) | |
6575 | l &= ((LONGEST) 1 << bits) - 1; | |
6576 | else | |
bf9198f1 | 6577 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
2df3850c JM |
6578 | } |
6579 | ||
6580 | SYMBOL_VALUE (sym) = l; | |
6581 | SYMBOL_CLASS (sym) = LOC_CONST; | |
6582 | } | |
6583 | ||
6584 | ||
c906108c SS |
6585 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
6586 | ||
6587 | static struct type * | |
e7c27a73 | 6588 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6589 | { |
6590 | struct type *type; | |
6591 | struct attribute *type_attr; | |
6592 | struct die_info *type_die; | |
6593 | unsigned int ref; | |
6594 | ||
e142c38c | 6595 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
c906108c SS |
6596 | if (!type_attr) |
6597 | { | |
6598 | /* A missing DW_AT_type represents a void type. */ | |
e142c38c | 6599 | return dwarf2_fundamental_type (cu->objfile, FT_VOID, cu); |
c906108c SS |
6600 | } |
6601 | else | |
6602 | { | |
e142c38c | 6603 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6604 | type_die = follow_die_ref (ref); |
6605 | if (!type_die) | |
6606 | { | |
659b0389 | 6607 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", |
e7c27a73 | 6608 | ref, cu->objfile->name); |
c906108c SS |
6609 | return NULL; |
6610 | } | |
6611 | } | |
e7c27a73 | 6612 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6613 | if (!type) |
6614 | { | |
6615 | dump_die (type_die); | |
659b0389 | 6616 | error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", |
e7c27a73 | 6617 | cu->objfile->name); |
c906108c SS |
6618 | } |
6619 | return type; | |
6620 | } | |
6621 | ||
6622 | /* Return the containing type of the die in question using its | |
6623 | DW_AT_containing_type attribute. */ | |
6624 | ||
6625 | static struct type * | |
e7c27a73 | 6626 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6627 | { |
6628 | struct type *type = NULL; | |
6629 | struct attribute *type_attr; | |
6630 | struct die_info *type_die = NULL; | |
6631 | unsigned int ref; | |
6632 | ||
e142c38c | 6633 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
c906108c SS |
6634 | if (type_attr) |
6635 | { | |
e142c38c | 6636 | ref = dwarf2_get_ref_die_offset (type_attr, cu); |
c906108c SS |
6637 | type_die = follow_die_ref (ref); |
6638 | if (!type_die) | |
6639 | { | |
659b0389 | 6640 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, |
e7c27a73 | 6641 | cu->objfile->name); |
c906108c SS |
6642 | return NULL; |
6643 | } | |
e7c27a73 | 6644 | type = tag_type_to_type (type_die, cu); |
c906108c SS |
6645 | } |
6646 | if (!type) | |
6647 | { | |
6648 | if (type_die) | |
6649 | dump_die (type_die); | |
659b0389 | 6650 | error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", |
e7c27a73 | 6651 | cu->objfile->name); |
c906108c SS |
6652 | } |
6653 | return type; | |
6654 | } | |
6655 | ||
6656 | #if 0 | |
6657 | static struct type * | |
e7c27a73 | 6658 | type_at_offset (unsigned int offset, struct dwarf2_cu *cu) |
c906108c SS |
6659 | { |
6660 | struct die_info *die; | |
6661 | struct type *type; | |
6662 | ||
6663 | die = follow_die_ref (offset); | |
6664 | if (!die) | |
6665 | { | |
6666 | error ("Dwarf Error: Cannot find type referent at offset %d.", offset); | |
6667 | return NULL; | |
6668 | } | |
e7c27a73 | 6669 | type = tag_type_to_type (die, cu); |
c906108c SS |
6670 | return type; |
6671 | } | |
6672 | #endif | |
6673 | ||
6674 | static struct type * | |
e7c27a73 | 6675 | tag_type_to_type (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6676 | { |
6677 | if (die->type) | |
6678 | { | |
6679 | return die->type; | |
6680 | } | |
6681 | else | |
6682 | { | |
e7c27a73 | 6683 | read_type_die (die, cu); |
c906108c SS |
6684 | if (!die->type) |
6685 | { | |
6686 | dump_die (die); | |
659b0389 | 6687 | error ("Dwarf Error: Cannot find type of die [in module %s]", |
e7c27a73 | 6688 | cu->objfile->name); |
c906108c SS |
6689 | } |
6690 | return die->type; | |
6691 | } | |
6692 | } | |
6693 | ||
6694 | static void | |
e7c27a73 | 6695 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
c906108c | 6696 | { |
e142c38c | 6697 | char *prefix = determine_prefix (die, cu); |
63d06c5c DC |
6698 | const char *old_prefix = processing_current_prefix; |
6699 | struct cleanup *back_to = make_cleanup (xfree, prefix); | |
6700 | processing_current_prefix = prefix; | |
6701 | ||
c906108c SS |
6702 | switch (die->tag) |
6703 | { | |
6704 | case DW_TAG_class_type: | |
6705 | case DW_TAG_structure_type: | |
6706 | case DW_TAG_union_type: | |
134d01f1 | 6707 | read_structure_type (die, cu); |
c906108c SS |
6708 | break; |
6709 | case DW_TAG_enumeration_type: | |
134d01f1 | 6710 | read_enumeration_type (die, cu); |
c906108c SS |
6711 | break; |
6712 | case DW_TAG_subprogram: | |
6713 | case DW_TAG_subroutine_type: | |
e7c27a73 | 6714 | read_subroutine_type (die, cu); |
c906108c SS |
6715 | break; |
6716 | case DW_TAG_array_type: | |
e7c27a73 | 6717 | read_array_type (die, cu); |
c906108c SS |
6718 | break; |
6719 | case DW_TAG_pointer_type: | |
e7c27a73 | 6720 | read_tag_pointer_type (die, cu); |
c906108c SS |
6721 | break; |
6722 | case DW_TAG_ptr_to_member_type: | |
e7c27a73 | 6723 | read_tag_ptr_to_member_type (die, cu); |
c906108c SS |
6724 | break; |
6725 | case DW_TAG_reference_type: | |
e7c27a73 | 6726 | read_tag_reference_type (die, cu); |
c906108c SS |
6727 | break; |
6728 | case DW_TAG_const_type: | |
e7c27a73 | 6729 | read_tag_const_type (die, cu); |
c906108c SS |
6730 | break; |
6731 | case DW_TAG_volatile_type: | |
e7c27a73 | 6732 | read_tag_volatile_type (die, cu); |
c906108c SS |
6733 | break; |
6734 | case DW_TAG_string_type: | |
e7c27a73 | 6735 | read_tag_string_type (die, cu); |
c906108c SS |
6736 | break; |
6737 | case DW_TAG_typedef: | |
e7c27a73 | 6738 | read_typedef (die, cu); |
c906108c | 6739 | break; |
a02abb62 JB |
6740 | case DW_TAG_subrange_type: |
6741 | read_subrange_type (die, cu); | |
6742 | break; | |
c906108c | 6743 | case DW_TAG_base_type: |
e7c27a73 | 6744 | read_base_type (die, cu); |
c906108c SS |
6745 | break; |
6746 | default: | |
4d3c2250 KB |
6747 | complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", |
6748 | dwarf_tag_name (die->tag)); | |
c906108c SS |
6749 | break; |
6750 | } | |
63d06c5c DC |
6751 | |
6752 | processing_current_prefix = old_prefix; | |
6753 | do_cleanups (back_to); | |
6754 | } | |
6755 | ||
fdde2d81 DC |
6756 | /* Return the name of the namespace/class that DIE is defined within, |
6757 | or "" if we can't tell. The caller should xfree the result. */ | |
6758 | ||
6759 | /* NOTE: carlton/2004-01-23: See read_func_scope (and the comment | |
6760 | therein) for an example of how to use this function to deal with | |
6761 | DW_AT_specification. */ | |
6762 | ||
6763 | static char * | |
e142c38c | 6764 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
63d06c5c DC |
6765 | { |
6766 | struct die_info *parent; | |
6767 | ||
e142c38c | 6768 | if (cu->language != language_cplus) |
63d06c5c DC |
6769 | return NULL; |
6770 | ||
6771 | parent = die->parent; | |
6772 | ||
6773 | if (parent == NULL) | |
6774 | { | |
8176b9b8 | 6775 | return xstrdup (""); |
63d06c5c DC |
6776 | } |
6777 | else | |
6778 | { | |
63d06c5c DC |
6779 | switch (parent->tag) { |
6780 | case DW_TAG_namespace: | |
6781 | { | |
8176b9b8 DC |
6782 | /* FIXME: carlton/2004-03-05: Should I follow extension dies |
6783 | before doing this check? */ | |
6784 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) | |
6785 | { | |
6786 | return xstrdup (TYPE_TAG_NAME (parent->type)); | |
6787 | } | |
6788 | else | |
6789 | { | |
6790 | int dummy; | |
6791 | char *parent_prefix = determine_prefix (parent, cu); | |
6792 | char *retval = typename_concat (parent_prefix, | |
6793 | namespace_name (parent, &dummy, | |
6794 | cu)); | |
6795 | xfree (parent_prefix); | |
6796 | return retval; | |
6797 | } | |
63d06c5c DC |
6798 | } |
6799 | break; | |
6800 | case DW_TAG_class_type: | |
6801 | case DW_TAG_structure_type: | |
6802 | { | |
8176b9b8 | 6803 | if (parent->type != NULL && TYPE_TAG_NAME (parent->type) != NULL) |
63d06c5c | 6804 | { |
8176b9b8 | 6805 | return xstrdup (TYPE_TAG_NAME (parent->type)); |
63d06c5c DC |
6806 | } |
6807 | else | |
8176b9b8 DC |
6808 | { |
6809 | const char *old_prefix = processing_current_prefix; | |
6810 | char *new_prefix = determine_prefix (parent, cu); | |
6811 | char *retval; | |
6812 | ||
6813 | processing_current_prefix = new_prefix; | |
6814 | retval = determine_class_name (parent, cu); | |
6815 | processing_current_prefix = old_prefix; | |
6816 | ||
6817 | xfree (new_prefix); | |
6818 | return retval; | |
6819 | } | |
63d06c5c | 6820 | } |
63d06c5c | 6821 | default: |
8176b9b8 | 6822 | return determine_prefix (parent, cu); |
63d06c5c | 6823 | } |
63d06c5c DC |
6824 | } |
6825 | } | |
6826 | ||
6827 | /* Return a newly-allocated string formed by concatenating PREFIX, | |
6828 | "::", and SUFFIX, except that if PREFIX is NULL or the empty | |
6829 | string, just return a copy of SUFFIX. */ | |
6830 | ||
6831 | static char * | |
6832 | typename_concat (const char *prefix, const char *suffix) | |
6833 | { | |
6834 | if (prefix == NULL || prefix[0] == '\0') | |
6835 | return xstrdup (suffix); | |
6836 | else | |
6837 | { | |
6838 | char *retval = xmalloc (strlen (prefix) + 2 + strlen (suffix) + 1); | |
6839 | ||
6840 | strcpy (retval, prefix); | |
6841 | strcat (retval, "::"); | |
6842 | strcat (retval, suffix); | |
6843 | ||
6844 | return retval; | |
6845 | } | |
6846 | } | |
6847 | ||
c906108c | 6848 | static struct type * |
e7c27a73 | 6849 | dwarf_base_type (int encoding, int size, struct dwarf2_cu *cu) |
c906108c | 6850 | { |
e7c27a73 DJ |
6851 | struct objfile *objfile = cu->objfile; |
6852 | ||
c906108c SS |
6853 | /* FIXME - this should not produce a new (struct type *) |
6854 | every time. It should cache base types. */ | |
6855 | struct type *type; | |
6856 | switch (encoding) | |
6857 | { | |
6858 | case DW_ATE_address: | |
e142c38c | 6859 | type = dwarf2_fundamental_type (objfile, FT_VOID, cu); |
c906108c SS |
6860 | return type; |
6861 | case DW_ATE_boolean: | |
e142c38c | 6862 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN, cu); |
c906108c SS |
6863 | return type; |
6864 | case DW_ATE_complex_float: | |
6865 | if (size == 16) | |
6866 | { | |
e142c38c | 6867 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX, cu); |
c906108c SS |
6868 | } |
6869 | else | |
6870 | { | |
e142c38c | 6871 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX, cu); |
c906108c SS |
6872 | } |
6873 | return type; | |
6874 | case DW_ATE_float: | |
6875 | if (size == 8) | |
6876 | { | |
e142c38c | 6877 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT, cu); |
c906108c SS |
6878 | } |
6879 | else | |
6880 | { | |
e142c38c | 6881 | type = dwarf2_fundamental_type (objfile, FT_FLOAT, cu); |
c906108c SS |
6882 | } |
6883 | return type; | |
6884 | case DW_ATE_signed: | |
6885 | switch (size) | |
6886 | { | |
6887 | case 1: | |
e142c38c | 6888 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6889 | break; |
6890 | case 2: | |
e142c38c | 6891 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT, cu); |
c906108c SS |
6892 | break; |
6893 | default: | |
6894 | case 4: | |
e142c38c | 6895 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6896 | break; |
6897 | } | |
6898 | return type; | |
6899 | case DW_ATE_signed_char: | |
e142c38c | 6900 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR, cu); |
c906108c SS |
6901 | return type; |
6902 | case DW_ATE_unsigned: | |
6903 | switch (size) | |
6904 | { | |
6905 | case 1: | |
e142c38c | 6906 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6907 | break; |
6908 | case 2: | |
e142c38c | 6909 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT, cu); |
c906108c SS |
6910 | break; |
6911 | default: | |
6912 | case 4: | |
e142c38c | 6913 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER, cu); |
c906108c SS |
6914 | break; |
6915 | } | |
6916 | return type; | |
6917 | case DW_ATE_unsigned_char: | |
e142c38c | 6918 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR, cu); |
c906108c SS |
6919 | return type; |
6920 | default: | |
e142c38c | 6921 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER, cu); |
c906108c SS |
6922 | return type; |
6923 | } | |
6924 | } | |
6925 | ||
6926 | #if 0 | |
6927 | struct die_info * | |
fba45db2 | 6928 | copy_die (struct die_info *old_die) |
c906108c SS |
6929 | { |
6930 | struct die_info *new_die; | |
6931 | int i, num_attrs; | |
6932 | ||
6933 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
6934 | memset (new_die, 0, sizeof (struct die_info)); | |
6935 | ||
6936 | new_die->tag = old_die->tag; | |
6937 | new_die->has_children = old_die->has_children; | |
6938 | new_die->abbrev = old_die->abbrev; | |
6939 | new_die->offset = old_die->offset; | |
6940 | new_die->type = NULL; | |
6941 | ||
6942 | num_attrs = old_die->num_attrs; | |
6943 | new_die->num_attrs = num_attrs; | |
6944 | new_die->attrs = (struct attribute *) | |
6945 | xmalloc (num_attrs * sizeof (struct attribute)); | |
6946 | ||
6947 | for (i = 0; i < old_die->num_attrs; ++i) | |
6948 | { | |
6949 | new_die->attrs[i].name = old_die->attrs[i].name; | |
6950 | new_die->attrs[i].form = old_die->attrs[i].form; | |
6951 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; | |
6952 | } | |
6953 | ||
6954 | new_die->next = NULL; | |
6955 | return new_die; | |
6956 | } | |
6957 | #endif | |
6958 | ||
6959 | /* Return sibling of die, NULL if no sibling. */ | |
6960 | ||
f9aca02d | 6961 | static struct die_info * |
fba45db2 | 6962 | sibling_die (struct die_info *die) |
c906108c | 6963 | { |
639d11d3 | 6964 | return die->sibling; |
c906108c SS |
6965 | } |
6966 | ||
6967 | /* Get linkage name of a die, return NULL if not found. */ | |
6968 | ||
6969 | static char * | |
e142c38c | 6970 | dwarf2_linkage_name (struct die_info *die, struct dwarf2_cu *cu) |
c906108c SS |
6971 | { |
6972 | struct attribute *attr; | |
6973 | ||
e142c38c | 6974 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
c906108c SS |
6975 | if (attr && DW_STRING (attr)) |
6976 | return DW_STRING (attr); | |
e142c38c | 6977 | attr = dwarf2_attr (die, DW_AT_name, cu); |
c906108c SS |
6978 | if (attr && DW_STRING (attr)) |
6979 | return DW_STRING (attr); | |
6980 | return NULL; | |
6981 | } | |
6982 | ||
9219021c DC |
6983 | /* Get name of a die, return NULL if not found. */ |
6984 | ||
6985 | static char * | |
e142c38c | 6986 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
6987 | { |
6988 | struct attribute *attr; | |
6989 | ||
e142c38c | 6990 | attr = dwarf2_attr (die, DW_AT_name, cu); |
9219021c DC |
6991 | if (attr && DW_STRING (attr)) |
6992 | return DW_STRING (attr); | |
6993 | return NULL; | |
6994 | } | |
6995 | ||
6996 | /* Return the die that this die in an extension of, or NULL if there | |
6997 | is none. */ | |
6998 | ||
6999 | static struct die_info * | |
e142c38c | 7000 | dwarf2_extension (struct die_info *die, struct dwarf2_cu *cu) |
9219021c DC |
7001 | { |
7002 | struct attribute *attr; | |
7003 | struct die_info *extension_die; | |
7004 | unsigned int ref; | |
7005 | ||
e142c38c | 7006 | attr = dwarf2_attr (die, DW_AT_extension, cu); |
9219021c DC |
7007 | if (attr == NULL) |
7008 | return NULL; | |
7009 | ||
e142c38c | 7010 | ref = dwarf2_get_ref_die_offset (attr, cu); |
9219021c DC |
7011 | extension_die = follow_die_ref (ref); |
7012 | if (!extension_die) | |
7013 | { | |
7014 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); | |
7015 | } | |
7016 | ||
7017 | return extension_die; | |
7018 | } | |
7019 | ||
c906108c SS |
7020 | /* Convert a DIE tag into its string name. */ |
7021 | ||
7022 | static char * | |
aa1ee363 | 7023 | dwarf_tag_name (unsigned tag) |
c906108c SS |
7024 | { |
7025 | switch (tag) | |
7026 | { | |
7027 | case DW_TAG_padding: | |
7028 | return "DW_TAG_padding"; | |
7029 | case DW_TAG_array_type: | |
7030 | return "DW_TAG_array_type"; | |
7031 | case DW_TAG_class_type: | |
7032 | return "DW_TAG_class_type"; | |
7033 | case DW_TAG_entry_point: | |
7034 | return "DW_TAG_entry_point"; | |
7035 | case DW_TAG_enumeration_type: | |
7036 | return "DW_TAG_enumeration_type"; | |
7037 | case DW_TAG_formal_parameter: | |
7038 | return "DW_TAG_formal_parameter"; | |
7039 | case DW_TAG_imported_declaration: | |
7040 | return "DW_TAG_imported_declaration"; | |
7041 | case DW_TAG_label: | |
7042 | return "DW_TAG_label"; | |
7043 | case DW_TAG_lexical_block: | |
7044 | return "DW_TAG_lexical_block"; | |
7045 | case DW_TAG_member: | |
7046 | return "DW_TAG_member"; | |
7047 | case DW_TAG_pointer_type: | |
7048 | return "DW_TAG_pointer_type"; | |
7049 | case DW_TAG_reference_type: | |
7050 | return "DW_TAG_reference_type"; | |
7051 | case DW_TAG_compile_unit: | |
7052 | return "DW_TAG_compile_unit"; | |
7053 | case DW_TAG_string_type: | |
7054 | return "DW_TAG_string_type"; | |
7055 | case DW_TAG_structure_type: | |
7056 | return "DW_TAG_structure_type"; | |
7057 | case DW_TAG_subroutine_type: | |
7058 | return "DW_TAG_subroutine_type"; | |
7059 | case DW_TAG_typedef: | |
7060 | return "DW_TAG_typedef"; | |
7061 | case DW_TAG_union_type: | |
7062 | return "DW_TAG_union_type"; | |
7063 | case DW_TAG_unspecified_parameters: | |
7064 | return "DW_TAG_unspecified_parameters"; | |
7065 | case DW_TAG_variant: | |
7066 | return "DW_TAG_variant"; | |
7067 | case DW_TAG_common_block: | |
7068 | return "DW_TAG_common_block"; | |
7069 | case DW_TAG_common_inclusion: | |
7070 | return "DW_TAG_common_inclusion"; | |
7071 | case DW_TAG_inheritance: | |
7072 | return "DW_TAG_inheritance"; | |
7073 | case DW_TAG_inlined_subroutine: | |
7074 | return "DW_TAG_inlined_subroutine"; | |
7075 | case DW_TAG_module: | |
7076 | return "DW_TAG_module"; | |
7077 | case DW_TAG_ptr_to_member_type: | |
7078 | return "DW_TAG_ptr_to_member_type"; | |
7079 | case DW_TAG_set_type: | |
7080 | return "DW_TAG_set_type"; | |
7081 | case DW_TAG_subrange_type: | |
7082 | return "DW_TAG_subrange_type"; | |
7083 | case DW_TAG_with_stmt: | |
7084 | return "DW_TAG_with_stmt"; | |
7085 | case DW_TAG_access_declaration: | |
7086 | return "DW_TAG_access_declaration"; | |
7087 | case DW_TAG_base_type: | |
7088 | return "DW_TAG_base_type"; | |
7089 | case DW_TAG_catch_block: | |
7090 | return "DW_TAG_catch_block"; | |
7091 | case DW_TAG_const_type: | |
7092 | return "DW_TAG_const_type"; | |
7093 | case DW_TAG_constant: | |
7094 | return "DW_TAG_constant"; | |
7095 | case DW_TAG_enumerator: | |
7096 | return "DW_TAG_enumerator"; | |
7097 | case DW_TAG_file_type: | |
7098 | return "DW_TAG_file_type"; | |
7099 | case DW_TAG_friend: | |
7100 | return "DW_TAG_friend"; | |
7101 | case DW_TAG_namelist: | |
7102 | return "DW_TAG_namelist"; | |
7103 | case DW_TAG_namelist_item: | |
7104 | return "DW_TAG_namelist_item"; | |
7105 | case DW_TAG_packed_type: | |
7106 | return "DW_TAG_packed_type"; | |
7107 | case DW_TAG_subprogram: | |
7108 | return "DW_TAG_subprogram"; | |
7109 | case DW_TAG_template_type_param: | |
7110 | return "DW_TAG_template_type_param"; | |
7111 | case DW_TAG_template_value_param: | |
7112 | return "DW_TAG_template_value_param"; | |
7113 | case DW_TAG_thrown_type: | |
7114 | return "DW_TAG_thrown_type"; | |
7115 | case DW_TAG_try_block: | |
7116 | return "DW_TAG_try_block"; | |
7117 | case DW_TAG_variant_part: | |
7118 | return "DW_TAG_variant_part"; | |
7119 | case DW_TAG_variable: | |
7120 | return "DW_TAG_variable"; | |
7121 | case DW_TAG_volatile_type: | |
7122 | return "DW_TAG_volatile_type"; | |
d9fa45fe DC |
7123 | case DW_TAG_dwarf_procedure: |
7124 | return "DW_TAG_dwarf_procedure"; | |
7125 | case DW_TAG_restrict_type: | |
7126 | return "DW_TAG_restrict_type"; | |
7127 | case DW_TAG_interface_type: | |
7128 | return "DW_TAG_interface_type"; | |
7129 | case DW_TAG_namespace: | |
7130 | return "DW_TAG_namespace"; | |
7131 | case DW_TAG_imported_module: | |
7132 | return "DW_TAG_imported_module"; | |
7133 | case DW_TAG_unspecified_type: | |
7134 | return "DW_TAG_unspecified_type"; | |
7135 | case DW_TAG_partial_unit: | |
7136 | return "DW_TAG_partial_unit"; | |
7137 | case DW_TAG_imported_unit: | |
7138 | return "DW_TAG_imported_unit"; | |
c906108c SS |
7139 | case DW_TAG_MIPS_loop: |
7140 | return "DW_TAG_MIPS_loop"; | |
7141 | case DW_TAG_format_label: | |
7142 | return "DW_TAG_format_label"; | |
7143 | case DW_TAG_function_template: | |
7144 | return "DW_TAG_function_template"; | |
7145 | case DW_TAG_class_template: | |
7146 | return "DW_TAG_class_template"; | |
7147 | default: | |
7148 | return "DW_TAG_<unknown>"; | |
7149 | } | |
7150 | } | |
7151 | ||
7152 | /* Convert a DWARF attribute code into its string name. */ | |
7153 | ||
7154 | static char * | |
aa1ee363 | 7155 | dwarf_attr_name (unsigned attr) |
c906108c SS |
7156 | { |
7157 | switch (attr) | |
7158 | { | |
7159 | case DW_AT_sibling: | |
7160 | return "DW_AT_sibling"; | |
7161 | case DW_AT_location: | |
7162 | return "DW_AT_location"; | |
7163 | case DW_AT_name: | |
7164 | return "DW_AT_name"; | |
7165 | case DW_AT_ordering: | |
7166 | return "DW_AT_ordering"; | |
7167 | case DW_AT_subscr_data: | |
7168 | return "DW_AT_subscr_data"; | |
7169 | case DW_AT_byte_size: | |
7170 | return "DW_AT_byte_size"; | |
7171 | case DW_AT_bit_offset: | |
7172 | return "DW_AT_bit_offset"; | |
7173 | case DW_AT_bit_size: | |
7174 | return "DW_AT_bit_size"; | |
7175 | case DW_AT_element_list: | |
7176 | return "DW_AT_element_list"; | |
7177 | case DW_AT_stmt_list: | |
7178 | return "DW_AT_stmt_list"; | |
7179 | case DW_AT_low_pc: | |
7180 | return "DW_AT_low_pc"; | |
7181 | case DW_AT_high_pc: | |
7182 | return "DW_AT_high_pc"; | |
7183 | case DW_AT_language: | |
7184 | return "DW_AT_language"; | |
7185 | case DW_AT_member: | |
7186 | return "DW_AT_member"; | |
7187 | case DW_AT_discr: | |
7188 | return "DW_AT_discr"; | |
7189 | case DW_AT_discr_value: | |
7190 | return "DW_AT_discr_value"; | |
7191 | case DW_AT_visibility: | |
7192 | return "DW_AT_visibility"; | |
7193 | case DW_AT_import: | |
7194 | return "DW_AT_import"; | |
7195 | case DW_AT_string_length: | |
7196 | return "DW_AT_string_length"; | |
7197 | case DW_AT_common_reference: | |
7198 | return "DW_AT_common_reference"; | |
7199 | case DW_AT_comp_dir: | |
7200 | return "DW_AT_comp_dir"; | |
7201 | case DW_AT_const_value: | |
7202 | return "DW_AT_const_value"; | |
7203 | case DW_AT_containing_type: | |
7204 | return "DW_AT_containing_type"; | |
7205 | case DW_AT_default_value: | |
7206 | return "DW_AT_default_value"; | |
7207 | case DW_AT_inline: | |
7208 | return "DW_AT_inline"; | |
7209 | case DW_AT_is_optional: | |
7210 | return "DW_AT_is_optional"; | |
7211 | case DW_AT_lower_bound: | |
7212 | return "DW_AT_lower_bound"; | |
7213 | case DW_AT_producer: | |
7214 | return "DW_AT_producer"; | |
7215 | case DW_AT_prototyped: | |
7216 | return "DW_AT_prototyped"; | |
7217 | case DW_AT_return_addr: | |
7218 | return "DW_AT_return_addr"; | |
7219 | case DW_AT_start_scope: | |
7220 | return "DW_AT_start_scope"; | |
7221 | case DW_AT_stride_size: | |
7222 | return "DW_AT_stride_size"; | |
7223 | case DW_AT_upper_bound: | |
7224 | return "DW_AT_upper_bound"; | |
7225 | case DW_AT_abstract_origin: | |
7226 | return "DW_AT_abstract_origin"; | |
7227 | case DW_AT_accessibility: | |
7228 | return "DW_AT_accessibility"; | |
7229 | case DW_AT_address_class: | |
7230 | return "DW_AT_address_class"; | |
7231 | case DW_AT_artificial: | |
7232 | return "DW_AT_artificial"; | |
7233 | case DW_AT_base_types: | |
7234 | return "DW_AT_base_types"; | |
7235 | case DW_AT_calling_convention: | |
7236 | return "DW_AT_calling_convention"; | |
7237 | case DW_AT_count: | |
7238 | return "DW_AT_count"; | |
7239 | case DW_AT_data_member_location: | |
7240 | return "DW_AT_data_member_location"; | |
7241 | case DW_AT_decl_column: | |
7242 | return "DW_AT_decl_column"; | |
7243 | case DW_AT_decl_file: | |
7244 | return "DW_AT_decl_file"; | |
7245 | case DW_AT_decl_line: | |
7246 | return "DW_AT_decl_line"; | |
7247 | case DW_AT_declaration: | |
7248 | return "DW_AT_declaration"; | |
7249 | case DW_AT_discr_list: | |
7250 | return "DW_AT_discr_list"; | |
7251 | case DW_AT_encoding: | |
7252 | return "DW_AT_encoding"; | |
7253 | case DW_AT_external: | |
7254 | return "DW_AT_external"; | |
7255 | case DW_AT_frame_base: | |
7256 | return "DW_AT_frame_base"; | |
7257 | case DW_AT_friend: | |
7258 | return "DW_AT_friend"; | |
7259 | case DW_AT_identifier_case: | |
7260 | return "DW_AT_identifier_case"; | |
7261 | case DW_AT_macro_info: | |
7262 | return "DW_AT_macro_info"; | |
7263 | case DW_AT_namelist_items: | |
7264 | return "DW_AT_namelist_items"; | |
7265 | case DW_AT_priority: | |
7266 | return "DW_AT_priority"; | |
7267 | case DW_AT_segment: | |
7268 | return "DW_AT_segment"; | |
7269 | case DW_AT_specification: | |
7270 | return "DW_AT_specification"; | |
7271 | case DW_AT_static_link: | |
7272 | return "DW_AT_static_link"; | |
7273 | case DW_AT_type: | |
7274 | return "DW_AT_type"; | |
7275 | case DW_AT_use_location: | |
7276 | return "DW_AT_use_location"; | |
7277 | case DW_AT_variable_parameter: | |
7278 | return "DW_AT_variable_parameter"; | |
7279 | case DW_AT_virtuality: | |
7280 | return "DW_AT_virtuality"; | |
7281 | case DW_AT_vtable_elem_location: | |
7282 | return "DW_AT_vtable_elem_location"; | |
d9fa45fe DC |
7283 | case DW_AT_allocated: |
7284 | return "DW_AT_allocated"; | |
7285 | case DW_AT_associated: | |
7286 | return "DW_AT_associated"; | |
7287 | case DW_AT_data_location: | |
7288 | return "DW_AT_data_location"; | |
7289 | case DW_AT_stride: | |
7290 | return "DW_AT_stride"; | |
7291 | case DW_AT_entry_pc: | |
7292 | return "DW_AT_entry_pc"; | |
7293 | case DW_AT_use_UTF8: | |
7294 | return "DW_AT_use_UTF8"; | |
7295 | case DW_AT_extension: | |
7296 | return "DW_AT_extension"; | |
7297 | case DW_AT_ranges: | |
7298 | return "DW_AT_ranges"; | |
7299 | case DW_AT_trampoline: | |
7300 | return "DW_AT_trampoline"; | |
7301 | case DW_AT_call_column: | |
7302 | return "DW_AT_call_column"; | |
7303 | case DW_AT_call_file: | |
7304 | return "DW_AT_call_file"; | |
7305 | case DW_AT_call_line: | |
7306 | return "DW_AT_call_line"; | |
c906108c SS |
7307 | #ifdef MIPS |
7308 | case DW_AT_MIPS_fde: | |
7309 | return "DW_AT_MIPS_fde"; | |
7310 | case DW_AT_MIPS_loop_begin: | |
7311 | return "DW_AT_MIPS_loop_begin"; | |
7312 | case DW_AT_MIPS_tail_loop_begin: | |
7313 | return "DW_AT_MIPS_tail_loop_begin"; | |
7314 | case DW_AT_MIPS_epilog_begin: | |
7315 | return "DW_AT_MIPS_epilog_begin"; | |
7316 | case DW_AT_MIPS_loop_unroll_factor: | |
7317 | return "DW_AT_MIPS_loop_unroll_factor"; | |
7318 | case DW_AT_MIPS_software_pipeline_depth: | |
7319 | return "DW_AT_MIPS_software_pipeline_depth"; | |
e0a4f5a1 | 7320 | #endif |
c906108c SS |
7321 | case DW_AT_MIPS_linkage_name: |
7322 | return "DW_AT_MIPS_linkage_name"; | |
c906108c SS |
7323 | |
7324 | case DW_AT_sf_names: | |
7325 | return "DW_AT_sf_names"; | |
7326 | case DW_AT_src_info: | |
7327 | return "DW_AT_src_info"; | |
7328 | case DW_AT_mac_info: | |
7329 | return "DW_AT_mac_info"; | |
7330 | case DW_AT_src_coords: | |
7331 | return "DW_AT_src_coords"; | |
7332 | case DW_AT_body_begin: | |
7333 | return "DW_AT_body_begin"; | |
7334 | case DW_AT_body_end: | |
7335 | return "DW_AT_body_end"; | |
f5f8a009 EZ |
7336 | case DW_AT_GNU_vector: |
7337 | return "DW_AT_GNU_vector"; | |
c906108c SS |
7338 | default: |
7339 | return "DW_AT_<unknown>"; | |
7340 | } | |
7341 | } | |
7342 | ||
7343 | /* Convert a DWARF value form code into its string name. */ | |
7344 | ||
7345 | static char * | |
aa1ee363 | 7346 | dwarf_form_name (unsigned form) |
c906108c SS |
7347 | { |
7348 | switch (form) | |
7349 | { | |
7350 | case DW_FORM_addr: | |
7351 | return "DW_FORM_addr"; | |
7352 | case DW_FORM_block2: | |
7353 | return "DW_FORM_block2"; | |
7354 | case DW_FORM_block4: | |
7355 | return "DW_FORM_block4"; | |
7356 | case DW_FORM_data2: | |
7357 | return "DW_FORM_data2"; | |
7358 | case DW_FORM_data4: | |
7359 | return "DW_FORM_data4"; | |
7360 | case DW_FORM_data8: | |
7361 | return "DW_FORM_data8"; | |
7362 | case DW_FORM_string: | |
7363 | return "DW_FORM_string"; | |
7364 | case DW_FORM_block: | |
7365 | return "DW_FORM_block"; | |
7366 | case DW_FORM_block1: | |
7367 | return "DW_FORM_block1"; | |
7368 | case DW_FORM_data1: | |
7369 | return "DW_FORM_data1"; | |
7370 | case DW_FORM_flag: | |
7371 | return "DW_FORM_flag"; | |
7372 | case DW_FORM_sdata: | |
7373 | return "DW_FORM_sdata"; | |
7374 | case DW_FORM_strp: | |
7375 | return "DW_FORM_strp"; | |
7376 | case DW_FORM_udata: | |
7377 | return "DW_FORM_udata"; | |
7378 | case DW_FORM_ref_addr: | |
7379 | return "DW_FORM_ref_addr"; | |
7380 | case DW_FORM_ref1: | |
7381 | return "DW_FORM_ref1"; | |
7382 | case DW_FORM_ref2: | |
7383 | return "DW_FORM_ref2"; | |
7384 | case DW_FORM_ref4: | |
7385 | return "DW_FORM_ref4"; | |
7386 | case DW_FORM_ref8: | |
7387 | return "DW_FORM_ref8"; | |
7388 | case DW_FORM_ref_udata: | |
7389 | return "DW_FORM_ref_udata"; | |
7390 | case DW_FORM_indirect: | |
7391 | return "DW_FORM_indirect"; | |
7392 | default: | |
7393 | return "DW_FORM_<unknown>"; | |
7394 | } | |
7395 | } | |
7396 | ||
7397 | /* Convert a DWARF stack opcode into its string name. */ | |
7398 | ||
7399 | static char * | |
aa1ee363 | 7400 | dwarf_stack_op_name (unsigned op) |
c906108c SS |
7401 | { |
7402 | switch (op) | |
7403 | { | |
7404 | case DW_OP_addr: | |
7405 | return "DW_OP_addr"; | |
7406 | case DW_OP_deref: | |
7407 | return "DW_OP_deref"; | |
7408 | case DW_OP_const1u: | |
7409 | return "DW_OP_const1u"; | |
7410 | case DW_OP_const1s: | |
7411 | return "DW_OP_const1s"; | |
7412 | case DW_OP_const2u: | |
7413 | return "DW_OP_const2u"; | |
7414 | case DW_OP_const2s: | |
7415 | return "DW_OP_const2s"; | |
7416 | case DW_OP_const4u: | |
7417 | return "DW_OP_const4u"; | |
7418 | case DW_OP_const4s: | |
7419 | return "DW_OP_const4s"; | |
7420 | case DW_OP_const8u: | |
7421 | return "DW_OP_const8u"; | |
7422 | case DW_OP_const8s: | |
7423 | return "DW_OP_const8s"; | |
7424 | case DW_OP_constu: | |
7425 | return "DW_OP_constu"; | |
7426 | case DW_OP_consts: | |
7427 | return "DW_OP_consts"; | |
7428 | case DW_OP_dup: | |
7429 | return "DW_OP_dup"; | |
7430 | case DW_OP_drop: | |
7431 | return "DW_OP_drop"; | |
7432 | case DW_OP_over: | |
7433 | return "DW_OP_over"; | |
7434 | case DW_OP_pick: | |
7435 | return "DW_OP_pick"; | |
7436 | case DW_OP_swap: | |
7437 | return "DW_OP_swap"; | |
7438 | case DW_OP_rot: | |
7439 | return "DW_OP_rot"; | |
7440 | case DW_OP_xderef: | |
7441 | return "DW_OP_xderef"; | |
7442 | case DW_OP_abs: | |
7443 | return "DW_OP_abs"; | |
7444 | case DW_OP_and: | |
7445 | return "DW_OP_and"; | |
7446 | case DW_OP_div: | |
7447 | return "DW_OP_div"; | |
7448 | case DW_OP_minus: | |
7449 | return "DW_OP_minus"; | |
7450 | case DW_OP_mod: | |
7451 | return "DW_OP_mod"; | |
7452 | case DW_OP_mul: | |
7453 | return "DW_OP_mul"; | |
7454 | case DW_OP_neg: | |
7455 | return "DW_OP_neg"; | |
7456 | case DW_OP_not: | |
7457 | return "DW_OP_not"; | |
7458 | case DW_OP_or: | |
7459 | return "DW_OP_or"; | |
7460 | case DW_OP_plus: | |
7461 | return "DW_OP_plus"; | |
7462 | case DW_OP_plus_uconst: | |
7463 | return "DW_OP_plus_uconst"; | |
7464 | case DW_OP_shl: | |
7465 | return "DW_OP_shl"; | |
7466 | case DW_OP_shr: | |
7467 | return "DW_OP_shr"; | |
7468 | case DW_OP_shra: | |
7469 | return "DW_OP_shra"; | |
7470 | case DW_OP_xor: | |
7471 | return "DW_OP_xor"; | |
7472 | case DW_OP_bra: | |
7473 | return "DW_OP_bra"; | |
7474 | case DW_OP_eq: | |
7475 | return "DW_OP_eq"; | |
7476 | case DW_OP_ge: | |
7477 | return "DW_OP_ge"; | |
7478 | case DW_OP_gt: | |
7479 | return "DW_OP_gt"; | |
7480 | case DW_OP_le: | |
7481 | return "DW_OP_le"; | |
7482 | case DW_OP_lt: | |
7483 | return "DW_OP_lt"; | |
7484 | case DW_OP_ne: | |
7485 | return "DW_OP_ne"; | |
7486 | case DW_OP_skip: | |
7487 | return "DW_OP_skip"; | |
7488 | case DW_OP_lit0: | |
7489 | return "DW_OP_lit0"; | |
7490 | case DW_OP_lit1: | |
7491 | return "DW_OP_lit1"; | |
7492 | case DW_OP_lit2: | |
7493 | return "DW_OP_lit2"; | |
7494 | case DW_OP_lit3: | |
7495 | return "DW_OP_lit3"; | |
7496 | case DW_OP_lit4: | |
7497 | return "DW_OP_lit4"; | |
7498 | case DW_OP_lit5: | |
7499 | return "DW_OP_lit5"; | |
7500 | case DW_OP_lit6: | |
7501 | return "DW_OP_lit6"; | |
7502 | case DW_OP_lit7: | |
7503 | return "DW_OP_lit7"; | |
7504 | case DW_OP_lit8: | |
7505 | return "DW_OP_lit8"; | |
7506 | case DW_OP_lit9: | |
7507 | return "DW_OP_lit9"; | |
7508 | case DW_OP_lit10: | |
7509 | return "DW_OP_lit10"; | |
7510 | case DW_OP_lit11: | |
7511 | return "DW_OP_lit11"; | |
7512 | case DW_OP_lit12: | |
7513 | return "DW_OP_lit12"; | |
7514 | case DW_OP_lit13: | |
7515 | return "DW_OP_lit13"; | |
7516 | case DW_OP_lit14: | |
7517 | return "DW_OP_lit14"; | |
7518 | case DW_OP_lit15: | |
7519 | return "DW_OP_lit15"; | |
7520 | case DW_OP_lit16: | |
7521 | return "DW_OP_lit16"; | |
7522 | case DW_OP_lit17: | |
7523 | return "DW_OP_lit17"; | |
7524 | case DW_OP_lit18: | |
7525 | return "DW_OP_lit18"; | |
7526 | case DW_OP_lit19: | |
7527 | return "DW_OP_lit19"; | |
7528 | case DW_OP_lit20: | |
7529 | return "DW_OP_lit20"; | |
7530 | case DW_OP_lit21: | |
7531 | return "DW_OP_lit21"; | |
7532 | case DW_OP_lit22: | |
7533 | return "DW_OP_lit22"; | |
7534 | case DW_OP_lit23: | |
7535 | return "DW_OP_lit23"; | |
7536 | case DW_OP_lit24: | |
7537 | return "DW_OP_lit24"; | |
7538 | case DW_OP_lit25: | |
7539 | return "DW_OP_lit25"; | |
7540 | case DW_OP_lit26: | |
7541 | return "DW_OP_lit26"; | |
7542 | case DW_OP_lit27: | |
7543 | return "DW_OP_lit27"; | |
7544 | case DW_OP_lit28: | |
7545 | return "DW_OP_lit28"; | |
7546 | case DW_OP_lit29: | |
7547 | return "DW_OP_lit29"; | |
7548 | case DW_OP_lit30: | |
7549 | return "DW_OP_lit30"; | |
7550 | case DW_OP_lit31: | |
7551 | return "DW_OP_lit31"; | |
7552 | case DW_OP_reg0: | |
7553 | return "DW_OP_reg0"; | |
7554 | case DW_OP_reg1: | |
7555 | return "DW_OP_reg1"; | |
7556 | case DW_OP_reg2: | |
7557 | return "DW_OP_reg2"; | |
7558 | case DW_OP_reg3: | |
7559 | return "DW_OP_reg3"; | |
7560 | case DW_OP_reg4: | |
7561 | return "DW_OP_reg4"; | |
7562 | case DW_OP_reg5: | |
7563 | return "DW_OP_reg5"; | |
7564 | case DW_OP_reg6: | |
7565 | return "DW_OP_reg6"; | |
7566 | case DW_OP_reg7: | |
7567 | return "DW_OP_reg7"; | |
7568 | case DW_OP_reg8: | |
7569 | return "DW_OP_reg8"; | |
7570 | case DW_OP_reg9: | |
7571 | return "DW_OP_reg9"; | |
7572 | case DW_OP_reg10: | |
7573 | return "DW_OP_reg10"; | |
7574 | case DW_OP_reg11: | |
7575 | return "DW_OP_reg11"; | |
7576 | case DW_OP_reg12: | |
7577 | return "DW_OP_reg12"; | |
7578 | case DW_OP_reg13: | |
7579 | return "DW_OP_reg13"; | |
7580 | case DW_OP_reg14: | |
7581 | return "DW_OP_reg14"; | |
7582 | case DW_OP_reg15: | |
7583 | return "DW_OP_reg15"; | |
7584 | case DW_OP_reg16: | |
7585 | return "DW_OP_reg16"; | |
7586 | case DW_OP_reg17: | |
7587 | return "DW_OP_reg17"; | |
7588 | case DW_OP_reg18: | |
7589 | return "DW_OP_reg18"; | |
7590 | case DW_OP_reg19: | |
7591 | return "DW_OP_reg19"; | |
7592 | case DW_OP_reg20: | |
7593 | return "DW_OP_reg20"; | |
7594 | case DW_OP_reg21: | |
7595 | return "DW_OP_reg21"; | |
7596 | case DW_OP_reg22: | |
7597 | return "DW_OP_reg22"; | |
7598 | case DW_OP_reg23: | |
7599 | return "DW_OP_reg23"; | |
7600 | case DW_OP_reg24: | |
7601 | return "DW_OP_reg24"; | |
7602 | case DW_OP_reg25: | |
7603 | return "DW_OP_reg25"; | |
7604 | case DW_OP_reg26: | |
7605 | return "DW_OP_reg26"; | |
7606 | case DW_OP_reg27: | |
7607 | return "DW_OP_reg27"; | |
7608 | case DW_OP_reg28: | |
7609 | return "DW_OP_reg28"; | |
7610 | case DW_OP_reg29: | |
7611 | return "DW_OP_reg29"; | |
7612 | case DW_OP_reg30: | |
7613 | return "DW_OP_reg30"; | |
7614 | case DW_OP_reg31: | |
7615 | return "DW_OP_reg31"; | |
7616 | case DW_OP_breg0: | |
7617 | return "DW_OP_breg0"; | |
7618 | case DW_OP_breg1: | |
7619 | return "DW_OP_breg1"; | |
7620 | case DW_OP_breg2: | |
7621 | return "DW_OP_breg2"; | |
7622 | case DW_OP_breg3: | |
7623 | return "DW_OP_breg3"; | |
7624 | case DW_OP_breg4: | |
7625 | return "DW_OP_breg4"; | |
7626 | case DW_OP_breg5: | |
7627 | return "DW_OP_breg5"; | |
7628 | case DW_OP_breg6: | |
7629 | return "DW_OP_breg6"; | |
7630 | case DW_OP_breg7: | |
7631 | return "DW_OP_breg7"; | |
7632 | case DW_OP_breg8: | |
7633 | return "DW_OP_breg8"; | |
7634 | case DW_OP_breg9: | |
7635 | return "DW_OP_breg9"; | |
7636 | case DW_OP_breg10: | |
7637 | return "DW_OP_breg10"; | |
7638 | case DW_OP_breg11: | |
7639 | return "DW_OP_breg11"; | |
7640 | case DW_OP_breg12: | |
7641 | return "DW_OP_breg12"; | |
7642 | case DW_OP_breg13: | |
7643 | return "DW_OP_breg13"; | |
7644 | case DW_OP_breg14: | |
7645 | return "DW_OP_breg14"; | |
7646 | case DW_OP_breg15: | |
7647 | return "DW_OP_breg15"; | |
7648 | case DW_OP_breg16: | |
7649 | return "DW_OP_breg16"; | |
7650 | case DW_OP_breg17: | |
7651 | return "DW_OP_breg17"; | |
7652 | case DW_OP_breg18: | |
7653 | return "DW_OP_breg18"; | |
7654 | case DW_OP_breg19: | |
7655 | return "DW_OP_breg19"; | |
7656 | case DW_OP_breg20: | |
7657 | return "DW_OP_breg20"; | |
7658 | case DW_OP_breg21: | |
7659 | return "DW_OP_breg21"; | |
7660 | case DW_OP_breg22: | |
7661 | return "DW_OP_breg22"; | |
7662 | case DW_OP_breg23: | |
7663 | return "DW_OP_breg23"; | |
7664 | case DW_OP_breg24: | |
7665 | return "DW_OP_breg24"; | |
7666 | case DW_OP_breg25: | |
7667 | return "DW_OP_breg25"; | |
7668 | case DW_OP_breg26: | |
7669 | return "DW_OP_breg26"; | |
7670 | case DW_OP_breg27: | |
7671 | return "DW_OP_breg27"; | |
7672 | case DW_OP_breg28: | |
7673 | return "DW_OP_breg28"; | |
7674 | case DW_OP_breg29: | |
7675 | return "DW_OP_breg29"; | |
7676 | case DW_OP_breg30: | |
7677 | return "DW_OP_breg30"; | |
7678 | case DW_OP_breg31: | |
7679 | return "DW_OP_breg31"; | |
7680 | case DW_OP_regx: | |
7681 | return "DW_OP_regx"; | |
7682 | case DW_OP_fbreg: | |
7683 | return "DW_OP_fbreg"; | |
7684 | case DW_OP_bregx: | |
7685 | return "DW_OP_bregx"; | |
7686 | case DW_OP_piece: | |
7687 | return "DW_OP_piece"; | |
7688 | case DW_OP_deref_size: | |
7689 | return "DW_OP_deref_size"; | |
7690 | case DW_OP_xderef_size: | |
7691 | return "DW_OP_xderef_size"; | |
7692 | case DW_OP_nop: | |
7693 | return "DW_OP_nop"; | |
ed348acc EZ |
7694 | /* DWARF 3 extensions. */ |
7695 | case DW_OP_push_object_address: | |
7696 | return "DW_OP_push_object_address"; | |
7697 | case DW_OP_call2: | |
7698 | return "DW_OP_call2"; | |
7699 | case DW_OP_call4: | |
7700 | return "DW_OP_call4"; | |
7701 | case DW_OP_call_ref: | |
7702 | return "DW_OP_call_ref"; | |
7703 | /* GNU extensions. */ | |
7704 | case DW_OP_GNU_push_tls_address: | |
7705 | return "DW_OP_GNU_push_tls_address"; | |
c906108c SS |
7706 | default: |
7707 | return "OP_<unknown>"; | |
7708 | } | |
7709 | } | |
7710 | ||
7711 | static char * | |
fba45db2 | 7712 | dwarf_bool_name (unsigned mybool) |
c906108c SS |
7713 | { |
7714 | if (mybool) | |
7715 | return "TRUE"; | |
7716 | else | |
7717 | return "FALSE"; | |
7718 | } | |
7719 | ||
7720 | /* Convert a DWARF type code into its string name. */ | |
7721 | ||
7722 | static char * | |
aa1ee363 | 7723 | dwarf_type_encoding_name (unsigned enc) |
c906108c SS |
7724 | { |
7725 | switch (enc) | |
7726 | { | |
7727 | case DW_ATE_address: | |
7728 | return "DW_ATE_address"; | |
7729 | case DW_ATE_boolean: | |
7730 | return "DW_ATE_boolean"; | |
7731 | case DW_ATE_complex_float: | |
7732 | return "DW_ATE_complex_float"; | |
7733 | case DW_ATE_float: | |
7734 | return "DW_ATE_float"; | |
7735 | case DW_ATE_signed: | |
7736 | return "DW_ATE_signed"; | |
7737 | case DW_ATE_signed_char: | |
7738 | return "DW_ATE_signed_char"; | |
7739 | case DW_ATE_unsigned: | |
7740 | return "DW_ATE_unsigned"; | |
7741 | case DW_ATE_unsigned_char: | |
7742 | return "DW_ATE_unsigned_char"; | |
d9fa45fe DC |
7743 | case DW_ATE_imaginary_float: |
7744 | return "DW_ATE_imaginary_float"; | |
c906108c SS |
7745 | default: |
7746 | return "DW_ATE_<unknown>"; | |
7747 | } | |
7748 | } | |
7749 | ||
7750 | /* Convert a DWARF call frame info operation to its string name. */ | |
7751 | ||
7752 | #if 0 | |
7753 | static char * | |
aa1ee363 | 7754 | dwarf_cfi_name (unsigned cfi_opc) |
c906108c SS |
7755 | { |
7756 | switch (cfi_opc) | |
7757 | { | |
7758 | case DW_CFA_advance_loc: | |
7759 | return "DW_CFA_advance_loc"; | |
7760 | case DW_CFA_offset: | |
7761 | return "DW_CFA_offset"; | |
7762 | case DW_CFA_restore: | |
7763 | return "DW_CFA_restore"; | |
7764 | case DW_CFA_nop: | |
7765 | return "DW_CFA_nop"; | |
7766 | case DW_CFA_set_loc: | |
7767 | return "DW_CFA_set_loc"; | |
7768 | case DW_CFA_advance_loc1: | |
7769 | return "DW_CFA_advance_loc1"; | |
7770 | case DW_CFA_advance_loc2: | |
7771 | return "DW_CFA_advance_loc2"; | |
7772 | case DW_CFA_advance_loc4: | |
7773 | return "DW_CFA_advance_loc4"; | |
7774 | case DW_CFA_offset_extended: | |
7775 | return "DW_CFA_offset_extended"; | |
7776 | case DW_CFA_restore_extended: | |
7777 | return "DW_CFA_restore_extended"; | |
7778 | case DW_CFA_undefined: | |
7779 | return "DW_CFA_undefined"; | |
7780 | case DW_CFA_same_value: | |
7781 | return "DW_CFA_same_value"; | |
7782 | case DW_CFA_register: | |
7783 | return "DW_CFA_register"; | |
7784 | case DW_CFA_remember_state: | |
7785 | return "DW_CFA_remember_state"; | |
7786 | case DW_CFA_restore_state: | |
7787 | return "DW_CFA_restore_state"; | |
7788 | case DW_CFA_def_cfa: | |
7789 | return "DW_CFA_def_cfa"; | |
7790 | case DW_CFA_def_cfa_register: | |
7791 | return "DW_CFA_def_cfa_register"; | |
7792 | case DW_CFA_def_cfa_offset: | |
7793 | return "DW_CFA_def_cfa_offset"; | |
985cb1a3 JM |
7794 | |
7795 | /* DWARF 3 */ | |
7796 | case DW_CFA_def_cfa_expression: | |
7797 | return "DW_CFA_def_cfa_expression"; | |
7798 | case DW_CFA_expression: | |
7799 | return "DW_CFA_expression"; | |
7800 | case DW_CFA_offset_extended_sf: | |
7801 | return "DW_CFA_offset_extended_sf"; | |
7802 | case DW_CFA_def_cfa_sf: | |
7803 | return "DW_CFA_def_cfa_sf"; | |
7804 | case DW_CFA_def_cfa_offset_sf: | |
7805 | return "DW_CFA_def_cfa_offset_sf"; | |
7806 | ||
c906108c SS |
7807 | /* SGI/MIPS specific */ |
7808 | case DW_CFA_MIPS_advance_loc8: | |
7809 | return "DW_CFA_MIPS_advance_loc8"; | |
985cb1a3 JM |
7810 | |
7811 | /* GNU extensions */ | |
7812 | case DW_CFA_GNU_window_save: | |
7813 | return "DW_CFA_GNU_window_save"; | |
7814 | case DW_CFA_GNU_args_size: | |
7815 | return "DW_CFA_GNU_args_size"; | |
7816 | case DW_CFA_GNU_negative_offset_extended: | |
7817 | return "DW_CFA_GNU_negative_offset_extended"; | |
7818 | ||
c906108c SS |
7819 | default: |
7820 | return "DW_CFA_<unknown>"; | |
7821 | } | |
7822 | } | |
7823 | #endif | |
7824 | ||
f9aca02d | 7825 | static void |
fba45db2 | 7826 | dump_die (struct die_info *die) |
c906108c SS |
7827 | { |
7828 | unsigned int i; | |
7829 | ||
48cd0caa | 7830 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
c906108c | 7831 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
48cd0caa | 7832 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
639d11d3 | 7833 | dwarf_bool_name (die->child != NULL)); |
c906108c | 7834 | |
48cd0caa | 7835 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
c906108c SS |
7836 | for (i = 0; i < die->num_attrs; ++i) |
7837 | { | |
48cd0caa | 7838 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
c906108c SS |
7839 | dwarf_attr_name (die->attrs[i].name), |
7840 | dwarf_form_name (die->attrs[i].form)); | |
7841 | switch (die->attrs[i].form) | |
7842 | { | |
7843 | case DW_FORM_ref_addr: | |
7844 | case DW_FORM_addr: | |
48cd0caa | 7845 | fprintf_unfiltered (gdb_stderr, "address: "); |
c906108c SS |
7846 | print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); |
7847 | break; | |
7848 | case DW_FORM_block2: | |
7849 | case DW_FORM_block4: | |
7850 | case DW_FORM_block: | |
7851 | case DW_FORM_block1: | |
48cd0caa | 7852 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
c906108c SS |
7853 | break; |
7854 | case DW_FORM_data1: | |
7855 | case DW_FORM_data2: | |
7856 | case DW_FORM_data4: | |
ce5d95e1 | 7857 | case DW_FORM_data8: |
c906108c SS |
7858 | case DW_FORM_ref1: |
7859 | case DW_FORM_ref2: | |
7860 | case DW_FORM_ref4: | |
7861 | case DW_FORM_udata: | |
7862 | case DW_FORM_sdata: | |
48cd0caa | 7863 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
c906108c SS |
7864 | break; |
7865 | case DW_FORM_string: | |
4bdf3d34 | 7866 | case DW_FORM_strp: |
48cd0caa | 7867 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
c906108c | 7868 | DW_STRING (&die->attrs[i]) |
c5aa993b | 7869 | ? DW_STRING (&die->attrs[i]) : ""); |
c906108c SS |
7870 | break; |
7871 | case DW_FORM_flag: | |
7872 | if (DW_UNSND (&die->attrs[i])) | |
48cd0caa | 7873 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
c906108c | 7874 | else |
48cd0caa | 7875 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
c906108c | 7876 | break; |
a8329558 KW |
7877 | case DW_FORM_indirect: |
7878 | /* the reader will have reduced the indirect form to | |
7879 | the "base form" so this form should not occur */ | |
48cd0caa | 7880 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
a8329558 | 7881 | break; |
c906108c | 7882 | default: |
48cd0caa | 7883 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
c5aa993b | 7884 | die->attrs[i].form); |
c906108c | 7885 | } |
48cd0caa | 7886 | fprintf_unfiltered (gdb_stderr, "\n"); |
c906108c SS |
7887 | } |
7888 | } | |
7889 | ||
f9aca02d | 7890 | static void |
fba45db2 | 7891 | dump_die_list (struct die_info *die) |
c906108c SS |
7892 | { |
7893 | while (die) | |
7894 | { | |
7895 | dump_die (die); | |
639d11d3 DC |
7896 | if (die->child != NULL) |
7897 | dump_die_list (die->child); | |
7898 | if (die->sibling != NULL) | |
7899 | dump_die_list (die->sibling); | |
c906108c SS |
7900 | } |
7901 | } | |
7902 | ||
f9aca02d | 7903 | static void |
fba45db2 | 7904 | store_in_ref_table (unsigned int offset, struct die_info *die) |
c906108c SS |
7905 | { |
7906 | int h; | |
7907 | struct die_info *old; | |
7908 | ||
7909 | h = (offset % REF_HASH_SIZE); | |
7910 | old = die_ref_table[h]; | |
7911 | die->next_ref = old; | |
7912 | die_ref_table[h] = die; | |
7913 | } | |
7914 | ||
7915 | ||
7916 | static void | |
fba45db2 | 7917 | dwarf2_empty_hash_tables (void) |
c906108c SS |
7918 | { |
7919 | memset (die_ref_table, 0, sizeof (die_ref_table)); | |
7920 | } | |
7921 | ||
7922 | static unsigned int | |
e142c38c | 7923 | dwarf2_get_ref_die_offset (struct attribute *attr, struct dwarf2_cu *cu) |
c906108c SS |
7924 | { |
7925 | unsigned int result = 0; | |
7926 | ||
7927 | switch (attr->form) | |
7928 | { | |
7929 | case DW_FORM_ref_addr: | |
7930 | result = DW_ADDR (attr); | |
7931 | break; | |
7932 | case DW_FORM_ref1: | |
7933 | case DW_FORM_ref2: | |
7934 | case DW_FORM_ref4: | |
613e1657 | 7935 | case DW_FORM_ref8: |
c906108c | 7936 | case DW_FORM_ref_udata: |
e142c38c | 7937 | result = cu->header.offset + DW_UNSND (attr); |
c906108c SS |
7938 | break; |
7939 | default: | |
4d3c2250 KB |
7940 | complaint (&symfile_complaints, |
7941 | "unsupported die ref attribute form: '%s'", | |
7942 | dwarf_form_name (attr->form)); | |
c906108c SS |
7943 | } |
7944 | return result; | |
7945 | } | |
7946 | ||
a02abb62 JB |
7947 | /* Return the constant value held by the given attribute. Return -1 |
7948 | if the value held by the attribute is not constant. */ | |
7949 | ||
7950 | static int | |
7951 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) | |
7952 | { | |
7953 | if (attr->form == DW_FORM_sdata) | |
7954 | return DW_SND (attr); | |
7955 | else if (attr->form == DW_FORM_udata | |
7956 | || attr->form == DW_FORM_data1 | |
7957 | || attr->form == DW_FORM_data2 | |
7958 | || attr->form == DW_FORM_data4 | |
7959 | || attr->form == DW_FORM_data8) | |
7960 | return DW_UNSND (attr); | |
7961 | else | |
7962 | { | |
7963 | complaint (&symfile_complaints, "Attribute value is not a constant (%s)", | |
7964 | dwarf_form_name (attr->form)); | |
7965 | return default_value; | |
7966 | } | |
7967 | } | |
7968 | ||
f9aca02d | 7969 | static struct die_info * |
fba45db2 | 7970 | follow_die_ref (unsigned int offset) |
c906108c SS |
7971 | { |
7972 | struct die_info *die; | |
7973 | int h; | |
7974 | ||
7975 | h = (offset % REF_HASH_SIZE); | |
7976 | die = die_ref_table[h]; | |
7977 | while (die) | |
7978 | { | |
7979 | if (die->offset == offset) | |
7980 | { | |
7981 | return die; | |
7982 | } | |
7983 | die = die->next_ref; | |
7984 | } | |
7985 | return NULL; | |
7986 | } | |
7987 | ||
7988 | static struct type * | |
e142c38c DJ |
7989 | dwarf2_fundamental_type (struct objfile *objfile, int typeid, |
7990 | struct dwarf2_cu *cu) | |
c906108c SS |
7991 | { |
7992 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) | |
7993 | { | |
659b0389 ML |
7994 | error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", |
7995 | typeid, objfile->name); | |
c906108c SS |
7996 | } |
7997 | ||
7998 | /* Look for this particular type in the fundamental type vector. If | |
7999 | one is not found, create and install one appropriate for the | |
8000 | current language and the current target machine. */ | |
8001 | ||
e142c38c | 8002 | if (cu->ftypes[typeid] == NULL) |
c906108c | 8003 | { |
e142c38c | 8004 | cu->ftypes[typeid] = cu->language_defn->la_fund_type (objfile, typeid); |
c906108c SS |
8005 | } |
8006 | ||
e142c38c | 8007 | return (cu->ftypes[typeid]); |
c906108c SS |
8008 | } |
8009 | ||
8010 | /* Decode simple location descriptions. | |
8011 | Given a pointer to a dwarf block that defines a location, compute | |
8012 | the location and return the value. | |
8013 | ||
4cecd739 DJ |
8014 | NOTE drow/2003-11-18: This function is called in two situations |
8015 | now: for the address of static or global variables (partial symbols | |
8016 | only) and for offsets into structures which are expected to be | |
8017 | (more or less) constant. The partial symbol case should go away, | |
8018 | and only the constant case should remain. That will let this | |
8019 | function complain more accurately. A few special modes are allowed | |
8020 | without complaint for global variables (for instance, global | |
8021 | register values and thread-local values). | |
c906108c SS |
8022 | |
8023 | A location description containing no operations indicates that the | |
4cecd739 | 8024 | object is optimized out. The return value is 0 for that case. |
6b992462 DJ |
8025 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
8026 | callers will only want a very basic result and this can become a | |
8027 | complaint. | |
c906108c SS |
8028 | |
8029 | When the result is a register number, the global isreg flag is set, | |
8030 | otherwise it is cleared. | |
8031 | ||
c906108c SS |
8032 | Note that stack[0] is unused except as a default error return. |
8033 | Note that stack overflow is not yet handled. */ | |
8034 | ||
8035 | static CORE_ADDR | |
e7c27a73 | 8036 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
c906108c | 8037 | { |
e7c27a73 DJ |
8038 | struct objfile *objfile = cu->objfile; |
8039 | struct comp_unit_head *cu_header = &cu->header; | |
c906108c SS |
8040 | int i; |
8041 | int size = blk->size; | |
8042 | char *data = blk->data; | |
8043 | CORE_ADDR stack[64]; | |
8044 | int stacki; | |
8045 | unsigned int bytes_read, unsnd; | |
8046 | unsigned char op; | |
8047 | ||
8048 | i = 0; | |
8049 | stacki = 0; | |
8050 | stack[stacki] = 0; | |
8051 | isreg = 0; | |
c906108c SS |
8052 | |
8053 | while (i < size) | |
8054 | { | |
c906108c SS |
8055 | op = data[i++]; |
8056 | switch (op) | |
8057 | { | |
f1bea926 JM |
8058 | case DW_OP_lit0: |
8059 | case DW_OP_lit1: | |
8060 | case DW_OP_lit2: | |
8061 | case DW_OP_lit3: | |
8062 | case DW_OP_lit4: | |
8063 | case DW_OP_lit5: | |
8064 | case DW_OP_lit6: | |
8065 | case DW_OP_lit7: | |
8066 | case DW_OP_lit8: | |
8067 | case DW_OP_lit9: | |
8068 | case DW_OP_lit10: | |
8069 | case DW_OP_lit11: | |
8070 | case DW_OP_lit12: | |
8071 | case DW_OP_lit13: | |
8072 | case DW_OP_lit14: | |
8073 | case DW_OP_lit15: | |
8074 | case DW_OP_lit16: | |
8075 | case DW_OP_lit17: | |
8076 | case DW_OP_lit18: | |
8077 | case DW_OP_lit19: | |
8078 | case DW_OP_lit20: | |
8079 | case DW_OP_lit21: | |
8080 | case DW_OP_lit22: | |
8081 | case DW_OP_lit23: | |
8082 | case DW_OP_lit24: | |
8083 | case DW_OP_lit25: | |
8084 | case DW_OP_lit26: | |
8085 | case DW_OP_lit27: | |
8086 | case DW_OP_lit28: | |
8087 | case DW_OP_lit29: | |
8088 | case DW_OP_lit30: | |
8089 | case DW_OP_lit31: | |
8090 | stack[++stacki] = op - DW_OP_lit0; | |
8091 | break; | |
8092 | ||
c906108c SS |
8093 | case DW_OP_reg0: |
8094 | case DW_OP_reg1: | |
8095 | case DW_OP_reg2: | |
8096 | case DW_OP_reg3: | |
8097 | case DW_OP_reg4: | |
8098 | case DW_OP_reg5: | |
8099 | case DW_OP_reg6: | |
8100 | case DW_OP_reg7: | |
8101 | case DW_OP_reg8: | |
8102 | case DW_OP_reg9: | |
8103 | case DW_OP_reg10: | |
8104 | case DW_OP_reg11: | |
8105 | case DW_OP_reg12: | |
8106 | case DW_OP_reg13: | |
8107 | case DW_OP_reg14: | |
8108 | case DW_OP_reg15: | |
8109 | case DW_OP_reg16: | |
8110 | case DW_OP_reg17: | |
8111 | case DW_OP_reg18: | |
8112 | case DW_OP_reg19: | |
8113 | case DW_OP_reg20: | |
8114 | case DW_OP_reg21: | |
8115 | case DW_OP_reg22: | |
8116 | case DW_OP_reg23: | |
8117 | case DW_OP_reg24: | |
8118 | case DW_OP_reg25: | |
8119 | case DW_OP_reg26: | |
8120 | case DW_OP_reg27: | |
8121 | case DW_OP_reg28: | |
8122 | case DW_OP_reg29: | |
8123 | case DW_OP_reg30: | |
8124 | case DW_OP_reg31: | |
8125 | isreg = 1; | |
8126 | stack[++stacki] = op - DW_OP_reg0; | |
4cecd739 DJ |
8127 | if (i < size) |
8128 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8129 | break; |
8130 | ||
8131 | case DW_OP_regx: | |
8132 | isreg = 1; | |
8133 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8134 | i += bytes_read; | |
c906108c | 8135 | stack[++stacki] = unsnd; |
4cecd739 DJ |
8136 | if (i < size) |
8137 | dwarf2_complex_location_expr_complaint (); | |
c906108c SS |
8138 | break; |
8139 | ||
8140 | case DW_OP_addr: | |
107d2387 | 8141 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
e7c27a73 | 8142 | cu, &bytes_read); |
107d2387 | 8143 | i += bytes_read; |
c906108c SS |
8144 | break; |
8145 | ||
8146 | case DW_OP_const1u: | |
8147 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); | |
8148 | i += 1; | |
8149 | break; | |
8150 | ||
8151 | case DW_OP_const1s: | |
8152 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); | |
8153 | i += 1; | |
8154 | break; | |
8155 | ||
8156 | case DW_OP_const2u: | |
8157 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); | |
8158 | i += 2; | |
8159 | break; | |
8160 | ||
8161 | case DW_OP_const2s: | |
8162 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); | |
8163 | i += 2; | |
8164 | break; | |
8165 | ||
8166 | case DW_OP_const4u: | |
8167 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); | |
8168 | i += 4; | |
8169 | break; | |
8170 | ||
8171 | case DW_OP_const4s: | |
8172 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); | |
8173 | i += 4; | |
8174 | break; | |
8175 | ||
8176 | case DW_OP_constu: | |
8177 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), | |
c5aa993b | 8178 | &bytes_read); |
c906108c SS |
8179 | i += bytes_read; |
8180 | break; | |
8181 | ||
8182 | case DW_OP_consts: | |
8183 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); | |
8184 | i += bytes_read; | |
8185 | break; | |
8186 | ||
f1bea926 JM |
8187 | case DW_OP_dup: |
8188 | stack[stacki + 1] = stack[stacki]; | |
8189 | stacki++; | |
8190 | break; | |
8191 | ||
c906108c SS |
8192 | case DW_OP_plus: |
8193 | stack[stacki - 1] += stack[stacki]; | |
8194 | stacki--; | |
8195 | break; | |
8196 | ||
8197 | case DW_OP_plus_uconst: | |
8198 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); | |
8199 | i += bytes_read; | |
8200 | break; | |
8201 | ||
8202 | case DW_OP_minus: | |
f1bea926 | 8203 | stack[stacki - 1] -= stack[stacki]; |
c906108c SS |
8204 | stacki--; |
8205 | break; | |
8206 | ||
7a292a7a | 8207 | case DW_OP_deref: |
7a292a7a | 8208 | /* If we're not the last op, then we definitely can't encode |
4cecd739 DJ |
8209 | this using GDB's address_class enum. This is valid for partial |
8210 | global symbols, although the variable's address will be bogus | |
8211 | in the psymtab. */ | |
7a292a7a | 8212 | if (i < size) |
4d3c2250 | 8213 | dwarf2_complex_location_expr_complaint (); |
7a292a7a SS |
8214 | break; |
8215 | ||
9d774e44 | 8216 | case DW_OP_GNU_push_tls_address: |
9d774e44 EZ |
8217 | /* The top of the stack has the offset from the beginning |
8218 | of the thread control block at which the variable is located. */ | |
8219 | /* Nothing should follow this operator, so the top of stack would | |
8220 | be returned. */ | |
4cecd739 DJ |
8221 | /* This is valid for partial global symbols, but the variable's |
8222 | address will be bogus in the psymtab. */ | |
9d774e44 | 8223 | if (i < size) |
4d3c2250 | 8224 | dwarf2_complex_location_expr_complaint (); |
9d774e44 EZ |
8225 | break; |
8226 | ||
c906108c | 8227 | default: |
4d3c2250 KB |
8228 | complaint (&symfile_complaints, "unsupported stack op: '%s'", |
8229 | dwarf_stack_op_name (op)); | |
c906108c SS |
8230 | return (stack[stacki]); |
8231 | } | |
8232 | } | |
8233 | return (stack[stacki]); | |
8234 | } | |
8235 | ||
8236 | /* memory allocation interface */ | |
8237 | ||
c906108c | 8238 | static struct dwarf_block * |
7b5a2f43 | 8239 | dwarf_alloc_block (struct dwarf2_cu *cu) |
c906108c SS |
8240 | { |
8241 | struct dwarf_block *blk; | |
8242 | ||
8243 | blk = (struct dwarf_block *) | |
7b5a2f43 | 8244 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
c906108c SS |
8245 | return (blk); |
8246 | } | |
8247 | ||
8248 | static struct abbrev_info * | |
f3dd6933 | 8249 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
c906108c SS |
8250 | { |
8251 | struct abbrev_info *abbrev; | |
8252 | ||
f3dd6933 DJ |
8253 | abbrev = (struct abbrev_info *) |
8254 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); | |
c906108c SS |
8255 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
8256 | return (abbrev); | |
8257 | } | |
8258 | ||
8259 | static struct die_info * | |
fba45db2 | 8260 | dwarf_alloc_die (void) |
c906108c SS |
8261 | { |
8262 | struct die_info *die; | |
8263 | ||
8264 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); | |
8265 | memset (die, 0, sizeof (struct die_info)); | |
8266 | return (die); | |
8267 | } | |
2e276125 JB |
8268 | |
8269 | \f | |
8270 | /* Macro support. */ | |
8271 | ||
8272 | ||
8273 | /* Return the full name of file number I in *LH's file name table. | |
8274 | Use COMP_DIR as the name of the current directory of the | |
8275 | compilation. The result is allocated using xmalloc; the caller is | |
8276 | responsible for freeing it. */ | |
8277 | static char * | |
8278 | file_full_name (int file, struct line_header *lh, const char *comp_dir) | |
8279 | { | |
8280 | struct file_entry *fe = &lh->file_names[file - 1]; | |
8281 | ||
8282 | if (IS_ABSOLUTE_PATH (fe->name)) | |
8283 | return xstrdup (fe->name); | |
8284 | else | |
8285 | { | |
8286 | const char *dir; | |
8287 | int dir_len; | |
8288 | char *full_name; | |
8289 | ||
8290 | if (fe->dir_index) | |
8291 | dir = lh->include_dirs[fe->dir_index - 1]; | |
8292 | else | |
8293 | dir = comp_dir; | |
8294 | ||
8295 | if (dir) | |
8296 | { | |
8297 | dir_len = strlen (dir); | |
8298 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); | |
8299 | strcpy (full_name, dir); | |
8300 | full_name[dir_len] = '/'; | |
8301 | strcpy (full_name + dir_len + 1, fe->name); | |
8302 | return full_name; | |
8303 | } | |
8304 | else | |
8305 | return xstrdup (fe->name); | |
8306 | } | |
8307 | } | |
8308 | ||
8309 | ||
8310 | static struct macro_source_file * | |
8311 | macro_start_file (int file, int line, | |
8312 | struct macro_source_file *current_file, | |
8313 | const char *comp_dir, | |
8314 | struct line_header *lh, struct objfile *objfile) | |
8315 | { | |
8316 | /* The full name of this source file. */ | |
8317 | char *full_name = file_full_name (file, lh, comp_dir); | |
8318 | ||
8319 | /* We don't create a macro table for this compilation unit | |
8320 | at all until we actually get a filename. */ | |
8321 | if (! pending_macros) | |
4a146b47 | 8322 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
af5f3db6 | 8323 | objfile->macro_cache); |
2e276125 JB |
8324 | |
8325 | if (! current_file) | |
8326 | /* If we have no current file, then this must be the start_file | |
8327 | directive for the compilation unit's main source file. */ | |
8328 | current_file = macro_set_main (pending_macros, full_name); | |
8329 | else | |
8330 | current_file = macro_include (current_file, line, full_name); | |
8331 | ||
8332 | xfree (full_name); | |
8333 | ||
8334 | return current_file; | |
8335 | } | |
8336 | ||
8337 | ||
8338 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, | |
8339 | followed by a null byte. */ | |
8340 | static char * | |
8341 | copy_string (const char *buf, int len) | |
8342 | { | |
8343 | char *s = xmalloc (len + 1); | |
8344 | memcpy (s, buf, len); | |
8345 | s[len] = '\0'; | |
8346 | ||
8347 | return s; | |
8348 | } | |
8349 | ||
8350 | ||
8351 | static const char * | |
8352 | consume_improper_spaces (const char *p, const char *body) | |
8353 | { | |
8354 | if (*p == ' ') | |
8355 | { | |
4d3c2250 KB |
8356 | complaint (&symfile_complaints, |
8357 | "macro definition contains spaces in formal argument list:\n`%s'", | |
8358 | body); | |
2e276125 JB |
8359 | |
8360 | while (*p == ' ') | |
8361 | p++; | |
8362 | } | |
8363 | ||
8364 | return p; | |
8365 | } | |
8366 | ||
8367 | ||
8368 | static void | |
8369 | parse_macro_definition (struct macro_source_file *file, int line, | |
8370 | const char *body) | |
8371 | { | |
8372 | const char *p; | |
8373 | ||
8374 | /* The body string takes one of two forms. For object-like macro | |
8375 | definitions, it should be: | |
8376 | ||
8377 | <macro name> " " <definition> | |
8378 | ||
8379 | For function-like macro definitions, it should be: | |
8380 | ||
8381 | <macro name> "() " <definition> | |
8382 | or | |
8383 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> | |
8384 | ||
8385 | Spaces may appear only where explicitly indicated, and in the | |
8386 | <definition>. | |
8387 | ||
8388 | The Dwarf 2 spec says that an object-like macro's name is always | |
8389 | followed by a space, but versions of GCC around March 2002 omit | |
8390 | the space when the macro's definition is the empty string. | |
8391 | ||
8392 | The Dwarf 2 spec says that there should be no spaces between the | |
8393 | formal arguments in a function-like macro's formal argument list, | |
8394 | but versions of GCC around March 2002 include spaces after the | |
8395 | commas. */ | |
8396 | ||
8397 | ||
8398 | /* Find the extent of the macro name. The macro name is terminated | |
8399 | by either a space or null character (for an object-like macro) or | |
8400 | an opening paren (for a function-like macro). */ | |
8401 | for (p = body; *p; p++) | |
8402 | if (*p == ' ' || *p == '(') | |
8403 | break; | |
8404 | ||
8405 | if (*p == ' ' || *p == '\0') | |
8406 | { | |
8407 | /* It's an object-like macro. */ | |
8408 | int name_len = p - body; | |
8409 | char *name = copy_string (body, name_len); | |
8410 | const char *replacement; | |
8411 | ||
8412 | if (*p == ' ') | |
8413 | replacement = body + name_len + 1; | |
8414 | else | |
8415 | { | |
4d3c2250 | 8416 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8417 | replacement = body + name_len; |
8418 | } | |
8419 | ||
8420 | macro_define_object (file, line, name, replacement); | |
8421 | ||
8422 | xfree (name); | |
8423 | } | |
8424 | else if (*p == '(') | |
8425 | { | |
8426 | /* It's a function-like macro. */ | |
8427 | char *name = copy_string (body, p - body); | |
8428 | int argc = 0; | |
8429 | int argv_size = 1; | |
8430 | char **argv = xmalloc (argv_size * sizeof (*argv)); | |
8431 | ||
8432 | p++; | |
8433 | ||
8434 | p = consume_improper_spaces (p, body); | |
8435 | ||
8436 | /* Parse the formal argument list. */ | |
8437 | while (*p && *p != ')') | |
8438 | { | |
8439 | /* Find the extent of the current argument name. */ | |
8440 | const char *arg_start = p; | |
8441 | ||
8442 | while (*p && *p != ',' && *p != ')' && *p != ' ') | |
8443 | p++; | |
8444 | ||
8445 | if (! *p || p == arg_start) | |
4d3c2250 | 8446 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8447 | else |
8448 | { | |
8449 | /* Make sure argv has room for the new argument. */ | |
8450 | if (argc >= argv_size) | |
8451 | { | |
8452 | argv_size *= 2; | |
8453 | argv = xrealloc (argv, argv_size * sizeof (*argv)); | |
8454 | } | |
8455 | ||
8456 | argv[argc++] = copy_string (arg_start, p - arg_start); | |
8457 | } | |
8458 | ||
8459 | p = consume_improper_spaces (p, body); | |
8460 | ||
8461 | /* Consume the comma, if present. */ | |
8462 | if (*p == ',') | |
8463 | { | |
8464 | p++; | |
8465 | ||
8466 | p = consume_improper_spaces (p, body); | |
8467 | } | |
8468 | } | |
8469 | ||
8470 | if (*p == ')') | |
8471 | { | |
8472 | p++; | |
8473 | ||
8474 | if (*p == ' ') | |
8475 | /* Perfectly formed definition, no complaints. */ | |
8476 | macro_define_function (file, line, name, | |
8477 | argc, (const char **) argv, | |
8478 | p + 1); | |
8479 | else if (*p == '\0') | |
8480 | { | |
8481 | /* Complain, but do define it. */ | |
4d3c2250 | 8482 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8483 | macro_define_function (file, line, name, |
8484 | argc, (const char **) argv, | |
8485 | p); | |
8486 | } | |
8487 | else | |
8488 | /* Just complain. */ | |
4d3c2250 | 8489 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8490 | } |
8491 | else | |
8492 | /* Just complain. */ | |
4d3c2250 | 8493 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8494 | |
8495 | xfree (name); | |
8496 | { | |
8497 | int i; | |
8498 | ||
8499 | for (i = 0; i < argc; i++) | |
8500 | xfree (argv[i]); | |
8501 | } | |
8502 | xfree (argv); | |
8503 | } | |
8504 | else | |
4d3c2250 | 8505 | dwarf2_macro_malformed_definition_complaint (body); |
2e276125 JB |
8506 | } |
8507 | ||
8508 | ||
8509 | static void | |
8510 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, | |
8511 | char *comp_dir, bfd *abfd, | |
e7c27a73 | 8512 | struct dwarf2_cu *cu) |
2e276125 JB |
8513 | { |
8514 | char *mac_ptr, *mac_end; | |
8515 | struct macro_source_file *current_file = 0; | |
8516 | ||
6502dd73 | 8517 | if (dwarf2_per_objfile->macinfo_buffer == NULL) |
2e276125 | 8518 | { |
4d3c2250 | 8519 | complaint (&symfile_complaints, "missing .debug_macinfo section"); |
2e276125 JB |
8520 | return; |
8521 | } | |
8522 | ||
6502dd73 DJ |
8523 | mac_ptr = dwarf2_per_objfile->macinfo_buffer + offset; |
8524 | mac_end = dwarf2_per_objfile->macinfo_buffer | |
8525 | + dwarf2_per_objfile->macinfo_size; | |
2e276125 JB |
8526 | |
8527 | for (;;) | |
8528 | { | |
8529 | enum dwarf_macinfo_record_type macinfo_type; | |
8530 | ||
8531 | /* Do we at least have room for a macinfo type byte? */ | |
8532 | if (mac_ptr >= mac_end) | |
8533 | { | |
4d3c2250 | 8534 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8535 | return; |
8536 | } | |
8537 | ||
8538 | macinfo_type = read_1_byte (abfd, mac_ptr); | |
8539 | mac_ptr++; | |
8540 | ||
8541 | switch (macinfo_type) | |
8542 | { | |
8543 | /* A zero macinfo type indicates the end of the macro | |
8544 | information. */ | |
8545 | case 0: | |
8546 | return; | |
8547 | ||
8548 | case DW_MACINFO_define: | |
8549 | case DW_MACINFO_undef: | |
8550 | { | |
8551 | int bytes_read; | |
8552 | int line; | |
8553 | char *body; | |
8554 | ||
8555 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8556 | mac_ptr += bytes_read; | |
8557 | body = read_string (abfd, mac_ptr, &bytes_read); | |
8558 | mac_ptr += bytes_read; | |
8559 | ||
8560 | if (! current_file) | |
4d3c2250 KB |
8561 | complaint (&symfile_complaints, |
8562 | "debug info gives macro %s outside of any file: %s", | |
8563 | macinfo_type == | |
8564 | DW_MACINFO_define ? "definition" : macinfo_type == | |
8565 | DW_MACINFO_undef ? "undefinition" : | |
8566 | "something-or-other", body); | |
2e276125 JB |
8567 | else |
8568 | { | |
8569 | if (macinfo_type == DW_MACINFO_define) | |
8570 | parse_macro_definition (current_file, line, body); | |
8571 | else if (macinfo_type == DW_MACINFO_undef) | |
8572 | macro_undef (current_file, line, body); | |
8573 | } | |
8574 | } | |
8575 | break; | |
8576 | ||
8577 | case DW_MACINFO_start_file: | |
8578 | { | |
8579 | int bytes_read; | |
8580 | int line, file; | |
8581 | ||
8582 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8583 | mac_ptr += bytes_read; | |
8584 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8585 | mac_ptr += bytes_read; | |
8586 | ||
8587 | current_file = macro_start_file (file, line, | |
8588 | current_file, comp_dir, | |
e7c27a73 | 8589 | lh, cu->objfile); |
2e276125 JB |
8590 | } |
8591 | break; | |
8592 | ||
8593 | case DW_MACINFO_end_file: | |
8594 | if (! current_file) | |
4d3c2250 KB |
8595 | complaint (&symfile_complaints, |
8596 | "macro debug info has an unmatched `close_file' directive"); | |
2e276125 JB |
8597 | else |
8598 | { | |
8599 | current_file = current_file->included_by; | |
8600 | if (! current_file) | |
8601 | { | |
8602 | enum dwarf_macinfo_record_type next_type; | |
8603 | ||
8604 | /* GCC circa March 2002 doesn't produce the zero | |
8605 | type byte marking the end of the compilation | |
8606 | unit. Complain if it's not there, but exit no | |
8607 | matter what. */ | |
8608 | ||
8609 | /* Do we at least have room for a macinfo type byte? */ | |
8610 | if (mac_ptr >= mac_end) | |
8611 | { | |
4d3c2250 | 8612 | dwarf2_macros_too_long_complaint (); |
2e276125 JB |
8613 | return; |
8614 | } | |
8615 | ||
8616 | /* We don't increment mac_ptr here, so this is just | |
8617 | a look-ahead. */ | |
8618 | next_type = read_1_byte (abfd, mac_ptr); | |
8619 | if (next_type != 0) | |
4d3c2250 KB |
8620 | complaint (&symfile_complaints, |
8621 | "no terminating 0-type entry for macros in `.debug_macinfo' section"); | |
2e276125 JB |
8622 | |
8623 | return; | |
8624 | } | |
8625 | } | |
8626 | break; | |
8627 | ||
8628 | case DW_MACINFO_vendor_ext: | |
8629 | { | |
8630 | int bytes_read; | |
8631 | int constant; | |
8632 | char *string; | |
8633 | ||
8634 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); | |
8635 | mac_ptr += bytes_read; | |
8636 | string = read_string (abfd, mac_ptr, &bytes_read); | |
8637 | mac_ptr += bytes_read; | |
8638 | ||
8639 | /* We don't recognize any vendor extensions. */ | |
8640 | } | |
8641 | break; | |
8642 | } | |
8643 | } | |
8644 | } | |
8e19ed76 PS |
8645 | |
8646 | /* Check if the attribute's form is a DW_FORM_block* | |
8647 | if so return true else false. */ | |
8648 | static int | |
8649 | attr_form_is_block (struct attribute *attr) | |
8650 | { | |
8651 | return (attr == NULL ? 0 : | |
8652 | attr->form == DW_FORM_block1 | |
8653 | || attr->form == DW_FORM_block2 | |
8654 | || attr->form == DW_FORM_block4 | |
8655 | || attr->form == DW_FORM_block); | |
8656 | } | |
4c2df51b DJ |
8657 | |
8658 | static void | |
8659 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |
e7c27a73 | 8660 | struct dwarf2_cu *cu) |
4c2df51b | 8661 | { |
0d53c4c4 | 8662 | if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
4c2df51b | 8663 | { |
0d53c4c4 | 8664 | struct dwarf2_loclist_baton *baton; |
4c2df51b | 8665 | |
4a146b47 | 8666 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8667 | sizeof (struct dwarf2_loclist_baton)); |
e7c27a73 | 8668 | baton->objfile = cu->objfile; |
4c2df51b | 8669 | |
0d53c4c4 DJ |
8670 | /* We don't know how long the location list is, but make sure we |
8671 | don't run off the edge of the section. */ | |
6502dd73 DJ |
8672 | baton->size = dwarf2_per_objfile->loc_size - DW_UNSND (attr); |
8673 | baton->data = dwarf2_per_objfile->loc_buffer + DW_UNSND (attr); | |
e7c27a73 DJ |
8674 | baton->base_address = cu->header.base_address; |
8675 | if (cu->header.base_known == 0) | |
0d53c4c4 DJ |
8676 | complaint (&symfile_complaints, |
8677 | "Location list used without specifying the CU base address."); | |
4c2df51b | 8678 | |
a67af2b9 | 8679 | SYMBOL_OPS (sym) = &dwarf2_loclist_funcs; |
0d53c4c4 DJ |
8680 | SYMBOL_LOCATION_BATON (sym) = baton; |
8681 | } | |
8682 | else | |
8683 | { | |
8684 | struct dwarf2_locexpr_baton *baton; | |
8685 | ||
4a146b47 | 8686 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
0d53c4c4 | 8687 | sizeof (struct dwarf2_locexpr_baton)); |
e7c27a73 | 8688 | baton->objfile = cu->objfile; |
0d53c4c4 DJ |
8689 | |
8690 | if (attr_form_is_block (attr)) | |
8691 | { | |
8692 | /* Note that we're just copying the block's data pointer | |
8693 | here, not the actual data. We're still pointing into the | |
6502dd73 DJ |
8694 | info_buffer for SYM's objfile; right now we never release |
8695 | that buffer, but when we do clean up properly this may | |
8696 | need to change. */ | |
0d53c4c4 DJ |
8697 | baton->size = DW_BLOCK (attr)->size; |
8698 | baton->data = DW_BLOCK (attr)->data; | |
8699 | } | |
8700 | else | |
8701 | { | |
8702 | dwarf2_invalid_attrib_class_complaint ("location description", | |
8703 | SYMBOL_NATURAL_NAME (sym)); | |
8704 | baton->size = 0; | |
8705 | baton->data = NULL; | |
8706 | } | |
8707 | ||
a67af2b9 | 8708 | SYMBOL_OPS (sym) = &dwarf2_locexpr_funcs; |
0d53c4c4 DJ |
8709 | SYMBOL_LOCATION_BATON (sym) = baton; |
8710 | } | |
4c2df51b | 8711 | } |
6502dd73 | 8712 | |
72bf9492 DJ |
8713 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
8714 | when we're finished with it. We can't free the pointer itself, but | |
8715 | release any associated storage. | |
8716 | ||
8717 | Only used during partial symbol parsing. */ | |
8718 | ||
8719 | static void | |
8720 | free_stack_comp_unit (void *data) | |
8721 | { | |
8722 | struct dwarf2_cu *cu = data; | |
8723 | ||
8724 | obstack_free (&cu->comp_unit_obstack, NULL); | |
8725 | cu->partial_dies = NULL; | |
8726 | } | |
8727 | ||
8728 | /* Allocation function for the libiberty hash table which uses an | |
8729 | obstack. */ | |
8730 | ||
8731 | static void * | |
8732 | hashtab_obstack_allocate (void *data, size_t size, size_t count) | |
8733 | { | |
8734 | unsigned int total = size * count; | |
8735 | void *ptr = obstack_alloc ((struct obstack *) data, total); | |
8736 | memset (ptr, 0, total); | |
8737 | return ptr; | |
8738 | } | |
8739 | ||
8740 | /* Trivial deallocation function for the libiberty splay tree and hash | |
8741 | table - don't deallocate anything. Rely on later deletion of the | |
8742 | obstack. */ | |
8743 | ||
8744 | static void | |
8745 | dummy_obstack_deallocate (void *object, void *data) | |
8746 | { | |
8747 | return; | |
8748 | } | |
8749 | ||
8750 | /* Trivial hash function for partial_die_info: the hash value of a DIE | |
8751 | is its offset in .debug_info for this objfile. */ | |
8752 | ||
8753 | static hashval_t | |
8754 | partial_die_hash (const void *item) | |
8755 | { | |
8756 | const struct partial_die_info *part_die = item; | |
8757 | return part_die->offset; | |
8758 | } | |
8759 | ||
8760 | /* Trivial comparison function for partial_die_info structures: two DIEs | |
8761 | are equal if they have the same offset. */ | |
8762 | ||
8763 | static int | |
8764 | partial_die_eq (const void *item_lhs, const void *item_rhs) | |
8765 | { | |
8766 | const struct partial_die_info *part_die_lhs = item_lhs; | |
8767 | const struct partial_die_info *part_die_rhs = item_rhs; | |
8768 | return part_die_lhs->offset == part_die_rhs->offset; | |
8769 | } | |
8770 | ||
6502dd73 DJ |
8771 | void _initialize_dwarf2_read (void); |
8772 | ||
8773 | void | |
8774 | _initialize_dwarf2_read (void) | |
8775 | { | |
8776 | dwarf2_objfile_data_key = register_objfile_data (); | |
8777 | } |