56

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?
Community
  • 1
  • 1
Indra
  • 1,264
  • 3
  • 17
  • 24

3 Answers3

65

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.

xor007
  • 937
  • 1
  • 11
  • 19
  • 4
    this is the most correct answer! though the accepted answer will work, it is a hack, and changing this setting in the sysctl config is a much better option. – stonecrusher Dec 17 '14 at 15:45
  • This doesn't solve my problem while OP's one time solution is the only thing that works for me, but sadly jsut until enxt restart..... – dhein Aug 27 '15 at 12:19
24

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.

Indra
  • 1,264
  • 3
  • 17
  • 24
  • 2
    `sudo ~/Qt/Tools/QtCreator/bin/qtcreator`, and no need to modifies the files mentioned. – Life Jul 27 '14 at 01:17
  • 1
    Brilliant. Fixed mine too. Nice one – Beakie Aug 18 '14 at 18:45
  • 1
    Instead of rebooting you can also execute the command once in terminal: ```echo 0 | tee /proc/sys/kernel/yama/ptrace_scope``` – danger89 Sep 12 '14 at 17:14
  • 3
    @Life: this is probably a workaround. But the disadvantage is that you give root rights to your `qtcreator`. If there is a bug in `qtcreator` or a hacker finds an exploit, he/she has access rights to your entire machine. People should be more careful when it comes to `sudo`. – Willem Van Onsem Nov 11 '14 at 05:24
  • 10
    @Life: ***do not suggest that***. Ever. It's a security issue, not to mention that any Qt application using Qt >= 5.3 will happily `abort()` if run them with EUID 0 (see [here](https://codereview.qt-project.org/#/c/74531/)). -1 the main answer because the proper solution is modifying `/etc/sysctl.conf` or the right file under `/etc/sysctl.d/`, and *not* adding random stuff in the init sequence. – peppe Nov 21 '14 at 16:07
  • @people Really helpful suggestion. Thank you! – Life Nov 22 '14 at 03:28
5

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.

Community
  • 1
  • 1
Ehsan Sadr
  • 355
  • 3
  • 20
  • The only thing that changed to me is, that now the terminal app doesn't start even anymore. – dhein Aug 27 '15 at 12:12
  • You can find the output of your program in the "application output" in the bottom beside to Issues. If that's not what you are looking for, please explain your question in more details . – Ehsan Sadr Aug 27 '15 at 12:21
  • my problem is the same as the OP and it simply just doesn't make my programm start anymore. – dhein Aug 27 '15 at 12:23
  • is there a way to fix it on Android OS? i want to debug an app with GDB but it gives me "ptrace: Operation not permitted" error – 0xabc Apr 16 '16 at 08:08