/* Target description support for GDB.
- Copyright (C) 2006-2021 Free Software Foundation, Inc.
+ Copyright (C) 2006-2022 Free Software Foundation, Inc.
Contributed by CodeSourcery.
#include "xml-tdesc.h"
#include "osabi.h"
-#include "gdb_obstack.h"
+#include "gdbsupport/gdb_obstack.h"
#include "hashtab.h"
#include "inferior.h"
#include <algorithm>
bitsize = f.end - f.start + 1;
total_size = e->size * TARGET_CHAR_BIT;
if (gdbarch_byte_order (m_gdbarch) == BFD_ENDIAN_BIG)
- SET_FIELD_BITPOS (fld[0], total_size - f.start - bitsize);
+ fld->set_loc_bitpos (total_size - f.start - bitsize);
else
- SET_FIELD_BITPOS (fld[0], f.start);
+ fld->set_loc_bitpos (f.start);
FIELD_BITSIZE (fld[0]) = bitsize;
}
else
xstrdup (f.name.c_str ()),
NULL);
- SET_FIELD_BITPOS (fld[0], f.start);
+ fld->set_loc_enumval (f.start);
}
}
/* A flag indicating that a description has already been fetched
from the target, so it should not be queried again. */
- int fetched;
+ bool fetched = false;
/* The description fetched from the target, or NULL if the target
did not supply any description. Only valid when
code should access this; normally, the description should be
accessed through the gdbarch object. */
- const struct target_desc *tdesc;
+ const struct target_desc *tdesc = nullptr;
+
+ /* If not empty, the filename to read a target description from, as set by
+ "set tdesc filename ...".
- /* The filename to read a target description from, as set by "set
- tdesc filename ..." */
+ If empty, there is not filename specified by the user. */
- char *filename;
+ std::string filename;
};
/* Get the inferior INF's target description info, allocating one on
get_tdesc_info (struct inferior *inf)
{
if (inf->tdesc_info == NULL)
- inf->tdesc_info = XCNEW (struct target_desc_info);
+ inf->tdesc_info = new target_desc_info;
+
return inf->tdesc_info;
}
int
target_desc_info_from_user_p (struct target_desc_info *info)
{
- return info != NULL && info->filename != NULL;
+ return info != nullptr && !info->filename.empty ();
}
/* See target-descriptions.h. */
struct target_desc_info *src = get_tdesc_info (srcinf);
struct target_desc_info *dest = get_tdesc_info (destinf);
- dest->fetched = src->fetched;
- dest->tdesc = src->tdesc;
- dest->filename = src->filename != NULL ? xstrdup (src->filename) : NULL;
+ *dest = *src;
}
/* See target-descriptions.h. */
void
target_desc_info_free (struct target_desc_info *tdesc_info)
{
- if (tdesc_info != NULL)
- {
- xfree (tdesc_info->filename);
- xfree (tdesc_info);
- }
+ delete tdesc_info;
}
/* The string manipulated by the "set tdesc filename ..." command. */
-static char *tdesc_filename_cmd_string;
+static std::string tdesc_filename_cmd_string;
/* Fetch the current target's description, and switch the current
architecture to one which incorporates that description. */
/* First try to fetch an XML description from the user-specified
file. */
tdesc_info->tdesc = nullptr;
- if (tdesc_info->filename != nullptr && *tdesc_info->filename != '\0')
- tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename);
+ if (!tdesc_info->filename.empty ())
+ tdesc_info->tdesc = file_read_description_xml (tdesc_info->filename.data ());
/* Next try to read the description from the current target using
target objects. */
{
struct gdbarch_info info;
- gdbarch_info_init (&info);
info.target_desc = tdesc_info->tdesc;
if (!gdbarch_update_p (info))
warning (_("Architecture rejected target-supplied description"));
/* Now that we know this description is usable, record that we
fetched it. */
- tdesc_info->fetched = 1;
+ tdesc_info->fetched = true;
}
/* Discard any description fetched from the current target, and switch
if (!tdesc_info->fetched)
return;
- tdesc_info->fetched = 0;
+ tdesc_info->fetched = false;
tdesc_info->tdesc = nullptr;
gdbarch_info info;
- gdbarch_info_init (&info);
if (!gdbarch_update_p (info))
internal_error (__FILE__, __LINE__,
_("Could not remove target-supplied description"));
int
tdesc_register_in_reggroup_p (struct gdbarch *gdbarch, int regno,
- struct reggroup *reggroup)
+ const struct reggroup *reggroup)
{
struct tdesc_reg *reg = tdesc_find_register (gdbarch, regno);
if (reg != NULL && !reg->group.empty ()
- && (reg->group == reggroup_name (reggroup)))
+ && (reg->group == reggroup->name ()))
return 1;
if (reg != NULL
static int
tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regno,
- struct reggroup *reggroup)
+ const struct reggroup *reggroup)
{
int num_regs = gdbarch_num_regs (gdbarch);
int num_pseudo_regs = gdbarch_num_pseudo_regs (gdbarch);
{
target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
- xfree (tdesc_info->filename);
- tdesc_info->filename = xstrdup (tdesc_filename_cmd_string);
+ tdesc_info->filename = tdesc_filename_cmd_string;
target_clear_description ();
target_find_description ();
struct cmd_list_element *c,
const char *value)
{
- value = get_tdesc_info (current_inferior ())->filename;
+ value = get_tdesc_info (current_inferior ())->filename.data ();
if (value != NULL && *value != '\0')
- printf_filtered (_("The target description will be read from \"%s\".\n"),
- value);
+ gdb_printf (file,
+ _("The target description will be read from \"%s\".\n"),
+ value);
else
- printf_filtered (_("The target description will be "
- "read from the target.\n"));
+ gdb_printf (file,
+ _("The target description will be "
+ "read from the target.\n"));
}
static void
{
target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
- xfree (tdesc_info->filename);
- tdesc_info->filename = nullptr;
+ tdesc_info->filename.clear ();
target_clear_description ();
target_find_description ();
}
*outp = '\0';
/* Standard boilerplate. */
- printf_unfiltered ("/* THIS FILE IS GENERATED. "
- "-*- buffer-read-only: t -*- vi"
- ":set ro:\n");
+ gdb_printf ("/* THIS FILE IS GENERATED. "
+ "-*- buffer-read-only: t -*- vi"
+ ":set ro:\n");
}
~print_c_tdesc ()
void visit_pre (const target_desc *e) override
{
- printf_unfiltered (" Original: %s */\n\n",
- lbasename (m_filename_after_features.c_str ()));
-
- printf_unfiltered ("#include \"defs.h\"\n");
- printf_unfiltered ("#include \"osabi.h\"\n");
- printf_unfiltered ("#include \"target-descriptions.h\"\n");
- printf_unfiltered ("\n");
-
- printf_unfiltered ("struct target_desc *tdesc_%s;\n", m_function);
- printf_unfiltered ("static void\n");
- printf_unfiltered ("initialize_tdesc_%s (void)\n", m_function);
- printf_unfiltered ("{\n");
- printf_unfiltered
+ gdb_printf (" Original: %s */\n\n",
+ lbasename (m_filename_after_features.c_str ()));
+
+ gdb_printf ("#include \"defs.h\"\n");
+ gdb_printf ("#include \"osabi.h\"\n");
+ gdb_printf ("#include \"target-descriptions.h\"\n");
+ gdb_printf ("\n");
+
+ gdb_printf ("struct target_desc *tdesc_%s;\n", m_function);
+ gdb_printf ("static void\n");
+ gdb_printf ("initialize_tdesc_%s (void)\n", m_function);
+ gdb_printf ("{\n");
+ gdb_printf
(" target_desc_up result = allocate_target_description ();\n");
if (tdesc_architecture (e) != NULL)
{
- printf_unfiltered
+ gdb_printf
(" set_tdesc_architecture (result.get (), bfd_scan_arch (\"%s\"));\n",
tdesc_architecture (e)->printable_name);
- printf_unfiltered ("\n");
+ gdb_printf ("\n");
}
if (tdesc_osabi (e) > GDB_OSABI_UNKNOWN
&& tdesc_osabi (e) < GDB_OSABI_INVALID)
{
- printf_unfiltered
+ gdb_printf
(" set_tdesc_osabi (result.get (), osabi_from_tdesc_string (\"%s\"));\n",
gdbarch_osabi_name (tdesc_osabi (e)));
- printf_unfiltered ("\n");
+ gdb_printf ("\n");
}
for (const tdesc_compatible_info_up &compatible : e->compatible)
- printf_unfiltered
+ gdb_printf
(" tdesc_add_compatible (result.get (), bfd_scan_arch (\"%s\"));\n",
compatible->arch ()->printable_name);
if (!e->compatible.empty ())
- printf_unfiltered ("\n");
+ gdb_printf ("\n");
for (const property &prop : e->properties)
- printf_unfiltered (" set_tdesc_property (result.get (), \"%s\", \"%s\");\n",
- prop.key.c_str (), prop.value.c_str ());
+ gdb_printf (" set_tdesc_property (result.get (), \"%s\", \"%s\");\n",
+ prop.key.c_str (), prop.value.c_str ());
- printf_unfiltered (" struct tdesc_feature *feature;\n");
+ gdb_printf (" struct tdesc_feature *feature;\n");
}
void visit_pre (const tdesc_feature *e) override
{
- printf_unfiltered ("\n feature = tdesc_create_feature (result.get (), \"%s\");\n",
- e->name.c_str ());
+ gdb_printf ("\n feature = tdesc_create_feature (result.get (), \"%s\");\n",
+ e->name.c_str ());
}
void visit_post (const tdesc_feature *e) override
void visit_post (const target_desc *e) override
{
- printf_unfiltered ("\n tdesc_%s = result.release ();\n", m_function);
- printf_unfiltered ("}\n");
+ gdb_printf ("\n tdesc_%s = result.release ();\n", m_function);
+ gdb_printf ("}\n");
}
void visit (const tdesc_type_builtin *type) override
{
if (!m_printed_element_type)
{
- printf_unfiltered (" tdesc_type *element_type;\n");
+ gdb_printf (" tdesc_type *element_type;\n");
m_printed_element_type = true;
}
- printf_unfiltered
+ gdb_printf
(" element_type = tdesc_named_type (feature, \"%s\");\n",
type->element_type->name.c_str ());
- printf_unfiltered
+ gdb_printf
(" tdesc_create_vector (feature, \"%s\", element_type, %d);\n",
type->name.c_str (), type->count);
- printf_unfiltered ("\n");
+ gdb_printf ("\n");
}
void visit (const tdesc_type_with_fields *type) override
{
if (!m_printed_type_with_fields)
{
- printf_unfiltered (" tdesc_type_with_fields *type_with_fields;\n");
+ gdb_printf (" tdesc_type_with_fields *type_with_fields;\n");
m_printed_type_with_fields = true;
}
case TDESC_TYPE_FLAGS:
if (type->kind == TDESC_TYPE_STRUCT)
{
- printf_unfiltered
+ gdb_printf
(" type_with_fields = tdesc_create_struct (feature, \"%s\");\n",
type->name.c_str ());
if (type->size != 0)
- printf_unfiltered
+ gdb_printf
(" tdesc_set_struct_size (type_with_fields, %d);\n", type->size);
}
else
{
- printf_unfiltered
+ gdb_printf
(" type_with_fields = tdesc_create_flags (feature, \"%s\", %d);\n",
type->name.c_str (), type->size);
}
if (f.type->kind == TDESC_TYPE_BOOL)
{
gdb_assert (f.start == f.end);
- printf_unfiltered
+ gdb_printf
(" tdesc_add_flag (type_with_fields, %d, \"%s\");\n",
f.start, f.name.c_str ());
}
|| (type->size == 8
&& f.type->kind == TDESC_TYPE_UINT64))
{
- printf_unfiltered
+ gdb_printf
(" tdesc_add_bitfield (type_with_fields, \"%s\", %d, %d);\n",
f.name.c_str (), f.start, f.end);
}
printf_field_type_assignment
("tdesc_named_type (feature, \"%s\");\n",
type_name);
- printf_unfiltered
+ gdb_printf
(" tdesc_add_typed_bitfield (type_with_fields, \"%s\","
" %d, %d, field_type);\n",
f.name.c_str (), f.start, f.end);
gdb_assert (type->kind == TDESC_TYPE_STRUCT);
printf_field_type_assignment
("tdesc_named_type (feature, \"%s\");\n", type_name);
- printf_unfiltered
+ gdb_printf
(" tdesc_add_field (type_with_fields, \"%s\", field_type);\n",
f.name.c_str ());
}
}
break;
case TDESC_TYPE_UNION:
- printf_unfiltered
+ gdb_printf
(" type_with_fields = tdesc_create_union (feature, \"%s\");\n",
type->name.c_str ());
for (const tdesc_type_field &f : type->fields)
{
printf_field_type_assignment
("tdesc_named_type (feature, \"%s\");\n", f.type->name.c_str ());
- printf_unfiltered
+ gdb_printf
(" tdesc_add_field (type_with_fields, \"%s\", field_type);\n",
f.name.c_str ());
}
break;
case TDESC_TYPE_ENUM:
- printf_unfiltered
+ gdb_printf
(" type_with_fields = tdesc_create_enum (feature, \"%s\", %d);\n",
type->name.c_str (), type->size);
for (const tdesc_type_field &f : type->fields)
- printf_unfiltered
+ gdb_printf
(" tdesc_add_enum_value (type_with_fields, %d, \"%s\");\n",
f.start, f.name.c_str ());
break;
error (_("C output is not supported type \"%s\"."), type->name.c_str ());
}
- printf_unfiltered ("\n");
+ gdb_printf ("\n");
}
void visit (const tdesc_reg *reg) override
{
- printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
- reg->name.c_str (), reg->target_regnum,
- reg->save_restore);
+ gdb_printf (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
+ reg->name.c_str (), reg->target_regnum,
+ reg->save_restore);
if (!reg->group.empty ())
- printf_unfiltered ("\"%s\", ", reg->group.c_str ());
+ gdb_printf ("\"%s\", ", reg->group.c_str ());
else
- printf_unfiltered ("NULL, ");
- printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type.c_str ());
+ gdb_printf ("NULL, ");
+ gdb_printf ("%d, \"%s\");\n", reg->bitsize, reg->type.c_str ());
}
protected:
{
if (!m_printed_field_type)
{
- printf_unfiltered (" tdesc_type *field_type;\n");
+ gdb_printf (" tdesc_type *field_type;\n");
m_printed_field_type = true;
}
- printf_unfiltered (" field_type = ");
+ gdb_printf (" field_type = ");
va_list args;
va_start (args, fmt);
- vprintf_unfiltered (fmt, args);
+ gdb_vprintf (fmt, args);
va_end (args);
}
void visit_pre (const target_desc *e) override
{
- printf_unfiltered (" Original: %s */\n\n",
- lbasename (m_filename_after_features.c_str ()));
+ gdb_printf (" Original: %s */\n\n",
+ lbasename (m_filename_after_features.c_str ()));
- printf_unfiltered ("#include \"gdbsupport/tdesc.h\"\n");
- printf_unfiltered ("\n");
+ gdb_printf ("#include \"gdbsupport/tdesc.h\"\n");
+ gdb_printf ("\n");
}
void visit_post (const target_desc *e) override
std::replace (name.begin (), name.end (), '/', '_');
std::replace (name.begin (), name.end (), '-', '_');
- printf_unfiltered ("static int\n");
- printf_unfiltered ("create_feature_%s ", name.c_str ());
- printf_unfiltered ("(struct target_desc *result, long regnum)\n");
+ gdb_printf ("static int\n");
+ gdb_printf ("create_feature_%s ", name.c_str ());
+ gdb_printf ("(struct target_desc *result, long regnum)\n");
- printf_unfiltered ("{\n");
- printf_unfiltered (" struct tdesc_feature *feature;\n");
+ gdb_printf ("{\n");
+ gdb_printf (" struct tdesc_feature *feature;\n");
- printf_unfiltered
+ gdb_printf
("\n feature = tdesc_create_feature (result, \"%s\");\n",
e->name.c_str ());
}
void visit_post (const tdesc_feature *e) override
{
- printf_unfiltered (" return regnum;\n");
- printf_unfiltered ("}\n");
+ gdb_printf (" return regnum;\n");
+ gdb_printf ("}\n");
}
void visit (const tdesc_reg *reg) override
and also print the message so that it can be saved in the
generated c file. */
- printf_unfiltered ("ERROR: \"regnum\" attribute %ld ",
- reg->target_regnum);
- printf_unfiltered ("is not the largest number (%d).\n",
- m_next_regnum);
+ gdb_printf ("ERROR: \"regnum\" attribute %ld ",
+ reg->target_regnum);
+ gdb_printf ("is not the largest number (%d).\n",
+ m_next_regnum);
error (_("\"regnum\" attribute %ld is not the largest number (%d)."),
reg->target_regnum, m_next_regnum);
}
if (reg->target_regnum > m_next_regnum)
{
- printf_unfiltered (" regnum = %ld;\n", reg->target_regnum);
+ gdb_printf (" regnum = %ld;\n", reg->target_regnum);
m_next_regnum = reg->target_regnum;
}
- printf_unfiltered (" tdesc_create_reg (feature, \"%s\", regnum++, %d, ",
- reg->name.c_str (), reg->save_restore);
+ gdb_printf (" tdesc_create_reg (feature, \"%s\", regnum++, %d, ",
+ reg->name.c_str (), reg->save_restore);
if (!reg->group.empty ())
- printf_unfiltered ("\"%s\", ", reg->group.c_str ());
+ gdb_printf ("\"%s\", ", reg->group.c_str ());
else
- printf_unfiltered ("NULL, ");
- printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type.c_str ());
+ gdb_printf ("NULL, ");
+ gdb_printf ("%d, \"%s\");\n", reg->bitsize, reg->type.c_str ());
m_next_regnum++;
}
initialization code will reject the new description. */
target_desc_info *tdesc_info = get_tdesc_info (current_inferior ());
tdesc = tdesc_info->tdesc;
- filename = tdesc_info->filename;
+ filename = tdesc_info->filename.data ();
}
else
{
std::string buf;
print_xml_feature v (&buf);
tdesc->accept (v);
- puts_unfiltered (buf.c_str ());
+ gdb_puts (buf.c_str ());
}
namespace selftests {
if (xml == nullptr || *xml != '@')
{
- printf_filtered (_("Could not convert description for %s to xml.\n"),
- name);
+ gdb_printf (_("Could not convert description for %s to xml.\n"),
+ name);
return false;
}
if (tdesc_trans == nullptr)
{
- printf_filtered (_("Could not convert description for %s from xml.\n"),
- name);
+ gdb_printf (_("Could not convert description for %s from xml.\n"),
+ name);
return false;
}
else if (*tdesc != *tdesc_trans)
{
- printf_filtered (_("Converted description for %s does not match.\n"),
- name);
+ gdb_printf (_("Converted description for %s does not match.\n"),
+ name);
return false;
}
return true;
if (tdesc == NULL || *tdesc != *e.tdesc)
{
- printf_filtered ( _("Descriptions for %s do not match.\n"), e.name);
+ gdb_printf ( _("Descriptions for %s do not match.\n"), e.name);
failed++;
}
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"),
- (long) selftests::xml_tdesc.size (), failed);
+ gdb_printf (_("Tested %lu XML files, %d failed\n"),
+ (long) selftests::xml_tdesc.size (), failed);
}
void _initialize_target_descriptions ();
tdesc_data = gdbarch_data_register_pre_init (tdesc_data_init);
- add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
-Set target description specific variables."),
- &tdesc_set_cmdlist, "set tdesc ",
- 0 /* allow-unknown */, &setlist);
- add_show_prefix_cmd ("tdesc", class_maintenance, _("\
-Show target description specific variables."),
- &tdesc_show_cmdlist, "show tdesc ",
- 0 /* allow-unknown */, &showlist);
+ add_setshow_prefix_cmd ("tdesc", class_maintenance,
+ _("Set target description specific variables."),
+ _("Show target description specific variables."),
+ &tdesc_set_cmdlist, &tdesc_show_cmdlist,
+ &setlist, &showlist);
+
add_basic_prefix_cmd ("tdesc", class_maintenance, _("\
Unset target description specific variables."),
- &tdesc_unset_cmdlist, "unset tdesc ",
+ &tdesc_unset_cmdlist,
0 /* allow-unknown */, &unsetlist);
add_setshow_filename_cmd ("filename", class_obscure,