15

I am pretty new to Eclipse. Trying to set up to do remote debugging.

Here is situation, I am connecting to remote machine running Linux, I am running Windows.

1) I have installed all the necessary tool for Eclipse, and was able to connect to Linux machine.

2) Remote machine has gdbserver

linux1[1]% gdbserver
Usage:  gdbserver [OPTIONS] COMM PROG [ARGS ...]
        gdbserver [OPTIONS] --attach COMM PID
        gdbserver [OPTIONS] --multi COMM

COMM may either be a tty device (for serial debugging), or
HOST:PORT to listen for a TCP connection.

Options:
  --debug               Enable debugging output.

Do I need to configure anything in gdbserver ???

3) What else should I configure in Eclipse ? for remote debugging ?

4) Does it matter that my GDB version is different from remote Machine GDB ?

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
newprint
  • 6,936
  • 13
  • 67
  • 109
  • Possible duplicate of [Remote debugging C++ applications with Eclipse CDT/RSE/RDT](https://stackoverflow.com/questions/15685104/remote-debugging-c-applications-with-eclipse-cdt-rse-rdt) – Ciro Santilli OurBigBook.com Aug 13 '17 at 09:08

3 Answers3

12

CLI sanity check

Before you do anything, make sure you:

This answer supposes that you can do on the development board:

sudo apt-get install gdbserver
gdbserver :1234 path/to/executable

And on host:

aarch64-linux-gnu-gdb \
  -ex "target remote board-hostname:1234" \
  -ex "file path/to/cross/compiled/executable" \
  -ex 'tb main' \
  -ex c

and then step debug everything correctly.

Eclipse setup

Tested in Ubuntu 16.04 host, Eclipse Oxygen 4.7.0 (downloaded from website), gdbserver 7.12, aarch64-linux-gnu-gdb 7.6.

I have successfully used all of the following methods:

  • manual
  • automatic
    • password auth
    • public key auth

Manual

With this method, we have to launch gdbserver on the target before running debug on Eclipse.

Pro: dispenses configuring SSH connections through Eclipse to allow Eclipse to run gdbserver, which is another possible point of failure.

Con: you have to relaunch gdbserver every time debugging starts. This could be overcome if Eclipse understood gdbserver --multi, but I don't think it does?

Due to its simplicity, I recommend that you get this method working first.

Open the debug configurations, then create a new "C / C++ Remote Application".

Under the tab "Main":

  • select the "Name", "Project" and "C/C++ Application" as usual for a local debug

  • at the bottom launcher, click "Select other", check "Use configuration specific settings" and pick "GDB (DSF) Manual Remote Debugging Launcher"

    Why we do this: the automatic launcher first connects to the board with SSH and launches the gdbserver for you.

    enter image description here

Under the tab "Debugger":

  • "GDB debugger": same as used from CLI on host, aarch64-linux-gnu-gdb for this example

  • Sub-tab "Connection": set hostname and port as passed to the host on CLI (board-hostname and 1234)

    enter image description here

    enter image description here

Finally, manually launch gdbserver on the target just as we did from the CLI:

gdbserver :1234 path/to/executable

and start the debugger from Eclipse normally.

You have to restart gdbserver every time you terminate the program.

Automatic with password auth

This is the best method for development boards, which have fixed publicly known passwords.

It connects to the target with SSH and a password, and launches gdbserver on the target automatically every time, which is super convenient!

Target gdbserver stdout goes to the Eclipse "Console" window, which further reduces window switching.

In Eclipse set:

Automatic with public key

Very similar to the password authentication, except that you must go to: "Connection", "New", and choose "Public key based authentication"

Pros:

  • overcomes the "Secure storage was unable to save the master password" if you have an unencrypted private key (unsafe, but fine for devboards)
  • for servers, you likely have already setup the public key

Cons:

  • key setup may hurt the first time
  • must redo key setup whenever devboard is nuked

so I would prefer this method for servers.

SSH can connect without a password if you:

Before using this method, make sure that your authorized keys work from the command line, i.e. you should now be able to do:

ssh user@host

without typing any password.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • It seems that now in 4.8, Eclipse Photon systematically tries to start gdbserver by itself through a telnet connection. – fralbo Sep 27 '18 at 11:27
8

gdbserver needs more arguments. For example, say gdbserver localhost:1337 yourprogram yourprogramarguments and keep it running.

Then, in Eclipse, create a new debug configuration for a "C/C++ Application". On the main tab, on the bottom, choose GDB (GSF) Remote System Process Launcher as launcher. On the debugger tab, choose gdbserver Debugger as the debugger. Under connection, say TCP as connection type and give localhost:1337 as address. When you launch the configuration, you may control the remote gdb by entering commands into the console.

dennycrane
  • 2,301
  • 18
  • 15
  • 1
    There is no "GDB(GSF) Remote System Process Launcher" option in the main tab in "C/C++ Application" under debug configuration... :-( – Robin Hsu Aug 17 '18 at 02:33
4

Update for Eclipse 2019-03

In eclipse 2019, the above steps didn't work, because Eclipse has changed the layout of the configuration in "C/C++ Remote Application".

Updates of @Ciro post:

The following steps worked with me: Under "Debug Configurations" Under "C / C++ Remote Application" Under the tab "Main":

  • select the "Connection" ==> "Remote Host".
  • select "New" , "SSH" (In my case) , then enter the configuration for your remote target machine.
  • in "Remote Absolute File Path for C/C++ Application:" set the path of the application in the target/remote device.

Under the tab "Debugger":

  • Sub-tab "Connection" has been removed.
  • New sub-tab "Gdbserver Settings" has been added.
  • Configure "Gdbserver path:" to point to the path of gdbserver. In my case it was "/usr/bin/gdbserver"
  • Configure port number

These are the only changes I made so that the previous answer works with me.

Osama F Elias
  • 1,544
  • 1
  • 11
  • 10