From patchwork Thu Nov 7 09:14:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paunovic, Aleksandar" X-Patchwork-Id: 35715 Received: (qmail 65013 invoked by alias); 7 Nov 2019 09:14:35 -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 64998 invoked by uid 89); 7 Nov 2019 09:14:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-10.7 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS autolearn=ham version=3.3.1 spammy=Commercial, 10-12, HX-Spam-Relays-External:10.253.24.58, Deutschland X-HELO: mga17.intel.com Received: from mga17.intel.com (HELO mga17.intel.com) (192.55.52.151) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 07 Nov 2019 09:14:32 +0000 Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 07 Nov 2019 01:14:31 -0800 Received: from irsmsx151.ger.corp.intel.com ([163.33.192.59]) by fmsmga008.fm.intel.com with ESMTP; 07 Nov 2019 01:14:30 -0800 Received: from irsmsx107.ger.corp.intel.com ([169.254.10.18]) by IRSMSX151.ger.corp.intel.com ([169.254.4.59]) with mapi id 14.03.0439.000; Thu, 7 Nov 2019 09:14:29 +0000 From: "Paunovic, Aleksandar" To: Pedro Alves CC: "gdb-patches@sourceware.org" Subject: RE: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread Date: Thu, 7 Nov 2019 09:14:29 +0000 Message-ID: References: <20191017225026.30496-1-palves@redhat.com> <20191017225026.30496-9-palves@redhat.com> In-Reply-To: <20191017225026.30496-9-palves@redhat.com> MIME-Version: 1.0 X-IsSubscribed: yes Shouldn't there be this change as well: --- 2.14.5 Intel Deutschland GmbH Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany Tel: +49 89 99 8853-0, www.intel.de Managing Directors: Christin Eisenschmid, Gary Kershaw Chairperson of the Supervisory Board: Nicole Lau Registered Office: Munich Commercial Register: Amtsgericht Muenchen HRB 186928 diff --git a/gdb/progspace-and-thread.c b/gdb/progspace-and-thread.c index 3c92b5c8e0..f66aabea40 100644 --- a/gdb/progspace-and-thread.c +++ b/gdb/progspace-and-thread.c @@ -39,6 +39,5 @@ switch_to_program_space_and_thread (program_space *pspace) } } - switch_to_no_thread (); - set_current_program_space (pspace); + switch_to_inferior_no_thread (inf); } This fixes the case when an inferior has PID = 0. The problem is that in the current state GDB would switch to no_thread and also set the program space but because the inferior is not switched, potentially an incorrect target would remain. Here is a sample scenario that exploits this flow: # On terminal 1, start a gdbserver on a program named foo: $ gdbserver :1234 ./foo # On terminal 2, start gdb on a program named bar. Suppose foo and bar are compiled from foo.c and bar.c. They are completely separate. So, bar.c:2 has no meaning for foo. $ gdb -q ./bar Reading symbols from ./bar... (gdb) add-inferior [New inferior 2] Added inferior 2 (gdb) inferior 2 [Switching to inferior 2 [] ()] (gdb) target remote :1234 ... (gdb) set debug remote 2 (gdb) break bar.c:2 Sending packet: $Hgp0.0#ad...Packet received: OK Sending packet: $m5fa,12#f8...Packet received: E01 Sending packet: $m5fa,1#c6...Packet received: E01 Sending packet: $m5fb,3#c9...Packet received: E01 Sending packet: $m5fe,1#ca...Packet received: E01 Breakpoint 1 at 0x5fe: file bar.c, line 2. (gdb) Here we have an unnecessary sending of the packets to the gdbserver. But with the proposed change in progspace-and-thread.c there is this (gdb) break bar.c:2 Breakpoint 1 at 0x5fe: file bar.c, line 2. (gdb) Now there is no sending of the packets to the gdbserver. -----Original Message----- From: gdb-patches-owner@sourceware.org On Behalf Of Pedro Alves Sent: Friday, October 18, 2019 12:50 AM To: gdb-patches@sourceware.org Subject: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread 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. 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. * mi/mi-main.c (run_one_inferior): Use switch_to_inferior_no_thread. --- gdb/inferior.c | 21 +++++++++++++-------- gdb/inferior.h | 4 ++++ gdb/mi/mi-main.c | 6 +----- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/gdb/inferior.c b/gdb/inferior.c index 310b8f5dd3..619b8caac7 100644 --- a/gdb/inferior.c +++ b/gdb/inferior.c @@ -585,6 +585,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) { @@ -615,9 +625,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); @@ -747,11 +755,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 720d570fa3..2e19b751ca 100644 --- a/gdb/inferior.h +++ b/gdb/inferior.h @@ -310,6 +310,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 diff --git a/gdb/mi/mi-main.c b/gdb/mi/mi-main.c index 9a0b7f97b2..4fa7ffaf90 100644 --- a/gdb/mi/mi-main.c +++ b/gdb/mi/mi-main.c @@ -414,11 +414,7 @@ run_one_inferior (struct inferior *inf, void *arg) switch_to_thread (tp); } else - { - set_current_inferior (inf); - switch_to_no_thread (); - set_current_program_space (inf->pspace); - } + switch_to_inferior_no_thread (inf); mi_execute_cli_command (run_cmd, async_p, async_p ? "&" : NULL); return 0;