binutils-gdb/gdbserver/tdesc.cc
Andrew Burgess 51a948fdf0 gdb: Have allocate_target_description return a unique_ptr
Update allocate_target_description to return a target_desc_up, a
specialisation of unique_ptr.

This commit does not attempt to make use of the unique_ptr in the
best possible way, in almost all cases we immediately release the
pointer from within the unique_ptr and then continue as before.

There are a few places where it was easy to handle the unique_ptr, and
in these cases I've done that.

Everything under gdb/features/* is auto-regenerated.

There should be no user visible changes after this commit.

gdb/ChangeLog:

	* arch/aarch32.c (aarch32_create_target_description): Release
	unique_ptr returned from allocate_target_description.
	* arch/aarch64.c (aarch64_create_target_description): Likewise.
	* arch/amd64.c (amd64_create_target_description): Likewise.
	* arch/arc.c (arc_create_target_description): Likewise.
	* arch/arm.c (arm_create_target_description): Likewise.
	* arch/i386.c (i386_create_target_description): Likewise.
	* arch/riscv.c (riscv_create_target_description): Update return
	type.  Handle allocate_target_description returning a unique_ptr.
	(riscv_lookup_target_description): Update to handle unique_ptr.
	* arch/tic6x.c (tic6x_create_target_description): Release
	unique_ptr returned from allocate_target_description.
	* features/microblaze-with-stack-protect.c: Regenerate.
	* features/microblaze.c: Regenerate.
	* features/mips-dsp-linux.c: Regenerate.
	* features/mips-linux.c: Regenerate.
	* features/mips64-dsp-linux.c: Regenerate.
	* features/mips64-linux.c: Regenerate.
	* features/nds32.c: Regenerate.
	* features/nios2.c: Regenerate.
	* features/or1k.c: Regenerate.
	* features/rs6000/powerpc-32.c: Regenerate.
	* features/rs6000/powerpc-32l.c: Regenerate.
	* features/rs6000/powerpc-403.c: Regenerate.
	* features/rs6000/powerpc-403gc.c: Regenerate.
	* features/rs6000/powerpc-405.c: Regenerate.
	* features/rs6000/powerpc-505.c: Regenerate.
	* features/rs6000/powerpc-601.c: Regenerate.
	* features/rs6000/powerpc-602.c: Regenerate.
	* features/rs6000/powerpc-603.c: Regenerate.
	* features/rs6000/powerpc-604.c: Regenerate.
	* features/rs6000/powerpc-64.c: Regenerate.
	* features/rs6000/powerpc-64l.c: Regenerate.
	* features/rs6000/powerpc-7400.c: Regenerate.
	* features/rs6000/powerpc-750.c: Regenerate.
	* features/rs6000/powerpc-860.c: Regenerate.
	* features/rs6000/powerpc-altivec32.c: Regenerate.
	* features/rs6000/powerpc-altivec32l.c: Regenerate.
	* features/rs6000/powerpc-altivec64.c: Regenerate.
	* features/rs6000/powerpc-altivec64l.c: Regenerate.
	* features/rs6000/powerpc-e500.c: Regenerate.
	* features/rs6000/powerpc-e500l.c: Regenerate.
	* features/rs6000/powerpc-isa205-32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-altivec32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-altivec64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa205-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa205-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa207-htm-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa207-htm-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-isa207-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-isa207-vsx64l.c: Regenerate.
	* features/rs6000/powerpc-vsx32.c: Regenerate.
	* features/rs6000/powerpc-vsx32l.c: Regenerate.
	* features/rs6000/powerpc-vsx64.c: Regenerate.
	* features/rs6000/powerpc-vsx64l.c: Regenerate.
	* features/rs6000/rs6000.c: Regenerate.
	* features/rx.c: Regenerate.
	* features/s390-gs-linux64.c: Regenerate.
	* features/s390-linux32.c: Regenerate.
	* features/s390-linux32v1.c: Regenerate.
	* features/s390-linux32v2.c: Regenerate.
	* features/s390-linux64.c: Regenerate.
	* features/s390-linux64v1.c: Regenerate.
	* features/s390-linux64v2.c: Regenerate.
	* features/s390-te-linux64.c: Regenerate.
	* features/s390-tevx-linux64.c: Regenerate.
	* features/s390-vx-linux64.c: Regenerate.
	* features/s390x-gs-linux64.c: Regenerate.
	* features/s390x-linux64.c: Regenerate.
	* features/s390x-linux64v1.c: Regenerate.
	* features/s390x-linux64v2.c: Regenerate.
	* features/s390x-te-linux64.c: Regenerate.
	* features/s390x-tevx-linux64.c: Regenerate.
	* features/s390x-vx-linux64.c: Regenerate.
	* mips-tdep.c (_initialize_mips_tdep): Release unique_ptr returned
	from allocate_target_description.
	* target-descriptions.c (allocate_target_description): Update
	return type.
	(print_c_tdesc::visit_pre): Release unique_ptr returned from
	allocate_target_description.

gdbserver/ChangeLog:

	* linux-low.cc (linux_process_target::handle_extended_wait):
	Release the unique_ptr returned from allocate_target_description.
	* linux-riscv-low.cc (riscv_target::low_arch_setup): Likewise.
	* linux-x86-low.cc (tdesc_amd64_linux_no_xml): Change type.
	(tdesc_i386_linux_no_xml): Change type.
	(x86_linux_read_description): Borrow pointer from unique_ptr
	object.
	(x86_target::get_ipa_tdesc_idx): Likewise.
	(initialize_low_arch): Likewise.
	* tdesc.cc (allocate_target_description): Update return type.

gdbsupport/ChangeLog:

	* tdesc.h (allocate_target_description): Update return type.
2020-10-08 10:14:14 +01:00

236 lines
5.1 KiB
C++

/* Copyright (C) 2012-2020 Free Software Foundation, Inc.
This file is part of GDB.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "server.h"
#include "tdesc.h"
#include "regdef.h"
#ifndef IN_PROCESS_AGENT
target_desc::~target_desc ()
{
xfree ((char *) arch);
xfree ((char *) osabi);
}
bool target_desc::operator== (const target_desc &other) const
{
if (reg_defs != other.reg_defs)
return false;
/* Compare expedite_regs. */
int i = 0;
for (; expedite_regs[i] != NULL; i++)
{
if (strcmp (expedite_regs[i], other.expedite_regs[i]) != 0)
return false;
}
if (other.expedite_regs[i] != NULL)
return false;
return true;
}
#endif
void target_desc::accept (tdesc_element_visitor &v) const
{
#ifndef IN_PROCESS_AGENT
v.visit_pre (this);
for (const tdesc_feature_up &feature : features)
feature->accept (v);
v.visit_post (this);
#endif
}
void
init_target_desc (struct target_desc *tdesc,
const char **expedite_regs)
{
int offset = 0;
/* Go through all the features and populate reg_defs. */
for (const tdesc_feature_up &feature : tdesc->features)
for (const tdesc_reg_up &treg : feature->registers)
{
int regnum = treg->target_regnum;
/* Register number will increase (possibly with gaps) or be zero. */
gdb_assert (regnum == 0 || regnum >= tdesc->reg_defs.size ());
if (regnum != 0)
tdesc->reg_defs.resize (regnum, gdb::reg (offset));
tdesc->reg_defs.emplace_back (treg->name.c_str (), offset,
treg->bitsize);
offset += treg->bitsize;
}
tdesc->registers_size = offset / 8;
/* Make sure PBUFSIZ is large enough to hold a full register
packet. */
gdb_assert (2 * tdesc->registers_size + 32 <= PBUFSIZ);
#ifndef IN_PROCESS_AGENT
tdesc->expedite_regs = expedite_regs;
#endif
}
/* See gdbsupport/tdesc.h. */
target_desc_up
allocate_target_description (void)
{
return target_desc_up (new target_desc ());
}
/* See gdbsupport/tdesc.h. */
void
target_desc_deleter::operator() (struct target_desc *target_desc) const
{
delete target_desc;
}
#ifndef IN_PROCESS_AGENT
static const struct target_desc default_description {};
void
copy_target_description (struct target_desc *dest,
const struct target_desc *src)
{
dest->reg_defs = src->reg_defs;
dest->expedite_regs = src->expedite_regs;
dest->registers_size = src->registers_size;
dest->xmltarget = src->xmltarget;
}
const struct target_desc *
current_target_desc (void)
{
if (current_thread == NULL)
return &default_description;
return current_process ()->tdesc;
}
/* An empty structure. */
struct tdesc_compatible_info { };
/* See gdbsupport/tdesc.h. */
const std::vector<tdesc_compatible_info_up> &
tdesc_compatible_info_list (const target_desc *target_desc)
{
static std::vector<tdesc_compatible_info_up> empty;
return empty;
}
/* See gdbsupport/tdesc.h. */
const char *
tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &c_info)
{
return nullptr;
}
/* See gdbsupport/tdesc.h. */
const char *
tdesc_architecture_name (const struct target_desc *target_desc)
{
return target_desc->arch;
}
/* See gdbsupport/tdesc.h. */
void
set_tdesc_architecture (struct target_desc *target_desc,
const char *name)
{
target_desc->arch = xstrdup (name);
}
/* See gdbsupport/tdesc.h. */
const char *
tdesc_osabi_name (const struct target_desc *target_desc)
{
return target_desc->osabi;
}
/* See gdbsupport/tdesc.h. */
void
set_tdesc_osabi (struct target_desc *target_desc, const char *name)
{
target_desc->osabi = xstrdup (name);
}
/* See gdbsupport/tdesc.h. */
const char *
tdesc_get_features_xml (const target_desc *tdesc)
{
/* Either .xmltarget or .features is not NULL. */
gdb_assert (tdesc->xmltarget != NULL
|| (!tdesc->features.empty ()
&& tdesc->arch != NULL));
if (tdesc->xmltarget == NULL)
{
std::string buffer ("@");
print_xml_feature v (&buffer);
tdesc->accept (v);
tdesc->xmltarget = xstrdup (buffer.c_str ());
}
return tdesc->xmltarget;
}
#endif
/* See gdbsupport/tdesc.h. */
struct tdesc_feature *
tdesc_create_feature (struct target_desc *tdesc, const char *name)
{
struct tdesc_feature *new_feature = new tdesc_feature (name);
tdesc->features.emplace_back (new_feature);
return new_feature;
}
/* See gdbsupport/tdesc.h. */
bool
tdesc_contains_feature (const target_desc *tdesc, const std::string &feature)
{
gdb_assert (tdesc != nullptr);
for (const tdesc_feature_up &f : tdesc->features)
{
if (f->name == feature)
return true;
}
return false;
}