diff options
author | Tom Tromey <tom@tromey.com> | 2018-09-15 14:53:53 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-09-18 10:18:04 -0600 |
commit | 40f03055a23b7d77e18e14264046d8e21b6abf67 (patch) | |
tree | 47aa3286077ca10dbee01d4d2043025ca49395d7 | |
parent | c9e0a7e333107ad140d9e15110f8820115921555 (diff) | |
download | gdb-40f03055a23b7d77e18e14264046d8e21b6abf67.zip gdb-40f03055a23b7d77e18e14264046d8e21b6abf67.tar.gz gdb-40f03055a23b7d77e18e14264046d8e21b6abf67.tar.bz2 |
Remove remaining cleanups from compile-object-load.c
This removes the remaining cleanups from compile-object-load.c.
gdb/ChangeLog
2018-09-18 Tom Tromey <tom@tromey.com>
* compile/compile-object-load.c (struct
link_hash_table_cleanup_data): Add constructor and destructor.
Use DISABLE_COPY_AND_ASSIGN.
(~link_hash_table_cleanup_data): Rename from
link_hash_table_free. Now a destructor.
(copy_sections): Use gdb::unique_xmalloc_ptr. Remove cleanups.
-rw-r--r-- | gdb/ChangeLog | 9 | ||||
-rw-r--r-- | gdb/compile/compile-object-load.c | 64 |
2 files changed, 46 insertions, 27 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index a26e35a..328d48e 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,14 @@ 2018-09-18 Tom Tromey <tom@tromey.com> + * compile/compile-object-load.c (struct + link_hash_table_cleanup_data): Add constructor and destructor. + Use DISABLE_COPY_AND_ASSIGN. + (~link_hash_table_cleanup_data): Rename from + link_hash_table_free. Now a destructor. + (copy_sections): Use gdb::unique_xmalloc_ptr. Remove cleanups. + +2018-09-18 Tom Tromey <tom@tromey.com> + * compile/compile-object-run.c (do_module_cleanup): Use delete. * compile/compile-object-load.c (struct munmap_list): Move to header file. diff --git a/gdb/compile/compile-object-load.c b/gdb/compile/compile-object-load.c index 9a6069f..1a7b633 100644 --- a/gdb/compile/compile-object-load.c +++ b/gdb/compile/compile-object-load.c @@ -49,7 +49,18 @@ munmap_list::add (CORE_ADDR addr, CORE_ADDR size) munmap_list::~munmap_list () { for (auto &item : items) - gdbarch_infcall_munmap (target_gdbarch (), item.addr, item.size); + { + TRY + { + gdbarch_infcall_munmap (target_gdbarch (), item.addr, item.size); + } + CATCH (ex, RETURN_MASK_ERROR) + { + /* There's not much the user can do, so just ignore + this. */ + } + END_CATCH + } } /* Helper data for setup_sections. */ @@ -282,22 +293,26 @@ static const struct bfd_link_callbacks link_callbacks = struct link_hash_table_cleanup_data { - bfd *abfd; - bfd *link_next; -}; + explicit link_hash_table_cleanup_data (bfd *abfd_) + : abfd (abfd_), + link_next (abfd->link.next) + { + } -/* Cleanup callback for struct bfd_link_info. */ + ~link_hash_table_cleanup_data () + { + if (abfd->is_linker_output) + (*abfd->link.hash->hash_table_free) (abfd); + abfd->link.next = link_next; + } -static void -link_hash_table_free (void *d) -{ - struct link_hash_table_cleanup_data *data - = (struct link_hash_table_cleanup_data *) d; + DISABLE_COPY_AND_ASSIGN (link_hash_table_cleanup_data); - if (data->abfd->is_linker_output) - (*data->abfd->link.hash->hash_table_free) (data->abfd); - data->abfd->link.next = data->link_next; -} +private: + + bfd *abfd; + bfd *link_next; +}; /* Relocate and store into inferior memory each section SECT of ABFD. */ @@ -305,12 +320,10 @@ static void copy_sections (bfd *abfd, asection *sect, void *data) { asymbol **symbol_table = (asymbol **) data; - bfd_byte *sect_data, *sect_data_got; - struct cleanup *cleanups; + bfd_byte *sect_data_got; struct bfd_link_info link_info; struct bfd_link_order link_order; CORE_ADDR inferior_addr; - struct link_hash_table_cleanup_data cleanup_data; if ((bfd_get_section_flags (abfd, sect) & (SEC_ALLOC | SEC_LOAD)) != (SEC_ALLOC | SEC_LOAD)) @@ -326,13 +339,11 @@ copy_sections (bfd *abfd, asection *sect, void *data) link_info.input_bfds = abfd; link_info.input_bfds_tail = &abfd->link.next; - cleanup_data.abfd = abfd; - cleanup_data.link_next = abfd->link.next; + struct link_hash_table_cleanup_data cleanup_data (abfd); abfd->link.next = NULL; link_info.hash = bfd_link_hash_table_create (abfd); - cleanups = make_cleanup (link_hash_table_free, &cleanup_data); link_info.callbacks = &link_callbacks; memset (&link_order, 0, sizeof (link_order)); @@ -342,21 +353,22 @@ copy_sections (bfd *abfd, asection *sect, void *data) link_order.size = bfd_get_section_size (sect); link_order.u.indirect.section = sect; - sect_data = (bfd_byte *) xmalloc (bfd_get_section_size (sect)); - make_cleanup (xfree, sect_data); + gdb::unique_xmalloc_ptr<gdb_byte> sect_data + ((bfd_byte *) xmalloc (bfd_get_section_size (sect))); sect_data_got = bfd_get_relocated_section_contents (abfd, &link_info, - &link_order, sect_data, + &link_order, + sect_data.get (), FALSE, symbol_table); if (sect_data_got == NULL) error (_("Cannot map compiled module \"%s\" section \"%s\": %s"), bfd_get_filename (abfd), bfd_get_section_name (abfd, sect), bfd_errmsg (bfd_get_error ())); - gdb_assert (sect_data_got == sect_data); + gdb_assert (sect_data_got == sect_data.get ()); inferior_addr = bfd_get_section_vma (abfd, sect); - if (0 != target_write_memory (inferior_addr, sect_data, + if (0 != target_write_memory (inferior_addr, sect_data.get (), bfd_get_section_size (sect))) error (_("Cannot write compiled module \"%s\" section \"%s\" " "to inferior memory range %s-%s."), @@ -364,8 +376,6 @@ copy_sections (bfd *abfd, asection *sect, void *data) paddress (target_gdbarch (), inferior_addr), paddress (target_gdbarch (), inferior_addr + bfd_get_section_size (sect))); - - do_cleanups (cleanups); } /* Fetch the type of COMPILE_I_EXPR_PTR_TYPE and COMPILE_I_EXPR_VAL |