X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=gdb%2Fsolib-target.c;h=71a0da322c79b74412adcc4b456f057128d64f48;hb=d17f7b365cf3896b3129b9077d55b3154fc43131;hp=e40acc1823303d9f9aac2f9ddcb9e5a4edb4387d;hpb=d0e449a1865c741c5e0c9d43a7d61a0621163aa7;p=deliverable%2Fbinutils-gdb.git diff --git a/gdb/solib-target.c b/gdb/solib-target.c index e40acc1823..71a0da322c 100644 --- a/gdb/solib-target.c +++ b/gdb/solib-target.c @@ -25,28 +25,29 @@ #include "target.h" #include "vec.h" #include "solib-target.h" +#include /* Private data for each loaded library. */ struct lm_info_target : public lm_info_base { /* The library's name. The name is normally kept in the struct so_list; it is only here during XML parsing. */ - char *name; + std::string name; /* The target can either specify segment bases or section bases, not both. */ /* The base addresses for each independently relocatable segment of this shared library. */ - VEC(CORE_ADDR) *segment_bases; + std::vector segment_bases; /* The base addresses for each independently allocatable, relocatable section of this shared library. */ - VEC(CORE_ADDR) *section_bases; + std::vector section_bases; /* The cached offsets for each section of this shared library, determined from SEGMENT_BASES, or SECTION_BASES. */ - struct section_offsets *offsets; + section_offsets *offsets = NULL; }; typedef lm_info_target *lm_info_target_p; @@ -86,11 +87,11 @@ library_list_start_segment (struct gdb_xml_parser *parser, = (ULONGEST *) xml_find_attribute (attributes, "address")->value; CORE_ADDR address = (CORE_ADDR) *address_p; - if (last->section_bases != NULL) + if (!last->section_bases.empty ()) gdb_xml_error (parser, _("Library list with both segments and sections")); - VEC_safe_push (CORE_ADDR, last->segment_bases, address); + last->segment_bases.push_back (address); } static void @@ -104,11 +105,11 @@ library_list_start_section (struct gdb_xml_parser *parser, = (ULONGEST *) xml_find_attribute (attributes, "address")->value; CORE_ADDR address = (CORE_ADDR) *address_p; - if (last->segment_bases != NULL) + if (!last->segment_bases.empty ()) gdb_xml_error (parser, _("Library list with both segments and sections")); - VEC_safe_push (CORE_ADDR, last->section_bases, address); + last->section_bases.push_back (address); } /* Handle the start of a element. */ @@ -119,7 +120,7 @@ library_list_start_library (struct gdb_xml_parser *parser, void *user_data, VEC(gdb_xml_value_s) *attributes) { VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data; - lm_info_target *item = XCNEW (lm_info_target); + lm_info_target *item = new lm_info_target; const char *name = (const char *) xml_find_attribute (attributes, "name")->value; @@ -135,10 +136,8 @@ library_list_end_library (struct gdb_xml_parser *parser, VEC(lm_info_target_p) **list = (VEC(lm_info_target_p) **) user_data; lm_info_target *lm_info = VEC_last (lm_info_target_p, *list); - if (lm_info->segment_bases == NULL - && lm_info->section_bases == NULL) - gdb_xml_error (parser, - _("No segment or section bases defined")); + if (lm_info->segment_bases.empty () && lm_info->section_bases.empty ()) + gdb_xml_error (parser, _("No segment or section bases defined")); } @@ -173,12 +172,8 @@ solib_target_free_library_list (void *p) int ix; for (ix = 0; VEC_iterate (lm_info_target_p, *result, ix, info); ix++) - { - xfree (info->name); - VEC_free (CORE_ADDR, info->segment_bases); - VEC_free (CORE_ADDR, info->section_bases); - xfree (info); - } + delete info; + VEC_free (lm_info_target_p, *result); *result = NULL; } @@ -282,16 +277,16 @@ solib_target_current_sos (void) for (ix = 0; VEC_iterate (lm_info_target_p, library_list, ix, info); ix++) { new_solib = XCNEW (struct so_list); - strncpy (new_solib->so_name, info->name, SO_NAME_MAX_PATH_SIZE - 1); + strncpy (new_solib->so_name, info->name.c_str (), + SO_NAME_MAX_PATH_SIZE - 1); new_solib->so_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; - strncpy (new_solib->so_original_name, info->name, + strncpy (new_solib->so_original_name, info->name.c_str (), SO_NAME_MAX_PATH_SIZE - 1); new_solib->so_original_name[SO_NAME_MAX_PATH_SIZE - 1] = '\0'; new_solib->lm_info = info; /* We no longer need this copy of the name. */ - xfree (info->name); - info->name = NULL; + info->name.clear (); /* Add it to the list. */ if (!start) @@ -326,10 +321,9 @@ solib_target_free_so (struct so_list *so) { lm_info_target *li = (lm_info_target *) so->lm_info; - gdb_assert (li->name == NULL); - xfree (li->offsets); - VEC_free (CORE_ADDR, li->segment_bases); - xfree (li); + gdb_assert (li->name.empty ()); + + delete li; } static void @@ -349,12 +343,10 @@ solib_target_relocate_section_addresses (struct so_list *so, = ((struct section_offsets *) xzalloc (SIZEOF_N_SECTION_OFFSETS (num_sections))); - if (li->section_bases) + if (!li->section_bases.empty ()) { int i; asection *sect; - int num_section_bases - = VEC_length (CORE_ADDR, li->section_bases); int num_alloc_sections = 0; for (i = 0, sect = so->abfd->sections; @@ -363,7 +355,7 @@ solib_target_relocate_section_addresses (struct so_list *so, if ((bfd_get_section_flags (so->abfd, sect) & SEC_ALLOC)) num_alloc_sections++; - if (num_alloc_sections != num_section_bases) + if (num_alloc_sections != li->section_bases.size ()) warning (_("\ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), so->so_name); @@ -371,10 +363,6 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), { int bases_index = 0; int found_range = 0; - CORE_ADDR *section_bases; - - section_bases = VEC_address (CORE_ADDR, - li->section_bases); so->addr_low = ~(CORE_ADDR) 0; so->addr_high = 0; @@ -388,7 +376,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), { CORE_ADDR low, high; - low = section_bases[i]; + low = li->section_bases[i]; high = low + bfd_section_size (so->abfd, sect) - 1; if (low < so->addr_low) @@ -398,8 +386,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), gdb_assert (so->addr_low <= so->addr_high); found_range = 1; } - li->offsets->offsets[i] - = section_bases[bases_index]; + li->offsets->offsets[i] = li->section_bases[bases_index]; bases_index++; } if (!found_range) @@ -407,7 +394,7 @@ Could not relocate shared library \"%s\": wrong number of ALLOC sections"), gdb_assert (so->addr_low <= so->addr_high); } } - else if (li->segment_bases) + else if (!li->segment_bases.empty ()) { struct symfile_segment_data *data; @@ -419,37 +406,34 @@ Could not relocate shared library \"%s\": no segments"), so->so_name); { ULONGEST orig_delta; int i; - int num_bases; - CORE_ADDR *segment_bases; - - num_bases = VEC_length (CORE_ADDR, li->segment_bases); - segment_bases = VEC_address (CORE_ADDR, li->segment_bases); if (!symfile_map_offsets_to_segments (so->abfd, data, li->offsets, - num_bases, segment_bases)) + li->segment_bases.size (), + li->segment_bases.data ())) warning (_("\ Could not relocate shared library \"%s\": bad offsets"), so->so_name); /* Find the range of addresses to report for this library in "info sharedlibrary". Report any consecutive segments which were relocated as a single unit. */ - gdb_assert (num_bases > 0); - orig_delta = segment_bases[0] - data->segment_bases[0]; + gdb_assert (li->segment_bases.size () > 0); + orig_delta = li->segment_bases[0] - data->segment_bases[0]; for (i = 1; i < data->num_segments; i++) { /* If we have run out of offsets, assume all remaining segments have the same offset. */ - if (i >= num_bases) + if (i >= li->segment_bases.size ()) continue; /* If this segment does not have the same offset, do not include it in the library's range. */ - if (segment_bases[i] - data->segment_bases[i] != orig_delta) + if (li->segment_bases[i] - data->segment_bases[i] + != orig_delta) break; } - so->addr_low = segment_bases[0]; + so->addr_low = li->segment_bases[0]; so->addr_high = (data->segment_bases[i - 1] + data->segment_sizes[i - 1] + orig_delta);