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