From 4ecee2c47da3e91c0571683acb5cfb8400402663 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Mon, 7 Nov 2016 15:56:57 -0700 Subject: Introduce gdbpy_enter This introduces gdbpy_enter, a class that can be used to acquire and release the Python GIL, and also set other Python-related globals used by gdb. ensure_python_env is rewritten in terms of this new class. 2017-01-10 Tom Tromey * python/python.c (gdbpy_enter): New constructor. (~gdbpy_enter): New destructor. (restore_python_env, ensure_python_env): Rewrite. * python/python-internal.h (gdbpy_enter): New class. --- gdb/python/python-internal.h | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'gdb/python/python-internal.h') diff --git a/gdb/python/python-internal.h b/gdb/python/python-internal.h index 4b12aaf..a3b9b74 100644 --- a/gdb/python/python-internal.h +++ b/gdb/python/python-internal.h @@ -501,6 +501,31 @@ int gdbpy_initialize_unwind (void) struct cleanup *make_cleanup_py_decref (PyObject *py); struct cleanup *make_cleanup_py_xdecref (PyObject *py); +/* Called before entering the Python interpreter to install the + current language and architecture to be used for Python values. + Also set the active extension language for GDB so that SIGINT's + are directed our way, and if necessary install the right SIGINT + handler. */ +class gdbpy_enter +{ + public: + + gdbpy_enter (struct gdbarch *gdbarch, const struct language_defn *language); + + ~gdbpy_enter (); + + gdbpy_enter (const gdbpy_enter &) = delete; + gdbpy_enter &operator= (const gdbpy_enter &) = delete; + + private: + + struct active_ext_lang_state *m_previous_active; + PyGILState_STATE m_state; + struct gdbarch *m_gdbarch; + const struct language_defn *m_language; + PyObject *m_error_type, *m_error_value, *m_error_traceback; +}; + struct cleanup *ensure_python_env (struct gdbarch *gdbarch, const struct language_defn *language); -- cgit v1.1