From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by sourceware.org (Postfix) with ESMTPS id 1D21A385801E for ; Mon, 23 May 2022 18:01:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 1D21A385801E X-IronPort-AV: E=McAfee;i="6400,9594,10356"; a="359704111" X-IronPort-AV: E=Sophos;i="5.91,246,1647327600"; d="scan'208";a="359704111" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2022 11:01:31 -0700 X-IronPort-AV: E=Sophos;i="5.91,246,1647327600"; d="scan'208";a="744859026" Received: from labpcdell3650-001.iul.intel.com (HELO localhost) ([172.28.50.74]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 23 May 2022 11:01:30 -0700 From: Eduard Sargsyan To: gdb-patches@sourceware.org Cc: Aleksandar Paunovic Subject: [PATCH 2/2] gdb: Improve the resuming of the stepped thread Date: Mon, 23 May 2022 20:00:56 +0200 Message-Id: <20220523180056.1415229-3-eduard.sargsyan@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220523180056.1415229-1-eduard.sargsyan@intel.com> References: <20220523180056.1415229-1-eduard.sargsyan@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 May 2022 18:01:40 -0000 From: Aleksandar Paunovic 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 * infrun.c (keep_going_stepped_thread): Do not resume an already executing thread. gdb/testsuite/ChangeLog: 2021-04-30 Aleksandar Paunovic * gdb.base/breakpoint-running-inferior.exp: Add a start_step function check. Signed-off-by: Aleksandar Paunovic --- 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 d794f135219..2d777610a37 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -7472,7 +7472,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) @@ -7509,6 +7509,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 bb0406bc659..b95f2ec0122 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.25.1