Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: John Baldwin <jhb@FreeBSD.org>
To: gdb-patches@sourceware.org
Subject: [PATCH v2 1/3] Return a vector of integers from get_syscalls_by_group.
Date: Tue, 06 Nov 2018 17:56:00 -0000	[thread overview]
Message-ID: <20181106175431.59832-2-jhb@FreeBSD.org> (raw)
In-Reply-To: <20181106175431.59832-1-jhb@FreeBSD.org>

This removes the need for the caller to explicitly manage the memory
for the returned system call list.  This change only returns the
numbers rather than a vector of syscall structures since the caller
only needs the numbers.

gdb/ChangeLog:

	* break-catch-syscall.c (catch_syscall_split_args): Update for
	get_syscalls_by_group returning a vector.
	* xml-syscall.c [!HAVE_LIBEXPATH] (get_syscalls_by_group): Return
	empty vector.
	[HAVE_LIBEXPAT] (xml_list_syscalls_by_group)
	(get_syscalls_by_group): Return a vector of integers.
	* xml-syscall.h (get_syscalls_by_group): Change return type to a
	vector of integers.
---
 gdb/ChangeLog             | 11 +++++++++++
 gdb/break-catch-syscall.c | 16 +++++-----------
 gdb/xml-syscall.c         | 36 ++++++++++--------------------------
 gdb/xml-syscall.h         |  8 +++-----
 4 files changed, 29 insertions(+), 42 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 68ecef7728..9f4c450e4e 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,14 @@
+2018-11-06  John Baldwin  <jhb@FreeBSD.org>
+
+	* break-catch-syscall.c (catch_syscall_split_args): Update for
+	get_syscalls_by_group returning a vector.
+	* xml-syscall.c [!HAVE_LIBEXPATH] (get_syscalls_by_group): Return
+	empty vector.
+	[HAVE_LIBEXPAT] (xml_list_syscalls_by_group)
+	(get_syscalls_by_group): Return a vector of integers.
+	* xml-syscall.h (get_syscalls_by_group): Change return type to a
+	vector of integers.
+
 2018-11-06  John Baldwin  <jhb@FreeBSD.org>
 
 	* riscv-fbsd-nat.c (getregs_supplies): Return true for
diff --git a/gdb/break-catch-syscall.c b/gdb/break-catch-syscall.c
index 93ef74c249..8e1de10fa7 100644
--- a/gdb/break-catch-syscall.c
+++ b/gdb/break-catch-syscall.c
@@ -409,25 +409,19 @@ catch_syscall_split_args (const char *arg)
 	{
 	  /* 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);
+	  std::vector<int> numbers = get_syscalls_by_group (gdbarch,
+							    group_name);
 
-	  if (syscall_list == NULL)
+	  if (numbers.empty ())
 	    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.  */
-	      result.push_back (syscall_list[i].number);
-	    }
-
-	  xfree (syscall_list);
+	  for (int number : numbers)
+	    result.push_back (number);
 	}
       else
 	{
diff --git a/gdb/xml-syscall.c b/gdb/xml-syscall.c
index bf17642911..c3cd425186 100644
--- a/gdb/xml-syscall.c
+++ b/gdb/xml-syscall.c
@@ -77,11 +77,11 @@ get_syscall_names (struct gdbarch *gdbarch)
   return NULL;
 }
 
-struct syscall *
+std::vector<int>
 get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
 {
   syscall_warn_user ();
-  return NULL;
+  return std::vector<int> ();
 }
 
 const char **
@@ -444,38 +444,22 @@ xml_list_of_syscalls (struct gdbarch *gdbarch)
 }
 
 /* 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.  */
+   syscalls that are part of the given group.  */
 
-static struct syscall *
+static std::vector<int>
 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 *syscalls = NULL;
-  int nsyscalls;
-  int i;
+  std::vector<int> syscalls;
 
   if (syscalls_info == NULL)
-    return NULL;
+    return syscalls;
 
   groupdesc = syscall_group_get_group_by_name (syscalls_info, group);
-  if (groupdesc == NULL)
-    return NULL;
-
-  nsyscalls = groupdesc->syscalls.size ();
-  syscalls = (struct syscall*) xmalloc ((nsyscalls + 1)
-					* sizeof (struct syscall));
-
-  for (i = 0; i < groupdesc->syscalls.size (); i++)
-    {
-      syscalls[i].name = groupdesc->syscalls[i]->name.c_str ();
-      syscalls[i].number = groupdesc->syscalls[i]->number;
-    }
-
-  /* Add final element marker.  */
-  syscalls[i].name = NULL;
-  syscalls[i].number = 0;
+  if (groupdesc != NULL)
+    for (const struct syscall_desc *sysdesc : groupdesc->syscalls)
+      syscalls.push_back (sysdesc->number);
 
   return syscalls;
 }
@@ -542,7 +526,7 @@ get_syscall_names (struct gdbarch *gdbarch)
 
 /* See comment in xml-syscall.h.  */
 
-struct syscall *
+std::vector<int>
 get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
 {
   init_syscalls_info (gdbarch);
diff --git a/gdb/xml-syscall.h b/gdb/xml-syscall.h
index 4429d66400..95c968c9c7 100644
--- a/gdb/xml-syscall.h
+++ b/gdb/xml-syscall.h
@@ -51,12 +51,10 @@ 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.  */
+   the system.  Return a vector of syscall numbers that are elements
+   of the group.  */
 
-struct syscall *get_syscalls_by_group (struct gdbarch *gdbarch,
+std::vector<int> get_syscalls_by_group (struct gdbarch *gdbarch,
 				       const char *group);
 
 /* Function used to retrieve the list of syscall groups in the system.
-- 
2.18.0


  parent reply	other threads:[~2018-11-06 17:56 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06 17:56 [PATCH v2 0/3] Update FreeBSD's syscall table John Baldwin
2018-11-06 17:56 ` [PATCH v2 3/3] Update the FreeBSD system call table to match FreeBSD 12.0 John Baldwin
2018-11-09  4:38   ` Kevin Buettner
2018-11-09 16:34   ` Pedro Alves
2018-11-09 17:36     ` John Baldwin
2018-11-06 17:56 ` John Baldwin [this message]
2018-11-09  4:27   ` [PATCH v2 1/3] Return a vector of integers from get_syscalls_by_group Kevin Buettner
2018-11-09 17:55     ` John Baldwin
2018-11-06 17:56 ` [PATCH v2 2/3] Add an optional "alias" attribute to syscall entries John Baldwin
2018-11-09  4:34   ` Kevin Buettner
2018-11-09 15:28   ` Simon Marchi
2018-11-09 15:36     ` Simon Marchi
2018-11-09 16:31   ` Pedro Alves
2018-11-09 16:52     ` John Baldwin
2018-11-06 18:49 ` [PATCH v2 0/3] Update FreeBSD's syscall table Sergio Durigan Junior

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=20181106175431.59832-2-jhb@FreeBSD.org \
    --to=jhb@freebsd.org \
    --cc=gdb-patches@sourceware.org \
    /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