Index: Include/pyport.h =================================================================== --- Include/pyport.h (revision 84189) +++ Include/pyport.h (working copy) @@ -832,4 +832,13 @@ #endif #endif +/* + * System-dependent ways of injecting a breakpoint: + */ +#if defined(MS_WINDOWS) && defined(_DEBUG) +# define Py_BREAKPOINT() DebugBreak() +#elif defined(__GNUC__) && (defined(__i386__) || defined(__x86_64)) +# define Py_BREAKPOINT() __asm__ __volatile__ ("int $03") +#endif + #endif /* Py_PYPORT_H */ Index: Python/sysmodule.c =================================================================== --- Python/sysmodule.c (revision 84189) +++ Python/sysmodule.c (working copy) @@ -67,7 +67,23 @@ return PyDict_SetItemString(sd, name, v); } +#ifdef Py_BREAKPOINT +PyDoc_STRVAR(breakpoint_doc, +"breakpoint() -> None\n" +"\n" +"Inject a breakpoint signal in this process, for use when running CPython\n" +"under a debugger.\n" +); + static PyObject * +sys_breakpoint(PyObject *self, PyObject *noargs) +{ + Py_BREAKPOINT(); + Py_RETURN_NONE; +} +#endif /* Py_BREAKPOINT */ + +static PyObject * sys_displayhook(PyObject *self, PyObject *o) { PyObject *outf; @@ -986,6 +1002,9 @@ static PyMethodDef sys_methods[] = { /* Might as well keep this in alphabetic order */ +#ifdef Py_BREAKPOINT + {"breakpoint", sys_breakpoint, METH_NOARGS, breakpoint_doc}, +#endif {"callstats", (PyCFunction)PyEval_GetCallStats, METH_NOARGS, callstats_doc}, {"_clear_type_cache", sys_clear_type_cache, METH_NOARGS,