public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 0/4] Catch syscall groups
@ 2014-11-02 19:36 ` Gabriel Krisman Bertazi
  2014-11-02 19:36   ` [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
                     ` (6 more replies)
  0 siblings, 7 replies; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-02 19:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

Hello,

This patch series implements the ability to catch a group of related
syscalls with the catch syscall command.  Basically, We separate
syscalls into syscall groups, such as 'network' and 'process' and let
users say something like "catch syscall group:<groupname>" to catch all
the system calls in the group at once.

For the record, I sent a RFC for this feature a few weeks ago.  It can
 be seen here
 <https://www.sourceware.org/ml/gdb-patches/2014-10/msg00130.html>.

I followed the suggestions presented on that thread, and now we are
using the prefixes "group:" and "g:" to specify group names. So, these
syntaxes are allowed:

/* Catches network and process groups.  */
$ catch syscall group:network group:process

$ catch syscall g:network g:process

Other than the usual word completion feature, this patch doesn't provide
a way to list all the groups available.  This was discussed in the RFC
but we couldn't reach a consensus about the syntax.  So, I am leaving it
to a future patch.

Right now, I created syscall groups only for the x86_64 architecture.  I
sorted the syscalls following the same scheme strace does.  I plan to
include support for other architectures as well, after getting this part
upstream.

This patch series is divided as follows: Part 1 updates the xml-syscall
interface to support the syscall group feature; Part 2 has the actual
catchpoint code; Part 3 has the updated x86_64 xml, which defines the
syscall groups for this architecture, and includes tests for this
feature on x86_64; Finally, Part 4 updates documentation and the NEWS
file.

This presented no regressions on Fedora 20 x86 and x86_64.

Gabriel Krisman Bertazi (4):
  Implemement support for groups of syscalls in the xml-syscall    
    interface.
  Add support to catch groups of syscalls.
  Create syscall groups for x86_64.
  Update documentation on catching a group of related syscalls.

 gdb/NEWS                                 |   5 +
 gdb/breakpoint.c                         | 114 ++++++++--
 gdb/doc/gdb.texinfo                      |   8 +-
 gdb/syscalls/amd64-linux.xml             | 362 +++++++++++++++----------------
 gdb/syscalls/gdb-syscalls.dtd            |   3 +-
 gdb/testsuite/gdb.base/catch-syscall.exp |  33 +++
 gdb/xml-syscall.c                        | 219 ++++++++++++++++++-
 gdb/xml-syscall.h                        |  12 +
 8 files changed, 557 insertions(+), 199 deletions(-)

-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 2/4] Add support to catch groups of syscalls.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
  2014-11-02 19:36   ` [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
@ 2014-11-02 19:36   ` Gabriel Krisman Bertazi
  2014-11-14 22:55     ` Sergio Durigan Junior
  2014-11-02 19:37   ` [PATCH 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
                     ` (4 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-02 19:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

This implements the catchpoint side.  While parsing 'catch syscall'
arguments, we verify if the argument is a syscall group and expand it to
a list of syscalls that are part of that group.

gdb/

	* breakpoint.c (catch_syscall_split_args): Verify if argument
	is a syscall group and expand it to a list of syscalls when
	creating catchpoints.
	(catch_syscall_completer): Add word completion for system call
	groups.
---
 gdb/breakpoint.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 95 insertions(+), 9 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index cab6c56..8520361 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -12111,10 +12111,40 @@ catch_syscall_split_args (char *arg)
       cur_name[i] = '\0';
       arg += i;
 
-      /* Check if the user provided a syscall name or a number.  */
+      /* Check if the user provided a syscall name, group, or a
+	 number.  */
       syscall_number = (int) strtol (cur_name, &endptr, 0);
       if (*endptr == '\0')
-	get_syscall_by_number (syscall_number, &s);
+	{
+	  get_syscall_by_number (syscall_number, &s);
+	  VEC_safe_push (int, result, s.number);
+	}
+      else if ((cur_name[0] == 'g' && cur_name[1] == ':')
+	       || strstr (cur_name, "group:") == cur_name)
+	{
+	  /* We have a syscall group.  Let's expand it into a syscall
+	     list before inserting.  */
+	  struct syscall *syscall_list;
+	  const char *group_name;
+
+	  /* Skip over "g:" and "group:" prefix strings.  */
+	  group_name = strchr (cur_name, ':') + 1;
+
+	  syscall_list = get_syscalls_by_group (group_name);
+
+	  if (syscall_list == NULL)
+	    error (_("Unknown syscall group '%s'."), group_name);
+
+	  for (i = 0; syscall_list[i].name; i++)
+	    {
+	      /* Insert each syscall that are part of the group.  No
+		 need to check if it is valid.  */
+
+	      VEC_safe_push (int, result, syscall_list[i].number);
+	    }
+
+	  xfree (syscall_list);
+	}
       else
 	{
 	  /* We have a name.  Let's check if it's valid and convert it
@@ -12126,10 +12156,11 @@ catch_syscall_split_args (char *arg)
 	       because GDB cannot do anything useful if there's no
 	       syscall number to be caught.  */
 	    error (_("Unknown syscall name '%s'."), cur_name);
-	}
 
-      /* Ok, it's valid.  */
-      VEC_safe_push (int, result, s.number);
+	  /* Ok, it's valid.  */
+
+	  VEC_safe_push (int, result, s.number);
+	}
     }
 
   discard_cleanups (cleanup);
@@ -15417,11 +15448,66 @@ static VEC (char_ptr) *
 catch_syscall_completer (struct cmd_list_element *cmd,
                          const char *text, const char *word)
 {
-  const char **list = get_syscall_names ();
-  VEC (char_ptr) *retlist
-    = (list == NULL) ? NULL : complete_on_enum (list, word, word);
+  struct cleanup *cleanups;
+  VEC (char_ptr) *group_retlist = NULL;
+  VEC (char_ptr) *syscall_retlist = NULL;
+  VEC (char_ptr) *retlist = NULL;
+  const char **group_list = NULL;
+  const char **syscall_list = NULL;
+  const char *prefix;
+  int i;
+
+  /* Completion considers ':' to be a word separator, so we use this to
+     verify whether the previous word was a group prefix.  If so, we
+     build the completion list using group names only.  */
+  for (prefix = word; prefix != text && *(prefix-1) != ' '; prefix--)
+    ;
+
+  if (strncmp (prefix, "g:", strlen ("g:")) == 0
+      || strncmp (prefix, "group:", strlen ("group:")) == 0)
+    {
+      /* Perform completion inside 'group:' namespace only.  */
+
+      group_list = get_syscall_group_names ();
+      cleanups = make_cleanup (xfree, group_list);
+      retlist = (group_list == NULL) ?
+	NULL : complete_on_enum (group_list, word, word);
+    }
+  else
+    {
+      /* Complete with both, syscall names and groups.  */
+
+      syscall_list = get_syscall_names ();
+      group_list = get_syscall_group_names ();
+      cleanups = make_cleanup (xfree, group_list);
+
+      /* Append "group:" prefix to syscall groups.  */
+      for (i = 0; group_list[i]; i++)
+	{
+	  const char *group = group_list[i];
+	  size_t str_length = (sizeof (char)
+			       *(strlen (group) + strlen ("group:") + 1));
+	  char *prefixed_group = xmalloc (str_length);
+
+	  xsnprintf (prefixed_group, str_length, "group:%s", group);
+	  group_list[i] = prefixed_group;
+
+	  make_cleanup (xfree, prefixed_group);
+	}
+
+      syscall_retlist = (syscall_list == NULL) ?
+	NULL : complete_on_enum (syscall_list, word, word);
+      group_retlist = (group_list == NULL) ?
+	NULL : complete_on_enum (group_list, word, word);
+
+      retlist = VEC_merge (char_ptr, syscall_retlist, group_retlist);
+    }
+
+  VEC_free (char_ptr, syscall_retlist);
+  VEC_free (char_ptr, group_retlist);
+  xfree (syscall_list);
+  do_cleanups (cleanups);
 
-  xfree (list);
   return retlist;
 }
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
@ 2014-11-02 19:36   ` Gabriel Krisman Bertazi
  2014-11-14 22:42     ` Sergio Durigan Junior
  2014-11-02 19:36   ` [PATCH 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
                     ` (5 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-02 19:36 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

This implements support for groups of syscalls in the xml-syscall
interface.

It is done by maintaining a list of syscall_group_desc for each syscall
group inside the syscalls_info structure.  Inside each
syscall_group_desc we have a vector of pointers to the syscalls that are
part of that group.

I also experimented with storing the group info inside each syscall_desc
element, but that wasn't very practical when dealing with syscalls that
are part of more than one group. :)

gdb/

	* syscalls/gdb-syscalls.dtd: Include group attribute to the
	syscall element.
	* xml-syscall.c (get_syscalls_by_group): New.
	(get_syscall_group_names): New.
	(struct syscall_group_desc): New structure to store group data.
	(struct syscalls_info): Include field to store the group list.
	(sysinfo_free_syscall_group_desc): New.
	(free_syscalls_info): Free group list.
	(syscall_group_create_syscall_group_desc): New.
	(syscall_group_add_syscall): New.
	(syscall_create_syscall_desc): Add syscall to its groups.
	(syscall_start_syscall): Load group attribute.
	(syscall_group_get_group_by_name): New.
	(xml_list_syscalls_by_group): New.
	(xml_list_of_groups): New.
	* xml-syscall.h (get_syscalls_by_group): Export function
	to retrieve a list of syscalls filtered by the group name.
	(get_syscall_group_names): Export function to retrieve the list
	of syscall groups.
---
 gdb/syscalls/gdb-syscalls.dtd |   3 +-
 gdb/xml-syscall.c             | 219 +++++++++++++++++++++++++++++++++++++++++-
 gdb/xml-syscall.h             |  12 +++
 3 files changed, 231 insertions(+), 3 deletions(-)

diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
index 3ad3625..b60eb74 100644
--- a/gdb/syscalls/gdb-syscalls.dtd
+++ b/gdb/syscalls/gdb-syscalls.dtd
@@ -11,4 +11,5 @@
 <!ELEMENT syscall		EMPTY>
 <!ATTLIST syscall
 	name			CDATA	#REQUIRED
-	number			CDATA	#REQUIRED>
+	number			CDATA	#REQUIRED
+	groups			CDATA	#OPTIONAL>
diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
index 3824468..06be330 100644
--- a/gdb/xml-syscall.c
+++ b/gdb/xml-syscall.c
@@ -76,6 +76,20 @@ get_syscall_names (void)
   return NULL;
 }
 
+struct syscall *
+get_syscalls_by_group (const char *group)
+{
+  syscall_warn_user ();
+  return NULL;
+}
+
+const char **
+get_syscall_group_names (void)
+{
+  syscall_warn_user ();
+  return NULL;
+}
+
 #else /* ! HAVE_LIBEXPAT */
 
 /* Variable that will hold the last known data-directory.  This is useful to
@@ -95,12 +109,29 @@ typedef struct syscall_desc
 } *syscall_desc_p;
 DEF_VEC_P(syscall_desc_p);
 
+/* Structure of a syscall group.  */
+typedef struct syscall_group_desc
+{
+  /* The group name.  */
+
+  char *name;
+
+  /* The syscalls that are part of the group.  */
+
+  VEC(syscall_desc_p) *syscalls;
+} *syscall_group_desc_p;
+DEF_VEC_P(syscall_group_desc_p);
+
 /* Structure that represents syscalls information.  */
 struct syscalls_info
 {
   /* The syscalls.  */
 
   VEC(syscall_desc_p) *syscalls;
+
+  /* The syscall groups.  */
+
+  VEC(syscall_group_desc_p) *groups;
 };
 
 /* Callback data for syscall information parsing.  */
@@ -134,17 +165,32 @@ sysinfo_free_syscalls_desc (struct syscall_desc *sd)
 }
 
 static void
+sysinfo_free_syscall_group_desc (struct syscall_group_desc *sd)
+{
+  VEC_free (syscall_desc_p, sd->syscalls);
+  xfree (sd->name);
+}
+
+static void
 free_syscalls_info (void *arg)
 {
   struct syscalls_info *sysinfo = arg;
   struct syscall_desc *sysdesc;
+  struct syscall_group_desc *groupdesc;
   int i;
 
   for (i = 0;
        VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc);
        i++)
     sysinfo_free_syscalls_desc (sysdesc);
+
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
+       i++)
+    sysinfo_free_syscall_group_desc (groupdesc);
+
   VEC_free (syscall_desc_p, sysinfo->syscalls);
+  VEC_free (syscall_group_desc_p, sysinfo->groups);
 
   xfree (sysinfo);
 }
@@ -155,15 +201,66 @@ make_cleanup_free_syscalls_info (struct syscalls_info *sysinfo)
   return make_cleanup (free_syscalls_info, sysinfo);
 }
 
+/* Create a new syscall group.  Returns a pointer to the
+   syscall_group_desc structure that represents the new group.  */
+
+static struct syscall_group_desc *
+syscall_group_create_syscall_group_desc (struct syscalls_info *sysinfo,
+					 const char *group)
+{
+  struct syscall_group_desc *groupdesc = XCNEW (struct syscall_group_desc);
+
+  groupdesc->name = xstrdup (group);
+
+  VEC_safe_push (syscall_group_desc_p, sysinfo->groups, groupdesc);
+
+  return groupdesc;
+}
+
+/* Add a syscall to a group.  If the group doesn't exist, creates
+   it.  */
+
+static void
+syscall_group_add_syscall (struct syscalls_info *sysinfo,
+			   struct syscall_desc *syscall,
+			   const char *group)
+{
+  struct syscall_group_desc *groupdesc;
+  int i;
+
+  /* Search for an existing group.  */
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
+       i++)
+    if (strcmp (groupdesc->name, group) == 0)
+      break;
+
+  if (groupdesc == NULL)
+    {
+      /* No group was found with this name.  We must create a new
+	 one.  */
+      groupdesc = syscall_group_create_syscall_group_desc (sysinfo, group);
+    }
+
+  VEC_safe_push (syscall_desc_p, groupdesc->syscalls, syscall);
+}
+
 static void
 syscall_create_syscall_desc (struct syscalls_info *sysinfo,
-                             const char *name, int number)
+			     const char *name, int number,
+			     char *groups)
 {
   struct syscall_desc *sysdesc = XCNEW (struct syscall_desc);
+  char *group;
 
   sysdesc->name = xstrdup (name);
   sysdesc->number = number;
 
+  /*  Add syscall to its groups.  */
+  if (groups != NULL)
+    for (group = strtok (groups, ","); group; group = strtok (NULL, ","))
+      syscall_group_add_syscall (sysinfo, sysdesc, group);
+
   VEC_safe_push (syscall_desc_p, sysinfo->syscalls, sysdesc);
 }
 
@@ -179,6 +276,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
   /* syscall info.  */
   char *name = NULL;
   int number = 0;
+  char *groups = NULL;
 
   len = VEC_length (gdb_xml_value_s, attributes);
 
@@ -188,13 +286,15 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
         name = attrs[i].value;
       else if (strcmp (attrs[i].name, "number") == 0)
         number = * (ULONGEST *) attrs[i].value;
+      else if (strcmp (attrs[i].name, "groups") == 0)
+        groups = attrs[i].value;
       else
         internal_error (__FILE__, __LINE__,
                         _("Unknown attribute name '%s'."), attrs[i].name);
     }
 
   gdb_assert (name);
-  syscall_create_syscall_desc (data->sysinfo, name, number);
+  syscall_create_syscall_desc (data->sysinfo, name, number, groups);
 }
 
 
@@ -202,6 +302,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
 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 },
+  { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -315,6 +416,32 @@ init_sysinfo (void)
   my_gdb_datadir = xstrdup (gdb_datadir);
 }
 
+/* Search for a syscall group by its name.  Returns syscall_group_desc
+   structure for the group if found or NULL otherwise.  */
+
+static struct syscall_group_desc *
+syscall_group_get_group_by_name (const struct syscalls_info *sysinfo,
+				 const char *group)
+{
+  struct syscall_group_desc *groupdesc;
+  int i;
+
+  if (sysinfo == NULL)
+    return NULL;
+
+  if (group == NULL)
+    return NULL;
+
+   /* Search for existing group.  */
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
+       i++)
+    if (strcmp (groupdesc->name, group) == 0)
+      return groupdesc;
+
+  return NULL;
+}
+
 static int
 xml_get_syscall_number (const struct syscalls_info *sysinfo,
                         const char *syscall_name)
@@ -379,6 +506,72 @@ xml_list_of_syscalls (const struct syscalls_info *sysinfo)
   return names;
 }
 
+/*  Iterate over the syscall_group_desc element to return a list of
+    syscalls that are part of the given group, terminated by an empty
+    element.  If the syscall group doesn't exist, returns NULL.  */
+
+static struct syscall *
+xml_list_syscalls_by_group (const struct syscalls_info *sysinfo,
+			    const char *group)
+{
+  struct syscall_group_desc *groupdesc;
+  struct syscall_desc *sysdesc;
+  struct syscall *syscalls = NULL;
+  int nsyscalls;
+  int i;
+
+  if (sysinfo == NULL)
+    return NULL;
+
+  groupdesc = syscall_group_get_group_by_name (sysinfo, group);
+  if (groupdesc == NULL)
+    return NULL;
+
+  nsyscalls = VEC_length (syscall_desc_p, groupdesc->syscalls);
+  syscalls = xmalloc ((nsyscalls + 1) * sizeof (struct syscall));
+
+  for (i = 0;
+       VEC_iterate (syscall_desc_p, groupdesc->syscalls, i, sysdesc);
+       i++)
+    {
+      syscalls[i].name = sysdesc->name;
+      syscalls[i].number = sysdesc->number;
+    }
+
+  /* Add final element marker.  */
+  syscalls[i].name = NULL;
+  syscalls[i].number = 0;
+
+  return syscalls;
+}
+
+/* Returns the list of syscall groups.  If no syscall group is
+   available, returns NULL.  */
+
+static const char **
+xml_list_of_groups (const struct syscalls_info *sysinfo)
+{
+  struct syscall_group_desc *groupdesc;
+  const char **names = NULL;
+  int i;
+  int ngroups;
+
+  if (sysinfo == NULL)
+    return NULL;
+
+  ngroups = VEC_length (syscall_group_desc_p, sysinfo->groups);
+  names = xmalloc ((ngroups + 1) * sizeof (char *));
+
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
+       i++)
+    names[i] = groupdesc->name;
+
+  names[i] = NULL;
+
+  return names;
+}
+
 void
 set_xml_syscall_file_name (const char *name)
 {
@@ -413,4 +606,26 @@ get_syscall_names (void)
   return xml_list_of_syscalls (sysinfo);
 }
 
+/* Returns a list of syscalls that are part of a group, terminated by an
+   empty element.  If group doesn't exist, returns NULL.  */
+
+struct syscall *
+get_syscalls_by_group (const char *group)
+{
+  init_sysinfo ();
+
+  return xml_list_syscalls_by_group (sysinfo, group);
+}
+
+/* Return a list of available groups.  If there are no groups available,
+   returns NULL.  */
+
+const char **
+get_syscall_group_names (void)
+{
+  init_sysinfo ();
+
+  return xml_list_of_groups (sysinfo);
+}
+
 #endif /* ! HAVE_LIBEXPAT */
diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
index dff389d..573b588 100644
--- a/gdb/xml-syscall.h
+++ b/gdb/xml-syscall.h
@@ -47,4 +47,16 @@ void get_syscall_by_name (const char *syscall_name, struct syscall *s);
 
 const char **get_syscall_names (void);
 
+/* Function used to retrieve the list of syscalls of a given group in
+   the system.  Returns a list of syscalls that are element of the
+   group, terminated by an empty element.  If group doesn't exist,
+   returns NULL.  */
+
+struct syscall *get_syscalls_by_group (const char *group);
+
+/* Function used to retrieve the list of syscall groups in the system.
+   Returns an array of strings terminated by a NULL element.  */
+
+const char **get_syscall_group_names (void);
+
 #endif /* XML_SYSCALL_H */
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
  2014-11-02 19:36   ` [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
  2014-11-02 19:36   ` [PATCH 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
@ 2014-11-02 19:37   ` Gabriel Krisman Bertazi
  2014-11-02 19:45     ` Eli Zaretskii
  2014-11-03 18:38     ` Sergio Durigan Junior
  2014-11-02 19:37   ` [PATCH 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
                     ` (3 subsequent siblings)
  6 siblings, 2 replies; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-02 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

gdb/

	* breakpoint.c (_initialize_breakpoint): Update catch syscall
	command documentation.
	* NEWS: Include section about catching groups of syscalls.

gdb/doc/

	* gdb.texinfo (Set Catchpoints): Add 'group' argument to catch
	syscall.
---
 gdb/NEWS            |  5 +++++
 gdb/breakpoint.c    | 10 +++++-----
 gdb/doc/gdb.texinfo |  8 +++++++-
 3 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index 649c29e..edea1ff 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -60,6 +60,11 @@ SGI Irix-6.x				mips-*-irix6*
 VAX running (4.2 - 4.3 Reno) BSD 	vax-*-bsd*
 VAX running Ultrix 			vax-*-ultrix*
 
+* Catch syscall catches groups of related syscalls.
+
+  Catch syscall command supports catching a group of related
+  syscalls using the 'group:' or 'g:' prefix.
+
 *** Changes in GDB 7.8
 
 * New command line options
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 8520361..9bd3519 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -16736,11 +16736,11 @@ If REGEX is given, only stop for libraries matching the regular expression."),
 		     CATCH_PERMANENT,
 		     CATCH_TEMPORARY);
   add_catch_command ("syscall", _("\
-Catch system calls by their names and/or numbers.\n\
-Arguments say which system calls to catch.  If no arguments\n\
-are given, every system call will be caught.\n\
-Arguments, if given, should be one or more system call names\n\
-(if your system supports that), or system call numbers."),
+Catch system calls by their names, groups and/or numbers.  Arguments\n\
+say which system calls to catch.  If no arguments are given, every\n\
+system call will be caught.  Arguments, if given, should be one or\n\
+more system call names (if your system supports that), system call\n\
+groups or system call numbers."),
 		     catch_syscall_command_1,
 		     catch_syscall_completer,
 		     CATCH_PERMANENT,
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 15c2908..ca16e11 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4254,7 +4254,7 @@ A call to @code{exec}.  This is currently only available for HP-UX
 and @sc{gnu}/Linux.
 
 @item syscall
-@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
+@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @var{group:groupname} @r{|} @var{g:groupname}@r{]} @dots{}
 @kindex catch syscall
 @cindex break on a system call.
 A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
@@ -4289,6 +4289,12 @@ may be useful if @value{GDBN}'s database does not have the complete
 list of syscalls on your system (e.g., because @value{GDBN} lags
 behind the OS upgrades).
 
+You may specify a group of related syscalls to be caught at once
+using the @code{group:} syntax (@code{g:} is a shorter equivalent.).
+For instance, on some platforms GDB allows you to catch all network
+related syscalls, by passing the argument @code{group:network} to
+@code{catch syscall}.
+
 The example below illustrates how this command works if you don't provide
 arguments to it:
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 3/4] Create syscall groups for x86_64.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
                     ` (2 preceding siblings ...)
  2014-11-02 19:37   ` [PATCH 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
@ 2014-11-02 19:37   ` Gabriel Krisman Bertazi
  2014-11-14 23:00     ` Sergio Durigan Junior
  2014-11-21 19:05   ` [PATCH v2 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
                     ` (2 subsequent siblings)
  6 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-02 19:37 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

This commit introduces the following syscall groups for the x86_64
architecture: memory, ipc, process, descriptor, signal and file.

Please note that the sorting of the syscalls among these several groups
follows the same structure used in strace.

This also introduces tests for catching groups of syscalls on the x86_64
architecture.

gdb/

	* syscalls/amd64-linux.xml: Add 'groups' attribute to several
	syscalls on x86_64.  Create groups memory, ipc, file,
	descriptor, process and signal.

gdb/testsuite/

	* gdb.base/catch-syscall.exp (do_syscall_tests): Add call
	to test_catch_syscall_group.
	(test_catch_syscall_group): New.
---
 gdb/syscalls/amd64-linux.xml             | 362 +++++++++++++++----------------
 gdb/testsuite/gdb.base/catch-syscall.exp |  33 +++
 2 files changed, 214 insertions(+), 181 deletions(-)

diff --git a/gdb/syscalls/amd64-linux.xml b/gdb/syscalls/amd64-linux.xml
index 6a04218..974c5b5 100644
--- a/gdb/syscalls/amd64-linux.xml
+++ b/gdb/syscalls/amd64-linux.xml
@@ -14,101 +14,101 @@
      The file mentioned above belongs to the Linux Kernel.  -->
 
 <syscalls_info>
-  <syscall name="read" number="0"/>
-  <syscall name="write" number="1"/>
-  <syscall name="open" number="2"/>
-  <syscall name="close" number="3"/>
-  <syscall name="stat" number="4"/>
-  <syscall name="fstat" number="5"/>
-  <syscall name="lstat" number="6"/>
-  <syscall name="poll" number="7"/>
-  <syscall name="lseek" number="8"/>
-  <syscall name="mmap" number="9"/>
-  <syscall name="mprotect" number="10"/>
-  <syscall name="munmap" number="11"/>
-  <syscall name="brk" number="12"/>
-  <syscall name="rt_sigaction" number="13"/>
-  <syscall name="rt_sigprocmask" number="14"/>
-  <syscall name="rt_sigreturn" number="15"/>
-  <syscall name="ioctl" number="16"/>
-  <syscall name="pread64" number="17"/>
-  <syscall name="pwrite64" number="18"/>
-  <syscall name="readv" number="19"/>
-  <syscall name="writev" number="20"/>
-  <syscall name="access" number="21"/>
-  <syscall name="pipe" number="22"/>
-  <syscall name="select" number="23"/>
+  <syscall name="read" number="0" groups="descriptor"/>
+  <syscall name="write" number="1" groups="descriptor"/>
+  <syscall name="open" number="2" groups="descriptor,file"/>
+  <syscall name="close" number="3" groups="descriptor"/>
+  <syscall name="stat" number="4" groups="file"/>
+  <syscall name="fstat" number="5" groups="descriptor"/>
+  <syscall name="lstat" number="6" groups="file"/>
+  <syscall name="poll" number="7" groups="descriptor"/>
+  <syscall name="lseek" number="8" groups="descriptor"/>
+  <syscall name="mmap" number="9" groups="descriptor,memory"/>
+  <syscall name="mprotect" number="10" groups="memory"/>
+  <syscall name="munmap" number="11" groups="memory"/>
+  <syscall name="brk" number="12" groups="memory"/>
+  <syscall name="rt_sigaction" number="13" groups="signal"/>
+  <syscall name="rt_sigprocmask" number="14" groups="signal"/>
+  <syscall name="rt_sigreturn" number="15" groups="signal"/>
+  <syscall name="ioctl" number="16" groups="descriptor"/>
+  <syscall name="pread64" number="17" groups="descriptor"/>
+  <syscall name="pwrite64" number="18" groups="descriptor"/>
+  <syscall name="readv" number="19" groups="descriptor"/>
+  <syscall name="writev" number="20" groups="descriptor"/>
+  <syscall name="access" number="21" groups="file"/>
+  <syscall name="pipe" number="22" groups="descriptor"/>
+  <syscall name="select" number="23" groups="descriptor"/>
   <syscall name="sched_yield" number="24"/>
-  <syscall name="mremap" number="25"/>
-  <syscall name="msync" number="26"/>
-  <syscall name="mincore" number="27"/>
-  <syscall name="madvise" number="28"/>
-  <syscall name="shmget" number="29"/>
-  <syscall name="shmat" number="30"/>
-  <syscall name="shmctl" number="31"/>
-  <syscall name="dup" number="32"/>
-  <syscall name="dup2" number="33"/>
-  <syscall name="pause" number="34"/>
+  <syscall name="mremap" number="25" groups="memory"/>
+  <syscall name="msync" number="26" groups="memory"/>
+  <syscall name="mincore" number="27" groups="memory"/>
+  <syscall name="madvise" number="28" groups="memory"/>
+  <syscall name="shmget" number="29" groups="ipc"/>
+  <syscall name="shmat" number="30" groups="memory,ipc"/>
+  <syscall name="shmctl" number="31" groups="ipc"/>
+  <syscall name="dup" number="32" groups="descriptor"/>
+  <syscall name="dup2" number="33" groups="descriptor"/>
+  <syscall name="pause" number="34" groups="signal"/>
   <syscall name="nanosleep" number="35"/>
   <syscall name="getitimer" number="36"/>
   <syscall name="alarm" number="37"/>
   <syscall name="setitimer" number="38"/>
   <syscall name="getpid" number="39"/>
-  <syscall name="sendfile" number="40"/>
-  <syscall name="socket" number="41"/>
-  <syscall name="connect" number="42"/>
-  <syscall name="accept" number="43"/>
-  <syscall name="sendto" number="44"/>
-  <syscall name="recvfrom" number="45"/>
-  <syscall name="sendmsg" number="46"/>
-  <syscall name="recvmsg" number="47"/>
-  <syscall name="shutdown" number="48"/>
-  <syscall name="bind" number="49"/>
-  <syscall name="listen" number="50"/>
-  <syscall name="getsockname" number="51"/>
-  <syscall name="getpeername" number="52"/>
-  <syscall name="socketpair" number="53"/>
-  <syscall name="setsockopt" number="54"/>
-  <syscall name="getsockopt" number="55"/>
-  <syscall name="clone" number="56"/>
-  <syscall name="fork" number="57"/>
-  <syscall name="vfork" number="58"/>
-  <syscall name="execve" number="59"/>
-  <syscall name="exit" number="60"/>
-  <syscall name="wait4" number="61"/>
-  <syscall name="kill" number="62"/>
+  <syscall name="sendfile" number="40" groups="network,descriptor"/>
+  <syscall name="socket" number="41" groups="network"/>
+  <syscall name="connect" number="42" groups="network"/>
+  <syscall name="accept" number="43" groups="network"/>
+  <syscall name="sendto" number="44" groups="network"/>
+  <syscall name="recvfrom" number="45" groups="network"/>
+  <syscall name="sendmsg" number="46" groups="network"/>
+  <syscall name="recvmsg" number="47" groups="network"/>
+  <syscall name="shutdown" number="48" groups="network"/>
+  <syscall name="bind" number="49" groups="network"/>
+  <syscall name="listen" number="50" groups="network"/>
+  <syscall name="getsockname" number="51" groups="network"/>
+  <syscall name="getpeername" number="52" groups="network"/>
+  <syscall name="socketpair" number="53" groups="network"/>
+  <syscall name="setsockopt" number="54" groups="network"/>
+  <syscall name="getsockopt" number="55" groups="network"/>
+  <syscall name="clone" number="56" groups="process"/>
+  <syscall name="fork" number="57" groups="process"/>
+  <syscall name="vfork" number="58" groups="process"/>
+  <syscall name="execve" number="59" groups="process,file"/>
+  <syscall name="exit" number="60" groups="process"/>
+  <syscall name="wait4" number="61" groups="process"/>
+  <syscall name="kill" number="62" groups="signal"/>
   <syscall name="uname" number="63"/>
-  <syscall name="semget" number="64"/>
-  <syscall name="semop" number="65"/>
-  <syscall name="semctl" number="66"/>
-  <syscall name="shmdt" number="67"/>
-  <syscall name="msgget" number="68"/>
-  <syscall name="msgsnd" number="69"/>
-  <syscall name="msgrcv" number="70"/>
-  <syscall name="msgctl" number="71"/>
-  <syscall name="fcntl" number="72"/>
-  <syscall name="flock" number="73"/>
-  <syscall name="fsync" number="74"/>
-  <syscall name="fdatasync" number="75"/>
-  <syscall name="truncate" number="76"/>
-  <syscall name="ftruncate" number="77"/>
-  <syscall name="getdents" number="78"/>
-  <syscall name="getcwd" number="79"/>
-  <syscall name="chdir" number="80"/>
-  <syscall name="fchdir" number="81"/>
-  <syscall name="rename" number="82"/>
-  <syscall name="mkdir" number="83"/>
-  <syscall name="rmdir" number="84"/>
-  <syscall name="creat" number="85"/>
-  <syscall name="link" number="86"/>
-  <syscall name="unlink" number="87"/>
-  <syscall name="symlink" number="88"/>
-  <syscall name="readlink" number="89"/>
-  <syscall name="chmod" number="90"/>
-  <syscall name="fchmod" number="91"/>
-  <syscall name="chown" number="92"/>
-  <syscall name="fchown" number="93"/>
-  <syscall name="lchown" number="94"/>
+  <syscall name="semget" number="64" groups="ipc"/>
+  <syscall name="semop" number="65" groups="ipc"/>
+  <syscall name="semctl" number="66" groups="ipc"/>
+  <syscall name="shmdt" number="67" groups="memory,ipc"/>
+  <syscall name="msgget" number="68" groups="ipc"/>
+  <syscall name="msgsnd" number="69" groups="ipc"/>
+  <syscall name="msgrcv" number="70" groups="ipc"/>
+  <syscall name="msgctl" number="71" groups="ipc"/>
+  <syscall name="fcntl" number="72" groups="descriptor"/>
+  <syscall name="flock" number="73" groups="descriptor"/>
+  <syscall name="fsync" number="74" groups="descriptor"/>
+  <syscall name="fdatasync" number="75" groups="descriptor"/>
+  <syscall name="truncate" number="76" groups="file"/>
+  <syscall name="ftruncate" number="77" groups="descriptor"/>
+  <syscall name="getdents" number="78" groups="descriptor"/>
+  <syscall name="getcwd" number="79" groups="file"/>
+  <syscall name="chdir" number="80" groups="file"/>
+  <syscall name="fchdir" number="81" groups="descriptor"/>
+  <syscall name="rename" number="82" groups="file"/>
+  <syscall name="mkdir" number="83" groups="file"/>
+  <syscall name="rmdir" number="84" groups="file"/>
+  <syscall name="creat" number="85" groups="file,descriptor"/>
+  <syscall name="link" number="86" groups="file"/>
+  <syscall name="unlink" number="87" groups="file"/>
+  <syscall name="symlink" number="88" groups="file"/>
+  <syscall name="readlink" number="89" groups="file"/>
+  <syscall name="chmod" number="90" groups="file"/>
+  <syscall name="fchmod" number="91" groups="descriptor"/>
+  <syscall name="chown" number="92" groups="file"/>
+  <syscall name="fchown" number="93" groups="descriptor"/>
+  <syscall name="lchown" number="94" groups="file"/>
   <syscall name="umask" number="95"/>
   <syscall name="gettimeofday" number="96"/>
   <syscall name="getrlimit" number="97"/>
@@ -141,18 +141,18 @@
   <syscall name="getsid" number="124"/>
   <syscall name="capget" number="125"/>
   <syscall name="capset" number="126"/>
-  <syscall name="rt_sigpending" number="127"/>
-  <syscall name="rt_sigtimedwait" number="128"/>
-  <syscall name="rt_sigqueueinfo" number="129"/>
-  <syscall name="rt_sigsuspend" number="130"/>
-  <syscall name="sigaltstack" number="131"/>
-  <syscall name="utime" number="132"/>
-  <syscall name="mknod" number="133"/>
-  <syscall name="uselib" number="134"/>
+  <syscall name="rt_sigpending" number="127" groups="signal"/>
+  <syscall name="rt_sigtimedwait" number="128" groups="signal"/>
+  <syscall name="rt_sigqueueinfo" number="129" groups="signal"/>
+  <syscall name="rt_sigsuspend" number="130" groups="signal"/>
+  <syscall name="sigaltstack" number="131" groups="signal"/>
+  <syscall name="utime" number="132" groups="file"/>
+  <syscall name="mknod" number="133" groups="file"/>
+  <syscall name="uselib" number="134" groups="file"/>
   <syscall name="personality" number="135"/>
   <syscall name="ustat" number="136"/>
-  <syscall name="statfs" number="137"/>
-  <syscall name="fstatfs" number="138"/>
+  <syscall name="statfs" number="137" groups="file"/>
+  <syscall name="fstatfs" number="138" groups="descriptor"/>
   <syscall name="sysfs" number="139"/>
   <syscall name="getpriority" number="140"/>
   <syscall name="setpriority" number="141"/>
@@ -163,26 +163,26 @@
   <syscall name="sched_get_priority_max" number="146"/>
   <syscall name="sched_get_priority_min" number="147"/>
   <syscall name="sched_rr_get_interval" number="148"/>
-  <syscall name="mlock" number="149"/>
-  <syscall name="munlock" number="150"/>
-  <syscall name="mlockall" number="151"/>
-  <syscall name="munlockall" number="152"/>
+  <syscall name="mlock" number="149" groups="memory"/>
+  <syscall name="munlock" number="150" groups="memory"/>
+  <syscall name="mlockall" number="151" groups="memory"/>
+  <syscall name="munlockall" number="152" groups="memory"/>
   <syscall name="vhangup" number="153"/>
   <syscall name="modify_ldt" number="154"/>
-  <syscall name="pivot_root" number="155"/>
+  <syscall name="pivot_root" number="155" groups="file"/>
   <syscall name="_sysctl" number="156"/>
   <syscall name="prctl" number="157"/>
-  <syscall name="arch_prctl" number="158"/>
+  <syscall name="arch_prctl" number="158" groups="process"/>
   <syscall name="adjtimex" number="159"/>
   <syscall name="setrlimit" number="160"/>
-  <syscall name="chroot" number="161"/>
+  <syscall name="chroot" number="161" groups="file"/>
   <syscall name="sync" number="162"/>
-  <syscall name="acct" number="163"/>
+  <syscall name="acct" number="163" groups="file"/>
   <syscall name="settimeofday" number="164"/>
-  <syscall name="mount" number="165"/>
-  <syscall name="umount2" number="166"/>
-  <syscall name="swapon" number="167"/>
-  <syscall name="swapoff" number="168"/>
+  <syscall name="mount" number="165" groups="file"/>
+  <syscall name="umount2" number="166" groups="file"/>
+  <syscall name="swapon" number="167" groups="file"/>
+  <syscall name="swapoff" number="168" groups="file"/>
   <syscall name="reboot" number="169"/>
   <syscall name="sethostname" number="170"/>
   <syscall name="setdomainname" number="171"/>
@@ -193,7 +193,7 @@
   <syscall name="delete_module" number="176"/>
   <syscall name="get_kernel_syms" number="177"/>
   <syscall name="query_module" number="178"/>
-  <syscall name="quotactl" number="179"/>
+  <syscall name="quotactl" number="179" groups="file"/>
   <syscall name="nfsservctl" number="180"/>
   <syscall name="getpmsg" number="181"/>
   <syscall name="putpmsg" number="182"/>
@@ -201,20 +201,20 @@
   <syscall name="tuxcall" number="184"/>
   <syscall name="security" number="185"/>
   <syscall name="gettid" number="186"/>
-  <syscall name="readahead" number="187"/>
-  <syscall name="setxattr" number="188"/>
-  <syscall name="lsetxattr" number="189"/>
-  <syscall name="fsetxattr" number="190"/>
-  <syscall name="getxattr" number="191"/>
-  <syscall name="lgetxattr" number="192"/>
-  <syscall name="fgetxattr" number="193"/>
-  <syscall name="listxattr" number="194"/>
-  <syscall name="llistxattr" number="195"/>
-  <syscall name="flistxattr" number="196"/>
-  <syscall name="removexattr" number="197"/>
-  <syscall name="lremovexattr" number="198"/>
-  <syscall name="fremovexattr" number="199"/>
-  <syscall name="tkill" number="200"/>
+  <syscall name="readahead" number="187" groups="descriptor"/>
+  <syscall name="setxattr" number="188" groups="file"/>
+  <syscall name="lsetxattr" number="189" groups="file"/>
+  <syscall name="fsetxattr" number="190" groups="descriptor"/>
+  <syscall name="getxattr" number="191" groups="file"/>
+  <syscall name="lgetxattr" number="192" groups="file"/>
+  <syscall name="fgetxattr" number="193" groups="descriptor"/>
+  <syscall name="listxattr" number="194" groups="file"/>
+  <syscall name="llistxattr" number="195" groups="file"/>
+  <syscall name="flistxattr" number="196" groups="descriptor"/>
+  <syscall name="removexattr" number="197" groups="file"/>
+  <syscall name="lremovexattr" number="198" groups="file"/>
+  <syscall name="fremovexattr" number="199" groups="descriptor"/>
+  <syscall name="tkill" number="200" groups="signal"/>
   <syscall name="time" number="201"/>
   <syscall name="futex" number="202"/>
   <syscall name="sched_setaffinity" number="203"/>
@@ -227,15 +227,15 @@
   <syscall name="io_cancel" number="210"/>
   <syscall name="get_thread_area" number="211"/>
   <syscall name="lookup_dcookie" number="212"/>
-  <syscall name="epoll_create" number="213"/>
+  <syscall name="epoll_create" number="213" groups="descriptor"/>
   <syscall name="epoll_ctl_old" number="214"/>
   <syscall name="epoll_wait_old" number="215"/>
-  <syscall name="remap_file_pages" number="216"/>
-  <syscall name="getdents64" number="217"/>
+  <syscall name="remap_file_pages" number="216" groups="memory"/>
+  <syscall name="getdents64" number="217" groups="descriptor"/>
   <syscall name="set_tid_address" number="218"/>
   <syscall name="restart_syscall" number="219"/>
-  <syscall name="semtimedop" number="220"/>
-  <syscall name="fadvise64" number="221"/>
+  <syscall name="semtimedop" number="220" groups="ipc"/>
+  <syscall name="fadvise64" number="221" groups="descriptor"/>
   <syscall name="timer_create" number="222"/>
   <syscall name="timer_settime" number="223"/>
   <syscall name="timer_gettime" number="224"/>
@@ -245,15 +245,15 @@
   <syscall name="clock_gettime" number="228"/>
   <syscall name="clock_getres" number="229"/>
   <syscall name="clock_nanosleep" number="230"/>
-  <syscall name="exit_group" number="231"/>
-  <syscall name="epoll_wait" number="232"/>
-  <syscall name="epoll_ctl" number="233"/>
-  <syscall name="tgkill" number="234"/>
-  <syscall name="utimes" number="235"/>
+  <syscall name="exit_group" number="231" groups="process"/>
+  <syscall name="epoll_wait" number="232" groups="descriptor"/>
+  <syscall name="epoll_ctl" number="233" groups="descriptor"/>
+  <syscall name="tgkill" number="234" groups="signal"/>
+  <syscall name="utimes" number="235" groups="file"/>
   <syscall name="vserver" number="236"/>
-  <syscall name="mbind" number="237"/>
-  <syscall name="set_mempolicy" number="238"/>
-  <syscall name="get_mempolicy" number="239"/>
+  <syscall name="mbind" number="237" groups="memory"/>
+  <syscall name="set_mempolicy" number="238" groups="memory"/>
+  <syscall name="get_mempolicy" number="239" groups="memory"/>
   <syscall name="mq_open" number="240"/>
   <syscall name="mq_unlink" number="241"/>
   <syscall name="mq_timedsend" number="242"/>
@@ -261,54 +261,54 @@
   <syscall name="mq_notify" number="244"/>
   <syscall name="mq_getsetattr" number="245"/>
   <syscall name="kexec_load" number="246"/>
-  <syscall name="waitid" number="247"/>
+  <syscall name="waitid" number="247" groups="process"/>
   <syscall name="add_key" number="248"/>
   <syscall name="request_key" number="249"/>
   <syscall name="keyctl" number="250"/>
   <syscall name="ioprio_set" number="251"/>
   <syscall name="ioprio_get" number="252"/>
-  <syscall name="inotify_init" number="253"/>
-  <syscall name="inotify_add_watch" number="254"/>
-  <syscall name="inotify_rm_watch" number="255"/>
-  <syscall name="migrate_pages" number="256"/>
-  <syscall name="openat" number="257"/>
-  <syscall name="mkdirat" number="258"/>
-  <syscall name="mknodat" number="259"/>
-  <syscall name="fchownat" number="260"/>
-  <syscall name="futimesat" number="261"/>
-  <syscall name="newfstatat" number="262"/>
-  <syscall name="unlinkat" number="263"/>
-  <syscall name="renameat" number="264"/>
-  <syscall name="linkat" number="265"/>
-  <syscall name="symlinkat" number="266"/>
-  <syscall name="readlinkat" number="267"/>
-  <syscall name="fchmodat" number="268"/>
-  <syscall name="faccessat" number="269"/>
-  <syscall name="pselect6" number="270"/>
-  <syscall name="ppoll" number="271"/>
-  <syscall name="unshare" number="272"/>
+  <syscall name="inotify_init" number="253" groups="descriptor"/>
+  <syscall name="inotify_add_watch" number="254" groups="descriptor"/>
+  <syscall name="inotify_rm_watch" number="255" groups="descriptor"/>
+  <syscall name="migrate_pages" number="256" groups="memory"/>
+  <syscall name="openat" number="257" groups="file,descriptor"/>
+  <syscall name="mkdirat" number="258" groups="file,descriptor"/>
+  <syscall name="mknodat" number="259" groups="file,descriptor"/>
+  <syscall name="fchownat" number="260" groups="file,descriptor"/>
+  <syscall name="futimesat" number="261" groups="file,descriptor"/>
+  <syscall name="newfstatat" number="262" groups="file,descriptor"/>
+  <syscall name="unlinkat" number="263" groups="file,descriptor"/>
+  <syscall name="renameat" number="264" groups="file,descriptor"/>
+  <syscall name="linkat" number="265" groups="file,descriptor"/>
+  <syscall name="symlinkat" number="266" groups="file,descriptor"/>
+  <syscall name="readlinkat" number="267" groups="file,descriptor"/>
+  <syscall name="fchmodat" number="268" groups="file,descriptor"/>
+  <syscall name="faccessat" number="269" groups="file,descriptor"/>
+  <syscall name="pselect6" number="270" groups="descriptor"/>
+  <syscall name="ppoll" number="271" groups="descriptor"/>
+  <syscall name="unshare" number="272" groups="process"/>
   <syscall name="set_robust_list" number="273"/>
   <syscall name="get_robust_list" number="274"/>
-  <syscall name="splice" number="275"/>
-  <syscall name="tee" number="276"/>
-  <syscall name="sync_file_range" number="277"/>
-  <syscall name="vmsplice" number="278"/>
-  <syscall name="move_pages" number="279"/>
-  <syscall name="utimensat" number="280"/>
-  <syscall name="epoll_pwait" number="281"/>
-  <syscall name="signalfd" number="282"/>
-  <syscall name="timerfd_create" number="283"/>
-  <syscall name="eventfd" number="284"/>
-  <syscall name="fallocate" number="285"/>
-  <syscall name="timerfd_settime" number="286"/>
-  <syscall name="timerfd_gettime" number="287"/>
-  <syscall name="accept4" number="288"/>
-  <syscall name="signalfd4" number="289"/>
-  <syscall name="eventfd2" number="290"/>
-  <syscall name="epoll_create1" number="291"/>
-  <syscall name="dup3" number="292"/>
-  <syscall name="pipe2" number="293"/>
-  <syscall name="inotify_init1" number="294"/>
-  <syscall name="preadv" number="295"/>
-  <syscall name="pwritev" number="296"/>
+  <syscall name="splice" number="275" groups="descriptor"/>
+  <syscall name="tee" number="276" groups="descriptor"/>
+  <syscall name="sync_file_range" number="277" groups="descriptor"/>
+  <syscall name="vmsplice" number="278" groups="descriptor"/>
+  <syscall name="move_pages" number="279" groups="memory"/>
+  <syscall name="utimensat" number="280" groups="file,descriptor"/>
+  <syscall name="epoll_pwait" number="281" groups="descriptor"/>
+  <syscall name="signalfd" number="282" groups="signal,descriptor"/>
+  <syscall name="timerfd_create" number="283" groups="descriptor"/>
+  <syscall name="eventfd" number="284" groups="descriptor"/>
+  <syscall name="fallocate" number="285" groups="descriptor"/>
+  <syscall name="timerfd_settime" number="286" groups="descriptor"/>
+  <syscall name="timerfd_gettime" number="287" groups="descriptor"/>
+  <syscall name="accept4" number="288" groups="network"/>
+  <syscall name="signalfd4" number="289" groups="signal,descriptor"/>
+  <syscall name="eventfd2" number="290" groups="descriptor"/>
+  <syscall name="epoll_create1" number="291" groups="descriptor"/>
+  <syscall name="dup3" number="292" groups="descriptor"/>
+  <syscall name="pipe2" number="293" groups="descriptor"/>
+  <syscall name="inotify_init1" number="294" groups="descriptor"/>
+  <syscall name="preadv" number="295" groups="descriptor"/>
+  <syscall name="pwritev" number="296" groups="descriptor"/>
 </syscalls_info>
diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index a70534c..de92735 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -275,6 +275,36 @@ proc test_catch_syscall_fail_nodatadir {} {
     }
 }
 
+proc test_catch_syscall_group {} {
+    global decimal
+
+    # Until we have syscall groups to test on other targets.
+    if { ![istarget "x86_64-*-linux*"] } then {
+	return
+    }
+    set sysnum "\\\[\[0-9\]+\\\]"
+
+    gdb_test "catch syscall g:process" \
+	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \
+	"set catchpoint on a group of syscalls"
+
+    gdb_test "catch syscall g:process read" \
+	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \
+	"set catchpoints on a group of syscalls and on a single syscall"
+
+    gdb_test "complete catch syscall g:proc" \
+	"catch syscall g:process" \
+	"complete catch syscall group with 'g:' prefix"
+
+    gdb_test "complete catch syscall group:proc" \
+	"catch syscall group:process" \
+	"complete catch syscall group with 'group:' prefix"
+
+    gdb_test "complete catch syscall g" \
+	".*group:process.*" \
+	"complete catch syscall group suggests 'group:' prefix"
+}
+
 proc do_syscall_tests {} {
     # NOTE: We don't have to point gdb at the correct data-directory.
     # For the build tree that is handled by INTERNAL_GDBFLAGS.
@@ -311,6 +341,9 @@ proc do_syscall_tests {} {
     # Testing the 'catch' syscall command during a restart of
     # the inferior.
     if [runto_main] then { test_catch_syscall_restarting_inferior }
+
+    # Testing the 'catch' syscall command for a group of syscalls.
+    if [runto_main] then { test_catch_syscall_group }
 }
 
 proc test_catch_syscall_without_args_noxml {} {
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-02 19:37   ` [PATCH 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
@ 2014-11-02 19:45     ` Eli Zaretskii
  2014-11-12  2:04       ` Gabriel Krisman Bertazi
  2014-11-03 18:38     ` Sergio Durigan Junior
  1 sibling, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2014-11-02 19:45 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches, gabriel

> From: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Cc: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Date: Sun,  2 Nov 2014 17:35:44 -0200
> 
> diff --git a/gdb/NEWS b/gdb/NEWS
> index 649c29e..edea1ff 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS

This part is OK.

>  @item syscall
> -@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
> +@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @var{group:groupname} @r{|} @var{g:groupname}@r{]} @dots{}

Only "groupname" should be in @var, the "g:" and "group:" prefixes are
literal strings, so they should be in @r{}, like the brackets.

> +You may specify a group of related syscalls to be caught at once
> +using the @code{group:} syntax (@code{g:} is a shorter equivalent.).
> +For instance, on some platforms GDB allows you to catch all network
                                   ^^^
"@value{GDBN}"

> +related syscalls, by passing the argument @code{group:network} to
> +@code{catch syscall}.

How does one know which groups, if any, exist?

Thanks.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-02 19:37   ` [PATCH 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
  2014-11-02 19:45     ` Eli Zaretskii
@ 2014-11-03 18:38     ` Sergio Durigan Junior
  1 sibling, 0 replies; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-03 18:38 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:

> diff --git a/gdb/NEWS b/gdb/NEWS
> index 649c29e..edea1ff 100644
> --- a/gdb/NEWS
> +++ b/gdb/NEWS
> @@ -60,6 +60,11 @@ SGI Irix-6.x				mips-*-irix6*
>  VAX running (4.2 - 4.3 Reno) BSD 	vax-*-bsd*
>  VAX running Ultrix 			vax-*-ultrix*
>  
> +* Catch syscall catches groups of related syscalls.
> +
> +  Catch syscall command supports catching a group of related
> +  syscalls using the 'group:' or 'g:' prefix.
> +

Yay, thanks for the patch.  Almost there!

Hmm, I would prefer not to use capital letters when naming commands.
How about:

* The "catch syscall" command now supports catching groups of relates
  system calls, using the "group:" or "g:" prefixes.

?

> diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
> index 15c2908..ca16e11 100644
> --- a/gdb/doc/gdb.texinfo
> +++ b/gdb/doc/gdb.texinfo
> @@ -4254,7 +4254,7 @@ A call to @code{exec}.  This is currently only available for HP-UX
>  and @sc{gnu}/Linux.
>  
>  @item syscall
> -@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
> +@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @var{group:groupname} @r{|} @var{g:groupname}@r{]} @dots{}
>  @kindex catch syscall
>  @cindex break on a system call.
>  A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
> @@ -4289,6 +4289,12 @@ may be useful if @value{GDBN}'s database does not have the complete
>  list of syscalls on your system (e.g., because @value{GDBN} lags
>  behind the OS upgrades).
>  
> +You may specify a group of related syscalls to be caught at once
> +using the @code{group:} syntax (@code{g:} is a shorter equivalent.).
> +For instance, on some platforms GDB allows you to catch all network
> +related syscalls, by passing the argument @code{group:network} to
> +@code{catch syscall}.
> +

Aside from Eli's comments, I would really like to see an example of how
to use this feature in the manual.

Thanks,

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-02 19:45     ` Eli Zaretskii
@ 2014-11-12  2:04       ` Gabriel Krisman Bertazi
  2014-11-12  3:48         ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-12  2:04 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 967 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Gabriel Krisman Bertazi <gabriel@krisman.be>
>> Cc: Gabriel Krisman Bertazi <gabriel@krisman.be>
>> Date: Sun,  2 Nov 2014 17:35:44 -0200
>> 
>> diff --git a/gdb/NEWS b/gdb/NEWS
>> index 649c29e..edea1ff 100644
>> --- a/gdb/NEWS
>> +++ b/gdb/NEWS
>
> This part is OK.

Eli,

Thanks for your review.

>> +related syscalls, by passing the argument @code{group:network} to
>> +@code{catch syscall}.
>
> How does one know which groups, if any, exist?
>

Indeed, as I said in part 0, I don't provide any way to list which group
exists, other than the usual word completion.  The reason is that catch
syscall does not provide a way to list system calls and we couldn't
agree on the right syntax for this feature on the RFC I sent earlier to
this list.

Maybe I could rewrite this part of the documentation to suggest
something like "Tab is your friend". WDYT? :)

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-12  2:04       ` Gabriel Krisman Bertazi
@ 2014-11-12  3:48         ` Eli Zaretskii
  2014-11-14 18:52           ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2014-11-12  3:48 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

> From: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Cc: gdb-patches@sourceware.org
> Date: Wed, 12 Nov 2014 00:04:28 -0200
> 
> >> +related syscalls, by passing the argument @code{group:network} to
> >> +@code{catch syscall}.
> >
> > How does one know which groups, if any, exist?
> >
> 
> Indeed, as I said in part 0, I don't provide any way to list which group
> exists, other than the usual word completion.  The reason is that catch
> syscall does not provide a way to list system calls and we couldn't
> agree on the right syntax for this feature on the RFC I sent earlier to
> this list.
> 
> Maybe I could rewrite this part of the documentation to suggest
> something like "Tab is your friend". WDYT? :)

Yes, saying that TAB-completion (including M-TAB) can be used to see
the list of groups is fine with me.

Thanks.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-12  3:48         ` Eli Zaretskii
@ 2014-11-14 18:52           ` Gabriel Krisman Bertazi
  2014-11-14 20:38             ` Eli Zaretskii
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-14 18:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 488 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> Yes, saying that TAB-completion (including M-TAB) can be used to see
> the list of groups is fine with me.

Here goes a new version of this part.

What about the other parts, are they good to go? :)

Thanks!

gdb/

	* breakpoint.c (_initialize_breakpoint): Update catch syscall
	command documentation.
	* NEWS: Include section about catching groups of syscalls.

gdb/doc/

	* gdb.texinfo (Set Catchpoints): Add 'group' argument to catch
	syscall.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: doc_v3.patch --]
[-- Type: text/x-patch, Size: 3672 bytes --]

diff --git a/gdb/NEWS b/gdb/NEWS
index 649c29e..7e6f8ea 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -60,6 +60,11 @@ SGI Irix-6.x				mips-*-irix6*
 VAX running (4.2 - 4.3 Reno) BSD 	vax-*-bsd*
 VAX running Ultrix 			vax-*-ultrix*
 
+* The "catch syscall" command catches groups of related syscalls.
+
+  The "catch syscall" command now supports catching a group of related
+  syscalls using the 'group:' or 'g:' prefix.
+
 *** Changes in GDB 7.8
 
 * New command line options
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 8520361..9bd3519 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -16736,11 +16736,11 @@ If REGEX is given, only stop for libraries matching the regular expression."),
 		     CATCH_PERMANENT,
 		     CATCH_TEMPORARY);
   add_catch_command ("syscall", _("\
-Catch system calls by their names and/or numbers.\n\
-Arguments say which system calls to catch.  If no arguments\n\
-are given, every system call will be caught.\n\
-Arguments, if given, should be one or more system call names\n\
-(if your system supports that), or system call numbers."),
+Catch system calls by their names, groups and/or numbers.  Arguments\n\
+say which system calls to catch.  If no arguments are given, every\n\
+system call will be caught.  Arguments, if given, should be one or\n\
+more system call names (if your system supports that), system call\n\
+groups or system call numbers."),
 		     catch_syscall_command_1,
 		     catch_syscall_completer,
 		     CATCH_PERMANENT,
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 15c2908..83d8d64 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4254,7 +4254,7 @@ A call to @code{exec}.  This is currently only available for HP-UX
 and @sc{gnu}/Linux.
 
 @item syscall
-@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
+@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
 @kindex catch syscall
 @cindex break on a system call.
 A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
@@ -4289,6 +4289,15 @@ may be useful if @value{GDBN}'s database does not have the complete
 list of syscalls on your system (e.g., because @value{GDBN} lags
 behind the OS upgrades).
 
+You may specify a group of related syscalls to be caught at once using
+the @code{group:} syntax (@code{g:} is a shorter equivalent.).  For
+instance, on some platforms @value{GDBN} allows you to catch all
+network related syscalls, by passing the argument @code{group:network}
+to @code{catch syscall}.  Note that not all syscall groups are
+available in every system.  You can use the command completion
+facilities (@pxref{Completion,, command completion}) to list the
+syscall groups available on your environment.
+
 The example below illustrates how this command works if you don't provide
 arguments to it:
 
@@ -4345,6 +4354,23 @@ Program exited normally.
 (@value{GDBP})
 @end smallexample
 
+Here is an example of catching a syscall group:
+
+@smallexample
+(@value{GDBP}) catch syscall group:process
+Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
+'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
+'exit_group' [252] 'waitid' [284] 'unshare' [310])
+(@value{GDBP}) r
+Starting program: /tmp/catch-syscall
+
+Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
+   from /lib64/ld-linux-x86-64.so.2
+
+(@value{GDBP}) c
+Continuing.
+@end smallexample
+
 However, there can be situations when there is no corresponding name
 in XML file for that syscall number.  In this case, @value{GDBN} prints
 a warning message saying that it was not able to find the syscall name,

[-- Attachment #3: Type: text/plain, Size: 29 bytes --]


-- 
Gabriel Krisman Bertazi

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 4/4] Update documentation on catching a group of related syscalls.
  2014-11-14 18:52           ` Gabriel Krisman Bertazi
@ 2014-11-14 20:38             ` Eli Zaretskii
  0 siblings, 0 replies; 32+ messages in thread
From: Eli Zaretskii @ 2014-11-14 20:38 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

> From: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Cc: gdb-patches@sourceware.org
> Date: Fri, 14 Nov 2014 16:52:42 -0200
> 
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -16736,11 +16736,11 @@ If REGEX is given, only stop for libraries matching the regular expression."),
>  		     CATCH_PERMANENT,
>  		     CATCH_TEMPORARY);
>    add_catch_command ("syscall", _("\
> -Catch system calls by their names and/or numbers.\n\
> -Arguments say which system calls to catch.  If no arguments\n\
> -are given, every system call will be caught.\n\
> -Arguments, if given, should be one or more system call names\n\
> -(if your system supports that), or system call numbers."),
> +Catch system calls by their names, groups and/or numbers.  Arguments\n\
> +say which system calls to catch.  If no arguments are given, every\n\
> +system call will be caught.  Arguments, if given, should be one or\n\
> +more system call names (if your system supports that), system call\n\
> +groups or system call numbers."),

The first line of the doc string must be a single complete sentence
terminated by a period.  That's because some help-related commands
stop displaying at the first period.

Otherwise, these patches are OK.

Thanks.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-02 19:36   ` [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
@ 2014-11-14 22:42     ` Sergio Durigan Junior
  0 siblings, 0 replies; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-14 22:42 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:

> This implements support for groups of syscalls in the xml-syscall
> interface.
>
> It is done by maintaining a list of syscall_group_desc for each syscall
> group inside the syscalls_info structure.  Inside each
> syscall_group_desc we have a vector of pointers to the syscalls that are
> part of that group.
>
> I also experimented with storing the group info inside each syscall_desc
> element, but that wasn't very practical when dealing with syscalls that
> are part of more than one group. :)

Thanks for the patch.  It looks very good now.  I have only a few
comments, just nitpicking.

> gdb/
>
> 	* syscalls/gdb-syscalls.dtd: Include group attribute to the
> 	syscall element.
> 	* xml-syscall.c (get_syscalls_by_group): New.
> 	(get_syscall_group_names): New.
> 	(struct syscall_group_desc): New structure to store group data.
> 	(struct syscalls_info): Include field to store the group list.
> 	(sysinfo_free_syscall_group_desc): New.
> 	(free_syscalls_info): Free group list.
> 	(syscall_group_create_syscall_group_desc): New.
> 	(syscall_group_add_syscall): New.
> 	(syscall_create_syscall_desc): Add syscall to its groups.
> 	(syscall_start_syscall): Load group attribute.
> 	(syscall_group_get_group_by_name): New.
> 	(xml_list_syscalls_by_group): New.
> 	(xml_list_of_groups): New.
> 	* xml-syscall.h (get_syscalls_by_group): Export function
> 	to retrieve a list of syscalls filtered by the group name.
> 	(get_syscall_group_names): Export function to retrieve the list
> 	of syscall groups.
> ---
>  gdb/syscalls/gdb-syscalls.dtd |   3 +-
>  gdb/xml-syscall.c             | 219 +++++++++++++++++++++++++++++++++++++++++-
>  gdb/xml-syscall.h             |  12 +++
>  3 files changed, 231 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
> index 3ad3625..b60eb74 100644
> --- a/gdb/syscalls/gdb-syscalls.dtd
> +++ b/gdb/syscalls/gdb-syscalls.dtd
> @@ -11,4 +11,5 @@
>  <!ELEMENT syscall		EMPTY>
>  <!ATTLIST syscall
>  	name			CDATA	#REQUIRED
> -	number			CDATA	#REQUIRED>
> +	number			CDATA	#REQUIRED
> +	groups			CDATA	#OPTIONAL>
> diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
> index 3824468..06be330 100644
> --- a/gdb/xml-syscall.c
> +++ b/gdb/xml-syscall.c
> @@ -76,6 +76,20 @@ get_syscall_names (void)
>    return NULL;
>  }
>  
> +struct syscall *
> +get_syscalls_by_group (const char *group)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
> +const char **
> +get_syscall_group_names (void)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
>  #else /* ! HAVE_LIBEXPAT */
>  
>  /* Variable that will hold the last known data-directory.  This is useful to
> @@ -95,12 +109,29 @@ typedef struct syscall_desc
>  } *syscall_desc_p;
>  DEF_VEC_P(syscall_desc_p);
>  
> +/* Structure of a syscall group.  */
> +typedef struct syscall_group_desc
> +{
> +  /* The group name.  */
> +
> +  char *name;
> +
> +  /* The syscalls that are part of the group.  */
> +
> +  VEC(syscall_desc_p) *syscalls;
> +} *syscall_group_desc_p;
> +DEF_VEC_P(syscall_group_desc_p);
> +
>  /* Structure that represents syscalls information.  */
>  struct syscalls_info
>  {
>    /* The syscalls.  */
>  
>    VEC(syscall_desc_p) *syscalls;
> +
> +  /* The syscall groups.  */
> +
> +  VEC(syscall_group_desc_p) *groups;
>  };
>  
>  /* Callback data for syscall information parsing.  */
> @@ -134,17 +165,32 @@ sysinfo_free_syscalls_desc (struct syscall_desc *sd)
>  }
>  
>  static void
> +sysinfo_free_syscall_group_desc (struct syscall_group_desc *sd)
> +{
> +  VEC_free (syscall_desc_p, sd->syscalls);
> +  xfree (sd->name);
> +}

I know the whole xml-syscall.c file does not obey this rule, but every
new function should have a comment describing it.

> +
> +static void
>  free_syscalls_info (void *arg)
>  {
>    struct syscalls_info *sysinfo = arg;
>    struct syscall_desc *sysdesc;
> +  struct syscall_group_desc *groupdesc;
>    int i;
>  
>    for (i = 0;
>         VEC_iterate (syscall_desc_p, sysinfo->syscalls, i, sysdesc);
>         i++)
>      sysinfo_free_syscalls_desc (sysdesc);
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
> +       i++)
> +    sysinfo_free_syscall_group_desc (groupdesc);
> +
>    VEC_free (syscall_desc_p, sysinfo->syscalls);
> +  VEC_free (syscall_group_desc_p, sysinfo->groups);
>  
>    xfree (sysinfo);
>  }
> @@ -155,15 +201,66 @@ make_cleanup_free_syscalls_info (struct syscalls_info *sysinfo)
>    return make_cleanup (free_syscalls_info, sysinfo);
>  }
>  
> +/* Create a new syscall group.  Returns a pointer to the
> +   syscall_group_desc structure that represents the new group.  */

It is annoying, but we try to write comments using the imperative
language.  Therefore, we use "Return a pointer..." instead of "Returns a
pointer...".  Anyway, this is just a very minor nit, but I myself was
corrected about it before :-).

> +
> +static struct syscall_group_desc *
> +syscall_group_create_syscall_group_desc (struct syscalls_info *sysinfo,
> +					 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc = XCNEW (struct syscall_group_desc);
> +
> +  groupdesc->name = xstrdup (group);
> +
> +  VEC_safe_push (syscall_group_desc_p, sysinfo->groups, groupdesc);
> +
> +  return groupdesc;
> +}
> +
> +/* Add a syscall to a group.  If the group doesn't exist, creates
> +   it.  */
> +
> +static void
> +syscall_group_add_syscall (struct syscalls_info *sysinfo,
> +			   struct syscall_desc *syscall,
> +			   const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  /* Search for an existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      break;
> +
> +  if (groupdesc == NULL)
> +    {
> +      /* No group was found with this name.  We must create a new
> +	 one.  */
> +      groupdesc = syscall_group_create_syscall_group_desc (sysinfo, group);
> +    }
> +
> +  VEC_safe_push (syscall_desc_p, groupdesc->syscalls, syscall);
> +}
> +
>  static void
>  syscall_create_syscall_desc (struct syscalls_info *sysinfo,
> -                             const char *name, int number)
> +			     const char *name, int number,
> +			     char *groups)
>  {
>    struct syscall_desc *sysdesc = XCNEW (struct syscall_desc);
> +  char *group;
>  
>    sysdesc->name = xstrdup (name);
>    sysdesc->number = number;
>  
> +  /*  Add syscall to its groups.  */
> +  if (groups != NULL)
> +    for (group = strtok (groups, ","); group; group = strtok (NULL, ","))

This should use explicit comparison, i.e., "group != NULL".

> +      syscall_group_add_syscall (sysinfo, sysdesc, group);
> +
>    VEC_safe_push (syscall_desc_p, sysinfo->syscalls, sysdesc);
>  }
>  
> @@ -179,6 +276,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>    /* syscall info.  */
>    char *name = NULL;
>    int number = 0;
> +  char *groups = NULL;
>  
>    len = VEC_length (gdb_xml_value_s, attributes);
>  
> @@ -188,13 +286,15 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>          name = attrs[i].value;
>        else if (strcmp (attrs[i].name, "number") == 0)
>          number = * (ULONGEST *) attrs[i].value;
> +      else if (strcmp (attrs[i].name, "groups") == 0)
> +        groups = attrs[i].value;
>        else
>          internal_error (__FILE__, __LINE__,
>                          _("Unknown attribute name '%s'."), attrs[i].name);
>      }
>  
>    gdb_assert (name);
> -  syscall_create_syscall_desc (data->sysinfo, name, number);
> +  syscall_create_syscall_desc (data->sysinfo, name, number, groups);
>  }
>  
>  
> @@ -202,6 +302,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>  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 },
> +  { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { NULL, GDB_XML_AF_NONE, NULL, NULL }
>  };
>  
> @@ -315,6 +416,32 @@ init_sysinfo (void)
>    my_gdb_datadir = xstrdup (gdb_datadir);
>  }
>  
> +/* Search for a syscall group by its name.  Returns syscall_group_desc
> +   structure for the group if found or NULL otherwise.  */
> +
> +static struct syscall_group_desc *
> +syscall_group_get_group_by_name (const struct syscalls_info *sysinfo,
> +				 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  if (sysinfo == NULL)
> +    return NULL;
> +
> +  if (group == NULL)
> +    return NULL;
> +
> +   /* Search for existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      return groupdesc;
> +
> +  return NULL;
> +}
> +
>  static int
>  xml_get_syscall_number (const struct syscalls_info *sysinfo,
>                          const char *syscall_name)
> @@ -379,6 +506,72 @@ xml_list_of_syscalls (const struct syscalls_info *sysinfo)
>    return names;
>  }
>  
> +/*  Iterate over the syscall_group_desc element to return a list of
> +    syscalls that are part of the given group, terminated by an empty
> +    element.  If the syscall group doesn't exist, returns NULL.  */
> +
> +static struct syscall *
> +xml_list_syscalls_by_group (const struct syscalls_info *sysinfo,
> +			    const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  struct syscall_desc *sysdesc;
> +  struct syscall *syscalls = NULL;
> +  int nsyscalls;
> +  int i;
> +
> +  if (sysinfo == NULL)
> +    return NULL;
> +
> +  groupdesc = syscall_group_get_group_by_name (sysinfo, group);
> +  if (groupdesc == NULL)
> +    return NULL;
> +
> +  nsyscalls = VEC_length (syscall_desc_p, groupdesc->syscalls);
> +  syscalls = xmalloc ((nsyscalls + 1) * sizeof (struct syscall));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_desc_p, groupdesc->syscalls, i, sysdesc);
> +       i++)
> +    {
> +      syscalls[i].name = sysdesc->name;
> +      syscalls[i].number = sysdesc->number;
> +    }
> +
> +  /* Add final element marker.  */
> +  syscalls[i].name = NULL;
> +  syscalls[i].number = 0;
> +
> +  return syscalls;
> +}
> +
> +/* Returns the list of syscall groups.  If no syscall group is
> +   available, returns NULL.  */
> +
> +static const char **
> +xml_list_of_groups (const struct syscalls_info *sysinfo)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  const char **names = NULL;
> +  int i;
> +  int ngroups;
> +
> +  if (sysinfo == NULL)
> +    return NULL;
> +
> +  ngroups = VEC_length (syscall_group_desc_p, sysinfo->groups);
> +  names = xmalloc ((ngroups + 1) * sizeof (char *));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p, sysinfo->groups, i, groupdesc);
> +       i++)
> +    names[i] = groupdesc->name;
> +
> +  names[i] = NULL;
> +
> +  return names;
> +}
> +
>  void
>  set_xml_syscall_file_name (const char *name)
>  {
> @@ -413,4 +606,26 @@ get_syscall_names (void)
>    return xml_list_of_syscalls (sysinfo);
>  }
>  
> +/* Returns a list of syscalls that are part of a group, terminated by an
> +   empty element.  If group doesn't exist, returns NULL.  */
> +
> +struct syscall *
> +get_syscalls_by_group (const char *group)
> +{
> +  init_sysinfo ();
> +
> +  return xml_list_syscalls_by_group (sysinfo, group);
> +}

Instead of duplicating the comment for the function here, you could say
"See comment in xml-syscall.h".

> +
> +/* Return a list of available groups.  If there are no groups available,
> +   returns NULL.  */
> +
> +const char **
> +get_syscall_group_names (void)
> +{
> +  init_sysinfo ();
> +
> +  return xml_list_of_groups (sysinfo);
> +}
> +
>  #endif /* ! HAVE_LIBEXPAT */
> diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
> index dff389d..573b588 100644
> --- a/gdb/xml-syscall.h
> +++ b/gdb/xml-syscall.h
> @@ -47,4 +47,16 @@ void get_syscall_by_name (const char *syscall_name, struct syscall *s);
>  
>  const char **get_syscall_names (void);
>  
> +/* Function used to retrieve the list of syscalls of a given group in
> +   the system.  Returns a list of syscalls that are element of the
> +   group, terminated by an empty element.  If group doesn't exist,
> +   returns NULL.  */
> +
> +struct syscall *get_syscalls_by_group (const char *group);

And here, you could explicitly mention that the list returned is
dinamically allocated and should be freed by the caller.

> +
> +/* Function used to retrieve the list of syscall groups in the system.
> +   Returns an array of strings terminated by a NULL element.  */
> +
> +const char **get_syscall_group_names (void);
> +
>  #endif /* XML_SYSCALL_H */
> -- 
> 1.9.3

Otherwise, the patch looks good to me (I am not the maintainer of this
portion of the code).

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 2/4] Add support to catch groups of syscalls.
  2014-11-02 19:36   ` [PATCH 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
@ 2014-11-14 22:55     ` Sergio Durigan Junior
  0 siblings, 0 replies; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-14 22:55 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:

> This implements the catchpoint side.  While parsing 'catch syscall'
> arguments, we verify if the argument is a syscall group and expand it to
> a list of syscalls that are part of that group.

Nice, looks good :-).  A few comments.

> gdb/
>
> 	* breakpoint.c (catch_syscall_split_args): Verify if argument
> 	is a syscall group and expand it to a list of syscalls when
> 	creating catchpoints.
> 	(catch_syscall_completer): Add word completion for system call
> 	groups.
> ---
>  gdb/breakpoint.c | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
>  1 file changed, 95 insertions(+), 9 deletions(-)
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index cab6c56..8520361 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -12111,10 +12111,40 @@ catch_syscall_split_args (char *arg)
>        cur_name[i] = '\0';
>        arg += i;
>  
> -      /* Check if the user provided a syscall name or a number.  */
> +      /* Check if the user provided a syscall name, group, or a
> +	 number.  */
>        syscall_number = (int) strtol (cur_name, &endptr, 0);
>        if (*endptr == '\0')
> -	get_syscall_by_number (syscall_number, &s);
> +	{
> +	  get_syscall_by_number (syscall_number, &s);
> +	  VEC_safe_push (int, result, s.number);
> +	}
> +      else if ((cur_name[0] == 'g' && cur_name[1] == ':')
> +	       || strstr (cur_name, "group:") == cur_name)

Here you compare chars and use strstr, and then below you use two calls
to strncmp.  I prefer if you use strncmp here as well, because it would
be simpler.

> +	{
> +	  /* We have a syscall group.  Let's expand it into a syscall
> +	     list before inserting.  */
> +	  struct syscall *syscall_list;
> +	  const char *group_name;
> +
> +	  /* Skip over "g:" and "group:" prefix strings.  */
> +	  group_name = strchr (cur_name, ':') + 1;
> +
> +	  syscall_list = get_syscalls_by_group (group_name);
> +
> +	  if (syscall_list == NULL)
> +	    error (_("Unknown syscall group '%s'."), group_name);
> +
> +	  for (i = 0; syscall_list[i].name; i++)

Explicit comparison:

  syscall_list[i].name != NULL

> +	    {
> +	      /* Insert each syscall that are part of the group.  No
> +		 need to check if it is valid.  */
> +
> +	      VEC_safe_push (int, result, syscall_list[i].number);

I prefer without the extra newline separating the comment and the code.
Likewise for everywhere else you did this ;-).

> +	    }
> +
> +	  xfree (syscall_list);
> +	}
>        else
>  	{
>  	  /* We have a name.  Let's check if it's valid and convert it
> @@ -12126,10 +12156,11 @@ catch_syscall_split_args (char *arg)
>  	       because GDB cannot do anything useful if there's no
>  	       syscall number to be caught.  */
>  	    error (_("Unknown syscall name '%s'."), cur_name);
> -	}
>  
> -      /* Ok, it's valid.  */
> -      VEC_safe_push (int, result, s.number);
> +	  /* Ok, it's valid.  */
> +
> +	  VEC_safe_push (int, result, s.number);
> +	}
>      }
>  
>    discard_cleanups (cleanup);
> @@ -15417,11 +15448,66 @@ static VEC (char_ptr) *
>  catch_syscall_completer (struct cmd_list_element *cmd,
>                           const char *text, const char *word)
>  {
> -  const char **list = get_syscall_names ();
> -  VEC (char_ptr) *retlist
> -    = (list == NULL) ? NULL : complete_on_enum (list, word, word);
> +  struct cleanup *cleanups;
> +  VEC (char_ptr) *group_retlist = NULL;
> +  VEC (char_ptr) *syscall_retlist = NULL;
> +  VEC (char_ptr) *retlist = NULL;
> +  const char **group_list = NULL;
> +  const char **syscall_list = NULL;
> +  const char *prefix;
> +  int i;
> +
> +  /* Completion considers ':' to be a word separator, so we use this to
> +     verify whether the previous word was a group prefix.  If so, we
> +     build the completion list using group names only.  */
> +  for (prefix = word; prefix != text && *(prefix-1) != ' '; prefix--)

You can use prefix[-1] instead of *(prefix-1) here.  But if you decide
to the latter, then you should write *(prefix - 1).

> +    ;
> +
> +  if (strncmp (prefix, "g:", strlen ("g:")) == 0
> +      || strncmp (prefix, "group:", strlen ("group:")) == 0)
> +    {
> +      /* Perform completion inside 'group:' namespace only.  */
> +
> +      group_list = get_syscall_group_names ();
> +      cleanups = make_cleanup (xfree, group_list);
> +      retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);
> +    }
> +  else
> +    {
> +      /* Complete with both, syscall names and groups.  */
> +
> +      syscall_list = get_syscall_names ();
> +      group_list = get_syscall_group_names ();
> +      cleanups = make_cleanup (xfree, group_list);
> +
> +      /* Append "group:" prefix to syscall groups.  */
> +      for (i = 0; group_list[i]; i++)

Explicit comparison.

> +	{
> +	  const char *group = group_list[i];
> +	  size_t str_length = (sizeof (char)
> +			       *(strlen (group) + strlen ("group:") + 1));
                              ^^^

Missing space between operator and parenthesis.

> +	  char *prefixed_group = xmalloc (str_length);
> +
> +	  xsnprintf (prefixed_group, str_length, "group:%s", group);

You can use xstrprintf here, and drop the xmalloc dance.

> +	  group_list[i] = prefixed_group;
> +
> +	  make_cleanup (xfree, prefixed_group);
> +	}
> +
> +      syscall_retlist = (syscall_list == NULL) ?
> +	NULL : complete_on_enum (syscall_list, word, word);
> +      group_retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);
> +
> +      retlist = VEC_merge (char_ptr, syscall_retlist, group_retlist);
> +    }
> +
> +  VEC_free (char_ptr, syscall_retlist);
> +  VEC_free (char_ptr, group_retlist);
> +  xfree (syscall_list);
> +  do_cleanups (cleanups);
>  
> -  xfree (list);
>    return retlist;
>  }
>  
> -- 
> 1.9.3

Otherwise, the patch looks good to me (I am not the maintainer of this
part of the code).

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 3/4] Create syscall groups for x86_64.
  2014-11-02 19:37   ` [PATCH 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
@ 2014-11-14 23:00     ` Sergio Durigan Junior
  2014-11-20  2:11       ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-14 23:00 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:

> This commit introduces the following syscall groups for the x86_64
> architecture: memory, ipc, process, descriptor, signal and file.
>
> Please note that the sorting of the syscalls among these several groups
> follows the same structure used in strace.
>
> This also introduces tests for catching groups of syscalls on the x86_64
> architecture.

I guess I said that before, but just in case I didn't: I would prefer if
this patch already updated the other architectures as well.  IIUC you
are planning to do that in another series of patches, but it would be
good if you did everything at once, I think.  However, I will not oppose
if you decide to touch only on x86_64 for now.

Other than that, I have only one comment.

> gdb/
>
> 	* syscalls/amd64-linux.xml: Add 'groups' attribute to several
> 	syscalls on x86_64.  Create groups memory, ipc, file,
> 	descriptor, process and signal.
>
> gdb/testsuite/
>
> 	* gdb.base/catch-syscall.exp (do_syscall_tests): Add call
> 	to test_catch_syscall_group.
> 	(test_catch_syscall_group): New.
> ---
>  gdb/syscalls/amd64-linux.xml             | 362 +++++++++++++++----------------
>  gdb/testsuite/gdb.base/catch-syscall.exp |  33 +++
>  2 files changed, 214 insertions(+), 181 deletions(-)
>
> diff --git a/gdb/syscalls/amd64-linux.xml b/gdb/syscalls/amd64-linux.xml
> index 6a04218..974c5b5 100644
> --- a/gdb/syscalls/amd64-linux.xml
> +++ b/gdb/syscalls/amd64-linux.xml
> @@ -14,101 +14,101 @@
>       The file mentioned above belongs to the Linux Kernel.  -->
>  
>  <syscalls_info>
> -  <syscall name="read" number="0"/>
> -  <syscall name="write" number="1"/>
> -  <syscall name="open" number="2"/>
> -  <syscall name="close" number="3"/>
> -  <syscall name="stat" number="4"/>
> -  <syscall name="fstat" number="5"/>
> -  <syscall name="lstat" number="6"/>
> -  <syscall name="poll" number="7"/>
> -  <syscall name="lseek" number="8"/>
> -  <syscall name="mmap" number="9"/>
> -  <syscall name="mprotect" number="10"/>
> -  <syscall name="munmap" number="11"/>
> -  <syscall name="brk" number="12"/>
> -  <syscall name="rt_sigaction" number="13"/>
> -  <syscall name="rt_sigprocmask" number="14"/>
> -  <syscall name="rt_sigreturn" number="15"/>
> -  <syscall name="ioctl" number="16"/>
> -  <syscall name="pread64" number="17"/>
> -  <syscall name="pwrite64" number="18"/>
> -  <syscall name="readv" number="19"/>
> -  <syscall name="writev" number="20"/>
> -  <syscall name="access" number="21"/>
> -  <syscall name="pipe" number="22"/>
> -  <syscall name="select" number="23"/>
> +  <syscall name="read" number="0" groups="descriptor"/>
> +  <syscall name="write" number="1" groups="descriptor"/>
> +  <syscall name="open" number="2" groups="descriptor,file"/>
> +  <syscall name="close" number="3" groups="descriptor"/>
> +  <syscall name="stat" number="4" groups="file"/>
> +  <syscall name="fstat" number="5" groups="descriptor"/>
> +  <syscall name="lstat" number="6" groups="file"/>
> +  <syscall name="poll" number="7" groups="descriptor"/>
> +  <syscall name="lseek" number="8" groups="descriptor"/>
> +  <syscall name="mmap" number="9" groups="descriptor,memory"/>
> +  <syscall name="mprotect" number="10" groups="memory"/>
> +  <syscall name="munmap" number="11" groups="memory"/>
> +  <syscall name="brk" number="12" groups="memory"/>
> +  <syscall name="rt_sigaction" number="13" groups="signal"/>
> +  <syscall name="rt_sigprocmask" number="14" groups="signal"/>
> +  <syscall name="rt_sigreturn" number="15" groups="signal"/>
> +  <syscall name="ioctl" number="16" groups="descriptor"/>
> +  <syscall name="pread64" number="17" groups="descriptor"/>
> +  <syscall name="pwrite64" number="18" groups="descriptor"/>
> +  <syscall name="readv" number="19" groups="descriptor"/>
> +  <syscall name="writev" number="20" groups="descriptor"/>
> +  <syscall name="access" number="21" groups="file"/>
> +  <syscall name="pipe" number="22" groups="descriptor"/>
> +  <syscall name="select" number="23" groups="descriptor"/>
>    <syscall name="sched_yield" number="24"/>
> -  <syscall name="mremap" number="25"/>
> -  <syscall name="msync" number="26"/>
> -  <syscall name="mincore" number="27"/>
> -  <syscall name="madvise" number="28"/>
> -  <syscall name="shmget" number="29"/>
> -  <syscall name="shmat" number="30"/>
> -  <syscall name="shmctl" number="31"/>
> -  <syscall name="dup" number="32"/>
> -  <syscall name="dup2" number="33"/>
> -  <syscall name="pause" number="34"/>
> +  <syscall name="mremap" number="25" groups="memory"/>
> +  <syscall name="msync" number="26" groups="memory"/>
> +  <syscall name="mincore" number="27" groups="memory"/>
> +  <syscall name="madvise" number="28" groups="memory"/>
> +  <syscall name="shmget" number="29" groups="ipc"/>
> +  <syscall name="shmat" number="30" groups="memory,ipc"/>
> +  <syscall name="shmctl" number="31" groups="ipc"/>
> +  <syscall name="dup" number="32" groups="descriptor"/>
> +  <syscall name="dup2" number="33" groups="descriptor"/>
> +  <syscall name="pause" number="34" groups="signal"/>
>    <syscall name="nanosleep" number="35"/>
>    <syscall name="getitimer" number="36"/>
>    <syscall name="alarm" number="37"/>
>    <syscall name="setitimer" number="38"/>
>    <syscall name="getpid" number="39"/>
> -  <syscall name="sendfile" number="40"/>
> -  <syscall name="socket" number="41"/>
> -  <syscall name="connect" number="42"/>
> -  <syscall name="accept" number="43"/>
> -  <syscall name="sendto" number="44"/>
> -  <syscall name="recvfrom" number="45"/>
> -  <syscall name="sendmsg" number="46"/>
> -  <syscall name="recvmsg" number="47"/>
> -  <syscall name="shutdown" number="48"/>
> -  <syscall name="bind" number="49"/>
> -  <syscall name="listen" number="50"/>
> -  <syscall name="getsockname" number="51"/>
> -  <syscall name="getpeername" number="52"/>
> -  <syscall name="socketpair" number="53"/>
> -  <syscall name="setsockopt" number="54"/>
> -  <syscall name="getsockopt" number="55"/>
> -  <syscall name="clone" number="56"/>
> -  <syscall name="fork" number="57"/>
> -  <syscall name="vfork" number="58"/>
> -  <syscall name="execve" number="59"/>
> -  <syscall name="exit" number="60"/>
> -  <syscall name="wait4" number="61"/>
> -  <syscall name="kill" number="62"/>
> +  <syscall name="sendfile" number="40" groups="network,descriptor"/>
> +  <syscall name="socket" number="41" groups="network"/>
> +  <syscall name="connect" number="42" groups="network"/>
> +  <syscall name="accept" number="43" groups="network"/>
> +  <syscall name="sendto" number="44" groups="network"/>
> +  <syscall name="recvfrom" number="45" groups="network"/>
> +  <syscall name="sendmsg" number="46" groups="network"/>
> +  <syscall name="recvmsg" number="47" groups="network"/>
> +  <syscall name="shutdown" number="48" groups="network"/>
> +  <syscall name="bind" number="49" groups="network"/>
> +  <syscall name="listen" number="50" groups="network"/>
> +  <syscall name="getsockname" number="51" groups="network"/>
> +  <syscall name="getpeername" number="52" groups="network"/>
> +  <syscall name="socketpair" number="53" groups="network"/>
> +  <syscall name="setsockopt" number="54" groups="network"/>
> +  <syscall name="getsockopt" number="55" groups="network"/>
> +  <syscall name="clone" number="56" groups="process"/>
> +  <syscall name="fork" number="57" groups="process"/>
> +  <syscall name="vfork" number="58" groups="process"/>
> +  <syscall name="execve" number="59" groups="process,file"/>
> +  <syscall name="exit" number="60" groups="process"/>
> +  <syscall name="wait4" number="61" groups="process"/>
> +  <syscall name="kill" number="62" groups="signal"/>
>    <syscall name="uname" number="63"/>
> -  <syscall name="semget" number="64"/>
> -  <syscall name="semop" number="65"/>
> -  <syscall name="semctl" number="66"/>
> -  <syscall name="shmdt" number="67"/>
> -  <syscall name="msgget" number="68"/>
> -  <syscall name="msgsnd" number="69"/>
> -  <syscall name="msgrcv" number="70"/>
> -  <syscall name="msgctl" number="71"/>
> -  <syscall name="fcntl" number="72"/>
> -  <syscall name="flock" number="73"/>
> -  <syscall name="fsync" number="74"/>
> -  <syscall name="fdatasync" number="75"/>
> -  <syscall name="truncate" number="76"/>
> -  <syscall name="ftruncate" number="77"/>
> -  <syscall name="getdents" number="78"/>
> -  <syscall name="getcwd" number="79"/>
> -  <syscall name="chdir" number="80"/>
> -  <syscall name="fchdir" number="81"/>
> -  <syscall name="rename" number="82"/>
> -  <syscall name="mkdir" number="83"/>
> -  <syscall name="rmdir" number="84"/>
> -  <syscall name="creat" number="85"/>
> -  <syscall name="link" number="86"/>
> -  <syscall name="unlink" number="87"/>
> -  <syscall name="symlink" number="88"/>
> -  <syscall name="readlink" number="89"/>
> -  <syscall name="chmod" number="90"/>
> -  <syscall name="fchmod" number="91"/>
> -  <syscall name="chown" number="92"/>
> -  <syscall name="fchown" number="93"/>
> -  <syscall name="lchown" number="94"/>
> +  <syscall name="semget" number="64" groups="ipc"/>
> +  <syscall name="semop" number="65" groups="ipc"/>
> +  <syscall name="semctl" number="66" groups="ipc"/>
> +  <syscall name="shmdt" number="67" groups="memory,ipc"/>
> +  <syscall name="msgget" number="68" groups="ipc"/>
> +  <syscall name="msgsnd" number="69" groups="ipc"/>
> +  <syscall name="msgrcv" number="70" groups="ipc"/>
> +  <syscall name="msgctl" number="71" groups="ipc"/>
> +  <syscall name="fcntl" number="72" groups="descriptor"/>
> +  <syscall name="flock" number="73" groups="descriptor"/>
> +  <syscall name="fsync" number="74" groups="descriptor"/>
> +  <syscall name="fdatasync" number="75" groups="descriptor"/>
> +  <syscall name="truncate" number="76" groups="file"/>
> +  <syscall name="ftruncate" number="77" groups="descriptor"/>
> +  <syscall name="getdents" number="78" groups="descriptor"/>
> +  <syscall name="getcwd" number="79" groups="file"/>
> +  <syscall name="chdir" number="80" groups="file"/>
> +  <syscall name="fchdir" number="81" groups="descriptor"/>
> +  <syscall name="rename" number="82" groups="file"/>
> +  <syscall name="mkdir" number="83" groups="file"/>
> +  <syscall name="rmdir" number="84" groups="file"/>
> +  <syscall name="creat" number="85" groups="file,descriptor"/>
> +  <syscall name="link" number="86" groups="file"/>
> +  <syscall name="unlink" number="87" groups="file"/>
> +  <syscall name="symlink" number="88" groups="file"/>
> +  <syscall name="readlink" number="89" groups="file"/>
> +  <syscall name="chmod" number="90" groups="file"/>
> +  <syscall name="fchmod" number="91" groups="descriptor"/>
> +  <syscall name="chown" number="92" groups="file"/>
> +  <syscall name="fchown" number="93" groups="descriptor"/>
> +  <syscall name="lchown" number="94" groups="file"/>
>    <syscall name="umask" number="95"/>
>    <syscall name="gettimeofday" number="96"/>
>    <syscall name="getrlimit" number="97"/>
> @@ -141,18 +141,18 @@
>    <syscall name="getsid" number="124"/>
>    <syscall name="capget" number="125"/>
>    <syscall name="capset" number="126"/>
> -  <syscall name="rt_sigpending" number="127"/>
> -  <syscall name="rt_sigtimedwait" number="128"/>
> -  <syscall name="rt_sigqueueinfo" number="129"/>
> -  <syscall name="rt_sigsuspend" number="130"/>
> -  <syscall name="sigaltstack" number="131"/>
> -  <syscall name="utime" number="132"/>
> -  <syscall name="mknod" number="133"/>
> -  <syscall name="uselib" number="134"/>
> +  <syscall name="rt_sigpending" number="127" groups="signal"/>
> +  <syscall name="rt_sigtimedwait" number="128" groups="signal"/>
> +  <syscall name="rt_sigqueueinfo" number="129" groups="signal"/>
> +  <syscall name="rt_sigsuspend" number="130" groups="signal"/>
> +  <syscall name="sigaltstack" number="131" groups="signal"/>
> +  <syscall name="utime" number="132" groups="file"/>
> +  <syscall name="mknod" number="133" groups="file"/>
> +  <syscall name="uselib" number="134" groups="file"/>
>    <syscall name="personality" number="135"/>
>    <syscall name="ustat" number="136"/>
> -  <syscall name="statfs" number="137"/>
> -  <syscall name="fstatfs" number="138"/>
> +  <syscall name="statfs" number="137" groups="file"/>
> +  <syscall name="fstatfs" number="138" groups="descriptor"/>
>    <syscall name="sysfs" number="139"/>
>    <syscall name="getpriority" number="140"/>
>    <syscall name="setpriority" number="141"/>
> @@ -163,26 +163,26 @@
>    <syscall name="sched_get_priority_max" number="146"/>
>    <syscall name="sched_get_priority_min" number="147"/>
>    <syscall name="sched_rr_get_interval" number="148"/>
> -  <syscall name="mlock" number="149"/>
> -  <syscall name="munlock" number="150"/>
> -  <syscall name="mlockall" number="151"/>
> -  <syscall name="munlockall" number="152"/>
> +  <syscall name="mlock" number="149" groups="memory"/>
> +  <syscall name="munlock" number="150" groups="memory"/>
> +  <syscall name="mlockall" number="151" groups="memory"/>
> +  <syscall name="munlockall" number="152" groups="memory"/>
>    <syscall name="vhangup" number="153"/>
>    <syscall name="modify_ldt" number="154"/>
> -  <syscall name="pivot_root" number="155"/>
> +  <syscall name="pivot_root" number="155" groups="file"/>
>    <syscall name="_sysctl" number="156"/>
>    <syscall name="prctl" number="157"/>
> -  <syscall name="arch_prctl" number="158"/>
> +  <syscall name="arch_prctl" number="158" groups="process"/>
>    <syscall name="adjtimex" number="159"/>
>    <syscall name="setrlimit" number="160"/>
> -  <syscall name="chroot" number="161"/>
> +  <syscall name="chroot" number="161" groups="file"/>
>    <syscall name="sync" number="162"/>
> -  <syscall name="acct" number="163"/>
> +  <syscall name="acct" number="163" groups="file"/>
>    <syscall name="settimeofday" number="164"/>
> -  <syscall name="mount" number="165"/>
> -  <syscall name="umount2" number="166"/>
> -  <syscall name="swapon" number="167"/>
> -  <syscall name="swapoff" number="168"/>
> +  <syscall name="mount" number="165" groups="file"/>
> +  <syscall name="umount2" number="166" groups="file"/>
> +  <syscall name="swapon" number="167" groups="file"/>
> +  <syscall name="swapoff" number="168" groups="file"/>
>    <syscall name="reboot" number="169"/>
>    <syscall name="sethostname" number="170"/>
>    <syscall name="setdomainname" number="171"/>
> @@ -193,7 +193,7 @@
>    <syscall name="delete_module" number="176"/>
>    <syscall name="get_kernel_syms" number="177"/>
>    <syscall name="query_module" number="178"/>
> -  <syscall name="quotactl" number="179"/>
> +  <syscall name="quotactl" number="179" groups="file"/>
>    <syscall name="nfsservctl" number="180"/>
>    <syscall name="getpmsg" number="181"/>
>    <syscall name="putpmsg" number="182"/>
> @@ -201,20 +201,20 @@
>    <syscall name="tuxcall" number="184"/>
>    <syscall name="security" number="185"/>
>    <syscall name="gettid" number="186"/>
> -  <syscall name="readahead" number="187"/>
> -  <syscall name="setxattr" number="188"/>
> -  <syscall name="lsetxattr" number="189"/>
> -  <syscall name="fsetxattr" number="190"/>
> -  <syscall name="getxattr" number="191"/>
> -  <syscall name="lgetxattr" number="192"/>
> -  <syscall name="fgetxattr" number="193"/>
> -  <syscall name="listxattr" number="194"/>
> -  <syscall name="llistxattr" number="195"/>
> -  <syscall name="flistxattr" number="196"/>
> -  <syscall name="removexattr" number="197"/>
> -  <syscall name="lremovexattr" number="198"/>
> -  <syscall name="fremovexattr" number="199"/>
> -  <syscall name="tkill" number="200"/>
> +  <syscall name="readahead" number="187" groups="descriptor"/>
> +  <syscall name="setxattr" number="188" groups="file"/>
> +  <syscall name="lsetxattr" number="189" groups="file"/>
> +  <syscall name="fsetxattr" number="190" groups="descriptor"/>
> +  <syscall name="getxattr" number="191" groups="file"/>
> +  <syscall name="lgetxattr" number="192" groups="file"/>
> +  <syscall name="fgetxattr" number="193" groups="descriptor"/>
> +  <syscall name="listxattr" number="194" groups="file"/>
> +  <syscall name="llistxattr" number="195" groups="file"/>
> +  <syscall name="flistxattr" number="196" groups="descriptor"/>
> +  <syscall name="removexattr" number="197" groups="file"/>
> +  <syscall name="lremovexattr" number="198" groups="file"/>
> +  <syscall name="fremovexattr" number="199" groups="descriptor"/>
> +  <syscall name="tkill" number="200" groups="signal"/>
>    <syscall name="time" number="201"/>
>    <syscall name="futex" number="202"/>
>    <syscall name="sched_setaffinity" number="203"/>
> @@ -227,15 +227,15 @@
>    <syscall name="io_cancel" number="210"/>
>    <syscall name="get_thread_area" number="211"/>
>    <syscall name="lookup_dcookie" number="212"/>
> -  <syscall name="epoll_create" number="213"/>
> +  <syscall name="epoll_create" number="213" groups="descriptor"/>
>    <syscall name="epoll_ctl_old" number="214"/>
>    <syscall name="epoll_wait_old" number="215"/>
> -  <syscall name="remap_file_pages" number="216"/>
> -  <syscall name="getdents64" number="217"/>
> +  <syscall name="remap_file_pages" number="216" groups="memory"/>
> +  <syscall name="getdents64" number="217" groups="descriptor"/>
>    <syscall name="set_tid_address" number="218"/>
>    <syscall name="restart_syscall" number="219"/>
> -  <syscall name="semtimedop" number="220"/>
> -  <syscall name="fadvise64" number="221"/>
> +  <syscall name="semtimedop" number="220" groups="ipc"/>
> +  <syscall name="fadvise64" number="221" groups="descriptor"/>
>    <syscall name="timer_create" number="222"/>
>    <syscall name="timer_settime" number="223"/>
>    <syscall name="timer_gettime" number="224"/>
> @@ -245,15 +245,15 @@
>    <syscall name="clock_gettime" number="228"/>
>    <syscall name="clock_getres" number="229"/>
>    <syscall name="clock_nanosleep" number="230"/>
> -  <syscall name="exit_group" number="231"/>
> -  <syscall name="epoll_wait" number="232"/>
> -  <syscall name="epoll_ctl" number="233"/>
> -  <syscall name="tgkill" number="234"/>
> -  <syscall name="utimes" number="235"/>
> +  <syscall name="exit_group" number="231" groups="process"/>
> +  <syscall name="epoll_wait" number="232" groups="descriptor"/>
> +  <syscall name="epoll_ctl" number="233" groups="descriptor"/>
> +  <syscall name="tgkill" number="234" groups="signal"/>
> +  <syscall name="utimes" number="235" groups="file"/>
>    <syscall name="vserver" number="236"/>
> -  <syscall name="mbind" number="237"/>
> -  <syscall name="set_mempolicy" number="238"/>
> -  <syscall name="get_mempolicy" number="239"/>
> +  <syscall name="mbind" number="237" groups="memory"/>
> +  <syscall name="set_mempolicy" number="238" groups="memory"/>
> +  <syscall name="get_mempolicy" number="239" groups="memory"/>
>    <syscall name="mq_open" number="240"/>
>    <syscall name="mq_unlink" number="241"/>
>    <syscall name="mq_timedsend" number="242"/>
> @@ -261,54 +261,54 @@
>    <syscall name="mq_notify" number="244"/>
>    <syscall name="mq_getsetattr" number="245"/>
>    <syscall name="kexec_load" number="246"/>
> -  <syscall name="waitid" number="247"/>
> +  <syscall name="waitid" number="247" groups="process"/>
>    <syscall name="add_key" number="248"/>
>    <syscall name="request_key" number="249"/>
>    <syscall name="keyctl" number="250"/>
>    <syscall name="ioprio_set" number="251"/>
>    <syscall name="ioprio_get" number="252"/>
> -  <syscall name="inotify_init" number="253"/>
> -  <syscall name="inotify_add_watch" number="254"/>
> -  <syscall name="inotify_rm_watch" number="255"/>
> -  <syscall name="migrate_pages" number="256"/>
> -  <syscall name="openat" number="257"/>
> -  <syscall name="mkdirat" number="258"/>
> -  <syscall name="mknodat" number="259"/>
> -  <syscall name="fchownat" number="260"/>
> -  <syscall name="futimesat" number="261"/>
> -  <syscall name="newfstatat" number="262"/>
> -  <syscall name="unlinkat" number="263"/>
> -  <syscall name="renameat" number="264"/>
> -  <syscall name="linkat" number="265"/>
> -  <syscall name="symlinkat" number="266"/>
> -  <syscall name="readlinkat" number="267"/>
> -  <syscall name="fchmodat" number="268"/>
> -  <syscall name="faccessat" number="269"/>
> -  <syscall name="pselect6" number="270"/>
> -  <syscall name="ppoll" number="271"/>
> -  <syscall name="unshare" number="272"/>
> +  <syscall name="inotify_init" number="253" groups="descriptor"/>
> +  <syscall name="inotify_add_watch" number="254" groups="descriptor"/>
> +  <syscall name="inotify_rm_watch" number="255" groups="descriptor"/>
> +  <syscall name="migrate_pages" number="256" groups="memory"/>
> +  <syscall name="openat" number="257" groups="file,descriptor"/>
> +  <syscall name="mkdirat" number="258" groups="file,descriptor"/>
> +  <syscall name="mknodat" number="259" groups="file,descriptor"/>
> +  <syscall name="fchownat" number="260" groups="file,descriptor"/>
> +  <syscall name="futimesat" number="261" groups="file,descriptor"/>
> +  <syscall name="newfstatat" number="262" groups="file,descriptor"/>
> +  <syscall name="unlinkat" number="263" groups="file,descriptor"/>
> +  <syscall name="renameat" number="264" groups="file,descriptor"/>
> +  <syscall name="linkat" number="265" groups="file,descriptor"/>
> +  <syscall name="symlinkat" number="266" groups="file,descriptor"/>
> +  <syscall name="readlinkat" number="267" groups="file,descriptor"/>
> +  <syscall name="fchmodat" number="268" groups="file,descriptor"/>
> +  <syscall name="faccessat" number="269" groups="file,descriptor"/>
> +  <syscall name="pselect6" number="270" groups="descriptor"/>
> +  <syscall name="ppoll" number="271" groups="descriptor"/>
> +  <syscall name="unshare" number="272" groups="process"/>
>    <syscall name="set_robust_list" number="273"/>
>    <syscall name="get_robust_list" number="274"/>
> -  <syscall name="splice" number="275"/>
> -  <syscall name="tee" number="276"/>
> -  <syscall name="sync_file_range" number="277"/>
> -  <syscall name="vmsplice" number="278"/>
> -  <syscall name="move_pages" number="279"/>
> -  <syscall name="utimensat" number="280"/>
> -  <syscall name="epoll_pwait" number="281"/>
> -  <syscall name="signalfd" number="282"/>
> -  <syscall name="timerfd_create" number="283"/>
> -  <syscall name="eventfd" number="284"/>
> -  <syscall name="fallocate" number="285"/>
> -  <syscall name="timerfd_settime" number="286"/>
> -  <syscall name="timerfd_gettime" number="287"/>
> -  <syscall name="accept4" number="288"/>
> -  <syscall name="signalfd4" number="289"/>
> -  <syscall name="eventfd2" number="290"/>
> -  <syscall name="epoll_create1" number="291"/>
> -  <syscall name="dup3" number="292"/>
> -  <syscall name="pipe2" number="293"/>
> -  <syscall name="inotify_init1" number="294"/>
> -  <syscall name="preadv" number="295"/>
> -  <syscall name="pwritev" number="296"/>
> +  <syscall name="splice" number="275" groups="descriptor"/>
> +  <syscall name="tee" number="276" groups="descriptor"/>
> +  <syscall name="sync_file_range" number="277" groups="descriptor"/>
> +  <syscall name="vmsplice" number="278" groups="descriptor"/>
> +  <syscall name="move_pages" number="279" groups="memory"/>
> +  <syscall name="utimensat" number="280" groups="file,descriptor"/>
> +  <syscall name="epoll_pwait" number="281" groups="descriptor"/>
> +  <syscall name="signalfd" number="282" groups="signal,descriptor"/>
> +  <syscall name="timerfd_create" number="283" groups="descriptor"/>
> +  <syscall name="eventfd" number="284" groups="descriptor"/>
> +  <syscall name="fallocate" number="285" groups="descriptor"/>
> +  <syscall name="timerfd_settime" number="286" groups="descriptor"/>
> +  <syscall name="timerfd_gettime" number="287" groups="descriptor"/>
> +  <syscall name="accept4" number="288" groups="network"/>
> +  <syscall name="signalfd4" number="289" groups="signal,descriptor"/>
> +  <syscall name="eventfd2" number="290" groups="descriptor"/>
> +  <syscall name="epoll_create1" number="291" groups="descriptor"/>
> +  <syscall name="dup3" number="292" groups="descriptor"/>
> +  <syscall name="pipe2" number="293" groups="descriptor"/>
> +  <syscall name="inotify_init1" number="294" groups="descriptor"/>
> +  <syscall name="preadv" number="295" groups="descriptor"/>
> +  <syscall name="pwritev" number="296" groups="descriptor"/>
>  </syscalls_info>
> diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
> index a70534c..de92735 100644
> --- a/gdb/testsuite/gdb.base/catch-syscall.exp
> +++ b/gdb/testsuite/gdb.base/catch-syscall.exp
> @@ -275,6 +275,36 @@ proc test_catch_syscall_fail_nodatadir {} {
>      }
>  }
>  
> +proc test_catch_syscall_group {} {
> +    global decimal
> +
> +    # Until we have syscall groups to test on other targets.
> +    if { ![istarget "x86_64-*-linux*"] } then {
> +	return
> +    }
> +    set sysnum "\\\[\[0-9\]+\\\]"

This could be

  "\\\[${decimal}\\\]"

right?

> +
> +    gdb_test "catch syscall g:process" \
> +	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \
> +	"set catchpoint on a group of syscalls"
> +
> +    gdb_test "catch syscall g:process read" \
> +	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \
> +	"set catchpoints on a group of syscalls and on a single syscall"
> +
> +    gdb_test "complete catch syscall g:proc" \
> +	"catch syscall g:process" \
> +	"complete catch syscall group with 'g:' prefix"
> +
> +    gdb_test "complete catch syscall group:proc" \
> +	"catch syscall group:process" \
> +	"complete catch syscall group with 'group:' prefix"
> +
> +    gdb_test "complete catch syscall g" \
> +	".*group:process.*" \
> +	"complete catch syscall group suggests 'group:' prefix"
> +}
> +
>  proc do_syscall_tests {} {
>      # NOTE: We don't have to point gdb at the correct data-directory.
>      # For the build tree that is handled by INTERNAL_GDBFLAGS.
> @@ -311,6 +341,9 @@ proc do_syscall_tests {} {
>      # Testing the 'catch' syscall command during a restart of
>      # the inferior.
>      if [runto_main] then { test_catch_syscall_restarting_inferior }
> +
> +    # Testing the 'catch' syscall command for a group of syscalls.
> +    if [runto_main] then { test_catch_syscall_group }
>  }
>  
>  proc test_catch_syscall_without_args_noxml {} {
> -- 
> 1.9.3

This patch looks good to me (I am not the maintainer of this part of the
code).

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 3/4] Create syscall groups for x86_64.
  2014-11-14 23:00     ` Sergio Durigan Junior
@ 2014-11-20  2:11       ` Gabriel Krisman Bertazi
  2014-11-20  3:08         ` Sergio Durigan Junior
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-20  2:11 UTC (permalink / raw)
  To: Sergio Durigan Junior; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 1534 bytes --]

Sergio Durigan Junior <sergiodj@redhat.com> writes:

Sergio,

Thank you for your review.  I applied your suggestions and I will send
the updated patches to this list in a few moments.

> On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:
>
>> This commit introduces the following syscall groups for the x86_64
>> architecture: memory, ipc, process, descriptor, signal and file.
>>
>> Please note that the sorting of the syscalls among these several groups
>> follows the same structure used in strace.
>>
>> This also introduces tests for catching groups of syscalls on the x86_64
>> architecture.
>
> I guess I said that before, but just in case I didn't: I would prefer if
> this patch already updated the other architectures as well.  IIUC you
> are planning to do that in another series of patches, but it would be
> good if you did everything at once, I think.  However, I will not oppose
> if you decide to touch only on x86_64 for now.

Updating the syscall files by hand is quite error-prone and requires
lots of typing.  Should we bring PR 14276 to the table, it would also
require extra work to update the groups later.

A few weeks ago, you and I talked about writing a script to fix PR14276.
What I want to do is to save me some typing now and update the other
architectures only after we have such script to generate the syscall
files, so we can use it to also generate the group information
automatically.  What do you think? Is that ok for you?

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 3/4] Create syscall groups for x86_64.
  2014-11-20  2:11       ` Gabriel Krisman Bertazi
@ 2014-11-20  3:08         ` Sergio Durigan Junior
  0 siblings, 0 replies; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-20  3:08 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 2187 bytes --]

On Wednesday, November 19 2014, Gabriel Krisman Bertazi wrote:

> Sergio Durigan Junior <sergiodj@redhat.com> writes:
>
> Sergio,
>
> Thank you for your review.  I applied your suggestions and I will send
> the updated patches to this list in a few moments.

Thanks!

>> On Sunday, November 02 2014, Gabriel Krisman Bertazi wrote:
>>
>>> This commit introduces the following syscall groups for the x86_64
>>> architecture: memory, ipc, process, descriptor, signal and file.
>>>
>>> Please note that the sorting of the syscalls among these several groups
>>> follows the same structure used in strace.
>>>
>>> This also introduces tests for catching groups of syscalls on the x86_64
>>> architecture.
>>
>> I guess I said that before, but just in case I didn't: I would prefer if
>> this patch already updated the other architectures as well.  IIUC you
>> are planning to do that in another series of patches, but it would be
>> good if you did everything at once, I think.  However, I will not oppose
>> if you decide to touch only on x86_64 for now.
>
> Updating the syscall files by hand is quite error-prone and requires
> lots of typing.  Should we bring PR 14276 to the table, it would also
> require extra work to update the groups later.

Yeah, I am aware of that :-/.

> A few weeks ago, you and I talked about writing a script to fix PR14276.
> What I want to do is to save me some typing now and update the other
> architectures only after we have such script to generate the syscall
> files, so we can use it to also generate the group information
> automatically.  What do you think? Is that ok for you?

Heh, since you asked :-P...

My opinion is that writing this script could take some time, and I am
not counting on it be to ready soon, unfortunately.

That being said, I also don't think we should let the perfect be the
enemy of the good (I think Pedro said that once, and I liked the
phrase).  Therefore, I am OK with your patch as is, provided we don't
take too long to start working on this script :-).

Thanks,

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v2 2/4] Add support to catch groups of syscalls.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
                     ` (3 preceding siblings ...)
  2014-11-02 19:37   ` [PATCH 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
@ 2014-11-21 19:05   ` Gabriel Krisman Bertazi
  2014-11-21 21:34     ` Sergio Durigan Junior
  2015-01-15  8:12     ` Doug Evans
  2014-11-21 19:06   ` [PATCH v2 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
  2014-11-21 19:06   ` [PATCH v2 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
  6 siblings, 2 replies; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-21 19:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

This implements the catchpoint side.  While parsing 'catch syscall'
arguments, we verify if the argument is a syscall group and expand it to
a list of syscalls that are part of that group.

gdb/

	* breakpoint.c (catch_syscall_split_args): Verify if argument
	is a syscall group and expand it to a list of syscalls when
	creating catchpoints.
	(catch_syscall_completer): Add word completion for system call
	groups.
---
 gdb/breakpoint.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 1 file changed, 86 insertions(+), 9 deletions(-)

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 7b56260..098e28d 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -12058,10 +12058,39 @@ catch_syscall_split_args (char *arg)
       cur_name[i] = '\0';
       arg += i;
 
-      /* Check if the user provided a syscall name or a number.  */
+      /* Check if the user provided a syscall name, group, or a
+	 number.  */
       syscall_number = (int) strtol (cur_name, &endptr, 0);
       if (*endptr == '\0')
-	get_syscall_by_number (gdbarch, syscall_number, &s);
+	{
+	  get_syscall_by_number (gdbarch, syscall_number, &s);
+	  VEC_safe_push (int, result, s.number);
+	}
+      else if (strncmp (cur_name, "g:", 2) == 0
+	       || strncmp (cur_name, "group:", 6) == 0)
+	{
+	  /* We have a syscall group.  Let's expand it into a syscall
+	     list before inserting.  */
+	  struct syscall *syscall_list;
+	  const char *group_name;
+
+	  /* Skip over "g:" and "group:" prefix strings.  */
+	  group_name = strchr (cur_name, ':') + 1;
+
+	  syscall_list = get_syscalls_by_group (gdbarch, group_name);
+
+	  if (syscall_list == NULL)
+	    error (_("Unknown syscall group '%s'."), group_name);
+
+	  for (i = 0; syscall_list[i].name != NULL; i++)
+	    {
+	      /* Insert each syscall that are part of the group.  No
+		 need to check if it is valid.  */
+	      VEC_safe_push (int, result, syscall_list[i].number);
+	    }
+
+	  xfree (syscall_list);
+	}
       else
 	{
 	  /* We have a name.  Let's check if it's valid and convert it
@@ -12073,10 +12102,10 @@ catch_syscall_split_args (char *arg)
 	       because GDB cannot do anything useful if there's no
 	       syscall number to be caught.  */
 	    error (_("Unknown syscall name '%s'."), cur_name);
-	}
 
-      /* Ok, it's valid.  */
-      VEC_safe_push (int, result, s.number);
+	  /* Ok, it's valid.  */
+	  VEC_safe_push (int, result, s.number);
+	}
     }
 
   discard_cleanups (cleanup);
@@ -15350,11 +15379,59 @@ static VEC (char_ptr) *
 catch_syscall_completer (struct cmd_list_element *cmd,
                          const char *text, const char *word)
 {
-  const char **list = get_syscall_names (get_current_arch ());
-  VEC (char_ptr) *retlist
-    = (list == NULL) ? NULL : complete_on_enum (list, word, word);
+  struct gdbarch *gdbarch = get_current_arch ();
+  struct cleanup *cleanups;
+  VEC (char_ptr) *group_retlist = NULL;
+  VEC (char_ptr) *syscall_retlist = NULL;
+  VEC (char_ptr) *retlist = NULL;
+  const char **group_list = NULL;
+  const char **syscall_list = NULL;
+  const char *prefix;
+  int i;
+
+  /* Completion considers ':' to be a word separator, so we use this to
+     verify whether the previous word was a group prefix.  If so, we
+     build the completion list using group names only.  */
+  for (prefix = word; prefix != text && prefix[-1] != ' '; prefix--)
+    ;
+
+  if (strncmp (prefix, "g:", 2) == 0 || strncmp (prefix, "group:", 6) == 0)
+    {
+      /* Perform completion inside 'group:' namespace only.  */
+      group_list = get_syscall_group_names (gdbarch);
+      cleanups = make_cleanup (xfree, group_list);
+      retlist = (group_list == NULL) ?
+	NULL : complete_on_enum (group_list, word, word);
+    }
+  else
+    {
+      /* Complete with both, syscall names and groups.  */
+      syscall_list = get_syscall_names (gdbarch);
+      group_list = get_syscall_group_names (gdbarch);
+      cleanups = make_cleanup (xfree, group_list);
+
+      /* Append "group:" prefix to syscall groups.  */
+      for (i = 0; group_list[i] != NULL; i++)
+	{
+	  char *prefixed_group = xstrprintf ("group:%s", group_list[i]);
+
+	  group_list[i] = prefixed_group;
+	  make_cleanup (xfree, prefixed_group);
+	}
+
+      syscall_retlist = (syscall_list == NULL) ?
+	NULL : complete_on_enum (syscall_list, word, word);
+      group_retlist = (group_list == NULL) ?
+	NULL : complete_on_enum (group_list, word, word);
+
+      retlist = VEC_merge (char_ptr, syscall_retlist, group_retlist);
+    }
+
+  VEC_free (char_ptr, syscall_retlist);
+  VEC_free (char_ptr, group_retlist);
+  xfree (syscall_list);
+  do_cleanups (cleanups);
 
-  xfree (list);
   return retlist;
 }
 
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
@ 2014-11-21 19:05 Gabriel Krisman Bertazi
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
                   ` (2 more replies)
  6 siblings, 3 replies; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-21 19:05 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

Hello,

These are the updated patches after applying Sergio's suggestions.

Is this good to go?

gdb/

	* syscalls/gdb-syscalls.dtd: Include group attribute to the
	syscall element.
	* xml-syscall.c (get_syscalls_by_group): New.
	(get_syscall_group_names): New.
	(struct syscall_group_desc): New structure to store group data.
	(struct syscalls_info): Include field to store the group list.
	(syscalls_info_free_syscall_group_desc): New.
	(free_syscalls_info): Free group list.
	(syscall_group_create_syscall_group_desc): New.
	(syscall_group_add_syscall): New.
	(syscall_create_syscall_desc): Add syscall to its groups.
	(syscall_start_syscall): Load group attribute.
	(syscall_group_get_group_by_name): New.
	(xml_list_syscalls_by_group): New.
	(xml_list_of_groups): New.
	* xml-syscall.h (get_syscalls_by_group): Export function
	to retrieve a list of syscalls filtered by the group name.
	(get_syscall_group_names): Export function to retrieve the list
	of syscall groups.
---
 gdb/syscalls/gdb-syscalls.dtd |   3 +-
 gdb/xml-syscall.c             | 230 +++++++++++++++++++++++++++++++++++++++++-
 gdb/xml-syscall.h             |  15 +++
 3 files changed, 245 insertions(+), 3 deletions(-)

diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
index 3ad3625..b60eb74 100644
--- a/gdb/syscalls/gdb-syscalls.dtd
+++ b/gdb/syscalls/gdb-syscalls.dtd
@@ -11,4 +11,5 @@
 <!ELEMENT syscall		EMPTY>
 <!ATTLIST syscall
 	name			CDATA	#REQUIRED
-	number			CDATA	#REQUIRED>
+	number			CDATA	#REQUIRED
+	groups			CDATA	#OPTIONAL>
diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
index 987fe7a..0d11c3a 100644
--- a/gdb/xml-syscall.c
+++ b/gdb/xml-syscall.c
@@ -77,6 +77,20 @@ get_syscall_names (struct gdbarch *gdbarch)
   return NULL;
 }
 
+struct syscall *
+get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
+{
+  syscall_warn_user ();
+  return NULL;
+}
+
+const char **
+get_syscall_group_names (struct gdbarch *gdbarch)
+{
+  syscall_warn_user ();
+  return NULL;
+}
+
 #else /* ! HAVE_LIBEXPAT */
 
 /* Structure which describes a syscall.  */
@@ -92,6 +106,19 @@ typedef struct syscall_desc
 } *syscall_desc_p;
 DEF_VEC_P(syscall_desc_p);
 
+/* Structure of a syscall group.  */
+typedef struct syscall_group_desc
+{
+  /* The group name.  */
+
+  char *name;
+
+  /* The syscalls that are part of the group.  */
+
+  VEC(syscall_desc_p) *syscalls;
+} *syscall_group_desc_p;
+DEF_VEC_P(syscall_group_desc_p);
+
 /* Structure that represents syscalls information.  */
 struct syscalls_info
 {
@@ -99,6 +126,10 @@ struct syscalls_info
 
   VEC(syscall_desc_p) *syscalls;
 
+  /* The syscall groups.  */
+
+  VEC(syscall_group_desc_p) *groups;
+
   /* Variable that will hold the last known data-directory.  This is
      useful to know whether we should re-read the XML info for the
      target.  */
@@ -126,11 +157,21 @@ syscalls_info_free_syscalls_desc (struct syscall_desc *sd)
   xfree (sd->name);
 }
 
+/* Free syscall_group_desc members but not the structure itself.  */
+
+static void
+syscalls_info_free_syscall_group_desc (struct syscall_group_desc *sd)
+{
+  VEC_free (syscall_desc_p, sd->syscalls);
+  xfree (sd->name);
+}
+
 static void
 free_syscalls_info (void *arg)
 {
   struct syscalls_info *syscalls_info = arg;
   struct syscall_desc *sysdesc;
+  struct syscall_group_desc *groupdesc;
   int i;
 
   xfree (syscalls_info->my_gdb_datadir);
@@ -143,6 +184,15 @@ free_syscalls_info (void *arg)
 	syscalls_info_free_syscalls_desc (sysdesc);
       VEC_free (syscall_desc_p, syscalls_info->syscalls);
     }
+  if (syscalls_info->groups != NULL)
+    {
+      for (i = 0;
+	   VEC_iterate (syscall_group_desc_p,
+			syscalls_info->groups, i, groupdesc);
+	   i++)
+	syscalls_info_free_syscall_group_desc (groupdesc);
+      VEC_free (syscall_group_desc_p, syscalls_info->groups);
+    }
 
   xfree (syscalls_info);
 }
@@ -153,16 +203,71 @@ make_cleanup_free_syscalls_info (struct syscalls_info *syscalls_info)
   return make_cleanup (free_syscalls_info, syscalls_info);
 }
 
+/* Create a new syscall group.  Return pointer to the
+   syscall_group_desc structure that represents the new group.  */
+
+static struct syscall_group_desc *
+syscall_group_create_syscall_group_desc (struct syscalls_info *syscalls_info,
+					 const char *group)
+{
+  struct syscall_group_desc *groupdesc = XCNEW (struct syscall_group_desc);
+
+  groupdesc->name = xstrdup (group);
+
+  VEC_safe_push (syscall_group_desc_p, syscalls_info->groups, groupdesc);
+
+  return groupdesc;
+}
+
+/* Add a syscall to the group.  If group doesn't exist, create
+   it.  */
+
+static void
+syscall_group_add_syscall (struct syscalls_info *syscalls_info,
+			   struct syscall_desc *syscall,
+			   const char *group)
+{
+  struct syscall_group_desc *groupdesc;
+  int i;
+
+  /* Search for an existing group.  */
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p,
+		    syscalls_info->groups, i, groupdesc);
+       i++)
+    if (strcmp (groupdesc->name, group) == 0)
+      break;
+
+  if (groupdesc == NULL)
+    {
+      /* No group was found with this name.  We must create a new
+	 one.  */
+      groupdesc = syscall_group_create_syscall_group_desc (syscalls_info,
+							   group);
+    }
+
+  VEC_safe_push (syscall_desc_p, groupdesc->syscalls, syscall);
+}
+
 static void
 syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
-                             const char *name, int number)
+                             const char *name, int number,
+			     char *groups)
 {
   struct syscall_desc *sysdesc = XCNEW (struct syscall_desc);
+  char *group;
 
   sysdesc->name = xstrdup (name);
   sysdesc->number = number;
 
   VEC_safe_push (syscall_desc_p, syscalls_info->syscalls, sysdesc);
+
+  /*  Add syscall to its groups.  */
+  if (groups != NULL)
+    for (group = strtok (groups, ",");
+	 group != NULL;
+	 group = strtok (NULL, ","))
+      syscall_group_add_syscall (syscalls_info, sysdesc, group);
 }
 
 /* Handle the start of a <syscall> element.  */
@@ -177,6 +282,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
   /* syscall info.  */
   char *name = NULL;
   int number = 0;
+  char *groups = NULL;
 
   len = VEC_length (gdb_xml_value_s, attributes);
 
@@ -186,13 +292,16 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
         name = attrs[i].value;
       else if (strcmp (attrs[i].name, "number") == 0)
         number = * (ULONGEST *) attrs[i].value;
+      else if (strcmp (attrs[i].name, "groups") == 0)
+        groups = attrs[i].value;
       else
         internal_error (__FILE__, __LINE__,
                         _("Unknown attribute name '%s'."), attrs[i].name);
     }
 
   gdb_assert (name);
-  syscall_create_syscall_desc (data->syscalls_info, name, number);
+
+  syscall_create_syscall_desc (data->syscalls_info, name, number, groups);
 }
 
 
@@ -200,6 +309,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
 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 },
+  { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
   { NULL, GDB_XML_AF_NONE, NULL, NULL }
 };
 
@@ -321,6 +431,33 @@ init_syscalls_info (struct gdbarch *gdbarch)
   set_gdbarch_syscalls_info (gdbarch, syscalls_info);
 }
 
+/* Search for a syscall group by its name.  Return syscall_group_desc
+   structure for the group if found or NULL otherwise.  */
+
+static struct syscall_group_desc *
+syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
+				 const char *group)
+{
+  struct syscall_group_desc *groupdesc;
+  int i;
+
+  if (syscalls_info == NULL)
+    return NULL;
+
+  if (group == NULL)
+    return NULL;
+
+   /* Search for existing group.  */
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p,
+		    syscalls_info->groups, i, groupdesc);
+       i++)
+    if (strcmp (groupdesc->name, group) == 0)
+      return groupdesc;
+
+  return NULL;
+}
+
 static int
 xml_get_syscall_number (struct gdbarch *gdbarch,
                         const char *syscall_name)
@@ -388,6 +525,75 @@ xml_list_of_syscalls (struct gdbarch *gdbarch)
   return names;
 }
 
+/*  Iterate over the syscall_group_desc element to return a list of
+    syscalls that are part of the given group, terminated by an empty
+    element.  If the syscall group doesn't exist, return NULL.  */
+
+static struct syscall *
+xml_list_syscalls_by_group (struct gdbarch *gdbarch,
+			    const char *group)
+{
+  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
+  struct syscall_group_desc *groupdesc;
+  struct syscall_desc *sysdesc;
+  struct syscall *syscalls = NULL;
+  int nsyscalls;
+  int i;
+
+  if (syscalls_info == NULL)
+    return NULL;
+
+  groupdesc = syscall_group_get_group_by_name (syscalls_info, group);
+  if (groupdesc == NULL)
+    return NULL;
+
+  nsyscalls = VEC_length (syscall_desc_p, groupdesc->syscalls);
+  syscalls = xmalloc ((nsyscalls + 1) * sizeof (struct syscall));
+
+  for (i = 0;
+       VEC_iterate (syscall_desc_p, groupdesc->syscalls, i, sysdesc);
+       i++)
+    {
+      syscalls[i].name = sysdesc->name;
+      syscalls[i].number = sysdesc->number;
+    }
+
+  /* Add final element marker.  */
+  syscalls[i].name = NULL;
+  syscalls[i].number = 0;
+
+  return syscalls;
+}
+
+/* Return the list of syscall groups.  If no syscall group is
+   available, return NULL.  */
+
+static const char **
+xml_list_of_groups (struct gdbarch *gdbarch)
+{
+  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
+  struct syscall_group_desc *groupdesc;
+  const char **names = NULL;
+  int i;
+  int ngroups;
+
+  if (syscalls_info == NULL)
+    return NULL;
+
+  ngroups = VEC_length (syscall_group_desc_p, syscalls_info->groups);
+  names = xmalloc ((ngroups + 1) * sizeof (char *));
+
+  for (i = 0;
+       VEC_iterate (syscall_group_desc_p,
+		    syscalls_info->groups, i, groupdesc);
+       i++)
+    names[i] = groupdesc->name;
+
+  names[i] = NULL;
+
+  return names;
+}
+
 void
 set_xml_syscall_file_name (struct gdbarch *gdbarch, const char *name)
 {
@@ -422,4 +628,24 @@ get_syscall_names (struct gdbarch *gdbarch)
   return xml_list_of_syscalls (gdbarch);
 }
 
+/* See comment in xml-syscall.h.  */
+
+struct syscall *
+get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
+{
+  init_syscalls_info (gdbarch);
+
+  return xml_list_syscalls_by_group (gdbarch, group);
+}
+
+/* See comment in xml-syscall.h.  */
+
+const char **
+get_syscall_group_names (struct gdbarch *gdbarch)
+{
+  init_syscalls_info (gdbarch);
+
+  return xml_list_of_groups (gdbarch);
+}
+
 #endif /* ! HAVE_LIBEXPAT */
diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
index 42b9dea..9ba4e93 100644
--- a/gdb/xml-syscall.h
+++ b/gdb/xml-syscall.h
@@ -50,4 +50,19 @@ void get_syscall_by_name (struct gdbarch *gdbarch,
 
 const char **get_syscall_names (struct gdbarch *gdbarch);
 
+/* Function used to retrieve the list of syscalls of a given group in
+   the system.  Return a list of syscalls that are element of the
+   group, terminated by an empty element. The list is malloc'ed
+   and must be freed by the caller.  If group doesn't exist, return
+   NULL.  */
+
+struct syscall *get_syscalls_by_group (struct gdbarch *gdbarch,
+				       const char *group);
+
+/* Function used to retrieve the list of syscall groups in the system.
+   Return an array of strings terminated by a NULL element.  The list
+   must be freed by the caller.  */
+
+const char **get_syscall_group_names (struct gdbarch *gdbarch);
+
 #endif /* XML_SYSCALL_H */
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v2 3/4] Create syscall groups for x86_64.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
                     ` (5 preceding siblings ...)
  2014-11-21 19:06   ` [PATCH v2 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
@ 2014-11-21 19:06   ` Gabriel Krisman Bertazi
  2015-01-15  8:28     ` Doug Evans
  6 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-21 19:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

This commit introduces the following syscall groups for the x86_64
architecture: memory, ipc, process, descriptor, signal and file.

Please note that the sorting of the syscalls among these several groups
follows the same structure used in strace.

This also introduces tests for catching groups of syscalls on the x86_64
architecture.

gdb/

	* syscalls/amd64-linux.xml: Add 'groups' attribute to several
	syscalls on x86_64.  Create groups memory, ipc, file,
	descriptor, process and signal.

gdb/testsuite/

	* gdb.base/catch-syscall.exp (do_syscall_tests): Add call
	to test_catch_syscall_group.
	(test_catch_syscall_group): New.
---
 gdb/syscalls/amd64-linux.xml             | 362 +++++++++++++++----------------
 gdb/testsuite/gdb.base/catch-syscall.exp |  33 +++
 2 files changed, 214 insertions(+), 181 deletions(-)

diff --git a/gdb/syscalls/amd64-linux.xml b/gdb/syscalls/amd64-linux.xml
index 6a04218..974c5b5 100644
--- a/gdb/syscalls/amd64-linux.xml
+++ b/gdb/syscalls/amd64-linux.xml
@@ -14,101 +14,101 @@
      The file mentioned above belongs to the Linux Kernel.  -->
 
 <syscalls_info>
-  <syscall name="read" number="0"/>
-  <syscall name="write" number="1"/>
-  <syscall name="open" number="2"/>
-  <syscall name="close" number="3"/>
-  <syscall name="stat" number="4"/>
-  <syscall name="fstat" number="5"/>
-  <syscall name="lstat" number="6"/>
-  <syscall name="poll" number="7"/>
-  <syscall name="lseek" number="8"/>
-  <syscall name="mmap" number="9"/>
-  <syscall name="mprotect" number="10"/>
-  <syscall name="munmap" number="11"/>
-  <syscall name="brk" number="12"/>
-  <syscall name="rt_sigaction" number="13"/>
-  <syscall name="rt_sigprocmask" number="14"/>
-  <syscall name="rt_sigreturn" number="15"/>
-  <syscall name="ioctl" number="16"/>
-  <syscall name="pread64" number="17"/>
-  <syscall name="pwrite64" number="18"/>
-  <syscall name="readv" number="19"/>
-  <syscall name="writev" number="20"/>
-  <syscall name="access" number="21"/>
-  <syscall name="pipe" number="22"/>
-  <syscall name="select" number="23"/>
+  <syscall name="read" number="0" groups="descriptor"/>
+  <syscall name="write" number="1" groups="descriptor"/>
+  <syscall name="open" number="2" groups="descriptor,file"/>
+  <syscall name="close" number="3" groups="descriptor"/>
+  <syscall name="stat" number="4" groups="file"/>
+  <syscall name="fstat" number="5" groups="descriptor"/>
+  <syscall name="lstat" number="6" groups="file"/>
+  <syscall name="poll" number="7" groups="descriptor"/>
+  <syscall name="lseek" number="8" groups="descriptor"/>
+  <syscall name="mmap" number="9" groups="descriptor,memory"/>
+  <syscall name="mprotect" number="10" groups="memory"/>
+  <syscall name="munmap" number="11" groups="memory"/>
+  <syscall name="brk" number="12" groups="memory"/>
+  <syscall name="rt_sigaction" number="13" groups="signal"/>
+  <syscall name="rt_sigprocmask" number="14" groups="signal"/>
+  <syscall name="rt_sigreturn" number="15" groups="signal"/>
+  <syscall name="ioctl" number="16" groups="descriptor"/>
+  <syscall name="pread64" number="17" groups="descriptor"/>
+  <syscall name="pwrite64" number="18" groups="descriptor"/>
+  <syscall name="readv" number="19" groups="descriptor"/>
+  <syscall name="writev" number="20" groups="descriptor"/>
+  <syscall name="access" number="21" groups="file"/>
+  <syscall name="pipe" number="22" groups="descriptor"/>
+  <syscall name="select" number="23" groups="descriptor"/>
   <syscall name="sched_yield" number="24"/>
-  <syscall name="mremap" number="25"/>
-  <syscall name="msync" number="26"/>
-  <syscall name="mincore" number="27"/>
-  <syscall name="madvise" number="28"/>
-  <syscall name="shmget" number="29"/>
-  <syscall name="shmat" number="30"/>
-  <syscall name="shmctl" number="31"/>
-  <syscall name="dup" number="32"/>
-  <syscall name="dup2" number="33"/>
-  <syscall name="pause" number="34"/>
+  <syscall name="mremap" number="25" groups="memory"/>
+  <syscall name="msync" number="26" groups="memory"/>
+  <syscall name="mincore" number="27" groups="memory"/>
+  <syscall name="madvise" number="28" groups="memory"/>
+  <syscall name="shmget" number="29" groups="ipc"/>
+  <syscall name="shmat" number="30" groups="memory,ipc"/>
+  <syscall name="shmctl" number="31" groups="ipc"/>
+  <syscall name="dup" number="32" groups="descriptor"/>
+  <syscall name="dup2" number="33" groups="descriptor"/>
+  <syscall name="pause" number="34" groups="signal"/>
   <syscall name="nanosleep" number="35"/>
   <syscall name="getitimer" number="36"/>
   <syscall name="alarm" number="37"/>
   <syscall name="setitimer" number="38"/>
   <syscall name="getpid" number="39"/>
-  <syscall name="sendfile" number="40"/>
-  <syscall name="socket" number="41"/>
-  <syscall name="connect" number="42"/>
-  <syscall name="accept" number="43"/>
-  <syscall name="sendto" number="44"/>
-  <syscall name="recvfrom" number="45"/>
-  <syscall name="sendmsg" number="46"/>
-  <syscall name="recvmsg" number="47"/>
-  <syscall name="shutdown" number="48"/>
-  <syscall name="bind" number="49"/>
-  <syscall name="listen" number="50"/>
-  <syscall name="getsockname" number="51"/>
-  <syscall name="getpeername" number="52"/>
-  <syscall name="socketpair" number="53"/>
-  <syscall name="setsockopt" number="54"/>
-  <syscall name="getsockopt" number="55"/>
-  <syscall name="clone" number="56"/>
-  <syscall name="fork" number="57"/>
-  <syscall name="vfork" number="58"/>
-  <syscall name="execve" number="59"/>
-  <syscall name="exit" number="60"/>
-  <syscall name="wait4" number="61"/>
-  <syscall name="kill" number="62"/>
+  <syscall name="sendfile" number="40" groups="network,descriptor"/>
+  <syscall name="socket" number="41" groups="network"/>
+  <syscall name="connect" number="42" groups="network"/>
+  <syscall name="accept" number="43" groups="network"/>
+  <syscall name="sendto" number="44" groups="network"/>
+  <syscall name="recvfrom" number="45" groups="network"/>
+  <syscall name="sendmsg" number="46" groups="network"/>
+  <syscall name="recvmsg" number="47" groups="network"/>
+  <syscall name="shutdown" number="48" groups="network"/>
+  <syscall name="bind" number="49" groups="network"/>
+  <syscall name="listen" number="50" groups="network"/>
+  <syscall name="getsockname" number="51" groups="network"/>
+  <syscall name="getpeername" number="52" groups="network"/>
+  <syscall name="socketpair" number="53" groups="network"/>
+  <syscall name="setsockopt" number="54" groups="network"/>
+  <syscall name="getsockopt" number="55" groups="network"/>
+  <syscall name="clone" number="56" groups="process"/>
+  <syscall name="fork" number="57" groups="process"/>
+  <syscall name="vfork" number="58" groups="process"/>
+  <syscall name="execve" number="59" groups="process,file"/>
+  <syscall name="exit" number="60" groups="process"/>
+  <syscall name="wait4" number="61" groups="process"/>
+  <syscall name="kill" number="62" groups="signal"/>
   <syscall name="uname" number="63"/>
-  <syscall name="semget" number="64"/>
-  <syscall name="semop" number="65"/>
-  <syscall name="semctl" number="66"/>
-  <syscall name="shmdt" number="67"/>
-  <syscall name="msgget" number="68"/>
-  <syscall name="msgsnd" number="69"/>
-  <syscall name="msgrcv" number="70"/>
-  <syscall name="msgctl" number="71"/>
-  <syscall name="fcntl" number="72"/>
-  <syscall name="flock" number="73"/>
-  <syscall name="fsync" number="74"/>
-  <syscall name="fdatasync" number="75"/>
-  <syscall name="truncate" number="76"/>
-  <syscall name="ftruncate" number="77"/>
-  <syscall name="getdents" number="78"/>
-  <syscall name="getcwd" number="79"/>
-  <syscall name="chdir" number="80"/>
-  <syscall name="fchdir" number="81"/>
-  <syscall name="rename" number="82"/>
-  <syscall name="mkdir" number="83"/>
-  <syscall name="rmdir" number="84"/>
-  <syscall name="creat" number="85"/>
-  <syscall name="link" number="86"/>
-  <syscall name="unlink" number="87"/>
-  <syscall name="symlink" number="88"/>
-  <syscall name="readlink" number="89"/>
-  <syscall name="chmod" number="90"/>
-  <syscall name="fchmod" number="91"/>
-  <syscall name="chown" number="92"/>
-  <syscall name="fchown" number="93"/>
-  <syscall name="lchown" number="94"/>
+  <syscall name="semget" number="64" groups="ipc"/>
+  <syscall name="semop" number="65" groups="ipc"/>
+  <syscall name="semctl" number="66" groups="ipc"/>
+  <syscall name="shmdt" number="67" groups="memory,ipc"/>
+  <syscall name="msgget" number="68" groups="ipc"/>
+  <syscall name="msgsnd" number="69" groups="ipc"/>
+  <syscall name="msgrcv" number="70" groups="ipc"/>
+  <syscall name="msgctl" number="71" groups="ipc"/>
+  <syscall name="fcntl" number="72" groups="descriptor"/>
+  <syscall name="flock" number="73" groups="descriptor"/>
+  <syscall name="fsync" number="74" groups="descriptor"/>
+  <syscall name="fdatasync" number="75" groups="descriptor"/>
+  <syscall name="truncate" number="76" groups="file"/>
+  <syscall name="ftruncate" number="77" groups="descriptor"/>
+  <syscall name="getdents" number="78" groups="descriptor"/>
+  <syscall name="getcwd" number="79" groups="file"/>
+  <syscall name="chdir" number="80" groups="file"/>
+  <syscall name="fchdir" number="81" groups="descriptor"/>
+  <syscall name="rename" number="82" groups="file"/>
+  <syscall name="mkdir" number="83" groups="file"/>
+  <syscall name="rmdir" number="84" groups="file"/>
+  <syscall name="creat" number="85" groups="file,descriptor"/>
+  <syscall name="link" number="86" groups="file"/>
+  <syscall name="unlink" number="87" groups="file"/>
+  <syscall name="symlink" number="88" groups="file"/>
+  <syscall name="readlink" number="89" groups="file"/>
+  <syscall name="chmod" number="90" groups="file"/>
+  <syscall name="fchmod" number="91" groups="descriptor"/>
+  <syscall name="chown" number="92" groups="file"/>
+  <syscall name="fchown" number="93" groups="descriptor"/>
+  <syscall name="lchown" number="94" groups="file"/>
   <syscall name="umask" number="95"/>
   <syscall name="gettimeofday" number="96"/>
   <syscall name="getrlimit" number="97"/>
@@ -141,18 +141,18 @@
   <syscall name="getsid" number="124"/>
   <syscall name="capget" number="125"/>
   <syscall name="capset" number="126"/>
-  <syscall name="rt_sigpending" number="127"/>
-  <syscall name="rt_sigtimedwait" number="128"/>
-  <syscall name="rt_sigqueueinfo" number="129"/>
-  <syscall name="rt_sigsuspend" number="130"/>
-  <syscall name="sigaltstack" number="131"/>
-  <syscall name="utime" number="132"/>
-  <syscall name="mknod" number="133"/>
-  <syscall name="uselib" number="134"/>
+  <syscall name="rt_sigpending" number="127" groups="signal"/>
+  <syscall name="rt_sigtimedwait" number="128" groups="signal"/>
+  <syscall name="rt_sigqueueinfo" number="129" groups="signal"/>
+  <syscall name="rt_sigsuspend" number="130" groups="signal"/>
+  <syscall name="sigaltstack" number="131" groups="signal"/>
+  <syscall name="utime" number="132" groups="file"/>
+  <syscall name="mknod" number="133" groups="file"/>
+  <syscall name="uselib" number="134" groups="file"/>
   <syscall name="personality" number="135"/>
   <syscall name="ustat" number="136"/>
-  <syscall name="statfs" number="137"/>
-  <syscall name="fstatfs" number="138"/>
+  <syscall name="statfs" number="137" groups="file"/>
+  <syscall name="fstatfs" number="138" groups="descriptor"/>
   <syscall name="sysfs" number="139"/>
   <syscall name="getpriority" number="140"/>
   <syscall name="setpriority" number="141"/>
@@ -163,26 +163,26 @@
   <syscall name="sched_get_priority_max" number="146"/>
   <syscall name="sched_get_priority_min" number="147"/>
   <syscall name="sched_rr_get_interval" number="148"/>
-  <syscall name="mlock" number="149"/>
-  <syscall name="munlock" number="150"/>
-  <syscall name="mlockall" number="151"/>
-  <syscall name="munlockall" number="152"/>
+  <syscall name="mlock" number="149" groups="memory"/>
+  <syscall name="munlock" number="150" groups="memory"/>
+  <syscall name="mlockall" number="151" groups="memory"/>
+  <syscall name="munlockall" number="152" groups="memory"/>
   <syscall name="vhangup" number="153"/>
   <syscall name="modify_ldt" number="154"/>
-  <syscall name="pivot_root" number="155"/>
+  <syscall name="pivot_root" number="155" groups="file"/>
   <syscall name="_sysctl" number="156"/>
   <syscall name="prctl" number="157"/>
-  <syscall name="arch_prctl" number="158"/>
+  <syscall name="arch_prctl" number="158" groups="process"/>
   <syscall name="adjtimex" number="159"/>
   <syscall name="setrlimit" number="160"/>
-  <syscall name="chroot" number="161"/>
+  <syscall name="chroot" number="161" groups="file"/>
   <syscall name="sync" number="162"/>
-  <syscall name="acct" number="163"/>
+  <syscall name="acct" number="163" groups="file"/>
   <syscall name="settimeofday" number="164"/>
-  <syscall name="mount" number="165"/>
-  <syscall name="umount2" number="166"/>
-  <syscall name="swapon" number="167"/>
-  <syscall name="swapoff" number="168"/>
+  <syscall name="mount" number="165" groups="file"/>
+  <syscall name="umount2" number="166" groups="file"/>
+  <syscall name="swapon" number="167" groups="file"/>
+  <syscall name="swapoff" number="168" groups="file"/>
   <syscall name="reboot" number="169"/>
   <syscall name="sethostname" number="170"/>
   <syscall name="setdomainname" number="171"/>
@@ -193,7 +193,7 @@
   <syscall name="delete_module" number="176"/>
   <syscall name="get_kernel_syms" number="177"/>
   <syscall name="query_module" number="178"/>
-  <syscall name="quotactl" number="179"/>
+  <syscall name="quotactl" number="179" groups="file"/>
   <syscall name="nfsservctl" number="180"/>
   <syscall name="getpmsg" number="181"/>
   <syscall name="putpmsg" number="182"/>
@@ -201,20 +201,20 @@
   <syscall name="tuxcall" number="184"/>
   <syscall name="security" number="185"/>
   <syscall name="gettid" number="186"/>
-  <syscall name="readahead" number="187"/>
-  <syscall name="setxattr" number="188"/>
-  <syscall name="lsetxattr" number="189"/>
-  <syscall name="fsetxattr" number="190"/>
-  <syscall name="getxattr" number="191"/>
-  <syscall name="lgetxattr" number="192"/>
-  <syscall name="fgetxattr" number="193"/>
-  <syscall name="listxattr" number="194"/>
-  <syscall name="llistxattr" number="195"/>
-  <syscall name="flistxattr" number="196"/>
-  <syscall name="removexattr" number="197"/>
-  <syscall name="lremovexattr" number="198"/>
-  <syscall name="fremovexattr" number="199"/>
-  <syscall name="tkill" number="200"/>
+  <syscall name="readahead" number="187" groups="descriptor"/>
+  <syscall name="setxattr" number="188" groups="file"/>
+  <syscall name="lsetxattr" number="189" groups="file"/>
+  <syscall name="fsetxattr" number="190" groups="descriptor"/>
+  <syscall name="getxattr" number="191" groups="file"/>
+  <syscall name="lgetxattr" number="192" groups="file"/>
+  <syscall name="fgetxattr" number="193" groups="descriptor"/>
+  <syscall name="listxattr" number="194" groups="file"/>
+  <syscall name="llistxattr" number="195" groups="file"/>
+  <syscall name="flistxattr" number="196" groups="descriptor"/>
+  <syscall name="removexattr" number="197" groups="file"/>
+  <syscall name="lremovexattr" number="198" groups="file"/>
+  <syscall name="fremovexattr" number="199" groups="descriptor"/>
+  <syscall name="tkill" number="200" groups="signal"/>
   <syscall name="time" number="201"/>
   <syscall name="futex" number="202"/>
   <syscall name="sched_setaffinity" number="203"/>
@@ -227,15 +227,15 @@
   <syscall name="io_cancel" number="210"/>
   <syscall name="get_thread_area" number="211"/>
   <syscall name="lookup_dcookie" number="212"/>
-  <syscall name="epoll_create" number="213"/>
+  <syscall name="epoll_create" number="213" groups="descriptor"/>
   <syscall name="epoll_ctl_old" number="214"/>
   <syscall name="epoll_wait_old" number="215"/>
-  <syscall name="remap_file_pages" number="216"/>
-  <syscall name="getdents64" number="217"/>
+  <syscall name="remap_file_pages" number="216" groups="memory"/>
+  <syscall name="getdents64" number="217" groups="descriptor"/>
   <syscall name="set_tid_address" number="218"/>
   <syscall name="restart_syscall" number="219"/>
-  <syscall name="semtimedop" number="220"/>
-  <syscall name="fadvise64" number="221"/>
+  <syscall name="semtimedop" number="220" groups="ipc"/>
+  <syscall name="fadvise64" number="221" groups="descriptor"/>
   <syscall name="timer_create" number="222"/>
   <syscall name="timer_settime" number="223"/>
   <syscall name="timer_gettime" number="224"/>
@@ -245,15 +245,15 @@
   <syscall name="clock_gettime" number="228"/>
   <syscall name="clock_getres" number="229"/>
   <syscall name="clock_nanosleep" number="230"/>
-  <syscall name="exit_group" number="231"/>
-  <syscall name="epoll_wait" number="232"/>
-  <syscall name="epoll_ctl" number="233"/>
-  <syscall name="tgkill" number="234"/>
-  <syscall name="utimes" number="235"/>
+  <syscall name="exit_group" number="231" groups="process"/>
+  <syscall name="epoll_wait" number="232" groups="descriptor"/>
+  <syscall name="epoll_ctl" number="233" groups="descriptor"/>
+  <syscall name="tgkill" number="234" groups="signal"/>
+  <syscall name="utimes" number="235" groups="file"/>
   <syscall name="vserver" number="236"/>
-  <syscall name="mbind" number="237"/>
-  <syscall name="set_mempolicy" number="238"/>
-  <syscall name="get_mempolicy" number="239"/>
+  <syscall name="mbind" number="237" groups="memory"/>
+  <syscall name="set_mempolicy" number="238" groups="memory"/>
+  <syscall name="get_mempolicy" number="239" groups="memory"/>
   <syscall name="mq_open" number="240"/>
   <syscall name="mq_unlink" number="241"/>
   <syscall name="mq_timedsend" number="242"/>
@@ -261,54 +261,54 @@
   <syscall name="mq_notify" number="244"/>
   <syscall name="mq_getsetattr" number="245"/>
   <syscall name="kexec_load" number="246"/>
-  <syscall name="waitid" number="247"/>
+  <syscall name="waitid" number="247" groups="process"/>
   <syscall name="add_key" number="248"/>
   <syscall name="request_key" number="249"/>
   <syscall name="keyctl" number="250"/>
   <syscall name="ioprio_set" number="251"/>
   <syscall name="ioprio_get" number="252"/>
-  <syscall name="inotify_init" number="253"/>
-  <syscall name="inotify_add_watch" number="254"/>
-  <syscall name="inotify_rm_watch" number="255"/>
-  <syscall name="migrate_pages" number="256"/>
-  <syscall name="openat" number="257"/>
-  <syscall name="mkdirat" number="258"/>
-  <syscall name="mknodat" number="259"/>
-  <syscall name="fchownat" number="260"/>
-  <syscall name="futimesat" number="261"/>
-  <syscall name="newfstatat" number="262"/>
-  <syscall name="unlinkat" number="263"/>
-  <syscall name="renameat" number="264"/>
-  <syscall name="linkat" number="265"/>
-  <syscall name="symlinkat" number="266"/>
-  <syscall name="readlinkat" number="267"/>
-  <syscall name="fchmodat" number="268"/>
-  <syscall name="faccessat" number="269"/>
-  <syscall name="pselect6" number="270"/>
-  <syscall name="ppoll" number="271"/>
-  <syscall name="unshare" number="272"/>
+  <syscall name="inotify_init" number="253" groups="descriptor"/>
+  <syscall name="inotify_add_watch" number="254" groups="descriptor"/>
+  <syscall name="inotify_rm_watch" number="255" groups="descriptor"/>
+  <syscall name="migrate_pages" number="256" groups="memory"/>
+  <syscall name="openat" number="257" groups="file,descriptor"/>
+  <syscall name="mkdirat" number="258" groups="file,descriptor"/>
+  <syscall name="mknodat" number="259" groups="file,descriptor"/>
+  <syscall name="fchownat" number="260" groups="file,descriptor"/>
+  <syscall name="futimesat" number="261" groups="file,descriptor"/>
+  <syscall name="newfstatat" number="262" groups="file,descriptor"/>
+  <syscall name="unlinkat" number="263" groups="file,descriptor"/>
+  <syscall name="renameat" number="264" groups="file,descriptor"/>
+  <syscall name="linkat" number="265" groups="file,descriptor"/>
+  <syscall name="symlinkat" number="266" groups="file,descriptor"/>
+  <syscall name="readlinkat" number="267" groups="file,descriptor"/>
+  <syscall name="fchmodat" number="268" groups="file,descriptor"/>
+  <syscall name="faccessat" number="269" groups="file,descriptor"/>
+  <syscall name="pselect6" number="270" groups="descriptor"/>
+  <syscall name="ppoll" number="271" groups="descriptor"/>
+  <syscall name="unshare" number="272" groups="process"/>
   <syscall name="set_robust_list" number="273"/>
   <syscall name="get_robust_list" number="274"/>
-  <syscall name="splice" number="275"/>
-  <syscall name="tee" number="276"/>
-  <syscall name="sync_file_range" number="277"/>
-  <syscall name="vmsplice" number="278"/>
-  <syscall name="move_pages" number="279"/>
-  <syscall name="utimensat" number="280"/>
-  <syscall name="epoll_pwait" number="281"/>
-  <syscall name="signalfd" number="282"/>
-  <syscall name="timerfd_create" number="283"/>
-  <syscall name="eventfd" number="284"/>
-  <syscall name="fallocate" number="285"/>
-  <syscall name="timerfd_settime" number="286"/>
-  <syscall name="timerfd_gettime" number="287"/>
-  <syscall name="accept4" number="288"/>
-  <syscall name="signalfd4" number="289"/>
-  <syscall name="eventfd2" number="290"/>
-  <syscall name="epoll_create1" number="291"/>
-  <syscall name="dup3" number="292"/>
-  <syscall name="pipe2" number="293"/>
-  <syscall name="inotify_init1" number="294"/>
-  <syscall name="preadv" number="295"/>
-  <syscall name="pwritev" number="296"/>
+  <syscall name="splice" number="275" groups="descriptor"/>
+  <syscall name="tee" number="276" groups="descriptor"/>
+  <syscall name="sync_file_range" number="277" groups="descriptor"/>
+  <syscall name="vmsplice" number="278" groups="descriptor"/>
+  <syscall name="move_pages" number="279" groups="memory"/>
+  <syscall name="utimensat" number="280" groups="file,descriptor"/>
+  <syscall name="epoll_pwait" number="281" groups="descriptor"/>
+  <syscall name="signalfd" number="282" groups="signal,descriptor"/>
+  <syscall name="timerfd_create" number="283" groups="descriptor"/>
+  <syscall name="eventfd" number="284" groups="descriptor"/>
+  <syscall name="fallocate" number="285" groups="descriptor"/>
+  <syscall name="timerfd_settime" number="286" groups="descriptor"/>
+  <syscall name="timerfd_gettime" number="287" groups="descriptor"/>
+  <syscall name="accept4" number="288" groups="network"/>
+  <syscall name="signalfd4" number="289" groups="signal,descriptor"/>
+  <syscall name="eventfd2" number="290" groups="descriptor"/>
+  <syscall name="epoll_create1" number="291" groups="descriptor"/>
+  <syscall name="dup3" number="292" groups="descriptor"/>
+  <syscall name="pipe2" number="293" groups="descriptor"/>
+  <syscall name="inotify_init1" number="294" groups="descriptor"/>
+  <syscall name="preadv" number="295" groups="descriptor"/>
+  <syscall name="pwritev" number="296" groups="descriptor"/>
 </syscalls_info>
diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
index ed87d61..c061414 100644
--- a/gdb/testsuite/gdb.base/catch-syscall.exp
+++ b/gdb/testsuite/gdb.base/catch-syscall.exp
@@ -275,6 +275,36 @@ proc test_catch_syscall_fail_nodatadir {} {
     }
 }
 
+proc test_catch_syscall_group {} {
+    global decimal
+
+    # Until we have syscall groups to test on other targets.
+    if { ![istarget "x86_64-*-linux*"] } then {
+	return
+    }
+    set sysnum "\\\[${decimal}\\\]"
+
+    gdb_test "catch syscall g:process" \
+	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \
+	"set catchpoint on a group of syscalls"
+
+    gdb_test "catch syscall g:process read" \
+	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \
+	"set catchpoints on a group of syscalls and on a single syscall"
+
+    gdb_test "complete catch syscall g:proc" \
+	"catch syscall g:process" \
+	"complete catch syscall group with 'g:' prefix"
+
+    gdb_test "complete catch syscall group:proc" \
+	"catch syscall group:process" \
+	"complete catch syscall group with 'group:' prefix"
+
+    gdb_test "complete catch syscall g" \
+	".*group:process.*" \
+	"complete catch syscall group suggests 'group:' prefix"
+}
+
 proc do_syscall_tests {} {
     # NOTE: We don't have to point gdb at the correct data-directory.
     # For the build tree that is handled by INTERNAL_GDBFLAGS.
@@ -315,6 +345,9 @@ proc do_syscall_tests {} {
     # Testing if the 'catch syscall' command works when switching to
     # different architectures on-the-fly (PR gdb/10737).
     if [runto_main] then { test_catch_syscall_multi_arch }
+
+    # Testing the 'catch' syscall command for a group of syscalls.
+    if [runto_main] then { test_catch_syscall_group }
 }
 
 proc test_catch_syscall_without_args_noxml {} {
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH v2 4/4] Update documentation on catching a group of related syscalls.
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
                     ` (4 preceding siblings ...)
  2014-11-21 19:05   ` [PATCH v2 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
@ 2014-11-21 19:06   ` Gabriel Krisman Bertazi
  2014-11-21 19:48     ` Eli Zaretskii
  2014-11-21 19:06   ` [PATCH v2 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
  6 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-21 19:06 UTC (permalink / raw)
  To: gdb-patches; +Cc: Gabriel Krisman Bertazi

gdb/

	* breakpoint.c (_initialize_breakpoint): Update catch syscall
	command documentation.
	* NEWS: Include section about catching groups of syscalls.

gdb/doc/

	* gdb.texinfo (Set Catchpoints): Add 'group' argument to catch
	syscall.
---
 gdb/NEWS            |  5 +++++
 gdb/breakpoint.c    | 10 +++++-----
 gdb/doc/gdb.texinfo | 28 +++++++++++++++++++++++++++-
 3 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/gdb/NEWS b/gdb/NEWS
index d6a8b61..c901215 100644
--- a/gdb/NEWS
+++ b/gdb/NEWS
@@ -60,6 +60,11 @@ SGI Irix-6.x				mips-*-irix6*
 VAX running (4.2 - 4.3 Reno) BSD 	vax-*-bsd*
 VAX running Ultrix 			vax-*-ultrix*
 
+* The "catch syscall" command catches groups of related syscalls.
+
+  The "catch syscall" command now supports catching a group of related
+  syscalls using the 'group:' or 'g:' prefix.
+
 *** Changes in GDB 7.8
 
 * New command line options
diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 098e28d..c952d9a 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -16660,11 +16660,11 @@ If REGEX is given, only stop for libraries matching the regular expression."),
 		     CATCH_PERMANENT,
 		     CATCH_TEMPORARY);
   add_catch_command ("syscall", _("\
-Catch system calls by their names and/or numbers.\n\
-Arguments say which system calls to catch.  If no arguments\n\
-are given, every system call will be caught.\n\
-Arguments, if given, should be one or more system call names\n\
-(if your system supports that), or system call numbers."),
+Catch system calls by their names, groups and/or numbers.\n\
+Arguments say which system calls to catch.  If no arguments are given,\n\
+every system call will be caught.  Arguments, if given, should be one\n\
+or more system call names (if your system supports that), system call\n\
+groups or system call numbers."),
 		     catch_syscall_command_1,
 		     catch_syscall_completer,
 		     CATCH_PERMANENT,
diff --git a/gdb/doc/gdb.texinfo b/gdb/doc/gdb.texinfo
index 15c2908..83d8d64 100644
--- a/gdb/doc/gdb.texinfo
+++ b/gdb/doc/gdb.texinfo
@@ -4254,7 +4254,7 @@ A call to @code{exec}.  This is currently only available for HP-UX
 and @sc{gnu}/Linux.
 
 @item syscall
-@itemx syscall @r{[}@var{name} @r{|} @var{number}@r{]} @dots{} 
+@itemx syscall @r{[}@var{name} @r{|} @var{number} @r{|} @r{group:}@var{groupname} @r{|} @r{g:}@var{groupname}@r{]} @dots{}
 @kindex catch syscall
 @cindex break on a system call.
 A call to or return from a system call, a.k.a.@: @dfn{syscall}.  A
@@ -4289,6 +4289,15 @@ may be useful if @value{GDBN}'s database does not have the complete
 list of syscalls on your system (e.g., because @value{GDBN} lags
 behind the OS upgrades).
 
+You may specify a group of related syscalls to be caught at once using
+the @code{group:} syntax (@code{g:} is a shorter equivalent.).  For
+instance, on some platforms @value{GDBN} allows you to catch all
+network related syscalls, by passing the argument @code{group:network}
+to @code{catch syscall}.  Note that not all syscall groups are
+available in every system.  You can use the command completion
+facilities (@pxref{Completion,, command completion}) to list the
+syscall groups available on your environment.
+
 The example below illustrates how this command works if you don't provide
 arguments to it:
 
@@ -4345,6 +4354,23 @@ Program exited normally.
 (@value{GDBP})
 @end smallexample
 
+Here is an example of catching a syscall group:
+
+@smallexample
+(@value{GDBP}) catch syscall group:process
+Catchpoint 1 (syscalls 'exit' [1] 'fork' [2] 'waitpid' [7]
+'execve' [11] 'wait4' [114] 'clone' [120] 'vfork' [190]
+'exit_group' [252] 'waitid' [284] 'unshare' [310])
+(@value{GDBP}) r
+Starting program: /tmp/catch-syscall
+
+Catchpoint 1 (call to syscall fork), 0x00007ffff7df4e27 in open64 ()
+   from /lib64/ld-linux-x86-64.so.2
+
+(@value{GDBP}) c
+Continuing.
+@end smallexample
+
 However, there can be situations when there is no corresponding name
 in XML file for that syscall number.  In this case, @value{GDBN} prints
 a warning message saying that it was not able to find the syscall name,
-- 
1.9.3

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 4/4] Update documentation on catching a group of related syscalls.
  2014-11-21 19:06   ` [PATCH v2 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
@ 2014-11-21 19:48     ` Eli Zaretskii
  2014-11-26  3:58       ` Gabriel Krisman Bertazi
  0 siblings, 1 reply; 32+ messages in thread
From: Eli Zaretskii @ 2014-11-21 19:48 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches, gabriel

> From: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Cc: Gabriel Krisman Bertazi <gabriel@krisman.be>
> Date: Fri, 21 Nov 2014 17:05:31 -0200
> 
> gdb/
> 
> 	* breakpoint.c (_initialize_breakpoint): Update catch syscall
> 	command documentation.
> 	* NEWS: Include section about catching groups of syscalls.
> 
> gdb/doc/
> 
> 	* gdb.texinfo (Set Catchpoints): Add 'group' argument to catch
> 	syscall.

OK for the documentation parts (didn't I approve them already?).

Thanks.

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 2/4] Add support to catch groups of syscalls.
  2014-11-21 19:05   ` [PATCH v2 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
@ 2014-11-21 21:34     ` Sergio Durigan Junior
  2015-01-15  8:12     ` Doug Evans
  1 sibling, 0 replies; 32+ messages in thread
From: Sergio Durigan Junior @ 2014-11-21 21:34 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Friday, November 21 2014, Gabriel Krisman Bertazi wrote:

> This implements the catchpoint side.  While parsing 'catch syscall'
> arguments, we verify if the argument is a syscall group and expand it to
> a list of syscalls that are part of that group.

Thanks for the patch.  Just a few nits.

> gdb/
>
> 	* breakpoint.c (catch_syscall_split_args): Verify if argument
> 	is a syscall group and expand it to a list of syscalls when
> 	creating catchpoints.
> 	(catch_syscall_completer): Add word completion for system call
> 	groups.
> ---
>  gdb/breakpoint.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 86 insertions(+), 9 deletions(-)
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 7b56260..098e28d 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -12058,10 +12058,39 @@ catch_syscall_split_args (char *arg)
>        cur_name[i] = '\0';
>        arg += i;
>  
> -      /* Check if the user provided a syscall name or a number.  */
> +      /* Check if the user provided a syscall name, group, or a
> +	 number.  */
>        syscall_number = (int) strtol (cur_name, &endptr, 0);
>        if (*endptr == '\0')
> -	get_syscall_by_number (gdbarch, syscall_number, &s);
> +	{
> +	  get_syscall_by_number (gdbarch, syscall_number, &s);
> +	  VEC_safe_push (int, result, s.number);
> +	}
> +      else if (strncmp (cur_name, "g:", 2) == 0
> +	       || strncmp (cur_name, "group:", 6) == 0)

I'm not a fan of using numbers here.  I prefer something like:

  if (strncmp (cur_name, "g:", sizeof ("g:") -1) == 0)

which is a dialect used everywhere in GDB.

> +	{
> +	  /* We have a syscall group.  Let's expand it into a syscall
> +	     list before inserting.  */
> +	  struct syscall *syscall_list;
> +	  const char *group_name;
> +
> +	  /* Skip over "g:" and "group:" prefix strings.  */
> +	  group_name = strchr (cur_name, ':') + 1;
> +
> +	  syscall_list = get_syscalls_by_group (gdbarch, group_name);
> +
> +	  if (syscall_list == NULL)
> +	    error (_("Unknown syscall group '%s'."), group_name);
> +
> +	  for (i = 0; syscall_list[i].name != NULL; i++)
> +	    {
> +	      /* Insert each syscall that are part of the group.  No
> +		 need to check if it is valid.  */
> +	      VEC_safe_push (int, result, syscall_list[i].number);
> +	    }
> +
> +	  xfree (syscall_list);
> +	}
>        else
>  	{
>  	  /* We have a name.  Let's check if it's valid and convert it
> @@ -12073,10 +12102,10 @@ catch_syscall_split_args (char *arg)
>  	       because GDB cannot do anything useful if there's no
>  	       syscall number to be caught.  */
>  	    error (_("Unknown syscall name '%s'."), cur_name);
> -	}
>  
> -      /* Ok, it's valid.  */
> -      VEC_safe_push (int, result, s.number);
> +	  /* Ok, it's valid.  */
> +	  VEC_safe_push (int, result, s.number);
> +	}
>      }
>  
>    discard_cleanups (cleanup);
> @@ -15350,11 +15379,59 @@ static VEC (char_ptr) *
>  catch_syscall_completer (struct cmd_list_element *cmd,
>                           const char *text, const char *word)
>  {
> -  const char **list = get_syscall_names (get_current_arch ());
> -  VEC (char_ptr) *retlist
> -    = (list == NULL) ? NULL : complete_on_enum (list, word, word);
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  struct cleanup *cleanups;

I know you're initializing the "cleanups" both on "if" and on "else",
but I'd prefer if you did:

  struct cleanup *cleanups = make_cleanup (null_cleanup, NULL);

This way, if someone touches the code and removes the initialization
from some the if/else parts, the code would still DTRT.

> +  VEC (char_ptr) *group_retlist = NULL;
> +  VEC (char_ptr) *syscall_retlist = NULL;
> +  VEC (char_ptr) *retlist = NULL;
> +  const char **group_list = NULL;
> +  const char **syscall_list = NULL;
> +  const char *prefix;
> +  int i;
> +
> +  /* Completion considers ':' to be a word separator, so we use this to
> +     verify whether the previous word was a group prefix.  If so, we
> +     build the completion list using group names only.  */
> +  for (prefix = word; prefix != text && prefix[-1] != ' '; prefix--)
> +    ;
> +
> +  if (strncmp (prefix, "g:", 2) == 0 || strncmp (prefix, "group:", 6) == 0)

Same comment about using 'sizeof ("str") - 1' applies here.

> +    {
> +      /* Perform completion inside 'group:' namespace only.  */
> +      group_list = get_syscall_group_names (gdbarch);
> +      cleanups = make_cleanup (xfree, group_list);

If you follow my advice above, there's no need to do this assignment;
just call make_cleanup.

> +      retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);
> +    }
> +  else
> +    {
> +      /* Complete with both, syscall names and groups.  */
> +      syscall_list = get_syscall_names (gdbarch);
> +      group_list = get_syscall_group_names (gdbarch);
> +      cleanups = make_cleanup (xfree, group_list);
> +
> +      /* Append "group:" prefix to syscall groups.  */
> +      for (i = 0; group_list[i] != NULL; i++)
> +	{
> +	  char *prefixed_group = xstrprintf ("group:%s", group_list[i]);
> +
> +	  group_list[i] = prefixed_group;
> +	  make_cleanup (xfree, prefixed_group);
> +	}
> +
> +      syscall_retlist = (syscall_list == NULL) ?
> +	NULL : complete_on_enum (syscall_list, word, word);
> +      group_retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);
> +
> +      retlist = VEC_merge (char_ptr, syscall_retlist, group_retlist);
> +    }
> +
> +  VEC_free (char_ptr, syscall_retlist);
> +  VEC_free (char_ptr, group_retlist);
> +  xfree (syscall_list);
> +  do_cleanups (cleanups);
>  
> -  xfree (list);
>    return retlist;
>  }
>  
> -- 
> 1.9.3

Other than that, the patch looks good to me now.  I'd say there's no
need to send a v3 just because of those changes; just wait for some
global maintainer to approve it for you now :-).

Thanks for doing this.

-- 
Sergio
GPG key ID: 0x65FC5E36
Please send encrypted e-mail if possible
http://sergiodj.net/

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 4/4] Update documentation on catching a group of related syscalls.
  2014-11-21 19:48     ` Eli Zaretskii
@ 2014-11-26  3:58       ` Gabriel Krisman Bertazi
  0 siblings, 0 replies; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-26  3:58 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 267 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> OK for the documentation parts (didn't I approve them already?).

Yeah. Sorry about that.

I had to fix some stuff on the other parts and mistakenly sent
everything again. :-)

Thanks!

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [ping PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-21 19:05 [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
@ 2014-11-29  0:19 ` Gabriel Krisman Bertazi
  2014-12-08  0:09   ` [ping^2 " Gabriel Krisman Bertazi
  2015-01-15  8:03 ` [PATCH " Doug Evans
  2 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-11-29  0:19 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 12923 bytes --]

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:

> Hello,
>
> These are the updated patches after applying Sergio's suggestions.
>
> Is this good to go?
>

Ping. :)

> gdb/
>
> 	* syscalls/gdb-syscalls.dtd: Include group attribute to the
> 	syscall element.
> 	* xml-syscall.c (get_syscalls_by_group): New.
> 	(get_syscall_group_names): New.
> 	(struct syscall_group_desc): New structure to store group data.
> 	(struct syscalls_info): Include field to store the group list.
> 	(syscalls_info_free_syscall_group_desc): New.
> 	(free_syscalls_info): Free group list.
> 	(syscall_group_create_syscall_group_desc): New.
> 	(syscall_group_add_syscall): New.
> 	(syscall_create_syscall_desc): Add syscall to its groups.
> 	(syscall_start_syscall): Load group attribute.
> 	(syscall_group_get_group_by_name): New.
> 	(xml_list_syscalls_by_group): New.
> 	(xml_list_of_groups): New.
> 	* xml-syscall.h (get_syscalls_by_group): Export function
> 	to retrieve a list of syscalls filtered by the group name.
> 	(get_syscall_group_names): Export function to retrieve the list
> 	of syscall groups.
> ---
>  gdb/syscalls/gdb-syscalls.dtd |   3 +-
>  gdb/xml-syscall.c             | 230 +++++++++++++++++++++++++++++++++++++++++-
>  gdb/xml-syscall.h             |  15 +++
>  3 files changed, 245 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
> index 3ad3625..b60eb74 100644
> --- a/gdb/syscalls/gdb-syscalls.dtd
> +++ b/gdb/syscalls/gdb-syscalls.dtd
> @@ -11,4 +11,5 @@
>  <!ELEMENT syscall		EMPTY>
>  <!ATTLIST syscall
>  	name			CDATA	#REQUIRED
> -	number			CDATA	#REQUIRED>
> +	number			CDATA	#REQUIRED
> +	groups			CDATA	#OPTIONAL>
> diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
> index 987fe7a..0d11c3a 100644
> --- a/gdb/xml-syscall.c
> +++ b/gdb/xml-syscall.c
> @@ -77,6 +77,20 @@ get_syscall_names (struct gdbarch *gdbarch)
>    return NULL;
>  }
>  
> +struct syscall *
> +get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
> +const char **
> +get_syscall_group_names (struct gdbarch *gdbarch)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
>  #else /* ! HAVE_LIBEXPAT */
>  
>  /* Structure which describes a syscall.  */
> @@ -92,6 +106,19 @@ typedef struct syscall_desc
>  } *syscall_desc_p;
>  DEF_VEC_P(syscall_desc_p);
>  
> +/* Structure of a syscall group.  */
> +typedef struct syscall_group_desc
> +{
> +  /* The group name.  */
> +
> +  char *name;
> +
> +  /* The syscalls that are part of the group.  */
> +
> +  VEC(syscall_desc_p) *syscalls;
> +} *syscall_group_desc_p;
> +DEF_VEC_P(syscall_group_desc_p);
> +
>  /* Structure that represents syscalls information.  */
>  struct syscalls_info
>  {
> @@ -99,6 +126,10 @@ struct syscalls_info
>  
>    VEC(syscall_desc_p) *syscalls;
>  
> +  /* The syscall groups.  */
> +
> +  VEC(syscall_group_desc_p) *groups;
> +
>    /* Variable that will hold the last known data-directory.  This is
>       useful to know whether we should re-read the XML info for the
>       target.  */
> @@ -126,11 +157,21 @@ syscalls_info_free_syscalls_desc (struct syscall_desc *sd)
>    xfree (sd->name);
>  }
>  
> +/* Free syscall_group_desc members but not the structure itself.  */
> +
> +static void
> +syscalls_info_free_syscall_group_desc (struct syscall_group_desc *sd)
> +{
> +  VEC_free (syscall_desc_p, sd->syscalls);
> +  xfree (sd->name);
> +}
> +
>  static void
>  free_syscalls_info (void *arg)
>  {
>    struct syscalls_info *syscalls_info = arg;
>    struct syscall_desc *sysdesc;
> +  struct syscall_group_desc *groupdesc;
>    int i;
>  
>    xfree (syscalls_info->my_gdb_datadir);
> @@ -143,6 +184,15 @@ free_syscalls_info (void *arg)
>  	syscalls_info_free_syscalls_desc (sysdesc);
>        VEC_free (syscall_desc_p, syscalls_info->syscalls);
>      }
> +  if (syscalls_info->groups != NULL)
> +    {
> +      for (i = 0;
> +	   VEC_iterate (syscall_group_desc_p,
> +			syscalls_info->groups, i, groupdesc);
> +	   i++)
> +	syscalls_info_free_syscall_group_desc (groupdesc);
> +      VEC_free (syscall_group_desc_p, syscalls_info->groups);
> +    }
>  
>    xfree (syscalls_info);
>  }
> @@ -153,16 +203,71 @@ make_cleanup_free_syscalls_info (struct syscalls_info *syscalls_info)
>    return make_cleanup (free_syscalls_info, syscalls_info);
>  }
>  
> +/* Create a new syscall group.  Return pointer to the
> +   syscall_group_desc structure that represents the new group.  */
> +
> +static struct syscall_group_desc *
> +syscall_group_create_syscall_group_desc (struct syscalls_info *syscalls_info,
> +					 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc = XCNEW (struct syscall_group_desc);
> +
> +  groupdesc->name = xstrdup (group);
> +
> +  VEC_safe_push (syscall_group_desc_p, syscalls_info->groups, groupdesc);
> +
> +  return groupdesc;
> +}
> +
> +/* Add a syscall to the group.  If group doesn't exist, create
> +   it.  */
> +
> +static void
> +syscall_group_add_syscall (struct syscalls_info *syscalls_info,
> +			   struct syscall_desc *syscall,
> +			   const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  /* Search for an existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      break;
> +
> +  if (groupdesc == NULL)
> +    {
> +      /* No group was found with this name.  We must create a new
> +	 one.  */
> +      groupdesc = syscall_group_create_syscall_group_desc (syscalls_info,
> +							   group);
> +    }
> +
> +  VEC_safe_push (syscall_desc_p, groupdesc->syscalls, syscall);
> +}
> +
>  static void
>  syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
> -                             const char *name, int number)
> +                             const char *name, int number,
> +			     char *groups)
>  {
>    struct syscall_desc *sysdesc = XCNEW (struct syscall_desc);
> +  char *group;
>  
>    sysdesc->name = xstrdup (name);
>    sysdesc->number = number;
>  
>    VEC_safe_push (syscall_desc_p, syscalls_info->syscalls, sysdesc);
> +
> +  /*  Add syscall to its groups.  */
> +  if (groups != NULL)
> +    for (group = strtok (groups, ",");
> +	 group != NULL;
> +	 group = strtok (NULL, ","))
> +      syscall_group_add_syscall (syscalls_info, sysdesc, group);
>  }
>  
>  /* Handle the start of a <syscall> element.  */
> @@ -177,6 +282,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>    /* syscall info.  */
>    char *name = NULL;
>    int number = 0;
> +  char *groups = NULL;
>  
>    len = VEC_length (gdb_xml_value_s, attributes);
>  
> @@ -186,13 +292,16 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>          name = attrs[i].value;
>        else if (strcmp (attrs[i].name, "number") == 0)
>          number = * (ULONGEST *) attrs[i].value;
> +      else if (strcmp (attrs[i].name, "groups") == 0)
> +        groups = attrs[i].value;
>        else
>          internal_error (__FILE__, __LINE__,
>                          _("Unknown attribute name '%s'."), attrs[i].name);
>      }
>  
>    gdb_assert (name);
> -  syscall_create_syscall_desc (data->syscalls_info, name, number);
> +
> +  syscall_create_syscall_desc (data->syscalls_info, name, number, groups);
>  }
>  
>  
> @@ -200,6 +309,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>  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 },
> +  { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { NULL, GDB_XML_AF_NONE, NULL, NULL }
>  };
>  
> @@ -321,6 +431,33 @@ init_syscalls_info (struct gdbarch *gdbarch)
>    set_gdbarch_syscalls_info (gdbarch, syscalls_info);
>  }
>  
> +/* Search for a syscall group by its name.  Return syscall_group_desc
> +   structure for the group if found or NULL otherwise.  */
> +
> +static struct syscall_group_desc *
> +syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
> +				 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  if (group == NULL)
> +    return NULL;
> +
> +   /* Search for existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      return groupdesc;
> +
> +  return NULL;
> +}
> +
>  static int
>  xml_get_syscall_number (struct gdbarch *gdbarch,
>                          const char *syscall_name)
> @@ -388,6 +525,75 @@ xml_list_of_syscalls (struct gdbarch *gdbarch)
>    return names;
>  }
>  
> +/*  Iterate over the syscall_group_desc element to return a list of
> +    syscalls that are part of the given group, terminated by an empty
> +    element.  If the syscall group doesn't exist, return NULL.  */
> +
> +static struct syscall *
> +xml_list_syscalls_by_group (struct gdbarch *gdbarch,
> +			    const char *group)
> +{
> +  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
> +  struct syscall_group_desc *groupdesc;
> +  struct syscall_desc *sysdesc;
> +  struct syscall *syscalls = NULL;
> +  int nsyscalls;
> +  int i;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  groupdesc = syscall_group_get_group_by_name (syscalls_info, group);
> +  if (groupdesc == NULL)
> +    return NULL;
> +
> +  nsyscalls = VEC_length (syscall_desc_p, groupdesc->syscalls);
> +  syscalls = xmalloc ((nsyscalls + 1) * sizeof (struct syscall));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_desc_p, groupdesc->syscalls, i, sysdesc);
> +       i++)
> +    {
> +      syscalls[i].name = sysdesc->name;
> +      syscalls[i].number = sysdesc->number;
> +    }
> +
> +  /* Add final element marker.  */
> +  syscalls[i].name = NULL;
> +  syscalls[i].number = 0;
> +
> +  return syscalls;
> +}
> +
> +/* Return the list of syscall groups.  If no syscall group is
> +   available, return NULL.  */
> +
> +static const char **
> +xml_list_of_groups (struct gdbarch *gdbarch)
> +{
> +  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
> +  struct syscall_group_desc *groupdesc;
> +  const char **names = NULL;
> +  int i;
> +  int ngroups;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  ngroups = VEC_length (syscall_group_desc_p, syscalls_info->groups);
> +  names = xmalloc ((ngroups + 1) * sizeof (char *));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    names[i] = groupdesc->name;
> +
> +  names[i] = NULL;
> +
> +  return names;
> +}
> +
>  void
>  set_xml_syscall_file_name (struct gdbarch *gdbarch, const char *name)
>  {
> @@ -422,4 +628,24 @@ get_syscall_names (struct gdbarch *gdbarch)
>    return xml_list_of_syscalls (gdbarch);
>  }
>  
> +/* See comment in xml-syscall.h.  */
> +
> +struct syscall *
> +get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
> +{
> +  init_syscalls_info (gdbarch);
> +
> +  return xml_list_syscalls_by_group (gdbarch, group);
> +}
> +
> +/* See comment in xml-syscall.h.  */
> +
> +const char **
> +get_syscall_group_names (struct gdbarch *gdbarch)
> +{
> +  init_syscalls_info (gdbarch);
> +
> +  return xml_list_of_groups (gdbarch);
> +}
> +
>  #endif /* ! HAVE_LIBEXPAT */
> diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
> index 42b9dea..9ba4e93 100644
> --- a/gdb/xml-syscall.h
> +++ b/gdb/xml-syscall.h
> @@ -50,4 +50,19 @@ void get_syscall_by_name (struct gdbarch *gdbarch,
>  
>  const char **get_syscall_names (struct gdbarch *gdbarch);
>  
> +/* Function used to retrieve the list of syscalls of a given group in
> +   the system.  Return a list of syscalls that are element of the
> +   group, terminated by an empty element. The list is malloc'ed
> +   and must be freed by the caller.  If group doesn't exist, return
> +   NULL.  */
> +
> +struct syscall *get_syscalls_by_group (struct gdbarch *gdbarch,
> +				       const char *group);
> +
> +/* Function used to retrieve the list of syscall groups in the system.
> +   Return an array of strings terminated by a NULL element.  The list
> +   must be freed by the caller.  */
> +
> +const char **get_syscall_group_names (struct gdbarch *gdbarch);
> +
>  #endif /* XML_SYSCALL_H */

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [ping^2 PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-29  0:19 ` [ping PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
@ 2014-12-08  0:09   ` Gabriel Krisman Bertazi
  2014-12-21 15:59     ` [ping^3 " Gabriel Krisman Bertazi
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-12-08  0:09 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 145 bytes --]

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:

>> Is this good to go?
>>
>
> Ping. :)

ping^2



-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [ping^3 PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-12-08  0:09   ` [ping^2 " Gabriel Krisman Bertazi
@ 2014-12-21 15:59     ` Gabriel Krisman Bertazi
  2015-01-12 20:47       ` Doug Evans
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2014-12-21 15:59 UTC (permalink / raw)
  To: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 324 bytes --]

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:

> Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
>
>>> Is this good to go?
>>>
>>
>> Ping. :)
>
> ping^2

ping^3

Heh. Missed a few weekly pings.  Do you guys think we might get this
upstream anytime soon?

Thanks,

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [ping^3 PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-12-21 15:59     ` [ping^3 " Gabriel Krisman Bertazi
@ 2015-01-12 20:47       ` Doug Evans
  0 siblings, 0 replies; 32+ messages in thread
From: Doug Evans @ 2015-01-12 20:47 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches, sergiodj

Gabriel Krisman Bertazi writes:
 > Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
 > 
 > > Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
 > >
 > >>> Is this good to go?
 > >>>
 > >>
 > >> Ping. :)
 > >
 > > ping^2
 > 
 > ping^3
 > 
 > Heh. Missed a few weekly pings.  Do you guys think we might get this
 > upstream anytime soon?
 > 
 > Thanks,
 > 
 > -- 
 > Gabriel Krisman Bertazi

Hi.

Sorry for the delay.

It's on my list to get reviewed this week.
Please ping me directly if you don't hear from me by Thursday.

[And thanks Sergio for the heads up!]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2014-11-21 19:05 [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
  2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
  2014-11-29  0:19 ` [ping PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
@ 2015-01-15  8:03 ` Doug Evans
  2015-01-29  4:43   ` Gabriel Krisman Bertazi
  2 siblings, 1 reply; 32+ messages in thread
From: Doug Evans @ 2015-01-15  8:03 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
> Hello,
>
> These are the updated patches after applying Sergio's suggestions.
>
> Is this good to go?

Hi.
I didn't make sure that I'm not repeating something Sergio mentioned.

Several nits inline.
Ok with those changes (and those mentioned in other reviews).

>
> gdb/
>
> 	* syscalls/gdb-syscalls.dtd: Include group attribute to the
> 	syscall element.
> 	* xml-syscall.c (get_syscalls_by_group): New.
> 	(get_syscall_group_names): New.
> 	(struct syscall_group_desc): New structure to store group data.
> 	(struct syscalls_info): Include field to store the group list.
> 	(syscalls_info_free_syscall_group_desc): New.
> 	(free_syscalls_info): Free group list.
> 	(syscall_group_create_syscall_group_desc): New.
> 	(syscall_group_add_syscall): New.
> 	(syscall_create_syscall_desc): Add syscall to its groups.
> 	(syscall_start_syscall): Load group attribute.
> 	(syscall_group_get_group_by_name): New.
> 	(xml_list_syscalls_by_group): New.
> 	(xml_list_of_groups): New.
> 	* xml-syscall.h (get_syscalls_by_group): Export function
> 	to retrieve a list of syscalls filtered by the group name.
> 	(get_syscall_group_names): Export function to retrieve the list
> 	of syscall groups.
> ---
>  gdb/syscalls/gdb-syscalls.dtd |   3 +-
>  gdb/xml-syscall.c             | 230 +++++++++++++++++++++++++++++++++++++++++-
>  gdb/xml-syscall.h             |  15 +++
>  3 files changed, 245 insertions(+), 3 deletions(-)
>
> diff --git a/gdb/syscalls/gdb-syscalls.dtd b/gdb/syscalls/gdb-syscalls.dtd
> index 3ad3625..b60eb74 100644
> --- a/gdb/syscalls/gdb-syscalls.dtd
> +++ b/gdb/syscalls/gdb-syscalls.dtd
> @@ -11,4 +11,5 @@
>  <!ELEMENT syscall		EMPTY>
>  <!ATTLIST syscall
>  	name			CDATA	#REQUIRED
> -	number			CDATA	#REQUIRED>
> +	number			CDATA	#REQUIRED
> +	groups			CDATA	#OPTIONAL>
> diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
> index 987fe7a..0d11c3a 100644
> --- a/gdb/xml-syscall.c
> +++ b/gdb/xml-syscall.c
> @@ -77,6 +77,20 @@ get_syscall_names (struct gdbarch *gdbarch)
>    return NULL;
>  }
>  
> +struct syscall *
> +get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
> +const char **
> +get_syscall_group_names (struct gdbarch *gdbarch)
> +{
> +  syscall_warn_user ();
> +  return NULL;
> +}
> +
>  #else /* ! HAVE_LIBEXPAT */
>  
>  /* Structure which describes a syscall.  */
> @@ -92,6 +106,19 @@ typedef struct syscall_desc
>  } *syscall_desc_p;
>  DEF_VEC_P(syscall_desc_p);
>  
> +/* Structure of a syscall group.  */
> +typedef struct syscall_group_desc
> +{
> +  /* The group name.  */
> +
> +  char *name;
> +
> +  /* The syscalls that are part of the group.  */
> +
> +  VEC(syscall_desc_p) *syscalls;
> +} *syscall_group_desc_p;
> +DEF_VEC_P(syscall_group_desc_p);
> +
>  /* Structure that represents syscalls information.  */
>  struct syscalls_info
>  {
> @@ -99,6 +126,10 @@ struct syscalls_info
>  
>    VEC(syscall_desc_p) *syscalls;
>  
> +  /* The syscall groups.  */
> +
> +  VEC(syscall_group_desc_p) *groups;
> +
>    /* Variable that will hold the last known data-directory.  This is
>       useful to know whether we should re-read the XML info for the
>       target.  */
> @@ -126,11 +157,21 @@ syscalls_info_free_syscalls_desc (struct syscall_desc *sd)
>    xfree (sd->name);
>  }
>  
> +/* Free syscall_group_desc members but not the structure itself.  */
> +
> +static void
> +syscalls_info_free_syscall_group_desc (struct syscall_group_desc *sd)
> +{
> +  VEC_free (syscall_desc_p, sd->syscalls);
> +  xfree (sd->name);
> +}
> +
>  static void
>  free_syscalls_info (void *arg)
>  {
>    struct syscalls_info *syscalls_info = arg;
>    struct syscall_desc *sysdesc;
> +  struct syscall_group_desc *groupdesc;
>    int i;
>  
>    xfree (syscalls_info->my_gdb_datadir);
> @@ -143,6 +184,15 @@ free_syscalls_info (void *arg)
>  	syscalls_info_free_syscalls_desc (sysdesc);
>        VEC_free (syscall_desc_p, syscalls_info->syscalls);
>      }
> +  if (syscalls_info->groups != NULL)
> +    {
> +      for (i = 0;
> +	   VEC_iterate (syscall_group_desc_p,
> +			syscalls_info->groups, i, groupdesc);
> +	   i++)
> +	syscalls_info_free_syscall_group_desc (groupdesc);
> +      VEC_free (syscall_group_desc_p, syscalls_info->groups);
> +    }
>  
>    xfree (syscalls_info);
>  }
> @@ -153,16 +203,71 @@ make_cleanup_free_syscalls_info (struct syscalls_info *syscalls_info)
>    return make_cleanup (free_syscalls_info, syscalls_info);
>  }
>  
> +/* Create a new syscall group.  Return pointer to the
> +   syscall_group_desc structure that represents the new group.  */
> +
> +static struct syscall_group_desc *
> +syscall_group_create_syscall_group_desc (struct syscalls_info *syscalls_info,
> +					 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc = XCNEW (struct syscall_group_desc);
> +
> +  groupdesc->name = xstrdup (group);
> +
> +  VEC_safe_push (syscall_group_desc_p, syscalls_info->groups, groupdesc);
> +
> +  return groupdesc;
> +}
> +
> +/* Add a syscall to the group.  If group doesn't exist, create
> +   it.  */

Comments like this always look weird to me.
There's PLENTY of space on the previous line so "it"
doesn't have to appear by itself.

> +
> +static void
> +syscall_group_add_syscall (struct syscalls_info *syscalls_info,
> +			   struct syscall_desc *syscall,
> +			   const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  /* Search for an existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      break;
> +
> +  if (groupdesc == NULL)
> +    {
> +      /* No group was found with this name.  We must create a new
> +	 one.  */
> +      groupdesc = syscall_group_create_syscall_group_desc (syscalls_info,
> +							   group);
> +    }
> +
> +  VEC_safe_push (syscall_desc_p, groupdesc->syscalls, syscall);
> +}
> +
>  static void
>  syscall_create_syscall_desc (struct syscalls_info *syscalls_info,
> -                             const char *name, int number)
> +                             const char *name, int number,
> +			     char *groups)
>  {
>    struct syscall_desc *sysdesc = XCNEW (struct syscall_desc);
> +  char *group;
>  
>    sysdesc->name = xstrdup (name);
>    sysdesc->number = number;
>  
>    VEC_safe_push (syscall_desc_p, syscalls_info->syscalls, sysdesc);
> +
> +  /*  Add syscall to its groups.  */
> +  if (groups != NULL)
> +    for (group = strtok (groups, ",");
> +	 group != NULL;
> +	 group = strtok (NULL, ","))
> +      syscall_group_add_syscall (syscalls_info, sysdesc, group);

Enclose for() loop in {} braces.

  if (...)
    {
      ...
    }

>  }
>  
>  /* Handle the start of a <syscall> element.  */
> @@ -177,6 +282,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>    /* syscall info.  */
>    char *name = NULL;
>    int number = 0;
> +  char *groups = NULL;
>  
>    len = VEC_length (gdb_xml_value_s, attributes);
>  
> @@ -186,13 +292,16 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>          name = attrs[i].value;
>        else if (strcmp (attrs[i].name, "number") == 0)
>          number = * (ULONGEST *) attrs[i].value;
> +      else if (strcmp (attrs[i].name, "groups") == 0)
> +        groups = attrs[i].value;
>        else
>          internal_error (__FILE__, __LINE__,
>                          _("Unknown attribute name '%s'."), attrs[i].name);
>      }
>  
>    gdb_assert (name);
> -  syscall_create_syscall_desc (data->syscalls_info, name, number);
> +
> +  syscall_create_syscall_desc (data->syscalls_info, name, number, groups);
>  }
>  
>  
> @@ -200,6 +309,7 @@ syscall_start_syscall (struct gdb_xml_parser *parser,
>  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 },
> +  { "groups", GDB_XML_AF_OPTIONAL, NULL, NULL },
>    { NULL, GDB_XML_AF_NONE, NULL, NULL }
>  };
>  
> @@ -321,6 +431,33 @@ init_syscalls_info (struct gdbarch *gdbarch)
>    set_gdbarch_syscalls_info (gdbarch, syscalls_info);
>  }
>  
> +/* Search for a syscall group by its name.  Return syscall_group_desc
> +   structure for the group if found or NULL otherwise.  */
> +
> +static struct syscall_group_desc *
> +syscall_group_get_group_by_name (const struct syscalls_info *syscalls_info,
> +				 const char *group)
> +{
> +  struct syscall_group_desc *groupdesc;
> +  int i;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  if (group == NULL)
> +    return NULL;
> +
> +   /* Search for existing group.  */
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    if (strcmp (groupdesc->name, group) == 0)
> +      return groupdesc;

Enclose if () in {} braces.

  for (...)
    {
      if (...)
	...;
    }

> +
> +  return NULL;
> +}
> +
>  static int
>  xml_get_syscall_number (struct gdbarch *gdbarch,
>                          const char *syscall_name)
> @@ -388,6 +525,75 @@ xml_list_of_syscalls (struct gdbarch *gdbarch)
>    return names;
>  }
>  
> +/*  Iterate over the syscall_group_desc element to return a list of
> +    syscalls that are part of the given group, terminated by an empty
> +    element.  If the syscall group doesn't exist, return NULL.  */

Extra space of indentation.

> +
> +static struct syscall *
> +xml_list_syscalls_by_group (struct gdbarch *gdbarch,
> +			    const char *group)
> +{
> +  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
> +  struct syscall_group_desc *groupdesc;
> +  struct syscall_desc *sysdesc;
> +  struct syscall *syscalls = NULL;
> +  int nsyscalls;
> +  int i;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  groupdesc = syscall_group_get_group_by_name (syscalls_info, group);
> +  if (groupdesc == NULL)
> +    return NULL;
> +
> +  nsyscalls = VEC_length (syscall_desc_p, groupdesc->syscalls);
> +  syscalls = xmalloc ((nsyscalls + 1) * sizeof (struct syscall));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_desc_p, groupdesc->syscalls, i, sysdesc);
> +       i++)
> +    {
> +      syscalls[i].name = sysdesc->name;
> +      syscalls[i].number = sysdesc->number;
> +    }
> +
> +  /* Add final element marker.  */
> +  syscalls[i].name = NULL;
> +  syscalls[i].number = 0;
> +
> +  return syscalls;
> +}
> +
> +/* Return the list of syscall groups.  If no syscall group is
> +   available, return NULL.  */

The comment doesn't match what the function returns if syscalls_info
is non-NULL but syscalls_info->groups is NULL.  Can that happen?

> +
> +static const char **
> +xml_list_of_groups (struct gdbarch *gdbarch)
> +{
> +  struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
> +  struct syscall_group_desc *groupdesc;
> +  const char **names = NULL;
> +  int i;
> +  int ngroups;
> +
> +  if (syscalls_info == NULL)
> +    return NULL;
> +
> +  ngroups = VEC_length (syscall_group_desc_p, syscalls_info->groups);
> +  names = xmalloc ((ngroups + 1) * sizeof (char *));
> +
> +  for (i = 0;
> +       VEC_iterate (syscall_group_desc_p,
> +		    syscalls_info->groups, i, groupdesc);
> +       i++)
> +    names[i] = groupdesc->name;
> +
> +  names[i] = NULL;
> +
> +  return names;
> +}
> +
>  void
>  set_xml_syscall_file_name (struct gdbarch *gdbarch, const char *name)
>  {
> @@ -422,4 +628,24 @@ get_syscall_names (struct gdbarch *gdbarch)
>    return xml_list_of_syscalls (gdbarch);
>  }
>  
> +/* See comment in xml-syscall.h.  */
> +
> +struct syscall *
> +get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
> +{
> +  init_syscalls_info (gdbarch);
> +
> +  return xml_list_syscalls_by_group (gdbarch, group);
> +}
> +
> +/* See comment in xml-syscall.h.  */
> +
> +const char **
> +get_syscall_group_names (struct gdbarch *gdbarch)
> +{
> +  init_syscalls_info (gdbarch);
> +
> +  return xml_list_of_groups (gdbarch);
> +}
> +
>  #endif /* ! HAVE_LIBEXPAT */
> diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
> index 42b9dea..9ba4e93 100644
> --- a/gdb/xml-syscall.h
> +++ b/gdb/xml-syscall.h
> @@ -50,4 +50,19 @@ void get_syscall_by_name (struct gdbarch *gdbarch,
>  
>  const char **get_syscall_names (struct gdbarch *gdbarch);
>  
> +/* Function used to retrieve the list of syscalls of a given group in
> +   the system.  Return a list of syscalls that are element of the
> +   group, terminated by an empty element. The list is malloc'ed
> +   and must be freed by the caller.  If group doesn't exist, return
> +   NULL.  */
> +
> +struct syscall *get_syscalls_by_group (struct gdbarch *gdbarch,
> +				       const char *group);
> +
> +/* Function used to retrieve the list of syscall groups in the system.
> +   Return an array of strings terminated by a NULL element.  The list
> +   must be freed by the caller.  */

The function can return NULL but the comment doesn't mention this.

> +
> +const char **get_syscall_group_names (struct gdbarch *gdbarch);
> +
>  #endif /* XML_SYSCALL_H */

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 2/4] Add support to catch groups of syscalls.
  2014-11-21 19:05   ` [PATCH v2 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
  2014-11-21 21:34     ` Sergio Durigan Junior
@ 2015-01-15  8:12     ` Doug Evans
  1 sibling, 0 replies; 32+ messages in thread
From: Doug Evans @ 2015-01-15  8:12 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
> This implements the catchpoint side.  While parsing 'catch syscall'
> arguments, we verify if the argument is a syscall group and expand it to
> a list of syscalls that are part of that group.
>
> gdb/
>
> 	* breakpoint.c (catch_syscall_split_args): Verify if argument
> 	is a syscall group and expand it to a list of syscalls when
> 	creating catchpoints.
> 	(catch_syscall_completer): Add word completion for system call
> 	groups.

Hi.
A few nits inline.
Ok with those changes, and things mentioned in other reviews.

> ---
>  gdb/breakpoint.c | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++------
>  1 file changed, 86 insertions(+), 9 deletions(-)
>
> diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
> index 7b56260..098e28d 100644
> --- a/gdb/breakpoint.c
> +++ b/gdb/breakpoint.c
> @@ -12058,10 +12058,39 @@ catch_syscall_split_args (char *arg)
>        cur_name[i] = '\0';
>        arg += i;
>  
> -      /* Check if the user provided a syscall name or a number.  */
> +      /* Check if the user provided a syscall name, group, or a
> +	 number.  */

Put number on previous line.

>        syscall_number = (int) strtol (cur_name, &endptr, 0);
>        if (*endptr == '\0')
> -	get_syscall_by_number (gdbarch, syscall_number, &s);
> +	{
> +	  get_syscall_by_number (gdbarch, syscall_number, &s);
> +	  VEC_safe_push (int, result, s.number);
> +	}
> +      else if (strncmp (cur_name, "g:", 2) == 0
> +	       || strncmp (cur_name, "group:", 6) == 0)
> +	{
> +	  /* We have a syscall group.  Let's expand it into a syscall
> +	     list before inserting.  */
> +	  struct syscall *syscall_list;
> +	  const char *group_name;
> +
> +	  /* Skip over "g:" and "group:" prefix strings.  */
> +	  group_name = strchr (cur_name, ':') + 1;
> +
> +	  syscall_list = get_syscalls_by_group (gdbarch, group_name);
> +
> +	  if (syscall_list == NULL)
> +	    error (_("Unknown syscall group '%s'."), group_name);
> +
> +	  for (i = 0; syscall_list[i].name != NULL; i++)
> +	    {
> +	      /* Insert each syscall that are part of the group.  No
> +		 need to check if it is valid.  */
> +	      VEC_safe_push (int, result, syscall_list[i].number);
> +	    }
> +
> +	  xfree (syscall_list);
> +	}
>        else
>  	{
>  	  /* We have a name.  Let's check if it's valid and convert it
> @@ -12073,10 +12102,10 @@ catch_syscall_split_args (char *arg)
>  	       because GDB cannot do anything useful if there's no
>  	       syscall number to be caught.  */
>  	    error (_("Unknown syscall name '%s'."), cur_name);
> -	}
>  
> -      /* Ok, it's valid.  */
> -      VEC_safe_push (int, result, s.number);
> +	  /* Ok, it's valid.  */
> +	  VEC_safe_push (int, result, s.number);
> +	}
>      }
>  
>    discard_cleanups (cleanup);
> @@ -15350,11 +15379,59 @@ static VEC (char_ptr) *
>  catch_syscall_completer (struct cmd_list_element *cmd,
>                           const char *text, const char *word)
>  {
> -  const char **list = get_syscall_names (get_current_arch ());
> -  VEC (char_ptr) *retlist
> -    = (list == NULL) ? NULL : complete_on_enum (list, word, word);
> +  struct gdbarch *gdbarch = get_current_arch ();
> +  struct cleanup *cleanups;
> +  VEC (char_ptr) *group_retlist = NULL;
> +  VEC (char_ptr) *syscall_retlist = NULL;
> +  VEC (char_ptr) *retlist = NULL;
> +  const char **group_list = NULL;
> +  const char **syscall_list = NULL;
> +  const char *prefix;
> +  int i;
> +
> +  /* Completion considers ':' to be a word separator, so we use this to
> +     verify whether the previous word was a group prefix.  If so, we
> +     build the completion list using group names only.  */
> +  for (prefix = word; prefix != text && prefix[-1] != ' '; prefix--)
> +    ;
> +
> +  if (strncmp (prefix, "g:", 2) == 0 || strncmp (prefix, "group:", 6) == 0)
> +    {
> +      /* Perform completion inside 'group:' namespace only.  */
> +      group_list = get_syscall_group_names (gdbarch);
> +      cleanups = make_cleanup (xfree, group_list);
> +      retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);

The indentation is wrong here.  Here's one correct way.

      retlist = (group_list == NULL
		 ? NULL : complete_on_enum (group_list, word, word));

or

      retlist = (group_list == NULL
		 ? NULL
		 : complete_on_enum (group_list, word, word));

> +    }
> +  else
> +    {
> +      /* Complete with both, syscall names and groups.  */
> +      syscall_list = get_syscall_names (gdbarch);
> +      group_list = get_syscall_group_names (gdbarch);
> +      cleanups = make_cleanup (xfree, group_list);
> +
> +      /* Append "group:" prefix to syscall groups.  */
> +      for (i = 0; group_list[i] != NULL; i++)
> +	{
> +	  char *prefixed_group = xstrprintf ("group:%s", group_list[i]);
> +
> +	  group_list[i] = prefixed_group;
> +	  make_cleanup (xfree, prefixed_group);
> +	}
> +
> +      syscall_retlist = (syscall_list == NULL) ?
> +	NULL : complete_on_enum (syscall_list, word, word);
> +      group_retlist = (group_list == NULL) ?
> +	NULL : complete_on_enum (group_list, word, word);

Similarly, indentation is wrong.  See above.

> +
> +      retlist = VEC_merge (char_ptr, syscall_retlist, group_retlist);
> +    }
> +
> +  VEC_free (char_ptr, syscall_retlist);
> +  VEC_free (char_ptr, group_retlist);
> +  xfree (syscall_list);
> +  do_cleanups (cleanups);
>  
> -  xfree (list);
>    return retlist;
>  }

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 3/4] Create syscall groups for x86_64.
  2014-11-21 19:06   ` [PATCH v2 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
@ 2015-01-15  8:28     ` Doug Evans
  0 siblings, 0 replies; 32+ messages in thread
From: Doug Evans @ 2015-01-15  8:28 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

Gabriel Krisman Bertazi <gabriel@krisman.be> writes:
> This commit introduces the following syscall groups for the x86_64
> architecture: memory, ipc, process, descriptor, signal and file.
>
> Please note that the sorting of the syscalls among these several groups
> follows the same structure used in strace.

Some of these are a bit weird, but if this is identical to what strace
has done, then let's leave it at that.

Just some nits inline.
Ok with those changes, as well as review comments of others.
[I'm not sure offhand if Sergio commented on this one.]

Thanks!

>
> This also introduces tests for catching groups of syscalls on the x86_64
> architecture.
>
> gdb/
>
> 	* syscalls/amd64-linux.xml: Add 'groups' attribute to several
> 	syscalls on x86_64.  Create groups memory, ipc, file,
> 	descriptor, process and signal.
>
> gdb/testsuite/
>
> 	* gdb.base/catch-syscall.exp (do_syscall_tests): Add call
> 	to test_catch_syscall_group.
> 	(test_catch_syscall_group): New.
> ---
>  gdb/syscalls/amd64-linux.xml             | 362 +++++++++++++++----------------
>  gdb/testsuite/gdb.base/catch-syscall.exp |  33 +++
>  2 files changed, 214 insertions(+), 181 deletions(-)
>
> diff --git a/gdb/syscalls/amd64-linux.xml b/gdb/syscalls/amd64-linux.xml
> index 6a04218..974c5b5 100644
> --- a/gdb/syscalls/amd64-linux.xml
> +++ b/gdb/syscalls/amd64-linux.xml
> @@ -14,101 +14,101 @@
>       The file mentioned above belongs to the Linux Kernel.  -->
>  
>  <syscalls_info>
> -  <syscall name="read" number="0"/>
> -  <syscall name="write" number="1"/>
> -  <syscall name="open" number="2"/>
> -  <syscall name="close" number="3"/>
> -  <syscall name="stat" number="4"/>
> -  <syscall name="fstat" number="5"/>
> -  <syscall name="lstat" number="6"/>
> -  <syscall name="poll" number="7"/>
> -  <syscall name="lseek" number="8"/>
> -  <syscall name="mmap" number="9"/>
> -  <syscall name="mprotect" number="10"/>
> -  <syscall name="munmap" number="11"/>
> -  <syscall name="brk" number="12"/>
> -  <syscall name="rt_sigaction" number="13"/>
> -  <syscall name="rt_sigprocmask" number="14"/>
> -  <syscall name="rt_sigreturn" number="15"/>
> -  <syscall name="ioctl" number="16"/>
> -  <syscall name="pread64" number="17"/>
> -  <syscall name="pwrite64" number="18"/>
> -  <syscall name="readv" number="19"/>
> -  <syscall name="writev" number="20"/>
> -  <syscall name="access" number="21"/>
> -  <syscall name="pipe" number="22"/>
> -  <syscall name="select" number="23"/>
> +  <syscall name="read" number="0" groups="descriptor"/>
> +  <syscall name="write" number="1" groups="descriptor"/>
> +  <syscall name="open" number="2" groups="descriptor,file"/>
> +  <syscall name="close" number="3" groups="descriptor"/>
> +  <syscall name="stat" number="4" groups="file"/>
> +  <syscall name="fstat" number="5" groups="descriptor"/>
> +  <syscall name="lstat" number="6" groups="file"/>
> +  <syscall name="poll" number="7" groups="descriptor"/>
> +  <syscall name="lseek" number="8" groups="descriptor"/>
> +  <syscall name="mmap" number="9" groups="descriptor,memory"/>
> +  <syscall name="mprotect" number="10" groups="memory"/>
> +  <syscall name="munmap" number="11" groups="memory"/>
> +  <syscall name="brk" number="12" groups="memory"/>
> +  <syscall name="rt_sigaction" number="13" groups="signal"/>
> +  <syscall name="rt_sigprocmask" number="14" groups="signal"/>
> +  <syscall name="rt_sigreturn" number="15" groups="signal"/>
> +  <syscall name="ioctl" number="16" groups="descriptor"/>
> +  <syscall name="pread64" number="17" groups="descriptor"/>
> +  <syscall name="pwrite64" number="18" groups="descriptor"/>
> +  <syscall name="readv" number="19" groups="descriptor"/>
> +  <syscall name="writev" number="20" groups="descriptor"/>
> +  <syscall name="access" number="21" groups="file"/>
> +  <syscall name="pipe" number="22" groups="descriptor"/>
> +  <syscall name="select" number="23" groups="descriptor"/>
>    <syscall name="sched_yield" number="24"/>
> -  <syscall name="mremap" number="25"/>
> -  <syscall name="msync" number="26"/>
> -  <syscall name="mincore" number="27"/>
> -  <syscall name="madvise" number="28"/>
> -  <syscall name="shmget" number="29"/>
> -  <syscall name="shmat" number="30"/>
> -  <syscall name="shmctl" number="31"/>
> -  <syscall name="dup" number="32"/>
> -  <syscall name="dup2" number="33"/>
> -  <syscall name="pause" number="34"/>
> +  <syscall name="mremap" number="25" groups="memory"/>
> +  <syscall name="msync" number="26" groups="memory"/>
> +  <syscall name="mincore" number="27" groups="memory"/>
> +  <syscall name="madvise" number="28" groups="memory"/>
> +  <syscall name="shmget" number="29" groups="ipc"/>
> +  <syscall name="shmat" number="30" groups="memory,ipc"/>
> +  <syscall name="shmctl" number="31" groups="ipc"/>
> +  <syscall name="dup" number="32" groups="descriptor"/>
> +  <syscall name="dup2" number="33" groups="descriptor"/>
> +  <syscall name="pause" number="34" groups="signal"/>
>    <syscall name="nanosleep" number="35"/>
>    <syscall name="getitimer" number="36"/>
>    <syscall name="alarm" number="37"/>
>    <syscall name="setitimer" number="38"/>
>    <syscall name="getpid" number="39"/>
> -  <syscall name="sendfile" number="40"/>
> -  <syscall name="socket" number="41"/>
> -  <syscall name="connect" number="42"/>
> -  <syscall name="accept" number="43"/>
> -  <syscall name="sendto" number="44"/>
> -  <syscall name="recvfrom" number="45"/>
> -  <syscall name="sendmsg" number="46"/>
> -  <syscall name="recvmsg" number="47"/>
> -  <syscall name="shutdown" number="48"/>
> -  <syscall name="bind" number="49"/>
> -  <syscall name="listen" number="50"/>
> -  <syscall name="getsockname" number="51"/>
> -  <syscall name="getpeername" number="52"/>
> -  <syscall name="socketpair" number="53"/>
> -  <syscall name="setsockopt" number="54"/>
> -  <syscall name="getsockopt" number="55"/>
> -  <syscall name="clone" number="56"/>
> -  <syscall name="fork" number="57"/>
> -  <syscall name="vfork" number="58"/>
> -  <syscall name="execve" number="59"/>
> -  <syscall name="exit" number="60"/>
> -  <syscall name="wait4" number="61"/>
> -  <syscall name="kill" number="62"/>
> +  <syscall name="sendfile" number="40" groups="network,descriptor"/>
> +  <syscall name="socket" number="41" groups="network"/>
> +  <syscall name="connect" number="42" groups="network"/>
> +  <syscall name="accept" number="43" groups="network"/>
> +  <syscall name="sendto" number="44" groups="network"/>
> +  <syscall name="recvfrom" number="45" groups="network"/>
> +  <syscall name="sendmsg" number="46" groups="network"/>
> +  <syscall name="recvmsg" number="47" groups="network"/>
> +  <syscall name="shutdown" number="48" groups="network"/>
> +  <syscall name="bind" number="49" groups="network"/>
> +  <syscall name="listen" number="50" groups="network"/>
> +  <syscall name="getsockname" number="51" groups="network"/>
> +  <syscall name="getpeername" number="52" groups="network"/>
> +  <syscall name="socketpair" number="53" groups="network"/>
> +  <syscall name="setsockopt" number="54" groups="network"/>
> +  <syscall name="getsockopt" number="55" groups="network"/>
> +  <syscall name="clone" number="56" groups="process"/>
> +  <syscall name="fork" number="57" groups="process"/>
> +  <syscall name="vfork" number="58" groups="process"/>
> +  <syscall name="execve" number="59" groups="process,file"/>
> +  <syscall name="exit" number="60" groups="process"/>
> +  <syscall name="wait4" number="61" groups="process"/>
> +  <syscall name="kill" number="62" groups="signal"/>
>    <syscall name="uname" number="63"/>
> -  <syscall name="semget" number="64"/>
> -  <syscall name="semop" number="65"/>
> -  <syscall name="semctl" number="66"/>
> -  <syscall name="shmdt" number="67"/>
> -  <syscall name="msgget" number="68"/>
> -  <syscall name="msgsnd" number="69"/>
> -  <syscall name="msgrcv" number="70"/>
> -  <syscall name="msgctl" number="71"/>
> -  <syscall name="fcntl" number="72"/>
> -  <syscall name="flock" number="73"/>
> -  <syscall name="fsync" number="74"/>
> -  <syscall name="fdatasync" number="75"/>
> -  <syscall name="truncate" number="76"/>
> -  <syscall name="ftruncate" number="77"/>
> -  <syscall name="getdents" number="78"/>
> -  <syscall name="getcwd" number="79"/>
> -  <syscall name="chdir" number="80"/>
> -  <syscall name="fchdir" number="81"/>
> -  <syscall name="rename" number="82"/>
> -  <syscall name="mkdir" number="83"/>
> -  <syscall name="rmdir" number="84"/>
> -  <syscall name="creat" number="85"/>
> -  <syscall name="link" number="86"/>
> -  <syscall name="unlink" number="87"/>
> -  <syscall name="symlink" number="88"/>
> -  <syscall name="readlink" number="89"/>
> -  <syscall name="chmod" number="90"/>
> -  <syscall name="fchmod" number="91"/>
> -  <syscall name="chown" number="92"/>
> -  <syscall name="fchown" number="93"/>
> -  <syscall name="lchown" number="94"/>
> +  <syscall name="semget" number="64" groups="ipc"/>
> +  <syscall name="semop" number="65" groups="ipc"/>
> +  <syscall name="semctl" number="66" groups="ipc"/>
> +  <syscall name="shmdt" number="67" groups="memory,ipc"/>
> +  <syscall name="msgget" number="68" groups="ipc"/>
> +  <syscall name="msgsnd" number="69" groups="ipc"/>
> +  <syscall name="msgrcv" number="70" groups="ipc"/>
> +  <syscall name="msgctl" number="71" groups="ipc"/>
> +  <syscall name="fcntl" number="72" groups="descriptor"/>
> +  <syscall name="flock" number="73" groups="descriptor"/>
> +  <syscall name="fsync" number="74" groups="descriptor"/>
> +  <syscall name="fdatasync" number="75" groups="descriptor"/>
> +  <syscall name="truncate" number="76" groups="file"/>
> +  <syscall name="ftruncate" number="77" groups="descriptor"/>
> +  <syscall name="getdents" number="78" groups="descriptor"/>
> +  <syscall name="getcwd" number="79" groups="file"/>
> +  <syscall name="chdir" number="80" groups="file"/>
> +  <syscall name="fchdir" number="81" groups="descriptor"/>
> +  <syscall name="rename" number="82" groups="file"/>
> +  <syscall name="mkdir" number="83" groups="file"/>
> +  <syscall name="rmdir" number="84" groups="file"/>
> +  <syscall name="creat" number="85" groups="file,descriptor"/>
> +  <syscall name="link" number="86" groups="file"/>
> +  <syscall name="unlink" number="87" groups="file"/>
> +  <syscall name="symlink" number="88" groups="file"/>
> +  <syscall name="readlink" number="89" groups="file"/>
> +  <syscall name="chmod" number="90" groups="file"/>
> +  <syscall name="fchmod" number="91" groups="descriptor"/>
> +  <syscall name="chown" number="92" groups="file"/>
> +  <syscall name="fchown" number="93" groups="descriptor"/>
> +  <syscall name="lchown" number="94" groups="file"/>
>    <syscall name="umask" number="95"/>
>    <syscall name="gettimeofday" number="96"/>
>    <syscall name="getrlimit" number="97"/>
> @@ -141,18 +141,18 @@
>    <syscall name="getsid" number="124"/>
>    <syscall name="capget" number="125"/>
>    <syscall name="capset" number="126"/>
> -  <syscall name="rt_sigpending" number="127"/>
> -  <syscall name="rt_sigtimedwait" number="128"/>
> -  <syscall name="rt_sigqueueinfo" number="129"/>
> -  <syscall name="rt_sigsuspend" number="130"/>
> -  <syscall name="sigaltstack" number="131"/>
> -  <syscall name="utime" number="132"/>
> -  <syscall name="mknod" number="133"/>
> -  <syscall name="uselib" number="134"/>
> +  <syscall name="rt_sigpending" number="127" groups="signal"/>
> +  <syscall name="rt_sigtimedwait" number="128" groups="signal"/>
> +  <syscall name="rt_sigqueueinfo" number="129" groups="signal"/>
> +  <syscall name="rt_sigsuspend" number="130" groups="signal"/>
> +  <syscall name="sigaltstack" number="131" groups="signal"/>
> +  <syscall name="utime" number="132" groups="file"/>
> +  <syscall name="mknod" number="133" groups="file"/>
> +  <syscall name="uselib" number="134" groups="file"/>
>    <syscall name="personality" number="135"/>
>    <syscall name="ustat" number="136"/>
> -  <syscall name="statfs" number="137"/>
> -  <syscall name="fstatfs" number="138"/>
> +  <syscall name="statfs" number="137" groups="file"/>
> +  <syscall name="fstatfs" number="138" groups="descriptor"/>
>    <syscall name="sysfs" number="139"/>
>    <syscall name="getpriority" number="140"/>
>    <syscall name="setpriority" number="141"/>
> @@ -163,26 +163,26 @@
>    <syscall name="sched_get_priority_max" number="146"/>
>    <syscall name="sched_get_priority_min" number="147"/>
>    <syscall name="sched_rr_get_interval" number="148"/>
> -  <syscall name="mlock" number="149"/>
> -  <syscall name="munlock" number="150"/>
> -  <syscall name="mlockall" number="151"/>
> -  <syscall name="munlockall" number="152"/>
> +  <syscall name="mlock" number="149" groups="memory"/>
> +  <syscall name="munlock" number="150" groups="memory"/>
> +  <syscall name="mlockall" number="151" groups="memory"/>
> +  <syscall name="munlockall" number="152" groups="memory"/>
>    <syscall name="vhangup" number="153"/>
>    <syscall name="modify_ldt" number="154"/>
> -  <syscall name="pivot_root" number="155"/>
> +  <syscall name="pivot_root" number="155" groups="file"/>
>    <syscall name="_sysctl" number="156"/>
>    <syscall name="prctl" number="157"/>
> -  <syscall name="arch_prctl" number="158"/>
> +  <syscall name="arch_prctl" number="158" groups="process"/>
>    <syscall name="adjtimex" number="159"/>
>    <syscall name="setrlimit" number="160"/>
> -  <syscall name="chroot" number="161"/>
> +  <syscall name="chroot" number="161" groups="file"/>
>    <syscall name="sync" number="162"/>
> -  <syscall name="acct" number="163"/>
> +  <syscall name="acct" number="163" groups="file"/>
>    <syscall name="settimeofday" number="164"/>
> -  <syscall name="mount" number="165"/>
> -  <syscall name="umount2" number="166"/>
> -  <syscall name="swapon" number="167"/>
> -  <syscall name="swapoff" number="168"/>
> +  <syscall name="mount" number="165" groups="file"/>
> +  <syscall name="umount2" number="166" groups="file"/>
> +  <syscall name="swapon" number="167" groups="file"/>
> +  <syscall name="swapoff" number="168" groups="file"/>
>    <syscall name="reboot" number="169"/>
>    <syscall name="sethostname" number="170"/>
>    <syscall name="setdomainname" number="171"/>
> @@ -193,7 +193,7 @@
>    <syscall name="delete_module" number="176"/>
>    <syscall name="get_kernel_syms" number="177"/>
>    <syscall name="query_module" number="178"/>
> -  <syscall name="quotactl" number="179"/>
> +  <syscall name="quotactl" number="179" groups="file"/>
>    <syscall name="nfsservctl" number="180"/>
>    <syscall name="getpmsg" number="181"/>
>    <syscall name="putpmsg" number="182"/>
> @@ -201,20 +201,20 @@
>    <syscall name="tuxcall" number="184"/>
>    <syscall name="security" number="185"/>
>    <syscall name="gettid" number="186"/>
> -  <syscall name="readahead" number="187"/>
> -  <syscall name="setxattr" number="188"/>
> -  <syscall name="lsetxattr" number="189"/>
> -  <syscall name="fsetxattr" number="190"/>
> -  <syscall name="getxattr" number="191"/>
> -  <syscall name="lgetxattr" number="192"/>
> -  <syscall name="fgetxattr" number="193"/>
> -  <syscall name="listxattr" number="194"/>
> -  <syscall name="llistxattr" number="195"/>
> -  <syscall name="flistxattr" number="196"/>
> -  <syscall name="removexattr" number="197"/>
> -  <syscall name="lremovexattr" number="198"/>
> -  <syscall name="fremovexattr" number="199"/>
> -  <syscall name="tkill" number="200"/>
> +  <syscall name="readahead" number="187" groups="descriptor"/>
> +  <syscall name="setxattr" number="188" groups="file"/>
> +  <syscall name="lsetxattr" number="189" groups="file"/>
> +  <syscall name="fsetxattr" number="190" groups="descriptor"/>
> +  <syscall name="getxattr" number="191" groups="file"/>
> +  <syscall name="lgetxattr" number="192" groups="file"/>
> +  <syscall name="fgetxattr" number="193" groups="descriptor"/>
> +  <syscall name="listxattr" number="194" groups="file"/>
> +  <syscall name="llistxattr" number="195" groups="file"/>
> +  <syscall name="flistxattr" number="196" groups="descriptor"/>
> +  <syscall name="removexattr" number="197" groups="file"/>
> +  <syscall name="lremovexattr" number="198" groups="file"/>
> +  <syscall name="fremovexattr" number="199" groups="descriptor"/>
> +  <syscall name="tkill" number="200" groups="signal"/>
>    <syscall name="time" number="201"/>
>    <syscall name="futex" number="202"/>
>    <syscall name="sched_setaffinity" number="203"/>
> @@ -227,15 +227,15 @@
>    <syscall name="io_cancel" number="210"/>
>    <syscall name="get_thread_area" number="211"/>
>    <syscall name="lookup_dcookie" number="212"/>
> -  <syscall name="epoll_create" number="213"/>
> +  <syscall name="epoll_create" number="213" groups="descriptor"/>
>    <syscall name="epoll_ctl_old" number="214"/>
>    <syscall name="epoll_wait_old" number="215"/>
> -  <syscall name="remap_file_pages" number="216"/>
> -  <syscall name="getdents64" number="217"/>
> +  <syscall name="remap_file_pages" number="216" groups="memory"/>
> +  <syscall name="getdents64" number="217" groups="descriptor"/>
>    <syscall name="set_tid_address" number="218"/>
>    <syscall name="restart_syscall" number="219"/>
> -  <syscall name="semtimedop" number="220"/>
> -  <syscall name="fadvise64" number="221"/>
> +  <syscall name="semtimedop" number="220" groups="ipc"/>
> +  <syscall name="fadvise64" number="221" groups="descriptor"/>
>    <syscall name="timer_create" number="222"/>
>    <syscall name="timer_settime" number="223"/>
>    <syscall name="timer_gettime" number="224"/>
> @@ -245,15 +245,15 @@
>    <syscall name="clock_gettime" number="228"/>
>    <syscall name="clock_getres" number="229"/>
>    <syscall name="clock_nanosleep" number="230"/>
> -  <syscall name="exit_group" number="231"/>
> -  <syscall name="epoll_wait" number="232"/>
> -  <syscall name="epoll_ctl" number="233"/>
> -  <syscall name="tgkill" number="234"/>
> -  <syscall name="utimes" number="235"/>
> +  <syscall name="exit_group" number="231" groups="process"/>
> +  <syscall name="epoll_wait" number="232" groups="descriptor"/>
> +  <syscall name="epoll_ctl" number="233" groups="descriptor"/>
> +  <syscall name="tgkill" number="234" groups="signal"/>
> +  <syscall name="utimes" number="235" groups="file"/>
>    <syscall name="vserver" number="236"/>
> -  <syscall name="mbind" number="237"/>
> -  <syscall name="set_mempolicy" number="238"/>
> -  <syscall name="get_mempolicy" number="239"/>
> +  <syscall name="mbind" number="237" groups="memory"/>
> +  <syscall name="set_mempolicy" number="238" groups="memory"/>
> +  <syscall name="get_mempolicy" number="239" groups="memory"/>
>    <syscall name="mq_open" number="240"/>
>    <syscall name="mq_unlink" number="241"/>
>    <syscall name="mq_timedsend" number="242"/>
> @@ -261,54 +261,54 @@
>    <syscall name="mq_notify" number="244"/>
>    <syscall name="mq_getsetattr" number="245"/>
>    <syscall name="kexec_load" number="246"/>
> -  <syscall name="waitid" number="247"/>
> +  <syscall name="waitid" number="247" groups="process"/>
>    <syscall name="add_key" number="248"/>
>    <syscall name="request_key" number="249"/>
>    <syscall name="keyctl" number="250"/>
>    <syscall name="ioprio_set" number="251"/>
>    <syscall name="ioprio_get" number="252"/>
> -  <syscall name="inotify_init" number="253"/>
> -  <syscall name="inotify_add_watch" number="254"/>
> -  <syscall name="inotify_rm_watch" number="255"/>
> -  <syscall name="migrate_pages" number="256"/>
> -  <syscall name="openat" number="257"/>
> -  <syscall name="mkdirat" number="258"/>
> -  <syscall name="mknodat" number="259"/>
> -  <syscall name="fchownat" number="260"/>
> -  <syscall name="futimesat" number="261"/>
> -  <syscall name="newfstatat" number="262"/>
> -  <syscall name="unlinkat" number="263"/>
> -  <syscall name="renameat" number="264"/>
> -  <syscall name="linkat" number="265"/>
> -  <syscall name="symlinkat" number="266"/>
> -  <syscall name="readlinkat" number="267"/>
> -  <syscall name="fchmodat" number="268"/>
> -  <syscall name="faccessat" number="269"/>
> -  <syscall name="pselect6" number="270"/>
> -  <syscall name="ppoll" number="271"/>
> -  <syscall name="unshare" number="272"/>
> +  <syscall name="inotify_init" number="253" groups="descriptor"/>
> +  <syscall name="inotify_add_watch" number="254" groups="descriptor"/>
> +  <syscall name="inotify_rm_watch" number="255" groups="descriptor"/>
> +  <syscall name="migrate_pages" number="256" groups="memory"/>
> +  <syscall name="openat" number="257" groups="file,descriptor"/>
> +  <syscall name="mkdirat" number="258" groups="file,descriptor"/>
> +  <syscall name="mknodat" number="259" groups="file,descriptor"/>
> +  <syscall name="fchownat" number="260" groups="file,descriptor"/>
> +  <syscall name="futimesat" number="261" groups="file,descriptor"/>
> +  <syscall name="newfstatat" number="262" groups="file,descriptor"/>
> +  <syscall name="unlinkat" number="263" groups="file,descriptor"/>
> +  <syscall name="renameat" number="264" groups="file,descriptor"/>
> +  <syscall name="linkat" number="265" groups="file,descriptor"/>
> +  <syscall name="symlinkat" number="266" groups="file,descriptor"/>
> +  <syscall name="readlinkat" number="267" groups="file,descriptor"/>
> +  <syscall name="fchmodat" number="268" groups="file,descriptor"/>
> +  <syscall name="faccessat" number="269" groups="file,descriptor"/>
> +  <syscall name="pselect6" number="270" groups="descriptor"/>
> +  <syscall name="ppoll" number="271" groups="descriptor"/>
> +  <syscall name="unshare" number="272" groups="process"/>
>    <syscall name="set_robust_list" number="273"/>
>    <syscall name="get_robust_list" number="274"/>
> -  <syscall name="splice" number="275"/>
> -  <syscall name="tee" number="276"/>
> -  <syscall name="sync_file_range" number="277"/>
> -  <syscall name="vmsplice" number="278"/>
> -  <syscall name="move_pages" number="279"/>
> -  <syscall name="utimensat" number="280"/>
> -  <syscall name="epoll_pwait" number="281"/>
> -  <syscall name="signalfd" number="282"/>
> -  <syscall name="timerfd_create" number="283"/>
> -  <syscall name="eventfd" number="284"/>
> -  <syscall name="fallocate" number="285"/>
> -  <syscall name="timerfd_settime" number="286"/>
> -  <syscall name="timerfd_gettime" number="287"/>
> -  <syscall name="accept4" number="288"/>
> -  <syscall name="signalfd4" number="289"/>
> -  <syscall name="eventfd2" number="290"/>
> -  <syscall name="epoll_create1" number="291"/>
> -  <syscall name="dup3" number="292"/>
> -  <syscall name="pipe2" number="293"/>
> -  <syscall name="inotify_init1" number="294"/>
> -  <syscall name="preadv" number="295"/>
> -  <syscall name="pwritev" number="296"/>
> +  <syscall name="splice" number="275" groups="descriptor"/>
> +  <syscall name="tee" number="276" groups="descriptor"/>
> +  <syscall name="sync_file_range" number="277" groups="descriptor"/>
> +  <syscall name="vmsplice" number="278" groups="descriptor"/>
> +  <syscall name="move_pages" number="279" groups="memory"/>
> +  <syscall name="utimensat" number="280" groups="file,descriptor"/>
> +  <syscall name="epoll_pwait" number="281" groups="descriptor"/>
> +  <syscall name="signalfd" number="282" groups="signal,descriptor"/>
> +  <syscall name="timerfd_create" number="283" groups="descriptor"/>
> +  <syscall name="eventfd" number="284" groups="descriptor"/>
> +  <syscall name="fallocate" number="285" groups="descriptor"/>
> +  <syscall name="timerfd_settime" number="286" groups="descriptor"/>
> +  <syscall name="timerfd_gettime" number="287" groups="descriptor"/>
> +  <syscall name="accept4" number="288" groups="network"/>
> +  <syscall name="signalfd4" number="289" groups="signal,descriptor"/>
> +  <syscall name="eventfd2" number="290" groups="descriptor"/>
> +  <syscall name="epoll_create1" number="291" groups="descriptor"/>
> +  <syscall name="dup3" number="292" groups="descriptor"/>
> +  <syscall name="pipe2" number="293" groups="descriptor"/>
> +  <syscall name="inotify_init1" number="294" groups="descriptor"/>
> +  <syscall name="preadv" number="295" groups="descriptor"/>
> +  <syscall name="pwritev" number="296" groups="descriptor"/>
>  </syscalls_info>
> diff --git a/gdb/testsuite/gdb.base/catch-syscall.exp b/gdb/testsuite/gdb.base/catch-syscall.exp
> index ed87d61..c061414 100644
> --- a/gdb/testsuite/gdb.base/catch-syscall.exp
> +++ b/gdb/testsuite/gdb.base/catch-syscall.exp
> @@ -275,6 +275,36 @@ proc test_catch_syscall_fail_nodatadir {} {
>      }
>  }
>  
> +proc test_catch_syscall_group {} {
> +    global decimal
> +
> +    # Until we have syscall groups to test on other targets.
> +    if { ![istarget "x86_64-*-linux*"] } then {
> +	return
> +    }
> +    set sysnum "\\\[${decimal}\\\]"
> +
> +    gdb_test "catch syscall g:process" \
> +	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*" \
> +	"set catchpoint on a group of syscalls"
> +
> +    gdb_test "catch syscall g:process read" \

s/g:process/group:process/
[so that we test both g: and group: as args to catch]

> +	"Catchpoint $decimal \\(syscalls (\'(clone|fork|execve|exit)\' $sysnum)+.*read.*\\)" \
> +	"set catchpoints on a group of syscalls and on a single syscall"

Add a test that "g:" and "group:" without a group name and with a bad
group name are handled correctly.  To simplify things, I'd be ok with
"g:" and "group:junk" or some such.

> +
> +    gdb_test "complete catch syscall g:proc" \
> +	"catch syscall g:process" \
> +	"complete catch syscall group with 'g:' prefix"
> +
> +    gdb_test "complete catch syscall group:proc" \
> +	"catch syscall group:process" \
> +	"complete catch syscall group with 'group:' prefix"
> +
> +    gdb_test "complete catch syscall g" \
> +	".*group:process.*" \
> +	"complete catch syscall group suggests 'group:' prefix"
> +}
> +
>  proc do_syscall_tests {} {
>      # NOTE: We don't have to point gdb at the correct data-directory.
>      # For the build tree that is handled by INTERNAL_GDBFLAGS.
> @@ -315,6 +345,9 @@ proc do_syscall_tests {} {
>      # Testing if the 'catch syscall' command works when switching to
>      # different architectures on-the-fly (PR gdb/10737).
>      if [runto_main] then { test_catch_syscall_multi_arch }
> +
> +    # Testing the 'catch' syscall command for a group of syscalls.
> +    if [runto_main] then { test_catch_syscall_group }
>  }
>  
>  proc test_catch_syscall_without_args_noxml {} {

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2015-01-15  8:03 ` [PATCH " Doug Evans
@ 2015-01-29  4:43   ` Gabriel Krisman Bertazi
  2015-01-29  7:42     ` Doug Evans
  0 siblings, 1 reply; 32+ messages in thread
From: Gabriel Krisman Bertazi @ 2015-01-29  4:43 UTC (permalink / raw)
  To: Doug Evans; +Cc: gdb-patches

[-- Attachment #1: Type: text/plain, Size: 689 bytes --]

Doug Evans <xdje42@gmail.com> writes:

> Hi.
> I didn't make sure that I'm not repeating something Sergio mentioned.
>
Doug,

Thanks for your review.

Unfortunately, right now I have some issues with my copyright
assignment status and I should solve it before I can provide the changes
you mentioned and put this upstream.  It took me some time to answer
because of that, but I think it is gonna take a few more weeks until
everything is in place.

Let me put these patches on hold for a while and as soon as everything
is set, I'll ping you and the list with the updated version to include
the suggestions you and Sergio made.

Thanks!

-- 
Gabriel Krisman Bertazi

[-- Attachment #2: Type: application/pgp-signature, Size: 818 bytes --]

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface.
  2015-01-29  4:43   ` Gabriel Krisman Bertazi
@ 2015-01-29  7:42     ` Doug Evans
  0 siblings, 0 replies; 32+ messages in thread
From: Doug Evans @ 2015-01-29  7:42 UTC (permalink / raw)
  To: Gabriel Krisman Bertazi; +Cc: gdb-patches

On Wed, Jan 28, 2015 at 12:42 PM, Gabriel Krisman Bertazi
<gabriel@krisman.be> wrote:
> Doug Evans <xdje42@gmail.com> writes:
>
>> Hi.
>> I didn't make sure that I'm not repeating something Sergio mentioned.
>>
> Doug,
>
> Thanks for your review.
>
> Unfortunately, right now I have some issues with my copyright
> assignment status and I should solve it before I can provide the changes
> you mentioned and put this upstream.  It took me some time to answer
> because of that, but I think it is gonna take a few more weeks until
> everything is in place.
>
> Let me put these patches on hold for a while and as soon as everything
> is set, I'll ping you and the list with the updated version to include
> the suggestions you and Sergio made.
>
> Thanks!

Ok, no worries.

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2015-01-29  6:15 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-21 19:05 [PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
2014-11-02 19:36 ` [PATCH 0/4] Catch syscall groups Gabriel Krisman Bertazi
2014-11-02 19:36   ` [PATCH 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
2014-11-14 22:42     ` Sergio Durigan Junior
2014-11-02 19:36   ` [PATCH 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
2014-11-14 22:55     ` Sergio Durigan Junior
2014-11-02 19:37   ` [PATCH 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
2014-11-02 19:45     ` Eli Zaretskii
2014-11-12  2:04       ` Gabriel Krisman Bertazi
2014-11-12  3:48         ` Eli Zaretskii
2014-11-14 18:52           ` Gabriel Krisman Bertazi
2014-11-14 20:38             ` Eli Zaretskii
2014-11-03 18:38     ` Sergio Durigan Junior
2014-11-02 19:37   ` [PATCH 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
2014-11-14 23:00     ` Sergio Durigan Junior
2014-11-20  2:11       ` Gabriel Krisman Bertazi
2014-11-20  3:08         ` Sergio Durigan Junior
2014-11-21 19:05   ` [PATCH v2 2/4] Add support to catch groups of syscalls Gabriel Krisman Bertazi
2014-11-21 21:34     ` Sergio Durigan Junior
2015-01-15  8:12     ` Doug Evans
2014-11-21 19:06   ` [PATCH v2 4/4] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
2014-11-21 19:48     ` Eli Zaretskii
2014-11-26  3:58       ` Gabriel Krisman Bertazi
2014-11-21 19:06   ` [PATCH v2 3/4] Create syscall groups for x86_64 Gabriel Krisman Bertazi
2015-01-15  8:28     ` Doug Evans
2014-11-29  0:19 ` [ping PATCH v2 1/4] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
2014-12-08  0:09   ` [ping^2 " Gabriel Krisman Bertazi
2014-12-21 15:59     ` [ping^3 " Gabriel Krisman Bertazi
2015-01-12 20:47       ` Doug Evans
2015-01-15  8:03 ` [PATCH " Doug Evans
2015-01-29  4:43   ` Gabriel Krisman Bertazi
2015-01-29  7:42     ` Doug Evans

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).