如前文所述,gdb 遇到 fork 指令时默认会 attach 到父进程去,因此上述输出中有一行提示 ”Detaching after fork from child process 7509“,我们按 Ctrl + C 将程序中断下来,然后输入 bt 命令查看当前调用堆栈,输出的堆栈信息和我们在方法一中看到的父进程的调用堆栈一样,说明 gdb 在程序 fork 之后确实 attach ...
c:19 19 pid_t pid = fork(); (gdb) n [Detaching after fork from child process 5744] 20 if (pid < 0){ (gdb) hello world 23 else if (pid > 0){ (gdb) p pid $1 = 5744 (gdb) n 24 exit(0); (gdb) [Inferior 1 (process 5743) exited normally] pid=5744,说明gdb当前挂载在...
gdb (gdb)attach xxxxx--- xxxxx为利用ps命令获得的子进程process id (gdb)stop--- 这点很重要,你需要先暂停那个子进程,然后设置一些断点和一些Watch (gdb)break37-- 在result = wib(value, div);这行设置一个断点,可以使用list命令察看源代码 Breakpoint 1 at 0x10808: file eg1.c, line 37. (gdb)c...
方法1:调试多进程最土的办法:attach pid Attach是调试进程的常用办法,只要有可执行程序以及相应PID,即可工作。当然,为方便调试,可以在进程启动后,设定sleep一段时间,如30s,这样即可有充足的时间来attach。 方法2: set follow-fork-mode child + main断点 当设置set follow-fork-mode child,gdb将在fork之后直接执行...
Attach进程方法还是很方便的,它能够应付各种各样复杂的进程系统,比如孙子/曾孙进程,比如守护进程(daemon process),唯一需要的就是加入一小段代码。 2,follow-fork-mode/detach-on-fork 在2.5.60版Linux内核及以后,GDB对使用fork/vfork创建子进程的程序提供了follow-fork-mode选项来支持多进程调试 ...
int wib(int no1, int no2){ int result, diff;diff = no1 - no2;result = no1 / diff;return result;} int main(){ pid_t pid;pid = fork();if (pid <0) { printf("fork err\n");exit(-1);} else if (pid == 0) { /* in child process */ sleep(60)...
命令作用info inferiors查看进程列表attach pid绑定进程idinferior num切换到指定进程上进行调试print $_exitcode显示程序退出时的返回值set follow-fork-mode child追踪子进程set follow-fork-mode parent追踪父进程set detach-on-fork onfork调用时只追踪其中一个进程set detach-on-fork offfork调用时会同时追踪父子进...
/test_process Detaching after fork from child process 37482. this is parent,pid = 37478 [Inferior 1 (process 37478) exited normally] Missing separate debuginfos, use: debuginfo-install glibc-2.17-260.el7.x86_64 libgcc-4.8.5-36.el7.x86_64 libstdc++-4.8.5-36.el7.x86_64 (gdb) attach ...
attach $parent_pid file childcontinue 首先告诉 gdb 跟踪子进程;然后设置set breakpoint pending on是为了在设置断点时让 gdb 不强制在对符号下断点时就需要固定地址,这样在b _start时就会 pending 而不是报错;最后再连接到父进程以及加载子进程的符号。
调试起来并不方便。Attach子进程众所周知,GDB有附着(attach)到正在运行的进程的功能,即attach <pid>命令。因此我们可以利用该命令attach到子进程然后进行调试。例如我们要调试某个进程RIM_Oracle_Agent.9i,首先得到该进程的pid[root@tivf09 tianq]# ps -efgrep RIM_Oracle_Agent.9i...