diff options
author | Andrew Burgess <aburgess@redhat.com> | 2024-11-10 19:58:25 +0000 |
---|---|---|
committer | Andrew Burgess <aburgess@redhat.com> | 2024-11-14 19:34:44 +0000 |
commit | 8518ce5fc22fe33e1f6f698a26548edb1dcd2e74 (patch) | |
tree | 8483c7532e8dc9b313674dcbaee6fcde54978f6a | |
parent | ad39b4aae84a224dc5451d6a5f707b1db67a7b7e (diff) | |
download | binutils-8518ce5fc22fe33e1f6f698a26548edb1dcd2e74.zip binutils-8518ce5fc22fe33e1f6f698a26548edb1dcd2e74.tar.gz binutils-8518ce5fc22fe33e1f6f698a26548edb1dcd2e74.tar.bz2 |
gdb/python: missing PyObject_IsTrue error check in bppy_init
As with the previous two commits, this commit fixes a location where
we called PyObject_IsTrue without including an error check, this time
in bppy_init.
The 'qualified' argument is supposed to be a bool, the docs say:
The optional QUALIFIED argument is a boolean that allows
interpreting the function passed in 'spec' as a fully-qualified
name. It is equivalent to 'break''s '-qualified' flag (*note
Linespec Locations:: and *note Explicit Locations::).
It's not totally clear that the only valid values are True or False,
but I'm choosing to interpret the docs that way, and so I've added a
PyBool_Type check during argument parsing. Now, if a non-bool is
passed the user will get a TypeError during argument parsing. I've
added a test to cover this case.
This is a potentially breaking change to the Python API, but hopefully
this will not impact too many people. I've added a NEWS entry to
highlight this change.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Approved-By: Tom Tromey <tom@tromey.com>
-rw-r--r-- | gdb/NEWS | 3 | ||||
-rw-r--r-- | gdb/python/py-breakpoint.c | 13 | ||||
-rw-r--r-- | gdb/testsuite/gdb.python/py-breakpoint.exp | 9 |
3 files changed, 19 insertions, 6 deletions
@@ -75,6 +75,9 @@ ** The gdb.MICommand.installed property can only be set to True or False. + ** The 'qualified' argument to gdb.Breakpoint constructor will no + longer accept non-bool types. + * Debugger Adapter Protocol changes ** The "scopes" request will now return a scope holding global diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 1edd556..752917c 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -927,14 +927,14 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) char *label = NULL; char *source = NULL; char *function = NULL; - PyObject * qualified = NULL; + PyObject *qualified = Py_False; - if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO", keywords, + if (!gdb_PyArg_ParseTupleAndKeywords (args, kwargs, "|siiOOsssOO!", keywords, &spec, &type, &access_type, &internal, &temporary, &source, &function, &label, &lineobj, - &qualified)) + &PyBool_Type, &qualified)) return -1; @@ -982,10 +982,11 @@ bppy_init (PyObject *self, PyObject *args, PyObject *kwargs) case bp_hardware_breakpoint: { location_spec_up locspec; + gdb_assert (PyBool_Check (qualified)); symbol_name_match_type func_name_match_type - = (qualified != NULL && PyObject_IsTrue (qualified) - ? symbol_name_match_type::FULL - : symbol_name_match_type::WILD); + = (qualified == Py_True + ? symbol_name_match_type::FULL + : symbol_name_match_type::WILD); if (spec != NULL) { diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index 934690d..6f9245c 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -792,6 +792,15 @@ proc_with_prefix test_bkpt_qualified {} { $one_location_re \ "qualified true" + # Test qualified with a non-bool type. + delete_breakpoints + gdb_test \ + "python gdb.Breakpoint(\"multiply\", qualified=None)" \ + [multi_line \ + "Python Exception <class 'TypeError'>: argument 10 must be bool, not None" \ + "Error occurred in Python: argument 10 must be bool, not None"] \ + "qualified non_bool_type" + # Test qualified=True with an explicit function. delete_breakpoints gdb_test \ |