Introduction to the Python Debugger (pdb)

Post on 28-Nov-2014

1.556 views 2 download

description

Python pdb-meetup-bcn

Transcript of Introduction to the Python Debugger (pdb)

Introduction to the Python debugger (pdb)

@raulcumplido

Usages of pdb

Invoked as a script

Post Mortem Mode

Run Mode

Trace Mode

Invoked as a script

~$ python -m pdb test.py

~$ python -m pdb –c continue test.py

~$ python -i test.py

Only Python 3.2+

Post Mortem Mode

pdb.pm()

Post Mortem Mode>>> import pdb >>> import mymodule >>> mymodule.test() Traceback (most recent call last): File "<stdin>", line 1, in ? File "./mymodule.py", line 4, in test test2() File "./mymodule.py", line 3, in test2 print spam NameError: spam >>> pdb.pm() > ./mymodule.py(3)test2() > -> print spam (Pdb)

Run Mode

pdb.run(statement[, globals[, locals])

pdb.runeval(expression[globals[, locals])

pdb.runcall(function[, argument, ...])

Run Mode

>>> import pdb >>> import mymodule >>> pdb.run('mymodule.test()') > <string>(0)?() (Pdb) continue NameError: 'spam' > <string>(1)?() (Pdb)

Trace Mode

pdb.set_trace()

Debugger tips

• Entering a blank line repeats(except list)

• Commands not recognized are executed–When exception nothing

changes• Support for aliases

Debugger commands

h(elp) [command]

Debugger commands

w(here)

Debugger commands

d(own) u(p)

Debugger commands

s(tep)

Debugger commands

n(ext)

Debugger commands

unt(il)

Debugger commands

c(ont(inue))

Debugger commands

j(ump) lineno

Debugger commands

l(ist) [first[, last]]

Debugger commands

a(rgs)

Debugger commands

p expression pp expression

Debugger commands

[!]statement

Debugger commands

q(uit)

We’re hiring!

Raúl Cumplido | @raulcumplido raul@catchoom.com | +34 627566095

catchoom.com | @catchoom