From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81115 invoked by alias); 18 Mar 2016 19:18:46 -0000 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 Received: (qmail 81005 invoked by uid 89); 18 Mar 2016 19:18:45 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=no version=3.3.2 spammy=quit, newline, quits, control-c X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Fri, 18 Mar 2016 19:18:37 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id 96B34C000407 for ; Fri, 18 Mar 2016 19:18:36 +0000 (UTC) Received: from cascais.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u2IJIYjx028091 for ; Fri, 18 Mar 2016 15:18:36 -0400 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 01/30] Don't rely on immediate_quit in command_line_input Date: Fri, 18 Mar 2016 19:18:00 -0000 Message-Id: <1458328714-4938-2-git-send-email-palves@redhat.com> In-Reply-To: <1458328714-4938-1-git-send-email-palves@redhat.com> References: <1458328714-4938-1-git-send-email-palves@redhat.com> X-SW-Source: 2016-03/txt/msg00345.txt.bz2 AFAICS, immediate_quit was only needed here nowdays to be able to interrupt gdb_readline_no_editing. command_line_input can also take the gdb_readline_wrapper path, but since that is built on top of the event loop (gdb_select / poll and asynchronous signal handlers), it can be interrupted. gdb/ChangeLog: yyyy-mm-dd Pedro Alves * top.c: Include "gdb_select.h". (gdb_readline_no_editing): Wait for input with gdb_select instead of blocking in fgetc. (command_line_input): Don't set immediate_quit. --- gdb/top.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/gdb/top.c b/gdb/top.c index 89fe832..90a3f48 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -51,6 +51,7 @@ #include "filenames.h" #include "frame.h" #include "buffer.h" +#include "gdb_select.h" /* readline include files. */ #include "readline/readline.h" @@ -592,6 +593,10 @@ static char * gdb_readline_no_editing (const char *prompt) { struct buffer line_buffer; + /* Read from stdin if we are executing a user defined command. This + is the right thing for prompt_for_continue, at least. */ + FILE *stream = instream != NULL ? instream : stdin; + int fd = fileno (stream); buffer_init (&line_buffer); @@ -607,10 +612,26 @@ gdb_readline_no_editing (const char *prompt) while (1) { int c; + int numfds; + fd_set readfds; - /* Read from stdin if we are executing a user defined command. - This is the right thing for prompt_for_continue, at least. */ - c = fgetc (instream ? instream : stdin); + QUIT; + + /* Wait until at least one byte of data is available. Control-C + can interrupt gdb_select, but not fgetc. */ + FD_ZERO (&readfds); + FD_SET (fd, &readfds); + if (gdb_select (fd + 1, &readfds, NULL, NULL, NULL) == -1) + { + if (errno == EINTR) + { + /* If this was ctrl-c, the QUIT above handles it. */ + continue; + } + perror_with_name (("select")); + } + + c = fgetc (stream); if (c == EOF) { @@ -1048,10 +1069,6 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix) /* Starting a new command line. */ cmd_line_buffer.used_size = 0; - /* Control-C quits instantly if typed while in this loop - since it should not wait until the user types a newline. */ - immediate_quit++; - QUIT; #ifdef STOP_SIGNAL if (job_control) signal (STOP_SIGNAL, handle_stop_sig); @@ -1109,7 +1126,6 @@ command_line_input (const char *prompt_arg, int repeat, char *annotation_suffix) if (job_control) signal (STOP_SIGNAL, SIG_DFL); #endif - immediate_quit--; return cmd; } -- 2.5.0