debuggingcross-compilingmingw32wine

How to properly debug a cross-compiled Windows code on linux?


I have a small piece of Windows code, basically one copied from the MSDN tutorial but adapted for C++. I can compile it now using one of the methods:

All I want now is to start the file in a debugger (gdb or an interface to it if possible) and stop at the entry point WinMain. I'm failing badly at this. What I have tried (NB: in the following, hello without extension is, quite unconventially, the Windows executable):

I can't even remember the other combinations I tried. Surely it can't be that hard?


Solution

  • It seems I figured it out. With the compile command line

    i686-w64-mingw32-g++ -gstabs hello.cpp -o hello.exe
    

    I can run

    winedbg hello.exe
    

    and in its command line,

    break WinMain@16
    cont
    

    The important option was -gstabs instead of -g and no --gdb for winedbg. I figured out both after reading this mailing list thread, more relevant pieces of information are discussed there.

    Note that the bare winedbg is seriously impaired when it comes to name mangling and such, but gdb won't work (at least not out of the box) for the reasons outlined in the link above.