Abel
Abel

Reputation: 57159

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

Upvotes: 18

Views: 11395

Answers (4)

Carl Walsh
Carl Walsh

Reputation: 6949

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)

Upvotes: 14

alf
alf

Reputation: 18530

I just made a Visual Studio 2010 addin for this. Check this: http://weblogs.asp.net/uruit/archive/2011/08/04/visual-studio-2010-addin-setting-a-class-breakpoint.aspx

Update

This project now lives on Github. Feel free to contribute.

Upvotes: 1

SLaks
SLaks

Reputation: 887453

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.

Upvotes: 11

Richard
Richard

Reputation: 109005

At one time (pre VS2008) you could set a breakpoint at every line in a file by select all (ctrl-a) followed by set breakpoint (F9).

To set just one on the entry to every method takes, if I recall correctly, a macro. Check out John Robbins' blog as a possible source: http://www.wintellect.com/CS/blogs/jrobbins/

[EDIT: ctrl-A, F9 doesn't work in 2010 or 2008, so it must be an earlier version I remember this from]

Upvotes: 1

Related Questions