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