Introduction to the Python Debugger (pdb)

24
Introduction to the Python debugger (pdb) @raulcumplido

description

Python pdb-meetup-bcn

Transcript of Introduction to the Python Debugger (pdb)

Page 1: Introduction to the Python Debugger (pdb)

Introduction to the Python debugger (pdb)

@raulcumplido

Page 2: Introduction to the Python Debugger (pdb)

Usages of pdb

Invoked as a script

Post Mortem Mode

Run Mode

Trace Mode

Page 3: Introduction to the Python Debugger (pdb)

Invoked as a script

~$ python -m pdb test.py

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

~$ python -i test.py

Only Python 3.2+

Page 4: Introduction to the Python Debugger (pdb)

Post Mortem Mode

pdb.pm()

Page 5: Introduction to the Python Debugger (pdb)

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)

Page 6: Introduction to the Python Debugger (pdb)

Run Mode

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

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

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

Page 7: Introduction to the Python Debugger (pdb)

Run Mode

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

Page 8: Introduction to the Python Debugger (pdb)

Trace Mode

pdb.set_trace()

Page 9: Introduction to the Python Debugger (pdb)

Debugger tips

• Entering a blank line repeats(except list)

• Commands not recognized are executed–When exception nothing

changes• Support for aliases

Page 10: Introduction to the Python Debugger (pdb)

Debugger commands

h(elp) [command]

Page 11: Introduction to the Python Debugger (pdb)

Debugger commands

w(here)

Page 12: Introduction to the Python Debugger (pdb)

Debugger commands

d(own) u(p)

Page 13: Introduction to the Python Debugger (pdb)

Debugger commands

s(tep)

Page 14: Introduction to the Python Debugger (pdb)

Debugger commands

n(ext)

Page 15: Introduction to the Python Debugger (pdb)

Debugger commands

unt(il)

Page 16: Introduction to the Python Debugger (pdb)

Debugger commands

c(ont(inue))

Page 17: Introduction to the Python Debugger (pdb)

Debugger commands

j(ump) lineno

Page 18: Introduction to the Python Debugger (pdb)

Debugger commands

l(ist) [first[, last]]

Page 19: Introduction to the Python Debugger (pdb)

Debugger commands

a(rgs)

Page 20: Introduction to the Python Debugger (pdb)

Debugger commands

p expression pp expression

Page 21: Introduction to the Python Debugger (pdb)

Debugger commands

[!]statement

Page 22: Introduction to the Python Debugger (pdb)

Debugger commands

q(uit)

Page 24: Introduction to the Python Debugger (pdb)

We’re hiring!

Raúl Cumplido | @raulcumplido [email protected] | +34 627566095

catchoom.com | @catchoom