Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "Aktemur, Tankut Baris" <tankut.baris.aktemur@intel.com>
To: Pedro Alves <palves@redhat.com>
Cc: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>,
	"Paunovic, Aleksandar" <aleksandar.paunovic@intel.com>
Subject: RE: [PATCH] Switch the inferior too in switch_to_program_space_and_thread (Re: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread)
Date: Wed, 08 Jan 2020 15:48:00 -0000	[thread overview]
Message-ID: <BYAPR11MB3030EEB170A91F4A26C48051C43E0@BYAPR11MB3030.namprd11.prod.outlook.com> (raw)
In-Reply-To: <489c25ee-b0ae-6a17-65cc-32c5d7c652d2@redhat.com>

On Monday, December 23, 2019 8:30 PM, Pedro Alves wrote:
> 
> On 12/20/19 6:50 PM, Pedro Alves wrote:
> 
> > Oh wow, thanks much for this.  You're right.  I'm working on
> > converting your example above to a testsuite testcase.
> 
> Here it is.  I'm putting this at the end of the series, after the
> multi-target patches, because before multi-target, the test
> fails -- GDB sends a spurious Hg0.0 packet to the remote side.
> 
> From 839bb32983d8afb085eeec1ac6ca499f5bbd6244 Mon Sep 17 00:00:00 2001
> From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>
> Date: Mon, 23 Dec 2019 18:04:32 +0000
> Subject: [PATCH] Switch the inferior too in switch_to_program_space_and_thread
> 
> With multi-target, each inferior now has its own target connection.
> The problem in switch_to_program_space_and_thread is that in the
> current state GDB switches to "no thread" and also sets the program
> space but because the inferior is not switched, potentially an
> incorrect target remains selected.
> 
> 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 [<null>] (<noexec>)]
>  (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.
> 
> With this fix in progspace-and-thread.c, we'll get 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 gdbserver.
> 
> gdb/ChangeLog:
> yyyy-mm-dd  Aleksandar Paunovic  <aleksandar.paunovic@intel.com>
> 	    Pedro Alves  <palves@redhat.com>
> 
> 	* progspace-and-thread.c (switch_to_program_space_and_thread):
> 	Assert there's an inferior for PSPACE.  Use
> 	switch_to_inferior_no_thread to switch the inferior too.
> 
> gdb/testsuite/ChangeLog:
> yyyy-mm-dd  Pedro Alves  <palves@redhat.com>
> 
> 	* gdb.server/bkpt-other-inferior.exp: New file.
> ---
>  gdb/progspace-and-thread.c                       |  6 +-
>  gdb/testsuite/gdb.server/bkpt-other-inferior.exp | 93 ++++++++++++++++++++++++
>  2 files changed, 96 insertions(+), 3 deletions(-)
>  create mode 100644 gdb/testsuite/gdb.server/bkpt-other-inferior.exp
> 
> diff --git a/gdb/progspace-and-thread.c b/gdb/progspace-and-thread.c
> index 3c92b5c8e0..d51748035e 100644
> --- a/gdb/progspace-and-thread.c
> +++ b/gdb/progspace-and-thread.c
> @@ -25,8 +25,9 @@ void
>  switch_to_program_space_and_thread (program_space *pspace)
>  {
>    inferior *inf = find_inferior_for_program_space (pspace);
> +  gdb_assert (inf != nullptr);


This creates failure in gdb.base/step-over-exit.exp.  The problem is, a forked
child terminates, and GDB tries to switch to the pspace of that no-longer-existing
inferior through a remaining breakpoint location.  Would it make sense to guard
calls to `switch_to_program_space_and_thread` as below, for example?

diff --git a/gdb/breakpoint.c b/gdb/breakpoint.c
index 080e847de1..30af603c73 100644
--- a/gdb/breakpoint.c
+++ b/gdb/breakpoint.c
@@ -2879,6 +2879,9 @@ update_inserted_breakpoint_locations (void)
       if (!bl->inserted || !bl->needs_update)
        continue;

+      if (find_inferior_for_program_space (bl->pspace) == nullptr)
+       continue;
+
       switch_to_program_space_and_thread (bl->pspace);

       /* For targets that support global breakpoints, there's no need

There are a handful other cases that can be guarded/skipped similarly.
I'm not sure, though, if the problem is deeper and the calls to
`switch_to_program_space_and_thread` for a non-existing inferior should have
never occurred.  That is, should the breakpoint locations of exited inferiors
be cleaned up much earlier, before we come to this point?

-Baris

> -  if (inf != NULL && inf->pid != 0)
> +  if (inf->pid != 0)
>      {
>        thread_info *tp = any_live_thread_of_inferior (inf);
> 
> @@ -39,6 +40,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);
>  }
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

  reply	other threads:[~2020-01-08 15:48 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 22:50 [PATCH v2 00/24] Multi-target support Pedro Alves
2019-10-17 22:50 ` [PATCH v2 02/24] Don't rely on inferior_ptid in record_full_wait Pedro Alves
2019-11-01 14:54   ` Tom Tromey
2019-12-20 17:49     ` Pedro Alves
2019-12-20 18:57       ` Tom Tromey
2019-10-17 22:50 ` [PATCH v2 03/24] Make "show remote exec-file" inferior-aware Pedro Alves
2019-10-17 22:50 ` [PATCH v2 10/24] Some get_last_target_status tweaks Pedro Alves
2019-10-17 22:50 ` [PATCH v2 15/24] Avoid another inferior_ptid reference in gdb/remote.c Pedro Alves
2019-10-17 22:50 ` [PATCH v2 11/24] tfile_target::close: trace_fd can't be -1 Pedro Alves
2019-10-17 22:50 ` [PATCH v2 17/24] Fix reconnecting to a gdbserver already debugging multiple processes, II Pedro Alves
2019-10-17 22:50 ` [PATCH v2 16/24] Fix reconnecting to a gdbserver already debugging multiple processes, I Pedro Alves
2019-10-17 22:50 ` [PATCH v2 06/24] Don't check target is running in remote_target::mourn_inferior Pedro Alves
2019-10-17 22:50 ` [PATCH v2 01/24] Preserve selected thread in all-stop w/ background execution Pedro Alves
2019-11-01 13:20   ` Tom Tromey
2019-12-20 17:22     ` Pedro Alves
2019-12-20 18:54       ` Tom Tromey
2019-12-20 18:57         ` Pedro Alves
2019-12-20 18:57           ` Tom Tromey
2019-10-17 22:50 ` [PATCH v2 21/24] Revert 'Remove unused struct serial::name field' Pedro Alves
2019-10-17 22:50 ` [PATCH v2 09/24] switch inferior/thread before calling target methods Pedro Alves
2019-10-17 22:50 ` [PATCH v2 12/24] Use all_non_exited_inferiors in infrun.c Pedro Alves
2019-10-17 22:51 ` [PATCH v2 04/24] exceptions.c:print_flush: Remove obsolete check Pedro Alves
2019-10-17 22:51 ` [PATCH v2 22/24] Add "info connections" command, "info inferiors" connection number/string Pedro Alves
2019-10-17 22:51 ` [PATCH v2 18/24] Multi-target support Pedro Alves
2020-01-11  3:12   ` Simon Marchi
2020-01-12  1:58     ` [pushed] Remove last traces of discard_all_inferiors (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2020-01-12 20:17   ` [PATCH v2 18/24] Multi-target support Simon Marchi
2020-01-13 15:19     ` Pedro Alves
2020-01-13 16:37       ` Simon Marchi
2020-01-12 22:30   ` Simon Marchi
2020-01-13 15:59     ` Pedro Alves
2020-01-17  4:03   ` Simon Marchi
2020-01-17 16:19     ` Simon Marchi
2020-01-17 15:18   ` Simon Marchi
2020-05-16  8:16   ` Andreas Schwab
2020-05-16 11:33     ` Fix IA-64 GNU/Linux build (Re: [PATCH v2 18/24] Multi-target support) Pedro Alves
2019-10-17 22:51 ` [PATCH v2 19/24] Add multi-target tests Pedro Alves
2019-10-17 22:57 ` [PATCH v2 05/24] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Pedro Alves
2019-10-17 22:57 ` [PATCH v2 23/24] Require always-non-stop for multi-target resumptions Pedro Alves
2019-11-01 14:51   ` Tom Tromey
2019-12-30 18:30     ` Pedro Alves
2019-12-31 20:06       ` Tom Tromey
2019-10-17 22:57 ` [PATCH v2 07/24] Delete unnecessary code from kill_command Pedro Alves
2019-10-17 22:59 ` [PATCH v2 20/24] gdbarch-selftests.c: No longer error out if debugging something Pedro Alves
2019-10-17 22:59 ` [PATCH v2 13/24] Delete exit_inferior_silent(int pid) Pedro Alves
2019-10-17 22:59 ` [PATCH v2 24/24] Multi-target: NEWS and user manual Pedro Alves
2019-10-17 22:59 ` [PATCH v2 08/24] Introduce switch_to_inferior_no_thread Pedro Alves
2019-11-07  9:14   ` Paunovic, Aleksandar
2019-12-20 18:50     ` Pedro Alves
2019-12-23 19:30       ` [PATCH] Switch the inferior too in switch_to_program_space_and_thread (Re: [PATCH v2 08/24] Introduce switch_to_inferior_no_thread) Pedro Alves
2020-01-08 15:48         ` Aktemur, Tankut Baris [this message]
2020-01-10  2:03           ` Pedro Alves
     [not found]             ` <BYAPR11MB30305218B921F31040FE4C1EC4380@BYAPR11MB3030.namprd11.prod.outlook.com>
2020-01-10 12:18               ` Pedro Alves
2020-01-10 14:41             ` Tom Tromey
2020-01-10 20:03               ` Pedro Alves
2019-10-17 23:00 ` [PATCH v2 14/24] Tweak handling of remote errors in response to resumption packet Pedro Alves
2019-10-18 20:23 ` [PATCH v2 00/24] Multi-target support John Baldwin
2019-10-29 19:13   ` Pedro Alves
2020-01-09 19:32     ` John Baldwin
2020-01-09 19:50       ` Pedro Alves
2020-01-10 13:49         ` Aktemur, Tankut Baris
2020-01-10 15:40           ` [PATCH] Switch the inferior before outputting its id in "info inferiors" (Re: [PATCH v2 00/24] Multi-target support) Pedro Alves
2019-10-20 11:41 ` [PATCH v2 00/24] Multi-target support Philippe Waroquiers
2019-10-29 19:56   ` Pedro Alves
2019-11-01 14:56 ` Tom Tromey
2020-01-10 20:13 ` Pedro Alves
2020-08-04  3:30   ` Kevin Buettner
2020-08-06 15:16     ` Pedro Alves
2020-08-06 17:49       ` Tom Tromey
2020-08-07 22:43       ` Kevin Buettner
2020-08-12 18:45         ` Pedro Alves

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=BYAPR11MB3030EEB170A91F4A26C48051C43E0@BYAPR11MB3030.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@intel.com \
    --cc=aleksandar.paunovic@intel.com \
    --cc=gdb-patches@sourceware.org \
    --cc=palves@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox