views:

14

answers:

1

That's a mouthful of a question but basically I want to know if I can use GDB on an application compiled to i686-pc-mingw on a linux cross-compiler. I want to debug the resulting program on the target windows box with source code references etc.

Is it possible and if so what to I need to take into account (ie, same version of mingw files, same binutils, same relative path to source code, etc...)?

One thing that throws me a bit is the version numbers of GCC and GDB don't seem to match up. How do you tell if versions will be compatible?

If these questions sound silly it's just because I haven't used GDB much, it's just something I want to start doing so I'm not trying to guess what broke.

+1  A: 

Yes, you should be able to use GDB on a Linux host to debug an executable running on i686-pc-mingw.

Terminology: the i686-pc-mingw system is your target, the Linux system is your host.

  • You already have a linux-hosted compiler which targets i686-pc-mingw.
  • You need to build a gdbserver for your target (using your cross-compiler).
  • You also need to build a gdb (using native, not cross-compiler). That gdb needs to be configured for --host=x86-linux and --target=i686-pc-mingw. This is effectively cross-gdb -- it runs on Linux, but debugs mingw executables.

Now run gdbserver :0 foo.exe (on target). That should print a port number on which gdbserver is listening for connections.

Run gdb foo.exe (on host), and connect to the remote target with target remote <windows-target-host-name>:<gdbserver-port-number>, and you should be in business.

P.S.
GCC and GDB are completely separate projects, their versions do not have anything to do with each other. You should be able to build GDB using any relatively recent GCC version.

Employed Russian
Wow thanks. I had a feeling that if this could be done it would be a complex process but I think I can do what you are suggesting. The two machines have a dedicated 1Gbps ethernet linking them and already communicate with samba drives and X servers so communicating via another server isn't an issue. Thanks for your clear and detailed response, especially as the terminology can get confusing.
SpliFF
I have a follow-up if you don't mind. Can you tell me WHY the gdb must be native? What is the reason for that?
SpliFF