Debugging all events in Visual Studio 2010 without setting break points
Solution 1
For debugging a button click without setting breakpoints:
- Start the app with the debugger.
- Get to the state immediately before the intended click.
- Go back to the debugger and press Pause then F11 (Step Into) -- nothing will happen.
- Go to the app and press the button -- the debugger should take over and drop you into the event handler.
Note: This will not work if Paint, any Mouse event, or probably some other events are handled. The debugger will drop you into those handlers any time you attempt the steps above.
Solution 2
If you're using the Ultimate edition of your Visual Studio 2010 you can use its new feature called IntelliTrace (previously Historical Debugger). This will allow you to do exactly what you want - be able to see all method calls and events that happened during execution of your program, and you'll be able to jump back to the event which you need.
To enable IntelliTrace, go to Tools → Options → IntelliTrace
, and check the "Enable IntelliTrace" checkbox, and select one of two modes: "events only" or "events and call information", then run your application with a debugger (F5).
The difference between the two modes is that the latter uses the profiler to collect all runtime information, so you get a complete call stack, however you won't be able to use edit-and-continue features of the debugger.
You can find more in this series of articles, and of course, on MSDN.
Solution 3
You could also try a code coverage tool.
For example, if you have Resharper and dotCover, you can run your application (via the dotCover->Cover Application... menu item) and when the application finishes, dotCover will show you which lines of code were run in the VS IDE by highlighting them in green. Lines of code which where not run are coloured in red.
I don't know if there are other tools which do this, but it's an option.
Solution 4
I developed the Runtime Flow tool to solve exactly this problem - to understand a large unfamiliar .NET codebase via realtime function calls monitoring. It's similar to IntelliTrace, but places more emphasis on control flow than on debugging.
Solution 5
Why would you want to break on every line? This would be very onerous and time consuming. If you want to see the activity of your program as it executes, use a logging mechanism or Debug.Writeline
to output information to the Immediate window.
Related videos on Youtube
Ying Chan
Updated on July 09, 2022Comments
-
Ying Chan almost 2 years
I am trying to debug a windows form application which has a large number of events: button presses, timers, etc..
Is there a way to catch every line of code being executed by the application without setting a break point?
edit: The program was not written by me, so I am unfamiliar with the code. I wish to step through the entire program, catching every line of code being executed. Setting break points in every event is impractical as various controls are created dynamically.
-
Brian Rasmussen over 13 yearsDebugging is about focusing your attention on a few specific points, not breaking on each and every instruction if you ask me.
-
-
Ying Chan over 13 yearsThanks for the fast reply. But the problem is that I can't catch code thats being run within events
-
Justin over 13 years@Ying - You need to set your breakpoint inside the method event handler (unless I have miss-read you)
-
Ying Chan over 13 yearsThe problem is that this solution is highly impractical as the program is large and complex
-
stuartd over 13 yearsYou can set breakpoints programatically on all event handlers - see eg stackoverflow.com/questions/841782/…
-
Ying Chan over 13 yearsI've misused the term debugging. The program was not written by me, so I am unfamiliar with its operation. I wanted to be able to step through every line to see how it works.
-
Dave Swersky over 13 yearsYou can set a breakpoint at the first line of execution, then step through the execution line-by-line (can't remember the keyboard shortcut.)
-
Ying Chan over 13 yearsI might be doing it wrong.. but from my experience this doesn't catch code that is run within events without the use of breakpoints.
-
Ying Chan over 13 yearsthis sounds like the perfect solution for me. Is it available for Professional? I'm currently researching this and will update
-
ShockwaveNN over 13 yearsUnfortunately not, this is one of the features that's only available with Visual Studio Ultimate :(
-
ShockwaveNN over 13 yearsAlso, I believe you can download the trial version of Ultimate.
-
Ying Chan over 13 yearsthats what i'm doing right now :) I'm particularly excited about the "time travelling" feature. if intellitrace is enabled, are you still able to step through code at the same time?
-
ShockwaveNN over 13 yearsYup, IntelliTrace is a debug-time feature, I believe you can step through the code either normally with F10.
-
Rob3C over 11 yearsCan't believe I haven't been using "Break All" - exactly what I needed.
-
David says Reinstate Monica over 10 yearsWhat do you mean by pause? I only see a
Break All
button, and that doesnt work for your method. -
and_the_rand over 10 years@Dgrin91: This was 3.5 years ago but that doesn't work isn't much help. Perhaps a new question is in order.
-
David says Reinstate Monica over 10 years@AustinSalonen Per your request: stackoverflow.com/questions/22696787/…
-
Debashis Panda about 9 years@AustinSalonen => Thank you for the steps. I just had to modify a little to make it work for me. 1. Start the App with the debugger or attach to process 2. Go to the step before the intended click 3. On VS2010 Click on Break All (Ctrl + Alt + Break) or the '||' on the debug toolbar. 3. Go back to app and click on button 4. come back to debugger and use the "Step into" (F11) option. Visual studio breaks at the event handler method.