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