aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Tromey <tromey@adacore.com>2024-10-15 10:50:01 -0600
committerTom Tromey <tromey@adacore.com>2024-10-18 11:50:27 -0600
commit32af040ef2fcbeccf746acef230db826fad951f9 (patch)
treeb15237dba7cf86ea9e86372cb8b19d770a51261c
parentb2841da4f20b83b22fb46d82a86fe53ba7448469 (diff)
downloadgdb-32af040ef2fcbeccf746acef230db826fad951f9.zip
gdb-32af040ef2fcbeccf746acef230db826fad951f9.tar.gz
gdb-32af040ef2fcbeccf746acef230db826fad951f9.tar.bz2
Require a command argument in gdb.execute_mi
Hannes pointed out that gdb.execute_mi() will crash. This patch fixes the bug. Reviewed-By: Guinevere Larsen <guinevere@redhat.com>
-rw-r--r--gdb/python/py-mi.c7
-rw-r--r--gdb/testsuite/gdb.python/py-exec-mi.exp4
2 files changed, 11 insertions, 0 deletions
diff --git a/gdb/python/py-mi.c b/gdb/python/py-mi.c
index f0e28d9..cf75a18 100644
--- a/gdb/python/py-mi.c
+++ b/gdb/python/py-mi.c
@@ -143,6 +143,13 @@ gdbpy_execute_mi_command (PyObject *self, PyObject *args, PyObject *kw)
if (n_args < 0)
return nullptr;
+ if (n_args == 0)
+ {
+ PyErr_SetString (PyExc_TypeError,
+ _("gdb.execute_mi requires command argument"));
+ return nullptr;
+ }
+
for (Py_ssize_t i = 0; i < n_args; ++i)
{
/* Note this returns a borrowed reference. */
diff --git a/gdb/testsuite/gdb.python/py-exec-mi.exp b/gdb/testsuite/gdb.python/py-exec-mi.exp
index 8a5d0c9..6b81644 100644
--- a/gdb/testsuite/gdb.python/py-exec-mi.exp
+++ b/gdb/testsuite/gdb.python/py-exec-mi.exp
@@ -30,3 +30,7 @@ gdb_test_no_output "python gdb.execute_mi('-exec-arguments', 'a', 'b', 'c')" \
"set arguments"
gdb_test "show args" ".*\"a b c\"."
+
+# Ensure that this causes an error, not a crash.
+gdb_test "python gdb.execute_mi()" \
+ "Error occurred in Python: gdb.execute_mi requires command argument"