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