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

十年热恋 提交于 2020-01-13 15:50:55

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/15524038/visual-studio-how-to-get-idebugengine2-from-vs-package-except-ivsloader

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!