public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [RFA] Fix PR python/17981
@ 2016-05-19  3:47 Tom Tromey
  2016-05-23  8:52 ` Yao Qi
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2016-05-19  3:47 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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.

It's arguable whether this should be changed.  On the one hand, it may
mean some script has to adapt.  On the other hand, it's clearly better
this way.

Built and regtested on x86-64 Fedora 23.

2016-05-18  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-18  Tom Tromey  <tom@tromey.com>

	PR python/17981:
	* gdb.python/py-breakpoint.exp (test_bkpt_basic): Add test for
	no-breakpoint case.
---
 gdb/ChangeLog                              | 6 ++++++
 gdb/python/py-breakpoint.c                 | 4 ++--
 gdb/testsuite/ChangeLog                    | 6 ++++++
 gdb/testsuite/gdb.python/py-breakpoint.exp | 5 ++++-
 4 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 92024b6..53b11c0 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 2016-05-18  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-18  Tom Tromey  <tom@tromey.com>
+
 	* rust-lang.c (rust_subscript): Initialize "high".
 
 2016-05-17  Simon Marchi  <simon.marchi@ericsson.com>
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 611a41e..ed9cae6 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -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)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index a773c63..c09e858 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2016-05-18  Tom Tromey  <tom@tromey.com>
+
+	PR python/17981:
+	* gdb.python/py-breakpoint.exp (test_bkpt_basic): Add test for
+	no-breakpoint case.
+
 2016-05-18  Simon Marchi  <simon.marchi@ericsson.com>
 
 	* gdb.mi/mi-threads-interrupt.c: New file.
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index d1d1b22..0116705 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -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\])" \
-- 
2.5.5

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-19  3:47 [RFA] Fix PR python/17981 Tom Tromey
@ 2016-05-23  8:52 ` Yao Qi
  2016-05-23 14:05   ` Tom Tromey
  2016-05-23 19:07   ` Tom Tromey
  0 siblings, 2 replies; 8+ messages in thread
From: Yao Qi @ 2016-05-23  8:52 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

Tom Tromey <tom@tromey.com> writes:

> 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.
>

We need to update doc about gdb.breakpoints () for this change.

>  
> -  /* If iteratre_over_breakpoints returns non NULL it signals an error
> +  /* If iterate_over_breakpoints returns non NULL it signals an error

This is a typo fix, can go in as a separate patch.  Otherwise, patch is
good to me.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23  8:52 ` Yao Qi
@ 2016-05-23 14:05   ` Tom Tromey
  2016-05-23 14:29     ` Yao Qi
  2016-05-23 19:07   ` Tom Tromey
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2016-05-23 14:05 UTC (permalink / raw)
  To: Yao Qi; +Cc: Tom Tromey, gdb-patches

Yao> We need to update doc about gdb.breakpoints () for this change.

The docs already seemed correct:

 -- Function: gdb.breakpoints ()
     Return a sequence holding all of GDB's breakpoints.  *Note
     Breakpoints In Python::, for more information.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23 14:05   ` Tom Tromey
@ 2016-05-23 14:29     ` Yao Qi
  2016-05-23 19:07       ` Tom Tromey
  0 siblings, 1 reply; 8+ messages in thread
From: Yao Qi @ 2016-05-23 14:29 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Yao Qi, gdb-patches

Tom Tromey <tom@tromey.com> writes:

> The docs already seemed correct:
>
>  -- Function: gdb.breakpoints ()
>      Return a sequence holding all of GDB's breakpoints.  *Note
>      Breakpoints In Python::, for more information.

Yes, it is correct, but it is better to explicitly document an empty
sequence is returned if there are no breakpoints.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23 14:29     ` Yao Qi
@ 2016-05-23 19:07       ` Tom Tromey
  2016-05-23 19:15         ` Eli Zaretskii
  0 siblings, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2016-05-23 19:07 UTC (permalink / raw)
  To: Yao Qi; +Cc: Tom Tromey, gdb-patches

Yao> Yes, it is correct, but it is better to explicitly document an empty
Yao> sequence is returned if there are no breakpoints.

Here you go.

Tom

From 372c5d3e52de3695ca2148eb7683801285072c0c Mon Sep 17 00:00:00 2001
From: Tom Tromey <tom@tromey.com>
Date: Wed, 18 May 2016 21:41:28 -0600
Subject: [PATCH] Fix PR python/17981

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                              | 6 ++++++
 gdb/doc/ChangeLog                          | 4 ++++
 gdb/doc/python.texi                        | 5 ++++-
 gdb/python/py-breakpoint.c                 | 4 ++--
 gdb/testsuite/ChangeLog                    | 6 ++++++
 gdb/testsuite/gdb.python/py-breakpoint.exp | 5 ++++-
 6 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 07bc5d2..ef25519 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,11 @@
 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>
+
 	PR python/19438, PR python/18393:
 	* python/py-objfile.c (objfpy_initialize): Initialize self->dict.
 	* python/py-progspace.c (pspy_initialize): Initialize self->dict.
diff --git a/gdb/doc/ChangeLog b/gdb/doc/ChangeLog
index fe2e3be..3be4a88 100644
--- a/gdb/doc/ChangeLog
+++ b/gdb/doc/ChangeLog
@@ -1,3 +1,7 @@
+2016-05-23  Tom Tromey  <tom@tromey.com>
+
+	* python.texi (Basic Python): Document gdb.breakpoints return.
+
 2016-05-17  Tom Tromey  <tom@tromey.com>
 
 	* gdb.texinfo (Supported Languages): Mention Rust.  Update menu.
diff --git a/gdb/doc/python.texi b/gdb/doc/python.texi
index ffbf89a..6623d8e 100644
--- a/gdb/doc/python.texi
+++ b/gdb/doc/python.texi
@@ -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
diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c
index 611a41e..ed9cae6 100644
--- a/gdb/python/py-breakpoint.c
+++ b/gdb/python/py-breakpoint.c
@@ -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)
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog
index 1f0e3f9..afa358b 100644
--- a/gdb/testsuite/ChangeLog
+++ b/gdb/testsuite/ChangeLog
@@ -1,5 +1,11 @@
 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-23  Tom Tromey  <tom@tromey.com>
+
 	PR python/19438, PR python/18393:
 	* gdb.python/py-progspace.exp: Add "dir" test.
 	* gdb.python/py-objfile.exp: Add "dir" test.
diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index d1d1b22..f501aa9 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -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\])" \
-- 
2.5.5

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23  8:52 ` Yao Qi
  2016-05-23 14:05   ` Tom Tromey
@ 2016-05-23 19:07   ` Tom Tromey
  2016-05-24  8:38     ` Yao Qi
  1 sibling, 1 reply; 8+ messages in thread
From: Tom Tromey @ 2016-05-23 19:07 UTC (permalink / raw)
  To: Yao Qi; +Cc: Tom Tromey, gdb-patches

>> -  /* If iteratre_over_breakpoints returns non NULL it signals an error
>> +  /* If iterate_over_breakpoints returns non NULL it signals an error

Yao> This is a typo fix, can go in as a separate patch.  Otherwise, patch is
Yao> good to me.

Oops, I included it in my latest.
If that's not ok, let me know, and I'll remove it.

Tom

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23 19:07       ` Tom Tromey
@ 2016-05-23 19:15         ` Eli Zaretskii
  0 siblings, 0 replies; 8+ messages in thread
From: Eli Zaretskii @ 2016-05-23 19:15 UTC (permalink / raw)
  To: Tom Tromey; +Cc: qiyaoltc, gdb-patches

> From: Tom Tromey <tom@tromey.com>
> Cc: Tom Tromey <tom@tromey.com>,  gdb-patches@sourceware.org
> Date: Mon, 23 May 2016 13:06:51 -0600
> 
> Yao> Yes, it is correct, but it is better to explicitly document an empty
> Yao> sequence is returned if there are no breakpoints.
> 
> Here you go.

OK, thanks.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [RFA] Fix PR python/17981
  2016-05-23 19:07   ` Tom Tromey
@ 2016-05-24  8:38     ` Yao Qi
  0 siblings, 0 replies; 8+ messages in thread
From: Yao Qi @ 2016-05-24  8:38 UTC (permalink / raw)
  To: Tom Tromey; +Cc: Yao Qi, gdb-patches

Tom Tromey <tom@tromey.com> writes:

> Oops, I included it in my latest.
> If that's not ok, let me know, and I'll remove it.

That is fine by me.  It is better to move typo fix in a separate patch
in the future.

-- 
Yao (齐尧)

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2016-05-24  8:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-05-19  3:47 [RFA] Fix PR python/17981 Tom Tromey
2016-05-23  8:52 ` Yao Qi
2016-05-23 14:05   ` Tom Tromey
2016-05-23 14:29     ` Yao Qi
2016-05-23 19:07       ` Tom Tromey
2016-05-23 19:15         ` Eli Zaretskii
2016-05-23 19:07   ` Tom Tromey
2016-05-24  8:38     ` Yao Qi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).