From patchwork Mon Jan 16 10:02:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yao Qi X-Patchwork-Id: 18912 Received: (qmail 53248 invoked by alias); 16 Jan 2017 10:03:25 -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 53075 invoked by uid 89); 16 Jan 2017 10:03:23 -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=Hx-spam-relays-external:74.125.83.68, H*RU:74.125.83.68, ui_file_delete, sk:f419501 X-HELO: mail-pg0-f68.google.com Received: from mail-pg0-f68.google.com (HELO mail-pg0-f68.google.com) (74.125.83.68) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 16 Jan 2017 10:03:13 +0000 Received: by mail-pg0-f68.google.com with SMTP id 75so5045380pgf.3 for ; Mon, 16 Jan 2017 02:03:13 -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=g08eS8KDy3KA6Ba9ugWYswwedXVX9L04lNwsbasGWTs=; b=WQnwWYh17eMG49PuExYdUd476VgSdkoIIV+EU8rH8YQnX4zlSv7VpkatX8jZIPSfLO gREANPQZtq77Pvd5wn25sgdOLbDc3jtSLMsQR9C2ER4P+vIrvCmqLDbFxfNDcUJe+O3Y x8jzUQL6oX8yjZS1sh4npp87qsMBfX+c3OIzknv7LqQaPhdH4eVXoTKJiomTtbkSTaJa BmUqwInm03ZAiZpUvTDENHWCNo/3GuuXHK/g42fw2RKvekeZ5yPWW038JSBgz0IrVvLc /TXyKkLiZtiaE++SIsBruVh/zVVoOGe+YWkbJvJnujbGyop81xtkCfiwKyvdNHPSYNC+ oSHw== X-Gm-Message-State: AIkVDXKV2kpJBXnfqFKS6n6S0VctdJ4J3Ifu4yBXTQGt4wYHe+/fRsD5nc3mtSJdSMHiYw== X-Received: by 10.84.232.197 with SMTP id x5mr47599402plm.111.1484560991572; Mon, 16 Jan 2017 02:03:11 -0800 (PST) Received: from E107787-LIN.cambridge.arm.com (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id g28sm9695206pgn.3.2017.01.16.02.03.10 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 16 Jan 2017 02:03:11 -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: Mon, 16 Jan 2017 10:02:52 +0000 Message-Id: <1484560977-8693-2-git-send-email-yao.qi@linaro.org> In-Reply-To: <1484560977-8693-1-git-send-email-yao.qi@linaro.org> References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484560977-8693-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-13 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 | 13 +++++++++++++ gdb/utils.h | 4 ++++ 3 files changed, 18 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..7bad193 100644 --- a/gdb/utils.c +++ b/gdb/utils.c @@ -199,6 +199,19 @@ make_cleanup_ui_file_delete (struct ui_file *arg) return make_cleanup (do_ui_file_delete, arg); } +struct ui_file * +null_stream (void) +{ + static struct ui_file *stream = NULL; + + if (stream == NULL) + { + stream = ui_file_new (); + 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..26e60af 100644 --- a/gdb/utils.h +++ b/gdb/utils.h @@ -189,6 +189,10 @@ 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);