调试例程Debug Routines

C 运行时库的调试版本提供了很多诊断服务,便于调试程序并允许开发人员执行以下操作: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

    若要使用这些例程,必须定义 _DEBUG 标志。To use these routines, the _DEBUG flag must be defined. 所有这些例程在零售版本的应用程序中不执行任何操作。All of these routines do nothing in a retail build of an application. 有关如何使用新的调试例程的详细信息,请参阅 CRT 调试技术For more information on how to use the new debug routines, see CRT Debugging Techniques.

C 运行时库例程的调试版本Debug Versions of the C Run-Time Library Routines

例程所返回的值Routine 使用Use
_ASSERT_ASSERT 计算表达式,并在结果是 FALSE 时生成调试报告Evaluate an expression and generates a debug report when the result is FALSE
_ASSERTE_ASSERTE 类似于 _ASSERT,但包括生成报告中的失败表达式Similar to _ASSERT, but includes the failed expression in the generated report
_CrtCheckMemory_CrtCheckMemory 确认在调试堆上分配的内存块的完整性Confirm the integrity of the memory blocks allocated on the debug heap
_CrtDbgBreak_CrtDbgBreak 设置一个断点。Sets a break point.
_CrtDbgReport、_CrtDbgReportW_CrtDbgReport, _CrtDbgReportW 生成具有用户消息的调试报表并将此报表发送到三个可能的目标Generate a debug report with a user message and send the report to three possible destinations
_CrtDoForAllClientObjects_CrtDoForAllClientObjects 为堆中的所有 _CLIENT_BLOCK 类型调用应用程序提供的函数Call an application-supplied function for all _CLIENT_BLOCK types on the heap
_CrtDumpMemoryLeaks_CrtDumpMemoryLeaks 发生了大量内存泄漏时转储调试堆上的所有内存块Dump all of the memory blocks on the debug heap when a significant memory leak has occurred
_CrtIsMemoryBlock_CrtIsMemoryBlock 确认指定的内存块位于本地堆,并且具有有效的调试堆块类型标识符Verify that a specified memory block is located within the local heap and that it has a valid debug heap block type identifier
_CrtIsValidHeapPointer_CrtIsValidHeapPointer 验证指定的指针是否位于本地堆中Verifies that a specified pointer is in the local heap
_CrtIsValidPointer_CrtIsValidPointer 验证指定的内存范围对于读取和写入是否有效Verify that a specified memory range is valid for reading and writing
_CrtMemCheckpoint_CrtMemCheckpoint 获取调试堆的当前状态并将其存储在应用程序提供的 _CrtMemState 结构中Obtain the current state of the debug heap and store it in an application-supplied _CrtMemState structure
_CrtMemDifference_CrtMemDifference 比较两个内存状态的重要差异,并返回结果Compare two memory states for significant differences and return the results
_CrtMemDumpAllObjectsSince_CrtMemDumpAllObjectsSince 在提取指定检查点之后或者在开始执行程序时转储堆上的有关对象的信息Dump information about objects on the heap since a specified checkpoint was taken or from the start of program execution
_CrtMemDumpStatistics_CrtMemDumpStatistics 以用户可读的形式转储指定内存状态的调试标头信息Dump the debug header information for a specified memory state in a user-readable form
_CrtReportBlockType_CrtReportBlockType 返回与给定调试堆块指针相关联的块类型/子类型。Returns the block type/subtype associated with a given debug heap block pointer.
_CrtSetAllocHook_CrtSetAllocHook 通过挂钩到 C 运行时调试内存分配过程安装客户端定义的分配函数Install a client-defined allocation function by hooking it into the C run-time debug memory allocation process
_CrtSetBreakAlloc_CrtSetBreakAlloc 在指定的对象分配序号上设置断点Set a breakpoint on a specified object allocation order number
_CrtSetDbgFlag_CrtSetDbgFlag 检索或修改 _crtDbgFlag 标志的状态,以控制调试堆管理器的分配行为Retrieve or modify the state of the _crtDbgFlag flag to control the allocation behavior of the debug heap manager
_CrtSetDumpClient_CrtSetDumpClient 安装每次调用调试转储函数来转储 _CLIENT_BLOCK 类型内存块时所调用的应用程序定义的函数Install an application-defined function that is called every time a debug dump function is called to dump _CLIENT_BLOCK type memory blocks
_CrtSetReportFile_CrtSetReportFile 标识被 _CrtDbgReport 用作特定报表类型的目标的文件或流Identify the file or stream to be used as a destination for a specific report type by _CrtDbgReport
_CrtSetReportHook_CrtSetReportHook 通过以下方式安装客户端定义的报告函数:将该函数挂钩到 C 运行时调试报告过程中Install a client-defined reporting function by hooking it into the C run-time debug reporting process
_CrtSetReportHook2、_CrtSetReportHookW2_CrtSetReportHook2, _CrtSetReportHookW2 通过以下方式安装或卸载客户端定义的报告函数:将该函数挂钩到 C 运行时调试报告过程中。Installs or uninstalls a client-defined reporting function by hooking it into the C run-time debug reporting process.
_CrtSetReportMode_CrtSetReportMode 指定由 _CrtDbgReport 生成的特定报表类型的一般目标Specify the general destination(s) for a specific report type generated by _CrtDbgReport
_RPT[0,1,2,3,4]_RPT[0,1,2,3,4] 通过调用带格式字符串和可变数量参数的 _CrtDbgReport 生成调试报表来跟踪应用程序的进度。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]_RPTF[0,1,2,3,4] 类似于 _RPTn 宏,但提供发起报表请求的源文件名和行号Similar to the _RPTn macros, but provides the source file name and line number where the report request originated
_calloc_dbg_calloc_dbg 在具有额外空间的堆中为调试标头和覆盖缓冲区分配指定数量的内存块Allocate a specified number of memory blocks on the heap with additional space for a debugging header and overwrite buffers
_expand_dbg_expand_dbg 通过展开或收缩块调整堆上指定内存块的大小Resize a specified block of memory on the heap by expanding or contracting the block
_free_dbg_free_dbg 释放堆上的内存块Free a block of memory on the heap
_fullpath_dbg、_wfullpath_dbg_fullpath_dbg, _wfullpath_dbg 创建指定相对路径名称的绝对或完整路径名称,使用 _malloc_dbg 来分配内存。Create an absolute or full path name for the specified relative path name, using _malloc_dbg to allocate memory.
_getcwd_dbg、_wgetcwd_dbg_getcwd_dbg, _wgetcwd_dbg 获取当前工作目录,使用 _malloc_dbg 来分配内存。Get the current working directory, using _malloc_dbg to allocate memory.
_malloc_dbg_malloc_dbg 在具有额外空间的堆中为调试标头和覆盖缓冲区分配内存块Allocate a block of memory on the heap with additional space for a debugging header and overwrite buffers
_msize_dbg_msize_dbg 计算堆上的内存块大小Calculate the size of a block of memory on the heap
_realloc_dbg_realloc_dbg 通过移动和/或调整块的大小重新分配堆上的指定内存块Reallocate a specified block of memory on the heap by moving and/or resizing the block
_strdup_dbg、_wcsdup_dbg_strdup_dbg, _wcsdup_dbg 复制字符串,使用 _malloc_dbg 来分配内存。Duplicates a string, using _malloc_dbg to allocate memory.
_tempnam_dbg、_wtempnam_dbg_tempnam_dbg, _wtempnam_dbg 生成可用于创建临时文件的名称,使用 _malloc_dbg 来分配内存。Generate names you can use to create temporary files, using _malloc_dbg to allocate memory.

可以使用调试例程逐步完成调试过程中大部分其他 C 运行时例程的源代码。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. 但是,Microsoft 认为一些技术是专有的,因此,不会为这些例程提供源代码。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 运行时例程C Run-Time Routines That Are Not Available in Source Code Form

acos、acosf、acoslacos, acosf, acosl _fpclass_fpclass _nextafter_nextafter
asinasin _fpieee_flt_fpieee_flt powpow
atan、atan2atan, atan2 _fpreset_fpreset printf、_printf_l、wprintf、_wprintf_lprintf_s、_printf_s_l、wprintf_s、_wprintf_s_lprintf, _printf_l, wprintf, _wprintf_l, printf_s, _printf_s_l, wprintf_s, _wprintf_s_l
_cabs_cabs frexpfrexp _scalb_scalb
ceilceil _hypot_hypot scanf、_scanf_l、wscanf、_wscanf_lscanf_s、_scanf_s_l、wscanf_s、_wscanf_s_lscanf, _scanf_l, wscanf, _wscanf_l, scanf_s, _scanf_s_l, wscanf_s, _wscanf_s_l
_chgsign、_chgsignf、_chgsignl_chgsign, _chgsignf, _chgsignl _isnan_isnan setjmpsetjmp
_clear87、_clearfp_clear87, _clearfp _j0_j0 sinsin
_control87、_controlfp、__control87_2_control87, _controlfp, __control87_2 _j1_j1 sinhsinh
copysign、copysignf、copysignl、_copysign、_copysignf、_copysignlcopysign, copysignf, copysignl, _copysign, _copysignf, _copysignl _jn_jn sqrtsqrt
coscos ldexpldexp _status87、_statusfp_status87, _statusfp
coshcosh loglog tantan
ExpExp log10log10 tanhtanh
fabsfabs _logb_logb _y0_y0
_finite_finite longjmplongjmp _y1_y1
floorfloor _matherr_matherr _yn_yn
fmodfmod modfmodf

* 尽管为大部分此例程提供源代码,它仍会对另一个不提供源代码的例程执行内部调用。* 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.

从应用程序的调试版本执行调用时,某些 C 运行时函数和 C++ 运算符存在行为差异。Some C run-time functions and C++ operators behave differently when called from a debug build of an application. (请注意,应用程序的调试版本可以通过定义 _DEBUG 标志或与 C 运行时库的调试版本进行链接来完成。)行为差异通常包含由例程提供的额外功能或信息,以支持调试过程。(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 例程C abort routine C++ delete 运算符C++ delete operator
Cassert 例程C assert routine C++ new 运算符C++ new operator

请参阅See Also

按类别分的运行时例程 Run-Time Routines by Category
运行时错误检查Run-Time Error Checking