* [PATCH 0/3] Clean up solib_ops
@ 2022-08-08 19:27 Tom Tromey
2022-08-08 19:27 ` [PATCH 1/3] Remove current_target_so_ops Tom Tromey
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: Tom Tromey @ 2022-08-08 19:27 UTC (permalink / raw)
To: gdb-patches
While working on the recent regression fix, I found a few ways to
clean up solib_ops. Regression tested on x86-64 Fedora 34.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/3] Remove current_target_so_ops
2022-08-08 19:27 [PATCH 0/3] Clean up solib_ops Tom Tromey
@ 2022-08-08 19:27 ` Tom Tromey
2022-08-08 19:28 ` [PATCH 2/3] Move solib_ops into gdbarch Tom Tromey
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2022-08-08 19:27 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
current_target_so_ops is only set in a single place. It seems better
to simply remove it.
---
gdb/solib-target.c | 5 -----
gdb/solib.c | 9 +++------
gdb/solist.h | 3 ---
3 files changed, 3 insertions(+), 14 deletions(-)
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 54b98243e51..8def640a1e7 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -453,9 +453,4 @@ _initialize_solib_target ()
solib_target_so_ops.in_dynsym_resolve_code
= solib_target_in_dynsym_resolve_code;
solib_target_so_ops.bfd_open = solib_bfd_open;
-
- /* Set current_target_so_ops to solib_target_so_ops if not already
- set. */
- if (current_target_so_ops == 0)
- current_target_so_ops = &solib_target_so_ops;
}
diff --git a/gdb/solib.c b/gdb/solib.c
index 25adf586a02..859d345f39c 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -53,6 +53,7 @@
#include "debuginfod-support.h"
#include "source.h"
#include "cli/cli-style.h"
+#include "solib-target.h"
/* Architecture-specific operations. */
@@ -67,8 +68,8 @@ solib_ops (struct gdbarch *gdbarch)
const struct target_so_ops *result = solib_data.get (gdbarch);
if (result == nullptr)
{
- result = current_target_so_ops;
- set_solib_ops (gdbarch, current_target_so_ops);
+ result = &solib_target_so_ops;
+ set_solib_ops (gdbarch, &solib_target_so_ops);
}
return result;
}
@@ -84,10 +85,6 @@ set_solib_ops (struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
/* external data declarations */
-/* FIXME: gdbarch needs to control this variable, or else every
- configuration needs to call set_solib_ops. */
-struct target_so_ops *current_target_so_ops;
-
/* Local function prototypes */
/* If non-empty, this is a search path for loading non-absolute shared library
diff --git a/gdb/solist.h b/gdb/solist.h
index 34198dc0c4d..f102605e076 100644
--- a/gdb/solist.h
+++ b/gdb/solist.h
@@ -194,7 +194,4 @@ extern gdb_bfd_ref_ptr solib_bfd_fopen (const char *pathname, int fd);
/* Find solib binary file and open it. */
extern gdb_bfd_ref_ptr solib_bfd_open (const char *in_pathname);
-/* FIXME: gdbarch needs to control this variable. */
-extern struct target_so_ops *current_target_so_ops;
-
#endif
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 2/3] Move solib_ops into gdbarch
2022-08-08 19:27 [PATCH 0/3] Clean up solib_ops Tom Tromey
2022-08-08 19:27 ` [PATCH 1/3] Remove current_target_so_ops Tom Tromey
@ 2022-08-08 19:28 ` Tom Tromey
2022-08-08 19:28 ` [PATCH 3/3] Constify some target_so_ops instances Tom Tromey
2022-09-20 18:40 ` [PATCH 0/3] Clean up solib_ops Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2022-08-08 19:28 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changs solib_ops to be an ordinary gdbarch value and updates all
the uses. This removes a longstanding FIXME and makes the code
somewhat cleaner as well.
---
gdb/amd64-darwin-tdep.c | 2 +-
gdb/arch-utils.c | 1 +
gdb/dicos-tdep.c | 2 +-
gdb/frv-tdep.c | 2 +-
gdb/gdbarch-components.py | 8 +++++++
gdb/gdbarch-gen.h | 5 ++++
gdb/gdbarch.c | 22 ++++++++++++++++++
gdb/i386-darwin-tdep.c | 2 +-
gdb/i386-nto-tdep.c | 2 +-
gdb/mips-linux-tdep.c | 2 +-
gdb/ppc-linux-tdep.c | 2 +-
gdb/rs6000-aix-tdep.c | 2 +-
gdb/solib-svr4.c | 2 +-
gdb/solib.c | 48 ++++++++++-----------------------------
gdb/solib.h | 5 ----
gdb/tic6x-linux-tdep.c | 2 +-
gdb/windows-tdep.c | 2 +-
17 files changed, 59 insertions(+), 52 deletions(-)
diff --git a/gdb/amd64-darwin-tdep.c b/gdb/amd64-darwin-tdep.c
index 7fc35536bc6..718bf4996e5 100644
--- a/gdb/amd64-darwin-tdep.c
+++ b/gdb/amd64-darwin-tdep.c
@@ -113,7 +113,7 @@ x86_darwin_init_abi_64 (struct gdbarch_info info, struct gdbarch *gdbarch)
tdep->jb_pc_offset = 56;
- set_solib_ops (gdbarch, &darwin_so_ops);
+ set_gdbarch_so_ops (gdbarch, &darwin_so_ops);
}
void _initialize_amd64_darwin_tdep ();
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index 9c6b9268a69..61ba0d26a07 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -36,6 +36,7 @@
#include "reggroups.h"
#include "auxv.h"
#include "observable.h"
+#include "solib-target.h"
#include "gdbsupport/version.h"
diff --git a/gdb/dicos-tdep.c b/gdb/dicos-tdep.c
index caff2474719..d22dfd65c60 100644
--- a/gdb/dicos-tdep.c
+++ b/gdb/dicos-tdep.c
@@ -28,7 +28,7 @@
void
dicos_init_abi (struct gdbarch *gdbarch)
{
- set_solib_ops (gdbarch, &solib_target_so_ops);
+ set_gdbarch_so_ops (gdbarch, &solib_target_so_ops);
/* Every process, although has its own address space, sees the same
list of shared libraries. There's no "main executable" in DICOS,
diff --git a/gdb/frv-tdep.c b/gdb/frv-tdep.c
index 55a6cfd9618..1c9c13e1ea0 100644
--- a/gdb/frv-tdep.c
+++ b/gdb/frv-tdep.c
@@ -1556,7 +1556,7 @@ frv_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
set_gdbarch_convert_from_func_ptr_addr (gdbarch,
frv_convert_from_func_ptr_addr);
- set_solib_ops (gdbarch, &frv_so_ops);
+ set_gdbarch_so_ops (gdbarch, &frv_so_ops);
/* Hook in ABI-specific overrides, if they have been registered. */
gdbarch_init_osabi (info, gdbarch);
diff --git a/gdb/gdbarch-components.py b/gdb/gdbarch-components.py
index 71aa5991fbe..ad71bf754de 100644
--- a/gdb/gdbarch-components.py
+++ b/gdb/gdbarch-components.py
@@ -1262,6 +1262,14 @@ Function(
invalid=False,
)
+Value(
+ comment="Vtable of solib operations functions.",
+ type="const struct target_so_ops *",
+ name="so_ops",
+ postdefault="&solib_target_so_ops",
+ printer="host_address_to_string (gdbarch->so_ops)",
+)
+
Method(
comment="""
If in_solib_dynsym_resolve_code() returns true, and SKIP_SOLIB_RESOLVER
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 0504962e50d..c7a24704c7c 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -702,6 +702,11 @@ typedef CORE_ADDR (gdbarch_skip_trampoline_code_ftype) (struct frame_info *frame
extern CORE_ADDR gdbarch_skip_trampoline_code (struct gdbarch *gdbarch, struct frame_info *frame, CORE_ADDR pc);
extern void set_gdbarch_skip_trampoline_code (struct gdbarch *gdbarch, gdbarch_skip_trampoline_code_ftype *skip_trampoline_code);
+/* Vtable of solib operations functions. */
+
+extern const struct target_so_ops * gdbarch_so_ops (struct gdbarch *gdbarch);
+extern void set_gdbarch_so_ops (struct gdbarch *gdbarch, const struct target_so_ops * so_ops);
+
/* If in_solib_dynsym_resolve_code() returns true, and SKIP_SOLIB_RESOLVER
evaluates non-zero, this is the address where the debugger will place
a step-resume breakpoint to get us past the dynamic linker. */
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 0edae7f6f0a..18d46a39d7a 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -153,6 +153,7 @@ struct gdbarch
gdbarch_single_step_through_delay_ftype *single_step_through_delay = nullptr;
gdbarch_print_insn_ftype *print_insn = nullptr;
gdbarch_skip_trampoline_code_ftype *skip_trampoline_code = nullptr;
+ const struct target_so_ops * so_ops = 0;
gdbarch_skip_solib_resolver_ftype *skip_solib_resolver = nullptr;
gdbarch_in_solib_return_trampoline_ftype *in_solib_return_trampoline = nullptr;
gdbarch_in_indirect_branch_thunk_ftype *in_indirect_branch_thunk = nullptr;
@@ -504,6 +505,8 @@ verify_gdbarch (struct gdbarch *gdbarch)
/* Skip verify of single_step_through_delay, has predicate. */
/* Skip verify of print_insn, invalid_p == 0 */
/* Skip verify of skip_trampoline_code, invalid_p == 0 */
+ if (gdbarch->so_ops == 0)
+ gdbarch->so_ops = &solib_target_so_ops;
/* Skip verify of skip_solib_resolver, invalid_p == 0 */
/* Skip verify of in_solib_return_trampoline, invalid_p == 0 */
/* Skip verify of in_indirect_branch_thunk, invalid_p == 0 */
@@ -1012,6 +1015,9 @@ gdbarch_dump (struct gdbarch *gdbarch, struct ui_file *file)
gdb_printf (file,
"gdbarch_dump: skip_trampoline_code = <%s>\n",
host_address_to_string (gdbarch->skip_trampoline_code));
+ gdb_printf (file,
+ "gdbarch_dump: so_ops = %s\n",
+ host_address_to_string (gdbarch->so_ops));
gdb_printf (file,
"gdbarch_dump: skip_solib_resolver = <%s>\n",
host_address_to_string (gdbarch->skip_solib_resolver));
@@ -3366,6 +3372,22 @@ set_gdbarch_skip_trampoline_code (struct gdbarch *gdbarch,
gdbarch->skip_trampoline_code = skip_trampoline_code;
}
+const struct target_so_ops *
+gdbarch_so_ops (struct gdbarch *gdbarch)
+{
+ gdb_assert (gdbarch != NULL);
+ if (gdbarch_debug >= 2)
+ gdb_printf (gdb_stdlog, "gdbarch_so_ops called\n");
+ return gdbarch->so_ops;
+}
+
+void
+set_gdbarch_so_ops (struct gdbarch *gdbarch,
+ const struct target_so_ops * so_ops)
+{
+ gdbarch->so_ops = so_ops;
+}
+
CORE_ADDR
gdbarch_skip_solib_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
{
diff --git a/gdb/i386-darwin-tdep.c b/gdb/i386-darwin-tdep.c
index 2a9198aceb3..5e7929b2c99 100644
--- a/gdb/i386-darwin-tdep.c
+++ b/gdb/i386-darwin-tdep.c
@@ -271,7 +271,7 @@ i386_darwin_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
alignment. */
set_gdbarch_long_double_bit (gdbarch, 128);
- set_solib_ops (gdbarch, &darwin_so_ops);
+ set_gdbarch_so_ops (gdbarch, &darwin_so_ops);
}
static enum gdb_osabi
diff --git a/gdb/i386-nto-tdep.c b/gdb/i386-nto-tdep.c
index 259867f262b..69d298c871f 100644
--- a/gdb/i386-nto-tdep.c
+++ b/gdb/i386-nto-tdep.c
@@ -361,7 +361,7 @@ i386nto_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
nto_svr4_so_ops.in_dynsym_resolve_code
= nto_in_dynsym_resolve_code;
}
- set_solib_ops (gdbarch, &nto_svr4_so_ops);
+ set_gdbarch_so_ops (gdbarch, &nto_svr4_so_ops);
set_gdbarch_wchar_bit (gdbarch, 32);
set_gdbarch_wchar_signed (gdbarch, 0);
diff --git a/gdb/mips-linux-tdep.c b/gdb/mips-linux-tdep.c
index ca313a28279..7dae1ca34de 100644
--- a/gdb/mips-linux-tdep.c
+++ b/gdb/mips-linux-tdep.c
@@ -1594,7 +1594,7 @@ mips_linux_init_abi (struct gdbarch_info info,
mips_svr4_so_ops.in_dynsym_resolve_code
= mips_linux_in_dynsym_resolve_code;
}
- set_solib_ops (gdbarch, &mips_svr4_so_ops);
+ set_gdbarch_so_ops (gdbarch, &mips_svr4_so_ops);
set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
diff --git a/gdb/ppc-linux-tdep.c b/gdb/ppc-linux-tdep.c
index beef4bd393c..ed154fd4a63 100644
--- a/gdb/ppc-linux-tdep.c
+++ b/gdb/ppc-linux-tdep.c
@@ -2126,7 +2126,7 @@ ppc_linux_init_abi (struct gdbarch_info info,
powerpc_so_ops.in_dynsym_resolve_code =
powerpc_linux_in_dynsym_resolve_code;
}
- set_solib_ops (gdbarch, &powerpc_so_ops);
+ set_gdbarch_so_ops (gdbarch, &powerpc_so_ops);
set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
}
diff --git a/gdb/rs6000-aix-tdep.c b/gdb/rs6000-aix-tdep.c
index 41384993c26..86270c81855 100644
--- a/gdb/rs6000-aix-tdep.c
+++ b/gdb/rs6000-aix-tdep.c
@@ -1180,7 +1180,7 @@ rs6000_aix_init_osabi (struct gdbarch_info info, struct gdbarch *gdbarch)
set_gdbarch_wchar_signed (gdbarch, 0);
set_gdbarch_auto_wide_charset (gdbarch, rs6000_aix_auto_wide_charset);
- set_solib_ops (gdbarch, &solib_aix_so_ops);
+ set_gdbarch_so_ops (gdbarch, &solib_aix_so_ops);
frame_unwind_append_unwinder (gdbarch, &aix_sighandle_frame_unwind);
}
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 95a1e1eb722..893da86e27e 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3026,7 +3026,7 @@ set_solib_svr4_fetch_link_map_offsets (struct gdbarch *gdbarch,
ops->fetch_link_map_offsets = flmo;
- set_solib_ops (gdbarch, &svr4_so_ops);
+ set_gdbarch_so_ops (gdbarch, &svr4_so_ops);
set_gdbarch_iterate_over_objfiles_in_search_order
(gdbarch, svr4_iterate_over_objfiles_in_search_order);
}
diff --git a/gdb/solib.c b/gdb/solib.c
index 859d345f39c..7cfdd81114c 100644
--- a/gdb/solib.c
+++ b/gdb/solib.c
@@ -57,30 +57,6 @@
/* Architecture-specific operations. */
-/* Per-architecture data key. */
-static const registry<gdbarch>::key<const struct target_so_ops,
- gdb::noop_deleter<const struct target_so_ops>>
- solib_data;
-
-static const struct target_so_ops *
-solib_ops (struct gdbarch *gdbarch)
-{
- const struct target_so_ops *result = solib_data.get (gdbarch);
- if (result == nullptr)
- {
- result = &solib_target_so_ops;
- set_solib_ops (gdbarch, &solib_target_so_ops);
- }
- return result;
-}
-
-/* Set the solib operations for GDBARCH to NEW_OPS. */
-
-void
-set_solib_ops (struct gdbarch *gdbarch, const struct target_so_ops *new_ops)
-{
- solib_data.set (gdbarch, new_ops);
-}
\f
/* external data declarations */
@@ -145,7 +121,7 @@ show_solib_search_path (struct ui_file *file, int from_tty,
static gdb::unique_xmalloc_ptr<char>
solib_find_1 (const char *in_pathname, int *fd, bool is_solib)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
int found_file = -1;
gdb::unique_xmalloc_ptr<char> temp_pathname;
const char *fskind = effective_target_file_system_kind ();
@@ -576,7 +552,7 @@ get_cbfd_soname_build_id (gdb_bfd_ref_ptr abfd, const char *soname)
static int
solib_map_sections (struct so_list *so)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
gdb::unique_xmalloc_ptr<char> filename (tilde_expand (so->so_name));
gdb_bfd_ref_ptr abfd (ops->bfd_open (filename.get ()));
@@ -670,7 +646,7 @@ solib_map_sections (struct so_list *so)
static void
clear_so (struct so_list *so)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
delete so->sections;
so->sections = NULL;
@@ -707,7 +683,7 @@ clear_so (struct so_list *so)
void
free_so (struct so_list *so)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
clear_so (so);
ops->free_so (so);
@@ -793,7 +769,7 @@ solib_used (const struct so_list *const known)
void
update_solib_list (int from_tty)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
struct so_list *inferior = ops->current_sos();
struct so_list *gdb, **gdb_link;
@@ -1234,7 +1210,7 @@ solib_name_from_address (struct program_space *pspace, CORE_ADDR address)
bool
solib_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
if (ops->keep_data_in_core)
return ops->keep_data_in_core (vaddr, size) != 0;
@@ -1247,7 +1223,7 @@ solib_keep_data_in_core (CORE_ADDR vaddr, unsigned long size)
void
clear_solib (void)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
disable_breakpoints_in_shlibs ();
@@ -1272,7 +1248,7 @@ clear_solib (void)
void
solib_create_inferior_hook (int from_tty)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
ops->solib_create_inferior_hook (from_tty);
}
@@ -1282,7 +1258,7 @@ solib_create_inferior_hook (int from_tty)
bool
in_solib_dynsym_resolve_code (CORE_ADDR pc)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
return ops->in_dynsym_resolve_code (pc) != 0;
}
@@ -1318,7 +1294,7 @@ no_shared_libraries (const char *ignored, int from_tty)
void
update_solib_breakpoints (void)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
if (ops->update_breakpoints != NULL)
ops->update_breakpoints ();
@@ -1329,7 +1305,7 @@ update_solib_breakpoints (void)
void
handle_solib_event (void)
{
- const struct target_so_ops *ops = solib_ops (target_gdbarch ());
+ const struct target_so_ops *ops = gdbarch_so_ops (target_gdbarch ());
if (ops->handle_event != NULL)
ops->handle_event ();
@@ -1417,7 +1393,7 @@ reload_shared_libraries (const char *ignored, int from_tty,
reload_shared_libraries_1 (from_tty);
- ops = solib_ops (target_gdbarch ());
+ ops = gdbarch_so_ops (target_gdbarch ());
/* Creating inferior hooks here has two purposes. First, if we reload
shared libraries then the address of solib breakpoint we've computed
diff --git a/gdb/solib.h b/gdb/solib.h
index 251028472c0..a7e751ed9b3 100644
--- a/gdb/solib.h
+++ b/gdb/solib.h
@@ -71,11 +71,6 @@ extern bool in_solib_dynsym_resolve_code (CORE_ADDR);
extern void no_shared_libraries (const char *ignored, int from_tty);
-/* Set the solib operations for GDBARCH to NEW_OPS. */
-
-extern void set_solib_ops (struct gdbarch *gdbarch,
- const struct target_so_ops *new_ops);
-
/* Synchronize GDB's shared object list with inferior's.
Extract the list of currently loaded shared objects from the
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index b2422d1ccc0..b99cfc0d5e3 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -170,7 +170,7 @@ tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
linux_init_abi (info, gdbarch, 0);
/* Shared library handling. */
- set_solib_ops (gdbarch, &dsbt_so_ops);
+ set_gdbarch_so_ops (gdbarch, &dsbt_so_ops);
tdep->syscall_next_pc = tic6x_linux_syscall_next_pc;
diff --git a/gdb/windows-tdep.c b/gdb/windows-tdep.c
index 702af65d450..e5e37fcaa53 100644
--- a/gdb/windows-tdep.c
+++ b/gdb/windows-tdep.c
@@ -931,7 +931,7 @@ windows_init_abi_common (struct gdbarch_info info, struct gdbarch *gdbarch)
windows_so_ops = solib_target_so_ops;
windows_so_ops.solib_create_inferior_hook
= windows_solib_create_inferior_hook;
- set_solib_ops (gdbarch, &windows_so_ops);
+ set_gdbarch_so_ops (gdbarch, &windows_so_ops);
set_gdbarch_get_siginfo_type (gdbarch, windows_get_siginfo_type);
}
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 3/3] Constify some target_so_ops instances
2022-08-08 19:27 [PATCH 0/3] Clean up solib_ops Tom Tromey
2022-08-08 19:27 ` [PATCH 1/3] Remove current_target_so_ops Tom Tromey
2022-08-08 19:28 ` [PATCH 2/3] Move solib_ops into gdbarch Tom Tromey
@ 2022-08-08 19:28 ` Tom Tromey
2022-09-20 18:40 ` [PATCH 0/3] Clean up solib_ops Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2022-08-08 19:28 UTC (permalink / raw)
To: gdb-patches; +Cc: Tom Tromey
This changes some target_so_ops instances to be const. This makes
their use a little more obvious (they can't be mutated) and also
allows for the removal of some initialization code.
---
gdb/frv-tdep.h | 2 +-
gdb/solib-aix.c | 26 ++++++++++++--------------
gdb/solib-aix.h | 2 +-
gdb/solib-darwin.c | 26 ++++++++++++--------------
gdb/solib-darwin.h | 2 +-
gdb/solib-dsbt.c | 23 +++++++++++++----------
gdb/solib-dsbt.h | 28 ++++++++++++++++++++++++++++
gdb/solib-frv.c | 22 ++++++++++++----------
gdb/solib-svr4.c | 34 ++++++++++++++++++----------------
gdb/solib-svr4.h | 2 +-
gdb/solib-target.c | 29 +++++++++++------------------
gdb/solib-target.h | 2 +-
gdb/tic6x-linux-tdep.c | 2 +-
13 files changed, 112 insertions(+), 88 deletions(-)
create mode 100644 gdb/solib-dsbt.h
diff --git a/gdb/frv-tdep.h b/gdb/frv-tdep.h
index 64052b8e754..037d81a6ddd 100644
--- a/gdb/frv-tdep.h
+++ b/gdb/frv-tdep.h
@@ -119,6 +119,6 @@ CORE_ADDR frv_fdpic_find_canonical_descriptor (CORE_ADDR entry_point);
CORE_ADDR frv_fetch_objfile_link_map (struct objfile *objfile);
struct target_so_ops;
-extern struct target_so_ops frv_so_ops;
+extern const struct target_so_ops frv_so_ops;
#endif /* FRV_TDEP_H */
diff --git a/gdb/solib-aix.c b/gdb/solib-aix.c
index 948bd0f2463..f483f54de13 100644
--- a/gdb/solib-aix.c
+++ b/gdb/solib-aix.c
@@ -718,25 +718,23 @@ show_solib_aix_debug (struct ui_file *file, int from_tty,
}
/* The target_so_ops for AIX targets. */
-struct target_so_ops solib_aix_so_ops;
+const struct target_so_ops solib_aix_so_ops =
+{
+ solib_aix_relocate_section_addresses,
+ solib_aix_free_so,
+ nullptr,
+ solib_aix_clear_solib,
+ solib_aix_solib_create_inferior_hook,
+ solib_aix_current_sos,
+ solib_aix_open_symbol_file_object,
+ solib_aix_in_dynsym_resolve_code,
+ solib_aix_bfd_open,
+};
void _initialize_solib_aix ();
void
_initialize_solib_aix ()
{
- solib_aix_so_ops.relocate_section_addresses
- = solib_aix_relocate_section_addresses;
- solib_aix_so_ops.free_so = solib_aix_free_so;
- solib_aix_so_ops.clear_solib = solib_aix_clear_solib;
- solib_aix_so_ops.solib_create_inferior_hook
- = solib_aix_solib_create_inferior_hook;
- solib_aix_so_ops.current_sos = solib_aix_current_sos;
- solib_aix_so_ops.open_symbol_file_object
- = solib_aix_open_symbol_file_object;
- solib_aix_so_ops.in_dynsym_resolve_code
- = solib_aix_in_dynsym_resolve_code;
- solib_aix_so_ops.bfd_open = solib_aix_bfd_open;
-
gdb::observers::normal_stop.attach (solib_aix_normal_stop_observer,
"solib-aix");
diff --git a/gdb/solib-aix.h b/gdb/solib-aix.h
index edb0b5ad142..24415f66234 100644
--- a/gdb/solib-aix.h
+++ b/gdb/solib-aix.h
@@ -19,7 +19,7 @@
#define SOLIB_AIX_H
struct target_so_ops;
-extern struct target_so_ops solib_aix_so_ops;
+extern const struct target_so_ops solib_aix_so_ops;
extern CORE_ADDR solib_aix_get_toc_value (CORE_ADDR pc);
diff --git a/gdb/solib-darwin.c b/gdb/solib-darwin.c
index e61ec0d4bf3..4eca080618a 100644
--- a/gdb/solib-darwin.c
+++ b/gdb/solib-darwin.c
@@ -33,6 +33,7 @@
#include "solist.h"
#include "solib.h"
#include "solib-svr4.h"
+#include "solib-darwin.h"
#include "bfd-target.h"
#include "elf-bfd.h"
@@ -674,18 +675,15 @@ darwin_bfd_open (const char *pathname)
return res;
}
-struct target_so_ops darwin_so_ops;
-
-void _initialize_darwin_solib ();
-void
-_initialize_darwin_solib ()
+const struct target_so_ops darwin_so_ops =
{
- darwin_so_ops.relocate_section_addresses = darwin_relocate_section_addresses;
- darwin_so_ops.free_so = darwin_free_so;
- darwin_so_ops.clear_solib = darwin_clear_solib;
- darwin_so_ops.solib_create_inferior_hook = darwin_solib_create_inferior_hook;
- darwin_so_ops.current_sos = darwin_current_sos;
- darwin_so_ops.open_symbol_file_object = open_symbol_file_object;
- darwin_so_ops.in_dynsym_resolve_code = darwin_in_dynsym_resolve_code;
- darwin_so_ops.bfd_open = darwin_bfd_open;
-}
+ darwin_relocate_section_addresses,
+ darwin_free_so,
+ nullptr,
+ darwin_clear_solib,
+ darwin_solib_create_inferior_hook,
+ darwin_current_sos,
+ open_symbol_file_object,
+ darwin_in_dynsym_resolve_code,
+ darwin_bfd_open,
+};
diff --git a/gdb/solib-darwin.h b/gdb/solib-darwin.h
index e920e7a913e..32e7c8d1517 100644
--- a/gdb/solib-darwin.h
+++ b/gdb/solib-darwin.h
@@ -23,6 +23,6 @@
struct objfile;
struct target_so_ops;
-extern struct target_so_ops darwin_so_ops;
+extern const struct target_so_ops darwin_so_ops;
#endif /* solib-darwin.h */
diff --git a/gdb/solib-dsbt.c b/gdb/solib-dsbt.c
index b4cd16327a6..b866a0b4517 100644
--- a/gdb/solib-dsbt.c
+++ b/gdb/solib-dsbt.c
@@ -29,6 +29,7 @@
#include "gdbcmd.h"
#include "elf-bfd.h"
#include "gdb_bfd.h"
+#include "solib-dsbt.h"
#define GOT_MODULE_OFFSET 4
@@ -924,21 +925,23 @@ show_dsbt_debug (struct ui_file *file, int from_tty,
gdb_printf (file, _("solib-dsbt debugging is %s.\n"), value);
}
-struct target_so_ops dsbt_so_ops;
+const struct target_so_ops dsbt_so_ops =
+{
+ dsbt_relocate_section_addresses,
+ dsbt_free_so,
+ nullptr,
+ dsbt_clear_solib,
+ dsbt_solib_create_inferior_hook,
+ dsbt_current_sos,
+ open_symbol_file_object,
+ dsbt_in_dynsym_resolve_code,
+ solib_bfd_open,
+};
void _initialize_dsbt_solib ();
void
_initialize_dsbt_solib ()
{
- dsbt_so_ops.relocate_section_addresses = dsbt_relocate_section_addresses;
- dsbt_so_ops.free_so = dsbt_free_so;
- dsbt_so_ops.clear_solib = dsbt_clear_solib;
- dsbt_so_ops.solib_create_inferior_hook = dsbt_solib_create_inferior_hook;
- dsbt_so_ops.current_sos = dsbt_current_sos;
- dsbt_so_ops.open_symbol_file_object = open_symbol_file_object;
- dsbt_so_ops.in_dynsym_resolve_code = dsbt_in_dynsym_resolve_code;
- dsbt_so_ops.bfd_open = solib_bfd_open;
-
/* Debug this file's internals. */
add_setshow_zuinteger_cmd ("solib-dsbt", class_maintenance,
&solib_dsbt_debug, _("\
diff --git a/gdb/solib-dsbt.h b/gdb/solib-dsbt.h
new file mode 100644
index 00000000000..98c0a31d68b
--- /dev/null
+++ b/gdb/solib-dsbt.h
@@ -0,0 +1,28 @@
+/* Handle shared libraries for GDB, the GNU Debugger.
+
+ Copyright (C) 2022 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef SOLIB_DSBT_H
+#define SOLIB_DSBT_H
+
+struct objfile;
+struct target_so_ops;
+
+extern const struct target_so_ops dsbt_so_ops;
+
+#endif /* solib-dsbt.h */
diff --git a/gdb/solib-frv.c b/gdb/solib-frv.c
index df86b147f47..6ca303c3566 100644
--- a/gdb/solib-frv.c
+++ b/gdb/solib-frv.c
@@ -1129,21 +1129,23 @@ frv_fetch_objfile_link_map (struct objfile *objfile)
return 0;
}
-struct target_so_ops frv_so_ops;
+const struct target_so_ops frv_so_ops =
+{
+ frv_relocate_section_addresses,
+ frv_free_so,
+ nullptr,
+ frv_clear_solib,
+ frv_solib_create_inferior_hook,
+ frv_current_sos,
+ open_symbol_file_object,
+ frv_in_dynsym_resolve_code,
+ solib_bfd_open,
+};
void _initialize_frv_solib ();
void
_initialize_frv_solib ()
{
- frv_so_ops.relocate_section_addresses = frv_relocate_section_addresses;
- frv_so_ops.free_so = frv_free_so;
- frv_so_ops.clear_solib = frv_clear_solib;
- frv_so_ops.solib_create_inferior_hook = frv_solib_create_inferior_hook;
- frv_so_ops.current_sos = frv_current_sos;
- frv_so_ops.open_symbol_file_object = open_symbol_file_object;
- frv_so_ops.in_dynsym_resolve_code = frv_in_dynsym_resolve_code;
- frv_so_ops.bfd_open = solib_bfd_open;
-
/* Debug this file's internals. */
add_setshow_zuinteger_cmd ("solib-frv", class_maintenance,
&solib_frv_debug, _("\
diff --git a/gdb/solib-svr4.c b/gdb/solib-svr4.c
index 893da86e27e..bab76e25baf 100644
--- a/gdb/solib-svr4.c
+++ b/gdb/solib-svr4.c
@@ -3121,8 +3121,6 @@ svr4_lp64_fetch_link_map_offsets (void)
}
\f
-struct target_so_ops svr4_so_ops;
-
/* Search order for ELF DSOs linked with -Bsymbolic. Those DSOs have a
different rule for symbol lookup. The lookup begins here in the DSO, not in
the main executable. */
@@ -3163,24 +3161,28 @@ 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,
+ svr4_current_sos,
+ open_symbol_file_object,
+ svr4_in_dynsym_resolve_code,
+ solib_bfd_open,
+ nullptr,
+ svr4_same,
+ svr4_keep_data_in_core,
+ svr4_update_solib_event_breakpoints,
+ svr4_handle_solib_event,
+};
+
void _initialize_svr4_solib ();
void
_initialize_svr4_solib ()
{
- svr4_so_ops.relocate_section_addresses = svr4_relocate_section_addresses;
- svr4_so_ops.free_so = svr4_free_so;
- svr4_so_ops.clear_so = svr4_clear_so;
- svr4_so_ops.clear_solib = svr4_clear_solib;
- svr4_so_ops.solib_create_inferior_hook = svr4_solib_create_inferior_hook;
- svr4_so_ops.current_sos = svr4_current_sos;
- svr4_so_ops.open_symbol_file_object = open_symbol_file_object;
- svr4_so_ops.in_dynsym_resolve_code = svr4_in_dynsym_resolve_code;
- svr4_so_ops.bfd_open = solib_bfd_open;
- svr4_so_ops.same = svr4_same;
- svr4_so_ops.keep_data_in_core = svr4_keep_data_in_core;
- svr4_so_ops.update_breakpoints = svr4_update_solib_event_breakpoints;
- svr4_so_ops.handle_event = svr4_handle_solib_event;
-
gdb::observers::free_objfile.attach (svr4_free_objfile_observer,
"solib-svr4");
}
diff --git a/gdb/solib-svr4.h b/gdb/solib-svr4.h
index 8b4968509f2..4a6880225e2 100644
--- a/gdb/solib-svr4.h
+++ b/gdb/solib-svr4.h
@@ -25,7 +25,7 @@
struct objfile;
struct target_so_ops;
-extern struct target_so_ops svr4_so_ops;
+extern const struct target_so_ops svr4_so_ops;
/* Link map info to include in an allocated so_list entry. */
diff --git a/gdb/solib-target.c b/gdb/solib-target.c
index 8def640a1e7..6eb0d171147 100644
--- a/gdb/solib-target.c
+++ b/gdb/solib-target.c
@@ -435,22 +435,15 @@ solib_target_in_dynsym_resolve_code (CORE_ADDR pc)
return in_plt_section (pc);
}
-struct target_so_ops solib_target_so_ops;
-
-void _initialize_solib_target ();
-void
-_initialize_solib_target ()
+const struct target_so_ops solib_target_so_ops =
{
- solib_target_so_ops.relocate_section_addresses
- = solib_target_relocate_section_addresses;
- solib_target_so_ops.free_so = solib_target_free_so;
- solib_target_so_ops.clear_solib = solib_target_clear_solib;
- solib_target_so_ops.solib_create_inferior_hook
- = solib_target_solib_create_inferior_hook;
- solib_target_so_ops.current_sos = solib_target_current_sos;
- solib_target_so_ops.open_symbol_file_object
- = solib_target_open_symbol_file_object;
- solib_target_so_ops.in_dynsym_resolve_code
- = solib_target_in_dynsym_resolve_code;
- solib_target_so_ops.bfd_open = solib_bfd_open;
-}
+ solib_target_relocate_section_addresses,
+ solib_target_free_so,
+ nullptr,
+ solib_target_clear_solib,
+ solib_target_solib_create_inferior_hook,
+ solib_target_current_sos,
+ solib_target_open_symbol_file_object,
+ solib_target_in_dynsym_resolve_code,
+ solib_bfd_open,
+};
diff --git a/gdb/solib-target.h b/gdb/solib-target.h
index b2028447c71..016a5fe7c2d 100644
--- a/gdb/solib-target.h
+++ b/gdb/solib-target.h
@@ -21,6 +21,6 @@
#define SOLIB_TARGET_H
struct target_so_ops;
-extern struct target_so_ops solib_target_so_ops;
+extern const struct target_so_ops solib_target_so_ops;
#endif /* solib-target.h */
diff --git a/gdb/tic6x-linux-tdep.c b/gdb/tic6x-linux-tdep.c
index b99cfc0d5e3..855eb303537 100644
--- a/gdb/tic6x-linux-tdep.c
+++ b/gdb/tic6x-linux-tdep.c
@@ -27,6 +27,7 @@
#include "elf-bfd.h"
#include "elf/tic6x.h"
#include "gdbarch.h"
+#include "solib-dsbt.h"
/* The offset from rt_sigframe pointer to SP register. */
#define TIC6X_SP_RT_SIGFRAME 8
@@ -161,7 +162,6 @@ tic6x_linux_syscall_next_pc (struct frame_info *frame)
}
-extern struct target_so_ops dsbt_so_ops;
static void
tic6x_uclinux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
{
--
2.34.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 0/3] Clean up solib_ops
2022-08-08 19:27 [PATCH 0/3] Clean up solib_ops Tom Tromey
` (2 preceding siblings ...)
2022-08-08 19:28 ` [PATCH 3/3] Constify some target_so_ops instances Tom Tromey
@ 2022-09-20 18:40 ` Tom Tromey
3 siblings, 0 replies; 5+ messages in thread
From: Tom Tromey @ 2022-09-20 18:40 UTC (permalink / raw)
To: Tom Tromey via Gdb-patches; +Cc: Tom Tromey
>>>>> "Tom" == Tom Tromey via Gdb-patches <gdb-patches@sourceware.org> writes:
Tom> While working on the recent regression fix, I found a few ways to
Tom> clean up solib_ops. Regression tested on x86-64 Fedora 34.
I've rebased these and re-tested them. I'm checking them in now.
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-09-20 18:40 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-08 19:27 [PATCH 0/3] Clean up solib_ops Tom Tromey
2022-08-08 19:27 ` [PATCH 1/3] Remove current_target_so_ops Tom Tromey
2022-08-08 19:28 ` [PATCH 2/3] Move solib_ops into gdbarch Tom Tromey
2022-08-08 19:28 ` [PATCH 3/3] Constify some target_so_ops instances Tom Tromey
2022-09-20 18:40 ` [PATCH 0/3] Clean up solib_ops Tom Tromey
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).