GDB attach 报错 Operation not permitted 的解决

在进入gdb后,直接使用 attach ID,出现下面的情况:

Could not attach to process.  If your uid matches the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user.  For more details, see /etc/sysctl.d/10-ptrace.conf

原因是Ubuntu 16.04 的 /etc/sysctl.d/10-ptrace.conf 文件中最后一行默认 kernel.yama.ptrace_scope = 1 这个值不允许用户使用普通账户使用 attach ID 连接程序进行调试,需要使用超级用户权限才能连接。

可以把 kernel.yama.ptrace_scope 的值改为 0,即:

sudo vim /etc/sysctl.d/10-ptrace.conf

将最后一行改为 kernel.yama.ptrace_scope = 0,保存退出。

重启系统后,普通用户就可以使用 attach ID 连接程序调试了。


   转载规则


《GDB attach 报错 Operation not permitted 的解决》 由 吴杭沉 采用 知识共享署名 4.0 国际许可协议 进行许可。
  目录