/* Target description support for GDB.
- Copyright (C) 2006-2018 Free Software Foundation, Inc.
+ Copyright (C) 2006-2019 Free Software Foundation, Inc.
Contributed by CodeSourcery.
#include "reggroups.h"
#include "target.h"
#include "target-descriptions.h"
-#include "vec.h"
+#include "common/vec.h"
#include "xml-support.h"
#include "xml-tdesc.h"
#include "osabi.h"
{
m_type = arch_composite_type (m_gdbarch, NULL, TYPE_CODE_STRUCT);
TYPE_NAME (m_type) = xstrdup (e->name.c_str ());
- TYPE_TAG_NAME (m_type) = TYPE_NAME (m_type);
for (const tdesc_type_field &f : e->fields)
{
/* Next try to read the description from the current target using
target objects. */
if (current_target_desc == NULL)
- current_target_desc = target_read_description_xml (¤t_target);
+ current_target_desc = target_read_description_xml (current_top_target ());
/* If that failed try a target-specific hook. */
if (current_target_desc == NULL)
- current_target_desc = target_read_description (¤t_target);
+ current_target_desc = target_read_description (current_top_target ());
/* If a non-NULL description was returned, then update the current
architecture. */
static void *
tdesc_data_init (struct obstack *obstack)
{
- struct tdesc_arch_data *data;
-
- data = OBSTACK_ZALLOC (obstack, struct tdesc_arch_data);
- new (data) tdesc_arch_data ();
-
- return data;
+ return obstack_new<tdesc_arch_data> (obstack);
}
/* Similar, but for the temporary copy used during architecture
bits. The register must exist. */
int
-tdesc_register_size (const struct tdesc_feature *feature,
- const char *name)
+tdesc_register_bitsize (const struct tdesc_feature *feature, const char *name)
{
struct tdesc_reg *reg = tdesc_find_register_early (feature, name);
{
struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
int num_regs = gdbarch_num_regs (gdbarch);
- int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
if (reg != NULL)
return reg->name.c_str ();
- if (regno >= num_regs && regno < num_regs + num_pseudo_regs)
+ if (regno >= num_regs && regno < gdbarch_num_cooked_regs (gdbarch))
{
struct tdesc_arch_data *data
= (struct tdesc_arch_data *) gdbarch_data (gdbarch, tdesc_data);
return new target_desc ();
}
-static void
-free_target_description (void *arg)
+void
+target_desc_deleter::operator() (struct target_desc *target_desc) const
{
- struct target_desc *target_desc = (struct target_desc *) arg;
-
delete target_desc;
}
-struct cleanup *
-make_cleanup_free_target_description (struct target_desc *target_desc)
-{
- return make_cleanup (free_target_description, target_desc);
-}
-
void
tdesc_add_compatible (struct target_desc *target_desc,
const struct bfd_arch_info *compatible)
if (startswith (filename_after_features.c_str (), "i386/32bit-")
|| startswith (filename_after_features.c_str (), "i386/64bit-")
|| startswith (filename_after_features.c_str (), "i386/x32-core.xml")
+ || startswith (filename_after_features.c_str (), "riscv/")
|| startswith (filename_after_features.c_str (), "tic6x-")
|| startswith (filename_after_features.c_str (), "aarch64"))
{
namespace selftests {
-static std::vector<std::pair<const char*, const target_desc *>> xml_tdesc;
+/* A reference target description, used for testing (see record_xml_tdesc). */
+
+struct xml_test_tdesc
+{
+ xml_test_tdesc (const char *name, std::unique_ptr<const target_desc> &&tdesc)
+ : name (name), tdesc (std::move (tdesc))
+ {}
+
+ const char *name;
+ std::unique_ptr<const target_desc> tdesc;
+};
+
+static std::vector<xml_test_tdesc> xml_tdesc;
#if GDB_SELF_TEST
void
record_xml_tdesc (const char *xml_file, const struct target_desc *tdesc)
{
- xml_tdesc.emplace_back (xml_file, tdesc);
+ xml_tdesc.emplace_back (xml_file, std::unique_ptr<const target_desc> (tdesc));
}
#endif
for (auto const &e : selftests::xml_tdesc)
{
- std::string tdesc_xml = (feature_dir + SLASH_STRING + e.first);
+ std::string tdesc_xml = (feature_dir + SLASH_STRING + e.name);
const target_desc *tdesc
= file_read_description_xml (tdesc_xml.data ());
- if (tdesc == NULL || *tdesc != *e.second)
+ if (tdesc == NULL || *tdesc != *e.tdesc)
{
- printf_filtered ( _("Descriptions for %s do not match.\n"), e.first);
+ printf_filtered ( _("Descriptions for %s do not match.\n"), e.name);
failed++;
}
- else if (!maintenance_check_tdesc_xml_convert (tdesc, e.first)
- || !maintenance_check_tdesc_xml_convert (e.second, e.first))
+ else if (!maintenance_check_tdesc_xml_convert (tdesc, e.name)
+ || !maintenance_check_tdesc_xml_convert (e.tdesc.get (), e.name))
failed++;
}
printf_filtered (_("Tested %lu XML files, %d failed\n"),