Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remotely debugging a Linux process from Windows with gdb and gdbserver: what exactly is needed on the Windows side?

Tags:

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:

  • Launch the gdb client on the remote system over ssh. Problem here is that certain fields in the CDT debug launcher are tied to the local system (project path, executable path etc...).
  • Build/obtain a cross-debugging version of gdb that supports debugging Linux processes from Windows. Problem here is that there's little info on how to achieve this.

I have also raised this issue on the CDT forum.

like image 559
rewbs Avatar asked Aug 17 '10 12:08

rewbs


People also ask

How will you do remote debugging using GDB?

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.

How do I run a GDB client?

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.

What port does GDB use?

(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.


3 Answers

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]}
like image 64
Eugene Weiss Avatar answered Oct 26 '22 14:10

Eugene Weiss


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

like image 21
Mohamed Abdelazim Avatar answered Oct 26 '22 14:10

Mohamed Abdelazim


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!

like image 23
tutejszy Avatar answered Oct 26 '22 12:10

tutejszy