From patchwork Thu Jan 8 15:17:28 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 4570 Received: (qmail 6244 invoked by alias); 8 Jan 2015 15:17:55 -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 6223 invoked by uid 89); 8 Jan 2015 15:17:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, UNSUBSCRIBE_BODY autolearn=no version=3.3.2 X-HELO: mail-qc0-f169.google.com Received: from mail-qc0-f169.google.com (HELO mail-qc0-f169.google.com) (209.85.216.169) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-SHA encrypted) ESMTPS; Thu, 08 Jan 2015 15:17:48 +0000 Received: by mail-qc0-f169.google.com with SMTP id w7so2288098qcr.0 for ; Thu, 08 Jan 2015 07:17:45 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bD2YAPLDu5/HJs+0S34ygrqfN3NGb55SsJnxWyA/YeE=; b=bd1bK9CSJFthn4MsgogSLCzmpF+E4Z6eXEVPXNNtLdkZrCHWhceIh1zPI2bGpzDTy4 5/RPKjIpdKKDgz1/jYhy5V1E+P+7BIYIB8iMJ7MUTF3kx3nNwAq9loex0ikT5ZYTZOzF PBgxv0mv8Cbtd5O4REyRPHFS6CzXELJNLySJZHPkkX+Ihw5kvy8wO2B0G+NumfO7u7zp tkJfGP07pZnGGGbdcBoxXrRFB5sBOxM5BpuLr4DvPyiNdcvnUDXvunplYZnDhrSj3PsA MhJHeVek80QXO9tN2FSIe6NEitph1SUHL/RC0B8YoZM49VSr+uRWVlTjRhzzsMdAzGW6 OP4A== X-Gm-Message-State: ALoCoQl7wa43/7AM0IdOy5nf0U9gBZai9t/bg2mDFovedAzLlvc8rPYfhi7hv5P1U87QGkADICdh X-Received: by 10.140.35.240 with SMTP id n103mr15548203qgn.11.1420730264419; Thu, 08 Jan 2015 07:17:44 -0800 (PST) Received: from localhost.localdomain (ool-4353ac94.dyn.optonline.net. [67.83.172.148]) by mx.google.com with ESMTPSA id v65sm4222131qgd.20.2015.01.08.07.17.43 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 08 Jan 2015 07:17:43 -0800 (PST) From: Patrick Palka To: gdb-patches@sourceware.org Cc: palves@redhat.com, Patrick Palka Subject: [PATCH] Consolidate the custom TUI query hook with default query hook Date: Thu, 8 Jan 2015 10:17:28 -0500 Message-Id: <1420730248-18521-1-git-send-email-patrick@parcs.ath.cx> In-Reply-To: <54AE640B.3000701@redhat.com> References: <54AE640B.3000701@redhat.com> Hi Pedro, This is what I have so far. It seems to work well. Thoughts? -- >8 -- This patch primarily rewrites defaulted_query() to use gdb_readline_wrapper() to prompt the user for input, like prompt_for_continue() does. The motivation for this rewrite is to be able to reuse the default query hook in TUI, obviating the need for a custom TUI query hook. gdb/ChangeLog: * utils.c (defaulted_query): Rewrite to use gdb_readline_wrapper to prompt for input. * tui/tui-hooks.c (tui_query_hook): Remove. (tui_install_hooks): Don't set deprecated_query_hook. --- gdb/tui/tui-hooks.c | 64 ----------------------------------------------------- gdb/utils.c | 56 ++++++++++------------------------------------ 2 files changed, 12 insertions(+), 108 deletions(-) diff --git a/gdb/tui/tui-hooks.c b/gdb/tui/tui-hooks.c index 6ba6285..e53f526 100644 --- a/gdb/tui/tui-hooks.c +++ b/gdb/tui/tui-hooks.c @@ -63,68 +63,6 @@ tui_new_objfile_hook (struct objfile* objfile) tui_display_main (); } -static int ATTRIBUTE_PRINTF (1, 0) -tui_query_hook (const char *msg, va_list argp) -{ - int retval; - int ans2; - int answer; - char *question; - struct cleanup *old_chain; - - /* Format the question outside of the loop, to avoid reusing - ARGP. */ - question = xstrvprintf (msg, argp); - old_chain = make_cleanup (xfree, question); - - echo (); - while (1) - { - wrap_here (""); /* Flush any buffered output. */ - gdb_flush (gdb_stdout); - - fputs_filtered (question, gdb_stdout); - printf_filtered (_("(y or n) ")); - - wrap_here (""); - gdb_flush (gdb_stdout); - - answer = tui_getc (stdin); - clearerr (stdin); /* in case of C-d */ - if (answer == EOF) /* C-d */ - { - retval = 1; - break; - } - /* Eat rest of input line, to EOF or newline. */ - if (answer != '\n') - do - { - ans2 = tui_getc (stdin); - clearerr (stdin); - } - while (ans2 != EOF && ans2 != '\n' && ans2 != '\r'); - - if (answer >= 'a') - answer -= 040; - if (answer == 'Y') - { - retval = 1; - break; - } - if (answer == 'N') - { - retval = 0; - break; - } - printf_filtered (_("Please answer y or n.\n")); - } - noecho (); - - do_cleanups (old_chain); - return retval; -} - /* Prevent recursion of deprecated_register_changed_hook(). */ static int tui_refreshing_registers = 0; @@ -263,8 +201,6 @@ tui_install_hooks (void) deprecated_print_frame_info_listing_hook = tui_print_frame_info_listing_hook; - deprecated_query_hook = tui_query_hook; - /* Install the event hooks. */ tui_bp_created_observer = observer_attach_breakpoint_created (tui_event_create_breakpoint); diff --git a/gdb/utils.c b/gdb/utils.c index 084db87..187f91a 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -1198,12 +1198,11 @@ compile_rx_or_error (regex_t *pattern, const char *rx, const char *message) static int ATTRIBUTE_PRINTF (1, 0) defaulted_query (const char *ctlstr, const char defchar, va_list args) { - int answer; int ans2; int retval; int def_value; char def_answer, not_def_answer; - char *y_string, *n_string, *question; + char *y_string, *n_string, *question, *prompt; /* Used to add duration we waited for user to respond to prompt_for_continue_wait_time. */ struct timeval prompt_started, prompt_ended, prompt_delta; @@ -1263,62 +1262,31 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) /* Format the question outside of the loop, to avoid reusing args. */ question = xstrvprintf (ctlstr, args); + prompt = xstrprintf ("%s%s(%s or %s) %s", + annotation_level > 1 ? "\n\032\032pre-query\n" : "", + question, y_string, n_string, + annotation_level > 1 ? "\n\032\032query\n" : ""); + xfree (question); /* Used for calculating time spend waiting for user. */ gettimeofday (&prompt_started, NULL); while (1) { - wrap_here (""); /* Flush any buffered output. */ - gdb_flush (gdb_stdout); - - if (annotation_level > 1) - printf_filtered (("\n\032\032pre-query\n")); - - fputs_filtered (question, gdb_stdout); - printf_filtered (_("(%s or %s) "), y_string, n_string); - - if (annotation_level > 1) - printf_filtered (("\n\032\032query\n")); + char *response, answer = EOF; - wrap_here (""); gdb_flush (gdb_stdout); + response = gdb_readline_wrapper (prompt); + if (response != NULL) + answer = response[0]; + xfree (response); - answer = fgetc (stdin); - - /* We expect fgetc to block until a character is read. But - this may not be the case if the terminal was opened with - the NONBLOCK flag. In that case, if there is nothing to - read on stdin, fgetc returns EOF, but also sets the error - condition flag on stdin and errno to EAGAIN. With a true - EOF, stdin's error condition flag is not set. - - A situation where this behavior was observed is a pseudo - terminal on AIX. */ - while (answer == EOF && ferror (stdin) && errno == EAGAIN) - { - /* Not a real EOF. Wait a little while and try again until - we read something. */ - clearerr (stdin); - gdb_usleep (10000); - answer = fgetc (stdin); - } - - clearerr (stdin); /* in case of C-d */ if (answer == EOF) /* C-d */ { printf_filtered ("EOF [assumed %c]\n", def_answer); retval = def_value; break; } - /* Eat rest of input line, to EOF or newline. */ - if (answer != '\n') - do - { - ans2 = fgetc (stdin); - clearerr (stdin); - } - while (ans2 != EOF && ans2 != '\n' && ans2 != '\r'); if (answer >= 'a') answer -= 040; @@ -1350,7 +1318,7 @@ defaulted_query (const char *ctlstr, const char defchar, va_list args) timeval_add (&prompt_for_continue_wait_time, &prompt_for_continue_wait_time, &prompt_delta); - xfree (question); + xfree (prompt); if (annotation_level > 1) printf_filtered (("\n\032\032post-query\n")); return retval;