Visual Studio: How to get IDebugEngine2 from VS Package (except IVsLoader)
Asked Answered
D

2

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.

Dunnite answered 20/3, 2013 at 12:50 Comment(2)
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.Evars
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.Dunnite
S
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
Shauna answered 20/3, 2013 at 13:49 Comment(7)
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 as normal API's SetBreakWhenThrown is unusable due to connect.microsoft.com/VisualStudio/feedback/details/530408/….Dunnite
That method is called automatically based on settings in the Debug → Exceptions dialog.Shauna
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).Dunnite
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.Dunnite
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.Shauna
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.Dunnite
#15583236Dunnite
T
-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

Tauro answered 26/5, 2020 at 10:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.