I have 40-50 methods in a class, I want to add breakpoints to all of them. Can I add breakpoints to all of them at once?
问题:
回答1:
There is an addon-less method described here: How to set a breakpoint on a C++ class in the Visual Studio Debugger
In short, you can bring up the "New Breakpoint" dialog by pressing CTRL+B and type in ClassName::*
to the function field.
You can then disable some of them in the breakpoints window.
回答2:
Here's your macro, but it takes a while to set breakpoints on 1000+ functions... and it WILL slow down Visual Studio!
Sub BreakAtEveryFunction()
For Each project In DTE.Solution.Projects
SetBreakpointOnEveryFunction(project)
Next project
End Sub
' Macro editor
Sub SetBreakpointOnEveryFunction(ByVal project As Project)
Dim cm = project.CodeModel
' Look for all the namespaces and classes in the
' project.
Dim list As List(Of CodeFunction)
list = New List(Of CodeFunction)
Dim ce As CodeElement
For Each ce In cm.CodeElements
If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
' Determine whether that namespace or class
' contains other classes.
GetClass(ce, list)
End If
Next
For Each cf As CodeFunction In list
DTE.Debugger.Breakpoints.Add(cf.FullName)
Next
End Sub
Sub GetClass(ByVal ct As CodeElement, ByRef list As List(Of CodeFunction))
' Determine whether there are nested namespaces or classes that
' might contain other classes.
Dim aspace As CodeNamespace
Dim ce As CodeElement
Dim cn As CodeNamespace
Dim cc As CodeClass
Dim elements As CodeElements
If (TypeOf ct Is CodeNamespace) Then
cn = CType(ct, CodeNamespace)
elements = cn.Members
Else
cc = CType(ct, CodeClass)
elements = cc.Members
End If
Try
For Each ce In elements
If (TypeOf ce Is CodeNamespace) Or (TypeOf ce Is CodeClass) Then
GetClass(ce, list)
End If
If (TypeOf ce Is CodeFunction) Then
list.Add(ce)
End If
Next
Catch
End Try
End Sub
回答3:
There's a class breakpoint add-in you could try, or you could use a replace expression to add a __debugbreak()
at the start of each method.
回答4:
The accepted answer didn't work for me for some reason. And I don't think my workaround applies to Visual Studio 2010. But I used the Macros for Visual Studio extension with my Visual Studio 2015 to do this.
Steps:
- Find (Ctrl+F) the right indentation for the opening brace of the methods. Typically that is 8 white spaces (or 2 tabs etc. based upon the settings you might've made).
- Append this with an opening brace
{
. - Prepend this with
\r\n
to make sure it does not match any nested braces. Now it might look like\r\n {
. Also, turn on the regular expression search (by pressing the*
on the search dialog). - Start recording a macro.
- Press F3 and then press F9 to add a breakpoint. This adds a breakpoint to the first method found using the trick.
- Stop recording the macro. Play it for the number of method you might have.
- Caution: Be aware of when you reach the end. Otherwise it will start again from the top and that start removing the breakpoints you just added.
Let me know it there is any confusion.
回答5:
If you use vim (vsvim) you can manipulate breakpoints fairly easily. Here are some examples.
break on every line:{Escape}qq:vsc Debug.ToggleBreakpoint{Enter}jq100@q
break on every method:
{Escape}qq:vsc Edit.NextMethod{Enter}:vsc Debug.ToggleBreakpoint{Enter}jq100@q
replace the 100 with the appropriate number of lines/methods.
example: https://imgur.com/SFhlEr7