Services de diagnostic
The Microsoft Foundation Class Library supplies many diagnostic services that make debugging your programs easier. These diagnostic services include macros and global functions that allow you to track your program's memory allocations, dump the contents of objects during run time, and print debugging messages during run time. The macros and global functions for diagnostic services are grouped into the following categories:
General diagnostic macros
General diagnostic functions and variables
Object diagnostic functions
These macros and functions are available for all classes derived from CObject in the Debug and Release versions of MFC. However, all except DEBUG_NEW and VERIFY do nothing in the Release version.
In the Debug library, all allocated memory blocks are bracketed with a series of "guard bytes." If these bytes are disturbed by an errant memory write, then the diagnostic routines can report a problem. If you include the line:
#define new DEBUG_NEW
in your implementation file, all calls to new will store the filename and line number where the memory allocation took place. The function CMemoryState::DumpAllObjectsSince will display this extra information, allowing you to identify memory leaks. Refer also to the class CDumpContext for additional information on diagnostic output.
In addition, the C run-time library also supports a set of diagnostic functions you can use to debug your applications. For more information, see Debug Routines in the Run-Time Library Reference.
MFC General Diagnostic Macros
Prints a message and then aborts the program if the specified expression evaluates to FALSE in the Debug version of the library. |
|
Tests that an object is an object of the specified class or of a class derived from the specified class. |
|
Tests the internal validity of an object by calling its AssertValid member function; typically overridden from CObject. |
|
Supplies a filename and line number for all object allocations in Debug mode to help find memory leaks. |
|
Similar to ASSERT but does not test the value of the expression; useful for code that should execute only in Debug mode. |
|
Provides printf-like capability in the Debug version of the library. |
|
Similar to ASSERT but evaluates the expression in the Release version of the library as well as in the Debug version. |
MFC General Diagnostic Variables and Functions
Global variable that sends CDumpContext information to the debugger output window or to the debug terminal. |
|
Global variable that controls the behavior of the debugging memory allocator. |
|
Global variable used to test the passed SCODE to see if it is an error and, if so, throws the appropriate error. |
|
Checks the integrity of all currently allocated memory. |
|
If called while in the debugger, dumps the state of an object while debugging. |
|
Generate an image of the current stack. This function is always linked statically. |
|
Enables the memory leak dump. |
|
Turns memory tracking on and off. |
|
Verifies that a memory block has been properly allocated. |
|
Verifies that a memory address range is within the program's bounds. |
|
Determines whether a pointer to a string is valid. |
|
Enables the calling of a function on each memory allocation. |
MFC Object Diagnostic Functions
Performs a specified function on all CObject-derived classes that support run-time type checking. |
|
Performs a specified function on all CObject-derived objects that were allocated with new. |