]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make process_info::syscalls_to_catch an std::vector
authorSimon Marchi <simon.marchi@polymtl.ca>
Fri, 17 Nov 2017 18:02:25 +0000 (13:02 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Fri, 17 Nov 2017 18:03:34 +0000 (13:03 -0500)
This patch makes the syscalls_to_catch field of process_info an
std::vector<int>.  The process_info structure must now be
newed/deleted.

In handle_extended_wait, the code that handles exec events destroys the
existing process_info and creates a new one.  It moves the content of
syscalls_to_catch from the old to the new vector.  I used std::move for
that (through an intermediary variable), which should have the same
behavior as the old code.

gdb/gdbserver/ChangeLog:

* inferiors.h (struct process_info): Add constructor, initialize
fields..
<syscalls_to_catch>: Change type to std::vector<int>.
* inferiors.c (add_process): Allocate process_info with new.
(remove_process): Free process_info with delete.
* linux-low.c (handle_extended_wait): Adjust.
(gdb_catching_syscalls_p, gdb_catch_this_syscall_p): Adjust.
* server.c (handle_general_set): Adjust.

gdb/gdbserver/ChangeLog
gdb/gdbserver/inferiors.c
gdb/gdbserver/inferiors.h
gdb/gdbserver/linux-low.c
gdb/gdbserver/server.c

index d091b430660051b8a786ebcb4f66704466b5e1e7..ab59f5209a6c049184ba3ebc15d630e3c4bc11e7 100644 (file)
@@ -1,3 +1,14 @@
+2017-11-17  Simon Marchi  <simon.marchi@polymtl.ca>
+
+       * inferiors.h (struct process_info): Add constructor, initialize
+       fields..
+       <syscalls_to_catch>: Change type to std::vector<int>.
+       * inferiors.c (add_process): Allocate process_info with new.
+       (remove_process): Free process_info with delete.
+       * linux-low.c (handle_extended_wait): Adjust.
+       (gdb_catching_syscalls_p, gdb_catch_this_syscall_p): Adjust.
+       * server.c (handle_general_set): Adjust.
+
 2017-11-16  Pedro Alves  <palves@redhat.com>
 
        * remote-utils.c (remote_close): Block SIGIO signals instead of
index a0ece4d3514726a79d5ca70627e71586d56ab154..f4101c7513b08761301e02e99045d5f1f5629fa3 100644 (file)
@@ -194,10 +194,7 @@ clear_inferiors (void)
 struct process_info *
 add_process (int pid, int attached)
 {
-  struct process_info *process = XCNEW (struct process_info);
-
-  process->pid = pid;
-  process->attached = attached;
+  process_info *process = new process_info (pid, attached);
 
   all_processes.push_back (process);
 
@@ -215,8 +212,7 @@ remove_process (struct process_info *process)
   free_all_breakpoints (process);
   gdb_assert (find_thread_process (process) == NULL);
   all_processes.remove (process);
-  VEC_free (int, process->syscalls_to_catch);
-  free (process);
+  delete process;
 }
 
 process_info *
index fb0e2fda81fc634c1ee19b7cf1b03a39f331c580..4c66a74305c52a502e24649ecca13bedacc71e1e 100644 (file)
@@ -33,6 +33,10 @@ struct process_info_private;
 
 struct process_info
 {
+  process_info (int pid_, int attached_)
+  : pid (pid_), attached (attached_)
+  {}
+
   /* This process' pid.  */
   int pid;
 
@@ -42,28 +46,28 @@ struct process_info
 
   /* True if GDB asked us to detach from this process, but we remained
      attached anyway.  */
-  int gdb_detached;
+  int gdb_detached = 0;
 
   /* The symbol cache.  */
-  struct sym_cache *symbol_cache;
+  struct sym_cache *symbol_cache = NULL;
 
   /* The list of memory breakpoints.  */
-  struct breakpoint *breakpoints;
+  struct breakpoint *breakpoints = NULL;
 
   /* The list of raw memory breakpoints.  */
-  struct raw_breakpoint *raw_breakpoints;
+  struct raw_breakpoint *raw_breakpoints = NULL;
 
   /* The list of installed fast tracepoints.  */
-  struct fast_tracepoint_jump *fast_tracepoint_jumps;
+  struct fast_tracepoint_jump *fast_tracepoint_jumps = NULL;
 
   /* The list of syscalls to report, or just a single element, ANY_SYSCALL,
      for unfiltered syscall reporting.  */
-  VEC (int) *syscalls_to_catch;
+  std::vector<int> syscalls_to_catch;
 
-  const struct target_desc *tdesc;
+  const struct target_desc *tdesc = NULL;
 
   /* Private target data.  */
-  struct process_info_private *priv;
+  struct process_info_private *priv = NULL;
 };
 
 /* Get the pid of PROC.  */
index b367e535a999ff9181b92464d944f7a2a4f6d22b..b267c70f059ad94ec8da6d7c2cabc2e16a724aa6 100644 (file)
@@ -683,7 +683,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
   else if (event == PTRACE_EVENT_EXEC && report_exec_events)
     {
       struct process_info *proc;
-      VEC (int) *syscalls_to_catch;
+      std::vector<int> syscalls_to_catch;
       ptid_t event_ptid;
       pid_t event_pid;
 
@@ -699,8 +699,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
 
       /* Save the syscall list from the execing process.  */
       proc = get_thread_process (event_thr);
-      syscalls_to_catch = proc->syscalls_to_catch;
-      proc->syscalls_to_catch = NULL;
+      syscalls_to_catch = std::move (proc->syscalls_to_catch);
 
       /* Delete the execing process and all its threads.  */
       linux_mourn (proc);
@@ -731,7 +730,7 @@ handle_extended_wait (struct lwp_info **orig_event_lwp, int wstat)
       /* Restore the list to catch.  Don't rely on the client, which is free
         to avoid sending a new list when the architecture doesn't change.
         Also, for ANY_SYSCALL, the architecture doesn't really matter.  */
-      proc->syscalls_to_catch = syscalls_to_catch;
+      proc->syscalls_to_catch = std::move (syscalls_to_catch);
 
       /* Report the event.  */
       *orig_event_lwp = event_lwp;
@@ -3182,7 +3181,7 @@ gdb_catching_syscalls_p (struct lwp_info *event_child)
   struct thread_info *thread = get_lwp_thread (event_child);
   struct process_info *proc = get_thread_process (thread);
 
-  return !VEC_empty (int, proc->syscalls_to_catch);
+  return !proc->syscalls_to_catch.empty ();
 }
 
 /* Returns 1 if GDB is interested in the event_child syscall.
@@ -3191,21 +3190,19 @@ gdb_catching_syscalls_p (struct lwp_info *event_child)
 static int
 gdb_catch_this_syscall_p (struct lwp_info *event_child)
 {
-  int i, iter;
   int sysno;
   struct thread_info *thread = get_lwp_thread (event_child);
   struct process_info *proc = get_thread_process (thread);
 
-  if (VEC_empty (int, proc->syscalls_to_catch))
+  if (proc->syscalls_to_catch.empty ())
     return 0;
 
-  if (VEC_index (int, proc->syscalls_to_catch, 0) == ANY_SYSCALL)
+  if (proc->syscalls_to_catch[0] == ANY_SYSCALL)
     return 1;
 
   get_syscall_trapinfo (event_child, &sysno);
-  for (i = 0;
-       VEC_iterate (int, proc->syscalls_to_catch, i, iter);
-       i++)
+
+  for (int iter : proc->syscalls_to_catch)
     if (iter == sysno)
       return 1;
 
index e827b9c701c50721293f9af54cdc1236dd8496f0..f0dac9569af7660662455aad9b9393a55539d654 100644 (file)
@@ -623,7 +623,7 @@ handle_general_set (char *own_buf)
        }
 
       process = current_process ();
-      VEC_truncate (int, process->syscalls_to_catch, 0);
+      process->syscalls_to_catch.clear ();
 
       if (enabled)
        {
@@ -634,11 +634,11 @@ handle_general_set (char *own_buf)
              while (*p != '\0')
                {
                  p = decode_address_to_semicolon (&sysno, p);
-                 VEC_safe_push (int, process->syscalls_to_catch, (int) sysno);
+                 process->syscalls_to_catch.push_back (sysno);
                }
            }
          else
-           VEC_safe_push (int, process->syscalls_to_catch, ANY_SYSCALL);
+           process->syscalls_to_catch.push_back (ANY_SYSCALL);
        }
 
       write_ok (own_buf);