Package: pdbpp
pdb++, a drop-in replacement for pdbWhat is it?This module is an extension of thepdbmodule of the standard library.  It is
meant to be fully compatible with its predecessor, yet it introduces a number
of new features to make your debugging experience as nice as possible.pdb++features include:colorful TAB completion of Python expressions (throughfancycompleter)optional syntax highlighting of code listings (throughpygments)sticky modeseveral new commands to be used from the interactive(Pdb++)promptsmart command parsing(hint: have you ever typedrorcat the
prompt to print the value of some variable?)additional convenience functions in thepdbmodule, to be used from
your programpdb++is meant to be a drop-in replacement forpdb. If you find some
unexpected behavior, please report it as a bug.InstallationSincepdb++is not a valid identifier forpipandeasy_install,
the package is namedpdbpp:$ pip install pdbpp

-- OR --

$ easy_install pdbpppdb++is also available viaconda:$ conda install -c conda-forge pdbppAlternatively, you can just putpdb.pysomewhere inside yourPYTHONPATH.UsageNote that the module is calledpdb.pyso thatpdb++will automatically
be used in all places that doimport pdb(e.g.pytest--pdbwill
give you apdb++prompt).The oldpdbmodule is still available by doing e.g.import pdb; pdb.pdb.set_trace().New interactive commandsThe following are new commands that you can use from the interative(Pdb++)prompt.sticky [start end]Togglesticky mode.  When in this mode, every time the current position
changes, the screen is repainted and the whole function shown.  Thus, when
doing step-by-step execution you can easily follow the flow of the
execution.  Ifstartandendare given, sticky mode is enabled and
only lines within that range (extremes included) will be displayed.longlist(ll)List source code for the current function.  Different from the normal pdblistcommand,longlistdisplays the whole function.  The current
line is marked with->.  In case of post-mortem debugging, the line
which actually raised the exception is marked with>>.  If thehighlightconfig optionis set andpygmentsis installed, the source
code is highlighted.interactStart an interative interpreter whose global namespace contains all the
names found in the current scope.track EXPRESSIONDisplay a graph showing which objects are the value of the expression refers
to and are referred by.  This command requires thepypysource code to
be importable.display EXPRESSIONAdd an expression to thedisplay list; expressions in this list are
evaluated at each step, and printed every time its value changes.WARNING: since these expressions are evaluated multiple times, make sure
not to put expressions with side-effects in the display list.undisplay EXPRESSION:RemoveEXPRESSIONfrom the display list.source EXPRESSIONShow the source code for the given function/method/class.edit EXPRESSIONOpen the editor in the right position to edit the given
function/method/class.  The editor used is specified in aconfig
option.hf_unhide,hf_hide,hf_listSome frames might be marked as “hidden” by e.g. using the@pdb.hideframefunction decorator.  By default, hidden frames are not shown in the stack
trace, and cannot be reached usingupanddown.  You can usehf_unhideto tell pdb to ignore the hidden status (i.e., to treat hidden
frames as normal ones), andhf_hideto hide them again.hf_listprints a list of hidden frames.
The config optionenable_hidden_framescan be used to disable handling
of hidden frames in general.Smart command parsingBy default, pdb tries hard to interpret what you enter at the command prompt
as one of its builtin commands.  However, this is inconvenient if you want to
just print the value of a local variable which happens to have the same name
as one of the commands. E.g.:(Pdb) list
  1
  2     def fn():
  3         c = 42
  4         import pdb;pdb.set_trace()
  5  ->     return c
(Pdb) cIn the example above, instead of printing 42 pdb interprets the input as the
commandcontinue, and then you loose your prompt.  It’s even worse than
that, because it happens even if you type e.g.c.__class__.pdb++ fixes this unfriendly (from the author’s point of view, of course :-))
behavior by always prefering variable in scope, if it exists.  If you really
want to execute the corresponding command, you can prefix it with!!.
Thus, the example above becomes:(Pdb++) list
  1
  2     def fn():
  3         c = 42
  4         import pdb;pdb.set_trace()
  5  ->     return c
(Pdb++) c
42
(Pdb++) !!cNote that the “smart” behavior takes place only when there is ambiguity, i.e.
if there exists a variable with the same name as a command: in all other
cases, everything works as usual.Regarding thelistcommand itself, usinglist(…is a special case
that gets handled as the Python builtin:(Pdb++) list([1, 2])
[1, 2]Additional functions in thepdbmoduleThepdbmodule that comes with pdb++ includes all the functions and
classes that are in the module from the standard library.  If you find any
difference, please report it as a bug.In addition, there are some new convenience functions that are unique to
pdb++.pdb.xpm()eXtended Post Mortem: it is equivalent topdb.post_mortem(sys.exc_info()[2]).  If used inside anexceptclause, it will start a post-mortem pdb prompt from the line that raised the
exception being caught.pdb.disable()Disablepdb.set_trace(): any subsequent call to it will be ignored.pdb.enable()Re-enablepdb.set_trace(), in case it was disabled bypdb.disable().@pdb.hideframeA function decorator that tells pdb++ to hide the frame corresponding to the
function.  Hidden frames do not show up when using interactive commands such
asup,downorwhere, unlesshf_unhideis invoked.@pdb.break_on_setattr(attrname, condition=always)class decorator: break the execution of the program every time the
attributeattrnameis set on any instance of the class.conditionis
a callable that takes the target object of thesetattrand the actual value;
by default, it breaks every time the attribute is set. E.g.:@break_on_setattr('bar')
class Foo(object):
    pass
f = Foo()
f.bar = 42    # the program breaks hereIf can be used even after the class has already been created, e.g. if we
want to break when some attribute of a particular object is set:class Foo(object):
    pass
a = Foo()
b = Foo()

def break_if_a(obj, value):
    return obj is a

break_on_setattr('bar', condition=break_if_a)(Foo)
b.bar = 10   # no break
a.bar = 42   # the program breaks hereThis can be used afterpdb.set_trace()also:(Pdb++) import pdb
(Pdb++) pdb.break_on_setattr('tree_id')(obj.__class__)
(Pdb++) continueConfiguration and customizationTo customize pdb++, you can put a file named.pdbrc.pyin your home
directory.  The file must contain a class namedConfiginheriting frompdb.DefaultConfigand override the desired values.The following is a list of the options you can customize, together with their
default value:prompt ='(Pdb++)'The prompt to show when in interactive mode.highlight = TrueHighlight line numbers and the current line when showing thelonglistof
a function or when insticky mode.encoding ='utf-8'File encoding. Useful when there are international characters in your string
literals or comments.sticky_by_default = FalseDetermine whether pdb++ starts in sticky mode or not.line_number_color = Color.turquoiseThe color to use for line numbers.filename_color = Color.yellowThe color to use for file names when printing the stack entries.current_line_color = "39;49;7"The SGR parameters for the ANSI escape sequence to highlight the current
line.
This is set inside the SGR escape sequence\e[%smwhere\eis the
ESC character and%sthe given value.  SeeSGR parameters.
The following means “reset all colors” (0), set foreground color to 18
(48;5;18), and background to21.
The default uses the default foreground (39) and background (49)
colors, inversed (7).use_pygments = TrueIfpygmentsis installed andhighlight == True, apply syntax highlight
to the source code when showing thelonglistof a function or when insticky mode.bg = 'dark'Passed directly to thepygments.formatters.TerminalFormatterconstructor.
Selects the color scheme to use, depending on the background color of your
terminal. If you have a light background color, try to set it to'light'.colorscheme = NonePassed directly to thepygments.formatters.TerminalFormatterconstructor.
It expects a dictionary that maps token types to (lightbg, darkbg) color names orNone(default:None= use builtin colorscheme).editor ='${EDITOR:-vi}'The command to invoke when using theeditcommand. By default, it uses$EDITORif set, elsevi.  The command must support the standard
notationCOMMAND +n filenameto open filename at linen.emacsandviare known to support this.truncate_long_lines = TrueTruncate lines which exceed the terminal width.exec_if_unfocused = NoneShell command to execute when starting the pdb prompt and the terminal
window is not focused.  Useful to e.g. play a sound to alert the user that
the execution of the program stopped. It requires thewmctrlmodule.disable_pytest_capturing = FalseOld versions ofpytestcrash when you executepdb.set_trace()in a
test, but the standard output is captured (i.e., without the-soption,
which is the default behavior).  When this option is on, the stdout
capturing is automatically disabled before showing the interactive prompt.enable_hidden_frames = TrueCertain frames can be hidden by default.
If enabled, the commandshf_unhide,hf_hide, andhf_listcan be
used to control display of them.show_hidden_frames_count = TrueIfenable_hidden_framesisTruethis controls if the number of
hidden frames gets displayed.def setup(self, pdb): passThis method is called during the initialization of thePdbclass. Useful
to do complex setup.show_traceback_on_error = TrueDisplay tracebacks for errors viaPdb.error, that come fromPdb.default(i.e. the execution of an unrecognized pdb command),
and are not a direct cause of the expression itself (e.g.NameErrorwith a command likedoesnotexist).With this option disabled only*** exception stringgets printed, which
often misses useful context.show_traceback_on_error_limit = NoneThis option sets the limit to be used withtraceback.format_exception,
whenshow_traceback_on_erroris enabled.Coding guidelinespdb++is developed using Test Driven Development, and we try to keep test
coverage high.As a general rule, every commit should come with its own test. If it’s a new
feature, it should come with one or many tests which excercise it. If it’s a
bug fix, the test shouldfail before the fix, and pass after.The goal is to make refactoring easier in the future: if you wonder why a
certain line of code does something, in principle it should be possible to
comment it out and see which tests fail.In exceptional cases, the test might be too hard or impossible to write: in
that cases it is fine to do a commmit without a test, but you should explain
very precisely in the commit message why it is hard to write a test and how to
reproduce the buggy behaviour by hand.It is fine NOT to write a test in the following cases:typos, documentation, and in general any non-coding commitcode refactorings which do not add any featurecommits which fix an already failing testcommits to silence warningspurely cosmetic changes, such as change the color of the outputCHANGELOGChanges between 0.10.2 and 0.10.3Minor bugfix release, moving Continuous Integration from Travis/AppVeyor to
GitHub Actions, based on changes on master, but without the (more invasive)
(test) fixes for Windows.FixesFix hideframe decorator for Python 3.8+ (#263)Fix hidden_frames discrepancy with IPython (#426)Miscci: move to GitHub Actions (#444, #445)ci: use .coveragerc (#304)qa/flake8 fixestest fix for newer PyPy3Changes between 0.10.0 and 0.10.2Minor bugfix release to make pdb++ work better with a system-wide installation
from within a virtualenv.FixesFix pth hack: skip if added already (#297)Version 0.10.2 fixes only the deployment configuration.Changes between 0.9.15 and 0.10.0Changes
- config: improve current_line_color: default fg/bg/inversed (#188)
- Show tracebacks for errors with interactively run code (#185)This adds new config settings “show_traceback_on_error” (default: True),
and “show_traceback_on_error_limit” (default: None).FixesFix get_stack for non-last index (#192)This fixes a pretty nasty bug, which was triggered e.g. with the “next”
command running into a deeper exception, and the internal stack getting
confused (if hidden frames are involved).Misc:doc: document enable_hidden_frames, show_hidden_frames_count (#191)Make break_on_setattr not rely on @hideframe (#190)tests: cover sticky mode, small improvements (#177)doc: correct default value for disable_pytest_capturingChanges between 0.9.14 and 0.9.15FixesFix completion after debug command (#183)Misctests: fix test_syntaxerror_in_command for Python 3.7.3 (#182)setup.py: cleanup, testing extra (#181)test_help: fix restoring of sys.stdout (#180)tests: move pytest config to setup.cfg, use –pdbcls=pdb:pdb.Pdb (#179)tests: fix put tests on py27 with user pdbrc (#178)Improve tests (#176)Provide message/error methods for py27 (#175)Changes between 0.9.13 and 0.9.14FixesFix using the debug command multiple times (#174)Fix backport for bpo-31078 (keeping use_rawinput) (#169)Featuresnew config attribute: default_pdb_kwargs, which can be used to pass
default keyword arguments for the Pdb class (#167, #173)
This can be used to e.g. passskip=["importlib._bootstrap_external"].Misctest_python_m_pdb_uses_pdbpp: set HOME to tmpdir (#172)interaction: expand expression to call _cmdloop/cmdloop (#171)tests: restore sys.gettrace after test, for more coverage (#170)Changes between 0.9.12 and 0.9.13FixesFix crash in is_skipped_module with no module name (#163)FeaturesOptimize get_stack for show_hidden_frames (#162)Do not consider the frame with set_trace() as hidden (#161)MiscDefaultConfig: make it a new-style class (#166)Setup coverage reporting (#164)Changes between 0.9.11 and 0.9.12FixesFix forget(): check self.lineno, not GLOBAL_PDB.lineno (#160)do_debug: use func.__globals__ with rebind_globals (#159)Use super() (#145)Misctests: set_trace: allow to pass in Pdb class (#158)Changes between 0.9.8 and 0.9.11FixesMake wrapper compatible with python2’s sys.stdout (#155)
This was broken since 0.9.4/0.9.5.NOTE: 0.9.9 and 0.9.10 were not released to PyPI due to Travis CImisconfiguration.Changes between 0.9.7 and 0.9.8Fixesinteraction: fix ValueError (“signal only works in main thread”) (#143)rebind_globals: update globals() (#151)Fix do_debug for py38 (#150)Miscdo_debug: use PdbppWithConfig class (#147)tests: harden test_debug_with_overridden_continue (#146)tests: add test_signal_in_nonmain_thread_with_continuetests: fail if there is anything on stderrci: Travis: add Python 3.8-devChanges between 0.9.6 and 0.9.7Fixesdo_debug: fix setting of use_rawinput (#141)Changes between 0.9.5 and 0.9.6Fixesdo_debug: handle SyntaxError (#139)parseline: handle f-strings with py36 (#138)Changes between 0.9.3 and 0.9.5FixesFixpython-mpdb …(#135)Fix “TypeError: write() argument must be str, not bytes” with non-utf8
terminal encodings (#63)Handle pdb.Pdb._previous_sigint_handler with Python 3.5.3+ (#87)MiscUseshutil.get_terminal_sizeif available (#125)Slightly improve loading of pdb from stdlib (#133)NOTE: 0.9.4 was not released to PyPI due to Travis CI misconfiguration.Changes between 0.9.2 and 0.9.3FeaturesImprove sticky_by_default: don’t clear screen the first time (#83)Handle header kwarg added with Python 3.7 in pdb.set_trace (#115)config: allow to force use_terminal256formatter (#112)Add heuristic for which ‘list’ is meant (#82)FixesSkip/step overpdb.set_trace()(#119)Handle completions from original pdb (#116)Handle set_trace being invoked during completion (#89)_pdbpp_path_hack/pdb.py: fix ResourceWarning (#97)Fix “python -m pdb” (#108)setup/interaction: use/handle return value from pdb.Pdb.setup (#107)interaction: use _cmdloop if available (#106)Fixed virtualenv sys.path shuffling issue (#85)set_trace: do not delete pdb.curframe (#103)forget: only call pdb.Pdb.forget with GLOBAL_PDB onceTestsTravis: test pypy3Travis/tox: add py37, remove nightlytests: PdbTest: use nosigint=True (#117)Add test_debug_with_overridden_continue (#113)tests: re-enable/fix test_utf8 (#110)tests: fix conditional skipping with test_pdbrc_continuetests: runpdb: print output on Exceptionspytest.ini: addopts: -ratests: handle pytest’s--assert=plainmodetests: harden check: match all linestests: fix flake8 errors and invalid-escape DeprecationWarningsMiscsetup.py: add trove classifier for “… :: Debuggers”doc: separate usage section (#105)Format code: flake8 clean, using autopep8 mainly (#118)Add wheels supportREADME: grammar and example for break_on_setattr (#99)README: fix formattingSimplify the code, since we no longer support python 2.6Changes between 0.9.1 and 0.9.2AddLICENSE.txt.Improved import time for__version__.Changes between 0.8.2 and 0.9.1Installordereddictpackage only on Python versions older than 2.7.Python 3 supportImproved Windows supportChanges between 0.8.1 and 0.8.2fix wheel packaging; seehttps://bitbucket.org/antocuni/pdb/pull-request/38/support-pip-install-and-wheels-natively/diffChanges between 0.8 and 0.8.1fix issue 37: Doesn’t install on OS XRemoved dependency onbackports.inspectMade dependency onfuncsigsoptional.(https://bitbucket.org/antocuni/pdb/issue/37/doesn-t-install-on-os-x)(https://bitbucket.org/antocuni/pdb/pull-request/35/use-funcsigs-package-instead-of/diff)Changes between 0.7.2 and 0.8Python 3 compatibilityOptional support for 256 color formatting by settinguse_terminal256formatter = Truein~/.pdbrc.py(https://bitbucket.org/antocuni/pdb/pull-request/30)Makeset_trace()in same program remember previous state
(https://bitbucket.org/antocuni/pdb/pull-request/33)Append?and??to callable to get info a la IPython
(https://bitbucket.org/antocuni/pdb/pull-request/25)Don’t treat lines liker = 5orc = 6as commands
(https://bitbucket.org/antocuni/pdb/pull-request/11)fix issue 20: support argument-free post mortemChanges between 0.7.1 and 0.7.2don’t crash with newer versions ofpy.testChanges between 0.7 and 0.7.1Thepp(pretty print) command now uses the actual width of the terminal,
instead of hardcoding 80 columnspy.test and unittest internal frames are hidden by default (typehelp hidden_framesfor more info)don’t crash ifpyis installed butpy.testis not