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