From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674675508; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4fTqIoRdwk0+yrzphtdynpg0+Fc2a7SrgBtUBuRyoM4=; b=dIOTFAIZfLwUiGEk+BSNYEga2YUcWrP+xGwYD5WQPQpWE1YtOJ8Pp0CTk2FR2JmYc9vZKY fgG+7zWywTyQ4IuoRn+AVLwyoA6ts/FsrPB3RchVuELD3fC723V1Ma8fyT01r79oceWVb2 HKWYQpoNt8Vn4cuhL7iR+GJpi3qT5ao= 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) From: Keith Seitz 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 -- 2.38.1