From patchwork Thu Jul 12 22:25:41 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 28358 Received: (qmail 44384 invoked by alias); 12 Jul 2018 22:25:48 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 44239 invoked by uid 89); 12 Jul 2018 22:25:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mx1.redhat.com Received: from mx3-rdu2.redhat.com (HELO mx1.redhat.com) (66.187.233.73) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Jul 2018 22:25:46 +0000 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A68DA81A8EB4 for ; Thu, 12 Jul 2018 22:25:44 +0000 (UTC) Received: from localhost.localdomain (ovpn04.gateway.prod.ext.ams2.redhat.com [10.39.146.4]) by smtp.corp.redhat.com (Postfix) with ESMTP id 52E521C665 for ; Thu, 12 Jul 2018 22:25:44 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 2/2] GDBserver: Pass process_info pointer to target_kill Date: Thu, 12 Jul 2018 23:25:41 +0100 Message-Id: <20180712222541.16229-3-palves@redhat.com> In-Reply-To: <20180712222541.16229-1-palves@redhat.com> References: <20180712222541.16229-1-palves@redhat.com> We start from a process_info pointer, pass down process->pid, and then the target_kill implementations need to find the process from the pid again. Pass the process_info pointer down directly instead. gdb/gdbserver/ChangeLog: yyyy-mm-dd Pedro Alves * linux-low.c (linux_kill): Change parameter to process_info pointer instead of pid. Adjust. * lynx-low.c (lynx_kill): Likewise. * nto-low.c (nto_kill): Likewise. * spu-low.c (spu_kill): Likewise. * win32-low.c (win32_kill): Likewise. * server.c (handle_v_kill, kill_inferior_callback) (detach_or_kill_for_exit): Adjust. * target.c (kill_inferior): Change parameter to process_info pointer instead of pid. Adjust. * target.h (struct target_ops) : Change parameter to process_info pointer instead of pid. Adjust all implementations and callers. (kill_inferior): Likewise. --- gdb/gdbserver/linux-low.c | 11 +++-------- gdb/gdbserver/lynx-low.c | 9 ++------- gdb/gdbserver/nto-low.c | 4 +++- gdb/gdbserver/server.c | 12 ++++++------ gdb/gdbserver/spu-low.c | 6 ++---- gdb/gdbserver/target.c | 6 +++--- gdb/gdbserver/target.h | 6 +++--- gdb/gdbserver/win32-low.c | 11 +++-------- 8 files changed, 25 insertions(+), 40 deletions(-) diff --git a/gdb/gdbserver/linux-low.c b/gdb/gdbserver/linux-low.c index dfa7fbaa49..984464fcc2 100644 --- a/gdb/gdbserver/linux-low.c +++ b/gdb/gdbserver/linux-low.c @@ -1385,14 +1385,9 @@ kill_one_lwp_callback (thread_info *thread, int pid) } static int -linux_kill (int pid) +linux_kill (process_info *process) { - struct process_info *process; - struct lwp_info *lwp; - - process = find_process_pid (pid); - if (process == NULL) - return -1; + int pid = process->pid; /* If we're killing a running inferior, make sure it is stopped first, as PTRACE_KILL will not work otherwise. */ @@ -1405,7 +1400,7 @@ linux_kill (int pid) /* See the comment in linux_kill_one_lwp. We did not kill the first thread in the list, so do so now. */ - lwp = find_lwp_pid (ptid_t (pid)); + lwp_info *lwp = find_lwp_pid (ptid_t (pid)); if (lwp == NULL) { diff --git a/gdb/gdbserver/lynx-low.c b/gdb/gdbserver/lynx-low.c index 902a70386b..6c5933bc47 100644 --- a/gdb/gdbserver/lynx-low.c +++ b/gdb/gdbserver/lynx-low.c @@ -522,15 +522,10 @@ lynx_wait (ptid_t ptid, struct target_waitstatus *status, int options) /* Implement the kill target_ops method. */ static int -lynx_kill (int pid) +lynx_kill (process_info *process) { - ptid_t ptid = lynx_ptid_t (pid, 0); + ptid_t ptid = lynx_ptid_t (process->pid, 0); struct target_waitstatus status; - struct process_info *process; - - process = find_process_pid (pid); - if (process == NULL) - return -1; lynx_ptrace (PTRACE_KILL, ptid, 0, 0, 0); lynx_wait (ptid, &status, 0); diff --git a/gdb/gdbserver/nto-low.c b/gdb/gdbserver/nto-low.c index 46e96449a1..098678e70b 100644 --- a/gdb/gdbserver/nto-low.c +++ b/gdb/gdbserver/nto-low.c @@ -397,8 +397,10 @@ nto_attach (unsigned long pid) /* Send signal to process PID. */ static int -nto_kill (int pid) +nto_kill (process_info *proc) { + int pid = proc->pid; + TRACE ("%s %d\n", __func__, pid); kill (pid, SIGKILL); do_detach (); diff --git a/gdb/gdbserver/server.c b/gdb/gdbserver/server.c index b35015b7bf..540f643607 100644 --- a/gdb/gdbserver/server.c +++ b/gdb/gdbserver/server.c @@ -3080,7 +3080,10 @@ handle_v_kill (char *own_buf) pid = strtol (p, NULL, 16); else pid = signal_pid; - if (pid != 0 && kill_inferior (pid) == 0) + + process_info *proc = find_process_pid (pid); + + if (proc != nullptr && kill_inferior (proc) == 0) { cs.last_status.kind = TARGET_WAITKIND_SIGNALLED; cs.last_status.value.sig = GDB_SIGNAL_KILL; @@ -3481,10 +3484,7 @@ gdbserver_show_disableable (FILE *stream) static void kill_inferior_callback (process_info *process) { - int pid = process->pid; - - kill_inferior (pid); - discard_queued_stop_replies (ptid_t (pid)); + discard_queued_stop_replies (ptid_t (process->pid)); } /* Call this when exiting gdbserver with possible inferiors that need @@ -3528,7 +3528,7 @@ detach_or_kill_for_exit (void) if (process->attached) detach_inferior (process); else - kill_inferior (pid); + kill_inferior (process); discard_queued_stop_replies (ptid_t (pid)); }); diff --git a/gdb/gdbserver/spu-low.c b/gdb/gdbserver/spu-low.c index c2a8734f68..83a31a203d 100644 --- a/gdb/gdbserver/spu-low.c +++ b/gdb/gdbserver/spu-low.c @@ -326,12 +326,10 @@ spu_attach (unsigned long pid) /* Kill the inferior process. */ static int -spu_kill (int pid) +spu_kill (process_info *process) { int status, ret; - struct process_info *process = find_process_pid (pid); - if (process == NULL) - return -1; + int pid = process->pid; ptrace (PTRACE_KILL, pid, 0, 0); diff --git a/gdb/gdbserver/target.c b/gdb/gdbserver/target.c index 00379bfdc0..886e6cfb5c 100644 --- a/gdb/gdbserver/target.c +++ b/gdb/gdbserver/target.c @@ -332,11 +332,11 @@ target_pid_to_str (ptid_t ptid) } int -kill_inferior (int pid) +kill_inferior (process_info *proc) { - gdb_agent_about_to_close (pid); + gdb_agent_about_to_close (proc->pid); - return (*the_target->kill) (pid); + return (*the_target->kill) (proc); } /* Target can do hardware single step. */ diff --git a/gdb/gdbserver/target.h b/gdb/gdbserver/target.h index 7f59485580..fce54e05ad 100644 --- a/gdb/gdbserver/target.h +++ b/gdb/gdbserver/target.h @@ -90,9 +90,9 @@ struct target_ops int (*attach) (unsigned long pid); - /* Kill inferior PID. Return -1 on failure, and 0 on success. */ + /* Kill process PROC. Return -1 on failure, and 0 on success. */ - int (*kill) (int pid); + int (*kill) (process_info *proc); /* Detach from process PROC. Return -1 on failure, and 0 on success. */ @@ -497,7 +497,7 @@ void set_target_ops (struct target_ops *); #define myattach(pid) \ (*the_target->attach) (pid) -int kill_inferior (int); +int kill_inferior (process_info *proc); #define target_supports_fork_events() \ (the_target->supports_fork_events ? \ diff --git a/gdb/gdbserver/win32-low.c b/gdb/gdbserver/win32-low.c index 17729a83cc..765391dd47 100644 --- a/gdb/gdbserver/win32-low.c +++ b/gdb/gdbserver/win32-low.c @@ -805,15 +805,11 @@ win32_clear_inferiors (void) clear_inferiors (); } -/* Kill all inferiors. */ +/* Implementation of target_ops::kill. */ + static int -win32_kill (int pid) +win32_kill (process_info *process) { - struct process_info *process; - - if (current_process_handle == NULL) - return -1; - TerminateProcess (current_process_handle, 0); for (;;) { @@ -829,7 +825,6 @@ win32_kill (int pid) win32_clear_inferiors (); - process = find_process_pid (pid); remove_process (process); return 0; }