Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I set a breakpoint on every access to a class

When working with third party systems, especially very configurable systems that dynamically load providers, controllers, components and so on, I sometimes just want to know when a certain object or class is accessed. Normally, I'd place a breakpoint on any potential lines in my source (a nuisance, but it works), but if source is not available:

How can I instruct Visual Studio 2010 Ultimate to break on any and each access to a given class?

Note: as far as my experience goes, this is not generally possible, but I'd like to see it confirmed

like image 244
Abel Avatar asked Aug 25 '10 12:08

Abel


People also ask

How do you set a class breakpoint?

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 add a breakpoint to all methods in eclipse?

Select all the methods using ctrl . Right click and select Toggle Method Breakpoint .

How do I add a breakpoint to all methods in visual studio?

Press F3 and then press F9 to add a breakpoint.

How do you set a conditional breakpoint?

To set a conditional breakpoint, activate the context menu in the source pane, on the line where you want the breakpoint, and select “Add Conditional Breakpoint”. You'll then see a textbox where you can enter the expression. Press Return to finish.


2 Answers

Not the most elegant, but if you Ctrl+F public then you can spam between F9 [set breakpoint] then F3 [find next] to set a breakpoint on every public entry point into the class.

You might also want to add breakpoints for protected and internal entry points, and any explicit interface implementations (declarations that don't have public)

like image 72
Carl Walsh Avatar answered Sep 19 '22 12:09

Carl Walsh


You can click Debug > New Breakpoint > Breakpoint at Function. Ctrl-B brings you there directly. It'll allow you to break at a specific function.

During debugging, you can see in the Breakpoints-window whether the method is found and will be hit (red round icon) or not (white with circle icon, as of disabled breakpoint), just as with normal breakpoints.

like image 40
SLaks Avatar answered Sep 21 '22 12:09

SLaks