From patchwork Thu Oct 15 14:36:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandar Ristovski X-Patchwork-Id: 9162 Received: (qmail 94485 invoked by alias); 15 Oct 2015 14:36:58 -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 94476 invoked by uid 89); 15 Oct 2015 14:36:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_SOFTFAIL autolearn=no version=3.3.2 X-HELO: smtp-a01.blackberry.com Received: from smtp-a01.blackberry.com (HELO smtp-a01.blackberry.com) (208.65.78.90) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 15 Oct 2015 14:36:56 +0000 Received: from mhs102cnc.rim.net ([10.65.141.76]) by mhs210cnc-app.rim.net with ESMTP; 15 Oct 2015 10:36:54 -0400 Received: from unknown (HELO qnxws9580.ott.qnx.com) ([10.65.140.253]) by mhs102cnc.rim.net with ESMTP; 15 Oct 2015 14:36:56 +0000 From: Aleksandar Ristovski To: gdb-patches@sourceware.org Cc: Aleksandar Ristovski Subject: [PATCH] gdbserver: Reset current_thread when its process is removed. Date: Thu, 15 Oct 2015 10:36:48 -0400 Message-Id: <1444919808-22088-1-git-send-email-aristovski@qnx.com> In case of running gdbserver with --multi, if a nat file removes a process, current_thread may remain set to now freed 'process' entry. This may lead to wrong operation or a crash. gdb/gdbserver/ChangeLog: * inferiors.c (remove_process): Reset current_thread if its associated process gets removed. --- gdb/gdbserver/inferiors.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index 21f45fa..4688a44 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -291,6 +291,11 @@ remove_process (struct process_info *process) { clear_symbol_cache (&process->symbol_cache); free_all_breakpoints (process); + if (current_thread && get_thread_process (current_thread) == process) + { + remove_thread (current_thread); + current_thread = NULL; + } remove_inferior (&all_processes, &process->entry); free (process); }