views:

78

answers:

2

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

+2  A: 

You can click Debug > New Breakpoint > Breakpoint at Function. Ctrl-B brings you there directly. It'll allows 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.

SLaks
Thanks, that's handy for a single method, indeed, even if it isn't loaded. But it doesn't help me with every access to a class, nor do I seem to be able to set a breakpoint this way for the `ctor` or `cctor` (but perhaps I need to experiment more).
Abel
@Abel: Try `Namespace.ClassName.ClassName`.
SLaks
@SLaks: I can't get that to work for all types and methods, but I just decided to purchase Reflector Professional (used the free edition for ages) and it allows me to debug and set breakpoints on the reflected code of any loaded or referenced assembly.
Abel
Your suggestion at least works for quite some cases, while not a full answer (that would be: it is not possible), it helped nonetheless. Thanks.
Abel
+1  A: 

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]

Richard
@Richard: hitting F9 with multiple lines selected only sets a breakpoint at the current line. But your suggestion for making a macr is good.
Abel
@Abel: .. and it clears any other breakpoints already in the selected code. This is a change since some earlier version (it doesn't work in 2008, so maybe I'm remembering 2005?). I'll update the answer.
Richard
Thanks. And I use 2010 and really can't remember it from earlier editions, but then again, there're always features you don't discover before a next edition comes out.
Abel