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