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

checkpoint command

Creates a new checkpoint

Syntax

checkpoint

Remarks

A GDB checkpoint is a separate process that is created by copying the state of the debugged process using the fork() function. Once created the checkpoint process will remain suspended until it is selected using the restart command. You can switch back to the main process by executing the restart command with a checkpoint number of 0.

Examples

We will demonstrate the use of the checkpoint 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 a checkpoint at iteration 0, run the program up until iteration 3, restore the checkpoint, run several iterations there and go back to the main branch:

(gdb) break report
Breakpoint 1 at 0x8048453: file test.cpp, line 6.
(gdb) run
Starting program: /home/bazis/test

Breakpoint 1, report (iteration=0) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) checkpoint
checkpoint: fork returned pid 2003.
(gdb) continue 3
Will ignore next 2 crossings of breakpoint 1. Continuing.
Pid 1999, iteration 0
Pid 1999, iteration 1
Pid 1999, iteration 2

Breakpoint 1, report (iteration=3) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) info checkpoints
1 process 2003 at 0x8048453, file test.cpp, line 6
* 0 process 1999 (main process) at 0x8048453, file test.cpp, line 6
(gdb) restart 0
Switching to process 1999
#0 report (iteration=3) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 1
Switching to process 2003
#0 report (iteration=0) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) continue
Continuing.
Pid 2003, iteration 0

Breakpoint 1, report (iteration=1) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 0
Switching to process 1999
#0 report (iteration=3) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) continue
Continuing.
Pid 1999, iteration 3

Breakpoint 1, report (iteration=4) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) restart 1
Switching to process 2003
#0 report (iteration=1) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);
(gdb) continue
Continuing.
Pid 2003, iteration 1

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

Breakpoint 1, report (iteration=9) at test.cpp:6
6 printf("Pid %d, iteration %dgetpid(), iteration);

Compatibility with VisualGDB

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

See also