Constify some target_so_ops instances
authorTom Tromey <tromey@adacore.com>
Mon, 8 Aug 2022 17:00:50 +0000 (11:00 -0600)
committerTom Tromey <tromey@adacore.com>
Tue, 20 Sep 2022 18:25:19 +0000 (12:25 -0600)
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.

13 files changed:
gdb/frv-tdep.h
gdb/solib-aix.c
gdb/solib-aix.h
gdb/solib-darwin.c
gdb/solib-darwin.h
gdb/solib-dsbt.c
gdb/solib-dsbt.h [new file with mode: 0644]
gdb/solib-frv.c
gdb/solib-svr4.c
gdb/solib-svr4.h
gdb/solib-target.c
gdb/solib-target.h
gdb/tic6x-linux-tdep.c

index 64052b8e754c7034899bacbce84175f7ffd73f72..037d81a6ddd562f7f33765b38b29fa181068108d 100644 (file)
@@ -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 */
index 948bd0f2463176af6b33e239c5b3af864534c456..f483f54de13a9d39d43044e0c7dfdb48d1c301d7 100644 (file)
@@ -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");
 
index edb0b5ad1422eb4e00914e453e9b8acc0bbf467f..24415f662344f8bd482a1d36b602b69afbabd86f 100644 (file)
@@ -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);
 
index e61ec0d4bf3554112cb3101f9a556ccf119b3aea..4eca080618a9a91bc6cd8e5b6ec1216f5e526398 100644 (file)
@@ -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,
+};
index e920e7a913e25f738bb23a1172a86588ec083712..32e7c8d1517a08a6011747741ed3100b5ddb62fd 100644 (file)
@@ -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 */
index b4cd16327a69781574dba0b28aabb7132fbc05c9..b866a0b4517771ace75e66a01a65d849683197e2 100644 (file)
@@ -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 (file)
index 0000000..98c0a31
--- /dev/null
@@ -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 */
index df86b147f4748c574f6aa85d2468ee641ea00f78..6ca303c35662c34b654b3f49ac8d35696845a46c 100644 (file)
@@ -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, _("\
index 893da86e27ea5309ce3f5b7c52a80a2e866d1c32..bab76e25baf6684c71374b67758df1dd273e3c0a 100644 (file)
@@ -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");
 }
index 8b4968509f2a56123bb86c5776763375cd998e07..4a6880225e25401ce6b789d6ca6a3ba6a52ef4be 100644 (file)
@@ -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.  */
 
index 8def640a1e7bbf3b9d5fe527d10fea4b252451bc..6eb0d171147481f737ccef69c78ae79fb55f41f0 100644 (file)
@@ -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,
+};
index b2028447c71dd0b7c334de8f3d5009c66cf7000f..016a5fe7c2da404ae2a6fe86746c9433138ea75c 100644 (file)
@@ -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 */
index b99cfc0d5e30a7697694ef36ccd25a5b689874fa..855eb303537d3aef8e0c7575f530787e6acb188d 100644 (file)
@@ -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)
 {