From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from simark.ca by simark.ca with LMTP id AQY6C/2z42oHLA8AWB0awg (envelope-from ) for ; Thu, 29 Oct 2026 17:00:45 -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=hi54H5og; dkim-atps=neutral Received: by simark.ca (Postfix, from userid 112) id 2A373378002; Thu, 29 Oct 2026 17:00:45 -0400 (EDT) X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-25) on simark.ca X-Spam-Level: X-Spam-Status: No, score=-6.4 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 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 DA0FD1E033 for ; Thu, 29 Oct 2026 17:00:42 -0400 (EDT) Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E6CA84BA903D for ; Thu, 29 Oct 2026 21:00:41 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E6CA84BA903D 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=hi54H5og 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 38E354BA902B for ; Thu, 29 Oct 2026 20:58:27 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 38E354BA902B 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 38E354BA902B 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=1793307507; cv=none; b=JY3fcUIQxXGY0Ki1rZtzcNg+uJyLgp9mjbvkBfGDFoDLzoQx83iBQ72RD9wtb8OZlNVA0P9kju5vrxrNSG+XIMhXU5xfP7NkRgMMpoAAMIymgoRXWgyCmSKsJabd+8fHtftUPk7geflXGn+RmmhEcLGP4DRx3zpN6B0Ow69XR54= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1793307507; c=relaxed/simple; bh=+j/NTNAhmn0yH2WsaHjAPC7TT27CTUFi/8Zq8jpZRVc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Z5S5ZmHDnV9dVa8NyBR9SM8DmOCEMNcz2N2mGoZWT6d788PBhhmyWitD75xoNQ8A9fnPkRU/mRNwF/NqATid1890ABhrj/ofJmFrh1yUsXNuplNqph5cBOAwQSOUchCkoqlkV9Njc0l02wdb0WE8d5l3e+Dr3ZsORxbNeC2aTE0= 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=hi54H5og DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 38E354BA902B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793307506; 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=ky1+kkR8uQd2bNSmSs9wRqP1VPW9IWCihLdKAROsFRQ=; b=hi54H5ogBiSghxvCJSyVqexOCVvkgJM3Okmj/7xN88zYV3W9vrKJSNCtthVKw632Kvdd9G EtYekdJJS2SWSzhkgHoQS9pmnEx6FVJfe6HHqtnVf13AuzG1ky4/BVOU1cZhnQ+aOlMHwM DLNyRDqaZ0MgGO1anBcLmAHea/ypGGE= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-654-rb-XmfSRNTSAJrs6kEke8Q-1; Thu, 29 Oct 2026 16:58:25 -0400 X-MC-Unique: rb-XmfSRNTSAJrs6kEke8Q-1 X-Mimecast-MFC-AGG-ID: rb-XmfSRNTSAJrs6kEke8Q_1793307504 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5B41C180059B for ; Thu, 29 Oct 2026 20:58:24 +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 337CE5AA; Thu, 29 Oct 2026 20:58:22 +0000 (UTC) From: Guinevere Larsen To: gdb-patches@sourceware.org Cc: Guinevere Larsen Subject: [PATCH 2/7] gdb/record: add thread ID to the precsave format Date: Thu, 29 Oct 2026 17:57:38 -0300 Message-ID: <20261029205743.1917668-3-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: fbmNLgAKmZ4CZUqgg1lFJFx3oWOudnvQFw5Ds6tGSGI_1793307504 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 With the addition of the thread pointer to the instruction, the `record save' functionality should now also record this information. However, the pointer will not be the same across GDB executions. Even the thread's global ID (GID) won't be the same, but saving the PTID for every single instruction is overkill. To solve this, the new recording format starts with a table that relates GIDs from the current session to PTIDs of the threads, so that we can store the GIDs for each instruction. With this, the process of reading an instruction now includes: Reading the old thread GID, looks in the table for the PTID, then finds the pointer for the thread in this session. This changes the precsave format, so older formats will no longer be supported. It also adds a test to ensure that GDB is able to generate a precsave file with multiple threads, and read it correctly. The test needs to walk back to the start of the log manually because GDB isn't able to automatically switch threads yet, so attempting to "record save" will cause an assert to fail if we're not at the start. This will be fixed in a following commit in the same series Another issue that has to be solved is that, until now, we only needed one detached_regcache to emulate the execution, but now we need multiple regcaches to emulate all the threads. This commit does that by adding an std::map between global_num and the detached_regcache, so that we can easily find it during execution. --- gdb/record-full.c | 212 ++++++++++++++++-- .../gdb.reverse/pthreads-precsave.exp | 93 ++++++++ 2 files changed, 284 insertions(+), 21 deletions(-) create mode 100644 gdb/testsuite/gdb.reverse/pthreads-precsave.exp diff --git a/gdb/record-full.c b/gdb/record-full.c index 66df6c85aa3..9b84be2e11a 100644 --- a/gdb/record-full.c +++ b/gdb/record-full.c @@ -52,6 +52,7 @@ #include #include #include +#include /* This module implements "target record-full", also known as "process record and replay". This target sits on top of a "normal" target @@ -443,7 +444,8 @@ struct record_full_instruction void exec_insn (regcache *regcache); /* Create a full recorded instruction from a bfd. */ - static void from_bfd (bfd *cbfd, asection* osec, int *bfd_offset); + static void from_bfd (bfd *cbfd, asection* osec, int *bfd_offset, + std::map&); /* Save this instruction to a bfd file. */ void to_bfd (gdb_bfd_ref_ptr &obfd, asection *osec, int *bfd_offset, @@ -462,7 +464,7 @@ struct record_full_core_buf_entry }; /* Record buf with core target. */ -static detached_regcache *record_full_core_regbuf = NULL; +static std::map record_full_core_regbuf; static std::vector record_full_core_sections; static struct record_full_core_buf_entry *record_full_core_buf_list = NULL; @@ -946,17 +948,22 @@ record_full_async_inferior_event_handler (gdb_client_data data) static void record_full_core_open_1 (struct bfd &cbfd) { - regcache *regcache = get_thread_regcache (inferior_thread ()); - int regnum = gdbarch_num_regs (regcache->arch ()); + int regnum = gdbarch_num_regs (current_inferior ()->arch ()); int i; - /* Get record_full_core_regbuf. */ - target_fetch_registers (regcache, -1); - record_full_core_regbuf = new detached_regcache (regcache->arch (), false); + for (thread_info &tp: current_inferior ()->threads ()) + { + regcache *regcache = get_thread_regcache (&tp); + /* Get record_full_core_regbuf. */ + target_fetch_registers (regcache, -1); + detached_regcache *regbuf = new detached_regcache (regcache->arch (), + false); - for (i = 0; i < regnum; i ++) - record_full_core_regbuf->raw_supply (i, *regcache); + for (i = 0; i < regnum; i ++) + regbuf->raw_supply (i, *regcache); + record_full_core_regbuf[tp.global_num] = regbuf; + } record_full_core_sections = build_section_table (&cbfd); current_inferior ()->push_target (&record_full_core_ops); @@ -1032,10 +1039,11 @@ record_full_base_target::close () record_full_reset_history (); /* Release record_full_core_regbuf. */ - if (record_full_core_regbuf) + if (!record_full_core_regbuf.empty ()) { - delete record_full_core_regbuf; - record_full_core_regbuf = NULL; + for (auto &iter: record_full_core_regbuf) + delete iter.second; + record_full_core_regbuf.clear (); } /* Release record_full_core_buf_list. */ @@ -2059,16 +2067,19 @@ void record_full_core_target::fetch_registers (struct regcache *regcache, int regno) { + detached_regcache *regbuf + = record_full_core_regbuf[inferior_thread ()->global_num]; + if (regno < 0) { int num = gdbarch_num_regs (regcache->arch ()); int i; for (i = 0; i < num; i ++) - regcache->raw_supply (i, *record_full_core_regbuf); + regcache->raw_supply (i, *regbuf); } else - regcache->raw_supply (regno, *record_full_core_regbuf); + regcache->raw_supply (regno, *regbuf); } /* "prepare_to_store" method for prec over corefile. */ @@ -2084,8 +2095,11 @@ void record_full_core_target::store_registers (struct regcache *regcache, int regno) { + detached_regcache *regbuf + = record_full_core_regbuf[inferior_thread ()->global_num]; + if (record_full_gdb_operation_disable) - record_full_core_regbuf->raw_supply (regno, *regcache); + regbuf->raw_supply (regno, *regcache); else error (_("You can't do that without a process to debug.")); } @@ -2271,6 +2285,37 @@ record_full_core_target::has_execution (inferior *inf) 4 bytes: memory length. 8 bytes: memory address. n bytes: memory value (n = memory length). + + Version 4 (all numbers are in network order). + 4 bytes: Magic number (0x20260728). + NOTE: be sure to change whenever this file format changes! + + Thread table: + 4 bytes: number of entries + for each entry: + 4 bytes: GID (Global ID, GDB's internal representation). + 4 bytes: PID. + 8 bytes: TID. + 8 bytes: LWP. + + Records: + record_full_instruction: + 1 byte: signal. + 4 bytes: number of reg and mem entries for this instruction. + 4 bytes: instruction sequence number. + 4 bytes: PC register ID. + N bytes: PC address of instruction (N == size of PC). + 4 bytes: Thread GID. + Effects: + record_full_reg: + 1 byte: record_type (record_full_reg, see enum record_full_type). + 4 bytes: Register ID. + n bytes: register value (n == actual register size). + record_full_mem: + 1 byte: record_type (record_full_mem, see enum record_full_type). + 4 bytes: memory length. + 8 bytes: memory address. + n bytes: memory value (n = memory length). */ /* bfdcore_read -- read bytes from a core file section. */ @@ -2403,11 +2448,13 @@ record_full_entry::from_bfd (bfd *cbfd, asection *osec, int *bfd_offset) } void -record_full_instruction::from_bfd (bfd *cbfd, asection *osec, int *bfd_offset) +record_full_instruction::from_bfd (bfd *cbfd, asection *osec, int *bfd_offset, + std::map& thread_table) { uint32_t eff_count = 0; uint8_t sigval; uint32_t insn_num; + int32_t gid; /* First read the generic information for an instruction. */ bfdcore_read (cbfd, osec, &sigval, sizeof (uint8_t), bfd_offset); @@ -2415,16 +2462,30 @@ record_full_instruction::from_bfd (bfd *cbfd, asection *osec, int *bfd_offset) bfd_offset); bfdcore_read (cbfd, osec, &insn_num, sizeof (uint32_t), bfd_offset); + bfdcore_read (cbfd, osec, &gid, sizeof(gid), bfd_offset); + gid = netorder32 (gid); record_full_incomplete_instruction.insn_num = netorder32 (insn_num); if (sigval != GDB_SIGNAL_0) record_full_incomplete_instruction.sigval = (gdb_signal) sigval; - record_full_incomplete_instruction.pc - = record_full_reg_entry::from_bfd (cbfd, osec, bfd_offset); + ptid_t ptid = thread_table[gid]; + thread_info *t = current_inferior ()->find_thread (ptid); + gdb_assert (t != nullptr); + record_full_incomplete_instruction.thread = t; eff_count = netorder32 (eff_count); + if (record_debug) + gdb_printf (gdb_stdlog, + "Read instruction number %d, originally in thread %d" + " now thread %d. It has %d effects:\n", + record_full_incomplete_instruction.insn_num, + gid, t->global_num, eff_count); + + record_full_incomplete_instruction.pc + = record_full_reg_entry::from_bfd (cbfd, osec, bfd_offset); + /* This deals with all the side effects. */ while (eff_count > 0) { @@ -2434,6 +2495,27 @@ record_full_instruction::from_bfd (bfd *cbfd, asection *osec, int *bfd_offset) } } +/* Read a ptid_t variable from the core file. */ + +static ptid_t +read_ptid (bfd *cbfd, asection *osec, int *bfd_offset) +{ + /* These guarantee the right read size,independent of ptid_t or + ULONGEST size changes. */ + int32_t pid; + int64_t tid; + int64_t lwp; + + bfdcore_read (cbfd, osec, &pid, sizeof (pid), bfd_offset); + pid = netorder32 (pid); + bfdcore_read (cbfd, osec, &tid, sizeof (tid), bfd_offset); + tid = netorder64 (tid); + bfdcore_read (cbfd, osec, &lwp, sizeof (lwp), bfd_offset); + lwp = netorder64 (lwp); + + return ptid_t (pid, lwp, tid); +} + /* Restore the execution log from core file CBFD. */ static void @@ -2480,13 +2562,36 @@ record_full_restore (struct bfd &cbfd) try { + std::map thread_table; + int32_t thread_count = 0; + + /* First we read all the threads and their GIDs. Then, when we + read the instructions, we can find the threads based on the + PTID and store the real GID for this gdb session. */ + bfdcore_read (&cbfd, osec, &thread_count, + sizeof (thread_count), &bfd_offset); + thread_count = netorder32 (thread_count); + while (bfd_offset < osec_size + && thread_count > thread_table.size ()) + { + int32_t gid = 0; + bfdcore_read (&cbfd, osec, &gid, sizeof (gid), &bfd_offset); + thread_table[netorder32 (gid)] = read_ptid (&cbfd, osec, &bfd_offset); + } + while (bfd_offset < osec_size) { record_full_reset_incomplete (); - record_full_instruction::from_bfd (&cbfd, osec, &bfd_offset); + record_full_instruction::from_bfd (&cbfd, osec, &bfd_offset, + thread_table); - record_full_save_instruction (); + /* We can't use record_full_save_instruction here because it alters + the incomplete instruction, clobbering the current GID. So we + have to push things to the log manually. */ + record_full_incomplete_instruction.effects.shrink_to_fit (); + record_full_log.push_back (std::move + (record_full_incomplete_instruction)); } } catch (const gdb_exception &ex) @@ -2619,10 +2724,17 @@ record_full_instruction::to_bfd (gdb_bfd_ref_ptr &obfd, asection *osec, { uint32_t eff_count = (uint32_t) this->effects.size (); uint32_t insn_num = this->insn_num; + int32_t gid = this->thread->global_num; uint8_t sigval = (this->sigval.has_value ()) ? this->sigval.value () : GDB_SIGNAL_0; + if (record_debug) + gdb_printf (gdb_stdlog, + "\n Writing instruction number %d, with %d effects," + " in thread %d and PC:", + insn_num, eff_count, gid); + /* Signal. */ bfdcore_write (obfd.get (), osec, &sigval, sizeof (sigval), bfd_offset); eff_count = netorder32 (eff_count); @@ -2633,6 +2745,10 @@ record_full_instruction::to_bfd (gdb_bfd_ref_ptr &obfd, asection *osec, /* Instruction number. */ bfdcore_write (obfd.get (), osec, &insn_num, sizeof (uint32_t), bfd_offset); + /* Thread Identifier. */ + gid = netorder32 (gid); + bfdcore_write (obfd.get (), osec, &gid, sizeof(int32_t), + bfd_offset); this->pc.to_bfd (obfd, osec, bfd_offset); @@ -2642,6 +2758,21 @@ record_full_instruction::to_bfd (gdb_bfd_ref_ptr &obfd, asection *osec, } } +/* Write a ptid_t entr to the corefile pointed to by CBFD. */ + +static void +write_ptid (const gdb_bfd_ref_ptr &cbfd, asection *osec, int *bfd_offset, + ptid_t ptid) +{ + int32_t pid = netorder32 (ptid.pid ()); + int64_t tid = netorder64 (ptid.tid ()); + int64_t lwp = netorder64 (ptid.lwp ()); + + bfdcore_write (cbfd.get (), osec, &pid, sizeof (pid), bfd_offset); + bfdcore_write (cbfd.get (), osec, &tid, sizeof (tid), bfd_offset); + bfdcore_write (cbfd.get (), osec, &lwp, sizeof (lwp), bfd_offset); +} + /* Save the execution log to a file. We use a modified elf corefile format, with an extra section for our data. */ @@ -2677,12 +2808,19 @@ record_full_base_target::save_record (const char *recfilename) for (int i = record_full_next_insn - 1; i >= 0; i--) record_full_log[i].exec_insn (regcache); + /* Create a table relating this session's global ID and the + PTID of the thread, for reading the corefile in the future. */ + std::map thread_table; + for (thread_info &thr : all_threads_safe ()) + thread_table[thr.global_num] = thr.ptid; + /* Compute the size needed for the extra bfd section. */ save_size = 4; /* magic cookie */ for (int i = record_full_log.size () - 1; i >= 0; i--) { /* Number of effects of an instruction. */ - save_size += sizeof (uint32_t) + sizeof (uint8_t) + sizeof (uint32_t); + save_size += sizeof (uint32_t) + sizeof (uint8_t) + sizeof (uint32_t) + + sizeof (uint32_t); save_size += 4 + record_full_log[i].pc.len; for (auto &entry : record_full_log[i].effects) switch (entry.type ()) @@ -2694,8 +2832,16 @@ record_full_base_target::save_record (const char *recfilename) save_size += 1 + 4 + 8 + entry.mem ().len; break; } + + /* If a thread in the log hasn't been added yet, add it now. */ + if (thread_table.count (record_full_log[i].thread->global_num) == 0) + thread_table[i] = record_full_log[i].thread->ptid; } + int thread_count = thread_table.size (); + /* Space for the thread table. */ + save_size += 4 + (4 + 4 + 8 + 8) * thread_count; + /* Make the new bfd section. */ osec = bfd_make_section_anyway_with_flags (obfd.get (), "precord", SEC_HAS_CONTENTS @@ -2721,6 +2867,30 @@ record_full_base_target::save_record (const char *recfilename) phex_nz (magic, 4)); bfdcore_write (obfd.get (), osec, &magic, sizeof (magic), &bfd_offset); + /* Save the table of threads, so that multi-threaded execution can be + correctly reconstructed later. */ + if (record_debug) + gdb_printf (gdb_stdlog, + " Writing thread table with %d entries:", + thread_count); + + thread_count = netorder32 (thread_count); + bfdcore_write (obfd.get (), osec, &thread_count, + sizeof (thread_count), &bfd_offset); + for (auto &it : thread_table) + { + int32_t gid = it.first; + if (record_debug) + gdb_printf (gdb_stdlog, + " current global_num %d and PID %s", + gid, it.second.to_string ().c_str ()); + + gid = netorder32 (gid); + bfdcore_write (obfd.get (), osec, &gid, sizeof (it.first), + &bfd_offset); + write_ptid (obfd, osec, &bfd_offset, it.second); + } + /* Save the entries to recfd and forward execute to the end of record list. */ for (int i = 0; i < record_full_log.size (); i++) diff --git a/gdb/testsuite/gdb.reverse/pthreads-precsave.exp b/gdb/testsuite/gdb.reverse/pthreads-precsave.exp new file mode 100644 index 00000000000..53702ed26fa --- /dev/null +++ b/gdb/testsuite/gdb.reverse/pthreads-precsave.exp @@ -0,0 +1,93 @@ +# 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, save their logs to a precsave file and +# load it in a new session. + +require supports_reverse + +standard_testfile pthreads-reverse.c +set precsave [standard_output_file pthreads.precsave] + +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" + +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 "record save $precsave" \ + "Saved core file $precsave with execution log\." \ + "save execution log" + +clean_restart $testfile + +gdb_test "record full restore $precsave" \ + "Restored records from core file .*" \ + "reload precord save file" + +set main_thread -1 +set other_thread -1 + +gdb_test_multiple "info threads" "get thread numbers" -lbl { + -re "\r\n\[^\r\n\]* \(${::decimal}\) \[^\r\n\]+thread_func\[^\r\n\]*" { + set other_thread $expect_out(1,string) + exp_continue + } + -re "\r\n\[^\r\n\]* \(${::decimal}\) \[^\r\n\]+main\[^\r\n\]*" { + set main_thread $expect_out(1,string) + exp_continue + } + -re -wrap "" { + gdb_assert { $main_thread != -1 } "collected main thread ID" + gdb_assert { $other_thread != -1 } "collected other thread ID" + } +} + +if { $main_thread == -1 } { + untested "couldn't read the threads from the corefile" + return +} + +gdb_test "thread" ".*thread is $other_thread.*" \ + "identify starting thread" -- 2.56.0