gdb: add 'maintenance print record-instruction' command

While chasing some reverse debugging bugs, I found myself wondering what
was recorded by GDB to undo and redo a certain instruction. This commit
implements a simple way of printing that information.

If there isn't enough history to print the desired instruction (such as
when the user hasn't started recording yet or when they request 2
instructions back but only 1 was recorded), GDB warns the user like so:

(gdb) maint print record-instruction
Not enough recorded history

If there is enough, GDB prints the instruction like so:

(gdb) maint print record-instruction
4 bytes of memory at address 0x00007fffffffd5dc changed from: 01 00 00 00
Register eflags changed: [ IF ]
Register rip changed: (void (*)()) 0x401115 <main+15>

Approved-by: Eli Zaretskii <eliz@gnu.org>
Reviewed-by: Alexandra Hajkova <ahajkova@redhat.com>
Reviewed-by: Lancelot Six <lsix@lancelotsix.com>
Approved-by: Tom Tromey <tom@tromey.com>
This commit is contained in:
Bruno Larsen
2022-11-03 10:17:36 +01:00
parent 502c7218da
commit e24d337e21
5 changed files with 211 additions and 0 deletions

View File

@@ -40542,6 +40542,14 @@ that symbol is described. The type chain produced by this command is
a recursive definition of the data type as stored in @value{GDBN}'s
data structures, including its flags and contained types.
@kindex maint print record-instruction
@item maint print record-instruction
@itemx maint print record-instruction @var{N}
print how GDB recorded a given instruction. If @var{n} is not positive
number, it prints the values stored by the inferior before the @var{n}-th previous
instruction was exectued. If @var{n} is positive, print the values after the @var{n}-th
following instruction is executed. If @var{n} is not given, 0 is assumed.
@kindex maint selftest
@cindex self tests
@item maint selftest @r{[}-verbose@r{]} @r{[}@var{filter}@r{]}