Update release making notes.
[deliverable/binutils-gdb.git] / gdb / gdbserver / tdesc.c
index 4504c9bbc03ada2de3c6ad6f1706c9685d6deb44..de25e7cfb466cf00432e3c030c23649aa42dfd54 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2017 Free Software Foundation, Inc.
+/* Copyright (C) 2012-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 #include "tdesc.h"
 #include "regdef.h"
 
-void
-init_target_desc (struct target_desc *tdesc)
+#ifndef IN_PROCESS_AGENT
+
+target_desc::~target_desc ()
 {
-  int offset, i;
-  struct reg *reg;
+  xfree ((char *) arch);
+  xfree ((char *) osabi);
+}
 
-  offset = 0;
-  for (i = 0; VEC_iterate (tdesc_reg_p, tdesc->reg_defs, i, reg); i++)
+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++)
     {
-      reg->offset = offset;
-      offset += reg->size;
+      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, 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
+}
+
+struct target_desc *
+allocate_target_description (void)
+{
+  return new target_desc ();
 }
 
 #ifndef IN_PROCESS_AGENT
@@ -61,111 +121,84 @@ current_target_desc (void)
 
   return current_process ()->tdesc;
 }
-#endif
-
-struct tdesc_type
-{};
-
-/* See arch/tdesc.h.  */
-
-struct tdesc_feature *
-tdesc_create_feature (struct target_desc *tdesc, const char *name)
-{
-  return tdesc;
-}
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-struct tdesc_type *
-tdesc_create_flags (struct tdesc_feature *feature, const char *name,
-                   int size)
+const char *
+tdesc_architecture_name (const struct target_desc *target_desc)
 {
-  return NULL;
+  return target_desc->arch;
 }
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
 void
-tdesc_add_flag (struct tdesc_type *type, int start,
-               const char *flag_name)
-{}
-
-/* See arch/tdesc.h.  */
-
-struct tdesc_type *
-tdesc_named_type (const struct tdesc_feature *feature, const char *id)
+set_tdesc_architecture (struct target_desc *target_desc,
+                       const char *name)
 {
-  return NULL;
+  target_desc->arch = xstrdup (name);
 }
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-struct tdesc_type *
-tdesc_create_union (struct tdesc_feature *feature, const char *id)
+const char *
+tdesc_osabi_name (const struct target_desc *target_desc)
 {
-  return NULL;
+  return target_desc->osabi;
 }
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-struct tdesc_type *
-tdesc_create_struct (struct tdesc_feature *feature, const char *id)
+void
+set_tdesc_osabi (struct target_desc *target_desc, const char *name)
 {
-  return NULL;
+  target_desc->osabi = xstrdup (name);
 }
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-void
-tdesc_create_reg (struct tdesc_feature *feature, const char *name,
-                 int regnum, int save_restore, const char *group,
-                 int bitsize, const char *type)
+const char *
+tdesc_get_features_xml (const target_desc *tdesc)
 {
-  struct target_desc *tdesc = (struct target_desc *) feature;
+  /* Either .xmltarget or .features is not NULL.  */
+  gdb_assert (tdesc->xmltarget != NULL
+             || (!tdesc->features.empty ()
+                 && tdesc->arch != NULL));
 
-  while (VEC_length (tdesc_reg_p, tdesc->reg_defs) < regnum)
+  if (tdesc->xmltarget == NULL)
     {
-      struct reg *reg = XCNEW (struct reg);
-
-      reg->name = "";
-      reg->size = 0;
-      VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+      std::string buffer ("@");
+      print_xml_feature v (&buffer);
+      tdesc->accept (v);
+      tdesc->xmltarget = xstrdup (buffer.c_str ());
     }
 
-  gdb_assert (regnum == 0
-             || regnum == VEC_length (tdesc_reg_p, tdesc->reg_defs));
-
-  struct reg *reg = XCNEW (struct reg);
-
-  reg->name = name;
-  reg->size = bitsize;
-  VEC_safe_push (tdesc_reg_p, tdesc->reg_defs, reg);
+  return tdesc->xmltarget;
 }
+#endif
 
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-struct tdesc_type *
-tdesc_create_vector (struct tdesc_feature *feature, const char *name,
-                    struct tdesc_type *field_type, int count)
+struct tdesc_feature *
+tdesc_create_feature (struct target_desc *tdesc, const char *name)
 {
-  return NULL;
+  struct tdesc_feature *new_feature = new tdesc_feature (name);
+  tdesc->features.emplace_back (new_feature);
+  return new_feature;
 }
 
-void
-tdesc_add_bitfield (struct tdesc_type *type, const char *field_name,
-                   int start, int end)
-{}
-
-/* See arch/tdesc.h.  */
+/* See gdbsupport/tdesc.h.  */
 
-void
-tdesc_add_field (struct tdesc_type *type, const char *field_name,
-                struct tdesc_type *field_type)
-{}
+bool
+tdesc_contains_feature (const target_desc *tdesc, const std::string &feature)
+{
+  gdb_assert (tdesc != nullptr);
 
-/* See arch/tdesc.h.  */
+  for (const tdesc_feature_up &f : tdesc->features)
+    {
+      if (f->name == feature)
+       return true;
+    }
 
-void
-tdesc_set_struct_size (struct tdesc_type *type, int size)
-{
+  return false;
 }
This page took 0.046236 seconds and 4 git commands to generate.