Home | History | Annotate | Line # | Download | only in gdb
xml-syscall.c revision 1.8
      1  1.1  christos /* Functions that provide the mechanism to parse a syscall XML file
      2  1.1  christos    and get its values.
      3  1.1  christos 
      4  1.8  christos    Copyright (C) 2009-2019 Free Software Foundation, Inc.
      5  1.1  christos 
      6  1.1  christos    This file is part of GDB.
      7  1.1  christos 
      8  1.1  christos    This program is free software; you can redistribute it and/or modify
      9  1.1  christos    it under the terms of the GNU General Public License as published by
     10  1.1  christos    the Free Software Foundation; either version 3 of the License, or
     11  1.1  christos    (at your option) any later version.
     12  1.1  christos 
     13  1.1  christos    This program is distributed in the hope that it will be useful,
     14  1.1  christos    but WITHOUT ANY WARRANTY; without even the implied warranty of
     15  1.1  christos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     16  1.1  christos    GNU General Public License for more details.
     17  1.1  christos 
     18  1.1  christos    You should have received a copy of the GNU General Public License
     19  1.1  christos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     20  1.1  christos 
     21  1.1  christos #include "defs.h"
     22  1.1  christos #include "gdbtypes.h"
     23  1.1  christos #include "xml-support.h"
     24  1.1  christos #include "xml-syscall.h"
     25  1.3  christos #include "gdbarch.h"
     26  1.1  christos 
     27  1.1  christos /* For the struct syscall definition.  */
     28  1.1  christos #include "target.h"
     29  1.1  christos 
     30  1.1  christos #include "filenames.h"
     31  1.1  christos 
     32  1.1  christos #ifndef HAVE_LIBEXPAT
     33  1.1  christos 
     34  1.1  christos /* Dummy functions to indicate that there's no support for fetching
     35  1.1  christos    syscalls information.  */
     36  1.1  christos 
     37  1.1  christos static void
     38  1.1  christos syscall_warn_user (void)
     39  1.1  christos {
     40  1.1  christos   static int have_warned = 0;
     41  1.1  christos   if (!have_warned)
     42  1.1  christos     {
     43  1.1  christos       have_warned = 1;
     44  1.1  christos       warning (_("Can not parse XML syscalls information; XML support was "
     45  1.1  christos 		 "disabled at compile time."));
     46  1.1  christos     }
     47  1.1  christos }
     48  1.1  christos 
     49  1.1  christos void
     50  1.3  christos set_xml_syscall_file_name (struct gdbarch *gdbarch, const char *name)
     51  1.1  christos {
     52  1.1  christos   return;
     53  1.1  christos }
     54  1.1  christos 
     55  1.1  christos void
     56  1.3  christos get_syscall_by_number (struct gdbarch *gdbarch,
     57  1.3  christos 		       int syscall_number, struct syscall *s)
     58  1.1  christos {
     59  1.1  christos   syscall_warn_user ();
     60  1.1  christos   s->number = syscall_number;
     61  1.1  christos   s->name = NULL;
     62  1.1  christos }
     63  1.1  christos 
     64  1.8  christos bool
     65  1.8  christos get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name,
     66  1.8  christos 		      std::vector<int> *syscall_numbers)
     67  1.1  christos {
     68  1.1  christos   syscall_warn_user ();
     69  1.8  christos   return false;
     70  1.1  christos }
     71  1.1  christos 
     72  1.1  christos const char **
     73  1.3  christos get_syscall_names (struct gdbarch *gdbarch)
     74  1.1  christos {
     75  1.1  christos   syscall_warn_user ();
     76  1.1  christos   return NULL;
     77  1.1  christos }
     78  1.1  christos 
     79  1.8  christos bool
     80  1.8  christos get_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
     81  1.8  christos 		       std::vector<int> *syscall_numbers)
     82  1.6  christos {
     83  1.6  christos   syscall_warn_user ();
     84  1.8  christos   return false;
     85  1.6  christos }
     86  1.6  christos 
     87  1.6  christos const char **
     88  1.6  christos get_syscall_group_names (struct gdbarch *gdbarch)
     89  1.6  christos {
     90  1.6  christos   syscall_warn_user ();
     91  1.6  christos   return NULL;
     92  1.6  christos }
     93  1.6  christos 
     94  1.1  christos #else /* ! HAVE_LIBEXPAT */
     95  1.1  christos 
     96  1.1  christos /* Structure which describes a syscall.  */
     97  1.8  christos struct syscall_desc
     98  1.1  christos {
     99  1.8  christos   syscall_desc (int number_, std::string name_, std::string alias_)
    100  1.8  christos   : number (number_), name (name_), alias (alias_)
    101  1.8  christos   {}
    102  1.8  christos 
    103  1.1  christos   /* The syscall number.  */
    104  1.1  christos 
    105  1.1  christos   int number;
    106  1.1  christos 
    107  1.1  christos   /* The syscall name.  */
    108  1.1  christos 
    109  1.8  christos   std::string name;
    110  1.8  christos 
    111  1.8  christos   /* An optional alias.  */
    112  1.8  christos 
    113  1.8  christos   std::string alias;
    114  1.8  christos };
    115  1.8  christos 
    116  1.8  christos typedef std::unique_ptr<syscall_desc> syscall_desc_up;
    117  1.1  christos 
    118  1.6  christos /* Structure of a syscall group.  */
    119  1.8  christos struct syscall_group_desc
    120  1.6  christos {
    121  1.8  christos   syscall_group_desc (const std::string &name_)
    122  1.8  christos   : name (name_)
    123  1.8  christos   {}
    124  1.8  christos 
    125  1.6  christos   /* The group name.  */
    126  1.6  christos 
    127  1.8  christos   std::string name;
    128  1.6  christos 
    129  1.8  christos   /* The syscalls that are part of the group.  This is a non-owning
    130  1.8  christos      reference.  */
    131  1.8  christos 
    132  1.8  christos   std::vector<syscall_desc *> syscalls;
    133  1.8  christos };
    134  1.6  christos 
    135  1.8  christos typedef std::unique_ptr<syscall_group_desc> syscall_group_desc_up;
    136  1.6  christos 
    137  1.1  christos /* Structure that represents syscalls information.  */
    138  1.1  christos struct syscalls_info
    139  1.1  christos {
    140  1.1  christos   /* The syscalls.  */
    141  1.1  christos 
    142  1.8  christos   std::vector<syscall_desc_up> syscalls;
    143  1.3  christos 
    144  1.6  christos   /* The syscall groups.  */
    145  1.6  christos 
    146  1.8  christos   std::vector<syscall_group_desc_up> groups;
    147  1.6  christos 
    148  1.3  christos   /* Variable that will hold the last known data-directory.  This is
    149  1.3  christos      useful to know whether we should re-read the XML info for the
    150  1.3  christos      target.  */
    151  1.3  christos 
    152  1.8  christos   std::string my_gdb_datadir;
    153  1.1  christos };
    154  1.1  christos 
    155  1.8  christos typedef std::unique_ptr<syscalls_info> syscalls_info_up;
    156  1.8  christos 
    157  1.1  christos /* Callback data for syscall information parsing.  */
    158  1.1  christos struct syscall_parsing_data
    159  1.1  christos {
    160  1.1  christos   /* The syscalls_info we are building.  */
    161  1.1  christos 
    162  1.3  christos   struct syscalls_info *syscalls_info;
    163  1.1  christos };
    164  1.1  christos 
    165  1.6  christos /* Create a new syscall group.  Return pointer to the
    166  1.6  christos    syscall_group_desc structure that represents the new group.  */
    167  1.6  christos 
    168  1.6  christos static struct syscall_group_desc *
    169  1.6  christos syscall_group_create_syscall_group_desc (struct syscalls_info *syscalls_info,
    170  1.6  christos 					 const char *group)
    171  1.6  christos {
    172  1.8  christos   syscall_group_desc *groupdesc = new syscall_group_desc (group);
    173  1.6  christos 
    174  1.8  christos   syscalls_info->groups.emplace_back (groupdesc);
    175  1.6  christos 
    176  1.6  christos   return groupdesc;
    177  1.6  christos }
    178  1.6  christos 
    179  1.6  christos /* Add a syscall to the group.  If group doesn't exist, create it.  */
    180  1.6  christos 
    181  1.6  christos static void
    182  1.6  christos syscall_group_add_syscall (struct syscalls_info *syscalls_info,
    183  1.6  christos 			   struct syscall_desc *syscall,
    184  1.6  christos 			   const char *group)
    185  1.6  christos {
    186  1.8  christos   /* Search for an existing group.  */
    187  1.8  christos   std::vector<syscall_group_desc_up>::iterator it
    188  1.8  christos     = syscalls_info->groups.begin ();
    189  1.6  christos 
    190  1.8  christos   for (; it != syscalls_info->groups.end (); it++)
    191  1.6  christos     {
    192  1.8  christos       if ((*it)->name == group)
    193  1.6  christos 	break;
    194  1.6  christos     }
    195  1.6  christos 
    196  1.8  christos   syscall_group_desc *groupdesc;
    197  1.8  christos 
    198  1.8  christos   if (it != syscalls_info->groups.end ())
    199  1.8  christos     groupdesc = it->get ();
    200  1.8  christos   else
    201  1.6  christos     {
    202  1.6  christos       /* No group was found with this name.  We must create a new
    203  1.6  christos 	 one.  */
    204  1.6  christos       groupdesc = syscall_group_create_syscall_group_desc (syscalls_info,
    205  1.6  christos 							   group);
    206  1.6  christos     }
    207  1.6  christos 
    208  1.8  christos   groupdesc->syscalls.push_back (syscall);
    209  1.6  christos }
    210  1.6  christos 
    211  1.1  christos static void
    212  1.3  christos syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
    213  1.8  christos 			     const char *name, int number, const char *alias,
    214  1.6  christos 			     char *groups)
    215  1.1  christos {
    216  1.8  christos   syscall_desc *sysdesc = new syscall_desc (number, name,
    217  1.8  christos 					    alias != NULL ? alias : "");
    218  1.1  christos 
    219  1.8  christos   syscalls_info->syscalls.emplace_back (sysdesc);
    220  1.6  christos 
    221  1.6  christos   /*  Add syscall to its groups.  */
    222  1.6  christos   if (groups != NULL)
    223  1.6  christos     {
    224  1.8  christos       for (char *group = strtok (groups, ",");
    225  1.6  christos 	   group != NULL;
    226  1.6  christos 	   group = strtok (NULL, ","))
    227  1.6  christos 	syscall_group_add_syscall (syscalls_info, sysdesc, group);
    228  1.6  christos     }
    229  1.1  christos }
    230  1.1  christos 
    231  1.1  christos /* Handle the start of a <syscall> element.  */
    232  1.1  christos static void
    233  1.1  christos syscall_start_syscall (struct gdb_xml_parser *parser,
    234  1.1  christos                        const struct gdb_xml_element *element,
    235  1.8  christos                        void *user_data,
    236  1.8  christos 		       std::vector<gdb_xml_value> &attributes)
    237  1.1  christos {
    238  1.6  christos   struct syscall_parsing_data *data = (struct syscall_parsing_data *) user_data;
    239  1.1  christos   /* syscall info.  */
    240  1.1  christos   char *name = NULL;
    241  1.1  christos   int number = 0;
    242  1.8  christos   char *alias = NULL;
    243  1.6  christos   char *groups = NULL;
    244  1.1  christos 
    245  1.8  christos   for (const gdb_xml_value &attr : attributes)
    246  1.1  christos     {
    247  1.8  christos       if (strcmp (attr.name, "name") == 0)
    248  1.8  christos         name = (char *) attr.value.get ();
    249  1.8  christos       else if (strcmp (attr.name, "number") == 0)
    250  1.8  christos         number = * (ULONGEST *) attr.value.get ();
    251  1.8  christos       else if (strcmp (attr.name, "alias") == 0)
    252  1.8  christos         alias = (char *) attr.value.get ();
    253  1.8  christos       else if (strcmp (attr.name, "groups") == 0)
    254  1.8  christos         groups = (char *) attr.value.get ();
    255  1.1  christos       else
    256  1.1  christos         internal_error (__FILE__, __LINE__,
    257  1.8  christos                         _("Unknown attribute name '%s'."), attr.name);
    258  1.1  christos     }
    259  1.1  christos 
    260  1.1  christos   gdb_assert (name);
    261  1.8  christos   syscall_create_syscall_desc (data->syscalls_info, name, number, alias,
    262  1.8  christos 			       groups);
    263  1.1  christos }
    264  1.1  christos 
    265  1.1  christos 
    266  1.1  christos /* The elements and attributes of an XML syscall document.  */
    267  1.1  christos static const struct gdb_xml_attribute syscall_attr[] = {
    268  1.1  christos   { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
    269  1.1  christos   { "name", GDB_XML_AF_NONE, NULL, NULL },
    270  1.8  christos   { "alias", GDB_XML_AF_OPTIONAL, NULL, NULL },
    271  1.6  christos   { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
    272  1.1  christos   { NULL, GDB_XML_AF_NONE, NULL, NULL }
    273  1.1  christos };
    274  1.1  christos 
    275  1.1  christos static const struct gdb_xml_element syscalls_info_children[] = {
    276  1.1  christos   { "syscall", syscall_attr, NULL,
    277  1.1  christos     GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
    278  1.1  christos     syscall_start_syscall, NULL },
    279  1.1  christos   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
    280  1.1  christos };
    281  1.1  christos 
    282  1.1  christos static const struct gdb_xml_element syselements[] = {
    283  1.1  christos   { "syscalls_info", NULL, syscalls_info_children,
    284  1.1  christos     GDB_XML_EF_NONE, NULL, NULL },
    285  1.1  christos   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
    286  1.1  christos };
    287  1.1  christos 
    288  1.1  christos static struct syscalls_info *
    289  1.1  christos syscall_parse_xml (const char *document, xml_fetch_another fetcher,
    290  1.1  christos                    void *fetcher_baton)
    291  1.1  christos {
    292  1.1  christos   struct syscall_parsing_data data;
    293  1.8  christos   syscalls_info_up sysinfo (new syscalls_info ());
    294  1.1  christos 
    295  1.8  christos   data.syscalls_info = sysinfo.get ();
    296  1.1  christos 
    297  1.1  christos   if (gdb_xml_parse_quick (_("syscalls info"), NULL,
    298  1.1  christos 			   syselements, document, &data) == 0)
    299  1.1  christos     {
    300  1.1  christos       /* Parsed successfully.  */
    301  1.8  christos       return sysinfo.release ();
    302  1.1  christos     }
    303  1.1  christos   else
    304  1.1  christos     {
    305  1.1  christos       warning (_("Could not load XML syscalls info; ignoring"));
    306  1.1  christos       return NULL;
    307  1.1  christos     }
    308  1.1  christos }
    309  1.1  christos 
    310  1.1  christos /* Function responsible for initializing the information
    311  1.1  christos    about the syscalls.  It reads the XML file and fills the
    312  1.1  christos    struct syscalls_info with the values.
    313  1.1  christos 
    314  1.1  christos    Returns the struct syscalls_info if the file is valid, NULL otherwise.  */
    315  1.3  christos static struct syscalls_info *
    316  1.1  christos xml_init_syscalls_info (const char *filename)
    317  1.1  christos {
    318  1.8  christos   gdb::optional<gdb::char_vector> full_file
    319  1.8  christos     = xml_fetch_content_from_file (filename, gdb_datadir);
    320  1.8  christos   if (!full_file)
    321  1.1  christos     return NULL;
    322  1.1  christos 
    323  1.8  christos   return syscall_parse_xml (full_file->data (),
    324  1.8  christos 			    xml_fetch_content_from_file,
    325  1.8  christos 			    (void *) ldirname (filename).c_str ());
    326  1.1  christos }
    327  1.1  christos 
    328  1.1  christos /* Initializes the syscalls_info structure according to the
    329  1.1  christos    architecture.  */
    330  1.1  christos static void
    331  1.3  christos init_syscalls_info (struct gdbarch *gdbarch)
    332  1.1  christos {
    333  1.3  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    334  1.3  christos   const char *xml_syscall_file = gdbarch_xml_syscall_file (gdbarch);
    335  1.3  christos 
    336  1.1  christos   /* Should we re-read the XML info for this target?  */
    337  1.8  christos   if (syscalls_info != NULL && !syscalls_info->my_gdb_datadir.empty ()
    338  1.8  christos       && filename_cmp (syscalls_info->my_gdb_datadir.c_str (),
    339  1.8  christos 		       gdb_datadir) != 0)
    340  1.1  christos     {
    341  1.1  christos       /* The data-directory changed from the last time we used it.
    342  1.1  christos 	 It means that we have to re-read the XML info.  */
    343  1.8  christos       delete syscalls_info;
    344  1.3  christos       syscalls_info = NULL;
    345  1.3  christos       set_gdbarch_syscalls_info (gdbarch, NULL);
    346  1.1  christos     }
    347  1.1  christos 
    348  1.3  christos   /* Did we succeed at initializing this?  */
    349  1.3  christos   if (syscalls_info != NULL)
    350  1.1  christos     return;
    351  1.1  christos 
    352  1.3  christos   syscalls_info = xml_init_syscalls_info (xml_syscall_file);
    353  1.1  christos 
    354  1.3  christos   /* If there was some error reading the XML file, we initialize
    355  1.3  christos      gdbarch->syscalls_info anyway, in order to store information
    356  1.3  christos      about our attempt.  */
    357  1.3  christos   if (syscalls_info == NULL)
    358  1.8  christos     syscalls_info = new struct syscalls_info ();
    359  1.1  christos 
    360  1.8  christos   if (syscalls_info->syscalls.empty ())
    361  1.1  christos     {
    362  1.3  christos       if (xml_syscall_file != NULL)
    363  1.1  christos 	warning (_("Could not load the syscall XML file `%s/%s'."),
    364  1.1  christos 		 gdb_datadir, xml_syscall_file);
    365  1.1  christos       else
    366  1.1  christos 	warning (_("There is no XML file to open."));
    367  1.1  christos 
    368  1.1  christos       warning (_("GDB will not be able to display "
    369  1.1  christos 		 "syscall names nor to verify if\n"
    370  1.1  christos 		 "any provided syscall numbers are valid."));
    371  1.1  christos     }
    372  1.1  christos 
    373  1.1  christos   /* Saving the data-directory used to read this XML info.  */
    374  1.8  christos   syscalls_info->my_gdb_datadir.assign (gdb_datadir);
    375  1.3  christos 
    376  1.3  christos   set_gdbarch_syscalls_info (gdbarch, syscalls_info);
    377  1.1  christos }
    378  1.1  christos 
    379  1.6  christos /* Search for a syscall group by its name.  Return syscall_group_desc
    380  1.6  christos    structure for the group if found or NULL otherwise.  */
    381  1.6  christos 
    382  1.6  christos static struct syscall_group_desc *
    383  1.6  christos syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
    384  1.6  christos 				 const char *group)
    385  1.6  christos {
    386  1.6  christos   if (syscalls_info == NULL)
    387  1.6  christos     return NULL;
    388  1.6  christos 
    389  1.6  christos   if (group == NULL)
    390  1.6  christos     return NULL;
    391  1.6  christos 
    392  1.8  christos   /* Search for existing group.  */
    393  1.8  christos   for (const syscall_group_desc_up &groupdesc : syscalls_info->groups)
    394  1.6  christos     {
    395  1.8  christos       if (groupdesc->name == group)
    396  1.8  christos 	return groupdesc.get ();
    397  1.6  christos     }
    398  1.6  christos 
    399  1.6  christos   return NULL;
    400  1.6  christos }
    401  1.6  christos 
    402  1.8  christos static bool
    403  1.8  christos xml_get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name,
    404  1.8  christos 			  std::vector<int> *syscall_numbers)
    405  1.1  christos {
    406  1.3  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    407  1.1  christos 
    408  1.8  christos   bool found = false;
    409  1.8  christos   if (syscalls_info != NULL && syscall_name != NULL && syscall_numbers != NULL)
    410  1.8  christos     for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
    411  1.8  christos       if (sysdesc->name == syscall_name || sysdesc->alias == syscall_name)
    412  1.8  christos 	{
    413  1.8  christos 	  syscall_numbers->push_back (sysdesc->number);
    414  1.8  christos 	  found = true;
    415  1.8  christos 	}
    416  1.1  christos 
    417  1.8  christos   return found;
    418  1.1  christos }
    419  1.1  christos 
    420  1.1  christos static const char *
    421  1.3  christos xml_get_syscall_name (struct gdbarch *gdbarch,
    422  1.1  christos                       int syscall_number)
    423  1.1  christos {
    424  1.3  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    425  1.1  christos 
    426  1.3  christos   if (syscalls_info == NULL
    427  1.1  christos       || syscall_number < 0)
    428  1.1  christos     return NULL;
    429  1.1  christos 
    430  1.8  christos   for (const syscall_desc_up &sysdesc : syscalls_info->syscalls)
    431  1.1  christos     if (sysdesc->number == syscall_number)
    432  1.8  christos       return sysdesc->name.c_str ();
    433  1.1  christos 
    434  1.1  christos   return NULL;
    435  1.1  christos }
    436  1.1  christos 
    437  1.1  christos static const char **
    438  1.3  christos xml_list_of_syscalls (struct gdbarch *gdbarch)
    439  1.1  christos {
    440  1.3  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    441  1.1  christos 
    442  1.3  christos   if (syscalls_info == NULL)
    443  1.1  christos     return NULL;
    444  1.1  christos 
    445  1.8  christos   int nsyscalls = syscalls_info->syscalls.size ();
    446  1.8  christos   const char **names = XNEWVEC (const char *, nsyscalls + 1);
    447  1.1  christos 
    448  1.8  christos   int i;
    449  1.8  christos   for (i = 0; i < syscalls_info->syscalls.size (); i++)
    450  1.8  christos     names[i] = syscalls_info->syscalls[i]->name.c_str ();
    451  1.1  christos 
    452  1.1  christos   names[i] = NULL;
    453  1.1  christos 
    454  1.1  christos   return names;
    455  1.1  christos }
    456  1.1  christos 
    457  1.6  christos /* Iterate over the syscall_group_desc element to return a list of
    458  1.8  christos    syscalls that are part of the given group.  If the syscall group
    459  1.8  christos    doesn't exist, return false.  */
    460  1.6  christos 
    461  1.8  christos static bool
    462  1.8  christos xml_list_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
    463  1.8  christos 			    std::vector<int> *syscalls)
    464  1.6  christos {
    465  1.6  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    466  1.6  christos   struct syscall_group_desc *groupdesc;
    467  1.6  christos 
    468  1.8  christos   if (syscalls_info == NULL || syscalls == NULL)
    469  1.8  christos     return false;
    470  1.6  christos 
    471  1.6  christos   groupdesc = syscall_group_get_group_by_name (syscalls_info, group);
    472  1.6  christos   if (groupdesc == NULL)
    473  1.8  christos     return false;
    474  1.6  christos 
    475  1.8  christos   for (const syscall_desc *sysdesc : groupdesc->syscalls)
    476  1.8  christos     syscalls->push_back (sysdesc->number);
    477  1.6  christos 
    478  1.8  christos   return true;
    479  1.6  christos }
    480  1.6  christos 
    481  1.6  christos /* Return a NULL terminated list of syscall groups or an empty list, if
    482  1.6  christos    no syscall group is available.  Return NULL, if there is no syscall
    483  1.6  christos    information available.  */
    484  1.6  christos 
    485  1.6  christos static const char **
    486  1.6  christos xml_list_of_groups (struct gdbarch *gdbarch)
    487  1.6  christos {
    488  1.6  christos   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
    489  1.6  christos   const char **names = NULL;
    490  1.8  christos   int ngroups;
    491  1.6  christos   int i;
    492  1.6  christos 
    493  1.6  christos   if (syscalls_info == NULL)
    494  1.6  christos     return NULL;
    495  1.6  christos 
    496  1.8  christos   ngroups = syscalls_info->groups.size ();
    497  1.6  christos   names = (const char**) xmalloc ((ngroups + 1) * sizeof (char *));
    498  1.6  christos 
    499  1.8  christos   for (i = 0; i < syscalls_info->groups.size (); i++)
    500  1.8  christos     names[i] = syscalls_info->groups[i]->name.c_str ();
    501  1.6  christos 
    502  1.6  christos   names[i] = NULL;
    503  1.6  christos 
    504  1.6  christos   return names;
    505  1.6  christos }
    506  1.6  christos 
    507  1.1  christos void
    508  1.3  christos set_xml_syscall_file_name (struct gdbarch *gdbarch, const char *name)
    509  1.1  christos {
    510  1.3  christos   set_gdbarch_xml_syscall_file (gdbarch, name);
    511  1.1  christos }
    512  1.1  christos 
    513  1.1  christos void
    514  1.3  christos get_syscall_by_number (struct gdbarch *gdbarch,
    515  1.3  christos 		       int syscall_number, struct syscall *s)
    516  1.1  christos {
    517  1.3  christos   init_syscalls_info (gdbarch);
    518  1.1  christos 
    519  1.1  christos   s->number = syscall_number;
    520  1.3  christos   s->name = xml_get_syscall_name (gdbarch, syscall_number);
    521  1.1  christos }
    522  1.1  christos 
    523  1.8  christos bool
    524  1.8  christos get_syscalls_by_name (struct gdbarch *gdbarch, const char *syscall_name,
    525  1.8  christos 		      std::vector<int> *syscall_numbers)
    526  1.1  christos {
    527  1.3  christos   init_syscalls_info (gdbarch);
    528  1.1  christos 
    529  1.8  christos   return xml_get_syscalls_by_name (gdbarch, syscall_name, syscall_numbers);
    530  1.1  christos }
    531  1.1  christos 
    532  1.1  christos const char **
    533  1.3  christos get_syscall_names (struct gdbarch *gdbarch)
    534  1.1  christos {
    535  1.3  christos   init_syscalls_info (gdbarch);
    536  1.1  christos 
    537  1.3  christos   return xml_list_of_syscalls (gdbarch);
    538  1.1  christos }
    539  1.1  christos 
    540  1.6  christos /* See comment in xml-syscall.h.  */
    541  1.6  christos 
    542  1.8  christos bool
    543  1.8  christos get_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
    544  1.8  christos 		       std::vector<int> *syscall_numbers)
    545  1.6  christos {
    546  1.6  christos   init_syscalls_info (gdbarch);
    547  1.6  christos 
    548  1.8  christos   return xml_list_syscalls_by_group (gdbarch, group, syscall_numbers);
    549  1.6  christos }
    550  1.6  christos 
    551  1.6  christos /* See comment in xml-syscall.h.  */
    552  1.6  christos 
    553  1.6  christos const char **
    554  1.6  christos get_syscall_group_names (struct gdbarch *gdbarch)
    555  1.6  christos {
    556  1.6  christos   init_syscalls_info (gdbarch);
    557  1.6  christos 
    558  1.6  christos   return xml_list_of_groups (gdbarch);
    559  1.6  christos }
    560  1.6  christos 
    561  1.1  christos #endif /* ! HAVE_LIBEXPAT */
    562