Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: "aleksandar.paunovic via Gdb-patches" <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [PATCH 2/2] gdb: Improve the resuming of the stepped thread
Date: Mon,  7 Jun 2021 10:42:03 +0200	[thread overview]
Message-ID: <1623055323-3331-3-git-send-email-aleksandar.paunovic@intel.com> (raw)
In-Reply-To: <1623055323-3331-1-git-send-email-aleksandar.paunovic@intel.com>

From: Aleksandar Paunovic <aleksandar.paunovic@intel.com>

Stepped thread should not be resumed (again) if the next stopping point
(next stopping PC) cannot be determined.  Do not resume the stepped thread
in this case.  Resuming would lead to an inconsistent state where the
stepped thread would be running forever and GDB would never get to
breakpoints of the other threads.  */

gdb/ChangeLog:
2021-04-30  Aleksandar Paunovic  <aleksandar.paunovic@intel.com>

        * infrun.c (keep_going_stepped_thread): Do not resume an
	already executing thread.

gdb/testsuite/ChangeLog:
2021-04-30  Aleksandar Paunovic  <aleksandar.paunovic@intel.com>

	* gdb.base/breakpoint-running-inferior.exp: Add a start_step
	function check.

2021-06-07 Aleksandar Paunovic <aleksandar.paunovic@intel.com>
---
 gdb/infrun.c                                      | 15 ++++++++++++++-
 .../gdb.base/breakpoint-running-inferior.exp      |  5 +++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gdb/infrun.c b/gdb/infrun.c
index 78da1f0e72..459a679ee6 100644
--- a/gdb/infrun.c
+++ b/gdb/infrun.c
@@ -7529,7 +7529,7 @@ restart_after_all_stop_detach (process_stratum_target *proc_target)
 
 /* Set a previously stepped thread back to stepping.  Returns true on
    success, false if the resume is not possible (e.g., the thread
-   vanished).  */
+   vanished, or the thread breakpoint position cannot be determined).  */
 
 static bool
 keep_going_stepped_thread (struct thread_info *tp)
@@ -7566,6 +7566,19 @@ keep_going_stepped_thread (struct thread_info *tp)
       delete_thread (tp);
       return false;
     }
+  /* Step start function determines the location of the next stopping
+     point (next PC where the stepped thread should stop).  In case that
+     this position cannot be determined the step_start_function will not
+     be set.  Do not resume the stepped thread in this case.  Resuming
+     would lead to an inconsistent state where the stepped thread would be
+     running forever and GDB would never get to breakpoints of the other
+     threads.  */
+  if (tp->control.step_start_function == nullptr)
+    {
+      infrun_debug_printf ("not resuming previously stepped thread, it is "
+			   "already executing");
+      return 0;
+    }
 
   infrun_debug_printf ("resuming previously stepped thread");
 
diff --git a/gdb/testsuite/gdb.base/breakpoint-running-inferior.exp b/gdb/testsuite/gdb.base/breakpoint-running-inferior.exp
index bb0406bc65..b95f2ec012 100644
--- a/gdb/testsuite/gdb.base/breakpoint-running-inferior.exp
+++ b/gdb/testsuite/gdb.base/breakpoint-running-inferior.exp
@@ -74,10 +74,15 @@ gdb_test "next" ".*Thread 2.*hit Breakpoint.*" "next while in inferior 1"
 
 # We should be able to normally switch to thread 1.1.
 # In case of a bad GDB flow the GDB was losing the thread.
+# The thread should also not be in a "running" state because it is
+# stopped.
 gdb_test_multiple "thread 1.1" "Switching to thread 1.1" {
     -re "\\\[Switching to thread 1.1 \\(Thread .*\\)\\\]" {
         pass $gdb_test_name
     }
+    -re "\\\[Switching to thread 1.1.*\\(running\\)" {
+        fail $gdb_test_name
+    }
     -re ".*Thread ID 1.1 has terminated.*" {
         fail $gdb_test_name
     }
-- 
2.17.1


  parent reply	other threads:[~2021-06-07  8:44 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-07  8:42 [PATCH 0/2] Fix next command in the running inferior aleksandar.paunovic via Gdb-patches
2021-06-07  8:42 ` [PATCH 1/2] gdb: Fix deleted thread when issuing next command aleksandar.paunovic via Gdb-patches
2021-06-07  8:42 ` aleksandar.paunovic via Gdb-patches [this message]
2021-06-07 13:48   ` [PATCH 2/2] gdb: Improve the resuming of the stepped thread Andrew Burgess
2021-06-14 10:47     ` Paunovic, Aleksandar via Gdb-patches
2022-05-23 18:00 [PATCH 0/2] Some patches for multi inferior case Eduard Sargsyan via Gdb-patches
2022-05-23 18:00 ` [PATCH 2/2] gdb: Improve the resuming of the stepped thread Eduard Sargsyan via Gdb-patches
2022-08-25 23:20   ` Thiago Jung Bauermann via Gdb-patches

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=1623055323-3331-3-git-send-email-aleksandar.paunovic@intel.com \
    --to=gdb-patches@sourceware.org \
    --cc=aleksandar.paunovic@intel.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