Bus*_*ush 12 c eclipse gdb fork eclipse-cdt
我正在尝试使用eclipse cdt(Juno)调试一些fork()机制.我用C编写了程序.
if( -1 == (pid = fork()) ) /* error */
goto cleanup;
else if ( 0 == pid ) /* child */
{
execlp("gcc", "gcc", cFilePath, "-o" , GCC_OUTPUT_FILE_NAME, NULL);
goto cleanup; /* Arrives here only on error! */
}
else if (pid > 0) /* parent - checks: correct pid returns, returns normally, with exit status = 0*/
{
returnedpid = wait(exitStatus);
if( pid != returnedpid || exitStatus == NULL || !WIFEXITED(*exitStatus) || !WEXITSTATUS(*exitStatus) )
goto cleanup;
}
Run Code Online (Sandbox Code Playgroud)
我试着在set follow-fork-mode child这里添加" ":http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2006-02/msg00435.html
1.我如何调试代码部分在哪里(0==pid)?
2.当我进入wait语句时,调试器立即返回,是不是wait()假设暂停直到子进程返回?为什么会立即返回?
dbr*_*nk0 14
你的问题可能是由于"分离分叉"被设置为关闭.DSF默认设置它(它也是gdb的默认值).
1)在"execlp ..."和"returnedpid = ..."的行上放置一个断点.2)在调试配置中启用"非停止模式"和"自动调试分叉进程".3)启动调试会话.您将在孩子或父母中遇到断点.现在看看调试视图.

你会注意到你的二进制显示两个线程.
4)单击其中一个(上图中带有main()的行)以切换调试上下文.