When would you use the debugger? One scenario would be if you're just not getting the right values returned out of your functions. Or your variables aren't being set to the values you'd expect. You could then debug it, set a breakpoint to where you think it's broken, and see exactly what the values are at that given moment in your program. Also, you could use the GPIO pins to light various LED's. As you step through your program, you'll see them turn on and off as you'd expect.
To use the debugger, open a python file, and click the "Debug" link in the toolbar:
Once the debugger is ready, you'll see the following:
The first think you'll notice is the toolbar (#1) has new buttons available:
- Save/Restart allows you to save your file, and restart the debugger for that file in one click. You can initiate that by hitting control-s, or command-s (on OS X).
- The Exit link will exit the debugger.
- The Run link will continue execution of your program either to the end, or to the next breakpoint you have enabled. If there is a breakpoint enabled (clicking in the gutter (#6)), it will stop there, and wait for your instruction.
- Step Over will step through your program line-by-line until it hits the end. This option will skip any function calls. So, if you have a function called foo(), it will just run the entire function, and move to the next line.
- Step In will step through your program as well, but it will jump into many of the functions, instead of skipping over them.
At the bottom two panels, you'll see the Debug Output (#3), and the Debug Variables (#4). The Debug Output displays anything from stdout or stderr that your program would output (such as print statements). The Debug Variables displays the live variables as they're being assigned.
The red line in the editor (#5) moves as you step through your program. It is the line that will execute next, and will stay centered in the editor window as you step through your program.
At the far left of the editor (#6), there is a blank space to the left of the line numbers. This is called the gutter. If you click in the gutter when the debugger is in a "Ready" state, you can add breakpoints. A breakpoint is useful for many situations, such as if you have a longer script, and there is a certain troubling section that is buggy. Instead of slowly stepping through your program you would set the breakpoint (a red square will appear in the gutter), and then click "Run". The script will execute to the breakpoint, and the red line will stop, and wait for you to continue stepping through it.
The last feature you'll want to be aware of is the debug status messages (#7). These will show you what the debugger is doing. For example, when it initially loads, or when you click "Save/Restart", it will be in an "Initializing..." state. When it's ready for your input, it will be "Ready". Some parts of your script will cause it to appear locked up, but it's really waiting for the server to return a response from your script (a long sleep() statement could cause this, for example).
At this point in the debug cycle, you could edit your file, and Save/Restart. You could continue stepping through the program, or you could Exit the debugger.