如何知道gdb附加哪个进程(stat:T)? [英] How to know which process(stat: T) is attached by gdb?

查看:145
本文介绍了如何知道gdb附加哪个进程(stat:T)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当gdb附加进程时,进程的状态为T,如:

  root 6507 0.0 0.0 67896 952? Ss 12:01 0:00 / mytest 
root 6508 0.0 0.0 156472 7120? Sl 12:01 0:00 / mytest
root 26994 0.0 0.0 67896 956? Ss 19:59 0:00 / mytest
root 26995 0.0 0.0 156460 7116? Tl 19:59 0:00 / mytest
root 27833 0.0 0.0 97972 24564 pts / 2 S + 20:00 0:00 gdb / mytest

从以上所述,26995可能正在调试。我怎么知道26995是否调试?或者我可以知道gdb附加了哪个进程(27833)

pstree -p 27833 --- show gdb(27833)



另一个问题:如何知道一个进程(stat:T)是通过哪个gdb(PID)附加的?
在大多数情况下,我不是正在调试的peoson 中的 T ps 输出代表正在执行ptrace()d。所以这个过程(26995)正在被 追踪。这通常是 GDB strace



<所以,如果你知道你只运行 GDB 而不是 strace ,并且如果你看到一个单一的进程在 T 状态,那么你知道你正在调试该进程。



你也可以问<$ c

$ p $ g $ c $ g $ gdb info进程$($) b $ b(gdb)info劣质

更新
As Matthew Slattery正确地指出, T 只是表示进程已停止,并不是它是 ptrace()d



所以更好的解决方案是这样做的:

  grep' ^ TracerPid:'/ proc / * / status | grep -v':.0'
/ proc / 7657 / status:TracerPid:31069

从上面的输出可以看出进程7657正在被进程31069追踪。这会回答哪个进程正在调试程序和哪个调试程序正在调试什么。


When a process is attached by gdb, the stat of the process is "T", like:

root      6507  0.0  0.0  67896   952 ?        Ss   12:01   0:00 /mytest
root      6508  0.0  0.0 156472  7120 ?        Sl   12:01   0:00 /mytest
root     26994  0.0  0.0  67896   956 ?        Ss   19:59   0:00 /mytest
root     26995  0.0  0.0 156460  7116 ?        Tl   19:59   0:00 /mytest
root     27833  0.0  0.0  97972 24564 pts/2    S+   20:00   0:00 gdb /mytest

From the above, 26995 may be debuging. How can I know 26995 is debug or not? Or can I know which process is attached by gdb(27833)

pstree -p 27833 --- show gdb(27833)

Another question: How to know a process(stat: T) is attached by which gdb(PID)? In most siduation, I am not the peoson who is debuging the process.

解决方案

The T in ps output stands for "being ptrace()d". So that process (26995) is being traced by something. That something is most often either GDB, or strace.

So yes, if you know that you are only running GDB and not strace, and if you see a single process in T state, then you know that you are debugging that process.

You could also ask GDB which process(es) it is debugging:

(gdb) info process
(gdb) info inferior

Update As Matthew Slattery correctly noted, T just means the process is stopped, and not that it is being ptrace()d.

So a better solution is to do this:

 grep '^TracerPid:' /proc/*/status | grep -v ':.0'
 /proc/7657/status:TracerPid:    31069

From above output you can tell that process 7657 is being traced by process 31069. This answers both "which process is being debugger" and "which debugger is debugging what".

这篇关于如何知道gdb附加哪个进程(stat:T)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆