1*5796c8dcSSimon Schubert /* Functions that provide the mechanism to parse a syscall XML file 2*5796c8dcSSimon Schubert and get its values. 3*5796c8dcSSimon Schubert 4*5796c8dcSSimon Schubert Copyright (C) 1986, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 5*5796c8dcSSimon Schubert 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007, 2008 6*5796c8dcSSimon Schubert Free Software Foundation, Inc. 7*5796c8dcSSimon Schubert 8*5796c8dcSSimon Schubert This file is part of GDB. 9*5796c8dcSSimon Schubert 10*5796c8dcSSimon Schubert This program is free software; you can redistribute it and/or modify 11*5796c8dcSSimon Schubert it under the terms of the GNU General Public License as published by 12*5796c8dcSSimon Schubert the Free Software Foundation; either version 3 of the License, or 13*5796c8dcSSimon Schubert (at your option) any later version. 14*5796c8dcSSimon Schubert 15*5796c8dcSSimon Schubert This program is distributed in the hope that it will be useful, 16*5796c8dcSSimon Schubert but WITHOUT ANY WARRANTY; without even the implied warranty of 17*5796c8dcSSimon Schubert MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*5796c8dcSSimon Schubert GNU General Public License for more details. 19*5796c8dcSSimon Schubert 20*5796c8dcSSimon Schubert You should have received a copy of the GNU General Public License 21*5796c8dcSSimon Schubert along with this program. If not, see <http://www.gnu.org/licenses/>. */ 22*5796c8dcSSimon Schubert 23*5796c8dcSSimon Schubert #include "defs.h" 24*5796c8dcSSimon Schubert #include "gdbtypes.h" 25*5796c8dcSSimon Schubert #include "xml-support.h" 26*5796c8dcSSimon Schubert #include "xml-syscall.h" 27*5796c8dcSSimon Schubert 28*5796c8dcSSimon Schubert /* For the struct syscall definition. */ 29*5796c8dcSSimon Schubert #include "target.h" 30*5796c8dcSSimon Schubert 31*5796c8dcSSimon Schubert #include "filenames.h" 32*5796c8dcSSimon Schubert 33*5796c8dcSSimon Schubert #include "gdb_assert.h" 34*5796c8dcSSimon Schubert 35*5796c8dcSSimon Schubert #ifndef HAVE_LIBEXPAT 36*5796c8dcSSimon Schubert 37*5796c8dcSSimon Schubert /* Dummy functions to indicate that there's no support for fetching 38*5796c8dcSSimon Schubert syscalls information. */ 39*5796c8dcSSimon Schubert 40*5796c8dcSSimon Schubert static void 41*5796c8dcSSimon Schubert syscall_warn_user (void) 42*5796c8dcSSimon Schubert { 43*5796c8dcSSimon Schubert static int have_warned = 0; 44*5796c8dcSSimon Schubert if (!have_warned) 45*5796c8dcSSimon Schubert { 46*5796c8dcSSimon Schubert have_warned = 1; 47*5796c8dcSSimon Schubert warning (_("Can not parse XML syscalls information; XML support was " 48*5796c8dcSSimon Schubert "disabled at compile time.")); 49*5796c8dcSSimon Schubert } 50*5796c8dcSSimon Schubert } 51*5796c8dcSSimon Schubert 52*5796c8dcSSimon Schubert void 53*5796c8dcSSimon Schubert set_xml_syscall_file_name (const char *name) 54*5796c8dcSSimon Schubert { 55*5796c8dcSSimon Schubert syscall_warn_user (); 56*5796c8dcSSimon Schubert } 57*5796c8dcSSimon Schubert 58*5796c8dcSSimon Schubert void 59*5796c8dcSSimon Schubert get_syscall_by_number (int syscall_number, 60*5796c8dcSSimon Schubert struct syscall *s) 61*5796c8dcSSimon Schubert { 62*5796c8dcSSimon Schubert syscall_warn_user (); 63*5796c8dcSSimon Schubert s->number = syscall_number; 64*5796c8dcSSimon Schubert s->name = NULL; 65*5796c8dcSSimon Schubert } 66*5796c8dcSSimon Schubert 67*5796c8dcSSimon Schubert void 68*5796c8dcSSimon Schubert get_syscall_by_name (const char *syscall_name, 69*5796c8dcSSimon Schubert struct syscall *s) 70*5796c8dcSSimon Schubert { 71*5796c8dcSSimon Schubert syscall_warn_user (); 72*5796c8dcSSimon Schubert s->number = UNKNOWN_SYSCALL; 73*5796c8dcSSimon Schubert s->name = syscall_name; 74*5796c8dcSSimon Schubert } 75*5796c8dcSSimon Schubert 76*5796c8dcSSimon Schubert const char ** 77*5796c8dcSSimon Schubert get_syscall_names (void) 78*5796c8dcSSimon Schubert { 79*5796c8dcSSimon Schubert syscall_warn_user (); 80*5796c8dcSSimon Schubert return NULL; 81*5796c8dcSSimon Schubert } 82*5796c8dcSSimon Schubert 83*5796c8dcSSimon Schubert 84*5796c8dcSSimon Schubert #else /* ! HAVE_LIBEXPAT */ 85*5796c8dcSSimon Schubert 86*5796c8dcSSimon Schubert /* Structure which describes a syscall. */ 87*5796c8dcSSimon Schubert typedef struct syscall_desc 88*5796c8dcSSimon Schubert { 89*5796c8dcSSimon Schubert /* The syscall number. */ 90*5796c8dcSSimon Schubert 91*5796c8dcSSimon Schubert int number; 92*5796c8dcSSimon Schubert 93*5796c8dcSSimon Schubert /* The syscall name. */ 94*5796c8dcSSimon Schubert 95*5796c8dcSSimon Schubert char *name; 96*5796c8dcSSimon Schubert } *syscall_desc_p; 97*5796c8dcSSimon Schubert DEF_VEC_P(syscall_desc_p); 98*5796c8dcSSimon Schubert 99*5796c8dcSSimon Schubert /* Structure that represents syscalls information. */ 100*5796c8dcSSimon Schubert struct syscalls_info 101*5796c8dcSSimon Schubert { 102*5796c8dcSSimon Schubert /* The syscalls. */ 103*5796c8dcSSimon Schubert 104*5796c8dcSSimon Schubert VEC(syscall_desc_p) *syscalls; 105*5796c8dcSSimon Schubert }; 106*5796c8dcSSimon Schubert 107*5796c8dcSSimon Schubert /* Callback data for syscall information parsing. */ 108*5796c8dcSSimon Schubert struct syscall_parsing_data 109*5796c8dcSSimon Schubert { 110*5796c8dcSSimon Schubert /* The syscalls_info we are building. */ 111*5796c8dcSSimon Schubert 112*5796c8dcSSimon Schubert struct syscalls_info *sysinfo; 113*5796c8dcSSimon Schubert }; 114*5796c8dcSSimon Schubert 115*5796c8dcSSimon Schubert /* Structure used to store information about the available syscalls in 116*5796c8dcSSimon Schubert the system. */ 117*5796c8dcSSimon Schubert static const struct syscalls_info *_sysinfo = NULL; 118*5796c8dcSSimon Schubert 119*5796c8dcSSimon Schubert /* A flag to tell if we already initialized the structure above. */ 120*5796c8dcSSimon Schubert static int have_initialized_sysinfo = 0; 121*5796c8dcSSimon Schubert 122*5796c8dcSSimon Schubert /* The filename of the syscall's XML. */ 123*5796c8dcSSimon Schubert static const char *xml_syscall_file = NULL; 124*5796c8dcSSimon Schubert 125*5796c8dcSSimon Schubert static struct syscalls_info * 126*5796c8dcSSimon Schubert allocate_syscalls_info (void) 127*5796c8dcSSimon Schubert { 128*5796c8dcSSimon Schubert return XZALLOC (struct syscalls_info); 129*5796c8dcSSimon Schubert } 130*5796c8dcSSimon Schubert 131*5796c8dcSSimon Schubert static void 132*5796c8dcSSimon Schubert sysinfo_free_syscalls_desc (struct syscall_desc *sd) 133*5796c8dcSSimon Schubert { 134*5796c8dcSSimon Schubert xfree (sd->name); 135*5796c8dcSSimon Schubert } 136*5796c8dcSSimon Schubert 137*5796c8dcSSimon Schubert static void 138*5796c8dcSSimon Schubert free_syscalls_info (void *arg) 139*5796c8dcSSimon Schubert { 140*5796c8dcSSimon Schubert struct syscalls_info *sysinfo = arg; 141*5796c8dcSSimon Schubert struct syscall_desc *sysdesc; 142*5796c8dcSSimon Schubert int i; 143*5796c8dcSSimon Schubert 144*5796c8dcSSimon Schubert for (i = 0; 145*5796c8dcSSimon Schubert VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc); 146*5796c8dcSSimon Schubert i++) 147*5796c8dcSSimon Schubert sysinfo_free_syscalls_desc (sysdesc); 148*5796c8dcSSimon Schubert VEC_free (syscall_desc_p, sysinfo->syscalls); 149*5796c8dcSSimon Schubert 150*5796c8dcSSimon Schubert xfree (sysinfo); 151*5796c8dcSSimon Schubert } 152*5796c8dcSSimon Schubert 153*5796c8dcSSimon Schubert struct cleanup * 154*5796c8dcSSimon Schubert make_cleanup_free_syscalls_info (struct syscalls_info *sysinfo) 155*5796c8dcSSimon Schubert { 156*5796c8dcSSimon Schubert return make_cleanup (free_syscalls_info, sysinfo); 157*5796c8dcSSimon Schubert } 158*5796c8dcSSimon Schubert 159*5796c8dcSSimon Schubert static void 160*5796c8dcSSimon Schubert syscall_create_syscall_desc (struct syscalls_info *sysinfo, 161*5796c8dcSSimon Schubert const char *name, int number) 162*5796c8dcSSimon Schubert { 163*5796c8dcSSimon Schubert struct syscall_desc *sysdesc = XZALLOC (struct syscall_desc); 164*5796c8dcSSimon Schubert 165*5796c8dcSSimon Schubert sysdesc->name = xstrdup (name); 166*5796c8dcSSimon Schubert sysdesc->number = number; 167*5796c8dcSSimon Schubert 168*5796c8dcSSimon Schubert VEC_safe_push (syscall_desc_p, sysinfo->syscalls, sysdesc); 169*5796c8dcSSimon Schubert } 170*5796c8dcSSimon Schubert 171*5796c8dcSSimon Schubert /* Handle the start of a <syscalls_info> element. */ 172*5796c8dcSSimon Schubert static void 173*5796c8dcSSimon Schubert syscall_start_syscalls_info (struct gdb_xml_parser *parser, 174*5796c8dcSSimon Schubert const struct gdb_xml_element *element, 175*5796c8dcSSimon Schubert void *user_data, 176*5796c8dcSSimon Schubert VEC(gdb_xml_value_s) *attributes) 177*5796c8dcSSimon Schubert { 178*5796c8dcSSimon Schubert struct syscall_parsing_data *data = user_data; 179*5796c8dcSSimon Schubert struct syscalls_info *sysinfo = data->sysinfo; 180*5796c8dcSSimon Schubert } 181*5796c8dcSSimon Schubert 182*5796c8dcSSimon Schubert /* Handle the start of a <syscall> element. */ 183*5796c8dcSSimon Schubert static void 184*5796c8dcSSimon Schubert syscall_start_syscall (struct gdb_xml_parser *parser, 185*5796c8dcSSimon Schubert const struct gdb_xml_element *element, 186*5796c8dcSSimon Schubert void *user_data, VEC(gdb_xml_value_s) *attributes) 187*5796c8dcSSimon Schubert { 188*5796c8dcSSimon Schubert struct syscall_parsing_data *data = user_data; 189*5796c8dcSSimon Schubert struct gdb_xml_value *attrs = VEC_address (gdb_xml_value_s, attributes); 190*5796c8dcSSimon Schubert int len, i; 191*5796c8dcSSimon Schubert /* syscall info. */ 192*5796c8dcSSimon Schubert char *name = NULL; 193*5796c8dcSSimon Schubert int number = 0; 194*5796c8dcSSimon Schubert 195*5796c8dcSSimon Schubert len = VEC_length (gdb_xml_value_s, attributes); 196*5796c8dcSSimon Schubert 197*5796c8dcSSimon Schubert for (i = 0; i < len; i++) 198*5796c8dcSSimon Schubert { 199*5796c8dcSSimon Schubert if (strcmp (attrs[i].name, "name") == 0) 200*5796c8dcSSimon Schubert name = attrs[i].value; 201*5796c8dcSSimon Schubert else if (strcmp (attrs[i].name, "number") == 0) 202*5796c8dcSSimon Schubert number = * (ULONGEST *) attrs[i].value; 203*5796c8dcSSimon Schubert else 204*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 205*5796c8dcSSimon Schubert _("Unknown attribute name '%s'."), attrs[i].name); 206*5796c8dcSSimon Schubert } 207*5796c8dcSSimon Schubert 208*5796c8dcSSimon Schubert syscall_create_syscall_desc (data->sysinfo, name, number); 209*5796c8dcSSimon Schubert } 210*5796c8dcSSimon Schubert 211*5796c8dcSSimon Schubert 212*5796c8dcSSimon Schubert /* The elements and attributes of an XML syscall document. */ 213*5796c8dcSSimon Schubert static const struct gdb_xml_attribute syscall_attr[] = { 214*5796c8dcSSimon Schubert { "number", GDB_XML_AF_NONE, gdb_xml_parse_attr_ulongest, NULL }, 215*5796c8dcSSimon Schubert { "name", GDB_XML_AF_NONE, NULL, NULL }, 216*5796c8dcSSimon Schubert { NULL, GDB_XML_AF_NONE, NULL, NULL } 217*5796c8dcSSimon Schubert }; 218*5796c8dcSSimon Schubert 219*5796c8dcSSimon Schubert static const struct gdb_xml_element syscalls_info_children[] = { 220*5796c8dcSSimon Schubert { "syscall", syscall_attr, NULL, 221*5796c8dcSSimon Schubert GDB_XML_EF_OPTIONAL | GDB_XML_EF_REPEATABLE, 222*5796c8dcSSimon Schubert syscall_start_syscall, NULL }, 223*5796c8dcSSimon Schubert { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } 224*5796c8dcSSimon Schubert }; 225*5796c8dcSSimon Schubert 226*5796c8dcSSimon Schubert static const struct gdb_xml_element syselements[] = { 227*5796c8dcSSimon Schubert { "syscalls_info", NULL, syscalls_info_children, 228*5796c8dcSSimon Schubert GDB_XML_EF_NONE, syscall_start_syscalls_info, NULL }, 229*5796c8dcSSimon Schubert { NULL, NULL, NULL, GDB_XML_EF_NONE, NULL, NULL } 230*5796c8dcSSimon Schubert }; 231*5796c8dcSSimon Schubert 232*5796c8dcSSimon Schubert static struct syscalls_info * 233*5796c8dcSSimon Schubert syscall_parse_xml (const char *document, xml_fetch_another fetcher, 234*5796c8dcSSimon Schubert void *fetcher_baton) 235*5796c8dcSSimon Schubert { 236*5796c8dcSSimon Schubert struct cleanup *result_cleanup; 237*5796c8dcSSimon Schubert struct gdb_xml_parser *parser; 238*5796c8dcSSimon Schubert struct syscall_parsing_data data; 239*5796c8dcSSimon Schubert char *expanded_text; 240*5796c8dcSSimon Schubert int i; 241*5796c8dcSSimon Schubert 242*5796c8dcSSimon Schubert parser = gdb_xml_create_parser_and_cleanup (_("syscalls info"), 243*5796c8dcSSimon Schubert syselements, &data); 244*5796c8dcSSimon Schubert 245*5796c8dcSSimon Schubert memset (&data, 0, sizeof (struct syscall_parsing_data)); 246*5796c8dcSSimon Schubert data.sysinfo = allocate_syscalls_info (); 247*5796c8dcSSimon Schubert result_cleanup = make_cleanup_free_syscalls_info (data.sysinfo); 248*5796c8dcSSimon Schubert 249*5796c8dcSSimon Schubert if (gdb_xml_parse (parser, document) == 0) 250*5796c8dcSSimon Schubert { 251*5796c8dcSSimon Schubert /* Parsed successfully. */ 252*5796c8dcSSimon Schubert discard_cleanups (result_cleanup); 253*5796c8dcSSimon Schubert return data.sysinfo; 254*5796c8dcSSimon Schubert } 255*5796c8dcSSimon Schubert else 256*5796c8dcSSimon Schubert { 257*5796c8dcSSimon Schubert warning (_("Could not load XML syscalls info; ignoring")); 258*5796c8dcSSimon Schubert do_cleanups (result_cleanup); 259*5796c8dcSSimon Schubert return NULL; 260*5796c8dcSSimon Schubert } 261*5796c8dcSSimon Schubert } 262*5796c8dcSSimon Schubert 263*5796c8dcSSimon Schubert /* Function responsible for initializing the information 264*5796c8dcSSimon Schubert about the syscalls. It reads the XML file and fills the 265*5796c8dcSSimon Schubert struct syscalls_info with the values. 266*5796c8dcSSimon Schubert 267*5796c8dcSSimon Schubert Returns the struct syscalls_info if the file is valid, NULL otherwise. */ 268*5796c8dcSSimon Schubert static const struct syscalls_info * 269*5796c8dcSSimon Schubert xml_init_syscalls_info (const char *filename) 270*5796c8dcSSimon Schubert { 271*5796c8dcSSimon Schubert char *full_file; 272*5796c8dcSSimon Schubert char *dirname; 273*5796c8dcSSimon Schubert struct syscalls_info *sysinfo; 274*5796c8dcSSimon Schubert struct cleanup *back_to; 275*5796c8dcSSimon Schubert 276*5796c8dcSSimon Schubert full_file = xml_fetch_content_from_file (filename, gdb_datadir); 277*5796c8dcSSimon Schubert if (full_file == NULL) 278*5796c8dcSSimon Schubert { 279*5796c8dcSSimon Schubert warning (_("Could not open \"%s\""), filename); 280*5796c8dcSSimon Schubert return NULL; 281*5796c8dcSSimon Schubert } 282*5796c8dcSSimon Schubert 283*5796c8dcSSimon Schubert back_to = make_cleanup (xfree, full_file); 284*5796c8dcSSimon Schubert 285*5796c8dcSSimon Schubert dirname = ldirname (filename); 286*5796c8dcSSimon Schubert if (dirname != NULL) 287*5796c8dcSSimon Schubert make_cleanup (xfree, dirname); 288*5796c8dcSSimon Schubert 289*5796c8dcSSimon Schubert sysinfo = syscall_parse_xml (full_file, xml_fetch_content_from_file, dirname); 290*5796c8dcSSimon Schubert do_cleanups (back_to); 291*5796c8dcSSimon Schubert 292*5796c8dcSSimon Schubert return sysinfo; 293*5796c8dcSSimon Schubert } 294*5796c8dcSSimon Schubert 295*5796c8dcSSimon Schubert /* Initializes the syscalls_info structure according to the 296*5796c8dcSSimon Schubert architecture. */ 297*5796c8dcSSimon Schubert static void 298*5796c8dcSSimon Schubert init_sysinfo (void) 299*5796c8dcSSimon Schubert { 300*5796c8dcSSimon Schubert /* Did we already try to initialize the structure? */ 301*5796c8dcSSimon Schubert if (have_initialized_sysinfo) 302*5796c8dcSSimon Schubert return; 303*5796c8dcSSimon Schubert /* if (xml_syscall_file == NULL) 304*5796c8dcSSimon Schubert internal_error (__FILE__, __LINE__, 305*5796c8dcSSimon Schubert _("This architecture has not set the XML syscall file " 306*5796c8dcSSimon Schubert "name. This is a bug and should not happen; please " 307*5796c8dcSSimon Schubert "report it.")); */ 308*5796c8dcSSimon Schubert 309*5796c8dcSSimon Schubert _sysinfo = xml_init_syscalls_info (xml_syscall_file); 310*5796c8dcSSimon Schubert 311*5796c8dcSSimon Schubert have_initialized_sysinfo = 1; 312*5796c8dcSSimon Schubert 313*5796c8dcSSimon Schubert if (_sysinfo == NULL) 314*5796c8dcSSimon Schubert { 315*5796c8dcSSimon Schubert if (xml_syscall_file) 316*5796c8dcSSimon Schubert /* The initialization failed. Let's show a warning 317*5796c8dcSSimon Schubert message to the user (just this time) and leave. */ 318*5796c8dcSSimon Schubert warning (_("Could not load the syscall XML file `%s'.\n\ 319*5796c8dcSSimon Schubert GDB will not be able to display syscall names."), xml_syscall_file); 320*5796c8dcSSimon Schubert else 321*5796c8dcSSimon Schubert /* There's no file to open. Let's warn the user. */ 322*5796c8dcSSimon Schubert warning (_("There is no XML file to open.\n\ 323*5796c8dcSSimon Schubert GDB will not be able to display syscall names.")); 324*5796c8dcSSimon Schubert } 325*5796c8dcSSimon Schubert } 326*5796c8dcSSimon Schubert 327*5796c8dcSSimon Schubert static int 328*5796c8dcSSimon Schubert xml_get_syscall_number (const struct syscalls_info *sysinfo, 329*5796c8dcSSimon Schubert const char *syscall_name) 330*5796c8dcSSimon Schubert { 331*5796c8dcSSimon Schubert struct syscall_desc *sysdesc; 332*5796c8dcSSimon Schubert int i; 333*5796c8dcSSimon Schubert 334*5796c8dcSSimon Schubert if (sysinfo == NULL 335*5796c8dcSSimon Schubert || syscall_name == NULL) 336*5796c8dcSSimon Schubert return UNKNOWN_SYSCALL; 337*5796c8dcSSimon Schubert 338*5796c8dcSSimon Schubert for (i = 0; 339*5796c8dcSSimon Schubert VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc); 340*5796c8dcSSimon Schubert i++) 341*5796c8dcSSimon Schubert if (strcmp (sysdesc->name, syscall_name) == 0) 342*5796c8dcSSimon Schubert return sysdesc->number; 343*5796c8dcSSimon Schubert 344*5796c8dcSSimon Schubert return UNKNOWN_SYSCALL; 345*5796c8dcSSimon Schubert } 346*5796c8dcSSimon Schubert 347*5796c8dcSSimon Schubert static const char * 348*5796c8dcSSimon Schubert xml_get_syscall_name (const struct syscalls_info *sysinfo, 349*5796c8dcSSimon Schubert int syscall_number) 350*5796c8dcSSimon Schubert { 351*5796c8dcSSimon Schubert struct syscall_desc *sysdesc; 352*5796c8dcSSimon Schubert int i; 353*5796c8dcSSimon Schubert 354*5796c8dcSSimon Schubert if (sysinfo == NULL 355*5796c8dcSSimon Schubert || syscall_number < 0) 356*5796c8dcSSimon Schubert return NULL; 357*5796c8dcSSimon Schubert 358*5796c8dcSSimon Schubert for (i = 0; 359*5796c8dcSSimon Schubert VEC_iterate(syscall_desc_p, sysinfo->syscalls, i, sysdesc); 360*5796c8dcSSimon Schubert i++) 361*5796c8dcSSimon Schubert if (sysdesc->number == syscall_number) 362*5796c8dcSSimon Schubert return sysdesc->name; 363*5796c8dcSSimon Schubert 364*5796c8dcSSimon Schubert return NULL; 365*5796c8dcSSimon Schubert } 366*5796c8dcSSimon Schubert 367*5796c8dcSSimon Schubert static int 368*5796c8dcSSimon Schubert xml_number_of_syscalls (const struct syscalls_info *sysinfo) 369*5796c8dcSSimon Schubert { 370*5796c8dcSSimon Schubert return (sysinfo == NULL ? 0 : VEC_length (syscall_desc_p, 371*5796c8dcSSimon Schubert sysinfo->syscalls)); 372*5796c8dcSSimon Schubert } 373*5796c8dcSSimon Schubert 374*5796c8dcSSimon Schubert static const char ** 375*5796c8dcSSimon Schubert xml_list_of_syscalls (const struct syscalls_info *sysinfo) 376*5796c8dcSSimon Schubert { 377*5796c8dcSSimon Schubert struct syscall_desc *sysdesc; 378*5796c8dcSSimon Schubert const char **names = NULL; 379*5796c8dcSSimon Schubert int nsyscalls; 380*5796c8dcSSimon Schubert int i; 381*5796c8dcSSimon Schubert 382*5796c8dcSSimon Schubert if (sysinfo == NULL) 383*5796c8dcSSimon Schubert return NULL; 384*5796c8dcSSimon Schubert 385*5796c8dcSSimon Schubert nsyscalls = VEC_length (syscall_desc_p, sysinfo->syscalls); 386*5796c8dcSSimon Schubert names = xmalloc ((nsyscalls + 1) * sizeof (char *)); 387*5796c8dcSSimon Schubert 388*5796c8dcSSimon Schubert for (i = 0; 389*5796c8dcSSimon Schubert VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc); 390*5796c8dcSSimon Schubert i++) 391*5796c8dcSSimon Schubert names[i] = sysdesc->name; 392*5796c8dcSSimon Schubert 393*5796c8dcSSimon Schubert names[i] = NULL; 394*5796c8dcSSimon Schubert 395*5796c8dcSSimon Schubert return names; 396*5796c8dcSSimon Schubert } 397*5796c8dcSSimon Schubert 398*5796c8dcSSimon Schubert void 399*5796c8dcSSimon Schubert set_xml_syscall_file_name (const char *name) 400*5796c8dcSSimon Schubert { 401*5796c8dcSSimon Schubert xml_syscall_file = name; 402*5796c8dcSSimon Schubert } 403*5796c8dcSSimon Schubert 404*5796c8dcSSimon Schubert void 405*5796c8dcSSimon Schubert get_syscall_by_number (int syscall_number, 406*5796c8dcSSimon Schubert struct syscall *s) 407*5796c8dcSSimon Schubert { 408*5796c8dcSSimon Schubert init_sysinfo (); 409*5796c8dcSSimon Schubert 410*5796c8dcSSimon Schubert s->number = syscall_number; 411*5796c8dcSSimon Schubert s->name = xml_get_syscall_name (_sysinfo, syscall_number); 412*5796c8dcSSimon Schubert } 413*5796c8dcSSimon Schubert 414*5796c8dcSSimon Schubert void 415*5796c8dcSSimon Schubert get_syscall_by_name (const char *syscall_name, 416*5796c8dcSSimon Schubert struct syscall *s) 417*5796c8dcSSimon Schubert { 418*5796c8dcSSimon Schubert init_sysinfo (); 419*5796c8dcSSimon Schubert 420*5796c8dcSSimon Schubert s->number = xml_get_syscall_number (_sysinfo, syscall_name); 421*5796c8dcSSimon Schubert s->name = syscall_name; 422*5796c8dcSSimon Schubert } 423*5796c8dcSSimon Schubert 424*5796c8dcSSimon Schubert const char ** 425*5796c8dcSSimon Schubert get_syscall_names (void) 426*5796c8dcSSimon Schubert { 427*5796c8dcSSimon Schubert init_sysinfo (); 428*5796c8dcSSimon Schubert 429*5796c8dcSSimon Schubert return xml_list_of_syscalls (_sysinfo); 430*5796c8dcSSimon Schubert } 431*5796c8dcSSimon Schubert 432*5796c8dcSSimon Schubert #endif /* ! HAVE_LIBEXPAT */ 433