简体   繁体   English

如何使用DDD查找进程卡在哪里

[英]How to find where a process is stuck using DDD

I have a TCP Svr process written in C and running on CentOS 5.5. 我有一个用C编写并在CentOS 5.5上运行的TCP Svr进程。 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. 它充当外部客户端的TCP服务器,并使用已建立的Unix域套接字与系统中的其他进程进行一些IPC通信。 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. 我使用了一个epoll_wait()来侦听它在内部进程建立的TCP套接字或任何IPC套接字上的请求。 When the epoll_wait() function breaks,I process the request for whoever it is and then go back into epoll_wait() 当epoll_wait()函数中断时,我将处理请求的内容,然后返回epoll_wait()

I have a TCP Client that connects to this Process from outside (not IPC). 我有一个TCP客户端从外部(不是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. 一段时间后,TCP服务器停止响应来自TCP客户端的请求。 The TCP client connects successfully, sends a request message, but it doesnt get any response msg back from the TCP server. TCP客户端成功连接,发送请求消息,但没有从TCP服务器获得任何响应消息。

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. 因此,我认为TCP服务器被卡在其他地方,试图做某事,并且没有返回到epoll_wait()来处理其他传入的请求。我试图使用日志来弄清楚它,但这不能帮助我了解确切的位置这个过程卡住了。

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.... 放置断点是不堪重负的,原因是TCP Server进程具有大量文件和功能。

I'm trying to use DDD on CentOS 5.5, to figureout whats going on. 我正在尝试在CentOS 5.5上使用DDD,以了解发生了什么。 I attach to the process successfully. 我成功地加入了这个过程。 Then I click on "Step" or "Stepi" or "Next" button.... but nothing happens.... 然后,我单击“ Step”或“ Stepi”或“ Next”按钮。

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? 顺便说一句,当我使用Eclipse进行调试并附加到该进程(或任何进程)时,我总是得到“ __kernel_vsyscall()”。...这是否意味着程序在执行任何操作时默认都会中断? If thats the case, how do I come out of the __kernel_vsyscall() call, to continue within my program? 如果是这种情况,我如何从__kernel_vsyscall()调用中退出,以继续执行程序? 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. 如果我按f8键,它就会出来,但是后来我不知道它在哪里,因为我松开了堆栈跟踪...。 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 谢谢阿米特

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? 1)附加到C进程本身通常会引起问题,您是否可以通过任何方法在调试器中启动该进程?

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. 2)在设置断点并在命令上停止程序后,需要使用DDD的步进功能。 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? 您可能不想设置很多断点,但是可以在代码的关键部分设置一两个吗?

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"... 在Eclipse中创建配置....“调试配置-> C / C ++附加到应用程序” ...

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. 挂起时,打开eclipse,单击调试图标并运行配置的进程。 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. 这告诉您程序在哪里卡住。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM