【gdb】为vfork调用设置catchpoint
为vfork调用设置catchpoint
1.例子:
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>
int main(void)
{
pid_t pid;
pid = vfork();
if (pid < 0)
{
exit(1);
}
else if (pid > 0)
{
exit(0);
}
printf("hello world\n");
return 0;
}
使用gdb调试程序时,可以用“catch vfork
”命令为vfork
调用设置catchpoint
,以上面程序为例:
[root@node01 demo]# gcc demo.c -g
[root@node01 demo]# gdb a.out -q
Reading symbols from /root/demo/a.out...done.
(gdb) catch vfork
Catchpoint 1 (vfork)
(gdb) r
Starting program: /root/demo/a.out
Catchpoint 1 (vforked process 3228327), vfork () at ../sysdeps/unix/sysv/linux/x86_64/vfork.S:44
44 pushq %rdi
(gdb) bt
#0 vfork () at ../sysdeps/unix/sysv/linux/x86_64/vfork.S:44
#1 0x00000000004005ca in main () at demo.c:10
(gdb)