Debug Logging
Written by &name-dimitrie-paun; &email-dimitrie-paun;, 28 Mar 1998
(Extracted from wine/documentation/debug-msgs)
It is possible to turn on and of debugging output from
within the debugger using the set command. Please see the
WineDbg Command Reference section for how to do this.
At the end of the document, there is a "Style Guide" for
debugging messages. Please read it.
Debugging classes
There are 4 types (or classes) of messages:
FIXME
Messages in this class are meant to signal unimplemented
features, known bugs, etc. They serve as a constant and
active reminder of what needs to be done.
Examples: stubs, semi-implemented features, etc.
ERR
Messages in this class relate to serious errors in
Wine. This sort of messages signal an inconsistent
internal state, or more general, a condition which
should never happen by design.
Examples: unexpected change in internal state, etc.
WARN
These are warning messages. You should report a
warning when something unwanted happen but the
function behaves properly. That is, output a warning
when you encounter something unexpected (ex: could not
open a file) but the function deals correctly with the
situation (that is, according to the docs). If you do
not deal correctly with it, output a fixme.
Examples: fail to access a resource required by the app.
TRACE
These are detailed debugging messages that are mainly
useful to debug a component. These are usually turned
off.
Examples: everything else that does not fall in one of
the above mentioned categories and the user does not
need to know about it.
Debugging channels
To better manage the large volume of debugging messages that
Wine can generate, we divide them also on a component basis.
Each component is assigned a debugging channel. The
identifier of the channel must be a valid C identifier but
note that it may also be a reserved word like
int or static.
Examples of debugging channels:
reg
updown
string
We will refer to a generic channel as xxx.
How to use it
Typically, a file contains code pertaining to only one component,
and as such, there is only one channel to output to. To simplify
usage, you can declare that channel at the beginning of the file,
and simply write FIXMEs, ERRs, etc. as such:
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(xxx);
...
FIXME("some unimplemented feature", ...);
...
if (zero != 0)
ERR("This should never be non-null: %d", zero);
...
In rare situations there is a need to output to more than one
debug channel per file. In such cases, you need to declare
all the additional channels at the top of the file, and
use the _-version of the debugging macros:
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(xxx);
WINE_DECLARE_DEBUG_CHANNEL(yyy);
WINE_DECLARE_DEBUG_CHANNEL(zzz);
...
FIXME("this one goes to xxx channel");
...
FIXME_(yyy)("Some other msg for the yyy channel");
...
WARN_(zzz)("And yet another msg on another channel!");
...
If you need to declare a new debugging channel, simply use it in
your code. It will be picked up automatically by the build process.
Are we debugging?
To test whether the debugging output of class
yyy on channel xxx is
enabled, use:
TRACE_ON to test if TRACE is enabled
WARN_ON to test if WARN is enabled
FIXME_ON to test if FIXME is enabled
ERR_ON to test if ERR is enabled
Examples:
if(TRACE_ON(atom)){
...blah...
}
You should normally need to test only if
TRACE_ON. At present, none of the other
3 tests (except for ERR_ON which is
used only once!) are used in Wine.
Resource identifiers
Resource identifiers can be either strings or numbers. To
make life a bit easier for outputting these beasts (and to
help you avoid the need to build the message in memory), I
introduced a new function called debugres.
The function is defined in wine/debug.h
and has the following prototype:
LPSTR debugres(const void *id);
It takes a pointer to the resource id and returns a nicely
formatted string of the identifier (which can be a string or
a number, depending on the value of the high word).
Numbers are formatted as such:
#xxxx
while strings as:
'some-string'
Simply use it in your code like this:
#include "wine/debug.h"
...
TRACE("resource is %s", debugres(myresource));
The --debugmsg command line option
The --debugmsg command line
option controls the output of the debug messages.
It has the following syntax:
--debugmsg [yyy]#xxx[,[yyy1]#xxx1]*
where
# is either + or
-
when the optional class argument (yyy)
is not present, then the statement will
enable(+)/disable(-)
all messages for the given channel (xxx)
on all classes. For example:
--debugmsg +reg,-file
enables all messages on the reg
channel and disables all messages on the
file channel.
when the optional class argument (yyy)
is present, then the statement will enable
(+)/disable(-)
messages for the given channel (xxx)
only on the given class. For example:
--debugmsg trace+reg,warn-file
enables trace messages on the reg
channel and disables warning messages on the
file channel.
also, the pseudo-channel all is also supported and it
has the intuitive semantics:
--debugmsg +all -- enables all debug messages
--debugmsg -all -- disables all debug messages
--debugmsg yyy+all -- enables debug messages for class yyy on all
channels.
--debugmsg yyy-all -- disables debug messages for class yyy on all
channels.
So, for example:
--debugmsg warn-all -- disables all warning messages.
Also, note that at the moment:
the FIXME and ERR
classes are enabled by default
the TRACE and
WARN classes are disabled by
default
Compiling Out Debugging Messages
To compile out the debugging messages, provide
configure with the following options:
--disable-debug -- turns off TRACE, WARN, and FIXME (and DUMP).
--disable-trace -- turns off TRACE only.
This will result in an executable that, when stripped, is
about 15%-20% smaller. Note, however, that you will not be
able to effectively debug Wine without these messages.
This feature has not been extensively tested--it may subtly
break some things.
A Few Notes on Style
This new scheme makes certain things more consistent but
there is still room for improvement by using a common style
of debug messages. Before I continue, let me note that the
output format is the following:
yyy:xxx:fff <message>
where:
yyy = the class (fixme, err, warn, trace)
xxx = the channel (atom, win, font, etc)
fff = the function name
these fields are output automatically. All you have to
provide is the <message> part.
So here are some ideas:
do NOT include the name of the function: it is included automatically
if you want to output the parameters of the function, do
it as the first thing and include them in parentheses,
like this:
TRACE("(%d, %p, ...)\n", par1, par2, ...);
for stubs, you should output a FIXME
message. I suggest this style:
FIXME("(%x, %d, ...): stub\n", par1, par2, ...);
try to output one line per message. That is, the format
string should contain only one \n and it
should always appear at the end of the string. (there are
many reasons for this requirement, one of them is that
each debug macro adds things to the beginning of the line)
if you want to name a value, use = and
NOT :. That is, instead of saying:
FIXME("(fd: %d, file: %s): stub\n", fd, name);
say:
FIXME("(fd=%d, file=%s): stub\n", fd, name);
use : to separate categories.
try to avoid the style:
FIXME(xxx, "(fd=%d, file=%s)\n", fd, name);
instead use:
FIXME(xxx, "(fd=%d, file=%s): stub\n", fd, name);
The reason is that if you want to grep
for things, you would search for FIXME
but in the first case there is no additional information
available, where in the second one, there is (e.g. the word
stub)
if you output a string s that might contain control
characters, or if s may be
NULL, use
debugstr_a (for ASCII strings, or
debugstr_w for Unicode strings) to
convert s to a C string, like this:
HANDLE32 WINAPI YourFunc(LPCSTR s)
{
FIXME("(%s): stub\n", debugstr_a(s));
}
if you want to output a resource identifier, use debugres to
convert it to a string first, like this:
HANDLE32 WINAPI YourFunc(LPCSTR res)
{
FIXME("(res=%s): stub\n", debugres(s));
}
if the resource identifier is a SEGPTR, use
PTR_SEG_TO_LIN to get a
liner pointer first:
HRSRC16 WINAPI FindResource16( HMODULE16 hModule, SEGPTR name, SEGPTR type )
{
[...]
TRACE(resource, "module=%04x name=%s type=%s\n",
hModule, debugres(PTR_SEG_TO_LIN(name)),
debugres(PTR_SEG_TO_LIN(type)) );
[...]
}
for messages intended for the user (specifically those that
report errors in the wine config file), use the
MSG macro. Use it like a
printf:
MSG( "Definition of drive %d is incorrect!\n", drive );
However, note that there are very few
valid uses of this macro. Most messages are debugging
messages, so chances are you will not need to use this
macro. Grep the source to get an idea where it is
appropriate to use it.
For structure dumps, use the DUMP
macro. Use it like a printf, just like
the MSG macro. Similarly, there are only
a few valid uses of this macro. Grep the source to see when
to use it.