Remote GDB debugging - c++

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.

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!

Due to peculiarities in our makefile build system the file references contained in the debugging symbols look like this:
../src/main.cpp
../../src/utils/logger.cpp
This is no problem for GDB, but Qt Creator was unable to map these paths to the actual files. I was able to fix this by adding 'dir' statements in the GDB init file:
dir src
dir src/utils
...
Now it works.

Related

can't do remote-debugging with j-link in Clion IDE

I am trying to remote-debug a project in Clion but I can't seem to get a working debugging session. I think I've correctly launched my gdb server/client because my gdb client connects to the JLinkGDBServerCL.exe process
and they communicate.However, in clion, I can't break in the source code. The only thing that I get from clion is a disassembly of my program with no symbol at all which is odd because there is a symbol table in the .elf
that I am trying to debug. And one last detail, I can't "step in" the assembly code neither (but I can run commands in the gdb client in Clion).
Here is a picture of my debug configuration : debug config
And here is what I'm talking about when I say I can't get a proper debugging session : "debugging session"
Does anybody know what the problem is ?
System info:
OS: Windows 10
IDE: Clion 2018.1.6
GDB Server: JLinkGDBServerCL.exe
Target: TM4C129 (cortex M4) (no OS, just a firmware)
Program: USBMicroloader.elf (debug mode)
I'm having the same issue. I found that if I add the path to the elf file from the build directory into the "Symbol file" (in the run configuration where you set up the remote gdb connection), it fixes your issue. This seems a bit kludgey, but I haven't been able to find a better solution.
However, the next issue I run into is that I can only run that configuration a single time. When I stop debugging I get a message in the console that reads Remote doesn't know how to detach. Debugger disconnected. The clean and build menu options are greyed out until I restart CLion.

How do breakpoints work when using a remote build host in NetBeans?

I have been tasked with setting up a development environment for an embedded platform. So far, I have set up a remote build host in NetBeans, which copies all of the source files to the target device, compiles them natively with the GNU toolchain on the device (g++, ld, etc.), and then runs the compiled binary and forwards stdout to the development machine that NetBeans is running on.
What I don't understand is: How does the binary on the build machine know where and when to start/stop if the breakpoints exist only in NetBeans? The build host only required ssh access and a compiling/linking toolchain, but somehow seems to communicate with NetBeans for debugging. A colleague of mine suggested it uses gdbserver, but I have not found any documentation on the NetBeans website about this package, and it is not installed on the build host (at least not from apt). How is NetBeans doing this?
GUI IDE's which use (or can be configured to use) a distinct command-line toolchain for compilation and debug typically do this by running each required toolchain program as a subprocess and interacting with it through standard streams. Essentially, the IDE would use gcc or gdb with the same textual interface used when running it in a terminal window. The IDE uses its knowledge of lines in the source file to configure breakpoints in gdb much as you would while running it by hand.
In your case, the IDE is configured to use a "remote host" for all of this, so instead of being invoked locally, the toolchain is controlled through as ssh session to the remote machine where both building and running occur.
Because the gdb debugger and the target program are running on the same computer, no gdbserver is required.
In the cases where gdb is too large for the target system, gdbserver is a small program which often gets cross-compiled for the target and loaded onto it. This serves as a compact little delegate which talks to the main gdb program running on a build machine via a serial or network connection and performs the raw interaction with processor, memory, and running program on behalf of gdb.
Another possibility is that the gdbserver role is held by a helper program running on the same machine as gdb which instead commands something like a JTAG debug adapter to interact with the target hardware at a lower level. In this case however, the helper program implementing the gdbserver protocol is not usually called "gdbserver" but instead has an implementation specific name, for example openocd.
gdb runs on the target machine. Only communication with gdb (commands etc) goes via net to your local machine. Read gdb documentation if need to know more/
You can do exactly the same - just open the remote terminal , run gdbserver, start gdb and you are done :)

Control gdb running on remote target

I have ability to run gdb on remote target and if I debug directly on this remote, everything is good. But the problem that I don't want to use pure command line gdb.
I want:
Integrate remote gdb with host QT Creator
Highlight source code when debugging remote
Also I want try to avoid using remote debugging by gdbserver, because it's too difficult and I've encountered multiple problems.
These problems:
On host machine I have to have copy of application
All multiple shared libraries should be resolved (with the same version)
Leads to have copy of remote root filesystem or to mount this one by sshfs.
...
If it is possible I'll just write plugin for QT Creator.
Can't I control remote gdb and send them commands like "break", "run", "print"?

How to run and debug C++ application in Eclipse that's started with a script?

I'm trying to use Eclipse CDT on Ubuntu for C++ development. I'm working on a large C++ project that leverages Tcl as a scripting language to kick off and control the application.
How can I configure Eclipse to launch the application using shell scripts rather than using a C++ "main" application? The shell scripts launch a Tcl application that in turn calls into the C++ application.
Also, is it possible to debug a C++ application using Eclipse and gdb that's started via a script? If so, how does one go about doing it?
Interesting question. Without being able to provide you a straight solution, but Eclipse (gdb) can be attached to a running program - that may not help in your case.
What about trying to employ some kind of remote debugging? I.e. you start your program with gdb and configure gdb to wait for a remote debugger to attach? The 'remote' debugger will be on your local system, of course.
EDIT:
Start your program via
gdbserver localhost:1234 <executable>
Configure your debug session in Eclipse:
- GDB Hardware Debugging
- I had to select the "Standard GDB Hardware debugging launcher" (Debugger tab at the bottom for Helios)
- Check use remote target: Generic TCP/IP: localhost, port 1234
I didn't manage to resolve symbols yet, that might be a path issue.

How to do remote debugging with Eclipse CDT without gdbserver?

We're using the Eclipse CDT 5 C++ IDE on Windows to develop a C++ application on a remote AIX host.
Eclipse CDT has the ability to perform remote debugging using gdbserver. Unfortunately, gdbserver is not supported on AIX.
Is anyone familiar with a way to debug remotely using Eclipse CDT without gdbserver? Perhaps using an SSH shell connection to gdb?
finally I got gdb run remotly anyhow now. At the Bug-symbol on the taskbar I took Debug Configurations - GDB Hardware Debugging.
In Main C/C++ Applications I set the full path on the Samba share of the executable (X:\abin\vlmi9506). I also set a linked folder on X:\abin in the project. Then I modified my batch-script in GDB Setup. It's not directly calling gdb in the plink-session but a unix-shell-script, which opens gdb. By this I have the possibility to set some unix environment-variables for the program before doing debug. The call in my batch:
plink.exe prevoax1 -l suttera -pw XXXXX -i /proj/user/dev/suttera/vl/9506/test/vlmi9506ddd.run 20155 dev o m
In the unix script I started gdb with the command line params from eclipse, that I found in my former tryals. The call in the shell command looks like this:
gdb -nw -i mi -cd=$LVarPathExec $LVarPathExec/vlmi9506
Then IBM just gives gdb 6.0 for AIX. I found version 6.8 in the net at http://www.perzl.org/aix/index.php?n=Main.Gdb. Our Admin installed it.
I can now step through the program and watch variables. I even can write gdb-commands directly in the console-view. yabadabadooooooo
Hope that helps to others as well. Can not tell, what was really the winner-action.
But each answer gives more new questions. Now I got 3 of them.
When I start the debug config I have to click restart in the toolbar to come really in the main procedure. Is it possible to come directly in main without restarting?
On AIX our programs are first preprocessed for embedded sql. The preprocessed c-source is put in another directory. When I duble-click the line to set a breakpoint, I get the warning "unresolved breakpoint" and in the gdb-console I see, that the break is set to the preprocessed source which is wrong. Is it possible to set the breakpoints on the right source?
We are using CICS on AIX. With the xldb-Debugger and the CDCN-command of CICS we manage that debugging is started, when we come in our programs. Is it possible to get that remotely (in plink) with gdb-eclipse as well?
I wouldn't normally take a shot in the dark on a question I can't really test the answer to, but since this one has sat around for a day, I'll give it a shot. It seems from looking at:
http://wiki.eclipse.org/TM_and_RSE_FAQ#How_can_I_do_Remote_Debugging_with_CDT.3F
...that even if the CDT has changed since that wiki page was made, you should still be able to change the debug command to:
ssh remotehost gdb
instead of using TM which uses gdbserver. This will probably be slightly slower than the TM remote debugging since that actually uses a local gdb, but on the other hand this way you won't have to NFS or SMB mount your source code to make it available to the local debugger (and if you're on a LAN it probably won't matter anyhow).
There's also a reference TCF implementation for linux, which you may or may not have any luck recompiling for AIX, but it allows for remote debugging if gdbserver is otherwise not available:
http://wiki.eclipse.org/DSDP/TM/TCF_FAQ
tried also to remotly debug an aix-appl with windows eclipse-cdt-gdb.
Got blocked at the end with unix/windows path-problems. Maybe my result can help u a little further - maybe you already got it work. I'm interested in your comment. asked on eclipse news portal- following the answer of martin oberhuber (thanks again) tried dsp dd (also blocked with path problem) and set an request in eclipse bugzilla.
here the link to news:
http://www.eclipse.org/newsportal/article.php?id=406&group=eclipse.dsdp.tm
Here my bugzilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=252758
At the moment we still debug localy with xldb but I am trying ddd-gdb at the moment. At least locally gdb is running.