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