Reputation: 99408
I use pdb.set_trace()
in a script to set a breakpoint.
But I can't figure out why the function is called set_trace
.
It seem that trace
often appears in discussion of executing or debugging a program.
What does trace
mean in the executing or debugging a program?
Thanks.
Upvotes: 1
Views: 2047
Reputation: 375524
The Python debugger is implemented on top of the sys.settrace
function. This is a way to register a Python function that will be invoked for every line of code executed. As the Python interpreter executes your code, it will call the trace function for each line it encounters. The trace function can do whatever it likes.
The debugger has a trace function that it uses to track the execution of your code. It examines the current stack frame to see if you've gotten to a breakpoint, for example. pdb.set_trace
means, "set the pdb trace function as the trace function with sys.settrace."
It's not a good name, because it describes how the function is implemented, rather than what it does for the user.
Upvotes: 3
Reputation: 780843
As with many computer terms, it's a metaphor for something in the real world. Here are relevant dictionary definitions of trace
Tracking the progress through a computer program is analogous to following the path of something that has passed.
Usually when we refer to tracing in general, it's a debugging application that shows all the activities of a program. Setting a breakpoint is considered a subset of this.
Upvotes: 1