From patchwork Wed Jan 25 19:38:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 55435 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8D68E3858430 for ; Wed, 25 Jan 2023 19:38:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8D68E3858430 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674675533; bh=4fTqIoRdwk0+yrzphtdynpg0+Fc2a7SrgBtUBuRyoM4=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=qIWbfwrLn6SAG/7lLCkoB1WHnMjn/HnHjxGBz6g0Jvc74rVb/1MQJePlbzK/31ZiO r5994bdMeEPQF3nLTaVZLD1tBC2+PNwdJ5I74QUYO2PsQadxSQuyle3QJaRllrEAqt i7bkKL9ITJ1Rxy3Vkvi8HRWOJXWGwAMj9kGeZcJQ= X-Original-To: gdb-patches@sourceware.org Delivered-To: gdb-patches@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 4B7DA3858D28 for ; Wed, 25 Jan 2023 19:38:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4B7DA3858D28 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-558-KvgCnkHiNTC2unsyJZSrDQ-1; Wed, 25 Jan 2023 14:38:26 -0500 X-MC-Unique: KvgCnkHiNTC2unsyJZSrDQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9B86388B7A0; Wed, 25 Jan 2023 19:38:26 +0000 (UTC) Received: from guittard.uglyboxes.com (unknown [10.2.16.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34F402166B26; Wed, 25 Jan 2023 19:38:26 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Wendy.Peikes@netapp.com Subject: [RFC PATCH 0/2] Command expression evaulation substitution Date: Wed, 25 Jan 2023 11:38:23 -0800 Message-Id: <20230125193825.3665649-1-keiths@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-Patchwork-Original-From: Keith Seitz via Gdb-patches From: Keith Seitz Reply-To: Keith Seitz Errors-To: gdb-patches-bounces+patchwork=sourceware.org@sourceware.org Sender: "Gdb-patches" This RFC proposes a new syntax to allow arbitrary expressions to be substituted into command arguments. For example, the first patch in this series adds a new `_env' Python convenience function which gives users access to the shell's environment variables. If a user wanted to access the value of an environment variable within a GDB command, though, they cannot currently do that: (gdb) set logging file $_env("HOME")/$_env("MYLOG") (gdb) show logging file The current logfile is "$_env("HOME")/$_env("MYLOG")". (gdb) eval "set logging file %s/%s", $_env("HOME"), $_env("MYLOG") evaluation of this expression requires the target program to be active That `eval' doesn't work is likely a bug, but I nonetheless find the syntax quite cumbersome for this purpose. Therefore, I've chosen to introduce a new marker for expression substitution, $(). The second patch implements a proof-of-concept implementation following this concept: (gdb) set logging file $($_env("HOME"))/$($_env("MYLOG")) (gdb) show logging file The current logfile is "/home/keiths/my.log". There is a lot more to do to refine this new feature. For example, the value almost certainly needs to have a lot of format tweaking, since, for example, using chars does not work: (gdb) p 'a' $1 = 97 'a' (gdb) echo $($1)\n 97 'a' There are probably a multitude of other similar issues to be sorted out, such as arrays, repeating elements, symbol/object printing and so on. If anyone has any suggestions on how to improve this value printing code, I'd love to hear 'em. I've also chosen to hook this in at quite a low level so that all commands can immediately benefit from this. [That is, we don't have to add handling code into every command function in which we want to support this new syntax.] This may not be the best approach. @Wendy.Peikes@netapp.com: Would this proposal satisfy NetApp's needs? Keith Seitz (2): Add $_env convenience function Allow and evaluate expressions in command arguments gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/function/env.py | 21 ++++++++++ gdb/top.c | 65 ++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 gdb/python/lib/gdb/function/env.py