Write My Paper Button

WhatsApp Widget

Debugging Process | My Assignment Tutor

DebuggingDebugging is the process of finding and resolving defects or problems within a computerprogram that prevent correct operation of computer software or a system. Debugging tacticscan involve interactive debugging, control flow analysis, unit testing, integration testing, logfile analysis, monitoring at the application or system level, memory dumps, and profiling.Debugging ProcessSo the process of using the … Continue reading “Debugging Process | My Assignment Tutor”

DebuggingDebugging is the process of finding and resolving defects or problems within a computerprogram that prevent correct operation of computer software or a system. Debugging tacticscan involve interactive debugging, control flow analysis, unit testing, integration testing, logfile analysis, monitoring at the application or system level, memory dumps, and profiling.Debugging ProcessSo the process of using the debugger involves• setting breakpoints• stepping through the source code one line at a time• inspecting the values of variables as they change• making corrections to the source as bugs are found• rerunning the program to make sure the fixes are correctDebugging under IDLEIDLE has a debugger built into it. It is very useful for stepping through a program andwatching the variables change values.In the Shell window, click on the Debug menu option at the top and then on Debugger. Youwill see a “Debug Control” window like thisNotice that the Shell shows “[DEBUG ON]”.Explanations of a few other things in the Debug Control window• Over means that if the statement to be executed has a function call in it, go off and dothe function call without showing any details of the execution or variables, then returnand give the human control again, “step over the function”• Out assumes you are in some function’s code, finish execution of the function atnormal speed, return from the function and then give the human control again, “stepout of the function”• Quit stops the execution of the entire programFor the debugger to be most useful, you need to set a breakpoint in your source code beforeyou start running the program. A breakpoint is a marker on your code that tells the debugger“run to this point at normal speed, then pause and let the human have control”. You can havemany of them; in more complex programs you would need them at different places. RIGHTclick on a line of your source and choose “set breakpoint”.The background of the line you click on turns yellow to show the line marked with thebreakpoint.If you don’t put any breakpoints in your source, when you run it with the debugger on, it willpause at the first line of executable code (may be an import statement or a call to main()) butthen will run your program normally (i.e. with no pauses).Now run the program with F5 as usual.Note that the Debug Control window is opened and that the blue line states that the line “frommath import pi” is ready to be executed (the 7 is for line number 7 in the source file).From this point you can click the Go button near the top of the window. This will make theprogram run at normal speed until a breakpoint is encountered (or input is requested or theprogram finishes). You can also use the Step button to step through your code, one line at atime. This button is used quite a lot. If the line being stepped through has a function call,execution will go to the first line of the function definition (you are “stepping into” thefunction). If the line being stepped through doesn’t have a function call, the line is executed.In either case, then control goes back to the human.When you execute a line that has input in it, the debugger seems to shut down but it has not.If you bring up the Shell window you can see that the program is waiting for input. Makesure your cursor is in the right place on the window and give it some input and press Enter asusual.There are several things to note about this picture. The Shell window is in the background, itshows that the user entered 23 and pressed Enter. The Debug Control window shows thatexecution has moved on to the next line of code. Also, at the bottom of that window there is apane that says “Locals” and it shows the value of radius to be ’23’. This is useful in severalways. It shows the values of variables as they change, and it shows the types of variables.Note that the value of radius has quotes around it. This means that it is a string value.Click the Step button again.Note that the new variable height has been created and has a value of ’14’.Click the Step button again.Notice that there is an error in the run of the program at this point (the yellow bar in theDebug Control window). The interpreter is saying that it cannot multiply “sequence by nonint of type ‘float’”. What it means is that the two input variables are of the wrong type to becombined with numeric types. This has to be corrected before any more debugging takesplace. This is fixed by using the eval function in the two input statements.“You can only toggle the debugger when idle” If you get this message in a window when youtry to turn the debugger on, try clicking on the Quit button in the Debug Control window. Ifthat does not help, try shutting down the program file and reopening it. If that does not help,shut down Python completely and restart it from scratch.Note that the bugs in the input statements have been fixed with the addition of “eval”. Thebreakpoint was put in again. Breakpoint locations are not saved with the program; they haveto be set again for every debugging session.Note the type of the Local variables in this image. They don’t have the quotes around thevalues any more! They are numbers now.As you step through the program one statement at a time, you can see more variables getvalues. When we come to the next bug you can see that the variable Pi is not the same as thevariable pi, which is defined in the math library. This bug would need to be fixed, then thedebugging would continue. Another Option:The module pdb defines an interactive source code debugger for Python programs. Itsupports setting (conditional) breakpoints and single stepping at the source line level,inspection of stack frames, source code listing, and evaluation of arbitrary Python codein the context of any stack frame. It also supports post-mortem debugging and can becalled under program control.The debugger is extensible — it is actually defined as the class Pdb. This is currentlyundocumented but easily understood by reading the source. The extension interfaceuses the modules bdb and cmd.The debugger’s prompt is (Pdb). Typical usage to run a program under control of thedebugger is: import pdb import mymodule pdb.run(‘mymodule.test()’)> (0)?()(Pdb) continue> (1)?()(Pdb) continueNameError: ‘spam’> (1)?()(Pdb)pdb.py can also be invoked as a script to debug other scripts. For example:python -m pdb myscript.pyThe typical usage to break into the debugger from a running program is to insertimport pdb; pdb.set_trace()There are a few commands we can use with pdb are as follows.Some useful ones to remember are:• b: set a breakpoint• c: continue debugging until you hit a breakpoint• s: step through the code• n: to go to next line of code• l: list source code for the current file (default: 11 lines including the line beingexecuted)• u: navigate up a stack frame• d: navigate down a stack frame• p: to print the value of an expression in the current context

Don`t copy text!
WeCreativez WhatsApp Support
Our customer support team is here to answer your questions. Ask us anything!
???? Hi, how can I help?