After commit:
commit
51a948fdf0e14fb69ab9e0c79ae8b2415801f9a3
Date: Mon Jul 20 14:18:04 2020 +0100
gdb: Have allocate_target_description return a unique_ptr
There were a few places where we could (should?) have delayed
releasing the target_desc_up until a little later. This commit
catches these cases.
In the case of ARC, the target_desc_up is now exposed right out to
gdbserver, which means making a small change there too.
There should be no user visible changes after this commit.
gdb/ChangeLog:
* arch/aarch32.c (aarch32_create_target_description): Release the
target_desc_up as late as possible.
* arch/aarch64.c (aarch64_create_target_description): Likewise.
* arch/amd64.c (amd64_create_target_description): Likewise.
* arch/arc.c (arc_create_target_description): Return a
target_desc_up, don't release it.
* arch/arc.h (arc_create_target_description): Update declaration.
(arc_lookup_target_description): Move target_desc_up into the
cache, and return a borrowed pointer.
* arch/arm.c (arm_create_target_description): Release the
target_desc_up as late as possible.
* arch/i386.c (i386_create_target_description): Likewise.
* arch/riscv.h (riscv_create_target_description): Update
declaration to match definition.
* arch/tic6x.c (tic6x_create_target_description): Release the
target_desc_up as late as possible.
gdbserver/ChangeLog:
* linux-arc-low.cc (arc_linux_read_description): Release the
unique_ptr returned from arc_create_target_description.
+2020-10-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * arch/aarch32.c (aarch32_create_target_description): Release the
+ target_desc_up as late as possible.
+ * arch/aarch64.c (aarch64_create_target_description): Likewise.
+ * arch/amd64.c (amd64_create_target_description): Likewise.
+ * arch/arc.c (arc_create_target_description): Return a
+ target_desc_up, don't release it.
+ * arch/arc.h (arc_create_target_description): Update declaration.
+ (arc_lookup_target_description): Move target_desc_up into the
+ cache, and return a borrowed pointer.
+ * arch/arm.c (arm_create_target_description): Release the
+ target_desc_up as late as possible.
+ * arch/i386.c (i386_create_target_description): Likewise.
+ * arch/riscv.h (riscv_create_target_description): Update
+ declaration to match definition.
+ * arch/tic6x.c (tic6x_create_target_description): Release the
+ target_desc_up as late as possible.
+
2020-10-09 Andrew Burgess <andrew.burgess@embecosm.com>
* Makefile.in: Include Makefile.gnulib.inc. Don't define LIBGNU
target_desc *
aarch32_create_target_description ()
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
- set_tdesc_architecture (tdesc, "arm");
+ set_tdesc_architecture (tdesc.get (), "arm");
#endif
long regnum = 0;
- regnum = create_feature_arm_arm_core (tdesc, regnum);
+ regnum = create_feature_arm_arm_core (tdesc.get (), regnum);
/* Create a vfpv3 feature, then a blank NEON feature. */
- regnum = create_feature_arm_arm_vfpv3 (tdesc, regnum);
- tdesc_create_feature (tdesc, "org.gnu.gdb.arm.neon");
+ regnum = create_feature_arm_arm_vfpv3 (tdesc.get (), regnum);
+ tdesc_create_feature (tdesc.get (), "org.gnu.gdb.arm.neon");
- return tdesc;
+ return tdesc.release ();
}
target_desc *
aarch64_create_target_description (uint64_t vq, bool pauth_p)
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
- set_tdesc_architecture (tdesc, "aarch64");
+ set_tdesc_architecture (tdesc.get (), "aarch64");
#endif
long regnum = 0;
- regnum = create_feature_aarch64_core (tdesc, regnum);
+ regnum = create_feature_aarch64_core (tdesc.get (), regnum);
if (vq == 0)
- regnum = create_feature_aarch64_fpu (tdesc, regnum);
+ regnum = create_feature_aarch64_fpu (tdesc.get (), regnum);
else
- regnum = create_feature_aarch64_sve (tdesc, regnum, vq);
+ regnum = create_feature_aarch64_sve (tdesc.get (), regnum, vq);
if (pauth_p)
- regnum = create_feature_aarch64_pauth (tdesc, regnum);
+ regnum = create_feature_aarch64_pauth (tdesc.get (), regnum);
- return tdesc;
+ return tdesc.release ();
}
amd64_create_target_description (uint64_t xcr0, bool is_x32, bool is_linux,
bool segments)
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
- set_tdesc_architecture (tdesc, is_x32 ? "i386:x64-32" : "i386:x86-64");
+ set_tdesc_architecture (tdesc.get (),
+ is_x32 ? "i386:x64-32" : "i386:x86-64");
if (is_linux)
- set_tdesc_osabi (tdesc, "GNU/Linux");
+ set_tdesc_osabi (tdesc.get (), "GNU/Linux");
#endif
long regnum = 0;
if (is_x32)
- regnum = create_feature_i386_x32_core (tdesc, regnum);
+ regnum = create_feature_i386_x32_core (tdesc.get (), regnum);
else
- regnum = create_feature_i386_64bit_core (tdesc, regnum);
+ regnum = create_feature_i386_64bit_core (tdesc.get (), regnum);
- regnum = create_feature_i386_64bit_sse (tdesc, regnum);
+ regnum = create_feature_i386_64bit_sse (tdesc.get (), regnum);
if (is_linux)
- regnum = create_feature_i386_64bit_linux (tdesc, regnum);
+ regnum = create_feature_i386_64bit_linux (tdesc.get (), regnum);
if (segments)
- regnum = create_feature_i386_64bit_segments (tdesc, regnum);
+ regnum = create_feature_i386_64bit_segments (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_AVX)
- regnum = create_feature_i386_64bit_avx (tdesc, regnum);
+ regnum = create_feature_i386_64bit_avx (tdesc.get (), regnum);
if ((xcr0 & X86_XSTATE_MPX) && !is_x32)
- regnum = create_feature_i386_64bit_mpx (tdesc, regnum);
+ regnum = create_feature_i386_64bit_mpx (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_AVX512)
- regnum = create_feature_i386_64bit_avx512 (tdesc, regnum);
+ regnum = create_feature_i386_64bit_avx512 (tdesc.get (), regnum);
if ((xcr0 & X86_XSTATE_PKRU) && !is_x32)
- regnum = create_feature_i386_64bit_pkeys (tdesc, regnum);
+ regnum = create_feature_i386_64bit_pkeys (tdesc.get (), regnum);
- return tdesc;
+ return tdesc.release ();
}
#define STATIC_IN_GDB
#endif
-STATIC_IN_GDB target_desc *
+STATIC_IN_GDB target_desc_up
arc_create_target_description (const struct arc_arch_features &features)
{
/* Create a new target description. */
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
std::string arch_name;
gdb_assert_not_reached (msg.c_str ());
}
- set_tdesc_architecture (tdesc, arch_name.c_str ());
+ set_tdesc_architecture (tdesc.get (), arch_name.c_str ());
#endif
long regnum = 0;
switch (features.isa)
{
case ARC_ISA_ARCV1:
- regnum = create_feature_arc_v1_core (tdesc, regnum);
- regnum = create_feature_arc_v1_aux (tdesc, regnum);
+ regnum = create_feature_arc_v1_core (tdesc.get (), regnum);
+ regnum = create_feature_arc_v1_aux (tdesc.get (), regnum);
break;
case ARC_ISA_ARCV2:
- regnum = create_feature_arc_v2_core (tdesc, regnum);
- regnum = create_feature_arc_v2_aux (tdesc, regnum);
+ regnum = create_feature_arc_v2_core (tdesc.get (), regnum);
+ regnum = create_feature_arc_v2_aux (tdesc.get (), regnum);
break;
default:
std::string msg = string_printf
if (it != arc_tdesc_cache.end ())
return it->second.get ();
- target_desc *tdesc = arc_create_target_description (features);
+ target_desc_up tdesc = arc_create_target_description (features);
- /* Add the newly created target description to the repertoire. */
- arc_tdesc_cache.emplace (features, tdesc);
- return tdesc;
+ /* Add to the cache, and return a pointer borrowed from the
+ target_desc_up. This is safe as the cache (and the pointers
+ contained within it) are not deleted until GDB exits. */
+ target_desc *ptr = tdesc.get ();
+ arc_tdesc_cache.emplace (features, std::move (tdesc));
+ return ptr;
}
#endif /* !GDBSERVER */
The only external client of this must be the gdbserver which manipulates
the returned data. */
-target_desc *arc_create_target_description
+target_desc_up arc_create_target_description
(const struct arc_arch_features &features);
#else
target_desc *
arm_create_target_description (arm_fp_type fp_type)
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
if (fp_type == ARM_FP_TYPE_IWMMXT)
- set_tdesc_architecture (tdesc, "iwmmxt");
+ set_tdesc_architecture (tdesc.get (), "iwmmxt");
else
- set_tdesc_architecture (tdesc, "arm");
+ set_tdesc_architecture (tdesc.get (), "arm");
#endif
long regnum = 0;
- regnum = create_feature_arm_arm_core (tdesc, regnum);
+ regnum = create_feature_arm_arm_core (tdesc.get (), regnum);
switch (fp_type)
{
break;
case ARM_FP_TYPE_VFPV2:
- regnum = create_feature_arm_arm_vfpv2 (tdesc, regnum);
+ regnum = create_feature_arm_arm_vfpv2 (tdesc.get (), regnum);
break;
case ARM_FP_TYPE_VFPV3:
- regnum = create_feature_arm_arm_vfpv3 (tdesc, regnum);
+ regnum = create_feature_arm_arm_vfpv3 (tdesc.get (), regnum);
break;
case ARM_FP_TYPE_IWMMXT:
- regnum = create_feature_arm_xscale_iwmmxt (tdesc, regnum);
+ regnum = create_feature_arm_xscale_iwmmxt (tdesc.get (), regnum);
break;
default:
error (_("Invalid Arm FP type: %d"), fp_type);
}
- return tdesc;
+ return tdesc.release ();
}
/* See arch/arm.h. */
target_desc *
i386_create_target_description (uint64_t xcr0, bool is_linux, bool segments)
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
#ifndef IN_PROCESS_AGENT
- set_tdesc_architecture (tdesc, "i386");
+ set_tdesc_architecture (tdesc.get (), "i386");
if (is_linux)
- set_tdesc_osabi (tdesc, "GNU/Linux");
+ set_tdesc_osabi (tdesc.get (), "GNU/Linux");
#endif
long regnum = 0;
if (xcr0 & X86_XSTATE_X87)
- regnum = create_feature_i386_32bit_core (tdesc, regnum);
+ regnum = create_feature_i386_32bit_core (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_SSE)
- regnum = create_feature_i386_32bit_sse (tdesc, regnum);
+ regnum = create_feature_i386_32bit_sse (tdesc.get (), regnum);
if (is_linux)
- regnum = create_feature_i386_32bit_linux (tdesc, regnum);
+ regnum = create_feature_i386_32bit_linux (tdesc.get (), regnum);
if (segments)
- regnum = create_feature_i386_32bit_segments (tdesc, regnum);
+ regnum = create_feature_i386_32bit_segments (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_AVX)
- regnum = create_feature_i386_32bit_avx (tdesc, regnum);
+ regnum = create_feature_i386_32bit_avx (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_MPX)
- regnum = create_feature_i386_32bit_mpx (tdesc, regnum);
+ regnum = create_feature_i386_32bit_mpx (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_AVX512)
- regnum = create_feature_i386_32bit_avx512 (tdesc, regnum);
+ regnum = create_feature_i386_32bit_avx512 (tdesc.get (), regnum);
if (xcr0 & X86_XSTATE_PKRU)
- regnum = create_feature_i386_32bit_pkeys (tdesc, regnum);
+ regnum = create_feature_i386_32bit_pkeys (tdesc.get (), regnum);
- return tdesc;
+ return tdesc.release ();
}
This is only used directly from the gdbserver where the created target
description is modified after it is return. */
-target_desc *riscv_create_target_description
+target_desc_up riscv_create_target_description
(const struct riscv_gdbarch_features features);
#else
target_desc *
tic6x_create_target_description (enum c6x_feature feature)
{
- target_desc *tdesc = allocate_target_description ().release ();
+ target_desc_up tdesc = allocate_target_description ();
- set_tdesc_architecture (tdesc, "tic6x");
- set_tdesc_osabi (tdesc, "GNU/Linux");
+ set_tdesc_architecture (tdesc.get (), "tic6x");
+ set_tdesc_osabi (tdesc.get (), "GNU/Linux");
long regnum = 0;
- regnum = create_feature_tic6x_core (tdesc, regnum);
+ regnum = create_feature_tic6x_core (tdesc.get (), regnum);
if (feature == C6X_GP || feature == C6X_C6XP)
- regnum = create_feature_tic6x_gp (tdesc, regnum);
+ regnum = create_feature_tic6x_gp (tdesc.get (), regnum);
if (feature == C6X_C6XP)
- regnum = create_feature_tic6x_c6xp (tdesc, regnum);
+ regnum = create_feature_tic6x_c6xp (tdesc.get (), regnum);
- return tdesc;
+ return tdesc.release ();
}
+2020-10-09 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * linux-arc-low.cc (arc_linux_read_description): Release the
+ unique_ptr returned from arc_create_target_description.
+
2020-10-09 Andrew Burgess <andrew.burgess@embecosm.com>
* Makefile.in: Include Makefile.gnulib.inc. Don't define LIBGNU
#else
arc_arch_features features (4, ARC_ISA_ARCV2);
#endif
- struct target_desc *tdesc = arc_create_target_description (features);
+ target_desc_up tdesc = arc_create_target_description (features);
static const char *expedite_regs[] = { "sp", "status32", nullptr };
- init_target_desc (tdesc, expedite_regs);
+ init_target_desc (tdesc.get (), expedite_regs);
- return tdesc;
+ return tdesc.release ();
}
void