gdb/record: fix "maint print record-instruction" at the start of log

Message ID 20260901143316.42661-1-guinevere@redhat.com
State New
Headers
Series gdb/record: fix "maint print record-instruction" at the start of log |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Test passed

Commit Message

Guinevere Larsen Sept. 1, 2026, 2:33 p.m. UTC
  My recent commit:

    commit caa9d8df0fca004a48cd9fd5048abaaaf2dd3eb1
    Author: Guinevere Larsen <guinevere@redhat.com>
    Date:   Thu May 28 15:36:33 2026 -0300
    gdb/record: Refactor record history

Caused a regression where, if a user was at the start of the record
history and used the command "maint print record-instruction", GDB
would throw an internal error for trying to print an out-of-bounds
record. This commit fixes this by making the check for out of bounds
printing independent of an argument being supplied.
---
 gdb/record-full.c                                     | 10 +++++-----
 gdb/testsuite/gdb.reverse/maint-print-instruction.exp |  5 +++++
 2 files changed, 10 insertions(+), 5 deletions(-)


base-commit: 6f24afa4391bd33f1263378280b99385d2c13055
  

Comments

Tom Tromey Sept. 1, 2026, 4:55 p.m. UTC | #1
>>>>> "Guinevere" == Guinevere Larsen <guinevere@redhat.com> writes:

Guinevere> Caused a regression where, if a user was at the start of the record
Guinevere> history and used the command "maint print record-instruction", GDB
Guinevere> would throw an internal error for trying to print an out-of-bounds
Guinevere> record. This commit fixes this by making the check for out of bounds
Guinevere> printing independent of an argument being supplied.

Looks reasonable to me.
Approved-By: Tom Tromey <tom@tromey.com>

thanks,
Tom
  
Guinevere Larsen Sept. 2, 2026, 2:20 p.m. UTC | #2
On 9/1/26 1:55 PM, Tom Tromey wrote:
>>>>>> "Guinevere" == Guinevere Larsen <guinevere@redhat.com> writes:
> Guinevere> Caused a regression where, if a user was at the start of the record
> Guinevere> history and used the command "maint print record-instruction", GDB
> Guinevere> would throw an internal error for trying to print an out-of-bounds
> Guinevere> record. This commit fixes this by making the check for out of bounds
> Guinevere> printing independent of an argument being supplied.
>
> Looks reasonable to me.
> Approved-By: Tom Tromey <tom@tromey.com>
Thanks for the quick review, pushed!
> thanks,
> Tom
>
  

Patch

diff --git a/gdb/record-full.c b/gdb/record-full.c
index aa451c05a5d..f6d603d2357 100644
--- a/gdb/record-full.c
+++ b/gdb/record-full.c
@@ -2796,11 +2796,11 @@  maintenance_print_record_instruction (const char *args, int from_tty)
   if (offset == record_full_log.size ())
     offset--;
   if (args != nullptr)
-    {
-      offset += value_as_long (parse_and_eval (args));
-      if (offset >= record_full_log.size () || offset < 0)
-	error (_("Not enough recorded history"));
-    }
+    offset += value_as_long (parse_and_eval (args));
+
+  if (offset >= record_full_log.size () || offset < 0)
+    error (_("Not enough recorded history"));
+
   auto to_print = record_full_log.begin () + offset;
 
   gdbarch *arch = current_inferior ()->arch ();
diff --git a/gdb/testsuite/gdb.reverse/maint-print-instruction.exp b/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
index edf6ec081cd..199adebf08b 100644
--- a/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
+++ b/gdb/testsuite/gdb.reverse/maint-print-instruction.exp
@@ -73,3 +73,8 @@  test_print true "1" "print following after reversing"
 
 test_print false "-10" "trying to print too far back"
 test_print false "10" "trying to print too far forward"
+
+# Return to the beginning of history and print.
+# This used to cause an internal error.
+gdb_test "reverse-continue" ".*" "moving to start of history"
+test_print false "" "Print at the start of history"