English subtitles

← Build my-spyder - Software Debugging

Get Embed Code
4 Languages

Showing Revision 3 created 05/24/2016 by Udacity Robot.

  1. The idea is to use this trace-it function to build your own interactive debugger.
  2. We're going to call this my spyder for my simple Python debugger
  3. with the idea of a spider being something that catches all the bugs.
  4. My spyder is a super simple debugger as it says in the name.
  5. My spyder is a command line debugger, so it prompts you to enter a command
  6. and the command can be something like break in line 70.
  7. Run the program and when it reaches line 70, it stops and as it has stopped,
  8. we can print individual variables--for instance, an x and x saying has a value of 42.
  9. How do we do that? We need the number of variables that controls how the debugger works.
  10. First, a variable name stepping which tells us whether we are
  11. stepping line by line through the program or whether we're just running the program.
  12. We also have a list of breakpoints, actually it's a mapping
  13. of individual line numbers to arbitrary values, but if this mapping say has an entry for the number 7,
  14. this means that whenever the debugger reaches line 7, then execution should stop.
  15. For our current setting, we'll make a lot simple. We'll have a number of predefined breakpoints.
  16. We will have for instance a breakpoint in line 9, and possibly another one in line 14.
  17. Our trace-it function is being called for every single line and of course we want our debugger to stop
  18. whenever either a breakpoint is reached or when we're stepping from one line to the next.
  19. We want to access these global variables, so we need to declare them accordingly.
  20. If the event is that we reached a new line, we check if we're stepping
  21. or if our breakpoints dictionary has a value for the current line
  22. and if this actually is the case, we print out a proper diagnostic information
  23. which may be helpful for the debugger--what has happened, where we currently are,
  24. the functions that executed as well as the local variables.