Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure
@ 2008-09-07 21:15 Ulrich Weigand
  2008-09-08  3:09 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2008-09-07 21:15 UTC (permalink / raw)
  To: gdb-patches

Hello,

this patch extends the target description infrastructure to allow a target
to define "compatible" architectures.  This is used to specify e.g. on Cell
that even though the target is PowerPC, it is compatible with executables
of the SPU architecture -- in an inferior process of PowerPC architecture,
objfiles of SPU architecture may be present as shared libraries or even
the main executable.

This is primarily required to prevent choose_architecture_for_target from 
rejecting a target description of architecture PowerPC just because a main
executable of architecture SPU was just started.

It is also a convenient means to inquire whether the current target is
a Cell system (as opposed to a regular PowerPC).

Bye,
Ulrich


ChangeLog:

	* target-descriptions.h (tdesc_compatible_p): New.
	(tdesc_add_compatible): New.
	* target-descriptions.c (arch_p): New VEC_P type.
	(struct target_desc): New member compatible.
	(free_target_description): Handle it.
	(maint_print_c_tdesc_cmd): Likewise.
	(tdesc_compatible_p): New function.
	(tdesc_add_compatible): New function.

	* xml-tdesc.c (tdesc_end_compatible): New function.
	(target_children): Handle <compatible> element.

	* arch-utils.c (choose_architecture_for_target): Accept target
	description instead of BFD architecture as input.  Query target
	description for compatible architectures.
	(gdbarch_info_fill): Update call.

doc/ChangeLog:

	* gdb.texinfo (Target Descriptions): Document <compatible> element.


Index: src/gdb/arch-utils.c
===================================================================
--- src.orig/gdb/arch-utils.c
+++ src/gdb/arch-utils.c
@@ -326,15 +326,24 @@ set_endian (char *ignore_args, int from_
 }
 
 /* Given SELECTED, a currently selected BFD architecture, and
-   FROM_TARGET, a BFD architecture reported by the target description,
-   return what architecture to use.  Either may be NULL; if both are
-   specified, we use the more specific.  If the two are obviously
-   incompatible, warn the user.  */
+   TARGET_DESC, the current target description, return what
+   architecture to use.
+
+   SELECTED may be NULL, in which case we return the architecture
+   associated with TARGET_DESC.  If SELECTED specifies a variant
+   of the architecture associtated with TARGET_DESC, return the
+   more specific of the two.
+
+   If SELECTED is a different architecture, but it is accepted as
+   compatible by the target, we can use the target architecture.
+
+   If SELECTED is obviously incompatible, warn the user.  */
 
 static const struct bfd_arch_info *
-choose_architecture_for_target (const struct bfd_arch_info *selected,
-				const struct bfd_arch_info *from_target)
+choose_architecture_for_target (const struct target_desc *target_desc,
+				const struct bfd_arch_info *selected)
 {
+  const struct bfd_arch_info *from_target = tdesc_architecture (target_desc);
   const struct bfd_arch_info *compat1, *compat2;
 
   if (selected == NULL)
@@ -364,6 +373,11 @@ choose_architecture_for_target (const st
 
   if (compat1 == NULL && compat2 == NULL)
     {
+      /* BFD considers the architectures incompatible.  Check our target
+	 description whether it accepts SELECTED as compatible anyway.  */
+      if (tdesc_compatible_p (target_desc, selected))
+	return from_target;
+
       warning (_("Selected architecture %s is not compatible "
 		 "with reported target architecture %s"),
 	       selected->printable_name, from_target->printable_name);
@@ -692,7 +706,7 @@ gdbarch_info_fill (struct gdbarch_info *
   /* From the target.  */
   if (info->target_desc != NULL)
     info->bfd_arch_info = choose_architecture_for_target
-      (info->bfd_arch_info, tdesc_architecture (info->target_desc));
+			   (info->target_desc, info->bfd_arch_info);
   /* From the default.  */
   if (info->bfd_arch_info == NULL)
     info->bfd_arch_info = default_bfd_arch;
Index: src/gdb/target-descriptions.c
===================================================================
--- src.orig/gdb/target-descriptions.c
+++ src/gdb/target-descriptions.c
@@ -104,6 +104,10 @@ typedef struct tdesc_feature
 } *tdesc_feature_p;
 DEF_VEC_P(tdesc_feature_p);
 
+/* A compatible architecture from a target description.  */
+typedef const struct bfd_arch_info *arch_p;
+DEF_VEC_P(arch_p);
+
 /* A target description.  */
 
 struct target_desc
@@ -111,6 +115,9 @@ struct target_desc
   /* The architecture reported by the target, if any.  */
   const struct bfd_arch_info *arch;
 
+  /* The list of compatible architectures reported by the target.  */
+  VEC(arch_p) *compatible;
+
   /* Any architecture-specific properties specified by the target.  */
   VEC(property_s) *properties;
 
@@ -290,6 +297,28 @@ tdesc_architecture (const struct target_
 {
   return target_desc->arch;
 }
+
+/* Return non-zero if this target description is compatible
+   with the given BFD architecture.  */
+
+int
+tdesc_compatible_p (const struct target_desc *target_desc,
+		    const struct bfd_arch_info *arch)
+{
+  const struct bfd_arch_info *compat;
+  int ix;
+
+  for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
+       ix++)
+    {
+      if (compat == arch
+	  || arch->compatible (arch, compat)
+	  || compat->compatible (compat, arch))
+	return 1;
+    }
+
+  return 0;
+}
 \f
 
 /* Return 1 if this target description includes any registers.  */
@@ -885,6 +914,8 @@ free_target_description (void *arg)
     }
   VEC_free (property_s, target_desc->properties);
 
+  VEC_free (arch_p, target_desc->compatible);
+
   xfree (target_desc);
 }
 
@@ -895,6 +926,30 @@ make_cleanup_free_target_description (st
 }
 
 void
+tdesc_add_compatible (struct target_desc *target_desc,
+		      const struct bfd_arch_info *compatible)
+{
+  const struct bfd_arch_info *compat;
+  int ix;
+
+  /* If this instance of GDB is compiled without BFD support for the
+     compatible architecture, simply ignore it -- we would not be able
+     to handle it anyway.  */
+  if (compatible == NULL)
+    return;
+
+  for (ix = 0; VEC_iterate (arch_p, target_desc->compatible, ix, compat);
+       ix++)
+    if (compat == compatible)
+      internal_error (__FILE__, __LINE__,
+		      _("Attempted to add duplicate "
+			"compatible architecture \"%s\""),
+		      compatible->printable_name);
+
+  VEC_safe_push (arch_p, target_desc->compatible, compatible);
+}
+
+void
 set_tdesc_property (struct target_desc *target_desc,
 		    const char *key, const char *value)
 {
@@ -993,6 +1048,7 @@ static void
 maint_print_c_tdesc_cmd (char *args, int from_tty)
 {
   const struct target_desc *tdesc;
+  const struct bfd_arch_info *compatible;
   const char *filename, *inp;
   char *function, *outp;
   struct property *prop;
@@ -1049,6 +1105,16 @@ maint_print_c_tdesc_cmd (char *args, int
       printf_unfiltered ("\n");
     }
 
+  for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
+       ix++)
+    {
+      printf_unfiltered
+	("  tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
+	 compatible->printable_name);
+    }
+  if (ix)
+    printf_unfiltered ("\n");
+
   for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
        ix++)
     {
Index: src/gdb/target-descriptions.h
===================================================================
--- src.orig/gdb/target-descriptions.h
+++ src/gdb/target-descriptions.h
@@ -123,6 +123,12 @@ int tdesc_numbered_register_choices (con
 const struct bfd_arch_info *tdesc_architecture
   (const struct target_desc *);
 
+/* Return non-zero if this target description is compatible
+   with the given BFD architecture.  */
+
+int tdesc_compatible_p (const struct target_desc *,
+			const struct bfd_arch_info *);
+
 /* Return the string value of a property named KEY, or NULL if the
    property was not specified.  */
 
@@ -169,6 +175,8 @@ void set_tdesc_architecture (struct targ
 			     const struct bfd_arch_info *);
 void set_tdesc_property (struct target_desc *,
 			 const char *key, const char *value);
+void tdesc_add_compatible (struct target_desc *,
+			   const struct bfd_arch_info *);
 
 struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
 					    const char *name);
Index: src/gdb/xml-tdesc.c
===================================================================
--- src.orig/gdb/xml-tdesc.c
+++ src/gdb/xml-tdesc.c
@@ -106,6 +106,20 @@ tdesc_end_arch (struct gdb_xml_parser *p
   set_tdesc_architecture (data->tdesc, arch);
 }
 
+/* Handle the end of a <compatible> element and its value.  */
+
+static void
+tdesc_end_compatible (struct gdb_xml_parser *parser,
+		      const struct gdb_xml_element *element,
+		      void *user_data, const char *body_text)
+{
+  struct tdesc_parsing_data *data = user_data;
+  const struct bfd_arch_info *arch;
+
+  arch = bfd_scan_arch (body_text);
+  tdesc_add_compatible (data->tdesc, arch);
+}
+
 /* Handle the start of a <target> element.  */
 
 static void
@@ -345,6 +359,8 @@ static const struct gdb_xml_attribute ta
 static const struct gdb_xml_element target_children[] = {
   { "architecture", NULL, NULL, GDB_XML_EF_OPTIONAL,
     NULL, tdesc_end_arch },
+  { "compatible", NULL, NULL, GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
+    NULL, tdesc_end_compatible },
   { "feature", feature_attributes, feature_children,
     GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
     tdesc_start_feature, NULL },
Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo
+++ src/gdb/doc/gdb.texinfo
@@ -27586,6 +27586,7 @@ are explained further below.
 <!DOCTYPE target SYSTEM "gdb-target.dtd">
 <target version="1.0">
   @r{[}@var{architecture}@r{]}
+  @r{[}@var{compatible}@dots{}@r{]}
   @r{[}@var{feature}@dots{}@r{]}
 </target>
 @end smallexample
@@ -27641,6 +27642,26 @@ An @samp{<architecture>} element has thi
 accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
 Debugging Target}).
 
+@subsection Compatible Architecture
+@cindex <compatible>
+
+A @samp{<compatible>} element has this form:
+
+@smallexample
+  <compatible>@var{arch}</compatible>
+@end smallexample
+
+@var{arch} is an architecture name from the same selection
+accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
+Debugging Target}).
+
+A @samp{<compatible>} element is used to specify that the target
+is able to run binaries in some other than the main target architecture
+given by the @samp{<architecture>} element.  For example, on the
+Cell Broadband Engine, the main architecture is @code{powerpc:common}
+or @code{powerpc:common64}, but the system is able to run binaries
+in the @code{spu} architecture as well.
+
 @subsection Features
 @cindex <feature>
 
-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure
  2008-09-07 21:15 [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure Ulrich Weigand
@ 2008-09-08  3:09 ` Eli Zaretskii
  2008-09-08 11:45   ` Ulrich Weigand
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2008-09-08  3:09 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

> Date: Sun, 7 Sep 2008 23:15:01 +0200 (CEST)
> From: "Ulrich Weigand" <uweigand@de.ibm.com>
> 
> doc/ChangeLog:
> 
> 	* gdb.texinfo (Target Descriptions): Document <compatible> element.

This part is okay, with the following comments:

> +@var{arch} is an architecture name from the same selection
> +accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
> +Debugging Target}).

I don't understand the purpose of "the same" here.  Same as what?

>                                                   For example, on the
> +Cell Broadband Engine, the main architecture is @code{powerpc:common}
> +or @code{powerpc:common64}, but the system is able to run binaries
> +in the @code{spu} architecture as well.

This begs a continuation:

  The way to describe this capability with @samp{<compatible>} is as
  follows:

  @smallexample
  ...
  @end smallexample

Thanks.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure
  2008-09-08  3:09 ` Eli Zaretskii
@ 2008-09-08 11:45   ` Ulrich Weigand
  2008-09-08 19:25     ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: Ulrich Weigand @ 2008-09-08 11:45 UTC (permalink / raw)
  To: eliz; +Cc: gdb-patches

Eli Zaretskii wrote:

> > +@var{arch} is an architecture name from the same selection
> > +accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
> > +Debugging Target}).
> 
> I don't understand the purpose of "the same" here.  Same as what?

This element accepts the same set of architecture names as the set 
accepted by the "set architecture" command.

The wording I've used is copied above is copied from the description
of the <architecture> element (which also accepts the same set of
architecture names).  If you can suggest a clearer way to express
this, I think both places should be fixed ...

> This begs a continuation:
> 
>   The way to describe this capability with @samp{<compatible>} is as
>   follows:
> 
>   @smallexample
>   ...
>   @end smallexample

Added.  See below for an updated patch.

Thanks,
Ulrich


Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo
+++ src/gdb/doc/gdb.texinfo
@@ -27586,6 +27586,7 @@ are explained further below.
 <!DOCTYPE target SYSTEM "gdb-target.dtd">
 <target version="1.0">
   @r{[}@var{architecture}@r{]}
+  @r{[}@var{compatible}@dots{}@r{]}
   @r{[}@var{feature}@dots{}@r{]}
 </target>
 @end smallexample
@@ -27641,6 +27642,32 @@ An @samp{<architecture>} element has thi
 accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
 Debugging Target}).
 
+@subsection Compatible Architecture
+@cindex <compatible>
+
+A @samp{<compatible>} element has this form:
+
+@smallexample
+  <compatible>@var{arch}</compatible>
+@end smallexample
+
+@var{arch} is an architecture name from the same selection
+accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
+Debugging Target}).
+
+A @samp{<compatible>} element is used to specify that the target
+is able to run binaries in some other than the main target architecture
+given by the @samp{<architecture>} element.  For example, on the
+Cell Broadband Engine, the main architecture is @code{powerpc:common}
+or @code{powerpc:common64}, but the system is able to run binaries
+in the @code{spu} architecture as well.  The way to describe this
+capability with @samp{<compatible>} is as follows:
+
+@smallexample
+  <architecture>@code{powerpc:common}</architecture>
+  <compatible>@code{spu}</compatible>
+@end smallexample
+
 @subsection Features
 @cindex <feature>
 


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure
  2008-09-08 11:45   ` Ulrich Weigand
@ 2008-09-08 19:25     ` Eli Zaretskii
  2008-09-09 10:47       ` Ulrich Weigand
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2008-09-08 19:25 UTC (permalink / raw)
  To: Ulrich Weigand; +Cc: gdb-patches

> Date: Mon, 8 Sep 2008 13:45:01 +0200 (CEST)
> From: "Ulrich Weigand" <uweigand@de.ibm.com>
> Cc: gdb-patches@sourceware.org
> 
> Eli Zaretskii wrote:
> 
> > > +@var{arch} is an architecture name from the same selection
> > > +accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
> > > +Debugging Target}).
> > 
> > I don't understand the purpose of "the same" here.  Same as what?
> 
> This element accepts the same set of architecture names as the set 
> accepted by the "set architecture" command.

Then I suggest to rephrase:

 +@var{arch} is one of the architectures from the set accepted by
 +@code{set architecture} (@pxref{Targets, ,Specifying a Debugging
 +Target}).

> The wording I've used is copied above is copied from the description
> of the <architecture> element

Please fix that one as well.

> See below for an updated patch.

Thanks, this is fine (with the above wording change).


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure
  2008-09-08 19:25     ` Eli Zaretskii
@ 2008-09-09 10:47       ` Ulrich Weigand
  0 siblings, 0 replies; 5+ messages in thread
From: Ulrich Weigand @ 2008-09-09 10:47 UTC (permalink / raw)
  To: eliz; +Cc: gdb-patches

Eli Zaretskii wrote:

> Then I suggest to rephrase:
> 
>  +@var{arch} is one of the architectures from the set accepted by
>  +@code{set architecture} (@pxref{Targets, ,Specifying a Debugging
>  +Target}).
> 
> > The wording I've used is copied above is copied from the description
> > of the <architecture> element
> 
> Please fix that one as well.
> 
> > See below for an updated patch.
> 
> Thanks, this is fine (with the above wording change).

Thanks!  For reference, here's the current version of the gdb.texinfo
changes.

Bye,
Ulrich


Index: src/gdb/doc/gdb.texinfo
===================================================================
--- src.orig/gdb/doc/gdb.texinfo
+++ src/gdb/doc/gdb.texinfo
@@ -27586,6 +27586,7 @@ are explained further below.
 <!DOCTYPE target SYSTEM "gdb-target.dtd">
 <target version="1.0">
   @r{[}@var{architecture}@r{]}
+  @r{[}@var{compatible}@dots{}@r{]}
   @r{[}@var{feature}@dots{}@r{]}
 </target>
 @end smallexample
@@ -27637,9 +27638,33 @@ An @samp{<architecture>} element has thi
   <architecture>@var{arch}</architecture>
 @end smallexample
 
-@var{arch} is an architecture name from the same selection
-accepted by @code{set architecture} (@pxref{Targets, ,Specifying a
-Debugging Target}).
+@var{arch} is one of the architectures from the set accepted by
+@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
+
+@subsection Compatible Architecture
+@cindex <compatible>
+
+A @samp{<compatible>} element has this form:
+
+@smallexample
+  <compatible>@var{arch}</compatible>
+@end smallexample
+
+@var{arch} is one of the architectures from the set accepted by
+@code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}).
+
+A @samp{<compatible>} element is used to specify that the target
+is able to run binaries in some other than the main target architecture
+given by the @samp{<architecture>} element.  For example, on the
+Cell Broadband Engine, the main architecture is @code{powerpc:common}
+or @code{powerpc:common64}, but the system is able to run binaries
+in the @code{spu} architecture as well.  The way to describe this
+capability with @samp{<compatible>} is as follows:
+
+@smallexample
+  <architecture>@code{powerpc:common}</architecture>
+  <compatible>@code{spu}</compatible>
+@end smallexample
 
 @subsection Features
 @cindex <feature>


-- 
  Dr. Ulrich Weigand
  GNU Toolchain for Linux on System z and Cell BE
  Ulrich.Weigand@de.ibm.com


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-09-09 10:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-09-07 21:15 [rfc] [11/18] Cell multi-arch: Target description <compatible> infrastructure Ulrich Weigand
2008-09-08  3:09 ` Eli Zaretskii
2008-09-08 11:45   ` Ulrich Weigand
2008-09-08 19:25     ` Eli Zaretskii
2008-09-09 10:47       ` Ulrich Weigand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox