mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-07-15 05:01:13 +08:00
* python/python-internal.h (struct language_defn): Declare.
(python_gdbarch, python_language): Likewise. (ensure_python_env): Add prototype. (make_cleanup_py_restore_gil): Remove prototype. * python/python.c: Include "arch-utils.h", "value.h" and "language.h". (python_gdbarch, python_language): New global variables. (struct python_env): New data type. (ensure_python_env, restore_python_env): New functions. (eval_python_from_control_command): Call ensure_python_env to install current architecture and language. (python_command, gdbpy_new_objfile): Likewise. * python/python-cmd.c: Include "arch-utils.h" and "language.h". (cmdpy_destroyer, cmdpy_function, cmdpy_completer): Call ensure_python_env. * python/python-type.c (clean_up_objfile_types): Likewise. * python/python-objfile.c: Include "language.h". (clean_up_objfile): Call ensure_python_env. * python/python-prettyprint.c (apply_val_pretty_printer): Likewise. (apply_varobj_pretty_printer): Do not call PyGILState_Ensure. * varobj.c (varobj_ensure_python_env): New helper function. (varobj_get_display_hint, update_dynamic_varobj_children, install_default_visualizer, varobj_set_visualizer, free_variable, value_get_print_value): Call it. (value_get_print_value): Add varobj argument instead of pretty printer argument. Update all callers. * python/python-utils.c (py_gil_restore, make_cleanup_py_restore_gil): Remove. * value.h (internal_function_fn): Add GDBARCH and LANGUAGE argument. (call_internal_function): Likewise. * value.c (call_internal_function): Likewise. Pass to handler. * eval.c (evaluate_subexp_standard): Update call. * python/python-function.c: Include "language.h". (fnpy_call): Add GDBARCH and LANGAUAGE arguments and call make_cleanup_python_env. * python/python-value.c (builtin_type_pyint, builtin_type_pyfloat, builtin_type_pylong, builtin_type_pybool, builtin_type_pychar, valpy_str): Use python_gdbarch and python_language instead of current_gdbarch and current_language. * python/python-type.c (typy_lookup_typename): Likewise.
This commit is contained in:
@ -18,12 +18,15 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "defs.h"
|
||||
#include "arch-utils.h"
|
||||
#include "command.h"
|
||||
#include "ui-out.h"
|
||||
#include "cli/cli-script.h"
|
||||
#include "gdbcmd.h"
|
||||
#include "objfiles.h"
|
||||
#include "observer.h"
|
||||
#include "value.h"
|
||||
#include "language.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
@ -58,6 +61,52 @@ PyObject *gdbpy_children_cst;
|
||||
PyObject *gdbpy_display_hint_cst;
|
||||
PyObject *gdbpy_doc_cst;
|
||||
|
||||
|
||||
/* Architecture and language to be used in callbacks from
|
||||
the Python interpreter. */
|
||||
struct gdbarch *python_gdbarch;
|
||||
const struct language_defn *python_language;
|
||||
|
||||
/* Restore global language and architecture and Python GIL state
|
||||
when leaving the Python interpreter. */
|
||||
|
||||
struct python_env
|
||||
{
|
||||
PyGILState_STATE state;
|
||||
struct gdbarch *gdbarch;
|
||||
const struct language_defn *language;
|
||||
};
|
||||
|
||||
static void
|
||||
restore_python_env (void *p)
|
||||
{
|
||||
struct python_env *env = (struct python_env *)p;
|
||||
PyGILState_Release (env->state);
|
||||
python_gdbarch = env->gdbarch;
|
||||
python_language = env->language;
|
||||
xfree (env);
|
||||
}
|
||||
|
||||
/* Called before entering the Python interpreter to install the
|
||||
current language and architecture to be used for Python values. */
|
||||
|
||||
struct cleanup *
|
||||
ensure_python_env (struct gdbarch *gdbarch,
|
||||
const struct language_defn *language)
|
||||
{
|
||||
struct python_env *env = xmalloc (sizeof *env);
|
||||
|
||||
env->state = PyGILState_Ensure ();
|
||||
env->gdbarch = python_gdbarch;
|
||||
env->language = python_language;
|
||||
|
||||
python_gdbarch = gdbarch;
|
||||
python_language = language;
|
||||
|
||||
return make_cleanup (restore_python_env, env);
|
||||
}
|
||||
|
||||
|
||||
/* Given a command_line, return a command string suitable for passing
|
||||
to Python. Lines in the string are separated by newlines. The
|
||||
return value is allocated using xmalloc and the caller is
|
||||
@ -96,13 +145,11 @@ eval_python_from_control_command (struct command_line *cmd)
|
||||
int ret;
|
||||
char *script;
|
||||
struct cleanup *cleanup;
|
||||
PyGILState_STATE state;
|
||||
|
||||
if (cmd->body_count != 1)
|
||||
error (_("Invalid \"python\" block structure."));
|
||||
|
||||
state = PyGILState_Ensure ();
|
||||
cleanup = make_cleanup_py_restore_gil (&state);
|
||||
cleanup = ensure_python_env (get_current_arch (), current_language);
|
||||
|
||||
script = compute_python_string (cmd->body_list[0]);
|
||||
ret = PyRun_SimpleString (script);
|
||||
@ -122,10 +169,7 @@ static void
|
||||
python_command (char *arg, int from_tty)
|
||||
{
|
||||
struct cleanup *cleanup;
|
||||
PyGILState_STATE state;
|
||||
|
||||
state = PyGILState_Ensure ();
|
||||
cleanup = make_cleanup_py_restore_gil (&state);
|
||||
cleanup = ensure_python_env (get_current_arch (), current_language);
|
||||
|
||||
while (arg && *arg && isspace (*arg))
|
||||
++arg;
|
||||
@ -330,13 +374,12 @@ gdbpy_new_objfile (struct objfile *objfile)
|
||||
char *filename, *debugfile;
|
||||
int len;
|
||||
FILE *input;
|
||||
PyGILState_STATE state;
|
||||
struct cleanup *cleanups;
|
||||
|
||||
if (!gdbpy_auto_load || !objfile || !objfile->name)
|
||||
return;
|
||||
|
||||
state = PyGILState_Ensure ();
|
||||
cleanups = ensure_python_env (get_objfile_arch (objfile), current_language);
|
||||
|
||||
gdbpy_current_objfile = objfile;
|
||||
|
||||
@ -349,7 +392,7 @@ gdbpy_new_objfile (struct objfile *objfile)
|
||||
input = fopen (filename, "r");
|
||||
debugfile = filename;
|
||||
|
||||
cleanups = make_cleanup (xfree, filename);
|
||||
make_cleanup (xfree, filename);
|
||||
make_cleanup (xfree, realname);
|
||||
|
||||
if (!input && debug_file_directory)
|
||||
@ -391,8 +434,6 @@ gdbpy_new_objfile (struct objfile *objfile)
|
||||
|
||||
do_cleanups (cleanups);
|
||||
gdbpy_current_objfile = NULL;
|
||||
|
||||
PyGILState_Release (state);
|
||||
}
|
||||
|
||||
/* Return the current Objfile, or None if there isn't one. */
|
||||
|
Reference in New Issue
Block a user