Trace functions: Building a tiny debugger
summary
Shows how to use sys.settrace and a returned local tracer to build a tiny pdb replacement that actually works: captures events call, line, return and exception, reads source with inspect to print context, evaluates expressions with frame.f_globals/frame.f_locals, and uses sys.getframe to place the breakpoint at the caller. Implements commands: quit, continue, step/step‑into, jump‑to‑return and list with numbered context; demo proves the debugger runs and the main limitation is needing a small getframe hack to trace the exact breakpoint location.
AI-written summary · about
chapters (9)
- 0:00Introduction and setup
- 1:00Debugging basics with pdb
- 2:22Understanding trace functions
- 4:22Inspecting code execution
- 8:35Building an interactive REPL
- 10:34Adding evaluation and control
- 12:50Implementing stepping
- 15:25Advanced debugger features
- 19:37Conclusion and Q&A
related talks
28mWhat makes a Python debugger possible and how can we make it 100x faster
50mHow I built a power debugger out of the standard library and things I found on the internet
24mLet’s Rethink Debugging
27mThe Hidden Power of the Python Runtime
40mSo you think you can PDB?
06mImproving Debuggability with GDB's Python API
30mPython 3.12's new monitoring and debugging API
41mAdvanced Python Debugging Techniques Using GDB
