-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Add Py_BREAKPOINT and sys._breakpoint hooks #53844
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
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();
}
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: 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: |
|
Adding updated version of patch, which adds documentation to sys.rst and adds a unit test. I'm a little wary of this: it seems useful but also too much like a self-destruct button for my taste. |
I renamed it from sys.breakpoint to sys._breakpoint, since this is CPython-specific |
I would rename Py_BREAKPOINT to _Py_BREAKPOINT since we don't really want to support this. Also, why do you allow any arguments to sys._breakpoint()? |
Note to self: a messy way of forcing gdb to do the equivalent of a breakpoint directly from Python is: |
On Tue, 2010-11-02 at 17:25 +0000, Antoine Pitrou wrote:
The reason for allowing arguments to sys._breakpoint() is so that the Maybe the docs should read: ------ if foo and bar and not baz:
sys._breakpoint(some_func(foo, bar, baz)) In the above example, if the given python conditional holds (and no static PyObject *
sys_breakpoint(PyObject *self, PyObject *args)
{
_Py_BREAKPOINT();
Py_RETURN_NONE;
} It can also be useful to call when debugging the CPython interpreter: if I thought about it making it METH_O instead (to make it easier to look |
I don't like this API. I really prefer METH_O because it is already very difficult to dump a Python object in a debugger (especially with gdb macros). Why not using two functions? One without argument, One with an argument. The sys module is maybe not the right place for such low level function. You may create a new module with a name starting with _ (ex: _python_dbg). I'm quite sure that you will find other nice functions to add if you have a module dedicated to debugging :-) If you don't want to create a new module, faulthandler might be used to add new debug functions. It's maybe unrelated, but Brian Curtin also created a module to help debugging with Visual Studio: We may use the same module for all debugging functions? (I suppose that Brian Curtin wants to integrate its minidumper into Python 3.4.) Example:
-- For Power PC, the machine code to generate a breakpoint is 0x0cc00000. The instruction looks to be called twllei. Something like: "twllei reg_ZERO,trap_Cerror". Hum, it looks like there is family of instructions related to trap: all TW* instructions (twle, twlt, twge, ...). |
Did PEP-553 make this issue obsolete? |
On Fri, 2018-02-23 at 00:16 +0000, Cheryl Sabella wrote:
I *think* they have slightly different scope: if I'm reading it right, The idea was to make it easier to, say, step through a particular def test_something():
# lots of setup
sys.c_level_breakpoint()
# whatever comes next so that sys.c_level_breakpoint drops you into, say, gdb, and from there Hope that makes sense. That said, I'm full-time on gcc these days, and unlikely to pursue this |
While the feature request is legit, there is a lack of interest to implement it and this issue is inactive for many years. I close it. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: