diff options
author | Tom Tromey <tromey@adacore.com> | 2022-01-04 08:02:24 -0700 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2022-01-26 06:49:51 -0700 |
commit | 1da5d0e664e362857153af8682321a89ebafb7f6 (patch) | |
tree | b57ed08360a0351d66e4114c1d9b0d2b4cf95683 /gdb/python/py-utils.c | |
parent | 8a782bbf707e19d2da2159781789c4e4491dcdd1 (diff) | |
download | gdb-1da5d0e664e362857153af8682321a89ebafb7f6.zip gdb-1da5d0e664e362857153af8682321a89ebafb7f6.tar.gz gdb-1da5d0e664e362857153af8682321a89ebafb7f6.tar.bz2 |
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.
Diffstat (limited to 'gdb/python/py-utils.c')
-rw-r--r-- | gdb/python/py-utils.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/gdb/python/py-utils.c b/gdb/python/py-utils.c index 79e1c01..73c860b 100644 --- a/gdb/python/py-utils.c +++ b/gdb/python/py-utils.c @@ -93,8 +93,9 @@ unicode_to_encoded_python_string (PyObject *unicode_str, const char *charset) gdb::unique_xmalloc_ptr<char> unicode_to_target_string (PyObject *unicode_str) { - return unicode_to_encoded_string (unicode_str, - target_charset (python_gdbarch)); + return (unicode_to_encoded_string + (unicode_str, + target_charset (gdbpy_enter::get_gdbarch ()))); } /* Returns a PyObject with the contents of the given unicode string @@ -104,8 +105,9 @@ unicode_to_target_string (PyObject *unicode_str) static gdbpy_ref<> unicode_to_target_python_string (PyObject *unicode_str) { - return unicode_to_encoded_python_string (unicode_str, - target_charset (python_gdbarch)); + return (unicode_to_encoded_python_string + (unicode_str, + target_charset (gdbpy_enter::get_gdbarch ()))); } /* Converts a python string (8-bit or unicode) to a target string in |