Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom Tromey <tom@tromey.com>
To: gdb-patches@sourceware.org
Cc: Tom Tromey <tom@tromey.com>
Subject: [PATCH 4/7] Report Python errors coming from gdb.post_event
Date: Sat, 15 Sep 2018 07:25:00 -0000	[thread overview]
Message-ID: <20180915072459.14934-5-tom@tromey.com> (raw)
In-Reply-To: <20180915072459.14934-1-tom@tromey.com>

PR python/14062 points out that errors coming from the gdb.post_event
callback are not reported.  This can make it hard to understand why
your Python code in gdb isn't working.

Because users have control over whether exceptions are printed at all,
it seems good to simply have post_event report errors in the usual
way.

gdb/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/14062:
	* python/python.c (gdbpy_run_events): Do not ignore exceptions.

gdb/testsuite/ChangeLog
2018-09-15  Tom Tromey  <tom@tromey.com>

	PR python/14062:
	* gdb.python/python.exp: Add test for post_event error.
---
 gdb/ChangeLog                       |  5 +++++
 gdb/python/python.c                 |  3 +--
 gdb/testsuite/ChangeLog             |  5 +++++
 gdb/testsuite/gdb.python/python.exp | 13 ++++++++++++-
 4 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/gdb/python/python.c b/gdb/python/python.c
index e89c90f8d9f..66a43123a0a 100644
--- a/gdb/python/python.c
+++ b/gdb/python/python.c
@@ -1043,10 +1043,9 @@ gdbpy_run_events (int error, gdb_client_data client_data)
       if (gdbpy_event_list == NULL)
 	gdbpy_event_list_end = &gdbpy_event_list;
 
-      /* Ignore errors.  */
       gdbpy_ref<> call_result (PyObject_CallObject (item->event, NULL));
       if (call_result == NULL)
-	PyErr_Clear ();
+	gdbpy_print_stack ();
 
       Py_DECREF (item->event);
       xfree (item);
diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp
index 1d7ea5b6b4b..7c753215c7f 100644
--- a/gdb/testsuite/gdb.python/python.exp
+++ b/gdb/testsuite/gdb.python/python.exp
@@ -134,7 +134,18 @@ gdb_py_test_multiple "post event insertion" \
   "end" ""
 
 gdb_test "python print (someVal)" "1" "test post event execution"
-gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" "test non callable class"
+gdb_test "python gdb.post_event(str(1))" "RuntimeError: Posted event is not callable.*" \
+    "test non callable class"
+
+send_gdb "python gdb.post_event(lambda: invalid())\n"
+gdb_expect {
+    -re "name 'invalid' is not defined" {
+	pass "test post_event error on receipt"
+    }
+    default {
+	fail "test post_event error on receipt"
+    }
+}
 
 # Test (no) pagination of the executed command.
 gdb_test "show height" {Number of lines gdb thinks are in a page is unlimited\.}
-- 
2.17.1


  parent reply	other threads:[~2018-09-15  7:25 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-15  7:25 [PATCH 0/7] some small python fixes (one including a doc patch) Tom Tromey
2018-09-15  7:25 ` [PATCH 6/7] Consolidate gdb.GdbError handling Tom Tromey
2018-09-15  7:25 ` [PATCH 5/7] Check for negative argument in Type.template_argument Tom Tromey
2018-09-15  7:25 ` Tom Tromey [this message]
2018-09-15  7:25 ` [PATCH 2/7] Preserve sign when converting gdb.Value to Python int Tom Tromey
2018-09-15  7:25 ` [PATCH 1/7] Allow more Python scalar conversions Tom Tromey
2018-09-24  2:06   ` Simon Marchi
2018-09-24  4:58     ` Tom Tromey
2018-09-15  7:25 ` [PATCH 7/7] Allow setting a parameter to raise gdb.GdbError Tom Tromey
2018-09-15  9:16   ` Eli Zaretskii
2018-09-24  2:39     ` Simon Marchi
2018-09-24  4:58       ` Tom Tromey
2018-09-24  5:14         ` Tom Tromey
2018-09-24  7:10       ` Eli Zaretskii
2018-09-24 10:24         ` Tom Tromey
2018-09-24 12:39           ` Eli Zaretskii
2018-09-15  7:25 ` [PATCH 3/7] Allow conversion of pointers to Python int Tom Tromey

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180915072459.14934-5-tom@tromey.com \
    --to=tom@tromey.com \
    --cc=gdb-patches@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox