Fix PR python/17981
authorTom Tromey <tom@tromey.com>
Thu, 19 May 2016 03:41:28 +0000 (21:41 -0600)
committerTom Tromey <tom@tromey.com>
Tue, 24 May 2016 15:55:01 +0000 (09:55 -0600)
PR python/17981 notes that gdb.breakpoints() returns None when there
are no breakpoints; whereas an empty list or tuple would be more in
keeping with Python and the documentation.

This patch fixes the bug by changing the no-breakpoint return to make
an empty tuple.

Built and regtested on x86-64 Fedora 23.

2016-05-23  Tom Tromey  <tom@tromey.com>

PR python/17981:
* python/py-breakpoint.c (gdbpy_breakpoints): Return a new tuple
when there are no breakpoints.

2016-05-23  Tom Tromey  <tom@tromey.com>

* python.texi (Basic Python): Document gdb.breakpoints return.

2016-05-23  Tom Tromey  <tom@tromey.com>

PR python/17981:
* gdb.python/py-breakpoint.exp (test_bkpt_basic): Add test for
no-breakpoint case.

gdb/ChangeLog
gdb/doc/ChangeLog
gdb/doc/python.texi
gdb/python/py-breakpoint.c
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.python/py-breakpoint.exp

index 45cfe75a41dff38ea7ee3f56cc96c46da22e820c..9359532193e9b7de63e21cb0972d7f22236dd510 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/17981:
+       * python/py-breakpoint.c (gdbpy_breakpoints): Return a new tuple
+       when there are no breakpoints.
+
 2016-05-24  Pedro Alves  <palves@redhat.com>
 
        PR gdb/19828
index 594f926e8925d22404d34a9d9e466bd07d20e7e6..34b9527366c82bbff094e282a4d1ff594f27f476 100644 (file)
@@ -1,3 +1,7 @@
+2016-05-23  Tom Tromey  <tom@tromey.com>
+
+       * python.texi (Basic Python): Document gdb.breakpoints return.
+
 2016-05-24  Tom Tromey  <tom@tromey.com>
 
        PR gdb/19194:
index ffbf89abcb40558a586e2a58e27f8feae0027534..6623d8e1df89d13a00c4735d7caff4c6a0b08757 100644 (file)
@@ -236,7 +236,10 @@ and height, and its pagination will be disabled; @pxref{Screen Size}.
 @findex gdb.breakpoints
 @defun gdb.breakpoints ()
 Return a sequence holding all of @value{GDBN}'s breakpoints.
-@xref{Breakpoints In Python}, for more information.
+@xref{Breakpoints In Python}, for more information.  In @value{GDBN}
+version 7.11 and earlier, this function returned @code{None} if there
+were no breakpoints.  This peculiarity was subsequently fixed, and now
+@code{gdb.breakpoints} returns an empty sequence in this case.
 @end defun
 
 @findex gdb.parameter
index 611a41e182d8f9fb5228506c10e6b556f32f0631..ed9cae68b0ddd791d469ef8d2622248c30e6c059 100644 (file)
@@ -746,13 +746,13 @@ gdbpy_breakpoints (PyObject *self, PyObject *args)
   PyObject *list, *tuple;
 
   if (bppy_live == 0)
-    Py_RETURN_NONE;
+    return PyTuple_New (0);
 
   list = PyList_New (0);
   if (!list)
     return NULL;
 
-  /* If iteratre_over_breakpoints returns non NULL it signals an error
+  /* If iterate_over_breakpoints returns non NULL it signals an error
      condition.  In that case abandon building the list and return
      NULL.  */
   if (iterate_over_breakpoints (build_bp_list, list) != NULL)
index 16b756c506cb3ea3819b8ae6b1ebd1a57bed12b3..319c0f5c8cafb3e6e99dc241286e0e8bb89a3adb 100644 (file)
@@ -1,3 +1,9 @@
+2016-05-23  Tom Tromey  <tom@tromey.com>
+
+       PR python/17981:
+       * gdb.python/py-breakpoint.exp (test_bkpt_basic): Add test for
+       no-breakpoint case.
+
 2016-05-24  Pedro Alves  <palves@redhat.com>
 
        PR gdb/19828
index d1d1b2253f93a35c8eecf408923272a7ad81b5a2..f501aa91d8a4231366d56d80691f958d445a179d 100644 (file)
@@ -34,12 +34,15 @@ proc test_bkpt_basic { } {
        # Start with a fresh gdb.
        clean_restart ${testfile}
 
+       # We should start with no breakpoints.
+       gdb_test "python print (gdb.breakpoints())" "\\(\\)"
+
        if ![runto_main] then {
            fail "Cannot run to main."
            return 0
        }
 
-       # Initially there should be one breakpoint: main.
+       # Now there should be one breakpoint: main.
        gdb_py_test_silent_cmd "python blist = gdb.breakpoints()" \
            "Get Breakpoint List" 0
        gdb_test "python print (blist\[0\])" \
This page took 0.037619 seconds and 4 git commands to generate.