From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 90380 invoked by alias); 1 Feb 2017 20:02:02 -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 90326 invoked by uid 89); 1 Feb 2017 20:02:01 -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=baking, balanced, Hx-languages-length:2455, 2407 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:02:00 +0000 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 DDED0C04BD3B; Wed, 1 Feb 2017 20:01:59 +0000 (UTC) Received: from [127.0.0.1] (ovpn04.gateway.prod.ext.phx2.redhat.com [10.5.9.4]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v11K1wqm019666; Wed, 1 Feb 2017 15:01:59 -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> Cc: gdb-patches@sourceware.org From: Pedro Alves Message-ID: <31c02e39-d45f-8b65-2ff5-c21582d0f43d@redhat.com> Date: Wed, 01 Feb 2017 20:02: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: Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-SW-Source: 2017-02/txt/msg00044.txt.bz2 On 02/01/2017 06:09 PM, Simon Marchi wrote: > I don't think I understand the situation fully, but what you suggest > looks good to me. I was confused by the fact that the gdb_disassembler > constructor accepts a stream, but the pretty_print_insn method takes a > uiout. Which one is used for printing then? I think that your patch > clears that up. > Let me try to clear up a bit. v3, which predated the gdb_disassembler changes, did this: gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout, struct disassemble_info * di, const struct disasm_insn *insn, int flags, - struct ui_file *stb) + string_file &stb) { /* parts of the symbolic representation of the address */ int unmapped; @@ -240,7 +240,7 @@ gdb_pretty_print_insn (struct gdbarch *gdbarch, struct ui_out *uiout, if (name != NULL) xfree (name); - ui_file_rewind (stb); + stb.clear (); [...] uiout->field_stream ("inst", stb); - ui_file_rewind (stb); + stb.clear (); do_cleanups (ui_out_chain); uiout->text ("\n"); while in current master we have: int gdb_disassembler::pretty_print_insn (struct ui_out *uiout, const struct disasm_insn *insn, int flags) { [...] struct ui_file *stb = stream (); [...] ui_file_rewind (stb); [...] So we can no longer do the same thing v3 did, because "stream ();" is generic. Looking at the callers of pretty_print_insn, we know that the ui_file returned by "stream ();" here is "string_file *", but doing: - struct ui_file *stb = stream (); + string_file *stb = (string_file *) stream (); would be a gross hack, for baking in knowledge of who are the current callers. > The only possible issue I can see is that in your version, one > gdb_disassembler and one string_file object are constructed for each > disassembled instruction, rather than re-using them for as long as we > need to disassemble. I don't know how much impact it has on the > performance (probably negligible), but something to keep in mind. 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. Thanks, Pedro Alves