diff options
author | Joel Brobecker <brobecker@adacore.com> | 2013-11-18 12:05:02 +0400 |
---|---|---|
committer | Joel Brobecker <brobecker@adacore.com> | 2013-11-19 06:44:40 +0400 |
commit | df7752b044d8ed316827f3887e5afe675d3d243a (patch) | |
tree | 7729c4c5ddcf59172029109661d74a48274df87d | |
parent | 4a0a886ab6202ef83d74063aa9fe3467f815dd4e (diff) | |
download | gdb-df7752b044d8ed316827f3887e5afe675d3d243a.zip gdb-df7752b044d8ed316827f3887e5afe675d3d243a.tar.gz gdb-df7752b044d8ed316827f3887e5afe675d3d243a.tar.bz2 |
Fix int() builtin with range type gdb.Value objects.
Consider the following variable:
type Small is range -128 .. 127;
SR : Small := 48;
Trying to get its value as an integer within Python code yields:
(gdb) python sr = gdb.parse_and_eval('sr')
(gdb) python print int(sr)
Traceback (most recent call last):
File "<string>", line 1, in <module>
gdb.error: Cannot convert value to int.
Error while executing Python code.
This is happening because our variable is a range type, and
py-value's is_intlike does not handle TYPE_CODE_RANGE. This
patch fixes this.
gdb/ChangeLog:
* python/py-value.c (is_intlike): Add TYPE_CODE_RANGE handling.
gdb/testsuite/ChangeLog:
* gdb.ada/py_range: New testcase.
-rw-r--r-- | gdb/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/python/py-value.c | 1 | ||||
-rw-r--r-- | gdb/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/py_range.exp | 40 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/py_range/foo.adb | 32 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/py_range/pck.adb | 23 | ||||
-rw-r--r-- | gdb/testsuite/gdb.ada/py_range/pck.ads | 22 |
7 files changed, 126 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index b28d1ae..62c0654 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,9 @@ 2013-11-19 Joel Brobecker <brobecker@adacore.com> + * python/py-value.c (is_intlike): Add TYPE_CODE_RANGE handling. + +2013-11-19 Joel Brobecker <brobecker@adacore.com> + * contrib/ari/gdb_ari.sh: Remove checks for "dirent.h" and "stat.h". diff --git a/gdb/python/py-value.c b/gdb/python/py-value.c index 07feaf8..451bfaf 100644 --- a/gdb/python/py-value.c +++ b/gdb/python/py-value.c @@ -1137,6 +1137,7 @@ is_intlike (struct type *type, int ptr_ok) || TYPE_CODE (type) == TYPE_CODE_ENUM || TYPE_CODE (type) == TYPE_CODE_BOOL || TYPE_CODE (type) == TYPE_CODE_CHAR + || TYPE_CODE (type) == TYPE_CODE_RANGE || (ptr_ok && TYPE_CODE (type) == TYPE_CODE_PTR)); } diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index bcaf8bb..a026245 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2013-11-19 Joel Brobecker <brobecker@adacore.com> + + * gdb.ada/py_range: New testcase. + 2013-11-18 Joel Brobecker <brobecker@adacore.com> * mi-language.exp: Add "-list-features" test verifying that diff --git a/gdb/testsuite/gdb.ada/py_range.exp b/gdb/testsuite/gdb.ada/py_range.exp new file mode 100644 index 0000000..f24a06a --- /dev/null +++ b/gdb/testsuite/gdb.ada/py_range.exp @@ -0,0 +1,40 @@ +# Copyright 2013 Free Software Foundation, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +load_lib "ada.exp" +load_lib gdb-python.exp + +standard_ada_testfile foo + +if {[gdb_compile_ada "${srcfile}" "${binfile}" executable [list debug]] != "" } { + return -1 +} + +clean_restart ${testfile} + +# Skip this testcase if Python scripting is not enabled. +if { [skip_python_tests] } { continue } + +set bp_location [gdb_get_line_number "STOP" ${testdir}/foo.adb] +runto "foo.adb:$bp_location" + +gdb_test "python print int(gdb.parse_and_eval('sr'))" \ + "48" + +gdb_test "python print int(gdb.parse_and_eval('si'))" \ + "740804" + +gdb_test "python print int(gdb.parse_and_eval('ir'))" \ + "974" diff --git a/gdb/testsuite/gdb.ada/py_range/foo.adb b/gdb/testsuite/gdb.ada/py_range/foo.adb new file mode 100644 index 0000000..850b10f --- /dev/null +++ b/gdb/testsuite/gdb.ada/py_range/foo.adb @@ -0,0 +1,32 @@ +-- Copyright 2013 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +with Pck; use Pck; + +procedure Foo is + type Small is range -128 .. 127; + SR : Small := 48; + + type Small_Integer is range -2 ** 31 .. 2 ** 31 - 1; + SI : Small_Integer := 740804; + + type Integer4_T is range -2 ** 31 .. 2 ** 31 - 1; + for Integer4_T'Size use 32; + IR : Integer4_T := 974; +begin + Do_Nothing (SR'Address); -- STOP + Do_Nothing (SI'Address); + Do_Nothing (IR'Address); +end Foo; diff --git a/gdb/testsuite/gdb.ada/py_range/pck.adb b/gdb/testsuite/gdb.ada/py_range/pck.adb new file mode 100644 index 0000000..6b3d3c0 --- /dev/null +++ b/gdb/testsuite/gdb.ada/py_range/pck.adb @@ -0,0 +1,23 @@ +-- Copyright 2007-2013 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +package body Pck is + + procedure Do_Nothing (A : System.Address) is + begin + null; + end Do_Nothing; + +end Pck; diff --git a/gdb/testsuite/gdb.ada/py_range/pck.ads b/gdb/testsuite/gdb.ada/py_range/pck.ads new file mode 100644 index 0000000..e5f3fc0 --- /dev/null +++ b/gdb/testsuite/gdb.ada/py_range/pck.ads @@ -0,0 +1,22 @@ +-- Copyright 2007-2013 Free Software Foundation, Inc. +-- +-- This program is free software; you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation; either version 3 of the License, or +-- (at your option) any later version. +-- +-- This program is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with this program. If not, see <http://www.gnu.org/licenses/>. + +with System; + +package Pck is + + procedure Do_Nothing (A : System.Address); + +end Pck; |