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