From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26444 invoked by alias); 1 Feb 2017 20:31:17 -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 26414 invoked by uid 89); 1 Feb 2017 20:31:11 -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=survive, H*MI:sk:31c02e3, H*f:sk:31c02e3, *opcode_stream 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; Wed, 01 Feb 2017 20:31:10 +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 02F9086647; Wed, 1 Feb 2017 20:31:10 +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 v11KV8uH030012; Wed, 1 Feb 2017 15:31:09 -0500 Subject: Re: [PATCH v4 1/2] Add back gdb_pretty_print_insn To: Simon Marchi References: <1485909045-30285-1-git-send-email-palves@redhat.com> <1485909045-30285-2-git-send-email-palves@redhat.com> <31c02e39-d45f-8b65-2ff5-c21582d0f43d@redhat.com> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <3d886f4f-ba53-4ef6-3767-a7fe8a17ba85@redhat.com> Date: Wed, 01 Feb 2017 20:31: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: <31c02e39-d45f-8b65-2ff5-c21582d0f43d@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00046.txt.bz2 On 02/01/2017 08:01 PM, Pedro Alves wrote: > Yeah. It's simple to add a string_file parameter to gdb_pretty_print_insn, > in order to pass in a buffer that is reused, like it used to be, > if found necessary. > > gdb_disassembler is on the stack so practically doesn't > count, in overhead terms. I think for this series it may end > up balanced by allocating fewer cleanups, and also I suspect > most disassembled instructions fit std::string's > "small string optimization", meaning no heap allocation. If we do that, I think a better idea occurred to me. Note that gdb_disassembler::pretty_print_insn has yet another local buffer: /* Build the opcodes using a temporary stream so we can write them out in a single go for the MI. */ struct ui_file *opcode_stream = mem_fileopen (); struct cleanup *cleanups = make_cleanup_ui_file_delete (opcode_stream); so it would make sense to treat both buffers the same way. I.e., if we want to reuse one, we should probably reuse both. Which suggests creating a new struct to hold whatever should survive across calls. And then we can go the step further, and make that a class, with pretty_print_insn a method of _that_ class instead of of gdb_disassembler. Like: struct gdb_pretty_disassembler { int pretty_print_insn (struct ui_out *uiout, const struct disasm_insn *insn, int flags); private: string_file m_insn_buffer; string_file m_opcode_buffer; }; and then the use in loops would be something like: func () { gdb_pretty_disassembler disasm; while (whatever) { disasm.print_insn (uiout, ....); } } I can try that, but I think I'd rather do it after string_file is in already. Thanks, Pedro Alves