]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Change get_syscalls_by_group to append to an existing vector of integers.
authorJohn Baldwin <jhb@FreeBSD.org>
Thu, 13 Dec 2018 19:36:42 +0000 (11:36 -0800)
committerJohn Baldwin <jhb@FreeBSD.org>
Thu, 13 Dec 2018 19:36:42 +0000 (11:36 -0800)
This removes the need for the caller to explicitly manage the memory
for the returned system call list.  The sole caller only needed the
system call numbers rather than the full syscall structures.

get_syscalls_by_group now uses a boolean return value to indicate if
the requested group exists.

gdb/ChangeLog:

* break-catch-syscall.c (catch_syscall_split_args): Pass 'result'
to get_syscalls_by_group.
* xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_group): Return
false.
[HAVE_LIBEXPAT] (xml_list_syscalls_by_group): Append syscall
numbers to an existing vector of integers and return a bool.
(get_syscalls_by_group): Accept pointer to vector of integers
and change return type to bool.
* xml-syscall.h (get_syscalls_by_group): Likewise.

gdb/ChangeLog
gdb/break-catch-syscall.c
gdb/xml-syscall.c
gdb/xml-syscall.h

index bf40e682a9249946cdb1b86aaba242d8e7ff9595..93ee629cee512f1f6bebc7f73adc5aa5c75e2cb5 100644 (file)
@@ -1,3 +1,15 @@
+2018-12-13  John Baldwin  <jhb@FreeBSD.org>
+
+       * break-catch-syscall.c (catch_syscall_split_args): Pass 'result'
+       to get_syscalls_by_group.
+       * xml-syscall.c [!HAVE_LIBEXPAT] (get_syscalls_by_group): Return
+       false.
+       [HAVE_LIBEXPAT] (xml_list_syscalls_by_group): Append syscall
+       numbers to an existing vector of integers and return a bool.
+       (get_syscalls_by_group): Accept pointer to vector of integers
+       and change return type to bool.
+       * xml-syscall.h (get_syscalls_by_group): Likewise.
+
 2018-12-13  Jim Wilson  <jimw@sifive.com>
 
        * riscv-tdep.c (riscv_print_one_register_info): For MSTATUS, add
index 93ef74c249638df6206e159c930848f3e942ed20..bad34d6fd8652653078f9a0bf9cd5372ef2c9888 100644 (file)
@@ -409,25 +409,13 @@ 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);
-
-         if (syscall_list == NULL)
+         if (!get_syscalls_by_group (gdbarch, group_name, &result))
            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);
        }
       else
        {
index bf176429119e8f3798f31b91e3bdf0c8d05de5de..d1b5bf8a2fe9c37b10276a1d0fb7e23c1ea748c7 100644 (file)
@@ -77,11 +77,12 @@ get_syscall_names (struct gdbarch *gdbarch)
   return NULL;
 }
 
-struct syscall *
-get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
+bool
+get_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
+                      std::vector<int> *syscall_numbers)
 {
   syscall_warn_user ();
-  return NULL;
+  return false;
 }
 
 const char **
@@ -444,40 +445,27 @@ 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.  If the syscall group
+   doesn't exist, return false.  */
 
-static struct syscall *
-xml_list_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
+static bool
+xml_list_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
+                           std::vector<int> *syscalls)
 {
   struct syscalls_info *syscalls_info = gdbarch_syscalls_info (gdbarch);
   struct syscall_group_desc *groupdesc;
-  struct syscall *syscalls = NULL;
-  int nsyscalls;
-  int i;
 
-  if (syscalls_info == NULL)
-    return NULL;
+  if (syscalls_info == NULL || syscalls == NULL)
+    return false;
 
   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;
-    }
+    return false;
 
-  /* Add final element marker.  */
-  syscalls[i].name = NULL;
-  syscalls[i].number = 0;
+  for (const struct syscall_desc *sysdesc : groupdesc->syscalls)
+    syscalls->push_back (sysdesc->number);
 
-  return syscalls;
+  return true;
 }
 
 /* Return a NULL terminated list of syscall groups or an empty list, if
@@ -542,12 +530,13 @@ get_syscall_names (struct gdbarch *gdbarch)
 
 /* See comment in xml-syscall.h.  */
 
-struct syscall *
-get_syscalls_by_group (struct gdbarch *gdbarch, const char *group)
+bool
+get_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
+                      std::vector<int> *syscall_numbers)
 {
   init_syscalls_info (gdbarch);
 
-  return xml_list_syscalls_by_group (gdbarch, group);
+  return xml_list_syscalls_by_group (gdbarch, group, syscall_numbers);
 }
 
 /* See comment in xml-syscall.h.  */
index 4429d66400d4b0a312315dfbf8634a892f968490..012a4b75a4e4c3d4c68e9fef240a224765c3d405 100644 (file)
@@ -51,13 +51,11 @@ 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.  The syscall numbers are appended to SYSCALL_NUMBERS.
+   If the group doesn't exist, return false.  */
 
-struct syscall *get_syscalls_by_group (struct gdbarch *gdbarch,
-                                      const char *group);
+bool get_syscalls_by_group (struct gdbarch *gdbarch, const char *group,
+                           std::vector<int> *syscall_numbers);
 
 /* Function used to retrieve the list of syscall groups in the system.
    Return an array of strings terminated by a NULL element.  The list