Defrag Tools #105 - Writing a Debugger Extension Part 9

Sign in to queue

Description

In this episode of Defrag Tools, Andrew Richards and Chad Beeder finish a series on writing a Debugger Extension for the Debugging Tools for Windows. The series is based on a 3 part MSDN Magazine series that Andrew wrote back in early 2011.

Resources:
Writing a Debugging Tools for Windows Extension - Part 1 - March 2011
Writing a Debugging Tools for Windows Extension - Part 2 - May 2011
Writing a Debugging Tools for Windows Extension - Part 3 - June 2011

Timeline:
[00:00] - Debugger Markup Language (DML)
[01:10] - Example DML output - !pde.dpx & lmD
[03:19] - IDebugControl::ControlledOutput
[03:45]DEBUG_OUTCTL_XXX
[04:57] - Text output - DEBUG_OUTCTL_AMBIENT_TEXT
[05:29] - DML output - DEBUG_OUTCTL_AMBIENT_DML
[06:20] - Output issues - Mismatched markup
[09:35] - Output issues - HTML escape sequences; e.g. &lt; for <, &quot; for ", etc.
[10:35] - Output issues - %s vs %Y{t} (and %ma)
[14:42] - Bold (<b>text</b>), Italics (<i>text</i>) and Underline (<u>text</u>)
[15:21] - Hyperlink - Not Logged (<link cmd="url">text</link>) - recommended
[15:21] - Hyperlink - Logged (<exec cmd="url">text</exec>)
[18:15] - DML Ability (WinDBG vs. CDB)
[18:29]IDebugAdvanced2::Request - DEBUG_REQUEST_CURRENT_OUTPUT_CALLBACKS_ARE_DML_AWARE
[19:40] - DML Preference (.prefer_dml)
[20:42]IDebugControl::GetEngineOptions - DEBUG_ENGOPT_PREFER_DML
[20:42] - Foreground Color (<col fg="keyword">text</col>)
[20:42] - Background Color (<col bg="keyword">text</col>)
[20:42] - No explicit color selection; must use a Keyword - refer dml.doc in the debugger folder
[22:48] - Color of Keywords defined in View | Options
[24:35] - Suggest you use Source related keywords (src*) as they are unlikely to be customized
[26:48] - Source Code (MyExt7.zip) is on the OneDrive
[26:48] - Email us your issues at defragtools@microsoft.com

BOOL PreferDML(IDebugClient* pDebugClient)
{
    BOOL bPreferDML = FALSE;
    IDebugControl* pDebugControl;
    if (SUCCEEDED(pDebugClient->QueryInterface(__uuidof(IDebugControl), (void **)&pDebugControl)))
    {
        ULONG ulOptions = 0;
        if (SUCCEEDED(pDebugControl->GetEngineOptions(&ulOptions)))
        {
            bPreferDML = (ulOptions & DEBUG_ENGOPT_PREFER_DML);
        }
        pDebugControl->Release();
    }
    return bPreferDML;
}

BOOL AbilityDML(IDebugClient* pDebugClient)
{
    BOOL bAbilityDML = FALSE;
    IDebugAdvanced2* pDebugAdvanced2;
    if (SUCCEEDED(pDebugClient->QueryInterface(__uuidof(IDebugAdvanced2), (void **)&pDebugAdvanced2)))
    {
        HRESULT hr = 0;
        if (SUCCEEDED(hr = pDebugAdvanced2->Request(DEBUG_REQUEST_CURRENT_OUTPUT_CALLBACKS_ARE_DML_AWARE, NULL, 0, NULL, 0, NULL)))
        {
            if (hr == S_OK)
            {
                bAbilityDML = TRUE;
            }
        }
        pDebugAdvanced2->Release();
    }
    return bAbilityDML;
}

Embed

Download

The Discussion

  • User profile image
    Ben

    I really enjoyed this series. Thank you. I read the MSDN series a few years back so have always been interested in debugger extensions. However, nearly all of the debugging that I have done over the past decade or so has been for managed applications. I would love to create a debugger extension to simplify debugging of some of our managed applications. I eagerly watched each week hoping for a glimpse into how to extract managed types and stacks, but now that we have come to the end, it doesn't look like this happen. Sure, SOS can be programmatically called and the output parsed, but I'm already doing this with scripts anyway. I'd like to know how to output similar data WITHOUT going through SOS. Surely there must be some interfaces that can be called to do this. Once I can extract such data, the rest of this series does a great job on how to format this for output. Any pointers or samples would be most appreciated.

  • User profile image
    windev

    @Ben: Stay tuned -- I'm prepping a new mini-series on managed debugging at the moment. Instead of coding the logic in C++, you interop in to C# and do the logic over there with help from CLRMD.  Hopefully will get Lee Culver on to co-host (the developer of CLRMD and SOS).

    (If you can't wait, email me and I can get you started with what I have so far)

  • User profile image
    Alois Kraus

    To dump managed stacks you can use the managed debugging engine (no SOS needed). The little tool "stackdump" uses this approach http://stackdump.codeplex.com/
    No need for a debugger at all.

Add Your 2 Cents