调试fork()在eclipse cdt

编程入门 行业动态 更新时间:2024-10-09 10:31:32
本文介绍了调试fork()在eclipse cdt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我试图使用eclipse cdt(Juno)调试一些fork()机制。 我在C中写了程序。

if(-1 ==(pid = fork()))/ *错误* / goto清理; else if(0 == pid)/ * child * / { execlp(gcc,gcc,cFilePath,-o,GCC_OUTPUT_FILE_NAME,NULL); goto清理/ *到达这里只有错误! * / } else if(pid> 0)/ * parent - checks:正确的pid返回,正常返回,退出状态= 0 * / { returnedpid =等待(退出状态); if(pid!= returnedpid || exitStatus == NULL ||!WIFEXITED(* exitStatus)||!WEXITSTATUS(* exitStatus)) goto cleanup; }

我尝试添加 set follow-fork-模式孩子如下所示: unix.derkeiler/Newsgroups/comp.unix.programmer/2006-02/msg00435.html

1 。如何调试(0 == pid)?

2。当我到等待语句时,调试器刚刚返回,不等待()假设挂起,直到孩子返回?为什么会立即返回?

解决方案

您的问题可能是由于detach-on-fork关闭DSF默认设置(也是gdb的默认值)。

1)将断点放在execlp ...和returnedpid = ...的行上。 2)在调试配置中启用不间断模式和自动调试分叉进程。 3)启动调试会话。您将在小孩或父母中点击一个断点。现在看看调试视图。

你会注意到你的二进制显示两个线程。

4)点击一个或另一个(上图中带有main()的行)来切换调试上下文。

I'm trying to debug some fork() mechanism with eclipse cdt (Juno). I wrote the program in 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; }

I tried to add "set follow-fork-mode child" as said here: unix.derkeiler/Newsgroups/comp.unix.programmer/2006-02/msg00435.html

1. How can I debug the code section where (0==pid)?

2. When I get to the wait statement, the debugger just return immediately, isn't wait() suppose to suspend till the child returns? Why is it return immediately?

解决方案

Your problems are probably due to "detach-on-fork" being set to off. DSF sets this by default (it's also gdb's default).

1) Put a breakpoint onto lines with "execlp..." and "returnedpid =...". 2) In debug configuration enable "non-stop mode" and "automatically debug forked process". 3) Start debug session. You will hit a breakpoint either in child or parent. Now see debug view.

You will notice your binary shows two threads.

4) Click on one or the other (lines with main() in above image) to switch debug context.

更多推荐

调试fork()在eclipse cdt

本文发布于:2023-11-24 14:20:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1625563.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:fork   eclipse   cdt

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!