Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Tom de Vries via Gdb-patches <gdb-patches@sourceware.org>
To: gdb-patches@sourceware.org
Subject: [committed][gdb/testsuite] Fix gdb.python/py-breakpoint.exp with python 2
Date: Wed, 29 Sep 2021 15:55:05 +0200	[thread overview]
Message-ID: <20210929135503.GA16072@delia> (raw)

Hi,

With a gdb build using python 2.7, I run into:
...
(gdb) python \
  gdb.events.breakpoint_modified.connect(lambda bp: print(bp.enabled))^M
  File "<string>", line 1^M
    gdb.events.breakpoint_modified.connect(lambda bp: print(bp.enabled))^M
                                                          ^^M
SyntaxError: invalid syntax^M
Error while executing Python code.^M
(gdb) FAIL: gdb.python/py-breakpoint.exp: test_bkpt_auto_disable: \
  trap breakpoint_modified event
...

This is caused by the following:
- a lambda function body needs to be an expression
- in python 2, print is a statement, while in python 3 it's a function
- a function call is an expression, and a statement is not.

Fix this by defining a function print_bp_enabled:
...
def print_bp_enabled (bp):
    print (bp.enabled)
end
...
and using that instead.

Tested on x86_64-linux.

Committed to trunk.

Thanks,
- Tom

[gdb/testsuite] Fix gdb.python/py-breakpoint.exp with python 2

---
 gdb/testsuite/gdb.python/py-breakpoint.exp | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp
index 857480d4b61..bd99452dd5f 100644
--- a/gdb/testsuite/gdb.python/py-breakpoint.exp
+++ b/gdb/testsuite/gdb.python/py-breakpoint.exp
@@ -816,7 +816,15 @@ proc_with_prefix test_bkpt_auto_disable { } {
     set mult_line [gdb_get_line_number "Break at multiply."]
     gdb_breakpoint ${mult_line}
     gdb_test_no_output "enable count 1 2" "one shot enable"
-    gdb_test_no_output "python gdb.events.breakpoint_modified.connect(lambda bp: print(bp.enabled))" \
+    # Python 2 doesn't support print in lambda function, so use a named
+    # function instead.
+    gdb_test_multiline "Define print_bp_enabled" \
+	"python" "" \
+	"def print_bp_enabled (bp):" "" \
+	"    print (bp.enabled)" "" \
+	"end" ""
+    gdb_test_no_output \
+	"python gdb.events.breakpoint_modified.connect(print_bp_enabled)" \
 	"trap breakpoint_modified event"
     gdb_test "continue" "False.*" "auto-disabling after enable count reached"
 }

                 reply	other threads:[~2021-09-29 13:55 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20210929135503.GA16072@delia \
    --to=gdb-patches@sourceware.org \
    --cc=tdevries@suse.de \
    /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