May 6, 2012

Guide to create Windbg extension in Visual Studio 2010

I'm describing a way to create an extension for Windbg in Visual Studio 2010 Express. The description is applied for the 32-bit version of Windows debugger but the same steps could be easily adopted for the 64-bit debugger. If you're not interested in setting up a Visual Studio configuration, but want a sample extension, you can download one from CodePlex. That one was created using the steps below.

Create an Empty Visual C++ Project and save the solution as sampext. Add sampext.cpp to the project with the following content.
#include "sampext.h"


Add sampext.h to the project with the following content.
#pragma once
#include "engextcpp.hpp"

class EXT_CLASS : public ExtExtension

Add ver.cpp to the project file with the following content. This file contains the implementation of the sample command.
#include "ver.h"

            "Shows version number of the extension.\n",
    g_Ext->Out("Sample Windbg Extension in Visual Studio v0.1\n");
Add ver.h, too.
#pragma once

#include "sampext.h"
Add sampext.def that is the definition file.

; Core exports provided by the ExtCpp framework.


; Extension commands.

Create a folder called sdk in the solution folder.

Copy the inc and lib folders from the sdk folder of Windbg to the sdk folder of the solution.

Set the configuration type of the project to Dynamic Library DLL.

Add $(SolutionDir)sdk\inc to the additional include directories.

Add $(SolutionDir)sdk\lib\i386 to the additional library dependencies.

Add engextcpp.lib to the additional dependencies in the linker input.

Set up the module definition file to samplext.def in the linker input.

The extension is now ready to be built.
  This blog is written and maintained by Attila Suszter. Read in Feed Reader.