Today interview was asked a question, how to debug multi-process program, I answered GDB attach [PID], and then asked if some of the program data read wrong, but this phenomenon is accidental, this time to how to operate, then was ignorant ..., by looking up the data to find the answer, Now write down the blog post.
Checkpoint
Sometimes the occurrence of a bug occurs accidentally, if there is something to save the current state is good, in gdb, using checkpoint, GDB can save the moment of the program State or program image ( in addition to the process number and the output of the content ), And can return to the state of the program again, each checkpoint has a unique process ID, which is different from the PID of the original program, so if the program needs to use PID information, it needs to be considered carefully.
Use the snapshot using the following command:
Checkpoing: Generate a snapshot of the current state
Info checkpoint: Displaying snapshot information
Restart Checkpoint-id: revert to a checkpoint
Delete Checkpoint Checkpoint-id: Delete a checkpoint
GDB uses checkpoint to reproduce bugs