From patchwork Thu Feb 18 17:40:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pedro Alves X-Patchwork-Id: 10903 Received: (qmail 36255 invoked by alias); 18 Feb 2016 17:49:12 -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 36120 invoked by uid 89); 18 Feb 2016 17:49:01 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=Prefix, hardcode, 547 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; Thu, 18 Feb 2016 17:49:00 +0000 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (Postfix) with ESMTPS id 0A5BD47D2 for ; Thu, 18 Feb 2016 17:40:41 +0000 (UTC) Received: from brno.lan (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1IHea7A012351 for ; Thu, 18 Feb 2016 12:40:40 -0500 From: Pedro Alves To: gdb-patches@sourceware.org Subject: [PATCH 04/10] Eliminate async_annotation_suffix Date: Thu, 18 Feb 2016 17:40:30 +0000 Message-Id: <1455817236-13642-5-git-send-email-palves@redhat.com> In-Reply-To: <1455817236-13642-1-git-send-email-palves@redhat.com> References: <1455817236-13642-1-git-send-email-palves@redhat.com> The comments and existence of this global are a bit of misleading obfuscation, since this is only ever used to print the prompt annotation, and never changes. Just hardcode "prompt" where necessary, as done for most other annotations. gdb/ChangeLog: 2016-02-18 Pedro Alves * event-top.c (async_annotation_suffix): Delete. (top_level_prompt, command_line_handler): Don't use 'async_annotation_suffix' and simplify. * event-top.h (async_annotation_suffix): Delete declaration. (init_main): Remove reference to 'async_annotation_suffix'. --- gdb/event-top.c | 46 ++++++++-------------------------------------- gdb/event-top.h | 1 - gdb/top.c | 4 ---- 3 files changed, 8 insertions(+), 43 deletions(-) diff --git a/gdb/event-top.c b/gdb/event-top.c index 35830119..ee44197 100644 --- a/gdb/event-top.c +++ b/gdb/event-top.c @@ -107,10 +107,6 @@ void (*call_readline) (gdb_client_data); loop as default engine, and event-top.c is merged into top.c. */ int async_command_editing_p; -/* This is the annotation suffix that will be used when the - annotation_level is 2. */ -char *async_annotation_suffix; - /* This is used to display the notification of the completion of an asynchronous execution command. */ int exec_done_display_p = 0; @@ -363,49 +359,27 @@ display_gdb_prompt (const char *new_prompt) static char * top_level_prompt (void) { - char *prefix; - char *prompt = NULL; - char *suffix; - char *composed_prompt; - size_t prompt_length; + char *prompt; /* Give observers a chance of changing the prompt. E.g., the python `gdb.prompt_hook' is installed as an observer. */ observer_notify_before_prompt (get_prompt ()); - prompt = xstrdup (get_prompt ()); + prompt = get_prompt (); if (annotation_level >= 2) { /* Prefix needs to have new line at end. */ - prefix = (char *) alloca (strlen (async_annotation_suffix) + 10); - strcpy (prefix, "\n\032\032pre-"); - strcat (prefix, async_annotation_suffix); - strcat (prefix, "\n"); + const char prefix[] = "\n\032\032pre-prompt\n"; /* Suffix needs to have a new line at end and \032 \032 at beginning. */ - suffix = (char *) alloca (strlen (async_annotation_suffix) + 6); - strcpy (suffix, "\n\032\032"); - strcat (suffix, async_annotation_suffix); - strcat (suffix, "\n"); - } - else - { - prefix = ""; - suffix = ""; - } + const char suffix[] = "\n\032\032prompt\n"; - prompt_length = strlen (prefix) + strlen (prompt) + strlen (suffix); - composed_prompt = (char *) xmalloc (prompt_length + 1); - - strcpy (composed_prompt, prefix); - strcat (composed_prompt, prompt); - strcat (composed_prompt, suffix); - - xfree (prompt); + return concat (prefix, prompt, suffix, NULL); + } - return composed_prompt; + return xstrdup (prompt); } /* When there is an event ready on the stdin file desriptor, instead @@ -517,11 +491,7 @@ command_line_handler (char *rl) int repeat = (instream == stdin); if (annotation_level > 1 && instream == stdin) - { - printf_unfiltered (("\n\032\032post-")); - puts_unfiltered (async_annotation_suffix); - printf_unfiltered (("\n")); - } + printf_unfiltered (("\n\032\032post-prompt\n")); if (linebuffer == 0) { diff --git a/gdb/event-top.h b/gdb/event-top.h index 64c6fdf..1a79d62 100644 --- a/gdb/event-top.h +++ b/gdb/event-top.h @@ -54,7 +54,6 @@ extern void async_enable_stdin (void); extern int async_command_editing_p; extern int exec_done_display_p; -extern char *async_annotation_suffix; extern struct prompts the_prompts; extern void (*call_readline) (void *); extern void (*input_handler) (char *); diff --git a/gdb/top.c b/gdb/top.c index b5ee4af..fb1657a 100644 --- a/gdb/top.c +++ b/gdb/top.c @@ -1897,10 +1897,6 @@ init_main (void) the DEFAULT_PROMPT is. */ set_prompt (DEFAULT_PROMPT); - /* Set things up for annotation_level > 1, if the user ever decides - to use it. */ - async_annotation_suffix = "prompt"; - /* Set the important stuff up for command editing. */ command_editing_p = 1; history_expansion_p = 0;