]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
gdb: Print compatible information within print_xml_feature
authorAndrew Burgess <andrew.burgess@embecosm.com>
Thu, 11 Jun 2020 21:36:29 +0000 (22:36 +0100)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 23 Jun 2020 21:17:19 +0000 (22:17 +0100)
The gdbsupport directory contains a helper class print_xml_feature
that is shared between gdb and gdbserver.  This class is used for
printing an XML representation of a target_desc object.

Currently this class doesn't have the ability to print the
<compatible> entities that can appear within a target description, I
guess no targets have needed that functionality yet.

The print_xml_feature classes API is based around operating on the
target_desc class, however, the sharing between gdb and gdbserver is
purely textural, we rely on their being a class called target_desc in
both gdb and gdbserver, but there is no shared implementation.  We
then have a set of functions declared that operate on an object of
type target_desc, and again these functions have completely separate
implementations.

Currently then the gdb version of target_desc contains a vector of
bfd_arch_info pointers which represents the compatible entries from a
target description.  The gdbserver version of target_desc has no such
information.  Further, the gdbserver code doesn't seem to include the
bfd headers, and so doesn't know about the bfd types.

I was reluctant to include the bfd headers into gdbserver just so I
can reference the compatible information, which isn't (currently) even
needed in gdbserver.

So, the approach I take in this patch is to wrap the compatible
information into a new helper class.  This class is declared in the
gdbsupport library, but implemented separately in both gdb and
gdbserver.

In gdbserver the class is empty.  The compatible information within
the gdbserver is an empty list, of empty classes.

In gdb the class contains a pointer to the bfd_arch_info object.

With this in place we can now add support to print_xml_feature for
printing the compatible information if it is present.  In the
gdbserver code this will never happen, as the gdbserver never has any
compatible information.  But in gdb, this code will trigger when
appropriate.

gdb/ChangeLog:

* target-descriptions.c (class tdesc_compatible_info): New class.
(struct target_desc): Change type of compatible vector.
(tdesc_compatible_p): Update for change in type of
target_desc::compatible.
(tdesc_compatible_info_list): New function.
(tdesc_compatible_info_arch_name): New function.
(tdesc_add_compatible): Update for change in type of
target_desc::compatible.
(print_c_tdesc::visit_pre): Likewise.

gdbserver/ChangeLog:

* tdesc.cc (struct tdesc_compatible_info): New struct.
(tdesc_compatible_info_list): New function.
(tdesc_compatible_info_arch_name): New function.

gdbsupport/ChangeLog:

* tdesc.cc (print_xml_feature::visit_pre): Print compatible
information.
* tdesc.h (struct tdesc_compatible_info): Declare new struct.
(tdesc_compatible_info_up): New typedef.
(tdesc_compatible_info_list): Declare new function.
(tdesc_compatible_info_arch_name): Declare new function.

gdb/ChangeLog
gdb/target-descriptions.c
gdbserver/ChangeLog
gdbserver/tdesc.cc
gdbsupport/ChangeLog
gdbsupport/tdesc.cc
gdbsupport/tdesc.h

index 3e914eb0d92180197c7524033d2223a3d98dde82..0784e823e211b76a2f15cad94692cf01cfc2d4db 100644 (file)
@@ -1,3 +1,15 @@
+2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * target-descriptions.c (class tdesc_compatible_info): New class.
+       (struct target_desc): Change type of compatible vector.
+       (tdesc_compatible_p): Update for change in type of
+       target_desc::compatible.
+       (tdesc_compatible_info_list): New function.
+       (tdesc_compatible_info_arch_name): New function.
+       (tdesc_add_compatible): Update for change in type of
+       target_desc::compatible.
+       (print_c_tdesc::visit_pre): Likewise.
+
 2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
 
        * target-descriptions.c (print_c_tdesc::print_c_tdesc): Change
index da6cb76404c50963a112d84ce74e8b32f88b7dc6..1937e7ca4a7cb809059e52e29f0ebf1cc4eb59fb 100644 (file)
@@ -308,6 +308,29 @@ make_gdb_type (struct gdbarch *gdbarch, struct tdesc_type *ttype)
   return gdb_type.get_type ();
 }
 
+/* Wrapper around bfd_arch_info_type.  A class with this name is used in
+   the API that is shared between gdb and gdbserver code, but gdbserver
+   doesn't use compatibility information, so its version of this class is
+   empty.  */
+
+class tdesc_compatible_info
+{
+public:
+  /* Constructor.  */
+  explicit tdesc_compatible_info (const bfd_arch_info_type *arch)
+    : m_arch (arch)
+  { /* Nothing.  */ }
+
+  /* Access the contained pointer.  */
+  const bfd_arch_info_type *arch () const
+  { return m_arch; }
+
+private:
+  /* Architecture information looked up from the <compatible> entity within
+     a target description.  */
+  const bfd_arch_info_type *m_arch;
+};
+
 /* A target description.  */
 
 struct target_desc : tdesc_element
@@ -328,7 +351,7 @@ struct target_desc : tdesc_element
   enum gdb_osabi osabi = GDB_OSABI_UNKNOWN;
 
   /* The list of compatible architectures reported by the target.  */
-  std::vector<const bfd_arch_info *> compatible;
+  std::vector<tdesc_compatible_info_up> compatible;
 
   /* Any architecture-specific properties specified by the target.  */
   std::vector<property> properties;
@@ -598,11 +621,11 @@ int
 tdesc_compatible_p (const struct target_desc *target_desc,
                    const struct bfd_arch_info *arch)
 {
-  for (const bfd_arch_info *compat : target_desc->compatible)
+  for (const tdesc_compatible_info_up &compat : target_desc->compatible)
     {
-      if (compat == arch
-         || arch->compatible (arch, compat)
-         || compat->compatible (compat, arch))
+      if (compat->arch () == arch
+         || arch->compatible (arch, compat->arch ())
+         || compat->arch ()->compatible (compat->arch (), arch))
        return 1;
     }
 
@@ -642,6 +665,22 @@ tdesc_architecture_name (const struct target_desc *target_desc)
   return target_desc->arch->printable_name;
 }
 
+/* See gdbsupport/tdesc.h.  */
+
+const std::vector<tdesc_compatible_info_up> &
+tdesc_compatible_info_list (const target_desc *target_desc)
+{
+  return target_desc->compatible;
+}
+
+/* See gdbsupport/tdesc.h.  */
+
+const char *
+tdesc_compatible_info_arch_name (const tdesc_compatible_info_up &compatible)
+{
+  return compatible->arch ()->printable_name;
+}
+
 /* Return the OSABI associated with this target description, or
    GDB_OSABI_UNKNOWN if no osabi was specified.  */
 
@@ -1158,14 +1197,16 @@ tdesc_add_compatible (struct target_desc *target_desc,
   if (compatible == NULL)
     return;
 
-  for (const bfd_arch_info *compat : target_desc->compatible)
-    if (compat == compatible)
+  for (const tdesc_compatible_info_up &compat : target_desc->compatible)
+    if (compat->arch () == compatible)
       internal_error (__FILE__, __LINE__,
                      _("Attempted to add duplicate "
                        "compatible architecture \"%s\""),
                      compatible->printable_name);
 
-  target_desc->compatible.push_back (compatible);
+  target_desc->compatible.push_back
+    (std::unique_ptr<tdesc_compatible_info>
+     (new tdesc_compatible_info (compatible)));
 }
 
 void
@@ -1320,10 +1361,10 @@ public:
        printf_unfiltered ("\n");
       }
 
-    for (const bfd_arch_info_type *compatible : e->compatible)
+    for (const tdesc_compatible_info_up &compatible : e->compatible)
       printf_unfiltered
        ("  tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
-        compatible->printable_name);
+        compatible->arch ()->printable_name);
 
     if (!e->compatible.empty ())
       printf_unfiltered ("\n");
index c5c3b09841e0c159cb01c46740aa1172cfd32661..43b8bc895dbd2cc12ff528fcdb3ea8d499d4c328 100644 (file)
@@ -1,3 +1,9 @@
+2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * tdesc.cc (struct tdesc_compatible_info): New struct.
+       (tdesc_compatible_info_list): New function.
+       (tdesc_compatible_info_arch_name): New function.
+
 2020-06-22  Tankut Baris Aktemur  <tankut.baris.aktemur@intel.com>
 
        Use std::list to stop pending signal instead of manually-created
index 8d97defb9b5968c34968c47c178c739d2e7b5869..d21688b932b875a4beda8ea0d6d6aca68f9af2cf 100644 (file)
@@ -122,6 +122,27 @@ current_target_desc (void)
   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 *
index 7c2c4bff4750d1428d28793cad0a708573d61a3d..2e5cbba01c6b3ed3922ea1c03dac25bc8a42d540 100644 (file)
@@ -1,3 +1,12 @@
+2020-06-23  Andrew Burgess  <andrew.burgess@embecosm.com>
+
+       * tdesc.cc (print_xml_feature::visit_pre): Print compatible
+       information.
+       * tdesc.h (struct tdesc_compatible_info): Declare new struct.
+       (tdesc_compatible_info_up): New typedef.
+       (tdesc_compatible_info_list): Declare new function.
+       (tdesc_compatible_info_arch_name): Declare new function.
+
 2020-05-25  Michael Weghorn  <m.weghorn@posteo.de>
 
        * common-utils.cc, common-utils.h (stringify_argv): Drop
index aaea8e0d8a8f9357c8e941a07917f77ebe308c31..63f41cbf677f201dfd127f8ef3d0c70a90730be2 100644 (file)
@@ -392,6 +392,12 @@ void print_xml_feature::visit_pre (const target_desc *e)
   const char *osabi = tdesc_osabi_name (e);
   if (osabi != nullptr)
     string_appendf (*m_buffer, "<osabi>%s</osabi>", osabi);
+
+  const std::vector<tdesc_compatible_info_up> &compatible_list
+    = tdesc_compatible_info_list (e);
+  for (const auto &c : compatible_list)
+    string_appendf (*m_buffer, "<compatible>%s</compatible>\n",
+                   tdesc_compatible_info_arch_name (c));
 #endif
 }
 
index 3b1f1f57ff8d3aca707f0d0b2e2b67367b7d97eb..0cdcf56346c596fa1491cc1b6d5015b6269cc63a 100644 (file)
@@ -131,6 +131,27 @@ struct tdesc_reg : tdesc_element
 
 typedef std::unique_ptr<tdesc_reg> tdesc_reg_up;
 
+/* Declaration of a structure that holds information about one
+   "compatibility" entry within a target description.  */
+
+struct tdesc_compatible_info;
+
+/* A pointer to a single piece of compatibility information.  */
+
+typedef std::unique_ptr<tdesc_compatible_info> tdesc_compatible_info_up;
+
+/* Return a vector of compatibility information pointers from the target
+   description TARGET_DESC.  */
+
+const std::vector<tdesc_compatible_info_up> &tdesc_compatible_info_list
+       (const target_desc *target_desc);
+
+/* Return the architecture name from a compatibility information
+   COMPATIBLE.  */
+
+const char *tdesc_compatible_info_arch_name
+       (const tdesc_compatible_info_up &compatible);
+
 enum tdesc_type_kind
 {
   /* Predefined types.  */