From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id GRm1I8iz42oHLA8AWB0awg (envelope-from ) for ; Thu, 29 Oct 2026 16:59:52 -0400 Authentication-Results: simark.ca; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LB3cfw2f; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 87F00378002; Thu, 29 Oct 2026 16:59:52 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=ARC_SIGNED,ARC_VALID,BAYES_00, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED,RCVD_IN_SBL_CSS,RCVD_IN_VALIDITY_CERTIFIED_BLOCKED, RCVD_IN_VALIDITY_RPBL_BLOCKED,RCVD_IN_VALIDITY_SAFE_BLOCKED autolearn=no autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [38.145.34.32]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by simark.ca (Postfix) with ESMTPS id 5834F1E007 for ; Thu, 29 Oct 2026 16:59:51 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 850C74BAE7C3 for ; Thu, 29 Oct 2026 20:59:50 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 850C74BAE7C3 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LB3cfw2f Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTP id 92DDB4BAE7C1 for ; Thu, 29 Oct 2026 20:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92DDB4BAE7C1 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92DDB4BAE7C1 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793307510; cv=none; b=IfDBY4+LPBk1RhN4ijCiY2FJ7d4TJfgBD3XT2oxSi9Oxnmu7Tz1Yq79dzd305GLIxJFq+RRoVmbcKAhkQX/QISKVA5jYSBLDVMv6nTmZnw42ynk9/PQrUFPCW2/JFHcrCeqx9oVYw+uweLq9K5dsFz9Qpa+d7bBbSTAKWHdQQLI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793307510; c=relaxed/simple; bh=pwjlRYmx0Tj53v8IzHNHLwG1yneZ9zCqcvxPsTqgDv4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=xnhyf8e4yDfV8tWChvz3woeOH24Xim1+ARQUzJJQRbTZBbz53tPnu9vOvV107xyEhIj9GXly+aCUZhXvH993O2PJP6RKixcndEm8L6vulYkdvATaroDEkt2mAXWon2KWisBb1zWgDY/9uSkuj/ocH0NdGuoq9gCMBg9RM9pZyZQ= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=LB3cfw2f DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92DDB4BAE7C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793307510; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ATLPUU2I/OFxyZnopRNMDQCB7WErys+5qKv5iQ23xZo=; b=LB3cfw2fmnq0SXxzc3cIJt+Qo/+ZWvdaFp9P7Gze5lNjyCM3BPFUaH1GFNygzB9+aa8+CZ dcwZa3T3jQgeGnHNSdXdkFNcpmjQ+kRLHLgS5/fTrRJOChSOXvCsSNnufxY669CUpLP8Id NCmyIiUuUkOSNPyr19h8NBa9w5mu1p4= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-388-onoCSPnUPqKakQUOmnW4VQ-1; Thu, 29 Oct 2026 16:58:27 -0400 X-MC-Unique: onoCSPnUPqKakQUOmnW4VQ-1 X-Mimecast-MFC-AGG-ID: onoCSPnUPqKakQUOmnW4VQ_1793307506 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 322E31955DBE for ; Thu, 29 Oct 2026 20:58:26 +0000 (UTC) Received: from glarsen-thinkpadp16vgen1.rmtbr.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 392925AA; Thu, 29 Oct 2026 20:58:24 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH 3/7] gdb/record: Make GDB automatically switch threads when replaying Date: Thu, 29 Oct 2026 17:57:39 -0300 Message-ID: <20261029205743.1917668-4-guinevere@redhat.com> In-Reply-To: <20261029205743.1917668-1-guinevere@redhat.com> References: <20261029205743.1917668-1-guinevere@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: zjCtaCdrWyHltihqBasVxUtnrt3bHKsO85RGKByWivo_1793307506 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gdb-patches-bounces~public-inbox=simark.ca@sourceware.org The next step in supporting multi-threaded inferiors with record-full is being able to switch threads automatically while the inferior replays. To do so, we no longer tell the instruction which regcache needs to be changed, instead the instruction will fetch it from the associated thread. For convenience, the exec_insn method also returns the thread that was altered by it. record-full's wait function uses that to compare to the thread where the execution command was issued, and if they're not the same, it won't count the execution of a step/next as completed (unless the inferior would be stopped by something else, such as a breakpoint). If the inferior is stopped by another event, the altered thread is set as the current thread. This commit just manages the general case of thread execution. Recording through thread creation or destruction is not supported yet, those are left for future commits, to simplify future bisecting as much as possible. This commit also updates the tests to check the replayability function. --- gdb/record-full.c | 60 +++++++++++++------ .../gdb.reverse/pthreads-precsave.exp | 18 +++++- .../gdb.reverse/pthreads-reverse.exp | 12 ++++ 3 files changed, 70 insertions(+), 20 deletions(-) diff --git a/gdb/record-full.c b/gdb/record-full.c index 9b84be2e11a..146447adfbb 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -439,9 +439,11 @@ struct record_full_instruction /* The thread that executed this instruction. */ thread_info *thread = nullptr; - /* Execute the full instruction. As a side effect, set - record_full_stop_reason. */ - void exec_insn (regcache *regcache); + /* Execute the full instruction. As side effects, may set + record_full_stop_reason (if a watchpoint is triggered by + executing this instruction). Returns the PTID of the + thread that it just modified. */ + thread_info *exec_insn (); /* Create a full recorded instruction from a bfd. */ static void from_bfd (bfd *cbfd, asection* osec, int *bfd_offset, @@ -919,14 +921,16 @@ static enum target_stop_reason record_full_stop_reason /* Execute one entry in the log by executing all the effects. */ -void record_full_instruction::exec_insn (regcache *regcache) +thread_info *record_full_instruction::exec_insn () { - /* Assert that the regcache we were given belongs to the correct thread. */ - gdb_assert (thread->ptid == regcache->ptid ()); + regcache *regcache = get_thread_regcache (thread); + pc.execute (regcache); for (auto &entry : effects) if (entry.execute (regcache)) record_full_stop_reason = TARGET_STOPPED_BY_WATCHPOINT; + + return thread; } static void record_full_restore (struct bfd &cbfd); @@ -1332,7 +1336,10 @@ record_full_wait_1 (struct target_ops *ops, { switch_to_thread (current_inferior ()->process_target (), record_full_resume_ptid); - regcache *regcache = get_thread_regcache (inferior_thread ()); + thread_info *current_thread = inferior_thread (); + /* Last thread that was executed, in case we need to switch to it. */ + thread_info * last_thread = current_thread; + regcache *regcache = get_thread_regcache (current_thread); struct gdbarch *gdbarch = regcache->arch (); const address_space *aspace = current_inferior ()->aspace.get (); int continue_flag = 1; @@ -1377,15 +1384,33 @@ record_full_wait_1 (struct target_ops *ops, /* Check for beginning and end of log. */ if (execution_direction == EXEC_REVERSE && record_full_next_insn < 0) - break; + { + if (last_thread != current_thread) + { + switch_to_thread (last_thread); + current_thread->set_state (THREAD_STOPPED); + current_thread->set_internal_state (THREAD_INT_STOPPED); + } + break; + } else if (execution_direction != EXEC_REVERSE - && record_full_next_insn == record_full_log.size ()) - break; + && record_full_next_insn == record_full_log.size ()) + { + if (last_thread != current_thread) + { + switch_to_thread (last_thread); + current_thread->set_state (THREAD_STOPPED); + current_thread->set_internal_state (THREAD_INT_STOPPED); + } + break; + } - record_full_log[record_full_next_insn].exec_insn (regcache); + last_thread + = record_full_log[record_full_next_insn].exec_insn (); - /* step */ - if (record_full_resume_step) + /* We only count a single step as completed if we stepped the + same thread that we started with. */ + if (record_full_resume_step && current_thread == last_thread) { if (record_debug > 1) gdb_printf (gdb_stdlog, @@ -2806,7 +2831,7 @@ record_full_base_target::save_record (const char *recfilename) /* Reverse execute to the begin of record list. */ for (int i = record_full_next_insn - 1; i >= 0; i--) - record_full_log[i].exec_insn (regcache); + record_full_log[i].exec_insn (); /* Create a table relating this session's global ID and the PTID of the thread, for reading the corefile in the future. */ @@ -2898,7 +2923,7 @@ record_full_base_target::save_record (const char *recfilename) record_full_log[i].to_bfd (obfd, osec, &bfd_offset, gdbarch); /* Execute entry. */ if (i < record_full_next_insn) - record_full_log[i].exec_insn (regcache); + record_full_log[i].exec_insn (); } unlink_file.keep (); @@ -2918,17 +2943,16 @@ record_full_goto_insn (size_t target_insn, { scoped_restore restore_operation_disable = record_full_gdb_operation_disable_set (); - regcache *regcache = get_thread_regcache (inferior_thread ()); /* Assume everything is valid: we will hit the entry, and we will not hit the end of the recording. */ if (dir == EXEC_REVERSE) for (int i = record_full_next_insn; i > target_insn; i--) - record_full_log[i - 1].exec_insn (regcache); + record_full_log[i - 1].exec_insn (); else for (int i = record_full_next_insn; i < target_insn; i++) - record_full_log[i].exec_insn (regcache); + record_full_log[i].exec_insn (); record_full_next_insn = target_insn; } diff --git a/gdb/testsuite/gdb.reverse/pthreads-precsave.exp b/gdb/testsuite/gdb.reverse/pthreads-precsave.exp index 53702ed26fa..c9f69f88a20 100644 --- a/gdb/testsuite/gdb.reverse/pthreads-precsave.exp +++ b/gdb/testsuite/gdb.reverse/pthreads-precsave.exp @@ -53,8 +53,9 @@ gdb_test "next" "y = 2.*" "Record thread 2" gdb_test "thread 1" ".Switching to thread 1.*" gdb_test "next" "end of main.*" "Record thread 1" -gdb_test "reverse-next" ".*" -gdb_test "thread 2" ".*" +gdb_test "thread 2" ".Switching to thread 2.*" \ + "Returning to thread 2" +gdb_test "next" "return .void.*" "record thread 2 some more" gdb_test "record save $precsave" \ "Saved core file $precsave with execution log\." \ @@ -91,3 +92,16 @@ if { $main_thread == -1 } { gdb_test "thread" ".*thread is $other_thread.*" \ "identify starting thread" +gdb_test "reverse-next" ".*Backward execution from here not possible." \ + "check start of history" +gdb_test "continue" ".*Following forward execution will be added to history." \ + "move to the end of history" + +gdb_test "thread" ".*thread is $other_thread.*" \ + "identify last thread" +gdb_test "thread $main_thread" ".*end of main.*" \ + "Switch to main thread" +gdb_test "reverse-next" ".*TAG: PTHREAD SUCCESSFUL.*" \ + "Return one line in main" + +gdb_test "thread $other_thread" "y = 2.*" "check position of other thread" diff --git a/gdb/testsuite/gdb.reverse/pthreads-reverse.exp b/gdb/testsuite/gdb.reverse/pthreads-reverse.exp index b85bd572672..1ef1162acd1 100644 --- a/gdb/testsuite/gdb.reverse/pthreads-reverse.exp +++ b/gdb/testsuite/gdb.reverse/pthreads-reverse.exp @@ -81,3 +81,15 @@ gdb_test "next" "end of main.*" "Record thread 1" with_test_prefix "thread 1" { check_recorded_thread true } + +# Testing replaying through thread switches. +gdb_test "thread 2" ".Switching to thread 2.*" "Switching for testing purposes" +gdb_test "reverse-step" "x = 1.*" "step backwards through a thread change" +gdb_test "continue" ".*thread 1.*" "continue forwards through one thread change" + +# Testing additional thread switches. +gdb_test "thread 2" ".Switching to thread 2.*" \ + "Record further on thread 2" +gdb_test "next" "return .void ..*" "record some more on thread 2" +gdb_test "reverse-continue" "x = 1.*" "continue backwards through history thread change" +gdb_test "continue" "return .void .*" "continue forwards through multiple thread change" -- 2.56.0