gdb: remove target_so_ops::free_so

target_so_ops::free_so is responsible for freeing the specific lm_info
object.  All implementations basically just call delete.  Remove that
method, make the destructor of lm_info virtual, and call delete directly
from the free_so function.  Make the sub-classes final, just because
it's good practice.

Change-Id: Iee1fd4861c75034a9e41a656add8ed8dfd8964ee
Approved-By: Pedro Alves <pedro@palves.net>
Reviewed-By: Reviewed-By: Lancelot Six <lancelot.six@amd.com>
This commit is contained in:
Simon Marchi 2023-10-02 16:00:55 -04:00
parent ae4bf24404
commit e3b63a7910
9 changed files with 13 additions and 77 deletions

View File

@ -28,7 +28,7 @@
/* Our private data in struct so_list. */
struct lm_info_aix : public lm_info
struct lm_info_aix final : public lm_info
{
/* The name of the file mapped by the loader. Apart from the entry
for the main executable, this is usually a shared library (which,
@ -360,18 +360,6 @@ solib_aix_relocate_section_addresses (so_list &so, target_section *sec)
}
}
/* Implement the "free_so" target_so_ops method. */
static void
solib_aix_free_so (so_list &so)
{
lm_info_aix *li = (lm_info_aix *) so.lm_info;
solib_debug_printf ("%s", so.so_name);
delete li;
}
/* Compute and return the OBJFILE's section_offset array, using
the associated loader info (INFO). */
@ -704,7 +692,6 @@ solib_aix_normal_stop_observer (struct bpstat *unused_1, int unused_2)
const struct target_so_ops solib_aix_so_ops =
{
solib_aix_relocate_section_addresses,
solib_aix_free_so,
nullptr,
nullptr,
solib_aix_solib_create_inferior_hook,

View File

@ -135,7 +135,7 @@ darwin_load_image_infos (struct darwin_info *info)
/* Link map info to include in an allocated so_list entry. */
struct lm_info_darwin : public lm_info
struct lm_info_darwin final : public lm_info
{
/* The target location of lm. */
CORE_ADDR lm_addr = 0;
@ -608,14 +608,6 @@ darwin_clear_solib (program_space *pspace)
info->all_image.version = 0;
}
static void
darwin_free_so (so_list &so)
{
lm_info_darwin *li = (lm_info_darwin *) so.lm_info;
delete li;
}
/* The section table is built from bfd sections using bfd VMAs.
Relocate these VMAs according to solib info. */
@ -673,7 +665,6 @@ darwin_bfd_open (const char *pathname)
const struct target_so_ops darwin_so_ops =
{
darwin_relocate_section_addresses,
darwin_free_so,
nullptr,
darwin_clear_solib,
darwin_solib_create_inferior_hook,

View File

@ -123,7 +123,7 @@ struct dbst_ext_link_map
/* Link map info to include in an allocated so_list entry */
struct lm_info_dsbt : public lm_info
struct lm_info_dsbt final : public lm_info
{
~lm_info_dsbt ()
{
@ -879,14 +879,6 @@ dsbt_clear_solib (program_space *pspace)
info->main_executable_lm_info = NULL;
}
static void
dsbt_free_so (so_list &so)
{
lm_info_dsbt *li = (lm_info_dsbt *) so.lm_info;
delete li;
}
static void
dsbt_relocate_section_addresses (so_list &so, target_section *sec)
{
@ -917,7 +909,6 @@ show_dsbt_debug (struct ui_file *file, int from_tty,
const struct target_so_ops dsbt_so_ops =
{
dsbt_relocate_section_addresses,
dsbt_free_so,
nullptr,
dsbt_clear_solib,
dsbt_solib_create_inferior_hook,

View File

@ -196,7 +196,7 @@ struct ext_link_map
/* Link map info to include in an allocated so_list entry. */
struct lm_info_frv : public lm_info
struct lm_info_frv final : public lm_info
{
~lm_info_frv ()
{
@ -815,14 +815,6 @@ frv_clear_solib (program_space *pspace)
main_executable_lm_info = NULL;
}
static void
frv_free_so (so_list &so)
{
lm_info_frv *li = (lm_info_frv *) so.lm_info;
delete li;
}
static void
frv_relocate_section_addresses (so_list &so, target_section *sec)
{
@ -1089,7 +1081,6 @@ frv_fetch_objfile_link_map (struct objfile *objfile)
const struct target_so_ops frv_so_ops =
{
frv_relocate_section_addresses,
frv_free_so,
nullptr,
frv_clear_solib,
frv_solib_create_inferior_hook,

View File

@ -976,16 +976,6 @@ svr4_free_objfile_observer (struct objfile *objfile)
probes_table_remove_objfile_probes (objfile);
}
/* Implementation for target_so_ops.free_so. */
static void
svr4_free_so (so_list &so)
{
lm_info_svr4 *li = (lm_info_svr4 *) so.lm_info;
delete li;
}
/* Implement target_so_ops.clear_so. */
static void
@ -3465,7 +3455,6 @@ svr4_iterate_over_objfiles_in_search_order
const struct target_so_ops svr4_so_ops =
{
svr4_relocate_section_addresses,
svr4_free_so,
svr4_clear_so,
svr4_clear_solib,
svr4_solib_create_inferior_hook,

View File

@ -29,7 +29,7 @@ extern const struct target_so_ops svr4_so_ops;
/* Link map info to include in an allocated so_list entry. */
struct lm_info_svr4 : public lm_info
struct lm_info_svr4 final : public lm_info
{
/* Amount by which addresses in the binary should be relocated to
match the inferior. The direct inferior value is L_ADDR_INFERIOR.

View File

@ -28,7 +28,7 @@
#include "inferior.h"
/* Private data for each loaded library. */
struct lm_info_target : public lm_info
struct lm_info_target final : public lm_info
{
/* The library's name. The name is normally kept in the struct
so_list; it is only here during XML parsing. */
@ -281,16 +281,6 @@ solib_target_solib_create_inferior_hook (int from_tty)
/* Nothing needed. */
}
static void
solib_target_free_so (so_list &so)
{
lm_info_target *li = (lm_info_target *) so.lm_info;
gdb_assert (li->name.empty ());
delete li;
}
static void
solib_target_relocate_section_addresses (so_list &so, target_section *sec)
{
@ -431,7 +421,6 @@ solib_target_in_dynsym_resolve_code (CORE_ADDR pc)
const struct target_so_ops solib_target_so_ops =
{
solib_target_relocate_section_addresses,
solib_target_free_so,
nullptr,
nullptr,
solib_target_solib_create_inferior_hook,

View File

@ -658,6 +658,8 @@ clear_so (so_list &so)
ops->clear_so (so);
}
lm_info::~lm_info () = default;
/* Free the storage associated with the `struct so_list' object SO.
If we have opened a BFD for SO, close it.
@ -672,11 +674,8 @@ clear_so (so_list &so)
void
free_so (so_list &so)
{
const target_so_ops *ops = gdbarch_so_ops (current_inferior ()->arch ());
clear_so (so);
ops->free_so (so);
delete so.lm_info;
delete &so;
}

View File

@ -29,6 +29,9 @@
struct lm_info
{
lm_info () = default;
lm_info (const lm_info &) = default;
virtual ~lm_info () = 0;
};
struct so_list
@ -86,13 +89,9 @@ struct target_so_ops
which the object was actually mapped. */
void (*relocate_section_addresses) (so_list &so, target_section *);
/* Free the link map info and any other private data structures
associated with a so_list entry. */
void (*free_so) (so_list &so);
/* Reset private data structures associated with SO.
This is called when SO is about to be reloaded.
It is also called before free_so when SO is about to be freed. */
It is also called when SO is about to be freed. */
void (*clear_so) (const so_list &so);
/* Free private data structures associated to PSPACE. This method