From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id ofnSFZez42oHLA8AWB0awg (envelope-from ) for ; Thu, 29 Oct 2026 16:59:03 -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=ZHUptNJl; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 535A81E007; Thu, 29 Oct 2026 16:59:03 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-3.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 autolearn=ham autolearn_force=no version=4.0.1 Received: from vm01.sourceware.org (vm01.sourceware.org [IPv6:2620:52:6:3111::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 7D0DD1E007 for ; Thu, 29 Oct 2026 16:59:02 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F040D4BA900D for ; Thu, 29 Oct 2026 20:59:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F040D4BA900D 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=ZHUptNJl Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id BBBFA4BA798A for ; Thu, 29 Oct 2026 20:58:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BBBFA4BA798A 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 BBBFA4BA798A Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793307504; cv=none; b=Y36u8SCRtVmSHkxDkmD8EtbMNDgmWtNM3wde+KafC50AmAC178Dfx0AlHJO3PIjMqps2sgbJzXQY+k6mSA8QyKS/H39y3yTQnV6bAvYRm5wM2mnW6/AjLw+xqDCsIm0wOauBTS9jnrlN+VkI3lrJGCqMvEVaiHgZV4kJDlTp13c= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793307504; c=relaxed/simple; bh=UsUiRtxw3XRFlp+ITJFJgT81zBd1yqiLpAjFMNounH4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=STNXqdW9PZ258JcQPVL+23Hgs1iCd23NNC+wglkgCJ1MrJONEqixpXBNsfX6F/TdyDC+8gp5093DfzkILB8Zycys/fjcxHWpVwdg7fd7QmVhwZExrdF0nh93XGvy85Ze9jwgua16BL0CCapIVmzKXe577X3b2urDsj8NqGaKbJM= 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=ZHUptNJl DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BBBFA4BA798A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793307504; 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=KRqueO7Rrlmds3j8W/gxzF/pbTsZ0bN/r0YcBey7Qc0=; b=ZHUptNJlIEjln0WWz4WSKaI+iza3bIE6uqtWTalusMftYrx1mIF8EKR9UfRlDa3LA1e8L9 7CtsgdzARSDe5CkcSMoupO3ngq0N5DvbGo63hTglSzwvJrJmsiznbIjugZr3pOKhvjcSfY M5zKN3n57TI9M/H7EqpCGl1vLx9EVVU= Received: from mx-prod-mc-03.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-77-5mydiE8GM_K6f_pIlE_AUA-1; Thu, 29 Oct 2026 16:58:23 -0400 X-MC-Unique: 5mydiE8GM_K6f_pIlE_AUA-1 X-Mimecast-MFC-AGG-ID: 5mydiE8GM_K6f_pIlE_AUA_1793307502 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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1B9FC195604B for ; Thu, 29 Oct 2026 20:58:22 +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 1E7EC7C6; Thu, 29 Oct 2026 20:58:20 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH 1/7] gdb/record-full: Add thread pointer to recorded instructions Date: Thu, 29 Oct 2026 17:57:37 -0300 Message-ID: <20261029205743.1917668-2-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: xyI7c0jpGMIPioPLwTsXMlDVr0Pj-Ff1XWuP8HZ9xSg_1793307502 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 To be able to properly support multi-threaded inferiors with the record-full subsystem, we need some indication of which thread executed a given instruction, so that we update the correct register cache. This commit makes that change, and asserts that the instruction is changing the right regcache, so that (as of yet) unsupported workflows are now loudly unsupported, while making no changes for supported workflows. It also adds a test that does very basic checking that we record the information correctly, and that we're capable of executing backwards while manually switching threads. Support for automatically executing will be added in a future commit in this series, to minimize changes in a single commit. --- gdb/record-full.c | 10 +++ .../gdb.reverse/i386-avx-reverse.exp | 3 +- gdb/testsuite/gdb.reverse/pthreads-reverse.c | 40 +++++++++ .../gdb.reverse/pthreads-reverse.exp | 83 +++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 gdb/testsuite/gdb.reverse/pthreads-reverse.c create mode 100644 gdb/testsuite/gdb.reverse/pthreads-reverse.exp diff --git a/gdb/record-full.c b/gdb/record-full.c index 7b1d64069c7..66df6c85aa3 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -419,6 +419,7 @@ class record_full_entry * sigval: Whether the inferior received a signal while the following instruction was being recorded; * pc: The Program Counter at the start of the instruction; + * thread: The thread that executed the instruction. * effects: A list of record_full_entry structures, each of which describing one effect that the instruction has on the inferior. @@ -434,6 +435,8 @@ struct record_full_instruction std::optional sigval; std::vector effects; record_full_reg_entry pc; + /* The thread that executed this instruction. */ + thread_info *thread = nullptr; /* Execute the full instruction. As a side effect, set record_full_stop_reason. */ @@ -647,6 +650,7 @@ record_full_reset_incomplete () record_full_incomplete_instruction.effects.clear (); record_full_incomplete_instruction.sigval.reset (); record_full_incomplete_instruction.insn_num = 0; + record_full_incomplete_instruction.thread = nullptr; } /* See record-full.h. */ @@ -712,6 +716,7 @@ record_full_save_instruction () { ++record_full_insn_count; record_full_incomplete_instruction.insn_num = record_full_insn_count; + record_full_incomplete_instruction.thread = inferior_thread (); record_full_incomplete_instruction.effects.shrink_to_fit (); record_full_log.push_back (std::move (record_full_incomplete_instruction)); record_full_next_insn++; @@ -914,6 +919,8 @@ static enum target_stop_reason record_full_stop_reason void record_full_instruction::exec_insn (regcache *regcache) { + /* Assert that the regcache we were given belongs to the correct thread. */ + gdb_assert (thread->ptid == regcache->ptid ()); pc.execute (regcache); for (auto &entry : effects) if (entry.execute (regcache)) @@ -2836,6 +2843,9 @@ maintenance_print_record_instruction (const char *args, int from_tty) gdbarch_register_name (arch, to_print->pc.num)); value_print (val, gdb_stdout, opts); gdb_printf ("\n"); + + gdb_printf ("Instruction executed on thread %s\n", + to_print->thread->ptid.to_string ().c_str ()); } INIT_GDB_FILE (record_full) diff --git a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp index a5b0e6612aa..f1012a7a96d 100644 --- a/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp +++ b/gdb/testsuite/gdb.reverse/i386-avx-reverse.exp @@ -461,7 +461,8 @@ if {[record_full_function "vzeroupper"] == true} { "Register ymm13h changed: ${decimal}" \ "Register ymm14h changed: ${decimal}" \ "Register ymm15h changed: 3405707982" \ - "Register rip changed: \[^\r\n\]+" ] \ + "Register rip changed: \[^\r\n\]+" \ + "Instruction executed on thread ${decimal}.${decimal}.0" ] \ "verify vzeroupper recording" gdb_test "record stop" "Process record is stopped.*" \ diff --git a/gdb/testsuite/gdb.reverse/pthreads-reverse.c b/gdb/testsuite/gdb.reverse/pthreads-reverse.c new file mode 100644 index 00000000000..c172d30d810 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/pthreads-reverse.c @@ -0,0 +1,40 @@ +/* This testcase is part of GDB, the GNU debugger. + + Copyright 2026 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include +#include + +static void * +thread_func (void *arg) +{ + int x, y; + x = 1; + y = 2; + return (void *) (uintptr_t) (x + y); +} + +int main () { + pthread_t tid; + + if (pthread_create (&tid, NULL, thread_func, NULL) != 0) + return 1; /* TAG: THREAD CREATION FAIL. */ + + /* Small delay, just to make it easier to read the results. */ + for (int i = 0; i < 10; i++); /* TAG: PTHREAD SUCCESSFUL. */ + + return 0; /* end of main */ +} diff --git a/gdb/testsuite/gdb.reverse/pthreads-reverse.exp b/gdb/testsuite/gdb.reverse/pthreads-reverse.exp new file mode 100644 index 00000000000..b85bd572672 --- /dev/null +++ b/gdb/testsuite/gdb.reverse/pthreads-reverse.exp @@ -0,0 +1,83 @@ +# Copyright 2026 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . */ + +# This file is part of the GDB testsuite. It tests GDB's ability to +# record multithreaded programs. + +require supports_reverse + +standard_testfile + +# Check the thread that a recorded instruction executed in. EQUAL tells +# whether we should expect pid and tid to be the same (which is the +# equivalent of thread 1), or different. The exact numbers aren't important. +proc_with_prefix check_recorded_thread { equal } { + set PID -1 + set TID -1 + set LWP -1 + + gdb_test_multiple "maint print record-instruction" "get recorded PTID" { + -re -wrap "Instruction executed on thread \(${::decimal}\)\.\(${::decimal}\)\.\(${::decimal}\)" { + pass $gdb_test_name + set PID $expect_out(1,string) + set TID $expect_out(2,string) + set LWP $expect_out(3,string) + } + } + + if { $equal } { + gdb_assert { $PID == $TID && $LWP == 0 }; + } else { + gdb_assert { $PID != $TID && $LWP == 0}; + } +} + + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } { + return +} + +runto_main + +gdb_test_no_output "set scheduler-locking on" + +gdb_breakpoint "thread_func" + +# Recording thread creation is not trivial, and so this basic test +# just skips that complex use case for now. +if {[gdb_test "next" "TAG: PTHREAD SUCCESSFUL.*" \ + "next over pthread creation"] != 0} { + untested "Couldn't start pthreads" + return +} + +gdb_test "thread 2" ".Switching to thread 2 .*" +gdb_continue_to_breakpoint "thread_func" ".*thread_func.*" + +if {[supports_process_record]} { + # Activate process record/replay + gdb_test_no_output "record" "turn on process record" +} + +gdb_test "next" "y = 2.*" "Record thread 2" +with_test_prefix "thread 2" { + check_recorded_thread false +} + +gdb_test "thread 1" ".Switching to thread 1.*" +gdb_test "next" "end of main.*" "Record thread 1" +with_test_prefix "thread 1" { + check_recorded_thread true +} -- 2.56.0