gdb/python: exception trying to create empty array
authorJoel Brobecker <brobecker@adacore.com>
Tue, 6 Jan 2015 14:30:53 +0000 (18:30 +0400)
committerJoel Brobecker <brobecker@adacore.com>
Tue, 6 Jan 2015 15:07:12 +0000 (19:07 +0400)
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.

gdb/ChangeLog
gdb/python/py-type.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-type.exp

index b3e1263363b9f26868c5fe542f4a6dc69c9ee5de..a6211bf3fa588834d390f284eb57061e95c46ca4 100644 (file)
@@ -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.
index 54fc30f5cb58cc12020dc010da27aa9ae217589e..8e82c99f2e213147f6819c5784ab540e1f7ae874 100644 (file)
@@ -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"));
index 374c285dbe90365809ac10b2f8f4ac26f6e32361..7db08099584d277751c4234c8e8e351511ffa5b8 100644 (file)
@@ -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.
index 90de68dffc835bfc1ecb54f960124610e8b73d4c..c4c8d9f92aa292678932d60b5d16e70944cc6e01 100644 (file)
@@ -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"
This page took 0.031854 seconds and 4 git commands to generate.