[RFA reverse] Process record and replay target user docs for gdb manual

teawater
2008-10-02T09:24:38Z

[-- Attachment #1: Type: text/plain, Size: 72 bytes --]

Hi,

This is process record and replay target user manual.

Thanks,
Hui

[-- Attachment #2: user.txt --]
[-- Type: text/plain, Size: 5978 bytes --]

Process Record and Replay Target user Manual

1. Overview
Process record and replay target can record a log of the process execution, and replay it with both forward and reverse execute commands.

When this target is in use, if the next instruction to be executed is in the execution log, GDB will debug in replay mode so that all the execution events are taken from the execution log. Otherwise, GDB will debug in record mode and record the execution log while executing normally.
Example:
(gdb) list
1 int
2 main()
3 {
4 int a = 10;
5
6 printf ("a = %d\n", a);
7 return 0;
8 }
(gdb) break main
Breakpoint 1 at 0x8048385: file 2.c, line 4.
(gdb) run
Starting program: /home/teawater/rec/a.out
Breakpoint 1, main () at 2.c:4
4 int a = 10;
(gdb) record
(gdb) next
6 printf ("a = %d\n", a);
(gdb) next
a = 10
7 return 0;
(gdb) reverse-next
6 printf ("a = %d\n", a);
(gdb) reverse-continue
Continuing.
No more reverse-execution history.
main () at 2.c:4
4 int a = 10;

In this example, GDB began recording the execution log at line 4, and recorded the execution until line 7. GDB was then able to use the recorded execution log to execute the program backward, first from line 7 back to line 6, and then from line 6 back to line 4.

2. Start Process Record and Replay Target
To start process record and replay target:
target record This a standard command to start target.
record An alias for "target record"
rec Can be abbreviated to the first three letters.

Process record and replay target can only debug a process that already running. Therefore you need to first start the process ("run"), and then start the recording ("record").

3. Stop Process Record and Replay Target
To stop process record and replay target:
stoprecord Stop process record and replay target at once.
sr Abbreviated form.

When the inferior process exits, or GDB detaches from it, process record and replay target will automatically stop itself.

When Process record and replay target stops, all the execution log will be deleted and the inferior will either be terminated, or remain in its final state.

When you stop the process record and replay target in record mode (at the end of the execution log), the inferior will be stopped at the next instruction that would have been recorded.

In other words, if you record for a while and then stop recording, the inferior process will be left in the same state as if you had never done any recording.

For example:
(gdb) record
(gdb) next
6 printf ("a = %d\n", a);
(gdb) stoprecord
Record: delete recorded log and stop recording?(y or n) y
(gdb) next
a = 10
7 return 0;

The example shows that after the recording is stopped, the inferior continues executing undesturbed, as it would have if the recording had never been started.

On the other hand, if the process record and replay target is stopped while in replay mode (that is, not at the end of the execution log but at some earlier point), the inferior process will become "live" at that earlier state, and it will then be possible to continue debugging the process "live" from that state.

For example:
(gdb) record
(gdb) next
6 printf ("a = %d\n", a);
(gdb) next
a = 10
7 return 0;
(gdb) reverse-next
6 printf ("a = %d\n", a);
(gdb) stoprecord
Record: delete recorded log and stop recording?(y or n) y
(gdb) set a=999
(gdb) next
a = 999

In this example, we see that printf is executed in record mode with the output "a = 10". Then GDB makes the process go back to before printf was called, stops the recording, and then changes the value of "a" before proceeding.

In the second execution of printf, therefore, the output is changed to "a = 999".

4. Limit number of instructions to record

Because the execution log is currently a fixed size, process record and replay target maintains an upper limit to the number of instructions to record. When this limit is reached, GDB will allow the user to choose whether to stop recording, or to automatically delete the oldest recorded instructions to make room for new ones.

To control recorded instructions limit:

set record-auto-delete [0,1] Set the behavior when record instructions limit is reached. 0 is the default value, meaning that GDB will stop the inferior. 1 mean that GDB will auto delete the oldest record to make room for each new one.

show record-auto-delete Show the value of record-auto-delete.

set record-insn-number-max [number] Set the limit of instructions to be recorded. Default value is 200000. If set to 0, record instructions number limit function will disable. In this case, if record instructions number is bigger than record instructions number limit, GDB will auto delete the earliest recorded instruction to make room for each new one.

show record-insn-number-max Show the value of recorded instructions limit.

info record-insn-number Show the current number of recorded instructions.

5. Set values of variables
In record mode, if the user asks GDB to set the values of variables, process record and replay target will automatically record the values of registers and memory that will be changed.

In replay mode, GDB will ask the user to confirm that he wants to change the values of registers or memory. If so, GDB will automatically delete the recorded log for all subsequent instructions and switch to record mode.

Therefore if you are debugging "in the past", and you make a change in the process state (registers or memory), you automatically delete "the future" that was previously recorded, and begin to record a new "future".

6.Other commands:
delrecord When record target running in replay mode ("in the past"), delete the subsequent execution log and begin to record a new execution log starting from the current address.

This has much the same effect as "changing the past" (see "Set values of variables", above); it means you will abandon the previously recorded "future" and begin recording a new "future".

dr Abbreviation of command "delrecord".