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

C++QtLinux KernelQt5Linux Mint

C++ Problem Overview


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

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

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

    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.

What is the permanent solution for this?

C++ Solutions


Solution 1 - C++

If running Ubuntu,

The recommended way to enable the needed ptrace kernel setting (hinted by qtcreator) is to edit /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.

Solution 2 - C++

I got the answer.

  • Go to the location /etc with 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

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

Solution 3 - C++

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

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionIndraView Question on Stackoverflow
Solution 1 - C++xor007View Answer on Stackoverflow
Solution 2 - C++IndraView Answer on Stackoverflow
Solution 3 - C++eSadrView Answer on Stackoverflow