如何将调试断点添加到“查找结果”窗口中显示的行中 Visual Studio 中的窗口

发布于 2024-07-06 01:17:38 字数 115 浏览 9 评论 0原文

在 Visual Studio 2005-2015 中,可以查找包含某些引用的所有行并将它们显示在“查找结果”窗口中。

既然显示了这些结果行,是否有任何键盘快捷键可以允许向所有结果行添加调试断点?

In Visual Studio 2005-2015 it is possible to find all lines containing certain references and display them in a "Find Results" window.

Now that these result lines are displayed, is there any keyboard shortcut that would allow adding debug breakpoints to all of them?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

匿名的好友 2024-07-13 01:17:38

我需要类似的东西来禁用所有断点并在每个“Catch ex as Exception”上放置一个断点。 不过,我对此进行了一些扩展,以便它会在您选择的字符串的每次出现处放置一个断点。 您所需要做的就是突出显示要设置断点的字符串并运行宏。

 Sub BreakPointAtString()

    Try
        DTE.ExecuteCommand("Debug.DisableAllBreakpoints")
    Catch ex As Exception

    End Try

    Dim tsSelection As String = DTE.ActiveDocument.Selection.text
    DTE.ActiveDocument.Selection.selectall()
    Dim AllText As String = DTE.ActiveDocument.Selection.Text

    Dim findResultsReader As New StringReader(AllText)
    Dim findResult As String = findResultsReader.ReadLine()
    Dim lineNum As Integer = 1

    Do Until findResultsReader.Peek = -1
        lineNum += 1
        findResult = findResultsReader.ReadLine()
        If Trim(findResult) = Trim(tsSelection) Then
            DTE.ActiveDocument.Selection.GotoLine(lineNum)
            DTE.ExecuteCommand("Debug.ToggleBreakpoint")
        End If
    Loop

End Sub

希望对你有帮助 :)

I needed something similar to disable all breakpoints and place a breakpoint on every "Catch ex as Exception". However, I expanded this a little so it will place a breakpoint at every occurance of the string you have selected. All you need to do with this is highlight the string you want to have a breakpoint on and run the macro.

 Sub BreakPointAtString()

    Try
        DTE.ExecuteCommand("Debug.DisableAllBreakpoints")
    Catch ex As Exception

    End Try

    Dim tsSelection As String = DTE.ActiveDocument.Selection.text
    DTE.ActiveDocument.Selection.selectall()
    Dim AllText As String = DTE.ActiveDocument.Selection.Text

    Dim findResultsReader As New StringReader(AllText)
    Dim findResult As String = findResultsReader.ReadLine()
    Dim lineNum As Integer = 1

    Do Until findResultsReader.Peek = -1
        lineNum += 1
        findResult = findResultsReader.ReadLine()
        If Trim(findResult) = Trim(tsSelection) Then
            DTE.ActiveDocument.Selection.GotoLine(lineNum)
            DTE.ExecuteCommand("Debug.ToggleBreakpoint")
        End If
    Loop

End Sub

Hope it works for you :)

太阳哥哥 2024-07-13 01:17:38

保罗,非常感谢,但我有以下错误(消息框),可能我需要重新启动我的电脑:

Error
---------------------------
Error HRESULT E_FAIL has been returned from a call to a COM component.
---------------------------
OK   
---------------------------

我会提出以下解决方案,该解决方案非常简单,但对我有用

Sub BreakPointsFromSearch()
    Dim n As Integer = InputBox("Enter the number of search results")

    For i = 1 To n
        DTE.ExecuteCommand("Edit.GoToNextLocation")
        DTE.ExecuteCommand("Debug.ToggleBreakpoint")            
    Next
End Sub

Paul, thanks a lot, but I have the following error (message box), may be I need to restart my PC:

Error
---------------------------
Error HRESULT E_FAIL has been returned from a call to a COM component.
---------------------------
OK   
---------------------------

I would propose the following solution that's very simple but it works for me

Sub BreakPointsFromSearch()
    Dim n As Integer = InputBox("Enter the number of search results")

    For i = 1 To n
        DTE.ExecuteCommand("Edit.GoToNextLocation")
        DTE.ExecuteCommand("Debug.ToggleBreakpoint")            
    Next
End Sub
暮色兮凉城 2024-07-13 01:17:38

如果您可以准确搜索该单词,则可以使用一对键盘快捷键来快速完成。

工具-> 选项-> 环境-> 键盘

  • Edit.GoToFindResults1NextLocation
  • EditorContextMenus.CodeWindow.Breakpoint.InsertBreakpoint

将它们分配给 Control+Alt+F11 和 F10,您可以非常快速地浏览所有结果。 然而,我还没有找到转到下一个参考的捷径。

If you can search for the word exactly, you can use a pair of keyboard shortcuts to do it quickly.

Tools -> Options -> Enviroment -> Keyboard

  • Edit.GoToFindResults1NextLocation
  • EditorContextMenus.CodeWindow.Breakpoint.InsertBreakpoint

Assign them to Control+Alt+F11 and F10 and you can go through all the results very quickly. I haven't found a shortcut for going to the next reference however.

挽心 2024-07-13 01:17:38

此答案不适用于 Visual Studio 2015 或更高版本。 可以找到更新的答案 此处

您可以使用 Visual Studio 宏轻松完成此操作。 在 Visual Studio 中,按 Alt-F11 打开宏 IDE,并通过右键单击 MyMacros 并选择“添加|添加模块...”来添加新模块。

将以下内容粘贴到源代码编辑器中:

Imports System
Imports System.IO
Imports System.Text.RegularExpressions
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module CustomMacros
    Sub BreakpointFindResults()
        Dim findResultsWindow As Window = DTE.Windows.Item(Constants.vsWindowKindFindResults1)

        Dim selection As TextSelection
        selection = findResultsWindow.Selection
        selection.SelectAll()

        Dim findResultsReader As New StringReader(selection.Text)
        Dim findResult As String = findResultsReader.ReadLine()

        Dim findResultRegex As New Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):")

        While Not findResult Is Nothing
            Dim findResultMatch As Match = findResultRegex.Match(findResult)

            If findResultMatch.Success Then
                Dim path As String = findResultMatch.Groups.Item("Path").Value
                Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value)

                Try
                    DTE.Debugger.Breakpoints.Add("", path, lineNumber)
                Catch ex As Exception
                    ' breakpoints can't be added everywhere
                End Try
            End If

            findResult = findResultsReader.ReadLine()
        End While
    End Sub
End Module

本示例使用“查找”中的结果结果 1" 窗口; 您可能想为每个结果窗口创建单独的快捷方式。

您可以通过转到“工具|选项...”并选择左侧导航中的环境部分下的键盘来创建键盘快捷键。 选择您的宏并指定您喜欢的任何快捷方式。

您还可以通过转到“工具”|“自定义...”并选择左侧导航中的部分,将宏添加到菜单或工具栏。 在列表中找到宏后,您可以将其拖动到任何菜单或工具栏,其中可以将其文本或图标自定义为您想要的任何内容。

This answer does not work for Visual Studio 2015 or later. A more recent answer can be found here.

You can do this fairly easily with a Visual Studio macro. Within Visual Studio, hit Alt-F11 to open the Macro IDE and add a new module by right-clicking on MyMacros and selecting Add|Add Module...

Paste the following in the source editor:

Imports System
Imports System.IO
Imports System.Text.RegularExpressions
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics

Public Module CustomMacros
    Sub BreakpointFindResults()
        Dim findResultsWindow As Window = DTE.Windows.Item(Constants.vsWindowKindFindResults1)

        Dim selection As TextSelection
        selection = findResultsWindow.Selection
        selection.SelectAll()

        Dim findResultsReader As New StringReader(selection.Text)
        Dim findResult As String = findResultsReader.ReadLine()

        Dim findResultRegex As New Regex("(?<Path>.*?)\((?<LineNumber>\d+)\):")

        While Not findResult Is Nothing
            Dim findResultMatch As Match = findResultRegex.Match(findResult)

            If findResultMatch.Success Then
                Dim path As String = findResultMatch.Groups.Item("Path").Value
                Dim lineNumber As Integer = Integer.Parse(findResultMatch.Groups.Item("LineNumber").Value)

                Try
                    DTE.Debugger.Breakpoints.Add("", path, lineNumber)
                Catch ex As Exception
                    ' breakpoints can't be added everywhere
                End Try
            End If

            findResult = findResultsReader.ReadLine()
        End While
    End Sub
End Module

This example uses the results in the "Find Results 1" window; you might want to create an individual shortcut for each result window.

You can create a keyboard shortcut by going to Tools|Options... and selecting Keyboard under the Environment section in the navigation on the left. Select your macro and assign any shortcut you like.

You can also add your macro to a menu or toolbar by going to Tools|Customize... and selecting the Macros section in the navigation on the left. Once you locate your macro in the list, you can drag it to any menu or toolbar, where it its text or icon can be customized to whatever you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文