Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Debug Routines

The debug version of the C run-time 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 CRT Debugging Techniques.

Debug Versions of the C Run-Time Library Routines

Routine

Use

.NET Framework equivalent

_ASSERT

Evaluate an expression and generates a debug report when the result is FALSE

System::Diagnostics::Debug::Assert

_ASSERTE

Similar to _ASSERT, but includes the failed expression in the generated report

System::Diagnostics::Debug::Assert

_CrtCheckMemory

Confirm the integrity of the memory blocks allocated on the debug heap

System::Diagnostics::PerformanceCounter

_CrtDbgBreak

Sets a break point.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtDbgReport, _CrtDbgReportW

Generate a debug report with a user message and send the report to three possible destinations

System::Diagnostics::Debug::Write, System::Diagnostics::Debug::Writeline, System::Diagnostics::Debug::WriteIf, System::Diagnostics::Debug::WriteLineIf

_CrtDoForAllClientObjects

Call an application-supplied function for all _CLIENT_BLOCK types on the heap

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtDumpMemoryLeaks

Dump all of the memory blocks on the debug heap when a significant memory leak has occurred

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtIsMemoryBlock

Verify that a specified memory block is located within the local heap and that it has a valid debug heap block type identifier

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtIsValidHeapPointer

Verifies that a specified pointer is in the local heap

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtIsValidPointer

Verify that a specified memory range is valid for reading and writing

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtMemCheckpoint

Obtain the current state of the debug heap and store it in an application-supplied _CrtMemState structure

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtMemDifference

Compare two memory states for significant differences and return the results

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtMemDumpAllObjectsSince

Dump information about objects on the heap since a specified checkpoint was taken or from the start of program execution

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtMemDumpStatistics

Dump the debug header information for a specified memory state in a user-readable form

System::Diagnostics::PerformanceCounter

_CrtReportBlockType

Returns the block type/subtype associated with a given debug heap block pointer.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetAllocHook

Install a client-defined allocation function by hooking it into the C run-time debug memory allocation process

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetBreakAlloc

Set a breakpoint on a specified object allocation order number

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetDbgFlag

Retrieve or modify the state of the _crtDbgFlag flag to control the allocation behavior of the debug heap manager

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetDumpClient

Install an application-defined function that is called every time a debug dump function is called to dump _CLIENT_BLOCK type memory blocks

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetReportFile

Identify the file or stream to be used as a destination for a specific report type by _CrtDbgReport

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetReportHook

Install a client-defined reporting function by hooking it into the C run-time debug reporting process

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetReportHook2, _CrtSetReportHookW2

Installs or uninstalls a client-defined reporting function by hooking it into the C run-time debug reporting process.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_CrtSetReportMode

Specify the general destination(s) for a specific report type generated by _CrtDbgReport

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_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.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_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

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_calloc_dbg

Allocate a specified number of memory blocks on the heap with additional space for a debugging header and overwrite buffers

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_expand_dbg

Resize a specified block of memory on the heap by expanding or contracting the block

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_free_dbg

Free a block of memory on the heap

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_fullpath_dbg, _wfullpath_dbg

Create an absolute or full path name for the specified relative path name, using _malloc_dbg to allocate memory.

System::IO::File::Create

_getcwd_dbg, _wgetcwd_dbg

Get the current working directory, using _malloc_dbg to allocate memory.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_malloc_dbg

Allocate a block of memory on the heap with additional space for a debugging header and overwrite buffers

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_msize_dbg

Calculate the size of a block of memory on the heap

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_realloc_dbg

Reallocate a specified block of memory on the heap by moving and/or resizing the block

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

_strdup_dbg, _wcsdup_dbg

Duplicates a string, using _malloc_dbg to allocate memory.

System::String::Clone

_tempnam_dbg, _wtempnam_dbg

Generate names you can use to create temporary files, using _malloc_dbg to allocate memory.

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

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

*   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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.