LinuxCommandLibrary

ipdb

TLDR

Start ipdb debugger

$ python -m ipdb [script.py]
copy
Set breakpoint in code
$ import ipdb; ipdb.set_trace()
copy
Post-mortem debugging
$ python -m ipdb -c continue [script.py]
copy
Run until exception
$ ipdb.pm()
copy

SYNOPSIS

python -m ipdb [options] script [args]

DESCRIPTION

ipdb is the IPython-enhanced Python debugger. It provides the same interface as pdb but with syntax highlighting, tab completion, and better introspection from IPython.
ipdb makes Python debugging more interactive and user-friendly, especially for exploring variables and understanding program state.

PARAMETERS

-c command

Execute command on start.
script
Python script to debug.

DEBUGGER COMMANDS

$ n (next)      Execute next line
s (step)      Step into function
c (continue)  Continue execution
r (return)    Return from function
l (list)      List source code
p expr        Print expression
pp expr       Pretty-print expression
b line        Set breakpoint
cl            Clear breakpoints
q (quit)      Quit debugger
h (help)      Show help
copy

USAGE IN CODE

$ import ipdb

def problematic_function():
    x = calculate_something()
    ipdb.set_trace()  # Debugger starts here
    return process(x)
copy

CAVEATS

Requires ipython package. Breakpoints pause execution. Don't leave settrace() in production code. Use breakpoint() in Python 3.7+ with PYTHONBREAKPOINT=ipdb.settrace.

HISTORY

ipdb was created as a drop-in replacement for pdb that leverages IPython's features. It provides the familiar pdb interface with enhanced usability.

SEE ALSO

pdb(1), ipython(1), pudb(1)

Copied to clipboard