From 5486c5174894a1a6e68b9fdf1865b838b9c792d8 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Sat, 19 Sep 2020 11:54:49 -0600 Subject: [PATCH] Use gdb_bfd_sections in generic_load This changes generic_load to avoid bfd_map_over_sections, in favor of iteration. gdb/ChangeLog 2020-09-19 Tom Tromey * symfile.c (add_section_size_callback): Remove. (load_one_section): Rename from load_section_callback. Change parameters. (generic_load): Use foreach. --- gdb/ChangeLog | 7 +++++++ gdb/symfile.c | 23 +++++++---------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 7a5e122983d..131ec931708 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,10 @@ +2020-09-19 Tom Tromey + + * symfile.c (add_section_size_callback): Remove. + (load_one_section): Rename from load_section_callback. Change + parameters. + (generic_load): Use foreach. + 2020-09-19 Tom Tromey * exec.c (add_to_section_table): Remove. diff --git a/gdb/symfile.c b/gdb/symfile.c index 97a6d4b6676..baed72e936e 100644 --- a/gdb/symfile.c +++ b/gdb/symfile.c @@ -1842,16 +1842,6 @@ load_command (const char *arg, int from_tty) static int validate_download = 0; -/* Callback service function for generic_load (bfd_map_over_sections). */ - -static void -add_section_size_callback (bfd *abfd, asection *asec, void *data) -{ - bfd_size_type *sum = (bfd_size_type *) data; - - *sum += bfd_section_size (asec); -} - /* Opaque data for load_progress. */ struct load_progress_data { @@ -1966,12 +1956,12 @@ load_progress (ULONGEST bytes, void *untyped_arg) totals->total_size); } -/* Callback service function for generic_load (bfd_map_over_sections). */ +/* Service function for generic_load. */ static void -load_section_callback (bfd *abfd, asection *asec, void *data) +load_one_section (bfd *abfd, asection *asec, + struct load_section_data *args) { - struct load_section_data *args = (struct load_section_data *) data; bfd_size_type size = bfd_section_size (asec); const char *sect_name = bfd_section_name (asec); @@ -2040,10 +2030,11 @@ generic_load (const char *args, int from_tty) bfd_errmsg (bfd_get_error ())); } - bfd_map_over_sections (loadfile_bfd.get (), add_section_size_callback, - (void *) &total_progress.total_size); + for (asection *asec : gdb_bfd_sections (loadfile_bfd)) + total_progress.total_size += bfd_section_size (asec); - bfd_map_over_sections (loadfile_bfd.get (), load_section_callback, &cbdata); + for (asection *asec : gdb_bfd_sections (loadfile_bfd)) + load_one_section (loadfile_bfd.get (), asec, &cbdata); using namespace std::chrono; -- 2.30.2