public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads
@ 2022-04-19 22:47 Lancelot SIX
  2022-04-22 15:17 ` Pedro Alves
  2022-04-22 16:00 ` [PATCH v2] gdb/infrun: " Lancelot SIX
  0 siblings, 2 replies; 7+ messages in thread
From: Lancelot SIX @ 2022-04-19 22:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: lsix, Lancelot SIX

While working in gdb/infrun.c:restart_threads, I was wondering what are
the preconditions to call the function.  It seems to me that
!step_over_info_valid_p should be a precondition (i.e. if we are doing
an inline step over breakpoint, we do not want to resume non stepping
threads as one of them might miss the breakpoint which is temporally
disabled).

To convince myself that this is true, I have added an assertion to
enforce this, and got one regression in the testsuite:

    FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (GDB internal error)

This call to restart_threads originates from handle_vfork_done which
does not check if a step over is active when restarting other threads:

    if (target_is_non_stop_p ())
      {
        scoped_restore_current_thread restore_thread;

        insert_breakpoints ();
        restart_threads (event_thread, event_thread->inf);
        start_step_over ();
      }

In this patch, I propose to:
- Call start_step_over before restart_threads.  If a step over is already
  in progress (as it is the case in the failing testcase),
  start_step_over return immediately, and there is no point in restarting
  all threads just to stop them right away for a step over breakpoint.
- Only call restart_threads if no step over is in progress at this
  point.

In this patch, I also propose to keep the assertion in restart_threads
to help enforce this precondition, and state it explicitly.

I have also checked all other places which call restart_threads, and
they all seem to check that there is no step over currently active
before doing the call.

As for infrun-related things, I am never completely sure I did not miss
something.  So as usual, all feedback and thoughts are very welcome.

Tested on x86_64-linux-gnu.

Change-Id: If5f5f98ec4cf9aaeaabb5e3aa88ae6ffd70d4f37
---
 gdb/infrun.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index c311240b78c..6564a177e0e 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -101,6 +101,8 @@ static void restart_threads (struct thread_info *event_thread,
 
 static bool start_step_over (void);
 
+static bool step_over_info_valid_p (void);
+
 /* Asynchronous signal handler registered as event loop source for
    when we have pending events ready to be passed to the core.  */
 static struct async_event_handler *infrun_async_inferior_event_token;
@@ -1088,8 +1090,10 @@ handle_vfork_done (thread_info *event_thread)
       scoped_restore_current_thread restore_thread;
 
       insert_breakpoints ();
-      restart_threads (event_thread, event_thread->inf);
       start_step_over ();
+
+      if (!step_over_info_valid_p ())
+	restart_threads (event_thread, event_thread->inf);
     }
 }
 
@@ -5866,6 +5870,7 @@ handle_inferior_event (struct execution_control_state *ecs)
 static void
 restart_threads (struct thread_info *event_thread, inferior *inf)
 {
+  gdb_assert (!step_over_info_valid_p ());
   INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
 				 event_thread->ptid.to_string ().c_str (),
 				 inf != nullptr ? inf->num : -1);

base-commit: 6ea673e2d643b7b2283aa73d35b02dfc9aa7115f
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads
  2022-04-19 22:47 [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads Lancelot SIX
@ 2022-04-22 15:17 ` Pedro Alves
  2022-04-22 15:18   ` Pedro Alves
  2022-04-22 15:50   ` Lancelot SIX
  2022-04-22 16:00 ` [PATCH v2] gdb/infrun: " Lancelot SIX
  1 sibling, 2 replies; 7+ messages in thread
From: Pedro Alves @ 2022-04-22 15:17 UTC (permalink / raw)
  To: Lancelot SIX, gdb-patches; +Cc: lsix

On 2022-04-19 23:47, Lancelot SIX via Gdb-patches wrote:
> While working in gdb/infrun.c:restart_threads, I was wondering what are
> the preconditions to call the function.  It seems to me that
> !step_over_info_valid_p should be a precondition (i.e. if we are doing
> an inline step over breakpoint, we do not want to resume non stepping
> threads as one of them might miss the breakpoint which is temporally
> disabled).
> 
> To convince myself that this is true, I have added an assertion to
> enforce this, and got one regression in the testsuite:
> 
>     FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (GDB internal error)
> 
> This call to restart_threads originates from handle_vfork_done which
> does not check if a step over is active when restarting other threads:
> 
>     if (target_is_non_stop_p ())
>       {
>         scoped_restore_current_thread restore_thread;
> 
>         insert_breakpoints ();
>         restart_threads (event_thread, event_thread->inf);
>         start_step_over ();
>       }
> 
> In this patch, I propose to:
> - Call start_step_over before restart_threads.  If a step over is already
>   in progress (as it is the case in the failing testcase),
>   start_step_over return immediately, and there is no point in restarting
>   all threads just to stop them right away for a step over breakpoint.
> - Only call restart_threads if no step over is in progress at this
>   point.
> 
> In this patch, I also propose to keep the assertion in restart_threads
> to help enforce this precondition, and state it explicitly.
> 
> I have also checked all other places which call restart_threads, and
> they all seem to check that there is no step over currently active
> before doing the call.
> 
> As for infrun-related things, I am never completely sure I did not miss
> something.  So as usual, all feedback and thoughts are very welcome.
> 
> Tested on x86_64-linux-gnu.
> 
> Change-Id: If5f5f98ec4cf9aaeaabb5e3aa88ae6ffd70d4f37
> ---
>  gdb/infrun.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/gdb/infrun.c b/gdb/infrun.c
> index c311240b78c..6564a177e0e 100644
> --- a/gdb/infrun.c
> +++ b/gdb/infrun.c
> @@ -101,6 +101,8 @@ static void restart_threads (struct thread_info *event_thread,
>  
>  static bool start_step_over (void);
>  
> +static bool step_over_info_valid_p (void);
> +
>  /* Asynchronous signal handler registered as event loop source for
>     when we have pending events ready to be passed to the core.  */
>  static struct async_event_handler *infrun_async_inferior_event_token;
> @@ -1088,8 +1090,10 @@ handle_vfork_done (thread_info *event_thread)
>        scoped_restore_current_thread restore_thread;
>  
>        insert_breakpoints ();
> -      restart_threads (event_thread, event_thread->inf);
>        start_step_over ();
> +
> +      if (!step_over_info_valid_p ())
> +	restart_threads (event_thread, event_thread->inf);

This looks fine.

>      }
>  }
>  
> @@ -5866,6 +5870,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>  static void
>  restart_threads (struct thread_info *event_thread, inferior *inf)
>  {
> +  gdb_assert (!step_over_info_valid_p ());
>    INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
>  				 event_thread->ptid.to_string ().c_str (),
>  				 inf != nullptr ? inf->num : -1);
> 

Nit: this looks a bit too crammed to my eyes -- I mean, I would expect either the assertion
to be below the INFRUN_SCOPED_DEBUG_START_END (my preference, as it'll probably
print useful context to debug an assertion failure) with an empty line in between,
or at least put an empty line between the assert and the INFRUN_SCOPED_DEBUG_START_END.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads
  2022-04-22 15:17 ` Pedro Alves
@ 2022-04-22 15:18   ` Pedro Alves
  2022-04-22 15:50   ` Lancelot SIX
  1 sibling, 0 replies; 7+ messages in thread
From: Pedro Alves @ 2022-04-22 15:18 UTC (permalink / raw)
  To: Lancelot SIX, gdb-patches; +Cc: lsix

Also, infrum -> infrun.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads
  2022-04-22 15:17 ` Pedro Alves
  2022-04-22 15:18   ` Pedro Alves
@ 2022-04-22 15:50   ` Lancelot SIX
  1 sibling, 0 replies; 7+ messages in thread
From: Lancelot SIX @ 2022-04-22 15:50 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches; +Cc: lsix


>> @@ -5866,6 +5870,7 @@ handle_inferior_event (struct execution_control_state *ecs)
>>   static void
>>   restart_threads (struct thread_info *event_thread, inferior *inf)
>>   {
>> +  gdb_assert (!step_over_info_valid_p ());
>>     INFRUN_SCOPED_DEBUG_START_END ("event_thread=%s, inf=%d",
>>                                 event_thread->ptid.to_string ().c_str (),
>>                                 inf != nullptr ? inf->num : -1);
>>
> 
> Nit: this looks a bit too crammed to my eyes -- I mean, I would expect either the assertion
> to be below the INFRUN_SCOPED_DEBUG_START_END (my preference, as it'll probably
> print useful context to debug an assertion failure) with an empty line in between,
> or at least put an empty line between the assert and the INFRUN_SCOPED_DEBUG_START_END.

Thanks,

I changed this locally (i.e. the gdb_assert goes after the 
INFRUN_SCOPED_DEBUG_START_END call, with one empty line in between), as 
well as fixed the commit title.

I'll send the V2 shortly.

Best,
Lancelot.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2] gdb/infrun: assert !step_over_info_valid_p in restart_threads
  2022-04-19 22:47 [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads Lancelot SIX
  2022-04-22 15:17 ` Pedro Alves
@ 2022-04-22 16:00 ` Lancelot SIX
  2022-04-22 16:54   ` Pedro Alves
  1 sibling, 1 reply; 7+ messages in thread
From: Lancelot SIX @ 2022-04-22 16:00 UTC (permalink / raw)
  To: gdb-patches; +Cc: Lancelot SIX

Hi,

This is a V2 for https://sourceware.org/pipermail/gdb-patches/2022-April/188062.html

Since V1:

- Fixed typo in the subject
- Placed the gdb_assert in restart_threads after INFRUN_SCOPED_DEBUG_START_END

Best,
Lancelot

---

While working in gdb/infrun.c:restart_threads, I was wondering what are
the preconditions to call the function.  It seems to me that
!step_over_info_valid_p should be a precondition (i.e. if we are doing
an inline step over breakpoint, we do not want to resume non stepping
threads as one of them might miss the breakpoint which is temporally
disabled).

To convince myself that this is true, I have added an assertion to
enforce this, and got one regression in the testsuite:

    FAIL: gdb.base/step-over-syscall.exp: vfork: displaced=off: single step over vfork (GDB internal error)

This call to restart_threads originates from handle_vfork_done which
does not check if a step over is active when restarting other threads:

    if (target_is_non_stop_p ())
      {
        scoped_restore_current_thread restore_thread;

        insert_breakpoints ();
        restart_threads (event_thread, event_thread->inf);
        start_step_over ();
      }

In this patch, I propose to:
- Call start_step_over before restart_threads.  If a step over is already
  in progress (as it is the case in the failing testcase),
  start_step_over return immediately, and there is no point in restarting
  all threads just to stop them right away for a step over breakpoint.
- Only call restart_threads if no step over is in progress at this
  point.

In this patch, I also propose to keep the assertion in restart_threads
to help enforce this precondition, and state it explicitly.

I have also checked all other places which call restart_threads, and
they all seem to check that there is no step over currently active
before doing the call.

As for infrun-related things, I am never completely sure I did not miss
something.  So as usual, all feedback and thoughts are very welcome.

Tested on x86_64-linux-gnu.

Change-Id: If5f5f98ec4cf9aaeaabb5e3aa88ae6ffd70d4f37
---
 gdb/infrun.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index c311240b78c..fa2adb6d2a0 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -101,6 +101,8 @@ static void restart_threads (struct thread_info *event_thread,
 
 static bool start_step_over (void);
 
+static bool step_over_info_valid_p (void);
+
 /* Asynchronous signal handler registered as event loop source for
    when we have pending events ready to be passed to the core.  */
 static struct async_event_handler *infrun_async_inferior_event_token;
@@ -1088,8 +1090,10 @@ handle_vfork_done (thread_info *event_thread)
       scoped_restore_current_thread restore_thread;
 
       insert_breakpoints ();
-      restart_threads (event_thread, event_thread->inf);
       start_step_over ();
+
+      if (!step_over_info_valid_p ())
+	restart_threads (event_thread, event_thread->inf);
     }
 }
 
@@ -5870,6 +5874,8 @@ restart_threads (struct thread_info *event_thread, inferior *inf)
 				 event_thread->ptid.to_string ().c_str (),
 				 inf != nullptr ? inf->num : -1);
 
+  gdb_assert (!step_over_info_valid_p ());
+
   /* In case the instruction just stepped spawned a new thread.  */
   update_thread_list ();
 

base-commit: 9d748d023d2df565e04974b5bb45618c24b30c15
-- 
2.25.1


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] gdb/infrun: assert !step_over_info_valid_p in restart_threads
  2022-04-22 16:00 ` [PATCH v2] gdb/infrun: " Lancelot SIX
@ 2022-04-22 16:54   ` Pedro Alves
  2022-04-25  8:32     ` Lancelot SIX
  0 siblings, 1 reply; 7+ messages in thread
From: Pedro Alves @ 2022-04-22 16:54 UTC (permalink / raw)
  To: Lancelot SIX, gdb-patches

This is OK.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2] gdb/infrun: assert !step_over_info_valid_p in restart_threads
  2022-04-22 16:54   ` Pedro Alves
@ 2022-04-25  8:32     ` Lancelot SIX
  0 siblings, 0 replies; 7+ messages in thread
From: Lancelot SIX @ 2022-04-25  8:32 UTC (permalink / raw)
  To: Pedro Alves, gdb-patches

Thanks.

I just pushed this patch.

Best,
Lancelot.

On 22/04/2022 17:54, Pedro Alves wrote:
> [CAUTION: External Email]
> 
> This is OK.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-04-25  8:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-19 22:47 [PATCH] gdb/infrum: assert !step_over_info_valid_p in restart_threads Lancelot SIX
2022-04-22 15:17 ` Pedro Alves
2022-04-22 15:18   ` Pedro Alves
2022-04-22 15:50   ` Lancelot SIX
2022-04-22 16:00 ` [PATCH v2] gdb/infrun: " Lancelot SIX
2022-04-22 16:54   ` Pedro Alves
2022-04-25  8:32     ` Lancelot SIX

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).