From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 21559 invoked by alias); 22 Jul 2009 17:15:03 -0000 Received: (qmail 21433 invoked by uid 22791); 22 Jul 2009 17:15:01 -0000 X-SWARE-Spam-Status: No, hits=-0.4 required=5.0 tests=AWL,BAYES_20,J_CHICKENPOX_37,MSGID_FROM_MTA_HEADER,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mtagate5.de.ibm.com (HELO mtagate5.de.ibm.com) (195.212.29.154) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 22 Jul 2009 17:14:51 +0000 Received: from d12nrmr1607.megacenter.de.ibm.com (d12nrmr1607.megacenter.de.ibm.com [9.149.167.49]) by mtagate5.de.ibm.com (8.14.3/8.13.8) with ESMTP id n6MHEm9d120626 for ; Wed, 22 Jul 2009 17:14:48 GMT Received: from d12av02.megacenter.de.ibm.com (d12av02.megacenter.de.ibm.com [9.149.165.228]) by d12nrmr1607.megacenter.de.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n6MHEm8w2703572 for ; Wed, 22 Jul 2009 19:14:48 +0200 Received: from d12av02.megacenter.de.ibm.com (loopback [127.0.0.1]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n6MHEmBh012904 for ; Wed, 22 Jul 2009 19:14:48 +0200 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d12av02.megacenter.de.ibm.com (8.12.11.20060308/8.12.11) with SMTP id n6MHEkx6012886 for ; Wed, 22 Jul 2009 19:14:46 +0200 Message-Id: <200907221714.n6MHEkx6012886@d12av02.megacenter.de.ibm.com> Received: by tuxmaker.boeblingen.de.ibm.com (sSMTP sendmail emulation); Wed, 22 Jul 2009 19:14:46 +0200 Subject: [rfc] [1/9] Cell multi-arch: Target description infrastructure To: gdb-patches@sourceware.org Date: Wed, 22 Jul 2009 17:15:00 -0000 From: "Ulrich Weigand" MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2009-07/txt/msg00544.txt.bz2 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: * features/gdb-target.dtd (target): Accept optional elements. (compatible): Define element. * 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 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. * NEWS: Mention element of target descriptions. doc/ChangeLog: * gdb.texinfo (Target Descriptions): Document element. Index: src/gdb/arch-utils.c =================================================================== --- src.orig/gdb/arch-utils.c +++ src/gdb/arch-utils.c @@ -324,15 +324,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) @@ -362,6 +371,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); @@ -689,7 +703,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 @@ -158,6 +158,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 @@ -169,6 +173,9 @@ struct target_desc otherwise. */ enum gdb_osabi osabi; + /* 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; @@ -326,6 +333,28 @@ target_current_description (void) return NULL; } + +/* 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; +} /* Direct accessors for target descriptions. */ @@ -1140,6 +1169,8 @@ free_target_description (void *arg) } VEC_free (property_s, target_desc->properties); + VEC_free (arch_p, target_desc->compatible); + xfree (target_desc); } @@ -1150,6 +1181,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) { @@ -1241,6 +1296,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; @@ -1297,6 +1353,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 @@ -128,6 +128,12 @@ const struct bfd_arch_info *tdesc_archit enum gdb_osabi tdesc_osabi (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. */ @@ -175,6 +181,8 @@ void set_tdesc_architecture (struct targ void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); 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 @@ -124,6 +124,20 @@ tdesc_end_osabi (struct gdb_xml_parser * set_tdesc_osabi (data->tdesc, osabi); } +/* Handle the end of a 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 element. */ static void @@ -334,6 +348,8 @@ static const struct gdb_xml_element targ NULL, tdesc_end_arch }, { "osabi", NULL, NULL, GDB_XML_EF_OPTIONAL, NULL, tdesc_end_osabi }, + { "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 @@ -30807,6 +30807,7 @@ are explained further below. @r{[}@var{architecture}@r{]} @r{[}@var{osabi}@r{]} + @r{[}@var{compatible}@r{]} @r{[}@var{feature}@dots{}@r{]} @end smallexample @@ -30858,9 +30859,8 @@ An @samp{} element has thi @var{arch} @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 OS ABI @cindex @code{} @@ -30877,6 +30877,34 @@ An @samp{} element has this form: @var{abi-name} is an OS ABI name from the same selection accepted by @w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}). +@subsection Compatible Architecture +@cindex + +This optional field was introduced in @value{GDBN} version 7.0. +Previous versions of @value{GDBN} ignore it. + +A @samp{} element has this form: + +@smallexample + @var{arch} +@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{} 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{} 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{} is as follows: + +@smallexample + @code{powerpc:common} + @code{spu} +@end smallexample + @subsection Features @cindex Index: src/gdb/features/gdb-target.dtd =================================================================== --- src.orig/gdb/features/gdb-target.dtd +++ src/gdb/features/gdb-target.dtd @@ -6,10 +6,10 @@ - + - + @@ -17,6 +17,8 @@ + + Index: src/gdb/NEWS =================================================================== --- src.orig/gdb/NEWS +++ src/gdb/NEWS @@ -198,6 +198,12 @@ add new commands to existing prefixes, e "Target Description Format" section in the user manual for more information. +* Target descriptions can now describe "compatible" architectures +to indicate that the target can execute applications for a different +architecture in addition to those for the main target architecture. +See the "Target Description Format" section in the user manual for +more information. + * New commands (for set/show, see "New options" below) find [/size-char] [/max-count] start-address, end-address|+search-space-size, -- Dr. Ulrich Weigand GNU Toolchain for Linux on System z and Cell BE Ulrich.Weigand@de.ibm.com