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