1010#endif
1111
1212#ifndef MS_WINDOWS
13- /* register() is useless on Windows, because only SIGSEGV and SIGILL can be
14- handled by the process, and these signals can only be used with enable(),
15- not using register() */
13+ /* register() is useless on Windows, because only SIGSEGV, SIGABRT and
14+ SIGILL can be handled by the process, and these signals can only be used
15+ with enable(), not using register() */
1616# define FAULTHANDLER_USER
1717#endif
1818
@@ -96,6 +96,7 @@ static fault_handler_t faulthandler_handlers[] = {
9696 {SIGILL , 0 , "Illegal instruction" , },
9797#endif
9898 {SIGFPE , 0 , "Floating point exception" , },
99+ {SIGABRT , 0 , "Aborted" , },
99100 /* define SIGSEGV at the end to make it the default choice if searching the
100101 handler fails in faulthandler_fatal_error() */
101102 {SIGSEGV , 0 , "Segmentation fault" , }
@@ -202,7 +203,7 @@ faulthandler_dump_traceback_py(PyObject *self,
202203}
203204
204205
205- /* Handler of SIGSEGV, SIGFPE, SIGBUS and SIGILL signals.
206+ /* Handler of SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL signals.
206207
207208 Display the current Python traceback, restore the previous handler and call
208209 the previous handler.
@@ -253,9 +254,9 @@ faulthandler_fatal_error(
253254 PUTS (fd , handler -> name );
254255 PUTS (fd , "\n\n" );
255256
256- /* SIGSEGV, SIGFPE, SIGBUS and SIGILL are synchronous signals and so are
257- delivered to the thread that caused the fault. Get the Python thread
258- state of the current thread.
257+ /* SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL are synchronous signals and
258+ so are delivered to the thread that caused the fault. Get the Python
259+ thread state of the current thread.
259260
260261 PyThreadState_Get() doesn't give the state of the thread that caused the
261262 fault if the thread released the GIL, and so this function cannot be
@@ -282,7 +283,7 @@ faulthandler_fatal_error(
282283 raise (signum );
283284}
284285
285- /* Install handler for fatal signals (SIGSEGV, SIGFPE, ... ). */
286+ /* Install the handler for fatal signals, faulthandler_fatal_error( ). */
286287
287288static PyObject *
288289faulthandler_enable (PyObject * self , PyObject * args , PyObject * kwargs )
@@ -714,6 +715,20 @@ faulthandler_sigfpe(PyObject *self, PyObject *args)
714715 Py_RETURN_NONE ;
715716}
716717
718+ static PyObject *
719+ faulthandler_sigabrt (PyObject * self , PyObject * args )
720+ {
721+ #if _MSC_VER
722+ /* If Python is compiled in debug mode with Visual Studio, abort() opens
723+ a popup asking the user how to handle the assertion. Use raise(SIGABRT)
724+ instead. */
725+ raise (SIGABRT );
726+ #else
727+ abort ();
728+ #endif
729+ Py_RETURN_NONE ;
730+ }
731+
717732#ifdef SIGBUS
718733static PyObject *
719734faulthandler_sigbus (PyObject * self , PyObject * args )
@@ -847,6 +862,8 @@ static PyMethodDef module_methods[] = {
847862 "a SIGSEGV or SIGBUS signal depending on the platform" )},
848863 {"_sigsegv" , faulthandler_sigsegv , METH_VARARGS ,
849864 PyDoc_STR ("_sigsegv(): raise a SIGSEGV signal" )},
865+ {"_sigabrt" , faulthandler_sigabrt , METH_VARARGS ,
866+ PyDoc_STR ("_sigabrt(): raise a SIGABRT signal" )},
850867 {"_sigfpe" , (PyCFunction )faulthandler_sigfpe , METH_NOARGS ,
851868 PyDoc_STR ("_sigfpe(): raise a SIGFPE signal" )},
852869#ifdef SIGBUS
0 commit comments