From patchwork Wed Mar 8 05:29:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergio Durigan Junior X-Patchwork-Id: 19466 Received: (qmail 37748 invoked by alias); 8 Mar 2017 05:29:56 -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 37540 invoked by uid 89); 8 Mar 2017 05:29:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=ling, Hx-languages-length:5727, (unknown) X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 08 Mar 2017 05:29:43 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E8A4D81239; Wed, 8 Mar 2017 05:29:43 +0000 (UTC) Received: from psique.yyz.redhat.com (unused-10-15-17-193.yyz.redhat.com [10.15.17.193]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v285Te8A010590; Wed, 8 Mar 2017 00:29:43 -0500 From: Sergio Durigan Junior To: GDB Patches Cc: Pedro Alves , Luis Machado , Sergio Durigan Junior Subject: [PATCH v4 3/5] Share parts of gdb/gdbthread.h with gdbserver Date: Wed, 8 Mar 2017 00:29:29 -0500 Message-Id: <20170308052931.25398-4-sergiodj@redhat.com> In-Reply-To: <20170308052931.25398-1-sergiodj@redhat.com> References: <20170208032257.15443-1-sergiodj@redhat.com> <20170308052931.25398-1-sergiodj@redhat.com> X-IsSubscribed: yes Again, it was necessary to share a few functions declared on gdb/gdbthread.h with gdbserver, because they are needed by fork_inferior. I decided to implement them on gdb/gdbserver/inferiors.c because that's where the thread functions are also implemented on gdbserver. Some of these functions do not need to be implemented on gdbserver, or don't make sense there, so they are left blank and commented properly. gdb/ChangeLog: yyyy-mm-dd Sergio Durigan Junior * Makefile.in (HFILES_NO_SRCDIR): Add "common/common-gdbthread.h". * common/common-gdbthread.h: New file, with parts from "gdb/gdbthread.h". * gdbthread.h: Include "common-gdbthread.h". (init_thread_list): Moved to "common/common-gdbthread.h". (add_thread_silent): Likewise. (switch_to_thread): Likewise. (set_executing): Likewise. * thread.c (set_executing): Update function comment. gdb/gdbserver/ChangeLog: yyyy-mm-dd Sergio Durigan Junior * inferiors.c (init_thread_list): New function. (switch_to_thread): Likewise. (set_executing): Likewise. (add_thread_silent): Likewise. --- gdb/Makefile.in | 1 + gdb/common/common-gdbthread.h | 35 +++++++++++++++++++++++++++++++++++ gdb/gdbserver/inferiors.c | 31 +++++++++++++++++++++++++++++++ gdb/gdbthread.h | 12 +----------- 4 files changed, 68 insertions(+), 11 deletions(-) create mode 100644 gdb/common/common-gdbthread.h diff --git a/gdb/Makefile.in b/gdb/Makefile.in index 6ad03d7..e5b0363 100644 --- a/gdb/Makefile.in +++ b/gdb/Makefile.in @@ -1482,6 +1482,7 @@ HFILES_NO_SRCDIR = \ common/common-debug.h \ common/common-defs.h \ common/common-exceptions.h \ + common/common-gdbthread.h \ common/common-regcache.h \ common/common-types.h \ common/common-utils.h \ diff --git a/gdb/common/common-gdbthread.h b/gdb/common/common-gdbthread.h new file mode 100644 index 0000000..c8a4422 --- /dev/null +++ b/gdb/common/common-gdbthread.h @@ -0,0 +1,35 @@ +/* Common multi-process/thread control defs for GDB and gdbserver. + Copyright (C) 1987-2017 Free Software Foundation, Inc. + + This file is part of GDB. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#ifndef COMMON_GDBTHREAD_H +#define COMMON_GDBTHREAD_H + +struct target_waitstatus; + +/* Create an empty thread list, or empty the existing one. */ +extern void init_thread_list (void); + +/* Switch from one thread to another. */ +extern void switch_to_thread (ptid_t ptid); + +/* Add a thread to the thread list and return the pointer to the new + thread. Caller may use this pointer to initialize the private + thread data. */ +extern struct thread_info *add_thread_silent (ptid_t ptid); + +#endif /* ! COMMON_GDBTHREAD_H */ diff --git a/gdb/gdbserver/inferiors.c b/gdb/gdbserver/inferiors.c index b65a726..c9d03a8 100644 --- a/gdb/gdbserver/inferiors.c +++ b/gdb/gdbserver/inferiors.c @@ -468,3 +468,34 @@ make_cleanup_restore_current_thread (void) { return make_cleanup (do_restore_current_thread_cleanup, current_thread); } + +/* See common/common-gdbthread.h. */ + +void +init_thread_list (void) +{ + /* Placeholder needed for fork_inferior. No action is needed. */ +} + +/* See common/common-gdbthread.h. */ + +void +switch_to_thread (ptid_t ptid) +{ + if (!ptid_equal (ptid, minus_one_ptid)) + current_thread = find_thread_ptid (ptid); +} + +/* See common/common-gdbthread.h. */ + +struct thread_info * +add_thread_silent (ptid_t ptid) +{ + pid_t pid = ptid_get_pid (ptid); + + /* Check if there is a process already. */ + if (find_process_pid (pid) == NULL) + add_process (pid, 0); + + return add_thread (ptid_build (pid, pid, 0), NULL); +} diff --git a/gdb/gdbthread.h b/gdb/gdbthread.h index 06ed78f..5647ae6 100644 --- a/gdb/gdbthread.h +++ b/gdb/gdbthread.h @@ -31,6 +31,7 @@ struct symtab; #include "common/vec.h" #include "target/waitstatus.h" #include "cli/cli-utils.h" +#include "common-gdbthread.h" /* Frontend view of the thread state. Possible extensions: stepping, finishing, until(ling),... */ @@ -344,19 +345,12 @@ struct thread_info struct thread_info *step_over_next; }; -/* Create an empty thread list, or empty the existing one. */ -extern void init_thread_list (void); - /* Add a thread to the thread list, print a message that a new thread is found, and return the pointer to the new thread. Caller my use this pointer to initialize the private thread data. */ extern struct thread_info *add_thread (ptid_t ptid); -/* Same as add_thread, but does not print a message - about new thread. */ -extern struct thread_info *add_thread_silent (ptid_t ptid); - /* Same as add_thread, and sets the private info. */ extern struct thread_info *add_thread_with_info (ptid_t ptid, struct private_thread_info *); @@ -469,10 +463,6 @@ extern struct thread_info *iterate_over_threads (thread_callback_func, void *); extern int thread_count (void); -/* Switch from one thread to another. Also sets the STOP_PC - global. */ -extern void switch_to_thread (ptid_t ptid); - /* Switch from one thread to another. Does not read registers and sets STOP_PC to -1. */ extern void switch_to_thread_no_regs (struct thread_info *thread);