Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

PDB++

PDB++ (pdbpp) is an open source drop-in replacement for pdb that adds support for colorful output, sticky mode, and other conveniences. You can get PDB++ with pip or easy_install:

Shell
$ pip3 install pdbpp

The sticky command will keep a long list on the screen, above the interactive debugger. It highlights the line you’re stopped on as you debug. You can use @pdb.hideframe to hide a function’s associated stack frame from the where, up, and down commands.

If you want to use the old pdb, then replace your set_trace() line with the following:

Python
import pdb; pdb.pdb.set_trace()

To learn more about PDB++, visit PyPI.

00:00 pdb is great, but of course, in the world of programming, great is never enough. Programmers always want to make things better, and so an open-source drop-in replacement for pdb called PDB++ has been created.

00:18 It has all the same functionality of the built-in pdb module, but it comes with a few extra features and capabilities that make command line debugging a lot easier.

00:30 We can grab the PDB++ package with either pip or easy_install. Here in my terminal, I’ll run pip3 install pdbpp, which is the package name for PDB++.

00:47 Like I mention, this is a drop-in replacement, so our existing programs utilizing pdb will now use PDB++. I’ve written a new program here called example6.py, which will help to demonstrate some of the features of PDB++.

01:06 This program prompts the user to log in with a username, and greets them as long as their name isn’t "steve". I don’t know what Steve ever did.

01:17 The only difference here is that I’m importing pdb at the top of the file, and then calling the set_trace() function inside of the log_in() function.

01:27 You’ll see why I separated these two in a minute. As always, I’ll clear my screen and I will run this program in my terminal.

01:36 And now I will punch in my name so that we move into the log_in() function. Immediately we notice that this looks exactly like regular pdb, but we’ve got some color on the path and line number, which makes it a little bit easier to read.

01:54 My favorite PDB++ command is sticky, which acts sort of like ll (longlist), except it keeps the list on the screen as we continue to enter commands.

02:05 So now I can say n to move inside this conditional, and s to move inside the function call. PDB++ is displaying only the current stack frame, so we know where we are. And this system works with all of the existing pdb commands, so I can use a command like w (where) to get a nicely-colored stack trace. I’ll quit out of this debugging session and clear my console.

02:34 Another PDB++ feature I really like is the ability to hide the stack frame corresponding to a function. We can do this with a function decorator, just like this.

02:47 I’ll move into my script and right above the greet() function I’m going to type @pdb.hideframe. I can do this because I imported pdb in global scope at the top of the script.

03:03 Now, if we were to use the u (up), d (down), and w (where) commands, PDB++ wouldn’t see the greet() function, which can help simplify debugging if you have a lot of little utility functions that don’t need to be debugged or displayed within the stack trace.

03:22 I should also mention, if you want to use the old pdb but keep the new one installed, you can add pdb. to your set_trace() line, which works because PDB++ literally contains the old pdb that we can access.

Avatar image for az

az on Dec. 2, 2019

Hi Austin, Great course, really enjoyed it. However, I have encountered a small issue. when I install pdbpp, the whole pdb module stops working and when i uninstall pdbpp, the pdb module works. Can you please give any pointers as to how to remedy this situation ?

Regards Arif

Avatar image for Austin Cepalia

Austin Cepalia RP Team on Dec. 6, 2019

@az Hmm, that’s strange. Are you getting a “module not found” error or something else? Can you try creating a virtual environment and installing pdbpp there?

Avatar image for Ben Hammel

Ben Hammel on Oct. 30, 2020

pdbpp has been a game changer! Do you know if there is a way to set this as the default debugger for ipython?

If I run a script interactively with ipython, e.g. ipython -i <script>.py it will default to using vanilla pdb.

Become a Member to join the conversation.