From patchwork Wed Jan 25 19:38:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Keith Seitz X-Patchwork-Id: 63683 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 158A5385B535 for ; Wed, 25 Jan 2023 19:38:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 158A5385B535 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1674675536; bh=PHHdeo4n/CXZsYw5a7NROfBch4CqSAD7wpZgATmD74g=; 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=MyV1AzngYCZFeHzOD1GlSytMJKUea87N9mPsdSo4uSufdvfFbt9wM14NO1QxdsMw/ tKCd87XPLDA7BbfPwFIpM3CHDkGFcl85jeETnKQKWmubG5EIi+xP9xH2T27Pc0UiTO kn3iteo8m+0VKaFCq6qbBE/omPPRnlLLnEJHrvyg= 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 AE06A3858C50 for ; Wed, 25 Jan 2023 19:38:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE06A3858C50 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-564-zmaoraiOPoabwhwuhedIMg-1; Wed, 25 Jan 2023 14:38:27 -0500 X-MC-Unique: zmaoraiOPoabwhwuhedIMg-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 22040858F0E; Wed, 25 Jan 2023 19:38:27 +0000 (UTC) Received: from guittard.uglyboxes.com (unknown [10.2.16.51]) by smtp.corp.redhat.com (Postfix) with ESMTP id C1BE12166B26; Wed, 25 Jan 2023 19:38:26 +0000 (UTC) To: gdb-patches@sourceware.org Cc: Wendy.Peikes@netapp.com Subject: [RFC PATCH 1/2] Add $_env convenience function Date: Wed, 25 Jan 2023 11:38:24 -0800 Message-Id: <20230125193825.3665649-2-keiths@redhat.com> In-Reply-To: <20230125193825.3665649-1-keiths@redhat.com> References: <20230125193825.3665649-1-keiths@redhat.com> 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=-11.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP, WEIRD_QUOTING 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 patch adds a new Python convenience function which simply returns the value of the given environment variable or throws a KeyError. (gdb) p $_env("HOME") $1 = "/home/keiths" [This patch is here for the purposes of demonstarting an alternative design/implementation to a previously proposed patch. See https://sourceware.org/pipermail/gdb-patches/2022-October/192396.html .] --- gdb/data-directory/Makefile.in | 1 + gdb/python/lib/gdb/function/env.py | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 gdb/python/lib/gdb/function/env.py diff --git a/gdb/data-directory/Makefile.in b/gdb/data-directory/Makefile.in index f1139291eed..3b0a05d61dc 100644 --- a/gdb/data-directory/Makefile.in +++ b/gdb/data-directory/Makefile.in @@ -107,6 +107,7 @@ PYTHON_FILE_LIST = \ gdb/function/as_string.py \ gdb/function/caller_is.py \ gdb/function/strfns.py \ + gdb/function/env.py \ gdb/printer/__init__.py \ gdb/printer/bound_registers.py diff --git a/gdb/python/lib/gdb/function/env.py b/gdb/python/lib/gdb/function/env.py new file mode 100644 index 00000000000..54a441cea54 --- /dev/null +++ b/gdb/python/lib/gdb/function/env.py @@ -0,0 +1,21 @@ +"""$_env""" + +import gdb +import os + +class _Env(gdb.Function): + """$_env - return the value of an environment variable. + + Usage: $_env("NAME") + + Returns: + Value of the environment variable named NAME or throws KeyError if NAME is + undefined in the environment.""" + + def __init__(self): + super(_Env, self).__init__("_env") + + def invoke(self, name): + return os.environ[name.string()] + +_Env()