LECTURE NOTES CHAPTER 10 USING A DEBUGGER - programs rarely run perfectly the first time - frustrating to find bugs - logging - use to show key variables and program flow - time-consuming to insert and remove - as programs become longer, becomes less feasible - debugger - special program - packaged with most modern development environments - locate bugs by following the execution of the program - can't avoid using, because most efficient debugging tool - still takes time to run, so important to write best program possible initially - vary widely among systems - book shows Eclipse, which we are using - I'll be Eclipse specific, too - start by running in debug mode - debugger runs program until you tell it to stop - in Eclipse, can tell debugger to stop automatically at the first line of main - breakpoint - tell the debugger to pause the program when it gets to a certain line of code - can have multiple at a time - pauses the program at every breakpoint - next stop is the first breakpoint reached - should periodically clear unused breakpoints - when paused - look at current values of variables - purpose: verify all variables contain the expected values - variables window shows all variables in the current scope - useful for helping you understand scope! - inspect command - right click a variable in the code window - debugger shows you its current value - looking at objects: - in variable window, click + symbol - lets you inspect instance fields - how long to run before next pause - set another breakpoint (may depend on whether code working so far) - step - go through your code one line at a time - see how the code changes variables - see the program flow (how conditionals and loops depend on variables) - single step command - executes current line and stops at the next line - what happens when we get to a method call? - step into - jump to the method code - purpose: check if the method carries out its job correctly - step over - skip over this method - still executes the method - you continue on the next line after the method - purpose: streamline debugging when know method already works - debugger stops when program terminates - can rerun program in debugger - find a bug - for now, exit debugger, fix bug, re-enter debugger - some debuggers let you edit code on the fly and continue debugging!