[New-bugs-announce] [issue9635] RFE(patch): add Py_BREAKPOINT and sys.breakpoint hooks

Dave Malcolm report at bugs.python.org
Thu Aug 19 01:43:25 CEST 2010


New submission from Dave Malcolm <dmalcolm at redhat.com>:

It's sometimes useful to be able to programatically inject a breakpoint when debugging CPython.

For example, sometimes you want a conditional breakpoint, but the logic involved is too complex to be expressed in the debugger (e.g. runtime complexity of evaluating the conditional in the debugger process, or deficiency of the debugger itself).

I'm attaching a patch which:
  - adds a Py_BREAKPOINT macro to pyport.h   This is available as a quick and dirty way of hardcoding a breakpoint in code (e.g. in extension modules); so that when you need to you can put of these in (perhaps guarded by C-level conditionals):
       if (complex_conditional()) {
           Py_BREAKPOINT();
       }

  - when Py_BREAKPOINT is defined, adds a sys.breakpoint() method.  This means that you can add C-level breakpoints to Python scripts, perhaps guarded by python-level conditionals:
       if foo and bar and not baz:
          sys.breakpoint()

Naturally this is highly system-dependent.   Only tested on Linux (Fedora 13 x86_64 with gcc-4.4.4).  The Windows implementation was copied from http://bugs.python.org/issue8863 but I don't have a Windows box to test it on.

I note that the GLib library within GNOME has a similar idea with a G_BREAKPOINT macro, which has accumulated a collection of platform-specific logic:
  http://git.gnome.org/browse/glib/tree/glib/gbacktrace.h
(unfortunately that's LGPLv2+ licensed)

Doesn't yet have a unit test.

Note that when running on Linux when _not_ under a debugger, the default for SIGTRAP is to get a coredump:
   Trace/breakpoint trap (core dumped)
so people should be strongly discouraged from adding these calls to their code.

----------
components: Interpreter Core, Library (Lib)
files: add-sys.breakpoint.patch
keywords: patch, patch
messages: 114301
nosy: dmalcolm, haypo
priority: normal
severity: normal
stage: patch review
status: open
title: RFE(patch): add Py_BREAKPOINT and sys.breakpoint hooks
type: feature request
versions: Python 3.2, Python 3.3
Added file: http://bugs.python.org/file18572/add-sys.breakpoint.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9635>
_______________________________________


More information about the New-bugs-announce mailing list