为什么gdb不能附加到使用inetd召唤的服务器应用程序?

Wil*_*mKF 3 c++ 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) 
Run Code Online (Sandbox Code Playgroud)

Din*_*lla 7

我的解决方案是这样的:

echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
Run Code Online (Sandbox Code Playgroud)

  • 这是一个适用于Ubuntu的解决方案,但据我所知,它不适用于Debian.请参阅http://blog.mellenthin.de/archives/2010/10/18/gdb-attach-fails-with-ptrace-operation-not-permitted/和https://wiki.ubuntu.com/SecurityTeam/Roadmap/ KernelHardening#的ptrace%20Protection (2认同)