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