About Debugging
Starting a debugger,
- start button
- menu, debug, start degugger
- shortcut f5
Stopping debugger,
- stop button
- menu, debug, stop debugging
- shift + f5
Inserting a breakpoint,
- clicking on the left margin on that line
- r-click on that line and breakpoint, insert breakpoint
- f9
When r-clicking on left margin, we get options for different types of breakpoints.
We can also have a normal breakpoint, and if you r-click on it, it shows add conditions etc.
For conditions, we can have a conditional expression. And we have a hit count that may be used in a loop for a specific loop that we want to see.
A tracepoint, which may be used to print out some values in the output window, does not get ‘hit’, i.e. does not break the execution, it just prints the values. It basically is a breakpoint with ‘Actions’ added to it and ‘continue execution’ checked.
A temporary breakpoint, it just hits once and is then removed at this point.
A dependent breakpoint, it hits depending on whether another breakpoint also hit. Useful in scenario, ex. a log message method called from various places. We want a particular caller method hit and only then this log method should hit.
Want to add a breakpoint to a method but don’t know its location. So, menu, debug, add a breakpoint, function breakpoint. We basically provide the method name, and it doesn’t show the breakpoint anywhere, but will actually hit that method when executing. It works for all code, no need to open files and insert breakpoints. For method name, optionally we can give full signature for better matching.
To see all breakpoints, menu, debug, windows, breakpoints. Here you can see all of them, and delete them or export them etc.
When debugger working and breakpoint hit, we can step over by either the button on top, or in menu, debug or simply f10. This will take it to next statement.
If a statement calls a method and we want to go inside, we do step into by either button on top, or menu, debug or simply f11. This will take up into that called method.
Now, when into this called method, if we want to go back to the caller method, we do step out by either the button on top, or menu, debug or simply shift + f11. This takes us back to the caller method from where we came here.
While execution, we see the execution pointer in the left margin which points what statement is executing right now. We can drag this execution pointer up and down.
One thing is that, of course, we can add breakpoints ‘while’ execution is going on. Like, we come to a method and now are a breakpoint somewhere else and hit f5, and it takes us here directly.
Also, when breakpoint hit, and we hover over any further line, we see a green button on the left of the line, it says ‘run execution to here’. Clicking it take the execution to this line. Also, in this, what if we have further breakpoints in between the current hit breakpoint and the line we’re trying to get to. So, when we hover over the line and see the green button, we press shift, and this shows ‘force run execution to here’. This skips the in between breakpoints and brings us here.
When program not running, we r-click on any line, there’s a button ‘run to cursor’. It starts the program and breakpoint hits on this line. It works as a temporary breakpoint. We can also do ‘force run to cursor’ button, which skips any breakpoints that may have been hit until this point.
When executing and breakpoint hit, we can see the ‘data tips’ to see any current data in any variable etc. Apart from this, we have various windows. Menu, debug, windows, here we have autos, locals etc.
Autos window, will show variables for the current executing line and maybe line before that.
Locals window, will show all variables in the current scope. Maybe like current method.
Watch windows, can be used to track any variable. We can r-click on any variable and ‘Add to watch’, and we can see it in the watch window.
Another window, Immediate window, which allows us to type any expression in the current context and get its result.
The Call Stack window, shows the calling path of methods, as to how we got here at this point.