Not supported on windows
Supported on linux
Not supported on embedded
Not supported on android

restart command

Switches debugging session to the specified checkpoint

Syntax

restart [Checkpoint number]
restart 0

Parameters

Checkpoint number
Specifies the number of a checkpoint previously created using the checkpoint command. If 0 is specified, GDB will switch to debugging the original process.

Remarks

Note that a checkpoint is another branch of execution (a fork), not a snapshot. If you switch to a certain checkpoint and continue executing from there, the checkpoint state will be updated as well. If you want to continue from a checkpoint while preserving the checkpoint state, create another checkpoint before continuing from one.

Examples

We will demonstrate the use of the restart command using a basic C++ program that iterates from 0 to 9 and displays a message in each iteration:

#include <stdio.h>

int main(int argc, char **argv)
{
  for(int i = 0; i < argc; i++)
    printf("Arg %d: %s\n", i, argv[i]);
  return 0;
}

We will create several checkpoints at different stages of execution and use the info checkpoints command to display information about them.

(gdb) start
Temporary breakpoint 1 at 0x804847a: file test.cpp, line 11.
Starting program: /home/bazis/test

Temporary breakpoint 1, main (argc=1, argv=0xbffff064) at test.cpp:11
11 for (int i = 0; i < 10; i++)
(gdb) next
12 report(i);
(gdb) set variable i = 5
(gdb) checkpoint
checkpoint: fork returned pid 2113.
(gdb) step
report (iteration=5) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) break
Breakpoint 2 at 0x8048453: file test.cpp, line 6.
(gdb) continue
Continuing.
Pid 2109, iteration 5

Breakpoint 2, report (iteration=6) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) continue 3
Will ignore next 2 crossings of breakpoint 2. Continuing.
Pid 2109, iteration 6
Pid 2109, iteration 7
Pid 2109, iteration 8

Breakpoint 2, report (iteration=9) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 1
Switching to process 2113
#0 main (argc=1, argv=0xbffff064) at test.cpp:12
12 report(i);
(gdb) next

Breakpoint 2, report (iteration=5) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 0
Switching to process 2109
#0 report (iteration=9) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 1
Switching to process 2113
#0 report (iteration=5) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);

Compatibility with VisualGDB

You can use the restart command with VisualGDB using the GDB Session window in Visual Studio.

See also