public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
From: Gabriel Krisman Bertazi <gabriel@krisman.be>
To: gdb-patches@sourceware.org
Cc: dje@google.com,	sergiodj@redhat.com,
	Gabriel Krisman Bertazi <gabriel@krisman.be>
Subject: [PATCH v3 02/17] Add support to catch groups of syscalls.
Date: Sun, 26 Apr 2015 01:25:00 -0000	[thread overview]
Message-ID: <1430011521-24340-3-git-send-email-gabriel@krisman.be> (raw)
In-Reply-To: <1430011521-24340-1-git-send-email-gabriel@krisman.be>

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/

	* break-catch-syscall.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/break-catch-syscall.c | 94 ++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 85 insertions(+), 9 deletions(-)

diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 1718f49..686daf1 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -462,10 +462,38 @@ 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:", sizeof ("g:") - 1) == 0
+	       || strncmp (cur_name, "group:", sizeof ("group:") - 1) == 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
@@ -477,10 +505,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);
@@ -595,11 +623,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 = make_cleanup (null_cleanup, NULL);
+  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:", sizeof ("g:") - 1) == 0
+      || strncmp (prefix, "group:", sizeof ("group:") - 1) == 0)
+    {
+      /* Perform completion inside 'group:' namespace only.  */
+      group_list = get_syscall_group_names (gdbarch);
+      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);
+
+      /* 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);
+  xfree (group_list);
+  do_cleanups (cleanups);
 
-  xfree (list);
   return retlist;
 }
 
-- 
1.9.3

  parent reply	other threads:[~2015-04-26  1:25 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-26  1:25 [PATCH v3 00/17] Catch syscall group Gabriel Krisman Bertazi
2015-04-26  1:25 ` [PATCH v3 01/17] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
2015-04-26  1:25 ` [PATCH v3 03/17] Add tests for catching groups of syscalls on supported architectures Gabriel Krisman Bertazi
2015-04-26 18:44   ` Sergio Durigan Junior
2015-04-26  1:25 ` Gabriel Krisman Bertazi [this message]
2015-04-26  1:26 ` [PATCH v3 07/17] Create syscall groups for aarch64 Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 12/17] Create syscall groups for mips-n64 Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 08/17] Create syscall groups for arm Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 06/17] Create syscall groups for ppc64 Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 10/17] Create syscall groups for i386 Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 04/17] Create syscall groups for amd64 Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 09/17] Create syscall groups for bfin Gabriel Krisman Bertazi
2015-04-26  1:26 ` [PATCH v3 05/17] Create syscall groups for ppc Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 15/17] Create syscall groups for s390x Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 16/17] Create syscall groups for sparc Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 17/17] Create syscall groups for sparc64 Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 11/17] Create syscall groups for mips-n32 Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 14/17] Create syscall groups for s390 Gabriel Krisman Bertazi
2015-04-26  1:47 ` [PATCH v3 13/17] Create syscall groups for mips-o32 Gabriel Krisman Bertazi
2015-04-26 18:58 ` [PATCH v3 00/17] Catch syscall group Sergio Durigan Junior
2015-04-28 11:24 ` Pedro Alves
2015-04-29  0:45   ` Sergio Durigan Junior
2015-04-29 10:44     ` Pedro Alves
2015-05-04  2:34       ` Gabriel Krisman Bertazi
2015-05-06 14:38         ` Pedro Alves
2015-05-10 18:34           ` Gabriel Krisman Bertazi
2015-05-10 19:01             ` Sergio Durigan Junior
2015-05-11  0:28               ` [PATCH v4 0/4] catch " Gabriel Krisman Bertazi
2015-05-11  0:28                 ` [PATCH v4 2/5] Add support to catch groups of syscalls Gabriel Krisman Bertazi
2015-05-13 10:38                   ` Pedro Alves
2015-05-11  0:28                 ` [PATCH v4 1/5] Implemement support for groups of syscalls in the xml-syscall interface Gabriel Krisman Bertazi
2015-05-11  0:28                 ` [PATCH v4 5/5] Update documentation on catching a group of related syscalls Gabriel Krisman Bertazi
2015-05-11  0:40                   ` Gabriel Krisman Bertazi
2015-05-13 10:30                     ` Pedro Alves
2015-05-13 16:40                       ` Eli Zaretskii
2015-05-11  0:28                 ` [PATCH v4 4/5] Include group information in xml syscall files Gabriel Krisman Bertazi
2015-05-12 21:42                   ` Doug Evans
2015-05-13  1:17                     ` Gabriel Krisman Bertazi
2015-05-13 10:43                   ` Pedro Alves
2015-05-11  0:28                 ` [PATCH v4 3/5] Add tests for catching groups of syscalls on supported architectures Gabriel Krisman Bertazi
2015-05-13 10:47                 ` [PATCH v4 0/4] catch syscall group Pedro Alves
2015-05-11 11:39               ` [PATCH v3 00/17] Catch " Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1430011521-24340-3-git-send-email-gabriel@krisman.be \
    --to=gabriel@krisman.be \
    --cc=dje@google.com \
    --cc=gdb-patches@sourceware.org \
    --cc=sergiodj@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).