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