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