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>
This commit is contained in:
Tom Tromey 2024-03-21 11:15:56 -06:00
parent af25053d5f
commit c05dd51122
11 changed files with 30 additions and 35 deletions

View 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;
}
}

View 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

View 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;

View 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

View 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);

View 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;
}

View 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)",

View 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

View 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. */

View File

@ -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. */

View 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. */