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 AE06A3858C50 for ; Wed, 25 Jan 2023 19:38:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AE06A3858C50 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=1674675510; 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=PHHdeo4n/CXZsYw5a7NROfBch4CqSAD7wpZgATmD74g=; b=VCTYwD4rvwO64d80uGRjnWjECC1gIFJFoOqAAw1bIIQagLh3eWzo3ygd4gemQiobVIpzm6 aIZc3LHbaghWC1Rvc4eCuS5LMvlmqiYgMdtkIRWHjYeq+I5/8kubuO7jyJO1J+0ZjVFp06 XqQt0IHl5WsdScto608eqe3C+9ZUYIE= 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) From: Keith Seitz 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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() -- 2.38.1