+ All Categories
Home > Technology > So you think you can pdb?

So you think you can pdb?

Date post: 04-Dec-2014
Category:
Upload: clayton-parker
View: 656 times
Download: 1 times
Share this document with a friend
Description:
An intro to using PDB. Overview and example usage of all the basic commands.
25
So You Think You Can PDB? Clayton Parker - PyOhio 2014 So You Think You Can PDB? - Clayton Parker - PyOhio 2014
Transcript

So You Think You Can PDB?Clayton Parker - PyOhio 2014

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Who am I?Director of Development at Six Feet Upclaytron on the internets

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

What is PDB?Interactive debugging toolPure awesome

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

How to invoke it?Set a trace directly in the code:

import pdb; pdb.set_trace()

Or start a script with pdb directly:

$ python -m pdb example.py

It is that easy!

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Now what?Common commandsNavigating the stack

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

HelpType help or ? for short to know what commands are available

Further help on commands help help or help list

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Show the current contextType list or l to see the current position in the code

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Repeating the last commandJust type return

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Examine variablesType print or p to see what a variable is set to

Use pp to pretty print the result for easier reading

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Go to the next lineType next or n to go to the next line

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Step into a functionType step or s to step into a function for further inspection

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Skip over a loopType until or u to skip over the end of a loop

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Skip to the end of a functionType return or r to go to the end of a function

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

BreakpointsType break or b to see a list of breakpoints

Then b and a line number to set one

To clear out a breakpoint clear or cl and a breakpoint number

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Continue executionType continue or c to go to the next breakpoint or finishexecution

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Conditional breakpointsBreakpoints can take an expression to know when to break:

b 11, this_year == 2014

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

See where you are in thestackType where or w to see the current stack

You can debug at any point in the stack

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

Traverse the stackType up or u to go up the stackType down or d to go back down the stack

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

New features in Python 3:InteractType interact to open an interpreter in the current scope

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

New features in Python 3:Long listType longlist or ll to show the complete current function

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

All doneType quit or q to exit pdb and stop execution

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

PDB AlternativesPDB++ipdbrpdb / remote-pdb

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

HelpersPdbSublimeTextSupportvimpdbflake8-debugger

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

.pdbrcPersonalize your experience

Set up aliases / custom mappingsEnhance with readline support

So You Think You Can PDB? - Clayton Parker - PyOhio 2014

LinksPython Module of the Week: PDBIn Depth PDB - Nathan Yergler

So You Think You Can PDB? - Clayton Parker - PyOhio 2014


Recommended