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