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