C++ Qt Creator、ptrace:不允许操作。什么是永久解决方案?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22120711/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:56:24  来源:igfitidea点击:

Qt Creator, ptrace: Operation not permitted. What is the permanent solution?

c++qtlinux-kernelqt5linux-mint

提问by Indra

While debugging C++code in Qt creator I get the following error

C++在 Qt Creator 中调试代码时,出现以下错误

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

Here a temporary solution is found: Receiving error while trying to debug in QtProject

这里找到了一个临时解决方案:Receiving error while try to debug in QtProject

  • temporary solution (won't survive a reboot):

    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

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

    echo 0 | sudo tee /proc/sys/kernel/yama/ptrace_scope

But it is difficult to run the same code in terminal every time when I start my PC to use Qt.

但是每次启动PC使用Qt时,都很难在终端中运行相同的代码。

What is the permanent solution for this?

回答by xor007

If running Ubuntu,

如果运行 Ubuntu,

The recommended way to enable the needed ptrace kernel setting (hinted by qtcreator) is to edit /etc/sysctl.d/10-ptrace.conf

启用所需的 ptrace 内核设置(由 qtcreator 提示)的推荐方法是编辑 /etc/sysctl.d/10-ptrace.conf

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

Then change

然后改变

kernel.yama.ptrace_scope = 1

to

kernel.yama.ptrace_scope = 0

Save,

节省,

then apply:

然后申请:

$ sudo sysctl --system -a -p|grep yama
kernel.yama.ptrace_scope = 0

run

man sysctl

for more info.

了解更多信息。

回答by Indra

I got the answer.

我得到了答案。

  • Go to the location /etcwith root privilege.

  • Find the file rc.local.

  • Open it in a text editor like gedit and add the following code there
  • echo 0 | tee /proc/sys/kernel/yama/ptrace_scope
  • 转到/etc具有 root 权限的位置。

  • 找到文件rc.local

  • 在像 gedit 这样的文本编辑器中打开它并在那里添加以下代码
  • echo 0 | tee /proc/sys/kernel/yama/ptrace_scope

Restart your pc and you can see the debugger working perfectly.

重新启动您的电脑,您可以看到调试器完美运行。

回答by Ehsan Sadr

I found the answer that works for me on ubuntu in below link and the credit goes to dstzcxr

我在下面的链接中在 ubuntu 上找到了对我有用的答案,归功于dstzcxr

https://askubuntu.com/a/501271/395583

https://askubuntu.com/a/501271/395583

Just uncheck (or check - run - uncheck if it is for some reason unchecked) the box "Run in terminal" in "Projects" (on the left bar) - "Run" tab - "Run" section.

只需取消选中(或选中 - 运行 - 取消选中它是否由于某种原因未选中)“项目”(左侧栏)中的“在终端中运行”框 - “运行”选项卡 - “运行”部分。