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