From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5366 invoked by alias); 20 Apr 2011 13:50:36 -0000 Received: (qmail 5345 invoked by uid 22791); 20 Apr 2011 13:50:33 -0000 X-SWARE-Spam-Status: No, hits=-6.1 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 20 Apr 2011 13:50:15 +0000 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p3KDoFa2025889 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 20 Apr 2011 09:50:15 -0400 Received: from localhost.localdomain (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id p3KDoDVq002693 for ; Wed, 20 Apr 2011 09:50:13 -0400 From: Phil Muldoon To: gdb-patches@sourceware.org Subject: [patch] [python] python/12686 Reply-to: pmuldoon@redhat.com X-URL: http://www.redhat.com Date: Wed, 20 Apr 2011 13:50:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2011-04/txt/msg00354.txt.bz2 Kevin Pouget noticed that when GDB called the Python 'stop' callback, the terminal stilled belonged to the inferior. GDB intercepts the signal generated from terminal input and it forces GDB into the background. While this patch is simple, I would like feedback. I believe the terminal is restored to the inferior when the inferior is resumed (local tests seem to show this), but I am not totally sure. Is acquiring the terminal the right thing to do here? I was trying to think of a scenario where the Python method would need the inferior terminal, but could not. Comments? Cheers, Phil -- 2011-04-20 Phil Muldoon PR python/12686 * python/py-breakpoint.c (gdbpy_should_stop): Acquire terminal before executing Python code. 2011-04-20 Phil Muldoon PR python/12686 * gdb.python/py-breakpoint.exp: Add terminal input 'stop' method test. -- diff --git a/gdb/python/py-breakpoint.c b/gdb/python/py-breakpoint.c index 0c21bfc..3ee23be 100644 --- a/gdb/python/py-breakpoint.c +++ b/gdb/python/py-breakpoint.c @@ -729,7 +729,13 @@ gdbpy_should_stop (struct breakpoint_object *bp_obj) if (PyObject_HasAttrString (py_bp, stop_func)) { - PyObject *result = PyObject_CallMethod (py_bp, stop_func, NULL); + PyObject *result; + + /* GDB acquires the terminal from the inferior before the + call. The Python 'stop' method might need to do + input/output. */ + terminal_ours (); + result = PyObject_CallMethod (py_bp, stop_func, NULL); if (result) { diff --git a/gdb/testsuite/gdb.python/py-breakpoint.exp b/gdb/testsuite/gdb.python/py-breakpoint.exp index f0a83f1..d46a37c 100644 --- a/gdb/testsuite/gdb.python/py-breakpoint.exp +++ b/gdb/testsuite/gdb.python/py-breakpoint.exp @@ -237,6 +237,15 @@ gdb_py_test_multiple "Sub-class a third breakpoint" \ " count = 0" "" \ "end" "" +gdb_py_test_multiple "Breakpoint that asks for input" \ + "python" "" \ + "class ask_bp_input (gdb.Breakpoint):" "" \ + " def stop (self):" "" \ + " inp = raw_input(\"Input\")" "" \ + " print inp" "" \ + " return True" "" \ + "end" "" + set bp_location2 [gdb_get_line_number "Break at multiply."] set end_location [gdb_get_line_number "Break at end."] gdb_py_test_silent_cmd "python eval_bp1 = bp_eval(\"$bp_location2\")" "Set breakpoint" 0 @@ -293,3 +302,39 @@ gdb_py_test_silent_cmd "python wp1 = wp_eval (\"result\", type=gdb.BP_WATCHPOIN gdb_test "continue" ".*\[Ww\]atchpoint.*result.*Old value =.*New value = 788.*" "Test watchpoint write" gdb_test "python print never_eval_bp1.count" "0" \ "Check that this unrelated breakpoints eval function was never called." + +# Test breakpoints that require user input. +# Start with a fresh gdb. +delete_breakpoints +clean_restart ${testfile} + +gdb_py_test_multiple "Breakpoint that asks for input" \ + "python" "" \ + "class ask_bp_input (gdb.Breakpoint):" "" \ + " def stop (self):" "" \ + " inp = raw_input(\"Input? \")" "" \ + " print \"Output =\", inp" "" \ + " return True" "" \ + "end" "" + +set input_bp [gdb_get_line_number "Break at multiply."] +gdb_py_test_silent_cmd "python np_input = ask_bp_input(\"$input_bp\")" \ + "Set breakpoint" 0 +send_gdb "run\n" +gdb_expect { + -re "Input\?.*" { + pass "Input prompt has appeard and awaiting for input." + } + timeout { + fail "Input prompt has not appearead." + } +} +send_gdb "123\n" +gdb_expect { + -re "Output = 123.*Breakpoint.*main.*py-breakpoint.*" { + pass "Output recieved from input is correct and printed." + } + timeout { + fail "Output not recieved from input prompt." + } +}