From patchwork Sat Mar 23 20:00:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philippe Waroquiers X-Patchwork-Id: 31952 Received: (qmail 15845 invoked by alias); 23 Mar 2019 20:00:41 -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 15650 invoked by uid 89); 23 Mar 2019 20:00:40 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.8 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=suspended, forever, sk:handle_, 130 X-HELO: mailsec119.isp.belgacom.be Received: from mailsec119.isp.belgacom.be (HELO mailsec119.isp.belgacom.be) (195.238.20.115) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sat, 23 Mar 2019 20:00:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=skynet.be; i=@skynet.be; q=dns/txt; s=securemail; t=1553371238; x=1584907238; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ju3rUpreDheHWaqXPn44LZ5Oh+8XrQTMKhe8VUgf/q0=; b=Ou6lOzUzZFRU78YcrTD+Yna1zpa8PLy3sR271l7jVggo46GhKwQ+8AOk 1+2nvdsIScTxTJTl9zfss7bhSXTI1w==; Received: from unknown (HELO md.home) ([109.130.122.147]) by relay.skynet.be with ESMTP/TLS/DHE-RSA-AES128-GCM-SHA256; 23 Mar 2019 21:00:28 +0100 From: Philippe Waroquiers To: gdb-patches@sourceware.org Cc: Philippe Waroquiers Subject: [RFA 1/3] Fix GDB being suspended SIGTTOU when running gdb.multi/multi-arch-exec.exp Date: Sat, 23 Mar 2019 21:00:20 +0100 Message-Id: <20190323200022.28689-2-philippe.waroquiers@skynet.be> In-Reply-To: <20190323200022.28689-1-philippe.waroquiers@skynet.be> References: <20190323200022.28689-1-philippe.waroquiers@skynet.be> MIME-Version: 1.0 X-IsSubscribed: yes When running under valgrind, multi-arch-exec.exp blocks forever. Some (painful) investigation shows this is due to valgrind slowing down GDB, and GDB has to output some messages at a different time, when GDB does not have the terminal for output. To reproduce the problem, you need to slow down GDB. It can be reproduced by: cd gdb/testsuite/outputs/gdb.multi/multi-arch-exec/ ../../../../gdb -ex 'set debug lin-lwp 1' -ex 'break all_started' -ex 'run' ./2-multi-arch-exec The above stops at a breakpoint. Do continue. GDB is then suspended because of SIGTTOU. The stacktrace that leads to the hanging GDB is: (top-gdb) bt at ../../binutils-gdb/gdb/exceptions.c:130 .... Alternatively, the same happens when doing strace -o s.out ../../../../gdb -ex 'break all_started' -ex 'run' ./2-multi-arch-exec And of course, valgrind is also sufficiently slowing down GDB to reproduce this :). Fix this by calling target_terminal::ours_for_output (); at the beginning of follow_exec. Note that all this terminal handling is not very clear to me: * Some code takes the terminal, and then takes care to give it back to the inferior if the terminal was belonging to the inferior. (e.g. annotate_breakpoints_invalid). * some code takes the terminal, but does not give it back (e.g. update_inserted_breakpoint_locations). * some code takes it, and unconditionally gives it back (e.g. handle_jit_event) * here and there, we also find gdb::optional term_state; before a (sometimes optional) call to ours_for_output. And such calls to ours_for_output is sometimes protected by: if (target_supports_terminal_ours ()) (e.g. exceptions.c: print_flush). but most of the code calls it without checking if the target supports it. * some code is outputting some errors, but only takes the terminal after. E.g. infcmd.c: prepare_one_step gdb/ChangeLog 2019-03-23 Philippe Waroquiers * infrun.c (follow_exec): Call target_terminal::ours_for_output. --- gdb/infrun.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gdb/infrun.c b/gdb/infrun.c index ad7892105a..0cfa2d6825 100644 --- a/gdb/infrun.c +++ b/gdb/infrun.c @@ -1087,6 +1087,10 @@ follow_exec (ptid_t ptid, char *exec_file_target) int pid = ptid.pid (); ptid_t process_ptid; + /* Switch terminal for any messages produced e.g. by + breakpoint_re_set. */ + target_terminal::ours_for_output (); + /* This is an exec event that we actually wish to pay attention to. Refresh our symbol table to the newly exec'd program, remove any momentary bp's, etc.