From patchwork Mon Dec 21 11:30:43 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 10090 Received: (qmail 1710 invoked by alias); 21 Dec 2015 11:30:58 -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 1629 invoked by uid 89); 21 Dec 2015 11:30:57 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=pressed, 608, recorded, cooperative X-HELO: mail-pa0-f46.google.com Received: from mail-pa0-f46.google.com (HELO mail-pa0-f46.google.com) (209.85.220.46) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Mon, 21 Dec 2015 11:30:53 +0000 Received: by mail-pa0-f46.google.com with SMTP id wq6so98547844pac.1 for ; Mon, 21 Dec 2015 03:30:53 -0800 (PST) X-Received: by 10.67.14.201 with SMTP id fi9mr26290350pad.41.1450697451688; Mon, 21 Dec 2015 03:30:51 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id zo4sm26286984pac.28.2015.12.21.03.30.50 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 21 Dec 2015 03:30:51 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [RFC 2/2] Change SIGINT handler for extension languages only when target terminal is ours Date: Mon, 21 Dec 2015 11:30:43 +0000 Message-Id: <1450697443-29067-3-git-send-email-yao.qi@linaro.org> In-Reply-To: <1450697443-29067-1-git-send-email-yao.qi@linaro.org> References: <1450697443-29067-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes I see a timeout in gdb.base/random-signal.exp, Continuing.^M PASS: gdb.base/random-signal.exp: continue ^CPython Exception : ^M FAIL: gdb.base/random-signal.exp: stop with control-c (timeout) it can be reproduced by running random-signal.exp with native-gdbserver in a loop, like this, and the fail will be shown in about 20 runs, $ (set -e; while true; do make check RUNTESTFLAGS="--target_board=native-gdbserver random-signal.exp"; done) In the test, the program is being single-stepped for software watchpoint, and in each internal stop, python unwinder sniffer is used, #0 pyuw_sniffer (self=, this_frame=, cache_ptr=0xd554f8) at /home/yao/SourceCode/gnu/gdb/git/gdb/python/py-unwind.c:608 #1 0x00000000006a10ae in frame_unwind_try_unwinder (this_frame=this_frame@entry=0xd554e0, this_cache=this_cache@entry=0xd554f8, unwinder=0xecd540) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame-unwind.c:107 #2 0x00000000006a143f in frame_unwind_find_by_frame (this_frame=this_frame@entry=0xd554e0, this_cache=this_cache@entry=0xd554f8) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame-unwind.c:163 #3 0x000000000069dc6b in compute_frame_id (fi=0xd554e0) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:454 #4 get_prev_frame_if_no_cycle (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1781 #5 0x000000000069fdb9 in get_prev_frame_always_1 (this_frame=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1955 #6 get_prev_frame_always (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:1971 #7 0x00000000006a04b1 in get_prev_frame (this_frame=this_frame@entry=0xd55410) at /home/yao/SourceCode/gnu/gdb/git/gdb/frame.c:2213 when GDB goes to python extension, or other extension language, the SIGINT handler is changed, and is restored when GDB leaves extension language. GDB only stays in extension language for a very short period in this case, but if ctrl-c is pressed at that moment, python extension will handle the SIGINT, and exceptions.KeyboardInterrupt is shown. Language extension is used in GDB side rather than inferior side, so GDB should only change SIGINT handler for extension language when the terminal is ours (not inferior's). This is what this patch does. With this patch applied, I run random-signal.exp in a loop for 18 hours, and no fail is shown. gdb: 2015-12-21 Yao Qi * extension.c: Include target.h. (set_active_ext_lang): Only call install_gdb_sigint_handler, check_quit_flag, and set_quit_flag if target_terminal_is_inferior returns false. (restore_active_ext_lang): Likewise. --- gdb/extension.c | 51 ++++++++++++++++++++++++++++++--------------------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/gdb/extension.c b/gdb/extension.c index 1b5365a..1147df9 100644 --- a/gdb/extension.c +++ b/gdb/extension.c @@ -22,6 +22,7 @@ #include "defs.h" #include +#include "target.h" #include "auto-load.h" #include "breakpoint.h" #include "event-top.h" @@ -746,19 +747,24 @@ set_active_ext_lang (const struct extension_language_defn *now_active) = XCNEW (struct active_ext_lang_state); previous->ext_lang = active_ext_lang; + previous->sigint_handler.handler_saved = 0; active_ext_lang = now_active; - /* If the newly active extension language uses cooperative SIGINT handling - then ensure GDB's SIGINT handler is installed. */ - if (now_active->language == EXT_LANG_GDB - || now_active->ops->check_quit_flag != NULL) - install_gdb_sigint_handler (&previous->sigint_handler); - - /* If there's a SIGINT recorded in the cooperative extension languages, - move it to the new language, or save it in GDB's global flag if the newly - active extension language doesn't use cooperative SIGINT handling. */ - if (check_quit_flag ()) - set_quit_flag (); + if (!target_terminal_is_inferior ()) + { + /* If the newly active extension language uses cooperative SIGINT + handling then ensure GDB's SIGINT handler is installed. */ + if (now_active->language == EXT_LANG_GDB + || now_active->ops->check_quit_flag != NULL) + install_gdb_sigint_handler (&previous->sigint_handler); + + /* If there's a SIGINT recorded in the cooperative extension languages, + move it to the new language, or save it in GDB's global flag if the + newly active extension language doesn't use cooperative SIGINT + handling. */ + if (check_quit_flag ()) + set_quit_flag (); + } return previous; } @@ -772,16 +778,19 @@ restore_active_ext_lang (struct active_ext_lang_state *previous) active_ext_lang = previous->ext_lang; - /* Restore the previous SIGINT handler if one was saved. */ - if (previous->sigint_handler.handler_saved) - install_sigint_handler (&previous->sigint_handler); - - /* If there's a SIGINT recorded in the cooperative extension languages, - move it to the new language, or save it in GDB's global flag if the newly - active extension language doesn't use cooperative SIGINT handling. */ - if (check_quit_flag ()) - set_quit_flag (); - + if (!target_terminal_is_inferior ()) + { + /* Restore the previous SIGINT handler if one was saved. */ + if (previous->sigint_handler.handler_saved) + install_sigint_handler (&previous->sigint_handler); + + /* If there's a SIGINT recorded in the cooperative extension languages, + move it to the new language, or save it in GDB's global flag if the + newly active extension language doesn't use cooperative SIGINT + handling. */ + if (check_quit_flag ()) + set_quit_flag (); + } xfree (previous); }