diff options
author | Tom Tromey <tromey@adacore.com> | 2023-03-16 10:57:32 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-05-23 10:09:28 -0600 |
commit | c97d123d6701fbf462e96db001cea07ed32e4efa (patch) | |
tree | 7442dc14459bc1e8874998d219dda702371f380e /gdb/testsuite/gdb.python | |
parent | e7a2797eb00dbbceb6796f1baa120055d174a229 (diff) | |
download | binutils-c97d123d6701fbf462e96db001cea07ed32e4efa.zip binutils-c97d123d6701fbf462e96db001cea07ed32e4efa.tar.gz binutils-c97d123d6701fbf462e96db001cea07ed32e4efa.tar.bz2 |
Implement gdb.execute_mi
This adds a new Python function, gdb.execute_mi, that can be used to
invoke an MI command but get the output as a Python object, rather
than a string. This is done by implementing a new ui_out subclass
that builds a Python object.
Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=11688
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Diffstat (limited to 'gdb/testsuite/gdb.python')
-rw-r--r-- | gdb/testsuite/gdb.python/py-exec-mi.exp | 32 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-mi-cmd.py | 27 |
2 files changed, 59 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-exec-mi.exp b/gdb/testsuite/gdb.python/py-exec-mi.exp new file mode 100644 index 0000000..09c4877 --- /dev/null +++ b/gdb/testsuite/gdb.python/py-exec-mi.exp @@ -0,0 +1,32 @@ +# Copyright (C) 2023 Free Software Foundation, Inc. +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +# Test gdb.execute_mi. + +load_lib gdb-python.exp +require allow_python_tests + +clean_restart + +gdb_test_no_output "source ${srcdir}/${subdir}/py-mi-cmd.py" \ + "load python file" + +gdb_test "python run_execute_mi_tests()" "PASS" + +# Be sure to test a command implemented as CLI command, as those fetch +# the args. +gdb_test_no_output "python gdb.execute_mi('-exec-arguments', 'a', 'b', 'c')" \ + "set arguments" + +gdb_test "show args" ".*\"a b c\"." diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.py b/gdb/testsuite/gdb.python/py-mi-cmd.py index c7bf5b7..2c86c90 100644 --- a/gdb/testsuite/gdb.python/py-mi-cmd.py +++ b/gdb/testsuite/gdb.python/py-mi-cmd.py @@ -118,3 +118,30 @@ def free_invoke(obj, args): # these as a Python function which is then called from the exp script. def run_exception_tests(): print("PASS") + + +# Run some execute_mi tests. This is easier to do from Python. +def run_execute_mi_tests(): + # Install the command. + cmd = pycmd1("-pycmd") + # Pass in a representative subset of the pycmd1 keys, and then + # check that the result via MI is the same as the result via a + # direct Python call. Note that some results won't compare as + # equal -- for example, a Python MI command can return a tuple, + # but that will be translated to a Python list. + for name in ("int", "str", "dct"): + expect = cmd.invoke([name]) + got = gdb.execute_mi("-pycmd", name) + if expect != got: + print("FAIL: saw " + repr(got) + ", but expected " + repr(expect)) + return + ok = False + try: + gdb.execute_mi("-pycmd", "exp") + # Due to the "denaturation" problem, we have to expect a gdb.error + # here and not a gdb.GdbError. + except gdb.error: + ok = True + if not ok: + print("FAIL: did not throw exception") + print("PASS") |