xref: /dragonfly/contrib/gdb-7/gdb/xml-syscall.c (revision ef5ccd6c)
15796c8dcSSimon Schubert /* Functions that provide the mechanism to parse a syscall XML file
25796c8dcSSimon Schubert    and get its values.
35796c8dcSSimon Schubert 
4*ef5ccd6cSJohn Marino    Copyright (C) 2009-2013 Free Software Foundation, Inc.
55796c8dcSSimon Schubert 
65796c8dcSSimon Schubert    This file is part of GDB.
75796c8dcSSimon Schubert 
85796c8dcSSimon Schubert    This program is free software; you can redistribute it and/or modify
95796c8dcSSimon Schubert    it under the terms of the GNU General Public License as published by
105796c8dcSSimon Schubert    the Free Software Foundation; either version 3 of the License, or
115796c8dcSSimon Schubert    (at your option) any later version.
125796c8dcSSimon Schubert 
135796c8dcSSimon Schubert    This program is distributed in the hope that it will be useful,
145796c8dcSSimon Schubert    but WITHOUT ANY WARRANTY; without even the implied warranty of
155796c8dcSSimon Schubert    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
165796c8dcSSimon Schubert    GNU General Public License for more details.
175796c8dcSSimon Schubert 
185796c8dcSSimon Schubert    You should have received a copy of the GNU General Public License
195796c8dcSSimon Schubert    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
205796c8dcSSimon Schubert 
215796c8dcSSimon Schubert #include "defs.h"
225796c8dcSSimon Schubert #include "gdbtypes.h"
235796c8dcSSimon Schubert #include "xml-support.h"
245796c8dcSSimon Schubert #include "xml-syscall.h"
255796c8dcSSimon Schubert 
265796c8dcSSimon Schubert /* For the struct syscall definition.  */
275796c8dcSSimon Schubert #include "target.h"
285796c8dcSSimon Schubert 
295796c8dcSSimon Schubert #include "filenames.h"
305796c8dcSSimon Schubert 
315796c8dcSSimon Schubert #include "gdb_assert.h"
325796c8dcSSimon Schubert 
335796c8dcSSimon Schubert #ifndef HAVE_LIBEXPAT
345796c8dcSSimon Schubert 
355796c8dcSSimon Schubert /* Dummy functions to indicate that there's no support for fetching
365796c8dcSSimon Schubert    syscalls information.  */
375796c8dcSSimon Schubert 
385796c8dcSSimon Schubert static void
syscall_warn_user(void)395796c8dcSSimon Schubert syscall_warn_user (void)
405796c8dcSSimon Schubert {
415796c8dcSSimon Schubert   static int have_warned = 0;
425796c8dcSSimon Schubert   if (!have_warned)
435796c8dcSSimon Schubert     {
445796c8dcSSimon Schubert       have_warned = 1;
455796c8dcSSimon Schubert       warning (_("Can not parse XML syscalls information; XML support was "
465796c8dcSSimon Schubert 		 "disabled at compile time."));
475796c8dcSSimon Schubert     }
485796c8dcSSimon Schubert }
495796c8dcSSimon Schubert 
505796c8dcSSimon Schubert void
set_xml_syscall_file_name(const char * name)515796c8dcSSimon Schubert set_xml_syscall_file_name (const char *name)
525796c8dcSSimon Schubert {
53cf7f2e2dSJohn Marino   return;
545796c8dcSSimon Schubert }
555796c8dcSSimon Schubert 
565796c8dcSSimon Schubert void
get_syscall_by_number(int syscall_number,struct syscall * s)575796c8dcSSimon Schubert get_syscall_by_number (int syscall_number,
585796c8dcSSimon Schubert                        struct syscall *s)
595796c8dcSSimon Schubert {
605796c8dcSSimon Schubert   syscall_warn_user ();
615796c8dcSSimon Schubert   s->number = syscall_number;
625796c8dcSSimon Schubert   s->name = NULL;
635796c8dcSSimon Schubert }
645796c8dcSSimon Schubert 
655796c8dcSSimon Schubert void
get_syscall_by_name(const char * syscall_name,struct syscall * s)665796c8dcSSimon Schubert get_syscall_by_name (const char *syscall_name,
675796c8dcSSimon Schubert                      struct syscall *s)
685796c8dcSSimon Schubert {
695796c8dcSSimon Schubert   syscall_warn_user ();
705796c8dcSSimon Schubert   s->number = UNKNOWN_SYSCALL;
715796c8dcSSimon Schubert   s->name = syscall_name;
725796c8dcSSimon Schubert }
735796c8dcSSimon Schubert 
745796c8dcSSimon Schubert const char **
get_syscall_names(void)755796c8dcSSimon Schubert get_syscall_names (void)
765796c8dcSSimon Schubert {
775796c8dcSSimon Schubert   syscall_warn_user ();
785796c8dcSSimon Schubert   return NULL;
795796c8dcSSimon Schubert }
805796c8dcSSimon Schubert 
815796c8dcSSimon Schubert #else /* ! HAVE_LIBEXPAT */
825796c8dcSSimon Schubert 
83cf7f2e2dSJohn Marino /* Variable that will hold the last known data-directory.  This is useful to
84cf7f2e2dSJohn Marino    know whether we should re-read the XML info for the target.  */
85cf7f2e2dSJohn Marino static char *my_gdb_datadir = NULL;
86cf7f2e2dSJohn Marino 
875796c8dcSSimon Schubert /* Structure which describes a syscall.  */
885796c8dcSSimon Schubert typedef struct syscall_desc
895796c8dcSSimon Schubert {
905796c8dcSSimon Schubert   /* The syscall number.  */
915796c8dcSSimon Schubert 
925796c8dcSSimon Schubert   int number;
935796c8dcSSimon Schubert 
945796c8dcSSimon Schubert   /* The syscall name.  */
955796c8dcSSimon Schubert 
965796c8dcSSimon Schubert   char *name;
975796c8dcSSimon Schubert } *syscall_desc_p;
985796c8dcSSimon Schubert DEF_VEC_P(syscall_desc_p);
995796c8dcSSimon Schubert 
1005796c8dcSSimon Schubert /* Structure that represents syscalls information.  */
1015796c8dcSSimon Schubert struct syscalls_info
1025796c8dcSSimon Schubert {
1035796c8dcSSimon Schubert   /* The syscalls.  */
1045796c8dcSSimon Schubert 
1055796c8dcSSimon Schubert   VEC(syscall_desc_p) *syscalls;
1065796c8dcSSimon Schubert };
1075796c8dcSSimon Schubert 
1085796c8dcSSimon Schubert /* Callback data for syscall information parsing.  */
1095796c8dcSSimon Schubert struct syscall_parsing_data
1105796c8dcSSimon Schubert {
1115796c8dcSSimon Schubert   /* The syscalls_info we are building.  */
1125796c8dcSSimon Schubert 
1135796c8dcSSimon Schubert   struct syscalls_info *sysinfo;
1145796c8dcSSimon Schubert };
1155796c8dcSSimon Schubert 
1165796c8dcSSimon Schubert /* Structure used to store information about the available syscalls in
1175796c8dcSSimon Schubert    the system.  */
118cf7f2e2dSJohn Marino static const struct syscalls_info *sysinfo = NULL;
1195796c8dcSSimon Schubert 
1205796c8dcSSimon Schubert /* A flag to tell if we already initialized the structure above.  */
1215796c8dcSSimon Schubert static int have_initialized_sysinfo = 0;
1225796c8dcSSimon Schubert 
1235796c8dcSSimon Schubert /* The filename of the syscall's XML.  */
1245796c8dcSSimon Schubert static const char *xml_syscall_file = NULL;
1255796c8dcSSimon Schubert 
1265796c8dcSSimon Schubert static struct syscalls_info *
allocate_syscalls_info(void)1275796c8dcSSimon Schubert allocate_syscalls_info (void)
1285796c8dcSSimon Schubert {
1295796c8dcSSimon Schubert   return XZALLOC (struct syscalls_info);
1305796c8dcSSimon Schubert }
1315796c8dcSSimon Schubert 
1325796c8dcSSimon Schubert static void
sysinfo_free_syscalls_desc(struct syscall_desc * sd)1335796c8dcSSimon Schubert sysinfo_free_syscalls_desc (struct syscall_desc *sd)
1345796c8dcSSimon Schubert {
1355796c8dcSSimon Schubert   xfree (sd->name);
1365796c8dcSSimon Schubert }
1375796c8dcSSimon Schubert 
1385796c8dcSSimon Schubert static void
free_syscalls_info(void * arg)1395796c8dcSSimon Schubert free_syscalls_info (void *arg)
1405796c8dcSSimon Schubert {
1415796c8dcSSimon Schubert   struct syscalls_info *sysinfo = arg;
1425796c8dcSSimon Schubert   struct syscall_desc *sysdesc;
1435796c8dcSSimon Schubert   int i;
1445796c8dcSSimon Schubert 
1455796c8dcSSimon Schubert   for (i = 0;
1465796c8dcSSimon Schubert        VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc);
1475796c8dcSSimon Schubert        i++)
1485796c8dcSSimon Schubert     sysinfo_free_syscalls_desc (sysdesc);
1495796c8dcSSimon Schubert   VEC_free (syscall_desc_p, sysinfo->syscalls);
1505796c8dcSSimon Schubert 
1515796c8dcSSimon Schubert   xfree (sysinfo);
1525796c8dcSSimon Schubert }
1535796c8dcSSimon Schubert 
154*ef5ccd6cSJohn Marino static struct cleanup *
make_cleanup_free_syscalls_info(struct syscalls_info * sysinfo)1555796c8dcSSimon Schubert make_cleanup_free_syscalls_info (struct syscalls_info *sysinfo)
1565796c8dcSSimon Schubert {
1575796c8dcSSimon Schubert   return make_cleanup (free_syscalls_info, sysinfo);
1585796c8dcSSimon Schubert }
1595796c8dcSSimon Schubert 
1605796c8dcSSimon Schubert static void
syscall_create_syscall_desc(struct syscalls_info * sysinfo,const char * name,int number)1615796c8dcSSimon Schubert syscall_create_syscall_desc (struct syscalls_info *sysinfo,
1625796c8dcSSimon Schubert                              const char *name, int number)
1635796c8dcSSimon Schubert {
1645796c8dcSSimon Schubert   struct syscall_desc *sysdesc = XZALLOC (struct syscall_desc);
1655796c8dcSSimon Schubert 
1665796c8dcSSimon Schubert   sysdesc->name = xstrdup (name);
1675796c8dcSSimon Schubert   sysdesc->number = number;
1685796c8dcSSimon Schubert 
1695796c8dcSSimon Schubert   VEC_safe_push (syscall_desc_p, sysinfo->syscalls, sysdesc);
1705796c8dcSSimon Schubert }
1715796c8dcSSimon Schubert 
1725796c8dcSSimon Schubert /* Handle the start of a <syscall> element.  */
1735796c8dcSSimon Schubert 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)1745796c8dcSSimon Schubert syscall_start_syscall (struct gdb_xml_parser *parser,
1755796c8dcSSimon Schubert                        const struct gdb_xml_element *element,
1765796c8dcSSimon Schubert                        void *user_data, VEC(gdb_xml_value_s) *attributes)
1775796c8dcSSimon Schubert {
1785796c8dcSSimon Schubert   struct syscall_parsing_data *data = user_data;
1795796c8dcSSimon Schubert   struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes);
1805796c8dcSSimon Schubert   int len, i;
1815796c8dcSSimon Schubert   /* syscall info.  */
1825796c8dcSSimon Schubert   char *name = NULL;
1835796c8dcSSimon Schubert   int number = 0;
1845796c8dcSSimon Schubert 
1855796c8dcSSimon Schubert   len = VEC_length (gdb_xml_value_s, attributes);
1865796c8dcSSimon Schubert 
1875796c8dcSSimon Schubert   for (i = 0; i < len; i++)
1885796c8dcSSimon Schubert     {
1895796c8dcSSimon Schubert       if (strcmp (attrs[i].name, "name") == 0)
1905796c8dcSSimon Schubert         name = attrs[i].value;
1915796c8dcSSimon Schubert       else if (strcmp (attrs[i].name, "number") == 0)
1925796c8dcSSimon Schubert         number = * (ULONGEST *) attrs[i].value;
1935796c8dcSSimon Schubert       else
1945796c8dcSSimon Schubert         internal_error (__FILE__, __LINE__,
1955796c8dcSSimon Schubert                         _("Unknown attribute name '%s'."), attrs[i].name);
1965796c8dcSSimon Schubert     }
1975796c8dcSSimon Schubert 
198c50c785cSJohn Marino   gdb_assert (name);
1995796c8dcSSimon Schubert   syscall_create_syscall_desc (data->sysinfo, name, number);
2005796c8dcSSimon Schubert }
2015796c8dcSSimon Schubert 
2025796c8dcSSimon Schubert 
2035796c8dcSSimon Schubert /* The elements and attributes of an XML syscall document.  */
2045796c8dcSSimon Schubert static const struct gdb_xml_attribute syscall_attr[] = {
2055796c8dcSSimon Schubert   { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL },
2065796c8dcSSimon Schubert   { "name", GDB_XML_AF_NONE, NULL, NULL },
2075796c8dcSSimon Schubert   { NULL, GDB_XML_AF_NONE, NULL, NULL }
2085796c8dcSSimon Schubert };
2095796c8dcSSimon Schubert 
2105796c8dcSSimon Schubert static const struct gdb_xml_element syscalls_info_children[] = {
2115796c8dcSSimon Schubert   { "syscall", syscall_attr, NULL,
2125796c8dcSSimon Schubert     GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE,
2135796c8dcSSimon Schubert     syscall_start_syscall, NULL },
2145796c8dcSSimon Schubert   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2155796c8dcSSimon Schubert };
2165796c8dcSSimon Schubert 
2175796c8dcSSimon Schubert static const struct gdb_xml_element syselements[] = {
2185796c8dcSSimon Schubert   { "syscalls_info", NULL, syscalls_info_children,
219cf7f2e2dSJohn Marino     GDB_XML_EF_NONE, NULL, NULL },
2205796c8dcSSimon Schubert   { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL }
2215796c8dcSSimon Schubert };
2225796c8dcSSimon Schubert 
2235796c8dcSSimon Schubert static struct syscalls_info *
syscall_parse_xml(const char * document,xml_fetch_another fetcher,void * fetcher_baton)2245796c8dcSSimon Schubert syscall_parse_xml (const char *document, xml_fetch_another fetcher,
2255796c8dcSSimon Schubert                    void *fetcher_baton)
2265796c8dcSSimon Schubert {
2275796c8dcSSimon Schubert   struct cleanup *result_cleanup;
2285796c8dcSSimon Schubert   struct syscall_parsing_data data;
2295796c8dcSSimon Schubert 
2305796c8dcSSimon Schubert   data.sysinfo = allocate_syscalls_info ();
2315796c8dcSSimon Schubert   result_cleanup = make_cleanup_free_syscalls_info (data.sysinfo);
2325796c8dcSSimon Schubert 
233c50c785cSJohn Marino   if (gdb_xml_parse_quick (_("syscalls info"), NULL,
234c50c785cSJohn Marino 			   syselements, document, &data) == 0)
2355796c8dcSSimon Schubert     {
2365796c8dcSSimon Schubert       /* Parsed successfully.  */
2375796c8dcSSimon Schubert       discard_cleanups (result_cleanup);
2385796c8dcSSimon Schubert       return data.sysinfo;
2395796c8dcSSimon Schubert     }
2405796c8dcSSimon Schubert   else
2415796c8dcSSimon Schubert     {
2425796c8dcSSimon Schubert       warning (_("Could not load XML syscalls info; ignoring"));
2435796c8dcSSimon Schubert       do_cleanups (result_cleanup);
2445796c8dcSSimon Schubert       return NULL;
2455796c8dcSSimon Schubert     }
2465796c8dcSSimon Schubert }
2475796c8dcSSimon Schubert 
2485796c8dcSSimon Schubert /* Function responsible for initializing the information
2495796c8dcSSimon Schubert    about the syscalls.  It reads the XML file and fills the
2505796c8dcSSimon Schubert    struct syscalls_info with the values.
2515796c8dcSSimon Schubert 
2525796c8dcSSimon Schubert    Returns the struct syscalls_info if the file is valid, NULL otherwise.  */
2535796c8dcSSimon Schubert static const struct syscalls_info *
xml_init_syscalls_info(const char * filename)2545796c8dcSSimon Schubert xml_init_syscalls_info (const char *filename)
2555796c8dcSSimon Schubert {
2565796c8dcSSimon Schubert   char *full_file;
2575796c8dcSSimon Schubert   char *dirname;
2585796c8dcSSimon Schubert   struct syscalls_info *sysinfo;
2595796c8dcSSimon Schubert   struct cleanup *back_to;
2605796c8dcSSimon Schubert 
2615796c8dcSSimon Schubert   full_file = xml_fetch_content_from_file (filename, gdb_datadir);
2625796c8dcSSimon Schubert   if (full_file == NULL)
2635796c8dcSSimon Schubert     return NULL;
2645796c8dcSSimon Schubert 
2655796c8dcSSimon Schubert   back_to = make_cleanup (xfree, full_file);
2665796c8dcSSimon Schubert 
2675796c8dcSSimon Schubert   dirname = ldirname (filename);
2685796c8dcSSimon Schubert   if (dirname != NULL)
2695796c8dcSSimon Schubert     make_cleanup (xfree, dirname);
2705796c8dcSSimon Schubert 
271c50c785cSJohn Marino   sysinfo = syscall_parse_xml (full_file,
272c50c785cSJohn Marino 			       xml_fetch_content_from_file, dirname);
2735796c8dcSSimon Schubert   do_cleanups (back_to);
2745796c8dcSSimon Schubert 
2755796c8dcSSimon Schubert   return sysinfo;
2765796c8dcSSimon Schubert }
2775796c8dcSSimon Schubert 
2785796c8dcSSimon Schubert /* Initializes the syscalls_info structure according to the
2795796c8dcSSimon Schubert    architecture.  */
2805796c8dcSSimon Schubert static void
init_sysinfo(void)2815796c8dcSSimon Schubert init_sysinfo (void)
2825796c8dcSSimon Schubert {
283cf7f2e2dSJohn Marino   /* Should we re-read the XML info for this target?  */
284c50c785cSJohn Marino   if (my_gdb_datadir && filename_cmp (my_gdb_datadir, gdb_datadir) != 0)
285cf7f2e2dSJohn Marino     {
286cf7f2e2dSJohn Marino       /* The data-directory changed from the last time we used it.
287cf7f2e2dSJohn Marino 	 It means that we have to re-read the XML info.  */
288cf7f2e2dSJohn Marino       have_initialized_sysinfo = 0;
289cf7f2e2dSJohn Marino       xfree (my_gdb_datadir);
290cf7f2e2dSJohn Marino       my_gdb_datadir = NULL;
291cf7f2e2dSJohn Marino       if (sysinfo)
292cf7f2e2dSJohn Marino 	free_syscalls_info ((void *) sysinfo);
293cf7f2e2dSJohn Marino     }
294cf7f2e2dSJohn Marino 
2955796c8dcSSimon Schubert   /* Did we already try to initialize the structure?  */
2965796c8dcSSimon Schubert   if (have_initialized_sysinfo)
2975796c8dcSSimon Schubert     return;
2985796c8dcSSimon Schubert 
299cf7f2e2dSJohn Marino   sysinfo = xml_init_syscalls_info (xml_syscall_file);
3005796c8dcSSimon Schubert 
3015796c8dcSSimon Schubert   have_initialized_sysinfo = 1;
3025796c8dcSSimon Schubert 
303cf7f2e2dSJohn Marino   if (sysinfo == NULL)
3045796c8dcSSimon Schubert     {
3055796c8dcSSimon Schubert       if (xml_syscall_file)
306c50c785cSJohn Marino 	warning (_("Could not load the syscall XML file `%s/%s'."),
307cf7f2e2dSJohn Marino 		 gdb_datadir, xml_syscall_file);
3085796c8dcSSimon Schubert       else
309c50c785cSJohn Marino 	warning (_("There is no XML file to open."));
310cf7f2e2dSJohn Marino 
311c50c785cSJohn Marino       warning (_("GDB will not be able to display "
312c50c785cSJohn Marino 		 "syscall names nor to verify if\n"
313c50c785cSJohn Marino 		 "any provided syscall numbers are valid."));
3145796c8dcSSimon Schubert     }
315cf7f2e2dSJohn Marino 
316cf7f2e2dSJohn Marino   /* Saving the data-directory used to read this XML info.  */
317cf7f2e2dSJohn Marino   my_gdb_datadir = xstrdup (gdb_datadir);
3185796c8dcSSimon Schubert }
3195796c8dcSSimon Schubert 
3205796c8dcSSimon Schubert static int
xml_get_syscall_number(const struct syscalls_info * sysinfo,const char * syscall_name)3215796c8dcSSimon Schubert xml_get_syscall_number (const struct syscalls_info *sysinfo,
3225796c8dcSSimon Schubert                         const char *syscall_name)
3235796c8dcSSimon Schubert {
3245796c8dcSSimon Schubert   struct syscall_desc *sysdesc;
3255796c8dcSSimon Schubert   int i;
3265796c8dcSSimon Schubert 
3275796c8dcSSimon Schubert   if (sysinfo == NULL
3285796c8dcSSimon Schubert       || syscall_name == NULL)
3295796c8dcSSimon Schubert     return UNKNOWN_SYSCALL;
3305796c8dcSSimon Schubert 
3315796c8dcSSimon Schubert   for (i = 0;
3325796c8dcSSimon Schubert        VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc);
3335796c8dcSSimon Schubert        i++)
3345796c8dcSSimon Schubert     if (strcmp (sysdesc->name, syscall_name) == 0)
3355796c8dcSSimon Schubert       return sysdesc->number;
3365796c8dcSSimon Schubert 
3375796c8dcSSimon Schubert   return UNKNOWN_SYSCALL;
3385796c8dcSSimon Schubert }
3395796c8dcSSimon Schubert 
3405796c8dcSSimon Schubert static const char *
xml_get_syscall_name(const struct syscalls_info * sysinfo,int syscall_number)3415796c8dcSSimon Schubert xml_get_syscall_name (const struct syscalls_info *sysinfo,
3425796c8dcSSimon Schubert                       int syscall_number)
3435796c8dcSSimon Schubert {
3445796c8dcSSimon Schubert   struct syscall_desc *sysdesc;
3455796c8dcSSimon Schubert   int i;
3465796c8dcSSimon Schubert 
3475796c8dcSSimon Schubert   if (sysinfo == NULL
3485796c8dcSSimon Schubert       || syscall_number < 0)
3495796c8dcSSimon Schubert     return NULL;
3505796c8dcSSimon Schubert 
3515796c8dcSSimon Schubert   for (i = 0;
3525796c8dcSSimon Schubert        VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc);
3535796c8dcSSimon Schubert        i++)
3545796c8dcSSimon Schubert     if (sysdesc->number == syscall_number)
3555796c8dcSSimon Schubert       return sysdesc->name;
3565796c8dcSSimon Schubert 
3575796c8dcSSimon Schubert   return NULL;
3585796c8dcSSimon Schubert }
3595796c8dcSSimon Schubert 
3605796c8dcSSimon Schubert static const char **
xml_list_of_syscalls(const struct syscalls_info * sysinfo)3615796c8dcSSimon Schubert xml_list_of_syscalls (const struct syscalls_info *sysinfo)
3625796c8dcSSimon Schubert {
3635796c8dcSSimon Schubert   struct syscall_desc *sysdesc;
3645796c8dcSSimon Schubert   const char **names = NULL;
3655796c8dcSSimon Schubert   int nsyscalls;
3665796c8dcSSimon Schubert   int i;
3675796c8dcSSimon Schubert 
3685796c8dcSSimon Schubert   if (sysinfo == NULL)
3695796c8dcSSimon Schubert     return NULL;
3705796c8dcSSimon Schubert 
3715796c8dcSSimon Schubert   nsyscalls = VEC_length (syscall_desc_p, sysinfo->syscalls);
3725796c8dcSSimon Schubert   names = xmalloc ((nsyscalls + 1) * sizeof (char *));
3735796c8dcSSimon Schubert 
3745796c8dcSSimon Schubert   for (i = 0;
3755796c8dcSSimon Schubert        VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc);
3765796c8dcSSimon Schubert        i++)
3775796c8dcSSimon Schubert     names[i] = sysdesc->name;
3785796c8dcSSimon Schubert 
3795796c8dcSSimon Schubert   names[i] = NULL;
3805796c8dcSSimon Schubert 
3815796c8dcSSimon Schubert   return names;
3825796c8dcSSimon Schubert }
3835796c8dcSSimon Schubert 
3845796c8dcSSimon Schubert void
set_xml_syscall_file_name(const char * name)3855796c8dcSSimon Schubert set_xml_syscall_file_name (const char *name)
3865796c8dcSSimon Schubert {
3875796c8dcSSimon Schubert   xml_syscall_file = name;
3885796c8dcSSimon Schubert }
3895796c8dcSSimon Schubert 
3905796c8dcSSimon Schubert void
get_syscall_by_number(int syscall_number,struct syscall * s)3915796c8dcSSimon Schubert get_syscall_by_number (int syscall_number,
3925796c8dcSSimon Schubert                        struct syscall *s)
3935796c8dcSSimon Schubert {
3945796c8dcSSimon Schubert   init_sysinfo ();
3955796c8dcSSimon Schubert 
3965796c8dcSSimon Schubert   s->number = syscall_number;
397cf7f2e2dSJohn Marino   s->name = xml_get_syscall_name (sysinfo, syscall_number);
3985796c8dcSSimon Schubert }
3995796c8dcSSimon Schubert 
4005796c8dcSSimon Schubert void
get_syscall_by_name(const char * syscall_name,struct syscall * s)4015796c8dcSSimon Schubert get_syscall_by_name (const char *syscall_name,
4025796c8dcSSimon Schubert                      struct syscall *s)
4035796c8dcSSimon Schubert {
4045796c8dcSSimon Schubert   init_sysinfo ();
4055796c8dcSSimon Schubert 
406cf7f2e2dSJohn Marino   s->number = xml_get_syscall_number (sysinfo, syscall_name);
4075796c8dcSSimon Schubert   s->name = syscall_name;
4085796c8dcSSimon Schubert }
4095796c8dcSSimon Schubert 
4105796c8dcSSimon Schubert const char **
get_syscall_names(void)4115796c8dcSSimon Schubert get_syscall_names (void)
4125796c8dcSSimon Schubert {
4135796c8dcSSimon Schubert   init_sysinfo ();
4145796c8dcSSimon Schubert 
415cf7f2e2dSJohn Marino   return xml_list_of_syscalls (sysinfo);
4165796c8dcSSimon Schubert }
4175796c8dcSSimon Schubert 
4185796c8dcSSimon Schubert #endif /* ! HAVE_LIBEXPAT */
419