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