C++ – Remote GDB debugging

cgdb

I've just spent a whole day trying to find a way to enable GDB debugging from Qt Creator or Eclipse. I learned that there are basically two approaches to launch the target application:

  • Using ssh (ssh host gdb)
  • Using gdbserver

I was able to use both approaches to launch gdb remotely and start the application. However, GDB never responds to any breakpoints set in the IDE. Also I can't pause the application to inspect the program state. In Qt Creator I just get an obscure stack trace (I might have been looking at the traces of ssh or gdb actually…).

Can anyone help me to get started?

Progress!

I found that with Qt Creator 2.0 there is an feature called "Attach and debug remote application." It's based on gdbserver. The good thing is that it stops on the IDE's breakpoints. However, there are two issues:

  • When it hits a breakpoint it only shows assembly code, not the source code.
  • GDB often quits because of 'signal received'

I should probably mention that the remote executable is compiled with an older version of GCC than the one installed on my local PC. Perhaps some of the problems are related to this.

Update

I should mention that I switched to running cgdb on the remote machine via SSH.

The remote Qt Creator-based solution wasn't stable. GDB tends to quit because of mysterious 'signal received' messages.

Best Answer

So that GDB on your host (the machine you develop and compile on, so where you have Qt Creator) you have to give it access to the "symbol file".

I usually don't use Qt Creator, but GDB and gdbserver directly for cross-compiled programs remote-debugging. You could maybe give this a try to be sure that this works for you and maybe then find the missing option in Qt Creator (or maybe this will help you find what is missing).

On the target machine run:

gdbserver :5000 yourprogram

On the host machine, run gdb and then load the symbol file:

(gdb) symbol-file yourprogram

On GDB on the host machine, you then have to connect to connect GDB to the remote gdbserver:

(gdb) target remote target_ip_address:5000

From then you can use GDB on the host controlling the program on the target.

I hope this helps!

Related Topic