Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add Debug Breakpoints to lines displayed in a "Find Results" window in Visual Studio

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?

like image 283
Noah Avatar asked Sep 16 '08 14:09

Noah


People also ask

How do I add a breakpoint window in Visual Studio?

To set a breakpoint in source code, click in the far left margin next to a line of code. You can also select the line and press F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert breakpoint.

How do I Debug code in Visual Studio line by line?

Run to a breakpoint in code You can also select the line and then select F9, select Debug > Toggle Breakpoint, or right-click and select Breakpoint > Insert Breakpoint. The breakpoint appears as a red dot in the left margin next to the line of code. The debugger suspends execution just before the line runs.

How do I show breakpoints in Visual Studio?

Visual Studio's/Atmel Studio's Breakpoint Window gives you an overview of all breakpoints you have set in your project. You open the Breakpoint Window with the menu item Debug > Windows > Breakpoints or by pressing [Alt+F9].

How do I add a breakpoint to all methods in Visual Studio?

Press F3 and then press F9 to add a breakpoint.


1 Answers

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.

like image 118
Jeff Hillman Avatar answered Oct 22 '22 20:10

Jeff Hillman