I am running Eclipse CDT on Windows to develop C code that is built & tested on remote Linux systems. Currently, the code is never compiled on Windows.
I am able to use CDT to begin the remote process on the Linux target under gdbserver, and then attach gdb from the Windows host. However, gdb immediately fails with errors like:
warning: A handler for the OS ABI "GNU/Linux" is not built into this configuration
of GDB. Attempting to continue with the default i386 settings.
[...]
Remote 'g' packet reply is too long: 74afe9bff0aee9bf02000000f4af4a00a0aee9bf[...]
Debugging between two Linux systems works fine, so it's clear that I'm doing something wrong on the Windows host side. My specific questions are:
Is the Cygwin version of gdb sufficient to debug remote Linux processes, or do I need a special cross-gdb in order to run it on Windows and work with Linux processes? If so, is there anywhere can I get hold of such a gdb?
Remote debugging with gdb requires that symbols are available on the host system. What is the easiest way to achieve this? Can I just copy the symbols produced by the build on the Linux target to the Windows host, or do have to get a full build going on Windows? Is there a way to avoid this requirement, such that I can supply symbols only on the target?
Thanks,
-R
More info: The RSE FAQ provides some pointers, but unfortunately I'm still blocked. The FAQ describes two approaches:
I have also raised this issue on the CDT forum.
To start remote debugging, run GDB on the host machine, and specify as an executable file the program that is running in the remote machine. This tells GDB how to find your program's symbols and the contents of its pure text. Note that the colon is still required here.
Launch gdb on Host System You can also load the symbols separately in the host using “file” command in gdb. Run GDB on the host. Use “target remote” to connect to the target system. Now you can run the normal gdb commands, as if you are debugging a local gdb program.
(5) You must use the same port number with the host GDB target remote command. communicates via a TCP connection to port 2345 on host `the-target'. For TCP connections, you must start up gdbserver prior to using the target remote command.
Just rebuild gdb with target platform supporting. You can use Cygwin for this. Example for RHEL target platform:
> wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
> tar -xJvf gdb-<ver>.tar.xz
> mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
> cd gdb-<ver>/build/x86_64-redhat-linux-gnu
> ../../configure --target=x86_64-redhat-linux-gnu
> make && make install
> x86_64-redhat-linux-gnu-gdb.exe --version
Don't forget to reconfigure your toolchain after this. To obtain the target configuration name, you can use:
> echo ${BASH_VERSINFO[5]}
Now there is a plugin http://marketplace.eclipse.org/content/direct-remote-c-debugging
Which allows you to launch gdb on the server remotely over ssh. It takes care about path mapping and others things.
You don't need gdb server to be running remotely
I failed to build on Windows, but found quite easy building it under Linux. To summarize and complete @Eugene response: First, prepare sources:
wget http://ftp.gnu.org/gnu/gdb/gdb-<ver>.tar.xz
tar -xJvf gdb-<ver>.tar.xz
mkdir -p gdb-<ver>/build/x86_64-redhat-linux-gnu
cd gdb-<ver>/build/x86_64-redhat-linux-gnu
Download Windows compiler:
sudo apt-get install mingw-w64
Check out the target configuration platform you want to debug your binaries (what to put in --target parameter):
echo ${BASH_VERSINFO[5]}
Prepare makefiles targeted for your desired platform but running on different host. We compiling it static so that it doesn't depend on any DLLs or other libraries. Also we disabling building other binaries as gdb wiki suggests:
../../configure --host=x86_64-w64-mingw32 --target=x86_64-pc-linux-gnu --enable-static=yes --disable-interprocess-agent --disable-binutils --disable-ld --disable-gold --disable-gas --disable-sim --disable-gprof
finally, build (takes like 30-60 min):
make LDFLAGS=-static
You can find your debugger in gdb folder. It is also good to strip it of debugging symbols as after building executable is huge:
strip -s gdb/gdb.exe
Voila! gdb.exe ready to run in Windows and remotely debug Linux executables!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With