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