From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24458 invoked by alias); 25 Apr 2009 22:27:12 -0000 Received: (qmail 24440 invoked by uid 22791); 25 Apr 2009 22:27:04 -0000 X-SWARE-Spam-Status: No, hits=-0.5 required=5.0 tests=AWL,BAYES_50,J_CHICKENPOX_47 X-Spam-Check-By: sourceware.org Received: from e24smtp01.br.ibm.com (HELO e24smtp01.br.ibm.com) (32.104.18.85) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sat, 25 Apr 2009 22:26:53 +0000 Received: from mailhub3.br.ibm.com (mailhub3.br.ibm.com [9.18.232.110]) by e24smtp01.br.ibm.com (8.13.1/8.13.1) with ESMTP id n3PMgoHH026852 for ; Sat, 25 Apr 2009 19:42:50 -0300 Received: from d24av02.br.ibm.com (d24av02.br.ibm.com [9.18.232.47]) by mailhub3.br.ibm.com (8.13.8/8.13.8/NCO v9.2) with ESMTP id n3PMRASZ2072808 for ; Sat, 25 Apr 2009 19:27:10 -0300 Received: from d24av02.br.ibm.com (loopback [127.0.0.1]) by d24av02.br.ibm.com (8.12.11.20060308/8.13.3) with ESMTP id n3PMQllS022645 for ; Sat, 25 Apr 2009 19:26:47 -0300 Received: from [9.18.198.222] ([9.18.198.222]) by d24av02.br.ibm.com (8.12.11.20060308/8.12.11) with ESMTP id n3PMQkIT022638; Sat, 25 Apr 2009 19:26:46 -0300 Subject: Re: [PATCH 2/3] catch syscall -- try 5 -- XML support From: =?ISO-8859-1?Q?S=E9rgio?= Durigan =?ISO-8859-1?Q?J=FAnior?= To: Eli Zaretskii Cc: gdb-patches@sourceware.org In-Reply-To: <83oculf7a6.fsf@gnu.org> References: <1240446783.2000.84.camel@miki> <83oculf7a6.fsf@gnu.org> Content-Type: multipart/mixed; boundary="=-DLOS7a3308Om7Ejp5Cu+" Date: Sat, 25 Apr 2009 22:27:00 -0000 Message-Id: <1240698404.13755.2.camel@miki> Mime-Version: 1.0 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-04/txt/msg00710.txt.bz2 --=-DLOS7a3308Om7Ejp5Cu+ Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit Content-length: 2666 Hi Eli, On Sat, 2009-04-25 at 11:48 +0300, Eli Zaretskii wrote: > > From: =?ISO-8859-1?Q?S=E9rgio?= Durigan =?ISO-8859-1?Q?J=FAnior?= > > Date: Wed, 22 Apr 2009 21:33:03 -0300 > > > > gdb/ChangeLog: > > > > 2009-04-22 Sergio Durigan Junior > > > > * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML > > support. > > * syscalls/i386-syscalls.xml: New file for i386 syscalls. > > * syscalls/ppc-syscalls.xml: New file for PPC syscalls. > > * syscalls/ppc64-syscalls.xml: New file for PPC64 syscalls. > > The last 3 entries name the files incorrectly, and also do not say > that the lists are for GNU/Linux systems that use these hardware > architectures. Ops, sorry. I didn't notice that it was wrong, it's an old version of the ChangeLog. > > diff --git a/gdb/syscalls/i386-linux.xml b/gdb/syscalls/i386-linux.xml > > new file mode 100644 > > index 0000000..6f2beee > > --- /dev/null > > +++ b/gdb/syscalls/i386-linux.xml > > @@ -0,0 +1,334 @@ > > + > > + > > + > > + > > + > > + > > + > > Where does this information come from? If there's some system file > from which you gleaned this, I'd suggest to name it here. This is so > someone in the future could update this database per the OS > development. Oh, sure. Here goes a refreshed version of the patch containing the changes. I'll address the other comments (in the other patches) later today. Thank you, -- Sérgio Durigan Júnior Linux on Power Toolchain - Software Engineer Linux Technology Center - LTC IBM Brazil gdb/ChangeLog: 2009-04-25 Sergio Durigan Junior * syscalls/gdb-syscalls.dtd: New definition file for syscall's XML support. * syscalls/i386-linux.xml: New file containing information about syscalls for GNU/Linux systems that use i386 architecture. * syscalls/ppc-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC architecture. * syscalls/ppc64-linux.xml: New file containing information about syscalls for GNU/Linux systems that use PPC64 architecture. * xml-syscall.c: New file containing functions for manipulating syscall's XML files. * xml-syscall.h: New file, exporting the functions above mentioned. --=-DLOS7a3308Om7Ejp5Cu+ Content-Disposition: attachment; filename="catch-syscall-xml-part.patch" Content-Type: text/x-patch; name="catch-syscall-xml-part.patch"; charset="ISO-8859-1" Content-Transfer-Encoding: 7bit Content-length: 54960 diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd new file mode 100644 index 0000000..865eba6 --- /dev/null +++ b/gdb/syscalls/gdb-syscalls.dtd @@ -0,0 +1,14 @@ + + + + + + + + diff --git a/gdb/syscalls/i386-linux.xml b/gdb/syscalls/i386-linux.xml new file mode 100644 index 0000000..c79ad9c --- /dev/null +++ b/gdb/syscalls/i386-linux.xml @@ -0,0 +1,340 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb/syscalls/ppc-linux.xml b/gdb/syscalls/ppc-linux.xml new file mode 100644 index 0000000..876e0b6 --- /dev/null +++ b/gdb/syscalls/ppc-linux.xml @@ -0,0 +1,310 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb/syscalls/ppc64-linux.xml b/gdb/syscalls/ppc64-linux.xml new file mode 100644 index 0000000..d81d065 --- /dev/null +++ b/gdb/syscalls/ppc64-linux.xml @@ -0,0 +1,295 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c new file mode 100644 index 0000000..cf7a336 --- /dev/null +++ b/gdb/xml-syscall.c @@ -0,0 +1,432 @@ +/* Functions that provide the mechanism to parse a syscall XML file + and get its values. + + Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, + 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008 + Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include "defs.h" +#include "gdbtypes.h" +#include "xml-support.h" +#include "xml-syscall.h" + +/* For the struct syscall definition. */ +#include "target.h" + +#include "filenames.h" + +#include "gdb_assert.h" + +#ifndef HAVE_LIBEXPAT + +/* Dummy functions to indicate that there's no support for fetching + syscalls information. */ + +static void +syscall_warn_user (void) +{ + static int have_warned = 0; + if (!have_warned) + { + have_warned = 1; + warning (_("Can not parse XML syscalls information; XML support was " + "disabled at compile time.")); + } +} + +void +set_xml_syscall_file_name (const char *name) +{ + syscall_warn_user (); +} + +void +get_syscall_by_number (int syscall_number, + struct syscall *s) +{ + syscall_warn_user (); + s->number = syscall_number; + s->name = NULL; +} + +void +get_syscall_by_name (const char *syscall_name, + struct syscall *s) +{ + syscall_warn_user (); + s->number = UNKNOWN_SYSCALL; + s->name = syscall_name; +} + +const char ** +get_syscall_names (void) +{ + syscall_warn_user (); + return NULL; +} + + +#else /* ! HAVE_LIBEXPAT */ + +/* Structure which describes a syscall. */ +typedef struct syscall_desc +{ + /* The syscall number. */ + + int number; + + /* The syscall name. */ + + char *name; +} *syscall_desc_p; +DEF_VEC_P(syscall_desc_p); + +/* Structure that represents syscalls information. */ +struct syscalls_info +{ + /* The syscalls. */ + + VEC(syscall_desc_p) *syscalls; +}; + +/* Callback data for syscall information parsing. */ +struct syscall_parsing_data +{ + /* The syscalls_info we are building. */ + + struct syscalls_info *sysinfo; +}; + +/* Structure used to store information about the available syscalls in + the system. */ +static const struct syscalls_info *_sysinfo = NULL; + +/* A flag to tell if we already initialized the structure above. */ +static int have_initialized_sysinfo = 0; + +/* The filename of the syscall's XML. */ +static const char *xml_syscall_file = NULL; + +static struct syscalls_info * +allocate_syscalls_info (void) +{ + return XZALLOC (struct syscalls_info); +} + +static void +sysinfo_free_syscalls_desc (struct syscall_desc *sd) +{ + xfree (sd->name); +} + +static void +free_syscalls_info (void *arg) +{ + struct syscalls_info *sysinfo = arg; + struct syscall_desc *sysdesc; + int i; + + for (i = 0; + VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc); + i++) + sysinfo_free_syscalls_desc (sysdesc); + VEC_free (syscall_desc_p, sysinfo->syscalls); + + xfree (sysinfo); +} + +struct cleanup * +make_cleanup_free_syscalls_info (struct syscalls_info *sysinfo) +{ + return make_cleanup (free_syscalls_info, sysinfo); +} + +static void +syscall_create_syscall_desc (struct syscalls_info *sysinfo, + const char *name, int number) +{ + struct syscall_desc *sysdesc = XZALLOC (struct syscall_desc); + + sysdesc->name = xstrdup (name); + sysdesc->number = number; + + VEC_safe_push (syscall_desc_p, sysinfo->syscalls, sysdesc); +} + +/* Handle the start of a element. */ +static void +syscall_start_syscalls_info (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, + VEC(gdb_xml_value_s) *attributes) +{ + struct syscall_parsing_data *data = user_data; + struct syscalls_info *sysinfo = data->sysinfo; +} + +/* Handle the start of a element. */ +static void +syscall_start_syscall (struct gdb_xml_parser *parser, + const struct gdb_xml_element *element, + void *user_data, VEC(gdb_xml_value_s) *attributes) +{ + struct syscall_parsing_data *data = user_data; + struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes); + int len, i; + /* syscall info. */ + char *name = NULL; + int number = 0; + + len = VEC_length (gdb_xml_value_s, attributes); + + for (i = 0; i < len; i++) + { + if (strcmp (attrs[i].name, "name") == 0) + name = attrs[i].value; + else if (strcmp (attrs[i].name, "number") == 0) + number = * (ULONGEST *) attrs[i].value; + else + internal_error (__FILE__, __LINE__, + _("Unknown attribute name '%s'."), attrs[i].name); + } + + syscall_create_syscall_desc (data->sysinfo, name, number); +} + + +/* The elements and attributes of an XML syscall document. */ +static const struct gdb_xml_attribute syscall_attr[] = { + { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, + { "name", GDB_XML_AF_NONE, NULL, NULL }, + { NULL, GDB_XML_AF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element syscalls_info_children[] = { + { "syscall", syscall_attr, NULL, + GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE, + syscall_start_syscall, NULL }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + +static const struct gdb_xml_element syselements[] = { + { "syscalls_info", NULL, syscalls_info_children, + GDB_XML_EF_NONE, syscall_start_syscalls_info, NULL }, + { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } +}; + +static struct syscalls_info * +syscall_parse_xml (const char *document, xml_fetch_another fetcher, + void *fetcher_baton) +{ + struct cleanup *result_cleanup; + struct gdb_xml_parser *parser; + struct syscall_parsing_data data; + char *expanded_text; + int i; + + parser = gdb_xml_create_parser_and_cleanup (_("syscalls info"), + syselements, &data); + + memset (&data, 0, sizeof (struct syscall_parsing_data)); + data.sysinfo = allocate_syscalls_info (); + result_cleanup = make_cleanup_free_syscalls_info (data.sysinfo); + + if (gdb_xml_parse (parser, document) == 0) + { + /* Parsed successfully. */ + discard_cleanups (result_cleanup); + return data.sysinfo; + } + else + { + warning (_("Could not load XML syscalls info; ignoring")); + do_cleanups (result_cleanup); + return NULL; + } +} + +/* Function responsible for initializing the information + about the syscalls. It reads the XML file and fills the + struct syscalls_info with the values. + + Returns the struct syscalls_info if the file is valid, NULL otherwise. */ +static const struct syscalls_info * +xml_init_syscalls_info (const char *filename) +{ + char *full_file; + char *dirname; + struct syscalls_info *sysinfo; + struct cleanup *back_to; + + full_file = xml_fetch_content_from_file (filename, data_directory); + if (full_file == NULL) + { + warning (_("Could not open \"%s\""), filename); + return NULL; + } + + back_to = make_cleanup (xfree, full_file); + + dirname = ldirname (filename); + if (dirname != NULL) + make_cleanup (xfree, dirname); + + sysinfo = syscall_parse_xml (full_file, xml_fetch_content_from_file, dirname); + do_cleanups (back_to); + + return sysinfo; +} + +/* Initializes the syscalls_info structure according to the + architecture. */ +static void +init_sysinfo (void) +{ + /* Did we already try to initialize the structure? */ + if (have_initialized_sysinfo) + return; +/* if (xml_syscall_file == NULL) + internal_error (__FILE__, __LINE__, + _("This architecture has not set the XML syscall file " + "name. This is a bug and should not happen; please " + "report it.")); */ + + _sysinfo = xml_init_syscalls_info (xml_syscall_file); + + have_initialized_sysinfo = 1; + + if (_sysinfo == NULL) + { + if (xml_syscall_file) + /* The initialization failed. Let's show a warning + message to the user (just this time) and leave. */ + warning (_("Could not load the syscall XML file `%s'.\n\ +GDB will not be able to display syscall names."), xml_syscall_file); + else + /* There's no file to open. Let's warn the user. */ + warning (_("There is no XML file to open.\n\ +GDB will not be able to display syscall names.")); + } +} + +static int +xml_get_syscall_number (const struct syscalls_info *sysinfo, + const char *syscall_name) +{ + struct syscall_desc *sysdesc; + int i; + + if (sysinfo == NULL + || syscall_name == NULL) + return UNKNOWN_SYSCALL; + + for (i = 0; + VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc); + i++) + if (strcmp (sysdesc->name, syscall_name) == 0) + return sysdesc->number; + + return UNKNOWN_SYSCALL; +} + +static const char * +xml_get_syscall_name (const struct syscalls_info *sysinfo, + int syscall_number) +{ + struct syscall_desc *sysdesc; + int i; + + if (sysinfo == NULL + || syscall_number < 0) + return NULL; + + for (i = 0; + VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc); + i++) + if (sysdesc->number == syscall_number) + return sysdesc->name; + + return NULL; +} + +static int +xml_number_of_syscalls (const struct syscalls_info *sysinfo) +{ + return (sysinfo == NULL ? 0 : VEC_length (syscall_desc_p, + sysinfo->syscalls)); +} + +static const char ** +xml_list_of_syscalls (const struct syscalls_info *sysinfo) +{ + struct syscall_desc *sysdesc; + const char **names = NULL; + int nsyscalls; + int i; + + if (sysinfo == NULL) + return NULL; + + nsyscalls = VEC_length (syscall_desc_p, sysinfo->syscalls); + names = xmalloc ((nsyscalls + 1) * sizeof (char *)); + + for (i = 0; + VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc); + i++) + names[i] = sysdesc->name; + + names[i] = NULL; + + return names; +} + +void +set_xml_syscall_file_name (const char *name) +{ + xml_syscall_file = name; +} + +void +get_syscall_by_number (int syscall_number, + struct syscall *s) +{ + init_sysinfo (); + + s->number = syscall_number; + s->name = xml_get_syscall_name (_sysinfo, syscall_number); +} + +void +get_syscall_by_name (const char *syscall_name, + struct syscall *s) +{ + init_sysinfo (); + + s->number = xml_get_syscall_number (_sysinfo, syscall_name); + s->name = syscall_name; +} + +const char ** +get_syscall_names (void) +{ + init_sysinfo (); + + return xml_list_of_syscalls (_sysinfo); +} + +#endif /* ! HAVE_LIBEXPAT */ diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h new file mode 100644 index 0000000..00d3a54 --- /dev/null +++ b/gdb/xml-syscall.h @@ -0,0 +1,50 @@ +/* Functions that provide the mechanism to parse a syscall XML file + and get its values. + + Copyright (C) 2009 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef XML_SYSCALL_H +#define XML_SYSCALL_H 1 + +/* Function used to set the name of the file which contains + information about the system calls present in the current + architecture. + + This function *should* be called before anything else, otherwise + GDB won't be able to find the correct XML file to open and get + the syscalls definitions. */ + +void set_xml_syscall_file_name (const char *name); + +/* Function that retrieves the syscall name corresponding to the given + number. It puts the requested information inside 'struct syscall'. */ + +void get_syscall_by_number (int syscall_number, struct syscall *s); + +/* Function that retrieves the syscall number corresponding to the given + name. It puts the requested information inside 'struct syscall'. */ + +void get_syscall_by_name (const char *syscall_name, struct syscall *s); + +/* Function used to retrieve the list of syscalls in the system. This list + is returned as an array of strings. Returns the list of syscalls in the + system, or NULL otherwise. */ + +const char **get_syscall_names (void); + +#endif /* XML_SYSCALL_H */ --=-DLOS7a3308Om7Ejp5Cu+--