Vyktor
Vyktor

Reputation: 20997

WinDBG extension - Breakpoint listing

Is there any way how can I get a list of breakpoints from within Windows Debugger Extension?

I'm using plain C (and I'm trying to avoid using COM interface they provide and I'm not even sure if that COM interface provides a way to do that).

I've read and researched wdbgexts.h and dbghelp.h but neither of them seem to contain any usable function or global variable, although there are some info on BPs in those files, such as DBGKD_GET_VERSION::BreakpointWithStatus.

Upvotes: 2

Views: 511

Answers (2)

Vyktor
Vyktor

Reputation: 20997

Windows Debugger Extension provides function ULONG64 GetExpression(PCSTR lpExpression) (of course it's <sarcasm>well documented</sarcasm>)

#define GetExpression    (ExtensionApis.lpGetExpressionRoutine)

which allows you to get results from any WinDBG expression like ?? @eip.

GetExpression( "@eip"); // Without `?? ` in the beginning

Next, if you take a look at: Windows Debugger Help » Debugging Tools For Windows » Debuggers » Debugger References » Debugger Commands » Syntax Rules » Pseudo-Registers Syntax

You will find a line what looks like this:

$bpNumber - The address of the corresponding breakpoint. For example, $bp3 (or $bp03) refers to the breakpoint whose breakpoint ID is 3. Number is always a decimal number. If no breakpoint has an ID of Number, $bpNumber evaluates to zero. For more information about breakpoints, see Using Breakpoints.

So with some overhead you'll get this (working) solution:

#define MAX_BREAKPOINTS 100

DWORD i, addr;
CHAR buffer[] = "$bp\0\0\0\0\0\0\0\0\0\0\0\0";

for( i = 0; i < MAX_BREAKPOINTS; ++i){
    // Appends string to BP prefix
    itoa( i, buffer+3, 10);
    addr = GetExpression( buffer);
    if( !addr){
        break;
    }

    // Do stuff
}

The only another solution is to use COM objects as Steve Johnson suggested.

Upvotes: 3

Steve Johnson
Steve Johnson

Reputation: 3017

Use IDebugControl::GetNumberBreakpoints, then IDebugControl::GetBreakpointByIndex.

Upvotes: 3

Related Questions