Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gdb need to run as root. emacs gdb-many-windows

Tags:

emacs

gdb

I use gdb-many-windows in emacs as normal user. But the program need to run as root. Can i change to root in emacs before run gdb-many-windows? Is there other way to solve this problem?

Update: Thanks all.

like image 343
louxiu Avatar asked Sep 11 '11 13:09

louxiu


2 Answers

When you do Meta-X gdb, emacs allows you to change the gdb command it will invoke.

Just change it to sudo gdb --annotate=3 ...

Update: as matt comments, this is still quite insecure. Better make it

sudo /usr/bin/gdb -ex 'set auto-load-scripts no' --annotate=3 ...

An even better approach might be to change your setup such that the program you are debugging does not need to run as root in the first place. Perhaps you could use fakeroot instead?

Update 2: sudo appears to interfere with emacs terminal handling. In particular, it tries to read password from /dev/tty and doesn't get input from emacs mini-buffer.

The solution is to allow yourself to invoke GDB without password via sudo. Something like this (in /etc/sudoers) should work:

your_user_id ALL = NOPASSWD: /usr/bin/gdb
like image 198
Employed Russian Avatar answered Oct 12 '22 23:10

Employed Russian


A solution not mentioned here is to have your build script set the setuid bit on your binary and set the ownership to root

chmod u+s binaryname
chmod g+s binaryname
chown root:root binaryname

that's probably more secure then either of the two answers (although it'll let anybody that has execute permission run the file as root, that may not be what you want...)

like image 24
Woodrow Douglass Avatar answered Oct 13 '22 00:10

Woodrow Douglass