Advanced debugging – tracing
Tracing of a program right from the beginning can often be used as an advanced debugging technique. Tracing allows a developer to trace program execution, find caller/callee relationships, and figure out all functions executed during the run of a program.
The trace module
Python comes with a default trace
module as part of its standard library.
The trace module takes one of the –trace
, --count
, or –listfuncs
options. The first option traces and prints all the source lines as they are executed. The second option produces an annotated list of files, which shows how many times a statement was executed. The latter simply displays all the functions executed by running of the program.
The following is a screenshot of the subarray problem being invoked by the –trace
option of the trace
module:
As you can see, the trace
module traced the entire program execution...