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