X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=gdb%2Fdwarf2read.c;h=da895737dced49979f7cc738e6ab157d4b038224;hb=359cc68c808f70750a020c9bb76de330735a3202;hp=0d4f61ac467630ffbd3ed2ce37c66bf51aeae79d;hpb=48cb83fdd097716c0f21511e0e5b475bb1f2aa41;p=binutils-gdb.git diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 0d4f61ac467..da895737dce 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1133,6 +1133,7 @@ dwarf2_has_info (struct objfile *objfile) /* Initialize per-objfile state. */ struct dwarf2_per_objfile *data = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); + memset (data, 0, sizeof (*data)); set_objfile_data (objfile, dwarf2_objfile_data_key, data); dwarf2_per_objfile = data; @@ -1201,6 +1202,7 @@ dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) else if (section_is_p (sectp->name, EH_FRAME_SECTION)) { flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); + if (aflag & SEC_HAS_CONTENTS) { dwarf2_per_objfile->eh_frame.asection = sectp; @@ -1443,6 +1445,7 @@ offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) unsigned int top = (cu_header->offset + cu_header->length + cu_header->initial_length_size); + return (offset >= bottom && offset < top); } @@ -1584,6 +1587,7 @@ dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, if (attr) { unsigned int line_offset = DW_UNSND (attr); + lh = dwarf_decode_line_header (line_offset, abfd, cu); } if (lh == NULL) @@ -1598,6 +1602,7 @@ static hashval_t hash_type_signature (const void *item) { const struct signatured_type *type_sig = item; + /* This drops the top 32 bits of the signature, but is ok for a hash. */ return type_sig->signature; } @@ -1607,6 +1612,7 @@ eq_type_signature (const void *item_lhs, const void *item_rhs) { const struct signatured_type *lhs = item_lhs; const struct signatured_type *rhs = item_rhs; + return lhs->signature == rhs->signature; } @@ -2881,6 +2887,7 @@ dwarf2_psymtab_to_symtab (struct partial_symtab *pst) struct dwarf2_per_objfile *dpo_backlink = objfile_data (pst->objfile->separate_debug_objfile_backlink, dwarf2_objfile_data_key); + dwarf2_per_objfile->has_section_at_zero = dpo_backlink->has_section_at_zero; } @@ -3187,6 +3194,8 @@ process_die (struct die_info *die, struct dwarf2_cu *cu) case DW_TAG_base_type: case DW_TAG_subrange_type: case DW_TAG_typedef: + case DW_TAG_const_type: + case DW_TAG_volatile_type: /* Add a typedef symbol for the type definition, if it has a DW_AT_name. */ new_symbol (die, read_type_die (die, cu), cu); @@ -3250,6 +3259,7 @@ die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) if (dwarf2_attr (die, DW_AT_specification, cu)) { struct dwarf2_cu *spec_cu = cu; + return die_needs_namespace (die_specification (die, &spec_cu), spec_cu); } @@ -3303,6 +3313,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, if (*prefix != '\0') { char *prefixed_name = typename_concat (NULL, prefix, name, cu); + fputs_unfiltered (prefixed_name, buf); xfree (prefixed_name); } @@ -3346,6 +3357,7 @@ dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, char *cname = dwarf2_canonicalize_name (name, cu, &cu->objfile->objfile_obstack); + if (cname != NULL) name = cname; } @@ -3623,6 +3635,7 @@ read_file_scope (struct die_info *die, struct dwarf2_cu *cu) if (attr && line_header) { unsigned int macro_offset = DW_UNSND (attr); + dwarf_decode_macros (line_header, macro_offset, comp_dir, abfd, cu); } @@ -3791,6 +3804,7 @@ inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) but GCC versions at least through 4.4 generate this (GCC PR 40573). */ struct die_info *child_origin_die = child_die; + while (1) { attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, cu); @@ -3890,9 +3904,11 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) /* Ignore functions with missing or invalid low and high pc attributes. */ if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) { - complaint (&symfile_complaints, - _("cannot get low and high bounds for subprogram DIE at %d"), - die->offset); + attr = dwarf2_attr (die, DW_AT_external, cu); + if (!attr || !DW_UNSND (attr)) + complaint (&symfile_complaints, + _("cannot get low and high bounds for subprogram DIE at %d"), + die->offset); return; } @@ -4341,10 +4357,12 @@ dwarf2_record_block_ranges (struct die_info *die, struct block *block, if (attr) { CORE_ADDR high = DW_ADDR (attr); + attr = dwarf2_attr (die, DW_AT_low_pc, cu); if (attr) { CORE_ADDR low = DW_ADDR (attr); + record_block_range (block, baseaddr + low, baseaddr + high - 1); } } @@ -4882,6 +4900,7 @@ dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, && DW_BLOCK (attr)->data[0] == DW_OP_deref) { struct dwarf_block blk; + blk.size = DW_BLOCK (attr)->size - 1; blk.data = DW_BLOCK (attr)->data + 1; fnp->voffset = decode_locdesc (&blk, cu); @@ -5042,6 +5061,7 @@ read_structure_type (struct die_info *die, struct dwarf2_cu *cu) { struct dwarf2_cu *type_cu = cu; struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); + /* We could just recurse on read_structure_type, but we need to call get_die_type to ensure only one type for this DIE is created. This is important, for example, because for c++ classes we need @@ -5286,6 +5306,7 @@ read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) { struct dwarf2_cu *type_cu = cu; struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); + type = read_type_die (type_die, type_cu); return set_die_type (die, type, cu); } @@ -5430,6 +5451,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) if (child_die->tag == DW_TAG_subrange_type) { struct type *child_type = read_type_die (child_die, cu); + if (child_type != NULL) { /* The range type was succesfully read. Save it for @@ -5456,6 +5478,7 @@ read_array_type (struct die_info *die, struct dwarf2_cu *cu) if (read_array_order (die, cu) == DW_ORD_col_major) { int i = 0; + while (i < ndim) type = create_array_type (NULL, type, range_types[i++]); } @@ -5528,7 +5551,10 @@ static struct type * read_set_type (struct die_info *die, struct dwarf2_cu *cu) { struct type *set_type = create_set_type (NULL, die_type (die, cu)); + struct attribute *attr = dwarf2_attr (die, DW_AT_byte_size, cu); + if (attr) + TYPE_LENGTH (set_type) = DW_UNSND (attr); return set_die_type (die, set_type, cu); } @@ -5603,6 +5629,7 @@ read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) { struct die_info *ext_die; struct dwarf2_cu *ext_cu = cu; + ext_die = dwarf2_extension (die, &ext_cu); type = read_type_die (ext_die, ext_cu); return set_die_type (die, type, cu); @@ -5650,6 +5677,7 @@ read_namespace (struct die_info *die, struct dwarf2_cu *cu) if (is_anonymous) { const char *previous_prefix = determine_prefix (die, cu); + cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, NULL, &objfile->objfile_obstack); } @@ -5759,9 +5787,10 @@ read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) { complaint (&symfile_complaints, _("invalid pointer size %d"), byte_size); } - else { - /* Should we also complain about unhandled address classes? */ - } + else + { + /* Should we also complain about unhandled address classes? */ + } } TYPE_LENGTH (type) = byte_size; @@ -5972,6 +6001,7 @@ read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) if (cu->language == language_java) { const char *name = dwarf2_name (child_die, cu); + if (name && !strcmp (name, "this")) TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; } @@ -6101,16 +6131,8 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) LONGEST high = -1; char *name; LONGEST negative_mask; - + base_type = die_type (die, cu); - if (TYPE_CODE (base_type) == TYPE_CODE_VOID) - { - complaint (&symfile_complaints, - _("DW_AT_type missing from DW_TAG_subrange_type")); - base_type - = init_type (TYPE_CODE_INT, gdbarch_addr_bit (gdbarch) / 8, - 0, NULL, cu->objfile); - } if (cu->language == language_fortran) { @@ -6128,10 +6150,10 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_upper_bound, cu); if (attr) { - if (attr->form == DW_FORM_block1) + if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) { /* GCC encodes arrays with unspecified or dynamic length - with a DW_FORM_block1 attribute. + with a DW_FORM_block1 attribute or a reference attribute. FIXME: GDB does not yet know how to handle dynamic arrays properly, treat them as arrays with unspecified length for now. @@ -6146,6 +6168,54 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) else high = dwarf2_get_attr_constant_value (attr, 1); } + else + { + attr = dwarf2_attr (die, DW_AT_count, cu); + if (attr) + { + int count = dwarf2_get_attr_constant_value (attr, 1); + high = low + count - 1; + } + } + + /* Dwarf-2 specifications explicitly allows to create subrange types + without specifying a base type. + In that case, the base type must be set to the type of + the lower bound, upper bound or count, in that order, if any of these + three attributes references an object that has a type. + If no base type is found, the Dwarf-2 specifications say that + a signed integer type of size equal to the size of an address should + be used. + For the following C code: `extern char gdb_int [];' + GCC produces an empty range DIE. + FIXME: muller/2010-05-28: Possible references to object for low bound, + high bound or count are not yet handled by this code. + */ + if (TYPE_CODE (base_type) == TYPE_CODE_VOID) + { + struct objfile *objfile = cu->objfile; + struct gdbarch *gdbarch = get_objfile_arch (objfile); + int addr_size = gdbarch_addr_bit (gdbarch) /8; + struct type *int_type = objfile_type (objfile)->builtin_int; + + /* Test "int", "long int", and "long long int" objfile types, + and select the first one having a size above or equal to the + architecture address size. */ + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + else + { + int_type = objfile_type (objfile)->builtin_long_long; + if (int_type && TYPE_LENGTH (int_type) >= addr_size) + base_type = int_type; + } + } + } negative_mask = (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); @@ -6195,6 +6265,7 @@ static hashval_t die_hash (const void *item) { const struct die_info *die = item; + return die->offset; } @@ -6206,6 +6277,7 @@ die_eq (const void *item_lhs, const void *item_rhs) { const struct die_info *die_lhs = item_lhs; const struct die_info *die_rhs = item_rhs; + return die_lhs->offset == die_rhs->offset; } @@ -7430,6 +7502,7 @@ read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, unsigned int *bytes_read) { LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); + *bytes_read = cu_header->offset_size; return offset; } @@ -8312,6 +8385,7 @@ dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, for (i = 0; i < lh->num_file_names; i++) { char *dir = NULL; + fe = &lh->file_names[i]; if (fe->dir_index) dir = lh->include_dirs[fe->dir_index - 1]; @@ -8493,6 +8567,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) if (attr) { int file_index = DW_UNSND (attr); + if (cu->line_header == NULL || file_index > cu->line_header->num_file_names) complaint (&symfile_complaints, @@ -8500,6 +8575,7 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) else if (file_index > 0) { struct file_entry *fe; + fe = &cu->line_header->file_names[file_index - 1]; SYMBOL_SYMTAB (sym) = fe->symtab; } @@ -8630,6 +8706,15 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) { dwarf2_const_value (attr, sym, cu); } + attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); + if (attr && DW_UNSND (attr)) + { + struct type *ref_type; + + ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); + SYMBOL_TYPE (sym) = ref_type; + } + add_symbol_to_list (sym, cu->list_in_scope); break; case DW_TAG_unspecified_parameters: @@ -8710,6 +8795,8 @@ new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) break; case DW_TAG_base_type: case DW_TAG_subrange_type: + case DW_TAG_const_type: + case DW_TAG_volatile_type: SYMBOL_CLASS (sym) = LOC_TYPEDEF; SYMBOL_DOMAIN (sym) = VAR_DOMAIN; add_symbol_to_list (sym, cu->list_in_scope); @@ -8877,7 +8964,6 @@ dwarf2_const_value_data (struct attribute *attr, static struct type * die_type (struct die_info *die, struct dwarf2_cu *cu) { - struct type *type; struct attribute *type_attr; struct die_info *type_die; @@ -8890,14 +8976,7 @@ die_type (struct die_info *die, struct dwarf2_cu *cu) type_die = follow_die_ref_or_sig (die, type_attr, &cu); - type = tag_type_to_type (type_die, cu); - if (!type) - { - dump_die_for_error (type_die); - error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), - cu->objfile->name); - } - return type; + return tag_type_to_type (type_die, cu); } /* True iff CU's producer generates GNAT Ada auxiliary information @@ -8926,7 +9005,6 @@ need_gnat_info (struct dwarf2_cu *cu) static struct type * die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) { - struct type *type; struct attribute *type_attr; struct die_info *type_die; @@ -8935,14 +9013,7 @@ die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) return NULL; type_die = follow_die_ref (die, type_attr, &cu); - type = tag_type_to_type (type_die, cu); - if (!type) - { - dump_die_for_error (type_die); - error (_("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]"), - cu->objfile->name); - } - return type; + return tag_type_to_type (type_die, cu); } /* If DIE has a descriptive_type attribute, then set the TYPE's @@ -8967,24 +9038,16 @@ set_descriptive_type (struct type *type, struct die_info *die, static struct type * die_containing_type (struct die_info *die, struct dwarf2_cu *cu) { - struct type *type = NULL; struct attribute *type_attr; - struct die_info *type_die = NULL; + struct die_info *type_die; type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); - if (type_attr) - { - type_die = follow_die_ref_or_sig (die, type_attr, &cu); - type = tag_type_to_type (type_die, cu); - } - if (!type) - { - if (type_die) - dump_die_for_error (type_die); - error (_("Dwarf Error: Problem turning containing type into gdb type [in module %s]"), - cu->objfile->name); - } - return type; + if (!type_attr) + error (_("Dwarf Error: Problem turning containing type into gdb type " + "[in module %s]"), cu->objfile->name); + + type_die = follow_die_ref_or_sig (die, type_attr, &cu); + return tag_type_to_type (type_die, cu); } static struct type * @@ -9192,6 +9255,7 @@ typename_concat (struct obstack *obs, const char *prefix, const char *suffix, if (obs == NULL) { char *retval = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); + strcpy (retval, prefix); strcat (retval, sep); strcat (retval, suffix); @@ -10601,6 +10665,7 @@ follow_die_ref (struct die_info *src_die, struct attribute *attr, else if (! offset_in_cu_p (&cu->header, offset)) { struct dwarf2_per_cu_data *per_cu; + per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); /* If necessary, add it to the queue and load its DIEs. */ @@ -11088,6 +11153,7 @@ file_full_name (int file, struct line_header *lh, const char *comp_dir) record the macro definitions made in the file, even if we won't be able to find the file by name. */ char fake_name[80]; + sprintf (fake_name, "", file); complaint (&symfile_complaints, @@ -11133,9 +11199,9 @@ static char * copy_string (const char *buf, int len) { char *s = xmalloc (len + 1); + memcpy (s, buf, len); s[len] = '\0'; - return s; } @@ -11713,8 +11779,8 @@ dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) struct dwarf2_per_objfile *per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; - struct comp_unit_head cu_header; + memset (&cu_header, 0, sizeof cu_header); read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); return cu_header.addr_size; @@ -11736,6 +11802,7 @@ dwarf2_find_containing_comp_unit (unsigned int offset, while (high > low) { int mid = low + (high - low) / 2; + if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) high = mid; else @@ -11770,6 +11837,7 @@ static struct dwarf2_per_cu_data * dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) { struct dwarf2_per_cu_data *this_cu; + this_cu = dwarf2_find_containing_comp_unit (offset, objfile); if (this_cu->offset != offset) error (_("no compilation unit with offset %u."), offset); @@ -11955,6 +12023,7 @@ static hashval_t offset_and_type_hash (const void *item) { const struct dwarf2_offset_and_type *ofs = item; + return ofs->offset; } @@ -11965,6 +12034,7 @@ offset_and_type_eq (const void *item_lhs, const void *item_rhs) { const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; + return ofs_lhs->offset == ofs_rhs->offset; } @@ -12102,6 +12172,7 @@ static hashval_t partial_die_hash (const void *item) { const struct partial_die_info *part_die = item; + return part_die->offset; } @@ -12113,6 +12184,7 @@ partial_die_eq (const void *item_lhs, const void *item_rhs) { const struct partial_die_info *part_die_lhs = item_lhs; const struct partial_die_info *part_die_rhs = item_rhs; + return part_die_lhs->offset == part_die_rhs->offset; } @@ -12142,6 +12214,7 @@ munmap_section_buffer (struct dwarf2_section_info *info) intptr_t begin = (intptr_t) info->buffer; intptr_t map_begin = begin & ~(pagesize - 1); size_t map_length = info->size + begin - map_begin; + gdb_assert (munmap ((void *) map_begin, map_length) == 0); #else /* Without HAVE_MMAP, we should never be here to begin with. */ @@ -12156,6 +12229,7 @@ static void dwarf2_per_objfile_free (struct objfile *objfile, void *d) { struct dwarf2_per_objfile *data = d; + munmap_section_buffer (&data->info); munmap_section_buffer (&data->abbrev); munmap_section_buffer (&data->line);