When do you use the debugger?

...when your program compiles but isn't doing what you want, e.g., wrong output, infinite looping.

 

What can the debugger do?

Stop the program in the middle of execution and see what values variables have at that point. Run the program line by line. Keep track of function calls: which functions, with what arguments, how many times, etc.

 

What does this mean?

yellow arrow - This marks the next line the debugger will execute. As long as this mark appears next to a line, its execution has not completed.

breakpoint - If you want the debugger to run the program up to a certain line, set a breakpoint there and click Go or press F5. A red dot appears next to each breakpoint you set.

step over - Run the program to the next line.

step into - If the current line has a function call, rather than executing it in one step (as step over would do), the execution steps through the function's lines (the definition), one by one. (This is why it's called stepping into.)

 

When do I use step over, step into?

Step over lines with functions that you didn't write (e.g., printf) or that you're sure are working properly. Step into functions of your own which need debugging, i.e., which are not working the way you want.

 

When do I use breakpoints?

Breakpoints are handy when you know that large sections of your code are bug-free (not so easy!) and you've narrowed down your problems to a few spots in your program. Placing breakpoints just before these possibly buggy sections and stepping line by line from that point is a good debugging strategy.

If you run a program in the debugger (as opposed to stepping it) without any breakpoints set, it'll just run straight through without stopping anywhere, just like if you ran it outside the debugger.