Catch C/C++ Errors Early with VSTS Code Verifier

For a native C++ developer, VSTS Developer Edition provides support throughout the development cycle. From VSTS source annotations that enable you to annotate methods with the valid pre- and post-conditions of method parameters (and have the compiler warn you when the annotations are violated) through static code analysis and unit testing, VSTS provides a huge range of functionality that helps the native developer. This article looks at the VSTS Verifier, an analysis tool that monitors unmanaged code as it executes, and detects errors related to incorrect memory, lock, and handle usage.

My previous static code analysis article showed how some types of application errors can be detected by parsing the source code. However, the effectiveness of static code analysis is limited because interaction with black-box systems (such as third-party components and Windows DLLs) makes determining all the possible invalid states that an application can get into impossible.

In contrast, dynamic analysis inspects the values of key variables passed to various system functions to detect problems. While the method being called will detect some invalid parameters and report them via error conditions, some problems can go undetected when the invalid parameter is used. In that case, the symptoms of the problem will show up only much later as corrupt memory and unexpected application terminations.

Getting Started with the Application Verifier

Starting the Application Verifier is a simple matter. Just choose Debug | Start With Application Verifier, as shown in Figure 1.

Figure 1. Starting the Application Verifier

The first time you use the Application Verifier, Visual Studio will prompt you to download an additional DLL that allows handle and heap inspection through documented interfaces. For users in controlled environments that may need operations staff approval for patch installation, this Microsoft Knowledge Base article describes the files included in the Windows update.

For most users of the Application Verifier, the most difficult requirement is remembering to start the Verifier rather than launching a standard debugging session. Given that standard debugging functionality is available when using the Verifier, it is worth swapping the default shortcut keys for starting a debug session (F5) with the keys for starting a Verifier session (Shift+Alt+F5). This way, the power of the Verifier will be automatically utilized every time a debugging session occurs.

When the Application Verifier detects a problem, it halts execution and displays a dialog like that shown in Figure 2.

Figure 2. Verifier Stop Message

Diagnosing the problem hopefully will be a simple matter of looking at the history of the handle, lock, or heap pointer that caused the Verifier to stop execution, and working back to a point in time when the corruption occurred. While this isn't always the easiest debugging task, it beats starting the debugging process further downstream where heap or file corruption is the only symptom of a problem.

When the Verifier halts execution, a detailed description of the problem is also added to the task view, as shown in Figure 3. The information in the task view can be very handy, as the dialog shown in Figure 2 needs to be dismissed before the developer can jump into the debugger and start inspecting variable values.

Figure 3. Verifier Tasks List View

In addition to the Task List information, a separate Application Verifier window provides the most detailed information on the stop event (see Figure 4).

Figure 4. Verifier Window

The Application Verifier Checks

The VSTS Application Verifier focuses on three core areas: operating system handles, locks, and heap memory. Of these three types of check, handles are the simplest—Application Verifier checks to ensure that the handle is not null; the handle points to the correct operating system object type; and the handle is not used in a wait operation in the DllMain function, which is a sure recipe for deadlocks.

Lock checks include the following:

  • Checks for under and over initialization
  • Freeing of memory or unloading of modules that are holding a lock
  • Locks with invalid owners
  • Corrupt locks

The heap checks follow a similar pattern to the other two verifier targets, with checks on heap corruptions, invalid heap deletions, invalid heap handles, and heap overruns.

Configuring the Application Verifier

The configuration options for the Application Verifier are fairly minimal, as Figure 5 shows.

Figure 5. Verifier Configuration

Apart from being able to turn the three main verification features on or off, you can use the heap verification with or without guard pages (guard pages provide the earliest detection of corruption at the expense of taking up more memory) and the location of the heap guard page. The default location of the heap guard page is at the end of an allocation, which will detect buffer overruns. However, you can move this to the beginning of the allocation block if you need to detect the much-rarer buffer under-runs.

What Are You Waiting For?

The Application Verifier is one of the easiest VSTS tools to gets into—simply choose a different menu option to begin your debugging session, and let the Verifier share the hard work of tracking down some of those nasty native code problems.

About the Author

Nick Wienholt is an independent Windows and .NET consultant based in Sydney, Australia. He is the author of Maximizing .NET Performance from Apress, and specializes in system-level software architecture and development with a particular focus on performance, security, interoperability, and debugging. Nick can be reached at


  • Wholesale Oakley Jury sale for cheap

    Posted by nnzsaarip on 07/08/2013 01:15am

    Fake RayBans ,The amalgamation of the most comprehensive eye care products on the globe, Oakley sunglasses sale, a new without any the oldest and the majority well-known and the majority respected medical care brands. Wear OAKLEY sun screen lotion within the appropriate forum, our initial talk of the reason why you wish to opt for a different tag Oakley sunglasses. Oakley sunglasses defensive glasses varieties use a the CLOS tendency in order to avoid the interest with the area, prevent stamping eye particles, water, or substance. Cheap Oakley Radarlock Sunglasses ,Oakley is usually a gift of the perfect man and woman. Many of these are popular on the planet. Oakley on demand can often be in the market to upgrade. It is possible to difference between and ordinary OAKLEY sunglasses discount? This is a a number of sizes, shapes and designs to show off your attitude, discussing with you, in order to echo your personality. People always want to buy good quality, though the low discount prices. How should we go with a two of their own model of sunglasses? If you find the glasses frame distortion, sagging dashing towards dealer for a free adjustment or lens clarity affected. Fake Oakley Sunglasses ,At the beach or sailing: you can find a broad building or housing to close sunlight and the sky, not many folks are facing a 1 hour, and from the reflection of diffuse radiation beyond just the water within the entire sky. We are often up against the diffusion of pollutants, almost greatly ultraviolet atmosphere, totally like, like us from your sun. Fake Ray Ban ,Product design or selection of materials, is a huge number of advanced scientific experiments and testing to be sure the comfort and high-quality, advanced of integration and functionality and fashion. Brand the foundation with the story provides the Oakley's rich breath of life, its culture and outlook on life was deeply moved. Porte Monnai Sac Longchamp ,Eyeshades you will not be strange in point of fact could be the first step toward the main invention, the use of innovative technology to offer a glasses consist of the standard accessories for major items of equipment. Most girls are usually for example the development sari, related to the protection of the style recognize a brandname image in addition to Oakley sunglasses cheap teenager be aware that this manufacturer. Do you need prescription sunglasses or just want quality accessories to be sure you get what you purchase, you'll find those that offer online Oakley suppliers.

  • test

    Posted by chelaruvalentin on 10/17/2008 12:02pm


    • reply

      Posted by chelaruvalentin on 10/17/2008 12:18pm


Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Entire organizations suffer when their networks can't keep up and new opportunities are put on hold. Waiting on service providers isn't good business. In these examples, learn how to simplify network management so that your organization can better manage costs, adapt quickly to business demands, and seize market opportunities when they arise.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date