Debug Hook Function Writing

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2019. Download it here

This section describes a number of custom debug hook functions you can write that allow you to insert your code into some predefined points inside the debugger's normal processing.

In This Section

Client Block Hook Functions
Provides guidance and a prototype for writing functions that validate or report the contents of the data stored in _CLIENT_BLOCK blocks.

Allocation Hook Functions
Defines an allocation hook function, explores its different uses, points out restrictions, and provides a prototype.

Allocation Hooks and CRT Memory Allocations
Describes the restriction on allocation hook functions of explicitly ignoring _CRT_BLOCK blocks if they make any calls to C run-time library functions that allocate internal memory. This topic also lists the consequences if your allocation hook does not ignore _CRT_BLOCK blocks (with examples) and how to change the default allocation hook function, CrtDefaultAllocHook.

Report Hook Functions
Discusses _CrtSetReportHook, which you can use to filter reports to focus on specific types of allocations. This topic also provides a prototype.

CRT Debugging Techniques
Links to debugging techniques for the C Run-Time Library, including using the CRT Debug Library, macros for reporting, differences between malloc and _malloc_dbg, writing debug hook functions, and the CRT debug heap.