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