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