3

Is it possible to get a list or a specific instance of IDebugEngine2 (MSDN) from a Visual Studio Package without using IVsLoader approach (described here)?

Normally I would expect most services to be available through GetService, either directly or through some other service. But I can not easily find anything that can provide debug engines.

Andrey Shchekin
  • 21,101
  • 19
  • 94
  • 162
  • It's usually worth giving a reason if you've already ruled out a particular solution - the same reason may rule out some other approaches, or it may be possible that there's some misunderstanding and the ruled out solution is still possible. – Damien_The_Unbeliever Mar 20 '13 at 14:02
  • The thing is — I am still pursuing that one and I am having some problems with it, which might be just a misunderstanding. However the whole solution seems unreasonably hacky so I am asking for alternatives while I am struggling with it. – Andrey Shchekin Mar 20 '13 at 20:46

2 Answers2

2

What are you trying to do with it? The debugger interfaces are extremely fragile. Often there are 2, 3, or maybe more possible ways to perform an action with the debugger interfaces, but the particular DE implementation only supports 1 of them. Debug engine implementers are not expecting any direct calls to their debug engine interfaces from anywhere except Visual Studio itself, and the risk of breaking debugger functionality if you attempt it lies somewhere between very high and guaranteed.

For example, here are some of the potential ways to tell a DE to launch and/or attach to a process:

  • IDebugEngineLaunch2.LaunchSuspended
  • IDebugPortEx2.LaunchSuspended
  • IDebugProgramEx2.Attach
  • IDebugProgramNode2.Attach_V7
  • IDebugProgramNodeAttach2.OnAttach
  • IDebugEngine2.Attach
  • IVsDebuggableProjectCfg.DebugLaunch
  • VsShellUtilities.LaunchDebugger
  • IVsDebugger2.LaunchDebugTargets
  • IVsDebugger2.LaunchDebugTargets2

Edit 1: In the case of my Java debugger, the debug engine is created by the session manager with the following stack:

  • My code calls IVsDebugger2.LaunchDebugTargets2
  • The environment calls back to my implementation of IDebugProgramProvider2.WatchForProviderEvents
  • After creating a new instance of IDebugProgram2 (a copy of IDebugProcess2 obtained from the IDebugDefaultPort2 that VS passed to WatchForProviderEvents is passed to the IDebugProgram2 constructor), my code calls IDebugPortNotify2.AddProgramNode
  • The environment calls back to the constructor of my debug engine
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
  • I see, so each session creates a new debug engine? What I am trying to do is to get the right instance and call [SetException](http://msdn.microsoft.com/en-us/library/bb162170.aspx) as normal API's [SetBreakWhenThrown](http://msdn.microsoft.com/en-us/library/envdte90.exceptionsettings.setbreakwhenthrown.aspx) is unusable due to http://connect.microsoft.com/VisualStudio/feedback/details/530408/abysmal-performance-when-changing-debugger-break-on-throw-settings. – Andrey Shchekin Mar 20 '13 at 20:50
  • That method is called automatically based on settings in the Debug → Exceptions dialog. – Sam Harwell Mar 20 '13 at 20:53
  • I know, I want to automate toggling the contents of this dialog (basically a quick way to switch all on/off). As SetBreakWhenThrown is way too slow, my options are limited. I know any changes I make this way will not be seen in the dialog, but I can replace the dialog as well (since I am making a VS extension). – Andrey Shchekin Mar 20 '13 at 20:59
  • I might have found the answer — using IVsDebugger.AdviseDebugEventCallback with IDebugEventCallback2. Each Event call should have an engine passed in. Can't try it right now, but I'll definitely try it. – Andrey Shchekin Mar 20 '13 at 21:00
  • You might do well to post another question asking about that instead - I have a simpler answer for the exception settings that is likely to work. – Sam Harwell Mar 20 '13 at 21:16
  • Maybe you can answer here, then if I try it and it works you can post question/answer it at the same time? Because I feel a bit weird about asking question where I haven't yet tried all the approaches I have in mind. – Andrey Shchekin Mar 20 '13 at 23:15
  • http://stackoverflow.com/questions/15582736/visual-studio-how-to-set-break-on-all-exceptions-from-a-package – Andrey Shchekin Mar 23 '13 at 03:05
-1

I recently was investigating the same question, and eventually found you can easily do this via ILocalRegistry3.CreateInstance!

Please see my post here for more info

lordmilko
  • 161
  • 1
  • 8