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:
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();
IDebugEngineCreateEvent2::GetEngine()
I've tried to use it, but without any success. Please check the updated question to verify what I've done incorrectly (btw: I'm using VS2013 it this makes any difference). – Feminine