SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Downloaden Sie, um offline zu lesen
PDB LIKE A PRO
PHILIP BAUER
@StarzelDe
pbauer
pdb like a pro
THE BASICS
PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016
The Basics
▸ l[ist]

List source code for the current file
▸ n[ext]

Continue execution until the next line
▸ s[tep] 

Execute the current line, stop at the first possible occasion
▸ r[eturn]

Continue execution until the current function returns
▸ c[ontinue]

Continue execution, only stop when a breakpoint is encountered
PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016
The Basics II
▸ w[here] 

Show stack trace. Recent frame at bottom
▸ u[p] 

Move to older frame in stack trace
▸ d[own] 

Move to newer frame in stack trace
▸ b[reakpoint] 

Set a new breakpoint. tbreak Temporary breakpoint
▸ a[rgs]

Print the argument list of the current function.
PIMP MY PDB
PIMP MY PDB
Some Enhancements
▸ pdb++
▸ ipdb
▸ bpdb
▸ pudb
▸ and…
PIMP MY PDB
pdb in python 3.2+
▸ ll | longlist

List all source code for the current function or frame.
▸ source

Try to get source code for the given object and display it.
▸ …
PIMP MY PDB
ipdb
▸ + features
▸ - dependencies
▸ - weird sqllite
▸ - need to use ``import ipdb; ipdb.set_trace()``
PIMP MY PDB
pudb
▸ + features
▸ +/- UI
▸ - need to use import pudb; pudb.set_trace()
TEXT
PIMP MY PDB
▸ it’s actually called pdbpp
▸ + features
▸ + no problematic dependencies
▸ + drop-in-replacement
▸ - needs configuration to not break readline
pdb++
DEMO PDB++
PIMP MY PDB
pdb++
▸ you’ll need a file ~/.fancycompleterrc.py
pdb++
▸ Syntax highlighting
▸ ll | longlist

List all source code for the current function or frame.
▸ track EXPRESSION
▸ display EXPRESSION
▸ source EXPRESSION
▸ obj?
▸ obj.__class__??
▸ Sticky mode
PIMP MY PDB
Give pdb++ a try!
The person you trust
PIMP MY PDB
INTROSPECTION
INTROSPECTION
python stuff you should know
▸ dir(obj) - bäh!
▸ help(obj)
▸ help(obj.__class__)
▸ pp locals()
▸ obj.__dict__
▸ obj.__class__.__dict__
▸ pp dict(obj.__class__.__dict__)
INTROSPECTION
the inspect module
▸ It’s what is used by other nice tools
▸ import inspect
▸ print inspect.getsource(obj.__class__)
▸ inspect.getmro(obj.__class__)
ADVANCED TIPS
▸ break if some condition applies
▸ very useful in loops
▸ you need it in try/except blocks (e.g. indexing)
TIPS AND TRICKS
Conditional Breakpoints
TIPS AND TRICKS
debug
▸ Call any code and step into it with a pdb in a pdb
▸ You need to step into it after calling it!
▸ (Pdb++) self.context

<Document at /Plone/startseite>

(Pdb++) debug self.context.canSetLayout()

ENTERING RECURSIVE DEBUGGER

((Pdb++)) s

--Call--

[2] >[…]/Products/CMFDynamicViewFTI/
browserdefault.py(183)canSetLayout()

((Pdb++)) ll

183 -> @security.public

184 def canSetLayout(self):

186 mtool = getToolByName(self, 'portal_membership')
DEMO DEBUG
▸ Whenever there is a traceback you end up in a pdb!
▸ try:

run_your_stuff()

except:

import pdb; pdb.set_trace()
▸ Plone: Products.PDBDebugMode
▸ Disable when migrating/reindexing
TIPS AND TRICKS
Post-Mortem Debugging
▸ Drops you in a pdb whenever a test fails or errors
▸ Zope/Plone: bin/test -D

pytest & nosetest: pytest / nosetest --pdb

unittest: need to wrap in try/except
▸ Test-Driven Debug-Driven Development
TIPS AND TRICKS
Post-Mortem Testing
pdb like a pro
▸ add a config-file ~/.pdbrc
▸ alias inspect import inspect;

print inspect.getsource(%1)
▸ alias help !print help(%1)
TIPS AND TRICKS
Customize your pdb
TEXT
Sentry
▸ Collect tracebacks from production-environments
▸ The traceback includes all arguments for all stacks
▸ OpenSource / Django
▸ github.com/getsentry/sentry
▸ Available as a service: sentry.io
▸ starzel.de is working on a DebOps/Ansible role for Sentry
SUMMARY
SUMMARY
What to take away
▸ learn the basics
▸ try pdb++
▸ learn introspection
▸ try debug callable()
▸ use post-mortem-debugging
▸ always use pretty-print
▸ use Sentry to debug errors on production
QUESTIONS
Philip Bauer
@StarzelDe
pbauer
All Fotos by Philip Bauer. Taken in Boothbay, Maine October 2016

Weitere ähnliche Inhalte

Was ist angesagt?

Garbage Collection
Garbage CollectionGarbage Collection
Garbage CollectionEelco Visser
 
Intoroduction of py7zr
Intoroduction of py7zrIntoroduction of py7zr
Intoroduction of py7zrHiroshi Miura
 
3. basic data structures(2)
3. basic data structures(2)3. basic data structures(2)
3. basic data structures(2)Hongjun Jang
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06Niit Care
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsLuka Zakrajšek
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guideArulalan T
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTFramgia Vietnam
 
A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)John(Qiang) Zhang
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTEr. Ganesh Ram Suwal
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibMarc Gouw
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdbOwen Hsu
 

Was ist angesagt? (20)

Garbage Collection
Garbage CollectionGarbage Collection
Garbage Collection
 
Introduction to cython
Introduction to cythonIntroduction to cython
Introduction to cython
 
Intoroduction of py7zr
Intoroduction of py7zrIntoroduction of py7zr
Intoroduction of py7zr
 
Note
NoteNote
Note
 
3. basic data structures(2)
3. basic data structures(2)3. basic data structures(2)
3. basic data structures(2)
 
Using zone.js
Using zone.jsUsing zone.js
Using zone.js
 
3 rd animation
3 rd animation3 rd animation
3 rd animation
 
Maintainable go
Maintainable goMaintainable go
Maintainable go
 
Aae oop xp_06
Aae oop xp_06Aae oop xp_06
Aae oop xp_06
 
Let's Go-lang
Let's Go-langLet's Go-lang
Let's Go-lang
 
Emscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math opsEmscripten, asm.js, and billions of math ops
Emscripten, asm.js, and billions of math ops
 
Go for Rubyists
Go for RubyistsGo for Rubyists
Go for Rubyists
 
matplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guidematplotlib-installatin-interactive-contour-example-guide
matplotlib-installatin-interactive-contour-example-guide
 
Some Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDTSome Tricks in Using Terminal - KienDT
Some Tricks in Using Terminal - KienDT
 
A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)A useful tools in windows py2exe(optional)
A useful tools in windows py2exe(optional)
 
STACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LISTSTACK IMPLEMENTATION USING SINGLY LINKED LIST
STACK IMPLEMENTATION USING SINGLY LINKED LIST
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
Pollyfills in JavaScript
Pollyfills in JavaScriptPollyfills in JavaScript
Pollyfills in JavaScript
 
ECMA Script
ECMA ScriptECMA Script
ECMA Script
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 

Ähnlich wie pdb like a pro

Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationGlobalLogic Ukraine
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talkabrummett
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MoreMatt Harrison
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneDavid Glick
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by exampleYunWon Jeong
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfssuser02936f
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbSenthilKumar Selvaraj
 
1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.pptAmritMarwaha1
 
Tools for maintaining an open source project
Tools for maintaining an open source projectTools for maintaining an open source project
Tools for maintaining an open source projectAll Things Open
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+Romain Dorgueil
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Romain Dorgueil
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilPôle Systematic Paris-Region
 
Python advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksPython advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksJohn(Qiang) Zhang
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.Mosky Liu
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance PythonIan Ozsvald
 

Ähnlich wie pdb like a pro (20)

Boost.Python: C++ and Python Integration
Boost.Python: C++ and Python IntegrationBoost.Python: C++ and Python Integration
Boost.Python: C++ and Python Integration
 
Devel::hdb debugger talk
Devel::hdb debugger talkDevel::hdb debugger talk
Devel::hdb debugger talk
 
PyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and MorePyCon 2013 : Scripting to PyPi to GitHub and More
PyCon 2013 : Scripting to PyPi to GitHub and More
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting PloneWhen Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
When Good Code Goes Bad: Tools and Techniques for Troubleshooting Plone
 
PyCon KR 2019 sprint - RustPython by example
PyCon KR 2019 sprint  - RustPython by examplePyCon KR 2019 sprint  - RustPython by example
PyCon KR 2019 sprint - RustPython by example
 
Lecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdfLecture 2 - C Programming.pdf
Lecture 2 - C Programming.pdf
 
Debugging Modern C++ Application with Gdb
Debugging Modern C++ Application with GdbDebugging Modern C++ Application with Gdb
Debugging Modern C++ Application with Gdb
 
1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt1B-Introduction_to_python.ppt
1B-Introduction_to_python.ppt
 
Tools for maintaining an open source project
Tools for maintaining an open source projectTools for maintaining an open source project
Tools for maintaining an open source project
 
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+EuroPython 2017 - Bonono - Simple ETL in python 3.5+
EuroPython 2017 - Bonono - Simple ETL in python 3.5+
 
Testing Workshop
Testing WorkshopTesting Workshop
Testing Workshop
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017Simple ETL in python 3.5+ with Bonobo - PyParis 2017
Simple ETL in python 3.5+ with Bonobo - PyParis 2017
 
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain DorgueilSimple ETL in python 3.5+ with Bonobo, Romain Dorgueil
Simple ETL in python 3.5+ with Bonobo, Romain Dorgueil
 
Python advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocksPython advanced 3.the python std lib by example – application building blocks
Python advanced 3.the python std lib by example – application building blocks
 
Python lecture 02
Python lecture 02Python lecture 02
Python lecture 02
 
Programming with Python - Adv.
Programming with Python - Adv.Programming with Python - Adv.
Programming with Python - Adv.
 
Python and You Series
Python and You SeriesPython and You Series
Python and You Series
 
Euro python2011 High Performance Python
Euro python2011 High Performance PythonEuro python2011 High Performance Python
Euro python2011 High Performance Python
 

Mehr von Philip Bauer

Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesPhilip Bauer
 
Migrations migrations migrations
Migrations migrations migrationsMigrations migrations migrations
Migrations migrations migrationsPhilip Bauer
 
Plone ♥︎ Python 3
Plone ♥︎ Python 3Plone ♥︎ Python 3
Plone ♥︎ Python 3Philip Bauer
 
Mosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedMosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedPhilip Bauer
 
Upgrade to Plone 5
Upgrade to Plone 5Upgrade to Plone 5
Upgrade to Plone 5Philip Bauer
 
Migrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesMigrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesPhilip Bauer
 
It's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesIt's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesPhilip Bauer
 
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Philip Bauer
 
Plone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPlone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPhilip Bauer
 

Mehr von Philip Bauer (10)

Growing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaisesGrowing pains - PosKeyErrors and other malaises
Growing pains - PosKeyErrors and other malaises
 
Migrations migrations migrations
Migrations migrations migrationsMigrations migrations migrations
Migrations migrations migrations
 
Plone ♥︎ Python 3
Plone ♥︎ Python 3Plone ♥︎ Python 3
Plone ♥︎ Python 3
 
Mosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always WantedMosaic - The Layout Solution You Always Wanted
Mosaic - The Layout Solution You Always Wanted
 
Upgrade to Plone 5
Upgrade to Plone 5Upgrade to Plone 5
Upgrade to Plone 5
 
Migrations, Upgrades and Relaunches
Migrations, Upgrades and RelaunchesMigrations, Upgrades and Relaunches
Migrations, Upgrades and Relaunches
 
Pimp my Plone
Pimp my PlonePimp my Plone
Pimp my Plone
 
It's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypesIt's the way of the present - Why you should use plone.app.contenttypes
It's the way of the present - Why you should use plone.app.contenttypes
 
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
Alles in Allem. Wie man mit Deliverance existierende Inhalte oder Anwendungen...
 
Plone-Content-Typen mit Dexterity
Plone-Content-Typen mit DexterityPlone-Content-Typen mit Dexterity
Plone-Content-Typen mit Dexterity
 

Kürzlich hochgeladen

Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmonyelliciumsolutionspun
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesShyamsundar Das
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIIvo Andreev
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorShane Coughlan
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesSoftwareMill
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...OnePlan Solutions
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLAlluxio, Inc.
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageDista
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionsNirav Modi
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyRaymond Okyere-Forson
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Jaydeep Chhasatia
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfTobias Schneck
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampVICTOR MAESTRE RAMIREZ
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?AmeliaSmith90
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Incrobinwilliams8624
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptkinjal48
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxJoão Esperancinha
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsJaydeep Chhasatia
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadIvo Andreev
 

Kürzlich hochgeladen (20)

Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine HarmonyLeveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
Leveraging DxSherpa's Generative AI Services to Unlock Human-Machine Harmony
 
Watermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security ChallengesWatermarking in Source Code: Applications and Security Challenges
Watermarking in Source Code: Applications and Security Challenges
 
JS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AIJS-Experts - Cybersecurity for Generative AI
JS-Experts - Cybersecurity for Generative AI
 
OpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS CalculatorOpenChain Webinar: Universal CVSS Calculator
OpenChain Webinar: Universal CVSS Calculator
 
Growing Oxen: channel operators and retries
Growing Oxen: channel operators and retriesGrowing Oxen: channel operators and retries
Growing Oxen: channel operators and retries
 
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
Transforming PMO Success with AI - Discover OnePlan Strategic Portfolio Work ...
 
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/MLBig Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
Big Data Bellevue Meetup | Enhancing Python Data Loading in the Cloud for AI/ML
 
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales CoverageSales Territory Management: A Definitive Guide to Expand Sales Coverage
Sales Territory Management: A Definitive Guide to Expand Sales Coverage
 
eAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspectionseAuditor Audits & Inspections - conduct field inspections
eAuditor Audits & Inspections - conduct field inspections
 
AI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human BeautyAI Embracing Every Shade of Human Beauty
AI Embracing Every Shade of Human Beauty
 
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
Optimizing Business Potential: A Guide to Outsourcing Engineering Services in...
 
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdfARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
ARM Talk @ Rejekts - Will ARM be the new Mainstream in our Data Centers_.pdf
 
Deep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - DatacampDeep Learning for Images with PyTorch - Datacamp
Deep Learning for Images with PyTorch - Datacamp
 
How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?How Does the Epitome of Spyware Differ from Other Malicious Software?
How Does the Epitome of Spyware Differ from Other Malicious Software?
 
Enterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze IncEnterprise Document Management System - Qualityze Inc
Enterprise Document Management System - Qualityze Inc
 
Salesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptxSalesforce AI Associate Certification.pptx
Salesforce AI Associate Certification.pptx
 
Webinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.pptWebinar_050417_LeClair12345666777889.ppt
Webinar_050417_LeClair12345666777889.ppt
 
Fields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptxFields in Java and Kotlin and what to expect.pptx
Fields in Java and Kotlin and what to expect.pptx
 
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software TeamsYour Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
Your Vision, Our Expertise: TECUNIQUE's Tailored Software Teams
 
Cybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and BadCybersecurity Challenges with Generative AI - for Good and Bad
Cybersecurity Challenges with Generative AI - for Good and Bad
 

pdb like a pro

  • 1. PDB LIKE A PRO PHILIP BAUER @StarzelDe pbauer
  • 4. PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016 The Basics ▸ l[ist]
 List source code for the current file ▸ n[ext]
 Continue execution until the next line ▸ s[tep] 
 Execute the current line, stop at the first possible occasion ▸ r[eturn]
 Continue execution until the current function returns ▸ c[ontinue]
 Continue execution, only stop when a breakpoint is encountered
  • 5. PHILIP BAUER: PDB LIKE A PRO PYCON.DE 2016 The Basics II ▸ w[here] 
 Show stack trace. Recent frame at bottom ▸ u[p] 
 Move to older frame in stack trace ▸ d[own] 
 Move to newer frame in stack trace ▸ b[reakpoint] 
 Set a new breakpoint. tbreak Temporary breakpoint ▸ a[rgs]
 Print the argument list of the current function.
  • 7. PIMP MY PDB Some Enhancements ▸ pdb++ ▸ ipdb ▸ bpdb ▸ pudb ▸ and…
  • 8. PIMP MY PDB pdb in python 3.2+ ▸ ll | longlist
 List all source code for the current function or frame. ▸ source
 Try to get source code for the given object and display it. ▸ …
  • 9. PIMP MY PDB ipdb ▸ + features ▸ - dependencies ▸ - weird sqllite ▸ - need to use ``import ipdb; ipdb.set_trace()``
  • 10. PIMP MY PDB pudb ▸ + features ▸ +/- UI ▸ - need to use import pudb; pudb.set_trace()
  • 11. TEXT
  • 12. PIMP MY PDB ▸ it’s actually called pdbpp ▸ + features ▸ + no problematic dependencies ▸ + drop-in-replacement ▸ - needs configuration to not break readline pdb++
  • 14. PIMP MY PDB pdb++ ▸ you’ll need a file ~/.fancycompleterrc.py
  • 15. pdb++ ▸ Syntax highlighting ▸ ll | longlist
 List all source code for the current function or frame. ▸ track EXPRESSION ▸ display EXPRESSION ▸ source EXPRESSION ▸ obj? ▸ obj.__class__?? ▸ Sticky mode PIMP MY PDB
  • 16. Give pdb++ a try! The person you trust PIMP MY PDB
  • 18. INTROSPECTION python stuff you should know ▸ dir(obj) - bäh! ▸ help(obj) ▸ help(obj.__class__) ▸ pp locals() ▸ obj.__dict__ ▸ obj.__class__.__dict__ ▸ pp dict(obj.__class__.__dict__)
  • 19. INTROSPECTION the inspect module ▸ It’s what is used by other nice tools ▸ import inspect ▸ print inspect.getsource(obj.__class__) ▸ inspect.getmro(obj.__class__)
  • 21. ▸ break if some condition applies ▸ very useful in loops ▸ you need it in try/except blocks (e.g. indexing) TIPS AND TRICKS Conditional Breakpoints
  • 22. TIPS AND TRICKS debug ▸ Call any code and step into it with a pdb in a pdb ▸ You need to step into it after calling it! ▸ (Pdb++) self.context
 <Document at /Plone/startseite>
 (Pdb++) debug self.context.canSetLayout()
 ENTERING RECURSIVE DEBUGGER
 ((Pdb++)) s
 --Call--
 [2] >[…]/Products/CMFDynamicViewFTI/ browserdefault.py(183)canSetLayout()
 ((Pdb++)) ll
 183 -> @security.public
 184 def canSetLayout(self):
 186 mtool = getToolByName(self, 'portal_membership')
  • 24. ▸ Whenever there is a traceback you end up in a pdb! ▸ try:
 run_your_stuff()
 except:
 import pdb; pdb.set_trace() ▸ Plone: Products.PDBDebugMode ▸ Disable when migrating/reindexing TIPS AND TRICKS Post-Mortem Debugging
  • 25. ▸ Drops you in a pdb whenever a test fails or errors ▸ Zope/Plone: bin/test -D
 pytest & nosetest: pytest / nosetest --pdb
 unittest: need to wrap in try/except ▸ Test-Driven Debug-Driven Development TIPS AND TRICKS Post-Mortem Testing
  • 27. ▸ add a config-file ~/.pdbrc ▸ alias inspect import inspect;
 print inspect.getsource(%1) ▸ alias help !print help(%1) TIPS AND TRICKS Customize your pdb
  • 28. TEXT Sentry ▸ Collect tracebacks from production-environments ▸ The traceback includes all arguments for all stacks ▸ OpenSource / Django ▸ github.com/getsentry/sentry ▸ Available as a service: sentry.io ▸ starzel.de is working on a DebOps/Ansible role for Sentry
  • 30. SUMMARY What to take away ▸ learn the basics ▸ try pdb++ ▸ learn introspection ▸ try debug callable() ▸ use post-mortem-debugging ▸ always use pretty-print ▸ use Sentry to debug errors on production
  • 31. QUESTIONS Philip Bauer @StarzelDe pbauer All Fotos by Philip Bauer. Taken in Boothbay, Maine October 2016