From patchwork Sun Sep 3 15:38:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hsiangkai Wang X-Patchwork-Id: 22595 Received: (qmail 71809 invoked by alias); 3 Sep 2017 15:39:20 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 71416 invoked by uid 89); 3 Sep 2017 15:39:19 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, FSL_HELO_NON_FQDN_1, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RDNS_DYNAMIC, TVD_RCVD_IP autolearn=ham version=3.3.2 spammy=stepping, H*r:Debian-3 X-HELO: gym Received: from 220-134-139-55.HINET-IP.hinet.net (HELO gym) (220.134.139.55) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 03 Sep 2017 15:39:14 +0000 Received: from gym (localhost [127.0.0.1]) by gym (8.15.2/8.15.2/Debian-3) with ESMTP id v83Fd8sB009999; Sun, 3 Sep 2017 23:39:08 +0800 Received: (from kai@localhost) by gym (8.15.2/8.15.2/Submit) id v83Fd80f009995; Sun, 3 Sep 2017 23:39:08 +0800 From: Hsiangkai Wang To: gdb-patches@sourceware.org Cc: Hsiangkai Wang Subject: [PATCH] PR gdb/21698: Fix synchronization problems under python interface Date: Sun, 3 Sep 2017 23:38:06 +0800 Message-Id: <1504453086-9952-1-git-send-email-Hsiangkai@gmail.com> When executing multiple steppings through gdb.post_event(), prompt will show first and current_ui->prompt_state will be changed to PROMPTED. There is no chance to switch prompt_state to PROMPT_NEEDED or PROMPT_BLOCK. So, synchronous commands will behave like asynchronous commands under gdb.post_event(). In addition, GDB will raise an exception while checking thread state in ensure_not_running() and GDB will hang. I propose a solution to initialize current_ui->prompt_state to PROMPT_NEEDED in execute_gdb_command() to ensure synchronous commands will behave as expected. gdb/ChangeLog 2017-09-03 Hsiangkai Wang PR gdb/21698 * python/python.c (execute_gdb_command): Initialize prompt_state. testsuite/ChangeLog 2017-09-03 Hsiangkai Wang PR gdb/21698 * gdb.python/python.exp: Test multiple synchronous stepping through gdb.post_event(). * gdb.python/step.py: New file. --- gdb/ChangeLog | 5 +++++ gdb/python/python.c | 1 + gdb/testsuite/ChangeLog | 7 +++++++ gdb/testsuite/gdb.python/python.exp | 23 +++++++++++++++++++++++ gdb/testsuite/gdb.python/step.py | 7 +++++++ 5 files changed, 43 insertions(+) create mode 100644 gdb/testsuite/gdb.python/step.py diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 71566bd..7713b2f 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,3 +1,8 @@ +2017-09-03 Hsiangkai Wang + + PR gdb/21698 + * python/python.c (execute_gdb_command): Initialize prompt_state. + 2017-09-03 Simon Marchi * target/waitstatus.h (target_waitstatus_to_string): Change diff --git a/gdb/python/python.c b/gdb/python/python.c index c53e10f..49b5eff 100644 --- a/gdb/python/python.c +++ b/gdb/python/python.c @@ -589,6 +589,7 @@ execute_gdb_command (PyObject *self, PyObject *args, PyObject *kw) struct interp *interp; scoped_restore save_async = make_scoped_restore (¤t_ui->async, 0); + current_ui->prompt_state = PROMPT_NEEDED; scoped_restore save_uiout = make_scoped_restore (¤t_uiout); diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index c15743b..1c1b75b 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,3 +1,10 @@ +2017-09-03 Hsiangkai Wang + + PR gdb/21698 + * gdb.python/python.exp: Test multiple synchronous stepping + through gdb.post_event(). + * gdb.python/step.py: New file. + 2017-08-31 Sergio Durigan Junior * gdb.base/share-env-with-gdbserver.c: New file. diff --git a/gdb/testsuite/gdb.python/python.exp b/gdb/testsuite/gdb.python/python.exp index de8daad..6f46786 100644 --- a/gdb/testsuite/gdb.python/python.exp +++ b/gdb/testsuite/gdb.python/python.exp @@ -32,6 +32,9 @@ gdb_reinitialize_dir $srcdir/$subdir set remote_source2_py [gdb_remote_download host \ ${srcdir}/${subdir}/source2.py] +set remote_step_py [gdb_remote_download host \ + ${srcdir}/${subdir}/step.py] + # Do this instead of the skip_python_check. # We want to do some tests when Python is not present. @@ -474,3 +477,23 @@ gdb_py_test_silent_cmd "step" "Step into func2" 1 gdb_py_test_silent_cmd "up" "Step out of func2" 1 gdb_test "python print (gdb.find_pc_line(gdb.selected_frame().pc()).line > line)" "True" "test find_pc_line with resume address" + +# Start with a fresh gdb. +clean_restart ${testfile} + +# The following tests require execution. + +if ![runto_main] then { + fail "can't run to main" + return 0 +} + +send_gdb "source $remote_step_py\n" +gdb_expect { + -re ".*${gdb_prompt}.*Stepping successful" { + pass "multiple stepping in python script through post_event()" + } + timeout { + fail "multiple stepping in python script through post_event()" + } +} diff --git a/gdb/testsuite/gdb.python/step.py b/gdb/testsuite/gdb.python/step.py new file mode 100644 index 0000000..c8cb866 --- /dev/null +++ b/gdb/testsuite/gdb.python/step.py @@ -0,0 +1,7 @@ +def test_steps(): + for _ in range(6): + gdb.execute("si") + + print("Stepping successful.") + +gdb.post_event(test_steps)