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