Download presentation
Presentation is loading. Please wait.
1
Debuggers and Debugging
Professor Hugh C. Lauer CS-1004 — Introduction to Programming for Non-Majors (Slides include materials from Python Programming: An Introduction to Computer Science, 2nd edition, by John Zelle and copyright notes by Prof. George Heineman of Worcester Polytechnic Institute) CS-1004, A-Term 2014 Debuggers and Debugging
2
Debuggers and Debugging
A program that “runs” another program so that You can cause it to stop or pause at designated places Examine the values of variables when stopped See where it has been called from Step one statement at a time Step over entire functions … Essential to program development in all modern languages It is too difficult … … for ordinary humans … … to develop non-trivial programs … without the aid of a debugger CS-1004, A-Term 2014 Debuggers and Debugging
3
Debuggers and Debugging
Breakpoint A “flag” inserted into code to cause running program to suspend just before executing that statement Return control to debugger In Python:– Interpreter notices flag Calls debugger In compiled languages Debugger inserts special machine instruction in compiled code Triggers “interrupt” Interrupt-handler in OS transfers control to debugger Debugger may resume execution of running program As if nothing had happened (except passage of time) CS-1004, A-Term 2014 Debuggers and Debugging
4
Breakpoint (continued)
Debugger “knows” the source code i.e., which line is currently executing which line will execute next where variables are stored what variables are currently being changed In Python, because it is interpreted language In compiled languages, compiler plants extra info in machine code to connect to source code Go Debugger command to program to run normally until a breakpoint CS-1004, A-Term 2014 Debuggers and Debugging
5
Debuggers and Debugging
Single-step Debugger places flag in interpreter or processor to suspend execution at every statement Python interpreter “knows” whenever it is starting a new statement E.g., next statement in-line Branch of if-else Loop iteration … In compiled languages, Special modes in processor CS-1004, A-Term 2014 Debuggers and Debugging
6
Single-step scenarios
Simple Python statements Stops at start of every statement Function call, or Expression containing function call Stops at first statement inside function Function return Stops at first statement after function call (including first statement inside another function) (not including system & library functions) CS-1004, A-Term 2014 Debuggers and Debugging
7
Debuggers and Debugging
Clear Breakpoint Removes breakpoint Handy when you are satisfied with a piece of code and want to go on to debug next piece CS-1004, A-Term 2014 Debuggers and Debugging
8
Debuggers and Debugging
Questions? CS-1004, A-Term 2014 Debuggers and Debugging
9
Debuggers and Debugging
Step Over Debugger places (temporary) breakpoint at start of next statement Or function call, etc. Runs freely until next breakpoint (Temporary) breakpoint placed above Any other breakpoint CS-1004, A-Term 2014 Debuggers and Debugging
10
Debuggers and Debugging
Step Out Find caller of current function Place (temporary) breakpoint immediately after that call At start of next statement CS-1004, A-Term 2014 Debuggers and Debugging
11
Debuggers and Debugging
Viewing variables IDLE debugger lists all variables in current scope of current function Click on call history to see variables in scope of calling function(s) Can maneuver up and down ‘call stack’ Check source box to track execution i.e., highlight each line as it is executing Check the box to show globals I.e., variables, etc., defined outside of any function CS-1004, A-Term 2014 Debuggers and Debugging
12
Debuggers and Debugging
Questions? CS-1004, A-Term 2014 Debuggers and Debugging
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.