Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH v2] gdb/record: fix missing "no history" message in some situations
@ 2026-09-08 20:53 Guinevere Larsen
  0 siblings, 0 replies; only message in thread
From: Guinevere Larsen @ 2026-09-08 20:53 UTC (permalink / raw)
  To: gdb-patches; +Cc: Guinevere Larsen

I recently noticed that the end of recorded history message wasn't
shown when replaying an inferior until the end for the first time, it
was only shown when trying to reverse past the start of
history. Executing forward past the end will not warn the user that
recording is going to start again, it just does so. This is the
behavior before the change:

    (gdb) start
    Temporary breakpoint 1 at 0x40044a: file t.c, line 2.
    Starting program: /home/glarsen/a.out
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".

    Temporary breakpoint 1, main () at t.c:2
    2	  int x = 0;
    (gdb) record
    (gdb) n
    3	  x ++;
    (gdb) rn

    Reached end of recorded history; stopping.
    Backward execution from here not possible.
    main () at t.c:2
    2	  int x = 0;
    (gdb) n

    Reached end of recorded history; stopping.
    Following forward execution will be added to history.
    main () at t.c:3
    3	  x ++;
    (gdb)

And this is the behavior after the change:

    (gdb) start
    Temporary breakpoint 1 at 0x40044a: file t.c, line 2.
    Starting program: /home/glarsen/a.out
    [Thread debugging using libthread_db enabled]
    Using host libthread_db library "/lib64/libthread_db.so.1".

    Temporary breakpoint 1, main () at t.c:2
    2	  int x = 0;
    (gdb) record
    (gdb) n
    3	  x ++;
    (gdb) rn
    2	  int x = 0;
    (gdb) rn

    Reached end of recorded history; stopping.
    Backward execution from here not possible.
    main () at t.c:2
    2	  int x = 0;
    (gdb) n
    3	  x ++;
    (gdb) n
    4	  return x;

This was happening because the out-of-history was only set when it
caused the execution loop to stop, so using "next" to reach the end of
history, for example, wouldn't trigger it as I expected.  This commit
fixes that to make out-of-history check only happen after the loop is
finished.

Also add a test to ensure we dont regress again.
---
 gdb/record-full.c                        | 22 +++++--------
 gdb/testsuite/gdb.reverse/no-history.c   | 26 +++++++++++++++
 gdb/testsuite/gdb.reverse/no-history.exp | 40 ++++++++++++++++++++++++
 3 files changed, 74 insertions(+), 14 deletions(-)
 create mode 100644 gdb/testsuite/gdb.reverse/no-history.c
 create mode 100644 gdb/testsuite/gdb.reverse/no-history.exp

diff --git a/gdb/record-full.c b/gdb/record-full.c
index 26bd85d34f6..e9ec65b161b 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -1362,19 +1362,11 @@ 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)
-		{
-		  /* Hit beginning of record log in reverse.  */
-		  status->set_no_history ();
-		  record_full_next_insn = 0;
-		  break;
-		}
-	      if (execution_direction != EXEC_REVERSE
-		  && record_full_next_insn == record_full_log.size ())
-		{
-		  /* Hit end of record log going forward.  */
-		  status->set_no_history ();
-		  break;
-		}
+		break;
+
+	      else if (execution_direction != EXEC_REVERSE
+		       && record_full_next_insn == record_full_log.size ())
+		break;
 
 	      record_full_log[record_full_next_insn].exec_insn (regcache);
 
@@ -1424,11 +1416,13 @@ record_full_wait_1 (struct target_ops *ops,
 	    {
 	      gdb_assert (execution_direction == EXEC_REVERSE);
 	      record_full_next_insn = 0;
+	      status->set_no_history ();
 	    }
-	  else if (record_full_next_insn > record_full_log.size ())
+	  else if (record_full_next_insn >= record_full_log.size ())
 	    {
 	      gdb_assert (execution_direction == EXEC_FORWARD);
 	      record_full_next_insn = record_full_log.size ();
+	      status->set_no_history ();
 	    }
 	  /* Reset the current instruction to point to the one to be replayed
 	     moving forward.  */
diff --git a/gdb/testsuite/gdb.reverse/no-history.c b/gdb/testsuite/gdb.reverse/no-history.c
new file mode 100644
index 00000000000..4e7cf3786fd
--- /dev/null
+++ b/gdb/testsuite/gdb.reverse/no-history.c
@@ -0,0 +1,26 @@
+/* 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 <http://www.gnu.org/licenses/>.  */
+
+/* Test that GDB is printing the no-history messages as it should.  */
+
+int
+main ()
+{
+  int x = 0;
+  x++;
+  return 0;			/* END OF MAIN */
+}
diff --git a/gdb/testsuite/gdb.reverse/no-history.exp b/gdb/testsuite/gdb.reverse/no-history.exp
new file mode 100644
index 00000000000..443d3b66497
--- /dev/null
+++ b/gdb/testsuite/gdb.reverse/no-history.exp
@@ -0,0 +1,40 @@
+# Copyright 2008-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 <http://www.gnu.org/licenses/>.  */
+
+# This file is part of the GDB testsuite.  It tests the printing of
+# the "out of history" warnings.
+
+require supports_reverse
+
+standard_testfile
+
+if { [prepare_for_testing "failed to prepare" $testfile $srcfile] } {
+    return
+}
+
+runto_main
+
+if {[supports_process_record]} {
+    # Activate process record/replay
+    gdb_test_no_output "record" "turn on process record"
+}
+
+gdb_test "next" "x\\\+\\\+;" "Record a line of execution"
+gdb_test "reverse-next" \
+    ".*Reached end of recorded history; stopping.*" \
+    "Reverse to start of history"
+gdb_test "next" \
+    ".*Reached end of recorded history; stopping.*" \
+    "Forward to end of history"

base-commit: 0ca0b8de31ec76ff71f4a051db3dc1fcc9325154
-- 
2.55.0


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2026-09-08 20:54 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-08 20:53 [PATCH v2] gdb/record: fix missing "no history" message in some situations Guinevere Larsen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox