aboutsummaryrefslogtreecommitdiff
path: root/gdb/symfile.c
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-02-24 09:55:30 -0700
committerTom Tromey <tom@tromey.com>2018-02-27 12:00:34 -0700
commit55089490f79ce1ddb9610fd6abeeaf896825fb71 (patch)
tree9e745a2bfcfc782e678ab8df7876c9f401038116 /gdb/symfile.c
parent5b616beff49ce5fe10c5efc2784b6b234bb8cb4f (diff)
downloadgdb-55089490f79ce1ddb9610fd6abeeaf896825fb71.zip
gdb-55089490f79ce1ddb9610fd6abeeaf896825fb71.tar.gz
gdb-55089490f79ce1ddb9610fd6abeeaf896825fb71.tar.bz2
Change target_write_memory_blocks to use std::vector
This changes target_write_memory_blocks to use std::vector, rather than VEC. This allows the removal of some cleanups. This version incorporates the additions that Simon made. Regression tested by the buildbot. ChangeLog 2018-02-27 Simon Marchi <simon.marchi@polymtl.ca> Tom Tromey <tom@tromey.com> * target.h (memory_write_request_s): Remove typedef. Don't define VEC. (target_write_memory_blocks): Change argument to std::vector. (struct memory_write_request): Add constructor. * target-memory.c (compare_block_starting_address): Return bool. Change argument types. (claim_memory): Change arguments to use std::vector. (split_regular_and_flash_blocks, blocks_to_erase) (compute_garbled_blocks): Likewise. (cleanup_request_data, cleanup_write_requests_vector): Remove. (target_write_memory_blocks): Change argument to std::vector. * symfile.c (struct load_section_data): Add constructor and destructor. Use std::vector for "requests". (struct load_progress_data): Add initializers. (load_section_callback): Update. Use "new". (clear_memory_write_data): Remove. (generic_load): Update.
Diffstat (limited to 'gdb/symfile.c')
-rw-r--r--gdb/symfile.c109
1 files changed, 45 insertions, 64 deletions
diff --git a/gdb/symfile.c b/gdb/symfile.c
index 699d9e6..2a1428b 100644
--- a/gdb/symfile.c
+++ b/gdb/symfile.c
@@ -1892,33 +1892,56 @@ add_section_size_callback (bfd *abfd, asection *asec, void *data)
*sum += bfd_get_section_size (asec);
}
-/* Opaque data for load_section_callback. */
-struct load_section_data {
- CORE_ADDR load_offset;
- struct load_progress_data *progress_data;
- VEC(memory_write_request_s) *requests;
-};
-
/* Opaque data for load_progress. */
-struct load_progress_data {
+struct load_progress_data
+{
/* Cumulative data. */
- unsigned long write_count;
- unsigned long data_count;
- bfd_size_type total_size;
+ unsigned long write_count = 0;
+ unsigned long data_count = 0;
+ bfd_size_type total_size = 0;
};
/* Opaque data for load_progress for a single section. */
-struct load_progress_section_data {
+struct load_progress_section_data
+{
+ load_progress_section_data (load_progress_data *cumulative_,
+ const char *section_name_, ULONGEST section_size_,
+ CORE_ADDR lma_, gdb_byte *buffer_)
+ : cumulative (cumulative_), section_name (section_name_),
+ section_size (section_size_), lma (lma_), buffer (buffer_)
+ {}
+
struct load_progress_data *cumulative;
/* Per-section data. */
const char *section_name;
- ULONGEST section_sent;
+ ULONGEST section_sent = 0;
ULONGEST section_size;
CORE_ADDR lma;
gdb_byte *buffer;
};
+/* Opaque data for load_section_callback. */
+struct load_section_data
+{
+ load_section_data (load_progress_data *progress_data_)
+ : progress_data (progress_data_)
+ {}
+
+ ~load_section_data ()
+ {
+ for (auto &&request : requests)
+ {
+ xfree (request.data);
+ delete ((load_progress_section_data *) request.baton);
+ }
+ }
+
+ CORE_ADDR load_offset = 0;
+ struct load_progress_data *progress_data;
+ std::vector<struct memory_write_request> requests;
+};
+
/* Target write callback routine for progress reporting. */
static void
@@ -1988,11 +2011,8 @@ load_progress (ULONGEST bytes, void *untyped_arg)
static void
load_section_callback (bfd *abfd, asection *asec, void *data)
{
- struct memory_write_request *new_request;
struct load_section_data *args = (struct load_section_data *) data;
- struct load_progress_section_data *section_data;
bfd_size_type size = bfd_get_section_size (asec);
- gdb_byte *buffer;
const char *sect_name = bfd_get_section_name (abfd, asec);
if ((bfd_get_section_flags (abfd, asec) & SEC_LOAD) == 0)
@@ -2001,44 +2021,16 @@ load_section_callback (bfd *abfd, asection *asec, void *data)
if (size == 0)
return;
- new_request = VEC_safe_push (memory_write_request_s,
- args->requests, NULL);
- memset (new_request, 0, sizeof (struct memory_write_request));
- section_data = XCNEW (struct load_progress_section_data);
- new_request->begin = bfd_section_lma (abfd, asec) + args->load_offset;
- new_request->end = new_request->begin + size; /* FIXME Should size
- be in instead? */
- new_request->data = (gdb_byte *) xmalloc (size);
- new_request->baton = section_data;
-
- buffer = new_request->data;
-
- section_data->cumulative = args->progress_data;
- section_data->section_name = sect_name;
- section_data->section_size = size;
- section_data->lma = new_request->begin;
- section_data->buffer = buffer;
-
+ ULONGEST begin = bfd_section_lma (abfd, asec) + args->load_offset;
+ ULONGEST end = begin + size;
+ gdb_byte *buffer = (gdb_byte *) xmalloc (size);
bfd_get_section_contents (abfd, asec, buffer, 0, size);
-}
-/* Clean up an entire memory request vector, including load
- data and progress records. */
+ load_progress_section_data *section_data
+ = new load_progress_section_data (args->progress_data, sect_name, size,
+ begin, buffer);
-static void
-clear_memory_write_data (void *arg)
-{
- VEC(memory_write_request_s) **vec_p = (VEC(memory_write_request_s) **) arg;
- VEC(memory_write_request_s) *vec = *vec_p;
- int i;
- struct memory_write_request *mr;
-
- for (i = 0; VEC_iterate (memory_write_request_s, vec, i, mr); ++i)
- {
- xfree (mr->data);
- xfree (mr->baton);
- }
- VEC_free (memory_write_request_s, vec);
+ args->requests.emplace_back (begin, end, buffer, section_data);
}
static void print_transfer_performance (struct ui_file *stream,
@@ -2049,19 +2041,10 @@ static void print_transfer_performance (struct ui_file *stream,
void
generic_load (const char *args, int from_tty)
{
- struct cleanup *old_cleanups;
- struct load_section_data cbdata;
struct load_progress_data total_progress;
+ struct load_section_data cbdata (&total_progress);
struct ui_out *uiout = current_uiout;
- CORE_ADDR entry;
-
- memset (&cbdata, 0, sizeof (cbdata));
- memset (&total_progress, 0, sizeof (total_progress));
- cbdata.progress_data = &total_progress;
-
- old_cleanups = make_cleanup (clear_memory_write_data, &cbdata.requests);
-
if (args == NULL)
error_no_arg (_("file to load"));
@@ -2110,7 +2093,7 @@ generic_load (const char *args, int from_tty)
steady_clock::time_point end_time = steady_clock::now ();
- entry = bfd_get_start_address (loadfile_bfd.get ());
+ CORE_ADDR entry = bfd_get_start_address (loadfile_bfd.get ());
entry = gdbarch_addr_bits_remove (target_gdbarch (), entry);
uiout->text ("Start address ");
uiout->field_fmt ("address", "%s", paddress (target_gdbarch (), entry));
@@ -2132,8 +2115,6 @@ generic_load (const char *args, int from_tty)
print_transfer_performance (gdb_stdout, total_progress.data_count,
total_progress.write_count,
end_time - start_time);
-
- do_cleanups (old_cleanups);
}
/* Report on STREAM the performance of a memory transfer operation,