From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 70195 invoked by alias); 12 Jan 2017 15:44:49 -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 70172 invoked by uid 89); 12 Jan 2017 15:44:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-4.1 required=5.0 tests=BAYES_00,KAM_LAZY_DOMAIN_SECURITY,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=regarded, H*f:sk:72b83a2, Hx-languages-length:1999, UD:stream X-Spam-User: qpsmtpd, 2 recipients 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 ESMTP; Thu, 12 Jan 2017 15:44:47 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C1D6861B8E; Thu, 12 Jan 2017 15:44:47 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v0CFikxd011665; Thu, 12 Jan 2017 10:44:46 -0500 Subject: Re: [PATCH 3/8] Disassembly unit test: disassemble one instruction To: Yao Qi References: <1484051178-16013-1-git-send-email-yao.qi@linaro.org> <1484051178-16013-4-git-send-email-yao.qi@linaro.org> <72b83a2c-8450-7647-a83c-958d1b564296@redhat.com> <20170112153450.GF31406@E107787-LIN> Cc: binutils@sourceware.org, gdb-patches@sourceware.org From: Pedro Alves Message-ID: Date: Thu, 12 Jan 2017 15:44:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <20170112153450.GF31406@E107787-LIN> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-01/txt/msg00235.txt.bz2 On 01/12/2017 03:34 PM, Yao Qi wrote: > On 17-01-12 15:15:34, Pedro Alves wrote: >> On 01/10/2017 12:26 PM, Yao Qi wrote: >>> + class gdb_disassembler_test : public gdb_disassembler >>> + { >>> + public: >>> + >>> +#ifndef DISASSEMBLER_TEST_VERBOSE >>> + explicit gdb_disassembler_test (struct gdbarch *gdbarch, >>> + const gdb_byte *insn) >>> + : gdb_disassembler (gdbarch, ui_file_new (), >>> + gdb_disassembler_test::read_memory), >>> + m_insn (insn) >>> + { >>> + } >>> + >>> + ~gdb_disassembler_test () >>> + { >>> + ui_file_delete ((struct ui_file *) m_di.stream); >> >> >> Hmm, looks like you've made m_di be "protected" for >> these uses. >> >> But we have the public stream() method already, >> so I think could be: >> >> ~gdb_disassembler_test () >> { >> ui_file_delete (stream ()); >> } >> >> You could then make m_di private again. >> >> But you shouldn't really need to create a new stream for >> testing. We have other places that want to print to a >> a null stream. We can factor out out the null_stream creation >> from gdb_insn_length into a new function: >> >> struct ui_file * >> null_stream () >> { >> static struct ui_file *stream = NULL; >> >> if (stream == NULL) >> { >> stream = ui_file_new (); >> make_final_cleanup (do_ui_file_delete, stream); >> } >> return stream; >> } >> >> and then use it wherever necessary. >> > > I did write code that way, but I changed it because the destroy of > stream is done in cleanup. I want the test case depends on other > part of GDB as less as possible. I hope this test case can be run > even without cleanup stuff. It is sort of RAII (stream is regarded > as resource). Note that's a _final_ cleanup. I.e., it only runs when GDB exits. There's no need for gdb_disassembler_test to destroy the stream with that. And in my palves/cxx-eliminate-cleanups branch, where I've C++-fied the whole ui_file hierarchy, the cleanup completely disappears. Thanks, Pedro Alves