From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20346 invoked by alias); 6 Jul 2009 15:17:25 -0000 Received: (qmail 20327 invoked by uid 22791); 6 Jul 2009 15:17:22 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_38,J_CHICKENPOX_81,J_CHICKENPOX_83,J_CHICKENPOX_91,SPF_PASS X-Spam-Check-By: sourceware.org Received: from mail.codesourcery.com (HELO mail.codesourcery.com) (65.74.133.4) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Mon, 06 Jul 2009 15:17:15 +0000 Received: (qmail 11946 invoked from network); 6 Jul 2009 15:17:12 -0000 Received: from unknown (HELO orlando.local) (pedro@127.0.0.2) by mail.codesourcery.com with ESMTPA; 6 Jul 2009 15:17:12 -0000 From: Pedro Alves To: gdb-patches@sourceware.org Subject: Re: Reporting the OSABI in target descriptions. Date: Mon, 06 Jul 2009 15:17:00 -0000 User-Agent: KMail/1.9.10 Cc: Eli Zaretskii References: <200906102219.47898.pedro@codesourcery.com> In-Reply-To: <200906102219.47898.pedro@codesourcery.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200907061617.58494.pedro@codesourcery.com> X-IsSubscribed: yes 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/msg00137.txt.bz2 On Wednesday 10 June 2009 22:19:47, Pedro Alves wrote: > Hi all, > > Currently, target descriptions describe the target's architecture > only. This patch adds support for optionally reporting the OSABI too. > > If "set osabi" is set to auto, GDB can usualy figure the OSABI from > the executable's bfd, but, one isn't always available. > > E.g., If I hack my gdb/configure.tgt to default to GDB_OSABI_DICOS > instead of GDB_OSABI_LINUX, and I start GDB without a program > loaded, so it has nowhere to extract the OSABI from, I get this > when connecting to an x86_64 linux gdbserver, from my x86_64 linux > host: > > > ./gdb > : > (gdb) show osabi > The current OS ABI is "auto" (currently "DICOS"). > The default OS ABI is "DICOS". > : > (gdb) tar remote :9999 > [New Thread 0x7f942d04d6e0 (LWP 22002)] > Remote debugging using :9999 > warning: A handler for the OS ABI "DICOS" is not built into this configuration > of GDB. Attempting to continue with the default i386:x86-64 settings. > > Remote register badly formatted: T0506:0000000000000000;07:90a738c6ff7f0000;10:60fa16becf7f0000;thread:43e5; > here: 00000000;07:90a738c6ff7f0000;10:60fa16becf7f0000;thread:43e5; > (gdb) > > With the patch below, I now get: > > (gdb) tar remote :9999 > [New Thread 0x7f500e7fb6e0 (LWP 12913)] > Remote debugging using :9999 > warning: Could not load vsyscall page because no executable was specified > try using the "file" command first. > 0x00007f904813da60 in ?? () > > and voila... > > (gdb) show osabi > The current OS ABI is "auto" (currently "GNU/Linux"). > The default OS ABI is "DICOS". > (gdb) > > As for the string that is passed down, I chose to just pass what > GDB is already using as osabi names. These have been very stable > over the years. > > So that gdbserver supports this, I've tweaked the regformats/regdat.sh > script to grok a new "osabi" field in the .dat files, and done > a couple of examples: x86/x86_64-linux, which covers the specifying > the osabi in the .dat files directly, and mips-linux, that covers doing > it in from an embedded xml file. I didn't touch other archs as their > xml and dat files didn't have "linux" in the filename, but > it probably just means that we'd have to go add such linux files, > or check which ones aren't named foolinux.xml or foolinux.dat, > but are only really used by gdbserver-linux. We can of course > easilly add .xml and .dat files for Windows or other hosts > gdbserver runs on. > > As for the gdb-target.dtd change, older GDB's just ignore the > new element, and since it is optional, I think it is fine > to just not bump the dtd version. > > Tested on x86_64-linux {native and against local gdbserver}. > > Ok? Do I take it nobody has comments on this? (I forgot to mention that Daniel had oked this off-line.) Eli, are is the docs (mostly doing the same as the description of the "architecture" element does) and NEWS patch hunks below okay? 2009-07-06 Pedro Alves * features/gdb-target.dtd (target): Accept an optional 'osabi' element. (osabi): Define element. * features/mips-linux.xml (target): Add an osabi subelement set to GNU/Linux. * regformats/regdat.sh (xmlarch, xmlosabi): New variables. Don't write the architecture into $xmltarget. Store it in $xmlarch. Handle the 'osabi' type. Handle outputting the osabi element of the target description. * regformats/reg-x86-64-linux.dat (osabi): Set to GNU/Linux. * regformats/reg-i386-linux.dat (osabi): Set to GNU/Linux. * target-descriptions.h (tdesc_osabi, set_tdesc_osabi): Declare. * target-descriptions.c (struct target_desc) : New field. (tdesc_osabi): New function. (set_tdesc_osabi): New function. * xml-tdesc.c: Include osabi.h. (tdesc_end_osabi): New. (target_children): Parse "osabi" elements. * arch-utils.c (gdbarch_info_fill): Try to get the osabi from the target description if the user didn't override it or it is not extractable from the bfd. If that still fails, fallback to the configured in default. * osabi.h (osabi_from_tdesc_string): Declare. * osabi.c (osabi_from_tdesc_string): New. (gdbarch_lookup_osabi): Return GDB_OSABI_UNKNOWN instead of GDB_OSABI_DEFAULT. * NEWS: Mention that target descriptions can now describe the target OS ABI. 2009-07-06 Pedro Alves * gdb.textinfo (Target Description Format): Mention the new optional element. (subsection OS ABI): New subsection. --- gdb/NEWS | 4 +++ gdb/arch-utils.c | 7 ++++++ gdb/doc/gdb.texinfo | 19 +++++++++++++++++- gdb/features/gdb-target.dtd | 7 +++++- gdb/features/mips-linux.xml | 1 gdb/osabi.c | 38 +++++++++++++++++++++++++++--------- gdb/osabi.h | 4 +++ gdb/regformats/reg-i386-linux.dat | 1 gdb/regformats/reg-x86-64-linux.dat | 1 gdb/regformats/regdat.sh | 20 +++++++++++++++++- gdb/target-descriptions.c | 20 ++++++++++++++++++ gdb/target-descriptions.h | 6 +++++ gdb/xml-tdesc.c | 21 +++++++++++++++++++ 13 files changed, 136 insertions(+), 13 deletions(-) Index: src/gdb/features/gdb-target.dtd =================================================================== --- src.orig/gdb/features/gdb-target.dtd 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/features/gdb-target.dtd 2009-07-06 16:11:34.000000000 +0100 @@ -6,12 +6,17 @@ - + + + + + Index: src/gdb/features/mips-linux.xml =================================================================== --- src.orig/gdb/features/mips-linux.xml 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/features/mips-linux.xml 2009-07-06 16:11:34.000000000 +0100 @@ -8,6 +8,7 @@ mips + GNU/Linux Index: src/gdb/regformats/regdat.sh =================================================================== --- src.orig/gdb/regformats/regdat.sh 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/regformats/regdat.sh 2009-07-06 16:11:34.000000000 +0100 @@ -128,6 +128,8 @@ offset=0 i=0 name=x xmltarget=x +xmlarch=x +xmlosabi=x expedite=x exec < $1 while do_read @@ -140,7 +142,10 @@ do xmltarget="${entry}" continue elif test "${type}" = "xmlarch"; then - xmltarget="@${entry}" + xmlarch="${entry}" + continue + elif test "${type}" = "osabi"; then + xmlosabi="${entry}" continue elif test "${type}" = "expedite"; then expedite="${entry}" @@ -159,7 +164,18 @@ echo "};" echo echo "const char *expedite_regs_${name}[] = { \"`echo ${expedite} | sed 's/,/", "/g'`\", 0 };" if test "${xmltarget}" = x; then - echo "const char *xmltarget_${name} = 0;" + if test "${xmlarch}" = x && test "${xmlosabi}" = x; then + echo "const char *xmltarget_${name} = 0;" + else + echo "const char *xmltarget_${name} = \"@\\" + if test "${xmlarch}" != x; then + echo "${xmlarch}\\" + fi + if test "${xmlosabi}" != x; then + echo "${xmlosabi}\\" + fi + echo "\";" + fi else echo "const char *xmltarget_${name} = \"${xmltarget}\";" fi Index: src/gdb/regformats/reg-x86-64-linux.dat =================================================================== --- src.orig/gdb/regformats/reg-x86-64-linux.dat 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/regformats/reg-x86-64-linux.dat 2009-07-06 16:11:34.000000000 +0100 @@ -1,5 +1,6 @@ name:x86_64_linux xmlarch:i386:x86-64 +osabi:GNU/Linux expedite:rbp,rsp,rip 64:rax 64:rbx Index: src/gdb/regformats/reg-i386-linux.dat =================================================================== --- src.orig/gdb/regformats/reg-i386-linux.dat 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/regformats/reg-i386-linux.dat 2009-07-06 16:11:34.000000000 +0100 @@ -1,5 +1,6 @@ name:i386_linux xmlarch:i386 +osabi:GNU/Linux expedite:ebp,esp,eip 32:eax 32:ecx Index: src/gdb/target-descriptions.h =================================================================== --- src.orig/gdb/target-descriptions.h 2009-07-06 16:11:14.000000000 +0100 +++ src/gdb/target-descriptions.h 2009-07-06 16:11:34.000000000 +0100 @@ -123,6 +123,11 @@ int tdesc_numbered_register_choices (con const struct bfd_arch_info *tdesc_architecture (const struct target_desc *); +/* Return the OSABI associated with this target description, or + GDB_OSABI_UNKNOWN if no osabi was specified. */ + +enum gdb_osabi tdesc_osabi (const struct target_desc *); + /* Return the string value of a property named KEY, or NULL if the property was not specified. */ @@ -167,6 +172,7 @@ struct target_desc *allocate_target_desc struct cleanup *make_cleanup_free_target_description (struct target_desc *); void set_tdesc_architecture (struct target_desc *, const struct bfd_arch_info *); +void set_tdesc_osabi (struct target_desc *, enum gdb_osabi osabi); void set_tdesc_property (struct target_desc *, const char *key, const char *value); Index: src/gdb/target-descriptions.c =================================================================== --- src.orig/gdb/target-descriptions.c 2009-07-06 16:11:14.000000000 +0100 +++ src/gdb/target-descriptions.c 2009-07-06 16:11:34.000000000 +0100 @@ -165,6 +165,10 @@ struct target_desc /* The architecture reported by the target, if any. */ const struct bfd_arch_info *arch; + /* The osabi reported by the target, if any; GDB_OSABI_UNKNOWN + otherwise. */ + enum gdb_osabi osabi; + /* Any architecture-specific properties specified by the target. */ VEC(property_s) *properties; @@ -351,6 +355,16 @@ tdesc_architecture (const struct target_ { return target_desc->arch; } + +/* Return the OSABI associated with this target description, or + GDB_OSABI_UNKNOWN if no osabi was specified. */ + +enum gdb_osabi +tdesc_osabi (const struct target_desc *target_desc) +{ + return target_desc->osabi; +} + /* Return 1 if this target description includes any registers. */ @@ -1161,6 +1175,12 @@ set_tdesc_architecture (struct target_de { target_desc->arch = arch; } + +void +set_tdesc_osabi (struct target_desc *target_desc, enum gdb_osabi osabi) +{ + target_desc->osabi = osabi; +} static struct cmd_list_element *tdesc_set_cmdlist, *tdesc_show_cmdlist; Index: src/gdb/xml-tdesc.c =================================================================== --- src.orig/gdb/xml-tdesc.c 2009-07-06 16:11:15.000000000 +0100 +++ src/gdb/xml-tdesc.c 2009-07-06 16:11:34.000000000 +0100 @@ -24,6 +24,7 @@ #include "target-descriptions.h" #include "xml-support.h" #include "xml-tdesc.h" +#include "osabi.h" #include "filenames.h" @@ -105,6 +106,24 @@ tdesc_end_arch (struct gdb_xml_parser *p set_tdesc_architecture (data->tdesc, arch); } +/* Handle the end of an element and its value. */ + +static void +tdesc_end_osabi (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; + enum gdb_osabi osabi; + + osabi = osabi_from_tdesc_string (body_text); + if (osabi == GDB_OSABI_UNKNOWN) + warning (_("Target description specified unknown osabi \"%s\""), + body_text); + else + set_tdesc_osabi (data->tdesc, osabi); +} + /* Handle the start of a element. */ static void @@ -313,6 +332,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 }, + { "osabi", NULL, NULL, GDB_XML_EF_OPTIONAL, + NULL, tdesc_end_osabi }, { "feature", feature_attributes, feature_children, GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE, tdesc_start_feature, NULL }, Index: src/gdb/arch-utils.c =================================================================== --- src.orig/gdb/arch-utils.c 2009-07-06 16:11:06.000000000 +0100 +++ src/gdb/arch-utils.c 2009-07-06 16:11:34.000000000 +0100 @@ -710,8 +710,15 @@ gdbarch_info_fill (struct gdbarch_info * info->byte_order_for_code = info->byte_order; /* "(gdb) set osabi ...". Handled by gdbarch_lookup_osabi. */ + /* From the manual override, or from file. */ if (info->osabi == GDB_OSABI_UNINITIALIZED) info->osabi = gdbarch_lookup_osabi (info->abfd); + /* From the target. */ + if (info->osabi == GDB_OSABI_UNKNOWN && info->target_desc != NULL) + info->osabi = tdesc_osabi (info->target_desc); + /* From the configured default. */ + if (info->osabi == GDB_OSABI_UNKNOWN) + info->osabi = GDB_OSABI_DEFAULT; /* Must have at least filled in the architecture. */ gdb_assert (info->bfd_arch_info != NULL); Index: src/gdb/osabi.h =================================================================== --- src.orig/gdb/osabi.h 2009-07-06 16:10:38.000000000 +0100 +++ src/gdb/osabi.h 2009-07-06 16:11:34.000000000 +0100 @@ -40,6 +40,10 @@ void gdbarch_register_osabi (enum bfd_ar /* Lookup the OS ABI corresponding to the specified BFD. */ enum gdb_osabi gdbarch_lookup_osabi (bfd *); +/* Lookup the OS ABI corresponding to the specified target description + string. */ +enum gdb_osabi osabi_from_tdesc_string (const char *text); + /* Initialize the gdbarch for the specified OS ABI variant. */ void gdbarch_init_osabi (struct gdbarch_info, struct gdbarch *); Index: src/gdb/osabi.c =================================================================== --- src.orig/gdb/osabi.c 2009-07-06 16:11:11.000000000 +0100 +++ src/gdb/osabi.c 2009-07-06 16:11:34.000000000 +0100 @@ -87,6 +87,30 @@ gdbarch_osabi_name (enum gdb_osabi osabi return gdb_osabi_names[GDB_OSABI_INVALID]; } +/* Lookup the OS ABI corresponding to the specified target description + string. */ + +enum gdb_osabi +osabi_from_tdesc_string (const char *name) +{ + int i; + + for (i = 0; i < ARRAY_SIZE (gdb_osabi_names); i++) + if (strcmp (name, gdb_osabi_names[i]) == 0) + { + /* See note above: the name table matches the indices assigned + to enum gdb_osabi. */ + enum gdb_osabi osabi = (enum gdb_osabi) i; + + if (osabi == GDB_OSABI_INVALID) + return GDB_OSABI_UNKNOWN; + else + return osabi; + } + + return GDB_OSABI_UNKNOWN; +} + /* Handler for a given architecture/OS ABI pair. There should be only one handler for a given OS ABI each architecture family. */ struct gdb_osabi_handler @@ -205,10 +229,11 @@ gdbarch_lookup_osabi (bfd *abfd) if (user_osabi_state == osabi_user) return user_selected_osabi; - /* If we don't have a binary, return the default OS ABI (if set) or - unknown (otherwise). */ + /* If we don't have a binary, just return unknown. The caller may + have other sources the OSABI can be extracted from, e.g., the + target description. */ if (abfd == NULL) - return GDB_OSABI_DEFAULT; + return GDB_OSABI_UNKNOWN; match = GDB_OSABI_UNKNOWN; match_specific = 0; @@ -269,12 +294,7 @@ gdbarch_lookup_osabi (bfd *abfd) } } - /* If we didn't find a match, but a default was specified at configure - time, return the default. */ - if (GDB_OSABI_DEFAULT != GDB_OSABI_UNKNOWN && match == GDB_OSABI_UNKNOWN) - return GDB_OSABI_DEFAULT; - else - return match; + return match; } Index: src/gdb/NEWS =================================================================== --- src.orig/gdb/NEWS 2009-07-06 16:11:05.000000000 +0100 +++ src/gdb/NEWS 2009-07-06 16:11:34.000000000 +0100 @@ -185,6 +185,10 @@ add new commands to existing prefixes, e visible changes; see "New commands" and also "Removed commands" below. +* Target descriptions can now describe the target OS ABI. See the +section on target descriptions 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, Index: src/gdb/doc/gdb.texinfo =================================================================== --- src.orig/gdb/doc/gdb.texinfo 2009-07-06 16:11:17.000000000 +0100 +++ src/gdb/doc/gdb.texinfo 2009-07-06 16:11:34.000000000 +0100 @@ -30707,7 +30707,8 @@ their targets, we also describe the gram Target descriptions can identify the architecture of the remote target and (for some architectures) provide information about custom register -sets. @value{GDBN} can use this information to autoconfigure for your +sets. They can also identify the OS ABI of the remote target. +@value{GDBN} can use this information to autoconfigure for your target, or to warn you if you connect to an unsupported target. Here is a simple target description: @@ -30731,6 +30732,7 @@ are explained further below. @r{[}@var{architecture}@r{]} + @r{[}@var{osabi}@r{]} @r{[}@var{feature}@dots{}@r{]} @end smallexample @@ -30786,6 +30788,21 @@ An @samp{} element has thi accepted by @code{set architecture} (@pxref{Targets, ,Specifying a Debugging Target}). +@subsection OS ABI +@cindex + +This optional field was introduced in @value{GDBN} version 7.0. +Previous versions of @value{GDBN} ignore it. + +An @samp{} element has this form: + +@smallexample + @var{osabi} +@end smallexample + +@var{osabi} is an OS ABI name from the same selection accepted by +@w{@code{set osabi}} (@pxref{ABI, ,Configuring the Current ABI}). + @subsection Features @cindex