From patchwork Wed Jan 25 08:37:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 19016 Received: (qmail 50119 invoked by alias); 25 Jan 2017 08:38:34 -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 49925 invoked by uid 89); 25 Jan 2017 08:38:32 -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, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=H*MI:sk:1484560, dimensions, 1899 X-HELO: mail-pg0-f65.google.com Received: from mail-pg0-f65.google.com (HELO mail-pg0-f65.google.com) (74.125.83.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 25 Jan 2017 08:38:22 +0000 Received: by mail-pg0-f65.google.com with SMTP id 3so1338519pgj.1 for ; Wed, 25 Jan 2017 00:38:22 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=JlD5RcP/jpoIPsTxIbG9nuk+m7yRpzm484+9jaLwTdY=; b=EQGnnfNrRbSrgolHcHBD7JMRIceXzbGzVn6WVf0i8+N5Ti5mwRSO1G5AQnnyNhVUeV NBSTmppLNOR3Q2auQcU1dM7yf4Hoj8KioOZfISKWlZdd2jQvnBM7P1oJXS8Ip5BbP0Hg e5j/MJzVhsH8eN5SE/6tR54sCVhKtTurv+ZePACbntJn8FC7Kjj/yRoznsq/cWNRDU02 88gU0JkMfiINPaxgaEIaJ9d+0SLBaxZSp3AwC+p9bauabmUF9HpxhOLvU/u636AHQcth rvoae4ZXfhKxcJP96rqu8mfYcSc/KsAAseVgwTCCCYbnlNARnoWnss1edJbyBk3A8OMY 8EFw== X-Gm-Message-State: AIkVDXKOkbprnygwRetWIItn797RL/H+xrtLVK971wihwKTqnoe2FVl+SZui1X6vf5boqw== X-Received: by 10.99.1.142 with SMTP id 136mr45728318pgb.142.1485333500676; Wed, 25 Jan 2017 00:38:20 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id x2sm50271378pfa.71.2017.01.25.00.38.19 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 25 Jan 2017 00:38:20 -0800 (PST) From: Yao Qi X-Google-Original-From: Yao Qi To: gdb-patches@sourceware.org Subject: [PATCH 1/6] New function null_stream Date: Wed, 25 Jan 2017 08:37:55 +0000 Message-Id: <1485333480-20515-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1485333480-20515-1-git-send-email-yao.qi@linaro.org> References: <1484560977-8693-1-git-send-email-yao.qi@linaro.org> <1485333480-20515-1-git-send-email-yao.qi@linaro.org> X-IsSubscribed: yes This patch adds a new function null_stream, which returns a null stream. The null stream can be used in multiple places. It is used in gdb_insn_length, and the following patches will use it too. gdb: 2017-01-24 Yao Qi * disasm.c (do_ui_file_delete): Delete. (gdb_insn_length): Move code creating stream to ... * utils.c (null_stream): ... here. New function. * utils.h (null_stream): Declare. --- gdb/disasm.c | 17 +---------------- gdb/utils.c | 15 +++++++++++++++ gdb/utils.h | 3 +++ 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/gdb/disasm.c b/gdb/disasm.c index f419501..ae3a2f1 100644 --- a/gdb/disasm.c +++ b/gdb/disasm.c @@ -838,28 +838,13 @@ gdb_print_insn (struct gdbarch *gdbarch, CORE_ADDR memaddr, return length; } -static void -do_ui_file_delete (void *arg) -{ - ui_file_delete ((struct ui_file *) arg); -} - /* Return the length in bytes of the instruction at address MEMADDR in debugged memory. */ int gdb_insn_length (struct gdbarch *gdbarch, CORE_ADDR addr) { - static struct ui_file *null_stream = NULL; - - /* Dummy file descriptor for the disassembler. */ - if (!null_stream) - { - null_stream = ui_file_new (); - make_final_cleanup (do_ui_file_delete, null_stream); - } - - return gdb_print_insn (gdbarch, addr, null_stream, NULL); + return gdb_print_insn (gdbarch, addr, null_stream (), NULL); } /* fprintf-function for gdb_buffered_insn_length. This function is a diff --git a/gdb/utils.c b/gdb/utils.c index f142ffe..ab87143 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -199,6 +199,21 @@ make_cleanup_ui_file_delete (struct ui_file *arg) return make_cleanup (do_ui_file_delete, arg); } +struct ui_file * +null_stream (void) +{ + /* A simple implementation of singleton pattern. */ + static struct ui_file *stream = NULL; + + if (stream == NULL) + { + stream = ui_file_new (); + /* Delete it on gdb exit. */ + make_final_cleanup (do_ui_file_delete, stream); + } + return stream; +} + /* Helper function for make_cleanup_ui_out_redirect_pop. */ static void diff --git a/gdb/utils.h b/gdb/utils.h index c548a50..9e71cc2 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -189,6 +189,9 @@ extern struct ui_file *gdb_stdtarg; extern struct ui_file *gdb_stdtargerr; extern struct ui_file *gdb_stdtargin; +/* Return a null stream. */ +extern struct ui_file *null_stream (void); + /* Set the screen dimensions to WIDTH and HEIGHT. */ extern void set_screen_width_and_height (int width, int height);