I just recently upgraded from 10.04 to 11.04 and gdb won't allow me to attach to processes anymore I get the error
Attaching to process 10144 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 ptrace: Operation not permitted.
How do I fix this so that I can debug again without sudo?
In Maverick Meerkat (10.10) Ubuntu introduced a patch to disallow ptracing of non-child processes by non-root users - ie. only a process which is a parent of another process can ptrace it for normal users - whilst root can still ptrace every process. Hence why you can use gdb to attach via sudo still.
You can temporarily disable this restriction (and revert to the old behaviour allowing your user to ptrace (gdb) any of their other processes) by doing:
To permanently allow it edit
/etc/sysctl.d/10-ptrace.conf
and change the line:To read:
For some background on why this change was made, see the Ubuntu wiki.
If you prefer to leave
/proc/sys/kernel/yama/ptrace_scope
set to its default value of1
, then as a workaround you could consider usinggdb
to run the program you want to debug. You can then bring up the debugger simply by pressing^C
. For example, to debug to the (boring) programsleep 60
, do the following:Here is a complete example.
Since
/bin/sleep
was (unsurprisingly) compiled without debugging information, the above backtrace contains minimal information.