Tim
Tim

Reputation: 99408

What does "trace" mean in "pdb.set_trace()"?

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

Answers (2)

Ned Batchelder
Ned Batchelder

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

Barmar
Barmar

Reputation: 780843

As with many computer terms, it's a metaphor for something in the real world. Here are relevant dictionary definitions of trace

  • a mark or line left by something that has passed
  • a path, trail, or road made by the passage of animals, people, or vehicles

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

Related Questions