Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is gdb requiring root permission to debug user programs?

Tags:

linux

gdb

I have been using gdb quite successfully for a while, but I recently upgraded my version of Ubuntu, and now it seems that I can only get gdb to successfully run my program if I run as root. That is,

~ %  gdb -q sleep -ex 'run 60'
Reading symbols from /bin/sleep...(no debugging symbols found)...done.
Starting program: /bin/sleep 60
tcsh: Permission denied.
During startup program exited with code 1.
(gdb)

fails, whereas

~ %  sudo gdb -q sleep -ex 'run 60'
Reading symbols from /bin/sleep...(no debugging symbols found)...done.
Starting program: /bin/sleep 60
Running .tcshrc
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
^C
Program received signal SIGINT, Interrupt.
0x00007ffff7adada0 in __nanosleep_nocancel () at ../sysdeps/unix/syscall-template.S:82
82  ../sysdeps/unix/syscall-template.S: No such file or directory.
(gdb)

works. One clue is that in the first case, the gdb startup doesn't run my .tcshrc file, whereas in the second case it does.

It seems that this is a simple permissions issue, which I must have fixed at one time, because in the past, I have never needed to run gdb as root. After much googling, however, I wasn't able to find what I might have done (if I did in fact do something). One possible fix - set ptrace permissions - didn't seem to work.

Is there something that needs to be done to allow gdb to run programs without root privileges? I know in OSX, gdb has to be codesigned. Is there something similar for Ubuntu/Linux?

like image 982
Donna Avatar asked Aug 30 '14 21:08

Donna


1 Answers

here are some ideas for debugging the gdb problem. comments aren't really feasible for such things, so I put them into an answer.

try the -n option to make sure no init file is loaded.

use the echo program instead of sleep 60 to make debugging simpler (the SIGINT thing in your example is probably specific to the sleep program.

run gdb -batch and put the rest into ~/.gdbinit:

file /bin/echo
run

add set verbose on.

don't forget to clean up ~/.gdbinit when done.

like image 178
user829755 Avatar answered Sep 23 '22 00:09

user829755