target_set_syscall_catchpoint, use gdb::array_view and bool
authorPedro Alves <palves@redhat.com>
Wed, 6 Dec 2017 22:45:09 +0000 (17:45 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Wed, 6 Dec 2017 22:49:37 +0000 (17:49 -0500)
I noticed that we're passing down a data/size pair to
target_ops::to_set_syscall_catchpoint.  This commit makes use of
gdb::array_view instead.  While at it, use bool where appropriate as
well.

gdb/ChangeLog:

* break-catch-syscall.c (insert_catch_syscall)
(remove_catch_syscall): Adjust to pass reference to
inf_data->syscalls_counts directly via gdb::array_view.
* fbsd-nat.c (fbsd_set_syscall_catchpoint): Adjust to use bool
and gdb::array_view.
* linux-nat.c (linux_child_set_syscall_catchpoint): Likewise.
* remote.c (remote_set_syscall_catchpoint): Likewise.
* target-debug.h (target_debug_print_bool): New.
(define target_debug_print_gdb_array_view_const_int): New.
* target-delegates.c: Regenerate.
* target.h (target_ops) <to_set_syscall_catchpoint>: Use
gdb::array_view and bool.
(target_set_syscall_catchpoint): Likewise.

gdb/ChangeLog
gdb/break-catch-syscall.c
gdb/fbsd-nat.c
gdb/linux-nat.c
gdb/remote.c
gdb/target-debug.h
gdb/target-delegates.c
gdb/target.h

index c9a409831fa11f601a802d8f0ac592ed3d7ee32f..cb3c83dacea64cfe3730b1e844a26dffa1f1dc01 100644 (file)
@@ -1,3 +1,19 @@
+2017-12-06  Pedro Alves  <palves@redhat.com>
+
+       * break-catch-syscall.c (insert_catch_syscall)
+       (remove_catch_syscall): Adjust to pass reference to
+       inf_data->syscalls_counts directly via gdb::array_view.
+       * fbsd-nat.c (fbsd_set_syscall_catchpoint): Adjust to use bool
+       and gdb::array_view.
+       * linux-nat.c (linux_child_set_syscall_catchpoint): Likewise.
+       * remote.c (remote_set_syscall_catchpoint): Likewise.
+       * target-debug.h (target_debug_print_bool): New.
+       (define target_debug_print_gdb_array_view_const_int): New.
+       * target-delegates.c: Regenerate.
+       * target.h (target_ops) <to_set_syscall_catchpoint>: Use
+       gdb::array_view and bool.
+       (target_set_syscall_catchpoint): Likewise.
+
 2017-12-06  Simon Marchi  <simon.marchi@ericsson.com>
 
        * break-catch-syscall.c (catch_syscall_completer): Get pointers
index dd7b37997b4519c8a323fc39ab450d711942d852..57044c1bad1643897b6c7ba5998d7aaa6a5aeecb 100644 (file)
@@ -113,8 +113,7 @@ insert_catch_syscall (struct bp_location *bl)
   return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
                                        inf_data->total_syscalls_count != 0,
                                        inf_data->any_syscall_count,
-                                       inf_data->syscalls_counts.size (),
-                                       inf_data->syscalls_counts.data ());
+                                       inf_data->syscalls_counts);
 }
 
 /* Implement the "remove" breakpoint_ops method for syscall
@@ -145,8 +144,7 @@ remove_catch_syscall (struct bp_location *bl, enum remove_bp_reason reason)
   return target_set_syscall_catchpoint (ptid_get_pid (inferior_ptid),
                                        inf_data->total_syscalls_count != 0,
                                        inf_data->any_syscall_count,
-                                       inf_data->syscalls_counts.size (),
-                                       inf_data->syscalls_counts.data ());
+                                       inf_data->syscalls_counts);
 }
 
 /* Implement the "breakpoint_hit" breakpoint_ops method for syscall
index 265175a769478b0b184ba916f20710540971442d..29b7ee5e337c323be365f26fa865b64feca9193f 100644 (file)
@@ -1163,8 +1163,9 @@ fbsd_remove_exec_catchpoint (struct target_ops *self, int pid)
 
 #ifdef HAVE_STRUCT_PTRACE_LWPINFO_PL_SYSCALL_CODE
 static int
-fbsd_set_syscall_catchpoint (struct target_ops *self, int pid, int needed,
-                            int any_count, int table_size, int *table)
+fbsd_set_syscall_catchpoint (struct target_ops *self, int pid, bool needed,
+                            int any_count,
+                            gdb::array_view<const int> syscall_counts)
 {
 
   /* Ignore the arguments.  inf-ptrace.c will use PT_SYSCALL which
index 96cb21a2cf915d9e3dbea3ad0eaf976450789221..b8f3108937016222caf48103db3512666bb6bdb5 100644 (file)
@@ -676,8 +676,8 @@ linux_child_remove_exec_catchpoint (struct target_ops *self, int pid)
 
 static int
 linux_child_set_syscall_catchpoint (struct target_ops *self,
-                                   int pid, int needed, int any_count,
-                                   int table_size, int *table)
+                                   int pid, bool needed, int any_count,
+                                   gdb::array_view<const int> syscall_counts)
 {
   if (!linux_supports_tracesysgood ())
     return 1;
@@ -685,7 +685,7 @@ linux_child_set_syscall_catchpoint (struct target_ops *self,
   /* On GNU/Linux, we ignore the arguments.  It means that we only
      enable the syscall catchpoints, but do not disable them.
 
-     Also, we do not use the `table' information because we do not
+     Also, we do not use the `syscall_counts' information because we do not
      filter system calls here.  We let GDB do the logic for us.  */
   return 0;
 }
index 306cc1ea55f8a57cce27cf4c4070924a8e0c9f1a..fe2771316cbc63c23302c71d96c01ebb65b95ce5 100644 (file)
@@ -2024,8 +2024,8 @@ remote_pass_signals (struct target_ops *self,
 
 static int
 remote_set_syscall_catchpoint (struct target_ops *self,
-                              int pid, int needed, int any_count,
-                              int table_size, int *table)
+                              int pid, bool needed, int any_count,
+                              gdb::array_view<const int> syscall_counts)
 {
   const char *catch_packet;
   enum packet_result result;
@@ -2037,14 +2037,12 @@ remote_set_syscall_catchpoint (struct target_ops *self,
       return 1;
     }
 
-  if (needed && !any_count)
+  if (needed && any_count == 0)
     {
-      int i;
-
-      /* Count how many syscalls are to be caught (table[sysno] != 0).  */
-      for (i = 0; i < table_size; i++)
+      /* Count how many syscalls are to be caught.  */
+      for (size_t i = 0; i < syscall_counts.size (); i++)
        {
-         if (table[i] != 0)
+         if (syscall_counts[i] != 0)
            n_sysno++;
        }
     }
@@ -2066,13 +2064,13 @@ remote_set_syscall_catchpoint (struct target_ops *self,
       const int maxpktsz = strlen ("QCatchSyscalls:1") + n_sysno * 9 + 1;
       built_packet.reserve (maxpktsz);
       built_packet = "QCatchSyscalls:1";
-      if (!any_count)
+      if (any_count == 0)
        {
-         /* Add in catch_packet each syscall to be caught (table[i] != 0).  */
-         for (int i = 0; i < table_size; i++)
+         /* Add in each syscall to be caught.  */
+         for (size_t i = 0; i < syscall_counts.size (); i++)
            {
-             if (table[i] != 0)
-               string_appendf (built_packet, ";%x", i);
+             if (syscall_counts[i] != 0)
+               string_appendf (built_packet, ";%zx", i);
            }
        }
       if (built_packet.size () > get_remote_packet_size ())
index d1d7fb5b832b22d03e324707b692662ea630a495..27e5a55c40d9797dae2074786516dbfbd14fa1ec 100644 (file)
@@ -56,6 +56,8 @@
   target_debug_do_print (((X) ? (X) : "(null)"))
 #define target_debug_print_int(X)              \
   target_debug_do_print (plongest (X))
+#define target_debug_print_bool(X)             \
+  target_debug_do_print ((X) ? "true" : "false")
 #define target_debug_print_long(X)             \
   target_debug_do_print (plongest (X))
 #define target_debug_print_enum_target_xfer_status(X)  \
   target_debug_do_print (plongest (X))
 #define target_debug_print_traceframe_info_up(X) \
   target_debug_do_print (host_address_to_string (X.get ()))
+#define target_debug_print_gdb_array_view_const_int(X) \
+  target_debug_do_print (host_address_to_string (X.data ()))
 
 static void
 target_debug_print_struct_target_waitstatus_p (struct target_waitstatus *status)
index 9691074bfe21785e053b1dd22d037637de4fd3a3..aaf11d81b85d812aea1d38597978e2c19b95d4ba 100644 (file)
@@ -1286,36 +1286,34 @@ debug_follow_exec (struct target_ops *self, struct inferior *arg1, char *arg2)
 }
 
 static int
-delegate_set_syscall_catchpoint (struct target_ops *self, int arg1, int arg2, int arg3, int arg4, int *arg5)
+delegate_set_syscall_catchpoint (struct target_ops *self, int arg1, bool arg2, int arg3, gdb::array_view<const int> arg4)
 {
   self = self->beneath;
-  return self->to_set_syscall_catchpoint (self, arg1, arg2, arg3, arg4, arg5);
+  return self->to_set_syscall_catchpoint (self, arg1, arg2, arg3, arg4);
 }
 
 static int
-tdefault_set_syscall_catchpoint (struct target_ops *self, int arg1, int arg2, int arg3, int arg4, int *arg5)
+tdefault_set_syscall_catchpoint (struct target_ops *self, int arg1, bool arg2, int arg3, gdb::array_view<const int> arg4)
 {
   return 1;
 }
 
 static int
-debug_set_syscall_catchpoint (struct target_ops *self, int arg1, int arg2, int arg3, int arg4, int *arg5)
+debug_set_syscall_catchpoint (struct target_ops *self, int arg1, bool arg2, int arg3, gdb::array_view<const int> arg4)
 {
   int result;
   fprintf_unfiltered (gdb_stdlog, "-> %s->to_set_syscall_catchpoint (...)\n", debug_target.to_shortname);
-  result = debug_target.to_set_syscall_catchpoint (&debug_target, arg1, arg2, arg3, arg4, arg5);
+  result = debug_target.to_set_syscall_catchpoint (&debug_target, arg1, arg2, arg3, arg4);
   fprintf_unfiltered (gdb_stdlog, "<- %s->to_set_syscall_catchpoint (", debug_target.to_shortname);
   target_debug_print_struct_target_ops_p (&debug_target);
   fputs_unfiltered (", ", gdb_stdlog);
   target_debug_print_int (arg1);
   fputs_unfiltered (", ", gdb_stdlog);
-  target_debug_print_int (arg2);
+  target_debug_print_bool (arg2);
   fputs_unfiltered (", ", gdb_stdlog);
   target_debug_print_int (arg3);
   fputs_unfiltered (", ", gdb_stdlog);
-  target_debug_print_int (arg4);
-  fputs_unfiltered (", ", gdb_stdlog);
-  target_debug_print_int_p (arg5);
+  target_debug_print_gdb_array_view_const_int (arg4);
   fputs_unfiltered (") = ", gdb_stdlog);
   target_debug_print_int (result);
   fputs_unfiltered ("\n", gdb_stdlog);
index 638e2f06e684fa81c8defe0292dc8a810667b2a7..7863a8d843b3b28211e31b8934c1534c1ba9a46c 100644 (file)
@@ -607,7 +607,8 @@ struct target_ops
     void (*to_follow_exec) (struct target_ops *, struct inferior *, char *)
       TARGET_DEFAULT_IGNORE ();
     int (*to_set_syscall_catchpoint) (struct target_ops *,
-                                     int, int, int, int, int *)
+                                     int, bool, int,
+                                     gdb::array_view<const int>)
       TARGET_DEFAULT_RETURN (1);
     int (*to_has_exited) (struct target_ops *, int, int, int *)
       TARGET_DEFAULT_RETURN (0);
@@ -1615,28 +1616,24 @@ void target_follow_exec (struct inferior *inf, char *execd_pathname);
 
 /* Syscall catch.
 
-   NEEDED is nonzero if any syscall catch (of any kind) is requested.
-   If NEEDED is zero, it means the target can disable the mechanism to
+   NEEDED is true if any syscall catch (of any kind) is requested.
+   If NEEDED is false, it means the target can disable the mechanism to
    catch system calls because there are no more catchpoints of this type.
 
    ANY_COUNT is nonzero if a generic (filter-less) syscall catch is
-   being requested.  In this case, both TABLE_SIZE and TABLE should
-   be ignored.
+   being requested.  In this case, SYSCALL_COUNTS should be ignored.
 
-   TABLE_SIZE is the number of elements in TABLE.  It only matters if
-   ANY_COUNT is zero.
-
-   TABLE is an array of ints, indexed by syscall number.  An element in
-   this array is nonzero if that syscall should be caught.  This argument
-   only matters if ANY_COUNT is zero.
+   SYSCALL_COUNTS is an array of ints, indexed by syscall number.  An
+   element in this array is nonzero if that syscall should be caught.
+   This argument only matters if ANY_COUNT is zero.
 
    Return 0 for success, 1 if syscall catchpoints are not supported or -1
    for failure.  */
 
-#define target_set_syscall_catchpoint(pid, needed, any_count, table_size, table) \
+#define target_set_syscall_catchpoint(pid, needed, any_count, syscall_counts) \
      (*current_target.to_set_syscall_catchpoint) (&current_target,     \
                                                  pid, needed, any_count, \
-                                                 table_size, table)
+                                                 syscall_counts)
 
 /* Returns TRUE if PID has exited.  And, also sets EXIT_STATUS to the
    exit code of PID, if any.  */
This page took 0.043057 seconds and 4 git commands to generate.