Pergunta

In Visual Studio, if you want to attach debugger to any processes, you have the possibility to select some specific engine (code type) or set of engines you would like to use:

enter image description here

Next (after you selected any engines and processes), if you click Attach button, the debugger attach operation is started. Then also debug-related events are fired. IDebugEventCallback2::Event can be used to grab such events (and e.g. extract the names of the processes debugger is actually attaching to):

public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                 IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, 
                 uint attributes)
{
    if (debugEvent is IDebugProcessCreateEvent2)
    {
        string processname;
        if(process != null)
            process.GetName((uint) enum_GETNAME_TYPE.GN_FILENAME, out processname);
        //...
    }
}

Is there any similar way to get some information about the engines which have been chosen?

UPDATE: a bit more detailed code:

public class DebugEventsHunter : IVsDebuggerEvents, IDebugEventCallback2
{
    private readonly IVsDebugger _debugger;
    private uint _cookie;

    public DebugEventsHunter(IVsDebugger debugger) { _debugger = debugger; }

    public void Start()
    {
        _debugger.AdviseDebuggerEvents(this, out _cookie);
        _debugger.AdviseDebugEventCallback(this);
    }   

    public int Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program,
                     IDebugThread2 thread, IDebugEvent2 debugEvent, ref Guid riidEvent, uint attributes)
    {
        if (debugEvent is IDebugProcessCreateEvent2)
        {
            // get process name (shown before) 
        }               
        if (debugEvent is IDebugEngineCreateEvent2)
        {
            // why execution flow never enters this scope?
            IDebugEngine2 e;
            ((IDebugEngineCreateEvent2)debugEvent).GetEngine(out e);
        }
        // engine parameter is also always null within this scope
        return VSConstants.S_OK;
    }

    public int OnModeChange(DBGMODE mode) { /*...*/ }
}

and the usage:

var debugger = GetService(typeof(SVsShellDebugger)) as IVsDebugger;
var hunter = new DebugEventsHunter(debugger);
hunter.Start();
Foi útil?

Solução

When a debug engine launches a process or attaches to an existing process, it will send the IDebugLoadCompleteEvent2 event in a timely manner. You can use this event to determine exactly which debug engines were selected for debugging.

Edit: To determine the name of the debug engine, you can use the IDebugProgram2 instance that is included with the above event, and call the IDebugProgram2.GetEngineInfo method. This method provides the name and ID of the debug engine. Note that the name of the debug engine may not match what you are used to seeing in the debugger dialogs, in which case you will need to convert the canonical name returned by this method to a "friendly" name using your own mapping implementation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top