Get MinGW Cross Compiler at SourceForge.net. Fast, secure and Free Open Source software downloads

Cross Debug on Linux and Wine


GDB, The GNU Debugger is the standard debugger for the GNU software system. You can debug binary compiled on MinGW Cross Compile environment in Linux, using the GDB built for the cross environment. However, you need not only cross GDB but also GDBserver for remote debug, since cross GDB on Linux can not execute Win32 binary.

Compile with -g option

In order to debug your application using GDB, you need to add -g option when you compile and link you application. If you are interested in detail debug option, please refer GCC manual (4.3.2).

Bulding application with -g option

$ i686-pc-mingw32-gcc -g sample.c -o smaple.exe

Remote debug using Wine

Usually in remote debugging, copy of the application is to be run with GDBserver on the target platform, and also the application is to be loaded into GDB on the development workstation. In case of Fedora MinGW Cross Compiling environment, in stead of actual target platform, Microsoft Windows, Wine on Linux can be used without using copy of the application in debug, if Wine is available on your system.


TARGET SYSTEM (Win32)




DEVELOPMENT SYSTEM (Linux)




























GDBserver


communication


i686-pc-mingw32-gdb
































sample.exe






sample.exe































figure : Remote Debug using GDBserver

On the Wine as target platform, launch the application with GDBserver, while specifying the host and port for listening to an incoming TCP connection:

>gdbserver localhost:60000 sample.exe

note: port 60000 is used as example.

launch sample.exe with GDBserver

figure : launch sample.exe with GDBserver (Wine)

On the Linux console, also launch the application with cross-target GDB:

$ i686-pc-mingw32-gdb sample.exe

At the GDB console, type:

(gdb) target remote localhost:60000
(gdb) break main
(gdb) continue
launch sample.exe with cross GDB

figure : launch sample.exe with cross GDB (Linux)

start debugging at GDBserver

figure : start debugging at GDBserver (Wine)

The process is stopped at main function, and then, you can debug the program with a remote GDB.

set break point at main function

figure : set break point at main function (Linux)

using DDD

GNU DDD, Data Display Debugger is a graphical front-end for command-line debuggers for GDB and other debuggers. If you prefer using GUI rather than command-line operation in debugging, DDD would be a good tool for you.

In order to start DDD with cross debugger for MinGW, add --debugger option to specify debugger name of MinGW shown in the following:

start DDD with i686-pc-mingw32-gdb

$ ddd --debugger i686-pc-mingw32-gdb &

After starting DDD, open application file to debug on DDD by selecting menus "File" -> "Open Program...".

DDD with i686-pc-mingw32-gdb

figure : DDD with i686-pc-mingw32-gdb

On the Wine as target platform, launch the application with GDBserver as same way as above.

launch sample.exe with GDBserver (Wine)

figure : launch sample.exe with GDBserver (Wine)

In GDB command window on DDD, set remote target.

set remote target on DDD

figure : set remote target on DDD

Also, set break point at main function and do continue. Of course, you can manipulate same operation on the GUI.

set break at main function on DDD

figure : set break at main function on DDD

Then you can debug the program with DDD.

remote debug with DDD

figure : remote debug with DDD

Related Links

  1. GDB: The GNU Project Debugger
  2. DDD - Data Display Debugger - GNU Project - Free Software Foundation (FSF)
  3. Linux.com :: Remote cross-target debugging with GDB and GDBserver