Skip to content

gdb fork debug

solei1 edited this page Jul 17, 2019 · 1 revision
  1. set follow-fork-mode [parent|child]

  2. set detach-on-fork [on|off]

on: 断开调试follow-fork-mode指定的进程。 off: gdb将控制父进程和子进程。follow-fork-mode指定的进程将被调试,另一个进程置于暂停(suspended)状态。

  1. Attach子进程

  2. GDB wrapper

使用一个另一个文件替换目标文件

  1. set follow-fork-mode child + main断点

main函数的断点将被子进程继承(毕竟main是任何程序的入口)。

  1. set follow-fork-mode child + catch exec

  2. info inferiors/inferiors inferiors

设置set detach-on-fork off/set follow-exec-mode new。

If you choose to set `detach-on-fork' mode off, then gdb will retain control of all forked processes (including nested forks). You can list the forked processes under the control of gdb by using the info inferiors command, and switch from one fork to another by using the inferior command.

Clone this wiki locally