From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 61905 invoked by alias); 12 Jan 2017 15:35:07 -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 61784 invoked by uid 89); 12 Jan 2017 15:35:06 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: =?ISO-8859-1?Q?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==e5=b0=a7, H*r:AES128-SHA, Hx-languages-length:1634, regarded?= X-Spam-User: qpsmtpd, 2 recipients X-HELO: mail-lf0-f66.google.com Received: from mail-lf0-f66.google.com (HELO mail-lf0-f66.google.com) (209.85.215.66) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 12 Jan 2017 15:35:04 +0000 Received: by mail-lf0-f66.google.com with SMTP id v186so2345250lfa.2; Thu, 12 Jan 2017 07:35:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=ySnbskVoyH/lSf1Xaa/ZUb7NZP9dfjHuAr/TCrINyzI=; b=axZBK+YycrznILmuLD9ntI2tM7R8UgkUAVl4TPdx/jxmpMO2dPIv59UdqNZLWeFjOd VZOtKwGsk7IuXQ20P3E0pyrg0PHzIuNVqUis5ZH3ok3epF090WOkabAK4yAtLgdtntf3 KtqlfBMt6UElPaC5yybPblsrGLv7pDPYTNMfhot4mmpdrLwH+vZlKbR85oB7gTDLaBAS 4XiFOyU88y2RyP8ZV6ic7KE4aLyfPmwkhSLYuPUwVC7YToIG+LMbMXsneF5x6MCNInr2 MYCT/3mCJAo0Gqf7xPWAevqHpuW2t9njWwNea1LlBUwt54SX4daqIVtnwx45FxDPrz4v xcVw== X-Gm-Message-State: AIkVDXIEjcvI7+vEREXJqs3C/BMtde51sdL2CVpPPc3+g6TlwFdiqRt6fZq/nn2eC3SnGA== X-Received: by 10.194.59.177 with SMTP id a17mr2529299wjr.208.1484235302279; Thu, 12 Jan 2017 07:35:02 -0800 (PST) Received: from E107787-LIN (gcc1-power7.osuosl.org. [140.211.15.137]) by smtp.gmail.com with ESMTPSA id k11sm3711357wmb.18.2017.01.12.07.34.59 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 12 Jan 2017 07:35:01 -0800 (PST) Date: Thu, 12 Jan 2017 15:35:00 -0000 From: Yao Qi To: Pedro Alves Cc: binutils@sourceware.org, gdb-patches@sourceware.org Subject: Re: [PATCH 3/8] Disassembly unit test: disassemble one instruction Message-ID: <20170112153450.GF31406@E107787-LIN> 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> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <72b83a2c-8450-7647-a83c-958d1b564296@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes X-SW-Source: 2017-01/txt/msg00232.txt.bz2 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). -- Yao (齐尧)