如何使用 DDD 查找进程卡住的位置
我有一个用 C 编写并在 CentOS 5.5 上运行的 TCP Svr 进程。它充当外部客户端的 TCP 服务器,并且还使用它建立的 Unix 域套接字与系统中的其他进程进行一些 IPC 通信。这不是一个多线程进程。它一次执行一项任务。我使用 epoll_wait() 来侦听 TCP 套接字或它通过内部进程建立的任何 IPC 套接字上的请求。当 epoll_wait() 函数中断时,我处理请求,无论是谁,然后返回 epoll_wait()
我有一个 TCP 客户端从外部(而不是 IPC)连接到该进程。它连接成功,发送请求消息,收到响应。我把它放在无限循环中 只是为了测试其鲁棒性等。
一段时间后,TCP 服务器停止响应来自 TCP 客户端的请求。 TCP 客户端连接成功,发送请求消息,但没有从 TCP 服务器返回任何响应消息。
所以我认为TCP服务器卡在其他地方,试图做某事并且没有返回到epoll_wait()来处理 其他请求进来。我尝试使用日志来弄清楚,但这并不能帮助我了解进程到底卡在哪里。
所以我想使用任何可以给我一些信息(函数名称会很棒)的调试器,关于进程正在做什么。设置断点是压倒性的,因为 TCP 服务器进程有大量的文件和函数......
我试图在 CentOS 5.5 上使用 DDD 来弄清楚发生了什么。我成功附加到该过程。然后我单击“Step”或“Stepi”或“Next”按钮...... 但什么也没发生....
顺便说一句,当我使用 Eclipse 进行调试并附加到此进程(或任何进程)时,我总是得到“__kernel_vsyscall()”....这是否意味着程序默认在以下位置中断: 不管它在做什么?如果是这样,我如何退出 __kernel_vsyscall() 调用,继续在我的程序中?如果我按 f8,它就会出来,但我不知道它在哪里,因为我丢失了堆栈跟踪......就像我之前所说的那样。因为我无法弄清楚它在哪里,所以我不知道在哪里放置断点......
总之,我想弄清楚我的进程卡在哪里或者它在做什么,并尝试从该点开始调试......
我该如何做去做这个吗?
谢谢 阿米特
I have a TCP Svr process written in C and running on CentOS 5.5. It acts as a TCP Server for external clients and also does some IPC communication with other processes in the system using Unix Domain Sockets it has establised. It's not a multi threaded process. It does one task at a time. There's an epoll_wait() I use to listen for requests on either the TCP socket or any of the IPC sockets it has established with internal processes. When the epoll_wait() function breaks,I process the request for whoever it is and then go back into epoll_wait()
I have a TCP Client that connects to this Process from outside (not IPC). It connects sucessfully, sends a request msg, gets a response back. I've put this in an infinite loop
just to test out its robustness etc.
After a while, the TCP Server stops responding to requests coming from TCP Client. The TCP client connects successfully, sends a request message, but it doesnt get any response msg back from the TCP server.
So I reckon the TCP server is stuck somewhere else, trying to do something and has not returned to the epoll_wait() to process
other requests coming in. I've tried to figure it out using logs, but thats not helping me understand where exactly the process is stuck.
So I wanted to use any debugger that can give me some information (function name would be great), as to what the process is doing. Putting breakpoints, is overwhelming cause the TCP Server process has tons of files and functions....
I'm trying to use DDD on CentOS 5.5, to figureout whats going on. I attach to the process successfully. Then I click on "Step" or "Stepi" or "Next" button....
but nothing happens....
btw when I use Eclipse for debugging, and attach to this process (or any process), I always get "__kernel_vsyscall()"....Does this mean, the program breaks by default at
whatever its doing? If thats the case, how do I come out of the __kernel_vsyscall() call, to continue within my program? If I press f8, it comes out, but then I dont know where it was, since I loose the stack trace....Like I said earlier. Since I cant figure where it was, I dont know where to put breakpoint....
In summary, I want to figureout where my process is stuck or what its doing and try to debug from that point on....
How do I go about this?
Thanks
Amit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
1)附加到C进程本身通常会引起问题,有什么方法可以让您在调试器中启动该进程吗?
2)使用DDD的单步功能需要在设置断点并根据命令停止程序后进行。通过阅读您的问题,我不确定您是否已经这样做了。您可能不想设置很多断点,但是可以在代码的关键部分设置一两个断点吗?
1) Attaching to a C process can often cause problems in itself, is there any way for you to start the process in the debugger?
2) Using the step functions of DDD need to be done after you've set a breakpoint and the program is stopped on a command. From reading your question, I'm not sure you've done that. You may not want to set many breakpoints, but is setting one or two in critical sections of code possible?
总之,我想要完成的是能够找到我的程序在挂起时卡在哪里。我想通了——就是这么简单。在 Eclipse 中创建配置...“调试配置 -> C/C++ 附加到应用程序”...
让进程从 shell 正常运行(最好附加终端)。当它挂起时,打开 eclipse,单击调试图标并运行配置的进程。它会要求您附加到一个进程。查找您的进程名称并附加到它。
现在,只需查看整个堆栈跟踪......您将看到一些您自己的函数调用与内核函数调用混合在一起。这会告诉你程序卡在哪里。
In summary, What I wanted to accomplish was to be able to find where my program is stuck, when it hangs. I figured it out - It was so simple. Create a configuration in Eclipse ...."Debug Configurations->C/C++ attach to application"...
Let the process run normally from shell (preferably with a terminal attached). When it hangs, open eclipse, click on the debug icon and run the configured process. It'll ask you to attach to a process. Look for your process name and attach to it.
Now, just look at the entire stack trace....you'll see some of your own function calls mixed with kernel function calls. That tells you where the program is stuck.