Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remote GDB debugging

Tags:

c++

c

gdb

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.

like image 925
StackedCrooked Avatar asked Aug 18 '10 14:08

StackedCrooked


People also ask

Is there a GUI for GDB?

KDbg is a graphical user interface to gdb, the GNU debugger. It provides an intuitive interface for setting breakpoints, inspecting variables, and stepping through code. KDbg requires KDE, the K Desktop Environment, but you can of course debug any program.

What is LLDB server?

lldb-server provides the server counterpart of the LLVM debugger. The server runs and monitors the debugged program, while the user interfaces with it via a client, either running locally or connecting remotely. All of the code in the LLDB project is available under the Apache 2.0 License with LLVM exceptions.


1 Answers

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!

like image 173
Longfield Avatar answered Oct 07 '22 00:10

Longfield