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