views:

1229

answers:

2

I wonder if there's a way to do the following: I have a structure containing a member which is a pointer to a block of memory allocated by the kernel when I pass the structure to an API function (the structure is a WAVEHDR, the member is the reserved field.)

I can set a data breakpoint on the value of the reserved member - that in itself is not very helpful. What I'd like to do, when the breakpoint is hit, is to dereference the pointer stored in reserved and set a new data breakpoint on the memory pointed to by that pointer. I would like VisualStudio to break when that memory is set to a known value.

I know how to set a breakpoint from a macro, and how to have Visual Studio invoke that macro from a breakpoint when it's hit, but I don't know whether I can pass the pointer value to the macro so that it can set the breakpoint on the right address. The UI doesn't provide a way to do it.

Is there a way for the macro to access information about the running program, and do things like evaluate global variables or other expressions? I could accomplish what I'm trying to do if I had that kind of programmatic access to the running code (during a breakpoint) from the macro.

A: 

I'm not sure if thats possible. I know that there are conditional breakpoints, but that would require knowing the memory address ahead of time...

Something along the lines of *p == 0xADDRESS in the conditional break dialog.

Nicholas Mancuso
+1  A: 

A macro can evaluate anything that you can in the watch window:

    Dim e As EnvDTE.Expression

    e = DTE.Debugger.GetExpression("<my expression>", True)

    If e.IsValidValue Then
        ... use e.Value to do something
    End If

The value you get back in e.Value is exactly the string you would see in the watch window, so you may have to pull it apart. There are also a bunch of other properties on the Expression object you can use. See the MSDN documentation.

Rob Walker