2008-03-08 13:52:38 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: memory.h
|
2008-10-11 13:10:48 +00:00
|
|
|
// Purpose: interface of wxDebugContext
|
2008-03-08 13:52:38 +00:00
|
|
|
// Author: wxWidgets team
|
|
|
|
// RCS-ID: $Id$
|
|
|
|
// Licence: wxWindows license
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
|
|
|
@class wxDebugContext
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-11 13:10:48 +00:00
|
|
|
A class for performing various debugging and memory tracing operations.
|
|
|
|
|
|
|
|
Full functionality (such as printing out objects currently allocated) is
|
|
|
|
only present in a debugging build of wxWidgets, i.e. if the __WXDEBUG__
|
|
|
|
symbol is defined. wxDebugContext and related functions and macros can be
|
|
|
|
compiled out by setting wxUSE_DEBUG_CONTEXT to 0 is setup.h
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
@library{wxbase}
|
|
|
|
@category{debugging}
|
2008-03-08 14:43:31 +00:00
|
|
|
|
2008-10-11 13:10:48 +00:00
|
|
|
@see @ref overview_debugging
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-08 14:43:31 +00:00
|
|
|
class wxDebugContext
|
2008-03-08 13:52:38 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
Checks the memory blocks for errors, starting from the currently set
|
|
|
|
checkpoint.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return Returns the number of errors, so a value of zero represents
|
2008-10-11 13:10:48 +00:00
|
|
|
success. Returns -1 if an error was detected that prevents
|
|
|
|
further checking.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-28 15:36:26 +00:00
|
|
|
static int Check(bool checkAll = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Performs a memory dump from the currently set checkpoint, writing to the
|
|
|
|
current debug stream. Calls the @b Dump member function for each wxObject
|
|
|
|
derived instance.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-05-11 01:38:53 +00:00
|
|
|
@return @true if the function succeeded, @false otherwise.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static bool Dump();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Returns @true if the memory allocator checks all previous memory blocks for
|
|
|
|
errors.
|
2008-10-11 13:10:48 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
By default, this is @false since it slows down execution considerably.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see SetCheckPrevious()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static bool GetCheckPrevious();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Returns @true if debug mode is on.
|
|
|
|
|
|
|
|
If debug mode is on, the wxObject new and delete operators store or use
|
|
|
|
information about memory allocation. Otherwise, a straight malloc and
|
|
|
|
free will be performed by these operators.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see SetDebugMode()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static bool GetDebugMode();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Gets the debug level (default 1).
|
|
|
|
|
|
|
|
The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
|
|
|
|
macro to specify how detailed the trace information is; setting a
|
|
|
|
different level will only have an effect if trace statements in the
|
|
|
|
application specify a value other than one.
|
|
|
|
|
|
|
|
@deprecated
|
2008-03-08 13:52:38 +00:00
|
|
|
This is obsolete, replaced by wxLog functionality.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see SetLevel()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static int GetLevel();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Prints a list of the classes declared in this application, giving derivation
|
|
|
|
and whether instances of this class can be dynamically created.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see PrintStatistics()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static bool PrintClasses();
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Performs a statistics analysis from the currently set checkpoint, writing
|
|
|
|
to the current debug stream. The number of object and non-object
|
|
|
|
allocations is printed, together with the total size.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param detailed
|
2008-10-11 13:10:48 +00:00
|
|
|
If @true, the function will also print how many objects of each class
|
|
|
|
have been allocated, and the space taken by these class instances.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see PrintStatistics()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static bool PrintStatistics(bool detailed = true);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Tells the memory allocator to check all previous memory blocks for errors.
|
|
|
|
By default, this is @false since it slows down execution considerably.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see GetCheckPrevious()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static void SetCheckPrevious(bool check);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
Sets the current checkpoint: Dump and PrintStatistics operations will
|
|
|
|
be performed from this point on. This allows you to ignore allocations
|
|
|
|
that have been performed up to this point.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-08 14:43:31 +00:00
|
|
|
@param all
|
2008-10-11 13:10:48 +00:00
|
|
|
If @true, the checkpoint is reset to include all memory allocations
|
|
|
|
since the program started.
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static void SetCheckpoint(bool all = false);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Sets the debug mode on or off.
|
|
|
|
|
|
|
|
If debug mode is on, the wxObject new and delete operators store or use
|
|
|
|
information about memory allocation. Otherwise, a straight malloc and free
|
|
|
|
will be performed by these operators.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
By default, debug mode is on if __WXDEBUG__ is defined. If the application
|
|
|
|
uses this function, it should make sure that all object memory allocated
|
2008-10-11 13:10:48 +00:00
|
|
|
is deallocated with the same value of debug mode. Otherwise, the delete
|
|
|
|
operator might try to look for memory information that does not exist.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see GetDebugMode()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static void SetDebugMode(bool debug);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Sets the debug level (default 1).
|
|
|
|
|
|
|
|
The debug level is used by the wxTraceLevel function and the WXTRACELEVEL
|
|
|
|
macro to specify how detailed the trace information is; setting
|
2008-03-08 13:52:38 +00:00
|
|
|
a different level will only have an effect if trace statements in the
|
2008-10-11 13:10:48 +00:00
|
|
|
application specify a value other than one.
|
|
|
|
|
|
|
|
@deprecated
|
2008-03-08 13:52:38 +00:00
|
|
|
This is obsolete, replaced by wxLog functionality.
|
2008-03-20 13:45:17 +00:00
|
|
|
|
2008-03-09 12:33:59 +00:00
|
|
|
@see GetLevel()
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static void SetLevel(int level);
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-10-11 13:10:48 +00:00
|
|
|
Installs a function to be called at the end of wxWidgets shutdown.
|
|
|
|
It will be called after all files with global instances of
|
|
|
|
wxDebugContextDumpDelayCounter have run their destructors.
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
The shutdown function must be take no parameters and return nothing.
|
|
|
|
*/
|
2008-10-13 13:24:43 +00:00
|
|
|
static void SetShutdownNotifyFunction(wxShutdownNotifyFunction func);
|
2008-03-08 13:52:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-03-10 15:24:38 +00:00
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
// ============================================================================
|
|
|
|
// Global functions/macros
|
|
|
|
// ============================================================================
|
|
|
|
|
2009-01-05 20:48:06 +00:00
|
|
|
/** @addtogroup group_funcmacro_log */
|
2008-03-23 06:25:01 +00:00
|
|
|
//@{
|
|
|
|
|
2008-03-08 13:52:38 +00:00
|
|
|
/**
|
2008-03-23 06:25:01 +00:00
|
|
|
@deprecated Use one of the wxLogTrace() functions or one of the
|
|
|
|
wxVLogTrace() functions instead.
|
|
|
|
|
|
|
|
Calls wxTrace() with printf-style variable argument syntax. Output is
|
|
|
|
directed to the current output stream (see wxDebugContext).
|
|
|
|
|
|
|
|
@header{wx/memory.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-23 06:25:01 +00:00
|
|
|
#define WXTRACE(format, ...)
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-23 06:25:01 +00:00
|
|
|
@deprecated Use one of the wxLogTrace() functions or one of the
|
|
|
|
wxVLogTrace() functions instead.
|
|
|
|
|
|
|
|
Calls wxTraceLevel with printf-style variable argument syntax. Output is
|
|
|
|
directed to the current output stream (see wxDebugContext). The first
|
|
|
|
argument should be the level at which this information is appropriate. It
|
|
|
|
will only be output if the level returned by wxDebugContext::GetLevel is
|
|
|
|
equal to or greater than this value.
|
|
|
|
|
|
|
|
@header{wx/memory.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-23 06:25:01 +00:00
|
|
|
#define WXTRACELEVEL(level, format, ...)
|
2008-03-08 13:52:38 +00:00
|
|
|
|
|
|
|
/**
|
2008-03-23 06:25:01 +00:00
|
|
|
@deprecated Use one of the wxLogTrace() functions or one of the
|
|
|
|
wxVLogTrace() functions instead.
|
|
|
|
|
|
|
|
Takes printf-style variable argument syntax. Output is directed to the
|
|
|
|
current output stream (see wxDebugContext).
|
|
|
|
|
|
|
|
@header{wx/memory.h}
|
2008-03-08 13:52:38 +00:00
|
|
|
*/
|
2008-03-23 06:25:01 +00:00
|
|
|
void wxTrace(const wxString& format, ...);
|
|
|
|
|
|
|
|
/**
|
|
|
|
@deprecated Use one of the wxLogTrace() functions or one of the
|
|
|
|
wxVLogTrace() functions instead.
|
|
|
|
|
|
|
|
Takes @e printf() style variable argument syntax. Output is directed to the
|
|
|
|
current output stream (see wxDebugContext). The first argument should be
|
|
|
|
the level at which this information is appropriate. It will only be output
|
|
|
|
if the level returned by wxDebugContext::GetLevel() is equal to or greater
|
|
|
|
than this value.
|
|
|
|
|
|
|
|
@header{wx/memory.h}
|
|
|
|
*/
|
|
|
|
void wxTraceLevel(int level, const wxString& format, ...);
|
|
|
|
|
|
|
|
//@}
|
2008-03-08 13:52:38 +00:00
|
|
|
|