从正在调试的外接程序中更改主机调试器设置 [英] Altering the host debugger settings from within an Add-in that is being debugged

查看:77
本文介绍了从正在调试的外接程序中更改主机调试器设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这让我感到难过.在网上找到最好的更改我所需的设置的方法是在网上经常引用以下示例:

Sub BreakWhenThrown( 可选 ByVal strException As 字符串 = " )
昏暗 dbg As Debugger3 = DTE.Debugger
Dim 例如 As ExceptionSettings = dbg. ExceptionGroups.Item( " Comm关于语言运行时异常" )
,例如SetBreakWhenThrown(
True ,例如Item(strException))
结束

This has me stumped. The best I can find on-line to alter the settings I need is this oft cited example on-line:

Sub BreakWhenThrown( Optional ByVal strException As String = "" )
    
Dim dbg As Debugger3 = DTE.Debugger
    
Dim eg As ExceptionSettings = dbg.ExceptionGroups.Item( "Common Language Runtime Exceptions" )
    eg.SetBreakWhenThrown(
True , eg.Item(strException))
End Sub

太好了.但是我找不到为VS2008插件编写的C#代码示例,并且在DTE.Debugger行上没有牵引力.

Great. But I can't find an example of C# code written for a VS2008 addin and have no traction on the DTE.Debugger line.

我已经为Visual Studio编写了一个插件,可以很好地工作并且可以调试.调试时,我有一个VS2008实例,该实例启动了另一个安装了我的插件的VS2008实例.现在,在添加中,我希望关闭并再次打开Give Exception组的BreakWhenThrown标志.值得注意的是,当我进入常规使用try/catch对的代码区域(并且我知道并期望会抛出很多sof异常)时,我会关闭它,而当我不在这样的代码区域中时,我再次将其关闭(因此我的调试器会在异常发生时停止,我可以对其进行调试.)

I've written an addin for visual studio which works fine and debugs fine. When debugging it I have one instance of VS2008 which launches another instance of VS2008 with my addin installed. Now in the adding I wish to turn off and on again the BreakWhenThrown flag for a give Exception group. Notably I wnat to turn it off when I'm entering code areas where I use try/catch pairs routinely (and I know and expect lot sof exceptions to be thrown) and on again when I'm not in such a code area (so my debugger stops on the line of the exception and I can debug it).

可惜,我目前无法判断我的插件如何获得托管它的调试器对象(这是两个Visual Studio实例中的第一个)我想)做到这一点.

Alas, I have no way presently of divining how my addin, can get the debugger object which is hosting it (that is teh first of the two Visual Studio instances I guess) to do this.

现在,我知道我使用以下方法添加了托管调试器:

Now I know I break the hosting debugger from my adding using:

System.Diagnostics.Debugger.Break();

System.Diagnostics.Debugger.Break();

,我经常在需要时使用它,但是System.Diagnostics.Debugger对象无法识别调试器的实例,更不用说实现Debugger3的实例了.界面.

and I use this often when I need to, but the System.Diagnostics.Debugger object does not identify an instance of the debugger let alone one that implements the Debugger3 interface.

我的插件如何为给定的异常组获取调试器对象来设置或取消设置调试器中的BreakWhenThrown标志.令我惊讶的是,从文档中得知这是多么困难.看起来像是自动生成的文档,并且没有C#代码示例...

How can my addin get a debugger object to set or unset the BreakWhenThrown flag in the debugger for given exception groups. It amazes me how difficult this is to divine form the documentation. Loads of documentation that looks like it's autogenerated and no C# code examples ...

此处:

http://msdn.microsoft.com/en-us/library/envdte90.debugger3.aspx

http://msdn.microsoft.com/en-us/library/envdte90.debugger3.aspx

是一些示例VB和C ++代码,但是VB保留了上面提出的神秘问题,而我尚未解密的C + _ +,但这似乎是下一步(并行问一下任何人都知道的事情).

is some sample VB and C++ code, but the VB leaves the cryptic question open that is raised above, and the C+_+ I have yet to decrypt, but that seems to be the next step (asking here in parallel inc ase anyone knows).

肯定可以!!



推荐答案

C#代码如下所示:

无效 字符串 strException)
{
调试程序= _applicationObject.Debugger as Debugger3 ;
例外设置 ,es.Item(strException));
}

C# code would look something like the following:

public void BreakWhenThrown(string strException)
{
   Debugger3 debugger = _applicationObject.Debugger as Debugger3;
   ExceptionSettings es = debugger.ExceptionGroups.Item("Common Language Runtime Exceptions");
   es.SetBreakWhenThrown(
true, es.Item(strException));
}

 

我不确定我是否完全遵循您的要求,但是外接程序通常会使用通过OnConnection传入的applicationObject公开的Debugger接口.如果您的加载项需要与VS的另一个实例互操作,则需要通过运行对象表检索该实例,如以下链接中所述:

附加到IDE的特定实例
如何:对DTE和DTE对象的引用

此致,

I'm not sure I completely follow what your requirements are here, but an add-in will typically use the Debugger interface exposed via the applicationObject passed in via OnConnection. If you have an add-in that needs to interop with another instance of VS, then you will need to retrieve that instance via the Running Object Table, as described in the following links:

   Attaching to Specific Instances of the IDE
   Automating a specific instance of Visual Studio .Net (CodeProject article)

Or have your add-in launch the 2nd instance, so you can readily retrieve it' DTE interface, as described in the following link:

   How to: Get References to the DTE and DTE objects

Sincerely,


这篇关于从正在调试的外接程序中更改主机调试器设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆