Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set breakpoints to all methods in a class at once in Visual Studio?

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?

like image 201
Charu Avatar asked Jul 24 '12 07:07

Charu


People also ask

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

Press F3 and then press F9 to add a breakpoint.

How do I set breakpoint conditions in Visual Studio?

Right-click the breakpoint symbol and select Conditions (or press Alt + F9, C). Or hover over the breakpoint symbol, select the Settings icon, and then select Conditions in the Breakpoint Settings window.

How do you set a class breakpoint?

You can set a breakpoint on a class so that the debugger pauses when code from the class is about to be accessed and/or when the class is unloaded from memory. To set a breakpoint on a class: Choose Run | New Breakpoint (Ctrl-Shift-F8).


2 Answers

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+K, B and type in ClassName::* to the function field. In Visual Studio 2017 you need to include the namespace in the field, as in NamespaceName::ClassName::*. You can then disable some of them in the breakpoints window.

like image 71
vt. Avatar answered Sep 23 '22 19:09

vt.


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 
like image 36
alexkovelsky Avatar answered Sep 22 '22 19:09

alexkovelsky