Attach Visual Studio 2013 to managed and C++ processes using multiple engines

1

I am trying to get Visual Studio 2013 to programmatically attach the Debugger to a child process, which I start using the Process.Start method.

Process.Start(ProcessStartupInformation startupInfo)

var subProcess = Process.Start(startInfo);

// TODO: how to find the right VS instance?
var dte2 = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.12.0");
var debugger2 = (EnvDTE80.Debugger2)dte2.Debugger;
Process2 processToAttachTo = null;
if (debugger2.LocalProcesses != null)
{
    foreach (Process2 proc in debugger2.LocalProcesses)
    {
        if (proc.ProcessID == subProcess.Id)
        {
            processToAttachTo = proc;
        }
    }
 }

 if (processToAttachTo != null)
 {
      var trans = debugger2.Transports.Item("Default");
      var engine1 = trans.Engines.Item("Managed (v4.5, v4.0)");
      var engine2 = trans.Engines.Item("Native");
      var engines = new[] { engine1, engine2 };

      processToAttachTo.Attach2(engines);
  }

Unfortunately, this seems to crash the Debugger. However, if I use only one of the engines

      processToAttachTo.Attach2(engine1);

OR

      processToAttachTo.Attach2(engine2);

everything works fine.

In that scenario, I can only debug either my C++ child processes or my C# child processes. But not both.

If I try to get processToAttachTo.Transport.Engines and use those like so processToAttachTo.Attach2(processToAttachTo.Transport.Engines) the Debugger crashes as well and I get at Call was rejected by callee. (Exception from HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)) exception.

QUESTIONS:

  1. How do I use multiple engines to attach the Debugger?
  2. If it is not possible to attach multiple engines, how do I determine, which engine I should Attach?

Related Questions:

Further info:

http://msdn.microsoft.com/en-us/library/ms228772(v=vs.120).aspx

c#
c++
visual-studio-2013
visual-studio-debugging
asked on Stack Overflow Jan 15, 2014 by froeschli • edited May 23, 2017 by Community

1 Answer

2

A string[] works for me (VS 2017):

processToAttachTo.Attach2(new string[] {"Managed (v4.5, v4.0)", "Native"});
answered on Stack Overflow Jan 15, 2019 by Remus Rusanu

User contributions licensed under CC BY-SA 3.0