Wine Debugging Guide
Wine Debugging Guide
WineHQ (https://www.winehq.org/)
Wiki (http://wiki.winehq.org/)
AppDB (//appdb.winehq.org/)
Bugzilla (//bugs.winehq.org/)
Forums (//forums.winehq.org/)
(https://www.winehq.org/)
(https://www.winehq.org/)
Search
Page (/Wine_Developer%27s_Guide/Debugging_Wine)
Discussion (/index.php?title=Talk:Wine_Developer%27s_Guide/Debugging_Wine&action=edit&redlink=1)
View source (/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&action=edit)
History (/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&action=history)
Contents
1 Introduction
1.1 Processes and threads: in underlying OS and in Windows
1.2 Wine, debugging and WineDbg
2 WineDbg modes of invocation
2.1 Starting a process
2.2 Attaching
2.3 On exceptions
2.4 Interrupting
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 1/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
2.5 Quitting
3 Using the Wine Debugger
3.1 Crashes
3.2 Program hangs, nothing happens
3.3 Program reports an error with a message box
3.4 Disassembling programs
3.5 Sample debugging session
3.6 Debugging Tips
3.7 Some basic debugger usages
3.8 Useful programs
4 Useful memory addresses
5 Configuration
5.1 Windows Debugging configuration
5.2 WineDbg configuration
5.3 Configuring +relay behaviour
6 WineDbg Expressions and Variables
6.1 Expressions
7 WineDbg Command Reference
7.1 Misc
7.2 Flow control
7.3 Breakpoints, watch points
7.4 Stack manipulation
7.5 Directory & source file manipulation
7.6 Displaying
7.7 Disassembly
7.8 Memory (reading, writing, typing)
7.9 Information on Wine internals
7.10 Debug channels
8 Other debuggers
8.1 GDB mode
8.2 Graphical frontends to gdb
8.2.1 DDD
8.2.2 kdbg
8.3 Using other Unix debuggers
8.4 Using other Windows debuggers
8.5 Main differences between winedbg and regular Unix debuggers
1 Introduction
1.1 Processes and threads: in underlying OS and in Windows
Before going into the depths of debugging in Wine, here's a small overview of process and thread handling in Wine. It
has to be clear that there are two different beasts: processes/threads from the Unix point of view and
processes/threads from a Windows point of view.
Each Windows thread is implemented as a Unix thread, meaning that all threads of a same Windows process share the
same (unix) address space.
In the following:
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 2/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
A W-process is made of one or several W-threads . Each W-thread is mapped to one and only one U-process . All
U-processes of a same W-process share the same address space.
winedbg telnet.exe
winedbg hl.exe -windowed
2.2 Attaching
winedbg can also be launched without any command line argument: winedbg is started without any attached process.
You can get a list of running W-processes (and their wpid ) using the info process command, and then, with the
attach command, pick up the wpid of the W-process you want to debug. This is a neat feature as it allows you to
debug an already started application.
2.3 On exceptions
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 3/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
When something goes wrong, Windows tracks this as an exception. Exceptions exist for segmentation violation, stack
overflow, division by zero, etc.
When an exception occurs, Wine checks if the W-process is debugged. If so, the exception event is sent to the
debugger, which takes care of it: end of the story. This mechanism is part of the standard Windows debugging API.
If the W-process is not debugged, Wine tries to launch a debugger. This debugger (normally winedbg, see III
Configuration for more details), at startup, attaches to the W-process which generated the exception event. In this
case, you are able to look at the causes of the exception, and either fix the causes (and continue further the execution)
or dig deeper to understand what went wrong.
If winedbg is the standard debugger, the pass and cont commands are the two ways to let the process go further for
the handling of the exception event.
To be more precise on the way Wine (and Windows) generates exception events, when a fault occurs (segmentation
violation, stack overflow...), the event is first sent to the debugger (this is known as a first chance exception). The
debugger can give two answers:
continue
the debugger had the ability to correct what's generated the exception, and is now able to continue process execution.
pass
the debugger couldn't correct the cause of the first chance exception. Wine will now try to walk the list of exception
handlers to see if one of them can handle the exception. If no exception handler is found, the exception is sent once
again to the debugger to indicate the failure of the exception handling.
Note: since some of Wine code uses exceptions and try/catch blocks to provide some functionality, winedbg
can be entered in such cases with segv exceptions. This happens, for example, with IsBadReadPtr function. In
that case, the pass command shall be used, to let the handling of the exception to be done by the catch block
in IsBadReadPtr .
2.4 Interrupting
You can stop the debugger while it's running by hitting Ctrl+C in its window. This will stop the debugged process, and
let you manipulate the current context.
2.5 Quitting
Wine supports the new XP APIs, allowing for a debugger to detach from a program being debugged (see detach
command).
3.1 Crashes
These usually show up like this:
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 4/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x0043369e).
Register dump:
CS:0023 SS:002b DS:002b ES:002b FS:0063 GS:006b
EIP:0043369e ESP:0b3ee90c EBP:0b3ee938 EFLAGS:00010246( R- -- I Z- -P- )
EAX:00000072 EBX:7b8acff4 ECX:00000000 EDX:6f727265
ESI:7ba3b37c EDI:7ffa0000
Stack dump:
0x0b3ee90c: 7b82ced8 00000000 7ba3b348 7b884401
0x0b3ee91c: 7b883cdc 00000008 00000000 7bc36e7b
0x0b3ee92c: 7b8acff4 7b82ceb9 7b8acff4 0b3eea18
0x0b3ee93c: 7b82ce82 00000000 00000000 00000000
0x0b3ee94c: 00000000 0b3ee968 70d7ed7b 70c50000
0x0b3ee95c: 00000000 0b3eea40 7b87fd40 7b82d0d0
Backtrace:
=>0 0x0043369e in elementclient (+0x3369e) (0x0b3ee938)
1 0x7b82ce82 CONSOLE_SendEventThread+0xe1(pmt=0x0(nil)) [/usr/src/debug/wine-1.5.14/dlls/kernel32/
console.c:1989] in kernel32 (0x0b3eea18)
2 0x7bc76320 call_thread_func_wrapper+0xb() in ntdll (0x0b3eea28)
3 0x7bc7916e call_thread_func+0x7d(entry=0x7b82cda0, arg=0x0(nil), frame=0xb3eeb18) [/usr/src/debu
g/wine-1.5.14/dlls/ntdll/signal_i386.c:2522] in ntdll (0x0b3eeaf8)
4 0x7bc762fe RtlRaiseException+0x21() in ntdll (0x0b3eeb18)
5 0x7bc7f3da start_thread+0xe9(info=0x7ffa0fb8) [/usr/src/debug/wine-1.5.14/dlls/ntdll/thread.c:40
8] in ntdll (0x0b3ef368)
6 0xf7597adf start_thread+0xce() in libpthread.so.0 (0x0b3ef468)
0x0043369e: movl %edx,0x0(%ecx)
Modules:
Module Address Debug info Name (143 modules)
PE 340000- 3af000 Deferred speedtreert
PE 3b0000- 3d6000 Deferred ftdriver
PE 3e0000- 3e6000 Deferred immwrapper
PE 400000- b87000 Export elementclient
PE b90000- e04000 Deferred elementskill
PE e10000- e42000 Deferred ifc22
PE 10000000-10016000 Deferred zlibwapi
ELF 41f75000-41f7e000 Deferred librt.so.1
ELF 41ff9000-42012000 Deferred libresolv.so.2
PE 48080000-480a8000 Deferred msls31
PE 65340000-653d2000 Deferred oleaut32
PE 70200000-70294000 Deferred wininet
PE 702b0000-70328000 Deferred urlmon
PE 70440000-704cf000 Deferred mlang
PE 70bd0000-70c34000 Deferred shlwapi
PE 70c50000-70ef3000 Deferred mshtml
PE 71930000-719b8000 Deferred shdoclc
PE 78130000-781cb000 Deferred msvcr80
ELF 79afb000-7b800000 Deferred libnvidia-glcore.so.304.51
ELF 7b800000-7ba3d000 Dwarf kernel32<elf>
\-PE 7b810000-7ba3d000 \ kernel32
ELF 7bc00000-7bcd5000 Dwarf ntdll<elf>
\-PE 7bc10000-7bcd5000 \ ntdll
ELF 7bf00000-7bf04000 Deferred <wine-loader>
ELF 7c288000-7c400000 Deferred libvorbisenc.so.2
PE 7c420000-7c4a7000 Deferred msvcp80
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 5/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 6/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 7/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Steps to debug a crash. You may stop at any step, but please report the bug and provide as much of the information
gathered to the bug report as feasible.
1. Get the reason for the crash. This is usually a page fault, an unimplemented function in Wine, or the like. When
reporting a crash, report this whole crashdump even if it doesn't make sense to you.
(In this case it is page fault on write access to 0x00000000. Most likely Wine passed NULL to the application or
the like.)
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 8/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
2. Determine the cause of the crash. Since this is usually a primary/secondary reaction to a failed or misbehaving
Wine function, rerun Wine with the WINEDEBUG=+relay environment variable set. This will generate quite a lot of
output, but usually the reason is located in the last calls. Those lines usually look like this:
3. If you have found a misbehaving Wine function, try to find out why it misbehaves. Find the function in the source
code. Try to make sense of the arguments passed. Usually there is a WINE_DEFAULT_DEBUG_CHANNEL(channel);
at the beginning of the source file. Rerun wine with the WINEDEBUG=+xyz,+relay environment variable set.
Occasionally there are additional debug channels defined at the beginning of the source file in the form
WINE_DECLARE_DEBUG_CHANNEL(channel); if so the offending function may also use one of these alternate
channels. Look through the the function for TRACE_(channel)("... /n"); and add any additional channels to
the command line.
4. Additional information on how to debug using the internal debugger can be found in
programs/winedbg/README.
5. If this information isn't clear enough or if you want to know more about what's happening in the function itself, try
running wine with WINEDEBUG=+all , which dumps ALL included debug information in wine. It is often necessary
to limit the debug output produced. That can be done by piping the output through grep, or alternatively with
registry keys. See Section 1.5.3 for more information.
6. If even that isn't enough, add more debug output for yourself into the functions you find relevant. See The section
on Debug Logging in this guide for more information. You might also try to run the program in gdb instead of
using the Wine debugger. If you do that, use handle SIGSEGV nostop noprint to disable the handling of seg
faults inside gdb (needed for Win16).
7. You can also set a breakpoint for that function. Start wine using winedbg instead of wine. Once the debugger is
running enter break RegOpenKeyExW (replace by function you want to debug, case is relevant) to set a
breakpoint. Then use continue to start normal program-execution. Wine will stop if it reaches the breakpoint. If
the program isn't yet at the crashing call of that function, use continue again until you are about to enter that
function. You may now proceed with single-stepping the function until you reach the point of crash. Use the other
debugger commands to print registers and the like.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 9/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Sometimes programs are reporting failure using more or less nondescript message boxes. We can debug this using the
same method as Crashes, but there is one problem... For setting up a message box the program also calls Wine
producing huge chunks of debug code.
Since the failure happens usually directly before setting up the message box you can start winedbg and set a
breakpoint at MessageBoxA (called by win16 and win32 programs) and proceed with continue. With WINEDEBUG=+all
Wine will now stop directly before setting up the message box. Proceed as explained above.
You can also run wine using WINEDEBUG=+relay wine program.exe 2>&1 | less -i and in less search for
MessageBox.
push bp
mov bp, sp
... function code ..
retf XXXX <--------- XXXX is number of bytes of arguments
This is a FAR function with no local storage. The arguments usually start at [bp+6] with increasing offsets. Note, that
[bp+6] belongs to the rightmost argument, for exported win16 functions use the PASCAL calling convention. So, if we
use strcmp(a,b) with a and b both 32-bit variables b would be at [bp+6] and a at [bp+10].
Most functions make also use of local storage in the stackframe:
enter 0086, 00
... function code ...
leave
retf XXXX
This does mostly the same as above, but also adds 0x86 bytes of stackstorage, which is accessed using [bp-xx].
Before calling a function, arguments are pushed on the stack using something like this:
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 10/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Here first the selector and then the offset to the passed string are pushed.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 11/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 12/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
OF_CREATE|OF_SHARE_EXCLUSIVE|OF_READWRITE
|Call USER.1: MESSAGEBOX(0x0000,0x09278376"You must close Windows and load SHARE.EXE before you start
And MessageBox'ed.
The code seems to find a writable harddisk and tries to create a file there. To work around this bug, you can define C:
as a network drive, which is ignored by the code above.
to get a listing of the functions the program calls in its start function. Now you do a
winedbg winfile.exe
This way, you get into winedbg. Now you can set a breakpoint on any function the program calls in the start
function and just type c to bypass the eventual calls of Winfile to this function until you are finally at the place
where this function gets called by the crashing start function. Now you can proceed with your debugging as
usual.
If you try to run a program and it quits after showing an error message box, the problem can usually be identified
in the return value of one of the functions executed before MessageBox() . That's why you should re-run the
program with e.g.
Then do a more relmsg and search for the last occurrence of a call to the string "MESSAGEBOX". This is a line
like
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 13/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
In my example the lines before the call to MessageBox() look like that:
I think that the call to MessageBox() in this example is not caused by a wrong result value of some previously
executed function (it's happening quite often like that), but instead the message box complains about a runtime
error at 0x0004:0x1056.
As the segment value of the address is only 4, I think that that is only an internal program value. But the offset
address reveals something quite interesting: offset 1056 is very close to the return address of FREELIBRARY() :
Provided that segment 0x0004 is indeed segment 0x1cf, we now we can use IDA to disassemble the part that
caused the error. We just have to find the address of the call to FreeLibrary() . Some lines before that the
runtime error occurred. But be careful! In some cases you don't have to disassemble the main program, but
instead some DLL called by it in order to find the correct place where the runtime error occurred. That can be
determined by finding the origin of the segment value (in this case 0x1cf).
If you have created a relay file of some crashing program and want to set a breakpoint at a certain location which
is not yet available as the program loads the breakpoint segment during execution, you may set a breakpoint to
GetVersion16/32 as those functions are called very often.
Then do a c until you are able to set this breakpoint without error message.
winedbg myprog.exe
the program loads and you get a prompt at the program starting point. Then you can set breakpoints:
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 14/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Then you hit c (continue) to run the program. It stops at the breakpoint. You can type
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 15/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
These are the normal Win16 addresses, called SEGPTR. They have a segment:offset notation, e.g. 0x01d7:0x0012.
The segment part usually is a selector, which always has the lowest 3 bits set. Some sample selectors are 0x1f7,
0x16f, 0x8f. If these bits are set except for the lowest bit, as e.g. with 0x1f6,xi then it might be a handle to global
memory. Just set the lowest bit to get the selector in these cases. A selector kind of points to a certain linear (see
above) base address. It has more or less three important attributes: segment base address, segment limit, segment
access rights.
Example:
Selector 0x1f7 (0x40320000, 0x0000ffff, r-x) So 0x1f7 has a base address of 0x40320000, the segment's last address
is 0x4032ffff (limit 0xffff), and it's readable and executable. So an address of 0x1f7:0x2300 would be the linear address
of 0x40322300.
DOS/Win16 standard mode
They, too, have a segment:offset notation. But they are completely different from normal Win16 addresses, as they
just represent at most 1MB of memory: the segment part can be anything from 0 to 0xffff, and it's the same with the
offset part.
Now the strange thing is the calculation that's behind these addresses: just calculate segment*16 + offset in order to
get a linear DOS address. So e.g. 0x0f04:0x3628 results in 0xf040 + 0x3628 = 0x12668. And the highest address you
can get is 0xfffff (1MB), of course.
5 Configuration
5.1 Windows Debugging configuration
The Windows debugging API uses a registry entry to know which debugger to invoke when an unhandled exception
occurs (see On exceptions for some details). Two values in key
[MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug]
Note 1: Creating this key is mandatory. Not doing so will not fire the debugger when an exception occurs.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 16/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Note 2: wineinstall (available in Wine source) sets up this correctly. However, due to some limitation of the
registry installed, if a previous Wine installation exists, it's safer to remove the whole
[MACHINE\\Software\\Microsoft\\Windows NT\\CurrentVersion\\AeDebug]
[HKCU\\Software\\Wine\\WineDbg]
Those options can be read/written while inside winedbg, as part of the debugger expressions. To refer to one of these
options, its name must be prefixed by a $ sign. For example,
set $BreakAllThreadsStartup = 1
When setting WINEDEBUG to +relay and debugging, you might get a lot of output. You can limit the output by
configuring the value RelayExclude in the registry, located under the key [HKCU\\Software\\Wine\\Debug]
Set the value of RelayExclude to a semicolon-separated list of calls to exclude, e.g.
"RtlEnterCriticalSection;RtlLeaveCriticalSection;kernel32.97;kernel32.98".
RelayInclude is an option similar to RelayExclude, except that functions listed here will be the only ones included in
the output.
If your application runs too slow with +relay to get meaningful output and you're stuck with multi-GB relay log files, but
you're not sure what to exclude, here's a trick to get you started. First, run your application for a minute or so, piping its
output to a file on disk:
Then run this command to see which calls are performed the most:
awk -F'(' '{print $1}' < relay.log | awk '{print $2}' | sort | uniq -c | sort
Exclude the bottom-most calls with RelayExclude after making sure that they are irrelevant, then run your application
again.
When specifying an identifier by its name, if several symbols with the same name exist, the debugger will prompt for the
symbol you want to use. Pick up the one you want from its number.
In lots of cases, you can also use regular expressions for looking for a symbol.
winedbg defines its own set of variables. The configuration variables from above are part of them. Some others
include:
$ThreadId
ID of the W-thread currently examined by the debugger
$ProcessId
ID of the W-thread currently examined by the debugger
registers
All CPU registers are also available, using '$' as a prefix. You can use info regs to get a list of available CPU registers.
The $ThreadId and $ProcessId variables can be handy to set conditional breakpoints on a given thread or process.
cont, step, next, stepi, nexti can be postfixed by a number (N), meaning that the command must be executed N
times.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 19/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
enable
enables (break|watch)point N
N
disable
disables (break|watch)point N
N
delete
deletes (break|watch)point N
N
cond N removes any existing condition to (break|watch)point N
cond N adds condition expr to (break|watch)point N. expr will be evaluated each time the breakpoint is hit. If the
expr result is a zero value, the breakpoint isn't triggered.
break *
adds a breakpoint at address N
N
break id adds a breakpoint at the address of symbol id
break id
adds a breakpoint at line N inside symbol id
N
break N adds a breakpoint at line N of current source file
break adds a breakpoint at current $PC address
watch *
adds a watch command (on write) at address N (on 4 bytes)
N
watch
adds a watch command (on write) at the address of symbol id
id
info
lists all (break|watch)points (with state)
break
You can use the symbol EntryPoint to stand for the entry point of the DLL.
When setting a break/watch-point by id, if the symbol cannot be found (for example, the symbol is contained in a not
yet loaded module), winedbg will recall the name of the symbol and will try to set the breakpoint each time a new
module is loaded (until it succeeds).
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 20/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
show dir prints the list of dirs where source files are looked for
dir pathname adds pathname to the list of dirs where to look for source files
dir deletes the list of dirs where to look for source files
symbolfile pathname loads external symbol definition
symbolfile pathname N loads external symbol definition (applying an offset of N to addresses)
list lists 10 source lines forwards from current position
list - lists 10 source lines backwards from current position
list N lists 10 source lines from line N in current file
list path:N lists 10 source lines from line N in file path
list id lists 10 source lines of function id
list * N lists 10 source lines from address N
You can specify the end target (to change the 10 lines value) using the ','. For example:
list 123, 234 lists source lines from line 123 up to line 234 in current file
list foo.c:1, 56 lists source lines from line 1 up to 56 in file foo.c
7.6 Displaying
A display is an expression that's evaluated and printed after the execution of any winedbg command.
winedbg will automatically detect if the expression you entered contains a local variable. If so, display will only be
shown if the context is still in the same function as the one the debugger was in when the display expression was
entered.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 21/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
7.7 Disassembly
Table 1-8. WineDbg dissassembly
fmt is either letter or count letter (without a space between count and letter), where letter can be
s an ASCII string
u a Unicode UTF16 string
i instructions (disassemble)
x 32-bit unsigned hexadecimal integer
d 32-bit signed decimal integer
w 16-bit unsigned hexadecimal integer
c character (only printable 0x20-0x7f are actually printed)
b 8-bit unsigned hexadecimal integer
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 22/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
g GUID
8 Other debuggers
8.1 GDB mode
WineDbg can act as a remote monitor for GDB. This allows to use all the power of GDB, but while debugging wine
and/or any Win32 application. To enable this mode, just add --gdb to winedbg command line. You'll end up on a GDB
prompt. You'll have to use the GDB commands (not WineDbg ones).
However, some limitation in GDB while debugging wine (see below) don't appear in this mode:
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 23/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
GDB will correctly present Win32 thread information and breakpoint behavior
Moreover, it also provides support for the Dwarf II debug format (which became the default format (instead of
stabs) in gcc 3.1).
2. Start ddd
3. In ddd, use Open File or Open Program to point to the Wine executable.
Copy that line and paste into ddd command pane (the one with the (gdb) prompt)
The program should now be loaded and up and running.
8.2.2 kdbg
Use the following steps, in this order:
1. Start the Wine debugger with a command line like:
localhost:12345 is not a fixed value, but has been printed in first step. wine should also be the full path to the
Wine executable.
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 24/26
5/10/2017 Wine Developer's Guide/Debugging Wine - WineHQ Wiki
Note: If you plan to used gdb for a multi-threaded Wine application (native or Winelib), then gdb will be able to
handle the multiple threads directly only if:
Wine is running on the pthread model (it won't work in the kthread one). See the Wine architecture
documentation for further details.
gdb supports the multi-threading (you need at least version 5.0 for that).
In the unfortunate case (no direct thread support in gdb because one of the above conditions is false), you'll
have to spawn a different gdb session for each Windows thread you wish to debug (which means no
synchronization for debugging purposes between the various threads).
Here's how to get info about the current execution status of a certain Wine process:
Change into your Wine source dir and enter:
$ gdb wine
Switch to another console and enter ps ax | grep wine to find all wine processes. Inside gdb, repeat for all Wine
processes:
with wpid being the process ID of one of the Wine processes. Use
(gdb) bt
to get the backtrace of the current Wine process, i.e. the function call history. That way you can find out what the
current process is doing right now. And then you can use several times:
(gdb) n
or maybe even
(gdb) b SomeFunction
and
(gdb) c
to set a breakpoint at a certain function and continue up to that function. Finally you can enter
(gdb) detach
WineDbg gdb
WineDbg debugs a Windows process: the various threads gdb debugs a Windows thread: a separate gdb session is
will be handled by the same WineDbg session, and a needed for each thread of a Windows process and a
breakpoint will be triggered for any thread of the W- breakpoint will be triggered only for the w-thread
process debugged
WineDbg supports debug information from stabs GDB supports debug information from stabs (standard
(standard Unix format) and C, CodeView, .DBG (Microsoft) Unix format) and Dwarf II.
Hosted By (https://www.codeweavers.com/)
https://wiki.winehq.org/index.php?title=Wine_Developer%27s_Guide/Debugging_Wine&printable=yes 26/26