尝试在 QtProject 中调试时收到错误

use*_*009 14 compiling debugging qt c++

我安装了最新版本的 QtProject,所以现在我可以调试C++代码了。

第一次尝试调试时,我收到此错误:

ptrace: Operation not permitted.

Could not attach to the process. Make sure no other debugger traces this process.
Check the settings of
/proc/sys/kernel/yama/ptrace_scope
For more details, see /etc/sysctl.d/10-ptrace.conf
Run Code Online (Sandbox Code Playgroud)

ger*_*ijk 14

在 10.10 之后的 Ubuntu 版本上,您将在更多相关应用程序(例如 QtCreator)中遇到此问题。这是Ubuntu 的一项安全功能,可防止调试器附加到不属于他的进程。

这是作为针对 QtCreator错误 #3509 提交的。要解决此问题,请执行以下操作:

  • 临时解决方案(重新启动后将无法生存):

     echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope
    
    Run Code Online (Sandbox Code Playgroud)
  • 在一个文件/etc/sysctl.d/10-ptrace.conf(应该已经存在)中,改变kernel.yama.ptrace_scopeto的值,0然后重新加载配置:sudo sysctl -p.

我明确发布了临时解决方案,因为出于安全原因,您可能不想在常规计算机上禁用此功能。