From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from qproxy2-pub.mail.unifiedlayer.com (qproxy2-pub.mail.unifiedlayer.com [69.89.16.161]) by sourceware.org (Postfix) with ESMTPS id 9C8D63858D1E for ; Fri, 25 Feb 2022 19:23:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9C8D63858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=tromey.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=tromey.com Received: from gproxy2-pub.mail.unifiedlayer.com (gproxy2-pub.mail.unifiedlayer.com [69.89.18.3]) by qproxy2.mail.unifiedlayer.com (Postfix) with ESMTP id E881D8029F24 for ; Fri, 25 Feb 2022 19:23:19 +0000 (UTC) Received: from cmgw10.mail.unifiedlayer.com (unknown [10.0.90.125]) by progateway4.mail.pro1.eigbox.com (Postfix) with ESMTP id A480C1004836E for ; Fri, 25 Feb 2022 19:22:49 +0000 (UTC) Received: from box5379.bluehost.com ([162.241.216.53]) by cmsmtp with ESMTP id NgAznnKoEQs3CNgAzntEiF; Fri, 25 Feb 2022 19:22:49 +0000 X-Authority-Reason: nr=8 X-Authority-Analysis: v=2.4 cv=d8AwdTvE c=1 sm=1 tr=0 ts=62192c89 a=ApxJNpeYhEAb1aAlGBBbmA==:117 a=ApxJNpeYhEAb1aAlGBBbmA==:17 a=dLZJa+xiwSxG16/P+YVxDGlgEgI=:19 a=oGFeUVbbRNcA:10:nop_rcvd_month_year a=Qbun_eYptAEA:10:endurance_base64_authed_username_1 a=CCpqsmhAAAAA:8 a=8EmtCbBt5Z8adDL8kI8A:9 a=qh50Nh6Qa74A:10:demote_hacked_domain_1 a=ul9cdbp4aOFLsgKbc677:22 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=Xl7q6vymwY/trQTxlRj/3z62cW6M6O43HzF79keMGT8=; b=Ta6zh7+4X7VQkT9q0iXTzYnR+L 56/4ajrmvkYChIsAvOcQ1m/L3P4z+gQzHnhQurEdet/88WMOpU4QE8Y5Xj+y0Udy32EhJ75cBwi0H 7NDGoxfED1BZ+0zSca2xkN6ho; Received: from 75-166-146-214.hlrn.qwest.net ([75.166.146.214]:56036 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 1nNgAy-0012C9-Ha; Fri, 25 Feb 2022 12:22:48 -0700 From: Tom Tromey To: Andrew Burgess via Gdb-patches Cc: Andrew Burgess , Jan Vrany Subject: Re: [PATCHv4] gdb/python/mi: create MI commands using python References: <20220209122531.GA2768@redhat.com> <20220224103749.1719761-1-aburgess@redhat.com> X-Attribution: Tom Date: Fri, 25 Feb 2022 12:22:47 -0700 In-Reply-To: <20220224103749.1719761-1-aburgess@redhat.com> (Andrew Burgess via Gdb-patches's message of "Thu, 24 Feb 2022 10:37:49 +0000") Message-ID: <87r17qn43c.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: 75.166.146.214 X-Source-L: No X-Exim-ID: 1nNgAy-0012C9-Ha X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: 75-166-146-214.hlrn.qwest.net (murgatroyd) [75.166.146.214]:56036 X-Source-Auth: tom+tromey.com X-Email-Count: 1 X-Source-Cap: ZWx5bnJvYmk7ZWx5bnJvYmk7Ym94NTM3OS5ibHVlaG9zdC5jb20= X-Local-Domain: yes X-Spam-Status: No, score=-3025.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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: Fri, 25 Feb 2022 19:23:51 -0000 >>>>> "Andrew" == Andrew Burgess via Gdb-patches writes: Andrew> This v4 patch is identical to the version I posted here: Andrew> https://sourceware.org/pipermail/gdb-patches/2022-February/185821.html Andrew> except I've rebased onto current master. I just wanted to make sure Andrew> it was clear what the latest version of this patch was. Thank you both for working on this. Andrew> When used within gdb the above command produced output like this: Andrew> (gdb) Andrew> -echo-args a b c Andrew> ^done,args=["a","b","c"] Andrew> (gdb) Not necessary for this patch but I wonder if there should also be a way to emit an async event from Python. Andrew> I have required that the fields names used in mi result output must Andrew> follow C identifier restrictions (i.e. must match the regexp Andrew> "[a-zA-Z][a-zA-Z0-9_]*"). I think '-' is also supported, e.g.: uiout->field_string ("thread-id", print_thread_id (thr)); Andrew> +@defun MICommand.invoke (arguments) Andrew> +This method is called by @value{GDBN} when the new MI command is Andrew> +invoked. Andrew> + Andrew> +@var{arguments} is a list of strings. Note, that @code{--thread} Andrew> +and @code{--frame} arguments are handled by @value{GDBN} itself therefore Andrew> +they do not show up in @code{arguments}. I guess this is done because an option may or may not take a value? That kind of too bad since it would be nice if this could just be a dictionary. I suppose we could always also add an MI parsing helper, though Python also has tons of things for this as well. Andrew> +The strings used for @emph{VARIABLE} names in the @sc{GDB/MI} output Andrew> +must follow the following rules; the string must be at least one Andrew> +character long, the first character must be in the set Andrew> +@code{[a-zA-Z]}, while every subsequent character must be in the set Andrew> +@code{[a-zA-Z0-9_]}. This should be updated to include '-'. Andrew> +@smallexample Andrew> +class MIEcho(gdb.MICommand): Andrew> + """Echo arguments passed to the command.""" Andrew> + Andrew> + def __init__(self, name, mode, toplevel = None): Andrew> + self._mode = mode Andrew> + super(MIEcho, self).__init__(name, toplevel) What is 'toplevel' here? It isn't documented for gdb.MICommand. Andrew> + /* Called when the MI command is invoked. */ Andrew> + virtual void do_invoke(struct mi_parse *parse) const override; Andrew> + if (key_repr != nullptr) Andrew> + key_repr_string = python_string_to_target_string (key_repr.get ()); Andrew> + if (key_repr_string == nullptr) Andrew> + gdbpy_handle_exception (); Andrew> + Andrew> + gdbpy_error (_("non-string object used as key: %s"), Andrew> + key_repr_string.get ()); Someday I'd like gdb to solve the "denaturation" problem, where if Python code throw some exception, it's turned into a generic exception of some kind by gdb ... which if it is then caught again by Python, has transmuted into something else. Anyway this seems fine, just felt like I had to get that out. Andrew> + for (; *name != '\0'; ++name) Andrew> + if (!isalnum (*name) && *name != '_') Andrew> + return false; '-' Andrew> + else if (PyIter_Check (result)) Andrew> + { Andrew> + gdbpy_ref<> item; Andrew> + ui_out_emit_list list_emitter (uiout, field_name); Andrew> + while (true) Andrew> + { Not for this patch but I wonder if emitting dictionaries via ui_out might make for nicer CLI commands sometimes. Andrew> + gdbpy_enter enter_py (get_current_arch (), current_language); Probably should just drop the parameters here. thanks, Tom