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>
Subject: Re: [PATCH v1.1 01/23] Preserve selected thread in all-stop w/ background execution
Date: Thu, 17 Oct 2019 10:21:00 -0000	[thread overview]
Message-ID: <BYAPR11MB30305D5C8FBB36A09AE0480CC46D0@BYAPR11MB3030.namprd11.prod.outlook.com> (raw)
In-Reply-To: <c06fdff7-2f4a-f310-d6e0-23d00aab8cb6@redhat.com>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain; charset="utf-8", Size: 5778 bytes --]

* On Thursday, October 17, 2019 1:55 AM, Pedro Alves wrote:
> 
> On 10/9/19 10:36 AM, Aktemur, Tankut Baris wrote:
> > * On September 7, 2019 1:28 AM, Pedro Alves wrote:
> >>
> >> diff --git a/gdb/infrun.c b/gdb/infrun.c
> >> index a9588f896a..9c888aa72f 100644
> >> --- a/gdb/infrun.c
> >> +++ b/gdb/infrun.c
> >> @@ -3048,6 +3048,11 @@ proceed (CORE_ADDR addr, enum gdb_signal siggnal)
> >>
> >>    finish_state.release ();
> >>
> >> +  /* If we've switched threads above, switch back to the previously
> >> +     current thread.  We don't want the user to see a different
> >> +     selected thread.  */
> >> +  switch_to_thread (cur_thr);
> >> +
> >>    /* Tell the event loop to wait for it to stop.  If the target
> >>       supports asynchronous execution, it'll do this from within
> >>       target_resume.  */
> >> @@ -3702,14 +3707,11 @@ fetch_inferior_event (void *client_data)
> >>  	set_current_traceframe (-1);
> >>        }
> >>
> >> -    gdb::optional<scoped_restore_current_thread> maybe_restore_thread;
> >> -
> >> -    if (non_stop)
> >> -      /* In non-stop mode, the user/frontend should not notice a thread
> >> -	 switch due to internal events.  Make sure we reverse to the
> >> -	 user selected thread and frame after handling the event and
> >> -	 running any breakpoint commands.  */
> >> -      maybe_restore_thread.emplace ();
> >> +    /* The user/frontend should not notice a thread switch due to
> >> +       internal events.  Make sure we revert to the user selected
> >> +       thread and frame after handling the event and running any
> >> +       breakpoint commands.  */
> >> +    scoped_restore_current_thread restore_thread;
> >>
> >
> > Because this increases the refcount of the current thread, in case the
> > fetched inferior event denotes a thread exit, the thread will not be deleted
> > right away.  A non-deleted but exited thread stays in the inferior's thread
> > list.  This, in turn, causes the "init_thread_list" call in inferior.c to
> > be skipped.  As a side effect, a regression is observed in
> >
> >   gdb.arch/i386-mpx-simple_segv.exp
> 
> Thanks for spotting this.  I don't have MPX on my machine, so I'm not
> exactly sure the sequence of events that lead to a failure in that test,
> but I found a way to reproduce a related problem without MPX, and wrote
> a test based on it.
> 
> >
> > IMHO, the 'any_thread_p' predicate should be updated.  This predicate is used
> > in two places (one in 'inferior.c' and the other in 'mi/mi-main.c').  Both
> > uses, I believe, are in fact interested in whether there are any non-exited
> > threads.  I'd suggest updating 'any_thread_p' to 'any_non_exited_thread_p'.
> >
> 
> I'm really not sure about that.  Exited threads have a thread number still,
> as long as they're on the list.  Calling init_thread_list resets the
> global thread counter, meaning that you could end up with multiple threads
> with the same number, until the exited threads are purged.
> 
> I think instead a delete_exited_threads call in inferior_appeared
> is better.

Thanks, this makes sense.

> 
> >>      overlay_cache_invalid = 1;
> >>      /* Flush target cache before starting to handle each event.  Target
> >> @@ -3786,6 +3788,19 @@ fetch_inferior_event (void *client_data)
> >>  		inferior_event_handler (INF_EXEC_COMPLETE, NULL);
> >>  		cmd_done = 1;
> >>  	      }
> >> +
> >> +	    /* If we got a TARGET_WAITKIND_NO_RESUMED event, then the
> >> +	       previously selected thread is gone.  We have two
> >> +	       choices - switch to no thread selected, or restore the
> >> +	       previously selected thread (now exited).  We chose the
> >> +	       later, just because that's what GDB used to do.  After
> >> +	       this, "info threads" says "The current thread <Thread
> >> +	       ID 2> has terminated." instead of "No thread
> >> +	       selected.".  */
> >> +	    if (!non_stop
> >> +		&& cmd_done
> >> +		&& ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED)
> >> +	      restore_thread.dont_restore ();
> >>  	  }
> >>        }
> >>
> >
> > The comment and the code seem to contradict each other.  The comment says
> > "if we got a TARGET_WAITKIND_NO_RESUMED" whereas the condition is
> >
> >   ecs->ws.kind != TARGET_WAITKIND_NO_RESUMED
> 
> I don't think they're contradicting, actually.
> 
> When the 'if' condition is true, we won't restore the selected thread.
> So we if we got a TARGET_WAITKIND_NO_RESUMED, we restore the previous
> selected thread.  For all other event kinds, we won't restore.
> 

Right, sorry, my bad.

> >
> > Should TARGET_WAITKIND_THREAD_EXITED, TARGET_WAITKIND_EXITED, and
> > TARGET_WAITKIND_SIGNALLED be also included in the condition?  They also mean
> > that the thread is gone, right?
> 
> Not necessarily.  With checkpoint, gdb automatically switches to
> another checkpoint on TARGET_WAITKIND_EXITED/TARGET_WAITKIND_SIGNALLED:
> 
> (gdb) checkpoint
> checkpoint 1: fork returned pid 10741.
> (gdb) c
> Continuing.
> [Inferior 1 (process 10737) exited normally]
> [Switching to process 10741]
> (gdb) info threads
>   Id   Target Id            Frame
> * 1    process 10741 "main" main () at main.cc:21
> (gdb)
> 
> Here's an updated patch.  I believe it should fix the MPX issue too.

Yes, the MPX test no longer regresses with this updated patch.

Regards,
-Baris

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
\x16º&Öéj×!zÊÞ¶êçן{ßyb²Ö«r\x18\x1dn–­r\x17¬

  reply	other threads:[~2019-10-17 10:21 UTC|newest]

Thread overview: 67+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-06 23:28 [PATCH 00/23] Multi-target support Pedro Alves
2019-09-06 23:28 ` [PATCH 02/23] Don't rely on inferior_ptid in record_full_wait Pedro Alves
2020-07-31  3:17   ` Tom Tromey
2020-08-01 16:14     ` Simon Marchi
2020-08-01 19:32       ` John Baldwin
2020-08-01 20:47         ` Tom Tromey
2020-08-01 20:46       ` Tom Tromey
2020-08-01 22:56         ` Simon Marchi
2020-08-02 17:52           ` Tom Tromey
2020-08-03  0:08             ` Simon Marchi
2019-09-06 23:28 ` [PATCH 13/23] Delete exit_inferior_silent(int pid) Pedro Alves
2019-09-06 23:28 ` [PATCH 15/23] Fix reconnecting to a gdbserver already debugging multiple processes, I Pedro Alves
2019-09-06 23:28 ` [PATCH 10/23] Some get_last_target_status tweaks Pedro Alves
2019-09-09 18:53   ` Tom Tromey
2019-10-17  1:14     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 01/23] Preserve selected thread in all-stop w/ background execution Pedro Alves
2019-10-09  9:36   ` Aktemur, Tankut Baris
2019-10-16 23:54     ` [PATCH v1.1 " Pedro Alves
2019-10-17 10:21       ` Aktemur, Tankut Baris [this message]
2019-09-06 23:28 ` [PATCH 06/23] Don't check target is running in remote_target::mourn_inferior Pedro Alves
2019-09-06 23:28 ` [PATCH 20/23] Revert 'Remove unused struct serial::name field' Pedro Alves
2019-09-06 23:47   ` Christian Biesinger via gdb-patches
2019-09-08 19:30     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 16/23] Fix reconnecting to a gdbserver already debugging multiple processes, II Pedro Alves
2019-09-06 23:28 ` [PATCH 03/23] Make "show remote exec-file" inferior-aware Pedro Alves
2019-09-06 23:28 ` [PATCH 19/23] gdbarch-selftests.c: No longer error out if debugging something Pedro Alves
2019-09-06 23:28 ` [PATCH 09/23] switch inferior/thread before calling target methods Pedro Alves
2019-09-06 23:28 ` [PATCH 18/23] Add multi-target tests Pedro Alves
2019-10-09 16:01   ` Aktemur, Tankut Baris
2019-10-17  0:55     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 11/23] tfile_target::close: trace_fd can't be -1 Pedro Alves
2019-09-06 23:28 ` [PATCH 08/23] Introduce switch_to_inferior_no_thread Pedro Alves
2019-09-09 18:42   ` Tom Tromey
2019-10-17  1:07     ` Pedro Alves
2019-09-06 23:28 ` [PATCH 17/23] Multi-target support Pedro Alves
2019-09-11 17:11   ` Tom Tromey
2019-10-17  1:54     ` Pedro Alves
2019-09-06 23:33 ` [PATCH 23/23] Multi-target: NEWS and user manual Pedro Alves
2019-09-07  6:33   ` Eli Zaretskii
2019-10-17  2:08     ` Pedro Alves
2019-10-17  7:55       ` Eli Zaretskii
2019-10-17  2:42     ` Pedro Alves
2019-10-17  8:14       ` Eli Zaretskii
2019-10-17 15:31         ` Pedro Alves
2019-09-06 23:34 ` [PATCH 04/23] exceptions.c:print_flush: Remove obsolete check Pedro Alves
2019-09-09 18:07   ` Tom Tromey
2019-09-06 23:35 ` [PATCH 05/23] Make target_ops::has_execution take an 'inferior *' instead of a ptid_t Pedro Alves
2019-09-09 18:12   ` Tom Tromey
2019-09-06 23:36 ` [PATCH 14/23] Tweak handling of remote errors in response to resumption packet Pedro Alves
2019-10-09 13:35   ` Aktemur, Tankut Baris
2019-10-17  0:54     ` [PATCH 14.5/23] Avoid another inferior_ptid reference in gdb/remote.c (Re: [PATCH 14/23] Tweak handling of remote errors in response to resumption packet) Pedro Alves
2019-09-06 23:36 ` [PATCH 12/23] Use all_non_exited_inferiors in infrun.c Pedro Alves
2019-09-06 23:36 ` [PATCH 07/23] Delete unnecessary code from kill_command Pedro Alves
2019-10-01 10:19   ` Aktemur, Tankut Baris
2019-10-01 13:28     ` Aktemur, Tankut Baris
2019-09-06 23:37 ` [PATCH 22/23] Require always-non-stop for multi-target resumptions Pedro Alves
2019-09-06 23:37 ` [PATCH 21/23] Add "info connections" command, "info inferiors" connection number/string Pedro Alves
2019-09-09 20:18   ` Tom Tromey
2019-10-17  2:21     ` Pedro Alves
2019-10-17 14:23       ` Tom Tromey
2019-09-07 11:19 ` [PATCH 00/23] Multi-target support Philippe Waroquiers
2019-09-08 20:06   ` Pedro Alves
2019-09-08 20:50     ` Philippe Waroquiers
2019-10-16 19:08       ` Pedro Alves
2019-10-16 19:14       ` [PATCH] Avoid inferior_ptid reference in gdb/remote.c (Re: [PATCH 00/23] Multi-target support) Pedro Alves
2019-09-09 19:09 ` [PATCH 00/23] Multi-target support Tom Tromey
2019-09-09 20:22 ` Tom Tromey

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=BYAPR11MB30305D5C8FBB36A09AE0480CC46D0@BYAPR11MB3030.namprd11.prod.outlook.com \
    --to=tankut.baris.aktemur@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