Domanda

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?

È stato utile?

Soluzione

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.

Altri suggerimenti

I do not know of any such information. A different approach which might work is to add a WCF service to each process. This service will enable you both to launch a debugger , and also to check if a debugger was launched already.

 public class DebugService : IDebugService
    {
        public void LaunchDebugger()
        {
            //TODO - write some code indicating that this 
            //process was bebugged. e.g. - mark a flag in DB or file
            Debugger.Launch();
        }

        public bool WasDebuggedLastTime()
        {
            //TODO - write code to check if this process was debugged
        }

    }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top