diff mbox

[v2,1/3] Return a vector of integers from get_syscalls_by_group.

Message ID 20181106175431.59832-2-jhb@FreeBSD.org
State New
Headers show

Commit Message

John Baldwin Nov. 6, 2018, 5:54 p.m. UTC
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(-)

Comments

Kevin Buettner Nov. 9, 2018, 4:27 a.m. UTC | #1
On Tue,  6 Nov 2018 09:54:29 -0800
John Baldwin <jhb@FreeBSD.org> wrote:

> 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

s/HAVE_LIBEXPATH/HAVE_LIBEXPAT/

> 	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.

Otherwise, okay.

Kevin
John Baldwin Nov. 9, 2018, 5:55 p.m. UTC | #2
On 11/8/18 8:27 PM, Kevin Buettner wrote:
> On Tue,  6 Nov 2018 09:54:29 -0800
> John Baldwin <jhb@FreeBSD.org> wrote:
> 
>> 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
> 
> s/HAVE_LIBEXPATH/HAVE_LIBEXPAT/

Thanks, will be fixed in v3.
diff mbox

Patch

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.