Share via


Debug Routines

With this version, Visual C++ introduces debug support for the C run-time library. The new debug version of the library supplies many diagnostic services that make debugging programs easier and allow developers to:

  • Step directly into run-time functions during debugging

  • Resolve assertions, errors, and exceptions

  • Trace heap allocations and prevent memory leaks

  • Report debug messages to the user

To use these routines, the _DEBUG flag must be defined. All of these routines do nothing in a retail build of an application. For more information on how to use the new debug routines, see Using C Run-Time Library Debugging Support.

Debug Versions of the C Run-time Library Routines

Routine Use
_ASSERT Evaluate an expression and generates a debug report when the result is FALSE
_ASSERTE Similar to _ASSERT, but includes the failed expression in the generated report
_CrtCheckMemory Confirm the integrity of the memory blocks allocated on the debug heap
_CrtDbgReport Generate a debug report with a user message and send the report to three possible destinations
_CrtDoForAllClientObjects Call an application-supplied function for all _CLIENT_BLOCK types on the heap
_CrtDumpMemoryLeaks Dump all of the memory blocks on the debug heap when a significant memory leak has occurred
_CrtIsValidHeapPointer Verify that a specified pointer is in the local heap
_CrtIsMemoryBlock Verify that a specified memory block is located within the local heap and that it has a valid debug heap block type identifier
_CrtIsValidPointer Verify that a specified memory range is valid for reading and writing
_CrtMemCheckpoint Obtain the current state of the debug heap and store it in an application-supplied _CrtMemState structure
_CrtMemDifference Compare two memory states for significant differences and return the results
_CrtMemDumpAllObjectsSince Dump information about objects on the heap since a specified checkpoint was taken or from the start of program execution
_CrtMemDumpStatistics Dump the debug header information for a specified memory state in a user-readable form
_CrtSetAllocHook Install a client-defined allocation function by hooking it into the C run-time debug memory allocation process
_CrtSetBreakAlloc Set a breakpoint on a specified object allocation order number
_CrtSetDbgFlag Retrieve or modify the state of the _crtDbgFlag flag to control the allocation behavior of the debug heap manager
_CrtSetDumpClient Install an application-defined function that is called every time a debug dump function is called to dump _CLIENT_BLOCK type memory blocks
_CrtSetReportFile Identify the file or stream to be used as a destination for a specific report type by _CrtDbgReport
_CrtSetReportHook Install a client-defined reporting function by hooking it into the C run-time debug reporting process
_CrtSetReportMode Specify the general destination(s) for a specific report type generated by _CrtDbgReport
_RPT[0,1,2,3,4] Track the application’s progress by generating a debug report by calling _CrtDbgReport with a format string and a variable number of arguments. Provides no source file and line number information.
_RPTF[0,1,2,3,4] Similar to the _RPTn macros, but provides the source file name and line number where the report request originated
_calloc_dbg Allocate a specified number of memory blocks on the heap with additional space for a debugging header and overwrite buffers
_expand_dbg Resize a specified block of memory on the heap by expanding or contracting the block
_free_dbg Free a block of memory on the heap
_malloc_dbg Allocate a block of memory on the heap with additional space for a debugging header and overwrite buffers
_msize_dbg Calculate the size of a block of memory on the heap
_realloc_dbg Reallocate a specified block of memory on the heap by moving and/or resizing the block

The debug routines can be used to step through the source code for most of the other C run-time routines during the debugging process. However, Microsoft considers some technology to be proprietary and, therefore, does not provide the source code for these routines. Most of these routines belong to either the exception handling or floating-point processing groups, but a few others are included as well. The following table lists these routines.

C Run-time Routines that are Not Available in Source Code Form

acos _fpclass _nextafter
asin _fpieee_flt pow
atan, atan2 _fpreset printf, wprintf1
_cabs frexp _scalb
ceil _hypot scanf, wscanf1
_chgsign _isnan setjmp
_clear87, _clearfp _j0 sin
_control87, _controlfp _j1 sinh
_copysign _jn sqrt
cos ldexp _status87, _statusfp
cosh log tan
exp log10 tanh
fabs _logb _y0
_finite longjmp _y1
floor _matherr _yn
fmod modf

1   Although source code is available for most of this routine, it makes an internal call to another routine for which source code is not provided.

Some C run-time functions and C++ operators behave differently when called from a debug build of an application. (Note that a debug build of an application can be done by either defining the _DEBUG flag or by linking with a debug version of the C run-time library.) The behavioral differences usually consist of extra features or information provided by the routine to support the debugging process. The following table lists these routines.

Routines that Behave Differently in a Debug Build of an Application

C abort routine C++ delete operator
C assert routine C++ new operator

For more information about using the debug versions of the C++ operators in the preceding table, see Using the Debug Heap from C++.