为什么 gdb 无法附加到使用 inetd 调用的服务器应用程序?
我有一个服务器应用程序,可以使用 inetd 为客户端调用。但是,如果我尝试附加到使用 inetd 启动的服务器进程,我会收到以下响应: ptrace:不允许操作。
gdb --annotate=3 /my/app/here <processId>
Current directory is /usr/local/bin/
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Reading symbols from /usr/local/bin/flumed...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Attaching to program: /my/app/here, process <processId>
ptrace: Operation not permitted.
/usr/local/bin/<processId>: No such file or directory.
(gdb)
I have a server application that can be summoned for the client using inetd. However, if I try to attach to the server process that was launched with inetd, I get the following response: ptrace: Operation not permitted.
gdb --annotate=3 /my/app/here <processId>
Current directory is /usr/local/bin/
GNU gdb 6.8
Copyright (C) 2008 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Reading symbols from /usr/local/bin/flumed...done.
Using host libthread_db library "/lib/tls/libthread_db.so.1".
Attaching to program: /my/app/here, process <processId>
ptrace: Operation not permitted.
/usr/local/bin/<processId>: No such file or directory.
(gdb)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我的解决方案是这样的:
Solution for me was this:
显然,当用户 ID 不是 root 时,inetd 的情况会变得很奇怪。您最终会得到一个具有奇怪权限的进程。例如,即使权限为777,您也无法读取/proc/self/exe。我怀疑这个问题更多相同。尽管我是该进程的用户ID,但我没有权限。使用 root 运行 gdb 是一种解决方法。
Apparently, things get funky with inetd where the userid is not root. You end up with a process with weird permissions. For example, you are unable to read /proc/self/exe even though the permissions are 777. I suspect this issue is more of the same. Even though I'm the userid of the process, I don't have permissions. Using root for gdb is a work around.
根据 tgoodhart 的说法,其他 ptrace 用户(例如 /usr/bin/strace)也会阻止 gdb。
Further to what tgoodhart said, other
ptrace
users like/usr/bin/strace
will also blockgdb
.我还看到当多个 gdb 实例同时运行时会出现此问题,通常是因为我未能正确关闭 gdb。关闭这些泄露的实例解决了问题。
I have also seen this problem occur when multiple instances of gdb are running at the same time, usually because I failed to close gdb correctly. Closing these leaked instances fixed the problem.
请运行以下命令来解决您的问题:
sudo chmod +s /usr/bin/gdb
Pls run the following command to solve ur problem:
sudo chmod +s /usr/bin/gdb