File: | src/gnu/usr.bin/binutils/gdb/dwarf2read.c |
Warning: | line 8701, column 22 The left expression of the compound assignment is an uninitialized value. The computed value will also be garbage |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* DWARF 2 debugging format support for GDB. | |||
2 | ||||
3 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, | |||
4 | 2004 | |||
5 | Free Software Foundation, Inc. | |||
6 | ||||
7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, | |||
8 | Inc. with support from Florida State University (under contract | |||
9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. | |||
10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., | |||
11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 | |||
12 | support in dwarfread.c | |||
13 | ||||
14 | This file is part of GDB. | |||
15 | ||||
16 | This program is free software; you can redistribute it and/or modify | |||
17 | it under the terms of the GNU General Public License as published by | |||
18 | the Free Software Foundation; either version 2 of the License, or (at | |||
19 | your option) any later version. | |||
20 | ||||
21 | This program is distributed in the hope that it will be useful, but | |||
22 | WITHOUT ANY WARRANTY; without even the implied warranty of | |||
23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
24 | General Public License for more details. | |||
25 | ||||
26 | You should have received a copy of the GNU General Public License | |||
27 | along with this program; if not, write to the Free Software | |||
28 | Foundation, Inc., 59 Temple Place - Suite 330, | |||
29 | Boston, MA 02111-1307, USA. */ | |||
30 | ||||
31 | #include "defs.h" | |||
32 | #include "bfd.h" | |||
33 | #include "symtab.h" | |||
34 | #include "gdbtypes.h" | |||
35 | #include "objfiles.h" | |||
36 | #include "elf/dwarf2.h" | |||
37 | #include "buildsym.h" | |||
38 | #include "demangle.h" | |||
39 | #include "expression.h" | |||
40 | #include "filenames.h" /* for DOSish file names */ | |||
41 | #include "macrotab.h" | |||
42 | #include "language.h" | |||
43 | #include "complaints.h" | |||
44 | #include "bcache.h" | |||
45 | #include "dwarf2expr.h" | |||
46 | #include "dwarf2loc.h" | |||
47 | #include "cp-support.h" | |||
48 | #include "hashtab.h" | |||
49 | #include "command.h" | |||
50 | #include "gdbcmd.h" | |||
51 | ||||
52 | #include <fcntl.h> | |||
53 | #include "gdb_string.h" | |||
54 | #include "gdb_assert.h" | |||
55 | #include <sys/types.h> | |||
56 | ||||
57 | /* A note on memory usage for this file. | |||
58 | ||||
59 | At the present time, this code reads the debug info sections into | |||
60 | the objfile's objfile_obstack. A definite improvement for startup | |||
61 | time, on platforms which do not emit relocations for debug | |||
62 | sections, would be to use mmap instead. The object's complete | |||
63 | debug information is loaded into memory, partly to simplify | |||
64 | absolute DIE references. | |||
65 | ||||
66 | Whether using obstacks or mmap, the sections should remain loaded | |||
67 | until the objfile is released, and pointers into the section data | |||
68 | can be used for any other data associated to the objfile (symbol | |||
69 | names, type names, location expressions to name a few). */ | |||
70 | ||||
71 | #ifndef DWARF2_REG_TO_REGNUM | |||
72 | #define DWARF2_REG_TO_REGNUM(REG)(gdbarch_dwarf2_reg_to_regnum (current_gdbarch, REG)) (REG) | |||
73 | #endif | |||
74 | ||||
75 | #if 0 | |||
76 | /* .debug_info header for a compilation unit | |||
77 | Because of alignment constraints, this structure has padding and cannot | |||
78 | be mapped directly onto the beginning of the .debug_info section. */ | |||
79 | typedef struct comp_unit_header | |||
80 | { | |||
81 | unsigned int length; /* length of the .debug_info | |||
82 | contribution */ | |||
83 | unsigned short version; /* version number -- 2 for DWARF | |||
84 | version 2 */ | |||
85 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ | |||
86 | unsigned char addr_size; /* byte size of an address -- 4 */ | |||
87 | } | |||
88 | _COMP_UNIT_HEADER; | |||
89 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 | |||
90 | #endif | |||
91 | ||||
92 | /* .debug_pubnames header | |||
93 | Because of alignment constraints, this structure has padding and cannot | |||
94 | be mapped directly onto the beginning of the .debug_info section. */ | |||
95 | typedef struct pubnames_header | |||
96 | { | |||
97 | unsigned int length; /* length of the .debug_pubnames | |||
98 | contribution */ | |||
99 | unsigned char version; /* version number -- 2 for DWARF | |||
100 | version 2 */ | |||
101 | unsigned int info_offset; /* offset into .debug_info section */ | |||
102 | unsigned int info_size; /* byte size of .debug_info section | |||
103 | portion */ | |||
104 | } | |||
105 | _PUBNAMES_HEADER; | |||
106 | #define _ACTUAL_PUBNAMES_HEADER_SIZE13 13 | |||
107 | ||||
108 | /* .debug_pubnames header | |||
109 | Because of alignment constraints, this structure has padding and cannot | |||
110 | be mapped directly onto the beginning of the .debug_info section. */ | |||
111 | typedef struct aranges_header | |||
112 | { | |||
113 | unsigned int length; /* byte len of the .debug_aranges | |||
114 | contribution */ | |||
115 | unsigned short version; /* version number -- 2 for DWARF | |||
116 | version 2 */ | |||
117 | unsigned int info_offset; /* offset into .debug_info section */ | |||
118 | unsigned char addr_size; /* byte size of an address */ | |||
119 | unsigned char seg_size; /* byte size of segment descriptor */ | |||
120 | } | |||
121 | _ARANGES_HEADER; | |||
122 | #define _ACTUAL_ARANGES_HEADER_SIZE12 12 | |||
123 | ||||
124 | /* .debug_line statement program prologue | |||
125 | Because of alignment constraints, this structure has padding and cannot | |||
126 | be mapped directly onto the beginning of the .debug_info section. */ | |||
127 | typedef struct statement_prologue | |||
128 | { | |||
129 | unsigned int total_length; /* byte length of the statement | |||
130 | information */ | |||
131 | unsigned short version; /* version number -- 2 for DWARF | |||
132 | version 2 */ | |||
133 | unsigned int prologue_length; /* # bytes between prologue & | |||
134 | stmt program */ | |||
135 | unsigned char minimum_instruction_length; /* byte size of | |||
136 | smallest instr */ | |||
137 | unsigned char default_is_stmt; /* initial value of is_stmt | |||
138 | register */ | |||
139 | char line_base; | |||
140 | unsigned char line_range; | |||
141 | unsigned char opcode_base; /* number assigned to first special | |||
142 | opcode */ | |||
143 | unsigned char *standard_opcode_lengths; | |||
144 | } | |||
145 | _STATEMENT_PROLOGUE; | |||
146 | ||||
147 | static const struct objfile_data *dwarf2_objfile_data_key; | |||
148 | ||||
149 | struct dwarf2_per_objfile | |||
150 | { | |||
151 | /* Sizes of debugging sections. */ | |||
152 | unsigned int info_size; | |||
153 | unsigned int abbrev_size; | |||
154 | unsigned int line_size; | |||
155 | unsigned int pubnames_size; | |||
156 | unsigned int aranges_size; | |||
157 | unsigned int loc_size; | |||
158 | unsigned int macinfo_size; | |||
159 | unsigned int str_size; | |||
160 | unsigned int ranges_size; | |||
161 | unsigned int frame_size; | |||
162 | unsigned int eh_frame_size; | |||
163 | ||||
164 | /* Loaded data from the sections. */ | |||
165 | char *info_buffer; | |||
166 | char *abbrev_buffer; | |||
167 | char *line_buffer; | |||
168 | char *str_buffer; | |||
169 | char *macinfo_buffer; | |||
170 | char *ranges_buffer; | |||
171 | char *loc_buffer; | |||
172 | ||||
173 | /* A list of all the compilation units. This is used to locate | |||
174 | the target compilation unit of a particular reference. */ | |||
175 | struct dwarf2_per_cu_data **all_comp_units; | |||
176 | ||||
177 | /* The number of compilation units in ALL_COMP_UNITS. */ | |||
178 | int n_comp_units; | |||
179 | ||||
180 | /* A chain of compilation units that are currently read in, so that | |||
181 | they can be freed later. */ | |||
182 | struct dwarf2_per_cu_data *read_in_chain; | |||
183 | }; | |||
184 | ||||
185 | static struct dwarf2_per_objfile *dwarf2_per_objfile; | |||
186 | ||||
187 | static asection *dwarf_info_section; | |||
188 | static asection *dwarf_abbrev_section; | |||
189 | static asection *dwarf_line_section; | |||
190 | static asection *dwarf_pubnames_section; | |||
191 | static asection *dwarf_aranges_section; | |||
192 | static asection *dwarf_loc_section; | |||
193 | static asection *dwarf_macinfo_section; | |||
194 | static asection *dwarf_str_section; | |||
195 | static asection *dwarf_ranges_section; | |||
196 | asection *dwarf_frame_section; | |||
197 | asection *dwarf_eh_frame_section; | |||
198 | ||||
199 | /* names of the debugging sections */ | |||
200 | ||||
201 | #define INFO_SECTION".debug_info" ".debug_info" | |||
202 | #define ABBREV_SECTION".debug_abbrev" ".debug_abbrev" | |||
203 | #define LINE_SECTION".debug_line" ".debug_line" | |||
204 | #define PUBNAMES_SECTION".debug_pubnames" ".debug_pubnames" | |||
205 | #define ARANGES_SECTION".debug_aranges" ".debug_aranges" | |||
206 | #define LOC_SECTION".debug_loc" ".debug_loc" | |||
207 | #define MACINFO_SECTION".debug_macinfo" ".debug_macinfo" | |||
208 | #define STR_SECTION".debug_str" ".debug_str" | |||
209 | #define RANGES_SECTION".debug_ranges" ".debug_ranges" | |||
210 | #define FRAME_SECTION".debug_frame" ".debug_frame" | |||
211 | #define EH_FRAME_SECTION".eh_frame" ".eh_frame" | |||
212 | ||||
213 | /* local data types */ | |||
214 | ||||
215 | /* We hold several abbreviation tables in memory at the same time. */ | |||
216 | #ifndef ABBREV_HASH_SIZE121 | |||
217 | #define ABBREV_HASH_SIZE121 121 | |||
218 | #endif | |||
219 | ||||
220 | /* The data in a compilation unit header, after target2host | |||
221 | translation, looks like this. */ | |||
222 | struct comp_unit_head | |||
223 | { | |||
224 | unsigned long length; | |||
225 | short version; | |||
226 | unsigned int abbrev_offset; | |||
227 | unsigned char addr_size; | |||
228 | unsigned char signed_addr_p; | |||
229 | ||||
230 | /* Size of file offsets; either 4 or 8. */ | |||
231 | unsigned int offset_size; | |||
232 | ||||
233 | /* Size of the length field; either 4 or 12. */ | |||
234 | unsigned int initial_length_size; | |||
235 | ||||
236 | /* Offset to the first byte of this compilation unit header in the | |||
237 | .debug_info section, for resolving relative reference dies. */ | |||
238 | unsigned int offset; | |||
239 | ||||
240 | /* Pointer to this compilation unit header in the .debug_info | |||
241 | section. */ | |||
242 | char *cu_head_ptr; | |||
243 | ||||
244 | /* Pointer to the first die of this compilation unit. This will be | |||
245 | the first byte following the compilation unit header. */ | |||
246 | char *first_die_ptr; | |||
247 | ||||
248 | /* Pointer to the next compilation unit header in the program. */ | |||
249 | struct comp_unit_head *next; | |||
250 | ||||
251 | /* Base address of this compilation unit. */ | |||
252 | CORE_ADDR base_address; | |||
253 | ||||
254 | /* Non-zero if base_address has been set. */ | |||
255 | int base_known; | |||
256 | }; | |||
257 | ||||
258 | /* Fixed size for the DIE hash table. */ | |||
259 | #ifndef REF_HASH_SIZE1021 | |||
260 | #define REF_HASH_SIZE1021 1021 | |||
261 | #endif | |||
262 | ||||
263 | /* Internal state when decoding a particular compilation unit. */ | |||
264 | struct dwarf2_cu | |||
265 | { | |||
266 | /* The objfile containing this compilation unit. */ | |||
267 | struct objfile *objfile; | |||
268 | ||||
269 | /* The header of the compilation unit. | |||
270 | ||||
271 | FIXME drow/2003-11-10: Some of the things from the comp_unit_head | |||
272 | should logically be moved to the dwarf2_cu structure. */ | |||
273 | struct comp_unit_head header; | |||
274 | ||||
275 | struct function_range *first_fn, *last_fn, *cached_fn; | |||
276 | ||||
277 | /* The language we are debugging. */ | |||
278 | enum language language; | |||
279 | const struct language_defn *language_defn; | |||
280 | ||||
281 | const char *producer; | |||
282 | ||||
283 | /* The generic symbol table building routines have separate lists for | |||
284 | file scope symbols and all all other scopes (local scopes). So | |||
285 | we need to select the right one to pass to add_symbol_to_list(). | |||
286 | We do it by keeping a pointer to the correct list in list_in_scope. | |||
287 | ||||
288 | FIXME: The original dwarf code just treated the file scope as the | |||
289 | first local scope, and all other local scopes as nested local | |||
290 | scopes, and worked fine. Check to see if we really need to | |||
291 | distinguish these in buildsym.c. */ | |||
292 | struct pending **list_in_scope; | |||
293 | ||||
294 | /* Maintain an array of referenced fundamental types for the current | |||
295 | compilation unit being read. For DWARF version 1, we have to construct | |||
296 | the fundamental types on the fly, since no information about the | |||
297 | fundamental types is supplied. Each such fundamental type is created by | |||
298 | calling a language dependent routine to create the type, and then a | |||
299 | pointer to that type is then placed in the array at the index specified | |||
300 | by it's FT_<TYPENAME> value. The array has a fixed size set by the | |||
301 | FT_NUM_MEMBERS compile time constant, which is the number of predefined | |||
302 | fundamental types gdb knows how to construct. */ | |||
303 | struct type *ftypes[FT_NUM_MEMBERS29]; /* Fundamental types */ | |||
304 | ||||
305 | /* DWARF abbreviation table associated with this compilation unit. */ | |||
306 | struct abbrev_info **dwarf2_abbrevs; | |||
307 | ||||
308 | /* Storage for the abbrev table. */ | |||
309 | struct obstack abbrev_obstack; | |||
310 | ||||
311 | /* Hash table holding all the loaded partial DIEs. */ | |||
312 | htab_t partial_dies; | |||
313 | ||||
314 | /* Storage for things with the same lifetime as this read-in compilation | |||
315 | unit, including partial DIEs. */ | |||
316 | struct obstack comp_unit_obstack; | |||
317 | ||||
318 | /* When multiple dwarf2_cu structures are living in memory, this field | |||
319 | chains them all together, so that they can be released efficiently. | |||
320 | We will probably also want a generation counter so that most-recently-used | |||
321 | compilation units are cached... */ | |||
322 | struct dwarf2_per_cu_data *read_in_chain; | |||
323 | ||||
324 | /* Backchain to our per_cu entry if the tree has been built. */ | |||
325 | struct dwarf2_per_cu_data *per_cu; | |||
326 | ||||
327 | /* How many compilation units ago was this CU last referenced? */ | |||
328 | int last_used; | |||
329 | ||||
330 | /* A hash table of die offsets for following references. */ | |||
331 | struct die_info *die_ref_table[REF_HASH_SIZE1021]; | |||
332 | ||||
333 | /* Full DIEs if read in. */ | |||
334 | struct die_info *dies; | |||
335 | ||||
336 | /* A set of pointers to dwarf2_per_cu_data objects for compilation | |||
337 | units referenced by this one. Only set during full symbol processing; | |||
338 | partial symbol tables do not have dependencies. */ | |||
339 | htab_t dependencies; | |||
340 | ||||
341 | /* Mark used when releasing cached dies. */ | |||
342 | unsigned int mark : 1; | |||
343 | ||||
344 | /* This flag will be set if this compilation unit might include | |||
345 | inter-compilation-unit references. */ | |||
346 | unsigned int has_form_ref_addr : 1; | |||
347 | ||||
348 | /* This flag will be set if this compilation unit includes any | |||
349 | DW_TAG_namespace DIEs. If we know that there are explicit | |||
350 | DIEs for namespaces, we don't need to try to infer them | |||
351 | from mangled names. */ | |||
352 | unsigned int has_namespace_info : 1; | |||
353 | }; | |||
354 | ||||
355 | /* Persistent data held for a compilation unit, even when not | |||
356 | processing it. We put a pointer to this structure in the | |||
357 | read_symtab_private field of the psymtab. If we encounter | |||
358 | inter-compilation-unit references, we also maintain a sorted | |||
359 | list of all compilation units. */ | |||
360 | ||||
361 | struct dwarf2_per_cu_data | |||
362 | { | |||
363 | /* The start offset and length of this compilation unit. 2**31-1 | |||
364 | bytes should suffice to store the length of any compilation unit | |||
365 | - if it doesn't, GDB will fall over anyway. */ | |||
366 | unsigned long offset; | |||
367 | unsigned long length : 31; | |||
368 | ||||
369 | /* Flag indicating this compilation unit will be read in before | |||
370 | any of the current compilation units are processed. */ | |||
371 | unsigned long queued : 1; | |||
372 | ||||
373 | /* Set iff currently read in. */ | |||
374 | struct dwarf2_cu *cu; | |||
375 | ||||
376 | /* If full symbols for this CU have been read in, then this field | |||
377 | holds a map of DIE offsets to types. It isn't always possible | |||
378 | to reconstruct this information later, so we have to preserve | |||
379 | it. */ | |||
380 | htab_t type_hash; | |||
381 | ||||
382 | /* The partial symbol table associated with this compilation unit. */ | |||
383 | struct partial_symtab *psymtab; | |||
384 | }; | |||
385 | ||||
386 | /* The line number information for a compilation unit (found in the | |||
387 | .debug_line section) begins with a "statement program header", | |||
388 | which contains the following information. */ | |||
389 | struct line_header | |||
390 | { | |||
391 | unsigned int total_length; | |||
392 | unsigned short version; | |||
393 | unsigned int header_length; | |||
394 | unsigned char minimum_instruction_length; | |||
395 | unsigned char default_is_stmt; | |||
396 | int line_base; | |||
397 | unsigned char line_range; | |||
398 | unsigned char opcode_base; | |||
399 | ||||
400 | /* standard_opcode_lengths[i] is the number of operands for the | |||
401 | standard opcode whose value is i. This means that | |||
402 | standard_opcode_lengths[0] is unused, and the last meaningful | |||
403 | element is standard_opcode_lengths[opcode_base - 1]. */ | |||
404 | unsigned char *standard_opcode_lengths; | |||
405 | ||||
406 | /* The include_directories table. NOTE! These strings are not | |||
407 | allocated with xmalloc; instead, they are pointers into | |||
408 | debug_line_buffer. If you try to free them, `free' will get | |||
409 | indigestion. */ | |||
410 | unsigned int num_include_dirs, include_dirs_size; | |||
411 | char **include_dirs; | |||
412 | ||||
413 | /* The file_names table. NOTE! These strings are not allocated | |||
414 | with xmalloc; instead, they are pointers into debug_line_buffer. | |||
415 | Don't try to free them directly. */ | |||
416 | unsigned int num_file_names, file_names_size; | |||
417 | struct file_entry | |||
418 | { | |||
419 | char *name; | |||
420 | unsigned int dir_index; | |||
421 | unsigned int mod_time; | |||
422 | unsigned int length; | |||
423 | int included_p; /* Non-zero if referenced by the Line Number Program. */ | |||
424 | } *file_names; | |||
425 | ||||
426 | /* The start and end of the statement program following this | |||
427 | header. These point into dwarf2_per_objfile->line_buffer. */ | |||
428 | char *statement_program_start, *statement_program_end; | |||
429 | }; | |||
430 | ||||
431 | /* When we construct a partial symbol table entry we only | |||
432 | need this much information. */ | |||
433 | struct partial_die_info | |||
434 | { | |||
435 | /* Offset of this DIE. */ | |||
436 | unsigned int offset; | |||
437 | ||||
438 | /* DWARF-2 tag for this DIE. */ | |||
439 | ENUM_BITFIELD(dwarf_tag)enum dwarf_tag tag : 16; | |||
440 | ||||
441 | /* Language code associated with this DIE. This is only used | |||
442 | for the compilation unit DIE. */ | |||
443 | unsigned int language : 8; | |||
444 | ||||
445 | /* Assorted flags describing the data found in this DIE. */ | |||
446 | unsigned int has_children : 1; | |||
447 | unsigned int is_external : 1; | |||
448 | unsigned int is_declaration : 1; | |||
449 | unsigned int has_type : 1; | |||
450 | unsigned int has_specification : 1; | |||
451 | unsigned int has_stmt_list : 1; | |||
452 | unsigned int has_pc_info : 1; | |||
453 | ||||
454 | /* Flag set if the SCOPE field of this structure has been | |||
455 | computed. */ | |||
456 | unsigned int scope_set : 1; | |||
457 | ||||
458 | /* The name of this DIE. Normally the value of DW_AT_name, but | |||
459 | sometimes DW_TAG_MIPS_linkage_name or a string computed in some | |||
460 | other fashion. */ | |||
461 | char *name; | |||
462 | char *dirname; | |||
463 | ||||
464 | /* The scope to prepend to our children. This is generally | |||
465 | allocated on the comp_unit_obstack, so will disappear | |||
466 | when this compilation unit leaves the cache. */ | |||
467 | char *scope; | |||
468 | ||||
469 | /* The location description associated with this DIE, if any. */ | |||
470 | struct dwarf_block *locdesc; | |||
471 | ||||
472 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ | |||
473 | CORE_ADDR lowpc; | |||
474 | CORE_ADDR highpc; | |||
475 | ||||
476 | /* Pointer into the info_buffer pointing at the target of | |||
477 | DW_AT_sibling, if any. */ | |||
478 | char *sibling; | |||
479 | ||||
480 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by | |||
481 | DW_AT_specification (or DW_AT_abstract_origin or | |||
482 | DW_AT_extension). */ | |||
483 | unsigned int spec_offset; | |||
484 | ||||
485 | /* If HAS_STMT_LIST, the offset of the Line Number Information data. */ | |||
486 | unsigned int line_offset; | |||
487 | ||||
488 | /* Pointers to this DIE's parent, first child, and next sibling, | |||
489 | if any. */ | |||
490 | struct partial_die_info *die_parent, *die_child, *die_sibling; | |||
491 | }; | |||
492 | ||||
493 | /* This data structure holds the information of an abbrev. */ | |||
494 | struct abbrev_info | |||
495 | { | |||
496 | unsigned int number; /* number identifying abbrev */ | |||
497 | enum dwarf_tag tag; /* dwarf tag */ | |||
498 | unsigned short has_children; /* boolean */ | |||
499 | unsigned short num_attrs; /* number of attributes */ | |||
500 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ | |||
501 | struct abbrev_info *next; /* next in chain */ | |||
502 | }; | |||
503 | ||||
504 | struct attr_abbrev | |||
505 | { | |||
506 | enum dwarf_attribute name; | |||
507 | enum dwarf_form form; | |||
508 | }; | |||
509 | ||||
510 | /* This data structure holds a complete die structure. */ | |||
511 | struct die_info | |||
512 | { | |||
513 | enum dwarf_tag tag; /* Tag indicating type of die */ | |||
514 | unsigned int abbrev; /* Abbrev number */ | |||
515 | unsigned int offset; /* Offset in .debug_info section */ | |||
516 | unsigned int num_attrs; /* Number of attributes */ | |||
517 | struct attribute *attrs; /* An array of attributes */ | |||
518 | struct die_info *next_ref; /* Next die in ref hash table */ | |||
519 | ||||
520 | /* The dies in a compilation unit form an n-ary tree. PARENT | |||
521 | points to this die's parent; CHILD points to the first child of | |||
522 | this node; and all the children of a given node are chained | |||
523 | together via their SIBLING fields, terminated by a die whose | |||
524 | tag is zero. */ | |||
525 | struct die_info *child; /* Its first child, if any. */ | |||
526 | struct die_info *sibling; /* Its next sibling, if any. */ | |||
527 | struct die_info *parent; /* Its parent, if any. */ | |||
528 | ||||
529 | struct type *type; /* Cached type information */ | |||
530 | }; | |||
531 | ||||
532 | /* Attributes have a name and a value */ | |||
533 | struct attribute | |||
534 | { | |||
535 | enum dwarf_attribute name; | |||
536 | enum dwarf_form form; | |||
537 | union | |||
538 | { | |||
539 | char *str; | |||
540 | struct dwarf_block *blk; | |||
541 | unsigned long unsnd; | |||
542 | long int snd; | |||
543 | CORE_ADDR addr; | |||
544 | } | |||
545 | u; | |||
546 | }; | |||
547 | ||||
548 | struct function_range | |||
549 | { | |||
550 | const char *name; | |||
551 | CORE_ADDR lowpc, highpc; | |||
552 | int seen_line; | |||
553 | struct function_range *next; | |||
554 | }; | |||
555 | ||||
556 | /* Get at parts of an attribute structure */ | |||
557 | ||||
558 | #define DW_STRING(attr)((attr)->u.str) ((attr)->u.str) | |||
559 | #define DW_UNSND(attr)((attr)->u.unsnd) ((attr)->u.unsnd) | |||
560 | #define DW_BLOCK(attr)((attr)->u.blk) ((attr)->u.blk) | |||
561 | #define DW_SND(attr)((attr)->u.snd) ((attr)->u.snd) | |||
562 | #define DW_ADDR(attr)((attr)->u.addr) ((attr)->u.addr) | |||
563 | ||||
564 | /* Blocks are a bunch of untyped bytes. */ | |||
565 | struct dwarf_block | |||
566 | { | |||
567 | unsigned int size; | |||
568 | char *data; | |||
569 | }; | |||
570 | ||||
571 | #ifndef ATTR_ALLOC_CHUNK4 | |||
572 | #define ATTR_ALLOC_CHUNK4 4 | |||
573 | #endif | |||
574 | ||||
575 | /* Allocate fields for structs, unions and enums in this size. */ | |||
576 | #ifndef DW_FIELD_ALLOC_CHUNK4 | |||
577 | #define DW_FIELD_ALLOC_CHUNK4 4 | |||
578 | #endif | |||
579 | ||||
580 | /* A zeroed version of a partial die for initialization purposes. */ | |||
581 | static struct partial_die_info zeroed_partial_die; | |||
582 | ||||
583 | /* FIXME: decode_locdesc sets these variables to describe the location | |||
584 | to the caller. These ought to be a structure or something. If | |||
585 | none of the flags are set, the object lives at the address returned | |||
586 | by decode_locdesc. */ | |||
587 | ||||
588 | static int isreg; /* Object lives in register. | |||
589 | decode_locdesc's return value is | |||
590 | the register number. */ | |||
591 | ||||
592 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, | |||
593 | but this would require a corresponding change in unpack_field_as_long | |||
594 | and friends. */ | |||
595 | static int bits_per_byte = 8; | |||
596 | ||||
597 | /* The routines that read and process dies for a C struct or C++ class | |||
598 | pass lists of data member fields and lists of member function fields | |||
599 | in an instance of a field_info structure, as defined below. */ | |||
600 | struct field_info | |||
601 | { | |||
602 | /* List of data member and baseclasses fields. */ | |||
603 | struct nextfield | |||
604 | { | |||
605 | struct nextfield *next; | |||
606 | int accessibility; | |||
607 | int virtuality; | |||
608 | struct field field; | |||
609 | } | |||
610 | *fields; | |||
611 | ||||
612 | /* Number of fields. */ | |||
613 | int nfields; | |||
614 | ||||
615 | /* Number of baseclasses. */ | |||
616 | int nbaseclasses; | |||
617 | ||||
618 | /* Set if the accesibility of one of the fields is not public. */ | |||
619 | int non_public_fields; | |||
620 | ||||
621 | /* Member function fields array, entries are allocated in the order they | |||
622 | are encountered in the object file. */ | |||
623 | struct nextfnfield | |||
624 | { | |||
625 | struct nextfnfield *next; | |||
626 | struct fn_field fnfield; | |||
627 | } | |||
628 | *fnfields; | |||
629 | ||||
630 | /* Member function fieldlist array, contains name of possibly overloaded | |||
631 | member function, number of overloaded member functions and a pointer | |||
632 | to the head of the member function field chain. */ | |||
633 | struct fnfieldlist | |||
634 | { | |||
635 | char *name; | |||
636 | int length; | |||
637 | struct nextfnfield *head; | |||
638 | } | |||
639 | *fnfieldlists; | |||
640 | ||||
641 | /* Number of entries in the fnfieldlists array. */ | |||
642 | int nfnfields; | |||
643 | }; | |||
644 | ||||
645 | /* One item on the queue of compilation units to read in full symbols | |||
646 | for. */ | |||
647 | struct dwarf2_queue_item | |||
648 | { | |||
649 | struct dwarf2_per_cu_data *per_cu; | |||
650 | struct dwarf2_queue_item *next; | |||
651 | }; | |||
652 | ||||
653 | /* The current queue. */ | |||
654 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; | |||
655 | ||||
656 | /* Loaded secondary compilation units are kept in memory until they | |||
657 | have not been referenced for the processing of this many | |||
658 | compilation units. Set this to zero to disable caching. Cache | |||
659 | sizes of up to at least twenty will improve startup time for | |||
660 | typical inter-CU-reference binaries, at an obvious memory cost. */ | |||
661 | static int dwarf2_max_cache_age = 5; | |||
662 | ||||
663 | /* Various complaints about symbol reading that don't abort the process */ | |||
664 | ||||
665 | static void | |||
666 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) | |||
667 | { | |||
668 | complaint (&symfile_complaints, | |||
669 | "statement list doesn't fit in .debug_line section"); | |||
670 | } | |||
671 | ||||
672 | static void | |||
673 | dwarf2_complex_location_expr_complaint (void) | |||
674 | { | |||
675 | complaint (&symfile_complaints, "location expression too complex"); | |||
676 | } | |||
677 | ||||
678 | static void | |||
679 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, | |||
680 | int arg3) | |||
681 | { | |||
682 | complaint (&symfile_complaints, | |||
683 | "const value length mismatch for '%s', got %d, expected %d", arg1, | |||
684 | arg2, arg3); | |||
685 | } | |||
686 | ||||
687 | static void | |||
688 | dwarf2_macros_too_long_complaint (void) | |||
689 | { | |||
690 | complaint (&symfile_complaints, | |||
691 | "macro info runs off end of `.debug_macinfo' section"); | |||
692 | } | |||
693 | ||||
694 | static void | |||
695 | dwarf2_macro_malformed_definition_complaint (const char *arg1) | |||
696 | { | |||
697 | complaint (&symfile_complaints, | |||
698 | "macro debug info contains a malformed macro definition:\n`%s'", | |||
699 | arg1); | |||
700 | } | |||
701 | ||||
702 | static void | |||
703 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) | |||
704 | { | |||
705 | complaint (&symfile_complaints, | |||
706 | "invalid attribute class or form for '%s' in '%s'", arg1, arg2); | |||
707 | } | |||
708 | ||||
709 | /* local function prototypes */ | |||
710 | ||||
711 | static void dwarf2_locate_sections (bfd *, asection *, void *); | |||
712 | ||||
713 | #if 0 | |||
714 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); | |||
715 | #endif | |||
716 | ||||
717 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, | |||
718 | struct objfile *); | |||
719 | ||||
720 | static void dwarf2_build_include_psymtabs (struct dwarf2_cu *, | |||
721 | struct partial_die_info *, | |||
722 | struct partial_symtab *); | |||
723 | ||||
724 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); | |||
725 | ||||
726 | static void scan_partial_symbols (struct partial_die_info *, | |||
727 | CORE_ADDR *, CORE_ADDR *, | |||
728 | struct dwarf2_cu *); | |||
729 | ||||
730 | static void add_partial_symbol (struct partial_die_info *, | |||
731 | struct dwarf2_cu *); | |||
732 | ||||
733 | static int pdi_needs_namespace (enum dwarf_tag tag); | |||
734 | ||||
735 | static void add_partial_namespace (struct partial_die_info *pdi, | |||
736 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |||
737 | struct dwarf2_cu *cu); | |||
738 | ||||
739 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, | |||
740 | struct dwarf2_cu *cu); | |||
741 | ||||
742 | static char *locate_pdi_sibling (struct partial_die_info *orig_pdi, | |||
743 | char *info_ptr, | |||
744 | bfd *abfd, | |||
745 | struct dwarf2_cu *cu); | |||
746 | ||||
747 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); | |||
748 | ||||
749 | static void psymtab_to_symtab_1 (struct partial_symtab *); | |||
750 | ||||
751 | char *dwarf2_read_section (struct objfile *, asection *); | |||
752 | ||||
753 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); | |||
754 | ||||
755 | static void dwarf2_free_abbrev_table (void *); | |||
756 | ||||
757 | static struct abbrev_info *peek_die_abbrev (char *, int *, struct dwarf2_cu *); | |||
758 | ||||
759 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, | |||
760 | struct dwarf2_cu *); | |||
761 | ||||
762 | static struct partial_die_info *load_partial_dies (bfd *, char *, int, | |||
763 | struct dwarf2_cu *); | |||
764 | ||||
765 | static char *read_partial_die (struct partial_die_info *, | |||
766 | struct abbrev_info *abbrev, unsigned int, | |||
767 | bfd *, char *, struct dwarf2_cu *); | |||
768 | ||||
769 | static struct partial_die_info *find_partial_die (unsigned long, | |||
770 | struct dwarf2_cu *); | |||
771 | ||||
772 | static void fixup_partial_die (struct partial_die_info *, | |||
773 | struct dwarf2_cu *); | |||
774 | ||||
775 | static char *read_full_die (struct die_info **, bfd *, char *, | |||
776 | struct dwarf2_cu *, int *); | |||
777 | ||||
778 | static char *read_attribute (struct attribute *, struct attr_abbrev *, | |||
779 | bfd *, char *, struct dwarf2_cu *); | |||
780 | ||||
781 | static char *read_attribute_value (struct attribute *, unsigned, | |||
782 | bfd *, char *, struct dwarf2_cu *); | |||
783 | ||||
784 | static unsigned int read_1_byte (bfd *, char *); | |||
785 | ||||
786 | static int read_1_signed_byte (bfd *, char *); | |||
787 | ||||
788 | static unsigned int read_2_bytes (bfd *, char *); | |||
789 | ||||
790 | static unsigned int read_4_bytes (bfd *, char *); | |||
791 | ||||
792 | static unsigned long read_8_bytes (bfd *, char *); | |||
793 | ||||
794 | static CORE_ADDR read_address (bfd *, char *ptr, struct dwarf2_cu *, | |||
795 | int *bytes_read); | |||
796 | ||||
797 | static LONGESTlong read_initial_length (bfd *, char *, | |||
798 | struct comp_unit_head *, int *bytes_read); | |||
799 | ||||
800 | static LONGESTlong read_offset (bfd *, char *, const struct comp_unit_head *, | |||
801 | int *bytes_read); | |||
802 | ||||
803 | static char *read_n_bytes (bfd *, char *, unsigned int); | |||
804 | ||||
805 | static char *read_string (bfd *, char *, unsigned int *); | |||
806 | ||||
807 | static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, | |||
808 | unsigned int *); | |||
809 | ||||
810 | static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); | |||
811 | ||||
812 | static long read_signed_leb128 (bfd *, char *, unsigned int *); | |||
813 | ||||
814 | static char *skip_leb128 (bfd *, char *); | |||
815 | ||||
816 | static void set_cu_language (unsigned int, struct dwarf2_cu *); | |||
817 | ||||
818 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, | |||
819 | struct dwarf2_cu *); | |||
820 | ||||
821 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, | |||
822 | struct dwarf2_cu *cu); | |||
823 | ||||
824 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); | |||
825 | ||||
826 | static struct die_info *die_specification (struct die_info *die, | |||
827 | struct dwarf2_cu *); | |||
828 | ||||
829 | static void free_line_header (struct line_header *lh); | |||
830 | ||||
831 | static void add_file_name (struct line_header *, char *, unsigned int, | |||
832 | unsigned int, unsigned int); | |||
833 | ||||
834 | static struct line_header *(dwarf_decode_line_header | |||
835 | (unsigned int offset, | |||
836 | bfd *abfd, struct dwarf2_cu *cu)); | |||
837 | ||||
838 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, | |||
839 | struct dwarf2_cu *, struct partial_symtab *); | |||
840 | ||||
841 | static void dwarf2_start_subfile (char *, char *); | |||
842 | ||||
843 | static struct symbol *new_symbol (struct die_info *, struct type *, | |||
844 | struct dwarf2_cu *); | |||
845 | ||||
846 | static void dwarf2_const_value (struct attribute *, struct symbol *, | |||
847 | struct dwarf2_cu *); | |||
848 | ||||
849 | static void dwarf2_const_value_data (struct attribute *attr, | |||
850 | struct symbol *sym, | |||
851 | int bits); | |||
852 | ||||
853 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); | |||
854 | ||||
855 | static struct type *die_containing_type (struct die_info *, | |||
856 | struct dwarf2_cu *); | |||
857 | ||||
858 | static struct type *tag_type_to_type (struct die_info *, struct dwarf2_cu *); | |||
859 | ||||
860 | static void read_type_die (struct die_info *, struct dwarf2_cu *); | |||
861 | ||||
862 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); | |||
863 | ||||
864 | static char *typename_concat (struct obstack *, const char *prefix, const char *suffix, | |||
865 | struct dwarf2_cu *); | |||
866 | ||||
867 | static void read_typedef (struct die_info *, struct dwarf2_cu *); | |||
868 | ||||
869 | static void read_base_type (struct die_info *, struct dwarf2_cu *); | |||
870 | ||||
871 | static void read_subrange_type (struct die_info *die, struct dwarf2_cu *cu); | |||
872 | ||||
873 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); | |||
874 | ||||
875 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); | |||
876 | ||||
877 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); | |||
878 | ||||
879 | static int dwarf2_get_pc_bounds (struct die_info *, | |||
880 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *); | |||
881 | ||||
882 | static void get_scope_pc_bounds (struct die_info *, | |||
883 | CORE_ADDR *, CORE_ADDR *, | |||
884 | struct dwarf2_cu *); | |||
885 | ||||
886 | static void dwarf2_add_field (struct field_info *, struct die_info *, | |||
887 | struct dwarf2_cu *); | |||
888 | ||||
889 | static void dwarf2_attach_fields_to_type (struct field_info *, | |||
890 | struct type *, struct dwarf2_cu *); | |||
891 | ||||
892 | static void dwarf2_add_member_fn (struct field_info *, | |||
893 | struct die_info *, struct type *, | |||
894 | struct dwarf2_cu *); | |||
895 | ||||
896 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, | |||
897 | struct type *, struct dwarf2_cu *); | |||
898 | ||||
899 | static void read_structure_type (struct die_info *, struct dwarf2_cu *); | |||
900 | ||||
901 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); | |||
902 | ||||
903 | static char *determine_class_name (struct die_info *die, struct dwarf2_cu *cu); | |||
904 | ||||
905 | static void read_common_block (struct die_info *, struct dwarf2_cu *); | |||
906 | ||||
907 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); | |||
908 | ||||
909 | static const char *namespace_name (struct die_info *die, | |||
910 | int *is_anonymous, struct dwarf2_cu *); | |||
911 | ||||
912 | static void read_enumeration_type (struct die_info *, struct dwarf2_cu *); | |||
913 | ||||
914 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); | |||
915 | ||||
916 | static struct type *dwarf_base_type (int, int, struct dwarf2_cu *); | |||
917 | ||||
918 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); | |||
919 | ||||
920 | static void read_array_type (struct die_info *, struct dwarf2_cu *); | |||
921 | ||||
922 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, | |||
923 | struct dwarf2_cu *); | |||
924 | ||||
925 | static void read_tag_pointer_type (struct die_info *, struct dwarf2_cu *); | |||
926 | ||||
927 | static void read_tag_ptr_to_member_type (struct die_info *, | |||
928 | struct dwarf2_cu *); | |||
929 | ||||
930 | static void read_tag_reference_type (struct die_info *, struct dwarf2_cu *); | |||
931 | ||||
932 | static void read_tag_const_type (struct die_info *, struct dwarf2_cu *); | |||
933 | ||||
934 | static void read_tag_volatile_type (struct die_info *, struct dwarf2_cu *); | |||
935 | ||||
936 | static void read_tag_string_type (struct die_info *, struct dwarf2_cu *); | |||
937 | ||||
938 | static void read_subroutine_type (struct die_info *, struct dwarf2_cu *); | |||
939 | ||||
940 | static struct die_info *read_comp_unit (char *, bfd *, struct dwarf2_cu *); | |||
941 | ||||
942 | static struct die_info *read_die_and_children (char *info_ptr, bfd *abfd, | |||
943 | struct dwarf2_cu *, | |||
944 | char **new_info_ptr, | |||
945 | struct die_info *parent); | |||
946 | ||||
947 | static struct die_info *read_die_and_siblings (char *info_ptr, bfd *abfd, | |||
948 | struct dwarf2_cu *, | |||
949 | char **new_info_ptr, | |||
950 | struct die_info *parent); | |||
951 | ||||
952 | static void free_die_list (struct die_info *); | |||
953 | ||||
954 | static void process_die (struct die_info *, struct dwarf2_cu *); | |||
955 | ||||
956 | static char *dwarf2_linkage_name (struct die_info *, struct dwarf2_cu *); | |||
957 | ||||
958 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); | |||
959 | ||||
960 | static struct die_info *dwarf2_extension (struct die_info *die, | |||
961 | struct dwarf2_cu *); | |||
962 | ||||
963 | static char *dwarf_tag_name (unsigned int); | |||
964 | ||||
965 | static char *dwarf_attr_name (unsigned int); | |||
966 | ||||
967 | static char *dwarf_form_name (unsigned int); | |||
968 | ||||
969 | static char *dwarf_stack_op_name (unsigned int); | |||
970 | ||||
971 | static char *dwarf_bool_name (unsigned int); | |||
972 | ||||
973 | static char *dwarf_type_encoding_name (unsigned int); | |||
974 | ||||
975 | #if 0 | |||
976 | static char *dwarf_cfi_name (unsigned int); | |||
977 | ||||
978 | struct die_info *copy_die (struct die_info *); | |||
979 | #endif | |||
980 | ||||
981 | static struct die_info *sibling_die (struct die_info *); | |||
982 | ||||
983 | static void dump_die (struct die_info *); | |||
984 | ||||
985 | static void dump_die_list (struct die_info *); | |||
986 | ||||
987 | static void store_in_ref_table (unsigned int, struct die_info *, | |||
988 | struct dwarf2_cu *); | |||
989 | ||||
990 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *, | |||
991 | struct dwarf2_cu *); | |||
992 | ||||
993 | static int dwarf2_get_attr_constant_value (struct attribute *, int); | |||
994 | ||||
995 | static struct die_info *follow_die_ref (struct die_info *, | |||
996 | struct attribute *, | |||
997 | struct dwarf2_cu *); | |||
998 | ||||
999 | static struct type *dwarf2_fundamental_type (struct objfile *, int, | |||
1000 | struct dwarf2_cu *); | |||
1001 | ||||
1002 | /* memory allocation interface */ | |||
1003 | ||||
1004 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); | |||
1005 | ||||
1006 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); | |||
1007 | ||||
1008 | static struct die_info *dwarf_alloc_die (void); | |||
1009 | ||||
1010 | static void initialize_cu_func_list (struct dwarf2_cu *); | |||
1011 | ||||
1012 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, | |||
1013 | struct dwarf2_cu *); | |||
1014 | ||||
1015 | static void dwarf_decode_macros (struct line_header *, unsigned int, | |||
1016 | char *, bfd *, struct dwarf2_cu *); | |||
1017 | ||||
1018 | static int attr_form_is_block (struct attribute *); | |||
1019 | ||||
1020 | static void | |||
1021 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, | |||
1022 | struct dwarf2_cu *cu); | |||
1023 | ||||
1024 | static char *skip_one_die (char *info_ptr, struct abbrev_info *abbrev, | |||
1025 | struct dwarf2_cu *cu); | |||
1026 | ||||
1027 | static void free_stack_comp_unit (void *); | |||
1028 | ||||
1029 | static void *hashtab_obstack_allocate (void *data, size_t size, size_t count); | |||
1030 | ||||
1031 | static void dummy_obstack_deallocate (void *object, void *data); | |||
1032 | ||||
1033 | static hashval_t partial_die_hash (const void *item); | |||
1034 | ||||
1035 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); | |||
1036 | ||||
1037 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit | |||
1038 | (unsigned long offset, struct objfile *objfile); | |||
1039 | ||||
1040 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit | |||
1041 | (unsigned long offset, struct objfile *objfile); | |||
1042 | ||||
1043 | static void free_one_comp_unit (void *); | |||
1044 | ||||
1045 | static void free_cached_comp_units (void *); | |||
1046 | ||||
1047 | static void age_cached_comp_units (void); | |||
1048 | ||||
1049 | static void free_one_cached_comp_unit (void *); | |||
1050 | ||||
1051 | static void set_die_type (struct die_info *, struct type *, | |||
1052 | struct dwarf2_cu *); | |||
1053 | ||||
1054 | static void reset_die_and_siblings_types (struct die_info *, | |||
1055 | struct dwarf2_cu *); | |||
1056 | ||||
1057 | static void create_all_comp_units (struct objfile *); | |||
1058 | ||||
1059 | static struct dwarf2_cu *load_full_comp_unit (struct dwarf2_per_cu_data *); | |||
1060 | ||||
1061 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); | |||
1062 | ||||
1063 | static void dwarf2_add_dependence (struct dwarf2_cu *, | |||
1064 | struct dwarf2_per_cu_data *); | |||
1065 | ||||
1066 | static void dwarf2_mark (struct dwarf2_cu *); | |||
1067 | ||||
1068 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); | |||
1069 | ||||
1070 | /* Try to locate the sections we need for DWARF 2 debugging | |||
1071 | information and return true if we have enough to do something. */ | |||
1072 | ||||
1073 | int | |||
1074 | dwarf2_has_info (struct objfile *objfile) | |||
1075 | { | |||
1076 | struct dwarf2_per_objfile *data; | |||
1077 | ||||
1078 | /* Initialize per-objfile state. */ | |||
1079 | data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data))__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (*data))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack * __o1 = (__h); void *value; value = (void *) __o1->object_base ; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char * ) 0)+__o1->alignment_mask) & ~ (__o1->alignment_mask )) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1-> next_free = __o1->chunk_limit; __o1->object_base = __o1 ->next_free; value; }); }); | |||
1080 | memset (data, 0, sizeof (*data)); | |||
1081 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); | |||
1082 | dwarf2_per_objfile = data; | |||
1083 | ||||
1084 | dwarf_info_section = 0; | |||
1085 | dwarf_abbrev_section = 0; | |||
1086 | dwarf_line_section = 0; | |||
1087 | dwarf_str_section = 0; | |||
1088 | dwarf_macinfo_section = 0; | |||
1089 | dwarf_frame_section = 0; | |||
1090 | dwarf_eh_frame_section = 0; | |||
1091 | dwarf_ranges_section = 0; | |||
1092 | dwarf_loc_section = 0; | |||
1093 | ||||
1094 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL((void*)0)); | |||
1095 | return (dwarf_info_section != NULL((void*)0) && dwarf_abbrev_section != NULL((void*)0)); | |||
1096 | } | |||
1097 | ||||
1098 | /* This function is mapped across the sections and remembers the | |||
1099 | offset and size of each of the debugging sections we are interested | |||
1100 | in. */ | |||
1101 | ||||
1102 | static void | |||
1103 | dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) | |||
1104 | { | |||
1105 | if (strcmp (sectp->name, INFO_SECTION".debug_info") == 0) | |||
1106 | { | |||
1107 | dwarf2_per_objfile->info_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1108 | dwarf_info_section = sectp; | |||
1109 | } | |||
1110 | else if (strcmp (sectp->name, ABBREV_SECTION".debug_abbrev") == 0) | |||
1111 | { | |||
1112 | dwarf2_per_objfile->abbrev_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1113 | dwarf_abbrev_section = sectp; | |||
1114 | } | |||
1115 | else if (strcmp (sectp->name, LINE_SECTION".debug_line") == 0) | |||
1116 | { | |||
1117 | dwarf2_per_objfile->line_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1118 | dwarf_line_section = sectp; | |||
1119 | } | |||
1120 | else if (strcmp (sectp->name, PUBNAMES_SECTION".debug_pubnames") == 0) | |||
1121 | { | |||
1122 | dwarf2_per_objfile->pubnames_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1123 | dwarf_pubnames_section = sectp; | |||
1124 | } | |||
1125 | else if (strcmp (sectp->name, ARANGES_SECTION".debug_aranges") == 0) | |||
1126 | { | |||
1127 | dwarf2_per_objfile->aranges_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1128 | dwarf_aranges_section = sectp; | |||
1129 | } | |||
1130 | else if (strcmp (sectp->name, LOC_SECTION".debug_loc") == 0) | |||
1131 | { | |||
1132 | dwarf2_per_objfile->loc_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1133 | dwarf_loc_section = sectp; | |||
1134 | } | |||
1135 | else if (strcmp (sectp->name, MACINFO_SECTION".debug_macinfo") == 0) | |||
1136 | { | |||
1137 | dwarf2_per_objfile->macinfo_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1138 | dwarf_macinfo_section = sectp; | |||
1139 | } | |||
1140 | else if (strcmp (sectp->name, STR_SECTION".debug_str") == 0) | |||
1141 | { | |||
1142 | dwarf2_per_objfile->str_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1143 | dwarf_str_section = sectp; | |||
1144 | } | |||
1145 | else if (strcmp (sectp->name, FRAME_SECTION".debug_frame") == 0) | |||
1146 | { | |||
1147 | dwarf2_per_objfile->frame_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1148 | dwarf_frame_section = sectp; | |||
1149 | } | |||
1150 | else if (strcmp (sectp->name, EH_FRAME_SECTION".eh_frame") == 0) | |||
1151 | { | |||
1152 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp)((sectp)->flags + 0); | |||
1153 | if (aflag & SEC_HAS_CONTENTS0x200) | |||
1154 | { | |||
1155 | dwarf2_per_objfile->eh_frame_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1156 | dwarf_eh_frame_section = sectp; | |||
1157 | } | |||
1158 | } | |||
1159 | else if (strcmp (sectp->name, RANGES_SECTION".debug_ranges") == 0) | |||
1160 | { | |||
1161 | dwarf2_per_objfile->ranges_size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
1162 | dwarf_ranges_section = sectp; | |||
1163 | } | |||
1164 | } | |||
1165 | ||||
1166 | /* Build a partial symbol table. */ | |||
1167 | ||||
1168 | void | |||
1169 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) | |||
1170 | { | |||
1171 | /* We definitely need the .debug_info and .debug_abbrev sections */ | |||
1172 | ||||
1173 | dwarf2_per_objfile->info_buffer = dwarf2_read_section (objfile, dwarf_info_section); | |||
1174 | dwarf2_per_objfile->abbrev_buffer = dwarf2_read_section (objfile, dwarf_abbrev_section); | |||
1175 | ||||
1176 | if (dwarf_line_section) | |||
1177 | dwarf2_per_objfile->line_buffer = dwarf2_read_section (objfile, dwarf_line_section); | |||
1178 | else | |||
1179 | dwarf2_per_objfile->line_buffer = NULL((void*)0); | |||
1180 | ||||
1181 | if (dwarf_str_section) | |||
1182 | dwarf2_per_objfile->str_buffer = dwarf2_read_section (objfile, dwarf_str_section); | |||
1183 | else | |||
1184 | dwarf2_per_objfile->str_buffer = NULL((void*)0); | |||
1185 | ||||
1186 | if (dwarf_macinfo_section) | |||
1187 | dwarf2_per_objfile->macinfo_buffer = dwarf2_read_section (objfile, | |||
1188 | dwarf_macinfo_section); | |||
1189 | else | |||
1190 | dwarf2_per_objfile->macinfo_buffer = NULL((void*)0); | |||
1191 | ||||
1192 | if (dwarf_ranges_section) | |||
1193 | dwarf2_per_objfile->ranges_buffer = dwarf2_read_section (objfile, dwarf_ranges_section); | |||
1194 | else | |||
1195 | dwarf2_per_objfile->ranges_buffer = NULL((void*)0); | |||
1196 | ||||
1197 | if (dwarf_loc_section) | |||
1198 | dwarf2_per_objfile->loc_buffer = dwarf2_read_section (objfile, dwarf_loc_section); | |||
1199 | else | |||
1200 | dwarf2_per_objfile->loc_buffer = NULL((void*)0); | |||
1201 | ||||
1202 | if (mainline | |||
1203 | || (objfile->global_psymbols.size == 0 | |||
1204 | && objfile->static_psymbols.size == 0)) | |||
1205 | { | |||
1206 | init_psymbol_list (objfile, 1024); | |||
1207 | } | |||
1208 | ||||
1209 | #if 0 | |||
1210 | if (dwarf_aranges_offset && dwarf_pubnames_offset) | |||
1211 | { | |||
1212 | /* Things are significantly easier if we have .debug_aranges and | |||
1213 | .debug_pubnames sections */ | |||
1214 | ||||
1215 | dwarf2_build_psymtabs_easy (objfile, mainline); | |||
1216 | } | |||
1217 | else | |||
1218 | #endif | |||
1219 | /* only test this case for now */ | |||
1220 | { | |||
1221 | /* In this case we have to work a bit harder */ | |||
1222 | dwarf2_build_psymtabs_hard (objfile, mainline); | |||
1223 | } | |||
1224 | } | |||
1225 | ||||
1226 | #if 0 | |||
1227 | /* Build the partial symbol table from the information in the | |||
1228 | .debug_pubnames and .debug_aranges sections. */ | |||
1229 | ||||
1230 | static void | |||
1231 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) | |||
1232 | { | |||
1233 | bfd *abfd = objfile->obfd; | |||
1234 | char *aranges_buffer, *pubnames_buffer; | |||
1235 | char *aranges_ptr, *pubnames_ptr; | |||
1236 | unsigned int entry_length, version, info_offset, info_size; | |||
1237 | ||||
1238 | pubnames_buffer = dwarf2_read_section (objfile, | |||
1239 | dwarf_pubnames_section); | |||
1240 | pubnames_ptr = pubnames_buffer; | |||
1241 | while ((pubnames_ptr - pubnames_buffer) < dwarf2_per_objfile->pubnames_size) | |||
1242 | { | |||
1243 | struct comp_unit_head cu_header; | |||
1244 | int bytes_read; | |||
1245 | ||||
1246 | cu_header.initial_length_size = 0; | |||
1247 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, | |||
1248 | &bytes_read); | |||
1249 | pubnames_ptr += bytes_read; | |||
1250 | version = read_1_byte (abfd, pubnames_ptr); | |||
1251 | pubnames_ptr += 1; | |||
1252 | info_offset = read_4_bytes (abfd, pubnames_ptr); | |||
1253 | pubnames_ptr += 4; | |||
1254 | info_size = read_4_bytes (abfd, pubnames_ptr); | |||
1255 | pubnames_ptr += 4; | |||
1256 | } | |||
1257 | ||||
1258 | aranges_buffer = dwarf2_read_section (objfile, | |||
1259 | dwarf_aranges_section); | |||
1260 | ||||
1261 | } | |||
1262 | #endif | |||
1263 | ||||
1264 | /* Read in the comp unit header information from the debug_info at | |||
1265 | info_ptr. */ | |||
1266 | ||||
1267 | static char * | |||
1268 | read_comp_unit_head (struct comp_unit_head *cu_header, | |||
1269 | char *info_ptr, bfd *abfd) | |||
1270 | { | |||
1271 | int signed_addr; | |||
1272 | int bytes_read; | |||
1273 | ||||
1274 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, | |||
1275 | &bytes_read); | |||
1276 | info_ptr += bytes_read; | |||
1277 | cu_header->version = read_2_bytes (abfd, info_ptr); | |||
1278 | info_ptr += 2; | |||
1279 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, | |||
1280 | &bytes_read); | |||
1281 | info_ptr += bytes_read; | |||
1282 | cu_header->addr_size = read_1_byte (abfd, info_ptr); | |||
1283 | info_ptr += 1; | |||
1284 | signed_addr = bfd_get_sign_extend_vma (abfd); | |||
1285 | if (signed_addr < 0) | |||
1286 | internal_error (__FILE__"/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", __LINE__1286, | |||
1287 | "read_comp_unit_head: dwarf from non elf file"); | |||
1288 | cu_header->signed_addr_p = signed_addr; | |||
1289 | return info_ptr; | |||
1290 | } | |||
1291 | ||||
1292 | static char * | |||
1293 | partial_read_comp_unit_head (struct comp_unit_head *header, char *info_ptr, | |||
1294 | bfd *abfd) | |||
1295 | { | |||
1296 | char *beg_of_comp_unit = info_ptr; | |||
1297 | ||||
1298 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); | |||
1299 | ||||
1300 | if (header->version != 2) | |||
1301 | error ("Dwarf Error: wrong version in compilation unit header " | |||
1302 | "(is %d, should be %d) [in module %s]", header->version, | |||
1303 | 2, bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
1304 | ||||
1305 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev_size) | |||
1306 | error ("Dwarf Error: bad offset (0x%lx) in compilation unit header " | |||
1307 | "(offset 0x%lx + 6) [in module %s]", | |||
1308 | (long) header->abbrev_offset, | |||
1309 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |||
1310 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
1311 | ||||
1312 | if (beg_of_comp_unit + header->length + header->initial_length_size | |||
1313 | > dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |||
1314 | error ("Dwarf Error: bad length (0x%lx) in compilation unit header " | |||
1315 | "(offset 0x%lx + 0) [in module %s]", | |||
1316 | (long) header->length, | |||
1317 | (long) (beg_of_comp_unit - dwarf2_per_objfile->info_buffer), | |||
1318 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
1319 | ||||
1320 | return info_ptr; | |||
1321 | } | |||
1322 | ||||
1323 | /* Allocate a new partial symtab for file named NAME and mark this new | |||
1324 | partial symtab as being an include of PST. */ | |||
1325 | ||||
1326 | static void | |||
1327 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, | |||
1328 | struct objfile *objfile) | |||
1329 | { | |||
1330 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); | |||
1331 | ||||
1332 | subpst->section_offsets = pst->section_offsets; | |||
1333 | subpst->textlow = 0; | |||
1334 | subpst->texthigh = 0; | |||
1335 | ||||
1336 | subpst->dependencies = (struct partial_symtab **) | |||
1337 | obstack_alloc (&objfile->objfile_obstack,__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_symtab *))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
1338 | sizeof (struct partial_symtab *))__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_symtab *))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }); | |||
1339 | subpst->dependencies[0] = pst; | |||
1340 | subpst->number_of_dependencies = 1; | |||
1341 | ||||
1342 | subpst->globals_offset = 0; | |||
1343 | subpst->n_global_syms = 0; | |||
1344 | subpst->statics_offset = 0; | |||
1345 | subpst->n_static_syms = 0; | |||
1346 | subpst->symtab = NULL((void*)0); | |||
1347 | subpst->read_symtab = pst->read_symtab; | |||
1348 | subpst->readin = 0; | |||
1349 | ||||
1350 | /* No private part is necessary for include psymtabs. This property | |||
1351 | can be used to differentiate between such include psymtabs and | |||
1352 | the regular ones. */ | |||
1353 | subpst->read_symtab_private = NULL((void*)0); | |||
1354 | } | |||
1355 | ||||
1356 | /* Read the Line Number Program data and extract the list of files | |||
1357 | included by the source file represented by PST. Build an include | |||
1358 | partial symtab for each of these included files. | |||
1359 | ||||
1360 | This procedure assumes that there *is* a Line Number Program in | |||
1361 | the given CU. Callers should check that PDI->HAS_STMT_LIST is set | |||
1362 | before calling this procedure. */ | |||
1363 | ||||
1364 | static void | |||
1365 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, | |||
1366 | struct partial_die_info *pdi, | |||
1367 | struct partial_symtab *pst) | |||
1368 | { | |||
1369 | struct objfile *objfile = cu->objfile; | |||
1370 | bfd *abfd = objfile->obfd; | |||
1371 | struct line_header *lh; | |||
1372 | ||||
1373 | lh = dwarf_decode_line_header (pdi->line_offset, abfd, cu); | |||
1374 | if (lh == NULL((void*)0)) | |||
1375 | return; /* No linetable, so no includes. */ | |||
1376 | ||||
1377 | dwarf_decode_lines (lh, NULL((void*)0), abfd, cu, pst); | |||
1378 | ||||
1379 | free_line_header (lh); | |||
1380 | } | |||
1381 | ||||
1382 | ||||
1383 | /* Build the partial symbol table by doing a quick pass through the | |||
1384 | .debug_info and .debug_abbrev sections. */ | |||
1385 | ||||
1386 | static void | |||
1387 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) | |||
1388 | { | |||
1389 | /* Instead of reading this into a big buffer, we should probably use | |||
1390 | mmap() on architectures that support it. (FIXME) */ | |||
1391 | bfd *abfd = objfile->obfd; | |||
1392 | char *info_ptr; | |||
1393 | char *beg_of_comp_unit; | |||
1394 | struct partial_die_info comp_unit_die; | |||
1395 | struct partial_symtab *pst; | |||
1396 | struct cleanup *back_to; | |||
1397 | CORE_ADDR lowpc, highpc, baseaddr; | |||
1398 | ||||
1399 | info_ptr = dwarf2_per_objfile->info_buffer; | |||
1400 | ||||
1401 | /* Any cached compilation units will be linked by the per-objfile | |||
1402 | read_in_chain. Make sure to free them when we're done. */ | |||
1403 | back_to = make_cleanup (free_cached_comp_units, NULL((void*)0)); | |||
1404 | ||||
1405 | create_all_comp_units (objfile); | |||
1406 | ||||
1407 | /* Since the objects we're extracting from .debug_info vary in | |||
1408 | length, only the individual functions to extract them (like | |||
1409 | read_comp_unit_head and load_partial_die) can really know whether | |||
1410 | the buffer is large enough to hold another complete object. | |||
1411 | ||||
1412 | At the moment, they don't actually check that. If .debug_info | |||
1413 | holds just one extra byte after the last compilation unit's dies, | |||
1414 | then read_comp_unit_head will happily read off the end of the | |||
1415 | buffer. read_partial_die is similarly casual. Those functions | |||
1416 | should be fixed. | |||
1417 | ||||
1418 | For this loop condition, simply checking whether there's any data | |||
1419 | left at all should be sufficient. */ | |||
1420 | while (info_ptr < (dwarf2_per_objfile->info_buffer | |||
1421 | + dwarf2_per_objfile->info_size)) | |||
1422 | { | |||
1423 | struct cleanup *back_to_inner; | |||
1424 | struct dwarf2_cu cu; | |||
1425 | struct abbrev_info *abbrev; | |||
1426 | unsigned int bytes_read; | |||
1427 | struct dwarf2_per_cu_data *this_cu; | |||
1428 | ||||
1429 | beg_of_comp_unit = info_ptr; | |||
1430 | ||||
1431 | memset (&cu, 0, sizeof (cu)); | |||
1432 | ||||
1433 | obstack_init (&cu.comp_unit_obstack)_obstack_begin ((&cu.comp_unit_obstack), 0, 0, (void *(*) (long)) xmalloc, (void (*) (void *)) xfree); | |||
1434 | ||||
1435 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); | |||
1436 | ||||
1437 | cu.objfile = objfile; | |||
1438 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, abfd); | |||
1439 | ||||
1440 | /* Complete the cu_header */ | |||
1441 | cu.header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |||
1442 | cu.header.first_die_ptr = info_ptr; | |||
1443 | cu.header.cu_head_ptr = beg_of_comp_unit; | |||
1444 | ||||
1445 | cu.list_in_scope = &file_symbols; | |||
1446 | ||||
1447 | /* Read the abbrevs for this compilation unit into a table */ | |||
1448 | dwarf2_read_abbrevs (abfd, &cu); | |||
1449 | make_cleanup (dwarf2_free_abbrev_table, &cu); | |||
1450 | ||||
1451 | this_cu = dwarf2_find_comp_unit (cu.header.offset, objfile); | |||
1452 | ||||
1453 | /* Read the compilation unit die */ | |||
1454 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, &cu); | |||
1455 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |||
1456 | abfd, info_ptr, &cu); | |||
1457 | ||||
1458 | /* Set the language we're debugging */ | |||
1459 | set_cu_language (comp_unit_die.language, &cu); | |||
1460 | ||||
1461 | /* Allocate a new partial symbol table structure */ | |||
1462 | pst = start_psymtab_common (objfile, objfile->section_offsets, | |||
1463 | comp_unit_die.name ? comp_unit_die.name : "", | |||
1464 | comp_unit_die.lowpc, | |||
1465 | objfile->global_psymbols.next, | |||
1466 | objfile->static_psymbols.next); | |||
1467 | ||||
1468 | if (comp_unit_die.dirname) | |||
1469 | pst->dirname = xstrdup (comp_unit_die.dirname); | |||
1470 | ||||
1471 | pst->read_symtab_private = (char *) this_cu; | |||
1472 | ||||
1473 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1473, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1473, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1473, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
1474 | ||||
1475 | /* Store the function that reads in the rest of the symbol table */ | |||
1476 | pst->read_symtab = dwarf2_psymtab_to_symtab; | |||
1477 | ||||
1478 | /* If this compilation unit was already read in, free the | |||
1479 | cached copy in order to read it in again. This is | |||
1480 | necessary because we skipped some symbols when we first | |||
1481 | read in the compilation unit (see load_partial_dies). | |||
1482 | This problem could be avoided, but the benefit is | |||
1483 | unclear. */ | |||
1484 | if (this_cu->cu != NULL((void*)0)) | |||
1485 | free_one_cached_comp_unit (this_cu->cu); | |||
1486 | ||||
1487 | cu.per_cu = this_cu; | |||
1488 | ||||
1489 | /* Note that this is a pointer to our stack frame, being | |||
1490 | added to a global data structure. It will be cleaned up | |||
1491 | in free_stack_comp_unit when we finish with this | |||
1492 | compilation unit. */ | |||
1493 | this_cu->cu = &cu; | |||
1494 | ||||
1495 | this_cu->psymtab = pst; | |||
1496 | ||||
1497 | /* Check if comp unit has_children. | |||
1498 | If so, read the rest of the partial symbols from this comp unit. | |||
1499 | If not, there's no more debug_info for this comp unit. */ | |||
1500 | if (comp_unit_die.has_children) | |||
1501 | { | |||
1502 | struct partial_die_info *first_die; | |||
1503 | ||||
1504 | lowpc = ((CORE_ADDR) -1); | |||
1505 | highpc = ((CORE_ADDR) 0); | |||
1506 | ||||
1507 | first_die = load_partial_dies (abfd, info_ptr, 1, &cu); | |||
1508 | ||||
1509 | scan_partial_symbols (first_die, &lowpc, &highpc, &cu); | |||
1510 | ||||
1511 | /* If we didn't find a lowpc, set it to highpc to avoid | |||
1512 | complaints from `maint check'. */ | |||
1513 | if (lowpc == ((CORE_ADDR) -1)) | |||
1514 | lowpc = highpc; | |||
1515 | ||||
1516 | /* If the compilation unit didn't have an explicit address range, | |||
1517 | then use the information extracted from its child dies. */ | |||
1518 | if (! comp_unit_die.has_pc_info) | |||
1519 | { | |||
1520 | comp_unit_die.lowpc = lowpc; | |||
1521 | comp_unit_die.highpc = highpc; | |||
1522 | } | |||
1523 | } | |||
1524 | pst->textlow = comp_unit_die.lowpc + baseaddr; | |||
1525 | pst->texthigh = comp_unit_die.highpc + baseaddr; | |||
1526 | ||||
1527 | pst->n_global_syms = objfile->global_psymbols.next - | |||
1528 | (objfile->global_psymbols.list + pst->globals_offset); | |||
1529 | pst->n_static_syms = objfile->static_psymbols.next - | |||
1530 | (objfile->static_psymbols.list + pst->statics_offset); | |||
1531 | sort_pst_symbols (pst); | |||
1532 | ||||
1533 | /* If there is already a psymtab or symtab for a file of this | |||
1534 | name, remove it. (If there is a symtab, more drastic things | |||
1535 | also happen.) This happens in VxWorks. */ | |||
1536 | free_named_symtabs (pst->filename); | |||
1537 | ||||
1538 | info_ptr = beg_of_comp_unit + cu.header.length | |||
1539 | + cu.header.initial_length_size; | |||
1540 | ||||
1541 | if (comp_unit_die.has_stmt_list) | |||
1542 | { | |||
1543 | /* Get the list of files included in the current compilation unit, | |||
1544 | and build a psymtab for each of them. */ | |||
1545 | dwarf2_build_include_psymtabs (&cu, &comp_unit_die, pst); | |||
1546 | } | |||
1547 | ||||
1548 | do_cleanups (back_to_inner); | |||
1549 | } | |||
1550 | do_cleanups (back_to); | |||
1551 | } | |||
1552 | ||||
1553 | /* Load the DIEs for a secondary CU into memory. */ | |||
1554 | ||||
1555 | static void | |||
1556 | load_comp_unit (struct dwarf2_per_cu_data *this_cu, struct objfile *objfile) | |||
1557 | { | |||
1558 | bfd *abfd = objfile->obfd; | |||
1559 | char *info_ptr, *beg_of_comp_unit; | |||
1560 | struct partial_die_info comp_unit_die; | |||
1561 | struct dwarf2_cu *cu; | |||
1562 | struct abbrev_info *abbrev; | |||
1563 | unsigned int bytes_read; | |||
1564 | struct cleanup *back_to; | |||
1565 | ||||
1566 | info_ptr = dwarf2_per_objfile->info_buffer + this_cu->offset; | |||
1567 | beg_of_comp_unit = info_ptr; | |||
1568 | ||||
1569 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |||
1570 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |||
1571 | ||||
1572 | obstack_init (&cu->comp_unit_obstack)_obstack_begin ((&cu->comp_unit_obstack), 0, 0, (void * (*) (long)) xmalloc, (void (*) (void *)) xfree); | |||
1573 | ||||
1574 | cu->objfile = objfile; | |||
1575 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, abfd); | |||
1576 | ||||
1577 | /* Complete the cu_header. */ | |||
1578 | cu->header.offset = beg_of_comp_unit - dwarf2_per_objfile->info_buffer; | |||
1579 | cu->header.first_die_ptr = info_ptr; | |||
1580 | cu->header.cu_head_ptr = beg_of_comp_unit; | |||
1581 | ||||
1582 | /* Read the abbrevs for this compilation unit into a table. */ | |||
1583 | dwarf2_read_abbrevs (abfd, cu); | |||
1584 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |||
1585 | ||||
1586 | /* Read the compilation unit die. */ | |||
1587 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |||
1588 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, | |||
1589 | abfd, info_ptr, cu); | |||
1590 | ||||
1591 | /* Set the language we're debugging. */ | |||
1592 | set_cu_language (comp_unit_die.language, cu); | |||
1593 | ||||
1594 | /* Link this compilation unit into the compilation unit tree. */ | |||
1595 | this_cu->cu = cu; | |||
1596 | cu->per_cu = this_cu; | |||
1597 | ||||
1598 | /* Check if comp unit has_children. | |||
1599 | If so, read the rest of the partial symbols from this comp unit. | |||
1600 | If not, there's no more debug_info for this comp unit. */ | |||
1601 | if (comp_unit_die.has_children) | |||
1602 | load_partial_dies (abfd, info_ptr, 0, cu); | |||
1603 | ||||
1604 | do_cleanups (back_to); | |||
1605 | } | |||
1606 | ||||
1607 | /* Create a list of all compilation units in OBJFILE. We do this only | |||
1608 | if an inter-comp-unit reference is found; presumably if there is one, | |||
1609 | there will be many, and one will occur early in the .debug_info section. | |||
1610 | So there's no point in building this list incrementally. */ | |||
1611 | ||||
1612 | static void | |||
1613 | create_all_comp_units (struct objfile *objfile) | |||
1614 | { | |||
1615 | int n_allocated; | |||
1616 | int n_comp_units; | |||
1617 | struct dwarf2_per_cu_data **all_comp_units; | |||
1618 | char *info_ptr = dwarf2_per_objfile->info_buffer; | |||
1619 | ||||
1620 | n_comp_units = 0; | |||
1621 | n_allocated = 10; | |||
1622 | all_comp_units = xmalloc (n_allocated | |||
1623 | * sizeof (struct dwarf2_per_cu_data *)); | |||
1624 | ||||
1625 | while (info_ptr < dwarf2_per_objfile->info_buffer + dwarf2_per_objfile->info_size) | |||
1626 | { | |||
1627 | struct comp_unit_head cu_header; | |||
1628 | char *beg_of_comp_unit; | |||
1629 | struct dwarf2_per_cu_data *this_cu; | |||
1630 | unsigned long offset; | |||
1631 | int bytes_read; | |||
1632 | ||||
1633 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |||
1634 | ||||
1635 | /* Read just enough information to find out where the next | |||
1636 | compilation unit is. */ | |||
1637 | cu_header.initial_length_size = 0; | |||
1638 | cu_header.length = read_initial_length (objfile->obfd, info_ptr, | |||
1639 | &cu_header, &bytes_read); | |||
1640 | ||||
1641 | /* Save the compilation unit for later lookup. */ | |||
1642 | this_cu = obstack_alloc (&objfile->objfile_obstack,__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct dwarf2_per_cu_data))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len ); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
1643 | sizeof (struct dwarf2_per_cu_data))__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct dwarf2_per_cu_data))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len ); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }); | |||
1644 | memset (this_cu, 0, sizeof (*this_cu)); | |||
1645 | this_cu->offset = offset; | |||
1646 | this_cu->length = cu_header.length + cu_header.initial_length_size; | |||
1647 | ||||
1648 | if (n_comp_units == n_allocated) | |||
1649 | { | |||
1650 | n_allocated *= 2; | |||
1651 | all_comp_units = xrealloc (all_comp_units, | |||
1652 | n_allocated | |||
1653 | * sizeof (struct dwarf2_per_cu_data *)); | |||
1654 | } | |||
1655 | all_comp_units[n_comp_units++] = this_cu; | |||
1656 | ||||
1657 | info_ptr = info_ptr + this_cu->length; | |||
1658 | } | |||
1659 | ||||
1660 | dwarf2_per_objfile->all_comp_units | |||
1661 | = obstack_alloc (&objfile->objfile_obstack,__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (n_comp_units * sizeof (struct dwarf2_per_cu_data *))); if (__o ->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) | |||
1662 | n_comp_units * sizeof (struct dwarf2_per_cu_data *))__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (n_comp_units * sizeof (struct dwarf2_per_cu_data *))); if (__o ->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }); | |||
1663 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, | |||
1664 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); | |||
1665 | xfree (all_comp_units); | |||
1666 | dwarf2_per_objfile->n_comp_units = n_comp_units; | |||
1667 | } | |||
1668 | ||||
1669 | /* Process all loaded DIEs for compilation unit CU, starting at FIRST_DIE. | |||
1670 | Also set *LOWPC and *HIGHPC to the lowest and highest PC values found | |||
1671 | in CU. */ | |||
1672 | ||||
1673 | static void | |||
1674 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, | |||
1675 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |||
1676 | { | |||
1677 | struct objfile *objfile = cu->objfile; | |||
1678 | bfd *abfd = objfile->obfd; | |||
1679 | struct partial_die_info *pdi; | |||
1680 | ||||
1681 | /* Now, march along the PDI's, descending into ones which have | |||
1682 | interesting children but skipping the children of the other ones, | |||
1683 | until we reach the end of the compilation unit. */ | |||
1684 | ||||
1685 | pdi = first_die; | |||
1686 | ||||
1687 | while (pdi != NULL((void*)0)) | |||
1688 | { | |||
1689 | fixup_partial_die (pdi, cu); | |||
1690 | ||||
1691 | /* Anonymous namespaces have no name but have interesting | |||
1692 | children, so we need to look at them. Ditto for anonymous | |||
1693 | enums. */ | |||
1694 | ||||
1695 | if (pdi->name != NULL((void*)0) || pdi->tag == DW_TAG_namespace | |||
1696 | || pdi->tag == DW_TAG_enumeration_type) | |||
1697 | { | |||
1698 | switch (pdi->tag) | |||
1699 | { | |||
1700 | case DW_TAG_subprogram: | |||
1701 | if (pdi->has_pc_info) | |||
1702 | { | |||
1703 | if (pdi->lowpc < *lowpc) | |||
1704 | { | |||
1705 | *lowpc = pdi->lowpc; | |||
1706 | } | |||
1707 | if (pdi->highpc > *highpc) | |||
1708 | { | |||
1709 | *highpc = pdi->highpc; | |||
1710 | } | |||
1711 | if (!pdi->is_declaration) | |||
1712 | { | |||
1713 | add_partial_symbol (pdi, cu); | |||
1714 | } | |||
1715 | } | |||
1716 | break; | |||
1717 | case DW_TAG_variable: | |||
1718 | case DW_TAG_typedef: | |||
1719 | case DW_TAG_union_type: | |||
1720 | if (!pdi->is_declaration) | |||
1721 | { | |||
1722 | add_partial_symbol (pdi, cu); | |||
1723 | } | |||
1724 | break; | |||
1725 | case DW_TAG_class_type: | |||
1726 | case DW_TAG_structure_type: | |||
1727 | if (!pdi->is_declaration) | |||
1728 | { | |||
1729 | add_partial_symbol (pdi, cu); | |||
1730 | } | |||
1731 | break; | |||
1732 | case DW_TAG_enumeration_type: | |||
1733 | if (!pdi->is_declaration) | |||
1734 | add_partial_enumeration (pdi, cu); | |||
1735 | break; | |||
1736 | case DW_TAG_base_type: | |||
1737 | case DW_TAG_subrange_type: | |||
1738 | /* File scope base type definitions are added to the partial | |||
1739 | symbol table. */ | |||
1740 | add_partial_symbol (pdi, cu); | |||
1741 | break; | |||
1742 | case DW_TAG_namespace: | |||
1743 | add_partial_namespace (pdi, lowpc, highpc, cu); | |||
1744 | break; | |||
1745 | default: | |||
1746 | break; | |||
1747 | } | |||
1748 | } | |||
1749 | ||||
1750 | /* If the die has a sibling, skip to the sibling. */ | |||
1751 | ||||
1752 | pdi = pdi->die_sibling; | |||
1753 | } | |||
1754 | } | |||
1755 | ||||
1756 | /* Functions used to compute the fully scoped name of a partial DIE. | |||
1757 | ||||
1758 | Normally, this is simple. For C++, the parent DIE's fully scoped | |||
1759 | name is concatenated with "::" and the partial DIE's name. For | |||
1760 | Java, the same thing occurs except that "." is used instead of "::". | |||
1761 | Enumerators are an exception; they use the scope of their parent | |||
1762 | enumeration type, i.e. the name of the enumeration type is not | |||
1763 | prepended to the enumerator. | |||
1764 | ||||
1765 | There are two complexities. One is DW_AT_specification; in this | |||
1766 | case "parent" means the parent of the target of the specification, | |||
1767 | instead of the direct parent of the DIE. The other is compilers | |||
1768 | which do not emit DW_TAG_namespace; in this case we try to guess | |||
1769 | the fully qualified name of structure types from their members' | |||
1770 | linkage names. This must be done using the DIE's children rather | |||
1771 | than the children of any DW_AT_specification target. We only need | |||
1772 | to do this for structures at the top level, i.e. if the target of | |||
1773 | any DW_AT_specification (if any; otherwise the DIE itself) does not | |||
1774 | have a parent. */ | |||
1775 | ||||
1776 | /* Compute the scope prefix associated with PDI's parent, in | |||
1777 | compilation unit CU. The result will be allocated on CU's | |||
1778 | comp_unit_obstack, or a copy of the already allocated PDI->NAME | |||
1779 | field. NULL is returned if no prefix is necessary. */ | |||
1780 | static char * | |||
1781 | partial_die_parent_scope (struct partial_die_info *pdi, | |||
1782 | struct dwarf2_cu *cu) | |||
1783 | { | |||
1784 | char *grandparent_scope; | |||
1785 | struct partial_die_info *parent, *real_pdi; | |||
1786 | ||||
1787 | /* We need to look at our parent DIE; if we have a DW_AT_specification, | |||
1788 | then this means the parent of the specification DIE. */ | |||
1789 | ||||
1790 | real_pdi = pdi; | |||
1791 | while (real_pdi->has_specification) | |||
1792 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |||
1793 | ||||
1794 | parent = real_pdi->die_parent; | |||
1795 | if (parent == NULL((void*)0)) | |||
1796 | return NULL((void*)0); | |||
1797 | ||||
1798 | if (parent->scope_set) | |||
1799 | return parent->scope; | |||
1800 | ||||
1801 | fixup_partial_die (parent, cu); | |||
1802 | ||||
1803 | grandparent_scope = partial_die_parent_scope (parent, cu); | |||
1804 | ||||
1805 | if (parent->tag == DW_TAG_namespace | |||
1806 | || parent->tag == DW_TAG_structure_type | |||
1807 | || parent->tag == DW_TAG_class_type | |||
1808 | || parent->tag == DW_TAG_union_type) | |||
1809 | { | |||
1810 | if (grandparent_scope == NULL((void*)0)) | |||
1811 | parent->scope = parent->name; | |||
1812 | else | |||
1813 | parent->scope = typename_concat (&cu->comp_unit_obstack, grandparent_scope, | |||
1814 | parent->name, cu); | |||
1815 | } | |||
1816 | else if (parent->tag == DW_TAG_enumeration_type) | |||
1817 | /* Enumerators should not get the name of the enumeration as a prefix. */ | |||
1818 | parent->scope = grandparent_scope; | |||
1819 | else | |||
1820 | { | |||
1821 | /* FIXME drow/2004-04-01: What should we be doing with | |||
1822 | function-local names? For partial symbols, we should probably be | |||
1823 | ignoring them. */ | |||
1824 | complaint (&symfile_complaints, | |||
1825 | "unhandled containing DIE tag %d for DIE at %d", | |||
1826 | parent->tag, pdi->offset); | |||
1827 | parent->scope = grandparent_scope; | |||
1828 | } | |||
1829 | ||||
1830 | parent->scope_set = 1; | |||
1831 | return parent->scope; | |||
1832 | } | |||
1833 | ||||
1834 | /* Return the fully scoped name associated with PDI, from compilation unit | |||
1835 | CU. The result will be allocated with malloc. */ | |||
1836 | static char * | |||
1837 | partial_die_full_name (struct partial_die_info *pdi, | |||
1838 | struct dwarf2_cu *cu) | |||
1839 | { | |||
1840 | char *parent_scope; | |||
1841 | ||||
1842 | parent_scope = partial_die_parent_scope (pdi, cu); | |||
1843 | if (parent_scope == NULL((void*)0)) | |||
1844 | return NULL((void*)0); | |||
1845 | else | |||
1846 | return typename_concat (NULL((void*)0), parent_scope, pdi->name, cu); | |||
1847 | } | |||
1848 | ||||
1849 | static void | |||
1850 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) | |||
1851 | { | |||
1852 | struct objfile *objfile = cu->objfile; | |||
1853 | CORE_ADDR addr = 0; | |||
1854 | char *actual_name; | |||
1855 | const char *my_prefix; | |||
1856 | const struct partial_symbol *psym = NULL((void*)0); | |||
1857 | CORE_ADDR baseaddr; | |||
1858 | int built_actual_name = 0; | |||
1859 | ||||
1860 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1860, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1860, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 1860, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
1861 | ||||
1862 | actual_name = NULL((void*)0); | |||
1863 | ||||
1864 | if (pdi_needs_namespace (pdi->tag)) | |||
1865 | { | |||
1866 | actual_name = partial_die_full_name (pdi, cu); | |||
1867 | if (actual_name) | |||
1868 | built_actual_name = 1; | |||
1869 | } | |||
1870 | ||||
1871 | if (actual_name == NULL((void*)0)) | |||
1872 | actual_name = pdi->name; | |||
1873 | ||||
1874 | switch (pdi->tag) | |||
1875 | { | |||
1876 | case DW_TAG_subprogram: | |||
1877 | if (pdi->is_external) | |||
1878 | { | |||
1879 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, | |||
1880 | mst_text, objfile); */ | |||
1881 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1882 | VAR_DOMAIN, LOC_BLOCK, | |||
1883 | &objfile->global_psymbols, | |||
1884 | 0, pdi->lowpc + baseaddr, | |||
1885 | cu->language, objfile); | |||
1886 | } | |||
1887 | else | |||
1888 | { | |||
1889 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, | |||
1890 | mst_file_text, objfile); */ | |||
1891 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1892 | VAR_DOMAIN, LOC_BLOCK, | |||
1893 | &objfile->static_psymbols, | |||
1894 | 0, pdi->lowpc + baseaddr, | |||
1895 | cu->language, objfile); | |||
1896 | } | |||
1897 | break; | |||
1898 | case DW_TAG_variable: | |||
1899 | if (pdi->is_external) | |||
1900 | { | |||
1901 | /* Global Variable. | |||
1902 | Don't enter into the minimal symbol tables as there is | |||
1903 | a minimal symbol table entry from the ELF symbols already. | |||
1904 | Enter into partial symbol table if it has a location | |||
1905 | descriptor or a type. | |||
1906 | If the location descriptor is missing, new_symbol will create | |||
1907 | a LOC_UNRESOLVED symbol, the address of the variable will then | |||
1908 | be determined from the minimal symbol table whenever the variable | |||
1909 | is referenced. | |||
1910 | The address for the partial symbol table entry is not | |||
1911 | used by GDB, but it comes in handy for debugging partial symbol | |||
1912 | table building. */ | |||
1913 | ||||
1914 | if (pdi->locdesc) | |||
1915 | addr = decode_locdesc (pdi->locdesc, cu); | |||
1916 | if (pdi->locdesc || pdi->has_type) | |||
1917 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1918 | VAR_DOMAIN, LOC_STATIC, | |||
1919 | &objfile->global_psymbols, | |||
1920 | 0, addr + baseaddr, | |||
1921 | cu->language, objfile); | |||
1922 | } | |||
1923 | else | |||
1924 | { | |||
1925 | /* Static Variable. Skip symbols without location descriptors. */ | |||
1926 | if (pdi->locdesc == NULL((void*)0)) | |||
1927 | return; | |||
1928 | addr = decode_locdesc (pdi->locdesc, cu); | |||
1929 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, | |||
1930 | mst_file_data, objfile); */ | |||
1931 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1932 | VAR_DOMAIN, LOC_STATIC, | |||
1933 | &objfile->static_psymbols, | |||
1934 | 0, addr + baseaddr, | |||
1935 | cu->language, objfile); | |||
1936 | } | |||
1937 | break; | |||
1938 | case DW_TAG_typedef: | |||
1939 | case DW_TAG_base_type: | |||
1940 | case DW_TAG_subrange_type: | |||
1941 | add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1942 | VAR_DOMAIN, LOC_TYPEDEF, | |||
1943 | &objfile->static_psymbols, | |||
1944 | 0, (CORE_ADDR) 0, cu->language, objfile); | |||
1945 | break; | |||
1946 | case DW_TAG_namespace: | |||
1947 | add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1948 | VAR_DOMAIN, LOC_TYPEDEF, | |||
1949 | &objfile->global_psymbols, | |||
1950 | 0, (CORE_ADDR) 0, cu->language, objfile); | |||
1951 | break; | |||
1952 | case DW_TAG_class_type: | |||
1953 | case DW_TAG_structure_type: | |||
1954 | case DW_TAG_union_type: | |||
1955 | case DW_TAG_enumeration_type: | |||
1956 | /* Skip aggregate types without children, these are external | |||
1957 | references. */ | |||
1958 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about | |||
1959 | static vs. global. */ | |||
1960 | if (pdi->has_children == 0) | |||
1961 | return; | |||
1962 | add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1963 | STRUCT_DOMAIN, LOC_TYPEDEF, | |||
1964 | (cu->language == language_cplus | |||
1965 | || cu->language == language_java) | |||
1966 | ? &objfile->global_psymbols | |||
1967 | : &objfile->static_psymbols, | |||
1968 | 0, (CORE_ADDR) 0, cu->language, objfile); | |||
1969 | ||||
1970 | if (cu->language == language_cplus | |||
1971 | || cu->language == language_java) | |||
1972 | { | |||
1973 | /* For C++ and Java, these implicitly act as typedefs as well. */ | |||
1974 | add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1975 | VAR_DOMAIN, LOC_TYPEDEF, | |||
1976 | &objfile->global_psymbols, | |||
1977 | 0, (CORE_ADDR) 0, cu->language, objfile); | |||
1978 | } | |||
1979 | break; | |||
1980 | case DW_TAG_enumerator: | |||
1981 | add_psymbol_to_list (actual_name, strlen (actual_name), | |||
1982 | VAR_DOMAIN, LOC_CONST, | |||
1983 | (cu->language == language_cplus | |||
1984 | || cu->language == language_java) | |||
1985 | ? &objfile->global_psymbols | |||
1986 | : &objfile->static_psymbols, | |||
1987 | 0, (CORE_ADDR) 0, cu->language, objfile); | |||
1988 | break; | |||
1989 | default: | |||
1990 | break; | |||
1991 | } | |||
1992 | ||||
1993 | /* Check to see if we should scan the name for possible namespace | |||
1994 | info. Only do this if this is C++, if we don't have namespace | |||
1995 | debugging info in the file, if the psym is of an appropriate type | |||
1996 | (otherwise we'll have psym == NULL), and if we actually had a | |||
1997 | mangled name to begin with. */ | |||
1998 | ||||
1999 | /* FIXME drow/2004-02-22: Why don't we do this for classes, i.e. the | |||
2000 | cases which do not set PSYM above? */ | |||
2001 | ||||
2002 | if (cu->language == language_cplus | |||
2003 | && cu->has_namespace_info == 0 | |||
2004 | && psym != NULL((void*)0) | |||
2005 | && SYMBOL_CPLUS_DEMANGLED_NAME (psym)(psym)->ginfo.language_specific.cplus_specific.demangled_name != NULL((void*)0)) | |||
2006 | cp_check_possible_namespace_symbols (SYMBOL_CPLUS_DEMANGLED_NAME (psym)(psym)->ginfo.language_specific.cplus_specific.demangled_name, | |||
2007 | objfile); | |||
2008 | ||||
2009 | if (built_actual_name) | |||
2010 | xfree (actual_name); | |||
2011 | } | |||
2012 | ||||
2013 | /* Determine whether a die of type TAG living in a C++ class or | |||
2014 | namespace needs to have the name of the scope prepended to the | |||
2015 | name listed in the die. */ | |||
2016 | ||||
2017 | static int | |||
2018 | pdi_needs_namespace (enum dwarf_tag tag) | |||
2019 | { | |||
2020 | switch (tag) | |||
2021 | { | |||
2022 | case DW_TAG_namespace: | |||
2023 | case DW_TAG_typedef: | |||
2024 | case DW_TAG_class_type: | |||
2025 | case DW_TAG_structure_type: | |||
2026 | case DW_TAG_union_type: | |||
2027 | case DW_TAG_enumeration_type: | |||
2028 | case DW_TAG_enumerator: | |||
2029 | return 1; | |||
2030 | default: | |||
2031 | return 0; | |||
2032 | } | |||
2033 | } | |||
2034 | ||||
2035 | /* Read a partial die corresponding to a namespace; also, add a symbol | |||
2036 | corresponding to that namespace to the symbol table. NAMESPACE is | |||
2037 | the name of the enclosing namespace. */ | |||
2038 | ||||
2039 | static void | |||
2040 | add_partial_namespace (struct partial_die_info *pdi, | |||
2041 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |||
2042 | struct dwarf2_cu *cu) | |||
2043 | { | |||
2044 | struct objfile *objfile = cu->objfile; | |||
2045 | ||||
2046 | /* Add a symbol for the namespace. */ | |||
2047 | ||||
2048 | add_partial_symbol (pdi, cu); | |||
2049 | ||||
2050 | /* Now scan partial symbols in that namespace. */ | |||
2051 | ||||
2052 | if (pdi->has_children) | |||
2053 | scan_partial_symbols (pdi->die_child, lowpc, highpc, cu); | |||
2054 | } | |||
2055 | ||||
2056 | /* See if we can figure out if the class lives in a namespace. We do | |||
2057 | this by looking for a member function; its demangled name will | |||
2058 | contain namespace info, if there is any. */ | |||
2059 | ||||
2060 | static void | |||
2061 | guess_structure_name (struct partial_die_info *struct_pdi, | |||
2062 | struct dwarf2_cu *cu) | |||
2063 | { | |||
2064 | if ((cu->language == language_cplus | |||
2065 | || cu->language == language_java) | |||
2066 | && cu->has_namespace_info == 0 | |||
2067 | && struct_pdi->has_children) | |||
2068 | { | |||
2069 | /* NOTE: carlton/2003-10-07: Getting the info this way changes | |||
2070 | what template types look like, because the demangler | |||
2071 | frequently doesn't give the same name as the debug info. We | |||
2072 | could fix this by only using the demangled name to get the | |||
2073 | prefix (but see comment in read_structure_type). */ | |||
2074 | ||||
2075 | struct partial_die_info *child_pdi = struct_pdi->die_child; | |||
2076 | struct partial_die_info *real_pdi; | |||
2077 | ||||
2078 | /* If this DIE (this DIE's specification, if any) has a parent, then | |||
2079 | we should not do this. We'll prepend the parent's fully qualified | |||
2080 | name when we create the partial symbol. */ | |||
2081 | ||||
2082 | real_pdi = struct_pdi; | |||
2083 | while (real_pdi->has_specification) | |||
2084 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); | |||
2085 | ||||
2086 | if (real_pdi->die_parent != NULL((void*)0)) | |||
2087 | return; | |||
2088 | ||||
2089 | while (child_pdi != NULL((void*)0)) | |||
2090 | { | |||
2091 | if (child_pdi->tag == DW_TAG_subprogram) | |||
2092 | { | |||
2093 | char *actual_class_name | |||
2094 | = language_class_name_from_physname (cu->language_defn, | |||
2095 | child_pdi->name); | |||
2096 | if (actual_class_name != NULL((void*)0)) | |||
2097 | { | |||
2098 | struct_pdi->name | |||
2099 | = obsavestring (actual_class_name, | |||
2100 | strlen (actual_class_name), | |||
2101 | &cu->comp_unit_obstack); | |||
2102 | xfree (actual_class_name); | |||
2103 | } | |||
2104 | break; | |||
2105 | } | |||
2106 | ||||
2107 | child_pdi = child_pdi->die_sibling; | |||
2108 | } | |||
2109 | } | |||
2110 | } | |||
2111 | ||||
2112 | /* Read a partial die corresponding to an enumeration type. */ | |||
2113 | ||||
2114 | static void | |||
2115 | add_partial_enumeration (struct partial_die_info *enum_pdi, | |||
2116 | struct dwarf2_cu *cu) | |||
2117 | { | |||
2118 | struct objfile *objfile = cu->objfile; | |||
2119 | bfd *abfd = objfile->obfd; | |||
2120 | struct partial_die_info *pdi; | |||
2121 | ||||
2122 | if (enum_pdi->name != NULL((void*)0)) | |||
2123 | add_partial_symbol (enum_pdi, cu); | |||
2124 | ||||
2125 | pdi = enum_pdi->die_child; | |||
2126 | while (pdi) | |||
2127 | { | |||
2128 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL((void*)0)) | |||
2129 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); | |||
2130 | else | |||
2131 | add_partial_symbol (pdi, cu); | |||
2132 | pdi = pdi->die_sibling; | |||
2133 | } | |||
2134 | } | |||
2135 | ||||
2136 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. | |||
2137 | Return the corresponding abbrev, or NULL if the number is zero (indicating | |||
2138 | an empty DIE). In either case *BYTES_READ will be set to the length of | |||
2139 | the initial number. */ | |||
2140 | ||||
2141 | static struct abbrev_info * | |||
2142 | peek_die_abbrev (char *info_ptr, int *bytes_read, struct dwarf2_cu *cu) | |||
2143 | { | |||
2144 | bfd *abfd = cu->objfile->obfd; | |||
2145 | unsigned int abbrev_number; | |||
2146 | struct abbrev_info *abbrev; | |||
2147 | ||||
2148 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); | |||
2149 | ||||
2150 | if (abbrev_number == 0) | |||
2151 | return NULL((void*)0); | |||
2152 | ||||
2153 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |||
2154 | if (!abbrev) | |||
2155 | { | |||
2156 | error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, | |||
2157 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
2158 | } | |||
2159 | ||||
2160 | return abbrev; | |||
2161 | } | |||
2162 | ||||
2163 | /* Scan the debug information for CU starting at INFO_PTR. Returns a | |||
2164 | pointer to the end of a series of DIEs, terminated by an empty | |||
2165 | DIE. Any children of the skipped DIEs will also be skipped. */ | |||
2166 | ||||
2167 | static char * | |||
2168 | skip_children (char *info_ptr, struct dwarf2_cu *cu) | |||
2169 | { | |||
2170 | struct abbrev_info *abbrev; | |||
2171 | unsigned int bytes_read; | |||
2172 | ||||
2173 | while (1) | |||
2174 | { | |||
2175 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |||
2176 | if (abbrev == NULL((void*)0)) | |||
2177 | return info_ptr + bytes_read; | |||
2178 | else | |||
2179 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |||
2180 | } | |||
2181 | } | |||
2182 | ||||
2183 | /* Scan the debug information for CU starting at INFO_PTR. INFO_PTR | |||
2184 | should point just after the initial uleb128 of a DIE, and the | |||
2185 | abbrev corresponding to that skipped uleb128 should be passed in | |||
2186 | ABBREV. Returns a pointer to this DIE's sibling, skipping any | |||
2187 | children. */ | |||
2188 | ||||
2189 | static char * | |||
2190 | skip_one_die (char *info_ptr, struct abbrev_info *abbrev, | |||
2191 | struct dwarf2_cu *cu) | |||
2192 | { | |||
2193 | unsigned int bytes_read; | |||
2194 | struct attribute attr; | |||
2195 | bfd *abfd = cu->objfile->obfd; | |||
2196 | unsigned int form, i; | |||
2197 | ||||
2198 | for (i = 0; i < abbrev->num_attrs; i++) | |||
2199 | { | |||
2200 | /* The only abbrev we care about is DW_AT_sibling. */ | |||
2201 | if (abbrev->attrs[i].name == DW_AT_sibling) | |||
2202 | { | |||
2203 | read_attribute (&attr, &abbrev->attrs[i], | |||
2204 | abfd, info_ptr, cu); | |||
2205 | if (attr.form == DW_FORM_ref_addr) | |||
2206 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); | |||
2207 | else | |||
2208 | return dwarf2_per_objfile->info_buffer | |||
2209 | + dwarf2_get_ref_die_offset (&attr, cu); | |||
2210 | } | |||
2211 | ||||
2212 | /* If it isn't DW_AT_sibling, skip this attribute. */ | |||
2213 | form = abbrev->attrs[i].form; | |||
2214 | skip_attribute: | |||
2215 | switch (form) | |||
2216 | { | |||
2217 | case DW_FORM_addr: | |||
2218 | case DW_FORM_ref_addr: | |||
2219 | info_ptr += cu->header.addr_size; | |||
2220 | break; | |||
2221 | case DW_FORM_data1: | |||
2222 | case DW_FORM_ref1: | |||
2223 | case DW_FORM_flag: | |||
2224 | info_ptr += 1; | |||
2225 | break; | |||
2226 | case DW_FORM_data2: | |||
2227 | case DW_FORM_ref2: | |||
2228 | info_ptr += 2; | |||
2229 | break; | |||
2230 | case DW_FORM_data4: | |||
2231 | case DW_FORM_ref4: | |||
2232 | info_ptr += 4; | |||
2233 | break; | |||
2234 | case DW_FORM_data8: | |||
2235 | case DW_FORM_ref8: | |||
2236 | info_ptr += 8; | |||
2237 | break; | |||
2238 | case DW_FORM_string: | |||
2239 | read_string (abfd, info_ptr, &bytes_read); | |||
2240 | info_ptr += bytes_read; | |||
2241 | break; | |||
2242 | case DW_FORM_strp: | |||
2243 | info_ptr += cu->header.offset_size; | |||
2244 | break; | |||
2245 | case DW_FORM_block: | |||
2246 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
2247 | info_ptr += bytes_read; | |||
2248 | break; | |||
2249 | case DW_FORM_block1: | |||
2250 | info_ptr += 1 + read_1_byte (abfd, info_ptr); | |||
2251 | break; | |||
2252 | case DW_FORM_block2: | |||
2253 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); | |||
2254 | break; | |||
2255 | case DW_FORM_block4: | |||
2256 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); | |||
2257 | break; | |||
2258 | case DW_FORM_sdata: | |||
2259 | case DW_FORM_udata: | |||
2260 | case DW_FORM_ref_udata: | |||
2261 | info_ptr = skip_leb128 (abfd, info_ptr); | |||
2262 | break; | |||
2263 | case DW_FORM_indirect: | |||
2264 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
2265 | info_ptr += bytes_read; | |||
2266 | /* We need to continue parsing from here, so just go back to | |||
2267 | the top. */ | |||
2268 | goto skip_attribute; | |||
2269 | ||||
2270 | default: | |||
2271 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", | |||
2272 | dwarf_form_name (form), | |||
2273 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
2274 | } | |||
2275 | } | |||
2276 | ||||
2277 | if (abbrev->has_children) | |||
2278 | return skip_children (info_ptr, cu); | |||
2279 | else | |||
2280 | return info_ptr; | |||
2281 | } | |||
2282 | ||||
2283 | /* Locate ORIG_PDI's sibling; INFO_PTR should point to the start of | |||
2284 | the next DIE after ORIG_PDI. */ | |||
2285 | ||||
2286 | static char * | |||
2287 | locate_pdi_sibling (struct partial_die_info *orig_pdi, char *info_ptr, | |||
2288 | bfd *abfd, struct dwarf2_cu *cu) | |||
2289 | { | |||
2290 | /* Do we know the sibling already? */ | |||
2291 | ||||
2292 | if (orig_pdi->sibling) | |||
2293 | return orig_pdi->sibling; | |||
2294 | ||||
2295 | /* Are there any children to deal with? */ | |||
2296 | ||||
2297 | if (!orig_pdi->has_children) | |||
2298 | return info_ptr; | |||
2299 | ||||
2300 | /* Skip the children the long way. */ | |||
2301 | ||||
2302 | return skip_children (info_ptr, cu); | |||
2303 | } | |||
2304 | ||||
2305 | /* Expand this partial symbol table into a full symbol table. */ | |||
2306 | ||||
2307 | static void | |||
2308 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) | |||
2309 | { | |||
2310 | /* FIXME: This is barely more than a stub. */ | |||
2311 | if (pst != NULL((void*)0)) | |||
2312 | { | |||
2313 | if (pst->readin) | |||
2314 | { | |||
2315 | warning ("bug: psymtab for %s is already read in.", pst->filename); | |||
2316 | } | |||
2317 | else | |||
2318 | { | |||
2319 | if (info_verbose) | |||
2320 | { | |||
2321 | printf_filtered ("Reading in symbols for %s...", pst->filename); | |||
2322 | gdb_flush (gdb_stdout); | |||
2323 | } | |||
2324 | ||||
2325 | /* Restore our global data. */ | |||
2326 | dwarf2_per_objfile = objfile_data (pst->objfile, | |||
2327 | dwarf2_objfile_data_key); | |||
2328 | ||||
2329 | psymtab_to_symtab_1 (pst); | |||
2330 | ||||
2331 | /* Finish up the debug error message. */ | |||
2332 | if (info_verbose) | |||
2333 | printf_filtered ("done.\n"); | |||
2334 | } | |||
2335 | } | |||
2336 | } | |||
2337 | ||||
2338 | /* Add PER_CU to the queue. */ | |||
2339 | ||||
2340 | static void | |||
2341 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) | |||
2342 | { | |||
2343 | struct dwarf2_queue_item *item; | |||
2344 | ||||
2345 | per_cu->queued = 1; | |||
2346 | item = xmalloc (sizeof (*item)); | |||
2347 | item->per_cu = per_cu; | |||
2348 | item->next = NULL((void*)0); | |||
2349 | ||||
2350 | if (dwarf2_queue == NULL((void*)0)) | |||
2351 | dwarf2_queue = item; | |||
2352 | else | |||
2353 | dwarf2_queue_tail->next = item; | |||
2354 | ||||
2355 | dwarf2_queue_tail = item; | |||
2356 | } | |||
2357 | ||||
2358 | /* Process the queue. */ | |||
2359 | ||||
2360 | static void | |||
2361 | process_queue (struct objfile *objfile) | |||
2362 | { | |||
2363 | struct dwarf2_queue_item *item, *next_item; | |||
2364 | ||||
2365 | /* Initially, there is just one item on the queue. Load its DIEs, | |||
2366 | and the DIEs of any other compilation units it requires, | |||
2367 | transitively. */ | |||
2368 | ||||
2369 | for (item = dwarf2_queue; item != NULL((void*)0); item = item->next) | |||
2370 | { | |||
2371 | /* Read in this compilation unit. This may add new items to | |||
2372 | the end of the queue. */ | |||
2373 | load_full_comp_unit (item->per_cu); | |||
2374 | ||||
2375 | item->per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |||
2376 | dwarf2_per_objfile->read_in_chain = item->per_cu; | |||
2377 | ||||
2378 | /* If this compilation unit has already had full symbols created, | |||
2379 | reset the TYPE fields in each DIE. */ | |||
2380 | if (item->per_cu->psymtab->readin) | |||
2381 | reset_die_and_siblings_types (item->per_cu->cu->dies, | |||
2382 | item->per_cu->cu); | |||
2383 | } | |||
2384 | ||||
2385 | /* Now everything left on the queue needs to be read in. Process | |||
2386 | them, one at a time, removing from the queue as we finish. */ | |||
2387 | for (item = dwarf2_queue; item != NULL((void*)0); dwarf2_queue = item = next_item) | |||
2388 | { | |||
2389 | if (!item->per_cu->psymtab->readin) | |||
2390 | process_full_comp_unit (item->per_cu); | |||
2391 | ||||
2392 | item->per_cu->queued = 0; | |||
2393 | next_item = item->next; | |||
2394 | xfree (item); | |||
2395 | } | |||
2396 | ||||
2397 | dwarf2_queue_tail = NULL((void*)0); | |||
2398 | } | |||
2399 | ||||
2400 | /* Free all allocated queue entries. This function only releases anything if | |||
2401 | an error was thrown; if the queue was processed then it would have been | |||
2402 | freed as we went along. */ | |||
2403 | ||||
2404 | static void | |||
2405 | dwarf2_release_queue (void *dummy) | |||
2406 | { | |||
2407 | struct dwarf2_queue_item *item, *last; | |||
2408 | ||||
2409 | item = dwarf2_queue; | |||
2410 | while (item) | |||
2411 | { | |||
2412 | /* Anything still marked queued is likely to be in an | |||
2413 | inconsistent state, so discard it. */ | |||
2414 | if (item->per_cu->queued) | |||
2415 | { | |||
2416 | if (item->per_cu->cu != NULL((void*)0)) | |||
2417 | free_one_cached_comp_unit (item->per_cu->cu); | |||
2418 | item->per_cu->queued = 0; | |||
2419 | } | |||
2420 | ||||
2421 | last = item; | |||
2422 | item = item->next; | |||
2423 | xfree (last); | |||
2424 | } | |||
2425 | ||||
2426 | dwarf2_queue = dwarf2_queue_tail = NULL((void*)0); | |||
2427 | } | |||
2428 | ||||
2429 | /* Read in full symbols for PST, and anything it depends on. */ | |||
2430 | ||||
2431 | static void | |||
2432 | psymtab_to_symtab_1 (struct partial_symtab *pst) | |||
2433 | { | |||
2434 | struct dwarf2_per_cu_data *per_cu; | |||
2435 | struct cleanup *back_to; | |||
2436 | int i; | |||
2437 | ||||
2438 | for (i = 0; i < pst->number_of_dependencies; i++) | |||
2439 | if (!pst->dependencies[i]->readin) | |||
2440 | { | |||
2441 | /* Inform about additional files that need to be read in. */ | |||
2442 | if (info_verbose) | |||
2443 | { | |||
2444 | fputs_filtered (" ", gdb_stdout); | |||
2445 | wrap_here (""); | |||
2446 | fputs_filtered ("and ", gdb_stdout); | |||
2447 | wrap_here (""); | |||
2448 | printf_filtered ("%s...", pst->dependencies[i]->filename); | |||
2449 | wrap_here (""); /* Flush output */ | |||
2450 | gdb_flush (gdb_stdout); | |||
2451 | } | |||
2452 | psymtab_to_symtab_1 (pst->dependencies[i]); | |||
2453 | } | |||
2454 | ||||
2455 | per_cu = (struct dwarf2_per_cu_data *) pst->read_symtab_private; | |||
2456 | ||||
2457 | if (per_cu == NULL((void*)0)) | |||
2458 | { | |||
2459 | /* It's an include file, no symbols to read for it. | |||
2460 | Everything is in the parent symtab. */ | |||
2461 | pst->readin = 1; | |||
2462 | return; | |||
2463 | } | |||
2464 | ||||
2465 | back_to = make_cleanup (dwarf2_release_queue, NULL((void*)0)); | |||
2466 | ||||
2467 | queue_comp_unit (per_cu); | |||
2468 | ||||
2469 | process_queue (pst->objfile); | |||
2470 | ||||
2471 | /* Age the cache, releasing compilation units that have not | |||
2472 | been used recently. */ | |||
2473 | age_cached_comp_units (); | |||
2474 | ||||
2475 | do_cleanups (back_to); | |||
2476 | } | |||
2477 | ||||
2478 | /* Load the DIEs associated with PST and PER_CU into memory. */ | |||
2479 | ||||
2480 | static struct dwarf2_cu * | |||
2481 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |||
2482 | { | |||
2483 | struct partial_symtab *pst = per_cu->psymtab; | |||
2484 | bfd *abfd = pst->objfile->obfd; | |||
2485 | struct dwarf2_cu *cu; | |||
2486 | unsigned long offset; | |||
2487 | char *info_ptr; | |||
2488 | struct cleanup *back_to, *free_cu_cleanup; | |||
2489 | struct attribute *attr; | |||
2490 | CORE_ADDR baseaddr; | |||
2491 | ||||
2492 | /* Set local variables from the partial symbol table info. */ | |||
2493 | offset = per_cu->offset; | |||
2494 | ||||
2495 | info_ptr = dwarf2_per_objfile->info_buffer + offset; | |||
2496 | ||||
2497 | cu = xmalloc (sizeof (struct dwarf2_cu)); | |||
2498 | memset (cu, 0, sizeof (struct dwarf2_cu)); | |||
2499 | ||||
2500 | /* If an error occurs while loading, release our storage. */ | |||
2501 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); | |||
2502 | ||||
2503 | cu->objfile = pst->objfile; | |||
2504 | ||||
2505 | /* read in the comp_unit header */ | |||
2506 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); | |||
2507 | ||||
2508 | /* Read the abbrevs for this compilation unit */ | |||
2509 | dwarf2_read_abbrevs (abfd, cu); | |||
2510 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); | |||
2511 | ||||
2512 | cu->header.offset = offset; | |||
2513 | ||||
2514 | cu->per_cu = per_cu; | |||
2515 | per_cu->cu = cu; | |||
2516 | ||||
2517 | /* We use this obstack for block values in dwarf_alloc_block. */ | |||
2518 | obstack_init (&cu->comp_unit_obstack)_obstack_begin ((&cu->comp_unit_obstack), 0, 0, (void * (*) (long)) xmalloc, (void (*) (void *)) xfree); | |||
2519 | ||||
2520 | cu->dies = read_comp_unit (info_ptr, abfd, cu); | |||
2521 | ||||
2522 | /* We try not to read any attributes in this function, because not | |||
2523 | all objfiles needed for references have been loaded yet, and symbol | |||
2524 | table processing isn't initialized. But we have to set the CU language, | |||
2525 | or we won't be able to build types correctly. */ | |||
2526 | attr = dwarf2_attr (cu->dies, DW_AT_language, cu); | |||
2527 | if (attr) | |||
2528 | set_cu_language (DW_UNSND (attr)((attr)->u.unsnd), cu); | |||
2529 | else | |||
2530 | set_cu_language (language_minimal, cu); | |||
2531 | ||||
2532 | do_cleanups (back_to); | |||
2533 | ||||
2534 | /* We've successfully allocated this compilation unit. Let our caller | |||
2535 | clean it up when finished with it. */ | |||
2536 | discard_cleanups (free_cu_cleanup); | |||
2537 | ||||
2538 | return cu; | |||
2539 | } | |||
2540 | ||||
2541 | /* Generate full symbol information for PST and CU, whose DIEs have | |||
2542 | already been loaded into memory. */ | |||
2543 | ||||
2544 | static void | |||
2545 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) | |||
2546 | { | |||
2547 | struct partial_symtab *pst = per_cu->psymtab; | |||
2548 | struct dwarf2_cu *cu = per_cu->cu; | |||
2549 | struct objfile *objfile = pst->objfile; | |||
2550 | bfd *abfd = objfile->obfd; | |||
2551 | CORE_ADDR lowpc, highpc; | |||
2552 | struct symtab *symtab; | |||
2553 | struct cleanup *back_to; | |||
2554 | struct attribute *attr; | |||
2555 | CORE_ADDR baseaddr; | |||
2556 | ||||
2557 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2557, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2557, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2557, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
2558 | ||||
2559 | /* We're in the global namespace. */ | |||
2560 | processing_current_prefix = ""; | |||
2561 | ||||
2562 | buildsym_init (); | |||
2563 | back_to = make_cleanup (really_free_pendings, NULL((void*)0)); | |||
2564 | ||||
2565 | cu->list_in_scope = &file_symbols; | |||
2566 | ||||
2567 | /* Find the base address of the compilation unit for range lists and | |||
2568 | location lists. It will normally be specified by DW_AT_low_pc. | |||
2569 | In DWARF-3 draft 4, the base address could be overridden by | |||
2570 | DW_AT_entry_pc. It's been removed, but GCC still uses this for | |||
2571 | compilation units with discontinuous ranges. */ | |||
2572 | ||||
2573 | cu->header.base_known = 0; | |||
2574 | cu->header.base_address = 0; | |||
2575 | ||||
2576 | attr = dwarf2_attr (cu->dies, DW_AT_entry_pc, cu); | |||
2577 | if (attr) | |||
2578 | { | |||
2579 | cu->header.base_address = DW_ADDR (attr)((attr)->u.addr); | |||
2580 | cu->header.base_known = 1; | |||
2581 | } | |||
2582 | else | |||
2583 | { | |||
2584 | attr = dwarf2_attr (cu->dies, DW_AT_low_pc, cu); | |||
2585 | if (attr) | |||
2586 | { | |||
2587 | cu->header.base_address = DW_ADDR (attr)((attr)->u.addr); | |||
2588 | cu->header.base_known = 1; | |||
2589 | } | |||
2590 | } | |||
2591 | ||||
2592 | /* Do line number decoding in read_file_scope () */ | |||
2593 | process_die (cu->dies, cu); | |||
2594 | ||||
2595 | /* Some compilers don't define a DW_AT_high_pc attribute for the | |||
2596 | compilation unit. If the DW_AT_high_pc is missing, synthesize | |||
2597 | it, by scanning the DIE's below the compilation unit. */ | |||
2598 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); | |||
2599 | ||||
2600 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2600, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)); | |||
2601 | ||||
2602 | /* Set symtab language to language from DW_AT_language. | |||
2603 | If the compilation is from a C file generated by language preprocessors, | |||
2604 | do not set the language if it was already deduced by start_subfile. */ | |||
2605 | if (symtab != NULL((void*)0) | |||
2606 | && !(cu->language == language_c && symtab->language != language_c)) | |||
2607 | { | |||
2608 | symtab->language = cu->language; | |||
2609 | } | |||
2610 | pst->symtab = symtab; | |||
2611 | pst->readin = 1; | |||
2612 | ||||
2613 | do_cleanups (back_to); | |||
2614 | } | |||
2615 | ||||
2616 | /* Process a die and its children. */ | |||
2617 | ||||
2618 | static void | |||
2619 | process_die (struct die_info *die, struct dwarf2_cu *cu) | |||
2620 | { | |||
2621 | switch (die->tag) | |||
2622 | { | |||
2623 | case DW_TAG_padding: | |||
2624 | break; | |||
2625 | case DW_TAG_compile_unit: | |||
2626 | read_file_scope (die, cu); | |||
2627 | break; | |||
2628 | case DW_TAG_subprogram: | |||
2629 | read_subroutine_type (die, cu); | |||
2630 | read_func_scope (die, cu); | |||
2631 | break; | |||
2632 | case DW_TAG_inlined_subroutine: | |||
2633 | /* FIXME: These are ignored for now. | |||
2634 | They could be used to set breakpoints on all inlined instances | |||
2635 | of a function and make GDB `next' properly over inlined functions. */ | |||
2636 | break; | |||
2637 | case DW_TAG_lexical_block: | |||
2638 | case DW_TAG_try_block: | |||
2639 | case DW_TAG_catch_block: | |||
2640 | read_lexical_block_scope (die, cu); | |||
2641 | break; | |||
2642 | case DW_TAG_class_type: | |||
2643 | case DW_TAG_structure_type: | |||
2644 | case DW_TAG_union_type: | |||
2645 | read_structure_type (die, cu); | |||
2646 | process_structure_scope (die, cu); | |||
2647 | break; | |||
2648 | case DW_TAG_enumeration_type: | |||
2649 | read_enumeration_type (die, cu); | |||
2650 | process_enumeration_scope (die, cu); | |||
2651 | break; | |||
2652 | ||||
2653 | /* FIXME drow/2004-03-14: These initialize die->type, but do not create | |||
2654 | a symbol or process any children. Therefore it doesn't do anything | |||
2655 | that won't be done on-demand by read_type_die. */ | |||
2656 | case DW_TAG_subroutine_type: | |||
2657 | read_subroutine_type (die, cu); | |||
2658 | break; | |||
2659 | case DW_TAG_array_type: | |||
2660 | read_array_type (die, cu); | |||
2661 | break; | |||
2662 | case DW_TAG_pointer_type: | |||
2663 | read_tag_pointer_type (die, cu); | |||
2664 | break; | |||
2665 | case DW_TAG_ptr_to_member_type: | |||
2666 | read_tag_ptr_to_member_type (die, cu); | |||
2667 | break; | |||
2668 | case DW_TAG_reference_type: | |||
2669 | read_tag_reference_type (die, cu); | |||
2670 | break; | |||
2671 | case DW_TAG_string_type: | |||
2672 | read_tag_string_type (die, cu); | |||
2673 | break; | |||
2674 | /* END FIXME */ | |||
2675 | ||||
2676 | case DW_TAG_base_type: | |||
2677 | read_base_type (die, cu); | |||
2678 | /* Add a typedef symbol for the type definition, if it has a | |||
2679 | DW_AT_name. */ | |||
2680 | new_symbol (die, die->type, cu); | |||
2681 | break; | |||
2682 | case DW_TAG_subrange_type: | |||
2683 | read_subrange_type (die, cu); | |||
2684 | /* Add a typedef symbol for the type definition, if it has a | |||
2685 | DW_AT_name. */ | |||
2686 | new_symbol (die, die->type, cu); | |||
2687 | break; | |||
2688 | case DW_TAG_common_block: | |||
2689 | read_common_block (die, cu); | |||
2690 | break; | |||
2691 | case DW_TAG_common_inclusion: | |||
2692 | break; | |||
2693 | case DW_TAG_namespace: | |||
2694 | processing_has_namespace_info = 1; | |||
2695 | read_namespace (die, cu); | |||
2696 | break; | |||
2697 | case DW_TAG_imported_declaration: | |||
2698 | case DW_TAG_imported_module: | |||
2699 | /* FIXME: carlton/2002-10-16: Eventually, we should use the | |||
2700 | information contained in these. DW_TAG_imported_declaration | |||
2701 | dies shouldn't have children; DW_TAG_imported_module dies | |||
2702 | shouldn't in the C++ case, but conceivably could in the | |||
2703 | Fortran case, so we'll have to replace this gdb_assert if | |||
2704 | Fortran compilers start generating that info. */ | |||
2705 | processing_has_namespace_info = 1; | |||
2706 | gdb_assert (die->child == NULL)((void) ((die->child == ((void*)0)) ? 0 : (internal_error ( "/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", 2706, "%s: Assertion `%s' failed." , __PRETTY_FUNCTION__, "die->child == NULL"), 0))); | |||
2707 | break; | |||
2708 | default: | |||
2709 | new_symbol (die, NULL((void*)0), cu); | |||
2710 | break; | |||
2711 | } | |||
2712 | } | |||
2713 | ||||
2714 | static void | |||
2715 | initialize_cu_func_list (struct dwarf2_cu *cu) | |||
2716 | { | |||
2717 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL((void*)0); | |||
2718 | } | |||
2719 | ||||
2720 | static void | |||
2721 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) | |||
2722 | { | |||
2723 | struct objfile *objfile = cu->objfile; | |||
2724 | struct comp_unit_head *cu_header = &cu->header; | |||
2725 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |||
2726 | CORE_ADDR lowpc = ((CORE_ADDR) -1); | |||
2727 | CORE_ADDR highpc = ((CORE_ADDR) 0); | |||
2728 | struct attribute *attr; | |||
2729 | char *name = "<unknown>"; | |||
2730 | char *comp_dir = NULL((void*)0); | |||
2731 | struct die_info *child_die; | |||
2732 | bfd *abfd = objfile->obfd; | |||
2733 | struct line_header *line_header = 0; | |||
2734 | CORE_ADDR baseaddr; | |||
2735 | ||||
2736 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2736, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2736, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2736, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
2737 | ||||
2738 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); | |||
2739 | ||||
2740 | /* If we didn't find a lowpc, set it to highpc to avoid complaints | |||
2741 | from finish_block. */ | |||
2742 | if (lowpc == ((CORE_ADDR) -1)) | |||
2743 | lowpc = highpc; | |||
2744 | lowpc += baseaddr; | |||
2745 | highpc += baseaddr; | |||
2746 | ||||
2747 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
2748 | if (attr) | |||
2749 | { | |||
2750 | name = DW_STRING (attr)((attr)->u.str); | |||
2751 | } | |||
2752 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); | |||
2753 | if (attr) | |||
2754 | { | |||
2755 | comp_dir = DW_STRING (attr)((attr)->u.str); | |||
2756 | if (comp_dir) | |||
2757 | { | |||
2758 | /* Irix 6.2 native cc prepends <machine>.: to the compilation | |||
2759 | directory, get rid of it. */ | |||
2760 | char *cp = strchr (comp_dir, ':'); | |||
2761 | ||||
2762 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') | |||
2763 | comp_dir = cp + 1; | |||
2764 | } | |||
2765 | } | |||
2766 | ||||
2767 | attr = dwarf2_attr (die, DW_AT_language, cu); | |||
2768 | if (attr) | |||
2769 | { | |||
2770 | set_cu_language (DW_UNSND (attr)((attr)->u.unsnd), cu); | |||
2771 | } | |||
2772 | ||||
2773 | attr = dwarf2_attr (die, DW_AT_producer, cu); | |||
2774 | if (attr) | |||
2775 | cu->producer = DW_STRING (attr)((attr)->u.str); | |||
2776 | ||||
2777 | /* We assume that we're processing GCC output. */ | |||
2778 | processing_gcc_compilation = 2; | |||
2779 | #if 0 | |||
2780 | /* FIXME:Do something here. */ | |||
2781 | if (dip->at_producer != NULL((void*)0)) | |||
2782 | { | |||
2783 | handle_producer (dip->at_producer); | |||
2784 | } | |||
2785 | #endif | |||
2786 | ||||
2787 | /* The compilation unit may be in a different language or objfile, | |||
2788 | zero out all remembered fundamental types. */ | |||
2789 | memset (cu->ftypes, 0, FT_NUM_MEMBERS29 * sizeof (struct type *)); | |||
2790 | ||||
2791 | start_symtab (name, comp_dir, lowpc); | |||
2792 | record_debugformat ("DWARF 2"); | |||
2793 | ||||
2794 | initialize_cu_func_list (cu); | |||
2795 | ||||
2796 | /* Process all dies in compilation unit. */ | |||
2797 | if (die->child != NULL((void*)0)) | |||
2798 | { | |||
2799 | child_die = die->child; | |||
2800 | while (child_die && child_die->tag) | |||
2801 | { | |||
2802 | process_die (child_die, cu); | |||
2803 | child_die = sibling_die (child_die); | |||
2804 | } | |||
2805 | } | |||
2806 | ||||
2807 | /* Decode line number information if present. */ | |||
2808 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); | |||
2809 | if (attr) | |||
2810 | { | |||
2811 | unsigned int line_offset = DW_UNSND (attr)((attr)->u.unsnd); | |||
2812 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); | |||
2813 | if (line_header) | |||
2814 | { | |||
2815 | make_cleanup ((make_cleanup_ftype *) free_line_header, | |||
2816 | (void *) line_header); | |||
2817 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL((void*)0)); | |||
2818 | } | |||
2819 | } | |||
2820 | ||||
2821 | /* Decode macro information, if present. Dwarf 2 macro information | |||
2822 | refers to information in the line number info statement program | |||
2823 | header, so we can only read it if we've read the header | |||
2824 | successfully. */ | |||
2825 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); | |||
2826 | if (attr && line_header) | |||
2827 | { | |||
2828 | unsigned int macro_offset = DW_UNSND (attr)((attr)->u.unsnd); | |||
2829 | dwarf_decode_macros (line_header, macro_offset, | |||
2830 | comp_dir, abfd, cu); | |||
2831 | } | |||
2832 | do_cleanups (back_to); | |||
2833 | } | |||
2834 | ||||
2835 | static void | |||
2836 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, | |||
2837 | struct dwarf2_cu *cu) | |||
2838 | { | |||
2839 | struct function_range *thisfn; | |||
2840 | ||||
2841 | thisfn = (struct function_range *) | |||
2842 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range))__extension__ ({ struct obstack *__h = (&cu->comp_unit_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct function_range))); if (__o->chunk_limit - __o ->next_free < __len) _obstack_newchunk (__o, __len); (( __o)->next_free += (__len)); (void) 0; }); __extension__ ( { struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1-> maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free ) - (char *) 0)+__o1->alignment_mask) & ~ (__o1->alignment_mask )) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1-> next_free = __o1->chunk_limit; __o1->object_base = __o1 ->next_free; value; }); }); | |||
2843 | thisfn->name = name; | |||
2844 | thisfn->lowpc = lowpc; | |||
2845 | thisfn->highpc = highpc; | |||
2846 | thisfn->seen_line = 0; | |||
2847 | thisfn->next = NULL((void*)0); | |||
2848 | ||||
2849 | if (cu->last_fn == NULL((void*)0)) | |||
2850 | cu->first_fn = thisfn; | |||
2851 | else | |||
2852 | cu->last_fn->next = thisfn; | |||
2853 | ||||
2854 | cu->last_fn = thisfn; | |||
2855 | } | |||
2856 | ||||
2857 | static void | |||
2858 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) | |||
2859 | { | |||
2860 | struct objfile *objfile = cu->objfile; | |||
2861 | struct context_stack *new; | |||
2862 | CORE_ADDR lowpc; | |||
2863 | CORE_ADDR highpc; | |||
2864 | struct die_info *child_die; | |||
2865 | struct attribute *attr; | |||
2866 | char *name; | |||
2867 | const char *previous_prefix = processing_current_prefix; | |||
2868 | struct cleanup *back_to = NULL((void*)0); | |||
2869 | CORE_ADDR baseaddr; | |||
2870 | ||||
2871 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2871, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2871, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2871, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
2872 | ||||
2873 | name = dwarf2_linkage_name (die, cu); | |||
2874 | ||||
2875 | /* Ignore functions with missing or empty names and functions with | |||
2876 | missing or invalid low and high pc attributes. */ | |||
2877 | if (name == NULL((void*)0) || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) | |||
2878 | return; | |||
2879 | ||||
2880 | if (cu->language == language_cplus | |||
2881 | || cu->language == language_java) | |||
2882 | { | |||
2883 | struct die_info *spec_die = die_specification (die, cu); | |||
2884 | ||||
2885 | /* NOTE: carlton/2004-01-23: We have to be careful in the | |||
2886 | presence of DW_AT_specification. For example, with GCC 3.4, | |||
2887 | given the code | |||
2888 | ||||
2889 | namespace N { | |||
2890 | void foo() { | |||
2891 | // Definition of N::foo. | |||
2892 | } | |||
2893 | } | |||
2894 | ||||
2895 | then we'll have a tree of DIEs like this: | |||
2896 | ||||
2897 | 1: DW_TAG_compile_unit | |||
2898 | 2: DW_TAG_namespace // N | |||
2899 | 3: DW_TAG_subprogram // declaration of N::foo | |||
2900 | 4: DW_TAG_subprogram // definition of N::foo | |||
2901 | DW_AT_specification // refers to die #3 | |||
2902 | ||||
2903 | Thus, when processing die #4, we have to pretend that we're | |||
2904 | in the context of its DW_AT_specification, namely the contex | |||
2905 | of die #3. */ | |||
2906 | ||||
2907 | if (spec_die != NULL((void*)0)) | |||
2908 | { | |||
2909 | char *specification_prefix = determine_prefix (spec_die, cu); | |||
2910 | processing_current_prefix = specification_prefix; | |||
2911 | back_to = make_cleanup (xfree, specification_prefix); | |||
2912 | } | |||
2913 | } | |||
2914 | ||||
2915 | lowpc += baseaddr; | |||
2916 | highpc += baseaddr; | |||
2917 | ||||
2918 | /* Record the function range for dwarf_decode_lines. */ | |||
2919 | add_to_cu_func_list (name, lowpc, highpc, cu); | |||
2920 | ||||
2921 | new = push_context (0, lowpc); | |||
2922 | new->name = new_symbol (die, die->type, cu); | |||
2923 | ||||
2924 | /* If there is a location expression for DW_AT_frame_base, record | |||
2925 | it. */ | |||
2926 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); | |||
2927 | if (attr) | |||
2928 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location | |||
2929 | expression is being recorded directly in the function's symbol | |||
2930 | and not in a separate frame-base object. I guess this hack is | |||
2931 | to avoid adding some sort of frame-base adjunct/annex to the | |||
2932 | function's symbol :-(. The problem with doing this is that it | |||
2933 | results in a function symbol with a location expression that | |||
2934 | has nothing to do with the location of the function, ouch! The | |||
2935 | relationship should be: a function's symbol has-a frame base; a | |||
2936 | frame-base has-a location expression. */ | |||
2937 | dwarf2_symbol_mark_computed (attr, new->name, cu); | |||
2938 | ||||
2939 | cu->list_in_scope = &local_symbols; | |||
2940 | ||||
2941 | if (die->child != NULL((void*)0)) | |||
2942 | { | |||
2943 | child_die = die->child; | |||
2944 | while (child_die && child_die->tag) | |||
2945 | { | |||
2946 | process_die (child_die, cu); | |||
2947 | child_die = sibling_die (child_die); | |||
2948 | } | |||
2949 | } | |||
2950 | ||||
2951 | new = pop_context (); | |||
2952 | /* Make a block for the local symbols within. */ | |||
2953 | finish_block (new->name, &local_symbols, new->old_blocks, | |||
2954 | lowpc, highpc, objfile); | |||
2955 | ||||
2956 | /* In C++, we can have functions nested inside functions (e.g., when | |||
2957 | a function declares a class that has methods). This means that | |||
2958 | when we finish processing a function scope, we may need to go | |||
2959 | back to building a containing block's symbol lists. */ | |||
2960 | local_symbols = new->locals; | |||
2961 | param_symbols = new->params; | |||
2962 | ||||
2963 | /* If we've finished processing a top-level function, subsequent | |||
2964 | symbols go in the file symbol list. */ | |||
2965 | if (outermost_context_p ()(context_stack_depth == 0)) | |||
2966 | cu->list_in_scope = &file_symbols; | |||
2967 | ||||
2968 | processing_current_prefix = previous_prefix; | |||
2969 | if (back_to != NULL((void*)0)) | |||
2970 | do_cleanups (back_to); | |||
2971 | } | |||
2972 | ||||
2973 | /* Process all the DIES contained within a lexical block scope. Start | |||
2974 | a new scope, process the dies, and then close the scope. */ | |||
2975 | ||||
2976 | static void | |||
2977 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) | |||
2978 | { | |||
2979 | struct objfile *objfile = cu->objfile; | |||
2980 | struct context_stack *new; | |||
2981 | CORE_ADDR lowpc, highpc; | |||
2982 | struct die_info *child_die; | |||
2983 | CORE_ADDR baseaddr; | |||
2984 | ||||
2985 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile))((((objfile->sect_index_text == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2985, "sect_index_text not initialized"), -1) : objfile-> sect_index_text) == -1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2985, "Section index is uninitialized"), -1) : objfile-> section_offsets->offsets[((objfile->sect_index_text == - 1) ? (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 2985, "sect_index_text not initialized"), -1) : objfile-> sect_index_text)]); | |||
2986 | ||||
2987 | /* Ignore blocks with missing or invalid low and high pc attributes. */ | |||
2988 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges | |||
2989 | as multiple lexical blocks? Handling children in a sane way would | |||
2990 | be nasty. Might be easier to properly extend generic blocks to | |||
2991 | describe ranges. */ | |||
2992 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu)) | |||
2993 | return; | |||
2994 | lowpc += baseaddr; | |||
2995 | highpc += baseaddr; | |||
2996 | ||||
2997 | push_context (0, lowpc); | |||
2998 | if (die->child != NULL((void*)0)) | |||
2999 | { | |||
3000 | child_die = die->child; | |||
3001 | while (child_die && child_die->tag) | |||
3002 | { | |||
3003 | process_die (child_die, cu); | |||
3004 | child_die = sibling_die (child_die); | |||
3005 | } | |||
3006 | } | |||
3007 | new = pop_context (); | |||
3008 | ||||
3009 | if (local_symbols != NULL((void*)0)) | |||
3010 | { | |||
3011 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, | |||
3012 | highpc, objfile); | |||
3013 | } | |||
3014 | local_symbols = new->locals; | |||
3015 | } | |||
3016 | ||||
3017 | /* Get low and high pc attributes from a die. Return 1 if the attributes | |||
3018 | are present and valid, otherwise, return 0. Return -1 if the range is | |||
3019 | discontinuous, i.e. derived from DW_AT_ranges information. */ | |||
3020 | static int | |||
3021 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, | |||
3022 | CORE_ADDR *highpc, struct dwarf2_cu *cu) | |||
3023 | { | |||
3024 | struct objfile *objfile = cu->objfile; | |||
3025 | struct comp_unit_head *cu_header = &cu->header; | |||
3026 | struct attribute *attr; | |||
3027 | bfd *obfd = objfile->obfd; | |||
3028 | CORE_ADDR low = 0; | |||
3029 | CORE_ADDR high = 0; | |||
3030 | int ret = 0; | |||
3031 | ||||
3032 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); | |||
3033 | if (attr) | |||
3034 | { | |||
3035 | high = DW_ADDR (attr)((attr)->u.addr); | |||
3036 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); | |||
3037 | if (attr) | |||
3038 | low = DW_ADDR (attr)((attr)->u.addr); | |||
3039 | else | |||
3040 | /* Found high w/o low attribute. */ | |||
3041 | return 0; | |||
3042 | ||||
3043 | /* Found consecutive range of addresses. */ | |||
3044 | ret = 1; | |||
3045 | } | |||
3046 | else | |||
3047 | { | |||
3048 | attr = dwarf2_attr (die, DW_AT_ranges, cu); | |||
3049 | if (attr != NULL((void*)0)) | |||
3050 | { | |||
3051 | unsigned int addr_size = cu_header->addr_size; | |||
3052 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); | |||
3053 | /* Value of the DW_AT_ranges attribute is the offset in the | |||
3054 | .debug_ranges section. */ | |||
3055 | unsigned int offset = DW_UNSND (attr)((attr)->u.unsnd); | |||
3056 | /* Base address selection entry. */ | |||
3057 | CORE_ADDR base; | |||
3058 | int found_base; | |||
3059 | int dummy; | |||
3060 | char *buffer; | |||
3061 | CORE_ADDR marker; | |||
3062 | int low_set; | |||
3063 | ||||
3064 | found_base = cu_header->base_known; | |||
3065 | base = cu_header->base_address; | |||
3066 | ||||
3067 | if (offset >= dwarf2_per_objfile->ranges_size) | |||
3068 | { | |||
3069 | complaint (&symfile_complaints, | |||
3070 | "Offset %d out of bounds for DW_AT_ranges attribute", | |||
3071 | offset); | |||
3072 | return 0; | |||
3073 | } | |||
3074 | buffer = dwarf2_per_objfile->ranges_buffer + offset; | |||
3075 | ||||
3076 | /* Read in the largest possible address. */ | |||
3077 | marker = read_address (obfd, buffer, cu, &dummy); | |||
3078 | if ((marker & mask) == mask) | |||
3079 | { | |||
3080 | /* If we found the largest possible address, then | |||
3081 | read the base address. */ | |||
3082 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |||
3083 | buffer += 2 * addr_size; | |||
3084 | offset += 2 * addr_size; | |||
3085 | found_base = 1; | |||
3086 | } | |||
3087 | ||||
3088 | low_set = 0; | |||
3089 | ||||
3090 | while (1) | |||
3091 | { | |||
3092 | CORE_ADDR range_beginning, range_end; | |||
3093 | ||||
3094 | range_beginning = read_address (obfd, buffer, cu, &dummy); | |||
3095 | buffer += addr_size; | |||
3096 | range_end = read_address (obfd, buffer, cu, &dummy); | |||
3097 | buffer += addr_size; | |||
3098 | offset += 2 * addr_size; | |||
3099 | ||||
3100 | /* An end of list marker is a pair of zero addresses. */ | |||
3101 | if (range_beginning == 0 && range_end == 0) | |||
3102 | /* Found the end of list entry. */ | |||
3103 | break; | |||
3104 | ||||
3105 | /* Each base address selection entry is a pair of 2 values. | |||
3106 | The first is the largest possible address, the second is | |||
3107 | the base address. Check for a base address here. */ | |||
3108 | if ((range_beginning & mask) == mask) | |||
3109 | { | |||
3110 | /* If we found the largest possible address, then | |||
3111 | read the base address. */ | |||
3112 | base = read_address (obfd, buffer + addr_size, cu, &dummy); | |||
3113 | found_base = 1; | |||
3114 | continue; | |||
3115 | } | |||
3116 | ||||
3117 | if (!found_base) | |||
3118 | { | |||
3119 | /* We have no valid base address for the ranges | |||
3120 | data. */ | |||
3121 | complaint (&symfile_complaints, | |||
3122 | "Invalid .debug_ranges data (no base address)"); | |||
3123 | return 0; | |||
3124 | } | |||
3125 | ||||
3126 | range_beginning += base; | |||
3127 | range_end += base; | |||
3128 | ||||
3129 | /* FIXME: This is recording everything as a low-high | |||
3130 | segment of consecutive addresses. We should have a | |||
3131 | data structure for discontiguous block ranges | |||
3132 | instead. */ | |||
3133 | if (! low_set) | |||
3134 | { | |||
3135 | low = range_beginning; | |||
3136 | high = range_end; | |||
3137 | low_set = 1; | |||
3138 | } | |||
3139 | else | |||
3140 | { | |||
3141 | if (range_beginning < low) | |||
3142 | low = range_beginning; | |||
3143 | if (range_end > high) | |||
3144 | high = range_end; | |||
3145 | } | |||
3146 | } | |||
3147 | ||||
3148 | if (! low_set) | |||
3149 | /* If the first entry is an end-of-list marker, the range | |||
3150 | describes an empty scope, i.e. no instructions. */ | |||
3151 | return 0; | |||
3152 | ||||
3153 | ret = -1; | |||
3154 | } | |||
3155 | } | |||
3156 | ||||
3157 | if (high < low) | |||
3158 | return 0; | |||
3159 | ||||
3160 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |||
3161 | eliminate duplicate copies of functions and vtables and such. | |||
3162 | The linker will arbitrarily choose one and discard the others. | |||
3163 | The AT_*_pc values for such functions refer to local labels in | |||
3164 | these sections. If the section from that file was discarded, the | |||
3165 | labels are not in the output, so the relocs get a value of 0. | |||
3166 | If this is a discarded function, mark the pc bounds as invalid, | |||
3167 | so that GDB will ignore it. */ | |||
3168 | if (low == 0 && (bfd_get_file_flags (obfd)((obfd)->flags) & HAS_RELOC0x01) == 0) | |||
3169 | return 0; | |||
3170 | ||||
3171 | *lowpc = low; | |||
3172 | *highpc = high; | |||
3173 | return ret; | |||
3174 | } | |||
3175 | ||||
3176 | /* Get the low and high pc's represented by the scope DIE, and store | |||
3177 | them in *LOWPC and *HIGHPC. If the correct values can't be | |||
3178 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ | |||
3179 | ||||
3180 | static void | |||
3181 | get_scope_pc_bounds (struct die_info *die, | |||
3182 | CORE_ADDR *lowpc, CORE_ADDR *highpc, | |||
3183 | struct dwarf2_cu *cu) | |||
3184 | { | |||
3185 | CORE_ADDR best_low = (CORE_ADDR) -1; | |||
3186 | CORE_ADDR best_high = (CORE_ADDR) 0; | |||
3187 | CORE_ADDR current_low, current_high; | |||
3188 | ||||
3189 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu)) | |||
3190 | { | |||
3191 | best_low = current_low; | |||
3192 | best_high = current_high; | |||
3193 | } | |||
3194 | else | |||
3195 | { | |||
3196 | struct die_info *child = die->child; | |||
3197 | ||||
3198 | while (child && child->tag) | |||
3199 | { | |||
3200 | switch (child->tag) { | |||
3201 | case DW_TAG_subprogram: | |||
3202 | if (dwarf2_get_pc_bounds (child, ¤t_low, ¤t_high, cu)) | |||
3203 | { | |||
3204 | best_low = min (best_low, current_low)((best_low) < (current_low) ? (best_low) : (current_low)); | |||
3205 | best_high = max (best_high, current_high)((best_high) > (current_high) ? (best_high) : (current_high )); | |||
3206 | } | |||
3207 | break; | |||
3208 | case DW_TAG_namespace: | |||
3209 | /* FIXME: carlton/2004-01-16: Should we do this for | |||
3210 | DW_TAG_class_type/DW_TAG_structure_type, too? I think | |||
3211 | that current GCC's always emit the DIEs corresponding | |||
3212 | to definitions of methods of classes as children of a | |||
3213 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to | |||
3214 | the DIEs giving the declarations, which could be | |||
3215 | anywhere). But I don't see any reason why the | |||
3216 | standards says that they have to be there. */ | |||
3217 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); | |||
3218 | ||||
3219 | if (current_low != ((CORE_ADDR) -1)) | |||
3220 | { | |||
3221 | best_low = min (best_low, current_low)((best_low) < (current_low) ? (best_low) : (current_low)); | |||
3222 | best_high = max (best_high, current_high)((best_high) > (current_high) ? (best_high) : (current_high )); | |||
3223 | } | |||
3224 | break; | |||
3225 | default: | |||
3226 | /* Ignore. */ | |||
3227 | break; | |||
3228 | } | |||
3229 | ||||
3230 | child = sibling_die (child); | |||
3231 | } | |||
3232 | } | |||
3233 | ||||
3234 | *lowpc = best_low; | |||
3235 | *highpc = best_high; | |||
3236 | } | |||
3237 | ||||
3238 | /* Add an aggregate field to the field list. */ | |||
3239 | ||||
3240 | static void | |||
3241 | dwarf2_add_field (struct field_info *fip, struct die_info *die, | |||
3242 | struct dwarf2_cu *cu) | |||
3243 | { | |||
3244 | struct objfile *objfile = cu->objfile; | |||
3245 | struct nextfield *new_field; | |||
3246 | struct attribute *attr; | |||
3247 | struct field *fp; | |||
3248 | char *fieldname = ""; | |||
3249 | ||||
3250 | /* Allocate a new field list entry and link it in. */ | |||
3251 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); | |||
3252 | make_cleanup (xfree, new_field); | |||
3253 | memset (new_field, 0, sizeof (struct nextfield)); | |||
3254 | new_field->next = fip->fields; | |||
3255 | fip->fields = new_field; | |||
3256 | fip->nfields++; | |||
3257 | ||||
3258 | /* Handle accessibility and virtuality of field. | |||
3259 | The default accessibility for members is public, the default | |||
3260 | accessibility for inheritance is private. */ | |||
3261 | if (die->tag != DW_TAG_inheritance) | |||
3262 | new_field->accessibility = DW_ACCESS_public; | |||
3263 | else | |||
3264 | new_field->accessibility = DW_ACCESS_private; | |||
3265 | new_field->virtuality = DW_VIRTUALITY_none; | |||
3266 | ||||
3267 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); | |||
3268 | if (attr) | |||
3269 | new_field->accessibility = DW_UNSND (attr)((attr)->u.unsnd); | |||
3270 | if (new_field->accessibility != DW_ACCESS_public) | |||
3271 | fip->non_public_fields = 1; | |||
3272 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); | |||
3273 | if (attr) | |||
3274 | new_field->virtuality = DW_UNSND (attr)((attr)->u.unsnd); | |||
3275 | ||||
3276 | fp = &new_field->field; | |||
3277 | ||||
3278 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) | |||
3279 | { | |||
3280 | /* Data member other than a C++ static data member. */ | |||
3281 | ||||
3282 | /* Get type of field. */ | |||
3283 | fp->type = die_type (die, cu); | |||
3284 | ||||
3285 | FIELD_STATIC_KIND (*fp)((*fp).static_kind) = 0; | |||
3286 | ||||
3287 | /* Get bit size of field (zero if none). */ | |||
3288 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); | |||
3289 | if (attr) | |||
3290 | { | |||
3291 | FIELD_BITSIZE (*fp)((*fp).bitsize) = DW_UNSND (attr)((attr)->u.unsnd); | |||
3292 | } | |||
3293 | else | |||
3294 | { | |||
3295 | FIELD_BITSIZE (*fp)((*fp).bitsize) = 0; | |||
3296 | } | |||
3297 | ||||
3298 | /* Get bit offset of field. */ | |||
3299 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |||
3300 | if (attr) | |||
3301 | { | |||
3302 | FIELD_BITPOS (*fp)((*fp).loc.bitpos) = | |||
3303 | decode_locdesc (DW_BLOCK (attr)((attr)->u.blk), cu) * bits_per_byte; | |||
3304 | } | |||
3305 | else | |||
3306 | FIELD_BITPOS (*fp)((*fp).loc.bitpos) = 0; | |||
3307 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); | |||
3308 | if (attr) | |||
3309 | { | |||
3310 | if (BITS_BIG_ENDIAN((gdbarch_byte_order (current_gdbarch)) == BFD_ENDIAN_BIG)) | |||
3311 | { | |||
3312 | /* For big endian bits, the DW_AT_bit_offset gives the | |||
3313 | additional bit offset from the MSB of the containing | |||
3314 | anonymous object to the MSB of the field. We don't | |||
3315 | have to do anything special since we don't need to | |||
3316 | know the size of the anonymous object. */ | |||
3317 | FIELD_BITPOS (*fp)((*fp).loc.bitpos) += DW_UNSND (attr)((attr)->u.unsnd); | |||
3318 | } | |||
3319 | else | |||
3320 | { | |||
3321 | /* For little endian bits, compute the bit offset to the | |||
3322 | MSB of the anonymous object, subtract off the number of | |||
3323 | bits from the MSB of the field to the MSB of the | |||
3324 | object, and then subtract off the number of bits of | |||
3325 | the field itself. The result is the bit offset of | |||
3326 | the LSB of the field. */ | |||
3327 | int anonymous_size; | |||
3328 | int bit_offset = DW_UNSND (attr)((attr)->u.unsnd); | |||
3329 | ||||
3330 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
3331 | if (attr) | |||
3332 | { | |||
3333 | /* The size of the anonymous object containing | |||
3334 | the bit field is explicit, so use the | |||
3335 | indicated size (in bytes). */ | |||
3336 | anonymous_size = DW_UNSND (attr)((attr)->u.unsnd); | |||
3337 | } | |||
3338 | else | |||
3339 | { | |||
3340 | /* The size of the anonymous object containing | |||
3341 | the bit field must be inferred from the type | |||
3342 | attribute of the data member containing the | |||
3343 | bit field. */ | |||
3344 | anonymous_size = TYPE_LENGTH (fp->type)(fp->type)->length; | |||
3345 | } | |||
3346 | FIELD_BITPOS (*fp)((*fp).loc.bitpos) += anonymous_size * bits_per_byte | |||
3347 | - bit_offset - FIELD_BITSIZE (*fp)((*fp).bitsize); | |||
3348 | } | |||
3349 | } | |||
3350 | ||||
3351 | /* Get name of field. */ | |||
3352 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
3353 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
3354 | fieldname = DW_STRING (attr)((attr)->u.str); | |||
3355 | ||||
3356 | /* The name is already allocated along with this objfile, so we don't | |||
3357 | need to duplicate it for the type. */ | |||
3358 | fp->name = fieldname; | |||
3359 | ||||
3360 | /* Change accessibility for artificial fields (e.g. virtual table | |||
3361 | pointer or virtual base class pointer) to private. */ | |||
3362 | if (dwarf2_attr (die, DW_AT_artificial, cu)) | |||
3363 | { | |||
3364 | new_field->accessibility = DW_ACCESS_private; | |||
3365 | fip->non_public_fields = 1; | |||
3366 | } | |||
3367 | } | |||
3368 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) | |||
3369 | { | |||
3370 | /* C++ static member. */ | |||
3371 | ||||
3372 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that | |||
3373 | is a declaration, but all versions of G++ as of this writing | |||
3374 | (so through at least 3.2.1) incorrectly generate | |||
3375 | DW_TAG_variable tags. */ | |||
3376 | ||||
3377 | char *physname; | |||
3378 | ||||
3379 | /* Get name of field. */ | |||
3380 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
3381 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
3382 | fieldname = DW_STRING (attr)((attr)->u.str); | |||
3383 | else | |||
3384 | return; | |||
3385 | ||||
3386 | /* Get physical name. */ | |||
3387 | physname = dwarf2_linkage_name (die, cu); | |||
3388 | ||||
3389 | /* The name is already allocated along with this objfile, so we don't | |||
3390 | need to duplicate it for the type. */ | |||
3391 | SET_FIELD_PHYSNAME (*fp, physname ? physname : "")((*fp).static_kind = 1, ((*fp).loc.physname) = (physname ? physname : "")); | |||
3392 | FIELD_TYPE (*fp)((*fp).type) = die_type (die, cu); | |||
3393 | FIELD_NAME (*fp)((*fp).name) = fieldname; | |||
3394 | } | |||
3395 | else if (die->tag == DW_TAG_inheritance) | |||
3396 | { | |||
3397 | /* C++ base class field. */ | |||
3398 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); | |||
3399 | if (attr) | |||
3400 | FIELD_BITPOS (*fp)((*fp).loc.bitpos) = (decode_locdesc (DW_BLOCK (attr)((attr)->u.blk), cu) | |||
3401 | * bits_per_byte); | |||
3402 | FIELD_BITSIZE (*fp)((*fp).bitsize) = 0; | |||
3403 | FIELD_STATIC_KIND (*fp)((*fp).static_kind) = 0; | |||
3404 | FIELD_TYPE (*fp)((*fp).type) = die_type (die, cu); | |||
3405 | FIELD_NAME (*fp)((*fp).name) = type_name_no_tag (fp->type); | |||
3406 | fip->nbaseclasses++; | |||
3407 | } | |||
3408 | } | |||
3409 | ||||
3410 | /* Create the vector of fields, and attach it to the type. */ | |||
3411 | ||||
3412 | static void | |||
3413 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, | |||
3414 | struct dwarf2_cu *cu) | |||
3415 | { | |||
3416 | int nfields = fip->nfields; | |||
3417 | ||||
3418 | /* Record the field count, allocate space for the array of fields, | |||
3419 | and create blank accessibility bitfields if necessary. */ | |||
3420 | TYPE_NFIELDS (type)(type)->main_type->nfields = nfields; | |||
3421 | TYPE_FIELDS (type)(type)->main_type->fields = (struct field *) | |||
3422 | TYPE_ALLOC (type, sizeof (struct field) * nfields)((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((sizeof (struct field) * nfields)); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (sizeof (struct field) * nfields)); | |||
3423 | memset (TYPE_FIELDS (type)(type)->main_type->fields, 0, sizeof (struct field) * nfields); | |||
3424 | ||||
3425 | if (fip->non_public_fields) | |||
3426 | { | |||
3427 | ALLOCATE_CPLUS_STRUCT_TYPE (type)allocate_cplus_struct_type (type); | |||
3428 | ||||
3429 | TYPE_FIELD_PRIVATE_BITS (type)(type)->main_type->type_specific.cplus_stuff->private_field_bits = | |||
3430 | (B_TYPEunsigned char *) TYPE_ALLOC (type, B_BYTES (nfields))((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((( 1 + ((nfields)>>3) ))); if (__o ->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (( 1 + ((nfields)>>3) ))); | |||
3431 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields)memset (((type)->main_type->type_specific.cplus_stuff-> private_field_bits), 0, ( 1 + ((nfields)>>3) )); | |||
3432 | ||||
3433 | TYPE_FIELD_PROTECTED_BITS (type)(type)->main_type->type_specific.cplus_stuff->protected_field_bits = | |||
3434 | (B_TYPEunsigned char *) TYPE_ALLOC (type, B_BYTES (nfields))((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((( 1 + ((nfields)>>3) ))); if (__o ->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (( 1 + ((nfields)>>3) ))); | |||
3435 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields)memset (((type)->main_type->type_specific.cplus_stuff-> protected_field_bits), 0, ( 1 + ((nfields)>>3) )); | |||
3436 | ||||
3437 | TYPE_FIELD_IGNORE_BITS (type)(type)->main_type->type_specific.cplus_stuff->ignore_field_bits = | |||
3438 | (B_TYPEunsigned char *) TYPE_ALLOC (type, B_BYTES (nfields))((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((( 1 + ((nfields)>>3) ))); if (__o ->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (( 1 + ((nfields)>>3) ))); | |||
3439 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields)memset (((type)->main_type->type_specific.cplus_stuff-> ignore_field_bits), 0, ( 1 + ((nfields)>>3) )); | |||
3440 | } | |||
3441 | ||||
3442 | /* If the type has baseclasses, allocate and clear a bit vector for | |||
3443 | TYPE_FIELD_VIRTUAL_BITS. */ | |||
3444 | if (fip->nbaseclasses) | |||
3445 | { | |||
3446 | int num_bytes = B_BYTES (fip->nbaseclasses)( 1 + ((fip->nbaseclasses)>>3) ); | |||
3447 | char *pointer; | |||
3448 | ||||
3449 | ALLOCATE_CPLUS_STRUCT_TYPE (type)allocate_cplus_struct_type (type); | |||
3450 | pointer = (char *) TYPE_ALLOC (type, num_bytes)((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((num_bytes)); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) : xmalloc (num_bytes )); | |||
3451 | TYPE_FIELD_VIRTUAL_BITS (type)(type)->main_type->type_specific.cplus_stuff->virtual_field_bits = (B_TYPEunsigned char *) pointer; | |||
3452 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses)memset (((type)->main_type->type_specific.cplus_stuff-> virtual_field_bits), 0, ( 1 + ((fip->nbaseclasses)>> 3) )); | |||
3453 | TYPE_N_BASECLASSES (type)(type)->main_type->type_specific.cplus_stuff->n_baseclasses = fip->nbaseclasses; | |||
3454 | } | |||
3455 | ||||
3456 | /* Copy the saved-up fields into the field vector. Start from the head | |||
3457 | of the list, adding to the tail of the field array, so that they end | |||
3458 | up in the same order in the array in which they were added to the list. */ | |||
3459 | while (nfields-- > 0) | |||
3460 | { | |||
3461 | TYPE_FIELD (type, nfields)(type)->main_type->fields[nfields] = fip->fields->field; | |||
3462 | switch (fip->fields->accessibility) | |||
3463 | { | |||
3464 | case DW_ACCESS_private: | |||
3465 | SET_TYPE_FIELD_PRIVATE (type, nfields)(((type)->main_type->type_specific.cplus_stuff->private_field_bits )[((nfields))>>3] |= (1 << (((nfields))&7))); | |||
3466 | break; | |||
3467 | ||||
3468 | case DW_ACCESS_protected: | |||
3469 | SET_TYPE_FIELD_PROTECTED (type, nfields)(((type)->main_type->type_specific.cplus_stuff->protected_field_bits )[((nfields))>>3] |= (1 << (((nfields))&7))); | |||
3470 | break; | |||
3471 | ||||
3472 | case DW_ACCESS_public: | |||
3473 | break; | |||
3474 | ||||
3475 | default: | |||
3476 | /* Unknown accessibility. Complain and treat it as public. */ | |||
3477 | { | |||
3478 | complaint (&symfile_complaints, "unsupported accessibility %d", | |||
3479 | fip->fields->accessibility); | |||
3480 | } | |||
3481 | break; | |||
3482 | } | |||
3483 | if (nfields < fip->nbaseclasses) | |||
3484 | { | |||
3485 | switch (fip->fields->virtuality) | |||
3486 | { | |||
3487 | case DW_VIRTUALITY_virtual: | |||
3488 | case DW_VIRTUALITY_pure_virtual: | |||
3489 | SET_TYPE_FIELD_VIRTUAL (type, nfields)(((type)->main_type->type_specific.cplus_stuff->virtual_field_bits )[((nfields))>>3] |= (1 << (((nfields))&7))); | |||
3490 | break; | |||
3491 | } | |||
3492 | } | |||
3493 | fip->fields = fip->fields->next; | |||
3494 | } | |||
3495 | } | |||
3496 | ||||
3497 | /* Add a member function to the proper fieldlist. */ | |||
3498 | ||||
3499 | static void | |||
3500 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, | |||
3501 | struct type *type, struct dwarf2_cu *cu) | |||
3502 | { | |||
3503 | struct objfile *objfile = cu->objfile; | |||
3504 | struct attribute *attr; | |||
3505 | struct fnfieldlist *flp; | |||
3506 | int i; | |||
3507 | struct fn_field *fnp; | |||
3508 | char *fieldname; | |||
3509 | char *physname; | |||
3510 | struct nextfnfield *new_fnfield; | |||
3511 | ||||
3512 | /* Get name of member function. */ | |||
3513 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
3514 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
3515 | fieldname = DW_STRING (attr)((attr)->u.str); | |||
3516 | else | |||
3517 | return; | |||
3518 | ||||
3519 | /* Get the mangled name. */ | |||
3520 | physname = dwarf2_linkage_name (die, cu); | |||
3521 | ||||
3522 | /* Look up member function name in fieldlist. */ | |||
3523 | for (i = 0; i < fip->nfnfields; i++) | |||
3524 | { | |||
3525 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) | |||
3526 | break; | |||
3527 | } | |||
3528 | ||||
3529 | /* Create new list element if necessary. */ | |||
3530 | if (i < fip->nfnfields) | |||
3531 | flp = &fip->fnfieldlists[i]; | |||
3532 | else | |||
3533 | { | |||
3534 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK4) == 0) | |||
3535 | { | |||
3536 | fip->fnfieldlists = (struct fnfieldlist *) | |||
3537 | xrealloc (fip->fnfieldlists, | |||
3538 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK4) | |||
3539 | * sizeof (struct fnfieldlist)); | |||
3540 | if (fip->nfnfields == 0) | |||
3541 | make_cleanup (free_current_contents, &fip->fnfieldlists); | |||
3542 | } | |||
3543 | flp = &fip->fnfieldlists[fip->nfnfields]; | |||
3544 | flp->name = fieldname; | |||
3545 | flp->length = 0; | |||
3546 | flp->head = NULL((void*)0); | |||
3547 | fip->nfnfields++; | |||
3548 | } | |||
3549 | ||||
3550 | /* Create a new member function field and chain it to the field list | |||
3551 | entry. */ | |||
3552 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); | |||
3553 | make_cleanup (xfree, new_fnfield); | |||
3554 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); | |||
3555 | new_fnfield->next = flp->head; | |||
3556 | flp->head = new_fnfield; | |||
3557 | flp->length++; | |||
3558 | ||||
3559 | /* Fill in the member function field info. */ | |||
3560 | fnp = &new_fnfield->fnfield; | |||
3561 | /* The name is already allocated along with this objfile, so we don't | |||
3562 | need to duplicate it for the type. */ | |||
3563 | fnp->physname = physname ? physname : ""; | |||
3564 | fnp->type = alloc_type (objfile); | |||
3565 | if (die->type && TYPE_CODE (die->type)(die->type)->main_type->code == TYPE_CODE_FUNC) | |||
3566 | { | |||
3567 | int nparams = TYPE_NFIELDS (die->type)(die->type)->main_type->nfields; | |||
3568 | ||||
3569 | /* TYPE is the domain of this method, and DIE->TYPE is the type | |||
3570 | of the method itself (TYPE_CODE_METHOD). */ | |||
3571 | smash_to_method_type (fnp->type, type, | |||
3572 | TYPE_TARGET_TYPE (die->type)(die->type)->main_type->target_type, | |||
3573 | TYPE_FIELDS (die->type)(die->type)->main_type->fields, | |||
3574 | TYPE_NFIELDS (die->type)(die->type)->main_type->nfields, | |||
3575 | TYPE_VARARGS (die->type)((die->type)->main_type->flags & (1 << 11) )); | |||
3576 | ||||
3577 | /* Handle static member functions. | |||
3578 | Dwarf2 has no clean way to discern C++ static and non-static | |||
3579 | member functions. G++ helps GDB by marking the first | |||
3580 | parameter for non-static member functions (which is the | |||
3581 | this pointer) as artificial. We obtain this information | |||
3582 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ | |||
3583 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0)(((die->type)->main_type->fields[0]).artificial) == 0) | |||
3584 | fnp->voffset = VOFFSET_STATIC1; | |||
3585 | } | |||
3586 | else | |||
3587 | complaint (&symfile_complaints, "member function type missing for '%s'", | |||
3588 | physname); | |||
3589 | ||||
3590 | /* Get fcontext from DW_AT_containing_type if present. */ | |||
3591 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL((void*)0)) | |||
3592 | fnp->fcontext = die_containing_type (die, cu); | |||
3593 | ||||
3594 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const | |||
3595 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ | |||
3596 | ||||
3597 | /* Get accessibility. */ | |||
3598 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); | |||
3599 | if (attr) | |||
3600 | { | |||
3601 | switch (DW_UNSND (attr)((attr)->u.unsnd)) | |||
3602 | { | |||
3603 | case DW_ACCESS_private: | |||
3604 | fnp->is_private = 1; | |||
3605 | break; | |||
3606 | case DW_ACCESS_protected: | |||
3607 | fnp->is_protected = 1; | |||
3608 | break; | |||
3609 | } | |||
3610 | } | |||
3611 | ||||
3612 | /* Check for artificial methods. */ | |||
3613 | attr = dwarf2_attr (die, DW_AT_artificial, cu); | |||
3614 | if (attr && DW_UNSND (attr)((attr)->u.unsnd) != 0) | |||
3615 | fnp->is_artificial = 1; | |||
3616 | ||||
3617 | /* Get index in virtual function table if it is a virtual member function. */ | |||
3618 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); | |||
3619 | if (attr) | |||
3620 | { | |||
3621 | /* Support the .debug_loc offsets */ | |||
3622 | if (attr_form_is_block (attr)) | |||
3623 | { | |||
3624 | fnp->voffset = decode_locdesc (DW_BLOCK (attr)((attr)->u.blk), cu) + 2; | |||
3625 | } | |||
3626 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |||
3627 | { | |||
3628 | dwarf2_complex_location_expr_complaint (); | |||
3629 | } | |||
3630 | else | |||
3631 | { | |||
3632 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", | |||
3633 | fieldname); | |||
3634 | } | |||
3635 | } | |||
3636 | } | |||
3637 | ||||
3638 | /* Create the vector of member function fields, and attach it to the type. */ | |||
3639 | ||||
3640 | static void | |||
3641 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, | |||
3642 | struct dwarf2_cu *cu) | |||
3643 | { | |||
3644 | struct fnfieldlist *flp; | |||
3645 | int total_length = 0; | |||
3646 | int i; | |||
3647 | ||||
3648 | ALLOCATE_CPLUS_STRUCT_TYPE (type)allocate_cplus_struct_type (type); | |||
3649 | TYPE_FN_FIELDLISTS (type)(type)->main_type->type_specific.cplus_stuff->fn_fieldlists = (struct fn_fieldlist *) | |||
3650 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields)((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((sizeof (struct fn_fieldlist) * fip-> nfnfields)); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char * ) 0)+__o1->alignment_mask) & ~ (__o1->alignment_mask )) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1-> next_free = __o1->chunk_limit; __o1->object_base = __o1 ->next_free; value; }); }) : xmalloc (sizeof (struct fn_fieldlist ) * fip->nfnfields)); | |||
3651 | ||||
3652 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) | |||
3653 | { | |||
3654 | struct nextfnfield *nfp = flp->head; | |||
3655 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i)(type)->main_type->type_specific.cplus_stuff->fn_fieldlists [i]; | |||
3656 | int k; | |||
3657 | ||||
3658 | TYPE_FN_FIELDLIST_NAME (type, i)(type)->main_type->type_specific.cplus_stuff->fn_fieldlists [i].name = flp->name; | |||
3659 | TYPE_FN_FIELDLIST_LENGTH (type, i)(type)->main_type->type_specific.cplus_stuff->fn_fieldlists [i].length = flp->length; | |||
3660 | fn_flp->fn_fields = (struct fn_field *) | |||
3661 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length)((type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(type)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((sizeof (struct fn_field) * flp->length )); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (sizeof (struct fn_field) * flp->length)); | |||
3662 | for (k = flp->length; (k--, nfp); nfp = nfp->next) | |||
3663 | fn_flp->fn_fields[k] = nfp->fnfield; | |||
3664 | ||||
3665 | total_length += flp->length; | |||
3666 | } | |||
3667 | ||||
3668 | TYPE_NFN_FIELDS (type)(type)->main_type->type_specific.cplus_stuff->nfn_fields = fip->nfnfields; | |||
3669 | TYPE_NFN_FIELDS_TOTAL (type)(type)->main_type->type_specific.cplus_stuff->nfn_fields_total = total_length; | |||
3670 | } | |||
3671 | ||||
3672 | ||||
3673 | /* Returns non-zero if NAME is the name of a vtable member in CU's | |||
3674 | language, zero otherwise. */ | |||
3675 | static int | |||
3676 | is_vtable_name (const char *name, struct dwarf2_cu *cu) | |||
3677 | { | |||
3678 | static const char vptr[] = "_vptr"; | |||
3679 | static const char vtable[] = "vtable"; | |||
3680 | ||||
3681 | /* Look for the C++ and Java forms of the vtable. */ | |||
3682 | if ((cu->language == language_java | |||
3683 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) | |||
3684 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 | |||
3685 | && is_cplus_marker (name[sizeof (vptr) - 1]))) | |||
3686 | return 1; | |||
3687 | ||||
3688 | return 0; | |||
3689 | } | |||
3690 | ||||
3691 | ||||
3692 | /* Called when we find the DIE that starts a structure or union scope | |||
3693 | (definition) to process all dies that define the members of the | |||
3694 | structure or union. | |||
3695 | ||||
3696 | NOTE: we need to call struct_type regardless of whether or not the | |||
3697 | DIE has an at_name attribute, since it might be an anonymous | |||
3698 | structure or union. This gets the type entered into our set of | |||
3699 | user defined types. | |||
3700 | ||||
3701 | However, if the structure is incomplete (an opaque struct/union) | |||
3702 | then suppress creating a symbol table entry for it since gdb only | |||
3703 | wants to find the one with the complete definition. Note that if | |||
3704 | it is complete, we just call new_symbol, which does it's own | |||
3705 | checking about whether the struct/union is anonymous or not (and | |||
3706 | suppresses creating a symbol table entry itself). */ | |||
3707 | ||||
3708 | static void | |||
3709 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) | |||
3710 | { | |||
3711 | struct objfile *objfile = cu->objfile; | |||
3712 | struct type *type; | |||
3713 | struct attribute *attr; | |||
3714 | const char *previous_prefix = processing_current_prefix; | |||
3715 | struct cleanup *back_to = NULL((void*)0); | |||
3716 | ||||
3717 | if (die->type) | |||
3718 | return; | |||
3719 | ||||
3720 | type = alloc_type (objfile); | |||
3721 | ||||
3722 | INIT_CPLUS_SPECIFIC (type)((type)->main_type->type_specific.cplus_stuff=(struct cplus_struct_type *)&cplus_struct_default); | |||
3723 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
3724 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
3725 | { | |||
3726 | if (cu->language == language_cplus | |||
3727 | || cu->language == language_java) | |||
3728 | { | |||
3729 | char *new_prefix = determine_class_name (die, cu); | |||
3730 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = obsavestring (new_prefix, | |||
3731 | strlen (new_prefix), | |||
3732 | &objfile->objfile_obstack); | |||
3733 | back_to = make_cleanup (xfree, new_prefix); | |||
3734 | processing_current_prefix = new_prefix; | |||
3735 | } | |||
3736 | else | |||
3737 | { | |||
3738 | /* The name is already allocated along with this objfile, so | |||
3739 | we don't need to duplicate it for the type. */ | |||
3740 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = DW_STRING (attr)((attr)->u.str); | |||
3741 | } | |||
3742 | } | |||
3743 | ||||
3744 | if (die->tag == DW_TAG_structure_type) | |||
3745 | { | |||
3746 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE_STRUCT; | |||
3747 | } | |||
3748 | else if (die->tag == DW_TAG_union_type) | |||
3749 | { | |||
3750 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE_UNION; | |||
3751 | } | |||
3752 | else | |||
3753 | { | |||
3754 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT | |||
3755 | in gdbtypes.h. */ | |||
3756 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE_CLASSTYPE_CODE_STRUCT; | |||
3757 | } | |||
3758 | ||||
3759 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
3760 | if (attr) | |||
3761 | { | |||
3762 | TYPE_LENGTH (type)(type)->length = DW_UNSND (attr)((attr)->u.unsnd); | |||
3763 | } | |||
3764 | else | |||
3765 | { | |||
3766 | TYPE_LENGTH (type)(type)->length = 0; | |||
3767 | } | |||
3768 | ||||
3769 | if (die_is_declaration (die, cu)) | |||
3770 | TYPE_FLAGS (type)(type)->main_type->flags |= TYPE_FLAG_STUB(1 << 2); | |||
3771 | ||||
3772 | /* We need to add the type field to the die immediately so we don't | |||
3773 | infinitely recurse when dealing with pointers to the structure | |||
3774 | type within the structure itself. */ | |||
3775 | set_die_type (die, type, cu); | |||
3776 | ||||
3777 | if (die->child != NULL((void*)0) && ! die_is_declaration (die, cu)) | |||
3778 | { | |||
3779 | struct field_info fi; | |||
3780 | struct die_info *child_die; | |||
3781 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL((void*)0)); | |||
3782 | ||||
3783 | memset (&fi, 0, sizeof (struct field_info)); | |||
3784 | ||||
3785 | child_die = die->child; | |||
3786 | ||||
3787 | while (child_die && child_die->tag) | |||
3788 | { | |||
3789 | if (child_die->tag == DW_TAG_member | |||
3790 | || child_die->tag == DW_TAG_variable) | |||
3791 | { | |||
3792 | /* NOTE: carlton/2002-11-05: A C++ static data member | |||
3793 | should be a DW_TAG_member that is a declaration, but | |||
3794 | all versions of G++ as of this writing (so through at | |||
3795 | least 3.2.1) incorrectly generate DW_TAG_variable | |||
3796 | tags for them instead. */ | |||
3797 | dwarf2_add_field (&fi, child_die, cu); | |||
3798 | } | |||
3799 | else if (child_die->tag == DW_TAG_subprogram) | |||
3800 | { | |||
3801 | /* C++ member function. */ | |||
3802 | read_type_die (child_die, cu); | |||
3803 | dwarf2_add_member_fn (&fi, child_die, type, cu); | |||
3804 | } | |||
3805 | else if (child_die->tag == DW_TAG_inheritance) | |||
3806 | { | |||
3807 | /* C++ base class field. */ | |||
3808 | dwarf2_add_field (&fi, child_die, cu); | |||
3809 | } | |||
3810 | child_die = sibling_die (child_die); | |||
3811 | } | |||
3812 | ||||
3813 | /* Attach fields and member functions to the type. */ | |||
3814 | if (fi.nfields) | |||
3815 | dwarf2_attach_fields_to_type (&fi, type, cu); | |||
3816 | if (fi.nfnfields) | |||
3817 | { | |||
3818 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); | |||
3819 | ||||
3820 | /* Get the type which refers to the base class (possibly this | |||
3821 | class itself) which contains the vtable pointer for the current | |||
3822 | class from the DW_AT_containing_type attribute. */ | |||
3823 | ||||
3824 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL((void*)0)) | |||
3825 | { | |||
3826 | struct type *t = die_containing_type (die, cu); | |||
3827 | ||||
3828 | TYPE_VPTR_BASETYPE (type)(type)->main_type->vptr_basetype = t; | |||
3829 | if (type == t) | |||
3830 | { | |||
3831 | int i; | |||
3832 | ||||
3833 | /* Our own class provides vtbl ptr. */ | |||
3834 | for (i = TYPE_NFIELDS (t)(t)->main_type->nfields - 1; | |||
3835 | i >= TYPE_N_BASECLASSES (t)(t)->main_type->type_specific.cplus_stuff->n_baseclasses; | |||
3836 | --i) | |||
3837 | { | |||
3838 | char *fieldname = TYPE_FIELD_NAME (t, i)(((t)->main_type->fields[i]).name); | |||
3839 | ||||
3840 | if (is_vtable_name (fieldname, cu)) | |||
3841 | { | |||
3842 | TYPE_VPTR_FIELDNO (type)(type)->main_type->vptr_fieldno = i; | |||
3843 | break; | |||
3844 | } | |||
3845 | } | |||
3846 | ||||
3847 | /* Complain if virtual function table field not found. */ | |||
3848 | if (i < TYPE_N_BASECLASSES (t)(t)->main_type->type_specific.cplus_stuff->n_baseclasses) | |||
3849 | complaint (&symfile_complaints, | |||
3850 | "virtual function table pointer not found when defining class '%s'", | |||
3851 | TYPE_TAG_NAME (type)(type)->main_type->tag_name ? TYPE_TAG_NAME (type)(type)->main_type->tag_name : | |||
3852 | ""); | |||
3853 | } | |||
3854 | else | |||
3855 | { | |||
3856 | TYPE_VPTR_FIELDNO (type)(type)->main_type->vptr_fieldno = TYPE_VPTR_FIELDNO (t)(t)->main_type->vptr_fieldno; | |||
3857 | } | |||
3858 | } | |||
3859 | } | |||
3860 | ||||
3861 | do_cleanups (back_to); | |||
3862 | } | |||
3863 | ||||
3864 | processing_current_prefix = previous_prefix; | |||
3865 | if (back_to != NULL((void*)0)) | |||
3866 | do_cleanups (back_to); | |||
3867 | } | |||
3868 | ||||
3869 | static void | |||
3870 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) | |||
3871 | { | |||
3872 | struct objfile *objfile = cu->objfile; | |||
3873 | const char *previous_prefix = processing_current_prefix; | |||
3874 | struct die_info *child_die = die->child; | |||
3875 | ||||
3876 | if (TYPE_TAG_NAME (die->type)(die->type)->main_type->tag_name != NULL((void*)0)) | |||
3877 | processing_current_prefix = TYPE_TAG_NAME (die->type)(die->type)->main_type->tag_name; | |||
3878 | ||||
3879 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its | |||
3880 | snapshots) has been known to create a die giving a declaration | |||
3881 | for a class that has, as a child, a die giving a definition for a | |||
3882 | nested class. So we have to process our children even if the | |||
3883 | current die is a declaration. Normally, of course, a declaration | |||
3884 | won't have any children at all. */ | |||
3885 | ||||
3886 | while (child_die != NULL((void*)0) && child_die->tag) | |||
3887 | { | |||
3888 | if (child_die->tag == DW_TAG_member | |||
3889 | || child_die->tag == DW_TAG_variable | |||
3890 | || child_die->tag == DW_TAG_inheritance) | |||
3891 | { | |||
3892 | /* Do nothing. */ | |||
3893 | } | |||
3894 | else | |||
3895 | process_die (child_die, cu); | |||
3896 | ||||
3897 | child_die = sibling_die (child_die); | |||
3898 | } | |||
3899 | ||||
3900 | if (die->child != NULL((void*)0) && ! die_is_declaration (die, cu)) | |||
3901 | new_symbol (die, die->type, cu); | |||
3902 | ||||
3903 | processing_current_prefix = previous_prefix; | |||
3904 | } | |||
3905 | ||||
3906 | /* Given a DW_AT_enumeration_type die, set its type. We do not | |||
3907 | complete the type's fields yet, or create any symbols. */ | |||
3908 | ||||
3909 | static void | |||
3910 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) | |||
3911 | { | |||
3912 | struct objfile *objfile = cu->objfile; | |||
3913 | struct type *type; | |||
3914 | struct attribute *attr; | |||
3915 | ||||
3916 | if (die->type) | |||
3917 | return; | |||
3918 | ||||
3919 | type = alloc_type (objfile); | |||
3920 | ||||
3921 | TYPE_CODE (type)(type)->main_type->code = TYPE_CODE_ENUM; | |||
3922 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
3923 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
3924 | { | |||
3925 | char *name = DW_STRING (attr)((attr)->u.str); | |||
3926 | ||||
3927 | if (processing_has_namespace_info) | |||
3928 | { | |||
3929 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = typename_concat (&objfile->objfile_obstack, | |||
3930 | processing_current_prefix, | |||
3931 | name, cu); | |||
3932 | } | |||
3933 | else | |||
3934 | { | |||
3935 | /* The name is already allocated along with this objfile, so | |||
3936 | we don't need to duplicate it for the type. */ | |||
3937 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = name; | |||
3938 | } | |||
3939 | } | |||
3940 | ||||
3941 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
3942 | if (attr) | |||
3943 | { | |||
3944 | TYPE_LENGTH (type)(type)->length = DW_UNSND (attr)((attr)->u.unsnd); | |||
3945 | } | |||
3946 | else | |||
3947 | { | |||
3948 | TYPE_LENGTH (type)(type)->length = 0; | |||
3949 | } | |||
3950 | ||||
3951 | set_die_type (die, type, cu); | |||
3952 | } | |||
3953 | ||||
3954 | /* Determine the name of the type represented by DIE, which should be | |||
3955 | a named C++ or Java compound type. Return the name in question; the caller | |||
3956 | is responsible for xfree()'ing it. */ | |||
3957 | ||||
3958 | static char * | |||
3959 | determine_class_name (struct die_info *die, struct dwarf2_cu *cu) | |||
3960 | { | |||
3961 | struct cleanup *back_to = NULL((void*)0); | |||
3962 | struct die_info *spec_die = die_specification (die, cu); | |||
3963 | char *new_prefix = NULL((void*)0); | |||
3964 | ||||
3965 | /* If this is the definition of a class that is declared by another | |||
3966 | die, then processing_current_prefix may not be accurate; see | |||
3967 | read_func_scope for a similar example. */ | |||
3968 | if (spec_die != NULL((void*)0)) | |||
3969 | { | |||
3970 | char *specification_prefix = determine_prefix (spec_die, cu); | |||
3971 | processing_current_prefix = specification_prefix; | |||
3972 | back_to = make_cleanup (xfree, specification_prefix); | |||
3973 | } | |||
3974 | ||||
3975 | /* If we don't have namespace debug info, guess the name by trying | |||
3976 | to demangle the names of members, just like we did in | |||
3977 | guess_structure_name. */ | |||
3978 | if (!processing_has_namespace_info) | |||
3979 | { | |||
3980 | struct die_info *child; | |||
3981 | ||||
3982 | for (child = die->child; | |||
3983 | child != NULL((void*)0) && child->tag != 0; | |||
3984 | child = sibling_die (child)) | |||
3985 | { | |||
3986 | if (child->tag == DW_TAG_subprogram) | |||
3987 | { | |||
3988 | new_prefix | |||
3989 | = language_class_name_from_physname (cu->language_defn, | |||
3990 | dwarf2_linkage_name | |||
3991 | (child, cu)); | |||
3992 | ||||
3993 | if (new_prefix != NULL((void*)0)) | |||
3994 | break; | |||
3995 | } | |||
3996 | } | |||
3997 | } | |||
3998 | ||||
3999 | if (new_prefix == NULL((void*)0)) | |||
4000 | { | |||
4001 | const char *name = dwarf2_name (die, cu); | |||
4002 | new_prefix = typename_concat (NULL((void*)0), processing_current_prefix, | |||
4003 | name ? name : "<<anonymous>>", | |||
4004 | cu); | |||
4005 | } | |||
4006 | ||||
4007 | if (back_to != NULL((void*)0)) | |||
4008 | do_cleanups (back_to); | |||
4009 | ||||
4010 | return new_prefix; | |||
4011 | } | |||
4012 | ||||
4013 | /* Given a pointer to a die which begins an enumeration, process all | |||
4014 | the dies that define the members of the enumeration, and create the | |||
4015 | symbol for the enumeration type. | |||
4016 | ||||
4017 | NOTE: We reverse the order of the element list. */ | |||
4018 | ||||
4019 | static void | |||
4020 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) | |||
4021 | { | |||
4022 | struct objfile *objfile = cu->objfile; | |||
4023 | struct die_info *child_die; | |||
4024 | struct field *fields; | |||
4025 | struct attribute *attr; | |||
4026 | struct symbol *sym; | |||
4027 | int num_fields; | |||
4028 | int unsigned_enum = 1; | |||
4029 | ||||
4030 | num_fields = 0; | |||
4031 | fields = NULL((void*)0); | |||
4032 | if (die->child != NULL((void*)0)) | |||
4033 | { | |||
4034 | child_die = die->child; | |||
4035 | while (child_die && child_die->tag) | |||
4036 | { | |||
4037 | if (child_die->tag != DW_TAG_enumerator) | |||
4038 | { | |||
4039 | process_die (child_die, cu); | |||
4040 | } | |||
4041 | else | |||
4042 | { | |||
4043 | attr = dwarf2_attr (child_die, DW_AT_name, cu); | |||
4044 | if (attr) | |||
4045 | { | |||
4046 | sym = new_symbol (child_die, die->type, cu); | |||
4047 | if (SYMBOL_VALUE (sym)(sym)->ginfo.value.ivalue < 0) | |||
4048 | unsigned_enum = 0; | |||
4049 | ||||
4050 | if ((num_fields % DW_FIELD_ALLOC_CHUNK4) == 0) | |||
4051 | { | |||
4052 | fields = (struct field *) | |||
4053 | xrealloc (fields, | |||
4054 | (num_fields + DW_FIELD_ALLOC_CHUNK4) | |||
4055 | * sizeof (struct field)); | |||
4056 | } | |||
4057 | ||||
4058 | FIELD_NAME (fields[num_fields])((fields[num_fields]).name) = DEPRECATED_SYMBOL_NAME (sym)(sym)->ginfo.name; | |||
4059 | FIELD_TYPE (fields[num_fields])((fields[num_fields]).type) = NULL((void*)0); | |||
4060 | FIELD_BITPOS (fields[num_fields])((fields[num_fields]).loc.bitpos) = SYMBOL_VALUE (sym)(sym)->ginfo.value.ivalue; | |||
4061 | FIELD_BITSIZE (fields[num_fields])((fields[num_fields]).bitsize) = 0; | |||
4062 | FIELD_STATIC_KIND (fields[num_fields])((fields[num_fields]).static_kind) = 0; | |||
4063 | ||||
4064 | num_fields++; | |||
4065 | } | |||
4066 | } | |||
4067 | ||||
4068 | child_die = sibling_die (child_die); | |||
4069 | } | |||
4070 | ||||
4071 | if (num_fields) | |||
4072 | { | |||
4073 | TYPE_NFIELDS (die->type)(die->type)->main_type->nfields = num_fields; | |||
4074 | TYPE_FIELDS (die->type)(die->type)->main_type->fields = (struct field *) | |||
4075 | TYPE_ALLOC (die->type, sizeof (struct field) * num_fields)((die->type)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(die->type)->main_type-> objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((sizeof (struct field) * num_fields )); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (sizeof (struct field) * num_fields)); | |||
4076 | memcpy (TYPE_FIELDS (die->type)(die->type)->main_type->fields, fields, | |||
4077 | sizeof (struct field) * num_fields); | |||
4078 | xfree (fields); | |||
4079 | } | |||
4080 | if (unsigned_enum) | |||
4081 | TYPE_FLAGS (die->type)(die->type)->main_type->flags |= TYPE_FLAG_UNSIGNED(1 << 0); | |||
4082 | } | |||
4083 | ||||
4084 | new_symbol (die, die->type, cu); | |||
4085 | } | |||
4086 | ||||
4087 | /* Extract all information from a DW_TAG_array_type DIE and put it in | |||
4088 | the DIE's type field. For now, this only handles one dimensional | |||
4089 | arrays. */ | |||
4090 | ||||
4091 | static void | |||
4092 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4093 | { | |||
4094 | struct objfile *objfile = cu->objfile; | |||
4095 | struct die_info *child_die; | |||
4096 | struct type *type = NULL((void*)0); | |||
4097 | struct type *element_type, *range_type, *index_type; | |||
4098 | struct type **range_types = NULL((void*)0); | |||
4099 | struct attribute *attr; | |||
4100 | int ndim = 0; | |||
4101 | struct cleanup *back_to; | |||
4102 | ||||
4103 | /* Return if we've already decoded this type. */ | |||
4104 | if (die->type) | |||
4105 | { | |||
4106 | return; | |||
4107 | } | |||
4108 | ||||
4109 | element_type = die_type (die, cu); | |||
4110 | ||||
4111 | /* Irix 6.2 native cc creates array types without children for | |||
4112 | arrays with unspecified length. */ | |||
4113 | if (die->child == NULL((void*)0)) | |||
4114 | { | |||
4115 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER8, cu); | |||
4116 | range_type = create_range_type (NULL((void*)0), index_type, 0, -1); | |||
4117 | set_die_type (die, create_array_type (NULL((void*)0), element_type, range_type), | |||
4118 | cu); | |||
4119 | return; | |||
4120 | } | |||
4121 | ||||
4122 | back_to = make_cleanup (null_cleanup, NULL((void*)0)); | |||
4123 | child_die = die->child; | |||
4124 | while (child_die && child_die->tag) | |||
4125 | { | |||
4126 | if (child_die->tag == DW_TAG_subrange_type) | |||
4127 | { | |||
4128 | read_subrange_type (child_die, cu); | |||
4129 | ||||
4130 | if (child_die->type != NULL((void*)0)) | |||
4131 | { | |||
4132 | /* The range type was succesfully read. Save it for | |||
4133 | the array type creation. */ | |||
4134 | if ((ndim % DW_FIELD_ALLOC_CHUNK4) == 0) | |||
4135 | { | |||
4136 | range_types = (struct type **) | |||
4137 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK4) | |||
4138 | * sizeof (struct type *)); | |||
4139 | if (ndim == 0) | |||
4140 | make_cleanup (free_current_contents, &range_types); | |||
4141 | } | |||
4142 | range_types[ndim++] = child_die->type; | |||
4143 | } | |||
4144 | } | |||
4145 | child_die = sibling_die (child_die); | |||
4146 | } | |||
4147 | ||||
4148 | /* Dwarf2 dimensions are output from left to right, create the | |||
4149 | necessary array types in backwards order. */ | |||
4150 | ||||
4151 | type = element_type; | |||
4152 | ||||
4153 | if (read_array_order (die, cu) == DW_ORD_col_major) | |||
4154 | { | |||
4155 | int i = 0; | |||
4156 | while (i < ndim) | |||
4157 | type = create_array_type (NULL((void*)0), type, range_types[i++]); | |||
4158 | } | |||
4159 | else | |||
4160 | { | |||
4161 | while (ndim-- > 0) | |||
4162 | type = create_array_type (NULL((void*)0), type, range_types[ndim]); | |||
4163 | } | |||
4164 | ||||
4165 | /* Understand Dwarf2 support for vector types (like they occur on | |||
4166 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the | |||
4167 | array type. This is not part of the Dwarf2/3 standard yet, but a | |||
4168 | custom vendor extension. The main difference between a regular | |||
4169 | array and the vector variant is that vectors are passed by value | |||
4170 | to functions. */ | |||
4171 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); | |||
4172 | if (attr) | |||
4173 | TYPE_FLAGS (type)(type)->main_type->flags |= TYPE_FLAG_VECTOR(1 << 12); | |||
4174 | ||||
4175 | do_cleanups (back_to); | |||
4176 | ||||
4177 | /* Install the type in the die. */ | |||
4178 | set_die_type (die, type, cu); | |||
4179 | } | |||
4180 | ||||
4181 | static enum dwarf_array_dim_ordering | |||
4182 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) | |||
4183 | { | |||
4184 | struct attribute *attr; | |||
4185 | ||||
4186 | attr = dwarf2_attr (die, DW_AT_ordering, cu); | |||
4187 | ||||
4188 | if (attr) return DW_SND (attr)((attr)->u.snd); | |||
4189 | ||||
4190 | /* | |||
4191 | GNU F77 is a special case, as at 08/2004 array type info is the | |||
4192 | opposite order to the dwarf2 specification, but data is still | |||
4193 | laid out as per normal fortran. | |||
4194 | ||||
4195 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need | |||
4196 | version checking. | |||
4197 | */ | |||
4198 | ||||
4199 | if (cu->language == language_fortran && | |||
4200 | cu->producer && strstr (cu->producer, "GNU F77")) | |||
4201 | { | |||
4202 | return DW_ORD_row_major; | |||
4203 | } | |||
4204 | ||||
4205 | switch (cu->language_defn->la_array_ordering) | |||
4206 | { | |||
4207 | case array_column_major: | |||
4208 | return DW_ORD_col_major; | |||
4209 | case array_row_major: | |||
4210 | default: | |||
4211 | return DW_ORD_row_major; | |||
4212 | }; | |||
4213 | } | |||
4214 | ||||
4215 | ||||
4216 | /* First cut: install each common block member as a global variable. */ | |||
4217 | ||||
4218 | static void | |||
4219 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) | |||
4220 | { | |||
4221 | struct die_info *child_die; | |||
4222 | struct attribute *attr; | |||
4223 | struct symbol *sym; | |||
4224 | CORE_ADDR base = (CORE_ADDR) 0; | |||
4225 | ||||
4226 | attr = dwarf2_attr (die, DW_AT_location, cu); | |||
4227 | if (attr) | |||
4228 | { | |||
4229 | /* Support the .debug_loc offsets */ | |||
4230 | if (attr_form_is_block (attr)) | |||
4231 | { | |||
4232 | base = decode_locdesc (DW_BLOCK (attr)((attr)->u.blk), cu); | |||
4233 | } | |||
4234 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) | |||
4235 | { | |||
4236 | dwarf2_complex_location_expr_complaint (); | |||
4237 | } | |||
4238 | else | |||
4239 | { | |||
4240 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", | |||
4241 | "common block member"); | |||
4242 | } | |||
4243 | } | |||
4244 | if (die->child != NULL((void*)0)) | |||
4245 | { | |||
4246 | child_die = die->child; | |||
4247 | while (child_die && child_die->tag) | |||
4248 | { | |||
4249 | sym = new_symbol (child_die, NULL((void*)0), cu); | |||
4250 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); | |||
4251 | if (attr) | |||
4252 | { | |||
4253 | SYMBOL_VALUE_ADDRESS (sym)(sym)->ginfo.value.address = | |||
4254 | base + decode_locdesc (DW_BLOCK (attr)((attr)->u.blk), cu); | |||
4255 | add_symbol_to_list (sym, &global_symbols); | |||
4256 | } | |||
4257 | child_die = sibling_die (child_die); | |||
4258 | } | |||
4259 | } | |||
4260 | } | |||
4261 | ||||
4262 | /* Read a C++ namespace. */ | |||
4263 | ||||
4264 | static void | |||
4265 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) | |||
4266 | { | |||
4267 | struct objfile *objfile = cu->objfile; | |||
4268 | const char *previous_prefix = processing_current_prefix; | |||
4269 | const char *name; | |||
4270 | int is_anonymous; | |||
4271 | struct die_info *current_die; | |||
4272 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); | |||
4273 | ||||
4274 | name = namespace_name (die, &is_anonymous, cu); | |||
4275 | ||||
4276 | /* Now build the name of the current namespace. */ | |||
4277 | ||||
4278 | if (previous_prefix[0] == '\0') | |||
| ||||
4279 | { | |||
4280 | processing_current_prefix = name; | |||
4281 | } | |||
4282 | else | |||
4283 | { | |||
4284 | char *temp_name = typename_concat (NULL((void*)0), previous_prefix, name, cu); | |||
4285 | make_cleanup (xfree, temp_name); | |||
4286 | processing_current_prefix = temp_name; | |||
4287 | } | |||
4288 | ||||
4289 | /* Add a symbol associated to this if we haven't seen the namespace | |||
4290 | before. Also, add a using directive if it's an anonymous | |||
4291 | namespace. */ | |||
4292 | ||||
4293 | if (dwarf2_extension (die, cu) == NULL((void*)0)) | |||
4294 | { | |||
4295 | struct type *type; | |||
4296 | ||||
4297 | /* FIXME: carlton/2003-06-27: Once GDB is more const-correct, | |||
4298 | this cast will hopefully become unnecessary. */ | |||
4299 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, | |||
4300 | (char *) processing_current_prefix, | |||
4301 | objfile); | |||
4302 | TYPE_TAG_NAME (type)(type)->main_type->tag_name = TYPE_NAME (type)(type)->main_type->name; | |||
4303 | ||||
4304 | new_symbol (die, type, cu); | |||
4305 | set_die_type (die, type, cu); | |||
4306 | ||||
4307 | if (is_anonymous
| |||
4308 | cp_add_using_directive (processing_current_prefix, | |||
4309 | strlen (previous_prefix), | |||
4310 | strlen (processing_current_prefix)); | |||
4311 | } | |||
4312 | ||||
4313 | if (die->child != NULL((void*)0)) | |||
4314 | { | |||
4315 | struct die_info *child_die = die->child; | |||
4316 | ||||
4317 | while (child_die
| |||
4318 | { | |||
4319 | process_die (child_die, cu); | |||
4320 | child_die = sibling_die (child_die); | |||
4321 | } | |||
4322 | } | |||
4323 | ||||
4324 | processing_current_prefix = previous_prefix; | |||
4325 | do_cleanups (back_to); | |||
4326 | } | |||
4327 | ||||
4328 | /* Return the name of the namespace represented by DIE. Set | |||
4329 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous | |||
4330 | namespace. */ | |||
4331 | ||||
4332 | static const char * | |||
4333 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) | |||
4334 | { | |||
4335 | struct die_info *current_die; | |||
4336 | const char *name = NULL((void*)0); | |||
4337 | ||||
4338 | /* Loop through the extensions until we find a name. */ | |||
4339 | ||||
4340 | for (current_die = die; | |||
4341 | current_die != NULL((void*)0); | |||
4342 | current_die = dwarf2_extension (die, cu)) | |||
4343 | { | |||
4344 | name = dwarf2_name (current_die, cu); | |||
4345 | if (name != NULL((void*)0)) | |||
4346 | break; | |||
4347 | } | |||
4348 | ||||
4349 | /* Is it an anonymous namespace? */ | |||
4350 | ||||
4351 | *is_anonymous = (name == NULL((void*)0)); | |||
4352 | if (*is_anonymous) | |||
4353 | name = "(anonymous namespace)"; | |||
4354 | ||||
4355 | return name; | |||
4356 | } | |||
4357 | ||||
4358 | /* Extract all information from a DW_TAG_pointer_type DIE and add to | |||
4359 | the user defined type vector. */ | |||
4360 | ||||
4361 | static void | |||
4362 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4363 | { | |||
4364 | struct comp_unit_head *cu_header = &cu->header; | |||
4365 | struct type *type; | |||
4366 | struct attribute *attr_byte_size; | |||
4367 | struct attribute *attr_address_class; | |||
4368 | int byte_size, addr_class; | |||
4369 | ||||
4370 | if (die->type) | |||
4371 | { | |||
4372 | return; | |||
4373 | } | |||
4374 | ||||
4375 | type = lookup_pointer_type (die_type (die, cu)); | |||
4376 | ||||
4377 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
4378 | if (attr_byte_size) | |||
4379 | byte_size = DW_UNSND (attr_byte_size)((attr_byte_size)->u.unsnd); | |||
4380 | else | |||
4381 | byte_size = cu_header->addr_size; | |||
4382 | ||||
4383 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); | |||
4384 | if (attr_address_class) | |||
4385 | addr_class = DW_UNSND (attr_address_class)((attr_address_class)->u.unsnd); | |||
4386 | else | |||
4387 | addr_class = DW_ADDR_none0; | |||
4388 | ||||
4389 | /* If the pointer size or address class is different than the | |||
4390 | default, create a type variant marked as such and set the | |||
4391 | length accordingly. */ | |||
4392 | if (TYPE_LENGTH (type)(type)->length != byte_size || addr_class != DW_ADDR_none0) | |||
4393 | { | |||
4394 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()(gdbarch_address_class_type_flags_p (current_gdbarch))) | |||
4395 | { | |||
4396 | int type_flags; | |||
4397 | ||||
4398 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class)(gdbarch_address_class_type_flags (current_gdbarch, byte_size , addr_class)); | |||
4399 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0)((void) (((type_flags & ~((1 << 13) | (1 << 14 ))) == 0) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 4399, "%s: Assertion `%s' failed.", __PRETTY_FUNCTION__, "(type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0" ), 0))); | |||
4400 | type = make_type_with_address_space (type, type_flags); | |||
4401 | } | |||
4402 | else if (TYPE_LENGTH (type)(type)->length != byte_size) | |||
4403 | { | |||
4404 | complaint (&symfile_complaints, "invalid pointer size %d", byte_size); | |||
4405 | } | |||
4406 | else { | |||
4407 | /* Should we also complain about unhandled address classes? */ | |||
4408 | } | |||
4409 | } | |||
4410 | ||||
4411 | TYPE_LENGTH (type)(type)->length = byte_size; | |||
4412 | set_die_type (die, type, cu); | |||
4413 | } | |||
4414 | ||||
4415 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to | |||
4416 | the user defined type vector. */ | |||
4417 | ||||
4418 | static void | |||
4419 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4420 | { | |||
4421 | struct objfile *objfile = cu->objfile; | |||
4422 | struct type *type; | |||
4423 | struct type *to_type; | |||
4424 | struct type *domain; | |||
4425 | ||||
4426 | if (die->type) | |||
4427 | { | |||
4428 | return; | |||
4429 | } | |||
4430 | ||||
4431 | type = alloc_type (objfile); | |||
4432 | to_type = die_type (die, cu); | |||
4433 | domain = die_containing_type (die, cu); | |||
4434 | smash_to_member_type (type, domain, to_type); | |||
4435 | ||||
4436 | set_die_type (die, type, cu); | |||
4437 | } | |||
4438 | ||||
4439 | /* Extract all information from a DW_TAG_reference_type DIE and add to | |||
4440 | the user defined type vector. */ | |||
4441 | ||||
4442 | static void | |||
4443 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4444 | { | |||
4445 | struct comp_unit_head *cu_header = &cu->header; | |||
4446 | struct type *type; | |||
4447 | struct attribute *attr; | |||
4448 | ||||
4449 | if (die->type) | |||
4450 | { | |||
4451 | return; | |||
4452 | } | |||
4453 | ||||
4454 | type = lookup_reference_type (die_type (die, cu)); | |||
4455 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
4456 | if (attr) | |||
4457 | { | |||
4458 | TYPE_LENGTH (type)(type)->length = DW_UNSND (attr)((attr)->u.unsnd); | |||
4459 | } | |||
4460 | else | |||
4461 | { | |||
4462 | TYPE_LENGTH (type)(type)->length = cu_header->addr_size; | |||
4463 | } | |||
4464 | set_die_type (die, type, cu); | |||
4465 | } | |||
4466 | ||||
4467 | static void | |||
4468 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4469 | { | |||
4470 | struct type *base_type; | |||
4471 | ||||
4472 | if (die->type) | |||
4473 | { | |||
4474 | return; | |||
4475 | } | |||
4476 | ||||
4477 | base_type = die_type (die, cu); | |||
4478 | set_die_type (die, make_cv_type (1, TYPE_VOLATILE (base_type)((base_type)->instance_flags & (1 << 6)), base_type, 0), | |||
4479 | cu); | |||
4480 | } | |||
4481 | ||||
4482 | static void | |||
4483 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4484 | { | |||
4485 | struct type *base_type; | |||
4486 | ||||
4487 | if (die->type) | |||
4488 | { | |||
4489 | return; | |||
4490 | } | |||
4491 | ||||
4492 | base_type = die_type (die, cu); | |||
4493 | set_die_type (die, make_cv_type (TYPE_CONST (base_type)((base_type)->instance_flags & (1 << 5)), 1, base_type, 0), | |||
4494 | cu); | |||
4495 | } | |||
4496 | ||||
4497 | /* Extract all information from a DW_TAG_string_type DIE and add to | |||
4498 | the user defined type vector. It isn't really a user defined type, | |||
4499 | but it behaves like one, with other DIE's using an AT_user_def_type | |||
4500 | attribute to reference it. */ | |||
4501 | ||||
4502 | static void | |||
4503 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4504 | { | |||
4505 | struct objfile *objfile = cu->objfile; | |||
4506 | struct type *type, *range_type, *index_type, *char_type; | |||
4507 | struct attribute *attr; | |||
4508 | unsigned int length; | |||
4509 | ||||
4510 | if (die->type) | |||
4511 | { | |||
4512 | return; | |||
4513 | } | |||
4514 | ||||
4515 | attr = dwarf2_attr (die, DW_AT_string_length, cu); | |||
4516 | if (attr) | |||
4517 | { | |||
4518 | length = DW_UNSND (attr)((attr)->u.unsnd); | |||
4519 | } | |||
4520 | else | |||
4521 | { | |||
4522 | /* check for the DW_AT_byte_size attribute */ | |||
4523 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
4524 | if (attr) | |||
4525 | { | |||
4526 | length = DW_UNSND (attr)((attr)->u.unsnd); | |||
4527 | } | |||
4528 | else | |||
4529 | { | |||
4530 | length = 1; | |||
4531 | } | |||
4532 | } | |||
4533 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER8, cu); | |||
4534 | range_type = create_range_type (NULL((void*)0), index_type, 1, length); | |||
4535 | if (cu->language == language_fortran) | |||
4536 | { | |||
4537 | /* Need to create a unique string type for bounds | |||
4538 | information */ | |||
4539 | type = create_string_type (0, range_type); | |||
4540 | } | |||
4541 | else | |||
4542 | { | |||
4543 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR2, cu); | |||
4544 | type = create_string_type (char_type, range_type); | |||
4545 | } | |||
4546 | set_die_type (die, type, cu); | |||
4547 | } | |||
4548 | ||||
4549 | /* Handle DIES due to C code like: | |||
4550 | ||||
4551 | struct foo | |||
4552 | { | |||
4553 | int (*funcp)(int a, long l); | |||
4554 | int b; | |||
4555 | }; | |||
4556 | ||||
4557 | ('funcp' generates a DW_TAG_subroutine_type DIE) | |||
4558 | */ | |||
4559 | ||||
4560 | static void | |||
4561 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4562 | { | |||
4563 | struct type *type; /* Type that this function returns */ | |||
4564 | struct type *ftype; /* Function that returns above type */ | |||
4565 | struct attribute *attr; | |||
4566 | ||||
4567 | /* Decode the type that this subroutine returns */ | |||
4568 | if (die->type) | |||
4569 | { | |||
4570 | return; | |||
4571 | } | |||
4572 | type = die_type (die, cu); | |||
4573 | ftype = make_function_type (type, (struct type **) 0); | |||
4574 | ||||
4575 | /* All functions in C++ and Java have prototypes. */ | |||
4576 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); | |||
4577 | if ((attr && (DW_UNSND (attr)((attr)->u.unsnd) != 0)) | |||
4578 | || cu->language == language_cplus | |||
4579 | || cu->language == language_java) | |||
4580 | TYPE_FLAGS (ftype)(ftype)->main_type->flags |= TYPE_FLAG_PROTOTYPED(1 << 7); | |||
4581 | ||||
4582 | if (die->child != NULL((void*)0)) | |||
4583 | { | |||
4584 | struct die_info *child_die; | |||
4585 | int nparams = 0; | |||
4586 | int iparams = 0; | |||
4587 | ||||
4588 | /* Count the number of parameters. | |||
4589 | FIXME: GDB currently ignores vararg functions, but knows about | |||
4590 | vararg member functions. */ | |||
4591 | child_die = die->child; | |||
4592 | while (child_die && child_die->tag) | |||
4593 | { | |||
4594 | if (child_die->tag == DW_TAG_formal_parameter) | |||
4595 | nparams++; | |||
4596 | else if (child_die->tag == DW_TAG_unspecified_parameters) | |||
4597 | TYPE_FLAGS (ftype)(ftype)->main_type->flags |= TYPE_FLAG_VARARGS(1 << 11); | |||
4598 | child_die = sibling_die (child_die); | |||
4599 | } | |||
4600 | ||||
4601 | /* Allocate storage for parameters and fill them in. */ | |||
4602 | TYPE_NFIELDS (ftype)(ftype)->main_type->nfields = nparams; | |||
4603 | TYPE_FIELDS (ftype)(ftype)->main_type->fields = (struct field *) | |||
4604 | TYPE_ALLOC (ftype, nparams * sizeof (struct field))((ftype)->main_type->objfile != ((void*)0) ? __extension__ ({ struct obstack *__h = (&(ftype)->main_type->objfile -> objfile_obstack); __extension__ ({ struct obstack *__o = (__h); int __len = ((nparams * sizeof (struct field))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) : xmalloc (nparams * sizeof (struct field))); | |||
4605 | ||||
4606 | child_die = die->child; | |||
4607 | while (child_die && child_die->tag) | |||
4608 | { | |||
4609 | if (child_die->tag == DW_TAG_formal_parameter) | |||
4610 | { | |||
4611 | /* Dwarf2 has no clean way to discern C++ static and non-static | |||
4612 | member functions. G++ helps GDB by marking the first | |||
4613 | parameter for non-static member functions (which is the | |||
4614 | this pointer) as artificial. We pass this information | |||
4615 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ | |||
4616 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); | |||
4617 | if (attr) | |||
4618 | TYPE_FIELD_ARTIFICIAL (ftype, iparams)(((ftype)->main_type->fields[iparams]).artificial) = DW_UNSND (attr)((attr)->u.unsnd); | |||
4619 | else | |||
4620 | TYPE_FIELD_ARTIFICIAL (ftype, iparams)(((ftype)->main_type->fields[iparams]).artificial) = 0; | |||
4621 | TYPE_FIELD_TYPE (ftype, iparams)(((ftype)->main_type->fields[iparams]).type) = die_type (child_die, cu); | |||
4622 | iparams++; | |||
4623 | } | |||
4624 | child_die = sibling_die (child_die); | |||
4625 | } | |||
4626 | } | |||
4627 | ||||
4628 | set_die_type (die, ftype, cu); | |||
4629 | } | |||
4630 | ||||
4631 | static void | |||
4632 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) | |||
4633 | { | |||
4634 | struct objfile *objfile = cu->objfile; | |||
4635 | struct attribute *attr; | |||
4636 | char *name = NULL((void*)0); | |||
4637 | ||||
4638 | if (!die->type) | |||
4639 | { | |||
4640 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
4641 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
4642 | { | |||
4643 | name = DW_STRING (attr)((attr)->u.str); | |||
4644 | } | |||
4645 | set_die_type (die, init_type (TYPE_CODE_TYPEDEF, 0, | |||
4646 | TYPE_FLAG_TARGET_STUB(1 << 3), name, objfile), | |||
4647 | cu); | |||
4648 | TYPE_TARGET_TYPE (die->type)(die->type)->main_type->target_type = die_type (die, cu); | |||
4649 | } | |||
4650 | } | |||
4651 | ||||
4652 | /* Find a representation of a given base type and install | |||
4653 | it in the TYPE field of the die. */ | |||
4654 | ||||
4655 | static void | |||
4656 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4657 | { | |||
4658 | struct objfile *objfile = cu->objfile; | |||
4659 | struct type *type; | |||
4660 | struct attribute *attr; | |||
4661 | int encoding = 0, size = 0; | |||
4662 | ||||
4663 | /* If we've already decoded this die, this is a no-op. */ | |||
4664 | if (die->type) | |||
4665 | { | |||
4666 | return; | |||
4667 | } | |||
4668 | ||||
4669 | attr = dwarf2_attr (die, DW_AT_encoding, cu); | |||
4670 | if (attr) | |||
4671 | { | |||
4672 | encoding = DW_UNSND (attr)((attr)->u.unsnd); | |||
4673 | } | |||
4674 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
4675 | if (attr) | |||
4676 | { | |||
4677 | size = DW_UNSND (attr)((attr)->u.unsnd); | |||
4678 | } | |||
4679 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
4680 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
4681 | { | |||
4682 | enum type_code code = TYPE_CODE_INT; | |||
4683 | int type_flags = 0; | |||
4684 | ||||
4685 | switch (encoding) | |||
4686 | { | |||
4687 | case DW_ATE_address: | |||
4688 | /* Turn DW_ATE_address into a void * pointer. */ | |||
4689 | code = TYPE_CODE_PTR; | |||
4690 | type_flags |= TYPE_FLAG_UNSIGNED(1 << 0); | |||
4691 | break; | |||
4692 | case DW_ATE_boolean: | |||
4693 | code = TYPE_CODE_BOOL; | |||
4694 | type_flags |= TYPE_FLAG_UNSIGNED(1 << 0); | |||
4695 | break; | |||
4696 | case DW_ATE_complex_float: | |||
4697 | code = TYPE_CODE_COMPLEX; | |||
4698 | break; | |||
4699 | case DW_ATE_float: | |||
4700 | code = TYPE_CODE_FLT; | |||
4701 | break; | |||
4702 | case DW_ATE_signed: | |||
4703 | case DW_ATE_signed_char: | |||
4704 | break; | |||
4705 | case DW_ATE_unsigned: | |||
4706 | case DW_ATE_unsigned_char: | |||
4707 | type_flags |= TYPE_FLAG_UNSIGNED(1 << 0); | |||
4708 | break; | |||
4709 | default: | |||
4710 | complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", | |||
4711 | dwarf_type_encoding_name (encoding)); | |||
4712 | break; | |||
4713 | } | |||
4714 | type = init_type (code, size, type_flags, DW_STRING (attr)((attr)->u.str), objfile); | |||
4715 | if (encoding == DW_ATE_address) | |||
4716 | TYPE_TARGET_TYPE (type)(type)->main_type->target_type = dwarf2_fundamental_type (objfile, FT_VOID0, | |||
4717 | cu); | |||
4718 | else if (encoding == DW_ATE_complex_float) | |||
4719 | { | |||
4720 | if (size == 32) | |||
4721 | TYPE_TARGET_TYPE (type)(type)->main_type->target_type | |||
4722 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT19, cu); | |||
4723 | else if (size == 16) | |||
4724 | TYPE_TARGET_TYPE (type)(type)->main_type->target_type | |||
4725 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT18, cu); | |||
4726 | else if (size == 8) | |||
4727 | TYPE_TARGET_TYPE (type)(type)->main_type->target_type | |||
4728 | = dwarf2_fundamental_type (objfile, FT_FLOAT17, cu); | |||
4729 | } | |||
4730 | } | |||
4731 | else | |||
4732 | { | |||
4733 | type = dwarf_base_type (encoding, size, cu); | |||
4734 | } | |||
4735 | set_die_type (die, type, cu); | |||
4736 | } | |||
4737 | ||||
4738 | /* Read the given DW_AT_subrange DIE. */ | |||
4739 | ||||
4740 | static void | |||
4741 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) | |||
4742 | { | |||
4743 | struct type *base_type; | |||
4744 | struct type *range_type; | |||
4745 | struct attribute *attr; | |||
4746 | int low = 0; | |||
4747 | int high = -1; | |||
4748 | ||||
4749 | /* If we have already decoded this die, then nothing more to do. */ | |||
4750 | if (die->type) | |||
4751 | return; | |||
4752 | ||||
4753 | base_type = die_type (die, cu); | |||
4754 | if (base_type == NULL((void*)0)) | |||
4755 | { | |||
4756 | complaint (&symfile_complaints, | |||
4757 | "DW_AT_type missing from DW_TAG_subrange_type"); | |||
4758 | return; | |||
4759 | } | |||
4760 | ||||
4761 | if (TYPE_CODE (base_type)(base_type)->main_type->code == TYPE_CODE_VOID) | |||
4762 | base_type = alloc_type (NULL((void*)0)); | |||
4763 | ||||
4764 | if (cu->language == language_fortran) | |||
4765 | { | |||
4766 | /* FORTRAN implies a lower bound of 1, if not given. */ | |||
4767 | low = 1; | |||
4768 | } | |||
4769 | ||||
4770 | /* FIXME: For variable sized arrays either of these could be | |||
4771 | a variable rather than a constant value. We'll allow it, | |||
4772 | but we don't know how to handle it. */ | |||
4773 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); | |||
4774 | if (attr) | |||
4775 | low = dwarf2_get_attr_constant_value (attr, 0); | |||
4776 | ||||
4777 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); | |||
4778 | if (attr) | |||
4779 | { | |||
4780 | if (attr->form == DW_FORM_block1) | |||
4781 | { | |||
4782 | /* GCC encodes arrays with unspecified or dynamic length | |||
4783 | with a DW_FORM_block1 attribute. | |||
4784 | FIXME: GDB does not yet know how to handle dynamic | |||
4785 | arrays properly, treat them as arrays with unspecified | |||
4786 | length for now. | |||
4787 | ||||
4788 | FIXME: jimb/2003-09-22: GDB does not really know | |||
4789 | how to handle arrays of unspecified length | |||
4790 | either; we just represent them as zero-length | |||
4791 | arrays. Choose an appropriate upper bound given | |||
4792 | the lower bound we've computed above. */ | |||
4793 | high = low - 1; | |||
4794 | } | |||
4795 | else | |||
4796 | high = dwarf2_get_attr_constant_value (attr, 1); | |||
4797 | } | |||
4798 | ||||
4799 | range_type = create_range_type (NULL((void*)0), base_type, low, high); | |||
4800 | ||||
4801 | attr = dwarf2_attr (die, DW_AT_name, cu); | |||
4802 | if (attr && DW_STRING (attr)((attr)->u.str)) | |||
4803 | TYPE_NAME (range_type)(range_type)->main_type->name = DW_STRING (attr)((attr)->u.str); | |||
4804 | ||||
4805 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); | |||
4806 | if (attr) | |||
4807 | TYPE_LENGTH (range_type)(range_type)->length = DW_UNSND (attr)((attr)->u.unsnd); | |||
4808 | ||||
4809 | set_die_type (die, range_type, cu); | |||
4810 | } | |||
4811 | ||||
4812 | ||||
4813 | /* Read a whole compilation unit into a linked list of dies. */ | |||
4814 | ||||
4815 | static struct die_info * | |||
4816 | read_comp_unit (char *info_ptr, bfd *abfd, struct dwarf2_cu *cu) | |||
4817 | { | |||
4818 | return read_die_and_children (info_ptr, abfd, cu, &info_ptr, NULL((void*)0)); | |||
4819 | } | |||
4820 | ||||
4821 | /* Read a single die and all its descendents. Set the die's sibling | |||
4822 | field to NULL; set other fields in the die correctly, and set all | |||
4823 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the | |||
4824 | location of the info_ptr after reading all of those dies. PARENT | |||
4825 | is the parent of the die in question. */ | |||
4826 | ||||
4827 | static struct die_info * | |||
4828 | read_die_and_children (char *info_ptr, bfd *abfd, | |||
4829 | struct dwarf2_cu *cu, | |||
4830 | char **new_info_ptr, | |||
4831 | struct die_info *parent) | |||
4832 | { | |||
4833 | struct die_info *die; | |||
4834 | char *cur_ptr; | |||
4835 | int has_children; | |||
4836 | ||||
4837 | cur_ptr = read_full_die (&die, abfd, info_ptr, cu, &has_children); | |||
4838 | store_in_ref_table (die->offset, die, cu); | |||
4839 | ||||
4840 | if (has_children) | |||
4841 | { | |||
4842 | die->child = read_die_and_siblings (cur_ptr, abfd, cu, | |||
4843 | new_info_ptr, die); | |||
4844 | } | |||
4845 | else | |||
4846 | { | |||
4847 | die->child = NULL((void*)0); | |||
4848 | *new_info_ptr = cur_ptr; | |||
4849 | } | |||
4850 | ||||
4851 | die->sibling = NULL((void*)0); | |||
4852 | die->parent = parent; | |||
4853 | return die; | |||
4854 | } | |||
4855 | ||||
4856 | /* Read a die, all of its descendents, and all of its siblings; set | |||
4857 | all of the fields of all of the dies correctly. Arguments are as | |||
4858 | in read_die_and_children. */ | |||
4859 | ||||
4860 | static struct die_info * | |||
4861 | read_die_and_siblings (char *info_ptr, bfd *abfd, | |||
4862 | struct dwarf2_cu *cu, | |||
4863 | char **new_info_ptr, | |||
4864 | struct die_info *parent) | |||
4865 | { | |||
4866 | struct die_info *first_die, *last_sibling; | |||
4867 | char *cur_ptr; | |||
4868 | ||||
4869 | cur_ptr = info_ptr; | |||
4870 | first_die = last_sibling = NULL((void*)0); | |||
4871 | ||||
4872 | while (1) | |||
4873 | { | |||
4874 | struct die_info *die | |||
4875 | = read_die_and_children (cur_ptr, abfd, cu, &cur_ptr, parent); | |||
4876 | ||||
4877 | if (!first_die) | |||
4878 | { | |||
4879 | first_die = die; | |||
4880 | } | |||
4881 | else | |||
4882 | { | |||
4883 | last_sibling->sibling = die; | |||
4884 | } | |||
4885 | ||||
4886 | if (die->tag == 0) | |||
4887 | { | |||
4888 | *new_info_ptr = cur_ptr; | |||
4889 | return first_die; | |||
4890 | } | |||
4891 | else | |||
4892 | { | |||
4893 | last_sibling = die; | |||
4894 | } | |||
4895 | } | |||
4896 | } | |||
4897 | ||||
4898 | /* Free a linked list of dies. */ | |||
4899 | ||||
4900 | static void | |||
4901 | free_die_list (struct die_info *dies) | |||
4902 | { | |||
4903 | struct die_info *die, *next; | |||
4904 | ||||
4905 | die = dies; | |||
4906 | while (die) | |||
4907 | { | |||
4908 | if (die->child != NULL((void*)0)) | |||
4909 | free_die_list (die->child); | |||
4910 | next = die->sibling; | |||
4911 | xfree (die->attrs); | |||
4912 | xfree (die); | |||
4913 | die = next; | |||
4914 | } | |||
4915 | } | |||
4916 | ||||
4917 | /* Read the contents of the section at OFFSET and of size SIZE from the | |||
4918 | object file specified by OBJFILE into the objfile_obstack and return it. */ | |||
4919 | ||||
4920 | char * | |||
4921 | dwarf2_read_section (struct objfile *objfile, asection *sectp) | |||
4922 | { | |||
4923 | bfd *abfd = objfile->obfd; | |||
4924 | char *buf, *retbuf; | |||
4925 | bfd_size_type size = bfd_get_section_size (sectp)((sectp)->_raw_size); | |||
4926 | ||||
4927 | if (size == 0) | |||
4928 | return NULL((void*)0); | |||
4929 | ||||
4930 | buf = (char *) obstack_alloc (&objfile->objfile_obstack, size)__extension__ ({ struct obstack *__h = (&objfile->objfile_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (size)); if (__o->chunk_limit - __o->next_free < __len ) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len )); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h ); void *value; value = (void *) __o1->object_base; if (__o1 ->next_free == value) __o1->maybe_empty_object = 1; __o1 ->next_free = (((((__o1->next_free) - (char *) 0)+__o1-> alignment_mask) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1 ->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit; __o1->object_base = __o1->next_free ; value; }); }); | |||
4931 | retbuf | |||
4932 | = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); | |||
4933 | if (retbuf != NULL((void*)0)) | |||
4934 | return retbuf; | |||
4935 | ||||
4936 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET0) != 0 | |||
4937 | || bfd_bread (buf, size, abfd) != size) | |||
4938 | error ("Dwarf Error: Can't read DWARF data from '%s'", | |||
4939 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
4940 | ||||
4941 | return buf; | |||
4942 | } | |||
4943 | ||||
4944 | /* In DWARF version 2, the description of the debugging information is | |||
4945 | stored in a separate .debug_abbrev section. Before we read any | |||
4946 | dies from a section we read in all abbreviations and install them | |||
4947 | in a hash table. This function also sets flags in CU describing | |||
4948 | the data found in the abbrev table. */ | |||
4949 | ||||
4950 | static void | |||
4951 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) | |||
4952 | { | |||
4953 | struct comp_unit_head *cu_header = &cu->header; | |||
4954 | char *abbrev_ptr; | |||
4955 | struct abbrev_info *cur_abbrev; | |||
4956 | unsigned int abbrev_number, bytes_read, abbrev_name; | |||
4957 | unsigned int abbrev_form, hash_number; | |||
4958 | struct attr_abbrev *cur_attrs; | |||
4959 | unsigned int allocated_attrs; | |||
4960 | ||||
4961 | /* Initialize dwarf2 abbrevs */ | |||
4962 | obstack_init (&cu->abbrev_obstack)_obstack_begin ((&cu->abbrev_obstack), 0, 0, (void *(* ) (long)) xmalloc, (void (*) (void *)) xfree); | |||
4963 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack,__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((121 * sizeof (struct abbrev_info *)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len ); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
4964 | (ABBREV_HASH_SIZE__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((121 * sizeof (struct abbrev_info *)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len ); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
4965 | * sizeof (struct abbrev_info *)))__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((121 * sizeof (struct abbrev_info *)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len ); ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }); | |||
4966 | memset (cu->dwarf2_abbrevs, 0, | |||
4967 | ABBREV_HASH_SIZE121 * sizeof (struct abbrev_info *)); | |||
4968 | ||||
4969 | abbrev_ptr = dwarf2_per_objfile->abbrev_buffer + cu_header->abbrev_offset; | |||
4970 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
4971 | abbrev_ptr += bytes_read; | |||
4972 | ||||
4973 | allocated_attrs = ATTR_ALLOC_CHUNK4; | |||
4974 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); | |||
4975 | ||||
4976 | /* loop until we reach an abbrev number of 0 */ | |||
4977 | while (abbrev_number) | |||
4978 | { | |||
4979 | cur_abbrev = dwarf_alloc_abbrev (cu); | |||
4980 | ||||
4981 | /* read in abbrev header */ | |||
4982 | cur_abbrev->number = abbrev_number; | |||
4983 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
4984 | abbrev_ptr += bytes_read; | |||
4985 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); | |||
4986 | abbrev_ptr += 1; | |||
4987 | ||||
4988 | if (cur_abbrev->tag == DW_TAG_namespace) | |||
4989 | cu->has_namespace_info = 1; | |||
4990 | ||||
4991 | /* now read in declarations */ | |||
4992 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
4993 | abbrev_ptr += bytes_read; | |||
4994 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
4995 | abbrev_ptr += bytes_read; | |||
4996 | while (abbrev_name) | |||
4997 | { | |||
4998 | if (cur_abbrev->num_attrs == allocated_attrs) | |||
4999 | { | |||
5000 | allocated_attrs += ATTR_ALLOC_CHUNK4; | |||
5001 | cur_attrs | |||
5002 | = xrealloc (cur_attrs, (allocated_attrs | |||
5003 | * sizeof (struct attr_abbrev))); | |||
5004 | } | |||
5005 | ||||
5006 | /* Record whether this compilation unit might have | |||
5007 | inter-compilation-unit references. If we don't know what form | |||
5008 | this attribute will have, then it might potentially be a | |||
5009 | DW_FORM_ref_addr, so we conservatively expect inter-CU | |||
5010 | references. */ | |||
5011 | ||||
5012 | if (abbrev_form == DW_FORM_ref_addr | |||
5013 | || abbrev_form == DW_FORM_indirect) | |||
5014 | cu->has_form_ref_addr = 1; | |||
5015 | ||||
5016 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; | |||
5017 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; | |||
5018 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
5019 | abbrev_ptr += bytes_read; | |||
5020 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
5021 | abbrev_ptr += bytes_read; | |||
5022 | } | |||
5023 | ||||
5024 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack,__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((cur_abbrev->num_attrs * sizeof (struct attr_abbrev)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) | |||
5025 | (cur_abbrev->num_attrs__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((cur_abbrev->num_attrs * sizeof (struct attr_abbrev)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }) | |||
5026 | * sizeof (struct attr_abbrev)))__extension__ ({ struct obstack *__h = (&cu->abbrev_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( ((cur_abbrev->num_attrs * sizeof (struct attr_abbrev)))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len); ((__o)->next_free += (__len)); (void) 0; }) ; __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void *) __o1->object_base; if (__o1->next_free == value) __o1->maybe_empty_object = 1; __o1->next_free = (((((__o1->next_free) - (char *) 0)+__o1->alignment_mask ) & ~ (__o1->alignment_mask)) + (char *) 0); if (__o1-> next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1->chunk) __o1->next_free = __o1->chunk_limit ; __o1->object_base = __o1->next_free; value; }); }); | |||
5027 | memcpy (cur_abbrev->attrs, cur_attrs, | |||
5028 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); | |||
5029 | ||||
5030 | hash_number = abbrev_number % ABBREV_HASH_SIZE121; | |||
5031 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; | |||
5032 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; | |||
5033 | ||||
5034 | /* Get next abbreviation. | |||
5035 | Under Irix6 the abbreviations for a compilation unit are not | |||
5036 | always properly terminated with an abbrev number of 0. | |||
5037 | Exit loop if we encounter an abbreviation which we have | |||
5038 | already read (which means we are about to read the abbreviations | |||
5039 | for the next compile unit) or if the end of the abbreviation | |||
5040 | table is reached. */ | |||
5041 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev_buffer) | |||
5042 | >= dwarf2_per_objfile->abbrev_size) | |||
5043 | break; | |||
5044 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); | |||
5045 | abbrev_ptr += bytes_read; | |||
5046 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL((void*)0)) | |||
5047 | break; | |||
5048 | } | |||
5049 | ||||
5050 | xfree (cur_attrs); | |||
5051 | } | |||
5052 | ||||
5053 | /* Release the memory used by the abbrev table for a compilation unit. */ | |||
5054 | ||||
5055 | static void | |||
5056 | dwarf2_free_abbrev_table (void *ptr_to_cu) | |||
5057 | { | |||
5058 | struct dwarf2_cu *cu = ptr_to_cu; | |||
5059 | ||||
5060 | obstack_free (&cu->abbrev_obstack, NULL)__extension__ ({ struct obstack *__o = (&cu->abbrev_obstack ); void *__obj = (((void*)0)); if (__obj > (void *)__o-> chunk && __obj < (void *)__o->chunk_limit) __o-> next_free = __o->object_base = __obj; else (obstack_free) ( __o, __obj); }); | |||
5061 | cu->dwarf2_abbrevs = NULL((void*)0); | |||
5062 | } | |||
5063 | ||||
5064 | /* Lookup an abbrev_info structure in the abbrev hash table. */ | |||
5065 | ||||
5066 | static struct abbrev_info * | |||
5067 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) | |||
5068 | { | |||
5069 | unsigned int hash_number; | |||
5070 | struct abbrev_info *abbrev; | |||
5071 | ||||
5072 | hash_number = number % ABBREV_HASH_SIZE121; | |||
5073 | abbrev = cu->dwarf2_abbrevs[hash_number]; | |||
5074 | ||||
5075 | while (abbrev) | |||
5076 | { | |||
5077 | if (abbrev->number == number) | |||
5078 | return abbrev; | |||
5079 | else | |||
5080 | abbrev = abbrev->next; | |||
5081 | } | |||
5082 | return NULL((void*)0); | |||
5083 | } | |||
5084 | ||||
5085 | /* Returns nonzero if TAG represents a type that we might generate a partial | |||
5086 | symbol for. */ | |||
5087 | ||||
5088 | static int | |||
5089 | is_type_tag_for_partial (int tag) | |||
5090 | { | |||
5091 | switch (tag) | |||
5092 | { | |||
5093 | #if 0 | |||
5094 | /* Some types that would be reasonable to generate partial symbols for, | |||
5095 | that we don't at present. */ | |||
5096 | case DW_TAG_array_type: | |||
5097 | case DW_TAG_file_type: | |||
5098 | case DW_TAG_ptr_to_member_type: | |||
5099 | case DW_TAG_set_type: | |||
5100 | case DW_TAG_string_type: | |||
5101 | case DW_TAG_subroutine_type: | |||
5102 | #endif | |||
5103 | case DW_TAG_base_type: | |||
5104 | case DW_TAG_class_type: | |||
5105 | case DW_TAG_enumeration_type: | |||
5106 | case DW_TAG_structure_type: | |||
5107 | case DW_TAG_subrange_type: | |||
5108 | case DW_TAG_typedef: | |||
5109 | case DW_TAG_union_type: | |||
5110 | return 1; | |||
5111 | default: | |||
5112 | return 0; | |||
5113 | } | |||
5114 | } | |||
5115 | ||||
5116 | /* Load all DIEs that are interesting for partial symbols into memory. */ | |||
5117 | ||||
5118 | static struct partial_die_info * | |||
5119 | load_partial_dies (bfd *abfd, char *info_ptr, int building_psymtab, | |||
5120 | struct dwarf2_cu *cu) | |||
5121 | { | |||
5122 | struct partial_die_info *part_die; | |||
5123 | struct partial_die_info *parent_die, *last_die, *first_die = NULL((void*)0); | |||
5124 | struct abbrev_info *abbrev; | |||
5125 | unsigned int bytes_read; | |||
5126 | ||||
5127 | int nesting_level = 1; | |||
5128 | ||||
5129 | parent_die = NULL((void*)0); | |||
5130 | last_die = NULL((void*)0); | |||
5131 | ||||
5132 | cu->partial_dies | |||
5133 | = htab_create_alloc_ex (cu->header.length / 12, | |||
5134 | partial_die_hash, | |||
5135 | partial_die_eq, | |||
5136 | NULL((void*)0), | |||
5137 | &cu->comp_unit_obstack, | |||
5138 | hashtab_obstack_allocate, | |||
5139 | dummy_obstack_deallocate); | |||
5140 | ||||
5141 | part_die = obstack_alloc (&cu->comp_unit_obstack,__extension__ ({ struct obstack *__h = (&cu->comp_unit_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_die_info))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
5142 | sizeof (struct partial_die_info))__extension__ ({ struct obstack *__h = (&cu->comp_unit_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_die_info))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }); | |||
5143 | ||||
5144 | while (1) | |||
5145 | { | |||
5146 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); | |||
5147 | ||||
5148 | /* A NULL abbrev means the end of a series of children. */ | |||
5149 | if (abbrev == NULL((void*)0)) | |||
5150 | { | |||
5151 | if (--nesting_level == 0) | |||
5152 | { | |||
5153 | /* PART_DIE was probably the last thing allocated on the | |||
5154 | comp_unit_obstack, so we could call obstack_free | |||
5155 | here. We don't do that because the waste is small, | |||
5156 | and will be cleaned up when we're done with this | |||
5157 | compilation unit. This way, we're also more robust | |||
5158 | against other users of the comp_unit_obstack. */ | |||
5159 | return first_die; | |||
5160 | } | |||
5161 | info_ptr += bytes_read; | |||
5162 | last_die = parent_die; | |||
5163 | parent_die = parent_die->die_parent; | |||
5164 | continue; | |||
5165 | } | |||
5166 | ||||
5167 | /* Check whether this DIE is interesting enough to save. */ | |||
5168 | if (!is_type_tag_for_partial (abbrev->tag) | |||
5169 | && abbrev->tag != DW_TAG_enumerator | |||
5170 | && abbrev->tag != DW_TAG_subprogram | |||
5171 | && abbrev->tag != DW_TAG_variable | |||
5172 | && abbrev->tag != DW_TAG_namespace) | |||
5173 | { | |||
5174 | /* Otherwise we skip to the next sibling, if any. */ | |||
5175 | info_ptr = skip_one_die (info_ptr + bytes_read, abbrev, cu); | |||
5176 | continue; | |||
5177 | } | |||
5178 | ||||
5179 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, | |||
5180 | abfd, info_ptr, cu); | |||
5181 | ||||
5182 | /* This two-pass algorithm for processing partial symbols has a | |||
5183 | high cost in cache pressure. Thus, handle some simple cases | |||
5184 | here which cover the majority of C partial symbols. DIEs | |||
5185 | which neither have specification tags in them, nor could have | |||
5186 | specification tags elsewhere pointing at them, can simply be | |||
5187 | processed and discarded. | |||
5188 | ||||
5189 | This segment is also optional; scan_partial_symbols and | |||
5190 | add_partial_symbol will handle these DIEs if we chain | |||
5191 | them in normally. When compilers which do not emit large | |||
5192 | quantities of duplicate debug information are more common, | |||
5193 | this code can probably be removed. */ | |||
5194 | ||||
5195 | /* Any complete simple types at the top level (pretty much all | |||
5196 | of them, for a language without namespaces), can be processed | |||
5197 | directly. */ | |||
5198 | if (parent_die == NULL((void*)0) | |||
5199 | && part_die->has_specification == 0 | |||
5200 | && part_die->is_declaration == 0 | |||
5201 | && (part_die->tag == DW_TAG_typedef | |||
5202 | || part_die->tag == DW_TAG_base_type | |||
5203 | || part_die->tag == DW_TAG_subrange_type)) | |||
5204 | { | |||
5205 | if (building_psymtab && part_die->name != NULL((void*)0)) | |||
5206 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |||
5207 | VAR_DOMAIN, LOC_TYPEDEF, | |||
5208 | &cu->objfile->static_psymbols, | |||
5209 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |||
5210 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |||
5211 | continue; | |||
5212 | } | |||
5213 | ||||
5214 | /* If we're at the second level, and we're an enumerator, and | |||
5215 | our parent has no specification (meaning possibly lives in a | |||
5216 | namespace elsewhere), then we can add the partial symbol now | |||
5217 | instead of queueing it. */ | |||
5218 | if (part_die->tag == DW_TAG_enumerator | |||
5219 | && parent_die != NULL((void*)0) | |||
5220 | && parent_die->die_parent == NULL((void*)0) | |||
5221 | && parent_die->tag == DW_TAG_enumeration_type | |||
5222 | && parent_die->has_specification == 0) | |||
5223 | { | |||
5224 | if (part_die->name == NULL((void*)0)) | |||
5225 | complaint (&symfile_complaints, "malformed enumerator DIE ignored"); | |||
5226 | else if (building_psymtab) | |||
5227 | add_psymbol_to_list (part_die->name, strlen (part_die->name), | |||
5228 | VAR_DOMAIN, LOC_CONST, | |||
5229 | (cu->language == language_cplus | |||
5230 | || cu->language == language_java) | |||
5231 | ? &cu->objfile->global_psymbols | |||
5232 | : &cu->objfile->static_psymbols, | |||
5233 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); | |||
5234 | ||||
5235 | info_ptr = locate_pdi_sibling (part_die, info_ptr, abfd, cu); | |||
5236 | continue; | |||
5237 | } | |||
5238 | ||||
5239 | /* We'll save this DIE so link it in. */ | |||
5240 | part_die->die_parent = parent_die; | |||
5241 | part_die->die_sibling = NULL((void*)0); | |||
5242 | part_die->die_child = NULL((void*)0); | |||
5243 | ||||
5244 | if (last_die && last_die == parent_die) | |||
5245 | last_die->die_child = part_die; | |||
5246 | else if (last_die) | |||
5247 | last_die->die_sibling = part_die; | |||
5248 | ||||
5249 | last_die = part_die; | |||
5250 | ||||
5251 | if (first_die == NULL((void*)0)) | |||
5252 | first_die = part_die; | |||
5253 | ||||
5254 | /* Maybe add the DIE to the hash table. Not all DIEs that we | |||
5255 | find interesting need to be in the hash table, because we | |||
5256 | also have the parent/sibling/child chains; only those that we | |||
5257 | might refer to by offset later during partial symbol reading. | |||
5258 | ||||
5259 | For now this means things that might have be the target of a | |||
5260 | DW_AT_specification, DW_AT_abstract_origin, or | |||
5261 | DW_AT_extension. DW_AT_extension will refer only to | |||
5262 | namespaces; DW_AT_abstract_origin refers to functions (and | |||
5263 | many things under the function DIE, but we do not recurse | |||
5264 | into function DIEs during partial symbol reading) and | |||
5265 | possibly variables as well; DW_AT_specification refers to | |||
5266 | declarations. Declarations ought to have the DW_AT_declaration | |||
5267 | flag. It happens that GCC forgets to put it in sometimes, but | |||
5268 | only for functions, not for types. | |||
5269 | ||||
5270 | Adding more things than necessary to the hash table is harmless | |||
5271 | except for the performance cost. Adding too few will result in | |||
5272 | internal errors in find_partial_die. */ | |||
5273 | ||||
5274 | if (abbrev->tag == DW_TAG_subprogram | |||
5275 | || abbrev->tag == DW_TAG_variable | |||
5276 | || abbrev->tag == DW_TAG_namespace | |||
5277 | || part_die->is_declaration) | |||
5278 | { | |||
5279 | void **slot; | |||
5280 | ||||
5281 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, | |||
5282 | part_die->offset, INSERT); | |||
5283 | *slot = part_die; | |||
5284 | } | |||
5285 | ||||
5286 | part_die = obstack_alloc (&cu->comp_unit_obstack,__extension__ ({ struct obstack *__h = (&cu->comp_unit_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_die_info))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }) | |||
5287 | sizeof (struct partial_die_info))__extension__ ({ struct obstack *__h = (&cu->comp_unit_obstack ); __extension__ ({ struct obstack *__o = (__h); int __len = ( (sizeof (struct partial_die_info))); if (__o->chunk_limit - __o->next_free < __len) _obstack_newchunk (__o, __len) ; ((__o)->next_free += (__len)); (void) 0; }); __extension__ ({ struct obstack *__o1 = (__h); void *value; value = (void * ) __o1->object_base; if (__o1->next_free == value) __o1 ->maybe_empty_object = 1; __o1->next_free = (((((__o1-> next_free) - (char *) 0)+__o1->alignment_mask) & ~ (__o1 ->alignment_mask)) + (char *) 0); if (__o1->next_free - (char *)__o1->chunk > __o1->chunk_limit - (char *)__o1 ->chunk) __o1->next_free = __o1->chunk_limit; __o1-> object_base = __o1->next_free; value; }); }); | |||
5288 | ||||
5289 | /* For some DIEs we want to follow their children (if any). For C | |||
5290 | we have no reason to follow the children of structures; for other | |||
5291 | languages we have to, both so that we can get at method physnames | |||
5292 | to infer fully qualified class names, and for DW_AT_specification. */ | |||
5293 | if (last_die->has_children | |||
5294 | && (last_die->tag == DW_TAG_namespace | |||
5295 | || last_die->tag == DW_TAG_enumeration_type | |||
5296 | || (cu->language != language_c | |||
5297 | && (last_die->tag == DW_TAG_class_type | |||
5298 | || last_die->tag == DW_TAG_structure_type | |||
5299 | || last_die->tag == DW_TAG_union_type)))) | |||
5300 | { | |||
5301 | nesting_level++; | |||
5302 | parent_die = last_die; | |||
5303 | continue; | |||
5304 | } | |||
5305 | ||||
5306 | /* Otherwise we skip to the next sibling, if any. */ | |||
5307 | info_ptr = locate_pdi_sibling (last_die, info_ptr, abfd, cu); | |||
5308 | ||||
5309 | /* Back to the top, do it again. */ | |||
5310 | } | |||
5311 | } | |||
5312 | ||||
5313 | /* Read a minimal amount of information into the minimal die structure. */ | |||
5314 | ||||
5315 | static char * | |||
5316 | read_partial_die (struct partial_die_info *part_die, | |||
5317 | struct abbrev_info *abbrev, | |||
5318 | unsigned int abbrev_len, bfd *abfd, | |||
5319 | char *info_ptr, struct dwarf2_cu *cu) | |||
5320 | { | |||
5321 | unsigned int bytes_read, i; | |||
5322 | struct attribute attr; | |||
5323 | int has_low_pc_attr = 0; | |||
5324 | int has_high_pc_attr = 0; | |||
5325 | ||||
5326 | memset (part_die, 0, sizeof (struct partial_die_info)); | |||
5327 | ||||
5328 | part_die->offset = info_ptr - dwarf2_per_objfile->info_buffer; | |||
5329 | ||||
5330 | info_ptr += abbrev_len; | |||
5331 | ||||
5332 | if (abbrev == NULL((void*)0)) | |||
5333 | return info_ptr; | |||
5334 | ||||
5335 | part_die->tag = abbrev->tag; | |||
5336 | part_die->has_children = abbrev->has_children; | |||
5337 | ||||
5338 | for (i = 0; i < abbrev->num_attrs; ++i) | |||
5339 | { | |||
5340 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); | |||
5341 | ||||
5342 | /* Store the data if it is of an attribute we want to keep in a | |||
5343 | partial symbol table. */ | |||
5344 | switch (attr.name) | |||
5345 | { | |||
5346 | case DW_AT_name: | |||
5347 | ||||
5348 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ | |||
5349 | if (part_die->name == NULL((void*)0)) | |||
5350 | part_die->name = DW_STRING (&attr)((&attr)->u.str); | |||
5351 | break; | |||
5352 | case DW_AT_comp_dir: | |||
5353 | if (part_die->dirname == NULL((void*)0)) | |||
5354 | part_die->dirname = DW_STRING (&attr)((&attr)->u.str); | |||
5355 | break; | |||
5356 | case DW_AT_MIPS_linkage_name: | |||
5357 | part_die->name = DW_STRING (&attr)((&attr)->u.str); | |||
5358 | break; | |||
5359 | case DW_AT_low_pc: | |||
5360 | has_low_pc_attr = 1; | |||
5361 | part_die->lowpc = DW_ADDR (&attr)((&attr)->u.addr); | |||
5362 | break; | |||
5363 | case DW_AT_high_pc: | |||
5364 | has_high_pc_attr = 1; | |||
5365 | part_die->highpc = DW_ADDR (&attr)((&attr)->u.addr); | |||
5366 | break; | |||
5367 | case DW_AT_location: | |||
5368 | /* Support the .debug_loc offsets */ | |||
5369 | if (attr_form_is_block (&attr)) | |||
5370 | { | |||
5371 | part_die->locdesc = DW_BLOCK (&attr)((&attr)->u.blk); | |||
5372 | } | |||
5373 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) | |||
5374 | { | |||
5375 | dwarf2_complex_location_expr_complaint (); | |||
5376 | } | |||
5377 | else | |||
5378 | { | |||
5379 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", | |||
5380 | "partial symbol information"); | |||
5381 | } | |||
5382 | break; | |||
5383 | case DW_AT_language: | |||
5384 | part_die->language = DW_UNSND (&attr)((&attr)->u.unsnd); | |||
5385 | break; | |||
5386 | case DW_AT_external: | |||
5387 | part_die->is_external = DW_UNSND (&attr)((&attr)->u.unsnd); | |||
5388 | break; | |||
5389 | case DW_AT_declaration: | |||
5390 | part_die->is_declaration = DW_UNSND (&attr)((&attr)->u.unsnd); | |||
5391 | break; | |||
5392 | case DW_AT_type: | |||
5393 | part_die->has_type = 1; | |||
5394 | break; | |||
5395 | case DW_AT_abstract_origin: | |||
5396 | case DW_AT_specification: | |||
5397 | case DW_AT_extension: | |||
5398 | part_die->has_specification = 1; | |||
5399 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr, cu); | |||
5400 | break; | |||
5401 | case DW_AT_sibling: | |||
5402 | /* Ignore absolute siblings, they might point outside of | |||
5403 | the current compile unit. */ | |||
5404 | if (attr.form == DW_FORM_ref_addr) | |||
5405 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); | |||
5406 | else | |||
5407 | part_die->sibling = dwarf2_per_objfile->info_buffer | |||
5408 | + dwarf2_get_ref_die_offset (&attr, cu); | |||
5409 | break; | |||
5410 | case DW_AT_stmt_list: | |||
5411 | part_die->has_stmt_list = 1; | |||
5412 | part_die->line_offset = DW_UNSND (&attr)((&attr)->u.unsnd); | |||
5413 | break; | |||
5414 | default: | |||
5415 | break; | |||
5416 | } | |||
5417 | } | |||
5418 | ||||
5419 | /* When using the GNU linker, .gnu.linkonce. sections are used to | |||
5420 | eliminate duplicate copies of functions and vtables and such. | |||
5421 | The linker will arbitrarily choose one and discard the others. | |||
5422 | The AT_*_pc values for such functions refer to local labels in | |||
5423 | these sections. If the section from that file was discarded, the | |||
5424 | labels are not in the output, so the relocs get a value of 0. | |||
5425 | If this is a discarded function, mark the pc bounds as invalid, | |||
5426 | so that GDB will ignore it. */ | |||
5427 | if (has_low_pc_attr && has_high_pc_attr | |||
5428 | && part_die->lowpc < part_die->highpc | |||
5429 | && (part_die->lowpc != 0 | |||
5430 | || (bfd_get_file_flags (abfd)((abfd)->flags) & HAS_RELOC0x01))) | |||
5431 | part_die->has_pc_info = 1; | |||
5432 | return info_ptr; | |||
5433 | } | |||
5434 | ||||
5435 | /* Find a cached partial DIE at OFFSET in CU. */ | |||
5436 | ||||
5437 | static struct partial_die_info * | |||
5438 | find_partial_die_in_comp_unit (unsigned long offset, struct dwarf2_cu *cu) | |||
5439 | { | |||
5440 | struct partial_die_info *lookup_die = NULL((void*)0); | |||
5441 | struct partial_die_info part_die; | |||
5442 | ||||
5443 | part_die.offset = offset; | |||
5444 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); | |||
5445 | ||||
5446 | if (lookup_die == NULL((void*)0)) | |||
5447 | internal_error (__FILE__"/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", __LINE__5447, | |||
5448 | "could not find partial DIE in cache\n"); | |||
5449 | ||||
5450 | return lookup_die; | |||
5451 | } | |||
5452 | ||||
5453 | /* Find a partial DIE at OFFSET, which may or may not be in CU. */ | |||
5454 | ||||
5455 | static struct partial_die_info * | |||
5456 | find_partial_die (unsigned long offset, struct dwarf2_cu *cu) | |||
5457 | { | |||
5458 | struct dwarf2_per_cu_data *per_cu; | |||
5459 | ||||
5460 | if (offset >= cu->header.offset | |||
5461 | && offset < cu->header.offset + cu->header.length) | |||
5462 | return find_partial_die_in_comp_unit (offset, cu); | |||
5463 | ||||
5464 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); | |||
5465 | ||||
5466 | if (per_cu->cu == NULL((void*)0)) | |||
5467 | { | |||
5468 | load_comp_unit (per_cu, cu->objfile); | |||
5469 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; | |||
5470 | dwarf2_per_objfile->read_in_chain = per_cu; | |||
5471 | } | |||
5472 | ||||
5473 | per_cu->cu->last_used = 0; | |||
5474 | return find_partial_die_in_comp_unit (offset, per_cu->cu); | |||
5475 | } | |||
5476 | ||||
5477 | /* Adjust PART_DIE before generating a symbol for it. This function | |||
5478 | may set the is_external flag or change the DIE's name. */ | |||
5479 | ||||
5480 | static void | |||
5481 | fixup_partial_die (struct partial_die_info *part_die, | |||
5482 | struct dwarf2_cu *cu) | |||
5483 | { | |||
5484 | /* If we found a reference attribute and the DIE has no name, try | |||
5485 | to find a name in the referred to DIE. */ | |||
5486 | ||||
5487 | if (part_die->name == NULL((void*)0) && part_die->has_specification) | |||
5488 | { | |||
5489 | struct partial_die_info *spec_die; | |||
5490 | ||||
5491 | spec_die = find_partial_die (part_die->spec_offset, cu); | |||
5492 | ||||
5493 | fixup_partial_die (spec_die, cu); | |||
5494 | ||||
5495 | if (spec_die->name) | |||
5496 | { | |||
5497 | part_die->name = spec_die->name; | |||
5498 | ||||
5499 | /* Copy DW_AT_external attribute if it is set. */ | |||
5500 | if (spec_die->is_external) | |||
5501 | part_die->is_external = spec_die->is_external; | |||
5502 | } | |||
5503 | } | |||
5504 | ||||
5505 | /* Set default names for some unnamed DIEs. */ | |||
5506 | if (part_die->name == NULL((void*)0) && (part_die->tag == DW_TAG_structure_type | |||
5507 | || part_die->tag == DW_TAG_class_type)) | |||
5508 | part_die->name = "(anonymous class)"; | |||
5509 | ||||
5510 | if (part_die->name == NULL((void*)0) && part_die->tag == DW_TAG_namespace) | |||
5511 | part_die->name = "(anonymous namespace)"; | |||
5512 | ||||
5513 | if (part_die->tag == DW_TAG_structure_type | |||
5514 | || part_die->tag == DW_TAG_class_type | |||
5515 | || part_die->tag == DW_TAG_union_type) | |||
5516 | guess_structure_name (part_die, cu); | |||
5517 | } | |||
5518 | ||||
5519 | /* Read the die from the .debug_info section buffer. Set DIEP to | |||
5520 | point to a newly allocated die with its information, except for its | |||
5521 | child, sibling, and parent fields. Set HAS_CHILDREN to tell | |||
5522 | whether the die has children or not. */ | |||
5523 | ||||
5524 | static char * | |||
5525 | read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, | |||
5526 | struct dwarf2_cu *cu, int *has_children) | |||
5527 | { | |||
5528 | unsigned int abbrev_number, bytes_read, i, offset; | |||
5529 | struct abbrev_info *abbrev; | |||
5530 | struct die_info *die; | |||
5531 | ||||
5532 | offset = info_ptr - dwarf2_per_objfile->info_buffer; | |||
5533 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
5534 | info_ptr += bytes_read; | |||
5535 | if (!abbrev_number) | |||
5536 | { | |||
5537 | die = dwarf_alloc_die (); | |||
5538 | die->tag = 0; | |||
5539 | die->abbrev = abbrev_number; | |||
5540 | die->type = NULL((void*)0); | |||
5541 | *diep = die; | |||
5542 | *has_children = 0; | |||
5543 | return info_ptr; | |||
5544 | } | |||
5545 | ||||
5546 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); | |||
5547 | if (!abbrev) | |||
5548 | { | |||
5549 | error ("Dwarf Error: could not find abbrev number %d [in module %s]", | |||
5550 | abbrev_number, | |||
5551 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5552 | } | |||
5553 | die = dwarf_alloc_die (); | |||
5554 | die->offset = offset; | |||
5555 | die->tag = abbrev->tag; | |||
5556 | die->abbrev = abbrev_number; | |||
5557 | die->type = NULL((void*)0); | |||
5558 | ||||
5559 | die->num_attrs = abbrev->num_attrs; | |||
5560 | die->attrs = (struct attribute *) | |||
5561 | xmalloc (die->num_attrs * sizeof (struct attribute)); | |||
5562 | ||||
5563 | for (i = 0; i < abbrev->num_attrs; ++i) | |||
5564 | { | |||
5565 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], | |||
5566 | abfd, info_ptr, cu); | |||
5567 | ||||
5568 | /* If this attribute is an absolute reference to a different | |||
5569 | compilation unit, make sure that compilation unit is loaded | |||
5570 | also. */ | |||
5571 | if (die->attrs[i].form == DW_FORM_ref_addr | |||
5572 | && (DW_ADDR (&die->attrs[i])((&die->attrs[i])->u.addr) < cu->header.offset | |||
5573 | || (DW_ADDR (&die->attrs[i])((&die->attrs[i])->u.addr) | |||
5574 | >= cu->header.offset + cu->header.length))) | |||
5575 | { | |||
5576 | struct dwarf2_per_cu_data *per_cu; | |||
5577 | per_cu = dwarf2_find_containing_comp_unit (DW_ADDR (&die->attrs[i])((&die->attrs[i])->u.addr), | |||
5578 | cu->objfile); | |||
5579 | ||||
5580 | /* Mark the dependence relation so that we don't flush PER_CU | |||
5581 | too early. */ | |||
5582 | dwarf2_add_dependence (cu, per_cu); | |||
5583 | ||||
5584 | /* If it's already on the queue, we have nothing to do. */ | |||
5585 | if (per_cu->queued) | |||
5586 | continue; | |||
5587 | ||||
5588 | /* If the compilation unit is already loaded, just mark it as | |||
5589 | used. */ | |||
5590 | if (per_cu->cu != NULL((void*)0)) | |||
5591 | { | |||
5592 | per_cu->cu->last_used = 0; | |||
5593 | continue; | |||
5594 | } | |||
5595 | ||||
5596 | /* Add it to the queue. */ | |||
5597 | queue_comp_unit (per_cu); | |||
5598 | } | |||
5599 | } | |||
5600 | ||||
5601 | *diep = die; | |||
5602 | *has_children = abbrev->has_children; | |||
5603 | return info_ptr; | |||
5604 | } | |||
5605 | ||||
5606 | /* Read an attribute value described by an attribute form. */ | |||
5607 | ||||
5608 | static char * | |||
5609 | read_attribute_value (struct attribute *attr, unsigned form, | |||
5610 | bfd *abfd, char *info_ptr, | |||
5611 | struct dwarf2_cu *cu) | |||
5612 | { | |||
5613 | struct comp_unit_head *cu_header = &cu->header; | |||
5614 | unsigned int bytes_read; | |||
5615 | struct dwarf_block *blk; | |||
5616 | ||||
5617 | attr->form = form; | |||
5618 | switch (form) | |||
5619 | { | |||
5620 | case DW_FORM_addr: | |||
5621 | case DW_FORM_ref_addr: | |||
5622 | DW_ADDR (attr)((attr)->u.addr) = read_address (abfd, info_ptr, cu, &bytes_read); | |||
5623 | info_ptr += bytes_read; | |||
5624 | break; | |||
5625 | case DW_FORM_block2: | |||
5626 | blk = dwarf_alloc_block (cu); | |||
5627 | blk->size = read_2_bytes (abfd, info_ptr); | |||
5628 | info_ptr += 2; | |||
5629 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |||
5630 | info_ptr += blk->size; | |||
5631 | DW_BLOCK (attr)((attr)->u.blk) = blk; | |||
5632 | break; | |||
5633 | case DW_FORM_block4: | |||
5634 | blk = dwarf_alloc_block (cu); | |||
5635 | blk->size = read_4_bytes (abfd, info_ptr); | |||
5636 | info_ptr += 4; | |||
5637 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |||
5638 | info_ptr += blk->size; | |||
5639 | DW_BLOCK (attr)((attr)->u.blk) = blk; | |||
5640 | break; | |||
5641 | case DW_FORM_data2: | |||
5642 | DW_UNSND (attr)((attr)->u.unsnd) = read_2_bytes (abfd, info_ptr); | |||
5643 | info_ptr += 2; | |||
5644 | break; | |||
5645 | case DW_FORM_data4: | |||
5646 | DW_UNSND (attr)((attr)->u.unsnd) = read_4_bytes (abfd, info_ptr); | |||
5647 | info_ptr += 4; | |||
5648 | break; | |||
5649 | case DW_FORM_data8: | |||
5650 | DW_UNSND (attr)((attr)->u.unsnd) = read_8_bytes (abfd, info_ptr); | |||
5651 | info_ptr += 8; | |||
5652 | break; | |||
5653 | case DW_FORM_string: | |||
5654 | DW_STRING (attr)((attr)->u.str) = read_string (abfd, info_ptr, &bytes_read); | |||
5655 | info_ptr += bytes_read; | |||
5656 | break; | |||
5657 | case DW_FORM_strp: | |||
5658 | DW_STRING (attr)((attr)->u.str) = read_indirect_string (abfd, info_ptr, cu_header, | |||
5659 | &bytes_read); | |||
5660 | info_ptr += bytes_read; | |||
5661 | break; | |||
5662 | case DW_FORM_block: | |||
5663 | blk = dwarf_alloc_block (cu); | |||
5664 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
5665 | info_ptr += bytes_read; | |||
5666 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |||
5667 | info_ptr += blk->size; | |||
5668 | DW_BLOCK (attr)((attr)->u.blk) = blk; | |||
5669 | break; | |||
5670 | case DW_FORM_block1: | |||
5671 | blk = dwarf_alloc_block (cu); | |||
5672 | blk->size = read_1_byte (abfd, info_ptr); | |||
5673 | info_ptr += 1; | |||
5674 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); | |||
5675 | info_ptr += blk->size; | |||
5676 | DW_BLOCK (attr)((attr)->u.blk) = blk; | |||
5677 | break; | |||
5678 | case DW_FORM_data1: | |||
5679 | DW_UNSND (attr)((attr)->u.unsnd) = read_1_byte (abfd, info_ptr); | |||
5680 | info_ptr += 1; | |||
5681 | break; | |||
5682 | case DW_FORM_flag: | |||
5683 | DW_UNSND (attr)((attr)->u.unsnd) = read_1_byte (abfd, info_ptr); | |||
5684 | info_ptr += 1; | |||
5685 | break; | |||
5686 | case DW_FORM_sdata: | |||
5687 | DW_SND (attr)((attr)->u.snd) = read_signed_leb128 (abfd, info_ptr, &bytes_read); | |||
5688 | info_ptr += bytes_read; | |||
5689 | break; | |||
5690 | case DW_FORM_udata: | |||
5691 | DW_UNSND (attr)((attr)->u.unsnd) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
5692 | info_ptr += bytes_read; | |||
5693 | break; | |||
5694 | case DW_FORM_ref1: | |||
5695 | DW_ADDR (attr)((attr)->u.addr) = cu->header.offset + read_1_byte (abfd, info_ptr); | |||
5696 | info_ptr += 1; | |||
5697 | break; | |||
5698 | case DW_FORM_ref2: | |||
5699 | DW_ADDR (attr)((attr)->u.addr) = cu->header.offset + read_2_bytes (abfd, info_ptr); | |||
5700 | info_ptr += 2; | |||
5701 | break; | |||
5702 | case DW_FORM_ref4: | |||
5703 | DW_ADDR (attr)((attr)->u.addr) = cu->header.offset + read_4_bytes (abfd, info_ptr); | |||
5704 | info_ptr += 4; | |||
5705 | break; | |||
5706 | case DW_FORM_ref8: | |||
5707 | DW_ADDR (attr)((attr)->u.addr) = cu->header.offset + read_8_bytes (abfd, info_ptr); | |||
5708 | info_ptr += 8; | |||
5709 | break; | |||
5710 | case DW_FORM_ref_udata: | |||
5711 | DW_ADDR (attr)((attr)->u.addr) = (cu->header.offset | |||
5712 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); | |||
5713 | info_ptr += bytes_read; | |||
5714 | break; | |||
5715 | case DW_FORM_indirect: | |||
5716 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); | |||
5717 | info_ptr += bytes_read; | |||
5718 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); | |||
5719 | break; | |||
5720 | default: | |||
5721 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", | |||
5722 | dwarf_form_name (form), | |||
5723 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5724 | } | |||
5725 | return info_ptr; | |||
5726 | } | |||
5727 | ||||
5728 | /* Read an attribute described by an abbreviated attribute. */ | |||
5729 | ||||
5730 | static char * | |||
5731 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, | |||
5732 | bfd *abfd, char *info_ptr, struct dwarf2_cu *cu) | |||
5733 | { | |||
5734 | attr->name = abbrev->name; | |||
5735 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); | |||
5736 | } | |||
5737 | ||||
5738 | /* read dwarf information from a buffer */ | |||
5739 | ||||
5740 | static unsigned int | |||
5741 | read_1_byte (bfd *abfd, char *buf) | |||
5742 | { | |||
5743 | return bfd_get_8 (abfd, (bfd_byte *) buf)(*(unsigned char *) ((bfd_byte *) buf) & 0xff); | |||
5744 | } | |||
5745 | ||||
5746 | static int | |||
5747 | read_1_signed_byte (bfd *abfd, char *buf) | |||
5748 | { | |||
5749 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf)(((*(unsigned char *) ((bfd_byte *) buf) & 0xff) ^ 0x80) - 0x80); | |||
5750 | } | |||
5751 | ||||
5752 | static unsigned int | |||
5753 | read_2_bytes (bfd *abfd, char *buf) | |||
5754 | { | |||
5755 | return bfd_get_16 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx16)) ((bfd_byte *) buf)); | |||
5756 | } | |||
5757 | ||||
5758 | static int | |||
5759 | read_2_signed_bytes (bfd *abfd, char *buf) | |||
5760 | { | |||
5761 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx_signed_16)) ((bfd_byte *) buf )); | |||
5762 | } | |||
5763 | ||||
5764 | static unsigned int | |||
5765 | read_4_bytes (bfd *abfd, char *buf) | |||
5766 | { | |||
5767 | return bfd_get_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) buf)); | |||
5768 | } | |||
5769 | ||||
5770 | static int | |||
5771 | read_4_signed_bytes (bfd *abfd, char *buf) | |||
5772 | { | |||
5773 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx_signed_32)) ((bfd_byte *) buf )); | |||
5774 | } | |||
5775 | ||||
5776 | static unsigned long | |||
5777 | read_8_bytes (bfd *abfd, char *buf) | |||
5778 | { | |||
5779 | return bfd_get_64 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx64)) ((bfd_byte *) buf)); | |||
5780 | } | |||
5781 | ||||
5782 | static CORE_ADDR | |||
5783 | read_address (bfd *abfd, char *buf, struct dwarf2_cu *cu, int *bytes_read) | |||
5784 | { | |||
5785 | struct comp_unit_head *cu_header = &cu->header; | |||
5786 | CORE_ADDR retval = 0; | |||
5787 | ||||
5788 | if (cu_header->signed_addr_p) | |||
5789 | { | |||
5790 | switch (cu_header->addr_size) | |||
5791 | { | |||
5792 | case 2: | |||
5793 | retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx_signed_16)) ((bfd_byte *) buf )); | |||
5794 | break; | |||
5795 | case 4: | |||
5796 | retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx_signed_32)) ((bfd_byte *) buf )); | |||
5797 | break; | |||
5798 | case 8: | |||
5799 | retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx_signed_64)) ((bfd_byte *) buf )); | |||
5800 | break; | |||
5801 | default: | |||
5802 | internal_error (__FILE__"/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", __LINE__5802, | |||
5803 | "read_address: bad switch, signed [in module %s]", | |||
5804 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5805 | } | |||
5806 | } | |||
5807 | else | |||
5808 | { | |||
5809 | switch (cu_header->addr_size) | |||
5810 | { | |||
5811 | case 2: | |||
5812 | retval = bfd_get_16 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx16)) ((bfd_byte *) buf)); | |||
5813 | break; | |||
5814 | case 4: | |||
5815 | retval = bfd_get_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) buf)); | |||
5816 | break; | |||
5817 | case 8: | |||
5818 | retval = bfd_get_64 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx64)) ((bfd_byte *) buf)); | |||
5819 | break; | |||
5820 | default: | |||
5821 | internal_error (__FILE__"/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", __LINE__5821, | |||
5822 | "read_address: bad switch, unsigned [in module %s]", | |||
5823 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5824 | } | |||
5825 | } | |||
5826 | ||||
5827 | *bytes_read = cu_header->addr_size; | |||
5828 | return retval; | |||
5829 | } | |||
5830 | ||||
5831 | /* Read the initial length from a section. The (draft) DWARF 3 | |||
5832 | specification allows the initial length to take up either 4 bytes | |||
5833 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 | |||
5834 | bytes describe the length and all offsets will be 8 bytes in length | |||
5835 | instead of 4. | |||
5836 | ||||
5837 | An older, non-standard 64-bit format is also handled by this | |||
5838 | function. The older format in question stores the initial length | |||
5839 | as an 8-byte quantity without an escape value. Lengths greater | |||
5840 | than 2^32 aren't very common which means that the initial 4 bytes | |||
5841 | is almost always zero. Since a length value of zero doesn't make | |||
5842 | sense for the 32-bit format, this initial zero can be considered to | |||
5843 | be an escape value which indicates the presence of the older 64-bit | |||
5844 | format. As written, the code can't detect (old format) lengths | |||
5845 | greater than 4GB. If it becomes necessary to handle lengths | |||
5846 | somewhat larger than 4GB, we could allow other small values (such | |||
5847 | as the non-sensical values of 1, 2, and 3) to also be used as | |||
5848 | escape values indicating the presence of the old format. | |||
5849 | ||||
5850 | The value returned via bytes_read should be used to increment the | |||
5851 | relevant pointer after calling read_initial_length(). | |||
5852 | ||||
5853 | As a side effect, this function sets the fields initial_length_size | |||
5854 | and offset_size in cu_header to the values appropriate for the | |||
5855 | length field. (The format of the initial length field determines | |||
5856 | the width of file offsets to be fetched later with read_offset().) | |||
5857 | ||||
5858 | [ Note: read_initial_length() and read_offset() are based on the | |||
5859 | document entitled "DWARF Debugging Information Format", revision | |||
5860 | 3, draft 8, dated November 19, 2001. This document was obtained | |||
5861 | from: | |||
5862 | ||||
5863 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf | |||
5864 | ||||
5865 | This document is only a draft and is subject to change. (So beware.) | |||
5866 | ||||
5867 | Details regarding the older, non-standard 64-bit format were | |||
5868 | determined empirically by examining 64-bit ELF files produced by | |||
5869 | the SGI toolchain on an IRIX 6.5 machine. | |||
5870 | ||||
5871 | - Kevin, July 16, 2002 | |||
5872 | ] */ | |||
5873 | ||||
5874 | static LONGESTlong | |||
5875 | read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, | |||
5876 | int *bytes_read) | |||
5877 | { | |||
5878 | LONGESTlong length = bfd_get_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) buf)); | |||
5879 | ||||
5880 | if (length == 0xffffffff) | |||
5881 | { | |||
5882 | length = bfd_get_64 (abfd, (bfd_byte *) buf + 4)((*((abfd)->xvec->bfd_getx64)) ((bfd_byte *) buf + 4)); | |||
5883 | *bytes_read = 12; | |||
5884 | } | |||
5885 | else if (length == 0) | |||
5886 | { | |||
5887 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ | |||
5888 | length = bfd_get_64 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx64)) ((bfd_byte *) buf)); | |||
5889 | *bytes_read = 8; | |||
5890 | } | |||
5891 | else | |||
5892 | { | |||
5893 | *bytes_read = 4; | |||
5894 | } | |||
5895 | ||||
5896 | if (cu_header) | |||
5897 | { | |||
5898 | gdb_assert (cu_header->initial_length_size == 0((void) ((cu_header->initial_length_size == 0 || cu_header ->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", 5901, "%s: Assertion `%s' failed." , __PRETTY_FUNCTION__, "cu_header->initial_length_size == 0 || cu_header->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12" ), 0))) | |||
5899 | || cu_header->initial_length_size == 4((void) ((cu_header->initial_length_size == 0 || cu_header ->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", 5901, "%s: Assertion `%s' failed." , __PRETTY_FUNCTION__, "cu_header->initial_length_size == 0 || cu_header->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12" ), 0))) | |||
5900 | || cu_header->initial_length_size == 8((void) ((cu_header->initial_length_size == 0 || cu_header ->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", 5901, "%s: Assertion `%s' failed." , __PRETTY_FUNCTION__, "cu_header->initial_length_size == 0 || cu_header->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12" ), 0))) | |||
5901 | || cu_header->initial_length_size == 12)((void) ((cu_header->initial_length_size == 0 || cu_header ->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", 5901, "%s: Assertion `%s' failed." , __PRETTY_FUNCTION__, "cu_header->initial_length_size == 0 || cu_header->initial_length_size == 4 || cu_header->initial_length_size == 8 || cu_header->initial_length_size == 12" ), 0))); | |||
5902 | ||||
5903 | if (cu_header->initial_length_size != 0 | |||
5904 | && cu_header->initial_length_size != *bytes_read) | |||
5905 | complaint (&symfile_complaints, | |||
5906 | "intermixed 32-bit and 64-bit DWARF sections"); | |||
5907 | ||||
5908 | cu_header->initial_length_size = *bytes_read; | |||
5909 | cu_header->offset_size = (*bytes_read == 4) ? 4 : 8; | |||
5910 | } | |||
5911 | ||||
5912 | return length; | |||
5913 | } | |||
5914 | ||||
5915 | /* Read an offset from the data stream. The size of the offset is | |||
5916 | given by cu_header->offset_size. */ | |||
5917 | ||||
5918 | static LONGESTlong | |||
5919 | read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, | |||
5920 | int *bytes_read) | |||
5921 | { | |||
5922 | LONGESTlong retval = 0; | |||
5923 | ||||
5924 | switch (cu_header->offset_size) | |||
5925 | { | |||
5926 | case 4: | |||
5927 | retval = bfd_get_32 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx32)) ((bfd_byte *) buf)); | |||
5928 | *bytes_read = 4; | |||
5929 | break; | |||
5930 | case 8: | |||
5931 | retval = bfd_get_64 (abfd, (bfd_byte *) buf)((*((abfd)->xvec->bfd_getx64)) ((bfd_byte *) buf)); | |||
5932 | *bytes_read = 8; | |||
5933 | break; | |||
5934 | default: | |||
5935 | internal_error (__FILE__"/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c", __LINE__5935, | |||
5936 | "read_offset: bad switch [in module %s]", | |||
5937 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5938 | } | |||
5939 | ||||
5940 | return retval; | |||
5941 | } | |||
5942 | ||||
5943 | static char * | |||
5944 | read_n_bytes (bfd *abfd, char *buf, unsigned int size) | |||
5945 | { | |||
5946 | /* If the size of a host char is 8 bits, we can return a pointer | |||
5947 | to the buffer, otherwise we have to copy the data to a buffer | |||
5948 | allocated on the temporary obstack. */ | |||
5949 | gdb_assert (HOST_CHAR_BIT == 8)((void) ((8 == 8) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 5949, "%s: Assertion `%s' failed.", __PRETTY_FUNCTION__, "HOST_CHAR_BIT == 8" ), 0))); | |||
5950 | return buf; | |||
5951 | } | |||
5952 | ||||
5953 | static char * | |||
5954 | read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) | |||
5955 | { | |||
5956 | /* If the size of a host char is 8 bits, we can return a pointer | |||
5957 | to the string, otherwise we have to copy the string to a buffer | |||
5958 | allocated on the temporary obstack. */ | |||
5959 | gdb_assert (HOST_CHAR_BIT == 8)((void) ((8 == 8) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 5959, "%s: Assertion `%s' failed.", __PRETTY_FUNCTION__, "HOST_CHAR_BIT == 8" ), 0))); | |||
5960 | if (*buf == '\0') | |||
5961 | { | |||
5962 | *bytes_read_ptr = 1; | |||
5963 | return NULL((void*)0); | |||
5964 | } | |||
5965 | *bytes_read_ptr = strlen (buf) + 1; | |||
5966 | return buf; | |||
5967 | } | |||
5968 | ||||
5969 | static char * | |||
5970 | read_indirect_string (bfd *abfd, char *buf, | |||
5971 | const struct comp_unit_head *cu_header, | |||
5972 | unsigned int *bytes_read_ptr) | |||
5973 | { | |||
5974 | LONGESTlong str_offset = read_offset (abfd, buf, cu_header, | |||
5975 | (int *) bytes_read_ptr); | |||
5976 | ||||
5977 | if (dwarf2_per_objfile->str_buffer == NULL((void*)0)) | |||
5978 | { | |||
5979 | error ("DW_FORM_strp used without .debug_str section [in module %s]", | |||
5980 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5981 | return NULL((void*)0); | |||
5982 | } | |||
5983 | if (str_offset >= dwarf2_per_objfile->str_size) | |||
5984 | { | |||
5985 | error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", | |||
5986 | bfd_get_filename (abfd)((char *) (abfd)->filename)); | |||
5987 | return NULL((void*)0); | |||
5988 | } | |||
5989 | gdb_assert (HOST_CHAR_BIT == 8)((void) ((8 == 8) ? 0 : (internal_error ("/usr/src/gnu/usr.bin/binutils/gdb/dwarf2read.c" , 5989, "%s: Assertion `%s' failed.", __PRETTY_FUNCTION__, "HOST_CHAR_BIT == 8" ), 0))); | |||
5990 | if (dwarf2_per_objfile->str_buffer[str_offset] == '\0') | |||
5991 | return NULL((void*)0); | |||
5992 | return dwarf2_per_objfile->str_buffer + str_offset; | |||
5993 | } | |||
5994 | ||||
5995 | static unsigned long | |||
5996 | read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) | |||
5997 | { | |||
5998 | unsigned long result; | |||
5999 | unsigned int num_read; | |||
6000 | int i, shift; | |||
6001 | unsigned char byte; | |||
6002 | ||||
6003 | result = 0; | |||
6004 | shift = 0; | |||
6005 | num_read = 0; | |||
6006 | i = 0; | |||
6007 | while (1) | |||
6008 | { | |||
6009 | byte = bfd_get_8 (abfd, (bfd_byte *) buf)(*(unsigned char *) ((bfd_byte *) buf) & 0xff); | |||
6010 | buf++; | |||
6011 | num_read++; | |||
6012 | result |= ((unsigned long)(byte & 127) << shift); | |||
6013 | if ((byte & 128) == 0) | |||
6014 | { | |||
6015 | break; | |||
6016 | } | |||
6017 | shift += 7; | |||
6018 | } | |||
6019 | *bytes_read_ptr = num_read; | |||
6020 | return result; | |||
6021 | } | |||
6022 | ||||
6023 | static long | |||
6024 | read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) | |||
6025 | { | |||
6026 | long result; | |||
6027 | int i, shift, size, num_read; | |||
6028 | unsigned char byte; | |||
6029 | ||||
6030 | result = 0; | |||
6031 | shift = 0; | |||
6032 | size = 32; | |||
6033 | num_read = 0; | |||
6034 | i = 0; | |||
6035 | while (1) | |||
6036 | { | |||
6037 | byte = bfd_get_8 (abfd, (bfd_byte *) buf)(*(unsigned char *) ((bfd_byte *) buf) & 0xff); | |||
6038 | buf++; | |||
6039 | num_read++; | |||
6040 | result |= ((long)(byte & 127) << shift); | |||
6041 | shift += 7; | |||
6042 | if ((byte & 128) == 0) | |||
6043 | { | |||
6044 | break; | |||
6045 | } | |||
6046 | } | |||
6047 | if ((shift < size) && (byte & 0x40)) | |||
6048 | { | |||
6049 | result |= -(1 << shift); | |||
6050 | } | |||
6051 | *bytes_read_ptr = num_read; | |||
6052 | return result; | |||
6053 | } | |||
6054 | ||||
6055 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ | |||
6056 | ||||
6057 | static char * | |||
6058 | skip_leb128 (bfd *abfd, char *buf) | |||
6059 | { | |||
6060 | int byte; | |||
6061 | ||||
6062 | while (1) | |||
6063 | { | |||
6064 | byte = bfd_get_8 (abfd, (bfd_byte *) buf)(*(unsigned char *) ((bfd_byte *) buf) & 0xff); | |||
6065 | buf++; | |||
6066 | if ((byte & 128) == 0) | |||
6067 | return buf; | |||
6068 | } | |||
6069 | } | |||
6070 | ||||
6071 | static void | |||
6072 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) | |||
6073 | { | |||
6074 | switch (lang) | |||
6075 | { | |||
6076 | case DW_LANG_C89: | |||
6077 | case DW_LANG_C: | |||
6078 | cu->language = language_c; | |||
6079 | break; | |||
6080 | case DW_LANG_C_plus_plus: | |||
6081 | cu->language = language_cplus; | |||
6082 | break; | |||