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