From c97d123d6701fbf462e96db001cea07ed32e4efa Mon Sep 17 00:00:00 2001 From: Tom Tromey Date: Thu, 16 Mar 2023 10:57:32 -0600 Subject: 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 --- gdb/testsuite/gdb.python/py-mi-cmd.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'gdb/testsuite/gdb.python/py-mi-cmd.py') 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") -- cgit v1.1