diff options
Diffstat (limited to 'gdb/dwarf2read.c')
-rw-r--r-- | gdb/dwarf2read.c | 158 |
1 files changed, 132 insertions, 26 deletions
diff --git a/gdb/dwarf2read.c b/gdb/dwarf2read.c index 6658a38..678da8f 100644 --- a/gdb/dwarf2read.c +++ b/gdb/dwarf2read.c @@ -1764,7 +1764,8 @@ static void read_signatured_type (struct signatured_type *); static int attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, struct dwarf2_cu *cu, - struct dynamic_prop *prop); + struct dynamic_prop *prop, const gdb_byte *additional_data, + int additional_data_size); /* memory allocation interface */ @@ -11437,7 +11438,7 @@ read_func_scope (struct die_info *die, struct dwarf2_cu *cu) { newobj->static_link = XOBNEW (&objfile->objfile_obstack, struct dynamic_prop); - attr_to_dynamic_prop (attr, die, cu, newobj->static_link); + attr_to_dynamic_prop (attr, die, cu, newobj->static_link, NULL, 0); } cu->list_in_scope = &local_symbols; @@ -14495,29 +14496,94 @@ read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) struct gdbarch *gdbarch = get_objfile_arch (objfile); struct type *type, *range_type, *index_type, *char_type; struct attribute *attr; - unsigned int length; + unsigned int length = UINT_MAX; + + index_type = objfile_type (objfile)->builtin_int; + range_type = create_static_range_type (NULL, index_type, 1, length); + /* If DW_AT_string_length is defined, the length is stored in memory. */ attr = dwarf2_attr (die, DW_AT_string_length, cu); if (attr) { - length = DW_UNSND (attr); + if (attr_form_is_block (attr)) + { + struct attribute *byte_size, *bit_size; + struct dynamic_prop high; + + byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); + bit_size = dwarf2_attr (die, DW_AT_bit_size, cu); + + /* DW_AT_byte_size should never occur in combination with + DW_AT_bit_size. */ + if (byte_size != NULL && bit_size != NULL) + complaint (&symfile_complaints, + _("DW_AT_byte_size AND " + "DW_AT_bit_size found together at the same time.")); + + /* If DW_AT_string_length AND DW_AT_byte_size exist together, + DW_AT_byte_size describes the number of bytes that should be read + from the length memory location. */ + if (byte_size != NULL) + { + /* Build new dwarf2_locexpr_baton structure with additions to the + data attribute, to reflect DWARF specialities to get address + sizes. */ + const gdb_byte append_ops[] = + { + /* DW_OP_deref_size: size of an address on the target machine + (bytes), where the size will be specified by the next + operand. */ + DW_OP_deref_size, + /* Operand for DW_OP_deref_size. */ + DW_UNSND(byte_size) }; + + if (!attr_to_dynamic_prop (attr, die, cu, &high, append_ops, + ARRAY_SIZE(append_ops))) + complaint (&symfile_complaints, + _("Could not parse DW_AT_byte_size")); + } + else if (bit_size != NULL) + complaint (&symfile_complaints, + _("DW_AT_string_length AND " + "DW_AT_bit_size found but not supported yet.")); + /* If DW_AT_string_length WITHOUT DW_AT_byte_size exist, the default + is the address size of the target machine. */ + else + { + const gdb_byte append_ops[] = + { DW_OP_deref }; + + if (!attr_to_dynamic_prop (attr, die, cu, &high, append_ops, + ARRAY_SIZE(append_ops))) + complaint (&symfile_complaints, + _("Could not parse DW_AT_string_length")); + } + + TYPE_RANGE_DATA (range_type)->high = high; + } + else + { + TYPE_HIGH_BOUND (range_type) = DW_UNSND(attr); + TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST; + } } else { - /* Check for the DW_AT_byte_size attribute. */ + /* Check for the DW_AT_byte_size attribute, which represents the length + in this case. */ attr = dwarf2_attr (die, DW_AT_byte_size, cu); if (attr) - { - length = DW_UNSND (attr); - } + { + TYPE_HIGH_BOUND (range_type) = DW_UNSND(attr); + TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST; + } else - { - length = 1; - } + { + TYPE_HIGH_BOUND (range_type) = 1; + TYPE_HIGH_BOUND_KIND (range_type) = PROP_CONST; + } } - index_type = objfile_type (objfile)->builtin_int; - range_type = create_static_range_type (NULL, index_type, 1, length); char_type = language_string_char_type (cu->language_defn, gdbarch); type = create_string_type (NULL, char_type, range_type); @@ -14847,7 +14913,8 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu) static int attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, - struct dwarf2_cu *cu, struct dynamic_prop *prop) + struct dwarf2_cu *cu, struct dynamic_prop *prop, + const gdb_byte *additional_data, int additional_data_size) { struct dwarf2_property_baton *baton; struct obstack *obstack = &cu->objfile->objfile_obstack; @@ -14857,14 +14924,33 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, if (attr_form_is_block (attr)) { - baton = XOBNEW (obstack, struct dwarf2_property_baton); + baton = XOBNEW(obstack, struct dwarf2_property_baton); baton->referenced_type = NULL; baton->locexpr.per_cu = cu->per_cu; - baton->locexpr.size = DW_BLOCK (attr)->size; - baton->locexpr.data = DW_BLOCK (attr)->data; + + if (additional_data != NULL && additional_data_size > 0) + { + gdb_byte *data; + + data = (gdb_byte *) obstack_alloc( + &cu->objfile->objfile_obstack, + DW_BLOCK (attr)->size + additional_data_size); + memcpy (data, DW_BLOCK (attr)->data, DW_BLOCK (attr)->size); + memcpy (data + DW_BLOCK (attr)->size, additional_data, + additional_data_size); + + baton->locexpr.data = data; + baton->locexpr.size = DW_BLOCK (attr)->size + additional_data_size; + } + else + { + baton->locexpr.data = DW_BLOCK (attr)->data; + baton->locexpr.size = DW_BLOCK (attr)->size; + } + prop->data.baton = baton; prop->kind = PROP_LOCEXPR; - gdb_assert (prop->data.baton != NULL); + gdb_assert(prop->data.baton != NULL); } else if (attr_form_is_ref (attr)) { @@ -14897,8 +14983,28 @@ attr_to_dynamic_prop (const struct attribute *attr, struct die_info *die, baton = XOBNEW (obstack, struct dwarf2_property_baton); baton->referenced_type = die_type (target_die, target_cu); baton->locexpr.per_cu = cu->per_cu; - baton->locexpr.size = DW_BLOCK (target_attr)->size; - baton->locexpr.data = DW_BLOCK (target_attr)->data; + + if (additional_data != NULL && additional_data_size > 0) + { + gdb_byte *data; + + data = (gdb_byte *) obstack_alloc (&cu->objfile->objfile_obstack, + DW_BLOCK (target_attr)->size + additional_data_size); + memcpy (data, DW_BLOCK (target_attr)->data, + DW_BLOCK (target_attr)->size); + memcpy (data + DW_BLOCK (target_attr)->size, + additional_data, additional_data_size); + + baton->locexpr.data = data; + baton->locexpr.size = (DW_BLOCK (target_attr)->size + + additional_data_size); + } + else + { + baton->locexpr.data = DW_BLOCK (target_attr)->data; + baton->locexpr.size = DW_BLOCK (target_attr)->size; + } + prop->data.baton = baton; prop->kind = PROP_LOCEXPR; gdb_assert (prop->data.baton != NULL); @@ -15008,17 +15114,17 @@ read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_lower_bound, cu); if (attr) - attr_to_dynamic_prop (attr, die, cu, &low); + attr_to_dynamic_prop (attr, die, cu, &low, NULL, 0); else if (!low_default_is_valid) complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " "- DIE at 0x%x [in module %s]"), die->offset.sect_off, objfile_name (cu->objfile)); attr = dwarf2_attr (die, DW_AT_upper_bound, cu); - if (!attr_to_dynamic_prop (attr, die, cu, &high)) + if (!attr_to_dynamic_prop (attr, die, cu, &high, NULL, 0)) { attr = dwarf2_attr (die, DW_AT_count, cu); - if (attr_to_dynamic_prop (attr, die, cu, &high)) + if (attr_to_dynamic_prop (attr, die, cu, &high, NULL, 0)) { /* If bounds are constant do the final calculation here. */ if (low.kind == PROP_CONST && high.kind == PROP_CONST) @@ -22389,7 +22495,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_allocated, cu); if (attr_form_is_block (attr)) { - if (attr_to_dynamic_prop (attr, die, cu, &prop)) + if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0)) add_dyn_prop (DYN_PROP_ALLOCATED, prop, type, objfile); } else if (attr != NULL) @@ -22404,7 +22510,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) attr = dwarf2_attr (die, DW_AT_associated, cu); if (attr_form_is_block (attr)) { - if (attr_to_dynamic_prop (attr, die, cu, &prop)) + if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0)) add_dyn_prop (DYN_PROP_ASSOCIATED, prop, type, objfile); } else if (attr != NULL) @@ -22417,7 +22523,7 @@ set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) /* Read DW_AT_data_location and set in type. */ attr = dwarf2_attr (die, DW_AT_data_location, cu); - if (attr_to_dynamic_prop (attr, die, cu, &prop)) + if (attr_to_dynamic_prop (attr, die, cu, &prop, NULL, 0)) add_dyn_prop (DYN_PROP_DATA_LOCATION, prop, type, objfile); if (dwarf2_per_objfile->die_type_hash == NULL) |