]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Use std::string for disassembler options
authorTom Tromey <tromey@adacore.com>
Thu, 21 Mar 2024 17:15:56 +0000 (11:15 -0600)
committerTom Tromey <tromey@adacore.com>
Fri, 22 Mar 2024 19:17:43 +0000 (13:17 -0600)
I noticed that the disassembler_options code uses manual memory
management.  It seemed simpler to replace this with std::string.

Approved-By: John Baldwin <jhb@FreeBSD.org>
gdb/arc-tdep.c
gdb/arch-utils.c
gdb/arm-tdep.c
gdb/disasm.c
gdb/gdbarch-gen.h
gdb/gdbarch.c
gdb/gdbarch_components.py
gdb/mips-tdep.c
gdb/riscv-tdep.c
gdb/rs6000-tdep.c
gdb/s390-tdep.c

index 7dd43cc239f9cbeb3a83de95b21fc0fca48c8fd7..63a1fd918d1fede7a3363724268ab62cd764dda1 100644 (file)
@@ -299,7 +299,7 @@ static const struct arc_register_feature arc_common_aux_reg_feature =
   }
 };
 
-static char *arc_disassembler_options = NULL;
+static std::string arc_disassembler_options;
 
 /* Functions are sorted in the order as they are used in the
    _initialize_arc_tdep (), which uses the same order as gdbarch.h.  Static
@@ -2365,7 +2365,6 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
        = tdesc_architecture (info.target_desc);
       if (tdesc_arch != NULL)
        {
-         xfree (arc_disassembler_options);
          /* FIXME: It is not really good to change disassembler options
             behind the scene, because that might override options
             specified by the user.  However as of now ARC doesn't support
@@ -2386,24 +2385,24 @@ arc_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
          switch (tdesc_arch->mach)
            {
            case bfd_mach_arc_arc601:
-             arc_disassembler_options = xstrdup ("cpu=arc601");
+             arc_disassembler_options = "cpu=arc601";
              break;
            case bfd_mach_arc_arc600:
-             arc_disassembler_options = xstrdup ("cpu=arc600");
+             arc_disassembler_options = "cpu=arc600";
              break;
            case bfd_mach_arc_arc700:
-             arc_disassembler_options = xstrdup ("cpu=arc700");
+             arc_disassembler_options = "cpu=arc700";
              break;
            case bfd_mach_arc_arcv2:
              /* Machine arcv2 has three arches: ARCv2, EM and HS; where ARCv2
                 is treated as EM.  */
              if (arc_arch_is_hs (tdesc_arch))
-               arc_disassembler_options = xstrdup ("cpu=hs38_linux");
+               arc_disassembler_options = "cpu=hs38_linux";
              else
-               arc_disassembler_options = xstrdup ("cpu=em4_fpuda");
+               arc_disassembler_options = "cpu=em4_fpuda";
              break;
            default:
-             arc_disassembler_options = NULL;
+             arc_disassembler_options = "";
              break;
            }
        }
index ae3354f65799a8038dec4cc4dc0323259a505499..d404d1fc38a3019b9622883a4dd0731e2827afae 100644 (file)
@@ -1156,11 +1156,11 @@ pstring (const char *string)
 }
 
 static const char *
-pstring_ptr (char **string)
+pstring_ptr (std::string *string)
 {
-  if (string == NULL || *string == NULL)
+  if (string == nullptr)
     return "(null)";
-  return *string;
+  return string->c_str ();
 }
 
 /* Helper function to print a list of strings, represented as "const
index 82b06f63fcb78068122b9dc476d8f138c116683b..3a5fbe71b8b53930bde7d0dae82eaa0970a531b5 100644 (file)
@@ -232,7 +232,7 @@ static const char *const arm_register_names[] =
  "fps", "cpsr" };              /* 24 25       */
 
 /* Holds the current set of options to be passed to the disassembler.  */
-static char *arm_disassembler_options;
+static std::string arm_disassembler_options;
 
 /* Valid register name styles.  */
 static const char **valid_disassembly_styles;
@@ -11042,7 +11042,7 @@ _initialize_arm_tdep ()
                          &setarmcmdlist, &showarmcmdlist,
                          &setlist, &showlist);
 
-  arm_disassembler_options = xstrdup ("reg-names-std");
+  arm_disassembler_options = "reg-names-std";
   const disasm_options_t *disasm_options
     = &disassembler_options_arm ()->options;
   int num_disassembly_styles = 0;
index 5bab5cf61995ee95100c0e04d5d894f1b9d359b8..cafbc078c60dc2531fe08aafd68ffc94856afc17 100644 (file)
@@ -1294,17 +1294,17 @@ gdb_buffered_insn_length (struct gdbarch *gdbarch,
 const char *
 get_disassembler_options (struct gdbarch *gdbarch)
 {
-  char **disassembler_options = gdbarch_disassembler_options (gdbarch);
-  if (disassembler_options == NULL)
-    return NULL;
-  return *disassembler_options;
+  std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
+  if (disassembler_options == nullptr || disassembler_options->empty ())
+    return nullptr;
+  return disassembler_options->c_str ();
 }
 
 void
 set_disassembler_options (const char *prospective_options)
 {
   struct gdbarch *gdbarch = get_current_arch ();
-  char **disassembler_options = gdbarch_disassembler_options (gdbarch);
+  std::string *disassembler_options = gdbarch_disassembler_options (gdbarch);
   const disasm_options_and_args_t *valid_options_and_args;
   const disasm_options_t *valid_options;
   gdb::unique_xmalloc_ptr<char> prospective_options_local
@@ -1317,11 +1317,8 @@ set_disassembler_options (const char *prospective_options)
      to reset their disassembler options to NULL.  */
   if (options == NULL)
     {
-      if (disassembler_options != NULL)
-       {
-         free (*disassembler_options);
-         *disassembler_options = NULL;
-       }
+      if (disassembler_options != nullptr)
+       disassembler_options->clear ();
       return;
     }
 
@@ -1373,8 +1370,7 @@ set_disassembler_options (const char *prospective_options)
        }
     }
 
-  free (*disassembler_options);
-  *disassembler_options = xstrdup (options);
+  *disassembler_options = options;
 }
 
 static void
index 13dd0ed5d5e143e1fe016f3b08cd8eae24208cf7..ebcff80bb9e82de4afc78404fe91da0aa9b4d4ee 100644 (file)
@@ -1715,8 +1715,8 @@ extern void set_gdbarch_addressable_memory_unit_size (struct gdbarch *gdbarch, g
 extern const char * gdbarch_disassembler_options_implicit (struct gdbarch *gdbarch);
 extern void set_gdbarch_disassembler_options_implicit (struct gdbarch *gdbarch, const char * disassembler_options_implicit);
 
-extern char ** gdbarch_disassembler_options (struct gdbarch *gdbarch);
-extern void set_gdbarch_disassembler_options (struct gdbarch *gdbarch, char ** disassembler_options);
+extern std::string * gdbarch_disassembler_options (struct gdbarch *gdbarch);
+extern void set_gdbarch_disassembler_options (struct gdbarch *gdbarch, std::string * disassembler_options);
 
 extern const disasm_options_and_args_t * gdbarch_valid_disassembler_options (struct gdbarch *gdbarch);
 extern void set_gdbarch_valid_disassembler_options (struct gdbarch *gdbarch, const disasm_options_and_args_t * valid_disassembler_options);
index 80a04bf0caf8738ce14db3a5fb6994968fdf67df..9319571deba9bb20122acaa6069c5c7caeea5750 100644 (file)
@@ -252,7 +252,7 @@ struct gdbarch
   gdbarch_gnu_triplet_regexp_ftype *gnu_triplet_regexp = default_gnu_triplet_regexp;
   gdbarch_addressable_memory_unit_size_ftype *addressable_memory_unit_size = default_addressable_memory_unit_size;
   const char * disassembler_options_implicit = 0;
-  char ** disassembler_options = 0;
+  std::string * disassembler_options = 0;
   const disasm_options_and_args_t * valid_disassembler_options = 0;
   gdbarch_type_align_ftype *type_align = default_type_align;
   gdbarch_get_pc_address_flags_ftype *get_pc_address_flags = default_get_pc_address_flags;
@@ -5362,7 +5362,7 @@ set_gdbarch_disassembler_options_implicit (struct gdbarch *gdbarch,
   gdbarch->disassembler_options_implicit = disassembler_options_implicit;
 }
 
-char **
+std::string *
 gdbarch_disassembler_options (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
@@ -5374,7 +5374,7 @@ gdbarch_disassembler_options (struct gdbarch *gdbarch)
 
 void
 set_gdbarch_disassembler_options (struct gdbarch *gdbarch,
-                                 char ** disassembler_options)
+                                 std::string * disassembler_options)
 {
   gdbarch->disassembler_options = disassembler_options;
 }
index 762d48a0187f8216fe689d40e64d3b749cf4bfa1..7d913ade6211f86ce4aba812c75959b3604b4edd 100644 (file)
@@ -2711,7 +2711,7 @@ Functions for allowing a target to modify its disassembler options.
 )
 
 Value(
-    type="char **",
+    type="std::string *",
     name="disassembler_options",
     invalid=False,
     printer="pstring_ptr (gdbarch->disassembler_options)",
index 107d06191b46f76b7251691b08ed3e96bf6cf94f..67bed1d2ba050a8a533dfa97b3861475d70d0708 100644 (file)
@@ -213,7 +213,7 @@ struct target_desc *mips_tdesc_gp32;
 struct target_desc *mips_tdesc_gp64;
 
 /* The current set of options to be passed to the disassembler.  */
-static char *mips_disassembler_options;
+static std::string mips_disassembler_options;
 
 /* Implicit disassembler options for individual ABIs.  These tell
    libopcodes to use general-purpose register names corresponding
index 68ef3233e8d9a0e12d446449b56b8185ccc12eb1..604a19fe2a62e6b221ce81c5869e21ef0d6edba4 100644 (file)
@@ -133,7 +133,7 @@ static const char *riscv_feature_name_virtual = "org.gnu.gdb.riscv.virtual";
 static const char *riscv_feature_name_vector = "org.gnu.gdb.riscv.vector";
 
 /* The current set of options to be passed to the disassembler.  */
-static char *riscv_disassembler_options;
+static std::string riscv_disassembler_options;
 
 /* Cached information about a frame.  */
 
index c8450345be271a1d94cf0c6e8f141952ce749c45..3157213cb1fae5f5eeb2dec011df194fe549aaf4 100644 (file)
     && (regnum) < (tdep)->ppc_cefpr0_regnum + ppc_num_efprs)
 
 /* Holds the current set of options to be passed to the disassembler.  */
-static char *powerpc_disassembler_options;
+static std::string powerpc_disassembler_options;
 
 /* The list of available "set powerpc ..." and "show powerpc ..."
    commands.  */
index 75983550a5cef65aff384d4cb9fcce81d8f04d3c..174338e188521973d2b1a69017f19d406951f96e 100644 (file)
@@ -45,7 +45,7 @@
 #include "features/s390x-linux64.c"
 
 /* Holds the current set of options to be passed to the disassembler.  */
-static char *s390_disassembler_options;
+static std::string s390_disassembler_options;
 
 /* Breakpoints.  */