I'm trying to write Visual Studio package which allows attach to processes chosen in previous debugging session. Basically, I know how to attach to processes:
var dte = GetGlobalService(typeof(DTE)) as DTE2;
if (dte != null)
{
IList<Process2> processes =
dte.Debugger.LocalProcesses.Cast<Process2>()
.Where(process => process.Name.IndexOf("process.exe", StringComparison.Ordinal) != -1)
.ToList();
foreach (var p in processes)
{
p.Attach();
}
}
The question is, how to get processes which I have been attached to last time? Is there any information stored about this? If not, how to write logic which helps me with it?
IVsDebuggerEvents
(Microsoft.VisualStudio.Shell.Interop.dll) provides notification when the debugger changes mode while IDebugEventCallback2
(Microsoft.VisualStudio.Debugger.Interop.dll) is used by the debug engine to send debug events. Usage of these interfaces will allow to gather required information.
UPDATE: Detailed example of how to do it is shown on my github repository where I've written Visual Studio extension which allows to attach debugger to previously debugged processes.