.NET Tips and Tricks

Blog archive

Getting Back to a Useful Method in Debug Mode

Sometimes, in debug mode, you find yourself sitting on a line in a method that you have no interest in. What you actually want to do is to get back out of the method and stop in some method you've already passed through. Of course, if you just want to get back to the method that called the code you've stopped in, you can use Step Out (Ctrl+Shift+F8). But if you're more than one level deep, getting back to someplace useful can be painful.

In a recent article on the debugging tools available in Visual Studio, I described the benefits of the Breakpoint window. What I didn't talk about was the Call Stack window which lets you stop in any method that you passed through on your way to the current line of code.

To use the Call Stack window, after you've stopped on a line, first bring up the window: either use the menu choice Debug | Windows | Call stack or use the distinctly un-intuitive Ctrl + L (in Visual Studio 2010).  That will give you a window with a list of methods executed on the way to the line you've stopped at.

The method you're stopped at appears right at the top of the window. Listed below that line are the methods you passed through on the way to this line of code. Now just right-click on one of those methods and select Run to Cursor (or select the method and then press Ctrl+F8). Your code will execute until control returns to the method you've selected in the Call Stack. Once you've stopped there, you can treat it like any other breakpoint.

If you want to set something more permanent, after selecting a method in the Call Stack, use F9 (or Debug | Toggle Breakpoint) to set a breakpoint on the method.

Posted by Peter Vogel on 11/29/2011 at 1:16 PM


comments powered by Disqus

Reader Comments:

Mon, Jan 23, 2012 Peter Vogel Canada

Tom: I hadn't made that connection! You're right, of course. Cool.

Tue, Jan 17, 2012 Tom Hamilton Sacramento

Hi Peter - Ctrl-L seems un-intuitive now but the window was originally called 'Locals' for local variables

Add Your Comments Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

.NET Insight

Sign up for our newsletter.

I agree to this site's Privacy Policy.