How to properly debug a cross-compiled Windows code on linux?
<p>I have a small piece of Windows code, basically one copied from the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ff381409(v=vs.85).aspx" rel="noreferrer">MSDN tutorial</a> but adapted for C++. I can compile it now using one of the methods:</p>

<ul>
<li><p><code>i686-w64-mingw32-g++ -g hello.cpp -o hello</code> to produce a native Windows PE32 executable,</p></li>
<li><p><code>wineg++ -g hello.cpp -o hello</code> to produce a <code>libwine</code> wrapper pair <code>hello.exe</code> + <code>hello.exe.so</code>.</p></li>
</ul>

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

<ul>
<li><p><code>wine /usr/i686-w64-mingw32/sys-root/mingw/bin/gdbserver.exe :2000 hello</code> followed by <code>target remote :2000</code> in a local <code>gdb</code>: finds no symbols at all, everything is <code>??</code> across 10+ stack frames</p></li>
<li><p><code>wine /usr/i686-w64-mingw32/sys-root/mingw/bin/gdb.exe hello</code>: hangs, does not accept any user input on the command line</p></li>
<li><p><code>gdb wine</code> followed by <code>run hello</code>: <code>Missing separate debuginfos, use: dnf debuginfo-install wine-core-1.9.19-1.fc24.i686</code>, which I did and the error remains</p></li>
<li><p><code>gdb hello.exe.so</code>: causes a SIGSEGV</p></li>
<li><p>modifying the <code>hello.exe</code> script so that it sets the right environment but runs <code>gdb</code> in the end: no symbols whatsoever, <code>??</code> everywhere</p></li>
<li><p><code>winedbg hello</code> with and without <code>--gdb</code>: <strong>gets the farthest so far</strong>, starts with a black console window and lets me step in, but whatever is in my code is still <code>??</code>-ed out and <code>WinMain</code> (or anything containing that string) is not known</p></li>
<li><p><code>winedbg hello.exe</code> (for the output of <code>wineg++</code>): the program loads fully, the debugger hangs waiting for it while it already runs in the background</p></li>
<li><p>running the application and attaching to it in <code>winedbg</code>: does not fit the purpose (won't allow me to stop at the entry point) but otherwise works mostly like the last two points (works with the output of <code>MinGW</code> but does not show any internals of <code>hello.exe</code>, does not work at all with the output of <code>wineg++</code>).</p></li>
<li><p>reading tons of official and unofficial tutorials, bug reports, SO questions...</p></li>
</ul>

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