From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gateway30.websitewelcome.com (gateway30.websitewelcome.com [192.185.152.11]) by sourceware.org (Postfix) with ESMTPS id E255D385841A for ; Wed, 27 Oct 2021 20:38:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E255D385841A Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=tromey.com Received: from cm16.websitewelcome.com (cm16.websitewelcome.com [100.42.49.19]) by gateway30.websitewelcome.com (Postfix) with ESMTP id 569C012B72 for ; Wed, 27 Oct 2021 15:38:05 -0500 (CDT) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with SMTP id fpgTmVzyJtL6efpgTmmhSV; Wed, 27 Oct 2021 15:38:05 -0500 X-Authority-Reason: nr=8 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=tromey.com; s=default; h=Content-Type:MIME-Version:Message-ID:In-Reply-To:Date:References :Subject:Cc:To:From:Sender:Reply-To:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=wQ4spEdutWIgTncdBClMND+7ky8OxFxs5E4nMdLBakw=; b=NlNGqnfC+hekwJxmf7Ib+hk8c+ KQ/Lg+uyv+z8WtasHKskE77Dua+o4wnYbaqJ91MNIEAOMp0nATgy778N0+LyeGOeuS+MHlp7efHbW bWDwJK8YBWY+bjV27TdavfU/d; Received: from 174-16-0-219.hlrn.qwest.net ([174.16.0.219]:54100 helo=murgatroyd) by box5379.bluehost.com with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1mfpgT-0019gx-0A; Wed, 27 Oct 2021 14:38:05 -0600 From: Tom Tromey To: Andrew Burgess Cc: gdb-patches@sourceware.org Subject: Re: [PATCH 3/4] gdb: use python to colorize disassembler output References: X-Attribution: Tom Date: Wed, 27 Oct 2021 14:38:04 -0600 In-Reply-To: (Andrew Burgess's message of "Tue, 26 Oct 2021 10:37:58 +0100") Message-ID: <87k0hynqz7.fsf@tromey.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - box5379.bluehost.com X-AntiAbuse: Original Domain - sourceware.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - tromey.com X-BWhitelist: no X-Source-IP: 174.16.0.219 X-Source-L: No X-Exim-ID: 1mfpgT-0019gx-0A X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 174-16-0-219.hlrn.qwest.net (murgatroyd) [174.16.0.219]:54100 X-Source-Auth: tom+tromey.com X-Email-Count: 6 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_NEUTRAL, TXREP autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gdb-patches@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gdb-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 27 Oct 2021 20:38:26 -0000 >>>>> "Andrew" == Andrew Burgess writes: Andrew> In this commit I make use of the Python Pygments package to provide Andrew> the styling. I did investigate making use of libsource-highlight, Andrew> however, I found the highlighting results to be inferior to those of Andrew> Pygments; only some mnemonics were highlighted, and highlighting of Andrew> register names such as r9d and r8d (on x86-64) was incorrect. FWIW I think source highlight also only handles x86 assembly. I didn't look to see if Pygments is any better about this... is it? Andrew> One possibly odd choice I made with the new hook is to pass a Andrew> gdb.Architecture through, even though this is currently unused. ... Andrew> However, even though the Python function used to perform styling of Andrew> disassembly output is not part of any undocumented API, I don't want Andrew> to close the door on a user overriding this function to provide Andrew> architecture specific styling. Sounds very reasonable to me. Andrew> I don't know how much of a problem this is, for me, having the Andrew> disassembler fully styled is a big enough win. But, if people see Andrew> this as a huge problem we can investigate mechanisms to restore the Andrew> print_address styling (for the case where Pygments is not available). It does seem like a step backward when Pygments isn't available. Maybe one idea would be to disable the hook on the first failure -- just fall back to the gdb styling, with an output stream that accepts styling, and re-disassemble the single failing instruction. Would this work? Andrew> + if (!gdbpy_is_string (result.get ())) Andrew> + return {}; Andrew> + Andrew> + gdbpy_ref<> unic = python_string_to_unicode (result.get ()); Andrew> + if (unic == nullptr) I think the call to gdbpy_is_string is maybe not needed, as python_string_to_unicode already does type checking. Andrew> + { Andrew> + gdbpy_print_stack (); Andrew> + return {}; Andrew> + } Andrew> + gdbpy_ref<> host_str (PyUnicode_AsEncodedString (unic.get (), Andrew> + host_charset (), Andrew> + nullptr)); .. though actually perhaps the whole sequence could be replace with python_string_to_host_string. Though then you may prefer to use a unique_xmalloc_ptr rather than a std::string in the rest of the API. Tom