summaryrefslogtreecommitdiff
path: root/gdb
diff options
context:
space:
mode:
authorMaciej W. Rozycki <macro@embecosm.com>2022-10-21 08:54:18 +0100
committerMaciej W. Rozycki <macro@embecosm.com>2022-10-21 08:54:18 +0100
commitc506be7d9be55721a44d38782309d8f7fcd5e99e (patch)
tree412252debb54d25d9cbfa7d660c145bbe99620eb /gdb
parente7e1f2034567207e5e01cb75ea2ffd568a64e84d (diff)
downloadbinutils-gdb-c506be7d9be55721a44d38782309d8f7fcd5e99e.tar.gz
GDB/Python: Make `None' stand for `unlimited' in setting integer parameters
Similarly to booleans and following the fix for PR python/29217 make `gdb.parameter' accept `None' for `unlimited' with parameters of the PARAM_UINTEGER, PARAM_INTEGER, and PARAM_ZUINTEGER_UNLIMITED types, as `None' is already returned by parameters of the two former types, so one might expect to be able to feed it back. It also makes it possible to avoid the need to know what the internal integer representation is for the special setting of `unlimited'. Expand the testsuite accordingly. Approved-By: Simon Marchi <simon.marchi@polymtl.ca>
Diffstat (limited to 'gdb')
-rw-r--r--gdb/python/lib/gdb/__init__.py9
-rw-r--r--gdb/python/py-param.c10
-rw-r--r--gdb/testsuite/gdb.python/py-parameter.exp21
3 files changed, 28 insertions, 12 deletions
diff --git a/gdb/python/lib/gdb/__init__.py b/gdb/python/lib/gdb/__init__.py
index 191915e4f3b..dab57a3102f 100644
--- a/gdb/python/lib/gdb/__init__.py
+++ b/gdb/python/lib/gdb/__init__.py
@@ -235,9 +235,12 @@ def find_pc_line(pc):
def set_parameter(name, value):
"""Set the GDB parameter NAME to VALUE."""
- # Handle the specific case of booleans here, because gdb.parameter
- # can return them, but they can't be passed to 'set' this way.
- if isinstance(value, bool):
+ # Handle the specific cases of None and booleans here, because
+ # gdb.parameter can return them, but they can't be passed to 'set'
+ # this way.
+ if value is None:
+ value = "unlimited"
+ elif isinstance(value, bool):
if value:
value = "on"
else:
diff --git a/gdb/python/py-param.c b/gdb/python/py-param.c
index 5d509ba4658..cab0c563b0e 100644
--- a/gdb/python/py-param.c
+++ b/gdb/python/py-param.c
@@ -243,14 +243,18 @@ set_parameter_value (parmpy_object *self, PyObject *value)
long l;
int ok;
- if (!PyLong_Check (value))
+ if (value == Py_None
+ && (self->type == var_uinteger || self->type == var_integer))
+ l = 0;
+ else if (value == Py_None && self->type == var_zuinteger_unlimited)
+ l = -1;
+ else if (!PyLong_Check (value))
{
PyErr_SetString (PyExc_RuntimeError,
_("The value must be integer."));
return -1;
}
-
- if (! gdb_py_int_as_long (value, &l))
+ else if (! gdb_py_int_as_long (value, &l))
return -1;
switch (self->type)
diff --git a/gdb/testsuite/gdb.python/py-parameter.exp b/gdb/testsuite/gdb.python/py-parameter.exp
index 3476d4344c2..56ae2a525a9 100644
--- a/gdb/testsuite/gdb.python/py-parameter.exp
+++ b/gdb/testsuite/gdb.python/py-parameter.exp
@@ -346,18 +346,21 @@ proc_with_prefix test_gdb_parameter { } {
"listsize" {
set param_get_zero None
set param_get_minus_one -1
+ set param_get_none None
set param_get_unlimited None
set param_set_minus_one ""
}
"print elements" {
set param_get_zero None
set param_get_minus_one None
+ set param_get_none None
set param_get_unlimited None
set param_set_minus_one $param_range_error
}
"max-completions" {
set param_get_zero 0
set param_get_minus_one -1
+ set param_get_none -1
set param_get_unlimited -1
set param_set_minus_one ""
}
@@ -385,6 +388,12 @@ proc_with_prefix test_gdb_parameter { } {
gdb_test "python print(gdb.parameter('$param'))" \
$param_get_minus_one "test value of -1"
+ gdb_test_no_output "python gdb.set_parameter('$param', None)" \
+ "test set to None"
+
+ gdb_test "python print(gdb.parameter('$param'))" \
+ $param_get_none "test value of None"
+
gdb_test_no_output "python gdb.set_parameter('$param', 'unlimited')" \
"test set to 'unlimited'"
@@ -425,19 +434,19 @@ proc_with_prefix test_integer_parameter { } {
set param_get_zero None
set param_get_minus_one None
set param_get_minus_five 1
- set param_get_none 5
+ set param_get_none None
set param_set_minus_one $param_range_error
set param_set_minus_five $param_range_error
- set param_set_none $param_integer_error
+ set param_set_none ""
}
PARAM_INTEGER {
set param_get_zero None
set param_get_minus_one -1
set param_get_minus_five -5
- set param_get_none 5
+ set param_get_none None
set param_set_minus_one -1
set param_set_minus_five -5
- set param_set_none $param_integer_error
+ set param_set_none ""
}
PARAM_ZINTEGER {
set param_get_zero 0
@@ -461,10 +470,10 @@ proc_with_prefix test_integer_parameter { } {
set param_get_zero 0
set param_get_minus_one -1
set param_get_minus_five 1
- set param_get_none 5
+ set param_get_none -1
set param_set_minus_one ""
set param_set_minus_five $param_range_error
- set param_set_none $param_integer_error
+ set param_set_none ""
}
default {
error "invalid kind: $kind"