Use std::string for disassembler options

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>


diff --git a/gdb/arc-tdep.c b/gdb/arc-tdep.c
index 7dd43cc..63a1fd9 100644
--- a/gdb/arc-tdep.c
+++ b/gdb/arc-tdep.c
@@ -299,7 +299,7 @@
   }
 };
 
-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 @@
 	= 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 @@
 	  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;
 	    }
 	}
diff --git a/gdb/arch-utils.c b/gdb/arch-utils.c
index ae3354f..d404d1f 100644
--- a/gdb/arch-utils.c
+++ b/gdb/arch-utils.c
@@ -1156,11 +1156,11 @@
 }
 
 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
diff --git a/gdb/arm-tdep.c b/gdb/arm-tdep.c
index 82b06f6..3a5fbe7 100644
--- a/gdb/arm-tdep.c
+++ b/gdb/arm-tdep.c
@@ -232,7 +232,7 @@
  "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 @@
 			  &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;
diff --git a/gdb/disasm.c b/gdb/disasm.c
index 5bab5cf..cafbc07 100644
--- a/gdb/disasm.c
+++ b/gdb/disasm.c
@@ -1294,17 +1294,17 @@
 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 @@
      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 @@
 	}
     }
 
-  free (*disassembler_options);
-  *disassembler_options = xstrdup (options);
+  *disassembler_options = options;
 }
 
 static void
diff --git a/gdb/gdbarch-gen.h b/gdb/gdbarch-gen.h
index 13dd0ed..ebcff80 100644
--- a/gdb/gdbarch-gen.h
+++ b/gdb/gdbarch-gen.h
@@ -1715,8 +1715,8 @@
 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);
diff --git a/gdb/gdbarch.c b/gdb/gdbarch.c
index 80a04bf..9319571 100644
--- a/gdb/gdbarch.c
+++ b/gdb/gdbarch.c
@@ -252,7 +252,7 @@
   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 @@
   gdbarch->disassembler_options_implicit = disassembler_options_implicit;
 }
 
-char **
+std::string *
 gdbarch_disassembler_options (struct gdbarch *gdbarch)
 {
   gdb_assert (gdbarch != NULL);
@@ -5374,7 +5374,7 @@
 
 void
 set_gdbarch_disassembler_options (struct gdbarch *gdbarch,
-				  char ** disassembler_options)
+				  std::string * disassembler_options)
 {
   gdbarch->disassembler_options = disassembler_options;
 }
diff --git a/gdb/gdbarch_components.py b/gdb/gdbarch_components.py
index 762d48a..7d913ad 100644
--- a/gdb/gdbarch_components.py
+++ b/gdb/gdbarch_components.py
@@ -2711,7 +2711,7 @@
 )
 
 Value(
-    type="char **",
+    type="std::string *",
     name="disassembler_options",
     invalid=False,
     printer="pstring_ptr (gdbarch->disassembler_options)",
diff --git a/gdb/mips-tdep.c b/gdb/mips-tdep.c
index 107d061..67bed1d 100644
--- a/gdb/mips-tdep.c
+++ b/gdb/mips-tdep.c
@@ -213,7 +213,7 @@
 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
diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index 68ef323..604a19f 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -133,7 +133,7 @@
 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.  */
 
diff --git a/gdb/rs6000-tdep.c b/gdb/rs6000-tdep.c
index c845034..3157213 100644
--- a/gdb/rs6000-tdep.c
+++ b/gdb/rs6000-tdep.c
@@ -130,7 +130,7 @@
     && (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.  */
diff --git a/gdb/s390-tdep.c b/gdb/s390-tdep.c
index 7598355..174338e 100644
--- a/gdb/s390-tdep.c
+++ b/gdb/s390-tdep.c
@@ -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.  */