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