Upgrade to Pro — share decks privately, control downloads, hide ads and more …

2017 - Peter Hadlaw - Intro to pdb

PyBay
August 13, 2017

2017 - Peter Hadlaw - Intro to pdb

PyBay

August 13, 2017
Tweet

More Decks by PyBay

Other Decks in Programming

Transcript

  1. INTRO TO pdb Peter Hadlaw @ Tesorio August 13, 2017

    https://www.tesorio.com/careers
  2. CONS: Limited (can't interrupt execution) Messy (lot's of clean up)

    Zero interactivity (need to modify code and run everything again) Much harder to dive deeper into third party code (internal or external alike)
  3. DEBUGGER Exist in many languages and platforms Python's built-in debugger

    is... "A computer program that assists in the detection and correction of errors in computer programs."
  4. pdb

  5. THREE EASY STEPS 1. Set a breakpoint 2. Run program

    3. Execution halts at breakpoint and now, you, interact
  6. SETTING A BREAKPOINT import pdb; pdb.set_trace() Using a one liner

    is a nice habit to make clean up easier (e.g. a single dd in vi).
  7. GENERAL FLOW Use l to orient yourself and inspect what

    code is currently being executed. Use n to step forward in execution Use s to dive deeper Create expressions for the debugger to evaluate and gain insights into what's happening c to continue execution until next breakpoint / finish Profit.
  8. NOTES More commands and features available iPython version, much more

    powerful (has to be installed separately) Other languages have debuggers to, for example JavaScript in the browser, or C (gdb)