From 1da5d0e664e362857153af8682321a89ebafb7f6 Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Tue, 4 Jan 2022 08:02:24 -0700 Subject: Change how Python architecture and language are handled Currently, gdb's Python layer captures the current architecture and language when "entering" Python code. This has some undesirable effects, and so this series changes how this is handled. First, there is code like this: gdbpy_enter enter_py (python_gdbarch, python_language); This is incorrect, because both of these are NULL when not otherwise assigned. This can cause crashes in some cases -- I've added one to the test suite. (Note that this crasher is just an example, other ones along the same lines are possible.) Second, when the language is captured in this way, it means that Python code cannot affect the current language for its own purposes. It's reasonable to want to write code like this: gdb.execute('set language mumble') ... stuff using the current language gdb.execute('set language previous-value') However, this won't actually work, because the language is captured on entry. I've added a test to show this as well. This patch changes gdb to try to avoid capturing the current values. The Python concept of the current gdbarch is only set in those few cases where a non-default value is computed or needed; and the language is not captured at all -- instead, in the cases where it's required, the current language is temporarily changed. --- gdb/python/py-cmd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'gdb/python/py-cmd.c') diff --git a/gdb/python/py-cmd.c b/gdb/python/py-cmd.c index 3a4e649..b51b05c 100644 --- a/gdb/python/py-cmd.c +++ b/gdb/python/py-cmd.c @@ -90,7 +90,7 @@ cmdpy_dont_repeat (PyObject *self, PyObject *args) static void cmdpy_destroyer (struct cmd_list_element *self, void *context) { - gdbpy_enter enter_py (get_current_arch (), current_language); + gdbpy_enter enter_py; /* Release our hold on the command object. */ gdbpy_ref cmd ((cmdpy_object *) context); @@ -104,7 +104,7 @@ cmdpy_function (const char *args, int from_tty, cmd_list_element *command) { cmdpy_object *obj = (cmdpy_object *) command->context (); - gdbpy_enter enter_py (get_current_arch (), current_language); + gdbpy_enter enter_py; if (! obj) error (_("Invalid invocation of Python command object.")); @@ -223,7 +223,7 @@ cmdpy_completer_handle_brkchars (struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word) { - gdbpy_enter enter_py (get_current_arch (), current_language); + gdbpy_enter enter_py; /* Calling our helper to obtain a reference to the PyObject of the Python function. */ @@ -266,7 +266,7 @@ cmdpy_completer (struct cmd_list_element *command, completion_tracker &tracker, const char *text, const char *word) { - gdbpy_enter enter_py (get_current_arch (), current_language); + gdbpy_enter enter_py; /* Calling our helper to obtain a reference to the PyObject of the Python function. */ -- cgit v1.1