Remote debug GDB as Root

I had followed the blog and get the “Hello World” working

How, when I trying the “LEDs” test using the sys/class/leds method,
the remote GDB would not able to Open the brightness file.

When I copy the program to target and run with “sudo”, then it works.
How can I setup to work for GDB ?

This sounds like a file permission issue.

If you need sudo <program> for the program to work correctly then you need to change the configuration somewhere.

There are three potential options:

  1. Use chmod a+rwX to change the file permissions to allow the program to run as a non-root user.
  2. Configure eclipse to run sudo gdbserver instead of just gdbserver to launch the remote debub stub (see if it provides a way to alter the gdbserver command line in any of the preferences).
  3. Configure eclipse to connect as the root user (e.g. set up ssh on to make it possible to ssh root@linaro-alip and change the username eclipse uses to connect with).

I tried method #2 by adding the “sudo su” to “Command Execute Before Application” in Eclipse Debugger tab.
But it would not connect with below :

sudo su;gdbserver :2345 /home/linaro/Downloads/HelloDragon;exit

linaro@linaro-alip:~$ sudo su;gdbserver :2345 /home/linaro/Downloads/HelloDrago

What I had done wrong using method #2 ?

  1. changing to “sudo gdbserver” in Eclipse give error :
    sudo\ gdbserver :2345 /home/linaro/Downloads/HelloDragon;exit
    linaro@linaro-alip:~$ sudo\ gdbserver :2345 /home/linaro/Downloads/HelloDragon;
    -bash: sudo gdbserver: command not found

The problem is the backslash which causes the space to form part of
the command. In other words instead of running the command
"sudo" "gdbserver" ":2345" "/home/linaro/Downloads/HelloDragon"
(run sudo with three parameters) eclipse has run
"sudo gdbserver" ":2345" "/home/linaro/Downloads/HelloDragon" (run a
non-existant command with a space in the middle of the command name with
two parameters).

In other words you have changed what eclipse thinks is the executable
not the command line. As a result eclipse has helpfully added the
backslash for you.

If eclipse does not provide any means to alter the gdbserver command
line then try one of the other approaches.

Just to explain, my list of possible options is generic for any GUI debugger that wraps itself around gdbserver. It is possible that some of the approaches are not supported by eclipse…

Thanks for the advises… Finally get it working using the Method #3

  1. By default the ssh root login is disabled in Linaro-Debian pre-build image. Have changed /etc/ssh/sshd_config :

PermitRootLogin without-password
PermitRootLogin yes

  1. Since I don’t know what is the root password from default image, I also reset new password in sudo mode

  2. After that, I change the Eclipse ssh login user to root … then it works.


BTW regarding the ssh/root config an alternative it is to copy your ssh (public) key into /root/.ssh/authorized_keys (which is what ssh-copy-id does for you under the covers). This is what the the default setting (PermitRootLogin without-password) is designed to work with.

However there’s absolutely nothing wrong with your approach though… I just wanted to explain what mode the defaults are tailored too.

1 Like