2008-03-08 08:52:38 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
2008-03-08 09:43:31 -05:00
|
|
|
// Name: debug.h
|
2008-03-10 11:24:38 -04:00
|
|
|
// Purpose: interface of global functions
|
2008-03-08 09:43:31 -05:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2009-01-05 15:48:06 -05:00
|
|
|
/** @addtogroup group_funcmacro_debug */
|
2008-03-14 23:14:51 -04:00
|
|
|
//@{
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-03-21 19:36:37 -04:00
|
|
|
/**
|
|
|
|
@def wxDEBUG_LEVEL
|
|
|
|
|
|
|
|
Preprocessor symbol defining the level of debug support available.
|
|
|
|
|
|
|
|
Currently wxDEBUG_LEVEL is 0 in release builds (__WXDEBUG__ not defined)
|
|
|
|
and 1 in debug builds (it is). In the immediate future this will change
|
|
|
|
however and this symbol will be defined directly as 0, 1 or 2 while
|
|
|
|
__WXDEBUG__ won't be used by wxWidgets any longer.
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxDEBUG_LEVEL
|
|
|
|
|
|
|
|
/**
|
|
|
|
Type for the function called in case of assert failure.
|
|
|
|
|
|
|
|
@see wxSetAssertHandler()
|
|
|
|
*/
|
|
|
|
typedef void (*wxAssertHandler_t)(const wxString& file,
|
|
|
|
int line,
|
|
|
|
const wxString& func,
|
|
|
|
const wxString& cond,
|
|
|
|
const wxString& msg);
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Assert macro. An error message will be generated if the condition is @false in
|
|
|
|
debug mode, but nothing will be done in the release build.
|
2008-10-14 15:40:39 -04:00
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
Please note that the condition in wxASSERT() should have no side effects
|
|
|
|
because it will not be executed in release mode at all.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (in debug builds) logical errors done
|
|
|
|
by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@see wxASSERT_MSG(), wxCOMPILE_TIME_ASSERT()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxASSERT( condition )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2009-03-21 19:36:37 -04:00
|
|
|
/**
|
|
|
|
Assert macro for expensive run-time checks.
|
|
|
|
|
|
|
|
This macro does nothing unless wxDEBUG_LEVEL is 2 or more and is meant to
|
|
|
|
be used for the assertions with noticeable performance impact and which,
|
|
|
|
hence, should be disabled during run-time.
|
|
|
|
|
|
|
|
If wxDEBUG_LEVEL is 2 or more, it becomes the same as wxASSERT().
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxASSERT_LEVEL_2( condition )
|
|
|
|
|
|
|
|
/**
|
|
|
|
Assert macro with a custom message for expensive run-time checks.
|
|
|
|
|
|
|
|
If wxDEBUG_LEVEL is 2 or more, this is the same as wxASSERT_MSG(),
|
|
|
|
otherwise it doesn't do anything at all.
|
|
|
|
|
|
|
|
@see wxASSERT_LEVEL_2()
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxASSERT_LEVEL_2_MSG( condition, msg)
|
|
|
|
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
/**
|
2008-10-04 16:49:51 -04:00
|
|
|
This macro results in a @ref wxCOMPILE_TIME_ASSERT "compile time assertion failure"
|
|
|
|
if the size of the given @c type is less than @c size bits.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (in debug builds) logical errors done
|
|
|
|
by the programmer.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
You may use it like this, for example:
|
2008-03-09 08:33:59 -04:00
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
@code
|
|
|
|
// we rely on the int being able to hold values up to 2^32
|
2008-03-14 23:14:51 -04:00
|
|
|
wxASSERT_MIN_BITSIZE(int, 32);
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
// can't work with the platforms using UTF-8 for wchar_t
|
|
|
|
wxASSERT_MIN_BITSIZE(wchar_t, 16);
|
2008-03-08 08:52:38 -05:00
|
|
|
@endcode
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxASSERT_MIN_BITSIZE( type, size )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-10-04 16:49:51 -04:00
|
|
|
Assert macro with message.
|
|
|
|
An error message will be generated if the condition is @false.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (in debug builds) logical errors done
|
|
|
|
by the programmer.
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxASSERT(), wxCOMPILE_TIME_ASSERT()
|
2008-03-08 08:52:38 -05:00
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxASSERT_MSG( condition, message )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Checks that the condition is @true, returns with the given return value if
|
2008-10-04 16:49:51 -04:00
|
|
|
not (stops execution in debug mode). This check is done even in release mode.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (both in debug and release builds) logical
|
|
|
|
errors done by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxCHECK( condition, retValue )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Checks that the condition is @true, returns with the given return value if
|
2008-10-04 16:49:51 -04:00
|
|
|
not (stops execution in debug mode). This check is done even in release mode.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
This macro may be only used in non-void functions, see also wxCHECK_RET().
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (both in debug and release builds) logical
|
|
|
|
errors done by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxCHECK_MSG( condition, retValue, message )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Checks that the condition is @true, and returns if not (stops execution
|
|
|
|
with the given error message in debug mode). This check is done even in
|
|
|
|
release mode.
|
|
|
|
|
|
|
|
This macro should be used in void functions instead of wxCHECK_MSG().
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (both in debug and release builds) logical
|
|
|
|
errors done by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxCHECK_RET( condition, message )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Checks that the condition is @true, and if not, it will wxFAIL() and
|
|
|
|
execute the given @c operation if it is not. This is a generalisation of
|
|
|
|
wxCHECK() and may be used when something else than just returning from the
|
|
|
|
function must be done when the @c condition is @false. This check is done
|
|
|
|
even in release mode.
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (both in debug and release builds) logical
|
|
|
|
errors done by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxCHECK2(condition, operation)
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
This is the same as wxCHECK2(), but wxFAIL_MSG() with the specified
|
|
|
|
@c message is called instead of wxFAIL() if the @c condition is @false.
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (both in debug and release builds) logical
|
|
|
|
errors done by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
#define wxCHECK2_MSG( condition, operation, message )
|
2008-03-08 08:52:38 -05:00
|
|
|
|
|
|
|
/**
|
2008-03-14 23:14:51 -04:00
|
|
|
Using wxCOMPILE_TIME_ASSERT() results in a compilation error if the
|
|
|
|
specified @c condition is @false. The compiler error message should include
|
|
|
|
the @c message identifier - please note that it must be a valid C++
|
|
|
|
identifier and not a string unlike in the other cases.
|
|
|
|
|
2008-03-08 08:52:38 -05:00
|
|
|
This macro is mostly useful for testing the expressions involving the
|
|
|
|
@c sizeof operator as they can't be tested by the preprocessor but it is
|
|
|
|
sometimes desirable to test them at the compile time.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
Note that this macro internally declares a struct whose name it tries to
|
|
|
|
make unique by using the @c __LINE__ in it but it may still not work if you
|
2008-03-08 08:52:38 -05:00
|
|
|
use it on the same line in two different source files. In this case you may
|
|
|
|
either change the line in which either of them appears on or use the
|
2008-03-10 11:24:38 -04:00
|
|
|
wxCOMPILE_TIME_ASSERT2() macro.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
Also note that Microsoft Visual C++ has a bug which results in compiler
|
|
|
|
errors if you use this macro with 'Program Database For Edit And Continue'
|
|
|
|
(@c /ZI) option, so you shouldn't use it ('Program Database' (@c /Zi) is ok
|
|
|
|
though) for the code making use of this macro.
|
2008-03-08 09:43:31 -05:00
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch misconfigurations at compile-time.
|
|
|
|
|
2008-03-10 11:24:38 -04:00
|
|
|
@see wxASSERT_MSG(), wxASSERT_MIN_BITSIZE()
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxCOMPILE_TIME_ASSERT( condition, message )
|
|
|
|
|
|
|
|
/**
|
|
|
|
This macro is identical to wxCOMPILE_TIME_ASSERT() except that it allows
|
|
|
|
you to specify a unique @c name for the struct internally defined by this
|
|
|
|
macro to avoid getting the compilation errors described for
|
|
|
|
wxCOMPILE_TIME_ASSERT().
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch misconfigurations at compile-time.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxCOMPILE_TIME_ASSERT2(condition, message, name)
|
|
|
|
|
2009-03-21 19:36:37 -04:00
|
|
|
/**
|
|
|
|
Disable the condition checks in the assertions.
|
|
|
|
|
|
|
|
This is the same as calling wxSetAssertHandler() with @NULL handler.
|
|
|
|
*/
|
|
|
|
void wxDisableAsserts();
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
/**
|
2008-10-14 15:40:39 -04:00
|
|
|
Will always generate an assert error if this code is reached (in debug mode).
|
|
|
|
Note that you don't have to (and cannot) use brackets when invoking this
|
|
|
|
macro:
|
|
|
|
|
|
|
|
@code
|
|
|
|
if (...some condition...) {
|
|
|
|
wxFAIL;
|
|
|
|
}
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
This macro should be used to catch (in debug builds) logical errors done
|
|
|
|
by the programmer.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
@see wxFAIL_MSG()
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
2008-10-14 15:40:39 -04:00
|
|
|
#define wxFAIL
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Will always generate an assert error with specified message if this code is
|
|
|
|
reached (in debug mode).
|
|
|
|
|
|
|
|
This macro is useful for marking unreachable" code areas, for example it
|
|
|
|
may be used in the "default:" branch of a switch statement if all possible
|
|
|
|
cases are processed above.
|
|
|
|
|
2008-10-14 15:40:39 -04:00
|
|
|
This macro should be used to catch (in debug builds) logical errors done
|
|
|
|
by the programmer.
|
|
|
|
|
2008-03-14 23:14:51 -04:00
|
|
|
@see wxFAIL()
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
#define wxFAIL_MSG( message )
|
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the program is running under debugger, @false otherwise.
|
|
|
|
|
|
|
|
Please note that this function is currently only implemented for Win32 and
|
|
|
|
Mac builds using CodeWarrior and always returns @false elsewhere.
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
2008-03-08 08:52:38 -05:00
|
|
|
*/
|
2008-03-14 23:14:51 -04:00
|
|
|
bool wxIsDebuggerRunning();
|
|
|
|
|
|
|
|
/**
|
2009-03-21 19:36:37 -04:00
|
|
|
Sets the function to be called in case of assertion failure.
|
|
|
|
|
|
|
|
The default assert handler forwards to wxApp::OnAssertFailure() whose
|
|
|
|
default behaviour is, in turn, to show the standard assertion failure
|
|
|
|
dialog if a wxApp object exists or shows the same dialog itself directly
|
|
|
|
otherwise.
|
|
|
|
|
|
|
|
While usually it is enough -- and more convenient -- to just override
|
|
|
|
OnAssertFailure(), to handle all assertion failures, including those
|
|
|
|
occurring even before wxApp object creation of after its destruction you
|
|
|
|
need to provide your assertion handler function.
|
|
|
|
|
|
|
|
This function also provides a simple way to disable all asserts: simply
|
|
|
|
pass @NULL pointer to it. Doing this will result in not even evaluating
|
|
|
|
assert conditions at all, avoiding almost all run-time cost of asserts.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
2009-03-21 19:36:37 -04:00
|
|
|
Notice that this function is not MT-safe, so you should call it before
|
|
|
|
starting any other threads.
|
|
|
|
|
|
|
|
The return value of this function is the previous assertion handler. It can
|
|
|
|
be called after any pre-processing by your handler and can also be restored
|
|
|
|
later if you uninstall your handler.
|
|
|
|
|
|
|
|
@param handler
|
|
|
|
The function to call in case of assertion failure or @NULL.
|
|
|
|
@return
|
|
|
|
The previous assert handler which is not @NULL by default but could be
|
|
|
|
@NULL if it had been previously set to this value using this function.
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
@header{wx/debug.h}
|
2009-03-21 19:36:37 -04:00
|
|
|
*/
|
|
|
|
wxAssertHandler_t wxSetAssertHandler(wxAssertHandler_t handler);
|
2008-03-14 23:14:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
In debug mode (when @c __WXDEBUG__ is defined) this function generates a
|
|
|
|
debugger exception meaning that the control is passed to the debugger if
|
|
|
|
one is attached to the process. Otherwise the program just terminates
|
|
|
|
abnormally. In release mode this function does nothing.
|
|
|
|
|
|
|
|
@header{wx/debug.h}
|
|
|
|
*/
|
|
|
|
void wxTrap();
|
|
|
|
|
|
|
|
//@}
|
2008-03-08 08:52:38 -05:00
|
|
|
|