aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Burgess <aburgess@redhat.com>2024-11-10 15:50:26 +0000
committerAndrew Burgess <aburgess@redhat.com>2024-11-14 19:34:44 +0000
commitad39b4aae84a224dc5451d6a5f707b1db67a7b7e (patch)
treeba5c21256f770093040370fd7f61285f0f45b395 /gdb/testsuite
parentgdb/python: missing PyObject_IsTrue error check in py-arch.c (diff)
downloadbinutils-gdb-ad39b4aae84a224dc5451d6a5f707b1db67a7b7e.tar.gz
binutils-gdb-ad39b4aae84a224dc5451d6a5f707b1db67a7b7e.tar.bz2
binutils-gdb-ad39b4aae84a224dc5451d6a5f707b1db67a7b7e.zip
gdb/python: missing PyObject_IsTrue error check in micmdpy_set_installed
Like the previous commit, I discovered that in micmdpy_set_installed we were calling PyObject_IsTrue, but not checking for a possible error value being returned. The micmdpy_set_installed function implements the gdb.MICommand.installed attribute, and the documentation indicates that this attribute should only be assigned a bool: This attribute is read-write, setting this attribute to 'False' will uninstall the command, removing it from the set of available commands. Setting this attribute to 'True' will install the command for use. So I propose that instead of using PyObject_IsTrue we use PyBool_Check, and if the new value fails this check we raise an error. We can then compare the new value to Py_True directly instead of calling PyObject_IsTrue. This is a potentially breaking change to the Python API, but hopefully this will not impact too many people, and the fix is pretty easy (switch to using a bool). I've added a NEWS entry to draw attention to this change. Approved-By: Tom Tromey <tom@tromey.com>
Diffstat (limited to 'gdb/testsuite')
-rw-r--r--gdb/testsuite/gdb.python/py-mi-cmd.exp15
1 files changed, 15 insertions, 0 deletions
diff --git a/gdb/testsuite/gdb.python/py-mi-cmd.exp b/gdb/testsuite/gdb.python/py-mi-cmd.exp
index 52914099e6d..db017c6cdf9 100644
--- a/gdb/testsuite/gdb.python/py-mi-cmd.exp
+++ b/gdb/testsuite/gdb.python/py-mi-cmd.exp
@@ -233,6 +233,21 @@ mi_gdb_test "-abc str" \
"\\^error,msg=\"Undefined MI command: abc\",code=\"undefined-command\"" \
"-abc str, but now the command is gone"
+mi_gdb_test "python cmd.installed = None" \
+ ".*\r\n\\^error,msg=\"Error occurred in Python: gdb\\.MICommand\\.installed must be set to a bool, not None\"" \
+ "re-install the mi command using value None"
+
+mi_gdb_test "python cmd.installed = 1" \
+ ".*\r\n\\^error,msg=\"Error occurred in Python: gdb\\.MICommand\\.installed must be set to a bool, not int\"" \
+ "re-install the mi command using an int value"
+
+mi_gdb_test "python print(cmd.installed)" \
+ [multi_line \
+ ".*" \
+ "~\"False\\\\n\"" \
+ "\\^done"] \
+ "cmd is still not installed"
+
mi_gdb_test "python cmd.installed = True" \
".*\\^done" \
"re-install the mi command"