Change gcc_target_options to return std::string

This patch was inspired by a recent review that recommended using
std::string in a new implementation of the gcc_target_options gdbarch
function.  It changes this function to return std::string rather than
an ordinary xmalloc'd string.

I believe this caught a latent memory leak in compile.c:get_args.

Tested on x86-64 Fedora 29.

gdb/ChangeLog
2019-10-15  Tom Tromey  <tromey@adacore.com>

	* gdbarch.h, gdbarch.c: Rebuild.
	* gdbarch.sh (gcc_target_options): Change return type to
	std::string.
	* compile/compile.c (get_args): Update.
	* nios2-tdep.c (nios2_gcc_target_options): Return std::string.
	* arm-linux-tdep.c (arm_linux_gcc_target_options): Return
	std::string.
	* aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return
	std::string.
	* arch-utils.c (default_gcc_target_options): Return std::string.
	* arch-utils.h (default_gcc_target_options): Return std::string.
	* s390-tdep.c (s390_gcc_target_options): Return std::string.

Change-Id: I51f61703426a323089e646da8f22320a2cafbc1f
This commit is contained in:
Tom Tromey 2019-10-15 10:57:40 -06:00
parent 81e6b8eb20
commit 953cff5630
11 changed files with 35 additions and 19 deletions

View File

@ -1,3 +1,18 @@
2019-10-15 Tom Tromey <tromey@adacore.com>
* gdbarch.h, gdbarch.c: Rebuild.
* gdbarch.sh (gcc_target_options): Change return type to
std::string.
* compile/compile.c (get_args): Update.
* nios2-tdep.c (nios2_gcc_target_options): Return std::string.
* arm-linux-tdep.c (arm_linux_gcc_target_options): Return
std::string.
* aarch64-linux-tdep.c (aarch64_linux_gcc_target_options): Return
std::string.
* arch-utils.c (default_gcc_target_options): Return std::string.
* arch-utils.h (default_gcc_target_options): Return std::string.
* s390-tdep.c (s390_gcc_target_options): Return std::string.
2019-10-15 Christian Biesinger <cbiesinger@google.com>
* breakpoint.c (breakpoint_chain): Make static.

View File

@ -1429,11 +1429,11 @@ aarch64_linux_syscall_record (struct regcache *regcache,
/* Implement the "gcc_target_options" gdbarch method. */
static char *
static std::string
aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
{
/* GCC doesn't know "-m64". */
return NULL;
return {};
}
static void

View File

@ -903,11 +903,12 @@ default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size)
/* -mcmodel=large is used so that no GOT (Global Offset Table) is needed to be
created in inferior memory by GDB (normally it is set by ld.so). */
char *
std::string
default_gcc_target_options (struct gdbarch *gdbarch)
{
return xstrprintf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
gdbarch_ptr_bit (gdbarch) == 64 ? " -mcmodel=large" : "");
return string_printf ("-m%d%s", gdbarch_ptr_bit (gdbarch),
(gdbarch_ptr_bit (gdbarch) == 64
? " -mcmodel=large" : ""));
}
/* gdbarch gnu_triplet_regexp method. */

View File

@ -247,7 +247,7 @@ extern void default_skip_permanent_breakpoint (struct regcache *regcache);
extern CORE_ADDR default_infcall_mmap (CORE_ADDR size, unsigned prot);
extern void default_infcall_munmap (CORE_ADDR addr, CORE_ADDR size);
extern char *default_gcc_target_options (struct gdbarch *gdbarch);
extern std::string default_gcc_target_options (struct gdbarch *gdbarch);
extern const char *default_gnu_triplet_regexp (struct gdbarch *gdbarch);
extern int default_addressable_memory_unit_size (struct gdbarch *gdbarch);

View File

@ -1710,11 +1710,11 @@ arm_linux_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
/* Implement the gcc_target_options gdbarch method. */
static char *
static std::string
arm_linux_gcc_target_options (struct gdbarch *gdbarch)
{
/* GCC doesn't know "-m32". */
return NULL;
return {};
}
static void

View File

@ -635,7 +635,7 @@ get_args (const compile_instance *compiler, struct gdbarch *gdbarch,
int argc_compiler;
char **argv_compiler;
build_argc_argv (gdbarch_gcc_target_options (gdbarch),
build_argc_argv (gdbarch_gcc_target_options (gdbarch).c_str (),
argcp, argvp);
cs_producer_options = get_selected_pc_producer_options ();

View File

@ -5043,7 +5043,7 @@ set_gdbarch_infcall_munmap (struct gdbarch *gdbarch,
gdbarch->infcall_munmap = infcall_munmap;
}
char *
std::string
gdbarch_gcc_target_options (struct gdbarch *gdbarch)
{
gdb_assert (gdbarch != NULL);

View File

@ -1596,10 +1596,10 @@ extern void set_gdbarch_infcall_munmap (struct gdbarch *gdbarch, gdbarch_infcall
/* Return string (caller has to use xfree for it) with options for GCC
to produce code for this target, typically "-m64", "-m32" or "-m31".
These options are put before CU's DW_AT_producer compilation options so that
they can override it. Method may also return NULL. */
they can override it. */
typedef char * (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch);
extern char * gdbarch_gcc_target_options (struct gdbarch *gdbarch);
typedef std::string (gdbarch_gcc_target_options_ftype) (struct gdbarch *gdbarch);
extern std::string gdbarch_gcc_target_options (struct gdbarch *gdbarch);
extern void set_gdbarch_gcc_target_options (struct gdbarch *gdbarch, gdbarch_gcc_target_options_ftype *gcc_target_options);
/* Return a regular expression that matches names used by this

View File

@ -1184,8 +1184,8 @@ f;void;infcall_munmap;CORE_ADDR addr, CORE_ADDR size;addr, size;;default_infcall
# Return string (caller has to use xfree for it) with options for GCC
# to produce code for this target, typically "-m64", "-m32" or "-m31".
# These options are put before CU's DW_AT_producer compilation options so that
# they can override it. Method may also return NULL.
m;char *;gcc_target_options;void;;;default_gcc_target_options;;0
# they can override it.
m;std::string;gcc_target_options;void;;;default_gcc_target_options;;0
# Return a regular expression that matches names used by this
# architecture in GNU configury triplets. The result is statically

View File

@ -2260,11 +2260,11 @@ nios2_type_align (struct gdbarch *gdbarch, struct type *type)
}
/* Implement the gcc_target_options gdbarch method. */
static char *
static std::string
nios2_gcc_target_options (struct gdbarch *gdbarch)
{
/* GCC doesn't know "-m32". */
return NULL;
return {};
}
/* Initialize the Nios II gdbarch. */

View File

@ -6779,10 +6779,10 @@ UNKNOWN_OP:
/* Implement gdbarch_gcc_target_options. GCC does not know "-m32" or
"-mcmodel=large". */
static char *
static std::string
s390_gcc_target_options (struct gdbarch *gdbarch)
{
return xstrdup (gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31");
return gdbarch_ptr_bit (gdbarch) == 64 ? "-m64" : "-m31";
}
/* Implement gdbarch_gnu_triplet_regexp. Target triplets are "s390-*"