Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Using gdb to debug win32 programs on wine

0 views
Skip to first unread message

Mike Wetherell

unread,
Apr 13, 2002, 7:25:07 AM4/13/02
to
Here's a suggestion for how to use a unix version of gdb to debug Windows
programs running under Wine. This way, gdb can be used to debug programs
compiled using gcc (mingw or cygwin) ports and cross-compilers. I expect it
can debug others too, though not msvc++.

gdb supports a huge range of executable formats, including the PE format
used by Windows. But currently, the version of gdb on your unix system
isn't likely to have support for PE compiled in, and so won't do well
debugging Windows programs.

To add PE support get the gdb source and take a look at the file
'bfd/config.bfd'. Find your platform in the table and add 'i386pe_vec
i386pei_vec' to the 'targ_selvecs' line. Here's an example of the change
for GNU/Linux:

--- gdb-5.1.1.orig/bfd/config.bfd Fri Jun 8 07:21:29 2001
+++ gdb-5.1.1/bfd/config.bfd Fri Apr 12 14:50:29 2002
@@ -373,7 +373,7 @@
;;
i[3456]86-*-linux-gnu*)
targ_defvec=bfd_elf32_i386_vec
- targ_selvecs="i386linux_vec bfd_efi_app_ia32_vec"
+ targ_selvecs="i386linux_vec bfd_efi_app_ia32_vec i386pe_vec
i386pei_vec"
;;
#ifdef BFD64
x86_64-*-freebsd*)

Then run './configure' and 'make' (and perhaps 'strip') as usual.

Now, suppore you wan't to debug HelloWin.exe:

$ gdb -q wine
(gdb) set gnutarget pei-i386
(gdb) add-symbol-file HelloWin.exe
add symbol table from file "HelloWin.exe" at
(y or n) y
Reading symbols from HelloWin.exe...done.
(gdb) run HelloWin.exe
Starting program: /usr/local/bin/wine HelloWin.exe

Then you can hit ctrl+C and set your break points, and assuming got the
wine source you'll be able to step through the code of both HelloWin and
wine.

If you need to set a break point before running your program, say you want
to debug WinMain, then an easy way is to set break points at 'main' then at
'start_process' in the Wine code, at which point your program will have
been loaded and you will be able to set a break point in it. e.g:

$ gdb -q wine
(gdb) set gnutarget pei-i386
(gdb) add-symbol-file HelloWin.exe
add symbol table from file "HelloWin.exe" at
(y or n) y
Reading symbols from HelloWin.exe...done.
(gdb) tbreak main
Breakpoint 1 at 0x804c157: file main.c, line 86.
(gdb) run HelloWin.exe
Starting program: /usr/local/bin/wine HelloWin.exe
main (argc=2, argv=0xbffffa84) at main.c:86
86 PROCESS_InitWine( argc, argv, main_exe_name, &main_exe_file );
(gdb) tbreak start_process
Breakpoint 2 at 0x400c2461: file process.c, line 322.
(gdb) continue
Continuing.
start_process () at process.c:322
322 HFILE main_file = main_exe_file;
(gdb) tbreak WinMain
Breakpoint 3 at 0x401236: file HelloWin.c, line 35.
(gdb) continue
Continuing.
WinMain (hInstance=0x400000, hPrevInstance=0x0, lpCmdLine=0x40340d38 "",
nCmdShow=10) at HelloWin.c:35
35 lpszClass = "HelloWin";

You can automate all that by putting the commands in '.dbginit' in your
projects directory.

Anyway, post your comments on this if you have any. I'd be interested to
know if anybody thinks it's useful/good idea/bad idea etc.

0 new messages