From patchwork Fri Sep 6 23:27:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 34421 Received: (qmail 120092 invoked by alias); 6 Sep 2019 23:28:20 -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 120051 invoked by uid 89); 6 Sep 2019 23:28:19 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.9 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.1 spammy=5846 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; Fri, 06 Sep 2019 23:28:18 +0000 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 26E74981C9 for ; Fri, 6 Sep 2019 23:28:17 +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 B70445D9D3 for ; Fri, 6 Sep 2019 23:28:16 +0000 (UTC) From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 08/23] Introduce switch_to_inferior_no_thread Date: Sat, 7 Sep 2019 00:27:52 +0100 Message-Id: <20190906232807.6191-9-palves@redhat.com> In-Reply-To: <20190906232807.6191-1-palves@redhat.com> References: <20190906232807.6191-1-palves@redhat.com> Several places want to switch context to an inferior and its pspace, while at the same time switch to "no thread selected". This commit adds a function that does that, and uses it in a few places. The function is made extern because many more uses will be added in follow up commits. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * inferior.c (switch_to_inferior_no_thread): New function, factored out from ... (inferior_command): ... here. * inferior.h (switch_to_inferior_no_thread): Declare. --- gdb/inferior.c | 21 +++++++++++++-------- gdb/inferior.h | 4 ++++ 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/gdb/inferior.c b/gdb/inferior.c index 994938d564..18f6f805cc 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -584,6 +584,16 @@ kill_inferior_command (const char *args, int from_tty) bfd_cache_close_all (); } +/* See inferior.h. */ + +void +switch_to_inferior_no_thread (inferior *inf) +{ + set_current_inferior (inf); + switch_to_no_thread (); + set_current_program_space (inf->pspace); +} + static void inferior_command (const char *args, int from_tty) { @@ -614,9 +624,7 @@ inferior_command (const char *args, int from_tty) } else { - set_current_inferior (inf); - switch_to_no_thread (); - set_current_program_space (inf->pspace); + switch_to_inferior_no_thread (inf); gdb::observers::user_selected_context_changed.notify (USER_SELECTED_INFERIOR); @@ -746,11 +754,8 @@ add_inferior_command (const char *args, int from_tty) if (exec != NULL) { /* Switch over temporarily, while reading executable and - symbols.q. */ - set_current_program_space (inf->pspace); - set_current_inferior (inf); - switch_to_no_thread (); - + symbols. */ + switch_to_inferior_no_thread (inf); exec_file_attach (exec.get (), from_tty); symbol_file_add_main (exec.get (), add_flags); } diff --git a/gdb/inferior.h b/gdb/inferior.h index ce9bcbf122..967d4fa8b7 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -329,6 +329,10 @@ extern inferior *current_inferior (); extern void set_current_inferior (inferior *); +/* Switch inferior (and program space) to INF, and switch to no thread + selected. */ +extern void switch_to_inferior_no_thread (inferior *inf); + /* GDB represents the state of each program execution with an object called an inferior. An inferior typically corresponds to a process but is more general and applies also to targets that do not have a