]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: remove gdbarch_info_init
authorSimon Marchi <simon.marchi@polymtl.ca>
Mon, 28 Jun 2021 15:49:22 +0000 (11:49 -0400)
committerSimon Marchi <simon.marchi@polymtl.ca>
Mon, 28 Jun 2021 15:49:22 +0000 (11:49 -0400)
While reviewing another patch, I realized that gdbarch_info_init could
easily be removed in favor of initializing gdbarch_info fields directly
in the struct declaration.  The only odd part is the union.  I don't
know if it's actually important for it to be zero-initialized, but I
presume it is.  I added a constructor to gdbarch_info to take care of
that.  A proper solution would be to use std::variant.  Or, these could
also be separate fields, the little extra space required wouldn't
matter.

gdb/ChangeLog:

* gdbarch.sh (struct gdbarch_info): Initialize fields, add
constructor.
* gdbarch.h: Re-generate.
* arch-utils.h (gdbarch_info_init): Remove, delete all usages.
* arch-utils.c (gdbarch_info_init): Remove.

Change-Id: I7502e08fe0f278d84eef1667a072e8a97bda5ab5

18 files changed:
gdb/ChangeLog
gdb/aarch64-linux-nat.c
gdb/aarch64-tdep.c
gdb/arch-utils.c
gdb/arch-utils.h
gdb/arm-tdep.c
gdb/corelow.c
gdb/cris-tdep.c
gdb/gdbarch.h
gdb/gdbarch.sh
gdb/i386-darwin-nat.c
gdb/inferior.c
gdb/mips-tdep.c
gdb/osabi.c
gdb/rs6000-nat.c
gdb/rs6000-tdep.c
gdb/selftest-arch.c
gdb/target-descriptions.c

index a220fffbe93c0c57c7b4e3c240fd78ba01662868..2c4719781aa0b5e6abcbc4cf12641e855e6d523f 100644 (file)
@@ -1,3 +1,11 @@
+2021-06-28  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * gdbarch.sh (struct gdbarch_info): Initialize fields, add
+       constructor.
+       * gdbarch.h: Re-generate.
+       * arch-utils.h (gdbarch_info_init): Remove, delete all usages.
+       * arch-utils.c (gdbarch_info_init): Remove.
+
 2021-06-28  Simon Marchi  <simon.marchi@polymtl.ca>
 
        * gdbarch.sh (struct gdbarch_info) <tdep_info>: Remove.
index 61224022f6aab16e74daa6115e69f613e934f2cb..c7cbebbc3517e4325e46913ede496d140b4d4098 100644 (file)
@@ -1060,7 +1060,6 @@ aarch64_linux_nat_target::thread_architecture (ptid_t ptid)
      new one), stashing the vector length inside id.  Use -1 for when SVE
      unavailable, to distinguish from an unset value of 0.  */
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   info.bfd_arch_info = bfd_lookup_arch (bfd_arch_aarch64, bfd_mach_aarch64);
   info.id = (int *) (vq == 0 ? -1 : vq);
   return gdbarch_find_by_info (info);
index 202b02108744b13fb93fb46441941740be35fc1f..dea16e729c0324dd66c70266b0b3575b85e4b775 100644 (file)
@@ -627,7 +627,6 @@ aarch64_analyze_prologue_test (void)
 {
   struct gdbarch_info info;
 
-  gdbarch_info_init (&info);
   info.bfd_arch_info = bfd_scan_arch ("aarch64");
 
   struct gdbarch *gdbarch = gdbarch_find_by_info (info);
@@ -4559,7 +4558,6 @@ aarch64_process_record_test (void)
   struct gdbarch_info info;
   uint32_t ret;
 
-  gdbarch_info_init (&info);
   info.bfd_arch_info = bfd_scan_arch ("aarch64");
 
   struct gdbarch *gdbarch = gdbarch_find_by_info (info);
index c75a79757ea24ff852231c3d381ebae39766e83d..4290d637ce16dfa803e41002632868645bfc0a36 100644 (file)
@@ -389,8 +389,6 @@ set_endian (const char *ignore_args, int from_tty, struct cmd_list_element *c)
 {
   struct gdbarch_info info;
 
-  gdbarch_info_init (&info);
-
   if (set_endian_string == endian_auto)
     {
       target_byte_order_user = BFD_ENDIAN_UNKNOWN;
@@ -548,8 +546,6 @@ set_architecture (const char *ignore_args,
 {
   struct gdbarch_info info;
 
-  gdbarch_info_init (&info);
-
   if (strcmp (set_architecture_string, "auto") == 0)
     {
       target_architecture_user = NULL;
@@ -630,7 +626,6 @@ struct gdbarch *
 gdbarch_from_bfd (bfd *abfd)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
 
   info.abfd = abfd;
   return gdbarch_find_by_info (info);
@@ -645,7 +640,6 @@ set_gdbarch_from_file (bfd *abfd)
   struct gdbarch_info info;
   struct gdbarch *gdbarch;
 
-  gdbarch_info_init (&info);
   info.abfd = abfd;
   info.target_desc = target_current_description ();
   gdbarch = gdbarch_find_by_info (info);
@@ -679,10 +673,6 @@ void
 initialize_current_architecture (void)
 {
   const char **arches = gdbarch_printable_names ();
-  struct gdbarch_info info;
-
-  /* determine a default architecture and byte order.  */
-  gdbarch_info_init (&info);
   
   /* Find a default architecture.  */
   if (default_bfd_arch == NULL)
@@ -705,6 +695,7 @@ initialize_current_architecture (void)
                        _("initialize_current_architecture: Arch not found"));
     }
 
+  gdbarch_info info;
   info.bfd_arch_info = default_bfd_arch;
 
   /* Take several guesses at a byte order.  */
@@ -769,21 +760,6 @@ initialize_current_architecture (void)
   }
 }
 
-
-/* Initialize a gdbarch info to values that will be automatically
-   overridden.  Note: Originally, this ``struct info'' was initialized
-   using memset(0).  Unfortunately, that ran into problems, namely
-   BFD_ENDIAN_BIG is zero.  An explicit initialization function that
-   can explicitly set each field to a well defined value is used.  */
-
-void
-gdbarch_info_init (struct gdbarch_info *info)
-{
-  memset (info, 0, sizeof (struct gdbarch_info));
-  info->byte_order = BFD_ENDIAN_UNKNOWN;
-  info->byte_order_for_code = info->byte_order;
-}
-
 /* Similar to init, but this time fill in the blanks.  Information is
    obtained from the global "set ..." options and explicitly
    initialized INFO fields.  */
index a5b40ad8ff1bdbc0a4760482c3d527fd8314bbc5..03e9082f6d771ccb1868ece935b8109b1e3447f8 100644 (file)
@@ -196,12 +196,6 @@ extern enum bfd_endian selected_byte_order (void);
    was explicitly selected.  */
 extern const char *selected_architecture_name (void);
 
-/* Initialize a ``struct info''.  Can't use memset(0) since some
-   default values are not zero.  "fill" takes all available
-   information and fills in any unspecified fields.  */
-
-extern void gdbarch_info_init (struct gdbarch_info *info);
-
 /* Similar to init, but this time fill in the blanks.  Information is
    obtained from the global "set ..." options and explicitly
    initialized INFO fields.  */
index 857a52a9a5137c5e95d9d2f811d3645802f6d2d1..339e03271e7ea321a16d76d522f7f2716ecd3c8f 100644 (file)
@@ -8403,15 +8403,12 @@ arm_skip_stub (struct frame_info *frame, CORE_ADDR pc)
 static void
 arm_update_current_architecture (void)
 {
-  struct gdbarch_info info;
-
   /* If the current architecture is not ARM, we have nothing to do.  */
   if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_arm)
     return;
 
   /* Update the architecture.  */
-  gdbarch_info_init (&info);
-
+  gdbarch_info info;
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, _("could not update architecture"));
 }
@@ -13237,7 +13234,6 @@ static void
 arm_record_test (void)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   info.bfd_arch_info = bfd_scan_arch ("arm");
 
   struct gdbarch *gdbarch = gdbarch_find_by_info (info);
@@ -13329,7 +13325,6 @@ arm_analyze_prologue_test ()
   for (bfd_endian endianness : {BFD_ENDIAN_LITTLE, BFD_ENDIAN_BIG})
     {
       struct gdbarch_info info;
-      gdbarch_info_init (&info);
       info.byte_order = endianness;
       info.byte_order_for_code = endianness;
       info.bfd_arch_info = bfd_scan_arch ("arm");
index b762eaa0f2f4fff55234a47be588757a7eba1522..eb785a08633ac1659711a8c30e38aa90067ea333 100644 (file)
@@ -165,7 +165,6 @@ core_target::core_target ()
   if (tdesc != nullptr)
     {
       struct gdbarch_info info;
-      gdbarch_info_init (&info);
       info.abfd = core_bfd;
       info.target_desc = tdesc;
       m_core_gdbarch = gdbarch_find_by_info (info);
index e1c141865cc60b5f97d179b10889b70251485d1d..01ef1604bffa70d7319f812d4b56266c0b60f935 100644 (file)
@@ -3879,7 +3879,6 @@ set_cris_version (const char *ignore_args, int from_tty,
   usr_cmd_cris_version_valid = 1;
   
   /* Update the current architecture, if needed.  */
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, 
                    _("cris_gdbarch_update: failed to update architecture."));
@@ -3892,7 +3891,6 @@ set_cris_mode (const char *ignore_args, int from_tty,
   struct gdbarch_info info;
 
   /* Update the current architecture, if needed.  */
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, 
                    "cris_gdbarch_update: failed to update architecture.");
@@ -3905,7 +3903,6 @@ set_cris_dwarf2_cfi (const char *ignore_args, int from_tty,
   struct gdbarch_info info;
 
   /* Update the current architecture, if needed.  */
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, 
                    _("cris_gdbarch_update: failed to update architecture."));
index 36ea4de17c8c83e0fd22c19c86763ee7a9e17f93..ece765b826fadbc0d39c915dada1b605c75ae6a0 100644 (file)
@@ -1781,18 +1781,20 @@ struct gdbarch_list
 
 struct gdbarch_info
 {
-  /* Use default: NULL (ZERO).  */
-  const struct bfd_arch_info *bfd_arch_info;
+  gdbarch_info ()
+    /* Ensure the union is zero-initialized.  Relies on the fact that there's
+       no member larger than TDESC_DATA.  */
+    : tdesc_data ()
+  {}
 
-  /* Use default: BFD_ENDIAN_UNKNOWN (NB: is not ZERO).  */
-  enum bfd_endian byte_order;
+  const struct bfd_arch_info *bfd_arch_info = nullptr;
 
-  enum bfd_endian byte_order_for_code;
+  enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN;
 
-  /* Use default: NULL (ZERO).  */
-  bfd *abfd;
+  enum bfd_endian byte_order_for_code = BFD_ENDIAN_UNKNOWN;
+
+  bfd *abfd = nullptr;
 
-  /* Use default: NULL (ZERO).  */
   union
     {
       /* Architecture-specific target description data.  Numerous targets
@@ -1805,11 +1807,9 @@ struct gdbarch_info
       int *id;
     };
 
-  /* Use default: GDB_OSABI_UNINITIALIZED (-1).  */
-  enum gdb_osabi osabi;
+  enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
 
-  /* Use default: NULL (ZERO).  */
-  const struct target_desc *target_desc;
+  const struct target_desc *target_desc = nullptr;
 };
 
 typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
@@ -1883,8 +1883,8 @@ extern int gdbarch_update_p (struct gdbarch_info info);
 
 /* Helper function.  Find an architecture matching info.
 
-   INFO should be initialized using gdbarch_info_init, relevant fields
-   set, and then finished using gdbarch_info_fill.
+   INFO should have relevant fields set, and then finished using
+   gdbarch_info_fill.
 
    Returns the corresponding architecture, or NULL if no matching
    architecture was found.  */
index 01a5ac88219d54620d5f7b3de8751befe49d76fc..d9332c2103e29fc6fec60de398b5f802b3457982 100755 (executable)
@@ -1533,18 +1533,20 @@ struct gdbarch_list
 
 struct gdbarch_info
 {
-  /* Use default: NULL (ZERO).  */
-  const struct bfd_arch_info *bfd_arch_info;
+  gdbarch_info ()
+    /* Ensure the union is zero-initialized.  Relies on the fact that there's
+       no member larger than TDESC_DATA.  */
+    : tdesc_data ()
+  {}
+
+  const struct bfd_arch_info *bfd_arch_info = nullptr;
 
-  /* Use default: BFD_ENDIAN_UNKNOWN (NB: is not ZERO).  */
-  enum bfd_endian byte_order;
+  enum bfd_endian byte_order = BFD_ENDIAN_UNKNOWN;
 
-  enum bfd_endian byte_order_for_code;
+  enum bfd_endian byte_order_for_code = BFD_ENDIAN_UNKNOWN;
 
-  /* Use default: NULL (ZERO).  */
-  bfd *abfd;
+  bfd *abfd = nullptr;
 
-  /* Use default: NULL (ZERO).  */
   union
     {
       /* Architecture-specific target description data.  Numerous targets
@@ -1557,11 +1559,9 @@ struct gdbarch_info
       int *id;
     };
 
-  /* Use default: GDB_OSABI_UNINITIALIZED (-1).  */
-  enum gdb_osabi osabi;
+  enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
 
-  /* Use default: NULL (ZERO).  */
-  const struct target_desc *target_desc;
+  const struct target_desc *target_desc = nullptr;
 };
 
 typedef struct gdbarch *(gdbarch_init_ftype) (struct gdbarch_info info, struct gdbarch_list *arches);
@@ -1637,8 +1637,8 @@ extern int gdbarch_update_p (struct gdbarch_info info);
 
 /* Helper function.  Find an architecture matching info.
 
-   INFO should be initialized using gdbarch_info_init, relevant fields
-   set, and then finished using gdbarch_info_fill.
+   INFO should have relevant fields set, and then finished using
+   gdbarch_info_fill.
 
    Returns the corresponding architecture, or NULL if no matching
    architecture was found.  */
index 922d7a6df0caa4111be23cc21d7e50913c0889bb..c1d6139490d8c1b9946d0e7d68729406bf5ee738 100644 (file)
@@ -479,7 +479,6 @@ darwin_check_osabi (darwin_inferior *inf, thread_t thread)
     {
       /* Attaching to a process.  Let's figure out what kind it is.  */
       x86_thread_state_t gp_regs;
-      struct gdbarch_info info;
       unsigned int gp_count = x86_THREAD_STATE_COUNT;
       kern_return_t ret;
 
@@ -491,7 +490,7 @@ darwin_check_osabi (darwin_inferior *inf, thread_t thread)
          return;
        }
 
-      gdbarch_info_init (&info);
+      gdbarch_info info;
       gdbarch_info_fill (&info);
       info.byte_order = gdbarch_byte_order (target_gdbarch ());
       info.osabi = GDB_OSABI_DARWIN;
index 059839ec962697a7116c4a772637e5c62511f1ab..e1c70d553fde27c9fe12c398c108d24e8ad9f5ca 100644 (file)
@@ -747,7 +747,6 @@ add_inferior_with_spaces (void)
   struct address_space *aspace;
   struct program_space *pspace;
   struct inferior *inf;
-  struct gdbarch_info info;
 
   /* If all inferiors share an address space on this system, this
      doesn't really return a new address space; otherwise, it
@@ -760,7 +759,7 @@ add_inferior_with_spaces (void)
 
   /* Setup the inferior's initial arch, based on information obtained
      from the global "set ..." options.  */
-  gdbarch_info_init (&info);
+  gdbarch_info info;
   inf->gdbarch = gdbarch_find_by_info (info);
   /* The "set ..." options reject invalid settings, so we should
      always have a valid arch by now.  */
index dbace1212508d9286f847e5c36c75d18c0f5326e..2aee4f10b316d45bc2b5dc554f805dfb2e4bd111 100644 (file)
@@ -865,7 +865,6 @@ set_mips64_transfers_32bit_regs (const char *args, int from_tty,
                                 struct cmd_list_element *c)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
      instead of relying on globals.  Doing that would let generic code
      handle the search for this specific architecture.  */
@@ -6918,7 +6917,6 @@ static void
 set_mipsfpu_single_command (const char *args, int from_tty)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   mips_fpu_type = MIPS_FPU_SINGLE;
   mips_fpu_type_auto = 0;
   /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
@@ -6932,7 +6930,6 @@ static void
 set_mipsfpu_double_command (const char *args, int from_tty)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   mips_fpu_type = MIPS_FPU_DOUBLE;
   mips_fpu_type_auto = 0;
   /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
@@ -6946,7 +6943,6 @@ static void
 set_mipsfpu_none_command (const char *args, int from_tty)
 {
   struct gdbarch_info info;
-  gdbarch_info_init (&info);
   mips_fpu_type = MIPS_FPU_NONE;
   mips_fpu_type_auto = 0;
   /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
@@ -8790,7 +8786,6 @@ mips_abi_update (const char *ignore_args,
 
   /* Force the architecture to update, and (if it's a MIPS architecture)
      mips_gdbarch_init will take care of the rest.  */
-  gdbarch_info_init (&info);
   gdbarch_update_p (info);
 }
 
index b1603c09c8553bf49530683ed0f57909f10690eb..aabf895c04514cbe935d266368eedac7f14084c5 100644 (file)
@@ -598,8 +598,6 @@ generic_elf_osabi_sniffer (bfd *abfd)
 static void
 set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
 {
-  struct gdbarch_info info;
-
   if (strcmp (set_osabi_string, "auto") == 0)
     user_osabi_state = osabi_auto;
   else if (strcmp (set_osabi_string, "default") == 0)
@@ -630,7 +628,7 @@ set_osabi (const char *args, int from_tty, struct cmd_list_element *c)
 
   /* NOTE: At some point (true multiple architectures) we'll need to be more
      graceful here.  */
-  gdbarch_info_init (&info);
+  gdbarch_info info;
   if (! gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, _("Updating OS ABI failed."));
 }
index 50c96e281c64abb5590187a890f3ae3e60042794..ee00a600343a41b3e973d5d7189e433c7c5d947c 100644 (file)
@@ -558,7 +558,6 @@ rs6000_nat_target::create_inferior (const char *exec_file,
   enum bfd_architecture arch;
   unsigned long mach;
   bfd abfd;
-  struct gdbarch_info info;
 
   inf_ptrace_target::create_inferior (exec_file, allargs, env, from_tty);
 
@@ -593,7 +592,7 @@ rs6000_nat_target::create_inferior (const char *exec_file,
 
   bfd_default_set_arch_mach (&abfd, arch, mach);
 
-  gdbarch_info_init (&info);
+  gdbarch_info info;
   info.bfd_arch_info = bfd_get_arch_info (&abfd);
   info.abfd = current_program_space->exec_bfd ();
 
index 5bcf5fca2c3bb402d3a5b8e35c4c17679815518f..a629450d746fa8729a0f82ae4acf73ecaf1dab25 100644 (file)
@@ -7260,7 +7260,6 @@ powerpc_set_soft_float (const char *args, int from_tty,
   struct gdbarch_info info;
 
   /* Update the architecture.  */
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, _("could not update architecture"));
 }
@@ -7269,7 +7268,6 @@ static void
 powerpc_set_vector_abi (const char *args, int from_tty,
                        struct cmd_list_element *c)
 {
-  struct gdbarch_info info;
   int vector_abi;
 
   for (vector_abi = POWERPC_VEC_AUTO;
@@ -7287,7 +7285,7 @@ powerpc_set_vector_abi (const char *args, int from_tty,
                    powerpc_vector_abi_string);
 
   /* Update the architecture.  */
-  gdbarch_info_init (&info);
+  gdbarch_info info;
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__, _("could not update architecture"));
 }
index ab1215c848c3d0fc658125a16bad5bb2ab7544f7..0eef134d4841bcf57fbd6a800743d058d55c2388 100644 (file)
@@ -64,7 +64,6 @@ struct gdbarch_selftest : public selftest
          {
            struct gdbarch_info info;
 
-           gdbarch_info_init (&info);
            info.bfd_arch_info = bfd_scan_arch (arches[i]);
 
            struct gdbarch *gdbarch = gdbarch_find_by_info (info);
index f7d0a688c62f884be049e6c7d8b3b4445e40609e..f94ace756d4df234fe2faec56bcd44be9e17529a 100644 (file)
@@ -555,7 +555,6 @@ target_find_description (void)
     {
       struct gdbarch_info info;
 
-      gdbarch_info_init (&info);
       info.target_desc = tdesc_info->tdesc;
       if (!gdbarch_update_p (info))
        warning (_("Architecture rejected target-supplied description"));
@@ -592,7 +591,6 @@ target_clear_description (void)
   tdesc_info->tdesc = nullptr;
 
   gdbarch_info info;
-  gdbarch_info_init (&info);
   if (!gdbarch_update_p (info))
     internal_error (__FILE__, __LINE__,
                    _("Could not remove target-supplied description"));