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.
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
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...)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With