简体   繁体   English

使用 GDB 调试正在运行的守护进程

[英]debugging a running daemon with GDB

I want to debug a running daemon with the GDB.我想用 GDB 调试一个正在运行的守护进程。 I have the process id of respective process.我有相应进程的进程ID。 I typed: gdb attach process id info threads我输入:gdb attach process id info threads

I am getting the list of threads.我正在获取线程列表。 * one is the current one running thread (correct me if I am wrong) * 一个是当前正在运行的一个线程(如果我错了请纠正我)

Now I am sending:现在我发送:

systemctl kill daemonname (this command I am running on some other terminal) systemctl kill daemonname (这个命令我在其他终端上运行)

now I want to check that after hitting this command which thread is getting run.现在我想在点击这个命令后检查哪个线程正在运行。

since my daemon is getting stuck.因为我的守护进程卡住了。 it is not killing properly.它没有正确杀死。 I tried with the service-name status command.我尝试使用 service-name status 命令。 Since it is getting stuck after the above " servicename status " command.因为在上面的“servicename status”命令之后它被卡住了。 I want to trace the last thread that is getting stuck since my daemon is still not killed but running the command for checking the status of that daemon is stucked, no output is coming on output.我想跟踪最后一个卡住的线程,因为我的守护进程仍未被杀死,但运行检查该守护进程状态的命令被卡住了,output 上没有 output 即将到来。 while it should show that the service is not running or command not found if it gets killed properly.而如果它被正确杀死,它应该显示该服务没有运行或找不到命令。

Please help me.. i am new请帮助我..我是新人

I tried with the service-name status command.我尝试使用 service-name status 命令。

You may be holding it wrong.你可能拿错了。

After you execute systemctl kill daemonname , you want to attach GDB to the process and see where it is stuck (use thread apply all where ).执行systemctl kill daemonname后,您想将 GDB 附加到进程并查看它卡在哪里(使用thread apply all where )。

You will likely see that your threads are deadlocked (eg thread T1 is waiting for mutex A, which is held by thread T2; thread T2 is waiting for mutex B, held by thread T1).您可能会看到您的线程已死锁(例如,线程 T1 正在等待由线程 T2 持有的互斥锁 A;线程 T2 正在等待由线程 T1 持有的互斥锁 B)。

I want to trace the last thread that is getting stuck我想追踪最后一个卡住的线程

In general, tracing multithreaded processes is a fools errand, because the fact that you are tracing the process changes the execution environment and often causes it to no longer match execution without tracing.一般来说,跟踪多线程进程是一件傻事,因为您正在跟踪进程这一事实会改变执行环境,并且通常会导致它不再匹配执行而不进行跟踪。

Instead you should think about invariants, and make sure they are not violated.相反,您应该考虑不变量,并确保它们不被违反。

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

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