Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

Tools

Introduction to Power Debugging


Debugger Feature: Custom Debug Extensions

The Microsoft debuggers have an SDK that allows you to write your own debug extension. The extension simply exports debug commands and the debugger will pass your function the parameters entered by the user. The extensions are provided with APIs that allow it to read from and write to the memory in the process being debugged. They are also provided an API to write text out to the debug window.

In the past, the majority of debug extensions were written to simply dump the contents of data structures in a readable format. This use has all but disappeared with the addition of the dt command and structural information in the PDB symbol files. The dt command provides the ability to dump data structures that are contained in the PDB files. The PDBs provided by the Microsoft symbol server even contain a lot of the internal data structures in Windows. The use of PDBs for this purpose is better since structural information would be automatically updated each build rather than requiring you to modify your extension when the structure changes.

The command set of the debugger itself has also become richer, which makes debug extensions less necessary. Even so, there are still use cases for the debug extension and I will demonstrate a few. I will not go into any details of how to write a debug extension but an article on how to do this can be found at the following URL: http://www.codeproject.com/debug/cdbntsd4.asp.

Injecting & Extracting Binary Data

I was once debugging an application that wasn't properly displaying a bitmap. The problem was that the bitmap was received from the network or from a device and was only visible in the memory space of the process. I could have of course attempted to modify the code and write the bitmap to disk. The problem is that a lot of the code was also contained in a library that I did not have the source for. I still could modify the source to read and write to the disk, but I thought of another option that would be more dynamic and reusable.

That other option was to write a debug extension that had the ability to inject binary data into a process as well as extract it. This debug extension could then be used in other cases as a general solution while modifying just this code could not. I was able to extract the bitmap from memory and display it in another image viewer. I was also able to inject other bitmaps into the memory space overwriting that bitmap for use by the application.

This feature does have many other uses such as exporting data to files for binary comparison, extracting files that exist in memory only and the like. I have not included a demonstration, however the source code for the included debug extension includes !importfile and !exportfile for experimentation and modification.


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.