Can't get winedbg working with mingw-compiled exe

Questions about Wine on Linux
Locked
erickj00001
Newbie
Newbie
Posts: 1
Joined: Fri Jul 12, 2013 4:09 pm

Can't get winedbg working with mingw-compiled exe

Post by erickj00001 »

Hi, I'm trying to develop a program that runs in Windows. My development environment is Linux, so I'm compiling with mingw and using wine to run the resulting exe. This works, but I can't seem to get any debuggers to work with this setup. I know I must be doing something wrong -- it's probably really simple -- but I've not found any clues in the Wiki or on Google that have helped.

My system is Fedora 18, and I'm using mingw64-gcc version 4.7.2-7.fc18 (installed from yum). Wine is version 1.5.29-1.fc18 (also installed from yum).

For testing purposes, I have a very simple Windows program:

Code: Select all

[erick@erick-dell-690v-linux cfiles]$ cat simple.c
#include <windows.h>
#include <stdio.h>

void doSomething()
{
    char msg[256];
    sprintf(msg, "Process ID: %u", (unsigned)GetCurrentProcessId());
    MessageBox(NULL, msg, "Hello, world!", MB_OK | MB_ICONINFORMATION);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    doSomething();
    return 0;
}
[erick@erick-dell-690v-linux cfiles]$ x86_64-w64-mingw32-gcc -g -mwindows -o simple.exe simple.c
[erick@erick-dell-690v-linux cfiles]$ ./simple.exe
This works, and I see the message box popup. Now I'll try debugging:

Code: Select all

[erick@erick-dell-690v-linux cfiles]$ winedbg ./simple.exe
WineDbg starting on pid 0023
Looks ok, except the message box is already visible and I have no WineDbg command prompt. If I hit OK in the message box, I get this:

Code: Select all

Process of pid=0023 has terminated
Wine-dbg>
Now I have a command prompt, but it's too late -- the program has already exited! It seems like it should give me a command prompt before running the program, so I have time to set breakpoints etc.

I see that winedbg has a --gdb option, but I haven't had any luck with that either:

Code: Select all

[erick@erick-dell-690v-linux cfiles]$ winedbg --gdb ./simple.exe
0023:0024: create process 'Z:\home\erick\cfiles\simple.exe'/0x10ba0 @0x4014c0 (59904<1390>)
fixme:dbghelp:EnumerateLoadedModulesW64 If this happens, bump the number in mod
0023:0024: create thread I @0x4014c0
[erick@erick-dell-690v-linux cfiles]$
I don't have a clue what that error message means, and the message box doesn't appear in this case. Attaching to a running process doesn't work either:

Code: Select all

[erick@erick-dell-690v-linux cfiles]$ ./simple.exe &
[1] 725
[erick@erick-dell-690v-linux cfiles]$ winedbg --gdb 725
Can't attach process 02d5: error 87
Couldn't start process '725 '
Usage:
	winedbg [ [ --gdb ] [ prog-name [ prog-args ] | <num> | file.mdmp | --help ]
[erick@erick-dell-690v-linux cfiles]$ winedbg --gdb 36
0024:0025: create process 'Z:\home\erick\cfiles\simple.exe'/0x10bf0 @(nil) (59904<1390>)
fixme:dbghelp:EnumerateLoadedModulesW64 If this happens, bump the number in mod
0024:0025: create thread I @(nil)
I tried both the Linux process ID (725) and the Windows process ID (36, as was shown in the message box). The latter appears to be the "correct" choice, but it still just gives me a confusing error message and bombs out (also terminating simple.exe in the process).

I've also tried using gdb.exe from the mingw64-gdb package on yum.

Code: Select all

[erick@erick-dell-690v-linux cfiles]$ /usr/x86_64-w64-mingw32/sys-root/mingw/bin/gdb.exe simple.exe
GNU gdb (GDB) 7.5.1
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-w64-mingw32".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from Z:\home\erick\cfiles\simple.exe...done.
(gdb) break doSomething
It just hangs at that point, and I don't get another command prompt.

Can someone please tell me what I'm doing wrong? Any help would be greatly appreciated!
Locked