This is the mail archive of the
gdb-cvs@sourceware.org
mailing list for the GDB project.
[binutils-gdb/users/hjl/linux/master] gdb/python: exception trying to create empty array
- From: H.J.Lu <hjl at sourceware dot org>
- To: gdb-cvs at sourceware dot org
- Date: 11 Jan 2015 16:19:54 -0000
- Subject: [binutils-gdb/users/hjl/linux/master] gdb/python: exception trying to create empty array
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=8503d6e1e564cb5ac61bc6e3f16c0b384c76661e
commit 8503d6e1e564cb5ac61bc6e3f16c0b384c76661e
Author: Joel Brobecker <brobecker@adacore.com>
Date: Tue Jan 6 18:30:53 2015 +0400
gdb/python: exception trying to create empty array
The following python command fails:
(gdb) python print gdb.lookup_type('char').array(1, 0)
Traceback (most recent call last):
File "<string>", line 1, in <module>
ValueError: Array length must not be negative
Error while executing Python code.
The above is trying to create an empty array, which is fairly command
in Ada.
gdb/ChangeLog:
* python/py-type.c (typy_array_1): Do not raise negative-length
exception if N2 is equal to N1 - 1.
gdb/testsuite/ChangeLog:
* gdb.python/py-type.exp: Add a couple test about empty
array creation, and negative-length array creation.
Diff:
---
gdb/ChangeLog | 5 +++++
gdb/python/py-type.c | 2 +-
gdb/testsuite/ChangeLog | 5 +++++
gdb/testsuite/gdb.python/py-type.exp | 6 ++++++
4 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index b3e1263..a6211bf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-06 Joel Brobecker <brobecker@adacore.com>
+
+ * python/py-type.c (typy_array_1): Do not raise negative-length
+ exception if N2 is equal to N1 - 1.
+
2015-01-03 Doug Evans <xdje42@gmail.com>
* c-exp.y: Whitespace cleanup.
diff --git a/gdb/python/py-type.c b/gdb/python/py-type.c
index 54fc30f..8e82c99 100644
--- a/gdb/python/py-type.c
+++ b/gdb/python/py-type.c
@@ -528,7 +528,7 @@ typy_array_1 (PyObject *self, PyObject *args, int is_vector)
n1 = 0;
}
- if (n2 < n1)
+ if (n2 < n1 - 1)
{
PyErr_SetString (PyExc_ValueError,
_("Array length must not be negative"));
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 374c285..7db0809 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2015-01-06 Joel Brobecker <brobecker@adacore.com>
+
+ * gdb.python/py-type.exp: Add a couple test about empty
+ array creation, and negative-length array creation.
+
2015-01-02 Doug Evans <xdje42@gmail.com>
* gdb.cp/nsalias.exp: Fix output of external/declaration flags.
diff --git a/gdb/testsuite/gdb.python/py-type.exp b/gdb/testsuite/gdb.python/py-type.exp
index 90de68d..c4c8d9f 100644
--- a/gdb/testsuite/gdb.python/py-type.exp
+++ b/gdb/testsuite/gdb.python/py-type.exp
@@ -247,6 +247,12 @@ restart_gdb "${binfile}"
# Skip all tests if Python scripting is not enabled.
if { [skip_python_tests] } { continue }
+gdb_test "python print gdb.lookup_type('char').array(1, 0)" \
+ "char \\\[0\\\]"
+
+gdb_test "python print gdb.lookup_type('char').array(1, -1)" \
+ "Array length must not be negative.*"
+
with_test_prefix "lang_c" {
runto_bp "break to inspect struct and array."
test_fields "c"